From 0f162ecf0034d2002de5b450214cbfa4672682df Mon Sep 17 00:00:00 2001 From: Guillaume Claret Date: Thu, 9 May 2024 19:15:33 +0200 Subject: [PATCH 1/6] Add translation of all the files --- CoqOfPython/CoqMakefile | 2 +- CoqOfPython/ethereum/__init__.v | 56 + CoqOfPython/ethereum/arrow_glacier/__init__.v | 23 + CoqOfPython/ethereum/arrow_glacier/blocks.v | 95 + CoqOfPython/ethereum/arrow_glacier/bloom.v | 164 + .../ethereum/arrow_glacier/fork_types.v | 102 + CoqOfPython/ethereum/arrow_glacier/state.v | 1184 +++++++ .../ethereum/arrow_glacier/transactions.v | 274 ++ CoqOfPython/ethereum/arrow_glacier/trie.v | 1357 ++++++++ .../ethereum/arrow_glacier/utils/__init__.v | 8 + .../ethereum/arrow_glacier/utils/address.v | 204 ++ .../arrow_glacier/utils/hexadecimal.v | 155 + .../ethereum/arrow_glacier/utils/message.v | 254 ++ .../ethereum/arrow_glacier/vm/__init__.v | 262 ++ .../ethereum/arrow_glacier/vm/exceptions.v | 172 + .../arrow_glacier/vm/instructions/__init__.v | 87 + .../vm/instructions/arithmetic.v | 1085 +++++++ .../arrow_glacier/vm/instructions/bitwise.v | 601 ++++ .../arrow_glacier/vm/instructions/block.v | 379 +++ .../vm/instructions/comparison.v | 404 +++ .../vm/instructions/control_flow.v | 336 ++ .../vm/instructions/environment.v | 1436 +++++++++ .../arrow_glacier/vm/instructions/keccak.v | 181 ++ .../arrow_glacier/vm/instructions/log.v | 244 ++ .../arrow_glacier/vm/instructions/memory.v | 378 +++ .../arrow_glacier/vm/instructions/stack.v | 929 ++++++ .../arrow_glacier/vm/instructions/storage.v | 437 +++ .../ethereum/arrow_glacier/vm/interpreter.v | 645 ++++ .../ethereum/arrow_glacier/vm/memory.v | 153 + .../vm/precompiled_contracts/__init__.v | 117 + .../vm/precompiled_contracts/alt_bn128.v | 673 ++++ .../vm/precompiled_contracts/blake2f.v | 122 + .../vm/precompiled_contracts/ecrecover.v | 269 ++ .../vm/precompiled_contracts/identity.v | 94 + .../vm/precompiled_contracts/mapping.v | 82 + .../vm/precompiled_contracts/modexp.v | 608 ++++ .../vm/precompiled_contracts/ripemd160.v | 122 + .../vm/precompiled_contracts/sha256.v | 106 + .../ethereum/arrow_glacier/vm/runtime.v | 125 + CoqOfPython/ethereum/arrow_glacier/vm/stack.v | 120 + CoqOfPython/ethereum/berlin/__init__.v | 24 + CoqOfPython/ethereum/berlin/blocks.v | 95 + CoqOfPython/ethereum/berlin/bloom.v | 164 + CoqOfPython/ethereum/berlin/fork_types.v | 102 + CoqOfPython/ethereum/berlin/state.v | 1184 +++++++ CoqOfPython/ethereum/berlin/transactions.v | 213 ++ CoqOfPython/ethereum/berlin/trie.v | 1357 ++++++++ CoqOfPython/ethereum/berlin/utils/__init__.v | 8 + CoqOfPython/ethereum/berlin/utils/address.v | 204 ++ .../ethereum/berlin/utils/hexadecimal.v | 155 + CoqOfPython/ethereum/berlin/utils/message.v | 254 ++ CoqOfPython/ethereum/berlin/vm/__init__.v | 262 ++ CoqOfPython/ethereum/berlin/vm/exceptions.v | 162 + .../berlin/vm/instructions/__init__.v | 87 + .../berlin/vm/instructions/arithmetic.v | 1085 +++++++ .../ethereum/berlin/vm/instructions/bitwise.v | 601 ++++ .../ethereum/berlin/vm/instructions/block.v | 379 +++ .../berlin/vm/instructions/comparison.v | 404 +++ .../berlin/vm/instructions/control_flow.v | 336 ++ .../berlin/vm/instructions/environment.v | 1394 +++++++++ .../ethereum/berlin/vm/instructions/keccak.v | 181 ++ .../ethereum/berlin/vm/instructions/log.v | 244 ++ .../ethereum/berlin/vm/instructions/memory.v | 378 +++ .../ethereum/berlin/vm/instructions/stack.v | 929 ++++++ .../ethereum/berlin/vm/instructions/storage.v | 437 +++ CoqOfPython/ethereum/berlin/vm/interpreter.v | 643 ++++ CoqOfPython/ethereum/berlin/vm/memory.v | 153 + .../vm/precompiled_contracts/__init__.v | 117 + .../vm/precompiled_contracts/alt_bn128.v | 673 ++++ .../berlin/vm/precompiled_contracts/blake2f.v | 122 + .../vm/precompiled_contracts/ecrecover.v | 269 ++ .../vm/precompiled_contracts/identity.v | 94 + .../berlin/vm/precompiled_contracts/mapping.v | 82 + .../berlin/vm/precompiled_contracts/modexp.v | 608 ++++ .../vm/precompiled_contracts/ripemd160.v | 122 + .../berlin/vm/precompiled_contracts/sha256.v | 106 + CoqOfPython/ethereum/berlin/vm/runtime.v | 125 + CoqOfPython/ethereum/berlin/vm/stack.v | 120 + CoqOfPython/ethereum/byzantium/__init__.v | 24 + CoqOfPython/ethereum/byzantium/blocks.v | 93 + CoqOfPython/ethereum/byzantium/bloom.v | 164 + CoqOfPython/ethereum/byzantium/fork_types.v | 102 + CoqOfPython/ethereum/byzantium/state.v | 1031 ++++++ CoqOfPython/ethereum/byzantium/transactions.v | 60 + CoqOfPython/ethereum/byzantium/trie.v | 1357 ++++++++ .../ethereum/byzantium/utils/__init__.v | 8 + .../ethereum/byzantium/utils/address.v | 134 + .../ethereum/byzantium/utils/hexadecimal.v | 155 + .../ethereum/byzantium/utils/message.v | 201 ++ CoqOfPython/ethereum/byzantium/vm/__init__.v | 244 ++ .../ethereum/byzantium/vm/exceptions.v | 152 + .../byzantium/vm/instructions/__init__.v | 87 + .../byzantium/vm/instructions/arithmetic.v | 1085 +++++++ .../byzantium/vm/instructions/bitwise.v | 345 ++ .../byzantium/vm/instructions/block.v | 337 ++ .../byzantium/vm/instructions/comparison.v | 404 +++ .../byzantium/vm/instructions/control_flow.v | 336 ++ .../byzantium/vm/instructions/environment.v | 1140 +++++++ .../byzantium/vm/instructions/keccak.v | 181 ++ .../ethereum/byzantium/vm/instructions/log.v | 244 ++ .../byzantium/vm/instructions/memory.v | 378 +++ .../byzantium/vm/instructions/stack.v | 929 ++++++ .../byzantium/vm/instructions/storage.v | 228 ++ .../ethereum/byzantium/vm/interpreter.v | 627 ++++ CoqOfPython/ethereum/byzantium/vm/memory.v | 153 + .../vm/precompiled_contracts/__init__.v | 107 + .../vm/precompiled_contracts/alt_bn128.v | 673 ++++ .../vm/precompiled_contracts/ecrecover.v | 269 ++ .../vm/precompiled_contracts/identity.v | 94 + .../vm/precompiled_contracts/mapping.v | 76 + .../vm/precompiled_contracts/modexp.v | 506 +++ .../vm/precompiled_contracts/ripemd160.v | 122 + .../vm/precompiled_contracts/sha256.v | 106 + CoqOfPython/ethereum/byzantium/vm/runtime.v | 125 + CoqOfPython/ethereum/byzantium/vm/stack.v | 120 + CoqOfPython/ethereum/cancun/__init__.v | 25 + CoqOfPython/ethereum/cancun/blocks.v | 107 + CoqOfPython/ethereum/cancun/bloom.v | 164 + CoqOfPython/ethereum/cancun/fork.v | 2788 +++++++++++++++++ CoqOfPython/ethereum/cancun/fork_types.v | 106 + CoqOfPython/ethereum/cancun/state.v | 1403 +++++++++ CoqOfPython/ethereum/cancun/transactions.v | 337 ++ CoqOfPython/ethereum/cancun/trie.v | 1360 ++++++++ CoqOfPython/ethereum/cancun/utils/__init__.v | 8 + CoqOfPython/ethereum/cancun/utils/address.v | 204 ++ .../ethereum/cancun/utils/hexadecimal.v | 155 + CoqOfPython/ethereum/cancun/utils/message.v | 254 ++ CoqOfPython/ethereum/cancun/vm/__init__.v | 266 ++ CoqOfPython/ethereum/cancun/vm/exceptions.v | 182 ++ .../cancun/vm/instructions/__init__.v | 87 + .../cancun/vm/instructions/arithmetic.v | 1085 +++++++ .../ethereum/cancun/vm/instructions/bitwise.v | 601 ++++ .../ethereum/cancun/vm/instructions/block.v | 421 +++ .../cancun/vm/instructions/comparison.v | 404 +++ .../cancun/vm/instructions/control_flow.v | 336 ++ .../cancun/vm/instructions/environment.v | 1571 ++++++++++ .../ethereum/cancun/vm/instructions/keccak.v | 181 ++ .../ethereum/cancun/vm/instructions/log.v | 244 ++ .../ethereum/cancun/vm/instructions/memory.v | 504 +++ .../ethereum/cancun/vm/instructions/stack.v | 958 ++++++ .../ethereum/cancun/vm/instructions/storage.v | 560 ++++ CoqOfPython/ethereum/cancun/vm/interpreter.v | 652 ++++ CoqOfPython/ethereum/cancun/vm/memory.v | 153 + .../vm/precompiled_contracts/__init__.v | 127 + .../vm/precompiled_contracts/alt_bn128.v | 673 ++++ .../cancun/vm/precompiled_contracts/blake2f.v | 122 + .../vm/precompiled_contracts/ecrecover.v | 269 ++ .../vm/precompiled_contracts/identity.v | 94 + .../cancun/vm/precompiled_contracts/mapping.v | 88 + .../cancun/vm/precompiled_contracts/modexp.v | 608 ++++ .../precompiled_contracts/point_evaluation.v | 173 + .../vm/precompiled_contracts/ripemd160.v | 122 + .../cancun/vm/precompiled_contracts/sha256.v | 106 + CoqOfPython/ethereum/cancun/vm/runtime.v | 125 + CoqOfPython/ethereum/cancun/vm/stack.v | 120 + .../ethereum/constantinople/__init__.v | 24 + CoqOfPython/ethereum/constantinople/blocks.v | 93 + CoqOfPython/ethereum/constantinople/bloom.v | 164 + .../ethereum/constantinople/fork_types.v | 102 + CoqOfPython/ethereum/constantinople/state.v | 1031 ++++++ .../ethereum/constantinople/transactions.v | 60 + CoqOfPython/ethereum/constantinople/trie.v | 1357 ++++++++ .../ethereum/constantinople/utils/__init__.v | 8 + .../ethereum/constantinople/utils/address.v | 204 ++ .../constantinople/utils/hexadecimal.v | 155 + .../ethereum/constantinople/utils/message.v | 201 ++ .../ethereum/constantinople/vm/__init__.v | 244 ++ .../ethereum/constantinople/vm/exceptions.v | 152 + .../constantinople/vm/instructions/__init__.v | 87 + .../vm/instructions/arithmetic.v | 1085 +++++++ .../constantinople/vm/instructions/bitwise.v | 601 ++++ .../constantinople/vm/instructions/block.v | 337 ++ .../vm/instructions/comparison.v | 404 +++ .../vm/instructions/control_flow.v | 336 ++ .../vm/instructions/environment.v | 1239 ++++++++ .../constantinople/vm/instructions/keccak.v | 181 ++ .../constantinople/vm/instructions/log.v | 244 ++ .../constantinople/vm/instructions/memory.v | 378 +++ .../constantinople/vm/instructions/stack.v | 929 ++++++ .../constantinople/vm/instructions/storage.v | 228 ++ .../ethereum/constantinople/vm/interpreter.v | 627 ++++ .../ethereum/constantinople/vm/memory.v | 153 + .../vm/precompiled_contracts/__init__.v | 107 + .../vm/precompiled_contracts/alt_bn128.v | 673 ++++ .../vm/precompiled_contracts/ecrecover.v | 269 ++ .../vm/precompiled_contracts/identity.v | 94 + .../vm/precompiled_contracts/mapping.v | 76 + .../vm/precompiled_contracts/modexp.v | 506 +++ .../vm/precompiled_contracts/ripemd160.v | 122 + .../vm/precompiled_contracts/sha256.v | 106 + .../ethereum/constantinople/vm/runtime.v | 125 + .../ethereum/constantinople/vm/stack.v | 120 + CoqOfPython/ethereum/crypto/__init__.v | 8 + CoqOfPython/ethereum/crypto/alt_bn128.v | 677 ++++ CoqOfPython/ethereum/crypto/blake2.v | 541 ++++ CoqOfPython/ethereum/crypto/elliptic_curve.v | 669 ++++ CoqOfPython/ethereum/crypto/finite_field.v | 1929 ++++++++++++ CoqOfPython/ethereum/crypto/hash.v | 124 + CoqOfPython/ethereum/dao_fork/__init__.v | 24 + CoqOfPython/ethereum/dao_fork/blocks.v | 93 + CoqOfPython/ethereum/dao_fork/bloom.v | 164 + CoqOfPython/ethereum/dao_fork/dao.v | 87 + CoqOfPython/ethereum/dao_fork/fork.v | 2153 +++++++++++++ CoqOfPython/ethereum/dao_fork/fork_types.v | 102 + CoqOfPython/ethereum/dao_fork/state.v | 865 +++++ CoqOfPython/ethereum/dao_fork/transactions.v | 60 + CoqOfPython/ethereum/dao_fork/trie.v | 1357 ++++++++ .../ethereum/dao_fork/utils/__init__.v | 8 + CoqOfPython/ethereum/dao_fork/utils/address.v | 133 + .../ethereum/dao_fork/utils/hexadecimal.v | 155 + CoqOfPython/ethereum/dao_fork/utils/message.v | 197 ++ CoqOfPython/ethereum/dao_fork/vm/__init__.v | 145 + CoqOfPython/ethereum/dao_fork/vm/exceptions.v | 122 + .../dao_fork/vm/instructions/__init__.v | 87 + .../dao_fork/vm/instructions/arithmetic.v | 1085 +++++++ .../dao_fork/vm/instructions/bitwise.v | 345 ++ .../ethereum/dao_fork/vm/instructions/block.v | 337 ++ .../dao_fork/vm/instructions/comparison.v | 404 +++ .../dao_fork/vm/instructions/control_flow.v | 336 ++ .../dao_fork/vm/instructions/environment.v | 943 ++++++ .../dao_fork/vm/instructions/keccak.v | 181 ++ .../ethereum/dao_fork/vm/instructions/log.v | 228 ++ .../dao_fork/vm/instructions/memory.v | 378 +++ .../ethereum/dao_fork/vm/instructions/stack.v | 929 ++++++ .../dao_fork/vm/instructions/storage.v | 212 ++ .../dao_fork/vm/instructions/system.v | 1245 ++++++++ .../ethereum/dao_fork/vm/interpreter.v | 543 ++++ CoqOfPython/ethereum/dao_fork/vm/memory.v | 153 + .../vm/precompiled_contracts/__init__.v | 67 + .../vm/precompiled_contracts/ecrecover.v | 269 ++ .../vm/precompiled_contracts/identity.v | 94 + .../vm/precompiled_contracts/mapping.v | 56 + .../vm/precompiled_contracts/ripemd160.v | 122 + .../vm/precompiled_contracts/sha256.v | 106 + CoqOfPython/ethereum/dao_fork/vm/runtime.v | 125 + CoqOfPython/ethereum/dao_fork/vm/stack.v | 120 + CoqOfPython/ethereum/ethash.v | 1069 +++++++ CoqOfPython/ethereum/exceptions.v | 58 + CoqOfPython/ethereum/fork_criteria.v | 263 ++ CoqOfPython/ethereum/frontier/__init__.v | 22 + CoqOfPython/ethereum/frontier/blocks.v | 93 + CoqOfPython/ethereum/frontier/bloom.v | 164 + CoqOfPython/ethereum/frontier/fork.v | 2046 ++++++++++++ CoqOfPython/ethereum/frontier/fork_types.v | 102 + CoqOfPython/ethereum/frontier/state.v | 865 +++++ CoqOfPython/ethereum/frontier/transactions.v | 56 + CoqOfPython/ethereum/frontier/trie.v | 1350 ++++++++ .../ethereum/frontier/utils/__init__.v | 8 + CoqOfPython/ethereum/frontier/utils/address.v | 133 + .../ethereum/frontier/utils/hexadecimal.v | 155 + CoqOfPython/ethereum/frontier/utils/message.v | 195 ++ CoqOfPython/ethereum/frontier/vm/__init__.v | 152 + CoqOfPython/ethereum/frontier/vm/exceptions.v | 122 + .../frontier/vm/instructions/__init__.v | 87 + .../frontier/vm/instructions/arithmetic.v | 1085 +++++++ .../frontier/vm/instructions/bitwise.v | 345 ++ .../ethereum/frontier/vm/instructions/block.v | 337 ++ .../frontier/vm/instructions/comparison.v | 404 +++ .../frontier/vm/instructions/control_flow.v | 336 ++ .../frontier/vm/instructions/environment.v | 943 ++++++ .../frontier/vm/instructions/keccak.v | 181 ++ .../ethereum/frontier/vm/instructions/log.v | 228 ++ .../frontier/vm/instructions/memory.v | 378 +++ .../ethereum/frontier/vm/instructions/stack.v | 929 ++++++ .../frontier/vm/instructions/storage.v | 212 ++ .../frontier/vm/instructions/system.v | 1112 +++++++ .../ethereum/frontier/vm/interpreter.v | 553 ++++ CoqOfPython/ethereum/frontier/vm/memory.v | 153 + .../vm/precompiled_contracts/__init__.v | 67 + .../vm/precompiled_contracts/ecrecover.v | 269 ++ .../vm/precompiled_contracts/identity.v | 94 + .../vm/precompiled_contracts/mapping.v | 56 + .../vm/precompiled_contracts/ripemd160.v | 122 + .../vm/precompiled_contracts/sha256.v | 106 + CoqOfPython/ethereum/frontier/vm/runtime.v | 125 + CoqOfPython/ethereum/frontier/vm/stack.v | 120 + CoqOfPython/ethereum/genesis.v | 524 ++++ CoqOfPython/ethereum/gray_glacier/__init__.v | 23 + CoqOfPython/ethereum/gray_glacier/blocks.v | 95 + CoqOfPython/ethereum/gray_glacier/bloom.v | 164 + .../ethereum/gray_glacier/fork_types.v | 102 + CoqOfPython/ethereum/gray_glacier/state.v | 1184 +++++++ .../ethereum/gray_glacier/transactions.v | 274 ++ CoqOfPython/ethereum/gray_glacier/trie.v | 1357 ++++++++ .../ethereum/gray_glacier/utils/__init__.v | 8 + .../ethereum/gray_glacier/utils/address.v | 204 ++ .../ethereum/gray_glacier/utils/hexadecimal.v | 155 + .../ethereum/gray_glacier/utils/message.v | 254 ++ .../ethereum/gray_glacier/vm/__init__.v | 262 ++ .../ethereum/gray_glacier/vm/exceptions.v | 172 + .../gray_glacier/vm/instructions/__init__.v | 87 + .../gray_glacier/vm/instructions/arithmetic.v | 1085 +++++++ .../gray_glacier/vm/instructions/bitwise.v | 601 ++++ .../gray_glacier/vm/instructions/block.v | 379 +++ .../gray_glacier/vm/instructions/comparison.v | 404 +++ .../vm/instructions/control_flow.v | 336 ++ .../vm/instructions/environment.v | 1436 +++++++++ .../gray_glacier/vm/instructions/keccak.v | 181 ++ .../gray_glacier/vm/instructions/log.v | 244 ++ .../gray_glacier/vm/instructions/memory.v | 378 +++ .../gray_glacier/vm/instructions/stack.v | 929 ++++++ .../gray_glacier/vm/instructions/storage.v | 437 +++ .../ethereum/gray_glacier/vm/interpreter.v | 645 ++++ CoqOfPython/ethereum/gray_glacier/vm/memory.v | 153 + .../vm/precompiled_contracts/__init__.v | 117 + .../vm/precompiled_contracts/alt_bn128.v | 673 ++++ .../vm/precompiled_contracts/blake2f.v | 122 + .../vm/precompiled_contracts/ecrecover.v | 269 ++ .../vm/precompiled_contracts/identity.v | 94 + .../vm/precompiled_contracts/mapping.v | 82 + .../vm/precompiled_contracts/modexp.v | 608 ++++ .../vm/precompiled_contracts/ripemd160.v | 122 + .../vm/precompiled_contracts/sha256.v | 106 + .../ethereum/gray_glacier/vm/runtime.v | 125 + CoqOfPython/ethereum/gray_glacier/vm/stack.v | 120 + CoqOfPython/ethereum/homestead/__init__.v | 25 + CoqOfPython/ethereum/homestead/blocks.v | 93 + CoqOfPython/ethereum/homestead/bloom.v | 164 + CoqOfPython/ethereum/homestead/fork.v | 2104 +++++++++++++ CoqOfPython/ethereum/homestead/fork_types.v | 102 + CoqOfPython/ethereum/homestead/state.v | 865 +++++ CoqOfPython/ethereum/homestead/transactions.v | 60 + CoqOfPython/ethereum/homestead/trie.v | 1357 ++++++++ .../ethereum/homestead/utils/__init__.v | 8 + .../ethereum/homestead/utils/address.v | 133 + .../ethereum/homestead/utils/hexadecimal.v | 155 + .../ethereum/homestead/utils/message.v | 197 ++ CoqOfPython/ethereum/homestead/vm/__init__.v | 152 + .../ethereum/homestead/vm/exceptions.v | 122 + .../homestead/vm/instructions/__init__.v | 87 + .../homestead/vm/instructions/arithmetic.v | 1085 +++++++ .../homestead/vm/instructions/bitwise.v | 345 ++ .../homestead/vm/instructions/block.v | 337 ++ .../homestead/vm/instructions/comparison.v | 404 +++ .../homestead/vm/instructions/control_flow.v | 336 ++ .../homestead/vm/instructions/environment.v | 943 ++++++ .../homestead/vm/instructions/keccak.v | 181 ++ .../ethereum/homestead/vm/instructions/log.v | 228 ++ .../homestead/vm/instructions/memory.v | 378 +++ .../homestead/vm/instructions/stack.v | 929 ++++++ .../homestead/vm/instructions/storage.v | 212 ++ .../homestead/vm/instructions/system.v | 1245 ++++++++ .../ethereum/homestead/vm/interpreter.v | 551 ++++ CoqOfPython/ethereum/homestead/vm/memory.v | 153 + .../vm/precompiled_contracts/__init__.v | 67 + .../vm/precompiled_contracts/ecrecover.v | 269 ++ .../vm/precompiled_contracts/identity.v | 94 + .../vm/precompiled_contracts/mapping.v | 56 + .../vm/precompiled_contracts/ripemd160.v | 122 + .../vm/precompiled_contracts/sha256.v | 106 + CoqOfPython/ethereum/homestead/vm/runtime.v | 125 + CoqOfPython/ethereum/homestead/vm/stack.v | 120 + CoqOfPython/ethereum/istanbul/__init__.v | 24 + CoqOfPython/ethereum/istanbul/blocks.v | 93 + CoqOfPython/ethereum/istanbul/bloom.v | 164 + CoqOfPython/ethereum/istanbul/fork_types.v | 102 + CoqOfPython/ethereum/istanbul/state.v | 1184 +++++++ CoqOfPython/ethereum/istanbul/transactions.v | 60 + CoqOfPython/ethereum/istanbul/trie.v | 1357 ++++++++ .../ethereum/istanbul/utils/__init__.v | 8 + CoqOfPython/ethereum/istanbul/utils/address.v | 204 ++ .../ethereum/istanbul/utils/hexadecimal.v | 155 + CoqOfPython/ethereum/istanbul/utils/message.v | 201 ++ CoqOfPython/ethereum/istanbul/vm/__init__.v | 246 ++ CoqOfPython/ethereum/istanbul/vm/exceptions.v | 162 + .../istanbul/vm/instructions/__init__.v | 87 + .../istanbul/vm/instructions/arithmetic.v | 1085 +++++++ .../istanbul/vm/instructions/bitwise.v | 601 ++++ .../ethereum/istanbul/vm/instructions/block.v | 379 +++ .../istanbul/vm/instructions/comparison.v | 404 +++ .../istanbul/vm/instructions/control_flow.v | 336 ++ .../istanbul/vm/instructions/environment.v | 1286 ++++++++ .../istanbul/vm/instructions/keccak.v | 181 ++ .../ethereum/istanbul/vm/instructions/log.v | 244 ++ .../istanbul/vm/instructions/memory.v | 378 +++ .../ethereum/istanbul/vm/instructions/stack.v | 929 ++++++ .../istanbul/vm/instructions/storage.v | 364 +++ .../ethereum/istanbul/vm/interpreter.v | 643 ++++ CoqOfPython/ethereum/istanbul/vm/memory.v | 153 + .../vm/precompiled_contracts/__init__.v | 117 + .../vm/precompiled_contracts/alt_bn128.v | 673 ++++ .../vm/precompiled_contracts/blake2f.v | 122 + .../vm/precompiled_contracts/ecrecover.v | 269 ++ .../vm/precompiled_contracts/identity.v | 94 + .../vm/precompiled_contracts/mapping.v | 82 + .../vm/precompiled_contracts/modexp.v | 506 +++ .../vm/precompiled_contracts/ripemd160.v | 122 + .../vm/precompiled_contracts/sha256.v | 106 + CoqOfPython/ethereum/istanbul/vm/runtime.v | 125 + CoqOfPython/ethereum/istanbul/vm/stack.v | 120 + CoqOfPython/ethereum/london/__init__.v | 23 + CoqOfPython/ethereum/london/blocks.v | 95 + CoqOfPython/ethereum/london/bloom.v | 164 + CoqOfPython/ethereum/london/fork_types.v | 102 + CoqOfPython/ethereum/london/state.v | 1184 +++++++ CoqOfPython/ethereum/london/transactions.v | 274 ++ CoqOfPython/ethereum/london/trie.v | 1357 ++++++++ CoqOfPython/ethereum/london/utils/__init__.v | 8 + CoqOfPython/ethereum/london/utils/address.v | 204 ++ .../ethereum/london/utils/hexadecimal.v | 155 + CoqOfPython/ethereum/london/utils/message.v | 254 ++ CoqOfPython/ethereum/london/vm/__init__.v | 262 ++ CoqOfPython/ethereum/london/vm/exceptions.v | 172 + .../london/vm/instructions/__init__.v | 87 + .../london/vm/instructions/arithmetic.v | 1085 +++++++ .../ethereum/london/vm/instructions/bitwise.v | 601 ++++ .../ethereum/london/vm/instructions/block.v | 379 +++ .../london/vm/instructions/comparison.v | 404 +++ .../london/vm/instructions/control_flow.v | 336 ++ .../london/vm/instructions/environment.v | 1436 +++++++++ .../ethereum/london/vm/instructions/keccak.v | 181 ++ .../ethereum/london/vm/instructions/log.v | 244 ++ .../ethereum/london/vm/instructions/memory.v | 378 +++ .../ethereum/london/vm/instructions/stack.v | 929 ++++++ .../ethereum/london/vm/instructions/storage.v | 437 +++ CoqOfPython/ethereum/london/vm/interpreter.v | 645 ++++ CoqOfPython/ethereum/london/vm/memory.v | 153 + .../vm/precompiled_contracts/__init__.v | 117 + .../vm/precompiled_contracts/alt_bn128.v | 673 ++++ .../london/vm/precompiled_contracts/blake2f.v | 122 + .../vm/precompiled_contracts/ecrecover.v | 269 ++ .../vm/precompiled_contracts/identity.v | 94 + .../london/vm/precompiled_contracts/mapping.v | 82 + .../london/vm/precompiled_contracts/modexp.v | 608 ++++ .../vm/precompiled_contracts/ripemd160.v | 122 + .../london/vm/precompiled_contracts/sha256.v | 106 + CoqOfPython/ethereum/london/vm/runtime.v | 125 + CoqOfPython/ethereum/london/vm/stack.v | 120 + CoqOfPython/ethereum/muir_glacier/__init__.v | 23 + CoqOfPython/ethereum/muir_glacier/blocks.v | 93 + CoqOfPython/ethereum/muir_glacier/bloom.v | 164 + .../ethereum/muir_glacier/fork_types.v | 102 + CoqOfPython/ethereum/muir_glacier/state.v | 1184 +++++++ .../ethereum/muir_glacier/transactions.v | 60 + CoqOfPython/ethereum/muir_glacier/trie.v | 1357 ++++++++ .../ethereum/muir_glacier/utils/__init__.v | 8 + .../ethereum/muir_glacier/utils/address.v | 204 ++ .../ethereum/muir_glacier/utils/hexadecimal.v | 155 + .../ethereum/muir_glacier/utils/message.v | 201 ++ .../ethereum/muir_glacier/vm/__init__.v | 246 ++ .../ethereum/muir_glacier/vm/exceptions.v | 162 + .../muir_glacier/vm/instructions/__init__.v | 87 + .../muir_glacier/vm/instructions/arithmetic.v | 1085 +++++++ .../muir_glacier/vm/instructions/bitwise.v | 601 ++++ .../muir_glacier/vm/instructions/block.v | 379 +++ .../muir_glacier/vm/instructions/comparison.v | 404 +++ .../vm/instructions/control_flow.v | 336 ++ .../vm/instructions/environment.v | 1286 ++++++++ .../muir_glacier/vm/instructions/keccak.v | 181 ++ .../muir_glacier/vm/instructions/log.v | 244 ++ .../muir_glacier/vm/instructions/memory.v | 378 +++ .../muir_glacier/vm/instructions/stack.v | 929 ++++++ .../muir_glacier/vm/instructions/storage.v | 364 +++ .../ethereum/muir_glacier/vm/interpreter.v | 643 ++++ CoqOfPython/ethereum/muir_glacier/vm/memory.v | 153 + .../vm/precompiled_contracts/__init__.v | 117 + .../vm/precompiled_contracts/alt_bn128.v | 673 ++++ .../vm/precompiled_contracts/blake2f.v | 122 + .../vm/precompiled_contracts/ecrecover.v | 269 ++ .../vm/precompiled_contracts/identity.v | 94 + .../vm/precompiled_contracts/mapping.v | 82 + .../vm/precompiled_contracts/modexp.v | 506 +++ .../vm/precompiled_contracts/ripemd160.v | 122 + .../vm/precompiled_contracts/sha256.v | 106 + .../ethereum/muir_glacier/vm/runtime.v | 125 + CoqOfPython/ethereum/muir_glacier/vm/stack.v | 120 + CoqOfPython/ethereum/paris/__init__.v | 27 + CoqOfPython/ethereum/paris/blocks.v | 95 + CoqOfPython/ethereum/paris/bloom.v | 164 + CoqOfPython/ethereum/paris/fork.v | 2243 +++++++++++++ CoqOfPython/ethereum/paris/fork_types.v | 102 + CoqOfPython/ethereum/paris/state.v | 1157 +++++++ CoqOfPython/ethereum/paris/transactions.v | 274 ++ CoqOfPython/ethereum/paris/trie.v | 1357 ++++++++ CoqOfPython/ethereum/paris/utils/__init__.v | 8 + CoqOfPython/ethereum/paris/utils/address.v | 204 ++ .../ethereum/paris/utils/hexadecimal.v | 155 + CoqOfPython/ethereum/paris/utils/message.v | 254 ++ CoqOfPython/ethereum/paris/vm/__init__.v | 262 ++ CoqOfPython/ethereum/paris/vm/exceptions.v | 172 + .../ethereum/paris/vm/instructions/__init__.v | 87 + .../paris/vm/instructions/arithmetic.v | 1230 ++++++-- .../ethereum/paris/vm/instructions/bitwise.v | 601 ++++ .../ethereum/paris/vm/instructions/block.v | 421 +++ .../paris/vm/instructions/comparison.v | 404 +++ .../paris/vm/instructions/control_flow.v | 336 ++ .../paris/vm/instructions/environment.v | 1436 +++++++++ .../ethereum/paris/vm/instructions/keccak.v | 181 ++ .../ethereum/paris/vm/instructions/log.v | 244 ++ .../ethereum/paris/vm/instructions/memory.v | 378 +++ .../ethereum/paris/vm/instructions/stack.v | 929 ++++++ .../ethereum/paris/vm/instructions/storage.v | 437 +++ CoqOfPython/ethereum/paris/vm/interpreter.v | 647 ++++ CoqOfPython/ethereum/paris/vm/memory.v | 153 + .../paris/vm/precompiled_contracts/__init__.v | 117 + .../vm/precompiled_contracts/alt_bn128.v | 673 ++++ .../paris/vm/precompiled_contracts/blake2f.v | 122 + .../vm/precompiled_contracts/ecrecover.v | 269 ++ .../paris/vm/precompiled_contracts/identity.v | 94 + .../paris/vm/precompiled_contracts/mapping.v | 82 + .../paris/vm/precompiled_contracts/modexp.v | 608 ++++ .../vm/precompiled_contracts/ripemd160.v | 122 + .../paris/vm/precompiled_contracts/sha256.v | 106 + CoqOfPython/ethereum/paris/vm/runtime.v | 125 + CoqOfPython/ethereum/paris/vm/stack.v | 120 + CoqOfPython/ethereum/rlp.v | 2060 ++++++++++++ CoqOfPython/ethereum/shanghai/__init__.v | 24 + CoqOfPython/ethereum/shanghai/blocks.v | 107 + CoqOfPython/ethereum/shanghai/bloom.v | 164 + CoqOfPython/ethereum/shanghai/fork.v | 2432 ++++++++++++++ CoqOfPython/ethereum/shanghai/fork_types.v | 102 + CoqOfPython/ethereum/shanghai/state.v | 1179 +++++++ CoqOfPython/ethereum/shanghai/transactions.v | 274 ++ CoqOfPython/ethereum/shanghai/trie.v | 1360 ++++++++ .../ethereum/shanghai/utils/__init__.v | 8 + CoqOfPython/ethereum/shanghai/utils/address.v | 204 ++ .../ethereum/shanghai/utils/hexadecimal.v | 155 + CoqOfPython/ethereum/shanghai/utils/message.v | 254 ++ CoqOfPython/ethereum/shanghai/vm/__init__.v | 262 ++ CoqOfPython/ethereum/shanghai/vm/exceptions.v | 172 + .../shanghai/vm/instructions/__init__.v | 87 + .../shanghai/vm/instructions/arithmetic.v | 1085 +++++++ .../shanghai/vm/instructions/bitwise.v | 601 ++++ .../ethereum/shanghai/vm/instructions/block.v | 421 +++ .../shanghai/vm/instructions/comparison.v | 404 +++ .../shanghai/vm/instructions/control_flow.v | 336 ++ .../shanghai/vm/instructions/environment.v | 1436 +++++++++ .../shanghai/vm/instructions/keccak.v | 181 ++ .../ethereum/shanghai/vm/instructions/log.v | 244 ++ .../shanghai/vm/instructions/memory.v | 378 +++ .../ethereum/shanghai/vm/instructions/stack.v | 958 ++++++ .../shanghai/vm/instructions/storage.v | 437 +++ .../ethereum/shanghai/vm/interpreter.v | 647 ++++ CoqOfPython/ethereum/shanghai/vm/memory.v | 153 + .../vm/precompiled_contracts/__init__.v | 117 + .../vm/precompiled_contracts/alt_bn128.v | 673 ++++ .../vm/precompiled_contracts/blake2f.v | 122 + .../vm/precompiled_contracts/ecrecover.v | 269 ++ .../vm/precompiled_contracts/identity.v | 94 + .../vm/precompiled_contracts/mapping.v | 82 + .../vm/precompiled_contracts/modexp.v | 608 ++++ .../vm/precompiled_contracts/ripemd160.v | 122 + .../vm/precompiled_contracts/sha256.v | 106 + CoqOfPython/ethereum/shanghai/vm/runtime.v | 125 + CoqOfPython/ethereum/shanghai/vm/stack.v | 120 + .../ethereum/spurious_dragon/__init__.v | 26 + CoqOfPython/ethereum/spurious_dragon/blocks.v | 93 + CoqOfPython/ethereum/spurious_dragon/bloom.v | 164 + CoqOfPython/ethereum/spurious_dragon/fork.v | 2278 ++++++++++++++ .../ethereum/spurious_dragon/fork_types.v | 102 + CoqOfPython/ethereum/spurious_dragon/state.v | 1031 ++++++ .../ethereum/spurious_dragon/transactions.v | 60 + CoqOfPython/ethereum/spurious_dragon/trie.v | 1357 ++++++++ .../ethereum/spurious_dragon/utils/__init__.v | 8 + .../ethereum/spurious_dragon/utils/address.v | 134 + .../spurious_dragon/utils/hexadecimal.v | 155 + .../ethereum/spurious_dragon/utils/message.v | 198 ++ .../ethereum/spurious_dragon/vm/__init__.v | 244 ++ .../ethereum/spurious_dragon/vm/exceptions.v | 122 + .../vm/instructions/__init__.v | 87 + .../vm/instructions/arithmetic.v | 1085 +++++++ .../spurious_dragon/vm/instructions/bitwise.v | 345 ++ .../spurious_dragon/vm/instructions/block.v | 337 ++ .../vm/instructions/comparison.v | 404 +++ .../vm/instructions/control_flow.v | 336 ++ .../vm/instructions/environment.v | 943 ++++++ .../spurious_dragon/vm/instructions/keccak.v | 181 ++ .../spurious_dragon/vm/instructions/log.v | 228 ++ .../spurious_dragon/vm/instructions/memory.v | 378 +++ .../spurious_dragon/vm/instructions/stack.v | 929 ++++++ .../spurious_dragon/vm/instructions/storage.v | 212 ++ .../ethereum/spurious_dragon/vm/interpreter.v | 625 ++++ .../ethereum/spurious_dragon/vm/memory.v | 153 + .../vm/precompiled_contracts/__init__.v | 67 + .../vm/precompiled_contracts/ecrecover.v | 269 ++ .../vm/precompiled_contracts/identity.v | 94 + .../vm/precompiled_contracts/mapping.v | 56 + .../vm/precompiled_contracts/ripemd160.v | 122 + .../vm/precompiled_contracts/sha256.v | 106 + .../ethereum/spurious_dragon/vm/runtime.v | 125 + .../ethereum/spurious_dragon/vm/stack.v | 120 + .../ethereum/tangerine_whistle/__init__.v | 25 + .../ethereum/tangerine_whistle/blocks.v | 93 + .../ethereum/tangerine_whistle/bloom.v | 164 + CoqOfPython/ethereum/tangerine_whistle/fork.v | 2104 +++++++++++++ .../ethereum/tangerine_whistle/fork_types.v | 102 + .../ethereum/tangerine_whistle/state.v | 865 +++++ .../ethereum/tangerine_whistle/transactions.v | 60 + CoqOfPython/ethereum/tangerine_whistle/trie.v | 1357 ++++++++ .../tangerine_whistle/utils/__init__.v | 8 + .../tangerine_whistle/utils/address.v | 134 + .../tangerine_whistle/utils/hexadecimal.v | 155 + .../tangerine_whistle/utils/message.v | 198 ++ .../ethereum/tangerine_whistle/vm/__init__.v | 152 + .../tangerine_whistle/vm/exceptions.v | 122 + .../vm/instructions/__init__.v | 87 + .../vm/instructions/arithmetic.v | 1085 +++++++ .../vm/instructions/bitwise.v | 345 ++ .../tangerine_whistle/vm/instructions/block.v | 337 ++ .../vm/instructions/comparison.v | 404 +++ .../vm/instructions/control_flow.v | 336 ++ .../vm/instructions/environment.v | 943 ++++++ .../vm/instructions/keccak.v | 181 ++ .../tangerine_whistle/vm/instructions/log.v | 228 ++ .../vm/instructions/memory.v | 378 +++ .../tangerine_whistle/vm/instructions/stack.v | 929 ++++++ .../vm/instructions/storage.v | 212 ++ .../tangerine_whistle/vm/interpreter.v | 551 ++++ .../ethereum/tangerine_whistle/vm/memory.v | 153 + .../vm/precompiled_contracts/__init__.v | 67 + .../vm/precompiled_contracts/ecrecover.v | 269 ++ .../vm/precompiled_contracts/identity.v | 94 + .../vm/precompiled_contracts/mapping.v | 56 + .../vm/precompiled_contracts/ripemd160.v | 122 + .../vm/precompiled_contracts/sha256.v | 106 + .../ethereum/tangerine_whistle/vm/runtime.v | 125 + .../ethereum/tangerine_whistle/vm/stack.v | 120 + CoqOfPython/ethereum/trace.v | 135 + CoqOfPython/ethereum/utils/__init__.v | 8 + CoqOfPython/ethereum/utils/byte.v | 82 + CoqOfPython/ethereum/utils/ensure.v | 57 + CoqOfPython/ethereum/utils/hexadecimal.v | 491 +++ CoqOfPython/ethereum/utils/numeric.v | 423 +++ CoqOfPython/ethereum/utils/safe_arithmetic.v | 96 + convert_all.py | 14 +- main.py | 6 + 626 files changed, 234944 insertions(+), 260 deletions(-) create mode 100644 CoqOfPython/ethereum/__init__.v create mode 100644 CoqOfPython/ethereum/arrow_glacier/__init__.v create mode 100644 CoqOfPython/ethereum/arrow_glacier/blocks.v create mode 100644 CoqOfPython/ethereum/arrow_glacier/bloom.v create mode 100644 CoqOfPython/ethereum/arrow_glacier/fork_types.v create mode 100644 CoqOfPython/ethereum/arrow_glacier/state.v create mode 100644 CoqOfPython/ethereum/arrow_glacier/transactions.v create mode 100644 CoqOfPython/ethereum/arrow_glacier/trie.v create mode 100644 CoqOfPython/ethereum/arrow_glacier/utils/__init__.v create mode 100644 CoqOfPython/ethereum/arrow_glacier/utils/address.v create mode 100644 CoqOfPython/ethereum/arrow_glacier/utils/hexadecimal.v create mode 100644 CoqOfPython/ethereum/arrow_glacier/utils/message.v create mode 100644 CoqOfPython/ethereum/arrow_glacier/vm/__init__.v create mode 100644 CoqOfPython/ethereum/arrow_glacier/vm/exceptions.v create mode 100644 CoqOfPython/ethereum/arrow_glacier/vm/instructions/__init__.v create mode 100644 CoqOfPython/ethereum/arrow_glacier/vm/instructions/arithmetic.v create mode 100644 CoqOfPython/ethereum/arrow_glacier/vm/instructions/bitwise.v create mode 100644 CoqOfPython/ethereum/arrow_glacier/vm/instructions/block.v create mode 100644 CoqOfPython/ethereum/arrow_glacier/vm/instructions/comparison.v create mode 100644 CoqOfPython/ethereum/arrow_glacier/vm/instructions/control_flow.v create mode 100644 CoqOfPython/ethereum/arrow_glacier/vm/instructions/environment.v create mode 100644 CoqOfPython/ethereum/arrow_glacier/vm/instructions/keccak.v create mode 100644 CoqOfPython/ethereum/arrow_glacier/vm/instructions/log.v create mode 100644 CoqOfPython/ethereum/arrow_glacier/vm/instructions/memory.v create mode 100644 CoqOfPython/ethereum/arrow_glacier/vm/instructions/stack.v create mode 100644 CoqOfPython/ethereum/arrow_glacier/vm/instructions/storage.v create mode 100644 CoqOfPython/ethereum/arrow_glacier/vm/interpreter.v create mode 100644 CoqOfPython/ethereum/arrow_glacier/vm/memory.v create mode 100644 CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/__init__.v create mode 100644 CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/alt_bn128.v create mode 100644 CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/blake2f.v create mode 100644 CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/ecrecover.v create mode 100644 CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/identity.v create mode 100644 CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/mapping.v create mode 100644 CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/modexp.v create mode 100644 CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/ripemd160.v create mode 100644 CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/sha256.v create mode 100644 CoqOfPython/ethereum/arrow_glacier/vm/runtime.v create mode 100644 CoqOfPython/ethereum/arrow_glacier/vm/stack.v create mode 100644 CoqOfPython/ethereum/berlin/__init__.v create mode 100644 CoqOfPython/ethereum/berlin/blocks.v create mode 100644 CoqOfPython/ethereum/berlin/bloom.v create mode 100644 CoqOfPython/ethereum/berlin/fork_types.v create mode 100644 CoqOfPython/ethereum/berlin/state.v create mode 100644 CoqOfPython/ethereum/berlin/transactions.v create mode 100644 CoqOfPython/ethereum/berlin/trie.v create mode 100644 CoqOfPython/ethereum/berlin/utils/__init__.v create mode 100644 CoqOfPython/ethereum/berlin/utils/address.v create mode 100644 CoqOfPython/ethereum/berlin/utils/hexadecimal.v create mode 100644 CoqOfPython/ethereum/berlin/utils/message.v create mode 100644 CoqOfPython/ethereum/berlin/vm/__init__.v create mode 100644 CoqOfPython/ethereum/berlin/vm/exceptions.v create mode 100644 CoqOfPython/ethereum/berlin/vm/instructions/__init__.v create mode 100644 CoqOfPython/ethereum/berlin/vm/instructions/arithmetic.v create mode 100644 CoqOfPython/ethereum/berlin/vm/instructions/bitwise.v create mode 100644 CoqOfPython/ethereum/berlin/vm/instructions/block.v create mode 100644 CoqOfPython/ethereum/berlin/vm/instructions/comparison.v create mode 100644 CoqOfPython/ethereum/berlin/vm/instructions/control_flow.v create mode 100644 CoqOfPython/ethereum/berlin/vm/instructions/environment.v create mode 100644 CoqOfPython/ethereum/berlin/vm/instructions/keccak.v create mode 100644 CoqOfPython/ethereum/berlin/vm/instructions/log.v create mode 100644 CoqOfPython/ethereum/berlin/vm/instructions/memory.v create mode 100644 CoqOfPython/ethereum/berlin/vm/instructions/stack.v create mode 100644 CoqOfPython/ethereum/berlin/vm/instructions/storage.v create mode 100644 CoqOfPython/ethereum/berlin/vm/interpreter.v create mode 100644 CoqOfPython/ethereum/berlin/vm/memory.v create mode 100644 CoqOfPython/ethereum/berlin/vm/precompiled_contracts/__init__.v create mode 100644 CoqOfPython/ethereum/berlin/vm/precompiled_contracts/alt_bn128.v create mode 100644 CoqOfPython/ethereum/berlin/vm/precompiled_contracts/blake2f.v create mode 100644 CoqOfPython/ethereum/berlin/vm/precompiled_contracts/ecrecover.v create mode 100644 CoqOfPython/ethereum/berlin/vm/precompiled_contracts/identity.v create mode 100644 CoqOfPython/ethereum/berlin/vm/precompiled_contracts/mapping.v create mode 100644 CoqOfPython/ethereum/berlin/vm/precompiled_contracts/modexp.v create mode 100644 CoqOfPython/ethereum/berlin/vm/precompiled_contracts/ripemd160.v create mode 100644 CoqOfPython/ethereum/berlin/vm/precompiled_contracts/sha256.v create mode 100644 CoqOfPython/ethereum/berlin/vm/runtime.v create mode 100644 CoqOfPython/ethereum/berlin/vm/stack.v create mode 100644 CoqOfPython/ethereum/byzantium/__init__.v create mode 100644 CoqOfPython/ethereum/byzantium/blocks.v create mode 100644 CoqOfPython/ethereum/byzantium/bloom.v create mode 100644 CoqOfPython/ethereum/byzantium/fork_types.v create mode 100644 CoqOfPython/ethereum/byzantium/state.v create mode 100644 CoqOfPython/ethereum/byzantium/transactions.v create mode 100644 CoqOfPython/ethereum/byzantium/trie.v create mode 100644 CoqOfPython/ethereum/byzantium/utils/__init__.v create mode 100644 CoqOfPython/ethereum/byzantium/utils/address.v create mode 100644 CoqOfPython/ethereum/byzantium/utils/hexadecimal.v create mode 100644 CoqOfPython/ethereum/byzantium/utils/message.v create mode 100644 CoqOfPython/ethereum/byzantium/vm/__init__.v create mode 100644 CoqOfPython/ethereum/byzantium/vm/exceptions.v create mode 100644 CoqOfPython/ethereum/byzantium/vm/instructions/__init__.v create mode 100644 CoqOfPython/ethereum/byzantium/vm/instructions/arithmetic.v create mode 100644 CoqOfPython/ethereum/byzantium/vm/instructions/bitwise.v create mode 100644 CoqOfPython/ethereum/byzantium/vm/instructions/block.v create mode 100644 CoqOfPython/ethereum/byzantium/vm/instructions/comparison.v create mode 100644 CoqOfPython/ethereum/byzantium/vm/instructions/control_flow.v create mode 100644 CoqOfPython/ethereum/byzantium/vm/instructions/environment.v create mode 100644 CoqOfPython/ethereum/byzantium/vm/instructions/keccak.v create mode 100644 CoqOfPython/ethereum/byzantium/vm/instructions/log.v create mode 100644 CoqOfPython/ethereum/byzantium/vm/instructions/memory.v create mode 100644 CoqOfPython/ethereum/byzantium/vm/instructions/stack.v create mode 100644 CoqOfPython/ethereum/byzantium/vm/instructions/storage.v create mode 100644 CoqOfPython/ethereum/byzantium/vm/interpreter.v create mode 100644 CoqOfPython/ethereum/byzantium/vm/memory.v create mode 100644 CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/__init__.v create mode 100644 CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/alt_bn128.v create mode 100644 CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/ecrecover.v create mode 100644 CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/identity.v create mode 100644 CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/mapping.v create mode 100644 CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/modexp.v create mode 100644 CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/ripemd160.v create mode 100644 CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/sha256.v create mode 100644 CoqOfPython/ethereum/byzantium/vm/runtime.v create mode 100644 CoqOfPython/ethereum/byzantium/vm/stack.v create mode 100644 CoqOfPython/ethereum/cancun/__init__.v create mode 100644 CoqOfPython/ethereum/cancun/blocks.v create mode 100644 CoqOfPython/ethereum/cancun/bloom.v create mode 100644 CoqOfPython/ethereum/cancun/fork.v create mode 100644 CoqOfPython/ethereum/cancun/fork_types.v create mode 100644 CoqOfPython/ethereum/cancun/state.v create mode 100644 CoqOfPython/ethereum/cancun/transactions.v create mode 100644 CoqOfPython/ethereum/cancun/trie.v create mode 100644 CoqOfPython/ethereum/cancun/utils/__init__.v create mode 100644 CoqOfPython/ethereum/cancun/utils/address.v create mode 100644 CoqOfPython/ethereum/cancun/utils/hexadecimal.v create mode 100644 CoqOfPython/ethereum/cancun/utils/message.v create mode 100644 CoqOfPython/ethereum/cancun/vm/__init__.v create mode 100644 CoqOfPython/ethereum/cancun/vm/exceptions.v create mode 100644 CoqOfPython/ethereum/cancun/vm/instructions/__init__.v create mode 100644 CoqOfPython/ethereum/cancun/vm/instructions/arithmetic.v create mode 100644 CoqOfPython/ethereum/cancun/vm/instructions/bitwise.v create mode 100644 CoqOfPython/ethereum/cancun/vm/instructions/block.v create mode 100644 CoqOfPython/ethereum/cancun/vm/instructions/comparison.v create mode 100644 CoqOfPython/ethereum/cancun/vm/instructions/control_flow.v create mode 100644 CoqOfPython/ethereum/cancun/vm/instructions/environment.v create mode 100644 CoqOfPython/ethereum/cancun/vm/instructions/keccak.v create mode 100644 CoqOfPython/ethereum/cancun/vm/instructions/log.v create mode 100644 CoqOfPython/ethereum/cancun/vm/instructions/memory.v create mode 100644 CoqOfPython/ethereum/cancun/vm/instructions/stack.v create mode 100644 CoqOfPython/ethereum/cancun/vm/instructions/storage.v create mode 100644 CoqOfPython/ethereum/cancun/vm/interpreter.v create mode 100644 CoqOfPython/ethereum/cancun/vm/memory.v create mode 100644 CoqOfPython/ethereum/cancun/vm/precompiled_contracts/__init__.v create mode 100644 CoqOfPython/ethereum/cancun/vm/precompiled_contracts/alt_bn128.v create mode 100644 CoqOfPython/ethereum/cancun/vm/precompiled_contracts/blake2f.v create mode 100644 CoqOfPython/ethereum/cancun/vm/precompiled_contracts/ecrecover.v create mode 100644 CoqOfPython/ethereum/cancun/vm/precompiled_contracts/identity.v create mode 100644 CoqOfPython/ethereum/cancun/vm/precompiled_contracts/mapping.v create mode 100644 CoqOfPython/ethereum/cancun/vm/precompiled_contracts/modexp.v create mode 100644 CoqOfPython/ethereum/cancun/vm/precompiled_contracts/point_evaluation.v create mode 100644 CoqOfPython/ethereum/cancun/vm/precompiled_contracts/ripemd160.v create mode 100644 CoqOfPython/ethereum/cancun/vm/precompiled_contracts/sha256.v create mode 100644 CoqOfPython/ethereum/cancun/vm/runtime.v create mode 100644 CoqOfPython/ethereum/cancun/vm/stack.v create mode 100644 CoqOfPython/ethereum/constantinople/__init__.v create mode 100644 CoqOfPython/ethereum/constantinople/blocks.v create mode 100644 CoqOfPython/ethereum/constantinople/bloom.v create mode 100644 CoqOfPython/ethereum/constantinople/fork_types.v create mode 100644 CoqOfPython/ethereum/constantinople/state.v create mode 100644 CoqOfPython/ethereum/constantinople/transactions.v create mode 100644 CoqOfPython/ethereum/constantinople/trie.v create mode 100644 CoqOfPython/ethereum/constantinople/utils/__init__.v create mode 100644 CoqOfPython/ethereum/constantinople/utils/address.v create mode 100644 CoqOfPython/ethereum/constantinople/utils/hexadecimal.v create mode 100644 CoqOfPython/ethereum/constantinople/utils/message.v create mode 100644 CoqOfPython/ethereum/constantinople/vm/__init__.v create mode 100644 CoqOfPython/ethereum/constantinople/vm/exceptions.v create mode 100644 CoqOfPython/ethereum/constantinople/vm/instructions/__init__.v create mode 100644 CoqOfPython/ethereum/constantinople/vm/instructions/arithmetic.v create mode 100644 CoqOfPython/ethereum/constantinople/vm/instructions/bitwise.v create mode 100644 CoqOfPython/ethereum/constantinople/vm/instructions/block.v create mode 100644 CoqOfPython/ethereum/constantinople/vm/instructions/comparison.v create mode 100644 CoqOfPython/ethereum/constantinople/vm/instructions/control_flow.v create mode 100644 CoqOfPython/ethereum/constantinople/vm/instructions/environment.v create mode 100644 CoqOfPython/ethereum/constantinople/vm/instructions/keccak.v create mode 100644 CoqOfPython/ethereum/constantinople/vm/instructions/log.v create mode 100644 CoqOfPython/ethereum/constantinople/vm/instructions/memory.v create mode 100644 CoqOfPython/ethereum/constantinople/vm/instructions/stack.v create mode 100644 CoqOfPython/ethereum/constantinople/vm/instructions/storage.v create mode 100644 CoqOfPython/ethereum/constantinople/vm/interpreter.v create mode 100644 CoqOfPython/ethereum/constantinople/vm/memory.v create mode 100644 CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/__init__.v create mode 100644 CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/alt_bn128.v create mode 100644 CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/ecrecover.v create mode 100644 CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/identity.v create mode 100644 CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/mapping.v create mode 100644 CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/modexp.v create mode 100644 CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/ripemd160.v create mode 100644 CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/sha256.v create mode 100644 CoqOfPython/ethereum/constantinople/vm/runtime.v create mode 100644 CoqOfPython/ethereum/constantinople/vm/stack.v create mode 100644 CoqOfPython/ethereum/crypto/__init__.v create mode 100644 CoqOfPython/ethereum/crypto/alt_bn128.v create mode 100644 CoqOfPython/ethereum/crypto/blake2.v create mode 100644 CoqOfPython/ethereum/crypto/elliptic_curve.v create mode 100644 CoqOfPython/ethereum/crypto/finite_field.v create mode 100644 CoqOfPython/ethereum/crypto/hash.v create mode 100644 CoqOfPython/ethereum/dao_fork/__init__.v create mode 100644 CoqOfPython/ethereum/dao_fork/blocks.v create mode 100644 CoqOfPython/ethereum/dao_fork/bloom.v create mode 100644 CoqOfPython/ethereum/dao_fork/dao.v create mode 100644 CoqOfPython/ethereum/dao_fork/fork.v create mode 100644 CoqOfPython/ethereum/dao_fork/fork_types.v create mode 100644 CoqOfPython/ethereum/dao_fork/state.v create mode 100644 CoqOfPython/ethereum/dao_fork/transactions.v create mode 100644 CoqOfPython/ethereum/dao_fork/trie.v create mode 100644 CoqOfPython/ethereum/dao_fork/utils/__init__.v create mode 100644 CoqOfPython/ethereum/dao_fork/utils/address.v create mode 100644 CoqOfPython/ethereum/dao_fork/utils/hexadecimal.v create mode 100644 CoqOfPython/ethereum/dao_fork/utils/message.v create mode 100644 CoqOfPython/ethereum/dao_fork/vm/__init__.v create mode 100644 CoqOfPython/ethereum/dao_fork/vm/exceptions.v create mode 100644 CoqOfPython/ethereum/dao_fork/vm/instructions/__init__.v create mode 100644 CoqOfPython/ethereum/dao_fork/vm/instructions/arithmetic.v create mode 100644 CoqOfPython/ethereum/dao_fork/vm/instructions/bitwise.v create mode 100644 CoqOfPython/ethereum/dao_fork/vm/instructions/block.v create mode 100644 CoqOfPython/ethereum/dao_fork/vm/instructions/comparison.v create mode 100644 CoqOfPython/ethereum/dao_fork/vm/instructions/control_flow.v create mode 100644 CoqOfPython/ethereum/dao_fork/vm/instructions/environment.v create mode 100644 CoqOfPython/ethereum/dao_fork/vm/instructions/keccak.v create mode 100644 CoqOfPython/ethereum/dao_fork/vm/instructions/log.v create mode 100644 CoqOfPython/ethereum/dao_fork/vm/instructions/memory.v create mode 100644 CoqOfPython/ethereum/dao_fork/vm/instructions/stack.v create mode 100644 CoqOfPython/ethereum/dao_fork/vm/instructions/storage.v create mode 100644 CoqOfPython/ethereum/dao_fork/vm/instructions/system.v create mode 100644 CoqOfPython/ethereum/dao_fork/vm/interpreter.v create mode 100644 CoqOfPython/ethereum/dao_fork/vm/memory.v create mode 100644 CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/__init__.v create mode 100644 CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/ecrecover.v create mode 100644 CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/identity.v create mode 100644 CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/mapping.v create mode 100644 CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/ripemd160.v create mode 100644 CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/sha256.v create mode 100644 CoqOfPython/ethereum/dao_fork/vm/runtime.v create mode 100644 CoqOfPython/ethereum/dao_fork/vm/stack.v create mode 100644 CoqOfPython/ethereum/ethash.v create mode 100644 CoqOfPython/ethereum/exceptions.v create mode 100644 CoqOfPython/ethereum/fork_criteria.v create mode 100644 CoqOfPython/ethereum/frontier/__init__.v create mode 100644 CoqOfPython/ethereum/frontier/blocks.v create mode 100644 CoqOfPython/ethereum/frontier/bloom.v create mode 100644 CoqOfPython/ethereum/frontier/fork.v create mode 100644 CoqOfPython/ethereum/frontier/fork_types.v create mode 100644 CoqOfPython/ethereum/frontier/state.v create mode 100644 CoqOfPython/ethereum/frontier/transactions.v create mode 100644 CoqOfPython/ethereum/frontier/trie.v create mode 100644 CoqOfPython/ethereum/frontier/utils/__init__.v create mode 100644 CoqOfPython/ethereum/frontier/utils/address.v create mode 100644 CoqOfPython/ethereum/frontier/utils/hexadecimal.v create mode 100644 CoqOfPython/ethereum/frontier/utils/message.v create mode 100644 CoqOfPython/ethereum/frontier/vm/__init__.v create mode 100644 CoqOfPython/ethereum/frontier/vm/exceptions.v create mode 100644 CoqOfPython/ethereum/frontier/vm/instructions/__init__.v create mode 100644 CoqOfPython/ethereum/frontier/vm/instructions/arithmetic.v create mode 100644 CoqOfPython/ethereum/frontier/vm/instructions/bitwise.v create mode 100644 CoqOfPython/ethereum/frontier/vm/instructions/block.v create mode 100644 CoqOfPython/ethereum/frontier/vm/instructions/comparison.v create mode 100644 CoqOfPython/ethereum/frontier/vm/instructions/control_flow.v create mode 100644 CoqOfPython/ethereum/frontier/vm/instructions/environment.v create mode 100644 CoqOfPython/ethereum/frontier/vm/instructions/keccak.v create mode 100644 CoqOfPython/ethereum/frontier/vm/instructions/log.v create mode 100644 CoqOfPython/ethereum/frontier/vm/instructions/memory.v create mode 100644 CoqOfPython/ethereum/frontier/vm/instructions/stack.v create mode 100644 CoqOfPython/ethereum/frontier/vm/instructions/storage.v create mode 100644 CoqOfPython/ethereum/frontier/vm/instructions/system.v create mode 100644 CoqOfPython/ethereum/frontier/vm/interpreter.v create mode 100644 CoqOfPython/ethereum/frontier/vm/memory.v create mode 100644 CoqOfPython/ethereum/frontier/vm/precompiled_contracts/__init__.v create mode 100644 CoqOfPython/ethereum/frontier/vm/precompiled_contracts/ecrecover.v create mode 100644 CoqOfPython/ethereum/frontier/vm/precompiled_contracts/identity.v create mode 100644 CoqOfPython/ethereum/frontier/vm/precompiled_contracts/mapping.v create mode 100644 CoqOfPython/ethereum/frontier/vm/precompiled_contracts/ripemd160.v create mode 100644 CoqOfPython/ethereum/frontier/vm/precompiled_contracts/sha256.v create mode 100644 CoqOfPython/ethereum/frontier/vm/runtime.v create mode 100644 CoqOfPython/ethereum/frontier/vm/stack.v create mode 100644 CoqOfPython/ethereum/genesis.v create mode 100644 CoqOfPython/ethereum/gray_glacier/__init__.v create mode 100644 CoqOfPython/ethereum/gray_glacier/blocks.v create mode 100644 CoqOfPython/ethereum/gray_glacier/bloom.v create mode 100644 CoqOfPython/ethereum/gray_glacier/fork_types.v create mode 100644 CoqOfPython/ethereum/gray_glacier/state.v create mode 100644 CoqOfPython/ethereum/gray_glacier/transactions.v create mode 100644 CoqOfPython/ethereum/gray_glacier/trie.v create mode 100644 CoqOfPython/ethereum/gray_glacier/utils/__init__.v create mode 100644 CoqOfPython/ethereum/gray_glacier/utils/address.v create mode 100644 CoqOfPython/ethereum/gray_glacier/utils/hexadecimal.v create mode 100644 CoqOfPython/ethereum/gray_glacier/utils/message.v create mode 100644 CoqOfPython/ethereum/gray_glacier/vm/__init__.v create mode 100644 CoqOfPython/ethereum/gray_glacier/vm/exceptions.v create mode 100644 CoqOfPython/ethereum/gray_glacier/vm/instructions/__init__.v create mode 100644 CoqOfPython/ethereum/gray_glacier/vm/instructions/arithmetic.v create mode 100644 CoqOfPython/ethereum/gray_glacier/vm/instructions/bitwise.v create mode 100644 CoqOfPython/ethereum/gray_glacier/vm/instructions/block.v create mode 100644 CoqOfPython/ethereum/gray_glacier/vm/instructions/comparison.v create mode 100644 CoqOfPython/ethereum/gray_glacier/vm/instructions/control_flow.v create mode 100644 CoqOfPython/ethereum/gray_glacier/vm/instructions/environment.v create mode 100644 CoqOfPython/ethereum/gray_glacier/vm/instructions/keccak.v create mode 100644 CoqOfPython/ethereum/gray_glacier/vm/instructions/log.v create mode 100644 CoqOfPython/ethereum/gray_glacier/vm/instructions/memory.v create mode 100644 CoqOfPython/ethereum/gray_glacier/vm/instructions/stack.v create mode 100644 CoqOfPython/ethereum/gray_glacier/vm/instructions/storage.v create mode 100644 CoqOfPython/ethereum/gray_glacier/vm/interpreter.v create mode 100644 CoqOfPython/ethereum/gray_glacier/vm/memory.v create mode 100644 CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/__init__.v create mode 100644 CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/alt_bn128.v create mode 100644 CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/blake2f.v create mode 100644 CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/ecrecover.v create mode 100644 CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/identity.v create mode 100644 CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/mapping.v create mode 100644 CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/modexp.v create mode 100644 CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/ripemd160.v create mode 100644 CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/sha256.v create mode 100644 CoqOfPython/ethereum/gray_glacier/vm/runtime.v create mode 100644 CoqOfPython/ethereum/gray_glacier/vm/stack.v create mode 100644 CoqOfPython/ethereum/homestead/__init__.v create mode 100644 CoqOfPython/ethereum/homestead/blocks.v create mode 100644 CoqOfPython/ethereum/homestead/bloom.v create mode 100644 CoqOfPython/ethereum/homestead/fork.v create mode 100644 CoqOfPython/ethereum/homestead/fork_types.v create mode 100644 CoqOfPython/ethereum/homestead/state.v create mode 100644 CoqOfPython/ethereum/homestead/transactions.v create mode 100644 CoqOfPython/ethereum/homestead/trie.v create mode 100644 CoqOfPython/ethereum/homestead/utils/__init__.v create mode 100644 CoqOfPython/ethereum/homestead/utils/address.v create mode 100644 CoqOfPython/ethereum/homestead/utils/hexadecimal.v create mode 100644 CoqOfPython/ethereum/homestead/utils/message.v create mode 100644 CoqOfPython/ethereum/homestead/vm/__init__.v create mode 100644 CoqOfPython/ethereum/homestead/vm/exceptions.v create mode 100644 CoqOfPython/ethereum/homestead/vm/instructions/__init__.v create mode 100644 CoqOfPython/ethereum/homestead/vm/instructions/arithmetic.v create mode 100644 CoqOfPython/ethereum/homestead/vm/instructions/bitwise.v create mode 100644 CoqOfPython/ethereum/homestead/vm/instructions/block.v create mode 100644 CoqOfPython/ethereum/homestead/vm/instructions/comparison.v create mode 100644 CoqOfPython/ethereum/homestead/vm/instructions/control_flow.v create mode 100644 CoqOfPython/ethereum/homestead/vm/instructions/environment.v create mode 100644 CoqOfPython/ethereum/homestead/vm/instructions/keccak.v create mode 100644 CoqOfPython/ethereum/homestead/vm/instructions/log.v create mode 100644 CoqOfPython/ethereum/homestead/vm/instructions/memory.v create mode 100644 CoqOfPython/ethereum/homestead/vm/instructions/stack.v create mode 100644 CoqOfPython/ethereum/homestead/vm/instructions/storage.v create mode 100644 CoqOfPython/ethereum/homestead/vm/instructions/system.v create mode 100644 CoqOfPython/ethereum/homestead/vm/interpreter.v create mode 100644 CoqOfPython/ethereum/homestead/vm/memory.v create mode 100644 CoqOfPython/ethereum/homestead/vm/precompiled_contracts/__init__.v create mode 100644 CoqOfPython/ethereum/homestead/vm/precompiled_contracts/ecrecover.v create mode 100644 CoqOfPython/ethereum/homestead/vm/precompiled_contracts/identity.v create mode 100644 CoqOfPython/ethereum/homestead/vm/precompiled_contracts/mapping.v create mode 100644 CoqOfPython/ethereum/homestead/vm/precompiled_contracts/ripemd160.v create mode 100644 CoqOfPython/ethereum/homestead/vm/precompiled_contracts/sha256.v create mode 100644 CoqOfPython/ethereum/homestead/vm/runtime.v create mode 100644 CoqOfPython/ethereum/homestead/vm/stack.v create mode 100644 CoqOfPython/ethereum/istanbul/__init__.v create mode 100644 CoqOfPython/ethereum/istanbul/blocks.v create mode 100644 CoqOfPython/ethereum/istanbul/bloom.v create mode 100644 CoqOfPython/ethereum/istanbul/fork_types.v create mode 100644 CoqOfPython/ethereum/istanbul/state.v create mode 100644 CoqOfPython/ethereum/istanbul/transactions.v create mode 100644 CoqOfPython/ethereum/istanbul/trie.v create mode 100644 CoqOfPython/ethereum/istanbul/utils/__init__.v create mode 100644 CoqOfPython/ethereum/istanbul/utils/address.v create mode 100644 CoqOfPython/ethereum/istanbul/utils/hexadecimal.v create mode 100644 CoqOfPython/ethereum/istanbul/utils/message.v create mode 100644 CoqOfPython/ethereum/istanbul/vm/__init__.v create mode 100644 CoqOfPython/ethereum/istanbul/vm/exceptions.v create mode 100644 CoqOfPython/ethereum/istanbul/vm/instructions/__init__.v create mode 100644 CoqOfPython/ethereum/istanbul/vm/instructions/arithmetic.v create mode 100644 CoqOfPython/ethereum/istanbul/vm/instructions/bitwise.v create mode 100644 CoqOfPython/ethereum/istanbul/vm/instructions/block.v create mode 100644 CoqOfPython/ethereum/istanbul/vm/instructions/comparison.v create mode 100644 CoqOfPython/ethereum/istanbul/vm/instructions/control_flow.v create mode 100644 CoqOfPython/ethereum/istanbul/vm/instructions/environment.v create mode 100644 CoqOfPython/ethereum/istanbul/vm/instructions/keccak.v create mode 100644 CoqOfPython/ethereum/istanbul/vm/instructions/log.v create mode 100644 CoqOfPython/ethereum/istanbul/vm/instructions/memory.v create mode 100644 CoqOfPython/ethereum/istanbul/vm/instructions/stack.v create mode 100644 CoqOfPython/ethereum/istanbul/vm/instructions/storage.v create mode 100644 CoqOfPython/ethereum/istanbul/vm/interpreter.v create mode 100644 CoqOfPython/ethereum/istanbul/vm/memory.v create mode 100644 CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/__init__.v create mode 100644 CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/alt_bn128.v create mode 100644 CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/blake2f.v create mode 100644 CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/ecrecover.v create mode 100644 CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/identity.v create mode 100644 CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/mapping.v create mode 100644 CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/modexp.v create mode 100644 CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/ripemd160.v create mode 100644 CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/sha256.v create mode 100644 CoqOfPython/ethereum/istanbul/vm/runtime.v create mode 100644 CoqOfPython/ethereum/istanbul/vm/stack.v create mode 100644 CoqOfPython/ethereum/london/__init__.v create mode 100644 CoqOfPython/ethereum/london/blocks.v create mode 100644 CoqOfPython/ethereum/london/bloom.v create mode 100644 CoqOfPython/ethereum/london/fork_types.v create mode 100644 CoqOfPython/ethereum/london/state.v create mode 100644 CoqOfPython/ethereum/london/transactions.v create mode 100644 CoqOfPython/ethereum/london/trie.v create mode 100644 CoqOfPython/ethereum/london/utils/__init__.v create mode 100644 CoqOfPython/ethereum/london/utils/address.v create mode 100644 CoqOfPython/ethereum/london/utils/hexadecimal.v create mode 100644 CoqOfPython/ethereum/london/utils/message.v create mode 100644 CoqOfPython/ethereum/london/vm/__init__.v create mode 100644 CoqOfPython/ethereum/london/vm/exceptions.v create mode 100644 CoqOfPython/ethereum/london/vm/instructions/__init__.v create mode 100644 CoqOfPython/ethereum/london/vm/instructions/arithmetic.v create mode 100644 CoqOfPython/ethereum/london/vm/instructions/bitwise.v create mode 100644 CoqOfPython/ethereum/london/vm/instructions/block.v create mode 100644 CoqOfPython/ethereum/london/vm/instructions/comparison.v create mode 100644 CoqOfPython/ethereum/london/vm/instructions/control_flow.v create mode 100644 CoqOfPython/ethereum/london/vm/instructions/environment.v create mode 100644 CoqOfPython/ethereum/london/vm/instructions/keccak.v create mode 100644 CoqOfPython/ethereum/london/vm/instructions/log.v create mode 100644 CoqOfPython/ethereum/london/vm/instructions/memory.v create mode 100644 CoqOfPython/ethereum/london/vm/instructions/stack.v create mode 100644 CoqOfPython/ethereum/london/vm/instructions/storage.v create mode 100644 CoqOfPython/ethereum/london/vm/interpreter.v create mode 100644 CoqOfPython/ethereum/london/vm/memory.v create mode 100644 CoqOfPython/ethereum/london/vm/precompiled_contracts/__init__.v create mode 100644 CoqOfPython/ethereum/london/vm/precompiled_contracts/alt_bn128.v create mode 100644 CoqOfPython/ethereum/london/vm/precompiled_contracts/blake2f.v create mode 100644 CoqOfPython/ethereum/london/vm/precompiled_contracts/ecrecover.v create mode 100644 CoqOfPython/ethereum/london/vm/precompiled_contracts/identity.v create mode 100644 CoqOfPython/ethereum/london/vm/precompiled_contracts/mapping.v create mode 100644 CoqOfPython/ethereum/london/vm/precompiled_contracts/modexp.v create mode 100644 CoqOfPython/ethereum/london/vm/precompiled_contracts/ripemd160.v create mode 100644 CoqOfPython/ethereum/london/vm/precompiled_contracts/sha256.v create mode 100644 CoqOfPython/ethereum/london/vm/runtime.v create mode 100644 CoqOfPython/ethereum/london/vm/stack.v create mode 100644 CoqOfPython/ethereum/muir_glacier/__init__.v create mode 100644 CoqOfPython/ethereum/muir_glacier/blocks.v create mode 100644 CoqOfPython/ethereum/muir_glacier/bloom.v create mode 100644 CoqOfPython/ethereum/muir_glacier/fork_types.v create mode 100644 CoqOfPython/ethereum/muir_glacier/state.v create mode 100644 CoqOfPython/ethereum/muir_glacier/transactions.v create mode 100644 CoqOfPython/ethereum/muir_glacier/trie.v create mode 100644 CoqOfPython/ethereum/muir_glacier/utils/__init__.v create mode 100644 CoqOfPython/ethereum/muir_glacier/utils/address.v create mode 100644 CoqOfPython/ethereum/muir_glacier/utils/hexadecimal.v create mode 100644 CoqOfPython/ethereum/muir_glacier/utils/message.v create mode 100644 CoqOfPython/ethereum/muir_glacier/vm/__init__.v create mode 100644 CoqOfPython/ethereum/muir_glacier/vm/exceptions.v create mode 100644 CoqOfPython/ethereum/muir_glacier/vm/instructions/__init__.v create mode 100644 CoqOfPython/ethereum/muir_glacier/vm/instructions/arithmetic.v create mode 100644 CoqOfPython/ethereum/muir_glacier/vm/instructions/bitwise.v create mode 100644 CoqOfPython/ethereum/muir_glacier/vm/instructions/block.v create mode 100644 CoqOfPython/ethereum/muir_glacier/vm/instructions/comparison.v create mode 100644 CoqOfPython/ethereum/muir_glacier/vm/instructions/control_flow.v create mode 100644 CoqOfPython/ethereum/muir_glacier/vm/instructions/environment.v create mode 100644 CoqOfPython/ethereum/muir_glacier/vm/instructions/keccak.v create mode 100644 CoqOfPython/ethereum/muir_glacier/vm/instructions/log.v create mode 100644 CoqOfPython/ethereum/muir_glacier/vm/instructions/memory.v create mode 100644 CoqOfPython/ethereum/muir_glacier/vm/instructions/stack.v create mode 100644 CoqOfPython/ethereum/muir_glacier/vm/instructions/storage.v create mode 100644 CoqOfPython/ethereum/muir_glacier/vm/interpreter.v create mode 100644 CoqOfPython/ethereum/muir_glacier/vm/memory.v create mode 100644 CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/__init__.v create mode 100644 CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/alt_bn128.v create mode 100644 CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/blake2f.v create mode 100644 CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/ecrecover.v create mode 100644 CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/identity.v create mode 100644 CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/mapping.v create mode 100644 CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/modexp.v create mode 100644 CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/ripemd160.v create mode 100644 CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/sha256.v create mode 100644 CoqOfPython/ethereum/muir_glacier/vm/runtime.v create mode 100644 CoqOfPython/ethereum/muir_glacier/vm/stack.v create mode 100644 CoqOfPython/ethereum/paris/__init__.v create mode 100644 CoqOfPython/ethereum/paris/blocks.v create mode 100644 CoqOfPython/ethereum/paris/bloom.v create mode 100644 CoqOfPython/ethereum/paris/fork.v create mode 100644 CoqOfPython/ethereum/paris/fork_types.v create mode 100644 CoqOfPython/ethereum/paris/state.v create mode 100644 CoqOfPython/ethereum/paris/transactions.v create mode 100644 CoqOfPython/ethereum/paris/trie.v create mode 100644 CoqOfPython/ethereum/paris/utils/__init__.v create mode 100644 CoqOfPython/ethereum/paris/utils/address.v create mode 100644 CoqOfPython/ethereum/paris/utils/hexadecimal.v create mode 100644 CoqOfPython/ethereum/paris/utils/message.v create mode 100644 CoqOfPython/ethereum/paris/vm/__init__.v create mode 100644 CoqOfPython/ethereum/paris/vm/exceptions.v create mode 100644 CoqOfPython/ethereum/paris/vm/instructions/__init__.v create mode 100644 CoqOfPython/ethereum/paris/vm/instructions/bitwise.v create mode 100644 CoqOfPython/ethereum/paris/vm/instructions/block.v create mode 100644 CoqOfPython/ethereum/paris/vm/instructions/comparison.v create mode 100644 CoqOfPython/ethereum/paris/vm/instructions/control_flow.v create mode 100644 CoqOfPython/ethereum/paris/vm/instructions/environment.v create mode 100644 CoqOfPython/ethereum/paris/vm/instructions/keccak.v create mode 100644 CoqOfPython/ethereum/paris/vm/instructions/log.v create mode 100644 CoqOfPython/ethereum/paris/vm/instructions/memory.v create mode 100644 CoqOfPython/ethereum/paris/vm/instructions/stack.v create mode 100644 CoqOfPython/ethereum/paris/vm/instructions/storage.v create mode 100644 CoqOfPython/ethereum/paris/vm/interpreter.v create mode 100644 CoqOfPython/ethereum/paris/vm/memory.v create mode 100644 CoqOfPython/ethereum/paris/vm/precompiled_contracts/__init__.v create mode 100644 CoqOfPython/ethereum/paris/vm/precompiled_contracts/alt_bn128.v create mode 100644 CoqOfPython/ethereum/paris/vm/precompiled_contracts/blake2f.v create mode 100644 CoqOfPython/ethereum/paris/vm/precompiled_contracts/ecrecover.v create mode 100644 CoqOfPython/ethereum/paris/vm/precompiled_contracts/identity.v create mode 100644 CoqOfPython/ethereum/paris/vm/precompiled_contracts/mapping.v create mode 100644 CoqOfPython/ethereum/paris/vm/precompiled_contracts/modexp.v create mode 100644 CoqOfPython/ethereum/paris/vm/precompiled_contracts/ripemd160.v create mode 100644 CoqOfPython/ethereum/paris/vm/precompiled_contracts/sha256.v create mode 100644 CoqOfPython/ethereum/paris/vm/runtime.v create mode 100644 CoqOfPython/ethereum/paris/vm/stack.v create mode 100644 CoqOfPython/ethereum/rlp.v create mode 100644 CoqOfPython/ethereum/shanghai/__init__.v create mode 100644 CoqOfPython/ethereum/shanghai/blocks.v create mode 100644 CoqOfPython/ethereum/shanghai/bloom.v create mode 100644 CoqOfPython/ethereum/shanghai/fork.v create mode 100644 CoqOfPython/ethereum/shanghai/fork_types.v create mode 100644 CoqOfPython/ethereum/shanghai/state.v create mode 100644 CoqOfPython/ethereum/shanghai/transactions.v create mode 100644 CoqOfPython/ethereum/shanghai/trie.v create mode 100644 CoqOfPython/ethereum/shanghai/utils/__init__.v create mode 100644 CoqOfPython/ethereum/shanghai/utils/address.v create mode 100644 CoqOfPython/ethereum/shanghai/utils/hexadecimal.v create mode 100644 CoqOfPython/ethereum/shanghai/utils/message.v create mode 100644 CoqOfPython/ethereum/shanghai/vm/__init__.v create mode 100644 CoqOfPython/ethereum/shanghai/vm/exceptions.v create mode 100644 CoqOfPython/ethereum/shanghai/vm/instructions/__init__.v create mode 100644 CoqOfPython/ethereum/shanghai/vm/instructions/arithmetic.v create mode 100644 CoqOfPython/ethereum/shanghai/vm/instructions/bitwise.v create mode 100644 CoqOfPython/ethereum/shanghai/vm/instructions/block.v create mode 100644 CoqOfPython/ethereum/shanghai/vm/instructions/comparison.v create mode 100644 CoqOfPython/ethereum/shanghai/vm/instructions/control_flow.v create mode 100644 CoqOfPython/ethereum/shanghai/vm/instructions/environment.v create mode 100644 CoqOfPython/ethereum/shanghai/vm/instructions/keccak.v create mode 100644 CoqOfPython/ethereum/shanghai/vm/instructions/log.v create mode 100644 CoqOfPython/ethereum/shanghai/vm/instructions/memory.v create mode 100644 CoqOfPython/ethereum/shanghai/vm/instructions/stack.v create mode 100644 CoqOfPython/ethereum/shanghai/vm/instructions/storage.v create mode 100644 CoqOfPython/ethereum/shanghai/vm/interpreter.v create mode 100644 CoqOfPython/ethereum/shanghai/vm/memory.v create mode 100644 CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/__init__.v create mode 100644 CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/alt_bn128.v create mode 100644 CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/blake2f.v create mode 100644 CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/ecrecover.v create mode 100644 CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/identity.v create mode 100644 CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/mapping.v create mode 100644 CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/modexp.v create mode 100644 CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/ripemd160.v create mode 100644 CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/sha256.v create mode 100644 CoqOfPython/ethereum/shanghai/vm/runtime.v create mode 100644 CoqOfPython/ethereum/shanghai/vm/stack.v create mode 100644 CoqOfPython/ethereum/spurious_dragon/__init__.v create mode 100644 CoqOfPython/ethereum/spurious_dragon/blocks.v create mode 100644 CoqOfPython/ethereum/spurious_dragon/bloom.v create mode 100644 CoqOfPython/ethereum/spurious_dragon/fork.v create mode 100644 CoqOfPython/ethereum/spurious_dragon/fork_types.v create mode 100644 CoqOfPython/ethereum/spurious_dragon/state.v create mode 100644 CoqOfPython/ethereum/spurious_dragon/transactions.v create mode 100644 CoqOfPython/ethereum/spurious_dragon/trie.v create mode 100644 CoqOfPython/ethereum/spurious_dragon/utils/__init__.v create mode 100644 CoqOfPython/ethereum/spurious_dragon/utils/address.v create mode 100644 CoqOfPython/ethereum/spurious_dragon/utils/hexadecimal.v create mode 100644 CoqOfPython/ethereum/spurious_dragon/utils/message.v create mode 100644 CoqOfPython/ethereum/spurious_dragon/vm/__init__.v create mode 100644 CoqOfPython/ethereum/spurious_dragon/vm/exceptions.v create mode 100644 CoqOfPython/ethereum/spurious_dragon/vm/instructions/__init__.v create mode 100644 CoqOfPython/ethereum/spurious_dragon/vm/instructions/arithmetic.v create mode 100644 CoqOfPython/ethereum/spurious_dragon/vm/instructions/bitwise.v create mode 100644 CoqOfPython/ethereum/spurious_dragon/vm/instructions/block.v create mode 100644 CoqOfPython/ethereum/spurious_dragon/vm/instructions/comparison.v create mode 100644 CoqOfPython/ethereum/spurious_dragon/vm/instructions/control_flow.v create mode 100644 CoqOfPython/ethereum/spurious_dragon/vm/instructions/environment.v create mode 100644 CoqOfPython/ethereum/spurious_dragon/vm/instructions/keccak.v create mode 100644 CoqOfPython/ethereum/spurious_dragon/vm/instructions/log.v create mode 100644 CoqOfPython/ethereum/spurious_dragon/vm/instructions/memory.v create mode 100644 CoqOfPython/ethereum/spurious_dragon/vm/instructions/stack.v create mode 100644 CoqOfPython/ethereum/spurious_dragon/vm/instructions/storage.v create mode 100644 CoqOfPython/ethereum/spurious_dragon/vm/interpreter.v create mode 100644 CoqOfPython/ethereum/spurious_dragon/vm/memory.v create mode 100644 CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/__init__.v create mode 100644 CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/ecrecover.v create mode 100644 CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/identity.v create mode 100644 CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/mapping.v create mode 100644 CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/ripemd160.v create mode 100644 CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/sha256.v create mode 100644 CoqOfPython/ethereum/spurious_dragon/vm/runtime.v create mode 100644 CoqOfPython/ethereum/spurious_dragon/vm/stack.v create mode 100644 CoqOfPython/ethereum/tangerine_whistle/__init__.v create mode 100644 CoqOfPython/ethereum/tangerine_whistle/blocks.v create mode 100644 CoqOfPython/ethereum/tangerine_whistle/bloom.v create mode 100644 CoqOfPython/ethereum/tangerine_whistle/fork.v create mode 100644 CoqOfPython/ethereum/tangerine_whistle/fork_types.v create mode 100644 CoqOfPython/ethereum/tangerine_whistle/state.v create mode 100644 CoqOfPython/ethereum/tangerine_whistle/transactions.v create mode 100644 CoqOfPython/ethereum/tangerine_whistle/trie.v create mode 100644 CoqOfPython/ethereum/tangerine_whistle/utils/__init__.v create mode 100644 CoqOfPython/ethereum/tangerine_whistle/utils/address.v create mode 100644 CoqOfPython/ethereum/tangerine_whistle/utils/hexadecimal.v create mode 100644 CoqOfPython/ethereum/tangerine_whistle/utils/message.v create mode 100644 CoqOfPython/ethereum/tangerine_whistle/vm/__init__.v create mode 100644 CoqOfPython/ethereum/tangerine_whistle/vm/exceptions.v create mode 100644 CoqOfPython/ethereum/tangerine_whistle/vm/instructions/__init__.v create mode 100644 CoqOfPython/ethereum/tangerine_whistle/vm/instructions/arithmetic.v create mode 100644 CoqOfPython/ethereum/tangerine_whistle/vm/instructions/bitwise.v create mode 100644 CoqOfPython/ethereum/tangerine_whistle/vm/instructions/block.v create mode 100644 CoqOfPython/ethereum/tangerine_whistle/vm/instructions/comparison.v create mode 100644 CoqOfPython/ethereum/tangerine_whistle/vm/instructions/control_flow.v create mode 100644 CoqOfPython/ethereum/tangerine_whistle/vm/instructions/environment.v create mode 100644 CoqOfPython/ethereum/tangerine_whistle/vm/instructions/keccak.v create mode 100644 CoqOfPython/ethereum/tangerine_whistle/vm/instructions/log.v create mode 100644 CoqOfPython/ethereum/tangerine_whistle/vm/instructions/memory.v create mode 100644 CoqOfPython/ethereum/tangerine_whistle/vm/instructions/stack.v create mode 100644 CoqOfPython/ethereum/tangerine_whistle/vm/instructions/storage.v create mode 100644 CoqOfPython/ethereum/tangerine_whistle/vm/interpreter.v create mode 100644 CoqOfPython/ethereum/tangerine_whistle/vm/memory.v create mode 100644 CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/__init__.v create mode 100644 CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/ecrecover.v create mode 100644 CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/identity.v create mode 100644 CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/mapping.v create mode 100644 CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/ripemd160.v create mode 100644 CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/sha256.v create mode 100644 CoqOfPython/ethereum/tangerine_whistle/vm/runtime.v create mode 100644 CoqOfPython/ethereum/tangerine_whistle/vm/stack.v create mode 100644 CoqOfPython/ethereum/trace.v create mode 100644 CoqOfPython/ethereum/utils/__init__.v create mode 100644 CoqOfPython/ethereum/utils/byte.v create mode 100644 CoqOfPython/ethereum/utils/ensure.v create mode 100644 CoqOfPython/ethereum/utils/hexadecimal.v create mode 100644 CoqOfPython/ethereum/utils/numeric.v create mode 100644 CoqOfPython/ethereum/utils/safe_arithmetic.v diff --git a/CoqOfPython/CoqMakefile b/CoqOfPython/CoqMakefile index 7d44ffe..97d530e 100644 --- a/CoqOfPython/CoqMakefile +++ b/CoqOfPython/CoqMakefile @@ -45,7 +45,7 @@ HASNATDYNLINK := $(COQMF_HASNATDYNLINK) OCAMLWARN := $(COQMF_WARN) CoqMakefile.conf: _CoqProject - coq_makefile -f _CoqProject -o CoqMakefile ./CoqOfPython.v ./dataclasses.v ./ethereum/base_types.v ./ethereum/paris/vm/instructions/arithmetic.v ./RecordUpdate.v ./typing.v + coq_makefile -f _CoqProject -o CoqMakefile ./CoqOfPython.v ./dataclasses.v ./ethereum/arrow_glacier/blocks.v ./ethereum/arrow_glacier/bloom.v ./ethereum/arrow_glacier/fork_types.v ./ethereum/arrow_glacier/__init__.v ./ethereum/arrow_glacier/state.v ./ethereum/arrow_glacier/transactions.v ./ethereum/arrow_glacier/trie.v ./ethereum/arrow_glacier/utils/address.v ./ethereum/arrow_glacier/utils/hexadecimal.v ./ethereum/arrow_glacier/utils/__init__.v ./ethereum/arrow_glacier/utils/message.v ./ethereum/arrow_glacier/vm/exceptions.v ./ethereum/arrow_glacier/vm/__init__.v ./ethereum/arrow_glacier/vm/instructions/arithmetic.v ./ethereum/arrow_glacier/vm/instructions/bitwise.v ./ethereum/arrow_glacier/vm/instructions/block.v ./ethereum/arrow_glacier/vm/instructions/comparison.v ./ethereum/arrow_glacier/vm/instructions/control_flow.v ./ethereum/arrow_glacier/vm/instructions/environment.v ./ethereum/arrow_glacier/vm/instructions/__init__.v ./ethereum/arrow_glacier/vm/instructions/keccak.v ./ethereum/arrow_glacier/vm/instructions/log.v ./ethereum/arrow_glacier/vm/instructions/memory.v ./ethereum/arrow_glacier/vm/instructions/stack.v ./ethereum/arrow_glacier/vm/instructions/storage.v ./ethereum/arrow_glacier/vm/interpreter.v ./ethereum/arrow_glacier/vm/memory.v ./ethereum/arrow_glacier/vm/precompiled_contracts/alt_bn128.v ./ethereum/arrow_glacier/vm/precompiled_contracts/blake2f.v ./ethereum/arrow_glacier/vm/precompiled_contracts/ecrecover.v ./ethereum/arrow_glacier/vm/precompiled_contracts/identity.v ./ethereum/arrow_glacier/vm/precompiled_contracts/__init__.v ./ethereum/arrow_glacier/vm/precompiled_contracts/mapping.v ./ethereum/arrow_glacier/vm/precompiled_contracts/modexp.v ./ethereum/arrow_glacier/vm/precompiled_contracts/ripemd160.v ./ethereum/arrow_glacier/vm/precompiled_contracts/sha256.v ./ethereum/arrow_glacier/vm/runtime.v ./ethereum/arrow_glacier/vm/stack.v ./ethereum/base_types.v ./ethereum/berlin/blocks.v ./ethereum/berlin/bloom.v ./ethereum/berlin/fork_types.v ./ethereum/berlin/__init__.v ./ethereum/berlin/state.v ./ethereum/berlin/transactions.v ./ethereum/berlin/trie.v ./ethereum/berlin/utils/address.v ./ethereum/berlin/utils/hexadecimal.v ./ethereum/berlin/utils/__init__.v ./ethereum/berlin/utils/message.v ./ethereum/berlin/vm/exceptions.v ./ethereum/berlin/vm/__init__.v ./ethereum/berlin/vm/instructions/arithmetic.v ./ethereum/berlin/vm/instructions/bitwise.v ./ethereum/berlin/vm/instructions/block.v ./ethereum/berlin/vm/instructions/comparison.v ./ethereum/berlin/vm/instructions/control_flow.v ./ethereum/berlin/vm/instructions/environment.v ./ethereum/berlin/vm/instructions/__init__.v ./ethereum/berlin/vm/instructions/keccak.v ./ethereum/berlin/vm/instructions/log.v ./ethereum/berlin/vm/instructions/memory.v ./ethereum/berlin/vm/instructions/stack.v ./ethereum/berlin/vm/instructions/storage.v ./ethereum/berlin/vm/interpreter.v ./ethereum/berlin/vm/memory.v ./ethereum/berlin/vm/precompiled_contracts/alt_bn128.v ./ethereum/berlin/vm/precompiled_contracts/blake2f.v ./ethereum/berlin/vm/precompiled_contracts/ecrecover.v ./ethereum/berlin/vm/precompiled_contracts/identity.v ./ethereum/berlin/vm/precompiled_contracts/__init__.v ./ethereum/berlin/vm/precompiled_contracts/mapping.v ./ethereum/berlin/vm/precompiled_contracts/modexp.v ./ethereum/berlin/vm/precompiled_contracts/ripemd160.v ./ethereum/berlin/vm/precompiled_contracts/sha256.v ./ethereum/berlin/vm/runtime.v ./ethereum/berlin/vm/stack.v ./ethereum/byzantium/blocks.v ./ethereum/byzantium/bloom.v ./ethereum/byzantium/fork_types.v ./ethereum/byzantium/__init__.v ./ethereum/byzantium/state.v ./ethereum/byzantium/transactions.v ./ethereum/byzantium/trie.v ./ethereum/byzantium/utils/address.v ./ethereum/byzantium/utils/hexadecimal.v ./ethereum/byzantium/utils/__init__.v ./ethereum/byzantium/utils/message.v ./ethereum/byzantium/vm/exceptions.v ./ethereum/byzantium/vm/__init__.v ./ethereum/byzantium/vm/instructions/arithmetic.v ./ethereum/byzantium/vm/instructions/bitwise.v ./ethereum/byzantium/vm/instructions/block.v ./ethereum/byzantium/vm/instructions/comparison.v ./ethereum/byzantium/vm/instructions/control_flow.v ./ethereum/byzantium/vm/instructions/environment.v ./ethereum/byzantium/vm/instructions/__init__.v ./ethereum/byzantium/vm/instructions/keccak.v ./ethereum/byzantium/vm/instructions/log.v ./ethereum/byzantium/vm/instructions/memory.v ./ethereum/byzantium/vm/instructions/stack.v ./ethereum/byzantium/vm/instructions/storage.v ./ethereum/byzantium/vm/interpreter.v ./ethereum/byzantium/vm/memory.v ./ethereum/byzantium/vm/precompiled_contracts/alt_bn128.v ./ethereum/byzantium/vm/precompiled_contracts/ecrecover.v ./ethereum/byzantium/vm/precompiled_contracts/identity.v ./ethereum/byzantium/vm/precompiled_contracts/__init__.v ./ethereum/byzantium/vm/precompiled_contracts/mapping.v ./ethereum/byzantium/vm/precompiled_contracts/modexp.v ./ethereum/byzantium/vm/precompiled_contracts/ripemd160.v ./ethereum/byzantium/vm/precompiled_contracts/sha256.v ./ethereum/byzantium/vm/runtime.v ./ethereum/byzantium/vm/stack.v ./ethereum/cancun/blocks.v ./ethereum/cancun/bloom.v ./ethereum/cancun/fork_types.v ./ethereum/cancun/fork.v ./ethereum/cancun/__init__.v ./ethereum/cancun/state.v ./ethereum/cancun/transactions.v ./ethereum/cancun/trie.v ./ethereum/cancun/utils/address.v ./ethereum/cancun/utils/hexadecimal.v ./ethereum/cancun/utils/__init__.v ./ethereum/cancun/utils/message.v ./ethereum/cancun/vm/exceptions.v ./ethereum/cancun/vm/__init__.v ./ethereum/cancun/vm/instructions/arithmetic.v ./ethereum/cancun/vm/instructions/bitwise.v ./ethereum/cancun/vm/instructions/block.v ./ethereum/cancun/vm/instructions/comparison.v ./ethereum/cancun/vm/instructions/control_flow.v ./ethereum/cancun/vm/instructions/environment.v ./ethereum/cancun/vm/instructions/__init__.v ./ethereum/cancun/vm/instructions/keccak.v ./ethereum/cancun/vm/instructions/log.v ./ethereum/cancun/vm/instructions/memory.v ./ethereum/cancun/vm/instructions/stack.v ./ethereum/cancun/vm/instructions/storage.v ./ethereum/cancun/vm/interpreter.v ./ethereum/cancun/vm/memory.v ./ethereum/cancun/vm/precompiled_contracts/alt_bn128.v ./ethereum/cancun/vm/precompiled_contracts/blake2f.v ./ethereum/cancun/vm/precompiled_contracts/ecrecover.v ./ethereum/cancun/vm/precompiled_contracts/identity.v ./ethereum/cancun/vm/precompiled_contracts/__init__.v ./ethereum/cancun/vm/precompiled_contracts/mapping.v ./ethereum/cancun/vm/precompiled_contracts/modexp.v ./ethereum/cancun/vm/precompiled_contracts/point_evaluation.v ./ethereum/cancun/vm/precompiled_contracts/ripemd160.v ./ethereum/cancun/vm/precompiled_contracts/sha256.v ./ethereum/cancun/vm/runtime.v ./ethereum/cancun/vm/stack.v ./ethereum/constantinople/blocks.v ./ethereum/constantinople/bloom.v ./ethereum/constantinople/fork_types.v ./ethereum/constantinople/__init__.v ./ethereum/constantinople/state.v ./ethereum/constantinople/transactions.v ./ethereum/constantinople/trie.v ./ethereum/constantinople/utils/address.v ./ethereum/constantinople/utils/hexadecimal.v ./ethereum/constantinople/utils/__init__.v ./ethereum/constantinople/utils/message.v ./ethereum/constantinople/vm/exceptions.v ./ethereum/constantinople/vm/__init__.v ./ethereum/constantinople/vm/instructions/arithmetic.v ./ethereum/constantinople/vm/instructions/bitwise.v ./ethereum/constantinople/vm/instructions/block.v ./ethereum/constantinople/vm/instructions/comparison.v ./ethereum/constantinople/vm/instructions/control_flow.v ./ethereum/constantinople/vm/instructions/environment.v ./ethereum/constantinople/vm/instructions/__init__.v ./ethereum/constantinople/vm/instructions/keccak.v ./ethereum/constantinople/vm/instructions/log.v ./ethereum/constantinople/vm/instructions/memory.v ./ethereum/constantinople/vm/instructions/stack.v ./ethereum/constantinople/vm/instructions/storage.v ./ethereum/constantinople/vm/interpreter.v ./ethereum/constantinople/vm/memory.v ./ethereum/constantinople/vm/precompiled_contracts/alt_bn128.v ./ethereum/constantinople/vm/precompiled_contracts/ecrecover.v ./ethereum/constantinople/vm/precompiled_contracts/identity.v ./ethereum/constantinople/vm/precompiled_contracts/__init__.v ./ethereum/constantinople/vm/precompiled_contracts/mapping.v ./ethereum/constantinople/vm/precompiled_contracts/modexp.v ./ethereum/constantinople/vm/precompiled_contracts/ripemd160.v ./ethereum/constantinople/vm/precompiled_contracts/sha256.v ./ethereum/constantinople/vm/runtime.v ./ethereum/constantinople/vm/stack.v ./ethereum/crypto/alt_bn128.v ./ethereum/crypto/blake2.v ./ethereum/crypto/elliptic_curve.v ./ethereum/crypto/finite_field.v ./ethereum/crypto/hash.v ./ethereum/crypto/__init__.v ./ethereum/dao_fork/blocks.v ./ethereum/dao_fork/bloom.v ./ethereum/dao_fork/dao.v ./ethereum/dao_fork/fork_types.v ./ethereum/dao_fork/fork.v ./ethereum/dao_fork/__init__.v ./ethereum/dao_fork/state.v ./ethereum/dao_fork/transactions.v ./ethereum/dao_fork/trie.v ./ethereum/dao_fork/utils/address.v ./ethereum/dao_fork/utils/hexadecimal.v ./ethereum/dao_fork/utils/__init__.v ./ethereum/dao_fork/utils/message.v ./ethereum/dao_fork/vm/exceptions.v ./ethereum/dao_fork/vm/__init__.v ./ethereum/dao_fork/vm/instructions/arithmetic.v ./ethereum/dao_fork/vm/instructions/bitwise.v ./ethereum/dao_fork/vm/instructions/block.v ./ethereum/dao_fork/vm/instructions/comparison.v ./ethereum/dao_fork/vm/instructions/control_flow.v ./ethereum/dao_fork/vm/instructions/environment.v ./ethereum/dao_fork/vm/instructions/__init__.v ./ethereum/dao_fork/vm/instructions/keccak.v ./ethereum/dao_fork/vm/instructions/log.v ./ethereum/dao_fork/vm/instructions/memory.v ./ethereum/dao_fork/vm/instructions/stack.v ./ethereum/dao_fork/vm/instructions/storage.v ./ethereum/dao_fork/vm/instructions/system.v ./ethereum/dao_fork/vm/interpreter.v ./ethereum/dao_fork/vm/memory.v ./ethereum/dao_fork/vm/precompiled_contracts/ecrecover.v ./ethereum/dao_fork/vm/precompiled_contracts/identity.v ./ethereum/dao_fork/vm/precompiled_contracts/__init__.v ./ethereum/dao_fork/vm/precompiled_contracts/mapping.v ./ethereum/dao_fork/vm/precompiled_contracts/ripemd160.v ./ethereum/dao_fork/vm/precompiled_contracts/sha256.v ./ethereum/dao_fork/vm/runtime.v ./ethereum/dao_fork/vm/stack.v ./ethereum/ethash.v ./ethereum/exceptions.v ./ethereum/fork_criteria.v ./ethereum/frontier/blocks.v ./ethereum/frontier/bloom.v ./ethereum/frontier/fork_types.v ./ethereum/frontier/fork.v ./ethereum/frontier/__init__.v ./ethereum/frontier/state.v ./ethereum/frontier/transactions.v ./ethereum/frontier/trie.v ./ethereum/frontier/utils/address.v ./ethereum/frontier/utils/hexadecimal.v ./ethereum/frontier/utils/__init__.v ./ethereum/frontier/utils/message.v ./ethereum/frontier/vm/exceptions.v ./ethereum/frontier/vm/__init__.v ./ethereum/frontier/vm/instructions/arithmetic.v ./ethereum/frontier/vm/instructions/bitwise.v ./ethereum/frontier/vm/instructions/block.v ./ethereum/frontier/vm/instructions/comparison.v ./ethereum/frontier/vm/instructions/control_flow.v ./ethereum/frontier/vm/instructions/environment.v ./ethereum/frontier/vm/instructions/__init__.v ./ethereum/frontier/vm/instructions/keccak.v ./ethereum/frontier/vm/instructions/log.v ./ethereum/frontier/vm/instructions/memory.v ./ethereum/frontier/vm/instructions/stack.v ./ethereum/frontier/vm/instructions/storage.v ./ethereum/frontier/vm/instructions/system.v ./ethereum/frontier/vm/interpreter.v ./ethereum/frontier/vm/memory.v ./ethereum/frontier/vm/precompiled_contracts/ecrecover.v ./ethereum/frontier/vm/precompiled_contracts/identity.v ./ethereum/frontier/vm/precompiled_contracts/__init__.v ./ethereum/frontier/vm/precompiled_contracts/mapping.v ./ethereum/frontier/vm/precompiled_contracts/ripemd160.v ./ethereum/frontier/vm/precompiled_contracts/sha256.v ./ethereum/frontier/vm/runtime.v ./ethereum/frontier/vm/stack.v ./ethereum/genesis.v ./ethereum/gray_glacier/blocks.v ./ethereum/gray_glacier/bloom.v ./ethereum/gray_glacier/fork_types.v ./ethereum/gray_glacier/__init__.v ./ethereum/gray_glacier/state.v ./ethereum/gray_glacier/transactions.v ./ethereum/gray_glacier/trie.v ./ethereum/gray_glacier/utils/address.v ./ethereum/gray_glacier/utils/hexadecimal.v ./ethereum/gray_glacier/utils/__init__.v ./ethereum/gray_glacier/utils/message.v ./ethereum/gray_glacier/vm/exceptions.v ./ethereum/gray_glacier/vm/__init__.v ./ethereum/gray_glacier/vm/instructions/arithmetic.v ./ethereum/gray_glacier/vm/instructions/bitwise.v ./ethereum/gray_glacier/vm/instructions/block.v ./ethereum/gray_glacier/vm/instructions/comparison.v ./ethereum/gray_glacier/vm/instructions/control_flow.v ./ethereum/gray_glacier/vm/instructions/environment.v ./ethereum/gray_glacier/vm/instructions/__init__.v ./ethereum/gray_glacier/vm/instructions/keccak.v ./ethereum/gray_glacier/vm/instructions/log.v ./ethereum/gray_glacier/vm/instructions/memory.v ./ethereum/gray_glacier/vm/instructions/stack.v ./ethereum/gray_glacier/vm/instructions/storage.v ./ethereum/gray_glacier/vm/interpreter.v ./ethereum/gray_glacier/vm/memory.v ./ethereum/gray_glacier/vm/precompiled_contracts/alt_bn128.v ./ethereum/gray_glacier/vm/precompiled_contracts/blake2f.v ./ethereum/gray_glacier/vm/precompiled_contracts/ecrecover.v ./ethereum/gray_glacier/vm/precompiled_contracts/identity.v ./ethereum/gray_glacier/vm/precompiled_contracts/__init__.v ./ethereum/gray_glacier/vm/precompiled_contracts/mapping.v ./ethereum/gray_glacier/vm/precompiled_contracts/modexp.v ./ethereum/gray_glacier/vm/precompiled_contracts/ripemd160.v ./ethereum/gray_glacier/vm/precompiled_contracts/sha256.v ./ethereum/gray_glacier/vm/runtime.v ./ethereum/gray_glacier/vm/stack.v ./ethereum/homestead/blocks.v ./ethereum/homestead/bloom.v ./ethereum/homestead/fork_types.v ./ethereum/homestead/fork.v ./ethereum/homestead/__init__.v ./ethereum/homestead/state.v ./ethereum/homestead/transactions.v ./ethereum/homestead/trie.v ./ethereum/homestead/utils/address.v ./ethereum/homestead/utils/hexadecimal.v ./ethereum/homestead/utils/__init__.v ./ethereum/homestead/utils/message.v ./ethereum/homestead/vm/exceptions.v ./ethereum/homestead/vm/__init__.v ./ethereum/homestead/vm/instructions/arithmetic.v ./ethereum/homestead/vm/instructions/bitwise.v ./ethereum/homestead/vm/instructions/block.v ./ethereum/homestead/vm/instructions/comparison.v ./ethereum/homestead/vm/instructions/control_flow.v ./ethereum/homestead/vm/instructions/environment.v ./ethereum/homestead/vm/instructions/__init__.v ./ethereum/homestead/vm/instructions/keccak.v ./ethereum/homestead/vm/instructions/log.v ./ethereum/homestead/vm/instructions/memory.v ./ethereum/homestead/vm/instructions/stack.v ./ethereum/homestead/vm/instructions/storage.v ./ethereum/homestead/vm/instructions/system.v ./ethereum/homestead/vm/interpreter.v ./ethereum/homestead/vm/memory.v ./ethereum/homestead/vm/precompiled_contracts/ecrecover.v ./ethereum/homestead/vm/precompiled_contracts/identity.v ./ethereum/homestead/vm/precompiled_contracts/__init__.v ./ethereum/homestead/vm/precompiled_contracts/mapping.v ./ethereum/homestead/vm/precompiled_contracts/ripemd160.v ./ethereum/homestead/vm/precompiled_contracts/sha256.v ./ethereum/homestead/vm/runtime.v ./ethereum/homestead/vm/stack.v ./ethereum/__init__.v ./ethereum/istanbul/blocks.v ./ethereum/istanbul/bloom.v ./ethereum/istanbul/fork_types.v ./ethereum/istanbul/__init__.v ./ethereum/istanbul/state.v ./ethereum/istanbul/transactions.v ./ethereum/istanbul/trie.v ./ethereum/istanbul/utils/address.v ./ethereum/istanbul/utils/hexadecimal.v ./ethereum/istanbul/utils/__init__.v ./ethereum/istanbul/utils/message.v ./ethereum/istanbul/vm/exceptions.v ./ethereum/istanbul/vm/__init__.v ./ethereum/istanbul/vm/instructions/arithmetic.v ./ethereum/istanbul/vm/instructions/bitwise.v ./ethereum/istanbul/vm/instructions/block.v ./ethereum/istanbul/vm/instructions/comparison.v ./ethereum/istanbul/vm/instructions/control_flow.v ./ethereum/istanbul/vm/instructions/environment.v ./ethereum/istanbul/vm/instructions/__init__.v ./ethereum/istanbul/vm/instructions/keccak.v ./ethereum/istanbul/vm/instructions/log.v ./ethereum/istanbul/vm/instructions/memory.v ./ethereum/istanbul/vm/instructions/stack.v ./ethereum/istanbul/vm/instructions/storage.v ./ethereum/istanbul/vm/interpreter.v ./ethereum/istanbul/vm/memory.v ./ethereum/istanbul/vm/precompiled_contracts/alt_bn128.v ./ethereum/istanbul/vm/precompiled_contracts/blake2f.v ./ethereum/istanbul/vm/precompiled_contracts/ecrecover.v ./ethereum/istanbul/vm/precompiled_contracts/identity.v ./ethereum/istanbul/vm/precompiled_contracts/__init__.v ./ethereum/istanbul/vm/precompiled_contracts/mapping.v ./ethereum/istanbul/vm/precompiled_contracts/modexp.v ./ethereum/istanbul/vm/precompiled_contracts/ripemd160.v ./ethereum/istanbul/vm/precompiled_contracts/sha256.v ./ethereum/istanbul/vm/runtime.v ./ethereum/istanbul/vm/stack.v ./ethereum/london/blocks.v ./ethereum/london/bloom.v ./ethereum/london/fork_types.v ./ethereum/london/__init__.v ./ethereum/london/state.v ./ethereum/london/transactions.v ./ethereum/london/trie.v ./ethereum/london/utils/address.v ./ethereum/london/utils/hexadecimal.v ./ethereum/london/utils/__init__.v ./ethereum/london/utils/message.v ./ethereum/london/vm/exceptions.v ./ethereum/london/vm/__init__.v ./ethereum/london/vm/instructions/arithmetic.v ./ethereum/london/vm/instructions/bitwise.v ./ethereum/london/vm/instructions/block.v ./ethereum/london/vm/instructions/comparison.v ./ethereum/london/vm/instructions/control_flow.v ./ethereum/london/vm/instructions/environment.v ./ethereum/london/vm/instructions/__init__.v ./ethereum/london/vm/instructions/keccak.v ./ethereum/london/vm/instructions/log.v ./ethereum/london/vm/instructions/memory.v ./ethereum/london/vm/instructions/stack.v ./ethereum/london/vm/instructions/storage.v ./ethereum/london/vm/interpreter.v ./ethereum/london/vm/memory.v ./ethereum/london/vm/precompiled_contracts/alt_bn128.v ./ethereum/london/vm/precompiled_contracts/blake2f.v ./ethereum/london/vm/precompiled_contracts/ecrecover.v ./ethereum/london/vm/precompiled_contracts/identity.v ./ethereum/london/vm/precompiled_contracts/__init__.v ./ethereum/london/vm/precompiled_contracts/mapping.v ./ethereum/london/vm/precompiled_contracts/modexp.v ./ethereum/london/vm/precompiled_contracts/ripemd160.v ./ethereum/london/vm/precompiled_contracts/sha256.v ./ethereum/london/vm/runtime.v ./ethereum/london/vm/stack.v ./ethereum/muir_glacier/blocks.v ./ethereum/muir_glacier/bloom.v ./ethereum/muir_glacier/fork_types.v ./ethereum/muir_glacier/__init__.v ./ethereum/muir_glacier/state.v ./ethereum/muir_glacier/transactions.v ./ethereum/muir_glacier/trie.v ./ethereum/muir_glacier/utils/address.v ./ethereum/muir_glacier/utils/hexadecimal.v ./ethereum/muir_glacier/utils/__init__.v ./ethereum/muir_glacier/utils/message.v ./ethereum/muir_glacier/vm/exceptions.v ./ethereum/muir_glacier/vm/__init__.v ./ethereum/muir_glacier/vm/instructions/arithmetic.v ./ethereum/muir_glacier/vm/instructions/bitwise.v ./ethereum/muir_glacier/vm/instructions/block.v ./ethereum/muir_glacier/vm/instructions/comparison.v ./ethereum/muir_glacier/vm/instructions/control_flow.v ./ethereum/muir_glacier/vm/instructions/environment.v ./ethereum/muir_glacier/vm/instructions/__init__.v ./ethereum/muir_glacier/vm/instructions/keccak.v ./ethereum/muir_glacier/vm/instructions/log.v ./ethereum/muir_glacier/vm/instructions/memory.v ./ethereum/muir_glacier/vm/instructions/stack.v ./ethereum/muir_glacier/vm/instructions/storage.v ./ethereum/muir_glacier/vm/interpreter.v ./ethereum/muir_glacier/vm/memory.v ./ethereum/muir_glacier/vm/precompiled_contracts/alt_bn128.v ./ethereum/muir_glacier/vm/precompiled_contracts/blake2f.v ./ethereum/muir_glacier/vm/precompiled_contracts/ecrecover.v ./ethereum/muir_glacier/vm/precompiled_contracts/identity.v ./ethereum/muir_glacier/vm/precompiled_contracts/__init__.v ./ethereum/muir_glacier/vm/precompiled_contracts/mapping.v ./ethereum/muir_glacier/vm/precompiled_contracts/modexp.v ./ethereum/muir_glacier/vm/precompiled_contracts/ripemd160.v ./ethereum/muir_glacier/vm/precompiled_contracts/sha256.v ./ethereum/muir_glacier/vm/runtime.v ./ethereum/muir_glacier/vm/stack.v ./ethereum/paris/blocks.v ./ethereum/paris/bloom.v ./ethereum/paris/fork_types.v ./ethereum/paris/fork.v ./ethereum/paris/__init__.v ./ethereum/paris/state.v ./ethereum/paris/transactions.v ./ethereum/paris/trie.v ./ethereum/paris/utils/address.v ./ethereum/paris/utils/hexadecimal.v ./ethereum/paris/utils/__init__.v ./ethereum/paris/utils/message.v ./ethereum/paris/vm/exceptions.v ./ethereum/paris/vm/__init__.v ./ethereum/paris/vm/instructions/arithmetic.v ./ethereum/paris/vm/instructions/bitwise.v ./ethereum/paris/vm/instructions/block.v ./ethereum/paris/vm/instructions/comparison.v ./ethereum/paris/vm/instructions/control_flow.v ./ethereum/paris/vm/instructions/environment.v ./ethereum/paris/vm/instructions/__init__.v ./ethereum/paris/vm/instructions/keccak.v ./ethereum/paris/vm/instructions/log.v ./ethereum/paris/vm/instructions/memory.v ./ethereum/paris/vm/instructions/stack.v ./ethereum/paris/vm/instructions/storage.v ./ethereum/paris/vm/interpreter.v ./ethereum/paris/vm/memory.v ./ethereum/paris/vm/precompiled_contracts/alt_bn128.v ./ethereum/paris/vm/precompiled_contracts/blake2f.v ./ethereum/paris/vm/precompiled_contracts/ecrecover.v ./ethereum/paris/vm/precompiled_contracts/identity.v ./ethereum/paris/vm/precompiled_contracts/__init__.v ./ethereum/paris/vm/precompiled_contracts/mapping.v ./ethereum/paris/vm/precompiled_contracts/modexp.v ./ethereum/paris/vm/precompiled_contracts/ripemd160.v ./ethereum/paris/vm/precompiled_contracts/sha256.v ./ethereum/paris/vm/runtime.v ./ethereum/paris/vm/stack.v ./ethereum/rlp.v ./ethereum/shanghai/blocks.v ./ethereum/shanghai/bloom.v ./ethereum/shanghai/fork_types.v ./ethereum/shanghai/fork.v ./ethereum/shanghai/__init__.v ./ethereum/shanghai/state.v ./ethereum/shanghai/transactions.v ./ethereum/shanghai/trie.v ./ethereum/shanghai/utils/address.v ./ethereum/shanghai/utils/hexadecimal.v ./ethereum/shanghai/utils/__init__.v ./ethereum/shanghai/utils/message.v ./ethereum/shanghai/vm/exceptions.v ./ethereum/shanghai/vm/__init__.v ./ethereum/shanghai/vm/instructions/arithmetic.v ./ethereum/shanghai/vm/instructions/bitwise.v ./ethereum/shanghai/vm/instructions/block.v ./ethereum/shanghai/vm/instructions/comparison.v ./ethereum/shanghai/vm/instructions/control_flow.v ./ethereum/shanghai/vm/instructions/environment.v ./ethereum/shanghai/vm/instructions/__init__.v ./ethereum/shanghai/vm/instructions/keccak.v ./ethereum/shanghai/vm/instructions/log.v ./ethereum/shanghai/vm/instructions/memory.v ./ethereum/shanghai/vm/instructions/stack.v ./ethereum/shanghai/vm/instructions/storage.v ./ethereum/shanghai/vm/interpreter.v ./ethereum/shanghai/vm/memory.v ./ethereum/shanghai/vm/precompiled_contracts/alt_bn128.v ./ethereum/shanghai/vm/precompiled_contracts/blake2f.v ./ethereum/shanghai/vm/precompiled_contracts/ecrecover.v ./ethereum/shanghai/vm/precompiled_contracts/identity.v ./ethereum/shanghai/vm/precompiled_contracts/__init__.v ./ethereum/shanghai/vm/precompiled_contracts/mapping.v ./ethereum/shanghai/vm/precompiled_contracts/modexp.v ./ethereum/shanghai/vm/precompiled_contracts/ripemd160.v ./ethereum/shanghai/vm/precompiled_contracts/sha256.v ./ethereum/shanghai/vm/runtime.v ./ethereum/shanghai/vm/stack.v ./ethereum/spurious_dragon/blocks.v ./ethereum/spurious_dragon/bloom.v ./ethereum/spurious_dragon/fork_types.v ./ethereum/spurious_dragon/fork.v ./ethereum/spurious_dragon/__init__.v ./ethereum/spurious_dragon/state.v ./ethereum/spurious_dragon/transactions.v ./ethereum/spurious_dragon/trie.v ./ethereum/spurious_dragon/utils/address.v ./ethereum/spurious_dragon/utils/hexadecimal.v ./ethereum/spurious_dragon/utils/__init__.v ./ethereum/spurious_dragon/utils/message.v ./ethereum/spurious_dragon/vm/exceptions.v ./ethereum/spurious_dragon/vm/__init__.v ./ethereum/spurious_dragon/vm/instructions/arithmetic.v ./ethereum/spurious_dragon/vm/instructions/bitwise.v ./ethereum/spurious_dragon/vm/instructions/block.v ./ethereum/spurious_dragon/vm/instructions/comparison.v ./ethereum/spurious_dragon/vm/instructions/control_flow.v ./ethereum/spurious_dragon/vm/instructions/environment.v ./ethereum/spurious_dragon/vm/instructions/__init__.v ./ethereum/spurious_dragon/vm/instructions/keccak.v ./ethereum/spurious_dragon/vm/instructions/log.v ./ethereum/spurious_dragon/vm/instructions/memory.v ./ethereum/spurious_dragon/vm/instructions/stack.v ./ethereum/spurious_dragon/vm/instructions/storage.v ./ethereum/spurious_dragon/vm/interpreter.v ./ethereum/spurious_dragon/vm/memory.v ./ethereum/spurious_dragon/vm/precompiled_contracts/ecrecover.v ./ethereum/spurious_dragon/vm/precompiled_contracts/identity.v ./ethereum/spurious_dragon/vm/precompiled_contracts/__init__.v ./ethereum/spurious_dragon/vm/precompiled_contracts/mapping.v ./ethereum/spurious_dragon/vm/precompiled_contracts/ripemd160.v ./ethereum/spurious_dragon/vm/precompiled_contracts/sha256.v ./ethereum/spurious_dragon/vm/runtime.v ./ethereum/spurious_dragon/vm/stack.v ./ethereum/tangerine_whistle/blocks.v ./ethereum/tangerine_whistle/bloom.v ./ethereum/tangerine_whistle/fork_types.v ./ethereum/tangerine_whistle/fork.v ./ethereum/tangerine_whistle/__init__.v ./ethereum/tangerine_whistle/state.v ./ethereum/tangerine_whistle/transactions.v ./ethereum/tangerine_whistle/trie.v ./ethereum/tangerine_whistle/utils/address.v ./ethereum/tangerine_whistle/utils/hexadecimal.v ./ethereum/tangerine_whistle/utils/__init__.v ./ethereum/tangerine_whistle/utils/message.v ./ethereum/tangerine_whistle/vm/exceptions.v ./ethereum/tangerine_whistle/vm/__init__.v ./ethereum/tangerine_whistle/vm/instructions/arithmetic.v ./ethereum/tangerine_whistle/vm/instructions/bitwise.v ./ethereum/tangerine_whistle/vm/instructions/block.v ./ethereum/tangerine_whistle/vm/instructions/comparison.v ./ethereum/tangerine_whistle/vm/instructions/control_flow.v ./ethereum/tangerine_whistle/vm/instructions/environment.v ./ethereum/tangerine_whistle/vm/instructions/__init__.v ./ethereum/tangerine_whistle/vm/instructions/keccak.v ./ethereum/tangerine_whistle/vm/instructions/log.v ./ethereum/tangerine_whistle/vm/instructions/memory.v ./ethereum/tangerine_whistle/vm/instructions/stack.v ./ethereum/tangerine_whistle/vm/instructions/storage.v ./ethereum/tangerine_whistle/vm/interpreter.v ./ethereum/tangerine_whistle/vm/memory.v ./ethereum/tangerine_whistle/vm/precompiled_contracts/ecrecover.v ./ethereum/tangerine_whistle/vm/precompiled_contracts/identity.v ./ethereum/tangerine_whistle/vm/precompiled_contracts/__init__.v ./ethereum/tangerine_whistle/vm/precompiled_contracts/mapping.v ./ethereum/tangerine_whistle/vm/precompiled_contracts/ripemd160.v ./ethereum/tangerine_whistle/vm/precompiled_contracts/sha256.v ./ethereum/tangerine_whistle/vm/runtime.v ./ethereum/tangerine_whistle/vm/stack.v ./ethereum/trace.v ./ethereum/utils/byte.v ./ethereum/utils/ensure.v ./ethereum/utils/hexadecimal.v ./ethereum/utils/__init__.v ./ethereum/utils/numeric.v ./ethereum/utils/safe_arithmetic.v ./RecordUpdate.v ./typing.v # This file can be created by the user to hook into double colon rules or # add any other Makefile code he may need diff --git a/CoqOfPython/ethereum/__init__.v b/CoqOfPython/ethereum/__init__.v new file mode 100644 index 0000000..b5c42e6 --- /dev/null +++ b/CoqOfPython/ethereum/__init__.v @@ -0,0 +1,56 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +### Introduction + +Seeing as internet connections have been vastly expanding across the +world, spreading information has become as cheap as ever. Bitcoin, for +example, has demonstrated the possibility of creating a decentralized, +trade system that is accessible around the world. Namecoin is another +system that built off of Bitcoin's currency structure to create other +simple technological applications. + +Ethereum's goal is to create a cryptographically secure system in which +any and all types of transaction-based concepts can be built. It provides +an exceptionally accessible and decentralized system to build software +and execute transactions. + +This package contains a reference implementation, written as simply as +possible, to aid in defining the behavior of Ethereum clients. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Definition __version__ : Value.t := M.run ltac:(M.monadic ( + Constant.str "0.1.0" +)). + +Definition EVM_RECURSION_LIMIT : Value.t := M.run ltac:(M.monadic ( + BinOp.mult (| + Constant.int 1024, + Constant.int 12 + |) +)). + +Definition expr_27 : Value.t := + M.call (| + M.get_field (| M.get_name (| globals, "sys" |), "setrecursionlimit" |), + make_list [ + M.call (| + M.get_name (| globals, "max" |), + make_list [ + M.get_name (| globals, "EVM_RECURSION_LIMIT" |); + M.call (| + M.get_field (| M.get_name (| globals, "sys" |), "getrecursionlimit" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |). diff --git a/CoqOfPython/ethereum/arrow_glacier/__init__.v b/CoqOfPython/ethereum/arrow_glacier/__init__.v new file mode 100644 index 0000000..d26a14d --- /dev/null +++ b/CoqOfPython/ethereum/arrow_glacier/__init__.v @@ -0,0 +1,23 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +The Arrow Glacier fork delays the difficulty bomb. There are no other changes +in this fork. +". + +Require ethereum.fork_criteria. +Axiom ethereum_fork_criteria_ByBlockNumber : + IsGlobalAlias globals ethereum.fork_criteria.globals "ByBlockNumber". + +Definition FORK_CRITERIA : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "ByBlockNumber" |), + make_list [ + Constant.int 13773000 + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/arrow_glacier/blocks.v b/CoqOfPython/ethereum/arrow_glacier/blocks.v new file mode 100644 index 0000000..a90217e --- /dev/null +++ b/CoqOfPython/ethereum/arrow_glacier/blocks.v @@ -0,0 +1,95 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +A `Block` is a single link in the chain that is Ethereum. Each `Block` contains +a `Header` and zero or more transactions. Each `Header` contains associated +metadata like the block number, parent block hash, and how much gas was +consumed by its transactions. + +Together, these blocks form a cryptographically secure journal recording the +history of all state transitions that have happened since the genesis of the +chain. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes8 : + IsGlobalAlias globals base_types.globals "Bytes8". +Axiom base_types_Bytes32 : + IsGlobalAlias globals base_types.globals "Bytes32". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require crypto.hash. +Axiom crypto_hash_Hash32 : + IsGlobalAlias globals crypto.hash.globals "Hash32". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Require transactions. +Axiom transactions_LegacyTransaction : + IsGlobalAlias globals transactions.globals "LegacyTransaction". + +Definition Header : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Block : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Log : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Receipt : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. diff --git a/CoqOfPython/ethereum/arrow_glacier/bloom.v b/CoqOfPython/ethereum/arrow_glacier/bloom.v new file mode 100644 index 0000000..04b5d9f --- /dev/null +++ b/CoqOfPython/ethereum/arrow_glacier/bloom.v @@ -0,0 +1,164 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Logs Bloom +^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +This modules defines functions for calculating bloom filters of logs. For the +general theory of bloom filters see e.g. `Wikipedia +`_. Bloom filters are used to allow +for efficient searching of logs by address and/or topic, by rapidly +eliminating blocks and receipts from their search. +". + +Require typing. +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require fork_types. +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". + +Definition add_to_bloom : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "bloom"; "bloom_entry" ] |) in + let _ := Constant.str " + Add a bloom entry to the bloom filter (`bloom`). + + The number of hash functions used is 3. They are calculated by taking the + least significant 11 bits from the first 3 16-bit words of the + `keccak_256()` hash of `bloom_entry`. + + Parameters + ---------- + bloom : + The bloom filter. + bloom_entry : + An entry which is to be added to bloom filter. + " in + let hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "bloom_entry" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "idx" |) in make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ] do + let bit_to_set := + BinOp.bit_and (| + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |):BinOp.add (| + M.get_name (| globals, "idx" |), + Constant.int 2 + |) |) + ], + make_dict [] + |), + Constant.int 2047 + |) in + let bit_index := + BinOp.sub (| + Constant.int 2047, + M.get_name (| globals, "bit_to_set" |) + |) in + let byte_index := + BinOp.floor_div (| + M.get_name (| globals, "bit_index" |), + Constant.int 8 + |) in + let bit_value := + BinOp.l_shift (| + Constant.int 1, + BinOp.sub (| + Constant.int 7, + BinOp.mod_ (| + M.get_name (| globals, "bit_index" |), + Constant.int 8 + |) + |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), + BinOp.bit_or (| + M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), + M.get_name (| globals, "bit_value" |) + |) + |) in + EndFor. + M.pure Constant.None_)). + +Definition logs_bloom : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "logs" ] |) in + let _ := Constant.str " + Obtain the logs bloom from a list of log entries. + + The address and each topic of a log are added to the bloom filter. + + Parameters + ---------- + logs : + List of logs for which the logs bloom is to be obtained. + + Returns + ------- + logs_bloom : `Bloom` + The logs bloom obtained which is 256 bytes with some bits set as per + the caller address and the log topics. + " in +(* At stmt: unsupported node type: AnnAssign *) + For M.get_name (| globals, "log" |) in M.get_name (| globals, "logs" |) do + let _ := M.call (| + M.get_name (| globals, "add_to_bloom" |), + make_list [ + M.get_name (| globals, "bloom" |); + M.get_field (| M.get_name (| globals, "log" |), "address" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "topic" |) in M.get_field (| M.get_name (| globals, "log" |), "topics" |) do + let _ := M.call (| + M.get_name (| globals, "add_to_bloom" |), + make_list [ + M.get_name (| globals, "bloom" |); + M.get_name (| globals, "topic" |) + ], + make_dict [] + |) in + EndFor. + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bloom" |), + make_list [ + M.get_name (| globals, "bloom" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/fork_types.v b/CoqOfPython/ethereum/arrow_glacier/fork_types.v new file mode 100644 index 0000000..d12953d --- /dev/null +++ b/CoqOfPython/ethereum/arrow_glacier/fork_types.v @@ -0,0 +1,102 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Types +^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Types re-used throughout the specification, which are specific to Ethereum. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes20 : + IsGlobalAlias globals base_types.globals "Bytes20". +Axiom base_types_Bytes256 : + IsGlobalAlias globals base_types.globals "Bytes256". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require crypto.hash. +Axiom crypto_hash_Hash32 : + IsGlobalAlias globals crypto.hash.globals "Hash32". +Axiom crypto_hash_keccak256 : + IsGlobalAlias globals crypto.hash.globals "keccak256". + +Definition Address : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Bytes20" |) +)). + +Definition Root : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Hash32" |) +)). + +Definition Bloom : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Bytes256" |) +)). + +Definition Account : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition EMPTY_ACCOUNT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Account" |), + make_list [], + make_dict [] + |) +)). + +Definition encode_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "raw_account_data"; "storage_root" ] |) in + let _ := Constant.str " + Encode `Account` dataclass. + + Storage is not stored in the `Account` dataclass, so `Accounts` cannot be + encoded with providing a storage root. + " in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "raw_account_data" |), "nonce" |); M.get_field (| M.get_name (| globals, "raw_account_data" |), "balance" |); M.get_name (| globals, "storage_root" |); M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_field (| M.get_name (| globals, "raw_account_data" |), "code" |) + ], + make_dict [] + |) ] + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/state.v b/CoqOfPython/ethereum/arrow_glacier/state.v new file mode 100644 index 0000000..7b038e5 --- /dev/null +++ b/CoqOfPython/ethereum/arrow_glacier/state.v @@ -0,0 +1,1184 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +State +^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The state contains all information that is preserved between transactions. + +It consists of a main account trie and storage tries for each contract. + +There is a distinction between an account that does not exist and +`EMPTY_ACCOUNT`. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_field : + IsGlobalAlias globals dataclasses.globals "field". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_modify : + IsGlobalAlias globals ethereum.base_types.globals "modify". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require fork_types. +Axiom fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". +Axiom fork_types_Account : + IsGlobalAlias globals fork_types.globals "Account". +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Require trie. +Axiom trie_EMPTY_TRIE_ROOT : + IsGlobalAlias globals trie.globals "EMPTY_TRIE_ROOT". +Axiom trie_Trie : + IsGlobalAlias globals trie.globals "Trie". +Axiom trie_copy_trie : + IsGlobalAlias globals trie.globals "copy_trie". +Axiom trie_root : + IsGlobalAlias globals trie.globals "root". +Axiom trie_trie_get : + IsGlobalAlias globals trie.globals "trie_get". +Axiom trie_trie_set : + IsGlobalAlias globals trie.globals "trie_set". + +Definition State : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition close_state : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Free resources held by the state. Used by optimized implementations to + release file descriptors. + " in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) |) in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |) in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |) |) in + M.pure Constant.None_)). + +Definition begin_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Start a state transaction. + + Transactions are entirely implicit and can be nested. It is not possible to + calculate the state root during a transaction. + + Parameters + ---------- + state : State + The state. + " in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), "append" |), + make_list [ + make_tuple [ M.call (| + M.get_name (| globals, "copy_trie" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) + ], + make_dict [] + |); {M.get_name (| globals, "k" |): M.call (| + M.get_name (| globals, "copy_trie" |), + make_list [ + M.get_name (| globals, "t" |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)} ] + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition commit_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Commit a state transaction. + + Parameters + ---------- + state : State + The state. + " in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), "pop" |), + make_list [], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "clear" |), + make_list [], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition rollback_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Rollback a state transaction, resetting the state to the point when the + corresponding `start_transaction()` call was made. + + Parameters + ---------- + state : State + The state. + " in + let _ := M.assign (| + make_tuple [ M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) ], + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), "pop" |), + make_list [], + make_dict [] + |) + |) in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "clear" |), + make_list [], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition get_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Get the `Account` object at an address. Returns `EMPTY_ACCOUNT` if there + is no account at the address. + + Use `get_account_optional()` if you care about the difference between a + non-existent account and `EMPTY_ACCOUNT`. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address to lookup. + + Returns + ------- + account : `Account` + Account at address. + " in + let account := + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "account" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "account" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "EMPTY_ACCOUNT" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition get_account_optional : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Get the `Account` object at an address. Returns `None` (rather than + `EMPTY_ACCOUNT`) if there is no account at the address. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address to lookup. + + Returns + ------- + account : `Account` + Account at address. + " in + let account := + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "account" |) + |) in + M.pure Constant.None_)). + +Definition set_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "account" ] |) in + let _ := Constant.str " + Set the `Account` object at an address. Setting to `None` deletes + the account (but not its storage, see `destroy_account()`). + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address to set. + account : `Account` + Account to set at address. + " in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "account" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition destroy_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Completely remove the account at `address` and all of its storage. + + This function is made available exclusively for the `SELFDESTRUCT` + opcode. It is expected that `SELFDESTRUCT` will be disabled in a future + hardfork and this function will be removed. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of account to destroy. + " in + let _ := M.call (| + M.get_name (| globals, "destroy_storage" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + Constant.None_ + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition destroy_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Completely remove the storage at `address`. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of account whose storage is to be deleted. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition mark_account_created : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Mark an account as having been created in the current transaction. + This information is used by `get_storage_original()` to handle an obscure + edgecase. + + The marker is not removed even if the account creation reverts. Since the + account cannot have had code prior to its creation and can't call + `get_storage_original()`, this is harmless. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of the account that has been created. + " in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition get_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "key" ] |) in + let _ := Constant.str " + Get a value at a storage key on an account. Returns `U256(0)` if the + storage key has not been set previously. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of the account. + key : `Bytes` + Key to lookup. + + Returns + ------- + value : `U256` + Value at the key. + " in + let trie := + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let _ := M.assert (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "U256" |) + ], + make_dict [] + |) |) in + let _ := M.return_ (| + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_)). + +Definition set_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "key"; "value" ] |) in + let _ := Constant.str " + Set a value at a storage key on an account. Setting to `U256(0)` deletes + the key. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of the account. + key : `Bytes` + Key to set. + value : `U256` + Value to set at the key. + " in + let _ := M.assert (| Compare.is_not (| M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), Constant.None_ |) |) in + let trie := + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let trie := + M.call (| + M.get_name (| globals, "Trie" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), + M.get_name (| globals, "trie" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "key" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), {} |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition storage_root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Calculate the storage root of an account. + + Parameters + ---------- + state: + The state + address : + Address of the account. + + Returns + ------- + root : `Root` + Storage root of the account. + " in + let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "EMPTY_TRIE_ROOT" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition state_root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Calculate the state root. + + Parameters + ---------- + state: + The current state. + + Returns + ------- + root : `Root` + The state root. + " in + let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition account_exists : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account exists in the state trie + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + account_exists : `bool` + True if account exists in the state trie, False otherwise + " in + let _ := M.return_ (| + Compare.is_not (| M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), Constant.None_ |) + |) in + M.pure Constant.None_)). + +Definition account_has_code_or_nonce : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account has non zero nonce or non empty code + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + has_code_or_nonce : `bool` + True if if an account has non zero nonce or non empty code, + False otherwise. + " in + let account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + BoolOp.or (| + Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |) + )) + |) + |) in + M.pure Constant.None_)). + +Definition is_account_empty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account has zero nonce, empty code and zero balance. + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + is_empty : `bool` + True if if an account has zero nonce, empty code and zero balance, + False otherwise. + " in + let account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + ltac:(M.monadic ( + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + )) + |) + )) + |) + |) in + M.pure Constant.None_)). + +Definition account_exists_and_is_empty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account exists and has zero nonce, empty code and zero + balance. + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + exists_and_is_empty : `bool` + True if an account exists and has zero nonce, empty code and zero + balance, False otherwise. + " in + let account := + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + BoolOp.and (| + Compare.is_not (| M.get_name (| globals, "account" |), Constant.None_ |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + ltac:(M.monadic ( + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + )) + |) + )) + |) + )) + |) + |) in + M.pure Constant.None_)). + +Definition is_account_alive : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Check whether is an account is both in the state and non empty. + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + is_alive : `bool` + True if the account is alive. + " in + let account := + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "account" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + UnOp.not (| BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + ltac:(M.monadic ( + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + )) + |) + )) + |) |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition modify_state : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "f" ] |) in + let _ := Constant.str " + Modify an `Account` in the `State`. + " in + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.call (| + M.get_name (| globals, "modify" |), + make_list [ + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |); + M.get_name (| globals, "f" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition move_ether : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "sender_address"; "recipient_address"; "amount" ] |) in + let _ := Constant.str " + Move funds between accounts. + " in +(* At stmt: unsupported node type: FunctionDef *) +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "sender_address" |); + M.get_name (| globals, "reduce_sender_balance" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "recipient_address" |); + M.get_name (| globals, "increase_recipient_balance" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition set_account_balance : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "amount" ] |) in + let _ := Constant.str " + Sets the balance of an account. + + Parameters + ---------- + state: + The current state. + + address: + Address of the account whose nonce needs to be incremented. + + amount: + The amount that needs to set in balance. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "set_balance" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition touch_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Initializes an account to state. + + Parameters + ---------- + state: + The current state. + + address: + The address of the account that need to initialised. + " in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "account_exists" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "EMPTY_ACCOUNT" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition increment_nonce : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Increments the nonce of an account. + + Parameters + ---------- + state: + The current state. + + address: + Address of the account whose nonce needs to be incremented. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "increase_nonce" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition set_code : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "code" ] |) in + let _ := Constant.str " + Sets Account code. + + Parameters + ---------- + state: + The current state. + + address: + Address of the account whose code needs to be update. + + code: + The bytecode that needs to be set. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "write_code" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition create_ether : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "amount" ] |) in + let _ := Constant.str " + Add newly created ether to an account. + + Parameters + ---------- + state: + The current state. + address: + Address of the account to which ether is added. + amount: + The amount of ether to be added to the account of interest. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "increase_balance" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition get_storage_original : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "key" ] |) in + let _ := Constant.str " + Get the original value in a storage slot i.e. the value before the current + transaction began. This function reads the value from the snapshots taken + before executing the transaction. + + Parameters + ---------- + state: + The current state. + address: + Address of the account to read the value from. + key: + Key of the storage slot. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "_" |); M.get_name (| globals, "original_trie" |) ], + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), Constant.int 0 |) + |) in + let original_account_trie := + M.call (| + M.get_field (| M.get_name (| globals, "original_trie" |), "get" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "original_account_trie" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let original_value := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let original_value := + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_name (| globals, "original_account_trie" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.assert (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "original_value" |); + M.get_name (| globals, "U256" |) + ], + make_dict [] + |) |) in + let _ := M.return_ (| + M.get_name (| globals, "original_value" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/transactions.v b/CoqOfPython/ethereum/arrow_glacier/transactions.v new file mode 100644 index 0000000..56996d9 --- /dev/null +++ b/CoqOfPython/ethereum/arrow_glacier/transactions.v @@ -0,0 +1,274 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Transactions are atomic units of work created externally to Ethereum and +submitted to be executed. If Ethereum is viewed as a state machine, +transactions are the events that move between states. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U64 : + IsGlobalAlias globals base_types.globals "U64". +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes0 : + IsGlobalAlias globals base_types.globals "Bytes0". +Axiom base_types_Bytes32 : + IsGlobalAlias globals base_types.globals "Bytes32". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require exceptions. +Axiom exceptions_InvalidBlock : + IsGlobalAlias globals exceptions.globals "InvalidBlock". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( + Constant.int 21000 +)). + +Definition TX_DATA_COST_PER_NON_ZERO : Value.t := M.run ltac:(M.monadic ( + Constant.int 16 +)). + +Definition TX_DATA_COST_PER_ZERO : Value.t := M.run ltac:(M.monadic ( + Constant.int 4 +)). + +Definition TX_CREATE_COST : Value.t := M.run ltac:(M.monadic ( + Constant.int 32000 +)). + +Definition TX_ACCESS_LIST_ADDRESS_COST : Value.t := M.run ltac:(M.monadic ( + Constant.int 2400 +)). + +Definition TX_ACCESS_LIST_STORAGE_KEY_COST : Value.t := M.run ltac:(M.monadic ( + Constant.int 1900 +)). + +Definition LegacyTransaction : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition AccessListTransaction : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition FeeMarketTransaction : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Transaction : Value.t := M.run ltac:(M.monadic ( + M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "AccessListTransaction" |); M.get_name (| globals, "FeeMarketTransaction" |) ] |) +)). + +Definition encode_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Encode a transaction. Needed because non-legacy transactions aren't RLP. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "LegacyTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "tx" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "AccessListTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + (* At constant: unsupported node type: Constant *), + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "FeeMarketTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + (* At constant: unsupported node type: Constant *), + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "Exception" |), + make_list [ + (* At expr: unsupported node type: JoinedStr *) + ], + make_dict [] + |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition decode_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Decode a transaction. Needed because non-legacy transactions aren't RLP. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), Constant.int 1 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), + make_list [ + M.get_name (| globals, "AccessListTransaction" |); + M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 1:(* At expr: unsupported node type: NoneType *) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), Constant.int 2 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), + make_list [ + M.get_name (| globals, "FeeMarketTransaction" |); + M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 1:(* At expr: unsupported node type: NoneType *) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidBlock" |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "tx" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/trie.v b/CoqOfPython/ethereum/arrow_glacier/trie.v new file mode 100644 index 0000000..7ef28ee --- /dev/null +++ b/CoqOfPython/ethereum/arrow_glacier/trie.v @@ -0,0 +1,1357 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +State Trie +^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The state trie is the structure responsible for storing +`.fork_types.Account` objects. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_field : + IsGlobalAlias globals dataclasses.globals "field". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". +Axiom typing_Generic : + IsGlobalAlias globals typing.globals "Generic". +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Mapping : + IsGlobalAlias globals typing.globals "Mapping". +Axiom typing_MutableMapping : + IsGlobalAlias globals typing.globals "MutableMapping". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Sequence : + IsGlobalAlias globals typing.globals "Sequence". +Axiom typing_TypeVar : + IsGlobalAlias globals typing.globals "TypeVar". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". +Axiom typing_cast : + IsGlobalAlias globals typing.globals "cast". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.london. +Axiom ethereum_london_trie : + IsGlobalAlias globals ethereum.london.globals "trie". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require ethereum.utils.hexadecimal. +Axiom ethereum_utils_hexadecimal_hex_to_bytes : + IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require blocks. +Axiom blocks_Receipt : + IsGlobalAlias globals blocks.globals "Receipt". + +Require fork_types. +Axiom fork_types_Account : + IsGlobalAlias globals fork_types.globals "Account". +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". +Axiom fork_types_encode_account : + IsGlobalAlias globals fork_types.globals "encode_account". + +Require transactions. +Axiom transactions_LegacyTransaction : + IsGlobalAlias globals transactions.globals "LegacyTransaction". + +Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Root" |), + make_list [ + M.call (| + M.get_name (| globals, "hex_to_bytes" |), + make_list [ + Constant.str "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" + ], + make_dict [] + |) + ], + make_dict [] + |) +)). + +Definition Node : Value.t := M.run ltac:(M.monadic ( + M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Bytes" |); M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |); Constant.None_ ] |) +)). + +Definition K : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "TypeVar" |), + make_list [ + Constant.str "K" + ], + make_dict [] + |) +)). + +Definition V : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "TypeVar" |), + make_list [ + Constant.str "V"; + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Account" |) |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Bytes" |) |); + M.get_name (| globals, "Bytes" |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Bytes" |) ] |) |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Bytes" |) ] |) |); + M.get_name (| globals, "Uint" |); + M.get_name (| globals, "U256" |) + ], + make_dict [] + |) +)). + +Definition LeafNode : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition ExtensionNode : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition BranchNode : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition InternalNode : Value.t := M.run ltac:(M.monadic ( + M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LeafNode" |); M.get_name (| globals, "ExtensionNode" |); M.get_name (| globals, "BranchNode" |) ] |) +)). + +Definition encode_internal_node : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "node" ] |) in + let _ := Constant.str " + Encodes a Merkle Trie node into its RLP form. The RLP will then be + serialized into a `Bytes` and hashed unless it is less that 32 bytes + when serialized. + + This function also accepts `None`, representing the absence of a node, + which is encoded to `b""""""`. + + Parameters + ---------- + node : Optional[InternalNode] + The node to encode. + + Returns + ------- + encoded : `rlp.RLP` + The node encoded as RLP. + " in +(* At stmt: unsupported node type: AnnAssign *) + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "node" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let unencoded := + (* At constant: unsupported node type: Constant *) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "LeafNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "rest_of_key" |); + Constant.bool true + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "ExtensionNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "key_segment" |); + Constant.bool false + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "BranchNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + BinOp.add (| + M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "value" |) + ] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "AssertionError" |), + make_list [ + (* At expr: unsupported node type: JoinedStr *) + ], + make_dict [] + |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let encoded := + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "unencoded" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded" |) + ], + make_dict [] + |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "unencoded" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "encoded" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition encode_node : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "node"; "storage_root" ] |) in + let _ := Constant.str " + Encode a Node for storage in the Merkle Trie. + + Currently mostly an unimplemented stub. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "storage_root" |), Constant.None_ |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "encode_account" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "storage_root" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "U256" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "cast" |), + make_list [ + M.get_field (| M.get_name (| globals, "rlp" |), "RLP" |); + M.get_name (| globals, "node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "node" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "previous_trie" |), "encode_node" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "storage_root" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition Trie : Value.t := + builtins.make_klass + [(* At base: unsupported node type: Subscript *)] + [ + + ] + [ + + ]. + +Definition copy_trie : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie" ] |) in + let _ := Constant.str " + Create a copy of `trie`. Since only frozen objects may be stored in tries, + the contents are reused. + + Parameters + ---------- + trie: `Trie` + Trie to copy. + + Returns + ------- + new_trie : `Trie[K, V]` + A copy of the trie. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Trie" |), + make_list [ + M.get_field (| M.get_name (| globals, "trie" |), "secured" |); + M.get_field (| M.get_name (| globals, "trie" |), "default" |); + M.call (| + M.get_field (| M.get_name (| globals, "copy" |), "copy" |), + make_list [ + M.get_field (| M.get_name (| globals, "trie" |), "_data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition trie_set : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "key"; "value" ] |) in + let _ := Constant.str " + Stores an item in a Merkle Trie. + + This method deletes the key if `value == trie.default`, because the Merkle + Trie represents the default value by omitting it from the trie. + + Parameters + ---------- + trie: `Trie` + Trie to store in. + key : `Bytes` + Key to lookup. + value : `V` + Node to insert at `key`. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "value" |), M.get_field (| M.get_name (| globals, "trie" |), "default" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "key" |), M.get_field (| M.get_name (| globals, "trie" |), "_data" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition trie_get : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "key" ] |) in + let _ := Constant.str " + Gets an item from the Merkle Trie. + + This method returns `trie.default` if the key is missing. + + Parameters + ---------- + trie: + Trie to lookup in. + key : + Key to lookup. + + Returns + ------- + node : `V` + Node at `key` in the trie. + " in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "get" |), + make_list [ + M.get_name (| globals, "key" |); + M.get_field (| M.get_name (| globals, "trie" |), "default" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition common_prefix_length : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "a"; "b" ] |) in + let _ := Constant.str " + Find the longest common prefix of two sequences. + " in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + ], + make_dict [] + |) do + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| M.get_name (| globals, "i" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition nibble_list_to_compact : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "x"; "is_leaf" ] |) in + let _ := Constant.str " + Compresses nibble-list into a standard byte array with a flag. + + A nibble-list is a list of byte values no greater than `15`. The flag is + encoded in high nibble of the highest byte. The flag nibble can be broken + down into two two-bit flags. + + Highest nibble:: + + +---+---+----------+--------+ + | _ | _ | is_leaf | parity | + +---+---+----------+--------+ + 3 2 1 0 + + + The lowest bit of the nibble encodes the parity of the length of the + remaining nibbles -- `0` when even and `1` when odd. The second lowest bit + is used to distinguish leaf and extension nodes. The other two bits are not + used. + + Parameters + ---------- + x : + Array of nibbles. + is_leaf : + True if this is part of a leaf node, or false if it is an extension + node. + + Returns + ------- + compressed : `bytearray` + Compact byte array. + " in + let compact := + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + Constant.int 2 + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.mult (| + Constant.int 16, + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "is_leaf" |) + |) + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + BinOp.add (| + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "is_leaf" |) + |), + Constant.int 1 + |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), Constant.int 0 |) + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 1; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + M.get_name (| globals, "compact" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition bytes_to_nibble_list : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "bytes_" ] |) in + let _ := Constant.str " + Converts a `Bytes` into to a sequence of nibbles (bytes with value < 16). + + Parameters + ---------- + bytes_: + The `Bytes` to convert. + + Returns + ------- + nibble_list : `Bytes` + The `Bytes` in nibble-list format. + " in + let nibble_list := + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [ + BinOp.mult (| + Constant.int 2, + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "bytes_" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + For make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ] in M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "bytes_" |) + ], + make_dict [] + |) do + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |) |), + BinOp.r_shift (| + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 240 + |), + Constant.int 4 + |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |), + Constant.int 1 + |) |), + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 15 + |) + |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + M.get_name (| globals, "nibble_list" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition _prepare_trie : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "get_storage_root" ] |) in + let _ := Constant.str " + Prepares the trie for root calculation. Removes values that are empty, + hashes the keys (if `secured == True`) and encodes all the nodes. + + Parameters + ---------- + trie : + The `Trie` to prepare. + get_storage_root : + Function to get the storage root of an account. Needed to encode + `Account` objects. + + Returns + ------- + out : `Mapping[ethereum.base_types.Bytes, Node]` + Object with keys mapped to nibble-byte form. + " in +(* At stmt: unsupported node type: AnnAssign *) + For make_tuple [ M.get_name (| globals, "preimage" |); M.get_name (| globals, "value" |) ] in M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "items" |), + make_list [], + make_dict [] + |) do + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in + let address := + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |); + M.call (| + M.get_name (| globals, "get_storage_root" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_eq (| M.get_name (| globals, "encoded_value" |), (* At constant: unsupported node type: Constant *) |); + M.get_name (| globals, "AssertionError" |) + ], + make_dict [] + |) in +(* At stmt: unsupported node type: AnnAssign *) + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "trie" |), "secured" |), + (* then *) + ltac:(M.monadic ( + let key := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let key := + M.get_name (| globals, "preimage" |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "mapped" |), M.call (| + M.get_name (| globals, "bytes_to_nibble_list" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |) |), + M.get_name (| globals, "encoded_value" |) + |) in + EndFor. + let _ := M.return_ (| + M.get_name (| globals, "mapped" |) + |) in + M.pure Constant.None_)). + +Definition root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "get_storage_root" ] |) in + let _ := Constant.str " + Computes the root of a modified merkle patricia trie (MPT). + + Parameters + ---------- + trie : + `Trie` to get the root of. + get_storage_root : + Function to get the storage root of an account. Needed to encode + `Account` objects. + + + Returns + ------- + root : `.fork_types.Root` + MPT root of the underlying key-value pairs. + " in + let obj := + M.call (| + M.get_name (| globals, "_prepare_trie" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "get_storage_root" |) + ], + make_dict [] + |) in + let root_node := + M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_name (| globals, "obj" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assert (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "root_node" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Root" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition patricialize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "obj"; "level" ] |) in + let _ := Constant.str " + Structural composition function. + + Used to recursively patricialize and merkleize a dictionary. Includes + memoization of the tree structure and hashes. + + Parameters + ---------- + obj : + Underlying trie key-value pairs, with keys in nibble-list format. + level : + Current trie level. + + Returns + ------- + node : `ethereum.base_types.Bytes` + Root node of `obj`. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let arbitrary_key := + M.call (| + M.get_name (| globals, "next" |), + make_list [ + M.call (| + M.get_name (| globals, "iter" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), Constant.int 1 |), + (* then *) + ltac:(M.monadic ( + let leaf := + M.call (| + M.get_name (| globals, "LeafNode" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |); + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "leaf" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let substring := + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) in + let prefix_length := + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "substring" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do + let prefix_length := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_name (| globals, "prefix_length" |); + M.call (| + M.get_name (| globals, "common_prefix_length" |), + make_list [ + M.get_name (| globals, "substring" |); + M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let prefix := + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ExtensionNode" |), + make_list [ + M.get_name (| globals, "prefix" |); + M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_name (| globals, "obj" |); + BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in +(* At stmt: unsupported node type: AnnAssign *) + For M.get_name (| globals, "_" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 16 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "branches" |), "append" |), + make_list [ + {} + ], + make_dict [] + |) in + EndFor. + let value := + (* At constant: unsupported node type: Constant *) in + For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |), M.get_name (| globals, "level" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "AssertionError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) + |) in + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "BranchNode" |), + make_list [ + [M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "branches" |), M.get_name (| globals, "k" |) |); + BinOp.add (| + M.get_name (| globals, "level" |), + Constant.int 1 + |) + ], + make_dict [] + |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)]; + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/utils/__init__.v b/CoqOfPython/ethereum/arrow_glacier/utils/__init__.v new file mode 100644 index 0000000..1baedea --- /dev/null +++ b/CoqOfPython/ethereum/arrow_glacier/utils/__init__.v @@ -0,0 +1,8 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Utility functions unique to this particular fork. +". diff --git a/CoqOfPython/ethereum/arrow_glacier/utils/address.v b/CoqOfPython/ethereum/arrow_glacier/utils/address.v new file mode 100644 index 0000000..772eb53 --- /dev/null +++ b/CoqOfPython/ethereum/arrow_glacier/utils/address.v @@ -0,0 +1,204 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Hardfork Utility Functions For Addresses +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Address specific functions used in this arrow_glacier version of +specification. +". + +Require typing. +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_left_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Definition to_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "data" ] |) in + let _ := Constant.str " + Convert a Uint or U256 value to a valid address (20 bytes). + + Parameters + ---------- + data : + The string to be converted to bytes. + + Returns + ------- + address : `Address` + The obtained address. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_subscript (| M.call (| + M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition compute_contract_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "address"; "nonce" ] |) in + let _ := Constant.str " + Computes address of the new account that needs to be created. + + Parameters + ---------- + address : + The address of the account that wants to create the new account. + nonce : + The transaction count of the account that wants to create the new + account. + + Returns + ------- + address: `Address` + The computed address of the new account. + " in + let computed_address := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_list [ + M.get_name (| globals, "address" |); + M.get_name (| globals, "nonce" |) + ] + ], + make_dict [] + |) + ], + make_dict [] + |) in + let canonical_address := + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + let padded_address := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "canonical_address" |); + Constant.int 20 + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "padded_address" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition compute_create2_contract_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "address"; "salt"; "call_data" ] |) in + let _ := Constant.str " + Computes address of the new account that needs to be created, which is + based on the sender address, salt and the call data as well. + + Parameters + ---------- + address : + The address of the account that wants to create the new account. + salt : + Address generation salt. + call_data : + The code of the new account which is to be created. + + Returns + ------- + address: `ethereum.arrow_glacier.fork_types.Address` + The computed address of the new account. + " in + let preimage := + BinOp.add (| + BinOp.add (| + BinOp.add (| + (* At constant: unsupported node type: Constant *), + M.get_name (| globals, "address" |) + |), + M.get_name (| globals, "salt" |) + |), + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "call_data" |) + ], + make_dict [] + |) + |) in + let computed_address := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + let canonical_address := + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + let padded_address := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "canonical_address" |); + Constant.int 20 + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "padded_address" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/utils/hexadecimal.v b/CoqOfPython/ethereum/arrow_glacier/utils/hexadecimal.v new file mode 100644 index 0000000..859b060 --- /dev/null +++ b/CoqOfPython/ethereum/arrow_glacier/utils/hexadecimal.v @@ -0,0 +1,155 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Utility Functions For Hexadecimal Strings +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Hexadecimal utility functions used in this specification, specific to +Arrow Glacier types. +". + +Require ethereum.utils.hexadecimal. +Axiom ethereum_utils_hexadecimal_remove_hex_prefix : + IsGlobalAlias globals ethereum.utils.hexadecimal.globals "remove_hex_prefix". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Definition hex_to_root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to trie root. + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to trie root. + + Returns + ------- + root : `Root` + Trie root obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Root" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition hex_to_bloom : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to bloom. + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to bloom. + + Returns + ------- + bloom : `Bloom` + Bloom obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bloom" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition hex_to_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to Address (20 bytes). + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to Address. + + Returns + ------- + address : `Address` + The address obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |), "rjust" |), + make_list [ + Constant.int 40; + Constant.str "0" + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/utils/message.v b/CoqOfPython/ethereum/arrow_glacier/utils/message.v new file mode 100644 index 0000000..084c3b0 --- /dev/null +++ b/CoqOfPython/ethereum/arrow_glacier/utils/message.v @@ -0,0 +1,254 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Hardfork Utility Functions For The Message Data-structure +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Message specific functions used in this arrow_glacier version of +specification. +". + +Require typing. +Axiom typing_FrozenSet : + IsGlobalAlias globals typing.globals "FrozenSet". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". + +Require vm. +Axiom vm_Environment : + IsGlobalAlias globals vm.globals "Environment". +Axiom vm_Message : + IsGlobalAlias globals vm.globals "Message". + +Require vm.precompiled_contracts.mapping. +Axiom vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : + IsGlobalAlias globals vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". + +Require address. +Axiom address_compute_contract_address : + IsGlobalAlias globals address.globals "compute_contract_address". + +Definition prepare_message : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "caller"; "target"; "value"; "data"; "gas"; "env"; "code_address"; "should_transfer_value"; "is_static"; "preaccessed_addresses"; "preaccessed_storage_keys" ] |) in + let _ := Constant.str " + Execute a transaction against the provided environment. + + Parameters + ---------- + caller : + Address which initiated the transaction + target : + Address whose code will be executed + value : + Value to be transferred. + data : + Array of bytes provided to the code in `target`. + gas : + Gas provided for the code in `target`. + env : + Environment for the Ethereum Virtual Machine. + code_address : + This is usually same as the `target` address except when an alternative + accounts code needs to be executed. + eg. `CALLCODE` calling a precompile. + should_transfer_value : + if True ETH should be transferred while executing a message call. + is_static: + if True then it prevents all state-changing operations from being + executed. + preaccessed_addresses: + Addresses that should be marked as accessed prior to the message call + preaccessed_storage_keys: + Storage keys that should be marked as accessed prior to the message + call + + Returns + ------- + message: `ethereum.arrow_glacier.vm.Message` + Items containing contract creation or message call specific data. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Bytes0" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.call (| + M.get_name (| globals, "compute_contract_address" |), + make_list [ + M.get_name (| globals, "caller" |); + BinOp.sub (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "caller" |) + ], + make_dict [] + |), "nonce" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let msg_data := + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |) in + let code := + M.get_name (| globals, "data" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.get_name (| globals, "target" |) in + let msg_data := + M.get_name (| globals, "data" |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "target" |) + ], + make_dict [] + |), "code" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "code_address" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let code_address := + M.get_name (| globals, "target" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "AssertionError" |), + make_list [ + Constant.str "Target must be address or empty bytes" + ], + make_dict [] + |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let accessed_addresses := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "current_target" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "caller" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "accessed_addresses" |), "update" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "PRE_COMPILED_CONTRACTS" |), "keys" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "accessed_addresses" |), "update" |), + make_list [ + M.get_name (| globals, "preaccessed_addresses" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/__init__.v b/CoqOfPython/ethereum/arrow_glacier/vm/__init__.v new file mode 100644 index 0000000..2ff63cd --- /dev/null +++ b/CoqOfPython/ethereum/arrow_glacier/vm/__init__.v @@ -0,0 +1,262 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The abstract computer which runs the code stored in an +`.fork_types.Account`. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U64 : + IsGlobalAlias globals ethereum.base_types.globals "U64". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_State : + IsGlobalAlias globals state.globals "State". +Axiom state_account_exists_and_is_empty : + IsGlobalAlias globals state.globals "account_exists_and_is_empty". + +Require precompiled_contracts. +Axiom precompiled_contracts_RIPEMD160_ADDRESS : + IsGlobalAlias globals precompiled_contracts.globals "RIPEMD160_ADDRESS". + +Definition __all__ : Value.t := M.run ltac:(M.monadic ( + make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] +)). + +Definition Environment : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Message : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Evm : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition incorporate_child_on_success : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "child_evm" ] |) in + let _ := Constant.str " + Incorporate the state of a successful `child_evm` into the parent `evm`. + + Parameters + ---------- + evm : + The parent `EVM`. + child_evm : + The child evm to incorporate. + " in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "gas_left" |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "logs" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "logs" |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "refund_counter" |) + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "accounts_to_delete" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "accessed_addresses" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "accessed_storage_keys" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition incorporate_child_on_error : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "child_evm" ] |) in + let _ := Constant.str " + Incorporate the state of an unsuccessful `child_evm` into the parent `evm`. + + Parameters + ---------- + evm : + The parent `EVM`. + child_evm : + The child evm to incorporate. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "RIPEMD160_ADDRESS" |), M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |), M.get_name (| globals, "RIPEMD160_ADDRESS" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "gas_left" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/exceptions.v b/CoqOfPython/ethereum/arrow_glacier/vm/exceptions.v new file mode 100644 index 0000000..1f4363d --- /dev/null +++ b/CoqOfPython/ethereum/arrow_glacier/vm/exceptions.v @@ -0,0 +1,172 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Exceptions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Exceptions which cause the EVM to halt exceptionally. +". + +Require ethereum.exceptions. +Axiom ethereum_exceptions_EthereumException : + IsGlobalAlias globals ethereum.exceptions.globals "EthereumException". + +Definition ExceptionalHalt : Value.t := + builtins.make_klass + [(globals, "EthereumException")] + [ + + ] + [ + + ]. + +Definition Revert : Value.t := + builtins.make_klass + [(globals, "EthereumException")] + [ + + ] + [ + + ]. + +Definition StackUnderflowError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition StackOverflowError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition OutOfGasError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition InvalidOpcode : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + ( + "__init__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "code" ] |) in + let _ := M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "super" |), + make_list [], + make_dict [] + |), "__init__" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "self" |), "code" |), + M.get_name (| globals, "code" |) + |) in + M.pure Constant.None_)) + ) + ]. + +Definition InvalidJumpDestError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition StackDepthLimitError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition WriteInStaticContext : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition OutOfBoundsRead : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition InvalidParameter : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition InvalidContractPrefix : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition AddressCollision : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/__init__.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/__init__.v new file mode 100644 index 0000000..e5bebd7 --- /dev/null +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/__init__.v @@ -0,0 +1,87 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +EVM Instruction Encoding (Opcodes) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Machine readable representations of EVM instructions, and a mapping to their +implementations. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". + +Require __init__. +Axiom __init___arithmetic : + IsGlobalAlias globals __init__.globals "arithmetic". + +Require __init__. +Axiom __init___bitwise : + IsGlobalAlias globals __init__.globals "bitwise". + +Require __init__. +Axiom __init___block : + IsGlobalAlias globals __init__.globals "block". + +Require __init__. +Axiom __init___comparison : + IsGlobalAlias globals __init__.globals "comparison". + +Require __init__. +Axiom __init___control_flow : + IsGlobalAlias globals __init__.globals "control_flow". + +Require __init__. +Axiom __init___environment : + IsGlobalAlias globals __init__.globals "environment". + +Require __init__. +Axiom __init___keccak : + IsGlobalAlias globals __init__.globals "keccak". + +Require __init__. +Axiom __init___log : + IsGlobalAlias globals __init__.globals "log". + +Require __init__. +Axiom __init___memory : + IsGlobalAlias globals __init__.globals "memory". + +Require __init__. +Axiom __init___stack : + IsGlobalAlias globals __init__.globals "stack". + +Require __init__. +Axiom __init___storage : + IsGlobalAlias globals __init__.globals "storage". + +Require __init__. +Axiom __init___system : + IsGlobalAlias globals __init__.globals "system". + +Definition Ops : Value.t := + builtins.make_klass + [(* At base: unsupported node type: Attribute *)] + [ + + ] + [ + + ]. + +(* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/arithmetic.v new file mode 100644 index 0000000..a8b5c61 --- /dev/null +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/arithmetic.v @@ -0,0 +1,1085 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Arithmetic Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM Arithmetic instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U255_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U255_CEIL_VALUE". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_U256_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_get_sign : + IsGlobalAlias globals ethereum.utils.numeric.globals "get_sign". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_EXPONENTIATION : + IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION". +Axiom gas_GAS_EXPONENTIATION_PER_BYTE : + IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION_PER_BYTE". +Axiom gas_GAS_LOW : + IsGlobalAlias globals gas.globals "GAS_LOW". +Axiom gas_GAS_MID : + IsGlobalAlias globals gas.globals "GAS_MID". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition add : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Adds the top two elements of the stack together, and pushes the result back + on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "x" |), "wrapping_add" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition sub : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Subtracts the top two elements of the stack, and pushes the result back + on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "x" |), "wrapping_sub" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mul : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Multiply the top two elements of the stack, and pushes the result back + on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "x" |), "wrapping_mul" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition div : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Integer division of the top two elements of the stack. Pushes the result + back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let dividend := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let divisor := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let quotient := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let quotient := + BinOp.floor_div (| + M.get_name (| globals, "dividend" |), + M.get_name (| globals, "divisor" |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "quotient" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition sdiv : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed integer division of the top two elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let dividend := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let divisor := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let quotient := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_name (| globals, "dividend" |), UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "divisor" |), UnOp.sub (| Constant.int 1 |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let quotient := + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let sign := + M.call (| + M.get_name (| globals, "get_sign" |), + make_list [ + BinOp.mult (| + M.get_name (| globals, "dividend" |), + M.get_name (| globals, "divisor" |) + |) + ], + make_dict [] + |) in + let quotient := + BinOp.mult (| + M.get_name (| globals, "sign" |), + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "dividend" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "divisor" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + M.get_name (| globals, "quotient" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Modulo remainder of the top two elements of the stack. Pushes the result + back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let remainder := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let remainder := + BinOp.mod_ (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "remainder" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition smod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed modulo remainder of the top two elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let y := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let remainder := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let remainder := + BinOp.mult (| + M.call (| + M.get_name (| globals, "get_sign" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + BinOp.mod_ (| + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + M.get_name (| globals, "remainder" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition addmod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Modulo addition of the top 2 elements with the 3rd element. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let z := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_MID" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.add (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |), + M.get_name (| globals, "z" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mulmod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Modulo multiplication of the top 2 elements with the 3rd element. Pushes + the result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let z := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_MID" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.mult (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |), + M.get_name (| globals, "z" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition exp : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Exponential operation of the top 2 elements. Pushes the result back on + the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let base := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exponent := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exponent_bits := + M.call (| + M.get_field (| M.get_name (| globals, "exponent" |), "bit_length" |), + make_list [], + make_dict [] + |) in + let exponent_bytes := + BinOp.floor_div (| + BinOp.add (| + M.get_name (| globals, "exponent_bits" |), + Constant.int 7 + |), + Constant.int 8 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_EXPONENTIATION" |), + BinOp.mult (| + M.get_name (| globals, "GAS_EXPONENTIATION_PER_BYTE" |), + M.get_name (| globals, "exponent_bytes" |) + |) + |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "pow" |), + make_list [ + M.get_name (| globals, "base" |); + M.get_name (| globals, "exponent" |); + M.get_name (| globals, "U256_CEIL_VALUE" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition signextend : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Sign extend operation. In other words, extend a signed number which + fits in N bytes to 32 bytes. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let byte_num := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "byte_num" |), Constant.int 31 |), + (* then *) + ltac:(M.monadic ( + let result := + M.get_name (| globals, "value" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let value_bytes := + M.call (| + M.get_name (| globals, "bytes" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "value" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) in + let value_bytes := + M.get_subscript (| M.get_name (| globals, "value_bytes" |), BinOp.sub (| + Constant.int 31, + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "byte_num" |) + ], + make_dict [] + |) + |):(* At expr: unsupported node type: NoneType *) |) in + let sign_bit := + BinOp.r_shift (| + M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), + Constant.int 7 + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "sign_bit" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "value_bytes" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let num_bytes_prepend := + BinOp.sub (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "byte_num" |), + Constant.int 1 + |) + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + BinOp.add (| + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [ + BinOp.mult (| + make_list [ + Constant.int 255 + ], + M.get_name (| globals, "num_bytes_prepend" |) + |) + ], + make_dict [] + |), + M.get_name (| globals, "value_bytes" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/bitwise.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/bitwise.v new file mode 100644 index 0000000..9f2f382 --- /dev/null +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/bitwise.v @@ -0,0 +1,601 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Bitwise Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM bitwise instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_U256_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition bitwise_and : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise AND operation of the top 2 elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + BinOp.bit_and (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_or : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise OR operation of the top 2 elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + BinOp.bit_or (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_xor : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise XOR operation of the top 2 elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + BinOp.bit_xor (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_not : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise NOT operation of the top element of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + UnOp.invert (| M.get_name (| globals, "x" |) |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition get_byte : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + For a word (defined by next top element of the stack), retrieve the + Nth byte (0-indexed and defined by top element of stack) from the + left (most significant) to right (least significant). + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let byte_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let word := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "byte_index" |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let extra_bytes_to_right := + BinOp.sub (| + Constant.int 31, + M.get_name (| globals, "byte_index" |) + |) in + let word := + BinOp.r_shift (| + M.get_name (| globals, "word" |), + BinOp.mult (| + M.get_name (| globals, "extra_bytes_to_right" |), + Constant.int 8 + |) + |) in + let word := + BinOp.bit_and (| + M.get_name (| globals, "word" |), + Constant.int 255 + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "word" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_shl : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Logical shift left (SHL) operation of the top 2 elements of the stack. + Pushes the result back on the stack. + Parameters + ---------- + evm : + The current EVM frame. + " in + let shift := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.l_shift (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "shift" |) + |), + M.get_name (| globals, "U256_CEIL_VALUE" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_shr : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Logical shift right (SHR) operation of the top 2 elements of the stack. + Pushes the result back on the stack. + Parameters + ---------- + evm : + The current EVM frame. + " in + let shift := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), + (* then *) + ltac:(M.monadic ( + let result := + BinOp.r_shift (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "shift" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_sar : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Arithmetic shift right (SAR) operation of the top 2 elements of the stack. + Pushes the result back on the stack. + Parameters + ---------- + evm : + The current EVM frame. + " in + let shift := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let signed_value := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + BinOp.r_shift (| + M.get_name (| globals, "signed_value" |), + M.get_name (| globals, "shift" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "signed_value" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/block.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/block.v new file mode 100644 index 0000000..26c73a7 --- /dev/null +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/block.v @@ -0,0 +1,379 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Block Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM block instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_BLOCK_HASH : + IsGlobalAlias globals gas.globals "GAS_BLOCK_HASH". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition block_hash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the hash of one of the 256 most recent complete blocks onto the + stack. The block number to hash is present at the top of the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let block_number := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BLOCK_HASH" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt_e (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), M.get_name (| globals, "block_number" |) |), + ltac:(M.monadic ( + Compare.gt (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), BinOp.add (| + M.get_name (| globals, "block_number" |), + Constant.int 256 + |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let hash := + (* At constant: unsupported node type: Constant *) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let hash := + M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + M.get_name (| globals, "block_number" |) + |) |) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "hash" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition coinbase : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's beneficiary address (address of the block miner) + onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "coinbase" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition timestamp : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's timestamp onto the stack. Here the timestamp + being referred is actually the unix timestamp in seconds. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "time" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition number : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's number onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition difficulty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's difficulty onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "difficulty" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition gas_limit : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's gas limit onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "gas_limit" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition chain_id : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the chain id onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "chain_id" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/comparison.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/comparison.v new file mode 100644 index 0000000..fbc35f8 --- /dev/null +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/comparison.v @@ -0,0 +1,404 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Comparison Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM Comparison instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition less_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is less than the next top element. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let right := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition signed_less_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed less-than comparison. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let right := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition greater_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is greater than the next top element. Pushes + the result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let right := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition signed_greater_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed greater-than comparison. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let right := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition equal : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is equal to the next top element. Pushes + the result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let right := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.eq (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition is_zero : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is equal to 0. Pushes the result back on the + stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.eq (| M.get_name (| globals, "x" |), Constant.int 0 |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/control_flow.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/control_flow.v new file mode 100644 index 0000000..04a79d9 --- /dev/null +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/control_flow.v @@ -0,0 +1,336 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Control Flow Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM control flow instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require vm.gas. +Axiom vm_gas_GAS_BASE : + IsGlobalAlias globals vm.gas.globals "GAS_BASE". +Axiom vm_gas_GAS_HIGH : + IsGlobalAlias globals vm.gas.globals "GAS_HIGH". +Axiom vm_gas_GAS_JUMPDEST : + IsGlobalAlias globals vm.gas.globals "GAS_JUMPDEST". +Axiom vm_gas_GAS_MID : + IsGlobalAlias globals vm.gas.globals "GAS_MID". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_InvalidJumpDestError : + IsGlobalAlias globals exceptions.globals "InvalidJumpDestError". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition stop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stop further execution of EVM code. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let _ := M.pass (| |) in + let _ := M.pass (| |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "running" |), + Constant.bool false + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition jump : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Alter the program counter to the location specified by the top of the + stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let jump_dest := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_MID" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "jump_dest" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition jumpi : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Alter the program counter to the specified location if and only if a + condition is true. If the condition is not true, then the program counter + would increase only by 1. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let jump_dest := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let conditional_value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_HIGH" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "conditional_value" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let destination := + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let destination := + M.get_name (| globals, "jump_dest" |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "destination" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition pc : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push onto the stack the value of the program counter after reaching the + current instruction and without increasing it for the next instruction. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "pc" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition gas_left : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the amount of available gas (including the corresponding reduction + for the cost of this instruction) onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition jumpdest : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Mark a valid destination for jumps. This is a noop, present only + to be used by `JUMP` and `JUMPI` opcodes to verify that their jump is + valid. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_JUMPDEST" |) + ], + make_dict [] + |) in + let _ := M.pass (| |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/environment.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/environment.v new file mode 100644 index 0000000..530304e --- /dev/null +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/environment.v @@ -0,0 +1,1436 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Environmental Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM environment related instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require fork_types. +Axiom fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". + +Require state. +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". + +Require utils.address. +Axiom utils_address_to_address : + IsGlobalAlias globals utils.address.globals "to_address". + +Require vm.memory. +Axiom vm_memory_buffer_read : + IsGlobalAlias globals vm.memory.globals "buffer_read". +Axiom vm_memory_memory_write : + IsGlobalAlias globals vm.memory.globals "memory_write". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_OutOfBoundsRead : + IsGlobalAlias globals exceptions.globals "OutOfBoundsRead". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_COLD_ACCOUNT_ACCESS : + IsGlobalAlias globals gas.globals "GAS_COLD_ACCOUNT_ACCESS". +Axiom gas_GAS_COPY : + IsGlobalAlias globals gas.globals "GAS_COPY". +Axiom gas_GAS_FAST_STEP : + IsGlobalAlias globals gas.globals "GAS_FAST_STEP". +Axiom gas_GAS_RETURN_DATA_COPY : + IsGlobalAlias globals gas.globals "GAS_RETURN_DATA_COPY". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_GAS_WARM_ACCESS : + IsGlobalAlias globals gas.globals "GAS_WARM_ACCESS". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the address of the current executing account to the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition balance : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the balance of the given account onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "balance" |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "balance" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition origin : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the address of the original transaction sender to the stack. + The origin address can only be an EOA. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "origin" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition caller : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the address of the caller onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "caller" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition callvalue : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the value (in wei) sent with the call onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition calldataload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push a word (32 bytes) of the input data belonging to the current + environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |); + M.get_name (| globals, "start_index" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition calldatasize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the size of input data in current environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition calldatacopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy a portion of the input data in current environment to memory. + + This will also expand the memory, in case that the memory is insufficient + to store the data. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let data_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |); + M.get_name (| globals, "data_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition codesize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the size of code running in current environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "code" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition codecopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy a portion of the code in current environment to memory. + + This will also expand the memory, in case that the memory is insufficient + to store the data. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let code_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "code" |); + M.get_name (| globals, "code_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition gasprice : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the gas price used in current environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "gas_price" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition extcodesize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the code size of a given account onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let codesize := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "code" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "codesize" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition extcodecopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy a portion of an account's code to memory. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let code_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_WARM_ACCESS" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "code" |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "code" |); + M.get_name (| globals, "code_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition returndatasize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the size of the return data buffer onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition returndatacopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copies data from the return data buffer code to memory + + Parameters + ---------- + evm : + The current EVM frame. + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let return_data_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_RETURN_DATA_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "return_data_start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "OutOfBoundsRead" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |):BinOp.add (| + M.get_name (| globals, "return_data_start_position" |), + M.get_name (| globals, "size" |) + |) |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition extcodehash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Returns the keccak256 hash of a contract’s bytecode + Parameters + ---------- + evm : + The current EVM frame. + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "account" |), M.get_name (| globals, "EMPTY_ACCOUNT" |) |), + (* then *) + ltac:(M.monadic ( + let codehash := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let codehash := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_field (| M.get_name (| globals, "account" |), "code" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "codehash" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition self_balance : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the balance of the current address to the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_FAST_STEP" |) + ], + make_dict [] + |) in + let balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "balance" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition base_fee : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the base fee of the current block on to the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "base_fee_per_gas" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/keccak.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/keccak.v new file mode 100644 index 0000000..cab9ffb --- /dev/null +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/keccak.v @@ -0,0 +1,181 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Keccak Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM keccak instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_KECCAK256 : + IsGlobalAlias globals gas.globals "GAS_KECCAK256". +Axiom gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition keccak : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes to the stack the Keccak-256 hash of a region of memory. + + This also expands the memory, in case the memory is insufficient to + access the data's memory location. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let word_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_KECCAK256_WORD" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_KECCAK256" |), + M.get_name (| globals, "word_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let data := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "hash" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/log.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/log.v new file mode 100644 index 0000000..4891a4d --- /dev/null +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/log.v @@ -0,0 +1,244 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Logging Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM logging instructions. +". + +Require functools. +Axiom functools_partial : + IsGlobalAlias globals functools.globals "partial". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_WriteInStaticContext : + IsGlobalAlias globals exceptions.globals "WriteInStaticContext". + +Require gas. +Axiom gas_GAS_LOG : + IsGlobalAlias globals gas.globals "GAS_LOG". +Axiom gas_GAS_LOG_DATA : + IsGlobalAlias globals gas.globals "GAS_LOG_DATA". +Axiom gas_GAS_LOG_TOPIC : + IsGlobalAlias globals gas.globals "GAS_LOG_TOPIC". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". + +Definition log_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "num_topics" ] |) in + let _ := Constant.str " + Appends a log entry, having `num_topics` topics, to the evm logs. + + This will also expand the memory if the data (required by the log entry) + corresponding to the memory is not accessible. + + Parameters + ---------- + evm : + The current EVM frame. + num_topics : + The number of topics to be included in the log entry. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let topics := + make_list [] in + For M.get_name (| globals, "_" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "num_topics" |) + ], + make_dict [] + |) do + let topic := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "topics" |), "append" |), + make_list [ + M.get_name (| globals, "topic" |) + ], + make_dict [] + |) in + EndFor. + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_LOG" |), + BinOp.mult (| + M.get_name (| globals, "GAS_LOG_DATA" |), + M.get_name (| globals, "size" |) + |) + |), + BinOp.mult (| + M.get_name (| globals, "GAS_LOG_TOPIC" |), + M.get_name (| globals, "num_topics" |) + |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let log_entry := + M.call (| + M.get_name (| globals, "Log" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "logs" |), + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "logs" |), + make_tuple [ M.get_name (| globals, "log_entry" |) ] + |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition log0 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/memory.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/memory.v new file mode 100644 index 0000000..1e1c8b0 --- /dev/null +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/memory.v @@ -0,0 +1,378 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Memory Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM Memory instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". +Axiom memory_memory_write : + IsGlobalAlias globals memory.globals "memory_write". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition mstore : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a word to memory. + This also expands the memory, if the memory is + insufficient to store the word. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "start_position" |); M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + ], + make_dict [] + |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "start_position" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mstore8 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a byte to memory. + This also expands the memory, if the memory is + insufficient to store the word. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "start_position" |); M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let normalized_bytes_value := + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + make_list [ + BinOp.bit_and (| + M.get_name (| globals, "value" |), + Constant.int 255 + |) + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "start_position" |); + M.get_name (| globals, "normalized_bytes_value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Load word from memory. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "start_position" |); M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "start_position" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition msize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the size of active memory in bytes onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/stack.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/stack.v new file mode 100644 index 0000000..1eeda05 --- /dev/null +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/stack.v @@ -0,0 +1,929 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Stack Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM stack related instructions. +". + +Require functools. +Axiom functools_partial : + IsGlobalAlias globals functools.globals "partial". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". +Axiom __init___stack : + IsGlobalAlias globals __init__.globals "stack". + +Require exceptions. +Axiom exceptions_StackUnderflowError : + IsGlobalAlias globals exceptions.globals "StackUnderflowError". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_buffer_read : + IsGlobalAlias globals memory.globals "buffer_read". + +Definition pop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Remove item from stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.pass (| |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition push_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "num_bytes" ] |) in + let _ := Constant.str " + Pushes a N-byte immediate onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + num_bytes : + The number of immediate bytes to be read from the code and pushed to + the stack. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let data_to_push := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "code" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "num_bytes" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "data_to_push" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + BinOp.add (| + Constant.int 1, + M.get_name (| globals, "num_bytes" |) + |) + |) in + M.pure Constant.None_)). + +Definition dup_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "item_number" ] |) in + let _ := Constant.str " + Duplicate the Nth stack item (from top of the stack) to the top of stack. + + Parameters + ---------- + evm : + The current EVM frame. + + item_number : + The stack item number (0-indexed from top of stack) to be duplicated + to the top of stack. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "StackUnderflowError" |) + ], + make_dict [] + |) in + let data_to_duplicate := + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + BinOp.sub (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), + Constant.int 1 + |), + M.get_name (| globals, "item_number" |) + |) |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "data_to_duplicate" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition swap_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "item_number" ] |) in + let _ := Constant.str " + Swap the top and the `item_number` element of the stack, where + the top of the stack is position zero. + + If `item_number` is zero, this function does nothing (which should not be + possible, since there is no `SWAP0` instruction). + + Parameters + ---------- + evm : + The current EVM frame. + + item_number : + The stack item number (0-indexed from top of stack) to be swapped + with the top of stack element. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "StackUnderflowError" |) + ], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) |) ], + make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |) ] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition push1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push5 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push6 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push7 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push8 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push9 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push10 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push11 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push12 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push13 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push14 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push15 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push16 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push17 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push18 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push19 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push20 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push21 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push22 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push23 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push24 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push25 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push26 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push27 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push28 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push29 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push30 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push31 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push32 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition dup1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup5 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup6 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup7 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup8 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup9 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup10 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup11 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup12 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup13 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup14 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup15 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup16 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition swap1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap5 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap6 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap7 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap8 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap9 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap10 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap11 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap12 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap13 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap14 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap15 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap16 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/storage.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/storage.v new file mode 100644 index 0000000..2f0a831 --- /dev/null +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/storage.v @@ -0,0 +1,437 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Storage Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM storage related instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require state. +Axiom state_get_storage : + IsGlobalAlias globals state.globals "get_storage". +Axiom state_get_storage_original : + IsGlobalAlias globals state.globals "get_storage_original". +Axiom state_set_storage : + IsGlobalAlias globals state.globals "set_storage". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". +Axiom exceptions_WriteInStaticContext : + IsGlobalAlias globals exceptions.globals "WriteInStaticContext". + +Require gas. +Axiom gas_GAS_CALL_STIPEND : + IsGlobalAlias globals gas.globals "GAS_CALL_STIPEND". +Axiom gas_GAS_COLD_SLOAD : + IsGlobalAlias globals gas.globals "GAS_COLD_SLOAD". +Axiom gas_GAS_STORAGE_CLEAR_REFUND : + IsGlobalAlias globals gas.globals "GAS_STORAGE_CLEAR_REFUND". +Axiom gas_GAS_STORAGE_SET : + IsGlobalAlias globals gas.globals "GAS_STORAGE_SET". +Axiom gas_GAS_STORAGE_UPDATE : + IsGlobalAlias globals gas.globals "GAS_STORAGE_UPDATE". +Axiom gas_GAS_WARM_ACCESS : + IsGlobalAlias globals gas.globals "GAS_WARM_ACCESS". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition sload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Loads to the stack, the value corresponding to a certain key from the + storage of the current account. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let key := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "add" |), + make_list [ + make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_COLD_SLOAD" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let value := + M.call (| + M.get_name (| globals, "get_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition sstore : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a value at a certain key in the current context's storage. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let key := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let new_value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt (| M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), M.get_name (| globals, "GAS_CALL_STIPEND" |) |); + M.get_name (| globals, "OutOfGasError" |) + ], + make_dict [] + |) in + let original_value := + M.call (| + M.get_name (| globals, "get_storage_original" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let current_value := + M.call (| + M.get_name (| globals, "get_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let gas_cost := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "add" |), + make_list [ + make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ] + ], + make_dict [] + |) in + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_COLD_SLOAD" |) + M.get_name (| globals, "GAS_COLD_SLOAD" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_name (| globals, "original_value" |), M.get_name (| globals, "current_value" |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_name (| globals, "current_value" |), M.get_name (| globals, "new_value" |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_STORAGE_SET" |) + M.get_name (| globals, "GAS_STORAGE_SET" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let gas_cost := BinOp.add + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_UPDATE" |), + M.get_name (| globals, "GAS_COLD_SLOAD" |) + |) + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_UPDATE" |), + M.get_name (| globals, "GAS_COLD_SLOAD" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_WARM_ACCESS" |) + M.get_name (| globals, "GAS_WARM_ACCESS" |) in + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| M.get_name (| globals, "current_value" |), M.get_name (| globals, "new_value" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "new_value" |), Constant.int 0 |) + )) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.sub, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "original_value" |), M.get_name (| globals, "new_value" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_SET" |), + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.sub (| + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_UPDATE" |), + M.get_name (| globals, "GAS_COLD_SLOAD" |) + |), + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "gas_cost" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "set_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |); + M.get_name (| globals, "new_value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/interpreter.v b/CoqOfPython/ethereum/arrow_glacier/vm/interpreter.v new file mode 100644 index 0000000..8179355 --- /dev/null +++ b/CoqOfPython/ethereum/arrow_glacier/vm/interpreter.v @@ -0,0 +1,645 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Interpreter +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +A straightforward interpreter that executes EVM code. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Iterable : + IsGlobalAlias globals typing.globals "Iterable". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.trace. +Axiom ethereum_trace_EvmStop : + IsGlobalAlias globals ethereum.trace.globals "EvmStop". +Axiom ethereum_trace_OpEnd : + IsGlobalAlias globals ethereum.trace.globals "OpEnd". +Axiom ethereum_trace_OpException : + IsGlobalAlias globals ethereum.trace.globals "OpException". +Axiom ethereum_trace_OpStart : + IsGlobalAlias globals ethereum.trace.globals "OpStart". +Axiom ethereum_trace_PrecompileEnd : + IsGlobalAlias globals ethereum.trace.globals "PrecompileEnd". +Axiom ethereum_trace_PrecompileStart : + IsGlobalAlias globals ethereum.trace.globals "PrecompileStart". +Axiom ethereum_trace_TransactionEnd : + IsGlobalAlias globals ethereum.trace.globals "TransactionEnd". +Axiom ethereum_trace_evm_trace : + IsGlobalAlias globals ethereum.trace.globals "evm_trace". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_account_exists_and_is_empty : + IsGlobalAlias globals state.globals "account_exists_and_is_empty". +Axiom state_account_has_code_or_nonce : + IsGlobalAlias globals state.globals "account_has_code_or_nonce". +Axiom state_begin_transaction : + IsGlobalAlias globals state.globals "begin_transaction". +Axiom state_commit_transaction : + IsGlobalAlias globals state.globals "commit_transaction". +Axiom state_destroy_storage : + IsGlobalAlias globals state.globals "destroy_storage". +Axiom state_increment_nonce : + IsGlobalAlias globals state.globals "increment_nonce". +Axiom state_mark_account_created : + IsGlobalAlias globals state.globals "mark_account_created". +Axiom state_move_ether : + IsGlobalAlias globals state.globals "move_ether". +Axiom state_rollback_transaction : + IsGlobalAlias globals state.globals "rollback_transaction". +Axiom state_set_code : + IsGlobalAlias globals state.globals "set_code". +Axiom state_touch_account : + IsGlobalAlias globals state.globals "touch_account". + +Require vm. +Axiom vm_Message : + IsGlobalAlias globals vm.globals "Message". + +Require vm.gas. +Axiom vm_gas_GAS_CODE_DEPOSIT : + IsGlobalAlias globals vm.gas.globals "GAS_CODE_DEPOSIT". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require vm.precompiled_contracts.mapping. +Axiom vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : + IsGlobalAlias globals vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". + +Require __init__. +Axiom __init___Environment : + IsGlobalAlias globals __init__.globals "Environment". +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_AddressCollision : + IsGlobalAlias globals exceptions.globals "AddressCollision". +Axiom exceptions_ExceptionalHalt : + IsGlobalAlias globals exceptions.globals "ExceptionalHalt". +Axiom exceptions_InvalidContractPrefix : + IsGlobalAlias globals exceptions.globals "InvalidContractPrefix". +Axiom exceptions_InvalidOpcode : + IsGlobalAlias globals exceptions.globals "InvalidOpcode". +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". +Axiom exceptions_Revert : + IsGlobalAlias globals exceptions.globals "Revert". +Axiom exceptions_StackDepthLimitError : + IsGlobalAlias globals exceptions.globals "StackDepthLimitError". + +Require instructions. +Axiom instructions_Ops : + IsGlobalAlias globals instructions.globals "Ops". +Axiom instructions_op_implementation : + IsGlobalAlias globals instructions.globals "op_implementation". + +Require runtime. +Axiom runtime_get_valid_jump_destinations : + IsGlobalAlias globals runtime.globals "get_valid_jump_destinations". + +Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1024 + ], + make_dict [] + |) +)). + +Definition MAX_CODE_SIZE : Value.t := M.run ltac:(M.monadic ( + Constant.int 24576 +)). + +Definition MessageCallOutput : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition process_message_call : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + If `message.current` is empty then it creates a smart contract + else it executes a call from the `message.caller` to the `message.target`. + + Parameters + ---------- + message : + Transaction specific items. + + env : + External items required for EVM execution. + + Returns + ------- + output : `MessageCallOutput` + Output of the message call + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_name (| globals, "message" |), "target" |), M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let is_collision := + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_name (| globals, "is_collision" |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallOutput" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "tuple" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "AddressCollision" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let evm := + M.call (| + M.get_name (| globals, "process_create_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let evm := + M.call (| + M.get_name (| globals, "process_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_field (| M.get_name (| globals, "message" |), "target" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_field (| M.get_name (| globals, "message" |), "target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( +(* At stmt: unsupported node type: AnnAssign *) + let accounts_to_delete := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let touched_accounts := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let refund_counter := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let logs := + M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in + let accounts_to_delete := + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in + let touched_accounts := + M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |) in + let refund_counter := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let tx_end := + M.call (| + M.get_name (| globals, "TransactionEnd" |), + make_list [ + BinOp.sub (| + M.get_field (| M.get_name (| globals, "message" |), "gas" |), + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + |); + M.get_field (| M.get_name (| globals, "evm" |), "output" |); + M.get_field (| M.get_name (| globals, "evm" |), "error" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "evm_trace" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "tx_end" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallOutput" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition process_create_message : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + Executes a call to create a smart contract. + + Parameters + ---------- + message : + Transaction specific items. + env : + External items required for EVM execution. + + Returns + ------- + evm: :py:class:`~ethereum.london.vm.Evm` + Items containing execution specific objects. + " in + let _ := M.call (| + M.get_name (| globals, "begin_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "destroy_storage" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "mark_account_created" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let evm := + M.call (| + M.get_name (| globals, "process_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), + (* then *) + ltac:(M.monadic ( + let contract_code := + M.get_field (| M.get_name (| globals, "evm" |), "output" |) in + let contract_code_gas := + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "contract_code" |) + ], + make_dict [] + |), + M.get_name (| globals, "GAS_CODE_DEPOSIT" |) + |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "rollback_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.get_name (| globals, "evm" |) + |) in + M.pure Constant.None_)). + +Definition process_message : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + Executes a call to create a smart contract. + + Parameters + ---------- + message : + Transaction specific items. + env : + External items required for EVM execution. + + Returns + ------- + evm: :py:class:`~ethereum.london.vm.Evm` + Items containing execution specific objects + " in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_field (| M.get_name (| globals, "message" |), "depth" |), M.get_name (| globals, "STACK_DEPTH_LIMIT" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "StackDepthLimitError" |), + make_list [ + Constant.str "Stack depth limit reached" + ], + make_dict [] + |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "begin_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "touch_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + M.get_field (| M.get_name (| globals, "message" |), "should_transfer_value" |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_field (| M.get_name (| globals, "message" |), "value" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "move_ether" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "caller" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |); + M.get_field (| M.get_name (| globals, "message" |), "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let evm := + M.call (| + M.get_name (| globals, "execute_code" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "rollback_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "commit_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.get_name (| globals, "evm" |) + |) in + M.pure Constant.None_)). + +Definition execute_code : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + Executes bytecode present in the `message`. + + Parameters + ---------- + message : + Transaction specific items. + env : + External items required for EVM execution. + + Returns + ------- + evm: `ethereum.vm.EVM` + Items containing execution specific objects + " in + let code := + M.get_field (| M.get_name (| globals, "message" |), "code" |) in + let valid_jump_destinations := + M.call (| + M.get_name (| globals, "get_valid_jump_destinations" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) in + let evm := + M.call (| + M.get_name (| globals, "Evm" |), + make_list [], + make_dict [] + |) in +(* At stmt: unsupported node type: Try *) + let _ := M.return_ (| + M.get_name (| globals, "evm" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/memory.v b/CoqOfPython/ethereum/arrow_glacier/vm/memory.v new file mode 100644 index 0000000..fa8d906 --- /dev/null +++ b/CoqOfPython/ethereum/arrow_glacier/vm/memory.v @@ -0,0 +1,153 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Memory +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +EVM memory operations. +". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_right_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "right_pad_zero_bytes". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". + +Definition memory_write : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "memory"; "start_position"; "value" ] |) in + let _ := Constant.str " + Writes to memory. + + Parameters + ---------- + memory : + Memory contents of the EVM. + start_position : + Starting pointer to the memory. + value : + Data to write to memory. + " in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) |), + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_)). + +Definition memory_read_bytes : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "memory"; "start_position"; "size" ] |) in + let _ := Constant.str " + Read bytes from memory. + + Parameters + ---------- + memory : + Memory contents of the EVM. + start_position : + Starting pointer to the memory. + size : + Size of the data that needs to be read from `start_position`. + + Returns + ------- + data_bytes : + Data read from memory. + " in + let _ := M.return_ (| + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |) + |) in + M.pure Constant.None_)). + +Definition buffer_read : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "buffer"; "start_position"; "size" ] |) in + let _ := Constant.str " + Read bytes from a buffer. Padding with zeros if necessary. + + Parameters + ---------- + buffer : + Memory contents of the EVM. + start_position : + Starting pointer to the memory. + size : + Size of the data that needs to be read from `start_position`. + + Returns + ------- + data_bytes : + Data read from memory. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "right_pad_zero_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/__init__.v new file mode 100644 index 0000000..ca49311 --- /dev/null +++ b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/__init__.v @@ -0,0 +1,117 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Precompiled Contract Addresses +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Addresses of precompiled contracts and mappings to their +implementations. +". + +Require utils.hexadecimal. +Axiom utils_hexadecimal_hex_to_address : + IsGlobalAlias globals utils.hexadecimal.globals "hex_to_address". + +Definition __all__ : Value.t := M.run ltac:(M.monadic ( + make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS"; Constant.str "MODEXP_ADDRESS"; Constant.str "ALT_BN128_ADD_ADDRESS"; Constant.str "ALT_BN128_MUL_ADDRESS"; Constant.str "ALT_BN128_PAIRING_CHECK_ADDRESS"; Constant.str "BLAKE2F_ADDRESS" ] +)). + +Definition ECRECOVER_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x01" + ], + make_dict [] + |) +)). + +Definition SHA256_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x02" + ], + make_dict [] + |) +)). + +Definition RIPEMD160_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x03" + ], + make_dict [] + |) +)). + +Definition IDENTITY_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x04" + ], + make_dict [] + |) +)). + +Definition MODEXP_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x05" + ], + make_dict [] + |) +)). + +Definition ALT_BN128_ADD_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x06" + ], + make_dict [] + |) +)). + +Definition ALT_BN128_MUL_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x07" + ], + make_dict [] + |) +)). + +Definition ALT_BN128_PAIRING_CHECK_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x08" + ], + make_dict [] + |) +)). + +Definition BLAKE2F_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x09" + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/alt_bn128.v new file mode 100644 index 0000000..19b83fc --- /dev/null +++ b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/alt_bn128.v @@ -0,0 +1,673 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) ALT_BN128 CONTRACTS +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the ALT_BN128 precompiled contracts. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.alt_bn128. +Axiom ethereum_crypto_alt_bn128_ALT_BN128_CURVE_ORDER : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "ALT_BN128_CURVE_ORDER". +Axiom ethereum_crypto_alt_bn128_ALT_BN128_PRIME : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "ALT_BN128_PRIME". +Axiom ethereum_crypto_alt_bn128_BNF : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF". +Axiom ethereum_crypto_alt_bn128_BNF2 : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF2". +Axiom ethereum_crypto_alt_bn128_BNF12 : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF12". +Axiom ethereum_crypto_alt_bn128_BNP : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNP". +Axiom ethereum_crypto_alt_bn128_BNP2 : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNP2". +Axiom ethereum_crypto_alt_bn128_pairing : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "pairing". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require vm.memory. +Axiom vm_memory_buffer_read : + IsGlobalAlias globals vm.memory.globals "buffer_read". + +Require exceptions. +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". + +Definition alt_bn128_add : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + The ALT_BN128 addition precompiled contract. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 150 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x0_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x0_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "x0_bytes" |) + ], + make_dict [] + |) in + let y0_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y0_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "y0_bytes" |) + ], + make_dict [] + |) in + let x1_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x1_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "x1_bytes" |) + ], + make_dict [] + |) in + let y1_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y1_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "y1_bytes" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ] do + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "i" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. +(* At stmt: unsupported node type: Try *) + let p := + BinOp.add (| + M.get_name (| globals, "p0" |), + M.get_name (| globals, "p1" |) + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + BinOp.add (| + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "p" |), "x" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "p" |), "y" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) + |) in + M.pure Constant.None_)). + +Definition alt_bn128_mul : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + The ALT_BN128 multiplication precompiled contract. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 6000 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x0_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x0_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "x0_bytes" |) + ], + make_dict [] + |) in + let y0_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y0_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "y0_bytes" |) + ], + make_dict [] + |) in + let n := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ] do + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "i" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. +(* At stmt: unsupported node type: Try *) + let p := + M.call (| + M.get_field (| M.get_name (| globals, "p0" |), "mul_by" |), + make_list [ + M.get_name (| globals, "n" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + BinOp.add (| + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "p" |), "x" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "p" |), "y" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) + |) in + M.pure Constant.None_)). + +Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + The ALT_BN128 pairing check precompiled contract. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 34000, + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 192 + |) + |), + Constant.int 45000 + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 192 + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 192 + |) + ], + make_dict [] + |) do + let values := + make_list [] in + For M.get_name (| globals, "j" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 6 + ], + make_dict [] + |) do + let value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "data" |), BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + M.get_name (| globals, "j" |) + |) + |):BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "j" |), + Constant.int 1 + |) + |) + |) |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "value" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "values" |), "append" |), + make_list [ + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + EndFor. +(* At stmt: unsupported node type: Try *) + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.call (| + M.get_field (| M.get_name (| globals, "p" |), "mul_by" |), + make_list [ + M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) + ], + make_dict [] + |), M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) |); + M.get_name (| globals, "OutOfGasError" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.call (| + M.get_field (| M.get_name (| globals, "q" |), "mul_by" |), + make_list [ + M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) + ], + make_dict [] + |), M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) |); + M.get_name (| globals, "OutOfGasError" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "p" |), M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_name (| globals, "q" |), M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let result := + BinOp.mult (| + M.get_name (| globals, "result" |), + M.call (| + M.get_name (| globals, "pairing" |), + make_list [ + M.get_name (| globals, "q" |); + M.get_name (| globals, "p" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "result" |), M.call (| + M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/blake2f.v b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/blake2f.v new file mode 100644 index 0000000..5903066 --- /dev/null +++ b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/blake2f.v @@ -0,0 +1,122 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Blake2 PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `Blake2` precompiled contract. +". + +Require ethereum.crypto.blake2. +Axiom ethereum_crypto_blake2_Blake2b : + IsGlobalAlias globals ethereum.crypto.blake2.globals "Blake2b". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_BLAKE2_PER_ROUND : + IsGlobalAlias globals vm.gas.globals "GAS_BLAKE2_PER_ROUND". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require exceptions. +Axiom exceptions_InvalidParameter : + IsGlobalAlias globals exceptions.globals "InvalidParameter". + +Definition blake2f : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the Blake2 hash to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), Constant.int 213 |); + M.get_name (| globals, "InvalidParameter" |) + ], + make_dict [] + |) in + let blake2b := + M.call (| + M.get_name (| globals, "Blake2b" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "rounds" |); M.get_name (| globals, "h" |); M.get_name (| globals, "m" |); M.get_name (| globals, "t_0" |); M.get_name (| globals, "t_1" |); M.get_name (| globals, "f" |) ], + M.call (| + M.get_field (| M.get_name (| globals, "blake2b" |), "get_blake2_parameters" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.mult (| + M.get_name (| globals, "GAS_BLAKE2_PER_ROUND" |), + M.get_name (| globals, "rounds" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.in (| M.get_name (| globals, "f" |), make_list [ + Constant.int 0; + Constant.int 1 + ] |); + M.get_name (| globals, "InvalidParameter" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.get_name (| globals, "blake2b" |), "compress" |), + make_list [ + M.get_name (| globals, "rounds" |); + M.get_name (| globals, "h" |); + M.get_name (| globals, "m" |); + M.get_name (| globals, "t_0" |); + M.get_name (| globals, "t_1" |); + M.get_name (| globals, "f" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/ecrecover.v new file mode 100644 index 0000000..cc351b5 --- /dev/null +++ b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/ecrecover.v @@ -0,0 +1,269 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) ECRECOVER PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the ECRECOVER precompiled contract. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require ethereum.crypto.elliptic_curve. +Axiom ethereum_crypto_elliptic_curve_SECP256K1N : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_left_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_ECRECOVER : + IsGlobalAlias globals vm.gas.globals "GAS_ECRECOVER". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require vm.memory. +Axiom vm_memory_buffer_read : + IsGlobalAlias globals vm.memory.globals "buffer_read". + +Definition ecrecover : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Decrypts the address using elliptic curve DSA recovery mechanism and writes + the address to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_ECRECOVER" |) + ], + make_dict [] + |) in + let message_hash_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let message_hash := + M.call (| + M.get_name (| globals, "Hash32" |), + make_list [ + M.get_name (| globals, "message_hash_bytes" |) + ], + make_dict [] + |) in + let v := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let r := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let s := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 27 |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 28 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| Constant.int 0, M.get_name (| globals, "r" |) |), + ltac:(M.monadic ( + Compare.gt_e (| M.get_name (| globals, "r" |), M.get_name (| globals, "SECP256K1N" |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| Constant.int 0, M.get_name (| globals, "s" |) |), + ltac:(M.monadic ( + Compare.gt_e (| M.get_name (| globals, "s" |), M.get_name (| globals, "SECP256K1N" |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in +(* At stmt: unsupported node type: Try *) + let address := + M.get_subscript (| M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), Constant.int 12:Constant.int 32 |) in + let padded_address := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "address" |); + Constant.int 32 + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.get_name (| globals, "padded_address" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/identity.v new file mode 100644 index 0000000..fa96704 --- /dev/null +++ b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/identity.v @@ -0,0 +1,94 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) IDENTITY PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `IDENTITY` precompiled contract. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_IDENTITY : + IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY". +Axiom vm_gas_GAS_IDENTITY_WORD : + IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY_WORD". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition identity : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the message data to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let word_count := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_IDENTITY" |), + BinOp.mult (| + M.get_name (| globals, "GAS_IDENTITY_WORD" |), + M.get_name (| globals, "word_count" |) + |) + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.get_name (| globals, "data" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/mapping.v new file mode 100644 index 0000000..8a2e2eb --- /dev/null +++ b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/mapping.v @@ -0,0 +1,82 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Precompiled Contract Addresses +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Mapping of precompiled contracts their implementations. +". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require __init__. +Axiom __init___ALT_BN128_ADD_ADDRESS : + IsGlobalAlias globals __init__.globals "ALT_BN128_ADD_ADDRESS". +Axiom __init___ALT_BN128_MUL_ADDRESS : + IsGlobalAlias globals __init__.globals "ALT_BN128_MUL_ADDRESS". +Axiom __init___ALT_BN128_PAIRING_CHECK_ADDRESS : + IsGlobalAlias globals __init__.globals "ALT_BN128_PAIRING_CHECK_ADDRESS". +Axiom __init___BLAKE2F_ADDRESS : + IsGlobalAlias globals __init__.globals "BLAKE2F_ADDRESS". +Axiom __init___ECRECOVER_ADDRESS : + IsGlobalAlias globals __init__.globals "ECRECOVER_ADDRESS". +Axiom __init___IDENTITY_ADDRESS : + IsGlobalAlias globals __init__.globals "IDENTITY_ADDRESS". +Axiom __init___MODEXP_ADDRESS : + IsGlobalAlias globals __init__.globals "MODEXP_ADDRESS". +Axiom __init___RIPEMD160_ADDRESS : + IsGlobalAlias globals __init__.globals "RIPEMD160_ADDRESS". +Axiom __init___SHA256_ADDRESS : + IsGlobalAlias globals __init__.globals "SHA256_ADDRESS". + +Require alt_bn128. +Axiom alt_bn128_alt_bn128_add : + IsGlobalAlias globals alt_bn128.globals "alt_bn128_add". +Axiom alt_bn128_alt_bn128_mul : + IsGlobalAlias globals alt_bn128.globals "alt_bn128_mul". +Axiom alt_bn128_alt_bn128_pairing_check : + IsGlobalAlias globals alt_bn128.globals "alt_bn128_pairing_check". + +Require blake2f. +Axiom blake2f_blake2f : + IsGlobalAlias globals blake2f.globals "blake2f". + +Require ecrecover. +Axiom ecrecover_ecrecover : + IsGlobalAlias globals ecrecover.globals "ecrecover". + +Require identity. +Axiom identity_identity : + IsGlobalAlias globals identity.globals "identity". + +Require modexp. +Axiom modexp_modexp : + IsGlobalAlias globals modexp.globals "modexp". + +Require ripemd160. +Axiom ripemd160_ripemd160 : + IsGlobalAlias globals ripemd160.globals "ripemd160". + +Require sha256. +Axiom sha256_sha256 : + IsGlobalAlias globals sha256.globals "sha256". + +(* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/modexp.v new file mode 100644 index 0000000..544949e --- /dev/null +++ b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/modexp.v @@ -0,0 +1,608 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) MODEXP PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `MODEXP` precompiled contract. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require memory. +Axiom memory_buffer_read : + IsGlobalAlias globals memory.globals "buffer_read". + +Definition GQUADDIVISOR : Value.t := M.run ltac:(M.monadic ( + Constant.int 3 +)). + +Definition modexp : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Calculates `(base**exp) % modulus` for arbitrary sized `base`, `exp` and. + `modulus`. The return value is the same length as the modulus. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let base_length := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exp_length := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let modulus_length := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exp_start := + BinOp.add (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |), + M.get_name (| globals, "base_length" |) + |) in + let exp_head := + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.get_name (| globals, "exp_start" |); + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.get_name (| globals, "exp_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "gas_cost" |), + make_list [ + M.get_name (| globals, "base_length" |); + M.get_name (| globals, "modulus_length" |); + M.get_name (| globals, "exp_length" |); + M.get_name (| globals, "exp_head" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_name (| globals, "base_length" |), Constant.int 0 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "modulus_length" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [], + make_dict [] + |) + |) in + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let base := + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |); + M.get_name (| globals, "base_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exp := + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.get_name (| globals, "exp_start" |); + M.get_name (| globals, "exp_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let modulus_start := + BinOp.add (| + M.get_name (| globals, "exp_start" |), + M.get_name (| globals, "exp_length" |) + |) in + let modulus := + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.get_name (| globals, "modulus_start" |); + M.get_name (| globals, "modulus_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "modulus" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + BinOp.mult (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |), + M.get_name (| globals, "modulus_length" |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pow" |), + make_list [ + M.get_name (| globals, "base" |); + M.get_name (| globals, "exp" |); + M.get_name (| globals, "modulus" |) + ], + make_dict [] + |) + ], + make_dict [] + |), "to_bytes" |), + make_list [ + M.get_name (| globals, "modulus_length" |); + Constant.str "big" + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition complexity : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "base_length"; "modulus_length" ] |) in + let _ := Constant.str " + Estimate the complexity of performing a modular exponentiation. + + Parameters + ---------- + + base_length : + Length of the array representing the base integer. + + modulus_length : + Length of the array representing the modulus integer. + + Returns + ------- + + complexity : `Uint` + Complexity of performing the operation. + " in + let max_length := + M.call (| + M.get_name (| globals, "max" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "base_length" |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "modulus_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + BinOp.add (| + M.get_name (| globals, "max_length" |), + Constant.int 7 + |), + Constant.int 8 + |) in + let _ := M.return_ (| + BinOp.pow (| + M.get_name (| globals, "words" |), + Constant.int 2 + |) + |) in + M.pure Constant.None_)). + +Definition iterations : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "exponent_length"; "exponent_head" ] |) in + let _ := Constant.str " + Calculate the number of iterations required to perform a modular + exponentiation. + + Parameters + ---------- + + exponent_length : + Length of the array representing the exponent integer. + + exponent_head : + First 32 bytes of the exponent (with leading zero padding if it is + shorter than 32 bytes), as an unsigned integer. + + Returns + ------- + + iterations : `Uint` + Number of iterations. + " in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.lt_e (| M.get_name (| globals, "exponent_length" |), Constant.int 32 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "exponent_head" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let count := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| M.get_name (| globals, "exponent_length" |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let bit_length := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "exponent_head" |), "bit_length" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "bit_length" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let bit_length := BinOp.sub + Constant.int 1 + Constant.int 1 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let count := + M.get_name (| globals, "bit_length" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let length_part := + BinOp.mult (| + Constant.int 8, + BinOp.sub (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "exponent_length" |) + ], + make_dict [] + |), + Constant.int 32 + |) + |) in + let bits_part := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "exponent_head" |), "bit_length" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "bits_part" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let bits_part := BinOp.sub + Constant.int 1 + Constant.int 1 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let count := + BinOp.add (| + M.get_name (| globals, "length_part" |), + M.get_name (| globals, "bits_part" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "max" |), + make_list [ + M.get_name (| globals, "count" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition gas_cost : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "base_length"; "modulus_length"; "exponent_length"; "exponent_head" ] |) in + let _ := Constant.str " + Calculate the gas cost of performing a modular exponentiation. + + Parameters + ---------- + + base_length : + Length of the array representing the base integer. + + modulus_length : + Length of the array representing the modulus integer. + + exponent_length : + Length of the array representing the exponent integer. + + exponent_head : + First 32 bytes of the exponent (with leading zero padding if it is + shorter than 32 bytes), as an unsigned integer. + + Returns + ------- + + gas_cost : `Uint` + Gas required for performing the operation. + " in + let multiplication_complexity := + M.call (| + M.get_name (| globals, "complexity" |), + make_list [ + M.get_name (| globals, "base_length" |); + M.get_name (| globals, "modulus_length" |) + ], + make_dict [] + |) in + let iteration_count := + M.call (| + M.get_name (| globals, "iterations" |), + make_list [ + M.get_name (| globals, "exponent_length" |); + M.get_name (| globals, "exponent_head" |) + ], + make_dict [] + |) in + let cost := + BinOp.mult (| + M.get_name (| globals, "multiplication_complexity" |), + M.get_name (| globals, "iteration_count" |) + |) in + let cost := BinOp.floor_div + M.get_name (| globals, "GQUADDIVISOR" |) + M.get_name (| globals, "GQUADDIVISOR" |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "max" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 200 + ], + make_dict [] + |); + M.get_name (| globals, "cost" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/ripemd160.v new file mode 100644 index 0000000..96f8dcd --- /dev/null +++ b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/ripemd160.v @@ -0,0 +1,122 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) RIPEMD160 PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `RIPEMD160` precompiled contract. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_left_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_RIPEMD160 : + IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160". +Axiom vm_gas_GAS_RIPEMD160_WORD : + IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160_WORD". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition ripemd160 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the ripemd160 hash to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let word_count := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_RIPEMD160" |), + BinOp.mult (| + M.get_name (| globals, "GAS_RIPEMD160_WORD" |), + M.get_name (| globals, "word_count" |) + |) + |) + ], + make_dict [] + |) in + let hash_bytes := + M.call (| + M.get_field (| M.call (| + M.get_field (| M.get_name (| globals, "hashlib" |), "new" |), + make_list [ + Constant.str "ripemd160"; + M.get_name (| globals, "data" |) + ], + make_dict [] + |), "digest" |), + make_list [], + make_dict [] + |) in + let padded_hash := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "hash_bytes" |); + Constant.int 32 + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.get_name (| globals, "padded_hash" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/sha256.v new file mode 100644 index 0000000..9f6d2bf --- /dev/null +++ b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/sha256.v @@ -0,0 +1,106 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) SHA256 PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `SHA256` precompiled contract. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_SHA256 : + IsGlobalAlias globals vm.gas.globals "GAS_SHA256". +Axiom vm_gas_GAS_SHA256_WORD : + IsGlobalAlias globals vm.gas.globals "GAS_SHA256_WORD". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition sha256 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the sha256 hash to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let word_count := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_SHA256" |), + BinOp.mult (| + M.get_name (| globals, "GAS_SHA256_WORD" |), + M.get_name (| globals, "word_count" |) + |) + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_field (| M.get_name (| globals, "hashlib" |), "sha256" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), "digest" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/runtime.v b/CoqOfPython/ethereum/arrow_glacier/vm/runtime.v new file mode 100644 index 0000000..835b46c --- /dev/null +++ b/CoqOfPython/ethereum/arrow_glacier/vm/runtime.v @@ -0,0 +1,125 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Runtime Operations +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Runtime related operations used while executing EVM code. +". + +Require typing. +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require instructions. +Axiom instructions_Ops : + IsGlobalAlias globals instructions.globals "Ops". + +Definition get_valid_jump_destinations : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "code" ] |) in + let _ := Constant.str " + Analyze the evm code to obtain the set of valid jump destinations. + + Valid jump destinations are defined as follows: + * The jump destination is less than the length of the code. + * The jump destination should have the `JUMPDEST` opcode (0x5B). + * The jump destination shouldn't be part of the data corresponding to + `PUSH-N` opcodes. + + Note - Jump destinations are 0-indexed. + + Parameters + ---------- + code : + The EVM code which is to be executed. + + Returns + ------- + valid_jump_destinations: `Set[Uint]` + The set of valid jump destinations in the code. + " in + let valid_jump_destinations := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let pc := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + While Compare.lt (| M.get_name (| globals, "pc" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) |) do +(* At stmt: unsupported node type: Try *) + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "current_opcode" |), M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), + make_list [ + M.get_name (| globals, "pc" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + (* At expr: unsupported node type: Compare *), + (* then *) + ltac:(M.monadic ( + let push_data_size := + BinOp.add (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) + |), + Constant.int 1 + |) in + let pc := BinOp.add + M.get_name (| globals, "push_data_size" |) + M.get_name (| globals, "push_data_size" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let pc := BinOp.add + Constant.int 1 + Constant.int 1 in + EndWhile. + let _ := M.return_ (| + M.get_name (| globals, "valid_jump_destinations" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/stack.v b/CoqOfPython/ethereum/arrow_glacier/vm/stack.v new file mode 100644 index 0000000..42ea42d --- /dev/null +++ b/CoqOfPython/ethereum/arrow_glacier/vm/stack.v @@ -0,0 +1,120 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Stack +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the stack operators for the EVM. +". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require exceptions. +Axiom exceptions_StackOverflowError : + IsGlobalAlias globals exceptions.globals "StackOverflowError". +Axiom exceptions_StackUnderflowError : + IsGlobalAlias globals exceptions.globals "StackUnderflowError". + +Definition pop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "stack" ] |) in + let _ := Constant.str " + Pops the top item off of `stack`. + + Parameters + ---------- + stack : + EVM stack. + + Returns + ------- + value : `U256` + The top element on the stack. + + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "StackUnderflowError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "pop" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition push : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "stack"; "value" ] |) in + let _ := Constant.str " + Pushes `value` onto `stack`. + + Parameters + ---------- + stack : + EVM stack. + + value : + Item to be pushed onto `stack`. + + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), Constant.int 1024 |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "StackOverflowError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "append" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/__init__.v b/CoqOfPython/ethereum/berlin/__init__.v new file mode 100644 index 0000000..4a8bbc8 --- /dev/null +++ b/CoqOfPython/ethereum/berlin/__init__.v @@ -0,0 +1,24 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +The Berlin fork adjusts the gas costs of the `ModExp` precompile and several +state access EVM instructions, introduces typed transaction envelopes along +with the first new transaction type—optional access lists. +". + +Require ethereum.fork_criteria. +Axiom ethereum_fork_criteria_ByBlockNumber : + IsGlobalAlias globals ethereum.fork_criteria.globals "ByBlockNumber". + +Definition FORK_CRITERIA : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "ByBlockNumber" |), + make_list [ + Constant.int 12244000 + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/berlin/blocks.v b/CoqOfPython/ethereum/berlin/blocks.v new file mode 100644 index 0000000..a90217e --- /dev/null +++ b/CoqOfPython/ethereum/berlin/blocks.v @@ -0,0 +1,95 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +A `Block` is a single link in the chain that is Ethereum. Each `Block` contains +a `Header` and zero or more transactions. Each `Header` contains associated +metadata like the block number, parent block hash, and how much gas was +consumed by its transactions. + +Together, these blocks form a cryptographically secure journal recording the +history of all state transitions that have happened since the genesis of the +chain. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes8 : + IsGlobalAlias globals base_types.globals "Bytes8". +Axiom base_types_Bytes32 : + IsGlobalAlias globals base_types.globals "Bytes32". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require crypto.hash. +Axiom crypto_hash_Hash32 : + IsGlobalAlias globals crypto.hash.globals "Hash32". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Require transactions. +Axiom transactions_LegacyTransaction : + IsGlobalAlias globals transactions.globals "LegacyTransaction". + +Definition Header : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Block : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Log : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Receipt : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. diff --git a/CoqOfPython/ethereum/berlin/bloom.v b/CoqOfPython/ethereum/berlin/bloom.v new file mode 100644 index 0000000..04b5d9f --- /dev/null +++ b/CoqOfPython/ethereum/berlin/bloom.v @@ -0,0 +1,164 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Logs Bloom +^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +This modules defines functions for calculating bloom filters of logs. For the +general theory of bloom filters see e.g. `Wikipedia +`_. Bloom filters are used to allow +for efficient searching of logs by address and/or topic, by rapidly +eliminating blocks and receipts from their search. +". + +Require typing. +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require fork_types. +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". + +Definition add_to_bloom : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "bloom"; "bloom_entry" ] |) in + let _ := Constant.str " + Add a bloom entry to the bloom filter (`bloom`). + + The number of hash functions used is 3. They are calculated by taking the + least significant 11 bits from the first 3 16-bit words of the + `keccak_256()` hash of `bloom_entry`. + + Parameters + ---------- + bloom : + The bloom filter. + bloom_entry : + An entry which is to be added to bloom filter. + " in + let hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "bloom_entry" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "idx" |) in make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ] do + let bit_to_set := + BinOp.bit_and (| + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |):BinOp.add (| + M.get_name (| globals, "idx" |), + Constant.int 2 + |) |) + ], + make_dict [] + |), + Constant.int 2047 + |) in + let bit_index := + BinOp.sub (| + Constant.int 2047, + M.get_name (| globals, "bit_to_set" |) + |) in + let byte_index := + BinOp.floor_div (| + M.get_name (| globals, "bit_index" |), + Constant.int 8 + |) in + let bit_value := + BinOp.l_shift (| + Constant.int 1, + BinOp.sub (| + Constant.int 7, + BinOp.mod_ (| + M.get_name (| globals, "bit_index" |), + Constant.int 8 + |) + |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), + BinOp.bit_or (| + M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), + M.get_name (| globals, "bit_value" |) + |) + |) in + EndFor. + M.pure Constant.None_)). + +Definition logs_bloom : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "logs" ] |) in + let _ := Constant.str " + Obtain the logs bloom from a list of log entries. + + The address and each topic of a log are added to the bloom filter. + + Parameters + ---------- + logs : + List of logs for which the logs bloom is to be obtained. + + Returns + ------- + logs_bloom : `Bloom` + The logs bloom obtained which is 256 bytes with some bits set as per + the caller address and the log topics. + " in +(* At stmt: unsupported node type: AnnAssign *) + For M.get_name (| globals, "log" |) in M.get_name (| globals, "logs" |) do + let _ := M.call (| + M.get_name (| globals, "add_to_bloom" |), + make_list [ + M.get_name (| globals, "bloom" |); + M.get_field (| M.get_name (| globals, "log" |), "address" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "topic" |) in M.get_field (| M.get_name (| globals, "log" |), "topics" |) do + let _ := M.call (| + M.get_name (| globals, "add_to_bloom" |), + make_list [ + M.get_name (| globals, "bloom" |); + M.get_name (| globals, "topic" |) + ], + make_dict [] + |) in + EndFor. + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bloom" |), + make_list [ + M.get_name (| globals, "bloom" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/fork_types.v b/CoqOfPython/ethereum/berlin/fork_types.v new file mode 100644 index 0000000..d12953d --- /dev/null +++ b/CoqOfPython/ethereum/berlin/fork_types.v @@ -0,0 +1,102 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Types +^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Types re-used throughout the specification, which are specific to Ethereum. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes20 : + IsGlobalAlias globals base_types.globals "Bytes20". +Axiom base_types_Bytes256 : + IsGlobalAlias globals base_types.globals "Bytes256". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require crypto.hash. +Axiom crypto_hash_Hash32 : + IsGlobalAlias globals crypto.hash.globals "Hash32". +Axiom crypto_hash_keccak256 : + IsGlobalAlias globals crypto.hash.globals "keccak256". + +Definition Address : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Bytes20" |) +)). + +Definition Root : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Hash32" |) +)). + +Definition Bloom : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Bytes256" |) +)). + +Definition Account : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition EMPTY_ACCOUNT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Account" |), + make_list [], + make_dict [] + |) +)). + +Definition encode_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "raw_account_data"; "storage_root" ] |) in + let _ := Constant.str " + Encode `Account` dataclass. + + Storage is not stored in the `Account` dataclass, so `Accounts` cannot be + encoded with providing a storage root. + " in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "raw_account_data" |), "nonce" |); M.get_field (| M.get_name (| globals, "raw_account_data" |), "balance" |); M.get_name (| globals, "storage_root" |); M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_field (| M.get_name (| globals, "raw_account_data" |), "code" |) + ], + make_dict [] + |) ] + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/state.v b/CoqOfPython/ethereum/berlin/state.v new file mode 100644 index 0000000..7b038e5 --- /dev/null +++ b/CoqOfPython/ethereum/berlin/state.v @@ -0,0 +1,1184 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +State +^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The state contains all information that is preserved between transactions. + +It consists of a main account trie and storage tries for each contract. + +There is a distinction between an account that does not exist and +`EMPTY_ACCOUNT`. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_field : + IsGlobalAlias globals dataclasses.globals "field". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_modify : + IsGlobalAlias globals ethereum.base_types.globals "modify". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require fork_types. +Axiom fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". +Axiom fork_types_Account : + IsGlobalAlias globals fork_types.globals "Account". +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Require trie. +Axiom trie_EMPTY_TRIE_ROOT : + IsGlobalAlias globals trie.globals "EMPTY_TRIE_ROOT". +Axiom trie_Trie : + IsGlobalAlias globals trie.globals "Trie". +Axiom trie_copy_trie : + IsGlobalAlias globals trie.globals "copy_trie". +Axiom trie_root : + IsGlobalAlias globals trie.globals "root". +Axiom trie_trie_get : + IsGlobalAlias globals trie.globals "trie_get". +Axiom trie_trie_set : + IsGlobalAlias globals trie.globals "trie_set". + +Definition State : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition close_state : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Free resources held by the state. Used by optimized implementations to + release file descriptors. + " in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) |) in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |) in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |) |) in + M.pure Constant.None_)). + +Definition begin_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Start a state transaction. + + Transactions are entirely implicit and can be nested. It is not possible to + calculate the state root during a transaction. + + Parameters + ---------- + state : State + The state. + " in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), "append" |), + make_list [ + make_tuple [ M.call (| + M.get_name (| globals, "copy_trie" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) + ], + make_dict [] + |); {M.get_name (| globals, "k" |): M.call (| + M.get_name (| globals, "copy_trie" |), + make_list [ + M.get_name (| globals, "t" |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)} ] + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition commit_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Commit a state transaction. + + Parameters + ---------- + state : State + The state. + " in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), "pop" |), + make_list [], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "clear" |), + make_list [], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition rollback_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Rollback a state transaction, resetting the state to the point when the + corresponding `start_transaction()` call was made. + + Parameters + ---------- + state : State + The state. + " in + let _ := M.assign (| + make_tuple [ M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) ], + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), "pop" |), + make_list [], + make_dict [] + |) + |) in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "clear" |), + make_list [], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition get_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Get the `Account` object at an address. Returns `EMPTY_ACCOUNT` if there + is no account at the address. + + Use `get_account_optional()` if you care about the difference between a + non-existent account and `EMPTY_ACCOUNT`. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address to lookup. + + Returns + ------- + account : `Account` + Account at address. + " in + let account := + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "account" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "account" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "EMPTY_ACCOUNT" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition get_account_optional : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Get the `Account` object at an address. Returns `None` (rather than + `EMPTY_ACCOUNT`) if there is no account at the address. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address to lookup. + + Returns + ------- + account : `Account` + Account at address. + " in + let account := + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "account" |) + |) in + M.pure Constant.None_)). + +Definition set_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "account" ] |) in + let _ := Constant.str " + Set the `Account` object at an address. Setting to `None` deletes + the account (but not its storage, see `destroy_account()`). + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address to set. + account : `Account` + Account to set at address. + " in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "account" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition destroy_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Completely remove the account at `address` and all of its storage. + + This function is made available exclusively for the `SELFDESTRUCT` + opcode. It is expected that `SELFDESTRUCT` will be disabled in a future + hardfork and this function will be removed. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of account to destroy. + " in + let _ := M.call (| + M.get_name (| globals, "destroy_storage" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + Constant.None_ + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition destroy_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Completely remove the storage at `address`. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of account whose storage is to be deleted. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition mark_account_created : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Mark an account as having been created in the current transaction. + This information is used by `get_storage_original()` to handle an obscure + edgecase. + + The marker is not removed even if the account creation reverts. Since the + account cannot have had code prior to its creation and can't call + `get_storage_original()`, this is harmless. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of the account that has been created. + " in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition get_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "key" ] |) in + let _ := Constant.str " + Get a value at a storage key on an account. Returns `U256(0)` if the + storage key has not been set previously. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of the account. + key : `Bytes` + Key to lookup. + + Returns + ------- + value : `U256` + Value at the key. + " in + let trie := + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let _ := M.assert (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "U256" |) + ], + make_dict [] + |) |) in + let _ := M.return_ (| + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_)). + +Definition set_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "key"; "value" ] |) in + let _ := Constant.str " + Set a value at a storage key on an account. Setting to `U256(0)` deletes + the key. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of the account. + key : `Bytes` + Key to set. + value : `U256` + Value to set at the key. + " in + let _ := M.assert (| Compare.is_not (| M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), Constant.None_ |) |) in + let trie := + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let trie := + M.call (| + M.get_name (| globals, "Trie" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), + M.get_name (| globals, "trie" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "key" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), {} |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition storage_root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Calculate the storage root of an account. + + Parameters + ---------- + state: + The state + address : + Address of the account. + + Returns + ------- + root : `Root` + Storage root of the account. + " in + let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "EMPTY_TRIE_ROOT" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition state_root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Calculate the state root. + + Parameters + ---------- + state: + The current state. + + Returns + ------- + root : `Root` + The state root. + " in + let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition account_exists : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account exists in the state trie + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + account_exists : `bool` + True if account exists in the state trie, False otherwise + " in + let _ := M.return_ (| + Compare.is_not (| M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), Constant.None_ |) + |) in + M.pure Constant.None_)). + +Definition account_has_code_or_nonce : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account has non zero nonce or non empty code + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + has_code_or_nonce : `bool` + True if if an account has non zero nonce or non empty code, + False otherwise. + " in + let account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + BoolOp.or (| + Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |) + )) + |) + |) in + M.pure Constant.None_)). + +Definition is_account_empty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account has zero nonce, empty code and zero balance. + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + is_empty : `bool` + True if if an account has zero nonce, empty code and zero balance, + False otherwise. + " in + let account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + ltac:(M.monadic ( + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + )) + |) + )) + |) + |) in + M.pure Constant.None_)). + +Definition account_exists_and_is_empty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account exists and has zero nonce, empty code and zero + balance. + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + exists_and_is_empty : `bool` + True if an account exists and has zero nonce, empty code and zero + balance, False otherwise. + " in + let account := + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + BoolOp.and (| + Compare.is_not (| M.get_name (| globals, "account" |), Constant.None_ |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + ltac:(M.monadic ( + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + )) + |) + )) + |) + )) + |) + |) in + M.pure Constant.None_)). + +Definition is_account_alive : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Check whether is an account is both in the state and non empty. + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + is_alive : `bool` + True if the account is alive. + " in + let account := + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "account" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + UnOp.not (| BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + ltac:(M.monadic ( + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + )) + |) + )) + |) |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition modify_state : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "f" ] |) in + let _ := Constant.str " + Modify an `Account` in the `State`. + " in + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.call (| + M.get_name (| globals, "modify" |), + make_list [ + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |); + M.get_name (| globals, "f" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition move_ether : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "sender_address"; "recipient_address"; "amount" ] |) in + let _ := Constant.str " + Move funds between accounts. + " in +(* At stmt: unsupported node type: FunctionDef *) +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "sender_address" |); + M.get_name (| globals, "reduce_sender_balance" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "recipient_address" |); + M.get_name (| globals, "increase_recipient_balance" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition set_account_balance : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "amount" ] |) in + let _ := Constant.str " + Sets the balance of an account. + + Parameters + ---------- + state: + The current state. + + address: + Address of the account whose nonce needs to be incremented. + + amount: + The amount that needs to set in balance. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "set_balance" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition touch_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Initializes an account to state. + + Parameters + ---------- + state: + The current state. + + address: + The address of the account that need to initialised. + " in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "account_exists" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "EMPTY_ACCOUNT" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition increment_nonce : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Increments the nonce of an account. + + Parameters + ---------- + state: + The current state. + + address: + Address of the account whose nonce needs to be incremented. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "increase_nonce" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition set_code : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "code" ] |) in + let _ := Constant.str " + Sets Account code. + + Parameters + ---------- + state: + The current state. + + address: + Address of the account whose code needs to be update. + + code: + The bytecode that needs to be set. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "write_code" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition create_ether : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "amount" ] |) in + let _ := Constant.str " + Add newly created ether to an account. + + Parameters + ---------- + state: + The current state. + address: + Address of the account to which ether is added. + amount: + The amount of ether to be added to the account of interest. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "increase_balance" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition get_storage_original : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "key" ] |) in + let _ := Constant.str " + Get the original value in a storage slot i.e. the value before the current + transaction began. This function reads the value from the snapshots taken + before executing the transaction. + + Parameters + ---------- + state: + The current state. + address: + Address of the account to read the value from. + key: + Key of the storage slot. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "_" |); M.get_name (| globals, "original_trie" |) ], + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), Constant.int 0 |) + |) in + let original_account_trie := + M.call (| + M.get_field (| M.get_name (| globals, "original_trie" |), "get" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "original_account_trie" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let original_value := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let original_value := + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_name (| globals, "original_account_trie" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.assert (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "original_value" |); + M.get_name (| globals, "U256" |) + ], + make_dict [] + |) |) in + let _ := M.return_ (| + M.get_name (| globals, "original_value" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/transactions.v b/CoqOfPython/ethereum/berlin/transactions.v new file mode 100644 index 0000000..624882c --- /dev/null +++ b/CoqOfPython/ethereum/berlin/transactions.v @@ -0,0 +1,213 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Transactions are atomic units of work created externally to Ethereum and +submitted to be executed. If Ethereum is viewed as a state machine, +transactions are the events that move between states. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U64 : + IsGlobalAlias globals base_types.globals "U64". +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes0 : + IsGlobalAlias globals base_types.globals "Bytes0". +Axiom base_types_Bytes32 : + IsGlobalAlias globals base_types.globals "Bytes32". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require exceptions. +Axiom exceptions_InvalidBlock : + IsGlobalAlias globals exceptions.globals "InvalidBlock". + +Require utils.ensure. +Axiom utils_ensure_ensure : + IsGlobalAlias globals utils.ensure.globals "ensure". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( + Constant.int 21000 +)). + +Definition TX_DATA_COST_PER_NON_ZERO : Value.t := M.run ltac:(M.monadic ( + Constant.int 16 +)). + +Definition TX_DATA_COST_PER_ZERO : Value.t := M.run ltac:(M.monadic ( + Constant.int 4 +)). + +Definition TX_CREATE_COST : Value.t := M.run ltac:(M.monadic ( + Constant.int 32000 +)). + +Definition TX_ACCESS_LIST_ADDRESS_COST : Value.t := M.run ltac:(M.monadic ( + Constant.int 2400 +)). + +Definition TX_ACCESS_LIST_STORAGE_KEY_COST : Value.t := M.run ltac:(M.monadic ( + Constant.int 1900 +)). + +Definition LegacyTransaction : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition AccessListTransaction : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Transaction : Value.t := M.run ltac:(M.monadic ( + M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "AccessListTransaction" |) ] |) +)). + +Definition encode_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Encode a transaction. Needed because non-legacy transactions aren't RLP. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "LegacyTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "tx" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "AccessListTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + (* At constant: unsupported node type: Constant *), + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "Exception" |), + make_list [ + (* At expr: unsupported node type: JoinedStr *) + ], + make_dict [] + |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition decode_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Decode a transaction. Needed because non-legacy transactions aren't RLP. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), Constant.int 1 |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), + make_list [ + M.get_name (| globals, "AccessListTransaction" |); + M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 1:(* At expr: unsupported node type: NoneType *) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "tx" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/trie.v b/CoqOfPython/ethereum/berlin/trie.v new file mode 100644 index 0000000..9e5b907 --- /dev/null +++ b/CoqOfPython/ethereum/berlin/trie.v @@ -0,0 +1,1357 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +State Trie +^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The state trie is the structure responsible for storing +`.fork_types.Account` objects. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_field : + IsGlobalAlias globals dataclasses.globals "field". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". +Axiom typing_Generic : + IsGlobalAlias globals typing.globals "Generic". +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Mapping : + IsGlobalAlias globals typing.globals "Mapping". +Axiom typing_MutableMapping : + IsGlobalAlias globals typing.globals "MutableMapping". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Sequence : + IsGlobalAlias globals typing.globals "Sequence". +Axiom typing_TypeVar : + IsGlobalAlias globals typing.globals "TypeVar". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". +Axiom typing_cast : + IsGlobalAlias globals typing.globals "cast". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.muir_glacier. +Axiom ethereum_muir_glacier_trie : + IsGlobalAlias globals ethereum.muir_glacier.globals "trie". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require ethereum.utils.hexadecimal. +Axiom ethereum_utils_hexadecimal_hex_to_bytes : + IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require blocks. +Axiom blocks_Receipt : + IsGlobalAlias globals blocks.globals "Receipt". + +Require fork_types. +Axiom fork_types_Account : + IsGlobalAlias globals fork_types.globals "Account". +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". +Axiom fork_types_encode_account : + IsGlobalAlias globals fork_types.globals "encode_account". + +Require transactions. +Axiom transactions_LegacyTransaction : + IsGlobalAlias globals transactions.globals "LegacyTransaction". + +Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Root" |), + make_list [ + M.call (| + M.get_name (| globals, "hex_to_bytes" |), + make_list [ + Constant.str "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" + ], + make_dict [] + |) + ], + make_dict [] + |) +)). + +Definition Node : Value.t := M.run ltac:(M.monadic ( + M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Bytes" |); M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |); Constant.None_ ] |) +)). + +Definition K : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "TypeVar" |), + make_list [ + Constant.str "K" + ], + make_dict [] + |) +)). + +Definition V : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "TypeVar" |), + make_list [ + Constant.str "V"; + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Account" |) |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Bytes" |) |); + M.get_name (| globals, "Bytes" |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Bytes" |) ] |) |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Bytes" |) ] |) |); + M.get_name (| globals, "Uint" |); + M.get_name (| globals, "U256" |) + ], + make_dict [] + |) +)). + +Definition LeafNode : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition ExtensionNode : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition BranchNode : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition InternalNode : Value.t := M.run ltac:(M.monadic ( + M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LeafNode" |); M.get_name (| globals, "ExtensionNode" |); M.get_name (| globals, "BranchNode" |) ] |) +)). + +Definition encode_internal_node : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "node" ] |) in + let _ := Constant.str " + Encodes a Merkle Trie node into its RLP form. The RLP will then be + serialized into a `Bytes` and hashed unless it is less that 32 bytes + when serialized. + + This function also accepts `None`, representing the absence of a node, + which is encoded to `b""""""`. + + Parameters + ---------- + node : Optional[InternalNode] + The node to encode. + + Returns + ------- + encoded : `rlp.RLP` + The node encoded as RLP. + " in +(* At stmt: unsupported node type: AnnAssign *) + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "node" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let unencoded := + (* At constant: unsupported node type: Constant *) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "LeafNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "rest_of_key" |); + Constant.bool true + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "ExtensionNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "key_segment" |); + Constant.bool false + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "BranchNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + BinOp.add (| + M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "value" |) + ] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "AssertionError" |), + make_list [ + (* At expr: unsupported node type: JoinedStr *) + ], + make_dict [] + |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let encoded := + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "unencoded" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded" |) + ], + make_dict [] + |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "unencoded" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "encoded" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition encode_node : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "node"; "storage_root" ] |) in + let _ := Constant.str " + Encode a Node for storage in the Merkle Trie. + + Currently mostly an unimplemented stub. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "storage_root" |), Constant.None_ |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "encode_account" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "storage_root" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "U256" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "cast" |), + make_list [ + M.get_field (| M.get_name (| globals, "rlp" |), "RLP" |); + M.get_name (| globals, "node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "node" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "previous_trie" |), "encode_node" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "storage_root" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition Trie : Value.t := + builtins.make_klass + [(* At base: unsupported node type: Subscript *)] + [ + + ] + [ + + ]. + +Definition copy_trie : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie" ] |) in + let _ := Constant.str " + Create a copy of `trie`. Since only frozen objects may be stored in tries, + the contents are reused. + + Parameters + ---------- + trie: `Trie` + Trie to copy. + + Returns + ------- + new_trie : `Trie[K, V]` + A copy of the trie. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Trie" |), + make_list [ + M.get_field (| M.get_name (| globals, "trie" |), "secured" |); + M.get_field (| M.get_name (| globals, "trie" |), "default" |); + M.call (| + M.get_field (| M.get_name (| globals, "copy" |), "copy" |), + make_list [ + M.get_field (| M.get_name (| globals, "trie" |), "_data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition trie_set : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "key"; "value" ] |) in + let _ := Constant.str " + Stores an item in a Merkle Trie. + + This method deletes the key if `value == trie.default`, because the Merkle + Trie represents the default value by omitting it from the trie. + + Parameters + ---------- + trie: `Trie` + Trie to store in. + key : `Bytes` + Key to lookup. + value : `V` + Node to insert at `key`. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "value" |), M.get_field (| M.get_name (| globals, "trie" |), "default" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "key" |), M.get_field (| M.get_name (| globals, "trie" |), "_data" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition trie_get : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "key" ] |) in + let _ := Constant.str " + Gets an item from the Merkle Trie. + + This method returns `trie.default` if the key is missing. + + Parameters + ---------- + trie: + Trie to lookup in. + key : + Key to lookup. + + Returns + ------- + node : `V` + Node at `key` in the trie. + " in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "get" |), + make_list [ + M.get_name (| globals, "key" |); + M.get_field (| M.get_name (| globals, "trie" |), "default" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition common_prefix_length : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "a"; "b" ] |) in + let _ := Constant.str " + Find the longest common prefix of two sequences. + " in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + ], + make_dict [] + |) do + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| M.get_name (| globals, "i" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition nibble_list_to_compact : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "x"; "is_leaf" ] |) in + let _ := Constant.str " + Compresses nibble-list into a standard byte array with a flag. + + A nibble-list is a list of byte values no greater than `15`. The flag is + encoded in high nibble of the highest byte. The flag nibble can be broken + down into two two-bit flags. + + Highest nibble:: + + +---+---+----------+--------+ + | _ | _ | is_leaf | parity | + +---+---+----------+--------+ + 3 2 1 0 + + + The lowest bit of the nibble encodes the parity of the length of the + remaining nibbles -- `0` when even and `1` when odd. The second lowest bit + is used to distinguish leaf and extension nodes. The other two bits are not + used. + + Parameters + ---------- + x : + Array of nibbles. + is_leaf : + True if this is part of a leaf node, or false if it is an extension + node. + + Returns + ------- + compressed : `bytearray` + Compact byte array. + " in + let compact := + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + Constant.int 2 + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.mult (| + Constant.int 16, + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "is_leaf" |) + |) + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + BinOp.add (| + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "is_leaf" |) + |), + Constant.int 1 + |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), Constant.int 0 |) + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 1; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + M.get_name (| globals, "compact" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition bytes_to_nibble_list : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "bytes_" ] |) in + let _ := Constant.str " + Converts a `Bytes` into to a sequence of nibbles (bytes with value < 16). + + Parameters + ---------- + bytes_: + The `Bytes` to convert. + + Returns + ------- + nibble_list : `Bytes` + The `Bytes` in nibble-list format. + " in + let nibble_list := + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [ + BinOp.mult (| + Constant.int 2, + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "bytes_" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + For make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ] in M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "bytes_" |) + ], + make_dict [] + |) do + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |) |), + BinOp.r_shift (| + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 240 + |), + Constant.int 4 + |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |), + Constant.int 1 + |) |), + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 15 + |) + |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + M.get_name (| globals, "nibble_list" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition _prepare_trie : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "get_storage_root" ] |) in + let _ := Constant.str " + Prepares the trie for root calculation. Removes values that are empty, + hashes the keys (if `secured == True`) and encodes all the nodes. + + Parameters + ---------- + trie : + The `Trie` to prepare. + get_storage_root : + Function to get the storage root of an account. Needed to encode + `Account` objects. + + Returns + ------- + out : `Mapping[ethereum.base_types.Bytes, Node]` + Object with keys mapped to nibble-byte form. + " in +(* At stmt: unsupported node type: AnnAssign *) + For make_tuple [ M.get_name (| globals, "preimage" |); M.get_name (| globals, "value" |) ] in M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "items" |), + make_list [], + make_dict [] + |) do + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in + let address := + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |); + M.call (| + M.get_name (| globals, "get_storage_root" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_eq (| M.get_name (| globals, "encoded_value" |), (* At constant: unsupported node type: Constant *) |); + M.get_name (| globals, "AssertionError" |) + ], + make_dict [] + |) in +(* At stmt: unsupported node type: AnnAssign *) + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "trie" |), "secured" |), + (* then *) + ltac:(M.monadic ( + let key := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let key := + M.get_name (| globals, "preimage" |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "mapped" |), M.call (| + M.get_name (| globals, "bytes_to_nibble_list" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |) |), + M.get_name (| globals, "encoded_value" |) + |) in + EndFor. + let _ := M.return_ (| + M.get_name (| globals, "mapped" |) + |) in + M.pure Constant.None_)). + +Definition root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "get_storage_root" ] |) in + let _ := Constant.str " + Computes the root of a modified merkle patricia trie (MPT). + + Parameters + ---------- + trie : + `Trie` to get the root of. + get_storage_root : + Function to get the storage root of an account. Needed to encode + `Account` objects. + + + Returns + ------- + root : `eth1spec.fork_types.Root` + MPT root of the underlying key-value pairs. + " in + let obj := + M.call (| + M.get_name (| globals, "_prepare_trie" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "get_storage_root" |) + ], + make_dict [] + |) in + let root_node := + M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_name (| globals, "obj" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assert (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "root_node" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Root" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition patricialize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "obj"; "level" ] |) in + let _ := Constant.str " + Structural composition function. + + Used to recursively patricialize and merkleize a dictionary. Includes + memoization of the tree structure and hashes. + + Parameters + ---------- + obj : + Underlying trie key-value pairs, with keys in nibble-list format. + level : + Current trie level. + + Returns + ------- + node : `eth1spec.base_types.Bytes` + Root node of `obj`. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let arbitrary_key := + M.call (| + M.get_name (| globals, "next" |), + make_list [ + M.call (| + M.get_name (| globals, "iter" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), Constant.int 1 |), + (* then *) + ltac:(M.monadic ( + let leaf := + M.call (| + M.get_name (| globals, "LeafNode" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |); + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "leaf" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let substring := + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) in + let prefix_length := + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "substring" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do + let prefix_length := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_name (| globals, "prefix_length" |); + M.call (| + M.get_name (| globals, "common_prefix_length" |), + make_list [ + M.get_name (| globals, "substring" |); + M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let prefix := + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ExtensionNode" |), + make_list [ + M.get_name (| globals, "prefix" |); + M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_name (| globals, "obj" |); + BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in +(* At stmt: unsupported node type: AnnAssign *) + For M.get_name (| globals, "_" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 16 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "branches" |), "append" |), + make_list [ + {} + ], + make_dict [] + |) in + EndFor. + let value := + (* At constant: unsupported node type: Constant *) in + For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |), M.get_name (| globals, "level" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "AssertionError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) + |) in + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "BranchNode" |), + make_list [ + [M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "branches" |), M.get_name (| globals, "k" |) |); + BinOp.add (| + M.get_name (| globals, "level" |), + Constant.int 1 + |) + ], + make_dict [] + |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)]; + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/utils/__init__.v b/CoqOfPython/ethereum/berlin/utils/__init__.v new file mode 100644 index 0000000..1baedea --- /dev/null +++ b/CoqOfPython/ethereum/berlin/utils/__init__.v @@ -0,0 +1,8 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Utility functions unique to this particular fork. +". diff --git a/CoqOfPython/ethereum/berlin/utils/address.v b/CoqOfPython/ethereum/berlin/utils/address.v new file mode 100644 index 0000000..7ff5b92 --- /dev/null +++ b/CoqOfPython/ethereum/berlin/utils/address.v @@ -0,0 +1,204 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Hardfork Utility Functions For Addresses +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Address specific functions used in this berlin version of +specification. +". + +Require typing. +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_left_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Definition to_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "data" ] |) in + let _ := Constant.str " + Convert a Uint or U256 value to a valid address (20 bytes). + + Parameters + ---------- + data : + The string to be converted to bytes. + + Returns + ------- + address : `Address` + The obtained address. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_subscript (| M.call (| + M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition compute_contract_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "address"; "nonce" ] |) in + let _ := Constant.str " + Computes address of the new account that needs to be created. + + Parameters + ---------- + address : + The address of the account that wants to create the new account. + nonce : + The transaction count of the account that wants to create the new + account. + + Returns + ------- + address: `Address` + The computed address of the new account. + " in + let computed_address := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_list [ + M.get_name (| globals, "address" |); + M.get_name (| globals, "nonce" |) + ] + ], + make_dict [] + |) + ], + make_dict [] + |) in + let canonical_address := + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + let padded_address := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "canonical_address" |); + Constant.int 20 + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "padded_address" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition compute_create2_contract_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "address"; "salt"; "call_data" ] |) in + let _ := Constant.str " + Computes address of the new account that needs to be created, which is + based on the sender address, salt and the call data as well. + + Parameters + ---------- + address : + The address of the account that wants to create the new account. + salt : + Address generation salt. + call_data : + The code of the new account which is to be created. + + Returns + ------- + address: `ethereum.berlin.fork_types.Address` + The computed address of the new account. + " in + let preimage := + BinOp.add (| + BinOp.add (| + BinOp.add (| + (* At constant: unsupported node type: Constant *), + M.get_name (| globals, "address" |) + |), + M.get_name (| globals, "salt" |) + |), + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "call_data" |) + ], + make_dict [] + |) + |) in + let computed_address := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + let canonical_address := + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + let padded_address := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "canonical_address" |); + Constant.int 20 + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "padded_address" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/utils/hexadecimal.v b/CoqOfPython/ethereum/berlin/utils/hexadecimal.v new file mode 100644 index 0000000..6f8dcdd --- /dev/null +++ b/CoqOfPython/ethereum/berlin/utils/hexadecimal.v @@ -0,0 +1,155 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Utility Functions For Hexadecimal Strings +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Hexadecimal utility functions used in this specification, specific to +Berlin types. +". + +Require ethereum.utils.hexadecimal. +Axiom ethereum_utils_hexadecimal_remove_hex_prefix : + IsGlobalAlias globals ethereum.utils.hexadecimal.globals "remove_hex_prefix". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Definition hex_to_root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to trie root. + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to trie root. + + Returns + ------- + root : `Root` + Trie root obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Root" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition hex_to_bloom : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to bloom. + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to bloom. + + Returns + ------- + bloom : `Bloom` + Bloom obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bloom" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition hex_to_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to Address (20 bytes). + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to Address. + + Returns + ------- + address : `Address` + The address obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |), "rjust" |), + make_list [ + Constant.int 40; + Constant.str "0" + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/utils/message.v b/CoqOfPython/ethereum/berlin/utils/message.v new file mode 100644 index 0000000..9b19085 --- /dev/null +++ b/CoqOfPython/ethereum/berlin/utils/message.v @@ -0,0 +1,254 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Hardfork Utility Functions For The Message Data-structure +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Message specific functions used in this berlin version of +specification. +". + +Require typing. +Axiom typing_FrozenSet : + IsGlobalAlias globals typing.globals "FrozenSet". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". + +Require vm. +Axiom vm_Environment : + IsGlobalAlias globals vm.globals "Environment". +Axiom vm_Message : + IsGlobalAlias globals vm.globals "Message". + +Require vm.precompiled_contracts.mapping. +Axiom vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : + IsGlobalAlias globals vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". + +Require address. +Axiom address_compute_contract_address : + IsGlobalAlias globals address.globals "compute_contract_address". + +Definition prepare_message : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "caller"; "target"; "value"; "data"; "gas"; "env"; "code_address"; "should_transfer_value"; "is_static"; "preaccessed_addresses"; "preaccessed_storage_keys" ] |) in + let _ := Constant.str " + Execute a transaction against the provided environment. + + Parameters + ---------- + caller : + Address which initiated the transaction + target : + Address whose code will be executed + value : + Value to be transferred. + data : + Array of bytes provided to the code in `target`. + gas : + Gas provided for the code in `target`. + env : + Environment for the Ethereum Virtual Machine. + code_address : + This is usually same as the `target` address except when an alternative + accounts code needs to be executed. + eg. `CALLCODE` calling a precompile. + should_transfer_value : + if True ETH should be transferred while executing a message call. + is_static: + if True then it prevents all state-changing operations from being + executed. + preaccessed_addresses: + Addresses that should be marked as accessed prior to the message call + preaccessed_storage_keys: + Storage keys that should be marked as accessed prior to the message + call + + Returns + ------- + message: `ethereum.berlin.vm.Message` + Items containing contract creation or message call specific data. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Bytes0" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.call (| + M.get_name (| globals, "compute_contract_address" |), + make_list [ + M.get_name (| globals, "caller" |); + BinOp.sub (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "caller" |) + ], + make_dict [] + |), "nonce" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let msg_data := + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |) in + let code := + M.get_name (| globals, "data" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.get_name (| globals, "target" |) in + let msg_data := + M.get_name (| globals, "data" |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "target" |) + ], + make_dict [] + |), "code" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "code_address" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let code_address := + M.get_name (| globals, "target" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "AssertionError" |), + make_list [ + Constant.str "Target must be address or empty bytes" + ], + make_dict [] + |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let accessed_addresses := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "current_target" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "caller" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "accessed_addresses" |), "update" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "PRE_COMPILED_CONTRACTS" |), "keys" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "accessed_addresses" |), "update" |), + make_list [ + M.get_name (| globals, "preaccessed_addresses" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/vm/__init__.v b/CoqOfPython/ethereum/berlin/vm/__init__.v new file mode 100644 index 0000000..2ff63cd --- /dev/null +++ b/CoqOfPython/ethereum/berlin/vm/__init__.v @@ -0,0 +1,262 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The abstract computer which runs the code stored in an +`.fork_types.Account`. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U64 : + IsGlobalAlias globals ethereum.base_types.globals "U64". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_State : + IsGlobalAlias globals state.globals "State". +Axiom state_account_exists_and_is_empty : + IsGlobalAlias globals state.globals "account_exists_and_is_empty". + +Require precompiled_contracts. +Axiom precompiled_contracts_RIPEMD160_ADDRESS : + IsGlobalAlias globals precompiled_contracts.globals "RIPEMD160_ADDRESS". + +Definition __all__ : Value.t := M.run ltac:(M.monadic ( + make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] +)). + +Definition Environment : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Message : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Evm : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition incorporate_child_on_success : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "child_evm" ] |) in + let _ := Constant.str " + Incorporate the state of a successful `child_evm` into the parent `evm`. + + Parameters + ---------- + evm : + The parent `EVM`. + child_evm : + The child evm to incorporate. + " in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "gas_left" |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "logs" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "logs" |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "refund_counter" |) + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "accounts_to_delete" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "accessed_addresses" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "accessed_storage_keys" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition incorporate_child_on_error : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "child_evm" ] |) in + let _ := Constant.str " + Incorporate the state of an unsuccessful `child_evm` into the parent `evm`. + + Parameters + ---------- + evm : + The parent `EVM`. + child_evm : + The child evm to incorporate. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "RIPEMD160_ADDRESS" |), M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |), M.get_name (| globals, "RIPEMD160_ADDRESS" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "gas_left" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/vm/exceptions.v b/CoqOfPython/ethereum/berlin/vm/exceptions.v new file mode 100644 index 0000000..8560cef --- /dev/null +++ b/CoqOfPython/ethereum/berlin/vm/exceptions.v @@ -0,0 +1,162 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Exceptions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Exceptions which cause the EVM to halt exceptionally. +". + +Require ethereum.exceptions. +Axiom ethereum_exceptions_EthereumException : + IsGlobalAlias globals ethereum.exceptions.globals "EthereumException". + +Definition ExceptionalHalt : Value.t := + builtins.make_klass + [(globals, "EthereumException")] + [ + + ] + [ + + ]. + +Definition Revert : Value.t := + builtins.make_klass + [(globals, "EthereumException")] + [ + + ] + [ + + ]. + +Definition StackUnderflowError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition StackOverflowError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition OutOfGasError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition InvalidOpcode : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + ( + "__init__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "code" ] |) in + let _ := M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "super" |), + make_list [], + make_dict [] + |), "__init__" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "self" |), "code" |), + M.get_name (| globals, "code" |) + |) in + M.pure Constant.None_)) + ) + ]. + +Definition InvalidJumpDestError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition StackDepthLimitError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition WriteInStaticContext : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition OutOfBoundsRead : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition InvalidParameter : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition AddressCollision : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/__init__.v b/CoqOfPython/ethereum/berlin/vm/instructions/__init__.v new file mode 100644 index 0000000..e5bebd7 --- /dev/null +++ b/CoqOfPython/ethereum/berlin/vm/instructions/__init__.v @@ -0,0 +1,87 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +EVM Instruction Encoding (Opcodes) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Machine readable representations of EVM instructions, and a mapping to their +implementations. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". + +Require __init__. +Axiom __init___arithmetic : + IsGlobalAlias globals __init__.globals "arithmetic". + +Require __init__. +Axiom __init___bitwise : + IsGlobalAlias globals __init__.globals "bitwise". + +Require __init__. +Axiom __init___block : + IsGlobalAlias globals __init__.globals "block". + +Require __init__. +Axiom __init___comparison : + IsGlobalAlias globals __init__.globals "comparison". + +Require __init__. +Axiom __init___control_flow : + IsGlobalAlias globals __init__.globals "control_flow". + +Require __init__. +Axiom __init___environment : + IsGlobalAlias globals __init__.globals "environment". + +Require __init__. +Axiom __init___keccak : + IsGlobalAlias globals __init__.globals "keccak". + +Require __init__. +Axiom __init___log : + IsGlobalAlias globals __init__.globals "log". + +Require __init__. +Axiom __init___memory : + IsGlobalAlias globals __init__.globals "memory". + +Require __init__. +Axiom __init___stack : + IsGlobalAlias globals __init__.globals "stack". + +Require __init__. +Axiom __init___storage : + IsGlobalAlias globals __init__.globals "storage". + +Require __init__. +Axiom __init___system : + IsGlobalAlias globals __init__.globals "system". + +Definition Ops : Value.t := + builtins.make_klass + [(* At base: unsupported node type: Attribute *)] + [ + + ] + [ + + ]. + +(* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/berlin/vm/instructions/arithmetic.v new file mode 100644 index 0000000..a8b5c61 --- /dev/null +++ b/CoqOfPython/ethereum/berlin/vm/instructions/arithmetic.v @@ -0,0 +1,1085 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Arithmetic Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM Arithmetic instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U255_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U255_CEIL_VALUE". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_U256_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_get_sign : + IsGlobalAlias globals ethereum.utils.numeric.globals "get_sign". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_EXPONENTIATION : + IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION". +Axiom gas_GAS_EXPONENTIATION_PER_BYTE : + IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION_PER_BYTE". +Axiom gas_GAS_LOW : + IsGlobalAlias globals gas.globals "GAS_LOW". +Axiom gas_GAS_MID : + IsGlobalAlias globals gas.globals "GAS_MID". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition add : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Adds the top two elements of the stack together, and pushes the result back + on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "x" |), "wrapping_add" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition sub : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Subtracts the top two elements of the stack, and pushes the result back + on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "x" |), "wrapping_sub" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mul : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Multiply the top two elements of the stack, and pushes the result back + on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "x" |), "wrapping_mul" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition div : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Integer division of the top two elements of the stack. Pushes the result + back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let dividend := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let divisor := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let quotient := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let quotient := + BinOp.floor_div (| + M.get_name (| globals, "dividend" |), + M.get_name (| globals, "divisor" |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "quotient" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition sdiv : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed integer division of the top two elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let dividend := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let divisor := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let quotient := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_name (| globals, "dividend" |), UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "divisor" |), UnOp.sub (| Constant.int 1 |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let quotient := + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let sign := + M.call (| + M.get_name (| globals, "get_sign" |), + make_list [ + BinOp.mult (| + M.get_name (| globals, "dividend" |), + M.get_name (| globals, "divisor" |) + |) + ], + make_dict [] + |) in + let quotient := + BinOp.mult (| + M.get_name (| globals, "sign" |), + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "dividend" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "divisor" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + M.get_name (| globals, "quotient" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Modulo remainder of the top two elements of the stack. Pushes the result + back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let remainder := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let remainder := + BinOp.mod_ (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "remainder" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition smod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed modulo remainder of the top two elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let y := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let remainder := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let remainder := + BinOp.mult (| + M.call (| + M.get_name (| globals, "get_sign" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + BinOp.mod_ (| + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + M.get_name (| globals, "remainder" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition addmod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Modulo addition of the top 2 elements with the 3rd element. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let z := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_MID" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.add (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |), + M.get_name (| globals, "z" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mulmod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Modulo multiplication of the top 2 elements with the 3rd element. Pushes + the result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let z := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_MID" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.mult (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |), + M.get_name (| globals, "z" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition exp : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Exponential operation of the top 2 elements. Pushes the result back on + the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let base := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exponent := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exponent_bits := + M.call (| + M.get_field (| M.get_name (| globals, "exponent" |), "bit_length" |), + make_list [], + make_dict [] + |) in + let exponent_bytes := + BinOp.floor_div (| + BinOp.add (| + M.get_name (| globals, "exponent_bits" |), + Constant.int 7 + |), + Constant.int 8 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_EXPONENTIATION" |), + BinOp.mult (| + M.get_name (| globals, "GAS_EXPONENTIATION_PER_BYTE" |), + M.get_name (| globals, "exponent_bytes" |) + |) + |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "pow" |), + make_list [ + M.get_name (| globals, "base" |); + M.get_name (| globals, "exponent" |); + M.get_name (| globals, "U256_CEIL_VALUE" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition signextend : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Sign extend operation. In other words, extend a signed number which + fits in N bytes to 32 bytes. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let byte_num := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "byte_num" |), Constant.int 31 |), + (* then *) + ltac:(M.monadic ( + let result := + M.get_name (| globals, "value" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let value_bytes := + M.call (| + M.get_name (| globals, "bytes" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "value" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) in + let value_bytes := + M.get_subscript (| M.get_name (| globals, "value_bytes" |), BinOp.sub (| + Constant.int 31, + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "byte_num" |) + ], + make_dict [] + |) + |):(* At expr: unsupported node type: NoneType *) |) in + let sign_bit := + BinOp.r_shift (| + M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), + Constant.int 7 + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "sign_bit" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "value_bytes" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let num_bytes_prepend := + BinOp.sub (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "byte_num" |), + Constant.int 1 + |) + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + BinOp.add (| + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [ + BinOp.mult (| + make_list [ + Constant.int 255 + ], + M.get_name (| globals, "num_bytes_prepend" |) + |) + ], + make_dict [] + |), + M.get_name (| globals, "value_bytes" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/bitwise.v b/CoqOfPython/ethereum/berlin/vm/instructions/bitwise.v new file mode 100644 index 0000000..9f2f382 --- /dev/null +++ b/CoqOfPython/ethereum/berlin/vm/instructions/bitwise.v @@ -0,0 +1,601 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Bitwise Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM bitwise instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_U256_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition bitwise_and : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise AND operation of the top 2 elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + BinOp.bit_and (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_or : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise OR operation of the top 2 elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + BinOp.bit_or (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_xor : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise XOR operation of the top 2 elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + BinOp.bit_xor (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_not : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise NOT operation of the top element of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + UnOp.invert (| M.get_name (| globals, "x" |) |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition get_byte : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + For a word (defined by next top element of the stack), retrieve the + Nth byte (0-indexed and defined by top element of stack) from the + left (most significant) to right (least significant). + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let byte_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let word := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "byte_index" |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let extra_bytes_to_right := + BinOp.sub (| + Constant.int 31, + M.get_name (| globals, "byte_index" |) + |) in + let word := + BinOp.r_shift (| + M.get_name (| globals, "word" |), + BinOp.mult (| + M.get_name (| globals, "extra_bytes_to_right" |), + Constant.int 8 + |) + |) in + let word := + BinOp.bit_and (| + M.get_name (| globals, "word" |), + Constant.int 255 + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "word" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_shl : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Logical shift left (SHL) operation of the top 2 elements of the stack. + Pushes the result back on the stack. + Parameters + ---------- + evm : + The current EVM frame. + " in + let shift := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.l_shift (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "shift" |) + |), + M.get_name (| globals, "U256_CEIL_VALUE" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_shr : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Logical shift right (SHR) operation of the top 2 elements of the stack. + Pushes the result back on the stack. + Parameters + ---------- + evm : + The current EVM frame. + " in + let shift := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), + (* then *) + ltac:(M.monadic ( + let result := + BinOp.r_shift (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "shift" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_sar : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Arithmetic shift right (SAR) operation of the top 2 elements of the stack. + Pushes the result back on the stack. + Parameters + ---------- + evm : + The current EVM frame. + " in + let shift := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let signed_value := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + BinOp.r_shift (| + M.get_name (| globals, "signed_value" |), + M.get_name (| globals, "shift" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "signed_value" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/block.v b/CoqOfPython/ethereum/berlin/vm/instructions/block.v new file mode 100644 index 0000000..26c73a7 --- /dev/null +++ b/CoqOfPython/ethereum/berlin/vm/instructions/block.v @@ -0,0 +1,379 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Block Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM block instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_BLOCK_HASH : + IsGlobalAlias globals gas.globals "GAS_BLOCK_HASH". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition block_hash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the hash of one of the 256 most recent complete blocks onto the + stack. The block number to hash is present at the top of the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let block_number := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BLOCK_HASH" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt_e (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), M.get_name (| globals, "block_number" |) |), + ltac:(M.monadic ( + Compare.gt (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), BinOp.add (| + M.get_name (| globals, "block_number" |), + Constant.int 256 + |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let hash := + (* At constant: unsupported node type: Constant *) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let hash := + M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + M.get_name (| globals, "block_number" |) + |) |) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "hash" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition coinbase : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's beneficiary address (address of the block miner) + onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "coinbase" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition timestamp : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's timestamp onto the stack. Here the timestamp + being referred is actually the unix timestamp in seconds. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "time" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition number : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's number onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition difficulty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's difficulty onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "difficulty" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition gas_limit : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's gas limit onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "gas_limit" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition chain_id : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the chain id onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "chain_id" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/comparison.v b/CoqOfPython/ethereum/berlin/vm/instructions/comparison.v new file mode 100644 index 0000000..fbc35f8 --- /dev/null +++ b/CoqOfPython/ethereum/berlin/vm/instructions/comparison.v @@ -0,0 +1,404 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Comparison Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM Comparison instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition less_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is less than the next top element. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let right := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition signed_less_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed less-than comparison. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let right := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition greater_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is greater than the next top element. Pushes + the result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let right := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition signed_greater_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed greater-than comparison. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let right := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition equal : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is equal to the next top element. Pushes + the result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let right := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.eq (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition is_zero : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is equal to 0. Pushes the result back on the + stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.eq (| M.get_name (| globals, "x" |), Constant.int 0 |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/control_flow.v b/CoqOfPython/ethereum/berlin/vm/instructions/control_flow.v new file mode 100644 index 0000000..04a79d9 --- /dev/null +++ b/CoqOfPython/ethereum/berlin/vm/instructions/control_flow.v @@ -0,0 +1,336 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Control Flow Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM control flow instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require vm.gas. +Axiom vm_gas_GAS_BASE : + IsGlobalAlias globals vm.gas.globals "GAS_BASE". +Axiom vm_gas_GAS_HIGH : + IsGlobalAlias globals vm.gas.globals "GAS_HIGH". +Axiom vm_gas_GAS_JUMPDEST : + IsGlobalAlias globals vm.gas.globals "GAS_JUMPDEST". +Axiom vm_gas_GAS_MID : + IsGlobalAlias globals vm.gas.globals "GAS_MID". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_InvalidJumpDestError : + IsGlobalAlias globals exceptions.globals "InvalidJumpDestError". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition stop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stop further execution of EVM code. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let _ := M.pass (| |) in + let _ := M.pass (| |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "running" |), + Constant.bool false + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition jump : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Alter the program counter to the location specified by the top of the + stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let jump_dest := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_MID" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "jump_dest" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition jumpi : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Alter the program counter to the specified location if and only if a + condition is true. If the condition is not true, then the program counter + would increase only by 1. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let jump_dest := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let conditional_value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_HIGH" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "conditional_value" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let destination := + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let destination := + M.get_name (| globals, "jump_dest" |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "destination" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition pc : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push onto the stack the value of the program counter after reaching the + current instruction and without increasing it for the next instruction. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "pc" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition gas_left : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the amount of available gas (including the corresponding reduction + for the cost of this instruction) onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition jumpdest : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Mark a valid destination for jumps. This is a noop, present only + to be used by `JUMP` and `JUMPI` opcodes to verify that their jump is + valid. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_JUMPDEST" |) + ], + make_dict [] + |) in + let _ := M.pass (| |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/environment.v b/CoqOfPython/ethereum/berlin/vm/instructions/environment.v new file mode 100644 index 0000000..05f8cdf --- /dev/null +++ b/CoqOfPython/ethereum/berlin/vm/instructions/environment.v @@ -0,0 +1,1394 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Environmental Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM environment related instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require fork_types. +Axiom fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". + +Require state. +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". + +Require utils.address. +Axiom utils_address_to_address : + IsGlobalAlias globals utils.address.globals "to_address". + +Require vm.memory. +Axiom vm_memory_buffer_read : + IsGlobalAlias globals vm.memory.globals "buffer_read". +Axiom vm_memory_memory_write : + IsGlobalAlias globals vm.memory.globals "memory_write". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_OutOfBoundsRead : + IsGlobalAlias globals exceptions.globals "OutOfBoundsRead". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_COLD_ACCOUNT_ACCESS : + IsGlobalAlias globals gas.globals "GAS_COLD_ACCOUNT_ACCESS". +Axiom gas_GAS_COPY : + IsGlobalAlias globals gas.globals "GAS_COPY". +Axiom gas_GAS_FAST_STEP : + IsGlobalAlias globals gas.globals "GAS_FAST_STEP". +Axiom gas_GAS_RETURN_DATA_COPY : + IsGlobalAlias globals gas.globals "GAS_RETURN_DATA_COPY". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_GAS_WARM_ACCESS : + IsGlobalAlias globals gas.globals "GAS_WARM_ACCESS". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the address of the current executing account to the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition balance : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the balance of the given account onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "balance" |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "balance" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition origin : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the address of the original transaction sender to the stack. + The origin address can only be an EOA. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "origin" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition caller : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the address of the caller onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "caller" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition callvalue : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the value (in wei) sent with the call onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition calldataload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push a word (32 bytes) of the input data belonging to the current + environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |); + M.get_name (| globals, "start_index" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition calldatasize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the size of input data in current environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition calldatacopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy a portion of the input data in current environment to memory. + + This will also expand the memory, in case that the memory is insufficient + to store the data. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let data_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |); + M.get_name (| globals, "data_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition codesize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the size of code running in current environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "code" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition codecopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy a portion of the code in current environment to memory. + + This will also expand the memory, in case that the memory is insufficient + to store the data. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let code_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "code" |); + M.get_name (| globals, "code_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition gasprice : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the gas price used in current environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "gas_price" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition extcodesize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the code size of a given account onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let codesize := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "code" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "codesize" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition extcodecopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy a portion of an account's code to memory. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let code_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_WARM_ACCESS" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "code" |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "code" |); + M.get_name (| globals, "code_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition returndatasize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the size of the return data buffer onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition returndatacopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copies data from the return data buffer code to memory + + Parameters + ---------- + evm : + The current EVM frame. + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let return_data_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_RETURN_DATA_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "return_data_start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "OutOfBoundsRead" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |):BinOp.add (| + M.get_name (| globals, "return_data_start_position" |), + M.get_name (| globals, "size" |) + |) |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition extcodehash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Returns the keccak256 hash of a contract’s bytecode + Parameters + ---------- + evm : + The current EVM frame. + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "account" |), M.get_name (| globals, "EMPTY_ACCOUNT" |) |), + (* then *) + ltac:(M.monadic ( + let codehash := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let codehash := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_field (| M.get_name (| globals, "account" |), "code" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "codehash" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition self_balance : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the balance of the current address to the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_FAST_STEP" |) + ], + make_dict [] + |) in + let balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "balance" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/keccak.v b/CoqOfPython/ethereum/berlin/vm/instructions/keccak.v new file mode 100644 index 0000000..cab9ffb --- /dev/null +++ b/CoqOfPython/ethereum/berlin/vm/instructions/keccak.v @@ -0,0 +1,181 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Keccak Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM keccak instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_KECCAK256 : + IsGlobalAlias globals gas.globals "GAS_KECCAK256". +Axiom gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition keccak : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes to the stack the Keccak-256 hash of a region of memory. + + This also expands the memory, in case the memory is insufficient to + access the data's memory location. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let word_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_KECCAK256_WORD" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_KECCAK256" |), + M.get_name (| globals, "word_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let data := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "hash" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/log.v b/CoqOfPython/ethereum/berlin/vm/instructions/log.v new file mode 100644 index 0000000..4891a4d --- /dev/null +++ b/CoqOfPython/ethereum/berlin/vm/instructions/log.v @@ -0,0 +1,244 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Logging Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM logging instructions. +". + +Require functools. +Axiom functools_partial : + IsGlobalAlias globals functools.globals "partial". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_WriteInStaticContext : + IsGlobalAlias globals exceptions.globals "WriteInStaticContext". + +Require gas. +Axiom gas_GAS_LOG : + IsGlobalAlias globals gas.globals "GAS_LOG". +Axiom gas_GAS_LOG_DATA : + IsGlobalAlias globals gas.globals "GAS_LOG_DATA". +Axiom gas_GAS_LOG_TOPIC : + IsGlobalAlias globals gas.globals "GAS_LOG_TOPIC". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". + +Definition log_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "num_topics" ] |) in + let _ := Constant.str " + Appends a log entry, having `num_topics` topics, to the evm logs. + + This will also expand the memory if the data (required by the log entry) + corresponding to the memory is not accessible. + + Parameters + ---------- + evm : + The current EVM frame. + num_topics : + The number of topics to be included in the log entry. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let topics := + make_list [] in + For M.get_name (| globals, "_" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "num_topics" |) + ], + make_dict [] + |) do + let topic := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "topics" |), "append" |), + make_list [ + M.get_name (| globals, "topic" |) + ], + make_dict [] + |) in + EndFor. + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_LOG" |), + BinOp.mult (| + M.get_name (| globals, "GAS_LOG_DATA" |), + M.get_name (| globals, "size" |) + |) + |), + BinOp.mult (| + M.get_name (| globals, "GAS_LOG_TOPIC" |), + M.get_name (| globals, "num_topics" |) + |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let log_entry := + M.call (| + M.get_name (| globals, "Log" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "logs" |), + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "logs" |), + make_tuple [ M.get_name (| globals, "log_entry" |) ] + |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition log0 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/memory.v b/CoqOfPython/ethereum/berlin/vm/instructions/memory.v new file mode 100644 index 0000000..1e1c8b0 --- /dev/null +++ b/CoqOfPython/ethereum/berlin/vm/instructions/memory.v @@ -0,0 +1,378 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Memory Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM Memory instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". +Axiom memory_memory_write : + IsGlobalAlias globals memory.globals "memory_write". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition mstore : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a word to memory. + This also expands the memory, if the memory is + insufficient to store the word. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "start_position" |); M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + ], + make_dict [] + |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "start_position" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mstore8 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a byte to memory. + This also expands the memory, if the memory is + insufficient to store the word. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "start_position" |); M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let normalized_bytes_value := + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + make_list [ + BinOp.bit_and (| + M.get_name (| globals, "value" |), + Constant.int 255 + |) + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "start_position" |); + M.get_name (| globals, "normalized_bytes_value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Load word from memory. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "start_position" |); M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "start_position" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition msize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the size of active memory in bytes onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/stack.v b/CoqOfPython/ethereum/berlin/vm/instructions/stack.v new file mode 100644 index 0000000..1eeda05 --- /dev/null +++ b/CoqOfPython/ethereum/berlin/vm/instructions/stack.v @@ -0,0 +1,929 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Stack Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM stack related instructions. +". + +Require functools. +Axiom functools_partial : + IsGlobalAlias globals functools.globals "partial". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". +Axiom __init___stack : + IsGlobalAlias globals __init__.globals "stack". + +Require exceptions. +Axiom exceptions_StackUnderflowError : + IsGlobalAlias globals exceptions.globals "StackUnderflowError". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_buffer_read : + IsGlobalAlias globals memory.globals "buffer_read". + +Definition pop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Remove item from stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.pass (| |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition push_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "num_bytes" ] |) in + let _ := Constant.str " + Pushes a N-byte immediate onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + num_bytes : + The number of immediate bytes to be read from the code and pushed to + the stack. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let data_to_push := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "code" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "num_bytes" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "data_to_push" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + BinOp.add (| + Constant.int 1, + M.get_name (| globals, "num_bytes" |) + |) + |) in + M.pure Constant.None_)). + +Definition dup_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "item_number" ] |) in + let _ := Constant.str " + Duplicate the Nth stack item (from top of the stack) to the top of stack. + + Parameters + ---------- + evm : + The current EVM frame. + + item_number : + The stack item number (0-indexed from top of stack) to be duplicated + to the top of stack. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "StackUnderflowError" |) + ], + make_dict [] + |) in + let data_to_duplicate := + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + BinOp.sub (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), + Constant.int 1 + |), + M.get_name (| globals, "item_number" |) + |) |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "data_to_duplicate" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition swap_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "item_number" ] |) in + let _ := Constant.str " + Swap the top and the `item_number` element of the stack, where + the top of the stack is position zero. + + If `item_number` is zero, this function does nothing (which should not be + possible, since there is no `SWAP0` instruction). + + Parameters + ---------- + evm : + The current EVM frame. + + item_number : + The stack item number (0-indexed from top of stack) to be swapped + with the top of stack element. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "StackUnderflowError" |) + ], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) |) ], + make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |) ] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition push1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push5 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push6 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push7 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push8 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push9 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push10 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push11 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push12 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push13 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push14 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push15 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push16 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push17 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push18 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push19 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push20 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push21 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push22 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push23 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push24 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push25 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push26 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push27 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push28 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push29 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push30 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push31 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push32 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition dup1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup5 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup6 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup7 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup8 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup9 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup10 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup11 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup12 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup13 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup14 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup15 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup16 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition swap1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap5 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap6 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap7 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap8 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap9 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap10 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap11 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap12 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap13 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap14 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap15 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap16 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/storage.v b/CoqOfPython/ethereum/berlin/vm/instructions/storage.v new file mode 100644 index 0000000..2f0a831 --- /dev/null +++ b/CoqOfPython/ethereum/berlin/vm/instructions/storage.v @@ -0,0 +1,437 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Storage Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM storage related instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require state. +Axiom state_get_storage : + IsGlobalAlias globals state.globals "get_storage". +Axiom state_get_storage_original : + IsGlobalAlias globals state.globals "get_storage_original". +Axiom state_set_storage : + IsGlobalAlias globals state.globals "set_storage". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". +Axiom exceptions_WriteInStaticContext : + IsGlobalAlias globals exceptions.globals "WriteInStaticContext". + +Require gas. +Axiom gas_GAS_CALL_STIPEND : + IsGlobalAlias globals gas.globals "GAS_CALL_STIPEND". +Axiom gas_GAS_COLD_SLOAD : + IsGlobalAlias globals gas.globals "GAS_COLD_SLOAD". +Axiom gas_GAS_STORAGE_CLEAR_REFUND : + IsGlobalAlias globals gas.globals "GAS_STORAGE_CLEAR_REFUND". +Axiom gas_GAS_STORAGE_SET : + IsGlobalAlias globals gas.globals "GAS_STORAGE_SET". +Axiom gas_GAS_STORAGE_UPDATE : + IsGlobalAlias globals gas.globals "GAS_STORAGE_UPDATE". +Axiom gas_GAS_WARM_ACCESS : + IsGlobalAlias globals gas.globals "GAS_WARM_ACCESS". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition sload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Loads to the stack, the value corresponding to a certain key from the + storage of the current account. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let key := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "add" |), + make_list [ + make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_COLD_SLOAD" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let value := + M.call (| + M.get_name (| globals, "get_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition sstore : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a value at a certain key in the current context's storage. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let key := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let new_value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt (| M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), M.get_name (| globals, "GAS_CALL_STIPEND" |) |); + M.get_name (| globals, "OutOfGasError" |) + ], + make_dict [] + |) in + let original_value := + M.call (| + M.get_name (| globals, "get_storage_original" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let current_value := + M.call (| + M.get_name (| globals, "get_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let gas_cost := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "add" |), + make_list [ + make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ] + ], + make_dict [] + |) in + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_COLD_SLOAD" |) + M.get_name (| globals, "GAS_COLD_SLOAD" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_name (| globals, "original_value" |), M.get_name (| globals, "current_value" |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_name (| globals, "current_value" |), M.get_name (| globals, "new_value" |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_STORAGE_SET" |) + M.get_name (| globals, "GAS_STORAGE_SET" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let gas_cost := BinOp.add + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_UPDATE" |), + M.get_name (| globals, "GAS_COLD_SLOAD" |) + |) + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_UPDATE" |), + M.get_name (| globals, "GAS_COLD_SLOAD" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_WARM_ACCESS" |) + M.get_name (| globals, "GAS_WARM_ACCESS" |) in + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| M.get_name (| globals, "current_value" |), M.get_name (| globals, "new_value" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "new_value" |), Constant.int 0 |) + )) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.sub, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "original_value" |), M.get_name (| globals, "new_value" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_SET" |), + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.sub (| + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_UPDATE" |), + M.get_name (| globals, "GAS_COLD_SLOAD" |) + |), + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "gas_cost" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "set_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |); + M.get_name (| globals, "new_value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/vm/interpreter.v b/CoqOfPython/ethereum/berlin/vm/interpreter.v new file mode 100644 index 0000000..401ea98 --- /dev/null +++ b/CoqOfPython/ethereum/berlin/vm/interpreter.v @@ -0,0 +1,643 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Interpreter +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +A straightforward interpreter that executes EVM code. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Iterable : + IsGlobalAlias globals typing.globals "Iterable". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.trace. +Axiom ethereum_trace_EvmStop : + IsGlobalAlias globals ethereum.trace.globals "EvmStop". +Axiom ethereum_trace_OpEnd : + IsGlobalAlias globals ethereum.trace.globals "OpEnd". +Axiom ethereum_trace_OpException : + IsGlobalAlias globals ethereum.trace.globals "OpException". +Axiom ethereum_trace_OpStart : + IsGlobalAlias globals ethereum.trace.globals "OpStart". +Axiom ethereum_trace_PrecompileEnd : + IsGlobalAlias globals ethereum.trace.globals "PrecompileEnd". +Axiom ethereum_trace_PrecompileStart : + IsGlobalAlias globals ethereum.trace.globals "PrecompileStart". +Axiom ethereum_trace_TransactionEnd : + IsGlobalAlias globals ethereum.trace.globals "TransactionEnd". +Axiom ethereum_trace_evm_trace : + IsGlobalAlias globals ethereum.trace.globals "evm_trace". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_account_exists_and_is_empty : + IsGlobalAlias globals state.globals "account_exists_and_is_empty". +Axiom state_account_has_code_or_nonce : + IsGlobalAlias globals state.globals "account_has_code_or_nonce". +Axiom state_begin_transaction : + IsGlobalAlias globals state.globals "begin_transaction". +Axiom state_commit_transaction : + IsGlobalAlias globals state.globals "commit_transaction". +Axiom state_destroy_storage : + IsGlobalAlias globals state.globals "destroy_storage". +Axiom state_increment_nonce : + IsGlobalAlias globals state.globals "increment_nonce". +Axiom state_mark_account_created : + IsGlobalAlias globals state.globals "mark_account_created". +Axiom state_move_ether : + IsGlobalAlias globals state.globals "move_ether". +Axiom state_rollback_transaction : + IsGlobalAlias globals state.globals "rollback_transaction". +Axiom state_set_code : + IsGlobalAlias globals state.globals "set_code". +Axiom state_touch_account : + IsGlobalAlias globals state.globals "touch_account". + +Require vm. +Axiom vm_Message : + IsGlobalAlias globals vm.globals "Message". + +Require vm.gas. +Axiom vm_gas_GAS_CODE_DEPOSIT : + IsGlobalAlias globals vm.gas.globals "GAS_CODE_DEPOSIT". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require vm.precompiled_contracts.mapping. +Axiom vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : + IsGlobalAlias globals vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". + +Require __init__. +Axiom __init___Environment : + IsGlobalAlias globals __init__.globals "Environment". +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_AddressCollision : + IsGlobalAlias globals exceptions.globals "AddressCollision". +Axiom exceptions_ExceptionalHalt : + IsGlobalAlias globals exceptions.globals "ExceptionalHalt". +Axiom exceptions_InvalidOpcode : + IsGlobalAlias globals exceptions.globals "InvalidOpcode". +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". +Axiom exceptions_Revert : + IsGlobalAlias globals exceptions.globals "Revert". +Axiom exceptions_StackDepthLimitError : + IsGlobalAlias globals exceptions.globals "StackDepthLimitError". + +Require instructions. +Axiom instructions_Ops : + IsGlobalAlias globals instructions.globals "Ops". +Axiom instructions_op_implementation : + IsGlobalAlias globals instructions.globals "op_implementation". + +Require runtime. +Axiom runtime_get_valid_jump_destinations : + IsGlobalAlias globals runtime.globals "get_valid_jump_destinations". + +Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1024 + ], + make_dict [] + |) +)). + +Definition MAX_CODE_SIZE : Value.t := M.run ltac:(M.monadic ( + Constant.int 24576 +)). + +Definition MessageCallOutput : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition process_message_call : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + If `message.current` is empty then it creates a smart contract + else it executes a call from the `message.caller` to the `message.target`. + + Parameters + ---------- + message : + Transaction specific items. + + env : + External items required for EVM execution. + + Returns + ------- + output : `MessageCallOutput` + Output of the message call + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_name (| globals, "message" |), "target" |), M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let is_collision := + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_name (| globals, "is_collision" |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallOutput" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "tuple" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "AddressCollision" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let evm := + M.call (| + M.get_name (| globals, "process_create_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let evm := + M.call (| + M.get_name (| globals, "process_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_field (| M.get_name (| globals, "message" |), "target" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_field (| M.get_name (| globals, "message" |), "target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( +(* At stmt: unsupported node type: AnnAssign *) + let accounts_to_delete := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let touched_accounts := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let refund_counter := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let logs := + M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in + let accounts_to_delete := + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in + let touched_accounts := + M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |) in + let refund_counter := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let tx_end := + M.call (| + M.get_name (| globals, "TransactionEnd" |), + make_list [ + BinOp.sub (| + M.get_field (| M.get_name (| globals, "message" |), "gas" |), + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + |); + M.get_field (| M.get_name (| globals, "evm" |), "output" |); + M.get_field (| M.get_name (| globals, "evm" |), "error" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "evm_trace" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "tx_end" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallOutput" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition process_create_message : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + Executes a call to create a smart contract. + + Parameters + ---------- + message : + Transaction specific items. + env : + External items required for EVM execution. + + Returns + ------- + evm: :py:class:`~ethereum.berlin.vm.Evm` + Items containing execution specific objects. + " in + let _ := M.call (| + M.get_name (| globals, "begin_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "destroy_storage" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "mark_account_created" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let evm := + M.call (| + M.get_name (| globals, "process_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), + (* then *) + ltac:(M.monadic ( + let contract_code := + M.get_field (| M.get_name (| globals, "evm" |), "output" |) in + let contract_code_gas := + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "contract_code" |) + ], + make_dict [] + |), + M.get_name (| globals, "GAS_CODE_DEPOSIT" |) + |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "rollback_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.get_name (| globals, "evm" |) + |) in + M.pure Constant.None_)). + +Definition process_message : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + Executes a call to create a smart contract. + + Parameters + ---------- + message : + Transaction specific items. + env : + External items required for EVM execution. + + Returns + ------- + evm: :py:class:`~ethereum.berlin.vm.Evm` + Items containing execution specific objects + " in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_field (| M.get_name (| globals, "message" |), "depth" |), M.get_name (| globals, "STACK_DEPTH_LIMIT" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "StackDepthLimitError" |), + make_list [ + Constant.str "Stack depth limit reached" + ], + make_dict [] + |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "begin_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "touch_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + M.get_field (| M.get_name (| globals, "message" |), "should_transfer_value" |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_field (| M.get_name (| globals, "message" |), "value" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "move_ether" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "caller" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |); + M.get_field (| M.get_name (| globals, "message" |), "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let evm := + M.call (| + M.get_name (| globals, "execute_code" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "rollback_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "commit_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.get_name (| globals, "evm" |) + |) in + M.pure Constant.None_)). + +Definition execute_code : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + Executes bytecode present in the `message`. + + Parameters + ---------- + message : + Transaction specific items. + env : + External items required for EVM execution. + + Returns + ------- + evm: `ethereum.vm.EVM` + Items containing execution specific objects + " in + let code := + M.get_field (| M.get_name (| globals, "message" |), "code" |) in + let valid_jump_destinations := + M.call (| + M.get_name (| globals, "get_valid_jump_destinations" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) in + let evm := + M.call (| + M.get_name (| globals, "Evm" |), + make_list [], + make_dict [] + |) in +(* At stmt: unsupported node type: Try *) + let _ := M.return_ (| + M.get_name (| globals, "evm" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/vm/memory.v b/CoqOfPython/ethereum/berlin/vm/memory.v new file mode 100644 index 0000000..fa8d906 --- /dev/null +++ b/CoqOfPython/ethereum/berlin/vm/memory.v @@ -0,0 +1,153 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Memory +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +EVM memory operations. +". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_right_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "right_pad_zero_bytes". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". + +Definition memory_write : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "memory"; "start_position"; "value" ] |) in + let _ := Constant.str " + Writes to memory. + + Parameters + ---------- + memory : + Memory contents of the EVM. + start_position : + Starting pointer to the memory. + value : + Data to write to memory. + " in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) |), + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_)). + +Definition memory_read_bytes : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "memory"; "start_position"; "size" ] |) in + let _ := Constant.str " + Read bytes from memory. + + Parameters + ---------- + memory : + Memory contents of the EVM. + start_position : + Starting pointer to the memory. + size : + Size of the data that needs to be read from `start_position`. + + Returns + ------- + data_bytes : + Data read from memory. + " in + let _ := M.return_ (| + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |) + |) in + M.pure Constant.None_)). + +Definition buffer_read : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "buffer"; "start_position"; "size" ] |) in + let _ := Constant.str " + Read bytes from a buffer. Padding with zeros if necessary. + + Parameters + ---------- + buffer : + Memory contents of the EVM. + start_position : + Starting pointer to the memory. + size : + Size of the data that needs to be read from `start_position`. + + Returns + ------- + data_bytes : + Data read from memory. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "right_pad_zero_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/__init__.v new file mode 100644 index 0000000..ca49311 --- /dev/null +++ b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/__init__.v @@ -0,0 +1,117 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Precompiled Contract Addresses +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Addresses of precompiled contracts and mappings to their +implementations. +". + +Require utils.hexadecimal. +Axiom utils_hexadecimal_hex_to_address : + IsGlobalAlias globals utils.hexadecimal.globals "hex_to_address". + +Definition __all__ : Value.t := M.run ltac:(M.monadic ( + make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS"; Constant.str "MODEXP_ADDRESS"; Constant.str "ALT_BN128_ADD_ADDRESS"; Constant.str "ALT_BN128_MUL_ADDRESS"; Constant.str "ALT_BN128_PAIRING_CHECK_ADDRESS"; Constant.str "BLAKE2F_ADDRESS" ] +)). + +Definition ECRECOVER_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x01" + ], + make_dict [] + |) +)). + +Definition SHA256_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x02" + ], + make_dict [] + |) +)). + +Definition RIPEMD160_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x03" + ], + make_dict [] + |) +)). + +Definition IDENTITY_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x04" + ], + make_dict [] + |) +)). + +Definition MODEXP_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x05" + ], + make_dict [] + |) +)). + +Definition ALT_BN128_ADD_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x06" + ], + make_dict [] + |) +)). + +Definition ALT_BN128_MUL_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x07" + ], + make_dict [] + |) +)). + +Definition ALT_BN128_PAIRING_CHECK_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x08" + ], + make_dict [] + |) +)). + +Definition BLAKE2F_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x09" + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/alt_bn128.v new file mode 100644 index 0000000..19b83fc --- /dev/null +++ b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/alt_bn128.v @@ -0,0 +1,673 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) ALT_BN128 CONTRACTS +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the ALT_BN128 precompiled contracts. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.alt_bn128. +Axiom ethereum_crypto_alt_bn128_ALT_BN128_CURVE_ORDER : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "ALT_BN128_CURVE_ORDER". +Axiom ethereum_crypto_alt_bn128_ALT_BN128_PRIME : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "ALT_BN128_PRIME". +Axiom ethereum_crypto_alt_bn128_BNF : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF". +Axiom ethereum_crypto_alt_bn128_BNF2 : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF2". +Axiom ethereum_crypto_alt_bn128_BNF12 : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF12". +Axiom ethereum_crypto_alt_bn128_BNP : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNP". +Axiom ethereum_crypto_alt_bn128_BNP2 : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNP2". +Axiom ethereum_crypto_alt_bn128_pairing : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "pairing". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require vm.memory. +Axiom vm_memory_buffer_read : + IsGlobalAlias globals vm.memory.globals "buffer_read". + +Require exceptions. +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". + +Definition alt_bn128_add : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + The ALT_BN128 addition precompiled contract. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 150 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x0_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x0_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "x0_bytes" |) + ], + make_dict [] + |) in + let y0_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y0_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "y0_bytes" |) + ], + make_dict [] + |) in + let x1_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x1_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "x1_bytes" |) + ], + make_dict [] + |) in + let y1_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y1_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "y1_bytes" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ] do + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "i" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. +(* At stmt: unsupported node type: Try *) + let p := + BinOp.add (| + M.get_name (| globals, "p0" |), + M.get_name (| globals, "p1" |) + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + BinOp.add (| + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "p" |), "x" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "p" |), "y" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) + |) in + M.pure Constant.None_)). + +Definition alt_bn128_mul : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + The ALT_BN128 multiplication precompiled contract. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 6000 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x0_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x0_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "x0_bytes" |) + ], + make_dict [] + |) in + let y0_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y0_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "y0_bytes" |) + ], + make_dict [] + |) in + let n := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ] do + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "i" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. +(* At stmt: unsupported node type: Try *) + let p := + M.call (| + M.get_field (| M.get_name (| globals, "p0" |), "mul_by" |), + make_list [ + M.get_name (| globals, "n" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + BinOp.add (| + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "p" |), "x" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "p" |), "y" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) + |) in + M.pure Constant.None_)). + +Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + The ALT_BN128 pairing check precompiled contract. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 34000, + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 192 + |) + |), + Constant.int 45000 + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 192 + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 192 + |) + ], + make_dict [] + |) do + let values := + make_list [] in + For M.get_name (| globals, "j" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 6 + ], + make_dict [] + |) do + let value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "data" |), BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + M.get_name (| globals, "j" |) + |) + |):BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "j" |), + Constant.int 1 + |) + |) + |) |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "value" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "values" |), "append" |), + make_list [ + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + EndFor. +(* At stmt: unsupported node type: Try *) + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.call (| + M.get_field (| M.get_name (| globals, "p" |), "mul_by" |), + make_list [ + M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) + ], + make_dict [] + |), M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) |); + M.get_name (| globals, "OutOfGasError" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.call (| + M.get_field (| M.get_name (| globals, "q" |), "mul_by" |), + make_list [ + M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) + ], + make_dict [] + |), M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) |); + M.get_name (| globals, "OutOfGasError" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "p" |), M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_name (| globals, "q" |), M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let result := + BinOp.mult (| + M.get_name (| globals, "result" |), + M.call (| + M.get_name (| globals, "pairing" |), + make_list [ + M.get_name (| globals, "q" |); + M.get_name (| globals, "p" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "result" |), M.call (| + M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/blake2f.v b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/blake2f.v new file mode 100644 index 0000000..5903066 --- /dev/null +++ b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/blake2f.v @@ -0,0 +1,122 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Blake2 PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `Blake2` precompiled contract. +". + +Require ethereum.crypto.blake2. +Axiom ethereum_crypto_blake2_Blake2b : + IsGlobalAlias globals ethereum.crypto.blake2.globals "Blake2b". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_BLAKE2_PER_ROUND : + IsGlobalAlias globals vm.gas.globals "GAS_BLAKE2_PER_ROUND". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require exceptions. +Axiom exceptions_InvalidParameter : + IsGlobalAlias globals exceptions.globals "InvalidParameter". + +Definition blake2f : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the Blake2 hash to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), Constant.int 213 |); + M.get_name (| globals, "InvalidParameter" |) + ], + make_dict [] + |) in + let blake2b := + M.call (| + M.get_name (| globals, "Blake2b" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "rounds" |); M.get_name (| globals, "h" |); M.get_name (| globals, "m" |); M.get_name (| globals, "t_0" |); M.get_name (| globals, "t_1" |); M.get_name (| globals, "f" |) ], + M.call (| + M.get_field (| M.get_name (| globals, "blake2b" |), "get_blake2_parameters" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.mult (| + M.get_name (| globals, "GAS_BLAKE2_PER_ROUND" |), + M.get_name (| globals, "rounds" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.in (| M.get_name (| globals, "f" |), make_list [ + Constant.int 0; + Constant.int 1 + ] |); + M.get_name (| globals, "InvalidParameter" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.get_name (| globals, "blake2b" |), "compress" |), + make_list [ + M.get_name (| globals, "rounds" |); + M.get_name (| globals, "h" |); + M.get_name (| globals, "m" |); + M.get_name (| globals, "t_0" |); + M.get_name (| globals, "t_1" |); + M.get_name (| globals, "f" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/ecrecover.v new file mode 100644 index 0000000..cc351b5 --- /dev/null +++ b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/ecrecover.v @@ -0,0 +1,269 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) ECRECOVER PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the ECRECOVER precompiled contract. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require ethereum.crypto.elliptic_curve. +Axiom ethereum_crypto_elliptic_curve_SECP256K1N : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_left_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_ECRECOVER : + IsGlobalAlias globals vm.gas.globals "GAS_ECRECOVER". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require vm.memory. +Axiom vm_memory_buffer_read : + IsGlobalAlias globals vm.memory.globals "buffer_read". + +Definition ecrecover : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Decrypts the address using elliptic curve DSA recovery mechanism and writes + the address to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_ECRECOVER" |) + ], + make_dict [] + |) in + let message_hash_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let message_hash := + M.call (| + M.get_name (| globals, "Hash32" |), + make_list [ + M.get_name (| globals, "message_hash_bytes" |) + ], + make_dict [] + |) in + let v := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let r := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let s := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 27 |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 28 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| Constant.int 0, M.get_name (| globals, "r" |) |), + ltac:(M.monadic ( + Compare.gt_e (| M.get_name (| globals, "r" |), M.get_name (| globals, "SECP256K1N" |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| Constant.int 0, M.get_name (| globals, "s" |) |), + ltac:(M.monadic ( + Compare.gt_e (| M.get_name (| globals, "s" |), M.get_name (| globals, "SECP256K1N" |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in +(* At stmt: unsupported node type: Try *) + let address := + M.get_subscript (| M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), Constant.int 12:Constant.int 32 |) in + let padded_address := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "address" |); + Constant.int 32 + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.get_name (| globals, "padded_address" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/identity.v new file mode 100644 index 0000000..fa96704 --- /dev/null +++ b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/identity.v @@ -0,0 +1,94 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) IDENTITY PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `IDENTITY` precompiled contract. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_IDENTITY : + IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY". +Axiom vm_gas_GAS_IDENTITY_WORD : + IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY_WORD". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition identity : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the message data to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let word_count := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_IDENTITY" |), + BinOp.mult (| + M.get_name (| globals, "GAS_IDENTITY_WORD" |), + M.get_name (| globals, "word_count" |) + |) + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.get_name (| globals, "data" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/mapping.v new file mode 100644 index 0000000..8a2e2eb --- /dev/null +++ b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/mapping.v @@ -0,0 +1,82 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Precompiled Contract Addresses +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Mapping of precompiled contracts their implementations. +". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require __init__. +Axiom __init___ALT_BN128_ADD_ADDRESS : + IsGlobalAlias globals __init__.globals "ALT_BN128_ADD_ADDRESS". +Axiom __init___ALT_BN128_MUL_ADDRESS : + IsGlobalAlias globals __init__.globals "ALT_BN128_MUL_ADDRESS". +Axiom __init___ALT_BN128_PAIRING_CHECK_ADDRESS : + IsGlobalAlias globals __init__.globals "ALT_BN128_PAIRING_CHECK_ADDRESS". +Axiom __init___BLAKE2F_ADDRESS : + IsGlobalAlias globals __init__.globals "BLAKE2F_ADDRESS". +Axiom __init___ECRECOVER_ADDRESS : + IsGlobalAlias globals __init__.globals "ECRECOVER_ADDRESS". +Axiom __init___IDENTITY_ADDRESS : + IsGlobalAlias globals __init__.globals "IDENTITY_ADDRESS". +Axiom __init___MODEXP_ADDRESS : + IsGlobalAlias globals __init__.globals "MODEXP_ADDRESS". +Axiom __init___RIPEMD160_ADDRESS : + IsGlobalAlias globals __init__.globals "RIPEMD160_ADDRESS". +Axiom __init___SHA256_ADDRESS : + IsGlobalAlias globals __init__.globals "SHA256_ADDRESS". + +Require alt_bn128. +Axiom alt_bn128_alt_bn128_add : + IsGlobalAlias globals alt_bn128.globals "alt_bn128_add". +Axiom alt_bn128_alt_bn128_mul : + IsGlobalAlias globals alt_bn128.globals "alt_bn128_mul". +Axiom alt_bn128_alt_bn128_pairing_check : + IsGlobalAlias globals alt_bn128.globals "alt_bn128_pairing_check". + +Require blake2f. +Axiom blake2f_blake2f : + IsGlobalAlias globals blake2f.globals "blake2f". + +Require ecrecover. +Axiom ecrecover_ecrecover : + IsGlobalAlias globals ecrecover.globals "ecrecover". + +Require identity. +Axiom identity_identity : + IsGlobalAlias globals identity.globals "identity". + +Require modexp. +Axiom modexp_modexp : + IsGlobalAlias globals modexp.globals "modexp". + +Require ripemd160. +Axiom ripemd160_ripemd160 : + IsGlobalAlias globals ripemd160.globals "ripemd160". + +Require sha256. +Axiom sha256_sha256 : + IsGlobalAlias globals sha256.globals "sha256". + +(* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/modexp.v new file mode 100644 index 0000000..544949e --- /dev/null +++ b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/modexp.v @@ -0,0 +1,608 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) MODEXP PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `MODEXP` precompiled contract. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require memory. +Axiom memory_buffer_read : + IsGlobalAlias globals memory.globals "buffer_read". + +Definition GQUADDIVISOR : Value.t := M.run ltac:(M.monadic ( + Constant.int 3 +)). + +Definition modexp : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Calculates `(base**exp) % modulus` for arbitrary sized `base`, `exp` and. + `modulus`. The return value is the same length as the modulus. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let base_length := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exp_length := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let modulus_length := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exp_start := + BinOp.add (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |), + M.get_name (| globals, "base_length" |) + |) in + let exp_head := + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.get_name (| globals, "exp_start" |); + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.get_name (| globals, "exp_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "gas_cost" |), + make_list [ + M.get_name (| globals, "base_length" |); + M.get_name (| globals, "modulus_length" |); + M.get_name (| globals, "exp_length" |); + M.get_name (| globals, "exp_head" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_name (| globals, "base_length" |), Constant.int 0 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "modulus_length" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [], + make_dict [] + |) + |) in + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let base := + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |); + M.get_name (| globals, "base_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exp := + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.get_name (| globals, "exp_start" |); + M.get_name (| globals, "exp_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let modulus_start := + BinOp.add (| + M.get_name (| globals, "exp_start" |), + M.get_name (| globals, "exp_length" |) + |) in + let modulus := + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.get_name (| globals, "modulus_start" |); + M.get_name (| globals, "modulus_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "modulus" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + BinOp.mult (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |), + M.get_name (| globals, "modulus_length" |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pow" |), + make_list [ + M.get_name (| globals, "base" |); + M.get_name (| globals, "exp" |); + M.get_name (| globals, "modulus" |) + ], + make_dict [] + |) + ], + make_dict [] + |), "to_bytes" |), + make_list [ + M.get_name (| globals, "modulus_length" |); + Constant.str "big" + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition complexity : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "base_length"; "modulus_length" ] |) in + let _ := Constant.str " + Estimate the complexity of performing a modular exponentiation. + + Parameters + ---------- + + base_length : + Length of the array representing the base integer. + + modulus_length : + Length of the array representing the modulus integer. + + Returns + ------- + + complexity : `Uint` + Complexity of performing the operation. + " in + let max_length := + M.call (| + M.get_name (| globals, "max" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "base_length" |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "modulus_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + BinOp.add (| + M.get_name (| globals, "max_length" |), + Constant.int 7 + |), + Constant.int 8 + |) in + let _ := M.return_ (| + BinOp.pow (| + M.get_name (| globals, "words" |), + Constant.int 2 + |) + |) in + M.pure Constant.None_)). + +Definition iterations : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "exponent_length"; "exponent_head" ] |) in + let _ := Constant.str " + Calculate the number of iterations required to perform a modular + exponentiation. + + Parameters + ---------- + + exponent_length : + Length of the array representing the exponent integer. + + exponent_head : + First 32 bytes of the exponent (with leading zero padding if it is + shorter than 32 bytes), as an unsigned integer. + + Returns + ------- + + iterations : `Uint` + Number of iterations. + " in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.lt_e (| M.get_name (| globals, "exponent_length" |), Constant.int 32 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "exponent_head" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let count := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| M.get_name (| globals, "exponent_length" |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let bit_length := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "exponent_head" |), "bit_length" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "bit_length" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let bit_length := BinOp.sub + Constant.int 1 + Constant.int 1 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let count := + M.get_name (| globals, "bit_length" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let length_part := + BinOp.mult (| + Constant.int 8, + BinOp.sub (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "exponent_length" |) + ], + make_dict [] + |), + Constant.int 32 + |) + |) in + let bits_part := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "exponent_head" |), "bit_length" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "bits_part" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let bits_part := BinOp.sub + Constant.int 1 + Constant.int 1 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let count := + BinOp.add (| + M.get_name (| globals, "length_part" |), + M.get_name (| globals, "bits_part" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "max" |), + make_list [ + M.get_name (| globals, "count" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition gas_cost : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "base_length"; "modulus_length"; "exponent_length"; "exponent_head" ] |) in + let _ := Constant.str " + Calculate the gas cost of performing a modular exponentiation. + + Parameters + ---------- + + base_length : + Length of the array representing the base integer. + + modulus_length : + Length of the array representing the modulus integer. + + exponent_length : + Length of the array representing the exponent integer. + + exponent_head : + First 32 bytes of the exponent (with leading zero padding if it is + shorter than 32 bytes), as an unsigned integer. + + Returns + ------- + + gas_cost : `Uint` + Gas required for performing the operation. + " in + let multiplication_complexity := + M.call (| + M.get_name (| globals, "complexity" |), + make_list [ + M.get_name (| globals, "base_length" |); + M.get_name (| globals, "modulus_length" |) + ], + make_dict [] + |) in + let iteration_count := + M.call (| + M.get_name (| globals, "iterations" |), + make_list [ + M.get_name (| globals, "exponent_length" |); + M.get_name (| globals, "exponent_head" |) + ], + make_dict [] + |) in + let cost := + BinOp.mult (| + M.get_name (| globals, "multiplication_complexity" |), + M.get_name (| globals, "iteration_count" |) + |) in + let cost := BinOp.floor_div + M.get_name (| globals, "GQUADDIVISOR" |) + M.get_name (| globals, "GQUADDIVISOR" |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "max" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 200 + ], + make_dict [] + |); + M.get_name (| globals, "cost" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/ripemd160.v new file mode 100644 index 0000000..96f8dcd --- /dev/null +++ b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/ripemd160.v @@ -0,0 +1,122 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) RIPEMD160 PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `RIPEMD160` precompiled contract. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_left_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_RIPEMD160 : + IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160". +Axiom vm_gas_GAS_RIPEMD160_WORD : + IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160_WORD". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition ripemd160 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the ripemd160 hash to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let word_count := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_RIPEMD160" |), + BinOp.mult (| + M.get_name (| globals, "GAS_RIPEMD160_WORD" |), + M.get_name (| globals, "word_count" |) + |) + |) + ], + make_dict [] + |) in + let hash_bytes := + M.call (| + M.get_field (| M.call (| + M.get_field (| M.get_name (| globals, "hashlib" |), "new" |), + make_list [ + Constant.str "ripemd160"; + M.get_name (| globals, "data" |) + ], + make_dict [] + |), "digest" |), + make_list [], + make_dict [] + |) in + let padded_hash := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "hash_bytes" |); + Constant.int 32 + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.get_name (| globals, "padded_hash" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/sha256.v new file mode 100644 index 0000000..9f6d2bf --- /dev/null +++ b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/sha256.v @@ -0,0 +1,106 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) SHA256 PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `SHA256` precompiled contract. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_SHA256 : + IsGlobalAlias globals vm.gas.globals "GAS_SHA256". +Axiom vm_gas_GAS_SHA256_WORD : + IsGlobalAlias globals vm.gas.globals "GAS_SHA256_WORD". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition sha256 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the sha256 hash to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let word_count := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_SHA256" |), + BinOp.mult (| + M.get_name (| globals, "GAS_SHA256_WORD" |), + M.get_name (| globals, "word_count" |) + |) + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_field (| M.get_name (| globals, "hashlib" |), "sha256" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), "digest" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/vm/runtime.v b/CoqOfPython/ethereum/berlin/vm/runtime.v new file mode 100644 index 0000000..835b46c --- /dev/null +++ b/CoqOfPython/ethereum/berlin/vm/runtime.v @@ -0,0 +1,125 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Runtime Operations +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Runtime related operations used while executing EVM code. +". + +Require typing. +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require instructions. +Axiom instructions_Ops : + IsGlobalAlias globals instructions.globals "Ops". + +Definition get_valid_jump_destinations : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "code" ] |) in + let _ := Constant.str " + Analyze the evm code to obtain the set of valid jump destinations. + + Valid jump destinations are defined as follows: + * The jump destination is less than the length of the code. + * The jump destination should have the `JUMPDEST` opcode (0x5B). + * The jump destination shouldn't be part of the data corresponding to + `PUSH-N` opcodes. + + Note - Jump destinations are 0-indexed. + + Parameters + ---------- + code : + The EVM code which is to be executed. + + Returns + ------- + valid_jump_destinations: `Set[Uint]` + The set of valid jump destinations in the code. + " in + let valid_jump_destinations := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let pc := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + While Compare.lt (| M.get_name (| globals, "pc" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) |) do +(* At stmt: unsupported node type: Try *) + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "current_opcode" |), M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), + make_list [ + M.get_name (| globals, "pc" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + (* At expr: unsupported node type: Compare *), + (* then *) + ltac:(M.monadic ( + let push_data_size := + BinOp.add (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) + |), + Constant.int 1 + |) in + let pc := BinOp.add + M.get_name (| globals, "push_data_size" |) + M.get_name (| globals, "push_data_size" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let pc := BinOp.add + Constant.int 1 + Constant.int 1 in + EndWhile. + let _ := M.return_ (| + M.get_name (| globals, "valid_jump_destinations" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/vm/stack.v b/CoqOfPython/ethereum/berlin/vm/stack.v new file mode 100644 index 0000000..42ea42d --- /dev/null +++ b/CoqOfPython/ethereum/berlin/vm/stack.v @@ -0,0 +1,120 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Stack +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the stack operators for the EVM. +". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require exceptions. +Axiom exceptions_StackOverflowError : + IsGlobalAlias globals exceptions.globals "StackOverflowError". +Axiom exceptions_StackUnderflowError : + IsGlobalAlias globals exceptions.globals "StackUnderflowError". + +Definition pop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "stack" ] |) in + let _ := Constant.str " + Pops the top item off of `stack`. + + Parameters + ---------- + stack : + EVM stack. + + Returns + ------- + value : `U256` + The top element on the stack. + + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "StackUnderflowError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "pop" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition push : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "stack"; "value" ] |) in + let _ := Constant.str " + Pushes `value` onto `stack`. + + Parameters + ---------- + stack : + EVM stack. + + value : + Item to be pushed onto `stack`. + + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), Constant.int 1024 |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "StackOverflowError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "append" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/__init__.v b/CoqOfPython/ethereum/byzantium/__init__.v new file mode 100644 index 0000000..ee39b1c --- /dev/null +++ b/CoqOfPython/ethereum/byzantium/__init__.v @@ -0,0 +1,24 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +The Byzantium fork reduces the mining rewards, delays the difficulty bomb, +lets contracts make non-state-changing calls to other contracts, and adds +cryptographic primitives for layer 2 scaling. +". + +Require ethereum.fork_criteria. +Axiom ethereum_fork_criteria_ByBlockNumber : + IsGlobalAlias globals ethereum.fork_criteria.globals "ByBlockNumber". + +Definition FORK_CRITERIA : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "ByBlockNumber" |), + make_list [ + Constant.int 4370000 + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/byzantium/blocks.v b/CoqOfPython/ethereum/byzantium/blocks.v new file mode 100644 index 0000000..6501788 --- /dev/null +++ b/CoqOfPython/ethereum/byzantium/blocks.v @@ -0,0 +1,93 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +A `Block` is a single link in the chain that is Ethereum. Each `Block` contains +a `Header` and zero or more transactions. Each `Header` contains associated +metadata like the block number, parent block hash, and how much gas was +consumed by its transactions. + +Together, these blocks form a cryptographically secure journal recording the +history of all state transitions that have happened since the genesis of the +chain. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes8 : + IsGlobalAlias globals base_types.globals "Bytes8". +Axiom base_types_Bytes32 : + IsGlobalAlias globals base_types.globals "Bytes32". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require crypto.hash. +Axiom crypto_hash_Hash32 : + IsGlobalAlias globals crypto.hash.globals "Hash32". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Require transactions. +Axiom transactions_Transaction : + IsGlobalAlias globals transactions.globals "Transaction". + +Definition Header : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Block : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Log : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Receipt : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. diff --git a/CoqOfPython/ethereum/byzantium/bloom.v b/CoqOfPython/ethereum/byzantium/bloom.v new file mode 100644 index 0000000..04b5d9f --- /dev/null +++ b/CoqOfPython/ethereum/byzantium/bloom.v @@ -0,0 +1,164 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Logs Bloom +^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +This modules defines functions for calculating bloom filters of logs. For the +general theory of bloom filters see e.g. `Wikipedia +`_. Bloom filters are used to allow +for efficient searching of logs by address and/or topic, by rapidly +eliminating blocks and receipts from their search. +". + +Require typing. +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require fork_types. +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". + +Definition add_to_bloom : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "bloom"; "bloom_entry" ] |) in + let _ := Constant.str " + Add a bloom entry to the bloom filter (`bloom`). + + The number of hash functions used is 3. They are calculated by taking the + least significant 11 bits from the first 3 16-bit words of the + `keccak_256()` hash of `bloom_entry`. + + Parameters + ---------- + bloom : + The bloom filter. + bloom_entry : + An entry which is to be added to bloom filter. + " in + let hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "bloom_entry" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "idx" |) in make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ] do + let bit_to_set := + BinOp.bit_and (| + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |):BinOp.add (| + M.get_name (| globals, "idx" |), + Constant.int 2 + |) |) + ], + make_dict [] + |), + Constant.int 2047 + |) in + let bit_index := + BinOp.sub (| + Constant.int 2047, + M.get_name (| globals, "bit_to_set" |) + |) in + let byte_index := + BinOp.floor_div (| + M.get_name (| globals, "bit_index" |), + Constant.int 8 + |) in + let bit_value := + BinOp.l_shift (| + Constant.int 1, + BinOp.sub (| + Constant.int 7, + BinOp.mod_ (| + M.get_name (| globals, "bit_index" |), + Constant.int 8 + |) + |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), + BinOp.bit_or (| + M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), + M.get_name (| globals, "bit_value" |) + |) + |) in + EndFor. + M.pure Constant.None_)). + +Definition logs_bloom : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "logs" ] |) in + let _ := Constant.str " + Obtain the logs bloom from a list of log entries. + + The address and each topic of a log are added to the bloom filter. + + Parameters + ---------- + logs : + List of logs for which the logs bloom is to be obtained. + + Returns + ------- + logs_bloom : `Bloom` + The logs bloom obtained which is 256 bytes with some bits set as per + the caller address and the log topics. + " in +(* At stmt: unsupported node type: AnnAssign *) + For M.get_name (| globals, "log" |) in M.get_name (| globals, "logs" |) do + let _ := M.call (| + M.get_name (| globals, "add_to_bloom" |), + make_list [ + M.get_name (| globals, "bloom" |); + M.get_field (| M.get_name (| globals, "log" |), "address" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "topic" |) in M.get_field (| M.get_name (| globals, "log" |), "topics" |) do + let _ := M.call (| + M.get_name (| globals, "add_to_bloom" |), + make_list [ + M.get_name (| globals, "bloom" |); + M.get_name (| globals, "topic" |) + ], + make_dict [] + |) in + EndFor. + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bloom" |), + make_list [ + M.get_name (| globals, "bloom" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/fork_types.v b/CoqOfPython/ethereum/byzantium/fork_types.v new file mode 100644 index 0000000..d12953d --- /dev/null +++ b/CoqOfPython/ethereum/byzantium/fork_types.v @@ -0,0 +1,102 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Types +^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Types re-used throughout the specification, which are specific to Ethereum. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes20 : + IsGlobalAlias globals base_types.globals "Bytes20". +Axiom base_types_Bytes256 : + IsGlobalAlias globals base_types.globals "Bytes256". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require crypto.hash. +Axiom crypto_hash_Hash32 : + IsGlobalAlias globals crypto.hash.globals "Hash32". +Axiom crypto_hash_keccak256 : + IsGlobalAlias globals crypto.hash.globals "keccak256". + +Definition Address : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Bytes20" |) +)). + +Definition Root : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Hash32" |) +)). + +Definition Bloom : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Bytes256" |) +)). + +Definition Account : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition EMPTY_ACCOUNT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Account" |), + make_list [], + make_dict [] + |) +)). + +Definition encode_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "raw_account_data"; "storage_root" ] |) in + let _ := Constant.str " + Encode `Account` dataclass. + + Storage is not stored in the `Account` dataclass, so `Accounts` cannot be + encoded with providing a storage root. + " in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "raw_account_data" |), "nonce" |); M.get_field (| M.get_name (| globals, "raw_account_data" |), "balance" |); M.get_name (| globals, "storage_root" |); M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_field (| M.get_name (| globals, "raw_account_data" |), "code" |) + ], + make_dict [] + |) ] + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/state.v b/CoqOfPython/ethereum/byzantium/state.v new file mode 100644 index 0000000..53b3837 --- /dev/null +++ b/CoqOfPython/ethereum/byzantium/state.v @@ -0,0 +1,1031 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +State +^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The state contains all information that is preserved between transactions. + +It consists of a main account trie and storage tries for each contract. + +There is a distinction between an account that does not exist and +`EMPTY_ACCOUNT`. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_field : + IsGlobalAlias globals dataclasses.globals "field". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_modify : + IsGlobalAlias globals ethereum.base_types.globals "modify". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require fork_types. +Axiom fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". +Axiom fork_types_Account : + IsGlobalAlias globals fork_types.globals "Account". +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Require trie. +Axiom trie_EMPTY_TRIE_ROOT : + IsGlobalAlias globals trie.globals "EMPTY_TRIE_ROOT". +Axiom trie_Trie : + IsGlobalAlias globals trie.globals "Trie". +Axiom trie_copy_trie : + IsGlobalAlias globals trie.globals "copy_trie". +Axiom trie_root : + IsGlobalAlias globals trie.globals "root". +Axiom trie_trie_get : + IsGlobalAlias globals trie.globals "trie_get". +Axiom trie_trie_set : + IsGlobalAlias globals trie.globals "trie_set". + +Definition State : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition close_state : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Free resources held by the state. Used by optimized implementations to + release file descriptors. + " in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) |) in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |) in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) in + M.pure Constant.None_)). + +Definition begin_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Start a state transaction. + + Transactions are entirely implicit and can be nested. It is not possible to + calculate the state root during a transaction. + + Parameters + ---------- + state : State + The state. + " in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), "append" |), + make_list [ + make_tuple [ M.call (| + M.get_name (| globals, "copy_trie" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) + ], + make_dict [] + |); {M.get_name (| globals, "k" |): M.call (| + M.get_name (| globals, "copy_trie" |), + make_list [ + M.get_name (| globals, "t" |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)} ] + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition commit_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Commit a state transaction. + + Parameters + ---------- + state : State + The state. + " in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), "pop" |), + make_list [], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition rollback_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Rollback a state transaction, resetting the state to the point when the + corresponding `start_transaction()` call was made. + + Parameters + ---------- + state : State + The state. + " in + let _ := M.assign (| + make_tuple [ M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) ], + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), "pop" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition get_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Get the `Account` object at an address. Returns `EMPTY_ACCOUNT` if there + is no account at the address. + + Use `get_account_optional()` if you care about the difference between a + non-existent account and `EMPTY_ACCOUNT`. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address to lookup. + + Returns + ------- + account : `Account` + Account at address. + " in + let account := + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "account" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "account" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "EMPTY_ACCOUNT" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition get_account_optional : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Get the `Account` object at an address. Returns `None` (rather than + `EMPTY_ACCOUNT`) if there is no account at the address. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address to lookup. + + Returns + ------- + account : `Account` + Account at address. + " in + let account := + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "account" |) + |) in + M.pure Constant.None_)). + +Definition set_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "account" ] |) in + let _ := Constant.str " + Set the `Account` object at an address. Setting to `None` deletes + the account (but not its storage, see `destroy_account()`). + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address to set. + account : `Account` + Account to set at address. + " in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "account" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition destroy_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Completely remove the account at `address` and all of its storage. + + This function is made available exclusively for the `SELFDESTRUCT` + opcode. It is expected that `SELFDESTRUCT` will be disabled in a future + hardfork and this function will be removed. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of account to destroy. + " in + let _ := M.call (| + M.get_name (| globals, "destroy_storage" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + Constant.None_ + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition destroy_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Completely remove the storage at `address`. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of account whose storage is to be deleted. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition get_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "key" ] |) in + let _ := Constant.str " + Get a value at a storage key on an account. Returns `U256(0)` if the + storage key has not been set previously. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of the account. + key : `Bytes` + Key to lookup. + + Returns + ------- + value : `U256` + Value at the key. + " in + let trie := + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let _ := M.assert (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "U256" |) + ], + make_dict [] + |) |) in + let _ := M.return_ (| + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_)). + +Definition set_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "key"; "value" ] |) in + let _ := Constant.str " + Set a value at a storage key on an account. Setting to `U256(0)` deletes + the key. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of the account. + key : `Bytes` + Key to set. + value : `U256` + Value to set at the key. + " in + let _ := M.assert (| Compare.is_not (| M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), Constant.None_ |) |) in + let trie := + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let trie := + M.call (| + M.get_name (| globals, "Trie" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), + M.get_name (| globals, "trie" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "key" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), {} |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition storage_root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Calculate the storage root of an account. + + Parameters + ---------- + state: + The state + address : + Address of the account. + + Returns + ------- + root : `Root` + Storage root of the account. + " in + let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "EMPTY_TRIE_ROOT" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition state_root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Calculate the state root. + + Parameters + ---------- + state: + The current state. + + Returns + ------- + root : `Root` + The state root. + " in + let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition account_exists : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account exists in the state trie + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + account_exists : `bool` + True if account exists in the state trie, False otherwise + " in + let _ := M.return_ (| + Compare.is_not (| M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), Constant.None_ |) + |) in + M.pure Constant.None_)). + +Definition account_has_code_or_nonce : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account has non zero nonce or non empty code + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + has_code_or_nonce : `bool` + True if if an account has non zero nonce or non empty code, + False otherwise. + " in + let account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + BoolOp.or (| + Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |) + )) + |) + |) in + M.pure Constant.None_)). + +Definition is_account_empty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account has zero nonce, empty code and zero balance. + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + is_empty : `bool` + True if if an account has zero nonce, empty code and zero balance, + False otherwise. + " in + let account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + ltac:(M.monadic ( + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + )) + |) + )) + |) + |) in + M.pure Constant.None_)). + +Definition account_exists_and_is_empty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account exists and has zero nonce, empty code and zero + balance. + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + exists_and_is_empty : `bool` + True if an account exists and has zero nonce, empty code and zero + balance, False otherwise. + " in + let account := + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + BoolOp.and (| + Compare.is_not (| M.get_name (| globals, "account" |), Constant.None_ |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + ltac:(M.monadic ( + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + )) + |) + )) + |) + )) + |) + |) in + M.pure Constant.None_)). + +Definition is_account_alive : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Check whether is an account is both in the state and non empty. + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + is_alive : `bool` + True if the account is alive. + " in + let account := + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "account" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + UnOp.not (| BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + ltac:(M.monadic ( + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + )) + |) + )) + |) |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition modify_state : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "f" ] |) in + let _ := Constant.str " + Modify an `Account` in the `State`. + " in + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.call (| + M.get_name (| globals, "modify" |), + make_list [ + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |); + M.get_name (| globals, "f" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition move_ether : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "sender_address"; "recipient_address"; "amount" ] |) in + let _ := Constant.str " + Move funds between accounts. + " in +(* At stmt: unsupported node type: FunctionDef *) +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "sender_address" |); + M.get_name (| globals, "reduce_sender_balance" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "recipient_address" |); + M.get_name (| globals, "increase_recipient_balance" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition set_account_balance : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "amount" ] |) in + let _ := Constant.str " + Sets the balance of an account. + + Parameters + ---------- + state: + The current state. + + address: + Address of the account whose nonce needs to be incremented. + + amount: + The amount that needs to set in balance. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "set_balance" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition touch_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Initializes an account to state. + + Parameters + ---------- + state: + The current state. + + address: + The address of the account that need to initialised. + " in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "account_exists" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "EMPTY_ACCOUNT" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition increment_nonce : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Increments the nonce of an account. + + Parameters + ---------- + state: + The current state. + + address: + Address of the account whose nonce needs to be incremented. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "increase_nonce" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition set_code : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "code" ] |) in + let _ := Constant.str " + Sets Account code. + + Parameters + ---------- + state: + The current state. + + address: + Address of the account whose code needs to be update. + + code: + The bytecode that needs to be set. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "write_code" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition create_ether : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "amount" ] |) in + let _ := Constant.str " + Add newly created ether to an account. + + Parameters + ---------- + state: + The current state. + address: + Address of the account to which ether is added. + amount: + The amount of ether to be added to the account of interest. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "increase_balance" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/transactions.v b/CoqOfPython/ethereum/byzantium/transactions.v new file mode 100644 index 0000000..6d1bc6b --- /dev/null +++ b/CoqOfPython/ethereum/byzantium/transactions.v @@ -0,0 +1,60 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Transactions are atomic units of work created externally to Ethereum and +submitted to be executed. If Ethereum is viewed as a state machine, +transactions are the events that move between states. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes0 : + IsGlobalAlias globals base_types.globals "Bytes0". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( + Constant.int 21000 +)). + +Definition TX_DATA_COST_PER_NON_ZERO : Value.t := M.run ltac:(M.monadic ( + Constant.int 68 +)). + +Definition TX_DATA_COST_PER_ZERO : Value.t := M.run ltac:(M.monadic ( + Constant.int 4 +)). + +Definition TX_CREATE_COST : Value.t := M.run ltac:(M.monadic ( + Constant.int 32000 +)). + +Definition Transaction : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. diff --git a/CoqOfPython/ethereum/byzantium/trie.v b/CoqOfPython/ethereum/byzantium/trie.v new file mode 100644 index 0000000..6fbb787 --- /dev/null +++ b/CoqOfPython/ethereum/byzantium/trie.v @@ -0,0 +1,1357 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +State Trie +^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The state trie is the structure responsible for storing +`.fork_types.Account` objects. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_field : + IsGlobalAlias globals dataclasses.globals "field". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". +Axiom typing_Generic : + IsGlobalAlias globals typing.globals "Generic". +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Mapping : + IsGlobalAlias globals typing.globals "Mapping". +Axiom typing_MutableMapping : + IsGlobalAlias globals typing.globals "MutableMapping". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Sequence : + IsGlobalAlias globals typing.globals "Sequence". +Axiom typing_TypeVar : + IsGlobalAlias globals typing.globals "TypeVar". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". +Axiom typing_cast : + IsGlobalAlias globals typing.globals "cast". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.spurious_dragon. +Axiom ethereum_spurious_dragon_trie : + IsGlobalAlias globals ethereum.spurious_dragon.globals "trie". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require ethereum.utils.hexadecimal. +Axiom ethereum_utils_hexadecimal_hex_to_bytes : + IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require blocks. +Axiom blocks_Receipt : + IsGlobalAlias globals blocks.globals "Receipt". + +Require fork_types. +Axiom fork_types_Account : + IsGlobalAlias globals fork_types.globals "Account". +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". +Axiom fork_types_encode_account : + IsGlobalAlias globals fork_types.globals "encode_account". + +Require transactions. +Axiom transactions_Transaction : + IsGlobalAlias globals transactions.globals "Transaction". + +Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Root" |), + make_list [ + M.call (| + M.get_name (| globals, "hex_to_bytes" |), + make_list [ + Constant.str "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" + ], + make_dict [] + |) + ], + make_dict [] + |) +)). + +Definition Node : Value.t := M.run ltac:(M.monadic ( + M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Bytes" |); M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |); Constant.None_ ] |) +)). + +Definition K : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "TypeVar" |), + make_list [ + Constant.str "K" + ], + make_dict [] + |) +)). + +Definition V : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "TypeVar" |), + make_list [ + Constant.str "V"; + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Account" |) |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Bytes" |) |); + M.get_name (| globals, "Bytes" |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Transaction" |) |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Receipt" |) |); + M.get_name (| globals, "Uint" |); + M.get_name (| globals, "U256" |) + ], + make_dict [] + |) +)). + +Definition LeafNode : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition ExtensionNode : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition BranchNode : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition InternalNode : Value.t := M.run ltac:(M.monadic ( + M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LeafNode" |); M.get_name (| globals, "ExtensionNode" |); M.get_name (| globals, "BranchNode" |) ] |) +)). + +Definition encode_internal_node : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "node" ] |) in + let _ := Constant.str " + Encodes a Merkle Trie node into its RLP form. The RLP will then be + serialized into a `Bytes` and hashed unless it is less that 32 bytes + when serialized. + + This function also accepts `None`, representing the absence of a node, + which is encoded to `b""""""`. + + Parameters + ---------- + node : Optional[InternalNode] + The node to encode. + + Returns + ------- + encoded : `rlp.RLP` + The node encoded as RLP. + " in +(* At stmt: unsupported node type: AnnAssign *) + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "node" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let unencoded := + (* At constant: unsupported node type: Constant *) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "LeafNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "rest_of_key" |); + Constant.bool true + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "ExtensionNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "key_segment" |); + Constant.bool false + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "BranchNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + BinOp.add (| + M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "value" |) + ] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "AssertionError" |), + make_list [ + (* At expr: unsupported node type: JoinedStr *) + ], + make_dict [] + |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let encoded := + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "unencoded" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded" |) + ], + make_dict [] + |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "unencoded" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "encoded" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition encode_node : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "node"; "storage_root" ] |) in + let _ := Constant.str " + Encode a Node for storage in the Merkle Trie. + + Currently mostly an unimplemented stub. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "storage_root" |), Constant.None_ |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "encode_account" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "storage_root" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + make_tuple [ M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "U256" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "cast" |), + make_list [ + M.get_field (| M.get_name (| globals, "rlp" |), "RLP" |); + M.get_name (| globals, "node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "node" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "previous_trie" |), "encode_node" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "storage_root" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition Trie : Value.t := + builtins.make_klass + [(* At base: unsupported node type: Subscript *)] + [ + + ] + [ + + ]. + +Definition copy_trie : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie" ] |) in + let _ := Constant.str " + Create a copy of `trie`. Since only frozen objects may be stored in tries, + the contents are reused. + + Parameters + ---------- + trie: `Trie` + Trie to copy. + + Returns + ------- + new_trie : `Trie[K, V]` + A copy of the trie. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Trie" |), + make_list [ + M.get_field (| M.get_name (| globals, "trie" |), "secured" |); + M.get_field (| M.get_name (| globals, "trie" |), "default" |); + M.call (| + M.get_field (| M.get_name (| globals, "copy" |), "copy" |), + make_list [ + M.get_field (| M.get_name (| globals, "trie" |), "_data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition trie_set : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "key"; "value" ] |) in + let _ := Constant.str " + Stores an item in a Merkle Trie. + + This method deletes the key if `value == trie.default`, because the Merkle + Trie represents the default value by omitting it from the trie. + + Parameters + ---------- + trie: `Trie` + Trie to store in. + key : `Bytes` + Key to lookup. + value : `V` + Node to insert at `key`. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "value" |), M.get_field (| M.get_name (| globals, "trie" |), "default" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "key" |), M.get_field (| M.get_name (| globals, "trie" |), "_data" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition trie_get : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "key" ] |) in + let _ := Constant.str " + Gets an item from the Merkle Trie. + + This method returns `trie.default` if the key is missing. + + Parameters + ---------- + trie: + Trie to lookup in. + key : + Key to lookup. + + Returns + ------- + node : `V` + Node at `key` in the trie. + " in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "get" |), + make_list [ + M.get_name (| globals, "key" |); + M.get_field (| M.get_name (| globals, "trie" |), "default" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition common_prefix_length : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "a"; "b" ] |) in + let _ := Constant.str " + Find the longest common prefix of two sequences. + " in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + ], + make_dict [] + |) do + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| M.get_name (| globals, "i" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition nibble_list_to_compact : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "x"; "is_leaf" ] |) in + let _ := Constant.str " + Compresses nibble-list into a standard byte array with a flag. + + A nibble-list is a list of byte values no greater than `15`. The flag is + encoded in high nibble of the highest byte. The flag nibble can be broken + down into two two-bit flags. + + Highest nibble:: + + +---+---+----------+--------+ + | _ | _ | is_leaf | parity | + +---+---+----------+--------+ + 3 2 1 0 + + + The lowest bit of the nibble encodes the parity of the length of the + remaining nibbles -- `0` when even and `1` when odd. The second lowest bit + is used to distinguish leaf and extension nodes. The other two bits are not + used. + + Parameters + ---------- + x : + Array of nibbles. + is_leaf : + True if this is part of a leaf node, or false if it is an extension + node. + + Returns + ------- + compressed : `bytearray` + Compact byte array. + " in + let compact := + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + Constant.int 2 + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.mult (| + Constant.int 16, + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "is_leaf" |) + |) + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + BinOp.add (| + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "is_leaf" |) + |), + Constant.int 1 + |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), Constant.int 0 |) + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 1; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + M.get_name (| globals, "compact" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition bytes_to_nibble_list : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "bytes_" ] |) in + let _ := Constant.str " + Converts a `Bytes` into to a sequence of nibbles (bytes with value < 16). + + Parameters + ---------- + bytes_: + The `Bytes` to convert. + + Returns + ------- + nibble_list : `Bytes` + The `Bytes` in nibble-list format. + " in + let nibble_list := + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [ + BinOp.mult (| + Constant.int 2, + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "bytes_" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + For make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ] in M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "bytes_" |) + ], + make_dict [] + |) do + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |) |), + BinOp.r_shift (| + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 240 + |), + Constant.int 4 + |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |), + Constant.int 1 + |) |), + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 15 + |) + |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + M.get_name (| globals, "nibble_list" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition _prepare_trie : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "get_storage_root" ] |) in + let _ := Constant.str " + Prepares the trie for root calculation. Removes values that are empty, + hashes the keys (if `secured == True`) and encodes all the nodes. + + Parameters + ---------- + trie : + The `Trie` to prepare. + get_storage_root : + Function to get the storage root of an account. Needed to encode + `Account` objects. + + Returns + ------- + out : `Mapping[ethereum.base_types.Bytes, Node]` + Object with keys mapped to nibble-byte form. + " in +(* At stmt: unsupported node type: AnnAssign *) + For make_tuple [ M.get_name (| globals, "preimage" |); M.get_name (| globals, "value" |) ] in M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "items" |), + make_list [], + make_dict [] + |) do + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in + let address := + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |); + M.call (| + M.get_name (| globals, "get_storage_root" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_eq (| M.get_name (| globals, "encoded_value" |), (* At constant: unsupported node type: Constant *) |); + M.get_name (| globals, "AssertionError" |) + ], + make_dict [] + |) in +(* At stmt: unsupported node type: AnnAssign *) + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "trie" |), "secured" |), + (* then *) + ltac:(M.monadic ( + let key := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let key := + M.get_name (| globals, "preimage" |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "mapped" |), M.call (| + M.get_name (| globals, "bytes_to_nibble_list" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |) |), + M.get_name (| globals, "encoded_value" |) + |) in + EndFor. + let _ := M.return_ (| + M.get_name (| globals, "mapped" |) + |) in + M.pure Constant.None_)). + +Definition root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "get_storage_root" ] |) in + let _ := Constant.str " + Computes the root of a modified merkle patricia trie (MPT). + + Parameters + ---------- + trie : + `Trie` to get the root of. + get_storage_root : + Function to get the storage root of an account. Needed to encode + `Account` objects. + + + Returns + ------- + root : `.fork_types.Root` + MPT root of the underlying key-value pairs. + " in + let obj := + M.call (| + M.get_name (| globals, "_prepare_trie" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "get_storage_root" |) + ], + make_dict [] + |) in + let root_node := + M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_name (| globals, "obj" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assert (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "root_node" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Root" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition patricialize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "obj"; "level" ] |) in + let _ := Constant.str " + Structural composition function. + + Used to recursively patricialize and merkleize a dictionary. Includes + memoization of the tree structure and hashes. + + Parameters + ---------- + obj : + Underlying trie key-value pairs, with keys in nibble-list format. + level : + Current trie level. + + Returns + ------- + node : `ethereum.base_types.Bytes` + Root node of `obj`. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let arbitrary_key := + M.call (| + M.get_name (| globals, "next" |), + make_list [ + M.call (| + M.get_name (| globals, "iter" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), Constant.int 1 |), + (* then *) + ltac:(M.monadic ( + let leaf := + M.call (| + M.get_name (| globals, "LeafNode" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |); + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "leaf" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let substring := + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) in + let prefix_length := + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "substring" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do + let prefix_length := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_name (| globals, "prefix_length" |); + M.call (| + M.get_name (| globals, "common_prefix_length" |), + make_list [ + M.get_name (| globals, "substring" |); + M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let prefix := + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ExtensionNode" |), + make_list [ + M.get_name (| globals, "prefix" |); + M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_name (| globals, "obj" |); + BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in +(* At stmt: unsupported node type: AnnAssign *) + For M.get_name (| globals, "_" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 16 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "branches" |), "append" |), + make_list [ + {} + ], + make_dict [] + |) in + EndFor. + let value := + (* At constant: unsupported node type: Constant *) in + For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |), M.get_name (| globals, "level" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "AssertionError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) + |) in + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "BranchNode" |), + make_list [ + [M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "branches" |), M.get_name (| globals, "k" |) |); + BinOp.add (| + M.get_name (| globals, "level" |), + Constant.int 1 + |) + ], + make_dict [] + |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)]; + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/utils/__init__.v b/CoqOfPython/ethereum/byzantium/utils/__init__.v new file mode 100644 index 0000000..1baedea --- /dev/null +++ b/CoqOfPython/ethereum/byzantium/utils/__init__.v @@ -0,0 +1,8 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Utility functions unique to this particular fork. +". diff --git a/CoqOfPython/ethereum/byzantium/utils/address.v b/CoqOfPython/ethereum/byzantium/utils/address.v new file mode 100644 index 0000000..ad3e93e --- /dev/null +++ b/CoqOfPython/ethereum/byzantium/utils/address.v @@ -0,0 +1,134 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Hardfork Utility Functions For Addresses +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Address specific functions used in this byzantium version of +specification. +". + +Require typing. +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_left_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Definition to_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "data" ] |) in + let _ := Constant.str " + Convert a Uint or U256 value to a valid address (20 bytes). + + Parameters + ---------- + data : + The string to be converted to bytes. + + Returns + ------- + address : `Address` + The obtained address. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_subscript (| M.call (| + M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition compute_contract_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "address"; "nonce" ] |) in + let _ := Constant.str " + Computes address of the new account that needs to be created. + + Parameters + ---------- + address : + The address of the account that wants to create the new account. + nonce : + The transaction count of the account that wants to create the new + account. + + Returns + ------- + address: `ethereum.byzantium.fork_types.Address` + The computed address of the new account. + " in + let computed_address := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_list [ + M.get_name (| globals, "address" |); + M.get_name (| globals, "nonce" |) + ] + ], + make_dict [] + |) + ], + make_dict [] + |) in + let canonical_address := + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + let padded_address := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "canonical_address" |); + Constant.int 20 + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "padded_address" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/utils/hexadecimal.v b/CoqOfPython/ethereum/byzantium/utils/hexadecimal.v new file mode 100644 index 0000000..8e6273d --- /dev/null +++ b/CoqOfPython/ethereum/byzantium/utils/hexadecimal.v @@ -0,0 +1,155 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Utility Functions For Hexadecimal Strings +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Hexadecimal utility functions used in this specification, specific to +Byzantium types. +". + +Require ethereum.utils.hexadecimal. +Axiom ethereum_utils_hexadecimal_remove_hex_prefix : + IsGlobalAlias globals ethereum.utils.hexadecimal.globals "remove_hex_prefix". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Definition hex_to_root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to trie root. + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to trie root. + + Returns + ------- + root : `Root` + Trie root obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Root" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition hex_to_bloom : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to bloom. + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to bloom. + + Returns + ------- + bloom : `Bloom` + Bloom obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bloom" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition hex_to_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to Address (20 bytes). + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to Address. + + Returns + ------- + address : `Address` + The address obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |), "rjust" |), + make_list [ + Constant.int 40; + Constant.str "0" + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/utils/message.v b/CoqOfPython/ethereum/byzantium/utils/message.v new file mode 100644 index 0000000..092862d --- /dev/null +++ b/CoqOfPython/ethereum/byzantium/utils/message.v @@ -0,0 +1,201 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Hardfork Utility Functions For The Message Data-structure +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Message specific functions used in this byzantium version of +specification. +". + +Require typing. +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". + +Require vm. +Axiom vm_Environment : + IsGlobalAlias globals vm.globals "Environment". +Axiom vm_Message : + IsGlobalAlias globals vm.globals "Message". + +Require address. +Axiom address_compute_contract_address : + IsGlobalAlias globals address.globals "compute_contract_address". + +Definition prepare_message : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "caller"; "target"; "value"; "data"; "gas"; "env"; "code_address"; "should_transfer_value"; "is_static" ] |) in + let _ := Constant.str " + Execute a transaction against the provided environment. + + Parameters + ---------- + caller : + Address which initiated the transaction + target : + Address whose code will be executed + value : + Value to be transferred. + data : + Array of bytes provided to the code in `target`. + gas : + Gas provided for the code in `target`. + env : + Environment for the Ethereum Virtual Machine. + code_address : + This is usually same as the `target` address except when an alternative + accounts code needs to be executed. + eg. `CALLCODE` calling a precompile. + should_transfer_value : + if True ETH should be transferred while executing a message call. + is_static: + if True then it prevents all state-changing operations from being + executed. + + Returns + ------- + message: `ethereum.byzantium.vm.Message` + Items containing contract creation or message call specific data. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Bytes0" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.call (| + M.get_name (| globals, "compute_contract_address" |), + make_list [ + M.get_name (| globals, "caller" |); + BinOp.sub (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "caller" |) + ], + make_dict [] + |), "nonce" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let msg_data := + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |) in + let code := + M.get_name (| globals, "data" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.get_name (| globals, "target" |) in + let msg_data := + M.get_name (| globals, "data" |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "target" |) + ], + make_dict [] + |), "code" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "code_address" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let code_address := + M.get_name (| globals, "target" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "AssertionError" |), + make_list [ + Constant.str "Target must be address or empty bytes" + ], + make_dict [] + |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/vm/__init__.v b/CoqOfPython/ethereum/byzantium/vm/__init__.v new file mode 100644 index 0000000..520603e --- /dev/null +++ b/CoqOfPython/ethereum/byzantium/vm/__init__.v @@ -0,0 +1,244 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The abstract computer which runs the code stored in an +`.fork_types.Account`. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_State : + IsGlobalAlias globals state.globals "State". +Axiom state_account_exists_and_is_empty : + IsGlobalAlias globals state.globals "account_exists_and_is_empty". + +Require precompiled_contracts. +Axiom precompiled_contracts_RIPEMD160_ADDRESS : + IsGlobalAlias globals precompiled_contracts.globals "RIPEMD160_ADDRESS". + +Definition __all__ : Value.t := M.run ltac:(M.monadic ( + make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] +)). + +Definition Environment : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Message : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Evm : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition incorporate_child_on_success : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "child_evm" ] |) in + let _ := Constant.str " + Incorporate the state of a successful `child_evm` into the parent `evm`. + + Parameters + ---------- + evm : + The parent `EVM`. + child_evm : + The child evm to incorporate. + " in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "gas_left" |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "logs" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "logs" |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "refund_counter" |) + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "accounts_to_delete" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition incorporate_child_on_error : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "child_evm" ] |) in + let _ := Constant.str " + Incorporate the state of an unsuccessful `child_evm` into the parent `evm`. + + Parameters + ---------- + evm : + The parent `EVM`. + child_evm : + The child evm to incorporate. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "RIPEMD160_ADDRESS" |), M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |), M.get_name (| globals, "RIPEMD160_ADDRESS" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "gas_left" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/vm/exceptions.v b/CoqOfPython/ethereum/byzantium/vm/exceptions.v new file mode 100644 index 0000000..23d00db --- /dev/null +++ b/CoqOfPython/ethereum/byzantium/vm/exceptions.v @@ -0,0 +1,152 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Exceptions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Exceptions which cause the EVM to halt exceptionally. +". + +Require ethereum.exceptions. +Axiom ethereum_exceptions_EthereumException : + IsGlobalAlias globals ethereum.exceptions.globals "EthereumException". + +Definition ExceptionalHalt : Value.t := + builtins.make_klass + [(globals, "EthereumException")] + [ + + ] + [ + + ]. + +Definition Revert : Value.t := + builtins.make_klass + [(globals, "EthereumException")] + [ + + ] + [ + + ]. + +Definition StackUnderflowError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition StackOverflowError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition OutOfGasError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition InvalidOpcode : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + ( + "__init__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "code" ] |) in + let _ := M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "super" |), + make_list [], + make_dict [] + |), "__init__" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "self" |), "code" |), + M.get_name (| globals, "code" |) + |) in + M.pure Constant.None_)) + ) + ]. + +Definition InvalidJumpDestError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition StackDepthLimitError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition WriteInStaticContext : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition OutOfBoundsRead : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition AddressCollision : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/__init__.v b/CoqOfPython/ethereum/byzantium/vm/instructions/__init__.v new file mode 100644 index 0000000..e5bebd7 --- /dev/null +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/__init__.v @@ -0,0 +1,87 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +EVM Instruction Encoding (Opcodes) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Machine readable representations of EVM instructions, and a mapping to their +implementations. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". + +Require __init__. +Axiom __init___arithmetic : + IsGlobalAlias globals __init__.globals "arithmetic". + +Require __init__. +Axiom __init___bitwise : + IsGlobalAlias globals __init__.globals "bitwise". + +Require __init__. +Axiom __init___block : + IsGlobalAlias globals __init__.globals "block". + +Require __init__. +Axiom __init___comparison : + IsGlobalAlias globals __init__.globals "comparison". + +Require __init__. +Axiom __init___control_flow : + IsGlobalAlias globals __init__.globals "control_flow". + +Require __init__. +Axiom __init___environment : + IsGlobalAlias globals __init__.globals "environment". + +Require __init__. +Axiom __init___keccak : + IsGlobalAlias globals __init__.globals "keccak". + +Require __init__. +Axiom __init___log : + IsGlobalAlias globals __init__.globals "log". + +Require __init__. +Axiom __init___memory : + IsGlobalAlias globals __init__.globals "memory". + +Require __init__. +Axiom __init___stack : + IsGlobalAlias globals __init__.globals "stack". + +Require __init__. +Axiom __init___storage : + IsGlobalAlias globals __init__.globals "storage". + +Require __init__. +Axiom __init___system : + IsGlobalAlias globals __init__.globals "system". + +Definition Ops : Value.t := + builtins.make_klass + [(* At base: unsupported node type: Attribute *)] + [ + + ] + [ + + ]. + +(* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/byzantium/vm/instructions/arithmetic.v new file mode 100644 index 0000000..a8b5c61 --- /dev/null +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/arithmetic.v @@ -0,0 +1,1085 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Arithmetic Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM Arithmetic instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U255_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U255_CEIL_VALUE". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_U256_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_get_sign : + IsGlobalAlias globals ethereum.utils.numeric.globals "get_sign". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_EXPONENTIATION : + IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION". +Axiom gas_GAS_EXPONENTIATION_PER_BYTE : + IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION_PER_BYTE". +Axiom gas_GAS_LOW : + IsGlobalAlias globals gas.globals "GAS_LOW". +Axiom gas_GAS_MID : + IsGlobalAlias globals gas.globals "GAS_MID". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition add : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Adds the top two elements of the stack together, and pushes the result back + on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "x" |), "wrapping_add" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition sub : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Subtracts the top two elements of the stack, and pushes the result back + on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "x" |), "wrapping_sub" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mul : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Multiply the top two elements of the stack, and pushes the result back + on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "x" |), "wrapping_mul" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition div : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Integer division of the top two elements of the stack. Pushes the result + back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let dividend := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let divisor := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let quotient := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let quotient := + BinOp.floor_div (| + M.get_name (| globals, "dividend" |), + M.get_name (| globals, "divisor" |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "quotient" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition sdiv : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed integer division of the top two elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let dividend := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let divisor := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let quotient := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_name (| globals, "dividend" |), UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "divisor" |), UnOp.sub (| Constant.int 1 |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let quotient := + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let sign := + M.call (| + M.get_name (| globals, "get_sign" |), + make_list [ + BinOp.mult (| + M.get_name (| globals, "dividend" |), + M.get_name (| globals, "divisor" |) + |) + ], + make_dict [] + |) in + let quotient := + BinOp.mult (| + M.get_name (| globals, "sign" |), + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "dividend" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "divisor" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + M.get_name (| globals, "quotient" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Modulo remainder of the top two elements of the stack. Pushes the result + back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let remainder := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let remainder := + BinOp.mod_ (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "remainder" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition smod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed modulo remainder of the top two elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let y := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let remainder := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let remainder := + BinOp.mult (| + M.call (| + M.get_name (| globals, "get_sign" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + BinOp.mod_ (| + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + M.get_name (| globals, "remainder" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition addmod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Modulo addition of the top 2 elements with the 3rd element. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let z := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_MID" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.add (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |), + M.get_name (| globals, "z" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mulmod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Modulo multiplication of the top 2 elements with the 3rd element. Pushes + the result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let z := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_MID" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.mult (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |), + M.get_name (| globals, "z" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition exp : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Exponential operation of the top 2 elements. Pushes the result back on + the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let base := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exponent := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exponent_bits := + M.call (| + M.get_field (| M.get_name (| globals, "exponent" |), "bit_length" |), + make_list [], + make_dict [] + |) in + let exponent_bytes := + BinOp.floor_div (| + BinOp.add (| + M.get_name (| globals, "exponent_bits" |), + Constant.int 7 + |), + Constant.int 8 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_EXPONENTIATION" |), + BinOp.mult (| + M.get_name (| globals, "GAS_EXPONENTIATION_PER_BYTE" |), + M.get_name (| globals, "exponent_bytes" |) + |) + |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "pow" |), + make_list [ + M.get_name (| globals, "base" |); + M.get_name (| globals, "exponent" |); + M.get_name (| globals, "U256_CEIL_VALUE" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition signextend : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Sign extend operation. In other words, extend a signed number which + fits in N bytes to 32 bytes. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let byte_num := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "byte_num" |), Constant.int 31 |), + (* then *) + ltac:(M.monadic ( + let result := + M.get_name (| globals, "value" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let value_bytes := + M.call (| + M.get_name (| globals, "bytes" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "value" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) in + let value_bytes := + M.get_subscript (| M.get_name (| globals, "value_bytes" |), BinOp.sub (| + Constant.int 31, + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "byte_num" |) + ], + make_dict [] + |) + |):(* At expr: unsupported node type: NoneType *) |) in + let sign_bit := + BinOp.r_shift (| + M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), + Constant.int 7 + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "sign_bit" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "value_bytes" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let num_bytes_prepend := + BinOp.sub (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "byte_num" |), + Constant.int 1 + |) + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + BinOp.add (| + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [ + BinOp.mult (| + make_list [ + Constant.int 255 + ], + M.get_name (| globals, "num_bytes_prepend" |) + |) + ], + make_dict [] + |), + M.get_name (| globals, "value_bytes" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/bitwise.v b/CoqOfPython/ethereum/byzantium/vm/instructions/bitwise.v new file mode 100644 index 0000000..b20a1e5 --- /dev/null +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/bitwise.v @@ -0,0 +1,345 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Bitwise Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM bitwise instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition bitwise_and : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise AND operation of the top 2 elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + BinOp.bit_and (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_or : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise OR operation of the top 2 elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + BinOp.bit_or (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_xor : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise XOR operation of the top 2 elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + BinOp.bit_xor (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_not : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise NOT operation of the top element of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + UnOp.invert (| M.get_name (| globals, "x" |) |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition get_byte : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + For a word (defined by next top element of the stack), retrieve the + Nth byte (0-indexed and defined by top element of stack) from the + left (most significant) to right (least significant). + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let byte_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let word := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "byte_index" |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let extra_bytes_to_right := + BinOp.sub (| + Constant.int 31, + M.get_name (| globals, "byte_index" |) + |) in + let word := + BinOp.r_shift (| + M.get_name (| globals, "word" |), + BinOp.mult (| + M.get_name (| globals, "extra_bytes_to_right" |), + Constant.int 8 + |) + |) in + let word := + BinOp.bit_and (| + M.get_name (| globals, "word" |), + Constant.int 255 + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "word" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/block.v b/CoqOfPython/ethereum/byzantium/vm/instructions/block.v new file mode 100644 index 0000000..e5fa554 --- /dev/null +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/block.v @@ -0,0 +1,337 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Block Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM block instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_BLOCK_HASH : + IsGlobalAlias globals gas.globals "GAS_BLOCK_HASH". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition block_hash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the hash of one of the 256 most recent complete blocks onto the + stack. The block number to hash is present at the top of the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let block_number := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BLOCK_HASH" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt_e (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), M.get_name (| globals, "block_number" |) |), + ltac:(M.monadic ( + Compare.gt (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), BinOp.add (| + M.get_name (| globals, "block_number" |), + Constant.int 256 + |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let hash := + (* At constant: unsupported node type: Constant *) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let hash := + M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + M.get_name (| globals, "block_number" |) + |) |) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "hash" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition coinbase : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's beneficiary address (address of the block miner) + onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "coinbase" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition timestamp : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's timestamp onto the stack. Here the timestamp + being referred is actually the unix timestamp in seconds. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "time" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition number : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's number onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition difficulty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's difficulty onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "difficulty" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition gas_limit : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's gas limit onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "gas_limit" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/comparison.v b/CoqOfPython/ethereum/byzantium/vm/instructions/comparison.v new file mode 100644 index 0000000..fbc35f8 --- /dev/null +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/comparison.v @@ -0,0 +1,404 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Comparison Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM Comparison instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition less_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is less than the next top element. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let right := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition signed_less_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed less-than comparison. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let right := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition greater_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is greater than the next top element. Pushes + the result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let right := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition signed_greater_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed greater-than comparison. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let right := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition equal : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is equal to the next top element. Pushes + the result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let right := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.eq (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition is_zero : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is equal to 0. Pushes the result back on the + stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.eq (| M.get_name (| globals, "x" |), Constant.int 0 |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/control_flow.v b/CoqOfPython/ethereum/byzantium/vm/instructions/control_flow.v new file mode 100644 index 0000000..04a79d9 --- /dev/null +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/control_flow.v @@ -0,0 +1,336 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Control Flow Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM control flow instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require vm.gas. +Axiom vm_gas_GAS_BASE : + IsGlobalAlias globals vm.gas.globals "GAS_BASE". +Axiom vm_gas_GAS_HIGH : + IsGlobalAlias globals vm.gas.globals "GAS_HIGH". +Axiom vm_gas_GAS_JUMPDEST : + IsGlobalAlias globals vm.gas.globals "GAS_JUMPDEST". +Axiom vm_gas_GAS_MID : + IsGlobalAlias globals vm.gas.globals "GAS_MID". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_InvalidJumpDestError : + IsGlobalAlias globals exceptions.globals "InvalidJumpDestError". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition stop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stop further execution of EVM code. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let _ := M.pass (| |) in + let _ := M.pass (| |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "running" |), + Constant.bool false + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition jump : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Alter the program counter to the location specified by the top of the + stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let jump_dest := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_MID" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "jump_dest" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition jumpi : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Alter the program counter to the specified location if and only if a + condition is true. If the condition is not true, then the program counter + would increase only by 1. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let jump_dest := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let conditional_value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_HIGH" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "conditional_value" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let destination := + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let destination := + M.get_name (| globals, "jump_dest" |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "destination" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition pc : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push onto the stack the value of the program counter after reaching the + current instruction and without increasing it for the next instruction. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "pc" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition gas_left : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the amount of available gas (including the corresponding reduction + for the cost of this instruction) onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition jumpdest : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Mark a valid destination for jumps. This is a noop, present only + to be used by `JUMP` and `JUMPI` opcodes to verify that their jump is + valid. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_JUMPDEST" |) + ], + make_dict [] + |) in + let _ := M.pass (| |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/environment.v b/CoqOfPython/ethereum/byzantium/vm/instructions/environment.v new file mode 100644 index 0000000..2929b1e --- /dev/null +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/environment.v @@ -0,0 +1,1140 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Environmental Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM environment related instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require state. +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". + +Require utils.address. +Axiom utils_address_to_address : + IsGlobalAlias globals utils.address.globals "to_address". + +Require vm.memory. +Axiom vm_memory_buffer_read : + IsGlobalAlias globals vm.memory.globals "buffer_read". +Axiom vm_memory_memory_write : + IsGlobalAlias globals vm.memory.globals "memory_write". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_OutOfBoundsRead : + IsGlobalAlias globals exceptions.globals "OutOfBoundsRead". + +Require gas. +Axiom gas_GAS_BALANCE : + IsGlobalAlias globals gas.globals "GAS_BALANCE". +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_COPY : + IsGlobalAlias globals gas.globals "GAS_COPY". +Axiom gas_GAS_EXTERNAL : + IsGlobalAlias globals gas.globals "GAS_EXTERNAL". +Axiom gas_GAS_RETURN_DATA_COPY : + IsGlobalAlias globals gas.globals "GAS_RETURN_DATA_COPY". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the address of the current executing account to the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition balance : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the balance of the given account onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BALANCE" |) + ], + make_dict [] + |) in + let balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "balance" |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "balance" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition origin : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the address of the original transaction sender to the stack. + The origin address can only be an EOA. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "origin" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition caller : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the address of the caller onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "caller" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition callvalue : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the value (in wei) sent with the call onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition calldataload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push a word (32 bytes) of the input data belonging to the current + environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |); + M.get_name (| globals, "start_index" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition calldatasize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the size of input data in current environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition calldatacopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy a portion of the input data in current environment to memory. + + This will also expand the memory, in case that the memory is insufficient + to store the data. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let data_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |); + M.get_name (| globals, "data_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition codesize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the size of code running in current environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "code" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition codecopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy a portion of the code in current environment to memory. + + This will also expand the memory, in case that the memory is insufficient + to store the data. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let code_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "code" |); + M.get_name (| globals, "code_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition gasprice : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the gas price used in current environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "gas_price" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition extcodesize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the code size of a given account onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_EXTERNAL" |) + ], + make_dict [] + |) in + let codesize := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "code" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "codesize" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition extcodecopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy a portion of an account's code to memory. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let code_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_EXTERNAL" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "code" |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "code" |); + M.get_name (| globals, "code_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition returndatasize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the size of the return data buffer onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition returndatacopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copies data from the return data buffer code to memory + + Parameters + ---------- + evm : + The current EVM frame. + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let return_data_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_RETURN_DATA_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "return_data_start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "OutOfBoundsRead" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |):BinOp.add (| + M.get_name (| globals, "return_data_start_position" |), + M.get_name (| globals, "size" |) + |) |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/keccak.v b/CoqOfPython/ethereum/byzantium/vm/instructions/keccak.v new file mode 100644 index 0000000..cab9ffb --- /dev/null +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/keccak.v @@ -0,0 +1,181 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Keccak Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM keccak instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_KECCAK256 : + IsGlobalAlias globals gas.globals "GAS_KECCAK256". +Axiom gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition keccak : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes to the stack the Keccak-256 hash of a region of memory. + + This also expands the memory, in case the memory is insufficient to + access the data's memory location. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let word_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_KECCAK256_WORD" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_KECCAK256" |), + M.get_name (| globals, "word_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let data := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "hash" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/log.v b/CoqOfPython/ethereum/byzantium/vm/instructions/log.v new file mode 100644 index 0000000..4891a4d --- /dev/null +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/log.v @@ -0,0 +1,244 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Logging Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM logging instructions. +". + +Require functools. +Axiom functools_partial : + IsGlobalAlias globals functools.globals "partial". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_WriteInStaticContext : + IsGlobalAlias globals exceptions.globals "WriteInStaticContext". + +Require gas. +Axiom gas_GAS_LOG : + IsGlobalAlias globals gas.globals "GAS_LOG". +Axiom gas_GAS_LOG_DATA : + IsGlobalAlias globals gas.globals "GAS_LOG_DATA". +Axiom gas_GAS_LOG_TOPIC : + IsGlobalAlias globals gas.globals "GAS_LOG_TOPIC". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". + +Definition log_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "num_topics" ] |) in + let _ := Constant.str " + Appends a log entry, having `num_topics` topics, to the evm logs. + + This will also expand the memory if the data (required by the log entry) + corresponding to the memory is not accessible. + + Parameters + ---------- + evm : + The current EVM frame. + num_topics : + The number of topics to be included in the log entry. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let topics := + make_list [] in + For M.get_name (| globals, "_" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "num_topics" |) + ], + make_dict [] + |) do + let topic := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "topics" |), "append" |), + make_list [ + M.get_name (| globals, "topic" |) + ], + make_dict [] + |) in + EndFor. + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_LOG" |), + BinOp.mult (| + M.get_name (| globals, "GAS_LOG_DATA" |), + M.get_name (| globals, "size" |) + |) + |), + BinOp.mult (| + M.get_name (| globals, "GAS_LOG_TOPIC" |), + M.get_name (| globals, "num_topics" |) + |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let log_entry := + M.call (| + M.get_name (| globals, "Log" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "logs" |), + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "logs" |), + make_tuple [ M.get_name (| globals, "log_entry" |) ] + |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition log0 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/memory.v b/CoqOfPython/ethereum/byzantium/vm/instructions/memory.v new file mode 100644 index 0000000..1e1c8b0 --- /dev/null +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/memory.v @@ -0,0 +1,378 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Memory Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM Memory instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". +Axiom memory_memory_write : + IsGlobalAlias globals memory.globals "memory_write". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition mstore : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a word to memory. + This also expands the memory, if the memory is + insufficient to store the word. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "start_position" |); M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + ], + make_dict [] + |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "start_position" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mstore8 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a byte to memory. + This also expands the memory, if the memory is + insufficient to store the word. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "start_position" |); M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let normalized_bytes_value := + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + make_list [ + BinOp.bit_and (| + M.get_name (| globals, "value" |), + Constant.int 255 + |) + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "start_position" |); + M.get_name (| globals, "normalized_bytes_value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Load word from memory. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "start_position" |); M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "start_position" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition msize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the size of active memory in bytes onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/stack.v b/CoqOfPython/ethereum/byzantium/vm/instructions/stack.v new file mode 100644 index 0000000..1eeda05 --- /dev/null +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/stack.v @@ -0,0 +1,929 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Stack Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM stack related instructions. +". + +Require functools. +Axiom functools_partial : + IsGlobalAlias globals functools.globals "partial". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". +Axiom __init___stack : + IsGlobalAlias globals __init__.globals "stack". + +Require exceptions. +Axiom exceptions_StackUnderflowError : + IsGlobalAlias globals exceptions.globals "StackUnderflowError". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_buffer_read : + IsGlobalAlias globals memory.globals "buffer_read". + +Definition pop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Remove item from stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.pass (| |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition push_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "num_bytes" ] |) in + let _ := Constant.str " + Pushes a N-byte immediate onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + num_bytes : + The number of immediate bytes to be read from the code and pushed to + the stack. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let data_to_push := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "code" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "num_bytes" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "data_to_push" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + BinOp.add (| + Constant.int 1, + M.get_name (| globals, "num_bytes" |) + |) + |) in + M.pure Constant.None_)). + +Definition dup_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "item_number" ] |) in + let _ := Constant.str " + Duplicate the Nth stack item (from top of the stack) to the top of stack. + + Parameters + ---------- + evm : + The current EVM frame. + + item_number : + The stack item number (0-indexed from top of stack) to be duplicated + to the top of stack. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "StackUnderflowError" |) + ], + make_dict [] + |) in + let data_to_duplicate := + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + BinOp.sub (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), + Constant.int 1 + |), + M.get_name (| globals, "item_number" |) + |) |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "data_to_duplicate" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition swap_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "item_number" ] |) in + let _ := Constant.str " + Swap the top and the `item_number` element of the stack, where + the top of the stack is position zero. + + If `item_number` is zero, this function does nothing (which should not be + possible, since there is no `SWAP0` instruction). + + Parameters + ---------- + evm : + The current EVM frame. + + item_number : + The stack item number (0-indexed from top of stack) to be swapped + with the top of stack element. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "StackUnderflowError" |) + ], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) |) ], + make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |) ] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition push1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push5 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push6 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push7 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push8 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push9 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push10 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push11 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push12 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push13 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push14 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push15 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push16 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push17 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push18 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push19 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push20 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push21 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push22 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push23 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push24 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push25 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push26 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push27 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push28 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push29 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push30 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push31 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push32 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition dup1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup5 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup6 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup7 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup8 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup9 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup10 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup11 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup12 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup13 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup14 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup15 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup16 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition swap1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap5 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap6 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap7 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap8 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap9 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap10 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap11 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap12 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap13 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap14 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap15 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap16 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/storage.v b/CoqOfPython/ethereum/byzantium/vm/instructions/storage.v new file mode 100644 index 0000000..29ef235 --- /dev/null +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/storage.v @@ -0,0 +1,228 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Storage Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM storage related instructions. +". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require state. +Axiom state_get_storage : + IsGlobalAlias globals state.globals "get_storage". +Axiom state_set_storage : + IsGlobalAlias globals state.globals "set_storage". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_WriteInStaticContext : + IsGlobalAlias globals exceptions.globals "WriteInStaticContext". + +Require gas. +Axiom gas_GAS_SLOAD : + IsGlobalAlias globals gas.globals "GAS_SLOAD". +Axiom gas_GAS_STORAGE_CLEAR_REFUND : + IsGlobalAlias globals gas.globals "GAS_STORAGE_CLEAR_REFUND". +Axiom gas_GAS_STORAGE_SET : + IsGlobalAlias globals gas.globals "GAS_STORAGE_SET". +Axiom gas_GAS_STORAGE_UPDATE : + IsGlobalAlias globals gas.globals "GAS_STORAGE_UPDATE". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition sload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Loads to the stack, the value corresponding to a certain key from the + storage of the current account. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let key := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_SLOAD" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "get_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition sstore : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a value at a certain key in the current context's storage. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let key := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let new_value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let current_value := + M.call (| + M.get_name (| globals, "get_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "new_value" |), Constant.int 0 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let gas_cost := + M.get_name (| globals, "GAS_STORAGE_SET" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let gas_cost := + M.get_name (| globals, "GAS_STORAGE_UPDATE" |) in + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_name (| globals, "new_value" |), Constant.int 0 |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "gas_cost" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "set_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |); + M.get_name (| globals, "new_value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/vm/interpreter.v b/CoqOfPython/ethereum/byzantium/vm/interpreter.v new file mode 100644 index 0000000..c9f61e0 --- /dev/null +++ b/CoqOfPython/ethereum/byzantium/vm/interpreter.v @@ -0,0 +1,627 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Interpreter +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +A straightforward interpreter that executes EVM code. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Iterable : + IsGlobalAlias globals typing.globals "Iterable". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.trace. +Axiom ethereum_trace_EvmStop : + IsGlobalAlias globals ethereum.trace.globals "EvmStop". +Axiom ethereum_trace_OpEnd : + IsGlobalAlias globals ethereum.trace.globals "OpEnd". +Axiom ethereum_trace_OpException : + IsGlobalAlias globals ethereum.trace.globals "OpException". +Axiom ethereum_trace_OpStart : + IsGlobalAlias globals ethereum.trace.globals "OpStart". +Axiom ethereum_trace_PrecompileEnd : + IsGlobalAlias globals ethereum.trace.globals "PrecompileEnd". +Axiom ethereum_trace_PrecompileStart : + IsGlobalAlias globals ethereum.trace.globals "PrecompileStart". +Axiom ethereum_trace_TransactionEnd : + IsGlobalAlias globals ethereum.trace.globals "TransactionEnd". +Axiom ethereum_trace_evm_trace : + IsGlobalAlias globals ethereum.trace.globals "evm_trace". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_account_exists_and_is_empty : + IsGlobalAlias globals state.globals "account_exists_and_is_empty". +Axiom state_account_has_code_or_nonce : + IsGlobalAlias globals state.globals "account_has_code_or_nonce". +Axiom state_begin_transaction : + IsGlobalAlias globals state.globals "begin_transaction". +Axiom state_commit_transaction : + IsGlobalAlias globals state.globals "commit_transaction". +Axiom state_destroy_storage : + IsGlobalAlias globals state.globals "destroy_storage". +Axiom state_increment_nonce : + IsGlobalAlias globals state.globals "increment_nonce". +Axiom state_move_ether : + IsGlobalAlias globals state.globals "move_ether". +Axiom state_rollback_transaction : + IsGlobalAlias globals state.globals "rollback_transaction". +Axiom state_set_code : + IsGlobalAlias globals state.globals "set_code". +Axiom state_touch_account : + IsGlobalAlias globals state.globals "touch_account". + +Require vm. +Axiom vm_Message : + IsGlobalAlias globals vm.globals "Message". + +Require vm.gas. +Axiom vm_gas_GAS_CODE_DEPOSIT : + IsGlobalAlias globals vm.gas.globals "GAS_CODE_DEPOSIT". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require vm.precompiled_contracts.mapping. +Axiom vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : + IsGlobalAlias globals vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". + +Require __init__. +Axiom __init___Environment : + IsGlobalAlias globals __init__.globals "Environment". +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_AddressCollision : + IsGlobalAlias globals exceptions.globals "AddressCollision". +Axiom exceptions_ExceptionalHalt : + IsGlobalAlias globals exceptions.globals "ExceptionalHalt". +Axiom exceptions_InvalidOpcode : + IsGlobalAlias globals exceptions.globals "InvalidOpcode". +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". +Axiom exceptions_Revert : + IsGlobalAlias globals exceptions.globals "Revert". +Axiom exceptions_StackDepthLimitError : + IsGlobalAlias globals exceptions.globals "StackDepthLimitError". + +Require instructions. +Axiom instructions_Ops : + IsGlobalAlias globals instructions.globals "Ops". +Axiom instructions_op_implementation : + IsGlobalAlias globals instructions.globals "op_implementation". + +Require runtime. +Axiom runtime_get_valid_jump_destinations : + IsGlobalAlias globals runtime.globals "get_valid_jump_destinations". + +Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1024 + ], + make_dict [] + |) +)). + +Definition MAX_CODE_SIZE : Value.t := M.run ltac:(M.monadic ( + Constant.int 24576 +)). + +Definition MessageCallOutput : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition process_message_call : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + If `message.current` is empty then it creates a smart contract + else it executes a call from the `message.caller` to the `message.target`. + + Parameters + ---------- + message : + Transaction specific items. + + env : + External items required for EVM execution. + + Returns + ------- + output : `MessageCallOutput` + Output of the message call + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_name (| globals, "message" |), "target" |), M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let is_collision := + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_name (| globals, "is_collision" |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallOutput" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "tuple" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "AddressCollision" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let evm := + M.call (| + M.get_name (| globals, "process_create_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let evm := + M.call (| + M.get_name (| globals, "process_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_field (| M.get_name (| globals, "message" |), "target" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_field (| M.get_name (| globals, "message" |), "target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( +(* At stmt: unsupported node type: AnnAssign *) + let accounts_to_delete := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let touched_accounts := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let refund_counter := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let logs := + M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in + let accounts_to_delete := + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in + let touched_accounts := + M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |) in + let refund_counter := + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |) in + M.pure Constant.None_ + )) |) in + let tx_end := + M.call (| + M.get_name (| globals, "TransactionEnd" |), + make_list [ + BinOp.sub (| + M.get_field (| M.get_name (| globals, "message" |), "gas" |), + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + |); + M.get_field (| M.get_name (| globals, "evm" |), "output" |); + M.get_field (| M.get_name (| globals, "evm" |), "error" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "evm_trace" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "tx_end" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallOutput" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition process_create_message : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + Executes a call to create a smart contract. + + Parameters + ---------- + message : + Transaction specific items. + env : + External items required for EVM execution. + + Returns + ------- + evm: :py:class:`~ethereum.byzantium.vm.Evm` + Items containing execution specific objects. + " in + let _ := M.call (| + M.get_name (| globals, "begin_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "destroy_storage" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let evm := + M.call (| + M.get_name (| globals, "process_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), + (* then *) + ltac:(M.monadic ( + let contract_code := + M.get_field (| M.get_name (| globals, "evm" |), "output" |) in + let contract_code_gas := + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "contract_code" |) + ], + make_dict [] + |), + M.get_name (| globals, "GAS_CODE_DEPOSIT" |) + |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "rollback_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.get_name (| globals, "evm" |) + |) in + M.pure Constant.None_)). + +Definition process_message : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + Executes a call to create a smart contract. + + Parameters + ---------- + message : + Transaction specific items. + env : + External items required for EVM execution. + + Returns + ------- + evm: :py:class:`~ethereum.byzantium.vm.Evm` + Items containing execution specific objects + " in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_field (| M.get_name (| globals, "message" |), "depth" |), M.get_name (| globals, "STACK_DEPTH_LIMIT" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "StackDepthLimitError" |), + make_list [ + Constant.str "Stack depth limit reached" + ], + make_dict [] + |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "begin_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "touch_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + M.get_field (| M.get_name (| globals, "message" |), "should_transfer_value" |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_field (| M.get_name (| globals, "message" |), "value" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "move_ether" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "caller" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |); + M.get_field (| M.get_name (| globals, "message" |), "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let evm := + M.call (| + M.get_name (| globals, "execute_code" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "rollback_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "commit_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.get_name (| globals, "evm" |) + |) in + M.pure Constant.None_)). + +Definition execute_code : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + Executes bytecode present in the `message`. + + Parameters + ---------- + message : + Transaction specific items. + env : + External items required for EVM execution. + + Returns + ------- + evm: `ethereum.vm.EVM` + Items containing execution specific objects + " in + let code := + M.get_field (| M.get_name (| globals, "message" |), "code" |) in + let valid_jump_destinations := + M.call (| + M.get_name (| globals, "get_valid_jump_destinations" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) in + let evm := + M.call (| + M.get_name (| globals, "Evm" |), + make_list [], + make_dict [] + |) in +(* At stmt: unsupported node type: Try *) + let _ := M.return_ (| + M.get_name (| globals, "evm" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/vm/memory.v b/CoqOfPython/ethereum/byzantium/vm/memory.v new file mode 100644 index 0000000..fa8d906 --- /dev/null +++ b/CoqOfPython/ethereum/byzantium/vm/memory.v @@ -0,0 +1,153 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Memory +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +EVM memory operations. +". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_right_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "right_pad_zero_bytes". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". + +Definition memory_write : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "memory"; "start_position"; "value" ] |) in + let _ := Constant.str " + Writes to memory. + + Parameters + ---------- + memory : + Memory contents of the EVM. + start_position : + Starting pointer to the memory. + value : + Data to write to memory. + " in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) |), + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_)). + +Definition memory_read_bytes : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "memory"; "start_position"; "size" ] |) in + let _ := Constant.str " + Read bytes from memory. + + Parameters + ---------- + memory : + Memory contents of the EVM. + start_position : + Starting pointer to the memory. + size : + Size of the data that needs to be read from `start_position`. + + Returns + ------- + data_bytes : + Data read from memory. + " in + let _ := M.return_ (| + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |) + |) in + M.pure Constant.None_)). + +Definition buffer_read : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "buffer"; "start_position"; "size" ] |) in + let _ := Constant.str " + Read bytes from a buffer. Padding with zeros if necessary. + + Parameters + ---------- + buffer : + Memory contents of the EVM. + start_position : + Starting pointer to the memory. + size : + Size of the data that needs to be read from `start_position`. + + Returns + ------- + data_bytes : + Data read from memory. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "right_pad_zero_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/__init__.v new file mode 100644 index 0000000..0210a12 --- /dev/null +++ b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/__init__.v @@ -0,0 +1,107 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Precompiled Contract Addresses +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Addresses of precompiled contracts and mappings to their +implementations. +". + +Require utils.hexadecimal. +Axiom utils_hexadecimal_hex_to_address : + IsGlobalAlias globals utils.hexadecimal.globals "hex_to_address". + +Definition __all__ : Value.t := M.run ltac:(M.monadic ( + make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS"; Constant.str "MODEXP_ADDRESS"; Constant.str "ALT_BN128_ADD_ADDRESS"; Constant.str "ALT_BN128_MUL_ADDRESS"; Constant.str "ALT_BN128_PAIRING_CHECK_ADDRESS"; Constant.str "BLAKE2F_ADDRESS" ] +)). + +Definition ECRECOVER_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x01" + ], + make_dict [] + |) +)). + +Definition SHA256_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x02" + ], + make_dict [] + |) +)). + +Definition RIPEMD160_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x03" + ], + make_dict [] + |) +)). + +Definition IDENTITY_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x04" + ], + make_dict [] + |) +)). + +Definition MODEXP_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x05" + ], + make_dict [] + |) +)). + +Definition ALT_BN128_ADD_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x06" + ], + make_dict [] + |) +)). + +Definition ALT_BN128_MUL_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x07" + ], + make_dict [] + |) +)). + +Definition ALT_BN128_PAIRING_CHECK_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x08" + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/alt_bn128.v new file mode 100644 index 0000000..0823afa --- /dev/null +++ b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/alt_bn128.v @@ -0,0 +1,673 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) ALT_BN128 CONTRACTS +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the ALT_BN128 precompiled contracts. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.alt_bn128. +Axiom ethereum_crypto_alt_bn128_ALT_BN128_CURVE_ORDER : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "ALT_BN128_CURVE_ORDER". +Axiom ethereum_crypto_alt_bn128_ALT_BN128_PRIME : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "ALT_BN128_PRIME". +Axiom ethereum_crypto_alt_bn128_BNF : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF". +Axiom ethereum_crypto_alt_bn128_BNF2 : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF2". +Axiom ethereum_crypto_alt_bn128_BNF12 : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF12". +Axiom ethereum_crypto_alt_bn128_BNP : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNP". +Axiom ethereum_crypto_alt_bn128_BNP2 : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNP2". +Axiom ethereum_crypto_alt_bn128_pairing : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "pairing". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require vm.memory. +Axiom vm_memory_buffer_read : + IsGlobalAlias globals vm.memory.globals "buffer_read". + +Require exceptions. +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". + +Definition alt_bn128_add : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + The ALT_BN128 addition precompiled contract. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 500 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x0_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x0_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "x0_bytes" |) + ], + make_dict [] + |) in + let y0_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y0_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "y0_bytes" |) + ], + make_dict [] + |) in + let x1_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x1_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "x1_bytes" |) + ], + make_dict [] + |) in + let y1_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y1_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "y1_bytes" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ] do + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "i" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. +(* At stmt: unsupported node type: Try *) + let p := + BinOp.add (| + M.get_name (| globals, "p0" |), + M.get_name (| globals, "p1" |) + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + BinOp.add (| + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "p" |), "x" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "p" |), "y" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) + |) in + M.pure Constant.None_)). + +Definition alt_bn128_mul : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + The ALT_BN128 multiplication precompiled contract. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 40000 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x0_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x0_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "x0_bytes" |) + ], + make_dict [] + |) in + let y0_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y0_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "y0_bytes" |) + ], + make_dict [] + |) in + let n := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ] do + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "i" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. +(* At stmt: unsupported node type: Try *) + let p := + M.call (| + M.get_field (| M.get_name (| globals, "p0" |), "mul_by" |), + make_list [ + M.get_name (| globals, "n" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + BinOp.add (| + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "p" |), "x" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "p" |), "y" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) + |) in + M.pure Constant.None_)). + +Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + The ALT_BN128 pairing check precompiled contract. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 80000, + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 192 + |) + |), + Constant.int 100000 + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 192 + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 192 + |) + ], + make_dict [] + |) do + let values := + make_list [] in + For M.get_name (| globals, "j" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 6 + ], + make_dict [] + |) do + let value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "data" |), BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + M.get_name (| globals, "j" |) + |) + |):BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "j" |), + Constant.int 1 + |) + |) + |) |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "value" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "values" |), "append" |), + make_list [ + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + EndFor. +(* At stmt: unsupported node type: Try *) + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.call (| + M.get_field (| M.get_name (| globals, "p" |), "mul_by" |), + make_list [ + M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) + ], + make_dict [] + |), M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) |); + M.get_name (| globals, "OutOfGasError" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.call (| + M.get_field (| M.get_name (| globals, "q" |), "mul_by" |), + make_list [ + M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) + ], + make_dict [] + |), M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) |); + M.get_name (| globals, "OutOfGasError" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "p" |), M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_name (| globals, "q" |), M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let result := + BinOp.mult (| + M.get_name (| globals, "result" |), + M.call (| + M.get_name (| globals, "pairing" |), + make_list [ + M.get_name (| globals, "q" |); + M.get_name (| globals, "p" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "result" |), M.call (| + M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/ecrecover.v new file mode 100644 index 0000000..cc351b5 --- /dev/null +++ b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/ecrecover.v @@ -0,0 +1,269 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) ECRECOVER PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the ECRECOVER precompiled contract. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require ethereum.crypto.elliptic_curve. +Axiom ethereum_crypto_elliptic_curve_SECP256K1N : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_left_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_ECRECOVER : + IsGlobalAlias globals vm.gas.globals "GAS_ECRECOVER". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require vm.memory. +Axiom vm_memory_buffer_read : + IsGlobalAlias globals vm.memory.globals "buffer_read". + +Definition ecrecover : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Decrypts the address using elliptic curve DSA recovery mechanism and writes + the address to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_ECRECOVER" |) + ], + make_dict [] + |) in + let message_hash_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let message_hash := + M.call (| + M.get_name (| globals, "Hash32" |), + make_list [ + M.get_name (| globals, "message_hash_bytes" |) + ], + make_dict [] + |) in + let v := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let r := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let s := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 27 |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 28 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| Constant.int 0, M.get_name (| globals, "r" |) |), + ltac:(M.monadic ( + Compare.gt_e (| M.get_name (| globals, "r" |), M.get_name (| globals, "SECP256K1N" |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| Constant.int 0, M.get_name (| globals, "s" |) |), + ltac:(M.monadic ( + Compare.gt_e (| M.get_name (| globals, "s" |), M.get_name (| globals, "SECP256K1N" |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in +(* At stmt: unsupported node type: Try *) + let address := + M.get_subscript (| M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), Constant.int 12:Constant.int 32 |) in + let padded_address := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "address" |); + Constant.int 32 + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.get_name (| globals, "padded_address" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/identity.v new file mode 100644 index 0000000..fa96704 --- /dev/null +++ b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/identity.v @@ -0,0 +1,94 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) IDENTITY PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `IDENTITY` precompiled contract. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_IDENTITY : + IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY". +Axiom vm_gas_GAS_IDENTITY_WORD : + IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY_WORD". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition identity : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the message data to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let word_count := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_IDENTITY" |), + BinOp.mult (| + M.get_name (| globals, "GAS_IDENTITY_WORD" |), + M.get_name (| globals, "word_count" |) + |) + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.get_name (| globals, "data" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/mapping.v new file mode 100644 index 0000000..b1a0ed3 --- /dev/null +++ b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/mapping.v @@ -0,0 +1,76 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Precompiled Contract Addresses +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Mapping of precompiled contracts their implementations. +". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require __init__. +Axiom __init___ALT_BN128_ADD_ADDRESS : + IsGlobalAlias globals __init__.globals "ALT_BN128_ADD_ADDRESS". +Axiom __init___ALT_BN128_MUL_ADDRESS : + IsGlobalAlias globals __init__.globals "ALT_BN128_MUL_ADDRESS". +Axiom __init___ALT_BN128_PAIRING_CHECK_ADDRESS : + IsGlobalAlias globals __init__.globals "ALT_BN128_PAIRING_CHECK_ADDRESS". +Axiom __init___ECRECOVER_ADDRESS : + IsGlobalAlias globals __init__.globals "ECRECOVER_ADDRESS". +Axiom __init___IDENTITY_ADDRESS : + IsGlobalAlias globals __init__.globals "IDENTITY_ADDRESS". +Axiom __init___MODEXP_ADDRESS : + IsGlobalAlias globals __init__.globals "MODEXP_ADDRESS". +Axiom __init___RIPEMD160_ADDRESS : + IsGlobalAlias globals __init__.globals "RIPEMD160_ADDRESS". +Axiom __init___SHA256_ADDRESS : + IsGlobalAlias globals __init__.globals "SHA256_ADDRESS". + +Require alt_bn128. +Axiom alt_bn128_alt_bn128_add : + IsGlobalAlias globals alt_bn128.globals "alt_bn128_add". +Axiom alt_bn128_alt_bn128_mul : + IsGlobalAlias globals alt_bn128.globals "alt_bn128_mul". +Axiom alt_bn128_alt_bn128_pairing_check : + IsGlobalAlias globals alt_bn128.globals "alt_bn128_pairing_check". + +Require ecrecover. +Axiom ecrecover_ecrecover : + IsGlobalAlias globals ecrecover.globals "ecrecover". + +Require identity. +Axiom identity_identity : + IsGlobalAlias globals identity.globals "identity". + +Require modexp. +Axiom modexp_modexp : + IsGlobalAlias globals modexp.globals "modexp". + +Require ripemd160. +Axiom ripemd160_ripemd160 : + IsGlobalAlias globals ripemd160.globals "ripemd160". + +Require sha256. +Axiom sha256_sha256 : + IsGlobalAlias globals sha256.globals "sha256". + +(* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/modexp.v new file mode 100644 index 0000000..39ce4f9 --- /dev/null +++ b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/modexp.v @@ -0,0 +1,506 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) MODEXP PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `MODEXP` precompiled contract. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require memory. +Axiom memory_buffer_read : + IsGlobalAlias globals memory.globals "buffer_read". + +Definition GQUADDIVISOR : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 20 + ], + make_dict [] + |) +)). + +Definition modexp : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Calculates `(base**exp) % modulus` for arbitrary sized `base`, `exp` and. + `modulus`. The return value is the same length as the modulus. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let base_length := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exp_length := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let modulus_length := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exp_start := + BinOp.add (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |), + M.get_name (| globals, "base_length" |) + |) in + let exp_head := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.get_name (| globals, "exp_start" |); + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.get_name (| globals, "exp_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "exp_length" |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let adjusted_exp_length := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "max" |), + make_list [ + Constant.int 0; + BinOp.sub (| + M.call (| + M.get_field (| M.get_name (| globals, "exp_head" |), "bit_length" |), + make_list [], + make_dict [] + |), + Constant.int 1 + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let adjusted_exp_length := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 8, + BinOp.sub (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "exp_length" |) + ], + make_dict [] + |), + Constant.int 32 + |) + |), + M.call (| + M.get_name (| globals, "max" |), + make_list [ + Constant.int 0; + BinOp.sub (| + M.call (| + M.get_field (| M.get_name (| globals, "exp_head" |), "bit_length" |), + make_list [], + make_dict [] + |), + Constant.int 1 + |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.floor_div (| + BinOp.mult (| + M.call (| + M.get_name (| globals, "get_mult_complexity" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "max" |), + make_list [ + M.get_name (| globals, "base_length" |); + M.get_name (| globals, "modulus_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "max" |), + make_list [ + M.get_name (| globals, "adjusted_exp_length" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + ], + make_dict [] + |) + |), + M.get_name (| globals, "GQUADDIVISOR" |) + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_name (| globals, "base_length" |), Constant.int 0 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "modulus_length" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [], + make_dict [] + |) + |) in + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let base := + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |); + M.get_name (| globals, "base_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exp := + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.get_name (| globals, "exp_start" |); + M.get_name (| globals, "exp_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let modulus_start := + BinOp.add (| + M.get_name (| globals, "exp_start" |), + M.get_name (| globals, "exp_length" |) + |) in + let modulus := + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.get_name (| globals, "modulus_start" |); + M.get_name (| globals, "modulus_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "modulus" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + BinOp.mult (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |), + M.get_name (| globals, "modulus_length" |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pow" |), + make_list [ + M.get_name (| globals, "base" |); + M.get_name (| globals, "exp" |); + M.get_name (| globals, "modulus" |) + ], + make_dict [] + |) + ], + make_dict [] + |), "to_bytes" |), + make_list [ + M.get_name (| globals, "modulus_length" |); + Constant.str "big" + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition get_mult_complexity : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "x" ] |) in + let _ := Constant.str " + Estimate the complexity of performing Karatsuba multiplication. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| M.get_name (| globals, "x" |), Constant.int 64 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.pow (| + M.get_name (| globals, "x" |), + Constant.int 2 + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| M.get_name (| globals, "x" |), Constant.int 1024 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.sub (| + BinOp.add (| + BinOp.floor_div (| + BinOp.pow (| + M.get_name (| globals, "x" |), + Constant.int 2 + |), + Constant.int 4 + |), + BinOp.mult (| + Constant.int 96, + M.get_name (| globals, "x" |) + |) + |), + Constant.int 3072 + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.sub (| + BinOp.add (| + BinOp.floor_div (| + BinOp.pow (| + M.get_name (| globals, "x" |), + Constant.int 2 + |), + Constant.int 16 + |), + BinOp.mult (| + Constant.int 480, + M.get_name (| globals, "x" |) + |) + |), + Constant.int 199680 + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/ripemd160.v new file mode 100644 index 0000000..96f8dcd --- /dev/null +++ b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/ripemd160.v @@ -0,0 +1,122 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) RIPEMD160 PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `RIPEMD160` precompiled contract. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_left_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_RIPEMD160 : + IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160". +Axiom vm_gas_GAS_RIPEMD160_WORD : + IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160_WORD". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition ripemd160 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the ripemd160 hash to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let word_count := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_RIPEMD160" |), + BinOp.mult (| + M.get_name (| globals, "GAS_RIPEMD160_WORD" |), + M.get_name (| globals, "word_count" |) + |) + |) + ], + make_dict [] + |) in + let hash_bytes := + M.call (| + M.get_field (| M.call (| + M.get_field (| M.get_name (| globals, "hashlib" |), "new" |), + make_list [ + Constant.str "ripemd160"; + M.get_name (| globals, "data" |) + ], + make_dict [] + |), "digest" |), + make_list [], + make_dict [] + |) in + let padded_hash := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "hash_bytes" |); + Constant.int 32 + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.get_name (| globals, "padded_hash" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/sha256.v new file mode 100644 index 0000000..9f6d2bf --- /dev/null +++ b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/sha256.v @@ -0,0 +1,106 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) SHA256 PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `SHA256` precompiled contract. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_SHA256 : + IsGlobalAlias globals vm.gas.globals "GAS_SHA256". +Axiom vm_gas_GAS_SHA256_WORD : + IsGlobalAlias globals vm.gas.globals "GAS_SHA256_WORD". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition sha256 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the sha256 hash to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let word_count := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_SHA256" |), + BinOp.mult (| + M.get_name (| globals, "GAS_SHA256_WORD" |), + M.get_name (| globals, "word_count" |) + |) + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_field (| M.get_name (| globals, "hashlib" |), "sha256" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), "digest" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/vm/runtime.v b/CoqOfPython/ethereum/byzantium/vm/runtime.v new file mode 100644 index 0000000..835b46c --- /dev/null +++ b/CoqOfPython/ethereum/byzantium/vm/runtime.v @@ -0,0 +1,125 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Runtime Operations +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Runtime related operations used while executing EVM code. +". + +Require typing. +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require instructions. +Axiom instructions_Ops : + IsGlobalAlias globals instructions.globals "Ops". + +Definition get_valid_jump_destinations : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "code" ] |) in + let _ := Constant.str " + Analyze the evm code to obtain the set of valid jump destinations. + + Valid jump destinations are defined as follows: + * The jump destination is less than the length of the code. + * The jump destination should have the `JUMPDEST` opcode (0x5B). + * The jump destination shouldn't be part of the data corresponding to + `PUSH-N` opcodes. + + Note - Jump destinations are 0-indexed. + + Parameters + ---------- + code : + The EVM code which is to be executed. + + Returns + ------- + valid_jump_destinations: `Set[Uint]` + The set of valid jump destinations in the code. + " in + let valid_jump_destinations := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let pc := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + While Compare.lt (| M.get_name (| globals, "pc" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) |) do +(* At stmt: unsupported node type: Try *) + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "current_opcode" |), M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), + make_list [ + M.get_name (| globals, "pc" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + (* At expr: unsupported node type: Compare *), + (* then *) + ltac:(M.monadic ( + let push_data_size := + BinOp.add (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) + |), + Constant.int 1 + |) in + let pc := BinOp.add + M.get_name (| globals, "push_data_size" |) + M.get_name (| globals, "push_data_size" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let pc := BinOp.add + Constant.int 1 + Constant.int 1 in + EndWhile. + let _ := M.return_ (| + M.get_name (| globals, "valid_jump_destinations" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/vm/stack.v b/CoqOfPython/ethereum/byzantium/vm/stack.v new file mode 100644 index 0000000..42ea42d --- /dev/null +++ b/CoqOfPython/ethereum/byzantium/vm/stack.v @@ -0,0 +1,120 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Stack +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the stack operators for the EVM. +". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require exceptions. +Axiom exceptions_StackOverflowError : + IsGlobalAlias globals exceptions.globals "StackOverflowError". +Axiom exceptions_StackUnderflowError : + IsGlobalAlias globals exceptions.globals "StackUnderflowError". + +Definition pop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "stack" ] |) in + let _ := Constant.str " + Pops the top item off of `stack`. + + Parameters + ---------- + stack : + EVM stack. + + Returns + ------- + value : `U256` + The top element on the stack. + + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "StackUnderflowError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "pop" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition push : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "stack"; "value" ] |) in + let _ := Constant.str " + Pushes `value` onto `stack`. + + Parameters + ---------- + stack : + EVM stack. + + value : + Item to be pushed onto `stack`. + + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), Constant.int 1024 |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "StackOverflowError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "append" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/__init__.v b/CoqOfPython/ethereum/cancun/__init__.v new file mode 100644 index 0000000..17b03d0 --- /dev/null +++ b/CoqOfPython/ethereum/cancun/__init__.v @@ -0,0 +1,25 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +The Cancun fork introduces transient storage, exposes beacon chain roots, +introduces a new blob-carrying transaction type, adds a memory copying +instruction, limits self-destruct to only work for contracts created in the +same transaction, and adds an instruction to read the blob base fee. +". + +Require ethereum.fork_criteria. +Axiom ethereum_fork_criteria_ByTimestamp : + IsGlobalAlias globals ethereum.fork_criteria.globals "ByTimestamp". + +Definition FORK_CRITERIA : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "ByTimestamp" |), + make_list [ + Constant.int 1710338135 + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/cancun/blocks.v b/CoqOfPython/ethereum/cancun/blocks.v new file mode 100644 index 0000000..2130667 --- /dev/null +++ b/CoqOfPython/ethereum/cancun/blocks.v @@ -0,0 +1,107 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +A `Block` is a single link in the chain that is Ethereum. Each `Block` contains +a `Header` and zero or more transactions. Each `Header` contains associated +metadata like the block number, parent block hash, and how much gas was +consumed by its transactions. + +Together, these blocks form a cryptographically secure journal recording the +history of all state transitions that have happened since the genesis of the +chain. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require base_types. +Axiom base_types_U64 : + IsGlobalAlias globals base_types.globals "U64". +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes8 : + IsGlobalAlias globals base_types.globals "Bytes8". +Axiom base_types_Bytes32 : + IsGlobalAlias globals base_types.globals "Bytes32". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require crypto.hash. +Axiom crypto_hash_Hash32 : + IsGlobalAlias globals crypto.hash.globals "Hash32". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Require transactions. +Axiom transactions_LegacyTransaction : + IsGlobalAlias globals transactions.globals "LegacyTransaction". + +Definition Withdrawal : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Header : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Block : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Log : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Receipt : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. diff --git a/CoqOfPython/ethereum/cancun/bloom.v b/CoqOfPython/ethereum/cancun/bloom.v new file mode 100644 index 0000000..04b5d9f --- /dev/null +++ b/CoqOfPython/ethereum/cancun/bloom.v @@ -0,0 +1,164 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Logs Bloom +^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +This modules defines functions for calculating bloom filters of logs. For the +general theory of bloom filters see e.g. `Wikipedia +`_. Bloom filters are used to allow +for efficient searching of logs by address and/or topic, by rapidly +eliminating blocks and receipts from their search. +". + +Require typing. +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require fork_types. +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". + +Definition add_to_bloom : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "bloom"; "bloom_entry" ] |) in + let _ := Constant.str " + Add a bloom entry to the bloom filter (`bloom`). + + The number of hash functions used is 3. They are calculated by taking the + least significant 11 bits from the first 3 16-bit words of the + `keccak_256()` hash of `bloom_entry`. + + Parameters + ---------- + bloom : + The bloom filter. + bloom_entry : + An entry which is to be added to bloom filter. + " in + let hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "bloom_entry" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "idx" |) in make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ] do + let bit_to_set := + BinOp.bit_and (| + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |):BinOp.add (| + M.get_name (| globals, "idx" |), + Constant.int 2 + |) |) + ], + make_dict [] + |), + Constant.int 2047 + |) in + let bit_index := + BinOp.sub (| + Constant.int 2047, + M.get_name (| globals, "bit_to_set" |) + |) in + let byte_index := + BinOp.floor_div (| + M.get_name (| globals, "bit_index" |), + Constant.int 8 + |) in + let bit_value := + BinOp.l_shift (| + Constant.int 1, + BinOp.sub (| + Constant.int 7, + BinOp.mod_ (| + M.get_name (| globals, "bit_index" |), + Constant.int 8 + |) + |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), + BinOp.bit_or (| + M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), + M.get_name (| globals, "bit_value" |) + |) + |) in + EndFor. + M.pure Constant.None_)). + +Definition logs_bloom : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "logs" ] |) in + let _ := Constant.str " + Obtain the logs bloom from a list of log entries. + + The address and each topic of a log are added to the bloom filter. + + Parameters + ---------- + logs : + List of logs for which the logs bloom is to be obtained. + + Returns + ------- + logs_bloom : `Bloom` + The logs bloom obtained which is 256 bytes with some bits set as per + the caller address and the log topics. + " in +(* At stmt: unsupported node type: AnnAssign *) + For M.get_name (| globals, "log" |) in M.get_name (| globals, "logs" |) do + let _ := M.call (| + M.get_name (| globals, "add_to_bloom" |), + make_list [ + M.get_name (| globals, "bloom" |); + M.get_field (| M.get_name (| globals, "log" |), "address" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "topic" |) in M.get_field (| M.get_name (| globals, "log" |), "topics" |) do + let _ := M.call (| + M.get_name (| globals, "add_to_bloom" |), + make_list [ + M.get_name (| globals, "bloom" |); + M.get_name (| globals, "topic" |) + ], + make_dict [] + |) in + EndFor. + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bloom" |), + make_list [ + M.get_name (| globals, "bloom" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/fork.v b/CoqOfPython/ethereum/cancun/fork.v new file mode 100644 index 0000000..21f0a4f --- /dev/null +++ b/CoqOfPython/ethereum/cancun/fork.v @@ -0,0 +1,2788 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Specification +^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Entry point for the Ethereum specification. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". + +Require ethereum.crypto.elliptic_curve. +Axiom ethereum_crypto_elliptic_curve_SECP256K1N : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.exceptions. +Axiom ethereum_exceptions_InvalidBlock : + IsGlobalAlias globals ethereum.exceptions.globals "InvalidBlock". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U64 : + IsGlobalAlias globals base_types.globals "U64". +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". + +Require __init__. +Axiom __init___vm : + IsGlobalAlias globals __init__.globals "vm". + +Require blocks. +Axiom blocks_Block : + IsGlobalAlias globals blocks.globals "Block". +Axiom blocks_Header : + IsGlobalAlias globals blocks.globals "Header". +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". +Axiom blocks_Receipt : + IsGlobalAlias globals blocks.globals "Receipt". +Axiom blocks_Withdrawal : + IsGlobalAlias globals blocks.globals "Withdrawal". + +Require bloom. +Axiom bloom_logs_bloom : + IsGlobalAlias globals bloom.globals "logs_bloom". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". +Axiom fork_types_VersionedHash : + IsGlobalAlias globals fork_types.globals "VersionedHash". + +Require state. +Axiom state_State : + IsGlobalAlias globals state.globals "State". +Axiom state_TransientStorage : + IsGlobalAlias globals state.globals "TransientStorage". +Axiom state_account_exists_and_is_empty : + IsGlobalAlias globals state.globals "account_exists_and_is_empty". +Axiom state_destroy_account : + IsGlobalAlias globals state.globals "destroy_account". +Axiom state_destroy_touched_empty_accounts : + IsGlobalAlias globals state.globals "destroy_touched_empty_accounts". +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". +Axiom state_increment_nonce : + IsGlobalAlias globals state.globals "increment_nonce". +Axiom state_process_withdrawal : + IsGlobalAlias globals state.globals "process_withdrawal". +Axiom state_set_account_balance : + IsGlobalAlias globals state.globals "set_account_balance". +Axiom state_state_root : + IsGlobalAlias globals state.globals "state_root". + +Require transactions. +Axiom transactions_TX_ACCESS_LIST_ADDRESS_COST : + IsGlobalAlias globals transactions.globals "TX_ACCESS_LIST_ADDRESS_COST". +Axiom transactions_TX_ACCESS_LIST_STORAGE_KEY_COST : + IsGlobalAlias globals transactions.globals "TX_ACCESS_LIST_STORAGE_KEY_COST". +Axiom transactions_TX_BASE_COST : + IsGlobalAlias globals transactions.globals "TX_BASE_COST". +Axiom transactions_TX_CREATE_COST : + IsGlobalAlias globals transactions.globals "TX_CREATE_COST". +Axiom transactions_TX_DATA_COST_PER_NON_ZERO : + IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_NON_ZERO". +Axiom transactions_TX_DATA_COST_PER_ZERO : + IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_ZERO". +Axiom transactions_AccessListTransaction : + IsGlobalAlias globals transactions.globals "AccessListTransaction". +Axiom transactions_BlobTransaction : + IsGlobalAlias globals transactions.globals "BlobTransaction". +Axiom transactions_FeeMarketTransaction : + IsGlobalAlias globals transactions.globals "FeeMarketTransaction". +Axiom transactions_LegacyTransaction : + IsGlobalAlias globals transactions.globals "LegacyTransaction". +Axiom transactions_Transaction : + IsGlobalAlias globals transactions.globals "Transaction". +Axiom transactions_decode_transaction : + IsGlobalAlias globals transactions.globals "decode_transaction". +Axiom transactions_encode_transaction : + IsGlobalAlias globals transactions.globals "encode_transaction". + +Require trie. +Axiom trie_Trie : + IsGlobalAlias globals trie.globals "Trie". +Axiom trie_root : + IsGlobalAlias globals trie.globals "root". +Axiom trie_trie_set : + IsGlobalAlias globals trie.globals "trie_set". + +Require utils.hexadecimal. +Axiom utils_hexadecimal_hex_to_address : + IsGlobalAlias globals utils.hexadecimal.globals "hex_to_address". + +Require utils.message. +Axiom utils_message_prepare_message : + IsGlobalAlias globals utils.message.globals "prepare_message". + +Require vm. +Axiom vm_Message : + IsGlobalAlias globals vm.globals "Message". + +Require vm.gas. +Axiom vm_gas_calculate_blob_gas_price : + IsGlobalAlias globals vm.gas.globals "calculate_blob_gas_price". +Axiom vm_gas_calculate_data_fee : + IsGlobalAlias globals vm.gas.globals "calculate_data_fee". +Axiom vm_gas_calculate_excess_blob_gas : + IsGlobalAlias globals vm.gas.globals "calculate_excess_blob_gas". +Axiom vm_gas_calculate_total_blob_gas : + IsGlobalAlias globals vm.gas.globals "calculate_total_blob_gas". +Axiom vm_gas_init_code_cost : + IsGlobalAlias globals vm.gas.globals "init_code_cost". + +Require vm.interpreter. +Axiom vm_interpreter_MAX_CODE_SIZE : + IsGlobalAlias globals vm.interpreter.globals "MAX_CODE_SIZE". +Axiom vm_interpreter_process_message_call : + IsGlobalAlias globals vm.interpreter.globals "process_message_call". + +Definition BASE_FEE_MAX_CHANGE_DENOMINATOR : Value.t := M.run ltac:(M.monadic ( + Constant.int 8 +)). + +Definition ELASTICITY_MULTIPLIER : Value.t := M.run ltac:(M.monadic ( + Constant.int 2 +)). + +Definition GAS_LIMIT_ADJUSTMENT_FACTOR : Value.t := M.run ltac:(M.monadic ( + Constant.int 1024 +)). + +Definition GAS_LIMIT_MINIMUM : Value.t := M.run ltac:(M.monadic ( + Constant.int 5000 +)). + +Definition EMPTY_OMMER_HASH : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_list [] + ], + make_dict [] + |) + ], + make_dict [] + |) +)). + +Definition SYSTEM_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0xfffffffffffffffffffffffffffffffffffffffe" + ], + make_dict [] + |) +)). + +Definition BEACON_ROOTS_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02" + ], + make_dict [] + |) +)). + +Definition SYSTEM_TRANSACTION_GAS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 30000000 + ], + make_dict [] + |) +)). + +Definition MAX_BLOB_GAS_PER_BLOCK : Value.t := M.run ltac:(M.monadic ( + Constant.int 786432 +)). + +Definition VERSIONED_HASH_VERSION_KZG : Value.t := M.run ltac:(M.monadic ( + (* At constant: unsupported node type: Constant *) +)). + +Definition BlockChain : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition apply_fork : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "old" ] |) in + let _ := Constant.str " + Transforms the state from the previous hard fork (`old`) into the block + chain object for this hard fork and returns it. + + When forks need to implement an irregular state transition, this function + is used to handle the irregularity. See the :ref:`DAO Fork ` for + an example. + + Parameters + ---------- + old : + Previous block chain object. + + Returns + ------- + new : `BlockChain` + Upgraded block chain object for this hard fork. + " in + let _ := M.return_ (| + M.get_name (| globals, "old" |) + |) in + M.pure Constant.None_)). + +Definition get_last_256_block_hashes : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "chain" ] |) in + let _ := Constant.str " + Obtain the list of hashes of the previous 256 blocks in order of + increasing block number. + + This function will return less hashes for the first 256 blocks. + + The ``BLOCKHASH`` opcode needs to access the latest hashes on the chain, + therefore this function retrieves them. + + Parameters + ---------- + chain : + History and current state. + + Returns + ------- + recent_block_hashes : `List[Hash32]` + Hashes of the recent 256 blocks in order of increasing block number. + " in + let recent_blocks := + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |):(* At expr: unsupported node type: NoneType *) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "recent_blocks" |) + ], + make_dict [] + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + make_list [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let recent_block_hashes := + make_list [] in + For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_blocks" |) do + let prev_block_hash := + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), + make_list [ + M.get_name (| globals, "prev_block_hash" |) + ], + make_dict [] + |) in + EndFor. + let most_recent_block_hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_field (| M.get_subscript (| M.get_name (| globals, "recent_blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), + make_list [ + M.get_name (| globals, "most_recent_block_hash" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "recent_block_hashes" |) + |) in + M.pure Constant.None_)). + +Definition state_transition : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "chain"; "block" ] |) in + let _ := Constant.str " + Attempts to apply a block to an existing block chain. + + All parts of the block's contents need to be verified before being added + to the chain. Blocks are verified by ensuring that the contents of the + block make logical sense with the contents of the parent block. The + information in the block's header must also match the corresponding + information in the block. + + To implement Ethereum, in theory clients are only required to store the + most recent 255 blocks of the chain since as far as execution is + concerned, only those blocks are accessed. Practically, however, clients + should store more blocks to handle reorgs. + + Parameters + ---------- + chain : + History and current state. + block : + Block to apply to `chain`. + " in + let parent_header := + M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) in + let excess_blob_gas := + M.call (| + M.get_name (| globals, "calculate_excess_blob_gas" |), + make_list [ + M.get_name (| globals, "parent_header" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "excess_blob_gas" |), M.get_name (| globals, "excess_blob_gas" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "validate_header" |), + make_list [ + M.get_field (| M.get_name (| globals, "block" |), "header" |); + M.get_name (| globals, "parent_header" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "block" |), "ommers" |), make_tuple [ ] |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let apply_body_output := + M.call (| + M.get_name (| globals, "apply_body" |), + make_list [ + M.get_field (| M.get_name (| globals, "chain" |), "state" |); + M.call (| + M.get_name (| globals, "get_last_256_block_hashes" |), + make_list [ + M.get_name (| globals, "chain" |) + ], + make_dict [] + |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "coinbase" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "number" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "base_fee_per_gas" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "gas_limit" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "timestamp" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "prev_randao" |); + M.get_field (| M.get_name (| globals, "block" |), "transactions" |); + M.get_field (| M.get_name (| globals, "chain" |), "chain_id" |); + M.get_field (| M.get_name (| globals, "block" |), "withdrawals" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_beacon_block_root" |); + M.get_name (| globals, "excess_blob_gas" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_gas_used" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "gas_used" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "transactions_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "transactions_root" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "state_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "state_root" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "receipt_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "receipt_root" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_logs_bloom" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "bloom" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "withdrawals_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "withdrawals_root" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "blob_gas_used" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "blob_gas_used" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), "append" |), + make_list [ + M.get_name (| globals, "block" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |) + ], + make_dict [] + |), Constant.int 255 |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |):(* At expr: unsupported node type: NoneType *) |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "block_gas_limit"; "parent_gas_limit"; "parent_gas_used"; "parent_base_fee_per_gas" ] |) in + let _ := Constant.str " + Calculates the base fee per gas for the block. + + Parameters + ---------- + block_gas_limit : + Gas limit of the block for which the base fee is being calculated. + parent_gas_limit : + Gas limit of the parent block. + parent_gas_used : + Gas used in the parent block. + parent_base_fee_per_gas : + Base fee per gas of the parent block. + + Returns + ------- + base_fee_per_gas : `Uint` + Base fee per gas for the block. + " in + let parent_gas_target := + BinOp.floor_div (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "ELASTICITY_MULTIPLIER" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + M.call (| + M.get_name (| globals, "check_gas_limit" |), + make_list [ + M.get_name (| globals, "block_gas_limit" |); + M.get_name (| globals, "parent_gas_limit" |) + ], + make_dict [] + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "parent_gas_used" |), M.get_name (| globals, "parent_gas_target" |) |), + (* then *) + ltac:(M.monadic ( + let expected_base_fee_per_gas := + M.get_name (| globals, "parent_base_fee_per_gas" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "parent_gas_used" |), M.get_name (| globals, "parent_gas_target" |) |), + (* then *) + ltac:(M.monadic ( + let gas_used_delta := + BinOp.sub (| + M.get_name (| globals, "parent_gas_used" |), + M.get_name (| globals, "parent_gas_target" |) + |) in + let parent_fee_gas_delta := + BinOp.mult (| + M.get_name (| globals, "parent_base_fee_per_gas" |), + M.get_name (| globals, "gas_used_delta" |) + |) in + let target_fee_gas_delta := + BinOp.floor_div (| + M.get_name (| globals, "parent_fee_gas_delta" |), + M.get_name (| globals, "parent_gas_target" |) + |) in + let base_fee_per_gas_delta := + M.call (| + M.get_name (| globals, "max" |), + make_list [ + BinOp.floor_div (| + M.get_name (| globals, "target_fee_gas_delta" |), + M.get_name (| globals, "BASE_FEE_MAX_CHANGE_DENOMINATOR" |) + |); + Constant.int 1 + ], + make_dict [] + |) in + let expected_base_fee_per_gas := + BinOp.add (| + M.get_name (| globals, "parent_base_fee_per_gas" |), + M.get_name (| globals, "base_fee_per_gas_delta" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let gas_used_delta := + BinOp.sub (| + M.get_name (| globals, "parent_gas_target" |), + M.get_name (| globals, "parent_gas_used" |) + |) in + let parent_fee_gas_delta := + BinOp.mult (| + M.get_name (| globals, "parent_base_fee_per_gas" |), + M.get_name (| globals, "gas_used_delta" |) + |) in + let target_fee_gas_delta := + BinOp.floor_div (| + M.get_name (| globals, "parent_fee_gas_delta" |), + M.get_name (| globals, "parent_gas_target" |) + |) in + let base_fee_per_gas_delta := + BinOp.floor_div (| + M.get_name (| globals, "target_fee_gas_delta" |), + M.get_name (| globals, "BASE_FEE_MAX_CHANGE_DENOMINATOR" |) + |) in + let expected_base_fee_per_gas := + BinOp.sub (| + M.get_name (| globals, "parent_base_fee_per_gas" |), + M.get_name (| globals, "base_fee_per_gas_delta" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "expected_base_fee_per_gas" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition validate_header : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header"; "parent_header" ] |) in + let _ := Constant.str " + Verifies a block header. + + In order to consider a block's header valid, the logic for the + quantities in the header should match the logic for the block itself. + For example the header timestamp should be greater than the block's parent + timestamp because the block was created *after* the parent block. + Additionally, the block's number should be directly following the parent + block's number since it is the next block in the sequence. + + Parameters + ---------- + header : + Header to check for correctness. + parent_header : + Parent Header of the header to check for correctness + " in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| M.get_field (| M.get_name (| globals, "header" |), "gas_used" |), M.get_field (| M.get_name (| globals, "header" |), "gas_limit" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let expected_base_fee_per_gas := + M.call (| + M.get_name (| globals, "calculate_base_fee_per_gas" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "gas_limit" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "gas_limit" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "gas_used" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "base_fee_per_gas" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_name (| globals, "expected_base_fee_per_gas" |), M.get_field (| M.get_name (| globals, "header" |), "base_fee_per_gas" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt (| M.get_field (| M.get_name (| globals, "header" |), "timestamp" |), M.get_field (| M.get_name (| globals, "parent_header" |), "timestamp" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "number" |), BinOp.add (| + M.get_field (| M.get_name (| globals, "parent_header" |), "number" |), + Constant.int 1 + |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) + ], + make_dict [] + |), Constant.int 32 |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "difficulty" |), Constant.int 0 |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "nonce" |), (* At constant: unsupported node type: Constant *) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "ommers_hash" |), M.get_name (| globals, "EMPTY_OMMER_HASH" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let block_parent_hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "parent_header" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |), M.get_name (| globals, "block_parent_hash" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition check_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "tx"; "gas_available"; "chain_id"; "base_fee_per_gas"; "excess_blob_gas" ] |) in + let _ := Constant.str " + Check if the transaction is includable in the block. + + Parameters + ---------- + state : + Current state. + tx : + The transaction. + gas_available : + The gas remaining in the block. + chain_id : + The ID of the current chain. + base_fee_per_gas : + The block base fee. + excess_blob_gas : + The excess blob gas. + + Returns + ------- + sender_address : + The sender of the transaction. + effective_gas_price : + The price to charge for gas when the transaction is executed. + blob_versioned_hashes : + The blob versioned hashes of the transaction. + + Raises + ------ + InvalidBlock : + If the transaction is not includable. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.call (| + M.get_name (| globals, "calculate_intrinsic_cost" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |), M.get_field (| M.get_name (| globals, "tx" |), "gas" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidBlock" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_field (| M.get_name (| globals, "tx" |), "nonce" |), BinOp.sub (| + BinOp.pow (| + Constant.int 2, + Constant.int 64 + |), + Constant.int 1 + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidBlock" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "tx" |), "to" |), M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.gt (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "tx" |), "data" |) + ], + make_dict [] + |), BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "MAX_CODE_SIZE" |) + |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidBlock" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_name (| globals, "gas_available" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidBlock" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let sender := + M.call (| + M.get_name (| globals, "recover_sender" |), + make_list [ + M.get_name (| globals, "chain_id" |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) in + let sender_account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + make_tuple [ M.get_name (| globals, "FeeMarketTransaction" |); M.get_name (| globals, "BlobTransaction" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |), M.get_field (| M.get_name (| globals, "tx" |), "max_priority_fee_per_gas" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidBlock" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |), M.get_name (| globals, "base_fee_per_gas" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidBlock" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let priority_fee_per_gas := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_field (| M.get_name (| globals, "tx" |), "max_priority_fee_per_gas" |); + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |), + M.get_name (| globals, "base_fee_per_gas" |) + |) + ], + make_dict [] + |) in + let effective_gas_price := + BinOp.add (| + M.get_name (| globals, "priority_fee_per_gas" |), + M.get_name (| globals, "base_fee_per_gas" |) + |) in + let max_gas_fee := + BinOp.mult (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |), M.get_name (| globals, "base_fee_per_gas" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidBlock" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let effective_gas_price := + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) in + let max_gas_fee := + BinOp.mult (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) + |) in + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "BlobTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_field (| M.get_name (| globals, "tx" |), "to" |); + M.get_name (| globals, "Address" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidBlock" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "tx" |), "blob_versioned_hashes" |) + ], + make_dict [] + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidBlock" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + For M.get_name (| globals, "blob_versioned_hash" |) in M.get_field (| M.get_name (| globals, "tx" |), "blob_versioned_hashes" |) do + let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| M.get_subscript (| M.get_name (| globals, "blob_versioned_hash" |), Constant.int 0:Constant.int 1 |), M.get_name (| globals, "VERSIONED_HASH_VERSION_KZG" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidBlock" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_blob_gas" |), M.call (| + M.get_name (| globals, "calculate_blob_gas_price" |), + make_list [ + M.get_name (| globals, "excess_blob_gas" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidBlock" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let max_gas_fee := BinOp.add + BinOp.mult (| + M.call (| + M.get_name (| globals, "calculate_total_blob_gas" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |), + M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_blob_gas" |) + |) + BinOp.mult (| + M.call (| + M.get_name (| globals, "calculate_total_blob_gas" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |), + M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_blob_gas" |) + |) in + let blob_versioned_hashes := + M.get_field (| M.get_name (| globals, "tx" |), "blob_versioned_hashes" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let blob_versioned_hashes := + make_tuple [ ] in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "sender_account" |), "nonce" |), M.get_field (| M.get_name (| globals, "tx" |), "nonce" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt_e (| M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), BinOp.add (| + M.get_name (| globals, "max_gas_fee" |), + M.get_field (| M.get_name (| globals, "tx" |), "value" |) + |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "sender_account" |), "code" |), M.call (| + M.get_name (| globals, "bytearray" |), + make_list [], + make_dict [] + |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + make_tuple [ M.get_name (| globals, "sender" |); M.get_name (| globals, "effective_gas_price" |); M.get_name (| globals, "blob_versioned_hashes" |) ] + |) in + M.pure Constant.None_)). + +Definition make_receipt : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx"; "error"; "cumulative_gas_used"; "logs" ] |) in + let _ := Constant.str " + Make the receipt for a transaction that was executed. + + Parameters + ---------- + tx : + The executed transaction. + error : + Error in the top level frame of the transaction, if any. + cumulative_gas_used : + The total gas used so far in the block after the transaction was + executed. + logs : + The logs produced by the transaction. + + Returns + ------- + receipt : + The receipt for the transaction. + " in + let receipt := + M.call (| + M.get_name (| globals, "Receipt" |), + make_list [], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "AccessListTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + (* At constant: unsupported node type: Constant *), + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "receipt" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "FeeMarketTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + (* At constant: unsupported node type: Constant *), + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "receipt" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "BlobTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + (* At constant: unsupported node type: Constant *), + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "receipt" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "receipt" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition ApplyBodyOutput : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition apply_body : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "block_hashes"; "coinbase"; "block_number"; "base_fee_per_gas"; "block_gas_limit"; "block_time"; "prev_randao"; "transactions"; "chain_id"; "withdrawals"; "parent_beacon_block_root"; "excess_blob_gas" ] |) in + let _ := Constant.str " + Executes a block. + + Many of the contents of a block are stored in data structures called + tries. There is a transactions trie which is similar to a ledger of the + transactions stored in the current block. There is also a receipts trie + which stores the results of executing a transaction, like the post state + and gas used. This function creates and executes the block that is to be + added to the chain. + + Parameters + ---------- + state : + Current account state. + block_hashes : + List of hashes of the previous 256 blocks in the order of + increasing block number. + coinbase : + Address of account which receives block reward and transaction fees. + block_number : + Position of the block within the chain. + base_fee_per_gas : + Base fee per gas of within the block. + block_gas_limit : + Initial amount of gas available for execution in this block. + block_time : + Time the block was produced, measured in seconds since the epoch. + prev_randao : + The previous randao from the beacon chain. + transactions : + Transactions included in the block. + ommers : + Headers of ancestor blocks which are not direct parents (formerly + uncles.) + chain_id : + ID of the executing chain. + withdrawals : + Withdrawals to be processed in the current block. + parent_beacon_block_root : + The root of the beacon block from the parent block. + excess_blob_gas : + Excess blob gas calculated from the previous block. + + Returns + ------- + apply_body_output : `ApplyBodyOutput` + Output of applying the block body to the state. + " in + let blob_gas_used := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let gas_available := + M.get_name (| globals, "block_gas_limit" |) in +(* At stmt: unsupported node type: AnnAssign *) +(* At stmt: unsupported node type: AnnAssign *) +(* At stmt: unsupported node type: AnnAssign *) +(* At stmt: unsupported node type: AnnAssign *) + let beacon_block_roots_contract_code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "BEACON_ROOTS_ADDRESS" |) + ], + make_dict [] + |), "code" |) in + let system_tx_message := + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) in + let system_tx_env := + M.call (| + M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), + make_list [], + make_dict [] + |) in + let system_tx_output := + M.call (| + M.get_name (| globals, "process_message_call" |), + make_list [ + M.get_name (| globals, "system_tx_message" |); + M.get_name (| globals, "system_tx_env" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "destroy_touched_empty_accounts" |), + make_list [ + M.get_field (| M.get_name (| globals, "system_tx_env" |), "state" |); + M.get_field (| M.get_name (| globals, "system_tx_output" |), "touched_accounts" |) + ], + make_dict [] + |) in + For make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "tx" |) ] in M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.call (| + M.get_name (| globals, "map" |), + make_list [ + M.get_name (| globals, "decode_transaction" |); + M.get_name (| globals, "transactions" |) + ], + make_dict [] + |) + ], + make_dict [] + |) do + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "transactions_trie" |); + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "i" |) + ], + make_dict [] + |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "encode_transaction" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "sender_address" |); M.get_name (| globals, "effective_gas_price" |); M.get_name (| globals, "blob_versioned_hashes" |) ], + M.call (| + M.get_name (| globals, "check_transaction" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "tx" |); + M.get_name (| globals, "gas_available" |); + M.get_name (| globals, "chain_id" |); + M.get_name (| globals, "base_fee_per_gas" |); + M.get_name (| globals, "excess_blob_gas" |) + ], + make_dict [] + |) + |) in + let env := + M.call (| + M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |); M.get_name (| globals, "error" |) ], + M.call (| + M.get_name (| globals, "process_transaction" |), + make_list [ + M.get_name (| globals, "env" |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) in + let gas_available := BinOp.sub + M.get_name (| globals, "gas_used" |) + M.get_name (| globals, "gas_used" |) in + let receipt := + M.call (| + M.get_name (| globals, "make_receipt" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "error" |); + BinOp.sub (| + M.get_name (| globals, "block_gas_limit" |), + M.get_name (| globals, "gas_available" |) + |); + M.get_name (| globals, "logs" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "receipts_trie" |); + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "i" |) + ], + make_dict [] + |) + ], + make_dict [] + |); + M.get_name (| globals, "receipt" |) + ], + make_dict [] + |) in + let block_logs := BinOp.add + M.get_name (| globals, "logs" |) + M.get_name (| globals, "logs" |) in + let blob_gas_used := BinOp.add + M.call (| + M.get_name (| globals, "calculate_total_blob_gas" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + M.call (| + M.get_name (| globals, "calculate_total_blob_gas" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) in + EndFor. + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| M.get_name (| globals, "blob_gas_used" |), M.get_name (| globals, "MAX_BLOB_GAS_PER_BLOCK" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let block_gas_used := + BinOp.sub (| + M.get_name (| globals, "block_gas_limit" |), + M.get_name (| globals, "gas_available" |) + |) in + let block_logs_bloom := + M.call (| + M.get_name (| globals, "logs_bloom" |), + make_list [ + M.get_name (| globals, "block_logs" |) + ], + make_dict [] + |) in + For make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "wd" |) ] in M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "withdrawals" |) + ], + make_dict [] + |) do + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "withdrawals_trie" |); + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "i" |) + ], + make_dict [] + |) + ], + make_dict [] + |); + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "wd" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "process_withdrawal" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "wd" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_field (| M.get_name (| globals, "wd" |), "address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_field (| M.get_name (| globals, "wd" |), "address" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ApplyBodyOutput" |), + make_list [ + M.get_name (| globals, "block_gas_used" |); + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_name (| globals, "transactions_trie" |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_name (| globals, "receipts_trie" |) + ], + make_dict [] + |); + M.get_name (| globals, "block_logs_bloom" |); + M.call (| + M.get_name (| globals, "state_root" |), + make_list [ + M.get_name (| globals, "state" |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_name (| globals, "withdrawals_trie" |) + ], + make_dict [] + |); + M.get_name (| globals, "blob_gas_used" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition process_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "env"; "tx" ] |) in + let _ := Constant.str " + Execute a transaction against the provided environment. + + This function processes the actions needed to execute a transaction. + It decrements the sender's account after calculating the gas fee and + refunds them the proper amount after execution. Calling contracts, + deploying code, and incrementing nonces are all examples of actions that + happen within this function or from a call made within this function. + + Accounts that are marked for deletion are processed and destroyed after + execution. + + Parameters + ---------- + env : + Environment for the Ethereum Virtual Machine. + tx : + Transaction to execute. + + Returns + ------- + gas_left : `ethereum.base_types.U256` + Remaining gas after execution. + logs : `Tuple[ethereum.blocks.Log, ...]` + Logs generated during execution. + " in + let sender := + M.get_field (| M.get_name (| globals, "env" |), "origin" |) in + let sender_account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "BlobTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let blob_gas_fee := + M.call (| + M.get_name (| globals, "calculate_data_fee" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "excess_blob_gas" |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let blob_gas_fee := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let effective_gas_fee := + BinOp.mult (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "env" |), "gas_price" |) + |) in + let gas := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.call (| + M.get_name (| globals, "calculate_intrinsic_cost" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) in + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |) in + let sender_balance_after_gas_fee := + BinOp.sub (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), + M.get_name (| globals, "effective_gas_fee" |) + |), + M.get_name (| globals, "blob_gas_fee" |) + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |); + M.get_name (| globals, "sender_balance_after_gas_fee" |) + ], + make_dict [] + |) in + let preaccessed_addresses := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let preaccessed_storage_keys := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "preaccessed_addresses" |), "add" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + make_tuple [ M.get_name (| globals, "AccessListTransaction" |); M.get_name (| globals, "FeeMarketTransaction" |); M.get_name (| globals, "BlobTransaction" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + For make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "keys" |) ] in M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "preaccessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "key" |) in M.get_name (| globals, "keys" |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "preaccessed_storage_keys" |), "add" |), + make_list [ + make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "key" |) ] + ], + make_dict [] + |) in + EndFor. + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let message := + M.call (| + M.get_name (| globals, "prepare_message" |), + make_list [ + M.get_name (| globals, "sender" |); + M.get_field (| M.get_name (| globals, "tx" |), "to" |); + M.get_field (| M.get_name (| globals, "tx" |), "value" |); + M.get_field (| M.get_name (| globals, "tx" |), "data" |); + M.get_name (| globals, "gas" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let output := + M.call (| + M.get_name (| globals, "process_message_call" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let gas_used := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "output" |), "gas_left" |) + |) in + let gas_refund := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + BinOp.floor_div (| + M.get_name (| globals, "gas_used" |), + Constant.int 5 + |); + M.get_field (| M.get_name (| globals, "output" |), "refund_counter" |) + ], + make_dict [] + |) in + let gas_refund_amount := + BinOp.mult (| + BinOp.add (| + M.get_field (| M.get_name (| globals, "output" |), "gas_left" |), + M.get_name (| globals, "gas_refund" |) + |), + M.get_field (| M.get_name (| globals, "env" |), "gas_price" |) + |) in + let priority_fee_per_gas := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "env" |), "gas_price" |), + M.get_field (| M.get_name (| globals, "env" |), "base_fee_per_gas" |) + |) in + let transaction_fee := + BinOp.mult (| + BinOp.sub (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "output" |), "gas_left" |) + |), + M.get_name (| globals, "gas_refund" |) + |), + M.get_name (| globals, "priority_fee_per_gas" |) + |) in + let total_gas_used := + BinOp.sub (| + M.get_name (| globals, "gas_used" |), + M.get_name (| globals, "gas_refund" |) + |) in + let sender_balance_after_refund := + BinOp.add (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |), "balance" |), + M.get_name (| globals, "gas_refund_amount" |) + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |); + M.get_name (| globals, "sender_balance_after_refund" |) + ], + make_dict [] + |) in + let coinbase_balance_after_mining_fee := + BinOp.add (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |), "balance" |), + M.get_name (| globals, "transaction_fee" |) + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| M.get_name (| globals, "coinbase_balance_after_mining_fee" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |); + M.get_name (| globals, "coinbase_balance_after_mining_fee" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "accounts_to_delete" |) do + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + EndFor. + let _ := M.call (| + M.get_name (| globals, "destroy_touched_empty_accounts" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "output" |), "touched_accounts" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |); M.get_field (| M.get_name (| globals, "output" |), "error" |) ] + |) in + M.pure Constant.None_)). + +Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Calculates the gas that is charged before execution is started. + + The intrinsic cost of the transaction is charged before execution has + begun. Functions/operations in the EVM cost money to execute so this + intrinsic cost is for the operations that need to be paid for as part of + the transaction. Data transfer, for example, is part of this intrinsic + cost. It costs ether to send data over the wire and that ether is + accounted for in the intrinsic cost calculated in this function. This + intrinsic cost must be calculated and paid for before execution in order + for all operations to be implemented. + + Parameters + ---------- + tx : + Transaction to compute the intrinsic cost of. + + Returns + ------- + verified : `ethereum.base_types.Uint` + The intrinsic cost of the transaction. + " in + let data_cost := + Constant.int 0 in + For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "byte" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + M.pure Constant.None_ + )) |) in + EndFor. + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_name (| globals, "tx" |), "to" |), M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let create_cost := + BinOp.add (| + M.get_name (| globals, "TX_CREATE_COST" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.call (| + M.get_name (| globals, "init_code_cost" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "tx" |), "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let create_cost := + Constant.int 0 in + M.pure Constant.None_ + )) |) in + let access_list_cost := + Constant.int 0 in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + make_tuple [ M.get_name (| globals, "AccessListTransaction" |); M.get_name (| globals, "FeeMarketTransaction" |); M.get_name (| globals, "BlobTransaction" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + For make_tuple [ M.get_name (| globals, "_address" |); M.get_name (| globals, "keys" |) ] in M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) do + let access_list_cost := BinOp.add + M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) + M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) in + let access_list_cost := BinOp.add + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "keys" |) + ], + make_dict [] + |), + M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) + |) + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "keys" |) + ], + make_dict [] + |), + M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) + |) in + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.add (| + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "TX_BASE_COST" |), + M.get_name (| globals, "data_cost" |) + |), + M.get_name (| globals, "create_cost" |) + |), + M.get_name (| globals, "access_list_cost" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition recover_sender : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "chain_id"; "tx" ] |) in + let _ := Constant.str " + Extracts the sender address from a transaction. + + The v, r, and s values are the three parts that make up the signature + of a transaction. In order to recover the sender of a transaction the two + components needed are the signature (``v``, ``r``, and ``s``) and the + signing hash of the transaction. The sender's public key can be obtained + with these two values and therefore the sender address can be retrieved. + + Parameters + ---------- + tx : + Transaction of interest. + chain_id : + ID of the executing chain. + + Returns + ------- + sender : `ethereum.fork_types.Address` + The address of the account that signed the transaction. + " in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "r" |); M.get_name (| globals, "s" |) ], + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "r" |); M.get_field (| M.get_name (| globals, "tx" |), "s" |) ] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.and (| + Compare.lt (| Constant.int 0, M.get_name (| globals, "r" |) |), + ltac:(M.monadic ( + Compare.lt (| M.get_name (| globals, "r" |), M.get_name (| globals, "SECP256K1N" |) |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.and (| + Compare.lt (| Constant.int 0, M.get_name (| globals, "s" |) |), + ltac:(M.monadic ( + Compare.lt_e (| M.get_name (| globals, "s" |), BinOp.floor_div (| + M.get_name (| globals, "SECP256K1N" |), + Constant.int 2 + |) |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "LegacyTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let v := + M.get_field (| M.get_name (| globals, "tx" |), "v" |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.eq (| M.get_name (| globals, "v" |), Constant.int 27 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "v" |), Constant.int 28 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + BinOp.sub (| + M.get_name (| globals, "v" |), + Constant.int 27 + |); + M.call (| + M.get_name (| globals, "signing_hash_pre155" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.or (| + Compare.eq (| M.get_name (| globals, "v" |), BinOp.add (| + Constant.int 35, + BinOp.mult (| + M.get_name (| globals, "chain_id" |), + Constant.int 2 + |) + |) |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "v" |), BinOp.add (| + Constant.int 36, + BinOp.mult (| + M.get_name (| globals, "chain_id" |), + Constant.int 2 + |) + |) |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + BinOp.sub (| + BinOp.sub (| + M.get_name (| globals, "v" |), + Constant.int 35 + |), + BinOp.mult (| + M.get_name (| globals, "chain_id" |), + Constant.int 2 + |) + |); + M.call (| + M.get_name (| globals, "signing_hash_155" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "chain_id" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "AccessListTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + M.get_field (| M.get_name (| globals, "tx" |), "y_parity" |); + M.call (| + M.get_name (| globals, "signing_hash_2930" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "FeeMarketTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + M.get_field (| M.get_name (| globals, "tx" |), "y_parity" |); + M.call (| + M.get_name (| globals, "signing_hash_1559" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "BlobTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + M.get_field (| M.get_name (| globals, "tx" |), "y_parity" |); + M.call (| + M.get_name (| globals, "signing_hash_4844" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_subscript (| M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), Constant.int 12:Constant.int 32 |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition signing_hash_pre155 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Compute the hash of a transaction used in a legacy (pre EIP 155) signature. + + Parameters + ---------- + tx : + Transaction of interest. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the transaction. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "nonce" |); M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |); M.get_field (| M.get_name (| globals, "tx" |), "gas" |); M.get_field (| M.get_name (| globals, "tx" |), "to" |); M.get_field (| M.get_name (| globals, "tx" |), "value" |); M.get_field (| M.get_name (| globals, "tx" |), "data" |) ] + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition signing_hash_155 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx"; "chain_id" ] |) in + let _ := Constant.str " + Compute the hash of a transaction used in a EIP 155 signature. + + Parameters + ---------- + tx : + Transaction of interest. + chain_id : + The id of the current chain. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the transaction. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "nonce" |); M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |); M.get_field (| M.get_name (| globals, "tx" |), "gas" |); M.get_field (| M.get_name (| globals, "tx" |), "to" |); M.get_field (| M.get_name (| globals, "tx" |), "value" |); M.get_field (| M.get_name (| globals, "tx" |), "data" |); M.get_name (| globals, "chain_id" |); M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) ] + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition signing_hash_2930 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Compute the hash of a transaction used in a EIP 2930 signature. + + Parameters + ---------- + tx : + Transaction of interest. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the transaction. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + BinOp.add (| + (* At constant: unsupported node type: Constant *), + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "chain_id" |); M.get_field (| M.get_name (| globals, "tx" |), "nonce" |); M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |); M.get_field (| M.get_name (| globals, "tx" |), "gas" |); M.get_field (| M.get_name (| globals, "tx" |), "to" |); M.get_field (| M.get_name (| globals, "tx" |), "value" |); M.get_field (| M.get_name (| globals, "tx" |), "data" |); M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) ] + ], + make_dict [] + |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition signing_hash_1559 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Compute the hash of a transaction used in a EIP 1559 signature. + + Parameters + ---------- + tx : + Transaction of interest. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the transaction. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + BinOp.add (| + (* At constant: unsupported node type: Constant *), + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "chain_id" |); M.get_field (| M.get_name (| globals, "tx" |), "nonce" |); M.get_field (| M.get_name (| globals, "tx" |), "max_priority_fee_per_gas" |); M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |); M.get_field (| M.get_name (| globals, "tx" |), "gas" |); M.get_field (| M.get_name (| globals, "tx" |), "to" |); M.get_field (| M.get_name (| globals, "tx" |), "value" |); M.get_field (| M.get_name (| globals, "tx" |), "data" |); M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) ] + ], + make_dict [] + |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition signing_hash_4844 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Compute the hash of a transaction used in a EIP-4844 signature. + + Parameters + ---------- + tx : + Transaction of interest. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the transaction. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + BinOp.add (| + (* At constant: unsupported node type: Constant *), + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "chain_id" |); M.get_field (| M.get_name (| globals, "tx" |), "nonce" |); M.get_field (| M.get_name (| globals, "tx" |), "max_priority_fee_per_gas" |); M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |); M.get_field (| M.get_name (| globals, "tx" |), "gas" |); M.get_field (| M.get_name (| globals, "tx" |), "to" |); M.get_field (| M.get_name (| globals, "tx" |), "value" |); M.get_field (| M.get_name (| globals, "tx" |), "data" |); M.get_field (| M.get_name (| globals, "tx" |), "access_list" |); M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_blob_gas" |); M.get_field (| M.get_name (| globals, "tx" |), "blob_versioned_hashes" |) ] + ], + make_dict [] + |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition compute_header_hash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header" ] |) in + let _ := Constant.str " + Computes the hash of a block header. + + The header hash of a block is the canonical hash that is used to refer + to a specific block and completely distinguishes a block from another. + + ``keccak256`` is a function that produces a 256 bit hash of any input. + It also takes in any number of bytes as an input and produces a single + hash for them. A hash is a completely unique output for a single input. + So an input corresponds to one unique hash that can be used to identify + the input exactly. + + Prior to using the ``keccak256`` hash function, the header must be + encoded using the Recursive-Length Prefix. See :ref:`rlp`. + RLP encoding the header converts it into a space-efficient format that + allows for easy transfer of data between nodes. The purpose of RLP is to + encode arbitrarily nested arrays of binary data, and RLP is the primary + encoding method used to serialize objects in Ethereum's execution layer. + The only purpose of RLP is to encode structure; encoding specific data + types (e.g. strings, floats) is left up to higher-order protocols. + + Parameters + ---------- + header : + Header of interest. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the header. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "header" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition check_gas_limit : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "gas_limit"; "parent_gas_limit" ] |) in + let _ := Constant.str " + Validates the gas limit for a block. + + The bounds of the gas limit, ``max_adjustment_delta``, is set as the + quotient of the parent block's gas limit and the + ``GAS_LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is + passed through as a parameter is greater than or equal to the *sum* of + the parent's gas and the adjustment delta then the limit for gas is too + high and fails this function's check. Similarly, if the limit is less + than or equal to the *difference* of the parent's gas and the adjustment + delta *or* the predefined ``GAS_LIMIT_MINIMUM`` then this function's + check fails because the gas limit doesn't allow for a sufficient or + reasonable amount of gas to be used on a block. + + Parameters + ---------- + gas_limit : + Gas limit to validate. + + parent_gas_limit : + Gas limit of the parent block. + + Returns + ------- + check : `bool` + True if gas limit constraints are satisfied, False otherwise. + " in + let max_adjustment_delta := + BinOp.floor_div (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "gas_limit" |), BinOp.add (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| M.get_name (| globals, "gas_limit" |), BinOp.sub (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "gas_limit" |), M.get_name (| globals, "GAS_LIMIT_MINIMUM" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + Constant.bool true + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/fork_types.v b/CoqOfPython/ethereum/cancun/fork_types.v new file mode 100644 index 0000000..d51b593 --- /dev/null +++ b/CoqOfPython/ethereum/cancun/fork_types.v @@ -0,0 +1,106 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Types +^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Types re-used throughout the specification, which are specific to Ethereum. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes20 : + IsGlobalAlias globals base_types.globals "Bytes20". +Axiom base_types_Bytes256 : + IsGlobalAlias globals base_types.globals "Bytes256". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require crypto.hash. +Axiom crypto_hash_Hash32 : + IsGlobalAlias globals crypto.hash.globals "Hash32". +Axiom crypto_hash_keccak256 : + IsGlobalAlias globals crypto.hash.globals "keccak256". + +Definition Address : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Bytes20" |) +)). + +Definition Root : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Hash32" |) +)). + +Definition VersionedHash : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Hash32" |) +)). + +Definition Bloom : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Bytes256" |) +)). + +Definition Account : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition EMPTY_ACCOUNT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Account" |), + make_list [], + make_dict [] + |) +)). + +Definition encode_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "raw_account_data"; "storage_root" ] |) in + let _ := Constant.str " + Encode `Account` dataclass. + + Storage is not stored in the `Account` dataclass, so `Accounts` cannot be + encoded with providing a storage root. + " in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "raw_account_data" |), "nonce" |); M.get_field (| M.get_name (| globals, "raw_account_data" |), "balance" |); M.get_name (| globals, "storage_root" |); M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_field (| M.get_name (| globals, "raw_account_data" |), "code" |) + ], + make_dict [] + |) ] + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/state.v b/CoqOfPython/ethereum/cancun/state.v new file mode 100644 index 0000000..504eebb --- /dev/null +++ b/CoqOfPython/ethereum/cancun/state.v @@ -0,0 +1,1403 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +State +^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The state contains all information that is preserved between transactions. + +It consists of a main account trie and storage tries for each contract. + +There is a distinction between an account that does not exist and +`EMPTY_ACCOUNT`. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_field : + IsGlobalAlias globals dataclasses.globals "field". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". +Axiom typing_Iterable : + IsGlobalAlias globals typing.globals "Iterable". +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_modify : + IsGlobalAlias globals ethereum.base_types.globals "modify". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require blocks. +Axiom blocks_Withdrawal : + IsGlobalAlias globals blocks.globals "Withdrawal". + +Require fork_types. +Axiom fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". +Axiom fork_types_Account : + IsGlobalAlias globals fork_types.globals "Account". +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Require trie. +Axiom trie_EMPTY_TRIE_ROOT : + IsGlobalAlias globals trie.globals "EMPTY_TRIE_ROOT". +Axiom trie_Trie : + IsGlobalAlias globals trie.globals "Trie". +Axiom trie_copy_trie : + IsGlobalAlias globals trie.globals "copy_trie". +Axiom trie_root : + IsGlobalAlias globals trie.globals "root". +Axiom trie_trie_get : + IsGlobalAlias globals trie.globals "trie_get". +Axiom trie_trie_set : + IsGlobalAlias globals trie.globals "trie_set". + +Definition State : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition TransientStorage : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition close_state : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Free resources held by the state. Used by optimized implementations to + release file descriptors. + " in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) |) in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |) in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "created_accounts" |) |) in + M.pure Constant.None_)). + +Definition begin_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "transient_storage" ] |) in + let _ := Constant.str " + Start a state transaction. + + Transactions are entirely implicit and can be nested. It is not possible to + calculate the state root during a transaction. + + Parameters + ---------- + state : State + The state. + transient_storage : TransientStorage + The transient storage of the transaction. + " in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), "append" |), + make_list [ + make_tuple [ M.call (| + M.get_name (| globals, "copy_trie" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) + ], + make_dict [] + |); {M.get_name (| globals, "k" |): M.call (| + M.get_name (| globals, "copy_trie" |), + make_list [ + M.get_name (| globals, "t" |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)} ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "transient_storage" |), "_snapshots" |), "append" |), + make_list [ + {M.get_name (| globals, "k" |): M.call (| + M.get_name (| globals, "copy_trie" |), + make_list [ + M.get_name (| globals, "t" |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)} + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition commit_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "transient_storage" ] |) in + let _ := Constant.str " + Commit a state transaction. + + Parameters + ---------- + state : State + The state. + transient_storage : TransientStorage + The transient storage of the transaction. + " in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), "pop" |), + make_list [], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "created_accounts" |), "clear" |), + make_list [], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "transient_storage" |), "_snapshots" |), "pop" |), + make_list [], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition rollback_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "transient_storage" ] |) in + let _ := Constant.str " + Rollback a state transaction, resetting the state to the point when the + corresponding `start_transaction()` call was made. + + Parameters + ---------- + state : State + The state. + transient_storage : TransientStorage + The transient storage of the transaction. + " in + let _ := M.assign (| + make_tuple [ M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) ], + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), "pop" |), + make_list [], + make_dict [] + |) + |) in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "created_accounts" |), "clear" |), + make_list [], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "transient_storage" |), "_tries" |), + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "transient_storage" |), "_snapshots" |), "pop" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition get_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Get the `Account` object at an address. Returns `EMPTY_ACCOUNT` if there + is no account at the address. + + Use `get_account_optional()` if you care about the difference between a + non-existent account and `EMPTY_ACCOUNT`. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address to lookup. + + Returns + ------- + account : `Account` + Account at address. + " in + let account := + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "account" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "account" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "EMPTY_ACCOUNT" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition get_account_optional : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Get the `Account` object at an address. Returns `None` (rather than + `EMPTY_ACCOUNT`) if there is no account at the address. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address to lookup. + + Returns + ------- + account : `Account` + Account at address. + " in + let account := + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "account" |) + |) in + M.pure Constant.None_)). + +Definition set_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "account" ] |) in + let _ := Constant.str " + Set the `Account` object at an address. Setting to `None` deletes + the account (but not its storage, see `destroy_account()`). + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address to set. + account : `Account` + Account to set at address. + " in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "account" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition destroy_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Completely remove the account at `address` and all of its storage. + + This function is made available exclusively for the `SELFDESTRUCT` + opcode. It is expected that `SELFDESTRUCT` will be disabled in a future + hardfork and this function will be removed. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of account to destroy. + " in + let _ := M.call (| + M.get_name (| globals, "destroy_storage" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + Constant.None_ + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition destroy_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Completely remove the storage at `address`. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of account whose storage is to be deleted. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition mark_account_created : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Mark an account as having been created in the current transaction. + This information is used by `get_storage_original()` to handle an obscure + edgecase. + + The marker is not removed even if the account creation reverts. Since the + account cannot have had code prior to its creation and can't call + `get_storage_original()`, this is harmless. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of the account that has been created. + " in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "created_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition get_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "key" ] |) in + let _ := Constant.str " + Get a value at a storage key on an account. Returns `U256(0)` if the + storage key has not been set previously. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of the account. + key : `Bytes` + Key to lookup. + + Returns + ------- + value : `U256` + Value at the key. + " in + let trie := + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let _ := M.assert (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "U256" |) + ], + make_dict [] + |) |) in + let _ := M.return_ (| + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_)). + +Definition set_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "key"; "value" ] |) in + let _ := Constant.str " + Set a value at a storage key on an account. Setting to `U256(0)` deletes + the key. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of the account. + key : `Bytes` + Key to set. + value : `U256` + Value to set at the key. + " in + let _ := M.assert (| Compare.is_not (| M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), Constant.None_ |) |) in + let trie := + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let trie := + M.call (| + M.get_name (| globals, "Trie" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), + M.get_name (| globals, "trie" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "key" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), {} |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition storage_root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Calculate the storage root of an account. + + Parameters + ---------- + state: + The state + address : + Address of the account. + + Returns + ------- + root : `Root` + Storage root of the account. + " in + let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "EMPTY_TRIE_ROOT" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition state_root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Calculate the state root. + + Parameters + ---------- + state: + The current state. + + Returns + ------- + root : `Root` + The state root. + " in + let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition account_exists : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account exists in the state trie + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + account_exists : `bool` + True if account exists in the state trie, False otherwise + " in + let _ := M.return_ (| + Compare.is_not (| M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), Constant.None_ |) + |) in + M.pure Constant.None_)). + +Definition account_has_code_or_nonce : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account has non zero nonce or non empty code + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + has_code_or_nonce : `bool` + True if if an account has non zero nonce or non empty code, + False otherwise. + " in + let account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + BoolOp.or (| + Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |) + )) + |) + |) in + M.pure Constant.None_)). + +Definition is_account_empty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account has zero nonce, empty code and zero balance. + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + is_empty : `bool` + True if if an account has zero nonce, empty code and zero balance, + False otherwise. + " in + let account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + ltac:(M.monadic ( + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + )) + |) + )) + |) + |) in + M.pure Constant.None_)). + +Definition account_exists_and_is_empty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account exists and has zero nonce, empty code and zero + balance. + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + exists_and_is_empty : `bool` + True if an account exists and has zero nonce, empty code and zero + balance, False otherwise. + " in + let account := + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + BoolOp.and (| + Compare.is_not (| M.get_name (| globals, "account" |), Constant.None_ |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + ltac:(M.monadic ( + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + )) + |) + )) + |) + )) + |) + |) in + M.pure Constant.None_)). + +Definition is_account_alive : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Check whether is an account is both in the state and non empty. + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + is_alive : `bool` + True if the account is alive. + " in + let account := + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "account" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + UnOp.not (| BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + ltac:(M.monadic ( + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + )) + |) + )) + |) |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition modify_state : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "f" ] |) in + let _ := Constant.str " + Modify an `Account` in the `State`. + " in + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.call (| + M.get_name (| globals, "modify" |), + make_list [ + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |); + M.get_name (| globals, "f" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition move_ether : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "sender_address"; "recipient_address"; "amount" ] |) in + let _ := Constant.str " + Move funds between accounts. + " in +(* At stmt: unsupported node type: FunctionDef *) +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "sender_address" |); + M.get_name (| globals, "reduce_sender_balance" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "recipient_address" |); + M.get_name (| globals, "increase_recipient_balance" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition process_withdrawal : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "wd" ] |) in + let _ := Constant.str " + Increase the balance of the withdrawing account. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_field (| M.get_name (| globals, "wd" |), "address" |); + M.get_name (| globals, "increase_recipient_balance" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition set_account_balance : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "amount" ] |) in + let _ := Constant.str " + Sets the balance of an account. + + Parameters + ---------- + state: + The current state. + + address: + Address of the account whose nonce needs to be incremented. + + amount: + The amount that needs to set in balance. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "set_balance" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition touch_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Initializes an account to state. + + Parameters + ---------- + state: + The current state. + + address: + The address of the account that need to initialised. + " in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "account_exists" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "EMPTY_ACCOUNT" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition increment_nonce : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Increments the nonce of an account. + + Parameters + ---------- + state: + The current state. + + address: + Address of the account whose nonce needs to be incremented. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "increase_nonce" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition set_code : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "code" ] |) in + let _ := Constant.str " + Sets Account code. + + Parameters + ---------- + state: + The current state. + + address: + Address of the account whose code needs to be update. + + code: + The bytecode that needs to be set. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "write_code" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition get_storage_original : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "key" ] |) in + let _ := Constant.str " + Get the original value in a storage slot i.e. the value before the current + transaction began. This function reads the value from the snapshots taken + before executing the transaction. + + Parameters + ---------- + state: + The current state. + address: + Address of the account to read the value from. + key: + Key of the storage slot. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "created_accounts" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "_" |); M.get_name (| globals, "original_trie" |) ], + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), Constant.int 0 |) + |) in + let original_account_trie := + M.call (| + M.get_field (| M.get_name (| globals, "original_trie" |), "get" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "original_account_trie" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let original_value := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let original_value := + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_name (| globals, "original_account_trie" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.assert (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "original_value" |); + M.get_name (| globals, "U256" |) + ], + make_dict [] + |) |) in + let _ := M.return_ (| + M.get_name (| globals, "original_value" |) + |) in + M.pure Constant.None_)). + +Definition get_transient_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "transient_storage"; "address"; "key" ] |) in + let _ := Constant.str " + Get a value at a storage key on an account from transient storage. + Returns `U256(0)` if the storage key has not been set previously. + Parameters + ---------- + transient_storage: `TransientStorage` + The transient storage + address : `Address` + Address of the account. + key : `Bytes` + Key to lookup. + Returns + ------- + value : `U256` + Value at the key. + " in + let trie := + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "transient_storage" |), "_tries" |), "get" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let _ := M.assert (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "U256" |) + ], + make_dict [] + |) |) in + let _ := M.return_ (| + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_)). + +Definition set_transient_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "transient_storage"; "address"; "key"; "value" ] |) in + let _ := Constant.str " + Set a value at a storage key on an account. Setting to `U256(0)` deletes + the key. + Parameters + ---------- + transient_storage: `TransientStorage` + The transient storage + address : `Address` + Address of the account. + key : `Bytes` + Key to set. + value : `U256` + Value to set at the key. + " in + let trie := + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "transient_storage" |), "_tries" |), "get" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let trie := + M.call (| + M.get_name (| globals, "Trie" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "transient_storage" |), "_tries" |), M.get_name (| globals, "address" |) |), + M.get_name (| globals, "trie" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "key" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), {} |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "transient_storage" |), "_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition destroy_touched_empty_accounts : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "touched_accounts" ] |) in + let _ := Constant.str " + Destroy all touched accounts that are empty. + Parameters + ---------- + state: `State` + The current state. + touched_accounts: `Iterable[Address]` + All the accounts that have been touched in the current transaction. + " in + For M.get_name (| globals, "address" |) in M.get_name (| globals, "touched_accounts" |) do + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/transactions.v b/CoqOfPython/ethereum/cancun/transactions.v new file mode 100644 index 0000000..7829244 --- /dev/null +++ b/CoqOfPython/ethereum/cancun/transactions.v @@ -0,0 +1,337 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Transactions are atomic units of work created externally to Ethereum and +submitted to be executed. If Ethereum is viewed as a state machine, +transactions are the events that move between states. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U64 : + IsGlobalAlias globals base_types.globals "U64". +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes0 : + IsGlobalAlias globals base_types.globals "Bytes0". +Axiom base_types_Bytes32 : + IsGlobalAlias globals base_types.globals "Bytes32". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require exceptions. +Axiom exceptions_InvalidBlock : + IsGlobalAlias globals exceptions.globals "InvalidBlock". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_VersionedHash : + IsGlobalAlias globals fork_types.globals "VersionedHash". + +Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( + Constant.int 21000 +)). + +Definition TX_DATA_COST_PER_NON_ZERO : Value.t := M.run ltac:(M.monadic ( + Constant.int 16 +)). + +Definition TX_DATA_COST_PER_ZERO : Value.t := M.run ltac:(M.monadic ( + Constant.int 4 +)). + +Definition TX_CREATE_COST : Value.t := M.run ltac:(M.monadic ( + Constant.int 32000 +)). + +Definition TX_ACCESS_LIST_ADDRESS_COST : Value.t := M.run ltac:(M.monadic ( + Constant.int 2400 +)). + +Definition TX_ACCESS_LIST_STORAGE_KEY_COST : Value.t := M.run ltac:(M.monadic ( + Constant.int 1900 +)). + +Definition LegacyTransaction : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition AccessListTransaction : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition FeeMarketTransaction : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition BlobTransaction : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Transaction : Value.t := M.run ltac:(M.monadic ( + M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "AccessListTransaction" |); M.get_name (| globals, "FeeMarketTransaction" |); M.get_name (| globals, "BlobTransaction" |) ] |) +)). + +Definition encode_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Encode a transaction. Needed because non-legacy transactions aren't RLP. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "LegacyTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "tx" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "AccessListTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + (* At constant: unsupported node type: Constant *), + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "FeeMarketTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + (* At constant: unsupported node type: Constant *), + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "BlobTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + (* At constant: unsupported node type: Constant *), + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "Exception" |), + make_list [ + (* At expr: unsupported node type: JoinedStr *) + ], + make_dict [] + |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition decode_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Decode a transaction. Needed because non-legacy transactions aren't RLP. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), Constant.int 1 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), + make_list [ + M.get_name (| globals, "AccessListTransaction" |); + M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 1:(* At expr: unsupported node type: NoneType *) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), Constant.int 2 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), + make_list [ + M.get_name (| globals, "FeeMarketTransaction" |); + M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 1:(* At expr: unsupported node type: NoneType *) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), Constant.int 3 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), + make_list [ + M.get_name (| globals, "BlobTransaction" |); + M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 1:(* At expr: unsupported node type: NoneType *) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidBlock" |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "tx" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/trie.v b/CoqOfPython/ethereum/cancun/trie.v new file mode 100644 index 0000000..c6fe5c3 --- /dev/null +++ b/CoqOfPython/ethereum/cancun/trie.v @@ -0,0 +1,1360 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +State Trie +^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The state trie is the structure responsible for storing +`.fork_types.Account` objects. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_field : + IsGlobalAlias globals dataclasses.globals "field". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". +Axiom typing_Generic : + IsGlobalAlias globals typing.globals "Generic". +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Mapping : + IsGlobalAlias globals typing.globals "Mapping". +Axiom typing_MutableMapping : + IsGlobalAlias globals typing.globals "MutableMapping". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Sequence : + IsGlobalAlias globals typing.globals "Sequence". +Axiom typing_TypeVar : + IsGlobalAlias globals typing.globals "TypeVar". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". +Axiom typing_cast : + IsGlobalAlias globals typing.globals "cast". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.shanghai. +Axiom ethereum_shanghai_trie : + IsGlobalAlias globals ethereum.shanghai.globals "trie". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require ethereum.utils.hexadecimal. +Axiom ethereum_utils_hexadecimal_hex_to_bytes : + IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require blocks. +Axiom blocks_Receipt : + IsGlobalAlias globals blocks.globals "Receipt". +Axiom blocks_Withdrawal : + IsGlobalAlias globals blocks.globals "Withdrawal". + +Require fork_types. +Axiom fork_types_Account : + IsGlobalAlias globals fork_types.globals "Account". +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". +Axiom fork_types_encode_account : + IsGlobalAlias globals fork_types.globals "encode_account". + +Require transactions. +Axiom transactions_LegacyTransaction : + IsGlobalAlias globals transactions.globals "LegacyTransaction". + +Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Root" |), + make_list [ + M.call (| + M.get_name (| globals, "hex_to_bytes" |), + make_list [ + Constant.str "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" + ], + make_dict [] + |) + ], + make_dict [] + |) +)). + +Definition Node : Value.t := M.run ltac:(M.monadic ( + M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Bytes" |); M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |); M.get_name (| globals, "Withdrawal" |); Constant.None_ ] |) +)). + +Definition K : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "TypeVar" |), + make_list [ + Constant.str "K" + ], + make_dict [] + |) +)). + +Definition V : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "TypeVar" |), + make_list [ + Constant.str "V"; + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Account" |) |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Bytes" |) |); + M.get_name (| globals, "Bytes" |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Bytes" |) ] |) |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Bytes" |) ] |) |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Withdrawal" |); M.get_name (| globals, "Bytes" |) ] |) |); + M.get_name (| globals, "Uint" |); + M.get_name (| globals, "U256" |) + ], + make_dict [] + |) +)). + +Definition LeafNode : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition ExtensionNode : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition BranchNode : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition InternalNode : Value.t := M.run ltac:(M.monadic ( + M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LeafNode" |); M.get_name (| globals, "ExtensionNode" |); M.get_name (| globals, "BranchNode" |) ] |) +)). + +Definition encode_internal_node : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "node" ] |) in + let _ := Constant.str " + Encodes a Merkle Trie node into its RLP form. The RLP will then be + serialized into a `Bytes` and hashed unless it is less that 32 bytes + when serialized. + + This function also accepts `None`, representing the absence of a node, + which is encoded to `b""""""`. + + Parameters + ---------- + node : Optional[InternalNode] + The node to encode. + + Returns + ------- + encoded : `rlp.RLP` + The node encoded as RLP. + " in +(* At stmt: unsupported node type: AnnAssign *) + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "node" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let unencoded := + (* At constant: unsupported node type: Constant *) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "LeafNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "rest_of_key" |); + Constant.bool true + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "ExtensionNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "key_segment" |); + Constant.bool false + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "BranchNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + BinOp.add (| + M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "value" |) + ] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "AssertionError" |), + make_list [ + (* At expr: unsupported node type: JoinedStr *) + ], + make_dict [] + |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let encoded := + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "unencoded" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded" |) + ], + make_dict [] + |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "unencoded" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "encoded" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition encode_node : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "node"; "storage_root" ] |) in + let _ := Constant.str " + Encode a Node for storage in the Merkle Trie. + + Currently mostly an unimplemented stub. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "storage_root" |), Constant.None_ |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "encode_account" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "storage_root" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Withdrawal" |); M.get_name (| globals, "U256" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "cast" |), + make_list [ + M.get_field (| M.get_name (| globals, "rlp" |), "RLP" |); + M.get_name (| globals, "node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "node" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "previous_trie" |), "encode_node" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "storage_root" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition Trie : Value.t := + builtins.make_klass + [(* At base: unsupported node type: Subscript *)] + [ + + ] + [ + + ]. + +Definition copy_trie : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie" ] |) in + let _ := Constant.str " + Create a copy of `trie`. Since only frozen objects may be stored in tries, + the contents are reused. + + Parameters + ---------- + trie: `Trie` + Trie to copy. + + Returns + ------- + new_trie : `Trie[K, V]` + A copy of the trie. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Trie" |), + make_list [ + M.get_field (| M.get_name (| globals, "trie" |), "secured" |); + M.get_field (| M.get_name (| globals, "trie" |), "default" |); + M.call (| + M.get_field (| M.get_name (| globals, "copy" |), "copy" |), + make_list [ + M.get_field (| M.get_name (| globals, "trie" |), "_data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition trie_set : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "key"; "value" ] |) in + let _ := Constant.str " + Stores an item in a Merkle Trie. + + This method deletes the key if `value == trie.default`, because the Merkle + Trie represents the default value by omitting it from the trie. + + Parameters + ---------- + trie: `Trie` + Trie to store in. + key : `Bytes` + Key to lookup. + value : `V` + Node to insert at `key`. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "value" |), M.get_field (| M.get_name (| globals, "trie" |), "default" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "key" |), M.get_field (| M.get_name (| globals, "trie" |), "_data" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition trie_get : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "key" ] |) in + let _ := Constant.str " + Gets an item from the Merkle Trie. + + This method returns `trie.default` if the key is missing. + + Parameters + ---------- + trie: + Trie to lookup in. + key : + Key to lookup. + + Returns + ------- + node : `V` + Node at `key` in the trie. + " in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "get" |), + make_list [ + M.get_name (| globals, "key" |); + M.get_field (| M.get_name (| globals, "trie" |), "default" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition common_prefix_length : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "a"; "b" ] |) in + let _ := Constant.str " + Find the longest common prefix of two sequences. + " in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + ], + make_dict [] + |) do + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| M.get_name (| globals, "i" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition nibble_list_to_compact : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "x"; "is_leaf" ] |) in + let _ := Constant.str " + Compresses nibble-list into a standard byte array with a flag. + + A nibble-list is a list of byte values no greater than `15`. The flag is + encoded in high nibble of the highest byte. The flag nibble can be broken + down into two two-bit flags. + + Highest nibble:: + + +---+---+----------+--------+ + | _ | _ | is_leaf | parity | + +---+---+----------+--------+ + 3 2 1 0 + + + The lowest bit of the nibble encodes the parity of the length of the + remaining nibbles -- `0` when even and `1` when odd. The second lowest bit + is used to distinguish leaf and extension nodes. The other two bits are not + used. + + Parameters + ---------- + x : + Array of nibbles. + is_leaf : + True if this is part of a leaf node, or false if it is an extension + node. + + Returns + ------- + compressed : `bytearray` + Compact byte array. + " in + let compact := + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + Constant.int 2 + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.mult (| + Constant.int 16, + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "is_leaf" |) + |) + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + BinOp.add (| + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "is_leaf" |) + |), + Constant.int 1 + |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), Constant.int 0 |) + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 1; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + M.get_name (| globals, "compact" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition bytes_to_nibble_list : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "bytes_" ] |) in + let _ := Constant.str " + Converts a `Bytes` into to a sequence of nibbles (bytes with value < 16). + + Parameters + ---------- + bytes_: + The `Bytes` to convert. + + Returns + ------- + nibble_list : `Bytes` + The `Bytes` in nibble-list format. + " in + let nibble_list := + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [ + BinOp.mult (| + Constant.int 2, + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "bytes_" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + For make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ] in M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "bytes_" |) + ], + make_dict [] + |) do + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |) |), + BinOp.r_shift (| + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 240 + |), + Constant.int 4 + |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |), + Constant.int 1 + |) |), + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 15 + |) + |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + M.get_name (| globals, "nibble_list" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition _prepare_trie : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "get_storage_root" ] |) in + let _ := Constant.str " + Prepares the trie for root calculation. Removes values that are empty, + hashes the keys (if `secured == True`) and encodes all the nodes. + + Parameters + ---------- + trie : + The `Trie` to prepare. + get_storage_root : + Function to get the storage root of an account. Needed to encode + `Account` objects. + + Returns + ------- + out : `Mapping[ethereum.base_types.Bytes, Node]` + Object with keys mapped to nibble-byte form. + " in +(* At stmt: unsupported node type: AnnAssign *) + For make_tuple [ M.get_name (| globals, "preimage" |); M.get_name (| globals, "value" |) ] in M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "items" |), + make_list [], + make_dict [] + |) do + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in + let address := + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |); + M.call (| + M.get_name (| globals, "get_storage_root" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_eq (| M.get_name (| globals, "encoded_value" |), (* At constant: unsupported node type: Constant *) |); + M.get_name (| globals, "AssertionError" |) + ], + make_dict [] + |) in +(* At stmt: unsupported node type: AnnAssign *) + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "trie" |), "secured" |), + (* then *) + ltac:(M.monadic ( + let key := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let key := + M.get_name (| globals, "preimage" |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "mapped" |), M.call (| + M.get_name (| globals, "bytes_to_nibble_list" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |) |), + M.get_name (| globals, "encoded_value" |) + |) in + EndFor. + let _ := M.return_ (| + M.get_name (| globals, "mapped" |) + |) in + M.pure Constant.None_)). + +Definition root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "get_storage_root" ] |) in + let _ := Constant.str " + Computes the root of a modified merkle patricia trie (MPT). + + Parameters + ---------- + trie : + `Trie` to get the root of. + get_storage_root : + Function to get the storage root of an account. Needed to encode + `Account` objects. + + + Returns + ------- + root : `.fork_types.Root` + MPT root of the underlying key-value pairs. + " in + let obj := + M.call (| + M.get_name (| globals, "_prepare_trie" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "get_storage_root" |) + ], + make_dict [] + |) in + let root_node := + M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_name (| globals, "obj" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assert (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "root_node" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Root" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition patricialize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "obj"; "level" ] |) in + let _ := Constant.str " + Structural composition function. + + Used to recursively patricialize and merkleize a dictionary. Includes + memoization of the tree structure and hashes. + + Parameters + ---------- + obj : + Underlying trie key-value pairs, with keys in nibble-list format. + level : + Current trie level. + + Returns + ------- + node : `ethereum.base_types.Bytes` + Root node of `obj`. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let arbitrary_key := + M.call (| + M.get_name (| globals, "next" |), + make_list [ + M.call (| + M.get_name (| globals, "iter" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), Constant.int 1 |), + (* then *) + ltac:(M.monadic ( + let leaf := + M.call (| + M.get_name (| globals, "LeafNode" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |); + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "leaf" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let substring := + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) in + let prefix_length := + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "substring" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do + let prefix_length := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_name (| globals, "prefix_length" |); + M.call (| + M.get_name (| globals, "common_prefix_length" |), + make_list [ + M.get_name (| globals, "substring" |); + M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let prefix := + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ExtensionNode" |), + make_list [ + M.get_name (| globals, "prefix" |); + M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_name (| globals, "obj" |); + BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in +(* At stmt: unsupported node type: AnnAssign *) + For M.get_name (| globals, "_" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 16 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "branches" |), "append" |), + make_list [ + {} + ], + make_dict [] + |) in + EndFor. + let value := + (* At constant: unsupported node type: Constant *) in + For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |), M.get_name (| globals, "level" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "AssertionError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) + |) in + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "BranchNode" |), + make_list [ + [M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "branches" |), M.get_name (| globals, "k" |) |); + BinOp.add (| + M.get_name (| globals, "level" |), + Constant.int 1 + |) + ], + make_dict [] + |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)]; + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/utils/__init__.v b/CoqOfPython/ethereum/cancun/utils/__init__.v new file mode 100644 index 0000000..1baedea --- /dev/null +++ b/CoqOfPython/ethereum/cancun/utils/__init__.v @@ -0,0 +1,8 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Utility functions unique to this particular fork. +". diff --git a/CoqOfPython/ethereum/cancun/utils/address.v b/CoqOfPython/ethereum/cancun/utils/address.v new file mode 100644 index 0000000..02c6d56 --- /dev/null +++ b/CoqOfPython/ethereum/cancun/utils/address.v @@ -0,0 +1,204 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Hardfork Utility Functions For Addresses +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Address specific functions used in this cancun version of +specification. +". + +Require typing. +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_left_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Definition to_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "data" ] |) in + let _ := Constant.str " + Convert a Uint or U256 value to a valid address (20 bytes). + + Parameters + ---------- + data : + The string to be converted to bytes. + + Returns + ------- + address : `Address` + The obtained address. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_subscript (| M.call (| + M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition compute_contract_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "address"; "nonce" ] |) in + let _ := Constant.str " + Computes address of the new account that needs to be created. + + Parameters + ---------- + address : + The address of the account that wants to create the new account. + nonce : + The transaction count of the account that wants to create the new + account. + + Returns + ------- + address: `Address` + The computed address of the new account. + " in + let computed_address := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_list [ + M.get_name (| globals, "address" |); + M.get_name (| globals, "nonce" |) + ] + ], + make_dict [] + |) + ], + make_dict [] + |) in + let canonical_address := + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + let padded_address := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "canonical_address" |); + Constant.int 20 + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "padded_address" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition compute_create2_contract_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "address"; "salt"; "call_data" ] |) in + let _ := Constant.str " + Computes address of the new account that needs to be created, which is + based on the sender address, salt and the call data as well. + + Parameters + ---------- + address : + The address of the account that wants to create the new account. + salt : + Address generation salt. + call_data : + The code of the new account which is to be created. + + Returns + ------- + address: `ethereum.cancun.fork_types.Address` + The computed address of the new account. + " in + let preimage := + BinOp.add (| + BinOp.add (| + BinOp.add (| + (* At constant: unsupported node type: Constant *), + M.get_name (| globals, "address" |) + |), + M.get_name (| globals, "salt" |) + |), + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "call_data" |) + ], + make_dict [] + |) + |) in + let computed_address := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + let canonical_address := + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + let padded_address := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "canonical_address" |); + Constant.int 20 + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "padded_address" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/utils/hexadecimal.v b/CoqOfPython/ethereum/cancun/utils/hexadecimal.v new file mode 100644 index 0000000..60d41d5 --- /dev/null +++ b/CoqOfPython/ethereum/cancun/utils/hexadecimal.v @@ -0,0 +1,155 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Utility Functions For Hexadecimal Strings +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Hexadecimal utility functions used in this specification, specific to +Cancun types. +". + +Require ethereum.utils.hexadecimal. +Axiom ethereum_utils_hexadecimal_remove_hex_prefix : + IsGlobalAlias globals ethereum.utils.hexadecimal.globals "remove_hex_prefix". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Definition hex_to_root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to trie root. + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to trie root. + + Returns + ------- + root : `Root` + Trie root obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Root" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition hex_to_bloom : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to bloom. + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to bloom. + + Returns + ------- + bloom : `Bloom` + Bloom obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bloom" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition hex_to_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to Address (20 bytes). + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to Address. + + Returns + ------- + address : `Address` + The address obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |), "rjust" |), + make_list [ + Constant.int 40; + Constant.str "0" + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/utils/message.v b/CoqOfPython/ethereum/cancun/utils/message.v new file mode 100644 index 0000000..5794d05 --- /dev/null +++ b/CoqOfPython/ethereum/cancun/utils/message.v @@ -0,0 +1,254 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Hardfork Utility Functions For The Message Data-structure +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Message specific functions used in this cancun version of +specification. +". + +Require typing. +Axiom typing_FrozenSet : + IsGlobalAlias globals typing.globals "FrozenSet". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". + +Require vm. +Axiom vm_Environment : + IsGlobalAlias globals vm.globals "Environment". +Axiom vm_Message : + IsGlobalAlias globals vm.globals "Message". + +Require vm.precompiled_contracts.mapping. +Axiom vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : + IsGlobalAlias globals vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". + +Require address. +Axiom address_compute_contract_address : + IsGlobalAlias globals address.globals "compute_contract_address". + +Definition prepare_message : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "caller"; "target"; "value"; "data"; "gas"; "env"; "code_address"; "should_transfer_value"; "is_static"; "preaccessed_addresses"; "preaccessed_storage_keys" ] |) in + let _ := Constant.str " + Execute a transaction against the provided environment. + + Parameters + ---------- + caller : + Address which initiated the transaction + target : + Address whose code will be executed + value : + Value to be transferred. + data : + Array of bytes provided to the code in `target`. + gas : + Gas provided for the code in `target`. + env : + Environment for the Ethereum Virtual Machine. + code_address : + This is usually same as the `target` address except when an alternative + accounts code needs to be executed. + eg. `CALLCODE` calling a precompile. + should_transfer_value : + if True ETH should be transferred while executing a message call. + is_static: + if True then it prevents all state-changing operations from being + executed. + preaccessed_addresses: + Addresses that should be marked as accessed prior to the message call + preaccessed_storage_keys: + Storage keys that should be marked as accessed prior to the message + call + + Returns + ------- + message: `ethereum.cancun.vm.Message` + Items containing contract creation or message call specific data. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Bytes0" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.call (| + M.get_name (| globals, "compute_contract_address" |), + make_list [ + M.get_name (| globals, "caller" |); + BinOp.sub (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "caller" |) + ], + make_dict [] + |), "nonce" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let msg_data := + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |) in + let code := + M.get_name (| globals, "data" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.get_name (| globals, "target" |) in + let msg_data := + M.get_name (| globals, "data" |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "target" |) + ], + make_dict [] + |), "code" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "code_address" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let code_address := + M.get_name (| globals, "target" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "AssertionError" |), + make_list [ + Constant.str "Target must be address or empty bytes" + ], + make_dict [] + |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let accessed_addresses := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "current_target" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "caller" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "accessed_addresses" |), "update" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "PRE_COMPILED_CONTRACTS" |), "keys" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "accessed_addresses" |), "update" |), + make_list [ + M.get_name (| globals, "preaccessed_addresses" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/vm/__init__.v b/CoqOfPython/ethereum/cancun/vm/__init__.v new file mode 100644 index 0000000..874ad86 --- /dev/null +++ b/CoqOfPython/ethereum/cancun/vm/__init__.v @@ -0,0 +1,266 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The abstract computer which runs the code stored in an +`.fork_types.Account`. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U64 : + IsGlobalAlias globals ethereum.base_types.globals "U64". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_VersionedHash : + IsGlobalAlias globals fork_types.globals "VersionedHash". + +Require state. +Axiom state_State : + IsGlobalAlias globals state.globals "State". +Axiom state_TransientStorage : + IsGlobalAlias globals state.globals "TransientStorage". +Axiom state_account_exists_and_is_empty : + IsGlobalAlias globals state.globals "account_exists_and_is_empty". + +Require precompiled_contracts. +Axiom precompiled_contracts_RIPEMD160_ADDRESS : + IsGlobalAlias globals precompiled_contracts.globals "RIPEMD160_ADDRESS". + +Definition __all__ : Value.t := M.run ltac:(M.monadic ( + make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] +)). + +Definition Environment : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Message : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Evm : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition incorporate_child_on_success : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "child_evm" ] |) in + let _ := Constant.str " + Incorporate the state of a successful `child_evm` into the parent `evm`. + + Parameters + ---------- + evm : + The parent `EVM`. + child_evm : + The child evm to incorporate. + " in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "gas_left" |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "logs" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "logs" |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "refund_counter" |) + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "accounts_to_delete" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "accessed_addresses" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "accessed_storage_keys" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition incorporate_child_on_error : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "child_evm" ] |) in + let _ := Constant.str " + Incorporate the state of an unsuccessful `child_evm` into the parent `evm`. + + Parameters + ---------- + evm : + The parent `EVM`. + child_evm : + The child evm to incorporate. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "RIPEMD160_ADDRESS" |), M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |), M.get_name (| globals, "RIPEMD160_ADDRESS" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "gas_left" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/vm/exceptions.v b/CoqOfPython/ethereum/cancun/vm/exceptions.v new file mode 100644 index 0000000..722d4a8 --- /dev/null +++ b/CoqOfPython/ethereum/cancun/vm/exceptions.v @@ -0,0 +1,182 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Exceptions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Exceptions which cause the EVM to halt exceptionally. +". + +Require ethereum.exceptions. +Axiom ethereum_exceptions_EthereumException : + IsGlobalAlias globals ethereum.exceptions.globals "EthereumException". + +Definition ExceptionalHalt : Value.t := + builtins.make_klass + [(globals, "EthereumException")] + [ + + ] + [ + + ]. + +Definition Revert : Value.t := + builtins.make_klass + [(globals, "EthereumException")] + [ + + ] + [ + + ]. + +Definition StackUnderflowError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition StackOverflowError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition OutOfGasError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition InvalidOpcode : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + ( + "__init__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "code" ] |) in + let _ := M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "super" |), + make_list [], + make_dict [] + |), "__init__" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "self" |), "code" |), + M.get_name (| globals, "code" |) + |) in + M.pure Constant.None_)) + ) + ]. + +Definition InvalidJumpDestError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition StackDepthLimitError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition WriteInStaticContext : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition OutOfBoundsRead : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition InvalidParameter : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition InvalidContractPrefix : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition AddressCollision : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition KZGProofError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/__init__.v b/CoqOfPython/ethereum/cancun/vm/instructions/__init__.v new file mode 100644 index 0000000..e5bebd7 --- /dev/null +++ b/CoqOfPython/ethereum/cancun/vm/instructions/__init__.v @@ -0,0 +1,87 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +EVM Instruction Encoding (Opcodes) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Machine readable representations of EVM instructions, and a mapping to their +implementations. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". + +Require __init__. +Axiom __init___arithmetic : + IsGlobalAlias globals __init__.globals "arithmetic". + +Require __init__. +Axiom __init___bitwise : + IsGlobalAlias globals __init__.globals "bitwise". + +Require __init__. +Axiom __init___block : + IsGlobalAlias globals __init__.globals "block". + +Require __init__. +Axiom __init___comparison : + IsGlobalAlias globals __init__.globals "comparison". + +Require __init__. +Axiom __init___control_flow : + IsGlobalAlias globals __init__.globals "control_flow". + +Require __init__. +Axiom __init___environment : + IsGlobalAlias globals __init__.globals "environment". + +Require __init__. +Axiom __init___keccak : + IsGlobalAlias globals __init__.globals "keccak". + +Require __init__. +Axiom __init___log : + IsGlobalAlias globals __init__.globals "log". + +Require __init__. +Axiom __init___memory : + IsGlobalAlias globals __init__.globals "memory". + +Require __init__. +Axiom __init___stack : + IsGlobalAlias globals __init__.globals "stack". + +Require __init__. +Axiom __init___storage : + IsGlobalAlias globals __init__.globals "storage". + +Require __init__. +Axiom __init___system : + IsGlobalAlias globals __init__.globals "system". + +Definition Ops : Value.t := + builtins.make_klass + [(* At base: unsupported node type: Attribute *)] + [ + + ] + [ + + ]. + +(* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/cancun/vm/instructions/arithmetic.v new file mode 100644 index 0000000..a8b5c61 --- /dev/null +++ b/CoqOfPython/ethereum/cancun/vm/instructions/arithmetic.v @@ -0,0 +1,1085 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Arithmetic Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM Arithmetic instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U255_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U255_CEIL_VALUE". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_U256_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_get_sign : + IsGlobalAlias globals ethereum.utils.numeric.globals "get_sign". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_EXPONENTIATION : + IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION". +Axiom gas_GAS_EXPONENTIATION_PER_BYTE : + IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION_PER_BYTE". +Axiom gas_GAS_LOW : + IsGlobalAlias globals gas.globals "GAS_LOW". +Axiom gas_GAS_MID : + IsGlobalAlias globals gas.globals "GAS_MID". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition add : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Adds the top two elements of the stack together, and pushes the result back + on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "x" |), "wrapping_add" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition sub : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Subtracts the top two elements of the stack, and pushes the result back + on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "x" |), "wrapping_sub" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mul : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Multiply the top two elements of the stack, and pushes the result back + on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "x" |), "wrapping_mul" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition div : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Integer division of the top two elements of the stack. Pushes the result + back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let dividend := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let divisor := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let quotient := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let quotient := + BinOp.floor_div (| + M.get_name (| globals, "dividend" |), + M.get_name (| globals, "divisor" |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "quotient" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition sdiv : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed integer division of the top two elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let dividend := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let divisor := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let quotient := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_name (| globals, "dividend" |), UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "divisor" |), UnOp.sub (| Constant.int 1 |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let quotient := + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let sign := + M.call (| + M.get_name (| globals, "get_sign" |), + make_list [ + BinOp.mult (| + M.get_name (| globals, "dividend" |), + M.get_name (| globals, "divisor" |) + |) + ], + make_dict [] + |) in + let quotient := + BinOp.mult (| + M.get_name (| globals, "sign" |), + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "dividend" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "divisor" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + M.get_name (| globals, "quotient" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Modulo remainder of the top two elements of the stack. Pushes the result + back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let remainder := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let remainder := + BinOp.mod_ (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "remainder" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition smod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed modulo remainder of the top two elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let y := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let remainder := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let remainder := + BinOp.mult (| + M.call (| + M.get_name (| globals, "get_sign" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + BinOp.mod_ (| + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + M.get_name (| globals, "remainder" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition addmod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Modulo addition of the top 2 elements with the 3rd element. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let z := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_MID" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.add (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |), + M.get_name (| globals, "z" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mulmod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Modulo multiplication of the top 2 elements with the 3rd element. Pushes + the result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let z := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_MID" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.mult (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |), + M.get_name (| globals, "z" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition exp : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Exponential operation of the top 2 elements. Pushes the result back on + the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let base := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exponent := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exponent_bits := + M.call (| + M.get_field (| M.get_name (| globals, "exponent" |), "bit_length" |), + make_list [], + make_dict [] + |) in + let exponent_bytes := + BinOp.floor_div (| + BinOp.add (| + M.get_name (| globals, "exponent_bits" |), + Constant.int 7 + |), + Constant.int 8 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_EXPONENTIATION" |), + BinOp.mult (| + M.get_name (| globals, "GAS_EXPONENTIATION_PER_BYTE" |), + M.get_name (| globals, "exponent_bytes" |) + |) + |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "pow" |), + make_list [ + M.get_name (| globals, "base" |); + M.get_name (| globals, "exponent" |); + M.get_name (| globals, "U256_CEIL_VALUE" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition signextend : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Sign extend operation. In other words, extend a signed number which + fits in N bytes to 32 bytes. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let byte_num := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "byte_num" |), Constant.int 31 |), + (* then *) + ltac:(M.monadic ( + let result := + M.get_name (| globals, "value" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let value_bytes := + M.call (| + M.get_name (| globals, "bytes" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "value" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) in + let value_bytes := + M.get_subscript (| M.get_name (| globals, "value_bytes" |), BinOp.sub (| + Constant.int 31, + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "byte_num" |) + ], + make_dict [] + |) + |):(* At expr: unsupported node type: NoneType *) |) in + let sign_bit := + BinOp.r_shift (| + M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), + Constant.int 7 + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "sign_bit" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "value_bytes" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let num_bytes_prepend := + BinOp.sub (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "byte_num" |), + Constant.int 1 + |) + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + BinOp.add (| + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [ + BinOp.mult (| + make_list [ + Constant.int 255 + ], + M.get_name (| globals, "num_bytes_prepend" |) + |) + ], + make_dict [] + |), + M.get_name (| globals, "value_bytes" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/bitwise.v b/CoqOfPython/ethereum/cancun/vm/instructions/bitwise.v new file mode 100644 index 0000000..9f2f382 --- /dev/null +++ b/CoqOfPython/ethereum/cancun/vm/instructions/bitwise.v @@ -0,0 +1,601 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Bitwise Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM bitwise instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_U256_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition bitwise_and : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise AND operation of the top 2 elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + BinOp.bit_and (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_or : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise OR operation of the top 2 elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + BinOp.bit_or (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_xor : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise XOR operation of the top 2 elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + BinOp.bit_xor (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_not : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise NOT operation of the top element of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + UnOp.invert (| M.get_name (| globals, "x" |) |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition get_byte : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + For a word (defined by next top element of the stack), retrieve the + Nth byte (0-indexed and defined by top element of stack) from the + left (most significant) to right (least significant). + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let byte_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let word := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "byte_index" |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let extra_bytes_to_right := + BinOp.sub (| + Constant.int 31, + M.get_name (| globals, "byte_index" |) + |) in + let word := + BinOp.r_shift (| + M.get_name (| globals, "word" |), + BinOp.mult (| + M.get_name (| globals, "extra_bytes_to_right" |), + Constant.int 8 + |) + |) in + let word := + BinOp.bit_and (| + M.get_name (| globals, "word" |), + Constant.int 255 + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "word" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_shl : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Logical shift left (SHL) operation of the top 2 elements of the stack. + Pushes the result back on the stack. + Parameters + ---------- + evm : + The current EVM frame. + " in + let shift := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.l_shift (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "shift" |) + |), + M.get_name (| globals, "U256_CEIL_VALUE" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_shr : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Logical shift right (SHR) operation of the top 2 elements of the stack. + Pushes the result back on the stack. + Parameters + ---------- + evm : + The current EVM frame. + " in + let shift := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), + (* then *) + ltac:(M.monadic ( + let result := + BinOp.r_shift (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "shift" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_sar : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Arithmetic shift right (SAR) operation of the top 2 elements of the stack. + Pushes the result back on the stack. + Parameters + ---------- + evm : + The current EVM frame. + " in + let shift := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let signed_value := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + BinOp.r_shift (| + M.get_name (| globals, "signed_value" |), + M.get_name (| globals, "shift" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "signed_value" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/block.v b/CoqOfPython/ethereum/cancun/vm/instructions/block.v new file mode 100644 index 0000000..27a38cb --- /dev/null +++ b/CoqOfPython/ethereum/cancun/vm/instructions/block.v @@ -0,0 +1,421 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Block Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM block instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_BLOCK_HASH : + IsGlobalAlias globals gas.globals "GAS_BLOCK_HASH". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition block_hash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the hash of one of the 256 most recent complete blocks onto the + stack. The block number to hash is present at the top of the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + Raises + ------ + :py:class:`~ethereum.cancun.vm.exceptions.StackUnderflowError` + If `len(stack)` is less than `1`. + :py:class:`~ethereum.cancun.vm.exceptions.OutOfGasError` + If `evm.gas_left` is less than `20`. + " in + let block_number := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BLOCK_HASH" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt_e (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), M.get_name (| globals, "block_number" |) |), + ltac:(M.monadic ( + Compare.gt (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), BinOp.add (| + M.get_name (| globals, "block_number" |), + Constant.int 256 + |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let hash := + (* At constant: unsupported node type: Constant *) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let hash := + M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + M.get_name (| globals, "block_number" |) + |) |) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "hash" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition coinbase : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's beneficiary address (address of the block miner) + onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + Raises + ------ + :py:class:`~ethereum.cancun.vm.exceptions.StackOverflowError` + If `len(stack)` is equal to `1024`. + :py:class:`~ethereum.cancun.vm.exceptions.OutOfGasError` + If `evm.gas_left` is less than `2`. + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "coinbase" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition timestamp : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's timestamp onto the stack. Here the timestamp + being referred is actually the unix timestamp in seconds. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + Raises + ------ + :py:class:`~ethereum.cancun.vm.exceptions.StackOverflowError` + If `len(stack)` is equal to `1024`. + :py:class:`~ethereum.cancun.vm.exceptions.OutOfGasError` + If `evm.gas_left` is less than `2`. + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "time" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition number : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's number onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + Raises + ------ + :py:class:`~ethereum.cancun.vm.exceptions.StackOverflowError` + If `len(stack)` is equal to `1024`. + :py:class:`~ethereum.cancun.vm.exceptions.OutOfGasError` + If `evm.gas_left` is less than `2`. + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition prev_randao : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the `prev_randao` value onto the stack. + + The `prev_randao` value is the random output of the beacon chain's + randomness oracle for the previous block. + + Parameters + ---------- + evm : + The current EVM frame. + + Raises + ------ + :py:class:`~ethereum.cancun.vm.exceptions.StackOverflowError` + If `len(stack)` is equal to `1024`. + :py:class:`~ethereum.cancun.vm.exceptions.OutOfGasError` + If `evm.gas_left` is less than `2`. + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "prev_randao" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition gas_limit : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's gas limit onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + Raises + ------ + :py:class:`~ethereum.cancun.vm.exceptions.StackOverflowError` + If `len(stack)` is equal to `1024`. + :py:class:`~ethereum.cancun.vm.exceptions.OutOfGasError` + If `evm.gas_left` is less than `2`. + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "gas_limit" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition chain_id : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the chain id onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + Raises + ------ + :py:class:`~ethereum.cancun.vm.exceptions.StackOverflowError` + If `len(stack)` is equal to `1024`. + :py:class:`~ethereum.cancun.vm.exceptions.OutOfGasError` + If `evm.gas_left` is less than `2`. + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "chain_id" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/comparison.v b/CoqOfPython/ethereum/cancun/vm/instructions/comparison.v new file mode 100644 index 0000000..fbc35f8 --- /dev/null +++ b/CoqOfPython/ethereum/cancun/vm/instructions/comparison.v @@ -0,0 +1,404 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Comparison Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM Comparison instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition less_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is less than the next top element. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let right := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition signed_less_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed less-than comparison. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let right := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition greater_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is greater than the next top element. Pushes + the result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let right := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition signed_greater_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed greater-than comparison. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let right := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition equal : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is equal to the next top element. Pushes + the result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let right := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.eq (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition is_zero : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is equal to 0. Pushes the result back on the + stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.eq (| M.get_name (| globals, "x" |), Constant.int 0 |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/control_flow.v b/CoqOfPython/ethereum/cancun/vm/instructions/control_flow.v new file mode 100644 index 0000000..04a79d9 --- /dev/null +++ b/CoqOfPython/ethereum/cancun/vm/instructions/control_flow.v @@ -0,0 +1,336 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Control Flow Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM control flow instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require vm.gas. +Axiom vm_gas_GAS_BASE : + IsGlobalAlias globals vm.gas.globals "GAS_BASE". +Axiom vm_gas_GAS_HIGH : + IsGlobalAlias globals vm.gas.globals "GAS_HIGH". +Axiom vm_gas_GAS_JUMPDEST : + IsGlobalAlias globals vm.gas.globals "GAS_JUMPDEST". +Axiom vm_gas_GAS_MID : + IsGlobalAlias globals vm.gas.globals "GAS_MID". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_InvalidJumpDestError : + IsGlobalAlias globals exceptions.globals "InvalidJumpDestError". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition stop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stop further execution of EVM code. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let _ := M.pass (| |) in + let _ := M.pass (| |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "running" |), + Constant.bool false + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition jump : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Alter the program counter to the location specified by the top of the + stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let jump_dest := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_MID" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "jump_dest" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition jumpi : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Alter the program counter to the specified location if and only if a + condition is true. If the condition is not true, then the program counter + would increase only by 1. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let jump_dest := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let conditional_value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_HIGH" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "conditional_value" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let destination := + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let destination := + M.get_name (| globals, "jump_dest" |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "destination" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition pc : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push onto the stack the value of the program counter after reaching the + current instruction and without increasing it for the next instruction. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "pc" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition gas_left : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the amount of available gas (including the corresponding reduction + for the cost of this instruction) onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition jumpdest : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Mark a valid destination for jumps. This is a noop, present only + to be used by `JUMP` and `JUMPI` opcodes to verify that their jump is + valid. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_JUMPDEST" |) + ], + make_dict [] + |) in + let _ := M.pass (| |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/environment.v b/CoqOfPython/ethereum/cancun/vm/instructions/environment.v new file mode 100644 index 0000000..4ff61a8 --- /dev/null +++ b/CoqOfPython/ethereum/cancun/vm/instructions/environment.v @@ -0,0 +1,1571 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Environmental Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM environment related instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require fork_types. +Axiom fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". + +Require state. +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". + +Require utils.address. +Axiom utils_address_to_address : + IsGlobalAlias globals utils.address.globals "to_address". + +Require vm.memory. +Axiom vm_memory_buffer_read : + IsGlobalAlias globals vm.memory.globals "buffer_read". +Axiom vm_memory_memory_write : + IsGlobalAlias globals vm.memory.globals "memory_write". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_OutOfBoundsRead : + IsGlobalAlias globals exceptions.globals "OutOfBoundsRead". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_BLOBHASH_OPCODE : + IsGlobalAlias globals gas.globals "GAS_BLOBHASH_OPCODE". +Axiom gas_GAS_COLD_ACCOUNT_ACCESS : + IsGlobalAlias globals gas.globals "GAS_COLD_ACCOUNT_ACCESS". +Axiom gas_GAS_COPY : + IsGlobalAlias globals gas.globals "GAS_COPY". +Axiom gas_GAS_FAST_STEP : + IsGlobalAlias globals gas.globals "GAS_FAST_STEP". +Axiom gas_GAS_RETURN_DATA_COPY : + IsGlobalAlias globals gas.globals "GAS_RETURN_DATA_COPY". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_GAS_WARM_ACCESS : + IsGlobalAlias globals gas.globals "GAS_WARM_ACCESS". +Axiom gas_calculate_blob_gas_price : + IsGlobalAlias globals gas.globals "calculate_blob_gas_price". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the address of the current executing account to the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition balance : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the balance of the given account onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "balance" |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "balance" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition origin : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the address of the original transaction sender to the stack. + The origin address can only be an EOA. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "origin" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition caller : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the address of the caller onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "caller" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition callvalue : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the value (in wei) sent with the call onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition calldataload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push a word (32 bytes) of the input data belonging to the current + environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |); + M.get_name (| globals, "start_index" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition calldatasize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the size of input data in current environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition calldatacopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy a portion of the input data in current environment to memory. + + This will also expand the memory, in case that the memory is insufficient + to store the data. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let data_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |); + M.get_name (| globals, "data_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition codesize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the size of code running in current environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "code" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition codecopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy a portion of the code in current environment to memory. + + This will also expand the memory, in case that the memory is insufficient + to store the data. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let code_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "code" |); + M.get_name (| globals, "code_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition gasprice : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the gas price used in current environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "gas_price" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition extcodesize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the code size of a given account onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let codesize := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "code" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "codesize" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition extcodecopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy a portion of an account's code to memory. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let code_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_WARM_ACCESS" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "code" |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "code" |); + M.get_name (| globals, "code_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition returndatasize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the size of the return data buffer onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition returndatacopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copies data from the return data buffer code to memory + + Parameters + ---------- + evm : + The current EVM frame. + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let return_data_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_RETURN_DATA_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "return_data_start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "OutOfBoundsRead" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |):BinOp.add (| + M.get_name (| globals, "return_data_start_position" |), + M.get_name (| globals, "size" |) + |) |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition extcodehash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Returns the keccak256 hash of a contract’s bytecode + Parameters + ---------- + evm : + The current EVM frame. + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "account" |), M.get_name (| globals, "EMPTY_ACCOUNT" |) |), + (* then *) + ltac:(M.monadic ( + let codehash := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let codehash := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_field (| M.get_name (| globals, "account" |), "code" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "codehash" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition self_balance : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the balance of the current address to the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_FAST_STEP" |) + ], + make_dict [] + |) in + let balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "balance" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition base_fee : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the base fee of the current block on to the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "base_fee_per_gas" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition blob_hash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the versioned hash at a particular index on to the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BLOBHASH_OPCODE" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "index" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "blob_versioned_hashes" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let blob_hash := + M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "blob_versioned_hashes" |), M.get_name (| globals, "index" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let blob_hash := + M.call (| + M.get_name (| globals, "Bytes32" |), + make_list [ + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + Constant.int 32 + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "blob_hash" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition blob_base_fee : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the blob base fee on to the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let blob_base_fee := + M.call (| + M.get_name (| globals, "calculate_blob_gas_price" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "excess_blob_gas" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "blob_base_fee" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/keccak.v b/CoqOfPython/ethereum/cancun/vm/instructions/keccak.v new file mode 100644 index 0000000..cab9ffb --- /dev/null +++ b/CoqOfPython/ethereum/cancun/vm/instructions/keccak.v @@ -0,0 +1,181 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Keccak Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM keccak instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_KECCAK256 : + IsGlobalAlias globals gas.globals "GAS_KECCAK256". +Axiom gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition keccak : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes to the stack the Keccak-256 hash of a region of memory. + + This also expands the memory, in case the memory is insufficient to + access the data's memory location. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let word_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_KECCAK256_WORD" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_KECCAK256" |), + M.get_name (| globals, "word_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let data := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "hash" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/log.v b/CoqOfPython/ethereum/cancun/vm/instructions/log.v new file mode 100644 index 0000000..4891a4d --- /dev/null +++ b/CoqOfPython/ethereum/cancun/vm/instructions/log.v @@ -0,0 +1,244 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Logging Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM logging instructions. +". + +Require functools. +Axiom functools_partial : + IsGlobalAlias globals functools.globals "partial". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_WriteInStaticContext : + IsGlobalAlias globals exceptions.globals "WriteInStaticContext". + +Require gas. +Axiom gas_GAS_LOG : + IsGlobalAlias globals gas.globals "GAS_LOG". +Axiom gas_GAS_LOG_DATA : + IsGlobalAlias globals gas.globals "GAS_LOG_DATA". +Axiom gas_GAS_LOG_TOPIC : + IsGlobalAlias globals gas.globals "GAS_LOG_TOPIC". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". + +Definition log_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "num_topics" ] |) in + let _ := Constant.str " + Appends a log entry, having `num_topics` topics, to the evm logs. + + This will also expand the memory if the data (required by the log entry) + corresponding to the memory is not accessible. + + Parameters + ---------- + evm : + The current EVM frame. + num_topics : + The number of topics to be included in the log entry. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let topics := + make_list [] in + For M.get_name (| globals, "_" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "num_topics" |) + ], + make_dict [] + |) do + let topic := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "topics" |), "append" |), + make_list [ + M.get_name (| globals, "topic" |) + ], + make_dict [] + |) in + EndFor. + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_LOG" |), + BinOp.mult (| + M.get_name (| globals, "GAS_LOG_DATA" |), + M.get_name (| globals, "size" |) + |) + |), + BinOp.mult (| + M.get_name (| globals, "GAS_LOG_TOPIC" |), + M.get_name (| globals, "num_topics" |) + |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let log_entry := + M.call (| + M.get_name (| globals, "Log" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "logs" |), + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "logs" |), + make_tuple [ M.get_name (| globals, "log_entry" |) ] + |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition log0 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/memory.v b/CoqOfPython/ethereum/cancun/vm/instructions/memory.v new file mode 100644 index 0000000..9625fa6 --- /dev/null +++ b/CoqOfPython/ethereum/cancun/vm/instructions/memory.v @@ -0,0 +1,504 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Memory Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM Memory instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_COPY : + IsGlobalAlias globals gas.globals "GAS_COPY". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". +Axiom memory_memory_write : + IsGlobalAlias globals memory.globals "memory_write". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition mstore : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a word to memory. + This also expands the memory, if the memory is + insufficient to store the word. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "start_position" |); M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + ], + make_dict [] + |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "start_position" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mstore8 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a byte to memory. + This also expands the memory, if the memory is + insufficient to store the word. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "start_position" |); M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let normalized_bytes_value := + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + make_list [ + BinOp.bit_and (| + M.get_name (| globals, "value" |), + Constant.int 255 + |) + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "start_position" |); + M.get_name (| globals, "normalized_bytes_value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Load word from memory. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "start_position" |); M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "start_position" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition msize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the size of active memory in bytes onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mcopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy the bytes in memory from one location to another. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let destination := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let source := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let length := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "length" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "source" |); M.get_name (| globals, "length" |) ]; + make_tuple [ M.get_name (| globals, "destination" |); M.get_name (| globals, "length" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "source" |); + M.get_name (| globals, "length" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "destination" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/stack.v b/CoqOfPython/ethereum/cancun/vm/instructions/stack.v new file mode 100644 index 0000000..46a91f6 --- /dev/null +++ b/CoqOfPython/ethereum/cancun/vm/instructions/stack.v @@ -0,0 +1,958 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Stack Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM stack related instructions. +". + +Require functools. +Axiom functools_partial : + IsGlobalAlias globals functools.globals "partial". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". +Axiom __init___stack : + IsGlobalAlias globals __init__.globals "stack". + +Require exceptions. +Axiom exceptions_StackUnderflowError : + IsGlobalAlias globals exceptions.globals "StackUnderflowError". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_buffer_read : + IsGlobalAlias globals memory.globals "buffer_read". + +Definition pop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Remove item from stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.pass (| |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition push_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "num_bytes" ] |) in + let _ := Constant.str " + Pushes a N-byte immediate onto the stack. Push zero if num_bytes is zero. + + Parameters + ---------- + evm : + The current EVM frame. + + num_bytes : + The number of immediate bytes to be read from the code and pushed to + the stack. Push zero if num_bytes is zero. + + " in + let _ := M.pass (| |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "num_bytes" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let data_to_push := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "code" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "num_bytes" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "data_to_push" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + BinOp.add (| + Constant.int 1, + M.get_name (| globals, "num_bytes" |) + |) + |) in + M.pure Constant.None_)). + +Definition dup_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "item_number" ] |) in + let _ := Constant.str " + Duplicate the Nth stack item (from top of the stack) to the top of stack. + + Parameters + ---------- + evm : + The current EVM frame. + + item_number : + The stack item number (0-indexed from top of stack) to be duplicated + to the top of stack. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "StackUnderflowError" |) + ], + make_dict [] + |) in + let data_to_duplicate := + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + BinOp.sub (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), + Constant.int 1 + |), + M.get_name (| globals, "item_number" |) + |) |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "data_to_duplicate" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition swap_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "item_number" ] |) in + let _ := Constant.str " + Swap the top and the `item_number` element of the stack, where + the top of the stack is position zero. + + If `item_number` is zero, this function does nothing (which should not be + possible, since there is no `SWAP0` instruction). + + Parameters + ---------- + evm : + The current EVM frame. + + item_number : + The stack item number (0-indexed from top of stack) to be swapped + with the top of stack element. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "StackUnderflowError" |) + ], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) |) ], + make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |) ] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition push0 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push5 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push6 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push7 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push8 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push9 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push10 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push11 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push12 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push13 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push14 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push15 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push16 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push17 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push18 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push19 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push20 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push21 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push22 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push23 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push24 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push25 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push26 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push27 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push28 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push29 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push30 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push31 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push32 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition dup1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup5 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup6 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup7 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup8 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup9 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup10 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup11 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup12 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup13 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup14 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup15 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup16 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition swap1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap5 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap6 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap7 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap8 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap9 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap10 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap11 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap12 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap13 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap14 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap15 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap16 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/storage.v b/CoqOfPython/ethereum/cancun/vm/instructions/storage.v new file mode 100644 index 0000000..51a730d --- /dev/null +++ b/CoqOfPython/ethereum/cancun/vm/instructions/storage.v @@ -0,0 +1,560 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Storage Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM storage related instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require state. +Axiom state_get_storage : + IsGlobalAlias globals state.globals "get_storage". +Axiom state_get_storage_original : + IsGlobalAlias globals state.globals "get_storage_original". +Axiom state_get_transient_storage : + IsGlobalAlias globals state.globals "get_transient_storage". +Axiom state_set_storage : + IsGlobalAlias globals state.globals "set_storage". +Axiom state_set_transient_storage : + IsGlobalAlias globals state.globals "set_transient_storage". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". +Axiom exceptions_WriteInStaticContext : + IsGlobalAlias globals exceptions.globals "WriteInStaticContext". + +Require gas. +Axiom gas_GAS_CALL_STIPEND : + IsGlobalAlias globals gas.globals "GAS_CALL_STIPEND". +Axiom gas_GAS_COLD_SLOAD : + IsGlobalAlias globals gas.globals "GAS_COLD_SLOAD". +Axiom gas_GAS_STORAGE_CLEAR_REFUND : + IsGlobalAlias globals gas.globals "GAS_STORAGE_CLEAR_REFUND". +Axiom gas_GAS_STORAGE_SET : + IsGlobalAlias globals gas.globals "GAS_STORAGE_SET". +Axiom gas_GAS_STORAGE_UPDATE : + IsGlobalAlias globals gas.globals "GAS_STORAGE_UPDATE". +Axiom gas_GAS_WARM_ACCESS : + IsGlobalAlias globals gas.globals "GAS_WARM_ACCESS". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition sload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Loads to the stack, the value corresponding to a certain key from the + storage of the current account. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let key := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "add" |), + make_list [ + make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_COLD_SLOAD" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let value := + M.call (| + M.get_name (| globals, "get_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition sstore : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a value at a certain key in the current context's storage. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let key := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let new_value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt (| M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), M.get_name (| globals, "GAS_CALL_STIPEND" |) |); + M.get_name (| globals, "OutOfGasError" |) + ], + make_dict [] + |) in + let original_value := + M.call (| + M.get_name (| globals, "get_storage_original" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let current_value := + M.call (| + M.get_name (| globals, "get_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let gas_cost := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "add" |), + make_list [ + make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ] + ], + make_dict [] + |) in + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_COLD_SLOAD" |) + M.get_name (| globals, "GAS_COLD_SLOAD" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_name (| globals, "original_value" |), M.get_name (| globals, "current_value" |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_name (| globals, "current_value" |), M.get_name (| globals, "new_value" |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_STORAGE_SET" |) + M.get_name (| globals, "GAS_STORAGE_SET" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let gas_cost := BinOp.add + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_UPDATE" |), + M.get_name (| globals, "GAS_COLD_SLOAD" |) + |) + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_UPDATE" |), + M.get_name (| globals, "GAS_COLD_SLOAD" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_WARM_ACCESS" |) + M.get_name (| globals, "GAS_WARM_ACCESS" |) in + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| M.get_name (| globals, "current_value" |), M.get_name (| globals, "new_value" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "new_value" |), Constant.int 0 |) + )) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.sub, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "original_value" |), M.get_name (| globals, "new_value" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_SET" |), + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.sub (| + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_UPDATE" |), + M.get_name (| globals, "GAS_COLD_SLOAD" |) + |), + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "gas_cost" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "set_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |); + M.get_name (| globals, "new_value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition tload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Loads to the stack, the value corresponding to a certain key from the + transient storage of the current account. + Parameters + ---------- + evm : + The current EVM frame. + " in + let key := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "get_transient_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "transient_storage" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition tstore : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a value at a certain key in the current context's transient storage. + Parameters + ---------- + evm : + The current EVM frame. + " in + let key := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let new_value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "set_transient_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "transient_storage" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |); + M.get_name (| globals, "new_value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/vm/interpreter.v b/CoqOfPython/ethereum/cancun/vm/interpreter.v new file mode 100644 index 0000000..e394207 --- /dev/null +++ b/CoqOfPython/ethereum/cancun/vm/interpreter.v @@ -0,0 +1,652 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Interpreter +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +A straightforward interpreter that executes EVM code. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Iterable : + IsGlobalAlias globals typing.globals "Iterable". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.trace. +Axiom ethereum_trace_EvmStop : + IsGlobalAlias globals ethereum.trace.globals "EvmStop". +Axiom ethereum_trace_OpEnd : + IsGlobalAlias globals ethereum.trace.globals "OpEnd". +Axiom ethereum_trace_OpException : + IsGlobalAlias globals ethereum.trace.globals "OpException". +Axiom ethereum_trace_OpStart : + IsGlobalAlias globals ethereum.trace.globals "OpStart". +Axiom ethereum_trace_PrecompileEnd : + IsGlobalAlias globals ethereum.trace.globals "PrecompileEnd". +Axiom ethereum_trace_PrecompileStart : + IsGlobalAlias globals ethereum.trace.globals "PrecompileStart". +Axiom ethereum_trace_TransactionEnd : + IsGlobalAlias globals ethereum.trace.globals "TransactionEnd". +Axiom ethereum_trace_evm_trace : + IsGlobalAlias globals ethereum.trace.globals "evm_trace". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_account_exists_and_is_empty : + IsGlobalAlias globals state.globals "account_exists_and_is_empty". +Axiom state_account_has_code_or_nonce : + IsGlobalAlias globals state.globals "account_has_code_or_nonce". +Axiom state_begin_transaction : + IsGlobalAlias globals state.globals "begin_transaction". +Axiom state_commit_transaction : + IsGlobalAlias globals state.globals "commit_transaction". +Axiom state_destroy_storage : + IsGlobalAlias globals state.globals "destroy_storage". +Axiom state_increment_nonce : + IsGlobalAlias globals state.globals "increment_nonce". +Axiom state_mark_account_created : + IsGlobalAlias globals state.globals "mark_account_created". +Axiom state_move_ether : + IsGlobalAlias globals state.globals "move_ether". +Axiom state_rollback_transaction : + IsGlobalAlias globals state.globals "rollback_transaction". +Axiom state_set_code : + IsGlobalAlias globals state.globals "set_code". +Axiom state_touch_account : + IsGlobalAlias globals state.globals "touch_account". + +Require vm. +Axiom vm_Message : + IsGlobalAlias globals vm.globals "Message". + +Require vm.gas. +Axiom vm_gas_GAS_CODE_DEPOSIT : + IsGlobalAlias globals vm.gas.globals "GAS_CODE_DEPOSIT". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require vm.precompiled_contracts.mapping. +Axiom vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : + IsGlobalAlias globals vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". + +Require __init__. +Axiom __init___Environment : + IsGlobalAlias globals __init__.globals "Environment". +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_AddressCollision : + IsGlobalAlias globals exceptions.globals "AddressCollision". +Axiom exceptions_ExceptionalHalt : + IsGlobalAlias globals exceptions.globals "ExceptionalHalt". +Axiom exceptions_InvalidContractPrefix : + IsGlobalAlias globals exceptions.globals "InvalidContractPrefix". +Axiom exceptions_InvalidOpcode : + IsGlobalAlias globals exceptions.globals "InvalidOpcode". +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". +Axiom exceptions_Revert : + IsGlobalAlias globals exceptions.globals "Revert". +Axiom exceptions_StackDepthLimitError : + IsGlobalAlias globals exceptions.globals "StackDepthLimitError". + +Require instructions. +Axiom instructions_Ops : + IsGlobalAlias globals instructions.globals "Ops". +Axiom instructions_op_implementation : + IsGlobalAlias globals instructions.globals "op_implementation". + +Require runtime. +Axiom runtime_get_valid_jump_destinations : + IsGlobalAlias globals runtime.globals "get_valid_jump_destinations". + +Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1024 + ], + make_dict [] + |) +)). + +Definition MAX_CODE_SIZE : Value.t := M.run ltac:(M.monadic ( + Constant.int 24576 +)). + +Definition MessageCallOutput : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition process_message_call : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + If `message.current` is empty then it creates a smart contract + else it executes a call from the `message.caller` to the `message.target`. + + Parameters + ---------- + message : + Transaction specific items. + + env : + External items required for EVM execution. + + Returns + ------- + output : `MessageCallOutput` + Output of the message call + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_name (| globals, "message" |), "target" |), M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let is_collision := + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_name (| globals, "is_collision" |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallOutput" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "tuple" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "AddressCollision" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let evm := + M.call (| + M.get_name (| globals, "process_create_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let evm := + M.call (| + M.get_name (| globals, "process_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_field (| M.get_name (| globals, "message" |), "target" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_field (| M.get_name (| globals, "message" |), "target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( +(* At stmt: unsupported node type: AnnAssign *) + let accounts_to_delete := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let touched_accounts := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let refund_counter := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let logs := + M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in + let accounts_to_delete := + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in + let touched_accounts := + M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |) in + let refund_counter := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let tx_end := + M.call (| + M.get_name (| globals, "TransactionEnd" |), + make_list [ + BinOp.sub (| + M.get_field (| M.get_name (| globals, "message" |), "gas" |), + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + |); + M.get_field (| M.get_name (| globals, "evm" |), "output" |); + M.get_field (| M.get_name (| globals, "evm" |), "error" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "evm_trace" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "tx_end" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallOutput" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition process_create_message : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + Executes a call to create a smart contract. + + Parameters + ---------- + message : + Transaction specific items. + env : + External items required for EVM execution. + + Returns + ------- + evm: :py:class:`~ethereum.cancun.vm.Evm` + Items containing execution specific objects. + " in + let _ := M.call (| + M.get_name (| globals, "begin_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "transient_storage" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "destroy_storage" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "mark_account_created" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let evm := + M.call (| + M.get_name (| globals, "process_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), + (* then *) + ltac:(M.monadic ( + let contract_code := + M.get_field (| M.get_name (| globals, "evm" |), "output" |) in + let contract_code_gas := + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "contract_code" |) + ], + make_dict [] + |), + M.get_name (| globals, "GAS_CODE_DEPOSIT" |) + |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "rollback_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "transient_storage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.get_name (| globals, "evm" |) + |) in + M.pure Constant.None_)). + +Definition process_message : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + Executes a call to create a smart contract. + + Parameters + ---------- + message : + Transaction specific items. + env : + External items required for EVM execution. + + Returns + ------- + evm: :py:class:`~ethereum.cancun.vm.Evm` + Items containing execution specific objects + " in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_field (| M.get_name (| globals, "message" |), "depth" |), M.get_name (| globals, "STACK_DEPTH_LIMIT" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "StackDepthLimitError" |), + make_list [ + Constant.str "Stack depth limit reached" + ], + make_dict [] + |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "begin_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "transient_storage" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "touch_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + M.get_field (| M.get_name (| globals, "message" |), "should_transfer_value" |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_field (| M.get_name (| globals, "message" |), "value" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "move_ether" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "caller" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |); + M.get_field (| M.get_name (| globals, "message" |), "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let evm := + M.call (| + M.get_name (| globals, "execute_code" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "rollback_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "transient_storage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "commit_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "transient_storage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.get_name (| globals, "evm" |) + |) in + M.pure Constant.None_)). + +Definition execute_code : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + Executes bytecode present in the `message`. + + Parameters + ---------- + message : + Transaction specific items. + env : + External items required for EVM execution. + + Returns + ------- + evm: `ethereum.vm.EVM` + Items containing execution specific objects + " in + let code := + M.get_field (| M.get_name (| globals, "message" |), "code" |) in + let valid_jump_destinations := + M.call (| + M.get_name (| globals, "get_valid_jump_destinations" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) in + let evm := + M.call (| + M.get_name (| globals, "Evm" |), + make_list [], + make_dict [] + |) in +(* At stmt: unsupported node type: Try *) + let _ := M.return_ (| + M.get_name (| globals, "evm" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/vm/memory.v b/CoqOfPython/ethereum/cancun/vm/memory.v new file mode 100644 index 0000000..fa8d906 --- /dev/null +++ b/CoqOfPython/ethereum/cancun/vm/memory.v @@ -0,0 +1,153 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Memory +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +EVM memory operations. +". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_right_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "right_pad_zero_bytes". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". + +Definition memory_write : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "memory"; "start_position"; "value" ] |) in + let _ := Constant.str " + Writes to memory. + + Parameters + ---------- + memory : + Memory contents of the EVM. + start_position : + Starting pointer to the memory. + value : + Data to write to memory. + " in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) |), + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_)). + +Definition memory_read_bytes : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "memory"; "start_position"; "size" ] |) in + let _ := Constant.str " + Read bytes from memory. + + Parameters + ---------- + memory : + Memory contents of the EVM. + start_position : + Starting pointer to the memory. + size : + Size of the data that needs to be read from `start_position`. + + Returns + ------- + data_bytes : + Data read from memory. + " in + let _ := M.return_ (| + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |) + |) in + M.pure Constant.None_)). + +Definition buffer_read : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "buffer"; "start_position"; "size" ] |) in + let _ := Constant.str " + Read bytes from a buffer. Padding with zeros if necessary. + + Parameters + ---------- + buffer : + Memory contents of the EVM. + start_position : + Starting pointer to the memory. + size : + Size of the data that needs to be read from `start_position`. + + Returns + ------- + data_bytes : + Data read from memory. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "right_pad_zero_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/__init__.v new file mode 100644 index 0000000..b78533a --- /dev/null +++ b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/__init__.v @@ -0,0 +1,127 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Precompiled Contract Addresses +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Addresses of precompiled contracts and mappings to their +implementations. +". + +Require utils.hexadecimal. +Axiom utils_hexadecimal_hex_to_address : + IsGlobalAlias globals utils.hexadecimal.globals "hex_to_address". + +Definition __all__ : Value.t := M.run ltac:(M.monadic ( + make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS"; Constant.str "MODEXP_ADDRESS"; Constant.str "ALT_BN128_ADD_ADDRESS"; Constant.str "ALT_BN128_MUL_ADDRESS"; Constant.str "ALT_BN128_PAIRING_CHECK_ADDRESS"; Constant.str "BLAKE2F_ADDRESS"; Constant.str "POINT_EVALUATION_ADDRESS" ] +)). + +Definition ECRECOVER_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x01" + ], + make_dict [] + |) +)). + +Definition SHA256_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x02" + ], + make_dict [] + |) +)). + +Definition RIPEMD160_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x03" + ], + make_dict [] + |) +)). + +Definition IDENTITY_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x04" + ], + make_dict [] + |) +)). + +Definition MODEXP_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x05" + ], + make_dict [] + |) +)). + +Definition ALT_BN128_ADD_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x06" + ], + make_dict [] + |) +)). + +Definition ALT_BN128_MUL_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x07" + ], + make_dict [] + |) +)). + +Definition ALT_BN128_PAIRING_CHECK_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x08" + ], + make_dict [] + |) +)). + +Definition BLAKE2F_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x09" + ], + make_dict [] + |) +)). + +Definition POINT_EVALUATION_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x0a" + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/alt_bn128.v new file mode 100644 index 0000000..19b83fc --- /dev/null +++ b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/alt_bn128.v @@ -0,0 +1,673 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) ALT_BN128 CONTRACTS +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the ALT_BN128 precompiled contracts. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.alt_bn128. +Axiom ethereum_crypto_alt_bn128_ALT_BN128_CURVE_ORDER : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "ALT_BN128_CURVE_ORDER". +Axiom ethereum_crypto_alt_bn128_ALT_BN128_PRIME : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "ALT_BN128_PRIME". +Axiom ethereum_crypto_alt_bn128_BNF : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF". +Axiom ethereum_crypto_alt_bn128_BNF2 : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF2". +Axiom ethereum_crypto_alt_bn128_BNF12 : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF12". +Axiom ethereum_crypto_alt_bn128_BNP : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNP". +Axiom ethereum_crypto_alt_bn128_BNP2 : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNP2". +Axiom ethereum_crypto_alt_bn128_pairing : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "pairing". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require vm.memory. +Axiom vm_memory_buffer_read : + IsGlobalAlias globals vm.memory.globals "buffer_read". + +Require exceptions. +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". + +Definition alt_bn128_add : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + The ALT_BN128 addition precompiled contract. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 150 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x0_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x0_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "x0_bytes" |) + ], + make_dict [] + |) in + let y0_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y0_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "y0_bytes" |) + ], + make_dict [] + |) in + let x1_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x1_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "x1_bytes" |) + ], + make_dict [] + |) in + let y1_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y1_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "y1_bytes" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ] do + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "i" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. +(* At stmt: unsupported node type: Try *) + let p := + BinOp.add (| + M.get_name (| globals, "p0" |), + M.get_name (| globals, "p1" |) + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + BinOp.add (| + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "p" |), "x" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "p" |), "y" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) + |) in + M.pure Constant.None_)). + +Definition alt_bn128_mul : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + The ALT_BN128 multiplication precompiled contract. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 6000 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x0_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x0_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "x0_bytes" |) + ], + make_dict [] + |) in + let y0_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y0_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "y0_bytes" |) + ], + make_dict [] + |) in + let n := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ] do + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "i" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. +(* At stmt: unsupported node type: Try *) + let p := + M.call (| + M.get_field (| M.get_name (| globals, "p0" |), "mul_by" |), + make_list [ + M.get_name (| globals, "n" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + BinOp.add (| + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "p" |), "x" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "p" |), "y" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) + |) in + M.pure Constant.None_)). + +Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + The ALT_BN128 pairing check precompiled contract. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 34000, + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 192 + |) + |), + Constant.int 45000 + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 192 + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 192 + |) + ], + make_dict [] + |) do + let values := + make_list [] in + For M.get_name (| globals, "j" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 6 + ], + make_dict [] + |) do + let value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "data" |), BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + M.get_name (| globals, "j" |) + |) + |):BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "j" |), + Constant.int 1 + |) + |) + |) |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "value" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "values" |), "append" |), + make_list [ + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + EndFor. +(* At stmt: unsupported node type: Try *) + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.call (| + M.get_field (| M.get_name (| globals, "p" |), "mul_by" |), + make_list [ + M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) + ], + make_dict [] + |), M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) |); + M.get_name (| globals, "OutOfGasError" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.call (| + M.get_field (| M.get_name (| globals, "q" |), "mul_by" |), + make_list [ + M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) + ], + make_dict [] + |), M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) |); + M.get_name (| globals, "OutOfGasError" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "p" |), M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_name (| globals, "q" |), M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let result := + BinOp.mult (| + M.get_name (| globals, "result" |), + M.call (| + M.get_name (| globals, "pairing" |), + make_list [ + M.get_name (| globals, "q" |); + M.get_name (| globals, "p" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "result" |), M.call (| + M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/blake2f.v b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/blake2f.v new file mode 100644 index 0000000..5903066 --- /dev/null +++ b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/blake2f.v @@ -0,0 +1,122 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Blake2 PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `Blake2` precompiled contract. +". + +Require ethereum.crypto.blake2. +Axiom ethereum_crypto_blake2_Blake2b : + IsGlobalAlias globals ethereum.crypto.blake2.globals "Blake2b". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_BLAKE2_PER_ROUND : + IsGlobalAlias globals vm.gas.globals "GAS_BLAKE2_PER_ROUND". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require exceptions. +Axiom exceptions_InvalidParameter : + IsGlobalAlias globals exceptions.globals "InvalidParameter". + +Definition blake2f : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the Blake2 hash to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), Constant.int 213 |); + M.get_name (| globals, "InvalidParameter" |) + ], + make_dict [] + |) in + let blake2b := + M.call (| + M.get_name (| globals, "Blake2b" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "rounds" |); M.get_name (| globals, "h" |); M.get_name (| globals, "m" |); M.get_name (| globals, "t_0" |); M.get_name (| globals, "t_1" |); M.get_name (| globals, "f" |) ], + M.call (| + M.get_field (| M.get_name (| globals, "blake2b" |), "get_blake2_parameters" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.mult (| + M.get_name (| globals, "GAS_BLAKE2_PER_ROUND" |), + M.get_name (| globals, "rounds" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.in (| M.get_name (| globals, "f" |), make_list [ + Constant.int 0; + Constant.int 1 + ] |); + M.get_name (| globals, "InvalidParameter" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.get_name (| globals, "blake2b" |), "compress" |), + make_list [ + M.get_name (| globals, "rounds" |); + M.get_name (| globals, "h" |); + M.get_name (| globals, "m" |); + M.get_name (| globals, "t_0" |); + M.get_name (| globals, "t_1" |); + M.get_name (| globals, "f" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/ecrecover.v new file mode 100644 index 0000000..cc351b5 --- /dev/null +++ b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/ecrecover.v @@ -0,0 +1,269 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) ECRECOVER PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the ECRECOVER precompiled contract. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require ethereum.crypto.elliptic_curve. +Axiom ethereum_crypto_elliptic_curve_SECP256K1N : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_left_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_ECRECOVER : + IsGlobalAlias globals vm.gas.globals "GAS_ECRECOVER". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require vm.memory. +Axiom vm_memory_buffer_read : + IsGlobalAlias globals vm.memory.globals "buffer_read". + +Definition ecrecover : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Decrypts the address using elliptic curve DSA recovery mechanism and writes + the address to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_ECRECOVER" |) + ], + make_dict [] + |) in + let message_hash_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let message_hash := + M.call (| + M.get_name (| globals, "Hash32" |), + make_list [ + M.get_name (| globals, "message_hash_bytes" |) + ], + make_dict [] + |) in + let v := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let r := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let s := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 27 |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 28 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| Constant.int 0, M.get_name (| globals, "r" |) |), + ltac:(M.monadic ( + Compare.gt_e (| M.get_name (| globals, "r" |), M.get_name (| globals, "SECP256K1N" |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| Constant.int 0, M.get_name (| globals, "s" |) |), + ltac:(M.monadic ( + Compare.gt_e (| M.get_name (| globals, "s" |), M.get_name (| globals, "SECP256K1N" |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in +(* At stmt: unsupported node type: Try *) + let address := + M.get_subscript (| M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), Constant.int 12:Constant.int 32 |) in + let padded_address := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "address" |); + Constant.int 32 + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.get_name (| globals, "padded_address" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/identity.v new file mode 100644 index 0000000..fa96704 --- /dev/null +++ b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/identity.v @@ -0,0 +1,94 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) IDENTITY PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `IDENTITY` precompiled contract. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_IDENTITY : + IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY". +Axiom vm_gas_GAS_IDENTITY_WORD : + IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY_WORD". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition identity : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the message data to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let word_count := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_IDENTITY" |), + BinOp.mult (| + M.get_name (| globals, "GAS_IDENTITY_WORD" |), + M.get_name (| globals, "word_count" |) + |) + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.get_name (| globals, "data" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/mapping.v new file mode 100644 index 0000000..062ec88 --- /dev/null +++ b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/mapping.v @@ -0,0 +1,88 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Precompiled Contract Addresses +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Mapping of precompiled contracts their implementations. +". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require __init__. +Axiom __init___ALT_BN128_ADD_ADDRESS : + IsGlobalAlias globals __init__.globals "ALT_BN128_ADD_ADDRESS". +Axiom __init___ALT_BN128_MUL_ADDRESS : + IsGlobalAlias globals __init__.globals "ALT_BN128_MUL_ADDRESS". +Axiom __init___ALT_BN128_PAIRING_CHECK_ADDRESS : + IsGlobalAlias globals __init__.globals "ALT_BN128_PAIRING_CHECK_ADDRESS". +Axiom __init___BLAKE2F_ADDRESS : + IsGlobalAlias globals __init__.globals "BLAKE2F_ADDRESS". +Axiom __init___ECRECOVER_ADDRESS : + IsGlobalAlias globals __init__.globals "ECRECOVER_ADDRESS". +Axiom __init___IDENTITY_ADDRESS : + IsGlobalAlias globals __init__.globals "IDENTITY_ADDRESS". +Axiom __init___MODEXP_ADDRESS : + IsGlobalAlias globals __init__.globals "MODEXP_ADDRESS". +Axiom __init___POINT_EVALUATION_ADDRESS : + IsGlobalAlias globals __init__.globals "POINT_EVALUATION_ADDRESS". +Axiom __init___RIPEMD160_ADDRESS : + IsGlobalAlias globals __init__.globals "RIPEMD160_ADDRESS". +Axiom __init___SHA256_ADDRESS : + IsGlobalAlias globals __init__.globals "SHA256_ADDRESS". + +Require alt_bn128. +Axiom alt_bn128_alt_bn128_add : + IsGlobalAlias globals alt_bn128.globals "alt_bn128_add". +Axiom alt_bn128_alt_bn128_mul : + IsGlobalAlias globals alt_bn128.globals "alt_bn128_mul". +Axiom alt_bn128_alt_bn128_pairing_check : + IsGlobalAlias globals alt_bn128.globals "alt_bn128_pairing_check". + +Require blake2f. +Axiom blake2f_blake2f : + IsGlobalAlias globals blake2f.globals "blake2f". + +Require ecrecover. +Axiom ecrecover_ecrecover : + IsGlobalAlias globals ecrecover.globals "ecrecover". + +Require identity. +Axiom identity_identity : + IsGlobalAlias globals identity.globals "identity". + +Require modexp. +Axiom modexp_modexp : + IsGlobalAlias globals modexp.globals "modexp". + +Require point_evaluation. +Axiom point_evaluation_point_evaluation : + IsGlobalAlias globals point_evaluation.globals "point_evaluation". + +Require ripemd160. +Axiom ripemd160_ripemd160 : + IsGlobalAlias globals ripemd160.globals "ripemd160". + +Require sha256. +Axiom sha256_sha256 : + IsGlobalAlias globals sha256.globals "sha256". + +(* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/modexp.v new file mode 100644 index 0000000..544949e --- /dev/null +++ b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/modexp.v @@ -0,0 +1,608 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) MODEXP PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `MODEXP` precompiled contract. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require memory. +Axiom memory_buffer_read : + IsGlobalAlias globals memory.globals "buffer_read". + +Definition GQUADDIVISOR : Value.t := M.run ltac:(M.monadic ( + Constant.int 3 +)). + +Definition modexp : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Calculates `(base**exp) % modulus` for arbitrary sized `base`, `exp` and. + `modulus`. The return value is the same length as the modulus. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let base_length := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exp_length := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let modulus_length := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exp_start := + BinOp.add (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |), + M.get_name (| globals, "base_length" |) + |) in + let exp_head := + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.get_name (| globals, "exp_start" |); + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.get_name (| globals, "exp_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "gas_cost" |), + make_list [ + M.get_name (| globals, "base_length" |); + M.get_name (| globals, "modulus_length" |); + M.get_name (| globals, "exp_length" |); + M.get_name (| globals, "exp_head" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_name (| globals, "base_length" |), Constant.int 0 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "modulus_length" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [], + make_dict [] + |) + |) in + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let base := + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |); + M.get_name (| globals, "base_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exp := + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.get_name (| globals, "exp_start" |); + M.get_name (| globals, "exp_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let modulus_start := + BinOp.add (| + M.get_name (| globals, "exp_start" |), + M.get_name (| globals, "exp_length" |) + |) in + let modulus := + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.get_name (| globals, "modulus_start" |); + M.get_name (| globals, "modulus_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "modulus" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + BinOp.mult (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |), + M.get_name (| globals, "modulus_length" |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pow" |), + make_list [ + M.get_name (| globals, "base" |); + M.get_name (| globals, "exp" |); + M.get_name (| globals, "modulus" |) + ], + make_dict [] + |) + ], + make_dict [] + |), "to_bytes" |), + make_list [ + M.get_name (| globals, "modulus_length" |); + Constant.str "big" + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition complexity : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "base_length"; "modulus_length" ] |) in + let _ := Constant.str " + Estimate the complexity of performing a modular exponentiation. + + Parameters + ---------- + + base_length : + Length of the array representing the base integer. + + modulus_length : + Length of the array representing the modulus integer. + + Returns + ------- + + complexity : `Uint` + Complexity of performing the operation. + " in + let max_length := + M.call (| + M.get_name (| globals, "max" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "base_length" |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "modulus_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + BinOp.add (| + M.get_name (| globals, "max_length" |), + Constant.int 7 + |), + Constant.int 8 + |) in + let _ := M.return_ (| + BinOp.pow (| + M.get_name (| globals, "words" |), + Constant.int 2 + |) + |) in + M.pure Constant.None_)). + +Definition iterations : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "exponent_length"; "exponent_head" ] |) in + let _ := Constant.str " + Calculate the number of iterations required to perform a modular + exponentiation. + + Parameters + ---------- + + exponent_length : + Length of the array representing the exponent integer. + + exponent_head : + First 32 bytes of the exponent (with leading zero padding if it is + shorter than 32 bytes), as an unsigned integer. + + Returns + ------- + + iterations : `Uint` + Number of iterations. + " in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.lt_e (| M.get_name (| globals, "exponent_length" |), Constant.int 32 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "exponent_head" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let count := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| M.get_name (| globals, "exponent_length" |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let bit_length := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "exponent_head" |), "bit_length" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "bit_length" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let bit_length := BinOp.sub + Constant.int 1 + Constant.int 1 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let count := + M.get_name (| globals, "bit_length" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let length_part := + BinOp.mult (| + Constant.int 8, + BinOp.sub (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "exponent_length" |) + ], + make_dict [] + |), + Constant.int 32 + |) + |) in + let bits_part := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "exponent_head" |), "bit_length" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "bits_part" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let bits_part := BinOp.sub + Constant.int 1 + Constant.int 1 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let count := + BinOp.add (| + M.get_name (| globals, "length_part" |), + M.get_name (| globals, "bits_part" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "max" |), + make_list [ + M.get_name (| globals, "count" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition gas_cost : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "base_length"; "modulus_length"; "exponent_length"; "exponent_head" ] |) in + let _ := Constant.str " + Calculate the gas cost of performing a modular exponentiation. + + Parameters + ---------- + + base_length : + Length of the array representing the base integer. + + modulus_length : + Length of the array representing the modulus integer. + + exponent_length : + Length of the array representing the exponent integer. + + exponent_head : + First 32 bytes of the exponent (with leading zero padding if it is + shorter than 32 bytes), as an unsigned integer. + + Returns + ------- + + gas_cost : `Uint` + Gas required for performing the operation. + " in + let multiplication_complexity := + M.call (| + M.get_name (| globals, "complexity" |), + make_list [ + M.get_name (| globals, "base_length" |); + M.get_name (| globals, "modulus_length" |) + ], + make_dict [] + |) in + let iteration_count := + M.call (| + M.get_name (| globals, "iterations" |), + make_list [ + M.get_name (| globals, "exponent_length" |); + M.get_name (| globals, "exponent_head" |) + ], + make_dict [] + |) in + let cost := + BinOp.mult (| + M.get_name (| globals, "multiplication_complexity" |), + M.get_name (| globals, "iteration_count" |) + |) in + let cost := BinOp.floor_div + M.get_name (| globals, "GQUADDIVISOR" |) + M.get_name (| globals, "GQUADDIVISOR" |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "max" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 200 + ], + make_dict [] + |); + M.get_name (| globals, "cost" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/point_evaluation.v b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/point_evaluation.v new file mode 100644 index 0000000..d9af97f --- /dev/null +++ b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/point_evaluation.v @@ -0,0 +1,173 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) POINT EVALUATION PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the POINT EVALUATION precompiled contract. +". + +Require eth2spec.deneb.mainnet. +Axiom eth2spec_deneb_mainnet_KZGCommitment : + IsGlobalAlias globals eth2spec.deneb.mainnet.globals "KZGCommitment". +Axiom eth2spec_deneb_mainnet_kzg_commitment_to_versioned_hash : + IsGlobalAlias globals eth2spec.deneb.mainnet.globals "kzg_commitment_to_versioned_hash". +Axiom eth2spec_deneb_mainnet_verify_kzg_proof : + IsGlobalAlias globals eth2spec.deneb.mainnet.globals "verify_kzg_proof". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.exceptions. +Axiom vm_exceptions_KZGProofError : + IsGlobalAlias globals vm.exceptions.globals "KZGProofError". + +Require vm.gas. +Axiom vm_gas_GAS_POINT_EVALUATION : + IsGlobalAlias globals vm.gas.globals "GAS_POINT_EVALUATION". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition FIELD_ELEMENTS_PER_BLOB : Value.t := M.run ltac:(M.monadic ( + Constant.int 4096 +)). + +Definition BLS_MODULUS : Value.t := M.run ltac:(M.monadic ( + Constant.int 52435875175126190479447740508185965837690552500527637822603658699938581184513 +)). + +Definition VERSIONED_HASH_VERSION_KZG : Value.t := M.run ltac:(M.monadic ( + (* At constant: unsupported node type: Constant *) +)). + +Definition point_evaluation : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + A pre-compile that verifies a KZG proof which claims that a blob + (represented by a commitment) evaluates to a given value at a given point. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), Constant.int 192 |); + M.get_name (| globals, "KZGProofError" |) + ], + make_dict [] + |) in + let versioned_hash := + M.get_subscript (| M.get_name (| globals, "data" |), (* At expr: unsupported node type: NoneType *):Constant.int 32 |) in + let z := + M.get_subscript (| M.get_name (| globals, "data" |), Constant.int 32:Constant.int 64 |) in + let y := + M.get_subscript (| M.get_name (| globals, "data" |), Constant.int 64:Constant.int 96 |) in + let commitment := + M.call (| + M.get_name (| globals, "KZGCommitment" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "data" |), Constant.int 96:Constant.int 144 |) + ], + make_dict [] + |) in + let proof := + M.get_subscript (| M.get_name (| globals, "data" |), Constant.int 144:Constant.int 192 |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_POINT_EVALUATION" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.call (| + M.get_name (| globals, "kzg_commitment_to_versioned_hash" |), + make_list [ + M.get_name (| globals, "commitment" |) + ], + make_dict [] + |), M.get_name (| globals, "versioned_hash" |) |); + M.get_name (| globals, "KZGProofError" |) + ], + make_dict [] + |) in +(* At stmt: unsupported node type: Try *) + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + M.get_name (| globals, "kzg_proof_verification" |); + M.get_name (| globals, "KZGProofError" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + BinOp.add (| + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "FIELD_ELEMENTS_PER_BLOB" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "BLS_MODULUS" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/ripemd160.v new file mode 100644 index 0000000..96f8dcd --- /dev/null +++ b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/ripemd160.v @@ -0,0 +1,122 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) RIPEMD160 PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `RIPEMD160` precompiled contract. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_left_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_RIPEMD160 : + IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160". +Axiom vm_gas_GAS_RIPEMD160_WORD : + IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160_WORD". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition ripemd160 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the ripemd160 hash to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let word_count := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_RIPEMD160" |), + BinOp.mult (| + M.get_name (| globals, "GAS_RIPEMD160_WORD" |), + M.get_name (| globals, "word_count" |) + |) + |) + ], + make_dict [] + |) in + let hash_bytes := + M.call (| + M.get_field (| M.call (| + M.get_field (| M.get_name (| globals, "hashlib" |), "new" |), + make_list [ + Constant.str "ripemd160"; + M.get_name (| globals, "data" |) + ], + make_dict [] + |), "digest" |), + make_list [], + make_dict [] + |) in + let padded_hash := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "hash_bytes" |); + Constant.int 32 + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.get_name (| globals, "padded_hash" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/sha256.v new file mode 100644 index 0000000..9f6d2bf --- /dev/null +++ b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/sha256.v @@ -0,0 +1,106 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) SHA256 PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `SHA256` precompiled contract. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_SHA256 : + IsGlobalAlias globals vm.gas.globals "GAS_SHA256". +Axiom vm_gas_GAS_SHA256_WORD : + IsGlobalAlias globals vm.gas.globals "GAS_SHA256_WORD". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition sha256 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the sha256 hash to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let word_count := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_SHA256" |), + BinOp.mult (| + M.get_name (| globals, "GAS_SHA256_WORD" |), + M.get_name (| globals, "word_count" |) + |) + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_field (| M.get_name (| globals, "hashlib" |), "sha256" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), "digest" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/vm/runtime.v b/CoqOfPython/ethereum/cancun/vm/runtime.v new file mode 100644 index 0000000..835b46c --- /dev/null +++ b/CoqOfPython/ethereum/cancun/vm/runtime.v @@ -0,0 +1,125 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Runtime Operations +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Runtime related operations used while executing EVM code. +". + +Require typing. +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require instructions. +Axiom instructions_Ops : + IsGlobalAlias globals instructions.globals "Ops". + +Definition get_valid_jump_destinations : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "code" ] |) in + let _ := Constant.str " + Analyze the evm code to obtain the set of valid jump destinations. + + Valid jump destinations are defined as follows: + * The jump destination is less than the length of the code. + * The jump destination should have the `JUMPDEST` opcode (0x5B). + * The jump destination shouldn't be part of the data corresponding to + `PUSH-N` opcodes. + + Note - Jump destinations are 0-indexed. + + Parameters + ---------- + code : + The EVM code which is to be executed. + + Returns + ------- + valid_jump_destinations: `Set[Uint]` + The set of valid jump destinations in the code. + " in + let valid_jump_destinations := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let pc := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + While Compare.lt (| M.get_name (| globals, "pc" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) |) do +(* At stmt: unsupported node type: Try *) + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "current_opcode" |), M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), + make_list [ + M.get_name (| globals, "pc" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + (* At expr: unsupported node type: Compare *), + (* then *) + ltac:(M.monadic ( + let push_data_size := + BinOp.add (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) + |), + Constant.int 1 + |) in + let pc := BinOp.add + M.get_name (| globals, "push_data_size" |) + M.get_name (| globals, "push_data_size" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let pc := BinOp.add + Constant.int 1 + Constant.int 1 in + EndWhile. + let _ := M.return_ (| + M.get_name (| globals, "valid_jump_destinations" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/vm/stack.v b/CoqOfPython/ethereum/cancun/vm/stack.v new file mode 100644 index 0000000..42ea42d --- /dev/null +++ b/CoqOfPython/ethereum/cancun/vm/stack.v @@ -0,0 +1,120 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Stack +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the stack operators for the EVM. +". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require exceptions. +Axiom exceptions_StackOverflowError : + IsGlobalAlias globals exceptions.globals "StackOverflowError". +Axiom exceptions_StackUnderflowError : + IsGlobalAlias globals exceptions.globals "StackUnderflowError". + +Definition pop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "stack" ] |) in + let _ := Constant.str " + Pops the top item off of `stack`. + + Parameters + ---------- + stack : + EVM stack. + + Returns + ------- + value : `U256` + The top element on the stack. + + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "StackUnderflowError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "pop" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition push : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "stack"; "value" ] |) in + let _ := Constant.str " + Pushes `value` onto `stack`. + + Parameters + ---------- + stack : + EVM stack. + + value : + Item to be pushed onto `stack`. + + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), Constant.int 1024 |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "StackOverflowError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "append" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/__init__.v b/CoqOfPython/ethereum/constantinople/__init__.v new file mode 100644 index 0000000..1ebc0ac --- /dev/null +++ b/CoqOfPython/ethereum/constantinople/__init__.v @@ -0,0 +1,24 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +The Constantinople fork reduces mining rewards, delays the difficulty bomb, +and introduces new EVM instructions for logical shifts, counterfactual +contract deployment, and computing bytecode hashes. +". + +Require ethereum.fork_criteria. +Axiom ethereum_fork_criteria_ByBlockNumber : + IsGlobalAlias globals ethereum.fork_criteria.globals "ByBlockNumber". + +Definition FORK_CRITERIA : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "ByBlockNumber" |), + make_list [ + Constant.int 7280000 + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/constantinople/blocks.v b/CoqOfPython/ethereum/constantinople/blocks.v new file mode 100644 index 0000000..6501788 --- /dev/null +++ b/CoqOfPython/ethereum/constantinople/blocks.v @@ -0,0 +1,93 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +A `Block` is a single link in the chain that is Ethereum. Each `Block` contains +a `Header` and zero or more transactions. Each `Header` contains associated +metadata like the block number, parent block hash, and how much gas was +consumed by its transactions. + +Together, these blocks form a cryptographically secure journal recording the +history of all state transitions that have happened since the genesis of the +chain. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes8 : + IsGlobalAlias globals base_types.globals "Bytes8". +Axiom base_types_Bytes32 : + IsGlobalAlias globals base_types.globals "Bytes32". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require crypto.hash. +Axiom crypto_hash_Hash32 : + IsGlobalAlias globals crypto.hash.globals "Hash32". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Require transactions. +Axiom transactions_Transaction : + IsGlobalAlias globals transactions.globals "Transaction". + +Definition Header : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Block : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Log : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Receipt : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. diff --git a/CoqOfPython/ethereum/constantinople/bloom.v b/CoqOfPython/ethereum/constantinople/bloom.v new file mode 100644 index 0000000..04b5d9f --- /dev/null +++ b/CoqOfPython/ethereum/constantinople/bloom.v @@ -0,0 +1,164 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Logs Bloom +^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +This modules defines functions for calculating bloom filters of logs. For the +general theory of bloom filters see e.g. `Wikipedia +`_. Bloom filters are used to allow +for efficient searching of logs by address and/or topic, by rapidly +eliminating blocks and receipts from their search. +". + +Require typing. +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require fork_types. +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". + +Definition add_to_bloom : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "bloom"; "bloom_entry" ] |) in + let _ := Constant.str " + Add a bloom entry to the bloom filter (`bloom`). + + The number of hash functions used is 3. They are calculated by taking the + least significant 11 bits from the first 3 16-bit words of the + `keccak_256()` hash of `bloom_entry`. + + Parameters + ---------- + bloom : + The bloom filter. + bloom_entry : + An entry which is to be added to bloom filter. + " in + let hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "bloom_entry" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "idx" |) in make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ] do + let bit_to_set := + BinOp.bit_and (| + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |):BinOp.add (| + M.get_name (| globals, "idx" |), + Constant.int 2 + |) |) + ], + make_dict [] + |), + Constant.int 2047 + |) in + let bit_index := + BinOp.sub (| + Constant.int 2047, + M.get_name (| globals, "bit_to_set" |) + |) in + let byte_index := + BinOp.floor_div (| + M.get_name (| globals, "bit_index" |), + Constant.int 8 + |) in + let bit_value := + BinOp.l_shift (| + Constant.int 1, + BinOp.sub (| + Constant.int 7, + BinOp.mod_ (| + M.get_name (| globals, "bit_index" |), + Constant.int 8 + |) + |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), + BinOp.bit_or (| + M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), + M.get_name (| globals, "bit_value" |) + |) + |) in + EndFor. + M.pure Constant.None_)). + +Definition logs_bloom : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "logs" ] |) in + let _ := Constant.str " + Obtain the logs bloom from a list of log entries. + + The address and each topic of a log are added to the bloom filter. + + Parameters + ---------- + logs : + List of logs for which the logs bloom is to be obtained. + + Returns + ------- + logs_bloom : `Bloom` + The logs bloom obtained which is 256 bytes with some bits set as per + the caller address and the log topics. + " in +(* At stmt: unsupported node type: AnnAssign *) + For M.get_name (| globals, "log" |) in M.get_name (| globals, "logs" |) do + let _ := M.call (| + M.get_name (| globals, "add_to_bloom" |), + make_list [ + M.get_name (| globals, "bloom" |); + M.get_field (| M.get_name (| globals, "log" |), "address" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "topic" |) in M.get_field (| M.get_name (| globals, "log" |), "topics" |) do + let _ := M.call (| + M.get_name (| globals, "add_to_bloom" |), + make_list [ + M.get_name (| globals, "bloom" |); + M.get_name (| globals, "topic" |) + ], + make_dict [] + |) in + EndFor. + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bloom" |), + make_list [ + M.get_name (| globals, "bloom" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/fork_types.v b/CoqOfPython/ethereum/constantinople/fork_types.v new file mode 100644 index 0000000..d12953d --- /dev/null +++ b/CoqOfPython/ethereum/constantinople/fork_types.v @@ -0,0 +1,102 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Types +^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Types re-used throughout the specification, which are specific to Ethereum. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes20 : + IsGlobalAlias globals base_types.globals "Bytes20". +Axiom base_types_Bytes256 : + IsGlobalAlias globals base_types.globals "Bytes256". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require crypto.hash. +Axiom crypto_hash_Hash32 : + IsGlobalAlias globals crypto.hash.globals "Hash32". +Axiom crypto_hash_keccak256 : + IsGlobalAlias globals crypto.hash.globals "keccak256". + +Definition Address : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Bytes20" |) +)). + +Definition Root : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Hash32" |) +)). + +Definition Bloom : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Bytes256" |) +)). + +Definition Account : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition EMPTY_ACCOUNT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Account" |), + make_list [], + make_dict [] + |) +)). + +Definition encode_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "raw_account_data"; "storage_root" ] |) in + let _ := Constant.str " + Encode `Account` dataclass. + + Storage is not stored in the `Account` dataclass, so `Accounts` cannot be + encoded with providing a storage root. + " in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "raw_account_data" |), "nonce" |); M.get_field (| M.get_name (| globals, "raw_account_data" |), "balance" |); M.get_name (| globals, "storage_root" |); M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_field (| M.get_name (| globals, "raw_account_data" |), "code" |) + ], + make_dict [] + |) ] + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/state.v b/CoqOfPython/ethereum/constantinople/state.v new file mode 100644 index 0000000..53b3837 --- /dev/null +++ b/CoqOfPython/ethereum/constantinople/state.v @@ -0,0 +1,1031 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +State +^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The state contains all information that is preserved between transactions. + +It consists of a main account trie and storage tries for each contract. + +There is a distinction between an account that does not exist and +`EMPTY_ACCOUNT`. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_field : + IsGlobalAlias globals dataclasses.globals "field". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_modify : + IsGlobalAlias globals ethereum.base_types.globals "modify". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require fork_types. +Axiom fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". +Axiom fork_types_Account : + IsGlobalAlias globals fork_types.globals "Account". +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Require trie. +Axiom trie_EMPTY_TRIE_ROOT : + IsGlobalAlias globals trie.globals "EMPTY_TRIE_ROOT". +Axiom trie_Trie : + IsGlobalAlias globals trie.globals "Trie". +Axiom trie_copy_trie : + IsGlobalAlias globals trie.globals "copy_trie". +Axiom trie_root : + IsGlobalAlias globals trie.globals "root". +Axiom trie_trie_get : + IsGlobalAlias globals trie.globals "trie_get". +Axiom trie_trie_set : + IsGlobalAlias globals trie.globals "trie_set". + +Definition State : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition close_state : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Free resources held by the state. Used by optimized implementations to + release file descriptors. + " in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) |) in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |) in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) in + M.pure Constant.None_)). + +Definition begin_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Start a state transaction. + + Transactions are entirely implicit and can be nested. It is not possible to + calculate the state root during a transaction. + + Parameters + ---------- + state : State + The state. + " in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), "append" |), + make_list [ + make_tuple [ M.call (| + M.get_name (| globals, "copy_trie" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) + ], + make_dict [] + |); {M.get_name (| globals, "k" |): M.call (| + M.get_name (| globals, "copy_trie" |), + make_list [ + M.get_name (| globals, "t" |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)} ] + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition commit_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Commit a state transaction. + + Parameters + ---------- + state : State + The state. + " in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), "pop" |), + make_list [], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition rollback_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Rollback a state transaction, resetting the state to the point when the + corresponding `start_transaction()` call was made. + + Parameters + ---------- + state : State + The state. + " in + let _ := M.assign (| + make_tuple [ M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) ], + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), "pop" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition get_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Get the `Account` object at an address. Returns `EMPTY_ACCOUNT` if there + is no account at the address. + + Use `get_account_optional()` if you care about the difference between a + non-existent account and `EMPTY_ACCOUNT`. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address to lookup. + + Returns + ------- + account : `Account` + Account at address. + " in + let account := + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "account" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "account" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "EMPTY_ACCOUNT" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition get_account_optional : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Get the `Account` object at an address. Returns `None` (rather than + `EMPTY_ACCOUNT`) if there is no account at the address. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address to lookup. + + Returns + ------- + account : `Account` + Account at address. + " in + let account := + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "account" |) + |) in + M.pure Constant.None_)). + +Definition set_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "account" ] |) in + let _ := Constant.str " + Set the `Account` object at an address. Setting to `None` deletes + the account (but not its storage, see `destroy_account()`). + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address to set. + account : `Account` + Account to set at address. + " in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "account" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition destroy_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Completely remove the account at `address` and all of its storage. + + This function is made available exclusively for the `SELFDESTRUCT` + opcode. It is expected that `SELFDESTRUCT` will be disabled in a future + hardfork and this function will be removed. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of account to destroy. + " in + let _ := M.call (| + M.get_name (| globals, "destroy_storage" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + Constant.None_ + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition destroy_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Completely remove the storage at `address`. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of account whose storage is to be deleted. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition get_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "key" ] |) in + let _ := Constant.str " + Get a value at a storage key on an account. Returns `U256(0)` if the + storage key has not been set previously. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of the account. + key : `Bytes` + Key to lookup. + + Returns + ------- + value : `U256` + Value at the key. + " in + let trie := + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let _ := M.assert (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "U256" |) + ], + make_dict [] + |) |) in + let _ := M.return_ (| + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_)). + +Definition set_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "key"; "value" ] |) in + let _ := Constant.str " + Set a value at a storage key on an account. Setting to `U256(0)` deletes + the key. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of the account. + key : `Bytes` + Key to set. + value : `U256` + Value to set at the key. + " in + let _ := M.assert (| Compare.is_not (| M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), Constant.None_ |) |) in + let trie := + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let trie := + M.call (| + M.get_name (| globals, "Trie" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), + M.get_name (| globals, "trie" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "key" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), {} |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition storage_root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Calculate the storage root of an account. + + Parameters + ---------- + state: + The state + address : + Address of the account. + + Returns + ------- + root : `Root` + Storage root of the account. + " in + let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "EMPTY_TRIE_ROOT" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition state_root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Calculate the state root. + + Parameters + ---------- + state: + The current state. + + Returns + ------- + root : `Root` + The state root. + " in + let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition account_exists : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account exists in the state trie + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + account_exists : `bool` + True if account exists in the state trie, False otherwise + " in + let _ := M.return_ (| + Compare.is_not (| M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), Constant.None_ |) + |) in + M.pure Constant.None_)). + +Definition account_has_code_or_nonce : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account has non zero nonce or non empty code + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + has_code_or_nonce : `bool` + True if if an account has non zero nonce or non empty code, + False otherwise. + " in + let account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + BoolOp.or (| + Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |) + )) + |) + |) in + M.pure Constant.None_)). + +Definition is_account_empty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account has zero nonce, empty code and zero balance. + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + is_empty : `bool` + True if if an account has zero nonce, empty code and zero balance, + False otherwise. + " in + let account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + ltac:(M.monadic ( + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + )) + |) + )) + |) + |) in + M.pure Constant.None_)). + +Definition account_exists_and_is_empty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account exists and has zero nonce, empty code and zero + balance. + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + exists_and_is_empty : `bool` + True if an account exists and has zero nonce, empty code and zero + balance, False otherwise. + " in + let account := + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + BoolOp.and (| + Compare.is_not (| M.get_name (| globals, "account" |), Constant.None_ |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + ltac:(M.monadic ( + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + )) + |) + )) + |) + )) + |) + |) in + M.pure Constant.None_)). + +Definition is_account_alive : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Check whether is an account is both in the state and non empty. + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + is_alive : `bool` + True if the account is alive. + " in + let account := + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "account" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + UnOp.not (| BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + ltac:(M.monadic ( + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + )) + |) + )) + |) |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition modify_state : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "f" ] |) in + let _ := Constant.str " + Modify an `Account` in the `State`. + " in + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.call (| + M.get_name (| globals, "modify" |), + make_list [ + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |); + M.get_name (| globals, "f" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition move_ether : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "sender_address"; "recipient_address"; "amount" ] |) in + let _ := Constant.str " + Move funds between accounts. + " in +(* At stmt: unsupported node type: FunctionDef *) +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "sender_address" |); + M.get_name (| globals, "reduce_sender_balance" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "recipient_address" |); + M.get_name (| globals, "increase_recipient_balance" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition set_account_balance : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "amount" ] |) in + let _ := Constant.str " + Sets the balance of an account. + + Parameters + ---------- + state: + The current state. + + address: + Address of the account whose nonce needs to be incremented. + + amount: + The amount that needs to set in balance. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "set_balance" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition touch_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Initializes an account to state. + + Parameters + ---------- + state: + The current state. + + address: + The address of the account that need to initialised. + " in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "account_exists" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "EMPTY_ACCOUNT" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition increment_nonce : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Increments the nonce of an account. + + Parameters + ---------- + state: + The current state. + + address: + Address of the account whose nonce needs to be incremented. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "increase_nonce" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition set_code : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "code" ] |) in + let _ := Constant.str " + Sets Account code. + + Parameters + ---------- + state: + The current state. + + address: + Address of the account whose code needs to be update. + + code: + The bytecode that needs to be set. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "write_code" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition create_ether : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "amount" ] |) in + let _ := Constant.str " + Add newly created ether to an account. + + Parameters + ---------- + state: + The current state. + address: + Address of the account to which ether is added. + amount: + The amount of ether to be added to the account of interest. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "increase_balance" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/transactions.v b/CoqOfPython/ethereum/constantinople/transactions.v new file mode 100644 index 0000000..6d1bc6b --- /dev/null +++ b/CoqOfPython/ethereum/constantinople/transactions.v @@ -0,0 +1,60 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Transactions are atomic units of work created externally to Ethereum and +submitted to be executed. If Ethereum is viewed as a state machine, +transactions are the events that move between states. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes0 : + IsGlobalAlias globals base_types.globals "Bytes0". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( + Constant.int 21000 +)). + +Definition TX_DATA_COST_PER_NON_ZERO : Value.t := M.run ltac:(M.monadic ( + Constant.int 68 +)). + +Definition TX_DATA_COST_PER_ZERO : Value.t := M.run ltac:(M.monadic ( + Constant.int 4 +)). + +Definition TX_CREATE_COST : Value.t := M.run ltac:(M.monadic ( + Constant.int 32000 +)). + +Definition Transaction : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. diff --git a/CoqOfPython/ethereum/constantinople/trie.v b/CoqOfPython/ethereum/constantinople/trie.v new file mode 100644 index 0000000..7210f99 --- /dev/null +++ b/CoqOfPython/ethereum/constantinople/trie.v @@ -0,0 +1,1357 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +State Trie +^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The state trie is the structure responsible for storing +`.fork_types.Account` objects. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_field : + IsGlobalAlias globals dataclasses.globals "field". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". +Axiom typing_Generic : + IsGlobalAlias globals typing.globals "Generic". +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Mapping : + IsGlobalAlias globals typing.globals "Mapping". +Axiom typing_MutableMapping : + IsGlobalAlias globals typing.globals "MutableMapping". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Sequence : + IsGlobalAlias globals typing.globals "Sequence". +Axiom typing_TypeVar : + IsGlobalAlias globals typing.globals "TypeVar". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". +Axiom typing_cast : + IsGlobalAlias globals typing.globals "cast". + +Require ethereum.byzantium. +Axiom ethereum_byzantium_trie : + IsGlobalAlias globals ethereum.byzantium.globals "trie". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require ethereum.utils.hexadecimal. +Axiom ethereum_utils_hexadecimal_hex_to_bytes : + IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require blocks. +Axiom blocks_Receipt : + IsGlobalAlias globals blocks.globals "Receipt". + +Require fork_types. +Axiom fork_types_Account : + IsGlobalAlias globals fork_types.globals "Account". +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". +Axiom fork_types_encode_account : + IsGlobalAlias globals fork_types.globals "encode_account". + +Require transactions. +Axiom transactions_Transaction : + IsGlobalAlias globals transactions.globals "Transaction". + +Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Root" |), + make_list [ + M.call (| + M.get_name (| globals, "hex_to_bytes" |), + make_list [ + Constant.str "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" + ], + make_dict [] + |) + ], + make_dict [] + |) +)). + +Definition Node : Value.t := M.run ltac:(M.monadic ( + M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Bytes" |); M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |); Constant.None_ ] |) +)). + +Definition K : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "TypeVar" |), + make_list [ + Constant.str "K" + ], + make_dict [] + |) +)). + +Definition V : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "TypeVar" |), + make_list [ + Constant.str "V"; + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Account" |) |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Bytes" |) |); + M.get_name (| globals, "Bytes" |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Transaction" |) |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Receipt" |) |); + M.get_name (| globals, "Uint" |); + M.get_name (| globals, "U256" |) + ], + make_dict [] + |) +)). + +Definition LeafNode : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition ExtensionNode : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition BranchNode : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition InternalNode : Value.t := M.run ltac:(M.monadic ( + M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LeafNode" |); M.get_name (| globals, "ExtensionNode" |); M.get_name (| globals, "BranchNode" |) ] |) +)). + +Definition encode_internal_node : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "node" ] |) in + let _ := Constant.str " + Encodes a Merkle Trie node into its RLP form. The RLP will then be + serialized into a `Bytes` and hashed unless it is less that 32 bytes + when serialized. + + This function also accepts `None`, representing the absence of a node, + which is encoded to `b""""""`. + + Parameters + ---------- + node : Optional[InternalNode] + The node to encode. + + Returns + ------- + encoded : `rlp.RLP` + The node encoded as RLP. + " in +(* At stmt: unsupported node type: AnnAssign *) + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "node" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let unencoded := + (* At constant: unsupported node type: Constant *) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "LeafNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "rest_of_key" |); + Constant.bool true + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "ExtensionNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "key_segment" |); + Constant.bool false + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "BranchNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + BinOp.add (| + M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "value" |) + ] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "AssertionError" |), + make_list [ + (* At expr: unsupported node type: JoinedStr *) + ], + make_dict [] + |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let encoded := + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "unencoded" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded" |) + ], + make_dict [] + |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "unencoded" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "encoded" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition encode_node : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "node"; "storage_root" ] |) in + let _ := Constant.str " + Encode a Node for storage in the Merkle Trie. + + Currently mostly an unimplemented stub. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "storage_root" |), Constant.None_ |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "encode_account" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "storage_root" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + make_tuple [ M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "U256" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "cast" |), + make_list [ + M.get_field (| M.get_name (| globals, "rlp" |), "RLP" |); + M.get_name (| globals, "node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "node" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "previous_trie" |), "encode_node" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "storage_root" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition Trie : Value.t := + builtins.make_klass + [(* At base: unsupported node type: Subscript *)] + [ + + ] + [ + + ]. + +Definition copy_trie : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie" ] |) in + let _ := Constant.str " + Create a copy of `trie`. Since only frozen objects may be stored in tries, + the contents are reused. + + Parameters + ---------- + trie: `Trie` + Trie to copy. + + Returns + ------- + new_trie : `Trie[K, V]` + A copy of the trie. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Trie" |), + make_list [ + M.get_field (| M.get_name (| globals, "trie" |), "secured" |); + M.get_field (| M.get_name (| globals, "trie" |), "default" |); + M.call (| + M.get_field (| M.get_name (| globals, "copy" |), "copy" |), + make_list [ + M.get_field (| M.get_name (| globals, "trie" |), "_data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition trie_set : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "key"; "value" ] |) in + let _ := Constant.str " + Stores an item in a Merkle Trie. + + This method deletes the key if `value == trie.default`, because the Merkle + Trie represents the default value by omitting it from the trie. + + Parameters + ---------- + trie: `Trie` + Trie to store in. + key : `Bytes` + Key to lookup. + value : `V` + Node to insert at `key`. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "value" |), M.get_field (| M.get_name (| globals, "trie" |), "default" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "key" |), M.get_field (| M.get_name (| globals, "trie" |), "_data" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition trie_get : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "key" ] |) in + let _ := Constant.str " + Gets an item from the Merkle Trie. + + This method returns `trie.default` if the key is missing. + + Parameters + ---------- + trie: + Trie to lookup in. + key : + Key to lookup. + + Returns + ------- + node : `V` + Node at `key` in the trie. + " in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "get" |), + make_list [ + M.get_name (| globals, "key" |); + M.get_field (| M.get_name (| globals, "trie" |), "default" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition common_prefix_length : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "a"; "b" ] |) in + let _ := Constant.str " + Find the longest common prefix of two sequences. + " in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + ], + make_dict [] + |) do + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| M.get_name (| globals, "i" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition nibble_list_to_compact : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "x"; "is_leaf" ] |) in + let _ := Constant.str " + Compresses nibble-list into a standard byte array with a flag. + + A nibble-list is a list of byte values no greater than `15`. The flag is + encoded in high nibble of the highest byte. The flag nibble can be broken + down into two two-bit flags. + + Highest nibble:: + + +---+---+----------+--------+ + | _ | _ | is_leaf | parity | + +---+---+----------+--------+ + 3 2 1 0 + + + The lowest bit of the nibble encodes the parity of the length of the + remaining nibbles -- `0` when even and `1` when odd. The second lowest bit + is used to distinguish leaf and extension nodes. The other two bits are not + used. + + Parameters + ---------- + x : + Array of nibbles. + is_leaf : + True if this is part of a leaf node, or false if it is an extension + node. + + Returns + ------- + compressed : `bytearray` + Compact byte array. + " in + let compact := + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + Constant.int 2 + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.mult (| + Constant.int 16, + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "is_leaf" |) + |) + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + BinOp.add (| + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "is_leaf" |) + |), + Constant.int 1 + |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), Constant.int 0 |) + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 1; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + M.get_name (| globals, "compact" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition bytes_to_nibble_list : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "bytes_" ] |) in + let _ := Constant.str " + Converts a `Bytes` into to a sequence of nibbles (bytes with value < 16). + + Parameters + ---------- + bytes_: + The `Bytes` to convert. + + Returns + ------- + nibble_list : `Bytes` + The `Bytes` in nibble-list format. + " in + let nibble_list := + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [ + BinOp.mult (| + Constant.int 2, + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "bytes_" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + For make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ] in M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "bytes_" |) + ], + make_dict [] + |) do + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |) |), + BinOp.r_shift (| + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 240 + |), + Constant.int 4 + |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |), + Constant.int 1 + |) |), + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 15 + |) + |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + M.get_name (| globals, "nibble_list" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition _prepare_trie : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "get_storage_root" ] |) in + let _ := Constant.str " + Prepares the trie for root calculation. Removes values that are empty, + hashes the keys (if `secured == True`) and encodes all the nodes. + + Parameters + ---------- + trie : + The `Trie` to prepare. + get_storage_root : + Function to get the storage root of an account. Needed to encode + `Account` objects. + + Returns + ------- + out : `Mapping[ethereum.base_types.Bytes, Node]` + Object with keys mapped to nibble-byte form. + " in +(* At stmt: unsupported node type: AnnAssign *) + For make_tuple [ M.get_name (| globals, "preimage" |); M.get_name (| globals, "value" |) ] in M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "items" |), + make_list [], + make_dict [] + |) do + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in + let address := + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |); + M.call (| + M.get_name (| globals, "get_storage_root" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_eq (| M.get_name (| globals, "encoded_value" |), (* At constant: unsupported node type: Constant *) |); + M.get_name (| globals, "AssertionError" |) + ], + make_dict [] + |) in +(* At stmt: unsupported node type: AnnAssign *) + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "trie" |), "secured" |), + (* then *) + ltac:(M.monadic ( + let key := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let key := + M.get_name (| globals, "preimage" |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "mapped" |), M.call (| + M.get_name (| globals, "bytes_to_nibble_list" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |) |), + M.get_name (| globals, "encoded_value" |) + |) in + EndFor. + let _ := M.return_ (| + M.get_name (| globals, "mapped" |) + |) in + M.pure Constant.None_)). + +Definition root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "get_storage_root" ] |) in + let _ := Constant.str " + Computes the root of a modified merkle patricia trie (MPT). + + Parameters + ---------- + trie : + `Trie` to get the root of. + get_storage_root : + Function to get the storage root of an account. Needed to encode + `Account` objects. + + + Returns + ------- + root : `.fork_types.Root` + MPT root of the underlying key-value pairs. + " in + let obj := + M.call (| + M.get_name (| globals, "_prepare_trie" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "get_storage_root" |) + ], + make_dict [] + |) in + let root_node := + M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_name (| globals, "obj" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assert (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "root_node" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Root" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition patricialize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "obj"; "level" ] |) in + let _ := Constant.str " + Structural composition function. + + Used to recursively patricialize and merkleize a dictionary. Includes + memoization of the tree structure and hashes. + + Parameters + ---------- + obj : + Underlying trie key-value pairs, with keys in nibble-list format. + level : + Current trie level. + + Returns + ------- + node : `ethereum.base_types.Bytes` + Root node of `obj`. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let arbitrary_key := + M.call (| + M.get_name (| globals, "next" |), + make_list [ + M.call (| + M.get_name (| globals, "iter" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), Constant.int 1 |), + (* then *) + ltac:(M.monadic ( + let leaf := + M.call (| + M.get_name (| globals, "LeafNode" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |); + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "leaf" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let substring := + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) in + let prefix_length := + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "substring" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do + let prefix_length := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_name (| globals, "prefix_length" |); + M.call (| + M.get_name (| globals, "common_prefix_length" |), + make_list [ + M.get_name (| globals, "substring" |); + M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let prefix := + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ExtensionNode" |), + make_list [ + M.get_name (| globals, "prefix" |); + M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_name (| globals, "obj" |); + BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in +(* At stmt: unsupported node type: AnnAssign *) + For M.get_name (| globals, "_" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 16 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "branches" |), "append" |), + make_list [ + {} + ], + make_dict [] + |) in + EndFor. + let value := + (* At constant: unsupported node type: Constant *) in + For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |), M.get_name (| globals, "level" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "AssertionError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) + |) in + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "BranchNode" |), + make_list [ + [M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "branches" |), M.get_name (| globals, "k" |) |); + BinOp.add (| + M.get_name (| globals, "level" |), + Constant.int 1 + |) + ], + make_dict [] + |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)]; + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/utils/__init__.v b/CoqOfPython/ethereum/constantinople/utils/__init__.v new file mode 100644 index 0000000..1baedea --- /dev/null +++ b/CoqOfPython/ethereum/constantinople/utils/__init__.v @@ -0,0 +1,8 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Utility functions unique to this particular fork. +". diff --git a/CoqOfPython/ethereum/constantinople/utils/address.v b/CoqOfPython/ethereum/constantinople/utils/address.v new file mode 100644 index 0000000..a0fd4e2 --- /dev/null +++ b/CoqOfPython/ethereum/constantinople/utils/address.v @@ -0,0 +1,204 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Hardfork Utility Functions For Addresses +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Address specific functions used in this constantinople version of +specification. +". + +Require typing. +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_left_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Definition to_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "data" ] |) in + let _ := Constant.str " + Convert a Uint or U256 value to a valid address (20 bytes). + + Parameters + ---------- + data : + The string to be converted to bytes. + + Returns + ------- + address : `Address` + The obtained address. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_subscript (| M.call (| + M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition compute_contract_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "address"; "nonce" ] |) in + let _ := Constant.str " + Computes address of the new account that needs to be created. + + Parameters + ---------- + address : + The address of the account that wants to create the new account. + nonce : + The transaction count of the account that wants to create the new + account. + + Returns + ------- + address: `Address` + The computed address of the new account. + " in + let computed_address := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_list [ + M.get_name (| globals, "address" |); + M.get_name (| globals, "nonce" |) + ] + ], + make_dict [] + |) + ], + make_dict [] + |) in + let canonical_address := + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + let padded_address := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "canonical_address" |); + Constant.int 20 + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "padded_address" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition compute_create2_contract_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "address"; "salt"; "call_data" ] |) in + let _ := Constant.str " + Computes address of the new account that needs to be created, which is + based on the sender address, salt and the call data as well. + + Parameters + ---------- + address : + The address of the account that wants to create the new account. + salt : + Address generation salt. + call_data : + The code of the new account which is to be created. + + Returns + ------- + address: `ethereum.constantinople.fork_types.Address` + The computed address of the new account. + " in + let preimage := + BinOp.add (| + BinOp.add (| + BinOp.add (| + (* At constant: unsupported node type: Constant *), + M.get_name (| globals, "address" |) + |), + M.get_name (| globals, "salt" |) + |), + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "call_data" |) + ], + make_dict [] + |) + |) in + let computed_address := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + let canonical_address := + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + let padded_address := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "canonical_address" |); + Constant.int 20 + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "padded_address" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/utils/hexadecimal.v b/CoqOfPython/ethereum/constantinople/utils/hexadecimal.v new file mode 100644 index 0000000..0e18043 --- /dev/null +++ b/CoqOfPython/ethereum/constantinople/utils/hexadecimal.v @@ -0,0 +1,155 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Utility Functions For Hexadecimal Strings +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Hexadecimal utility functions used in this specification, specific to +Constantinople types. +". + +Require ethereum.utils.hexadecimal. +Axiom ethereum_utils_hexadecimal_remove_hex_prefix : + IsGlobalAlias globals ethereum.utils.hexadecimal.globals "remove_hex_prefix". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Definition hex_to_root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to trie root. + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to trie root. + + Returns + ------- + root : `Root` + Trie root obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Root" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition hex_to_bloom : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to bloom. + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to bloom. + + Returns + ------- + bloom : `Bloom` + Bloom obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bloom" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition hex_to_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to Address (20 bytes). + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to Address. + + Returns + ------- + address : `Address` + The address obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |), "rjust" |), + make_list [ + Constant.int 40; + Constant.str "0" + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/utils/message.v b/CoqOfPython/ethereum/constantinople/utils/message.v new file mode 100644 index 0000000..efb5e7c --- /dev/null +++ b/CoqOfPython/ethereum/constantinople/utils/message.v @@ -0,0 +1,201 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Hardfork Utility Functions For The Message Data-structure +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Message specific functions used in this constantinople version of +specification. +". + +Require typing. +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". + +Require vm. +Axiom vm_Environment : + IsGlobalAlias globals vm.globals "Environment". +Axiom vm_Message : + IsGlobalAlias globals vm.globals "Message". + +Require address. +Axiom address_compute_contract_address : + IsGlobalAlias globals address.globals "compute_contract_address". + +Definition prepare_message : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "caller"; "target"; "value"; "data"; "gas"; "env"; "code_address"; "should_transfer_value"; "is_static" ] |) in + let _ := Constant.str " + Execute a transaction against the provided environment. + + Parameters + ---------- + caller : + Address which initiated the transaction + target : + Address whose code will be executed + value : + Value to be transferred. + data : + Array of bytes provided to the code in `target`. + gas : + Gas provided for the code in `target`. + env : + Environment for the Ethereum Virtual Machine. + code_address : + This is usually same as the `target` address except when an alternative + accounts code needs to be executed. + eg. `CALLCODE` calling a precompile. + should_transfer_value : + if True ETH should be transferred while executing a message call. + is_static: + if True then it prevents all state-changing operations from being + executed. + + Returns + ------- + message: `ethereum.constantinople.vm.Message` + Items containing contract creation or message call specific data. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Bytes0" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.call (| + M.get_name (| globals, "compute_contract_address" |), + make_list [ + M.get_name (| globals, "caller" |); + BinOp.sub (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "caller" |) + ], + make_dict [] + |), "nonce" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let msg_data := + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |) in + let code := + M.get_name (| globals, "data" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.get_name (| globals, "target" |) in + let msg_data := + M.get_name (| globals, "data" |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "target" |) + ], + make_dict [] + |), "code" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "code_address" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let code_address := + M.get_name (| globals, "target" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "AssertionError" |), + make_list [ + Constant.str "Target must be address or empty bytes" + ], + make_dict [] + |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/vm/__init__.v b/CoqOfPython/ethereum/constantinople/vm/__init__.v new file mode 100644 index 0000000..520603e --- /dev/null +++ b/CoqOfPython/ethereum/constantinople/vm/__init__.v @@ -0,0 +1,244 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The abstract computer which runs the code stored in an +`.fork_types.Account`. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_State : + IsGlobalAlias globals state.globals "State". +Axiom state_account_exists_and_is_empty : + IsGlobalAlias globals state.globals "account_exists_and_is_empty". + +Require precompiled_contracts. +Axiom precompiled_contracts_RIPEMD160_ADDRESS : + IsGlobalAlias globals precompiled_contracts.globals "RIPEMD160_ADDRESS". + +Definition __all__ : Value.t := M.run ltac:(M.monadic ( + make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] +)). + +Definition Environment : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Message : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Evm : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition incorporate_child_on_success : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "child_evm" ] |) in + let _ := Constant.str " + Incorporate the state of a successful `child_evm` into the parent `evm`. + + Parameters + ---------- + evm : + The parent `EVM`. + child_evm : + The child evm to incorporate. + " in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "gas_left" |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "logs" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "logs" |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "refund_counter" |) + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "accounts_to_delete" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition incorporate_child_on_error : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "child_evm" ] |) in + let _ := Constant.str " + Incorporate the state of an unsuccessful `child_evm` into the parent `evm`. + + Parameters + ---------- + evm : + The parent `EVM`. + child_evm : + The child evm to incorporate. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "RIPEMD160_ADDRESS" |), M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |), M.get_name (| globals, "RIPEMD160_ADDRESS" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "gas_left" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/vm/exceptions.v b/CoqOfPython/ethereum/constantinople/vm/exceptions.v new file mode 100644 index 0000000..23d00db --- /dev/null +++ b/CoqOfPython/ethereum/constantinople/vm/exceptions.v @@ -0,0 +1,152 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Exceptions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Exceptions which cause the EVM to halt exceptionally. +". + +Require ethereum.exceptions. +Axiom ethereum_exceptions_EthereumException : + IsGlobalAlias globals ethereum.exceptions.globals "EthereumException". + +Definition ExceptionalHalt : Value.t := + builtins.make_klass + [(globals, "EthereumException")] + [ + + ] + [ + + ]. + +Definition Revert : Value.t := + builtins.make_klass + [(globals, "EthereumException")] + [ + + ] + [ + + ]. + +Definition StackUnderflowError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition StackOverflowError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition OutOfGasError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition InvalidOpcode : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + ( + "__init__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "code" ] |) in + let _ := M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "super" |), + make_list [], + make_dict [] + |), "__init__" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "self" |), "code" |), + M.get_name (| globals, "code" |) + |) in + M.pure Constant.None_)) + ) + ]. + +Definition InvalidJumpDestError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition StackDepthLimitError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition WriteInStaticContext : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition OutOfBoundsRead : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition AddressCollision : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/__init__.v b/CoqOfPython/ethereum/constantinople/vm/instructions/__init__.v new file mode 100644 index 0000000..e5bebd7 --- /dev/null +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/__init__.v @@ -0,0 +1,87 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +EVM Instruction Encoding (Opcodes) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Machine readable representations of EVM instructions, and a mapping to their +implementations. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". + +Require __init__. +Axiom __init___arithmetic : + IsGlobalAlias globals __init__.globals "arithmetic". + +Require __init__. +Axiom __init___bitwise : + IsGlobalAlias globals __init__.globals "bitwise". + +Require __init__. +Axiom __init___block : + IsGlobalAlias globals __init__.globals "block". + +Require __init__. +Axiom __init___comparison : + IsGlobalAlias globals __init__.globals "comparison". + +Require __init__. +Axiom __init___control_flow : + IsGlobalAlias globals __init__.globals "control_flow". + +Require __init__. +Axiom __init___environment : + IsGlobalAlias globals __init__.globals "environment". + +Require __init__. +Axiom __init___keccak : + IsGlobalAlias globals __init__.globals "keccak". + +Require __init__. +Axiom __init___log : + IsGlobalAlias globals __init__.globals "log". + +Require __init__. +Axiom __init___memory : + IsGlobalAlias globals __init__.globals "memory". + +Require __init__. +Axiom __init___stack : + IsGlobalAlias globals __init__.globals "stack". + +Require __init__. +Axiom __init___storage : + IsGlobalAlias globals __init__.globals "storage". + +Require __init__. +Axiom __init___system : + IsGlobalAlias globals __init__.globals "system". + +Definition Ops : Value.t := + builtins.make_klass + [(* At base: unsupported node type: Attribute *)] + [ + + ] + [ + + ]. + +(* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/constantinople/vm/instructions/arithmetic.v new file mode 100644 index 0000000..a8b5c61 --- /dev/null +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/arithmetic.v @@ -0,0 +1,1085 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Arithmetic Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM Arithmetic instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U255_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U255_CEIL_VALUE". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_U256_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_get_sign : + IsGlobalAlias globals ethereum.utils.numeric.globals "get_sign". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_EXPONENTIATION : + IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION". +Axiom gas_GAS_EXPONENTIATION_PER_BYTE : + IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION_PER_BYTE". +Axiom gas_GAS_LOW : + IsGlobalAlias globals gas.globals "GAS_LOW". +Axiom gas_GAS_MID : + IsGlobalAlias globals gas.globals "GAS_MID". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition add : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Adds the top two elements of the stack together, and pushes the result back + on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "x" |), "wrapping_add" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition sub : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Subtracts the top two elements of the stack, and pushes the result back + on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "x" |), "wrapping_sub" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mul : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Multiply the top two elements of the stack, and pushes the result back + on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "x" |), "wrapping_mul" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition div : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Integer division of the top two elements of the stack. Pushes the result + back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let dividend := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let divisor := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let quotient := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let quotient := + BinOp.floor_div (| + M.get_name (| globals, "dividend" |), + M.get_name (| globals, "divisor" |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "quotient" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition sdiv : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed integer division of the top two elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let dividend := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let divisor := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let quotient := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_name (| globals, "dividend" |), UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "divisor" |), UnOp.sub (| Constant.int 1 |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let quotient := + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let sign := + M.call (| + M.get_name (| globals, "get_sign" |), + make_list [ + BinOp.mult (| + M.get_name (| globals, "dividend" |), + M.get_name (| globals, "divisor" |) + |) + ], + make_dict [] + |) in + let quotient := + BinOp.mult (| + M.get_name (| globals, "sign" |), + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "dividend" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "divisor" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + M.get_name (| globals, "quotient" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Modulo remainder of the top two elements of the stack. Pushes the result + back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let remainder := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let remainder := + BinOp.mod_ (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "remainder" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition smod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed modulo remainder of the top two elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let y := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let remainder := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let remainder := + BinOp.mult (| + M.call (| + M.get_name (| globals, "get_sign" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + BinOp.mod_ (| + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + M.get_name (| globals, "remainder" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition addmod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Modulo addition of the top 2 elements with the 3rd element. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let z := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_MID" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.add (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |), + M.get_name (| globals, "z" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mulmod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Modulo multiplication of the top 2 elements with the 3rd element. Pushes + the result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let z := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_MID" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.mult (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |), + M.get_name (| globals, "z" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition exp : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Exponential operation of the top 2 elements. Pushes the result back on + the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let base := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exponent := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exponent_bits := + M.call (| + M.get_field (| M.get_name (| globals, "exponent" |), "bit_length" |), + make_list [], + make_dict [] + |) in + let exponent_bytes := + BinOp.floor_div (| + BinOp.add (| + M.get_name (| globals, "exponent_bits" |), + Constant.int 7 + |), + Constant.int 8 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_EXPONENTIATION" |), + BinOp.mult (| + M.get_name (| globals, "GAS_EXPONENTIATION_PER_BYTE" |), + M.get_name (| globals, "exponent_bytes" |) + |) + |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "pow" |), + make_list [ + M.get_name (| globals, "base" |); + M.get_name (| globals, "exponent" |); + M.get_name (| globals, "U256_CEIL_VALUE" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition signextend : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Sign extend operation. In other words, extend a signed number which + fits in N bytes to 32 bytes. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let byte_num := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "byte_num" |), Constant.int 31 |), + (* then *) + ltac:(M.monadic ( + let result := + M.get_name (| globals, "value" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let value_bytes := + M.call (| + M.get_name (| globals, "bytes" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "value" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) in + let value_bytes := + M.get_subscript (| M.get_name (| globals, "value_bytes" |), BinOp.sub (| + Constant.int 31, + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "byte_num" |) + ], + make_dict [] + |) + |):(* At expr: unsupported node type: NoneType *) |) in + let sign_bit := + BinOp.r_shift (| + M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), + Constant.int 7 + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "sign_bit" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "value_bytes" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let num_bytes_prepend := + BinOp.sub (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "byte_num" |), + Constant.int 1 + |) + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + BinOp.add (| + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [ + BinOp.mult (| + make_list [ + Constant.int 255 + ], + M.get_name (| globals, "num_bytes_prepend" |) + |) + ], + make_dict [] + |), + M.get_name (| globals, "value_bytes" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/bitwise.v b/CoqOfPython/ethereum/constantinople/vm/instructions/bitwise.v new file mode 100644 index 0000000..9f2f382 --- /dev/null +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/bitwise.v @@ -0,0 +1,601 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Bitwise Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM bitwise instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_U256_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition bitwise_and : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise AND operation of the top 2 elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + BinOp.bit_and (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_or : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise OR operation of the top 2 elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + BinOp.bit_or (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_xor : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise XOR operation of the top 2 elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + BinOp.bit_xor (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_not : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise NOT operation of the top element of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + UnOp.invert (| M.get_name (| globals, "x" |) |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition get_byte : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + For a word (defined by next top element of the stack), retrieve the + Nth byte (0-indexed and defined by top element of stack) from the + left (most significant) to right (least significant). + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let byte_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let word := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "byte_index" |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let extra_bytes_to_right := + BinOp.sub (| + Constant.int 31, + M.get_name (| globals, "byte_index" |) + |) in + let word := + BinOp.r_shift (| + M.get_name (| globals, "word" |), + BinOp.mult (| + M.get_name (| globals, "extra_bytes_to_right" |), + Constant.int 8 + |) + |) in + let word := + BinOp.bit_and (| + M.get_name (| globals, "word" |), + Constant.int 255 + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "word" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_shl : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Logical shift left (SHL) operation of the top 2 elements of the stack. + Pushes the result back on the stack. + Parameters + ---------- + evm : + The current EVM frame. + " in + let shift := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.l_shift (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "shift" |) + |), + M.get_name (| globals, "U256_CEIL_VALUE" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_shr : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Logical shift right (SHR) operation of the top 2 elements of the stack. + Pushes the result back on the stack. + Parameters + ---------- + evm : + The current EVM frame. + " in + let shift := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), + (* then *) + ltac:(M.monadic ( + let result := + BinOp.r_shift (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "shift" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_sar : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Arithmetic shift right (SAR) operation of the top 2 elements of the stack. + Pushes the result back on the stack. + Parameters + ---------- + evm : + The current EVM frame. + " in + let shift := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let signed_value := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + BinOp.r_shift (| + M.get_name (| globals, "signed_value" |), + M.get_name (| globals, "shift" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "signed_value" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/block.v b/CoqOfPython/ethereum/constantinople/vm/instructions/block.v new file mode 100644 index 0000000..e5fa554 --- /dev/null +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/block.v @@ -0,0 +1,337 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Block Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM block instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_BLOCK_HASH : + IsGlobalAlias globals gas.globals "GAS_BLOCK_HASH". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition block_hash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the hash of one of the 256 most recent complete blocks onto the + stack. The block number to hash is present at the top of the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let block_number := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BLOCK_HASH" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt_e (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), M.get_name (| globals, "block_number" |) |), + ltac:(M.monadic ( + Compare.gt (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), BinOp.add (| + M.get_name (| globals, "block_number" |), + Constant.int 256 + |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let hash := + (* At constant: unsupported node type: Constant *) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let hash := + M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + M.get_name (| globals, "block_number" |) + |) |) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "hash" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition coinbase : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's beneficiary address (address of the block miner) + onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "coinbase" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition timestamp : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's timestamp onto the stack. Here the timestamp + being referred is actually the unix timestamp in seconds. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "time" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition number : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's number onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition difficulty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's difficulty onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "difficulty" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition gas_limit : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's gas limit onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "gas_limit" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/comparison.v b/CoqOfPython/ethereum/constantinople/vm/instructions/comparison.v new file mode 100644 index 0000000..fbc35f8 --- /dev/null +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/comparison.v @@ -0,0 +1,404 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Comparison Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM Comparison instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition less_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is less than the next top element. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let right := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition signed_less_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed less-than comparison. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let right := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition greater_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is greater than the next top element. Pushes + the result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let right := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition signed_greater_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed greater-than comparison. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let right := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition equal : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is equal to the next top element. Pushes + the result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let right := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.eq (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition is_zero : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is equal to 0. Pushes the result back on the + stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.eq (| M.get_name (| globals, "x" |), Constant.int 0 |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/control_flow.v b/CoqOfPython/ethereum/constantinople/vm/instructions/control_flow.v new file mode 100644 index 0000000..04a79d9 --- /dev/null +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/control_flow.v @@ -0,0 +1,336 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Control Flow Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM control flow instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require vm.gas. +Axiom vm_gas_GAS_BASE : + IsGlobalAlias globals vm.gas.globals "GAS_BASE". +Axiom vm_gas_GAS_HIGH : + IsGlobalAlias globals vm.gas.globals "GAS_HIGH". +Axiom vm_gas_GAS_JUMPDEST : + IsGlobalAlias globals vm.gas.globals "GAS_JUMPDEST". +Axiom vm_gas_GAS_MID : + IsGlobalAlias globals vm.gas.globals "GAS_MID". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_InvalidJumpDestError : + IsGlobalAlias globals exceptions.globals "InvalidJumpDestError". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition stop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stop further execution of EVM code. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let _ := M.pass (| |) in + let _ := M.pass (| |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "running" |), + Constant.bool false + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition jump : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Alter the program counter to the location specified by the top of the + stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let jump_dest := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_MID" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "jump_dest" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition jumpi : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Alter the program counter to the specified location if and only if a + condition is true. If the condition is not true, then the program counter + would increase only by 1. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let jump_dest := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let conditional_value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_HIGH" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "conditional_value" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let destination := + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let destination := + M.get_name (| globals, "jump_dest" |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "destination" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition pc : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push onto the stack the value of the program counter after reaching the + current instruction and without increasing it for the next instruction. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "pc" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition gas_left : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the amount of available gas (including the corresponding reduction + for the cost of this instruction) onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition jumpdest : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Mark a valid destination for jumps. This is a noop, present only + to be used by `JUMP` and `JUMPI` opcodes to verify that their jump is + valid. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_JUMPDEST" |) + ], + make_dict [] + |) in + let _ := M.pass (| |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/environment.v b/CoqOfPython/ethereum/constantinople/vm/instructions/environment.v new file mode 100644 index 0000000..d0a3a8f --- /dev/null +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/environment.v @@ -0,0 +1,1239 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Environmental Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM environment related instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require fork_types. +Axiom fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". + +Require state. +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". + +Require utils.address. +Axiom utils_address_to_address : + IsGlobalAlias globals utils.address.globals "to_address". + +Require vm.memory. +Axiom vm_memory_buffer_read : + IsGlobalAlias globals vm.memory.globals "buffer_read". +Axiom vm_memory_memory_write : + IsGlobalAlias globals vm.memory.globals "memory_write". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_OutOfBoundsRead : + IsGlobalAlias globals exceptions.globals "OutOfBoundsRead". + +Require gas. +Axiom gas_GAS_BALANCE : + IsGlobalAlias globals gas.globals "GAS_BALANCE". +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_CODE_HASH : + IsGlobalAlias globals gas.globals "GAS_CODE_HASH". +Axiom gas_GAS_COPY : + IsGlobalAlias globals gas.globals "GAS_COPY". +Axiom gas_GAS_EXTERNAL : + IsGlobalAlias globals gas.globals "GAS_EXTERNAL". +Axiom gas_GAS_RETURN_DATA_COPY : + IsGlobalAlias globals gas.globals "GAS_RETURN_DATA_COPY". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the address of the current executing account to the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition balance : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the balance of the given account onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BALANCE" |) + ], + make_dict [] + |) in + let balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "balance" |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "balance" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition origin : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the address of the original transaction sender to the stack. + The origin address can only be an EOA. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "origin" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition caller : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the address of the caller onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "caller" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition callvalue : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the value (in wei) sent with the call onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition calldataload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push a word (32 bytes) of the input data belonging to the current + environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |); + M.get_name (| globals, "start_index" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition calldatasize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the size of input data in current environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition calldatacopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy a portion of the input data in current environment to memory. + + This will also expand the memory, in case that the memory is insufficient + to store the data. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let data_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |); + M.get_name (| globals, "data_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition codesize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the size of code running in current environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "code" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition codecopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy a portion of the code in current environment to memory. + + This will also expand the memory, in case that the memory is insufficient + to store the data. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let code_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "code" |); + M.get_name (| globals, "code_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition gasprice : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the gas price used in current environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "gas_price" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition extcodesize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the code size of a given account onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_EXTERNAL" |) + ], + make_dict [] + |) in + let codesize := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "code" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "codesize" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition extcodecopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy a portion of an account's code to memory. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let code_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_EXTERNAL" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "code" |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "code" |); + M.get_name (| globals, "code_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition returndatasize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the size of the return data buffer onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition returndatacopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copies data from the return data buffer code to memory + + Parameters + ---------- + evm : + The current EVM frame. + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let return_data_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_RETURN_DATA_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "return_data_start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "OutOfBoundsRead" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |):BinOp.add (| + M.get_name (| globals, "return_data_start_position" |), + M.get_name (| globals, "size" |) + |) |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition extcodehash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Returns the keccak256 hash of a contract’s bytecode + Parameters + ---------- + evm : + The current EVM frame. + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_CODE_HASH" |) + ], + make_dict [] + |) in + let account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "account" |), M.get_name (| globals, "EMPTY_ACCOUNT" |) |), + (* then *) + ltac:(M.monadic ( + let codehash := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let codehash := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_field (| M.get_name (| globals, "account" |), "code" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "codehash" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/keccak.v b/CoqOfPython/ethereum/constantinople/vm/instructions/keccak.v new file mode 100644 index 0000000..cab9ffb --- /dev/null +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/keccak.v @@ -0,0 +1,181 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Keccak Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM keccak instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_KECCAK256 : + IsGlobalAlias globals gas.globals "GAS_KECCAK256". +Axiom gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition keccak : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes to the stack the Keccak-256 hash of a region of memory. + + This also expands the memory, in case the memory is insufficient to + access the data's memory location. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let word_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_KECCAK256_WORD" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_KECCAK256" |), + M.get_name (| globals, "word_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let data := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "hash" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/log.v b/CoqOfPython/ethereum/constantinople/vm/instructions/log.v new file mode 100644 index 0000000..4891a4d --- /dev/null +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/log.v @@ -0,0 +1,244 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Logging Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM logging instructions. +". + +Require functools. +Axiom functools_partial : + IsGlobalAlias globals functools.globals "partial". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_WriteInStaticContext : + IsGlobalAlias globals exceptions.globals "WriteInStaticContext". + +Require gas. +Axiom gas_GAS_LOG : + IsGlobalAlias globals gas.globals "GAS_LOG". +Axiom gas_GAS_LOG_DATA : + IsGlobalAlias globals gas.globals "GAS_LOG_DATA". +Axiom gas_GAS_LOG_TOPIC : + IsGlobalAlias globals gas.globals "GAS_LOG_TOPIC". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". + +Definition log_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "num_topics" ] |) in + let _ := Constant.str " + Appends a log entry, having `num_topics` topics, to the evm logs. + + This will also expand the memory if the data (required by the log entry) + corresponding to the memory is not accessible. + + Parameters + ---------- + evm : + The current EVM frame. + num_topics : + The number of topics to be included in the log entry. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let topics := + make_list [] in + For M.get_name (| globals, "_" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "num_topics" |) + ], + make_dict [] + |) do + let topic := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "topics" |), "append" |), + make_list [ + M.get_name (| globals, "topic" |) + ], + make_dict [] + |) in + EndFor. + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_LOG" |), + BinOp.mult (| + M.get_name (| globals, "GAS_LOG_DATA" |), + M.get_name (| globals, "size" |) + |) + |), + BinOp.mult (| + M.get_name (| globals, "GAS_LOG_TOPIC" |), + M.get_name (| globals, "num_topics" |) + |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let log_entry := + M.call (| + M.get_name (| globals, "Log" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "logs" |), + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "logs" |), + make_tuple [ M.get_name (| globals, "log_entry" |) ] + |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition log0 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/memory.v b/CoqOfPython/ethereum/constantinople/vm/instructions/memory.v new file mode 100644 index 0000000..1e1c8b0 --- /dev/null +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/memory.v @@ -0,0 +1,378 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Memory Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM Memory instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". +Axiom memory_memory_write : + IsGlobalAlias globals memory.globals "memory_write". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition mstore : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a word to memory. + This also expands the memory, if the memory is + insufficient to store the word. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "start_position" |); M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + ], + make_dict [] + |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "start_position" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mstore8 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a byte to memory. + This also expands the memory, if the memory is + insufficient to store the word. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "start_position" |); M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let normalized_bytes_value := + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + make_list [ + BinOp.bit_and (| + M.get_name (| globals, "value" |), + Constant.int 255 + |) + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "start_position" |); + M.get_name (| globals, "normalized_bytes_value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Load word from memory. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "start_position" |); M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "start_position" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition msize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the size of active memory in bytes onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/stack.v b/CoqOfPython/ethereum/constantinople/vm/instructions/stack.v new file mode 100644 index 0000000..1eeda05 --- /dev/null +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/stack.v @@ -0,0 +1,929 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Stack Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM stack related instructions. +". + +Require functools. +Axiom functools_partial : + IsGlobalAlias globals functools.globals "partial". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". +Axiom __init___stack : + IsGlobalAlias globals __init__.globals "stack". + +Require exceptions. +Axiom exceptions_StackUnderflowError : + IsGlobalAlias globals exceptions.globals "StackUnderflowError". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_buffer_read : + IsGlobalAlias globals memory.globals "buffer_read". + +Definition pop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Remove item from stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.pass (| |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition push_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "num_bytes" ] |) in + let _ := Constant.str " + Pushes a N-byte immediate onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + num_bytes : + The number of immediate bytes to be read from the code and pushed to + the stack. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let data_to_push := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "code" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "num_bytes" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "data_to_push" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + BinOp.add (| + Constant.int 1, + M.get_name (| globals, "num_bytes" |) + |) + |) in + M.pure Constant.None_)). + +Definition dup_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "item_number" ] |) in + let _ := Constant.str " + Duplicate the Nth stack item (from top of the stack) to the top of stack. + + Parameters + ---------- + evm : + The current EVM frame. + + item_number : + The stack item number (0-indexed from top of stack) to be duplicated + to the top of stack. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "StackUnderflowError" |) + ], + make_dict [] + |) in + let data_to_duplicate := + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + BinOp.sub (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), + Constant.int 1 + |), + M.get_name (| globals, "item_number" |) + |) |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "data_to_duplicate" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition swap_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "item_number" ] |) in + let _ := Constant.str " + Swap the top and the `item_number` element of the stack, where + the top of the stack is position zero. + + If `item_number` is zero, this function does nothing (which should not be + possible, since there is no `SWAP0` instruction). + + Parameters + ---------- + evm : + The current EVM frame. + + item_number : + The stack item number (0-indexed from top of stack) to be swapped + with the top of stack element. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "StackUnderflowError" |) + ], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) |) ], + make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |) ] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition push1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push5 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push6 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push7 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push8 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push9 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push10 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push11 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push12 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push13 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push14 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push15 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push16 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push17 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push18 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push19 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push20 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push21 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push22 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push23 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push24 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push25 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push26 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push27 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push28 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push29 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push30 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push31 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push32 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition dup1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup5 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup6 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup7 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup8 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup9 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup10 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup11 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup12 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup13 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup14 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup15 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup16 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition swap1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap5 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap6 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap7 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap8 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap9 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap10 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap11 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap12 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap13 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap14 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap15 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap16 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/storage.v b/CoqOfPython/ethereum/constantinople/vm/instructions/storage.v new file mode 100644 index 0000000..29ef235 --- /dev/null +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/storage.v @@ -0,0 +1,228 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Storage Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM storage related instructions. +". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require state. +Axiom state_get_storage : + IsGlobalAlias globals state.globals "get_storage". +Axiom state_set_storage : + IsGlobalAlias globals state.globals "set_storage". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_WriteInStaticContext : + IsGlobalAlias globals exceptions.globals "WriteInStaticContext". + +Require gas. +Axiom gas_GAS_SLOAD : + IsGlobalAlias globals gas.globals "GAS_SLOAD". +Axiom gas_GAS_STORAGE_CLEAR_REFUND : + IsGlobalAlias globals gas.globals "GAS_STORAGE_CLEAR_REFUND". +Axiom gas_GAS_STORAGE_SET : + IsGlobalAlias globals gas.globals "GAS_STORAGE_SET". +Axiom gas_GAS_STORAGE_UPDATE : + IsGlobalAlias globals gas.globals "GAS_STORAGE_UPDATE". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition sload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Loads to the stack, the value corresponding to a certain key from the + storage of the current account. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let key := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_SLOAD" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "get_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition sstore : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a value at a certain key in the current context's storage. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let key := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let new_value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let current_value := + M.call (| + M.get_name (| globals, "get_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "new_value" |), Constant.int 0 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let gas_cost := + M.get_name (| globals, "GAS_STORAGE_SET" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let gas_cost := + M.get_name (| globals, "GAS_STORAGE_UPDATE" |) in + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_name (| globals, "new_value" |), Constant.int 0 |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "gas_cost" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "set_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |); + M.get_name (| globals, "new_value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/vm/interpreter.v b/CoqOfPython/ethereum/constantinople/vm/interpreter.v new file mode 100644 index 0000000..309a7b7 --- /dev/null +++ b/CoqOfPython/ethereum/constantinople/vm/interpreter.v @@ -0,0 +1,627 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Interpreter +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +A straightforward interpreter that executes EVM code. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Iterable : + IsGlobalAlias globals typing.globals "Iterable". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.trace. +Axiom ethereum_trace_EvmStop : + IsGlobalAlias globals ethereum.trace.globals "EvmStop". +Axiom ethereum_trace_OpEnd : + IsGlobalAlias globals ethereum.trace.globals "OpEnd". +Axiom ethereum_trace_OpException : + IsGlobalAlias globals ethereum.trace.globals "OpException". +Axiom ethereum_trace_OpStart : + IsGlobalAlias globals ethereum.trace.globals "OpStart". +Axiom ethereum_trace_PrecompileEnd : + IsGlobalAlias globals ethereum.trace.globals "PrecompileEnd". +Axiom ethereum_trace_PrecompileStart : + IsGlobalAlias globals ethereum.trace.globals "PrecompileStart". +Axiom ethereum_trace_TransactionEnd : + IsGlobalAlias globals ethereum.trace.globals "TransactionEnd". +Axiom ethereum_trace_evm_trace : + IsGlobalAlias globals ethereum.trace.globals "evm_trace". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_account_exists_and_is_empty : + IsGlobalAlias globals state.globals "account_exists_and_is_empty". +Axiom state_account_has_code_or_nonce : + IsGlobalAlias globals state.globals "account_has_code_or_nonce". +Axiom state_begin_transaction : + IsGlobalAlias globals state.globals "begin_transaction". +Axiom state_commit_transaction : + IsGlobalAlias globals state.globals "commit_transaction". +Axiom state_destroy_storage : + IsGlobalAlias globals state.globals "destroy_storage". +Axiom state_increment_nonce : + IsGlobalAlias globals state.globals "increment_nonce". +Axiom state_move_ether : + IsGlobalAlias globals state.globals "move_ether". +Axiom state_rollback_transaction : + IsGlobalAlias globals state.globals "rollback_transaction". +Axiom state_set_code : + IsGlobalAlias globals state.globals "set_code". +Axiom state_touch_account : + IsGlobalAlias globals state.globals "touch_account". + +Require vm. +Axiom vm_Message : + IsGlobalAlias globals vm.globals "Message". + +Require vm.gas. +Axiom vm_gas_GAS_CODE_DEPOSIT : + IsGlobalAlias globals vm.gas.globals "GAS_CODE_DEPOSIT". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require vm.precompiled_contracts.mapping. +Axiom vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : + IsGlobalAlias globals vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". + +Require __init__. +Axiom __init___Environment : + IsGlobalAlias globals __init__.globals "Environment". +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_AddressCollision : + IsGlobalAlias globals exceptions.globals "AddressCollision". +Axiom exceptions_ExceptionalHalt : + IsGlobalAlias globals exceptions.globals "ExceptionalHalt". +Axiom exceptions_InvalidOpcode : + IsGlobalAlias globals exceptions.globals "InvalidOpcode". +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". +Axiom exceptions_Revert : + IsGlobalAlias globals exceptions.globals "Revert". +Axiom exceptions_StackDepthLimitError : + IsGlobalAlias globals exceptions.globals "StackDepthLimitError". + +Require instructions. +Axiom instructions_Ops : + IsGlobalAlias globals instructions.globals "Ops". +Axiom instructions_op_implementation : + IsGlobalAlias globals instructions.globals "op_implementation". + +Require runtime. +Axiom runtime_get_valid_jump_destinations : + IsGlobalAlias globals runtime.globals "get_valid_jump_destinations". + +Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1024 + ], + make_dict [] + |) +)). + +Definition MAX_CODE_SIZE : Value.t := M.run ltac:(M.monadic ( + Constant.int 24576 +)). + +Definition MessageCallOutput : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition process_message_call : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + If `message.current` is empty then it creates a smart contract + else it executes a call from the `message.caller` to the `message.target`. + + Parameters + ---------- + message : + Transaction specific items. + + env : + External items required for EVM execution. + + Returns + ------- + output : `MessageCallOutput` + Output of the message call + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_name (| globals, "message" |), "target" |), M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let is_collision := + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_name (| globals, "is_collision" |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallOutput" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "tuple" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "AddressCollision" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let evm := + M.call (| + M.get_name (| globals, "process_create_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let evm := + M.call (| + M.get_name (| globals, "process_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_field (| M.get_name (| globals, "message" |), "target" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_field (| M.get_name (| globals, "message" |), "target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( +(* At stmt: unsupported node type: AnnAssign *) + let accounts_to_delete := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let touched_accounts := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let refund_counter := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let logs := + M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in + let accounts_to_delete := + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in + let touched_accounts := + M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |) in + let refund_counter := + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |) in + M.pure Constant.None_ + )) |) in + let tx_end := + M.call (| + M.get_name (| globals, "TransactionEnd" |), + make_list [ + BinOp.sub (| + M.get_field (| M.get_name (| globals, "message" |), "gas" |), + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + |); + M.get_field (| M.get_name (| globals, "evm" |), "output" |); + M.get_field (| M.get_name (| globals, "evm" |), "error" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "evm_trace" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "tx_end" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallOutput" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition process_create_message : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + Executes a call to create a smart contract. + + Parameters + ---------- + message : + Transaction specific items. + env : + External items required for EVM execution. + + Returns + ------- + evm: :py:class:`~ethereum.constantinople.vm.Evm` + Items containing execution specific objects. + " in + let _ := M.call (| + M.get_name (| globals, "begin_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "destroy_storage" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let evm := + M.call (| + M.get_name (| globals, "process_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), + (* then *) + ltac:(M.monadic ( + let contract_code := + M.get_field (| M.get_name (| globals, "evm" |), "output" |) in + let contract_code_gas := + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "contract_code" |) + ], + make_dict [] + |), + M.get_name (| globals, "GAS_CODE_DEPOSIT" |) + |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "rollback_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.get_name (| globals, "evm" |) + |) in + M.pure Constant.None_)). + +Definition process_message : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + Executes a call to create a smart contract. + + Parameters + ---------- + message : + Transaction specific items. + env : + External items required for EVM execution. + + Returns + ------- + evm: :py:class:`~ethereum.constantinople.vm.Evm` + Items containing execution specific objects + " in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_field (| M.get_name (| globals, "message" |), "depth" |), M.get_name (| globals, "STACK_DEPTH_LIMIT" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "StackDepthLimitError" |), + make_list [ + Constant.str "Stack depth limit reached" + ], + make_dict [] + |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "begin_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "touch_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + M.get_field (| M.get_name (| globals, "message" |), "should_transfer_value" |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_field (| M.get_name (| globals, "message" |), "value" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "move_ether" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "caller" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |); + M.get_field (| M.get_name (| globals, "message" |), "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let evm := + M.call (| + M.get_name (| globals, "execute_code" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "rollback_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "commit_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.get_name (| globals, "evm" |) + |) in + M.pure Constant.None_)). + +Definition execute_code : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + Executes bytecode present in the `message`. + + Parameters + ---------- + message : + Transaction specific items. + env : + External items required for EVM execution. + + Returns + ------- + evm: `ethereum.vm.EVM` + Items containing execution specific objects + " in + let code := + M.get_field (| M.get_name (| globals, "message" |), "code" |) in + let valid_jump_destinations := + M.call (| + M.get_name (| globals, "get_valid_jump_destinations" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) in + let evm := + M.call (| + M.get_name (| globals, "Evm" |), + make_list [], + make_dict [] + |) in +(* At stmt: unsupported node type: Try *) + let _ := M.return_ (| + M.get_name (| globals, "evm" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/vm/memory.v b/CoqOfPython/ethereum/constantinople/vm/memory.v new file mode 100644 index 0000000..fa8d906 --- /dev/null +++ b/CoqOfPython/ethereum/constantinople/vm/memory.v @@ -0,0 +1,153 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Memory +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +EVM memory operations. +". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_right_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "right_pad_zero_bytes". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". + +Definition memory_write : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "memory"; "start_position"; "value" ] |) in + let _ := Constant.str " + Writes to memory. + + Parameters + ---------- + memory : + Memory contents of the EVM. + start_position : + Starting pointer to the memory. + value : + Data to write to memory. + " in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) |), + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_)). + +Definition memory_read_bytes : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "memory"; "start_position"; "size" ] |) in + let _ := Constant.str " + Read bytes from memory. + + Parameters + ---------- + memory : + Memory contents of the EVM. + start_position : + Starting pointer to the memory. + size : + Size of the data that needs to be read from `start_position`. + + Returns + ------- + data_bytes : + Data read from memory. + " in + let _ := M.return_ (| + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |) + |) in + M.pure Constant.None_)). + +Definition buffer_read : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "buffer"; "start_position"; "size" ] |) in + let _ := Constant.str " + Read bytes from a buffer. Padding with zeros if necessary. + + Parameters + ---------- + buffer : + Memory contents of the EVM. + start_position : + Starting pointer to the memory. + size : + Size of the data that needs to be read from `start_position`. + + Returns + ------- + data_bytes : + Data read from memory. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "right_pad_zero_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/__init__.v new file mode 100644 index 0000000..0210a12 --- /dev/null +++ b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/__init__.v @@ -0,0 +1,107 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Precompiled Contract Addresses +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Addresses of precompiled contracts and mappings to their +implementations. +". + +Require utils.hexadecimal. +Axiom utils_hexadecimal_hex_to_address : + IsGlobalAlias globals utils.hexadecimal.globals "hex_to_address". + +Definition __all__ : Value.t := M.run ltac:(M.monadic ( + make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS"; Constant.str "MODEXP_ADDRESS"; Constant.str "ALT_BN128_ADD_ADDRESS"; Constant.str "ALT_BN128_MUL_ADDRESS"; Constant.str "ALT_BN128_PAIRING_CHECK_ADDRESS"; Constant.str "BLAKE2F_ADDRESS" ] +)). + +Definition ECRECOVER_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x01" + ], + make_dict [] + |) +)). + +Definition SHA256_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x02" + ], + make_dict [] + |) +)). + +Definition RIPEMD160_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x03" + ], + make_dict [] + |) +)). + +Definition IDENTITY_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x04" + ], + make_dict [] + |) +)). + +Definition MODEXP_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x05" + ], + make_dict [] + |) +)). + +Definition ALT_BN128_ADD_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x06" + ], + make_dict [] + |) +)). + +Definition ALT_BN128_MUL_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x07" + ], + make_dict [] + |) +)). + +Definition ALT_BN128_PAIRING_CHECK_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x08" + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/alt_bn128.v new file mode 100644 index 0000000..0823afa --- /dev/null +++ b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/alt_bn128.v @@ -0,0 +1,673 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) ALT_BN128 CONTRACTS +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the ALT_BN128 precompiled contracts. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.alt_bn128. +Axiom ethereum_crypto_alt_bn128_ALT_BN128_CURVE_ORDER : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "ALT_BN128_CURVE_ORDER". +Axiom ethereum_crypto_alt_bn128_ALT_BN128_PRIME : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "ALT_BN128_PRIME". +Axiom ethereum_crypto_alt_bn128_BNF : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF". +Axiom ethereum_crypto_alt_bn128_BNF2 : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF2". +Axiom ethereum_crypto_alt_bn128_BNF12 : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF12". +Axiom ethereum_crypto_alt_bn128_BNP : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNP". +Axiom ethereum_crypto_alt_bn128_BNP2 : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNP2". +Axiom ethereum_crypto_alt_bn128_pairing : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "pairing". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require vm.memory. +Axiom vm_memory_buffer_read : + IsGlobalAlias globals vm.memory.globals "buffer_read". + +Require exceptions. +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". + +Definition alt_bn128_add : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + The ALT_BN128 addition precompiled contract. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 500 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x0_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x0_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "x0_bytes" |) + ], + make_dict [] + |) in + let y0_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y0_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "y0_bytes" |) + ], + make_dict [] + |) in + let x1_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x1_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "x1_bytes" |) + ], + make_dict [] + |) in + let y1_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y1_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "y1_bytes" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ] do + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "i" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. +(* At stmt: unsupported node type: Try *) + let p := + BinOp.add (| + M.get_name (| globals, "p0" |), + M.get_name (| globals, "p1" |) + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + BinOp.add (| + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "p" |), "x" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "p" |), "y" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) + |) in + M.pure Constant.None_)). + +Definition alt_bn128_mul : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + The ALT_BN128 multiplication precompiled contract. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 40000 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x0_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x0_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "x0_bytes" |) + ], + make_dict [] + |) in + let y0_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y0_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "y0_bytes" |) + ], + make_dict [] + |) in + let n := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ] do + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "i" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. +(* At stmt: unsupported node type: Try *) + let p := + M.call (| + M.get_field (| M.get_name (| globals, "p0" |), "mul_by" |), + make_list [ + M.get_name (| globals, "n" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + BinOp.add (| + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "p" |), "x" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "p" |), "y" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) + |) in + M.pure Constant.None_)). + +Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + The ALT_BN128 pairing check precompiled contract. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 80000, + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 192 + |) + |), + Constant.int 100000 + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 192 + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 192 + |) + ], + make_dict [] + |) do + let values := + make_list [] in + For M.get_name (| globals, "j" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 6 + ], + make_dict [] + |) do + let value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "data" |), BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + M.get_name (| globals, "j" |) + |) + |):BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "j" |), + Constant.int 1 + |) + |) + |) |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "value" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "values" |), "append" |), + make_list [ + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + EndFor. +(* At stmt: unsupported node type: Try *) + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.call (| + M.get_field (| M.get_name (| globals, "p" |), "mul_by" |), + make_list [ + M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) + ], + make_dict [] + |), M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) |); + M.get_name (| globals, "OutOfGasError" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.call (| + M.get_field (| M.get_name (| globals, "q" |), "mul_by" |), + make_list [ + M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) + ], + make_dict [] + |), M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) |); + M.get_name (| globals, "OutOfGasError" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "p" |), M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_name (| globals, "q" |), M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let result := + BinOp.mult (| + M.get_name (| globals, "result" |), + M.call (| + M.get_name (| globals, "pairing" |), + make_list [ + M.get_name (| globals, "q" |); + M.get_name (| globals, "p" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "result" |), M.call (| + M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/ecrecover.v new file mode 100644 index 0000000..cc351b5 --- /dev/null +++ b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/ecrecover.v @@ -0,0 +1,269 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) ECRECOVER PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the ECRECOVER precompiled contract. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require ethereum.crypto.elliptic_curve. +Axiom ethereum_crypto_elliptic_curve_SECP256K1N : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_left_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_ECRECOVER : + IsGlobalAlias globals vm.gas.globals "GAS_ECRECOVER". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require vm.memory. +Axiom vm_memory_buffer_read : + IsGlobalAlias globals vm.memory.globals "buffer_read". + +Definition ecrecover : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Decrypts the address using elliptic curve DSA recovery mechanism and writes + the address to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_ECRECOVER" |) + ], + make_dict [] + |) in + let message_hash_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let message_hash := + M.call (| + M.get_name (| globals, "Hash32" |), + make_list [ + M.get_name (| globals, "message_hash_bytes" |) + ], + make_dict [] + |) in + let v := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let r := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let s := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 27 |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 28 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| Constant.int 0, M.get_name (| globals, "r" |) |), + ltac:(M.monadic ( + Compare.gt_e (| M.get_name (| globals, "r" |), M.get_name (| globals, "SECP256K1N" |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| Constant.int 0, M.get_name (| globals, "s" |) |), + ltac:(M.monadic ( + Compare.gt_e (| M.get_name (| globals, "s" |), M.get_name (| globals, "SECP256K1N" |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in +(* At stmt: unsupported node type: Try *) + let address := + M.get_subscript (| M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), Constant.int 12:Constant.int 32 |) in + let padded_address := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "address" |); + Constant.int 32 + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.get_name (| globals, "padded_address" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/identity.v new file mode 100644 index 0000000..fa96704 --- /dev/null +++ b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/identity.v @@ -0,0 +1,94 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) IDENTITY PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `IDENTITY` precompiled contract. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_IDENTITY : + IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY". +Axiom vm_gas_GAS_IDENTITY_WORD : + IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY_WORD". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition identity : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the message data to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let word_count := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_IDENTITY" |), + BinOp.mult (| + M.get_name (| globals, "GAS_IDENTITY_WORD" |), + M.get_name (| globals, "word_count" |) + |) + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.get_name (| globals, "data" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/mapping.v new file mode 100644 index 0000000..b1a0ed3 --- /dev/null +++ b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/mapping.v @@ -0,0 +1,76 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Precompiled Contract Addresses +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Mapping of precompiled contracts their implementations. +". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require __init__. +Axiom __init___ALT_BN128_ADD_ADDRESS : + IsGlobalAlias globals __init__.globals "ALT_BN128_ADD_ADDRESS". +Axiom __init___ALT_BN128_MUL_ADDRESS : + IsGlobalAlias globals __init__.globals "ALT_BN128_MUL_ADDRESS". +Axiom __init___ALT_BN128_PAIRING_CHECK_ADDRESS : + IsGlobalAlias globals __init__.globals "ALT_BN128_PAIRING_CHECK_ADDRESS". +Axiom __init___ECRECOVER_ADDRESS : + IsGlobalAlias globals __init__.globals "ECRECOVER_ADDRESS". +Axiom __init___IDENTITY_ADDRESS : + IsGlobalAlias globals __init__.globals "IDENTITY_ADDRESS". +Axiom __init___MODEXP_ADDRESS : + IsGlobalAlias globals __init__.globals "MODEXP_ADDRESS". +Axiom __init___RIPEMD160_ADDRESS : + IsGlobalAlias globals __init__.globals "RIPEMD160_ADDRESS". +Axiom __init___SHA256_ADDRESS : + IsGlobalAlias globals __init__.globals "SHA256_ADDRESS". + +Require alt_bn128. +Axiom alt_bn128_alt_bn128_add : + IsGlobalAlias globals alt_bn128.globals "alt_bn128_add". +Axiom alt_bn128_alt_bn128_mul : + IsGlobalAlias globals alt_bn128.globals "alt_bn128_mul". +Axiom alt_bn128_alt_bn128_pairing_check : + IsGlobalAlias globals alt_bn128.globals "alt_bn128_pairing_check". + +Require ecrecover. +Axiom ecrecover_ecrecover : + IsGlobalAlias globals ecrecover.globals "ecrecover". + +Require identity. +Axiom identity_identity : + IsGlobalAlias globals identity.globals "identity". + +Require modexp. +Axiom modexp_modexp : + IsGlobalAlias globals modexp.globals "modexp". + +Require ripemd160. +Axiom ripemd160_ripemd160 : + IsGlobalAlias globals ripemd160.globals "ripemd160". + +Require sha256. +Axiom sha256_sha256 : + IsGlobalAlias globals sha256.globals "sha256". + +(* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/modexp.v new file mode 100644 index 0000000..39ce4f9 --- /dev/null +++ b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/modexp.v @@ -0,0 +1,506 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) MODEXP PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `MODEXP` precompiled contract. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require memory. +Axiom memory_buffer_read : + IsGlobalAlias globals memory.globals "buffer_read". + +Definition GQUADDIVISOR : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 20 + ], + make_dict [] + |) +)). + +Definition modexp : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Calculates `(base**exp) % modulus` for arbitrary sized `base`, `exp` and. + `modulus`. The return value is the same length as the modulus. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let base_length := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exp_length := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let modulus_length := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exp_start := + BinOp.add (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |), + M.get_name (| globals, "base_length" |) + |) in + let exp_head := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.get_name (| globals, "exp_start" |); + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.get_name (| globals, "exp_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "exp_length" |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let adjusted_exp_length := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "max" |), + make_list [ + Constant.int 0; + BinOp.sub (| + M.call (| + M.get_field (| M.get_name (| globals, "exp_head" |), "bit_length" |), + make_list [], + make_dict [] + |), + Constant.int 1 + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let adjusted_exp_length := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 8, + BinOp.sub (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "exp_length" |) + ], + make_dict [] + |), + Constant.int 32 + |) + |), + M.call (| + M.get_name (| globals, "max" |), + make_list [ + Constant.int 0; + BinOp.sub (| + M.call (| + M.get_field (| M.get_name (| globals, "exp_head" |), "bit_length" |), + make_list [], + make_dict [] + |), + Constant.int 1 + |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.floor_div (| + BinOp.mult (| + M.call (| + M.get_name (| globals, "get_mult_complexity" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "max" |), + make_list [ + M.get_name (| globals, "base_length" |); + M.get_name (| globals, "modulus_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "max" |), + make_list [ + M.get_name (| globals, "adjusted_exp_length" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + ], + make_dict [] + |) + |), + M.get_name (| globals, "GQUADDIVISOR" |) + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_name (| globals, "base_length" |), Constant.int 0 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "modulus_length" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [], + make_dict [] + |) + |) in + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let base := + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |); + M.get_name (| globals, "base_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exp := + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.get_name (| globals, "exp_start" |); + M.get_name (| globals, "exp_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let modulus_start := + BinOp.add (| + M.get_name (| globals, "exp_start" |), + M.get_name (| globals, "exp_length" |) + |) in + let modulus := + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.get_name (| globals, "modulus_start" |); + M.get_name (| globals, "modulus_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "modulus" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + BinOp.mult (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |), + M.get_name (| globals, "modulus_length" |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pow" |), + make_list [ + M.get_name (| globals, "base" |); + M.get_name (| globals, "exp" |); + M.get_name (| globals, "modulus" |) + ], + make_dict [] + |) + ], + make_dict [] + |), "to_bytes" |), + make_list [ + M.get_name (| globals, "modulus_length" |); + Constant.str "big" + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition get_mult_complexity : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "x" ] |) in + let _ := Constant.str " + Estimate the complexity of performing Karatsuba multiplication. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| M.get_name (| globals, "x" |), Constant.int 64 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.pow (| + M.get_name (| globals, "x" |), + Constant.int 2 + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| M.get_name (| globals, "x" |), Constant.int 1024 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.sub (| + BinOp.add (| + BinOp.floor_div (| + BinOp.pow (| + M.get_name (| globals, "x" |), + Constant.int 2 + |), + Constant.int 4 + |), + BinOp.mult (| + Constant.int 96, + M.get_name (| globals, "x" |) + |) + |), + Constant.int 3072 + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.sub (| + BinOp.add (| + BinOp.floor_div (| + BinOp.pow (| + M.get_name (| globals, "x" |), + Constant.int 2 + |), + Constant.int 16 + |), + BinOp.mult (| + Constant.int 480, + M.get_name (| globals, "x" |) + |) + |), + Constant.int 199680 + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/ripemd160.v new file mode 100644 index 0000000..96f8dcd --- /dev/null +++ b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/ripemd160.v @@ -0,0 +1,122 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) RIPEMD160 PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `RIPEMD160` precompiled contract. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_left_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_RIPEMD160 : + IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160". +Axiom vm_gas_GAS_RIPEMD160_WORD : + IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160_WORD". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition ripemd160 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the ripemd160 hash to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let word_count := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_RIPEMD160" |), + BinOp.mult (| + M.get_name (| globals, "GAS_RIPEMD160_WORD" |), + M.get_name (| globals, "word_count" |) + |) + |) + ], + make_dict [] + |) in + let hash_bytes := + M.call (| + M.get_field (| M.call (| + M.get_field (| M.get_name (| globals, "hashlib" |), "new" |), + make_list [ + Constant.str "ripemd160"; + M.get_name (| globals, "data" |) + ], + make_dict [] + |), "digest" |), + make_list [], + make_dict [] + |) in + let padded_hash := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "hash_bytes" |); + Constant.int 32 + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.get_name (| globals, "padded_hash" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/sha256.v new file mode 100644 index 0000000..9f6d2bf --- /dev/null +++ b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/sha256.v @@ -0,0 +1,106 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) SHA256 PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `SHA256` precompiled contract. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_SHA256 : + IsGlobalAlias globals vm.gas.globals "GAS_SHA256". +Axiom vm_gas_GAS_SHA256_WORD : + IsGlobalAlias globals vm.gas.globals "GAS_SHA256_WORD". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition sha256 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the sha256 hash to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let word_count := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_SHA256" |), + BinOp.mult (| + M.get_name (| globals, "GAS_SHA256_WORD" |), + M.get_name (| globals, "word_count" |) + |) + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_field (| M.get_name (| globals, "hashlib" |), "sha256" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), "digest" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/vm/runtime.v b/CoqOfPython/ethereum/constantinople/vm/runtime.v new file mode 100644 index 0000000..835b46c --- /dev/null +++ b/CoqOfPython/ethereum/constantinople/vm/runtime.v @@ -0,0 +1,125 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Runtime Operations +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Runtime related operations used while executing EVM code. +". + +Require typing. +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require instructions. +Axiom instructions_Ops : + IsGlobalAlias globals instructions.globals "Ops". + +Definition get_valid_jump_destinations : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "code" ] |) in + let _ := Constant.str " + Analyze the evm code to obtain the set of valid jump destinations. + + Valid jump destinations are defined as follows: + * The jump destination is less than the length of the code. + * The jump destination should have the `JUMPDEST` opcode (0x5B). + * The jump destination shouldn't be part of the data corresponding to + `PUSH-N` opcodes. + + Note - Jump destinations are 0-indexed. + + Parameters + ---------- + code : + The EVM code which is to be executed. + + Returns + ------- + valid_jump_destinations: `Set[Uint]` + The set of valid jump destinations in the code. + " in + let valid_jump_destinations := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let pc := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + While Compare.lt (| M.get_name (| globals, "pc" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) |) do +(* At stmt: unsupported node type: Try *) + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "current_opcode" |), M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), + make_list [ + M.get_name (| globals, "pc" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + (* At expr: unsupported node type: Compare *), + (* then *) + ltac:(M.monadic ( + let push_data_size := + BinOp.add (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) + |), + Constant.int 1 + |) in + let pc := BinOp.add + M.get_name (| globals, "push_data_size" |) + M.get_name (| globals, "push_data_size" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let pc := BinOp.add + Constant.int 1 + Constant.int 1 in + EndWhile. + let _ := M.return_ (| + M.get_name (| globals, "valid_jump_destinations" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/vm/stack.v b/CoqOfPython/ethereum/constantinople/vm/stack.v new file mode 100644 index 0000000..42ea42d --- /dev/null +++ b/CoqOfPython/ethereum/constantinople/vm/stack.v @@ -0,0 +1,120 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Stack +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the stack operators for the EVM. +". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require exceptions. +Axiom exceptions_StackOverflowError : + IsGlobalAlias globals exceptions.globals "StackOverflowError". +Axiom exceptions_StackUnderflowError : + IsGlobalAlias globals exceptions.globals "StackUnderflowError". + +Definition pop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "stack" ] |) in + let _ := Constant.str " + Pops the top item off of `stack`. + + Parameters + ---------- + stack : + EVM stack. + + Returns + ------- + value : `U256` + The top element on the stack. + + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "StackUnderflowError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "pop" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition push : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "stack"; "value" ] |) in + let _ := Constant.str " + Pushes `value` onto `stack`. + + Parameters + ---------- + stack : + EVM stack. + + value : + Item to be pushed onto `stack`. + + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), Constant.int 1024 |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "StackOverflowError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "append" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/crypto/__init__.v b/CoqOfPython/ethereum/crypto/__init__.v new file mode 100644 index 0000000..97b4e39 --- /dev/null +++ b/CoqOfPython/ethereum/crypto/__init__.v @@ -0,0 +1,8 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Cryptographic primitives used in Ethereum. +". diff --git a/CoqOfPython/ethereum/crypto/alt_bn128.v b/CoqOfPython/ethereum/crypto/alt_bn128.v new file mode 100644 index 0000000..00b0acf --- /dev/null +++ b/CoqOfPython/ethereum/crypto/alt_bn128.v @@ -0,0 +1,677 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +The alt_bn128 curve +^^^^^^^^^^^^^^^^^^^ +". + +Require __init__. +Axiom __init___elliptic_curve : + IsGlobalAlias globals __init__.globals "elliptic_curve". +Axiom __init___finite_field : + IsGlobalAlias globals __init__.globals "finite_field". + +Definition ALT_BN128_PRIME : Value.t := M.run ltac:(M.monadic ( + Constant.int 21888242871839275222246405745257275088696311157297823662689037894645226208583 +)). + +Definition ALT_BN128_CURVE_ORDER : Value.t := M.run ltac:(M.monadic ( + Constant.int 21888242871839275222246405745257275088548364400416034343698204186575808495617 +)). + +Definition ATE_PAIRING_COUNT : Value.t := M.run ltac:(M.monadic ( + Constant.int 29793968203157093289 +)). + +Definition ATE_PAIRING_COUNT_BITS : Value.t := M.run ltac:(M.monadic ( + Constant.int 63 +)). + +Definition BNF : Value.t := + builtins.make_klass + [(* At base: unsupported node type: Attribute *)] + [ + + ] + [ + + ]. + +Definition BNP : Value.t := + builtins.make_klass + [(* At base: unsupported node type: Attribute *)] + [ + + ] + [ + + ]. + +Definition BNF2 : Value.t := + builtins.make_klass + [(* At base: unsupported node type: Attribute *)] + [ + + ] + [ + + ]. + +(* At top_level_stmt: unsupported node type: Assign *) + +Definition expr_45 : Value.t := + Constant.str "autoapi_noindex". + +(* At top_level_stmt: unsupported node type: Assign *) + +Definition expr_48 : Value.t := + Constant.str "autoapi_noindex". + +(* At top_level_stmt: unsupported node type: Assign *) + +Definition expr_51 : Value.t := + Constant.str "autoapi_noindex". + +Definition BNP2 : Value.t := + builtins.make_klass + [(* At base: unsupported node type: Attribute *)] + [ + + ] + [ + + ]. + +Definition BNF12 : Value.t := + builtins.make_klass + [(* At base: unsupported node type: Attribute *)] + [ + + ] + [ + ( + "__mul__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in + let _ := Constant.str " + Multiplication special cased for BNF12. + " in + let mul := + BinOp.mult (| + make_list [ + Constant.int 0 + ], + Constant.int 23 + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 12 + ], + make_dict [] + |) do + For M.get_name (| globals, "j" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 12 + ], + make_dict [] + |) do + let _ := M.assign_op (| + BinOp.add, + M.get_subscript (| M.get_name (| globals, "mul" |), BinOp.add (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "j" |) + |) |), + BinOp.mult (| + M.get_subscript (| M.get_name (| globals, "self" |), M.get_name (| globals, "i" |) |), + M.get_subscript (| M.get_name (| globals, "right" |), M.get_name (| globals, "j" |) |) + |) + |) in + EndFor. + EndFor. + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 22; + Constant.int 11; + UnOp.sub (| Constant.int 1 |) + ], + make_dict [] + |) do + let _ := M.assign_op (| + BinOp.sub, + M.get_subscript (| M.get_name (| globals, "mul" |), BinOp.sub (| + M.get_name (| globals, "i" |), + Constant.int 6 + |) |), + BinOp.mult (| + M.get_subscript (| M.get_name (| globals, "mul" |), M.get_name (| globals, "i" |) |), + UnOp.sub (| Constant.int 18 |) + |) + |) in + let _ := M.assign_op (| + BinOp.sub, + M.get_subscript (| M.get_name (| globals, "mul" |), BinOp.sub (| + M.get_name (| globals, "i" |), + Constant.int 12 + |) |), + BinOp.mult (| + M.get_subscript (| M.get_name (| globals, "mul" |), M.get_name (| globals, "i" |) |), + Constant.int 82 + |) + |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "BNF12" |), "__new__" |), + make_list [ + M.get_name (| globals, "BNF12" |); + M.get_subscript (| M.get_name (| globals, "mul" |), (* At expr: unsupported node type: NoneType *):Constant.int 12 |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)) + ) + ]. + +(* At top_level_stmt: unsupported node type: Assign *) + +Definition expr_98 : Value.t := + Constant.str "autoapi_noindex". + +(* At top_level_stmt: unsupported node type: Assign *) + +Definition expr_101 : Value.t := + Constant.str "autoapi_noindex". + +(* At top_level_stmt: unsupported node type: Assign *) + +Definition expr_104 : Value.t := + Constant.str "autoapi_noindex". + +Definition BNP12 : Value.t := + builtins.make_klass + [(* At base: unsupported node type: Attribute *)] + [ + + ] + [ + + ]. + +Definition bnf2_to_bnf12 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "x" ] |) in + let _ := Constant.str " + Lift a field element in `BNF2` to `BNF12`. + " in + let _ := M.return_ (| + BinOp.add (| + M.call (| + M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "x" |), Constant.int 0 |) + ], + make_dict [] + |), + BinOp.mult (| + M.call (| + M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "x" |), Constant.int 1 |) + ], + make_dict [] + |), + BinOp.sub (| + M.get_field (| M.get_name (| globals, "BNF12" |), "i_plus_9" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), + make_list [ + Constant.int 9 + ], + make_dict [] + |) + |) + |) + |) + |) in + M.pure Constant.None_)). + +Definition bnp_to_bnp12 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "p" ] |) in + let _ := Constant.str " + Lift a point from `BNP` to `BNP12`. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "BNP12" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), + make_list [ + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_field (| M.get_name (| globals, "p" |), "x" |) + ], + make_dict [] + |) + ], + make_dict [] + |); + M.call (| + M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), + make_list [ + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_field (| M.get_name (| globals, "p" |), "y" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition twist : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "p" ] |) in + let _ := Constant.str " + Apply to twist to change variables from the curve `BNP2` to `BNP12`. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "BNP12" |), + make_list [ + BinOp.mult (| + M.call (| + M.get_name (| globals, "bnf2_to_bnf12" |), + make_list [ + M.get_field (| M.get_name (| globals, "p" |), "x" |) + ], + make_dict [] + |), + BinOp.pow (| + M.get_field (| M.get_name (| globals, "BNF12" |), "w" |), + Constant.int 2 + |) + |); + BinOp.mult (| + M.call (| + M.get_name (| globals, "bnf2_to_bnf12" |), + make_list [ + M.get_field (| M.get_name (| globals, "p" |), "y" |) + ], + make_dict [] + |), + BinOp.pow (| + M.get_field (| M.get_name (| globals, "BNF12" |), "w" |), + Constant.int 3 + |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition linefunc : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "p1"; "p2"; "t" ] |) in + let _ := Constant.str " + Evaluate the function defining the line between points `p1` and `p2` at the + point `t`. The mathematical significance of this function is that is has + divisor `(p1) + (p2) + (p1 + p2) - 3(O)`. + + Note: Abstract mathematical presentations of Miller's algorithm often + specify the divisor `(p1) + (p2) - (p1 + p2) - (O)`. This turns out not to + matter. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| M.get_field (| M.get_name (| globals, "p1" |), "x" |), M.get_field (| M.get_name (| globals, "p2" |), "x" |) |), + (* then *) + ltac:(M.monadic ( + let lam := + BinOp.div (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "p2" |), "y" |), + M.get_field (| M.get_name (| globals, "p1" |), "y" |) + |), + BinOp.sub (| + M.get_field (| M.get_name (| globals, "p2" |), "x" |), + M.get_field (| M.get_name (| globals, "p1" |), "x" |) + |) + |) in + let _ := M.return_ (| + BinOp.sub (| + BinOp.mult (| + M.get_name (| globals, "lam" |), + BinOp.sub (| + M.get_field (| M.get_name (| globals, "t" |), "x" |), + M.get_field (| M.get_name (| globals, "p1" |), "x" |) + |) + |), + BinOp.sub (| + M.get_field (| M.get_name (| globals, "t" |), "y" |), + M.get_field (| M.get_name (| globals, "p1" |), "y" |) + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_name (| globals, "p1" |), "y" |), M.get_field (| M.get_name (| globals, "p2" |), "y" |) |), + (* then *) + ltac:(M.monadic ( + let lam := + BinOp.div (| + BinOp.mult (| + M.call (| + M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |), + BinOp.pow (| + M.get_field (| M.get_name (| globals, "p1" |), "x" |), + Constant.int 2 + |) + |), + BinOp.mult (| + M.call (| + M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), + make_list [ + Constant.int 2 + ], + make_dict [] + |), + M.get_field (| M.get_name (| globals, "p1" |), "y" |) + |) + |) in + let _ := M.return_ (| + BinOp.sub (| + BinOp.mult (| + M.get_name (| globals, "lam" |), + BinOp.sub (| + M.get_field (| M.get_name (| globals, "t" |), "x" |), + M.get_field (| M.get_name (| globals, "p1" |), "x" |) + |) + |), + BinOp.sub (| + M.get_field (| M.get_name (| globals, "t" |), "y" |), + M.get_field (| M.get_name (| globals, "p1" |), "y" |) + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "t" |), "x" |), + M.get_field (| M.get_name (| globals, "p1" |), "x" |) + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition miller_loop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "q"; "p" ] |) in + let _ := Constant.str " + The core of the pairing algorithm. + " in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.eq (| M.get_name (| globals, "p" |), M.call (| + M.get_field (| M.get_name (| globals, "BNP12" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "q" |), M.call (| + M.get_field (| M.get_name (| globals, "BNP12" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let r := + M.get_name (| globals, "q" |) in + let f := + M.call (| + M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "ATE_PAIRING_COUNT_BITS" |); + UnOp.sub (| Constant.int 1 |); + UnOp.sub (| Constant.int 1 |) + ], + make_dict [] + |) do + let f := + BinOp.mult (| + BinOp.mult (| + M.get_name (| globals, "f" |), + M.get_name (| globals, "f" |) + |), + M.call (| + M.get_name (| globals, "linefunc" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "r" |); + M.get_name (| globals, "p" |) + ], + make_dict [] + |) + |) in + let r := + M.call (| + M.get_field (| M.get_name (| globals, "r" |), "double" |), + make_list [], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BinOp.bit_and (| + BinOp.sub (| + M.get_name (| globals, "ATE_PAIRING_COUNT" |), + Constant.int 1 + |), + BinOp.pow (| + Constant.int 2, + M.get_name (| globals, "i" |) + |) + |), + (* then *) + ltac:(M.monadic ( + let f := + BinOp.mult (| + M.get_name (| globals, "f" |), + M.call (| + M.get_name (| globals, "linefunc" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "q" |); + M.get_name (| globals, "p" |) + ], + make_dict [] + |) + |) in + let r := + BinOp.add (| + M.get_name (| globals, "r" |), + M.get_name (| globals, "q" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.assert (| Compare.eq (| M.get_name (| globals, "r" |), M.call (| + M.get_field (| M.get_name (| globals, "q" |), "mul_by" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "ATE_PAIRING_COUNT" |), + Constant.int 1 + |) + ], + make_dict [] + |) |) |) in + let q1 := + M.call (| + M.get_name (| globals, "BNP12" |), + make_list [ + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "q" |), "x" |), "frobenius" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "q" |), "y" |), "frobenius" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) in + let nq2 := + M.call (| + M.get_name (| globals, "BNP12" |), + make_list [ + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "q1" |), "x" |), "frobenius" |), + make_list [], + make_dict [] + |); + UnOp.sub (| M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "q1" |), "y" |), "frobenius" |), + make_list [], + make_dict [] + |) |) + ], + make_dict [] + |) in + let f := + BinOp.mult (| + M.get_name (| globals, "f" |), + M.call (| + M.get_name (| globals, "linefunc" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "q1" |); + M.get_name (| globals, "p" |) + ], + make_dict [] + |) + |) in + let r := + BinOp.add (| + M.get_name (| globals, "r" |), + M.get_name (| globals, "q1" |) + |) in + let f := + BinOp.mult (| + M.get_name (| globals, "f" |), + M.call (| + M.get_name (| globals, "linefunc" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "nq2" |); + M.get_name (| globals, "p" |) + ], + make_dict [] + |) + |) in + let _ := M.return_ (| + BinOp.pow (| + M.get_name (| globals, "f" |), + BinOp.floor_div (| + BinOp.sub (| + BinOp.pow (| + M.get_name (| globals, "ALT_BN128_PRIME" |), + Constant.int 12 + |), + Constant.int 1 + |), + M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) + |) + |) + |) in + M.pure Constant.None_)). + +Definition pairing : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "q"; "p" ] |) in + let _ := Constant.str " + Compute the pairing of `q` and `p`. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "miller_loop" |), + make_list [ + M.call (| + M.get_name (| globals, "twist" |), + make_list [ + M.get_name (| globals, "q" |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "bnp_to_bnp12" |), + make_list [ + M.get_name (| globals, "p" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/crypto/blake2.v b/CoqOfPython/ethereum/crypto/blake2.v new file mode 100644 index 0000000..68db13a --- /dev/null +++ b/CoqOfPython/ethereum/crypto/blake2.v @@ -0,0 +1,541 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +The Blake2 Implementation +^^^^^^^^^^^^^^^^^^^^^^^^^^ +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Definition spit_le_to_uint : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "data"; "start"; "num_words" ] |) in + let _ := Constant.str " + Extracts 8 byte words from a given data. + + Parameters + ---------- + data : + The data in bytes from which the words need to be extracted + start : + Position to start the extraction + num_words: + The number of words to be extracted + " in + let words := + make_list [] in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "num_words" |) + ], + make_dict [] + |) do + let start_position := + BinOp.add (| + M.get_name (| globals, "start" |), + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 8 + |) + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "words" |), "append" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_le_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "data" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.get_name (| globals, "start_position" |), + Constant.int 8 + |) |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + EndFor. + let _ := M.return_ (| + M.get_name (| globals, "words" |) + |) in + M.pure Constant.None_)). + +Definition Blake2 : Value.t := + builtins.make_klass + [] + [ + + ] + [ + ( + "get_blake2_parameters", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "data" ] |) in + let _ := Constant.str " + Extract the parameters required in the Blake2 compression function + from the provided bytes data. + + Parameters + ---------- + data : + The bytes data that has been passed in the message. + " in + let rounds := + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "data" |), (* At expr: unsupported node type: NoneType *):Constant.int 4 |) + ], + make_dict [] + |) in + let h := + M.call (| + M.get_name (| globals, "spit_le_to_uint" |), + make_list [ + M.get_name (| globals, "data" |); + Constant.int 4; + Constant.int 8 + ], + make_dict [] + |) in + let m := + M.call (| + M.get_name (| globals, "spit_le_to_uint" |), + make_list [ + M.get_name (| globals, "data" |); + Constant.int 68; + Constant.int 16 + ], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "t_0" |); M.get_name (| globals, "t_1" |) ], + M.call (| + M.get_name (| globals, "spit_le_to_uint" |), + make_list [ + M.get_name (| globals, "data" |); + Constant.int 196; + Constant.int 2 + ], + make_dict [] + |) + |) in + let f := + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "data" |), Constant.int 212:(* At expr: unsupported node type: NoneType *) |) + ], + make_dict [] + |) in + let _ := M.return_ (| + make_tuple [ M.get_name (| globals, "rounds" |); M.get_name (| globals, "h" |); M.get_name (| globals, "m" |); M.get_name (| globals, "t_0" |); M.get_name (| globals, "t_1" |); M.get_name (| globals, "f" |) ] + |) in + M.pure Constant.None_)) + ); + ( + "G", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "v"; "a"; "b"; "c"; "d"; "x"; "y" ] |) in + let _ := Constant.str " + The mixing function used in Blake2 + https://datatracker.ietf.org/doc/html/rfc7693#section-3.1 + + Parameters + ---------- + v : + The working vector to be mixed. + a, b, c, d : + Indexes within v of the words to be mixed. + x, y : + The two input words for the mixing. + " in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "a" |) |), + BinOp.mod_ (| + BinOp.add (| + BinOp.add (| + M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "a" |) |), + M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "b" |) |) + |), + M.get_name (| globals, "x" |) + |), + M.get_field (| M.get_name (| globals, "self" |), "max_word" |) + |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "d" |) |), + BinOp.bit_xor (| + BinOp.r_shift (| + BinOp.bit_xor (| + M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "d" |) |), + M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "a" |) |) + |), + M.get_field (| M.get_name (| globals, "self" |), "R1" |) + |), + BinOp.mod_ (| + BinOp.l_shift (| + BinOp.bit_xor (| + M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "d" |) |), + M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "a" |) |) + |), + M.get_field (| M.get_name (| globals, "self" |), "w_R1" |) + |), + M.get_field (| M.get_name (| globals, "self" |), "max_word" |) + |) + |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "c" |) |), + BinOp.mod_ (| + BinOp.add (| + M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "c" |) |), + M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "d" |) |) + |), + M.get_field (| M.get_name (| globals, "self" |), "max_word" |) + |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "b" |) |), + BinOp.bit_xor (| + BinOp.r_shift (| + BinOp.bit_xor (| + M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "b" |) |), + M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "c" |) |) + |), + M.get_field (| M.get_name (| globals, "self" |), "R2" |) + |), + BinOp.mod_ (| + BinOp.l_shift (| + BinOp.bit_xor (| + M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "b" |) |), + M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "c" |) |) + |), + M.get_field (| M.get_name (| globals, "self" |), "w_R2" |) + |), + M.get_field (| M.get_name (| globals, "self" |), "max_word" |) + |) + |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "a" |) |), + BinOp.mod_ (| + BinOp.add (| + BinOp.add (| + M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "a" |) |), + M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "b" |) |) + |), + M.get_name (| globals, "y" |) + |), + M.get_field (| M.get_name (| globals, "self" |), "max_word" |) + |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "d" |) |), + BinOp.bit_xor (| + BinOp.r_shift (| + BinOp.bit_xor (| + M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "d" |) |), + M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "a" |) |) + |), + M.get_field (| M.get_name (| globals, "self" |), "R3" |) + |), + BinOp.mod_ (| + BinOp.l_shift (| + BinOp.bit_xor (| + M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "d" |) |), + M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "a" |) |) + |), + M.get_field (| M.get_name (| globals, "self" |), "w_R3" |) + |), + M.get_field (| M.get_name (| globals, "self" |), "max_word" |) + |) + |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "c" |) |), + BinOp.mod_ (| + BinOp.add (| + M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "c" |) |), + M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "d" |) |) + |), + M.get_field (| M.get_name (| globals, "self" |), "max_word" |) + |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "b" |) |), + BinOp.bit_xor (| + BinOp.r_shift (| + BinOp.bit_xor (| + M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "b" |) |), + M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "c" |) |) + |), + M.get_field (| M.get_name (| globals, "self" |), "R4" |) + |), + BinOp.mod_ (| + BinOp.l_shift (| + BinOp.bit_xor (| + M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "b" |) |), + M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "c" |) |) + |), + M.get_field (| M.get_name (| globals, "self" |), "w_R4" |) + |), + M.get_field (| M.get_name (| globals, "self" |), "max_word" |) + |) + |) + |) in + let _ := M.return_ (| + M.get_name (| globals, "v" |) + |) in + M.pure Constant.None_)) + ); + ( + "compress", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "num_rounds"; "h"; "m"; "t_0"; "t_1"; "f" ] |) in + let _ := Constant.str " + 'F Compression' from section 3.2 of RFC 7693: + https://tools.ietf.org/html/rfc7693#section-3.2 + + Parameters + ---------- + num_rounds : + The number of rounds. A 32-bit unsigned big-endian word + h : + The state vector. 8 unsigned 64-bit little-endian words + m : + The message block vector. 16 unsigned 64-bit little-endian words + t_0, t_1 : + Offset counters. 2 unsigned 64-bit little-endian words + f: + The final block indicator flag. An 8-bit word + " in + let v := + BinOp.mult (| + make_list [ + Constant.int 0 + ], + Constant.int 16 + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "v" |), Constant.int 0:Constant.int 8 |), + M.get_name (| globals, "h" |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "v" |), Constant.int 8:Constant.int 15 |), + M.get_field (| M.get_name (| globals, "self" |), "IV" |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "v" |), Constant.int 12 |), + BinOp.bit_xor (| + M.get_name (| globals, "t_0" |), + M.get_subscript (| M.get_field (| M.get_name (| globals, "self" |), "IV" |), Constant.int 4 |) + |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "v" |), Constant.int 13 |), + BinOp.bit_xor (| + M.get_name (| globals, "t_1" |), + M.get_subscript (| M.get_field (| M.get_name (| globals, "self" |), "IV" |), Constant.int 5 |) + |) + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_name (| globals, "f" |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "v" |), Constant.int 14 |), + BinOp.bit_xor (| + M.get_subscript (| M.get_name (| globals, "v" |), Constant.int 14 |), + M.get_field (| M.get_name (| globals, "self" |), "mask_bits" |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + For M.get_name (| globals, "r" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "num_rounds" |) + ], + make_dict [] + |) do + let s := + M.get_subscript (| M.get_field (| M.get_name (| globals, "self" |), "sigma" |), BinOp.mod_ (| + M.get_name (| globals, "r" |), + M.get_field (| M.get_name (| globals, "self" |), "sigma_len" |) + |) |) in + let v := + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "G" |), + make_list [ + M.get_name (| globals, "v" |); + Constant.int 0; + Constant.int 4; + Constant.int 8; + Constant.int 12; + M.get_subscript (| M.get_name (| globals, "m" |), M.get_subscript (| M.get_name (| globals, "s" |), Constant.int 0 |) |); + M.get_subscript (| M.get_name (| globals, "m" |), M.get_subscript (| M.get_name (| globals, "s" |), Constant.int 1 |) |) + ], + make_dict [] + |) in + let v := + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "G" |), + make_list [ + M.get_name (| globals, "v" |); + Constant.int 1; + Constant.int 5; + Constant.int 9; + Constant.int 13; + M.get_subscript (| M.get_name (| globals, "m" |), M.get_subscript (| M.get_name (| globals, "s" |), Constant.int 2 |) |); + M.get_subscript (| M.get_name (| globals, "m" |), M.get_subscript (| M.get_name (| globals, "s" |), Constant.int 3 |) |) + ], + make_dict [] + |) in + let v := + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "G" |), + make_list [ + M.get_name (| globals, "v" |); + Constant.int 2; + Constant.int 6; + Constant.int 10; + Constant.int 14; + M.get_subscript (| M.get_name (| globals, "m" |), M.get_subscript (| M.get_name (| globals, "s" |), Constant.int 4 |) |); + M.get_subscript (| M.get_name (| globals, "m" |), M.get_subscript (| M.get_name (| globals, "s" |), Constant.int 5 |) |) + ], + make_dict [] + |) in + let v := + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "G" |), + make_list [ + M.get_name (| globals, "v" |); + Constant.int 3; + Constant.int 7; + Constant.int 11; + Constant.int 15; + M.get_subscript (| M.get_name (| globals, "m" |), M.get_subscript (| M.get_name (| globals, "s" |), Constant.int 6 |) |); + M.get_subscript (| M.get_name (| globals, "m" |), M.get_subscript (| M.get_name (| globals, "s" |), Constant.int 7 |) |) + ], + make_dict [] + |) in + let v := + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "G" |), + make_list [ + M.get_name (| globals, "v" |); + Constant.int 0; + Constant.int 5; + Constant.int 10; + Constant.int 15; + M.get_subscript (| M.get_name (| globals, "m" |), M.get_subscript (| M.get_name (| globals, "s" |), Constant.int 8 |) |); + M.get_subscript (| M.get_name (| globals, "m" |), M.get_subscript (| M.get_name (| globals, "s" |), Constant.int 9 |) |) + ], + make_dict [] + |) in + let v := + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "G" |), + make_list [ + M.get_name (| globals, "v" |); + Constant.int 1; + Constant.int 6; + Constant.int 11; + Constant.int 12; + M.get_subscript (| M.get_name (| globals, "m" |), M.get_subscript (| M.get_name (| globals, "s" |), Constant.int 10 |) |); + M.get_subscript (| M.get_name (| globals, "m" |), M.get_subscript (| M.get_name (| globals, "s" |), Constant.int 11 |) |) + ], + make_dict [] + |) in + let v := + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "G" |), + make_list [ + M.get_name (| globals, "v" |); + Constant.int 2; + Constant.int 7; + Constant.int 8; + Constant.int 13; + M.get_subscript (| M.get_name (| globals, "m" |), M.get_subscript (| M.get_name (| globals, "s" |), Constant.int 12 |) |); + M.get_subscript (| M.get_name (| globals, "m" |), M.get_subscript (| M.get_name (| globals, "s" |), Constant.int 13 |) |) + ], + make_dict [] + |) in + let v := + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "G" |), + make_list [ + M.get_name (| globals, "v" |); + Constant.int 3; + Constant.int 4; + Constant.int 9; + Constant.int 14; + M.get_subscript (| M.get_name (| globals, "m" |), M.get_subscript (| M.get_name (| globals, "s" |), Constant.int 14 |) |); + M.get_subscript (| M.get_name (| globals, "m" |), M.get_subscript (| M.get_name (| globals, "s" |), Constant.int 15 |) |) + ], + make_dict [] + |) in + EndFor. + let result_message_words := + (BinOp.bit_xor (| + BinOp.bit_xor (| + M.get_subscript (| M.get_name (| globals, "h" |), M.get_name (| globals, "i" |) |), + M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "v" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 8 + |) |) + |) for (* At expr: unsupported node type: list *)) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "struct" |), "pack" |), + make_list_concat (| [ + make_list [ + BinOp.mod_ (| + Constant.str "<8%s", + M.get_field (| M.get_name (| globals, "self" |), "word_format" |) + |) + ]; + M.get_name (| globals, "result_message_words" |) + ] |), + make_dict [] + |) + |) in + M.pure Constant.None_)) + ) + ]. + +Definition Blake2b : Value.t := + builtins.make_klass + [(globals, "Blake2")] + [ + + ] + [ + + ]. diff --git a/CoqOfPython/ethereum/crypto/elliptic_curve.v b/CoqOfPython/ethereum/crypto/elliptic_curve.v new file mode 100644 index 0000000..c0bae4d --- /dev/null +++ b/CoqOfPython/ethereum/crypto/elliptic_curve.v @@ -0,0 +1,669 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Elliptic Curves +^^^^^^^^^^^^^^^ +". + +Require typing. +Axiom typing_Generic : + IsGlobalAlias globals typing.globals "Generic". +Axiom typing_Type_ : + IsGlobalAlias globals typing.globals "Type_". +Axiom typing_TypeVar : + IsGlobalAlias globals typing.globals "TypeVar". + +(* At top_level_stmt: unsupported node type: Import *) + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". + +Require finite_field. +Axiom finite_field_Field : + IsGlobalAlias globals finite_field.globals "Field". + +Require hash. +Axiom hash_Hash32 : + IsGlobalAlias globals hash.globals "Hash32". + +Definition SECP256K1N : Value.t := M.run ltac:(M.monadic ( + Constant.int 115792089237316195423570985008687907852837564279074904382605163141518161494337 +)). + +Definition F : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "TypeVar" |), + make_list [ + Constant.str "F" + ], + make_dict [] + |) +)). + +Definition T : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "TypeVar" |), + make_list [ + Constant.str "T" + ], + make_dict [] + |) +)). + +Definition secp256k1_recover : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "r"; "s"; "v"; "msg_hash" ] |) in + let _ := Constant.str " + Recovers the public key from a given signature. + + Parameters + ---------- + r : + TODO + s : + TODO + v : + TODO + msg_hash : + Hash of the message being recovered. + + Returns + ------- + public_key : `ethereum.base_types.Bytes` + Recovered public key. + " in + let r_bytes := + M.call (| + M.get_field (| M.get_name (| globals, "r" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let s_bytes := + M.call (| + M.get_field (| M.get_name (| globals, "s" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let signature := + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [ + BinOp.mult (| + make_list [ + Constant.int 0 + ], + Constant.int 65 + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "signature" |), BinOp.sub (| + Constant.int 32, + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "r_bytes" |) + ], + make_dict [] + |) + |):Constant.int 32 |), + M.get_name (| globals, "r_bytes" |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "signature" |), BinOp.sub (| + Constant.int 64, + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "s_bytes" |) + ], + make_dict [] + |) + |):Constant.int 64 |), + M.get_name (| globals, "s_bytes" |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "signature" |), Constant.int 64 |), + M.get_name (| globals, "v" |) + |) in + let public_key := + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "coincurve" |), "PublicKey" |), "from_signature_and_message" |), + make_list [ + M.call (| + M.get_name (| globals, "bytes" |), + make_list [ + M.get_name (| globals, "signature" |) + ], + make_dict [] + |); + M.get_name (| globals, "msg_hash" |) + ], + make_dict [] + |) in + let public_key := + M.get_subscript (| M.call (| + M.get_field (| M.get_name (| globals, "public_key" |), "format" |), + make_list [], + make_dict [] + |), Constant.int 1:(* At expr: unsupported node type: NoneType *) |) in + let _ := M.return_ (| + M.get_name (| globals, "public_key" |) + |) in + M.pure Constant.None_)). + +Definition EllipticCurve : Value.t := + builtins.make_klass + [(* At base: unsupported node type: Subscript *)] + [ + ( + "point_at_infinity", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "cls" ] |) in + let _ := Constant.str " + Return the point at infinity. This is the identity element of the group + operation. + + The point at infinity doesn't actually have coordinates so we use + `(0, 0)` (which isn't on the curve) to represent it. + " in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "cls" |), "__new__" |), + make_list [ + M.get_name (| globals, "cls" |); + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "cls" |), "FIELD" |), "zero" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "cls" |), "FIELD" |), "zero" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)) + ) + ] + [ + ( + "__new__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "cls"; "x"; "y" ] |) in + let _ := Constant.str " + Make new point on the curve. The point is not checked to see if it is + on the curve. + " in + let res := + M.call (| + M.get_field (| M.get_name (| globals, "object" |), "__new__" |), + make_list [ + M.get_name (| globals, "cls" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "res" |), "x" |), + M.get_name (| globals, "x" |) + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "res" |), "y" |), + M.get_name (| globals, "y" |) + |) in + let _ := M.return_ (| + M.get_name (| globals, "res" |) + |) in + M.pure Constant.None_)) + ); + ( + "__init__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "x"; "y" ] |) in + let _ := Constant.str " + Checks if the point is on the curve. To skip this check call + `__new__()` directly. + " in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + BoolOp.or (| + Compare.not_eq (| M.get_name (| globals, "x" |), M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "self" |), "FIELD" |), "zero" |), + make_list [], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_name (| globals, "y" |), M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "self" |), "FIELD" |), "zero" |), + make_list [], + make_dict [] + |) |) + )) + |), + ltac:(M.monadic ( + Compare.not_eq (| BinOp.sub (| + BinOp.sub (| + BinOp.sub (| + BinOp.pow (| + M.get_name (| globals, "y" |), + Constant.int 2 + |), + BinOp.pow (| + M.get_name (| globals, "x" |), + Constant.int 3 + |) + |), + BinOp.mult (| + M.get_field (| M.get_name (| globals, "self" |), "A" |), + M.get_name (| globals, "x" |) + |) + |), + M.get_field (| M.get_name (| globals, "self" |), "B" |) + |), M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "self" |), "FIELD" |), "zero" |), + make_list [], + make_dict [] + |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "ValueError" |), + make_list [ + Constant.str "Point not on curve" + ], + make_dict [] + |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)) + ); + ( + "__eq__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "other" ] |) in + let _ := Constant.str " + Test two points for equality. + " in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "other" |); + M.call (| + M.get_name (| globals, "type" |), + make_list [ + M.get_name (| globals, "self" |) + ], + make_dict [] + |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "self" |), "x" |), M.get_field (| M.get_name (| globals, "other" |), "x" |) |), + ltac:(M.monadic ( + Compare.eq (| M.get_field (| M.get_name (| globals, "self" |), "y" |), M.get_field (| M.get_name (| globals, "other" |), "y" |) |) + )) + |) + |) in + M.pure Constant.None_)) + ); + ( + "__str__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self" ] |) in + let _ := Constant.str " + Stringify a point as its coordinates. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "str" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "self" |), "x" |); M.get_field (| M.get_name (| globals, "self" |), "y" |) ] + ], + make_dict [] + |) + |) in + M.pure Constant.None_)) + ); + ( + "double", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self" ] |) in + let _ := Constant.str " + Add a point to itself. + " in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "x" |); M.get_name (| globals, "y" |); M.get_name (| globals, "F" |) ], + make_tuple [ M.get_field (| M.get_name (| globals, "self" |), "x" |); M.get_field (| M.get_name (| globals, "self" |), "y" |); M.get_field (| M.get_name (| globals, "self" |), "FIELD" |) ] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_name (| globals, "x" |), Constant.int 0 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "self" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let lam := + BinOp.div (| + BinOp.add (| + BinOp.mult (| + M.call (| + M.get_field (| M.get_name (| globals, "F" |), "from_int" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |), + BinOp.pow (| + M.get_name (| globals, "x" |), + Constant.int 2 + |) + |), + M.get_field (| M.get_name (| globals, "self" |), "A" |) + |), + BinOp.mult (| + M.call (| + M.get_field (| M.get_name (| globals, "F" |), "from_int" |), + make_list [ + Constant.int 2 + ], + make_dict [] + |), + M.get_name (| globals, "y" |) + |) + |) in + let new_x := + BinOp.sub (| + BinOp.sub (| + BinOp.pow (| + M.get_name (| globals, "lam" |), + Constant.int 2 + |), + M.get_name (| globals, "x" |) + |), + M.get_name (| globals, "x" |) + |) in + let new_y := + BinOp.sub (| + BinOp.mult (| + M.get_name (| globals, "lam" |), + BinOp.sub (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "new_x" |) + |) + |), + M.get_name (| globals, "y" |) + |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "__new__" |), + make_list [ + M.call (| + M.get_name (| globals, "type" |), + make_list [ + M.get_name (| globals, "self" |) + ], + make_dict [] + |); + M.get_name (| globals, "new_x" |); + M.get_name (| globals, "new_y" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)) + ); + ( + "__add__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "other" ] |) in + let _ := Constant.str " + Add two points together. + " in + let ZERO := + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "self" |), "FIELD" |), "zero" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "self_x" |); M.get_name (| globals, "self_y" |); M.get_name (| globals, "other_x" |); M.get_name (| globals, "other_y" |) ], + make_tuple [ M.get_field (| M.get_name (| globals, "self" |), "x" |); M.get_field (| M.get_name (| globals, "self" |), "y" |); M.get_field (| M.get_name (| globals, "other" |), "x" |); M.get_field (| M.get_name (| globals, "other" |), "y" |) ] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_name (| globals, "self_x" |), M.get_name (| globals, "ZERO" |) |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "self_y" |), M.get_name (| globals, "ZERO" |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "other" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_name (| globals, "other_x" |), M.get_name (| globals, "ZERO" |) |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "other_y" |), M.get_name (| globals, "ZERO" |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "self" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "self_x" |), M.get_name (| globals, "other_x" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "self_y" |), M.get_name (| globals, "other_y" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "double" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let lam := + BinOp.div (| + BinOp.sub (| + M.get_name (| globals, "other_y" |), + M.get_name (| globals, "self_y" |) + |), + BinOp.sub (| + M.get_name (| globals, "other_x" |), + M.get_name (| globals, "self_x" |) + |) + |) in + let x := + BinOp.sub (| + BinOp.sub (| + BinOp.pow (| + M.get_name (| globals, "lam" |), + Constant.int 2 + |), + M.get_name (| globals, "self_x" |) + |), + M.get_name (| globals, "other_x" |) + |) in + let y := + BinOp.sub (| + BinOp.mult (| + M.get_name (| globals, "lam" |), + BinOp.sub (| + M.get_name (| globals, "self_x" |), + M.get_name (| globals, "x" |) + |) + |), + M.get_name (| globals, "self_y" |) + |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "__new__" |), + make_list [ + M.call (| + M.get_name (| globals, "type" |), + make_list [ + M.get_name (| globals, "self" |) + ], + make_dict [] + |); + M.get_name (| globals, "x" |); + M.get_name (| globals, "y" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)) + ); + ( + "mul_by", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "n" ] |) in + let _ := Constant.str " + Multiply `self` by `n` using the double and add algorithm. + " in + let res := + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "__new__" |), + make_list [ + M.call (| + M.get_name (| globals, "type" |), + make_list [ + M.get_name (| globals, "self" |) + ], + make_dict [] + |); + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "self" |), "FIELD" |), "zero" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "self" |), "FIELD" |), "zero" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) in + let s := + M.get_name (| globals, "self" |) in + While Compare.not_eq (| M.get_name (| globals, "n" |), Constant.int 0 |) do + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| BinOp.mod_ (| + M.get_name (| globals, "n" |), + Constant.int 2 + |), Constant.int 1 |), + (* then *) + ltac:(M.monadic ( + let res := + BinOp.add (| + M.get_name (| globals, "res" |), + M.get_name (| globals, "s" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let s := + BinOp.add (| + M.get_name (| globals, "s" |), + M.get_name (| globals, "s" |) + |) in + let n := BinOp.floor_div + Constant.int 2 + Constant.int 2 in + EndWhile. + let _ := M.return_ (| + M.get_name (| globals, "res" |) + |) in + M.pure Constant.None_)) + ) + ]. diff --git a/CoqOfPython/ethereum/crypto/finite_field.v b/CoqOfPython/ethereum/crypto/finite_field.v new file mode 100644 index 0000000..87dac3a --- /dev/null +++ b/CoqOfPython/ethereum/crypto/finite_field.v @@ -0,0 +1,1929 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Finite Fields +^^^^^^^^^^^^^ +". + +Require typing. +Axiom typing_Iterable : + IsGlobalAlias globals typing.globals "Iterable". +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Type_ : + IsGlobalAlias globals typing.globals "Type_". +Axiom typing_TypeVar : + IsGlobalAlias globals typing.globals "TypeVar". +Axiom typing_cast : + IsGlobalAlias globals typing.globals "cast". + +Require typing_extensions. +Axiom typing_extensions_Protocol : + IsGlobalAlias globals typing_extensions.globals "Protocol". + +Require base_types. +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes32 : + IsGlobalAlias globals base_types.globals "Bytes32". + +Definition F : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "TypeVar" |), + make_list [ + Constant.str "F" + ], + make_dict [] + |) +)). + +Definition Field : Value.t := + builtins.make_klass + [(globals, "Protocol")] + [ + ( + "zero", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "cls" ] |) in + let _ := (* At constant: unsupported node type: Constant *) in + M.pure Constant.None_)) + ); + ( + "from_int", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "cls"; "n" ] |) in + let _ := (* At constant: unsupported node type: Constant *) in + M.pure Constant.None_)) + ) + ] + [ + ( + "__radd__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "left" ] |) in + let _ := (* At constant: unsupported node type: Constant *) in + M.pure Constant.None_)) + ); + ( + "__add__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in + let _ := (* At constant: unsupported node type: Constant *) in + M.pure Constant.None_)) + ); + ( + "__iadd__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in + let _ := (* At constant: unsupported node type: Constant *) in + M.pure Constant.None_)) + ); + ( + "__sub__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in + let _ := (* At constant: unsupported node type: Constant *) in + M.pure Constant.None_)) + ); + ( + "__rsub__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "left" ] |) in + let _ := (* At constant: unsupported node type: Constant *) in + M.pure Constant.None_)) + ); + ( + "__mul__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in + let _ := (* At constant: unsupported node type: Constant *) in + M.pure Constant.None_)) + ); + ( + "__rmul__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "left" ] |) in + let _ := (* At constant: unsupported node type: Constant *) in + M.pure Constant.None_)) + ); + ( + "__imul__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in + let _ := (* At constant: unsupported node type: Constant *) in + M.pure Constant.None_)) + ); + ( + "__pow__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "exponent" ] |) in + let _ := (* At constant: unsupported node type: Constant *) in + M.pure Constant.None_)) + ); + ( + "__ipow__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in + let _ := (* At constant: unsupported node type: Constant *) in + M.pure Constant.None_)) + ); + ( + "__neg__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self" ] |) in + let _ := (* At constant: unsupported node type: Constant *) in + M.pure Constant.None_)) + ); + ( + "__truediv__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in + let _ := (* At constant: unsupported node type: Constant *) in + M.pure Constant.None_)) + ) + ]. + +Definition T : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "TypeVar" |), + make_list [ + Constant.str "T" + ], + make_dict [] + |) +)). + +Definition PrimeField : Value.t := + builtins.make_klass + [(globals, "int"); (globals, "Field")] + [ + ( + "from_be_bytes", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "cls"; "buffer" ] |) in + let _ := Constant.str " + Converts a sequence of bytes into a element of the field. + Parameters + ---------- + buffer : + Bytes to decode. + Returns + ------- + self : `T` + Unsigned integer decoded from `buffer`. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "cls" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "int" |), "from_bytes" |), + make_list [ + M.get_name (| globals, "buffer" |); + Constant.str "big" + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)) + ); + ( + "zero", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "cls" ] |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "cls" |), "__new__" |), + make_list [ + M.get_name (| globals, "cls" |); + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_)) + ); + ( + "from_int", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "cls"; "n" ] |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "cls" |), + make_list [ + M.get_name (| globals, "n" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)) + ) + ] + [ + ( + "__new__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "cls"; "value" ] |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "int" |), "__new__" |), + make_list [ + M.get_name (| globals, "cls" |); + BinOp.mod_ (| + M.get_name (| globals, "value" |), + M.get_field (| M.get_name (| globals, "cls" |), "PRIME" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)) + ); + ( + "__radd__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "left" ] |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "__add__" |), + make_list [ + M.get_name (| globals, "left" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)) + ); + ( + "__add__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "right" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "__new__" |), + make_list [ + M.call (| + M.get_name (| globals, "type" |), + make_list [ + M.get_name (| globals, "self" |) + ], + make_dict [] + |); + M.call (| + M.get_field (| M.get_name (| globals, "int" |), "__add__" |), + make_list [ + M.get_name (| globals, "self" |); + M.get_name (| globals, "right" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)) + ); + ( + "__iadd__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "__add__" |), + make_list [ + M.get_name (| globals, "right" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)) + ); + ( + "__sub__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "right" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "__new__" |), + make_list [ + M.call (| + M.get_name (| globals, "type" |), + make_list [ + M.get_name (| globals, "self" |) + ], + make_dict [] + |); + M.call (| + M.get_field (| M.get_name (| globals, "int" |), "__sub__" |), + make_list [ + M.get_name (| globals, "self" |); + M.get_name (| globals, "right" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)) + ); + ( + "__rsub__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "left" ] |) in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "left" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "__new__" |), + make_list [ + M.call (| + M.get_name (| globals, "type" |), + make_list [ + M.get_name (| globals, "self" |) + ], + make_dict [] + |); + M.call (| + M.get_field (| M.get_name (| globals, "int" |), "__rsub__" |), + make_list [ + M.get_name (| globals, "self" |); + M.get_name (| globals, "left" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)) + ); + ( + "__mul__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "right" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "__new__" |), + make_list [ + M.call (| + M.get_name (| globals, "type" |), + make_list [ + M.get_name (| globals, "self" |) + ], + make_dict [] + |); + M.call (| + M.get_field (| M.get_name (| globals, "int" |), "__mul__" |), + make_list [ + M.get_name (| globals, "self" |); + M.get_name (| globals, "right" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)) + ); + ( + "__rmul__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "left" ] |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "__mul__" |), + make_list [ + M.get_name (| globals, "left" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)) + ); + ( + "__imul__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "__mul__" |), + make_list [ + M.get_name (| globals, "right" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)) + ); + ( + "__pow__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "exponent" ] |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "__new__" |), + make_list [ + M.call (| + M.get_name (| globals, "type" |), + make_list [ + M.get_name (| globals, "self" |) + ], + make_dict [] + |); + M.call (| + M.get_field (| M.get_name (| globals, "int" |), "__pow__" |), + make_list [ + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "self" |) + ], + make_dict [] + |); + M.get_name (| globals, "exponent" |); + M.get_field (| M.get_name (| globals, "self" |), "PRIME" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)) + ); + ( + "__ipow__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "__pow__" |), + make_list [ + M.get_name (| globals, "right" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)) + ); + ( + "__neg__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self" ] |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "__new__" |), + make_list [ + M.call (| + M.get_name (| globals, "type" |), + make_list [ + M.get_name (| globals, "self" |) + ], + make_dict [] + |); + M.call (| + M.get_field (| M.get_name (| globals, "int" |), "__neg__" |), + make_list [ + M.get_name (| globals, "self" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)) + ); + ( + "__truediv__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in + let _ := M.return_ (| + BinOp.mult (| + M.get_name (| globals, "self" |), + M.call (| + M.get_field (| M.get_name (| globals, "right" |), "multiplicative_inverse" |), + make_list [], + make_dict [] + |) + |) + |) in + M.pure Constant.None_)) + ); + ( + "multiplicative_inverse", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self" ] |) in + let _ := M.return_ (| + BinOp.pow (| + M.get_name (| globals, "self" |), + UnOp.sub (| Constant.int 1 |) + |) + |) in + M.pure Constant.None_)) + ); + ( + "to_be_bytes32", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self" ] |) in + let _ := Constant.str " + Converts this arbitrarily sized unsigned integer into its big endian + representation with exactly 32 bytes. + Returns + ------- + big_endian : `Bytes32` + Big endian (most significant bits first) representation. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bytes32" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "to_bytes" |), + make_list [ + Constant.int 32; + Constant.str "big" + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)) + ) + ]. + +Definition U : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "TypeVar" |), + make_list [ + Constant.str "U" + ], + make_dict [] + |) +)). + +Definition GaloisField : Value.t := + builtins.make_klass + [(globals, "tuple"); (globals, "Field")] + [ + ( + "zero", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "cls" ] |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "cls" |), "__new__" |), + make_list [ + M.get_name (| globals, "cls" |); + BinOp.mult (| + make_list [ + Constant.int 0 + ], + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "cls" |), "MODULUS" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)) + ); + ( + "from_int", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "cls"; "n" ] |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "cls" |), "__new__" |), + make_list [ + M.get_name (| globals, "cls" |); + BinOp.add (| + make_list [ + M.get_name (| globals, "n" |) + ], + BinOp.mult (| + make_list [ + Constant.int 0 + ], + BinOp.sub (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "cls" |), "MODULUS" |) + ], + make_dict [] + |), + Constant.int 1 + |) + |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)) + ); + ( + "calculate_frobenius_coefficients", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "cls" ] |) in + let _ := Constant.str " + Calculate the coefficients needed by `frobenius()`. + " in + let coefficients := + make_list [] in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "cls" |), "MODULUS" |) + ], + make_dict [] + |) + ], + make_dict [] + |) do + let x := + BinOp.mult (| + make_list [ + Constant.int 0 + ], + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "cls" |), "MODULUS" |) + ], + make_dict [] + |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |), + Constant.int 1 + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "coefficients" |), "append" |), + make_list [ + BinOp.pow (| + M.call (| + M.get_field (| M.get_name (| globals, "cls" |), "__new__" |), + make_list [ + M.get_name (| globals, "cls" |); + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + M.get_field (| M.get_name (| globals, "cls" |), "PRIME" |) + |) + ], + make_dict [] + |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "tuple" |), + make_list [ + M.get_name (| globals, "coefficients" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)) + ) + ] + [ + ( + "__new__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "cls"; "iterable" ] |) in + let self := + M.call (| + M.get_field (| M.get_name (| globals, "tuple" |), "__new__" |), + make_list [ + M.get_name (| globals, "cls" |); + (BinOp.mod_ (| + M.get_name (| globals, "x" |), + M.get_field (| M.get_name (| globals, "cls" |), "PRIME" |) + |) for (* At expr: unsupported node type: list *)) + ], + make_dict [] + |) in + let _ := M.assert (| Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "self" |) + ], + make_dict [] + |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "cls" |), "MODULUS" |) + ], + make_dict [] + |) |) |) in + let _ := M.return_ (| + M.get_name (| globals, "self" |) + |) in + M.pure Constant.None_)) + ); + ( + "__add__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "right" |); + M.call (| + M.get_name (| globals, "type" |), + make_list [ + M.get_name (| globals, "self" |) + ], + make_dict [] + |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "__new__" |), + make_list [ + M.call (| + M.get_name (| globals, "type" |), + make_list [ + M.get_name (| globals, "self" |) + ], + make_dict [] + |); + (BinOp.add (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) for (* At expr: unsupported node type: list *)) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)) + ); + ( + "__radd__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "left" ] |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "__add__" |), + make_list [ + M.get_name (| globals, "left" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)) + ); + ( + "__iadd__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "__add__" |), + make_list [ + M.get_name (| globals, "right" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)) + ); + ( + "__sub__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "right" |); + M.call (| + M.get_name (| globals, "type" |), + make_list [ + M.get_name (| globals, "self" |) + ], + make_dict [] + |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in +(* At stmt: unsupported node type: AnnAssign *) +(* At stmt: unsupported node type: AnnAssign *) + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "__new__" |), + make_list [ + M.call (| + M.get_name (| globals, "type" |), + make_list [ + M.get_name (| globals, "self" |) + ], + make_dict [] + |); + (BinOp.sub (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) for (* At expr: unsupported node type: list *)) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)) + ); + ( + "__rsub__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "left" ] |) in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "left" |); + M.call (| + M.get_name (| globals, "type" |), + make_list [ + M.get_name (| globals, "self" |) + ], + make_dict [] + |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "__new__" |), + make_list [ + M.call (| + M.get_name (| globals, "type" |), + make_list [ + M.get_name (| globals, "self" |) + ], + make_dict [] + |); + (BinOp.sub (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) for (* At expr: unsupported node type: list *)) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)) + ); + ( + "__mul__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in + let modulus := + M.get_field (| M.get_name (| globals, "self" |), "MODULUS" |) in + let degree := + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "modulus" |) + ], + make_dict [] + |) in + let prime := + M.get_field (| M.get_name (| globals, "self" |), "PRIME" |) in + let mul := + BinOp.mult (| + make_list [ + Constant.int 0 + ], + BinOp.mult (| + M.get_name (| globals, "degree" |), + Constant.int 2 + |) + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "degree" |) + ], + make_dict [] + |) do + For M.get_name (| globals, "j" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "degree" |) + ], + make_dict [] + |) do + let _ := M.assign_op (| + BinOp.add, + M.get_subscript (| M.get_name (| globals, "mul" |), BinOp.add (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "j" |) + |) |), + BinOp.mult (| + M.get_subscript (| M.get_name (| globals, "self" |), M.get_name (| globals, "i" |) |), + M.get_subscript (| M.get_name (| globals, "right" |), M.get_name (| globals, "j" |) |) + |) + |) in + EndFor. + EndFor. + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + BinOp.sub (| + BinOp.mult (| + M.get_name (| globals, "degree" |), + Constant.int 2 + |), + Constant.int 1 + |); + BinOp.sub (| + M.get_name (| globals, "degree" |), + Constant.int 1 + |); + UnOp.sub (| Constant.int 1 |) + ], + make_dict [] + |) do + For M.get_name (| globals, "j" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "degree" |) + |); + M.get_name (| globals, "i" |) + ], + make_dict [] + |) do + let _ := M.assign_op (| + BinOp.sub, + M.get_subscript (| M.get_name (| globals, "mul" |), M.get_name (| globals, "j" |) |), + BinOp.mod_ (| + BinOp.mult (| + M.get_subscript (| M.get_name (| globals, "mul" |), M.get_name (| globals, "i" |) |), + M.get_subscript (| M.get_name (| globals, "modulus" |), BinOp.sub (| + M.get_name (| globals, "degree" |), + BinOp.sub (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "j" |) + |) + |) |) + |), + M.get_name (| globals, "prime" |) + |) + |) in + EndFor. + EndFor. + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "__new__" |), + make_list [ + M.call (| + M.get_name (| globals, "type" |), + make_list [ + M.get_name (| globals, "self" |) + ], + make_dict [] + |); + M.get_subscript (| M.get_name (| globals, "mul" |), (* At expr: unsupported node type: NoneType *):M.get_name (| globals, "degree" |) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)) + ); + ( + "__rmul__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "left" ] |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "__mul__" |), + make_list [ + M.get_name (| globals, "left" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)) + ); + ( + "__imul__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "__mul__" |), + make_list [ + M.get_name (| globals, "right" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)) + ); + ( + "__truediv__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in + let _ := M.return_ (| + BinOp.mult (| + M.get_name (| globals, "self" |), + M.call (| + M.get_field (| M.get_name (| globals, "right" |), "multiplicative_inverse" |), + make_list [], + make_dict [] + |) + |) + |) in + M.pure Constant.None_)) + ); + ( + "__neg__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self" ] |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "__new__" |), + make_list [ + M.call (| + M.get_name (| globals, "type" |), + make_list [ + M.get_name (| globals, "self" |) + ], + make_dict [] + |); + (UnOp.sub (| M.get_name (| globals, "a" |) |) for (* At expr: unsupported node type: list *)) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)) + ); + ( + "scalar_mul", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "x" ] |) in + let _ := Constant.str " + Multiply a field element by a integer. This is faster than using + `from_int()` and field multiplication. + " in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "__new__" |), + make_list [ + M.call (| + M.get_name (| globals, "type" |), + make_list [ + M.get_name (| globals, "self" |) + ], + make_dict [] + |); + (BinOp.mult (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "n" |) + |) for (* At expr: unsupported node type: list *)) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)) + ); + ( + "deg", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self" ] |) in + let _ := Constant.str " + This is a support function for `multiplicative_inverse()`. + " in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + BinOp.sub (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "self" |), "MODULUS" |) + ], + make_dict [] + |), + Constant.int 1 + |); + UnOp.sub (| Constant.int 1 |); + UnOp.sub (| Constant.int 1 |) + ], + make_dict [] + |) do + let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| M.get_subscript (| M.get_name (| globals, "self" |), M.get_name (| globals, "i" |) |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.raise (| M.call (| + M.get_name (| globals, "ValueError" |), + make_list [ + Constant.str "deg() does not support zero" + ], + make_dict [] + |) |) in + M.pure Constant.None_)) + ); + ( + "multiplicative_inverse", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self" ] |) in + let _ := Constant.str " + Calculate the multiplicative inverse. Uses the Euclidean algorithm. + " in +(* At stmt: unsupported node type: AnnAssign *) + let p := + M.get_field (| M.get_name (| globals, "self" |), "PRIME" |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "x1" |); M.get_name (| globals, "f1" |) ], + make_tuple [ M.call (| + M.get_name (| globals, "list" |), + make_list [ + M.get_field (| M.get_name (| globals, "self" |), "MODULUS" |) + ], + make_dict [] + |); BinOp.mult (| + make_list [ + Constant.int 0 + ], + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "self" |) + ], + make_dict [] + |) + |) ] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "x2" |); M.get_name (| globals, "f2" |); M.get_name (| globals, "d2" |) ], + make_tuple [ M.call (| + M.get_name (| globals, "list" |), + make_list [ + M.get_name (| globals, "self" |) + ], + make_dict [] + |); BinOp.add (| + make_list [ + Constant.int 1 + ], + BinOp.mult (| + make_list [ + Constant.int 0 + ], + BinOp.sub (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "self" |) + ], + make_dict [] + |), + Constant.int 1 + |) + |) + |); M.call (| + M.get_field (| M.get_name (| globals, "self" |), "deg" |), + make_list [], + make_dict [] + |) ] + |) in + let q_0 := + M.call (| + M.get_name (| globals, "pow" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "x2" |), M.get_name (| globals, "d2" |) |); + UnOp.sub (| Constant.int 1 |); + M.get_name (| globals, "p" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "d2" |) + ], + make_dict [] + |) do + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "x1" |), BinOp.sub (| + BinOp.add (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x1" |) + ], + make_dict [] + |) + |), + M.get_name (| globals, "d2" |) + |) |), + BinOp.mod_ (| + BinOp.sub (| + M.get_subscript (| M.get_name (| globals, "x1" |), BinOp.sub (| + BinOp.add (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x1" |) + ], + make_dict [] + |) + |), + M.get_name (| globals, "d2" |) + |) |), + BinOp.mult (| + M.get_name (| globals, "q_0" |), + M.get_subscript (| M.get_name (| globals, "x2" |), M.get_name (| globals, "i" |) |) + |) + |), + M.get_name (| globals, "p" |) + |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "f1" |), BinOp.sub (| + BinOp.add (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x1" |) + ], + make_dict [] + |) + |), + M.get_name (| globals, "d2" |) + |) |), + BinOp.mod_ (| + BinOp.sub (| + M.get_subscript (| M.get_name (| globals, "f1" |), BinOp.sub (| + BinOp.add (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x1" |) + ], + make_dict [] + |) + |), + M.get_name (| globals, "d2" |) + |) |), + BinOp.mult (| + M.get_name (| globals, "q_0" |), + M.get_subscript (| M.get_name (| globals, "f2" |), M.get_name (| globals, "i" |) |) + |) + |), + M.get_name (| globals, "p" |) + |) + |) in + EndFor. + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + BinOp.sub (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "self" |), "MODULUS" |) + ], + make_dict [] + |), + Constant.int 1 + |); + UnOp.sub (| Constant.int 1 |); + UnOp.sub (| Constant.int 1 |) + ], + make_dict [] + |) do + let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| M.get_subscript (| M.get_name (| globals, "x1" |), M.get_name (| globals, "i" |) |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let d1 := + M.get_name (| globals, "i" |) in + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + While Constant.bool true do + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "d1" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let ans := + M.get_name (| globals, "f1" |) in + let q := + M.call (| + M.get_name (| globals, "pow" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "x1" |), Constant.int 0 |); + UnOp.sub (| Constant.int 1 |); + M.get_field (| M.get_name (| globals, "self" |), "PRIME" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ans" |) + ], + make_dict [] + |) + ], + make_dict [] + |) do + let _ := M.assign_op (| + BinOp.mult, + M.get_subscript (| M.get_name (| globals, "ans" |), M.get_name (| globals, "i" |) |), + M.get_name (| globals, "q" |) + |) in + EndFor. + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "d2" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let ans := + M.get_name (| globals, "f2" |) in + let q := + M.call (| + M.get_name (| globals, "pow" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "x2" |), Constant.int 0 |); + UnOp.sub (| Constant.int 1 |); + M.get_field (| M.get_name (| globals, "self" |), "PRIME" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ans" |) + ], + make_dict [] + |) + ], + make_dict [] + |) do + let ans := BinOp.mult + M.get_name (| globals, "q" |) + M.get_name (| globals, "q" |) in + EndFor. + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "d1" |), M.get_name (| globals, "d2" |) |), + (* then *) + ltac:(M.monadic ( + let q := + BinOp.mult (| + M.get_subscript (| M.get_name (| globals, "x2" |), M.get_name (| globals, "d2" |) |), + M.call (| + M.get_name (| globals, "pow" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "x1" |), M.get_name (| globals, "d1" |) |); + UnOp.sub (| Constant.int 1 |); + M.get_field (| M.get_name (| globals, "self" |), "PRIME" |) + ], + make_dict [] + |) + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + BinOp.sub (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "self" |), "MODULUS" |) + ], + make_dict [] + |), + BinOp.sub (| + M.get_name (| globals, "d2" |), + M.get_name (| globals, "d1" |) + |) + |) + ], + make_dict [] + |) do + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "x2" |), BinOp.add (| + M.get_name (| globals, "i" |), + BinOp.sub (| + M.get_name (| globals, "d2" |), + M.get_name (| globals, "d1" |) + |) + |) |), + BinOp.mod_ (| + BinOp.sub (| + M.get_subscript (| M.get_name (| globals, "x2" |), BinOp.add (| + M.get_name (| globals, "i" |), + BinOp.sub (| + M.get_name (| globals, "d2" |), + M.get_name (| globals, "d1" |) + |) + |) |), + BinOp.mult (| + M.get_name (| globals, "q" |), + M.get_subscript (| M.get_name (| globals, "x1" |), M.get_name (| globals, "i" |) |) + |) + |), + M.get_name (| globals, "p" |) + |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "f2" |), BinOp.add (| + M.get_name (| globals, "i" |), + BinOp.sub (| + M.get_name (| globals, "d2" |), + M.get_name (| globals, "d1" |) + |) + |) |), + BinOp.mod_ (| + BinOp.sub (| + M.get_subscript (| M.get_name (| globals, "f2" |), BinOp.add (| + M.get_name (| globals, "i" |), + BinOp.sub (| + M.get_name (| globals, "d2" |), + M.get_name (| globals, "d1" |) + |) + |) |), + BinOp.mult (| + M.get_name (| globals, "q" |), + M.get_subscript (| M.get_name (| globals, "f1" |), M.get_name (| globals, "i" |) |) + |) + |), + M.get_name (| globals, "p" |) + |) + |) in + EndFor. + While Compare.eq (| M.get_subscript (| M.get_name (| globals, "x2" |), M.get_name (| globals, "d2" |) |), Constant.int 0 |) do + let d2 := BinOp.sub + Constant.int 1 + Constant.int 1 in + EndWhile. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let q := + BinOp.mult (| + M.get_subscript (| M.get_name (| globals, "x1" |), M.get_name (| globals, "d1" |) |), + M.call (| + M.get_name (| globals, "pow" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "x2" |), M.get_name (| globals, "d2" |) |); + UnOp.sub (| Constant.int 1 |); + M.get_field (| M.get_name (| globals, "self" |), "PRIME" |) + ], + make_dict [] + |) + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + BinOp.sub (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "self" |), "MODULUS" |) + ], + make_dict [] + |), + BinOp.sub (| + M.get_name (| globals, "d1" |), + M.get_name (| globals, "d2" |) + |) + |) + ], + make_dict [] + |) do + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "x1" |), BinOp.add (| + M.get_name (| globals, "i" |), + BinOp.sub (| + M.get_name (| globals, "d1" |), + M.get_name (| globals, "d2" |) + |) + |) |), + BinOp.mod_ (| + BinOp.sub (| + M.get_subscript (| M.get_name (| globals, "x1" |), BinOp.add (| + M.get_name (| globals, "i" |), + BinOp.sub (| + M.get_name (| globals, "d1" |), + M.get_name (| globals, "d2" |) + |) + |) |), + BinOp.mult (| + M.get_name (| globals, "q" |), + M.get_subscript (| M.get_name (| globals, "x2" |), M.get_name (| globals, "i" |) |) + |) + |), + M.get_name (| globals, "p" |) + |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "f1" |), BinOp.add (| + M.get_name (| globals, "i" |), + BinOp.sub (| + M.get_name (| globals, "d1" |), + M.get_name (| globals, "d2" |) + |) + |) |), + BinOp.mod_ (| + BinOp.sub (| + M.get_subscript (| M.get_name (| globals, "f1" |), BinOp.add (| + M.get_name (| globals, "i" |), + BinOp.sub (| + M.get_name (| globals, "d1" |), + M.get_name (| globals, "d2" |) + |) + |) |), + BinOp.mult (| + M.get_name (| globals, "q" |), + M.get_subscript (| M.get_name (| globals, "f2" |), M.get_name (| globals, "i" |) |) + |) + |), + M.get_name (| globals, "p" |) + |) + |) in + EndFor. + While Compare.eq (| M.get_subscript (| M.get_name (| globals, "x1" |), M.get_name (| globals, "d1" |) |), Constant.int 0 |) do + let d1 := BinOp.sub + Constant.int 1 + Constant.int 1 in + EndWhile. + M.pure Constant.None_ + )) |) in + EndWhile. + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "__new__" |), + make_list [ + M.call (| + M.get_name (| globals, "type" |), + make_list [ + M.get_name (| globals, "self" |) + ], + make_dict [] + |); + M.get_name (| globals, "ans" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)) + ); + ( + "__pow__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "exponent" ] |) in + let degree := + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "self" |), "MODULUS" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "exponent" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let self := + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "multiplicative_inverse" |), + make_list [], + make_dict [] + |) in + let exponent := + UnOp.sub (| M.get_name (| globals, "exponent" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let res := + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "__new__" |), + make_list [ + M.call (| + M.get_name (| globals, "type" |), + make_list [ + M.get_name (| globals, "self" |) + ], + make_dict [] + |); + BinOp.add (| + make_list [ + Constant.int 1 + ], + BinOp.mult (| + make_list [ + Constant.int 0 + ], + BinOp.sub (| + M.get_name (| globals, "degree" |), + Constant.int 1 + |) + |) + |) + ], + make_dict [] + |) in + let s := + M.get_name (| globals, "self" |) in + While Compare.not_eq (| M.get_name (| globals, "exponent" |), Constant.int 0 |) do + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| BinOp.mod_ (| + M.get_name (| globals, "exponent" |), + Constant.int 2 + |), Constant.int 1 |), + (* then *) + ltac:(M.monadic ( + let res := BinOp.mult + M.get_name (| globals, "s" |) + M.get_name (| globals, "s" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let s := BinOp.mult + M.get_name (| globals, "s" |) + M.get_name (| globals, "s" |) in + let exponent := BinOp.floor_div + Constant.int 2 + Constant.int 2 in + EndWhile. + let _ := M.return_ (| + M.get_name (| globals, "res" |) + |) in + M.pure Constant.None_)) + ); + ( + "__ipow__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "__pow__" |), + make_list [ + M.get_name (| globals, "right" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)) + ); + ( + "frobenius", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self" ] |) in + let _ := Constant.str " + Returns `self ** p`. This function is known as the Frobenius + endomorphism and has many special mathematical properties. In + particular it is extremely cheap to compute compared to other + exponentiations. + " in + let ans := + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "from_int" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in +(* At stmt: unsupported node type: AnnAssign *) + For make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "a" |) ] in M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "self" |) + ], + make_dict [] + |) do + let ans := BinOp.add + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "cast" |), + make_list [ + M.get_name (| globals, "U" |); + M.get_subscript (| M.get_field (| M.get_name (| globals, "self" |), "FROBENIUS_COEFFICIENTS" |), M.get_name (| globals, "i" |) |) + ], + make_dict [] + |), "scalar_mul" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "cast" |), + make_list [ + M.get_name (| globals, "U" |); + M.get_subscript (| M.get_field (| M.get_name (| globals, "self" |), "FROBENIUS_COEFFICIENTS" |), M.get_name (| globals, "i" |) |) + ], + make_dict [] + |), "scalar_mul" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) in + EndFor. + let _ := M.return_ (| + M.get_name (| globals, "ans" |) + |) in + M.pure Constant.None_)) + ) + ]. diff --git a/CoqOfPython/ethereum/crypto/hash.v b/CoqOfPython/ethereum/crypto/hash.v new file mode 100644 index 0000000..b7e39d0 --- /dev/null +++ b/CoqOfPython/ethereum/crypto/hash.v @@ -0,0 +1,124 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Cryptographic Hash Functions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Cryptographic hashing functions. +". + +Require Crypto.Hash. +Axiom Crypto_Hash_keccak : + IsGlobalAlias globals Crypto.Hash.globals "keccak". + +Require base_types. +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes32 : + IsGlobalAlias globals base_types.globals "Bytes32". +Axiom base_types_Bytes64 : + IsGlobalAlias globals base_types.globals "Bytes64". + +Definition Hash32 : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Bytes32" |) +)). + +Definition Hash64 : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Bytes64" |) +)). + +Definition keccak256 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "buffer" ] |) in + let _ := Constant.str " + Computes the keccak256 hash of the input `buffer`. + + Parameters + ---------- + buffer : + Input for the hashing function. + + Returns + ------- + hash : `ethereum.base_types.Hash32` + Output of the hash function. + " in + let k := + M.call (| + M.get_field (| M.get_name (| globals, "keccak" |), "new" |), + make_list [], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Hash32" |), + make_list [ + M.call (| + M.get_field (| M.call (| + M.get_field (| M.get_name (| globals, "k" |), "update" |), + make_list [ + M.get_name (| globals, "buffer" |) + ], + make_dict [] + |), "digest" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition keccak512 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "buffer" ] |) in + let _ := Constant.str " + Computes the keccak512 hash of the input `buffer`. + + Parameters + ---------- + buffer : + Input for the hashing function. + + Returns + ------- + hash : `ethereum.base_types.Hash32` + Output of the hash function. + " in + let k := + M.call (| + M.get_field (| M.get_name (| globals, "keccak" |), "new" |), + make_list [], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Hash64" |), + make_list [ + M.call (| + M.get_field (| M.call (| + M.get_field (| M.get_name (| globals, "k" |), "update" |), + make_list [ + M.get_name (| globals, "buffer" |) + ], + make_dict [] + |), "digest" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/__init__.v b/CoqOfPython/ethereum/dao_fork/__init__.v new file mode 100644 index 0000000..99f8b78 --- /dev/null +++ b/CoqOfPython/ethereum/dao_fork/__init__.v @@ -0,0 +1,24 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +The DAO Fork is a response to a smart contract exploit known as the 2016 DAO +Attack where a vulnerable contract was drained of its ether. This fork recovers +the stolen funds into a new contract. +". + +Require ethereum.fork_criteria. +Axiom ethereum_fork_criteria_ByBlockNumber : + IsGlobalAlias globals ethereum.fork_criteria.globals "ByBlockNumber". + +Definition FORK_CRITERIA : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "ByBlockNumber" |), + make_list [ + Constant.int 1920000 + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/dao_fork/blocks.v b/CoqOfPython/ethereum/dao_fork/blocks.v new file mode 100644 index 0000000..6501788 --- /dev/null +++ b/CoqOfPython/ethereum/dao_fork/blocks.v @@ -0,0 +1,93 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +A `Block` is a single link in the chain that is Ethereum. Each `Block` contains +a `Header` and zero or more transactions. Each `Header` contains associated +metadata like the block number, parent block hash, and how much gas was +consumed by its transactions. + +Together, these blocks form a cryptographically secure journal recording the +history of all state transitions that have happened since the genesis of the +chain. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes8 : + IsGlobalAlias globals base_types.globals "Bytes8". +Axiom base_types_Bytes32 : + IsGlobalAlias globals base_types.globals "Bytes32". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require crypto.hash. +Axiom crypto_hash_Hash32 : + IsGlobalAlias globals crypto.hash.globals "Hash32". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Require transactions. +Axiom transactions_Transaction : + IsGlobalAlias globals transactions.globals "Transaction". + +Definition Header : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Block : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Log : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Receipt : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. diff --git a/CoqOfPython/ethereum/dao_fork/bloom.v b/CoqOfPython/ethereum/dao_fork/bloom.v new file mode 100644 index 0000000..04b5d9f --- /dev/null +++ b/CoqOfPython/ethereum/dao_fork/bloom.v @@ -0,0 +1,164 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Logs Bloom +^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +This modules defines functions for calculating bloom filters of logs. For the +general theory of bloom filters see e.g. `Wikipedia +`_. Bloom filters are used to allow +for efficient searching of logs by address and/or topic, by rapidly +eliminating blocks and receipts from their search. +". + +Require typing. +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require fork_types. +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". + +Definition add_to_bloom : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "bloom"; "bloom_entry" ] |) in + let _ := Constant.str " + Add a bloom entry to the bloom filter (`bloom`). + + The number of hash functions used is 3. They are calculated by taking the + least significant 11 bits from the first 3 16-bit words of the + `keccak_256()` hash of `bloom_entry`. + + Parameters + ---------- + bloom : + The bloom filter. + bloom_entry : + An entry which is to be added to bloom filter. + " in + let hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "bloom_entry" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "idx" |) in make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ] do + let bit_to_set := + BinOp.bit_and (| + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |):BinOp.add (| + M.get_name (| globals, "idx" |), + Constant.int 2 + |) |) + ], + make_dict [] + |), + Constant.int 2047 + |) in + let bit_index := + BinOp.sub (| + Constant.int 2047, + M.get_name (| globals, "bit_to_set" |) + |) in + let byte_index := + BinOp.floor_div (| + M.get_name (| globals, "bit_index" |), + Constant.int 8 + |) in + let bit_value := + BinOp.l_shift (| + Constant.int 1, + BinOp.sub (| + Constant.int 7, + BinOp.mod_ (| + M.get_name (| globals, "bit_index" |), + Constant.int 8 + |) + |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), + BinOp.bit_or (| + M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), + M.get_name (| globals, "bit_value" |) + |) + |) in + EndFor. + M.pure Constant.None_)). + +Definition logs_bloom : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "logs" ] |) in + let _ := Constant.str " + Obtain the logs bloom from a list of log entries. + + The address and each topic of a log are added to the bloom filter. + + Parameters + ---------- + logs : + List of logs for which the logs bloom is to be obtained. + + Returns + ------- + logs_bloom : `Bloom` + The logs bloom obtained which is 256 bytes with some bits set as per + the caller address and the log topics. + " in +(* At stmt: unsupported node type: AnnAssign *) + For M.get_name (| globals, "log" |) in M.get_name (| globals, "logs" |) do + let _ := M.call (| + M.get_name (| globals, "add_to_bloom" |), + make_list [ + M.get_name (| globals, "bloom" |); + M.get_field (| M.get_name (| globals, "log" |), "address" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "topic" |) in M.get_field (| M.get_name (| globals, "log" |), "topics" |) do + let _ := M.call (| + M.get_name (| globals, "add_to_bloom" |), + make_list [ + M.get_name (| globals, "bloom" |); + M.get_name (| globals, "topic" |) + ], + make_dict [] + |) in + EndFor. + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bloom" |), + make_list [ + M.get_name (| globals, "bloom" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/dao.v b/CoqOfPython/ethereum/dao_fork/dao.v new file mode 100644 index 0000000..047dd0d --- /dev/null +++ b/CoqOfPython/ethereum/dao_fork/dao.v @@ -0,0 +1,87 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Dao Fork +^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The Dao Fork was an irregular state change that moved all Ether from a large +collection of accounts (The Dao and all its children) to a recovery contract. + +The recovery contract was previously created using normal contract deployment. +". + +Require state. +Axiom state_State : + IsGlobalAlias globals state.globals "State". +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". +Axiom state_move_ether : + IsGlobalAlias globals state.globals "move_ether". + +Require utils.hexadecimal. +Axiom utils_hexadecimal_hex_to_address : + IsGlobalAlias globals utils.hexadecimal.globals "hex_to_address". + +Definition DAO_ACCOUNTS : Value.t := M.run ltac:(M.monadic ( + [M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)] +)). + +Definition DAO_RECOVERY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0xbf4ed7b27f1d666546e30d74d50d173d20bca754" + ], + make_dict [] + |) +)). + +Definition apply_dao : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Apply the dao fork to the state. + + Parameters + ---------- + state : + State before applying the DAO Fork. + " in + For M.get_name (| globals, "address" |) in M.get_name (| globals, "DAO_ACCOUNTS" |) do + let balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "balance" |) in + let _ := M.call (| + M.get_name (| globals, "move_ether" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "DAO_RECOVERY" |); + M.get_name (| globals, "balance" |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/fork.v b/CoqOfPython/ethereum/dao_fork/fork.v new file mode 100644 index 0000000..b2ecaf9 --- /dev/null +++ b/CoqOfPython/ethereum/dao_fork/fork.v @@ -0,0 +1,2153 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +.. _dao-fork: + +Ethereum Specification +^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Entry point for the Ethereum specification. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". + +Require ethereum.crypto.elliptic_curve. +Axiom ethereum_crypto_elliptic_curve_SECP256K1N : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.ethash. +Axiom ethereum_ethash_dataset_size : + IsGlobalAlias globals ethereum.ethash.globals "dataset_size". +Axiom ethereum_ethash_generate_cache : + IsGlobalAlias globals ethereum.ethash.globals "generate_cache". +Axiom ethereum_ethash_hashimoto_light : + IsGlobalAlias globals ethereum.ethash.globals "hashimoto_light". + +Require ethereum.exceptions. +Axiom ethereum_exceptions_InvalidBlock : + IsGlobalAlias globals ethereum.exceptions.globals "InvalidBlock". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U64 : + IsGlobalAlias globals base_types.globals "U64". +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_U256_CEIL_VALUE : + IsGlobalAlias globals base_types.globals "U256_CEIL_VALUE". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes32 : + IsGlobalAlias globals base_types.globals "Bytes32". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". + +Require __init__. +Axiom __init___FORK_CRITERIA : + IsGlobalAlias globals __init__.globals "FORK_CRITERIA". +Axiom __init___vm : + IsGlobalAlias globals __init__.globals "vm". + +Require blocks. +Axiom blocks_Block : + IsGlobalAlias globals blocks.globals "Block". +Axiom blocks_Header : + IsGlobalAlias globals blocks.globals "Header". +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". +Axiom blocks_Receipt : + IsGlobalAlias globals blocks.globals "Receipt". + +Require bloom. +Axiom bloom_logs_bloom : + IsGlobalAlias globals bloom.globals "logs_bloom". + +Require dao. +Axiom dao_apply_dao : + IsGlobalAlias globals dao.globals "apply_dao". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Require state. +Axiom state_State : + IsGlobalAlias globals state.globals "State". +Axiom state_create_ether : + IsGlobalAlias globals state.globals "create_ether". +Axiom state_destroy_account : + IsGlobalAlias globals state.globals "destroy_account". +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". +Axiom state_increment_nonce : + IsGlobalAlias globals state.globals "increment_nonce". +Axiom state_set_account_balance : + IsGlobalAlias globals state.globals "set_account_balance". +Axiom state_state_root : + IsGlobalAlias globals state.globals "state_root". + +Require transactions. +Axiom transactions_TX_BASE_COST : + IsGlobalAlias globals transactions.globals "TX_BASE_COST". +Axiom transactions_TX_CREATE_COST : + IsGlobalAlias globals transactions.globals "TX_CREATE_COST". +Axiom transactions_TX_DATA_COST_PER_NON_ZERO : + IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_NON_ZERO". +Axiom transactions_TX_DATA_COST_PER_ZERO : + IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_ZERO". +Axiom transactions_Transaction : + IsGlobalAlias globals transactions.globals "Transaction". + +Require trie. +Axiom trie_Trie : + IsGlobalAlias globals trie.globals "Trie". +Axiom trie_root : + IsGlobalAlias globals trie.globals "root". +Axiom trie_trie_set : + IsGlobalAlias globals trie.globals "trie_set". + +Require utils.message. +Axiom utils_message_prepare_message : + IsGlobalAlias globals utils.message.globals "prepare_message". + +Require vm.interpreter. +Axiom vm_interpreter_process_message_call : + IsGlobalAlias globals vm.interpreter.globals "process_message_call". + +Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mult (| + Constant.int 5, + BinOp.pow (| + Constant.int 10, + Constant.int 18 + |) + |) + ], + make_dict [] + |) +)). + +Definition GAS_LIMIT_ADJUSTMENT_FACTOR : Value.t := M.run ltac:(M.monadic ( + Constant.int 1024 +)). + +Definition GAS_LIMIT_MINIMUM : Value.t := M.run ltac:(M.monadic ( + Constant.int 5000 +)). + +Definition MINIMUM_DIFFICULTY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 131072 + ], + make_dict [] + |) +)). + +Definition MAX_OMMER_DEPTH : Value.t := M.run ltac:(M.monadic ( + Constant.int 6 +)). + +Definition BlockChain : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition apply_fork : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "old" ] |) in + let _ := Constant.str " + Transforms the state from the previous hard fork (`old`) into the block + chain object for this hard fork and returns it. + + When forks need to implement an irregular state transition, this function + is used to handle the irregularity. + + The DAO-Fork occurred as a result of the `2016 DAO Hacks + `_ in which an + unknown entity managed to drain more than 3.6 million ether causing the + price of ether to drop by nearly 35%. This fork was the solution to the + hacks and manually reset the affected parties' accounts to their state + prior to the attack. This fork essentially rewrote the history of the + Ethereum network. + + Parameters + ---------- + old : + Previous block chain object. + + Returns + ------- + new : `BlockChain` + Upgraded block chain object for this hard fork. + " in + let _ := M.call (| + M.get_name (| globals, "apply_dao" |), + make_list [ + M.get_field (| M.get_name (| globals, "old" |), "state" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "old" |) + |) in + M.pure Constant.None_)). + +Definition get_last_256_block_hashes : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "chain" ] |) in + let _ := Constant.str " + Obtain the list of hashes of the previous 256 blocks in order of + increasing block number. + + This function will return less hashes for the first 256 blocks. + + The ``BLOCKHASH`` opcode needs to access the latest hashes on the chain, + therefore this function retrieves them. + + Parameters + ---------- + chain : + History and current state. + + Returns + ------- + recent_block_hashes : `List[Hash32]` + Hashes of the recent 256 blocks in order of increasing block number. + " in + let recent_blocks := + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |):(* At expr: unsupported node type: NoneType *) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "recent_blocks" |) + ], + make_dict [] + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + make_list [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let recent_block_hashes := + make_list [] in + For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_blocks" |) do + let prev_block_hash := + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), + make_list [ + M.get_name (| globals, "prev_block_hash" |) + ], + make_dict [] + |) in + EndFor. + let most_recent_block_hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_field (| M.get_subscript (| M.get_name (| globals, "recent_blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), + make_list [ + M.get_name (| globals, "most_recent_block_hash" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "recent_block_hashes" |) + |) in + M.pure Constant.None_)). + +Definition state_transition : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "chain"; "block" ] |) in + let _ := Constant.str " + Attempts to apply a block to an existing block chain. + + All parts of the block's contents need to be verified before being added + to the chain. Blocks are verified by ensuring that the contents of the + block make logical sense with the contents of the parent block. The + information in the block's header must also match the corresponding + information in the block. + + To implement Ethereum, in theory clients are only required to store the + most recent 255 blocks of the chain since as far as execution is + concerned, only those blocks are accessed. Practically, however, clients + should store more blocks to handle reorgs. + + Parameters + ---------- + chain : + History and current state. + block : + Block to apply to `chain`. + " in + let parent_header := + M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) in + let _ := M.call (| + M.get_name (| globals, "validate_header" |), + make_list [ + M.get_field (| M.get_name (| globals, "block" |), "header" |); + M.get_name (| globals, "parent_header" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "validate_ommers" |), + make_list [ + M.get_field (| M.get_name (| globals, "block" |), "ommers" |); + M.get_field (| M.get_name (| globals, "block" |), "header" |); + M.get_name (| globals, "chain" |) + ], + make_dict [] + |) in + let apply_body_output := + M.call (| + M.get_name (| globals, "apply_body" |), + make_list [ + M.get_field (| M.get_name (| globals, "chain" |), "state" |); + M.call (| + M.get_name (| globals, "get_last_256_block_hashes" |), + make_list [ + M.get_name (| globals, "chain" |) + ], + make_dict [] + |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "coinbase" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "number" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "gas_limit" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "timestamp" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "difficulty" |); + M.get_field (| M.get_name (| globals, "block" |), "transactions" |); + M.get_field (| M.get_name (| globals, "block" |), "ommers" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_gas_used" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "gas_used" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "transactions_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "transactions_root" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "state_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "state_root" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "receipt_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "receipt_root" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_logs_bloom" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "bloom" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), "append" |), + make_list [ + M.get_name (| globals, "block" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |) + ], + make_dict [] + |), Constant.int 255 |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |):(* At expr: unsupported node type: NoneType *) |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition validate_header : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header"; "parent_header" ] |) in + let _ := Constant.str " + Verifies a block header. + + In order to consider a block's header valid, the logic for the + quantities in the header should match the logic for the block itself. + For example the header timestamp should be greater than the block's parent + timestamp because the block was created *after* the parent block. + Additionally, the block's number should be directly following the parent + block's number since it is the next block in the sequence. + + Parameters + ---------- + header : + Header to check for correctness. + parent_header : + Parent Header of the header to check for correctness + " in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt (| M.get_field (| M.get_name (| globals, "header" |), "timestamp" |), M.get_field (| M.get_name (| globals, "parent_header" |), "timestamp" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "number" |), BinOp.add (| + M.get_field (| M.get_name (| globals, "parent_header" |), "number" |), + Constant.int 1 + |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + M.call (| + M.get_name (| globals, "check_gas_limit" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "gas_limit" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "gas_limit" |) + ], + make_dict [] + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) + ], + make_dict [] + |), Constant.int 32 |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let block_difficulty := + M.call (| + M.get_name (| globals, "calculate_block_difficulty" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "number" |); + M.get_field (| M.get_name (| globals, "header" |), "timestamp" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "timestamp" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "difficulty" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "difficulty" |), M.get_name (| globals, "block_difficulty" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let block_parent_hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "parent_header" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |), M.get_name (| globals, "block_parent_hash" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.gt_e (| M.get_field (| M.get_name (| globals, "header" |), "number" |), M.get_field (| M.get_name (| globals, "FORK_CRITERIA" |), "block_number" |) |), + ltac:(M.monadic ( + Compare.lt (| M.get_field (| M.get_name (| globals, "header" |), "number" |), BinOp.add (| + M.get_field (| M.get_name (| globals, "FORK_CRITERIA" |), "block_number" |), + Constant.int 10 + |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "extra_data" |), (* At constant: unsupported node type: Constant *) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "validate_proof_of_work" |), + make_list [ + M.get_name (| globals, "header" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header" ] |) in + let _ := Constant.str " + Generate rlp hash of the header which is to be used for Proof-of-Work + verification. + + In other words, the PoW artefacts `mix_digest` and `nonce` are ignored + while calculating this hash. + + A particular PoW is valid for a single hash, that hash is computed by + this function. The `nonce` and `mix_digest` are omitted from this hash + because they are being changed by miners in their search for a sufficient + proof-of-work. + + Parameters + ---------- + header : + The header object for which the hash is to be generated. + + Returns + ------- + hash : `Hash32` + The PoW valid rlp hash of the passed in header. + " in + let header_data_without_pow_artefacts := + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |); + M.get_field (| M.get_name (| globals, "header" |), "ommers_hash" |); + M.get_field (| M.get_name (| globals, "header" |), "coinbase" |); + M.get_field (| M.get_name (| globals, "header" |), "state_root" |); + M.get_field (| M.get_name (| globals, "header" |), "transactions_root" |); + M.get_field (| M.get_name (| globals, "header" |), "receipt_root" |); + M.get_field (| M.get_name (| globals, "header" |), "bloom" |); + M.get_field (| M.get_name (| globals, "header" |), "difficulty" |); + M.get_field (| M.get_name (| globals, "header" |), "number" |); + M.get_field (| M.get_name (| globals, "header" |), "gas_limit" |); + M.get_field (| M.get_name (| globals, "header" |), "gas_used" |); + M.get_field (| M.get_name (| globals, "header" |), "timestamp" |); + M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) + ] in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "header_data_without_pow_artefacts" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition validate_proof_of_work : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header" ] |) in + let _ := Constant.str " + Validates the Proof of Work constraints. + + In order to verify that a miner's proof-of-work is valid for a block, a + ``mix-digest`` and ``result`` are calculated using the ``hashimoto_light`` + hash function. The mix digest is a hash of the header and the nonce that + is passed through and it confirms whether or not proof-of-work was done + on the correct block. The result is the actual hash value of the block. + + Parameters + ---------- + header : + Header of interest. + " in + let header_hash := + M.call (| + M.get_name (| globals, "generate_header_hash_for_pow" |), + make_list [ + M.get_name (| globals, "header" |) + ], + make_dict [] + |) in + let cache := + M.call (| + M.get_name (| globals, "generate_cache" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "number" |) + ], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "mix_digest" |); M.get_name (| globals, "result" |) ], + M.call (| + M.get_name (| globals, "hashimoto_light" |), + make_list [ + M.get_name (| globals, "header_hash" |); + M.get_field (| M.get_name (| globals, "header" |), "nonce" |); + M.get_name (| globals, "cache" |); + M.call (| + M.get_name (| globals, "dataset_size" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "number" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_name (| globals, "mix_digest" |), M.get_field (| M.get_name (| globals, "header" |), "mix_digest" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "result" |) + ], + make_dict [] + |), BinOp.floor_div (| + M.get_name (| globals, "U256_CEIL_VALUE" |), + M.get_field (| M.get_name (| globals, "header" |), "difficulty" |) + |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition check_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx"; "gas_available" ] |) in + let _ := Constant.str " + Check if the transaction is includable in the block. + + Parameters + ---------- + tx : + The transaction. + gas_available : + The gas remaining in the block. + + Returns + ------- + sender_address : + The sender of the transaction. + + Raises + ------ + InvalidBlock : + If the transaction is not includable. + " in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_name (| globals, "gas_available" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let sender_address := + M.call (| + M.get_name (| globals, "recover_sender" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "sender_address" |) + |) in + M.pure Constant.None_)). + +Definition make_receipt : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx"; "post_state"; "cumulative_gas_used"; "logs" ] |) in + let _ := Constant.str " + Make the receipt for a transaction that was executed. + + Parameters + ---------- + tx : + The executed transaction. + post_state : + The state root immediately after this transaction. + cumulative_gas_used : + The total gas used so far in the block after the transaction was + executed. + logs : + The logs produced by the transaction. + + Returns + ------- + receipt : + The receipt for the transaction. + " in + let receipt := + M.call (| + M.get_name (| globals, "Receipt" |), + make_list [], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "receipt" |) + |) in + M.pure Constant.None_)). + +Definition ApplyBodyOutput : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition apply_body : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "block_hashes"; "coinbase"; "block_number"; "block_gas_limit"; "block_time"; "block_difficulty"; "transactions"; "ommers" ] |) in + let _ := Constant.str " + Executes a block. + + Many of the contents of a block are stored in data structures called + tries. There is a transactions trie which is similar to a ledger of the + transactions stored in the current block. There is also a receipts trie + which stores the results of executing a transaction, like the post state + and gas used. This function creates and executes the block that is to be + added to the chain. + + Parameters + ---------- + state : + Current account state. + block_hashes : + List of hashes of the previous 256 blocks in the order of + increasing block number. + coinbase : + Address of account which receives block reward and transaction fees. + block_number : + Position of the block within the chain. + block_gas_limit : + Initial amount of gas available for execution in this block. + block_time : + Time the block was produced, measured in seconds since the epoch. + block_difficulty : + Difficulty of the block. + transactions : + Transactions included in the block. + ommers : + Headers of ancestor blocks which are not direct parents (formerly + uncles.) + + Returns + ------- + apply_body_output : `ApplyBodyOutput` + Output of applying the block body to the state. + " in + let gas_available := + M.get_name (| globals, "block_gas_limit" |) in +(* At stmt: unsupported node type: AnnAssign *) +(* At stmt: unsupported node type: AnnAssign *) +(* At stmt: unsupported node type: AnnAssign *) + For make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "tx" |) ] in M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "transactions" |) + ], + make_dict [] + |) do + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "transactions_trie" |); + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "i" |) + ], + make_dict [] + |) + ], + make_dict [] + |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) in + let sender_address := + M.call (| + M.get_name (| globals, "check_transaction" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "gas_available" |) + ], + make_dict [] + |) in + let env := + M.call (| + M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |) ], + M.call (| + M.get_name (| globals, "process_transaction" |), + make_list [ + M.get_name (| globals, "env" |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) in + let gas_available := BinOp.sub + M.get_name (| globals, "gas_used" |) + M.get_name (| globals, "gas_used" |) in + let receipt := + M.call (| + M.get_name (| globals, "make_receipt" |), + make_list [ + M.get_name (| globals, "tx" |); + M.call (| + M.get_name (| globals, "state_root" |), + make_list [ + M.get_name (| globals, "state" |) + ], + make_dict [] + |); + BinOp.sub (| + M.get_name (| globals, "block_gas_limit" |), + M.get_name (| globals, "gas_available" |) + |); + M.get_name (| globals, "logs" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "receipts_trie" |); + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "i" |) + ], + make_dict [] + |) + ], + make_dict [] + |); + M.get_name (| globals, "receipt" |) + ], + make_dict [] + |) in + let block_logs := BinOp.add + M.get_name (| globals, "logs" |) + M.get_name (| globals, "logs" |) in + EndFor. + let _ := M.call (| + M.get_name (| globals, "pay_rewards" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "block_number" |); + M.get_name (| globals, "coinbase" |); + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |) in + let block_gas_used := + BinOp.sub (| + M.get_name (| globals, "block_gas_limit" |), + M.get_name (| globals, "gas_available" |) + |) in + let block_logs_bloom := + M.call (| + M.get_name (| globals, "logs_bloom" |), + make_list [ + M.get_name (| globals, "block_logs" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ApplyBodyOutput" |), + make_list [ + M.get_name (| globals, "block_gas_used" |); + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_name (| globals, "transactions_trie" |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_name (| globals, "receipts_trie" |) + ], + make_dict [] + |); + M.get_name (| globals, "block_logs_bloom" |); + M.call (| + M.get_name (| globals, "state_root" |), + make_list [ + M.get_name (| globals, "state" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition validate_ommers : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "ommers"; "block_header"; "chain" ] |) in + let _ := Constant.str " + Validates the ommers mentioned in the block. + + An ommer block is a block that wasn't canonically added to the + blockchain because it wasn't validated as fast as the canonical block + but was mined at the same time. + + To be considered valid, the ommers must adhere to the rules defined in + the Ethereum protocol. The maximum amount of ommers is 2 per block and + there cannot be duplicate ommers in a block. Many of the other ommer + constraints are listed in the in-line comments of this function. + + Parameters + ---------- + ommers : + List of ommers mentioned in the current block. + block_header: + The header of current block. + chain : + History and current state. + " in + let block_hash := + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "block_header" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), M.get_field (| M.get_name (| globals, "block_header" |), "ommers_hash" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + (* At expr: unsupported node type: Compare *); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let ommer_parent_header := + M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), BinOp.sub (| + UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) |), + Constant.int 1 + |) |), "header" |) in + let _ := M.call (| + M.get_name (| globals, "validate_header" |), + make_list [ + M.get_name (| globals, "ommer" |); + M.get_name (| globals, "ommer_parent_header" |) + ], + make_dict [] + |) in + EndFor. + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), Constant.int 2 |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let ommers_hashes := + [M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "ommer" |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)] in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers_hashes" |) + ], + make_dict [] + |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_name (| globals, "set" |), + make_list [ + M.get_name (| globals, "ommers_hashes" |) + ], + make_dict [] + |) + ], + make_dict [] + |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let recent_canonical_blocks := + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| BinOp.add (| + M.get_name (| globals, "MAX_OMMER_DEPTH" |), + Constant.int 1 + |) |):(* At expr: unsupported node type: NoneType *) |) in + let recent_canonical_block_hashes := + {M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_field (| M.get_name (| globals, "block" |), "header" |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)} in +(* At stmt: unsupported node type: AnnAssign *) + For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_canonical_blocks" |) do + let recent_ommers_hashes := + M.call (| + M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), + make_list [ + {M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "ommer" |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)} + ], + make_dict [] + |) in + EndFor. + For make_tuple [ M.get_name (| globals, "ommer_index" |); M.get_name (| globals, "ommer" |) ] in M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |) do + let ommer_hash := + M.get_subscript (| M.get_name (| globals, "ommers_hashes" |), M.get_name (| globals, "ommer_index" |) |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_eq (| M.get_name (| globals, "ommer_hash" |), M.get_name (| globals, "block_hash" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_in (| M.get_name (| globals, "ommer_hash" |), M.get_name (| globals, "recent_canonical_block_hashes" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_in (| M.get_name (| globals, "ommer_hash" |), M.get_name (| globals, "recent_ommers_hashes" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let ommer_age := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + (* At expr: unsupported node type: Compare *); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.in (| M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), M.get_name (| globals, "recent_canonical_block_hashes" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_eq (| M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), M.get_field (| M.get_name (| globals, "block_header" |), "parent_hash" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_)). + +Definition pay_rewards : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "block_number"; "coinbase"; "ommers" ] |) in + let _ := Constant.str " + Pay rewards to the block miner as well as the ommers miners. + + The miner of the canonical block is rewarded with the predetermined + block reward, ``BLOCK_REWARD``, plus a variable award based off of the + number of ommer blocks that were mined around the same time, and included + in the canonical block's header. An ommer block is a block that wasn't + added to the canonical blockchain because it wasn't validated as fast as + the accepted block but was mined at the same time. Although not all blocks + that are mined are added to the canonical chain, miners are still paid a + reward for their efforts. This reward is called an ommer reward and is + calculated based on the number associated with the ommer block that they + mined. + + Parameters + ---------- + state : + Current account state. + block_number : + Position of the block within the chain. + coinbase : + Address of account which receives block reward and transaction fees. + ommers : + List of ommers mentioned in the current block. + " in + let miner_reward := + BinOp.add (| + M.get_name (| globals, "BLOCK_REWARD" |), + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + BinOp.floor_div (| + M.get_name (| globals, "BLOCK_REWARD" |), + Constant.int 32 + |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "create_ether" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "coinbase" |); + M.get_name (| globals, "miner_reward" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do + let ommer_age := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "block_number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) + ], + make_dict [] + |) in + let ommer_miner_reward := + BinOp.floor_div (| + BinOp.mult (| + BinOp.sub (| + Constant.int 8, + M.get_name (| globals, "ommer_age" |) + |), + M.get_name (| globals, "BLOCK_REWARD" |) + |), + Constant.int 8 + |) in + let _ := M.call (| + M.get_name (| globals, "create_ether" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_field (| M.get_name (| globals, "ommer" |), "coinbase" |); + M.get_name (| globals, "ommer_miner_reward" |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_)). + +Definition process_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "env"; "tx" ] |) in + let _ := Constant.str " + Execute a transaction against the provided environment. + + This function processes the actions needed to execute a transaction. + It decrements the sender's account after calculating the gas fee and + refunds them the proper amount after execution. Calling contracts, + deploying code, and incrementing nonces are all examples of actions that + happen within this function or from a call made within this function. + + Accounts that are marked for deletion are processed and destroyed after + execution. + + Parameters + ---------- + env : + Environment for the Ethereum Virtual Machine. + tx : + Transaction to execute. + + Returns + ------- + gas_left : `ethereum.base_types.U256` + Remaining gas after execution. + logs : `Tuple[ethereum.blocks.Log, ...]` + Logs generated during execution. + " in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + M.call (| + M.get_name (| globals, "validate_transaction" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let sender := + M.get_field (| M.get_name (| globals, "env" |), "origin" |) in + let sender_account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |) in + let gas_fee := + BinOp.mult (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "sender_account" |), "nonce" |), M.get_field (| M.get_name (| globals, "tx" |), "nonce" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt_e (| M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), BinOp.add (| + M.get_name (| globals, "gas_fee" |), + M.get_field (| M.get_name (| globals, "tx" |), "value" |) + |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "sender_account" |), "code" |), M.call (| + M.get_name (| globals, "bytearray" |), + make_list [], + make_dict [] + |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let gas := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.call (| + M.get_name (| globals, "calculate_intrinsic_cost" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) in + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |) in + let sender_balance_after_gas_fee := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), + M.get_name (| globals, "gas_fee" |) + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |); + M.get_name (| globals, "sender_balance_after_gas_fee" |) + ], + make_dict [] + |) in + let message := + M.call (| + M.get_name (| globals, "prepare_message" |), + make_list [ + M.get_name (| globals, "sender" |); + M.get_field (| M.get_name (| globals, "tx" |), "to" |); + M.get_field (| M.get_name (| globals, "tx" |), "value" |); + M.get_field (| M.get_name (| globals, "tx" |), "data" |); + M.get_name (| globals, "gas" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let output := + M.call (| + M.get_name (| globals, "process_message_call" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let gas_used := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "output" |), "gas_left" |) + |) in + let gas_refund := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + BinOp.floor_div (| + M.get_name (| globals, "gas_used" |), + Constant.int 2 + |); + M.get_field (| M.get_name (| globals, "output" |), "refund_counter" |) + ], + make_dict [] + |) in + let gas_refund_amount := + BinOp.mult (| + BinOp.add (| + M.get_field (| M.get_name (| globals, "output" |), "gas_left" |), + M.get_name (| globals, "gas_refund" |) + |), + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) + |) in + let transaction_fee := + BinOp.mult (| + BinOp.sub (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "output" |), "gas_left" |) + |), + M.get_name (| globals, "gas_refund" |) + |), + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) + |) in + let total_gas_used := + BinOp.sub (| + M.get_name (| globals, "gas_used" |), + M.get_name (| globals, "gas_refund" |) + |) in + let sender_balance_after_refund := + BinOp.add (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |), "balance" |), + M.get_name (| globals, "gas_refund_amount" |) + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |); + M.get_name (| globals, "sender_balance_after_refund" |) + ], + make_dict [] + |) in + let coinbase_balance_after_mining_fee := + BinOp.add (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |), "balance" |), + M.get_name (| globals, "transaction_fee" |) + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |); + M.get_name (| globals, "coinbase_balance_after_mining_fee" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "accounts_to_delete" |) do + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + EndFor. + let _ := M.return_ (| + make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |) ] + |) in + M.pure Constant.None_)). + +Definition validate_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Verifies a transaction. + + The gas in a transaction gets used to pay for the intrinsic cost of + operations, therefore if there is insufficient gas then it would not + be possible to execute a transaction and it will be declared invalid. + + Additionally, the nonce of a transaction must not equal or exceed the + limit defined in `EIP-2681 `_. + In practice, defining the limit as ``2**64-1`` has no impact because + sending ``2**64-1`` transactions is improbable. It's not strictly + impossible though, ``2**64-1`` transactions is the entire capacity of the + Ethereum blockchain at 2022 gas limits for a little over 22 years. + + Parameters + ---------- + tx : + Transaction to validate. + + Returns + ------- + verified : `bool` + True if the transaction can be executed, or False otherwise. + " in + let _ := M.return_ (| + BoolOp.and (| + Compare.lt_e (| M.call (| + M.get_name (| globals, "calculate_intrinsic_cost" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |), M.get_field (| M.get_name (| globals, "tx" |), "gas" |) |), + ltac:(M.monadic ( + Compare.lt (| M.get_field (| M.get_name (| globals, "tx" |), "nonce" |), BinOp.sub (| + BinOp.pow (| + Constant.int 2, + Constant.int 64 + |), + Constant.int 1 + |) |) + )) + |) + |) in + M.pure Constant.None_)). + +Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Calculates the gas that is charged before execution is started. + + The intrinsic cost of the transaction is charged before execution has + begun. Functions/operations in the EVM cost money to execute so this + intrinsic cost is for the operations that need to be paid for as part of + the transaction. Data transfer, for example, is part of this intrinsic + cost. It costs ether to send data over the wire and that ether is + accounted for in the intrinsic cost calculated in this function. This + intrinsic cost must be calculated and paid for before execution in order + for all operations to be implemented. + + Parameters + ---------- + tx : + Transaction to compute the intrinsic cost of. + + Returns + ------- + verified : `ethereum.base_types.Uint` + The intrinsic cost of the transaction. + " in + let data_cost := + Constant.int 0 in + For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "byte" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + M.pure Constant.None_ + )) |) in + EndFor. + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_name (| globals, "tx" |), "to" |), M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let create_cost := + M.get_name (| globals, "TX_CREATE_COST" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let create_cost := + Constant.int 0 in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "TX_BASE_COST" |), + M.get_name (| globals, "data_cost" |) + |), + M.get_name (| globals, "create_cost" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition recover_sender : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Extracts the sender address from a transaction. + + The v, r, and s values are the three parts that make up the signature + of a transaction. In order to recover the sender of a transaction the two + components needed are the signature (``v``, ``r``, and ``s``) and the + signing hash of the transaction. The sender's public key can be obtained + with these two values and therefore the sender address can be retrieved. + + Parameters + ---------- + tx : + Transaction of interest. + + Returns + ------- + sender : `ethereum.fork_types.Address` + The address of the account that signed the transaction. + " in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "v" |); M.get_name (| globals, "r" |); M.get_name (| globals, "s" |) ], + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "v" |); M.get_field (| M.get_name (| globals, "tx" |), "r" |); M.get_field (| M.get_name (| globals, "tx" |), "s" |) ] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.or (| + Compare.eq (| M.get_name (| globals, "v" |), Constant.int 27 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "v" |), Constant.int 28 |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.and (| + Compare.lt (| Constant.int 0, M.get_name (| globals, "r" |) |), + ltac:(M.monadic ( + Compare.lt (| M.get_name (| globals, "r" |), M.get_name (| globals, "SECP256K1N" |) |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.and (| + Compare.lt (| Constant.int 0, M.get_name (| globals, "s" |) |), + ltac:(M.monadic ( + Compare.lt_e (| M.get_name (| globals, "s" |), BinOp.floor_div (| + M.get_name (| globals, "SECP256K1N" |), + Constant.int 2 + |) |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + BinOp.sub (| + M.get_name (| globals, "v" |), + Constant.int 27 + |); + M.call (| + M.get_name (| globals, "signing_hash" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_subscript (| M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), Constant.int 12:Constant.int 32 |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition signing_hash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Compute the hash of a transaction used in the signature. + + The values that are used to compute the signing hash set the rules for a + transaction. For example, signing over the gas sets a limit for the + amount of money that is allowed to be pulled out of the sender's account. + + Parameters + ---------- + tx : + Transaction of interest. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the transaction. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "nonce" |); M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |); M.get_field (| M.get_name (| globals, "tx" |), "gas" |); M.get_field (| M.get_name (| globals, "tx" |), "to" |); M.get_field (| M.get_name (| globals, "tx" |), "value" |); M.get_field (| M.get_name (| globals, "tx" |), "data" |) ] + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition compute_header_hash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header" ] |) in + let _ := Constant.str " + Computes the hash of a block header. + + The header hash of a block is the canonical hash that is used to refer + to a specific block and completely distinguishes a block from another. + + ``keccak256`` is a function that produces a 256 bit hash of any input. + It also takes in any number of bytes as an input and produces a single + hash for them. A hash is a completely unique output for a single input. + So an input corresponds to one unique hash that can be used to identify + the input exactly. + + Prior to using the ``keccak256`` hash function, the header must be + encoded using the Recursive-Length Prefix. See :ref:`rlp`. + RLP encoding the header converts it into a space-efficient format that + allows for easy transfer of data between nodes. The purpose of RLP is to + encode arbitrarily nested arrays of binary data, and RLP is the primary + encoding method used to serialize objects in Ethereum's execution layer. + The only purpose of RLP is to encode structure; encoding specific data + types (e.g. strings, floats) is left up to higher-order protocols. + + Parameters + ---------- + header : + Header of interest. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the header. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "header" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition check_gas_limit : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "gas_limit"; "parent_gas_limit" ] |) in + let _ := Constant.str " + Validates the gas limit for a block. + + The bounds of the gas limit, ``max_adjustment_delta``, is set as the + quotient of the parent block's gas limit and the + ``GAS_LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is + passed through as a parameter is greater than or equal to the *sum* of + the parent's gas and the adjustment delta then the limit for gas is too + high and fails this function's check. Similarly, if the limit is less + than or equal to the *difference* of the parent's gas and the adjustment + delta *or* the predefined ``GAS_LIMIT_MINIMUM`` then this function's + check fails because the gas limit doesn't allow for a sufficient or + reasonable amount of gas to be used on a block. + + Parameters + ---------- + gas_limit : + Gas limit to validate. + + parent_gas_limit : + Gas limit of the parent block. + + Returns + ------- + check : `bool` + True if gas limit constraints are satisfied, False otherwise. + " in + let max_adjustment_delta := + BinOp.floor_div (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "gas_limit" |), BinOp.add (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| M.get_name (| globals, "gas_limit" |), BinOp.sub (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "gas_limit" |), M.get_name (| globals, "GAS_LIMIT_MINIMUM" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + Constant.bool true + |) in + M.pure Constant.None_)). + +Definition calculate_block_difficulty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "block_number"; "block_timestamp"; "parent_timestamp"; "parent_difficulty" ] |) in + let _ := Constant.str " + Computes difficulty of a block using its header and parent header. + + The difficulty is determined by the time the block was created after its + parent. The ``offset`` is calculated using the parent block's difficulty, + ``parent_difficulty``, and the timestamp between blocks. This offset is + then added to the parent difficulty and is stored as the ``difficulty`` + variable. If the time between the block and its parent is too short, the + offset will result in a positive number thus making the sum of + ``parent_difficulty`` and ``offset`` to be a greater value in order to + avoid mass forking. But, if the time is long enough, then the offset + results in a negative value making the block less difficult than + its parent. + + The base standard for a block's difficulty is the predefined value + set for the genesis block since it has no parent. So, a block + can't be less difficult than the genesis block, therefore each block's + difficulty is set to the maximum value between the calculated + difficulty and the ``GENESIS_DIFFICULTY``. + + Parameters + ---------- + block_number : + Block number of the block. + block_timestamp : + Timestamp of the block. + parent_timestamp : + Timestamp of the parent block. + parent_difficulty : + difficulty of the parent block. + + Returns + ------- + difficulty : `ethereum.base_types.Uint` + Computed difficulty for a block. + " in + let offset := + BinOp.mult (| + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "parent_difficulty" |) + ], + make_dict [] + |), + Constant.int 2048 + |), + M.call (| + M.get_name (| globals, "max" |), + make_list [ + BinOp.sub (| + Constant.int 1, + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "block_timestamp" |), + M.get_name (| globals, "parent_timestamp" |) + |) + ], + make_dict [] + |), + Constant.int 10 + |) + |); + UnOp.sub (| Constant.int 99 |) + ], + make_dict [] + |) + |) in + let difficulty := + BinOp.add (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "parent_difficulty" |) + ], + make_dict [] + |), + M.get_name (| globals, "offset" |) + |) in + let num_bomb_periods := + BinOp.sub (| + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "block_number" |) + ], + make_dict [] + |), + Constant.int 100000 + |), + Constant.int 2 + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "num_bomb_periods" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let difficulty := BinOp.add + BinOp.pow (| + Constant.int 2, + M.get_name (| globals, "num_bomb_periods" |) + |) + BinOp.pow (| + Constant.int 2, + M.get_name (| globals, "num_bomb_periods" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "max" |), + make_list [ + M.get_name (| globals, "difficulty" |); + M.get_name (| globals, "MINIMUM_DIFFICULTY" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/fork_types.v b/CoqOfPython/ethereum/dao_fork/fork_types.v new file mode 100644 index 0000000..d12953d --- /dev/null +++ b/CoqOfPython/ethereum/dao_fork/fork_types.v @@ -0,0 +1,102 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Types +^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Types re-used throughout the specification, which are specific to Ethereum. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes20 : + IsGlobalAlias globals base_types.globals "Bytes20". +Axiom base_types_Bytes256 : + IsGlobalAlias globals base_types.globals "Bytes256". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require crypto.hash. +Axiom crypto_hash_Hash32 : + IsGlobalAlias globals crypto.hash.globals "Hash32". +Axiom crypto_hash_keccak256 : + IsGlobalAlias globals crypto.hash.globals "keccak256". + +Definition Address : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Bytes20" |) +)). + +Definition Root : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Hash32" |) +)). + +Definition Bloom : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Bytes256" |) +)). + +Definition Account : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition EMPTY_ACCOUNT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Account" |), + make_list [], + make_dict [] + |) +)). + +Definition encode_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "raw_account_data"; "storage_root" ] |) in + let _ := Constant.str " + Encode `Account` dataclass. + + Storage is not stored in the `Account` dataclass, so `Accounts` cannot be + encoded with providing a storage root. + " in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "raw_account_data" |), "nonce" |); M.get_field (| M.get_name (| globals, "raw_account_data" |), "balance" |); M.get_name (| globals, "storage_root" |); M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_field (| M.get_name (| globals, "raw_account_data" |), "code" |) + ], + make_dict [] + |) ] + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/state.v b/CoqOfPython/ethereum/dao_fork/state.v new file mode 100644 index 0000000..38fe9d1 --- /dev/null +++ b/CoqOfPython/ethereum/dao_fork/state.v @@ -0,0 +1,865 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +State +^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The state contains all information that is preserved between transactions. + +It consists of a main account trie and storage tries for each contract. + +There is a distinction between an account that does not exist and +`EMPTY_ACCOUNT`. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_field : + IsGlobalAlias globals dataclasses.globals "field". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_modify : + IsGlobalAlias globals ethereum.base_types.globals "modify". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require fork_types. +Axiom fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". +Axiom fork_types_Account : + IsGlobalAlias globals fork_types.globals "Account". +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Require trie. +Axiom trie_EMPTY_TRIE_ROOT : + IsGlobalAlias globals trie.globals "EMPTY_TRIE_ROOT". +Axiom trie_Trie : + IsGlobalAlias globals trie.globals "Trie". +Axiom trie_copy_trie : + IsGlobalAlias globals trie.globals "copy_trie". +Axiom trie_root : + IsGlobalAlias globals trie.globals "root". +Axiom trie_trie_get : + IsGlobalAlias globals trie.globals "trie_get". +Axiom trie_trie_set : + IsGlobalAlias globals trie.globals "trie_set". + +Definition State : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition close_state : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Free resources held by the state. Used by optimized implementations to + release file descriptors. + " in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) |) in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |) in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) in + M.pure Constant.None_)). + +Definition begin_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Start a state transaction. + + Transactions are entirely implicit and can be nested. It is not possible to + calculate the state root during a transaction. + + Parameters + ---------- + state : State + The state. + " in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), "append" |), + make_list [ + make_tuple [ M.call (| + M.get_name (| globals, "copy_trie" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) + ], + make_dict [] + |); {M.get_name (| globals, "k" |): M.call (| + M.get_name (| globals, "copy_trie" |), + make_list [ + M.get_name (| globals, "t" |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)} ] + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition commit_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Commit a state transaction. + + Parameters + ---------- + state : State + The state. + " in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), "pop" |), + make_list [], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition rollback_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Rollback a state transaction, resetting the state to the point when the + corresponding `start_transaction()` call was made. + + Parameters + ---------- + state : State + The state. + " in + let _ := M.assign (| + make_tuple [ M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) ], + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), "pop" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition get_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Get the `Account` object at an address. Returns `EMPTY_ACCOUNT` if there + is no account at the address. + + Use `get_account_optional()` if you care about the difference between a + non-existent account and `EMPTY_ACCOUNT`. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address to lookup. + + Returns + ------- + account : `Account` + Account at address. + " in + let account := + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "account" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "account" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "EMPTY_ACCOUNT" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition get_account_optional : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Get the `Account` object at an address. Returns `None` (rather than + `EMPTY_ACCOUNT`) if there is no account at the address. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address to lookup. + + Returns + ------- + account : `Account` + Account at address. + " in + let account := + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "account" |) + |) in + M.pure Constant.None_)). + +Definition set_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "account" ] |) in + let _ := Constant.str " + Set the `Account` object at an address. Setting to `None` deletes + the account (but not its storage, see `destroy_account()`). + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address to set. + account : `Account` + Account to set at address. + " in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "account" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition destroy_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Completely remove the account at `address` and all of its storage. + + This function is made available exclusively for the `SELFDESTRUCT` + opcode. It is expected that `SELFDESTRUCT` will be disabled in a future + hardfork and this function will be removed. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of account to destroy. + " in + let _ := M.call (| + M.get_name (| globals, "destroy_storage" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + Constant.None_ + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition destroy_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Completely remove the storage at `address`. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of account whose storage is to be deleted. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition get_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "key" ] |) in + let _ := Constant.str " + Get a value at a storage key on an account. Returns `U256(0)` if the + storage key has not been set previously. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of the account. + key : `Bytes` + Key to lookup. + + Returns + ------- + value : `U256` + Value at the key. + " in + let trie := + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let _ := M.assert (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "U256" |) + ], + make_dict [] + |) |) in + let _ := M.return_ (| + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_)). + +Definition set_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "key"; "value" ] |) in + let _ := Constant.str " + Set a value at a storage key on an account. Setting to `U256(0)` deletes + the key. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of the account. + key : `Bytes` + Key to set. + value : `U256` + Value to set at the key. + " in + let _ := M.assert (| Compare.is_not (| M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), Constant.None_ |) |) in + let trie := + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let trie := + M.call (| + M.get_name (| globals, "Trie" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), + M.get_name (| globals, "trie" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "key" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), {} |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition storage_root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Calculate the storage root of an account. + + Parameters + ---------- + state: + The state + address : + Address of the account. + + Returns + ------- + root : `Root` + Storage root of the account. + " in + let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "EMPTY_TRIE_ROOT" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition state_root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Calculate the state root. + + Parameters + ---------- + state: + The current state. + + Returns + ------- + root : `Root` + The state root. + " in + let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition account_exists : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account exists in the state trie + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + account_exists : `bool` + True if account exists in the state trie, False otherwise + " in + let _ := M.return_ (| + Compare.is_not (| M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), Constant.None_ |) + |) in + M.pure Constant.None_)). + +Definition account_has_code_or_nonce : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account has non zero nonce or non empty code + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + has_code_or_nonce : `bool` + True if if an account has non zero nonce or non empty code, + False otherwise. + " in + let account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + BoolOp.or (| + Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |) + )) + |) + |) in + M.pure Constant.None_)). + +Definition modify_state : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "f" ] |) in + let _ := Constant.str " + Modify an `Account` in the `State`. + " in + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.call (| + M.get_name (| globals, "modify" |), + make_list [ + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |); + M.get_name (| globals, "f" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition move_ether : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "sender_address"; "recipient_address"; "amount" ] |) in + let _ := Constant.str " + Move funds between accounts. + " in +(* At stmt: unsupported node type: FunctionDef *) +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "sender_address" |); + M.get_name (| globals, "reduce_sender_balance" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "recipient_address" |); + M.get_name (| globals, "increase_recipient_balance" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition set_account_balance : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "amount" ] |) in + let _ := Constant.str " + Sets the balance of an account. + + Parameters + ---------- + state: + The current state. + + address: + Address of the account whose nonce needs to be incremented. + + amount: + The amount that needs to set in balance. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "set_balance" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition touch_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Initializes an account to state. + + Parameters + ---------- + state: + The current state. + + address: + The address of the account that need to initialised. + " in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "account_exists" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "EMPTY_ACCOUNT" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition increment_nonce : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Increments the nonce of an account. + + Parameters + ---------- + state: + The current state. + + address: + Address of the account whose nonce needs to be incremented. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "increase_nonce" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition set_code : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "code" ] |) in + let _ := Constant.str " + Sets Account code. + + Parameters + ---------- + state: + The current state. + + address: + Address of the account whose code needs to be update. + + code: + The bytecode that needs to be set. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "write_code" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition create_ether : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "amount" ] |) in + let _ := Constant.str " + Add newly created ether to an account. + + Parameters + ---------- + state: + The current state. + address: + Address of the account to which ether is added. + amount: + The amount of ether to be added to the account of interest. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "increase_balance" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/transactions.v b/CoqOfPython/ethereum/dao_fork/transactions.v new file mode 100644 index 0000000..6d1bc6b --- /dev/null +++ b/CoqOfPython/ethereum/dao_fork/transactions.v @@ -0,0 +1,60 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Transactions are atomic units of work created externally to Ethereum and +submitted to be executed. If Ethereum is viewed as a state machine, +transactions are the events that move between states. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes0 : + IsGlobalAlias globals base_types.globals "Bytes0". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( + Constant.int 21000 +)). + +Definition TX_DATA_COST_PER_NON_ZERO : Value.t := M.run ltac:(M.monadic ( + Constant.int 68 +)). + +Definition TX_DATA_COST_PER_ZERO : Value.t := M.run ltac:(M.monadic ( + Constant.int 4 +)). + +Definition TX_CREATE_COST : Value.t := M.run ltac:(M.monadic ( + Constant.int 32000 +)). + +Definition Transaction : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. diff --git a/CoqOfPython/ethereum/dao_fork/trie.v b/CoqOfPython/ethereum/dao_fork/trie.v new file mode 100644 index 0000000..884333c --- /dev/null +++ b/CoqOfPython/ethereum/dao_fork/trie.v @@ -0,0 +1,1357 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +State Trie +^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The state trie is the structure responsible for storing +`.fork_types.Account` objects. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_field : + IsGlobalAlias globals dataclasses.globals "field". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". +Axiom typing_Generic : + IsGlobalAlias globals typing.globals "Generic". +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Mapping : + IsGlobalAlias globals typing.globals "Mapping". +Axiom typing_MutableMapping : + IsGlobalAlias globals typing.globals "MutableMapping". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Sequence : + IsGlobalAlias globals typing.globals "Sequence". +Axiom typing_TypeVar : + IsGlobalAlias globals typing.globals "TypeVar". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". +Axiom typing_cast : + IsGlobalAlias globals typing.globals "cast". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.homestead. +Axiom ethereum_homestead_trie : + IsGlobalAlias globals ethereum.homestead.globals "trie". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require ethereum.utils.hexadecimal. +Axiom ethereum_utils_hexadecimal_hex_to_bytes : + IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require blocks. +Axiom blocks_Receipt : + IsGlobalAlias globals blocks.globals "Receipt". + +Require fork_types. +Axiom fork_types_Account : + IsGlobalAlias globals fork_types.globals "Account". +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". +Axiom fork_types_encode_account : + IsGlobalAlias globals fork_types.globals "encode_account". + +Require transactions. +Axiom transactions_Transaction : + IsGlobalAlias globals transactions.globals "Transaction". + +Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Root" |), + make_list [ + M.call (| + M.get_name (| globals, "hex_to_bytes" |), + make_list [ + Constant.str "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" + ], + make_dict [] + |) + ], + make_dict [] + |) +)). + +Definition Node : Value.t := M.run ltac:(M.monadic ( + M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Bytes" |); M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |); Constant.None_ ] |) +)). + +Definition K : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "TypeVar" |), + make_list [ + Constant.str "K" + ], + make_dict [] + |) +)). + +Definition V : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "TypeVar" |), + make_list [ + Constant.str "V"; + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Account" |) |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Bytes" |) |); + M.get_name (| globals, "Bytes" |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Transaction" |) |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Receipt" |) |); + M.get_name (| globals, "Uint" |); + M.get_name (| globals, "U256" |) + ], + make_dict [] + |) +)). + +Definition LeafNode : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition ExtensionNode : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition BranchNode : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition InternalNode : Value.t := M.run ltac:(M.monadic ( + M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LeafNode" |); M.get_name (| globals, "ExtensionNode" |); M.get_name (| globals, "BranchNode" |) ] |) +)). + +Definition encode_internal_node : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "node" ] |) in + let _ := Constant.str " + Encodes a Merkle Trie node into its RLP form. The RLP will then be + serialized into a `Bytes` and hashed unless it is less that 32 bytes + when serialized. + + This function also accepts `None`, representing the absence of a node, + which is encoded to `b""""""`. + + Parameters + ---------- + node : Optional[InternalNode] + The node to encode. + + Returns + ------- + encoded : `rlp.RLP` + The node encoded as RLP. + " in +(* At stmt: unsupported node type: AnnAssign *) + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "node" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let unencoded := + (* At constant: unsupported node type: Constant *) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "LeafNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "rest_of_key" |); + Constant.bool true + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "ExtensionNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "key_segment" |); + Constant.bool false + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "BranchNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + BinOp.add (| + M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "value" |) + ] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "AssertionError" |), + make_list [ + (* At expr: unsupported node type: JoinedStr *) + ], + make_dict [] + |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let encoded := + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "unencoded" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded" |) + ], + make_dict [] + |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "unencoded" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "encoded" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition encode_node : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "node"; "storage_root" ] |) in + let _ := Constant.str " + Encode a Node for storage in the Merkle Trie. + + Currently mostly an unimplemented stub. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "storage_root" |), Constant.None_ |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "encode_account" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "storage_root" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + make_tuple [ M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "U256" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "cast" |), + make_list [ + M.get_field (| M.get_name (| globals, "rlp" |), "RLP" |); + M.get_name (| globals, "node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "node" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "previous_trie" |), "encode_node" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "storage_root" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition Trie : Value.t := + builtins.make_klass + [(* At base: unsupported node type: Subscript *)] + [ + + ] + [ + + ]. + +Definition copy_trie : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie" ] |) in + let _ := Constant.str " + Create a copy of `trie`. Since only frozen objects may be stored in tries, + the contents are reused. + + Parameters + ---------- + trie: `Trie` + Trie to copy. + + Returns + ------- + new_trie : `Trie[K, V]` + A copy of the trie. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Trie" |), + make_list [ + M.get_field (| M.get_name (| globals, "trie" |), "secured" |); + M.get_field (| M.get_name (| globals, "trie" |), "default" |); + M.call (| + M.get_field (| M.get_name (| globals, "copy" |), "copy" |), + make_list [ + M.get_field (| M.get_name (| globals, "trie" |), "_data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition trie_set : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "key"; "value" ] |) in + let _ := Constant.str " + Stores an item in a Merkle Trie. + + This method deletes the key if `value == trie.default`, because the Merkle + Trie represents the default value by omitting it from the trie. + + Parameters + ---------- + trie: `Trie` + Trie to store in. + key : `Bytes` + Key to lookup. + value : `V` + Node to insert at `key`. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "value" |), M.get_field (| M.get_name (| globals, "trie" |), "default" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "key" |), M.get_field (| M.get_name (| globals, "trie" |), "_data" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition trie_get : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "key" ] |) in + let _ := Constant.str " + Gets an item from the Merkle Trie. + + This method returns `trie.default` if the key is missing. + + Parameters + ---------- + trie: + Trie to lookup in. + key : + Key to lookup. + + Returns + ------- + node : `V` + Node at `key` in the trie. + " in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "get" |), + make_list [ + M.get_name (| globals, "key" |); + M.get_field (| M.get_name (| globals, "trie" |), "default" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition common_prefix_length : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "a"; "b" ] |) in + let _ := Constant.str " + Find the longest common prefix of two sequences. + " in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + ], + make_dict [] + |) do + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| M.get_name (| globals, "i" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition nibble_list_to_compact : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "x"; "is_leaf" ] |) in + let _ := Constant.str " + Compresses nibble-list into a standard byte array with a flag. + + A nibble-list is a list of byte values no greater than `15`. The flag is + encoded in high nibble of the highest byte. The flag nibble can be broken + down into two two-bit flags. + + Highest nibble:: + + +---+---+----------+--------+ + | _ | _ | is_leaf | parity | + +---+---+----------+--------+ + 3 2 1 0 + + + The lowest bit of the nibble encodes the parity of the length of the + remaining nibbles -- `0` when even and `1` when odd. The second lowest bit + is used to distinguish leaf and extension nodes. The other two bits are not + used. + + Parameters + ---------- + x : + Array of nibbles. + is_leaf : + True if this is part of a leaf node, or false if it is an extension + node. + + Returns + ------- + compressed : `bytearray` + Compact byte array. + " in + let compact := + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + Constant.int 2 + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.mult (| + Constant.int 16, + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "is_leaf" |) + |) + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + BinOp.add (| + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "is_leaf" |) + |), + Constant.int 1 + |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), Constant.int 0 |) + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 1; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + M.get_name (| globals, "compact" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition bytes_to_nibble_list : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "bytes_" ] |) in + let _ := Constant.str " + Converts a `Bytes` into to a sequence of nibbles (bytes with value < 16). + + Parameters + ---------- + bytes_: + The `Bytes` to convert. + + Returns + ------- + nibble_list : `Bytes` + The `Bytes` in nibble-list format. + " in + let nibble_list := + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [ + BinOp.mult (| + Constant.int 2, + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "bytes_" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + For make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ] in M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "bytes_" |) + ], + make_dict [] + |) do + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |) |), + BinOp.r_shift (| + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 240 + |), + Constant.int 4 + |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |), + Constant.int 1 + |) |), + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 15 + |) + |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + M.get_name (| globals, "nibble_list" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition _prepare_trie : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "get_storage_root" ] |) in + let _ := Constant.str " + Prepares the trie for root calculation. Removes values that are empty, + hashes the keys (if `secured == True`) and encodes all the nodes. + + Parameters + ---------- + trie : + The `Trie` to prepare. + get_storage_root : + Function to get the storage root of an account. Needed to encode + `Account` objects. + + Returns + ------- + out : `Mapping[ethereum.base_types.Bytes, Node]` + Object with keys mapped to nibble-byte form. + " in +(* At stmt: unsupported node type: AnnAssign *) + For make_tuple [ M.get_name (| globals, "preimage" |); M.get_name (| globals, "value" |) ] in M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "items" |), + make_list [], + make_dict [] + |) do + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in + let address := + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |); + M.call (| + M.get_name (| globals, "get_storage_root" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_eq (| M.get_name (| globals, "encoded_value" |), (* At constant: unsupported node type: Constant *) |); + M.get_name (| globals, "AssertionError" |) + ], + make_dict [] + |) in +(* At stmt: unsupported node type: AnnAssign *) + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "trie" |), "secured" |), + (* then *) + ltac:(M.monadic ( + let key := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let key := + M.get_name (| globals, "preimage" |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "mapped" |), M.call (| + M.get_name (| globals, "bytes_to_nibble_list" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |) |), + M.get_name (| globals, "encoded_value" |) + |) in + EndFor. + let _ := M.return_ (| + M.get_name (| globals, "mapped" |) + |) in + M.pure Constant.None_)). + +Definition root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "get_storage_root" ] |) in + let _ := Constant.str " + Computes the root of a modified merkle patricia trie (MPT). + + Parameters + ---------- + trie : + `Trie` to get the root of. + get_storage_root : + Function to get the storage root of an account. Needed to encode + `Account` objects. + + + Returns + ------- + root : `.fork_types.Root` + MPT root of the underlying key-value pairs. + " in + let obj := + M.call (| + M.get_name (| globals, "_prepare_trie" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "get_storage_root" |) + ], + make_dict [] + |) in + let root_node := + M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_name (| globals, "obj" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assert (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "root_node" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Root" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition patricialize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "obj"; "level" ] |) in + let _ := Constant.str " + Structural composition function. + + Used to recursively patricialize and merkleize a dictionary. Includes + memoization of the tree structure and hashes. + + Parameters + ---------- + obj : + Underlying trie key-value pairs, with keys in nibble-list format. + level : + Current trie level. + + Returns + ------- + node : `ethereum.base_types.Bytes` + Root node of `obj`. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let arbitrary_key := + M.call (| + M.get_name (| globals, "next" |), + make_list [ + M.call (| + M.get_name (| globals, "iter" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), Constant.int 1 |), + (* then *) + ltac:(M.monadic ( + let leaf := + M.call (| + M.get_name (| globals, "LeafNode" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |); + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "leaf" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let substring := + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) in + let prefix_length := + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "substring" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do + let prefix_length := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_name (| globals, "prefix_length" |); + M.call (| + M.get_name (| globals, "common_prefix_length" |), + make_list [ + M.get_name (| globals, "substring" |); + M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let prefix := + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ExtensionNode" |), + make_list [ + M.get_name (| globals, "prefix" |); + M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_name (| globals, "obj" |); + BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in +(* At stmt: unsupported node type: AnnAssign *) + For M.get_name (| globals, "_" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 16 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "branches" |), "append" |), + make_list [ + {} + ], + make_dict [] + |) in + EndFor. + let value := + (* At constant: unsupported node type: Constant *) in + For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |), M.get_name (| globals, "level" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "AssertionError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) + |) in + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "BranchNode" |), + make_list [ + [M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "branches" |), M.get_name (| globals, "k" |) |); + BinOp.add (| + M.get_name (| globals, "level" |), + Constant.int 1 + |) + ], + make_dict [] + |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)]; + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/utils/__init__.v b/CoqOfPython/ethereum/dao_fork/utils/__init__.v new file mode 100644 index 0000000..1baedea --- /dev/null +++ b/CoqOfPython/ethereum/dao_fork/utils/__init__.v @@ -0,0 +1,8 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Utility functions unique to this particular fork. +". diff --git a/CoqOfPython/ethereum/dao_fork/utils/address.v b/CoqOfPython/ethereum/dao_fork/utils/address.v new file mode 100644 index 0000000..460935f --- /dev/null +++ b/CoqOfPython/ethereum/dao_fork/utils/address.v @@ -0,0 +1,133 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Hardfork Utility Functions For Addresses +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Address specific functions used in this Dao Fork version of specification. +". + +Require typing. +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_left_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Definition to_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "data" ] |) in + let _ := Constant.str " + Convert a Uint or U256 value to a valid address (20 bytes). + + Parameters + ---------- + data : + The string to be converted to bytes. + + Returns + ------- + address : `Address` + The obtained address. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_subscript (| M.call (| + M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition compute_contract_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "address"; "nonce" ] |) in + let _ := Constant.str " + Computes address of the new account that needs to be created. + + Parameters + ---------- + address : + The address of the account that wants to create the new account. + nonce : + The transaction count of the account that wants to create the new + account. + + Returns + ------- + address: `ethereum.dao_fork.fork_types.Address` + The computed address of the new account. + " in + let computed_address := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_list [ + M.get_name (| globals, "address" |); + M.get_name (| globals, "nonce" |) + ] + ], + make_dict [] + |) + ], + make_dict [] + |) in + let canonical_address := + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + let padded_address := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "canonical_address" |); + Constant.int 20 + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "padded_address" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/utils/hexadecimal.v b/CoqOfPython/ethereum/dao_fork/utils/hexadecimal.v new file mode 100644 index 0000000..ca91cac --- /dev/null +++ b/CoqOfPython/ethereum/dao_fork/utils/hexadecimal.v @@ -0,0 +1,155 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Utility Functions For Hexadecimal Strings +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Hexadecimal utility functions used in this specification, specific to Dao Fork +types. +". + +Require ethereum.utils.hexadecimal. +Axiom ethereum_utils_hexadecimal_remove_hex_prefix : + IsGlobalAlias globals ethereum.utils.hexadecimal.globals "remove_hex_prefix". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Definition hex_to_root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to trie root. + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to trie root. + + Returns + ------- + root : `Root` + Trie root obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Root" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition hex_to_bloom : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to bloom. + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to bloom. + + Returns + ------- + bloom : `Bloom` + Bloom obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bloom" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition hex_to_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to Address (20 bytes). + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to Address. + + Returns + ------- + address : `Address` + The address obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |), "rjust" |), + make_list [ + Constant.int 40; + Constant.str "0" + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/utils/message.v b/CoqOfPython/ethereum/dao_fork/utils/message.v new file mode 100644 index 0000000..a459724 --- /dev/null +++ b/CoqOfPython/ethereum/dao_fork/utils/message.v @@ -0,0 +1,197 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Hardfork Utility Functions For The Message Data-structure +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Message specific functions used in this Dao Fork version of specification. +". + +Require typing. +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". + +Require vm. +Axiom vm_Environment : + IsGlobalAlias globals vm.globals "Environment". +Axiom vm_Message : + IsGlobalAlias globals vm.globals "Message". + +Require address. +Axiom address_compute_contract_address : + IsGlobalAlias globals address.globals "compute_contract_address". + +Definition prepare_message : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "caller"; "target"; "value"; "data"; "gas"; "env"; "code_address"; "should_transfer_value" ] |) in + let _ := Constant.str " + Execute a transaction against the provided environment. + + Parameters + ---------- + caller : + Address which initiated the transaction + target : + Address whose code will be executed + value : + Value to be transferred. + data : + Array of bytes provided to the code in `target`. + gas : + Gas provided for the code in `target`. + env : + Environment for the Ethereum Virtual Machine. + code_address : + This is usually same as the `target` address except when an alternative + accounts code needs to be executed. + eg. `CALLCODE` calling a precompile. + should_transfer_value : + if True ETH should be transferred while executing a message call. + + Returns + ------- + message: `ethereum.dao_fork.vm.Message` + Items containing contract creation or message call specific data. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Bytes0" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.call (| + M.get_name (| globals, "compute_contract_address" |), + make_list [ + M.get_name (| globals, "caller" |); + BinOp.sub (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "caller" |) + ], + make_dict [] + |), "nonce" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let msg_data := + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |) in + let code := + M.get_name (| globals, "data" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.get_name (| globals, "target" |) in + let msg_data := + M.get_name (| globals, "data" |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "target" |) + ], + make_dict [] + |), "code" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "code_address" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let code_address := + M.get_name (| globals, "target" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "AssertionError" |), + make_list [ + Constant.str "Target must be address or empty bytes" + ], + make_dict [] + |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/vm/__init__.v b/CoqOfPython/ethereum/dao_fork/vm/__init__.v new file mode 100644 index 0000000..4a6d18f --- /dev/null +++ b/CoqOfPython/ethereum/dao_fork/vm/__init__.v @@ -0,0 +1,145 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The abstract computer which runs the code stored in an +`.fork_types.Account`. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_State : + IsGlobalAlias globals state.globals "State". + +Definition __all__ : Value.t := M.run ltac:(M.monadic ( + make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] +)). + +Definition Environment : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Message : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Evm : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition incorporate_child_on_success : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "child_evm" ] |) in + let _ := Constant.str " + Incorporate the state of a successful `child_evm` into the parent `evm`. + + Parameters + ---------- + evm : + The parent `EVM`. + child_evm : + The child evm to incorporate. + " in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "gas_left" |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "logs" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "logs" |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "refund_counter" |) + |) in + M.pure Constant.None_)). + +Definition incorporate_child_on_error : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "child_evm" ] |) in + let _ := Constant.str " + Incorporate the state of an unsuccessful `child_evm` into the parent `evm`. + + Parameters + ---------- + evm : + The parent `EVM`. + child_evm : + The child evm to incorporate. + " in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "gas_left" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/vm/exceptions.v b/CoqOfPython/ethereum/dao_fork/vm/exceptions.v new file mode 100644 index 0000000..45435b3 --- /dev/null +++ b/CoqOfPython/ethereum/dao_fork/vm/exceptions.v @@ -0,0 +1,122 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Exceptions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Exceptions which cause the EVM to halt exceptionally. +". + +Require ethereum.exceptions. +Axiom ethereum_exceptions_EthereumException : + IsGlobalAlias globals ethereum.exceptions.globals "EthereumException". + +Definition ExceptionalHalt : Value.t := + builtins.make_klass + [(globals, "EthereumException")] + [ + + ] + [ + + ]. + +Definition StackUnderflowError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition StackOverflowError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition OutOfGasError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition InvalidOpcode : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + ( + "__init__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "code" ] |) in + let _ := M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "super" |), + make_list [], + make_dict [] + |), "__init__" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "self" |), "code" |), + M.get_name (| globals, "code" |) + |) in + M.pure Constant.None_)) + ) + ]. + +Definition InvalidJumpDestError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition StackDepthLimitError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition AddressCollision : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/__init__.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/__init__.v new file mode 100644 index 0000000..e5bebd7 --- /dev/null +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/__init__.v @@ -0,0 +1,87 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +EVM Instruction Encoding (Opcodes) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Machine readable representations of EVM instructions, and a mapping to their +implementations. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". + +Require __init__. +Axiom __init___arithmetic : + IsGlobalAlias globals __init__.globals "arithmetic". + +Require __init__. +Axiom __init___bitwise : + IsGlobalAlias globals __init__.globals "bitwise". + +Require __init__. +Axiom __init___block : + IsGlobalAlias globals __init__.globals "block". + +Require __init__. +Axiom __init___comparison : + IsGlobalAlias globals __init__.globals "comparison". + +Require __init__. +Axiom __init___control_flow : + IsGlobalAlias globals __init__.globals "control_flow". + +Require __init__. +Axiom __init___environment : + IsGlobalAlias globals __init__.globals "environment". + +Require __init__. +Axiom __init___keccak : + IsGlobalAlias globals __init__.globals "keccak". + +Require __init__. +Axiom __init___log : + IsGlobalAlias globals __init__.globals "log". + +Require __init__. +Axiom __init___memory : + IsGlobalAlias globals __init__.globals "memory". + +Require __init__. +Axiom __init___stack : + IsGlobalAlias globals __init__.globals "stack". + +Require __init__. +Axiom __init___storage : + IsGlobalAlias globals __init__.globals "storage". + +Require __init__. +Axiom __init___system : + IsGlobalAlias globals __init__.globals "system". + +Definition Ops : Value.t := + builtins.make_klass + [(* At base: unsupported node type: Attribute *)] + [ + + ] + [ + + ]. + +(* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/arithmetic.v new file mode 100644 index 0000000..a8b5c61 --- /dev/null +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/arithmetic.v @@ -0,0 +1,1085 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Arithmetic Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM Arithmetic instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U255_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U255_CEIL_VALUE". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_U256_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_get_sign : + IsGlobalAlias globals ethereum.utils.numeric.globals "get_sign". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_EXPONENTIATION : + IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION". +Axiom gas_GAS_EXPONENTIATION_PER_BYTE : + IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION_PER_BYTE". +Axiom gas_GAS_LOW : + IsGlobalAlias globals gas.globals "GAS_LOW". +Axiom gas_GAS_MID : + IsGlobalAlias globals gas.globals "GAS_MID". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition add : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Adds the top two elements of the stack together, and pushes the result back + on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "x" |), "wrapping_add" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition sub : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Subtracts the top two elements of the stack, and pushes the result back + on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "x" |), "wrapping_sub" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mul : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Multiply the top two elements of the stack, and pushes the result back + on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "x" |), "wrapping_mul" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition div : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Integer division of the top two elements of the stack. Pushes the result + back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let dividend := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let divisor := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let quotient := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let quotient := + BinOp.floor_div (| + M.get_name (| globals, "dividend" |), + M.get_name (| globals, "divisor" |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "quotient" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition sdiv : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed integer division of the top two elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let dividend := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let divisor := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let quotient := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_name (| globals, "dividend" |), UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "divisor" |), UnOp.sub (| Constant.int 1 |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let quotient := + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let sign := + M.call (| + M.get_name (| globals, "get_sign" |), + make_list [ + BinOp.mult (| + M.get_name (| globals, "dividend" |), + M.get_name (| globals, "divisor" |) + |) + ], + make_dict [] + |) in + let quotient := + BinOp.mult (| + M.get_name (| globals, "sign" |), + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "dividend" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "divisor" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + M.get_name (| globals, "quotient" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Modulo remainder of the top two elements of the stack. Pushes the result + back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let remainder := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let remainder := + BinOp.mod_ (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "remainder" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition smod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed modulo remainder of the top two elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let y := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let remainder := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let remainder := + BinOp.mult (| + M.call (| + M.get_name (| globals, "get_sign" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + BinOp.mod_ (| + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + M.get_name (| globals, "remainder" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition addmod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Modulo addition of the top 2 elements with the 3rd element. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let z := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_MID" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.add (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |), + M.get_name (| globals, "z" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mulmod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Modulo multiplication of the top 2 elements with the 3rd element. Pushes + the result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let z := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_MID" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.mult (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |), + M.get_name (| globals, "z" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition exp : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Exponential operation of the top 2 elements. Pushes the result back on + the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let base := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exponent := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exponent_bits := + M.call (| + M.get_field (| M.get_name (| globals, "exponent" |), "bit_length" |), + make_list [], + make_dict [] + |) in + let exponent_bytes := + BinOp.floor_div (| + BinOp.add (| + M.get_name (| globals, "exponent_bits" |), + Constant.int 7 + |), + Constant.int 8 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_EXPONENTIATION" |), + BinOp.mult (| + M.get_name (| globals, "GAS_EXPONENTIATION_PER_BYTE" |), + M.get_name (| globals, "exponent_bytes" |) + |) + |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "pow" |), + make_list [ + M.get_name (| globals, "base" |); + M.get_name (| globals, "exponent" |); + M.get_name (| globals, "U256_CEIL_VALUE" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition signextend : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Sign extend operation. In other words, extend a signed number which + fits in N bytes to 32 bytes. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let byte_num := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "byte_num" |), Constant.int 31 |), + (* then *) + ltac:(M.monadic ( + let result := + M.get_name (| globals, "value" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let value_bytes := + M.call (| + M.get_name (| globals, "bytes" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "value" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) in + let value_bytes := + M.get_subscript (| M.get_name (| globals, "value_bytes" |), BinOp.sub (| + Constant.int 31, + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "byte_num" |) + ], + make_dict [] + |) + |):(* At expr: unsupported node type: NoneType *) |) in + let sign_bit := + BinOp.r_shift (| + M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), + Constant.int 7 + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "sign_bit" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "value_bytes" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let num_bytes_prepend := + BinOp.sub (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "byte_num" |), + Constant.int 1 + |) + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + BinOp.add (| + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [ + BinOp.mult (| + make_list [ + Constant.int 255 + ], + M.get_name (| globals, "num_bytes_prepend" |) + |) + ], + make_dict [] + |), + M.get_name (| globals, "value_bytes" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/bitwise.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/bitwise.v new file mode 100644 index 0000000..b20a1e5 --- /dev/null +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/bitwise.v @@ -0,0 +1,345 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Bitwise Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM bitwise instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition bitwise_and : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise AND operation of the top 2 elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + BinOp.bit_and (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_or : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise OR operation of the top 2 elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + BinOp.bit_or (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_xor : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise XOR operation of the top 2 elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + BinOp.bit_xor (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_not : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise NOT operation of the top element of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + UnOp.invert (| M.get_name (| globals, "x" |) |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition get_byte : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + For a word (defined by next top element of the stack), retrieve the + Nth byte (0-indexed and defined by top element of stack) from the + left (most significant) to right (least significant). + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let byte_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let word := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "byte_index" |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let extra_bytes_to_right := + BinOp.sub (| + Constant.int 31, + M.get_name (| globals, "byte_index" |) + |) in + let word := + BinOp.r_shift (| + M.get_name (| globals, "word" |), + BinOp.mult (| + M.get_name (| globals, "extra_bytes_to_right" |), + Constant.int 8 + |) + |) in + let word := + BinOp.bit_and (| + M.get_name (| globals, "word" |), + Constant.int 255 + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "word" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/block.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/block.v new file mode 100644 index 0000000..e5fa554 --- /dev/null +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/block.v @@ -0,0 +1,337 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Block Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM block instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_BLOCK_HASH : + IsGlobalAlias globals gas.globals "GAS_BLOCK_HASH". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition block_hash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the hash of one of the 256 most recent complete blocks onto the + stack. The block number to hash is present at the top of the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let block_number := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BLOCK_HASH" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt_e (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), M.get_name (| globals, "block_number" |) |), + ltac:(M.monadic ( + Compare.gt (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), BinOp.add (| + M.get_name (| globals, "block_number" |), + Constant.int 256 + |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let hash := + (* At constant: unsupported node type: Constant *) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let hash := + M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + M.get_name (| globals, "block_number" |) + |) |) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "hash" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition coinbase : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's beneficiary address (address of the block miner) + onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "coinbase" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition timestamp : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's timestamp onto the stack. Here the timestamp + being referred is actually the unix timestamp in seconds. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "time" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition number : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's number onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition difficulty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's difficulty onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "difficulty" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition gas_limit : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's gas limit onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "gas_limit" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/comparison.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/comparison.v new file mode 100644 index 0000000..fbc35f8 --- /dev/null +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/comparison.v @@ -0,0 +1,404 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Comparison Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM Comparison instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition less_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is less than the next top element. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let right := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition signed_less_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed less-than comparison. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let right := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition greater_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is greater than the next top element. Pushes + the result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let right := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition signed_greater_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed greater-than comparison. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let right := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition equal : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is equal to the next top element. Pushes + the result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let right := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.eq (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition is_zero : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is equal to 0. Pushes the result back on the + stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.eq (| M.get_name (| globals, "x" |), Constant.int 0 |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/control_flow.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/control_flow.v new file mode 100644 index 0000000..04a79d9 --- /dev/null +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/control_flow.v @@ -0,0 +1,336 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Control Flow Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM control flow instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require vm.gas. +Axiom vm_gas_GAS_BASE : + IsGlobalAlias globals vm.gas.globals "GAS_BASE". +Axiom vm_gas_GAS_HIGH : + IsGlobalAlias globals vm.gas.globals "GAS_HIGH". +Axiom vm_gas_GAS_JUMPDEST : + IsGlobalAlias globals vm.gas.globals "GAS_JUMPDEST". +Axiom vm_gas_GAS_MID : + IsGlobalAlias globals vm.gas.globals "GAS_MID". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_InvalidJumpDestError : + IsGlobalAlias globals exceptions.globals "InvalidJumpDestError". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition stop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stop further execution of EVM code. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let _ := M.pass (| |) in + let _ := M.pass (| |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "running" |), + Constant.bool false + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition jump : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Alter the program counter to the location specified by the top of the + stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let jump_dest := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_MID" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "jump_dest" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition jumpi : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Alter the program counter to the specified location if and only if a + condition is true. If the condition is not true, then the program counter + would increase only by 1. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let jump_dest := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let conditional_value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_HIGH" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "conditional_value" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let destination := + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let destination := + M.get_name (| globals, "jump_dest" |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "destination" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition pc : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push onto the stack the value of the program counter after reaching the + current instruction and without increasing it for the next instruction. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "pc" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition gas_left : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the amount of available gas (including the corresponding reduction + for the cost of this instruction) onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition jumpdest : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Mark a valid destination for jumps. This is a noop, present only + to be used by `JUMP` and `JUMPI` opcodes to verify that their jump is + valid. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_JUMPDEST" |) + ], + make_dict [] + |) in + let _ := M.pass (| |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/environment.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/environment.v new file mode 100644 index 0000000..4d26a46 --- /dev/null +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/environment.v @@ -0,0 +1,943 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Environmental Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM environment related instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require state. +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". + +Require utils.address. +Axiom utils_address_to_address : + IsGlobalAlias globals utils.address.globals "to_address". + +Require vm.memory. +Axiom vm_memory_buffer_read : + IsGlobalAlias globals vm.memory.globals "buffer_read". +Axiom vm_memory_memory_write : + IsGlobalAlias globals vm.memory.globals "memory_write". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_BALANCE : + IsGlobalAlias globals gas.globals "GAS_BALANCE". +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_COPY : + IsGlobalAlias globals gas.globals "GAS_COPY". +Axiom gas_GAS_EXTERNAL : + IsGlobalAlias globals gas.globals "GAS_EXTERNAL". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the address of the current executing account to the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition balance : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the balance of the given account onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BALANCE" |) + ], + make_dict [] + |) in + let balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "balance" |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "balance" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition origin : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the address of the original transaction sender to the stack. + The origin address can only be an EOA. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "origin" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition caller : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the address of the caller onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "caller" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition callvalue : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the value (in wei) sent with the call onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition calldataload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push a word (32 bytes) of the input data belonging to the current + environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |); + M.get_name (| globals, "start_index" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition calldatasize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the size of input data in current environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition calldatacopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy a portion of the input data in current environment to memory. + + This will also expand the memory, in case that the memory is insufficient + to store the data. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let data_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |); + M.get_name (| globals, "data_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition codesize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the size of code running in current environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "code" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition codecopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy a portion of the code in current environment to memory. + + This will also expand the memory, in case that the memory is insufficient + to store the data. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let code_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "code" |); + M.get_name (| globals, "code_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition gasprice : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the gas price used in current environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "gas_price" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition extcodesize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the code size of a given account onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_EXTERNAL" |) + ], + make_dict [] + |) in + let codesize := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "code" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "codesize" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition extcodecopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy a portion of an account's code to memory. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let code_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_EXTERNAL" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "code" |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "code" |); + M.get_name (| globals, "code_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/keccak.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/keccak.v new file mode 100644 index 0000000..cab9ffb --- /dev/null +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/keccak.v @@ -0,0 +1,181 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Keccak Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM keccak instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_KECCAK256 : + IsGlobalAlias globals gas.globals "GAS_KECCAK256". +Axiom gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition keccak : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes to the stack the Keccak-256 hash of a region of memory. + + This also expands the memory, in case the memory is insufficient to + access the data's memory location. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let word_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_KECCAK256_WORD" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_KECCAK256" |), + M.get_name (| globals, "word_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let data := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "hash" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/log.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/log.v new file mode 100644 index 0000000..f246f9d --- /dev/null +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/log.v @@ -0,0 +1,228 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Logging Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM logging instructions. +". + +Require functools. +Axiom functools_partial : + IsGlobalAlias globals functools.globals "partial". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_LOG : + IsGlobalAlias globals gas.globals "GAS_LOG". +Axiom gas_GAS_LOG_DATA : + IsGlobalAlias globals gas.globals "GAS_LOG_DATA". +Axiom gas_GAS_LOG_TOPIC : + IsGlobalAlias globals gas.globals "GAS_LOG_TOPIC". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". + +Definition log_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "num_topics" ] |) in + let _ := Constant.str " + Appends a log entry, having `num_topics` topics, to the evm logs. + + This will also expand the memory if the data (required by the log entry) + corresponding to the memory is not accessible. + + Parameters + ---------- + evm : + The current EVM frame. + num_topics : + The number of topics to be included in the log entry. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let topics := + make_list [] in + For M.get_name (| globals, "_" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "num_topics" |) + ], + make_dict [] + |) do + let topic := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "topics" |), "append" |), + make_list [ + M.get_name (| globals, "topic" |) + ], + make_dict [] + |) in + EndFor. + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_LOG" |), + BinOp.mult (| + M.get_name (| globals, "GAS_LOG_DATA" |), + M.get_name (| globals, "size" |) + |) + |), + BinOp.mult (| + M.get_name (| globals, "GAS_LOG_TOPIC" |), + M.get_name (| globals, "num_topics" |) + |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let log_entry := + M.call (| + M.get_name (| globals, "Log" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "logs" |), + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "logs" |), + make_tuple [ M.get_name (| globals, "log_entry" |) ] + |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition log0 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/memory.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/memory.v new file mode 100644 index 0000000..1e1c8b0 --- /dev/null +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/memory.v @@ -0,0 +1,378 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Memory Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM Memory instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". +Axiom memory_memory_write : + IsGlobalAlias globals memory.globals "memory_write". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition mstore : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a word to memory. + This also expands the memory, if the memory is + insufficient to store the word. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "start_position" |); M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + ], + make_dict [] + |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "start_position" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mstore8 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a byte to memory. + This also expands the memory, if the memory is + insufficient to store the word. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "start_position" |); M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let normalized_bytes_value := + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + make_list [ + BinOp.bit_and (| + M.get_name (| globals, "value" |), + Constant.int 255 + |) + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "start_position" |); + M.get_name (| globals, "normalized_bytes_value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Load word from memory. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "start_position" |); M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "start_position" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition msize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the size of active memory in bytes onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/stack.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/stack.v new file mode 100644 index 0000000..1eeda05 --- /dev/null +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/stack.v @@ -0,0 +1,929 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Stack Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM stack related instructions. +". + +Require functools. +Axiom functools_partial : + IsGlobalAlias globals functools.globals "partial". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". +Axiom __init___stack : + IsGlobalAlias globals __init__.globals "stack". + +Require exceptions. +Axiom exceptions_StackUnderflowError : + IsGlobalAlias globals exceptions.globals "StackUnderflowError". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_buffer_read : + IsGlobalAlias globals memory.globals "buffer_read". + +Definition pop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Remove item from stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.pass (| |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition push_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "num_bytes" ] |) in + let _ := Constant.str " + Pushes a N-byte immediate onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + num_bytes : + The number of immediate bytes to be read from the code and pushed to + the stack. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let data_to_push := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "code" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "num_bytes" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "data_to_push" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + BinOp.add (| + Constant.int 1, + M.get_name (| globals, "num_bytes" |) + |) + |) in + M.pure Constant.None_)). + +Definition dup_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "item_number" ] |) in + let _ := Constant.str " + Duplicate the Nth stack item (from top of the stack) to the top of stack. + + Parameters + ---------- + evm : + The current EVM frame. + + item_number : + The stack item number (0-indexed from top of stack) to be duplicated + to the top of stack. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "StackUnderflowError" |) + ], + make_dict [] + |) in + let data_to_duplicate := + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + BinOp.sub (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), + Constant.int 1 + |), + M.get_name (| globals, "item_number" |) + |) |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "data_to_duplicate" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition swap_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "item_number" ] |) in + let _ := Constant.str " + Swap the top and the `item_number` element of the stack, where + the top of the stack is position zero. + + If `item_number` is zero, this function does nothing (which should not be + possible, since there is no `SWAP0` instruction). + + Parameters + ---------- + evm : + The current EVM frame. + + item_number : + The stack item number (0-indexed from top of stack) to be swapped + with the top of stack element. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "StackUnderflowError" |) + ], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) |) ], + make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |) ] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition push1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push5 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push6 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push7 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push8 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push9 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push10 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push11 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push12 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push13 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push14 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push15 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push16 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push17 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push18 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push19 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push20 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push21 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push22 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push23 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push24 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push25 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push26 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push27 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push28 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push29 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push30 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push31 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push32 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition dup1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup5 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup6 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup7 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup8 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup9 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup10 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup11 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup12 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup13 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup14 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup15 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup16 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition swap1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap5 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap6 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap7 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap8 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap9 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap10 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap11 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap12 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap13 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap14 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap15 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap16 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/storage.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/storage.v new file mode 100644 index 0000000..4292e3b --- /dev/null +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/storage.v @@ -0,0 +1,212 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Storage Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM storage related instructions. +". + +Require state. +Axiom state_get_storage : + IsGlobalAlias globals state.globals "get_storage". +Axiom state_set_storage : + IsGlobalAlias globals state.globals "set_storage". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_SLOAD : + IsGlobalAlias globals gas.globals "GAS_SLOAD". +Axiom gas_GAS_STORAGE_CLEAR_REFUND : + IsGlobalAlias globals gas.globals "GAS_STORAGE_CLEAR_REFUND". +Axiom gas_GAS_STORAGE_SET : + IsGlobalAlias globals gas.globals "GAS_STORAGE_SET". +Axiom gas_GAS_STORAGE_UPDATE : + IsGlobalAlias globals gas.globals "GAS_STORAGE_UPDATE". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition sload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Loads to the stack, the value corresponding to a certain key from the + storage of the current account. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let key := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_SLOAD" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "get_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition sstore : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a value at a certain key in the current context's storage. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let key := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let new_value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let current_value := + M.call (| + M.get_name (| globals, "get_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "new_value" |), Constant.int 0 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let gas_cost := + M.get_name (| globals, "GAS_STORAGE_SET" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let gas_cost := + M.get_name (| globals, "GAS_STORAGE_UPDATE" |) in + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_name (| globals, "new_value" |), Constant.int 0 |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "gas_cost" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "set_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |); + M.get_name (| globals, "new_value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/system.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/system.v new file mode 100644 index 0000000..335986d --- /dev/null +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/system.v @@ -0,0 +1,1245 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) System Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM system related instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_account_has_code_or_nonce : + IsGlobalAlias globals state.globals "account_has_code_or_nonce". +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". +Axiom state_increment_nonce : + IsGlobalAlias globals state.globals "increment_nonce". +Axiom state_set_account_balance : + IsGlobalAlias globals state.globals "set_account_balance". + +Require utils.address. +Axiom utils_address_compute_contract_address : + IsGlobalAlias globals utils.address.globals "compute_contract_address". +Axiom utils_address_to_address : + IsGlobalAlias globals utils.address.globals "to_address". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". +Axiom __init___Message : + IsGlobalAlias globals __init__.globals "Message". +Axiom __init___incorporate_child_on_error : + IsGlobalAlias globals __init__.globals "incorporate_child_on_error". +Axiom __init___incorporate_child_on_success : + IsGlobalAlias globals __init__.globals "incorporate_child_on_success". + +Require gas. +Axiom gas_GAS_CALL : + IsGlobalAlias globals gas.globals "GAS_CALL". +Axiom gas_GAS_CREATE : + IsGlobalAlias globals gas.globals "GAS_CREATE". +Axiom gas_GAS_ZERO : + IsGlobalAlias globals gas.globals "GAS_ZERO". +Axiom gas_REFUND_SELF_DESTRUCT : + IsGlobalAlias globals gas.globals "REFUND_SELF_DESTRUCT". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_calculate_message_call_gas : + IsGlobalAlias globals gas.globals "calculate_message_call_gas". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". +Axiom memory_memory_write : + IsGlobalAlias globals memory.globals "memory_write". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition create : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Creates a new account with associated code. + + Parameters + ---------- + evm : + The current EVM frame. + " in +(* At stmt: unsupported node type: ImportFrom *) + let endowment := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_position" |); M.get_name (| globals, "memory_size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_CREATE" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let create_message_gas := + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let sender_address := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in + let sender := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "sender_address" |) + ], + make_dict [] + |) in + let contract_address := + M.call (| + M.get_name (| globals, "compute_contract_address" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "nonce" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt (| M.get_field (| M.get_name (| globals, "sender" |), "balance" |), M.get_name (| globals, "endowment" |) |), + ltac:(M.monadic ( + BoolOp.or (| + Compare.eq (| M.get_field (| M.get_name (| globals, "sender" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.sub (| + BinOp.pow (| + Constant.int 2, + Constant.int 64 + |), + Constant.int 1 + |) + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.gt (| BinOp.add (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "depth" |), + Constant.int 1 + |), M.get_name (| globals, "STACK_DEPTH_LIMIT" |) |) + )) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "create_message_gas" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "contract_address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let call_data := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + let child_message := + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) in + let child_evm := + M.call (| + M.get_name (| globals, "process_create_message" |), + make_list [ + M.get_name (| globals, "child_message" |); + M.get_field (| M.get_name (| globals, "evm" |), "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "child_evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_error" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_success" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition return_ : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Halts execution returning output data. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let memory_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_position" |); M.get_name (| globals, "memory_size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_ZERO" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "running" |), + Constant.bool false + |) in + let _ := M.pass (| |) in + M.pure Constant.None_)). + +Definition generic_call : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "gas"; "value"; "caller"; "to"; "code_address"; "should_transfer_value"; "memory_input_start_position"; "memory_input_size"; "memory_output_start_position"; "memory_output_size" ] |) in + let _ := Constant.str " + Perform the core logic of the `CALL*` family of opcodes. + " in +(* At stmt: unsupported node type: ImportFrom *) + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| BinOp.add (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "depth" |), + Constant.int 1 + |), M.get_name (| globals, "STACK_DEPTH_LIMIT" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "gas" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let call_data := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |) + ], + make_dict [] + |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "code_address" |) + ], + make_dict [] + |), "code" |) in + let child_message := + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) in + let child_evm := + M.call (| + M.get_name (| globals, "process_message" |), + make_list [ + M.get_name (| globals, "child_message" |); + M.get_field (| M.get_name (| globals, "evm" |), "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "child_evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_error" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_success" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let actual_output_size := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_name (| globals, "memory_output_size" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), (* At expr: unsupported node type: NoneType *):M.get_name (| globals, "actual_output_size" |) |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition call : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into an account. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let to := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "gas" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let sender_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "sender_balance" |), M.get_name (| globals, "value" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.get_name (| globals, "value" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "to" |); + Constant.bool true; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition callcode : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into this account with alternative account’s code. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let code_address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let to := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "gas" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let sender_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "sender_balance" |), M.get_name (| globals, "value" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.get_name (| globals, "value" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "code_address" |); + Constant.bool true; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition selfdestruct : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Halt execution and register account for later deletion. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let beneficiary := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let gas_cost := + M.get_name (| globals, "GAS_ZERO" |) in + let originator := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in + let refunded_accounts := + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in + let parent_evm := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "parent_evm" |) in + While Compare.is_not (| M.get_name (| globals, "parent_evm" |), Constant.None_ |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "refunded_accounts" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "parent_evm" |), "accounts_to_delete" |) + ], + make_dict [] + |) in + let parent_evm := + M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in + EndWhile. + let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| M.get_name (| globals, "originator" |), M.get_name (| globals, "refunded_accounts" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.get_name (| globals, "REFUND_SELF_DESTRUCT" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "gas_cost" |) + ], + make_dict [] + |) in + let beneficiary_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |), "balance" |) in + let originator_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "originator" |) + ], + make_dict [] + |), "balance" |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |); + BinOp.add (| + M.get_name (| globals, "beneficiary_balance" |), + M.get_name (| globals, "originator_balance" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "originator" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |), "add" |), + make_list [ + M.get_name (| globals, "originator" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "running" |), + Constant.bool false + |) in + let _ := M.pass (| |) in + M.pure Constant.None_)). + +Definition delegatecall : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into an account. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let code_address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_CALL" |), + M.get_name (| globals, "gas" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "gas" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "value" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "caller" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "code_address" |); + Constant.bool false; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/vm/interpreter.v b/CoqOfPython/ethereum/dao_fork/vm/interpreter.v new file mode 100644 index 0000000..85a383f --- /dev/null +++ b/CoqOfPython/ethereum/dao_fork/vm/interpreter.v @@ -0,0 +1,543 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Interpreter +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +A straightforward interpreter that executes EVM code. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.trace. +Axiom ethereum_trace_EvmStop : + IsGlobalAlias globals ethereum.trace.globals "EvmStop". +Axiom ethereum_trace_OpEnd : + IsGlobalAlias globals ethereum.trace.globals "OpEnd". +Axiom ethereum_trace_OpException : + IsGlobalAlias globals ethereum.trace.globals "OpException". +Axiom ethereum_trace_OpStart : + IsGlobalAlias globals ethereum.trace.globals "OpStart". +Axiom ethereum_trace_PrecompileEnd : + IsGlobalAlias globals ethereum.trace.globals "PrecompileEnd". +Axiom ethereum_trace_PrecompileStart : + IsGlobalAlias globals ethereum.trace.globals "PrecompileStart". +Axiom ethereum_trace_TransactionEnd : + IsGlobalAlias globals ethereum.trace.globals "TransactionEnd". +Axiom ethereum_trace_evm_trace : + IsGlobalAlias globals ethereum.trace.globals "evm_trace". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_account_has_code_or_nonce : + IsGlobalAlias globals state.globals "account_has_code_or_nonce". +Axiom state_begin_transaction : + IsGlobalAlias globals state.globals "begin_transaction". +Axiom state_commit_transaction : + IsGlobalAlias globals state.globals "commit_transaction". +Axiom state_move_ether : + IsGlobalAlias globals state.globals "move_ether". +Axiom state_rollback_transaction : + IsGlobalAlias globals state.globals "rollback_transaction". +Axiom state_set_code : + IsGlobalAlias globals state.globals "set_code". +Axiom state_touch_account : + IsGlobalAlias globals state.globals "touch_account". + +Require vm. +Axiom vm_Message : + IsGlobalAlias globals vm.globals "Message". + +Require vm.gas. +Axiom vm_gas_GAS_CODE_DEPOSIT : + IsGlobalAlias globals vm.gas.globals "GAS_CODE_DEPOSIT". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require vm.precompiled_contracts.mapping. +Axiom vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : + IsGlobalAlias globals vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". + +Require __init__. +Axiom __init___Environment : + IsGlobalAlias globals __init__.globals "Environment". +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_AddressCollision : + IsGlobalAlias globals exceptions.globals "AddressCollision". +Axiom exceptions_ExceptionalHalt : + IsGlobalAlias globals exceptions.globals "ExceptionalHalt". +Axiom exceptions_InvalidOpcode : + IsGlobalAlias globals exceptions.globals "InvalidOpcode". +Axiom exceptions_StackDepthLimitError : + IsGlobalAlias globals exceptions.globals "StackDepthLimitError". + +Require instructions. +Axiom instructions_Ops : + IsGlobalAlias globals instructions.globals "Ops". +Axiom instructions_op_implementation : + IsGlobalAlias globals instructions.globals "op_implementation". + +Require runtime. +Axiom runtime_get_valid_jump_destinations : + IsGlobalAlias globals runtime.globals "get_valid_jump_destinations". + +Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1024 + ], + make_dict [] + |) +)). + +Definition MessageCallOutput : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition process_message_call : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + If `message.current` is empty then it creates a smart contract + else it executes a call from the `message.caller` to the `message.target`. + + Parameters + ---------- + message : + Transaction specific items. + + env : + External items required for EVM execution. + + Returns + ------- + output : `MessageCallOutput` + Output of the message call + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_name (| globals, "message" |), "target" |), M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let is_collision := + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_name (| globals, "is_collision" |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallOutput" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "tuple" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "AddressCollision" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let evm := + M.call (| + M.get_name (| globals, "process_create_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let evm := + M.call (| + M.get_name (| globals, "process_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( +(* At stmt: unsupported node type: AnnAssign *) + let accounts_to_delete := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let refund_counter := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let logs := + M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in + let accounts_to_delete := + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in + let refund_counter := + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |) in + M.pure Constant.None_ + )) |) in + let tx_end := + M.call (| + M.get_name (| globals, "TransactionEnd" |), + make_list [ + BinOp.sub (| + M.get_field (| M.get_name (| globals, "message" |), "gas" |), + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + |); + M.get_field (| M.get_name (| globals, "evm" |), "output" |); + M.get_field (| M.get_name (| globals, "evm" |), "error" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "evm_trace" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "tx_end" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallOutput" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition process_create_message : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + Executes a call to create a smart contract. + + Parameters + ---------- + message : + Transaction specific items. + env : + External items required for EVM execution. + + Returns + ------- + evm: :py:class:`~ethereum.dao_fork.vm.Evm` + Items containing execution specific objects. + " in + let _ := M.call (| + M.get_name (| globals, "begin_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + let evm := + M.call (| + M.get_name (| globals, "process_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), + (* then *) + ltac:(M.monadic ( + let contract_code := + M.get_field (| M.get_name (| globals, "evm" |), "output" |) in + let contract_code_gas := + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "contract_code" |) + ], + make_dict [] + |), + M.get_name (| globals, "GAS_CODE_DEPOSIT" |) + |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "rollback_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.get_name (| globals, "evm" |) + |) in + M.pure Constant.None_)). + +Definition process_message : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + Executes a call to create a smart contract. + + Parameters + ---------- + message : + Transaction specific items. + env : + External items required for EVM execution. + + Returns + ------- + evm: :py:class:`~ethereum.dao_fork.vm.Evm` + Items containing execution specific objects + " in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_field (| M.get_name (| globals, "message" |), "depth" |), M.get_name (| globals, "STACK_DEPTH_LIMIT" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "StackDepthLimitError" |), + make_list [ + Constant.str "Stack depth limit reached" + ], + make_dict [] + |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "begin_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "touch_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + M.get_field (| M.get_name (| globals, "message" |), "should_transfer_value" |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_field (| M.get_name (| globals, "message" |), "value" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "move_ether" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "caller" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |); + M.get_field (| M.get_name (| globals, "message" |), "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let evm := + M.call (| + M.get_name (| globals, "execute_code" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "rollback_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "commit_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.get_name (| globals, "evm" |) + |) in + M.pure Constant.None_)). + +Definition execute_code : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + Executes bytecode present in the `message`. + + Parameters + ---------- + message : + Transaction specific items. + env : + External items required for EVM execution. + + Returns + ------- + evm: `ethereum.vm.EVM` + Items containing execution specific objects + " in + let code := + M.get_field (| M.get_name (| globals, "message" |), "code" |) in + let valid_jump_destinations := + M.call (| + M.get_name (| globals, "get_valid_jump_destinations" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) in + let evm := + M.call (| + M.get_name (| globals, "Evm" |), + make_list [], + make_dict [] + |) in +(* At stmt: unsupported node type: Try *) + let _ := M.return_ (| + M.get_name (| globals, "evm" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/vm/memory.v b/CoqOfPython/ethereum/dao_fork/vm/memory.v new file mode 100644 index 0000000..fa8d906 --- /dev/null +++ b/CoqOfPython/ethereum/dao_fork/vm/memory.v @@ -0,0 +1,153 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Memory +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +EVM memory operations. +". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_right_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "right_pad_zero_bytes". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". + +Definition memory_write : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "memory"; "start_position"; "value" ] |) in + let _ := Constant.str " + Writes to memory. + + Parameters + ---------- + memory : + Memory contents of the EVM. + start_position : + Starting pointer to the memory. + value : + Data to write to memory. + " in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) |), + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_)). + +Definition memory_read_bytes : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "memory"; "start_position"; "size" ] |) in + let _ := Constant.str " + Read bytes from memory. + + Parameters + ---------- + memory : + Memory contents of the EVM. + start_position : + Starting pointer to the memory. + size : + Size of the data that needs to be read from `start_position`. + + Returns + ------- + data_bytes : + Data read from memory. + " in + let _ := M.return_ (| + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |) + |) in + M.pure Constant.None_)). + +Definition buffer_read : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "buffer"; "start_position"; "size" ] |) in + let _ := Constant.str " + Read bytes from a buffer. Padding with zeros if necessary. + + Parameters + ---------- + buffer : + Memory contents of the EVM. + start_position : + Starting pointer to the memory. + size : + Size of the data that needs to be read from `start_position`. + + Returns + ------- + data_bytes : + Data read from memory. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "right_pad_zero_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/__init__.v new file mode 100644 index 0000000..422f670 --- /dev/null +++ b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/__init__.v @@ -0,0 +1,67 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Precompiled Contract Addresses +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Addresses of precompiled contracts and mappings to their +implementations. +". + +Require utils.hexadecimal. +Axiom utils_hexadecimal_hex_to_address : + IsGlobalAlias globals utils.hexadecimal.globals "hex_to_address". + +Definition __all__ : Value.t := M.run ltac:(M.monadic ( + make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS" ] +)). + +Definition ECRECOVER_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x01" + ], + make_dict [] + |) +)). + +Definition SHA256_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x02" + ], + make_dict [] + |) +)). + +Definition RIPEMD160_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x03" + ], + make_dict [] + |) +)). + +Definition IDENTITY_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x04" + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/ecrecover.v new file mode 100644 index 0000000..cc351b5 --- /dev/null +++ b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/ecrecover.v @@ -0,0 +1,269 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) ECRECOVER PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the ECRECOVER precompiled contract. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require ethereum.crypto.elliptic_curve. +Axiom ethereum_crypto_elliptic_curve_SECP256K1N : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_left_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_ECRECOVER : + IsGlobalAlias globals vm.gas.globals "GAS_ECRECOVER". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require vm.memory. +Axiom vm_memory_buffer_read : + IsGlobalAlias globals vm.memory.globals "buffer_read". + +Definition ecrecover : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Decrypts the address using elliptic curve DSA recovery mechanism and writes + the address to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_ECRECOVER" |) + ], + make_dict [] + |) in + let message_hash_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let message_hash := + M.call (| + M.get_name (| globals, "Hash32" |), + make_list [ + M.get_name (| globals, "message_hash_bytes" |) + ], + make_dict [] + |) in + let v := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let r := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let s := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 27 |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 28 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| Constant.int 0, M.get_name (| globals, "r" |) |), + ltac:(M.monadic ( + Compare.gt_e (| M.get_name (| globals, "r" |), M.get_name (| globals, "SECP256K1N" |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| Constant.int 0, M.get_name (| globals, "s" |) |), + ltac:(M.monadic ( + Compare.gt_e (| M.get_name (| globals, "s" |), M.get_name (| globals, "SECP256K1N" |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in +(* At stmt: unsupported node type: Try *) + let address := + M.get_subscript (| M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), Constant.int 12:Constant.int 32 |) in + let padded_address := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "address" |); + Constant.int 32 + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.get_name (| globals, "padded_address" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/identity.v new file mode 100644 index 0000000..fa96704 --- /dev/null +++ b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/identity.v @@ -0,0 +1,94 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) IDENTITY PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `IDENTITY` precompiled contract. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_IDENTITY : + IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY". +Axiom vm_gas_GAS_IDENTITY_WORD : + IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY_WORD". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition identity : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the message data to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let word_count := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_IDENTITY" |), + BinOp.mult (| + M.get_name (| globals, "GAS_IDENTITY_WORD" |), + M.get_name (| globals, "word_count" |) + |) + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.get_name (| globals, "data" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/mapping.v new file mode 100644 index 0000000..710457d --- /dev/null +++ b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/mapping.v @@ -0,0 +1,56 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Precompiled Contract Addresses +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Mapping of precompiled contracts their implementations. +". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require __init__. +Axiom __init___ECRECOVER_ADDRESS : + IsGlobalAlias globals __init__.globals "ECRECOVER_ADDRESS". +Axiom __init___IDENTITY_ADDRESS : + IsGlobalAlias globals __init__.globals "IDENTITY_ADDRESS". +Axiom __init___RIPEMD160_ADDRESS : + IsGlobalAlias globals __init__.globals "RIPEMD160_ADDRESS". +Axiom __init___SHA256_ADDRESS : + IsGlobalAlias globals __init__.globals "SHA256_ADDRESS". + +Require ecrecover. +Axiom ecrecover_ecrecover : + IsGlobalAlias globals ecrecover.globals "ecrecover". + +Require identity. +Axiom identity_identity : + IsGlobalAlias globals identity.globals "identity". + +Require ripemd160. +Axiom ripemd160_ripemd160 : + IsGlobalAlias globals ripemd160.globals "ripemd160". + +Require sha256. +Axiom sha256_sha256 : + IsGlobalAlias globals sha256.globals "sha256". + +(* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/ripemd160.v new file mode 100644 index 0000000..96f8dcd --- /dev/null +++ b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/ripemd160.v @@ -0,0 +1,122 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) RIPEMD160 PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `RIPEMD160` precompiled contract. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_left_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_RIPEMD160 : + IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160". +Axiom vm_gas_GAS_RIPEMD160_WORD : + IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160_WORD". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition ripemd160 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the ripemd160 hash to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let word_count := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_RIPEMD160" |), + BinOp.mult (| + M.get_name (| globals, "GAS_RIPEMD160_WORD" |), + M.get_name (| globals, "word_count" |) + |) + |) + ], + make_dict [] + |) in + let hash_bytes := + M.call (| + M.get_field (| M.call (| + M.get_field (| M.get_name (| globals, "hashlib" |), "new" |), + make_list [ + Constant.str "ripemd160"; + M.get_name (| globals, "data" |) + ], + make_dict [] + |), "digest" |), + make_list [], + make_dict [] + |) in + let padded_hash := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "hash_bytes" |); + Constant.int 32 + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.get_name (| globals, "padded_hash" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/sha256.v new file mode 100644 index 0000000..9f6d2bf --- /dev/null +++ b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/sha256.v @@ -0,0 +1,106 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) SHA256 PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `SHA256` precompiled contract. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_SHA256 : + IsGlobalAlias globals vm.gas.globals "GAS_SHA256". +Axiom vm_gas_GAS_SHA256_WORD : + IsGlobalAlias globals vm.gas.globals "GAS_SHA256_WORD". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition sha256 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the sha256 hash to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let word_count := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_SHA256" |), + BinOp.mult (| + M.get_name (| globals, "GAS_SHA256_WORD" |), + M.get_name (| globals, "word_count" |) + |) + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_field (| M.get_name (| globals, "hashlib" |), "sha256" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), "digest" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/vm/runtime.v b/CoqOfPython/ethereum/dao_fork/vm/runtime.v new file mode 100644 index 0000000..835b46c --- /dev/null +++ b/CoqOfPython/ethereum/dao_fork/vm/runtime.v @@ -0,0 +1,125 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Runtime Operations +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Runtime related operations used while executing EVM code. +". + +Require typing. +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require instructions. +Axiom instructions_Ops : + IsGlobalAlias globals instructions.globals "Ops". + +Definition get_valid_jump_destinations : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "code" ] |) in + let _ := Constant.str " + Analyze the evm code to obtain the set of valid jump destinations. + + Valid jump destinations are defined as follows: + * The jump destination is less than the length of the code. + * The jump destination should have the `JUMPDEST` opcode (0x5B). + * The jump destination shouldn't be part of the data corresponding to + `PUSH-N` opcodes. + + Note - Jump destinations are 0-indexed. + + Parameters + ---------- + code : + The EVM code which is to be executed. + + Returns + ------- + valid_jump_destinations: `Set[Uint]` + The set of valid jump destinations in the code. + " in + let valid_jump_destinations := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let pc := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + While Compare.lt (| M.get_name (| globals, "pc" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) |) do +(* At stmt: unsupported node type: Try *) + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "current_opcode" |), M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), + make_list [ + M.get_name (| globals, "pc" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + (* At expr: unsupported node type: Compare *), + (* then *) + ltac:(M.monadic ( + let push_data_size := + BinOp.add (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) + |), + Constant.int 1 + |) in + let pc := BinOp.add + M.get_name (| globals, "push_data_size" |) + M.get_name (| globals, "push_data_size" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let pc := BinOp.add + Constant.int 1 + Constant.int 1 in + EndWhile. + let _ := M.return_ (| + M.get_name (| globals, "valid_jump_destinations" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/vm/stack.v b/CoqOfPython/ethereum/dao_fork/vm/stack.v new file mode 100644 index 0000000..42ea42d --- /dev/null +++ b/CoqOfPython/ethereum/dao_fork/vm/stack.v @@ -0,0 +1,120 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Stack +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the stack operators for the EVM. +". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require exceptions. +Axiom exceptions_StackOverflowError : + IsGlobalAlias globals exceptions.globals "StackOverflowError". +Axiom exceptions_StackUnderflowError : + IsGlobalAlias globals exceptions.globals "StackUnderflowError". + +Definition pop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "stack" ] |) in + let _ := Constant.str " + Pops the top item off of `stack`. + + Parameters + ---------- + stack : + EVM stack. + + Returns + ------- + value : `U256` + The top element on the stack. + + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "StackUnderflowError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "pop" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition push : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "stack"; "value" ] |) in + let _ := Constant.str " + Pushes `value` onto `stack`. + + Parameters + ---------- + stack : + EVM stack. + + value : + Item to be pushed onto `stack`. + + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), Constant.int 1024 |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "StackOverflowError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "append" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/ethash.v b/CoqOfPython/ethereum/ethash.v new file mode 100644 index 0000000..afff624 --- /dev/null +++ b/CoqOfPython/ethereum/ethash.v @@ -0,0 +1,1069 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethash is a proof-of-work algorithm designed to be [ASIC] resistant through +[memory hardness][mem-hard]. + +To achieve memory hardness, computing Ethash requires access to subsets of a +large structure. The particular subsets chosen are based on the nonce and block +header, while the set itself is changed every [`epoch`]. + +At a high level, the Ethash algorithm is as follows: + +1. Create a **seed** value, generated with [`generate_seed`] and based on the + preceding block numbers. +1. From the seed, compute a pseudorandom **cache** with [`generate_cache`]. +1. From the cache, generate a **dataset** with [`generate_dataset`]. The + dataset grows over time based on [`DATASET_EPOCH_GROWTH_SIZE`]. +1. Miners hash slices of the dataset together, which is where the memory + hardness is introduced. Verification of the proof-of-work only requires the + cache to be able to recompute a much smaller subset of the full dataset. + +[`DATASET_EPOCH_GROWTH_SIZE`]: ref:ethereum.ethash.DATASET_EPOCH_GROWTH_SIZE +[`generate_dataset`]: ref:ethereum.ethash.generate_dataset +[`generate_cache`]: ref:ethereum.ethash.generate_cache +[`generate_seed`]: ref:ethereum.ethash.generate_seed +[`epoch`]: ref:ethereum.ethash.epoch +[ASIC]: https://en.wikipedia.org/wiki/Application-specific_integrated_circuit +[mem-hard]: https://en.wikipedia.org/wiki/Memory-hard_function +". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U32 : + IsGlobalAlias globals ethereum.base_types.globals "U32". +Axiom ethereum_base_types_Bytes8 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes8". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_Hash64 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash64". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_keccak512 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak512". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_is_prime : + IsGlobalAlias globals ethereum.utils.numeric.globals "is_prime". +Axiom ethereum_utils_numeric_le_bytes_to_uint32_sequence : + IsGlobalAlias globals ethereum.utils.numeric.globals "le_bytes_to_uint32_sequence". +Axiom ethereum_utils_numeric_le_uint32_sequence_to_bytes : + IsGlobalAlias globals ethereum.utils.numeric.globals "le_uint32_sequence_to_bytes". +Axiom ethereum_utils_numeric_le_uint32_sequence_to_uint : + IsGlobalAlias globals ethereum.utils.numeric.globals "le_uint32_sequence_to_uint". + +Definition EPOCH_SIZE : Value.t := M.run ltac:(M.monadic ( + Constant.int 30000 +)). + +Definition expr_41 : Value.t := + Constant.str " +Number of blocks before a dataset needs to be regenerated (known as an +"""epoch""".) See [`epoch`]. + +[`epoch`]: ref:ethereum.ethash.epoch +". + +Definition INITIAL_CACHE_SIZE : Value.t := M.run ltac:(M.monadic ( + BinOp.pow (| + Constant.int 2, + Constant.int 24 + |) +)). + +Definition expr_49 : Value.t := + Constant.str " +Size of the cache (in bytes) during the first epoch. Each subsequent epoch's +cache roughly grows by [`CACHE_EPOCH_GROWTH_SIZE`] bytes. See [`cache_size`]. + +[`CACHE_EPOCH_GROWTH_SIZE`]: ref:ethereum.ethash.CACHE_EPOCH_GROWTH_SIZE +[`cache_size`]: ref:ethereum.ethash.cache_size +". + +Definition CACHE_EPOCH_GROWTH_SIZE : Value.t := M.run ltac:(M.monadic ( + BinOp.pow (| + Constant.int 2, + Constant.int 17 + |) +)). + +Definition expr_58 : Value.t := + Constant.str " +After the first epoch, the cache size grows by roughly this amount. See +[`cache_size`]. + +[`cache_size`]: ref:ethereum.ethash.cache_size +". + +Definition INITIAL_DATASET_SIZE : Value.t := M.run ltac:(M.monadic ( + BinOp.pow (| + Constant.int 2, + Constant.int 30 + |) +)). + +Definition expr_66 : Value.t := + Constant.str " +Size of the dataset (in bytes) during the first epoch. Each subsequent epoch's +dataset roughly grows by [`DATASET_EPOCH_GROWTH_SIZE`] bytes. See +[`dataset_size`]. + +[`DATASET_EPOCH_GROWTH_SIZE`]: ref:ethereum.ethash.DATASET_EPOCH_GROWTH_SIZE +[`dataset_size`]: ref:ethereum.ethash.dataset_size +". + +Definition DATASET_EPOCH_GROWTH_SIZE : Value.t := M.run ltac:(M.monadic ( + BinOp.pow (| + Constant.int 2, + Constant.int 23 + |) +)). + +Definition expr_76 : Value.t := + Constant.str " +After the first epoch, the dataset size grows by roughly this amount. See +[`dataset_size`]. + +[`dataset_size`]: ref:ethereum.ethash.dataset_size +". + +Definition HASH_BYTES : Value.t := M.run ltac:(M.monadic ( + Constant.int 64 +)). + +Definition expr_84 : Value.t := + Constant.str " +Length of a hash, in bytes. +". + +Definition MIX_BYTES : Value.t := M.run ltac:(M.monadic ( + Constant.int 128 +)). + +Definition expr_89 : Value.t := + Constant.str " +Width of mix, in bytes. See [`generate_dataset_item`]. + +[`generate_dataset_item`]: ref:ethereum.ethash.generate_dataset_item +". + +Definition CACHE_ROUNDS : Value.t := M.run ltac:(M.monadic ( + Constant.int 3 +)). + +Definition expr_96 : Value.t := + Constant.str " +Number of times to repeat the [`keccak512`] step while generating the hash. See +[`generate_cache`]. + +[`keccak512`]: ref:ethereum.crypto.hash.keccak512 +[`generate_cache`]: ref:ethereum.ethash.generate_cache +". + +Definition DATASET_PARENTS : Value.t := M.run ltac:(M.monadic ( + Constant.int 256 +)). + +Definition expr_105 : Value.t := + Constant.str " +Number of parents of each dataset element. See [`generate_dataset_item`]. + +[`generate_dataset_item`]: ref:ethereum.ethash.generate_dataset_item +". + +Definition HASHIMOTO_ACCESSES : Value.t := M.run ltac:(M.monadic ( + Constant.int 64 +)). + +Definition expr_112 : Value.t := + Constant.str " +Number of accesses in the [`hashimoto`] loop. + +[`hashimoto`]: ref:ethereum.ethash.hashimoto +". + +Definition epoch : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "block_number" ] |) in + let _ := Constant.str " + Obtain the epoch number to which the block identified by `block_number` + belongs. The first epoch is numbered zero. + + An Ethash epoch is a fixed number of blocks ([`EPOCH_SIZE`]) long, during + which the dataset remains constant. At the end of each epoch, the dataset + is generated anew. See [`generate_dataset`]. + + [`EPOCH_SIZE`]: ref:ethereum.ethash.EPOCH_SIZE + [`generate_dataset`]: ref:ethereum.ethash.generate_dataset + " in + let _ := M.return_ (| + BinOp.floor_div (| + M.get_name (| globals, "block_number" |), + M.get_name (| globals, "EPOCH_SIZE" |) + |) + |) in + M.pure Constant.None_)). + +Definition cache_size : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "block_number" ] |) in + let _ := Constant.str " + Obtain the cache size (in bytes) of the epoch to which `block_number` + belongs. + + See [`INITIAL_CACHE_SIZE`] and [`CACHE_EPOCH_GROWTH_SIZE`] for the initial + size and linear growth rate, respectively. The cache is generated in + [`generate_cache`]. + + The actual cache size is smaller than simply multiplying + `CACHE_EPOCH_GROWTH_SIZE` by the epoch number to minimize the risk of + unintended cyclic behavior. It is defined as the highest prime number below + what linear growth would calculate. + + [`INITIAL_CACHE_SIZE`]: ref:ethereum.ethash.INITIAL_CACHE_SIZE + [`CACHE_EPOCH_GROWTH_SIZE`]: ref:ethereum.ethash.CACHE_EPOCH_GROWTH_SIZE + [`generate_cache`]: ref:ethereum.ethash.generate_cache + " in + let size := + BinOp.add (| + M.get_name (| globals, "INITIAL_CACHE_SIZE" |), + BinOp.mult (| + M.get_name (| globals, "CACHE_EPOCH_GROWTH_SIZE" |), + M.call (| + M.get_name (| globals, "epoch" |), + make_list [ + M.get_name (| globals, "block_number" |) + ], + make_dict [] + |) + |) + |) in + let size := BinOp.sub + M.get_name (| globals, "HASH_BYTES" |) + M.get_name (| globals, "HASH_BYTES" |) in + While UnOp.not (| M.call (| + M.get_name (| globals, "is_prime" |), + make_list [ + BinOp.floor_div (| + M.get_name (| globals, "size" |), + M.get_name (| globals, "HASH_BYTES" |) + |) + ], + make_dict [] + |) |) do + let size := BinOp.sub + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "HASH_BYTES" |) + |) + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "HASH_BYTES" |) + |) in + EndWhile. + let _ := M.return_ (| + M.get_name (| globals, "size" |) + |) in + M.pure Constant.None_)). + +Definition dataset_size : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "block_number" ] |) in + let _ := Constant.str " + Obtain the dataset size (in bytes) of the epoch to which `block_number` + belongs. + + See [`INITIAL_DATASET_SIZE`] and [`DATASET_EPOCH_GROWTH_SIZE`][ds] for the + initial size and linear growth rate, respectively. The complete dataset is + generated in [`generate_dataset`], while the slices used in verification + are generated in [`generate_dataset_item`]. + + The actual dataset size is smaller than simply multiplying + `DATASET_EPOCH_GROWTH_SIZE` by the epoch number to minimize the risk of + unintended cyclic behavior. It is defined as the highest prime number below + what linear growth would calculate. + + [`INITIAL_DATASET_SIZE`]: ref:ethereum.ethash.INITIAL_DATASET_SIZE + [ds]: ref:ethereum.ethash.DATASET_EPOCH_GROWTH_SIZE + [`generate_dataset`]: ref:ethereum.ethash.generate_dataset + [`generate_dataset_item`]: ref:ethereum.ethash.generate_dataset_item + " in + let size := + BinOp.add (| + M.get_name (| globals, "INITIAL_DATASET_SIZE" |), + BinOp.mult (| + M.get_name (| globals, "DATASET_EPOCH_GROWTH_SIZE" |), + M.call (| + M.get_name (| globals, "epoch" |), + make_list [ + M.get_name (| globals, "block_number" |) + ], + make_dict [] + |) + |) + |) in + let size := BinOp.sub + M.get_name (| globals, "MIX_BYTES" |) + M.get_name (| globals, "MIX_BYTES" |) in + While UnOp.not (| M.call (| + M.get_name (| globals, "is_prime" |), + make_list [ + BinOp.floor_div (| + M.get_name (| globals, "size" |), + M.get_name (| globals, "MIX_BYTES" |) + |) + ], + make_dict [] + |) |) do + let size := BinOp.sub + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "MIX_BYTES" |) + |) + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "MIX_BYTES" |) + |) in + EndWhile. + let _ := M.return_ (| + M.get_name (| globals, "size" |) + |) in + M.pure Constant.None_)). + +Definition generate_seed : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "block_number" ] |) in + let _ := Constant.str " + Obtain the cache generation seed for the block identified by + `block_number`. See [`generate_cache`]. + + [`generate_cache`]: ref:ethereum.ethash.generate_cache + " in + let epoch_number := + M.call (| + M.get_name (| globals, "epoch" |), + make_list [ + M.get_name (| globals, "block_number" |) + ], + make_dict [] + |) in + let seed := + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + Constant.int 32 + |) in + While Compare.not_eq (| M.get_name (| globals, "epoch_number" |), Constant.int 0 |) do + let seed := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "seed" |) + ], + make_dict [] + |) in + let epoch_number := BinOp.sub + Constant.int 1 + Constant.int 1 in + EndWhile. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Hash32" |), + make_list [ + M.get_name (| globals, "seed" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition generate_cache : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "block_number" ] |) in + let _ := Constant.str " + Generate the cache for the block identified by `block_number`. See + [`generate_dataset`] for how the cache is used. + + The cache is generated in two steps: filling the array with a chain of + [`keccak512`] hashes, then running two rounds of Sergio Demian Lerner's + [RandMemoHash] on those bytes. + + [`keccak512`]: ref:ethereum.crypto.hash.keccak512 + [`generate_dataset`]: ref:ethereum.ethash.generate_dataset + [RandMemoHash]: http://www.hashcash.org/papers/memohash.pdf + " in + let seed := + M.call (| + M.get_name (| globals, "generate_seed" |), + make_list [ + M.get_name (| globals, "block_number" |) + ], + make_dict [] + |) in + let cache_size_bytes := + M.call (| + M.get_name (| globals, "cache_size" |), + make_list [ + M.get_name (| globals, "block_number" |) + ], + make_dict [] + |) in + let cache_size_words := + BinOp.floor_div (| + M.get_name (| globals, "cache_size_bytes" |), + M.get_name (| globals, "HASH_BYTES" |) + |) in + let cache := + make_list [ + M.call (| + M.get_name (| globals, "keccak512" |), + make_list [ + M.get_name (| globals, "seed" |) + ], + make_dict [] + |) + ] in + For M.get_name (| globals, "index" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 1; + M.get_name (| globals, "cache_size_words" |) + ], + make_dict [] + |) do + let cache_item := + M.call (| + M.get_name (| globals, "keccak512" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "cache" |), BinOp.sub (| + M.get_name (| globals, "index" |), + Constant.int 1 + |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "cache" |), "append" |), + make_list [ + M.get_name (| globals, "cache_item" |) + ], + make_dict [] + |) in + EndFor. + For M.get_name (| globals, "_" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "CACHE_ROUNDS" |) + ], + make_dict [] + |) do + For M.get_name (| globals, "index" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "cache_size_words" |) + ], + make_dict [] + |) do + let first_cache_item := + M.get_subscript (| M.get_name (| globals, "cache" |), BinOp.mod_ (| + BinOp.add (| + BinOp.sub (| + M.get_name (| globals, "index" |), + Constant.int 1 + |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "cache_size_words" |) + ], + make_dict [] + |) + |), + M.get_name (| globals, "cache_size_words" |) + |) |) in + let second_cache_item := + M.get_subscript (| M.get_name (| globals, "cache" |), BinOp.mod_ (| + M.call (| + M.get_field (| M.get_name (| globals, "U32" |), "from_le_bytes" |), + make_list [ + M.get_subscript (| M.get_subscript (| M.get_name (| globals, "cache" |), M.get_name (| globals, "index" |) |), Constant.int 0:Constant.int 4 |) + ], + make_dict [] + |), + M.get_name (| globals, "cache_size_words" |) + |) |) in + let result := + M.call (| + M.get_name (| globals, "bytes" |), + make_list [ + [BinOp.bit_xor (| + M.get_name (| globals, "a" |), + M.get_name (| globals, "b" |) + |) for (* At expr: unsupported node type: list *)] + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "cache" |), M.get_name (| globals, "index" |) |), + M.call (| + M.get_name (| globals, "keccak512" |), + make_list [ + M.get_name (| globals, "result" |) + ], + make_dict [] + |) + |) in + EndFor. + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "tuple" |), + make_list [ + (M.call (| + M.get_name (| globals, "le_bytes_to_uint32_sequence" |), + make_list [ + M.get_name (| globals, "cache_item" |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition fnv : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "a"; "b" ] |) in + let _ := Constant.str " + A non-associative substitute for XOR, inspired by the [FNV] hash by Fowler, + Noll, and Vo. See [`fnv_hash`], [`generate_dataset_item`], and + [`hashimoto`]. + + Note that here we multiply the prime with the full 32-bit input, in + contrast with the [FNV-1] spec which multiplies the prime with one byte + (octet) in turn. + + [`hashimoto`]: ref:ethereum.ethash.hashimoto + [`generate_dataset_item`]: ref:ethereum.ethash.generate_dataset_item + [`fnv_hash`]: ref:ethereum.ethash.fnv_hash + [FNV]: https://w.wiki/XKZ + [FNV-1]: http://www.isthe.com/chongo/tech/comp/fnv/#FNV-1 + " in + let result := + BinOp.bit_and (| + BinOp.bit_xor (| + BinOp.mult (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |), + Constant.int 16777619 + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) + |), + M.get_field (| M.get_name (| globals, "U32" |), "MAX_VALUE" |) + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U32" |), + make_list [ + M.get_name (| globals, "result" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition fnv_hash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "mix_integers"; "data" ] |) in + let _ := Constant.str " + Combines `data` into `mix_integers` using [`fnv`]. See [`hashimoto`] and + [`generate_dataset_item`]. + + [`hashimoto`]: ref:ethereum.ethash.hashimoto + [`generate_dataset_item`]: ref:ethereum.ethash.generate_dataset_item + [`fnv`]: ref:ethereum.ethash.fnv + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "tuple" |), + make_list [ + (M.call (| + M.get_name (| globals, "fnv" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "mix_integers" |), M.get_name (| globals, "i" |) |); + M.get_subscript (| M.get_name (| globals, "data" |), M.get_name (| globals, "i" |) |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition generate_dataset_item : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "cache"; "index" ] |) in + let _ := Constant.str " + Generate a particular dataset item 0-indexed by `index` by hashing + pseudorandomly-selected entries from `cache` together. See [`fnv`] and + [`fnv_hash`] for the digest function, [`generate_cache`] for generating + `cache`, and [`generate_dataset`] for the full dataset generation + algorithm. + + [`fnv`]: ref:ethereum.ethash.fnv + [`fnv_hash`]: ref:ethereum.ethash.fnv_hash + [`generate_dataset`]: ref:ethereum.ethash.generate_dataset + [`generate_cache`]: ref:ethereum.ethash.generate_cache + " in + let mix := + M.call (| + M.get_name (| globals, "keccak512" |), + make_list [ + M.call (| + M.get_field (| BinOp.bit_xor (| + M.call (| + M.get_name (| globals, "le_uint32_sequence_to_uint" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "cache" |), BinOp.mod_ (| + M.get_name (| globals, "index" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "cache" |) + ], + make_dict [] + |) + |) |) + ], + make_dict [] + |), + M.get_name (| globals, "index" |) + |), "to_le_bytes" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) in + let mix_integers := + M.call (| + M.get_name (| globals, "le_bytes_to_uint32_sequence" |), + make_list [ + M.get_name (| globals, "mix" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "j" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "DATASET_PARENTS" |) + ], + make_dict [] + |) do +(* At stmt: unsupported node type: AnnAssign *) + let cache_index := + BinOp.mod_ (| + M.call (| + M.get_name (| globals, "fnv" |), + make_list [ + BinOp.bit_xor (| + M.get_name (| globals, "index" |), + M.get_name (| globals, "j" |) + |); + M.get_name (| globals, "mix_word" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "cache" |) + ], + make_dict [] + |) + |) in + let parent := + M.get_subscript (| M.get_name (| globals, "cache" |), M.get_name (| globals, "cache_index" |) |) in + let mix_integers := + M.call (| + M.get_name (| globals, "fnv_hash" |), + make_list [ + M.get_name (| globals, "mix_integers" |); + M.get_name (| globals, "parent" |) + ], + make_dict [] + |) in + EndFor. + let mix := + M.call (| + M.get_name (| globals, "Hash64" |), + make_list [ + M.call (| + M.get_name (| globals, "le_uint32_sequence_to_bytes" |), + make_list [ + M.get_name (| globals, "mix_integers" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak512" |), + make_list [ + M.get_name (| globals, "mix" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition generate_dataset : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "block_number" ] |) in + let _ := Constant.str " + Generate the full dataset for the block identified by `block_number`. + + This function is present only for demonstration purposes. It is not used + while validating blocks. + " in +(* At stmt: unsupported node type: AnnAssign *) +(* At stmt: unsupported node type: AnnAssign *) + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "tuple" |), + make_list [ + (M.call (| + M.get_name (| globals, "generate_dataset_item" |), + make_list [ + M.get_name (| globals, "cache" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "index" |) + ], + make_dict [] + |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition hashimoto : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header_hash"; "nonce"; "dataset_size"; "fetch_dataset_item" ] |) in + let _ := Constant.str " + Obtain the mix digest and the final value for a header, by aggregating + data from the full dataset. + + #### Parameters + + - `header_hash` is a valid [RLP hash] of a block header. + - `nonce` is the propagated nonce for the given block. + - `dataset_size` is the size of the dataset. See [`dataset_size`]. + - `fetch_dataset_item` is a function that retrieves a specific dataset item + based on its index. + + #### Returns + + - The mix digest generated from the header hash and propagated nonce. + - The final result obtained which will be checked for leading zeros (in + byte representation) in correspondence with the block difficulty. + + [RLP hash]: ref:ethereum.rlp.rlp_hash + [`dataset_size`]: ref:ethereum.ethash.dataset_size + " in + let nonce_le := + M.call (| + M.get_name (| globals, "bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "reversed" |), + make_list [ + M.get_name (| globals, "nonce" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let seed_hash := + M.call (| + M.get_name (| globals, "keccak512" |), + make_list [ + BinOp.add (| + M.get_name (| globals, "header_hash" |), + M.get_name (| globals, "nonce_le" |) + |) + ], + make_dict [] + |) in + let seed_head := + M.call (| + M.get_field (| M.get_name (| globals, "U32" |), "from_le_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "seed_hash" |), (* At expr: unsupported node type: NoneType *):Constant.int 4 |) + ], + make_dict [] + |) in + let rows := + BinOp.floor_div (| + M.get_name (| globals, "dataset_size" |), + Constant.int 128 + |) in + let mix := + BinOp.mult (| + M.call (| + M.get_name (| globals, "le_bytes_to_uint32_sequence" |), + make_list [ + M.get_name (| globals, "seed_hash" |) + ], + make_dict [] + |), + BinOp.floor_div (| + M.get_name (| globals, "MIX_BYTES" |), + M.get_name (| globals, "HASH_BYTES" |) + |) + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "HASHIMOTO_ACCESSES" |) + ], + make_dict [] + |) do +(* At stmt: unsupported node type: AnnAssign *) + let parent := + BinOp.mod_ (| + M.call (| + M.get_name (| globals, "fnv" |), + make_list [ + BinOp.bit_xor (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "seed_head" |) + |); + M.get_subscript (| M.get_name (| globals, "mix" |), BinOp.mod_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "mix" |) + ], + make_dict [] + |) + |) |) + ], + make_dict [] + |), + M.get_name (| globals, "rows" |) + |) in + For M.get_name (| globals, "j" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + BinOp.floor_div (| + M.get_name (| globals, "MIX_BYTES" |), + M.get_name (| globals, "HASH_BYTES" |) + |) + ], + make_dict [] + |) do + let new_data := BinOp.add + M.call (| + M.get_name (| globals, "fetch_dataset_item" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 2, + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "parent" |) + ], + make_dict [] + |) + |), + M.get_name (| globals, "j" |) + |) + ], + make_dict [] + |) + M.call (| + M.get_name (| globals, "fetch_dataset_item" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 2, + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "parent" |) + ], + make_dict [] + |) + |), + M.get_name (| globals, "j" |) + |) + ], + make_dict [] + |) in + EndFor. + let mix := + M.call (| + M.get_name (| globals, "fnv_hash" |), + make_list [ + M.get_name (| globals, "mix" |); + M.get_name (| globals, "new_data" |) + ], + make_dict [] + |) in + EndFor. + let compressed_mix := + make_list [] in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "mix" |) + ], + make_dict [] + |); + Constant.int 4 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compressed_mix" |), "append" |), + make_list [ + M.call (| + M.get_name (| globals, "fnv" |), + make_list [ + M.call (| + M.get_name (| globals, "fnv" |), + make_list [ + M.call (| + M.get_name (| globals, "fnv" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "mix" |), M.get_name (| globals, "i" |) |); + M.get_subscript (| M.get_name (| globals, "mix" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + ], + make_dict [] + |); + M.get_subscript (| M.get_name (| globals, "mix" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 2 + |) |) + ], + make_dict [] + |); + M.get_subscript (| M.get_name (| globals, "mix" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 3 + |) |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + EndFor. + let mix_digest := + M.call (| + M.get_name (| globals, "le_uint32_sequence_to_bytes" |), + make_list [ + M.get_name (| globals, "compressed_mix" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + BinOp.add (| + M.get_name (| globals, "seed_hash" |), + M.get_name (| globals, "mix_digest" |) + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + make_tuple [ M.get_name (| globals, "mix_digest" |); M.get_name (| globals, "result" |) ] + |) in + M.pure Constant.None_)). + +Definition hashimoto_light : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header_hash"; "nonce"; "cache"; "dataset_size" ] |) in + let _ := Constant.str " + Run the [`hashimoto`] algorithm by generating dataset item using the cache + instead of loading the full dataset into main memory. + + #### Parameters + + - `header_hash` is a valid [RLP hash] of a block header. + - `nonce` is the propagated nonce for the given block. + - `cache` is the cache generated by [`generate_cache`]. + - `dataset_size` is the size of the dataset. See [`dataset_size`]. + + #### Returns + + - The mix digest generated from the header hash and propagated nonce. + - The final result obtained which will be checked for leading zeros (in + byte representation) in correspondence with the block difficulty. + + [RLP hash]: ref:ethereum.rlp.rlp_hash + [`dataset_size`]: ref:ethereum.ethash.dataset_size + [`generate_cache`]: ref:ethereum.ethash.generate_cache + [`hashimoto`]: ref:ethereum.ethash.hashimoto + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "hashimoto" |), + make_list [ + M.get_name (| globals, "header_hash" |); + M.get_name (| globals, "nonce" |); + M.get_name (| globals, "dataset_size" |); + M.get_name (| globals, "fetch_dataset_item" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/exceptions.v b/CoqOfPython/ethereum/exceptions.v new file mode 100644 index 0000000..ea05a9f --- /dev/null +++ b/CoqOfPython/ethereum/exceptions.v @@ -0,0 +1,58 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Exceptions +^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The Ethereum specification exception classes. +". + +Definition EthereumException : Value.t := + builtins.make_klass + [(globals, "Exception")] + [ + + ] + [ + + ]. + +Definition InvalidBlock : Value.t := + builtins.make_klass + [(globals, "EthereumException")] + [ + + ] + [ + + ]. + +Definition RLPDecodingError : Value.t := + builtins.make_klass + [(globals, "InvalidBlock")] + [ + + ] + [ + + ]. + +Definition RLPEncodingError : Value.t := + builtins.make_klass + [(globals, "EthereumException")] + [ + + ] + [ + + ]. diff --git a/CoqOfPython/ethereum/fork_criteria.v b/CoqOfPython/ethereum/fork_criteria.v new file mode 100644 index 0000000..6614a4e --- /dev/null +++ b/CoqOfPython/ethereum/fork_criteria.v @@ -0,0 +1,263 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Fork Criteria +^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Classes for specifying criteria for Mainnet forks. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require abc. +Axiom abc_ABC : + IsGlobalAlias globals abc.globals "ABC". +Axiom abc_abstractmethod : + IsGlobalAlias globals abc.globals "abstractmethod". + +Require typing. +Axiom typing_Final : + IsGlobalAlias globals typing.globals "Final". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Definition ForkCriteria : Value.t := + builtins.make_klass + [(globals, "ABC")] + [ + + ] + [ + ( + "__eq__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "other" ] |) in + let _ := Constant.str " + Equality for fork criteria. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "other" |); + M.get_name (| globals, "ForkCriteria" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Compare.eq (| M.get_field (| M.get_name (| globals, "self" |), "_internal" |), M.get_field (| M.get_name (| globals, "other" |), "_internal" |) |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_)) + ); + ( + "__lt__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "other" ] |) in + let _ := Constant.str " + Ordering for fork criteria. Block number forks are before timestamp + forks and scheduled forks are before unscheduled forks. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "other" |); + M.get_name (| globals, "ForkCriteria" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Compare.lt (| M.get_field (| M.get_name (| globals, "self" |), "_internal" |), M.get_field (| M.get_name (| globals, "other" |), "_internal" |) |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_)) + ); + ( + "__hash__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self" ] |) in + let _ := Constant.str " + `ForkCriteria` is hashable, so it can be stored in dictionaries. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "hash" |), + make_list [ + M.get_field (| M.get_name (| globals, "self" |), "_internal" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)) + ) + ]. + +Definition ByBlockNumber : Value.t := + builtins.make_klass + [(globals, "ForkCriteria")] + [ + + ] + [ + ( + "__init__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "block_number" ] |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "self" |), "_internal" |), + make_tuple [ M.get_field (| M.get_name (| globals, "ForkCriteria" |), "BLOCK_NUMBER" |); M.get_name (| globals, "block_number" |) ] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "self" |), "block_number" |), + M.get_name (| globals, "block_number" |) + |) in + M.pure Constant.None_)) + ); + ( + "check", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "block_number"; "timestamp" ] |) in + let _ := Constant.str " + Check whether the block number has been reached. + " in + let _ := M.return_ (| + Compare.gt_e (| M.get_name (| globals, "block_number" |), M.get_field (| M.get_name (| globals, "self" |), "block_number" |) |) + |) in + M.pure Constant.None_)) + ); + ( + "__repr__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self" ] |) in + let _ := Constant.str " + String representation of this object. + " in + let _ := M.return_ (| + (* At expr: unsupported node type: JoinedStr *) + |) in + M.pure Constant.None_)) + ) + ]. + +Definition ByTimestamp : Value.t := + builtins.make_klass + [(globals, "ForkCriteria")] + [ + + ] + [ + ( + "__init__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "timestamp" ] |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "self" |), "_internal" |), + make_tuple [ M.get_field (| M.get_name (| globals, "ForkCriteria" |), "TIMESTAMP" |); M.get_name (| globals, "timestamp" |) ] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "self" |), "timestamp" |), + M.get_name (| globals, "timestamp" |) + |) in + M.pure Constant.None_)) + ); + ( + "check", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "block_number"; "timestamp" ] |) in + let _ := Constant.str " + Check whether the timestamp has been reached. + " in + let _ := M.return_ (| + Compare.gt_e (| M.get_name (| globals, "timestamp" |), M.get_field (| M.get_name (| globals, "self" |), "timestamp" |) |) + |) in + M.pure Constant.None_)) + ); + ( + "__repr__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self" ] |) in + let _ := Constant.str " + String representation of this object. + " in + let _ := M.return_ (| + (* At expr: unsupported node type: JoinedStr *) + |) in + M.pure Constant.None_)) + ) + ]. + +Definition Unscheduled : Value.t := + builtins.make_klass + [(globals, "ForkCriteria")] + [ + + ] + [ + ( + "__init__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self" ] |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "self" |), "_internal" |), + make_tuple [ M.get_field (| M.get_name (| globals, "ForkCriteria" |), "UNSCHEDULED" |); Constant.int 0 ] + |) in + M.pure Constant.None_)) + ); + ( + "check", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "block_number"; "timestamp" ] |) in + let _ := Constant.str " + Unscheduled forks never occur. + " in + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_)) + ); + ( + "__repr__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self" ] |) in + let _ := Constant.str " + String representation of this object. + " in + let _ := M.return_ (| + Constant.str "Unscheduled()" + |) in + M.pure Constant.None_)) + ) + ]. diff --git a/CoqOfPython/ethereum/frontier/__init__.v b/CoqOfPython/ethereum/frontier/__init__.v new file mode 100644 index 0000000..c80e652 --- /dev/null +++ b/CoqOfPython/ethereum/frontier/__init__.v @@ -0,0 +1,22 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Frontier is the first production-ready iteration of the Ethereum protocol. +". + +Require ethereum.fork_criteria. +Axiom ethereum_fork_criteria_ByBlockNumber : + IsGlobalAlias globals ethereum.fork_criteria.globals "ByBlockNumber". + +Definition FORK_CRITERIA : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "ByBlockNumber" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/frontier/blocks.v b/CoqOfPython/ethereum/frontier/blocks.v new file mode 100644 index 0000000..6501788 --- /dev/null +++ b/CoqOfPython/ethereum/frontier/blocks.v @@ -0,0 +1,93 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +A `Block` is a single link in the chain that is Ethereum. Each `Block` contains +a `Header` and zero or more transactions. Each `Header` contains associated +metadata like the block number, parent block hash, and how much gas was +consumed by its transactions. + +Together, these blocks form a cryptographically secure journal recording the +history of all state transitions that have happened since the genesis of the +chain. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes8 : + IsGlobalAlias globals base_types.globals "Bytes8". +Axiom base_types_Bytes32 : + IsGlobalAlias globals base_types.globals "Bytes32". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require crypto.hash. +Axiom crypto_hash_Hash32 : + IsGlobalAlias globals crypto.hash.globals "Hash32". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Require transactions. +Axiom transactions_Transaction : + IsGlobalAlias globals transactions.globals "Transaction". + +Definition Header : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Block : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Log : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Receipt : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. diff --git a/CoqOfPython/ethereum/frontier/bloom.v b/CoqOfPython/ethereum/frontier/bloom.v new file mode 100644 index 0000000..04b5d9f --- /dev/null +++ b/CoqOfPython/ethereum/frontier/bloom.v @@ -0,0 +1,164 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Logs Bloom +^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +This modules defines functions for calculating bloom filters of logs. For the +general theory of bloom filters see e.g. `Wikipedia +`_. Bloom filters are used to allow +for efficient searching of logs by address and/or topic, by rapidly +eliminating blocks and receipts from their search. +". + +Require typing. +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require fork_types. +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". + +Definition add_to_bloom : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "bloom"; "bloom_entry" ] |) in + let _ := Constant.str " + Add a bloom entry to the bloom filter (`bloom`). + + The number of hash functions used is 3. They are calculated by taking the + least significant 11 bits from the first 3 16-bit words of the + `keccak_256()` hash of `bloom_entry`. + + Parameters + ---------- + bloom : + The bloom filter. + bloom_entry : + An entry which is to be added to bloom filter. + " in + let hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "bloom_entry" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "idx" |) in make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ] do + let bit_to_set := + BinOp.bit_and (| + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |):BinOp.add (| + M.get_name (| globals, "idx" |), + Constant.int 2 + |) |) + ], + make_dict [] + |), + Constant.int 2047 + |) in + let bit_index := + BinOp.sub (| + Constant.int 2047, + M.get_name (| globals, "bit_to_set" |) + |) in + let byte_index := + BinOp.floor_div (| + M.get_name (| globals, "bit_index" |), + Constant.int 8 + |) in + let bit_value := + BinOp.l_shift (| + Constant.int 1, + BinOp.sub (| + Constant.int 7, + BinOp.mod_ (| + M.get_name (| globals, "bit_index" |), + Constant.int 8 + |) + |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), + BinOp.bit_or (| + M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), + M.get_name (| globals, "bit_value" |) + |) + |) in + EndFor. + M.pure Constant.None_)). + +Definition logs_bloom : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "logs" ] |) in + let _ := Constant.str " + Obtain the logs bloom from a list of log entries. + + The address and each topic of a log are added to the bloom filter. + + Parameters + ---------- + logs : + List of logs for which the logs bloom is to be obtained. + + Returns + ------- + logs_bloom : `Bloom` + The logs bloom obtained which is 256 bytes with some bits set as per + the caller address and the log topics. + " in +(* At stmt: unsupported node type: AnnAssign *) + For M.get_name (| globals, "log" |) in M.get_name (| globals, "logs" |) do + let _ := M.call (| + M.get_name (| globals, "add_to_bloom" |), + make_list [ + M.get_name (| globals, "bloom" |); + M.get_field (| M.get_name (| globals, "log" |), "address" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "topic" |) in M.get_field (| M.get_name (| globals, "log" |), "topics" |) do + let _ := M.call (| + M.get_name (| globals, "add_to_bloom" |), + make_list [ + M.get_name (| globals, "bloom" |); + M.get_name (| globals, "topic" |) + ], + make_dict [] + |) in + EndFor. + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bloom" |), + make_list [ + M.get_name (| globals, "bloom" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/fork.v b/CoqOfPython/ethereum/frontier/fork.v new file mode 100644 index 0000000..2a44b1f --- /dev/null +++ b/CoqOfPython/ethereum/frontier/fork.v @@ -0,0 +1,2046 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Specification +^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Entry point for the Ethereum specification. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.crypto.elliptic_curve. +Axiom ethereum_crypto_elliptic_curve_SECP256K1N : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.ethash. +Axiom ethereum_ethash_dataset_size : + IsGlobalAlias globals ethereum.ethash.globals "dataset_size". +Axiom ethereum_ethash_generate_cache : + IsGlobalAlias globals ethereum.ethash.globals "generate_cache". +Axiom ethereum_ethash_hashimoto_light : + IsGlobalAlias globals ethereum.ethash.globals "hashimoto_light". + +Require ethereum.exceptions. +Axiom ethereum_exceptions_InvalidBlock : + IsGlobalAlias globals ethereum.exceptions.globals "InvalidBlock". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U64 : + IsGlobalAlias globals base_types.globals "U64". +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_U256_CEIL_VALUE : + IsGlobalAlias globals base_types.globals "U256_CEIL_VALUE". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes32 : + IsGlobalAlias globals base_types.globals "Bytes32". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". + +Require __init__. +Axiom __init___vm : + IsGlobalAlias globals __init__.globals "vm". + +Require blocks. +Axiom blocks_Block : + IsGlobalAlias globals blocks.globals "Block". +Axiom blocks_Header : + IsGlobalAlias globals blocks.globals "Header". +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". +Axiom blocks_Receipt : + IsGlobalAlias globals blocks.globals "Receipt". + +Require bloom. +Axiom bloom_logs_bloom : + IsGlobalAlias globals bloom.globals "logs_bloom". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Require state. +Axiom state_State : + IsGlobalAlias globals state.globals "State". +Axiom state_create_ether : + IsGlobalAlias globals state.globals "create_ether". +Axiom state_destroy_account : + IsGlobalAlias globals state.globals "destroy_account". +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". +Axiom state_increment_nonce : + IsGlobalAlias globals state.globals "increment_nonce". +Axiom state_set_account_balance : + IsGlobalAlias globals state.globals "set_account_balance". +Axiom state_state_root : + IsGlobalAlias globals state.globals "state_root". + +Require transactions. +Axiom transactions_TX_BASE_COST : + IsGlobalAlias globals transactions.globals "TX_BASE_COST". +Axiom transactions_TX_DATA_COST_PER_NON_ZERO : + IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_NON_ZERO". +Axiom transactions_TX_DATA_COST_PER_ZERO : + IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_ZERO". +Axiom transactions_Transaction : + IsGlobalAlias globals transactions.globals "Transaction". + +Require trie. +Axiom trie_Trie : + IsGlobalAlias globals trie.globals "Trie". +Axiom trie_root : + IsGlobalAlias globals trie.globals "root". +Axiom trie_trie_set : + IsGlobalAlias globals trie.globals "trie_set". + +Require utils.message. +Axiom utils_message_prepare_message : + IsGlobalAlias globals utils.message.globals "prepare_message". + +Require vm.interpreter. +Axiom vm_interpreter_process_message_call : + IsGlobalAlias globals vm.interpreter.globals "process_message_call". + +Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mult (| + Constant.int 5, + BinOp.pow (| + Constant.int 10, + Constant.int 18 + |) + |) + ], + make_dict [] + |) +)). + +Definition GAS_LIMIT_ADJUSTMENT_FACTOR : Value.t := M.run ltac:(M.monadic ( + Constant.int 1024 +)). + +Definition GAS_LIMIT_MINIMUM : Value.t := M.run ltac:(M.monadic ( + Constant.int 5000 +)). + +Definition MINIMUM_DIFFICULTY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 131072 + ], + make_dict [] + |) +)). + +Definition MAX_OMMER_DEPTH : Value.t := M.run ltac:(M.monadic ( + Constant.int 6 +)). + +Definition BlockChain : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition apply_fork : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "old" ] |) in + let _ := Constant.str " + Transforms the state from the previous hard fork (`old`) into the block + chain object for this hard fork and returns it. + + When forks need to implement an irregular state transition, this function + is used to handle the irregularity. See the :ref:`DAO Fork ` for + an example. + + Parameters + ---------- + old : + Previous block chain object. + + Returns + ------- + new : `BlockChain` + Upgraded block chain object for this hard fork. + " in + let _ := M.return_ (| + M.get_name (| globals, "old" |) + |) in + M.pure Constant.None_)). + +Definition get_last_256_block_hashes : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "chain" ] |) in + let _ := Constant.str " + Obtain the list of hashes of the previous 256 blocks in order of + increasing block number. + + This function will return less hashes for the first 256 blocks. + + The ``BLOCKHASH`` opcode needs to access the latest hashes on the chain, + therefore this function retrieves them. + + Parameters + ---------- + chain : + History and current state. + + Returns + ------- + recent_block_hashes : `List[Hash32]` + Hashes of the recent 256 blocks in order of increasing block number. + " in + let recent_blocks := + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |):(* At expr: unsupported node type: NoneType *) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "recent_blocks" |) + ], + make_dict [] + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + make_list [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let recent_block_hashes := + make_list [] in + For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_blocks" |) do + let prev_block_hash := + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), + make_list [ + M.get_name (| globals, "prev_block_hash" |) + ], + make_dict [] + |) in + EndFor. + let most_recent_block_hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_field (| M.get_subscript (| M.get_name (| globals, "recent_blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), + make_list [ + M.get_name (| globals, "most_recent_block_hash" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "recent_block_hashes" |) + |) in + M.pure Constant.None_)). + +Definition state_transition : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "chain"; "block" ] |) in + let _ := Constant.str " + Attempts to apply a block to an existing block chain. + + All parts of the block's contents need to be verified before being added + to the chain. Blocks are verified by ensuring that the contents of the + block make logical sense with the contents of the parent block. The + information in the block's header must also match the corresponding + information in the block. + + To implement Ethereum, in theory clients are only required to store the + most recent 255 blocks of the chain since as far as execution is + concerned, only those blocks are accessed. Practically, however, clients + should store more blocks to handle reorgs. + + Parameters + ---------- + chain : + History and current state. + block : + Block to apply to `chain`. + " in + let parent_header := + M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) in + let _ := M.call (| + M.get_name (| globals, "validate_header" |), + make_list [ + M.get_field (| M.get_name (| globals, "block" |), "header" |); + M.get_name (| globals, "parent_header" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "validate_ommers" |), + make_list [ + M.get_field (| M.get_name (| globals, "block" |), "ommers" |); + M.get_field (| M.get_name (| globals, "block" |), "header" |); + M.get_name (| globals, "chain" |) + ], + make_dict [] + |) in + let apply_body_output := + M.call (| + M.get_name (| globals, "apply_body" |), + make_list [ + M.get_field (| M.get_name (| globals, "chain" |), "state" |); + M.call (| + M.get_name (| globals, "get_last_256_block_hashes" |), + make_list [ + M.get_name (| globals, "chain" |) + ], + make_dict [] + |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "coinbase" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "number" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "gas_limit" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "timestamp" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "difficulty" |); + M.get_field (| M.get_name (| globals, "block" |), "transactions" |); + M.get_field (| M.get_name (| globals, "block" |), "ommers" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_gas_used" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "gas_used" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "transactions_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "transactions_root" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "state_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "state_root" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "receipt_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "receipt_root" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_logs_bloom" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "bloom" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), "append" |), + make_list [ + M.get_name (| globals, "block" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |) + ], + make_dict [] + |), Constant.int 255 |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |):(* At expr: unsupported node type: NoneType *) |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition validate_header : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header"; "parent_header" ] |) in + let _ := Constant.str " + Verifies a block header. + + In order to consider a block's header valid, the logic for the + quantities in the header should match the logic for the block itself. + For example the header timestamp should be greater than the block's parent + timestamp because the block was created *after* the parent block. + Additionally, the block's number should be directly following the parent + block's number since it is the next block in the sequence. + + Parameters + ---------- + header : + Header to check for correctness. + parent_header : + Parent Header of the header to check for correctness + " in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt (| M.get_field (| M.get_name (| globals, "header" |), "timestamp" |), M.get_field (| M.get_name (| globals, "parent_header" |), "timestamp" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "number" |), BinOp.add (| + M.get_field (| M.get_name (| globals, "parent_header" |), "number" |), + Constant.int 1 + |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + M.call (| + M.get_name (| globals, "check_gas_limit" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "gas_limit" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "gas_limit" |) + ], + make_dict [] + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) + ], + make_dict [] + |), Constant.int 32 |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let block_difficulty := + M.call (| + M.get_name (| globals, "calculate_block_difficulty" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "number" |); + M.get_field (| M.get_name (| globals, "header" |), "timestamp" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "timestamp" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "difficulty" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "difficulty" |), M.get_name (| globals, "block_difficulty" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let block_parent_hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "parent_header" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |), M.get_name (| globals, "block_parent_hash" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "validate_proof_of_work" |), + make_list [ + M.get_name (| globals, "header" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header" ] |) in + let _ := Constant.str " + Generate rlp hash of the header which is to be used for Proof-of-Work + verification. + + In other words, the PoW artefacts `mix_digest` and `nonce` are ignored + while calculating this hash. + + A particular PoW is valid for a single hash, that hash is computed by + this function. The `nonce` and `mix_digest` are omitted from this hash + because they are being changed by miners in their search for a sufficient + proof-of-work. + + Parameters + ---------- + header : + The header object for which the hash is to be generated. + + Returns + ------- + hash : `Hash32` + The PoW valid rlp hash of the passed in header. + " in + let header_data_without_pow_artefacts := + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |); + M.get_field (| M.get_name (| globals, "header" |), "ommers_hash" |); + M.get_field (| M.get_name (| globals, "header" |), "coinbase" |); + M.get_field (| M.get_name (| globals, "header" |), "state_root" |); + M.get_field (| M.get_name (| globals, "header" |), "transactions_root" |); + M.get_field (| M.get_name (| globals, "header" |), "receipt_root" |); + M.get_field (| M.get_name (| globals, "header" |), "bloom" |); + M.get_field (| M.get_name (| globals, "header" |), "difficulty" |); + M.get_field (| M.get_name (| globals, "header" |), "number" |); + M.get_field (| M.get_name (| globals, "header" |), "gas_limit" |); + M.get_field (| M.get_name (| globals, "header" |), "gas_used" |); + M.get_field (| M.get_name (| globals, "header" |), "timestamp" |); + M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) + ] in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "header_data_without_pow_artefacts" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition validate_proof_of_work : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header" ] |) in + let _ := Constant.str " + Validates the Proof of Work constraints. + + In order to verify that a miner's proof-of-work is valid for a block, a + ``mix-digest`` and ``result`` are calculated using the ``hashimoto_light`` + hash function. The mix digest is a hash of the header and the nonce that + is passed through and it confirms whether or not proof-of-work was done + on the correct block. The result is the actual hash value of the block. + + Parameters + ---------- + header : + Header of interest. + " in + let header_hash := + M.call (| + M.get_name (| globals, "generate_header_hash_for_pow" |), + make_list [ + M.get_name (| globals, "header" |) + ], + make_dict [] + |) in + let cache := + M.call (| + M.get_name (| globals, "generate_cache" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "number" |) + ], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "mix_digest" |); M.get_name (| globals, "result" |) ], + M.call (| + M.get_name (| globals, "hashimoto_light" |), + make_list [ + M.get_name (| globals, "header_hash" |); + M.get_field (| M.get_name (| globals, "header" |), "nonce" |); + M.get_name (| globals, "cache" |); + M.call (| + M.get_name (| globals, "dataset_size" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "number" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_name (| globals, "mix_digest" |), M.get_field (| M.get_name (| globals, "header" |), "mix_digest" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "result" |) + ], + make_dict [] + |), BinOp.floor_div (| + M.get_name (| globals, "U256_CEIL_VALUE" |), + M.get_field (| M.get_name (| globals, "header" |), "difficulty" |) + |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition check_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx"; "gas_available" ] |) in + let _ := Constant.str " + Check if the transaction is includable in the block. + + Parameters + ---------- + tx : + The transaction. + gas_available : + The gas remaining in the block. + + Returns + ------- + sender_address : + The sender of the transaction. + + Raises + ------ + InvalidBlock : + If the transaction is not includable. + " in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_name (| globals, "gas_available" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let sender_address := + M.call (| + M.get_name (| globals, "recover_sender" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "sender_address" |) + |) in + M.pure Constant.None_)). + +Definition make_receipt : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx"; "post_state"; "cumulative_gas_used"; "logs" ] |) in + let _ := Constant.str " + Make the receipt for a transaction that was executed. + + Parameters + ---------- + tx : + The executed transaction. + post_state : + The state root immediately after this transaction. + cumulative_gas_used : + The total gas used so far in the block after the transaction was + executed. + logs : + The logs produced by the transaction. + + Returns + ------- + receipt : + The receipt for the transaction. + " in + let receipt := + M.call (| + M.get_name (| globals, "Receipt" |), + make_list [], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "receipt" |) + |) in + M.pure Constant.None_)). + +Definition ApplyBodyOutput : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition apply_body : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "block_hashes"; "coinbase"; "block_number"; "block_gas_limit"; "block_time"; "block_difficulty"; "transactions"; "ommers" ] |) in + let _ := Constant.str " + Executes a block. + + Many of the contents of a block are stored in data structures called + tries. There is a transactions trie which is similar to a ledger of the + transactions stored in the current block. There is also a receipts trie + which stores the results of executing a transaction, like the post state + and gas used. This function creates and executes the block that is to be + added to the chain. + + Parameters + ---------- + state : + Current account state. + block_hashes : + List of hashes of the previous 256 blocks in the order of + increasing block number. + coinbase : + Address of account which receives block reward and transaction fees. + block_number : + Position of the block within the chain. + block_gas_limit : + Initial amount of gas available for execution in this block. + block_time : + Time the block was produced, measured in seconds since the epoch. + block_difficulty : + Difficulty of the block. + transactions : + Transactions included in the block. + ommers : + Headers of ancestor blocks which are not direct parents (formerly + uncles.) + + Returns + ------- + apply_body_output : `ApplyBodyOutput` + Output of applying the block body to the state. + " in + let gas_available := + M.get_name (| globals, "block_gas_limit" |) in +(* At stmt: unsupported node type: AnnAssign *) +(* At stmt: unsupported node type: AnnAssign *) +(* At stmt: unsupported node type: AnnAssign *) + For make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "tx" |) ] in M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "transactions" |) + ], + make_dict [] + |) do + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "transactions_trie" |); + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "i" |) + ], + make_dict [] + |) + ], + make_dict [] + |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) in + let sender_address := + M.call (| + M.get_name (| globals, "check_transaction" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "gas_available" |) + ], + make_dict [] + |) in + let env := + M.call (| + M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |) ], + M.call (| + M.get_name (| globals, "process_transaction" |), + make_list [ + M.get_name (| globals, "env" |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) in + let gas_available := BinOp.sub + M.get_name (| globals, "gas_used" |) + M.get_name (| globals, "gas_used" |) in + let receipt := + M.call (| + M.get_name (| globals, "make_receipt" |), + make_list [ + M.get_name (| globals, "tx" |); + M.call (| + M.get_name (| globals, "state_root" |), + make_list [ + M.get_name (| globals, "state" |) + ], + make_dict [] + |); + BinOp.sub (| + M.get_name (| globals, "block_gas_limit" |), + M.get_name (| globals, "gas_available" |) + |); + M.get_name (| globals, "logs" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "receipts_trie" |); + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "i" |) + ], + make_dict [] + |) + ], + make_dict [] + |); + M.get_name (| globals, "receipt" |) + ], + make_dict [] + |) in + let block_logs := BinOp.add + M.get_name (| globals, "logs" |) + M.get_name (| globals, "logs" |) in + EndFor. + let _ := M.call (| + M.get_name (| globals, "pay_rewards" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "block_number" |); + M.get_name (| globals, "coinbase" |); + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |) in + let block_gas_used := + BinOp.sub (| + M.get_name (| globals, "block_gas_limit" |), + M.get_name (| globals, "gas_available" |) + |) in + let block_logs_bloom := + M.call (| + M.get_name (| globals, "logs_bloom" |), + make_list [ + M.get_name (| globals, "block_logs" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ApplyBodyOutput" |), + make_list [ + M.get_name (| globals, "block_gas_used" |); + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_name (| globals, "transactions_trie" |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_name (| globals, "receipts_trie" |) + ], + make_dict [] + |); + M.get_name (| globals, "block_logs_bloom" |); + M.call (| + M.get_name (| globals, "state_root" |), + make_list [ + M.get_name (| globals, "state" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition validate_ommers : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "ommers"; "block_header"; "chain" ] |) in + let _ := Constant.str " + Validates the ommers mentioned in the block. + + An ommer block is a block that wasn't canonically added to the + blockchain because it wasn't validated as fast as the canonical block + but was mined at the same time. + + To be considered valid, the ommers must adhere to the rules defined in + the Ethereum protocol. The maximum amount of ommers is 2 per block and + there cannot be duplicate ommers in a block. Many of the other ommer + constraints are listed in the in-line comments of this function. + + Parameters + ---------- + ommers : + List of ommers mentioned in the current block. + block_header: + The header of current block. + chain : + History and current state. + " in + let block_hash := + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "block_header" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), M.get_field (| M.get_name (| globals, "block_header" |), "ommers_hash" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + (* At expr: unsupported node type: Compare *); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let ommer_parent_header := + M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), BinOp.sub (| + UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) |), + Constant.int 1 + |) |), "header" |) in + let _ := M.call (| + M.get_name (| globals, "validate_header" |), + make_list [ + M.get_name (| globals, "ommer" |); + M.get_name (| globals, "ommer_parent_header" |) + ], + make_dict [] + |) in + EndFor. + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), Constant.int 2 |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let ommers_hashes := + [M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "ommer" |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)] in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers_hashes" |) + ], + make_dict [] + |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_name (| globals, "set" |), + make_list [ + M.get_name (| globals, "ommers_hashes" |) + ], + make_dict [] + |) + ], + make_dict [] + |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let recent_canonical_blocks := + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| BinOp.add (| + M.get_name (| globals, "MAX_OMMER_DEPTH" |), + Constant.int 1 + |) |):(* At expr: unsupported node type: NoneType *) |) in + let recent_canonical_block_hashes := + {M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_field (| M.get_name (| globals, "block" |), "header" |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)} in +(* At stmt: unsupported node type: AnnAssign *) + For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_canonical_blocks" |) do + let recent_ommers_hashes := + M.call (| + M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), + make_list [ + {M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "ommer" |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)} + ], + make_dict [] + |) in + EndFor. + For make_tuple [ M.get_name (| globals, "ommer_index" |); M.get_name (| globals, "ommer" |) ] in M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |) do + let ommer_hash := + M.get_subscript (| M.get_name (| globals, "ommers_hashes" |), M.get_name (| globals, "ommer_index" |) |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_eq (| M.get_name (| globals, "ommer_hash" |), M.get_name (| globals, "block_hash" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_in (| M.get_name (| globals, "ommer_hash" |), M.get_name (| globals, "recent_canonical_block_hashes" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_in (| M.get_name (| globals, "ommer_hash" |), M.get_name (| globals, "recent_ommers_hashes" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let ommer_age := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + (* At expr: unsupported node type: Compare *); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.in (| M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), M.get_name (| globals, "recent_canonical_block_hashes" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_eq (| M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), M.get_field (| M.get_name (| globals, "block_header" |), "parent_hash" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_)). + +Definition pay_rewards : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "block_number"; "coinbase"; "ommers" ] |) in + let _ := Constant.str " + Pay rewards to the block miner as well as the ommers miners. + + The miner of the canonical block is rewarded with the predetermined + block reward, ``BLOCK_REWARD``, plus a variable award based off of the + number of ommer blocks that were mined around the same time, and included + in the canonical block's header. An ommer block is a block that wasn't + added to the canonical blockchain because it wasn't validated as fast as + the accepted block but was mined at the same time. Although not all blocks + that are mined are added to the canonical chain, miners are still paid a + reward for their efforts. This reward is called an ommer reward and is + calculated based on the number associated with the ommer block that they + mined. + + Parameters + ---------- + state : + Current account state. + block_number : + Position of the block within the chain. + coinbase : + Address of account which receives block reward and transaction fees. + ommers : + List of ommers mentioned in the current block. + " in + let miner_reward := + BinOp.add (| + M.get_name (| globals, "BLOCK_REWARD" |), + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + BinOp.floor_div (| + M.get_name (| globals, "BLOCK_REWARD" |), + Constant.int 32 + |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "create_ether" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "coinbase" |); + M.get_name (| globals, "miner_reward" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do + let ommer_age := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "block_number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) + ], + make_dict [] + |) in + let ommer_miner_reward := + BinOp.floor_div (| + BinOp.mult (| + BinOp.sub (| + Constant.int 8, + M.get_name (| globals, "ommer_age" |) + |), + M.get_name (| globals, "BLOCK_REWARD" |) + |), + Constant.int 8 + |) in + let _ := M.call (| + M.get_name (| globals, "create_ether" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_field (| M.get_name (| globals, "ommer" |), "coinbase" |); + M.get_name (| globals, "ommer_miner_reward" |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_)). + +Definition process_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "env"; "tx" ] |) in + let _ := Constant.str " + Execute a transaction against the provided environment. + + This function processes the actions needed to execute a transaction. + It decrements the sender's account after calculating the gas fee and + refunds them the proper amount after execution. Calling contracts, + deploying code, and incrementing nonces are all examples of actions that + happen within this function or from a call made within this function. + + Accounts that are marked for deletion are processed and destroyed after + execution. + + Parameters + ---------- + env : + Environment for the Ethereum Virtual Machine. + tx : + Transaction to execute. + + Returns + ------- + gas_left : `ethereum.base_types.U256` + Remaining gas after execution. + logs : `Tuple[ethereum.blocks.Log, ...]` + Logs generated during execution. + " in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + M.call (| + M.get_name (| globals, "validate_transaction" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let sender := + M.get_field (| M.get_name (| globals, "env" |), "origin" |) in + let sender_account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |) in + let gas_fee := + BinOp.mult (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "sender_account" |), "nonce" |), M.get_field (| M.get_name (| globals, "tx" |), "nonce" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt_e (| M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), BinOp.add (| + M.get_name (| globals, "gas_fee" |), + M.get_field (| M.get_name (| globals, "tx" |), "value" |) + |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "sender_account" |), "code" |), M.call (| + M.get_name (| globals, "bytearray" |), + make_list [], + make_dict [] + |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let gas := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.call (| + M.get_name (| globals, "calculate_intrinsic_cost" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) in + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |) in + let sender_balance_after_gas_fee := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), + M.get_name (| globals, "gas_fee" |) + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |); + M.get_name (| globals, "sender_balance_after_gas_fee" |) + ], + make_dict [] + |) in + let message := + M.call (| + M.get_name (| globals, "prepare_message" |), + make_list [ + M.get_name (| globals, "sender" |); + M.get_field (| M.get_name (| globals, "tx" |), "to" |); + M.get_field (| M.get_name (| globals, "tx" |), "value" |); + M.get_field (| M.get_name (| globals, "tx" |), "data" |); + M.get_name (| globals, "gas" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let output := + M.call (| + M.get_name (| globals, "process_message_call" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let gas_used := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "output" |), "gas_left" |) + |) in + let gas_refund := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + BinOp.floor_div (| + M.get_name (| globals, "gas_used" |), + Constant.int 2 + |); + M.get_field (| M.get_name (| globals, "output" |), "refund_counter" |) + ], + make_dict [] + |) in + let gas_refund_amount := + BinOp.mult (| + BinOp.add (| + M.get_field (| M.get_name (| globals, "output" |), "gas_left" |), + M.get_name (| globals, "gas_refund" |) + |), + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) + |) in + let transaction_fee := + BinOp.mult (| + BinOp.sub (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "output" |), "gas_left" |) + |), + M.get_name (| globals, "gas_refund" |) + |), + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) + |) in + let total_gas_used := + BinOp.sub (| + M.get_name (| globals, "gas_used" |), + M.get_name (| globals, "gas_refund" |) + |) in + let sender_balance_after_refund := + BinOp.add (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |), "balance" |), + M.get_name (| globals, "gas_refund_amount" |) + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |); + M.get_name (| globals, "sender_balance_after_refund" |) + ], + make_dict [] + |) in + let coinbase_balance_after_mining_fee := + BinOp.add (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |), "balance" |), + M.get_name (| globals, "transaction_fee" |) + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |); + M.get_name (| globals, "coinbase_balance_after_mining_fee" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "accounts_to_delete" |) do + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + EndFor. + let _ := M.return_ (| + make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |) ] + |) in + M.pure Constant.None_)). + +Definition validate_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Verifies a transaction. + + The gas in a transaction gets used to pay for the intrinsic cost of + operations, therefore if there is insufficient gas then it would not + be possible to execute a transaction and it will be declared invalid. + + Additionally, the nonce of a transaction must not equal or exceed the + limit defined in `EIP-2681 `_. + In practice, defining the limit as ``2**64-1`` has no impact because + sending ``2**64-1`` transactions is improbable. It's not strictly + impossible though, ``2**64-1`` transactions is the entire capacity of the + Ethereum blockchain at 2022 gas limits for a little over 22 years. + + Parameters + ---------- + tx : + Transaction to validate. + + Returns + ------- + verified : `bool` + True if the transaction can be executed, or False otherwise. + " in + let _ := M.return_ (| + BoolOp.and (| + Compare.lt_e (| M.call (| + M.get_name (| globals, "calculate_intrinsic_cost" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |), M.get_field (| M.get_name (| globals, "tx" |), "gas" |) |), + ltac:(M.monadic ( + Compare.lt (| M.get_field (| M.get_name (| globals, "tx" |), "nonce" |), BinOp.sub (| + BinOp.pow (| + Constant.int 2, + Constant.int 64 + |), + Constant.int 1 + |) |) + )) + |) + |) in + M.pure Constant.None_)). + +Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Calculates the gas that is charged before execution is started. + + The intrinsic cost of the transaction is charged before execution has + begun. Functions/operations in the EVM cost money to execute so this + intrinsic cost is for the operations that need to be paid for as part of + the transaction. Data transfer, for example, is part of this intrinsic + cost. It costs ether to send data over the wire and that ether is + accounted for in the intrinsic cost calculated in this function. This + intrinsic cost must be calculated and paid for before execution in order + for all operations to be implemented. + + Parameters + ---------- + tx : + Transaction to compute the intrinsic cost of. + + Returns + ------- + verified : `ethereum.base_types.Uint` + The intrinsic cost of the transaction. + " in + let data_cost := + Constant.int 0 in + For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "byte" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.add (| + M.get_name (| globals, "TX_BASE_COST" |), + M.get_name (| globals, "data_cost" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition recover_sender : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Extracts the sender address from a transaction. + + The v, r, and s values are the three parts that make up the signature + of a transaction. In order to recover the sender of a transaction the two + components needed are the signature (``v``, ``r``, and ``s``) and the + signing hash of the transaction. The sender's public key can be obtained + with these two values and therefore the sender address can be retrieved. + + Parameters + ---------- + tx : + Transaction of interest. + + Returns + ------- + sender : `ethereum.fork_types.Address` + The address of the account that signed the transaction. + " in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "v" |); M.get_name (| globals, "r" |); M.get_name (| globals, "s" |) ], + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "v" |); M.get_field (| M.get_name (| globals, "tx" |), "r" |); M.get_field (| M.get_name (| globals, "tx" |), "s" |) ] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.or (| + Compare.eq (| M.get_name (| globals, "v" |), Constant.int 27 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "v" |), Constant.int 28 |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.and (| + Compare.lt (| Constant.int 0, M.get_name (| globals, "r" |) |), + ltac:(M.monadic ( + Compare.lt (| M.get_name (| globals, "r" |), M.get_name (| globals, "SECP256K1N" |) |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.and (| + Compare.lt (| Constant.int 0, M.get_name (| globals, "s" |) |), + ltac:(M.monadic ( + Compare.lt (| M.get_name (| globals, "s" |), M.get_name (| globals, "SECP256K1N" |) |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + BinOp.sub (| + M.get_name (| globals, "v" |), + Constant.int 27 + |); + M.call (| + M.get_name (| globals, "signing_hash" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_subscript (| M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), Constant.int 12:Constant.int 32 |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition signing_hash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Compute the hash of a transaction used in the signature. + + The values that are used to compute the signing hash set the rules for a + transaction. For example, signing over the gas sets a limit for the + amount of money that is allowed to be pulled out of the sender's account. + + Parameters + ---------- + tx : + Transaction of interest. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the transaction. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "nonce" |); M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |); M.get_field (| M.get_name (| globals, "tx" |), "gas" |); M.get_field (| M.get_name (| globals, "tx" |), "to" |); M.get_field (| M.get_name (| globals, "tx" |), "value" |); M.get_field (| M.get_name (| globals, "tx" |), "data" |) ] + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition compute_header_hash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header" ] |) in + let _ := Constant.str " + Computes the hash of a block header. + + The header hash of a block is the canonical hash that is used to refer + to a specific block and completely distinguishes a block from another. + + ``keccak256`` is a function that produces a 256 bit hash of any input. + It also takes in any number of bytes as an input and produces a single + hash for them. A hash is a completely unique output for a single input. + So an input corresponds to one unique hash that can be used to identify + the input exactly. + + Prior to using the ``keccak256`` hash function, the header must be + encoded using the Recursive-Length Prefix. See :ref:`rlp`. + RLP encoding the header converts it into a space-efficient format that + allows for easy transfer of data between nodes. The purpose of RLP is to + encode arbitrarily nested arrays of binary data, and RLP is the primary + encoding method used to serialize objects in Ethereum's execution layer. + The only purpose of RLP is to encode structure; encoding specific data + types (e.g. strings, floats) is left up to higher-order protocols. + + Parameters + ---------- + header : + Header of interest. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the header. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "header" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition check_gas_limit : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "gas_limit"; "parent_gas_limit" ] |) in + let _ := Constant.str " + Validates the gas limit for a block. + + The bounds of the gas limit, ``max_adjustment_delta``, is set as the + quotient of the parent block's gas limit and the + ``GAS_LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is + passed through as a parameter is greater than or equal to the *sum* of + the parent's gas and the adjustment delta then the limit for gas is too + high and fails this function's check. Similarly, if the limit is less + than or equal to the *difference* of the parent's gas and the adjustment + delta *or* the predefined ``GAS_LIMIT_MINIMUM`` then this function's + check fails because the gas limit doesn't allow for a sufficient or + reasonable amount of gas to be used on a block. + + Parameters + ---------- + gas_limit : + Gas limit to validate. + + parent_gas_limit : + Gas limit of the parent block. + + Returns + ------- + check : `bool` + True if gas limit constraints are satisfied, False otherwise. + " in + let max_adjustment_delta := + BinOp.floor_div (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "gas_limit" |), BinOp.add (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| M.get_name (| globals, "gas_limit" |), BinOp.sub (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "gas_limit" |), M.get_name (| globals, "GAS_LIMIT_MINIMUM" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + Constant.bool true + |) in + M.pure Constant.None_)). + +Definition calculate_block_difficulty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "block_number"; "block_timestamp"; "parent_timestamp"; "parent_difficulty" ] |) in + let _ := Constant.str " + Computes difficulty of a block using its header and + parent header. + + The difficulty of a block is determined by the time the block was + created after its parent. If a block's timestamp is more than 13 + seconds after its parent block then its difficulty is set as the + difference between the parent's difficulty and the + ``max_adjustment_delta``. Otherwise, if the time between parent and + child blocks is too small (under 13 seconds) then, to avoid mass + forking, the block's difficulty is set to the sum of the delta and + the parent's difficulty. + + Parameters + ---------- + block_number : + Block number of the block. + block_timestamp : + Timestamp of the block. + parent_timestamp : + Timestamp of the parent block. + parent_difficulty : + difficulty of the parent block. + + Returns + ------- + difficulty : `ethereum.base_types.Uint` + Computed difficulty for a block. + " in + let max_adjustment_delta := + BinOp.floor_div (| + M.get_name (| globals, "parent_difficulty" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 2048 + ], + make_dict [] + |) + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "block_timestamp" |), BinOp.add (| + M.get_name (| globals, "parent_timestamp" |), + Constant.int 13 + |) |), + (* then *) + ltac:(M.monadic ( + let difficulty := + BinOp.add (| + M.get_name (| globals, "parent_difficulty" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let difficulty := + BinOp.sub (| + M.get_name (| globals, "parent_difficulty" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) in + M.pure Constant.None_ + )) |) in + let num_bomb_periods := + BinOp.sub (| + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "block_number" |) + ], + make_dict [] + |), + Constant.int 100000 + |), + Constant.int 2 + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "num_bomb_periods" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let difficulty := BinOp.add + BinOp.pow (| + Constant.int 2, + M.get_name (| globals, "num_bomb_periods" |) + |) + BinOp.pow (| + Constant.int 2, + M.get_name (| globals, "num_bomb_periods" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "max" |), + make_list [ + M.get_name (| globals, "difficulty" |); + M.get_name (| globals, "MINIMUM_DIFFICULTY" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/fork_types.v b/CoqOfPython/ethereum/frontier/fork_types.v new file mode 100644 index 0000000..d12953d --- /dev/null +++ b/CoqOfPython/ethereum/frontier/fork_types.v @@ -0,0 +1,102 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Types +^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Types re-used throughout the specification, which are specific to Ethereum. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes20 : + IsGlobalAlias globals base_types.globals "Bytes20". +Axiom base_types_Bytes256 : + IsGlobalAlias globals base_types.globals "Bytes256". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require crypto.hash. +Axiom crypto_hash_Hash32 : + IsGlobalAlias globals crypto.hash.globals "Hash32". +Axiom crypto_hash_keccak256 : + IsGlobalAlias globals crypto.hash.globals "keccak256". + +Definition Address : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Bytes20" |) +)). + +Definition Root : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Hash32" |) +)). + +Definition Bloom : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Bytes256" |) +)). + +Definition Account : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition EMPTY_ACCOUNT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Account" |), + make_list [], + make_dict [] + |) +)). + +Definition encode_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "raw_account_data"; "storage_root" ] |) in + let _ := Constant.str " + Encode `Account` dataclass. + + Storage is not stored in the `Account` dataclass, so `Accounts` cannot be + encoded with providing a storage root. + " in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "raw_account_data" |), "nonce" |); M.get_field (| M.get_name (| globals, "raw_account_data" |), "balance" |); M.get_name (| globals, "storage_root" |); M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_field (| M.get_name (| globals, "raw_account_data" |), "code" |) + ], + make_dict [] + |) ] + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/state.v b/CoqOfPython/ethereum/frontier/state.v new file mode 100644 index 0000000..38fe9d1 --- /dev/null +++ b/CoqOfPython/ethereum/frontier/state.v @@ -0,0 +1,865 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +State +^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The state contains all information that is preserved between transactions. + +It consists of a main account trie and storage tries for each contract. + +There is a distinction between an account that does not exist and +`EMPTY_ACCOUNT`. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_field : + IsGlobalAlias globals dataclasses.globals "field". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_modify : + IsGlobalAlias globals ethereum.base_types.globals "modify". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require fork_types. +Axiom fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". +Axiom fork_types_Account : + IsGlobalAlias globals fork_types.globals "Account". +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Require trie. +Axiom trie_EMPTY_TRIE_ROOT : + IsGlobalAlias globals trie.globals "EMPTY_TRIE_ROOT". +Axiom trie_Trie : + IsGlobalAlias globals trie.globals "Trie". +Axiom trie_copy_trie : + IsGlobalAlias globals trie.globals "copy_trie". +Axiom trie_root : + IsGlobalAlias globals trie.globals "root". +Axiom trie_trie_get : + IsGlobalAlias globals trie.globals "trie_get". +Axiom trie_trie_set : + IsGlobalAlias globals trie.globals "trie_set". + +Definition State : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition close_state : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Free resources held by the state. Used by optimized implementations to + release file descriptors. + " in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) |) in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |) in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) in + M.pure Constant.None_)). + +Definition begin_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Start a state transaction. + + Transactions are entirely implicit and can be nested. It is not possible to + calculate the state root during a transaction. + + Parameters + ---------- + state : State + The state. + " in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), "append" |), + make_list [ + make_tuple [ M.call (| + M.get_name (| globals, "copy_trie" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) + ], + make_dict [] + |); {M.get_name (| globals, "k" |): M.call (| + M.get_name (| globals, "copy_trie" |), + make_list [ + M.get_name (| globals, "t" |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)} ] + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition commit_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Commit a state transaction. + + Parameters + ---------- + state : State + The state. + " in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), "pop" |), + make_list [], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition rollback_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Rollback a state transaction, resetting the state to the point when the + corresponding `start_transaction()` call was made. + + Parameters + ---------- + state : State + The state. + " in + let _ := M.assign (| + make_tuple [ M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) ], + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), "pop" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition get_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Get the `Account` object at an address. Returns `EMPTY_ACCOUNT` if there + is no account at the address. + + Use `get_account_optional()` if you care about the difference between a + non-existent account and `EMPTY_ACCOUNT`. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address to lookup. + + Returns + ------- + account : `Account` + Account at address. + " in + let account := + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "account" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "account" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "EMPTY_ACCOUNT" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition get_account_optional : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Get the `Account` object at an address. Returns `None` (rather than + `EMPTY_ACCOUNT`) if there is no account at the address. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address to lookup. + + Returns + ------- + account : `Account` + Account at address. + " in + let account := + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "account" |) + |) in + M.pure Constant.None_)). + +Definition set_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "account" ] |) in + let _ := Constant.str " + Set the `Account` object at an address. Setting to `None` deletes + the account (but not its storage, see `destroy_account()`). + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address to set. + account : `Account` + Account to set at address. + " in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "account" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition destroy_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Completely remove the account at `address` and all of its storage. + + This function is made available exclusively for the `SELFDESTRUCT` + opcode. It is expected that `SELFDESTRUCT` will be disabled in a future + hardfork and this function will be removed. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of account to destroy. + " in + let _ := M.call (| + M.get_name (| globals, "destroy_storage" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + Constant.None_ + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition destroy_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Completely remove the storage at `address`. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of account whose storage is to be deleted. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition get_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "key" ] |) in + let _ := Constant.str " + Get a value at a storage key on an account. Returns `U256(0)` if the + storage key has not been set previously. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of the account. + key : `Bytes` + Key to lookup. + + Returns + ------- + value : `U256` + Value at the key. + " in + let trie := + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let _ := M.assert (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "U256" |) + ], + make_dict [] + |) |) in + let _ := M.return_ (| + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_)). + +Definition set_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "key"; "value" ] |) in + let _ := Constant.str " + Set a value at a storage key on an account. Setting to `U256(0)` deletes + the key. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of the account. + key : `Bytes` + Key to set. + value : `U256` + Value to set at the key. + " in + let _ := M.assert (| Compare.is_not (| M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), Constant.None_ |) |) in + let trie := + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let trie := + M.call (| + M.get_name (| globals, "Trie" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), + M.get_name (| globals, "trie" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "key" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), {} |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition storage_root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Calculate the storage root of an account. + + Parameters + ---------- + state: + The state + address : + Address of the account. + + Returns + ------- + root : `Root` + Storage root of the account. + " in + let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "EMPTY_TRIE_ROOT" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition state_root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Calculate the state root. + + Parameters + ---------- + state: + The current state. + + Returns + ------- + root : `Root` + The state root. + " in + let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition account_exists : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account exists in the state trie + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + account_exists : `bool` + True if account exists in the state trie, False otherwise + " in + let _ := M.return_ (| + Compare.is_not (| M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), Constant.None_ |) + |) in + M.pure Constant.None_)). + +Definition account_has_code_or_nonce : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account has non zero nonce or non empty code + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + has_code_or_nonce : `bool` + True if if an account has non zero nonce or non empty code, + False otherwise. + " in + let account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + BoolOp.or (| + Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |) + )) + |) + |) in + M.pure Constant.None_)). + +Definition modify_state : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "f" ] |) in + let _ := Constant.str " + Modify an `Account` in the `State`. + " in + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.call (| + M.get_name (| globals, "modify" |), + make_list [ + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |); + M.get_name (| globals, "f" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition move_ether : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "sender_address"; "recipient_address"; "amount" ] |) in + let _ := Constant.str " + Move funds between accounts. + " in +(* At stmt: unsupported node type: FunctionDef *) +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "sender_address" |); + M.get_name (| globals, "reduce_sender_balance" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "recipient_address" |); + M.get_name (| globals, "increase_recipient_balance" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition set_account_balance : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "amount" ] |) in + let _ := Constant.str " + Sets the balance of an account. + + Parameters + ---------- + state: + The current state. + + address: + Address of the account whose nonce needs to be incremented. + + amount: + The amount that needs to set in balance. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "set_balance" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition touch_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Initializes an account to state. + + Parameters + ---------- + state: + The current state. + + address: + The address of the account that need to initialised. + " in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "account_exists" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "EMPTY_ACCOUNT" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition increment_nonce : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Increments the nonce of an account. + + Parameters + ---------- + state: + The current state. + + address: + Address of the account whose nonce needs to be incremented. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "increase_nonce" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition set_code : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "code" ] |) in + let _ := Constant.str " + Sets Account code. + + Parameters + ---------- + state: + The current state. + + address: + Address of the account whose code needs to be update. + + code: + The bytecode that needs to be set. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "write_code" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition create_ether : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "amount" ] |) in + let _ := Constant.str " + Add newly created ether to an account. + + Parameters + ---------- + state: + The current state. + address: + Address of the account to which ether is added. + amount: + The amount of ether to be added to the account of interest. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "increase_balance" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/transactions.v b/CoqOfPython/ethereum/frontier/transactions.v new file mode 100644 index 0000000..c9ea3bf --- /dev/null +++ b/CoqOfPython/ethereum/frontier/transactions.v @@ -0,0 +1,56 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Transactions are atomic units of work created externally to Ethereum and +submitted to be executed. If Ethereum is viewed as a state machine, +transactions are the events that move between states. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes0 : + IsGlobalAlias globals base_types.globals "Bytes0". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( + Constant.int 21000 +)). + +Definition TX_DATA_COST_PER_NON_ZERO : Value.t := M.run ltac:(M.monadic ( + Constant.int 68 +)). + +Definition TX_DATA_COST_PER_ZERO : Value.t := M.run ltac:(M.monadic ( + Constant.int 4 +)). + +Definition Transaction : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. diff --git a/CoqOfPython/ethereum/frontier/trie.v b/CoqOfPython/ethereum/frontier/trie.v new file mode 100644 index 0000000..85234ca --- /dev/null +++ b/CoqOfPython/ethereum/frontier/trie.v @@ -0,0 +1,1350 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +State Trie +^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The state trie is the structure responsible for storing +`.fork_types.Account` objects. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_field : + IsGlobalAlias globals dataclasses.globals "field". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". +Axiom typing_Generic : + IsGlobalAlias globals typing.globals "Generic". +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Mapping : + IsGlobalAlias globals typing.globals "Mapping". +Axiom typing_MutableMapping : + IsGlobalAlias globals typing.globals "MutableMapping". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Sequence : + IsGlobalAlias globals typing.globals "Sequence". +Axiom typing_TypeVar : + IsGlobalAlias globals typing.globals "TypeVar". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". +Axiom typing_cast : + IsGlobalAlias globals typing.globals "cast". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require ethereum.utils.hexadecimal. +Axiom ethereum_utils_hexadecimal_hex_to_bytes : + IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require blocks. +Axiom blocks_Receipt : + IsGlobalAlias globals blocks.globals "Receipt". + +Require fork_types. +Axiom fork_types_Account : + IsGlobalAlias globals fork_types.globals "Account". +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". +Axiom fork_types_encode_account : + IsGlobalAlias globals fork_types.globals "encode_account". + +Require transactions. +Axiom transactions_Transaction : + IsGlobalAlias globals transactions.globals "Transaction". + +Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Root" |), + make_list [ + M.call (| + M.get_name (| globals, "hex_to_bytes" |), + make_list [ + Constant.str "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" + ], + make_dict [] + |) + ], + make_dict [] + |) +)). + +Definition Node : Value.t := M.run ltac:(M.monadic ( + M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Bytes" |); M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |); Constant.None_ ] |) +)). + +Definition K : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "TypeVar" |), + make_list [ + Constant.str "K" + ], + make_dict [] + |) +)). + +Definition V : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "TypeVar" |), + make_list [ + Constant.str "V"; + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Account" |) |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Bytes" |) |); + M.get_name (| globals, "Bytes" |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Transaction" |) |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Receipt" |) |); + M.get_name (| globals, "Uint" |); + M.get_name (| globals, "U256" |) + ], + make_dict [] + |) +)). + +Definition LeafNode : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition ExtensionNode : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition BranchNode : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition InternalNode : Value.t := M.run ltac:(M.monadic ( + M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LeafNode" |); M.get_name (| globals, "ExtensionNode" |); M.get_name (| globals, "BranchNode" |) ] |) +)). + +Definition encode_internal_node : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "node" ] |) in + let _ := Constant.str " + Encodes a Merkle Trie node into its RLP form. The RLP will then be + serialized into a `Bytes` and hashed unless it is less that 32 bytes + when serialized. + + This function also accepts `None`, representing the absence of a node, + which is encoded to `b""""""`. + + Parameters + ---------- + node : Optional[InternalNode] + The node to encode. + + Returns + ------- + encoded : `rlp.RLP` + The node encoded as RLP. + " in +(* At stmt: unsupported node type: AnnAssign *) + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "node" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let unencoded := + (* At constant: unsupported node type: Constant *) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "LeafNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "rest_of_key" |); + Constant.bool true + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "ExtensionNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "key_segment" |); + Constant.bool false + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "BranchNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + BinOp.add (| + M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "value" |) + ] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "AssertionError" |), + make_list [ + (* At expr: unsupported node type: JoinedStr *) + ], + make_dict [] + |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let encoded := + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "unencoded" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded" |) + ], + make_dict [] + |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "unencoded" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "encoded" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition encode_node : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "node"; "storage_root" ] |) in + let _ := Constant.str " + Encode a Node for storage in the Merkle Trie. + + Currently mostly an unimplemented stub. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "storage_root" |), Constant.None_ |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "encode_account" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "storage_root" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + make_tuple [ M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "U256" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "cast" |), + make_list [ + M.get_field (| M.get_name (| globals, "rlp" |), "RLP" |); + M.get_name (| globals, "node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "node" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "AssertionError" |), + make_list [ + (* At expr: unsupported node type: JoinedStr *) + ], + make_dict [] + |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition Trie : Value.t := + builtins.make_klass + [(* At base: unsupported node type: Subscript *)] + [ + + ] + [ + + ]. + +Definition copy_trie : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie" ] |) in + let _ := Constant.str " + Create a copy of `trie`. Since only frozen objects may be stored in tries, + the contents are reused. + + Parameters + ---------- + trie: `Trie` + Trie to copy. + + Returns + ------- + new_trie : `Trie[K, V]` + A copy of the trie. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Trie" |), + make_list [ + M.get_field (| M.get_name (| globals, "trie" |), "secured" |); + M.get_field (| M.get_name (| globals, "trie" |), "default" |); + M.call (| + M.get_field (| M.get_name (| globals, "copy" |), "copy" |), + make_list [ + M.get_field (| M.get_name (| globals, "trie" |), "_data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition trie_set : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "key"; "value" ] |) in + let _ := Constant.str " + Stores an item in a Merkle Trie. + + This method deletes the key if `value == trie.default`, because the Merkle + Trie represents the default value by omitting it from the trie. + + Parameters + ---------- + trie: `Trie` + Trie to store in. + key : `Bytes` + Key to lookup. + value : `V` + Node to insert at `key`. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "value" |), M.get_field (| M.get_name (| globals, "trie" |), "default" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "key" |), M.get_field (| M.get_name (| globals, "trie" |), "_data" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition trie_get : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "key" ] |) in + let _ := Constant.str " + Gets an item from the Merkle Trie. + + This method returns `trie.default` if the key is missing. + + Parameters + ---------- + trie: + Trie to lookup in. + key : + Key to lookup. + + Returns + ------- + node : `V` + Node at `key` in the trie. + " in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "get" |), + make_list [ + M.get_name (| globals, "key" |); + M.get_field (| M.get_name (| globals, "trie" |), "default" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition common_prefix_length : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "a"; "b" ] |) in + let _ := Constant.str " + Find the longest common prefix of two sequences. + " in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + ], + make_dict [] + |) do + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| M.get_name (| globals, "i" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition nibble_list_to_compact : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "x"; "is_leaf" ] |) in + let _ := Constant.str " + Compresses nibble-list into a standard byte array with a flag. + + A nibble-list is a list of byte values no greater than `15`. The flag is + encoded in high nibble of the highest byte. The flag nibble can be broken + down into two two-bit flags. + + Highest nibble:: + + +---+---+----------+--------+ + | _ | _ | is_leaf | parity | + +---+---+----------+--------+ + 3 2 1 0 + + + The lowest bit of the nibble encodes the parity of the length of the + remaining nibbles -- `0` when even and `1` when odd. The second lowest bit + is used to distinguish leaf and extension nodes. The other two bits are not + used. + + Parameters + ---------- + x : + Array of nibbles. + is_leaf : + True if this is part of a leaf node, or false if it is an extension + node. + + Returns + ------- + compressed : `bytearray` + Compact byte array. + " in + let compact := + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + Constant.int 2 + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.mult (| + Constant.int 16, + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "is_leaf" |) + |) + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + BinOp.add (| + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "is_leaf" |) + |), + Constant.int 1 + |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), Constant.int 0 |) + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 1; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + M.get_name (| globals, "compact" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition bytes_to_nibble_list : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "bytes_" ] |) in + let _ := Constant.str " + Converts a `Bytes` into to a sequence of nibbles (bytes with value < 16). + + Parameters + ---------- + bytes_: + The `Bytes` to convert. + + Returns + ------- + nibble_list : `Bytes` + The `Bytes` in nibble-list format. + " in + let nibble_list := + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [ + BinOp.mult (| + Constant.int 2, + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "bytes_" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + For make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ] in M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "bytes_" |) + ], + make_dict [] + |) do + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |) |), + BinOp.r_shift (| + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 240 + |), + Constant.int 4 + |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |), + Constant.int 1 + |) |), + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 15 + |) + |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + M.get_name (| globals, "nibble_list" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition _prepare_trie : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "get_storage_root" ] |) in + let _ := Constant.str " + Prepares the trie for root calculation. Removes values that are empty, + hashes the keys (if `secured == True`) and encodes all the nodes. + + Parameters + ---------- + trie : + The `Trie` to prepare. + get_storage_root : + Function to get the storage root of an account. Needed to encode + `Account` objects. + + Returns + ------- + out : `Mapping[ethereum.base_types.Bytes, Node]` + Object with keys mapped to nibble-byte form. + " in +(* At stmt: unsupported node type: AnnAssign *) + For make_tuple [ M.get_name (| globals, "preimage" |); M.get_name (| globals, "value" |) ] in M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "items" |), + make_list [], + make_dict [] + |) do + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in + let address := + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |); + M.call (| + M.get_name (| globals, "get_storage_root" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_eq (| M.get_name (| globals, "encoded_value" |), (* At constant: unsupported node type: Constant *) |); + M.get_name (| globals, "AssertionError" |) + ], + make_dict [] + |) in +(* At stmt: unsupported node type: AnnAssign *) + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "trie" |), "secured" |), + (* then *) + ltac:(M.monadic ( + let key := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let key := + M.get_name (| globals, "preimage" |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "mapped" |), M.call (| + M.get_name (| globals, "bytes_to_nibble_list" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |) |), + M.get_name (| globals, "encoded_value" |) + |) in + EndFor. + let _ := M.return_ (| + M.get_name (| globals, "mapped" |) + |) in + M.pure Constant.None_)). + +Definition root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "get_storage_root" ] |) in + let _ := Constant.str " + Computes the root of a modified merkle patricia trie (MPT). + + Parameters + ---------- + trie : + `Trie` to get the root of. + get_storage_root : + Function to get the storage root of an account. Needed to encode + `Account` objects. + + + Returns + ------- + root : `.fork_types.Root` + MPT root of the underlying key-value pairs. + " in + let obj := + M.call (| + M.get_name (| globals, "_prepare_trie" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "get_storage_root" |) + ], + make_dict [] + |) in + let root_node := + M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_name (| globals, "obj" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assert (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "root_node" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Root" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition patricialize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "obj"; "level" ] |) in + let _ := Constant.str " + Structural composition function. + + Used to recursively patricialize and merkleize a dictionary. Includes + memoization of the tree structure and hashes. + + Parameters + ---------- + obj : + Underlying trie key-value pairs, with keys in nibble-list format. + level : + Current trie level. + + Returns + ------- + node : `ethereum.base_types.Bytes` + Root node of `obj`. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let arbitrary_key := + M.call (| + M.get_name (| globals, "next" |), + make_list [ + M.call (| + M.get_name (| globals, "iter" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), Constant.int 1 |), + (* then *) + ltac:(M.monadic ( + let leaf := + M.call (| + M.get_name (| globals, "LeafNode" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |); + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "leaf" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let substring := + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) in + let prefix_length := + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "substring" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do + let prefix_length := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_name (| globals, "prefix_length" |); + M.call (| + M.get_name (| globals, "common_prefix_length" |), + make_list [ + M.get_name (| globals, "substring" |); + M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let prefix := + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ExtensionNode" |), + make_list [ + M.get_name (| globals, "prefix" |); + M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_name (| globals, "obj" |); + BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in +(* At stmt: unsupported node type: AnnAssign *) + For M.get_name (| globals, "_" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 16 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "branches" |), "append" |), + make_list [ + {} + ], + make_dict [] + |) in + EndFor. + let value := + (* At constant: unsupported node type: Constant *) in + For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |), M.get_name (| globals, "level" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "AssertionError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) + |) in + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "BranchNode" |), + make_list [ + [M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "branches" |), M.get_name (| globals, "k" |) |); + BinOp.add (| + M.get_name (| globals, "level" |), + Constant.int 1 + |) + ], + make_dict [] + |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)]; + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/utils/__init__.v b/CoqOfPython/ethereum/frontier/utils/__init__.v new file mode 100644 index 0000000..1baedea --- /dev/null +++ b/CoqOfPython/ethereum/frontier/utils/__init__.v @@ -0,0 +1,8 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Utility functions unique to this particular fork. +". diff --git a/CoqOfPython/ethereum/frontier/utils/address.v b/CoqOfPython/ethereum/frontier/utils/address.v new file mode 100644 index 0000000..4ee1ff9 --- /dev/null +++ b/CoqOfPython/ethereum/frontier/utils/address.v @@ -0,0 +1,133 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Hardfork Utility Functions For Addresses +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Address specific functions used in this frontier version of specification. +". + +Require typing. +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_left_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Definition to_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "data" ] |) in + let _ := Constant.str " + Convert a Uint or U256 value to a valid address (20 bytes). + + Parameters + ---------- + data : + The string to be converted to bytes. + + Returns + ------- + address : `Address` + The obtained address. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_subscript (| M.call (| + M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition compute_contract_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "address"; "nonce" ] |) in + let _ := Constant.str " + Computes address of the new account that needs to be created. + + Parameters + ---------- + address : + The address of the account that wants to create the new account. + nonce : + The transaction count of the account that wants to create the new + account. + + Returns + ------- + address: `ethereum.frontier.fork_types.Address` + The computed address of the new account. + " in + let computed_address := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_list [ + M.get_name (| globals, "address" |); + M.get_name (| globals, "nonce" |) + ] + ], + make_dict [] + |) + ], + make_dict [] + |) in + let canonical_address := + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + let padded_address := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "canonical_address" |); + Constant.int 20 + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "padded_address" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/utils/hexadecimal.v b/CoqOfPython/ethereum/frontier/utils/hexadecimal.v new file mode 100644 index 0000000..44b9f35 --- /dev/null +++ b/CoqOfPython/ethereum/frontier/utils/hexadecimal.v @@ -0,0 +1,155 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Utility Functions For Hexadecimal Strings +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Hexadecimal utility functions used in this specification, specific to Frontier +types. +". + +Require ethereum.utils.hexadecimal. +Axiom ethereum_utils_hexadecimal_remove_hex_prefix : + IsGlobalAlias globals ethereum.utils.hexadecimal.globals "remove_hex_prefix". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Definition hex_to_root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to trie root. + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to trie root. + + Returns + ------- + root : `Root` + Trie root obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Root" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition hex_to_bloom : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to bloom. + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to bloom. + + Returns + ------- + bloom : `Bloom` + Bloom obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bloom" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition hex_to_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to Address (20 bytes). + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to Address. + + Returns + ------- + address : `Address` + The address obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |), "rjust" |), + make_list [ + Constant.int 40; + Constant.str "0" + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/utils/message.v b/CoqOfPython/ethereum/frontier/utils/message.v new file mode 100644 index 0000000..6b13d93 --- /dev/null +++ b/CoqOfPython/ethereum/frontier/utils/message.v @@ -0,0 +1,195 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Hardfork Utility Functions For The Message Data-structure +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Message specific functions used in this frontier version of specification. +". + +Require typing. +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". + +Require vm. +Axiom vm_Environment : + IsGlobalAlias globals vm.globals "Environment". +Axiom vm_Message : + IsGlobalAlias globals vm.globals "Message". + +Require address. +Axiom address_compute_contract_address : + IsGlobalAlias globals address.globals "compute_contract_address". + +Definition prepare_message : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "caller"; "target"; "value"; "data"; "gas"; "env"; "code_address" ] |) in + let _ := Constant.str " + Execute a transaction against the provided environment. + + Parameters + ---------- + caller : + Address which initiated the transaction + target : + Address whose code will be executed + value : + Value to be transferred. + data : + Array of bytes provided to the code in `target`. + gas : + Gas provided for the code in `target`. + env : + Environment for the Ethereum Virtual Machine. + code_address : + This is usually same as the `target` address except when an alternative + accounts code needs to be executed. + eg. `CALLCODE` calling a precompile. + + Returns + ------- + message: `ethereum.frontier.vm.Message` + Items containing contract creation or message call specific data. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Bytes0" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.call (| + M.get_name (| globals, "compute_contract_address" |), + make_list [ + M.get_name (| globals, "caller" |); + BinOp.sub (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "caller" |) + ], + make_dict [] + |), "nonce" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let msg_data := + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |) in + let code := + M.get_name (| globals, "data" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.get_name (| globals, "target" |) in + let msg_data := + M.get_name (| globals, "data" |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "target" |) + ], + make_dict [] + |), "code" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "code_address" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let code_address := + M.get_name (| globals, "target" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "AssertionError" |), + make_list [ + Constant.str "Target must be address or empty bytes" + ], + make_dict [] + |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/vm/__init__.v b/CoqOfPython/ethereum/frontier/vm/__init__.v new file mode 100644 index 0000000..49bcb40 --- /dev/null +++ b/CoqOfPython/ethereum/frontier/vm/__init__.v @@ -0,0 +1,152 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The abstract computer which runs the code stored in an +`.fork_types.Account`. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_State : + IsGlobalAlias globals state.globals "State". + +Definition __all__ : Value.t := M.run ltac:(M.monadic ( + make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] +)). + +Definition Environment : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Message : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Evm : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition incorporate_child_on_success : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "child_evm" ] |) in + let _ := Constant.str " + Incorporate the state of a successful `child_evm` into the parent `evm`. + + Parameters + ---------- + evm : + The parent `EVM`. + child_evm : + The child evm to incorporate. + " in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "gas_left" |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "logs" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "logs" |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "refund_counter" |) + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "accounts_to_delete" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition incorporate_child_on_error : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "child_evm" ] |) in + let _ := Constant.str " + Incorporate the state of an unsuccessful `child_evm` into the parent `evm`. + + Parameters + ---------- + evm : + The parent `EVM`. + child_evm : + The child evm to incorporate. + " in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "gas_left" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/vm/exceptions.v b/CoqOfPython/ethereum/frontier/vm/exceptions.v new file mode 100644 index 0000000..45435b3 --- /dev/null +++ b/CoqOfPython/ethereum/frontier/vm/exceptions.v @@ -0,0 +1,122 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Exceptions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Exceptions which cause the EVM to halt exceptionally. +". + +Require ethereum.exceptions. +Axiom ethereum_exceptions_EthereumException : + IsGlobalAlias globals ethereum.exceptions.globals "EthereumException". + +Definition ExceptionalHalt : Value.t := + builtins.make_klass + [(globals, "EthereumException")] + [ + + ] + [ + + ]. + +Definition StackUnderflowError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition StackOverflowError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition OutOfGasError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition InvalidOpcode : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + ( + "__init__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "code" ] |) in + let _ := M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "super" |), + make_list [], + make_dict [] + |), "__init__" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "self" |), "code" |), + M.get_name (| globals, "code" |) + |) in + M.pure Constant.None_)) + ) + ]. + +Definition InvalidJumpDestError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition StackDepthLimitError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition AddressCollision : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/__init__.v b/CoqOfPython/ethereum/frontier/vm/instructions/__init__.v new file mode 100644 index 0000000..e5bebd7 --- /dev/null +++ b/CoqOfPython/ethereum/frontier/vm/instructions/__init__.v @@ -0,0 +1,87 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +EVM Instruction Encoding (Opcodes) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Machine readable representations of EVM instructions, and a mapping to their +implementations. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". + +Require __init__. +Axiom __init___arithmetic : + IsGlobalAlias globals __init__.globals "arithmetic". + +Require __init__. +Axiom __init___bitwise : + IsGlobalAlias globals __init__.globals "bitwise". + +Require __init__. +Axiom __init___block : + IsGlobalAlias globals __init__.globals "block". + +Require __init__. +Axiom __init___comparison : + IsGlobalAlias globals __init__.globals "comparison". + +Require __init__. +Axiom __init___control_flow : + IsGlobalAlias globals __init__.globals "control_flow". + +Require __init__. +Axiom __init___environment : + IsGlobalAlias globals __init__.globals "environment". + +Require __init__. +Axiom __init___keccak : + IsGlobalAlias globals __init__.globals "keccak". + +Require __init__. +Axiom __init___log : + IsGlobalAlias globals __init__.globals "log". + +Require __init__. +Axiom __init___memory : + IsGlobalAlias globals __init__.globals "memory". + +Require __init__. +Axiom __init___stack : + IsGlobalAlias globals __init__.globals "stack". + +Require __init__. +Axiom __init___storage : + IsGlobalAlias globals __init__.globals "storage". + +Require __init__. +Axiom __init___system : + IsGlobalAlias globals __init__.globals "system". + +Definition Ops : Value.t := + builtins.make_klass + [(* At base: unsupported node type: Attribute *)] + [ + + ] + [ + + ]. + +(* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/frontier/vm/instructions/arithmetic.v new file mode 100644 index 0000000..a8b5c61 --- /dev/null +++ b/CoqOfPython/ethereum/frontier/vm/instructions/arithmetic.v @@ -0,0 +1,1085 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Arithmetic Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM Arithmetic instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U255_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U255_CEIL_VALUE". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_U256_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_get_sign : + IsGlobalAlias globals ethereum.utils.numeric.globals "get_sign". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_EXPONENTIATION : + IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION". +Axiom gas_GAS_EXPONENTIATION_PER_BYTE : + IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION_PER_BYTE". +Axiom gas_GAS_LOW : + IsGlobalAlias globals gas.globals "GAS_LOW". +Axiom gas_GAS_MID : + IsGlobalAlias globals gas.globals "GAS_MID". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition add : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Adds the top two elements of the stack together, and pushes the result back + on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "x" |), "wrapping_add" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition sub : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Subtracts the top two elements of the stack, and pushes the result back + on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "x" |), "wrapping_sub" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mul : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Multiply the top two elements of the stack, and pushes the result back + on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "x" |), "wrapping_mul" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition div : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Integer division of the top two elements of the stack. Pushes the result + back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let dividend := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let divisor := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let quotient := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let quotient := + BinOp.floor_div (| + M.get_name (| globals, "dividend" |), + M.get_name (| globals, "divisor" |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "quotient" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition sdiv : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed integer division of the top two elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let dividend := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let divisor := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let quotient := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_name (| globals, "dividend" |), UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "divisor" |), UnOp.sub (| Constant.int 1 |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let quotient := + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let sign := + M.call (| + M.get_name (| globals, "get_sign" |), + make_list [ + BinOp.mult (| + M.get_name (| globals, "dividend" |), + M.get_name (| globals, "divisor" |) + |) + ], + make_dict [] + |) in + let quotient := + BinOp.mult (| + M.get_name (| globals, "sign" |), + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "dividend" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "divisor" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + M.get_name (| globals, "quotient" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Modulo remainder of the top two elements of the stack. Pushes the result + back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let remainder := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let remainder := + BinOp.mod_ (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "remainder" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition smod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed modulo remainder of the top two elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let y := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let remainder := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let remainder := + BinOp.mult (| + M.call (| + M.get_name (| globals, "get_sign" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + BinOp.mod_ (| + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + M.get_name (| globals, "remainder" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition addmod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Modulo addition of the top 2 elements with the 3rd element. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let z := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_MID" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.add (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |), + M.get_name (| globals, "z" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mulmod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Modulo multiplication of the top 2 elements with the 3rd element. Pushes + the result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let z := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_MID" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.mult (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |), + M.get_name (| globals, "z" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition exp : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Exponential operation of the top 2 elements. Pushes the result back on + the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let base := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exponent := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exponent_bits := + M.call (| + M.get_field (| M.get_name (| globals, "exponent" |), "bit_length" |), + make_list [], + make_dict [] + |) in + let exponent_bytes := + BinOp.floor_div (| + BinOp.add (| + M.get_name (| globals, "exponent_bits" |), + Constant.int 7 + |), + Constant.int 8 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_EXPONENTIATION" |), + BinOp.mult (| + M.get_name (| globals, "GAS_EXPONENTIATION_PER_BYTE" |), + M.get_name (| globals, "exponent_bytes" |) + |) + |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "pow" |), + make_list [ + M.get_name (| globals, "base" |); + M.get_name (| globals, "exponent" |); + M.get_name (| globals, "U256_CEIL_VALUE" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition signextend : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Sign extend operation. In other words, extend a signed number which + fits in N bytes to 32 bytes. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let byte_num := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "byte_num" |), Constant.int 31 |), + (* then *) + ltac:(M.monadic ( + let result := + M.get_name (| globals, "value" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let value_bytes := + M.call (| + M.get_name (| globals, "bytes" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "value" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) in + let value_bytes := + M.get_subscript (| M.get_name (| globals, "value_bytes" |), BinOp.sub (| + Constant.int 31, + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "byte_num" |) + ], + make_dict [] + |) + |):(* At expr: unsupported node type: NoneType *) |) in + let sign_bit := + BinOp.r_shift (| + M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), + Constant.int 7 + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "sign_bit" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "value_bytes" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let num_bytes_prepend := + BinOp.sub (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "byte_num" |), + Constant.int 1 + |) + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + BinOp.add (| + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [ + BinOp.mult (| + make_list [ + Constant.int 255 + ], + M.get_name (| globals, "num_bytes_prepend" |) + |) + ], + make_dict [] + |), + M.get_name (| globals, "value_bytes" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/bitwise.v b/CoqOfPython/ethereum/frontier/vm/instructions/bitwise.v new file mode 100644 index 0000000..b20a1e5 --- /dev/null +++ b/CoqOfPython/ethereum/frontier/vm/instructions/bitwise.v @@ -0,0 +1,345 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Bitwise Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM bitwise instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition bitwise_and : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise AND operation of the top 2 elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + BinOp.bit_and (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_or : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise OR operation of the top 2 elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + BinOp.bit_or (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_xor : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise XOR operation of the top 2 elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + BinOp.bit_xor (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_not : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise NOT operation of the top element of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + UnOp.invert (| M.get_name (| globals, "x" |) |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition get_byte : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + For a word (defined by next top element of the stack), retrieve the + Nth byte (0-indexed and defined by top element of stack) from the + left (most significant) to right (least significant). + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let byte_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let word := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "byte_index" |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let extra_bytes_to_right := + BinOp.sub (| + Constant.int 31, + M.get_name (| globals, "byte_index" |) + |) in + let word := + BinOp.r_shift (| + M.get_name (| globals, "word" |), + BinOp.mult (| + M.get_name (| globals, "extra_bytes_to_right" |), + Constant.int 8 + |) + |) in + let word := + BinOp.bit_and (| + M.get_name (| globals, "word" |), + Constant.int 255 + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "word" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/block.v b/CoqOfPython/ethereum/frontier/vm/instructions/block.v new file mode 100644 index 0000000..e5fa554 --- /dev/null +++ b/CoqOfPython/ethereum/frontier/vm/instructions/block.v @@ -0,0 +1,337 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Block Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM block instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_BLOCK_HASH : + IsGlobalAlias globals gas.globals "GAS_BLOCK_HASH". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition block_hash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the hash of one of the 256 most recent complete blocks onto the + stack. The block number to hash is present at the top of the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let block_number := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BLOCK_HASH" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt_e (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), M.get_name (| globals, "block_number" |) |), + ltac:(M.monadic ( + Compare.gt (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), BinOp.add (| + M.get_name (| globals, "block_number" |), + Constant.int 256 + |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let hash := + (* At constant: unsupported node type: Constant *) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let hash := + M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + M.get_name (| globals, "block_number" |) + |) |) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "hash" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition coinbase : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's beneficiary address (address of the block miner) + onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "coinbase" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition timestamp : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's timestamp onto the stack. Here the timestamp + being referred is actually the unix timestamp in seconds. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "time" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition number : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's number onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition difficulty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's difficulty onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "difficulty" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition gas_limit : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's gas limit onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "gas_limit" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/comparison.v b/CoqOfPython/ethereum/frontier/vm/instructions/comparison.v new file mode 100644 index 0000000..fbc35f8 --- /dev/null +++ b/CoqOfPython/ethereum/frontier/vm/instructions/comparison.v @@ -0,0 +1,404 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Comparison Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM Comparison instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition less_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is less than the next top element. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let right := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition signed_less_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed less-than comparison. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let right := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition greater_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is greater than the next top element. Pushes + the result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let right := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition signed_greater_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed greater-than comparison. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let right := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition equal : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is equal to the next top element. Pushes + the result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let right := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.eq (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition is_zero : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is equal to 0. Pushes the result back on the + stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.eq (| M.get_name (| globals, "x" |), Constant.int 0 |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/control_flow.v b/CoqOfPython/ethereum/frontier/vm/instructions/control_flow.v new file mode 100644 index 0000000..04a79d9 --- /dev/null +++ b/CoqOfPython/ethereum/frontier/vm/instructions/control_flow.v @@ -0,0 +1,336 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Control Flow Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM control flow instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require vm.gas. +Axiom vm_gas_GAS_BASE : + IsGlobalAlias globals vm.gas.globals "GAS_BASE". +Axiom vm_gas_GAS_HIGH : + IsGlobalAlias globals vm.gas.globals "GAS_HIGH". +Axiom vm_gas_GAS_JUMPDEST : + IsGlobalAlias globals vm.gas.globals "GAS_JUMPDEST". +Axiom vm_gas_GAS_MID : + IsGlobalAlias globals vm.gas.globals "GAS_MID". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_InvalidJumpDestError : + IsGlobalAlias globals exceptions.globals "InvalidJumpDestError". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition stop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stop further execution of EVM code. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let _ := M.pass (| |) in + let _ := M.pass (| |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "running" |), + Constant.bool false + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition jump : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Alter the program counter to the location specified by the top of the + stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let jump_dest := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_MID" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "jump_dest" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition jumpi : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Alter the program counter to the specified location if and only if a + condition is true. If the condition is not true, then the program counter + would increase only by 1. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let jump_dest := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let conditional_value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_HIGH" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "conditional_value" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let destination := + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let destination := + M.get_name (| globals, "jump_dest" |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "destination" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition pc : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push onto the stack the value of the program counter after reaching the + current instruction and without increasing it for the next instruction. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "pc" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition gas_left : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the amount of available gas (including the corresponding reduction + for the cost of this instruction) onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition jumpdest : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Mark a valid destination for jumps. This is a noop, present only + to be used by `JUMP` and `JUMPI` opcodes to verify that their jump is + valid. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_JUMPDEST" |) + ], + make_dict [] + |) in + let _ := M.pass (| |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/environment.v b/CoqOfPython/ethereum/frontier/vm/instructions/environment.v new file mode 100644 index 0000000..4d26a46 --- /dev/null +++ b/CoqOfPython/ethereum/frontier/vm/instructions/environment.v @@ -0,0 +1,943 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Environmental Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM environment related instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require state. +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". + +Require utils.address. +Axiom utils_address_to_address : + IsGlobalAlias globals utils.address.globals "to_address". + +Require vm.memory. +Axiom vm_memory_buffer_read : + IsGlobalAlias globals vm.memory.globals "buffer_read". +Axiom vm_memory_memory_write : + IsGlobalAlias globals vm.memory.globals "memory_write". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_BALANCE : + IsGlobalAlias globals gas.globals "GAS_BALANCE". +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_COPY : + IsGlobalAlias globals gas.globals "GAS_COPY". +Axiom gas_GAS_EXTERNAL : + IsGlobalAlias globals gas.globals "GAS_EXTERNAL". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the address of the current executing account to the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition balance : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the balance of the given account onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BALANCE" |) + ], + make_dict [] + |) in + let balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "balance" |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "balance" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition origin : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the address of the original transaction sender to the stack. + The origin address can only be an EOA. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "origin" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition caller : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the address of the caller onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "caller" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition callvalue : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the value (in wei) sent with the call onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition calldataload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push a word (32 bytes) of the input data belonging to the current + environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |); + M.get_name (| globals, "start_index" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition calldatasize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the size of input data in current environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition calldatacopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy a portion of the input data in current environment to memory. + + This will also expand the memory, in case that the memory is insufficient + to store the data. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let data_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |); + M.get_name (| globals, "data_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition codesize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the size of code running in current environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "code" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition codecopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy a portion of the code in current environment to memory. + + This will also expand the memory, in case that the memory is insufficient + to store the data. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let code_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "code" |); + M.get_name (| globals, "code_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition gasprice : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the gas price used in current environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "gas_price" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition extcodesize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the code size of a given account onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_EXTERNAL" |) + ], + make_dict [] + |) in + let codesize := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "code" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "codesize" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition extcodecopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy a portion of an account's code to memory. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let code_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_EXTERNAL" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "code" |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "code" |); + M.get_name (| globals, "code_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/keccak.v b/CoqOfPython/ethereum/frontier/vm/instructions/keccak.v new file mode 100644 index 0000000..cab9ffb --- /dev/null +++ b/CoqOfPython/ethereum/frontier/vm/instructions/keccak.v @@ -0,0 +1,181 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Keccak Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM keccak instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_KECCAK256 : + IsGlobalAlias globals gas.globals "GAS_KECCAK256". +Axiom gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition keccak : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes to the stack the Keccak-256 hash of a region of memory. + + This also expands the memory, in case the memory is insufficient to + access the data's memory location. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let word_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_KECCAK256_WORD" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_KECCAK256" |), + M.get_name (| globals, "word_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let data := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "hash" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/log.v b/CoqOfPython/ethereum/frontier/vm/instructions/log.v new file mode 100644 index 0000000..f246f9d --- /dev/null +++ b/CoqOfPython/ethereum/frontier/vm/instructions/log.v @@ -0,0 +1,228 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Logging Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM logging instructions. +". + +Require functools. +Axiom functools_partial : + IsGlobalAlias globals functools.globals "partial". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_LOG : + IsGlobalAlias globals gas.globals "GAS_LOG". +Axiom gas_GAS_LOG_DATA : + IsGlobalAlias globals gas.globals "GAS_LOG_DATA". +Axiom gas_GAS_LOG_TOPIC : + IsGlobalAlias globals gas.globals "GAS_LOG_TOPIC". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". + +Definition log_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "num_topics" ] |) in + let _ := Constant.str " + Appends a log entry, having `num_topics` topics, to the evm logs. + + This will also expand the memory if the data (required by the log entry) + corresponding to the memory is not accessible. + + Parameters + ---------- + evm : + The current EVM frame. + num_topics : + The number of topics to be included in the log entry. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let topics := + make_list [] in + For M.get_name (| globals, "_" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "num_topics" |) + ], + make_dict [] + |) do + let topic := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "topics" |), "append" |), + make_list [ + M.get_name (| globals, "topic" |) + ], + make_dict [] + |) in + EndFor. + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_LOG" |), + BinOp.mult (| + M.get_name (| globals, "GAS_LOG_DATA" |), + M.get_name (| globals, "size" |) + |) + |), + BinOp.mult (| + M.get_name (| globals, "GAS_LOG_TOPIC" |), + M.get_name (| globals, "num_topics" |) + |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let log_entry := + M.call (| + M.get_name (| globals, "Log" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "logs" |), + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "logs" |), + make_tuple [ M.get_name (| globals, "log_entry" |) ] + |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition log0 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/memory.v b/CoqOfPython/ethereum/frontier/vm/instructions/memory.v new file mode 100644 index 0000000..1e1c8b0 --- /dev/null +++ b/CoqOfPython/ethereum/frontier/vm/instructions/memory.v @@ -0,0 +1,378 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Memory Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM Memory instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". +Axiom memory_memory_write : + IsGlobalAlias globals memory.globals "memory_write". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition mstore : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a word to memory. + This also expands the memory, if the memory is + insufficient to store the word. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "start_position" |); M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + ], + make_dict [] + |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "start_position" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mstore8 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a byte to memory. + This also expands the memory, if the memory is + insufficient to store the word. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "start_position" |); M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let normalized_bytes_value := + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + make_list [ + BinOp.bit_and (| + M.get_name (| globals, "value" |), + Constant.int 255 + |) + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "start_position" |); + M.get_name (| globals, "normalized_bytes_value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Load word from memory. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "start_position" |); M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "start_position" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition msize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the size of active memory in bytes onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/stack.v b/CoqOfPython/ethereum/frontier/vm/instructions/stack.v new file mode 100644 index 0000000..1eeda05 --- /dev/null +++ b/CoqOfPython/ethereum/frontier/vm/instructions/stack.v @@ -0,0 +1,929 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Stack Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM stack related instructions. +". + +Require functools. +Axiom functools_partial : + IsGlobalAlias globals functools.globals "partial". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". +Axiom __init___stack : + IsGlobalAlias globals __init__.globals "stack". + +Require exceptions. +Axiom exceptions_StackUnderflowError : + IsGlobalAlias globals exceptions.globals "StackUnderflowError". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_buffer_read : + IsGlobalAlias globals memory.globals "buffer_read". + +Definition pop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Remove item from stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.pass (| |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition push_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "num_bytes" ] |) in + let _ := Constant.str " + Pushes a N-byte immediate onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + num_bytes : + The number of immediate bytes to be read from the code and pushed to + the stack. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let data_to_push := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "code" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "num_bytes" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "data_to_push" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + BinOp.add (| + Constant.int 1, + M.get_name (| globals, "num_bytes" |) + |) + |) in + M.pure Constant.None_)). + +Definition dup_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "item_number" ] |) in + let _ := Constant.str " + Duplicate the Nth stack item (from top of the stack) to the top of stack. + + Parameters + ---------- + evm : + The current EVM frame. + + item_number : + The stack item number (0-indexed from top of stack) to be duplicated + to the top of stack. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "StackUnderflowError" |) + ], + make_dict [] + |) in + let data_to_duplicate := + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + BinOp.sub (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), + Constant.int 1 + |), + M.get_name (| globals, "item_number" |) + |) |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "data_to_duplicate" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition swap_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "item_number" ] |) in + let _ := Constant.str " + Swap the top and the `item_number` element of the stack, where + the top of the stack is position zero. + + If `item_number` is zero, this function does nothing (which should not be + possible, since there is no `SWAP0` instruction). + + Parameters + ---------- + evm : + The current EVM frame. + + item_number : + The stack item number (0-indexed from top of stack) to be swapped + with the top of stack element. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "StackUnderflowError" |) + ], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) |) ], + make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |) ] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition push1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push5 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push6 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push7 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push8 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push9 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push10 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push11 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push12 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push13 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push14 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push15 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push16 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push17 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push18 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push19 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push20 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push21 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push22 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push23 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push24 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push25 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push26 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push27 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push28 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push29 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push30 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push31 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push32 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition dup1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup5 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup6 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup7 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup8 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup9 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup10 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup11 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup12 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup13 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup14 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup15 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup16 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition swap1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap5 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap6 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap7 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap8 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap9 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap10 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap11 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap12 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap13 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap14 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap15 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap16 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/storage.v b/CoqOfPython/ethereum/frontier/vm/instructions/storage.v new file mode 100644 index 0000000..4292e3b --- /dev/null +++ b/CoqOfPython/ethereum/frontier/vm/instructions/storage.v @@ -0,0 +1,212 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Storage Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM storage related instructions. +". + +Require state. +Axiom state_get_storage : + IsGlobalAlias globals state.globals "get_storage". +Axiom state_set_storage : + IsGlobalAlias globals state.globals "set_storage". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_SLOAD : + IsGlobalAlias globals gas.globals "GAS_SLOAD". +Axiom gas_GAS_STORAGE_CLEAR_REFUND : + IsGlobalAlias globals gas.globals "GAS_STORAGE_CLEAR_REFUND". +Axiom gas_GAS_STORAGE_SET : + IsGlobalAlias globals gas.globals "GAS_STORAGE_SET". +Axiom gas_GAS_STORAGE_UPDATE : + IsGlobalAlias globals gas.globals "GAS_STORAGE_UPDATE". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition sload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Loads to the stack, the value corresponding to a certain key from the + storage of the current account. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let key := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_SLOAD" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "get_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition sstore : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a value at a certain key in the current context's storage. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let key := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let new_value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let current_value := + M.call (| + M.get_name (| globals, "get_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "new_value" |), Constant.int 0 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let gas_cost := + M.get_name (| globals, "GAS_STORAGE_SET" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let gas_cost := + M.get_name (| globals, "GAS_STORAGE_UPDATE" |) in + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_name (| globals, "new_value" |), Constant.int 0 |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "gas_cost" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "set_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |); + M.get_name (| globals, "new_value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/system.v b/CoqOfPython/ethereum/frontier/vm/instructions/system.v new file mode 100644 index 0000000..782fcdd --- /dev/null +++ b/CoqOfPython/ethereum/frontier/vm/instructions/system.v @@ -0,0 +1,1112 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) System Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM system related instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_account_has_code_or_nonce : + IsGlobalAlias globals state.globals "account_has_code_or_nonce". +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". +Axiom state_increment_nonce : + IsGlobalAlias globals state.globals "increment_nonce". +Axiom state_set_account_balance : + IsGlobalAlias globals state.globals "set_account_balance". + +Require utils.address. +Axiom utils_address_compute_contract_address : + IsGlobalAlias globals utils.address.globals "compute_contract_address". +Axiom utils_address_to_address : + IsGlobalAlias globals utils.address.globals "to_address". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". +Axiom __init___Message : + IsGlobalAlias globals __init__.globals "Message". +Axiom __init___incorporate_child_on_error : + IsGlobalAlias globals __init__.globals "incorporate_child_on_error". +Axiom __init___incorporate_child_on_success : + IsGlobalAlias globals __init__.globals "incorporate_child_on_success". + +Require gas. +Axiom gas_GAS_CREATE : + IsGlobalAlias globals gas.globals "GAS_CREATE". +Axiom gas_GAS_ZERO : + IsGlobalAlias globals gas.globals "GAS_ZERO". +Axiom gas_REFUND_SELF_DESTRUCT : + IsGlobalAlias globals gas.globals "REFUND_SELF_DESTRUCT". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_calculate_message_call_gas : + IsGlobalAlias globals gas.globals "calculate_message_call_gas". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". +Axiom memory_memory_write : + IsGlobalAlias globals memory.globals "memory_write". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition create : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Creates a new account with associated code. + + Parameters + ---------- + evm : + The current EVM frame. + " in +(* At stmt: unsupported node type: ImportFrom *) + let endowment := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_position" |); M.get_name (| globals, "memory_size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_CREATE" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let create_message_gas := + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let sender_address := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in + let sender := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "sender_address" |) + ], + make_dict [] + |) in + let contract_address := + M.call (| + M.get_name (| globals, "compute_contract_address" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "nonce" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt (| M.get_field (| M.get_name (| globals, "sender" |), "balance" |), M.get_name (| globals, "endowment" |) |), + ltac:(M.monadic ( + BoolOp.or (| + Compare.eq (| M.get_field (| M.get_name (| globals, "sender" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.sub (| + BinOp.pow (| + Constant.int 2, + Constant.int 64 + |), + Constant.int 1 + |) + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.gt (| BinOp.add (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "depth" |), + Constant.int 1 + |), M.get_name (| globals, "STACK_DEPTH_LIMIT" |) |) + )) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "create_message_gas" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "contract_address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let call_data := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + let child_message := + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) in + let child_evm := + M.call (| + M.get_name (| globals, "process_create_message" |), + make_list [ + M.get_name (| globals, "child_message" |); + M.get_field (| M.get_name (| globals, "evm" |), "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "child_evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_error" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_success" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition return_ : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Halts execution returning output data. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let memory_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_position" |); M.get_name (| globals, "memory_size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_ZERO" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "running" |), + Constant.bool false + |) in + let _ := M.pass (| |) in + M.pure Constant.None_)). + +Definition generic_call : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "gas"; "value"; "caller"; "to"; "code_address"; "memory_input_start_position"; "memory_input_size"; "memory_output_start_position"; "memory_output_size" ] |) in + let _ := Constant.str " + Perform the core logic of the `CALL*` family of opcodes. + " in +(* At stmt: unsupported node type: ImportFrom *) + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| BinOp.add (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "depth" |), + Constant.int 1 + |), M.get_name (| globals, "STACK_DEPTH_LIMIT" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "gas" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let call_data := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |) + ], + make_dict [] + |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "code_address" |) + ], + make_dict [] + |), "code" |) in + let child_message := + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) in + let child_evm := + M.call (| + M.get_name (| globals, "process_message" |), + make_list [ + M.get_name (| globals, "child_message" |); + M.get_field (| M.get_name (| globals, "evm" |), "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "child_evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_error" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_success" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let actual_output_size := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_name (| globals, "memory_output_size" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), (* At expr: unsupported node type: NoneType *):M.get_name (| globals, "actual_output_size" |) |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition call : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into an account. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let to := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "gas" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let sender_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "sender_balance" |), M.get_name (| globals, "value" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.get_name (| globals, "value" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition callcode : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into this account with alternative account’s code. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let code_address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let to := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "gas" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let sender_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "sender_balance" |), M.get_name (| globals, "value" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.get_name (| globals, "value" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "code_address" |); + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition selfdestruct : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Halt execution and register account for later deletion. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let beneficiary := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let gas_cost := + M.get_name (| globals, "GAS_ZERO" |) in + let originator := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in + let refunded_accounts := + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in + let parent_evm := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "parent_evm" |) in + While Compare.is_not (| M.get_name (| globals, "parent_evm" |), Constant.None_ |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "refunded_accounts" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "parent_evm" |), "accounts_to_delete" |) + ], + make_dict [] + |) in + let parent_evm := + M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in + EndWhile. + let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| M.get_name (| globals, "originator" |), M.get_name (| globals, "refunded_accounts" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.get_name (| globals, "REFUND_SELF_DESTRUCT" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "gas_cost" |) + ], + make_dict [] + |) in + let beneficiary_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |), "balance" |) in + let originator_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "originator" |) + ], + make_dict [] + |), "balance" |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |); + BinOp.add (| + M.get_name (| globals, "beneficiary_balance" |), + M.get_name (| globals, "originator_balance" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "originator" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |), "add" |), + make_list [ + M.get_name (| globals, "originator" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "running" |), + Constant.bool false + |) in + let _ := M.pass (| |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/vm/interpreter.v b/CoqOfPython/ethereum/frontier/vm/interpreter.v new file mode 100644 index 0000000..94f70de --- /dev/null +++ b/CoqOfPython/ethereum/frontier/vm/interpreter.v @@ -0,0 +1,553 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Interpreter +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +A straightforward interpreter that executes EVM code. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.trace. +Axiom ethereum_trace_EvmStop : + IsGlobalAlias globals ethereum.trace.globals "EvmStop". +Axiom ethereum_trace_OpEnd : + IsGlobalAlias globals ethereum.trace.globals "OpEnd". +Axiom ethereum_trace_OpException : + IsGlobalAlias globals ethereum.trace.globals "OpException". +Axiom ethereum_trace_OpStart : + IsGlobalAlias globals ethereum.trace.globals "OpStart". +Axiom ethereum_trace_PrecompileEnd : + IsGlobalAlias globals ethereum.trace.globals "PrecompileEnd". +Axiom ethereum_trace_PrecompileStart : + IsGlobalAlias globals ethereum.trace.globals "PrecompileStart". +Axiom ethereum_trace_TransactionEnd : + IsGlobalAlias globals ethereum.trace.globals "TransactionEnd". +Axiom ethereum_trace_evm_trace : + IsGlobalAlias globals ethereum.trace.globals "evm_trace". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_account_has_code_or_nonce : + IsGlobalAlias globals state.globals "account_has_code_or_nonce". +Axiom state_begin_transaction : + IsGlobalAlias globals state.globals "begin_transaction". +Axiom state_commit_transaction : + IsGlobalAlias globals state.globals "commit_transaction". +Axiom state_destroy_storage : + IsGlobalAlias globals state.globals "destroy_storage". +Axiom state_move_ether : + IsGlobalAlias globals state.globals "move_ether". +Axiom state_rollback_transaction : + IsGlobalAlias globals state.globals "rollback_transaction". +Axiom state_set_code : + IsGlobalAlias globals state.globals "set_code". +Axiom state_touch_account : + IsGlobalAlias globals state.globals "touch_account". + +Require vm. +Axiom vm_Message : + IsGlobalAlias globals vm.globals "Message". + +Require vm.gas. +Axiom vm_gas_GAS_CODE_DEPOSIT : + IsGlobalAlias globals vm.gas.globals "GAS_CODE_DEPOSIT". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require vm.precompiled_contracts.mapping. +Axiom vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : + IsGlobalAlias globals vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". + +Require __init__. +Axiom __init___Environment : + IsGlobalAlias globals __init__.globals "Environment". +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_AddressCollision : + IsGlobalAlias globals exceptions.globals "AddressCollision". +Axiom exceptions_ExceptionalHalt : + IsGlobalAlias globals exceptions.globals "ExceptionalHalt". +Axiom exceptions_InvalidOpcode : + IsGlobalAlias globals exceptions.globals "InvalidOpcode". +Axiom exceptions_StackDepthLimitError : + IsGlobalAlias globals exceptions.globals "StackDepthLimitError". + +Require instructions. +Axiom instructions_Ops : + IsGlobalAlias globals instructions.globals "Ops". +Axiom instructions_op_implementation : + IsGlobalAlias globals instructions.globals "op_implementation". + +Require runtime. +Axiom runtime_get_valid_jump_destinations : + IsGlobalAlias globals runtime.globals "get_valid_jump_destinations". + +Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1024 + ], + make_dict [] + |) +)). + +Definition MessageCallOutput : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition process_message_call : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + If `message.current` is empty then it creates a smart contract + else it executes a call from the `message.caller` to the `message.target`. + + Parameters + ---------- + message : + Transaction specific items. + + env : + External items required for EVM execution. + + Returns + ------- + output : `MessageCallOutput` + Output of the message call + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_name (| globals, "message" |), "target" |), M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let is_collision := + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_name (| globals, "is_collision" |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallOutput" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "tuple" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "AddressCollision" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let evm := + M.call (| + M.get_name (| globals, "process_create_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let evm := + M.call (| + M.get_name (| globals, "process_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( +(* At stmt: unsupported node type: AnnAssign *) + let accounts_to_delete := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let refund_counter := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let logs := + M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in + let accounts_to_delete := + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in + let refund_counter := + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |) in + M.pure Constant.None_ + )) |) in + let tx_end := + M.call (| + M.get_name (| globals, "TransactionEnd" |), + make_list [ + BinOp.sub (| + M.get_field (| M.get_name (| globals, "message" |), "gas" |), + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + |); + M.get_field (| M.get_name (| globals, "evm" |), "output" |); + M.get_field (| M.get_name (| globals, "evm" |), "error" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "evm_trace" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "tx_end" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallOutput" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition process_create_message : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + Executes a call to create a smart contract. + + Parameters + ---------- + message : + Transaction specific items. + env : + External items required for EVM execution. + + Returns + ------- + evm: :py:class:`~ethereum.frontier.vm.Evm` + Items containing execution specific objects. + " in + let _ := M.call (| + M.get_name (| globals, "begin_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "destroy_storage" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let evm := + M.call (| + M.get_name (| globals, "process_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), + (* then *) + ltac:(M.monadic ( + let contract_code := + M.get_field (| M.get_name (| globals, "evm" |), "output" |) in + let contract_code_gas := + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "contract_code" |) + ], + make_dict [] + |), + M.get_name (| globals, "GAS_CODE_DEPOSIT" |) + |) in +(* At stmt: unsupported node type: Try *) + let _ := M.call (| + M.get_name (| globals, "commit_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "rollback_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.get_name (| globals, "evm" |) + |) in + M.pure Constant.None_)). + +Definition process_message : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + Executes a call to create a smart contract. + + Parameters + ---------- + message : + Transaction specific items. + env : + External items required for EVM execution. + + Returns + ------- + evm: :py:class:`~ethereum.frontier.vm.Evm` + Items containing execution specific objects + " in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_field (| M.get_name (| globals, "message" |), "depth" |), M.get_name (| globals, "STACK_DEPTH_LIMIT" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "StackDepthLimitError" |), + make_list [ + Constant.str "Stack depth limit reached" + ], + make_dict [] + |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "begin_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "touch_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| M.get_field (| M.get_name (| globals, "message" |), "value" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "move_ether" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "caller" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |); + M.get_field (| M.get_name (| globals, "message" |), "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let evm := + M.call (| + M.get_name (| globals, "execute_code" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "rollback_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "commit_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.get_name (| globals, "evm" |) + |) in + M.pure Constant.None_)). + +Definition execute_code : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + Executes bytecode present in the `message`. + + Parameters + ---------- + message : + Transaction specific items. + env : + External items required for EVM execution. + + Returns + ------- + evm: `ethereum.vm.EVM` + Items containing execution specific objects + " in + let code := + M.get_field (| M.get_name (| globals, "message" |), "code" |) in + let valid_jump_destinations := + M.call (| + M.get_name (| globals, "get_valid_jump_destinations" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) in + let evm := + M.call (| + M.get_name (| globals, "Evm" |), + make_list [], + make_dict [] + |) in +(* At stmt: unsupported node type: Try *) + let _ := M.return_ (| + M.get_name (| globals, "evm" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/vm/memory.v b/CoqOfPython/ethereum/frontier/vm/memory.v new file mode 100644 index 0000000..fa8d906 --- /dev/null +++ b/CoqOfPython/ethereum/frontier/vm/memory.v @@ -0,0 +1,153 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Memory +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +EVM memory operations. +". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_right_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "right_pad_zero_bytes". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". + +Definition memory_write : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "memory"; "start_position"; "value" ] |) in + let _ := Constant.str " + Writes to memory. + + Parameters + ---------- + memory : + Memory contents of the EVM. + start_position : + Starting pointer to the memory. + value : + Data to write to memory. + " in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) |), + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_)). + +Definition memory_read_bytes : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "memory"; "start_position"; "size" ] |) in + let _ := Constant.str " + Read bytes from memory. + + Parameters + ---------- + memory : + Memory contents of the EVM. + start_position : + Starting pointer to the memory. + size : + Size of the data that needs to be read from `start_position`. + + Returns + ------- + data_bytes : + Data read from memory. + " in + let _ := M.return_ (| + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |) + |) in + M.pure Constant.None_)). + +Definition buffer_read : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "buffer"; "start_position"; "size" ] |) in + let _ := Constant.str " + Read bytes from a buffer. Padding with zeros if necessary. + + Parameters + ---------- + buffer : + Memory contents of the EVM. + start_position : + Starting pointer to the memory. + size : + Size of the data that needs to be read from `start_position`. + + Returns + ------- + data_bytes : + Data read from memory. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "right_pad_zero_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/__init__.v new file mode 100644 index 0000000..422f670 --- /dev/null +++ b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/__init__.v @@ -0,0 +1,67 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Precompiled Contract Addresses +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Addresses of precompiled contracts and mappings to their +implementations. +". + +Require utils.hexadecimal. +Axiom utils_hexadecimal_hex_to_address : + IsGlobalAlias globals utils.hexadecimal.globals "hex_to_address". + +Definition __all__ : Value.t := M.run ltac:(M.monadic ( + make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS" ] +)). + +Definition ECRECOVER_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x01" + ], + make_dict [] + |) +)). + +Definition SHA256_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x02" + ], + make_dict [] + |) +)). + +Definition RIPEMD160_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x03" + ], + make_dict [] + |) +)). + +Definition IDENTITY_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x04" + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/ecrecover.v new file mode 100644 index 0000000..cc351b5 --- /dev/null +++ b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/ecrecover.v @@ -0,0 +1,269 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) ECRECOVER PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the ECRECOVER precompiled contract. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require ethereum.crypto.elliptic_curve. +Axiom ethereum_crypto_elliptic_curve_SECP256K1N : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_left_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_ECRECOVER : + IsGlobalAlias globals vm.gas.globals "GAS_ECRECOVER". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require vm.memory. +Axiom vm_memory_buffer_read : + IsGlobalAlias globals vm.memory.globals "buffer_read". + +Definition ecrecover : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Decrypts the address using elliptic curve DSA recovery mechanism and writes + the address to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_ECRECOVER" |) + ], + make_dict [] + |) in + let message_hash_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let message_hash := + M.call (| + M.get_name (| globals, "Hash32" |), + make_list [ + M.get_name (| globals, "message_hash_bytes" |) + ], + make_dict [] + |) in + let v := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let r := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let s := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 27 |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 28 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| Constant.int 0, M.get_name (| globals, "r" |) |), + ltac:(M.monadic ( + Compare.gt_e (| M.get_name (| globals, "r" |), M.get_name (| globals, "SECP256K1N" |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| Constant.int 0, M.get_name (| globals, "s" |) |), + ltac:(M.monadic ( + Compare.gt_e (| M.get_name (| globals, "s" |), M.get_name (| globals, "SECP256K1N" |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in +(* At stmt: unsupported node type: Try *) + let address := + M.get_subscript (| M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), Constant.int 12:Constant.int 32 |) in + let padded_address := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "address" |); + Constant.int 32 + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.get_name (| globals, "padded_address" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/identity.v new file mode 100644 index 0000000..fa96704 --- /dev/null +++ b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/identity.v @@ -0,0 +1,94 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) IDENTITY PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `IDENTITY` precompiled contract. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_IDENTITY : + IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY". +Axiom vm_gas_GAS_IDENTITY_WORD : + IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY_WORD". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition identity : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the message data to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let word_count := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_IDENTITY" |), + BinOp.mult (| + M.get_name (| globals, "GAS_IDENTITY_WORD" |), + M.get_name (| globals, "word_count" |) + |) + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.get_name (| globals, "data" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/mapping.v new file mode 100644 index 0000000..710457d --- /dev/null +++ b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/mapping.v @@ -0,0 +1,56 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Precompiled Contract Addresses +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Mapping of precompiled contracts their implementations. +". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require __init__. +Axiom __init___ECRECOVER_ADDRESS : + IsGlobalAlias globals __init__.globals "ECRECOVER_ADDRESS". +Axiom __init___IDENTITY_ADDRESS : + IsGlobalAlias globals __init__.globals "IDENTITY_ADDRESS". +Axiom __init___RIPEMD160_ADDRESS : + IsGlobalAlias globals __init__.globals "RIPEMD160_ADDRESS". +Axiom __init___SHA256_ADDRESS : + IsGlobalAlias globals __init__.globals "SHA256_ADDRESS". + +Require ecrecover. +Axiom ecrecover_ecrecover : + IsGlobalAlias globals ecrecover.globals "ecrecover". + +Require identity. +Axiom identity_identity : + IsGlobalAlias globals identity.globals "identity". + +Require ripemd160. +Axiom ripemd160_ripemd160 : + IsGlobalAlias globals ripemd160.globals "ripemd160". + +Require sha256. +Axiom sha256_sha256 : + IsGlobalAlias globals sha256.globals "sha256". + +(* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/ripemd160.v new file mode 100644 index 0000000..96f8dcd --- /dev/null +++ b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/ripemd160.v @@ -0,0 +1,122 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) RIPEMD160 PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `RIPEMD160` precompiled contract. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_left_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_RIPEMD160 : + IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160". +Axiom vm_gas_GAS_RIPEMD160_WORD : + IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160_WORD". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition ripemd160 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the ripemd160 hash to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let word_count := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_RIPEMD160" |), + BinOp.mult (| + M.get_name (| globals, "GAS_RIPEMD160_WORD" |), + M.get_name (| globals, "word_count" |) + |) + |) + ], + make_dict [] + |) in + let hash_bytes := + M.call (| + M.get_field (| M.call (| + M.get_field (| M.get_name (| globals, "hashlib" |), "new" |), + make_list [ + Constant.str "ripemd160"; + M.get_name (| globals, "data" |) + ], + make_dict [] + |), "digest" |), + make_list [], + make_dict [] + |) in + let padded_hash := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "hash_bytes" |); + Constant.int 32 + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.get_name (| globals, "padded_hash" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/sha256.v new file mode 100644 index 0000000..9f6d2bf --- /dev/null +++ b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/sha256.v @@ -0,0 +1,106 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) SHA256 PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `SHA256` precompiled contract. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_SHA256 : + IsGlobalAlias globals vm.gas.globals "GAS_SHA256". +Axiom vm_gas_GAS_SHA256_WORD : + IsGlobalAlias globals vm.gas.globals "GAS_SHA256_WORD". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition sha256 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the sha256 hash to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let word_count := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_SHA256" |), + BinOp.mult (| + M.get_name (| globals, "GAS_SHA256_WORD" |), + M.get_name (| globals, "word_count" |) + |) + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_field (| M.get_name (| globals, "hashlib" |), "sha256" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), "digest" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/vm/runtime.v b/CoqOfPython/ethereum/frontier/vm/runtime.v new file mode 100644 index 0000000..835b46c --- /dev/null +++ b/CoqOfPython/ethereum/frontier/vm/runtime.v @@ -0,0 +1,125 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Runtime Operations +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Runtime related operations used while executing EVM code. +". + +Require typing. +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require instructions. +Axiom instructions_Ops : + IsGlobalAlias globals instructions.globals "Ops". + +Definition get_valid_jump_destinations : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "code" ] |) in + let _ := Constant.str " + Analyze the evm code to obtain the set of valid jump destinations. + + Valid jump destinations are defined as follows: + * The jump destination is less than the length of the code. + * The jump destination should have the `JUMPDEST` opcode (0x5B). + * The jump destination shouldn't be part of the data corresponding to + `PUSH-N` opcodes. + + Note - Jump destinations are 0-indexed. + + Parameters + ---------- + code : + The EVM code which is to be executed. + + Returns + ------- + valid_jump_destinations: `Set[Uint]` + The set of valid jump destinations in the code. + " in + let valid_jump_destinations := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let pc := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + While Compare.lt (| M.get_name (| globals, "pc" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) |) do +(* At stmt: unsupported node type: Try *) + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "current_opcode" |), M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), + make_list [ + M.get_name (| globals, "pc" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + (* At expr: unsupported node type: Compare *), + (* then *) + ltac:(M.monadic ( + let push_data_size := + BinOp.add (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) + |), + Constant.int 1 + |) in + let pc := BinOp.add + M.get_name (| globals, "push_data_size" |) + M.get_name (| globals, "push_data_size" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let pc := BinOp.add + Constant.int 1 + Constant.int 1 in + EndWhile. + let _ := M.return_ (| + M.get_name (| globals, "valid_jump_destinations" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/vm/stack.v b/CoqOfPython/ethereum/frontier/vm/stack.v new file mode 100644 index 0000000..42ea42d --- /dev/null +++ b/CoqOfPython/ethereum/frontier/vm/stack.v @@ -0,0 +1,120 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Stack +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the stack operators for the EVM. +". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require exceptions. +Axiom exceptions_StackOverflowError : + IsGlobalAlias globals exceptions.globals "StackOverflowError". +Axiom exceptions_StackUnderflowError : + IsGlobalAlias globals exceptions.globals "StackUnderflowError". + +Definition pop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "stack" ] |) in + let _ := Constant.str " + Pops the top item off of `stack`. + + Parameters + ---------- + stack : + EVM stack. + + Returns + ------- + value : `U256` + The top element on the stack. + + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "StackUnderflowError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "pop" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition push : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "stack"; "value" ] |) in + let _ := Constant.str " + Pushes `value` onto `stack`. + + Parameters + ---------- + stack : + EVM stack. + + value : + Item to be pushed onto `stack`. + + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), Constant.int 1024 |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "StackOverflowError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "append" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/genesis.v b/CoqOfPython/ethereum/genesis.v new file mode 100644 index 0000000..b6dd143 --- /dev/null +++ b/CoqOfPython/ethereum/genesis.v @@ -0,0 +1,524 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Genesis Configuration +^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Functionalities and entities to obtain the genesis configurations for +different chains. +". + +(* At top_level_stmt: unsupported node type: Import *) + +(* At top_level_stmt: unsupported node type: Import *) + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Any : + IsGlobalAlias globals typing.globals "Any". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". +Axiom typing_cast : + IsGlobalAlias globals typing.globals "cast". + +Require ethereum. +Axiom ethereum_rlp : + IsGlobalAlias globals ethereum.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U64 : + IsGlobalAlias globals ethereum.base_types.globals "U64". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes8 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes8". +Axiom ethereum_base_types_Bytes20 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes20". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.utils.hexadecimal. +Axiom ethereum_utils_hexadecimal_hex_to_bytes : + IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". +Axiom ethereum_utils_hexadecimal_hex_to_bytes8 : + IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes8". +Axiom ethereum_utils_hexadecimal_hex_to_bytes32 : + IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes32". +Axiom ethereum_utils_hexadecimal_hex_to_u256 : + IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_u256". +Axiom ethereum_utils_hexadecimal_hex_to_uint : + IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_uint". + +Definition Address : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Bytes20" |) +)). + +Definition GenesisConfiguration : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition get_genesis_configuration : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "genesis_file" ] |) in + let _ := Constant.str " + Obtain the genesis configuration from the given genesis json file. + + The genesis file should be present in the `assets` directory. + + Parameters + ---------- + genesis_file : + The json file which contains the parameters for the genesis block + and the pre-sale allocation data. + + Returns + ------- + configuration : `GenesisConfiguration` + The genesis configuration obtained from the json genesis file. + " in + let genesis_str_data := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "cast" |), + make_list [ + M.get_name (| globals, "bytes" |); + M.call (| + M.get_field (| M.get_name (| globals, "pkgutil" |), "get_data" |), + make_list [ + Constant.str "ethereum"; + (* At expr: unsupported node type: JoinedStr *) + ], + make_dict [] + |) + ], + make_dict [] + |), "decode" |), + make_list [], + make_dict [] + |) in + let genesis_data := + M.call (| + M.get_field (| M.get_name (| globals, "json" |), "loads" |), + make_list [ + M.get_name (| globals, "genesis_str_data" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "GenesisConfiguration" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition hex_or_base_10_str_to_u256 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "balance" ] |) in + let _ := Constant.str " + The genesis format can have balances and timestamps as either base 10 + numbers or 0x prefixed hex. This function supports both. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_field (| M.get_name (| globals, "balance" |), "startswith" |), + make_list [ + Constant.str "0x" + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "hex_to_u256" |), + make_list [ + M.get_name (| globals, "balance" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "balance" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition add_genesis_block : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hardfork"; "chain"; "genesis" ] |) in + let _ := Constant.str " + Adds the genesis block to an empty blockchain. + + The genesis block is an entirely sui generis block (unique) that is not + governed by the general rules applying to all other Ethereum blocks. + Instead, the only consensus requirement is that it must be identical to + the block added by this function. + + The mainnet genesis configuration was originally created using the + `mk_genesis_block.py` script. It is long since defunct, but is still + available at https://github.com/ethereum/genesis_block_generator. + + The initial state is populated with balances based on the Ethereum presale + that happened on the Bitcoin blockchain. Additional Ether worth 1.98% of + the presale was given to the foundation. + + The `state_root` is set to the root of the initial state. The `gas_limit` + and `difficulty` are set to suitable starting values. In particular the + low gas limit made sending transactions impossible in the early stages of + Frontier. + + The `nonce` field is `0x42` referencing Douglas Adams' """HitchHiker's Guide + to the Galaxy""". + + The `extra_data` field contains the hash of block `1028201` on + the pre-launch Olympus testnet. The creation of block `1028201` on Olympus + marked the """starting gun""" for Ethereum block creation. Including its hash + in the genesis block ensured a fair launch of the Ethereum mining process. + + The remaining fields are set to appropriate default values. + + On testnets the genesis configuration usually allocates 1 wei to addresses + `0x00` to `0xFF` to avoid edgecases around precompiles being created or + cleared (by EIP 161). + + Parameters + ---------- + hardfork: + The module containing the initial hardfork + chain : + An empty `Blockchain` object. + genesis : + The genesis configuration to use. + " in + For make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "account" |) ] in M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "genesis" |), "initial_accounts" |), "items" |), + make_list [], + make_dict [] + |) do + let address := + M.call (| + M.get_field (| M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "utils" |), "hexadecimal" |), "hex_to_address" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "state" |), "set_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "chain" |), "state" |); + M.get_name (| globals, "address" |); + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "fork_types" |), "Account" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "account" |), "get" |), + make_list [ + Constant.str "nonce"; + Constant.str "0" + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "hex_or_base_10_str_to_u256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "account" |), "get" |), + make_list [ + Constant.str "balance"; + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "hex_to_bytes" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "account" |), "get" |), + make_list [ + Constant.str "code"; + Constant.str "0x" + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + For make_tuple [ M.get_name (| globals, "key" |); M.get_name (| globals, "value" |) ] in M.call (| + M.get_field (| M.call (| + M.get_field (| M.get_name (| globals, "account" |), "get" |), + make_list [ + Constant.str "storage"; + {} + ], + make_dict [] + |), "items" |), + make_list [], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "state" |), "set_storage" |), + make_list [ + M.get_field (| M.get_name (| globals, "chain" |), "state" |); + M.get_name (| globals, "address" |); + M.call (| + M.get_name (| globals, "hex_to_bytes32" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "hex_to_uint" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + EndFor. + EndFor. + let fields := + {Constant.str "parent_hash": M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "fork_types" |), "Hash32" |), + make_list [ + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + Constant.int 32 + |) + ], + make_dict [] + |), Constant.str "ommers_hash": M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + make_tuple [ ] + ], + make_dict [] + |), Constant.str "coinbase": M.call (| + M.get_name (| globals, "Address" |), + make_list [ + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + Constant.int 20 + |) + ], + make_dict [] + |), Constant.str "state_root": M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "state" |), "state_root" |), + make_list [ + M.get_field (| M.get_name (| globals, "chain" |), "state" |) + ], + make_dict [] + |), Constant.str "transactions_root": M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "trie" |), "root" |), + make_list [ + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "trie" |), "Trie" |), + make_list [ + Constant.bool false; + Constant.None_ + ], + make_dict [] + |) + ], + make_dict [] + |), Constant.str "receipt_root": M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "trie" |), "root" |), + make_list [ + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "trie" |), "Trie" |), + make_list [ + Constant.bool false; + Constant.None_ + ], + make_dict [] + |) + ], + make_dict [] + |), Constant.str "bloom": M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "fork_types" |), "Bloom" |), + make_list [ + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + Constant.int 256 + |) + ], + make_dict [] + |), Constant.str "difficulty": M.get_field (| M.get_name (| globals, "genesis" |), "difficulty" |), Constant.str "number": M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |), Constant.str "gas_limit": M.get_field (| M.get_name (| globals, "genesis" |), "gas_limit" |), Constant.str "gas_used": M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |), Constant.str "timestamp": M.get_field (| M.get_name (| globals, "genesis" |), "timestamp" |), Constant.str "extra_data": M.get_field (| M.get_name (| globals, "genesis" |), "extra_data" |), Constant.str "nonce": M.get_field (| M.get_name (| globals, "genesis" |), "nonce" |)} in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "hasattr" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "blocks" |), "Header" |); + Constant.str "mix_digest" + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "fields" |), Constant.str "mix_digest" |), + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "fork_types" |), "Hash32" |), + make_list [ + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + Constant.int 32 + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "fields" |), Constant.str "prev_randao" |), + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "fork_types" |), "Hash32" |), + make_list [ + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + Constant.int 32 + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "hasattr" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "blocks" |), "Header" |); + Constant.str "base_fee_per_gas" + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "fields" |), Constant.str "base_fee_per_gas" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.pow (| + Constant.int 10, + Constant.int 9 + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let genesis_header := + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "blocks" |), "Header" |), + make_list [], + make_dict [] + |) in + let genesis_block := + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "blocks" |), "Block" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), "append" |), + make_list [ + M.get_name (| globals, "genesis_block" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "chain" |), "chain_id" |), + M.get_field (| M.get_name (| globals, "genesis" |), "chain_id" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/__init__.v b/CoqOfPython/ethereum/gray_glacier/__init__.v new file mode 100644 index 0000000..2ed64ad --- /dev/null +++ b/CoqOfPython/ethereum/gray_glacier/__init__.v @@ -0,0 +1,23 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +The Gray Glacier fork delays the difficulty bomb. There are no other changes +in this fork. +". + +Require ethereum.fork_criteria. +Axiom ethereum_fork_criteria_ByBlockNumber : + IsGlobalAlias globals ethereum.fork_criteria.globals "ByBlockNumber". + +Definition FORK_CRITERIA : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "ByBlockNumber" |), + make_list [ + Constant.int 15050000 + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/gray_glacier/blocks.v b/CoqOfPython/ethereum/gray_glacier/blocks.v new file mode 100644 index 0000000..a90217e --- /dev/null +++ b/CoqOfPython/ethereum/gray_glacier/blocks.v @@ -0,0 +1,95 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +A `Block` is a single link in the chain that is Ethereum. Each `Block` contains +a `Header` and zero or more transactions. Each `Header` contains associated +metadata like the block number, parent block hash, and how much gas was +consumed by its transactions. + +Together, these blocks form a cryptographically secure journal recording the +history of all state transitions that have happened since the genesis of the +chain. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes8 : + IsGlobalAlias globals base_types.globals "Bytes8". +Axiom base_types_Bytes32 : + IsGlobalAlias globals base_types.globals "Bytes32". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require crypto.hash. +Axiom crypto_hash_Hash32 : + IsGlobalAlias globals crypto.hash.globals "Hash32". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Require transactions. +Axiom transactions_LegacyTransaction : + IsGlobalAlias globals transactions.globals "LegacyTransaction". + +Definition Header : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Block : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Log : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Receipt : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. diff --git a/CoqOfPython/ethereum/gray_glacier/bloom.v b/CoqOfPython/ethereum/gray_glacier/bloom.v new file mode 100644 index 0000000..04b5d9f --- /dev/null +++ b/CoqOfPython/ethereum/gray_glacier/bloom.v @@ -0,0 +1,164 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Logs Bloom +^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +This modules defines functions for calculating bloom filters of logs. For the +general theory of bloom filters see e.g. `Wikipedia +`_. Bloom filters are used to allow +for efficient searching of logs by address and/or topic, by rapidly +eliminating blocks and receipts from their search. +". + +Require typing. +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require fork_types. +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". + +Definition add_to_bloom : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "bloom"; "bloom_entry" ] |) in + let _ := Constant.str " + Add a bloom entry to the bloom filter (`bloom`). + + The number of hash functions used is 3. They are calculated by taking the + least significant 11 bits from the first 3 16-bit words of the + `keccak_256()` hash of `bloom_entry`. + + Parameters + ---------- + bloom : + The bloom filter. + bloom_entry : + An entry which is to be added to bloom filter. + " in + let hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "bloom_entry" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "idx" |) in make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ] do + let bit_to_set := + BinOp.bit_and (| + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |):BinOp.add (| + M.get_name (| globals, "idx" |), + Constant.int 2 + |) |) + ], + make_dict [] + |), + Constant.int 2047 + |) in + let bit_index := + BinOp.sub (| + Constant.int 2047, + M.get_name (| globals, "bit_to_set" |) + |) in + let byte_index := + BinOp.floor_div (| + M.get_name (| globals, "bit_index" |), + Constant.int 8 + |) in + let bit_value := + BinOp.l_shift (| + Constant.int 1, + BinOp.sub (| + Constant.int 7, + BinOp.mod_ (| + M.get_name (| globals, "bit_index" |), + Constant.int 8 + |) + |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), + BinOp.bit_or (| + M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), + M.get_name (| globals, "bit_value" |) + |) + |) in + EndFor. + M.pure Constant.None_)). + +Definition logs_bloom : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "logs" ] |) in + let _ := Constant.str " + Obtain the logs bloom from a list of log entries. + + The address and each topic of a log are added to the bloom filter. + + Parameters + ---------- + logs : + List of logs for which the logs bloom is to be obtained. + + Returns + ------- + logs_bloom : `Bloom` + The logs bloom obtained which is 256 bytes with some bits set as per + the caller address and the log topics. + " in +(* At stmt: unsupported node type: AnnAssign *) + For M.get_name (| globals, "log" |) in M.get_name (| globals, "logs" |) do + let _ := M.call (| + M.get_name (| globals, "add_to_bloom" |), + make_list [ + M.get_name (| globals, "bloom" |); + M.get_field (| M.get_name (| globals, "log" |), "address" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "topic" |) in M.get_field (| M.get_name (| globals, "log" |), "topics" |) do + let _ := M.call (| + M.get_name (| globals, "add_to_bloom" |), + make_list [ + M.get_name (| globals, "bloom" |); + M.get_name (| globals, "topic" |) + ], + make_dict [] + |) in + EndFor. + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bloom" |), + make_list [ + M.get_name (| globals, "bloom" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/fork_types.v b/CoqOfPython/ethereum/gray_glacier/fork_types.v new file mode 100644 index 0000000..d12953d --- /dev/null +++ b/CoqOfPython/ethereum/gray_glacier/fork_types.v @@ -0,0 +1,102 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Types +^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Types re-used throughout the specification, which are specific to Ethereum. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes20 : + IsGlobalAlias globals base_types.globals "Bytes20". +Axiom base_types_Bytes256 : + IsGlobalAlias globals base_types.globals "Bytes256". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require crypto.hash. +Axiom crypto_hash_Hash32 : + IsGlobalAlias globals crypto.hash.globals "Hash32". +Axiom crypto_hash_keccak256 : + IsGlobalAlias globals crypto.hash.globals "keccak256". + +Definition Address : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Bytes20" |) +)). + +Definition Root : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Hash32" |) +)). + +Definition Bloom : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Bytes256" |) +)). + +Definition Account : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition EMPTY_ACCOUNT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Account" |), + make_list [], + make_dict [] + |) +)). + +Definition encode_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "raw_account_data"; "storage_root" ] |) in + let _ := Constant.str " + Encode `Account` dataclass. + + Storage is not stored in the `Account` dataclass, so `Accounts` cannot be + encoded with providing a storage root. + " in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "raw_account_data" |), "nonce" |); M.get_field (| M.get_name (| globals, "raw_account_data" |), "balance" |); M.get_name (| globals, "storage_root" |); M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_field (| M.get_name (| globals, "raw_account_data" |), "code" |) + ], + make_dict [] + |) ] + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/state.v b/CoqOfPython/ethereum/gray_glacier/state.v new file mode 100644 index 0000000..7b038e5 --- /dev/null +++ b/CoqOfPython/ethereum/gray_glacier/state.v @@ -0,0 +1,1184 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +State +^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The state contains all information that is preserved between transactions. + +It consists of a main account trie and storage tries for each contract. + +There is a distinction between an account that does not exist and +`EMPTY_ACCOUNT`. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_field : + IsGlobalAlias globals dataclasses.globals "field". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_modify : + IsGlobalAlias globals ethereum.base_types.globals "modify". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require fork_types. +Axiom fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". +Axiom fork_types_Account : + IsGlobalAlias globals fork_types.globals "Account". +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Require trie. +Axiom trie_EMPTY_TRIE_ROOT : + IsGlobalAlias globals trie.globals "EMPTY_TRIE_ROOT". +Axiom trie_Trie : + IsGlobalAlias globals trie.globals "Trie". +Axiom trie_copy_trie : + IsGlobalAlias globals trie.globals "copy_trie". +Axiom trie_root : + IsGlobalAlias globals trie.globals "root". +Axiom trie_trie_get : + IsGlobalAlias globals trie.globals "trie_get". +Axiom trie_trie_set : + IsGlobalAlias globals trie.globals "trie_set". + +Definition State : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition close_state : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Free resources held by the state. Used by optimized implementations to + release file descriptors. + " in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) |) in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |) in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |) |) in + M.pure Constant.None_)). + +Definition begin_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Start a state transaction. + + Transactions are entirely implicit and can be nested. It is not possible to + calculate the state root during a transaction. + + Parameters + ---------- + state : State + The state. + " in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), "append" |), + make_list [ + make_tuple [ M.call (| + M.get_name (| globals, "copy_trie" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) + ], + make_dict [] + |); {M.get_name (| globals, "k" |): M.call (| + M.get_name (| globals, "copy_trie" |), + make_list [ + M.get_name (| globals, "t" |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)} ] + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition commit_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Commit a state transaction. + + Parameters + ---------- + state : State + The state. + " in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), "pop" |), + make_list [], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "clear" |), + make_list [], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition rollback_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Rollback a state transaction, resetting the state to the point when the + corresponding `start_transaction()` call was made. + + Parameters + ---------- + state : State + The state. + " in + let _ := M.assign (| + make_tuple [ M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) ], + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), "pop" |), + make_list [], + make_dict [] + |) + |) in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "clear" |), + make_list [], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition get_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Get the `Account` object at an address. Returns `EMPTY_ACCOUNT` if there + is no account at the address. + + Use `get_account_optional()` if you care about the difference between a + non-existent account and `EMPTY_ACCOUNT`. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address to lookup. + + Returns + ------- + account : `Account` + Account at address. + " in + let account := + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "account" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "account" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "EMPTY_ACCOUNT" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition get_account_optional : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Get the `Account` object at an address. Returns `None` (rather than + `EMPTY_ACCOUNT`) if there is no account at the address. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address to lookup. + + Returns + ------- + account : `Account` + Account at address. + " in + let account := + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "account" |) + |) in + M.pure Constant.None_)). + +Definition set_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "account" ] |) in + let _ := Constant.str " + Set the `Account` object at an address. Setting to `None` deletes + the account (but not its storage, see `destroy_account()`). + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address to set. + account : `Account` + Account to set at address. + " in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "account" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition destroy_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Completely remove the account at `address` and all of its storage. + + This function is made available exclusively for the `SELFDESTRUCT` + opcode. It is expected that `SELFDESTRUCT` will be disabled in a future + hardfork and this function will be removed. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of account to destroy. + " in + let _ := M.call (| + M.get_name (| globals, "destroy_storage" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + Constant.None_ + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition destroy_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Completely remove the storage at `address`. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of account whose storage is to be deleted. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition mark_account_created : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Mark an account as having been created in the current transaction. + This information is used by `get_storage_original()` to handle an obscure + edgecase. + + The marker is not removed even if the account creation reverts. Since the + account cannot have had code prior to its creation and can't call + `get_storage_original()`, this is harmless. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of the account that has been created. + " in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition get_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "key" ] |) in + let _ := Constant.str " + Get a value at a storage key on an account. Returns `U256(0)` if the + storage key has not been set previously. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of the account. + key : `Bytes` + Key to lookup. + + Returns + ------- + value : `U256` + Value at the key. + " in + let trie := + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let _ := M.assert (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "U256" |) + ], + make_dict [] + |) |) in + let _ := M.return_ (| + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_)). + +Definition set_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "key"; "value" ] |) in + let _ := Constant.str " + Set a value at a storage key on an account. Setting to `U256(0)` deletes + the key. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of the account. + key : `Bytes` + Key to set. + value : `U256` + Value to set at the key. + " in + let _ := M.assert (| Compare.is_not (| M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), Constant.None_ |) |) in + let trie := + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let trie := + M.call (| + M.get_name (| globals, "Trie" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), + M.get_name (| globals, "trie" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "key" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), {} |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition storage_root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Calculate the storage root of an account. + + Parameters + ---------- + state: + The state + address : + Address of the account. + + Returns + ------- + root : `Root` + Storage root of the account. + " in + let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "EMPTY_TRIE_ROOT" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition state_root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Calculate the state root. + + Parameters + ---------- + state: + The current state. + + Returns + ------- + root : `Root` + The state root. + " in + let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition account_exists : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account exists in the state trie + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + account_exists : `bool` + True if account exists in the state trie, False otherwise + " in + let _ := M.return_ (| + Compare.is_not (| M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), Constant.None_ |) + |) in + M.pure Constant.None_)). + +Definition account_has_code_or_nonce : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account has non zero nonce or non empty code + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + has_code_or_nonce : `bool` + True if if an account has non zero nonce or non empty code, + False otherwise. + " in + let account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + BoolOp.or (| + Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |) + )) + |) + |) in + M.pure Constant.None_)). + +Definition is_account_empty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account has zero nonce, empty code and zero balance. + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + is_empty : `bool` + True if if an account has zero nonce, empty code and zero balance, + False otherwise. + " in + let account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + ltac:(M.monadic ( + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + )) + |) + )) + |) + |) in + M.pure Constant.None_)). + +Definition account_exists_and_is_empty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account exists and has zero nonce, empty code and zero + balance. + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + exists_and_is_empty : `bool` + True if an account exists and has zero nonce, empty code and zero + balance, False otherwise. + " in + let account := + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + BoolOp.and (| + Compare.is_not (| M.get_name (| globals, "account" |), Constant.None_ |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + ltac:(M.monadic ( + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + )) + |) + )) + |) + )) + |) + |) in + M.pure Constant.None_)). + +Definition is_account_alive : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Check whether is an account is both in the state and non empty. + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + is_alive : `bool` + True if the account is alive. + " in + let account := + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "account" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + UnOp.not (| BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + ltac:(M.monadic ( + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + )) + |) + )) + |) |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition modify_state : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "f" ] |) in + let _ := Constant.str " + Modify an `Account` in the `State`. + " in + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.call (| + M.get_name (| globals, "modify" |), + make_list [ + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |); + M.get_name (| globals, "f" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition move_ether : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "sender_address"; "recipient_address"; "amount" ] |) in + let _ := Constant.str " + Move funds between accounts. + " in +(* At stmt: unsupported node type: FunctionDef *) +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "sender_address" |); + M.get_name (| globals, "reduce_sender_balance" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "recipient_address" |); + M.get_name (| globals, "increase_recipient_balance" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition set_account_balance : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "amount" ] |) in + let _ := Constant.str " + Sets the balance of an account. + + Parameters + ---------- + state: + The current state. + + address: + Address of the account whose nonce needs to be incremented. + + amount: + The amount that needs to set in balance. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "set_balance" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition touch_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Initializes an account to state. + + Parameters + ---------- + state: + The current state. + + address: + The address of the account that need to initialised. + " in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "account_exists" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "EMPTY_ACCOUNT" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition increment_nonce : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Increments the nonce of an account. + + Parameters + ---------- + state: + The current state. + + address: + Address of the account whose nonce needs to be incremented. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "increase_nonce" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition set_code : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "code" ] |) in + let _ := Constant.str " + Sets Account code. + + Parameters + ---------- + state: + The current state. + + address: + Address of the account whose code needs to be update. + + code: + The bytecode that needs to be set. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "write_code" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition create_ether : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "amount" ] |) in + let _ := Constant.str " + Add newly created ether to an account. + + Parameters + ---------- + state: + The current state. + address: + Address of the account to which ether is added. + amount: + The amount of ether to be added to the account of interest. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "increase_balance" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition get_storage_original : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "key" ] |) in + let _ := Constant.str " + Get the original value in a storage slot i.e. the value before the current + transaction began. This function reads the value from the snapshots taken + before executing the transaction. + + Parameters + ---------- + state: + The current state. + address: + Address of the account to read the value from. + key: + Key of the storage slot. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "_" |); M.get_name (| globals, "original_trie" |) ], + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), Constant.int 0 |) + |) in + let original_account_trie := + M.call (| + M.get_field (| M.get_name (| globals, "original_trie" |), "get" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "original_account_trie" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let original_value := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let original_value := + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_name (| globals, "original_account_trie" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.assert (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "original_value" |); + M.get_name (| globals, "U256" |) + ], + make_dict [] + |) |) in + let _ := M.return_ (| + M.get_name (| globals, "original_value" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/transactions.v b/CoqOfPython/ethereum/gray_glacier/transactions.v new file mode 100644 index 0000000..56996d9 --- /dev/null +++ b/CoqOfPython/ethereum/gray_glacier/transactions.v @@ -0,0 +1,274 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Transactions are atomic units of work created externally to Ethereum and +submitted to be executed. If Ethereum is viewed as a state machine, +transactions are the events that move between states. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U64 : + IsGlobalAlias globals base_types.globals "U64". +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes0 : + IsGlobalAlias globals base_types.globals "Bytes0". +Axiom base_types_Bytes32 : + IsGlobalAlias globals base_types.globals "Bytes32". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require exceptions. +Axiom exceptions_InvalidBlock : + IsGlobalAlias globals exceptions.globals "InvalidBlock". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( + Constant.int 21000 +)). + +Definition TX_DATA_COST_PER_NON_ZERO : Value.t := M.run ltac:(M.monadic ( + Constant.int 16 +)). + +Definition TX_DATA_COST_PER_ZERO : Value.t := M.run ltac:(M.monadic ( + Constant.int 4 +)). + +Definition TX_CREATE_COST : Value.t := M.run ltac:(M.monadic ( + Constant.int 32000 +)). + +Definition TX_ACCESS_LIST_ADDRESS_COST : Value.t := M.run ltac:(M.monadic ( + Constant.int 2400 +)). + +Definition TX_ACCESS_LIST_STORAGE_KEY_COST : Value.t := M.run ltac:(M.monadic ( + Constant.int 1900 +)). + +Definition LegacyTransaction : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition AccessListTransaction : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition FeeMarketTransaction : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Transaction : Value.t := M.run ltac:(M.monadic ( + M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "AccessListTransaction" |); M.get_name (| globals, "FeeMarketTransaction" |) ] |) +)). + +Definition encode_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Encode a transaction. Needed because non-legacy transactions aren't RLP. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "LegacyTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "tx" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "AccessListTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + (* At constant: unsupported node type: Constant *), + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "FeeMarketTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + (* At constant: unsupported node type: Constant *), + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "Exception" |), + make_list [ + (* At expr: unsupported node type: JoinedStr *) + ], + make_dict [] + |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition decode_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Decode a transaction. Needed because non-legacy transactions aren't RLP. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), Constant.int 1 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), + make_list [ + M.get_name (| globals, "AccessListTransaction" |); + M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 1:(* At expr: unsupported node type: NoneType *) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), Constant.int 2 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), + make_list [ + M.get_name (| globals, "FeeMarketTransaction" |); + M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 1:(* At expr: unsupported node type: NoneType *) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidBlock" |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "tx" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/trie.v b/CoqOfPython/ethereum/gray_glacier/trie.v new file mode 100644 index 0000000..75d7da2 --- /dev/null +++ b/CoqOfPython/ethereum/gray_glacier/trie.v @@ -0,0 +1,1357 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +State Trie +^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The state trie is the structure responsible for storing +`.fork_types.Account` objects. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_field : + IsGlobalAlias globals dataclasses.globals "field". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". +Axiom typing_Generic : + IsGlobalAlias globals typing.globals "Generic". +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Mapping : + IsGlobalAlias globals typing.globals "Mapping". +Axiom typing_MutableMapping : + IsGlobalAlias globals typing.globals "MutableMapping". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Sequence : + IsGlobalAlias globals typing.globals "Sequence". +Axiom typing_TypeVar : + IsGlobalAlias globals typing.globals "TypeVar". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". +Axiom typing_cast : + IsGlobalAlias globals typing.globals "cast". + +Require ethereum.arrow_glacier. +Axiom ethereum_arrow_glacier_trie : + IsGlobalAlias globals ethereum.arrow_glacier.globals "trie". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require ethereum.utils.hexadecimal. +Axiom ethereum_utils_hexadecimal_hex_to_bytes : + IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require blocks. +Axiom blocks_Receipt : + IsGlobalAlias globals blocks.globals "Receipt". + +Require fork_types. +Axiom fork_types_Account : + IsGlobalAlias globals fork_types.globals "Account". +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". +Axiom fork_types_encode_account : + IsGlobalAlias globals fork_types.globals "encode_account". + +Require transactions. +Axiom transactions_LegacyTransaction : + IsGlobalAlias globals transactions.globals "LegacyTransaction". + +Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Root" |), + make_list [ + M.call (| + M.get_name (| globals, "hex_to_bytes" |), + make_list [ + Constant.str "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" + ], + make_dict [] + |) + ], + make_dict [] + |) +)). + +Definition Node : Value.t := M.run ltac:(M.monadic ( + M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Bytes" |); M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |); Constant.None_ ] |) +)). + +Definition K : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "TypeVar" |), + make_list [ + Constant.str "K" + ], + make_dict [] + |) +)). + +Definition V : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "TypeVar" |), + make_list [ + Constant.str "V"; + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Account" |) |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Bytes" |) |); + M.get_name (| globals, "Bytes" |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Bytes" |) ] |) |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Bytes" |) ] |) |); + M.get_name (| globals, "Uint" |); + M.get_name (| globals, "U256" |) + ], + make_dict [] + |) +)). + +Definition LeafNode : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition ExtensionNode : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition BranchNode : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition InternalNode : Value.t := M.run ltac:(M.monadic ( + M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LeafNode" |); M.get_name (| globals, "ExtensionNode" |); M.get_name (| globals, "BranchNode" |) ] |) +)). + +Definition encode_internal_node : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "node" ] |) in + let _ := Constant.str " + Encodes a Merkle Trie node into its RLP form. The RLP will then be + serialized into a `Bytes` and hashed unless it is less that 32 bytes + when serialized. + + This function also accepts `None`, representing the absence of a node, + which is encoded to `b""""""`. + + Parameters + ---------- + node : Optional[InternalNode] + The node to encode. + + Returns + ------- + encoded : `rlp.RLP` + The node encoded as RLP. + " in +(* At stmt: unsupported node type: AnnAssign *) + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "node" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let unencoded := + (* At constant: unsupported node type: Constant *) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "LeafNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "rest_of_key" |); + Constant.bool true + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "ExtensionNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "key_segment" |); + Constant.bool false + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "BranchNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + BinOp.add (| + M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "value" |) + ] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "AssertionError" |), + make_list [ + (* At expr: unsupported node type: JoinedStr *) + ], + make_dict [] + |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let encoded := + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "unencoded" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded" |) + ], + make_dict [] + |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "unencoded" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "encoded" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition encode_node : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "node"; "storage_root" ] |) in + let _ := Constant.str " + Encode a Node for storage in the Merkle Trie. + + Currently mostly an unimplemented stub. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "storage_root" |), Constant.None_ |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "encode_account" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "storage_root" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "U256" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "cast" |), + make_list [ + M.get_field (| M.get_name (| globals, "rlp" |), "RLP" |); + M.get_name (| globals, "node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "node" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "previous_trie" |), "encode_node" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "storage_root" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition Trie : Value.t := + builtins.make_klass + [(* At base: unsupported node type: Subscript *)] + [ + + ] + [ + + ]. + +Definition copy_trie : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie" ] |) in + let _ := Constant.str " + Create a copy of `trie`. Since only frozen objects may be stored in tries, + the contents are reused. + + Parameters + ---------- + trie: `Trie` + Trie to copy. + + Returns + ------- + new_trie : `Trie[K, V]` + A copy of the trie. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Trie" |), + make_list [ + M.get_field (| M.get_name (| globals, "trie" |), "secured" |); + M.get_field (| M.get_name (| globals, "trie" |), "default" |); + M.call (| + M.get_field (| M.get_name (| globals, "copy" |), "copy" |), + make_list [ + M.get_field (| M.get_name (| globals, "trie" |), "_data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition trie_set : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "key"; "value" ] |) in + let _ := Constant.str " + Stores an item in a Merkle Trie. + + This method deletes the key if `value == trie.default`, because the Merkle + Trie represents the default value by omitting it from the trie. + + Parameters + ---------- + trie: `Trie` + Trie to store in. + key : `Bytes` + Key to lookup. + value : `V` + Node to insert at `key`. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "value" |), M.get_field (| M.get_name (| globals, "trie" |), "default" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "key" |), M.get_field (| M.get_name (| globals, "trie" |), "_data" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition trie_get : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "key" ] |) in + let _ := Constant.str " + Gets an item from the Merkle Trie. + + This method returns `trie.default` if the key is missing. + + Parameters + ---------- + trie: + Trie to lookup in. + key : + Key to lookup. + + Returns + ------- + node : `V` + Node at `key` in the trie. + " in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "get" |), + make_list [ + M.get_name (| globals, "key" |); + M.get_field (| M.get_name (| globals, "trie" |), "default" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition common_prefix_length : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "a"; "b" ] |) in + let _ := Constant.str " + Find the longest common prefix of two sequences. + " in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + ], + make_dict [] + |) do + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| M.get_name (| globals, "i" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition nibble_list_to_compact : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "x"; "is_leaf" ] |) in + let _ := Constant.str " + Compresses nibble-list into a standard byte array with a flag. + + A nibble-list is a list of byte values no greater than `15`. The flag is + encoded in high nibble of the highest byte. The flag nibble can be broken + down into two two-bit flags. + + Highest nibble:: + + +---+---+----------+--------+ + | _ | _ | is_leaf | parity | + +---+---+----------+--------+ + 3 2 1 0 + + + The lowest bit of the nibble encodes the parity of the length of the + remaining nibbles -- `0` when even and `1` when odd. The second lowest bit + is used to distinguish leaf and extension nodes. The other two bits are not + used. + + Parameters + ---------- + x : + Array of nibbles. + is_leaf : + True if this is part of a leaf node, or false if it is an extension + node. + + Returns + ------- + compressed : `bytearray` + Compact byte array. + " in + let compact := + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + Constant.int 2 + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.mult (| + Constant.int 16, + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "is_leaf" |) + |) + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + BinOp.add (| + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "is_leaf" |) + |), + Constant.int 1 + |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), Constant.int 0 |) + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 1; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + M.get_name (| globals, "compact" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition bytes_to_nibble_list : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "bytes_" ] |) in + let _ := Constant.str " + Converts a `Bytes` into to a sequence of nibbles (bytes with value < 16). + + Parameters + ---------- + bytes_: + The `Bytes` to convert. + + Returns + ------- + nibble_list : `Bytes` + The `Bytes` in nibble-list format. + " in + let nibble_list := + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [ + BinOp.mult (| + Constant.int 2, + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "bytes_" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + For make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ] in M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "bytes_" |) + ], + make_dict [] + |) do + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |) |), + BinOp.r_shift (| + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 240 + |), + Constant.int 4 + |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |), + Constant.int 1 + |) |), + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 15 + |) + |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + M.get_name (| globals, "nibble_list" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition _prepare_trie : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "get_storage_root" ] |) in + let _ := Constant.str " + Prepares the trie for root calculation. Removes values that are empty, + hashes the keys (if `secured == True`) and encodes all the nodes. + + Parameters + ---------- + trie : + The `Trie` to prepare. + get_storage_root : + Function to get the storage root of an account. Needed to encode + `Account` objects. + + Returns + ------- + out : `Mapping[ethereum.base_types.Bytes, Node]` + Object with keys mapped to nibble-byte form. + " in +(* At stmt: unsupported node type: AnnAssign *) + For make_tuple [ M.get_name (| globals, "preimage" |); M.get_name (| globals, "value" |) ] in M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "items" |), + make_list [], + make_dict [] + |) do + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in + let address := + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |); + M.call (| + M.get_name (| globals, "get_storage_root" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_eq (| M.get_name (| globals, "encoded_value" |), (* At constant: unsupported node type: Constant *) |); + M.get_name (| globals, "AssertionError" |) + ], + make_dict [] + |) in +(* At stmt: unsupported node type: AnnAssign *) + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "trie" |), "secured" |), + (* then *) + ltac:(M.monadic ( + let key := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let key := + M.get_name (| globals, "preimage" |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "mapped" |), M.call (| + M.get_name (| globals, "bytes_to_nibble_list" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |) |), + M.get_name (| globals, "encoded_value" |) + |) in + EndFor. + let _ := M.return_ (| + M.get_name (| globals, "mapped" |) + |) in + M.pure Constant.None_)). + +Definition root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "get_storage_root" ] |) in + let _ := Constant.str " + Computes the root of a modified merkle patricia trie (MPT). + + Parameters + ---------- + trie : + `Trie` to get the root of. + get_storage_root : + Function to get the storage root of an account. Needed to encode + `Account` objects. + + + Returns + ------- + root : `.fork_types.Root` + MPT root of the underlying key-value pairs. + " in + let obj := + M.call (| + M.get_name (| globals, "_prepare_trie" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "get_storage_root" |) + ], + make_dict [] + |) in + let root_node := + M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_name (| globals, "obj" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assert (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "root_node" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Root" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition patricialize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "obj"; "level" ] |) in + let _ := Constant.str " + Structural composition function. + + Used to recursively patricialize and merkleize a dictionary. Includes + memoization of the tree structure and hashes. + + Parameters + ---------- + obj : + Underlying trie key-value pairs, with keys in nibble-list format. + level : + Current trie level. + + Returns + ------- + node : `ethereum.base_types.Bytes` + Root node of `obj`. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let arbitrary_key := + M.call (| + M.get_name (| globals, "next" |), + make_list [ + M.call (| + M.get_name (| globals, "iter" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), Constant.int 1 |), + (* then *) + ltac:(M.monadic ( + let leaf := + M.call (| + M.get_name (| globals, "LeafNode" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |); + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "leaf" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let substring := + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) in + let prefix_length := + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "substring" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do + let prefix_length := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_name (| globals, "prefix_length" |); + M.call (| + M.get_name (| globals, "common_prefix_length" |), + make_list [ + M.get_name (| globals, "substring" |); + M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let prefix := + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ExtensionNode" |), + make_list [ + M.get_name (| globals, "prefix" |); + M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_name (| globals, "obj" |); + BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in +(* At stmt: unsupported node type: AnnAssign *) + For M.get_name (| globals, "_" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 16 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "branches" |), "append" |), + make_list [ + {} + ], + make_dict [] + |) in + EndFor. + let value := + (* At constant: unsupported node type: Constant *) in + For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |), M.get_name (| globals, "level" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "AssertionError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) + |) in + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "BranchNode" |), + make_list [ + [M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "branches" |), M.get_name (| globals, "k" |) |); + BinOp.add (| + M.get_name (| globals, "level" |), + Constant.int 1 + |) + ], + make_dict [] + |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)]; + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/utils/__init__.v b/CoqOfPython/ethereum/gray_glacier/utils/__init__.v new file mode 100644 index 0000000..1baedea --- /dev/null +++ b/CoqOfPython/ethereum/gray_glacier/utils/__init__.v @@ -0,0 +1,8 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Utility functions unique to this particular fork. +". diff --git a/CoqOfPython/ethereum/gray_glacier/utils/address.v b/CoqOfPython/ethereum/gray_glacier/utils/address.v new file mode 100644 index 0000000..60e2f15 --- /dev/null +++ b/CoqOfPython/ethereum/gray_glacier/utils/address.v @@ -0,0 +1,204 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Hardfork Utility Functions For Addresses +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Address specific functions used in this gray_glacier version of +specification. +". + +Require typing. +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_left_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Definition to_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "data" ] |) in + let _ := Constant.str " + Convert a Uint or U256 value to a valid address (20 bytes). + + Parameters + ---------- + data : + The string to be converted to bytes. + + Returns + ------- + address : `Address` + The obtained address. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_subscript (| M.call (| + M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition compute_contract_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "address"; "nonce" ] |) in + let _ := Constant.str " + Computes address of the new account that needs to be created. + + Parameters + ---------- + address : + The address of the account that wants to create the new account. + nonce : + The transaction count of the account that wants to create the new + account. + + Returns + ------- + address: `Address` + The computed address of the new account. + " in + let computed_address := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_list [ + M.get_name (| globals, "address" |); + M.get_name (| globals, "nonce" |) + ] + ], + make_dict [] + |) + ], + make_dict [] + |) in + let canonical_address := + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + let padded_address := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "canonical_address" |); + Constant.int 20 + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "padded_address" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition compute_create2_contract_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "address"; "salt"; "call_data" ] |) in + let _ := Constant.str " + Computes address of the new account that needs to be created, which is + based on the sender address, salt and the call data as well. + + Parameters + ---------- + address : + The address of the account that wants to create the new account. + salt : + Address generation salt. + call_data : + The code of the new account which is to be created. + + Returns + ------- + address: `ethereum.gray_glacier.fork_types.Address` + The computed address of the new account. + " in + let preimage := + BinOp.add (| + BinOp.add (| + BinOp.add (| + (* At constant: unsupported node type: Constant *), + M.get_name (| globals, "address" |) + |), + M.get_name (| globals, "salt" |) + |), + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "call_data" |) + ], + make_dict [] + |) + |) in + let computed_address := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + let canonical_address := + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + let padded_address := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "canonical_address" |); + Constant.int 20 + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "padded_address" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/utils/hexadecimal.v b/CoqOfPython/ethereum/gray_glacier/utils/hexadecimal.v new file mode 100644 index 0000000..3d948f3 --- /dev/null +++ b/CoqOfPython/ethereum/gray_glacier/utils/hexadecimal.v @@ -0,0 +1,155 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Utility Functions For Hexadecimal Strings +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Hexadecimal utility functions used in this specification, specific to +Gray Glacier types. +". + +Require ethereum.utils.hexadecimal. +Axiom ethereum_utils_hexadecimal_remove_hex_prefix : + IsGlobalAlias globals ethereum.utils.hexadecimal.globals "remove_hex_prefix". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Definition hex_to_root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to trie root. + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to trie root. + + Returns + ------- + root : `Root` + Trie root obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Root" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition hex_to_bloom : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to bloom. + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to bloom. + + Returns + ------- + bloom : `Bloom` + Bloom obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bloom" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition hex_to_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to Address (20 bytes). + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to Address. + + Returns + ------- + address : `Address` + The address obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |), "rjust" |), + make_list [ + Constant.int 40; + Constant.str "0" + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/utils/message.v b/CoqOfPython/ethereum/gray_glacier/utils/message.v new file mode 100644 index 0000000..148c61e --- /dev/null +++ b/CoqOfPython/ethereum/gray_glacier/utils/message.v @@ -0,0 +1,254 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Hardfork Utility Functions For The Message Data-structure +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Message specific functions used in this gray_glacier version of +specification. +". + +Require typing. +Axiom typing_FrozenSet : + IsGlobalAlias globals typing.globals "FrozenSet". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". + +Require vm. +Axiom vm_Environment : + IsGlobalAlias globals vm.globals "Environment". +Axiom vm_Message : + IsGlobalAlias globals vm.globals "Message". + +Require vm.precompiled_contracts.mapping. +Axiom vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : + IsGlobalAlias globals vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". + +Require address. +Axiom address_compute_contract_address : + IsGlobalAlias globals address.globals "compute_contract_address". + +Definition prepare_message : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "caller"; "target"; "value"; "data"; "gas"; "env"; "code_address"; "should_transfer_value"; "is_static"; "preaccessed_addresses"; "preaccessed_storage_keys" ] |) in + let _ := Constant.str " + Execute a transaction against the provided environment. + + Parameters + ---------- + caller : + Address which initiated the transaction + target : + Address whose code will be executed + value : + Value to be transferred. + data : + Array of bytes provided to the code in `target`. + gas : + Gas provided for the code in `target`. + env : + Environment for the Ethereum Virtual Machine. + code_address : + This is usually same as the `target` address except when an alternative + accounts code needs to be executed. + eg. `CALLCODE` calling a precompile. + should_transfer_value : + if True ETH should be transferred while executing a message call. + is_static: + if True then it prevents all state-changing operations from being + executed. + preaccessed_addresses: + Addresses that should be marked as accessed prior to the message call + preaccessed_storage_keys: + Storage keys that should be marked as accessed prior to the message + call + + Returns + ------- + message: `ethereum.gray_glacier.vm.Message` + Items containing contract creation or message call specific data. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Bytes0" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.call (| + M.get_name (| globals, "compute_contract_address" |), + make_list [ + M.get_name (| globals, "caller" |); + BinOp.sub (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "caller" |) + ], + make_dict [] + |), "nonce" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let msg_data := + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |) in + let code := + M.get_name (| globals, "data" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.get_name (| globals, "target" |) in + let msg_data := + M.get_name (| globals, "data" |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "target" |) + ], + make_dict [] + |), "code" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "code_address" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let code_address := + M.get_name (| globals, "target" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "AssertionError" |), + make_list [ + Constant.str "Target must be address or empty bytes" + ], + make_dict [] + |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let accessed_addresses := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "current_target" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "caller" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "accessed_addresses" |), "update" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "PRE_COMPILED_CONTRACTS" |), "keys" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "accessed_addresses" |), "update" |), + make_list [ + M.get_name (| globals, "preaccessed_addresses" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/vm/__init__.v b/CoqOfPython/ethereum/gray_glacier/vm/__init__.v new file mode 100644 index 0000000..2ff63cd --- /dev/null +++ b/CoqOfPython/ethereum/gray_glacier/vm/__init__.v @@ -0,0 +1,262 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The abstract computer which runs the code stored in an +`.fork_types.Account`. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U64 : + IsGlobalAlias globals ethereum.base_types.globals "U64". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_State : + IsGlobalAlias globals state.globals "State". +Axiom state_account_exists_and_is_empty : + IsGlobalAlias globals state.globals "account_exists_and_is_empty". + +Require precompiled_contracts. +Axiom precompiled_contracts_RIPEMD160_ADDRESS : + IsGlobalAlias globals precompiled_contracts.globals "RIPEMD160_ADDRESS". + +Definition __all__ : Value.t := M.run ltac:(M.monadic ( + make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] +)). + +Definition Environment : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Message : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Evm : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition incorporate_child_on_success : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "child_evm" ] |) in + let _ := Constant.str " + Incorporate the state of a successful `child_evm` into the parent `evm`. + + Parameters + ---------- + evm : + The parent `EVM`. + child_evm : + The child evm to incorporate. + " in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "gas_left" |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "logs" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "logs" |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "refund_counter" |) + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "accounts_to_delete" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "accessed_addresses" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "accessed_storage_keys" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition incorporate_child_on_error : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "child_evm" ] |) in + let _ := Constant.str " + Incorporate the state of an unsuccessful `child_evm` into the parent `evm`. + + Parameters + ---------- + evm : + The parent `EVM`. + child_evm : + The child evm to incorporate. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "RIPEMD160_ADDRESS" |), M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |), M.get_name (| globals, "RIPEMD160_ADDRESS" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "gas_left" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/vm/exceptions.v b/CoqOfPython/ethereum/gray_glacier/vm/exceptions.v new file mode 100644 index 0000000..1f4363d --- /dev/null +++ b/CoqOfPython/ethereum/gray_glacier/vm/exceptions.v @@ -0,0 +1,172 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Exceptions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Exceptions which cause the EVM to halt exceptionally. +". + +Require ethereum.exceptions. +Axiom ethereum_exceptions_EthereumException : + IsGlobalAlias globals ethereum.exceptions.globals "EthereumException". + +Definition ExceptionalHalt : Value.t := + builtins.make_klass + [(globals, "EthereumException")] + [ + + ] + [ + + ]. + +Definition Revert : Value.t := + builtins.make_klass + [(globals, "EthereumException")] + [ + + ] + [ + + ]. + +Definition StackUnderflowError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition StackOverflowError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition OutOfGasError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition InvalidOpcode : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + ( + "__init__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "code" ] |) in + let _ := M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "super" |), + make_list [], + make_dict [] + |), "__init__" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "self" |), "code" |), + M.get_name (| globals, "code" |) + |) in + M.pure Constant.None_)) + ) + ]. + +Definition InvalidJumpDestError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition StackDepthLimitError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition WriteInStaticContext : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition OutOfBoundsRead : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition InvalidParameter : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition InvalidContractPrefix : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition AddressCollision : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/__init__.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/__init__.v new file mode 100644 index 0000000..e5bebd7 --- /dev/null +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/__init__.v @@ -0,0 +1,87 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +EVM Instruction Encoding (Opcodes) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Machine readable representations of EVM instructions, and a mapping to their +implementations. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". + +Require __init__. +Axiom __init___arithmetic : + IsGlobalAlias globals __init__.globals "arithmetic". + +Require __init__. +Axiom __init___bitwise : + IsGlobalAlias globals __init__.globals "bitwise". + +Require __init__. +Axiom __init___block : + IsGlobalAlias globals __init__.globals "block". + +Require __init__. +Axiom __init___comparison : + IsGlobalAlias globals __init__.globals "comparison". + +Require __init__. +Axiom __init___control_flow : + IsGlobalAlias globals __init__.globals "control_flow". + +Require __init__. +Axiom __init___environment : + IsGlobalAlias globals __init__.globals "environment". + +Require __init__. +Axiom __init___keccak : + IsGlobalAlias globals __init__.globals "keccak". + +Require __init__. +Axiom __init___log : + IsGlobalAlias globals __init__.globals "log". + +Require __init__. +Axiom __init___memory : + IsGlobalAlias globals __init__.globals "memory". + +Require __init__. +Axiom __init___stack : + IsGlobalAlias globals __init__.globals "stack". + +Require __init__. +Axiom __init___storage : + IsGlobalAlias globals __init__.globals "storage". + +Require __init__. +Axiom __init___system : + IsGlobalAlias globals __init__.globals "system". + +Definition Ops : Value.t := + builtins.make_klass + [(* At base: unsupported node type: Attribute *)] + [ + + ] + [ + + ]. + +(* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/arithmetic.v new file mode 100644 index 0000000..a8b5c61 --- /dev/null +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/arithmetic.v @@ -0,0 +1,1085 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Arithmetic Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM Arithmetic instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U255_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U255_CEIL_VALUE". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_U256_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_get_sign : + IsGlobalAlias globals ethereum.utils.numeric.globals "get_sign". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_EXPONENTIATION : + IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION". +Axiom gas_GAS_EXPONENTIATION_PER_BYTE : + IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION_PER_BYTE". +Axiom gas_GAS_LOW : + IsGlobalAlias globals gas.globals "GAS_LOW". +Axiom gas_GAS_MID : + IsGlobalAlias globals gas.globals "GAS_MID". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition add : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Adds the top two elements of the stack together, and pushes the result back + on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "x" |), "wrapping_add" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition sub : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Subtracts the top two elements of the stack, and pushes the result back + on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "x" |), "wrapping_sub" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mul : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Multiply the top two elements of the stack, and pushes the result back + on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "x" |), "wrapping_mul" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition div : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Integer division of the top two elements of the stack. Pushes the result + back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let dividend := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let divisor := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let quotient := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let quotient := + BinOp.floor_div (| + M.get_name (| globals, "dividend" |), + M.get_name (| globals, "divisor" |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "quotient" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition sdiv : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed integer division of the top two elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let dividend := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let divisor := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let quotient := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_name (| globals, "dividend" |), UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "divisor" |), UnOp.sub (| Constant.int 1 |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let quotient := + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let sign := + M.call (| + M.get_name (| globals, "get_sign" |), + make_list [ + BinOp.mult (| + M.get_name (| globals, "dividend" |), + M.get_name (| globals, "divisor" |) + |) + ], + make_dict [] + |) in + let quotient := + BinOp.mult (| + M.get_name (| globals, "sign" |), + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "dividend" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "divisor" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + M.get_name (| globals, "quotient" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Modulo remainder of the top two elements of the stack. Pushes the result + back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let remainder := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let remainder := + BinOp.mod_ (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "remainder" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition smod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed modulo remainder of the top two elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let y := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let remainder := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let remainder := + BinOp.mult (| + M.call (| + M.get_name (| globals, "get_sign" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + BinOp.mod_ (| + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + M.get_name (| globals, "remainder" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition addmod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Modulo addition of the top 2 elements with the 3rd element. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let z := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_MID" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.add (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |), + M.get_name (| globals, "z" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mulmod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Modulo multiplication of the top 2 elements with the 3rd element. Pushes + the result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let z := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_MID" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.mult (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |), + M.get_name (| globals, "z" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition exp : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Exponential operation of the top 2 elements. Pushes the result back on + the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let base := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exponent := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exponent_bits := + M.call (| + M.get_field (| M.get_name (| globals, "exponent" |), "bit_length" |), + make_list [], + make_dict [] + |) in + let exponent_bytes := + BinOp.floor_div (| + BinOp.add (| + M.get_name (| globals, "exponent_bits" |), + Constant.int 7 + |), + Constant.int 8 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_EXPONENTIATION" |), + BinOp.mult (| + M.get_name (| globals, "GAS_EXPONENTIATION_PER_BYTE" |), + M.get_name (| globals, "exponent_bytes" |) + |) + |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "pow" |), + make_list [ + M.get_name (| globals, "base" |); + M.get_name (| globals, "exponent" |); + M.get_name (| globals, "U256_CEIL_VALUE" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition signextend : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Sign extend operation. In other words, extend a signed number which + fits in N bytes to 32 bytes. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let byte_num := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "byte_num" |), Constant.int 31 |), + (* then *) + ltac:(M.monadic ( + let result := + M.get_name (| globals, "value" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let value_bytes := + M.call (| + M.get_name (| globals, "bytes" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "value" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) in + let value_bytes := + M.get_subscript (| M.get_name (| globals, "value_bytes" |), BinOp.sub (| + Constant.int 31, + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "byte_num" |) + ], + make_dict [] + |) + |):(* At expr: unsupported node type: NoneType *) |) in + let sign_bit := + BinOp.r_shift (| + M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), + Constant.int 7 + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "sign_bit" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "value_bytes" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let num_bytes_prepend := + BinOp.sub (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "byte_num" |), + Constant.int 1 + |) + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + BinOp.add (| + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [ + BinOp.mult (| + make_list [ + Constant.int 255 + ], + M.get_name (| globals, "num_bytes_prepend" |) + |) + ], + make_dict [] + |), + M.get_name (| globals, "value_bytes" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/bitwise.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/bitwise.v new file mode 100644 index 0000000..9f2f382 --- /dev/null +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/bitwise.v @@ -0,0 +1,601 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Bitwise Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM bitwise instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_U256_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition bitwise_and : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise AND operation of the top 2 elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + BinOp.bit_and (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_or : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise OR operation of the top 2 elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + BinOp.bit_or (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_xor : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise XOR operation of the top 2 elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + BinOp.bit_xor (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_not : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise NOT operation of the top element of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + UnOp.invert (| M.get_name (| globals, "x" |) |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition get_byte : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + For a word (defined by next top element of the stack), retrieve the + Nth byte (0-indexed and defined by top element of stack) from the + left (most significant) to right (least significant). + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let byte_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let word := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "byte_index" |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let extra_bytes_to_right := + BinOp.sub (| + Constant.int 31, + M.get_name (| globals, "byte_index" |) + |) in + let word := + BinOp.r_shift (| + M.get_name (| globals, "word" |), + BinOp.mult (| + M.get_name (| globals, "extra_bytes_to_right" |), + Constant.int 8 + |) + |) in + let word := + BinOp.bit_and (| + M.get_name (| globals, "word" |), + Constant.int 255 + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "word" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_shl : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Logical shift left (SHL) operation of the top 2 elements of the stack. + Pushes the result back on the stack. + Parameters + ---------- + evm : + The current EVM frame. + " in + let shift := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.l_shift (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "shift" |) + |), + M.get_name (| globals, "U256_CEIL_VALUE" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_shr : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Logical shift right (SHR) operation of the top 2 elements of the stack. + Pushes the result back on the stack. + Parameters + ---------- + evm : + The current EVM frame. + " in + let shift := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), + (* then *) + ltac:(M.monadic ( + let result := + BinOp.r_shift (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "shift" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_sar : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Arithmetic shift right (SAR) operation of the top 2 elements of the stack. + Pushes the result back on the stack. + Parameters + ---------- + evm : + The current EVM frame. + " in + let shift := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let signed_value := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + BinOp.r_shift (| + M.get_name (| globals, "signed_value" |), + M.get_name (| globals, "shift" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "signed_value" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/block.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/block.v new file mode 100644 index 0000000..26c73a7 --- /dev/null +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/block.v @@ -0,0 +1,379 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Block Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM block instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_BLOCK_HASH : + IsGlobalAlias globals gas.globals "GAS_BLOCK_HASH". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition block_hash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the hash of one of the 256 most recent complete blocks onto the + stack. The block number to hash is present at the top of the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let block_number := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BLOCK_HASH" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt_e (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), M.get_name (| globals, "block_number" |) |), + ltac:(M.monadic ( + Compare.gt (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), BinOp.add (| + M.get_name (| globals, "block_number" |), + Constant.int 256 + |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let hash := + (* At constant: unsupported node type: Constant *) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let hash := + M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + M.get_name (| globals, "block_number" |) + |) |) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "hash" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition coinbase : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's beneficiary address (address of the block miner) + onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "coinbase" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition timestamp : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's timestamp onto the stack. Here the timestamp + being referred is actually the unix timestamp in seconds. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "time" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition number : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's number onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition difficulty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's difficulty onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "difficulty" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition gas_limit : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's gas limit onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "gas_limit" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition chain_id : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the chain id onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "chain_id" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/comparison.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/comparison.v new file mode 100644 index 0000000..fbc35f8 --- /dev/null +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/comparison.v @@ -0,0 +1,404 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Comparison Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM Comparison instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition less_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is less than the next top element. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let right := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition signed_less_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed less-than comparison. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let right := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition greater_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is greater than the next top element. Pushes + the result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let right := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition signed_greater_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed greater-than comparison. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let right := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition equal : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is equal to the next top element. Pushes + the result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let right := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.eq (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition is_zero : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is equal to 0. Pushes the result back on the + stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.eq (| M.get_name (| globals, "x" |), Constant.int 0 |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/control_flow.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/control_flow.v new file mode 100644 index 0000000..04a79d9 --- /dev/null +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/control_flow.v @@ -0,0 +1,336 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Control Flow Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM control flow instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require vm.gas. +Axiom vm_gas_GAS_BASE : + IsGlobalAlias globals vm.gas.globals "GAS_BASE". +Axiom vm_gas_GAS_HIGH : + IsGlobalAlias globals vm.gas.globals "GAS_HIGH". +Axiom vm_gas_GAS_JUMPDEST : + IsGlobalAlias globals vm.gas.globals "GAS_JUMPDEST". +Axiom vm_gas_GAS_MID : + IsGlobalAlias globals vm.gas.globals "GAS_MID". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_InvalidJumpDestError : + IsGlobalAlias globals exceptions.globals "InvalidJumpDestError". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition stop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stop further execution of EVM code. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let _ := M.pass (| |) in + let _ := M.pass (| |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "running" |), + Constant.bool false + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition jump : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Alter the program counter to the location specified by the top of the + stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let jump_dest := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_MID" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "jump_dest" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition jumpi : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Alter the program counter to the specified location if and only if a + condition is true. If the condition is not true, then the program counter + would increase only by 1. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let jump_dest := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let conditional_value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_HIGH" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "conditional_value" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let destination := + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let destination := + M.get_name (| globals, "jump_dest" |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "destination" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition pc : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push onto the stack the value of the program counter after reaching the + current instruction and without increasing it for the next instruction. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "pc" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition gas_left : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the amount of available gas (including the corresponding reduction + for the cost of this instruction) onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition jumpdest : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Mark a valid destination for jumps. This is a noop, present only + to be used by `JUMP` and `JUMPI` opcodes to verify that their jump is + valid. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_JUMPDEST" |) + ], + make_dict [] + |) in + let _ := M.pass (| |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/environment.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/environment.v new file mode 100644 index 0000000..530304e --- /dev/null +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/environment.v @@ -0,0 +1,1436 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Environmental Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM environment related instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require fork_types. +Axiom fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". + +Require state. +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". + +Require utils.address. +Axiom utils_address_to_address : + IsGlobalAlias globals utils.address.globals "to_address". + +Require vm.memory. +Axiom vm_memory_buffer_read : + IsGlobalAlias globals vm.memory.globals "buffer_read". +Axiom vm_memory_memory_write : + IsGlobalAlias globals vm.memory.globals "memory_write". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_OutOfBoundsRead : + IsGlobalAlias globals exceptions.globals "OutOfBoundsRead". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_COLD_ACCOUNT_ACCESS : + IsGlobalAlias globals gas.globals "GAS_COLD_ACCOUNT_ACCESS". +Axiom gas_GAS_COPY : + IsGlobalAlias globals gas.globals "GAS_COPY". +Axiom gas_GAS_FAST_STEP : + IsGlobalAlias globals gas.globals "GAS_FAST_STEP". +Axiom gas_GAS_RETURN_DATA_COPY : + IsGlobalAlias globals gas.globals "GAS_RETURN_DATA_COPY". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_GAS_WARM_ACCESS : + IsGlobalAlias globals gas.globals "GAS_WARM_ACCESS". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the address of the current executing account to the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition balance : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the balance of the given account onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "balance" |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "balance" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition origin : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the address of the original transaction sender to the stack. + The origin address can only be an EOA. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "origin" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition caller : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the address of the caller onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "caller" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition callvalue : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the value (in wei) sent with the call onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition calldataload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push a word (32 bytes) of the input data belonging to the current + environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |); + M.get_name (| globals, "start_index" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition calldatasize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the size of input data in current environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition calldatacopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy a portion of the input data in current environment to memory. + + This will also expand the memory, in case that the memory is insufficient + to store the data. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let data_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |); + M.get_name (| globals, "data_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition codesize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the size of code running in current environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "code" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition codecopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy a portion of the code in current environment to memory. + + This will also expand the memory, in case that the memory is insufficient + to store the data. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let code_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "code" |); + M.get_name (| globals, "code_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition gasprice : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the gas price used in current environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "gas_price" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition extcodesize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the code size of a given account onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let codesize := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "code" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "codesize" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition extcodecopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy a portion of an account's code to memory. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let code_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_WARM_ACCESS" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "code" |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "code" |); + M.get_name (| globals, "code_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition returndatasize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the size of the return data buffer onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition returndatacopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copies data from the return data buffer code to memory + + Parameters + ---------- + evm : + The current EVM frame. + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let return_data_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_RETURN_DATA_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "return_data_start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "OutOfBoundsRead" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |):BinOp.add (| + M.get_name (| globals, "return_data_start_position" |), + M.get_name (| globals, "size" |) + |) |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition extcodehash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Returns the keccak256 hash of a contract’s bytecode + Parameters + ---------- + evm : + The current EVM frame. + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "account" |), M.get_name (| globals, "EMPTY_ACCOUNT" |) |), + (* then *) + ltac:(M.monadic ( + let codehash := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let codehash := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_field (| M.get_name (| globals, "account" |), "code" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "codehash" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition self_balance : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the balance of the current address to the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_FAST_STEP" |) + ], + make_dict [] + |) in + let balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "balance" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition base_fee : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the base fee of the current block on to the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "base_fee_per_gas" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/keccak.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/keccak.v new file mode 100644 index 0000000..cab9ffb --- /dev/null +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/keccak.v @@ -0,0 +1,181 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Keccak Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM keccak instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_KECCAK256 : + IsGlobalAlias globals gas.globals "GAS_KECCAK256". +Axiom gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition keccak : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes to the stack the Keccak-256 hash of a region of memory. + + This also expands the memory, in case the memory is insufficient to + access the data's memory location. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let word_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_KECCAK256_WORD" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_KECCAK256" |), + M.get_name (| globals, "word_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let data := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "hash" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/log.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/log.v new file mode 100644 index 0000000..4891a4d --- /dev/null +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/log.v @@ -0,0 +1,244 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Logging Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM logging instructions. +". + +Require functools. +Axiom functools_partial : + IsGlobalAlias globals functools.globals "partial". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_WriteInStaticContext : + IsGlobalAlias globals exceptions.globals "WriteInStaticContext". + +Require gas. +Axiom gas_GAS_LOG : + IsGlobalAlias globals gas.globals "GAS_LOG". +Axiom gas_GAS_LOG_DATA : + IsGlobalAlias globals gas.globals "GAS_LOG_DATA". +Axiom gas_GAS_LOG_TOPIC : + IsGlobalAlias globals gas.globals "GAS_LOG_TOPIC". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". + +Definition log_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "num_topics" ] |) in + let _ := Constant.str " + Appends a log entry, having `num_topics` topics, to the evm logs. + + This will also expand the memory if the data (required by the log entry) + corresponding to the memory is not accessible. + + Parameters + ---------- + evm : + The current EVM frame. + num_topics : + The number of topics to be included in the log entry. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let topics := + make_list [] in + For M.get_name (| globals, "_" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "num_topics" |) + ], + make_dict [] + |) do + let topic := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "topics" |), "append" |), + make_list [ + M.get_name (| globals, "topic" |) + ], + make_dict [] + |) in + EndFor. + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_LOG" |), + BinOp.mult (| + M.get_name (| globals, "GAS_LOG_DATA" |), + M.get_name (| globals, "size" |) + |) + |), + BinOp.mult (| + M.get_name (| globals, "GAS_LOG_TOPIC" |), + M.get_name (| globals, "num_topics" |) + |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let log_entry := + M.call (| + M.get_name (| globals, "Log" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "logs" |), + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "logs" |), + make_tuple [ M.get_name (| globals, "log_entry" |) ] + |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition log0 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/memory.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/memory.v new file mode 100644 index 0000000..1e1c8b0 --- /dev/null +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/memory.v @@ -0,0 +1,378 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Memory Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM Memory instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". +Axiom memory_memory_write : + IsGlobalAlias globals memory.globals "memory_write". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition mstore : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a word to memory. + This also expands the memory, if the memory is + insufficient to store the word. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "start_position" |); M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + ], + make_dict [] + |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "start_position" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mstore8 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a byte to memory. + This also expands the memory, if the memory is + insufficient to store the word. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "start_position" |); M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let normalized_bytes_value := + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + make_list [ + BinOp.bit_and (| + M.get_name (| globals, "value" |), + Constant.int 255 + |) + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "start_position" |); + M.get_name (| globals, "normalized_bytes_value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Load word from memory. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "start_position" |); M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "start_position" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition msize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the size of active memory in bytes onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/stack.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/stack.v new file mode 100644 index 0000000..1eeda05 --- /dev/null +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/stack.v @@ -0,0 +1,929 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Stack Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM stack related instructions. +". + +Require functools. +Axiom functools_partial : + IsGlobalAlias globals functools.globals "partial". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". +Axiom __init___stack : + IsGlobalAlias globals __init__.globals "stack". + +Require exceptions. +Axiom exceptions_StackUnderflowError : + IsGlobalAlias globals exceptions.globals "StackUnderflowError". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_buffer_read : + IsGlobalAlias globals memory.globals "buffer_read". + +Definition pop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Remove item from stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.pass (| |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition push_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "num_bytes" ] |) in + let _ := Constant.str " + Pushes a N-byte immediate onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + num_bytes : + The number of immediate bytes to be read from the code and pushed to + the stack. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let data_to_push := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "code" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "num_bytes" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "data_to_push" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + BinOp.add (| + Constant.int 1, + M.get_name (| globals, "num_bytes" |) + |) + |) in + M.pure Constant.None_)). + +Definition dup_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "item_number" ] |) in + let _ := Constant.str " + Duplicate the Nth stack item (from top of the stack) to the top of stack. + + Parameters + ---------- + evm : + The current EVM frame. + + item_number : + The stack item number (0-indexed from top of stack) to be duplicated + to the top of stack. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "StackUnderflowError" |) + ], + make_dict [] + |) in + let data_to_duplicate := + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + BinOp.sub (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), + Constant.int 1 + |), + M.get_name (| globals, "item_number" |) + |) |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "data_to_duplicate" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition swap_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "item_number" ] |) in + let _ := Constant.str " + Swap the top and the `item_number` element of the stack, where + the top of the stack is position zero. + + If `item_number` is zero, this function does nothing (which should not be + possible, since there is no `SWAP0` instruction). + + Parameters + ---------- + evm : + The current EVM frame. + + item_number : + The stack item number (0-indexed from top of stack) to be swapped + with the top of stack element. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "StackUnderflowError" |) + ], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) |) ], + make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |) ] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition push1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push5 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push6 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push7 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push8 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push9 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push10 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push11 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push12 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push13 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push14 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push15 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push16 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push17 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push18 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push19 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push20 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push21 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push22 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push23 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push24 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push25 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push26 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push27 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push28 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push29 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push30 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push31 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push32 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition dup1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup5 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup6 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup7 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup8 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup9 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup10 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup11 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup12 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup13 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup14 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup15 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup16 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition swap1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap5 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap6 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap7 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap8 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap9 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap10 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap11 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap12 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap13 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap14 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap15 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap16 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/storage.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/storage.v new file mode 100644 index 0000000..2f0a831 --- /dev/null +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/storage.v @@ -0,0 +1,437 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Storage Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM storage related instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require state. +Axiom state_get_storage : + IsGlobalAlias globals state.globals "get_storage". +Axiom state_get_storage_original : + IsGlobalAlias globals state.globals "get_storage_original". +Axiom state_set_storage : + IsGlobalAlias globals state.globals "set_storage". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". +Axiom exceptions_WriteInStaticContext : + IsGlobalAlias globals exceptions.globals "WriteInStaticContext". + +Require gas. +Axiom gas_GAS_CALL_STIPEND : + IsGlobalAlias globals gas.globals "GAS_CALL_STIPEND". +Axiom gas_GAS_COLD_SLOAD : + IsGlobalAlias globals gas.globals "GAS_COLD_SLOAD". +Axiom gas_GAS_STORAGE_CLEAR_REFUND : + IsGlobalAlias globals gas.globals "GAS_STORAGE_CLEAR_REFUND". +Axiom gas_GAS_STORAGE_SET : + IsGlobalAlias globals gas.globals "GAS_STORAGE_SET". +Axiom gas_GAS_STORAGE_UPDATE : + IsGlobalAlias globals gas.globals "GAS_STORAGE_UPDATE". +Axiom gas_GAS_WARM_ACCESS : + IsGlobalAlias globals gas.globals "GAS_WARM_ACCESS". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition sload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Loads to the stack, the value corresponding to a certain key from the + storage of the current account. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let key := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "add" |), + make_list [ + make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_COLD_SLOAD" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let value := + M.call (| + M.get_name (| globals, "get_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition sstore : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a value at a certain key in the current context's storage. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let key := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let new_value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt (| M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), M.get_name (| globals, "GAS_CALL_STIPEND" |) |); + M.get_name (| globals, "OutOfGasError" |) + ], + make_dict [] + |) in + let original_value := + M.call (| + M.get_name (| globals, "get_storage_original" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let current_value := + M.call (| + M.get_name (| globals, "get_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let gas_cost := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "add" |), + make_list [ + make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ] + ], + make_dict [] + |) in + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_COLD_SLOAD" |) + M.get_name (| globals, "GAS_COLD_SLOAD" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_name (| globals, "original_value" |), M.get_name (| globals, "current_value" |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_name (| globals, "current_value" |), M.get_name (| globals, "new_value" |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_STORAGE_SET" |) + M.get_name (| globals, "GAS_STORAGE_SET" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let gas_cost := BinOp.add + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_UPDATE" |), + M.get_name (| globals, "GAS_COLD_SLOAD" |) + |) + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_UPDATE" |), + M.get_name (| globals, "GAS_COLD_SLOAD" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_WARM_ACCESS" |) + M.get_name (| globals, "GAS_WARM_ACCESS" |) in + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| M.get_name (| globals, "current_value" |), M.get_name (| globals, "new_value" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "new_value" |), Constant.int 0 |) + )) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.sub, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "original_value" |), M.get_name (| globals, "new_value" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_SET" |), + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.sub (| + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_UPDATE" |), + M.get_name (| globals, "GAS_COLD_SLOAD" |) + |), + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "gas_cost" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "set_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |); + M.get_name (| globals, "new_value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/vm/interpreter.v b/CoqOfPython/ethereum/gray_glacier/vm/interpreter.v new file mode 100644 index 0000000..8179355 --- /dev/null +++ b/CoqOfPython/ethereum/gray_glacier/vm/interpreter.v @@ -0,0 +1,645 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Interpreter +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +A straightforward interpreter that executes EVM code. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Iterable : + IsGlobalAlias globals typing.globals "Iterable". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.trace. +Axiom ethereum_trace_EvmStop : + IsGlobalAlias globals ethereum.trace.globals "EvmStop". +Axiom ethereum_trace_OpEnd : + IsGlobalAlias globals ethereum.trace.globals "OpEnd". +Axiom ethereum_trace_OpException : + IsGlobalAlias globals ethereum.trace.globals "OpException". +Axiom ethereum_trace_OpStart : + IsGlobalAlias globals ethereum.trace.globals "OpStart". +Axiom ethereum_trace_PrecompileEnd : + IsGlobalAlias globals ethereum.trace.globals "PrecompileEnd". +Axiom ethereum_trace_PrecompileStart : + IsGlobalAlias globals ethereum.trace.globals "PrecompileStart". +Axiom ethereum_trace_TransactionEnd : + IsGlobalAlias globals ethereum.trace.globals "TransactionEnd". +Axiom ethereum_trace_evm_trace : + IsGlobalAlias globals ethereum.trace.globals "evm_trace". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_account_exists_and_is_empty : + IsGlobalAlias globals state.globals "account_exists_and_is_empty". +Axiom state_account_has_code_or_nonce : + IsGlobalAlias globals state.globals "account_has_code_or_nonce". +Axiom state_begin_transaction : + IsGlobalAlias globals state.globals "begin_transaction". +Axiom state_commit_transaction : + IsGlobalAlias globals state.globals "commit_transaction". +Axiom state_destroy_storage : + IsGlobalAlias globals state.globals "destroy_storage". +Axiom state_increment_nonce : + IsGlobalAlias globals state.globals "increment_nonce". +Axiom state_mark_account_created : + IsGlobalAlias globals state.globals "mark_account_created". +Axiom state_move_ether : + IsGlobalAlias globals state.globals "move_ether". +Axiom state_rollback_transaction : + IsGlobalAlias globals state.globals "rollback_transaction". +Axiom state_set_code : + IsGlobalAlias globals state.globals "set_code". +Axiom state_touch_account : + IsGlobalAlias globals state.globals "touch_account". + +Require vm. +Axiom vm_Message : + IsGlobalAlias globals vm.globals "Message". + +Require vm.gas. +Axiom vm_gas_GAS_CODE_DEPOSIT : + IsGlobalAlias globals vm.gas.globals "GAS_CODE_DEPOSIT". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require vm.precompiled_contracts.mapping. +Axiom vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : + IsGlobalAlias globals vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". + +Require __init__. +Axiom __init___Environment : + IsGlobalAlias globals __init__.globals "Environment". +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_AddressCollision : + IsGlobalAlias globals exceptions.globals "AddressCollision". +Axiom exceptions_ExceptionalHalt : + IsGlobalAlias globals exceptions.globals "ExceptionalHalt". +Axiom exceptions_InvalidContractPrefix : + IsGlobalAlias globals exceptions.globals "InvalidContractPrefix". +Axiom exceptions_InvalidOpcode : + IsGlobalAlias globals exceptions.globals "InvalidOpcode". +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". +Axiom exceptions_Revert : + IsGlobalAlias globals exceptions.globals "Revert". +Axiom exceptions_StackDepthLimitError : + IsGlobalAlias globals exceptions.globals "StackDepthLimitError". + +Require instructions. +Axiom instructions_Ops : + IsGlobalAlias globals instructions.globals "Ops". +Axiom instructions_op_implementation : + IsGlobalAlias globals instructions.globals "op_implementation". + +Require runtime. +Axiom runtime_get_valid_jump_destinations : + IsGlobalAlias globals runtime.globals "get_valid_jump_destinations". + +Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1024 + ], + make_dict [] + |) +)). + +Definition MAX_CODE_SIZE : Value.t := M.run ltac:(M.monadic ( + Constant.int 24576 +)). + +Definition MessageCallOutput : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition process_message_call : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + If `message.current` is empty then it creates a smart contract + else it executes a call from the `message.caller` to the `message.target`. + + Parameters + ---------- + message : + Transaction specific items. + + env : + External items required for EVM execution. + + Returns + ------- + output : `MessageCallOutput` + Output of the message call + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_name (| globals, "message" |), "target" |), M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let is_collision := + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_name (| globals, "is_collision" |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallOutput" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "tuple" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "AddressCollision" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let evm := + M.call (| + M.get_name (| globals, "process_create_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let evm := + M.call (| + M.get_name (| globals, "process_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_field (| M.get_name (| globals, "message" |), "target" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_field (| M.get_name (| globals, "message" |), "target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( +(* At stmt: unsupported node type: AnnAssign *) + let accounts_to_delete := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let touched_accounts := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let refund_counter := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let logs := + M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in + let accounts_to_delete := + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in + let touched_accounts := + M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |) in + let refund_counter := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let tx_end := + M.call (| + M.get_name (| globals, "TransactionEnd" |), + make_list [ + BinOp.sub (| + M.get_field (| M.get_name (| globals, "message" |), "gas" |), + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + |); + M.get_field (| M.get_name (| globals, "evm" |), "output" |); + M.get_field (| M.get_name (| globals, "evm" |), "error" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "evm_trace" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "tx_end" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallOutput" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition process_create_message : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + Executes a call to create a smart contract. + + Parameters + ---------- + message : + Transaction specific items. + env : + External items required for EVM execution. + + Returns + ------- + evm: :py:class:`~ethereum.london.vm.Evm` + Items containing execution specific objects. + " in + let _ := M.call (| + M.get_name (| globals, "begin_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "destroy_storage" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "mark_account_created" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let evm := + M.call (| + M.get_name (| globals, "process_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), + (* then *) + ltac:(M.monadic ( + let contract_code := + M.get_field (| M.get_name (| globals, "evm" |), "output" |) in + let contract_code_gas := + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "contract_code" |) + ], + make_dict [] + |), + M.get_name (| globals, "GAS_CODE_DEPOSIT" |) + |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "rollback_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.get_name (| globals, "evm" |) + |) in + M.pure Constant.None_)). + +Definition process_message : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + Executes a call to create a smart contract. + + Parameters + ---------- + message : + Transaction specific items. + env : + External items required for EVM execution. + + Returns + ------- + evm: :py:class:`~ethereum.london.vm.Evm` + Items containing execution specific objects + " in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_field (| M.get_name (| globals, "message" |), "depth" |), M.get_name (| globals, "STACK_DEPTH_LIMIT" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "StackDepthLimitError" |), + make_list [ + Constant.str "Stack depth limit reached" + ], + make_dict [] + |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "begin_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "touch_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + M.get_field (| M.get_name (| globals, "message" |), "should_transfer_value" |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_field (| M.get_name (| globals, "message" |), "value" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "move_ether" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "caller" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |); + M.get_field (| M.get_name (| globals, "message" |), "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let evm := + M.call (| + M.get_name (| globals, "execute_code" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "rollback_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "commit_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.get_name (| globals, "evm" |) + |) in + M.pure Constant.None_)). + +Definition execute_code : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + Executes bytecode present in the `message`. + + Parameters + ---------- + message : + Transaction specific items. + env : + External items required for EVM execution. + + Returns + ------- + evm: `ethereum.vm.EVM` + Items containing execution specific objects + " in + let code := + M.get_field (| M.get_name (| globals, "message" |), "code" |) in + let valid_jump_destinations := + M.call (| + M.get_name (| globals, "get_valid_jump_destinations" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) in + let evm := + M.call (| + M.get_name (| globals, "Evm" |), + make_list [], + make_dict [] + |) in +(* At stmt: unsupported node type: Try *) + let _ := M.return_ (| + M.get_name (| globals, "evm" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/vm/memory.v b/CoqOfPython/ethereum/gray_glacier/vm/memory.v new file mode 100644 index 0000000..fa8d906 --- /dev/null +++ b/CoqOfPython/ethereum/gray_glacier/vm/memory.v @@ -0,0 +1,153 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Memory +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +EVM memory operations. +". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_right_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "right_pad_zero_bytes". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". + +Definition memory_write : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "memory"; "start_position"; "value" ] |) in + let _ := Constant.str " + Writes to memory. + + Parameters + ---------- + memory : + Memory contents of the EVM. + start_position : + Starting pointer to the memory. + value : + Data to write to memory. + " in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) |), + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_)). + +Definition memory_read_bytes : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "memory"; "start_position"; "size" ] |) in + let _ := Constant.str " + Read bytes from memory. + + Parameters + ---------- + memory : + Memory contents of the EVM. + start_position : + Starting pointer to the memory. + size : + Size of the data that needs to be read from `start_position`. + + Returns + ------- + data_bytes : + Data read from memory. + " in + let _ := M.return_ (| + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |) + |) in + M.pure Constant.None_)). + +Definition buffer_read : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "buffer"; "start_position"; "size" ] |) in + let _ := Constant.str " + Read bytes from a buffer. Padding with zeros if necessary. + + Parameters + ---------- + buffer : + Memory contents of the EVM. + start_position : + Starting pointer to the memory. + size : + Size of the data that needs to be read from `start_position`. + + Returns + ------- + data_bytes : + Data read from memory. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "right_pad_zero_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/__init__.v new file mode 100644 index 0000000..ca49311 --- /dev/null +++ b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/__init__.v @@ -0,0 +1,117 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Precompiled Contract Addresses +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Addresses of precompiled contracts and mappings to their +implementations. +". + +Require utils.hexadecimal. +Axiom utils_hexadecimal_hex_to_address : + IsGlobalAlias globals utils.hexadecimal.globals "hex_to_address". + +Definition __all__ : Value.t := M.run ltac:(M.monadic ( + make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS"; Constant.str "MODEXP_ADDRESS"; Constant.str "ALT_BN128_ADD_ADDRESS"; Constant.str "ALT_BN128_MUL_ADDRESS"; Constant.str "ALT_BN128_PAIRING_CHECK_ADDRESS"; Constant.str "BLAKE2F_ADDRESS" ] +)). + +Definition ECRECOVER_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x01" + ], + make_dict [] + |) +)). + +Definition SHA256_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x02" + ], + make_dict [] + |) +)). + +Definition RIPEMD160_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x03" + ], + make_dict [] + |) +)). + +Definition IDENTITY_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x04" + ], + make_dict [] + |) +)). + +Definition MODEXP_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x05" + ], + make_dict [] + |) +)). + +Definition ALT_BN128_ADD_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x06" + ], + make_dict [] + |) +)). + +Definition ALT_BN128_MUL_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x07" + ], + make_dict [] + |) +)). + +Definition ALT_BN128_PAIRING_CHECK_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x08" + ], + make_dict [] + |) +)). + +Definition BLAKE2F_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x09" + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/alt_bn128.v new file mode 100644 index 0000000..19b83fc --- /dev/null +++ b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/alt_bn128.v @@ -0,0 +1,673 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) ALT_BN128 CONTRACTS +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the ALT_BN128 precompiled contracts. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.alt_bn128. +Axiom ethereum_crypto_alt_bn128_ALT_BN128_CURVE_ORDER : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "ALT_BN128_CURVE_ORDER". +Axiom ethereum_crypto_alt_bn128_ALT_BN128_PRIME : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "ALT_BN128_PRIME". +Axiom ethereum_crypto_alt_bn128_BNF : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF". +Axiom ethereum_crypto_alt_bn128_BNF2 : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF2". +Axiom ethereum_crypto_alt_bn128_BNF12 : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF12". +Axiom ethereum_crypto_alt_bn128_BNP : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNP". +Axiom ethereum_crypto_alt_bn128_BNP2 : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNP2". +Axiom ethereum_crypto_alt_bn128_pairing : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "pairing". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require vm.memory. +Axiom vm_memory_buffer_read : + IsGlobalAlias globals vm.memory.globals "buffer_read". + +Require exceptions. +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". + +Definition alt_bn128_add : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + The ALT_BN128 addition precompiled contract. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 150 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x0_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x0_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "x0_bytes" |) + ], + make_dict [] + |) in + let y0_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y0_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "y0_bytes" |) + ], + make_dict [] + |) in + let x1_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x1_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "x1_bytes" |) + ], + make_dict [] + |) in + let y1_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y1_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "y1_bytes" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ] do + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "i" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. +(* At stmt: unsupported node type: Try *) + let p := + BinOp.add (| + M.get_name (| globals, "p0" |), + M.get_name (| globals, "p1" |) + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + BinOp.add (| + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "p" |), "x" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "p" |), "y" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) + |) in + M.pure Constant.None_)). + +Definition alt_bn128_mul : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + The ALT_BN128 multiplication precompiled contract. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 6000 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x0_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x0_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "x0_bytes" |) + ], + make_dict [] + |) in + let y0_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y0_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "y0_bytes" |) + ], + make_dict [] + |) in + let n := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ] do + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "i" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. +(* At stmt: unsupported node type: Try *) + let p := + M.call (| + M.get_field (| M.get_name (| globals, "p0" |), "mul_by" |), + make_list [ + M.get_name (| globals, "n" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + BinOp.add (| + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "p" |), "x" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "p" |), "y" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) + |) in + M.pure Constant.None_)). + +Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + The ALT_BN128 pairing check precompiled contract. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 34000, + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 192 + |) + |), + Constant.int 45000 + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 192 + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 192 + |) + ], + make_dict [] + |) do + let values := + make_list [] in + For M.get_name (| globals, "j" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 6 + ], + make_dict [] + |) do + let value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "data" |), BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + M.get_name (| globals, "j" |) + |) + |):BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "j" |), + Constant.int 1 + |) + |) + |) |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "value" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "values" |), "append" |), + make_list [ + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + EndFor. +(* At stmt: unsupported node type: Try *) + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.call (| + M.get_field (| M.get_name (| globals, "p" |), "mul_by" |), + make_list [ + M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) + ], + make_dict [] + |), M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) |); + M.get_name (| globals, "OutOfGasError" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.call (| + M.get_field (| M.get_name (| globals, "q" |), "mul_by" |), + make_list [ + M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) + ], + make_dict [] + |), M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) |); + M.get_name (| globals, "OutOfGasError" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "p" |), M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_name (| globals, "q" |), M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let result := + BinOp.mult (| + M.get_name (| globals, "result" |), + M.call (| + M.get_name (| globals, "pairing" |), + make_list [ + M.get_name (| globals, "q" |); + M.get_name (| globals, "p" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "result" |), M.call (| + M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/blake2f.v b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/blake2f.v new file mode 100644 index 0000000..5903066 --- /dev/null +++ b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/blake2f.v @@ -0,0 +1,122 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Blake2 PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `Blake2` precompiled contract. +". + +Require ethereum.crypto.blake2. +Axiom ethereum_crypto_blake2_Blake2b : + IsGlobalAlias globals ethereum.crypto.blake2.globals "Blake2b". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_BLAKE2_PER_ROUND : + IsGlobalAlias globals vm.gas.globals "GAS_BLAKE2_PER_ROUND". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require exceptions. +Axiom exceptions_InvalidParameter : + IsGlobalAlias globals exceptions.globals "InvalidParameter". + +Definition blake2f : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the Blake2 hash to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), Constant.int 213 |); + M.get_name (| globals, "InvalidParameter" |) + ], + make_dict [] + |) in + let blake2b := + M.call (| + M.get_name (| globals, "Blake2b" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "rounds" |); M.get_name (| globals, "h" |); M.get_name (| globals, "m" |); M.get_name (| globals, "t_0" |); M.get_name (| globals, "t_1" |); M.get_name (| globals, "f" |) ], + M.call (| + M.get_field (| M.get_name (| globals, "blake2b" |), "get_blake2_parameters" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.mult (| + M.get_name (| globals, "GAS_BLAKE2_PER_ROUND" |), + M.get_name (| globals, "rounds" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.in (| M.get_name (| globals, "f" |), make_list [ + Constant.int 0; + Constant.int 1 + ] |); + M.get_name (| globals, "InvalidParameter" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.get_name (| globals, "blake2b" |), "compress" |), + make_list [ + M.get_name (| globals, "rounds" |); + M.get_name (| globals, "h" |); + M.get_name (| globals, "m" |); + M.get_name (| globals, "t_0" |); + M.get_name (| globals, "t_1" |); + M.get_name (| globals, "f" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/ecrecover.v new file mode 100644 index 0000000..cc351b5 --- /dev/null +++ b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/ecrecover.v @@ -0,0 +1,269 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) ECRECOVER PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the ECRECOVER precompiled contract. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require ethereum.crypto.elliptic_curve. +Axiom ethereum_crypto_elliptic_curve_SECP256K1N : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_left_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_ECRECOVER : + IsGlobalAlias globals vm.gas.globals "GAS_ECRECOVER". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require vm.memory. +Axiom vm_memory_buffer_read : + IsGlobalAlias globals vm.memory.globals "buffer_read". + +Definition ecrecover : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Decrypts the address using elliptic curve DSA recovery mechanism and writes + the address to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_ECRECOVER" |) + ], + make_dict [] + |) in + let message_hash_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let message_hash := + M.call (| + M.get_name (| globals, "Hash32" |), + make_list [ + M.get_name (| globals, "message_hash_bytes" |) + ], + make_dict [] + |) in + let v := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let r := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let s := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 27 |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 28 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| Constant.int 0, M.get_name (| globals, "r" |) |), + ltac:(M.monadic ( + Compare.gt_e (| M.get_name (| globals, "r" |), M.get_name (| globals, "SECP256K1N" |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| Constant.int 0, M.get_name (| globals, "s" |) |), + ltac:(M.monadic ( + Compare.gt_e (| M.get_name (| globals, "s" |), M.get_name (| globals, "SECP256K1N" |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in +(* At stmt: unsupported node type: Try *) + let address := + M.get_subscript (| M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), Constant.int 12:Constant.int 32 |) in + let padded_address := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "address" |); + Constant.int 32 + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.get_name (| globals, "padded_address" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/identity.v new file mode 100644 index 0000000..fa96704 --- /dev/null +++ b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/identity.v @@ -0,0 +1,94 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) IDENTITY PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `IDENTITY` precompiled contract. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_IDENTITY : + IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY". +Axiom vm_gas_GAS_IDENTITY_WORD : + IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY_WORD". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition identity : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the message data to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let word_count := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_IDENTITY" |), + BinOp.mult (| + M.get_name (| globals, "GAS_IDENTITY_WORD" |), + M.get_name (| globals, "word_count" |) + |) + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.get_name (| globals, "data" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/mapping.v new file mode 100644 index 0000000..8a2e2eb --- /dev/null +++ b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/mapping.v @@ -0,0 +1,82 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Precompiled Contract Addresses +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Mapping of precompiled contracts their implementations. +". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require __init__. +Axiom __init___ALT_BN128_ADD_ADDRESS : + IsGlobalAlias globals __init__.globals "ALT_BN128_ADD_ADDRESS". +Axiom __init___ALT_BN128_MUL_ADDRESS : + IsGlobalAlias globals __init__.globals "ALT_BN128_MUL_ADDRESS". +Axiom __init___ALT_BN128_PAIRING_CHECK_ADDRESS : + IsGlobalAlias globals __init__.globals "ALT_BN128_PAIRING_CHECK_ADDRESS". +Axiom __init___BLAKE2F_ADDRESS : + IsGlobalAlias globals __init__.globals "BLAKE2F_ADDRESS". +Axiom __init___ECRECOVER_ADDRESS : + IsGlobalAlias globals __init__.globals "ECRECOVER_ADDRESS". +Axiom __init___IDENTITY_ADDRESS : + IsGlobalAlias globals __init__.globals "IDENTITY_ADDRESS". +Axiom __init___MODEXP_ADDRESS : + IsGlobalAlias globals __init__.globals "MODEXP_ADDRESS". +Axiom __init___RIPEMD160_ADDRESS : + IsGlobalAlias globals __init__.globals "RIPEMD160_ADDRESS". +Axiom __init___SHA256_ADDRESS : + IsGlobalAlias globals __init__.globals "SHA256_ADDRESS". + +Require alt_bn128. +Axiom alt_bn128_alt_bn128_add : + IsGlobalAlias globals alt_bn128.globals "alt_bn128_add". +Axiom alt_bn128_alt_bn128_mul : + IsGlobalAlias globals alt_bn128.globals "alt_bn128_mul". +Axiom alt_bn128_alt_bn128_pairing_check : + IsGlobalAlias globals alt_bn128.globals "alt_bn128_pairing_check". + +Require blake2f. +Axiom blake2f_blake2f : + IsGlobalAlias globals blake2f.globals "blake2f". + +Require ecrecover. +Axiom ecrecover_ecrecover : + IsGlobalAlias globals ecrecover.globals "ecrecover". + +Require identity. +Axiom identity_identity : + IsGlobalAlias globals identity.globals "identity". + +Require modexp. +Axiom modexp_modexp : + IsGlobalAlias globals modexp.globals "modexp". + +Require ripemd160. +Axiom ripemd160_ripemd160 : + IsGlobalAlias globals ripemd160.globals "ripemd160". + +Require sha256. +Axiom sha256_sha256 : + IsGlobalAlias globals sha256.globals "sha256". + +(* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/modexp.v new file mode 100644 index 0000000..544949e --- /dev/null +++ b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/modexp.v @@ -0,0 +1,608 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) MODEXP PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `MODEXP` precompiled contract. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require memory. +Axiom memory_buffer_read : + IsGlobalAlias globals memory.globals "buffer_read". + +Definition GQUADDIVISOR : Value.t := M.run ltac:(M.monadic ( + Constant.int 3 +)). + +Definition modexp : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Calculates `(base**exp) % modulus` for arbitrary sized `base`, `exp` and. + `modulus`. The return value is the same length as the modulus. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let base_length := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exp_length := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let modulus_length := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exp_start := + BinOp.add (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |), + M.get_name (| globals, "base_length" |) + |) in + let exp_head := + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.get_name (| globals, "exp_start" |); + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.get_name (| globals, "exp_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "gas_cost" |), + make_list [ + M.get_name (| globals, "base_length" |); + M.get_name (| globals, "modulus_length" |); + M.get_name (| globals, "exp_length" |); + M.get_name (| globals, "exp_head" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_name (| globals, "base_length" |), Constant.int 0 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "modulus_length" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [], + make_dict [] + |) + |) in + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let base := + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |); + M.get_name (| globals, "base_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exp := + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.get_name (| globals, "exp_start" |); + M.get_name (| globals, "exp_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let modulus_start := + BinOp.add (| + M.get_name (| globals, "exp_start" |), + M.get_name (| globals, "exp_length" |) + |) in + let modulus := + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.get_name (| globals, "modulus_start" |); + M.get_name (| globals, "modulus_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "modulus" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + BinOp.mult (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |), + M.get_name (| globals, "modulus_length" |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pow" |), + make_list [ + M.get_name (| globals, "base" |); + M.get_name (| globals, "exp" |); + M.get_name (| globals, "modulus" |) + ], + make_dict [] + |) + ], + make_dict [] + |), "to_bytes" |), + make_list [ + M.get_name (| globals, "modulus_length" |); + Constant.str "big" + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition complexity : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "base_length"; "modulus_length" ] |) in + let _ := Constant.str " + Estimate the complexity of performing a modular exponentiation. + + Parameters + ---------- + + base_length : + Length of the array representing the base integer. + + modulus_length : + Length of the array representing the modulus integer. + + Returns + ------- + + complexity : `Uint` + Complexity of performing the operation. + " in + let max_length := + M.call (| + M.get_name (| globals, "max" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "base_length" |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "modulus_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + BinOp.add (| + M.get_name (| globals, "max_length" |), + Constant.int 7 + |), + Constant.int 8 + |) in + let _ := M.return_ (| + BinOp.pow (| + M.get_name (| globals, "words" |), + Constant.int 2 + |) + |) in + M.pure Constant.None_)). + +Definition iterations : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "exponent_length"; "exponent_head" ] |) in + let _ := Constant.str " + Calculate the number of iterations required to perform a modular + exponentiation. + + Parameters + ---------- + + exponent_length : + Length of the array representing the exponent integer. + + exponent_head : + First 32 bytes of the exponent (with leading zero padding if it is + shorter than 32 bytes), as an unsigned integer. + + Returns + ------- + + iterations : `Uint` + Number of iterations. + " in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.lt_e (| M.get_name (| globals, "exponent_length" |), Constant.int 32 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "exponent_head" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let count := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| M.get_name (| globals, "exponent_length" |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let bit_length := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "exponent_head" |), "bit_length" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "bit_length" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let bit_length := BinOp.sub + Constant.int 1 + Constant.int 1 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let count := + M.get_name (| globals, "bit_length" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let length_part := + BinOp.mult (| + Constant.int 8, + BinOp.sub (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "exponent_length" |) + ], + make_dict [] + |), + Constant.int 32 + |) + |) in + let bits_part := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "exponent_head" |), "bit_length" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "bits_part" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let bits_part := BinOp.sub + Constant.int 1 + Constant.int 1 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let count := + BinOp.add (| + M.get_name (| globals, "length_part" |), + M.get_name (| globals, "bits_part" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "max" |), + make_list [ + M.get_name (| globals, "count" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition gas_cost : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "base_length"; "modulus_length"; "exponent_length"; "exponent_head" ] |) in + let _ := Constant.str " + Calculate the gas cost of performing a modular exponentiation. + + Parameters + ---------- + + base_length : + Length of the array representing the base integer. + + modulus_length : + Length of the array representing the modulus integer. + + exponent_length : + Length of the array representing the exponent integer. + + exponent_head : + First 32 bytes of the exponent (with leading zero padding if it is + shorter than 32 bytes), as an unsigned integer. + + Returns + ------- + + gas_cost : `Uint` + Gas required for performing the operation. + " in + let multiplication_complexity := + M.call (| + M.get_name (| globals, "complexity" |), + make_list [ + M.get_name (| globals, "base_length" |); + M.get_name (| globals, "modulus_length" |) + ], + make_dict [] + |) in + let iteration_count := + M.call (| + M.get_name (| globals, "iterations" |), + make_list [ + M.get_name (| globals, "exponent_length" |); + M.get_name (| globals, "exponent_head" |) + ], + make_dict [] + |) in + let cost := + BinOp.mult (| + M.get_name (| globals, "multiplication_complexity" |), + M.get_name (| globals, "iteration_count" |) + |) in + let cost := BinOp.floor_div + M.get_name (| globals, "GQUADDIVISOR" |) + M.get_name (| globals, "GQUADDIVISOR" |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "max" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 200 + ], + make_dict [] + |); + M.get_name (| globals, "cost" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/ripemd160.v new file mode 100644 index 0000000..96f8dcd --- /dev/null +++ b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/ripemd160.v @@ -0,0 +1,122 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) RIPEMD160 PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `RIPEMD160` precompiled contract. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_left_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_RIPEMD160 : + IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160". +Axiom vm_gas_GAS_RIPEMD160_WORD : + IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160_WORD". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition ripemd160 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the ripemd160 hash to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let word_count := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_RIPEMD160" |), + BinOp.mult (| + M.get_name (| globals, "GAS_RIPEMD160_WORD" |), + M.get_name (| globals, "word_count" |) + |) + |) + ], + make_dict [] + |) in + let hash_bytes := + M.call (| + M.get_field (| M.call (| + M.get_field (| M.get_name (| globals, "hashlib" |), "new" |), + make_list [ + Constant.str "ripemd160"; + M.get_name (| globals, "data" |) + ], + make_dict [] + |), "digest" |), + make_list [], + make_dict [] + |) in + let padded_hash := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "hash_bytes" |); + Constant.int 32 + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.get_name (| globals, "padded_hash" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/sha256.v new file mode 100644 index 0000000..9f6d2bf --- /dev/null +++ b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/sha256.v @@ -0,0 +1,106 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) SHA256 PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `SHA256` precompiled contract. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_SHA256 : + IsGlobalAlias globals vm.gas.globals "GAS_SHA256". +Axiom vm_gas_GAS_SHA256_WORD : + IsGlobalAlias globals vm.gas.globals "GAS_SHA256_WORD". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition sha256 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the sha256 hash to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let word_count := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_SHA256" |), + BinOp.mult (| + M.get_name (| globals, "GAS_SHA256_WORD" |), + M.get_name (| globals, "word_count" |) + |) + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_field (| M.get_name (| globals, "hashlib" |), "sha256" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), "digest" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/vm/runtime.v b/CoqOfPython/ethereum/gray_glacier/vm/runtime.v new file mode 100644 index 0000000..835b46c --- /dev/null +++ b/CoqOfPython/ethereum/gray_glacier/vm/runtime.v @@ -0,0 +1,125 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Runtime Operations +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Runtime related operations used while executing EVM code. +". + +Require typing. +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require instructions. +Axiom instructions_Ops : + IsGlobalAlias globals instructions.globals "Ops". + +Definition get_valid_jump_destinations : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "code" ] |) in + let _ := Constant.str " + Analyze the evm code to obtain the set of valid jump destinations. + + Valid jump destinations are defined as follows: + * The jump destination is less than the length of the code. + * The jump destination should have the `JUMPDEST` opcode (0x5B). + * The jump destination shouldn't be part of the data corresponding to + `PUSH-N` opcodes. + + Note - Jump destinations are 0-indexed. + + Parameters + ---------- + code : + The EVM code which is to be executed. + + Returns + ------- + valid_jump_destinations: `Set[Uint]` + The set of valid jump destinations in the code. + " in + let valid_jump_destinations := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let pc := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + While Compare.lt (| M.get_name (| globals, "pc" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) |) do +(* At stmt: unsupported node type: Try *) + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "current_opcode" |), M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), + make_list [ + M.get_name (| globals, "pc" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + (* At expr: unsupported node type: Compare *), + (* then *) + ltac:(M.monadic ( + let push_data_size := + BinOp.add (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) + |), + Constant.int 1 + |) in + let pc := BinOp.add + M.get_name (| globals, "push_data_size" |) + M.get_name (| globals, "push_data_size" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let pc := BinOp.add + Constant.int 1 + Constant.int 1 in + EndWhile. + let _ := M.return_ (| + M.get_name (| globals, "valid_jump_destinations" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/vm/stack.v b/CoqOfPython/ethereum/gray_glacier/vm/stack.v new file mode 100644 index 0000000..42ea42d --- /dev/null +++ b/CoqOfPython/ethereum/gray_glacier/vm/stack.v @@ -0,0 +1,120 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Stack +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the stack operators for the EVM. +". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require exceptions. +Axiom exceptions_StackOverflowError : + IsGlobalAlias globals exceptions.globals "StackOverflowError". +Axiom exceptions_StackUnderflowError : + IsGlobalAlias globals exceptions.globals "StackUnderflowError". + +Definition pop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "stack" ] |) in + let _ := Constant.str " + Pops the top item off of `stack`. + + Parameters + ---------- + stack : + EVM stack. + + Returns + ------- + value : `U256` + The top element on the stack. + + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "StackUnderflowError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "pop" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition push : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "stack"; "value" ] |) in + let _ := Constant.str " + Pushes `value` onto `stack`. + + Parameters + ---------- + stack : + EVM stack. + + value : + Item to be pushed onto `stack`. + + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), Constant.int 1024 |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "StackOverflowError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "append" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/__init__.v b/CoqOfPython/ethereum/homestead/__init__.v new file mode 100644 index 0000000..b8c6ea5 --- /dev/null +++ b/CoqOfPython/ethereum/homestead/__init__.v @@ -0,0 +1,25 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +The Homestead fork increases the gas cost of creating contracts, restricts the +range of valid ECDSA signatures for transactions (but not precompiles), tweaks +the behavior of contract creation with insufficient gas, delays the +difficulty bomb, and adds an improved delegate call EVM instruction. +". + +Require ethereum.fork_criteria. +Axiom ethereum_fork_criteria_ByBlockNumber : + IsGlobalAlias globals ethereum.fork_criteria.globals "ByBlockNumber". + +Definition FORK_CRITERIA : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "ByBlockNumber" |), + make_list [ + Constant.int 1150000 + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/homestead/blocks.v b/CoqOfPython/ethereum/homestead/blocks.v new file mode 100644 index 0000000..6501788 --- /dev/null +++ b/CoqOfPython/ethereum/homestead/blocks.v @@ -0,0 +1,93 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +A `Block` is a single link in the chain that is Ethereum. Each `Block` contains +a `Header` and zero or more transactions. Each `Header` contains associated +metadata like the block number, parent block hash, and how much gas was +consumed by its transactions. + +Together, these blocks form a cryptographically secure journal recording the +history of all state transitions that have happened since the genesis of the +chain. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes8 : + IsGlobalAlias globals base_types.globals "Bytes8". +Axiom base_types_Bytes32 : + IsGlobalAlias globals base_types.globals "Bytes32". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require crypto.hash. +Axiom crypto_hash_Hash32 : + IsGlobalAlias globals crypto.hash.globals "Hash32". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Require transactions. +Axiom transactions_Transaction : + IsGlobalAlias globals transactions.globals "Transaction". + +Definition Header : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Block : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Log : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Receipt : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. diff --git a/CoqOfPython/ethereum/homestead/bloom.v b/CoqOfPython/ethereum/homestead/bloom.v new file mode 100644 index 0000000..04b5d9f --- /dev/null +++ b/CoqOfPython/ethereum/homestead/bloom.v @@ -0,0 +1,164 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Logs Bloom +^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +This modules defines functions for calculating bloom filters of logs. For the +general theory of bloom filters see e.g. `Wikipedia +`_. Bloom filters are used to allow +for efficient searching of logs by address and/or topic, by rapidly +eliminating blocks and receipts from their search. +". + +Require typing. +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require fork_types. +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". + +Definition add_to_bloom : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "bloom"; "bloom_entry" ] |) in + let _ := Constant.str " + Add a bloom entry to the bloom filter (`bloom`). + + The number of hash functions used is 3. They are calculated by taking the + least significant 11 bits from the first 3 16-bit words of the + `keccak_256()` hash of `bloom_entry`. + + Parameters + ---------- + bloom : + The bloom filter. + bloom_entry : + An entry which is to be added to bloom filter. + " in + let hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "bloom_entry" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "idx" |) in make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ] do + let bit_to_set := + BinOp.bit_and (| + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |):BinOp.add (| + M.get_name (| globals, "idx" |), + Constant.int 2 + |) |) + ], + make_dict [] + |), + Constant.int 2047 + |) in + let bit_index := + BinOp.sub (| + Constant.int 2047, + M.get_name (| globals, "bit_to_set" |) + |) in + let byte_index := + BinOp.floor_div (| + M.get_name (| globals, "bit_index" |), + Constant.int 8 + |) in + let bit_value := + BinOp.l_shift (| + Constant.int 1, + BinOp.sub (| + Constant.int 7, + BinOp.mod_ (| + M.get_name (| globals, "bit_index" |), + Constant.int 8 + |) + |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), + BinOp.bit_or (| + M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), + M.get_name (| globals, "bit_value" |) + |) + |) in + EndFor. + M.pure Constant.None_)). + +Definition logs_bloom : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "logs" ] |) in + let _ := Constant.str " + Obtain the logs bloom from a list of log entries. + + The address and each topic of a log are added to the bloom filter. + + Parameters + ---------- + logs : + List of logs for which the logs bloom is to be obtained. + + Returns + ------- + logs_bloom : `Bloom` + The logs bloom obtained which is 256 bytes with some bits set as per + the caller address and the log topics. + " in +(* At stmt: unsupported node type: AnnAssign *) + For M.get_name (| globals, "log" |) in M.get_name (| globals, "logs" |) do + let _ := M.call (| + M.get_name (| globals, "add_to_bloom" |), + make_list [ + M.get_name (| globals, "bloom" |); + M.get_field (| M.get_name (| globals, "log" |), "address" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "topic" |) in M.get_field (| M.get_name (| globals, "log" |), "topics" |) do + let _ := M.call (| + M.get_name (| globals, "add_to_bloom" |), + make_list [ + M.get_name (| globals, "bloom" |); + M.get_name (| globals, "topic" |) + ], + make_dict [] + |) in + EndFor. + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bloom" |), + make_list [ + M.get_name (| globals, "bloom" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/fork.v b/CoqOfPython/ethereum/homestead/fork.v new file mode 100644 index 0000000..951cae7 --- /dev/null +++ b/CoqOfPython/ethereum/homestead/fork.v @@ -0,0 +1,2104 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Specification +^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Entry point for the Ethereum specification. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". + +Require ethereum.crypto.elliptic_curve. +Axiom ethereum_crypto_elliptic_curve_SECP256K1N : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.ethash. +Axiom ethereum_ethash_dataset_size : + IsGlobalAlias globals ethereum.ethash.globals "dataset_size". +Axiom ethereum_ethash_generate_cache : + IsGlobalAlias globals ethereum.ethash.globals "generate_cache". +Axiom ethereum_ethash_hashimoto_light : + IsGlobalAlias globals ethereum.ethash.globals "hashimoto_light". + +Require ethereum.exceptions. +Axiom ethereum_exceptions_InvalidBlock : + IsGlobalAlias globals ethereum.exceptions.globals "InvalidBlock". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U64 : + IsGlobalAlias globals base_types.globals "U64". +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_U256_CEIL_VALUE : + IsGlobalAlias globals base_types.globals "U256_CEIL_VALUE". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes32 : + IsGlobalAlias globals base_types.globals "Bytes32". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". + +Require __init__. +Axiom __init___vm : + IsGlobalAlias globals __init__.globals "vm". + +Require blocks. +Axiom blocks_Block : + IsGlobalAlias globals blocks.globals "Block". +Axiom blocks_Header : + IsGlobalAlias globals blocks.globals "Header". +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". +Axiom blocks_Receipt : + IsGlobalAlias globals blocks.globals "Receipt". + +Require bloom. +Axiom bloom_logs_bloom : + IsGlobalAlias globals bloom.globals "logs_bloom". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Require state. +Axiom state_State : + IsGlobalAlias globals state.globals "State". +Axiom state_create_ether : + IsGlobalAlias globals state.globals "create_ether". +Axiom state_destroy_account : + IsGlobalAlias globals state.globals "destroy_account". +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". +Axiom state_increment_nonce : + IsGlobalAlias globals state.globals "increment_nonce". +Axiom state_set_account_balance : + IsGlobalAlias globals state.globals "set_account_balance". +Axiom state_state_root : + IsGlobalAlias globals state.globals "state_root". + +Require transactions. +Axiom transactions_TX_BASE_COST : + IsGlobalAlias globals transactions.globals "TX_BASE_COST". +Axiom transactions_TX_CREATE_COST : + IsGlobalAlias globals transactions.globals "TX_CREATE_COST". +Axiom transactions_TX_DATA_COST_PER_NON_ZERO : + IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_NON_ZERO". +Axiom transactions_TX_DATA_COST_PER_ZERO : + IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_ZERO". +Axiom transactions_Transaction : + IsGlobalAlias globals transactions.globals "Transaction". + +Require trie. +Axiom trie_Trie : + IsGlobalAlias globals trie.globals "Trie". +Axiom trie_root : + IsGlobalAlias globals trie.globals "root". +Axiom trie_trie_set : + IsGlobalAlias globals trie.globals "trie_set". + +Require utils.message. +Axiom utils_message_prepare_message : + IsGlobalAlias globals utils.message.globals "prepare_message". + +Require vm.interpreter. +Axiom vm_interpreter_process_message_call : + IsGlobalAlias globals vm.interpreter.globals "process_message_call". + +Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mult (| + Constant.int 5, + BinOp.pow (| + Constant.int 10, + Constant.int 18 + |) + |) + ], + make_dict [] + |) +)). + +Definition GAS_LIMIT_ADJUSTMENT_FACTOR : Value.t := M.run ltac:(M.monadic ( + Constant.int 1024 +)). + +Definition GAS_LIMIT_MINIMUM : Value.t := M.run ltac:(M.monadic ( + Constant.int 5000 +)). + +Definition MINIMUM_DIFFICULTY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 131072 + ], + make_dict [] + |) +)). + +Definition MAX_OMMER_DEPTH : Value.t := M.run ltac:(M.monadic ( + Constant.int 6 +)). + +Definition BlockChain : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition apply_fork : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "old" ] |) in + let _ := Constant.str " + Transforms the state from the previous hard fork (`old`) into the block + chain object for this hard fork and returns it. + + When forks need to implement an irregular state transition, this function + is used to handle the irregularity. See the :ref:`DAO Fork ` for + an example. + + Parameters + ---------- + old : + Previous block chain object. + + Returns + ------- + new : `BlockChain` + Upgraded block chain object for this hard fork. + " in + let _ := M.return_ (| + M.get_name (| globals, "old" |) + |) in + M.pure Constant.None_)). + +Definition get_last_256_block_hashes : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "chain" ] |) in + let _ := Constant.str " + Obtain the list of hashes of the previous 256 blocks in order of + increasing block number. + + This function will return less hashes for the first 256 blocks. + + The ``BLOCKHASH`` opcode needs to access the latest hashes on the chain, + therefore this function retrieves them. + + Parameters + ---------- + chain : + History and current state. + + Returns + ------- + recent_block_hashes : `List[Hash32]` + Hashes of the recent 256 blocks in order of increasing block number. + " in + let recent_blocks := + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |):(* At expr: unsupported node type: NoneType *) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "recent_blocks" |) + ], + make_dict [] + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + make_list [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let recent_block_hashes := + make_list [] in + For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_blocks" |) do + let prev_block_hash := + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), + make_list [ + M.get_name (| globals, "prev_block_hash" |) + ], + make_dict [] + |) in + EndFor. + let most_recent_block_hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_field (| M.get_subscript (| M.get_name (| globals, "recent_blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), + make_list [ + M.get_name (| globals, "most_recent_block_hash" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "recent_block_hashes" |) + |) in + M.pure Constant.None_)). + +Definition state_transition : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "chain"; "block" ] |) in + let _ := Constant.str " + Attempts to apply a block to an existing block chain. + + All parts of the block's contents need to be verified before being added + to the chain. Blocks are verified by ensuring that the contents of the + block make logical sense with the contents of the parent block. The + information in the block's header must also match the corresponding + information in the block. + + To implement Ethereum, in theory clients are only required to store the + most recent 255 blocks of the chain since as far as execution is + concerned, only those blocks are accessed. Practically, however, clients + should store more blocks to handle reorgs. + + Parameters + ---------- + chain : + History and current state. + block : + Block to apply to `chain`. + " in + let parent_header := + M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) in + let _ := M.call (| + M.get_name (| globals, "validate_header" |), + make_list [ + M.get_field (| M.get_name (| globals, "block" |), "header" |); + M.get_name (| globals, "parent_header" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "validate_ommers" |), + make_list [ + M.get_field (| M.get_name (| globals, "block" |), "ommers" |); + M.get_field (| M.get_name (| globals, "block" |), "header" |); + M.get_name (| globals, "chain" |) + ], + make_dict [] + |) in + let apply_body_output := + M.call (| + M.get_name (| globals, "apply_body" |), + make_list [ + M.get_field (| M.get_name (| globals, "chain" |), "state" |); + M.call (| + M.get_name (| globals, "get_last_256_block_hashes" |), + make_list [ + M.get_name (| globals, "chain" |) + ], + make_dict [] + |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "coinbase" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "number" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "gas_limit" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "timestamp" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "difficulty" |); + M.get_field (| M.get_name (| globals, "block" |), "transactions" |); + M.get_field (| M.get_name (| globals, "block" |), "ommers" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_gas_used" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "gas_used" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "transactions_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "transactions_root" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "state_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "state_root" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "receipt_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "receipt_root" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_logs_bloom" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "bloom" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), "append" |), + make_list [ + M.get_name (| globals, "block" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |) + ], + make_dict [] + |), Constant.int 255 |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |):(* At expr: unsupported node type: NoneType *) |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition validate_header : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header"; "parent_header" ] |) in + let _ := Constant.str " + Verifies a block header. + + In order to consider a block's header valid, the logic for the + quantities in the header should match the logic for the block itself. + For example the header timestamp should be greater than the block's parent + timestamp because the block was created *after* the parent block. + Additionally, the block's number should be directly following the parent + block's number since it is the next block in the sequence. + + Parameters + ---------- + header : + Header to check for correctness. + parent_header : + Parent Header of the header to check for correctness + " in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt (| M.get_field (| M.get_name (| globals, "header" |), "timestamp" |), M.get_field (| M.get_name (| globals, "parent_header" |), "timestamp" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "number" |), BinOp.add (| + M.get_field (| M.get_name (| globals, "parent_header" |), "number" |), + Constant.int 1 + |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + M.call (| + M.get_name (| globals, "check_gas_limit" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "gas_limit" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "gas_limit" |) + ], + make_dict [] + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) + ], + make_dict [] + |), Constant.int 32 |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let block_difficulty := + M.call (| + M.get_name (| globals, "calculate_block_difficulty" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "number" |); + M.get_field (| M.get_name (| globals, "header" |), "timestamp" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "timestamp" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "difficulty" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "difficulty" |), M.get_name (| globals, "block_difficulty" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let block_parent_hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "parent_header" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |), M.get_name (| globals, "block_parent_hash" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "validate_proof_of_work" |), + make_list [ + M.get_name (| globals, "header" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header" ] |) in + let _ := Constant.str " + Generate rlp hash of the header which is to be used for Proof-of-Work + verification. + + In other words, the PoW artefacts `mix_digest` and `nonce` are ignored + while calculating this hash. + + A particular PoW is valid for a single hash, that hash is computed by + this function. The `nonce` and `mix_digest` are omitted from this hash + because they are being changed by miners in their search for a sufficient + proof-of-work. + + Parameters + ---------- + header : + The header object for which the hash is to be generated. + + Returns + ------- + hash : `Hash32` + The PoW valid rlp hash of the passed in header. + " in + let header_data_without_pow_artefacts := + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |); + M.get_field (| M.get_name (| globals, "header" |), "ommers_hash" |); + M.get_field (| M.get_name (| globals, "header" |), "coinbase" |); + M.get_field (| M.get_name (| globals, "header" |), "state_root" |); + M.get_field (| M.get_name (| globals, "header" |), "transactions_root" |); + M.get_field (| M.get_name (| globals, "header" |), "receipt_root" |); + M.get_field (| M.get_name (| globals, "header" |), "bloom" |); + M.get_field (| M.get_name (| globals, "header" |), "difficulty" |); + M.get_field (| M.get_name (| globals, "header" |), "number" |); + M.get_field (| M.get_name (| globals, "header" |), "gas_limit" |); + M.get_field (| M.get_name (| globals, "header" |), "gas_used" |); + M.get_field (| M.get_name (| globals, "header" |), "timestamp" |); + M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) + ] in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "header_data_without_pow_artefacts" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition validate_proof_of_work : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header" ] |) in + let _ := Constant.str " + Validates the Proof of Work constraints. + + In order to verify that a miner's proof-of-work is valid for a block, a + ``mix-digest`` and ``result`` are calculated using the ``hashimoto_light`` + hash function. The mix digest is a hash of the header and the nonce that + is passed through and it confirms whether or not proof-of-work was done + on the correct block. The result is the actual hash value of the block. + + Parameters + ---------- + header : + Header of interest. + " in + let header_hash := + M.call (| + M.get_name (| globals, "generate_header_hash_for_pow" |), + make_list [ + M.get_name (| globals, "header" |) + ], + make_dict [] + |) in + let cache := + M.call (| + M.get_name (| globals, "generate_cache" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "number" |) + ], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "mix_digest" |); M.get_name (| globals, "result" |) ], + M.call (| + M.get_name (| globals, "hashimoto_light" |), + make_list [ + M.get_name (| globals, "header_hash" |); + M.get_field (| M.get_name (| globals, "header" |), "nonce" |); + M.get_name (| globals, "cache" |); + M.call (| + M.get_name (| globals, "dataset_size" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "number" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_name (| globals, "mix_digest" |), M.get_field (| M.get_name (| globals, "header" |), "mix_digest" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "result" |) + ], + make_dict [] + |), BinOp.floor_div (| + M.get_name (| globals, "U256_CEIL_VALUE" |), + M.get_field (| M.get_name (| globals, "header" |), "difficulty" |) + |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition check_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx"; "gas_available" ] |) in + let _ := Constant.str " + Check if the transaction is includable in the block. + + Parameters + ---------- + tx : + The transaction. + gas_available : + The gas remaining in the block. + + Returns + ------- + sender_address : + The sender of the transaction. + + Raises + ------ + InvalidBlock : + If the transaction is not includable. + " in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_name (| globals, "gas_available" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let sender_address := + M.call (| + M.get_name (| globals, "recover_sender" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "sender_address" |) + |) in + M.pure Constant.None_)). + +Definition make_receipt : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx"; "post_state"; "cumulative_gas_used"; "logs" ] |) in + let _ := Constant.str " + Make the receipt for a transaction that was executed. + + Parameters + ---------- + tx : + The executed transaction. + post_state : + The state root immediately after this transaction. + cumulative_gas_used : + The total gas used so far in the block after the transaction was + executed. + logs : + The logs produced by the transaction. + + Returns + ------- + receipt : + The receipt for the transaction. + " in + let receipt := + M.call (| + M.get_name (| globals, "Receipt" |), + make_list [], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "receipt" |) + |) in + M.pure Constant.None_)). + +Definition ApplyBodyOutput : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition apply_body : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "block_hashes"; "coinbase"; "block_number"; "block_gas_limit"; "block_time"; "block_difficulty"; "transactions"; "ommers" ] |) in + let _ := Constant.str " + Executes a block. + + Many of the contents of a block are stored in data structures called + tries. There is a transactions trie which is similar to a ledger of the + transactions stored in the current block. There is also a receipts trie + which stores the results of executing a transaction, like the post state + and gas used. This function creates and executes the block that is to be + added to the chain. + + Parameters + ---------- + state : + Current account state. + block_hashes : + List of hashes of the previous 256 blocks in the order of + increasing block number. + coinbase : + Address of account which receives block reward and transaction fees. + block_number : + Position of the block within the chain. + block_gas_limit : + Initial amount of gas available for execution in this block. + block_time : + Time the block was produced, measured in seconds since the epoch. + block_difficulty : + Difficulty of the block. + transactions : + Transactions included in the block. + ommers : + Headers of ancestor blocks which are not direct parents (formerly + uncles.) + + Returns + ------- + apply_body_output : `ApplyBodyOutput` + Output of applying the block body to the state. + " in + let gas_available := + M.get_name (| globals, "block_gas_limit" |) in +(* At stmt: unsupported node type: AnnAssign *) +(* At stmt: unsupported node type: AnnAssign *) +(* At stmt: unsupported node type: AnnAssign *) + For make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "tx" |) ] in M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "transactions" |) + ], + make_dict [] + |) do + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "transactions_trie" |); + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "i" |) + ], + make_dict [] + |) + ], + make_dict [] + |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) in + let sender_address := + M.call (| + M.get_name (| globals, "check_transaction" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "gas_available" |) + ], + make_dict [] + |) in + let env := + M.call (| + M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |) ], + M.call (| + M.get_name (| globals, "process_transaction" |), + make_list [ + M.get_name (| globals, "env" |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) in + let gas_available := BinOp.sub + M.get_name (| globals, "gas_used" |) + M.get_name (| globals, "gas_used" |) in + let receipt := + M.call (| + M.get_name (| globals, "make_receipt" |), + make_list [ + M.get_name (| globals, "tx" |); + M.call (| + M.get_name (| globals, "state_root" |), + make_list [ + M.get_name (| globals, "state" |) + ], + make_dict [] + |); + BinOp.sub (| + M.get_name (| globals, "block_gas_limit" |), + M.get_name (| globals, "gas_available" |) + |); + M.get_name (| globals, "logs" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "receipts_trie" |); + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "i" |) + ], + make_dict [] + |) + ], + make_dict [] + |); + M.get_name (| globals, "receipt" |) + ], + make_dict [] + |) in + let block_logs := BinOp.add + M.get_name (| globals, "logs" |) + M.get_name (| globals, "logs" |) in + EndFor. + let _ := M.call (| + M.get_name (| globals, "pay_rewards" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "block_number" |); + M.get_name (| globals, "coinbase" |); + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |) in + let block_gas_used := + BinOp.sub (| + M.get_name (| globals, "block_gas_limit" |), + M.get_name (| globals, "gas_available" |) + |) in + let block_logs_bloom := + M.call (| + M.get_name (| globals, "logs_bloom" |), + make_list [ + M.get_name (| globals, "block_logs" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ApplyBodyOutput" |), + make_list [ + M.get_name (| globals, "block_gas_used" |); + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_name (| globals, "transactions_trie" |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_name (| globals, "receipts_trie" |) + ], + make_dict [] + |); + M.get_name (| globals, "block_logs_bloom" |); + M.call (| + M.get_name (| globals, "state_root" |), + make_list [ + M.get_name (| globals, "state" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition validate_ommers : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "ommers"; "block_header"; "chain" ] |) in + let _ := Constant.str " + Validates the ommers mentioned in the block. + + An ommer block is a block that wasn't canonically added to the + blockchain because it wasn't validated as fast as the canonical block + but was mined at the same time. + + To be considered valid, the ommers must adhere to the rules defined in + the Ethereum protocol. The maximum amount of ommers is 2 per block and + there cannot be duplicate ommers in a block. Many of the other ommer + constraints are listed in the in-line comments of this function. + + Parameters + ---------- + ommers : + List of ommers mentioned in the current block. + block_header: + The header of current block. + chain : + History and current state. + " in + let block_hash := + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "block_header" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), M.get_field (| M.get_name (| globals, "block_header" |), "ommers_hash" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + (* At expr: unsupported node type: Compare *); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let ommer_parent_header := + M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), BinOp.sub (| + UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) |), + Constant.int 1 + |) |), "header" |) in + let _ := M.call (| + M.get_name (| globals, "validate_header" |), + make_list [ + M.get_name (| globals, "ommer" |); + M.get_name (| globals, "ommer_parent_header" |) + ], + make_dict [] + |) in + EndFor. + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), Constant.int 2 |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let ommers_hashes := + [M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "ommer" |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)] in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers_hashes" |) + ], + make_dict [] + |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_name (| globals, "set" |), + make_list [ + M.get_name (| globals, "ommers_hashes" |) + ], + make_dict [] + |) + ], + make_dict [] + |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let recent_canonical_blocks := + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| BinOp.add (| + M.get_name (| globals, "MAX_OMMER_DEPTH" |), + Constant.int 1 + |) |):(* At expr: unsupported node type: NoneType *) |) in + let recent_canonical_block_hashes := + {M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_field (| M.get_name (| globals, "block" |), "header" |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)} in +(* At stmt: unsupported node type: AnnAssign *) + For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_canonical_blocks" |) do + let recent_ommers_hashes := + M.call (| + M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), + make_list [ + {M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "ommer" |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)} + ], + make_dict [] + |) in + EndFor. + For make_tuple [ M.get_name (| globals, "ommer_index" |); M.get_name (| globals, "ommer" |) ] in M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |) do + let ommer_hash := + M.get_subscript (| M.get_name (| globals, "ommers_hashes" |), M.get_name (| globals, "ommer_index" |) |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_eq (| M.get_name (| globals, "ommer_hash" |), M.get_name (| globals, "block_hash" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_in (| M.get_name (| globals, "ommer_hash" |), M.get_name (| globals, "recent_canonical_block_hashes" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_in (| M.get_name (| globals, "ommer_hash" |), M.get_name (| globals, "recent_ommers_hashes" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let ommer_age := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + (* At expr: unsupported node type: Compare *); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.in (| M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), M.get_name (| globals, "recent_canonical_block_hashes" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_eq (| M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), M.get_field (| M.get_name (| globals, "block_header" |), "parent_hash" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_)). + +Definition pay_rewards : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "block_number"; "coinbase"; "ommers" ] |) in + let _ := Constant.str " + Pay rewards to the block miner as well as the ommers miners. + + The miner of the canonical block is rewarded with the predetermined + block reward, ``BLOCK_REWARD``, plus a variable award based off of the + number of ommer blocks that were mined around the same time, and included + in the canonical block's header. An ommer block is a block that wasn't + added to the canonical blockchain because it wasn't validated as fast as + the accepted block but was mined at the same time. Although not all blocks + that are mined are added to the canonical chain, miners are still paid a + reward for their efforts. This reward is called an ommer reward and is + calculated based on the number associated with the ommer block that they + mined. + + Parameters + ---------- + state : + Current account state. + block_number : + Position of the block within the chain. + coinbase : + Address of account which receives block reward and transaction fees. + ommers : + List of ommers mentioned in the current block. + " in + let miner_reward := + BinOp.add (| + M.get_name (| globals, "BLOCK_REWARD" |), + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + BinOp.floor_div (| + M.get_name (| globals, "BLOCK_REWARD" |), + Constant.int 32 + |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "create_ether" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "coinbase" |); + M.get_name (| globals, "miner_reward" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do + let ommer_age := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "block_number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) + ], + make_dict [] + |) in + let ommer_miner_reward := + BinOp.floor_div (| + BinOp.mult (| + BinOp.sub (| + Constant.int 8, + M.get_name (| globals, "ommer_age" |) + |), + M.get_name (| globals, "BLOCK_REWARD" |) + |), + Constant.int 8 + |) in + let _ := M.call (| + M.get_name (| globals, "create_ether" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_field (| M.get_name (| globals, "ommer" |), "coinbase" |); + M.get_name (| globals, "ommer_miner_reward" |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_)). + +Definition process_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "env"; "tx" ] |) in + let _ := Constant.str " + Execute a transaction against the provided environment. + + This function processes the actions needed to execute a transaction. + It decrements the sender's account after calculating the gas fee and + refunds them the proper amount after execution. Calling contracts, + deploying code, and incrementing nonces are all examples of actions that + happen within this function or from a call made within this function. + + Accounts that are marked for deletion are processed and destroyed after + execution. + + Parameters + ---------- + env : + Environment for the Ethereum Virtual Machine. + tx : + Transaction to execute. + + Returns + ------- + gas_left : `ethereum.base_types.U256` + Remaining gas after execution. + logs : `Tuple[ethereum.blocks.Log, ...]` + Logs generated during execution. + " in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + M.call (| + M.get_name (| globals, "validate_transaction" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let sender := + M.get_field (| M.get_name (| globals, "env" |), "origin" |) in + let sender_account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |) in + let gas_fee := + BinOp.mult (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "sender_account" |), "nonce" |), M.get_field (| M.get_name (| globals, "tx" |), "nonce" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt_e (| M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), BinOp.add (| + M.get_name (| globals, "gas_fee" |), + M.get_field (| M.get_name (| globals, "tx" |), "value" |) + |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "sender_account" |), "code" |), M.call (| + M.get_name (| globals, "bytearray" |), + make_list [], + make_dict [] + |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let gas := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.call (| + M.get_name (| globals, "calculate_intrinsic_cost" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) in + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |) in + let sender_balance_after_gas_fee := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), + M.get_name (| globals, "gas_fee" |) + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |); + M.get_name (| globals, "sender_balance_after_gas_fee" |) + ], + make_dict [] + |) in + let message := + M.call (| + M.get_name (| globals, "prepare_message" |), + make_list [ + M.get_name (| globals, "sender" |); + M.get_field (| M.get_name (| globals, "tx" |), "to" |); + M.get_field (| M.get_name (| globals, "tx" |), "value" |); + M.get_field (| M.get_name (| globals, "tx" |), "data" |); + M.get_name (| globals, "gas" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let output := + M.call (| + M.get_name (| globals, "process_message_call" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let gas_used := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "output" |), "gas_left" |) + |) in + let gas_refund := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + BinOp.floor_div (| + M.get_name (| globals, "gas_used" |), + Constant.int 2 + |); + M.get_field (| M.get_name (| globals, "output" |), "refund_counter" |) + ], + make_dict [] + |) in + let gas_refund_amount := + BinOp.mult (| + BinOp.add (| + M.get_field (| M.get_name (| globals, "output" |), "gas_left" |), + M.get_name (| globals, "gas_refund" |) + |), + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) + |) in + let transaction_fee := + BinOp.mult (| + BinOp.sub (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "output" |), "gas_left" |) + |), + M.get_name (| globals, "gas_refund" |) + |), + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) + |) in + let total_gas_used := + BinOp.sub (| + M.get_name (| globals, "gas_used" |), + M.get_name (| globals, "gas_refund" |) + |) in + let sender_balance_after_refund := + BinOp.add (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |), "balance" |), + M.get_name (| globals, "gas_refund_amount" |) + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |); + M.get_name (| globals, "sender_balance_after_refund" |) + ], + make_dict [] + |) in + let coinbase_balance_after_mining_fee := + BinOp.add (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |), "balance" |), + M.get_name (| globals, "transaction_fee" |) + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |); + M.get_name (| globals, "coinbase_balance_after_mining_fee" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "accounts_to_delete" |) do + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + EndFor. + let _ := M.return_ (| + make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |) ] + |) in + M.pure Constant.None_)). + +Definition validate_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Verifies a transaction. + + The gas in a transaction gets used to pay for the intrinsic cost of + operations, therefore if there is insufficient gas then it would not + be possible to execute a transaction and it will be declared invalid. + + Additionally, the nonce of a transaction must not equal or exceed the + limit defined in `EIP-2681 `_. + In practice, defining the limit as ``2**64-1`` has no impact because + sending ``2**64-1`` transactions is improbable. It's not strictly + impossible though, ``2**64-1`` transactions is the entire capacity of the + Ethereum blockchain at 2022 gas limits for a little over 22 years. + + Parameters + ---------- + tx : + Transaction to validate. + + Returns + ------- + verified : `bool` + True if the transaction can be executed, or False otherwise. + " in + let _ := M.return_ (| + BoolOp.and (| + Compare.lt_e (| M.call (| + M.get_name (| globals, "calculate_intrinsic_cost" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |), M.get_field (| M.get_name (| globals, "tx" |), "gas" |) |), + ltac:(M.monadic ( + Compare.lt (| M.get_field (| M.get_name (| globals, "tx" |), "nonce" |), BinOp.sub (| + BinOp.pow (| + Constant.int 2, + Constant.int 64 + |), + Constant.int 1 + |) |) + )) + |) + |) in + M.pure Constant.None_)). + +Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Calculates the gas that is charged before execution is started. + + The intrinsic cost of the transaction is charged before execution has + begun. Functions/operations in the EVM cost money to execute so this + intrinsic cost is for the operations that need to be paid for as part of + the transaction. Data transfer, for example, is part of this intrinsic + cost. It costs ether to send data over the wire and that ether is + accounted for in the intrinsic cost calculated in this function. This + intrinsic cost must be calculated and paid for before execution in order + for all operations to be implemented. + + Parameters + ---------- + tx : + Transaction to compute the intrinsic cost of. + + Returns + ------- + verified : `ethereum.base_types.Uint` + The intrinsic cost of the transaction. + " in + let data_cost := + Constant.int 0 in + For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "byte" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + M.pure Constant.None_ + )) |) in + EndFor. + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_name (| globals, "tx" |), "to" |), M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let create_cost := + M.get_name (| globals, "TX_CREATE_COST" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let create_cost := + Constant.int 0 in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "TX_BASE_COST" |), + M.get_name (| globals, "data_cost" |) + |), + M.get_name (| globals, "create_cost" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition recover_sender : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Extracts the sender address from a transaction. + + The v, r, and s values are the three parts that make up the signature + of a transaction. In order to recover the sender of a transaction the two + components needed are the signature (``v``, ``r``, and ``s``) and the + signing hash of the transaction. The sender's public key can be obtained + with these two values and therefore the sender address can be retrieved. + + Parameters + ---------- + tx : + Transaction of interest. + + Returns + ------- + sender : `ethereum.fork_types.Address` + The address of the account that signed the transaction. + " in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "v" |); M.get_name (| globals, "r" |); M.get_name (| globals, "s" |) ], + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "v" |); M.get_field (| M.get_name (| globals, "tx" |), "r" |); M.get_field (| M.get_name (| globals, "tx" |), "s" |) ] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.or (| + Compare.eq (| M.get_name (| globals, "v" |), Constant.int 27 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "v" |), Constant.int 28 |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.and (| + Compare.lt (| Constant.int 0, M.get_name (| globals, "r" |) |), + ltac:(M.monadic ( + Compare.lt (| M.get_name (| globals, "r" |), M.get_name (| globals, "SECP256K1N" |) |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.and (| + Compare.lt (| Constant.int 0, M.get_name (| globals, "s" |) |), + ltac:(M.monadic ( + Compare.lt_e (| M.get_name (| globals, "s" |), BinOp.floor_div (| + M.get_name (| globals, "SECP256K1N" |), + Constant.int 2 + |) |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + BinOp.sub (| + M.get_name (| globals, "v" |), + Constant.int 27 + |); + M.call (| + M.get_name (| globals, "signing_hash" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_subscript (| M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), Constant.int 12:Constant.int 32 |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition signing_hash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Compute the hash of a transaction used in the signature. + + The values that are used to compute the signing hash set the rules for a + transaction. For example, signing over the gas sets a limit for the + amount of money that is allowed to be pulled out of the sender's account. + + Parameters + ---------- + tx : + Transaction of interest. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the transaction. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "nonce" |); M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |); M.get_field (| M.get_name (| globals, "tx" |), "gas" |); M.get_field (| M.get_name (| globals, "tx" |), "to" |); M.get_field (| M.get_name (| globals, "tx" |), "value" |); M.get_field (| M.get_name (| globals, "tx" |), "data" |) ] + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition compute_header_hash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header" ] |) in + let _ := Constant.str " + Computes the hash of a block header. + + The header hash of a block is the canonical hash that is used to refer + to a specific block and completely distinguishes a block from another. + + ``keccak256`` is a function that produces a 256 bit hash of any input. + It also takes in any number of bytes as an input and produces a single + hash for them. A hash is a completely unique output for a single input. + So an input corresponds to one unique hash that can be used to identify + the input exactly. + + Prior to using the ``keccak256`` hash function, the header must be + encoded using the Recursive-Length Prefix. See :ref:`rlp`. + RLP encoding the header converts it into a space-efficient format that + allows for easy transfer of data between nodes. The purpose of RLP is to + encode arbitrarily nested arrays of binary data, and RLP is the primary + encoding method used to serialize objects in Ethereum's execution layer. + The only purpose of RLP is to encode structure; encoding specific data + types (e.g. strings, floats) is left up to higher-order protocols. + + Parameters + ---------- + header : + Header of interest. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the header. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "header" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition check_gas_limit : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "gas_limit"; "parent_gas_limit" ] |) in + let _ := Constant.str " + Validates the gas limit for a block. + + The bounds of the gas limit, ``max_adjustment_delta``, is set as the + quotient of the parent block's gas limit and the + ``GAS_LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is + passed through as a parameter is greater than or equal to the *sum* of + the parent's gas and the adjustment delta then the limit for gas is too + high and fails this function's check. Similarly, if the limit is less + than or equal to the *difference* of the parent's gas and the adjustment + delta *or* the predefined ``GAS_LIMIT_MINIMUM`` then this function's + check fails because the gas limit doesn't allow for a sufficient or + reasonable amount of gas to be used on a block. + + Parameters + ---------- + gas_limit : + Gas limit to validate. + + parent_gas_limit : + Gas limit of the parent block. + + Returns + ------- + check : `bool` + True if gas limit constraints are satisfied, False otherwise. + " in + let max_adjustment_delta := + BinOp.floor_div (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "gas_limit" |), BinOp.add (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| M.get_name (| globals, "gas_limit" |), BinOp.sub (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "gas_limit" |), M.get_name (| globals, "GAS_LIMIT_MINIMUM" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + Constant.bool true + |) in + M.pure Constant.None_)). + +Definition calculate_block_difficulty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "block_number"; "block_timestamp"; "parent_timestamp"; "parent_difficulty" ] |) in + let _ := Constant.str " + Computes difficulty of a block using its header and parent header. + + The difficulty is determined by the time the block was created after its + parent. The ``offset`` is calculated using the parent block's difficulty, + ``parent_difficulty``, and the timestamp between blocks. This offset is + then added to the parent difficulty and is stored as the ``difficulty`` + variable. If the time between the block and its parent is too short, the + offset will result in a positive number thus making the sum of + ``parent_difficulty`` and ``offset`` to be a greater value in order to + avoid mass forking. But, if the time is long enough, then the offset + results in a negative value making the block less difficult than + its parent. + + The base standard for a block's difficulty is the predefined value + set for the genesis block since it has no parent. So, a block + can't be less difficult than the genesis block, therefore each block's + difficulty is set to the maximum value between the calculated + difficulty and the ``GENESIS_DIFFICULTY``. + + Parameters + ---------- + block_number : + Block number of the block. + block_timestamp : + Timestamp of the block. + parent_timestamp : + Timestamp of the parent block. + parent_difficulty : + difficulty of the parent block. + + Returns + ------- + difficulty : `ethereum.base_types.Uint` + Computed difficulty for a block. + " in + let offset := + BinOp.mult (| + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "parent_difficulty" |) + ], + make_dict [] + |), + Constant.int 2048 + |), + M.call (| + M.get_name (| globals, "max" |), + make_list [ + BinOp.sub (| + Constant.int 1, + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "block_timestamp" |), + M.get_name (| globals, "parent_timestamp" |) + |) + ], + make_dict [] + |), + Constant.int 10 + |) + |); + UnOp.sub (| Constant.int 99 |) + ], + make_dict [] + |) + |) in + let difficulty := + BinOp.add (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "parent_difficulty" |) + ], + make_dict [] + |), + M.get_name (| globals, "offset" |) + |) in + let num_bomb_periods := + BinOp.sub (| + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "block_number" |) + ], + make_dict [] + |), + Constant.int 100000 + |), + Constant.int 2 + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "num_bomb_periods" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let difficulty := BinOp.add + BinOp.pow (| + Constant.int 2, + M.get_name (| globals, "num_bomb_periods" |) + |) + BinOp.pow (| + Constant.int 2, + M.get_name (| globals, "num_bomb_periods" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "max" |), + make_list [ + M.get_name (| globals, "difficulty" |); + M.get_name (| globals, "MINIMUM_DIFFICULTY" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/fork_types.v b/CoqOfPython/ethereum/homestead/fork_types.v new file mode 100644 index 0000000..d12953d --- /dev/null +++ b/CoqOfPython/ethereum/homestead/fork_types.v @@ -0,0 +1,102 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Types +^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Types re-used throughout the specification, which are specific to Ethereum. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes20 : + IsGlobalAlias globals base_types.globals "Bytes20". +Axiom base_types_Bytes256 : + IsGlobalAlias globals base_types.globals "Bytes256". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require crypto.hash. +Axiom crypto_hash_Hash32 : + IsGlobalAlias globals crypto.hash.globals "Hash32". +Axiom crypto_hash_keccak256 : + IsGlobalAlias globals crypto.hash.globals "keccak256". + +Definition Address : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Bytes20" |) +)). + +Definition Root : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Hash32" |) +)). + +Definition Bloom : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Bytes256" |) +)). + +Definition Account : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition EMPTY_ACCOUNT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Account" |), + make_list [], + make_dict [] + |) +)). + +Definition encode_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "raw_account_data"; "storage_root" ] |) in + let _ := Constant.str " + Encode `Account` dataclass. + + Storage is not stored in the `Account` dataclass, so `Accounts` cannot be + encoded with providing a storage root. + " in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "raw_account_data" |), "nonce" |); M.get_field (| M.get_name (| globals, "raw_account_data" |), "balance" |); M.get_name (| globals, "storage_root" |); M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_field (| M.get_name (| globals, "raw_account_data" |), "code" |) + ], + make_dict [] + |) ] + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/state.v b/CoqOfPython/ethereum/homestead/state.v new file mode 100644 index 0000000..38fe9d1 --- /dev/null +++ b/CoqOfPython/ethereum/homestead/state.v @@ -0,0 +1,865 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +State +^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The state contains all information that is preserved between transactions. + +It consists of a main account trie and storage tries for each contract. + +There is a distinction between an account that does not exist and +`EMPTY_ACCOUNT`. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_field : + IsGlobalAlias globals dataclasses.globals "field". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_modify : + IsGlobalAlias globals ethereum.base_types.globals "modify". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require fork_types. +Axiom fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". +Axiom fork_types_Account : + IsGlobalAlias globals fork_types.globals "Account". +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Require trie. +Axiom trie_EMPTY_TRIE_ROOT : + IsGlobalAlias globals trie.globals "EMPTY_TRIE_ROOT". +Axiom trie_Trie : + IsGlobalAlias globals trie.globals "Trie". +Axiom trie_copy_trie : + IsGlobalAlias globals trie.globals "copy_trie". +Axiom trie_root : + IsGlobalAlias globals trie.globals "root". +Axiom trie_trie_get : + IsGlobalAlias globals trie.globals "trie_get". +Axiom trie_trie_set : + IsGlobalAlias globals trie.globals "trie_set". + +Definition State : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition close_state : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Free resources held by the state. Used by optimized implementations to + release file descriptors. + " in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) |) in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |) in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) in + M.pure Constant.None_)). + +Definition begin_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Start a state transaction. + + Transactions are entirely implicit and can be nested. It is not possible to + calculate the state root during a transaction. + + Parameters + ---------- + state : State + The state. + " in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), "append" |), + make_list [ + make_tuple [ M.call (| + M.get_name (| globals, "copy_trie" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) + ], + make_dict [] + |); {M.get_name (| globals, "k" |): M.call (| + M.get_name (| globals, "copy_trie" |), + make_list [ + M.get_name (| globals, "t" |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)} ] + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition commit_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Commit a state transaction. + + Parameters + ---------- + state : State + The state. + " in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), "pop" |), + make_list [], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition rollback_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Rollback a state transaction, resetting the state to the point when the + corresponding `start_transaction()` call was made. + + Parameters + ---------- + state : State + The state. + " in + let _ := M.assign (| + make_tuple [ M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) ], + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), "pop" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition get_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Get the `Account` object at an address. Returns `EMPTY_ACCOUNT` if there + is no account at the address. + + Use `get_account_optional()` if you care about the difference between a + non-existent account and `EMPTY_ACCOUNT`. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address to lookup. + + Returns + ------- + account : `Account` + Account at address. + " in + let account := + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "account" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "account" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "EMPTY_ACCOUNT" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition get_account_optional : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Get the `Account` object at an address. Returns `None` (rather than + `EMPTY_ACCOUNT`) if there is no account at the address. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address to lookup. + + Returns + ------- + account : `Account` + Account at address. + " in + let account := + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "account" |) + |) in + M.pure Constant.None_)). + +Definition set_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "account" ] |) in + let _ := Constant.str " + Set the `Account` object at an address. Setting to `None` deletes + the account (but not its storage, see `destroy_account()`). + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address to set. + account : `Account` + Account to set at address. + " in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "account" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition destroy_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Completely remove the account at `address` and all of its storage. + + This function is made available exclusively for the `SELFDESTRUCT` + opcode. It is expected that `SELFDESTRUCT` will be disabled in a future + hardfork and this function will be removed. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of account to destroy. + " in + let _ := M.call (| + M.get_name (| globals, "destroy_storage" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + Constant.None_ + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition destroy_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Completely remove the storage at `address`. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of account whose storage is to be deleted. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition get_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "key" ] |) in + let _ := Constant.str " + Get a value at a storage key on an account. Returns `U256(0)` if the + storage key has not been set previously. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of the account. + key : `Bytes` + Key to lookup. + + Returns + ------- + value : `U256` + Value at the key. + " in + let trie := + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let _ := M.assert (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "U256" |) + ], + make_dict [] + |) |) in + let _ := M.return_ (| + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_)). + +Definition set_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "key"; "value" ] |) in + let _ := Constant.str " + Set a value at a storage key on an account. Setting to `U256(0)` deletes + the key. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of the account. + key : `Bytes` + Key to set. + value : `U256` + Value to set at the key. + " in + let _ := M.assert (| Compare.is_not (| M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), Constant.None_ |) |) in + let trie := + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let trie := + M.call (| + M.get_name (| globals, "Trie" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), + M.get_name (| globals, "trie" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "key" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), {} |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition storage_root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Calculate the storage root of an account. + + Parameters + ---------- + state: + The state + address : + Address of the account. + + Returns + ------- + root : `Root` + Storage root of the account. + " in + let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "EMPTY_TRIE_ROOT" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition state_root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Calculate the state root. + + Parameters + ---------- + state: + The current state. + + Returns + ------- + root : `Root` + The state root. + " in + let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition account_exists : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account exists in the state trie + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + account_exists : `bool` + True if account exists in the state trie, False otherwise + " in + let _ := M.return_ (| + Compare.is_not (| M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), Constant.None_ |) + |) in + M.pure Constant.None_)). + +Definition account_has_code_or_nonce : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account has non zero nonce or non empty code + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + has_code_or_nonce : `bool` + True if if an account has non zero nonce or non empty code, + False otherwise. + " in + let account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + BoolOp.or (| + Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |) + )) + |) + |) in + M.pure Constant.None_)). + +Definition modify_state : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "f" ] |) in + let _ := Constant.str " + Modify an `Account` in the `State`. + " in + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.call (| + M.get_name (| globals, "modify" |), + make_list [ + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |); + M.get_name (| globals, "f" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition move_ether : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "sender_address"; "recipient_address"; "amount" ] |) in + let _ := Constant.str " + Move funds between accounts. + " in +(* At stmt: unsupported node type: FunctionDef *) +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "sender_address" |); + M.get_name (| globals, "reduce_sender_balance" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "recipient_address" |); + M.get_name (| globals, "increase_recipient_balance" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition set_account_balance : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "amount" ] |) in + let _ := Constant.str " + Sets the balance of an account. + + Parameters + ---------- + state: + The current state. + + address: + Address of the account whose nonce needs to be incremented. + + amount: + The amount that needs to set in balance. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "set_balance" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition touch_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Initializes an account to state. + + Parameters + ---------- + state: + The current state. + + address: + The address of the account that need to initialised. + " in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "account_exists" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "EMPTY_ACCOUNT" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition increment_nonce : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Increments the nonce of an account. + + Parameters + ---------- + state: + The current state. + + address: + Address of the account whose nonce needs to be incremented. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "increase_nonce" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition set_code : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "code" ] |) in + let _ := Constant.str " + Sets Account code. + + Parameters + ---------- + state: + The current state. + + address: + Address of the account whose code needs to be update. + + code: + The bytecode that needs to be set. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "write_code" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition create_ether : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "amount" ] |) in + let _ := Constant.str " + Add newly created ether to an account. + + Parameters + ---------- + state: + The current state. + address: + Address of the account to which ether is added. + amount: + The amount of ether to be added to the account of interest. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "increase_balance" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/transactions.v b/CoqOfPython/ethereum/homestead/transactions.v new file mode 100644 index 0000000..6d1bc6b --- /dev/null +++ b/CoqOfPython/ethereum/homestead/transactions.v @@ -0,0 +1,60 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Transactions are atomic units of work created externally to Ethereum and +submitted to be executed. If Ethereum is viewed as a state machine, +transactions are the events that move between states. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes0 : + IsGlobalAlias globals base_types.globals "Bytes0". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( + Constant.int 21000 +)). + +Definition TX_DATA_COST_PER_NON_ZERO : Value.t := M.run ltac:(M.monadic ( + Constant.int 68 +)). + +Definition TX_DATA_COST_PER_ZERO : Value.t := M.run ltac:(M.monadic ( + Constant.int 4 +)). + +Definition TX_CREATE_COST : Value.t := M.run ltac:(M.monadic ( + Constant.int 32000 +)). + +Definition Transaction : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. diff --git a/CoqOfPython/ethereum/homestead/trie.v b/CoqOfPython/ethereum/homestead/trie.v new file mode 100644 index 0000000..a9cbb1f --- /dev/null +++ b/CoqOfPython/ethereum/homestead/trie.v @@ -0,0 +1,1357 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +State Trie +^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The state trie is the structure responsible for storing +`.fork_types.Account` objects. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_field : + IsGlobalAlias globals dataclasses.globals "field". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". +Axiom typing_Generic : + IsGlobalAlias globals typing.globals "Generic". +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Mapping : + IsGlobalAlias globals typing.globals "Mapping". +Axiom typing_MutableMapping : + IsGlobalAlias globals typing.globals "MutableMapping". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Sequence : + IsGlobalAlias globals typing.globals "Sequence". +Axiom typing_TypeVar : + IsGlobalAlias globals typing.globals "TypeVar". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". +Axiom typing_cast : + IsGlobalAlias globals typing.globals "cast". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.frontier. +Axiom ethereum_frontier_trie : + IsGlobalAlias globals ethereum.frontier.globals "trie". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require ethereum.utils.hexadecimal. +Axiom ethereum_utils_hexadecimal_hex_to_bytes : + IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require blocks. +Axiom blocks_Receipt : + IsGlobalAlias globals blocks.globals "Receipt". + +Require fork_types. +Axiom fork_types_Account : + IsGlobalAlias globals fork_types.globals "Account". +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". +Axiom fork_types_encode_account : + IsGlobalAlias globals fork_types.globals "encode_account". + +Require transactions. +Axiom transactions_Transaction : + IsGlobalAlias globals transactions.globals "Transaction". + +Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Root" |), + make_list [ + M.call (| + M.get_name (| globals, "hex_to_bytes" |), + make_list [ + Constant.str "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" + ], + make_dict [] + |) + ], + make_dict [] + |) +)). + +Definition Node : Value.t := M.run ltac:(M.monadic ( + M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Bytes" |); M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |); Constant.None_ ] |) +)). + +Definition K : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "TypeVar" |), + make_list [ + Constant.str "K" + ], + make_dict [] + |) +)). + +Definition V : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "TypeVar" |), + make_list [ + Constant.str "V"; + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Account" |) |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Bytes" |) |); + M.get_name (| globals, "Bytes" |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Transaction" |) |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Receipt" |) |); + M.get_name (| globals, "Uint" |); + M.get_name (| globals, "U256" |) + ], + make_dict [] + |) +)). + +Definition LeafNode : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition ExtensionNode : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition BranchNode : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition InternalNode : Value.t := M.run ltac:(M.monadic ( + M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LeafNode" |); M.get_name (| globals, "ExtensionNode" |); M.get_name (| globals, "BranchNode" |) ] |) +)). + +Definition encode_internal_node : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "node" ] |) in + let _ := Constant.str " + Encodes a Merkle Trie node into its RLP form. The RLP will then be + serialized into a `Bytes` and hashed unless it is less that 32 bytes + when serialized. + + This function also accepts `None`, representing the absence of a node, + which is encoded to `b""""""`. + + Parameters + ---------- + node : Optional[InternalNode] + The node to encode. + + Returns + ------- + encoded : `rlp.RLP` + The node encoded as RLP. + " in +(* At stmt: unsupported node type: AnnAssign *) + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "node" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let unencoded := + (* At constant: unsupported node type: Constant *) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "LeafNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "rest_of_key" |); + Constant.bool true + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "ExtensionNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "key_segment" |); + Constant.bool false + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "BranchNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + BinOp.add (| + M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "value" |) + ] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "AssertionError" |), + make_list [ + (* At expr: unsupported node type: JoinedStr *) + ], + make_dict [] + |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let encoded := + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "unencoded" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded" |) + ], + make_dict [] + |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "unencoded" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "encoded" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition encode_node : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "node"; "storage_root" ] |) in + let _ := Constant.str " + Encode a Node for storage in the Merkle Trie. + + Currently mostly an unimplemented stub. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "storage_root" |), Constant.None_ |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "encode_account" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "storage_root" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + make_tuple [ M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "U256" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "cast" |), + make_list [ + M.get_field (| M.get_name (| globals, "rlp" |), "RLP" |); + M.get_name (| globals, "node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "node" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "previous_trie" |), "encode_node" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "storage_root" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition Trie : Value.t := + builtins.make_klass + [(* At base: unsupported node type: Subscript *)] + [ + + ] + [ + + ]. + +Definition copy_trie : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie" ] |) in + let _ := Constant.str " + Create a copy of `trie`. Since only frozen objects may be stored in tries, + the contents are reused. + + Parameters + ---------- + trie: `Trie` + Trie to copy. + + Returns + ------- + new_trie : `Trie[K, V]` + A copy of the trie. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Trie" |), + make_list [ + M.get_field (| M.get_name (| globals, "trie" |), "secured" |); + M.get_field (| M.get_name (| globals, "trie" |), "default" |); + M.call (| + M.get_field (| M.get_name (| globals, "copy" |), "copy" |), + make_list [ + M.get_field (| M.get_name (| globals, "trie" |), "_data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition trie_set : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "key"; "value" ] |) in + let _ := Constant.str " + Stores an item in a Merkle Trie. + + This method deletes the key if `value == trie.default`, because the Merkle + Trie represents the default value by omitting it from the trie. + + Parameters + ---------- + trie: `Trie` + Trie to store in. + key : `Bytes` + Key to lookup. + value : `V` + Node to insert at `key`. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "value" |), M.get_field (| M.get_name (| globals, "trie" |), "default" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "key" |), M.get_field (| M.get_name (| globals, "trie" |), "_data" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition trie_get : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "key" ] |) in + let _ := Constant.str " + Gets an item from the Merkle Trie. + + This method returns `trie.default` if the key is missing. + + Parameters + ---------- + trie: + Trie to lookup in. + key : + Key to lookup. + + Returns + ------- + node : `V` + Node at `key` in the trie. + " in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "get" |), + make_list [ + M.get_name (| globals, "key" |); + M.get_field (| M.get_name (| globals, "trie" |), "default" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition common_prefix_length : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "a"; "b" ] |) in + let _ := Constant.str " + Find the longest common prefix of two sequences. + " in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + ], + make_dict [] + |) do + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| M.get_name (| globals, "i" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition nibble_list_to_compact : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "x"; "is_leaf" ] |) in + let _ := Constant.str " + Compresses nibble-list into a standard byte array with a flag. + + A nibble-list is a list of byte values no greater than `15`. The flag is + encoded in high nibble of the highest byte. The flag nibble can be broken + down into two two-bit flags. + + Highest nibble:: + + +---+---+----------+--------+ + | _ | _ | is_leaf | parity | + +---+---+----------+--------+ + 3 2 1 0 + + + The lowest bit of the nibble encodes the parity of the length of the + remaining nibbles -- `0` when even and `1` when odd. The second lowest bit + is used to distinguish leaf and extension nodes. The other two bits are not + used. + + Parameters + ---------- + x : + Array of nibbles. + is_leaf : + True if this is part of a leaf node, or false if it is an extension + node. + + Returns + ------- + compressed : `bytearray` + Compact byte array. + " in + let compact := + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + Constant.int 2 + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.mult (| + Constant.int 16, + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "is_leaf" |) + |) + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + BinOp.add (| + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "is_leaf" |) + |), + Constant.int 1 + |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), Constant.int 0 |) + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 1; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + M.get_name (| globals, "compact" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition bytes_to_nibble_list : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "bytes_" ] |) in + let _ := Constant.str " + Converts a `Bytes` into to a sequence of nibbles (bytes with value < 16). + + Parameters + ---------- + bytes_: + The `Bytes` to convert. + + Returns + ------- + nibble_list : `Bytes` + The `Bytes` in nibble-list format. + " in + let nibble_list := + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [ + BinOp.mult (| + Constant.int 2, + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "bytes_" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + For make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ] in M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "bytes_" |) + ], + make_dict [] + |) do + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |) |), + BinOp.r_shift (| + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 240 + |), + Constant.int 4 + |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |), + Constant.int 1 + |) |), + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 15 + |) + |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + M.get_name (| globals, "nibble_list" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition _prepare_trie : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "get_storage_root" ] |) in + let _ := Constant.str " + Prepares the trie for root calculation. Removes values that are empty, + hashes the keys (if `secured == True`) and encodes all the nodes. + + Parameters + ---------- + trie : + The `Trie` to prepare. + get_storage_root : + Function to get the storage root of an account. Needed to encode + `Account` objects. + + Returns + ------- + out : `Mapping[ethereum.base_types.Bytes, Node]` + Object with keys mapped to nibble-byte form. + " in +(* At stmt: unsupported node type: AnnAssign *) + For make_tuple [ M.get_name (| globals, "preimage" |); M.get_name (| globals, "value" |) ] in M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "items" |), + make_list [], + make_dict [] + |) do + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in + let address := + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |); + M.call (| + M.get_name (| globals, "get_storage_root" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_eq (| M.get_name (| globals, "encoded_value" |), (* At constant: unsupported node type: Constant *) |); + M.get_name (| globals, "AssertionError" |) + ], + make_dict [] + |) in +(* At stmt: unsupported node type: AnnAssign *) + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "trie" |), "secured" |), + (* then *) + ltac:(M.monadic ( + let key := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let key := + M.get_name (| globals, "preimage" |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "mapped" |), M.call (| + M.get_name (| globals, "bytes_to_nibble_list" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |) |), + M.get_name (| globals, "encoded_value" |) + |) in + EndFor. + let _ := M.return_ (| + M.get_name (| globals, "mapped" |) + |) in + M.pure Constant.None_)). + +Definition root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "get_storage_root" ] |) in + let _ := Constant.str " + Computes the root of a modified merkle patricia trie (MPT). + + Parameters + ---------- + trie : + `Trie` to get the root of. + get_storage_root : + Function to get the storage root of an account. Needed to encode + `Account` objects. + + + Returns + ------- + root : `.fork_types.Root` + MPT root of the underlying key-value pairs. + " in + let obj := + M.call (| + M.get_name (| globals, "_prepare_trie" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "get_storage_root" |) + ], + make_dict [] + |) in + let root_node := + M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_name (| globals, "obj" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assert (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "root_node" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Root" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition patricialize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "obj"; "level" ] |) in + let _ := Constant.str " + Structural composition function. + + Used to recursively patricialize and merkleize a dictionary. Includes + memoization of the tree structure and hashes. + + Parameters + ---------- + obj : + Underlying trie key-value pairs, with keys in nibble-list format. + level : + Current trie level. + + Returns + ------- + node : `ethereum.base_types.Bytes` + Root node of `obj`. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let arbitrary_key := + M.call (| + M.get_name (| globals, "next" |), + make_list [ + M.call (| + M.get_name (| globals, "iter" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), Constant.int 1 |), + (* then *) + ltac:(M.monadic ( + let leaf := + M.call (| + M.get_name (| globals, "LeafNode" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |); + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "leaf" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let substring := + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) in + let prefix_length := + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "substring" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do + let prefix_length := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_name (| globals, "prefix_length" |); + M.call (| + M.get_name (| globals, "common_prefix_length" |), + make_list [ + M.get_name (| globals, "substring" |); + M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let prefix := + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ExtensionNode" |), + make_list [ + M.get_name (| globals, "prefix" |); + M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_name (| globals, "obj" |); + BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in +(* At stmt: unsupported node type: AnnAssign *) + For M.get_name (| globals, "_" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 16 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "branches" |), "append" |), + make_list [ + {} + ], + make_dict [] + |) in + EndFor. + let value := + (* At constant: unsupported node type: Constant *) in + For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |), M.get_name (| globals, "level" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "AssertionError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) + |) in + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "BranchNode" |), + make_list [ + [M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "branches" |), M.get_name (| globals, "k" |) |); + BinOp.add (| + M.get_name (| globals, "level" |), + Constant.int 1 + |) + ], + make_dict [] + |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)]; + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/utils/__init__.v b/CoqOfPython/ethereum/homestead/utils/__init__.v new file mode 100644 index 0000000..1baedea --- /dev/null +++ b/CoqOfPython/ethereum/homestead/utils/__init__.v @@ -0,0 +1,8 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Utility functions unique to this particular fork. +". diff --git a/CoqOfPython/ethereum/homestead/utils/address.v b/CoqOfPython/ethereum/homestead/utils/address.v new file mode 100644 index 0000000..e36c5e8 --- /dev/null +++ b/CoqOfPython/ethereum/homestead/utils/address.v @@ -0,0 +1,133 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Hardfork Utility Functions For Addresses +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Address specific functions used in this homestead version of specification. +". + +Require typing. +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_left_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Definition to_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "data" ] |) in + let _ := Constant.str " + Convert a Uint or U256 value to a valid address (20 bytes). + + Parameters + ---------- + data : + The string to be converted to bytes. + + Returns + ------- + address : `Address` + The obtained address. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_subscript (| M.call (| + M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition compute_contract_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "address"; "nonce" ] |) in + let _ := Constant.str " + Computes address of the new account that needs to be created. + + Parameters + ---------- + address : + The address of the account that wants to create the new account. + nonce : + The transaction count of the account that wants to create the new + account. + + Returns + ------- + address: `ethereum.homestead.fork_types.Address` + The computed address of the new account. + " in + let computed_address := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_list [ + M.get_name (| globals, "address" |); + M.get_name (| globals, "nonce" |) + ] + ], + make_dict [] + |) + ], + make_dict [] + |) in + let canonical_address := + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + let padded_address := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "canonical_address" |); + Constant.int 20 + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "padded_address" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/utils/hexadecimal.v b/CoqOfPython/ethereum/homestead/utils/hexadecimal.v new file mode 100644 index 0000000..3d8c6ad --- /dev/null +++ b/CoqOfPython/ethereum/homestead/utils/hexadecimal.v @@ -0,0 +1,155 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Utility Functions For Hexadecimal Strings +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Hexadecimal utility functions used in this specification, specific to Homestead +types. +". + +Require ethereum.utils.hexadecimal. +Axiom ethereum_utils_hexadecimal_remove_hex_prefix : + IsGlobalAlias globals ethereum.utils.hexadecimal.globals "remove_hex_prefix". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Definition hex_to_root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to trie root. + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to trie root. + + Returns + ------- + root : `Root` + Trie root obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Root" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition hex_to_bloom : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to bloom. + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to bloom. + + Returns + ------- + bloom : `Bloom` + Bloom obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bloom" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition hex_to_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to Address (20 bytes). + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to Address. + + Returns + ------- + address : `Address` + The address obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |), "rjust" |), + make_list [ + Constant.int 40; + Constant.str "0" + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/utils/message.v b/CoqOfPython/ethereum/homestead/utils/message.v new file mode 100644 index 0000000..eb1c3a9 --- /dev/null +++ b/CoqOfPython/ethereum/homestead/utils/message.v @@ -0,0 +1,197 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Hardfork Utility Functions For The Message Data-structure +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Message specific functions used in this homestead version of specification. +". + +Require typing. +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". + +Require vm. +Axiom vm_Environment : + IsGlobalAlias globals vm.globals "Environment". +Axiom vm_Message : + IsGlobalAlias globals vm.globals "Message". + +Require address. +Axiom address_compute_contract_address : + IsGlobalAlias globals address.globals "compute_contract_address". + +Definition prepare_message : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "caller"; "target"; "value"; "data"; "gas"; "env"; "code_address"; "should_transfer_value" ] |) in + let _ := Constant.str " + Execute a transaction against the provided environment. + + Parameters + ---------- + caller : + Address which initiated the transaction + target : + Address whose code will be executed + value : + Value to be transferred. + data : + Array of bytes provided to the code in `target`. + gas : + Gas provided for the code in `target`. + env : + Environment for the Ethereum Virtual Machine. + code_address : + This is usually same as the `target` address except when an alternative + accounts code needs to be executed. + eg. `CALLCODE` calling a precompile. + should_transfer_value : + if True ETH should be transferred while executing a message call. + + Returns + ------- + message: `ethereum.homestead.vm.Message` + Items containing contract creation or message call specific data. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Bytes0" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.call (| + M.get_name (| globals, "compute_contract_address" |), + make_list [ + M.get_name (| globals, "caller" |); + BinOp.sub (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "caller" |) + ], + make_dict [] + |), "nonce" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let msg_data := + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |) in + let code := + M.get_name (| globals, "data" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.get_name (| globals, "target" |) in + let msg_data := + M.get_name (| globals, "data" |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "target" |) + ], + make_dict [] + |), "code" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "code_address" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let code_address := + M.get_name (| globals, "target" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "AssertionError" |), + make_list [ + Constant.str "Target must be address or empty bytes" + ], + make_dict [] + |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/vm/__init__.v b/CoqOfPython/ethereum/homestead/vm/__init__.v new file mode 100644 index 0000000..49bcb40 --- /dev/null +++ b/CoqOfPython/ethereum/homestead/vm/__init__.v @@ -0,0 +1,152 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The abstract computer which runs the code stored in an +`.fork_types.Account`. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_State : + IsGlobalAlias globals state.globals "State". + +Definition __all__ : Value.t := M.run ltac:(M.monadic ( + make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] +)). + +Definition Environment : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Message : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Evm : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition incorporate_child_on_success : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "child_evm" ] |) in + let _ := Constant.str " + Incorporate the state of a successful `child_evm` into the parent `evm`. + + Parameters + ---------- + evm : + The parent `EVM`. + child_evm : + The child evm to incorporate. + " in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "gas_left" |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "logs" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "logs" |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "refund_counter" |) + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "accounts_to_delete" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition incorporate_child_on_error : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "child_evm" ] |) in + let _ := Constant.str " + Incorporate the state of an unsuccessful `child_evm` into the parent `evm`. + + Parameters + ---------- + evm : + The parent `EVM`. + child_evm : + The child evm to incorporate. + " in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "gas_left" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/vm/exceptions.v b/CoqOfPython/ethereum/homestead/vm/exceptions.v new file mode 100644 index 0000000..45435b3 --- /dev/null +++ b/CoqOfPython/ethereum/homestead/vm/exceptions.v @@ -0,0 +1,122 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Exceptions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Exceptions which cause the EVM to halt exceptionally. +". + +Require ethereum.exceptions. +Axiom ethereum_exceptions_EthereumException : + IsGlobalAlias globals ethereum.exceptions.globals "EthereumException". + +Definition ExceptionalHalt : Value.t := + builtins.make_klass + [(globals, "EthereumException")] + [ + + ] + [ + + ]. + +Definition StackUnderflowError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition StackOverflowError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition OutOfGasError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition InvalidOpcode : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + ( + "__init__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "code" ] |) in + let _ := M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "super" |), + make_list [], + make_dict [] + |), "__init__" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "self" |), "code" |), + M.get_name (| globals, "code" |) + |) in + M.pure Constant.None_)) + ) + ]. + +Definition InvalidJumpDestError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition StackDepthLimitError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition AddressCollision : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/__init__.v b/CoqOfPython/ethereum/homestead/vm/instructions/__init__.v new file mode 100644 index 0000000..e5bebd7 --- /dev/null +++ b/CoqOfPython/ethereum/homestead/vm/instructions/__init__.v @@ -0,0 +1,87 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +EVM Instruction Encoding (Opcodes) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Machine readable representations of EVM instructions, and a mapping to their +implementations. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". + +Require __init__. +Axiom __init___arithmetic : + IsGlobalAlias globals __init__.globals "arithmetic". + +Require __init__. +Axiom __init___bitwise : + IsGlobalAlias globals __init__.globals "bitwise". + +Require __init__. +Axiom __init___block : + IsGlobalAlias globals __init__.globals "block". + +Require __init__. +Axiom __init___comparison : + IsGlobalAlias globals __init__.globals "comparison". + +Require __init__. +Axiom __init___control_flow : + IsGlobalAlias globals __init__.globals "control_flow". + +Require __init__. +Axiom __init___environment : + IsGlobalAlias globals __init__.globals "environment". + +Require __init__. +Axiom __init___keccak : + IsGlobalAlias globals __init__.globals "keccak". + +Require __init__. +Axiom __init___log : + IsGlobalAlias globals __init__.globals "log". + +Require __init__. +Axiom __init___memory : + IsGlobalAlias globals __init__.globals "memory". + +Require __init__. +Axiom __init___stack : + IsGlobalAlias globals __init__.globals "stack". + +Require __init__. +Axiom __init___storage : + IsGlobalAlias globals __init__.globals "storage". + +Require __init__. +Axiom __init___system : + IsGlobalAlias globals __init__.globals "system". + +Definition Ops : Value.t := + builtins.make_klass + [(* At base: unsupported node type: Attribute *)] + [ + + ] + [ + + ]. + +(* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/homestead/vm/instructions/arithmetic.v new file mode 100644 index 0000000..a8b5c61 --- /dev/null +++ b/CoqOfPython/ethereum/homestead/vm/instructions/arithmetic.v @@ -0,0 +1,1085 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Arithmetic Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM Arithmetic instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U255_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U255_CEIL_VALUE". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_U256_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_get_sign : + IsGlobalAlias globals ethereum.utils.numeric.globals "get_sign". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_EXPONENTIATION : + IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION". +Axiom gas_GAS_EXPONENTIATION_PER_BYTE : + IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION_PER_BYTE". +Axiom gas_GAS_LOW : + IsGlobalAlias globals gas.globals "GAS_LOW". +Axiom gas_GAS_MID : + IsGlobalAlias globals gas.globals "GAS_MID". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition add : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Adds the top two elements of the stack together, and pushes the result back + on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "x" |), "wrapping_add" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition sub : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Subtracts the top two elements of the stack, and pushes the result back + on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "x" |), "wrapping_sub" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mul : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Multiply the top two elements of the stack, and pushes the result back + on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "x" |), "wrapping_mul" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition div : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Integer division of the top two elements of the stack. Pushes the result + back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let dividend := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let divisor := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let quotient := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let quotient := + BinOp.floor_div (| + M.get_name (| globals, "dividend" |), + M.get_name (| globals, "divisor" |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "quotient" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition sdiv : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed integer division of the top two elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let dividend := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let divisor := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let quotient := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_name (| globals, "dividend" |), UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "divisor" |), UnOp.sub (| Constant.int 1 |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let quotient := + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let sign := + M.call (| + M.get_name (| globals, "get_sign" |), + make_list [ + BinOp.mult (| + M.get_name (| globals, "dividend" |), + M.get_name (| globals, "divisor" |) + |) + ], + make_dict [] + |) in + let quotient := + BinOp.mult (| + M.get_name (| globals, "sign" |), + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "dividend" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "divisor" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + M.get_name (| globals, "quotient" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Modulo remainder of the top two elements of the stack. Pushes the result + back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let remainder := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let remainder := + BinOp.mod_ (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "remainder" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition smod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed modulo remainder of the top two elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let y := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let remainder := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let remainder := + BinOp.mult (| + M.call (| + M.get_name (| globals, "get_sign" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + BinOp.mod_ (| + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + M.get_name (| globals, "remainder" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition addmod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Modulo addition of the top 2 elements with the 3rd element. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let z := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_MID" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.add (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |), + M.get_name (| globals, "z" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mulmod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Modulo multiplication of the top 2 elements with the 3rd element. Pushes + the result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let z := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_MID" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.mult (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |), + M.get_name (| globals, "z" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition exp : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Exponential operation of the top 2 elements. Pushes the result back on + the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let base := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exponent := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exponent_bits := + M.call (| + M.get_field (| M.get_name (| globals, "exponent" |), "bit_length" |), + make_list [], + make_dict [] + |) in + let exponent_bytes := + BinOp.floor_div (| + BinOp.add (| + M.get_name (| globals, "exponent_bits" |), + Constant.int 7 + |), + Constant.int 8 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_EXPONENTIATION" |), + BinOp.mult (| + M.get_name (| globals, "GAS_EXPONENTIATION_PER_BYTE" |), + M.get_name (| globals, "exponent_bytes" |) + |) + |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "pow" |), + make_list [ + M.get_name (| globals, "base" |); + M.get_name (| globals, "exponent" |); + M.get_name (| globals, "U256_CEIL_VALUE" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition signextend : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Sign extend operation. In other words, extend a signed number which + fits in N bytes to 32 bytes. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let byte_num := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "byte_num" |), Constant.int 31 |), + (* then *) + ltac:(M.monadic ( + let result := + M.get_name (| globals, "value" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let value_bytes := + M.call (| + M.get_name (| globals, "bytes" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "value" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) in + let value_bytes := + M.get_subscript (| M.get_name (| globals, "value_bytes" |), BinOp.sub (| + Constant.int 31, + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "byte_num" |) + ], + make_dict [] + |) + |):(* At expr: unsupported node type: NoneType *) |) in + let sign_bit := + BinOp.r_shift (| + M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), + Constant.int 7 + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "sign_bit" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "value_bytes" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let num_bytes_prepend := + BinOp.sub (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "byte_num" |), + Constant.int 1 + |) + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + BinOp.add (| + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [ + BinOp.mult (| + make_list [ + Constant.int 255 + ], + M.get_name (| globals, "num_bytes_prepend" |) + |) + ], + make_dict [] + |), + M.get_name (| globals, "value_bytes" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/bitwise.v b/CoqOfPython/ethereum/homestead/vm/instructions/bitwise.v new file mode 100644 index 0000000..b20a1e5 --- /dev/null +++ b/CoqOfPython/ethereum/homestead/vm/instructions/bitwise.v @@ -0,0 +1,345 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Bitwise Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM bitwise instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition bitwise_and : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise AND operation of the top 2 elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + BinOp.bit_and (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_or : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise OR operation of the top 2 elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + BinOp.bit_or (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_xor : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise XOR operation of the top 2 elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + BinOp.bit_xor (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_not : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise NOT operation of the top element of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + UnOp.invert (| M.get_name (| globals, "x" |) |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition get_byte : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + For a word (defined by next top element of the stack), retrieve the + Nth byte (0-indexed and defined by top element of stack) from the + left (most significant) to right (least significant). + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let byte_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let word := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "byte_index" |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let extra_bytes_to_right := + BinOp.sub (| + Constant.int 31, + M.get_name (| globals, "byte_index" |) + |) in + let word := + BinOp.r_shift (| + M.get_name (| globals, "word" |), + BinOp.mult (| + M.get_name (| globals, "extra_bytes_to_right" |), + Constant.int 8 + |) + |) in + let word := + BinOp.bit_and (| + M.get_name (| globals, "word" |), + Constant.int 255 + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "word" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/block.v b/CoqOfPython/ethereum/homestead/vm/instructions/block.v new file mode 100644 index 0000000..e5fa554 --- /dev/null +++ b/CoqOfPython/ethereum/homestead/vm/instructions/block.v @@ -0,0 +1,337 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Block Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM block instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_BLOCK_HASH : + IsGlobalAlias globals gas.globals "GAS_BLOCK_HASH". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition block_hash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the hash of one of the 256 most recent complete blocks onto the + stack. The block number to hash is present at the top of the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let block_number := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BLOCK_HASH" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt_e (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), M.get_name (| globals, "block_number" |) |), + ltac:(M.monadic ( + Compare.gt (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), BinOp.add (| + M.get_name (| globals, "block_number" |), + Constant.int 256 + |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let hash := + (* At constant: unsupported node type: Constant *) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let hash := + M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + M.get_name (| globals, "block_number" |) + |) |) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "hash" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition coinbase : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's beneficiary address (address of the block miner) + onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "coinbase" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition timestamp : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's timestamp onto the stack. Here the timestamp + being referred is actually the unix timestamp in seconds. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "time" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition number : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's number onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition difficulty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's difficulty onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "difficulty" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition gas_limit : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's gas limit onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "gas_limit" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/comparison.v b/CoqOfPython/ethereum/homestead/vm/instructions/comparison.v new file mode 100644 index 0000000..fbc35f8 --- /dev/null +++ b/CoqOfPython/ethereum/homestead/vm/instructions/comparison.v @@ -0,0 +1,404 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Comparison Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM Comparison instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition less_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is less than the next top element. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let right := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition signed_less_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed less-than comparison. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let right := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition greater_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is greater than the next top element. Pushes + the result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let right := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition signed_greater_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed greater-than comparison. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let right := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition equal : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is equal to the next top element. Pushes + the result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let right := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.eq (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition is_zero : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is equal to 0. Pushes the result back on the + stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.eq (| M.get_name (| globals, "x" |), Constant.int 0 |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/control_flow.v b/CoqOfPython/ethereum/homestead/vm/instructions/control_flow.v new file mode 100644 index 0000000..04a79d9 --- /dev/null +++ b/CoqOfPython/ethereum/homestead/vm/instructions/control_flow.v @@ -0,0 +1,336 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Control Flow Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM control flow instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require vm.gas. +Axiom vm_gas_GAS_BASE : + IsGlobalAlias globals vm.gas.globals "GAS_BASE". +Axiom vm_gas_GAS_HIGH : + IsGlobalAlias globals vm.gas.globals "GAS_HIGH". +Axiom vm_gas_GAS_JUMPDEST : + IsGlobalAlias globals vm.gas.globals "GAS_JUMPDEST". +Axiom vm_gas_GAS_MID : + IsGlobalAlias globals vm.gas.globals "GAS_MID". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_InvalidJumpDestError : + IsGlobalAlias globals exceptions.globals "InvalidJumpDestError". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition stop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stop further execution of EVM code. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let _ := M.pass (| |) in + let _ := M.pass (| |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "running" |), + Constant.bool false + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition jump : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Alter the program counter to the location specified by the top of the + stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let jump_dest := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_MID" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "jump_dest" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition jumpi : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Alter the program counter to the specified location if and only if a + condition is true. If the condition is not true, then the program counter + would increase only by 1. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let jump_dest := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let conditional_value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_HIGH" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "conditional_value" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let destination := + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let destination := + M.get_name (| globals, "jump_dest" |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "destination" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition pc : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push onto the stack the value of the program counter after reaching the + current instruction and without increasing it for the next instruction. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "pc" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition gas_left : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the amount of available gas (including the corresponding reduction + for the cost of this instruction) onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition jumpdest : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Mark a valid destination for jumps. This is a noop, present only + to be used by `JUMP` and `JUMPI` opcodes to verify that their jump is + valid. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_JUMPDEST" |) + ], + make_dict [] + |) in + let _ := M.pass (| |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/environment.v b/CoqOfPython/ethereum/homestead/vm/instructions/environment.v new file mode 100644 index 0000000..4d26a46 --- /dev/null +++ b/CoqOfPython/ethereum/homestead/vm/instructions/environment.v @@ -0,0 +1,943 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Environmental Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM environment related instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require state. +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". + +Require utils.address. +Axiom utils_address_to_address : + IsGlobalAlias globals utils.address.globals "to_address". + +Require vm.memory. +Axiom vm_memory_buffer_read : + IsGlobalAlias globals vm.memory.globals "buffer_read". +Axiom vm_memory_memory_write : + IsGlobalAlias globals vm.memory.globals "memory_write". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_BALANCE : + IsGlobalAlias globals gas.globals "GAS_BALANCE". +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_COPY : + IsGlobalAlias globals gas.globals "GAS_COPY". +Axiom gas_GAS_EXTERNAL : + IsGlobalAlias globals gas.globals "GAS_EXTERNAL". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the address of the current executing account to the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition balance : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the balance of the given account onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BALANCE" |) + ], + make_dict [] + |) in + let balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "balance" |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "balance" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition origin : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the address of the original transaction sender to the stack. + The origin address can only be an EOA. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "origin" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition caller : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the address of the caller onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "caller" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition callvalue : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the value (in wei) sent with the call onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition calldataload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push a word (32 bytes) of the input data belonging to the current + environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |); + M.get_name (| globals, "start_index" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition calldatasize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the size of input data in current environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition calldatacopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy a portion of the input data in current environment to memory. + + This will also expand the memory, in case that the memory is insufficient + to store the data. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let data_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |); + M.get_name (| globals, "data_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition codesize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the size of code running in current environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "code" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition codecopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy a portion of the code in current environment to memory. + + This will also expand the memory, in case that the memory is insufficient + to store the data. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let code_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "code" |); + M.get_name (| globals, "code_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition gasprice : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the gas price used in current environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "gas_price" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition extcodesize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the code size of a given account onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_EXTERNAL" |) + ], + make_dict [] + |) in + let codesize := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "code" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "codesize" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition extcodecopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy a portion of an account's code to memory. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let code_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_EXTERNAL" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "code" |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "code" |); + M.get_name (| globals, "code_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/keccak.v b/CoqOfPython/ethereum/homestead/vm/instructions/keccak.v new file mode 100644 index 0000000..cab9ffb --- /dev/null +++ b/CoqOfPython/ethereum/homestead/vm/instructions/keccak.v @@ -0,0 +1,181 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Keccak Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM keccak instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_KECCAK256 : + IsGlobalAlias globals gas.globals "GAS_KECCAK256". +Axiom gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition keccak : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes to the stack the Keccak-256 hash of a region of memory. + + This also expands the memory, in case the memory is insufficient to + access the data's memory location. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let word_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_KECCAK256_WORD" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_KECCAK256" |), + M.get_name (| globals, "word_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let data := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "hash" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/log.v b/CoqOfPython/ethereum/homestead/vm/instructions/log.v new file mode 100644 index 0000000..f246f9d --- /dev/null +++ b/CoqOfPython/ethereum/homestead/vm/instructions/log.v @@ -0,0 +1,228 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Logging Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM logging instructions. +". + +Require functools. +Axiom functools_partial : + IsGlobalAlias globals functools.globals "partial". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_LOG : + IsGlobalAlias globals gas.globals "GAS_LOG". +Axiom gas_GAS_LOG_DATA : + IsGlobalAlias globals gas.globals "GAS_LOG_DATA". +Axiom gas_GAS_LOG_TOPIC : + IsGlobalAlias globals gas.globals "GAS_LOG_TOPIC". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". + +Definition log_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "num_topics" ] |) in + let _ := Constant.str " + Appends a log entry, having `num_topics` topics, to the evm logs. + + This will also expand the memory if the data (required by the log entry) + corresponding to the memory is not accessible. + + Parameters + ---------- + evm : + The current EVM frame. + num_topics : + The number of topics to be included in the log entry. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let topics := + make_list [] in + For M.get_name (| globals, "_" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "num_topics" |) + ], + make_dict [] + |) do + let topic := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "topics" |), "append" |), + make_list [ + M.get_name (| globals, "topic" |) + ], + make_dict [] + |) in + EndFor. + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_LOG" |), + BinOp.mult (| + M.get_name (| globals, "GAS_LOG_DATA" |), + M.get_name (| globals, "size" |) + |) + |), + BinOp.mult (| + M.get_name (| globals, "GAS_LOG_TOPIC" |), + M.get_name (| globals, "num_topics" |) + |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let log_entry := + M.call (| + M.get_name (| globals, "Log" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "logs" |), + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "logs" |), + make_tuple [ M.get_name (| globals, "log_entry" |) ] + |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition log0 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/memory.v b/CoqOfPython/ethereum/homestead/vm/instructions/memory.v new file mode 100644 index 0000000..1e1c8b0 --- /dev/null +++ b/CoqOfPython/ethereum/homestead/vm/instructions/memory.v @@ -0,0 +1,378 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Memory Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM Memory instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". +Axiom memory_memory_write : + IsGlobalAlias globals memory.globals "memory_write". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition mstore : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a word to memory. + This also expands the memory, if the memory is + insufficient to store the word. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "start_position" |); M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + ], + make_dict [] + |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "start_position" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mstore8 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a byte to memory. + This also expands the memory, if the memory is + insufficient to store the word. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "start_position" |); M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let normalized_bytes_value := + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + make_list [ + BinOp.bit_and (| + M.get_name (| globals, "value" |), + Constant.int 255 + |) + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "start_position" |); + M.get_name (| globals, "normalized_bytes_value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Load word from memory. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "start_position" |); M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "start_position" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition msize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the size of active memory in bytes onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/stack.v b/CoqOfPython/ethereum/homestead/vm/instructions/stack.v new file mode 100644 index 0000000..1eeda05 --- /dev/null +++ b/CoqOfPython/ethereum/homestead/vm/instructions/stack.v @@ -0,0 +1,929 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Stack Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM stack related instructions. +". + +Require functools. +Axiom functools_partial : + IsGlobalAlias globals functools.globals "partial". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". +Axiom __init___stack : + IsGlobalAlias globals __init__.globals "stack". + +Require exceptions. +Axiom exceptions_StackUnderflowError : + IsGlobalAlias globals exceptions.globals "StackUnderflowError". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_buffer_read : + IsGlobalAlias globals memory.globals "buffer_read". + +Definition pop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Remove item from stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.pass (| |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition push_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "num_bytes" ] |) in + let _ := Constant.str " + Pushes a N-byte immediate onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + num_bytes : + The number of immediate bytes to be read from the code and pushed to + the stack. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let data_to_push := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "code" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "num_bytes" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "data_to_push" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + BinOp.add (| + Constant.int 1, + M.get_name (| globals, "num_bytes" |) + |) + |) in + M.pure Constant.None_)). + +Definition dup_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "item_number" ] |) in + let _ := Constant.str " + Duplicate the Nth stack item (from top of the stack) to the top of stack. + + Parameters + ---------- + evm : + The current EVM frame. + + item_number : + The stack item number (0-indexed from top of stack) to be duplicated + to the top of stack. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "StackUnderflowError" |) + ], + make_dict [] + |) in + let data_to_duplicate := + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + BinOp.sub (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), + Constant.int 1 + |), + M.get_name (| globals, "item_number" |) + |) |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "data_to_duplicate" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition swap_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "item_number" ] |) in + let _ := Constant.str " + Swap the top and the `item_number` element of the stack, where + the top of the stack is position zero. + + If `item_number` is zero, this function does nothing (which should not be + possible, since there is no `SWAP0` instruction). + + Parameters + ---------- + evm : + The current EVM frame. + + item_number : + The stack item number (0-indexed from top of stack) to be swapped + with the top of stack element. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "StackUnderflowError" |) + ], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) |) ], + make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |) ] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition push1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push5 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push6 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push7 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push8 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push9 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push10 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push11 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push12 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push13 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push14 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push15 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push16 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push17 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push18 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push19 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push20 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push21 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push22 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push23 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push24 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push25 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push26 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push27 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push28 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push29 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push30 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push31 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push32 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition dup1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup5 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup6 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup7 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup8 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup9 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup10 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup11 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup12 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup13 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup14 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup15 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup16 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition swap1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap5 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap6 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap7 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap8 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap9 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap10 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap11 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap12 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap13 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap14 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap15 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap16 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/storage.v b/CoqOfPython/ethereum/homestead/vm/instructions/storage.v new file mode 100644 index 0000000..4292e3b --- /dev/null +++ b/CoqOfPython/ethereum/homestead/vm/instructions/storage.v @@ -0,0 +1,212 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Storage Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM storage related instructions. +". + +Require state. +Axiom state_get_storage : + IsGlobalAlias globals state.globals "get_storage". +Axiom state_set_storage : + IsGlobalAlias globals state.globals "set_storage". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_SLOAD : + IsGlobalAlias globals gas.globals "GAS_SLOAD". +Axiom gas_GAS_STORAGE_CLEAR_REFUND : + IsGlobalAlias globals gas.globals "GAS_STORAGE_CLEAR_REFUND". +Axiom gas_GAS_STORAGE_SET : + IsGlobalAlias globals gas.globals "GAS_STORAGE_SET". +Axiom gas_GAS_STORAGE_UPDATE : + IsGlobalAlias globals gas.globals "GAS_STORAGE_UPDATE". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition sload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Loads to the stack, the value corresponding to a certain key from the + storage of the current account. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let key := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_SLOAD" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "get_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition sstore : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a value at a certain key in the current context's storage. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let key := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let new_value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let current_value := + M.call (| + M.get_name (| globals, "get_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "new_value" |), Constant.int 0 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let gas_cost := + M.get_name (| globals, "GAS_STORAGE_SET" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let gas_cost := + M.get_name (| globals, "GAS_STORAGE_UPDATE" |) in + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_name (| globals, "new_value" |), Constant.int 0 |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "gas_cost" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "set_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |); + M.get_name (| globals, "new_value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/system.v b/CoqOfPython/ethereum/homestead/vm/instructions/system.v new file mode 100644 index 0000000..335986d --- /dev/null +++ b/CoqOfPython/ethereum/homestead/vm/instructions/system.v @@ -0,0 +1,1245 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) System Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM system related instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_account_has_code_or_nonce : + IsGlobalAlias globals state.globals "account_has_code_or_nonce". +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". +Axiom state_increment_nonce : + IsGlobalAlias globals state.globals "increment_nonce". +Axiom state_set_account_balance : + IsGlobalAlias globals state.globals "set_account_balance". + +Require utils.address. +Axiom utils_address_compute_contract_address : + IsGlobalAlias globals utils.address.globals "compute_contract_address". +Axiom utils_address_to_address : + IsGlobalAlias globals utils.address.globals "to_address". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". +Axiom __init___Message : + IsGlobalAlias globals __init__.globals "Message". +Axiom __init___incorporate_child_on_error : + IsGlobalAlias globals __init__.globals "incorporate_child_on_error". +Axiom __init___incorporate_child_on_success : + IsGlobalAlias globals __init__.globals "incorporate_child_on_success". + +Require gas. +Axiom gas_GAS_CALL : + IsGlobalAlias globals gas.globals "GAS_CALL". +Axiom gas_GAS_CREATE : + IsGlobalAlias globals gas.globals "GAS_CREATE". +Axiom gas_GAS_ZERO : + IsGlobalAlias globals gas.globals "GAS_ZERO". +Axiom gas_REFUND_SELF_DESTRUCT : + IsGlobalAlias globals gas.globals "REFUND_SELF_DESTRUCT". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_calculate_message_call_gas : + IsGlobalAlias globals gas.globals "calculate_message_call_gas". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". +Axiom memory_memory_write : + IsGlobalAlias globals memory.globals "memory_write". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition create : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Creates a new account with associated code. + + Parameters + ---------- + evm : + The current EVM frame. + " in +(* At stmt: unsupported node type: ImportFrom *) + let endowment := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_position" |); M.get_name (| globals, "memory_size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_CREATE" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let create_message_gas := + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let sender_address := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in + let sender := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "sender_address" |) + ], + make_dict [] + |) in + let contract_address := + M.call (| + M.get_name (| globals, "compute_contract_address" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "nonce" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt (| M.get_field (| M.get_name (| globals, "sender" |), "balance" |), M.get_name (| globals, "endowment" |) |), + ltac:(M.monadic ( + BoolOp.or (| + Compare.eq (| M.get_field (| M.get_name (| globals, "sender" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.sub (| + BinOp.pow (| + Constant.int 2, + Constant.int 64 + |), + Constant.int 1 + |) + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.gt (| BinOp.add (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "depth" |), + Constant.int 1 + |), M.get_name (| globals, "STACK_DEPTH_LIMIT" |) |) + )) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "create_message_gas" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "contract_address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let call_data := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + let child_message := + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) in + let child_evm := + M.call (| + M.get_name (| globals, "process_create_message" |), + make_list [ + M.get_name (| globals, "child_message" |); + M.get_field (| M.get_name (| globals, "evm" |), "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "child_evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_error" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_success" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition return_ : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Halts execution returning output data. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let memory_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_position" |); M.get_name (| globals, "memory_size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_ZERO" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "running" |), + Constant.bool false + |) in + let _ := M.pass (| |) in + M.pure Constant.None_)). + +Definition generic_call : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "gas"; "value"; "caller"; "to"; "code_address"; "should_transfer_value"; "memory_input_start_position"; "memory_input_size"; "memory_output_start_position"; "memory_output_size" ] |) in + let _ := Constant.str " + Perform the core logic of the `CALL*` family of opcodes. + " in +(* At stmt: unsupported node type: ImportFrom *) + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| BinOp.add (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "depth" |), + Constant.int 1 + |), M.get_name (| globals, "STACK_DEPTH_LIMIT" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "gas" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let call_data := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |) + ], + make_dict [] + |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "code_address" |) + ], + make_dict [] + |), "code" |) in + let child_message := + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) in + let child_evm := + M.call (| + M.get_name (| globals, "process_message" |), + make_list [ + M.get_name (| globals, "child_message" |); + M.get_field (| M.get_name (| globals, "evm" |), "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "child_evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_error" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_success" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let actual_output_size := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_name (| globals, "memory_output_size" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), (* At expr: unsupported node type: NoneType *):M.get_name (| globals, "actual_output_size" |) |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition call : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into an account. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let to := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "gas" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let sender_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "sender_balance" |), M.get_name (| globals, "value" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.get_name (| globals, "value" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "to" |); + Constant.bool true; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition callcode : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into this account with alternative account’s code. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let code_address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let to := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "gas" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let sender_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "sender_balance" |), M.get_name (| globals, "value" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.get_name (| globals, "value" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "code_address" |); + Constant.bool true; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition selfdestruct : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Halt execution and register account for later deletion. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let beneficiary := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let gas_cost := + M.get_name (| globals, "GAS_ZERO" |) in + let originator := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in + let refunded_accounts := + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in + let parent_evm := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "parent_evm" |) in + While Compare.is_not (| M.get_name (| globals, "parent_evm" |), Constant.None_ |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "refunded_accounts" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "parent_evm" |), "accounts_to_delete" |) + ], + make_dict [] + |) in + let parent_evm := + M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in + EndWhile. + let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| M.get_name (| globals, "originator" |), M.get_name (| globals, "refunded_accounts" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.get_name (| globals, "REFUND_SELF_DESTRUCT" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "gas_cost" |) + ], + make_dict [] + |) in + let beneficiary_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |), "balance" |) in + let originator_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "originator" |) + ], + make_dict [] + |), "balance" |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |); + BinOp.add (| + M.get_name (| globals, "beneficiary_balance" |), + M.get_name (| globals, "originator_balance" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "originator" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |), "add" |), + make_list [ + M.get_name (| globals, "originator" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "running" |), + Constant.bool false + |) in + let _ := M.pass (| |) in + M.pure Constant.None_)). + +Definition delegatecall : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into an account. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let code_address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_CALL" |), + M.get_name (| globals, "gas" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "gas" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "value" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "caller" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "code_address" |); + Constant.bool false; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/vm/interpreter.v b/CoqOfPython/ethereum/homestead/vm/interpreter.v new file mode 100644 index 0000000..b4e4a21 --- /dev/null +++ b/CoqOfPython/ethereum/homestead/vm/interpreter.v @@ -0,0 +1,551 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Interpreter +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +A straightforward interpreter that executes EVM code. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.trace. +Axiom ethereum_trace_EvmStop : + IsGlobalAlias globals ethereum.trace.globals "EvmStop". +Axiom ethereum_trace_OpEnd : + IsGlobalAlias globals ethereum.trace.globals "OpEnd". +Axiom ethereum_trace_OpException : + IsGlobalAlias globals ethereum.trace.globals "OpException". +Axiom ethereum_trace_OpStart : + IsGlobalAlias globals ethereum.trace.globals "OpStart". +Axiom ethereum_trace_PrecompileEnd : + IsGlobalAlias globals ethereum.trace.globals "PrecompileEnd". +Axiom ethereum_trace_PrecompileStart : + IsGlobalAlias globals ethereum.trace.globals "PrecompileStart". +Axiom ethereum_trace_TransactionEnd : + IsGlobalAlias globals ethereum.trace.globals "TransactionEnd". +Axiom ethereum_trace_evm_trace : + IsGlobalAlias globals ethereum.trace.globals "evm_trace". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_account_has_code_or_nonce : + IsGlobalAlias globals state.globals "account_has_code_or_nonce". +Axiom state_begin_transaction : + IsGlobalAlias globals state.globals "begin_transaction". +Axiom state_commit_transaction : + IsGlobalAlias globals state.globals "commit_transaction". +Axiom state_destroy_storage : + IsGlobalAlias globals state.globals "destroy_storage". +Axiom state_move_ether : + IsGlobalAlias globals state.globals "move_ether". +Axiom state_rollback_transaction : + IsGlobalAlias globals state.globals "rollback_transaction". +Axiom state_set_code : + IsGlobalAlias globals state.globals "set_code". +Axiom state_touch_account : + IsGlobalAlias globals state.globals "touch_account". + +Require vm. +Axiom vm_Message : + IsGlobalAlias globals vm.globals "Message". + +Require vm.gas. +Axiom vm_gas_GAS_CODE_DEPOSIT : + IsGlobalAlias globals vm.gas.globals "GAS_CODE_DEPOSIT". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require vm.precompiled_contracts.mapping. +Axiom vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : + IsGlobalAlias globals vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". + +Require __init__. +Axiom __init___Environment : + IsGlobalAlias globals __init__.globals "Environment". +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_AddressCollision : + IsGlobalAlias globals exceptions.globals "AddressCollision". +Axiom exceptions_ExceptionalHalt : + IsGlobalAlias globals exceptions.globals "ExceptionalHalt". +Axiom exceptions_InvalidOpcode : + IsGlobalAlias globals exceptions.globals "InvalidOpcode". +Axiom exceptions_StackDepthLimitError : + IsGlobalAlias globals exceptions.globals "StackDepthLimitError". + +Require instructions. +Axiom instructions_Ops : + IsGlobalAlias globals instructions.globals "Ops". +Axiom instructions_op_implementation : + IsGlobalAlias globals instructions.globals "op_implementation". + +Require runtime. +Axiom runtime_get_valid_jump_destinations : + IsGlobalAlias globals runtime.globals "get_valid_jump_destinations". + +Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1024 + ], + make_dict [] + |) +)). + +Definition MessageCallOutput : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition process_message_call : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + If `message.current` is empty then it creates a smart contract + else it executes a call from the `message.caller` to the `message.target`. + + Parameters + ---------- + message : + Transaction specific items. + + env : + External items required for EVM execution. + + Returns + ------- + output : `MessageCallOutput` + Output of the message call + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_name (| globals, "message" |), "target" |), M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let is_collision := + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_name (| globals, "is_collision" |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallOutput" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "tuple" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "AddressCollision" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let evm := + M.call (| + M.get_name (| globals, "process_create_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let evm := + M.call (| + M.get_name (| globals, "process_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( +(* At stmt: unsupported node type: AnnAssign *) + let accounts_to_delete := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let refund_counter := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let logs := + M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in + let accounts_to_delete := + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in + let refund_counter := + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |) in + M.pure Constant.None_ + )) |) in + let tx_end := + M.call (| + M.get_name (| globals, "TransactionEnd" |), + make_list [ + BinOp.sub (| + M.get_field (| M.get_name (| globals, "message" |), "gas" |), + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + |); + M.get_field (| M.get_name (| globals, "evm" |), "output" |); + M.get_field (| M.get_name (| globals, "evm" |), "error" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "evm_trace" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "tx_end" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallOutput" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition process_create_message : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + Executes a call to create a smart contract. + + Parameters + ---------- + message : + Transaction specific items. + env : + External items required for EVM execution. + + Returns + ------- + evm: :py:class:`~ethereum.homestead.vm.Evm` + Items containing execution specific objects. + " in + let _ := M.call (| + M.get_name (| globals, "begin_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "destroy_storage" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let evm := + M.call (| + M.get_name (| globals, "process_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), + (* then *) + ltac:(M.monadic ( + let contract_code := + M.get_field (| M.get_name (| globals, "evm" |), "output" |) in + let contract_code_gas := + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "contract_code" |) + ], + make_dict [] + |), + M.get_name (| globals, "GAS_CODE_DEPOSIT" |) + |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "rollback_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.get_name (| globals, "evm" |) + |) in + M.pure Constant.None_)). + +Definition process_message : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + Executes a call to create a smart contract. + + Parameters + ---------- + message : + Transaction specific items. + env : + External items required for EVM execution. + + Returns + ------- + evm: :py:class:`~ethereum.homestead.vm.Evm` + Items containing execution specific objects + " in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_field (| M.get_name (| globals, "message" |), "depth" |), M.get_name (| globals, "STACK_DEPTH_LIMIT" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "StackDepthLimitError" |), + make_list [ + Constant.str "Stack depth limit reached" + ], + make_dict [] + |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "begin_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "touch_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + M.get_field (| M.get_name (| globals, "message" |), "should_transfer_value" |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_field (| M.get_name (| globals, "message" |), "value" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "move_ether" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "caller" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |); + M.get_field (| M.get_name (| globals, "message" |), "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let evm := + M.call (| + M.get_name (| globals, "execute_code" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "rollback_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "commit_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.get_name (| globals, "evm" |) + |) in + M.pure Constant.None_)). + +Definition execute_code : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + Executes bytecode present in the `message`. + + Parameters + ---------- + message : + Transaction specific items. + env : + External items required for EVM execution. + + Returns + ------- + evm: `ethereum.vm.EVM` + Items containing execution specific objects + " in + let code := + M.get_field (| M.get_name (| globals, "message" |), "code" |) in + let valid_jump_destinations := + M.call (| + M.get_name (| globals, "get_valid_jump_destinations" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) in + let evm := + M.call (| + M.get_name (| globals, "Evm" |), + make_list [], + make_dict [] + |) in +(* At stmt: unsupported node type: Try *) + let _ := M.return_ (| + M.get_name (| globals, "evm" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/vm/memory.v b/CoqOfPython/ethereum/homestead/vm/memory.v new file mode 100644 index 0000000..fa8d906 --- /dev/null +++ b/CoqOfPython/ethereum/homestead/vm/memory.v @@ -0,0 +1,153 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Memory +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +EVM memory operations. +". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_right_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "right_pad_zero_bytes". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". + +Definition memory_write : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "memory"; "start_position"; "value" ] |) in + let _ := Constant.str " + Writes to memory. + + Parameters + ---------- + memory : + Memory contents of the EVM. + start_position : + Starting pointer to the memory. + value : + Data to write to memory. + " in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) |), + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_)). + +Definition memory_read_bytes : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "memory"; "start_position"; "size" ] |) in + let _ := Constant.str " + Read bytes from memory. + + Parameters + ---------- + memory : + Memory contents of the EVM. + start_position : + Starting pointer to the memory. + size : + Size of the data that needs to be read from `start_position`. + + Returns + ------- + data_bytes : + Data read from memory. + " in + let _ := M.return_ (| + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |) + |) in + M.pure Constant.None_)). + +Definition buffer_read : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "buffer"; "start_position"; "size" ] |) in + let _ := Constant.str " + Read bytes from a buffer. Padding with zeros if necessary. + + Parameters + ---------- + buffer : + Memory contents of the EVM. + start_position : + Starting pointer to the memory. + size : + Size of the data that needs to be read from `start_position`. + + Returns + ------- + data_bytes : + Data read from memory. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "right_pad_zero_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/__init__.v new file mode 100644 index 0000000..422f670 --- /dev/null +++ b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/__init__.v @@ -0,0 +1,67 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Precompiled Contract Addresses +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Addresses of precompiled contracts and mappings to their +implementations. +". + +Require utils.hexadecimal. +Axiom utils_hexadecimal_hex_to_address : + IsGlobalAlias globals utils.hexadecimal.globals "hex_to_address". + +Definition __all__ : Value.t := M.run ltac:(M.monadic ( + make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS" ] +)). + +Definition ECRECOVER_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x01" + ], + make_dict [] + |) +)). + +Definition SHA256_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x02" + ], + make_dict [] + |) +)). + +Definition RIPEMD160_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x03" + ], + make_dict [] + |) +)). + +Definition IDENTITY_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x04" + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/ecrecover.v new file mode 100644 index 0000000..cc351b5 --- /dev/null +++ b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/ecrecover.v @@ -0,0 +1,269 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) ECRECOVER PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the ECRECOVER precompiled contract. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require ethereum.crypto.elliptic_curve. +Axiom ethereum_crypto_elliptic_curve_SECP256K1N : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_left_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_ECRECOVER : + IsGlobalAlias globals vm.gas.globals "GAS_ECRECOVER". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require vm.memory. +Axiom vm_memory_buffer_read : + IsGlobalAlias globals vm.memory.globals "buffer_read". + +Definition ecrecover : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Decrypts the address using elliptic curve DSA recovery mechanism and writes + the address to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_ECRECOVER" |) + ], + make_dict [] + |) in + let message_hash_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let message_hash := + M.call (| + M.get_name (| globals, "Hash32" |), + make_list [ + M.get_name (| globals, "message_hash_bytes" |) + ], + make_dict [] + |) in + let v := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let r := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let s := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 27 |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 28 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| Constant.int 0, M.get_name (| globals, "r" |) |), + ltac:(M.monadic ( + Compare.gt_e (| M.get_name (| globals, "r" |), M.get_name (| globals, "SECP256K1N" |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| Constant.int 0, M.get_name (| globals, "s" |) |), + ltac:(M.monadic ( + Compare.gt_e (| M.get_name (| globals, "s" |), M.get_name (| globals, "SECP256K1N" |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in +(* At stmt: unsupported node type: Try *) + let address := + M.get_subscript (| M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), Constant.int 12:Constant.int 32 |) in + let padded_address := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "address" |); + Constant.int 32 + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.get_name (| globals, "padded_address" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/identity.v new file mode 100644 index 0000000..fa96704 --- /dev/null +++ b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/identity.v @@ -0,0 +1,94 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) IDENTITY PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `IDENTITY` precompiled contract. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_IDENTITY : + IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY". +Axiom vm_gas_GAS_IDENTITY_WORD : + IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY_WORD". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition identity : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the message data to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let word_count := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_IDENTITY" |), + BinOp.mult (| + M.get_name (| globals, "GAS_IDENTITY_WORD" |), + M.get_name (| globals, "word_count" |) + |) + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.get_name (| globals, "data" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/mapping.v new file mode 100644 index 0000000..710457d --- /dev/null +++ b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/mapping.v @@ -0,0 +1,56 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Precompiled Contract Addresses +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Mapping of precompiled contracts their implementations. +". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require __init__. +Axiom __init___ECRECOVER_ADDRESS : + IsGlobalAlias globals __init__.globals "ECRECOVER_ADDRESS". +Axiom __init___IDENTITY_ADDRESS : + IsGlobalAlias globals __init__.globals "IDENTITY_ADDRESS". +Axiom __init___RIPEMD160_ADDRESS : + IsGlobalAlias globals __init__.globals "RIPEMD160_ADDRESS". +Axiom __init___SHA256_ADDRESS : + IsGlobalAlias globals __init__.globals "SHA256_ADDRESS". + +Require ecrecover. +Axiom ecrecover_ecrecover : + IsGlobalAlias globals ecrecover.globals "ecrecover". + +Require identity. +Axiom identity_identity : + IsGlobalAlias globals identity.globals "identity". + +Require ripemd160. +Axiom ripemd160_ripemd160 : + IsGlobalAlias globals ripemd160.globals "ripemd160". + +Require sha256. +Axiom sha256_sha256 : + IsGlobalAlias globals sha256.globals "sha256". + +(* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/ripemd160.v new file mode 100644 index 0000000..96f8dcd --- /dev/null +++ b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/ripemd160.v @@ -0,0 +1,122 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) RIPEMD160 PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `RIPEMD160` precompiled contract. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_left_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_RIPEMD160 : + IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160". +Axiom vm_gas_GAS_RIPEMD160_WORD : + IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160_WORD". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition ripemd160 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the ripemd160 hash to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let word_count := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_RIPEMD160" |), + BinOp.mult (| + M.get_name (| globals, "GAS_RIPEMD160_WORD" |), + M.get_name (| globals, "word_count" |) + |) + |) + ], + make_dict [] + |) in + let hash_bytes := + M.call (| + M.get_field (| M.call (| + M.get_field (| M.get_name (| globals, "hashlib" |), "new" |), + make_list [ + Constant.str "ripemd160"; + M.get_name (| globals, "data" |) + ], + make_dict [] + |), "digest" |), + make_list [], + make_dict [] + |) in + let padded_hash := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "hash_bytes" |); + Constant.int 32 + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.get_name (| globals, "padded_hash" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/sha256.v new file mode 100644 index 0000000..9f6d2bf --- /dev/null +++ b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/sha256.v @@ -0,0 +1,106 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) SHA256 PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `SHA256` precompiled contract. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_SHA256 : + IsGlobalAlias globals vm.gas.globals "GAS_SHA256". +Axiom vm_gas_GAS_SHA256_WORD : + IsGlobalAlias globals vm.gas.globals "GAS_SHA256_WORD". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition sha256 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the sha256 hash to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let word_count := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_SHA256" |), + BinOp.mult (| + M.get_name (| globals, "GAS_SHA256_WORD" |), + M.get_name (| globals, "word_count" |) + |) + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_field (| M.get_name (| globals, "hashlib" |), "sha256" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), "digest" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/vm/runtime.v b/CoqOfPython/ethereum/homestead/vm/runtime.v new file mode 100644 index 0000000..835b46c --- /dev/null +++ b/CoqOfPython/ethereum/homestead/vm/runtime.v @@ -0,0 +1,125 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Runtime Operations +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Runtime related operations used while executing EVM code. +". + +Require typing. +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require instructions. +Axiom instructions_Ops : + IsGlobalAlias globals instructions.globals "Ops". + +Definition get_valid_jump_destinations : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "code" ] |) in + let _ := Constant.str " + Analyze the evm code to obtain the set of valid jump destinations. + + Valid jump destinations are defined as follows: + * The jump destination is less than the length of the code. + * The jump destination should have the `JUMPDEST` opcode (0x5B). + * The jump destination shouldn't be part of the data corresponding to + `PUSH-N` opcodes. + + Note - Jump destinations are 0-indexed. + + Parameters + ---------- + code : + The EVM code which is to be executed. + + Returns + ------- + valid_jump_destinations: `Set[Uint]` + The set of valid jump destinations in the code. + " in + let valid_jump_destinations := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let pc := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + While Compare.lt (| M.get_name (| globals, "pc" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) |) do +(* At stmt: unsupported node type: Try *) + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "current_opcode" |), M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), + make_list [ + M.get_name (| globals, "pc" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + (* At expr: unsupported node type: Compare *), + (* then *) + ltac:(M.monadic ( + let push_data_size := + BinOp.add (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) + |), + Constant.int 1 + |) in + let pc := BinOp.add + M.get_name (| globals, "push_data_size" |) + M.get_name (| globals, "push_data_size" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let pc := BinOp.add + Constant.int 1 + Constant.int 1 in + EndWhile. + let _ := M.return_ (| + M.get_name (| globals, "valid_jump_destinations" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/vm/stack.v b/CoqOfPython/ethereum/homestead/vm/stack.v new file mode 100644 index 0000000..42ea42d --- /dev/null +++ b/CoqOfPython/ethereum/homestead/vm/stack.v @@ -0,0 +1,120 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Stack +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the stack operators for the EVM. +". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require exceptions. +Axiom exceptions_StackOverflowError : + IsGlobalAlias globals exceptions.globals "StackOverflowError". +Axiom exceptions_StackUnderflowError : + IsGlobalAlias globals exceptions.globals "StackUnderflowError". + +Definition pop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "stack" ] |) in + let _ := Constant.str " + Pops the top item off of `stack`. + + Parameters + ---------- + stack : + EVM stack. + + Returns + ------- + value : `U256` + The top element on the stack. + + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "StackUnderflowError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "pop" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition push : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "stack"; "value" ] |) in + let _ := Constant.str " + Pushes `value` onto `stack`. + + Parameters + ---------- + stack : + EVM stack. + + value : + Item to be pushed onto `stack`. + + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), Constant.int 1024 |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "StackOverflowError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "append" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/__init__.v b/CoqOfPython/ethereum/istanbul/__init__.v new file mode 100644 index 0000000..bea9b01 --- /dev/null +++ b/CoqOfPython/ethereum/istanbul/__init__.v @@ -0,0 +1,24 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +The Istanbul fork makes changes to the gas costs of EVM instructions and data, +adds a cryptographic primitive, and introduces an instruction to fetch the +current chain identifier. +". + +Require ethereum.fork_criteria. +Axiom ethereum_fork_criteria_ByBlockNumber : + IsGlobalAlias globals ethereum.fork_criteria.globals "ByBlockNumber". + +Definition FORK_CRITERIA : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "ByBlockNumber" |), + make_list [ + Constant.int 9069000 + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/istanbul/blocks.v b/CoqOfPython/ethereum/istanbul/blocks.v new file mode 100644 index 0000000..6501788 --- /dev/null +++ b/CoqOfPython/ethereum/istanbul/blocks.v @@ -0,0 +1,93 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +A `Block` is a single link in the chain that is Ethereum. Each `Block` contains +a `Header` and zero or more transactions. Each `Header` contains associated +metadata like the block number, parent block hash, and how much gas was +consumed by its transactions. + +Together, these blocks form a cryptographically secure journal recording the +history of all state transitions that have happened since the genesis of the +chain. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes8 : + IsGlobalAlias globals base_types.globals "Bytes8". +Axiom base_types_Bytes32 : + IsGlobalAlias globals base_types.globals "Bytes32". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require crypto.hash. +Axiom crypto_hash_Hash32 : + IsGlobalAlias globals crypto.hash.globals "Hash32". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Require transactions. +Axiom transactions_Transaction : + IsGlobalAlias globals transactions.globals "Transaction". + +Definition Header : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Block : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Log : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Receipt : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. diff --git a/CoqOfPython/ethereum/istanbul/bloom.v b/CoqOfPython/ethereum/istanbul/bloom.v new file mode 100644 index 0000000..04b5d9f --- /dev/null +++ b/CoqOfPython/ethereum/istanbul/bloom.v @@ -0,0 +1,164 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Logs Bloom +^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +This modules defines functions for calculating bloom filters of logs. For the +general theory of bloom filters see e.g. `Wikipedia +`_. Bloom filters are used to allow +for efficient searching of logs by address and/or topic, by rapidly +eliminating blocks and receipts from their search. +". + +Require typing. +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require fork_types. +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". + +Definition add_to_bloom : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "bloom"; "bloom_entry" ] |) in + let _ := Constant.str " + Add a bloom entry to the bloom filter (`bloom`). + + The number of hash functions used is 3. They are calculated by taking the + least significant 11 bits from the first 3 16-bit words of the + `keccak_256()` hash of `bloom_entry`. + + Parameters + ---------- + bloom : + The bloom filter. + bloom_entry : + An entry which is to be added to bloom filter. + " in + let hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "bloom_entry" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "idx" |) in make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ] do + let bit_to_set := + BinOp.bit_and (| + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |):BinOp.add (| + M.get_name (| globals, "idx" |), + Constant.int 2 + |) |) + ], + make_dict [] + |), + Constant.int 2047 + |) in + let bit_index := + BinOp.sub (| + Constant.int 2047, + M.get_name (| globals, "bit_to_set" |) + |) in + let byte_index := + BinOp.floor_div (| + M.get_name (| globals, "bit_index" |), + Constant.int 8 + |) in + let bit_value := + BinOp.l_shift (| + Constant.int 1, + BinOp.sub (| + Constant.int 7, + BinOp.mod_ (| + M.get_name (| globals, "bit_index" |), + Constant.int 8 + |) + |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), + BinOp.bit_or (| + M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), + M.get_name (| globals, "bit_value" |) + |) + |) in + EndFor. + M.pure Constant.None_)). + +Definition logs_bloom : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "logs" ] |) in + let _ := Constant.str " + Obtain the logs bloom from a list of log entries. + + The address and each topic of a log are added to the bloom filter. + + Parameters + ---------- + logs : + List of logs for which the logs bloom is to be obtained. + + Returns + ------- + logs_bloom : `Bloom` + The logs bloom obtained which is 256 bytes with some bits set as per + the caller address and the log topics. + " in +(* At stmt: unsupported node type: AnnAssign *) + For M.get_name (| globals, "log" |) in M.get_name (| globals, "logs" |) do + let _ := M.call (| + M.get_name (| globals, "add_to_bloom" |), + make_list [ + M.get_name (| globals, "bloom" |); + M.get_field (| M.get_name (| globals, "log" |), "address" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "topic" |) in M.get_field (| M.get_name (| globals, "log" |), "topics" |) do + let _ := M.call (| + M.get_name (| globals, "add_to_bloom" |), + make_list [ + M.get_name (| globals, "bloom" |); + M.get_name (| globals, "topic" |) + ], + make_dict [] + |) in + EndFor. + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bloom" |), + make_list [ + M.get_name (| globals, "bloom" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/fork_types.v b/CoqOfPython/ethereum/istanbul/fork_types.v new file mode 100644 index 0000000..d12953d --- /dev/null +++ b/CoqOfPython/ethereum/istanbul/fork_types.v @@ -0,0 +1,102 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Types +^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Types re-used throughout the specification, which are specific to Ethereum. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes20 : + IsGlobalAlias globals base_types.globals "Bytes20". +Axiom base_types_Bytes256 : + IsGlobalAlias globals base_types.globals "Bytes256". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require crypto.hash. +Axiom crypto_hash_Hash32 : + IsGlobalAlias globals crypto.hash.globals "Hash32". +Axiom crypto_hash_keccak256 : + IsGlobalAlias globals crypto.hash.globals "keccak256". + +Definition Address : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Bytes20" |) +)). + +Definition Root : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Hash32" |) +)). + +Definition Bloom : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Bytes256" |) +)). + +Definition Account : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition EMPTY_ACCOUNT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Account" |), + make_list [], + make_dict [] + |) +)). + +Definition encode_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "raw_account_data"; "storage_root" ] |) in + let _ := Constant.str " + Encode `Account` dataclass. + + Storage is not stored in the `Account` dataclass, so `Accounts` cannot be + encoded with providing a storage root. + " in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "raw_account_data" |), "nonce" |); M.get_field (| M.get_name (| globals, "raw_account_data" |), "balance" |); M.get_name (| globals, "storage_root" |); M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_field (| M.get_name (| globals, "raw_account_data" |), "code" |) + ], + make_dict [] + |) ] + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/state.v b/CoqOfPython/ethereum/istanbul/state.v new file mode 100644 index 0000000..7b038e5 --- /dev/null +++ b/CoqOfPython/ethereum/istanbul/state.v @@ -0,0 +1,1184 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +State +^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The state contains all information that is preserved between transactions. + +It consists of a main account trie and storage tries for each contract. + +There is a distinction between an account that does not exist and +`EMPTY_ACCOUNT`. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_field : + IsGlobalAlias globals dataclasses.globals "field". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_modify : + IsGlobalAlias globals ethereum.base_types.globals "modify". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require fork_types. +Axiom fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". +Axiom fork_types_Account : + IsGlobalAlias globals fork_types.globals "Account". +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Require trie. +Axiom trie_EMPTY_TRIE_ROOT : + IsGlobalAlias globals trie.globals "EMPTY_TRIE_ROOT". +Axiom trie_Trie : + IsGlobalAlias globals trie.globals "Trie". +Axiom trie_copy_trie : + IsGlobalAlias globals trie.globals "copy_trie". +Axiom trie_root : + IsGlobalAlias globals trie.globals "root". +Axiom trie_trie_get : + IsGlobalAlias globals trie.globals "trie_get". +Axiom trie_trie_set : + IsGlobalAlias globals trie.globals "trie_set". + +Definition State : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition close_state : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Free resources held by the state. Used by optimized implementations to + release file descriptors. + " in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) |) in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |) in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |) |) in + M.pure Constant.None_)). + +Definition begin_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Start a state transaction. + + Transactions are entirely implicit and can be nested. It is not possible to + calculate the state root during a transaction. + + Parameters + ---------- + state : State + The state. + " in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), "append" |), + make_list [ + make_tuple [ M.call (| + M.get_name (| globals, "copy_trie" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) + ], + make_dict [] + |); {M.get_name (| globals, "k" |): M.call (| + M.get_name (| globals, "copy_trie" |), + make_list [ + M.get_name (| globals, "t" |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)} ] + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition commit_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Commit a state transaction. + + Parameters + ---------- + state : State + The state. + " in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), "pop" |), + make_list [], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "clear" |), + make_list [], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition rollback_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Rollback a state transaction, resetting the state to the point when the + corresponding `start_transaction()` call was made. + + Parameters + ---------- + state : State + The state. + " in + let _ := M.assign (| + make_tuple [ M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) ], + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), "pop" |), + make_list [], + make_dict [] + |) + |) in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "clear" |), + make_list [], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition get_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Get the `Account` object at an address. Returns `EMPTY_ACCOUNT` if there + is no account at the address. + + Use `get_account_optional()` if you care about the difference between a + non-existent account and `EMPTY_ACCOUNT`. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address to lookup. + + Returns + ------- + account : `Account` + Account at address. + " in + let account := + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "account" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "account" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "EMPTY_ACCOUNT" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition get_account_optional : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Get the `Account` object at an address. Returns `None` (rather than + `EMPTY_ACCOUNT`) if there is no account at the address. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address to lookup. + + Returns + ------- + account : `Account` + Account at address. + " in + let account := + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "account" |) + |) in + M.pure Constant.None_)). + +Definition set_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "account" ] |) in + let _ := Constant.str " + Set the `Account` object at an address. Setting to `None` deletes + the account (but not its storage, see `destroy_account()`). + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address to set. + account : `Account` + Account to set at address. + " in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "account" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition destroy_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Completely remove the account at `address` and all of its storage. + + This function is made available exclusively for the `SELFDESTRUCT` + opcode. It is expected that `SELFDESTRUCT` will be disabled in a future + hardfork and this function will be removed. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of account to destroy. + " in + let _ := M.call (| + M.get_name (| globals, "destroy_storage" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + Constant.None_ + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition destroy_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Completely remove the storage at `address`. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of account whose storage is to be deleted. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition mark_account_created : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Mark an account as having been created in the current transaction. + This information is used by `get_storage_original()` to handle an obscure + edgecase. + + The marker is not removed even if the account creation reverts. Since the + account cannot have had code prior to its creation and can't call + `get_storage_original()`, this is harmless. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of the account that has been created. + " in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition get_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "key" ] |) in + let _ := Constant.str " + Get a value at a storage key on an account. Returns `U256(0)` if the + storage key has not been set previously. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of the account. + key : `Bytes` + Key to lookup. + + Returns + ------- + value : `U256` + Value at the key. + " in + let trie := + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let _ := M.assert (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "U256" |) + ], + make_dict [] + |) |) in + let _ := M.return_ (| + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_)). + +Definition set_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "key"; "value" ] |) in + let _ := Constant.str " + Set a value at a storage key on an account. Setting to `U256(0)` deletes + the key. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of the account. + key : `Bytes` + Key to set. + value : `U256` + Value to set at the key. + " in + let _ := M.assert (| Compare.is_not (| M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), Constant.None_ |) |) in + let trie := + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let trie := + M.call (| + M.get_name (| globals, "Trie" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), + M.get_name (| globals, "trie" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "key" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), {} |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition storage_root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Calculate the storage root of an account. + + Parameters + ---------- + state: + The state + address : + Address of the account. + + Returns + ------- + root : `Root` + Storage root of the account. + " in + let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "EMPTY_TRIE_ROOT" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition state_root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Calculate the state root. + + Parameters + ---------- + state: + The current state. + + Returns + ------- + root : `Root` + The state root. + " in + let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition account_exists : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account exists in the state trie + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + account_exists : `bool` + True if account exists in the state trie, False otherwise + " in + let _ := M.return_ (| + Compare.is_not (| M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), Constant.None_ |) + |) in + M.pure Constant.None_)). + +Definition account_has_code_or_nonce : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account has non zero nonce or non empty code + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + has_code_or_nonce : `bool` + True if if an account has non zero nonce or non empty code, + False otherwise. + " in + let account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + BoolOp.or (| + Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |) + )) + |) + |) in + M.pure Constant.None_)). + +Definition is_account_empty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account has zero nonce, empty code and zero balance. + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + is_empty : `bool` + True if if an account has zero nonce, empty code and zero balance, + False otherwise. + " in + let account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + ltac:(M.monadic ( + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + )) + |) + )) + |) + |) in + M.pure Constant.None_)). + +Definition account_exists_and_is_empty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account exists and has zero nonce, empty code and zero + balance. + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + exists_and_is_empty : `bool` + True if an account exists and has zero nonce, empty code and zero + balance, False otherwise. + " in + let account := + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + BoolOp.and (| + Compare.is_not (| M.get_name (| globals, "account" |), Constant.None_ |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + ltac:(M.monadic ( + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + )) + |) + )) + |) + )) + |) + |) in + M.pure Constant.None_)). + +Definition is_account_alive : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Check whether is an account is both in the state and non empty. + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + is_alive : `bool` + True if the account is alive. + " in + let account := + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "account" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + UnOp.not (| BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + ltac:(M.monadic ( + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + )) + |) + )) + |) |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition modify_state : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "f" ] |) in + let _ := Constant.str " + Modify an `Account` in the `State`. + " in + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.call (| + M.get_name (| globals, "modify" |), + make_list [ + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |); + M.get_name (| globals, "f" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition move_ether : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "sender_address"; "recipient_address"; "amount" ] |) in + let _ := Constant.str " + Move funds between accounts. + " in +(* At stmt: unsupported node type: FunctionDef *) +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "sender_address" |); + M.get_name (| globals, "reduce_sender_balance" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "recipient_address" |); + M.get_name (| globals, "increase_recipient_balance" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition set_account_balance : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "amount" ] |) in + let _ := Constant.str " + Sets the balance of an account. + + Parameters + ---------- + state: + The current state. + + address: + Address of the account whose nonce needs to be incremented. + + amount: + The amount that needs to set in balance. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "set_balance" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition touch_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Initializes an account to state. + + Parameters + ---------- + state: + The current state. + + address: + The address of the account that need to initialised. + " in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "account_exists" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "EMPTY_ACCOUNT" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition increment_nonce : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Increments the nonce of an account. + + Parameters + ---------- + state: + The current state. + + address: + Address of the account whose nonce needs to be incremented. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "increase_nonce" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition set_code : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "code" ] |) in + let _ := Constant.str " + Sets Account code. + + Parameters + ---------- + state: + The current state. + + address: + Address of the account whose code needs to be update. + + code: + The bytecode that needs to be set. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "write_code" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition create_ether : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "amount" ] |) in + let _ := Constant.str " + Add newly created ether to an account. + + Parameters + ---------- + state: + The current state. + address: + Address of the account to which ether is added. + amount: + The amount of ether to be added to the account of interest. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "increase_balance" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition get_storage_original : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "key" ] |) in + let _ := Constant.str " + Get the original value in a storage slot i.e. the value before the current + transaction began. This function reads the value from the snapshots taken + before executing the transaction. + + Parameters + ---------- + state: + The current state. + address: + Address of the account to read the value from. + key: + Key of the storage slot. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "_" |); M.get_name (| globals, "original_trie" |) ], + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), Constant.int 0 |) + |) in + let original_account_trie := + M.call (| + M.get_field (| M.get_name (| globals, "original_trie" |), "get" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "original_account_trie" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let original_value := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let original_value := + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_name (| globals, "original_account_trie" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.assert (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "original_value" |); + M.get_name (| globals, "U256" |) + ], + make_dict [] + |) |) in + let _ := M.return_ (| + M.get_name (| globals, "original_value" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/transactions.v b/CoqOfPython/ethereum/istanbul/transactions.v new file mode 100644 index 0000000..f94a3bd --- /dev/null +++ b/CoqOfPython/ethereum/istanbul/transactions.v @@ -0,0 +1,60 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Transactions are atomic units of work created externally to Ethereum and +submitted to be executed. If Ethereum is viewed as a state machine, +transactions are the events that move between states. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes0 : + IsGlobalAlias globals base_types.globals "Bytes0". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( + Constant.int 21000 +)). + +Definition TX_DATA_COST_PER_NON_ZERO : Value.t := M.run ltac:(M.monadic ( + Constant.int 16 +)). + +Definition TX_DATA_COST_PER_ZERO : Value.t := M.run ltac:(M.monadic ( + Constant.int 4 +)). + +Definition TX_CREATE_COST : Value.t := M.run ltac:(M.monadic ( + Constant.int 32000 +)). + +Definition Transaction : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. diff --git a/CoqOfPython/ethereum/istanbul/trie.v b/CoqOfPython/ethereum/istanbul/trie.v new file mode 100644 index 0000000..3246619 --- /dev/null +++ b/CoqOfPython/ethereum/istanbul/trie.v @@ -0,0 +1,1357 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +State Trie +^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The state trie is the structure responsible for storing +`.fork_types.Account` objects. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_field : + IsGlobalAlias globals dataclasses.globals "field". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". +Axiom typing_Generic : + IsGlobalAlias globals typing.globals "Generic". +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Mapping : + IsGlobalAlias globals typing.globals "Mapping". +Axiom typing_MutableMapping : + IsGlobalAlias globals typing.globals "MutableMapping". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Sequence : + IsGlobalAlias globals typing.globals "Sequence". +Axiom typing_TypeVar : + IsGlobalAlias globals typing.globals "TypeVar". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". +Axiom typing_cast : + IsGlobalAlias globals typing.globals "cast". + +Require ethereum.constantinople. +Axiom ethereum_constantinople_trie : + IsGlobalAlias globals ethereum.constantinople.globals "trie". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require ethereum.utils.hexadecimal. +Axiom ethereum_utils_hexadecimal_hex_to_bytes : + IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require blocks. +Axiom blocks_Receipt : + IsGlobalAlias globals blocks.globals "Receipt". + +Require fork_types. +Axiom fork_types_Account : + IsGlobalAlias globals fork_types.globals "Account". +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". +Axiom fork_types_encode_account : + IsGlobalAlias globals fork_types.globals "encode_account". + +Require transactions. +Axiom transactions_Transaction : + IsGlobalAlias globals transactions.globals "Transaction". + +Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Root" |), + make_list [ + M.call (| + M.get_name (| globals, "hex_to_bytes" |), + make_list [ + Constant.str "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" + ], + make_dict [] + |) + ], + make_dict [] + |) +)). + +Definition Node : Value.t := M.run ltac:(M.monadic ( + M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Bytes" |); M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |); Constant.None_ ] |) +)). + +Definition K : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "TypeVar" |), + make_list [ + Constant.str "K" + ], + make_dict [] + |) +)). + +Definition V : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "TypeVar" |), + make_list [ + Constant.str "V"; + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Account" |) |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Bytes" |) |); + M.get_name (| globals, "Bytes" |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Transaction" |) |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Receipt" |) |); + M.get_name (| globals, "Uint" |); + M.get_name (| globals, "U256" |) + ], + make_dict [] + |) +)). + +Definition LeafNode : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition ExtensionNode : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition BranchNode : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition InternalNode : Value.t := M.run ltac:(M.monadic ( + M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LeafNode" |); M.get_name (| globals, "ExtensionNode" |); M.get_name (| globals, "BranchNode" |) ] |) +)). + +Definition encode_internal_node : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "node" ] |) in + let _ := Constant.str " + Encodes a Merkle Trie node into its RLP form. The RLP will then be + serialized into a `Bytes` and hashed unless it is less that 32 bytes + when serialized. + + This function also accepts `None`, representing the absence of a node, + which is encoded to `b""""""`. + + Parameters + ---------- + node : Optional[InternalNode] + The node to encode. + + Returns + ------- + encoded : `rlp.RLP` + The node encoded as RLP. + " in +(* At stmt: unsupported node type: AnnAssign *) + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "node" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let unencoded := + (* At constant: unsupported node type: Constant *) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "LeafNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "rest_of_key" |); + Constant.bool true + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "ExtensionNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "key_segment" |); + Constant.bool false + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "BranchNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + BinOp.add (| + M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "value" |) + ] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "AssertionError" |), + make_list [ + (* At expr: unsupported node type: JoinedStr *) + ], + make_dict [] + |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let encoded := + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "unencoded" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded" |) + ], + make_dict [] + |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "unencoded" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "encoded" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition encode_node : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "node"; "storage_root" ] |) in + let _ := Constant.str " + Encode a Node for storage in the Merkle Trie. + + Currently mostly an unimplemented stub. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "storage_root" |), Constant.None_ |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "encode_account" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "storage_root" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + make_tuple [ M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "U256" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "cast" |), + make_list [ + M.get_field (| M.get_name (| globals, "rlp" |), "RLP" |); + M.get_name (| globals, "node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "node" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "previous_trie" |), "encode_node" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "storage_root" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition Trie : Value.t := + builtins.make_klass + [(* At base: unsupported node type: Subscript *)] + [ + + ] + [ + + ]. + +Definition copy_trie : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie" ] |) in + let _ := Constant.str " + Create a copy of `trie`. Since only frozen objects may be stored in tries, + the contents are reused. + + Parameters + ---------- + trie: `Trie` + Trie to copy. + + Returns + ------- + new_trie : `Trie[K, V]` + A copy of the trie. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Trie" |), + make_list [ + M.get_field (| M.get_name (| globals, "trie" |), "secured" |); + M.get_field (| M.get_name (| globals, "trie" |), "default" |); + M.call (| + M.get_field (| M.get_name (| globals, "copy" |), "copy" |), + make_list [ + M.get_field (| M.get_name (| globals, "trie" |), "_data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition trie_set : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "key"; "value" ] |) in + let _ := Constant.str " + Stores an item in a Merkle Trie. + + This method deletes the key if `value == trie.default`, because the Merkle + Trie represents the default value by omitting it from the trie. + + Parameters + ---------- + trie: `Trie` + Trie to store in. + key : `Bytes` + Key to lookup. + value : `V` + Node to insert at `key`. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "value" |), M.get_field (| M.get_name (| globals, "trie" |), "default" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "key" |), M.get_field (| M.get_name (| globals, "trie" |), "_data" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition trie_get : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "key" ] |) in + let _ := Constant.str " + Gets an item from the Merkle Trie. + + This method returns `trie.default` if the key is missing. + + Parameters + ---------- + trie: + Trie to lookup in. + key : + Key to lookup. + + Returns + ------- + node : `V` + Node at `key` in the trie. + " in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "get" |), + make_list [ + M.get_name (| globals, "key" |); + M.get_field (| M.get_name (| globals, "trie" |), "default" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition common_prefix_length : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "a"; "b" ] |) in + let _ := Constant.str " + Find the longest common prefix of two sequences. + " in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + ], + make_dict [] + |) do + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| M.get_name (| globals, "i" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition nibble_list_to_compact : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "x"; "is_leaf" ] |) in + let _ := Constant.str " + Compresses nibble-list into a standard byte array with a flag. + + A nibble-list is a list of byte values no greater than `15`. The flag is + encoded in high nibble of the highest byte. The flag nibble can be broken + down into two two-bit flags. + + Highest nibble:: + + +---+---+----------+--------+ + | _ | _ | is_leaf | parity | + +---+---+----------+--------+ + 3 2 1 0 + + + The lowest bit of the nibble encodes the parity of the length of the + remaining nibbles -- `0` when even and `1` when odd. The second lowest bit + is used to distinguish leaf and extension nodes. The other two bits are not + used. + + Parameters + ---------- + x : + Array of nibbles. + is_leaf : + True if this is part of a leaf node, or false if it is an extension + node. + + Returns + ------- + compressed : `bytearray` + Compact byte array. + " in + let compact := + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + Constant.int 2 + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.mult (| + Constant.int 16, + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "is_leaf" |) + |) + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + BinOp.add (| + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "is_leaf" |) + |), + Constant.int 1 + |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), Constant.int 0 |) + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 1; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + M.get_name (| globals, "compact" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition bytes_to_nibble_list : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "bytes_" ] |) in + let _ := Constant.str " + Converts a `Bytes` into to a sequence of nibbles (bytes with value < 16). + + Parameters + ---------- + bytes_: + The `Bytes` to convert. + + Returns + ------- + nibble_list : `Bytes` + The `Bytes` in nibble-list format. + " in + let nibble_list := + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [ + BinOp.mult (| + Constant.int 2, + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "bytes_" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + For make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ] in M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "bytes_" |) + ], + make_dict [] + |) do + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |) |), + BinOp.r_shift (| + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 240 + |), + Constant.int 4 + |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |), + Constant.int 1 + |) |), + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 15 + |) + |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + M.get_name (| globals, "nibble_list" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition _prepare_trie : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "get_storage_root" ] |) in + let _ := Constant.str " + Prepares the trie for root calculation. Removes values that are empty, + hashes the keys (if `secured == True`) and encodes all the nodes. + + Parameters + ---------- + trie : + The `Trie` to prepare. + get_storage_root : + Function to get the storage root of an account. Needed to encode + `Account` objects. + + Returns + ------- + out : `Mapping[ethereum.base_types.Bytes, Node]` + Object with keys mapped to nibble-byte form. + " in +(* At stmt: unsupported node type: AnnAssign *) + For make_tuple [ M.get_name (| globals, "preimage" |); M.get_name (| globals, "value" |) ] in M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "items" |), + make_list [], + make_dict [] + |) do + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in + let address := + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |); + M.call (| + M.get_name (| globals, "get_storage_root" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_eq (| M.get_name (| globals, "encoded_value" |), (* At constant: unsupported node type: Constant *) |); + M.get_name (| globals, "AssertionError" |) + ], + make_dict [] + |) in +(* At stmt: unsupported node type: AnnAssign *) + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "trie" |), "secured" |), + (* then *) + ltac:(M.monadic ( + let key := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let key := + M.get_name (| globals, "preimage" |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "mapped" |), M.call (| + M.get_name (| globals, "bytes_to_nibble_list" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |) |), + M.get_name (| globals, "encoded_value" |) + |) in + EndFor. + let _ := M.return_ (| + M.get_name (| globals, "mapped" |) + |) in + M.pure Constant.None_)). + +Definition root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "get_storage_root" ] |) in + let _ := Constant.str " + Computes the root of a modified merkle patricia trie (MPT). + + Parameters + ---------- + trie : + `Trie` to get the root of. + get_storage_root : + Function to get the storage root of an account. Needed to encode + `Account` objects. + + + Returns + ------- + root : `.fork_types.Root` + MPT root of the underlying key-value pairs. + " in + let obj := + M.call (| + M.get_name (| globals, "_prepare_trie" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "get_storage_root" |) + ], + make_dict [] + |) in + let root_node := + M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_name (| globals, "obj" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assert (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "root_node" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Root" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition patricialize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "obj"; "level" ] |) in + let _ := Constant.str " + Structural composition function. + + Used to recursively patricialize and merkleize a dictionary. Includes + memoization of the tree structure and hashes. + + Parameters + ---------- + obj : + Underlying trie key-value pairs, with keys in nibble-list format. + level : + Current trie level. + + Returns + ------- + node : `ethereum.base_types.Bytes` + Root node of `obj`. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let arbitrary_key := + M.call (| + M.get_name (| globals, "next" |), + make_list [ + M.call (| + M.get_name (| globals, "iter" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), Constant.int 1 |), + (* then *) + ltac:(M.monadic ( + let leaf := + M.call (| + M.get_name (| globals, "LeafNode" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |); + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "leaf" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let substring := + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) in + let prefix_length := + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "substring" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do + let prefix_length := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_name (| globals, "prefix_length" |); + M.call (| + M.get_name (| globals, "common_prefix_length" |), + make_list [ + M.get_name (| globals, "substring" |); + M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let prefix := + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ExtensionNode" |), + make_list [ + M.get_name (| globals, "prefix" |); + M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_name (| globals, "obj" |); + BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in +(* At stmt: unsupported node type: AnnAssign *) + For M.get_name (| globals, "_" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 16 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "branches" |), "append" |), + make_list [ + {} + ], + make_dict [] + |) in + EndFor. + let value := + (* At constant: unsupported node type: Constant *) in + For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |), M.get_name (| globals, "level" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "AssertionError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) + |) in + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "BranchNode" |), + make_list [ + [M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "branches" |), M.get_name (| globals, "k" |) |); + BinOp.add (| + M.get_name (| globals, "level" |), + Constant.int 1 + |) + ], + make_dict [] + |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)]; + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/utils/__init__.v b/CoqOfPython/ethereum/istanbul/utils/__init__.v new file mode 100644 index 0000000..1baedea --- /dev/null +++ b/CoqOfPython/ethereum/istanbul/utils/__init__.v @@ -0,0 +1,8 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Utility functions unique to this particular fork. +". diff --git a/CoqOfPython/ethereum/istanbul/utils/address.v b/CoqOfPython/ethereum/istanbul/utils/address.v new file mode 100644 index 0000000..22dc0b6 --- /dev/null +++ b/CoqOfPython/ethereum/istanbul/utils/address.v @@ -0,0 +1,204 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Hardfork Utility Functions For Addresses +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Address specific functions used in this istanbul version of +specification. +". + +Require typing. +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_left_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Definition to_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "data" ] |) in + let _ := Constant.str " + Convert a Uint or U256 value to a valid address (20 bytes). + + Parameters + ---------- + data : + The string to be converted to bytes. + + Returns + ------- + address : `Address` + The obtained address. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_subscript (| M.call (| + M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition compute_contract_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "address"; "nonce" ] |) in + let _ := Constant.str " + Computes address of the new account that needs to be created. + + Parameters + ---------- + address : + The address of the account that wants to create the new account. + nonce : + The transaction count of the account that wants to create the new + account. + + Returns + ------- + address: `Address` + The computed address of the new account. + " in + let computed_address := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_list [ + M.get_name (| globals, "address" |); + M.get_name (| globals, "nonce" |) + ] + ], + make_dict [] + |) + ], + make_dict [] + |) in + let canonical_address := + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + let padded_address := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "canonical_address" |); + Constant.int 20 + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "padded_address" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition compute_create2_contract_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "address"; "salt"; "call_data" ] |) in + let _ := Constant.str " + Computes address of the new account that needs to be created, which is + based on the sender address, salt and the call data as well. + + Parameters + ---------- + address : + The address of the account that wants to create the new account. + salt : + Address generation salt. + call_data : + The code of the new account which is to be created. + + Returns + ------- + address: `ethereum.istanbul.fork_types.Address` + The computed address of the new account. + " in + let preimage := + BinOp.add (| + BinOp.add (| + BinOp.add (| + (* At constant: unsupported node type: Constant *), + M.get_name (| globals, "address" |) + |), + M.get_name (| globals, "salt" |) + |), + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "call_data" |) + ], + make_dict [] + |) + |) in + let computed_address := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + let canonical_address := + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + let padded_address := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "canonical_address" |); + Constant.int 20 + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "padded_address" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/utils/hexadecimal.v b/CoqOfPython/ethereum/istanbul/utils/hexadecimal.v new file mode 100644 index 0000000..0a09964 --- /dev/null +++ b/CoqOfPython/ethereum/istanbul/utils/hexadecimal.v @@ -0,0 +1,155 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Utility Functions For Hexadecimal Strings +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Hexadecimal utility functions used in this specification, specific to +Istanbul types. +". + +Require ethereum.utils.hexadecimal. +Axiom ethereum_utils_hexadecimal_remove_hex_prefix : + IsGlobalAlias globals ethereum.utils.hexadecimal.globals "remove_hex_prefix". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Definition hex_to_root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to trie root. + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to trie root. + + Returns + ------- + root : `Root` + Trie root obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Root" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition hex_to_bloom : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to bloom. + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to bloom. + + Returns + ------- + bloom : `Bloom` + Bloom obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bloom" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition hex_to_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to Address (20 bytes). + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to Address. + + Returns + ------- + address : `Address` + The address obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |), "rjust" |), + make_list [ + Constant.int 40; + Constant.str "0" + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/utils/message.v b/CoqOfPython/ethereum/istanbul/utils/message.v new file mode 100644 index 0000000..3a425ec --- /dev/null +++ b/CoqOfPython/ethereum/istanbul/utils/message.v @@ -0,0 +1,201 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Hardfork Utility Functions For The Message Data-structure +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Message specific functions used in this istanbul version of +specification. +". + +Require typing. +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". + +Require vm. +Axiom vm_Environment : + IsGlobalAlias globals vm.globals "Environment". +Axiom vm_Message : + IsGlobalAlias globals vm.globals "Message". + +Require address. +Axiom address_compute_contract_address : + IsGlobalAlias globals address.globals "compute_contract_address". + +Definition prepare_message : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "caller"; "target"; "value"; "data"; "gas"; "env"; "code_address"; "should_transfer_value"; "is_static" ] |) in + let _ := Constant.str " + Execute a transaction against the provided environment. + + Parameters + ---------- + caller : + Address which initiated the transaction + target : + Address whose code will be executed + value : + Value to be transferred. + data : + Array of bytes provided to the code in `target`. + gas : + Gas provided for the code in `target`. + env : + Environment for the Ethereum Virtual Machine. + code_address : + This is usually same as the `target` address except when an alternative + accounts code needs to be executed. + eg. `CALLCODE` calling a precompile. + should_transfer_value : + if True ETH should be transferred while executing a message call. + is_static: + if True then it prevents all state-changing operations from being + executed. + + Returns + ------- + message: `ethereum.istanbul.vm.Message` + Items containing contract creation or message call specific data. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Bytes0" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.call (| + M.get_name (| globals, "compute_contract_address" |), + make_list [ + M.get_name (| globals, "caller" |); + BinOp.sub (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "caller" |) + ], + make_dict [] + |), "nonce" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let msg_data := + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |) in + let code := + M.get_name (| globals, "data" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.get_name (| globals, "target" |) in + let msg_data := + M.get_name (| globals, "data" |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "target" |) + ], + make_dict [] + |), "code" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "code_address" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let code_address := + M.get_name (| globals, "target" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "AssertionError" |), + make_list [ + Constant.str "Target must be address or empty bytes" + ], + make_dict [] + |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/vm/__init__.v b/CoqOfPython/ethereum/istanbul/vm/__init__.v new file mode 100644 index 0000000..d408aed --- /dev/null +++ b/CoqOfPython/ethereum/istanbul/vm/__init__.v @@ -0,0 +1,246 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The abstract computer which runs the code stored in an +`.fork_types.Account`. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U64 : + IsGlobalAlias globals ethereum.base_types.globals "U64". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_State : + IsGlobalAlias globals state.globals "State". +Axiom state_account_exists_and_is_empty : + IsGlobalAlias globals state.globals "account_exists_and_is_empty". + +Require precompiled_contracts. +Axiom precompiled_contracts_RIPEMD160_ADDRESS : + IsGlobalAlias globals precompiled_contracts.globals "RIPEMD160_ADDRESS". + +Definition __all__ : Value.t := M.run ltac:(M.monadic ( + make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] +)). + +Definition Environment : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Message : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Evm : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition incorporate_child_on_success : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "child_evm" ] |) in + let _ := Constant.str " + Incorporate the state of a successful `child_evm` into the parent `evm`. + + Parameters + ---------- + evm : + The parent `EVM`. + child_evm : + The child evm to incorporate. + " in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "gas_left" |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "logs" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "logs" |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "refund_counter" |) + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "accounts_to_delete" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition incorporate_child_on_error : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "child_evm" ] |) in + let _ := Constant.str " + Incorporate the state of an unsuccessful `child_evm` into the parent `evm`. + + Parameters + ---------- + evm : + The parent `EVM`. + child_evm : + The child evm to incorporate. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "RIPEMD160_ADDRESS" |), M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |), M.get_name (| globals, "RIPEMD160_ADDRESS" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "gas_left" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/vm/exceptions.v b/CoqOfPython/ethereum/istanbul/vm/exceptions.v new file mode 100644 index 0000000..8560cef --- /dev/null +++ b/CoqOfPython/ethereum/istanbul/vm/exceptions.v @@ -0,0 +1,162 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Exceptions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Exceptions which cause the EVM to halt exceptionally. +". + +Require ethereum.exceptions. +Axiom ethereum_exceptions_EthereumException : + IsGlobalAlias globals ethereum.exceptions.globals "EthereumException". + +Definition ExceptionalHalt : Value.t := + builtins.make_klass + [(globals, "EthereumException")] + [ + + ] + [ + + ]. + +Definition Revert : Value.t := + builtins.make_klass + [(globals, "EthereumException")] + [ + + ] + [ + + ]. + +Definition StackUnderflowError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition StackOverflowError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition OutOfGasError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition InvalidOpcode : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + ( + "__init__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "code" ] |) in + let _ := M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "super" |), + make_list [], + make_dict [] + |), "__init__" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "self" |), "code" |), + M.get_name (| globals, "code" |) + |) in + M.pure Constant.None_)) + ) + ]. + +Definition InvalidJumpDestError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition StackDepthLimitError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition WriteInStaticContext : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition OutOfBoundsRead : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition InvalidParameter : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition AddressCollision : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/__init__.v b/CoqOfPython/ethereum/istanbul/vm/instructions/__init__.v new file mode 100644 index 0000000..e5bebd7 --- /dev/null +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/__init__.v @@ -0,0 +1,87 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +EVM Instruction Encoding (Opcodes) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Machine readable representations of EVM instructions, and a mapping to their +implementations. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". + +Require __init__. +Axiom __init___arithmetic : + IsGlobalAlias globals __init__.globals "arithmetic". + +Require __init__. +Axiom __init___bitwise : + IsGlobalAlias globals __init__.globals "bitwise". + +Require __init__. +Axiom __init___block : + IsGlobalAlias globals __init__.globals "block". + +Require __init__. +Axiom __init___comparison : + IsGlobalAlias globals __init__.globals "comparison". + +Require __init__. +Axiom __init___control_flow : + IsGlobalAlias globals __init__.globals "control_flow". + +Require __init__. +Axiom __init___environment : + IsGlobalAlias globals __init__.globals "environment". + +Require __init__. +Axiom __init___keccak : + IsGlobalAlias globals __init__.globals "keccak". + +Require __init__. +Axiom __init___log : + IsGlobalAlias globals __init__.globals "log". + +Require __init__. +Axiom __init___memory : + IsGlobalAlias globals __init__.globals "memory". + +Require __init__. +Axiom __init___stack : + IsGlobalAlias globals __init__.globals "stack". + +Require __init__. +Axiom __init___storage : + IsGlobalAlias globals __init__.globals "storage". + +Require __init__. +Axiom __init___system : + IsGlobalAlias globals __init__.globals "system". + +Definition Ops : Value.t := + builtins.make_klass + [(* At base: unsupported node type: Attribute *)] + [ + + ] + [ + + ]. + +(* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/istanbul/vm/instructions/arithmetic.v new file mode 100644 index 0000000..a8b5c61 --- /dev/null +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/arithmetic.v @@ -0,0 +1,1085 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Arithmetic Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM Arithmetic instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U255_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U255_CEIL_VALUE". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_U256_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_get_sign : + IsGlobalAlias globals ethereum.utils.numeric.globals "get_sign". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_EXPONENTIATION : + IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION". +Axiom gas_GAS_EXPONENTIATION_PER_BYTE : + IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION_PER_BYTE". +Axiom gas_GAS_LOW : + IsGlobalAlias globals gas.globals "GAS_LOW". +Axiom gas_GAS_MID : + IsGlobalAlias globals gas.globals "GAS_MID". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition add : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Adds the top two elements of the stack together, and pushes the result back + on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "x" |), "wrapping_add" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition sub : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Subtracts the top two elements of the stack, and pushes the result back + on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "x" |), "wrapping_sub" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mul : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Multiply the top two elements of the stack, and pushes the result back + on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "x" |), "wrapping_mul" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition div : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Integer division of the top two elements of the stack. Pushes the result + back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let dividend := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let divisor := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let quotient := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let quotient := + BinOp.floor_div (| + M.get_name (| globals, "dividend" |), + M.get_name (| globals, "divisor" |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "quotient" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition sdiv : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed integer division of the top two elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let dividend := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let divisor := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let quotient := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_name (| globals, "dividend" |), UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "divisor" |), UnOp.sub (| Constant.int 1 |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let quotient := + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let sign := + M.call (| + M.get_name (| globals, "get_sign" |), + make_list [ + BinOp.mult (| + M.get_name (| globals, "dividend" |), + M.get_name (| globals, "divisor" |) + |) + ], + make_dict [] + |) in + let quotient := + BinOp.mult (| + M.get_name (| globals, "sign" |), + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "dividend" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "divisor" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + M.get_name (| globals, "quotient" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Modulo remainder of the top two elements of the stack. Pushes the result + back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let remainder := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let remainder := + BinOp.mod_ (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "remainder" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition smod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed modulo remainder of the top two elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let y := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let remainder := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let remainder := + BinOp.mult (| + M.call (| + M.get_name (| globals, "get_sign" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + BinOp.mod_ (| + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + M.get_name (| globals, "remainder" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition addmod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Modulo addition of the top 2 elements with the 3rd element. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let z := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_MID" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.add (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |), + M.get_name (| globals, "z" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mulmod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Modulo multiplication of the top 2 elements with the 3rd element. Pushes + the result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let z := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_MID" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.mult (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |), + M.get_name (| globals, "z" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition exp : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Exponential operation of the top 2 elements. Pushes the result back on + the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let base := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exponent := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exponent_bits := + M.call (| + M.get_field (| M.get_name (| globals, "exponent" |), "bit_length" |), + make_list [], + make_dict [] + |) in + let exponent_bytes := + BinOp.floor_div (| + BinOp.add (| + M.get_name (| globals, "exponent_bits" |), + Constant.int 7 + |), + Constant.int 8 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_EXPONENTIATION" |), + BinOp.mult (| + M.get_name (| globals, "GAS_EXPONENTIATION_PER_BYTE" |), + M.get_name (| globals, "exponent_bytes" |) + |) + |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "pow" |), + make_list [ + M.get_name (| globals, "base" |); + M.get_name (| globals, "exponent" |); + M.get_name (| globals, "U256_CEIL_VALUE" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition signextend : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Sign extend operation. In other words, extend a signed number which + fits in N bytes to 32 bytes. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let byte_num := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "byte_num" |), Constant.int 31 |), + (* then *) + ltac:(M.monadic ( + let result := + M.get_name (| globals, "value" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let value_bytes := + M.call (| + M.get_name (| globals, "bytes" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "value" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) in + let value_bytes := + M.get_subscript (| M.get_name (| globals, "value_bytes" |), BinOp.sub (| + Constant.int 31, + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "byte_num" |) + ], + make_dict [] + |) + |):(* At expr: unsupported node type: NoneType *) |) in + let sign_bit := + BinOp.r_shift (| + M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), + Constant.int 7 + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "sign_bit" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "value_bytes" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let num_bytes_prepend := + BinOp.sub (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "byte_num" |), + Constant.int 1 + |) + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + BinOp.add (| + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [ + BinOp.mult (| + make_list [ + Constant.int 255 + ], + M.get_name (| globals, "num_bytes_prepend" |) + |) + ], + make_dict [] + |), + M.get_name (| globals, "value_bytes" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/bitwise.v b/CoqOfPython/ethereum/istanbul/vm/instructions/bitwise.v new file mode 100644 index 0000000..9f2f382 --- /dev/null +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/bitwise.v @@ -0,0 +1,601 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Bitwise Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM bitwise instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_U256_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition bitwise_and : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise AND operation of the top 2 elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + BinOp.bit_and (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_or : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise OR operation of the top 2 elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + BinOp.bit_or (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_xor : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise XOR operation of the top 2 elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + BinOp.bit_xor (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_not : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise NOT operation of the top element of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + UnOp.invert (| M.get_name (| globals, "x" |) |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition get_byte : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + For a word (defined by next top element of the stack), retrieve the + Nth byte (0-indexed and defined by top element of stack) from the + left (most significant) to right (least significant). + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let byte_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let word := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "byte_index" |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let extra_bytes_to_right := + BinOp.sub (| + Constant.int 31, + M.get_name (| globals, "byte_index" |) + |) in + let word := + BinOp.r_shift (| + M.get_name (| globals, "word" |), + BinOp.mult (| + M.get_name (| globals, "extra_bytes_to_right" |), + Constant.int 8 + |) + |) in + let word := + BinOp.bit_and (| + M.get_name (| globals, "word" |), + Constant.int 255 + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "word" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_shl : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Logical shift left (SHL) operation of the top 2 elements of the stack. + Pushes the result back on the stack. + Parameters + ---------- + evm : + The current EVM frame. + " in + let shift := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.l_shift (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "shift" |) + |), + M.get_name (| globals, "U256_CEIL_VALUE" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_shr : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Logical shift right (SHR) operation of the top 2 elements of the stack. + Pushes the result back on the stack. + Parameters + ---------- + evm : + The current EVM frame. + " in + let shift := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), + (* then *) + ltac:(M.monadic ( + let result := + BinOp.r_shift (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "shift" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_sar : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Arithmetic shift right (SAR) operation of the top 2 elements of the stack. + Pushes the result back on the stack. + Parameters + ---------- + evm : + The current EVM frame. + " in + let shift := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let signed_value := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + BinOp.r_shift (| + M.get_name (| globals, "signed_value" |), + M.get_name (| globals, "shift" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "signed_value" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/block.v b/CoqOfPython/ethereum/istanbul/vm/instructions/block.v new file mode 100644 index 0000000..26c73a7 --- /dev/null +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/block.v @@ -0,0 +1,379 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Block Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM block instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_BLOCK_HASH : + IsGlobalAlias globals gas.globals "GAS_BLOCK_HASH". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition block_hash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the hash of one of the 256 most recent complete blocks onto the + stack. The block number to hash is present at the top of the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let block_number := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BLOCK_HASH" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt_e (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), M.get_name (| globals, "block_number" |) |), + ltac:(M.monadic ( + Compare.gt (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), BinOp.add (| + M.get_name (| globals, "block_number" |), + Constant.int 256 + |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let hash := + (* At constant: unsupported node type: Constant *) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let hash := + M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + M.get_name (| globals, "block_number" |) + |) |) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "hash" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition coinbase : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's beneficiary address (address of the block miner) + onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "coinbase" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition timestamp : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's timestamp onto the stack. Here the timestamp + being referred is actually the unix timestamp in seconds. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "time" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition number : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's number onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition difficulty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's difficulty onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "difficulty" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition gas_limit : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's gas limit onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "gas_limit" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition chain_id : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the chain id onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "chain_id" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/comparison.v b/CoqOfPython/ethereum/istanbul/vm/instructions/comparison.v new file mode 100644 index 0000000..fbc35f8 --- /dev/null +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/comparison.v @@ -0,0 +1,404 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Comparison Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM Comparison instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition less_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is less than the next top element. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let right := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition signed_less_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed less-than comparison. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let right := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition greater_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is greater than the next top element. Pushes + the result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let right := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition signed_greater_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed greater-than comparison. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let right := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition equal : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is equal to the next top element. Pushes + the result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let right := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.eq (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition is_zero : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is equal to 0. Pushes the result back on the + stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.eq (| M.get_name (| globals, "x" |), Constant.int 0 |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/control_flow.v b/CoqOfPython/ethereum/istanbul/vm/instructions/control_flow.v new file mode 100644 index 0000000..04a79d9 --- /dev/null +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/control_flow.v @@ -0,0 +1,336 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Control Flow Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM control flow instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require vm.gas. +Axiom vm_gas_GAS_BASE : + IsGlobalAlias globals vm.gas.globals "GAS_BASE". +Axiom vm_gas_GAS_HIGH : + IsGlobalAlias globals vm.gas.globals "GAS_HIGH". +Axiom vm_gas_GAS_JUMPDEST : + IsGlobalAlias globals vm.gas.globals "GAS_JUMPDEST". +Axiom vm_gas_GAS_MID : + IsGlobalAlias globals vm.gas.globals "GAS_MID". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_InvalidJumpDestError : + IsGlobalAlias globals exceptions.globals "InvalidJumpDestError". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition stop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stop further execution of EVM code. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let _ := M.pass (| |) in + let _ := M.pass (| |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "running" |), + Constant.bool false + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition jump : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Alter the program counter to the location specified by the top of the + stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let jump_dest := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_MID" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "jump_dest" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition jumpi : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Alter the program counter to the specified location if and only if a + condition is true. If the condition is not true, then the program counter + would increase only by 1. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let jump_dest := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let conditional_value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_HIGH" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "conditional_value" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let destination := + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let destination := + M.get_name (| globals, "jump_dest" |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "destination" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition pc : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push onto the stack the value of the program counter after reaching the + current instruction and without increasing it for the next instruction. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "pc" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition gas_left : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the amount of available gas (including the corresponding reduction + for the cost of this instruction) onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition jumpdest : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Mark a valid destination for jumps. This is a noop, present only + to be used by `JUMP` and `JUMPI` opcodes to verify that their jump is + valid. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_JUMPDEST" |) + ], + make_dict [] + |) in + let _ := M.pass (| |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/environment.v b/CoqOfPython/ethereum/istanbul/vm/instructions/environment.v new file mode 100644 index 0000000..d9b3151 --- /dev/null +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/environment.v @@ -0,0 +1,1286 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Environmental Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM environment related instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require fork_types. +Axiom fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". + +Require state. +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". + +Require utils.address. +Axiom utils_address_to_address : + IsGlobalAlias globals utils.address.globals "to_address". + +Require vm.memory. +Axiom vm_memory_buffer_read : + IsGlobalAlias globals vm.memory.globals "buffer_read". +Axiom vm_memory_memory_write : + IsGlobalAlias globals vm.memory.globals "memory_write". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_OutOfBoundsRead : + IsGlobalAlias globals exceptions.globals "OutOfBoundsRead". + +Require gas. +Axiom gas_GAS_BALANCE : + IsGlobalAlias globals gas.globals "GAS_BALANCE". +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_CODE_HASH : + IsGlobalAlias globals gas.globals "GAS_CODE_HASH". +Axiom gas_GAS_COPY : + IsGlobalAlias globals gas.globals "GAS_COPY". +Axiom gas_GAS_EXTERNAL : + IsGlobalAlias globals gas.globals "GAS_EXTERNAL". +Axiom gas_GAS_FAST_STEP : + IsGlobalAlias globals gas.globals "GAS_FAST_STEP". +Axiom gas_GAS_RETURN_DATA_COPY : + IsGlobalAlias globals gas.globals "GAS_RETURN_DATA_COPY". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the address of the current executing account to the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition balance : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the balance of the given account onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BALANCE" |) + ], + make_dict [] + |) in + let balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "balance" |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "balance" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition origin : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the address of the original transaction sender to the stack. + The origin address can only be an EOA. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "origin" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition caller : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the address of the caller onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "caller" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition callvalue : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the value (in wei) sent with the call onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition calldataload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push a word (32 bytes) of the input data belonging to the current + environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |); + M.get_name (| globals, "start_index" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition calldatasize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the size of input data in current environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition calldatacopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy a portion of the input data in current environment to memory. + + This will also expand the memory, in case that the memory is insufficient + to store the data. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let data_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |); + M.get_name (| globals, "data_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition codesize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the size of code running in current environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "code" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition codecopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy a portion of the code in current environment to memory. + + This will also expand the memory, in case that the memory is insufficient + to store the data. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let code_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "code" |); + M.get_name (| globals, "code_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition gasprice : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the gas price used in current environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "gas_price" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition extcodesize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the code size of a given account onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_EXTERNAL" |) + ], + make_dict [] + |) in + let codesize := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "code" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "codesize" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition extcodecopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy a portion of an account's code to memory. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let code_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_EXTERNAL" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "code" |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "code" |); + M.get_name (| globals, "code_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition returndatasize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the size of the return data buffer onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition returndatacopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copies data from the return data buffer code to memory + + Parameters + ---------- + evm : + The current EVM frame. + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let return_data_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_RETURN_DATA_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "return_data_start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "OutOfBoundsRead" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |):BinOp.add (| + M.get_name (| globals, "return_data_start_position" |), + M.get_name (| globals, "size" |) + |) |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition extcodehash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Returns the keccak256 hash of a contract’s bytecode + Parameters + ---------- + evm : + The current EVM frame. + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_CODE_HASH" |) + ], + make_dict [] + |) in + let account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "account" |), M.get_name (| globals, "EMPTY_ACCOUNT" |) |), + (* then *) + ltac:(M.monadic ( + let codehash := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let codehash := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_field (| M.get_name (| globals, "account" |), "code" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "codehash" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition self_balance : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the balance of the current address to the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_FAST_STEP" |) + ], + make_dict [] + |) in + let balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "balance" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/keccak.v b/CoqOfPython/ethereum/istanbul/vm/instructions/keccak.v new file mode 100644 index 0000000..cab9ffb --- /dev/null +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/keccak.v @@ -0,0 +1,181 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Keccak Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM keccak instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_KECCAK256 : + IsGlobalAlias globals gas.globals "GAS_KECCAK256". +Axiom gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition keccak : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes to the stack the Keccak-256 hash of a region of memory. + + This also expands the memory, in case the memory is insufficient to + access the data's memory location. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let word_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_KECCAK256_WORD" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_KECCAK256" |), + M.get_name (| globals, "word_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let data := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "hash" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/log.v b/CoqOfPython/ethereum/istanbul/vm/instructions/log.v new file mode 100644 index 0000000..4891a4d --- /dev/null +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/log.v @@ -0,0 +1,244 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Logging Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM logging instructions. +". + +Require functools. +Axiom functools_partial : + IsGlobalAlias globals functools.globals "partial". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_WriteInStaticContext : + IsGlobalAlias globals exceptions.globals "WriteInStaticContext". + +Require gas. +Axiom gas_GAS_LOG : + IsGlobalAlias globals gas.globals "GAS_LOG". +Axiom gas_GAS_LOG_DATA : + IsGlobalAlias globals gas.globals "GAS_LOG_DATA". +Axiom gas_GAS_LOG_TOPIC : + IsGlobalAlias globals gas.globals "GAS_LOG_TOPIC". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". + +Definition log_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "num_topics" ] |) in + let _ := Constant.str " + Appends a log entry, having `num_topics` topics, to the evm logs. + + This will also expand the memory if the data (required by the log entry) + corresponding to the memory is not accessible. + + Parameters + ---------- + evm : + The current EVM frame. + num_topics : + The number of topics to be included in the log entry. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let topics := + make_list [] in + For M.get_name (| globals, "_" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "num_topics" |) + ], + make_dict [] + |) do + let topic := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "topics" |), "append" |), + make_list [ + M.get_name (| globals, "topic" |) + ], + make_dict [] + |) in + EndFor. + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_LOG" |), + BinOp.mult (| + M.get_name (| globals, "GAS_LOG_DATA" |), + M.get_name (| globals, "size" |) + |) + |), + BinOp.mult (| + M.get_name (| globals, "GAS_LOG_TOPIC" |), + M.get_name (| globals, "num_topics" |) + |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let log_entry := + M.call (| + M.get_name (| globals, "Log" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "logs" |), + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "logs" |), + make_tuple [ M.get_name (| globals, "log_entry" |) ] + |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition log0 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/memory.v b/CoqOfPython/ethereum/istanbul/vm/instructions/memory.v new file mode 100644 index 0000000..1e1c8b0 --- /dev/null +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/memory.v @@ -0,0 +1,378 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Memory Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM Memory instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". +Axiom memory_memory_write : + IsGlobalAlias globals memory.globals "memory_write". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition mstore : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a word to memory. + This also expands the memory, if the memory is + insufficient to store the word. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "start_position" |); M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + ], + make_dict [] + |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "start_position" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mstore8 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a byte to memory. + This also expands the memory, if the memory is + insufficient to store the word. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "start_position" |); M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let normalized_bytes_value := + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + make_list [ + BinOp.bit_and (| + M.get_name (| globals, "value" |), + Constant.int 255 + |) + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "start_position" |); + M.get_name (| globals, "normalized_bytes_value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Load word from memory. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "start_position" |); M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "start_position" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition msize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the size of active memory in bytes onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/stack.v b/CoqOfPython/ethereum/istanbul/vm/instructions/stack.v new file mode 100644 index 0000000..1eeda05 --- /dev/null +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/stack.v @@ -0,0 +1,929 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Stack Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM stack related instructions. +". + +Require functools. +Axiom functools_partial : + IsGlobalAlias globals functools.globals "partial". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". +Axiom __init___stack : + IsGlobalAlias globals __init__.globals "stack". + +Require exceptions. +Axiom exceptions_StackUnderflowError : + IsGlobalAlias globals exceptions.globals "StackUnderflowError". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_buffer_read : + IsGlobalAlias globals memory.globals "buffer_read". + +Definition pop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Remove item from stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.pass (| |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition push_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "num_bytes" ] |) in + let _ := Constant.str " + Pushes a N-byte immediate onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + num_bytes : + The number of immediate bytes to be read from the code and pushed to + the stack. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let data_to_push := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "code" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "num_bytes" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "data_to_push" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + BinOp.add (| + Constant.int 1, + M.get_name (| globals, "num_bytes" |) + |) + |) in + M.pure Constant.None_)). + +Definition dup_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "item_number" ] |) in + let _ := Constant.str " + Duplicate the Nth stack item (from top of the stack) to the top of stack. + + Parameters + ---------- + evm : + The current EVM frame. + + item_number : + The stack item number (0-indexed from top of stack) to be duplicated + to the top of stack. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "StackUnderflowError" |) + ], + make_dict [] + |) in + let data_to_duplicate := + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + BinOp.sub (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), + Constant.int 1 + |), + M.get_name (| globals, "item_number" |) + |) |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "data_to_duplicate" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition swap_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "item_number" ] |) in + let _ := Constant.str " + Swap the top and the `item_number` element of the stack, where + the top of the stack is position zero. + + If `item_number` is zero, this function does nothing (which should not be + possible, since there is no `SWAP0` instruction). + + Parameters + ---------- + evm : + The current EVM frame. + + item_number : + The stack item number (0-indexed from top of stack) to be swapped + with the top of stack element. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "StackUnderflowError" |) + ], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) |) ], + make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |) ] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition push1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push5 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push6 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push7 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push8 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push9 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push10 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push11 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push12 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push13 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push14 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push15 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push16 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push17 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push18 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push19 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push20 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push21 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push22 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push23 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push24 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push25 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push26 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push27 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push28 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push29 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push30 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push31 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push32 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition dup1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup5 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup6 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup7 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup8 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup9 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup10 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup11 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup12 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup13 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup14 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup15 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup16 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition swap1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap5 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap6 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap7 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap8 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap9 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap10 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap11 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap12 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap13 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap14 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap15 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap16 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/storage.v b/CoqOfPython/ethereum/istanbul/vm/instructions/storage.v new file mode 100644 index 0000000..5f4c9f2 --- /dev/null +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/storage.v @@ -0,0 +1,364 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Storage Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM storage related instructions. +". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require state. +Axiom state_get_storage : + IsGlobalAlias globals state.globals "get_storage". +Axiom state_get_storage_original : + IsGlobalAlias globals state.globals "get_storage_original". +Axiom state_set_storage : + IsGlobalAlias globals state.globals "set_storage". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". +Axiom exceptions_WriteInStaticContext : + IsGlobalAlias globals exceptions.globals "WriteInStaticContext". + +Require gas. +Axiom gas_GAS_CALL_STIPEND : + IsGlobalAlias globals gas.globals "GAS_CALL_STIPEND". +Axiom gas_GAS_SLOAD : + IsGlobalAlias globals gas.globals "GAS_SLOAD". +Axiom gas_GAS_STORAGE_CLEAR_REFUND : + IsGlobalAlias globals gas.globals "GAS_STORAGE_CLEAR_REFUND". +Axiom gas_GAS_STORAGE_SET : + IsGlobalAlias globals gas.globals "GAS_STORAGE_SET". +Axiom gas_GAS_STORAGE_UPDATE : + IsGlobalAlias globals gas.globals "GAS_STORAGE_UPDATE". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition sload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Loads to the stack, the value corresponding to a certain key from the + storage of the current account. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let key := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_SLOAD" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "get_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition sstore : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a value at a certain key in the current context's storage. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let key := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let new_value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt (| M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), M.get_name (| globals, "GAS_CALL_STIPEND" |) |); + M.get_name (| globals, "OutOfGasError" |) + ], + make_dict [] + |) in + let original_value := + M.call (| + M.get_name (| globals, "get_storage_original" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let current_value := + M.call (| + M.get_name (| globals, "get_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_name (| globals, "original_value" |), M.get_name (| globals, "current_value" |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_name (| globals, "current_value" |), M.get_name (| globals, "new_value" |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let gas_cost := + M.get_name (| globals, "GAS_STORAGE_SET" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let gas_cost := + M.get_name (| globals, "GAS_STORAGE_UPDATE" |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let gas_cost := + M.get_name (| globals, "GAS_SLOAD" |) in + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| M.get_name (| globals, "current_value" |), M.get_name (| globals, "new_value" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "new_value" |), Constant.int 0 |) + )) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.sub, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "original_value" |), M.get_name (| globals, "new_value" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_SET" |), + M.get_name (| globals, "GAS_SLOAD" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_UPDATE" |), + M.get_name (| globals, "GAS_SLOAD" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "gas_cost" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "set_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |); + M.get_name (| globals, "new_value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/vm/interpreter.v b/CoqOfPython/ethereum/istanbul/vm/interpreter.v new file mode 100644 index 0000000..26a41ed --- /dev/null +++ b/CoqOfPython/ethereum/istanbul/vm/interpreter.v @@ -0,0 +1,643 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Interpreter +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +A straightforward interpreter that executes EVM code. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Iterable : + IsGlobalAlias globals typing.globals "Iterable". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.trace. +Axiom ethereum_trace_EvmStop : + IsGlobalAlias globals ethereum.trace.globals "EvmStop". +Axiom ethereum_trace_OpEnd : + IsGlobalAlias globals ethereum.trace.globals "OpEnd". +Axiom ethereum_trace_OpException : + IsGlobalAlias globals ethereum.trace.globals "OpException". +Axiom ethereum_trace_OpStart : + IsGlobalAlias globals ethereum.trace.globals "OpStart". +Axiom ethereum_trace_PrecompileEnd : + IsGlobalAlias globals ethereum.trace.globals "PrecompileEnd". +Axiom ethereum_trace_PrecompileStart : + IsGlobalAlias globals ethereum.trace.globals "PrecompileStart". +Axiom ethereum_trace_TransactionEnd : + IsGlobalAlias globals ethereum.trace.globals "TransactionEnd". +Axiom ethereum_trace_evm_trace : + IsGlobalAlias globals ethereum.trace.globals "evm_trace". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_account_exists_and_is_empty : + IsGlobalAlias globals state.globals "account_exists_and_is_empty". +Axiom state_account_has_code_or_nonce : + IsGlobalAlias globals state.globals "account_has_code_or_nonce". +Axiom state_begin_transaction : + IsGlobalAlias globals state.globals "begin_transaction". +Axiom state_commit_transaction : + IsGlobalAlias globals state.globals "commit_transaction". +Axiom state_destroy_storage : + IsGlobalAlias globals state.globals "destroy_storage". +Axiom state_increment_nonce : + IsGlobalAlias globals state.globals "increment_nonce". +Axiom state_mark_account_created : + IsGlobalAlias globals state.globals "mark_account_created". +Axiom state_move_ether : + IsGlobalAlias globals state.globals "move_ether". +Axiom state_rollback_transaction : + IsGlobalAlias globals state.globals "rollback_transaction". +Axiom state_set_code : + IsGlobalAlias globals state.globals "set_code". +Axiom state_touch_account : + IsGlobalAlias globals state.globals "touch_account". + +Require vm. +Axiom vm_Message : + IsGlobalAlias globals vm.globals "Message". + +Require vm.gas. +Axiom vm_gas_GAS_CODE_DEPOSIT : + IsGlobalAlias globals vm.gas.globals "GAS_CODE_DEPOSIT". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require vm.precompiled_contracts.mapping. +Axiom vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : + IsGlobalAlias globals vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". + +Require __init__. +Axiom __init___Environment : + IsGlobalAlias globals __init__.globals "Environment". +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_AddressCollision : + IsGlobalAlias globals exceptions.globals "AddressCollision". +Axiom exceptions_ExceptionalHalt : + IsGlobalAlias globals exceptions.globals "ExceptionalHalt". +Axiom exceptions_InvalidOpcode : + IsGlobalAlias globals exceptions.globals "InvalidOpcode". +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". +Axiom exceptions_Revert : + IsGlobalAlias globals exceptions.globals "Revert". +Axiom exceptions_StackDepthLimitError : + IsGlobalAlias globals exceptions.globals "StackDepthLimitError". + +Require instructions. +Axiom instructions_Ops : + IsGlobalAlias globals instructions.globals "Ops". +Axiom instructions_op_implementation : + IsGlobalAlias globals instructions.globals "op_implementation". + +Require runtime. +Axiom runtime_get_valid_jump_destinations : + IsGlobalAlias globals runtime.globals "get_valid_jump_destinations". + +Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1024 + ], + make_dict [] + |) +)). + +Definition MAX_CODE_SIZE : Value.t := M.run ltac:(M.monadic ( + Constant.int 24576 +)). + +Definition MessageCallOutput : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition process_message_call : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + If `message.current` is empty then it creates a smart contract + else it executes a call from the `message.caller` to the `message.target`. + + Parameters + ---------- + message : + Transaction specific items. + + env : + External items required for EVM execution. + + Returns + ------- + output : `MessageCallOutput` + Output of the message call + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_name (| globals, "message" |), "target" |), M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let is_collision := + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_name (| globals, "is_collision" |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallOutput" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "tuple" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "AddressCollision" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let evm := + M.call (| + M.get_name (| globals, "process_create_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let evm := + M.call (| + M.get_name (| globals, "process_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_field (| M.get_name (| globals, "message" |), "target" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_field (| M.get_name (| globals, "message" |), "target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( +(* At stmt: unsupported node type: AnnAssign *) + let accounts_to_delete := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let touched_accounts := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let refund_counter := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let logs := + M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in + let accounts_to_delete := + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in + let touched_accounts := + M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |) in + let refund_counter := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let tx_end := + M.call (| + M.get_name (| globals, "TransactionEnd" |), + make_list [ + BinOp.sub (| + M.get_field (| M.get_name (| globals, "message" |), "gas" |), + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + |); + M.get_field (| M.get_name (| globals, "evm" |), "output" |); + M.get_field (| M.get_name (| globals, "evm" |), "error" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "evm_trace" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "tx_end" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallOutput" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition process_create_message : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + Executes a call to create a smart contract. + + Parameters + ---------- + message : + Transaction specific items. + env : + External items required for EVM execution. + + Returns + ------- + evm: :py:class:`~ethereum.istanbul.vm.Evm` + Items containing execution specific objects. + " in + let _ := M.call (| + M.get_name (| globals, "begin_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "destroy_storage" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "mark_account_created" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let evm := + M.call (| + M.get_name (| globals, "process_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), + (* then *) + ltac:(M.monadic ( + let contract_code := + M.get_field (| M.get_name (| globals, "evm" |), "output" |) in + let contract_code_gas := + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "contract_code" |) + ], + make_dict [] + |), + M.get_name (| globals, "GAS_CODE_DEPOSIT" |) + |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "rollback_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.get_name (| globals, "evm" |) + |) in + M.pure Constant.None_)). + +Definition process_message : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + Executes a call to create a smart contract. + + Parameters + ---------- + message : + Transaction specific items. + env : + External items required for EVM execution. + + Returns + ------- + evm: :py:class:`~ethereum.istanbul.vm.Evm` + Items containing execution specific objects + " in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_field (| M.get_name (| globals, "message" |), "depth" |), M.get_name (| globals, "STACK_DEPTH_LIMIT" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "StackDepthLimitError" |), + make_list [ + Constant.str "Stack depth limit reached" + ], + make_dict [] + |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "begin_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "touch_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + M.get_field (| M.get_name (| globals, "message" |), "should_transfer_value" |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_field (| M.get_name (| globals, "message" |), "value" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "move_ether" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "caller" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |); + M.get_field (| M.get_name (| globals, "message" |), "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let evm := + M.call (| + M.get_name (| globals, "execute_code" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "rollback_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "commit_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.get_name (| globals, "evm" |) + |) in + M.pure Constant.None_)). + +Definition execute_code : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + Executes bytecode present in the `message`. + + Parameters + ---------- + message : + Transaction specific items. + env : + External items required for EVM execution. + + Returns + ------- + evm: `ethereum.vm.EVM` + Items containing execution specific objects + " in + let code := + M.get_field (| M.get_name (| globals, "message" |), "code" |) in + let valid_jump_destinations := + M.call (| + M.get_name (| globals, "get_valid_jump_destinations" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) in + let evm := + M.call (| + M.get_name (| globals, "Evm" |), + make_list [], + make_dict [] + |) in +(* At stmt: unsupported node type: Try *) + let _ := M.return_ (| + M.get_name (| globals, "evm" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/vm/memory.v b/CoqOfPython/ethereum/istanbul/vm/memory.v new file mode 100644 index 0000000..fa8d906 --- /dev/null +++ b/CoqOfPython/ethereum/istanbul/vm/memory.v @@ -0,0 +1,153 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Memory +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +EVM memory operations. +". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_right_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "right_pad_zero_bytes". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". + +Definition memory_write : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "memory"; "start_position"; "value" ] |) in + let _ := Constant.str " + Writes to memory. + + Parameters + ---------- + memory : + Memory contents of the EVM. + start_position : + Starting pointer to the memory. + value : + Data to write to memory. + " in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) |), + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_)). + +Definition memory_read_bytes : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "memory"; "start_position"; "size" ] |) in + let _ := Constant.str " + Read bytes from memory. + + Parameters + ---------- + memory : + Memory contents of the EVM. + start_position : + Starting pointer to the memory. + size : + Size of the data that needs to be read from `start_position`. + + Returns + ------- + data_bytes : + Data read from memory. + " in + let _ := M.return_ (| + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |) + |) in + M.pure Constant.None_)). + +Definition buffer_read : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "buffer"; "start_position"; "size" ] |) in + let _ := Constant.str " + Read bytes from a buffer. Padding with zeros if necessary. + + Parameters + ---------- + buffer : + Memory contents of the EVM. + start_position : + Starting pointer to the memory. + size : + Size of the data that needs to be read from `start_position`. + + Returns + ------- + data_bytes : + Data read from memory. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "right_pad_zero_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/__init__.v new file mode 100644 index 0000000..ca49311 --- /dev/null +++ b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/__init__.v @@ -0,0 +1,117 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Precompiled Contract Addresses +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Addresses of precompiled contracts and mappings to their +implementations. +". + +Require utils.hexadecimal. +Axiom utils_hexadecimal_hex_to_address : + IsGlobalAlias globals utils.hexadecimal.globals "hex_to_address". + +Definition __all__ : Value.t := M.run ltac:(M.monadic ( + make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS"; Constant.str "MODEXP_ADDRESS"; Constant.str "ALT_BN128_ADD_ADDRESS"; Constant.str "ALT_BN128_MUL_ADDRESS"; Constant.str "ALT_BN128_PAIRING_CHECK_ADDRESS"; Constant.str "BLAKE2F_ADDRESS" ] +)). + +Definition ECRECOVER_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x01" + ], + make_dict [] + |) +)). + +Definition SHA256_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x02" + ], + make_dict [] + |) +)). + +Definition RIPEMD160_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x03" + ], + make_dict [] + |) +)). + +Definition IDENTITY_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x04" + ], + make_dict [] + |) +)). + +Definition MODEXP_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x05" + ], + make_dict [] + |) +)). + +Definition ALT_BN128_ADD_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x06" + ], + make_dict [] + |) +)). + +Definition ALT_BN128_MUL_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x07" + ], + make_dict [] + |) +)). + +Definition ALT_BN128_PAIRING_CHECK_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x08" + ], + make_dict [] + |) +)). + +Definition BLAKE2F_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x09" + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/alt_bn128.v new file mode 100644 index 0000000..19b83fc --- /dev/null +++ b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/alt_bn128.v @@ -0,0 +1,673 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) ALT_BN128 CONTRACTS +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the ALT_BN128 precompiled contracts. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.alt_bn128. +Axiom ethereum_crypto_alt_bn128_ALT_BN128_CURVE_ORDER : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "ALT_BN128_CURVE_ORDER". +Axiom ethereum_crypto_alt_bn128_ALT_BN128_PRIME : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "ALT_BN128_PRIME". +Axiom ethereum_crypto_alt_bn128_BNF : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF". +Axiom ethereum_crypto_alt_bn128_BNF2 : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF2". +Axiom ethereum_crypto_alt_bn128_BNF12 : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF12". +Axiom ethereum_crypto_alt_bn128_BNP : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNP". +Axiom ethereum_crypto_alt_bn128_BNP2 : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNP2". +Axiom ethereum_crypto_alt_bn128_pairing : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "pairing". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require vm.memory. +Axiom vm_memory_buffer_read : + IsGlobalAlias globals vm.memory.globals "buffer_read". + +Require exceptions. +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". + +Definition alt_bn128_add : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + The ALT_BN128 addition precompiled contract. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 150 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x0_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x0_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "x0_bytes" |) + ], + make_dict [] + |) in + let y0_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y0_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "y0_bytes" |) + ], + make_dict [] + |) in + let x1_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x1_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "x1_bytes" |) + ], + make_dict [] + |) in + let y1_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y1_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "y1_bytes" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ] do + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "i" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. +(* At stmt: unsupported node type: Try *) + let p := + BinOp.add (| + M.get_name (| globals, "p0" |), + M.get_name (| globals, "p1" |) + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + BinOp.add (| + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "p" |), "x" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "p" |), "y" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) + |) in + M.pure Constant.None_)). + +Definition alt_bn128_mul : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + The ALT_BN128 multiplication precompiled contract. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 6000 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x0_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x0_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "x0_bytes" |) + ], + make_dict [] + |) in + let y0_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y0_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "y0_bytes" |) + ], + make_dict [] + |) in + let n := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ] do + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "i" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. +(* At stmt: unsupported node type: Try *) + let p := + M.call (| + M.get_field (| M.get_name (| globals, "p0" |), "mul_by" |), + make_list [ + M.get_name (| globals, "n" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + BinOp.add (| + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "p" |), "x" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "p" |), "y" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) + |) in + M.pure Constant.None_)). + +Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + The ALT_BN128 pairing check precompiled contract. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 34000, + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 192 + |) + |), + Constant.int 45000 + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 192 + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 192 + |) + ], + make_dict [] + |) do + let values := + make_list [] in + For M.get_name (| globals, "j" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 6 + ], + make_dict [] + |) do + let value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "data" |), BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + M.get_name (| globals, "j" |) + |) + |):BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "j" |), + Constant.int 1 + |) + |) + |) |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "value" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "values" |), "append" |), + make_list [ + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + EndFor. +(* At stmt: unsupported node type: Try *) + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.call (| + M.get_field (| M.get_name (| globals, "p" |), "mul_by" |), + make_list [ + M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) + ], + make_dict [] + |), M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) |); + M.get_name (| globals, "OutOfGasError" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.call (| + M.get_field (| M.get_name (| globals, "q" |), "mul_by" |), + make_list [ + M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) + ], + make_dict [] + |), M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) |); + M.get_name (| globals, "OutOfGasError" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "p" |), M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_name (| globals, "q" |), M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let result := + BinOp.mult (| + M.get_name (| globals, "result" |), + M.call (| + M.get_name (| globals, "pairing" |), + make_list [ + M.get_name (| globals, "q" |); + M.get_name (| globals, "p" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "result" |), M.call (| + M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/blake2f.v b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/blake2f.v new file mode 100644 index 0000000..5903066 --- /dev/null +++ b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/blake2f.v @@ -0,0 +1,122 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Blake2 PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `Blake2` precompiled contract. +". + +Require ethereum.crypto.blake2. +Axiom ethereum_crypto_blake2_Blake2b : + IsGlobalAlias globals ethereum.crypto.blake2.globals "Blake2b". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_BLAKE2_PER_ROUND : + IsGlobalAlias globals vm.gas.globals "GAS_BLAKE2_PER_ROUND". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require exceptions. +Axiom exceptions_InvalidParameter : + IsGlobalAlias globals exceptions.globals "InvalidParameter". + +Definition blake2f : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the Blake2 hash to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), Constant.int 213 |); + M.get_name (| globals, "InvalidParameter" |) + ], + make_dict [] + |) in + let blake2b := + M.call (| + M.get_name (| globals, "Blake2b" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "rounds" |); M.get_name (| globals, "h" |); M.get_name (| globals, "m" |); M.get_name (| globals, "t_0" |); M.get_name (| globals, "t_1" |); M.get_name (| globals, "f" |) ], + M.call (| + M.get_field (| M.get_name (| globals, "blake2b" |), "get_blake2_parameters" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.mult (| + M.get_name (| globals, "GAS_BLAKE2_PER_ROUND" |), + M.get_name (| globals, "rounds" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.in (| M.get_name (| globals, "f" |), make_list [ + Constant.int 0; + Constant.int 1 + ] |); + M.get_name (| globals, "InvalidParameter" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.get_name (| globals, "blake2b" |), "compress" |), + make_list [ + M.get_name (| globals, "rounds" |); + M.get_name (| globals, "h" |); + M.get_name (| globals, "m" |); + M.get_name (| globals, "t_0" |); + M.get_name (| globals, "t_1" |); + M.get_name (| globals, "f" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/ecrecover.v new file mode 100644 index 0000000..cc351b5 --- /dev/null +++ b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/ecrecover.v @@ -0,0 +1,269 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) ECRECOVER PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the ECRECOVER precompiled contract. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require ethereum.crypto.elliptic_curve. +Axiom ethereum_crypto_elliptic_curve_SECP256K1N : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_left_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_ECRECOVER : + IsGlobalAlias globals vm.gas.globals "GAS_ECRECOVER". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require vm.memory. +Axiom vm_memory_buffer_read : + IsGlobalAlias globals vm.memory.globals "buffer_read". + +Definition ecrecover : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Decrypts the address using elliptic curve DSA recovery mechanism and writes + the address to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_ECRECOVER" |) + ], + make_dict [] + |) in + let message_hash_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let message_hash := + M.call (| + M.get_name (| globals, "Hash32" |), + make_list [ + M.get_name (| globals, "message_hash_bytes" |) + ], + make_dict [] + |) in + let v := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let r := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let s := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 27 |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 28 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| Constant.int 0, M.get_name (| globals, "r" |) |), + ltac:(M.monadic ( + Compare.gt_e (| M.get_name (| globals, "r" |), M.get_name (| globals, "SECP256K1N" |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| Constant.int 0, M.get_name (| globals, "s" |) |), + ltac:(M.monadic ( + Compare.gt_e (| M.get_name (| globals, "s" |), M.get_name (| globals, "SECP256K1N" |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in +(* At stmt: unsupported node type: Try *) + let address := + M.get_subscript (| M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), Constant.int 12:Constant.int 32 |) in + let padded_address := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "address" |); + Constant.int 32 + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.get_name (| globals, "padded_address" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/identity.v new file mode 100644 index 0000000..fa96704 --- /dev/null +++ b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/identity.v @@ -0,0 +1,94 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) IDENTITY PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `IDENTITY` precompiled contract. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_IDENTITY : + IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY". +Axiom vm_gas_GAS_IDENTITY_WORD : + IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY_WORD". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition identity : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the message data to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let word_count := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_IDENTITY" |), + BinOp.mult (| + M.get_name (| globals, "GAS_IDENTITY_WORD" |), + M.get_name (| globals, "word_count" |) + |) + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.get_name (| globals, "data" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/mapping.v new file mode 100644 index 0000000..8a2e2eb --- /dev/null +++ b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/mapping.v @@ -0,0 +1,82 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Precompiled Contract Addresses +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Mapping of precompiled contracts their implementations. +". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require __init__. +Axiom __init___ALT_BN128_ADD_ADDRESS : + IsGlobalAlias globals __init__.globals "ALT_BN128_ADD_ADDRESS". +Axiom __init___ALT_BN128_MUL_ADDRESS : + IsGlobalAlias globals __init__.globals "ALT_BN128_MUL_ADDRESS". +Axiom __init___ALT_BN128_PAIRING_CHECK_ADDRESS : + IsGlobalAlias globals __init__.globals "ALT_BN128_PAIRING_CHECK_ADDRESS". +Axiom __init___BLAKE2F_ADDRESS : + IsGlobalAlias globals __init__.globals "BLAKE2F_ADDRESS". +Axiom __init___ECRECOVER_ADDRESS : + IsGlobalAlias globals __init__.globals "ECRECOVER_ADDRESS". +Axiom __init___IDENTITY_ADDRESS : + IsGlobalAlias globals __init__.globals "IDENTITY_ADDRESS". +Axiom __init___MODEXP_ADDRESS : + IsGlobalAlias globals __init__.globals "MODEXP_ADDRESS". +Axiom __init___RIPEMD160_ADDRESS : + IsGlobalAlias globals __init__.globals "RIPEMD160_ADDRESS". +Axiom __init___SHA256_ADDRESS : + IsGlobalAlias globals __init__.globals "SHA256_ADDRESS". + +Require alt_bn128. +Axiom alt_bn128_alt_bn128_add : + IsGlobalAlias globals alt_bn128.globals "alt_bn128_add". +Axiom alt_bn128_alt_bn128_mul : + IsGlobalAlias globals alt_bn128.globals "alt_bn128_mul". +Axiom alt_bn128_alt_bn128_pairing_check : + IsGlobalAlias globals alt_bn128.globals "alt_bn128_pairing_check". + +Require blake2f. +Axiom blake2f_blake2f : + IsGlobalAlias globals blake2f.globals "blake2f". + +Require ecrecover. +Axiom ecrecover_ecrecover : + IsGlobalAlias globals ecrecover.globals "ecrecover". + +Require identity. +Axiom identity_identity : + IsGlobalAlias globals identity.globals "identity". + +Require modexp. +Axiom modexp_modexp : + IsGlobalAlias globals modexp.globals "modexp". + +Require ripemd160. +Axiom ripemd160_ripemd160 : + IsGlobalAlias globals ripemd160.globals "ripemd160". + +Require sha256. +Axiom sha256_sha256 : + IsGlobalAlias globals sha256.globals "sha256". + +(* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/modexp.v new file mode 100644 index 0000000..39ce4f9 --- /dev/null +++ b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/modexp.v @@ -0,0 +1,506 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) MODEXP PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `MODEXP` precompiled contract. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require memory. +Axiom memory_buffer_read : + IsGlobalAlias globals memory.globals "buffer_read". + +Definition GQUADDIVISOR : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 20 + ], + make_dict [] + |) +)). + +Definition modexp : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Calculates `(base**exp) % modulus` for arbitrary sized `base`, `exp` and. + `modulus`. The return value is the same length as the modulus. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let base_length := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exp_length := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let modulus_length := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exp_start := + BinOp.add (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |), + M.get_name (| globals, "base_length" |) + |) in + let exp_head := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.get_name (| globals, "exp_start" |); + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.get_name (| globals, "exp_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "exp_length" |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let adjusted_exp_length := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "max" |), + make_list [ + Constant.int 0; + BinOp.sub (| + M.call (| + M.get_field (| M.get_name (| globals, "exp_head" |), "bit_length" |), + make_list [], + make_dict [] + |), + Constant.int 1 + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let adjusted_exp_length := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 8, + BinOp.sub (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "exp_length" |) + ], + make_dict [] + |), + Constant.int 32 + |) + |), + M.call (| + M.get_name (| globals, "max" |), + make_list [ + Constant.int 0; + BinOp.sub (| + M.call (| + M.get_field (| M.get_name (| globals, "exp_head" |), "bit_length" |), + make_list [], + make_dict [] + |), + Constant.int 1 + |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.floor_div (| + BinOp.mult (| + M.call (| + M.get_name (| globals, "get_mult_complexity" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "max" |), + make_list [ + M.get_name (| globals, "base_length" |); + M.get_name (| globals, "modulus_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "max" |), + make_list [ + M.get_name (| globals, "adjusted_exp_length" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + ], + make_dict [] + |) + |), + M.get_name (| globals, "GQUADDIVISOR" |) + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_name (| globals, "base_length" |), Constant.int 0 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "modulus_length" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [], + make_dict [] + |) + |) in + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let base := + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |); + M.get_name (| globals, "base_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exp := + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.get_name (| globals, "exp_start" |); + M.get_name (| globals, "exp_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let modulus_start := + BinOp.add (| + M.get_name (| globals, "exp_start" |), + M.get_name (| globals, "exp_length" |) + |) in + let modulus := + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.get_name (| globals, "modulus_start" |); + M.get_name (| globals, "modulus_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "modulus" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + BinOp.mult (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |), + M.get_name (| globals, "modulus_length" |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pow" |), + make_list [ + M.get_name (| globals, "base" |); + M.get_name (| globals, "exp" |); + M.get_name (| globals, "modulus" |) + ], + make_dict [] + |) + ], + make_dict [] + |), "to_bytes" |), + make_list [ + M.get_name (| globals, "modulus_length" |); + Constant.str "big" + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition get_mult_complexity : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "x" ] |) in + let _ := Constant.str " + Estimate the complexity of performing Karatsuba multiplication. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| M.get_name (| globals, "x" |), Constant.int 64 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.pow (| + M.get_name (| globals, "x" |), + Constant.int 2 + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| M.get_name (| globals, "x" |), Constant.int 1024 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.sub (| + BinOp.add (| + BinOp.floor_div (| + BinOp.pow (| + M.get_name (| globals, "x" |), + Constant.int 2 + |), + Constant.int 4 + |), + BinOp.mult (| + Constant.int 96, + M.get_name (| globals, "x" |) + |) + |), + Constant.int 3072 + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.sub (| + BinOp.add (| + BinOp.floor_div (| + BinOp.pow (| + M.get_name (| globals, "x" |), + Constant.int 2 + |), + Constant.int 16 + |), + BinOp.mult (| + Constant.int 480, + M.get_name (| globals, "x" |) + |) + |), + Constant.int 199680 + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/ripemd160.v new file mode 100644 index 0000000..96f8dcd --- /dev/null +++ b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/ripemd160.v @@ -0,0 +1,122 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) RIPEMD160 PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `RIPEMD160` precompiled contract. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_left_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_RIPEMD160 : + IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160". +Axiom vm_gas_GAS_RIPEMD160_WORD : + IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160_WORD". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition ripemd160 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the ripemd160 hash to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let word_count := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_RIPEMD160" |), + BinOp.mult (| + M.get_name (| globals, "GAS_RIPEMD160_WORD" |), + M.get_name (| globals, "word_count" |) + |) + |) + ], + make_dict [] + |) in + let hash_bytes := + M.call (| + M.get_field (| M.call (| + M.get_field (| M.get_name (| globals, "hashlib" |), "new" |), + make_list [ + Constant.str "ripemd160"; + M.get_name (| globals, "data" |) + ], + make_dict [] + |), "digest" |), + make_list [], + make_dict [] + |) in + let padded_hash := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "hash_bytes" |); + Constant.int 32 + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.get_name (| globals, "padded_hash" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/sha256.v new file mode 100644 index 0000000..9f6d2bf --- /dev/null +++ b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/sha256.v @@ -0,0 +1,106 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) SHA256 PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `SHA256` precompiled contract. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_SHA256 : + IsGlobalAlias globals vm.gas.globals "GAS_SHA256". +Axiom vm_gas_GAS_SHA256_WORD : + IsGlobalAlias globals vm.gas.globals "GAS_SHA256_WORD". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition sha256 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the sha256 hash to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let word_count := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_SHA256" |), + BinOp.mult (| + M.get_name (| globals, "GAS_SHA256_WORD" |), + M.get_name (| globals, "word_count" |) + |) + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_field (| M.get_name (| globals, "hashlib" |), "sha256" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), "digest" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/vm/runtime.v b/CoqOfPython/ethereum/istanbul/vm/runtime.v new file mode 100644 index 0000000..835b46c --- /dev/null +++ b/CoqOfPython/ethereum/istanbul/vm/runtime.v @@ -0,0 +1,125 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Runtime Operations +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Runtime related operations used while executing EVM code. +". + +Require typing. +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require instructions. +Axiom instructions_Ops : + IsGlobalAlias globals instructions.globals "Ops". + +Definition get_valid_jump_destinations : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "code" ] |) in + let _ := Constant.str " + Analyze the evm code to obtain the set of valid jump destinations. + + Valid jump destinations are defined as follows: + * The jump destination is less than the length of the code. + * The jump destination should have the `JUMPDEST` opcode (0x5B). + * The jump destination shouldn't be part of the data corresponding to + `PUSH-N` opcodes. + + Note - Jump destinations are 0-indexed. + + Parameters + ---------- + code : + The EVM code which is to be executed. + + Returns + ------- + valid_jump_destinations: `Set[Uint]` + The set of valid jump destinations in the code. + " in + let valid_jump_destinations := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let pc := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + While Compare.lt (| M.get_name (| globals, "pc" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) |) do +(* At stmt: unsupported node type: Try *) + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "current_opcode" |), M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), + make_list [ + M.get_name (| globals, "pc" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + (* At expr: unsupported node type: Compare *), + (* then *) + ltac:(M.monadic ( + let push_data_size := + BinOp.add (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) + |), + Constant.int 1 + |) in + let pc := BinOp.add + M.get_name (| globals, "push_data_size" |) + M.get_name (| globals, "push_data_size" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let pc := BinOp.add + Constant.int 1 + Constant.int 1 in + EndWhile. + let _ := M.return_ (| + M.get_name (| globals, "valid_jump_destinations" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/vm/stack.v b/CoqOfPython/ethereum/istanbul/vm/stack.v new file mode 100644 index 0000000..42ea42d --- /dev/null +++ b/CoqOfPython/ethereum/istanbul/vm/stack.v @@ -0,0 +1,120 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Stack +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the stack operators for the EVM. +". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require exceptions. +Axiom exceptions_StackOverflowError : + IsGlobalAlias globals exceptions.globals "StackOverflowError". +Axiom exceptions_StackUnderflowError : + IsGlobalAlias globals exceptions.globals "StackUnderflowError". + +Definition pop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "stack" ] |) in + let _ := Constant.str " + Pops the top item off of `stack`. + + Parameters + ---------- + stack : + EVM stack. + + Returns + ------- + value : `U256` + The top element on the stack. + + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "StackUnderflowError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "pop" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition push : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "stack"; "value" ] |) in + let _ := Constant.str " + Pushes `value` onto `stack`. + + Parameters + ---------- + stack : + EVM stack. + + value : + Item to be pushed onto `stack`. + + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), Constant.int 1024 |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "StackOverflowError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "append" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/__init__.v b/CoqOfPython/ethereum/london/__init__.v new file mode 100644 index 0000000..f653d66 --- /dev/null +++ b/CoqOfPython/ethereum/london/__init__.v @@ -0,0 +1,23 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +The London fork overhauls the transaction fee market, changes gas refunds, +reserves a contract prefix for future use, and delays the difficulty bomb. +". + +Require ethereum.fork_criteria. +Axiom ethereum_fork_criteria_ByBlockNumber : + IsGlobalAlias globals ethereum.fork_criteria.globals "ByBlockNumber". + +Definition FORK_CRITERIA : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "ByBlockNumber" |), + make_list [ + Constant.int 12965000 + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/london/blocks.v b/CoqOfPython/ethereum/london/blocks.v new file mode 100644 index 0000000..a90217e --- /dev/null +++ b/CoqOfPython/ethereum/london/blocks.v @@ -0,0 +1,95 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +A `Block` is a single link in the chain that is Ethereum. Each `Block` contains +a `Header` and zero or more transactions. Each `Header` contains associated +metadata like the block number, parent block hash, and how much gas was +consumed by its transactions. + +Together, these blocks form a cryptographically secure journal recording the +history of all state transitions that have happened since the genesis of the +chain. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes8 : + IsGlobalAlias globals base_types.globals "Bytes8". +Axiom base_types_Bytes32 : + IsGlobalAlias globals base_types.globals "Bytes32". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require crypto.hash. +Axiom crypto_hash_Hash32 : + IsGlobalAlias globals crypto.hash.globals "Hash32". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Require transactions. +Axiom transactions_LegacyTransaction : + IsGlobalAlias globals transactions.globals "LegacyTransaction". + +Definition Header : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Block : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Log : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Receipt : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. diff --git a/CoqOfPython/ethereum/london/bloom.v b/CoqOfPython/ethereum/london/bloom.v new file mode 100644 index 0000000..04b5d9f --- /dev/null +++ b/CoqOfPython/ethereum/london/bloom.v @@ -0,0 +1,164 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Logs Bloom +^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +This modules defines functions for calculating bloom filters of logs. For the +general theory of bloom filters see e.g. `Wikipedia +`_. Bloom filters are used to allow +for efficient searching of logs by address and/or topic, by rapidly +eliminating blocks and receipts from their search. +". + +Require typing. +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require fork_types. +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". + +Definition add_to_bloom : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "bloom"; "bloom_entry" ] |) in + let _ := Constant.str " + Add a bloom entry to the bloom filter (`bloom`). + + The number of hash functions used is 3. They are calculated by taking the + least significant 11 bits from the first 3 16-bit words of the + `keccak_256()` hash of `bloom_entry`. + + Parameters + ---------- + bloom : + The bloom filter. + bloom_entry : + An entry which is to be added to bloom filter. + " in + let hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "bloom_entry" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "idx" |) in make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ] do + let bit_to_set := + BinOp.bit_and (| + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |):BinOp.add (| + M.get_name (| globals, "idx" |), + Constant.int 2 + |) |) + ], + make_dict [] + |), + Constant.int 2047 + |) in + let bit_index := + BinOp.sub (| + Constant.int 2047, + M.get_name (| globals, "bit_to_set" |) + |) in + let byte_index := + BinOp.floor_div (| + M.get_name (| globals, "bit_index" |), + Constant.int 8 + |) in + let bit_value := + BinOp.l_shift (| + Constant.int 1, + BinOp.sub (| + Constant.int 7, + BinOp.mod_ (| + M.get_name (| globals, "bit_index" |), + Constant.int 8 + |) + |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), + BinOp.bit_or (| + M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), + M.get_name (| globals, "bit_value" |) + |) + |) in + EndFor. + M.pure Constant.None_)). + +Definition logs_bloom : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "logs" ] |) in + let _ := Constant.str " + Obtain the logs bloom from a list of log entries. + + The address and each topic of a log are added to the bloom filter. + + Parameters + ---------- + logs : + List of logs for which the logs bloom is to be obtained. + + Returns + ------- + logs_bloom : `Bloom` + The logs bloom obtained which is 256 bytes with some bits set as per + the caller address and the log topics. + " in +(* At stmt: unsupported node type: AnnAssign *) + For M.get_name (| globals, "log" |) in M.get_name (| globals, "logs" |) do + let _ := M.call (| + M.get_name (| globals, "add_to_bloom" |), + make_list [ + M.get_name (| globals, "bloom" |); + M.get_field (| M.get_name (| globals, "log" |), "address" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "topic" |) in M.get_field (| M.get_name (| globals, "log" |), "topics" |) do + let _ := M.call (| + M.get_name (| globals, "add_to_bloom" |), + make_list [ + M.get_name (| globals, "bloom" |); + M.get_name (| globals, "topic" |) + ], + make_dict [] + |) in + EndFor. + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bloom" |), + make_list [ + M.get_name (| globals, "bloom" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/fork_types.v b/CoqOfPython/ethereum/london/fork_types.v new file mode 100644 index 0000000..d12953d --- /dev/null +++ b/CoqOfPython/ethereum/london/fork_types.v @@ -0,0 +1,102 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Types +^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Types re-used throughout the specification, which are specific to Ethereum. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes20 : + IsGlobalAlias globals base_types.globals "Bytes20". +Axiom base_types_Bytes256 : + IsGlobalAlias globals base_types.globals "Bytes256". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require crypto.hash. +Axiom crypto_hash_Hash32 : + IsGlobalAlias globals crypto.hash.globals "Hash32". +Axiom crypto_hash_keccak256 : + IsGlobalAlias globals crypto.hash.globals "keccak256". + +Definition Address : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Bytes20" |) +)). + +Definition Root : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Hash32" |) +)). + +Definition Bloom : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Bytes256" |) +)). + +Definition Account : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition EMPTY_ACCOUNT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Account" |), + make_list [], + make_dict [] + |) +)). + +Definition encode_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "raw_account_data"; "storage_root" ] |) in + let _ := Constant.str " + Encode `Account` dataclass. + + Storage is not stored in the `Account` dataclass, so `Accounts` cannot be + encoded with providing a storage root. + " in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "raw_account_data" |), "nonce" |); M.get_field (| M.get_name (| globals, "raw_account_data" |), "balance" |); M.get_name (| globals, "storage_root" |); M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_field (| M.get_name (| globals, "raw_account_data" |), "code" |) + ], + make_dict [] + |) ] + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/state.v b/CoqOfPython/ethereum/london/state.v new file mode 100644 index 0000000..7b038e5 --- /dev/null +++ b/CoqOfPython/ethereum/london/state.v @@ -0,0 +1,1184 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +State +^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The state contains all information that is preserved between transactions. + +It consists of a main account trie and storage tries for each contract. + +There is a distinction between an account that does not exist and +`EMPTY_ACCOUNT`. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_field : + IsGlobalAlias globals dataclasses.globals "field". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_modify : + IsGlobalAlias globals ethereum.base_types.globals "modify". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require fork_types. +Axiom fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". +Axiom fork_types_Account : + IsGlobalAlias globals fork_types.globals "Account". +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Require trie. +Axiom trie_EMPTY_TRIE_ROOT : + IsGlobalAlias globals trie.globals "EMPTY_TRIE_ROOT". +Axiom trie_Trie : + IsGlobalAlias globals trie.globals "Trie". +Axiom trie_copy_trie : + IsGlobalAlias globals trie.globals "copy_trie". +Axiom trie_root : + IsGlobalAlias globals trie.globals "root". +Axiom trie_trie_get : + IsGlobalAlias globals trie.globals "trie_get". +Axiom trie_trie_set : + IsGlobalAlias globals trie.globals "trie_set". + +Definition State : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition close_state : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Free resources held by the state. Used by optimized implementations to + release file descriptors. + " in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) |) in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |) in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |) |) in + M.pure Constant.None_)). + +Definition begin_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Start a state transaction. + + Transactions are entirely implicit and can be nested. It is not possible to + calculate the state root during a transaction. + + Parameters + ---------- + state : State + The state. + " in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), "append" |), + make_list [ + make_tuple [ M.call (| + M.get_name (| globals, "copy_trie" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) + ], + make_dict [] + |); {M.get_name (| globals, "k" |): M.call (| + M.get_name (| globals, "copy_trie" |), + make_list [ + M.get_name (| globals, "t" |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)} ] + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition commit_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Commit a state transaction. + + Parameters + ---------- + state : State + The state. + " in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), "pop" |), + make_list [], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "clear" |), + make_list [], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition rollback_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Rollback a state transaction, resetting the state to the point when the + corresponding `start_transaction()` call was made. + + Parameters + ---------- + state : State + The state. + " in + let _ := M.assign (| + make_tuple [ M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) ], + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), "pop" |), + make_list [], + make_dict [] + |) + |) in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "clear" |), + make_list [], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition get_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Get the `Account` object at an address. Returns `EMPTY_ACCOUNT` if there + is no account at the address. + + Use `get_account_optional()` if you care about the difference between a + non-existent account and `EMPTY_ACCOUNT`. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address to lookup. + + Returns + ------- + account : `Account` + Account at address. + " in + let account := + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "account" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "account" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "EMPTY_ACCOUNT" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition get_account_optional : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Get the `Account` object at an address. Returns `None` (rather than + `EMPTY_ACCOUNT`) if there is no account at the address. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address to lookup. + + Returns + ------- + account : `Account` + Account at address. + " in + let account := + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "account" |) + |) in + M.pure Constant.None_)). + +Definition set_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "account" ] |) in + let _ := Constant.str " + Set the `Account` object at an address. Setting to `None` deletes + the account (but not its storage, see `destroy_account()`). + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address to set. + account : `Account` + Account to set at address. + " in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "account" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition destroy_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Completely remove the account at `address` and all of its storage. + + This function is made available exclusively for the `SELFDESTRUCT` + opcode. It is expected that `SELFDESTRUCT` will be disabled in a future + hardfork and this function will be removed. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of account to destroy. + " in + let _ := M.call (| + M.get_name (| globals, "destroy_storage" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + Constant.None_ + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition destroy_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Completely remove the storage at `address`. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of account whose storage is to be deleted. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition mark_account_created : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Mark an account as having been created in the current transaction. + This information is used by `get_storage_original()` to handle an obscure + edgecase. + + The marker is not removed even if the account creation reverts. Since the + account cannot have had code prior to its creation and can't call + `get_storage_original()`, this is harmless. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of the account that has been created. + " in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition get_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "key" ] |) in + let _ := Constant.str " + Get a value at a storage key on an account. Returns `U256(0)` if the + storage key has not been set previously. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of the account. + key : `Bytes` + Key to lookup. + + Returns + ------- + value : `U256` + Value at the key. + " in + let trie := + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let _ := M.assert (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "U256" |) + ], + make_dict [] + |) |) in + let _ := M.return_ (| + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_)). + +Definition set_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "key"; "value" ] |) in + let _ := Constant.str " + Set a value at a storage key on an account. Setting to `U256(0)` deletes + the key. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of the account. + key : `Bytes` + Key to set. + value : `U256` + Value to set at the key. + " in + let _ := M.assert (| Compare.is_not (| M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), Constant.None_ |) |) in + let trie := + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let trie := + M.call (| + M.get_name (| globals, "Trie" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), + M.get_name (| globals, "trie" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "key" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), {} |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition storage_root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Calculate the storage root of an account. + + Parameters + ---------- + state: + The state + address : + Address of the account. + + Returns + ------- + root : `Root` + Storage root of the account. + " in + let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "EMPTY_TRIE_ROOT" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition state_root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Calculate the state root. + + Parameters + ---------- + state: + The current state. + + Returns + ------- + root : `Root` + The state root. + " in + let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition account_exists : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account exists in the state trie + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + account_exists : `bool` + True if account exists in the state trie, False otherwise + " in + let _ := M.return_ (| + Compare.is_not (| M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), Constant.None_ |) + |) in + M.pure Constant.None_)). + +Definition account_has_code_or_nonce : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account has non zero nonce or non empty code + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + has_code_or_nonce : `bool` + True if if an account has non zero nonce or non empty code, + False otherwise. + " in + let account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + BoolOp.or (| + Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |) + )) + |) + |) in + M.pure Constant.None_)). + +Definition is_account_empty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account has zero nonce, empty code and zero balance. + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + is_empty : `bool` + True if if an account has zero nonce, empty code and zero balance, + False otherwise. + " in + let account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + ltac:(M.monadic ( + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + )) + |) + )) + |) + |) in + M.pure Constant.None_)). + +Definition account_exists_and_is_empty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account exists and has zero nonce, empty code and zero + balance. + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + exists_and_is_empty : `bool` + True if an account exists and has zero nonce, empty code and zero + balance, False otherwise. + " in + let account := + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + BoolOp.and (| + Compare.is_not (| M.get_name (| globals, "account" |), Constant.None_ |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + ltac:(M.monadic ( + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + )) + |) + )) + |) + )) + |) + |) in + M.pure Constant.None_)). + +Definition is_account_alive : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Check whether is an account is both in the state and non empty. + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + is_alive : `bool` + True if the account is alive. + " in + let account := + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "account" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + UnOp.not (| BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + ltac:(M.monadic ( + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + )) + |) + )) + |) |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition modify_state : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "f" ] |) in + let _ := Constant.str " + Modify an `Account` in the `State`. + " in + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.call (| + M.get_name (| globals, "modify" |), + make_list [ + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |); + M.get_name (| globals, "f" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition move_ether : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "sender_address"; "recipient_address"; "amount" ] |) in + let _ := Constant.str " + Move funds between accounts. + " in +(* At stmt: unsupported node type: FunctionDef *) +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "sender_address" |); + M.get_name (| globals, "reduce_sender_balance" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "recipient_address" |); + M.get_name (| globals, "increase_recipient_balance" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition set_account_balance : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "amount" ] |) in + let _ := Constant.str " + Sets the balance of an account. + + Parameters + ---------- + state: + The current state. + + address: + Address of the account whose nonce needs to be incremented. + + amount: + The amount that needs to set in balance. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "set_balance" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition touch_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Initializes an account to state. + + Parameters + ---------- + state: + The current state. + + address: + The address of the account that need to initialised. + " in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "account_exists" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "EMPTY_ACCOUNT" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition increment_nonce : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Increments the nonce of an account. + + Parameters + ---------- + state: + The current state. + + address: + Address of the account whose nonce needs to be incremented. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "increase_nonce" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition set_code : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "code" ] |) in + let _ := Constant.str " + Sets Account code. + + Parameters + ---------- + state: + The current state. + + address: + Address of the account whose code needs to be update. + + code: + The bytecode that needs to be set. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "write_code" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition create_ether : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "amount" ] |) in + let _ := Constant.str " + Add newly created ether to an account. + + Parameters + ---------- + state: + The current state. + address: + Address of the account to which ether is added. + amount: + The amount of ether to be added to the account of interest. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "increase_balance" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition get_storage_original : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "key" ] |) in + let _ := Constant.str " + Get the original value in a storage slot i.e. the value before the current + transaction began. This function reads the value from the snapshots taken + before executing the transaction. + + Parameters + ---------- + state: + The current state. + address: + Address of the account to read the value from. + key: + Key of the storage slot. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "_" |); M.get_name (| globals, "original_trie" |) ], + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), Constant.int 0 |) + |) in + let original_account_trie := + M.call (| + M.get_field (| M.get_name (| globals, "original_trie" |), "get" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "original_account_trie" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let original_value := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let original_value := + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_name (| globals, "original_account_trie" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.assert (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "original_value" |); + M.get_name (| globals, "U256" |) + ], + make_dict [] + |) |) in + let _ := M.return_ (| + M.get_name (| globals, "original_value" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/transactions.v b/CoqOfPython/ethereum/london/transactions.v new file mode 100644 index 0000000..56996d9 --- /dev/null +++ b/CoqOfPython/ethereum/london/transactions.v @@ -0,0 +1,274 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Transactions are atomic units of work created externally to Ethereum and +submitted to be executed. If Ethereum is viewed as a state machine, +transactions are the events that move between states. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U64 : + IsGlobalAlias globals base_types.globals "U64". +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes0 : + IsGlobalAlias globals base_types.globals "Bytes0". +Axiom base_types_Bytes32 : + IsGlobalAlias globals base_types.globals "Bytes32". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require exceptions. +Axiom exceptions_InvalidBlock : + IsGlobalAlias globals exceptions.globals "InvalidBlock". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( + Constant.int 21000 +)). + +Definition TX_DATA_COST_PER_NON_ZERO : Value.t := M.run ltac:(M.monadic ( + Constant.int 16 +)). + +Definition TX_DATA_COST_PER_ZERO : Value.t := M.run ltac:(M.monadic ( + Constant.int 4 +)). + +Definition TX_CREATE_COST : Value.t := M.run ltac:(M.monadic ( + Constant.int 32000 +)). + +Definition TX_ACCESS_LIST_ADDRESS_COST : Value.t := M.run ltac:(M.monadic ( + Constant.int 2400 +)). + +Definition TX_ACCESS_LIST_STORAGE_KEY_COST : Value.t := M.run ltac:(M.monadic ( + Constant.int 1900 +)). + +Definition LegacyTransaction : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition AccessListTransaction : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition FeeMarketTransaction : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Transaction : Value.t := M.run ltac:(M.monadic ( + M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "AccessListTransaction" |); M.get_name (| globals, "FeeMarketTransaction" |) ] |) +)). + +Definition encode_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Encode a transaction. Needed because non-legacy transactions aren't RLP. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "LegacyTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "tx" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "AccessListTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + (* At constant: unsupported node type: Constant *), + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "FeeMarketTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + (* At constant: unsupported node type: Constant *), + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "Exception" |), + make_list [ + (* At expr: unsupported node type: JoinedStr *) + ], + make_dict [] + |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition decode_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Decode a transaction. Needed because non-legacy transactions aren't RLP. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), Constant.int 1 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), + make_list [ + M.get_name (| globals, "AccessListTransaction" |); + M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 1:(* At expr: unsupported node type: NoneType *) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), Constant.int 2 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), + make_list [ + M.get_name (| globals, "FeeMarketTransaction" |); + M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 1:(* At expr: unsupported node type: NoneType *) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidBlock" |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "tx" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/trie.v b/CoqOfPython/ethereum/london/trie.v new file mode 100644 index 0000000..3effadb --- /dev/null +++ b/CoqOfPython/ethereum/london/trie.v @@ -0,0 +1,1357 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +State Trie +^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The state trie is the structure responsible for storing +`.fork_types.Account` objects. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_field : + IsGlobalAlias globals dataclasses.globals "field". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". +Axiom typing_Generic : + IsGlobalAlias globals typing.globals "Generic". +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Mapping : + IsGlobalAlias globals typing.globals "Mapping". +Axiom typing_MutableMapping : + IsGlobalAlias globals typing.globals "MutableMapping". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Sequence : + IsGlobalAlias globals typing.globals "Sequence". +Axiom typing_TypeVar : + IsGlobalAlias globals typing.globals "TypeVar". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". +Axiom typing_cast : + IsGlobalAlias globals typing.globals "cast". + +Require ethereum.berlin. +Axiom ethereum_berlin_trie : + IsGlobalAlias globals ethereum.berlin.globals "trie". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require ethereum.utils.hexadecimal. +Axiom ethereum_utils_hexadecimal_hex_to_bytes : + IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require blocks. +Axiom blocks_Receipt : + IsGlobalAlias globals blocks.globals "Receipt". + +Require fork_types. +Axiom fork_types_Account : + IsGlobalAlias globals fork_types.globals "Account". +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". +Axiom fork_types_encode_account : + IsGlobalAlias globals fork_types.globals "encode_account". + +Require transactions. +Axiom transactions_LegacyTransaction : + IsGlobalAlias globals transactions.globals "LegacyTransaction". + +Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Root" |), + make_list [ + M.call (| + M.get_name (| globals, "hex_to_bytes" |), + make_list [ + Constant.str "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" + ], + make_dict [] + |) + ], + make_dict [] + |) +)). + +Definition Node : Value.t := M.run ltac:(M.monadic ( + M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Bytes" |); M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |); Constant.None_ ] |) +)). + +Definition K : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "TypeVar" |), + make_list [ + Constant.str "K" + ], + make_dict [] + |) +)). + +Definition V : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "TypeVar" |), + make_list [ + Constant.str "V"; + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Account" |) |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Bytes" |) |); + M.get_name (| globals, "Bytes" |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Bytes" |) ] |) |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Bytes" |) ] |) |); + M.get_name (| globals, "Uint" |); + M.get_name (| globals, "U256" |) + ], + make_dict [] + |) +)). + +Definition LeafNode : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition ExtensionNode : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition BranchNode : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition InternalNode : Value.t := M.run ltac:(M.monadic ( + M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LeafNode" |); M.get_name (| globals, "ExtensionNode" |); M.get_name (| globals, "BranchNode" |) ] |) +)). + +Definition encode_internal_node : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "node" ] |) in + let _ := Constant.str " + Encodes a Merkle Trie node into its RLP form. The RLP will then be + serialized into a `Bytes` and hashed unless it is less that 32 bytes + when serialized. + + This function also accepts `None`, representing the absence of a node, + which is encoded to `b""""""`. + + Parameters + ---------- + node : Optional[InternalNode] + The node to encode. + + Returns + ------- + encoded : `rlp.RLP` + The node encoded as RLP. + " in +(* At stmt: unsupported node type: AnnAssign *) + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "node" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let unencoded := + (* At constant: unsupported node type: Constant *) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "LeafNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "rest_of_key" |); + Constant.bool true + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "ExtensionNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "key_segment" |); + Constant.bool false + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "BranchNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + BinOp.add (| + M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "value" |) + ] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "AssertionError" |), + make_list [ + (* At expr: unsupported node type: JoinedStr *) + ], + make_dict [] + |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let encoded := + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "unencoded" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded" |) + ], + make_dict [] + |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "unencoded" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "encoded" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition encode_node : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "node"; "storage_root" ] |) in + let _ := Constant.str " + Encode a Node for storage in the Merkle Trie. + + Currently mostly an unimplemented stub. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "storage_root" |), Constant.None_ |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "encode_account" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "storage_root" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "U256" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "cast" |), + make_list [ + M.get_field (| M.get_name (| globals, "rlp" |), "RLP" |); + M.get_name (| globals, "node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "node" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "previous_trie" |), "encode_node" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "storage_root" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition Trie : Value.t := + builtins.make_klass + [(* At base: unsupported node type: Subscript *)] + [ + + ] + [ + + ]. + +Definition copy_trie : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie" ] |) in + let _ := Constant.str " + Create a copy of `trie`. Since only frozen objects may be stored in tries, + the contents are reused. + + Parameters + ---------- + trie: `Trie` + Trie to copy. + + Returns + ------- + new_trie : `Trie[K, V]` + A copy of the trie. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Trie" |), + make_list [ + M.get_field (| M.get_name (| globals, "trie" |), "secured" |); + M.get_field (| M.get_name (| globals, "trie" |), "default" |); + M.call (| + M.get_field (| M.get_name (| globals, "copy" |), "copy" |), + make_list [ + M.get_field (| M.get_name (| globals, "trie" |), "_data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition trie_set : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "key"; "value" ] |) in + let _ := Constant.str " + Stores an item in a Merkle Trie. + + This method deletes the key if `value == trie.default`, because the Merkle + Trie represents the default value by omitting it from the trie. + + Parameters + ---------- + trie: `Trie` + Trie to store in. + key : `Bytes` + Key to lookup. + value : `V` + Node to insert at `key`. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "value" |), M.get_field (| M.get_name (| globals, "trie" |), "default" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "key" |), M.get_field (| M.get_name (| globals, "trie" |), "_data" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition trie_get : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "key" ] |) in + let _ := Constant.str " + Gets an item from the Merkle Trie. + + This method returns `trie.default` if the key is missing. + + Parameters + ---------- + trie: + Trie to lookup in. + key : + Key to lookup. + + Returns + ------- + node : `V` + Node at `key` in the trie. + " in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "get" |), + make_list [ + M.get_name (| globals, "key" |); + M.get_field (| M.get_name (| globals, "trie" |), "default" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition common_prefix_length : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "a"; "b" ] |) in + let _ := Constant.str " + Find the longest common prefix of two sequences. + " in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + ], + make_dict [] + |) do + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| M.get_name (| globals, "i" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition nibble_list_to_compact : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "x"; "is_leaf" ] |) in + let _ := Constant.str " + Compresses nibble-list into a standard byte array with a flag. + + A nibble-list is a list of byte values no greater than `15`. The flag is + encoded in high nibble of the highest byte. The flag nibble can be broken + down into two two-bit flags. + + Highest nibble:: + + +---+---+----------+--------+ + | _ | _ | is_leaf | parity | + +---+---+----------+--------+ + 3 2 1 0 + + + The lowest bit of the nibble encodes the parity of the length of the + remaining nibbles -- `0` when even and `1` when odd. The second lowest bit + is used to distinguish leaf and extension nodes. The other two bits are not + used. + + Parameters + ---------- + x : + Array of nibbles. + is_leaf : + True if this is part of a leaf node, or false if it is an extension + node. + + Returns + ------- + compressed : `bytearray` + Compact byte array. + " in + let compact := + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + Constant.int 2 + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.mult (| + Constant.int 16, + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "is_leaf" |) + |) + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + BinOp.add (| + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "is_leaf" |) + |), + Constant.int 1 + |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), Constant.int 0 |) + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 1; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + M.get_name (| globals, "compact" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition bytes_to_nibble_list : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "bytes_" ] |) in + let _ := Constant.str " + Converts a `Bytes` into to a sequence of nibbles (bytes with value < 16). + + Parameters + ---------- + bytes_: + The `Bytes` to convert. + + Returns + ------- + nibble_list : `Bytes` + The `Bytes` in nibble-list format. + " in + let nibble_list := + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [ + BinOp.mult (| + Constant.int 2, + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "bytes_" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + For make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ] in M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "bytes_" |) + ], + make_dict [] + |) do + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |) |), + BinOp.r_shift (| + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 240 + |), + Constant.int 4 + |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |), + Constant.int 1 + |) |), + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 15 + |) + |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + M.get_name (| globals, "nibble_list" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition _prepare_trie : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "get_storage_root" ] |) in + let _ := Constant.str " + Prepares the trie for root calculation. Removes values that are empty, + hashes the keys (if `secured == True`) and encodes all the nodes. + + Parameters + ---------- + trie : + The `Trie` to prepare. + get_storage_root : + Function to get the storage root of an account. Needed to encode + `Account` objects. + + Returns + ------- + out : `Mapping[ethereum.base_types.Bytes, Node]` + Object with keys mapped to nibble-byte form. + " in +(* At stmt: unsupported node type: AnnAssign *) + For make_tuple [ M.get_name (| globals, "preimage" |); M.get_name (| globals, "value" |) ] in M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "items" |), + make_list [], + make_dict [] + |) do + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in + let address := + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |); + M.call (| + M.get_name (| globals, "get_storage_root" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_eq (| M.get_name (| globals, "encoded_value" |), (* At constant: unsupported node type: Constant *) |); + M.get_name (| globals, "AssertionError" |) + ], + make_dict [] + |) in +(* At stmt: unsupported node type: AnnAssign *) + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "trie" |), "secured" |), + (* then *) + ltac:(M.monadic ( + let key := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let key := + M.get_name (| globals, "preimage" |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "mapped" |), M.call (| + M.get_name (| globals, "bytes_to_nibble_list" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |) |), + M.get_name (| globals, "encoded_value" |) + |) in + EndFor. + let _ := M.return_ (| + M.get_name (| globals, "mapped" |) + |) in + M.pure Constant.None_)). + +Definition root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "get_storage_root" ] |) in + let _ := Constant.str " + Computes the root of a modified merkle patricia trie (MPT). + + Parameters + ---------- + trie : + `Trie` to get the root of. + get_storage_root : + Function to get the storage root of an account. Needed to encode + `Account` objects. + + + Returns + ------- + root : `.fork_types.Root` + MPT root of the underlying key-value pairs. + " in + let obj := + M.call (| + M.get_name (| globals, "_prepare_trie" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "get_storage_root" |) + ], + make_dict [] + |) in + let root_node := + M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_name (| globals, "obj" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assert (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "root_node" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Root" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition patricialize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "obj"; "level" ] |) in + let _ := Constant.str " + Structural composition function. + + Used to recursively patricialize and merkleize a dictionary. Includes + memoization of the tree structure and hashes. + + Parameters + ---------- + obj : + Underlying trie key-value pairs, with keys in nibble-list format. + level : + Current trie level. + + Returns + ------- + node : `ethereum.base_types.Bytes` + Root node of `obj`. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let arbitrary_key := + M.call (| + M.get_name (| globals, "next" |), + make_list [ + M.call (| + M.get_name (| globals, "iter" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), Constant.int 1 |), + (* then *) + ltac:(M.monadic ( + let leaf := + M.call (| + M.get_name (| globals, "LeafNode" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |); + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "leaf" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let substring := + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) in + let prefix_length := + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "substring" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do + let prefix_length := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_name (| globals, "prefix_length" |); + M.call (| + M.get_name (| globals, "common_prefix_length" |), + make_list [ + M.get_name (| globals, "substring" |); + M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let prefix := + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ExtensionNode" |), + make_list [ + M.get_name (| globals, "prefix" |); + M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_name (| globals, "obj" |); + BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in +(* At stmt: unsupported node type: AnnAssign *) + For M.get_name (| globals, "_" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 16 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "branches" |), "append" |), + make_list [ + {} + ], + make_dict [] + |) in + EndFor. + let value := + (* At constant: unsupported node type: Constant *) in + For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |), M.get_name (| globals, "level" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "AssertionError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) + |) in + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "BranchNode" |), + make_list [ + [M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "branches" |), M.get_name (| globals, "k" |) |); + BinOp.add (| + M.get_name (| globals, "level" |), + Constant.int 1 + |) + ], + make_dict [] + |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)]; + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/utils/__init__.v b/CoqOfPython/ethereum/london/utils/__init__.v new file mode 100644 index 0000000..1baedea --- /dev/null +++ b/CoqOfPython/ethereum/london/utils/__init__.v @@ -0,0 +1,8 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Utility functions unique to this particular fork. +". diff --git a/CoqOfPython/ethereum/london/utils/address.v b/CoqOfPython/ethereum/london/utils/address.v new file mode 100644 index 0000000..03314ab --- /dev/null +++ b/CoqOfPython/ethereum/london/utils/address.v @@ -0,0 +1,204 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Hardfork Utility Functions For Addresses +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Address specific functions used in this london version of +specification. +". + +Require typing. +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_left_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Definition to_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "data" ] |) in + let _ := Constant.str " + Convert a Uint or U256 value to a valid address (20 bytes). + + Parameters + ---------- + data : + The string to be converted to bytes. + + Returns + ------- + address : `Address` + The obtained address. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_subscript (| M.call (| + M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition compute_contract_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "address"; "nonce" ] |) in + let _ := Constant.str " + Computes address of the new account that needs to be created. + + Parameters + ---------- + address : + The address of the account that wants to create the new account. + nonce : + The transaction count of the account that wants to create the new + account. + + Returns + ------- + address: `Address` + The computed address of the new account. + " in + let computed_address := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_list [ + M.get_name (| globals, "address" |); + M.get_name (| globals, "nonce" |) + ] + ], + make_dict [] + |) + ], + make_dict [] + |) in + let canonical_address := + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + let padded_address := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "canonical_address" |); + Constant.int 20 + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "padded_address" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition compute_create2_contract_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "address"; "salt"; "call_data" ] |) in + let _ := Constant.str " + Computes address of the new account that needs to be created, which is + based on the sender address, salt and the call data as well. + + Parameters + ---------- + address : + The address of the account that wants to create the new account. + salt : + Address generation salt. + call_data : + The code of the new account which is to be created. + + Returns + ------- + address: `ethereum.london.fork_types.Address` + The computed address of the new account. + " in + let preimage := + BinOp.add (| + BinOp.add (| + BinOp.add (| + (* At constant: unsupported node type: Constant *), + M.get_name (| globals, "address" |) + |), + M.get_name (| globals, "salt" |) + |), + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "call_data" |) + ], + make_dict [] + |) + |) in + let computed_address := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + let canonical_address := + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + let padded_address := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "canonical_address" |); + Constant.int 20 + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "padded_address" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/utils/hexadecimal.v b/CoqOfPython/ethereum/london/utils/hexadecimal.v new file mode 100644 index 0000000..f9e532a --- /dev/null +++ b/CoqOfPython/ethereum/london/utils/hexadecimal.v @@ -0,0 +1,155 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Utility Functions For Hexadecimal Strings +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Hexadecimal utility functions used in this specification, specific to +London types. +". + +Require ethereum.utils.hexadecimal. +Axiom ethereum_utils_hexadecimal_remove_hex_prefix : + IsGlobalAlias globals ethereum.utils.hexadecimal.globals "remove_hex_prefix". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Definition hex_to_root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to trie root. + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to trie root. + + Returns + ------- + root : `Root` + Trie root obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Root" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition hex_to_bloom : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to bloom. + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to bloom. + + Returns + ------- + bloom : `Bloom` + Bloom obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bloom" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition hex_to_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to Address (20 bytes). + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to Address. + + Returns + ------- + address : `Address` + The address obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |), "rjust" |), + make_list [ + Constant.int 40; + Constant.str "0" + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/utils/message.v b/CoqOfPython/ethereum/london/utils/message.v new file mode 100644 index 0000000..bd5a2d5 --- /dev/null +++ b/CoqOfPython/ethereum/london/utils/message.v @@ -0,0 +1,254 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Hardfork Utility Functions For The Message Data-structure +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Message specific functions used in this london version of +specification. +". + +Require typing. +Axiom typing_FrozenSet : + IsGlobalAlias globals typing.globals "FrozenSet". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". + +Require vm. +Axiom vm_Environment : + IsGlobalAlias globals vm.globals "Environment". +Axiom vm_Message : + IsGlobalAlias globals vm.globals "Message". + +Require vm.precompiled_contracts.mapping. +Axiom vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : + IsGlobalAlias globals vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". + +Require address. +Axiom address_compute_contract_address : + IsGlobalAlias globals address.globals "compute_contract_address". + +Definition prepare_message : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "caller"; "target"; "value"; "data"; "gas"; "env"; "code_address"; "should_transfer_value"; "is_static"; "preaccessed_addresses"; "preaccessed_storage_keys" ] |) in + let _ := Constant.str " + Execute a transaction against the provided environment. + + Parameters + ---------- + caller : + Address which initiated the transaction + target : + Address whose code will be executed + value : + Value to be transferred. + data : + Array of bytes provided to the code in `target`. + gas : + Gas provided for the code in `target`. + env : + Environment for the Ethereum Virtual Machine. + code_address : + This is usually same as the `target` address except when an alternative + accounts code needs to be executed. + eg. `CALLCODE` calling a precompile. + should_transfer_value : + if True ETH should be transferred while executing a message call. + is_static: + if True then it prevents all state-changing operations from being + executed. + preaccessed_addresses: + Addresses that should be marked as accessed prior to the message call + preaccessed_storage_keys: + Storage keys that should be marked as accessed prior to the message + call + + Returns + ------- + message: `ethereum.london.vm.Message` + Items containing contract creation or message call specific data. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Bytes0" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.call (| + M.get_name (| globals, "compute_contract_address" |), + make_list [ + M.get_name (| globals, "caller" |); + BinOp.sub (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "caller" |) + ], + make_dict [] + |), "nonce" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let msg_data := + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |) in + let code := + M.get_name (| globals, "data" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.get_name (| globals, "target" |) in + let msg_data := + M.get_name (| globals, "data" |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "target" |) + ], + make_dict [] + |), "code" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "code_address" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let code_address := + M.get_name (| globals, "target" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "AssertionError" |), + make_list [ + Constant.str "Target must be address or empty bytes" + ], + make_dict [] + |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let accessed_addresses := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "current_target" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "caller" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "accessed_addresses" |), "update" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "PRE_COMPILED_CONTRACTS" |), "keys" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "accessed_addresses" |), "update" |), + make_list [ + M.get_name (| globals, "preaccessed_addresses" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/vm/__init__.v b/CoqOfPython/ethereum/london/vm/__init__.v new file mode 100644 index 0000000..2ff63cd --- /dev/null +++ b/CoqOfPython/ethereum/london/vm/__init__.v @@ -0,0 +1,262 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The abstract computer which runs the code stored in an +`.fork_types.Account`. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U64 : + IsGlobalAlias globals ethereum.base_types.globals "U64". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_State : + IsGlobalAlias globals state.globals "State". +Axiom state_account_exists_and_is_empty : + IsGlobalAlias globals state.globals "account_exists_and_is_empty". + +Require precompiled_contracts. +Axiom precompiled_contracts_RIPEMD160_ADDRESS : + IsGlobalAlias globals precompiled_contracts.globals "RIPEMD160_ADDRESS". + +Definition __all__ : Value.t := M.run ltac:(M.monadic ( + make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] +)). + +Definition Environment : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Message : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Evm : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition incorporate_child_on_success : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "child_evm" ] |) in + let _ := Constant.str " + Incorporate the state of a successful `child_evm` into the parent `evm`. + + Parameters + ---------- + evm : + The parent `EVM`. + child_evm : + The child evm to incorporate. + " in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "gas_left" |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "logs" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "logs" |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "refund_counter" |) + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "accounts_to_delete" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "accessed_addresses" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "accessed_storage_keys" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition incorporate_child_on_error : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "child_evm" ] |) in + let _ := Constant.str " + Incorporate the state of an unsuccessful `child_evm` into the parent `evm`. + + Parameters + ---------- + evm : + The parent `EVM`. + child_evm : + The child evm to incorporate. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "RIPEMD160_ADDRESS" |), M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |), M.get_name (| globals, "RIPEMD160_ADDRESS" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "gas_left" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/vm/exceptions.v b/CoqOfPython/ethereum/london/vm/exceptions.v new file mode 100644 index 0000000..1f4363d --- /dev/null +++ b/CoqOfPython/ethereum/london/vm/exceptions.v @@ -0,0 +1,172 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Exceptions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Exceptions which cause the EVM to halt exceptionally. +". + +Require ethereum.exceptions. +Axiom ethereum_exceptions_EthereumException : + IsGlobalAlias globals ethereum.exceptions.globals "EthereumException". + +Definition ExceptionalHalt : Value.t := + builtins.make_klass + [(globals, "EthereumException")] + [ + + ] + [ + + ]. + +Definition Revert : Value.t := + builtins.make_klass + [(globals, "EthereumException")] + [ + + ] + [ + + ]. + +Definition StackUnderflowError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition StackOverflowError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition OutOfGasError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition InvalidOpcode : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + ( + "__init__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "code" ] |) in + let _ := M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "super" |), + make_list [], + make_dict [] + |), "__init__" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "self" |), "code" |), + M.get_name (| globals, "code" |) + |) in + M.pure Constant.None_)) + ) + ]. + +Definition InvalidJumpDestError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition StackDepthLimitError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition WriteInStaticContext : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition OutOfBoundsRead : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition InvalidParameter : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition InvalidContractPrefix : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition AddressCollision : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. diff --git a/CoqOfPython/ethereum/london/vm/instructions/__init__.v b/CoqOfPython/ethereum/london/vm/instructions/__init__.v new file mode 100644 index 0000000..e5bebd7 --- /dev/null +++ b/CoqOfPython/ethereum/london/vm/instructions/__init__.v @@ -0,0 +1,87 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +EVM Instruction Encoding (Opcodes) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Machine readable representations of EVM instructions, and a mapping to their +implementations. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". + +Require __init__. +Axiom __init___arithmetic : + IsGlobalAlias globals __init__.globals "arithmetic". + +Require __init__. +Axiom __init___bitwise : + IsGlobalAlias globals __init__.globals "bitwise". + +Require __init__. +Axiom __init___block : + IsGlobalAlias globals __init__.globals "block". + +Require __init__. +Axiom __init___comparison : + IsGlobalAlias globals __init__.globals "comparison". + +Require __init__. +Axiom __init___control_flow : + IsGlobalAlias globals __init__.globals "control_flow". + +Require __init__. +Axiom __init___environment : + IsGlobalAlias globals __init__.globals "environment". + +Require __init__. +Axiom __init___keccak : + IsGlobalAlias globals __init__.globals "keccak". + +Require __init__. +Axiom __init___log : + IsGlobalAlias globals __init__.globals "log". + +Require __init__. +Axiom __init___memory : + IsGlobalAlias globals __init__.globals "memory". + +Require __init__. +Axiom __init___stack : + IsGlobalAlias globals __init__.globals "stack". + +Require __init__. +Axiom __init___storage : + IsGlobalAlias globals __init__.globals "storage". + +Require __init__. +Axiom __init___system : + IsGlobalAlias globals __init__.globals "system". + +Definition Ops : Value.t := + builtins.make_klass + [(* At base: unsupported node type: Attribute *)] + [ + + ] + [ + + ]. + +(* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/london/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/london/vm/instructions/arithmetic.v new file mode 100644 index 0000000..a8b5c61 --- /dev/null +++ b/CoqOfPython/ethereum/london/vm/instructions/arithmetic.v @@ -0,0 +1,1085 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Arithmetic Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM Arithmetic instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U255_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U255_CEIL_VALUE". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_U256_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_get_sign : + IsGlobalAlias globals ethereum.utils.numeric.globals "get_sign". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_EXPONENTIATION : + IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION". +Axiom gas_GAS_EXPONENTIATION_PER_BYTE : + IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION_PER_BYTE". +Axiom gas_GAS_LOW : + IsGlobalAlias globals gas.globals "GAS_LOW". +Axiom gas_GAS_MID : + IsGlobalAlias globals gas.globals "GAS_MID". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition add : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Adds the top two elements of the stack together, and pushes the result back + on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "x" |), "wrapping_add" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition sub : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Subtracts the top two elements of the stack, and pushes the result back + on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "x" |), "wrapping_sub" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mul : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Multiply the top two elements of the stack, and pushes the result back + on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "x" |), "wrapping_mul" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition div : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Integer division of the top two elements of the stack. Pushes the result + back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let dividend := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let divisor := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let quotient := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let quotient := + BinOp.floor_div (| + M.get_name (| globals, "dividend" |), + M.get_name (| globals, "divisor" |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "quotient" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition sdiv : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed integer division of the top two elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let dividend := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let divisor := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let quotient := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_name (| globals, "dividend" |), UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "divisor" |), UnOp.sub (| Constant.int 1 |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let quotient := + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let sign := + M.call (| + M.get_name (| globals, "get_sign" |), + make_list [ + BinOp.mult (| + M.get_name (| globals, "dividend" |), + M.get_name (| globals, "divisor" |) + |) + ], + make_dict [] + |) in + let quotient := + BinOp.mult (| + M.get_name (| globals, "sign" |), + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "dividend" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "divisor" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + M.get_name (| globals, "quotient" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Modulo remainder of the top two elements of the stack. Pushes the result + back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let remainder := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let remainder := + BinOp.mod_ (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "remainder" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition smod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed modulo remainder of the top two elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let y := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let remainder := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let remainder := + BinOp.mult (| + M.call (| + M.get_name (| globals, "get_sign" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + BinOp.mod_ (| + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + M.get_name (| globals, "remainder" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition addmod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Modulo addition of the top 2 elements with the 3rd element. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let z := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_MID" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.add (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |), + M.get_name (| globals, "z" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mulmod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Modulo multiplication of the top 2 elements with the 3rd element. Pushes + the result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let z := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_MID" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.mult (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |), + M.get_name (| globals, "z" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition exp : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Exponential operation of the top 2 elements. Pushes the result back on + the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let base := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exponent := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exponent_bits := + M.call (| + M.get_field (| M.get_name (| globals, "exponent" |), "bit_length" |), + make_list [], + make_dict [] + |) in + let exponent_bytes := + BinOp.floor_div (| + BinOp.add (| + M.get_name (| globals, "exponent_bits" |), + Constant.int 7 + |), + Constant.int 8 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_EXPONENTIATION" |), + BinOp.mult (| + M.get_name (| globals, "GAS_EXPONENTIATION_PER_BYTE" |), + M.get_name (| globals, "exponent_bytes" |) + |) + |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "pow" |), + make_list [ + M.get_name (| globals, "base" |); + M.get_name (| globals, "exponent" |); + M.get_name (| globals, "U256_CEIL_VALUE" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition signextend : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Sign extend operation. In other words, extend a signed number which + fits in N bytes to 32 bytes. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let byte_num := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "byte_num" |), Constant.int 31 |), + (* then *) + ltac:(M.monadic ( + let result := + M.get_name (| globals, "value" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let value_bytes := + M.call (| + M.get_name (| globals, "bytes" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "value" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) in + let value_bytes := + M.get_subscript (| M.get_name (| globals, "value_bytes" |), BinOp.sub (| + Constant.int 31, + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "byte_num" |) + ], + make_dict [] + |) + |):(* At expr: unsupported node type: NoneType *) |) in + let sign_bit := + BinOp.r_shift (| + M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), + Constant.int 7 + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "sign_bit" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "value_bytes" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let num_bytes_prepend := + BinOp.sub (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "byte_num" |), + Constant.int 1 + |) + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + BinOp.add (| + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [ + BinOp.mult (| + make_list [ + Constant.int 255 + ], + M.get_name (| globals, "num_bytes_prepend" |) + |) + ], + make_dict [] + |), + M.get_name (| globals, "value_bytes" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/vm/instructions/bitwise.v b/CoqOfPython/ethereum/london/vm/instructions/bitwise.v new file mode 100644 index 0000000..9f2f382 --- /dev/null +++ b/CoqOfPython/ethereum/london/vm/instructions/bitwise.v @@ -0,0 +1,601 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Bitwise Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM bitwise instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_U256_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition bitwise_and : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise AND operation of the top 2 elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + BinOp.bit_and (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_or : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise OR operation of the top 2 elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + BinOp.bit_or (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_xor : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise XOR operation of the top 2 elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + BinOp.bit_xor (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_not : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise NOT operation of the top element of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + UnOp.invert (| M.get_name (| globals, "x" |) |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition get_byte : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + For a word (defined by next top element of the stack), retrieve the + Nth byte (0-indexed and defined by top element of stack) from the + left (most significant) to right (least significant). + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let byte_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let word := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "byte_index" |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let extra_bytes_to_right := + BinOp.sub (| + Constant.int 31, + M.get_name (| globals, "byte_index" |) + |) in + let word := + BinOp.r_shift (| + M.get_name (| globals, "word" |), + BinOp.mult (| + M.get_name (| globals, "extra_bytes_to_right" |), + Constant.int 8 + |) + |) in + let word := + BinOp.bit_and (| + M.get_name (| globals, "word" |), + Constant.int 255 + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "word" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_shl : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Logical shift left (SHL) operation of the top 2 elements of the stack. + Pushes the result back on the stack. + Parameters + ---------- + evm : + The current EVM frame. + " in + let shift := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.l_shift (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "shift" |) + |), + M.get_name (| globals, "U256_CEIL_VALUE" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_shr : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Logical shift right (SHR) operation of the top 2 elements of the stack. + Pushes the result back on the stack. + Parameters + ---------- + evm : + The current EVM frame. + " in + let shift := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), + (* then *) + ltac:(M.monadic ( + let result := + BinOp.r_shift (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "shift" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_sar : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Arithmetic shift right (SAR) operation of the top 2 elements of the stack. + Pushes the result back on the stack. + Parameters + ---------- + evm : + The current EVM frame. + " in + let shift := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let signed_value := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + BinOp.r_shift (| + M.get_name (| globals, "signed_value" |), + M.get_name (| globals, "shift" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "signed_value" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/vm/instructions/block.v b/CoqOfPython/ethereum/london/vm/instructions/block.v new file mode 100644 index 0000000..26c73a7 --- /dev/null +++ b/CoqOfPython/ethereum/london/vm/instructions/block.v @@ -0,0 +1,379 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Block Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM block instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_BLOCK_HASH : + IsGlobalAlias globals gas.globals "GAS_BLOCK_HASH". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition block_hash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the hash of one of the 256 most recent complete blocks onto the + stack. The block number to hash is present at the top of the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let block_number := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BLOCK_HASH" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt_e (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), M.get_name (| globals, "block_number" |) |), + ltac:(M.monadic ( + Compare.gt (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), BinOp.add (| + M.get_name (| globals, "block_number" |), + Constant.int 256 + |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let hash := + (* At constant: unsupported node type: Constant *) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let hash := + M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + M.get_name (| globals, "block_number" |) + |) |) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "hash" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition coinbase : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's beneficiary address (address of the block miner) + onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "coinbase" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition timestamp : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's timestamp onto the stack. Here the timestamp + being referred is actually the unix timestamp in seconds. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "time" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition number : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's number onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition difficulty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's difficulty onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "difficulty" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition gas_limit : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's gas limit onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "gas_limit" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition chain_id : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the chain id onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "chain_id" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/vm/instructions/comparison.v b/CoqOfPython/ethereum/london/vm/instructions/comparison.v new file mode 100644 index 0000000..fbc35f8 --- /dev/null +++ b/CoqOfPython/ethereum/london/vm/instructions/comparison.v @@ -0,0 +1,404 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Comparison Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM Comparison instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition less_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is less than the next top element. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let right := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition signed_less_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed less-than comparison. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let right := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition greater_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is greater than the next top element. Pushes + the result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let right := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition signed_greater_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed greater-than comparison. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let right := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition equal : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is equal to the next top element. Pushes + the result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let right := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.eq (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition is_zero : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is equal to 0. Pushes the result back on the + stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.eq (| M.get_name (| globals, "x" |), Constant.int 0 |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/vm/instructions/control_flow.v b/CoqOfPython/ethereum/london/vm/instructions/control_flow.v new file mode 100644 index 0000000..04a79d9 --- /dev/null +++ b/CoqOfPython/ethereum/london/vm/instructions/control_flow.v @@ -0,0 +1,336 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Control Flow Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM control flow instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require vm.gas. +Axiom vm_gas_GAS_BASE : + IsGlobalAlias globals vm.gas.globals "GAS_BASE". +Axiom vm_gas_GAS_HIGH : + IsGlobalAlias globals vm.gas.globals "GAS_HIGH". +Axiom vm_gas_GAS_JUMPDEST : + IsGlobalAlias globals vm.gas.globals "GAS_JUMPDEST". +Axiom vm_gas_GAS_MID : + IsGlobalAlias globals vm.gas.globals "GAS_MID". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_InvalidJumpDestError : + IsGlobalAlias globals exceptions.globals "InvalidJumpDestError". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition stop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stop further execution of EVM code. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let _ := M.pass (| |) in + let _ := M.pass (| |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "running" |), + Constant.bool false + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition jump : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Alter the program counter to the location specified by the top of the + stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let jump_dest := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_MID" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "jump_dest" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition jumpi : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Alter the program counter to the specified location if and only if a + condition is true. If the condition is not true, then the program counter + would increase only by 1. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let jump_dest := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let conditional_value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_HIGH" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "conditional_value" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let destination := + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let destination := + M.get_name (| globals, "jump_dest" |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "destination" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition pc : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push onto the stack the value of the program counter after reaching the + current instruction and without increasing it for the next instruction. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "pc" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition gas_left : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the amount of available gas (including the corresponding reduction + for the cost of this instruction) onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition jumpdest : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Mark a valid destination for jumps. This is a noop, present only + to be used by `JUMP` and `JUMPI` opcodes to verify that their jump is + valid. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_JUMPDEST" |) + ], + make_dict [] + |) in + let _ := M.pass (| |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/vm/instructions/environment.v b/CoqOfPython/ethereum/london/vm/instructions/environment.v new file mode 100644 index 0000000..530304e --- /dev/null +++ b/CoqOfPython/ethereum/london/vm/instructions/environment.v @@ -0,0 +1,1436 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Environmental Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM environment related instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require fork_types. +Axiom fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". + +Require state. +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". + +Require utils.address. +Axiom utils_address_to_address : + IsGlobalAlias globals utils.address.globals "to_address". + +Require vm.memory. +Axiom vm_memory_buffer_read : + IsGlobalAlias globals vm.memory.globals "buffer_read". +Axiom vm_memory_memory_write : + IsGlobalAlias globals vm.memory.globals "memory_write". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_OutOfBoundsRead : + IsGlobalAlias globals exceptions.globals "OutOfBoundsRead". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_COLD_ACCOUNT_ACCESS : + IsGlobalAlias globals gas.globals "GAS_COLD_ACCOUNT_ACCESS". +Axiom gas_GAS_COPY : + IsGlobalAlias globals gas.globals "GAS_COPY". +Axiom gas_GAS_FAST_STEP : + IsGlobalAlias globals gas.globals "GAS_FAST_STEP". +Axiom gas_GAS_RETURN_DATA_COPY : + IsGlobalAlias globals gas.globals "GAS_RETURN_DATA_COPY". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_GAS_WARM_ACCESS : + IsGlobalAlias globals gas.globals "GAS_WARM_ACCESS". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the address of the current executing account to the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition balance : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the balance of the given account onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "balance" |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "balance" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition origin : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the address of the original transaction sender to the stack. + The origin address can only be an EOA. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "origin" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition caller : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the address of the caller onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "caller" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition callvalue : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the value (in wei) sent with the call onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition calldataload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push a word (32 bytes) of the input data belonging to the current + environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |); + M.get_name (| globals, "start_index" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition calldatasize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the size of input data in current environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition calldatacopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy a portion of the input data in current environment to memory. + + This will also expand the memory, in case that the memory is insufficient + to store the data. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let data_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |); + M.get_name (| globals, "data_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition codesize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the size of code running in current environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "code" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition codecopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy a portion of the code in current environment to memory. + + This will also expand the memory, in case that the memory is insufficient + to store the data. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let code_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "code" |); + M.get_name (| globals, "code_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition gasprice : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the gas price used in current environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "gas_price" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition extcodesize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the code size of a given account onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let codesize := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "code" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "codesize" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition extcodecopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy a portion of an account's code to memory. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let code_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_WARM_ACCESS" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "code" |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "code" |); + M.get_name (| globals, "code_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition returndatasize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the size of the return data buffer onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition returndatacopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copies data from the return data buffer code to memory + + Parameters + ---------- + evm : + The current EVM frame. + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let return_data_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_RETURN_DATA_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "return_data_start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "OutOfBoundsRead" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |):BinOp.add (| + M.get_name (| globals, "return_data_start_position" |), + M.get_name (| globals, "size" |) + |) |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition extcodehash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Returns the keccak256 hash of a contract’s bytecode + Parameters + ---------- + evm : + The current EVM frame. + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "account" |), M.get_name (| globals, "EMPTY_ACCOUNT" |) |), + (* then *) + ltac:(M.monadic ( + let codehash := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let codehash := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_field (| M.get_name (| globals, "account" |), "code" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "codehash" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition self_balance : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the balance of the current address to the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_FAST_STEP" |) + ], + make_dict [] + |) in + let balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "balance" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition base_fee : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the base fee of the current block on to the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "base_fee_per_gas" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/vm/instructions/keccak.v b/CoqOfPython/ethereum/london/vm/instructions/keccak.v new file mode 100644 index 0000000..cab9ffb --- /dev/null +++ b/CoqOfPython/ethereum/london/vm/instructions/keccak.v @@ -0,0 +1,181 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Keccak Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM keccak instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_KECCAK256 : + IsGlobalAlias globals gas.globals "GAS_KECCAK256". +Axiom gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition keccak : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes to the stack the Keccak-256 hash of a region of memory. + + This also expands the memory, in case the memory is insufficient to + access the data's memory location. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let word_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_KECCAK256_WORD" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_KECCAK256" |), + M.get_name (| globals, "word_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let data := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "hash" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/vm/instructions/log.v b/CoqOfPython/ethereum/london/vm/instructions/log.v new file mode 100644 index 0000000..4891a4d --- /dev/null +++ b/CoqOfPython/ethereum/london/vm/instructions/log.v @@ -0,0 +1,244 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Logging Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM logging instructions. +". + +Require functools. +Axiom functools_partial : + IsGlobalAlias globals functools.globals "partial". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_WriteInStaticContext : + IsGlobalAlias globals exceptions.globals "WriteInStaticContext". + +Require gas. +Axiom gas_GAS_LOG : + IsGlobalAlias globals gas.globals "GAS_LOG". +Axiom gas_GAS_LOG_DATA : + IsGlobalAlias globals gas.globals "GAS_LOG_DATA". +Axiom gas_GAS_LOG_TOPIC : + IsGlobalAlias globals gas.globals "GAS_LOG_TOPIC". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". + +Definition log_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "num_topics" ] |) in + let _ := Constant.str " + Appends a log entry, having `num_topics` topics, to the evm logs. + + This will also expand the memory if the data (required by the log entry) + corresponding to the memory is not accessible. + + Parameters + ---------- + evm : + The current EVM frame. + num_topics : + The number of topics to be included in the log entry. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let topics := + make_list [] in + For M.get_name (| globals, "_" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "num_topics" |) + ], + make_dict [] + |) do + let topic := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "topics" |), "append" |), + make_list [ + M.get_name (| globals, "topic" |) + ], + make_dict [] + |) in + EndFor. + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_LOG" |), + BinOp.mult (| + M.get_name (| globals, "GAS_LOG_DATA" |), + M.get_name (| globals, "size" |) + |) + |), + BinOp.mult (| + M.get_name (| globals, "GAS_LOG_TOPIC" |), + M.get_name (| globals, "num_topics" |) + |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let log_entry := + M.call (| + M.get_name (| globals, "Log" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "logs" |), + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "logs" |), + make_tuple [ M.get_name (| globals, "log_entry" |) ] + |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition log0 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/london/vm/instructions/memory.v b/CoqOfPython/ethereum/london/vm/instructions/memory.v new file mode 100644 index 0000000..1e1c8b0 --- /dev/null +++ b/CoqOfPython/ethereum/london/vm/instructions/memory.v @@ -0,0 +1,378 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Memory Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM Memory instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". +Axiom memory_memory_write : + IsGlobalAlias globals memory.globals "memory_write". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition mstore : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a word to memory. + This also expands the memory, if the memory is + insufficient to store the word. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "start_position" |); M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + ], + make_dict [] + |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "start_position" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mstore8 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a byte to memory. + This also expands the memory, if the memory is + insufficient to store the word. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "start_position" |); M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let normalized_bytes_value := + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + make_list [ + BinOp.bit_and (| + M.get_name (| globals, "value" |), + Constant.int 255 + |) + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "start_position" |); + M.get_name (| globals, "normalized_bytes_value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Load word from memory. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "start_position" |); M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "start_position" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition msize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the size of active memory in bytes onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/vm/instructions/stack.v b/CoqOfPython/ethereum/london/vm/instructions/stack.v new file mode 100644 index 0000000..1eeda05 --- /dev/null +++ b/CoqOfPython/ethereum/london/vm/instructions/stack.v @@ -0,0 +1,929 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Stack Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM stack related instructions. +". + +Require functools. +Axiom functools_partial : + IsGlobalAlias globals functools.globals "partial". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". +Axiom __init___stack : + IsGlobalAlias globals __init__.globals "stack". + +Require exceptions. +Axiom exceptions_StackUnderflowError : + IsGlobalAlias globals exceptions.globals "StackUnderflowError". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_buffer_read : + IsGlobalAlias globals memory.globals "buffer_read". + +Definition pop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Remove item from stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.pass (| |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition push_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "num_bytes" ] |) in + let _ := Constant.str " + Pushes a N-byte immediate onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + num_bytes : + The number of immediate bytes to be read from the code and pushed to + the stack. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let data_to_push := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "code" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "num_bytes" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "data_to_push" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + BinOp.add (| + Constant.int 1, + M.get_name (| globals, "num_bytes" |) + |) + |) in + M.pure Constant.None_)). + +Definition dup_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "item_number" ] |) in + let _ := Constant.str " + Duplicate the Nth stack item (from top of the stack) to the top of stack. + + Parameters + ---------- + evm : + The current EVM frame. + + item_number : + The stack item number (0-indexed from top of stack) to be duplicated + to the top of stack. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "StackUnderflowError" |) + ], + make_dict [] + |) in + let data_to_duplicate := + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + BinOp.sub (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), + Constant.int 1 + |), + M.get_name (| globals, "item_number" |) + |) |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "data_to_duplicate" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition swap_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "item_number" ] |) in + let _ := Constant.str " + Swap the top and the `item_number` element of the stack, where + the top of the stack is position zero. + + If `item_number` is zero, this function does nothing (which should not be + possible, since there is no `SWAP0` instruction). + + Parameters + ---------- + evm : + The current EVM frame. + + item_number : + The stack item number (0-indexed from top of stack) to be swapped + with the top of stack element. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "StackUnderflowError" |) + ], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) |) ], + make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |) ] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition push1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push5 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push6 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push7 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push8 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push9 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push10 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push11 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push12 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push13 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push14 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push15 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push16 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push17 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push18 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push19 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push20 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push21 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push22 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push23 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push24 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push25 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push26 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push27 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push28 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push29 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push30 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push31 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push32 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition dup1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup5 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup6 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup7 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup8 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup9 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup10 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup11 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup12 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup13 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup14 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup15 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup16 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition swap1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap5 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap6 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap7 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap8 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap9 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap10 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap11 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap12 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap13 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap14 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap15 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap16 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/london/vm/instructions/storage.v b/CoqOfPython/ethereum/london/vm/instructions/storage.v new file mode 100644 index 0000000..2f0a831 --- /dev/null +++ b/CoqOfPython/ethereum/london/vm/instructions/storage.v @@ -0,0 +1,437 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Storage Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM storage related instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require state. +Axiom state_get_storage : + IsGlobalAlias globals state.globals "get_storage". +Axiom state_get_storage_original : + IsGlobalAlias globals state.globals "get_storage_original". +Axiom state_set_storage : + IsGlobalAlias globals state.globals "set_storage". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". +Axiom exceptions_WriteInStaticContext : + IsGlobalAlias globals exceptions.globals "WriteInStaticContext". + +Require gas. +Axiom gas_GAS_CALL_STIPEND : + IsGlobalAlias globals gas.globals "GAS_CALL_STIPEND". +Axiom gas_GAS_COLD_SLOAD : + IsGlobalAlias globals gas.globals "GAS_COLD_SLOAD". +Axiom gas_GAS_STORAGE_CLEAR_REFUND : + IsGlobalAlias globals gas.globals "GAS_STORAGE_CLEAR_REFUND". +Axiom gas_GAS_STORAGE_SET : + IsGlobalAlias globals gas.globals "GAS_STORAGE_SET". +Axiom gas_GAS_STORAGE_UPDATE : + IsGlobalAlias globals gas.globals "GAS_STORAGE_UPDATE". +Axiom gas_GAS_WARM_ACCESS : + IsGlobalAlias globals gas.globals "GAS_WARM_ACCESS". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition sload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Loads to the stack, the value corresponding to a certain key from the + storage of the current account. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let key := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "add" |), + make_list [ + make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_COLD_SLOAD" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let value := + M.call (| + M.get_name (| globals, "get_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition sstore : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a value at a certain key in the current context's storage. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let key := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let new_value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt (| M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), M.get_name (| globals, "GAS_CALL_STIPEND" |) |); + M.get_name (| globals, "OutOfGasError" |) + ], + make_dict [] + |) in + let original_value := + M.call (| + M.get_name (| globals, "get_storage_original" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let current_value := + M.call (| + M.get_name (| globals, "get_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let gas_cost := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "add" |), + make_list [ + make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ] + ], + make_dict [] + |) in + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_COLD_SLOAD" |) + M.get_name (| globals, "GAS_COLD_SLOAD" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_name (| globals, "original_value" |), M.get_name (| globals, "current_value" |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_name (| globals, "current_value" |), M.get_name (| globals, "new_value" |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_STORAGE_SET" |) + M.get_name (| globals, "GAS_STORAGE_SET" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let gas_cost := BinOp.add + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_UPDATE" |), + M.get_name (| globals, "GAS_COLD_SLOAD" |) + |) + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_UPDATE" |), + M.get_name (| globals, "GAS_COLD_SLOAD" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_WARM_ACCESS" |) + M.get_name (| globals, "GAS_WARM_ACCESS" |) in + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| M.get_name (| globals, "current_value" |), M.get_name (| globals, "new_value" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "new_value" |), Constant.int 0 |) + )) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.sub, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "original_value" |), M.get_name (| globals, "new_value" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_SET" |), + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.sub (| + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_UPDATE" |), + M.get_name (| globals, "GAS_COLD_SLOAD" |) + |), + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "gas_cost" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "set_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |); + M.get_name (| globals, "new_value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/vm/interpreter.v b/CoqOfPython/ethereum/london/vm/interpreter.v new file mode 100644 index 0000000..8179355 --- /dev/null +++ b/CoqOfPython/ethereum/london/vm/interpreter.v @@ -0,0 +1,645 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Interpreter +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +A straightforward interpreter that executes EVM code. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Iterable : + IsGlobalAlias globals typing.globals "Iterable". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.trace. +Axiom ethereum_trace_EvmStop : + IsGlobalAlias globals ethereum.trace.globals "EvmStop". +Axiom ethereum_trace_OpEnd : + IsGlobalAlias globals ethereum.trace.globals "OpEnd". +Axiom ethereum_trace_OpException : + IsGlobalAlias globals ethereum.trace.globals "OpException". +Axiom ethereum_trace_OpStart : + IsGlobalAlias globals ethereum.trace.globals "OpStart". +Axiom ethereum_trace_PrecompileEnd : + IsGlobalAlias globals ethereum.trace.globals "PrecompileEnd". +Axiom ethereum_trace_PrecompileStart : + IsGlobalAlias globals ethereum.trace.globals "PrecompileStart". +Axiom ethereum_trace_TransactionEnd : + IsGlobalAlias globals ethereum.trace.globals "TransactionEnd". +Axiom ethereum_trace_evm_trace : + IsGlobalAlias globals ethereum.trace.globals "evm_trace". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_account_exists_and_is_empty : + IsGlobalAlias globals state.globals "account_exists_and_is_empty". +Axiom state_account_has_code_or_nonce : + IsGlobalAlias globals state.globals "account_has_code_or_nonce". +Axiom state_begin_transaction : + IsGlobalAlias globals state.globals "begin_transaction". +Axiom state_commit_transaction : + IsGlobalAlias globals state.globals "commit_transaction". +Axiom state_destroy_storage : + IsGlobalAlias globals state.globals "destroy_storage". +Axiom state_increment_nonce : + IsGlobalAlias globals state.globals "increment_nonce". +Axiom state_mark_account_created : + IsGlobalAlias globals state.globals "mark_account_created". +Axiom state_move_ether : + IsGlobalAlias globals state.globals "move_ether". +Axiom state_rollback_transaction : + IsGlobalAlias globals state.globals "rollback_transaction". +Axiom state_set_code : + IsGlobalAlias globals state.globals "set_code". +Axiom state_touch_account : + IsGlobalAlias globals state.globals "touch_account". + +Require vm. +Axiom vm_Message : + IsGlobalAlias globals vm.globals "Message". + +Require vm.gas. +Axiom vm_gas_GAS_CODE_DEPOSIT : + IsGlobalAlias globals vm.gas.globals "GAS_CODE_DEPOSIT". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require vm.precompiled_contracts.mapping. +Axiom vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : + IsGlobalAlias globals vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". + +Require __init__. +Axiom __init___Environment : + IsGlobalAlias globals __init__.globals "Environment". +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_AddressCollision : + IsGlobalAlias globals exceptions.globals "AddressCollision". +Axiom exceptions_ExceptionalHalt : + IsGlobalAlias globals exceptions.globals "ExceptionalHalt". +Axiom exceptions_InvalidContractPrefix : + IsGlobalAlias globals exceptions.globals "InvalidContractPrefix". +Axiom exceptions_InvalidOpcode : + IsGlobalAlias globals exceptions.globals "InvalidOpcode". +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". +Axiom exceptions_Revert : + IsGlobalAlias globals exceptions.globals "Revert". +Axiom exceptions_StackDepthLimitError : + IsGlobalAlias globals exceptions.globals "StackDepthLimitError". + +Require instructions. +Axiom instructions_Ops : + IsGlobalAlias globals instructions.globals "Ops". +Axiom instructions_op_implementation : + IsGlobalAlias globals instructions.globals "op_implementation". + +Require runtime. +Axiom runtime_get_valid_jump_destinations : + IsGlobalAlias globals runtime.globals "get_valid_jump_destinations". + +Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1024 + ], + make_dict [] + |) +)). + +Definition MAX_CODE_SIZE : Value.t := M.run ltac:(M.monadic ( + Constant.int 24576 +)). + +Definition MessageCallOutput : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition process_message_call : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + If `message.current` is empty then it creates a smart contract + else it executes a call from the `message.caller` to the `message.target`. + + Parameters + ---------- + message : + Transaction specific items. + + env : + External items required for EVM execution. + + Returns + ------- + output : `MessageCallOutput` + Output of the message call + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_name (| globals, "message" |), "target" |), M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let is_collision := + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_name (| globals, "is_collision" |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallOutput" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "tuple" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "AddressCollision" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let evm := + M.call (| + M.get_name (| globals, "process_create_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let evm := + M.call (| + M.get_name (| globals, "process_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_field (| M.get_name (| globals, "message" |), "target" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_field (| M.get_name (| globals, "message" |), "target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( +(* At stmt: unsupported node type: AnnAssign *) + let accounts_to_delete := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let touched_accounts := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let refund_counter := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let logs := + M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in + let accounts_to_delete := + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in + let touched_accounts := + M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |) in + let refund_counter := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let tx_end := + M.call (| + M.get_name (| globals, "TransactionEnd" |), + make_list [ + BinOp.sub (| + M.get_field (| M.get_name (| globals, "message" |), "gas" |), + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + |); + M.get_field (| M.get_name (| globals, "evm" |), "output" |); + M.get_field (| M.get_name (| globals, "evm" |), "error" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "evm_trace" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "tx_end" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallOutput" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition process_create_message : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + Executes a call to create a smart contract. + + Parameters + ---------- + message : + Transaction specific items. + env : + External items required for EVM execution. + + Returns + ------- + evm: :py:class:`~ethereum.london.vm.Evm` + Items containing execution specific objects. + " in + let _ := M.call (| + M.get_name (| globals, "begin_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "destroy_storage" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "mark_account_created" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let evm := + M.call (| + M.get_name (| globals, "process_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), + (* then *) + ltac:(M.monadic ( + let contract_code := + M.get_field (| M.get_name (| globals, "evm" |), "output" |) in + let contract_code_gas := + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "contract_code" |) + ], + make_dict [] + |), + M.get_name (| globals, "GAS_CODE_DEPOSIT" |) + |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "rollback_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.get_name (| globals, "evm" |) + |) in + M.pure Constant.None_)). + +Definition process_message : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + Executes a call to create a smart contract. + + Parameters + ---------- + message : + Transaction specific items. + env : + External items required for EVM execution. + + Returns + ------- + evm: :py:class:`~ethereum.london.vm.Evm` + Items containing execution specific objects + " in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_field (| M.get_name (| globals, "message" |), "depth" |), M.get_name (| globals, "STACK_DEPTH_LIMIT" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "StackDepthLimitError" |), + make_list [ + Constant.str "Stack depth limit reached" + ], + make_dict [] + |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "begin_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "touch_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + M.get_field (| M.get_name (| globals, "message" |), "should_transfer_value" |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_field (| M.get_name (| globals, "message" |), "value" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "move_ether" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "caller" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |); + M.get_field (| M.get_name (| globals, "message" |), "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let evm := + M.call (| + M.get_name (| globals, "execute_code" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "rollback_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "commit_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.get_name (| globals, "evm" |) + |) in + M.pure Constant.None_)). + +Definition execute_code : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + Executes bytecode present in the `message`. + + Parameters + ---------- + message : + Transaction specific items. + env : + External items required for EVM execution. + + Returns + ------- + evm: `ethereum.vm.EVM` + Items containing execution specific objects + " in + let code := + M.get_field (| M.get_name (| globals, "message" |), "code" |) in + let valid_jump_destinations := + M.call (| + M.get_name (| globals, "get_valid_jump_destinations" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) in + let evm := + M.call (| + M.get_name (| globals, "Evm" |), + make_list [], + make_dict [] + |) in +(* At stmt: unsupported node type: Try *) + let _ := M.return_ (| + M.get_name (| globals, "evm" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/vm/memory.v b/CoqOfPython/ethereum/london/vm/memory.v new file mode 100644 index 0000000..fa8d906 --- /dev/null +++ b/CoqOfPython/ethereum/london/vm/memory.v @@ -0,0 +1,153 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Memory +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +EVM memory operations. +". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_right_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "right_pad_zero_bytes". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". + +Definition memory_write : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "memory"; "start_position"; "value" ] |) in + let _ := Constant.str " + Writes to memory. + + Parameters + ---------- + memory : + Memory contents of the EVM. + start_position : + Starting pointer to the memory. + value : + Data to write to memory. + " in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) |), + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_)). + +Definition memory_read_bytes : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "memory"; "start_position"; "size" ] |) in + let _ := Constant.str " + Read bytes from memory. + + Parameters + ---------- + memory : + Memory contents of the EVM. + start_position : + Starting pointer to the memory. + size : + Size of the data that needs to be read from `start_position`. + + Returns + ------- + data_bytes : + Data read from memory. + " in + let _ := M.return_ (| + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |) + |) in + M.pure Constant.None_)). + +Definition buffer_read : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "buffer"; "start_position"; "size" ] |) in + let _ := Constant.str " + Read bytes from a buffer. Padding with zeros if necessary. + + Parameters + ---------- + buffer : + Memory contents of the EVM. + start_position : + Starting pointer to the memory. + size : + Size of the data that needs to be read from `start_position`. + + Returns + ------- + data_bytes : + Data read from memory. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "right_pad_zero_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/london/vm/precompiled_contracts/__init__.v new file mode 100644 index 0000000..ca49311 --- /dev/null +++ b/CoqOfPython/ethereum/london/vm/precompiled_contracts/__init__.v @@ -0,0 +1,117 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Precompiled Contract Addresses +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Addresses of precompiled contracts and mappings to their +implementations. +". + +Require utils.hexadecimal. +Axiom utils_hexadecimal_hex_to_address : + IsGlobalAlias globals utils.hexadecimal.globals "hex_to_address". + +Definition __all__ : Value.t := M.run ltac:(M.monadic ( + make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS"; Constant.str "MODEXP_ADDRESS"; Constant.str "ALT_BN128_ADD_ADDRESS"; Constant.str "ALT_BN128_MUL_ADDRESS"; Constant.str "ALT_BN128_PAIRING_CHECK_ADDRESS"; Constant.str "BLAKE2F_ADDRESS" ] +)). + +Definition ECRECOVER_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x01" + ], + make_dict [] + |) +)). + +Definition SHA256_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x02" + ], + make_dict [] + |) +)). + +Definition RIPEMD160_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x03" + ], + make_dict [] + |) +)). + +Definition IDENTITY_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x04" + ], + make_dict [] + |) +)). + +Definition MODEXP_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x05" + ], + make_dict [] + |) +)). + +Definition ALT_BN128_ADD_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x06" + ], + make_dict [] + |) +)). + +Definition ALT_BN128_MUL_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x07" + ], + make_dict [] + |) +)). + +Definition ALT_BN128_PAIRING_CHECK_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x08" + ], + make_dict [] + |) +)). + +Definition BLAKE2F_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x09" + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/london/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/london/vm/precompiled_contracts/alt_bn128.v new file mode 100644 index 0000000..19b83fc --- /dev/null +++ b/CoqOfPython/ethereum/london/vm/precompiled_contracts/alt_bn128.v @@ -0,0 +1,673 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) ALT_BN128 CONTRACTS +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the ALT_BN128 precompiled contracts. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.alt_bn128. +Axiom ethereum_crypto_alt_bn128_ALT_BN128_CURVE_ORDER : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "ALT_BN128_CURVE_ORDER". +Axiom ethereum_crypto_alt_bn128_ALT_BN128_PRIME : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "ALT_BN128_PRIME". +Axiom ethereum_crypto_alt_bn128_BNF : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF". +Axiom ethereum_crypto_alt_bn128_BNF2 : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF2". +Axiom ethereum_crypto_alt_bn128_BNF12 : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF12". +Axiom ethereum_crypto_alt_bn128_BNP : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNP". +Axiom ethereum_crypto_alt_bn128_BNP2 : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNP2". +Axiom ethereum_crypto_alt_bn128_pairing : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "pairing". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require vm.memory. +Axiom vm_memory_buffer_read : + IsGlobalAlias globals vm.memory.globals "buffer_read". + +Require exceptions. +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". + +Definition alt_bn128_add : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + The ALT_BN128 addition precompiled contract. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 150 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x0_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x0_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "x0_bytes" |) + ], + make_dict [] + |) in + let y0_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y0_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "y0_bytes" |) + ], + make_dict [] + |) in + let x1_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x1_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "x1_bytes" |) + ], + make_dict [] + |) in + let y1_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y1_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "y1_bytes" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ] do + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "i" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. +(* At stmt: unsupported node type: Try *) + let p := + BinOp.add (| + M.get_name (| globals, "p0" |), + M.get_name (| globals, "p1" |) + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + BinOp.add (| + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "p" |), "x" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "p" |), "y" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) + |) in + M.pure Constant.None_)). + +Definition alt_bn128_mul : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + The ALT_BN128 multiplication precompiled contract. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 6000 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x0_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x0_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "x0_bytes" |) + ], + make_dict [] + |) in + let y0_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y0_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "y0_bytes" |) + ], + make_dict [] + |) in + let n := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ] do + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "i" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. +(* At stmt: unsupported node type: Try *) + let p := + M.call (| + M.get_field (| M.get_name (| globals, "p0" |), "mul_by" |), + make_list [ + M.get_name (| globals, "n" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + BinOp.add (| + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "p" |), "x" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "p" |), "y" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) + |) in + M.pure Constant.None_)). + +Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + The ALT_BN128 pairing check precompiled contract. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 34000, + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 192 + |) + |), + Constant.int 45000 + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 192 + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 192 + |) + ], + make_dict [] + |) do + let values := + make_list [] in + For M.get_name (| globals, "j" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 6 + ], + make_dict [] + |) do + let value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "data" |), BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + M.get_name (| globals, "j" |) + |) + |):BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "j" |), + Constant.int 1 + |) + |) + |) |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "value" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "values" |), "append" |), + make_list [ + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + EndFor. +(* At stmt: unsupported node type: Try *) + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.call (| + M.get_field (| M.get_name (| globals, "p" |), "mul_by" |), + make_list [ + M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) + ], + make_dict [] + |), M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) |); + M.get_name (| globals, "OutOfGasError" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.call (| + M.get_field (| M.get_name (| globals, "q" |), "mul_by" |), + make_list [ + M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) + ], + make_dict [] + |), M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) |); + M.get_name (| globals, "OutOfGasError" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "p" |), M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_name (| globals, "q" |), M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let result := + BinOp.mult (| + M.get_name (| globals, "result" |), + M.call (| + M.get_name (| globals, "pairing" |), + make_list [ + M.get_name (| globals, "q" |); + M.get_name (| globals, "p" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "result" |), M.call (| + M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/vm/precompiled_contracts/blake2f.v b/CoqOfPython/ethereum/london/vm/precompiled_contracts/blake2f.v new file mode 100644 index 0000000..5903066 --- /dev/null +++ b/CoqOfPython/ethereum/london/vm/precompiled_contracts/blake2f.v @@ -0,0 +1,122 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Blake2 PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `Blake2` precompiled contract. +". + +Require ethereum.crypto.blake2. +Axiom ethereum_crypto_blake2_Blake2b : + IsGlobalAlias globals ethereum.crypto.blake2.globals "Blake2b". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_BLAKE2_PER_ROUND : + IsGlobalAlias globals vm.gas.globals "GAS_BLAKE2_PER_ROUND". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require exceptions. +Axiom exceptions_InvalidParameter : + IsGlobalAlias globals exceptions.globals "InvalidParameter". + +Definition blake2f : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the Blake2 hash to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), Constant.int 213 |); + M.get_name (| globals, "InvalidParameter" |) + ], + make_dict [] + |) in + let blake2b := + M.call (| + M.get_name (| globals, "Blake2b" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "rounds" |); M.get_name (| globals, "h" |); M.get_name (| globals, "m" |); M.get_name (| globals, "t_0" |); M.get_name (| globals, "t_1" |); M.get_name (| globals, "f" |) ], + M.call (| + M.get_field (| M.get_name (| globals, "blake2b" |), "get_blake2_parameters" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.mult (| + M.get_name (| globals, "GAS_BLAKE2_PER_ROUND" |), + M.get_name (| globals, "rounds" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.in (| M.get_name (| globals, "f" |), make_list [ + Constant.int 0; + Constant.int 1 + ] |); + M.get_name (| globals, "InvalidParameter" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.get_name (| globals, "blake2b" |), "compress" |), + make_list [ + M.get_name (| globals, "rounds" |); + M.get_name (| globals, "h" |); + M.get_name (| globals, "m" |); + M.get_name (| globals, "t_0" |); + M.get_name (| globals, "t_1" |); + M.get_name (| globals, "f" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/london/vm/precompiled_contracts/ecrecover.v new file mode 100644 index 0000000..cc351b5 --- /dev/null +++ b/CoqOfPython/ethereum/london/vm/precompiled_contracts/ecrecover.v @@ -0,0 +1,269 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) ECRECOVER PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the ECRECOVER precompiled contract. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require ethereum.crypto.elliptic_curve. +Axiom ethereum_crypto_elliptic_curve_SECP256K1N : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_left_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_ECRECOVER : + IsGlobalAlias globals vm.gas.globals "GAS_ECRECOVER". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require vm.memory. +Axiom vm_memory_buffer_read : + IsGlobalAlias globals vm.memory.globals "buffer_read". + +Definition ecrecover : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Decrypts the address using elliptic curve DSA recovery mechanism and writes + the address to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_ECRECOVER" |) + ], + make_dict [] + |) in + let message_hash_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let message_hash := + M.call (| + M.get_name (| globals, "Hash32" |), + make_list [ + M.get_name (| globals, "message_hash_bytes" |) + ], + make_dict [] + |) in + let v := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let r := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let s := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 27 |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 28 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| Constant.int 0, M.get_name (| globals, "r" |) |), + ltac:(M.monadic ( + Compare.gt_e (| M.get_name (| globals, "r" |), M.get_name (| globals, "SECP256K1N" |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| Constant.int 0, M.get_name (| globals, "s" |) |), + ltac:(M.monadic ( + Compare.gt_e (| M.get_name (| globals, "s" |), M.get_name (| globals, "SECP256K1N" |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in +(* At stmt: unsupported node type: Try *) + let address := + M.get_subscript (| M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), Constant.int 12:Constant.int 32 |) in + let padded_address := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "address" |); + Constant.int 32 + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.get_name (| globals, "padded_address" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/london/vm/precompiled_contracts/identity.v new file mode 100644 index 0000000..fa96704 --- /dev/null +++ b/CoqOfPython/ethereum/london/vm/precompiled_contracts/identity.v @@ -0,0 +1,94 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) IDENTITY PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `IDENTITY` precompiled contract. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_IDENTITY : + IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY". +Axiom vm_gas_GAS_IDENTITY_WORD : + IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY_WORD". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition identity : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the message data to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let word_count := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_IDENTITY" |), + BinOp.mult (| + M.get_name (| globals, "GAS_IDENTITY_WORD" |), + M.get_name (| globals, "word_count" |) + |) + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.get_name (| globals, "data" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/london/vm/precompiled_contracts/mapping.v new file mode 100644 index 0000000..8a2e2eb --- /dev/null +++ b/CoqOfPython/ethereum/london/vm/precompiled_contracts/mapping.v @@ -0,0 +1,82 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Precompiled Contract Addresses +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Mapping of precompiled contracts their implementations. +". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require __init__. +Axiom __init___ALT_BN128_ADD_ADDRESS : + IsGlobalAlias globals __init__.globals "ALT_BN128_ADD_ADDRESS". +Axiom __init___ALT_BN128_MUL_ADDRESS : + IsGlobalAlias globals __init__.globals "ALT_BN128_MUL_ADDRESS". +Axiom __init___ALT_BN128_PAIRING_CHECK_ADDRESS : + IsGlobalAlias globals __init__.globals "ALT_BN128_PAIRING_CHECK_ADDRESS". +Axiom __init___BLAKE2F_ADDRESS : + IsGlobalAlias globals __init__.globals "BLAKE2F_ADDRESS". +Axiom __init___ECRECOVER_ADDRESS : + IsGlobalAlias globals __init__.globals "ECRECOVER_ADDRESS". +Axiom __init___IDENTITY_ADDRESS : + IsGlobalAlias globals __init__.globals "IDENTITY_ADDRESS". +Axiom __init___MODEXP_ADDRESS : + IsGlobalAlias globals __init__.globals "MODEXP_ADDRESS". +Axiom __init___RIPEMD160_ADDRESS : + IsGlobalAlias globals __init__.globals "RIPEMD160_ADDRESS". +Axiom __init___SHA256_ADDRESS : + IsGlobalAlias globals __init__.globals "SHA256_ADDRESS". + +Require alt_bn128. +Axiom alt_bn128_alt_bn128_add : + IsGlobalAlias globals alt_bn128.globals "alt_bn128_add". +Axiom alt_bn128_alt_bn128_mul : + IsGlobalAlias globals alt_bn128.globals "alt_bn128_mul". +Axiom alt_bn128_alt_bn128_pairing_check : + IsGlobalAlias globals alt_bn128.globals "alt_bn128_pairing_check". + +Require blake2f. +Axiom blake2f_blake2f : + IsGlobalAlias globals blake2f.globals "blake2f". + +Require ecrecover. +Axiom ecrecover_ecrecover : + IsGlobalAlias globals ecrecover.globals "ecrecover". + +Require identity. +Axiom identity_identity : + IsGlobalAlias globals identity.globals "identity". + +Require modexp. +Axiom modexp_modexp : + IsGlobalAlias globals modexp.globals "modexp". + +Require ripemd160. +Axiom ripemd160_ripemd160 : + IsGlobalAlias globals ripemd160.globals "ripemd160". + +Require sha256. +Axiom sha256_sha256 : + IsGlobalAlias globals sha256.globals "sha256". + +(* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/london/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/london/vm/precompiled_contracts/modexp.v new file mode 100644 index 0000000..544949e --- /dev/null +++ b/CoqOfPython/ethereum/london/vm/precompiled_contracts/modexp.v @@ -0,0 +1,608 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) MODEXP PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `MODEXP` precompiled contract. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require memory. +Axiom memory_buffer_read : + IsGlobalAlias globals memory.globals "buffer_read". + +Definition GQUADDIVISOR : Value.t := M.run ltac:(M.monadic ( + Constant.int 3 +)). + +Definition modexp : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Calculates `(base**exp) % modulus` for arbitrary sized `base`, `exp` and. + `modulus`. The return value is the same length as the modulus. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let base_length := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exp_length := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let modulus_length := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exp_start := + BinOp.add (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |), + M.get_name (| globals, "base_length" |) + |) in + let exp_head := + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.get_name (| globals, "exp_start" |); + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.get_name (| globals, "exp_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "gas_cost" |), + make_list [ + M.get_name (| globals, "base_length" |); + M.get_name (| globals, "modulus_length" |); + M.get_name (| globals, "exp_length" |); + M.get_name (| globals, "exp_head" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_name (| globals, "base_length" |), Constant.int 0 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "modulus_length" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [], + make_dict [] + |) + |) in + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let base := + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |); + M.get_name (| globals, "base_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exp := + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.get_name (| globals, "exp_start" |); + M.get_name (| globals, "exp_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let modulus_start := + BinOp.add (| + M.get_name (| globals, "exp_start" |), + M.get_name (| globals, "exp_length" |) + |) in + let modulus := + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.get_name (| globals, "modulus_start" |); + M.get_name (| globals, "modulus_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "modulus" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + BinOp.mult (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |), + M.get_name (| globals, "modulus_length" |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pow" |), + make_list [ + M.get_name (| globals, "base" |); + M.get_name (| globals, "exp" |); + M.get_name (| globals, "modulus" |) + ], + make_dict [] + |) + ], + make_dict [] + |), "to_bytes" |), + make_list [ + M.get_name (| globals, "modulus_length" |); + Constant.str "big" + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition complexity : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "base_length"; "modulus_length" ] |) in + let _ := Constant.str " + Estimate the complexity of performing a modular exponentiation. + + Parameters + ---------- + + base_length : + Length of the array representing the base integer. + + modulus_length : + Length of the array representing the modulus integer. + + Returns + ------- + + complexity : `Uint` + Complexity of performing the operation. + " in + let max_length := + M.call (| + M.get_name (| globals, "max" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "base_length" |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "modulus_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + BinOp.add (| + M.get_name (| globals, "max_length" |), + Constant.int 7 + |), + Constant.int 8 + |) in + let _ := M.return_ (| + BinOp.pow (| + M.get_name (| globals, "words" |), + Constant.int 2 + |) + |) in + M.pure Constant.None_)). + +Definition iterations : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "exponent_length"; "exponent_head" ] |) in + let _ := Constant.str " + Calculate the number of iterations required to perform a modular + exponentiation. + + Parameters + ---------- + + exponent_length : + Length of the array representing the exponent integer. + + exponent_head : + First 32 bytes of the exponent (with leading zero padding if it is + shorter than 32 bytes), as an unsigned integer. + + Returns + ------- + + iterations : `Uint` + Number of iterations. + " in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.lt_e (| M.get_name (| globals, "exponent_length" |), Constant.int 32 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "exponent_head" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let count := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| M.get_name (| globals, "exponent_length" |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let bit_length := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "exponent_head" |), "bit_length" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "bit_length" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let bit_length := BinOp.sub + Constant.int 1 + Constant.int 1 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let count := + M.get_name (| globals, "bit_length" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let length_part := + BinOp.mult (| + Constant.int 8, + BinOp.sub (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "exponent_length" |) + ], + make_dict [] + |), + Constant.int 32 + |) + |) in + let bits_part := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "exponent_head" |), "bit_length" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "bits_part" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let bits_part := BinOp.sub + Constant.int 1 + Constant.int 1 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let count := + BinOp.add (| + M.get_name (| globals, "length_part" |), + M.get_name (| globals, "bits_part" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "max" |), + make_list [ + M.get_name (| globals, "count" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition gas_cost : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "base_length"; "modulus_length"; "exponent_length"; "exponent_head" ] |) in + let _ := Constant.str " + Calculate the gas cost of performing a modular exponentiation. + + Parameters + ---------- + + base_length : + Length of the array representing the base integer. + + modulus_length : + Length of the array representing the modulus integer. + + exponent_length : + Length of the array representing the exponent integer. + + exponent_head : + First 32 bytes of the exponent (with leading zero padding if it is + shorter than 32 bytes), as an unsigned integer. + + Returns + ------- + + gas_cost : `Uint` + Gas required for performing the operation. + " in + let multiplication_complexity := + M.call (| + M.get_name (| globals, "complexity" |), + make_list [ + M.get_name (| globals, "base_length" |); + M.get_name (| globals, "modulus_length" |) + ], + make_dict [] + |) in + let iteration_count := + M.call (| + M.get_name (| globals, "iterations" |), + make_list [ + M.get_name (| globals, "exponent_length" |); + M.get_name (| globals, "exponent_head" |) + ], + make_dict [] + |) in + let cost := + BinOp.mult (| + M.get_name (| globals, "multiplication_complexity" |), + M.get_name (| globals, "iteration_count" |) + |) in + let cost := BinOp.floor_div + M.get_name (| globals, "GQUADDIVISOR" |) + M.get_name (| globals, "GQUADDIVISOR" |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "max" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 200 + ], + make_dict [] + |); + M.get_name (| globals, "cost" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/london/vm/precompiled_contracts/ripemd160.v new file mode 100644 index 0000000..96f8dcd --- /dev/null +++ b/CoqOfPython/ethereum/london/vm/precompiled_contracts/ripemd160.v @@ -0,0 +1,122 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) RIPEMD160 PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `RIPEMD160` precompiled contract. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_left_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_RIPEMD160 : + IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160". +Axiom vm_gas_GAS_RIPEMD160_WORD : + IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160_WORD". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition ripemd160 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the ripemd160 hash to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let word_count := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_RIPEMD160" |), + BinOp.mult (| + M.get_name (| globals, "GAS_RIPEMD160_WORD" |), + M.get_name (| globals, "word_count" |) + |) + |) + ], + make_dict [] + |) in + let hash_bytes := + M.call (| + M.get_field (| M.call (| + M.get_field (| M.get_name (| globals, "hashlib" |), "new" |), + make_list [ + Constant.str "ripemd160"; + M.get_name (| globals, "data" |) + ], + make_dict [] + |), "digest" |), + make_list [], + make_dict [] + |) in + let padded_hash := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "hash_bytes" |); + Constant.int 32 + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.get_name (| globals, "padded_hash" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/london/vm/precompiled_contracts/sha256.v new file mode 100644 index 0000000..9f6d2bf --- /dev/null +++ b/CoqOfPython/ethereum/london/vm/precompiled_contracts/sha256.v @@ -0,0 +1,106 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) SHA256 PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `SHA256` precompiled contract. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_SHA256 : + IsGlobalAlias globals vm.gas.globals "GAS_SHA256". +Axiom vm_gas_GAS_SHA256_WORD : + IsGlobalAlias globals vm.gas.globals "GAS_SHA256_WORD". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition sha256 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the sha256 hash to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let word_count := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_SHA256" |), + BinOp.mult (| + M.get_name (| globals, "GAS_SHA256_WORD" |), + M.get_name (| globals, "word_count" |) + |) + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_field (| M.get_name (| globals, "hashlib" |), "sha256" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), "digest" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/vm/runtime.v b/CoqOfPython/ethereum/london/vm/runtime.v new file mode 100644 index 0000000..835b46c --- /dev/null +++ b/CoqOfPython/ethereum/london/vm/runtime.v @@ -0,0 +1,125 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Runtime Operations +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Runtime related operations used while executing EVM code. +". + +Require typing. +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require instructions. +Axiom instructions_Ops : + IsGlobalAlias globals instructions.globals "Ops". + +Definition get_valid_jump_destinations : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "code" ] |) in + let _ := Constant.str " + Analyze the evm code to obtain the set of valid jump destinations. + + Valid jump destinations are defined as follows: + * The jump destination is less than the length of the code. + * The jump destination should have the `JUMPDEST` opcode (0x5B). + * The jump destination shouldn't be part of the data corresponding to + `PUSH-N` opcodes. + + Note - Jump destinations are 0-indexed. + + Parameters + ---------- + code : + The EVM code which is to be executed. + + Returns + ------- + valid_jump_destinations: `Set[Uint]` + The set of valid jump destinations in the code. + " in + let valid_jump_destinations := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let pc := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + While Compare.lt (| M.get_name (| globals, "pc" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) |) do +(* At stmt: unsupported node type: Try *) + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "current_opcode" |), M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), + make_list [ + M.get_name (| globals, "pc" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + (* At expr: unsupported node type: Compare *), + (* then *) + ltac:(M.monadic ( + let push_data_size := + BinOp.add (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) + |), + Constant.int 1 + |) in + let pc := BinOp.add + M.get_name (| globals, "push_data_size" |) + M.get_name (| globals, "push_data_size" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let pc := BinOp.add + Constant.int 1 + Constant.int 1 in + EndWhile. + let _ := M.return_ (| + M.get_name (| globals, "valid_jump_destinations" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/vm/stack.v b/CoqOfPython/ethereum/london/vm/stack.v new file mode 100644 index 0000000..42ea42d --- /dev/null +++ b/CoqOfPython/ethereum/london/vm/stack.v @@ -0,0 +1,120 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Stack +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the stack operators for the EVM. +". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require exceptions. +Axiom exceptions_StackOverflowError : + IsGlobalAlias globals exceptions.globals "StackOverflowError". +Axiom exceptions_StackUnderflowError : + IsGlobalAlias globals exceptions.globals "StackUnderflowError". + +Definition pop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "stack" ] |) in + let _ := Constant.str " + Pops the top item off of `stack`. + + Parameters + ---------- + stack : + EVM stack. + + Returns + ------- + value : `U256` + The top element on the stack. + + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "StackUnderflowError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "pop" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition push : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "stack"; "value" ] |) in + let _ := Constant.str " + Pushes `value` onto `stack`. + + Parameters + ---------- + stack : + EVM stack. + + value : + Item to be pushed onto `stack`. + + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), Constant.int 1024 |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "StackOverflowError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "append" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/__init__.v b/CoqOfPython/ethereum/muir_glacier/__init__.v new file mode 100644 index 0000000..35111c4 --- /dev/null +++ b/CoqOfPython/ethereum/muir_glacier/__init__.v @@ -0,0 +1,23 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +The Muir Glacier fork delays the difficulty bomb. There are no other changes +in this fork. +". + +Require ethereum.fork_criteria. +Axiom ethereum_fork_criteria_ByBlockNumber : + IsGlobalAlias globals ethereum.fork_criteria.globals "ByBlockNumber". + +Definition FORK_CRITERIA : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "ByBlockNumber" |), + make_list [ + Constant.int 9200000 + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/muir_glacier/blocks.v b/CoqOfPython/ethereum/muir_glacier/blocks.v new file mode 100644 index 0000000..6501788 --- /dev/null +++ b/CoqOfPython/ethereum/muir_glacier/blocks.v @@ -0,0 +1,93 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +A `Block` is a single link in the chain that is Ethereum. Each `Block` contains +a `Header` and zero or more transactions. Each `Header` contains associated +metadata like the block number, parent block hash, and how much gas was +consumed by its transactions. + +Together, these blocks form a cryptographically secure journal recording the +history of all state transitions that have happened since the genesis of the +chain. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes8 : + IsGlobalAlias globals base_types.globals "Bytes8". +Axiom base_types_Bytes32 : + IsGlobalAlias globals base_types.globals "Bytes32". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require crypto.hash. +Axiom crypto_hash_Hash32 : + IsGlobalAlias globals crypto.hash.globals "Hash32". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Require transactions. +Axiom transactions_Transaction : + IsGlobalAlias globals transactions.globals "Transaction". + +Definition Header : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Block : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Log : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Receipt : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. diff --git a/CoqOfPython/ethereum/muir_glacier/bloom.v b/CoqOfPython/ethereum/muir_glacier/bloom.v new file mode 100644 index 0000000..04b5d9f --- /dev/null +++ b/CoqOfPython/ethereum/muir_glacier/bloom.v @@ -0,0 +1,164 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Logs Bloom +^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +This modules defines functions for calculating bloom filters of logs. For the +general theory of bloom filters see e.g. `Wikipedia +`_. Bloom filters are used to allow +for efficient searching of logs by address and/or topic, by rapidly +eliminating blocks and receipts from their search. +". + +Require typing. +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require fork_types. +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". + +Definition add_to_bloom : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "bloom"; "bloom_entry" ] |) in + let _ := Constant.str " + Add a bloom entry to the bloom filter (`bloom`). + + The number of hash functions used is 3. They are calculated by taking the + least significant 11 bits from the first 3 16-bit words of the + `keccak_256()` hash of `bloom_entry`. + + Parameters + ---------- + bloom : + The bloom filter. + bloom_entry : + An entry which is to be added to bloom filter. + " in + let hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "bloom_entry" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "idx" |) in make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ] do + let bit_to_set := + BinOp.bit_and (| + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |):BinOp.add (| + M.get_name (| globals, "idx" |), + Constant.int 2 + |) |) + ], + make_dict [] + |), + Constant.int 2047 + |) in + let bit_index := + BinOp.sub (| + Constant.int 2047, + M.get_name (| globals, "bit_to_set" |) + |) in + let byte_index := + BinOp.floor_div (| + M.get_name (| globals, "bit_index" |), + Constant.int 8 + |) in + let bit_value := + BinOp.l_shift (| + Constant.int 1, + BinOp.sub (| + Constant.int 7, + BinOp.mod_ (| + M.get_name (| globals, "bit_index" |), + Constant.int 8 + |) + |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), + BinOp.bit_or (| + M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), + M.get_name (| globals, "bit_value" |) + |) + |) in + EndFor. + M.pure Constant.None_)). + +Definition logs_bloom : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "logs" ] |) in + let _ := Constant.str " + Obtain the logs bloom from a list of log entries. + + The address and each topic of a log are added to the bloom filter. + + Parameters + ---------- + logs : + List of logs for which the logs bloom is to be obtained. + + Returns + ------- + logs_bloom : `Bloom` + The logs bloom obtained which is 256 bytes with some bits set as per + the caller address and the log topics. + " in +(* At stmt: unsupported node type: AnnAssign *) + For M.get_name (| globals, "log" |) in M.get_name (| globals, "logs" |) do + let _ := M.call (| + M.get_name (| globals, "add_to_bloom" |), + make_list [ + M.get_name (| globals, "bloom" |); + M.get_field (| M.get_name (| globals, "log" |), "address" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "topic" |) in M.get_field (| M.get_name (| globals, "log" |), "topics" |) do + let _ := M.call (| + M.get_name (| globals, "add_to_bloom" |), + make_list [ + M.get_name (| globals, "bloom" |); + M.get_name (| globals, "topic" |) + ], + make_dict [] + |) in + EndFor. + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bloom" |), + make_list [ + M.get_name (| globals, "bloom" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/fork_types.v b/CoqOfPython/ethereum/muir_glacier/fork_types.v new file mode 100644 index 0000000..d12953d --- /dev/null +++ b/CoqOfPython/ethereum/muir_glacier/fork_types.v @@ -0,0 +1,102 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Types +^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Types re-used throughout the specification, which are specific to Ethereum. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes20 : + IsGlobalAlias globals base_types.globals "Bytes20". +Axiom base_types_Bytes256 : + IsGlobalAlias globals base_types.globals "Bytes256". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require crypto.hash. +Axiom crypto_hash_Hash32 : + IsGlobalAlias globals crypto.hash.globals "Hash32". +Axiom crypto_hash_keccak256 : + IsGlobalAlias globals crypto.hash.globals "keccak256". + +Definition Address : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Bytes20" |) +)). + +Definition Root : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Hash32" |) +)). + +Definition Bloom : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Bytes256" |) +)). + +Definition Account : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition EMPTY_ACCOUNT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Account" |), + make_list [], + make_dict [] + |) +)). + +Definition encode_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "raw_account_data"; "storage_root" ] |) in + let _ := Constant.str " + Encode `Account` dataclass. + + Storage is not stored in the `Account` dataclass, so `Accounts` cannot be + encoded with providing a storage root. + " in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "raw_account_data" |), "nonce" |); M.get_field (| M.get_name (| globals, "raw_account_data" |), "balance" |); M.get_name (| globals, "storage_root" |); M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_field (| M.get_name (| globals, "raw_account_data" |), "code" |) + ], + make_dict [] + |) ] + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/state.v b/CoqOfPython/ethereum/muir_glacier/state.v new file mode 100644 index 0000000..7b038e5 --- /dev/null +++ b/CoqOfPython/ethereum/muir_glacier/state.v @@ -0,0 +1,1184 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +State +^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The state contains all information that is preserved between transactions. + +It consists of a main account trie and storage tries for each contract. + +There is a distinction between an account that does not exist and +`EMPTY_ACCOUNT`. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_field : + IsGlobalAlias globals dataclasses.globals "field". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_modify : + IsGlobalAlias globals ethereum.base_types.globals "modify". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require fork_types. +Axiom fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". +Axiom fork_types_Account : + IsGlobalAlias globals fork_types.globals "Account". +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Require trie. +Axiom trie_EMPTY_TRIE_ROOT : + IsGlobalAlias globals trie.globals "EMPTY_TRIE_ROOT". +Axiom trie_Trie : + IsGlobalAlias globals trie.globals "Trie". +Axiom trie_copy_trie : + IsGlobalAlias globals trie.globals "copy_trie". +Axiom trie_root : + IsGlobalAlias globals trie.globals "root". +Axiom trie_trie_get : + IsGlobalAlias globals trie.globals "trie_get". +Axiom trie_trie_set : + IsGlobalAlias globals trie.globals "trie_set". + +Definition State : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition close_state : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Free resources held by the state. Used by optimized implementations to + release file descriptors. + " in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) |) in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |) in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |) |) in + M.pure Constant.None_)). + +Definition begin_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Start a state transaction. + + Transactions are entirely implicit and can be nested. It is not possible to + calculate the state root during a transaction. + + Parameters + ---------- + state : State + The state. + " in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), "append" |), + make_list [ + make_tuple [ M.call (| + M.get_name (| globals, "copy_trie" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) + ], + make_dict [] + |); {M.get_name (| globals, "k" |): M.call (| + M.get_name (| globals, "copy_trie" |), + make_list [ + M.get_name (| globals, "t" |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)} ] + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition commit_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Commit a state transaction. + + Parameters + ---------- + state : State + The state. + " in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), "pop" |), + make_list [], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "clear" |), + make_list [], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition rollback_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Rollback a state transaction, resetting the state to the point when the + corresponding `start_transaction()` call was made. + + Parameters + ---------- + state : State + The state. + " in + let _ := M.assign (| + make_tuple [ M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) ], + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), "pop" |), + make_list [], + make_dict [] + |) + |) in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "clear" |), + make_list [], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition get_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Get the `Account` object at an address. Returns `EMPTY_ACCOUNT` if there + is no account at the address. + + Use `get_account_optional()` if you care about the difference between a + non-existent account and `EMPTY_ACCOUNT`. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address to lookup. + + Returns + ------- + account : `Account` + Account at address. + " in + let account := + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "account" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "account" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "EMPTY_ACCOUNT" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition get_account_optional : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Get the `Account` object at an address. Returns `None` (rather than + `EMPTY_ACCOUNT`) if there is no account at the address. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address to lookup. + + Returns + ------- + account : `Account` + Account at address. + " in + let account := + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "account" |) + |) in + M.pure Constant.None_)). + +Definition set_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "account" ] |) in + let _ := Constant.str " + Set the `Account` object at an address. Setting to `None` deletes + the account (but not its storage, see `destroy_account()`). + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address to set. + account : `Account` + Account to set at address. + " in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "account" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition destroy_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Completely remove the account at `address` and all of its storage. + + This function is made available exclusively for the `SELFDESTRUCT` + opcode. It is expected that `SELFDESTRUCT` will be disabled in a future + hardfork and this function will be removed. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of account to destroy. + " in + let _ := M.call (| + M.get_name (| globals, "destroy_storage" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + Constant.None_ + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition destroy_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Completely remove the storage at `address`. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of account whose storage is to be deleted. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition mark_account_created : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Mark an account as having been created in the current transaction. + This information is used by `get_storage_original()` to handle an obscure + edgecase. + + The marker is not removed even if the account creation reverts. Since the + account cannot have had code prior to its creation and can't call + `get_storage_original()`, this is harmless. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of the account that has been created. + " in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition get_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "key" ] |) in + let _ := Constant.str " + Get a value at a storage key on an account. Returns `U256(0)` if the + storage key has not been set previously. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of the account. + key : `Bytes` + Key to lookup. + + Returns + ------- + value : `U256` + Value at the key. + " in + let trie := + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let _ := M.assert (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "U256" |) + ], + make_dict [] + |) |) in + let _ := M.return_ (| + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_)). + +Definition set_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "key"; "value" ] |) in + let _ := Constant.str " + Set a value at a storage key on an account. Setting to `U256(0)` deletes + the key. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of the account. + key : `Bytes` + Key to set. + value : `U256` + Value to set at the key. + " in + let _ := M.assert (| Compare.is_not (| M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), Constant.None_ |) |) in + let trie := + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let trie := + M.call (| + M.get_name (| globals, "Trie" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), + M.get_name (| globals, "trie" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "key" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), {} |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition storage_root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Calculate the storage root of an account. + + Parameters + ---------- + state: + The state + address : + Address of the account. + + Returns + ------- + root : `Root` + Storage root of the account. + " in + let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "EMPTY_TRIE_ROOT" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition state_root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Calculate the state root. + + Parameters + ---------- + state: + The current state. + + Returns + ------- + root : `Root` + The state root. + " in + let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition account_exists : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account exists in the state trie + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + account_exists : `bool` + True if account exists in the state trie, False otherwise + " in + let _ := M.return_ (| + Compare.is_not (| M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), Constant.None_ |) + |) in + M.pure Constant.None_)). + +Definition account_has_code_or_nonce : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account has non zero nonce or non empty code + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + has_code_or_nonce : `bool` + True if if an account has non zero nonce or non empty code, + False otherwise. + " in + let account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + BoolOp.or (| + Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |) + )) + |) + |) in + M.pure Constant.None_)). + +Definition is_account_empty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account has zero nonce, empty code and zero balance. + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + is_empty : `bool` + True if if an account has zero nonce, empty code and zero balance, + False otherwise. + " in + let account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + ltac:(M.monadic ( + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + )) + |) + )) + |) + |) in + M.pure Constant.None_)). + +Definition account_exists_and_is_empty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account exists and has zero nonce, empty code and zero + balance. + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + exists_and_is_empty : `bool` + True if an account exists and has zero nonce, empty code and zero + balance, False otherwise. + " in + let account := + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + BoolOp.and (| + Compare.is_not (| M.get_name (| globals, "account" |), Constant.None_ |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + ltac:(M.monadic ( + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + )) + |) + )) + |) + )) + |) + |) in + M.pure Constant.None_)). + +Definition is_account_alive : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Check whether is an account is both in the state and non empty. + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + is_alive : `bool` + True if the account is alive. + " in + let account := + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "account" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + UnOp.not (| BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + ltac:(M.monadic ( + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + )) + |) + )) + |) |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition modify_state : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "f" ] |) in + let _ := Constant.str " + Modify an `Account` in the `State`. + " in + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.call (| + M.get_name (| globals, "modify" |), + make_list [ + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |); + M.get_name (| globals, "f" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition move_ether : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "sender_address"; "recipient_address"; "amount" ] |) in + let _ := Constant.str " + Move funds between accounts. + " in +(* At stmt: unsupported node type: FunctionDef *) +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "sender_address" |); + M.get_name (| globals, "reduce_sender_balance" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "recipient_address" |); + M.get_name (| globals, "increase_recipient_balance" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition set_account_balance : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "amount" ] |) in + let _ := Constant.str " + Sets the balance of an account. + + Parameters + ---------- + state: + The current state. + + address: + Address of the account whose nonce needs to be incremented. + + amount: + The amount that needs to set in balance. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "set_balance" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition touch_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Initializes an account to state. + + Parameters + ---------- + state: + The current state. + + address: + The address of the account that need to initialised. + " in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "account_exists" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "EMPTY_ACCOUNT" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition increment_nonce : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Increments the nonce of an account. + + Parameters + ---------- + state: + The current state. + + address: + Address of the account whose nonce needs to be incremented. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "increase_nonce" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition set_code : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "code" ] |) in + let _ := Constant.str " + Sets Account code. + + Parameters + ---------- + state: + The current state. + + address: + Address of the account whose code needs to be update. + + code: + The bytecode that needs to be set. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "write_code" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition create_ether : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "amount" ] |) in + let _ := Constant.str " + Add newly created ether to an account. + + Parameters + ---------- + state: + The current state. + address: + Address of the account to which ether is added. + amount: + The amount of ether to be added to the account of interest. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "increase_balance" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition get_storage_original : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "key" ] |) in + let _ := Constant.str " + Get the original value in a storage slot i.e. the value before the current + transaction began. This function reads the value from the snapshots taken + before executing the transaction. + + Parameters + ---------- + state: + The current state. + address: + Address of the account to read the value from. + key: + Key of the storage slot. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "_" |); M.get_name (| globals, "original_trie" |) ], + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), Constant.int 0 |) + |) in + let original_account_trie := + M.call (| + M.get_field (| M.get_name (| globals, "original_trie" |), "get" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "original_account_trie" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let original_value := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let original_value := + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_name (| globals, "original_account_trie" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.assert (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "original_value" |); + M.get_name (| globals, "U256" |) + ], + make_dict [] + |) |) in + let _ := M.return_ (| + M.get_name (| globals, "original_value" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/transactions.v b/CoqOfPython/ethereum/muir_glacier/transactions.v new file mode 100644 index 0000000..f94a3bd --- /dev/null +++ b/CoqOfPython/ethereum/muir_glacier/transactions.v @@ -0,0 +1,60 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Transactions are atomic units of work created externally to Ethereum and +submitted to be executed. If Ethereum is viewed as a state machine, +transactions are the events that move between states. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes0 : + IsGlobalAlias globals base_types.globals "Bytes0". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( + Constant.int 21000 +)). + +Definition TX_DATA_COST_PER_NON_ZERO : Value.t := M.run ltac:(M.monadic ( + Constant.int 16 +)). + +Definition TX_DATA_COST_PER_ZERO : Value.t := M.run ltac:(M.monadic ( + Constant.int 4 +)). + +Definition TX_CREATE_COST : Value.t := M.run ltac:(M.monadic ( + Constant.int 32000 +)). + +Definition Transaction : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. diff --git a/CoqOfPython/ethereum/muir_glacier/trie.v b/CoqOfPython/ethereum/muir_glacier/trie.v new file mode 100644 index 0000000..0a7e5af --- /dev/null +++ b/CoqOfPython/ethereum/muir_glacier/trie.v @@ -0,0 +1,1357 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +State Trie +^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The state trie is the structure responsible for storing +`.fork_types.Account` objects. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_field : + IsGlobalAlias globals dataclasses.globals "field". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". +Axiom typing_Generic : + IsGlobalAlias globals typing.globals "Generic". +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Mapping : + IsGlobalAlias globals typing.globals "Mapping". +Axiom typing_MutableMapping : + IsGlobalAlias globals typing.globals "MutableMapping". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Sequence : + IsGlobalAlias globals typing.globals "Sequence". +Axiom typing_TypeVar : + IsGlobalAlias globals typing.globals "TypeVar". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". +Axiom typing_cast : + IsGlobalAlias globals typing.globals "cast". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.istanbul. +Axiom ethereum_istanbul_trie : + IsGlobalAlias globals ethereum.istanbul.globals "trie". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require ethereum.utils.hexadecimal. +Axiom ethereum_utils_hexadecimal_hex_to_bytes : + IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require blocks. +Axiom blocks_Receipt : + IsGlobalAlias globals blocks.globals "Receipt". + +Require fork_types. +Axiom fork_types_Account : + IsGlobalAlias globals fork_types.globals "Account". +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". +Axiom fork_types_encode_account : + IsGlobalAlias globals fork_types.globals "encode_account". + +Require transactions. +Axiom transactions_Transaction : + IsGlobalAlias globals transactions.globals "Transaction". + +Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Root" |), + make_list [ + M.call (| + M.get_name (| globals, "hex_to_bytes" |), + make_list [ + Constant.str "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" + ], + make_dict [] + |) + ], + make_dict [] + |) +)). + +Definition Node : Value.t := M.run ltac:(M.monadic ( + M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Bytes" |); M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |); Constant.None_ ] |) +)). + +Definition K : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "TypeVar" |), + make_list [ + Constant.str "K" + ], + make_dict [] + |) +)). + +Definition V : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "TypeVar" |), + make_list [ + Constant.str "V"; + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Account" |) |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Bytes" |) |); + M.get_name (| globals, "Bytes" |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Transaction" |) |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Receipt" |) |); + M.get_name (| globals, "Uint" |); + M.get_name (| globals, "U256" |) + ], + make_dict [] + |) +)). + +Definition LeafNode : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition ExtensionNode : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition BranchNode : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition InternalNode : Value.t := M.run ltac:(M.monadic ( + M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LeafNode" |); M.get_name (| globals, "ExtensionNode" |); M.get_name (| globals, "BranchNode" |) ] |) +)). + +Definition encode_internal_node : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "node" ] |) in + let _ := Constant.str " + Encodes a Merkle Trie node into its RLP form. The RLP will then be + serialized into a `Bytes` and hashed unless it is less that 32 bytes + when serialized. + + This function also accepts `None`, representing the absence of a node, + which is encoded to `b""""""`. + + Parameters + ---------- + node : Optional[InternalNode] + The node to encode. + + Returns + ------- + encoded : `rlp.RLP` + The node encoded as RLP. + " in +(* At stmt: unsupported node type: AnnAssign *) + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "node" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let unencoded := + (* At constant: unsupported node type: Constant *) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "LeafNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "rest_of_key" |); + Constant.bool true + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "ExtensionNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "key_segment" |); + Constant.bool false + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "BranchNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + BinOp.add (| + M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "value" |) + ] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "AssertionError" |), + make_list [ + (* At expr: unsupported node type: JoinedStr *) + ], + make_dict [] + |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let encoded := + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "unencoded" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded" |) + ], + make_dict [] + |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "unencoded" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "encoded" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition encode_node : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "node"; "storage_root" ] |) in + let _ := Constant.str " + Encode a Node for storage in the Merkle Trie. + + Currently mostly an unimplemented stub. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "storage_root" |), Constant.None_ |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "encode_account" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "storage_root" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + make_tuple [ M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "U256" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "cast" |), + make_list [ + M.get_field (| M.get_name (| globals, "rlp" |), "RLP" |); + M.get_name (| globals, "node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "node" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "previous_trie" |), "encode_node" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "storage_root" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition Trie : Value.t := + builtins.make_klass + [(* At base: unsupported node type: Subscript *)] + [ + + ] + [ + + ]. + +Definition copy_trie : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie" ] |) in + let _ := Constant.str " + Create a copy of `trie`. Since only frozen objects may be stored in tries, + the contents are reused. + + Parameters + ---------- + trie: `Trie` + Trie to copy. + + Returns + ------- + new_trie : `Trie[K, V]` + A copy of the trie. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Trie" |), + make_list [ + M.get_field (| M.get_name (| globals, "trie" |), "secured" |); + M.get_field (| M.get_name (| globals, "trie" |), "default" |); + M.call (| + M.get_field (| M.get_name (| globals, "copy" |), "copy" |), + make_list [ + M.get_field (| M.get_name (| globals, "trie" |), "_data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition trie_set : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "key"; "value" ] |) in + let _ := Constant.str " + Stores an item in a Merkle Trie. + + This method deletes the key if `value == trie.default`, because the Merkle + Trie represents the default value by omitting it from the trie. + + Parameters + ---------- + trie: `Trie` + Trie to store in. + key : `Bytes` + Key to lookup. + value : `V` + Node to insert at `key`. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "value" |), M.get_field (| M.get_name (| globals, "trie" |), "default" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "key" |), M.get_field (| M.get_name (| globals, "trie" |), "_data" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition trie_get : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "key" ] |) in + let _ := Constant.str " + Gets an item from the Merkle Trie. + + This method returns `trie.default` if the key is missing. + + Parameters + ---------- + trie: + Trie to lookup in. + key : + Key to lookup. + + Returns + ------- + node : `V` + Node at `key` in the trie. + " in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "get" |), + make_list [ + M.get_name (| globals, "key" |); + M.get_field (| M.get_name (| globals, "trie" |), "default" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition common_prefix_length : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "a"; "b" ] |) in + let _ := Constant.str " + Find the longest common prefix of two sequences. + " in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + ], + make_dict [] + |) do + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| M.get_name (| globals, "i" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition nibble_list_to_compact : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "x"; "is_leaf" ] |) in + let _ := Constant.str " + Compresses nibble-list into a standard byte array with a flag. + + A nibble-list is a list of byte values no greater than `15`. The flag is + encoded in high nibble of the highest byte. The flag nibble can be broken + down into two two-bit flags. + + Highest nibble:: + + +---+---+----------+--------+ + | _ | _ | is_leaf | parity | + +---+---+----------+--------+ + 3 2 1 0 + + + The lowest bit of the nibble encodes the parity of the length of the + remaining nibbles -- `0` when even and `1` when odd. The second lowest bit + is used to distinguish leaf and extension nodes. The other two bits are not + used. + + Parameters + ---------- + x : + Array of nibbles. + is_leaf : + True if this is part of a leaf node, or false if it is an extension + node. + + Returns + ------- + compressed : `bytearray` + Compact byte array. + " in + let compact := + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + Constant.int 2 + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.mult (| + Constant.int 16, + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "is_leaf" |) + |) + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + BinOp.add (| + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "is_leaf" |) + |), + Constant.int 1 + |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), Constant.int 0 |) + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 1; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + M.get_name (| globals, "compact" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition bytes_to_nibble_list : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "bytes_" ] |) in + let _ := Constant.str " + Converts a `Bytes` into to a sequence of nibbles (bytes with value < 16). + + Parameters + ---------- + bytes_: + The `Bytes` to convert. + + Returns + ------- + nibble_list : `Bytes` + The `Bytes` in nibble-list format. + " in + let nibble_list := + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [ + BinOp.mult (| + Constant.int 2, + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "bytes_" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + For make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ] in M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "bytes_" |) + ], + make_dict [] + |) do + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |) |), + BinOp.r_shift (| + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 240 + |), + Constant.int 4 + |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |), + Constant.int 1 + |) |), + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 15 + |) + |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + M.get_name (| globals, "nibble_list" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition _prepare_trie : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "get_storage_root" ] |) in + let _ := Constant.str " + Prepares the trie for root calculation. Removes values that are empty, + hashes the keys (if `secured == True`) and encodes all the nodes. + + Parameters + ---------- + trie : + The `Trie` to prepare. + get_storage_root : + Function to get the storage root of an account. Needed to encode + `Account` objects. + + Returns + ------- + out : `Mapping[ethereum.base_types.Bytes, Node]` + Object with keys mapped to nibble-byte form. + " in +(* At stmt: unsupported node type: AnnAssign *) + For make_tuple [ M.get_name (| globals, "preimage" |); M.get_name (| globals, "value" |) ] in M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "items" |), + make_list [], + make_dict [] + |) do + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in + let address := + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |); + M.call (| + M.get_name (| globals, "get_storage_root" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_eq (| M.get_name (| globals, "encoded_value" |), (* At constant: unsupported node type: Constant *) |); + M.get_name (| globals, "AssertionError" |) + ], + make_dict [] + |) in +(* At stmt: unsupported node type: AnnAssign *) + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "trie" |), "secured" |), + (* then *) + ltac:(M.monadic ( + let key := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let key := + M.get_name (| globals, "preimage" |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "mapped" |), M.call (| + M.get_name (| globals, "bytes_to_nibble_list" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |) |), + M.get_name (| globals, "encoded_value" |) + |) in + EndFor. + let _ := M.return_ (| + M.get_name (| globals, "mapped" |) + |) in + M.pure Constant.None_)). + +Definition root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "get_storage_root" ] |) in + let _ := Constant.str " + Computes the root of a modified merkle patricia trie (MPT). + + Parameters + ---------- + trie : + `Trie` to get the root of. + get_storage_root : + Function to get the storage root of an account. Needed to encode + `Account` objects. + + + Returns + ------- + root : `.fork_types.Root` + MPT root of the underlying key-value pairs. + " in + let obj := + M.call (| + M.get_name (| globals, "_prepare_trie" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "get_storage_root" |) + ], + make_dict [] + |) in + let root_node := + M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_name (| globals, "obj" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assert (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "root_node" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Root" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition patricialize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "obj"; "level" ] |) in + let _ := Constant.str " + Structural composition function. + + Used to recursively patricialize and merkleize a dictionary. Includes + memoization of the tree structure and hashes. + + Parameters + ---------- + obj : + Underlying trie key-value pairs, with keys in nibble-list format. + level : + Current trie level. + + Returns + ------- + node : `ethereum.base_types.Bytes` + Root node of `obj`. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let arbitrary_key := + M.call (| + M.get_name (| globals, "next" |), + make_list [ + M.call (| + M.get_name (| globals, "iter" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), Constant.int 1 |), + (* then *) + ltac:(M.monadic ( + let leaf := + M.call (| + M.get_name (| globals, "LeafNode" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |); + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "leaf" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let substring := + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) in + let prefix_length := + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "substring" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do + let prefix_length := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_name (| globals, "prefix_length" |); + M.call (| + M.get_name (| globals, "common_prefix_length" |), + make_list [ + M.get_name (| globals, "substring" |); + M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let prefix := + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ExtensionNode" |), + make_list [ + M.get_name (| globals, "prefix" |); + M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_name (| globals, "obj" |); + BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in +(* At stmt: unsupported node type: AnnAssign *) + For M.get_name (| globals, "_" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 16 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "branches" |), "append" |), + make_list [ + {} + ], + make_dict [] + |) in + EndFor. + let value := + (* At constant: unsupported node type: Constant *) in + For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |), M.get_name (| globals, "level" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "AssertionError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) + |) in + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "BranchNode" |), + make_list [ + [M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "branches" |), M.get_name (| globals, "k" |) |); + BinOp.add (| + M.get_name (| globals, "level" |), + Constant.int 1 + |) + ], + make_dict [] + |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)]; + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/utils/__init__.v b/CoqOfPython/ethereum/muir_glacier/utils/__init__.v new file mode 100644 index 0000000..1baedea --- /dev/null +++ b/CoqOfPython/ethereum/muir_glacier/utils/__init__.v @@ -0,0 +1,8 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Utility functions unique to this particular fork. +". diff --git a/CoqOfPython/ethereum/muir_glacier/utils/address.v b/CoqOfPython/ethereum/muir_glacier/utils/address.v new file mode 100644 index 0000000..9215bb2 --- /dev/null +++ b/CoqOfPython/ethereum/muir_glacier/utils/address.v @@ -0,0 +1,204 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Hardfork Utility Functions For Addresses +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Address specific functions used in this muir_glacier version of +specification. +". + +Require typing. +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_left_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Definition to_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "data" ] |) in + let _ := Constant.str " + Convert a Uint or U256 value to a valid address (20 bytes). + + Parameters + ---------- + data : + The string to be converted to bytes. + + Returns + ------- + address : `Address` + The obtained address. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_subscript (| M.call (| + M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition compute_contract_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "address"; "nonce" ] |) in + let _ := Constant.str " + Computes address of the new account that needs to be created. + + Parameters + ---------- + address : + The address of the account that wants to create the new account. + nonce : + The transaction count of the account that wants to create the new + account. + + Returns + ------- + address: `Address` + The computed address of the new account. + " in + let computed_address := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_list [ + M.get_name (| globals, "address" |); + M.get_name (| globals, "nonce" |) + ] + ], + make_dict [] + |) + ], + make_dict [] + |) in + let canonical_address := + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + let padded_address := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "canonical_address" |); + Constant.int 20 + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "padded_address" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition compute_create2_contract_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "address"; "salt"; "call_data" ] |) in + let _ := Constant.str " + Computes address of the new account that needs to be created, which is + based on the sender address, salt and the call data as well. + + Parameters + ---------- + address : + The address of the account that wants to create the new account. + salt : + Address generation salt. + call_data : + The code of the new account which is to be created. + + Returns + ------- + address: `ethereum.muir_glacier.fork_types.Address` + The computed address of the new account. + " in + let preimage := + BinOp.add (| + BinOp.add (| + BinOp.add (| + (* At constant: unsupported node type: Constant *), + M.get_name (| globals, "address" |) + |), + M.get_name (| globals, "salt" |) + |), + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "call_data" |) + ], + make_dict [] + |) + |) in + let computed_address := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + let canonical_address := + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + let padded_address := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "canonical_address" |); + Constant.int 20 + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "padded_address" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/utils/hexadecimal.v b/CoqOfPython/ethereum/muir_glacier/utils/hexadecimal.v new file mode 100644 index 0000000..9b3030d --- /dev/null +++ b/CoqOfPython/ethereum/muir_glacier/utils/hexadecimal.v @@ -0,0 +1,155 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Utility Functions For Hexadecimal Strings +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Hexadecimal utility functions used in this specification, specific to +Muir Glacier types. +". + +Require ethereum.utils.hexadecimal. +Axiom ethereum_utils_hexadecimal_remove_hex_prefix : + IsGlobalAlias globals ethereum.utils.hexadecimal.globals "remove_hex_prefix". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Definition hex_to_root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to trie root. + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to trie root. + + Returns + ------- + root : `Root` + Trie root obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Root" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition hex_to_bloom : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to bloom. + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to bloom. + + Returns + ------- + bloom : `Bloom` + Bloom obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bloom" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition hex_to_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to Address (20 bytes). + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to Address. + + Returns + ------- + address : `Address` + The address obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |), "rjust" |), + make_list [ + Constant.int 40; + Constant.str "0" + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/utils/message.v b/CoqOfPython/ethereum/muir_glacier/utils/message.v new file mode 100644 index 0000000..a226a3a --- /dev/null +++ b/CoqOfPython/ethereum/muir_glacier/utils/message.v @@ -0,0 +1,201 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Hardfork Utility Functions For The Message Data-structure +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Message specific functions used in this muir_glacier version of +specification. +". + +Require typing. +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". + +Require vm. +Axiom vm_Environment : + IsGlobalAlias globals vm.globals "Environment". +Axiom vm_Message : + IsGlobalAlias globals vm.globals "Message". + +Require address. +Axiom address_compute_contract_address : + IsGlobalAlias globals address.globals "compute_contract_address". + +Definition prepare_message : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "caller"; "target"; "value"; "data"; "gas"; "env"; "code_address"; "should_transfer_value"; "is_static" ] |) in + let _ := Constant.str " + Execute a transaction against the provided environment. + + Parameters + ---------- + caller : + Address which initiated the transaction + target : + Address whose code will be executed + value : + Value to be transferred. + data : + Array of bytes provided to the code in `target`. + gas : + Gas provided for the code in `target`. + env : + Environment for the Ethereum Virtual Machine. + code_address : + This is usually same as the `target` address except when an alternative + accounts code needs to be executed. + eg. `CALLCODE` calling a precompile. + should_transfer_value : + if True ETH should be transferred while executing a message call. + is_static: + if True then it prevents all state-changing operations from being + executed. + + Returns + ------- + message: `ethereum.muir_glacier.vm.Message` + Items containing contract creation or message call specific data. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Bytes0" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.call (| + M.get_name (| globals, "compute_contract_address" |), + make_list [ + M.get_name (| globals, "caller" |); + BinOp.sub (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "caller" |) + ], + make_dict [] + |), "nonce" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let msg_data := + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |) in + let code := + M.get_name (| globals, "data" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.get_name (| globals, "target" |) in + let msg_data := + M.get_name (| globals, "data" |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "target" |) + ], + make_dict [] + |), "code" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "code_address" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let code_address := + M.get_name (| globals, "target" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "AssertionError" |), + make_list [ + Constant.str "Target must be address or empty bytes" + ], + make_dict [] + |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/vm/__init__.v b/CoqOfPython/ethereum/muir_glacier/vm/__init__.v new file mode 100644 index 0000000..d408aed --- /dev/null +++ b/CoqOfPython/ethereum/muir_glacier/vm/__init__.v @@ -0,0 +1,246 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The abstract computer which runs the code stored in an +`.fork_types.Account`. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U64 : + IsGlobalAlias globals ethereum.base_types.globals "U64". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_State : + IsGlobalAlias globals state.globals "State". +Axiom state_account_exists_and_is_empty : + IsGlobalAlias globals state.globals "account_exists_and_is_empty". + +Require precompiled_contracts. +Axiom precompiled_contracts_RIPEMD160_ADDRESS : + IsGlobalAlias globals precompiled_contracts.globals "RIPEMD160_ADDRESS". + +Definition __all__ : Value.t := M.run ltac:(M.monadic ( + make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] +)). + +Definition Environment : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Message : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Evm : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition incorporate_child_on_success : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "child_evm" ] |) in + let _ := Constant.str " + Incorporate the state of a successful `child_evm` into the parent `evm`. + + Parameters + ---------- + evm : + The parent `EVM`. + child_evm : + The child evm to incorporate. + " in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "gas_left" |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "logs" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "logs" |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "refund_counter" |) + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "accounts_to_delete" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition incorporate_child_on_error : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "child_evm" ] |) in + let _ := Constant.str " + Incorporate the state of an unsuccessful `child_evm` into the parent `evm`. + + Parameters + ---------- + evm : + The parent `EVM`. + child_evm : + The child evm to incorporate. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "RIPEMD160_ADDRESS" |), M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |), M.get_name (| globals, "RIPEMD160_ADDRESS" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "gas_left" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/vm/exceptions.v b/CoqOfPython/ethereum/muir_glacier/vm/exceptions.v new file mode 100644 index 0000000..8560cef --- /dev/null +++ b/CoqOfPython/ethereum/muir_glacier/vm/exceptions.v @@ -0,0 +1,162 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Exceptions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Exceptions which cause the EVM to halt exceptionally. +". + +Require ethereum.exceptions. +Axiom ethereum_exceptions_EthereumException : + IsGlobalAlias globals ethereum.exceptions.globals "EthereumException". + +Definition ExceptionalHalt : Value.t := + builtins.make_klass + [(globals, "EthereumException")] + [ + + ] + [ + + ]. + +Definition Revert : Value.t := + builtins.make_klass + [(globals, "EthereumException")] + [ + + ] + [ + + ]. + +Definition StackUnderflowError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition StackOverflowError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition OutOfGasError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition InvalidOpcode : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + ( + "__init__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "code" ] |) in + let _ := M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "super" |), + make_list [], + make_dict [] + |), "__init__" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "self" |), "code" |), + M.get_name (| globals, "code" |) + |) in + M.pure Constant.None_)) + ) + ]. + +Definition InvalidJumpDestError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition StackDepthLimitError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition WriteInStaticContext : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition OutOfBoundsRead : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition InvalidParameter : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition AddressCollision : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/__init__.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/__init__.v new file mode 100644 index 0000000..e5bebd7 --- /dev/null +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/__init__.v @@ -0,0 +1,87 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +EVM Instruction Encoding (Opcodes) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Machine readable representations of EVM instructions, and a mapping to their +implementations. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". + +Require __init__. +Axiom __init___arithmetic : + IsGlobalAlias globals __init__.globals "arithmetic". + +Require __init__. +Axiom __init___bitwise : + IsGlobalAlias globals __init__.globals "bitwise". + +Require __init__. +Axiom __init___block : + IsGlobalAlias globals __init__.globals "block". + +Require __init__. +Axiom __init___comparison : + IsGlobalAlias globals __init__.globals "comparison". + +Require __init__. +Axiom __init___control_flow : + IsGlobalAlias globals __init__.globals "control_flow". + +Require __init__. +Axiom __init___environment : + IsGlobalAlias globals __init__.globals "environment". + +Require __init__. +Axiom __init___keccak : + IsGlobalAlias globals __init__.globals "keccak". + +Require __init__. +Axiom __init___log : + IsGlobalAlias globals __init__.globals "log". + +Require __init__. +Axiom __init___memory : + IsGlobalAlias globals __init__.globals "memory". + +Require __init__. +Axiom __init___stack : + IsGlobalAlias globals __init__.globals "stack". + +Require __init__. +Axiom __init___storage : + IsGlobalAlias globals __init__.globals "storage". + +Require __init__. +Axiom __init___system : + IsGlobalAlias globals __init__.globals "system". + +Definition Ops : Value.t := + builtins.make_klass + [(* At base: unsupported node type: Attribute *)] + [ + + ] + [ + + ]. + +(* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/arithmetic.v new file mode 100644 index 0000000..a8b5c61 --- /dev/null +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/arithmetic.v @@ -0,0 +1,1085 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Arithmetic Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM Arithmetic instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U255_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U255_CEIL_VALUE". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_U256_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_get_sign : + IsGlobalAlias globals ethereum.utils.numeric.globals "get_sign". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_EXPONENTIATION : + IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION". +Axiom gas_GAS_EXPONENTIATION_PER_BYTE : + IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION_PER_BYTE". +Axiom gas_GAS_LOW : + IsGlobalAlias globals gas.globals "GAS_LOW". +Axiom gas_GAS_MID : + IsGlobalAlias globals gas.globals "GAS_MID". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition add : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Adds the top two elements of the stack together, and pushes the result back + on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "x" |), "wrapping_add" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition sub : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Subtracts the top two elements of the stack, and pushes the result back + on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "x" |), "wrapping_sub" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mul : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Multiply the top two elements of the stack, and pushes the result back + on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "x" |), "wrapping_mul" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition div : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Integer division of the top two elements of the stack. Pushes the result + back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let dividend := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let divisor := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let quotient := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let quotient := + BinOp.floor_div (| + M.get_name (| globals, "dividend" |), + M.get_name (| globals, "divisor" |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "quotient" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition sdiv : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed integer division of the top two elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let dividend := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let divisor := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let quotient := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_name (| globals, "dividend" |), UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "divisor" |), UnOp.sub (| Constant.int 1 |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let quotient := + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let sign := + M.call (| + M.get_name (| globals, "get_sign" |), + make_list [ + BinOp.mult (| + M.get_name (| globals, "dividend" |), + M.get_name (| globals, "divisor" |) + |) + ], + make_dict [] + |) in + let quotient := + BinOp.mult (| + M.get_name (| globals, "sign" |), + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "dividend" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "divisor" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + M.get_name (| globals, "quotient" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Modulo remainder of the top two elements of the stack. Pushes the result + back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let remainder := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let remainder := + BinOp.mod_ (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "remainder" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition smod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed modulo remainder of the top two elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let y := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let remainder := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let remainder := + BinOp.mult (| + M.call (| + M.get_name (| globals, "get_sign" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + BinOp.mod_ (| + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + M.get_name (| globals, "remainder" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition addmod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Modulo addition of the top 2 elements with the 3rd element. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let z := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_MID" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.add (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |), + M.get_name (| globals, "z" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mulmod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Modulo multiplication of the top 2 elements with the 3rd element. Pushes + the result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let z := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_MID" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.mult (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |), + M.get_name (| globals, "z" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition exp : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Exponential operation of the top 2 elements. Pushes the result back on + the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let base := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exponent := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exponent_bits := + M.call (| + M.get_field (| M.get_name (| globals, "exponent" |), "bit_length" |), + make_list [], + make_dict [] + |) in + let exponent_bytes := + BinOp.floor_div (| + BinOp.add (| + M.get_name (| globals, "exponent_bits" |), + Constant.int 7 + |), + Constant.int 8 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_EXPONENTIATION" |), + BinOp.mult (| + M.get_name (| globals, "GAS_EXPONENTIATION_PER_BYTE" |), + M.get_name (| globals, "exponent_bytes" |) + |) + |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "pow" |), + make_list [ + M.get_name (| globals, "base" |); + M.get_name (| globals, "exponent" |); + M.get_name (| globals, "U256_CEIL_VALUE" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition signextend : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Sign extend operation. In other words, extend a signed number which + fits in N bytes to 32 bytes. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let byte_num := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "byte_num" |), Constant.int 31 |), + (* then *) + ltac:(M.monadic ( + let result := + M.get_name (| globals, "value" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let value_bytes := + M.call (| + M.get_name (| globals, "bytes" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "value" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) in + let value_bytes := + M.get_subscript (| M.get_name (| globals, "value_bytes" |), BinOp.sub (| + Constant.int 31, + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "byte_num" |) + ], + make_dict [] + |) + |):(* At expr: unsupported node type: NoneType *) |) in + let sign_bit := + BinOp.r_shift (| + M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), + Constant.int 7 + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "sign_bit" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "value_bytes" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let num_bytes_prepend := + BinOp.sub (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "byte_num" |), + Constant.int 1 + |) + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + BinOp.add (| + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [ + BinOp.mult (| + make_list [ + Constant.int 255 + ], + M.get_name (| globals, "num_bytes_prepend" |) + |) + ], + make_dict [] + |), + M.get_name (| globals, "value_bytes" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/bitwise.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/bitwise.v new file mode 100644 index 0000000..9f2f382 --- /dev/null +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/bitwise.v @@ -0,0 +1,601 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Bitwise Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM bitwise instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_U256_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition bitwise_and : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise AND operation of the top 2 elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + BinOp.bit_and (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_or : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise OR operation of the top 2 elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + BinOp.bit_or (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_xor : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise XOR operation of the top 2 elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + BinOp.bit_xor (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_not : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise NOT operation of the top element of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + UnOp.invert (| M.get_name (| globals, "x" |) |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition get_byte : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + For a word (defined by next top element of the stack), retrieve the + Nth byte (0-indexed and defined by top element of stack) from the + left (most significant) to right (least significant). + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let byte_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let word := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "byte_index" |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let extra_bytes_to_right := + BinOp.sub (| + Constant.int 31, + M.get_name (| globals, "byte_index" |) + |) in + let word := + BinOp.r_shift (| + M.get_name (| globals, "word" |), + BinOp.mult (| + M.get_name (| globals, "extra_bytes_to_right" |), + Constant.int 8 + |) + |) in + let word := + BinOp.bit_and (| + M.get_name (| globals, "word" |), + Constant.int 255 + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "word" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_shl : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Logical shift left (SHL) operation of the top 2 elements of the stack. + Pushes the result back on the stack. + Parameters + ---------- + evm : + The current EVM frame. + " in + let shift := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.l_shift (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "shift" |) + |), + M.get_name (| globals, "U256_CEIL_VALUE" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_shr : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Logical shift right (SHR) operation of the top 2 elements of the stack. + Pushes the result back on the stack. + Parameters + ---------- + evm : + The current EVM frame. + " in + let shift := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), + (* then *) + ltac:(M.monadic ( + let result := + BinOp.r_shift (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "shift" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_sar : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Arithmetic shift right (SAR) operation of the top 2 elements of the stack. + Pushes the result back on the stack. + Parameters + ---------- + evm : + The current EVM frame. + " in + let shift := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let signed_value := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + BinOp.r_shift (| + M.get_name (| globals, "signed_value" |), + M.get_name (| globals, "shift" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "signed_value" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/block.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/block.v new file mode 100644 index 0000000..26c73a7 --- /dev/null +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/block.v @@ -0,0 +1,379 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Block Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM block instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_BLOCK_HASH : + IsGlobalAlias globals gas.globals "GAS_BLOCK_HASH". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition block_hash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the hash of one of the 256 most recent complete blocks onto the + stack. The block number to hash is present at the top of the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let block_number := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BLOCK_HASH" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt_e (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), M.get_name (| globals, "block_number" |) |), + ltac:(M.monadic ( + Compare.gt (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), BinOp.add (| + M.get_name (| globals, "block_number" |), + Constant.int 256 + |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let hash := + (* At constant: unsupported node type: Constant *) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let hash := + M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + M.get_name (| globals, "block_number" |) + |) |) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "hash" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition coinbase : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's beneficiary address (address of the block miner) + onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "coinbase" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition timestamp : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's timestamp onto the stack. Here the timestamp + being referred is actually the unix timestamp in seconds. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "time" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition number : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's number onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition difficulty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's difficulty onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "difficulty" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition gas_limit : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's gas limit onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "gas_limit" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition chain_id : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the chain id onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "chain_id" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/comparison.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/comparison.v new file mode 100644 index 0000000..fbc35f8 --- /dev/null +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/comparison.v @@ -0,0 +1,404 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Comparison Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM Comparison instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition less_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is less than the next top element. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let right := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition signed_less_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed less-than comparison. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let right := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition greater_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is greater than the next top element. Pushes + the result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let right := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition signed_greater_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed greater-than comparison. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let right := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition equal : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is equal to the next top element. Pushes + the result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let right := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.eq (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition is_zero : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is equal to 0. Pushes the result back on the + stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.eq (| M.get_name (| globals, "x" |), Constant.int 0 |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/control_flow.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/control_flow.v new file mode 100644 index 0000000..04a79d9 --- /dev/null +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/control_flow.v @@ -0,0 +1,336 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Control Flow Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM control flow instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require vm.gas. +Axiom vm_gas_GAS_BASE : + IsGlobalAlias globals vm.gas.globals "GAS_BASE". +Axiom vm_gas_GAS_HIGH : + IsGlobalAlias globals vm.gas.globals "GAS_HIGH". +Axiom vm_gas_GAS_JUMPDEST : + IsGlobalAlias globals vm.gas.globals "GAS_JUMPDEST". +Axiom vm_gas_GAS_MID : + IsGlobalAlias globals vm.gas.globals "GAS_MID". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_InvalidJumpDestError : + IsGlobalAlias globals exceptions.globals "InvalidJumpDestError". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition stop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stop further execution of EVM code. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let _ := M.pass (| |) in + let _ := M.pass (| |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "running" |), + Constant.bool false + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition jump : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Alter the program counter to the location specified by the top of the + stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let jump_dest := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_MID" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "jump_dest" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition jumpi : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Alter the program counter to the specified location if and only if a + condition is true. If the condition is not true, then the program counter + would increase only by 1. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let jump_dest := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let conditional_value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_HIGH" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "conditional_value" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let destination := + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let destination := + M.get_name (| globals, "jump_dest" |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "destination" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition pc : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push onto the stack the value of the program counter after reaching the + current instruction and without increasing it for the next instruction. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "pc" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition gas_left : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the amount of available gas (including the corresponding reduction + for the cost of this instruction) onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition jumpdest : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Mark a valid destination for jumps. This is a noop, present only + to be used by `JUMP` and `JUMPI` opcodes to verify that their jump is + valid. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_JUMPDEST" |) + ], + make_dict [] + |) in + let _ := M.pass (| |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/environment.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/environment.v new file mode 100644 index 0000000..d9b3151 --- /dev/null +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/environment.v @@ -0,0 +1,1286 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Environmental Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM environment related instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require fork_types. +Axiom fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". + +Require state. +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". + +Require utils.address. +Axiom utils_address_to_address : + IsGlobalAlias globals utils.address.globals "to_address". + +Require vm.memory. +Axiom vm_memory_buffer_read : + IsGlobalAlias globals vm.memory.globals "buffer_read". +Axiom vm_memory_memory_write : + IsGlobalAlias globals vm.memory.globals "memory_write". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_OutOfBoundsRead : + IsGlobalAlias globals exceptions.globals "OutOfBoundsRead". + +Require gas. +Axiom gas_GAS_BALANCE : + IsGlobalAlias globals gas.globals "GAS_BALANCE". +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_CODE_HASH : + IsGlobalAlias globals gas.globals "GAS_CODE_HASH". +Axiom gas_GAS_COPY : + IsGlobalAlias globals gas.globals "GAS_COPY". +Axiom gas_GAS_EXTERNAL : + IsGlobalAlias globals gas.globals "GAS_EXTERNAL". +Axiom gas_GAS_FAST_STEP : + IsGlobalAlias globals gas.globals "GAS_FAST_STEP". +Axiom gas_GAS_RETURN_DATA_COPY : + IsGlobalAlias globals gas.globals "GAS_RETURN_DATA_COPY". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the address of the current executing account to the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition balance : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the balance of the given account onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BALANCE" |) + ], + make_dict [] + |) in + let balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "balance" |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "balance" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition origin : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the address of the original transaction sender to the stack. + The origin address can only be an EOA. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "origin" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition caller : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the address of the caller onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "caller" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition callvalue : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the value (in wei) sent with the call onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition calldataload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push a word (32 bytes) of the input data belonging to the current + environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |); + M.get_name (| globals, "start_index" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition calldatasize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the size of input data in current environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition calldatacopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy a portion of the input data in current environment to memory. + + This will also expand the memory, in case that the memory is insufficient + to store the data. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let data_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |); + M.get_name (| globals, "data_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition codesize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the size of code running in current environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "code" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition codecopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy a portion of the code in current environment to memory. + + This will also expand the memory, in case that the memory is insufficient + to store the data. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let code_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "code" |); + M.get_name (| globals, "code_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition gasprice : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the gas price used in current environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "gas_price" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition extcodesize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the code size of a given account onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_EXTERNAL" |) + ], + make_dict [] + |) in + let codesize := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "code" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "codesize" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition extcodecopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy a portion of an account's code to memory. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let code_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_EXTERNAL" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "code" |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "code" |); + M.get_name (| globals, "code_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition returndatasize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the size of the return data buffer onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition returndatacopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copies data from the return data buffer code to memory + + Parameters + ---------- + evm : + The current EVM frame. + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let return_data_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_RETURN_DATA_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "return_data_start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "OutOfBoundsRead" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |):BinOp.add (| + M.get_name (| globals, "return_data_start_position" |), + M.get_name (| globals, "size" |) + |) |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition extcodehash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Returns the keccak256 hash of a contract’s bytecode + Parameters + ---------- + evm : + The current EVM frame. + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_CODE_HASH" |) + ], + make_dict [] + |) in + let account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "account" |), M.get_name (| globals, "EMPTY_ACCOUNT" |) |), + (* then *) + ltac:(M.monadic ( + let codehash := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let codehash := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_field (| M.get_name (| globals, "account" |), "code" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "codehash" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition self_balance : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the balance of the current address to the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_FAST_STEP" |) + ], + make_dict [] + |) in + let balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "balance" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/keccak.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/keccak.v new file mode 100644 index 0000000..cab9ffb --- /dev/null +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/keccak.v @@ -0,0 +1,181 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Keccak Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM keccak instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_KECCAK256 : + IsGlobalAlias globals gas.globals "GAS_KECCAK256". +Axiom gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition keccak : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes to the stack the Keccak-256 hash of a region of memory. + + This also expands the memory, in case the memory is insufficient to + access the data's memory location. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let word_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_KECCAK256_WORD" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_KECCAK256" |), + M.get_name (| globals, "word_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let data := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "hash" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/log.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/log.v new file mode 100644 index 0000000..4891a4d --- /dev/null +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/log.v @@ -0,0 +1,244 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Logging Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM logging instructions. +". + +Require functools. +Axiom functools_partial : + IsGlobalAlias globals functools.globals "partial". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_WriteInStaticContext : + IsGlobalAlias globals exceptions.globals "WriteInStaticContext". + +Require gas. +Axiom gas_GAS_LOG : + IsGlobalAlias globals gas.globals "GAS_LOG". +Axiom gas_GAS_LOG_DATA : + IsGlobalAlias globals gas.globals "GAS_LOG_DATA". +Axiom gas_GAS_LOG_TOPIC : + IsGlobalAlias globals gas.globals "GAS_LOG_TOPIC". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". + +Definition log_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "num_topics" ] |) in + let _ := Constant.str " + Appends a log entry, having `num_topics` topics, to the evm logs. + + This will also expand the memory if the data (required by the log entry) + corresponding to the memory is not accessible. + + Parameters + ---------- + evm : + The current EVM frame. + num_topics : + The number of topics to be included in the log entry. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let topics := + make_list [] in + For M.get_name (| globals, "_" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "num_topics" |) + ], + make_dict [] + |) do + let topic := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "topics" |), "append" |), + make_list [ + M.get_name (| globals, "topic" |) + ], + make_dict [] + |) in + EndFor. + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_LOG" |), + BinOp.mult (| + M.get_name (| globals, "GAS_LOG_DATA" |), + M.get_name (| globals, "size" |) + |) + |), + BinOp.mult (| + M.get_name (| globals, "GAS_LOG_TOPIC" |), + M.get_name (| globals, "num_topics" |) + |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let log_entry := + M.call (| + M.get_name (| globals, "Log" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "logs" |), + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "logs" |), + make_tuple [ M.get_name (| globals, "log_entry" |) ] + |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition log0 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/memory.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/memory.v new file mode 100644 index 0000000..1e1c8b0 --- /dev/null +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/memory.v @@ -0,0 +1,378 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Memory Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM Memory instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". +Axiom memory_memory_write : + IsGlobalAlias globals memory.globals "memory_write". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition mstore : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a word to memory. + This also expands the memory, if the memory is + insufficient to store the word. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "start_position" |); M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + ], + make_dict [] + |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "start_position" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mstore8 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a byte to memory. + This also expands the memory, if the memory is + insufficient to store the word. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "start_position" |); M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let normalized_bytes_value := + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + make_list [ + BinOp.bit_and (| + M.get_name (| globals, "value" |), + Constant.int 255 + |) + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "start_position" |); + M.get_name (| globals, "normalized_bytes_value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Load word from memory. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "start_position" |); M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "start_position" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition msize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the size of active memory in bytes onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/stack.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/stack.v new file mode 100644 index 0000000..1eeda05 --- /dev/null +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/stack.v @@ -0,0 +1,929 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Stack Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM stack related instructions. +". + +Require functools. +Axiom functools_partial : + IsGlobalAlias globals functools.globals "partial". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". +Axiom __init___stack : + IsGlobalAlias globals __init__.globals "stack". + +Require exceptions. +Axiom exceptions_StackUnderflowError : + IsGlobalAlias globals exceptions.globals "StackUnderflowError". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_buffer_read : + IsGlobalAlias globals memory.globals "buffer_read". + +Definition pop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Remove item from stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.pass (| |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition push_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "num_bytes" ] |) in + let _ := Constant.str " + Pushes a N-byte immediate onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + num_bytes : + The number of immediate bytes to be read from the code and pushed to + the stack. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let data_to_push := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "code" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "num_bytes" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "data_to_push" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + BinOp.add (| + Constant.int 1, + M.get_name (| globals, "num_bytes" |) + |) + |) in + M.pure Constant.None_)). + +Definition dup_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "item_number" ] |) in + let _ := Constant.str " + Duplicate the Nth stack item (from top of the stack) to the top of stack. + + Parameters + ---------- + evm : + The current EVM frame. + + item_number : + The stack item number (0-indexed from top of stack) to be duplicated + to the top of stack. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "StackUnderflowError" |) + ], + make_dict [] + |) in + let data_to_duplicate := + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + BinOp.sub (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), + Constant.int 1 + |), + M.get_name (| globals, "item_number" |) + |) |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "data_to_duplicate" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition swap_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "item_number" ] |) in + let _ := Constant.str " + Swap the top and the `item_number` element of the stack, where + the top of the stack is position zero. + + If `item_number` is zero, this function does nothing (which should not be + possible, since there is no `SWAP0` instruction). + + Parameters + ---------- + evm : + The current EVM frame. + + item_number : + The stack item number (0-indexed from top of stack) to be swapped + with the top of stack element. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "StackUnderflowError" |) + ], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) |) ], + make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |) ] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition push1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push5 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push6 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push7 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push8 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push9 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push10 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push11 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push12 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push13 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push14 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push15 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push16 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push17 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push18 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push19 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push20 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push21 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push22 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push23 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push24 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push25 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push26 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push27 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push28 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push29 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push30 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push31 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push32 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition dup1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup5 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup6 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup7 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup8 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup9 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup10 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup11 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup12 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup13 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup14 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup15 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup16 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition swap1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap5 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap6 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap7 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap8 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap9 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap10 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap11 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap12 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap13 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap14 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap15 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap16 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/storage.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/storage.v new file mode 100644 index 0000000..5f4c9f2 --- /dev/null +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/storage.v @@ -0,0 +1,364 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Storage Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM storage related instructions. +". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require state. +Axiom state_get_storage : + IsGlobalAlias globals state.globals "get_storage". +Axiom state_get_storage_original : + IsGlobalAlias globals state.globals "get_storage_original". +Axiom state_set_storage : + IsGlobalAlias globals state.globals "set_storage". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". +Axiom exceptions_WriteInStaticContext : + IsGlobalAlias globals exceptions.globals "WriteInStaticContext". + +Require gas. +Axiom gas_GAS_CALL_STIPEND : + IsGlobalAlias globals gas.globals "GAS_CALL_STIPEND". +Axiom gas_GAS_SLOAD : + IsGlobalAlias globals gas.globals "GAS_SLOAD". +Axiom gas_GAS_STORAGE_CLEAR_REFUND : + IsGlobalAlias globals gas.globals "GAS_STORAGE_CLEAR_REFUND". +Axiom gas_GAS_STORAGE_SET : + IsGlobalAlias globals gas.globals "GAS_STORAGE_SET". +Axiom gas_GAS_STORAGE_UPDATE : + IsGlobalAlias globals gas.globals "GAS_STORAGE_UPDATE". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition sload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Loads to the stack, the value corresponding to a certain key from the + storage of the current account. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let key := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_SLOAD" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "get_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition sstore : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a value at a certain key in the current context's storage. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let key := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let new_value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt (| M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), M.get_name (| globals, "GAS_CALL_STIPEND" |) |); + M.get_name (| globals, "OutOfGasError" |) + ], + make_dict [] + |) in + let original_value := + M.call (| + M.get_name (| globals, "get_storage_original" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let current_value := + M.call (| + M.get_name (| globals, "get_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_name (| globals, "original_value" |), M.get_name (| globals, "current_value" |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_name (| globals, "current_value" |), M.get_name (| globals, "new_value" |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let gas_cost := + M.get_name (| globals, "GAS_STORAGE_SET" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let gas_cost := + M.get_name (| globals, "GAS_STORAGE_UPDATE" |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let gas_cost := + M.get_name (| globals, "GAS_SLOAD" |) in + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| M.get_name (| globals, "current_value" |), M.get_name (| globals, "new_value" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "new_value" |), Constant.int 0 |) + )) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.sub, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "original_value" |), M.get_name (| globals, "new_value" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_SET" |), + M.get_name (| globals, "GAS_SLOAD" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_UPDATE" |), + M.get_name (| globals, "GAS_SLOAD" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "gas_cost" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "set_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |); + M.get_name (| globals, "new_value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/vm/interpreter.v b/CoqOfPython/ethereum/muir_glacier/vm/interpreter.v new file mode 100644 index 0000000..5496638 --- /dev/null +++ b/CoqOfPython/ethereum/muir_glacier/vm/interpreter.v @@ -0,0 +1,643 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Interpreter +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +A straightforward interpreter that executes EVM code. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Iterable : + IsGlobalAlias globals typing.globals "Iterable". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.trace. +Axiom ethereum_trace_EvmStop : + IsGlobalAlias globals ethereum.trace.globals "EvmStop". +Axiom ethereum_trace_OpEnd : + IsGlobalAlias globals ethereum.trace.globals "OpEnd". +Axiom ethereum_trace_OpException : + IsGlobalAlias globals ethereum.trace.globals "OpException". +Axiom ethereum_trace_OpStart : + IsGlobalAlias globals ethereum.trace.globals "OpStart". +Axiom ethereum_trace_PrecompileEnd : + IsGlobalAlias globals ethereum.trace.globals "PrecompileEnd". +Axiom ethereum_trace_PrecompileStart : + IsGlobalAlias globals ethereum.trace.globals "PrecompileStart". +Axiom ethereum_trace_TransactionEnd : + IsGlobalAlias globals ethereum.trace.globals "TransactionEnd". +Axiom ethereum_trace_evm_trace : + IsGlobalAlias globals ethereum.trace.globals "evm_trace". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_account_exists_and_is_empty : + IsGlobalAlias globals state.globals "account_exists_and_is_empty". +Axiom state_account_has_code_or_nonce : + IsGlobalAlias globals state.globals "account_has_code_or_nonce". +Axiom state_begin_transaction : + IsGlobalAlias globals state.globals "begin_transaction". +Axiom state_commit_transaction : + IsGlobalAlias globals state.globals "commit_transaction". +Axiom state_destroy_storage : + IsGlobalAlias globals state.globals "destroy_storage". +Axiom state_increment_nonce : + IsGlobalAlias globals state.globals "increment_nonce". +Axiom state_mark_account_created : + IsGlobalAlias globals state.globals "mark_account_created". +Axiom state_move_ether : + IsGlobalAlias globals state.globals "move_ether". +Axiom state_rollback_transaction : + IsGlobalAlias globals state.globals "rollback_transaction". +Axiom state_set_code : + IsGlobalAlias globals state.globals "set_code". +Axiom state_touch_account : + IsGlobalAlias globals state.globals "touch_account". + +Require vm. +Axiom vm_Message : + IsGlobalAlias globals vm.globals "Message". + +Require vm.gas. +Axiom vm_gas_GAS_CODE_DEPOSIT : + IsGlobalAlias globals vm.gas.globals "GAS_CODE_DEPOSIT". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require vm.precompiled_contracts.mapping. +Axiom vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : + IsGlobalAlias globals vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". + +Require __init__. +Axiom __init___Environment : + IsGlobalAlias globals __init__.globals "Environment". +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_AddressCollision : + IsGlobalAlias globals exceptions.globals "AddressCollision". +Axiom exceptions_ExceptionalHalt : + IsGlobalAlias globals exceptions.globals "ExceptionalHalt". +Axiom exceptions_InvalidOpcode : + IsGlobalAlias globals exceptions.globals "InvalidOpcode". +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". +Axiom exceptions_Revert : + IsGlobalAlias globals exceptions.globals "Revert". +Axiom exceptions_StackDepthLimitError : + IsGlobalAlias globals exceptions.globals "StackDepthLimitError". + +Require instructions. +Axiom instructions_Ops : + IsGlobalAlias globals instructions.globals "Ops". +Axiom instructions_op_implementation : + IsGlobalAlias globals instructions.globals "op_implementation". + +Require runtime. +Axiom runtime_get_valid_jump_destinations : + IsGlobalAlias globals runtime.globals "get_valid_jump_destinations". + +Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1024 + ], + make_dict [] + |) +)). + +Definition MAX_CODE_SIZE : Value.t := M.run ltac:(M.monadic ( + Constant.int 24576 +)). + +Definition MessageCallOutput : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition process_message_call : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + If `message.current` is empty then it creates a smart contract + else it executes a call from the `message.caller` to the `message.target`. + + Parameters + ---------- + message : + Transaction specific items. + + env : + External items required for EVM execution. + + Returns + ------- + output : `MessageCallOutput` + Output of the message call + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_name (| globals, "message" |), "target" |), M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let is_collision := + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_name (| globals, "is_collision" |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallOutput" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "tuple" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "AddressCollision" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let evm := + M.call (| + M.get_name (| globals, "process_create_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let evm := + M.call (| + M.get_name (| globals, "process_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_field (| M.get_name (| globals, "message" |), "target" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_field (| M.get_name (| globals, "message" |), "target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( +(* At stmt: unsupported node type: AnnAssign *) + let accounts_to_delete := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let touched_accounts := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let refund_counter := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let logs := + M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in + let accounts_to_delete := + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in + let touched_accounts := + M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |) in + let refund_counter := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let tx_end := + M.call (| + M.get_name (| globals, "TransactionEnd" |), + make_list [ + BinOp.sub (| + M.get_field (| M.get_name (| globals, "message" |), "gas" |), + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + |); + M.get_field (| M.get_name (| globals, "evm" |), "output" |); + M.get_field (| M.get_name (| globals, "evm" |), "error" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "evm_trace" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "tx_end" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallOutput" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition process_create_message : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + Executes a call to create a smart contract. + + Parameters + ---------- + message : + Transaction specific items. + env : + External items required for EVM execution. + + Returns + ------- + evm: :py:class:`~ethereum.muir_glacier.vm.Evm` + Items containing execution specific objects. + " in + let _ := M.call (| + M.get_name (| globals, "begin_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "destroy_storage" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "mark_account_created" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let evm := + M.call (| + M.get_name (| globals, "process_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), + (* then *) + ltac:(M.monadic ( + let contract_code := + M.get_field (| M.get_name (| globals, "evm" |), "output" |) in + let contract_code_gas := + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "contract_code" |) + ], + make_dict [] + |), + M.get_name (| globals, "GAS_CODE_DEPOSIT" |) + |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "rollback_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.get_name (| globals, "evm" |) + |) in + M.pure Constant.None_)). + +Definition process_message : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + Executes a call to create a smart contract. + + Parameters + ---------- + message : + Transaction specific items. + env : + External items required for EVM execution. + + Returns + ------- + evm: :py:class:`~ethereum.muir_glacier.vm.Evm` + Items containing execution specific objects + " in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_field (| M.get_name (| globals, "message" |), "depth" |), M.get_name (| globals, "STACK_DEPTH_LIMIT" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "StackDepthLimitError" |), + make_list [ + Constant.str "Stack depth limit reached" + ], + make_dict [] + |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "begin_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "touch_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + M.get_field (| M.get_name (| globals, "message" |), "should_transfer_value" |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_field (| M.get_name (| globals, "message" |), "value" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "move_ether" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "caller" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |); + M.get_field (| M.get_name (| globals, "message" |), "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let evm := + M.call (| + M.get_name (| globals, "execute_code" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "rollback_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "commit_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.get_name (| globals, "evm" |) + |) in + M.pure Constant.None_)). + +Definition execute_code : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + Executes bytecode present in the `message`. + + Parameters + ---------- + message : + Transaction specific items. + env : + External items required for EVM execution. + + Returns + ------- + evm: `ethereum.vm.EVM` + Items containing execution specific objects + " in + let code := + M.get_field (| M.get_name (| globals, "message" |), "code" |) in + let valid_jump_destinations := + M.call (| + M.get_name (| globals, "get_valid_jump_destinations" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) in + let evm := + M.call (| + M.get_name (| globals, "Evm" |), + make_list [], + make_dict [] + |) in +(* At stmt: unsupported node type: Try *) + let _ := M.return_ (| + M.get_name (| globals, "evm" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/vm/memory.v b/CoqOfPython/ethereum/muir_glacier/vm/memory.v new file mode 100644 index 0000000..fa8d906 --- /dev/null +++ b/CoqOfPython/ethereum/muir_glacier/vm/memory.v @@ -0,0 +1,153 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Memory +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +EVM memory operations. +". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_right_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "right_pad_zero_bytes". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". + +Definition memory_write : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "memory"; "start_position"; "value" ] |) in + let _ := Constant.str " + Writes to memory. + + Parameters + ---------- + memory : + Memory contents of the EVM. + start_position : + Starting pointer to the memory. + value : + Data to write to memory. + " in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) |), + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_)). + +Definition memory_read_bytes : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "memory"; "start_position"; "size" ] |) in + let _ := Constant.str " + Read bytes from memory. + + Parameters + ---------- + memory : + Memory contents of the EVM. + start_position : + Starting pointer to the memory. + size : + Size of the data that needs to be read from `start_position`. + + Returns + ------- + data_bytes : + Data read from memory. + " in + let _ := M.return_ (| + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |) + |) in + M.pure Constant.None_)). + +Definition buffer_read : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "buffer"; "start_position"; "size" ] |) in + let _ := Constant.str " + Read bytes from a buffer. Padding with zeros if necessary. + + Parameters + ---------- + buffer : + Memory contents of the EVM. + start_position : + Starting pointer to the memory. + size : + Size of the data that needs to be read from `start_position`. + + Returns + ------- + data_bytes : + Data read from memory. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "right_pad_zero_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/__init__.v new file mode 100644 index 0000000..ca49311 --- /dev/null +++ b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/__init__.v @@ -0,0 +1,117 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Precompiled Contract Addresses +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Addresses of precompiled contracts and mappings to their +implementations. +". + +Require utils.hexadecimal. +Axiom utils_hexadecimal_hex_to_address : + IsGlobalAlias globals utils.hexadecimal.globals "hex_to_address". + +Definition __all__ : Value.t := M.run ltac:(M.monadic ( + make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS"; Constant.str "MODEXP_ADDRESS"; Constant.str "ALT_BN128_ADD_ADDRESS"; Constant.str "ALT_BN128_MUL_ADDRESS"; Constant.str "ALT_BN128_PAIRING_CHECK_ADDRESS"; Constant.str "BLAKE2F_ADDRESS" ] +)). + +Definition ECRECOVER_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x01" + ], + make_dict [] + |) +)). + +Definition SHA256_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x02" + ], + make_dict [] + |) +)). + +Definition RIPEMD160_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x03" + ], + make_dict [] + |) +)). + +Definition IDENTITY_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x04" + ], + make_dict [] + |) +)). + +Definition MODEXP_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x05" + ], + make_dict [] + |) +)). + +Definition ALT_BN128_ADD_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x06" + ], + make_dict [] + |) +)). + +Definition ALT_BN128_MUL_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x07" + ], + make_dict [] + |) +)). + +Definition ALT_BN128_PAIRING_CHECK_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x08" + ], + make_dict [] + |) +)). + +Definition BLAKE2F_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x09" + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/alt_bn128.v new file mode 100644 index 0000000..19b83fc --- /dev/null +++ b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/alt_bn128.v @@ -0,0 +1,673 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) ALT_BN128 CONTRACTS +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the ALT_BN128 precompiled contracts. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.alt_bn128. +Axiom ethereum_crypto_alt_bn128_ALT_BN128_CURVE_ORDER : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "ALT_BN128_CURVE_ORDER". +Axiom ethereum_crypto_alt_bn128_ALT_BN128_PRIME : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "ALT_BN128_PRIME". +Axiom ethereum_crypto_alt_bn128_BNF : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF". +Axiom ethereum_crypto_alt_bn128_BNF2 : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF2". +Axiom ethereum_crypto_alt_bn128_BNF12 : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF12". +Axiom ethereum_crypto_alt_bn128_BNP : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNP". +Axiom ethereum_crypto_alt_bn128_BNP2 : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNP2". +Axiom ethereum_crypto_alt_bn128_pairing : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "pairing". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require vm.memory. +Axiom vm_memory_buffer_read : + IsGlobalAlias globals vm.memory.globals "buffer_read". + +Require exceptions. +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". + +Definition alt_bn128_add : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + The ALT_BN128 addition precompiled contract. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 150 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x0_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x0_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "x0_bytes" |) + ], + make_dict [] + |) in + let y0_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y0_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "y0_bytes" |) + ], + make_dict [] + |) in + let x1_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x1_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "x1_bytes" |) + ], + make_dict [] + |) in + let y1_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y1_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "y1_bytes" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ] do + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "i" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. +(* At stmt: unsupported node type: Try *) + let p := + BinOp.add (| + M.get_name (| globals, "p0" |), + M.get_name (| globals, "p1" |) + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + BinOp.add (| + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "p" |), "x" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "p" |), "y" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) + |) in + M.pure Constant.None_)). + +Definition alt_bn128_mul : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + The ALT_BN128 multiplication precompiled contract. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 6000 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x0_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x0_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "x0_bytes" |) + ], + make_dict [] + |) in + let y0_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y0_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "y0_bytes" |) + ], + make_dict [] + |) in + let n := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ] do + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "i" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. +(* At stmt: unsupported node type: Try *) + let p := + M.call (| + M.get_field (| M.get_name (| globals, "p0" |), "mul_by" |), + make_list [ + M.get_name (| globals, "n" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + BinOp.add (| + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "p" |), "x" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "p" |), "y" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) + |) in + M.pure Constant.None_)). + +Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + The ALT_BN128 pairing check precompiled contract. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 34000, + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 192 + |) + |), + Constant.int 45000 + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 192 + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 192 + |) + ], + make_dict [] + |) do + let values := + make_list [] in + For M.get_name (| globals, "j" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 6 + ], + make_dict [] + |) do + let value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "data" |), BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + M.get_name (| globals, "j" |) + |) + |):BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "j" |), + Constant.int 1 + |) + |) + |) |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "value" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "values" |), "append" |), + make_list [ + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + EndFor. +(* At stmt: unsupported node type: Try *) + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.call (| + M.get_field (| M.get_name (| globals, "p" |), "mul_by" |), + make_list [ + M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) + ], + make_dict [] + |), M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) |); + M.get_name (| globals, "OutOfGasError" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.call (| + M.get_field (| M.get_name (| globals, "q" |), "mul_by" |), + make_list [ + M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) + ], + make_dict [] + |), M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) |); + M.get_name (| globals, "OutOfGasError" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "p" |), M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_name (| globals, "q" |), M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let result := + BinOp.mult (| + M.get_name (| globals, "result" |), + M.call (| + M.get_name (| globals, "pairing" |), + make_list [ + M.get_name (| globals, "q" |); + M.get_name (| globals, "p" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "result" |), M.call (| + M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/blake2f.v b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/blake2f.v new file mode 100644 index 0000000..5903066 --- /dev/null +++ b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/blake2f.v @@ -0,0 +1,122 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Blake2 PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `Blake2` precompiled contract. +". + +Require ethereum.crypto.blake2. +Axiom ethereum_crypto_blake2_Blake2b : + IsGlobalAlias globals ethereum.crypto.blake2.globals "Blake2b". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_BLAKE2_PER_ROUND : + IsGlobalAlias globals vm.gas.globals "GAS_BLAKE2_PER_ROUND". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require exceptions. +Axiom exceptions_InvalidParameter : + IsGlobalAlias globals exceptions.globals "InvalidParameter". + +Definition blake2f : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the Blake2 hash to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), Constant.int 213 |); + M.get_name (| globals, "InvalidParameter" |) + ], + make_dict [] + |) in + let blake2b := + M.call (| + M.get_name (| globals, "Blake2b" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "rounds" |); M.get_name (| globals, "h" |); M.get_name (| globals, "m" |); M.get_name (| globals, "t_0" |); M.get_name (| globals, "t_1" |); M.get_name (| globals, "f" |) ], + M.call (| + M.get_field (| M.get_name (| globals, "blake2b" |), "get_blake2_parameters" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.mult (| + M.get_name (| globals, "GAS_BLAKE2_PER_ROUND" |), + M.get_name (| globals, "rounds" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.in (| M.get_name (| globals, "f" |), make_list [ + Constant.int 0; + Constant.int 1 + ] |); + M.get_name (| globals, "InvalidParameter" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.get_name (| globals, "blake2b" |), "compress" |), + make_list [ + M.get_name (| globals, "rounds" |); + M.get_name (| globals, "h" |); + M.get_name (| globals, "m" |); + M.get_name (| globals, "t_0" |); + M.get_name (| globals, "t_1" |); + M.get_name (| globals, "f" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/ecrecover.v new file mode 100644 index 0000000..cc351b5 --- /dev/null +++ b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/ecrecover.v @@ -0,0 +1,269 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) ECRECOVER PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the ECRECOVER precompiled contract. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require ethereum.crypto.elliptic_curve. +Axiom ethereum_crypto_elliptic_curve_SECP256K1N : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_left_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_ECRECOVER : + IsGlobalAlias globals vm.gas.globals "GAS_ECRECOVER". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require vm.memory. +Axiom vm_memory_buffer_read : + IsGlobalAlias globals vm.memory.globals "buffer_read". + +Definition ecrecover : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Decrypts the address using elliptic curve DSA recovery mechanism and writes + the address to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_ECRECOVER" |) + ], + make_dict [] + |) in + let message_hash_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let message_hash := + M.call (| + M.get_name (| globals, "Hash32" |), + make_list [ + M.get_name (| globals, "message_hash_bytes" |) + ], + make_dict [] + |) in + let v := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let r := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let s := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 27 |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 28 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| Constant.int 0, M.get_name (| globals, "r" |) |), + ltac:(M.monadic ( + Compare.gt_e (| M.get_name (| globals, "r" |), M.get_name (| globals, "SECP256K1N" |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| Constant.int 0, M.get_name (| globals, "s" |) |), + ltac:(M.monadic ( + Compare.gt_e (| M.get_name (| globals, "s" |), M.get_name (| globals, "SECP256K1N" |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in +(* At stmt: unsupported node type: Try *) + let address := + M.get_subscript (| M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), Constant.int 12:Constant.int 32 |) in + let padded_address := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "address" |); + Constant.int 32 + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.get_name (| globals, "padded_address" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/identity.v new file mode 100644 index 0000000..fa96704 --- /dev/null +++ b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/identity.v @@ -0,0 +1,94 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) IDENTITY PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `IDENTITY` precompiled contract. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_IDENTITY : + IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY". +Axiom vm_gas_GAS_IDENTITY_WORD : + IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY_WORD". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition identity : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the message data to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let word_count := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_IDENTITY" |), + BinOp.mult (| + M.get_name (| globals, "GAS_IDENTITY_WORD" |), + M.get_name (| globals, "word_count" |) + |) + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.get_name (| globals, "data" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/mapping.v new file mode 100644 index 0000000..8a2e2eb --- /dev/null +++ b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/mapping.v @@ -0,0 +1,82 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Precompiled Contract Addresses +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Mapping of precompiled contracts their implementations. +". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require __init__. +Axiom __init___ALT_BN128_ADD_ADDRESS : + IsGlobalAlias globals __init__.globals "ALT_BN128_ADD_ADDRESS". +Axiom __init___ALT_BN128_MUL_ADDRESS : + IsGlobalAlias globals __init__.globals "ALT_BN128_MUL_ADDRESS". +Axiom __init___ALT_BN128_PAIRING_CHECK_ADDRESS : + IsGlobalAlias globals __init__.globals "ALT_BN128_PAIRING_CHECK_ADDRESS". +Axiom __init___BLAKE2F_ADDRESS : + IsGlobalAlias globals __init__.globals "BLAKE2F_ADDRESS". +Axiom __init___ECRECOVER_ADDRESS : + IsGlobalAlias globals __init__.globals "ECRECOVER_ADDRESS". +Axiom __init___IDENTITY_ADDRESS : + IsGlobalAlias globals __init__.globals "IDENTITY_ADDRESS". +Axiom __init___MODEXP_ADDRESS : + IsGlobalAlias globals __init__.globals "MODEXP_ADDRESS". +Axiom __init___RIPEMD160_ADDRESS : + IsGlobalAlias globals __init__.globals "RIPEMD160_ADDRESS". +Axiom __init___SHA256_ADDRESS : + IsGlobalAlias globals __init__.globals "SHA256_ADDRESS". + +Require alt_bn128. +Axiom alt_bn128_alt_bn128_add : + IsGlobalAlias globals alt_bn128.globals "alt_bn128_add". +Axiom alt_bn128_alt_bn128_mul : + IsGlobalAlias globals alt_bn128.globals "alt_bn128_mul". +Axiom alt_bn128_alt_bn128_pairing_check : + IsGlobalAlias globals alt_bn128.globals "alt_bn128_pairing_check". + +Require blake2f. +Axiom blake2f_blake2f : + IsGlobalAlias globals blake2f.globals "blake2f". + +Require ecrecover. +Axiom ecrecover_ecrecover : + IsGlobalAlias globals ecrecover.globals "ecrecover". + +Require identity. +Axiom identity_identity : + IsGlobalAlias globals identity.globals "identity". + +Require modexp. +Axiom modexp_modexp : + IsGlobalAlias globals modexp.globals "modexp". + +Require ripemd160. +Axiom ripemd160_ripemd160 : + IsGlobalAlias globals ripemd160.globals "ripemd160". + +Require sha256. +Axiom sha256_sha256 : + IsGlobalAlias globals sha256.globals "sha256". + +(* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/modexp.v new file mode 100644 index 0000000..39ce4f9 --- /dev/null +++ b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/modexp.v @@ -0,0 +1,506 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) MODEXP PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `MODEXP` precompiled contract. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require memory. +Axiom memory_buffer_read : + IsGlobalAlias globals memory.globals "buffer_read". + +Definition GQUADDIVISOR : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 20 + ], + make_dict [] + |) +)). + +Definition modexp : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Calculates `(base**exp) % modulus` for arbitrary sized `base`, `exp` and. + `modulus`. The return value is the same length as the modulus. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let base_length := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exp_length := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let modulus_length := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exp_start := + BinOp.add (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |), + M.get_name (| globals, "base_length" |) + |) in + let exp_head := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.get_name (| globals, "exp_start" |); + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.get_name (| globals, "exp_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "exp_length" |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let adjusted_exp_length := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "max" |), + make_list [ + Constant.int 0; + BinOp.sub (| + M.call (| + M.get_field (| M.get_name (| globals, "exp_head" |), "bit_length" |), + make_list [], + make_dict [] + |), + Constant.int 1 + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let adjusted_exp_length := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 8, + BinOp.sub (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "exp_length" |) + ], + make_dict [] + |), + Constant.int 32 + |) + |), + M.call (| + M.get_name (| globals, "max" |), + make_list [ + Constant.int 0; + BinOp.sub (| + M.call (| + M.get_field (| M.get_name (| globals, "exp_head" |), "bit_length" |), + make_list [], + make_dict [] + |), + Constant.int 1 + |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.floor_div (| + BinOp.mult (| + M.call (| + M.get_name (| globals, "get_mult_complexity" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "max" |), + make_list [ + M.get_name (| globals, "base_length" |); + M.get_name (| globals, "modulus_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "max" |), + make_list [ + M.get_name (| globals, "adjusted_exp_length" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + ], + make_dict [] + |) + |), + M.get_name (| globals, "GQUADDIVISOR" |) + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_name (| globals, "base_length" |), Constant.int 0 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "modulus_length" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [], + make_dict [] + |) + |) in + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let base := + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |); + M.get_name (| globals, "base_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exp := + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.get_name (| globals, "exp_start" |); + M.get_name (| globals, "exp_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let modulus_start := + BinOp.add (| + M.get_name (| globals, "exp_start" |), + M.get_name (| globals, "exp_length" |) + |) in + let modulus := + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.get_name (| globals, "modulus_start" |); + M.get_name (| globals, "modulus_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "modulus" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + BinOp.mult (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |), + M.get_name (| globals, "modulus_length" |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pow" |), + make_list [ + M.get_name (| globals, "base" |); + M.get_name (| globals, "exp" |); + M.get_name (| globals, "modulus" |) + ], + make_dict [] + |) + ], + make_dict [] + |), "to_bytes" |), + make_list [ + M.get_name (| globals, "modulus_length" |); + Constant.str "big" + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition get_mult_complexity : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "x" ] |) in + let _ := Constant.str " + Estimate the complexity of performing Karatsuba multiplication. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| M.get_name (| globals, "x" |), Constant.int 64 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.pow (| + M.get_name (| globals, "x" |), + Constant.int 2 + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| M.get_name (| globals, "x" |), Constant.int 1024 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.sub (| + BinOp.add (| + BinOp.floor_div (| + BinOp.pow (| + M.get_name (| globals, "x" |), + Constant.int 2 + |), + Constant.int 4 + |), + BinOp.mult (| + Constant.int 96, + M.get_name (| globals, "x" |) + |) + |), + Constant.int 3072 + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.sub (| + BinOp.add (| + BinOp.floor_div (| + BinOp.pow (| + M.get_name (| globals, "x" |), + Constant.int 2 + |), + Constant.int 16 + |), + BinOp.mult (| + Constant.int 480, + M.get_name (| globals, "x" |) + |) + |), + Constant.int 199680 + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/ripemd160.v new file mode 100644 index 0000000..96f8dcd --- /dev/null +++ b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/ripemd160.v @@ -0,0 +1,122 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) RIPEMD160 PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `RIPEMD160` precompiled contract. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_left_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_RIPEMD160 : + IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160". +Axiom vm_gas_GAS_RIPEMD160_WORD : + IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160_WORD". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition ripemd160 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the ripemd160 hash to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let word_count := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_RIPEMD160" |), + BinOp.mult (| + M.get_name (| globals, "GAS_RIPEMD160_WORD" |), + M.get_name (| globals, "word_count" |) + |) + |) + ], + make_dict [] + |) in + let hash_bytes := + M.call (| + M.get_field (| M.call (| + M.get_field (| M.get_name (| globals, "hashlib" |), "new" |), + make_list [ + Constant.str "ripemd160"; + M.get_name (| globals, "data" |) + ], + make_dict [] + |), "digest" |), + make_list [], + make_dict [] + |) in + let padded_hash := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "hash_bytes" |); + Constant.int 32 + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.get_name (| globals, "padded_hash" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/sha256.v new file mode 100644 index 0000000..9f6d2bf --- /dev/null +++ b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/sha256.v @@ -0,0 +1,106 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) SHA256 PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `SHA256` precompiled contract. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_SHA256 : + IsGlobalAlias globals vm.gas.globals "GAS_SHA256". +Axiom vm_gas_GAS_SHA256_WORD : + IsGlobalAlias globals vm.gas.globals "GAS_SHA256_WORD". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition sha256 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the sha256 hash to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let word_count := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_SHA256" |), + BinOp.mult (| + M.get_name (| globals, "GAS_SHA256_WORD" |), + M.get_name (| globals, "word_count" |) + |) + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_field (| M.get_name (| globals, "hashlib" |), "sha256" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), "digest" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/vm/runtime.v b/CoqOfPython/ethereum/muir_glacier/vm/runtime.v new file mode 100644 index 0000000..835b46c --- /dev/null +++ b/CoqOfPython/ethereum/muir_glacier/vm/runtime.v @@ -0,0 +1,125 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Runtime Operations +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Runtime related operations used while executing EVM code. +". + +Require typing. +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require instructions. +Axiom instructions_Ops : + IsGlobalAlias globals instructions.globals "Ops". + +Definition get_valid_jump_destinations : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "code" ] |) in + let _ := Constant.str " + Analyze the evm code to obtain the set of valid jump destinations. + + Valid jump destinations are defined as follows: + * The jump destination is less than the length of the code. + * The jump destination should have the `JUMPDEST` opcode (0x5B). + * The jump destination shouldn't be part of the data corresponding to + `PUSH-N` opcodes. + + Note - Jump destinations are 0-indexed. + + Parameters + ---------- + code : + The EVM code which is to be executed. + + Returns + ------- + valid_jump_destinations: `Set[Uint]` + The set of valid jump destinations in the code. + " in + let valid_jump_destinations := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let pc := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + While Compare.lt (| M.get_name (| globals, "pc" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) |) do +(* At stmt: unsupported node type: Try *) + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "current_opcode" |), M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), + make_list [ + M.get_name (| globals, "pc" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + (* At expr: unsupported node type: Compare *), + (* then *) + ltac:(M.monadic ( + let push_data_size := + BinOp.add (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) + |), + Constant.int 1 + |) in + let pc := BinOp.add + M.get_name (| globals, "push_data_size" |) + M.get_name (| globals, "push_data_size" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let pc := BinOp.add + Constant.int 1 + Constant.int 1 in + EndWhile. + let _ := M.return_ (| + M.get_name (| globals, "valid_jump_destinations" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/vm/stack.v b/CoqOfPython/ethereum/muir_glacier/vm/stack.v new file mode 100644 index 0000000..42ea42d --- /dev/null +++ b/CoqOfPython/ethereum/muir_glacier/vm/stack.v @@ -0,0 +1,120 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Stack +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the stack operators for the EVM. +". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require exceptions. +Axiom exceptions_StackOverflowError : + IsGlobalAlias globals exceptions.globals "StackOverflowError". +Axiom exceptions_StackUnderflowError : + IsGlobalAlias globals exceptions.globals "StackUnderflowError". + +Definition pop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "stack" ] |) in + let _ := Constant.str " + Pops the top item off of `stack`. + + Parameters + ---------- + stack : + EVM stack. + + Returns + ------- + value : `U256` + The top element on the stack. + + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "StackUnderflowError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "pop" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition push : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "stack"; "value" ] |) in + let _ := Constant.str " + Pushes `value` onto `stack`. + + Parameters + ---------- + stack : + EVM stack. + + value : + Item to be pushed onto `stack`. + + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), Constant.int 1024 |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "StackOverflowError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "append" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/__init__.v b/CoqOfPython/ethereum/paris/__init__.v new file mode 100644 index 0000000..27930db --- /dev/null +++ b/CoqOfPython/ethereum/paris/__init__.v @@ -0,0 +1,27 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +The Paris fork transitions Ethereum from a proof-of-work consensus model to a +proof-of-stake one. This fork is often referred to as """The Merge""" because it +marks the integration of the [consensus layer] with the execution layer +(defined in this project.) + +[consensus layer]: https://github.com/ethereum/consensus-specs +". + +Require ethereum.fork_criteria. +Axiom ethereum_fork_criteria_ByBlockNumber : + IsGlobalAlias globals ethereum.fork_criteria.globals "ByBlockNumber". + +Definition FORK_CRITERIA : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "ByBlockNumber" |), + make_list [ + Constant.int 15537394 + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/paris/blocks.v b/CoqOfPython/ethereum/paris/blocks.v new file mode 100644 index 0000000..a90217e --- /dev/null +++ b/CoqOfPython/ethereum/paris/blocks.v @@ -0,0 +1,95 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +A `Block` is a single link in the chain that is Ethereum. Each `Block` contains +a `Header` and zero or more transactions. Each `Header` contains associated +metadata like the block number, parent block hash, and how much gas was +consumed by its transactions. + +Together, these blocks form a cryptographically secure journal recording the +history of all state transitions that have happened since the genesis of the +chain. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes8 : + IsGlobalAlias globals base_types.globals "Bytes8". +Axiom base_types_Bytes32 : + IsGlobalAlias globals base_types.globals "Bytes32". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require crypto.hash. +Axiom crypto_hash_Hash32 : + IsGlobalAlias globals crypto.hash.globals "Hash32". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Require transactions. +Axiom transactions_LegacyTransaction : + IsGlobalAlias globals transactions.globals "LegacyTransaction". + +Definition Header : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Block : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Log : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Receipt : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. diff --git a/CoqOfPython/ethereum/paris/bloom.v b/CoqOfPython/ethereum/paris/bloom.v new file mode 100644 index 0000000..04b5d9f --- /dev/null +++ b/CoqOfPython/ethereum/paris/bloom.v @@ -0,0 +1,164 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Logs Bloom +^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +This modules defines functions for calculating bloom filters of logs. For the +general theory of bloom filters see e.g. `Wikipedia +`_. Bloom filters are used to allow +for efficient searching of logs by address and/or topic, by rapidly +eliminating blocks and receipts from their search. +". + +Require typing. +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require fork_types. +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". + +Definition add_to_bloom : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "bloom"; "bloom_entry" ] |) in + let _ := Constant.str " + Add a bloom entry to the bloom filter (`bloom`). + + The number of hash functions used is 3. They are calculated by taking the + least significant 11 bits from the first 3 16-bit words of the + `keccak_256()` hash of `bloom_entry`. + + Parameters + ---------- + bloom : + The bloom filter. + bloom_entry : + An entry which is to be added to bloom filter. + " in + let hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "bloom_entry" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "idx" |) in make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ] do + let bit_to_set := + BinOp.bit_and (| + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |):BinOp.add (| + M.get_name (| globals, "idx" |), + Constant.int 2 + |) |) + ], + make_dict [] + |), + Constant.int 2047 + |) in + let bit_index := + BinOp.sub (| + Constant.int 2047, + M.get_name (| globals, "bit_to_set" |) + |) in + let byte_index := + BinOp.floor_div (| + M.get_name (| globals, "bit_index" |), + Constant.int 8 + |) in + let bit_value := + BinOp.l_shift (| + Constant.int 1, + BinOp.sub (| + Constant.int 7, + BinOp.mod_ (| + M.get_name (| globals, "bit_index" |), + Constant.int 8 + |) + |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), + BinOp.bit_or (| + M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), + M.get_name (| globals, "bit_value" |) + |) + |) in + EndFor. + M.pure Constant.None_)). + +Definition logs_bloom : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "logs" ] |) in + let _ := Constant.str " + Obtain the logs bloom from a list of log entries. + + The address and each topic of a log are added to the bloom filter. + + Parameters + ---------- + logs : + List of logs for which the logs bloom is to be obtained. + + Returns + ------- + logs_bloom : `Bloom` + The logs bloom obtained which is 256 bytes with some bits set as per + the caller address and the log topics. + " in +(* At stmt: unsupported node type: AnnAssign *) + For M.get_name (| globals, "log" |) in M.get_name (| globals, "logs" |) do + let _ := M.call (| + M.get_name (| globals, "add_to_bloom" |), + make_list [ + M.get_name (| globals, "bloom" |); + M.get_field (| M.get_name (| globals, "log" |), "address" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "topic" |) in M.get_field (| M.get_name (| globals, "log" |), "topics" |) do + let _ := M.call (| + M.get_name (| globals, "add_to_bloom" |), + make_list [ + M.get_name (| globals, "bloom" |); + M.get_name (| globals, "topic" |) + ], + make_dict [] + |) in + EndFor. + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bloom" |), + make_list [ + M.get_name (| globals, "bloom" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/fork.v b/CoqOfPython/ethereum/paris/fork.v new file mode 100644 index 0000000..ec98469 --- /dev/null +++ b/CoqOfPython/ethereum/paris/fork.v @@ -0,0 +1,2243 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Specification +^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Entry point for the Ethereum specification. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". + +Require ethereum.crypto.elliptic_curve. +Axiom ethereum_crypto_elliptic_curve_SECP256K1N : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.exceptions. +Axiom ethereum_exceptions_InvalidBlock : + IsGlobalAlias globals ethereum.exceptions.globals "InvalidBlock". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U64 : + IsGlobalAlias globals base_types.globals "U64". +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". + +Require __init__. +Axiom __init___vm : + IsGlobalAlias globals __init__.globals "vm". + +Require blocks. +Axiom blocks_Block : + IsGlobalAlias globals blocks.globals "Block". +Axiom blocks_Header : + IsGlobalAlias globals blocks.globals "Header". +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". +Axiom blocks_Receipt : + IsGlobalAlias globals blocks.globals "Receipt". + +Require bloom. +Axiom bloom_logs_bloom : + IsGlobalAlias globals bloom.globals "logs_bloom". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Require state. +Axiom state_State : + IsGlobalAlias globals state.globals "State". +Axiom state_account_exists_and_is_empty : + IsGlobalAlias globals state.globals "account_exists_and_is_empty". +Axiom state_destroy_account : + IsGlobalAlias globals state.globals "destroy_account". +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". +Axiom state_increment_nonce : + IsGlobalAlias globals state.globals "increment_nonce". +Axiom state_set_account_balance : + IsGlobalAlias globals state.globals "set_account_balance". +Axiom state_state_root : + IsGlobalAlias globals state.globals "state_root". + +Require transactions. +Axiom transactions_TX_ACCESS_LIST_ADDRESS_COST : + IsGlobalAlias globals transactions.globals "TX_ACCESS_LIST_ADDRESS_COST". +Axiom transactions_TX_ACCESS_LIST_STORAGE_KEY_COST : + IsGlobalAlias globals transactions.globals "TX_ACCESS_LIST_STORAGE_KEY_COST". +Axiom transactions_TX_BASE_COST : + IsGlobalAlias globals transactions.globals "TX_BASE_COST". +Axiom transactions_TX_CREATE_COST : + IsGlobalAlias globals transactions.globals "TX_CREATE_COST". +Axiom transactions_TX_DATA_COST_PER_NON_ZERO : + IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_NON_ZERO". +Axiom transactions_TX_DATA_COST_PER_ZERO : + IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_ZERO". +Axiom transactions_AccessListTransaction : + IsGlobalAlias globals transactions.globals "AccessListTransaction". +Axiom transactions_FeeMarketTransaction : + IsGlobalAlias globals transactions.globals "FeeMarketTransaction". +Axiom transactions_LegacyTransaction : + IsGlobalAlias globals transactions.globals "LegacyTransaction". +Axiom transactions_Transaction : + IsGlobalAlias globals transactions.globals "Transaction". +Axiom transactions_decode_transaction : + IsGlobalAlias globals transactions.globals "decode_transaction". +Axiom transactions_encode_transaction : + IsGlobalAlias globals transactions.globals "encode_transaction". + +Require trie. +Axiom trie_Trie : + IsGlobalAlias globals trie.globals "Trie". +Axiom trie_root : + IsGlobalAlias globals trie.globals "root". +Axiom trie_trie_set : + IsGlobalAlias globals trie.globals "trie_set". + +Require utils.message. +Axiom utils_message_prepare_message : + IsGlobalAlias globals utils.message.globals "prepare_message". + +Require vm.interpreter. +Axiom vm_interpreter_process_message_call : + IsGlobalAlias globals vm.interpreter.globals "process_message_call". + +Definition BASE_FEE_MAX_CHANGE_DENOMINATOR : Value.t := M.run ltac:(M.monadic ( + Constant.int 8 +)). + +Definition ELASTICITY_MULTIPLIER : Value.t := M.run ltac:(M.monadic ( + Constant.int 2 +)). + +Definition GAS_LIMIT_ADJUSTMENT_FACTOR : Value.t := M.run ltac:(M.monadic ( + Constant.int 1024 +)). + +Definition GAS_LIMIT_MINIMUM : Value.t := M.run ltac:(M.monadic ( + Constant.int 5000 +)). + +Definition EMPTY_OMMER_HASH : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_list [] + ], + make_dict [] + |) + ], + make_dict [] + |) +)). + +Definition BlockChain : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition apply_fork : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "old" ] |) in + let _ := Constant.str " + Transforms the state from the previous hard fork (`old`) into the block + chain object for this hard fork and returns it. + + When forks need to implement an irregular state transition, this function + is used to handle the irregularity. See the :ref:`DAO Fork ` for + an example. + + Parameters + ---------- + old : + Previous block chain object. + + Returns + ------- + new : `BlockChain` + Upgraded block chain object for this hard fork. + " in + let _ := M.return_ (| + M.get_name (| globals, "old" |) + |) in + M.pure Constant.None_)). + +Definition get_last_256_block_hashes : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "chain" ] |) in + let _ := Constant.str " + Obtain the list of hashes of the previous 256 blocks in order of + increasing block number. + + This function will return less hashes for the first 256 blocks. + + The ``BLOCKHASH`` opcode needs to access the latest hashes on the chain, + therefore this function retrieves them. + + Parameters + ---------- + chain : + History and current state. + + Returns + ------- + recent_block_hashes : `List[Hash32]` + Hashes of the recent 256 blocks in order of increasing block number. + " in + let recent_blocks := + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |):(* At expr: unsupported node type: NoneType *) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "recent_blocks" |) + ], + make_dict [] + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + make_list [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let recent_block_hashes := + make_list [] in + For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_blocks" |) do + let prev_block_hash := + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), + make_list [ + M.get_name (| globals, "prev_block_hash" |) + ], + make_dict [] + |) in + EndFor. + let most_recent_block_hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_field (| M.get_subscript (| M.get_name (| globals, "recent_blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), + make_list [ + M.get_name (| globals, "most_recent_block_hash" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "recent_block_hashes" |) + |) in + M.pure Constant.None_)). + +Definition state_transition : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "chain"; "block" ] |) in + let _ := Constant.str " + Attempts to apply a block to an existing block chain. + + All parts of the block's contents need to be verified before being added + to the chain. Blocks are verified by ensuring that the contents of the + block make logical sense with the contents of the parent block. The + information in the block's header must also match the corresponding + information in the block. + + To implement Ethereum, in theory clients are only required to store the + most recent 255 blocks of the chain since as far as execution is + concerned, only those blocks are accessed. Practically, however, clients + should store more blocks to handle reorgs. + + Parameters + ---------- + chain : + History and current state. + block : + Block to apply to `chain`. + " in + let parent_header := + M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) in + let _ := M.call (| + M.get_name (| globals, "validate_header" |), + make_list [ + M.get_field (| M.get_name (| globals, "block" |), "header" |); + M.get_name (| globals, "parent_header" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "block" |), "ommers" |), make_tuple [ ] |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let apply_body_output := + M.call (| + M.get_name (| globals, "apply_body" |), + make_list [ + M.get_field (| M.get_name (| globals, "chain" |), "state" |); + M.call (| + M.get_name (| globals, "get_last_256_block_hashes" |), + make_list [ + M.get_name (| globals, "chain" |) + ], + make_dict [] + |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "coinbase" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "number" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "base_fee_per_gas" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "gas_limit" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "timestamp" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "prev_randao" |); + M.get_field (| M.get_name (| globals, "block" |), "transactions" |); + M.get_field (| M.get_name (| globals, "chain" |), "chain_id" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_gas_used" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "gas_used" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "transactions_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "transactions_root" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "state_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "state_root" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "receipt_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "receipt_root" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_logs_bloom" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "bloom" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), "append" |), + make_list [ + M.get_name (| globals, "block" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |) + ], + make_dict [] + |), Constant.int 255 |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |):(* At expr: unsupported node type: NoneType *) |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "block_gas_limit"; "parent_gas_limit"; "parent_gas_used"; "parent_base_fee_per_gas" ] |) in + let _ := Constant.str " + Calculates the base fee per gas for the block. + + Parameters + ---------- + block_gas_limit : + Gas limit of the block for which the base fee is being calculated. + parent_gas_limit : + Gas limit of the parent block. + parent_gas_used : + Gas used in the parent block. + parent_base_fee_per_gas : + Base fee per gas of the parent block. + + Returns + ------- + base_fee_per_gas : `Uint` + Base fee per gas for the block. + " in + let parent_gas_target := + BinOp.floor_div (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "ELASTICITY_MULTIPLIER" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + M.call (| + M.get_name (| globals, "check_gas_limit" |), + make_list [ + M.get_name (| globals, "block_gas_limit" |); + M.get_name (| globals, "parent_gas_limit" |) + ], + make_dict [] + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "parent_gas_used" |), M.get_name (| globals, "parent_gas_target" |) |), + (* then *) + ltac:(M.monadic ( + let expected_base_fee_per_gas := + M.get_name (| globals, "parent_base_fee_per_gas" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "parent_gas_used" |), M.get_name (| globals, "parent_gas_target" |) |), + (* then *) + ltac:(M.monadic ( + let gas_used_delta := + BinOp.sub (| + M.get_name (| globals, "parent_gas_used" |), + M.get_name (| globals, "parent_gas_target" |) + |) in + let parent_fee_gas_delta := + BinOp.mult (| + M.get_name (| globals, "parent_base_fee_per_gas" |), + M.get_name (| globals, "gas_used_delta" |) + |) in + let target_fee_gas_delta := + BinOp.floor_div (| + M.get_name (| globals, "parent_fee_gas_delta" |), + M.get_name (| globals, "parent_gas_target" |) + |) in + let base_fee_per_gas_delta := + M.call (| + M.get_name (| globals, "max" |), + make_list [ + BinOp.floor_div (| + M.get_name (| globals, "target_fee_gas_delta" |), + M.get_name (| globals, "BASE_FEE_MAX_CHANGE_DENOMINATOR" |) + |); + Constant.int 1 + ], + make_dict [] + |) in + let expected_base_fee_per_gas := + BinOp.add (| + M.get_name (| globals, "parent_base_fee_per_gas" |), + M.get_name (| globals, "base_fee_per_gas_delta" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let gas_used_delta := + BinOp.sub (| + M.get_name (| globals, "parent_gas_target" |), + M.get_name (| globals, "parent_gas_used" |) + |) in + let parent_fee_gas_delta := + BinOp.mult (| + M.get_name (| globals, "parent_base_fee_per_gas" |), + M.get_name (| globals, "gas_used_delta" |) + |) in + let target_fee_gas_delta := + BinOp.floor_div (| + M.get_name (| globals, "parent_fee_gas_delta" |), + M.get_name (| globals, "parent_gas_target" |) + |) in + let base_fee_per_gas_delta := + BinOp.floor_div (| + M.get_name (| globals, "target_fee_gas_delta" |), + M.get_name (| globals, "BASE_FEE_MAX_CHANGE_DENOMINATOR" |) + |) in + let expected_base_fee_per_gas := + BinOp.sub (| + M.get_name (| globals, "parent_base_fee_per_gas" |), + M.get_name (| globals, "base_fee_per_gas_delta" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "expected_base_fee_per_gas" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition validate_header : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header"; "parent_header" ] |) in + let _ := Constant.str " + Verifies a block header. + + In order to consider a block's header valid, the logic for the + quantities in the header should match the logic for the block itself. + For example the header timestamp should be greater than the block's parent + timestamp because the block was created *after* the parent block. + Additionally, the block's number should be directly following the parent + block's number since it is the next block in the sequence. + + Parameters + ---------- + header : + Header to check for correctness. + parent_header : + Parent Header of the header to check for correctness + " in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| M.get_field (| M.get_name (| globals, "header" |), "gas_used" |), M.get_field (| M.get_name (| globals, "header" |), "gas_limit" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let expected_base_fee_per_gas := + M.call (| + M.get_name (| globals, "calculate_base_fee_per_gas" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "gas_limit" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "gas_limit" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "gas_used" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "base_fee_per_gas" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_name (| globals, "expected_base_fee_per_gas" |), M.get_field (| M.get_name (| globals, "header" |), "base_fee_per_gas" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt (| M.get_field (| M.get_name (| globals, "header" |), "timestamp" |), M.get_field (| M.get_name (| globals, "parent_header" |), "timestamp" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "number" |), BinOp.add (| + M.get_field (| M.get_name (| globals, "parent_header" |), "number" |), + Constant.int 1 + |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) + ], + make_dict [] + |), Constant.int 32 |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "difficulty" |), Constant.int 0 |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "nonce" |), (* At constant: unsupported node type: Constant *) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "ommers_hash" |), M.get_name (| globals, "EMPTY_OMMER_HASH" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let block_parent_hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "parent_header" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |), M.get_name (| globals, "block_parent_hash" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition check_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx"; "base_fee_per_gas"; "gas_available"; "chain_id" ] |) in + let _ := Constant.str " + Check if the transaction is includable in the block. + + Parameters + ---------- + tx : + The transaction. + base_fee_per_gas : + The block base fee. + gas_available : + The gas remaining in the block. + chain_id : + The ID of the current chain. + + Returns + ------- + sender_address : + The sender of the transaction. + effective_gas_price : + The price to charge for gas when the transaction is executed. + + Raises + ------ + InvalidBlock : + If the transaction is not includable. + " in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_name (| globals, "gas_available" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let sender_address := + M.call (| + M.get_name (| globals, "recover_sender" |), + make_list [ + M.get_name (| globals, "chain_id" |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "FeeMarketTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt_e (| M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |), M.get_field (| M.get_name (| globals, "tx" |), "max_priority_fee_per_gas" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt_e (| M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |), M.get_name (| globals, "base_fee_per_gas" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let priority_fee_per_gas := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_field (| M.get_name (| globals, "tx" |), "max_priority_fee_per_gas" |); + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |), + M.get_name (| globals, "base_fee_per_gas" |) + |) + ], + make_dict [] + |) in + let effective_gas_price := + BinOp.add (| + M.get_name (| globals, "priority_fee_per_gas" |), + M.get_name (| globals, "base_fee_per_gas" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt_e (| M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |), M.get_name (| globals, "base_fee_per_gas" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let effective_gas_price := + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + make_tuple [ M.get_name (| globals, "sender_address" |); M.get_name (| globals, "effective_gas_price" |) ] + |) in + M.pure Constant.None_)). + +Definition make_receipt : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx"; "error"; "cumulative_gas_used"; "logs" ] |) in + let _ := Constant.str " + Make the receipt for a transaction that was executed. + + Parameters + ---------- + tx : + The executed transaction. + error : + The error from the execution if any. + cumulative_gas_used : + The total gas used so far in the block after the transaction was + executed. + logs : + The logs produced by the transaction. + + Returns + ------- + receipt : + The receipt for the transaction. + " in + let receipt := + M.call (| + M.get_name (| globals, "Receipt" |), + make_list [], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "AccessListTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + (* At constant: unsupported node type: Constant *), + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "receipt" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "FeeMarketTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + (* At constant: unsupported node type: Constant *), + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "receipt" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "receipt" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition ApplyBodyOutput : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition apply_body : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "block_hashes"; "coinbase"; "block_number"; "base_fee_per_gas"; "block_gas_limit"; "block_time"; "prev_randao"; "transactions"; "chain_id" ] |) in + let _ := Constant.str " + Executes a block. + + Many of the contents of a block are stored in data structures called + tries. There is a transactions trie which is similar to a ledger of the + transactions stored in the current block. There is also a receipts trie + which stores the results of executing a transaction, like the post state + and gas used. This function creates and executes the block that is to be + added to the chain. + + Parameters + ---------- + state : + Current account state. + block_hashes : + List of hashes of the previous 256 blocks in the order of + increasing block number. + coinbase : + Address of account which receives block reward and transaction fees. + block_number : + Position of the block within the chain. + base_fee_per_gas : + Base fee per gas of within the block. + block_gas_limit : + Initial amount of gas available for execution in this block. + block_time : + Time the block was produced, measured in seconds since the epoch. + prev_randao : + The previous randao from the beacon chain. + transactions : + Transactions included in the block. + ommers : + Headers of ancestor blocks which are not direct parents (formerly + uncles.) + chain_id : + ID of the executing chain. + + Returns + ------- + apply_body_output : `ApplyBodyOutput` + Output of applying the block body to the state. + " in + let gas_available := + M.get_name (| globals, "block_gas_limit" |) in +(* At stmt: unsupported node type: AnnAssign *) +(* At stmt: unsupported node type: AnnAssign *) +(* At stmt: unsupported node type: AnnAssign *) + For make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "tx" |) ] in M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.call (| + M.get_name (| globals, "map" |), + make_list [ + M.get_name (| globals, "decode_transaction" |); + M.get_name (| globals, "transactions" |) + ], + make_dict [] + |) + ], + make_dict [] + |) do + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "transactions_trie" |); + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "i" |) + ], + make_dict [] + |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "encode_transaction" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "sender_address" |); M.get_name (| globals, "effective_gas_price" |) ], + M.call (| + M.get_name (| globals, "check_transaction" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "base_fee_per_gas" |); + M.get_name (| globals, "gas_available" |); + M.get_name (| globals, "chain_id" |) + ], + make_dict [] + |) + |) in + let env := + M.call (| + M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |); M.get_name (| globals, "error" |) ], + M.call (| + M.get_name (| globals, "process_transaction" |), + make_list [ + M.get_name (| globals, "env" |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) in + let gas_available := BinOp.sub + M.get_name (| globals, "gas_used" |) + M.get_name (| globals, "gas_used" |) in + let receipt := + M.call (| + M.get_name (| globals, "make_receipt" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "error" |); + BinOp.sub (| + M.get_name (| globals, "block_gas_limit" |), + M.get_name (| globals, "gas_available" |) + |); + M.get_name (| globals, "logs" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "receipts_trie" |); + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "i" |) + ], + make_dict [] + |) + ], + make_dict [] + |); + M.get_name (| globals, "receipt" |) + ], + make_dict [] + |) in + let block_logs := BinOp.add + M.get_name (| globals, "logs" |) + M.get_name (| globals, "logs" |) in + EndFor. + let block_gas_used := + BinOp.sub (| + M.get_name (| globals, "block_gas_limit" |), + M.get_name (| globals, "gas_available" |) + |) in + let block_logs_bloom := + M.call (| + M.get_name (| globals, "logs_bloom" |), + make_list [ + M.get_name (| globals, "block_logs" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ApplyBodyOutput" |), + make_list [ + M.get_name (| globals, "block_gas_used" |); + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_name (| globals, "transactions_trie" |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_name (| globals, "receipts_trie" |) + ], + make_dict [] + |); + M.get_name (| globals, "block_logs_bloom" |); + M.call (| + M.get_name (| globals, "state_root" |), + make_list [ + M.get_name (| globals, "state" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition process_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "env"; "tx" ] |) in + let _ := Constant.str " + Execute a transaction against the provided environment. + + This function processes the actions needed to execute a transaction. + It decrements the sender's account after calculating the gas fee and + refunds them the proper amount after execution. Calling contracts, + deploying code, and incrementing nonces are all examples of actions that + happen within this function or from a call made within this function. + + Accounts that are marked for deletion are processed and destroyed after + execution. + + Parameters + ---------- + env : + Environment for the Ethereum Virtual Machine. + tx : + Transaction to execute. + + Returns + ------- + gas_left : `ethereum.base_types.U256` + Remaining gas after execution. + logs : `Tuple[ethereum.blocks.Log, ...]` + Logs generated during execution. + " in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + M.call (| + M.get_name (| globals, "validate_transaction" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let sender := + M.get_field (| M.get_name (| globals, "env" |), "origin" |) in + let sender_account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "FeeMarketTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let max_gas_fee := + BinOp.mult (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let max_gas_fee := + BinOp.mult (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "sender_account" |), "nonce" |), M.get_field (| M.get_name (| globals, "tx" |), "nonce" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt_e (| M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), BinOp.add (| + M.get_name (| globals, "max_gas_fee" |), + M.get_field (| M.get_name (| globals, "tx" |), "value" |) + |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "sender_account" |), "code" |), M.call (| + M.get_name (| globals, "bytearray" |), + make_list [], + make_dict [] + |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let effective_gas_fee := + BinOp.mult (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "env" |), "gas_price" |) + |) in + let gas := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.call (| + M.get_name (| globals, "calculate_intrinsic_cost" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) in + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |) in + let sender_balance_after_gas_fee := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), + M.get_name (| globals, "effective_gas_fee" |) + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |); + M.get_name (| globals, "sender_balance_after_gas_fee" |) + ], + make_dict [] + |) in + let preaccessed_addresses := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let preaccessed_storage_keys := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + make_tuple [ M.get_name (| globals, "AccessListTransaction" |); M.get_name (| globals, "FeeMarketTransaction" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + For make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "keys" |) ] in M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "preaccessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "key" |) in M.get_name (| globals, "keys" |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "preaccessed_storage_keys" |), "add" |), + make_list [ + make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "key" |) ] + ], + make_dict [] + |) in + EndFor. + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let message := + M.call (| + M.get_name (| globals, "prepare_message" |), + make_list [ + M.get_name (| globals, "sender" |); + M.get_field (| M.get_name (| globals, "tx" |), "to" |); + M.get_field (| M.get_name (| globals, "tx" |), "value" |); + M.get_field (| M.get_name (| globals, "tx" |), "data" |); + M.get_name (| globals, "gas" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let output := + M.call (| + M.get_name (| globals, "process_message_call" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let gas_used := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "output" |), "gas_left" |) + |) in + let gas_refund := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + BinOp.floor_div (| + M.get_name (| globals, "gas_used" |), + Constant.int 5 + |); + M.get_field (| M.get_name (| globals, "output" |), "refund_counter" |) + ], + make_dict [] + |) in + let gas_refund_amount := + BinOp.mult (| + BinOp.add (| + M.get_field (| M.get_name (| globals, "output" |), "gas_left" |), + M.get_name (| globals, "gas_refund" |) + |), + M.get_field (| M.get_name (| globals, "env" |), "gas_price" |) + |) in + let priority_fee_per_gas := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "env" |), "gas_price" |), + M.get_field (| M.get_name (| globals, "env" |), "base_fee_per_gas" |) + |) in + let transaction_fee := + BinOp.mult (| + BinOp.sub (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "output" |), "gas_left" |) + |), + M.get_name (| globals, "gas_refund" |) + |), + M.get_name (| globals, "priority_fee_per_gas" |) + |) in + let total_gas_used := + BinOp.sub (| + M.get_name (| globals, "gas_used" |), + M.get_name (| globals, "gas_refund" |) + |) in + let sender_balance_after_refund := + BinOp.add (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |), "balance" |), + M.get_name (| globals, "gas_refund_amount" |) + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |); + M.get_name (| globals, "sender_balance_after_refund" |) + ], + make_dict [] + |) in + let coinbase_balance_after_mining_fee := + BinOp.add (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |), "balance" |), + M.get_name (| globals, "transaction_fee" |) + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| M.get_name (| globals, "coinbase_balance_after_mining_fee" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |); + M.get_name (| globals, "coinbase_balance_after_mining_fee" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "accounts_to_delete" |) do + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + EndFor. + For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "touched_accounts" |) do + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.return_ (| + make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |); M.get_field (| M.get_name (| globals, "output" |), "error" |) ] + |) in + M.pure Constant.None_)). + +Definition validate_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Verifies a transaction. + + The gas in a transaction gets used to pay for the intrinsic cost of + operations, therefore if there is insufficient gas then it would not + be possible to execute a transaction and it will be declared invalid. + + Additionally, the nonce of a transaction must not equal or exceed the + limit defined in `EIP-2681 `_. + In practice, defining the limit as ``2**64-1`` has no impact because + sending ``2**64-1`` transactions is improbable. It's not strictly + impossible though, ``2**64-1`` transactions is the entire capacity of the + Ethereum blockchain at 2022 gas limits for a little over 22 years. + + Parameters + ---------- + tx : + Transaction to validate. + + Returns + ------- + verified : `bool` + True if the transaction can be executed, or False otherwise. + " in + let _ := M.return_ (| + BoolOp.and (| + Compare.lt_e (| M.call (| + M.get_name (| globals, "calculate_intrinsic_cost" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |), M.get_field (| M.get_name (| globals, "tx" |), "gas" |) |), + ltac:(M.monadic ( + Compare.lt (| M.get_field (| M.get_name (| globals, "tx" |), "nonce" |), BinOp.sub (| + BinOp.pow (| + Constant.int 2, + Constant.int 64 + |), + Constant.int 1 + |) |) + )) + |) + |) in + M.pure Constant.None_)). + +Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Calculates the gas that is charged before execution is started. + + The intrinsic cost of the transaction is charged before execution has + begun. Functions/operations in the EVM cost money to execute so this + intrinsic cost is for the operations that need to be paid for as part of + the transaction. Data transfer, for example, is part of this intrinsic + cost. It costs ether to send data over the wire and that ether is + accounted for in the intrinsic cost calculated in this function. This + intrinsic cost must be calculated and paid for before execution in order + for all operations to be implemented. + + Parameters + ---------- + tx : + Transaction to compute the intrinsic cost of. + + Returns + ------- + verified : `ethereum.base_types.Uint` + The intrinsic cost of the transaction. + " in + let data_cost := + Constant.int 0 in + For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "byte" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + M.pure Constant.None_ + )) |) in + EndFor. + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_name (| globals, "tx" |), "to" |), M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let create_cost := + M.get_name (| globals, "TX_CREATE_COST" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let create_cost := + Constant.int 0 in + M.pure Constant.None_ + )) |) in + let access_list_cost := + Constant.int 0 in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + make_tuple [ M.get_name (| globals, "AccessListTransaction" |); M.get_name (| globals, "FeeMarketTransaction" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + For make_tuple [ M.get_name (| globals, "_address" |); M.get_name (| globals, "keys" |) ] in M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) do + let access_list_cost := BinOp.add + M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) + M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) in + let access_list_cost := BinOp.add + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "keys" |) + ], + make_dict [] + |), + M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) + |) + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "keys" |) + ], + make_dict [] + |), + M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) + |) in + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.add (| + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "TX_BASE_COST" |), + M.get_name (| globals, "data_cost" |) + |), + M.get_name (| globals, "create_cost" |) + |), + M.get_name (| globals, "access_list_cost" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition recover_sender : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "chain_id"; "tx" ] |) in + let _ := Constant.str " + Extracts the sender address from a transaction. + + The v, r, and s values are the three parts that make up the signature + of a transaction. In order to recover the sender of a transaction the two + components needed are the signature (``v``, ``r``, and ``s``) and the + signing hash of the transaction. The sender's public key can be obtained + with these two values and therefore the sender address can be retrieved. + + Parameters + ---------- + tx : + Transaction of interest. + chain_id : + ID of the executing chain. + + Returns + ------- + sender : `ethereum.fork_types.Address` + The address of the account that signed the transaction. + " in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "r" |); M.get_name (| globals, "s" |) ], + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "r" |); M.get_field (| M.get_name (| globals, "tx" |), "s" |) ] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.and (| + Compare.lt (| Constant.int 0, M.get_name (| globals, "r" |) |), + ltac:(M.monadic ( + Compare.lt (| M.get_name (| globals, "r" |), M.get_name (| globals, "SECP256K1N" |) |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.and (| + Compare.lt (| Constant.int 0, M.get_name (| globals, "s" |) |), + ltac:(M.monadic ( + Compare.lt_e (| M.get_name (| globals, "s" |), BinOp.floor_div (| + M.get_name (| globals, "SECP256K1N" |), + Constant.int 2 + |) |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "LegacyTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let v := + M.get_field (| M.get_name (| globals, "tx" |), "v" |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.eq (| M.get_name (| globals, "v" |), Constant.int 27 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "v" |), Constant.int 28 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + BinOp.sub (| + M.get_name (| globals, "v" |), + Constant.int 27 + |); + M.call (| + M.get_name (| globals, "signing_hash_pre155" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.or (| + Compare.eq (| M.get_name (| globals, "v" |), BinOp.add (| + Constant.int 35, + BinOp.mult (| + M.get_name (| globals, "chain_id" |), + Constant.int 2 + |) + |) |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "v" |), BinOp.add (| + Constant.int 36, + BinOp.mult (| + M.get_name (| globals, "chain_id" |), + Constant.int 2 + |) + |) |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + BinOp.sub (| + BinOp.sub (| + M.get_name (| globals, "v" |), + Constant.int 35 + |), + BinOp.mult (| + M.get_name (| globals, "chain_id" |), + Constant.int 2 + |) + |); + M.call (| + M.get_name (| globals, "signing_hash_155" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "chain_id" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "AccessListTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + M.get_field (| M.get_name (| globals, "tx" |), "y_parity" |); + M.call (| + M.get_name (| globals, "signing_hash_2930" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "FeeMarketTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + M.get_field (| M.get_name (| globals, "tx" |), "y_parity" |); + M.call (| + M.get_name (| globals, "signing_hash_1559" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_subscript (| M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), Constant.int 12:Constant.int 32 |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition signing_hash_pre155 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Compute the hash of a transaction used in a legacy (pre EIP 155) signature. + + Parameters + ---------- + tx : + Transaction of interest. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the transaction. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "nonce" |); M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |); M.get_field (| M.get_name (| globals, "tx" |), "gas" |); M.get_field (| M.get_name (| globals, "tx" |), "to" |); M.get_field (| M.get_name (| globals, "tx" |), "value" |); M.get_field (| M.get_name (| globals, "tx" |), "data" |) ] + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition signing_hash_155 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx"; "chain_id" ] |) in + let _ := Constant.str " + Compute the hash of a transaction used in a EIP 155 signature. + + Parameters + ---------- + tx : + Transaction of interest. + chain_id : + The id of the current chain. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the transaction. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "nonce" |); M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |); M.get_field (| M.get_name (| globals, "tx" |), "gas" |); M.get_field (| M.get_name (| globals, "tx" |), "to" |); M.get_field (| M.get_name (| globals, "tx" |), "value" |); M.get_field (| M.get_name (| globals, "tx" |), "data" |); M.get_name (| globals, "chain_id" |); M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) ] + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition signing_hash_2930 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Compute the hash of a transaction used in a EIP 2930 signature. + + Parameters + ---------- + tx : + Transaction of interest. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the transaction. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + BinOp.add (| + (* At constant: unsupported node type: Constant *), + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "chain_id" |); M.get_field (| M.get_name (| globals, "tx" |), "nonce" |); M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |); M.get_field (| M.get_name (| globals, "tx" |), "gas" |); M.get_field (| M.get_name (| globals, "tx" |), "to" |); M.get_field (| M.get_name (| globals, "tx" |), "value" |); M.get_field (| M.get_name (| globals, "tx" |), "data" |); M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) ] + ], + make_dict [] + |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition signing_hash_1559 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Compute the hash of a transaction used in a EIP 1559 signature. + + Parameters + ---------- + tx : + Transaction of interest. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the transaction. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + BinOp.add (| + (* At constant: unsupported node type: Constant *), + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "chain_id" |); M.get_field (| M.get_name (| globals, "tx" |), "nonce" |); M.get_field (| M.get_name (| globals, "tx" |), "max_priority_fee_per_gas" |); M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |); M.get_field (| M.get_name (| globals, "tx" |), "gas" |); M.get_field (| M.get_name (| globals, "tx" |), "to" |); M.get_field (| M.get_name (| globals, "tx" |), "value" |); M.get_field (| M.get_name (| globals, "tx" |), "data" |); M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) ] + ], + make_dict [] + |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition compute_header_hash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header" ] |) in + let _ := Constant.str " + Computes the hash of a block header. + + The header hash of a block is the canonical hash that is used to refer + to a specific block and completely distinguishes a block from another. + + ``keccak256`` is a function that produces a 256 bit hash of any input. + It also takes in any number of bytes as an input and produces a single + hash for them. A hash is a completely unique output for a single input. + So an input corresponds to one unique hash that can be used to identify + the input exactly. + + Prior to using the ``keccak256`` hash function, the header must be + encoded using the Recursive-Length Prefix. See :ref:`rlp`. + RLP encoding the header converts it into a space-efficient format that + allows for easy transfer of data between nodes. The purpose of RLP is to + encode arbitrarily nested arrays of binary data, and RLP is the primary + encoding method used to serialize objects in Ethereum's execution layer. + The only purpose of RLP is to encode structure; encoding specific data + types (e.g. strings, floats) is left up to higher-order protocols. + + Parameters + ---------- + header : + Header of interest. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the header. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "header" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition check_gas_limit : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "gas_limit"; "parent_gas_limit" ] |) in + let _ := Constant.str " + Validates the gas limit for a block. + + The bounds of the gas limit, ``max_adjustment_delta``, is set as the + quotient of the parent block's gas limit and the + ``GAS_LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is + passed through as a parameter is greater than or equal to the *sum* of + the parent's gas and the adjustment delta then the limit for gas is too + high and fails this function's check. Similarly, if the limit is less + than or equal to the *difference* of the parent's gas and the adjustment + delta *or* the predefined ``GAS_LIMIT_MINIMUM`` then this function's + check fails because the gas limit doesn't allow for a sufficient or + reasonable amount of gas to be used on a block. + + Parameters + ---------- + gas_limit : + Gas limit to validate. + + parent_gas_limit : + Gas limit of the parent block. + + Returns + ------- + check : `bool` + True if gas limit constraints are satisfied, False otherwise. + " in + let max_adjustment_delta := + BinOp.floor_div (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "gas_limit" |), BinOp.add (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| M.get_name (| globals, "gas_limit" |), BinOp.sub (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "gas_limit" |), M.get_name (| globals, "GAS_LIMIT_MINIMUM" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + Constant.bool true + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/fork_types.v b/CoqOfPython/ethereum/paris/fork_types.v new file mode 100644 index 0000000..d12953d --- /dev/null +++ b/CoqOfPython/ethereum/paris/fork_types.v @@ -0,0 +1,102 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Types +^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Types re-used throughout the specification, which are specific to Ethereum. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes20 : + IsGlobalAlias globals base_types.globals "Bytes20". +Axiom base_types_Bytes256 : + IsGlobalAlias globals base_types.globals "Bytes256". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require crypto.hash. +Axiom crypto_hash_Hash32 : + IsGlobalAlias globals crypto.hash.globals "Hash32". +Axiom crypto_hash_keccak256 : + IsGlobalAlias globals crypto.hash.globals "keccak256". + +Definition Address : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Bytes20" |) +)). + +Definition Root : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Hash32" |) +)). + +Definition Bloom : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Bytes256" |) +)). + +Definition Account : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition EMPTY_ACCOUNT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Account" |), + make_list [], + make_dict [] + |) +)). + +Definition encode_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "raw_account_data"; "storage_root" ] |) in + let _ := Constant.str " + Encode `Account` dataclass. + + Storage is not stored in the `Account` dataclass, so `Accounts` cannot be + encoded with providing a storage root. + " in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "raw_account_data" |), "nonce" |); M.get_field (| M.get_name (| globals, "raw_account_data" |), "balance" |); M.get_name (| globals, "storage_root" |); M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_field (| M.get_name (| globals, "raw_account_data" |), "code" |) + ], + make_dict [] + |) ] + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/state.v b/CoqOfPython/ethereum/paris/state.v new file mode 100644 index 0000000..833879c --- /dev/null +++ b/CoqOfPython/ethereum/paris/state.v @@ -0,0 +1,1157 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +State +^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The state contains all information that is preserved between transactions. + +It consists of a main account trie and storage tries for each contract. + +There is a distinction between an account that does not exist and +`EMPTY_ACCOUNT`. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_field : + IsGlobalAlias globals dataclasses.globals "field". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_modify : + IsGlobalAlias globals ethereum.base_types.globals "modify". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require fork_types. +Axiom fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". +Axiom fork_types_Account : + IsGlobalAlias globals fork_types.globals "Account". +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Require trie. +Axiom trie_EMPTY_TRIE_ROOT : + IsGlobalAlias globals trie.globals "EMPTY_TRIE_ROOT". +Axiom trie_Trie : + IsGlobalAlias globals trie.globals "Trie". +Axiom trie_copy_trie : + IsGlobalAlias globals trie.globals "copy_trie". +Axiom trie_root : + IsGlobalAlias globals trie.globals "root". +Axiom trie_trie_get : + IsGlobalAlias globals trie.globals "trie_get". +Axiom trie_trie_set : + IsGlobalAlias globals trie.globals "trie_set". + +Definition State : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition close_state : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Free resources held by the state. Used by optimized implementations to + release file descriptors. + " in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) |) in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |) in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |) |) in + M.pure Constant.None_)). + +Definition begin_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Start a state transaction. + + Transactions are entirely implicit and can be nested. It is not possible to + calculate the state root during a transaction. + + Parameters + ---------- + state : State + The state. + " in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), "append" |), + make_list [ + make_tuple [ M.call (| + M.get_name (| globals, "copy_trie" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) + ], + make_dict [] + |); {M.get_name (| globals, "k" |): M.call (| + M.get_name (| globals, "copy_trie" |), + make_list [ + M.get_name (| globals, "t" |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)} ] + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition commit_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Commit a state transaction. + + Parameters + ---------- + state : State + The state. + " in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), "pop" |), + make_list [], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "clear" |), + make_list [], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition rollback_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Rollback a state transaction, resetting the state to the point when the + corresponding `start_transaction()` call was made. + + Parameters + ---------- + state : State + The state. + " in + let _ := M.assign (| + make_tuple [ M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) ], + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), "pop" |), + make_list [], + make_dict [] + |) + |) in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "clear" |), + make_list [], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition get_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Get the `Account` object at an address. Returns `EMPTY_ACCOUNT` if there + is no account at the address. + + Use `get_account_optional()` if you care about the difference between a + non-existent account and `EMPTY_ACCOUNT`. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address to lookup. + + Returns + ------- + account : `Account` + Account at address. + " in + let account := + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "account" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "account" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "EMPTY_ACCOUNT" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition get_account_optional : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Get the `Account` object at an address. Returns `None` (rather than + `EMPTY_ACCOUNT`) if there is no account at the address. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address to lookup. + + Returns + ------- + account : `Account` + Account at address. + " in + let account := + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "account" |) + |) in + M.pure Constant.None_)). + +Definition set_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "account" ] |) in + let _ := Constant.str " + Set the `Account` object at an address. Setting to `None` deletes + the account (but not its storage, see `destroy_account()`). + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address to set. + account : `Account` + Account to set at address. + " in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "account" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition destroy_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Completely remove the account at `address` and all of its storage. + + This function is made available exclusively for the `SELFDESTRUCT` + opcode. It is expected that `SELFDESTRUCT` will be disabled in a future + hardfork and this function will be removed. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of account to destroy. + " in + let _ := M.call (| + M.get_name (| globals, "destroy_storage" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + Constant.None_ + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition destroy_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Completely remove the storage at `address`. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of account whose storage is to be deleted. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition mark_account_created : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Mark an account as having been created in the current transaction. + This information is used by `get_storage_original()` to handle an obscure + edgecase. + + The marker is not removed even if the account creation reverts. Since the + account cannot have had code prior to its creation and can't call + `get_storage_original()`, this is harmless. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of the account that has been created. + " in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition get_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "key" ] |) in + let _ := Constant.str " + Get a value at a storage key on an account. Returns `U256(0)` if the + storage key has not been set previously. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of the account. + key : `Bytes` + Key to lookup. + + Returns + ------- + value : `U256` + Value at the key. + " in + let trie := + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let _ := M.assert (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "U256" |) + ], + make_dict [] + |) |) in + let _ := M.return_ (| + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_)). + +Definition set_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "key"; "value" ] |) in + let _ := Constant.str " + Set a value at a storage key on an account. Setting to `U256(0)` deletes + the key. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of the account. + key : `Bytes` + Key to set. + value : `U256` + Value to set at the key. + " in + let _ := M.assert (| Compare.is_not (| M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), Constant.None_ |) |) in + let trie := + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let trie := + M.call (| + M.get_name (| globals, "Trie" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), + M.get_name (| globals, "trie" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "key" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), {} |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition storage_root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Calculate the storage root of an account. + + Parameters + ---------- + state: + The state + address : + Address of the account. + + Returns + ------- + root : `Root` + Storage root of the account. + " in + let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "EMPTY_TRIE_ROOT" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition state_root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Calculate the state root. + + Parameters + ---------- + state: + The current state. + + Returns + ------- + root : `Root` + The state root. + " in + let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition account_exists : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account exists in the state trie + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + account_exists : `bool` + True if account exists in the state trie, False otherwise + " in + let _ := M.return_ (| + Compare.is_not (| M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), Constant.None_ |) + |) in + M.pure Constant.None_)). + +Definition account_has_code_or_nonce : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account has non zero nonce or non empty code + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + has_code_or_nonce : `bool` + True if if an account has non zero nonce or non empty code, + False otherwise. + " in + let account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + BoolOp.or (| + Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |) + )) + |) + |) in + M.pure Constant.None_)). + +Definition is_account_empty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account has zero nonce, empty code and zero balance. + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + is_empty : `bool` + True if if an account has zero nonce, empty code and zero balance, + False otherwise. + " in + let account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + ltac:(M.monadic ( + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + )) + |) + )) + |) + |) in + M.pure Constant.None_)). + +Definition account_exists_and_is_empty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account exists and has zero nonce, empty code and zero + balance. + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + exists_and_is_empty : `bool` + True if an account exists and has zero nonce, empty code and zero + balance, False otherwise. + " in + let account := + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + BoolOp.and (| + Compare.is_not (| M.get_name (| globals, "account" |), Constant.None_ |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + ltac:(M.monadic ( + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + )) + |) + )) + |) + )) + |) + |) in + M.pure Constant.None_)). + +Definition is_account_alive : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Check whether is an account is both in the state and non empty. + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + is_alive : `bool` + True if the account is alive. + " in + let account := + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "account" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + UnOp.not (| BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + ltac:(M.monadic ( + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + )) + |) + )) + |) |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition modify_state : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "f" ] |) in + let _ := Constant.str " + Modify an `Account` in the `State`. + " in + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.call (| + M.get_name (| globals, "modify" |), + make_list [ + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |); + M.get_name (| globals, "f" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition move_ether : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "sender_address"; "recipient_address"; "amount" ] |) in + let _ := Constant.str " + Move funds between accounts. + " in +(* At stmt: unsupported node type: FunctionDef *) +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "sender_address" |); + M.get_name (| globals, "reduce_sender_balance" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "recipient_address" |); + M.get_name (| globals, "increase_recipient_balance" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition set_account_balance : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "amount" ] |) in + let _ := Constant.str " + Sets the balance of an account. + + Parameters + ---------- + state: + The current state. + + address: + Address of the account whose nonce needs to be incremented. + + amount: + The amount that needs to set in balance. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "set_balance" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition touch_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Initializes an account to state. + + Parameters + ---------- + state: + The current state. + + address: + The address of the account that need to initialised. + " in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "account_exists" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "EMPTY_ACCOUNT" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition increment_nonce : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Increments the nonce of an account. + + Parameters + ---------- + state: + The current state. + + address: + Address of the account whose nonce needs to be incremented. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "increase_nonce" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition set_code : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "code" ] |) in + let _ := Constant.str " + Sets Account code. + + Parameters + ---------- + state: + The current state. + + address: + Address of the account whose code needs to be update. + + code: + The bytecode that needs to be set. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "write_code" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition get_storage_original : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "key" ] |) in + let _ := Constant.str " + Get the original value in a storage slot i.e. the value before the current + transaction began. This function reads the value from the snapshots taken + before executing the transaction. + + Parameters + ---------- + state: + The current state. + address: + Address of the account to read the value from. + key: + Key of the storage slot. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "_" |); M.get_name (| globals, "original_trie" |) ], + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), Constant.int 0 |) + |) in + let original_account_trie := + M.call (| + M.get_field (| M.get_name (| globals, "original_trie" |), "get" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "original_account_trie" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let original_value := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let original_value := + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_name (| globals, "original_account_trie" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.assert (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "original_value" |); + M.get_name (| globals, "U256" |) + ], + make_dict [] + |) |) in + let _ := M.return_ (| + M.get_name (| globals, "original_value" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/transactions.v b/CoqOfPython/ethereum/paris/transactions.v new file mode 100644 index 0000000..56996d9 --- /dev/null +++ b/CoqOfPython/ethereum/paris/transactions.v @@ -0,0 +1,274 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Transactions are atomic units of work created externally to Ethereum and +submitted to be executed. If Ethereum is viewed as a state machine, +transactions are the events that move between states. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U64 : + IsGlobalAlias globals base_types.globals "U64". +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes0 : + IsGlobalAlias globals base_types.globals "Bytes0". +Axiom base_types_Bytes32 : + IsGlobalAlias globals base_types.globals "Bytes32". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require exceptions. +Axiom exceptions_InvalidBlock : + IsGlobalAlias globals exceptions.globals "InvalidBlock". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( + Constant.int 21000 +)). + +Definition TX_DATA_COST_PER_NON_ZERO : Value.t := M.run ltac:(M.monadic ( + Constant.int 16 +)). + +Definition TX_DATA_COST_PER_ZERO : Value.t := M.run ltac:(M.monadic ( + Constant.int 4 +)). + +Definition TX_CREATE_COST : Value.t := M.run ltac:(M.monadic ( + Constant.int 32000 +)). + +Definition TX_ACCESS_LIST_ADDRESS_COST : Value.t := M.run ltac:(M.monadic ( + Constant.int 2400 +)). + +Definition TX_ACCESS_LIST_STORAGE_KEY_COST : Value.t := M.run ltac:(M.monadic ( + Constant.int 1900 +)). + +Definition LegacyTransaction : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition AccessListTransaction : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition FeeMarketTransaction : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Transaction : Value.t := M.run ltac:(M.monadic ( + M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "AccessListTransaction" |); M.get_name (| globals, "FeeMarketTransaction" |) ] |) +)). + +Definition encode_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Encode a transaction. Needed because non-legacy transactions aren't RLP. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "LegacyTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "tx" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "AccessListTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + (* At constant: unsupported node type: Constant *), + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "FeeMarketTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + (* At constant: unsupported node type: Constant *), + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "Exception" |), + make_list [ + (* At expr: unsupported node type: JoinedStr *) + ], + make_dict [] + |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition decode_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Decode a transaction. Needed because non-legacy transactions aren't RLP. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), Constant.int 1 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), + make_list [ + M.get_name (| globals, "AccessListTransaction" |); + M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 1:(* At expr: unsupported node type: NoneType *) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), Constant.int 2 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), + make_list [ + M.get_name (| globals, "FeeMarketTransaction" |); + M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 1:(* At expr: unsupported node type: NoneType *) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidBlock" |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "tx" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/trie.v b/CoqOfPython/ethereum/paris/trie.v new file mode 100644 index 0000000..3dbf56c --- /dev/null +++ b/CoqOfPython/ethereum/paris/trie.v @@ -0,0 +1,1357 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +State Trie +^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The state trie is the structure responsible for storing +`.fork_types.Account` objects. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_field : + IsGlobalAlias globals dataclasses.globals "field". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". +Axiom typing_Generic : + IsGlobalAlias globals typing.globals "Generic". +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Mapping : + IsGlobalAlias globals typing.globals "Mapping". +Axiom typing_MutableMapping : + IsGlobalAlias globals typing.globals "MutableMapping". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Sequence : + IsGlobalAlias globals typing.globals "Sequence". +Axiom typing_TypeVar : + IsGlobalAlias globals typing.globals "TypeVar". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". +Axiom typing_cast : + IsGlobalAlias globals typing.globals "cast". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.gray_glacier. +Axiom ethereum_gray_glacier_trie : + IsGlobalAlias globals ethereum.gray_glacier.globals "trie". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require ethereum.utils.hexadecimal. +Axiom ethereum_utils_hexadecimal_hex_to_bytes : + IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require blocks. +Axiom blocks_Receipt : + IsGlobalAlias globals blocks.globals "Receipt". + +Require fork_types. +Axiom fork_types_Account : + IsGlobalAlias globals fork_types.globals "Account". +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". +Axiom fork_types_encode_account : + IsGlobalAlias globals fork_types.globals "encode_account". + +Require transactions. +Axiom transactions_LegacyTransaction : + IsGlobalAlias globals transactions.globals "LegacyTransaction". + +Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Root" |), + make_list [ + M.call (| + M.get_name (| globals, "hex_to_bytes" |), + make_list [ + Constant.str "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" + ], + make_dict [] + |) + ], + make_dict [] + |) +)). + +Definition Node : Value.t := M.run ltac:(M.monadic ( + M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Bytes" |); M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |); Constant.None_ ] |) +)). + +Definition K : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "TypeVar" |), + make_list [ + Constant.str "K" + ], + make_dict [] + |) +)). + +Definition V : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "TypeVar" |), + make_list [ + Constant.str "V"; + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Account" |) |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Bytes" |) |); + M.get_name (| globals, "Bytes" |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Bytes" |) ] |) |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Bytes" |) ] |) |); + M.get_name (| globals, "Uint" |); + M.get_name (| globals, "U256" |) + ], + make_dict [] + |) +)). + +Definition LeafNode : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition ExtensionNode : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition BranchNode : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition InternalNode : Value.t := M.run ltac:(M.monadic ( + M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LeafNode" |); M.get_name (| globals, "ExtensionNode" |); M.get_name (| globals, "BranchNode" |) ] |) +)). + +Definition encode_internal_node : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "node" ] |) in + let _ := Constant.str " + Encodes a Merkle Trie node into its RLP form. The RLP will then be + serialized into a `Bytes` and hashed unless it is less that 32 bytes + when serialized. + + This function also accepts `None`, representing the absence of a node, + which is encoded to `b""""""`. + + Parameters + ---------- + node : Optional[InternalNode] + The node to encode. + + Returns + ------- + encoded : `rlp.RLP` + The node encoded as RLP. + " in +(* At stmt: unsupported node type: AnnAssign *) + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "node" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let unencoded := + (* At constant: unsupported node type: Constant *) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "LeafNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "rest_of_key" |); + Constant.bool true + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "ExtensionNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "key_segment" |); + Constant.bool false + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "BranchNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + BinOp.add (| + M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "value" |) + ] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "AssertionError" |), + make_list [ + (* At expr: unsupported node type: JoinedStr *) + ], + make_dict [] + |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let encoded := + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "unencoded" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded" |) + ], + make_dict [] + |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "unencoded" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "encoded" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition encode_node : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "node"; "storage_root" ] |) in + let _ := Constant.str " + Encode a Node for storage in the Merkle Trie. + + Currently mostly an unimplemented stub. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "storage_root" |), Constant.None_ |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "encode_account" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "storage_root" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "U256" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "cast" |), + make_list [ + M.get_field (| M.get_name (| globals, "rlp" |), "RLP" |); + M.get_name (| globals, "node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "node" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "previous_trie" |), "encode_node" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "storage_root" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition Trie : Value.t := + builtins.make_klass + [(* At base: unsupported node type: Subscript *)] + [ + + ] + [ + + ]. + +Definition copy_trie : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie" ] |) in + let _ := Constant.str " + Create a copy of `trie`. Since only frozen objects may be stored in tries, + the contents are reused. + + Parameters + ---------- + trie: `Trie` + Trie to copy. + + Returns + ------- + new_trie : `Trie[K, V]` + A copy of the trie. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Trie" |), + make_list [ + M.get_field (| M.get_name (| globals, "trie" |), "secured" |); + M.get_field (| M.get_name (| globals, "trie" |), "default" |); + M.call (| + M.get_field (| M.get_name (| globals, "copy" |), "copy" |), + make_list [ + M.get_field (| M.get_name (| globals, "trie" |), "_data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition trie_set : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "key"; "value" ] |) in + let _ := Constant.str " + Stores an item in a Merkle Trie. + + This method deletes the key if `value == trie.default`, because the Merkle + Trie represents the default value by omitting it from the trie. + + Parameters + ---------- + trie: `Trie` + Trie to store in. + key : `Bytes` + Key to lookup. + value : `V` + Node to insert at `key`. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "value" |), M.get_field (| M.get_name (| globals, "trie" |), "default" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "key" |), M.get_field (| M.get_name (| globals, "trie" |), "_data" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition trie_get : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "key" ] |) in + let _ := Constant.str " + Gets an item from the Merkle Trie. + + This method returns `trie.default` if the key is missing. + + Parameters + ---------- + trie: + Trie to lookup in. + key : + Key to lookup. + + Returns + ------- + node : `V` + Node at `key` in the trie. + " in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "get" |), + make_list [ + M.get_name (| globals, "key" |); + M.get_field (| M.get_name (| globals, "trie" |), "default" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition common_prefix_length : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "a"; "b" ] |) in + let _ := Constant.str " + Find the longest common prefix of two sequences. + " in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + ], + make_dict [] + |) do + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| M.get_name (| globals, "i" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition nibble_list_to_compact : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "x"; "is_leaf" ] |) in + let _ := Constant.str " + Compresses nibble-list into a standard byte array with a flag. + + A nibble-list is a list of byte values no greater than `15`. The flag is + encoded in high nibble of the highest byte. The flag nibble can be broken + down into two two-bit flags. + + Highest nibble:: + + +---+---+----------+--------+ + | _ | _ | is_leaf | parity | + +---+---+----------+--------+ + 3 2 1 0 + + + The lowest bit of the nibble encodes the parity of the length of the + remaining nibbles -- `0` when even and `1` when odd. The second lowest bit + is used to distinguish leaf and extension nodes. The other two bits are not + used. + + Parameters + ---------- + x : + Array of nibbles. + is_leaf : + True if this is part of a leaf node, or false if it is an extension + node. + + Returns + ------- + compressed : `bytearray` + Compact byte array. + " in + let compact := + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + Constant.int 2 + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.mult (| + Constant.int 16, + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "is_leaf" |) + |) + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + BinOp.add (| + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "is_leaf" |) + |), + Constant.int 1 + |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), Constant.int 0 |) + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 1; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + M.get_name (| globals, "compact" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition bytes_to_nibble_list : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "bytes_" ] |) in + let _ := Constant.str " + Converts a `Bytes` into to a sequence of nibbles (bytes with value < 16). + + Parameters + ---------- + bytes_: + The `Bytes` to convert. + + Returns + ------- + nibble_list : `Bytes` + The `Bytes` in nibble-list format. + " in + let nibble_list := + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [ + BinOp.mult (| + Constant.int 2, + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "bytes_" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + For make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ] in M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "bytes_" |) + ], + make_dict [] + |) do + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |) |), + BinOp.r_shift (| + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 240 + |), + Constant.int 4 + |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |), + Constant.int 1 + |) |), + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 15 + |) + |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + M.get_name (| globals, "nibble_list" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition _prepare_trie : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "get_storage_root" ] |) in + let _ := Constant.str " + Prepares the trie for root calculation. Removes values that are empty, + hashes the keys (if `secured == True`) and encodes all the nodes. + + Parameters + ---------- + trie : + The `Trie` to prepare. + get_storage_root : + Function to get the storage root of an account. Needed to encode + `Account` objects. + + Returns + ------- + out : `Mapping[ethereum.base_types.Bytes, Node]` + Object with keys mapped to nibble-byte form. + " in +(* At stmt: unsupported node type: AnnAssign *) + For make_tuple [ M.get_name (| globals, "preimage" |); M.get_name (| globals, "value" |) ] in M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "items" |), + make_list [], + make_dict [] + |) do + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in + let address := + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |); + M.call (| + M.get_name (| globals, "get_storage_root" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_eq (| M.get_name (| globals, "encoded_value" |), (* At constant: unsupported node type: Constant *) |); + M.get_name (| globals, "AssertionError" |) + ], + make_dict [] + |) in +(* At stmt: unsupported node type: AnnAssign *) + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "trie" |), "secured" |), + (* then *) + ltac:(M.monadic ( + let key := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let key := + M.get_name (| globals, "preimage" |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "mapped" |), M.call (| + M.get_name (| globals, "bytes_to_nibble_list" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |) |), + M.get_name (| globals, "encoded_value" |) + |) in + EndFor. + let _ := M.return_ (| + M.get_name (| globals, "mapped" |) + |) in + M.pure Constant.None_)). + +Definition root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "get_storage_root" ] |) in + let _ := Constant.str " + Computes the root of a modified merkle patricia trie (MPT). + + Parameters + ---------- + trie : + `Trie` to get the root of. + get_storage_root : + Function to get the storage root of an account. Needed to encode + `Account` objects. + + + Returns + ------- + root : `.fork_types.Root` + MPT root of the underlying key-value pairs. + " in + let obj := + M.call (| + M.get_name (| globals, "_prepare_trie" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "get_storage_root" |) + ], + make_dict [] + |) in + let root_node := + M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_name (| globals, "obj" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assert (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "root_node" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Root" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition patricialize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "obj"; "level" ] |) in + let _ := Constant.str " + Structural composition function. + + Used to recursively patricialize and merkleize a dictionary. Includes + memoization of the tree structure and hashes. + + Parameters + ---------- + obj : + Underlying trie key-value pairs, with keys in nibble-list format. + level : + Current trie level. + + Returns + ------- + node : `ethereum.base_types.Bytes` + Root node of `obj`. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let arbitrary_key := + M.call (| + M.get_name (| globals, "next" |), + make_list [ + M.call (| + M.get_name (| globals, "iter" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), Constant.int 1 |), + (* then *) + ltac:(M.monadic ( + let leaf := + M.call (| + M.get_name (| globals, "LeafNode" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |); + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "leaf" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let substring := + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) in + let prefix_length := + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "substring" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do + let prefix_length := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_name (| globals, "prefix_length" |); + M.call (| + M.get_name (| globals, "common_prefix_length" |), + make_list [ + M.get_name (| globals, "substring" |); + M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let prefix := + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ExtensionNode" |), + make_list [ + M.get_name (| globals, "prefix" |); + M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_name (| globals, "obj" |); + BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in +(* At stmt: unsupported node type: AnnAssign *) + For M.get_name (| globals, "_" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 16 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "branches" |), "append" |), + make_list [ + {} + ], + make_dict [] + |) in + EndFor. + let value := + (* At constant: unsupported node type: Constant *) in + For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |), M.get_name (| globals, "level" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "AssertionError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) + |) in + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "BranchNode" |), + make_list [ + [M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "branches" |), M.get_name (| globals, "k" |) |); + BinOp.add (| + M.get_name (| globals, "level" |), + Constant.int 1 + |) + ], + make_dict [] + |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)]; + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/utils/__init__.v b/CoqOfPython/ethereum/paris/utils/__init__.v new file mode 100644 index 0000000..1baedea --- /dev/null +++ b/CoqOfPython/ethereum/paris/utils/__init__.v @@ -0,0 +1,8 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Utility functions unique to this particular fork. +". diff --git a/CoqOfPython/ethereum/paris/utils/address.v b/CoqOfPython/ethereum/paris/utils/address.v new file mode 100644 index 0000000..cea4829 --- /dev/null +++ b/CoqOfPython/ethereum/paris/utils/address.v @@ -0,0 +1,204 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Hardfork Utility Functions For Addresses +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Address specific functions used in this paris version of +specification. +". + +Require typing. +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_left_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Definition to_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "data" ] |) in + let _ := Constant.str " + Convert a Uint or U256 value to a valid address (20 bytes). + + Parameters + ---------- + data : + The string to be converted to bytes. + + Returns + ------- + address : `Address` + The obtained address. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_subscript (| M.call (| + M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition compute_contract_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "address"; "nonce" ] |) in + let _ := Constant.str " + Computes address of the new account that needs to be created. + + Parameters + ---------- + address : + The address of the account that wants to create the new account. + nonce : + The transaction count of the account that wants to create the new + account. + + Returns + ------- + address: `Address` + The computed address of the new account. + " in + let computed_address := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_list [ + M.get_name (| globals, "address" |); + M.get_name (| globals, "nonce" |) + ] + ], + make_dict [] + |) + ], + make_dict [] + |) in + let canonical_address := + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + let padded_address := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "canonical_address" |); + Constant.int 20 + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "padded_address" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition compute_create2_contract_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "address"; "salt"; "call_data" ] |) in + let _ := Constant.str " + Computes address of the new account that needs to be created, which is + based on the sender address, salt and the call data as well. + + Parameters + ---------- + address : + The address of the account that wants to create the new account. + salt : + Address generation salt. + call_data : + The code of the new account which is to be created. + + Returns + ------- + address: `ethereum.paris.fork_types.Address` + The computed address of the new account. + " in + let preimage := + BinOp.add (| + BinOp.add (| + BinOp.add (| + (* At constant: unsupported node type: Constant *), + M.get_name (| globals, "address" |) + |), + M.get_name (| globals, "salt" |) + |), + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "call_data" |) + ], + make_dict [] + |) + |) in + let computed_address := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + let canonical_address := + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + let padded_address := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "canonical_address" |); + Constant.int 20 + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "padded_address" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/utils/hexadecimal.v b/CoqOfPython/ethereum/paris/utils/hexadecimal.v new file mode 100644 index 0000000..b1bc56b --- /dev/null +++ b/CoqOfPython/ethereum/paris/utils/hexadecimal.v @@ -0,0 +1,155 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Utility Functions For Hexadecimal Strings +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Hexadecimal utility functions used in this specification, specific to +Paris types. +". + +Require ethereum.utils.hexadecimal. +Axiom ethereum_utils_hexadecimal_remove_hex_prefix : + IsGlobalAlias globals ethereum.utils.hexadecimal.globals "remove_hex_prefix". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Definition hex_to_root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to trie root. + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to trie root. + + Returns + ------- + root : `Root` + Trie root obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Root" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition hex_to_bloom : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to bloom. + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to bloom. + + Returns + ------- + bloom : `Bloom` + Bloom obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bloom" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition hex_to_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to Address (20 bytes). + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to Address. + + Returns + ------- + address : `Address` + The address obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |), "rjust" |), + make_list [ + Constant.int 40; + Constant.str "0" + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/utils/message.v b/CoqOfPython/ethereum/paris/utils/message.v new file mode 100644 index 0000000..416f071 --- /dev/null +++ b/CoqOfPython/ethereum/paris/utils/message.v @@ -0,0 +1,254 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Hardfork Utility Functions For The Message Data-structure +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Message specific functions used in this paris version of +specification. +". + +Require typing. +Axiom typing_FrozenSet : + IsGlobalAlias globals typing.globals "FrozenSet". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". + +Require vm. +Axiom vm_Environment : + IsGlobalAlias globals vm.globals "Environment". +Axiom vm_Message : + IsGlobalAlias globals vm.globals "Message". + +Require vm.precompiled_contracts.mapping. +Axiom vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : + IsGlobalAlias globals vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". + +Require address. +Axiom address_compute_contract_address : + IsGlobalAlias globals address.globals "compute_contract_address". + +Definition prepare_message : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "caller"; "target"; "value"; "data"; "gas"; "env"; "code_address"; "should_transfer_value"; "is_static"; "preaccessed_addresses"; "preaccessed_storage_keys" ] |) in + let _ := Constant.str " + Execute a transaction against the provided environment. + + Parameters + ---------- + caller : + Address which initiated the transaction + target : + Address whose code will be executed + value : + Value to be transferred. + data : + Array of bytes provided to the code in `target`. + gas : + Gas provided for the code in `target`. + env : + Environment for the Ethereum Virtual Machine. + code_address : + This is usually same as the `target` address except when an alternative + accounts code needs to be executed. + eg. `CALLCODE` calling a precompile. + should_transfer_value : + if True ETH should be transferred while executing a message call. + is_static: + if True then it prevents all state-changing operations from being + executed. + preaccessed_addresses: + Addresses that should be marked as accessed prior to the message call + preaccessed_storage_keys: + Storage keys that should be marked as accessed prior to the message + call + + Returns + ------- + message: `ethereum.paris.vm.Message` + Items containing contract creation or message call specific data. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Bytes0" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.call (| + M.get_name (| globals, "compute_contract_address" |), + make_list [ + M.get_name (| globals, "caller" |); + BinOp.sub (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "caller" |) + ], + make_dict [] + |), "nonce" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let msg_data := + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |) in + let code := + M.get_name (| globals, "data" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.get_name (| globals, "target" |) in + let msg_data := + M.get_name (| globals, "data" |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "target" |) + ], + make_dict [] + |), "code" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "code_address" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let code_address := + M.get_name (| globals, "target" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "AssertionError" |), + make_list [ + Constant.str "Target must be address or empty bytes" + ], + make_dict [] + |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let accessed_addresses := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "current_target" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "caller" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "accessed_addresses" |), "update" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "PRE_COMPILED_CONTRACTS" |), "keys" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "accessed_addresses" |), "update" |), + make_list [ + M.get_name (| globals, "preaccessed_addresses" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/vm/__init__.v b/CoqOfPython/ethereum/paris/vm/__init__.v new file mode 100644 index 0000000..2ff63cd --- /dev/null +++ b/CoqOfPython/ethereum/paris/vm/__init__.v @@ -0,0 +1,262 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The abstract computer which runs the code stored in an +`.fork_types.Account`. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U64 : + IsGlobalAlias globals ethereum.base_types.globals "U64". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_State : + IsGlobalAlias globals state.globals "State". +Axiom state_account_exists_and_is_empty : + IsGlobalAlias globals state.globals "account_exists_and_is_empty". + +Require precompiled_contracts. +Axiom precompiled_contracts_RIPEMD160_ADDRESS : + IsGlobalAlias globals precompiled_contracts.globals "RIPEMD160_ADDRESS". + +Definition __all__ : Value.t := M.run ltac:(M.monadic ( + make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] +)). + +Definition Environment : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Message : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Evm : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition incorporate_child_on_success : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "child_evm" ] |) in + let _ := Constant.str " + Incorporate the state of a successful `child_evm` into the parent `evm`. + + Parameters + ---------- + evm : + The parent `EVM`. + child_evm : + The child evm to incorporate. + " in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "gas_left" |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "logs" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "logs" |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "refund_counter" |) + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "accounts_to_delete" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "accessed_addresses" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "accessed_storage_keys" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition incorporate_child_on_error : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "child_evm" ] |) in + let _ := Constant.str " + Incorporate the state of an unsuccessful `child_evm` into the parent `evm`. + + Parameters + ---------- + evm : + The parent `EVM`. + child_evm : + The child evm to incorporate. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "RIPEMD160_ADDRESS" |), M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |), M.get_name (| globals, "RIPEMD160_ADDRESS" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "gas_left" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/vm/exceptions.v b/CoqOfPython/ethereum/paris/vm/exceptions.v new file mode 100644 index 0000000..1f4363d --- /dev/null +++ b/CoqOfPython/ethereum/paris/vm/exceptions.v @@ -0,0 +1,172 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Exceptions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Exceptions which cause the EVM to halt exceptionally. +". + +Require ethereum.exceptions. +Axiom ethereum_exceptions_EthereumException : + IsGlobalAlias globals ethereum.exceptions.globals "EthereumException". + +Definition ExceptionalHalt : Value.t := + builtins.make_klass + [(globals, "EthereumException")] + [ + + ] + [ + + ]. + +Definition Revert : Value.t := + builtins.make_klass + [(globals, "EthereumException")] + [ + + ] + [ + + ]. + +Definition StackUnderflowError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition StackOverflowError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition OutOfGasError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition InvalidOpcode : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + ( + "__init__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "code" ] |) in + let _ := M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "super" |), + make_list [], + make_dict [] + |), "__init__" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "self" |), "code" |), + M.get_name (| globals, "code" |) + |) in + M.pure Constant.None_)) + ) + ]. + +Definition InvalidJumpDestError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition StackDepthLimitError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition WriteInStaticContext : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition OutOfBoundsRead : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition InvalidParameter : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition InvalidContractPrefix : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition AddressCollision : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. diff --git a/CoqOfPython/ethereum/paris/vm/instructions/__init__.v b/CoqOfPython/ethereum/paris/vm/instructions/__init__.v new file mode 100644 index 0000000..e5bebd7 --- /dev/null +++ b/CoqOfPython/ethereum/paris/vm/instructions/__init__.v @@ -0,0 +1,87 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +EVM Instruction Encoding (Opcodes) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Machine readable representations of EVM instructions, and a mapping to their +implementations. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". + +Require __init__. +Axiom __init___arithmetic : + IsGlobalAlias globals __init__.globals "arithmetic". + +Require __init__. +Axiom __init___bitwise : + IsGlobalAlias globals __init__.globals "bitwise". + +Require __init__. +Axiom __init___block : + IsGlobalAlias globals __init__.globals "block". + +Require __init__. +Axiom __init___comparison : + IsGlobalAlias globals __init__.globals "comparison". + +Require __init__. +Axiom __init___control_flow : + IsGlobalAlias globals __init__.globals "control_flow". + +Require __init__. +Axiom __init___environment : + IsGlobalAlias globals __init__.globals "environment". + +Require __init__. +Axiom __init___keccak : + IsGlobalAlias globals __init__.globals "keccak". + +Require __init__. +Axiom __init___log : + IsGlobalAlias globals __init__.globals "log". + +Require __init__. +Axiom __init___memory : + IsGlobalAlias globals __init__.globals "memory". + +Require __init__. +Axiom __init___stack : + IsGlobalAlias globals __init__.globals "stack". + +Require __init__. +Axiom __init___storage : + IsGlobalAlias globals __init__.globals "storage". + +Require __init__. +Axiom __init___system : + IsGlobalAlias globals __init__.globals "system". + +Definition Ops : Value.t := + builtins.make_klass + [(* At base: unsupported node type: Attribute *)] + [ + + ] + [ + + ]. + +(* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/paris/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/paris/vm/instructions/arithmetic.v index 9020f6d..a8b5c61 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/arithmetic.v @@ -1,7 +1,9 @@ Require Import CoqOfPython.CoqOfPython. +Inductive globals : Set :=. + Definition expr_1 : Value.t := - (Value.String " + Constant.str " Ethereum Virtual Machine (EVM) Arithmetic Instructions ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -13,36 +15,50 @@ Introduction ------------ Implementations of the EVM Arithmetic instructions. -"). +". Require ethereum.base_types. -Definition U255_CEIL_VALUE := U255_CEIL_VALUE. -Definition U256 := U256. -Definition U256_CEIL_VALUE := U256_CEIL_VALUE. -Definition Uint := Uint. +Axiom ethereum_base_types_U255_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U255_CEIL_VALUE". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_U256_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". Require ethereum.utils.numeric. -Definition get_sign := get_sign. +Axiom ethereum_utils_numeric_get_sign : + IsGlobalAlias globals ethereum.utils.numeric.globals "get_sign". Require __init__. -Definition Evm := Evm. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". Require gas. -Definition GAS_EXPONENTIATION := GAS_EXPONENTIATION. -Definition GAS_EXPONENTIATION_PER_BYTE := GAS_EXPONENTIATION_PER_BYTE. -Definition GAS_LOW := GAS_LOW. -Definition GAS_MID := GAS_MID. -Definition GAS_VERY_LOW := GAS_VERY_LOW. -Definition charge_gas := charge_gas. +Axiom gas_GAS_EXPONENTIATION : + IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION". +Axiom gas_GAS_EXPONENTIATION_PER_BYTE : + IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION_PER_BYTE". +Axiom gas_GAS_LOW : + IsGlobalAlias globals gas.globals "GAS_LOW". +Axiom gas_GAS_MID : + IsGlobalAlias globals gas.globals "GAS_MID". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". Require stack. -Definition pop := pop. -Definition push := push. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". -Definition add (args : list Value.t) : M := - match args with - | [evm] => ltac:(M.monadic ( - let _ := (Value.String " +Definition add : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " Adds the top two elements of the stack together, and pushes the result back on the stack. @@ -51,24 +67,58 @@ Definition add (args : list Value.t) : M := evm : The current EVM frame. - ") in - let x := (M.call (| pop, [evm.stack] |)) in - let y := (M.call (| pop, [evm.stack] |)) in - let _ := (M.call (| charge_gas, [evm; GAS_VERY_LOW] |)) in - let result := (M.call (| x.wrapping_add, [y] |)) in - let _ := (M.call (| push, [evm.stack; result] |)) in - let _ := M.assign_op (| - BinOp.add, - evm.pc, - (Value.Integer 1) - |) in)) - | _ => M.impossible - end. - -Definition sub (args : list Value.t) : M := - match args with - | [evm] => ltac:(M.monadic ( - let _ := (Value.String " + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "x" |), "wrapping_add" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition sub : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " Subtracts the top two elements of the stack, and pushes the result back on the stack. @@ -77,24 +127,58 @@ Definition sub (args : list Value.t) : M := evm : The current EVM frame. - ") in - let x := (M.call (| pop, [evm.stack] |)) in - let y := (M.call (| pop, [evm.stack] |)) in - let _ := (M.call (| charge_gas, [evm; GAS_VERY_LOW] |)) in - let result := (M.call (| x.wrapping_sub, [y] |)) in - let _ := (M.call (| push, [evm.stack; result] |)) in - let _ := M.assign_op (| - BinOp.add, - evm.pc, - (Value.Integer 1) - |) in)) - | _ => M.impossible - end. - -Definition mul (args : list Value.t) : M := - match args with - | [evm] => ltac:(M.monadic ( - let _ := (Value.String " + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "x" |), "wrapping_sub" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mul : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " Multiply the top two elements of the stack, and pushes the result back on the stack. @@ -103,24 +187,58 @@ Definition mul (args : list Value.t) : M := evm : The current EVM frame. - ") in - let x := (M.call (| pop, [evm.stack] |)) in - let y := (M.call (| pop, [evm.stack] |)) in - let _ := (M.call (| charge_gas, [evm; GAS_LOW] |)) in - let result := (M.call (| x.wrapping_mul, [y] |)) in - let _ := (M.call (| push, [evm.stack; result] |)) in - let _ := M.assign_op (| - BinOp.add, - evm.pc, - (Value.Integer 1) - |) in)) - | _ => M.impossible - end. - -Definition div (args : list Value.t) : M := - match args with - | [evm] => ltac:(M.monadic ( - let _ := (Value.String " + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "x" |), "wrapping_mul" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition div : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " Integer division of the top two elements of the stack. Pushes the result back on the stack. @@ -129,28 +247,74 @@ Definition div (args : list Value.t) : M := evm : The current EVM frame. - ") in - let dividend := (M.call (| pop, [evm.stack] |)) in - let divisor := (M.call (| pop, [evm.stack] |)) in - let _ := (M.call (| charge_gas, [evm; GAS_LOW] |)) in - let _ := - if M.is_true (Compare.eq (| divisor, (Value.Integer 0) |)) then - let quotient := (M.call (| U256, [(Value.Integer 0)] |)) in - else - let quotient := BinOp.floor_div (| dividend, divisor |) in in - let _ := (M.call (| push, [evm.stack; quotient] |)) in - let _ := M.assign_op (| - BinOp.add, - evm.pc, - (Value.Integer 1) - |) in)) - | _ => M.impossible - end. - -Definition sdiv (args : list Value.t) : M := - match args with - | [evm] => ltac:(M.monadic ( - let _ := (Value.String " + " in + let dividend := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let divisor := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let quotient := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let quotient := + BinOp.floor_div (| + M.get_name (| globals, "dividend" |), + M.get_name (| globals, "divisor" |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "quotient" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition sdiv : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " Signed integer division of the top two elements of the stack. Pushes the result back on the stack. @@ -159,33 +323,126 @@ Definition sdiv (args : list Value.t) : M := evm : The current EVM frame. - ") in - let dividend := (M.call (| (M.call (| pop, [evm.stack] |)).to_signed, [] |)) in - let divisor := (M.call (| (M.call (| pop, [evm.stack] |)).to_signed, [] |)) in - let _ := (M.call (| charge_gas, [evm; GAS_LOW] |)) in - let _ := - if M.is_true (Compare.eq (| divisor, (Value.Integer 0) |)) then - let quotient := (Value.Integer 0) in - else - let _ := - if M.is_true (BoolOp.and(Compare.eq (| dividend, (UnOp.subU255_CEIL_VALUE) |)) (Compare.eq (| divisor, (UnOp.sub(Value.Integer 1)) |))) then - let quotient := (UnOp.subU255_CEIL_VALUE) in - else - let sign := (M.call (| get_sign, [BinOp.mult (| dividend, divisor |)] |)) in - let quotient := BinOp.mult (| sign, BinOp.floor_div (| (M.call (| abs, [dividend] |)), (M.call (| abs, [divisor] |)) |) |) in in in - let _ := (M.call (| push, [evm.stack; (M.call (| U256.from_signed, [quotient] |))] |)) in - let _ := M.assign_op (| - BinOp.add, - evm.pc, - (Value.Integer 1) - |) in)) - | _ => M.impossible - end. - -Definition mod (args : list Value.t) : M := - match args with - | [evm] => ltac:(M.monadic ( - let _ := (Value.String " + " in + let dividend := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let divisor := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let quotient := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_name (| globals, "dividend" |), UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "divisor" |), UnOp.sub (| Constant.int 1 |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let quotient := + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let sign := + M.call (| + M.get_name (| globals, "get_sign" |), + make_list [ + BinOp.mult (| + M.get_name (| globals, "dividend" |), + M.get_name (| globals, "divisor" |) + |) + ], + make_dict [] + |) in + let quotient := + BinOp.mult (| + M.get_name (| globals, "sign" |), + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "dividend" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "divisor" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + M.get_name (| globals, "quotient" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " Modulo remainder of the top two elements of the stack. Pushes the result back on the stack. @@ -194,28 +451,74 @@ Definition mod (args : list Value.t) : M := evm : The current EVM frame. - ") in - let x := (M.call (| pop, [evm.stack] |)) in - let y := (M.call (| pop, [evm.stack] |)) in - let _ := (M.call (| charge_gas, [evm; GAS_LOW] |)) in - let _ := - if M.is_true (Compare.eq (| y, (Value.Integer 0) |)) then - let remainder := (M.call (| U256, [(Value.Integer 0)] |)) in - else - let remainder := BinOp.mod_ (| x, y |) in in - let _ := (M.call (| push, [evm.stack; remainder] |)) in - let _ := M.assign_op (| - BinOp.add, - evm.pc, - (Value.Integer 1) - |) in)) - | _ => M.impossible - end. - -Definition smod (args : list Value.t) : M := - match args with - | [evm] => ltac:(M.monadic ( - let _ := (Value.String " + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let remainder := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let remainder := + BinOp.mod_ (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "remainder" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition smod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " Signed modulo remainder of the top two elements of the stack. Pushes the result back on the stack. @@ -224,28 +527,103 @@ Definition smod (args : list Value.t) : M := evm : The current EVM frame. - ") in - let x := (M.call (| (M.call (| pop, [evm.stack] |)).to_signed, [] |)) in - let y := (M.call (| (M.call (| pop, [evm.stack] |)).to_signed, [] |)) in - let _ := (M.call (| charge_gas, [evm; GAS_LOW] |)) in - let _ := - if M.is_true (Compare.eq (| y, (Value.Integer 0) |)) then - let remainder := (Value.Integer 0) in - else - let remainder := BinOp.mult (| (M.call (| get_sign, [x] |)), BinOp.mod_ (| (M.call (| abs, [x] |)), (M.call (| abs, [y] |)) |) |) in in - let _ := (M.call (| push, [evm.stack; (M.call (| U256.from_signed, [remainder] |))] |)) in - let _ := M.assign_op (| - BinOp.add, - evm.pc, - (Value.Integer 1) - |) in)) - | _ => M.impossible - end. - -Definition addmod (args : list Value.t) : M := - match args with - | [evm] => ltac:(M.monadic ( - let _ := (Value.String " + " in + let x := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let y := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let remainder := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let remainder := + BinOp.mult (| + M.call (| + M.get_name (| globals, "get_sign" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + BinOp.mod_ (| + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + M.get_name (| globals, "remainder" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition addmod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " Modulo addition of the top 2 elements with the 3rd element. Pushes the result back on the stack. @@ -254,29 +632,109 @@ Definition addmod (args : list Value.t) : M := evm : The current EVM frame. - ") in - let x := (M.call (| Uint, [(M.call (| pop, [evm.stack] |))] |)) in - let y := (M.call (| Uint, [(M.call (| pop, [evm.stack] |))] |)) in - let z := (M.call (| Uint, [(M.call (| pop, [evm.stack] |))] |)) in - let _ := (M.call (| charge_gas, [evm; GAS_MID] |)) in - let _ := - if M.is_true (Compare.eq (| z, (Value.Integer 0) |)) then - let result := (M.call (| U256, [(Value.Integer 0)] |)) in - else - let result := (M.call (| U256, [BinOp.mod_ (| BinOp.add (| x, y |), z |)] |)) in in - let _ := (M.call (| push, [evm.stack; result] |)) in - let _ := M.assign_op (| - BinOp.add, - evm.pc, - (Value.Integer 1) - |) in)) - | _ => M.impossible - end. - -Definition mulmod (args : list Value.t) : M := - match args with - | [evm] => ltac:(M.monadic ( - let _ := (Value.String " + " in + let x := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let z := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_MID" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.add (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |), + M.get_name (| globals, "z" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mulmod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " Modulo multiplication of the top 2 elements with the 3rd element. Pushes the result back on the stack. @@ -285,29 +743,109 @@ Definition mulmod (args : list Value.t) : M := evm : The current EVM frame. - ") in - let x := (M.call (| Uint, [(M.call (| pop, [evm.stack] |))] |)) in - let y := (M.call (| Uint, [(M.call (| pop, [evm.stack] |))] |)) in - let z := (M.call (| Uint, [(M.call (| pop, [evm.stack] |))] |)) in - let _ := (M.call (| charge_gas, [evm; GAS_MID] |)) in - let _ := - if M.is_true (Compare.eq (| z, (Value.Integer 0) |)) then - let result := (M.call (| U256, [(Value.Integer 0)] |)) in - else - let result := (M.call (| U256, [BinOp.mod_ (| BinOp.mult (| x, y |), z |)] |)) in in - let _ := (M.call (| push, [evm.stack; result] |)) in - let _ := M.assign_op (| - BinOp.add, - evm.pc, - (Value.Integer 1) - |) in)) - | _ => M.impossible - end. - -Definition exp (args : list Value.t) : M := - match args with - | [evm] => ltac:(M.monadic ( - let _ := (Value.String " + " in + let x := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let z := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_MID" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.mult (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |), + M.get_name (| globals, "z" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition exp : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " Exponential operation of the top 2 elements. Pushes the result back on the stack. @@ -316,26 +854,98 @@ Definition exp (args : list Value.t) : M := evm : The current EVM frame. - ") in - let base := (M.call (| Uint, [(M.call (| pop, [evm.stack] |))] |)) in - let exponent := (M.call (| Uint, [(M.call (| pop, [evm.stack] |))] |)) in - let exponent_bits := (M.call (| exponent.bit_length, [] |)) in - let exponent_bytes := BinOp.floor_div (| BinOp.add (| exponent_bits, (Value.Integer 7) |), (Value.Integer 8) |) in - let _ := (M.call (| charge_gas, [evm; BinOp.add (| GAS_EXPONENTIATION, BinOp.mult (| GAS_EXPONENTIATION_PER_BYTE, exponent_bytes |) |)] |)) in - let result := (M.call (| U256, [(M.call (| pow, [base; exponent; U256_CEIL_VALUE] |))] |)) in - let _ := (M.call (| push, [evm.stack; result] |)) in - let _ := M.assign_op (| - BinOp.add, - evm.pc, - (Value.Integer 1) - |) in)) - | _ => M.impossible - end. - -Definition signextend (args : list Value.t) : M := - match args with - | [evm] => ltac:(M.monadic ( - let _ := (Value.String " + " in + let base := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exponent := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exponent_bits := + M.call (| + M.get_field (| M.get_name (| globals, "exponent" |), "bit_length" |), + make_list [], + make_dict [] + |) in + let exponent_bytes := + BinOp.floor_div (| + BinOp.add (| + M.get_name (| globals, "exponent_bits" |), + Constant.int 7 + |), + Constant.int 8 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_EXPONENTIATION" |), + BinOp.mult (| + M.get_name (| globals, "GAS_EXPONENTIATION_PER_BYTE" |), + M.get_name (| globals, "exponent_bytes" |) + |) + |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "pow" |), + make_list [ + M.get_name (| globals, "base" |); + M.get_name (| globals, "exponent" |); + M.get_name (| globals, "U256_CEIL_VALUE" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition signextend : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " Sign extend operation. In other words, extend a signed number which fits in N bytes to 32 bytes. @@ -344,28 +954,132 @@ Definition signextend (args : list Value.t) : M := evm : The current EVM frame. - ") in - let byte_num := (M.call (| pop, [evm.stack] |)) in - let value := (M.call (| pop, [evm.stack] |)) in - let _ := (M.call (| charge_gas, [evm; GAS_LOW] |)) in - let _ := - if M.is_true (Compare.gt (| byte_num, (Value.Integer 31) |)) then - let result := value in - else - let value_bytes := (M.call (| bytes, [(M.call (| value.to_be_bytes32, [] |))] |)) in - let value_bytes := value_bytes[BinOp.sub (| (Value.Integer 31), (M.call (| int, [byte_num] |)) |):(* At stmt: unsupported node type: NoneType *)] in - let sign_bit := BinOp.r_shift (| value_bytes[(Value.Integer 0)], (Value.Integer 7) |) in - let _ := - if M.is_true (Compare.eq (| sign_bit, (Value.Integer 0) |)) then - let result := (M.call (| U256.from_be_bytes, [value_bytes] |)) in - else - let num_bytes_prepend := BinOp.sub (| (Value.Integer 32), BinOp.add (| byte_num, (Value.Integer 1) |) |) in - let result := (M.call (| U256.from_be_bytes, [BinOp.add (| (M.call (| bytearray, [BinOp.mult (| [(Value.Integer 255)], num_bytes_prepend |)] |)), value_bytes |)] |)) in in in - let _ := (M.call (| push, [evm.stack; result] |)) in - let _ := M.assign_op (| - BinOp.add, - evm.pc, - (Value.Integer 1) - |) in)) - | _ => M.impossible - end. + " in + let byte_num := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "byte_num" |), Constant.int 31 |), + (* then *) + ltac:(M.monadic ( + let result := + M.get_name (| globals, "value" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let value_bytes := + M.call (| + M.get_name (| globals, "bytes" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "value" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) in + let value_bytes := + M.get_subscript (| M.get_name (| globals, "value_bytes" |), BinOp.sub (| + Constant.int 31, + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "byte_num" |) + ], + make_dict [] + |) + |):(* At expr: unsupported node type: NoneType *) |) in + let sign_bit := + BinOp.r_shift (| + M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), + Constant.int 7 + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "sign_bit" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "value_bytes" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let num_bytes_prepend := + BinOp.sub (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "byte_num" |), + Constant.int 1 + |) + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + BinOp.add (| + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [ + BinOp.mult (| + make_list [ + Constant.int 255 + ], + M.get_name (| globals, "num_bytes_prepend" |) + |) + ], + make_dict [] + |), + M.get_name (| globals, "value_bytes" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/vm/instructions/bitwise.v b/CoqOfPython/ethereum/paris/vm/instructions/bitwise.v new file mode 100644 index 0000000..9f2f382 --- /dev/null +++ b/CoqOfPython/ethereum/paris/vm/instructions/bitwise.v @@ -0,0 +1,601 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Bitwise Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM bitwise instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_U256_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition bitwise_and : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise AND operation of the top 2 elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + BinOp.bit_and (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_or : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise OR operation of the top 2 elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + BinOp.bit_or (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_xor : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise XOR operation of the top 2 elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + BinOp.bit_xor (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_not : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise NOT operation of the top element of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + UnOp.invert (| M.get_name (| globals, "x" |) |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition get_byte : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + For a word (defined by next top element of the stack), retrieve the + Nth byte (0-indexed and defined by top element of stack) from the + left (most significant) to right (least significant). + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let byte_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let word := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "byte_index" |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let extra_bytes_to_right := + BinOp.sub (| + Constant.int 31, + M.get_name (| globals, "byte_index" |) + |) in + let word := + BinOp.r_shift (| + M.get_name (| globals, "word" |), + BinOp.mult (| + M.get_name (| globals, "extra_bytes_to_right" |), + Constant.int 8 + |) + |) in + let word := + BinOp.bit_and (| + M.get_name (| globals, "word" |), + Constant.int 255 + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "word" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_shl : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Logical shift left (SHL) operation of the top 2 elements of the stack. + Pushes the result back on the stack. + Parameters + ---------- + evm : + The current EVM frame. + " in + let shift := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.l_shift (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "shift" |) + |), + M.get_name (| globals, "U256_CEIL_VALUE" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_shr : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Logical shift right (SHR) operation of the top 2 elements of the stack. + Pushes the result back on the stack. + Parameters + ---------- + evm : + The current EVM frame. + " in + let shift := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), + (* then *) + ltac:(M.monadic ( + let result := + BinOp.r_shift (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "shift" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_sar : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Arithmetic shift right (SAR) operation of the top 2 elements of the stack. + Pushes the result back on the stack. + Parameters + ---------- + evm : + The current EVM frame. + " in + let shift := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let signed_value := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + BinOp.r_shift (| + M.get_name (| globals, "signed_value" |), + M.get_name (| globals, "shift" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "signed_value" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/vm/instructions/block.v b/CoqOfPython/ethereum/paris/vm/instructions/block.v new file mode 100644 index 0000000..c66d2d9 --- /dev/null +++ b/CoqOfPython/ethereum/paris/vm/instructions/block.v @@ -0,0 +1,421 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Block Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM block instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_BLOCK_HASH : + IsGlobalAlias globals gas.globals "GAS_BLOCK_HASH". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition block_hash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the hash of one of the 256 most recent complete blocks onto the + stack. The block number to hash is present at the top of the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + Raises + ------ + :py:class:`~ethereum.paris.vm.exceptions.StackUnderflowError` + If `len(stack)` is less than `1`. + :py:class:`~ethereum.paris.vm.exceptions.OutOfGasError` + If `evm.gas_left` is less than `20`. + " in + let block_number := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BLOCK_HASH" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt_e (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), M.get_name (| globals, "block_number" |) |), + ltac:(M.monadic ( + Compare.gt (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), BinOp.add (| + M.get_name (| globals, "block_number" |), + Constant.int 256 + |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let hash := + (* At constant: unsupported node type: Constant *) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let hash := + M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + M.get_name (| globals, "block_number" |) + |) |) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "hash" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition coinbase : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's beneficiary address (address of the block miner) + onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + Raises + ------ + :py:class:`~ethereum.paris.vm.exceptions.StackOverflowError` + If `len(stack)` is equal to `1024`. + :py:class:`~ethereum.paris.vm.exceptions.OutOfGasError` + If `evm.gas_left` is less than `2`. + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "coinbase" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition timestamp : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's timestamp onto the stack. Here the timestamp + being referred is actually the unix timestamp in seconds. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + Raises + ------ + :py:class:`~ethereum.paris.vm.exceptions.StackOverflowError` + If `len(stack)` is equal to `1024`. + :py:class:`~ethereum.paris.vm.exceptions.OutOfGasError` + If `evm.gas_left` is less than `2`. + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "time" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition number : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's number onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + Raises + ------ + :py:class:`~ethereum.paris.vm.exceptions.StackOverflowError` + If `len(stack)` is equal to `1024`. + :py:class:`~ethereum.paris.vm.exceptions.OutOfGasError` + If `evm.gas_left` is less than `2`. + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition prev_randao : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the `prev_randao` value onto the stack. + + The `prev_randao` value is the random output of the beacon chain's + randomness oracle for the previous block. + + Parameters + ---------- + evm : + The current EVM frame. + + Raises + ------ + :py:class:`~ethereum.paris.vm.exceptions.StackOverflowError` + If `len(stack)` is equal to `1024`. + :py:class:`~ethereum.paris.vm.exceptions.OutOfGasError` + If `evm.gas_left` is less than `2`. + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "prev_randao" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition gas_limit : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's gas limit onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + Raises + ------ + :py:class:`~ethereum.paris.vm.exceptions.StackOverflowError` + If `len(stack)` is equal to `1024`. + :py:class:`~ethereum.paris.vm.exceptions.OutOfGasError` + If `evm.gas_left` is less than `2`. + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "gas_limit" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition chain_id : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the chain id onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + Raises + ------ + :py:class:`~ethereum.paris.vm.exceptions.StackOverflowError` + If `len(stack)` is equal to `1024`. + :py:class:`~ethereum.paris.vm.exceptions.OutOfGasError` + If `evm.gas_left` is less than `2`. + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "chain_id" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/vm/instructions/comparison.v b/CoqOfPython/ethereum/paris/vm/instructions/comparison.v new file mode 100644 index 0000000..fbc35f8 --- /dev/null +++ b/CoqOfPython/ethereum/paris/vm/instructions/comparison.v @@ -0,0 +1,404 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Comparison Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM Comparison instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition less_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is less than the next top element. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let right := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition signed_less_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed less-than comparison. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let right := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition greater_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is greater than the next top element. Pushes + the result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let right := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition signed_greater_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed greater-than comparison. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let right := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition equal : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is equal to the next top element. Pushes + the result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let right := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.eq (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition is_zero : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is equal to 0. Pushes the result back on the + stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.eq (| M.get_name (| globals, "x" |), Constant.int 0 |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/vm/instructions/control_flow.v b/CoqOfPython/ethereum/paris/vm/instructions/control_flow.v new file mode 100644 index 0000000..04a79d9 --- /dev/null +++ b/CoqOfPython/ethereum/paris/vm/instructions/control_flow.v @@ -0,0 +1,336 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Control Flow Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM control flow instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require vm.gas. +Axiom vm_gas_GAS_BASE : + IsGlobalAlias globals vm.gas.globals "GAS_BASE". +Axiom vm_gas_GAS_HIGH : + IsGlobalAlias globals vm.gas.globals "GAS_HIGH". +Axiom vm_gas_GAS_JUMPDEST : + IsGlobalAlias globals vm.gas.globals "GAS_JUMPDEST". +Axiom vm_gas_GAS_MID : + IsGlobalAlias globals vm.gas.globals "GAS_MID". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_InvalidJumpDestError : + IsGlobalAlias globals exceptions.globals "InvalidJumpDestError". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition stop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stop further execution of EVM code. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let _ := M.pass (| |) in + let _ := M.pass (| |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "running" |), + Constant.bool false + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition jump : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Alter the program counter to the location specified by the top of the + stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let jump_dest := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_MID" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "jump_dest" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition jumpi : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Alter the program counter to the specified location if and only if a + condition is true. If the condition is not true, then the program counter + would increase only by 1. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let jump_dest := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let conditional_value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_HIGH" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "conditional_value" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let destination := + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let destination := + M.get_name (| globals, "jump_dest" |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "destination" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition pc : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push onto the stack the value of the program counter after reaching the + current instruction and without increasing it for the next instruction. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "pc" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition gas_left : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the amount of available gas (including the corresponding reduction + for the cost of this instruction) onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition jumpdest : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Mark a valid destination for jumps. This is a noop, present only + to be used by `JUMP` and `JUMPI` opcodes to verify that their jump is + valid. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_JUMPDEST" |) + ], + make_dict [] + |) in + let _ := M.pass (| |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/vm/instructions/environment.v b/CoqOfPython/ethereum/paris/vm/instructions/environment.v new file mode 100644 index 0000000..530304e --- /dev/null +++ b/CoqOfPython/ethereum/paris/vm/instructions/environment.v @@ -0,0 +1,1436 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Environmental Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM environment related instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require fork_types. +Axiom fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". + +Require state. +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". + +Require utils.address. +Axiom utils_address_to_address : + IsGlobalAlias globals utils.address.globals "to_address". + +Require vm.memory. +Axiom vm_memory_buffer_read : + IsGlobalAlias globals vm.memory.globals "buffer_read". +Axiom vm_memory_memory_write : + IsGlobalAlias globals vm.memory.globals "memory_write". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_OutOfBoundsRead : + IsGlobalAlias globals exceptions.globals "OutOfBoundsRead". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_COLD_ACCOUNT_ACCESS : + IsGlobalAlias globals gas.globals "GAS_COLD_ACCOUNT_ACCESS". +Axiom gas_GAS_COPY : + IsGlobalAlias globals gas.globals "GAS_COPY". +Axiom gas_GAS_FAST_STEP : + IsGlobalAlias globals gas.globals "GAS_FAST_STEP". +Axiom gas_GAS_RETURN_DATA_COPY : + IsGlobalAlias globals gas.globals "GAS_RETURN_DATA_COPY". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_GAS_WARM_ACCESS : + IsGlobalAlias globals gas.globals "GAS_WARM_ACCESS". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the address of the current executing account to the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition balance : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the balance of the given account onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "balance" |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "balance" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition origin : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the address of the original transaction sender to the stack. + The origin address can only be an EOA. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "origin" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition caller : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the address of the caller onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "caller" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition callvalue : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the value (in wei) sent with the call onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition calldataload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push a word (32 bytes) of the input data belonging to the current + environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |); + M.get_name (| globals, "start_index" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition calldatasize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the size of input data in current environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition calldatacopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy a portion of the input data in current environment to memory. + + This will also expand the memory, in case that the memory is insufficient + to store the data. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let data_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |); + M.get_name (| globals, "data_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition codesize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the size of code running in current environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "code" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition codecopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy a portion of the code in current environment to memory. + + This will also expand the memory, in case that the memory is insufficient + to store the data. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let code_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "code" |); + M.get_name (| globals, "code_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition gasprice : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the gas price used in current environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "gas_price" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition extcodesize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the code size of a given account onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let codesize := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "code" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "codesize" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition extcodecopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy a portion of an account's code to memory. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let code_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_WARM_ACCESS" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "code" |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "code" |); + M.get_name (| globals, "code_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition returndatasize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the size of the return data buffer onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition returndatacopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copies data from the return data buffer code to memory + + Parameters + ---------- + evm : + The current EVM frame. + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let return_data_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_RETURN_DATA_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "return_data_start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "OutOfBoundsRead" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |):BinOp.add (| + M.get_name (| globals, "return_data_start_position" |), + M.get_name (| globals, "size" |) + |) |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition extcodehash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Returns the keccak256 hash of a contract’s bytecode + Parameters + ---------- + evm : + The current EVM frame. + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "account" |), M.get_name (| globals, "EMPTY_ACCOUNT" |) |), + (* then *) + ltac:(M.monadic ( + let codehash := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let codehash := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_field (| M.get_name (| globals, "account" |), "code" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "codehash" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition self_balance : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the balance of the current address to the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_FAST_STEP" |) + ], + make_dict [] + |) in + let balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "balance" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition base_fee : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the base fee of the current block on to the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "base_fee_per_gas" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/vm/instructions/keccak.v b/CoqOfPython/ethereum/paris/vm/instructions/keccak.v new file mode 100644 index 0000000..cab9ffb --- /dev/null +++ b/CoqOfPython/ethereum/paris/vm/instructions/keccak.v @@ -0,0 +1,181 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Keccak Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM keccak instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_KECCAK256 : + IsGlobalAlias globals gas.globals "GAS_KECCAK256". +Axiom gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition keccak : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes to the stack the Keccak-256 hash of a region of memory. + + This also expands the memory, in case the memory is insufficient to + access the data's memory location. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let word_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_KECCAK256_WORD" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_KECCAK256" |), + M.get_name (| globals, "word_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let data := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "hash" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/vm/instructions/log.v b/CoqOfPython/ethereum/paris/vm/instructions/log.v new file mode 100644 index 0000000..4891a4d --- /dev/null +++ b/CoqOfPython/ethereum/paris/vm/instructions/log.v @@ -0,0 +1,244 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Logging Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM logging instructions. +". + +Require functools. +Axiom functools_partial : + IsGlobalAlias globals functools.globals "partial". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_WriteInStaticContext : + IsGlobalAlias globals exceptions.globals "WriteInStaticContext". + +Require gas. +Axiom gas_GAS_LOG : + IsGlobalAlias globals gas.globals "GAS_LOG". +Axiom gas_GAS_LOG_DATA : + IsGlobalAlias globals gas.globals "GAS_LOG_DATA". +Axiom gas_GAS_LOG_TOPIC : + IsGlobalAlias globals gas.globals "GAS_LOG_TOPIC". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". + +Definition log_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "num_topics" ] |) in + let _ := Constant.str " + Appends a log entry, having `num_topics` topics, to the evm logs. + + This will also expand the memory if the data (required by the log entry) + corresponding to the memory is not accessible. + + Parameters + ---------- + evm : + The current EVM frame. + num_topics : + The number of topics to be included in the log entry. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let topics := + make_list [] in + For M.get_name (| globals, "_" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "num_topics" |) + ], + make_dict [] + |) do + let topic := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "topics" |), "append" |), + make_list [ + M.get_name (| globals, "topic" |) + ], + make_dict [] + |) in + EndFor. + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_LOG" |), + BinOp.mult (| + M.get_name (| globals, "GAS_LOG_DATA" |), + M.get_name (| globals, "size" |) + |) + |), + BinOp.mult (| + M.get_name (| globals, "GAS_LOG_TOPIC" |), + M.get_name (| globals, "num_topics" |) + |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let log_entry := + M.call (| + M.get_name (| globals, "Log" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "logs" |), + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "logs" |), + make_tuple [ M.get_name (| globals, "log_entry" |) ] + |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition log0 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/paris/vm/instructions/memory.v b/CoqOfPython/ethereum/paris/vm/instructions/memory.v new file mode 100644 index 0000000..1e1c8b0 --- /dev/null +++ b/CoqOfPython/ethereum/paris/vm/instructions/memory.v @@ -0,0 +1,378 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Memory Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM Memory instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". +Axiom memory_memory_write : + IsGlobalAlias globals memory.globals "memory_write". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition mstore : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a word to memory. + This also expands the memory, if the memory is + insufficient to store the word. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "start_position" |); M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + ], + make_dict [] + |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "start_position" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mstore8 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a byte to memory. + This also expands the memory, if the memory is + insufficient to store the word. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "start_position" |); M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let normalized_bytes_value := + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + make_list [ + BinOp.bit_and (| + M.get_name (| globals, "value" |), + Constant.int 255 + |) + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "start_position" |); + M.get_name (| globals, "normalized_bytes_value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Load word from memory. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "start_position" |); M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "start_position" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition msize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the size of active memory in bytes onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/vm/instructions/stack.v b/CoqOfPython/ethereum/paris/vm/instructions/stack.v new file mode 100644 index 0000000..1eeda05 --- /dev/null +++ b/CoqOfPython/ethereum/paris/vm/instructions/stack.v @@ -0,0 +1,929 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Stack Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM stack related instructions. +". + +Require functools. +Axiom functools_partial : + IsGlobalAlias globals functools.globals "partial". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". +Axiom __init___stack : + IsGlobalAlias globals __init__.globals "stack". + +Require exceptions. +Axiom exceptions_StackUnderflowError : + IsGlobalAlias globals exceptions.globals "StackUnderflowError". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_buffer_read : + IsGlobalAlias globals memory.globals "buffer_read". + +Definition pop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Remove item from stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.pass (| |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition push_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "num_bytes" ] |) in + let _ := Constant.str " + Pushes a N-byte immediate onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + num_bytes : + The number of immediate bytes to be read from the code and pushed to + the stack. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let data_to_push := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "code" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "num_bytes" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "data_to_push" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + BinOp.add (| + Constant.int 1, + M.get_name (| globals, "num_bytes" |) + |) + |) in + M.pure Constant.None_)). + +Definition dup_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "item_number" ] |) in + let _ := Constant.str " + Duplicate the Nth stack item (from top of the stack) to the top of stack. + + Parameters + ---------- + evm : + The current EVM frame. + + item_number : + The stack item number (0-indexed from top of stack) to be duplicated + to the top of stack. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "StackUnderflowError" |) + ], + make_dict [] + |) in + let data_to_duplicate := + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + BinOp.sub (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), + Constant.int 1 + |), + M.get_name (| globals, "item_number" |) + |) |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "data_to_duplicate" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition swap_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "item_number" ] |) in + let _ := Constant.str " + Swap the top and the `item_number` element of the stack, where + the top of the stack is position zero. + + If `item_number` is zero, this function does nothing (which should not be + possible, since there is no `SWAP0` instruction). + + Parameters + ---------- + evm : + The current EVM frame. + + item_number : + The stack item number (0-indexed from top of stack) to be swapped + with the top of stack element. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "StackUnderflowError" |) + ], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) |) ], + make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |) ] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition push1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push5 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push6 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push7 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push8 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push9 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push10 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push11 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push12 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push13 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push14 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push15 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push16 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push17 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push18 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push19 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push20 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push21 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push22 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push23 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push24 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push25 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push26 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push27 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push28 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push29 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push30 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push31 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push32 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition dup1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup5 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup6 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup7 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup8 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup9 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup10 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup11 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup12 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup13 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup14 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup15 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup16 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition swap1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap5 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap6 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap7 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap8 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap9 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap10 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap11 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap12 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap13 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap14 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap15 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap16 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/paris/vm/instructions/storage.v b/CoqOfPython/ethereum/paris/vm/instructions/storage.v new file mode 100644 index 0000000..2f0a831 --- /dev/null +++ b/CoqOfPython/ethereum/paris/vm/instructions/storage.v @@ -0,0 +1,437 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Storage Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM storage related instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require state. +Axiom state_get_storage : + IsGlobalAlias globals state.globals "get_storage". +Axiom state_get_storage_original : + IsGlobalAlias globals state.globals "get_storage_original". +Axiom state_set_storage : + IsGlobalAlias globals state.globals "set_storage". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". +Axiom exceptions_WriteInStaticContext : + IsGlobalAlias globals exceptions.globals "WriteInStaticContext". + +Require gas. +Axiom gas_GAS_CALL_STIPEND : + IsGlobalAlias globals gas.globals "GAS_CALL_STIPEND". +Axiom gas_GAS_COLD_SLOAD : + IsGlobalAlias globals gas.globals "GAS_COLD_SLOAD". +Axiom gas_GAS_STORAGE_CLEAR_REFUND : + IsGlobalAlias globals gas.globals "GAS_STORAGE_CLEAR_REFUND". +Axiom gas_GAS_STORAGE_SET : + IsGlobalAlias globals gas.globals "GAS_STORAGE_SET". +Axiom gas_GAS_STORAGE_UPDATE : + IsGlobalAlias globals gas.globals "GAS_STORAGE_UPDATE". +Axiom gas_GAS_WARM_ACCESS : + IsGlobalAlias globals gas.globals "GAS_WARM_ACCESS". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition sload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Loads to the stack, the value corresponding to a certain key from the + storage of the current account. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let key := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "add" |), + make_list [ + make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_COLD_SLOAD" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let value := + M.call (| + M.get_name (| globals, "get_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition sstore : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a value at a certain key in the current context's storage. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let key := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let new_value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt (| M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), M.get_name (| globals, "GAS_CALL_STIPEND" |) |); + M.get_name (| globals, "OutOfGasError" |) + ], + make_dict [] + |) in + let original_value := + M.call (| + M.get_name (| globals, "get_storage_original" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let current_value := + M.call (| + M.get_name (| globals, "get_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let gas_cost := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "add" |), + make_list [ + make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ] + ], + make_dict [] + |) in + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_COLD_SLOAD" |) + M.get_name (| globals, "GAS_COLD_SLOAD" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_name (| globals, "original_value" |), M.get_name (| globals, "current_value" |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_name (| globals, "current_value" |), M.get_name (| globals, "new_value" |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_STORAGE_SET" |) + M.get_name (| globals, "GAS_STORAGE_SET" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let gas_cost := BinOp.add + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_UPDATE" |), + M.get_name (| globals, "GAS_COLD_SLOAD" |) + |) + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_UPDATE" |), + M.get_name (| globals, "GAS_COLD_SLOAD" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_WARM_ACCESS" |) + M.get_name (| globals, "GAS_WARM_ACCESS" |) in + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| M.get_name (| globals, "current_value" |), M.get_name (| globals, "new_value" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "new_value" |), Constant.int 0 |) + )) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.sub, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "original_value" |), M.get_name (| globals, "new_value" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_SET" |), + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.sub (| + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_UPDATE" |), + M.get_name (| globals, "GAS_COLD_SLOAD" |) + |), + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "gas_cost" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "set_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |); + M.get_name (| globals, "new_value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/vm/interpreter.v b/CoqOfPython/ethereum/paris/vm/interpreter.v new file mode 100644 index 0000000..121e62d --- /dev/null +++ b/CoqOfPython/ethereum/paris/vm/interpreter.v @@ -0,0 +1,647 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Interpreter +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +A straightforward interpreter that executes EVM code. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Iterable : + IsGlobalAlias globals typing.globals "Iterable". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.trace. +Axiom ethereum_trace_EvmStop : + IsGlobalAlias globals ethereum.trace.globals "EvmStop". +Axiom ethereum_trace_OpEnd : + IsGlobalAlias globals ethereum.trace.globals "OpEnd". +Axiom ethereum_trace_OpException : + IsGlobalAlias globals ethereum.trace.globals "OpException". +Axiom ethereum_trace_OpStart : + IsGlobalAlias globals ethereum.trace.globals "OpStart". +Axiom ethereum_trace_PrecompileEnd : + IsGlobalAlias globals ethereum.trace.globals "PrecompileEnd". +Axiom ethereum_trace_PrecompileStart : + IsGlobalAlias globals ethereum.trace.globals "PrecompileStart". +Axiom ethereum_trace_TransactionEnd : + IsGlobalAlias globals ethereum.trace.globals "TransactionEnd". +Axiom ethereum_trace_evm_trace : + IsGlobalAlias globals ethereum.trace.globals "evm_trace". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_account_exists_and_is_empty : + IsGlobalAlias globals state.globals "account_exists_and_is_empty". +Axiom state_account_has_code_or_nonce : + IsGlobalAlias globals state.globals "account_has_code_or_nonce". +Axiom state_begin_transaction : + IsGlobalAlias globals state.globals "begin_transaction". +Axiom state_commit_transaction : + IsGlobalAlias globals state.globals "commit_transaction". +Axiom state_destroy_storage : + IsGlobalAlias globals state.globals "destroy_storage". +Axiom state_increment_nonce : + IsGlobalAlias globals state.globals "increment_nonce". +Axiom state_mark_account_created : + IsGlobalAlias globals state.globals "mark_account_created". +Axiom state_move_ether : + IsGlobalAlias globals state.globals "move_ether". +Axiom state_rollback_transaction : + IsGlobalAlias globals state.globals "rollback_transaction". +Axiom state_set_code : + IsGlobalAlias globals state.globals "set_code". +Axiom state_touch_account : + IsGlobalAlias globals state.globals "touch_account". + +Require vm. +Axiom vm_Message : + IsGlobalAlias globals vm.globals "Message". + +Require vm.gas. +Axiom vm_gas_GAS_CODE_DEPOSIT : + IsGlobalAlias globals vm.gas.globals "GAS_CODE_DEPOSIT". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require vm.precompiled_contracts.mapping. +Axiom vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : + IsGlobalAlias globals vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". + +Require __init__. +Axiom __init___Environment : + IsGlobalAlias globals __init__.globals "Environment". +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_AddressCollision : + IsGlobalAlias globals exceptions.globals "AddressCollision". +Axiom exceptions_ExceptionalHalt : + IsGlobalAlias globals exceptions.globals "ExceptionalHalt". +Axiom exceptions_InvalidContractPrefix : + IsGlobalAlias globals exceptions.globals "InvalidContractPrefix". +Axiom exceptions_InvalidOpcode : + IsGlobalAlias globals exceptions.globals "InvalidOpcode". +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". +Axiom exceptions_Revert : + IsGlobalAlias globals exceptions.globals "Revert". +Axiom exceptions_StackDepthLimitError : + IsGlobalAlias globals exceptions.globals "StackDepthLimitError". + +Require instructions. +Axiom instructions_Ops : + IsGlobalAlias globals instructions.globals "Ops". +Axiom instructions_op_implementation : + IsGlobalAlias globals instructions.globals "op_implementation". + +Require runtime. +Axiom runtime_get_valid_jump_destinations : + IsGlobalAlias globals runtime.globals "get_valid_jump_destinations". + +Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1024 + ], + make_dict [] + |) +)). + +Definition MAX_CODE_SIZE : Value.t := M.run ltac:(M.monadic ( + Constant.int 24576 +)). + +Definition MessageCallOutput : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition process_message_call : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + If `message.current` is empty then it creates a smart contract + else it executes a call from the `message.caller` to the `message.target`. + + Parameters + ---------- + message : + Transaction specific items. + + env : + External items required for EVM execution. + + Returns + ------- + output : `MessageCallOutput` + Output of the message call + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_name (| globals, "message" |), "target" |), M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let is_collision := + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_name (| globals, "is_collision" |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallOutput" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "tuple" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "AddressCollision" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let evm := + M.call (| + M.get_name (| globals, "process_create_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let evm := + M.call (| + M.get_name (| globals, "process_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_field (| M.get_name (| globals, "message" |), "target" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_field (| M.get_name (| globals, "message" |), "target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( +(* At stmt: unsupported node type: AnnAssign *) + let accounts_to_delete := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let touched_accounts := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let refund_counter := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let logs := + M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in + let accounts_to_delete := + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in + let touched_accounts := + M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |) in + let refund_counter := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let tx_end := + M.call (| + M.get_name (| globals, "TransactionEnd" |), + make_list [ + BinOp.sub (| + M.get_field (| M.get_name (| globals, "message" |), "gas" |), + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + |); + M.get_field (| M.get_name (| globals, "evm" |), "output" |); + M.get_field (| M.get_name (| globals, "evm" |), "error" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "evm_trace" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "tx_end" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallOutput" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition process_create_message : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + Executes a call to create a smart contract. + + Parameters + ---------- + message : + Transaction specific items. + env : + External items required for EVM execution. + + Returns + ------- + evm: :py:class:`~ethereum.paris.vm.Evm` + Items containing execution specific objects. + " in + let _ := M.call (| + M.get_name (| globals, "begin_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "destroy_storage" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "mark_account_created" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let evm := + M.call (| + M.get_name (| globals, "process_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), + (* then *) + ltac:(M.monadic ( + let contract_code := + M.get_field (| M.get_name (| globals, "evm" |), "output" |) in + let contract_code_gas := + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "contract_code" |) + ], + make_dict [] + |), + M.get_name (| globals, "GAS_CODE_DEPOSIT" |) + |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "rollback_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.get_name (| globals, "evm" |) + |) in + M.pure Constant.None_)). + +Definition process_message : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + Executes a call to create a smart contract. + + Parameters + ---------- + message : + Transaction specific items. + env : + External items required for EVM execution. + + Returns + ------- + evm: :py:class:`~ethereum.paris.vm.Evm` + Items containing execution specific objects + " in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_field (| M.get_name (| globals, "message" |), "depth" |), M.get_name (| globals, "STACK_DEPTH_LIMIT" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "StackDepthLimitError" |), + make_list [ + Constant.str "Stack depth limit reached" + ], + make_dict [] + |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "begin_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "touch_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + M.get_field (| M.get_name (| globals, "message" |), "should_transfer_value" |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_field (| M.get_name (| globals, "message" |), "value" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "move_ether" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "caller" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |); + M.get_field (| M.get_name (| globals, "message" |), "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let evm := + M.call (| + M.get_name (| globals, "execute_code" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "rollback_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "commit_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.get_name (| globals, "evm" |) + |) in + M.pure Constant.None_)). + +Definition execute_code : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + Executes bytecode present in the `message`. + + Parameters + ---------- + message : + Transaction specific items. + env : + External items required for EVM execution. + + Returns + ------- + evm: `ethereum.vm.EVM` + Items containing execution specific objects + " in + let code := + M.get_field (| M.get_name (| globals, "message" |), "code" |) in + let valid_jump_destinations := + M.call (| + M.get_name (| globals, "get_valid_jump_destinations" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) in + let evm := + M.call (| + M.get_name (| globals, "Evm" |), + make_list [], + make_dict [] + |) in +(* At stmt: unsupported node type: Try *) + let _ := M.return_ (| + M.get_name (| globals, "evm" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/vm/memory.v b/CoqOfPython/ethereum/paris/vm/memory.v new file mode 100644 index 0000000..fa8d906 --- /dev/null +++ b/CoqOfPython/ethereum/paris/vm/memory.v @@ -0,0 +1,153 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Memory +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +EVM memory operations. +". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_right_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "right_pad_zero_bytes". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". + +Definition memory_write : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "memory"; "start_position"; "value" ] |) in + let _ := Constant.str " + Writes to memory. + + Parameters + ---------- + memory : + Memory contents of the EVM. + start_position : + Starting pointer to the memory. + value : + Data to write to memory. + " in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) |), + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_)). + +Definition memory_read_bytes : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "memory"; "start_position"; "size" ] |) in + let _ := Constant.str " + Read bytes from memory. + + Parameters + ---------- + memory : + Memory contents of the EVM. + start_position : + Starting pointer to the memory. + size : + Size of the data that needs to be read from `start_position`. + + Returns + ------- + data_bytes : + Data read from memory. + " in + let _ := M.return_ (| + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |) + |) in + M.pure Constant.None_)). + +Definition buffer_read : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "buffer"; "start_position"; "size" ] |) in + let _ := Constant.str " + Read bytes from a buffer. Padding with zeros if necessary. + + Parameters + ---------- + buffer : + Memory contents of the EVM. + start_position : + Starting pointer to the memory. + size : + Size of the data that needs to be read from `start_position`. + + Returns + ------- + data_bytes : + Data read from memory. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "right_pad_zero_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/__init__.v new file mode 100644 index 0000000..ca49311 --- /dev/null +++ b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/__init__.v @@ -0,0 +1,117 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Precompiled Contract Addresses +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Addresses of precompiled contracts and mappings to their +implementations. +". + +Require utils.hexadecimal. +Axiom utils_hexadecimal_hex_to_address : + IsGlobalAlias globals utils.hexadecimal.globals "hex_to_address". + +Definition __all__ : Value.t := M.run ltac:(M.monadic ( + make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS"; Constant.str "MODEXP_ADDRESS"; Constant.str "ALT_BN128_ADD_ADDRESS"; Constant.str "ALT_BN128_MUL_ADDRESS"; Constant.str "ALT_BN128_PAIRING_CHECK_ADDRESS"; Constant.str "BLAKE2F_ADDRESS" ] +)). + +Definition ECRECOVER_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x01" + ], + make_dict [] + |) +)). + +Definition SHA256_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x02" + ], + make_dict [] + |) +)). + +Definition RIPEMD160_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x03" + ], + make_dict [] + |) +)). + +Definition IDENTITY_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x04" + ], + make_dict [] + |) +)). + +Definition MODEXP_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x05" + ], + make_dict [] + |) +)). + +Definition ALT_BN128_ADD_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x06" + ], + make_dict [] + |) +)). + +Definition ALT_BN128_MUL_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x07" + ], + make_dict [] + |) +)). + +Definition ALT_BN128_PAIRING_CHECK_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x08" + ], + make_dict [] + |) +)). + +Definition BLAKE2F_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x09" + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/alt_bn128.v new file mode 100644 index 0000000..19b83fc --- /dev/null +++ b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/alt_bn128.v @@ -0,0 +1,673 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) ALT_BN128 CONTRACTS +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the ALT_BN128 precompiled contracts. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.alt_bn128. +Axiom ethereum_crypto_alt_bn128_ALT_BN128_CURVE_ORDER : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "ALT_BN128_CURVE_ORDER". +Axiom ethereum_crypto_alt_bn128_ALT_BN128_PRIME : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "ALT_BN128_PRIME". +Axiom ethereum_crypto_alt_bn128_BNF : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF". +Axiom ethereum_crypto_alt_bn128_BNF2 : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF2". +Axiom ethereum_crypto_alt_bn128_BNF12 : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF12". +Axiom ethereum_crypto_alt_bn128_BNP : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNP". +Axiom ethereum_crypto_alt_bn128_BNP2 : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNP2". +Axiom ethereum_crypto_alt_bn128_pairing : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "pairing". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require vm.memory. +Axiom vm_memory_buffer_read : + IsGlobalAlias globals vm.memory.globals "buffer_read". + +Require exceptions. +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". + +Definition alt_bn128_add : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + The ALT_BN128 addition precompiled contract. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 150 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x0_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x0_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "x0_bytes" |) + ], + make_dict [] + |) in + let y0_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y0_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "y0_bytes" |) + ], + make_dict [] + |) in + let x1_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x1_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "x1_bytes" |) + ], + make_dict [] + |) in + let y1_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y1_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "y1_bytes" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ] do + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "i" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. +(* At stmt: unsupported node type: Try *) + let p := + BinOp.add (| + M.get_name (| globals, "p0" |), + M.get_name (| globals, "p1" |) + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + BinOp.add (| + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "p" |), "x" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "p" |), "y" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) + |) in + M.pure Constant.None_)). + +Definition alt_bn128_mul : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + The ALT_BN128 multiplication precompiled contract. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 6000 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x0_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x0_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "x0_bytes" |) + ], + make_dict [] + |) in + let y0_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y0_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "y0_bytes" |) + ], + make_dict [] + |) in + let n := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ] do + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "i" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. +(* At stmt: unsupported node type: Try *) + let p := + M.call (| + M.get_field (| M.get_name (| globals, "p0" |), "mul_by" |), + make_list [ + M.get_name (| globals, "n" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + BinOp.add (| + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "p" |), "x" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "p" |), "y" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) + |) in + M.pure Constant.None_)). + +Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + The ALT_BN128 pairing check precompiled contract. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 34000, + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 192 + |) + |), + Constant.int 45000 + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 192 + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 192 + |) + ], + make_dict [] + |) do + let values := + make_list [] in + For M.get_name (| globals, "j" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 6 + ], + make_dict [] + |) do + let value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "data" |), BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + M.get_name (| globals, "j" |) + |) + |):BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "j" |), + Constant.int 1 + |) + |) + |) |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "value" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "values" |), "append" |), + make_list [ + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + EndFor. +(* At stmt: unsupported node type: Try *) + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.call (| + M.get_field (| M.get_name (| globals, "p" |), "mul_by" |), + make_list [ + M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) + ], + make_dict [] + |), M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) |); + M.get_name (| globals, "OutOfGasError" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.call (| + M.get_field (| M.get_name (| globals, "q" |), "mul_by" |), + make_list [ + M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) + ], + make_dict [] + |), M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) |); + M.get_name (| globals, "OutOfGasError" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "p" |), M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_name (| globals, "q" |), M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let result := + BinOp.mult (| + M.get_name (| globals, "result" |), + M.call (| + M.get_name (| globals, "pairing" |), + make_list [ + M.get_name (| globals, "q" |); + M.get_name (| globals, "p" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "result" |), M.call (| + M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/blake2f.v b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/blake2f.v new file mode 100644 index 0000000..5903066 --- /dev/null +++ b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/blake2f.v @@ -0,0 +1,122 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Blake2 PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `Blake2` precompiled contract. +". + +Require ethereum.crypto.blake2. +Axiom ethereum_crypto_blake2_Blake2b : + IsGlobalAlias globals ethereum.crypto.blake2.globals "Blake2b". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_BLAKE2_PER_ROUND : + IsGlobalAlias globals vm.gas.globals "GAS_BLAKE2_PER_ROUND". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require exceptions. +Axiom exceptions_InvalidParameter : + IsGlobalAlias globals exceptions.globals "InvalidParameter". + +Definition blake2f : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the Blake2 hash to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), Constant.int 213 |); + M.get_name (| globals, "InvalidParameter" |) + ], + make_dict [] + |) in + let blake2b := + M.call (| + M.get_name (| globals, "Blake2b" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "rounds" |); M.get_name (| globals, "h" |); M.get_name (| globals, "m" |); M.get_name (| globals, "t_0" |); M.get_name (| globals, "t_1" |); M.get_name (| globals, "f" |) ], + M.call (| + M.get_field (| M.get_name (| globals, "blake2b" |), "get_blake2_parameters" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.mult (| + M.get_name (| globals, "GAS_BLAKE2_PER_ROUND" |), + M.get_name (| globals, "rounds" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.in (| M.get_name (| globals, "f" |), make_list [ + Constant.int 0; + Constant.int 1 + ] |); + M.get_name (| globals, "InvalidParameter" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.get_name (| globals, "blake2b" |), "compress" |), + make_list [ + M.get_name (| globals, "rounds" |); + M.get_name (| globals, "h" |); + M.get_name (| globals, "m" |); + M.get_name (| globals, "t_0" |); + M.get_name (| globals, "t_1" |); + M.get_name (| globals, "f" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/ecrecover.v new file mode 100644 index 0000000..cc351b5 --- /dev/null +++ b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/ecrecover.v @@ -0,0 +1,269 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) ECRECOVER PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the ECRECOVER precompiled contract. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require ethereum.crypto.elliptic_curve. +Axiom ethereum_crypto_elliptic_curve_SECP256K1N : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_left_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_ECRECOVER : + IsGlobalAlias globals vm.gas.globals "GAS_ECRECOVER". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require vm.memory. +Axiom vm_memory_buffer_read : + IsGlobalAlias globals vm.memory.globals "buffer_read". + +Definition ecrecover : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Decrypts the address using elliptic curve DSA recovery mechanism and writes + the address to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_ECRECOVER" |) + ], + make_dict [] + |) in + let message_hash_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let message_hash := + M.call (| + M.get_name (| globals, "Hash32" |), + make_list [ + M.get_name (| globals, "message_hash_bytes" |) + ], + make_dict [] + |) in + let v := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let r := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let s := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 27 |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 28 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| Constant.int 0, M.get_name (| globals, "r" |) |), + ltac:(M.monadic ( + Compare.gt_e (| M.get_name (| globals, "r" |), M.get_name (| globals, "SECP256K1N" |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| Constant.int 0, M.get_name (| globals, "s" |) |), + ltac:(M.monadic ( + Compare.gt_e (| M.get_name (| globals, "s" |), M.get_name (| globals, "SECP256K1N" |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in +(* At stmt: unsupported node type: Try *) + let address := + M.get_subscript (| M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), Constant.int 12:Constant.int 32 |) in + let padded_address := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "address" |); + Constant.int 32 + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.get_name (| globals, "padded_address" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/identity.v new file mode 100644 index 0000000..fa96704 --- /dev/null +++ b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/identity.v @@ -0,0 +1,94 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) IDENTITY PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `IDENTITY` precompiled contract. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_IDENTITY : + IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY". +Axiom vm_gas_GAS_IDENTITY_WORD : + IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY_WORD". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition identity : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the message data to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let word_count := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_IDENTITY" |), + BinOp.mult (| + M.get_name (| globals, "GAS_IDENTITY_WORD" |), + M.get_name (| globals, "word_count" |) + |) + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.get_name (| globals, "data" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/mapping.v new file mode 100644 index 0000000..8a2e2eb --- /dev/null +++ b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/mapping.v @@ -0,0 +1,82 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Precompiled Contract Addresses +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Mapping of precompiled contracts their implementations. +". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require __init__. +Axiom __init___ALT_BN128_ADD_ADDRESS : + IsGlobalAlias globals __init__.globals "ALT_BN128_ADD_ADDRESS". +Axiom __init___ALT_BN128_MUL_ADDRESS : + IsGlobalAlias globals __init__.globals "ALT_BN128_MUL_ADDRESS". +Axiom __init___ALT_BN128_PAIRING_CHECK_ADDRESS : + IsGlobalAlias globals __init__.globals "ALT_BN128_PAIRING_CHECK_ADDRESS". +Axiom __init___BLAKE2F_ADDRESS : + IsGlobalAlias globals __init__.globals "BLAKE2F_ADDRESS". +Axiom __init___ECRECOVER_ADDRESS : + IsGlobalAlias globals __init__.globals "ECRECOVER_ADDRESS". +Axiom __init___IDENTITY_ADDRESS : + IsGlobalAlias globals __init__.globals "IDENTITY_ADDRESS". +Axiom __init___MODEXP_ADDRESS : + IsGlobalAlias globals __init__.globals "MODEXP_ADDRESS". +Axiom __init___RIPEMD160_ADDRESS : + IsGlobalAlias globals __init__.globals "RIPEMD160_ADDRESS". +Axiom __init___SHA256_ADDRESS : + IsGlobalAlias globals __init__.globals "SHA256_ADDRESS". + +Require alt_bn128. +Axiom alt_bn128_alt_bn128_add : + IsGlobalAlias globals alt_bn128.globals "alt_bn128_add". +Axiom alt_bn128_alt_bn128_mul : + IsGlobalAlias globals alt_bn128.globals "alt_bn128_mul". +Axiom alt_bn128_alt_bn128_pairing_check : + IsGlobalAlias globals alt_bn128.globals "alt_bn128_pairing_check". + +Require blake2f. +Axiom blake2f_blake2f : + IsGlobalAlias globals blake2f.globals "blake2f". + +Require ecrecover. +Axiom ecrecover_ecrecover : + IsGlobalAlias globals ecrecover.globals "ecrecover". + +Require identity. +Axiom identity_identity : + IsGlobalAlias globals identity.globals "identity". + +Require modexp. +Axiom modexp_modexp : + IsGlobalAlias globals modexp.globals "modexp". + +Require ripemd160. +Axiom ripemd160_ripemd160 : + IsGlobalAlias globals ripemd160.globals "ripemd160". + +Require sha256. +Axiom sha256_sha256 : + IsGlobalAlias globals sha256.globals "sha256". + +(* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/modexp.v new file mode 100644 index 0000000..544949e --- /dev/null +++ b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/modexp.v @@ -0,0 +1,608 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) MODEXP PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `MODEXP` precompiled contract. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require memory. +Axiom memory_buffer_read : + IsGlobalAlias globals memory.globals "buffer_read". + +Definition GQUADDIVISOR : Value.t := M.run ltac:(M.monadic ( + Constant.int 3 +)). + +Definition modexp : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Calculates `(base**exp) % modulus` for arbitrary sized `base`, `exp` and. + `modulus`. The return value is the same length as the modulus. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let base_length := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exp_length := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let modulus_length := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exp_start := + BinOp.add (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |), + M.get_name (| globals, "base_length" |) + |) in + let exp_head := + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.get_name (| globals, "exp_start" |); + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.get_name (| globals, "exp_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "gas_cost" |), + make_list [ + M.get_name (| globals, "base_length" |); + M.get_name (| globals, "modulus_length" |); + M.get_name (| globals, "exp_length" |); + M.get_name (| globals, "exp_head" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_name (| globals, "base_length" |), Constant.int 0 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "modulus_length" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [], + make_dict [] + |) + |) in + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let base := + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |); + M.get_name (| globals, "base_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exp := + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.get_name (| globals, "exp_start" |); + M.get_name (| globals, "exp_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let modulus_start := + BinOp.add (| + M.get_name (| globals, "exp_start" |), + M.get_name (| globals, "exp_length" |) + |) in + let modulus := + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.get_name (| globals, "modulus_start" |); + M.get_name (| globals, "modulus_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "modulus" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + BinOp.mult (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |), + M.get_name (| globals, "modulus_length" |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pow" |), + make_list [ + M.get_name (| globals, "base" |); + M.get_name (| globals, "exp" |); + M.get_name (| globals, "modulus" |) + ], + make_dict [] + |) + ], + make_dict [] + |), "to_bytes" |), + make_list [ + M.get_name (| globals, "modulus_length" |); + Constant.str "big" + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition complexity : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "base_length"; "modulus_length" ] |) in + let _ := Constant.str " + Estimate the complexity of performing a modular exponentiation. + + Parameters + ---------- + + base_length : + Length of the array representing the base integer. + + modulus_length : + Length of the array representing the modulus integer. + + Returns + ------- + + complexity : `Uint` + Complexity of performing the operation. + " in + let max_length := + M.call (| + M.get_name (| globals, "max" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "base_length" |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "modulus_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + BinOp.add (| + M.get_name (| globals, "max_length" |), + Constant.int 7 + |), + Constant.int 8 + |) in + let _ := M.return_ (| + BinOp.pow (| + M.get_name (| globals, "words" |), + Constant.int 2 + |) + |) in + M.pure Constant.None_)). + +Definition iterations : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "exponent_length"; "exponent_head" ] |) in + let _ := Constant.str " + Calculate the number of iterations required to perform a modular + exponentiation. + + Parameters + ---------- + + exponent_length : + Length of the array representing the exponent integer. + + exponent_head : + First 32 bytes of the exponent (with leading zero padding if it is + shorter than 32 bytes), as an unsigned integer. + + Returns + ------- + + iterations : `Uint` + Number of iterations. + " in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.lt_e (| M.get_name (| globals, "exponent_length" |), Constant.int 32 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "exponent_head" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let count := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| M.get_name (| globals, "exponent_length" |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let bit_length := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "exponent_head" |), "bit_length" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "bit_length" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let bit_length := BinOp.sub + Constant.int 1 + Constant.int 1 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let count := + M.get_name (| globals, "bit_length" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let length_part := + BinOp.mult (| + Constant.int 8, + BinOp.sub (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "exponent_length" |) + ], + make_dict [] + |), + Constant.int 32 + |) + |) in + let bits_part := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "exponent_head" |), "bit_length" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "bits_part" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let bits_part := BinOp.sub + Constant.int 1 + Constant.int 1 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let count := + BinOp.add (| + M.get_name (| globals, "length_part" |), + M.get_name (| globals, "bits_part" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "max" |), + make_list [ + M.get_name (| globals, "count" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition gas_cost : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "base_length"; "modulus_length"; "exponent_length"; "exponent_head" ] |) in + let _ := Constant.str " + Calculate the gas cost of performing a modular exponentiation. + + Parameters + ---------- + + base_length : + Length of the array representing the base integer. + + modulus_length : + Length of the array representing the modulus integer. + + exponent_length : + Length of the array representing the exponent integer. + + exponent_head : + First 32 bytes of the exponent (with leading zero padding if it is + shorter than 32 bytes), as an unsigned integer. + + Returns + ------- + + gas_cost : `Uint` + Gas required for performing the operation. + " in + let multiplication_complexity := + M.call (| + M.get_name (| globals, "complexity" |), + make_list [ + M.get_name (| globals, "base_length" |); + M.get_name (| globals, "modulus_length" |) + ], + make_dict [] + |) in + let iteration_count := + M.call (| + M.get_name (| globals, "iterations" |), + make_list [ + M.get_name (| globals, "exponent_length" |); + M.get_name (| globals, "exponent_head" |) + ], + make_dict [] + |) in + let cost := + BinOp.mult (| + M.get_name (| globals, "multiplication_complexity" |), + M.get_name (| globals, "iteration_count" |) + |) in + let cost := BinOp.floor_div + M.get_name (| globals, "GQUADDIVISOR" |) + M.get_name (| globals, "GQUADDIVISOR" |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "max" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 200 + ], + make_dict [] + |); + M.get_name (| globals, "cost" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/ripemd160.v new file mode 100644 index 0000000..96f8dcd --- /dev/null +++ b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/ripemd160.v @@ -0,0 +1,122 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) RIPEMD160 PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `RIPEMD160` precompiled contract. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_left_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_RIPEMD160 : + IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160". +Axiom vm_gas_GAS_RIPEMD160_WORD : + IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160_WORD". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition ripemd160 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the ripemd160 hash to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let word_count := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_RIPEMD160" |), + BinOp.mult (| + M.get_name (| globals, "GAS_RIPEMD160_WORD" |), + M.get_name (| globals, "word_count" |) + |) + |) + ], + make_dict [] + |) in + let hash_bytes := + M.call (| + M.get_field (| M.call (| + M.get_field (| M.get_name (| globals, "hashlib" |), "new" |), + make_list [ + Constant.str "ripemd160"; + M.get_name (| globals, "data" |) + ], + make_dict [] + |), "digest" |), + make_list [], + make_dict [] + |) in + let padded_hash := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "hash_bytes" |); + Constant.int 32 + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.get_name (| globals, "padded_hash" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/sha256.v new file mode 100644 index 0000000..9f6d2bf --- /dev/null +++ b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/sha256.v @@ -0,0 +1,106 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) SHA256 PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `SHA256` precompiled contract. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_SHA256 : + IsGlobalAlias globals vm.gas.globals "GAS_SHA256". +Axiom vm_gas_GAS_SHA256_WORD : + IsGlobalAlias globals vm.gas.globals "GAS_SHA256_WORD". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition sha256 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the sha256 hash to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let word_count := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_SHA256" |), + BinOp.mult (| + M.get_name (| globals, "GAS_SHA256_WORD" |), + M.get_name (| globals, "word_count" |) + |) + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_field (| M.get_name (| globals, "hashlib" |), "sha256" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), "digest" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/vm/runtime.v b/CoqOfPython/ethereum/paris/vm/runtime.v new file mode 100644 index 0000000..835b46c --- /dev/null +++ b/CoqOfPython/ethereum/paris/vm/runtime.v @@ -0,0 +1,125 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Runtime Operations +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Runtime related operations used while executing EVM code. +". + +Require typing. +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require instructions. +Axiom instructions_Ops : + IsGlobalAlias globals instructions.globals "Ops". + +Definition get_valid_jump_destinations : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "code" ] |) in + let _ := Constant.str " + Analyze the evm code to obtain the set of valid jump destinations. + + Valid jump destinations are defined as follows: + * The jump destination is less than the length of the code. + * The jump destination should have the `JUMPDEST` opcode (0x5B). + * The jump destination shouldn't be part of the data corresponding to + `PUSH-N` opcodes. + + Note - Jump destinations are 0-indexed. + + Parameters + ---------- + code : + The EVM code which is to be executed. + + Returns + ------- + valid_jump_destinations: `Set[Uint]` + The set of valid jump destinations in the code. + " in + let valid_jump_destinations := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let pc := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + While Compare.lt (| M.get_name (| globals, "pc" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) |) do +(* At stmt: unsupported node type: Try *) + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "current_opcode" |), M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), + make_list [ + M.get_name (| globals, "pc" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + (* At expr: unsupported node type: Compare *), + (* then *) + ltac:(M.monadic ( + let push_data_size := + BinOp.add (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) + |), + Constant.int 1 + |) in + let pc := BinOp.add + M.get_name (| globals, "push_data_size" |) + M.get_name (| globals, "push_data_size" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let pc := BinOp.add + Constant.int 1 + Constant.int 1 in + EndWhile. + let _ := M.return_ (| + M.get_name (| globals, "valid_jump_destinations" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/vm/stack.v b/CoqOfPython/ethereum/paris/vm/stack.v new file mode 100644 index 0000000..42ea42d --- /dev/null +++ b/CoqOfPython/ethereum/paris/vm/stack.v @@ -0,0 +1,120 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Stack +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the stack operators for the EVM. +". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require exceptions. +Axiom exceptions_StackOverflowError : + IsGlobalAlias globals exceptions.globals "StackOverflowError". +Axiom exceptions_StackUnderflowError : + IsGlobalAlias globals exceptions.globals "StackUnderflowError". + +Definition pop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "stack" ] |) in + let _ := Constant.str " + Pops the top item off of `stack`. + + Parameters + ---------- + stack : + EVM stack. + + Returns + ------- + value : `U256` + The top element on the stack. + + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "StackUnderflowError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "pop" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition push : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "stack"; "value" ] |) in + let _ := Constant.str " + Pushes `value` onto `stack`. + + Parameters + ---------- + stack : + EVM stack. + + value : + Item to be pushed onto `stack`. + + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), Constant.int 1024 |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "StackOverflowError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "append" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/rlp.v b/CoqOfPython/ethereum/rlp.v new file mode 100644 index 0000000..6479bf7 --- /dev/null +++ b/CoqOfPython/ethereum/rlp.v @@ -0,0 +1,2060 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +.. _rlp: + +Recursive Length Prefix (RLP) Encoding +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Defines the serialization and deserialization format used throughout Ethereum. +". + +Require dataclasses. +Axiom dataclasses_astuple : + IsGlobalAlias globals dataclasses.globals "astuple". +Axiom dataclasses_fields : + IsGlobalAlias globals dataclasses.globals "fields". +Axiom dataclasses_is_dataclass : + IsGlobalAlias globals dataclasses.globals "is_dataclass". + +Require typing. +Axiom typing_Any : + IsGlobalAlias globals typing.globals "Any". +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Sequence : + IsGlobalAlias globals typing.globals "Sequence". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Type_ : + IsGlobalAlias globals typing.globals "Type_". +Axiom typing_TypeVar : + IsGlobalAlias globals typing.globals "TypeVar". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". +Axiom typing_cast : + IsGlobalAlias globals typing.globals "cast". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.exceptions. +Axiom ethereum_exceptions_RLPDecodingError : + IsGlobalAlias globals ethereum.exceptions.globals "RLPDecodingError". +Axiom ethereum_exceptions_RLPEncodingError : + IsGlobalAlias globals ethereum.exceptions.globals "RLPEncodingError". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require base_types. +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes0 : + IsGlobalAlias globals base_types.globals "Bytes0". +Axiom base_types_Bytes20 : + IsGlobalAlias globals base_types.globals "Bytes20". +Axiom base_types_FixedBytes : + IsGlobalAlias globals base_types.globals "FixedBytes". +Axiom base_types_FixedUint : + IsGlobalAlias globals base_types.globals "FixedUint". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". + +Definition RLP : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Any" |) +)). + +Definition encode : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "raw_data" ] |) in + let _ := Constant.str " + Encodes `raw_data` into a sequence of bytes using RLP. + + Parameters + ---------- + raw_data : + A `Bytes`, `Uint`, `Uint256` or sequence of `RLP` encodable + objects. + + Returns + ------- + encoded : `ethereum.base_types.Bytes` + The RLP encoded bytes representing `raw_data`. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "raw_data" |); + make_tuple [ M.get_name (| globals, "bytearray" |); M.get_name (| globals, "bytes" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "encode_bytes" |), + make_list [ + M.get_name (| globals, "raw_data" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "raw_data" |); + make_tuple [ M.get_name (| globals, "Uint" |); M.get_name (| globals, "FixedUint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "encode" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "raw_data" |), "to_be_bytes" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "raw_data" |); + M.get_name (| globals, "str" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "encode_bytes" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "raw_data" |), "encode" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "raw_data" |); + M.get_name (| globals, "bool" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.get_name (| globals, "raw_data" |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "encode_bytes" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "encode_bytes" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "raw_data" |); + M.get_name (| globals, "Sequence" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "encode_sequence" |), + make_list [ + M.get_name (| globals, "raw_data" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "is_dataclass" |), + make_list [ + M.get_name (| globals, "raw_data" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "astuple" |), + make_list [ + M.get_name (| globals, "raw_data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "RLPEncodingError" |), + make_list [ + M.call (| + M.get_field (| Constant.str "RLP Encoding of type {} is not supported", "format" |), + make_list [ + M.call (| + M.get_name (| globals, "type" |), + make_list [ + M.get_name (| globals, "raw_data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition encode_bytes : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "raw_bytes" ] |) in + let _ := Constant.str " + Encodes `raw_bytes`, a sequence of bytes, using RLP. + + Parameters + ---------- + raw_bytes : + Bytes to encode with RLP. + + Returns + ------- + encoded : `ethereum.base_types.Bytes` + The RLP encoded bytes representing `raw_bytes`. + " in + let len_raw_data := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "raw_bytes" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_name (| globals, "len_raw_data" |), Constant.int 1 |), + ltac:(M.monadic ( + Compare.lt (| M.get_subscript (| M.get_name (| globals, "raw_bytes" |), Constant.int 0 |), Constant.int 128 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "raw_bytes" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "len_raw_data" |), Constant.int 56 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + M.call (| + M.get_name (| globals, "bytes" |), + make_list [ + make_list [ + BinOp.add (| + Constant.int 128, + M.get_name (| globals, "len_raw_data" |) + |) + ] + ], + make_dict [] + |), + M.get_name (| globals, "raw_bytes" |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let len_raw_data_as_be := + M.call (| + M.get_field (| M.get_name (| globals, "len_raw_data" |), "to_be_bytes" |), + make_list [], + make_dict [] + |) in + let _ := M.return_ (| + BinOp.add (| + BinOp.add (| + M.call (| + M.get_name (| globals, "bytes" |), + make_list [ + make_list [ + BinOp.add (| + Constant.int 183, + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "len_raw_data_as_be" |) + ], + make_dict [] + |) + |) + ] + ], + make_dict [] + |), + M.get_name (| globals, "len_raw_data_as_be" |) + |), + M.get_name (| globals, "raw_bytes" |) + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition encode_sequence : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "raw_sequence" ] |) in + let _ := Constant.str " + Encodes a list of RLP encodable objects (`raw_sequence`) using RLP. + + Parameters + ---------- + raw_sequence : + Sequence of RLP encodable objects. + + Returns + ------- + encoded : `ethereum.base_types.Bytes` + The RLP encoded bytes representing `raw_sequence`. + " in + let joined_encodings := + M.call (| + M.get_name (| globals, "get_joined_encodings" |), + make_list [ + M.get_name (| globals, "raw_sequence" |) + ], + make_dict [] + |) in + let len_joined_encodings := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "joined_encodings" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "len_joined_encodings" |), Constant.int 56 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + make_list [ + BinOp.add (| + Constant.int 192, + M.get_name (| globals, "len_joined_encodings" |) + |) + ] + ], + make_dict [] + |), + M.get_name (| globals, "joined_encodings" |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let len_joined_encodings_as_be := + M.call (| + M.get_field (| M.get_name (| globals, "len_joined_encodings" |), "to_be_bytes" |), + make_list [], + make_dict [] + |) in + let _ := M.return_ (| + BinOp.add (| + BinOp.add (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + make_list [ + BinOp.add (| + Constant.int 247, + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "len_joined_encodings_as_be" |) + ], + make_dict [] + |) + |) + ] + ], + make_dict [] + |), + M.get_name (| globals, "len_joined_encodings_as_be" |) + |), + M.get_name (| globals, "joined_encodings" |) + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition get_joined_encodings : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "raw_sequence" ] |) in + let _ := Constant.str " + Obtain concatenation of rlp encoding for each item in the sequence + raw_sequence. + + Parameters + ---------- + raw_sequence : + Sequence to encode with RLP. + + Returns + ------- + joined_encodings : `ethereum.base_types.Bytes` + The concatenated RLP encoded bytes for each item in sequence + raw_sequence. + " in + let _ := M.return_ (| + M.call (| + M.get_field (| (* At constant: unsupported node type: Constant *), "join" |), + make_list [ + (M.call (| + M.get_name (| globals, "encode" |), + make_list [ + M.get_name (| globals, "item" |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition decode : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "encoded_data" ] |) in + let _ := Constant.str " + Decodes an integer, byte sequence, or list of RLP encodable objects + from the byte sequence `encoded_data`, using RLP. + + Parameters + ---------- + encoded_data : + A sequence of bytes, in RLP form. + + Returns + ------- + decoded_data : `RLP` + Object decoded from `encoded_data`. + " in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded_data" |) + ], + make_dict [] + |), Constant.int 0 |); + M.call (| + M.get_name (| globals, "RLPDecodingError" |), + make_list [ + Constant.str "Cannot decode empty bytestring" + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| M.get_subscript (| M.get_name (| globals, "encoded_data" |), Constant.int 0 |), Constant.int 191 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "decode_to_bytes" |), + make_list [ + M.get_name (| globals, "encoded_data" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "decode_to_sequence" |), + make_list [ + M.get_name (| globals, "encoded_data" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition T : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "TypeVar" |), + make_list [ + Constant.str "T" + ], + make_dict [] + |) +)). + +Definition decode_to : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "cls"; "encoded_data" ] |) in + let _ := Constant.str " + Decode the bytes in `encoded_data` to an object of type `cls`. `cls` can be + a `Bytes` subclass, a dataclass, `Uint`, `U256` or `Tuple[cls]`. + + Parameters + ---------- + cls: `Type[T]` + The type to decode to. + encoded_data : + A sequence of bytes, in RLP form. + + Returns + ------- + decoded_data : `T` + Object decoded from `encoded_data`. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "_decode_to" |), + make_list [ + M.get_name (| globals, "cls" |); + M.call (| + M.get_name (| globals, "decode" |), + make_list [ + M.get_name (| globals, "encoded_data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition _decode_to : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "cls"; "raw_rlp" ] |) in + let _ := Constant.str " + Decode the rlp structure in `encoded_data` to an object of type `cls`. + `cls` can be a `Bytes` subclass, a dataclass, `Uint`, `U256`, + `Tuple[cls, ...]`, `Tuple[cls1, cls2]` or `Union[Bytes, cls]`. + + Parameters + ---------- + cls: `Type[T]` + The type to decode to. + raw_rlp : + A decoded rlp structure. + + Returns + ------- + decoded_data : `T` + Object decoded from `encoded_data`. + " in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "cls" |); + M.call (| + M.get_name (| globals, "type" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "Tuple" |), make_tuple [ M.get_name (| globals, "Uint" |); (* At constant: unsupported node type: Constant *) ] |) + ], + make_dict [] + |) + ], + make_dict [] + |), + ltac:(M.monadic ( + Compare.eq (| M.get_field (| M.get_name (| globals, "cls" |), "_name" |), Constant.str "Tuple" |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "raw_rlp" |); + M.get_name (| globals, "list" |) + ], + make_dict [] + |); + M.get_name (| globals, "RLPDecodingError" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_subscript (| M.get_field (| M.get_name (| globals, "cls" |), "__args__" |), Constant.int 1 |), (* At constant: unsupported node type: Constant *) |), + (* then *) + ltac:(M.monadic ( + let args := + make_list [] in + For M.get_name (| globals, "raw_item" |) in M.get_name (| globals, "raw_rlp" |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "args" |), "append" |), + make_list [ + M.call (| + M.get_name (| globals, "_decode_to" |), + make_list [ + M.get_subscript (| M.get_field (| M.get_name (| globals, "cls" |), "__args__" |), Constant.int 0 |); + M.get_name (| globals, "raw_item" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "tuple" |), + make_list [ + M.get_name (| globals, "args" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let args := + make_list [] in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "raw_rlp" |) + ], + make_dict [] + |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "cls" |), "__args__" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "RLPDecodingError" |) + ], + make_dict [] + |) in + For make_tuple [ M.get_name (| globals, "t" |); M.get_name (| globals, "raw_item" |) ] in M.call (| + M.get_name (| globals, "zip" |), + make_list [ + M.get_field (| M.get_name (| globals, "cls" |), "__args__" |); + M.get_name (| globals, "raw_rlp" |) + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "args" |), "append" |), + make_list [ + M.call (| + M.get_name (| globals, "_decode_to" |), + make_list [ + M.get_name (| globals, "t" |); + M.get_name (| globals, "raw_item" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "tuple" |), + make_list [ + M.get_name (| globals, "args" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "cls" |), M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Bytes0" |); M.get_name (| globals, "Bytes20" |) ] |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "raw_rlp" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |); + M.get_name (| globals, "RLPDecodingError" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "raw_rlp" |) + ], + make_dict [] + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "raw_rlp" |) + ], + make_dict [] + |), Constant.int 20 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bytes20" |), + make_list [ + M.get_name (| globals, "raw_rlp" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "RLPDecodingError" |), + make_list [ + M.call (| + M.get_field (| Constant.str "Bytes has length {}, expected 0 or 20", "format" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "raw_rlp" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "cls" |); + M.call (| + M.get_name (| globals, "type" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "List" |), M.get_name (| globals, "Bytes" |) |) + ], + make_dict [] + |) + ], + make_dict [] + |), + ltac:(M.monadic ( + Compare.eq (| M.get_field (| M.get_name (| globals, "cls" |), "_name" |), Constant.str "List" |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "raw_rlp" |); + M.get_name (| globals, "list" |) + ], + make_dict [] + |); + M.get_name (| globals, "RLPDecodingError" |) + ], + make_dict [] + |) in + let items := + make_list [] in + For M.get_name (| globals, "raw_item" |) in M.get_name (| globals, "raw_rlp" |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "items" |), "append" |), + make_list [ + M.call (| + M.get_name (| globals, "_decode_to" |), + make_list [ + M.get_subscript (| M.get_field (| M.get_name (| globals, "cls" |), "__args__" |), Constant.int 0 |); + M.get_name (| globals, "raw_item" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + EndFor. + let _ := M.return_ (| + M.get_name (| globals, "items" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "cls" |); + M.call (| + M.get_name (| globals, "type" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Bytes" |); M.get_subscript (| M.get_name (| globals, "List" |), M.get_name (| globals, "Bytes" |) |) ] |) + ], + make_dict [] + |) + ], + make_dict [] + |), + ltac:(M.monadic ( + Compare.eq (| M.get_field (| M.get_name (| globals, "cls" |), "__origin__" |), M.get_name (| globals, "Union" |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.not_eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "cls" |), "__args__" |) + ], + make_dict [] + |), Constant.int 2 |), + ltac:(M.monadic ( + Compare.not_in (| M.get_name (| globals, "Bytes" |), M.get_field (| M.get_name (| globals, "cls" |), "__args__" |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "RLPDecodingError" |), + make_list [ + M.call (| + M.get_field (| Constant.str "RLP Decoding to type {} is not supported", "format" |), + make_list [ + M.get_name (| globals, "cls" |) + ], + make_dict [] + |) + ], + make_dict [] + |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "raw_rlp" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "raw_rlp" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_subscript (| M.get_field (| M.get_name (| globals, "cls" |), "__args__" |), Constant.int 0 |), M.get_name (| globals, "Bytes" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "_decode_to" |), + make_list [ + M.get_subscript (| M.get_field (| M.get_name (| globals, "cls" |), "__args__" |), Constant.int 1 |); + M.get_name (| globals, "raw_rlp" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "_decode_to" |), + make_list [ + M.get_subscript (| M.get_field (| M.get_name (| globals, "cls" |), "__args__" |), Constant.int 0 |); + M.get_name (| globals, "raw_rlp" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "issubclass" |), + make_list [ + M.get_name (| globals, "cls" |); + M.get_name (| globals, "bool" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "raw_rlp" |), (* At constant: unsupported node type: Constant *) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "cls" |), + make_list [ + Constant.bool true + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "raw_rlp" |), (* At constant: unsupported node type: Constant *) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "cls" |), + make_list [ + Constant.bool false + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "TypeError" |), + make_list [ + M.call (| + M.get_field (| Constant.str "Cannot decode {} as {}", "format" |), + make_list [ + M.get_name (| globals, "raw_rlp" |); + M.get_name (| globals, "cls" |) + ], + make_dict [] + |) + ], + make_dict [] + |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "issubclass" |), + make_list [ + M.get_name (| globals, "cls" |); + M.get_name (| globals, "FixedBytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "raw_rlp" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |); + M.get_name (| globals, "RLPDecodingError" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "raw_rlp" |) + ], + make_dict [] + |), M.get_field (| M.get_name (| globals, "cls" |), "LENGTH" |) |); + M.get_name (| globals, "RLPDecodingError" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "cls" |), + make_list [ + M.get_name (| globals, "raw_rlp" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "issubclass" |), + make_list [ + M.get_name (| globals, "cls" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "raw_rlp" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |); + M.get_name (| globals, "RLPDecodingError" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "raw_rlp" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "issubclass" |), + make_list [ + M.get_name (| globals, "cls" |); + make_tuple [ M.get_name (| globals, "Uint" |); M.get_name (| globals, "FixedUint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "raw_rlp" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |); + M.get_name (| globals, "RLPDecodingError" |) + ], + make_dict [] + |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "is_dataclass" |), + make_list [ + M.get_name (| globals, "cls" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "raw_rlp" |); + M.get_name (| globals, "list" |) + ], + make_dict [] + |); + M.get_name (| globals, "RLPDecodingError" |) + ], + make_dict [] + |) in + let _ := M.assert (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "raw_rlp" |); + M.get_name (| globals, "list" |) + ], + make_dict [] + |) |) in + let args := + make_list [] in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_name (| globals, "fields" |), + make_list [ + M.get_name (| globals, "cls" |) + ], + make_dict [] + |) + ], + make_dict [] + |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "raw_rlp" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "RLPDecodingError" |) + ], + make_dict [] + |) in + For make_tuple [ M.get_name (| globals, "field" |); M.get_name (| globals, "rlp_item" |) ] in M.call (| + M.get_name (| globals, "zip" |), + make_list [ + M.call (| + M.get_name (| globals, "fields" |), + make_list [ + M.get_name (| globals, "cls" |) + ], + make_dict [] + |); + M.get_name (| globals, "raw_rlp" |) + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "args" |), "append" |), + make_list [ + M.call (| + M.get_name (| globals, "_decode_to" |), + make_list [ + M.get_field (| M.get_name (| globals, "field" |), "type" |); + M.get_name (| globals, "rlp_item" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "cast" |), + make_list [ + M.get_name (| globals, "T" |); + M.call (| + M.get_name (| globals, "cls" |), + M.get_name (| globals, "args" |), + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "RLPDecodingError" |), + make_list [ + M.call (| + M.get_field (| Constant.str "RLP Decoding to type {} is not supported", "format" |), + make_list [ + M.get_name (| globals, "cls" |) + ], + make_dict [] + |) + ], + make_dict [] + |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition decode_to_bytes : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "encoded_bytes" ] |) in + let _ := Constant.str " + Decodes a rlp encoded byte stream assuming that the decoded data + should be of type `bytes`. + + Parameters + ---------- + encoded_bytes : + RLP encoded byte stream. + + Returns + ------- + decoded : `ethereum.base_types.Bytes` + RLP decoded Bytes data + " in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded_bytes" |) + ], + make_dict [] + |), Constant.int 1 |), + ltac:(M.monadic ( + Compare.lt (| M.get_subscript (| M.get_name (| globals, "encoded_bytes" |), Constant.int 0 |), Constant.int 128 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "encoded_bytes" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| M.get_subscript (| M.get_name (| globals, "encoded_bytes" |), Constant.int 0 |), Constant.int 183 |), + (* then *) + ltac:(M.monadic ( + let len_raw_data := + BinOp.sub (| + M.get_subscript (| M.get_name (| globals, "encoded_bytes" |), Constant.int 0 |), + Constant.int 128 + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt (| M.get_name (| globals, "len_raw_data" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded_bytes" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "RLPDecodingError" |) + ], + make_dict [] + |) in + let raw_data := + M.get_subscript (| M.get_name (| globals, "encoded_bytes" |), Constant.int 1:BinOp.add (| + Constant.int 1, + M.get_name (| globals, "len_raw_data" |) + |) |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + UnOp.not (| BoolOp.and (| + Compare.eq (| M.get_name (| globals, "len_raw_data" |), Constant.int 1 |), + ltac:(M.monadic ( + Compare.lt (| M.get_subscript (| M.get_name (| globals, "raw_data" |), Constant.int 0 |), Constant.int 128 |) + )) + |) |); + M.get_name (| globals, "RLPDecodingError" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "raw_data" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let decoded_data_start_idx := + BinOp.sub (| + BinOp.add (| + Constant.int 1, + M.get_subscript (| M.get_name (| globals, "encoded_bytes" |), Constant.int 0 |) + |), + Constant.int 183 + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt (| BinOp.sub (| + M.get_name (| globals, "decoded_data_start_idx" |), + Constant.int 1 + |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded_bytes" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "RLPDecodingError" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_eq (| M.get_subscript (| M.get_name (| globals, "encoded_bytes" |), Constant.int 1 |), Constant.int 0 |); + M.get_name (| globals, "RLPDecodingError" |) + ], + make_dict [] + |) in + let len_decoded_data := + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "encoded_bytes" |), Constant.int 1:M.get_name (| globals, "decoded_data_start_idx" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt_e (| M.get_name (| globals, "len_decoded_data" |), Constant.int 56 |); + M.get_name (| globals, "RLPDecodingError" |) + ], + make_dict [] + |) in + let decoded_data_end_idx := + BinOp.add (| + M.get_name (| globals, "decoded_data_start_idx" |), + M.get_name (| globals, "len_decoded_data" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt (| BinOp.sub (| + M.get_name (| globals, "decoded_data_end_idx" |), + Constant.int 1 + |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded_bytes" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "RLPDecodingError" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_subscript (| M.get_name (| globals, "encoded_bytes" |), M.get_name (| globals, "decoded_data_start_idx" |):M.get_name (| globals, "decoded_data_end_idx" |) |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition decode_to_sequence : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "encoded_sequence" ] |) in + let _ := Constant.str " + Decodes a rlp encoded byte stream assuming that the decoded data + should be of type `Sequence` of objects. + + Parameters + ---------- + encoded_sequence : + An RLP encoded Sequence. + + Returns + ------- + decoded : `Sequence[RLP]` + Sequence of objects decoded from `encoded_sequence`. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| M.get_subscript (| M.get_name (| globals, "encoded_sequence" |), Constant.int 0 |), Constant.int 247 |), + (* then *) + ltac:(M.monadic ( + let len_joined_encodings := + BinOp.sub (| + M.get_subscript (| M.get_name (| globals, "encoded_sequence" |), Constant.int 0 |), + Constant.int 192 + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt (| M.get_name (| globals, "len_joined_encodings" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded_sequence" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "RLPDecodingError" |) + ], + make_dict [] + |) in + let joined_encodings := + M.get_subscript (| M.get_name (| globals, "encoded_sequence" |), Constant.int 1:BinOp.add (| + Constant.int 1, + M.get_name (| globals, "len_joined_encodings" |) + |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let joined_encodings_start_idx := + BinOp.sub (| + BinOp.add (| + Constant.int 1, + M.get_subscript (| M.get_name (| globals, "encoded_sequence" |), Constant.int 0 |) + |), + Constant.int 247 + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt (| BinOp.sub (| + M.get_name (| globals, "joined_encodings_start_idx" |), + Constant.int 1 + |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded_sequence" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "RLPDecodingError" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_eq (| M.get_subscript (| M.get_name (| globals, "encoded_sequence" |), Constant.int 1 |), Constant.int 0 |); + M.get_name (| globals, "RLPDecodingError" |) + ], + make_dict [] + |) in + let len_joined_encodings := + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "encoded_sequence" |), Constant.int 1:M.get_name (| globals, "joined_encodings_start_idx" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt_e (| M.get_name (| globals, "len_joined_encodings" |), Constant.int 56 |); + M.get_name (| globals, "RLPDecodingError" |) + ], + make_dict [] + |) in + let joined_encodings_end_idx := + BinOp.add (| + M.get_name (| globals, "joined_encodings_start_idx" |), + M.get_name (| globals, "len_joined_encodings" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt (| BinOp.sub (| + M.get_name (| globals, "joined_encodings_end_idx" |), + Constant.int 1 + |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded_sequence" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "RLPDecodingError" |) + ], + make_dict [] + |) in + let joined_encodings := + M.get_subscript (| M.get_name (| globals, "encoded_sequence" |), M.get_name (| globals, "joined_encodings_start_idx" |):M.get_name (| globals, "joined_encodings_end_idx" |) |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "decode_joined_encodings" |), + make_list [ + M.get_name (| globals, "joined_encodings" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition decode_joined_encodings : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "joined_encodings" ] |) in + let _ := Constant.str " + Decodes `joined_encodings`, which is a concatenation of RLP encoded + objects. + + Parameters + ---------- + joined_encodings : + concatenation of RLP encoded objects + + Returns + ------- + decoded : `List[RLP]` + A list of objects decoded from `joined_encodings`. + " in + let decoded_sequence := + make_list [] in + let item_start_idx := + Constant.int 0 in + While Compare.lt (| M.get_name (| globals, "item_start_idx" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "joined_encodings" |) + ], + make_dict [] + |) |) do + let encoded_item_length := + M.call (| + M.get_name (| globals, "decode_item_length" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "joined_encodings" |), M.get_name (| globals, "item_start_idx" |):(* At expr: unsupported node type: NoneType *) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt (| BinOp.sub (| + BinOp.add (| + M.get_name (| globals, "item_start_idx" |), + M.get_name (| globals, "encoded_item_length" |) + |), + Constant.int 1 + |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "joined_encodings" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "RLPDecodingError" |) + ], + make_dict [] + |) in + let encoded_item := + M.get_subscript (| M.get_name (| globals, "joined_encodings" |), M.get_name (| globals, "item_start_idx" |):BinOp.add (| + M.get_name (| globals, "item_start_idx" |), + M.get_name (| globals, "encoded_item_length" |) + |) |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "decoded_sequence" |), "append" |), + make_list [ + M.call (| + M.get_name (| globals, "decode" |), + make_list [ + M.get_name (| globals, "encoded_item" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let item_start_idx := BinOp.add + M.get_name (| globals, "encoded_item_length" |) + M.get_name (| globals, "encoded_item_length" |) in + EndWhile. + let _ := M.return_ (| + M.get_name (| globals, "decoded_sequence" |) + |) in + M.pure Constant.None_)). + +Definition decode_item_length : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "encoded_data" ] |) in + let _ := Constant.str " + Find the length of the rlp encoding for the first object in the + encoded sequence. + Here `encoded_data` refers to concatenation of rlp encoding for each + item in a sequence. + + NOTE - This is a helper function not described in the spec. It was + introduced as the spec doesn't discuss about decoding the RLP encoded + data. + + Parameters + ---------- + encoded_data : + RLP encoded data for a sequence of objects. + + Returns + ------- + rlp_length : `int` + " in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded_data" |) + ], + make_dict [] + |), Constant.int 0 |); + M.get_name (| globals, "RLPDecodingError" |) + ], + make_dict [] + |) in + let first_rlp_byte := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "encoded_data" |), Constant.int 0 |) + ], + make_dict [] + |) in + let length_length := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let decoded_data_length := + Constant.int 0 in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "first_rlp_byte" |), Constant.int 128 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.int 1 + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| M.get_name (| globals, "first_rlp_byte" |), Constant.int 183 |), + (* then *) + ltac:(M.monadic ( + let decoded_data_length := + BinOp.sub (| + M.get_name (| globals, "first_rlp_byte" |), + Constant.int 128 + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| M.get_name (| globals, "first_rlp_byte" |), Constant.int 191 |), + (* then *) + ltac:(M.monadic ( + let length_length := + BinOp.sub (| + M.get_name (| globals, "first_rlp_byte" |), + Constant.int 183 + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt (| M.get_name (| globals, "length_length" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded_data" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "RLPDecodingError" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_eq (| M.get_subscript (| M.get_name (| globals, "encoded_data" |), Constant.int 1 |), Constant.int 0 |); + M.get_name (| globals, "RLPDecodingError" |) + ], + make_dict [] + |) in + let decoded_data_length := + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "encoded_data" |), Constant.int 1:BinOp.add (| + Constant.int 1, + M.get_name (| globals, "length_length" |) + |) |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| M.get_name (| globals, "first_rlp_byte" |), Constant.int 247 |), + (* then *) + ltac:(M.monadic ( + let decoded_data_length := + BinOp.sub (| + M.get_name (| globals, "first_rlp_byte" |), + Constant.int 192 + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| M.get_name (| globals, "first_rlp_byte" |), Constant.int 255 |), + (* then *) + ltac:(M.monadic ( + let length_length := + BinOp.sub (| + M.get_name (| globals, "first_rlp_byte" |), + Constant.int 247 + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt (| M.get_name (| globals, "length_length" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded_data" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "RLPDecodingError" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_eq (| M.get_subscript (| M.get_name (| globals, "encoded_data" |), Constant.int 1 |), Constant.int 0 |); + M.get_name (| globals, "RLPDecodingError" |) + ], + make_dict [] + |) in + let decoded_data_length := + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "encoded_data" |), Constant.int 1:BinOp.add (| + Constant.int 1, + M.get_name (| globals, "length_length" |) + |) |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + BinOp.add (| + BinOp.add (| + Constant.int 1, + M.get_name (| globals, "length_length" |) + |), + M.get_name (| globals, "decoded_data_length" |) + |) + |) in + M.pure Constant.None_)). + +Definition rlp_hash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "data" ] |) in + let _ := Constant.str " + Obtain the keccak-256 hash of the rlp encoding of the passed in data. + + Parameters + ---------- + data : + The data for which we need the rlp hash. + + Returns + ------- + hash : `Hash32` + The rlp hash of the passed in data. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_name (| globals, "encode" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/__init__.v b/CoqOfPython/ethereum/shanghai/__init__.v new file mode 100644 index 0000000..1e974d9 --- /dev/null +++ b/CoqOfPython/ethereum/shanghai/__init__.v @@ -0,0 +1,24 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +The Shanghai fork brings staking withdrawals to the execution layer, adds a +push-zero EVM instruction, limits the maximum size of initialization +bytecode, and deprecates the self-destruct EVM instruction. +". + +Require ethereum.fork_criteria. +Axiom ethereum_fork_criteria_ByTimestamp : + IsGlobalAlias globals ethereum.fork_criteria.globals "ByTimestamp". + +Definition FORK_CRITERIA : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "ByTimestamp" |), + make_list [ + Constant.int 1681338455 + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/shanghai/blocks.v b/CoqOfPython/ethereum/shanghai/blocks.v new file mode 100644 index 0000000..2130667 --- /dev/null +++ b/CoqOfPython/ethereum/shanghai/blocks.v @@ -0,0 +1,107 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +A `Block` is a single link in the chain that is Ethereum. Each `Block` contains +a `Header` and zero or more transactions. Each `Header` contains associated +metadata like the block number, parent block hash, and how much gas was +consumed by its transactions. + +Together, these blocks form a cryptographically secure journal recording the +history of all state transitions that have happened since the genesis of the +chain. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require base_types. +Axiom base_types_U64 : + IsGlobalAlias globals base_types.globals "U64". +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes8 : + IsGlobalAlias globals base_types.globals "Bytes8". +Axiom base_types_Bytes32 : + IsGlobalAlias globals base_types.globals "Bytes32". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require crypto.hash. +Axiom crypto_hash_Hash32 : + IsGlobalAlias globals crypto.hash.globals "Hash32". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Require transactions. +Axiom transactions_LegacyTransaction : + IsGlobalAlias globals transactions.globals "LegacyTransaction". + +Definition Withdrawal : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Header : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Block : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Log : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Receipt : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. diff --git a/CoqOfPython/ethereum/shanghai/bloom.v b/CoqOfPython/ethereum/shanghai/bloom.v new file mode 100644 index 0000000..04b5d9f --- /dev/null +++ b/CoqOfPython/ethereum/shanghai/bloom.v @@ -0,0 +1,164 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Logs Bloom +^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +This modules defines functions for calculating bloom filters of logs. For the +general theory of bloom filters see e.g. `Wikipedia +`_. Bloom filters are used to allow +for efficient searching of logs by address and/or topic, by rapidly +eliminating blocks and receipts from their search. +". + +Require typing. +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require fork_types. +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". + +Definition add_to_bloom : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "bloom"; "bloom_entry" ] |) in + let _ := Constant.str " + Add a bloom entry to the bloom filter (`bloom`). + + The number of hash functions used is 3. They are calculated by taking the + least significant 11 bits from the first 3 16-bit words of the + `keccak_256()` hash of `bloom_entry`. + + Parameters + ---------- + bloom : + The bloom filter. + bloom_entry : + An entry which is to be added to bloom filter. + " in + let hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "bloom_entry" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "idx" |) in make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ] do + let bit_to_set := + BinOp.bit_and (| + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |):BinOp.add (| + M.get_name (| globals, "idx" |), + Constant.int 2 + |) |) + ], + make_dict [] + |), + Constant.int 2047 + |) in + let bit_index := + BinOp.sub (| + Constant.int 2047, + M.get_name (| globals, "bit_to_set" |) + |) in + let byte_index := + BinOp.floor_div (| + M.get_name (| globals, "bit_index" |), + Constant.int 8 + |) in + let bit_value := + BinOp.l_shift (| + Constant.int 1, + BinOp.sub (| + Constant.int 7, + BinOp.mod_ (| + M.get_name (| globals, "bit_index" |), + Constant.int 8 + |) + |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), + BinOp.bit_or (| + M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), + M.get_name (| globals, "bit_value" |) + |) + |) in + EndFor. + M.pure Constant.None_)). + +Definition logs_bloom : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "logs" ] |) in + let _ := Constant.str " + Obtain the logs bloom from a list of log entries. + + The address and each topic of a log are added to the bloom filter. + + Parameters + ---------- + logs : + List of logs for which the logs bloom is to be obtained. + + Returns + ------- + logs_bloom : `Bloom` + The logs bloom obtained which is 256 bytes with some bits set as per + the caller address and the log topics. + " in +(* At stmt: unsupported node type: AnnAssign *) + For M.get_name (| globals, "log" |) in M.get_name (| globals, "logs" |) do + let _ := M.call (| + M.get_name (| globals, "add_to_bloom" |), + make_list [ + M.get_name (| globals, "bloom" |); + M.get_field (| M.get_name (| globals, "log" |), "address" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "topic" |) in M.get_field (| M.get_name (| globals, "log" |), "topics" |) do + let _ := M.call (| + M.get_name (| globals, "add_to_bloom" |), + make_list [ + M.get_name (| globals, "bloom" |); + M.get_name (| globals, "topic" |) + ], + make_dict [] + |) in + EndFor. + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bloom" |), + make_list [ + M.get_name (| globals, "bloom" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/fork.v b/CoqOfPython/ethereum/shanghai/fork.v new file mode 100644 index 0000000..50d8f50 --- /dev/null +++ b/CoqOfPython/ethereum/shanghai/fork.v @@ -0,0 +1,2432 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Specification +^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Entry point for the Ethereum specification. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". + +Require ethereum.crypto.elliptic_curve. +Axiom ethereum_crypto_elliptic_curve_SECP256K1N : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.exceptions. +Axiom ethereum_exceptions_InvalidBlock : + IsGlobalAlias globals ethereum.exceptions.globals "InvalidBlock". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U64 : + IsGlobalAlias globals base_types.globals "U64". +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". + +Require __init__. +Axiom __init___vm : + IsGlobalAlias globals __init__.globals "vm". + +Require blocks. +Axiom blocks_Block : + IsGlobalAlias globals blocks.globals "Block". +Axiom blocks_Header : + IsGlobalAlias globals blocks.globals "Header". +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". +Axiom blocks_Receipt : + IsGlobalAlias globals blocks.globals "Receipt". +Axiom blocks_Withdrawal : + IsGlobalAlias globals blocks.globals "Withdrawal". + +Require bloom. +Axiom bloom_logs_bloom : + IsGlobalAlias globals bloom.globals "logs_bloom". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Require state. +Axiom state_State : + IsGlobalAlias globals state.globals "State". +Axiom state_account_exists_and_is_empty : + IsGlobalAlias globals state.globals "account_exists_and_is_empty". +Axiom state_destroy_account : + IsGlobalAlias globals state.globals "destroy_account". +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". +Axiom state_increment_nonce : + IsGlobalAlias globals state.globals "increment_nonce". +Axiom state_process_withdrawal : + IsGlobalAlias globals state.globals "process_withdrawal". +Axiom state_set_account_balance : + IsGlobalAlias globals state.globals "set_account_balance". +Axiom state_state_root : + IsGlobalAlias globals state.globals "state_root". + +Require transactions. +Axiom transactions_TX_ACCESS_LIST_ADDRESS_COST : + IsGlobalAlias globals transactions.globals "TX_ACCESS_LIST_ADDRESS_COST". +Axiom transactions_TX_ACCESS_LIST_STORAGE_KEY_COST : + IsGlobalAlias globals transactions.globals "TX_ACCESS_LIST_STORAGE_KEY_COST". +Axiom transactions_TX_BASE_COST : + IsGlobalAlias globals transactions.globals "TX_BASE_COST". +Axiom transactions_TX_CREATE_COST : + IsGlobalAlias globals transactions.globals "TX_CREATE_COST". +Axiom transactions_TX_DATA_COST_PER_NON_ZERO : + IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_NON_ZERO". +Axiom transactions_TX_DATA_COST_PER_ZERO : + IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_ZERO". +Axiom transactions_AccessListTransaction : + IsGlobalAlias globals transactions.globals "AccessListTransaction". +Axiom transactions_FeeMarketTransaction : + IsGlobalAlias globals transactions.globals "FeeMarketTransaction". +Axiom transactions_LegacyTransaction : + IsGlobalAlias globals transactions.globals "LegacyTransaction". +Axiom transactions_Transaction : + IsGlobalAlias globals transactions.globals "Transaction". +Axiom transactions_decode_transaction : + IsGlobalAlias globals transactions.globals "decode_transaction". +Axiom transactions_encode_transaction : + IsGlobalAlias globals transactions.globals "encode_transaction". + +Require trie. +Axiom trie_Trie : + IsGlobalAlias globals trie.globals "Trie". +Axiom trie_root : + IsGlobalAlias globals trie.globals "root". +Axiom trie_trie_set : + IsGlobalAlias globals trie.globals "trie_set". + +Require utils.message. +Axiom utils_message_prepare_message : + IsGlobalAlias globals utils.message.globals "prepare_message". + +Require vm.gas. +Axiom vm_gas_init_code_cost : + IsGlobalAlias globals vm.gas.globals "init_code_cost". + +Require vm.interpreter. +Axiom vm_interpreter_MAX_CODE_SIZE : + IsGlobalAlias globals vm.interpreter.globals "MAX_CODE_SIZE". +Axiom vm_interpreter_process_message_call : + IsGlobalAlias globals vm.interpreter.globals "process_message_call". + +Definition BASE_FEE_MAX_CHANGE_DENOMINATOR : Value.t := M.run ltac:(M.monadic ( + Constant.int 8 +)). + +Definition ELASTICITY_MULTIPLIER : Value.t := M.run ltac:(M.monadic ( + Constant.int 2 +)). + +Definition GAS_LIMIT_ADJUSTMENT_FACTOR : Value.t := M.run ltac:(M.monadic ( + Constant.int 1024 +)). + +Definition GAS_LIMIT_MINIMUM : Value.t := M.run ltac:(M.monadic ( + Constant.int 5000 +)). + +Definition EMPTY_OMMER_HASH : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_list [] + ], + make_dict [] + |) + ], + make_dict [] + |) +)). + +Definition BlockChain : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition apply_fork : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "old" ] |) in + let _ := Constant.str " + Transforms the state from the previous hard fork (`old`) into the block + chain object for this hard fork and returns it. + + When forks need to implement an irregular state transition, this function + is used to handle the irregularity. See the :ref:`DAO Fork ` for + an example. + + Parameters + ---------- + old : + Previous block chain object. + + Returns + ------- + new : `BlockChain` + Upgraded block chain object for this hard fork. + " in + let _ := M.return_ (| + M.get_name (| globals, "old" |) + |) in + M.pure Constant.None_)). + +Definition get_last_256_block_hashes : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "chain" ] |) in + let _ := Constant.str " + Obtain the list of hashes of the previous 256 blocks in order of + increasing block number. + + This function will return less hashes for the first 256 blocks. + + The ``BLOCKHASH`` opcode needs to access the latest hashes on the chain, + therefore this function retrieves them. + + Parameters + ---------- + chain : + History and current state. + + Returns + ------- + recent_block_hashes : `List[Hash32]` + Hashes of the recent 256 blocks in order of increasing block number. + " in + let recent_blocks := + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |):(* At expr: unsupported node type: NoneType *) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "recent_blocks" |) + ], + make_dict [] + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + make_list [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let recent_block_hashes := + make_list [] in + For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_blocks" |) do + let prev_block_hash := + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), + make_list [ + M.get_name (| globals, "prev_block_hash" |) + ], + make_dict [] + |) in + EndFor. + let most_recent_block_hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_field (| M.get_subscript (| M.get_name (| globals, "recent_blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), + make_list [ + M.get_name (| globals, "most_recent_block_hash" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "recent_block_hashes" |) + |) in + M.pure Constant.None_)). + +Definition state_transition : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "chain"; "block" ] |) in + let _ := Constant.str " + Attempts to apply a block to an existing block chain. + + All parts of the block's contents need to be verified before being added + to the chain. Blocks are verified by ensuring that the contents of the + block make logical sense with the contents of the parent block. The + information in the block's header must also match the corresponding + information in the block. + + To implement Ethereum, in theory clients are only required to store the + most recent 255 blocks of the chain since as far as execution is + concerned, only those blocks are accessed. Practically, however, clients + should store more blocks to handle reorgs. + + Parameters + ---------- + chain : + History and current state. + block : + Block to apply to `chain`. + " in + let parent_header := + M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) in + let _ := M.call (| + M.get_name (| globals, "validate_header" |), + make_list [ + M.get_field (| M.get_name (| globals, "block" |), "header" |); + M.get_name (| globals, "parent_header" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "block" |), "ommers" |), make_tuple [ ] |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let apply_body_output := + M.call (| + M.get_name (| globals, "apply_body" |), + make_list [ + M.get_field (| M.get_name (| globals, "chain" |), "state" |); + M.call (| + M.get_name (| globals, "get_last_256_block_hashes" |), + make_list [ + M.get_name (| globals, "chain" |) + ], + make_dict [] + |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "coinbase" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "number" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "base_fee_per_gas" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "gas_limit" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "timestamp" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "prev_randao" |); + M.get_field (| M.get_name (| globals, "block" |), "transactions" |); + M.get_field (| M.get_name (| globals, "chain" |), "chain_id" |); + M.get_field (| M.get_name (| globals, "block" |), "withdrawals" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_gas_used" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "gas_used" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "transactions_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "transactions_root" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "state_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "state_root" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "receipt_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "receipt_root" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_logs_bloom" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "bloom" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "withdrawals_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "withdrawals_root" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), "append" |), + make_list [ + M.get_name (| globals, "block" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |) + ], + make_dict [] + |), Constant.int 255 |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |):(* At expr: unsupported node type: NoneType *) |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "block_gas_limit"; "parent_gas_limit"; "parent_gas_used"; "parent_base_fee_per_gas" ] |) in + let _ := Constant.str " + Calculates the base fee per gas for the block. + + Parameters + ---------- + block_gas_limit : + Gas limit of the block for which the base fee is being calculated. + parent_gas_limit : + Gas limit of the parent block. + parent_gas_used : + Gas used in the parent block. + parent_base_fee_per_gas : + Base fee per gas of the parent block. + + Returns + ------- + base_fee_per_gas : `Uint` + Base fee per gas for the block. + " in + let parent_gas_target := + BinOp.floor_div (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "ELASTICITY_MULTIPLIER" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + M.call (| + M.get_name (| globals, "check_gas_limit" |), + make_list [ + M.get_name (| globals, "block_gas_limit" |); + M.get_name (| globals, "parent_gas_limit" |) + ], + make_dict [] + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "parent_gas_used" |), M.get_name (| globals, "parent_gas_target" |) |), + (* then *) + ltac:(M.monadic ( + let expected_base_fee_per_gas := + M.get_name (| globals, "parent_base_fee_per_gas" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "parent_gas_used" |), M.get_name (| globals, "parent_gas_target" |) |), + (* then *) + ltac:(M.monadic ( + let gas_used_delta := + BinOp.sub (| + M.get_name (| globals, "parent_gas_used" |), + M.get_name (| globals, "parent_gas_target" |) + |) in + let parent_fee_gas_delta := + BinOp.mult (| + M.get_name (| globals, "parent_base_fee_per_gas" |), + M.get_name (| globals, "gas_used_delta" |) + |) in + let target_fee_gas_delta := + BinOp.floor_div (| + M.get_name (| globals, "parent_fee_gas_delta" |), + M.get_name (| globals, "parent_gas_target" |) + |) in + let base_fee_per_gas_delta := + M.call (| + M.get_name (| globals, "max" |), + make_list [ + BinOp.floor_div (| + M.get_name (| globals, "target_fee_gas_delta" |), + M.get_name (| globals, "BASE_FEE_MAX_CHANGE_DENOMINATOR" |) + |); + Constant.int 1 + ], + make_dict [] + |) in + let expected_base_fee_per_gas := + BinOp.add (| + M.get_name (| globals, "parent_base_fee_per_gas" |), + M.get_name (| globals, "base_fee_per_gas_delta" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let gas_used_delta := + BinOp.sub (| + M.get_name (| globals, "parent_gas_target" |), + M.get_name (| globals, "parent_gas_used" |) + |) in + let parent_fee_gas_delta := + BinOp.mult (| + M.get_name (| globals, "parent_base_fee_per_gas" |), + M.get_name (| globals, "gas_used_delta" |) + |) in + let target_fee_gas_delta := + BinOp.floor_div (| + M.get_name (| globals, "parent_fee_gas_delta" |), + M.get_name (| globals, "parent_gas_target" |) + |) in + let base_fee_per_gas_delta := + BinOp.floor_div (| + M.get_name (| globals, "target_fee_gas_delta" |), + M.get_name (| globals, "BASE_FEE_MAX_CHANGE_DENOMINATOR" |) + |) in + let expected_base_fee_per_gas := + BinOp.sub (| + M.get_name (| globals, "parent_base_fee_per_gas" |), + M.get_name (| globals, "base_fee_per_gas_delta" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "expected_base_fee_per_gas" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition validate_header : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header"; "parent_header" ] |) in + let _ := Constant.str " + Verifies a block header. + + In order to consider a block's header valid, the logic for the + quantities in the header should match the logic for the block itself. + For example the header timestamp should be greater than the block's parent + timestamp because the block was created *after* the parent block. + Additionally, the block's number should be directly following the parent + block's number since it is the next block in the sequence. + + Parameters + ---------- + header : + Header to check for correctness. + parent_header : + Parent Header of the header to check for correctness + " in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| M.get_field (| M.get_name (| globals, "header" |), "gas_used" |), M.get_field (| M.get_name (| globals, "header" |), "gas_limit" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let expected_base_fee_per_gas := + M.call (| + M.get_name (| globals, "calculate_base_fee_per_gas" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "gas_limit" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "gas_limit" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "gas_used" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "base_fee_per_gas" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_name (| globals, "expected_base_fee_per_gas" |), M.get_field (| M.get_name (| globals, "header" |), "base_fee_per_gas" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt (| M.get_field (| M.get_name (| globals, "header" |), "timestamp" |), M.get_field (| M.get_name (| globals, "parent_header" |), "timestamp" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "number" |), BinOp.add (| + M.get_field (| M.get_name (| globals, "parent_header" |), "number" |), + Constant.int 1 + |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) + ], + make_dict [] + |), Constant.int 32 |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "difficulty" |), Constant.int 0 |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "nonce" |), (* At constant: unsupported node type: Constant *) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "ommers_hash" |), M.get_name (| globals, "EMPTY_OMMER_HASH" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let block_parent_hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "parent_header" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |), M.get_name (| globals, "block_parent_hash" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition check_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx"; "base_fee_per_gas"; "gas_available"; "chain_id" ] |) in + let _ := Constant.str " + Check if the transaction is includable in the block. + + Parameters + ---------- + tx : + The transaction. + base_fee_per_gas : + The block base fee. + gas_available : + The gas remaining in the block. + chain_id : + The ID of the current chain. + + Returns + ------- + sender_address : + The sender of the transaction. + effective_gas_price : + The price to charge for gas when the transaction is executed. + + Raises + ------ + InvalidBlock : + If the transaction is not includable. + " in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_name (| globals, "gas_available" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let sender_address := + M.call (| + M.get_name (| globals, "recover_sender" |), + make_list [ + M.get_name (| globals, "chain_id" |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "FeeMarketTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt_e (| M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |), M.get_field (| M.get_name (| globals, "tx" |), "max_priority_fee_per_gas" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt_e (| M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |), M.get_name (| globals, "base_fee_per_gas" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let priority_fee_per_gas := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_field (| M.get_name (| globals, "tx" |), "max_priority_fee_per_gas" |); + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |), + M.get_name (| globals, "base_fee_per_gas" |) + |) + ], + make_dict [] + |) in + let effective_gas_price := + BinOp.add (| + M.get_name (| globals, "priority_fee_per_gas" |), + M.get_name (| globals, "base_fee_per_gas" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt_e (| M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |), M.get_name (| globals, "base_fee_per_gas" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let effective_gas_price := + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + make_tuple [ M.get_name (| globals, "sender_address" |); M.get_name (| globals, "effective_gas_price" |) ] + |) in + M.pure Constant.None_)). + +Definition make_receipt : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx"; "error"; "cumulative_gas_used"; "logs" ] |) in + let _ := Constant.str " + Make the receipt for a transaction that was executed. + + Parameters + ---------- + tx : + The executed transaction. + error : + Error in the top level frame of the transaction, if any. + cumulative_gas_used : + The total gas used so far in the block after the transaction was + executed. + logs : + The logs produced by the transaction. + + Returns + ------- + receipt : + The receipt for the transaction. + " in + let receipt := + M.call (| + M.get_name (| globals, "Receipt" |), + make_list [], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "AccessListTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + (* At constant: unsupported node type: Constant *), + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "receipt" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "FeeMarketTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + (* At constant: unsupported node type: Constant *), + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "receipt" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "receipt" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition ApplyBodyOutput : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition apply_body : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "block_hashes"; "coinbase"; "block_number"; "base_fee_per_gas"; "block_gas_limit"; "block_time"; "prev_randao"; "transactions"; "chain_id"; "withdrawals" ] |) in + let _ := Constant.str " + Executes a block. + + Many of the contents of a block are stored in data structures called + tries. There is a transactions trie which is similar to a ledger of the + transactions stored in the current block. There is also a receipts trie + which stores the results of executing a transaction, like the post state + and gas used. This function creates and executes the block that is to be + added to the chain. + + Parameters + ---------- + state : + Current account state. + block_hashes : + List of hashes of the previous 256 blocks in the order of + increasing block number. + coinbase : + Address of account which receives block reward and transaction fees. + block_number : + Position of the block within the chain. + base_fee_per_gas : + Base fee per gas of within the block. + block_gas_limit : + Initial amount of gas available for execution in this block. + block_time : + Time the block was produced, measured in seconds since the epoch. + prev_randao : + The previous randao from the beacon chain. + transactions : + Transactions included in the block. + ommers : + Headers of ancestor blocks which are not direct parents (formerly + uncles.) + chain_id : + ID of the executing chain. + withdrawals : + Withdrawals to be processed in the current block. + + Returns + ------- + apply_body_output : `ApplyBodyOutput` + Output of applying the block body to the state. + " in + let gas_available := + M.get_name (| globals, "block_gas_limit" |) in +(* At stmt: unsupported node type: AnnAssign *) +(* At stmt: unsupported node type: AnnAssign *) +(* At stmt: unsupported node type: AnnAssign *) +(* At stmt: unsupported node type: AnnAssign *) + For make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "tx" |) ] in M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.call (| + M.get_name (| globals, "map" |), + make_list [ + M.get_name (| globals, "decode_transaction" |); + M.get_name (| globals, "transactions" |) + ], + make_dict [] + |) + ], + make_dict [] + |) do + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "transactions_trie" |); + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "i" |) + ], + make_dict [] + |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "encode_transaction" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "sender_address" |); M.get_name (| globals, "effective_gas_price" |) ], + M.call (| + M.get_name (| globals, "check_transaction" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "base_fee_per_gas" |); + M.get_name (| globals, "gas_available" |); + M.get_name (| globals, "chain_id" |) + ], + make_dict [] + |) + |) in + let env := + M.call (| + M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |); M.get_name (| globals, "error" |) ], + M.call (| + M.get_name (| globals, "process_transaction" |), + make_list [ + M.get_name (| globals, "env" |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) in + let gas_available := BinOp.sub + M.get_name (| globals, "gas_used" |) + M.get_name (| globals, "gas_used" |) in + let receipt := + M.call (| + M.get_name (| globals, "make_receipt" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "error" |); + BinOp.sub (| + M.get_name (| globals, "block_gas_limit" |), + M.get_name (| globals, "gas_available" |) + |); + M.get_name (| globals, "logs" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "receipts_trie" |); + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "i" |) + ], + make_dict [] + |) + ], + make_dict [] + |); + M.get_name (| globals, "receipt" |) + ], + make_dict [] + |) in + let block_logs := BinOp.add + M.get_name (| globals, "logs" |) + M.get_name (| globals, "logs" |) in + EndFor. + let block_gas_used := + BinOp.sub (| + M.get_name (| globals, "block_gas_limit" |), + M.get_name (| globals, "gas_available" |) + |) in + let block_logs_bloom := + M.call (| + M.get_name (| globals, "logs_bloom" |), + make_list [ + M.get_name (| globals, "block_logs" |) + ], + make_dict [] + |) in + For make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "wd" |) ] in M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "withdrawals" |) + ], + make_dict [] + |) do + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "withdrawals_trie" |); + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "i" |) + ], + make_dict [] + |) + ], + make_dict [] + |); + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "wd" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "process_withdrawal" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "wd" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_field (| M.get_name (| globals, "wd" |), "address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_field (| M.get_name (| globals, "wd" |), "address" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ApplyBodyOutput" |), + make_list [ + M.get_name (| globals, "block_gas_used" |); + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_name (| globals, "transactions_trie" |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_name (| globals, "receipts_trie" |) + ], + make_dict [] + |); + M.get_name (| globals, "block_logs_bloom" |); + M.call (| + M.get_name (| globals, "state_root" |), + make_list [ + M.get_name (| globals, "state" |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_name (| globals, "withdrawals_trie" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition process_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "env"; "tx" ] |) in + let _ := Constant.str " + Execute a transaction against the provided environment. + + This function processes the actions needed to execute a transaction. + It decrements the sender's account after calculating the gas fee and + refunds them the proper amount after execution. Calling contracts, + deploying code, and incrementing nonces are all examples of actions that + happen within this function or from a call made within this function. + + Accounts that are marked for deletion are processed and destroyed after + execution. + + Parameters + ---------- + env : + Environment for the Ethereum Virtual Machine. + tx : + Transaction to execute. + + Returns + ------- + gas_left : `ethereum.base_types.U256` + Remaining gas after execution. + logs : `Tuple[ethereum.blocks.Log, ...]` + Logs generated during execution. + " in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + M.call (| + M.get_name (| globals, "validate_transaction" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let sender := + M.get_field (| M.get_name (| globals, "env" |), "origin" |) in + let sender_account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "FeeMarketTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let max_gas_fee := + BinOp.mult (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let max_gas_fee := + BinOp.mult (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "sender_account" |), "nonce" |), M.get_field (| M.get_name (| globals, "tx" |), "nonce" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt_e (| M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), BinOp.add (| + M.get_name (| globals, "max_gas_fee" |), + M.get_field (| M.get_name (| globals, "tx" |), "value" |) + |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "sender_account" |), "code" |), M.call (| + M.get_name (| globals, "bytearray" |), + make_list [], + make_dict [] + |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let effective_gas_fee := + BinOp.mult (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "env" |), "gas_price" |) + |) in + let gas := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.call (| + M.get_name (| globals, "calculate_intrinsic_cost" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) in + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |) in + let sender_balance_after_gas_fee := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), + M.get_name (| globals, "effective_gas_fee" |) + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |); + M.get_name (| globals, "sender_balance_after_gas_fee" |) + ], + make_dict [] + |) in + let preaccessed_addresses := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let preaccessed_storage_keys := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "preaccessed_addresses" |), "add" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + make_tuple [ M.get_name (| globals, "AccessListTransaction" |); M.get_name (| globals, "FeeMarketTransaction" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + For make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "keys" |) ] in M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "preaccessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "key" |) in M.get_name (| globals, "keys" |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "preaccessed_storage_keys" |), "add" |), + make_list [ + make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "key" |) ] + ], + make_dict [] + |) in + EndFor. + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let message := + M.call (| + M.get_name (| globals, "prepare_message" |), + make_list [ + M.get_name (| globals, "sender" |); + M.get_field (| M.get_name (| globals, "tx" |), "to" |); + M.get_field (| M.get_name (| globals, "tx" |), "value" |); + M.get_field (| M.get_name (| globals, "tx" |), "data" |); + M.get_name (| globals, "gas" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let output := + M.call (| + M.get_name (| globals, "process_message_call" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let gas_used := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "output" |), "gas_left" |) + |) in + let gas_refund := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + BinOp.floor_div (| + M.get_name (| globals, "gas_used" |), + Constant.int 5 + |); + M.get_field (| M.get_name (| globals, "output" |), "refund_counter" |) + ], + make_dict [] + |) in + let gas_refund_amount := + BinOp.mult (| + BinOp.add (| + M.get_field (| M.get_name (| globals, "output" |), "gas_left" |), + M.get_name (| globals, "gas_refund" |) + |), + M.get_field (| M.get_name (| globals, "env" |), "gas_price" |) + |) in + let priority_fee_per_gas := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "env" |), "gas_price" |), + M.get_field (| M.get_name (| globals, "env" |), "base_fee_per_gas" |) + |) in + let transaction_fee := + BinOp.mult (| + BinOp.sub (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "output" |), "gas_left" |) + |), + M.get_name (| globals, "gas_refund" |) + |), + M.get_name (| globals, "priority_fee_per_gas" |) + |) in + let total_gas_used := + BinOp.sub (| + M.get_name (| globals, "gas_used" |), + M.get_name (| globals, "gas_refund" |) + |) in + let sender_balance_after_refund := + BinOp.add (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |), "balance" |), + M.get_name (| globals, "gas_refund_amount" |) + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |); + M.get_name (| globals, "sender_balance_after_refund" |) + ], + make_dict [] + |) in + let coinbase_balance_after_mining_fee := + BinOp.add (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |), "balance" |), + M.get_name (| globals, "transaction_fee" |) + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| M.get_name (| globals, "coinbase_balance_after_mining_fee" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |); + M.get_name (| globals, "coinbase_balance_after_mining_fee" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "accounts_to_delete" |) do + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + EndFor. + For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "touched_accounts" |) do + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.return_ (| + make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |); M.get_field (| M.get_name (| globals, "output" |), "error" |) ] + |) in + M.pure Constant.None_)). + +Definition validate_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Verifies a transaction. + + The gas in a transaction gets used to pay for the intrinsic cost of + operations, therefore if there is insufficient gas then it would not + be possible to execute a transaction and it will be declared invalid. + + Additionally, the nonce of a transaction must not equal or exceed the + limit defined in `EIP-2681 `_. + In practice, defining the limit as ``2**64-1`` has no impact because + sending ``2**64-1`` transactions is improbable. It's not strictly + impossible though, ``2**64-1`` transactions is the entire capacity of the + Ethereum blockchain at 2022 gas limits for a little over 22 years. + + Parameters + ---------- + tx : + Transaction to validate. + + Returns + ------- + verified : `bool` + True if the transaction can be executed, or False otherwise. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.call (| + M.get_name (| globals, "calculate_intrinsic_cost" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |), M.get_field (| M.get_name (| globals, "tx" |), "gas" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_field (| M.get_name (| globals, "tx" |), "nonce" |), BinOp.sub (| + BinOp.pow (| + Constant.int 2, + Constant.int 64 + |), + Constant.int 1 + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "tx" |), "to" |), M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.gt (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "tx" |), "data" |) + ], + make_dict [] + |), BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "MAX_CODE_SIZE" |) + |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + Constant.bool true + |) in + M.pure Constant.None_)). + +Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Calculates the gas that is charged before execution is started. + + The intrinsic cost of the transaction is charged before execution has + begun. Functions/operations in the EVM cost money to execute so this + intrinsic cost is for the operations that need to be paid for as part of + the transaction. Data transfer, for example, is part of this intrinsic + cost. It costs ether to send data over the wire and that ether is + accounted for in the intrinsic cost calculated in this function. This + intrinsic cost must be calculated and paid for before execution in order + for all operations to be implemented. + + Parameters + ---------- + tx : + Transaction to compute the intrinsic cost of. + + Returns + ------- + verified : `ethereum.base_types.Uint` + The intrinsic cost of the transaction. + " in + let data_cost := + Constant.int 0 in + For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "byte" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + M.pure Constant.None_ + )) |) in + EndFor. + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_name (| globals, "tx" |), "to" |), M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let create_cost := + BinOp.add (| + M.get_name (| globals, "TX_CREATE_COST" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.call (| + M.get_name (| globals, "init_code_cost" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "tx" |), "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let create_cost := + Constant.int 0 in + M.pure Constant.None_ + )) |) in + let access_list_cost := + Constant.int 0 in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + make_tuple [ M.get_name (| globals, "AccessListTransaction" |); M.get_name (| globals, "FeeMarketTransaction" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + For make_tuple [ M.get_name (| globals, "_address" |); M.get_name (| globals, "keys" |) ] in M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) do + let access_list_cost := BinOp.add + M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) + M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) in + let access_list_cost := BinOp.add + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "keys" |) + ], + make_dict [] + |), + M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) + |) + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "keys" |) + ], + make_dict [] + |), + M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) + |) in + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.add (| + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "TX_BASE_COST" |), + M.get_name (| globals, "data_cost" |) + |), + M.get_name (| globals, "create_cost" |) + |), + M.get_name (| globals, "access_list_cost" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition recover_sender : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "chain_id"; "tx" ] |) in + let _ := Constant.str " + Extracts the sender address from a transaction. + + The v, r, and s values are the three parts that make up the signature + of a transaction. In order to recover the sender of a transaction the two + components needed are the signature (``v``, ``r``, and ``s``) and the + signing hash of the transaction. The sender's public key can be obtained + with these two values and therefore the sender address can be retrieved. + + Parameters + ---------- + tx : + Transaction of interest. + chain_id : + ID of the executing chain. + + Returns + ------- + sender : `ethereum.fork_types.Address` + The address of the account that signed the transaction. + " in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "r" |); M.get_name (| globals, "s" |) ], + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "r" |); M.get_field (| M.get_name (| globals, "tx" |), "s" |) ] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.and (| + Compare.lt (| Constant.int 0, M.get_name (| globals, "r" |) |), + ltac:(M.monadic ( + Compare.lt (| M.get_name (| globals, "r" |), M.get_name (| globals, "SECP256K1N" |) |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.and (| + Compare.lt (| Constant.int 0, M.get_name (| globals, "s" |) |), + ltac:(M.monadic ( + Compare.lt_e (| M.get_name (| globals, "s" |), BinOp.floor_div (| + M.get_name (| globals, "SECP256K1N" |), + Constant.int 2 + |) |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "LegacyTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let v := + M.get_field (| M.get_name (| globals, "tx" |), "v" |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.eq (| M.get_name (| globals, "v" |), Constant.int 27 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "v" |), Constant.int 28 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + BinOp.sub (| + M.get_name (| globals, "v" |), + Constant.int 27 + |); + M.call (| + M.get_name (| globals, "signing_hash_pre155" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.or (| + Compare.eq (| M.get_name (| globals, "v" |), BinOp.add (| + Constant.int 35, + BinOp.mult (| + M.get_name (| globals, "chain_id" |), + Constant.int 2 + |) + |) |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "v" |), BinOp.add (| + Constant.int 36, + BinOp.mult (| + M.get_name (| globals, "chain_id" |), + Constant.int 2 + |) + |) |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + BinOp.sub (| + BinOp.sub (| + M.get_name (| globals, "v" |), + Constant.int 35 + |), + BinOp.mult (| + M.get_name (| globals, "chain_id" |), + Constant.int 2 + |) + |); + M.call (| + M.get_name (| globals, "signing_hash_155" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "chain_id" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "AccessListTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + M.get_field (| M.get_name (| globals, "tx" |), "y_parity" |); + M.call (| + M.get_name (| globals, "signing_hash_2930" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "FeeMarketTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + M.get_field (| M.get_name (| globals, "tx" |), "y_parity" |); + M.call (| + M.get_name (| globals, "signing_hash_1559" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_subscript (| M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), Constant.int 12:Constant.int 32 |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition signing_hash_pre155 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Compute the hash of a transaction used in a legacy (pre EIP 155) signature. + + Parameters + ---------- + tx : + Transaction of interest. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the transaction. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "nonce" |); M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |); M.get_field (| M.get_name (| globals, "tx" |), "gas" |); M.get_field (| M.get_name (| globals, "tx" |), "to" |); M.get_field (| M.get_name (| globals, "tx" |), "value" |); M.get_field (| M.get_name (| globals, "tx" |), "data" |) ] + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition signing_hash_155 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx"; "chain_id" ] |) in + let _ := Constant.str " + Compute the hash of a transaction used in a EIP 155 signature. + + Parameters + ---------- + tx : + Transaction of interest. + chain_id : + The id of the current chain. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the transaction. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "nonce" |); M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |); M.get_field (| M.get_name (| globals, "tx" |), "gas" |); M.get_field (| M.get_name (| globals, "tx" |), "to" |); M.get_field (| M.get_name (| globals, "tx" |), "value" |); M.get_field (| M.get_name (| globals, "tx" |), "data" |); M.get_name (| globals, "chain_id" |); M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) ] + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition signing_hash_2930 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Compute the hash of a transaction used in a EIP 2930 signature. + + Parameters + ---------- + tx : + Transaction of interest. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the transaction. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + BinOp.add (| + (* At constant: unsupported node type: Constant *), + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "chain_id" |); M.get_field (| M.get_name (| globals, "tx" |), "nonce" |); M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |); M.get_field (| M.get_name (| globals, "tx" |), "gas" |); M.get_field (| M.get_name (| globals, "tx" |), "to" |); M.get_field (| M.get_name (| globals, "tx" |), "value" |); M.get_field (| M.get_name (| globals, "tx" |), "data" |); M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) ] + ], + make_dict [] + |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition signing_hash_1559 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Compute the hash of a transaction used in a EIP 1559 signature. + + Parameters + ---------- + tx : + Transaction of interest. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the transaction. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + BinOp.add (| + (* At constant: unsupported node type: Constant *), + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "chain_id" |); M.get_field (| M.get_name (| globals, "tx" |), "nonce" |); M.get_field (| M.get_name (| globals, "tx" |), "max_priority_fee_per_gas" |); M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |); M.get_field (| M.get_name (| globals, "tx" |), "gas" |); M.get_field (| M.get_name (| globals, "tx" |), "to" |); M.get_field (| M.get_name (| globals, "tx" |), "value" |); M.get_field (| M.get_name (| globals, "tx" |), "data" |); M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) ] + ], + make_dict [] + |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition compute_header_hash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header" ] |) in + let _ := Constant.str " + Computes the hash of a block header. + + The header hash of a block is the canonical hash that is used to refer + to a specific block and completely distinguishes a block from another. + + ``keccak256`` is a function that produces a 256 bit hash of any input. + It also takes in any number of bytes as an input and produces a single + hash for them. A hash is a completely unique output for a single input. + So an input corresponds to one unique hash that can be used to identify + the input exactly. + + Prior to using the ``keccak256`` hash function, the header must be + encoded using the Recursive-Length Prefix. See :ref:`rlp`. + RLP encoding the header converts it into a space-efficient format that + allows for easy transfer of data between nodes. The purpose of RLP is to + encode arbitrarily nested arrays of binary data, and RLP is the primary + encoding method used to serialize objects in Ethereum's execution layer. + The only purpose of RLP is to encode structure; encoding specific data + types (e.g. strings, floats) is left up to higher-order protocols. + + Parameters + ---------- + header : + Header of interest. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the header. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "header" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition check_gas_limit : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "gas_limit"; "parent_gas_limit" ] |) in + let _ := Constant.str " + Validates the gas limit for a block. + + The bounds of the gas limit, ``max_adjustment_delta``, is set as the + quotient of the parent block's gas limit and the + ``GAS_LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is + passed through as a parameter is greater than or equal to the *sum* of + the parent's gas and the adjustment delta then the limit for gas is too + high and fails this function's check. Similarly, if the limit is less + than or equal to the *difference* of the parent's gas and the adjustment + delta *or* the predefined ``GAS_LIMIT_MINIMUM`` then this function's + check fails because the gas limit doesn't allow for a sufficient or + reasonable amount of gas to be used on a block. + + Parameters + ---------- + gas_limit : + Gas limit to validate. + + parent_gas_limit : + Gas limit of the parent block. + + Returns + ------- + check : `bool` + True if gas limit constraints are satisfied, False otherwise. + " in + let max_adjustment_delta := + BinOp.floor_div (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "gas_limit" |), BinOp.add (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| M.get_name (| globals, "gas_limit" |), BinOp.sub (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "gas_limit" |), M.get_name (| globals, "GAS_LIMIT_MINIMUM" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + Constant.bool true + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/fork_types.v b/CoqOfPython/ethereum/shanghai/fork_types.v new file mode 100644 index 0000000..d12953d --- /dev/null +++ b/CoqOfPython/ethereum/shanghai/fork_types.v @@ -0,0 +1,102 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Types +^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Types re-used throughout the specification, which are specific to Ethereum. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes20 : + IsGlobalAlias globals base_types.globals "Bytes20". +Axiom base_types_Bytes256 : + IsGlobalAlias globals base_types.globals "Bytes256". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require crypto.hash. +Axiom crypto_hash_Hash32 : + IsGlobalAlias globals crypto.hash.globals "Hash32". +Axiom crypto_hash_keccak256 : + IsGlobalAlias globals crypto.hash.globals "keccak256". + +Definition Address : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Bytes20" |) +)). + +Definition Root : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Hash32" |) +)). + +Definition Bloom : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Bytes256" |) +)). + +Definition Account : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition EMPTY_ACCOUNT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Account" |), + make_list [], + make_dict [] + |) +)). + +Definition encode_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "raw_account_data"; "storage_root" ] |) in + let _ := Constant.str " + Encode `Account` dataclass. + + Storage is not stored in the `Account` dataclass, so `Accounts` cannot be + encoded with providing a storage root. + " in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "raw_account_data" |), "nonce" |); M.get_field (| M.get_name (| globals, "raw_account_data" |), "balance" |); M.get_name (| globals, "storage_root" |); M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_field (| M.get_name (| globals, "raw_account_data" |), "code" |) + ], + make_dict [] + |) ] + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/state.v b/CoqOfPython/ethereum/shanghai/state.v new file mode 100644 index 0000000..a950e08 --- /dev/null +++ b/CoqOfPython/ethereum/shanghai/state.v @@ -0,0 +1,1179 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +State +^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The state contains all information that is preserved between transactions. + +It consists of a main account trie and storage tries for each contract. + +There is a distinction between an account that does not exist and +`EMPTY_ACCOUNT`. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_field : + IsGlobalAlias globals dataclasses.globals "field". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_modify : + IsGlobalAlias globals ethereum.base_types.globals "modify". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require blocks. +Axiom blocks_Withdrawal : + IsGlobalAlias globals blocks.globals "Withdrawal". + +Require fork_types. +Axiom fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". +Axiom fork_types_Account : + IsGlobalAlias globals fork_types.globals "Account". +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Require trie. +Axiom trie_EMPTY_TRIE_ROOT : + IsGlobalAlias globals trie.globals "EMPTY_TRIE_ROOT". +Axiom trie_Trie : + IsGlobalAlias globals trie.globals "Trie". +Axiom trie_copy_trie : + IsGlobalAlias globals trie.globals "copy_trie". +Axiom trie_root : + IsGlobalAlias globals trie.globals "root". +Axiom trie_trie_get : + IsGlobalAlias globals trie.globals "trie_get". +Axiom trie_trie_set : + IsGlobalAlias globals trie.globals "trie_set". + +Definition State : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition close_state : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Free resources held by the state. Used by optimized implementations to + release file descriptors. + " in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) |) in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |) in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |) |) in + M.pure Constant.None_)). + +Definition begin_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Start a state transaction. + + Transactions are entirely implicit and can be nested. It is not possible to + calculate the state root during a transaction. + + Parameters + ---------- + state : State + The state. + " in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), "append" |), + make_list [ + make_tuple [ M.call (| + M.get_name (| globals, "copy_trie" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) + ], + make_dict [] + |); {M.get_name (| globals, "k" |): M.call (| + M.get_name (| globals, "copy_trie" |), + make_list [ + M.get_name (| globals, "t" |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)} ] + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition commit_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Commit a state transaction. + + Parameters + ---------- + state : State + The state. + " in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), "pop" |), + make_list [], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "clear" |), + make_list [], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition rollback_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Rollback a state transaction, resetting the state to the point when the + corresponding `start_transaction()` call was made. + + Parameters + ---------- + state : State + The state. + " in + let _ := M.assign (| + make_tuple [ M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) ], + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), "pop" |), + make_list [], + make_dict [] + |) + |) in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "clear" |), + make_list [], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition get_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Get the `Account` object at an address. Returns `EMPTY_ACCOUNT` if there + is no account at the address. + + Use `get_account_optional()` if you care about the difference between a + non-existent account and `EMPTY_ACCOUNT`. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address to lookup. + + Returns + ------- + account : `Account` + Account at address. + " in + let account := + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "account" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "account" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "EMPTY_ACCOUNT" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition get_account_optional : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Get the `Account` object at an address. Returns `None` (rather than + `EMPTY_ACCOUNT`) if there is no account at the address. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address to lookup. + + Returns + ------- + account : `Account` + Account at address. + " in + let account := + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "account" |) + |) in + M.pure Constant.None_)). + +Definition set_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "account" ] |) in + let _ := Constant.str " + Set the `Account` object at an address. Setting to `None` deletes + the account (but not its storage, see `destroy_account()`). + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address to set. + account : `Account` + Account to set at address. + " in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "account" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition destroy_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Completely remove the account at `address` and all of its storage. + + This function is made available exclusively for the `SELFDESTRUCT` + opcode. It is expected that `SELFDESTRUCT` will be disabled in a future + hardfork and this function will be removed. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of account to destroy. + " in + let _ := M.call (| + M.get_name (| globals, "destroy_storage" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + Constant.None_ + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition destroy_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Completely remove the storage at `address`. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of account whose storage is to be deleted. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition mark_account_created : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Mark an account as having been created in the current transaction. + This information is used by `get_storage_original()` to handle an obscure + edgecase. + + The marker is not removed even if the account creation reverts. Since the + account cannot have had code prior to its creation and can't call + `get_storage_original()`, this is harmless. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of the account that has been created. + " in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition get_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "key" ] |) in + let _ := Constant.str " + Get a value at a storage key on an account. Returns `U256(0)` if the + storage key has not been set previously. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of the account. + key : `Bytes` + Key to lookup. + + Returns + ------- + value : `U256` + Value at the key. + " in + let trie := + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let _ := M.assert (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "U256" |) + ], + make_dict [] + |) |) in + let _ := M.return_ (| + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_)). + +Definition set_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "key"; "value" ] |) in + let _ := Constant.str " + Set a value at a storage key on an account. Setting to `U256(0)` deletes + the key. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of the account. + key : `Bytes` + Key to set. + value : `U256` + Value to set at the key. + " in + let _ := M.assert (| Compare.is_not (| M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), Constant.None_ |) |) in + let trie := + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let trie := + M.call (| + M.get_name (| globals, "Trie" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), + M.get_name (| globals, "trie" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "key" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), {} |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition storage_root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Calculate the storage root of an account. + + Parameters + ---------- + state: + The state + address : + Address of the account. + + Returns + ------- + root : `Root` + Storage root of the account. + " in + let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "EMPTY_TRIE_ROOT" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition state_root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Calculate the state root. + + Parameters + ---------- + state: + The current state. + + Returns + ------- + root : `Root` + The state root. + " in + let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition account_exists : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account exists in the state trie + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + account_exists : `bool` + True if account exists in the state trie, False otherwise + " in + let _ := M.return_ (| + Compare.is_not (| M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), Constant.None_ |) + |) in + M.pure Constant.None_)). + +Definition account_has_code_or_nonce : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account has non zero nonce or non empty code + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + has_code_or_nonce : `bool` + True if if an account has non zero nonce or non empty code, + False otherwise. + " in + let account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + BoolOp.or (| + Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |) + )) + |) + |) in + M.pure Constant.None_)). + +Definition is_account_empty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account has zero nonce, empty code and zero balance. + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + is_empty : `bool` + True if if an account has zero nonce, empty code and zero balance, + False otherwise. + " in + let account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + ltac:(M.monadic ( + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + )) + |) + )) + |) + |) in + M.pure Constant.None_)). + +Definition account_exists_and_is_empty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account exists and has zero nonce, empty code and zero + balance. + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + exists_and_is_empty : `bool` + True if an account exists and has zero nonce, empty code and zero + balance, False otherwise. + " in + let account := + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + BoolOp.and (| + Compare.is_not (| M.get_name (| globals, "account" |), Constant.None_ |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + ltac:(M.monadic ( + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + )) + |) + )) + |) + )) + |) + |) in + M.pure Constant.None_)). + +Definition is_account_alive : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Check whether is an account is both in the state and non empty. + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + is_alive : `bool` + True if the account is alive. + " in + let account := + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "account" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + UnOp.not (| BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + ltac:(M.monadic ( + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + )) + |) + )) + |) |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition modify_state : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "f" ] |) in + let _ := Constant.str " + Modify an `Account` in the `State`. + " in + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.call (| + M.get_name (| globals, "modify" |), + make_list [ + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |); + M.get_name (| globals, "f" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition move_ether : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "sender_address"; "recipient_address"; "amount" ] |) in + let _ := Constant.str " + Move funds between accounts. + " in +(* At stmt: unsupported node type: FunctionDef *) +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "sender_address" |); + M.get_name (| globals, "reduce_sender_balance" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "recipient_address" |); + M.get_name (| globals, "increase_recipient_balance" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition process_withdrawal : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "wd" ] |) in + let _ := Constant.str " + Increase the balance of the withdrawing account. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_field (| M.get_name (| globals, "wd" |), "address" |); + M.get_name (| globals, "increase_recipient_balance" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition set_account_balance : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "amount" ] |) in + let _ := Constant.str " + Sets the balance of an account. + + Parameters + ---------- + state: + The current state. + + address: + Address of the account whose nonce needs to be incremented. + + amount: + The amount that needs to set in balance. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "set_balance" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition touch_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Initializes an account to state. + + Parameters + ---------- + state: + The current state. + + address: + The address of the account that need to initialised. + " in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "account_exists" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "EMPTY_ACCOUNT" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition increment_nonce : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Increments the nonce of an account. + + Parameters + ---------- + state: + The current state. + + address: + Address of the account whose nonce needs to be incremented. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "increase_nonce" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition set_code : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "code" ] |) in + let _ := Constant.str " + Sets Account code. + + Parameters + ---------- + state: + The current state. + + address: + Address of the account whose code needs to be update. + + code: + The bytecode that needs to be set. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "write_code" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition get_storage_original : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "key" ] |) in + let _ := Constant.str " + Get the original value in a storage slot i.e. the value before the current + transaction began. This function reads the value from the snapshots taken + before executing the transaction. + + Parameters + ---------- + state: + The current state. + address: + Address of the account to read the value from. + key: + Key of the storage slot. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "_" |); M.get_name (| globals, "original_trie" |) ], + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), Constant.int 0 |) + |) in + let original_account_trie := + M.call (| + M.get_field (| M.get_name (| globals, "original_trie" |), "get" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "original_account_trie" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let original_value := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let original_value := + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_name (| globals, "original_account_trie" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.assert (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "original_value" |); + M.get_name (| globals, "U256" |) + ], + make_dict [] + |) |) in + let _ := M.return_ (| + M.get_name (| globals, "original_value" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/transactions.v b/CoqOfPython/ethereum/shanghai/transactions.v new file mode 100644 index 0000000..56996d9 --- /dev/null +++ b/CoqOfPython/ethereum/shanghai/transactions.v @@ -0,0 +1,274 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Transactions are atomic units of work created externally to Ethereum and +submitted to be executed. If Ethereum is viewed as a state machine, +transactions are the events that move between states. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U64 : + IsGlobalAlias globals base_types.globals "U64". +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes0 : + IsGlobalAlias globals base_types.globals "Bytes0". +Axiom base_types_Bytes32 : + IsGlobalAlias globals base_types.globals "Bytes32". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require exceptions. +Axiom exceptions_InvalidBlock : + IsGlobalAlias globals exceptions.globals "InvalidBlock". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( + Constant.int 21000 +)). + +Definition TX_DATA_COST_PER_NON_ZERO : Value.t := M.run ltac:(M.monadic ( + Constant.int 16 +)). + +Definition TX_DATA_COST_PER_ZERO : Value.t := M.run ltac:(M.monadic ( + Constant.int 4 +)). + +Definition TX_CREATE_COST : Value.t := M.run ltac:(M.monadic ( + Constant.int 32000 +)). + +Definition TX_ACCESS_LIST_ADDRESS_COST : Value.t := M.run ltac:(M.monadic ( + Constant.int 2400 +)). + +Definition TX_ACCESS_LIST_STORAGE_KEY_COST : Value.t := M.run ltac:(M.monadic ( + Constant.int 1900 +)). + +Definition LegacyTransaction : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition AccessListTransaction : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition FeeMarketTransaction : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Transaction : Value.t := M.run ltac:(M.monadic ( + M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "AccessListTransaction" |); M.get_name (| globals, "FeeMarketTransaction" |) ] |) +)). + +Definition encode_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Encode a transaction. Needed because non-legacy transactions aren't RLP. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "LegacyTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "tx" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "AccessListTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + (* At constant: unsupported node type: Constant *), + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "FeeMarketTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + (* At constant: unsupported node type: Constant *), + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "Exception" |), + make_list [ + (* At expr: unsupported node type: JoinedStr *) + ], + make_dict [] + |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition decode_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Decode a transaction. Needed because non-legacy transactions aren't RLP. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), Constant.int 1 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), + make_list [ + M.get_name (| globals, "AccessListTransaction" |); + M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 1:(* At expr: unsupported node type: NoneType *) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), Constant.int 2 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), + make_list [ + M.get_name (| globals, "FeeMarketTransaction" |); + M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 1:(* At expr: unsupported node type: NoneType *) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidBlock" |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "tx" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/trie.v b/CoqOfPython/ethereum/shanghai/trie.v new file mode 100644 index 0000000..fcb4569 --- /dev/null +++ b/CoqOfPython/ethereum/shanghai/trie.v @@ -0,0 +1,1360 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +State Trie +^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The state trie is the structure responsible for storing +`.fork_types.Account` objects. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_field : + IsGlobalAlias globals dataclasses.globals "field". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". +Axiom typing_Generic : + IsGlobalAlias globals typing.globals "Generic". +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Mapping : + IsGlobalAlias globals typing.globals "Mapping". +Axiom typing_MutableMapping : + IsGlobalAlias globals typing.globals "MutableMapping". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Sequence : + IsGlobalAlias globals typing.globals "Sequence". +Axiom typing_TypeVar : + IsGlobalAlias globals typing.globals "TypeVar". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". +Axiom typing_cast : + IsGlobalAlias globals typing.globals "cast". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.paris. +Axiom ethereum_paris_trie : + IsGlobalAlias globals ethereum.paris.globals "trie". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require ethereum.utils.hexadecimal. +Axiom ethereum_utils_hexadecimal_hex_to_bytes : + IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require blocks. +Axiom blocks_Receipt : + IsGlobalAlias globals blocks.globals "Receipt". +Axiom blocks_Withdrawal : + IsGlobalAlias globals blocks.globals "Withdrawal". + +Require fork_types. +Axiom fork_types_Account : + IsGlobalAlias globals fork_types.globals "Account". +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". +Axiom fork_types_encode_account : + IsGlobalAlias globals fork_types.globals "encode_account". + +Require transactions. +Axiom transactions_LegacyTransaction : + IsGlobalAlias globals transactions.globals "LegacyTransaction". + +Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Root" |), + make_list [ + M.call (| + M.get_name (| globals, "hex_to_bytes" |), + make_list [ + Constant.str "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" + ], + make_dict [] + |) + ], + make_dict [] + |) +)). + +Definition Node : Value.t := M.run ltac:(M.monadic ( + M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Bytes" |); M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |); M.get_name (| globals, "Withdrawal" |); Constant.None_ ] |) +)). + +Definition K : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "TypeVar" |), + make_list [ + Constant.str "K" + ], + make_dict [] + |) +)). + +Definition V : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "TypeVar" |), + make_list [ + Constant.str "V"; + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Account" |) |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Bytes" |) |); + M.get_name (| globals, "Bytes" |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Bytes" |) ] |) |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Bytes" |) ] |) |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Withdrawal" |); M.get_name (| globals, "Bytes" |) ] |) |); + M.get_name (| globals, "Uint" |); + M.get_name (| globals, "U256" |) + ], + make_dict [] + |) +)). + +Definition LeafNode : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition ExtensionNode : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition BranchNode : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition InternalNode : Value.t := M.run ltac:(M.monadic ( + M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LeafNode" |); M.get_name (| globals, "ExtensionNode" |); M.get_name (| globals, "BranchNode" |) ] |) +)). + +Definition encode_internal_node : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "node" ] |) in + let _ := Constant.str " + Encodes a Merkle Trie node into its RLP form. The RLP will then be + serialized into a `Bytes` and hashed unless it is less that 32 bytes + when serialized. + + This function also accepts `None`, representing the absence of a node, + which is encoded to `b""""""`. + + Parameters + ---------- + node : Optional[InternalNode] + The node to encode. + + Returns + ------- + encoded : `rlp.RLP` + The node encoded as RLP. + " in +(* At stmt: unsupported node type: AnnAssign *) + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "node" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let unencoded := + (* At constant: unsupported node type: Constant *) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "LeafNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "rest_of_key" |); + Constant.bool true + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "ExtensionNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "key_segment" |); + Constant.bool false + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "BranchNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + BinOp.add (| + M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "value" |) + ] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "AssertionError" |), + make_list [ + (* At expr: unsupported node type: JoinedStr *) + ], + make_dict [] + |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let encoded := + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "unencoded" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded" |) + ], + make_dict [] + |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "unencoded" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "encoded" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition encode_node : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "node"; "storage_root" ] |) in + let _ := Constant.str " + Encode a Node for storage in the Merkle Trie. + + Currently mostly an unimplemented stub. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "storage_root" |), Constant.None_ |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "encode_account" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "storage_root" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Withdrawal" |); M.get_name (| globals, "U256" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "cast" |), + make_list [ + M.get_field (| M.get_name (| globals, "rlp" |), "RLP" |); + M.get_name (| globals, "node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "node" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "previous_trie" |), "encode_node" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "storage_root" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition Trie : Value.t := + builtins.make_klass + [(* At base: unsupported node type: Subscript *)] + [ + + ] + [ + + ]. + +Definition copy_trie : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie" ] |) in + let _ := Constant.str " + Create a copy of `trie`. Since only frozen objects may be stored in tries, + the contents are reused. + + Parameters + ---------- + trie: `Trie` + Trie to copy. + + Returns + ------- + new_trie : `Trie[K, V]` + A copy of the trie. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Trie" |), + make_list [ + M.get_field (| M.get_name (| globals, "trie" |), "secured" |); + M.get_field (| M.get_name (| globals, "trie" |), "default" |); + M.call (| + M.get_field (| M.get_name (| globals, "copy" |), "copy" |), + make_list [ + M.get_field (| M.get_name (| globals, "trie" |), "_data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition trie_set : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "key"; "value" ] |) in + let _ := Constant.str " + Stores an item in a Merkle Trie. + + This method deletes the key if `value == trie.default`, because the Merkle + Trie represents the default value by omitting it from the trie. + + Parameters + ---------- + trie: `Trie` + Trie to store in. + key : `Bytes` + Key to lookup. + value : `V` + Node to insert at `key`. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "value" |), M.get_field (| M.get_name (| globals, "trie" |), "default" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "key" |), M.get_field (| M.get_name (| globals, "trie" |), "_data" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition trie_get : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "key" ] |) in + let _ := Constant.str " + Gets an item from the Merkle Trie. + + This method returns `trie.default` if the key is missing. + + Parameters + ---------- + trie: + Trie to lookup in. + key : + Key to lookup. + + Returns + ------- + node : `V` + Node at `key` in the trie. + " in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "get" |), + make_list [ + M.get_name (| globals, "key" |); + M.get_field (| M.get_name (| globals, "trie" |), "default" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition common_prefix_length : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "a"; "b" ] |) in + let _ := Constant.str " + Find the longest common prefix of two sequences. + " in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + ], + make_dict [] + |) do + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| M.get_name (| globals, "i" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition nibble_list_to_compact : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "x"; "is_leaf" ] |) in + let _ := Constant.str " + Compresses nibble-list into a standard byte array with a flag. + + A nibble-list is a list of byte values no greater than `15`. The flag is + encoded in high nibble of the highest byte. The flag nibble can be broken + down into two two-bit flags. + + Highest nibble:: + + +---+---+----------+--------+ + | _ | _ | is_leaf | parity | + +---+---+----------+--------+ + 3 2 1 0 + + + The lowest bit of the nibble encodes the parity of the length of the + remaining nibbles -- `0` when even and `1` when odd. The second lowest bit + is used to distinguish leaf and extension nodes. The other two bits are not + used. + + Parameters + ---------- + x : + Array of nibbles. + is_leaf : + True if this is part of a leaf node, or false if it is an extension + node. + + Returns + ------- + compressed : `bytearray` + Compact byte array. + " in + let compact := + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + Constant.int 2 + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.mult (| + Constant.int 16, + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "is_leaf" |) + |) + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + BinOp.add (| + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "is_leaf" |) + |), + Constant.int 1 + |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), Constant.int 0 |) + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 1; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + M.get_name (| globals, "compact" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition bytes_to_nibble_list : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "bytes_" ] |) in + let _ := Constant.str " + Converts a `Bytes` into to a sequence of nibbles (bytes with value < 16). + + Parameters + ---------- + bytes_: + The `Bytes` to convert. + + Returns + ------- + nibble_list : `Bytes` + The `Bytes` in nibble-list format. + " in + let nibble_list := + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [ + BinOp.mult (| + Constant.int 2, + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "bytes_" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + For make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ] in M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "bytes_" |) + ], + make_dict [] + |) do + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |) |), + BinOp.r_shift (| + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 240 + |), + Constant.int 4 + |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |), + Constant.int 1 + |) |), + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 15 + |) + |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + M.get_name (| globals, "nibble_list" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition _prepare_trie : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "get_storage_root" ] |) in + let _ := Constant.str " + Prepares the trie for root calculation. Removes values that are empty, + hashes the keys (if `secured == True`) and encodes all the nodes. + + Parameters + ---------- + trie : + The `Trie` to prepare. + get_storage_root : + Function to get the storage root of an account. Needed to encode + `Account` objects. + + Returns + ------- + out : `Mapping[ethereum.base_types.Bytes, Node]` + Object with keys mapped to nibble-byte form. + " in +(* At stmt: unsupported node type: AnnAssign *) + For make_tuple [ M.get_name (| globals, "preimage" |); M.get_name (| globals, "value" |) ] in M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "items" |), + make_list [], + make_dict [] + |) do + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in + let address := + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |); + M.call (| + M.get_name (| globals, "get_storage_root" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_eq (| M.get_name (| globals, "encoded_value" |), (* At constant: unsupported node type: Constant *) |); + M.get_name (| globals, "AssertionError" |) + ], + make_dict [] + |) in +(* At stmt: unsupported node type: AnnAssign *) + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "trie" |), "secured" |), + (* then *) + ltac:(M.monadic ( + let key := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let key := + M.get_name (| globals, "preimage" |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "mapped" |), M.call (| + M.get_name (| globals, "bytes_to_nibble_list" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |) |), + M.get_name (| globals, "encoded_value" |) + |) in + EndFor. + let _ := M.return_ (| + M.get_name (| globals, "mapped" |) + |) in + M.pure Constant.None_)). + +Definition root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "get_storage_root" ] |) in + let _ := Constant.str " + Computes the root of a modified merkle patricia trie (MPT). + + Parameters + ---------- + trie : + `Trie` to get the root of. + get_storage_root : + Function to get the storage root of an account. Needed to encode + `Account` objects. + + + Returns + ------- + root : `.fork_types.Root` + MPT root of the underlying key-value pairs. + " in + let obj := + M.call (| + M.get_name (| globals, "_prepare_trie" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "get_storage_root" |) + ], + make_dict [] + |) in + let root_node := + M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_name (| globals, "obj" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assert (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "root_node" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Root" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition patricialize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "obj"; "level" ] |) in + let _ := Constant.str " + Structural composition function. + + Used to recursively patricialize and merkleize a dictionary. Includes + memoization of the tree structure and hashes. + + Parameters + ---------- + obj : + Underlying trie key-value pairs, with keys in nibble-list format. + level : + Current trie level. + + Returns + ------- + node : `ethereum.base_types.Bytes` + Root node of `obj`. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let arbitrary_key := + M.call (| + M.get_name (| globals, "next" |), + make_list [ + M.call (| + M.get_name (| globals, "iter" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), Constant.int 1 |), + (* then *) + ltac:(M.monadic ( + let leaf := + M.call (| + M.get_name (| globals, "LeafNode" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |); + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "leaf" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let substring := + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) in + let prefix_length := + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "substring" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do + let prefix_length := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_name (| globals, "prefix_length" |); + M.call (| + M.get_name (| globals, "common_prefix_length" |), + make_list [ + M.get_name (| globals, "substring" |); + M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let prefix := + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ExtensionNode" |), + make_list [ + M.get_name (| globals, "prefix" |); + M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_name (| globals, "obj" |); + BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in +(* At stmt: unsupported node type: AnnAssign *) + For M.get_name (| globals, "_" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 16 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "branches" |), "append" |), + make_list [ + {} + ], + make_dict [] + |) in + EndFor. + let value := + (* At constant: unsupported node type: Constant *) in + For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |), M.get_name (| globals, "level" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "AssertionError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) + |) in + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "BranchNode" |), + make_list [ + [M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "branches" |), M.get_name (| globals, "k" |) |); + BinOp.add (| + M.get_name (| globals, "level" |), + Constant.int 1 + |) + ], + make_dict [] + |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)]; + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/utils/__init__.v b/CoqOfPython/ethereum/shanghai/utils/__init__.v new file mode 100644 index 0000000..1baedea --- /dev/null +++ b/CoqOfPython/ethereum/shanghai/utils/__init__.v @@ -0,0 +1,8 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Utility functions unique to this particular fork. +". diff --git a/CoqOfPython/ethereum/shanghai/utils/address.v b/CoqOfPython/ethereum/shanghai/utils/address.v new file mode 100644 index 0000000..e2cf508 --- /dev/null +++ b/CoqOfPython/ethereum/shanghai/utils/address.v @@ -0,0 +1,204 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Hardfork Utility Functions For Addresses +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Address specific functions used in this shanghai version of +specification. +". + +Require typing. +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_left_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Definition to_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "data" ] |) in + let _ := Constant.str " + Convert a Uint or U256 value to a valid address (20 bytes). + + Parameters + ---------- + data : + The string to be converted to bytes. + + Returns + ------- + address : `Address` + The obtained address. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_subscript (| M.call (| + M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition compute_contract_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "address"; "nonce" ] |) in + let _ := Constant.str " + Computes address of the new account that needs to be created. + + Parameters + ---------- + address : + The address of the account that wants to create the new account. + nonce : + The transaction count of the account that wants to create the new + account. + + Returns + ------- + address: `Address` + The computed address of the new account. + " in + let computed_address := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_list [ + M.get_name (| globals, "address" |); + M.get_name (| globals, "nonce" |) + ] + ], + make_dict [] + |) + ], + make_dict [] + |) in + let canonical_address := + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + let padded_address := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "canonical_address" |); + Constant.int 20 + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "padded_address" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition compute_create2_contract_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "address"; "salt"; "call_data" ] |) in + let _ := Constant.str " + Computes address of the new account that needs to be created, which is + based on the sender address, salt and the call data as well. + + Parameters + ---------- + address : + The address of the account that wants to create the new account. + salt : + Address generation salt. + call_data : + The code of the new account which is to be created. + + Returns + ------- + address: `ethereum.shanghai.fork_types.Address` + The computed address of the new account. + " in + let preimage := + BinOp.add (| + BinOp.add (| + BinOp.add (| + (* At constant: unsupported node type: Constant *), + M.get_name (| globals, "address" |) + |), + M.get_name (| globals, "salt" |) + |), + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "call_data" |) + ], + make_dict [] + |) + |) in + let computed_address := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + let canonical_address := + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + let padded_address := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "canonical_address" |); + Constant.int 20 + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "padded_address" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/utils/hexadecimal.v b/CoqOfPython/ethereum/shanghai/utils/hexadecimal.v new file mode 100644 index 0000000..a77e4e4 --- /dev/null +++ b/CoqOfPython/ethereum/shanghai/utils/hexadecimal.v @@ -0,0 +1,155 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Utility Functions For Hexadecimal Strings +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Hexadecimal utility functions used in this specification, specific to +Shanghai types. +". + +Require ethereum.utils.hexadecimal. +Axiom ethereum_utils_hexadecimal_remove_hex_prefix : + IsGlobalAlias globals ethereum.utils.hexadecimal.globals "remove_hex_prefix". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Definition hex_to_root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to trie root. + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to trie root. + + Returns + ------- + root : `Root` + Trie root obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Root" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition hex_to_bloom : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to bloom. + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to bloom. + + Returns + ------- + bloom : `Bloom` + Bloom obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bloom" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition hex_to_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to Address (20 bytes). + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to Address. + + Returns + ------- + address : `Address` + The address obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |), "rjust" |), + make_list [ + Constant.int 40; + Constant.str "0" + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/utils/message.v b/CoqOfPython/ethereum/shanghai/utils/message.v new file mode 100644 index 0000000..a58178e --- /dev/null +++ b/CoqOfPython/ethereum/shanghai/utils/message.v @@ -0,0 +1,254 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Hardfork Utility Functions For The Message Data-structure +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Message specific functions used in this shanghai version of +specification. +". + +Require typing. +Axiom typing_FrozenSet : + IsGlobalAlias globals typing.globals "FrozenSet". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". + +Require vm. +Axiom vm_Environment : + IsGlobalAlias globals vm.globals "Environment". +Axiom vm_Message : + IsGlobalAlias globals vm.globals "Message". + +Require vm.precompiled_contracts.mapping. +Axiom vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : + IsGlobalAlias globals vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". + +Require address. +Axiom address_compute_contract_address : + IsGlobalAlias globals address.globals "compute_contract_address". + +Definition prepare_message : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "caller"; "target"; "value"; "data"; "gas"; "env"; "code_address"; "should_transfer_value"; "is_static"; "preaccessed_addresses"; "preaccessed_storage_keys" ] |) in + let _ := Constant.str " + Execute a transaction against the provided environment. + + Parameters + ---------- + caller : + Address which initiated the transaction + target : + Address whose code will be executed + value : + Value to be transferred. + data : + Array of bytes provided to the code in `target`. + gas : + Gas provided for the code in `target`. + env : + Environment for the Ethereum Virtual Machine. + code_address : + This is usually same as the `target` address except when an alternative + accounts code needs to be executed. + eg. `CALLCODE` calling a precompile. + should_transfer_value : + if True ETH should be transferred while executing a message call. + is_static: + if True then it prevents all state-changing operations from being + executed. + preaccessed_addresses: + Addresses that should be marked as accessed prior to the message call + preaccessed_storage_keys: + Storage keys that should be marked as accessed prior to the message + call + + Returns + ------- + message: `ethereum.shanghai.vm.Message` + Items containing contract creation or message call specific data. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Bytes0" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.call (| + M.get_name (| globals, "compute_contract_address" |), + make_list [ + M.get_name (| globals, "caller" |); + BinOp.sub (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "caller" |) + ], + make_dict [] + |), "nonce" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let msg_data := + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |) in + let code := + M.get_name (| globals, "data" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.get_name (| globals, "target" |) in + let msg_data := + M.get_name (| globals, "data" |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "target" |) + ], + make_dict [] + |), "code" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "code_address" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let code_address := + M.get_name (| globals, "target" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "AssertionError" |), + make_list [ + Constant.str "Target must be address or empty bytes" + ], + make_dict [] + |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let accessed_addresses := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "current_target" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "caller" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "accessed_addresses" |), "update" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "PRE_COMPILED_CONTRACTS" |), "keys" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "accessed_addresses" |), "update" |), + make_list [ + M.get_name (| globals, "preaccessed_addresses" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/vm/__init__.v b/CoqOfPython/ethereum/shanghai/vm/__init__.v new file mode 100644 index 0000000..2ff63cd --- /dev/null +++ b/CoqOfPython/ethereum/shanghai/vm/__init__.v @@ -0,0 +1,262 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The abstract computer which runs the code stored in an +`.fork_types.Account`. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U64 : + IsGlobalAlias globals ethereum.base_types.globals "U64". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_State : + IsGlobalAlias globals state.globals "State". +Axiom state_account_exists_and_is_empty : + IsGlobalAlias globals state.globals "account_exists_and_is_empty". + +Require precompiled_contracts. +Axiom precompiled_contracts_RIPEMD160_ADDRESS : + IsGlobalAlias globals precompiled_contracts.globals "RIPEMD160_ADDRESS". + +Definition __all__ : Value.t := M.run ltac:(M.monadic ( + make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] +)). + +Definition Environment : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Message : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Evm : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition incorporate_child_on_success : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "child_evm" ] |) in + let _ := Constant.str " + Incorporate the state of a successful `child_evm` into the parent `evm`. + + Parameters + ---------- + evm : + The parent `EVM`. + child_evm : + The child evm to incorporate. + " in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "gas_left" |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "logs" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "logs" |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "refund_counter" |) + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "accounts_to_delete" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "accessed_addresses" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "accessed_storage_keys" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition incorporate_child_on_error : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "child_evm" ] |) in + let _ := Constant.str " + Incorporate the state of an unsuccessful `child_evm` into the parent `evm`. + + Parameters + ---------- + evm : + The parent `EVM`. + child_evm : + The child evm to incorporate. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "RIPEMD160_ADDRESS" |), M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |), M.get_name (| globals, "RIPEMD160_ADDRESS" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "gas_left" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/vm/exceptions.v b/CoqOfPython/ethereum/shanghai/vm/exceptions.v new file mode 100644 index 0000000..1f4363d --- /dev/null +++ b/CoqOfPython/ethereum/shanghai/vm/exceptions.v @@ -0,0 +1,172 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Exceptions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Exceptions which cause the EVM to halt exceptionally. +". + +Require ethereum.exceptions. +Axiom ethereum_exceptions_EthereumException : + IsGlobalAlias globals ethereum.exceptions.globals "EthereumException". + +Definition ExceptionalHalt : Value.t := + builtins.make_klass + [(globals, "EthereumException")] + [ + + ] + [ + + ]. + +Definition Revert : Value.t := + builtins.make_klass + [(globals, "EthereumException")] + [ + + ] + [ + + ]. + +Definition StackUnderflowError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition StackOverflowError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition OutOfGasError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition InvalidOpcode : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + ( + "__init__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "code" ] |) in + let _ := M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "super" |), + make_list [], + make_dict [] + |), "__init__" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "self" |), "code" |), + M.get_name (| globals, "code" |) + |) in + M.pure Constant.None_)) + ) + ]. + +Definition InvalidJumpDestError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition StackDepthLimitError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition WriteInStaticContext : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition OutOfBoundsRead : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition InvalidParameter : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition InvalidContractPrefix : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition AddressCollision : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/__init__.v b/CoqOfPython/ethereum/shanghai/vm/instructions/__init__.v new file mode 100644 index 0000000..e5bebd7 --- /dev/null +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/__init__.v @@ -0,0 +1,87 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +EVM Instruction Encoding (Opcodes) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Machine readable representations of EVM instructions, and a mapping to their +implementations. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". + +Require __init__. +Axiom __init___arithmetic : + IsGlobalAlias globals __init__.globals "arithmetic". + +Require __init__. +Axiom __init___bitwise : + IsGlobalAlias globals __init__.globals "bitwise". + +Require __init__. +Axiom __init___block : + IsGlobalAlias globals __init__.globals "block". + +Require __init__. +Axiom __init___comparison : + IsGlobalAlias globals __init__.globals "comparison". + +Require __init__. +Axiom __init___control_flow : + IsGlobalAlias globals __init__.globals "control_flow". + +Require __init__. +Axiom __init___environment : + IsGlobalAlias globals __init__.globals "environment". + +Require __init__. +Axiom __init___keccak : + IsGlobalAlias globals __init__.globals "keccak". + +Require __init__. +Axiom __init___log : + IsGlobalAlias globals __init__.globals "log". + +Require __init__. +Axiom __init___memory : + IsGlobalAlias globals __init__.globals "memory". + +Require __init__. +Axiom __init___stack : + IsGlobalAlias globals __init__.globals "stack". + +Require __init__. +Axiom __init___storage : + IsGlobalAlias globals __init__.globals "storage". + +Require __init__. +Axiom __init___system : + IsGlobalAlias globals __init__.globals "system". + +Definition Ops : Value.t := + builtins.make_klass + [(* At base: unsupported node type: Attribute *)] + [ + + ] + [ + + ]. + +(* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/shanghai/vm/instructions/arithmetic.v new file mode 100644 index 0000000..a8b5c61 --- /dev/null +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/arithmetic.v @@ -0,0 +1,1085 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Arithmetic Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM Arithmetic instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U255_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U255_CEIL_VALUE". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_U256_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_get_sign : + IsGlobalAlias globals ethereum.utils.numeric.globals "get_sign". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_EXPONENTIATION : + IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION". +Axiom gas_GAS_EXPONENTIATION_PER_BYTE : + IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION_PER_BYTE". +Axiom gas_GAS_LOW : + IsGlobalAlias globals gas.globals "GAS_LOW". +Axiom gas_GAS_MID : + IsGlobalAlias globals gas.globals "GAS_MID". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition add : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Adds the top two elements of the stack together, and pushes the result back + on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "x" |), "wrapping_add" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition sub : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Subtracts the top two elements of the stack, and pushes the result back + on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "x" |), "wrapping_sub" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mul : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Multiply the top two elements of the stack, and pushes the result back + on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "x" |), "wrapping_mul" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition div : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Integer division of the top two elements of the stack. Pushes the result + back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let dividend := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let divisor := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let quotient := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let quotient := + BinOp.floor_div (| + M.get_name (| globals, "dividend" |), + M.get_name (| globals, "divisor" |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "quotient" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition sdiv : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed integer division of the top two elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let dividend := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let divisor := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let quotient := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_name (| globals, "dividend" |), UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "divisor" |), UnOp.sub (| Constant.int 1 |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let quotient := + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let sign := + M.call (| + M.get_name (| globals, "get_sign" |), + make_list [ + BinOp.mult (| + M.get_name (| globals, "dividend" |), + M.get_name (| globals, "divisor" |) + |) + ], + make_dict [] + |) in + let quotient := + BinOp.mult (| + M.get_name (| globals, "sign" |), + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "dividend" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "divisor" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + M.get_name (| globals, "quotient" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Modulo remainder of the top two elements of the stack. Pushes the result + back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let remainder := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let remainder := + BinOp.mod_ (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "remainder" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition smod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed modulo remainder of the top two elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let y := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let remainder := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let remainder := + BinOp.mult (| + M.call (| + M.get_name (| globals, "get_sign" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + BinOp.mod_ (| + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + M.get_name (| globals, "remainder" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition addmod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Modulo addition of the top 2 elements with the 3rd element. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let z := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_MID" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.add (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |), + M.get_name (| globals, "z" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mulmod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Modulo multiplication of the top 2 elements with the 3rd element. Pushes + the result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let z := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_MID" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.mult (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |), + M.get_name (| globals, "z" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition exp : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Exponential operation of the top 2 elements. Pushes the result back on + the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let base := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exponent := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exponent_bits := + M.call (| + M.get_field (| M.get_name (| globals, "exponent" |), "bit_length" |), + make_list [], + make_dict [] + |) in + let exponent_bytes := + BinOp.floor_div (| + BinOp.add (| + M.get_name (| globals, "exponent_bits" |), + Constant.int 7 + |), + Constant.int 8 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_EXPONENTIATION" |), + BinOp.mult (| + M.get_name (| globals, "GAS_EXPONENTIATION_PER_BYTE" |), + M.get_name (| globals, "exponent_bytes" |) + |) + |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "pow" |), + make_list [ + M.get_name (| globals, "base" |); + M.get_name (| globals, "exponent" |); + M.get_name (| globals, "U256_CEIL_VALUE" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition signextend : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Sign extend operation. In other words, extend a signed number which + fits in N bytes to 32 bytes. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let byte_num := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "byte_num" |), Constant.int 31 |), + (* then *) + ltac:(M.monadic ( + let result := + M.get_name (| globals, "value" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let value_bytes := + M.call (| + M.get_name (| globals, "bytes" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "value" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) in + let value_bytes := + M.get_subscript (| M.get_name (| globals, "value_bytes" |), BinOp.sub (| + Constant.int 31, + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "byte_num" |) + ], + make_dict [] + |) + |):(* At expr: unsupported node type: NoneType *) |) in + let sign_bit := + BinOp.r_shift (| + M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), + Constant.int 7 + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "sign_bit" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "value_bytes" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let num_bytes_prepend := + BinOp.sub (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "byte_num" |), + Constant.int 1 + |) + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + BinOp.add (| + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [ + BinOp.mult (| + make_list [ + Constant.int 255 + ], + M.get_name (| globals, "num_bytes_prepend" |) + |) + ], + make_dict [] + |), + M.get_name (| globals, "value_bytes" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/bitwise.v b/CoqOfPython/ethereum/shanghai/vm/instructions/bitwise.v new file mode 100644 index 0000000..9f2f382 --- /dev/null +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/bitwise.v @@ -0,0 +1,601 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Bitwise Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM bitwise instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_U256_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition bitwise_and : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise AND operation of the top 2 elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + BinOp.bit_and (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_or : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise OR operation of the top 2 elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + BinOp.bit_or (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_xor : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise XOR operation of the top 2 elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + BinOp.bit_xor (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_not : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise NOT operation of the top element of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + UnOp.invert (| M.get_name (| globals, "x" |) |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition get_byte : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + For a word (defined by next top element of the stack), retrieve the + Nth byte (0-indexed and defined by top element of stack) from the + left (most significant) to right (least significant). + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let byte_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let word := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "byte_index" |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let extra_bytes_to_right := + BinOp.sub (| + Constant.int 31, + M.get_name (| globals, "byte_index" |) + |) in + let word := + BinOp.r_shift (| + M.get_name (| globals, "word" |), + BinOp.mult (| + M.get_name (| globals, "extra_bytes_to_right" |), + Constant.int 8 + |) + |) in + let word := + BinOp.bit_and (| + M.get_name (| globals, "word" |), + Constant.int 255 + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "word" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_shl : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Logical shift left (SHL) operation of the top 2 elements of the stack. + Pushes the result back on the stack. + Parameters + ---------- + evm : + The current EVM frame. + " in + let shift := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.l_shift (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "shift" |) + |), + M.get_name (| globals, "U256_CEIL_VALUE" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_shr : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Logical shift right (SHR) operation of the top 2 elements of the stack. + Pushes the result back on the stack. + Parameters + ---------- + evm : + The current EVM frame. + " in + let shift := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), + (* then *) + ltac:(M.monadic ( + let result := + BinOp.r_shift (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "shift" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_sar : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Arithmetic shift right (SAR) operation of the top 2 elements of the stack. + Pushes the result back on the stack. + Parameters + ---------- + evm : + The current EVM frame. + " in + let shift := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let signed_value := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + BinOp.r_shift (| + M.get_name (| globals, "signed_value" |), + M.get_name (| globals, "shift" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "signed_value" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/block.v b/CoqOfPython/ethereum/shanghai/vm/instructions/block.v new file mode 100644 index 0000000..35d4735 --- /dev/null +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/block.v @@ -0,0 +1,421 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Block Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM block instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_BLOCK_HASH : + IsGlobalAlias globals gas.globals "GAS_BLOCK_HASH". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition block_hash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the hash of one of the 256 most recent complete blocks onto the + stack. The block number to hash is present at the top of the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + Raises + ------ + :py:class:`~ethereum.shanghai.vm.exceptions.StackUnderflowError` + If `len(stack)` is less than `1`. + :py:class:`~ethereum.shanghai.vm.exceptions.OutOfGasError` + If `evm.gas_left` is less than `20`. + " in + let block_number := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BLOCK_HASH" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt_e (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), M.get_name (| globals, "block_number" |) |), + ltac:(M.monadic ( + Compare.gt (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), BinOp.add (| + M.get_name (| globals, "block_number" |), + Constant.int 256 + |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let hash := + (* At constant: unsupported node type: Constant *) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let hash := + M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + M.get_name (| globals, "block_number" |) + |) |) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "hash" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition coinbase : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's beneficiary address (address of the block miner) + onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + Raises + ------ + :py:class:`~ethereum.shanghai.vm.exceptions.StackOverflowError` + If `len(stack)` is equal to `1024`. + :py:class:`~ethereum.shanghai.vm.exceptions.OutOfGasError` + If `evm.gas_left` is less than `2`. + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "coinbase" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition timestamp : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's timestamp onto the stack. Here the timestamp + being referred is actually the unix timestamp in seconds. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + Raises + ------ + :py:class:`~ethereum.shanghai.vm.exceptions.StackOverflowError` + If `len(stack)` is equal to `1024`. + :py:class:`~ethereum.shanghai.vm.exceptions.OutOfGasError` + If `evm.gas_left` is less than `2`. + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "time" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition number : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's number onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + Raises + ------ + :py:class:`~ethereum.shanghai.vm.exceptions.StackOverflowError` + If `len(stack)` is equal to `1024`. + :py:class:`~ethereum.shanghai.vm.exceptions.OutOfGasError` + If `evm.gas_left` is less than `2`. + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition prev_randao : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the `prev_randao` value onto the stack. + + The `prev_randao` value is the random output of the beacon chain's + randomness oracle for the previous block. + + Parameters + ---------- + evm : + The current EVM frame. + + Raises + ------ + :py:class:`~ethereum.shanghai.vm.exceptions.StackOverflowError` + If `len(stack)` is equal to `1024`. + :py:class:`~ethereum.shanghai.vm.exceptions.OutOfGasError` + If `evm.gas_left` is less than `2`. + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "prev_randao" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition gas_limit : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's gas limit onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + Raises + ------ + :py:class:`~ethereum.shanghai.vm.exceptions.StackOverflowError` + If `len(stack)` is equal to `1024`. + :py:class:`~ethereum.shanghai.vm.exceptions.OutOfGasError` + If `evm.gas_left` is less than `2`. + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "gas_limit" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition chain_id : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the chain id onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + Raises + ------ + :py:class:`~ethereum.shanghai.vm.exceptions.StackOverflowError` + If `len(stack)` is equal to `1024`. + :py:class:`~ethereum.shanghai.vm.exceptions.OutOfGasError` + If `evm.gas_left` is less than `2`. + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "chain_id" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/comparison.v b/CoqOfPython/ethereum/shanghai/vm/instructions/comparison.v new file mode 100644 index 0000000..fbc35f8 --- /dev/null +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/comparison.v @@ -0,0 +1,404 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Comparison Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM Comparison instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition less_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is less than the next top element. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let right := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition signed_less_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed less-than comparison. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let right := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition greater_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is greater than the next top element. Pushes + the result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let right := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition signed_greater_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed greater-than comparison. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let right := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition equal : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is equal to the next top element. Pushes + the result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let right := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.eq (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition is_zero : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is equal to 0. Pushes the result back on the + stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.eq (| M.get_name (| globals, "x" |), Constant.int 0 |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/control_flow.v b/CoqOfPython/ethereum/shanghai/vm/instructions/control_flow.v new file mode 100644 index 0000000..04a79d9 --- /dev/null +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/control_flow.v @@ -0,0 +1,336 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Control Flow Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM control flow instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require vm.gas. +Axiom vm_gas_GAS_BASE : + IsGlobalAlias globals vm.gas.globals "GAS_BASE". +Axiom vm_gas_GAS_HIGH : + IsGlobalAlias globals vm.gas.globals "GAS_HIGH". +Axiom vm_gas_GAS_JUMPDEST : + IsGlobalAlias globals vm.gas.globals "GAS_JUMPDEST". +Axiom vm_gas_GAS_MID : + IsGlobalAlias globals vm.gas.globals "GAS_MID". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_InvalidJumpDestError : + IsGlobalAlias globals exceptions.globals "InvalidJumpDestError". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition stop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stop further execution of EVM code. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let _ := M.pass (| |) in + let _ := M.pass (| |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "running" |), + Constant.bool false + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition jump : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Alter the program counter to the location specified by the top of the + stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let jump_dest := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_MID" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "jump_dest" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition jumpi : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Alter the program counter to the specified location if and only if a + condition is true. If the condition is not true, then the program counter + would increase only by 1. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let jump_dest := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let conditional_value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_HIGH" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "conditional_value" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let destination := + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let destination := + M.get_name (| globals, "jump_dest" |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "destination" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition pc : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push onto the stack the value of the program counter after reaching the + current instruction and without increasing it for the next instruction. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "pc" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition gas_left : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the amount of available gas (including the corresponding reduction + for the cost of this instruction) onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition jumpdest : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Mark a valid destination for jumps. This is a noop, present only + to be used by `JUMP` and `JUMPI` opcodes to verify that their jump is + valid. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_JUMPDEST" |) + ], + make_dict [] + |) in + let _ := M.pass (| |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/environment.v b/CoqOfPython/ethereum/shanghai/vm/instructions/environment.v new file mode 100644 index 0000000..530304e --- /dev/null +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/environment.v @@ -0,0 +1,1436 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Environmental Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM environment related instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require fork_types. +Axiom fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". + +Require state. +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". + +Require utils.address. +Axiom utils_address_to_address : + IsGlobalAlias globals utils.address.globals "to_address". + +Require vm.memory. +Axiom vm_memory_buffer_read : + IsGlobalAlias globals vm.memory.globals "buffer_read". +Axiom vm_memory_memory_write : + IsGlobalAlias globals vm.memory.globals "memory_write". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_OutOfBoundsRead : + IsGlobalAlias globals exceptions.globals "OutOfBoundsRead". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_COLD_ACCOUNT_ACCESS : + IsGlobalAlias globals gas.globals "GAS_COLD_ACCOUNT_ACCESS". +Axiom gas_GAS_COPY : + IsGlobalAlias globals gas.globals "GAS_COPY". +Axiom gas_GAS_FAST_STEP : + IsGlobalAlias globals gas.globals "GAS_FAST_STEP". +Axiom gas_GAS_RETURN_DATA_COPY : + IsGlobalAlias globals gas.globals "GAS_RETURN_DATA_COPY". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_GAS_WARM_ACCESS : + IsGlobalAlias globals gas.globals "GAS_WARM_ACCESS". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the address of the current executing account to the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition balance : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the balance of the given account onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "balance" |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "balance" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition origin : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the address of the original transaction sender to the stack. + The origin address can only be an EOA. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "origin" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition caller : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the address of the caller onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "caller" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition callvalue : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the value (in wei) sent with the call onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition calldataload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push a word (32 bytes) of the input data belonging to the current + environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |); + M.get_name (| globals, "start_index" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition calldatasize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the size of input data in current environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition calldatacopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy a portion of the input data in current environment to memory. + + This will also expand the memory, in case that the memory is insufficient + to store the data. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let data_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |); + M.get_name (| globals, "data_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition codesize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the size of code running in current environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "code" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition codecopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy a portion of the code in current environment to memory. + + This will also expand the memory, in case that the memory is insufficient + to store the data. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let code_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "code" |); + M.get_name (| globals, "code_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition gasprice : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the gas price used in current environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "gas_price" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition extcodesize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the code size of a given account onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let codesize := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "code" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "codesize" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition extcodecopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy a portion of an account's code to memory. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let code_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_WARM_ACCESS" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "code" |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "code" |); + M.get_name (| globals, "code_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition returndatasize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the size of the return data buffer onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition returndatacopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copies data from the return data buffer code to memory + + Parameters + ---------- + evm : + The current EVM frame. + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let return_data_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_RETURN_DATA_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "return_data_start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "OutOfBoundsRead" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |):BinOp.add (| + M.get_name (| globals, "return_data_start_position" |), + M.get_name (| globals, "size" |) + |) |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition extcodehash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Returns the keccak256 hash of a contract’s bytecode + Parameters + ---------- + evm : + The current EVM frame. + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "account" |), M.get_name (| globals, "EMPTY_ACCOUNT" |) |), + (* then *) + ltac:(M.monadic ( + let codehash := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let codehash := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_field (| M.get_name (| globals, "account" |), "code" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "codehash" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition self_balance : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the balance of the current address to the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_FAST_STEP" |) + ], + make_dict [] + |) in + let balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "balance" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition base_fee : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the base fee of the current block on to the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "base_fee_per_gas" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/keccak.v b/CoqOfPython/ethereum/shanghai/vm/instructions/keccak.v new file mode 100644 index 0000000..cab9ffb --- /dev/null +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/keccak.v @@ -0,0 +1,181 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Keccak Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM keccak instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_KECCAK256 : + IsGlobalAlias globals gas.globals "GAS_KECCAK256". +Axiom gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition keccak : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes to the stack the Keccak-256 hash of a region of memory. + + This also expands the memory, in case the memory is insufficient to + access the data's memory location. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let word_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_KECCAK256_WORD" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_KECCAK256" |), + M.get_name (| globals, "word_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let data := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "hash" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/log.v b/CoqOfPython/ethereum/shanghai/vm/instructions/log.v new file mode 100644 index 0000000..4891a4d --- /dev/null +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/log.v @@ -0,0 +1,244 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Logging Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM logging instructions. +". + +Require functools. +Axiom functools_partial : + IsGlobalAlias globals functools.globals "partial". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_WriteInStaticContext : + IsGlobalAlias globals exceptions.globals "WriteInStaticContext". + +Require gas. +Axiom gas_GAS_LOG : + IsGlobalAlias globals gas.globals "GAS_LOG". +Axiom gas_GAS_LOG_DATA : + IsGlobalAlias globals gas.globals "GAS_LOG_DATA". +Axiom gas_GAS_LOG_TOPIC : + IsGlobalAlias globals gas.globals "GAS_LOG_TOPIC". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". + +Definition log_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "num_topics" ] |) in + let _ := Constant.str " + Appends a log entry, having `num_topics` topics, to the evm logs. + + This will also expand the memory if the data (required by the log entry) + corresponding to the memory is not accessible. + + Parameters + ---------- + evm : + The current EVM frame. + num_topics : + The number of topics to be included in the log entry. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let topics := + make_list [] in + For M.get_name (| globals, "_" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "num_topics" |) + ], + make_dict [] + |) do + let topic := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "topics" |), "append" |), + make_list [ + M.get_name (| globals, "topic" |) + ], + make_dict [] + |) in + EndFor. + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_LOG" |), + BinOp.mult (| + M.get_name (| globals, "GAS_LOG_DATA" |), + M.get_name (| globals, "size" |) + |) + |), + BinOp.mult (| + M.get_name (| globals, "GAS_LOG_TOPIC" |), + M.get_name (| globals, "num_topics" |) + |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let log_entry := + M.call (| + M.get_name (| globals, "Log" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "logs" |), + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "logs" |), + make_tuple [ M.get_name (| globals, "log_entry" |) ] + |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition log0 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/memory.v b/CoqOfPython/ethereum/shanghai/vm/instructions/memory.v new file mode 100644 index 0000000..1e1c8b0 --- /dev/null +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/memory.v @@ -0,0 +1,378 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Memory Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM Memory instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". +Axiom memory_memory_write : + IsGlobalAlias globals memory.globals "memory_write". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition mstore : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a word to memory. + This also expands the memory, if the memory is + insufficient to store the word. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "start_position" |); M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + ], + make_dict [] + |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "start_position" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mstore8 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a byte to memory. + This also expands the memory, if the memory is + insufficient to store the word. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "start_position" |); M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let normalized_bytes_value := + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + make_list [ + BinOp.bit_and (| + M.get_name (| globals, "value" |), + Constant.int 255 + |) + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "start_position" |); + M.get_name (| globals, "normalized_bytes_value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Load word from memory. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "start_position" |); M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "start_position" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition msize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the size of active memory in bytes onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/stack.v b/CoqOfPython/ethereum/shanghai/vm/instructions/stack.v new file mode 100644 index 0000000..46a91f6 --- /dev/null +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/stack.v @@ -0,0 +1,958 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Stack Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM stack related instructions. +". + +Require functools. +Axiom functools_partial : + IsGlobalAlias globals functools.globals "partial". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". +Axiom __init___stack : + IsGlobalAlias globals __init__.globals "stack". + +Require exceptions. +Axiom exceptions_StackUnderflowError : + IsGlobalAlias globals exceptions.globals "StackUnderflowError". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_buffer_read : + IsGlobalAlias globals memory.globals "buffer_read". + +Definition pop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Remove item from stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.pass (| |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition push_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "num_bytes" ] |) in + let _ := Constant.str " + Pushes a N-byte immediate onto the stack. Push zero if num_bytes is zero. + + Parameters + ---------- + evm : + The current EVM frame. + + num_bytes : + The number of immediate bytes to be read from the code and pushed to + the stack. Push zero if num_bytes is zero. + + " in + let _ := M.pass (| |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "num_bytes" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let data_to_push := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "code" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "num_bytes" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "data_to_push" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + BinOp.add (| + Constant.int 1, + M.get_name (| globals, "num_bytes" |) + |) + |) in + M.pure Constant.None_)). + +Definition dup_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "item_number" ] |) in + let _ := Constant.str " + Duplicate the Nth stack item (from top of the stack) to the top of stack. + + Parameters + ---------- + evm : + The current EVM frame. + + item_number : + The stack item number (0-indexed from top of stack) to be duplicated + to the top of stack. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "StackUnderflowError" |) + ], + make_dict [] + |) in + let data_to_duplicate := + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + BinOp.sub (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), + Constant.int 1 + |), + M.get_name (| globals, "item_number" |) + |) |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "data_to_duplicate" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition swap_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "item_number" ] |) in + let _ := Constant.str " + Swap the top and the `item_number` element of the stack, where + the top of the stack is position zero. + + If `item_number` is zero, this function does nothing (which should not be + possible, since there is no `SWAP0` instruction). + + Parameters + ---------- + evm : + The current EVM frame. + + item_number : + The stack item number (0-indexed from top of stack) to be swapped + with the top of stack element. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "StackUnderflowError" |) + ], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) |) ], + make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |) ] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition push0 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push5 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push6 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push7 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push8 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push9 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push10 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push11 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push12 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push13 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push14 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push15 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push16 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push17 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push18 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push19 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push20 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push21 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push22 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push23 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push24 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push25 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push26 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push27 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push28 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push29 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push30 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push31 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push32 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition dup1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup5 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup6 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup7 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup8 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup9 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup10 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup11 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup12 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup13 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup14 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup15 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup16 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition swap1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap5 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap6 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap7 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap8 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap9 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap10 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap11 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap12 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap13 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap14 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap15 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap16 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/storage.v b/CoqOfPython/ethereum/shanghai/vm/instructions/storage.v new file mode 100644 index 0000000..2f0a831 --- /dev/null +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/storage.v @@ -0,0 +1,437 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Storage Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM storage related instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require state. +Axiom state_get_storage : + IsGlobalAlias globals state.globals "get_storage". +Axiom state_get_storage_original : + IsGlobalAlias globals state.globals "get_storage_original". +Axiom state_set_storage : + IsGlobalAlias globals state.globals "set_storage". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". +Axiom exceptions_WriteInStaticContext : + IsGlobalAlias globals exceptions.globals "WriteInStaticContext". + +Require gas. +Axiom gas_GAS_CALL_STIPEND : + IsGlobalAlias globals gas.globals "GAS_CALL_STIPEND". +Axiom gas_GAS_COLD_SLOAD : + IsGlobalAlias globals gas.globals "GAS_COLD_SLOAD". +Axiom gas_GAS_STORAGE_CLEAR_REFUND : + IsGlobalAlias globals gas.globals "GAS_STORAGE_CLEAR_REFUND". +Axiom gas_GAS_STORAGE_SET : + IsGlobalAlias globals gas.globals "GAS_STORAGE_SET". +Axiom gas_GAS_STORAGE_UPDATE : + IsGlobalAlias globals gas.globals "GAS_STORAGE_UPDATE". +Axiom gas_GAS_WARM_ACCESS : + IsGlobalAlias globals gas.globals "GAS_WARM_ACCESS". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition sload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Loads to the stack, the value corresponding to a certain key from the + storage of the current account. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let key := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "add" |), + make_list [ + make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_COLD_SLOAD" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let value := + M.call (| + M.get_name (| globals, "get_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition sstore : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a value at a certain key in the current context's storage. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let key := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let new_value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt (| M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), M.get_name (| globals, "GAS_CALL_STIPEND" |) |); + M.get_name (| globals, "OutOfGasError" |) + ], + make_dict [] + |) in + let original_value := + M.call (| + M.get_name (| globals, "get_storage_original" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let current_value := + M.call (| + M.get_name (| globals, "get_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let gas_cost := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "add" |), + make_list [ + make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ] + ], + make_dict [] + |) in + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_COLD_SLOAD" |) + M.get_name (| globals, "GAS_COLD_SLOAD" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_name (| globals, "original_value" |), M.get_name (| globals, "current_value" |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_name (| globals, "current_value" |), M.get_name (| globals, "new_value" |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_STORAGE_SET" |) + M.get_name (| globals, "GAS_STORAGE_SET" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let gas_cost := BinOp.add + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_UPDATE" |), + M.get_name (| globals, "GAS_COLD_SLOAD" |) + |) + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_UPDATE" |), + M.get_name (| globals, "GAS_COLD_SLOAD" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_WARM_ACCESS" |) + M.get_name (| globals, "GAS_WARM_ACCESS" |) in + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| M.get_name (| globals, "current_value" |), M.get_name (| globals, "new_value" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "new_value" |), Constant.int 0 |) + )) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.sub, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "original_value" |), M.get_name (| globals, "new_value" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_SET" |), + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.sub (| + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_UPDATE" |), + M.get_name (| globals, "GAS_COLD_SLOAD" |) + |), + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "gas_cost" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "set_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |); + M.get_name (| globals, "new_value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/vm/interpreter.v b/CoqOfPython/ethereum/shanghai/vm/interpreter.v new file mode 100644 index 0000000..903fa29 --- /dev/null +++ b/CoqOfPython/ethereum/shanghai/vm/interpreter.v @@ -0,0 +1,647 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Interpreter +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +A straightforward interpreter that executes EVM code. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Iterable : + IsGlobalAlias globals typing.globals "Iterable". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.trace. +Axiom ethereum_trace_EvmStop : + IsGlobalAlias globals ethereum.trace.globals "EvmStop". +Axiom ethereum_trace_OpEnd : + IsGlobalAlias globals ethereum.trace.globals "OpEnd". +Axiom ethereum_trace_OpException : + IsGlobalAlias globals ethereum.trace.globals "OpException". +Axiom ethereum_trace_OpStart : + IsGlobalAlias globals ethereum.trace.globals "OpStart". +Axiom ethereum_trace_PrecompileEnd : + IsGlobalAlias globals ethereum.trace.globals "PrecompileEnd". +Axiom ethereum_trace_PrecompileStart : + IsGlobalAlias globals ethereum.trace.globals "PrecompileStart". +Axiom ethereum_trace_TransactionEnd : + IsGlobalAlias globals ethereum.trace.globals "TransactionEnd". +Axiom ethereum_trace_evm_trace : + IsGlobalAlias globals ethereum.trace.globals "evm_trace". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_account_exists_and_is_empty : + IsGlobalAlias globals state.globals "account_exists_and_is_empty". +Axiom state_account_has_code_or_nonce : + IsGlobalAlias globals state.globals "account_has_code_or_nonce". +Axiom state_begin_transaction : + IsGlobalAlias globals state.globals "begin_transaction". +Axiom state_commit_transaction : + IsGlobalAlias globals state.globals "commit_transaction". +Axiom state_destroy_storage : + IsGlobalAlias globals state.globals "destroy_storage". +Axiom state_increment_nonce : + IsGlobalAlias globals state.globals "increment_nonce". +Axiom state_mark_account_created : + IsGlobalAlias globals state.globals "mark_account_created". +Axiom state_move_ether : + IsGlobalAlias globals state.globals "move_ether". +Axiom state_rollback_transaction : + IsGlobalAlias globals state.globals "rollback_transaction". +Axiom state_set_code : + IsGlobalAlias globals state.globals "set_code". +Axiom state_touch_account : + IsGlobalAlias globals state.globals "touch_account". + +Require vm. +Axiom vm_Message : + IsGlobalAlias globals vm.globals "Message". + +Require vm.gas. +Axiom vm_gas_GAS_CODE_DEPOSIT : + IsGlobalAlias globals vm.gas.globals "GAS_CODE_DEPOSIT". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require vm.precompiled_contracts.mapping. +Axiom vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : + IsGlobalAlias globals vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". + +Require __init__. +Axiom __init___Environment : + IsGlobalAlias globals __init__.globals "Environment". +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_AddressCollision : + IsGlobalAlias globals exceptions.globals "AddressCollision". +Axiom exceptions_ExceptionalHalt : + IsGlobalAlias globals exceptions.globals "ExceptionalHalt". +Axiom exceptions_InvalidContractPrefix : + IsGlobalAlias globals exceptions.globals "InvalidContractPrefix". +Axiom exceptions_InvalidOpcode : + IsGlobalAlias globals exceptions.globals "InvalidOpcode". +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". +Axiom exceptions_Revert : + IsGlobalAlias globals exceptions.globals "Revert". +Axiom exceptions_StackDepthLimitError : + IsGlobalAlias globals exceptions.globals "StackDepthLimitError". + +Require instructions. +Axiom instructions_Ops : + IsGlobalAlias globals instructions.globals "Ops". +Axiom instructions_op_implementation : + IsGlobalAlias globals instructions.globals "op_implementation". + +Require runtime. +Axiom runtime_get_valid_jump_destinations : + IsGlobalAlias globals runtime.globals "get_valid_jump_destinations". + +Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1024 + ], + make_dict [] + |) +)). + +Definition MAX_CODE_SIZE : Value.t := M.run ltac:(M.monadic ( + Constant.int 24576 +)). + +Definition MessageCallOutput : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition process_message_call : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + If `message.current` is empty then it creates a smart contract + else it executes a call from the `message.caller` to the `message.target`. + + Parameters + ---------- + message : + Transaction specific items. + + env : + External items required for EVM execution. + + Returns + ------- + output : `MessageCallOutput` + Output of the message call + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_name (| globals, "message" |), "target" |), M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let is_collision := + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_name (| globals, "is_collision" |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallOutput" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "tuple" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "AddressCollision" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let evm := + M.call (| + M.get_name (| globals, "process_create_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let evm := + M.call (| + M.get_name (| globals, "process_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_field (| M.get_name (| globals, "message" |), "target" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_field (| M.get_name (| globals, "message" |), "target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( +(* At stmt: unsupported node type: AnnAssign *) + let accounts_to_delete := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let touched_accounts := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let refund_counter := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let logs := + M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in + let accounts_to_delete := + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in + let touched_accounts := + M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |) in + let refund_counter := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let tx_end := + M.call (| + M.get_name (| globals, "TransactionEnd" |), + make_list [ + BinOp.sub (| + M.get_field (| M.get_name (| globals, "message" |), "gas" |), + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + |); + M.get_field (| M.get_name (| globals, "evm" |), "output" |); + M.get_field (| M.get_name (| globals, "evm" |), "error" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "evm_trace" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "tx_end" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallOutput" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition process_create_message : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + Executes a call to create a smart contract. + + Parameters + ---------- + message : + Transaction specific items. + env : + External items required for EVM execution. + + Returns + ------- + evm: :py:class:`~ethereum.shanghai.vm.Evm` + Items containing execution specific objects. + " in + let _ := M.call (| + M.get_name (| globals, "begin_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "destroy_storage" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "mark_account_created" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let evm := + M.call (| + M.get_name (| globals, "process_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), + (* then *) + ltac:(M.monadic ( + let contract_code := + M.get_field (| M.get_name (| globals, "evm" |), "output" |) in + let contract_code_gas := + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "contract_code" |) + ], + make_dict [] + |), + M.get_name (| globals, "GAS_CODE_DEPOSIT" |) + |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "rollback_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.get_name (| globals, "evm" |) + |) in + M.pure Constant.None_)). + +Definition process_message : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + Executes a call to create a smart contract. + + Parameters + ---------- + message : + Transaction specific items. + env : + External items required for EVM execution. + + Returns + ------- + evm: :py:class:`~ethereum.shanghai.vm.Evm` + Items containing execution specific objects + " in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_field (| M.get_name (| globals, "message" |), "depth" |), M.get_name (| globals, "STACK_DEPTH_LIMIT" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "StackDepthLimitError" |), + make_list [ + Constant.str "Stack depth limit reached" + ], + make_dict [] + |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "begin_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "touch_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + M.get_field (| M.get_name (| globals, "message" |), "should_transfer_value" |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_field (| M.get_name (| globals, "message" |), "value" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "move_ether" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "caller" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |); + M.get_field (| M.get_name (| globals, "message" |), "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let evm := + M.call (| + M.get_name (| globals, "execute_code" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "rollback_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "commit_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.get_name (| globals, "evm" |) + |) in + M.pure Constant.None_)). + +Definition execute_code : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + Executes bytecode present in the `message`. + + Parameters + ---------- + message : + Transaction specific items. + env : + External items required for EVM execution. + + Returns + ------- + evm: `ethereum.vm.EVM` + Items containing execution specific objects + " in + let code := + M.get_field (| M.get_name (| globals, "message" |), "code" |) in + let valid_jump_destinations := + M.call (| + M.get_name (| globals, "get_valid_jump_destinations" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) in + let evm := + M.call (| + M.get_name (| globals, "Evm" |), + make_list [], + make_dict [] + |) in +(* At stmt: unsupported node type: Try *) + let _ := M.return_ (| + M.get_name (| globals, "evm" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/vm/memory.v b/CoqOfPython/ethereum/shanghai/vm/memory.v new file mode 100644 index 0000000..fa8d906 --- /dev/null +++ b/CoqOfPython/ethereum/shanghai/vm/memory.v @@ -0,0 +1,153 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Memory +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +EVM memory operations. +". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_right_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "right_pad_zero_bytes". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". + +Definition memory_write : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "memory"; "start_position"; "value" ] |) in + let _ := Constant.str " + Writes to memory. + + Parameters + ---------- + memory : + Memory contents of the EVM. + start_position : + Starting pointer to the memory. + value : + Data to write to memory. + " in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) |), + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_)). + +Definition memory_read_bytes : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "memory"; "start_position"; "size" ] |) in + let _ := Constant.str " + Read bytes from memory. + + Parameters + ---------- + memory : + Memory contents of the EVM. + start_position : + Starting pointer to the memory. + size : + Size of the data that needs to be read from `start_position`. + + Returns + ------- + data_bytes : + Data read from memory. + " in + let _ := M.return_ (| + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |) + |) in + M.pure Constant.None_)). + +Definition buffer_read : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "buffer"; "start_position"; "size" ] |) in + let _ := Constant.str " + Read bytes from a buffer. Padding with zeros if necessary. + + Parameters + ---------- + buffer : + Memory contents of the EVM. + start_position : + Starting pointer to the memory. + size : + Size of the data that needs to be read from `start_position`. + + Returns + ------- + data_bytes : + Data read from memory. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "right_pad_zero_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/__init__.v new file mode 100644 index 0000000..ca49311 --- /dev/null +++ b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/__init__.v @@ -0,0 +1,117 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Precompiled Contract Addresses +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Addresses of precompiled contracts and mappings to their +implementations. +". + +Require utils.hexadecimal. +Axiom utils_hexadecimal_hex_to_address : + IsGlobalAlias globals utils.hexadecimal.globals "hex_to_address". + +Definition __all__ : Value.t := M.run ltac:(M.monadic ( + make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS"; Constant.str "MODEXP_ADDRESS"; Constant.str "ALT_BN128_ADD_ADDRESS"; Constant.str "ALT_BN128_MUL_ADDRESS"; Constant.str "ALT_BN128_PAIRING_CHECK_ADDRESS"; Constant.str "BLAKE2F_ADDRESS" ] +)). + +Definition ECRECOVER_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x01" + ], + make_dict [] + |) +)). + +Definition SHA256_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x02" + ], + make_dict [] + |) +)). + +Definition RIPEMD160_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x03" + ], + make_dict [] + |) +)). + +Definition IDENTITY_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x04" + ], + make_dict [] + |) +)). + +Definition MODEXP_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x05" + ], + make_dict [] + |) +)). + +Definition ALT_BN128_ADD_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x06" + ], + make_dict [] + |) +)). + +Definition ALT_BN128_MUL_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x07" + ], + make_dict [] + |) +)). + +Definition ALT_BN128_PAIRING_CHECK_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x08" + ], + make_dict [] + |) +)). + +Definition BLAKE2F_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x09" + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/alt_bn128.v new file mode 100644 index 0000000..19b83fc --- /dev/null +++ b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/alt_bn128.v @@ -0,0 +1,673 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) ALT_BN128 CONTRACTS +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the ALT_BN128 precompiled contracts. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.alt_bn128. +Axiom ethereum_crypto_alt_bn128_ALT_BN128_CURVE_ORDER : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "ALT_BN128_CURVE_ORDER". +Axiom ethereum_crypto_alt_bn128_ALT_BN128_PRIME : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "ALT_BN128_PRIME". +Axiom ethereum_crypto_alt_bn128_BNF : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF". +Axiom ethereum_crypto_alt_bn128_BNF2 : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF2". +Axiom ethereum_crypto_alt_bn128_BNF12 : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF12". +Axiom ethereum_crypto_alt_bn128_BNP : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNP". +Axiom ethereum_crypto_alt_bn128_BNP2 : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNP2". +Axiom ethereum_crypto_alt_bn128_pairing : + IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "pairing". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require vm.memory. +Axiom vm_memory_buffer_read : + IsGlobalAlias globals vm.memory.globals "buffer_read". + +Require exceptions. +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". + +Definition alt_bn128_add : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + The ALT_BN128 addition precompiled contract. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 150 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x0_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x0_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "x0_bytes" |) + ], + make_dict [] + |) in + let y0_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y0_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "y0_bytes" |) + ], + make_dict [] + |) in + let x1_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x1_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "x1_bytes" |) + ], + make_dict [] + |) in + let y1_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y1_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "y1_bytes" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ] do + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "i" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. +(* At stmt: unsupported node type: Try *) + let p := + BinOp.add (| + M.get_name (| globals, "p0" |), + M.get_name (| globals, "p1" |) + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + BinOp.add (| + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "p" |), "x" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "p" |), "y" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) + |) in + M.pure Constant.None_)). + +Definition alt_bn128_mul : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + The ALT_BN128 multiplication precompiled contract. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 6000 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x0_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let x0_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "x0_bytes" |) + ], + make_dict [] + |) in + let y0_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y0_value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "y0_bytes" |) + ], + make_dict [] + |) in + let n := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ] do + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "i" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. +(* At stmt: unsupported node type: Try *) + let p := + M.call (| + M.get_field (| M.get_name (| globals, "p0" |), "mul_by" |), + make_list [ + M.get_name (| globals, "n" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + BinOp.add (| + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "p" |), "x" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "p" |), "y" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) + |) in + M.pure Constant.None_)). + +Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + The ALT_BN128 pairing check precompiled contract. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 34000, + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 192 + |) + |), + Constant.int 45000 + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 192 + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 192 + |) + ], + make_dict [] + |) do + let values := + make_list [] in + For M.get_name (| globals, "j" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 6 + ], + make_dict [] + |) do + let value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "data" |), BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + M.get_name (| globals, "j" |) + |) + |):BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "j" |), + Constant.int 1 + |) + |) + |) |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "value" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "values" |), "append" |), + make_list [ + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + EndFor. +(* At stmt: unsupported node type: Try *) + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.call (| + M.get_field (| M.get_name (| globals, "p" |), "mul_by" |), + make_list [ + M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) + ], + make_dict [] + |), M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) |); + M.get_name (| globals, "OutOfGasError" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.call (| + M.get_field (| M.get_name (| globals, "q" |), "mul_by" |), + make_list [ + M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) + ], + make_dict [] + |), M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) |); + M.get_name (| globals, "OutOfGasError" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "p" |), M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_name (| globals, "q" |), M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let result := + BinOp.mult (| + M.get_name (| globals, "result" |), + M.call (| + M.get_name (| globals, "pairing" |), + make_list [ + M.get_name (| globals, "q" |); + M.get_name (| globals, "p" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "result" |), M.call (| + M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/blake2f.v b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/blake2f.v new file mode 100644 index 0000000..5903066 --- /dev/null +++ b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/blake2f.v @@ -0,0 +1,122 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Blake2 PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `Blake2` precompiled contract. +". + +Require ethereum.crypto.blake2. +Axiom ethereum_crypto_blake2_Blake2b : + IsGlobalAlias globals ethereum.crypto.blake2.globals "Blake2b". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_BLAKE2_PER_ROUND : + IsGlobalAlias globals vm.gas.globals "GAS_BLAKE2_PER_ROUND". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require exceptions. +Axiom exceptions_InvalidParameter : + IsGlobalAlias globals exceptions.globals "InvalidParameter". + +Definition blake2f : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the Blake2 hash to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), Constant.int 213 |); + M.get_name (| globals, "InvalidParameter" |) + ], + make_dict [] + |) in + let blake2b := + M.call (| + M.get_name (| globals, "Blake2b" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "rounds" |); M.get_name (| globals, "h" |); M.get_name (| globals, "m" |); M.get_name (| globals, "t_0" |); M.get_name (| globals, "t_1" |); M.get_name (| globals, "f" |) ], + M.call (| + M.get_field (| M.get_name (| globals, "blake2b" |), "get_blake2_parameters" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.mult (| + M.get_name (| globals, "GAS_BLAKE2_PER_ROUND" |), + M.get_name (| globals, "rounds" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.in (| M.get_name (| globals, "f" |), make_list [ + Constant.int 0; + Constant.int 1 + ] |); + M.get_name (| globals, "InvalidParameter" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.get_name (| globals, "blake2b" |), "compress" |), + make_list [ + M.get_name (| globals, "rounds" |); + M.get_name (| globals, "h" |); + M.get_name (| globals, "m" |); + M.get_name (| globals, "t_0" |); + M.get_name (| globals, "t_1" |); + M.get_name (| globals, "f" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/ecrecover.v new file mode 100644 index 0000000..cc351b5 --- /dev/null +++ b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/ecrecover.v @@ -0,0 +1,269 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) ECRECOVER PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the ECRECOVER precompiled contract. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require ethereum.crypto.elliptic_curve. +Axiom ethereum_crypto_elliptic_curve_SECP256K1N : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_left_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_ECRECOVER : + IsGlobalAlias globals vm.gas.globals "GAS_ECRECOVER". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require vm.memory. +Axiom vm_memory_buffer_read : + IsGlobalAlias globals vm.memory.globals "buffer_read". + +Definition ecrecover : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Decrypts the address using elliptic curve DSA recovery mechanism and writes + the address to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_ECRECOVER" |) + ], + make_dict [] + |) in + let message_hash_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let message_hash := + M.call (| + M.get_name (| globals, "Hash32" |), + make_list [ + M.get_name (| globals, "message_hash_bytes" |) + ], + make_dict [] + |) in + let v := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let r := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let s := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 27 |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 28 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| Constant.int 0, M.get_name (| globals, "r" |) |), + ltac:(M.monadic ( + Compare.gt_e (| M.get_name (| globals, "r" |), M.get_name (| globals, "SECP256K1N" |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| Constant.int 0, M.get_name (| globals, "s" |) |), + ltac:(M.monadic ( + Compare.gt_e (| M.get_name (| globals, "s" |), M.get_name (| globals, "SECP256K1N" |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in +(* At stmt: unsupported node type: Try *) + let address := + M.get_subscript (| M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), Constant.int 12:Constant.int 32 |) in + let padded_address := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "address" |); + Constant.int 32 + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.get_name (| globals, "padded_address" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/identity.v new file mode 100644 index 0000000..fa96704 --- /dev/null +++ b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/identity.v @@ -0,0 +1,94 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) IDENTITY PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `IDENTITY` precompiled contract. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_IDENTITY : + IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY". +Axiom vm_gas_GAS_IDENTITY_WORD : + IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY_WORD". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition identity : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the message data to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let word_count := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_IDENTITY" |), + BinOp.mult (| + M.get_name (| globals, "GAS_IDENTITY_WORD" |), + M.get_name (| globals, "word_count" |) + |) + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.get_name (| globals, "data" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/mapping.v new file mode 100644 index 0000000..8a2e2eb --- /dev/null +++ b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/mapping.v @@ -0,0 +1,82 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Precompiled Contract Addresses +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Mapping of precompiled contracts their implementations. +". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require __init__. +Axiom __init___ALT_BN128_ADD_ADDRESS : + IsGlobalAlias globals __init__.globals "ALT_BN128_ADD_ADDRESS". +Axiom __init___ALT_BN128_MUL_ADDRESS : + IsGlobalAlias globals __init__.globals "ALT_BN128_MUL_ADDRESS". +Axiom __init___ALT_BN128_PAIRING_CHECK_ADDRESS : + IsGlobalAlias globals __init__.globals "ALT_BN128_PAIRING_CHECK_ADDRESS". +Axiom __init___BLAKE2F_ADDRESS : + IsGlobalAlias globals __init__.globals "BLAKE2F_ADDRESS". +Axiom __init___ECRECOVER_ADDRESS : + IsGlobalAlias globals __init__.globals "ECRECOVER_ADDRESS". +Axiom __init___IDENTITY_ADDRESS : + IsGlobalAlias globals __init__.globals "IDENTITY_ADDRESS". +Axiom __init___MODEXP_ADDRESS : + IsGlobalAlias globals __init__.globals "MODEXP_ADDRESS". +Axiom __init___RIPEMD160_ADDRESS : + IsGlobalAlias globals __init__.globals "RIPEMD160_ADDRESS". +Axiom __init___SHA256_ADDRESS : + IsGlobalAlias globals __init__.globals "SHA256_ADDRESS". + +Require alt_bn128. +Axiom alt_bn128_alt_bn128_add : + IsGlobalAlias globals alt_bn128.globals "alt_bn128_add". +Axiom alt_bn128_alt_bn128_mul : + IsGlobalAlias globals alt_bn128.globals "alt_bn128_mul". +Axiom alt_bn128_alt_bn128_pairing_check : + IsGlobalAlias globals alt_bn128.globals "alt_bn128_pairing_check". + +Require blake2f. +Axiom blake2f_blake2f : + IsGlobalAlias globals blake2f.globals "blake2f". + +Require ecrecover. +Axiom ecrecover_ecrecover : + IsGlobalAlias globals ecrecover.globals "ecrecover". + +Require identity. +Axiom identity_identity : + IsGlobalAlias globals identity.globals "identity". + +Require modexp. +Axiom modexp_modexp : + IsGlobalAlias globals modexp.globals "modexp". + +Require ripemd160. +Axiom ripemd160_ripemd160 : + IsGlobalAlias globals ripemd160.globals "ripemd160". + +Require sha256. +Axiom sha256_sha256 : + IsGlobalAlias globals sha256.globals "sha256". + +(* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/modexp.v new file mode 100644 index 0000000..544949e --- /dev/null +++ b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/modexp.v @@ -0,0 +1,608 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) MODEXP PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `MODEXP` precompiled contract. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require memory. +Axiom memory_buffer_read : + IsGlobalAlias globals memory.globals "buffer_read". + +Definition GQUADDIVISOR : Value.t := M.run ltac:(M.monadic ( + Constant.int 3 +)). + +Definition modexp : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Calculates `(base**exp) % modulus` for arbitrary sized `base`, `exp` and. + `modulus`. The return value is the same length as the modulus. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let base_length := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exp_length := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let modulus_length := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exp_start := + BinOp.add (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |), + M.get_name (| globals, "base_length" |) + |) in + let exp_head := + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.get_name (| globals, "exp_start" |); + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.get_name (| globals, "exp_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "gas_cost" |), + make_list [ + M.get_name (| globals, "base_length" |); + M.get_name (| globals, "modulus_length" |); + M.get_name (| globals, "exp_length" |); + M.get_name (| globals, "exp_head" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_name (| globals, "base_length" |), Constant.int 0 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "modulus_length" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [], + make_dict [] + |) + |) in + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let base := + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |); + M.get_name (| globals, "base_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exp := + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.get_name (| globals, "exp_start" |); + M.get_name (| globals, "exp_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let modulus_start := + BinOp.add (| + M.get_name (| globals, "exp_start" |), + M.get_name (| globals, "exp_length" |) + |) in + let modulus := + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.get_name (| globals, "modulus_start" |); + M.get_name (| globals, "modulus_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "modulus" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + BinOp.mult (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |), + M.get_name (| globals, "modulus_length" |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pow" |), + make_list [ + M.get_name (| globals, "base" |); + M.get_name (| globals, "exp" |); + M.get_name (| globals, "modulus" |) + ], + make_dict [] + |) + ], + make_dict [] + |), "to_bytes" |), + make_list [ + M.get_name (| globals, "modulus_length" |); + Constant.str "big" + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition complexity : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "base_length"; "modulus_length" ] |) in + let _ := Constant.str " + Estimate the complexity of performing a modular exponentiation. + + Parameters + ---------- + + base_length : + Length of the array representing the base integer. + + modulus_length : + Length of the array representing the modulus integer. + + Returns + ------- + + complexity : `Uint` + Complexity of performing the operation. + " in + let max_length := + M.call (| + M.get_name (| globals, "max" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "base_length" |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "modulus_length" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + BinOp.add (| + M.get_name (| globals, "max_length" |), + Constant.int 7 + |), + Constant.int 8 + |) in + let _ := M.return_ (| + BinOp.pow (| + M.get_name (| globals, "words" |), + Constant.int 2 + |) + |) in + M.pure Constant.None_)). + +Definition iterations : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "exponent_length"; "exponent_head" ] |) in + let _ := Constant.str " + Calculate the number of iterations required to perform a modular + exponentiation. + + Parameters + ---------- + + exponent_length : + Length of the array representing the exponent integer. + + exponent_head : + First 32 bytes of the exponent (with leading zero padding if it is + shorter than 32 bytes), as an unsigned integer. + + Returns + ------- + + iterations : `Uint` + Number of iterations. + " in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.lt_e (| M.get_name (| globals, "exponent_length" |), Constant.int 32 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "exponent_head" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let count := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| M.get_name (| globals, "exponent_length" |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let bit_length := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "exponent_head" |), "bit_length" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "bit_length" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let bit_length := BinOp.sub + Constant.int 1 + Constant.int 1 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let count := + M.get_name (| globals, "bit_length" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let length_part := + BinOp.mult (| + Constant.int 8, + BinOp.sub (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "exponent_length" |) + ], + make_dict [] + |), + Constant.int 32 + |) + |) in + let bits_part := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "exponent_head" |), "bit_length" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "bits_part" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let bits_part := BinOp.sub + Constant.int 1 + Constant.int 1 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let count := + BinOp.add (| + M.get_name (| globals, "length_part" |), + M.get_name (| globals, "bits_part" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "max" |), + make_list [ + M.get_name (| globals, "count" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition gas_cost : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "base_length"; "modulus_length"; "exponent_length"; "exponent_head" ] |) in + let _ := Constant.str " + Calculate the gas cost of performing a modular exponentiation. + + Parameters + ---------- + + base_length : + Length of the array representing the base integer. + + modulus_length : + Length of the array representing the modulus integer. + + exponent_length : + Length of the array representing the exponent integer. + + exponent_head : + First 32 bytes of the exponent (with leading zero padding if it is + shorter than 32 bytes), as an unsigned integer. + + Returns + ------- + + gas_cost : `Uint` + Gas required for performing the operation. + " in + let multiplication_complexity := + M.call (| + M.get_name (| globals, "complexity" |), + make_list [ + M.get_name (| globals, "base_length" |); + M.get_name (| globals, "modulus_length" |) + ], + make_dict [] + |) in + let iteration_count := + M.call (| + M.get_name (| globals, "iterations" |), + make_list [ + M.get_name (| globals, "exponent_length" |); + M.get_name (| globals, "exponent_head" |) + ], + make_dict [] + |) in + let cost := + BinOp.mult (| + M.get_name (| globals, "multiplication_complexity" |), + M.get_name (| globals, "iteration_count" |) + |) in + let cost := BinOp.floor_div + M.get_name (| globals, "GQUADDIVISOR" |) + M.get_name (| globals, "GQUADDIVISOR" |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "max" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 200 + ], + make_dict [] + |); + M.get_name (| globals, "cost" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/ripemd160.v new file mode 100644 index 0000000..96f8dcd --- /dev/null +++ b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/ripemd160.v @@ -0,0 +1,122 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) RIPEMD160 PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `RIPEMD160` precompiled contract. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_left_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_RIPEMD160 : + IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160". +Axiom vm_gas_GAS_RIPEMD160_WORD : + IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160_WORD". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition ripemd160 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the ripemd160 hash to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let word_count := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_RIPEMD160" |), + BinOp.mult (| + M.get_name (| globals, "GAS_RIPEMD160_WORD" |), + M.get_name (| globals, "word_count" |) + |) + |) + ], + make_dict [] + |) in + let hash_bytes := + M.call (| + M.get_field (| M.call (| + M.get_field (| M.get_name (| globals, "hashlib" |), "new" |), + make_list [ + Constant.str "ripemd160"; + M.get_name (| globals, "data" |) + ], + make_dict [] + |), "digest" |), + make_list [], + make_dict [] + |) in + let padded_hash := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "hash_bytes" |); + Constant.int 32 + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.get_name (| globals, "padded_hash" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/sha256.v new file mode 100644 index 0000000..9f6d2bf --- /dev/null +++ b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/sha256.v @@ -0,0 +1,106 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) SHA256 PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `SHA256` precompiled contract. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_SHA256 : + IsGlobalAlias globals vm.gas.globals "GAS_SHA256". +Axiom vm_gas_GAS_SHA256_WORD : + IsGlobalAlias globals vm.gas.globals "GAS_SHA256_WORD". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition sha256 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the sha256 hash to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let word_count := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_SHA256" |), + BinOp.mult (| + M.get_name (| globals, "GAS_SHA256_WORD" |), + M.get_name (| globals, "word_count" |) + |) + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_field (| M.get_name (| globals, "hashlib" |), "sha256" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), "digest" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/vm/runtime.v b/CoqOfPython/ethereum/shanghai/vm/runtime.v new file mode 100644 index 0000000..835b46c --- /dev/null +++ b/CoqOfPython/ethereum/shanghai/vm/runtime.v @@ -0,0 +1,125 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Runtime Operations +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Runtime related operations used while executing EVM code. +". + +Require typing. +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require instructions. +Axiom instructions_Ops : + IsGlobalAlias globals instructions.globals "Ops". + +Definition get_valid_jump_destinations : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "code" ] |) in + let _ := Constant.str " + Analyze the evm code to obtain the set of valid jump destinations. + + Valid jump destinations are defined as follows: + * The jump destination is less than the length of the code. + * The jump destination should have the `JUMPDEST` opcode (0x5B). + * The jump destination shouldn't be part of the data corresponding to + `PUSH-N` opcodes. + + Note - Jump destinations are 0-indexed. + + Parameters + ---------- + code : + The EVM code which is to be executed. + + Returns + ------- + valid_jump_destinations: `Set[Uint]` + The set of valid jump destinations in the code. + " in + let valid_jump_destinations := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let pc := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + While Compare.lt (| M.get_name (| globals, "pc" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) |) do +(* At stmt: unsupported node type: Try *) + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "current_opcode" |), M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), + make_list [ + M.get_name (| globals, "pc" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + (* At expr: unsupported node type: Compare *), + (* then *) + ltac:(M.monadic ( + let push_data_size := + BinOp.add (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) + |), + Constant.int 1 + |) in + let pc := BinOp.add + M.get_name (| globals, "push_data_size" |) + M.get_name (| globals, "push_data_size" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let pc := BinOp.add + Constant.int 1 + Constant.int 1 in + EndWhile. + let _ := M.return_ (| + M.get_name (| globals, "valid_jump_destinations" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/vm/stack.v b/CoqOfPython/ethereum/shanghai/vm/stack.v new file mode 100644 index 0000000..42ea42d --- /dev/null +++ b/CoqOfPython/ethereum/shanghai/vm/stack.v @@ -0,0 +1,120 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Stack +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the stack operators for the EVM. +". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require exceptions. +Axiom exceptions_StackOverflowError : + IsGlobalAlias globals exceptions.globals "StackOverflowError". +Axiom exceptions_StackUnderflowError : + IsGlobalAlias globals exceptions.globals "StackUnderflowError". + +Definition pop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "stack" ] |) in + let _ := Constant.str " + Pops the top item off of `stack`. + + Parameters + ---------- + stack : + EVM stack. + + Returns + ------- + value : `U256` + The top element on the stack. + + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "StackUnderflowError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "pop" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition push : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "stack"; "value" ] |) in + let _ := Constant.str " + Pushes `value` onto `stack`. + + Parameters + ---------- + stack : + EVM stack. + + value : + Item to be pushed onto `stack`. + + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), Constant.int 1024 |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "StackOverflowError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "append" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/__init__.v b/CoqOfPython/ethereum/spurious_dragon/__init__.v new file mode 100644 index 0000000..56d74fe --- /dev/null +++ b/CoqOfPython/ethereum/spurious_dragon/__init__.v @@ -0,0 +1,26 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +The Spurious Dragon fork is the second of two forks responding to a +denial-of-service attack on the Ethereum network. It tunes the prices of EVM +instructions, adds protection against replaying transaction on different +chains, limits the maximum size of contract code, and enables the removal of +empty accounts. +". + +Require ethereum.fork_criteria. +Axiom ethereum_fork_criteria_ByBlockNumber : + IsGlobalAlias globals ethereum.fork_criteria.globals "ByBlockNumber". + +Definition FORK_CRITERIA : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "ByBlockNumber" |), + make_list [ + Constant.int 2675000 + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/spurious_dragon/blocks.v b/CoqOfPython/ethereum/spurious_dragon/blocks.v new file mode 100644 index 0000000..6501788 --- /dev/null +++ b/CoqOfPython/ethereum/spurious_dragon/blocks.v @@ -0,0 +1,93 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +A `Block` is a single link in the chain that is Ethereum. Each `Block` contains +a `Header` and zero or more transactions. Each `Header` contains associated +metadata like the block number, parent block hash, and how much gas was +consumed by its transactions. + +Together, these blocks form a cryptographically secure journal recording the +history of all state transitions that have happened since the genesis of the +chain. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes8 : + IsGlobalAlias globals base_types.globals "Bytes8". +Axiom base_types_Bytes32 : + IsGlobalAlias globals base_types.globals "Bytes32". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require crypto.hash. +Axiom crypto_hash_Hash32 : + IsGlobalAlias globals crypto.hash.globals "Hash32". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Require transactions. +Axiom transactions_Transaction : + IsGlobalAlias globals transactions.globals "Transaction". + +Definition Header : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Block : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Log : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Receipt : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. diff --git a/CoqOfPython/ethereum/spurious_dragon/bloom.v b/CoqOfPython/ethereum/spurious_dragon/bloom.v new file mode 100644 index 0000000..04b5d9f --- /dev/null +++ b/CoqOfPython/ethereum/spurious_dragon/bloom.v @@ -0,0 +1,164 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Logs Bloom +^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +This modules defines functions for calculating bloom filters of logs. For the +general theory of bloom filters see e.g. `Wikipedia +`_. Bloom filters are used to allow +for efficient searching of logs by address and/or topic, by rapidly +eliminating blocks and receipts from their search. +". + +Require typing. +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require fork_types. +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". + +Definition add_to_bloom : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "bloom"; "bloom_entry" ] |) in + let _ := Constant.str " + Add a bloom entry to the bloom filter (`bloom`). + + The number of hash functions used is 3. They are calculated by taking the + least significant 11 bits from the first 3 16-bit words of the + `keccak_256()` hash of `bloom_entry`. + + Parameters + ---------- + bloom : + The bloom filter. + bloom_entry : + An entry which is to be added to bloom filter. + " in + let hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "bloom_entry" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "idx" |) in make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ] do + let bit_to_set := + BinOp.bit_and (| + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |):BinOp.add (| + M.get_name (| globals, "idx" |), + Constant.int 2 + |) |) + ], + make_dict [] + |), + Constant.int 2047 + |) in + let bit_index := + BinOp.sub (| + Constant.int 2047, + M.get_name (| globals, "bit_to_set" |) + |) in + let byte_index := + BinOp.floor_div (| + M.get_name (| globals, "bit_index" |), + Constant.int 8 + |) in + let bit_value := + BinOp.l_shift (| + Constant.int 1, + BinOp.sub (| + Constant.int 7, + BinOp.mod_ (| + M.get_name (| globals, "bit_index" |), + Constant.int 8 + |) + |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), + BinOp.bit_or (| + M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), + M.get_name (| globals, "bit_value" |) + |) + |) in + EndFor. + M.pure Constant.None_)). + +Definition logs_bloom : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "logs" ] |) in + let _ := Constant.str " + Obtain the logs bloom from a list of log entries. + + The address and each topic of a log are added to the bloom filter. + + Parameters + ---------- + logs : + List of logs for which the logs bloom is to be obtained. + + Returns + ------- + logs_bloom : `Bloom` + The logs bloom obtained which is 256 bytes with some bits set as per + the caller address and the log topics. + " in +(* At stmt: unsupported node type: AnnAssign *) + For M.get_name (| globals, "log" |) in M.get_name (| globals, "logs" |) do + let _ := M.call (| + M.get_name (| globals, "add_to_bloom" |), + make_list [ + M.get_name (| globals, "bloom" |); + M.get_field (| M.get_name (| globals, "log" |), "address" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "topic" |) in M.get_field (| M.get_name (| globals, "log" |), "topics" |) do + let _ := M.call (| + M.get_name (| globals, "add_to_bloom" |), + make_list [ + M.get_name (| globals, "bloom" |); + M.get_name (| globals, "topic" |) + ], + make_dict [] + |) in + EndFor. + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bloom" |), + make_list [ + M.get_name (| globals, "bloom" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/fork.v b/CoqOfPython/ethereum/spurious_dragon/fork.v new file mode 100644 index 0000000..7799350 --- /dev/null +++ b/CoqOfPython/ethereum/spurious_dragon/fork.v @@ -0,0 +1,2278 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Specification +^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Entry point for the Ethereum specification. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". + +Require ethereum.crypto.elliptic_curve. +Axiom ethereum_crypto_elliptic_curve_SECP256K1N : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.ethash. +Axiom ethereum_ethash_dataset_size : + IsGlobalAlias globals ethereum.ethash.globals "dataset_size". +Axiom ethereum_ethash_generate_cache : + IsGlobalAlias globals ethereum.ethash.globals "generate_cache". +Axiom ethereum_ethash_hashimoto_light : + IsGlobalAlias globals ethereum.ethash.globals "hashimoto_light". + +Require ethereum.exceptions. +Axiom ethereum_exceptions_InvalidBlock : + IsGlobalAlias globals ethereum.exceptions.globals "InvalidBlock". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U64 : + IsGlobalAlias globals base_types.globals "U64". +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_U256_CEIL_VALUE : + IsGlobalAlias globals base_types.globals "U256_CEIL_VALUE". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes32 : + IsGlobalAlias globals base_types.globals "Bytes32". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". + +Require __init__. +Axiom __init___vm : + IsGlobalAlias globals __init__.globals "vm". + +Require blocks. +Axiom blocks_Block : + IsGlobalAlias globals blocks.globals "Block". +Axiom blocks_Header : + IsGlobalAlias globals blocks.globals "Header". +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". +Axiom blocks_Receipt : + IsGlobalAlias globals blocks.globals "Receipt". + +Require bloom. +Axiom bloom_logs_bloom : + IsGlobalAlias globals bloom.globals "logs_bloom". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Require state. +Axiom state_State : + IsGlobalAlias globals state.globals "State". +Axiom state_account_exists_and_is_empty : + IsGlobalAlias globals state.globals "account_exists_and_is_empty". +Axiom state_create_ether : + IsGlobalAlias globals state.globals "create_ether". +Axiom state_destroy_account : + IsGlobalAlias globals state.globals "destroy_account". +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". +Axiom state_increment_nonce : + IsGlobalAlias globals state.globals "increment_nonce". +Axiom state_set_account_balance : + IsGlobalAlias globals state.globals "set_account_balance". +Axiom state_state_root : + IsGlobalAlias globals state.globals "state_root". + +Require transactions. +Axiom transactions_TX_BASE_COST : + IsGlobalAlias globals transactions.globals "TX_BASE_COST". +Axiom transactions_TX_CREATE_COST : + IsGlobalAlias globals transactions.globals "TX_CREATE_COST". +Axiom transactions_TX_DATA_COST_PER_NON_ZERO : + IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_NON_ZERO". +Axiom transactions_TX_DATA_COST_PER_ZERO : + IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_ZERO". +Axiom transactions_Transaction : + IsGlobalAlias globals transactions.globals "Transaction". + +Require trie. +Axiom trie_Trie : + IsGlobalAlias globals trie.globals "Trie". +Axiom trie_root : + IsGlobalAlias globals trie.globals "root". +Axiom trie_trie_set : + IsGlobalAlias globals trie.globals "trie_set". + +Require utils.message. +Axiom utils_message_prepare_message : + IsGlobalAlias globals utils.message.globals "prepare_message". + +Require vm.interpreter. +Axiom vm_interpreter_process_message_call : + IsGlobalAlias globals vm.interpreter.globals "process_message_call". + +Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mult (| + Constant.int 5, + BinOp.pow (| + Constant.int 10, + Constant.int 18 + |) + |) + ], + make_dict [] + |) +)). + +Definition GAS_LIMIT_ADJUSTMENT_FACTOR : Value.t := M.run ltac:(M.monadic ( + Constant.int 1024 +)). + +Definition GAS_LIMIT_MINIMUM : Value.t := M.run ltac:(M.monadic ( + Constant.int 5000 +)). + +Definition MINIMUM_DIFFICULTY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 131072 + ], + make_dict [] + |) +)). + +Definition MAX_OMMER_DEPTH : Value.t := M.run ltac:(M.monadic ( + Constant.int 6 +)). + +Definition BlockChain : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition apply_fork : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "old" ] |) in + let _ := Constant.str " + Transforms the state from the previous hard fork (`old`) into the block + chain object for this hard fork and returns it. + + When forks need to implement an irregular state transition, this function + is used to handle the irregularity. See the :ref:`DAO Fork ` for + an example. + + Parameters + ---------- + old : + Previous block chain object. + + Returns + ------- + new : `BlockChain` + Upgraded block chain object for this hard fork. + " in + let _ := M.return_ (| + M.get_name (| globals, "old" |) + |) in + M.pure Constant.None_)). + +Definition get_last_256_block_hashes : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "chain" ] |) in + let _ := Constant.str " + Obtain the list of hashes of the previous 256 blocks in order of + increasing block number. + + This function will return less hashes for the first 256 blocks. + + The ``BLOCKHASH`` opcode needs to access the latest hashes on the chain, + therefore this function retrieves them. + + Parameters + ---------- + chain : + History and current state. + + Returns + ------- + recent_block_hashes : `List[Hash32]` + Hashes of the recent 256 blocks in order of increasing block number. + " in + let recent_blocks := + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |):(* At expr: unsupported node type: NoneType *) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "recent_blocks" |) + ], + make_dict [] + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + make_list [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let recent_block_hashes := + make_list [] in + For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_blocks" |) do + let prev_block_hash := + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), + make_list [ + M.get_name (| globals, "prev_block_hash" |) + ], + make_dict [] + |) in + EndFor. + let most_recent_block_hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_field (| M.get_subscript (| M.get_name (| globals, "recent_blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), + make_list [ + M.get_name (| globals, "most_recent_block_hash" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "recent_block_hashes" |) + |) in + M.pure Constant.None_)). + +Definition state_transition : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "chain"; "block" ] |) in + let _ := Constant.str " + Attempts to apply a block to an existing block chain. + + All parts of the block's contents need to be verified before being added + to the chain. Blocks are verified by ensuring that the contents of the + block make logical sense with the contents of the parent block. The + information in the block's header must also match the corresponding + information in the block. + + To implement Ethereum, in theory clients are only required to store the + most recent 255 blocks of the chain since as far as execution is + concerned, only those blocks are accessed. Practically, however, clients + should store more blocks to handle reorgs. + + Parameters + ---------- + chain : + History and current state. + block : + Block to apply to `chain`. + " in + let parent_header := + M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) in + let _ := M.call (| + M.get_name (| globals, "validate_header" |), + make_list [ + M.get_field (| M.get_name (| globals, "block" |), "header" |); + M.get_name (| globals, "parent_header" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "validate_ommers" |), + make_list [ + M.get_field (| M.get_name (| globals, "block" |), "ommers" |); + M.get_field (| M.get_name (| globals, "block" |), "header" |); + M.get_name (| globals, "chain" |) + ], + make_dict [] + |) in + let apply_body_output := + M.call (| + M.get_name (| globals, "apply_body" |), + make_list [ + M.get_field (| M.get_name (| globals, "chain" |), "state" |); + M.call (| + M.get_name (| globals, "get_last_256_block_hashes" |), + make_list [ + M.get_name (| globals, "chain" |) + ], + make_dict [] + |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "coinbase" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "number" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "gas_limit" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "timestamp" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "difficulty" |); + M.get_field (| M.get_name (| globals, "block" |), "transactions" |); + M.get_field (| M.get_name (| globals, "block" |), "ommers" |); + M.get_field (| M.get_name (| globals, "chain" |), "chain_id" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_gas_used" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "gas_used" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "transactions_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "transactions_root" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "state_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "state_root" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "receipt_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "receipt_root" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_logs_bloom" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "bloom" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), "append" |), + make_list [ + M.get_name (| globals, "block" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |) + ], + make_dict [] + |), Constant.int 255 |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |):(* At expr: unsupported node type: NoneType *) |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition validate_header : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header"; "parent_header" ] |) in + let _ := Constant.str " + Verifies a block header. + + In order to consider a block's header valid, the logic for the + quantities in the header should match the logic for the block itself. + For example the header timestamp should be greater than the block's parent + timestamp because the block was created *after* the parent block. + Additionally, the block's number should be directly following the parent + block's number since it is the next block in the sequence. + + Parameters + ---------- + header : + Header to check for correctness. + parent_header : + Parent Header of the header to check for correctness + " in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt (| M.get_field (| M.get_name (| globals, "header" |), "timestamp" |), M.get_field (| M.get_name (| globals, "parent_header" |), "timestamp" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "number" |), BinOp.add (| + M.get_field (| M.get_name (| globals, "parent_header" |), "number" |), + Constant.int 1 + |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + M.call (| + M.get_name (| globals, "check_gas_limit" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "gas_limit" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "gas_limit" |) + ], + make_dict [] + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) + ], + make_dict [] + |), Constant.int 32 |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let block_difficulty := + M.call (| + M.get_name (| globals, "calculate_block_difficulty" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "number" |); + M.get_field (| M.get_name (| globals, "header" |), "timestamp" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "timestamp" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "difficulty" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "difficulty" |), M.get_name (| globals, "block_difficulty" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let block_parent_hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "parent_header" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |), M.get_name (| globals, "block_parent_hash" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "validate_proof_of_work" |), + make_list [ + M.get_name (| globals, "header" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header" ] |) in + let _ := Constant.str " + Generate rlp hash of the header which is to be used for Proof-of-Work + verification. + + In other words, the PoW artefacts `mix_digest` and `nonce` are ignored + while calculating this hash. + + A particular PoW is valid for a single hash, that hash is computed by + this function. The `nonce` and `mix_digest` are omitted from this hash + because they are being changed by miners in their search for a sufficient + proof-of-work. + + Parameters + ---------- + header : + The header object for which the hash is to be generated. + + Returns + ------- + hash : `Hash32` + The PoW valid rlp hash of the passed in header. + " in + let header_data_without_pow_artefacts := + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |); + M.get_field (| M.get_name (| globals, "header" |), "ommers_hash" |); + M.get_field (| M.get_name (| globals, "header" |), "coinbase" |); + M.get_field (| M.get_name (| globals, "header" |), "state_root" |); + M.get_field (| M.get_name (| globals, "header" |), "transactions_root" |); + M.get_field (| M.get_name (| globals, "header" |), "receipt_root" |); + M.get_field (| M.get_name (| globals, "header" |), "bloom" |); + M.get_field (| M.get_name (| globals, "header" |), "difficulty" |); + M.get_field (| M.get_name (| globals, "header" |), "number" |); + M.get_field (| M.get_name (| globals, "header" |), "gas_limit" |); + M.get_field (| M.get_name (| globals, "header" |), "gas_used" |); + M.get_field (| M.get_name (| globals, "header" |), "timestamp" |); + M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) + ] in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "header_data_without_pow_artefacts" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition validate_proof_of_work : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header" ] |) in + let _ := Constant.str " + Validates the Proof of Work constraints. + + In order to verify that a miner's proof-of-work is valid for a block, a + ``mix-digest`` and ``result`` are calculated using the ``hashimoto_light`` + hash function. The mix digest is a hash of the header and the nonce that + is passed through and it confirms whether or not proof-of-work was done + on the correct block. The result is the actual hash value of the block. + + Parameters + ---------- + header : + Header of interest. + " in + let header_hash := + M.call (| + M.get_name (| globals, "generate_header_hash_for_pow" |), + make_list [ + M.get_name (| globals, "header" |) + ], + make_dict [] + |) in + let cache := + M.call (| + M.get_name (| globals, "generate_cache" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "number" |) + ], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "mix_digest" |); M.get_name (| globals, "result" |) ], + M.call (| + M.get_name (| globals, "hashimoto_light" |), + make_list [ + M.get_name (| globals, "header_hash" |); + M.get_field (| M.get_name (| globals, "header" |), "nonce" |); + M.get_name (| globals, "cache" |); + M.call (| + M.get_name (| globals, "dataset_size" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "number" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_name (| globals, "mix_digest" |), M.get_field (| M.get_name (| globals, "header" |), "mix_digest" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "result" |) + ], + make_dict [] + |), BinOp.floor_div (| + M.get_name (| globals, "U256_CEIL_VALUE" |), + M.get_field (| M.get_name (| globals, "header" |), "difficulty" |) + |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition check_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx"; "gas_available"; "chain_id" ] |) in + let _ := Constant.str " + Check if the transaction is includable in the block. + + Parameters + ---------- + tx : + The transaction. + gas_available : + The gas remaining in the block. + chain_id : + The ID of the current chain. + + Returns + ------- + sender_address : + The sender of the transaction. + + Raises + ------ + InvalidBlock : + If the transaction is not includable. + " in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_name (| globals, "gas_available" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let sender_address := + M.call (| + M.get_name (| globals, "recover_sender" |), + make_list [ + M.get_name (| globals, "chain_id" |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "sender_address" |) + |) in + M.pure Constant.None_)). + +Definition make_receipt : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx"; "post_state"; "cumulative_gas_used"; "logs" ] |) in + let _ := Constant.str " + Make the receipt for a transaction that was executed. + + Parameters + ---------- + tx : + The executed transaction. + post_state : + The state root immediately after this transaction. + cumulative_gas_used : + The total gas used so far in the block after the transaction was + executed. + logs : + The logs produced by the transaction. + + Returns + ------- + receipt : + The receipt for the transaction. + " in + let receipt := + M.call (| + M.get_name (| globals, "Receipt" |), + make_list [], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "receipt" |) + |) in + M.pure Constant.None_)). + +Definition ApplyBodyOutput : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition apply_body : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "block_hashes"; "coinbase"; "block_number"; "block_gas_limit"; "block_time"; "block_difficulty"; "transactions"; "ommers"; "chain_id" ] |) in + let _ := Constant.str " + Executes a block. + + Many of the contents of a block are stored in data structures called + tries. There is a transactions trie which is similar to a ledger of the + transactions stored in the current block. There is also a receipts trie + which stores the results of executing a transaction, like the post state + and gas used. This function creates and executes the block that is to be + added to the chain. + + Parameters + ---------- + state : + Current account state. + block_hashes : + List of hashes of the previous 256 blocks in the order of + increasing block number. + coinbase : + Address of account which receives block reward and transaction fees. + block_number : + Position of the block within the chain. + block_gas_limit : + Initial amount of gas available for execution in this block. + block_time : + Time the block was produced, measured in seconds since the epoch. + block_difficulty : + Difficulty of the block. + transactions : + Transactions included in the block. + ommers : + Headers of ancestor blocks which are not direct parents (formerly + uncles.) + chain_id : + ID of the executing chain. + + Returns + ------- + apply_body_output : `ApplyBodyOutput` + Output of applying the block body to the state. + " in + let gas_available := + M.get_name (| globals, "block_gas_limit" |) in +(* At stmt: unsupported node type: AnnAssign *) +(* At stmt: unsupported node type: AnnAssign *) +(* At stmt: unsupported node type: AnnAssign *) + For make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "tx" |) ] in M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "transactions" |) + ], + make_dict [] + |) do + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "transactions_trie" |); + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "i" |) + ], + make_dict [] + |) + ], + make_dict [] + |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) in + let sender_address := + M.call (| + M.get_name (| globals, "check_transaction" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "gas_available" |); + M.get_name (| globals, "chain_id" |) + ], + make_dict [] + |) in + let env := + M.call (| + M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |) ], + M.call (| + M.get_name (| globals, "process_transaction" |), + make_list [ + M.get_name (| globals, "env" |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) in + let gas_available := BinOp.sub + M.get_name (| globals, "gas_used" |) + M.get_name (| globals, "gas_used" |) in + let receipt := + M.call (| + M.get_name (| globals, "make_receipt" |), + make_list [ + M.get_name (| globals, "tx" |); + M.call (| + M.get_name (| globals, "state_root" |), + make_list [ + M.get_name (| globals, "state" |) + ], + make_dict [] + |); + BinOp.sub (| + M.get_name (| globals, "block_gas_limit" |), + M.get_name (| globals, "gas_available" |) + |); + M.get_name (| globals, "logs" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "receipts_trie" |); + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "i" |) + ], + make_dict [] + |) + ], + make_dict [] + |); + M.get_name (| globals, "receipt" |) + ], + make_dict [] + |) in + let block_logs := BinOp.add + M.get_name (| globals, "logs" |) + M.get_name (| globals, "logs" |) in + EndFor. + let _ := M.call (| + M.get_name (| globals, "pay_rewards" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "block_number" |); + M.get_name (| globals, "coinbase" |); + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |) in + let block_gas_used := + BinOp.sub (| + M.get_name (| globals, "block_gas_limit" |), + M.get_name (| globals, "gas_available" |) + |) in + let block_logs_bloom := + M.call (| + M.get_name (| globals, "logs_bloom" |), + make_list [ + M.get_name (| globals, "block_logs" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ApplyBodyOutput" |), + make_list [ + M.get_name (| globals, "block_gas_used" |); + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_name (| globals, "transactions_trie" |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_name (| globals, "receipts_trie" |) + ], + make_dict [] + |); + M.get_name (| globals, "block_logs_bloom" |); + M.call (| + M.get_name (| globals, "state_root" |), + make_list [ + M.get_name (| globals, "state" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition validate_ommers : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "ommers"; "block_header"; "chain" ] |) in + let _ := Constant.str " + Validates the ommers mentioned in the block. + + An ommer block is a block that wasn't canonically added to the + blockchain because it wasn't validated as fast as the canonical block + but was mined at the same time. + + To be considered valid, the ommers must adhere to the rules defined in + the Ethereum protocol. The maximum amount of ommers is 2 per block and + there cannot be duplicate ommers in a block. Many of the other ommer + constraints are listed in the in-line comments of this function. + + Parameters + ---------- + ommers : + List of ommers mentioned in the current block. + block_header: + The header of current block. + chain : + History and current state. + " in + let block_hash := + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "block_header" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), M.get_field (| M.get_name (| globals, "block_header" |), "ommers_hash" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + (* At expr: unsupported node type: Compare *); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let ommer_parent_header := + M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), BinOp.sub (| + UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) |), + Constant.int 1 + |) |), "header" |) in + let _ := M.call (| + M.get_name (| globals, "validate_header" |), + make_list [ + M.get_name (| globals, "ommer" |); + M.get_name (| globals, "ommer_parent_header" |) + ], + make_dict [] + |) in + EndFor. + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), Constant.int 2 |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let ommers_hashes := + [M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "ommer" |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)] in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers_hashes" |) + ], + make_dict [] + |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_name (| globals, "set" |), + make_list [ + M.get_name (| globals, "ommers_hashes" |) + ], + make_dict [] + |) + ], + make_dict [] + |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let recent_canonical_blocks := + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| BinOp.add (| + M.get_name (| globals, "MAX_OMMER_DEPTH" |), + Constant.int 1 + |) |):(* At expr: unsupported node type: NoneType *) |) in + let recent_canonical_block_hashes := + {M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_field (| M.get_name (| globals, "block" |), "header" |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)} in +(* At stmt: unsupported node type: AnnAssign *) + For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_canonical_blocks" |) do + let recent_ommers_hashes := + M.call (| + M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), + make_list [ + {M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "ommer" |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)} + ], + make_dict [] + |) in + EndFor. + For make_tuple [ M.get_name (| globals, "ommer_index" |); M.get_name (| globals, "ommer" |) ] in M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |) do + let ommer_hash := + M.get_subscript (| M.get_name (| globals, "ommers_hashes" |), M.get_name (| globals, "ommer_index" |) |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_eq (| M.get_name (| globals, "ommer_hash" |), M.get_name (| globals, "block_hash" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_in (| M.get_name (| globals, "ommer_hash" |), M.get_name (| globals, "recent_canonical_block_hashes" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_in (| M.get_name (| globals, "ommer_hash" |), M.get_name (| globals, "recent_ommers_hashes" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let ommer_age := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + (* At expr: unsupported node type: Compare *); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.in (| M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), M.get_name (| globals, "recent_canonical_block_hashes" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_eq (| M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), M.get_field (| M.get_name (| globals, "block_header" |), "parent_hash" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_)). + +Definition pay_rewards : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "block_number"; "coinbase"; "ommers" ] |) in + let _ := Constant.str " + Pay rewards to the block miner as well as the ommers miners. + + The miner of the canonical block is rewarded with the predetermined + block reward, ``BLOCK_REWARD``, plus a variable award based off of the + number of ommer blocks that were mined around the same time, and included + in the canonical block's header. An ommer block is a block that wasn't + added to the canonical blockchain because it wasn't validated as fast as + the accepted block but was mined at the same time. Although not all blocks + that are mined are added to the canonical chain, miners are still paid a + reward for their efforts. This reward is called an ommer reward and is + calculated based on the number associated with the ommer block that they + mined. + + Parameters + ---------- + state : + Current account state. + block_number : + Position of the block within the chain. + coinbase : + Address of account which receives block reward and transaction fees. + ommers : + List of ommers mentioned in the current block. + " in + let miner_reward := + BinOp.add (| + M.get_name (| globals, "BLOCK_REWARD" |), + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + BinOp.floor_div (| + M.get_name (| globals, "BLOCK_REWARD" |), + Constant.int 32 + |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "create_ether" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "coinbase" |); + M.get_name (| globals, "miner_reward" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do + let ommer_age := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "block_number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) + ], + make_dict [] + |) in + let ommer_miner_reward := + BinOp.floor_div (| + BinOp.mult (| + BinOp.sub (| + Constant.int 8, + M.get_name (| globals, "ommer_age" |) + |), + M.get_name (| globals, "BLOCK_REWARD" |) + |), + Constant.int 8 + |) in + let _ := M.call (| + M.get_name (| globals, "create_ether" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_field (| M.get_name (| globals, "ommer" |), "coinbase" |); + M.get_name (| globals, "ommer_miner_reward" |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_)). + +Definition process_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "env"; "tx" ] |) in + let _ := Constant.str " + Execute a transaction against the provided environment. + + This function processes the actions needed to execute a transaction. + It decrements the sender's account after calculating the gas fee and + refunds them the proper amount after execution. Calling contracts, + deploying code, and incrementing nonces are all examples of actions that + happen within this function or from a call made within this function. + + Accounts that are marked for deletion are processed and destroyed after + execution. + + Parameters + ---------- + env : + Environment for the Ethereum Virtual Machine. + tx : + Transaction to execute. + + Returns + ------- + gas_left : `ethereum.base_types.U256` + Remaining gas after execution. + logs : `Tuple[ethereum.blocks.Log, ...]` + Logs generated during execution. + " in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + M.call (| + M.get_name (| globals, "validate_transaction" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let sender := + M.get_field (| M.get_name (| globals, "env" |), "origin" |) in + let sender_account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |) in + let gas_fee := + BinOp.mult (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "sender_account" |), "nonce" |), M.get_field (| M.get_name (| globals, "tx" |), "nonce" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt_e (| M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), BinOp.add (| + M.get_name (| globals, "gas_fee" |), + M.get_field (| M.get_name (| globals, "tx" |), "value" |) + |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "sender_account" |), "code" |), M.call (| + M.get_name (| globals, "bytearray" |), + make_list [], + make_dict [] + |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let gas := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.call (| + M.get_name (| globals, "calculate_intrinsic_cost" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) in + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |) in + let sender_balance_after_gas_fee := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), + M.get_name (| globals, "gas_fee" |) + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |); + M.get_name (| globals, "sender_balance_after_gas_fee" |) + ], + make_dict [] + |) in + let message := + M.call (| + M.get_name (| globals, "prepare_message" |), + make_list [ + M.get_name (| globals, "sender" |); + M.get_field (| M.get_name (| globals, "tx" |), "to" |); + M.get_field (| M.get_name (| globals, "tx" |), "value" |); + M.get_field (| M.get_name (| globals, "tx" |), "data" |); + M.get_name (| globals, "gas" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let output := + M.call (| + M.get_name (| globals, "process_message_call" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let gas_used := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "output" |), "gas_left" |) + |) in + let gas_refund := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + BinOp.floor_div (| + M.get_name (| globals, "gas_used" |), + Constant.int 2 + |); + M.get_field (| M.get_name (| globals, "output" |), "refund_counter" |) + ], + make_dict [] + |) in + let gas_refund_amount := + BinOp.mult (| + BinOp.add (| + M.get_field (| M.get_name (| globals, "output" |), "gas_left" |), + M.get_name (| globals, "gas_refund" |) + |), + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) + |) in + let transaction_fee := + BinOp.mult (| + BinOp.sub (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "output" |), "gas_left" |) + |), + M.get_name (| globals, "gas_refund" |) + |), + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) + |) in + let total_gas_used := + BinOp.sub (| + M.get_name (| globals, "gas_used" |), + M.get_name (| globals, "gas_refund" |) + |) in + let sender_balance_after_refund := + BinOp.add (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |), "balance" |), + M.get_name (| globals, "gas_refund_amount" |) + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |); + M.get_name (| globals, "sender_balance_after_refund" |) + ], + make_dict [] + |) in + let coinbase_balance_after_mining_fee := + BinOp.add (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |), "balance" |), + M.get_name (| globals, "transaction_fee" |) + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| M.get_name (| globals, "coinbase_balance_after_mining_fee" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |); + M.get_name (| globals, "coinbase_balance_after_mining_fee" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "accounts_to_delete" |) do + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + EndFor. + For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "touched_accounts" |) do + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.return_ (| + make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |) ] + |) in + M.pure Constant.None_)). + +Definition validate_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Verifies a transaction. + + The gas in a transaction gets used to pay for the intrinsic cost of + operations, therefore if there is insufficient gas then it would not + be possible to execute a transaction and it will be declared invalid. + + Additionally, the nonce of a transaction must not equal or exceed the + limit defined in `EIP-2681 `_. + In practice, defining the limit as ``2**64-1`` has no impact because + sending ``2**64-1`` transactions is improbable. It's not strictly + impossible though, ``2**64-1`` transactions is the entire capacity of the + Ethereum blockchain at 2022 gas limits for a little over 22 years. + + Parameters + ---------- + tx : + Transaction to validate. + + Returns + ------- + verified : `bool` + True if the transaction can be executed, or False otherwise. + " in + let _ := M.return_ (| + BoolOp.and (| + Compare.lt_e (| M.call (| + M.get_name (| globals, "calculate_intrinsic_cost" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |), M.get_field (| M.get_name (| globals, "tx" |), "gas" |) |), + ltac:(M.monadic ( + Compare.lt (| M.get_field (| M.get_name (| globals, "tx" |), "nonce" |), BinOp.sub (| + BinOp.pow (| + Constant.int 2, + Constant.int 64 + |), + Constant.int 1 + |) |) + )) + |) + |) in + M.pure Constant.None_)). + +Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Calculates the gas that is charged before execution is started. + + The intrinsic cost of the transaction is charged before execution has + begun. Functions/operations in the EVM cost money to execute so this + intrinsic cost is for the operations that need to be paid for as part of + the transaction. Data transfer, for example, is part of this intrinsic + cost. It costs ether to send data over the wire and that ether is + accounted for in the intrinsic cost calculated in this function. This + intrinsic cost must be calculated and paid for before execution in order + for all operations to be implemented. + + Parameters + ---------- + tx : + Transaction to compute the intrinsic cost of. + + Returns + ------- + verified : `ethereum.base_types.Uint` + The intrinsic cost of the transaction. + " in + let data_cost := + Constant.int 0 in + For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "byte" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + M.pure Constant.None_ + )) |) in + EndFor. + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_name (| globals, "tx" |), "to" |), M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let create_cost := + M.get_name (| globals, "TX_CREATE_COST" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let create_cost := + Constant.int 0 in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "TX_BASE_COST" |), + M.get_name (| globals, "data_cost" |) + |), + M.get_name (| globals, "create_cost" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition recover_sender : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "chain_id"; "tx" ] |) in + let _ := Constant.str " + Extracts the sender address from a transaction. + + The v, r, and s values are the three parts that make up the signature + of a transaction. In order to recover the sender of a transaction the two + components needed are the signature (``v``, ``r``, and ``s``) and the + signing hash of the transaction. The sender's public key can be obtained + with these two values and therefore the sender address can be retrieved. + + Parameters + ---------- + tx : + Transaction of interest. + chain_id : + ID of the executing chain. + + Returns + ------- + sender : `ethereum.fork_types.Address` + The address of the account that signed the transaction. + " in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "v" |); M.get_name (| globals, "r" |); M.get_name (| globals, "s" |) ], + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "v" |); M.get_field (| M.get_name (| globals, "tx" |), "r" |); M.get_field (| M.get_name (| globals, "tx" |), "s" |) ] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.and (| + Compare.lt (| Constant.int 0, M.get_name (| globals, "r" |) |), + ltac:(M.monadic ( + Compare.lt (| M.get_name (| globals, "r" |), M.get_name (| globals, "SECP256K1N" |) |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.and (| + Compare.lt (| Constant.int 0, M.get_name (| globals, "s" |) |), + ltac:(M.monadic ( + Compare.lt_e (| M.get_name (| globals, "s" |), BinOp.floor_div (| + M.get_name (| globals, "SECP256K1N" |), + Constant.int 2 + |) |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.eq (| M.get_name (| globals, "v" |), Constant.int 27 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "v" |), Constant.int 28 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + BinOp.sub (| + M.get_name (| globals, "v" |), + Constant.int 27 + |); + M.call (| + M.get_name (| globals, "signing_hash_pre155" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.or (| + Compare.eq (| M.get_name (| globals, "v" |), BinOp.add (| + Constant.int 35, + BinOp.mult (| + M.get_name (| globals, "chain_id" |), + Constant.int 2 + |) + |) |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "v" |), BinOp.add (| + Constant.int 36, + BinOp.mult (| + M.get_name (| globals, "chain_id" |), + Constant.int 2 + |) + |) |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + BinOp.sub (| + BinOp.sub (| + M.get_name (| globals, "v" |), + Constant.int 35 + |), + BinOp.mult (| + M.get_name (| globals, "chain_id" |), + Constant.int 2 + |) + |); + M.call (| + M.get_name (| globals, "signing_hash_155" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "chain_id" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_subscript (| M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), Constant.int 12:Constant.int 32 |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition signing_hash_pre155 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Compute the hash of a transaction used in a legacy (pre EIP 155) signature. + + Parameters + ---------- + tx : + Transaction of interest. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the transaction. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "nonce" |); M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |); M.get_field (| M.get_name (| globals, "tx" |), "gas" |); M.get_field (| M.get_name (| globals, "tx" |), "to" |); M.get_field (| M.get_name (| globals, "tx" |), "value" |); M.get_field (| M.get_name (| globals, "tx" |), "data" |) ] + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition signing_hash_155 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx"; "chain_id" ] |) in + let _ := Constant.str " + Compute the hash of a transaction used in a EIP 155 signature. + + Parameters + ---------- + tx : + Transaction of interest. + chain_id : + The id of the current chain. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the transaction. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "nonce" |); M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |); M.get_field (| M.get_name (| globals, "tx" |), "gas" |); M.get_field (| M.get_name (| globals, "tx" |), "to" |); M.get_field (| M.get_name (| globals, "tx" |), "value" |); M.get_field (| M.get_name (| globals, "tx" |), "data" |); M.get_name (| globals, "chain_id" |); M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) ] + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition compute_header_hash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header" ] |) in + let _ := Constant.str " + Computes the hash of a block header. + + The header hash of a block is the canonical hash that is used to refer + to a specific block and completely distinguishes a block from another. + + ``keccak256`` is a function that produces a 256 bit hash of any input. + It also takes in any number of bytes as an input and produces a single + hash for them. A hash is a completely unique output for a single input. + So an input corresponds to one unique hash that can be used to identify + the input exactly. + + Prior to using the ``keccak256`` hash function, the header must be + encoded using the Recursive-Length Prefix. See :ref:`rlp`. + RLP encoding the header converts it into a space-efficient format that + allows for easy transfer of data between nodes. The purpose of RLP is to + encode arbitrarily nested arrays of binary data, and RLP is the primary + encoding method used to serialize objects in Ethereum's execution layer. + The only purpose of RLP is to encode structure; encoding specific data + types (e.g. strings, floats) is left up to higher-order protocols. + + Parameters + ---------- + header : + Header of interest. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the header. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "header" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition check_gas_limit : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "gas_limit"; "parent_gas_limit" ] |) in + let _ := Constant.str " + Validates the gas limit for a block. + + The bounds of the gas limit, ``max_adjustment_delta``, is set as the + quotient of the parent block's gas limit and the + ``GAS_LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is + passed through as a parameter is greater than or equal to the *sum* of + the parent's gas and the adjustment delta then the limit for gas is too + high and fails this function's check. Similarly, if the limit is less + than or equal to the *difference* of the parent's gas and the adjustment + delta *or* the predefined ``GAS_LIMIT_MINIMUM`` then this function's + check fails because the gas limit doesn't allow for a sufficient or + reasonable amount of gas to be used on a block. + + Parameters + ---------- + gas_limit : + Gas limit to validate. + + parent_gas_limit : + Gas limit of the parent block. + + Returns + ------- + check : `bool` + True if gas limit constraints are satisfied, False otherwise. + " in + let max_adjustment_delta := + BinOp.floor_div (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "gas_limit" |), BinOp.add (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| M.get_name (| globals, "gas_limit" |), BinOp.sub (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "gas_limit" |), M.get_name (| globals, "GAS_LIMIT_MINIMUM" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + Constant.bool true + |) in + M.pure Constant.None_)). + +Definition calculate_block_difficulty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "block_number"; "block_timestamp"; "parent_timestamp"; "parent_difficulty" ] |) in + let _ := Constant.str " + Computes difficulty of a block using its header and parent header. + + The difficulty is determined by the time the block was created after its + parent. The ``offset`` is calculated using the parent block's difficulty, + ``parent_difficulty``, and the timestamp between blocks. This offset is + then added to the parent difficulty and is stored as the ``difficulty`` + variable. If the time between the block and its parent is too short, the + offset will result in a positive number thus making the sum of + ``parent_difficulty`` and ``offset`` to be a greater value in order to + avoid mass forking. But, if the time is long enough, then the offset + results in a negative value making the block less difficult than + its parent. + + The base standard for a block's difficulty is the predefined value + set for the genesis block since it has no parent. So, a block + can't be less difficult than the genesis block, therefore each block's + difficulty is set to the maximum value between the calculated + difficulty and the ``GENESIS_DIFFICULTY``. + + Parameters + ---------- + block_number : + Block number of the block. + block_timestamp : + Timestamp of the block. + parent_timestamp : + Timestamp of the parent block. + parent_difficulty : + difficulty of the parent block. + + Returns + ------- + difficulty : `ethereum.base_types.Uint` + Computed difficulty for a block. + " in + let offset := + BinOp.mult (| + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "parent_difficulty" |) + ], + make_dict [] + |), + Constant.int 2048 + |), + M.call (| + M.get_name (| globals, "max" |), + make_list [ + BinOp.sub (| + Constant.int 1, + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "block_timestamp" |), + M.get_name (| globals, "parent_timestamp" |) + |) + ], + make_dict [] + |), + Constant.int 10 + |) + |); + UnOp.sub (| Constant.int 99 |) + ], + make_dict [] + |) + |) in + let difficulty := + BinOp.add (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "parent_difficulty" |) + ], + make_dict [] + |), + M.get_name (| globals, "offset" |) + |) in + let num_bomb_periods := + BinOp.sub (| + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "block_number" |) + ], + make_dict [] + |), + Constant.int 100000 + |), + Constant.int 2 + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "num_bomb_periods" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let difficulty := BinOp.add + BinOp.pow (| + Constant.int 2, + M.get_name (| globals, "num_bomb_periods" |) + |) + BinOp.pow (| + Constant.int 2, + M.get_name (| globals, "num_bomb_periods" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "max" |), + make_list [ + M.get_name (| globals, "difficulty" |); + M.get_name (| globals, "MINIMUM_DIFFICULTY" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/fork_types.v b/CoqOfPython/ethereum/spurious_dragon/fork_types.v new file mode 100644 index 0000000..d12953d --- /dev/null +++ b/CoqOfPython/ethereum/spurious_dragon/fork_types.v @@ -0,0 +1,102 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Types +^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Types re-used throughout the specification, which are specific to Ethereum. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes20 : + IsGlobalAlias globals base_types.globals "Bytes20". +Axiom base_types_Bytes256 : + IsGlobalAlias globals base_types.globals "Bytes256". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require crypto.hash. +Axiom crypto_hash_Hash32 : + IsGlobalAlias globals crypto.hash.globals "Hash32". +Axiom crypto_hash_keccak256 : + IsGlobalAlias globals crypto.hash.globals "keccak256". + +Definition Address : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Bytes20" |) +)). + +Definition Root : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Hash32" |) +)). + +Definition Bloom : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Bytes256" |) +)). + +Definition Account : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition EMPTY_ACCOUNT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Account" |), + make_list [], + make_dict [] + |) +)). + +Definition encode_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "raw_account_data"; "storage_root" ] |) in + let _ := Constant.str " + Encode `Account` dataclass. + + Storage is not stored in the `Account` dataclass, so `Accounts` cannot be + encoded with providing a storage root. + " in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "raw_account_data" |), "nonce" |); M.get_field (| M.get_name (| globals, "raw_account_data" |), "balance" |); M.get_name (| globals, "storage_root" |); M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_field (| M.get_name (| globals, "raw_account_data" |), "code" |) + ], + make_dict [] + |) ] + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/state.v b/CoqOfPython/ethereum/spurious_dragon/state.v new file mode 100644 index 0000000..53b3837 --- /dev/null +++ b/CoqOfPython/ethereum/spurious_dragon/state.v @@ -0,0 +1,1031 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +State +^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The state contains all information that is preserved between transactions. + +It consists of a main account trie and storage tries for each contract. + +There is a distinction between an account that does not exist and +`EMPTY_ACCOUNT`. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_field : + IsGlobalAlias globals dataclasses.globals "field". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_modify : + IsGlobalAlias globals ethereum.base_types.globals "modify". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require fork_types. +Axiom fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". +Axiom fork_types_Account : + IsGlobalAlias globals fork_types.globals "Account". +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Require trie. +Axiom trie_EMPTY_TRIE_ROOT : + IsGlobalAlias globals trie.globals "EMPTY_TRIE_ROOT". +Axiom trie_Trie : + IsGlobalAlias globals trie.globals "Trie". +Axiom trie_copy_trie : + IsGlobalAlias globals trie.globals "copy_trie". +Axiom trie_root : + IsGlobalAlias globals trie.globals "root". +Axiom trie_trie_get : + IsGlobalAlias globals trie.globals "trie_get". +Axiom trie_trie_set : + IsGlobalAlias globals trie.globals "trie_set". + +Definition State : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition close_state : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Free resources held by the state. Used by optimized implementations to + release file descriptors. + " in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) |) in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |) in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) in + M.pure Constant.None_)). + +Definition begin_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Start a state transaction. + + Transactions are entirely implicit and can be nested. It is not possible to + calculate the state root during a transaction. + + Parameters + ---------- + state : State + The state. + " in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), "append" |), + make_list [ + make_tuple [ M.call (| + M.get_name (| globals, "copy_trie" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) + ], + make_dict [] + |); {M.get_name (| globals, "k" |): M.call (| + M.get_name (| globals, "copy_trie" |), + make_list [ + M.get_name (| globals, "t" |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)} ] + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition commit_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Commit a state transaction. + + Parameters + ---------- + state : State + The state. + " in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), "pop" |), + make_list [], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition rollback_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Rollback a state transaction, resetting the state to the point when the + corresponding `start_transaction()` call was made. + + Parameters + ---------- + state : State + The state. + " in + let _ := M.assign (| + make_tuple [ M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) ], + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), "pop" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition get_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Get the `Account` object at an address. Returns `EMPTY_ACCOUNT` if there + is no account at the address. + + Use `get_account_optional()` if you care about the difference between a + non-existent account and `EMPTY_ACCOUNT`. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address to lookup. + + Returns + ------- + account : `Account` + Account at address. + " in + let account := + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "account" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "account" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "EMPTY_ACCOUNT" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition get_account_optional : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Get the `Account` object at an address. Returns `None` (rather than + `EMPTY_ACCOUNT`) if there is no account at the address. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address to lookup. + + Returns + ------- + account : `Account` + Account at address. + " in + let account := + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "account" |) + |) in + M.pure Constant.None_)). + +Definition set_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "account" ] |) in + let _ := Constant.str " + Set the `Account` object at an address. Setting to `None` deletes + the account (but not its storage, see `destroy_account()`). + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address to set. + account : `Account` + Account to set at address. + " in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "account" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition destroy_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Completely remove the account at `address` and all of its storage. + + This function is made available exclusively for the `SELFDESTRUCT` + opcode. It is expected that `SELFDESTRUCT` will be disabled in a future + hardfork and this function will be removed. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of account to destroy. + " in + let _ := M.call (| + M.get_name (| globals, "destroy_storage" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + Constant.None_ + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition destroy_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Completely remove the storage at `address`. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of account whose storage is to be deleted. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition get_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "key" ] |) in + let _ := Constant.str " + Get a value at a storage key on an account. Returns `U256(0)` if the + storage key has not been set previously. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of the account. + key : `Bytes` + Key to lookup. + + Returns + ------- + value : `U256` + Value at the key. + " in + let trie := + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let _ := M.assert (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "U256" |) + ], + make_dict [] + |) |) in + let _ := M.return_ (| + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_)). + +Definition set_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "key"; "value" ] |) in + let _ := Constant.str " + Set a value at a storage key on an account. Setting to `U256(0)` deletes + the key. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of the account. + key : `Bytes` + Key to set. + value : `U256` + Value to set at the key. + " in + let _ := M.assert (| Compare.is_not (| M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), Constant.None_ |) |) in + let trie := + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let trie := + M.call (| + M.get_name (| globals, "Trie" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), + M.get_name (| globals, "trie" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "key" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), {} |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition storage_root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Calculate the storage root of an account. + + Parameters + ---------- + state: + The state + address : + Address of the account. + + Returns + ------- + root : `Root` + Storage root of the account. + " in + let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "EMPTY_TRIE_ROOT" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition state_root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Calculate the state root. + + Parameters + ---------- + state: + The current state. + + Returns + ------- + root : `Root` + The state root. + " in + let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition account_exists : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account exists in the state trie + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + account_exists : `bool` + True if account exists in the state trie, False otherwise + " in + let _ := M.return_ (| + Compare.is_not (| M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), Constant.None_ |) + |) in + M.pure Constant.None_)). + +Definition account_has_code_or_nonce : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account has non zero nonce or non empty code + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + has_code_or_nonce : `bool` + True if if an account has non zero nonce or non empty code, + False otherwise. + " in + let account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + BoolOp.or (| + Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |) + )) + |) + |) in + M.pure Constant.None_)). + +Definition is_account_empty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account has zero nonce, empty code and zero balance. + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + is_empty : `bool` + True if if an account has zero nonce, empty code and zero balance, + False otherwise. + " in + let account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + ltac:(M.monadic ( + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + )) + |) + )) + |) + |) in + M.pure Constant.None_)). + +Definition account_exists_and_is_empty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account exists and has zero nonce, empty code and zero + balance. + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + exists_and_is_empty : `bool` + True if an account exists and has zero nonce, empty code and zero + balance, False otherwise. + " in + let account := + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + BoolOp.and (| + Compare.is_not (| M.get_name (| globals, "account" |), Constant.None_ |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + ltac:(M.monadic ( + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + )) + |) + )) + |) + )) + |) + |) in + M.pure Constant.None_)). + +Definition is_account_alive : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Check whether is an account is both in the state and non empty. + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + is_alive : `bool` + True if the account is alive. + " in + let account := + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "account" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + UnOp.not (| BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + ltac:(M.monadic ( + Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + )) + |) + )) + |) |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition modify_state : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "f" ] |) in + let _ := Constant.str " + Modify an `Account` in the `State`. + " in + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.call (| + M.get_name (| globals, "modify" |), + make_list [ + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |); + M.get_name (| globals, "f" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition move_ether : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "sender_address"; "recipient_address"; "amount" ] |) in + let _ := Constant.str " + Move funds between accounts. + " in +(* At stmt: unsupported node type: FunctionDef *) +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "sender_address" |); + M.get_name (| globals, "reduce_sender_balance" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "recipient_address" |); + M.get_name (| globals, "increase_recipient_balance" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition set_account_balance : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "amount" ] |) in + let _ := Constant.str " + Sets the balance of an account. + + Parameters + ---------- + state: + The current state. + + address: + Address of the account whose nonce needs to be incremented. + + amount: + The amount that needs to set in balance. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "set_balance" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition touch_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Initializes an account to state. + + Parameters + ---------- + state: + The current state. + + address: + The address of the account that need to initialised. + " in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "account_exists" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "EMPTY_ACCOUNT" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition increment_nonce : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Increments the nonce of an account. + + Parameters + ---------- + state: + The current state. + + address: + Address of the account whose nonce needs to be incremented. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "increase_nonce" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition set_code : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "code" ] |) in + let _ := Constant.str " + Sets Account code. + + Parameters + ---------- + state: + The current state. + + address: + Address of the account whose code needs to be update. + + code: + The bytecode that needs to be set. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "write_code" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition create_ether : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "amount" ] |) in + let _ := Constant.str " + Add newly created ether to an account. + + Parameters + ---------- + state: + The current state. + address: + Address of the account to which ether is added. + amount: + The amount of ether to be added to the account of interest. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "increase_balance" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/transactions.v b/CoqOfPython/ethereum/spurious_dragon/transactions.v new file mode 100644 index 0000000..6d1bc6b --- /dev/null +++ b/CoqOfPython/ethereum/spurious_dragon/transactions.v @@ -0,0 +1,60 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Transactions are atomic units of work created externally to Ethereum and +submitted to be executed. If Ethereum is viewed as a state machine, +transactions are the events that move between states. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes0 : + IsGlobalAlias globals base_types.globals "Bytes0". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( + Constant.int 21000 +)). + +Definition TX_DATA_COST_PER_NON_ZERO : Value.t := M.run ltac:(M.monadic ( + Constant.int 68 +)). + +Definition TX_DATA_COST_PER_ZERO : Value.t := M.run ltac:(M.monadic ( + Constant.int 4 +)). + +Definition TX_CREATE_COST : Value.t := M.run ltac:(M.monadic ( + Constant.int 32000 +)). + +Definition Transaction : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. diff --git a/CoqOfPython/ethereum/spurious_dragon/trie.v b/CoqOfPython/ethereum/spurious_dragon/trie.v new file mode 100644 index 0000000..8ec85fb --- /dev/null +++ b/CoqOfPython/ethereum/spurious_dragon/trie.v @@ -0,0 +1,1357 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +State Trie +^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The state trie is the structure responsible for storing +`.fork_types.Account` objects. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_field : + IsGlobalAlias globals dataclasses.globals "field". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". +Axiom typing_Generic : + IsGlobalAlias globals typing.globals "Generic". +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Mapping : + IsGlobalAlias globals typing.globals "Mapping". +Axiom typing_MutableMapping : + IsGlobalAlias globals typing.globals "MutableMapping". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Sequence : + IsGlobalAlias globals typing.globals "Sequence". +Axiom typing_TypeVar : + IsGlobalAlias globals typing.globals "TypeVar". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". +Axiom typing_cast : + IsGlobalAlias globals typing.globals "cast". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.tangerine_whistle. +Axiom ethereum_tangerine_whistle_trie : + IsGlobalAlias globals ethereum.tangerine_whistle.globals "trie". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require ethereum.utils.hexadecimal. +Axiom ethereum_utils_hexadecimal_hex_to_bytes : + IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require blocks. +Axiom blocks_Receipt : + IsGlobalAlias globals blocks.globals "Receipt". + +Require fork_types. +Axiom fork_types_Account : + IsGlobalAlias globals fork_types.globals "Account". +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". +Axiom fork_types_encode_account : + IsGlobalAlias globals fork_types.globals "encode_account". + +Require transactions. +Axiom transactions_Transaction : + IsGlobalAlias globals transactions.globals "Transaction". + +Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Root" |), + make_list [ + M.call (| + M.get_name (| globals, "hex_to_bytes" |), + make_list [ + Constant.str "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" + ], + make_dict [] + |) + ], + make_dict [] + |) +)). + +Definition Node : Value.t := M.run ltac:(M.monadic ( + M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Bytes" |); M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |); Constant.None_ ] |) +)). + +Definition K : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "TypeVar" |), + make_list [ + Constant.str "K" + ], + make_dict [] + |) +)). + +Definition V : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "TypeVar" |), + make_list [ + Constant.str "V"; + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Account" |) |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Bytes" |) |); + M.get_name (| globals, "Bytes" |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Transaction" |) |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Receipt" |) |); + M.get_name (| globals, "Uint" |); + M.get_name (| globals, "U256" |) + ], + make_dict [] + |) +)). + +Definition LeafNode : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition ExtensionNode : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition BranchNode : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition InternalNode : Value.t := M.run ltac:(M.monadic ( + M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LeafNode" |); M.get_name (| globals, "ExtensionNode" |); M.get_name (| globals, "BranchNode" |) ] |) +)). + +Definition encode_internal_node : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "node" ] |) in + let _ := Constant.str " + Encodes a Merkle Trie node into its RLP form. The RLP will then be + serialized into a `Bytes` and hashed unless it is less that 32 bytes + when serialized. + + This function also accepts `None`, representing the absence of a node, + which is encoded to `b""""""`. + + Parameters + ---------- + node : Optional[InternalNode] + The node to encode. + + Returns + ------- + encoded : `rlp.RLP` + The node encoded as RLP. + " in +(* At stmt: unsupported node type: AnnAssign *) + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "node" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let unencoded := + (* At constant: unsupported node type: Constant *) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "LeafNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "rest_of_key" |); + Constant.bool true + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "ExtensionNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "key_segment" |); + Constant.bool false + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "BranchNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + BinOp.add (| + M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "value" |) + ] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "AssertionError" |), + make_list [ + (* At expr: unsupported node type: JoinedStr *) + ], + make_dict [] + |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let encoded := + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "unencoded" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded" |) + ], + make_dict [] + |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "unencoded" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "encoded" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition encode_node : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "node"; "storage_root" ] |) in + let _ := Constant.str " + Encode a Node for storage in the Merkle Trie. + + Currently mostly an unimplemented stub. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "storage_root" |), Constant.None_ |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "encode_account" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "storage_root" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + make_tuple [ M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "U256" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "cast" |), + make_list [ + M.get_field (| M.get_name (| globals, "rlp" |), "RLP" |); + M.get_name (| globals, "node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "node" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "previous_trie" |), "encode_node" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "storage_root" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition Trie : Value.t := + builtins.make_klass + [(* At base: unsupported node type: Subscript *)] + [ + + ] + [ + + ]. + +Definition copy_trie : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie" ] |) in + let _ := Constant.str " + Create a copy of `trie`. Since only frozen objects may be stored in tries, + the contents are reused. + + Parameters + ---------- + trie: `Trie` + Trie to copy. + + Returns + ------- + new_trie : `Trie[K, V]` + A copy of the trie. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Trie" |), + make_list [ + M.get_field (| M.get_name (| globals, "trie" |), "secured" |); + M.get_field (| M.get_name (| globals, "trie" |), "default" |); + M.call (| + M.get_field (| M.get_name (| globals, "copy" |), "copy" |), + make_list [ + M.get_field (| M.get_name (| globals, "trie" |), "_data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition trie_set : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "key"; "value" ] |) in + let _ := Constant.str " + Stores an item in a Merkle Trie. + + This method deletes the key if `value == trie.default`, because the Merkle + Trie represents the default value by omitting it from the trie. + + Parameters + ---------- + trie: `Trie` + Trie to store in. + key : `Bytes` + Key to lookup. + value : `V` + Node to insert at `key`. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "value" |), M.get_field (| M.get_name (| globals, "trie" |), "default" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "key" |), M.get_field (| M.get_name (| globals, "trie" |), "_data" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition trie_get : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "key" ] |) in + let _ := Constant.str " + Gets an item from the Merkle Trie. + + This method returns `trie.default` if the key is missing. + + Parameters + ---------- + trie: + Trie to lookup in. + key : + Key to lookup. + + Returns + ------- + node : `V` + Node at `key` in the trie. + " in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "get" |), + make_list [ + M.get_name (| globals, "key" |); + M.get_field (| M.get_name (| globals, "trie" |), "default" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition common_prefix_length : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "a"; "b" ] |) in + let _ := Constant.str " + Find the longest common prefix of two sequences. + " in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + ], + make_dict [] + |) do + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| M.get_name (| globals, "i" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition nibble_list_to_compact : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "x"; "is_leaf" ] |) in + let _ := Constant.str " + Compresses nibble-list into a standard byte array with a flag. + + A nibble-list is a list of byte values no greater than `15`. The flag is + encoded in high nibble of the highest byte. The flag nibble can be broken + down into two two-bit flags. + + Highest nibble:: + + +---+---+----------+--------+ + | _ | _ | is_leaf | parity | + +---+---+----------+--------+ + 3 2 1 0 + + + The lowest bit of the nibble encodes the parity of the length of the + remaining nibbles -- `0` when even and `1` when odd. The second lowest bit + is used to distinguish leaf and extension nodes. The other two bits are not + used. + + Parameters + ---------- + x : + Array of nibbles. + is_leaf : + True if this is part of a leaf node, or false if it is an extension + node. + + Returns + ------- + compressed : `bytearray` + Compact byte array. + " in + let compact := + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + Constant.int 2 + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.mult (| + Constant.int 16, + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "is_leaf" |) + |) + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + BinOp.add (| + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "is_leaf" |) + |), + Constant.int 1 + |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), Constant.int 0 |) + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 1; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + M.get_name (| globals, "compact" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition bytes_to_nibble_list : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "bytes_" ] |) in + let _ := Constant.str " + Converts a `Bytes` into to a sequence of nibbles (bytes with value < 16). + + Parameters + ---------- + bytes_: + The `Bytes` to convert. + + Returns + ------- + nibble_list : `Bytes` + The `Bytes` in nibble-list format. + " in + let nibble_list := + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [ + BinOp.mult (| + Constant.int 2, + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "bytes_" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + For make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ] in M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "bytes_" |) + ], + make_dict [] + |) do + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |) |), + BinOp.r_shift (| + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 240 + |), + Constant.int 4 + |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |), + Constant.int 1 + |) |), + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 15 + |) + |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + M.get_name (| globals, "nibble_list" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition _prepare_trie : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "get_storage_root" ] |) in + let _ := Constant.str " + Prepares the trie for root calculation. Removes values that are empty, + hashes the keys (if `secured == True`) and encodes all the nodes. + + Parameters + ---------- + trie : + The `Trie` to prepare. + get_storage_root : + Function to get the storage root of an account. Needed to encode + `Account` objects. + + Returns + ------- + out : `Mapping[ethereum.base_types.Bytes, Node]` + Object with keys mapped to nibble-byte form. + " in +(* At stmt: unsupported node type: AnnAssign *) + For make_tuple [ M.get_name (| globals, "preimage" |); M.get_name (| globals, "value" |) ] in M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "items" |), + make_list [], + make_dict [] + |) do + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in + let address := + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |); + M.call (| + M.get_name (| globals, "get_storage_root" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_eq (| M.get_name (| globals, "encoded_value" |), (* At constant: unsupported node type: Constant *) |); + M.get_name (| globals, "AssertionError" |) + ], + make_dict [] + |) in +(* At stmt: unsupported node type: AnnAssign *) + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "trie" |), "secured" |), + (* then *) + ltac:(M.monadic ( + let key := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let key := + M.get_name (| globals, "preimage" |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "mapped" |), M.call (| + M.get_name (| globals, "bytes_to_nibble_list" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |) |), + M.get_name (| globals, "encoded_value" |) + |) in + EndFor. + let _ := M.return_ (| + M.get_name (| globals, "mapped" |) + |) in + M.pure Constant.None_)). + +Definition root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "get_storage_root" ] |) in + let _ := Constant.str " + Computes the root of a modified merkle patricia trie (MPT). + + Parameters + ---------- + trie : + `Trie` to get the root of. + get_storage_root : + Function to get the storage root of an account. Needed to encode + `Account` objects. + + + Returns + ------- + root : `.fork_types.Root` + MPT root of the underlying key-value pairs. + " in + let obj := + M.call (| + M.get_name (| globals, "_prepare_trie" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "get_storage_root" |) + ], + make_dict [] + |) in + let root_node := + M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_name (| globals, "obj" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assert (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "root_node" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Root" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition patricialize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "obj"; "level" ] |) in + let _ := Constant.str " + Structural composition function. + + Used to recursively patricialize and merkleize a dictionary. Includes + memoization of the tree structure and hashes. + + Parameters + ---------- + obj : + Underlying trie key-value pairs, with keys in nibble-list format. + level : + Current trie level. + + Returns + ------- + node : `ethereum.base_types.Bytes` + Root node of `obj`. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let arbitrary_key := + M.call (| + M.get_name (| globals, "next" |), + make_list [ + M.call (| + M.get_name (| globals, "iter" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), Constant.int 1 |), + (* then *) + ltac:(M.monadic ( + let leaf := + M.call (| + M.get_name (| globals, "LeafNode" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |); + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "leaf" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let substring := + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) in + let prefix_length := + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "substring" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do + let prefix_length := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_name (| globals, "prefix_length" |); + M.call (| + M.get_name (| globals, "common_prefix_length" |), + make_list [ + M.get_name (| globals, "substring" |); + M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let prefix := + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ExtensionNode" |), + make_list [ + M.get_name (| globals, "prefix" |); + M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_name (| globals, "obj" |); + BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in +(* At stmt: unsupported node type: AnnAssign *) + For M.get_name (| globals, "_" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 16 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "branches" |), "append" |), + make_list [ + {} + ], + make_dict [] + |) in + EndFor. + let value := + (* At constant: unsupported node type: Constant *) in + For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |), M.get_name (| globals, "level" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "AssertionError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) + |) in + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "BranchNode" |), + make_list [ + [M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "branches" |), M.get_name (| globals, "k" |) |); + BinOp.add (| + M.get_name (| globals, "level" |), + Constant.int 1 + |) + ], + make_dict [] + |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)]; + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/utils/__init__.v b/CoqOfPython/ethereum/spurious_dragon/utils/__init__.v new file mode 100644 index 0000000..1baedea --- /dev/null +++ b/CoqOfPython/ethereum/spurious_dragon/utils/__init__.v @@ -0,0 +1,8 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Utility functions unique to this particular fork. +". diff --git a/CoqOfPython/ethereum/spurious_dragon/utils/address.v b/CoqOfPython/ethereum/spurious_dragon/utils/address.v new file mode 100644 index 0000000..65b1ac7 --- /dev/null +++ b/CoqOfPython/ethereum/spurious_dragon/utils/address.v @@ -0,0 +1,134 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Hardfork Utility Functions For Addresses +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Address specific functions used in this spurious dragon version of +specification. +". + +Require typing. +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_left_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Definition to_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "data" ] |) in + let _ := Constant.str " + Convert a Uint or U256 value to a valid address (20 bytes). + + Parameters + ---------- + data : + The string to be converted to bytes. + + Returns + ------- + address : `Address` + The obtained address. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_subscript (| M.call (| + M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition compute_contract_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "address"; "nonce" ] |) in + let _ := Constant.str " + Computes address of the new account that needs to be created. + + Parameters + ---------- + address : + The address of the account that wants to create the new account. + nonce : + The transaction count of the account that wants to create the new + account. + + Returns + ------- + address: `ethereum.spurious_dragon.fork_types.Address` + The computed address of the new account. + " in + let computed_address := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_list [ + M.get_name (| globals, "address" |); + M.get_name (| globals, "nonce" |) + ] + ], + make_dict [] + |) + ], + make_dict [] + |) in + let canonical_address := + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + let padded_address := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "canonical_address" |); + Constant.int 20 + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "padded_address" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/utils/hexadecimal.v b/CoqOfPython/ethereum/spurious_dragon/utils/hexadecimal.v new file mode 100644 index 0000000..0c93e84 --- /dev/null +++ b/CoqOfPython/ethereum/spurious_dragon/utils/hexadecimal.v @@ -0,0 +1,155 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Utility Functions For Hexadecimal Strings +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Hexadecimal utility functions used in this specification, specific to +Spurious Dragon types. +". + +Require ethereum.utils.hexadecimal. +Axiom ethereum_utils_hexadecimal_remove_hex_prefix : + IsGlobalAlias globals ethereum.utils.hexadecimal.globals "remove_hex_prefix". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Definition hex_to_root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to trie root. + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to trie root. + + Returns + ------- + root : `Root` + Trie root obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Root" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition hex_to_bloom : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to bloom. + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to bloom. + + Returns + ------- + bloom : `Bloom` + Bloom obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bloom" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition hex_to_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to Address (20 bytes). + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to Address. + + Returns + ------- + address : `Address` + The address obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |), "rjust" |), + make_list [ + Constant.int 40; + Constant.str "0" + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/utils/message.v b/CoqOfPython/ethereum/spurious_dragon/utils/message.v new file mode 100644 index 0000000..11d0d76 --- /dev/null +++ b/CoqOfPython/ethereum/spurious_dragon/utils/message.v @@ -0,0 +1,198 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Hardfork Utility Functions For The Message Data-structure +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Message specific functions used in this spurious dragon version of +specification. +". + +Require typing. +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". + +Require vm. +Axiom vm_Environment : + IsGlobalAlias globals vm.globals "Environment". +Axiom vm_Message : + IsGlobalAlias globals vm.globals "Message". + +Require address. +Axiom address_compute_contract_address : + IsGlobalAlias globals address.globals "compute_contract_address". + +Definition prepare_message : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "caller"; "target"; "value"; "data"; "gas"; "env"; "code_address"; "should_transfer_value" ] |) in + let _ := Constant.str " + Execute a transaction against the provided environment. + + Parameters + ---------- + caller : + Address which initiated the transaction + target : + Address whose code will be executed + value : + Value to be transferred. + data : + Array of bytes provided to the code in `target`. + gas : + Gas provided for the code in `target`. + env : + Environment for the Ethereum Virtual Machine. + code_address : + This is usually same as the `target` address except when an alternative + accounts code needs to be executed. + eg. `CALLCODE` calling a precompile. + should_transfer_value : + if True ETH should be transferred while executing a message call. + + Returns + ------- + message: `ethereum.spurious_dragon.vm.Message` + Items containing contract creation or message call specific data. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Bytes0" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.call (| + M.get_name (| globals, "compute_contract_address" |), + make_list [ + M.get_name (| globals, "caller" |); + BinOp.sub (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "caller" |) + ], + make_dict [] + |), "nonce" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let msg_data := + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |) in + let code := + M.get_name (| globals, "data" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.get_name (| globals, "target" |) in + let msg_data := + M.get_name (| globals, "data" |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "target" |) + ], + make_dict [] + |), "code" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "code_address" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let code_address := + M.get_name (| globals, "target" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "AssertionError" |), + make_list [ + Constant.str "Target must be address or empty bytes" + ], + make_dict [] + |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/__init__.v b/CoqOfPython/ethereum/spurious_dragon/vm/__init__.v new file mode 100644 index 0000000..520603e --- /dev/null +++ b/CoqOfPython/ethereum/spurious_dragon/vm/__init__.v @@ -0,0 +1,244 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The abstract computer which runs the code stored in an +`.fork_types.Account`. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_State : + IsGlobalAlias globals state.globals "State". +Axiom state_account_exists_and_is_empty : + IsGlobalAlias globals state.globals "account_exists_and_is_empty". + +Require precompiled_contracts. +Axiom precompiled_contracts_RIPEMD160_ADDRESS : + IsGlobalAlias globals precompiled_contracts.globals "RIPEMD160_ADDRESS". + +Definition __all__ : Value.t := M.run ltac:(M.monadic ( + make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] +)). + +Definition Environment : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Message : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Evm : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition incorporate_child_on_success : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "child_evm" ] |) in + let _ := Constant.str " + Incorporate the state of a successful `child_evm` into the parent `evm`. + + Parameters + ---------- + evm : + The parent `EVM`. + child_evm : + The child evm to incorporate. + " in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "gas_left" |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "logs" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "logs" |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "refund_counter" |) + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "accounts_to_delete" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition incorporate_child_on_error : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "child_evm" ] |) in + let _ := Constant.str " + Incorporate the state of an unsuccessful `child_evm` into the parent `evm`. + + Parameters + ---------- + evm : + The parent `EVM`. + child_evm : + The child evm to incorporate. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "RIPEMD160_ADDRESS" |), M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |), M.get_name (| globals, "RIPEMD160_ADDRESS" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "gas_left" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/exceptions.v b/CoqOfPython/ethereum/spurious_dragon/vm/exceptions.v new file mode 100644 index 0000000..45435b3 --- /dev/null +++ b/CoqOfPython/ethereum/spurious_dragon/vm/exceptions.v @@ -0,0 +1,122 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Exceptions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Exceptions which cause the EVM to halt exceptionally. +". + +Require ethereum.exceptions. +Axiom ethereum_exceptions_EthereumException : + IsGlobalAlias globals ethereum.exceptions.globals "EthereumException". + +Definition ExceptionalHalt : Value.t := + builtins.make_klass + [(globals, "EthereumException")] + [ + + ] + [ + + ]. + +Definition StackUnderflowError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition StackOverflowError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition OutOfGasError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition InvalidOpcode : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + ( + "__init__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "code" ] |) in + let _ := M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "super" |), + make_list [], + make_dict [] + |), "__init__" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "self" |), "code" |), + M.get_name (| globals, "code" |) + |) in + M.pure Constant.None_)) + ) + ]. + +Definition InvalidJumpDestError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition StackDepthLimitError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition AddressCollision : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/__init__.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/__init__.v new file mode 100644 index 0000000..e5bebd7 --- /dev/null +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/__init__.v @@ -0,0 +1,87 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +EVM Instruction Encoding (Opcodes) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Machine readable representations of EVM instructions, and a mapping to their +implementations. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". + +Require __init__. +Axiom __init___arithmetic : + IsGlobalAlias globals __init__.globals "arithmetic". + +Require __init__. +Axiom __init___bitwise : + IsGlobalAlias globals __init__.globals "bitwise". + +Require __init__. +Axiom __init___block : + IsGlobalAlias globals __init__.globals "block". + +Require __init__. +Axiom __init___comparison : + IsGlobalAlias globals __init__.globals "comparison". + +Require __init__. +Axiom __init___control_flow : + IsGlobalAlias globals __init__.globals "control_flow". + +Require __init__. +Axiom __init___environment : + IsGlobalAlias globals __init__.globals "environment". + +Require __init__. +Axiom __init___keccak : + IsGlobalAlias globals __init__.globals "keccak". + +Require __init__. +Axiom __init___log : + IsGlobalAlias globals __init__.globals "log". + +Require __init__. +Axiom __init___memory : + IsGlobalAlias globals __init__.globals "memory". + +Require __init__. +Axiom __init___stack : + IsGlobalAlias globals __init__.globals "stack". + +Require __init__. +Axiom __init___storage : + IsGlobalAlias globals __init__.globals "storage". + +Require __init__. +Axiom __init___system : + IsGlobalAlias globals __init__.globals "system". + +Definition Ops : Value.t := + builtins.make_klass + [(* At base: unsupported node type: Attribute *)] + [ + + ] + [ + + ]. + +(* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/arithmetic.v new file mode 100644 index 0000000..a8b5c61 --- /dev/null +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/arithmetic.v @@ -0,0 +1,1085 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Arithmetic Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM Arithmetic instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U255_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U255_CEIL_VALUE". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_U256_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_get_sign : + IsGlobalAlias globals ethereum.utils.numeric.globals "get_sign". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_EXPONENTIATION : + IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION". +Axiom gas_GAS_EXPONENTIATION_PER_BYTE : + IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION_PER_BYTE". +Axiom gas_GAS_LOW : + IsGlobalAlias globals gas.globals "GAS_LOW". +Axiom gas_GAS_MID : + IsGlobalAlias globals gas.globals "GAS_MID". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition add : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Adds the top two elements of the stack together, and pushes the result back + on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "x" |), "wrapping_add" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition sub : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Subtracts the top two elements of the stack, and pushes the result back + on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "x" |), "wrapping_sub" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mul : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Multiply the top two elements of the stack, and pushes the result back + on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "x" |), "wrapping_mul" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition div : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Integer division of the top two elements of the stack. Pushes the result + back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let dividend := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let divisor := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let quotient := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let quotient := + BinOp.floor_div (| + M.get_name (| globals, "dividend" |), + M.get_name (| globals, "divisor" |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "quotient" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition sdiv : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed integer division of the top two elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let dividend := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let divisor := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let quotient := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_name (| globals, "dividend" |), UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "divisor" |), UnOp.sub (| Constant.int 1 |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let quotient := + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let sign := + M.call (| + M.get_name (| globals, "get_sign" |), + make_list [ + BinOp.mult (| + M.get_name (| globals, "dividend" |), + M.get_name (| globals, "divisor" |) + |) + ], + make_dict [] + |) in + let quotient := + BinOp.mult (| + M.get_name (| globals, "sign" |), + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "dividend" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "divisor" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + M.get_name (| globals, "quotient" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Modulo remainder of the top two elements of the stack. Pushes the result + back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let remainder := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let remainder := + BinOp.mod_ (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "remainder" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition smod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed modulo remainder of the top two elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let y := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let remainder := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let remainder := + BinOp.mult (| + M.call (| + M.get_name (| globals, "get_sign" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + BinOp.mod_ (| + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + M.get_name (| globals, "remainder" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition addmod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Modulo addition of the top 2 elements with the 3rd element. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let z := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_MID" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.add (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |), + M.get_name (| globals, "z" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mulmod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Modulo multiplication of the top 2 elements with the 3rd element. Pushes + the result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let z := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_MID" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.mult (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |), + M.get_name (| globals, "z" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition exp : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Exponential operation of the top 2 elements. Pushes the result back on + the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let base := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exponent := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exponent_bits := + M.call (| + M.get_field (| M.get_name (| globals, "exponent" |), "bit_length" |), + make_list [], + make_dict [] + |) in + let exponent_bytes := + BinOp.floor_div (| + BinOp.add (| + M.get_name (| globals, "exponent_bits" |), + Constant.int 7 + |), + Constant.int 8 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_EXPONENTIATION" |), + BinOp.mult (| + M.get_name (| globals, "GAS_EXPONENTIATION_PER_BYTE" |), + M.get_name (| globals, "exponent_bytes" |) + |) + |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "pow" |), + make_list [ + M.get_name (| globals, "base" |); + M.get_name (| globals, "exponent" |); + M.get_name (| globals, "U256_CEIL_VALUE" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition signextend : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Sign extend operation. In other words, extend a signed number which + fits in N bytes to 32 bytes. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let byte_num := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "byte_num" |), Constant.int 31 |), + (* then *) + ltac:(M.monadic ( + let result := + M.get_name (| globals, "value" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let value_bytes := + M.call (| + M.get_name (| globals, "bytes" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "value" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) in + let value_bytes := + M.get_subscript (| M.get_name (| globals, "value_bytes" |), BinOp.sub (| + Constant.int 31, + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "byte_num" |) + ], + make_dict [] + |) + |):(* At expr: unsupported node type: NoneType *) |) in + let sign_bit := + BinOp.r_shift (| + M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), + Constant.int 7 + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "sign_bit" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "value_bytes" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let num_bytes_prepend := + BinOp.sub (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "byte_num" |), + Constant.int 1 + |) + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + BinOp.add (| + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [ + BinOp.mult (| + make_list [ + Constant.int 255 + ], + M.get_name (| globals, "num_bytes_prepend" |) + |) + ], + make_dict [] + |), + M.get_name (| globals, "value_bytes" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/bitwise.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/bitwise.v new file mode 100644 index 0000000..b20a1e5 --- /dev/null +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/bitwise.v @@ -0,0 +1,345 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Bitwise Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM bitwise instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition bitwise_and : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise AND operation of the top 2 elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + BinOp.bit_and (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_or : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise OR operation of the top 2 elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + BinOp.bit_or (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_xor : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise XOR operation of the top 2 elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + BinOp.bit_xor (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_not : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise NOT operation of the top element of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + UnOp.invert (| M.get_name (| globals, "x" |) |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition get_byte : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + For a word (defined by next top element of the stack), retrieve the + Nth byte (0-indexed and defined by top element of stack) from the + left (most significant) to right (least significant). + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let byte_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let word := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "byte_index" |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let extra_bytes_to_right := + BinOp.sub (| + Constant.int 31, + M.get_name (| globals, "byte_index" |) + |) in + let word := + BinOp.r_shift (| + M.get_name (| globals, "word" |), + BinOp.mult (| + M.get_name (| globals, "extra_bytes_to_right" |), + Constant.int 8 + |) + |) in + let word := + BinOp.bit_and (| + M.get_name (| globals, "word" |), + Constant.int 255 + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "word" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/block.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/block.v new file mode 100644 index 0000000..e5fa554 --- /dev/null +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/block.v @@ -0,0 +1,337 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Block Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM block instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_BLOCK_HASH : + IsGlobalAlias globals gas.globals "GAS_BLOCK_HASH". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition block_hash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the hash of one of the 256 most recent complete blocks onto the + stack. The block number to hash is present at the top of the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let block_number := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BLOCK_HASH" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt_e (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), M.get_name (| globals, "block_number" |) |), + ltac:(M.monadic ( + Compare.gt (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), BinOp.add (| + M.get_name (| globals, "block_number" |), + Constant.int 256 + |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let hash := + (* At constant: unsupported node type: Constant *) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let hash := + M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + M.get_name (| globals, "block_number" |) + |) |) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "hash" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition coinbase : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's beneficiary address (address of the block miner) + onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "coinbase" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition timestamp : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's timestamp onto the stack. Here the timestamp + being referred is actually the unix timestamp in seconds. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "time" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition number : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's number onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition difficulty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's difficulty onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "difficulty" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition gas_limit : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's gas limit onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "gas_limit" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/comparison.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/comparison.v new file mode 100644 index 0000000..fbc35f8 --- /dev/null +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/comparison.v @@ -0,0 +1,404 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Comparison Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM Comparison instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition less_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is less than the next top element. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let right := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition signed_less_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed less-than comparison. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let right := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition greater_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is greater than the next top element. Pushes + the result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let right := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition signed_greater_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed greater-than comparison. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let right := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition equal : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is equal to the next top element. Pushes + the result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let right := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.eq (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition is_zero : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is equal to 0. Pushes the result back on the + stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.eq (| M.get_name (| globals, "x" |), Constant.int 0 |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/control_flow.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/control_flow.v new file mode 100644 index 0000000..04a79d9 --- /dev/null +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/control_flow.v @@ -0,0 +1,336 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Control Flow Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM control flow instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require vm.gas. +Axiom vm_gas_GAS_BASE : + IsGlobalAlias globals vm.gas.globals "GAS_BASE". +Axiom vm_gas_GAS_HIGH : + IsGlobalAlias globals vm.gas.globals "GAS_HIGH". +Axiom vm_gas_GAS_JUMPDEST : + IsGlobalAlias globals vm.gas.globals "GAS_JUMPDEST". +Axiom vm_gas_GAS_MID : + IsGlobalAlias globals vm.gas.globals "GAS_MID". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_InvalidJumpDestError : + IsGlobalAlias globals exceptions.globals "InvalidJumpDestError". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition stop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stop further execution of EVM code. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let _ := M.pass (| |) in + let _ := M.pass (| |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "running" |), + Constant.bool false + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition jump : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Alter the program counter to the location specified by the top of the + stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let jump_dest := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_MID" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "jump_dest" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition jumpi : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Alter the program counter to the specified location if and only if a + condition is true. If the condition is not true, then the program counter + would increase only by 1. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let jump_dest := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let conditional_value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_HIGH" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "conditional_value" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let destination := + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let destination := + M.get_name (| globals, "jump_dest" |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "destination" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition pc : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push onto the stack the value of the program counter after reaching the + current instruction and without increasing it for the next instruction. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "pc" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition gas_left : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the amount of available gas (including the corresponding reduction + for the cost of this instruction) onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition jumpdest : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Mark a valid destination for jumps. This is a noop, present only + to be used by `JUMP` and `JUMPI` opcodes to verify that their jump is + valid. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_JUMPDEST" |) + ], + make_dict [] + |) in + let _ := M.pass (| |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/environment.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/environment.v new file mode 100644 index 0000000..4d26a46 --- /dev/null +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/environment.v @@ -0,0 +1,943 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Environmental Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM environment related instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require state. +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". + +Require utils.address. +Axiom utils_address_to_address : + IsGlobalAlias globals utils.address.globals "to_address". + +Require vm.memory. +Axiom vm_memory_buffer_read : + IsGlobalAlias globals vm.memory.globals "buffer_read". +Axiom vm_memory_memory_write : + IsGlobalAlias globals vm.memory.globals "memory_write". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_BALANCE : + IsGlobalAlias globals gas.globals "GAS_BALANCE". +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_COPY : + IsGlobalAlias globals gas.globals "GAS_COPY". +Axiom gas_GAS_EXTERNAL : + IsGlobalAlias globals gas.globals "GAS_EXTERNAL". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the address of the current executing account to the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition balance : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the balance of the given account onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BALANCE" |) + ], + make_dict [] + |) in + let balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "balance" |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "balance" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition origin : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the address of the original transaction sender to the stack. + The origin address can only be an EOA. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "origin" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition caller : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the address of the caller onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "caller" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition callvalue : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the value (in wei) sent with the call onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition calldataload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push a word (32 bytes) of the input data belonging to the current + environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |); + M.get_name (| globals, "start_index" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition calldatasize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the size of input data in current environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition calldatacopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy a portion of the input data in current environment to memory. + + This will also expand the memory, in case that the memory is insufficient + to store the data. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let data_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |); + M.get_name (| globals, "data_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition codesize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the size of code running in current environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "code" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition codecopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy a portion of the code in current environment to memory. + + This will also expand the memory, in case that the memory is insufficient + to store the data. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let code_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "code" |); + M.get_name (| globals, "code_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition gasprice : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the gas price used in current environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "gas_price" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition extcodesize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the code size of a given account onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_EXTERNAL" |) + ], + make_dict [] + |) in + let codesize := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "code" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "codesize" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition extcodecopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy a portion of an account's code to memory. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let code_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_EXTERNAL" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "code" |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "code" |); + M.get_name (| globals, "code_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/keccak.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/keccak.v new file mode 100644 index 0000000..cab9ffb --- /dev/null +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/keccak.v @@ -0,0 +1,181 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Keccak Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM keccak instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_KECCAK256 : + IsGlobalAlias globals gas.globals "GAS_KECCAK256". +Axiom gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition keccak : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes to the stack the Keccak-256 hash of a region of memory. + + This also expands the memory, in case the memory is insufficient to + access the data's memory location. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let word_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_KECCAK256_WORD" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_KECCAK256" |), + M.get_name (| globals, "word_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let data := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "hash" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/log.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/log.v new file mode 100644 index 0000000..f246f9d --- /dev/null +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/log.v @@ -0,0 +1,228 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Logging Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM logging instructions. +". + +Require functools. +Axiom functools_partial : + IsGlobalAlias globals functools.globals "partial". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_LOG : + IsGlobalAlias globals gas.globals "GAS_LOG". +Axiom gas_GAS_LOG_DATA : + IsGlobalAlias globals gas.globals "GAS_LOG_DATA". +Axiom gas_GAS_LOG_TOPIC : + IsGlobalAlias globals gas.globals "GAS_LOG_TOPIC". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". + +Definition log_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "num_topics" ] |) in + let _ := Constant.str " + Appends a log entry, having `num_topics` topics, to the evm logs. + + This will also expand the memory if the data (required by the log entry) + corresponding to the memory is not accessible. + + Parameters + ---------- + evm : + The current EVM frame. + num_topics : + The number of topics to be included in the log entry. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let topics := + make_list [] in + For M.get_name (| globals, "_" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "num_topics" |) + ], + make_dict [] + |) do + let topic := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "topics" |), "append" |), + make_list [ + M.get_name (| globals, "topic" |) + ], + make_dict [] + |) in + EndFor. + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_LOG" |), + BinOp.mult (| + M.get_name (| globals, "GAS_LOG_DATA" |), + M.get_name (| globals, "size" |) + |) + |), + BinOp.mult (| + M.get_name (| globals, "GAS_LOG_TOPIC" |), + M.get_name (| globals, "num_topics" |) + |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let log_entry := + M.call (| + M.get_name (| globals, "Log" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "logs" |), + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "logs" |), + make_tuple [ M.get_name (| globals, "log_entry" |) ] + |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition log0 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/memory.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/memory.v new file mode 100644 index 0000000..1e1c8b0 --- /dev/null +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/memory.v @@ -0,0 +1,378 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Memory Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM Memory instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". +Axiom memory_memory_write : + IsGlobalAlias globals memory.globals "memory_write". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition mstore : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a word to memory. + This also expands the memory, if the memory is + insufficient to store the word. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "start_position" |); M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + ], + make_dict [] + |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "start_position" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mstore8 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a byte to memory. + This also expands the memory, if the memory is + insufficient to store the word. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "start_position" |); M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let normalized_bytes_value := + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + make_list [ + BinOp.bit_and (| + M.get_name (| globals, "value" |), + Constant.int 255 + |) + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "start_position" |); + M.get_name (| globals, "normalized_bytes_value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Load word from memory. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "start_position" |); M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "start_position" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition msize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the size of active memory in bytes onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/stack.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/stack.v new file mode 100644 index 0000000..1eeda05 --- /dev/null +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/stack.v @@ -0,0 +1,929 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Stack Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM stack related instructions. +". + +Require functools. +Axiom functools_partial : + IsGlobalAlias globals functools.globals "partial". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". +Axiom __init___stack : + IsGlobalAlias globals __init__.globals "stack". + +Require exceptions. +Axiom exceptions_StackUnderflowError : + IsGlobalAlias globals exceptions.globals "StackUnderflowError". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_buffer_read : + IsGlobalAlias globals memory.globals "buffer_read". + +Definition pop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Remove item from stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.pass (| |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition push_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "num_bytes" ] |) in + let _ := Constant.str " + Pushes a N-byte immediate onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + num_bytes : + The number of immediate bytes to be read from the code and pushed to + the stack. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let data_to_push := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "code" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "num_bytes" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "data_to_push" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + BinOp.add (| + Constant.int 1, + M.get_name (| globals, "num_bytes" |) + |) + |) in + M.pure Constant.None_)). + +Definition dup_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "item_number" ] |) in + let _ := Constant.str " + Duplicate the Nth stack item (from top of the stack) to the top of stack. + + Parameters + ---------- + evm : + The current EVM frame. + + item_number : + The stack item number (0-indexed from top of stack) to be duplicated + to the top of stack. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "StackUnderflowError" |) + ], + make_dict [] + |) in + let data_to_duplicate := + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + BinOp.sub (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), + Constant.int 1 + |), + M.get_name (| globals, "item_number" |) + |) |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "data_to_duplicate" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition swap_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "item_number" ] |) in + let _ := Constant.str " + Swap the top and the `item_number` element of the stack, where + the top of the stack is position zero. + + If `item_number` is zero, this function does nothing (which should not be + possible, since there is no `SWAP0` instruction). + + Parameters + ---------- + evm : + The current EVM frame. + + item_number : + The stack item number (0-indexed from top of stack) to be swapped + with the top of stack element. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "StackUnderflowError" |) + ], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) |) ], + make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |) ] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition push1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push5 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push6 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push7 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push8 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push9 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push10 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push11 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push12 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push13 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push14 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push15 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push16 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push17 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push18 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push19 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push20 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push21 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push22 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push23 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push24 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push25 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push26 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push27 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push28 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push29 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push30 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push31 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push32 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition dup1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup5 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup6 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup7 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup8 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup9 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup10 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup11 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup12 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup13 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup14 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup15 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup16 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition swap1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap5 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap6 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap7 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap8 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap9 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap10 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap11 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap12 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap13 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap14 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap15 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap16 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/storage.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/storage.v new file mode 100644 index 0000000..4292e3b --- /dev/null +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/storage.v @@ -0,0 +1,212 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Storage Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM storage related instructions. +". + +Require state. +Axiom state_get_storage : + IsGlobalAlias globals state.globals "get_storage". +Axiom state_set_storage : + IsGlobalAlias globals state.globals "set_storage". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_SLOAD : + IsGlobalAlias globals gas.globals "GAS_SLOAD". +Axiom gas_GAS_STORAGE_CLEAR_REFUND : + IsGlobalAlias globals gas.globals "GAS_STORAGE_CLEAR_REFUND". +Axiom gas_GAS_STORAGE_SET : + IsGlobalAlias globals gas.globals "GAS_STORAGE_SET". +Axiom gas_GAS_STORAGE_UPDATE : + IsGlobalAlias globals gas.globals "GAS_STORAGE_UPDATE". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition sload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Loads to the stack, the value corresponding to a certain key from the + storage of the current account. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let key := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_SLOAD" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "get_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition sstore : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a value at a certain key in the current context's storage. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let key := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let new_value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let current_value := + M.call (| + M.get_name (| globals, "get_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "new_value" |), Constant.int 0 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let gas_cost := + M.get_name (| globals, "GAS_STORAGE_SET" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let gas_cost := + M.get_name (| globals, "GAS_STORAGE_UPDATE" |) in + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_name (| globals, "new_value" |), Constant.int 0 |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "gas_cost" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "set_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |); + M.get_name (| globals, "new_value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/interpreter.v b/CoqOfPython/ethereum/spurious_dragon/vm/interpreter.v new file mode 100644 index 0000000..f285aa8 --- /dev/null +++ b/CoqOfPython/ethereum/spurious_dragon/vm/interpreter.v @@ -0,0 +1,625 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Interpreter +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +A straightforward interpreter that executes EVM code. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Iterable : + IsGlobalAlias globals typing.globals "Iterable". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.trace. +Axiom ethereum_trace_EvmStop : + IsGlobalAlias globals ethereum.trace.globals "EvmStop". +Axiom ethereum_trace_OpEnd : + IsGlobalAlias globals ethereum.trace.globals "OpEnd". +Axiom ethereum_trace_OpException : + IsGlobalAlias globals ethereum.trace.globals "OpException". +Axiom ethereum_trace_OpStart : + IsGlobalAlias globals ethereum.trace.globals "OpStart". +Axiom ethereum_trace_PrecompileEnd : + IsGlobalAlias globals ethereum.trace.globals "PrecompileEnd". +Axiom ethereum_trace_PrecompileStart : + IsGlobalAlias globals ethereum.trace.globals "PrecompileStart". +Axiom ethereum_trace_TransactionEnd : + IsGlobalAlias globals ethereum.trace.globals "TransactionEnd". +Axiom ethereum_trace_evm_trace : + IsGlobalAlias globals ethereum.trace.globals "evm_trace". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_account_exists_and_is_empty : + IsGlobalAlias globals state.globals "account_exists_and_is_empty". +Axiom state_account_has_code_or_nonce : + IsGlobalAlias globals state.globals "account_has_code_or_nonce". +Axiom state_begin_transaction : + IsGlobalAlias globals state.globals "begin_transaction". +Axiom state_commit_transaction : + IsGlobalAlias globals state.globals "commit_transaction". +Axiom state_destroy_storage : + IsGlobalAlias globals state.globals "destroy_storage". +Axiom state_increment_nonce : + IsGlobalAlias globals state.globals "increment_nonce". +Axiom state_move_ether : + IsGlobalAlias globals state.globals "move_ether". +Axiom state_rollback_transaction : + IsGlobalAlias globals state.globals "rollback_transaction". +Axiom state_set_code : + IsGlobalAlias globals state.globals "set_code". +Axiom state_touch_account : + IsGlobalAlias globals state.globals "touch_account". + +Require vm. +Axiom vm_Message : + IsGlobalAlias globals vm.globals "Message". + +Require vm.gas. +Axiom vm_gas_GAS_CODE_DEPOSIT : + IsGlobalAlias globals vm.gas.globals "GAS_CODE_DEPOSIT". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require vm.precompiled_contracts.mapping. +Axiom vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : + IsGlobalAlias globals vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". + +Require __init__. +Axiom __init___Environment : + IsGlobalAlias globals __init__.globals "Environment". +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_AddressCollision : + IsGlobalAlias globals exceptions.globals "AddressCollision". +Axiom exceptions_ExceptionalHalt : + IsGlobalAlias globals exceptions.globals "ExceptionalHalt". +Axiom exceptions_InvalidOpcode : + IsGlobalAlias globals exceptions.globals "InvalidOpcode". +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". +Axiom exceptions_StackDepthLimitError : + IsGlobalAlias globals exceptions.globals "StackDepthLimitError". + +Require instructions. +Axiom instructions_Ops : + IsGlobalAlias globals instructions.globals "Ops". +Axiom instructions_op_implementation : + IsGlobalAlias globals instructions.globals "op_implementation". + +Require runtime. +Axiom runtime_get_valid_jump_destinations : + IsGlobalAlias globals runtime.globals "get_valid_jump_destinations". + +Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1024 + ], + make_dict [] + |) +)). + +Definition MAX_CODE_SIZE : Value.t := M.run ltac:(M.monadic ( + Constant.int 24576 +)). + +Definition MessageCallOutput : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition process_message_call : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + If `message.current` is empty then it creates a smart contract + else it executes a call from the `message.caller` to the `message.target`. + + Parameters + ---------- + message : + Transaction specific items. + + env : + External items required for EVM execution. + + Returns + ------- + output : `MessageCallOutput` + Output of the message call + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_name (| globals, "message" |), "target" |), M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let is_collision := + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_name (| globals, "is_collision" |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallOutput" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "tuple" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "AddressCollision" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let evm := + M.call (| + M.get_name (| globals, "process_create_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let evm := + M.call (| + M.get_name (| globals, "process_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_field (| M.get_name (| globals, "message" |), "target" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_field (| M.get_name (| globals, "message" |), "target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( +(* At stmt: unsupported node type: AnnAssign *) + let accounts_to_delete := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let touched_accounts := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let refund_counter := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let logs := + M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in + let accounts_to_delete := + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in + let touched_accounts := + M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |) in + let refund_counter := + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |) in + M.pure Constant.None_ + )) |) in + let tx_end := + M.call (| + M.get_name (| globals, "TransactionEnd" |), + make_list [ + BinOp.sub (| + M.get_field (| M.get_name (| globals, "message" |), "gas" |), + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + |); + M.get_field (| M.get_name (| globals, "evm" |), "output" |); + M.get_field (| M.get_name (| globals, "evm" |), "error" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "evm_trace" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "tx_end" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallOutput" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition process_create_message : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + Executes a call to create a smart contract. + + Parameters + ---------- + message : + Transaction specific items. + env : + External items required for EVM execution. + + Returns + ------- + evm: :py:class:`~ethereum.spurious_dragon.vm.Evm` + Items containing execution specific objects. + " in + let _ := M.call (| + M.get_name (| globals, "begin_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "destroy_storage" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let evm := + M.call (| + M.get_name (| globals, "process_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), + (* then *) + ltac:(M.monadic ( + let contract_code := + M.get_field (| M.get_name (| globals, "evm" |), "output" |) in + let contract_code_gas := + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "contract_code" |) + ], + make_dict [] + |), + M.get_name (| globals, "GAS_CODE_DEPOSIT" |) + |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "rollback_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.get_name (| globals, "evm" |) + |) in + M.pure Constant.None_)). + +Definition process_message : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + Executes a call to create a smart contract. + + Parameters + ---------- + message : + Transaction specific items. + env : + External items required for EVM execution. + + Returns + ------- + evm: :py:class:`~ethereum.spurious_dragon.vm.Evm` + Items containing execution specific objects + " in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_field (| M.get_name (| globals, "message" |), "depth" |), M.get_name (| globals, "STACK_DEPTH_LIMIT" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "StackDepthLimitError" |), + make_list [ + Constant.str "Stack depth limit reached" + ], + make_dict [] + |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "begin_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "touch_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + M.get_field (| M.get_name (| globals, "message" |), "should_transfer_value" |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_field (| M.get_name (| globals, "message" |), "value" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "move_ether" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "caller" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |); + M.get_field (| M.get_name (| globals, "message" |), "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let evm := + M.call (| + M.get_name (| globals, "execute_code" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "rollback_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "commit_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.get_name (| globals, "evm" |) + |) in + M.pure Constant.None_)). + +Definition execute_code : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + Executes bytecode present in the `message`. + + Parameters + ---------- + message : + Transaction specific items. + env : + External items required for EVM execution. + + Returns + ------- + evm: `ethereum.vm.EVM` + Items containing execution specific objects + " in + let code := + M.get_field (| M.get_name (| globals, "message" |), "code" |) in + let valid_jump_destinations := + M.call (| + M.get_name (| globals, "get_valid_jump_destinations" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) in + let evm := + M.call (| + M.get_name (| globals, "Evm" |), + make_list [], + make_dict [] + |) in +(* At stmt: unsupported node type: Try *) + let _ := M.return_ (| + M.get_name (| globals, "evm" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/memory.v b/CoqOfPython/ethereum/spurious_dragon/vm/memory.v new file mode 100644 index 0000000..fa8d906 --- /dev/null +++ b/CoqOfPython/ethereum/spurious_dragon/vm/memory.v @@ -0,0 +1,153 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Memory +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +EVM memory operations. +". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_right_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "right_pad_zero_bytes". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". + +Definition memory_write : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "memory"; "start_position"; "value" ] |) in + let _ := Constant.str " + Writes to memory. + + Parameters + ---------- + memory : + Memory contents of the EVM. + start_position : + Starting pointer to the memory. + value : + Data to write to memory. + " in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) |), + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_)). + +Definition memory_read_bytes : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "memory"; "start_position"; "size" ] |) in + let _ := Constant.str " + Read bytes from memory. + + Parameters + ---------- + memory : + Memory contents of the EVM. + start_position : + Starting pointer to the memory. + size : + Size of the data that needs to be read from `start_position`. + + Returns + ------- + data_bytes : + Data read from memory. + " in + let _ := M.return_ (| + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |) + |) in + M.pure Constant.None_)). + +Definition buffer_read : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "buffer"; "start_position"; "size" ] |) in + let _ := Constant.str " + Read bytes from a buffer. Padding with zeros if necessary. + + Parameters + ---------- + buffer : + Memory contents of the EVM. + start_position : + Starting pointer to the memory. + size : + Size of the data that needs to be read from `start_position`. + + Returns + ------- + data_bytes : + Data read from memory. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "right_pad_zero_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/__init__.v new file mode 100644 index 0000000..422f670 --- /dev/null +++ b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/__init__.v @@ -0,0 +1,67 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Precompiled Contract Addresses +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Addresses of precompiled contracts and mappings to their +implementations. +". + +Require utils.hexadecimal. +Axiom utils_hexadecimal_hex_to_address : + IsGlobalAlias globals utils.hexadecimal.globals "hex_to_address". + +Definition __all__ : Value.t := M.run ltac:(M.monadic ( + make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS" ] +)). + +Definition ECRECOVER_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x01" + ], + make_dict [] + |) +)). + +Definition SHA256_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x02" + ], + make_dict [] + |) +)). + +Definition RIPEMD160_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x03" + ], + make_dict [] + |) +)). + +Definition IDENTITY_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x04" + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/ecrecover.v new file mode 100644 index 0000000..cc351b5 --- /dev/null +++ b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/ecrecover.v @@ -0,0 +1,269 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) ECRECOVER PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the ECRECOVER precompiled contract. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require ethereum.crypto.elliptic_curve. +Axiom ethereum_crypto_elliptic_curve_SECP256K1N : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_left_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_ECRECOVER : + IsGlobalAlias globals vm.gas.globals "GAS_ECRECOVER". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require vm.memory. +Axiom vm_memory_buffer_read : + IsGlobalAlias globals vm.memory.globals "buffer_read". + +Definition ecrecover : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Decrypts the address using elliptic curve DSA recovery mechanism and writes + the address to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_ECRECOVER" |) + ], + make_dict [] + |) in + let message_hash_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let message_hash := + M.call (| + M.get_name (| globals, "Hash32" |), + make_list [ + M.get_name (| globals, "message_hash_bytes" |) + ], + make_dict [] + |) in + let v := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let r := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let s := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 27 |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 28 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| Constant.int 0, M.get_name (| globals, "r" |) |), + ltac:(M.monadic ( + Compare.gt_e (| M.get_name (| globals, "r" |), M.get_name (| globals, "SECP256K1N" |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| Constant.int 0, M.get_name (| globals, "s" |) |), + ltac:(M.monadic ( + Compare.gt_e (| M.get_name (| globals, "s" |), M.get_name (| globals, "SECP256K1N" |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in +(* At stmt: unsupported node type: Try *) + let address := + M.get_subscript (| M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), Constant.int 12:Constant.int 32 |) in + let padded_address := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "address" |); + Constant.int 32 + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.get_name (| globals, "padded_address" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/identity.v new file mode 100644 index 0000000..fa96704 --- /dev/null +++ b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/identity.v @@ -0,0 +1,94 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) IDENTITY PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `IDENTITY` precompiled contract. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_IDENTITY : + IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY". +Axiom vm_gas_GAS_IDENTITY_WORD : + IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY_WORD". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition identity : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the message data to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let word_count := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_IDENTITY" |), + BinOp.mult (| + M.get_name (| globals, "GAS_IDENTITY_WORD" |), + M.get_name (| globals, "word_count" |) + |) + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.get_name (| globals, "data" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/mapping.v new file mode 100644 index 0000000..710457d --- /dev/null +++ b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/mapping.v @@ -0,0 +1,56 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Precompiled Contract Addresses +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Mapping of precompiled contracts their implementations. +". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require __init__. +Axiom __init___ECRECOVER_ADDRESS : + IsGlobalAlias globals __init__.globals "ECRECOVER_ADDRESS". +Axiom __init___IDENTITY_ADDRESS : + IsGlobalAlias globals __init__.globals "IDENTITY_ADDRESS". +Axiom __init___RIPEMD160_ADDRESS : + IsGlobalAlias globals __init__.globals "RIPEMD160_ADDRESS". +Axiom __init___SHA256_ADDRESS : + IsGlobalAlias globals __init__.globals "SHA256_ADDRESS". + +Require ecrecover. +Axiom ecrecover_ecrecover : + IsGlobalAlias globals ecrecover.globals "ecrecover". + +Require identity. +Axiom identity_identity : + IsGlobalAlias globals identity.globals "identity". + +Require ripemd160. +Axiom ripemd160_ripemd160 : + IsGlobalAlias globals ripemd160.globals "ripemd160". + +Require sha256. +Axiom sha256_sha256 : + IsGlobalAlias globals sha256.globals "sha256". + +(* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/ripemd160.v new file mode 100644 index 0000000..96f8dcd --- /dev/null +++ b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/ripemd160.v @@ -0,0 +1,122 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) RIPEMD160 PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `RIPEMD160` precompiled contract. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_left_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_RIPEMD160 : + IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160". +Axiom vm_gas_GAS_RIPEMD160_WORD : + IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160_WORD". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition ripemd160 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the ripemd160 hash to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let word_count := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_RIPEMD160" |), + BinOp.mult (| + M.get_name (| globals, "GAS_RIPEMD160_WORD" |), + M.get_name (| globals, "word_count" |) + |) + |) + ], + make_dict [] + |) in + let hash_bytes := + M.call (| + M.get_field (| M.call (| + M.get_field (| M.get_name (| globals, "hashlib" |), "new" |), + make_list [ + Constant.str "ripemd160"; + M.get_name (| globals, "data" |) + ], + make_dict [] + |), "digest" |), + make_list [], + make_dict [] + |) in + let padded_hash := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "hash_bytes" |); + Constant.int 32 + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.get_name (| globals, "padded_hash" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/sha256.v new file mode 100644 index 0000000..9f6d2bf --- /dev/null +++ b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/sha256.v @@ -0,0 +1,106 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) SHA256 PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `SHA256` precompiled contract. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_SHA256 : + IsGlobalAlias globals vm.gas.globals "GAS_SHA256". +Axiom vm_gas_GAS_SHA256_WORD : + IsGlobalAlias globals vm.gas.globals "GAS_SHA256_WORD". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition sha256 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the sha256 hash to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let word_count := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_SHA256" |), + BinOp.mult (| + M.get_name (| globals, "GAS_SHA256_WORD" |), + M.get_name (| globals, "word_count" |) + |) + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_field (| M.get_name (| globals, "hashlib" |), "sha256" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), "digest" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/runtime.v b/CoqOfPython/ethereum/spurious_dragon/vm/runtime.v new file mode 100644 index 0000000..835b46c --- /dev/null +++ b/CoqOfPython/ethereum/spurious_dragon/vm/runtime.v @@ -0,0 +1,125 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Runtime Operations +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Runtime related operations used while executing EVM code. +". + +Require typing. +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require instructions. +Axiom instructions_Ops : + IsGlobalAlias globals instructions.globals "Ops". + +Definition get_valid_jump_destinations : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "code" ] |) in + let _ := Constant.str " + Analyze the evm code to obtain the set of valid jump destinations. + + Valid jump destinations are defined as follows: + * The jump destination is less than the length of the code. + * The jump destination should have the `JUMPDEST` opcode (0x5B). + * The jump destination shouldn't be part of the data corresponding to + `PUSH-N` opcodes. + + Note - Jump destinations are 0-indexed. + + Parameters + ---------- + code : + The EVM code which is to be executed. + + Returns + ------- + valid_jump_destinations: `Set[Uint]` + The set of valid jump destinations in the code. + " in + let valid_jump_destinations := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let pc := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + While Compare.lt (| M.get_name (| globals, "pc" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) |) do +(* At stmt: unsupported node type: Try *) + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "current_opcode" |), M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), + make_list [ + M.get_name (| globals, "pc" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + (* At expr: unsupported node type: Compare *), + (* then *) + ltac:(M.monadic ( + let push_data_size := + BinOp.add (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) + |), + Constant.int 1 + |) in + let pc := BinOp.add + M.get_name (| globals, "push_data_size" |) + M.get_name (| globals, "push_data_size" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let pc := BinOp.add + Constant.int 1 + Constant.int 1 in + EndWhile. + let _ := M.return_ (| + M.get_name (| globals, "valid_jump_destinations" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/stack.v b/CoqOfPython/ethereum/spurious_dragon/vm/stack.v new file mode 100644 index 0000000..42ea42d --- /dev/null +++ b/CoqOfPython/ethereum/spurious_dragon/vm/stack.v @@ -0,0 +1,120 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Stack +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the stack operators for the EVM. +". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require exceptions. +Axiom exceptions_StackOverflowError : + IsGlobalAlias globals exceptions.globals "StackOverflowError". +Axiom exceptions_StackUnderflowError : + IsGlobalAlias globals exceptions.globals "StackUnderflowError". + +Definition pop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "stack" ] |) in + let _ := Constant.str " + Pops the top item off of `stack`. + + Parameters + ---------- + stack : + EVM stack. + + Returns + ------- + value : `U256` + The top element on the stack. + + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "StackUnderflowError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "pop" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition push : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "stack"; "value" ] |) in + let _ := Constant.str " + Pushes `value` onto `stack`. + + Parameters + ---------- + stack : + EVM stack. + + value : + Item to be pushed onto `stack`. + + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), Constant.int 1024 |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "StackOverflowError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "append" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/__init__.v b/CoqOfPython/ethereum/tangerine_whistle/__init__.v new file mode 100644 index 0000000..25e2813 --- /dev/null +++ b/CoqOfPython/ethereum/tangerine_whistle/__init__.v @@ -0,0 +1,25 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +The Tangerine Whistle fork is the first of two forks responding to a +denial-of-service attack on the Ethereum network. It tunes the price of various +EVM instructions, and reduces the state size by removing a number of empty +accounts. +". + +Require ethereum.fork_criteria. +Axiom ethereum_fork_criteria_ByBlockNumber : + IsGlobalAlias globals ethereum.fork_criteria.globals "ByBlockNumber". + +Definition FORK_CRITERIA : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "ByBlockNumber" |), + make_list [ + Constant.int 2463000 + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/blocks.v b/CoqOfPython/ethereum/tangerine_whistle/blocks.v new file mode 100644 index 0000000..6501788 --- /dev/null +++ b/CoqOfPython/ethereum/tangerine_whistle/blocks.v @@ -0,0 +1,93 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +A `Block` is a single link in the chain that is Ethereum. Each `Block` contains +a `Header` and zero or more transactions. Each `Header` contains associated +metadata like the block number, parent block hash, and how much gas was +consumed by its transactions. + +Together, these blocks form a cryptographically secure journal recording the +history of all state transitions that have happened since the genesis of the +chain. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes8 : + IsGlobalAlias globals base_types.globals "Bytes8". +Axiom base_types_Bytes32 : + IsGlobalAlias globals base_types.globals "Bytes32". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require crypto.hash. +Axiom crypto_hash_Hash32 : + IsGlobalAlias globals crypto.hash.globals "Hash32". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Require transactions. +Axiom transactions_Transaction : + IsGlobalAlias globals transactions.globals "Transaction". + +Definition Header : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Block : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Log : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Receipt : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. diff --git a/CoqOfPython/ethereum/tangerine_whistle/bloom.v b/CoqOfPython/ethereum/tangerine_whistle/bloom.v new file mode 100644 index 0000000..04b5d9f --- /dev/null +++ b/CoqOfPython/ethereum/tangerine_whistle/bloom.v @@ -0,0 +1,164 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Logs Bloom +^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +This modules defines functions for calculating bloom filters of logs. For the +general theory of bloom filters see e.g. `Wikipedia +`_. Bloom filters are used to allow +for efficient searching of logs by address and/or topic, by rapidly +eliminating blocks and receipts from their search. +". + +Require typing. +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require fork_types. +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". + +Definition add_to_bloom : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "bloom"; "bloom_entry" ] |) in + let _ := Constant.str " + Add a bloom entry to the bloom filter (`bloom`). + + The number of hash functions used is 3. They are calculated by taking the + least significant 11 bits from the first 3 16-bit words of the + `keccak_256()` hash of `bloom_entry`. + + Parameters + ---------- + bloom : + The bloom filter. + bloom_entry : + An entry which is to be added to bloom filter. + " in + let hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "bloom_entry" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "idx" |) in make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ] do + let bit_to_set := + BinOp.bit_and (| + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |):BinOp.add (| + M.get_name (| globals, "idx" |), + Constant.int 2 + |) |) + ], + make_dict [] + |), + Constant.int 2047 + |) in + let bit_index := + BinOp.sub (| + Constant.int 2047, + M.get_name (| globals, "bit_to_set" |) + |) in + let byte_index := + BinOp.floor_div (| + M.get_name (| globals, "bit_index" |), + Constant.int 8 + |) in + let bit_value := + BinOp.l_shift (| + Constant.int 1, + BinOp.sub (| + Constant.int 7, + BinOp.mod_ (| + M.get_name (| globals, "bit_index" |), + Constant.int 8 + |) + |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), + BinOp.bit_or (| + M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), + M.get_name (| globals, "bit_value" |) + |) + |) in + EndFor. + M.pure Constant.None_)). + +Definition logs_bloom : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "logs" ] |) in + let _ := Constant.str " + Obtain the logs bloom from a list of log entries. + + The address and each topic of a log are added to the bloom filter. + + Parameters + ---------- + logs : + List of logs for which the logs bloom is to be obtained. + + Returns + ------- + logs_bloom : `Bloom` + The logs bloom obtained which is 256 bytes with some bits set as per + the caller address and the log topics. + " in +(* At stmt: unsupported node type: AnnAssign *) + For M.get_name (| globals, "log" |) in M.get_name (| globals, "logs" |) do + let _ := M.call (| + M.get_name (| globals, "add_to_bloom" |), + make_list [ + M.get_name (| globals, "bloom" |); + M.get_field (| M.get_name (| globals, "log" |), "address" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "topic" |) in M.get_field (| M.get_name (| globals, "log" |), "topics" |) do + let _ := M.call (| + M.get_name (| globals, "add_to_bloom" |), + make_list [ + M.get_name (| globals, "bloom" |); + M.get_name (| globals, "topic" |) + ], + make_dict [] + |) in + EndFor. + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bloom" |), + make_list [ + M.get_name (| globals, "bloom" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/fork.v b/CoqOfPython/ethereum/tangerine_whistle/fork.v new file mode 100644 index 0000000..951cae7 --- /dev/null +++ b/CoqOfPython/ethereum/tangerine_whistle/fork.v @@ -0,0 +1,2104 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Specification +^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Entry point for the Ethereum specification. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". + +Require ethereum.crypto.elliptic_curve. +Axiom ethereum_crypto_elliptic_curve_SECP256K1N : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.ethash. +Axiom ethereum_ethash_dataset_size : + IsGlobalAlias globals ethereum.ethash.globals "dataset_size". +Axiom ethereum_ethash_generate_cache : + IsGlobalAlias globals ethereum.ethash.globals "generate_cache". +Axiom ethereum_ethash_hashimoto_light : + IsGlobalAlias globals ethereum.ethash.globals "hashimoto_light". + +Require ethereum.exceptions. +Axiom ethereum_exceptions_InvalidBlock : + IsGlobalAlias globals ethereum.exceptions.globals "InvalidBlock". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U64 : + IsGlobalAlias globals base_types.globals "U64". +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_U256_CEIL_VALUE : + IsGlobalAlias globals base_types.globals "U256_CEIL_VALUE". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes32 : + IsGlobalAlias globals base_types.globals "Bytes32". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". + +Require __init__. +Axiom __init___vm : + IsGlobalAlias globals __init__.globals "vm". + +Require blocks. +Axiom blocks_Block : + IsGlobalAlias globals blocks.globals "Block". +Axiom blocks_Header : + IsGlobalAlias globals blocks.globals "Header". +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". +Axiom blocks_Receipt : + IsGlobalAlias globals blocks.globals "Receipt". + +Require bloom. +Axiom bloom_logs_bloom : + IsGlobalAlias globals bloom.globals "logs_bloom". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Require state. +Axiom state_State : + IsGlobalAlias globals state.globals "State". +Axiom state_create_ether : + IsGlobalAlias globals state.globals "create_ether". +Axiom state_destroy_account : + IsGlobalAlias globals state.globals "destroy_account". +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". +Axiom state_increment_nonce : + IsGlobalAlias globals state.globals "increment_nonce". +Axiom state_set_account_balance : + IsGlobalAlias globals state.globals "set_account_balance". +Axiom state_state_root : + IsGlobalAlias globals state.globals "state_root". + +Require transactions. +Axiom transactions_TX_BASE_COST : + IsGlobalAlias globals transactions.globals "TX_BASE_COST". +Axiom transactions_TX_CREATE_COST : + IsGlobalAlias globals transactions.globals "TX_CREATE_COST". +Axiom transactions_TX_DATA_COST_PER_NON_ZERO : + IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_NON_ZERO". +Axiom transactions_TX_DATA_COST_PER_ZERO : + IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_ZERO". +Axiom transactions_Transaction : + IsGlobalAlias globals transactions.globals "Transaction". + +Require trie. +Axiom trie_Trie : + IsGlobalAlias globals trie.globals "Trie". +Axiom trie_root : + IsGlobalAlias globals trie.globals "root". +Axiom trie_trie_set : + IsGlobalAlias globals trie.globals "trie_set". + +Require utils.message. +Axiom utils_message_prepare_message : + IsGlobalAlias globals utils.message.globals "prepare_message". + +Require vm.interpreter. +Axiom vm_interpreter_process_message_call : + IsGlobalAlias globals vm.interpreter.globals "process_message_call". + +Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mult (| + Constant.int 5, + BinOp.pow (| + Constant.int 10, + Constant.int 18 + |) + |) + ], + make_dict [] + |) +)). + +Definition GAS_LIMIT_ADJUSTMENT_FACTOR : Value.t := M.run ltac:(M.monadic ( + Constant.int 1024 +)). + +Definition GAS_LIMIT_MINIMUM : Value.t := M.run ltac:(M.monadic ( + Constant.int 5000 +)). + +Definition MINIMUM_DIFFICULTY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 131072 + ], + make_dict [] + |) +)). + +Definition MAX_OMMER_DEPTH : Value.t := M.run ltac:(M.monadic ( + Constant.int 6 +)). + +Definition BlockChain : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition apply_fork : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "old" ] |) in + let _ := Constant.str " + Transforms the state from the previous hard fork (`old`) into the block + chain object for this hard fork and returns it. + + When forks need to implement an irregular state transition, this function + is used to handle the irregularity. See the :ref:`DAO Fork ` for + an example. + + Parameters + ---------- + old : + Previous block chain object. + + Returns + ------- + new : `BlockChain` + Upgraded block chain object for this hard fork. + " in + let _ := M.return_ (| + M.get_name (| globals, "old" |) + |) in + M.pure Constant.None_)). + +Definition get_last_256_block_hashes : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "chain" ] |) in + let _ := Constant.str " + Obtain the list of hashes of the previous 256 blocks in order of + increasing block number. + + This function will return less hashes for the first 256 blocks. + + The ``BLOCKHASH`` opcode needs to access the latest hashes on the chain, + therefore this function retrieves them. + + Parameters + ---------- + chain : + History and current state. + + Returns + ------- + recent_block_hashes : `List[Hash32]` + Hashes of the recent 256 blocks in order of increasing block number. + " in + let recent_blocks := + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |):(* At expr: unsupported node type: NoneType *) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "recent_blocks" |) + ], + make_dict [] + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + make_list [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let recent_block_hashes := + make_list [] in + For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_blocks" |) do + let prev_block_hash := + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), + make_list [ + M.get_name (| globals, "prev_block_hash" |) + ], + make_dict [] + |) in + EndFor. + let most_recent_block_hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_field (| M.get_subscript (| M.get_name (| globals, "recent_blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), + make_list [ + M.get_name (| globals, "most_recent_block_hash" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "recent_block_hashes" |) + |) in + M.pure Constant.None_)). + +Definition state_transition : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "chain"; "block" ] |) in + let _ := Constant.str " + Attempts to apply a block to an existing block chain. + + All parts of the block's contents need to be verified before being added + to the chain. Blocks are verified by ensuring that the contents of the + block make logical sense with the contents of the parent block. The + information in the block's header must also match the corresponding + information in the block. + + To implement Ethereum, in theory clients are only required to store the + most recent 255 blocks of the chain since as far as execution is + concerned, only those blocks are accessed. Practically, however, clients + should store more blocks to handle reorgs. + + Parameters + ---------- + chain : + History and current state. + block : + Block to apply to `chain`. + " in + let parent_header := + M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) in + let _ := M.call (| + M.get_name (| globals, "validate_header" |), + make_list [ + M.get_field (| M.get_name (| globals, "block" |), "header" |); + M.get_name (| globals, "parent_header" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "validate_ommers" |), + make_list [ + M.get_field (| M.get_name (| globals, "block" |), "ommers" |); + M.get_field (| M.get_name (| globals, "block" |), "header" |); + M.get_name (| globals, "chain" |) + ], + make_dict [] + |) in + let apply_body_output := + M.call (| + M.get_name (| globals, "apply_body" |), + make_list [ + M.get_field (| M.get_name (| globals, "chain" |), "state" |); + M.call (| + M.get_name (| globals, "get_last_256_block_hashes" |), + make_list [ + M.get_name (| globals, "chain" |) + ], + make_dict [] + |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "coinbase" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "number" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "gas_limit" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "timestamp" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "difficulty" |); + M.get_field (| M.get_name (| globals, "block" |), "transactions" |); + M.get_field (| M.get_name (| globals, "block" |), "ommers" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_gas_used" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "gas_used" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "transactions_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "transactions_root" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "state_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "state_root" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "receipt_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "receipt_root" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_logs_bloom" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "bloom" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), "append" |), + make_list [ + M.get_name (| globals, "block" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |) + ], + make_dict [] + |), Constant.int 255 |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |):(* At expr: unsupported node type: NoneType *) |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition validate_header : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header"; "parent_header" ] |) in + let _ := Constant.str " + Verifies a block header. + + In order to consider a block's header valid, the logic for the + quantities in the header should match the logic for the block itself. + For example the header timestamp should be greater than the block's parent + timestamp because the block was created *after* the parent block. + Additionally, the block's number should be directly following the parent + block's number since it is the next block in the sequence. + + Parameters + ---------- + header : + Header to check for correctness. + parent_header : + Parent Header of the header to check for correctness + " in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt (| M.get_field (| M.get_name (| globals, "header" |), "timestamp" |), M.get_field (| M.get_name (| globals, "parent_header" |), "timestamp" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "number" |), BinOp.add (| + M.get_field (| M.get_name (| globals, "parent_header" |), "number" |), + Constant.int 1 + |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + M.call (| + M.get_name (| globals, "check_gas_limit" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "gas_limit" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "gas_limit" |) + ], + make_dict [] + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) + ], + make_dict [] + |), Constant.int 32 |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let block_difficulty := + M.call (| + M.get_name (| globals, "calculate_block_difficulty" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "number" |); + M.get_field (| M.get_name (| globals, "header" |), "timestamp" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "timestamp" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "difficulty" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "difficulty" |), M.get_name (| globals, "block_difficulty" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let block_parent_hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "parent_header" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |), M.get_name (| globals, "block_parent_hash" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "validate_proof_of_work" |), + make_list [ + M.get_name (| globals, "header" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header" ] |) in + let _ := Constant.str " + Generate rlp hash of the header which is to be used for Proof-of-Work + verification. + + In other words, the PoW artefacts `mix_digest` and `nonce` are ignored + while calculating this hash. + + A particular PoW is valid for a single hash, that hash is computed by + this function. The `nonce` and `mix_digest` are omitted from this hash + because they are being changed by miners in their search for a sufficient + proof-of-work. + + Parameters + ---------- + header : + The header object for which the hash is to be generated. + + Returns + ------- + hash : `Hash32` + The PoW valid rlp hash of the passed in header. + " in + let header_data_without_pow_artefacts := + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |); + M.get_field (| M.get_name (| globals, "header" |), "ommers_hash" |); + M.get_field (| M.get_name (| globals, "header" |), "coinbase" |); + M.get_field (| M.get_name (| globals, "header" |), "state_root" |); + M.get_field (| M.get_name (| globals, "header" |), "transactions_root" |); + M.get_field (| M.get_name (| globals, "header" |), "receipt_root" |); + M.get_field (| M.get_name (| globals, "header" |), "bloom" |); + M.get_field (| M.get_name (| globals, "header" |), "difficulty" |); + M.get_field (| M.get_name (| globals, "header" |), "number" |); + M.get_field (| M.get_name (| globals, "header" |), "gas_limit" |); + M.get_field (| M.get_name (| globals, "header" |), "gas_used" |); + M.get_field (| M.get_name (| globals, "header" |), "timestamp" |); + M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) + ] in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "header_data_without_pow_artefacts" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition validate_proof_of_work : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header" ] |) in + let _ := Constant.str " + Validates the Proof of Work constraints. + + In order to verify that a miner's proof-of-work is valid for a block, a + ``mix-digest`` and ``result`` are calculated using the ``hashimoto_light`` + hash function. The mix digest is a hash of the header and the nonce that + is passed through and it confirms whether or not proof-of-work was done + on the correct block. The result is the actual hash value of the block. + + Parameters + ---------- + header : + Header of interest. + " in + let header_hash := + M.call (| + M.get_name (| globals, "generate_header_hash_for_pow" |), + make_list [ + M.get_name (| globals, "header" |) + ], + make_dict [] + |) in + let cache := + M.call (| + M.get_name (| globals, "generate_cache" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "number" |) + ], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "mix_digest" |); M.get_name (| globals, "result" |) ], + M.call (| + M.get_name (| globals, "hashimoto_light" |), + make_list [ + M.get_name (| globals, "header_hash" |); + M.get_field (| M.get_name (| globals, "header" |), "nonce" |); + M.get_name (| globals, "cache" |); + M.call (| + M.get_name (| globals, "dataset_size" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "number" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_name (| globals, "mix_digest" |), M.get_field (| M.get_name (| globals, "header" |), "mix_digest" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "result" |) + ], + make_dict [] + |), BinOp.floor_div (| + M.get_name (| globals, "U256_CEIL_VALUE" |), + M.get_field (| M.get_name (| globals, "header" |), "difficulty" |) + |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition check_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx"; "gas_available" ] |) in + let _ := Constant.str " + Check if the transaction is includable in the block. + + Parameters + ---------- + tx : + The transaction. + gas_available : + The gas remaining in the block. + + Returns + ------- + sender_address : + The sender of the transaction. + + Raises + ------ + InvalidBlock : + If the transaction is not includable. + " in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_name (| globals, "gas_available" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let sender_address := + M.call (| + M.get_name (| globals, "recover_sender" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "sender_address" |) + |) in + M.pure Constant.None_)). + +Definition make_receipt : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx"; "post_state"; "cumulative_gas_used"; "logs" ] |) in + let _ := Constant.str " + Make the receipt for a transaction that was executed. + + Parameters + ---------- + tx : + The executed transaction. + post_state : + The state root immediately after this transaction. + cumulative_gas_used : + The total gas used so far in the block after the transaction was + executed. + logs : + The logs produced by the transaction. + + Returns + ------- + receipt : + The receipt for the transaction. + " in + let receipt := + M.call (| + M.get_name (| globals, "Receipt" |), + make_list [], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "receipt" |) + |) in + M.pure Constant.None_)). + +Definition ApplyBodyOutput : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition apply_body : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "block_hashes"; "coinbase"; "block_number"; "block_gas_limit"; "block_time"; "block_difficulty"; "transactions"; "ommers" ] |) in + let _ := Constant.str " + Executes a block. + + Many of the contents of a block are stored in data structures called + tries. There is a transactions trie which is similar to a ledger of the + transactions stored in the current block. There is also a receipts trie + which stores the results of executing a transaction, like the post state + and gas used. This function creates and executes the block that is to be + added to the chain. + + Parameters + ---------- + state : + Current account state. + block_hashes : + List of hashes of the previous 256 blocks in the order of + increasing block number. + coinbase : + Address of account which receives block reward and transaction fees. + block_number : + Position of the block within the chain. + block_gas_limit : + Initial amount of gas available for execution in this block. + block_time : + Time the block was produced, measured in seconds since the epoch. + block_difficulty : + Difficulty of the block. + transactions : + Transactions included in the block. + ommers : + Headers of ancestor blocks which are not direct parents (formerly + uncles.) + + Returns + ------- + apply_body_output : `ApplyBodyOutput` + Output of applying the block body to the state. + " in + let gas_available := + M.get_name (| globals, "block_gas_limit" |) in +(* At stmt: unsupported node type: AnnAssign *) +(* At stmt: unsupported node type: AnnAssign *) +(* At stmt: unsupported node type: AnnAssign *) + For make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "tx" |) ] in M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "transactions" |) + ], + make_dict [] + |) do + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "transactions_trie" |); + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "i" |) + ], + make_dict [] + |) + ], + make_dict [] + |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) in + let sender_address := + M.call (| + M.get_name (| globals, "check_transaction" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "gas_available" |) + ], + make_dict [] + |) in + let env := + M.call (| + M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |) ], + M.call (| + M.get_name (| globals, "process_transaction" |), + make_list [ + M.get_name (| globals, "env" |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) in + let gas_available := BinOp.sub + M.get_name (| globals, "gas_used" |) + M.get_name (| globals, "gas_used" |) in + let receipt := + M.call (| + M.get_name (| globals, "make_receipt" |), + make_list [ + M.get_name (| globals, "tx" |); + M.call (| + M.get_name (| globals, "state_root" |), + make_list [ + M.get_name (| globals, "state" |) + ], + make_dict [] + |); + BinOp.sub (| + M.get_name (| globals, "block_gas_limit" |), + M.get_name (| globals, "gas_available" |) + |); + M.get_name (| globals, "logs" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "receipts_trie" |); + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "i" |) + ], + make_dict [] + |) + ], + make_dict [] + |); + M.get_name (| globals, "receipt" |) + ], + make_dict [] + |) in + let block_logs := BinOp.add + M.get_name (| globals, "logs" |) + M.get_name (| globals, "logs" |) in + EndFor. + let _ := M.call (| + M.get_name (| globals, "pay_rewards" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "block_number" |); + M.get_name (| globals, "coinbase" |); + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |) in + let block_gas_used := + BinOp.sub (| + M.get_name (| globals, "block_gas_limit" |), + M.get_name (| globals, "gas_available" |) + |) in + let block_logs_bloom := + M.call (| + M.get_name (| globals, "logs_bloom" |), + make_list [ + M.get_name (| globals, "block_logs" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ApplyBodyOutput" |), + make_list [ + M.get_name (| globals, "block_gas_used" |); + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_name (| globals, "transactions_trie" |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_name (| globals, "receipts_trie" |) + ], + make_dict [] + |); + M.get_name (| globals, "block_logs_bloom" |); + M.call (| + M.get_name (| globals, "state_root" |), + make_list [ + M.get_name (| globals, "state" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition validate_ommers : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "ommers"; "block_header"; "chain" ] |) in + let _ := Constant.str " + Validates the ommers mentioned in the block. + + An ommer block is a block that wasn't canonically added to the + blockchain because it wasn't validated as fast as the canonical block + but was mined at the same time. + + To be considered valid, the ommers must adhere to the rules defined in + the Ethereum protocol. The maximum amount of ommers is 2 per block and + there cannot be duplicate ommers in a block. Many of the other ommer + constraints are listed in the in-line comments of this function. + + Parameters + ---------- + ommers : + List of ommers mentioned in the current block. + block_header: + The header of current block. + chain : + History and current state. + " in + let block_hash := + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "block_header" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), M.get_field (| M.get_name (| globals, "block_header" |), "ommers_hash" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + (* At expr: unsupported node type: Compare *); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let ommer_parent_header := + M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), BinOp.sub (| + UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) |), + Constant.int 1 + |) |), "header" |) in + let _ := M.call (| + M.get_name (| globals, "validate_header" |), + make_list [ + M.get_name (| globals, "ommer" |); + M.get_name (| globals, "ommer_parent_header" |) + ], + make_dict [] + |) in + EndFor. + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), Constant.int 2 |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let ommers_hashes := + [M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "ommer" |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)] in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers_hashes" |) + ], + make_dict [] + |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_name (| globals, "set" |), + make_list [ + M.get_name (| globals, "ommers_hashes" |) + ], + make_dict [] + |) + ], + make_dict [] + |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let recent_canonical_blocks := + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| BinOp.add (| + M.get_name (| globals, "MAX_OMMER_DEPTH" |), + Constant.int 1 + |) |):(* At expr: unsupported node type: NoneType *) |) in + let recent_canonical_block_hashes := + {M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_field (| M.get_name (| globals, "block" |), "header" |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)} in +(* At stmt: unsupported node type: AnnAssign *) + For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_canonical_blocks" |) do + let recent_ommers_hashes := + M.call (| + M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), + make_list [ + {M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "ommer" |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)} + ], + make_dict [] + |) in + EndFor. + For make_tuple [ M.get_name (| globals, "ommer_index" |); M.get_name (| globals, "ommer" |) ] in M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |) do + let ommer_hash := + M.get_subscript (| M.get_name (| globals, "ommers_hashes" |), M.get_name (| globals, "ommer_index" |) |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_eq (| M.get_name (| globals, "ommer_hash" |), M.get_name (| globals, "block_hash" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_in (| M.get_name (| globals, "ommer_hash" |), M.get_name (| globals, "recent_canonical_block_hashes" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_in (| M.get_name (| globals, "ommer_hash" |), M.get_name (| globals, "recent_ommers_hashes" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let ommer_age := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + (* At expr: unsupported node type: Compare *); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.in (| M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), M.get_name (| globals, "recent_canonical_block_hashes" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_eq (| M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), M.get_field (| M.get_name (| globals, "block_header" |), "parent_hash" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_)). + +Definition pay_rewards : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "block_number"; "coinbase"; "ommers" ] |) in + let _ := Constant.str " + Pay rewards to the block miner as well as the ommers miners. + + The miner of the canonical block is rewarded with the predetermined + block reward, ``BLOCK_REWARD``, plus a variable award based off of the + number of ommer blocks that were mined around the same time, and included + in the canonical block's header. An ommer block is a block that wasn't + added to the canonical blockchain because it wasn't validated as fast as + the accepted block but was mined at the same time. Although not all blocks + that are mined are added to the canonical chain, miners are still paid a + reward for their efforts. This reward is called an ommer reward and is + calculated based on the number associated with the ommer block that they + mined. + + Parameters + ---------- + state : + Current account state. + block_number : + Position of the block within the chain. + coinbase : + Address of account which receives block reward and transaction fees. + ommers : + List of ommers mentioned in the current block. + " in + let miner_reward := + BinOp.add (| + M.get_name (| globals, "BLOCK_REWARD" |), + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + BinOp.floor_div (| + M.get_name (| globals, "BLOCK_REWARD" |), + Constant.int 32 + |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "create_ether" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "coinbase" |); + M.get_name (| globals, "miner_reward" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do + let ommer_age := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "block_number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) + ], + make_dict [] + |) in + let ommer_miner_reward := + BinOp.floor_div (| + BinOp.mult (| + BinOp.sub (| + Constant.int 8, + M.get_name (| globals, "ommer_age" |) + |), + M.get_name (| globals, "BLOCK_REWARD" |) + |), + Constant.int 8 + |) in + let _ := M.call (| + M.get_name (| globals, "create_ether" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_field (| M.get_name (| globals, "ommer" |), "coinbase" |); + M.get_name (| globals, "ommer_miner_reward" |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_)). + +Definition process_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "env"; "tx" ] |) in + let _ := Constant.str " + Execute a transaction against the provided environment. + + This function processes the actions needed to execute a transaction. + It decrements the sender's account after calculating the gas fee and + refunds them the proper amount after execution. Calling contracts, + deploying code, and incrementing nonces are all examples of actions that + happen within this function or from a call made within this function. + + Accounts that are marked for deletion are processed and destroyed after + execution. + + Parameters + ---------- + env : + Environment for the Ethereum Virtual Machine. + tx : + Transaction to execute. + + Returns + ------- + gas_left : `ethereum.base_types.U256` + Remaining gas after execution. + logs : `Tuple[ethereum.blocks.Log, ...]` + Logs generated during execution. + " in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + M.call (| + M.get_name (| globals, "validate_transaction" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let sender := + M.get_field (| M.get_name (| globals, "env" |), "origin" |) in + let sender_account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |) in + let gas_fee := + BinOp.mult (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "sender_account" |), "nonce" |), M.get_field (| M.get_name (| globals, "tx" |), "nonce" |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt_e (| M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), BinOp.add (| + M.get_name (| globals, "gas_fee" |), + M.get_field (| M.get_name (| globals, "tx" |), "value" |) + |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.get_field (| M.get_name (| globals, "sender_account" |), "code" |), M.call (| + M.get_name (| globals, "bytearray" |), + make_list [], + make_dict [] + |) |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let gas := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.call (| + M.get_name (| globals, "calculate_intrinsic_cost" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) in + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |) in + let sender_balance_after_gas_fee := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), + M.get_name (| globals, "gas_fee" |) + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |); + M.get_name (| globals, "sender_balance_after_gas_fee" |) + ], + make_dict [] + |) in + let message := + M.call (| + M.get_name (| globals, "prepare_message" |), + make_list [ + M.get_name (| globals, "sender" |); + M.get_field (| M.get_name (| globals, "tx" |), "to" |); + M.get_field (| M.get_name (| globals, "tx" |), "value" |); + M.get_field (| M.get_name (| globals, "tx" |), "data" |); + M.get_name (| globals, "gas" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let output := + M.call (| + M.get_name (| globals, "process_message_call" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let gas_used := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "output" |), "gas_left" |) + |) in + let gas_refund := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + BinOp.floor_div (| + M.get_name (| globals, "gas_used" |), + Constant.int 2 + |); + M.get_field (| M.get_name (| globals, "output" |), "refund_counter" |) + ], + make_dict [] + |) in + let gas_refund_amount := + BinOp.mult (| + BinOp.add (| + M.get_field (| M.get_name (| globals, "output" |), "gas_left" |), + M.get_name (| globals, "gas_refund" |) + |), + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) + |) in + let transaction_fee := + BinOp.mult (| + BinOp.sub (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "output" |), "gas_left" |) + |), + M.get_name (| globals, "gas_refund" |) + |), + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) + |) in + let total_gas_used := + BinOp.sub (| + M.get_name (| globals, "gas_used" |), + M.get_name (| globals, "gas_refund" |) + |) in + let sender_balance_after_refund := + BinOp.add (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |), "balance" |), + M.get_name (| globals, "gas_refund_amount" |) + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |); + M.get_name (| globals, "sender_balance_after_refund" |) + ], + make_dict [] + |) in + let coinbase_balance_after_mining_fee := + BinOp.add (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |), "balance" |), + M.get_name (| globals, "transaction_fee" |) + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |); + M.get_name (| globals, "coinbase_balance_after_mining_fee" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "accounts_to_delete" |) do + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + EndFor. + let _ := M.return_ (| + make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |) ] + |) in + M.pure Constant.None_)). + +Definition validate_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Verifies a transaction. + + The gas in a transaction gets used to pay for the intrinsic cost of + operations, therefore if there is insufficient gas then it would not + be possible to execute a transaction and it will be declared invalid. + + Additionally, the nonce of a transaction must not equal or exceed the + limit defined in `EIP-2681 `_. + In practice, defining the limit as ``2**64-1`` has no impact because + sending ``2**64-1`` transactions is improbable. It's not strictly + impossible though, ``2**64-1`` transactions is the entire capacity of the + Ethereum blockchain at 2022 gas limits for a little over 22 years. + + Parameters + ---------- + tx : + Transaction to validate. + + Returns + ------- + verified : `bool` + True if the transaction can be executed, or False otherwise. + " in + let _ := M.return_ (| + BoolOp.and (| + Compare.lt_e (| M.call (| + M.get_name (| globals, "calculate_intrinsic_cost" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |), M.get_field (| M.get_name (| globals, "tx" |), "gas" |) |), + ltac:(M.monadic ( + Compare.lt (| M.get_field (| M.get_name (| globals, "tx" |), "nonce" |), BinOp.sub (| + BinOp.pow (| + Constant.int 2, + Constant.int 64 + |), + Constant.int 1 + |) |) + )) + |) + |) in + M.pure Constant.None_)). + +Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Calculates the gas that is charged before execution is started. + + The intrinsic cost of the transaction is charged before execution has + begun. Functions/operations in the EVM cost money to execute so this + intrinsic cost is for the operations that need to be paid for as part of + the transaction. Data transfer, for example, is part of this intrinsic + cost. It costs ether to send data over the wire and that ether is + accounted for in the intrinsic cost calculated in this function. This + intrinsic cost must be calculated and paid for before execution in order + for all operations to be implemented. + + Parameters + ---------- + tx : + Transaction to compute the intrinsic cost of. + + Returns + ------- + verified : `ethereum.base_types.Uint` + The intrinsic cost of the transaction. + " in + let data_cost := + Constant.int 0 in + For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "byte" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + M.pure Constant.None_ + )) |) in + EndFor. + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_name (| globals, "tx" |), "to" |), M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let create_cost := + M.get_name (| globals, "TX_CREATE_COST" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let create_cost := + Constant.int 0 in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "TX_BASE_COST" |), + M.get_name (| globals, "data_cost" |) + |), + M.get_name (| globals, "create_cost" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition recover_sender : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Extracts the sender address from a transaction. + + The v, r, and s values are the three parts that make up the signature + of a transaction. In order to recover the sender of a transaction the two + components needed are the signature (``v``, ``r``, and ``s``) and the + signing hash of the transaction. The sender's public key can be obtained + with these two values and therefore the sender address can be retrieved. + + Parameters + ---------- + tx : + Transaction of interest. + + Returns + ------- + sender : `ethereum.fork_types.Address` + The address of the account that signed the transaction. + " in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "v" |); M.get_name (| globals, "r" |); M.get_name (| globals, "s" |) ], + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "v" |); M.get_field (| M.get_name (| globals, "tx" |), "r" |); M.get_field (| M.get_name (| globals, "tx" |), "s" |) ] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.or (| + Compare.eq (| M.get_name (| globals, "v" |), Constant.int 27 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "v" |), Constant.int 28 |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.and (| + Compare.lt (| Constant.int 0, M.get_name (| globals, "r" |) |), + ltac:(M.monadic ( + Compare.lt (| M.get_name (| globals, "r" |), M.get_name (| globals, "SECP256K1N" |) |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.and (| + Compare.lt (| Constant.int 0, M.get_name (| globals, "s" |) |), + ltac:(M.monadic ( + Compare.lt_e (| M.get_name (| globals, "s" |), BinOp.floor_div (| + M.get_name (| globals, "SECP256K1N" |), + Constant.int 2 + |) |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + BinOp.sub (| + M.get_name (| globals, "v" |), + Constant.int 27 + |); + M.call (| + M.get_name (| globals, "signing_hash" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_subscript (| M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), Constant.int 12:Constant.int 32 |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition signing_hash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Compute the hash of a transaction used in the signature. + + The values that are used to compute the signing hash set the rules for a + transaction. For example, signing over the gas sets a limit for the + amount of money that is allowed to be pulled out of the sender's account. + + Parameters + ---------- + tx : + Transaction of interest. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the transaction. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "nonce" |); M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |); M.get_field (| M.get_name (| globals, "tx" |), "gas" |); M.get_field (| M.get_name (| globals, "tx" |), "to" |); M.get_field (| M.get_name (| globals, "tx" |), "value" |); M.get_field (| M.get_name (| globals, "tx" |), "data" |) ] + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition compute_header_hash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header" ] |) in + let _ := Constant.str " + Computes the hash of a block header. + + The header hash of a block is the canonical hash that is used to refer + to a specific block and completely distinguishes a block from another. + + ``keccak256`` is a function that produces a 256 bit hash of any input. + It also takes in any number of bytes as an input and produces a single + hash for them. A hash is a completely unique output for a single input. + So an input corresponds to one unique hash that can be used to identify + the input exactly. + + Prior to using the ``keccak256`` hash function, the header must be + encoded using the Recursive-Length Prefix. See :ref:`rlp`. + RLP encoding the header converts it into a space-efficient format that + allows for easy transfer of data between nodes. The purpose of RLP is to + encode arbitrarily nested arrays of binary data, and RLP is the primary + encoding method used to serialize objects in Ethereum's execution layer. + The only purpose of RLP is to encode structure; encoding specific data + types (e.g. strings, floats) is left up to higher-order protocols. + + Parameters + ---------- + header : + Header of interest. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the header. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "header" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition check_gas_limit : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "gas_limit"; "parent_gas_limit" ] |) in + let _ := Constant.str " + Validates the gas limit for a block. + + The bounds of the gas limit, ``max_adjustment_delta``, is set as the + quotient of the parent block's gas limit and the + ``GAS_LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is + passed through as a parameter is greater than or equal to the *sum* of + the parent's gas and the adjustment delta then the limit for gas is too + high and fails this function's check. Similarly, if the limit is less + than or equal to the *difference* of the parent's gas and the adjustment + delta *or* the predefined ``GAS_LIMIT_MINIMUM`` then this function's + check fails because the gas limit doesn't allow for a sufficient or + reasonable amount of gas to be used on a block. + + Parameters + ---------- + gas_limit : + Gas limit to validate. + + parent_gas_limit : + Gas limit of the parent block. + + Returns + ------- + check : `bool` + True if gas limit constraints are satisfied, False otherwise. + " in + let max_adjustment_delta := + BinOp.floor_div (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "gas_limit" |), BinOp.add (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| M.get_name (| globals, "gas_limit" |), BinOp.sub (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "gas_limit" |), M.get_name (| globals, "GAS_LIMIT_MINIMUM" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + Constant.bool true + |) in + M.pure Constant.None_)). + +Definition calculate_block_difficulty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "block_number"; "block_timestamp"; "parent_timestamp"; "parent_difficulty" ] |) in + let _ := Constant.str " + Computes difficulty of a block using its header and parent header. + + The difficulty is determined by the time the block was created after its + parent. The ``offset`` is calculated using the parent block's difficulty, + ``parent_difficulty``, and the timestamp between blocks. This offset is + then added to the parent difficulty and is stored as the ``difficulty`` + variable. If the time between the block and its parent is too short, the + offset will result in a positive number thus making the sum of + ``parent_difficulty`` and ``offset`` to be a greater value in order to + avoid mass forking. But, if the time is long enough, then the offset + results in a negative value making the block less difficult than + its parent. + + The base standard for a block's difficulty is the predefined value + set for the genesis block since it has no parent. So, a block + can't be less difficult than the genesis block, therefore each block's + difficulty is set to the maximum value between the calculated + difficulty and the ``GENESIS_DIFFICULTY``. + + Parameters + ---------- + block_number : + Block number of the block. + block_timestamp : + Timestamp of the block. + parent_timestamp : + Timestamp of the parent block. + parent_difficulty : + difficulty of the parent block. + + Returns + ------- + difficulty : `ethereum.base_types.Uint` + Computed difficulty for a block. + " in + let offset := + BinOp.mult (| + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "parent_difficulty" |) + ], + make_dict [] + |), + Constant.int 2048 + |), + M.call (| + M.get_name (| globals, "max" |), + make_list [ + BinOp.sub (| + Constant.int 1, + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "block_timestamp" |), + M.get_name (| globals, "parent_timestamp" |) + |) + ], + make_dict [] + |), + Constant.int 10 + |) + |); + UnOp.sub (| Constant.int 99 |) + ], + make_dict [] + |) + |) in + let difficulty := + BinOp.add (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "parent_difficulty" |) + ], + make_dict [] + |), + M.get_name (| globals, "offset" |) + |) in + let num_bomb_periods := + BinOp.sub (| + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "block_number" |) + ], + make_dict [] + |), + Constant.int 100000 + |), + Constant.int 2 + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "num_bomb_periods" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let difficulty := BinOp.add + BinOp.pow (| + Constant.int 2, + M.get_name (| globals, "num_bomb_periods" |) + |) + BinOp.pow (| + Constant.int 2, + M.get_name (| globals, "num_bomb_periods" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "max" |), + make_list [ + M.get_name (| globals, "difficulty" |); + M.get_name (| globals, "MINIMUM_DIFFICULTY" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/fork_types.v b/CoqOfPython/ethereum/tangerine_whistle/fork_types.v new file mode 100644 index 0000000..d12953d --- /dev/null +++ b/CoqOfPython/ethereum/tangerine_whistle/fork_types.v @@ -0,0 +1,102 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Types +^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Types re-used throughout the specification, which are specific to Ethereum. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes20 : + IsGlobalAlias globals base_types.globals "Bytes20". +Axiom base_types_Bytes256 : + IsGlobalAlias globals base_types.globals "Bytes256". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require crypto.hash. +Axiom crypto_hash_Hash32 : + IsGlobalAlias globals crypto.hash.globals "Hash32". +Axiom crypto_hash_keccak256 : + IsGlobalAlias globals crypto.hash.globals "keccak256". + +Definition Address : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Bytes20" |) +)). + +Definition Root : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Hash32" |) +)). + +Definition Bloom : Value.t := M.run ltac:(M.monadic ( + M.get_name (| globals, "Bytes256" |) +)). + +Definition Account : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition EMPTY_ACCOUNT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Account" |), + make_list [], + make_dict [] + |) +)). + +Definition encode_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "raw_account_data"; "storage_root" ] |) in + let _ := Constant.str " + Encode `Account` dataclass. + + Storage is not stored in the `Account` dataclass, so `Accounts` cannot be + encoded with providing a storage root. + " in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "raw_account_data" |), "nonce" |); M.get_field (| M.get_name (| globals, "raw_account_data" |), "balance" |); M.get_name (| globals, "storage_root" |); M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_field (| M.get_name (| globals, "raw_account_data" |), "code" |) + ], + make_dict [] + |) ] + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/state.v b/CoqOfPython/ethereum/tangerine_whistle/state.v new file mode 100644 index 0000000..38fe9d1 --- /dev/null +++ b/CoqOfPython/ethereum/tangerine_whistle/state.v @@ -0,0 +1,865 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +State +^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The state contains all information that is preserved between transactions. + +It consists of a main account trie and storage tries for each contract. + +There is a distinction between an account that does not exist and +`EMPTY_ACCOUNT`. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_field : + IsGlobalAlias globals dataclasses.globals "field". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_modify : + IsGlobalAlias globals ethereum.base_types.globals "modify". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require fork_types. +Axiom fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". +Axiom fork_types_Account : + IsGlobalAlias globals fork_types.globals "Account". +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Require trie. +Axiom trie_EMPTY_TRIE_ROOT : + IsGlobalAlias globals trie.globals "EMPTY_TRIE_ROOT". +Axiom trie_Trie : + IsGlobalAlias globals trie.globals "Trie". +Axiom trie_copy_trie : + IsGlobalAlias globals trie.globals "copy_trie". +Axiom trie_root : + IsGlobalAlias globals trie.globals "root". +Axiom trie_trie_get : + IsGlobalAlias globals trie.globals "trie_get". +Axiom trie_trie_set : + IsGlobalAlias globals trie.globals "trie_set". + +Definition State : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition close_state : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Free resources held by the state. Used by optimized implementations to + release file descriptors. + " in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) |) in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |) in + let _ := M.delete (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) in + M.pure Constant.None_)). + +Definition begin_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Start a state transaction. + + Transactions are entirely implicit and can be nested. It is not possible to + calculate the state root during a transaction. + + Parameters + ---------- + state : State + The state. + " in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), "append" |), + make_list [ + make_tuple [ M.call (| + M.get_name (| globals, "copy_trie" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) + ], + make_dict [] + |); {M.get_name (| globals, "k" |): M.call (| + M.get_name (| globals, "copy_trie" |), + make_list [ + M.get_name (| globals, "t" |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)} ] + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition commit_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Commit a state transaction. + + Parameters + ---------- + state : State + The state. + " in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), "pop" |), + make_list [], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition rollback_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Rollback a state transaction, resetting the state to the point when the + corresponding `start_transaction()` call was made. + + Parameters + ---------- + state : State + The state. + " in + let _ := M.assign (| + make_tuple [ M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) ], + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), "pop" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition get_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Get the `Account` object at an address. Returns `EMPTY_ACCOUNT` if there + is no account at the address. + + Use `get_account_optional()` if you care about the difference between a + non-existent account and `EMPTY_ACCOUNT`. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address to lookup. + + Returns + ------- + account : `Account` + Account at address. + " in + let account := + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "account" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "account" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "EMPTY_ACCOUNT" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition get_account_optional : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Get the `Account` object at an address. Returns `None` (rather than + `EMPTY_ACCOUNT`) if there is no account at the address. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address to lookup. + + Returns + ------- + account : `Account` + Account at address. + " in + let account := + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "account" |) + |) in + M.pure Constant.None_)). + +Definition set_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "account" ] |) in + let _ := Constant.str " + Set the `Account` object at an address. Setting to `None` deletes + the account (but not its storage, see `destroy_account()`). + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address to set. + account : `Account` + Account to set at address. + " in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "account" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition destroy_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Completely remove the account at `address` and all of its storage. + + This function is made available exclusively for the `SELFDESTRUCT` + opcode. It is expected that `SELFDESTRUCT` will be disabled in a future + hardfork and this function will be removed. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of account to destroy. + " in + let _ := M.call (| + M.get_name (| globals, "destroy_storage" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + Constant.None_ + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition destroy_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Completely remove the storage at `address`. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of account whose storage is to be deleted. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition get_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "key" ] |) in + let _ := Constant.str " + Get a value at a storage key on an account. Returns `U256(0)` if the + storage key has not been set previously. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of the account. + key : `Bytes` + Key to lookup. + + Returns + ------- + value : `U256` + Value at the key. + " in + let trie := + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let _ := M.assert (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "U256" |) + ], + make_dict [] + |) |) in + let _ := M.return_ (| + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_)). + +Definition set_storage : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "key"; "value" ] |) in + let _ := Constant.str " + Set a value at a storage key on an account. Setting to `U256(0)` deletes + the key. + + Parameters + ---------- + state: `State` + The state + address : `Address` + Address of the account. + key : `Bytes` + Key to set. + value : `U256` + Value to set at the key. + " in + let _ := M.assert (| Compare.is_not (| M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), Constant.None_ |) |) in + let trie := + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let trie := + M.call (| + M.get_name (| globals, "Trie" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), + M.get_name (| globals, "trie" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "key" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), {} |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition storage_root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Calculate the storage root of an account. + + Parameters + ---------- + state: + The state + address : + Address of the account. + + Returns + ------- + root : `Root` + Storage root of the account. + " in + let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "EMPTY_TRIE_ROOT" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition state_root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state" ] |) in + let _ := Constant.str " + Calculate the state root. + + Parameters + ---------- + state: + The current state. + + Returns + ------- + root : `Root` + The state root. + " in + let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition account_exists : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account exists in the state trie + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + account_exists : `bool` + True if account exists in the state trie, False otherwise + " in + let _ := M.return_ (| + Compare.is_not (| M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), Constant.None_ |) + |) in + M.pure Constant.None_)). + +Definition account_has_code_or_nonce : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Checks if an account has non zero nonce or non empty code + + Parameters + ---------- + state: + The state + address: + Address of the account that needs to be checked. + + Returns + ------- + has_code_or_nonce : `bool` + True if if an account has non zero nonce or non empty code, + False otherwise. + " in + let account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + BoolOp.or (| + Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |) + )) + |) + |) in + M.pure Constant.None_)). + +Definition modify_state : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "f" ] |) in + let _ := Constant.str " + Modify an `Account` in the `State`. + " in + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.call (| + M.get_name (| globals, "modify" |), + make_list [ + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |); + M.get_name (| globals, "f" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition move_ether : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "sender_address"; "recipient_address"; "amount" ] |) in + let _ := Constant.str " + Move funds between accounts. + " in +(* At stmt: unsupported node type: FunctionDef *) +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "sender_address" |); + M.get_name (| globals, "reduce_sender_balance" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "recipient_address" |); + M.get_name (| globals, "increase_recipient_balance" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition set_account_balance : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "amount" ] |) in + let _ := Constant.str " + Sets the balance of an account. + + Parameters + ---------- + state: + The current state. + + address: + Address of the account whose nonce needs to be incremented. + + amount: + The amount that needs to set in balance. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "set_balance" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition touch_account : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Initializes an account to state. + + Parameters + ---------- + state: + The current state. + + address: + The address of the account that need to initialised. + " in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "account_exists" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "EMPTY_ACCOUNT" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition increment_nonce : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address" ] |) in + let _ := Constant.str " + Increments the nonce of an account. + + Parameters + ---------- + state: + The current state. + + address: + Address of the account whose nonce needs to be incremented. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "increase_nonce" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition set_code : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "code" ] |) in + let _ := Constant.str " + Sets Account code. + + Parameters + ---------- + state: + The current state. + + address: + Address of the account whose code needs to be update. + + code: + The bytecode that needs to be set. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "write_code" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition create_ether : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "address"; "amount" ] |) in + let _ := Constant.str " + Add newly created ether to an account. + + Parameters + ---------- + state: + The current state. + address: + Address of the account to which ether is added. + amount: + The amount of ether to be added to the account of interest. + " in +(* At stmt: unsupported node type: FunctionDef *) + let _ := M.call (| + M.get_name (| globals, "modify_state" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "increase_balance" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/transactions.v b/CoqOfPython/ethereum/tangerine_whistle/transactions.v new file mode 100644 index 0000000..6d1bc6b --- /dev/null +++ b/CoqOfPython/ethereum/tangerine_whistle/transactions.v @@ -0,0 +1,60 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Transactions are atomic units of work created externally to Ethereum and +submitted to be executed. If Ethereum is viewed as a state machine, +transactions are the events that move between states. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Bytes0 : + IsGlobalAlias globals base_types.globals "Bytes0". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( + Constant.int 21000 +)). + +Definition TX_DATA_COST_PER_NON_ZERO : Value.t := M.run ltac:(M.monadic ( + Constant.int 68 +)). + +Definition TX_DATA_COST_PER_ZERO : Value.t := M.run ltac:(M.monadic ( + Constant.int 4 +)). + +Definition TX_CREATE_COST : Value.t := M.run ltac:(M.monadic ( + Constant.int 32000 +)). + +Definition Transaction : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. diff --git a/CoqOfPython/ethereum/tangerine_whistle/trie.v b/CoqOfPython/ethereum/tangerine_whistle/trie.v new file mode 100644 index 0000000..9b3038d --- /dev/null +++ b/CoqOfPython/ethereum/tangerine_whistle/trie.v @@ -0,0 +1,1357 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +State Trie +^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The state trie is the structure responsible for storing +`.fork_types.Account` objects. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_field : + IsGlobalAlias globals dataclasses.globals "field". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". +Axiom typing_Generic : + IsGlobalAlias globals typing.globals "Generic". +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Mapping : + IsGlobalAlias globals typing.globals "Mapping". +Axiom typing_MutableMapping : + IsGlobalAlias globals typing.globals "MutableMapping". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Sequence : + IsGlobalAlias globals typing.globals "Sequence". +Axiom typing_TypeVar : + IsGlobalAlias globals typing.globals "TypeVar". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". +Axiom typing_cast : + IsGlobalAlias globals typing.globals "cast". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.dao_fork. +Axiom ethereum_dao_fork_trie : + IsGlobalAlias globals ethereum.dao_fork.globals "trie". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require ethereum.utils.hexadecimal. +Axiom ethereum_utils_hexadecimal_hex_to_bytes : + IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". +Axiom base_types_slotted_freezable : + IsGlobalAlias globals base_types.globals "slotted_freezable". + +Require blocks. +Axiom blocks_Receipt : + IsGlobalAlias globals blocks.globals "Receipt". + +Require fork_types. +Axiom fork_types_Account : + IsGlobalAlias globals fork_types.globals "Account". +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". +Axiom fork_types_encode_account : + IsGlobalAlias globals fork_types.globals "encode_account". + +Require transactions. +Axiom transactions_Transaction : + IsGlobalAlias globals transactions.globals "Transaction". + +Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Root" |), + make_list [ + M.call (| + M.get_name (| globals, "hex_to_bytes" |), + make_list [ + Constant.str "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" + ], + make_dict [] + |) + ], + make_dict [] + |) +)). + +Definition Node : Value.t := M.run ltac:(M.monadic ( + M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Bytes" |); M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |); Constant.None_ ] |) +)). + +Definition K : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "TypeVar" |), + make_list [ + Constant.str "K" + ], + make_dict [] + |) +)). + +Definition V : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "TypeVar" |), + make_list [ + Constant.str "V"; + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Account" |) |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Bytes" |) |); + M.get_name (| globals, "Bytes" |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Transaction" |) |); + M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Receipt" |) |); + M.get_name (| globals, "Uint" |); + M.get_name (| globals, "U256" |) + ], + make_dict [] + |) +)). + +Definition LeafNode : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition ExtensionNode : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition BranchNode : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition InternalNode : Value.t := M.run ltac:(M.monadic ( + M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LeafNode" |); M.get_name (| globals, "ExtensionNode" |); M.get_name (| globals, "BranchNode" |) ] |) +)). + +Definition encode_internal_node : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "node" ] |) in + let _ := Constant.str " + Encodes a Merkle Trie node into its RLP form. The RLP will then be + serialized into a `Bytes` and hashed unless it is less that 32 bytes + when serialized. + + This function also accepts `None`, representing the absence of a node, + which is encoded to `b""""""`. + + Parameters + ---------- + node : Optional[InternalNode] + The node to encode. + + Returns + ------- + encoded : `rlp.RLP` + The node encoded as RLP. + " in +(* At stmt: unsupported node type: AnnAssign *) + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "node" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let unencoded := + (* At constant: unsupported node type: Constant *) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "LeafNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "rest_of_key" |); + Constant.bool true + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "ExtensionNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "key_segment" |); + Constant.bool false + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "BranchNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + BinOp.add (| + M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "value" |) + ] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "AssertionError" |), + make_list [ + (* At expr: unsupported node type: JoinedStr *) + ], + make_dict [] + |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let encoded := + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "unencoded" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded" |) + ], + make_dict [] + |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "unencoded" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "encoded" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition encode_node : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "node"; "storage_root" ] |) in + let _ := Constant.str " + Encode a Node for storage in the Merkle Trie. + + Currently mostly an unimplemented stub. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "storage_root" |), Constant.None_ |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "encode_account" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "storage_root" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + make_tuple [ M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "U256" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "cast" |), + make_list [ + M.get_field (| M.get_name (| globals, "rlp" |), "RLP" |); + M.get_name (| globals, "node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "node" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "previous_trie" |), "encode_node" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "storage_root" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition Trie : Value.t := + builtins.make_klass + [(* At base: unsupported node type: Subscript *)] + [ + + ] + [ + + ]. + +Definition copy_trie : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie" ] |) in + let _ := Constant.str " + Create a copy of `trie`. Since only frozen objects may be stored in tries, + the contents are reused. + + Parameters + ---------- + trie: `Trie` + Trie to copy. + + Returns + ------- + new_trie : `Trie[K, V]` + A copy of the trie. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Trie" |), + make_list [ + M.get_field (| M.get_name (| globals, "trie" |), "secured" |); + M.get_field (| M.get_name (| globals, "trie" |), "default" |); + M.call (| + M.get_field (| M.get_name (| globals, "copy" |), "copy" |), + make_list [ + M.get_field (| M.get_name (| globals, "trie" |), "_data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition trie_set : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "key"; "value" ] |) in + let _ := Constant.str " + Stores an item in a Merkle Trie. + + This method deletes the key if `value == trie.default`, because the Merkle + Trie represents the default value by omitting it from the trie. + + Parameters + ---------- + trie: `Trie` + Trie to store in. + key : `Bytes` + Key to lookup. + value : `V` + Node to insert at `key`. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "value" |), M.get_field (| M.get_name (| globals, "trie" |), "default" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.in (| M.get_name (| globals, "key" |), M.get_field (| M.get_name (| globals, "trie" |), "_data" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition trie_get : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "key" ] |) in + let _ := Constant.str " + Gets an item from the Merkle Trie. + + This method returns `trie.default` if the key is missing. + + Parameters + ---------- + trie: + Trie to lookup in. + key : + Key to lookup. + + Returns + ------- + node : `V` + Node at `key` in the trie. + " in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "get" |), + make_list [ + M.get_name (| globals, "key" |); + M.get_field (| M.get_name (| globals, "trie" |), "default" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition common_prefix_length : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "a"; "b" ] |) in + let _ := Constant.str " + Find the longest common prefix of two sequences. + " in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + ], + make_dict [] + |) do + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| M.get_name (| globals, "i" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition nibble_list_to_compact : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "x"; "is_leaf" ] |) in + let _ := Constant.str " + Compresses nibble-list into a standard byte array with a flag. + + A nibble-list is a list of byte values no greater than `15`. The flag is + encoded in high nibble of the highest byte. The flag nibble can be broken + down into two two-bit flags. + + Highest nibble:: + + +---+---+----------+--------+ + | _ | _ | is_leaf | parity | + +---+---+----------+--------+ + 3 2 1 0 + + + The lowest bit of the nibble encodes the parity of the length of the + remaining nibbles -- `0` when even and `1` when odd. The second lowest bit + is used to distinguish leaf and extension nodes. The other two bits are not + used. + + Parameters + ---------- + x : + Array of nibbles. + is_leaf : + True if this is part of a leaf node, or false if it is an extension + node. + + Returns + ------- + compressed : `bytearray` + Compact byte array. + " in + let compact := + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + Constant.int 2 + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.mult (| + Constant.int 16, + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "is_leaf" |) + |) + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + BinOp.add (| + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "is_leaf" |) + |), + Constant.int 1 + |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), Constant.int 0 |) + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 1; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + M.get_name (| globals, "compact" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition bytes_to_nibble_list : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "bytes_" ] |) in + let _ := Constant.str " + Converts a `Bytes` into to a sequence of nibbles (bytes with value < 16). + + Parameters + ---------- + bytes_: + The `Bytes` to convert. + + Returns + ------- + nibble_list : `Bytes` + The `Bytes` in nibble-list format. + " in + let nibble_list := + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [ + BinOp.mult (| + Constant.int 2, + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "bytes_" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + For make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ] in M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "bytes_" |) + ], + make_dict [] + |) do + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |) |), + BinOp.r_shift (| + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 240 + |), + Constant.int 4 + |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |), + Constant.int 1 + |) |), + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 15 + |) + |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + M.get_name (| globals, "nibble_list" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition _prepare_trie : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "get_storage_root" ] |) in + let _ := Constant.str " + Prepares the trie for root calculation. Removes values that are empty, + hashes the keys (if `secured == True`) and encodes all the nodes. + + Parameters + ---------- + trie : + The `Trie` to prepare. + get_storage_root : + Function to get the storage root of an account. Needed to encode + `Account` objects. + + Returns + ------- + out : `Mapping[ethereum.base_types.Bytes, Node]` + Object with keys mapped to nibble-byte form. + " in +(* At stmt: unsupported node type: AnnAssign *) + For make_tuple [ M.get_name (| globals, "preimage" |); M.get_name (| globals, "value" |) ] in M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "items" |), + make_list [], + make_dict [] + |) do + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in + let address := + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |); + M.call (| + M.get_name (| globals, "get_storage_root" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_eq (| M.get_name (| globals, "encoded_value" |), (* At constant: unsupported node type: Constant *) |); + M.get_name (| globals, "AssertionError" |) + ], + make_dict [] + |) in +(* At stmt: unsupported node type: AnnAssign *) + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "trie" |), "secured" |), + (* then *) + ltac:(M.monadic ( + let key := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let key := + M.get_name (| globals, "preimage" |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "mapped" |), M.call (| + M.get_name (| globals, "bytes_to_nibble_list" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |) |), + M.get_name (| globals, "encoded_value" |) + |) in + EndFor. + let _ := M.return_ (| + M.get_name (| globals, "mapped" |) + |) in + M.pure Constant.None_)). + +Definition root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "trie"; "get_storage_root" ] |) in + let _ := Constant.str " + Computes the root of a modified merkle patricia trie (MPT). + + Parameters + ---------- + trie : + `Trie` to get the root of. + get_storage_root : + Function to get the storage root of an account. Needed to encode + `Account` objects. + + + Returns + ------- + root : `.fork_types.Root` + MPT root of the underlying key-value pairs. + " in + let obj := + M.call (| + M.get_name (| globals, "_prepare_trie" |), + make_list [ + M.get_name (| globals, "trie" |); + M.get_name (| globals, "get_storage_root" |) + ], + make_dict [] + |) in + let root_node := + M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_name (| globals, "obj" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assert (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "root_node" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Root" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition patricialize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "obj"; "level" ] |) in + let _ := Constant.str " + Structural composition function. + + Used to recursively patricialize and merkleize a dictionary. Includes + memoization of the tree structure and hashes. + + Parameters + ---------- + obj : + Underlying trie key-value pairs, with keys in nibble-list format. + level : + Current trie level. + + Returns + ------- + node : `ethereum.base_types.Bytes` + Root node of `obj`. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let arbitrary_key := + M.call (| + M.get_name (| globals, "next" |), + make_list [ + M.call (| + M.get_name (| globals, "iter" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), Constant.int 1 |), + (* then *) + ltac:(M.monadic ( + let leaf := + M.call (| + M.get_name (| globals, "LeafNode" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |); + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "leaf" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let substring := + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) in + let prefix_length := + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "substring" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do + let prefix_length := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_name (| globals, "prefix_length" |); + M.call (| + M.get_name (| globals, "common_prefix_length" |), + make_list [ + M.get_name (| globals, "substring" |); + M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let prefix := + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ExtensionNode" |), + make_list [ + M.get_name (| globals, "prefix" |); + M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_name (| globals, "obj" |); + BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in +(* At stmt: unsupported node type: AnnAssign *) + For M.get_name (| globals, "_" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 16 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "branches" |), "append" |), + make_list [ + {} + ], + make_dict [] + |) in + EndFor. + let value := + (* At constant: unsupported node type: Constant *) in + For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |), M.get_name (| globals, "level" |) |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "AssertionError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) + |) in + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "BranchNode" |), + make_list [ + [M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "branches" |), M.get_name (| globals, "k" |) |); + BinOp.add (| + M.get_name (| globals, "level" |), + Constant.int 1 + |) + ], + make_dict [] + |) + ], + make_dict [] + |) for (* At expr: unsupported node type: list *)]; + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/utils/__init__.v b/CoqOfPython/ethereum/tangerine_whistle/utils/__init__.v new file mode 100644 index 0000000..1baedea --- /dev/null +++ b/CoqOfPython/ethereum/tangerine_whistle/utils/__init__.v @@ -0,0 +1,8 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Utility functions unique to this particular fork. +". diff --git a/CoqOfPython/ethereum/tangerine_whistle/utils/address.v b/CoqOfPython/ethereum/tangerine_whistle/utils/address.v new file mode 100644 index 0000000..a9446a6 --- /dev/null +++ b/CoqOfPython/ethereum/tangerine_whistle/utils/address.v @@ -0,0 +1,134 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Hardfork Utility Functions For Addresses +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Address specific functions used in this tangerine whistle version of +specification. +". + +Require typing. +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_left_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Definition to_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "data" ] |) in + let _ := Constant.str " + Convert a Uint or U256 value to a valid address (20 bytes). + + Parameters + ---------- + data : + The string to be converted to bytes. + + Returns + ------- + address : `Address` + The obtained address. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_subscript (| M.call (| + M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition compute_contract_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "address"; "nonce" ] |) in + let _ := Constant.str " + Computes address of the new account that needs to be created. + + Parameters + ---------- + address : + The address of the account that wants to create the new account. + nonce : + The transaction count of the account that wants to create the new + account. + + Returns + ------- + address: `ethereum.tangerine_whistle.fork_types.Address` + The computed address of the new account. + " in + let computed_address := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_list [ + M.get_name (| globals, "address" |); + M.get_name (| globals, "nonce" |) + ] + ], + make_dict [] + |) + ], + make_dict [] + |) in + let canonical_address := + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + let padded_address := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "canonical_address" |); + Constant.int 20 + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "padded_address" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/utils/hexadecimal.v b/CoqOfPython/ethereum/tangerine_whistle/utils/hexadecimal.v new file mode 100644 index 0000000..b6cbc45 --- /dev/null +++ b/CoqOfPython/ethereum/tangerine_whistle/utils/hexadecimal.v @@ -0,0 +1,155 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Utility Functions For Hexadecimal Strings +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Hexadecimal utility functions used in this specification, specific to +Tangerine Whistle types. +". + +Require ethereum.utils.hexadecimal. +Axiom ethereum_utils_hexadecimal_remove_hex_prefix : + IsGlobalAlias globals ethereum.utils.hexadecimal.globals "remove_hex_prefix". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Definition hex_to_root : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to trie root. + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to trie root. + + Returns + ------- + root : `Root` + Trie root obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Root" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition hex_to_bloom : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to bloom. + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to bloom. + + Returns + ------- + bloom : `Bloom` + Bloom obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bloom" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition hex_to_address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to Address (20 bytes). + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to Address. + + Returns + ------- + address : `Address` + The address obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |), "rjust" |), + make_list [ + Constant.int 40; + Constant.str "0" + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/utils/message.v b/CoqOfPython/ethereum/tangerine_whistle/utils/message.v new file mode 100644 index 0000000..e687ac9 --- /dev/null +++ b/CoqOfPython/ethereum/tangerine_whistle/utils/message.v @@ -0,0 +1,198 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Hardfork Utility Functions For The Message Data-structure +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Message specific functions used in this tangerine whistle version of +specification. +". + +Require typing. +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". + +Require vm. +Axiom vm_Environment : + IsGlobalAlias globals vm.globals "Environment". +Axiom vm_Message : + IsGlobalAlias globals vm.globals "Message". + +Require address. +Axiom address_compute_contract_address : + IsGlobalAlias globals address.globals "compute_contract_address". + +Definition prepare_message : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "caller"; "target"; "value"; "data"; "gas"; "env"; "code_address"; "should_transfer_value" ] |) in + let _ := Constant.str " + Execute a transaction against the provided environment. + + Parameters + ---------- + caller : + Address which initiated the transaction + target : + Address whose code will be executed + value : + Value to be transferred. + data : + Array of bytes provided to the code in `target`. + gas : + Gas provided for the code in `target`. + env : + Environment for the Ethereum Virtual Machine. + code_address : + This is usually same as the `target` address except when an alternative + accounts code needs to be executed. + eg. `CALLCODE` calling a precompile. + should_transfer_value : + if True ETH should be transferred while executing a message call. + + Returns + ------- + message: `ethereum.tangerine_whistle.vm.Message` + Items containing contract creation or message call specific data. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Bytes0" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.call (| + M.get_name (| globals, "compute_contract_address" |), + make_list [ + M.get_name (| globals, "caller" |); + BinOp.sub (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "caller" |) + ], + make_dict [] + |), "nonce" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let msg_data := + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |) in + let code := + M.get_name (| globals, "data" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.get_name (| globals, "target" |) in + let msg_data := + M.get_name (| globals, "data" |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "target" |) + ], + make_dict [] + |), "code" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| M.get_name (| globals, "code_address" |), Constant.None_ |), + (* then *) + ltac:(M.monadic ( + let code_address := + M.get_name (| globals, "target" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "AssertionError" |), + make_list [ + Constant.str "Target must be address or empty bytes" + ], + make_dict [] + |) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/__init__.v b/CoqOfPython/ethereum/tangerine_whistle/vm/__init__.v new file mode 100644 index 0000000..49bcb40 --- /dev/null +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/__init__.v @@ -0,0 +1,152 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +The abstract computer which runs the code stored in an +`.fork_types.Account`. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_State : + IsGlobalAlias globals state.globals "State". + +Definition __all__ : Value.t := M.run ltac:(M.monadic ( + make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] +)). + +Definition Environment : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Message : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition Evm : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition incorporate_child_on_success : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "child_evm" ] |) in + let _ := Constant.str " + Incorporate the state of a successful `child_evm` into the parent `evm`. + + Parameters + ---------- + evm : + The parent `EVM`. + child_evm : + The child evm to incorporate. + " in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "gas_left" |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "logs" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "logs" |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "refund_counter" |) + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "accounts_to_delete" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition incorporate_child_on_error : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "child_evm" ] |) in + let _ := Constant.str " + Incorporate the state of an unsuccessful `child_evm` into the parent `evm`. + + Parameters + ---------- + evm : + The parent `EVM`. + child_evm : + The child evm to incorporate. + " in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "gas_left" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/exceptions.v b/CoqOfPython/ethereum/tangerine_whistle/vm/exceptions.v new file mode 100644 index 0000000..45435b3 --- /dev/null +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/exceptions.v @@ -0,0 +1,122 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Exceptions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Exceptions which cause the EVM to halt exceptionally. +". + +Require ethereum.exceptions. +Axiom ethereum_exceptions_EthereumException : + IsGlobalAlias globals ethereum.exceptions.globals "EthereumException". + +Definition ExceptionalHalt : Value.t := + builtins.make_klass + [(globals, "EthereumException")] + [ + + ] + [ + + ]. + +Definition StackUnderflowError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition StackOverflowError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition OutOfGasError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition InvalidOpcode : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + ( + "__init__", + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "self"; "code" ] |) in + let _ := M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "super" |), + make_list [], + make_dict [] + |), "__init__" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "self" |), "code" |), + M.get_name (| globals, "code" |) + |) in + M.pure Constant.None_)) + ) + ]. + +Definition InvalidJumpDestError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition StackDepthLimitError : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. + +Definition AddressCollision : Value.t := + builtins.make_klass + [(globals, "ExceptionalHalt")] + [ + + ] + [ + + ]. diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/__init__.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/__init__.v new file mode 100644 index 0000000..e5bebd7 --- /dev/null +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/__init__.v @@ -0,0 +1,87 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +EVM Instruction Encoding (Opcodes) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Machine readable representations of EVM instructions, and a mapping to their +implementations. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". + +Require __init__. +Axiom __init___arithmetic : + IsGlobalAlias globals __init__.globals "arithmetic". + +Require __init__. +Axiom __init___bitwise : + IsGlobalAlias globals __init__.globals "bitwise". + +Require __init__. +Axiom __init___block : + IsGlobalAlias globals __init__.globals "block". + +Require __init__. +Axiom __init___comparison : + IsGlobalAlias globals __init__.globals "comparison". + +Require __init__. +Axiom __init___control_flow : + IsGlobalAlias globals __init__.globals "control_flow". + +Require __init__. +Axiom __init___environment : + IsGlobalAlias globals __init__.globals "environment". + +Require __init__. +Axiom __init___keccak : + IsGlobalAlias globals __init__.globals "keccak". + +Require __init__. +Axiom __init___log : + IsGlobalAlias globals __init__.globals "log". + +Require __init__. +Axiom __init___memory : + IsGlobalAlias globals __init__.globals "memory". + +Require __init__. +Axiom __init___stack : + IsGlobalAlias globals __init__.globals "stack". + +Require __init__. +Axiom __init___storage : + IsGlobalAlias globals __init__.globals "storage". + +Require __init__. +Axiom __init___system : + IsGlobalAlias globals __init__.globals "system". + +Definition Ops : Value.t := + builtins.make_klass + [(* At base: unsupported node type: Attribute *)] + [ + + ] + [ + + ]. + +(* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/arithmetic.v new file mode 100644 index 0000000..a8b5c61 --- /dev/null +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/arithmetic.v @@ -0,0 +1,1085 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Arithmetic Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM Arithmetic instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U255_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U255_CEIL_VALUE". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_U256_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_get_sign : + IsGlobalAlias globals ethereum.utils.numeric.globals "get_sign". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_EXPONENTIATION : + IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION". +Axiom gas_GAS_EXPONENTIATION_PER_BYTE : + IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION_PER_BYTE". +Axiom gas_GAS_LOW : + IsGlobalAlias globals gas.globals "GAS_LOW". +Axiom gas_GAS_MID : + IsGlobalAlias globals gas.globals "GAS_MID". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition add : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Adds the top two elements of the stack together, and pushes the result back + on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "x" |), "wrapping_add" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition sub : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Subtracts the top two elements of the stack, and pushes the result back + on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "x" |), "wrapping_sub" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mul : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Multiply the top two elements of the stack, and pushes the result back + on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "x" |), "wrapping_mul" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition div : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Integer division of the top two elements of the stack. Pushes the result + back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let dividend := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let divisor := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let quotient := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let quotient := + BinOp.floor_div (| + M.get_name (| globals, "dividend" |), + M.get_name (| globals, "divisor" |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "quotient" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition sdiv : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed integer division of the top two elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let dividend := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let divisor := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let quotient := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_name (| globals, "dividend" |), UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "divisor" |), UnOp.sub (| Constant.int 1 |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let quotient := + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let sign := + M.call (| + M.get_name (| globals, "get_sign" |), + make_list [ + BinOp.mult (| + M.get_name (| globals, "dividend" |), + M.get_name (| globals, "divisor" |) + |) + ], + make_dict [] + |) in + let quotient := + BinOp.mult (| + M.get_name (| globals, "sign" |), + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "dividend" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "divisor" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + M.get_name (| globals, "quotient" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Modulo remainder of the top two elements of the stack. Pushes the result + back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let remainder := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let remainder := + BinOp.mod_ (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "remainder" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition smod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed modulo remainder of the top two elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let y := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let remainder := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let remainder := + BinOp.mult (| + M.call (| + M.get_name (| globals, "get_sign" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + BinOp.mod_ (| + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "abs" |), + make_list [ + M.get_name (| globals, "y" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + M.get_name (| globals, "remainder" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition addmod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Modulo addition of the top 2 elements with the 3rd element. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let z := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_MID" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.add (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |), + M.get_name (| globals, "z" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mulmod : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Modulo multiplication of the top 2 elements with the 3rd element. Pushes + the result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let z := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_MID" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.mult (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |), + M.get_name (| globals, "z" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition exp : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Exponential operation of the top 2 elements. Pushes the result back on + the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let base := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exponent := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let exponent_bits := + M.call (| + M.get_field (| M.get_name (| globals, "exponent" |), "bit_length" |), + make_list [], + make_dict [] + |) in + let exponent_bytes := + BinOp.floor_div (| + BinOp.add (| + M.get_name (| globals, "exponent_bits" |), + Constant.int 7 + |), + Constant.int 8 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_EXPONENTIATION" |), + BinOp.mult (| + M.get_name (| globals, "GAS_EXPONENTIATION_PER_BYTE" |), + M.get_name (| globals, "exponent_bytes" |) + |) + |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "pow" |), + make_list [ + M.get_name (| globals, "base" |); + M.get_name (| globals, "exponent" |); + M.get_name (| globals, "U256_CEIL_VALUE" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition signextend : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Sign extend operation. In other words, extend a signed number which + fits in N bytes to 32 bytes. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let byte_num := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_name (| globals, "byte_num" |), Constant.int 31 |), + (* then *) + ltac:(M.monadic ( + let result := + M.get_name (| globals, "value" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let value_bytes := + M.call (| + M.get_name (| globals, "bytes" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "value" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) in + let value_bytes := + M.get_subscript (| M.get_name (| globals, "value_bytes" |), BinOp.sub (| + Constant.int 31, + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "byte_num" |) + ], + make_dict [] + |) + |):(* At expr: unsupported node type: NoneType *) |) in + let sign_bit := + BinOp.r_shift (| + M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), + Constant.int 7 + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "sign_bit" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "value_bytes" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let num_bytes_prepend := + BinOp.sub (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "byte_num" |), + Constant.int 1 + |) + |) in + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + BinOp.add (| + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [ + BinOp.mult (| + make_list [ + Constant.int 255 + ], + M.get_name (| globals, "num_bytes_prepend" |) + |) + ], + make_dict [] + |), + M.get_name (| globals, "value_bytes" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/bitwise.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/bitwise.v new file mode 100644 index 0000000..b20a1e5 --- /dev/null +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/bitwise.v @@ -0,0 +1,345 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Bitwise Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM bitwise instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition bitwise_and : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise AND operation of the top 2 elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + BinOp.bit_and (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_or : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise OR operation of the top 2 elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + BinOp.bit_or (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_xor : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise XOR operation of the top 2 elements of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let y := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + BinOp.bit_xor (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "y" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition bitwise_not : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Bitwise NOT operation of the top element of the stack. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + UnOp.invert (| M.get_name (| globals, "x" |) |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition get_byte : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + For a word (defined by next top element of the stack), retrieve the + Nth byte (0-indexed and defined by top element of stack) from the + left (most significant) to right (least significant). + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let byte_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let word := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| M.get_name (| globals, "byte_index" |), Constant.int 32 |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let extra_bytes_to_right := + BinOp.sub (| + Constant.int 31, + M.get_name (| globals, "byte_index" |) + |) in + let word := + BinOp.r_shift (| + M.get_name (| globals, "word" |), + BinOp.mult (| + M.get_name (| globals, "extra_bytes_to_right" |), + Constant.int 8 + |) + |) in + let word := + BinOp.bit_and (| + M.get_name (| globals, "word" |), + Constant.int 255 + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "word" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/block.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/block.v new file mode 100644 index 0000000..e5fa554 --- /dev/null +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/block.v @@ -0,0 +1,337 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Block Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM block instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_BLOCK_HASH : + IsGlobalAlias globals gas.globals "GAS_BLOCK_HASH". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition block_hash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the hash of one of the 256 most recent complete blocks onto the + stack. The block number to hash is present at the top of the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let block_number := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BLOCK_HASH" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt_e (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), M.get_name (| globals, "block_number" |) |), + ltac:(M.monadic ( + Compare.gt (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), BinOp.add (| + M.get_name (| globals, "block_number" |), + Constant.int 256 + |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let hash := + (* At constant: unsupported node type: Constant *) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let hash := + M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + M.get_name (| globals, "block_number" |) + |) |) |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "hash" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition coinbase : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's beneficiary address (address of the block miner) + onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "coinbase" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition timestamp : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's timestamp onto the stack. Here the timestamp + being referred is actually the unix timestamp in seconds. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "time" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition number : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's number onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition difficulty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's difficulty onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "difficulty" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition gas_limit : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the current block's gas limit onto the stack. + + Here the current block refers to the block in which the currently + executing transaction/call resides. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "gas_limit" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/comparison.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/comparison.v new file mode 100644 index 0000000..fbc35f8 --- /dev/null +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/comparison.v @@ -0,0 +1,404 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Comparison Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM Comparison instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition less_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is less than the next top element. Pushes the + result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let right := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition signed_less_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed less-than comparison. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let right := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition greater_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is greater than the next top element. Pushes + the result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let right := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition signed_greater_than : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Signed greater-than comparison. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let right := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_signed" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition equal : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is equal to the next top element. Pushes + the result back on the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let left := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let right := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.eq (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition is_zero : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Checks if the top element is equal to 0. Pushes the result back on the + stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let x := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Compare.eq (| M.get_name (| globals, "x" |), Constant.int 0 |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "result" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/control_flow.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/control_flow.v new file mode 100644 index 0000000..04a79d9 --- /dev/null +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/control_flow.v @@ -0,0 +1,336 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Control Flow Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM control flow instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require vm.gas. +Axiom vm_gas_GAS_BASE : + IsGlobalAlias globals vm.gas.globals "GAS_BASE". +Axiom vm_gas_GAS_HIGH : + IsGlobalAlias globals vm.gas.globals "GAS_HIGH". +Axiom vm_gas_GAS_JUMPDEST : + IsGlobalAlias globals vm.gas.globals "GAS_JUMPDEST". +Axiom vm_gas_GAS_MID : + IsGlobalAlias globals vm.gas.globals "GAS_MID". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_InvalidJumpDestError : + IsGlobalAlias globals exceptions.globals "InvalidJumpDestError". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition stop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stop further execution of EVM code. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let _ := M.pass (| |) in + let _ := M.pass (| |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "running" |), + Constant.bool false + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition jump : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Alter the program counter to the location specified by the top of the + stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let jump_dest := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_MID" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "jump_dest" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition jumpi : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Alter the program counter to the specified location if and only if a + condition is true. If the condition is not true, then the program counter + would increase only by 1. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let jump_dest := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let conditional_value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_HIGH" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "conditional_value" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let destination := + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let destination := + M.get_name (| globals, "jump_dest" |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "destination" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition pc : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push onto the stack the value of the program counter after reaching the + current instruction and without increasing it for the next instruction. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "pc" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition gas_left : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the amount of available gas (including the corresponding reduction + for the cost of this instruction) onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition jumpdest : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Mark a valid destination for jumps. This is a noop, present only + to be used by `JUMP` and `JUMPI` opcodes to verify that their jump is + valid. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_JUMPDEST" |) + ], + make_dict [] + |) in + let _ := M.pass (| |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/environment.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/environment.v new file mode 100644 index 0000000..4d26a46 --- /dev/null +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/environment.v @@ -0,0 +1,943 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Environmental Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM environment related instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require state. +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". + +Require utils.address. +Axiom utils_address_to_address : + IsGlobalAlias globals utils.address.globals "to_address". + +Require vm.memory. +Axiom vm_memory_buffer_read : + IsGlobalAlias globals vm.memory.globals "buffer_read". +Axiom vm_memory_memory_write : + IsGlobalAlias globals vm.memory.globals "memory_write". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_BALANCE : + IsGlobalAlias globals gas.globals "GAS_BALANCE". +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_COPY : + IsGlobalAlias globals gas.globals "GAS_COPY". +Axiom gas_GAS_EXTERNAL : + IsGlobalAlias globals gas.globals "GAS_EXTERNAL". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition address : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the address of the current executing account to the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition balance : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the balance of the given account onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BALANCE" |) + ], + make_dict [] + |) in + let balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "balance" |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "balance" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition origin : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the address of the original transaction sender to the stack. + The origin address can only be an EOA. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "origin" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition caller : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes the address of the caller onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "caller" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition callvalue : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the value (in wei) sent with the call onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition calldataload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push a word (32 bytes) of the input data belonging to the current + environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |); + M.get_name (| globals, "start_index" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition calldatasize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the size of input data in current environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition calldatacopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy a portion of the input data in current environment to memory. + + This will also expand the memory, in case that the memory is insufficient + to store the data. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let data_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |); + M.get_name (| globals, "data_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition codesize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the size of code running in current environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "code" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition codecopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy a portion of the code in current environment to memory. + + This will also expand the memory, in case that the memory is insufficient + to store the data. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let code_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "code" |); + M.get_name (| globals, "code_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition gasprice : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the gas price used in current environment onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "gas_price" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition extcodesize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the code size of a given account onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_EXTERNAL" |) + ], + make_dict [] + |) in + let codesize := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "code" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "codesize" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition extcodecopy : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Copy a portion of an account's code to memory. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let code_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let copy_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_COPY" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_EXTERNAL" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "code" |) in + let value := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "code" |); + M.get_name (| globals, "code_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/keccak.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/keccak.v new file mode 100644 index 0000000..cab9ffb --- /dev/null +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/keccak.v @@ -0,0 +1,181 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Keccak Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM keccak instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_KECCAK256 : + IsGlobalAlias globals gas.globals "GAS_KECCAK256". +Axiom gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition keccak : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Pushes to the stack the Keccak-256 hash of a region of memory. + + This also expands the memory, in case the memory is insufficient to + access the data's memory location. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let word_gas_cost := + BinOp.mult (| + M.get_name (| globals, "GAS_KECCAK256_WORD" |), + M.get_name (| globals, "words" |) + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_KECCAK256" |), + M.get_name (| globals, "word_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let data := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "hash" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/log.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/log.v new file mode 100644 index 0000000..f246f9d --- /dev/null +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/log.v @@ -0,0 +1,228 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Logging Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM logging instructions. +". + +Require functools. +Axiom functools_partial : + IsGlobalAlias globals functools.globals "partial". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_LOG : + IsGlobalAlias globals gas.globals "GAS_LOG". +Axiom gas_GAS_LOG_DATA : + IsGlobalAlias globals gas.globals "GAS_LOG_DATA". +Axiom gas_GAS_LOG_TOPIC : + IsGlobalAlias globals gas.globals "GAS_LOG_TOPIC". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". + +Definition log_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "num_topics" ] |) in + let _ := Constant.str " + Appends a log entry, having `num_topics` topics, to the evm logs. + + This will also expand the memory if the data (required by the log entry) + corresponding to the memory is not accessible. + + Parameters + ---------- + evm : + The current EVM frame. + num_topics : + The number of topics to be included in the log entry. + + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let topics := + make_list [] in + For M.get_name (| globals, "_" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "num_topics" |) + ], + make_dict [] + |) do + let topic := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "topics" |), "append" |), + make_list [ + M.get_name (| globals, "topic" |) + ], + make_dict [] + |) in + EndFor. + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_LOG" |), + BinOp.mult (| + M.get_name (| globals, "GAS_LOG_DATA" |), + M.get_name (| globals, "size" |) + |) + |), + BinOp.mult (| + M.get_name (| globals, "GAS_LOG_TOPIC" |), + M.get_name (| globals, "num_topics" |) + |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let log_entry := + M.call (| + M.get_name (| globals, "Log" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "logs" |), + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "logs" |), + make_tuple [ M.get_name (| globals, "log_entry" |) ] + |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition log0 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). + +Definition log4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "log_n" |) + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/memory.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/memory.v new file mode 100644 index 0000000..1e1c8b0 --- /dev/null +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/memory.v @@ -0,0 +1,378 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Memory Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM Memory instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". +Axiom memory_memory_write : + IsGlobalAlias globals memory.globals "memory_write". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition mstore : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a word to memory. + This also expands the memory, if the memory is + insufficient to store the word. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "start_position" |); M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + ], + make_dict [] + |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "start_position" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mstore8 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a byte to memory. + This also expands the memory, if the memory is + insufficient to store the word. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "start_position" |); M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let normalized_bytes_value := + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + make_list [ + BinOp.bit_and (| + M.get_name (| globals, "value" |), + Constant.int 255 + |) + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "start_position" |); + M.get_name (| globals, "normalized_bytes_value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition mload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Load word from memory. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "start_position" |); M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_VERY_LOW" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + (* At constant: unsupported node type: Constant *), + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "start_position" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition msize : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Push the size of active memory in bytes onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/stack.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/stack.v new file mode 100644 index 0000000..1eeda05 --- /dev/null +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/stack.v @@ -0,0 +1,929 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Stack Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM stack related instructions. +". + +Require functools. +Axiom functools_partial : + IsGlobalAlias globals functools.globals "partial". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". +Axiom __init___stack : + IsGlobalAlias globals __init__.globals "stack". + +Require exceptions. +Axiom exceptions_StackUnderflowError : + IsGlobalAlias globals exceptions.globals "StackUnderflowError". + +Require gas. +Axiom gas_GAS_BASE : + IsGlobalAlias globals gas.globals "GAS_BASE". +Axiom gas_GAS_VERY_LOW : + IsGlobalAlias globals gas.globals "GAS_VERY_LOW". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require memory. +Axiom memory_buffer_read : + IsGlobalAlias globals memory.globals "buffer_read". + +Definition pop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Remove item from stack. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + let _ := M.pass (| |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition push_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "num_bytes" ] |) in + let _ := Constant.str " + Pushes a N-byte immediate onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + num_bytes : + The number of immediate bytes to be read from the code and pushed to + the stack. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let data_to_push := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "code" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "num_bytes" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "data_to_push" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + BinOp.add (| + Constant.int 1, + M.get_name (| globals, "num_bytes" |) + |) + |) in + M.pure Constant.None_)). + +Definition dup_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "item_number" ] |) in + let _ := Constant.str " + Duplicate the Nth stack item (from top of the stack) to the top of stack. + + Parameters + ---------- + evm : + The current EVM frame. + + item_number : + The stack item number (0-indexed from top of stack) to be duplicated + to the top of stack. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "StackUnderflowError" |) + ], + make_dict [] + |) in + let data_to_duplicate := + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + BinOp.sub (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), + Constant.int 1 + |), + M.get_name (| globals, "item_number" |) + |) |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "data_to_duplicate" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition swap_n : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "item_number" ] |) in + let _ := Constant.str " + Swap the top and the `item_number` element of the stack, where + the top of the stack is position zero. + + If `item_number` is zero, this function does nothing (which should not be + possible, since there is no `SWAP0` instruction). + + Parameters + ---------- + evm : + The current EVM frame. + + item_number : + The stack item number (0-indexed from top of stack) to be swapped + with the top of stack element. + + " in + let _ := M.pass (| |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_VERY_LOW" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "StackUnderflowError" |) + ], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) |) ], + make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |) ] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition push1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push5 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push6 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push7 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push8 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push9 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push10 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push11 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push12 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push13 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push14 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push15 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push16 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push17 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push18 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push19 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push20 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push21 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push22 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push23 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push24 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push25 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push26 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push27 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push28 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push29 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push30 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push31 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition push32 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "push_n" |) + ], + make_dict [] + |) +)). + +Definition dup1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup5 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup6 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup7 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup8 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup9 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup10 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup11 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup12 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup13 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup14 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup15 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition dup16 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "dup_n" |) + ], + make_dict [] + |) +)). + +Definition swap1 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap2 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap3 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap4 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap5 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap6 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap7 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap8 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap9 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap10 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap11 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap12 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap13 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap14 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap15 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). + +Definition swap16 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "partial" |), + make_list [ + M.get_name (| globals, "swap_n" |) + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/storage.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/storage.v new file mode 100644 index 0000000..4292e3b --- /dev/null +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/storage.v @@ -0,0 +1,212 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Storage Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM storage related instructions. +". + +Require state. +Axiom state_get_storage : + IsGlobalAlias globals state.globals "get_storage". +Axiom state_set_storage : + IsGlobalAlias globals state.globals "set_storage". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require gas. +Axiom gas_GAS_SLOAD : + IsGlobalAlias globals gas.globals "GAS_SLOAD". +Axiom gas_GAS_STORAGE_CLEAR_REFUND : + IsGlobalAlias globals gas.globals "GAS_STORAGE_CLEAR_REFUND". +Axiom gas_GAS_STORAGE_SET : + IsGlobalAlias globals gas.globals "GAS_STORAGE_SET". +Axiom gas_GAS_STORAGE_UPDATE : + IsGlobalAlias globals gas.globals "GAS_STORAGE_UPDATE". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition sload : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Loads to the stack, the value corresponding to a certain key from the + storage of the current account. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let key := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_SLOAD" |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "get_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition sstore : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stores a value at a certain key in the current context's storage. + + Parameters + ---------- + evm : + The current EVM frame. + + " in + let key := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let new_value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let current_value := + M.call (| + M.get_name (| globals, "get_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "new_value" |), Constant.int 0 |), + ltac:(M.monadic ( + Compare.eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let gas_cost := + M.get_name (| globals, "GAS_STORAGE_SET" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let gas_cost := + M.get_name (| globals, "GAS_STORAGE_UPDATE" |) in + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| M.get_name (| globals, "new_value" |), Constant.int 0 |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "gas_cost" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "set_storage" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "key" |); + M.get_name (| globals, "new_value" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/interpreter.v b/CoqOfPython/ethereum/tangerine_whistle/vm/interpreter.v new file mode 100644 index 0000000..2aa7a4c --- /dev/null +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/interpreter.v @@ -0,0 +1,551 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Interpreter +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +A straightforward interpreter that executes EVM code. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.trace. +Axiom ethereum_trace_EvmStop : + IsGlobalAlias globals ethereum.trace.globals "EvmStop". +Axiom ethereum_trace_OpEnd : + IsGlobalAlias globals ethereum.trace.globals "OpEnd". +Axiom ethereum_trace_OpException : + IsGlobalAlias globals ethereum.trace.globals "OpException". +Axiom ethereum_trace_OpStart : + IsGlobalAlias globals ethereum.trace.globals "OpStart". +Axiom ethereum_trace_PrecompileEnd : + IsGlobalAlias globals ethereum.trace.globals "PrecompileEnd". +Axiom ethereum_trace_PrecompileStart : + IsGlobalAlias globals ethereum.trace.globals "PrecompileStart". +Axiom ethereum_trace_TransactionEnd : + IsGlobalAlias globals ethereum.trace.globals "TransactionEnd". +Axiom ethereum_trace_evm_trace : + IsGlobalAlias globals ethereum.trace.globals "evm_trace". + +Require blocks. +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_account_has_code_or_nonce : + IsGlobalAlias globals state.globals "account_has_code_or_nonce". +Axiom state_begin_transaction : + IsGlobalAlias globals state.globals "begin_transaction". +Axiom state_commit_transaction : + IsGlobalAlias globals state.globals "commit_transaction". +Axiom state_destroy_storage : + IsGlobalAlias globals state.globals "destroy_storage". +Axiom state_move_ether : + IsGlobalAlias globals state.globals "move_ether". +Axiom state_rollback_transaction : + IsGlobalAlias globals state.globals "rollback_transaction". +Axiom state_set_code : + IsGlobalAlias globals state.globals "set_code". +Axiom state_touch_account : + IsGlobalAlias globals state.globals "touch_account". + +Require vm. +Axiom vm_Message : + IsGlobalAlias globals vm.globals "Message". + +Require vm.gas. +Axiom vm_gas_GAS_CODE_DEPOSIT : + IsGlobalAlias globals vm.gas.globals "GAS_CODE_DEPOSIT". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require vm.precompiled_contracts.mapping. +Axiom vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : + IsGlobalAlias globals vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". + +Require __init__. +Axiom __init___Environment : + IsGlobalAlias globals __init__.globals "Environment". +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_AddressCollision : + IsGlobalAlias globals exceptions.globals "AddressCollision". +Axiom exceptions_ExceptionalHalt : + IsGlobalAlias globals exceptions.globals "ExceptionalHalt". +Axiom exceptions_InvalidOpcode : + IsGlobalAlias globals exceptions.globals "InvalidOpcode". +Axiom exceptions_StackDepthLimitError : + IsGlobalAlias globals exceptions.globals "StackDepthLimitError". + +Require instructions. +Axiom instructions_Ops : + IsGlobalAlias globals instructions.globals "Ops". +Axiom instructions_op_implementation : + IsGlobalAlias globals instructions.globals "op_implementation". + +Require runtime. +Axiom runtime_get_valid_jump_destinations : + IsGlobalAlias globals runtime.globals "get_valid_jump_destinations". + +Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1024 + ], + make_dict [] + |) +)). + +Definition MessageCallOutput : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition process_message_call : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + If `message.current` is empty then it creates a smart contract + else it executes a call from the `message.caller` to the `message.target`. + + Parameters + ---------- + message : + Transaction specific items. + + env : + External items required for EVM execution. + + Returns + ------- + output : `MessageCallOutput` + Output of the message call + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_field (| M.get_name (| globals, "message" |), "target" |), M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let is_collision := + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_name (| globals, "is_collision" |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallOutput" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "tuple" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "AddressCollision" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let evm := + M.call (| + M.get_name (| globals, "process_create_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let evm := + M.call (| + M.get_name (| globals, "process_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( +(* At stmt: unsupported node type: AnnAssign *) + let accounts_to_delete := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let refund_counter := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let logs := + M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in + let accounts_to_delete := + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in + let refund_counter := + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |) in + M.pure Constant.None_ + )) |) in + let tx_end := + M.call (| + M.get_name (| globals, "TransactionEnd" |), + make_list [ + BinOp.sub (| + M.get_field (| M.get_name (| globals, "message" |), "gas" |), + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + |); + M.get_field (| M.get_name (| globals, "evm" |), "output" |); + M.get_field (| M.get_name (| globals, "evm" |), "error" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "evm_trace" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "tx_end" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallOutput" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition process_create_message : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + Executes a call to create a smart contract. + + Parameters + ---------- + message : + Transaction specific items. + env : + External items required for EVM execution. + + Returns + ------- + evm: :py:class:`~ethereum.tangerine_whistle.vm.Evm` + Items containing execution specific objects. + " in + let _ := M.call (| + M.get_name (| globals, "begin_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "destroy_storage" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let evm := + M.call (| + M.get_name (| globals, "process_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), + (* then *) + ltac:(M.monadic ( + let contract_code := + M.get_field (| M.get_name (| globals, "evm" |), "output" |) in + let contract_code_gas := + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "contract_code" |) + ], + make_dict [] + |), + M.get_name (| globals, "GAS_CODE_DEPOSIT" |) + |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "rollback_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.get_name (| globals, "evm" |) + |) in + M.pure Constant.None_)). + +Definition process_message : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + Executes a call to create a smart contract. + + Parameters + ---------- + message : + Transaction specific items. + env : + External items required for EVM execution. + + Returns + ------- + evm: :py:class:`~ethereum.tangerine_whistle.vm.Evm` + Items containing execution specific objects + " in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| M.get_field (| M.get_name (| globals, "message" |), "depth" |), M.get_name (| globals, "STACK_DEPTH_LIMIT" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.call (| + M.get_name (| globals, "StackDepthLimitError" |), + make_list [ + Constant.str "Stack depth limit reached" + ], + make_dict [] + |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "begin_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "touch_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + M.get_field (| M.get_name (| globals, "message" |), "should_transfer_value" |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_field (| M.get_name (| globals, "message" |), "value" |), Constant.int 0 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "move_ether" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "caller" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |); + M.get_field (| M.get_name (| globals, "message" |), "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let evm := + M.call (| + M.get_name (| globals, "execute_code" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "rollback_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "commit_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.get_name (| globals, "evm" |) + |) in + M.pure Constant.None_)). + +Definition execute_code : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "message"; "env" ] |) in + let _ := Constant.str " + Executes bytecode present in the `message`. + + Parameters + ---------- + message : + Transaction specific items. + env : + External items required for EVM execution. + + Returns + ------- + evm: `ethereum.vm.EVM` + Items containing execution specific objects + " in + let code := + M.get_field (| M.get_name (| globals, "message" |), "code" |) in + let valid_jump_destinations := + M.call (| + M.get_name (| globals, "get_valid_jump_destinations" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) in + let evm := + M.call (| + M.get_name (| globals, "Evm" |), + make_list [], + make_dict [] + |) in +(* At stmt: unsupported node type: Try *) + let _ := M.return_ (| + M.get_name (| globals, "evm" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/memory.v b/CoqOfPython/ethereum/tangerine_whistle/vm/memory.v new file mode 100644 index 0000000..fa8d906 --- /dev/null +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/memory.v @@ -0,0 +1,153 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Memory +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +EVM memory operations. +". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_right_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "right_pad_zero_bytes". + +Require base_types. +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". + +Definition memory_write : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "memory"; "start_position"; "value" ] |) in + let _ := Constant.str " + Writes to memory. + + Parameters + ---------- + memory : + Memory contents of the EVM. + start_position : + Starting pointer to the memory. + value : + Data to write to memory. + " in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) |), + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_)). + +Definition memory_read_bytes : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "memory"; "start_position"; "size" ] |) in + let _ := Constant.str " + Read bytes from memory. + + Parameters + ---------- + memory : + Memory contents of the EVM. + start_position : + Starting pointer to the memory. + size : + Size of the data that needs to be read from `start_position`. + + Returns + ------- + data_bytes : + Data read from memory. + " in + let _ := M.return_ (| + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |) + |) in + M.pure Constant.None_)). + +Definition buffer_read : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "buffer"; "start_position"; "size" ] |) in + let _ := Constant.str " + Read bytes from a buffer. Padding with zeros if necessary. + + Parameters + ---------- + buffer : + Memory contents of the EVM. + start_position : + Starting pointer to the memory. + size : + Size of the data that needs to be read from `start_position`. + + Returns + ------- + data_bytes : + Data read from memory. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "right_pad_zero_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |):BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/__init__.v new file mode 100644 index 0000000..422f670 --- /dev/null +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/__init__.v @@ -0,0 +1,67 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Precompiled Contract Addresses +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Addresses of precompiled contracts and mappings to their +implementations. +". + +Require utils.hexadecimal. +Axiom utils_hexadecimal_hex_to_address : + IsGlobalAlias globals utils.hexadecimal.globals "hex_to_address". + +Definition __all__ : Value.t := M.run ltac:(M.monadic ( + make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS" ] +)). + +Definition ECRECOVER_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x01" + ], + make_dict [] + |) +)). + +Definition SHA256_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x02" + ], + make_dict [] + |) +)). + +Definition RIPEMD160_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x03" + ], + make_dict [] + |) +)). + +Definition IDENTITY_ADDRESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "hex_to_address" |), + make_list [ + Constant.str "0x04" + ], + make_dict [] + |) +)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/ecrecover.v new file mode 100644 index 0000000..cc351b5 --- /dev/null +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/ecrecover.v @@ -0,0 +1,269 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) ECRECOVER PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the ECRECOVER precompiled contract. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require ethereum.crypto.elliptic_curve. +Axiom ethereum_crypto_elliptic_curve_SECP256K1N : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_left_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_ECRECOVER : + IsGlobalAlias globals vm.gas.globals "GAS_ECRECOVER". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Require vm.memory. +Axiom vm_memory_buffer_read : + IsGlobalAlias globals vm.memory.globals "buffer_read". + +Definition ecrecover : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Decrypts the address using elliptic curve DSA recovery mechanism and writes + the address to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_ECRECOVER" |) + ], + make_dict [] + |) in + let message_hash_bytes := + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let message_hash := + M.call (| + M.get_name (| globals, "Hash32" |), + make_list [ + M.get_name (| globals, "message_hash_bytes" |) + ], + make_dict [] + |) in + let v := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let r := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 64 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let s := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.call (| + M.get_name (| globals, "buffer_read" |), + make_list [ + M.get_name (| globals, "data" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 96 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 27 |), + ltac:(M.monadic ( + Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 28 |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| Constant.int 0, M.get_name (| globals, "r" |) |), + ltac:(M.monadic ( + Compare.gt_e (| M.get_name (| globals, "r" |), M.get_name (| globals, "SECP256K1N" |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| Constant.int 0, M.get_name (| globals, "s" |) |), + ltac:(M.monadic ( + Compare.gt_e (| M.get_name (| globals, "s" |), M.get_name (| globals, "SECP256K1N" |) |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in +(* At stmt: unsupported node type: Try *) + let address := + M.get_subscript (| M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), Constant.int 12:Constant.int 32 |) in + let padded_address := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "address" |); + Constant.int 32 + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.get_name (| globals, "padded_address" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/identity.v new file mode 100644 index 0000000..fa96704 --- /dev/null +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/identity.v @@ -0,0 +1,94 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) IDENTITY PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `IDENTITY` precompiled contract. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_IDENTITY : + IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY". +Axiom vm_gas_GAS_IDENTITY_WORD : + IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY_WORD". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition identity : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the message data to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let word_count := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_IDENTITY" |), + BinOp.mult (| + M.get_name (| globals, "GAS_IDENTITY_WORD" |), + M.get_name (| globals, "word_count" |) + |) + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.get_name (| globals, "data" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/mapping.v new file mode 100644 index 0000000..710457d --- /dev/null +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/mapping.v @@ -0,0 +1,56 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Precompiled Contract Addresses +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Mapping of precompiled contracts their implementations. +". + +Require typing. +Axiom typing_Callable : + IsGlobalAlias globals typing.globals "Callable". +Axiom typing_Dict : + IsGlobalAlias globals typing.globals "Dict". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require __init__. +Axiom __init___ECRECOVER_ADDRESS : + IsGlobalAlias globals __init__.globals "ECRECOVER_ADDRESS". +Axiom __init___IDENTITY_ADDRESS : + IsGlobalAlias globals __init__.globals "IDENTITY_ADDRESS". +Axiom __init___RIPEMD160_ADDRESS : + IsGlobalAlias globals __init__.globals "RIPEMD160_ADDRESS". +Axiom __init___SHA256_ADDRESS : + IsGlobalAlias globals __init__.globals "SHA256_ADDRESS". + +Require ecrecover. +Axiom ecrecover_ecrecover : + IsGlobalAlias globals ecrecover.globals "ecrecover". + +Require identity. +Axiom identity_identity : + IsGlobalAlias globals identity.globals "identity". + +Require ripemd160. +Axiom ripemd160_ripemd160 : + IsGlobalAlias globals ripemd160.globals "ripemd160". + +Require sha256. +Axiom sha256_sha256 : + IsGlobalAlias globals sha256.globals "sha256". + +(* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/ripemd160.v new file mode 100644 index 0000000..96f8dcd --- /dev/null +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/ripemd160.v @@ -0,0 +1,122 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) RIPEMD160 PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `RIPEMD160` precompiled contract. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.byte. +Axiom ethereum_utils_byte_left_pad_zero_bytes : + IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_RIPEMD160 : + IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160". +Axiom vm_gas_GAS_RIPEMD160_WORD : + IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160_WORD". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition ripemd160 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the ripemd160 hash to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let word_count := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_RIPEMD160" |), + BinOp.mult (| + M.get_name (| globals, "GAS_RIPEMD160_WORD" |), + M.get_name (| globals, "word_count" |) + |) + |) + ], + make_dict [] + |) in + let hash_bytes := + M.call (| + M.get_field (| M.call (| + M.get_field (| M.get_name (| globals, "hashlib" |), "new" |), + make_list [ + Constant.str "ripemd160"; + M.get_name (| globals, "data" |) + ], + make_dict [] + |), "digest" |), + make_list [], + make_dict [] + |) in + let padded_hash := + M.call (| + M.get_name (| globals, "left_pad_zero_bytes" |), + make_list [ + M.get_name (| globals, "hash_bytes" |); + Constant.int 32 + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.get_name (| globals, "padded_hash" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/sha256.v new file mode 100644 index 0000000..9f6d2bf --- /dev/null +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/sha256.v @@ -0,0 +1,106 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) SHA256 PRECOMPILED CONTRACT +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the `SHA256` precompiled contract. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require vm. +Axiom vm_Evm : + IsGlobalAlias globals vm.globals "Evm". + +Require vm.gas. +Axiom vm_gas_GAS_SHA256 : + IsGlobalAlias globals vm.gas.globals "GAS_SHA256". +Axiom vm_gas_GAS_SHA256_WORD : + IsGlobalAlias globals vm.gas.globals "GAS_SHA256_WORD". +Axiom vm_gas_charge_gas : + IsGlobalAlias globals vm.gas.globals "charge_gas". + +Definition sha256 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Writes the sha256 hash to output. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let data := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let word_count := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_SHA256" |), + BinOp.mult (| + M.get_name (| globals, "GAS_SHA256_WORD" |), + M.get_name (| globals, "word_count" |) + |) + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_field (| M.get_name (| globals, "hashlib" |), "sha256" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), "digest" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/runtime.v b/CoqOfPython/ethereum/tangerine_whistle/vm/runtime.v new file mode 100644 index 0000000..835b46c --- /dev/null +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/runtime.v @@ -0,0 +1,125 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Runtime Operations +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Runtime related operations used while executing EVM code. +". + +Require typing. +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". + +Require ethereum.base_types. +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require instructions. +Axiom instructions_Ops : + IsGlobalAlias globals instructions.globals "Ops". + +Definition get_valid_jump_destinations : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "code" ] |) in + let _ := Constant.str " + Analyze the evm code to obtain the set of valid jump destinations. + + Valid jump destinations are defined as follows: + * The jump destination is less than the length of the code. + * The jump destination should have the `JUMPDEST` opcode (0x5B). + * The jump destination shouldn't be part of the data corresponding to + `PUSH-N` opcodes. + + Note - Jump destinations are 0-indexed. + + Parameters + ---------- + code : + The EVM code which is to be executed. + + Returns + ------- + valid_jump_destinations: `Set[Uint]` + The set of valid jump destinations in the code. + " in + let valid_jump_destinations := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let pc := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + While Compare.lt (| M.get_name (| globals, "pc" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) |) do +(* At stmt: unsupported node type: Try *) + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "current_opcode" |), M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), + make_list [ + M.get_name (| globals, "pc" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + (* At expr: unsupported node type: Compare *), + (* then *) + ltac:(M.monadic ( + let push_data_size := + BinOp.add (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) + |), + Constant.int 1 + |) in + let pc := BinOp.add + M.get_name (| globals, "push_data_size" |) + M.get_name (| globals, "push_data_size" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let pc := BinOp.add + Constant.int 1 + Constant.int 1 in + EndWhile. + let _ := M.return_ (| + M.get_name (| globals, "valid_jump_destinations" |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/stack.v b/CoqOfPython/ethereum/tangerine_whistle/vm/stack.v new file mode 100644 index 0000000..42ea42d --- /dev/null +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/stack.v @@ -0,0 +1,120 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Stack +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementation of the stack operators for the EVM. +". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". + +Require exceptions. +Axiom exceptions_StackOverflowError : + IsGlobalAlias globals exceptions.globals "StackOverflowError". +Axiom exceptions_StackUnderflowError : + IsGlobalAlias globals exceptions.globals "StackUnderflowError". + +Definition pop : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "stack" ] |) in + let _ := Constant.str " + Pops the top item off of `stack`. + + Parameters + ---------- + stack : + EVM stack. + + Returns + ------- + value : `U256` + The top element on the stack. + + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "StackUnderflowError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "pop" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition push : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "stack"; "value" ] |) in + let _ := Constant.str " + Pushes `value` onto `stack`. + + Parameters + ---------- + stack : + EVM stack. + + value : + Item to be pushed onto `stack`. + + " in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), Constant.int 1024 |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| M.get_name (| globals, "StackOverflowError" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "stack" |), "append" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/trace.v b/CoqOfPython/ethereum/trace.v new file mode 100644 index 0000000..be717d7 --- /dev/null +++ b/CoqOfPython/ethereum/trace.v @@ -0,0 +1,135 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +.. _trace: + +EVM Trace +^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Defines the functions required for creating evm traces during execution. +". + +(* At top_level_stmt: unsupported node type: Import *) + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Definition TransactionStart : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition TransactionEnd : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition PrecompileStart : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition PrecompileEnd : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition OpStart : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition OpEnd : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition OpException : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition EvmStop : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition GasAndRefund : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition TraceEvent : Value.t := M.run ltac:(M.monadic ( + M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "TransactionStart" |); M.get_name (| globals, "TransactionEnd" |); M.get_name (| globals, "PrecompileStart" |); M.get_name (| globals, "PrecompileEnd" |); M.get_name (| globals, "OpStart" |); M.get_name (| globals, "OpEnd" |); M.get_name (| globals, "OpException" |); M.get_name (| globals, "EvmStop" |); M.get_name (| globals, "GasAndRefund" |) ] |) +)). + +Definition evm_trace : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "event"; "trace_memory"; "trace_stack"; "trace_return_data" ] |) in + let _ := Constant.str " + Create a trace of the event. + " in + let _ := M.pass (| |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/utils/__init__.v b/CoqOfPython/ethereum/utils/__init__.v new file mode 100644 index 0000000..9fe6ec9 --- /dev/null +++ b/CoqOfPython/ethereum/utils/__init__.v @@ -0,0 +1,8 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Utility functions used in this specification. +". diff --git a/CoqOfPython/ethereum/utils/byte.v b/CoqOfPython/ethereum/utils/byte.v new file mode 100644 index 0000000..cdd16e1 --- /dev/null +++ b/CoqOfPython/ethereum/utils/byte.v @@ -0,0 +1,82 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Utility Functions For Byte Strings +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Byte specific utility functions used in this specification. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". + +Definition left_pad_zero_bytes : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "value"; "size" ] |) in + let _ := Constant.str " + Left pad zeroes to `value` if it's length is less than the given `size`. + + Parameters + ---------- + value : + The byte string that needs to be padded. + size : + The number of bytes that need that need to be padded. + + Returns + ------- + left_padded_value: `ethereum.base_types.Bytes` + left padded byte string of given `size`. + " in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "value" |), "rjust" |), + make_list [ + M.get_name (| globals, "size" |); + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition right_pad_zero_bytes : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "value"; "size" ] |) in + let _ := Constant.str " + Right pad zeroes to `value` if it's length is less than the given `size`. + + Parameters + ---------- + value : + The byte string that needs to be padded. + size : + The number of bytes that need that need to be padded. + + Returns + ------- + right_padded_value: `ethereum.base_types.Bytes` + right padded byte string of given `size`. + " in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "value" |), "ljust" |), + make_list [ + M.get_name (| globals, "size" |); + (* At constant: unsupported node type: Constant *) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/utils/ensure.v b/CoqOfPython/ethereum/utils/ensure.v new file mode 100644 index 0000000..4b8b1d8 --- /dev/null +++ b/CoqOfPython/ethereum/utils/ensure.v @@ -0,0 +1,57 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ensure (Assertion) Utilities +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Functions that simplify checking assertions and raising exceptions. +". + +Require typing. +Axiom typing_Type_ : + IsGlobalAlias globals typing.globals "Type_". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Definition ensure : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "value"; "exception" ] |) in + let _ := Constant.str " + Does nothing if `value` is truthy, otherwise raises the exception returned + by `exception_class`. + + Parameters + ---------- + + value : + Value that should be true. + + exception : + Constructor for the exception to raise. + " in + let _ := + (* if *) + M.if_then_else (| + M.get_name (| globals, "value" |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + (* At expr: unsupported node type: NoneType *) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.raise (| M.get_name (| globals, "exception" |) |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/utils/hexadecimal.v b/CoqOfPython/ethereum/utils/hexadecimal.v new file mode 100644 index 0000000..91ec2bc --- /dev/null +++ b/CoqOfPython/ethereum/utils/hexadecimal.v @@ -0,0 +1,491 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Utility Functions For Hexadecimal Strings +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Hexadecimal strings specific utility functions used in this specification. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U64 : + IsGlobalAlias globals ethereum.base_types.globals "U64". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes8 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes8". +Axiom ethereum_base_types_Bytes20 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes20". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Bytes256 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". + +Definition has_hex_prefix : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Check if a hex string starts with hex prefix (0x). + + Parameters + ---------- + hex_string : + The hexadecimal string to be checked for presence of prefix. + + Returns + ------- + has_prefix : `bool` + Boolean indicating whether the hex string has 0x prefix. + " in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "hex_string" |), "startswith" |), + make_list [ + Constant.str "0x" + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition remove_hex_prefix : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Remove 0x prefix from a hex string if present. This function returns the + passed hex string if it isn't prefixed with 0x. + + Parameters + ---------- + hex_string : + The hexadecimal string whose prefix is to be removed. + + Returns + ------- + modified_hex_string : `str` + The hexadecimal string with the 0x prefix removed if present. + " in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "has_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_subscript (| M.get_name (| globals, "hex_string" |), M.call (| + M.get_name (| globals, "len" |), + make_list [ + Constant.str "0x" + ], + make_dict [] + |):(* At expr: unsupported node type: NoneType *) |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.get_name (| globals, "hex_string" |) + |) in + M.pure Constant.None_)). + +Definition hex_to_bytes : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to bytes. + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to bytes. + + Returns + ------- + byte_stream : `bytes` + Byte stream corresponding to the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition hex_to_bytes8 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to 8 bytes. + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to 8 bytes. + + Returns + ------- + 8_byte_stream : `Bytes8` + 8-byte stream corresponding to the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bytes8" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |), "rjust" |), + make_list [ + Constant.int 16; + Constant.str "0" + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition hex_to_bytes20 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to 20 bytes. + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to 20 bytes. + + Returns + ------- + 20_byte_stream : `Bytes20` + 20-byte stream corresponding to the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bytes20" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |), "rjust" |), + make_list [ + Constant.int 20; + Constant.str "0" + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition hex_to_bytes32 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to 32 bytes. + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to 32 bytes. + + Returns + ------- + 32_byte_stream : `Bytes32` + 32-byte stream corresponding to the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bytes32" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |), "rjust" |), + make_list [ + Constant.int 64; + Constant.str "0" + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition hex_to_bytes256 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to 256 bytes. + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to 256 bytes. + + Returns + ------- + 256_byte_stream : `Bytes256` + 256-byte stream corresponding to the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bytes256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |), "rjust" |), + make_list [ + Constant.int 512; + Constant.str "0" + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition hex_to_hash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to hash32 (32 bytes). + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to hash32. + + Returns + ------- + hash : `Hash32` + 32-byte stream obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Hash32" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "bytes" |), "fromhex" |), + make_list [ + M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition hex_to_uint : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to Uint. + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to Uint. + + Returns + ------- + converted : `Uint` + The unsigned integer obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |); + Constant.int 16 + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition hex_to_u64 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to U64. + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to U256. + + Returns + ------- + converted : `U64` + The U64 integer obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U64" |), + make_list [ + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |); + Constant.int 16 + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition hex_to_u256 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "hex_string" ] |) in + let _ := Constant.str " + Convert hex string to U256. + + Parameters + ---------- + hex_string : + The hexadecimal string to be converted to U256. + + Returns + ------- + converted : `U256` + The U256 integer obtained from the given hexadecimal string. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.call (| + M.get_name (| globals, "remove_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |); + Constant.int 16 + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/utils/numeric.v b/CoqOfPython/ethereum/utils/numeric.v new file mode 100644 index 0000000..6f209d8 --- /dev/null +++ b/CoqOfPython/ethereum/utils/numeric.v @@ -0,0 +1,423 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Utility Functions For Numeric Operations +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Numeric operations specific utility functions used in this specification. +". + +Require typing. +Axiom typing_Sequence : + IsGlobalAlias globals typing.globals "Sequence". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_U32 : + IsGlobalAlias globals ethereum.base_types.globals "U32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Definition get_sign : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "value" ] |) in + let _ := Constant.str " + Determines the sign of a number. + + Parameters + ---------- + value : + The value whose sign is to be determined. + + Returns + ------- + sign : `int` + The sign of the number (-1 or 0 or 1). + The return value is based on math signum function. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| M.get_name (| globals, "value" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + UnOp.sub (| Constant.int 1 |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "value" |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.int 0 + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + Constant.int 1 + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition ceil32 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "value" ] |) in + let _ := Constant.str " + Converts a unsigned integer to the next closest multiple of 32. + + Parameters + ---------- + value : + The value whose ceil32 is to be calculated. + + Returns + ------- + ceil32 : `ethereum.base_types.U256` + The same value if it's a perfect multiple of 32 + else it returns the smallest multiple of 32 + that is greater than `value`. + " in + let ceiling := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 32 + ], + make_dict [] + |) in + let remainder := + BinOp.mod_ (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "ceiling" |) + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| M.get_name (| globals, "remainder" |), M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.sub (| + BinOp.add (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "ceiling" |) + |), + M.get_name (| globals, "remainder" |) + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition is_prime : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "number" ] |) in + let _ := Constant.str " + Checks if `number` is a prime number. + + Parameters + ---------- + number : + The number to check for primality. + + Returns + ------- + is_number_prime : `bool` + Boolean indicating if `number` is prime or not. + " in + let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| M.get_name (| globals, "number" |), Constant.int 1 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + For M.get_name (| globals, "x" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 2; + BinOp.add (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.pow (| + M.get_name (| globals, "number" |), + Value.Float 0.5 + |) + ], + make_dict [] + |), + Constant.int 1 + |) + ], + make_dict [] + |) do + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| BinOp.mod_ (| + M.get_name (| globals, "number" |), + M.get_name (| globals, "x" |) + |), Constant.int 0 |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.return_ (| + Constant.bool true + |) in + M.pure Constant.None_)). + +Definition le_bytes_to_uint32_sequence : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "data" ] |) in + let _ := Constant.str " + Convert little endian byte stream `data` to a little endian U32 + sequence i.e., the first U32 number of the sequence is the least + significant U32 number. + + Parameters + ---------- + data : + The byte stream (little endian) which is to be converted to a U32 + stream. + + Returns + ------- + uint32_sequence : `Tuple[U32, ...]` + Sequence of U32 numbers obtained from the little endian byte + stream. + " in + let sequence := + make_list [] in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |); + Constant.int 4 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "sequence" |), "append" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "U32" |), "from_le_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "data" |), M.get_name (| globals, "i" |):BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 4 + |) |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "tuple" |), + make_list [ + M.get_name (| globals, "sequence" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition le_uint32_sequence_to_bytes : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "sequence" ] |) in + let _ := Constant.str " + Obtain little endian byte stream from a little endian U32 sequence + i.e., the first U32 number of the sequence is the least significant + U32 number. + + Note - In this conversion, the most significant byte (byte at the end of + the little endian stream) may have leading zeroes. This function doesn't + take care of removing these leading zeroes as shown in below example. + + >>> le_uint32_sequence_to_bytes([U32(8)]) + b'\x08\x00\x00\x00' + + + Parameters + ---------- + sequence : + The U32 stream (little endian) which is to be converted to a + little endian byte stream. + + Returns + ------- + result : `bytes` + The byte stream obtained from the little endian U32 stream. + " in + let result_bytes := + (* At constant: unsupported node type: Constant *) in + For M.get_name (| globals, "item" |) in M.get_name (| globals, "sequence" |) do + let result_bytes := BinOp.add + M.call (| + M.get_field (| M.get_name (| globals, "item" |), "to_le_bytes4" |), + make_list [], + make_dict [] + |) + M.call (| + M.get_field (| M.get_name (| globals, "item" |), "to_le_bytes4" |), + make_list [], + make_dict [] + |) in + EndFor. + let _ := M.return_ (| + M.get_name (| globals, "result_bytes" |) + |) in + M.pure Constant.None_)). + +Definition le_uint32_sequence_to_uint : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "sequence" ] |) in + let _ := Constant.str " + Obtain Uint from a U32 sequence assuming that this sequence is little + endian i.e., the first U32 number of the sequence is the least + significant U32 number. + + Parameters + ---------- + sequence : + The U32 stream (little endian) which is to be converted to a Uint. + + Returns + ------- + value : `Uint` + The Uint number obtained from the conversion of the little endian + U32 stream. + " in + let sequence_as_bytes := + M.call (| + M.get_name (| globals, "le_uint32_sequence_to_bytes" |), + make_list [ + M.get_name (| globals, "sequence" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_le_bytes" |), + make_list [ + M.get_name (| globals, "sequence_as_bytes" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition taylor_exponential : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "factor"; "numerator"; "denominator" ] |) in + let _ := Constant.str " + Approximates factor * e ** (numerator / denominator) using + Taylor expansion. + + Parameters + ---------- + factor : + The factor. + numerator : + The numerator of the exponential. + denominator : + The denominator of the exponential. + + Returns + ------- + output : `ethereum.base_types.Uint` + The approximation of factor * e ** (numerator / denominator). + + " in + let i := + Constant.int 1 in + let output := + Constant.int 0 in + let numerator_accumulated := + BinOp.mult (| + M.get_name (| globals, "factor" |), + M.get_name (| globals, "denominator" |) + |) in + While Compare.gt (| M.get_name (| globals, "numerator_accumulated" |), Constant.int 0 |) do + let output := BinOp.add + M.get_name (| globals, "numerator_accumulated" |) + M.get_name (| globals, "numerator_accumulated" |) in + let numerator_accumulated := + BinOp.floor_div (| + BinOp.mult (| + M.get_name (| globals, "numerator_accumulated" |), + M.get_name (| globals, "numerator" |) + |), + BinOp.mult (| + M.get_name (| globals, "denominator" |), + M.get_name (| globals, "i" |) + |) + |) in + let i := BinOp.add + Constant.int 1 + Constant.int 1 in + EndWhile. + let _ := M.return_ (| + BinOp.floor_div (| + M.get_name (| globals, "output" |), + M.get_name (| globals, "denominator" |) + |) + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/utils/safe_arithmetic.v b/CoqOfPython/ethereum/utils/safe_arithmetic.v new file mode 100644 index 0000000..f9d67fc --- /dev/null +++ b/CoqOfPython/ethereum/utils/safe_arithmetic.v @@ -0,0 +1,96 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Safe Arithmetic for U256 Integer Type +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Safe arithmetic utility functions for U256 integer type. +". + +Require typing. +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Type_ : + IsGlobalAlias globals typing.globals "Type_". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Definition u256_safe_add : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ ] |) in + let _ := Constant.str " + Adds together the given sequence of numbers. If the total sum of the + numbers exceeds `U256.MAX_VALUE` then an exception is raised. + If `exception_type` = None then the exception raised defaults to the one + raised by `U256` when `U256.value > U256.MAX_VALUE` + else `exception_type` is raised. + + Parameters + ---------- + numbers : + The sequence of numbers that need to be added together. + + exception_type: + The exception that needs to be raised if the sum of the `numbers` + exceeds `U256.MAX_VALUE`. + + Returns + ------- + result : `ethereum.base_types.U256` + The sum of the given sequence of numbers if the total is less than + `U256.MAX_VALUE` else an exception is raised. + If `exception_type` = None then the exception raised defaults to the + one raised by `U256` when `U256.value > U256.MAX_VALUE` + else `exception_type` is raised. + " in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_)). + +Definition u256_safe_multiply : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ ] |) in + let _ := Constant.str " + Multiplies together the given sequence of numbers. If the net product of + the numbers exceeds `U256.MAX_VALUE` then an exception is raised. + If `exception_type` = None then the exception raised defaults to the one + raised by `U256` when `U256.value > U256.MAX_VALUE` else + `exception_type` is raised. + + Parameters + ---------- + numbers : + The sequence of numbers that need to be multiplies together. + + exception_type: + The exception that needs to be raised if the sum of the `numbers` + exceeds `U256.MAX_VALUE`. + + Returns + ------- + result : `ethereum.base_types.U256` + The multiplication product of the given sequence of numbers if the + net product is less than `U256.MAX_VALUE` else an exception is raised. + If `exception_type` = None then the exception raised defaults to the + one raised by `U256` when `U256.value > U256.MAX_VALUE` + else `exception_type` is raised. + " in + let result := + M.get_subscript (| M.get_name (| globals, "numbers" |), Constant.int 0 |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_)). diff --git a/convert_all.py b/convert_all.py index 71b0041..e2f2122 100644 --- a/convert_all.py +++ b/convert_all.py @@ -1,4 +1,6 @@ import os +import subprocess +import sys folder_to_convert = "../execution-specs/src/ethereum" @@ -11,4 +13,14 @@ # print("Converting file: " + full_path) short_path = full_path[(len(folder_to_convert) + 1):] print("Converting file: " + short_path) - os.system("python main.py " + short_path) + + try: + command = "python main.py " + short_path + print(command) + subprocess.run(command, shell=True, check=True) + except subprocess.CalledProcessError as e: + print(f"Error occurred: {e}") + # sys.exit(1) + except KeyboardInterrupt: + print("Ctrl-C pressed, interrupting the script.") + sys.exit(1) diff --git a/main.py b/main.py index 7cb21f3..53334bd 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,5 @@ import ast +import os import sys @@ -600,6 +601,11 @@ def generate_arg(node): {generate_mod(parsed_tree)} """ +# Ensure that the directory exists +output_directory = os.path.dirname(output_file_name) +if not os.path.exists(output_directory): + os.makedirs(output_directory) + # Output the generated Coq code with open(output_file_name, "w") as output_file: output_file.write(coq_code) From 3b12d6e9424009a42dbc866bed6b6614d0e789ce Mon Sep 17 00:00:00 2001 From: Guillaume Claret Date: Thu, 9 May 2024 23:38:58 +0200 Subject: [PATCH 2/6] Translating all the files without the script failing --- .gitignore | 1 + CoqOfPython/CoqMakefile | 981 ------- CoqOfPython/ethereum/arrow_glacier/bloom.v | 6 +- CoqOfPython/ethereum/arrow_glacier/fork.v | 2385 ++++++++++++++++ .../ethereum/arrow_glacier/fork_types.v | 1 - CoqOfPython/ethereum/arrow_glacier/state.v | 347 +-- .../ethereum/arrow_glacier/transactions.v | 135 +- CoqOfPython/ethereum/arrow_glacier/trie.v | 535 +--- .../ethereum/arrow_glacier/utils/address.v | 11 +- .../arrow_glacier/utils/hexadecimal.v | 3 - .../ethereum/arrow_glacier/utils/message.v | 96 +- .../ethereum/arrow_glacier/vm/__init__.v | 70 - CoqOfPython/ethereum/arrow_glacier/vm/gas.v | 811 ++++++ .../vm/instructions/arithmetic.v | 127 +- .../arrow_glacier/vm/instructions/bitwise.v | 86 - .../arrow_glacier/vm/instructions/block.v | 18 - .../vm/instructions/comparison.v | 30 +- .../vm/instructions/control_flow.v | 31 - .../vm/instructions/environment.v | 134 +- .../arrow_glacier/vm/instructions/keccak.v | 2 +- .../arrow_glacier/vm/instructions/log.v | 2 +- .../arrow_glacier/vm/instructions/memory.v | 6 +- .../arrow_glacier/vm/instructions/stack.v | 34 +- .../arrow_glacier/vm/instructions/storage.v | 195 +- .../arrow_glacier/vm/instructions/system.v | 1635 +++++++++++ .../ethereum/arrow_glacier/vm/interpreter.v | 227 -- .../ethereum/arrow_glacier/vm/memory.v | 53 +- .../vm/precompiled_contracts/alt_bn128.v | 168 +- .../vm/precompiled_contracts/blake2f.v | 28 +- .../vm/precompiled_contracts/ecrecover.v | 50 +- .../vm/precompiled_contracts/modexp.v | 116 - .../ethereum/arrow_glacier/vm/runtime.v | 52 +- CoqOfPython/ethereum/arrow_glacier/vm/stack.v | 32 - CoqOfPython/ethereum/base_types.v | 1778 ------------ CoqOfPython/ethereum/berlin/bloom.v | 6 +- CoqOfPython/ethereum/berlin/fork.v | 2193 +++++++++++++++ CoqOfPython/ethereum/berlin/fork_types.v | 1 - CoqOfPython/ethereum/berlin/state.v | 347 +-- CoqOfPython/ethereum/berlin/transactions.v | 83 +- CoqOfPython/ethereum/berlin/trie.v | 535 +--- CoqOfPython/ethereum/berlin/utils/address.v | 11 +- .../ethereum/berlin/utils/hexadecimal.v | 3 - CoqOfPython/ethereum/berlin/utils/message.v | 96 +- CoqOfPython/ethereum/berlin/vm/__init__.v | 70 - CoqOfPython/ethereum/berlin/vm/gas.v | 821 ++++++ .../berlin/vm/instructions/arithmetic.v | 127 +- .../ethereum/berlin/vm/instructions/bitwise.v | 86 - .../ethereum/berlin/vm/instructions/block.v | 18 - .../berlin/vm/instructions/comparison.v | 30 +- .../berlin/vm/instructions/control_flow.v | 31 - .../berlin/vm/instructions/environment.v | 134 +- .../ethereum/berlin/vm/instructions/keccak.v | 2 +- .../ethereum/berlin/vm/instructions/log.v | 2 +- .../ethereum/berlin/vm/instructions/memory.v | 6 +- .../ethereum/berlin/vm/instructions/stack.v | 34 +- .../ethereum/berlin/vm/instructions/storage.v | 195 +- .../ethereum/berlin/vm/instructions/system.v | 1658 ++++++++++++ CoqOfPython/ethereum/berlin/vm/interpreter.v | 227 -- CoqOfPython/ethereum/berlin/vm/memory.v | 53 +- .../vm/precompiled_contracts/alt_bn128.v | 168 +- .../berlin/vm/precompiled_contracts/blake2f.v | 28 +- .../vm/precompiled_contracts/ecrecover.v | 50 +- .../berlin/vm/precompiled_contracts/modexp.v | 116 - CoqOfPython/ethereum/berlin/vm/runtime.v | 52 +- CoqOfPython/ethereum/berlin/vm/stack.v | 32 - CoqOfPython/ethereum/byzantium/bloom.v | 6 +- CoqOfPython/ethereum/byzantium/fork.v | 2160 +++++++++++++++ CoqOfPython/ethereum/byzantium/fork_types.v | 1 - CoqOfPython/ethereum/byzantium/state.v | 287 +- CoqOfPython/ethereum/byzantium/trie.v | 535 +--- .../ethereum/byzantium/utils/address.v | 6 +- .../ethereum/byzantium/utils/hexadecimal.v | 3 - .../ethereum/byzantium/utils/message.v | 96 +- CoqOfPython/ethereum/byzantium/vm/__init__.v | 70 - CoqOfPython/ethereum/byzantium/vm/gas.v | 811 ++++++ .../byzantium/vm/instructions/arithmetic.v | 127 +- .../byzantium/vm/instructions/bitwise.v | 16 - .../byzantium/vm/instructions/block.v | 18 - .../byzantium/vm/instructions/comparison.v | 30 +- .../byzantium/vm/instructions/control_flow.v | 31 - .../byzantium/vm/instructions/environment.v | 48 +- .../byzantium/vm/instructions/keccak.v | 2 +- .../ethereum/byzantium/vm/instructions/log.v | 2 +- .../byzantium/vm/instructions/memory.v | 6 +- .../byzantium/vm/instructions/stack.v | 34 +- .../byzantium/vm/instructions/storage.v | 33 - .../byzantium/vm/instructions/system.v | 1432 ++++++++++ .../ethereum/byzantium/vm/interpreter.v | 227 -- CoqOfPython/ethereum/byzantium/vm/memory.v | 53 +- .../vm/precompiled_contracts/alt_bn128.v | 168 +- .../vm/precompiled_contracts/ecrecover.v | 50 +- .../vm/precompiled_contracts/modexp.v | 116 - CoqOfPython/ethereum/byzantium/vm/runtime.v | 52 +- CoqOfPython/ethereum/byzantium/vm/stack.v | 32 - CoqOfPython/ethereum/cancun/bloom.v | 6 +- CoqOfPython/ethereum/cancun/fork.v | 1058 +------- CoqOfPython/ethereum/cancun/fork_types.v | 1 - CoqOfPython/ethereum/cancun/state.v | 423 +-- CoqOfPython/ethereum/cancun/transactions.v | 183 +- CoqOfPython/ethereum/cancun/trie.v | 535 +--- CoqOfPython/ethereum/cancun/utils/address.v | 11 +- .../ethereum/cancun/utils/hexadecimal.v | 3 - CoqOfPython/ethereum/cancun/utils/message.v | 96 +- CoqOfPython/ethereum/cancun/vm/__init__.v | 70 - CoqOfPython/ethereum/cancun/vm/gas.v | 1058 ++++++++ .../cancun/vm/instructions/arithmetic.v | 127 +- .../ethereum/cancun/vm/instructions/bitwise.v | 86 - .../ethereum/cancun/vm/instructions/block.v | 18 - .../cancun/vm/instructions/comparison.v | 30 +- .../cancun/vm/instructions/control_flow.v | 31 - .../cancun/vm/instructions/environment.v | 152 +- .../ethereum/cancun/vm/instructions/keccak.v | 2 +- .../ethereum/cancun/vm/instructions/log.v | 2 +- .../ethereum/cancun/vm/instructions/memory.v | 8 +- .../ethereum/cancun/vm/instructions/stack.v | 50 +- .../ethereum/cancun/vm/instructions/storage.v | 195 +- .../ethereum/cancun/vm/instructions/system.v | 1667 ++++++++++++ CoqOfPython/ethereum/cancun/vm/interpreter.v | 228 -- CoqOfPython/ethereum/cancun/vm/memory.v | 53 +- .../vm/precompiled_contracts/alt_bn128.v | 168 +- .../cancun/vm/precompiled_contracts/blake2f.v | 28 +- .../vm/precompiled_contracts/ecrecover.v | 50 +- .../cancun/vm/precompiled_contracts/modexp.v | 116 - .../precompiled_contracts/point_evaluation.v | 46 +- CoqOfPython/ethereum/cancun/vm/runtime.v | 52 +- CoqOfPython/ethereum/cancun/vm/stack.v | 32 - CoqOfPython/ethereum/constantinople/bloom.v | 6 +- CoqOfPython/ethereum/constantinople/fork.v | 2160 +++++++++++++++ .../ethereum/constantinople/fork_types.v | 1 - CoqOfPython/ethereum/constantinople/state.v | 287 +- CoqOfPython/ethereum/constantinople/trie.v | 535 +--- .../ethereum/constantinople/utils/address.v | 11 +- .../constantinople/utils/hexadecimal.v | 3 - .../ethereum/constantinople/utils/message.v | 96 +- .../ethereum/constantinople/vm/__init__.v | 70 - CoqOfPython/ethereum/constantinople/vm/gas.v | 821 ++++++ .../vm/instructions/arithmetic.v | 127 +- .../constantinople/vm/instructions/bitwise.v | 86 - .../constantinople/vm/instructions/block.v | 18 - .../vm/instructions/comparison.v | 30 +- .../vm/instructions/control_flow.v | 31 - .../vm/instructions/environment.v | 64 +- .../constantinople/vm/instructions/keccak.v | 2 +- .../constantinople/vm/instructions/log.v | 2 +- .../constantinople/vm/instructions/memory.v | 6 +- .../constantinople/vm/instructions/stack.v | 34 +- .../constantinople/vm/instructions/storage.v | 33 - .../constantinople/vm/instructions/system.v | 1598 +++++++++++ .../ethereum/constantinople/vm/interpreter.v | 227 -- .../ethereum/constantinople/vm/memory.v | 53 +- .../vm/precompiled_contracts/alt_bn128.v | 168 +- .../vm/precompiled_contracts/ecrecover.v | 50 +- .../vm/precompiled_contracts/modexp.v | 116 - .../ethereum/constantinople/vm/runtime.v | 52 +- .../ethereum/constantinople/vm/stack.v | 32 - CoqOfPython/ethereum/crypto/alt_bn128.v | 180 +- CoqOfPython/ethereum/crypto/blake2.v | 43 +- CoqOfPython/ethereum/crypto/elliptic_curve.v | 205 +- CoqOfPython/ethereum/crypto/finite_field.v | 479 +--- CoqOfPython/ethereum/crypto/hash.v | 2 - CoqOfPython/ethereum/dao_fork/bloom.v | 6 +- CoqOfPython/ethereum/dao_fork/dao.v | 8 +- CoqOfPython/ethereum/dao_fork/fork.v | 515 ++-- CoqOfPython/ethereum/dao_fork/fork_types.v | 1 - CoqOfPython/ethereum/dao_fork/state.v | 187 +- CoqOfPython/ethereum/dao_fork/trie.v | 535 +--- CoqOfPython/ethereum/dao_fork/utils/address.v | 6 +- .../ethereum/dao_fork/utils/hexadecimal.v | 3 - CoqOfPython/ethereum/dao_fork/utils/message.v | 96 +- CoqOfPython/ethereum/dao_fork/vm/gas.v | 769 ++++++ .../dao_fork/vm/instructions/arithmetic.v | 127 +- .../dao_fork/vm/instructions/bitwise.v | 16 - .../ethereum/dao_fork/vm/instructions/block.v | 18 - .../dao_fork/vm/instructions/comparison.v | 30 +- .../dao_fork/vm/instructions/control_flow.v | 31 - .../dao_fork/vm/instructions/environment.v | 6 +- .../dao_fork/vm/instructions/keccak.v | 2 +- .../ethereum/dao_fork/vm/instructions/log.v | 2 +- .../dao_fork/vm/instructions/memory.v | 6 +- .../ethereum/dao_fork/vm/instructions/stack.v | 34 +- .../dao_fork/vm/instructions/storage.v | 33 - .../dao_fork/vm/instructions/system.v | 266 +- .../ethereum/dao_fork/vm/interpreter.v | 182 -- CoqOfPython/ethereum/dao_fork/vm/memory.v | 53 +- .../vm/precompiled_contracts/ecrecover.v | 50 +- CoqOfPython/ethereum/dao_fork/vm/runtime.v | 52 +- CoqOfPython/ethereum/dao_fork/vm/stack.v | 32 - CoqOfPython/ethereum/ethash.v | 59 +- CoqOfPython/ethereum/fork_criteria.v | 55 +- CoqOfPython/ethereum/frontier/bloom.v | 6 +- CoqOfPython/ethereum/frontier/fork.v | 489 ++-- CoqOfPython/ethereum/frontier/fork_types.v | 1 - CoqOfPython/ethereum/frontier/state.v | 187 +- CoqOfPython/ethereum/frontier/trie.v | 538 +--- CoqOfPython/ethereum/frontier/utils/address.v | 6 +- .../ethereum/frontier/utils/hexadecimal.v | 3 - CoqOfPython/ethereum/frontier/utils/message.v | 96 +- CoqOfPython/ethereum/frontier/vm/gas.v | 769 ++++++ .../frontier/vm/instructions/arithmetic.v | 127 +- .../frontier/vm/instructions/bitwise.v | 16 - .../ethereum/frontier/vm/instructions/block.v | 18 - .../frontier/vm/instructions/comparison.v | 30 +- .../frontier/vm/instructions/control_flow.v | 31 - .../frontier/vm/instructions/environment.v | 6 +- .../frontier/vm/instructions/keccak.v | 2 +- .../ethereum/frontier/vm/instructions/log.v | 2 +- .../frontier/vm/instructions/memory.v | 6 +- .../ethereum/frontier/vm/instructions/stack.v | 34 +- .../frontier/vm/instructions/storage.v | 33 - .../frontier/vm/instructions/system.v | 264 +- .../ethereum/frontier/vm/interpreter.v | 184 -- CoqOfPython/ethereum/frontier/vm/memory.v | 53 +- .../vm/precompiled_contracts/ecrecover.v | 50 +- CoqOfPython/ethereum/frontier/vm/runtime.v | 52 +- CoqOfPython/ethereum/frontier/vm/stack.v | 32 - CoqOfPython/ethereum/genesis.v | 162 +- CoqOfPython/ethereum/gray_glacier/bloom.v | 6 +- CoqOfPython/ethereum/gray_glacier/fork.v | 2385 ++++++++++++++++ .../ethereum/gray_glacier/fork_types.v | 1 - CoqOfPython/ethereum/gray_glacier/state.v | 347 +-- .../ethereum/gray_glacier/transactions.v | 135 +- CoqOfPython/ethereum/gray_glacier/trie.v | 535 +--- .../ethereum/gray_glacier/utils/address.v | 11 +- .../ethereum/gray_glacier/utils/hexadecimal.v | 3 - .../ethereum/gray_glacier/utils/message.v | 96 +- .../ethereum/gray_glacier/vm/__init__.v | 70 - CoqOfPython/ethereum/gray_glacier/vm/gas.v | 811 ++++++ .../gray_glacier/vm/instructions/arithmetic.v | 127 +- .../gray_glacier/vm/instructions/bitwise.v | 86 - .../gray_glacier/vm/instructions/block.v | 18 - .../gray_glacier/vm/instructions/comparison.v | 30 +- .../vm/instructions/control_flow.v | 31 - .../vm/instructions/environment.v | 134 +- .../gray_glacier/vm/instructions/keccak.v | 2 +- .../gray_glacier/vm/instructions/log.v | 2 +- .../gray_glacier/vm/instructions/memory.v | 6 +- .../gray_glacier/vm/instructions/stack.v | 34 +- .../gray_glacier/vm/instructions/storage.v | 195 +- .../gray_glacier/vm/instructions/system.v | 1635 +++++++++++ .../ethereum/gray_glacier/vm/interpreter.v | 227 -- CoqOfPython/ethereum/gray_glacier/vm/memory.v | 53 +- .../vm/precompiled_contracts/alt_bn128.v | 168 +- .../vm/precompiled_contracts/blake2f.v | 28 +- .../vm/precompiled_contracts/ecrecover.v | 50 +- .../vm/precompiled_contracts/modexp.v | 116 - .../ethereum/gray_glacier/vm/runtime.v | 52 +- CoqOfPython/ethereum/gray_glacier/vm/stack.v | 32 - CoqOfPython/ethereum/homestead/bloom.v | 6 +- CoqOfPython/ethereum/homestead/fork.v | 491 ++-- CoqOfPython/ethereum/homestead/fork_types.v | 1 - CoqOfPython/ethereum/homestead/state.v | 187 +- CoqOfPython/ethereum/homestead/trie.v | 535 +--- .../ethereum/homestead/utils/address.v | 6 +- .../ethereum/homestead/utils/hexadecimal.v | 3 - .../ethereum/homestead/utils/message.v | 96 +- CoqOfPython/ethereum/homestead/vm/gas.v | 769 ++++++ .../homestead/vm/instructions/arithmetic.v | 127 +- .../homestead/vm/instructions/bitwise.v | 16 - .../homestead/vm/instructions/block.v | 18 - .../homestead/vm/instructions/comparison.v | 30 +- .../homestead/vm/instructions/control_flow.v | 31 - .../homestead/vm/instructions/environment.v | 6 +- .../homestead/vm/instructions/keccak.v | 2 +- .../ethereum/homestead/vm/instructions/log.v | 2 +- .../homestead/vm/instructions/memory.v | 6 +- .../homestead/vm/instructions/stack.v | 34 +- .../homestead/vm/instructions/storage.v | 33 - .../homestead/vm/instructions/system.v | 266 +- .../ethereum/homestead/vm/interpreter.v | 182 -- CoqOfPython/ethereum/homestead/vm/memory.v | 53 +- .../vm/precompiled_contracts/ecrecover.v | 50 +- CoqOfPython/ethereum/homestead/vm/runtime.v | 52 +- CoqOfPython/ethereum/homestead/vm/stack.v | 32 - CoqOfPython/ethereum/istanbul/bloom.v | 6 +- CoqOfPython/ethereum/istanbul/fork.v | 2160 +++++++++++++++ CoqOfPython/ethereum/istanbul/fork_types.v | 1 - CoqOfPython/ethereum/istanbul/state.v | 347 +-- CoqOfPython/ethereum/istanbul/trie.v | 535 +--- CoqOfPython/ethereum/istanbul/utils/address.v | 11 +- .../ethereum/istanbul/utils/hexadecimal.v | 3 - CoqOfPython/ethereum/istanbul/utils/message.v | 96 +- CoqOfPython/ethereum/istanbul/vm/__init__.v | 70 - CoqOfPython/ethereum/istanbul/vm/gas.v | 841 ++++++ .../istanbul/vm/instructions/arithmetic.v | 127 +- .../istanbul/vm/instructions/bitwise.v | 86 - .../ethereum/istanbul/vm/instructions/block.v | 18 - .../istanbul/vm/instructions/comparison.v | 30 +- .../istanbul/vm/instructions/control_flow.v | 31 - .../istanbul/vm/instructions/environment.v | 64 +- .../istanbul/vm/instructions/keccak.v | 2 +- .../ethereum/istanbul/vm/instructions/log.v | 2 +- .../istanbul/vm/instructions/memory.v | 6 +- .../ethereum/istanbul/vm/instructions/stack.v | 34 +- .../istanbul/vm/instructions/storage.v | 150 +- .../istanbul/vm/instructions/system.v | 1598 +++++++++++ .../ethereum/istanbul/vm/interpreter.v | 227 -- CoqOfPython/ethereum/istanbul/vm/memory.v | 53 +- .../vm/precompiled_contracts/alt_bn128.v | 168 +- .../vm/precompiled_contracts/blake2f.v | 28 +- .../vm/precompiled_contracts/ecrecover.v | 50 +- .../vm/precompiled_contracts/modexp.v | 116 - CoqOfPython/ethereum/istanbul/vm/runtime.v | 52 +- CoqOfPython/ethereum/istanbul/vm/stack.v | 32 - CoqOfPython/ethereum/london/bloom.v | 6 +- CoqOfPython/ethereum/london/fork.v | 2402 +++++++++++++++++ CoqOfPython/ethereum/london/fork_types.v | 1 - CoqOfPython/ethereum/london/state.v | 347 +-- CoqOfPython/ethereum/london/transactions.v | 135 +- CoqOfPython/ethereum/london/trie.v | 535 +--- CoqOfPython/ethereum/london/utils/address.v | 11 +- .../ethereum/london/utils/hexadecimal.v | 3 - CoqOfPython/ethereum/london/utils/message.v | 96 +- CoqOfPython/ethereum/london/vm/__init__.v | 70 - CoqOfPython/ethereum/london/vm/gas.v | 811 ++++++ .../london/vm/instructions/arithmetic.v | 127 +- .../ethereum/london/vm/instructions/bitwise.v | 86 - .../ethereum/london/vm/instructions/block.v | 18 - .../london/vm/instructions/comparison.v | 30 +- .../london/vm/instructions/control_flow.v | 31 - .../london/vm/instructions/environment.v | 134 +- .../ethereum/london/vm/instructions/keccak.v | 2 +- .../ethereum/london/vm/instructions/log.v | 2 +- .../ethereum/london/vm/instructions/memory.v | 6 +- .../ethereum/london/vm/instructions/stack.v | 34 +- .../ethereum/london/vm/instructions/storage.v | 195 +- .../ethereum/london/vm/instructions/system.v | 1635 +++++++++++ CoqOfPython/ethereum/london/vm/interpreter.v | 227 -- CoqOfPython/ethereum/london/vm/memory.v | 53 +- .../vm/precompiled_contracts/alt_bn128.v | 168 +- .../london/vm/precompiled_contracts/blake2f.v | 28 +- .../vm/precompiled_contracts/ecrecover.v | 50 +- .../london/vm/precompiled_contracts/modexp.v | 116 - CoqOfPython/ethereum/london/vm/runtime.v | 52 +- CoqOfPython/ethereum/london/vm/stack.v | 32 - CoqOfPython/ethereum/muir_glacier/bloom.v | 6 +- CoqOfPython/ethereum/muir_glacier/fork.v | 2160 +++++++++++++++ .../ethereum/muir_glacier/fork_types.v | 1 - CoqOfPython/ethereum/muir_glacier/state.v | 347 +-- CoqOfPython/ethereum/muir_glacier/trie.v | 535 +--- .../ethereum/muir_glacier/utils/address.v | 11 +- .../ethereum/muir_glacier/utils/hexadecimal.v | 3 - .../ethereum/muir_glacier/utils/message.v | 96 +- .../ethereum/muir_glacier/vm/__init__.v | 70 - CoqOfPython/ethereum/muir_glacier/vm/gas.v | 841 ++++++ .../muir_glacier/vm/instructions/arithmetic.v | 127 +- .../muir_glacier/vm/instructions/bitwise.v | 86 - .../muir_glacier/vm/instructions/block.v | 18 - .../muir_glacier/vm/instructions/comparison.v | 30 +- .../vm/instructions/control_flow.v | 31 - .../vm/instructions/environment.v | 64 +- .../muir_glacier/vm/instructions/keccak.v | 2 +- .../muir_glacier/vm/instructions/log.v | 2 +- .../muir_glacier/vm/instructions/memory.v | 6 +- .../muir_glacier/vm/instructions/stack.v | 34 +- .../muir_glacier/vm/instructions/storage.v | 150 +- .../muir_glacier/vm/instructions/system.v | 1598 +++++++++++ .../ethereum/muir_glacier/vm/interpreter.v | 227 -- CoqOfPython/ethereum/muir_glacier/vm/memory.v | 53 +- .../vm/precompiled_contracts/alt_bn128.v | 168 +- .../vm/precompiled_contracts/blake2f.v | 28 +- .../vm/precompiled_contracts/ecrecover.v | 50 +- .../vm/precompiled_contracts/modexp.v | 116 - .../ethereum/muir_glacier/vm/runtime.v | 52 +- CoqOfPython/ethereum/muir_glacier/vm/stack.v | 32 - CoqOfPython/ethereum/paris/bloom.v | 6 +- CoqOfPython/ethereum/paris/fork.v | 781 +----- CoqOfPython/ethereum/paris/fork_types.v | 1 - CoqOfPython/ethereum/paris/state.v | 347 +-- CoqOfPython/ethereum/paris/transactions.v | 135 +- CoqOfPython/ethereum/paris/trie.v | 535 +--- CoqOfPython/ethereum/paris/utils/address.v | 11 +- .../ethereum/paris/utils/hexadecimal.v | 3 - CoqOfPython/ethereum/paris/utils/message.v | 96 +- CoqOfPython/ethereum/paris/vm/__init__.v | 70 - CoqOfPython/ethereum/paris/vm/gas.v | 811 ++++++ .../paris/vm/instructions/arithmetic.v | 127 +- .../ethereum/paris/vm/instructions/bitwise.v | 86 - .../ethereum/paris/vm/instructions/block.v | 18 - .../paris/vm/instructions/comparison.v | 30 +- .../paris/vm/instructions/control_flow.v | 31 - .../paris/vm/instructions/environment.v | 134 +- .../ethereum/paris/vm/instructions/keccak.v | 2 +- .../ethereum/paris/vm/instructions/log.v | 2 +- .../ethereum/paris/vm/instructions/memory.v | 6 +- .../ethereum/paris/vm/instructions/stack.v | 34 +- .../ethereum/paris/vm/instructions/storage.v | 195 +- .../ethereum/paris/vm/instructions/system.v | 1635 +++++++++++ CoqOfPython/ethereum/paris/vm/interpreter.v | 227 -- CoqOfPython/ethereum/paris/vm/memory.v | 53 +- .../vm/precompiled_contracts/alt_bn128.v | 168 +- .../paris/vm/precompiled_contracts/blake2f.v | 28 +- .../vm/precompiled_contracts/ecrecover.v | 50 +- .../paris/vm/precompiled_contracts/modexp.v | 116 - CoqOfPython/ethereum/paris/vm/runtime.v | 52 +- CoqOfPython/ethereum/paris/vm/stack.v | 32 - CoqOfPython/ethereum/rlp.v | 1570 ++--------- CoqOfPython/ethereum/shanghai/bloom.v | 6 +- CoqOfPython/ethereum/shanghai/fork.v | 877 +----- CoqOfPython/ethereum/shanghai/fork_types.v | 1 - CoqOfPython/ethereum/shanghai/state.v | 347 +-- CoqOfPython/ethereum/shanghai/transactions.v | 135 +- CoqOfPython/ethereum/shanghai/trie.v | 535 +--- CoqOfPython/ethereum/shanghai/utils/address.v | 11 +- .../ethereum/shanghai/utils/hexadecimal.v | 3 - CoqOfPython/ethereum/shanghai/utils/message.v | 96 +- CoqOfPython/ethereum/shanghai/vm/__init__.v | 70 - CoqOfPython/ethereum/shanghai/vm/gas.v | 849 ++++++ .../shanghai/vm/instructions/arithmetic.v | 127 +- .../shanghai/vm/instructions/bitwise.v | 86 - .../ethereum/shanghai/vm/instructions/block.v | 18 - .../shanghai/vm/instructions/comparison.v | 30 +- .../shanghai/vm/instructions/control_flow.v | 31 - .../shanghai/vm/instructions/environment.v | 134 +- .../shanghai/vm/instructions/keccak.v | 2 +- .../ethereum/shanghai/vm/instructions/log.v | 2 +- .../shanghai/vm/instructions/memory.v | 6 +- .../ethereum/shanghai/vm/instructions/stack.v | 50 +- .../shanghai/vm/instructions/storage.v | 195 +- .../shanghai/vm/instructions/system.v | 1695 ++++++++++++ .../ethereum/shanghai/vm/interpreter.v | 227 -- CoqOfPython/ethereum/shanghai/vm/memory.v | 53 +- .../vm/precompiled_contracts/alt_bn128.v | 168 +- .../vm/precompiled_contracts/blake2f.v | 28 +- .../vm/precompiled_contracts/ecrecover.v | 50 +- .../vm/precompiled_contracts/modexp.v | 116 - CoqOfPython/ethereum/shanghai/vm/runtime.v | 52 +- CoqOfPython/ethereum/shanghai/vm/stack.v | 32 - CoqOfPython/ethereum/spurious_dragon/bloom.v | 6 +- CoqOfPython/ethereum/spurious_dragon/fork.v | 600 ++-- .../ethereum/spurious_dragon/fork_types.v | 1 - CoqOfPython/ethereum/spurious_dragon/state.v | 287 +- CoqOfPython/ethereum/spurious_dragon/trie.v | 535 +--- .../ethereum/spurious_dragon/utils/address.v | 6 +- .../spurious_dragon/utils/hexadecimal.v | 3 - .../ethereum/spurious_dragon/utils/message.v | 96 +- .../ethereum/spurious_dragon/vm/__init__.v | 70 - CoqOfPython/ethereum/spurious_dragon/vm/gas.v | 801 ++++++ .../vm/instructions/arithmetic.v | 127 +- .../spurious_dragon/vm/instructions/bitwise.v | 16 - .../spurious_dragon/vm/instructions/block.v | 18 - .../vm/instructions/comparison.v | 30 +- .../vm/instructions/control_flow.v | 31 - .../vm/instructions/environment.v | 6 +- .../spurious_dragon/vm/instructions/keccak.v | 2 +- .../spurious_dragon/vm/instructions/log.v | 2 +- .../spurious_dragon/vm/instructions/memory.v | 6 +- .../spurious_dragon/vm/instructions/stack.v | 34 +- .../spurious_dragon/vm/instructions/storage.v | 33 - .../spurious_dragon/vm/instructions/system.v | 1130 ++++++++ .../ethereum/spurious_dragon/vm/interpreter.v | 227 -- .../ethereum/spurious_dragon/vm/memory.v | 53 +- .../vm/precompiled_contracts/ecrecover.v | 50 +- .../ethereum/spurious_dragon/vm/runtime.v | 52 +- .../ethereum/spurious_dragon/vm/stack.v | 32 - .../ethereum/tangerine_whistle/bloom.v | 6 +- CoqOfPython/ethereum/tangerine_whistle/fork.v | 491 ++-- .../ethereum/tangerine_whistle/fork_types.v | 1 - .../ethereum/tangerine_whistle/state.v | 187 +- CoqOfPython/ethereum/tangerine_whistle/trie.v | 535 +--- .../tangerine_whistle/utils/address.v | 6 +- .../tangerine_whistle/utils/hexadecimal.v | 3 - .../tangerine_whistle/utils/message.v | 96 +- .../ethereum/tangerine_whistle/vm/gas.v | 801 ++++++ .../vm/instructions/arithmetic.v | 127 +- .../vm/instructions/bitwise.v | 16 - .../tangerine_whistle/vm/instructions/block.v | 18 - .../vm/instructions/comparison.v | 30 +- .../vm/instructions/control_flow.v | 31 - .../vm/instructions/environment.v | 6 +- .../vm/instructions/keccak.v | 2 +- .../tangerine_whistle/vm/instructions/log.v | 2 +- .../vm/instructions/memory.v | 6 +- .../tangerine_whistle/vm/instructions/stack.v | 34 +- .../vm/instructions/storage.v | 33 - .../vm/instructions/system.v | 1119 ++++++++ .../tangerine_whistle/vm/interpreter.v | 182 -- .../ethereum/tangerine_whistle/vm/memory.v | 53 +- .../vm/precompiled_contracts/ecrecover.v | 50 +- .../ethereum/tangerine_whistle/vm/runtime.v | 52 +- .../ethereum/tangerine_whistle/vm/stack.v | 32 - CoqOfPython/ethereum/utils/byte.v | 6 +- CoqOfPython/ethereum/utils/ensure.v | 13 +- CoqOfPython/ethereum/utils/hexadecimal.v | 34 - CoqOfPython/ethereum/utils/numeric.v | 83 +- convert_all.py | 4 +- main.py | 121 +- 486 files changed, 56544 insertions(+), 41548 deletions(-) delete mode 100644 CoqOfPython/CoqMakefile create mode 100644 CoqOfPython/ethereum/arrow_glacier/fork.v create mode 100644 CoqOfPython/ethereum/arrow_glacier/vm/gas.v create mode 100644 CoqOfPython/ethereum/arrow_glacier/vm/instructions/system.v create mode 100644 CoqOfPython/ethereum/berlin/fork.v create mode 100644 CoqOfPython/ethereum/berlin/vm/gas.v create mode 100644 CoqOfPython/ethereum/berlin/vm/instructions/system.v create mode 100644 CoqOfPython/ethereum/byzantium/fork.v create mode 100644 CoqOfPython/ethereum/byzantium/vm/gas.v create mode 100644 CoqOfPython/ethereum/byzantium/vm/instructions/system.v create mode 100644 CoqOfPython/ethereum/cancun/vm/gas.v create mode 100644 CoqOfPython/ethereum/cancun/vm/instructions/system.v create mode 100644 CoqOfPython/ethereum/constantinople/fork.v create mode 100644 CoqOfPython/ethereum/constantinople/vm/gas.v create mode 100644 CoqOfPython/ethereum/constantinople/vm/instructions/system.v create mode 100644 CoqOfPython/ethereum/dao_fork/vm/gas.v create mode 100644 CoqOfPython/ethereum/frontier/vm/gas.v create mode 100644 CoqOfPython/ethereum/gray_glacier/fork.v create mode 100644 CoqOfPython/ethereum/gray_glacier/vm/gas.v create mode 100644 CoqOfPython/ethereum/gray_glacier/vm/instructions/system.v create mode 100644 CoqOfPython/ethereum/homestead/vm/gas.v create mode 100644 CoqOfPython/ethereum/istanbul/fork.v create mode 100644 CoqOfPython/ethereum/istanbul/vm/gas.v create mode 100644 CoqOfPython/ethereum/istanbul/vm/instructions/system.v create mode 100644 CoqOfPython/ethereum/london/fork.v create mode 100644 CoqOfPython/ethereum/london/vm/gas.v create mode 100644 CoqOfPython/ethereum/london/vm/instructions/system.v create mode 100644 CoqOfPython/ethereum/muir_glacier/fork.v create mode 100644 CoqOfPython/ethereum/muir_glacier/vm/gas.v create mode 100644 CoqOfPython/ethereum/muir_glacier/vm/instructions/system.v create mode 100644 CoqOfPython/ethereum/paris/vm/gas.v create mode 100644 CoqOfPython/ethereum/paris/vm/instructions/system.v create mode 100644 CoqOfPython/ethereum/shanghai/vm/gas.v create mode 100644 CoqOfPython/ethereum/shanghai/vm/instructions/system.v create mode 100644 CoqOfPython/ethereum/spurious_dragon/vm/gas.v create mode 100644 CoqOfPython/ethereum/spurious_dragon/vm/instructions/system.v create mode 100644 CoqOfPython/ethereum/tangerine_whistle/vm/gas.v create mode 100644 CoqOfPython/ethereum/tangerine_whistle/vm/instructions/system.v diff --git a/.gitignore b/.gitignore index 1616cf4..192b82b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # Coq rules .CoqMakefile.d +CoqMakefile CoqMakefile.conf *.vo *.vok diff --git a/CoqOfPython/CoqMakefile b/CoqOfPython/CoqMakefile deleted file mode 100644 index 97d530e..0000000 --- a/CoqOfPython/CoqMakefile +++ /dev/null @@ -1,981 +0,0 @@ -########################################################################## -## # The Coq Proof Assistant / The Coq Development Team ## -## v # Copyright INRIA, CNRS and contributors ## -## /dev/null 2>/dev/null; echo $$?)) -STDTIME?=command time -f $(TIMEFMT) -else -ifeq (0,$(shell gtime -f "" true >/dev/null 2>/dev/null; echo $$?)) -STDTIME?=gtime -f $(TIMEFMT) -else -STDTIME?=command time -endif -endif -else -STDTIME?=command time -f $(TIMEFMT) -endif - -COQBIN?= -ifneq (,$(COQBIN)) -# add an ending / -COQBIN:=$(COQBIN)/ -endif - -# Coq binaries -COQC ?= "$(COQBIN)coqc" -COQTOP ?= "$(COQBIN)coqtop" -COQCHK ?= "$(COQBIN)coqchk" -COQNATIVE ?= "$(COQBIN)coqnative" -COQDEP ?= "$(COQBIN)coqdep" -COQDOC ?= "$(COQBIN)coqdoc" -COQPP ?= "$(COQBIN)coqpp" -COQMKFILE ?= "$(COQBIN)coq_makefile" -OCAMLLIBDEP ?= "$(COQBIN)ocamllibdep" - -# Timing scripts -COQMAKE_ONE_TIME_FILE ?= "$(COQCORELIB)/tools/make-one-time-file.py" -COQMAKE_BOTH_TIME_FILES ?= "$(COQCORELIB)/tools/make-both-time-files.py" -COQMAKE_BOTH_SINGLE_TIMING_FILES ?= "$(COQCORELIB)/tools/make-both-single-timing-files.py" -BEFORE ?= -AFTER ?= - -# OCaml binaries -CAMLC ?= "$(OCAMLFIND)" ocamlc -c -CAMLOPTC ?= "$(OCAMLFIND)" opt -c -CAMLLINK ?= "$(OCAMLFIND)" ocamlc -linkall -CAMLOPTLINK ?= "$(OCAMLFIND)" opt -linkall -CAMLDOC ?= "$(OCAMLFIND)" ocamldoc -CAMLDEP ?= "$(OCAMLFIND)" ocamldep -slash -ml-synonym .mlpack - -# DESTDIR is prepended to all installation paths -DESTDIR ?= - -# Debug builds, typically -g to OCaml, -debug to Coq. -CAMLDEBUG ?= -COQDEBUG ?= - -# Extra packages to be linked in (as in findlib -package) -CAMLPKGS ?= -FINDLIBPKGS = -package coq-core.plugins.ltac $(CAMLPKGS) - -# Option for making timing files -TIMING?= -# Option for changing sorting of timing output file -TIMING_SORT_BY ?= auto -# Option for changing the fuzz parameter on the output file -TIMING_FUZZ ?= 0 -# Option for changing whether to use real or user time for timing tables -TIMING_REAL?= -# Option for including the memory column(s) -TIMING_INCLUDE_MEM?= -# Option for sorting by the memory column -TIMING_SORT_BY_MEM?= -# Output file names for timed builds -TIME_OF_BUILD_FILE ?= time-of-build.log -TIME_OF_BUILD_BEFORE_FILE ?= time-of-build-before.log -TIME_OF_BUILD_AFTER_FILE ?= time-of-build-after.log -TIME_OF_PRETTY_BUILD_FILE ?= time-of-build-pretty.log -TIME_OF_PRETTY_BOTH_BUILD_FILE ?= time-of-build-both.log -TIME_OF_PRETTY_BUILD_EXTRA_FILES ?= - # also output to the command line - -TGTS ?= - -# Retro compatibility (DESTDIR is standard on Unix, DSTROOT is not) -ifdef DSTROOT -DESTDIR := $(DSTROOT) -endif - -# Substitution of the path by appending $(DESTDIR) if needed. -# The variable $(COQMF_WINDRIVE) can be needed for Cygwin environments. -windrive_path = $(if $(COQMF_WINDRIVE),$(subst $(COQMF_WINDRIVE),/,$(1)),$(1)) -destination_path = $(if $(DESTDIR),$(DESTDIR)/$(call windrive_path,$(1)),$(1)) - -# Installation paths of libraries and documentation. -COQLIBINSTALL ?= $(call destination_path,$(COQLIB)/user-contrib) -COQDOCINSTALL ?= $(call destination_path,$(DOCDIR)/coq/user-contrib) -COQPLUGININSTALL ?= $(call destination_path,$(COQCORELIB)/..) -COQTOPINSTALL ?= $(call destination_path,$(COQLIB)/toploop) # FIXME: Unused variable? - -# findlib files installation -FINDLIBPREINST= mkdir -p "$(COQPLUGININSTALL)/" -FINDLIBDESTDIR= -destdir "$(COQPLUGININSTALL)/" - -# we need to move out of sight $(METAFILE) otherwise findlib thinks the -# package is already installed -findlib_install = \ - $(HIDE)if [ "$(METAFILE)" ]; then \ - $(FINDLIBPREINST) && \ - mv "$(METAFILE)" "$(METAFILE).skip" ; \ - "$(OCAMLFIND)" install $(2) $(FINDLIBDESTDIR) $(FINDLIBPACKAGE) $(1); \ - rc=$$?; \ - mv "$(METAFILE).skip" "$(METAFILE)"; \ - exit $$rc; \ - fi -findlib_remove = \ - $(HIDE)if [ ! -z "$(METAFILE)" ]; then\ - "$(OCAMLFIND)" remove $(FINDLIBDESTDIR) $(FINDLIBPACKAGE); \ - fi - - -########## End of parameters ################################################## -# What follows may be relevant to you only if you need to -# extend this Makefile. If so, look for 'Extension point' here and -# put in CoqMakefile.local double colon rules accordingly. -# E.g. to perform some work after the all target completes you can write -# -# post-all:: -# echo "All done!" -# -# in CoqMakefile.local -# -############################################################################### - - - - -# Flags ####################################################################### -# -# We define a bunch of variables combining the parameters. -# To add additional flags to coq, coqchk or coqdoc, set the -# {COQ,COQCHK,COQDOC}EXTRAFLAGS variable to whatever you want to add. -# To overwrite the default choice and set your own flags entirely, set the -# {COQ,COQCHK,COQDOC}FLAGS variable. - -SHOW := $(if $(VERBOSE),@true "",@echo "") -HIDE := $(if $(VERBOSE),,@) - -TIMER=$(if $(TIMED), $(STDTIME), $(TIMECMD)) - -OPT?= - -# The DYNOBJ and DYNLIB variables are used by "coqdep -dyndep var" in .v.d -ifeq '$(OPT)' '-byte' -USEBYTE:=true -DYNOBJ:=.cma -DYNLIB:=.cma -else -USEBYTE:= -DYNOBJ:=.cmxs -DYNLIB:=.cmxs -endif - -# these variables are meant to be overridden if you want to add *extra* flags -COQEXTRAFLAGS?= -COQCHKEXTRAFLAGS?= -COQDOCEXTRAFLAGS?= - -# Find the last argument of the form "-native-compiler FLAG" -COQUSERNATIVEFLAG:=$(strip \ -$(subst -native-compiler-,,\ -$(lastword \ -$(filter -native-compiler-%,\ -$(subst -native-compiler ,-native-compiler-,\ -$(strip $(COQEXTRAFLAGS))))))) - -COQFILTEREDEXTRAFLAGS:=$(strip \ -$(filter-out -native-compiler-%,\ -$(subst -native-compiler ,-native-compiler-,\ -$(strip $(COQEXTRAFLAGS))))) - -COQACTUALNATIVEFLAG:=$(lastword $(COQMF_COQ_NATIVE_COMPILER_DEFAULT) $(COQMF_COQPROJECTNATIVEFLAG) $(COQUSERNATIVEFLAG)) - -ifeq '$(COQACTUALNATIVEFLAG)' 'yes' - COQNATIVEFLAG="-w" "-deprecated-native-compiler-option" "-native-compiler" "ondemand" - COQDONATIVE="yes" -else -ifeq '$(COQACTUALNATIVEFLAG)' 'ondemand' - COQNATIVEFLAG="-w" "-deprecated-native-compiler-option" "-native-compiler" "ondemand" - COQDONATIVE="no" -else - COQNATIVEFLAG="-w" "-deprecated-native-compiler-option" "-native-compiler" "no" - COQDONATIVE="no" -endif -endif - -# these flags do NOT contain the libraries, to make them easier to overwrite -COQFLAGS?=-q $(OTHERFLAGS) $(COQFILTEREDEXTRAFLAGS) $(COQNATIVEFLAG) -COQCHKFLAGS?=-silent -o $(COQCHKEXTRAFLAGS) -COQDOCFLAGS?=-interpolate -utf8 $(COQDOCEXTRAFLAGS) - -COQDOCLIBS?=$(COQLIBS_NOML) - -# The version of Coq being run and the version of coq_makefile that -# generated this makefile -COQ_VERSION:=$(shell $(COQC) --print-version | cut -d " " -f 1) -COQMAKEFILE_VERSION:=8.17.1 - -# COQ_SRC_SUBDIRS is for user-overriding, usually to add -# `user-contrib/Foo` to the includes, we keep COQCORE_SRC_SUBDIRS for -# Coq's own core libraries, which should be replaced by ocamlfind -# options at some point. -COQ_SRC_SUBDIRS?= -COQSRCLIBS?= $(foreach d,$(COQ_SRC_SUBDIRS), -I "$(COQLIB)/$(d)") - -CAMLFLAGS+=$(OCAMLLIBS) $(COQSRCLIBS) -# ocamldoc fails with unknown argument otherwise -CAMLDOCFLAGS:=$(filter-out -annot, $(filter-out -bin-annot, $(CAMLFLAGS))) -CAMLFLAGS+=$(OCAMLWARN) - -ifneq (,$(TIMING)) -TIMING_ARG=-time -ifeq (after,$(TIMING)) -TIMING_EXT=after-timing -else -ifeq (before,$(TIMING)) -TIMING_EXT=before-timing -else -TIMING_EXT=timing -endif -endif -else -TIMING_ARG= -endif - -# Files ####################################################################### -# -# We here define a bunch of variables about the files being part of the -# Coq project in order to ease the writing of build target and build rules - -VDFILE := .CoqMakefile.d - -ALLSRCFILES := \ - $(MLGFILES) \ - $(MLFILES) \ - $(MLPACKFILES) \ - $(MLLIBFILES) \ - $(MLIFILES) - -# helpers -vo_to_obj = $(addsuffix .o,\ - $(filter-out Warning: Error:,\ - $(shell $(COQTOP) -q -noinit -batch -quiet -print-mod-uid $(1)))) -strip_dotslash = $(patsubst ./%,%,$(1)) - -# without this we get undefined variables in the expansion for the -# targets of the [deprecated,use-mllib-or-mlpack] rule -with_undef = $(if $(filter-out undefined, $(origin $(1))),$($(1))) - -VO = vo -VOS = vos - -VOFILES = $(VFILES:.v=.$(VO)) -GLOBFILES = $(VFILES:.v=.glob) -HTMLFILES = $(VFILES:.v=.html) -GHTMLFILES = $(VFILES:.v=.g.html) -BEAUTYFILES = $(addsuffix .beautified,$(VFILES)) -TEXFILES = $(VFILES:.v=.tex) -GTEXFILES = $(VFILES:.v=.g.tex) -CMOFILES = \ - $(MLGFILES:.mlg=.cmo) \ - $(MLFILES:.ml=.cmo) \ - $(MLPACKFILES:.mlpack=.cmo) -CMXFILES = $(CMOFILES:.cmo=.cmx) -OFILES = $(CMXFILES:.cmx=.o) -CMAFILES = $(MLLIBFILES:.mllib=.cma) $(MLPACKFILES:.mlpack=.cma) -CMXAFILES = $(CMAFILES:.cma=.cmxa) -CMIFILES = \ - $(CMOFILES:.cmo=.cmi) \ - $(MLIFILES:.mli=.cmi) -# the /if/ is because old _CoqProject did not list a .ml(pack|lib) but just -# a .mlg file -CMXSFILES = \ - $(MLPACKFILES:.mlpack=.cmxs) \ - $(CMXAFILES:.cmxa=.cmxs) \ - $(if $(MLPACKFILES)$(CMXAFILES),,\ - $(MLGFILES:.mlg=.cmxs) $(MLFILES:.ml=.cmxs)) - -# files that are packed into a plugin (no extension) -PACKEDFILES = \ - $(call strip_dotslash, \ - $(foreach lib, \ - $(call strip_dotslash, \ - $(MLPACKFILES:.mlpack=_MLPACK_DEPENDENCIES)),$(call with_undef,$(lib)))) -# files that are archived into a .cma (mllib) -LIBEDFILES = \ - $(call strip_dotslash, \ - $(foreach lib, \ - $(call strip_dotslash, \ - $(MLLIBFILES:.mllib=_MLLIB_DEPENDENCIES)),$(call with_undef,$(lib)))) -CMIFILESTOINSTALL = $(filter-out $(addsuffix .cmi,$(PACKEDFILES)),$(CMIFILES)) -CMOFILESTOINSTALL = $(filter-out $(addsuffix .cmo,$(PACKEDFILES)),$(CMOFILES)) -OBJFILES = $(call vo_to_obj,$(VOFILES)) -ALLNATIVEFILES = \ - $(OBJFILES:.o=.cmi) \ - $(OBJFILES:.o=.cmx) \ - $(OBJFILES:.o=.cmxs) -FINDLIBPACKAGE=$(patsubst .%,%,$(suffix $(METAFILE))) - -# trick: wildcard filters out non-existing files, so that `install` doesn't show -# warnings and `clean` doesn't pass to rm a list of files that is too long for -# the shell. -NATIVEFILES = $(wildcard $(ALLNATIVEFILES)) -FILESTOINSTALL = \ - $(VOFILES) \ - $(VFILES) \ - $(GLOBFILES) \ - $(NATIVEFILES) \ - $(CMXSFILES) # to be removed when we remove legacy loading -FINDLIBFILESTOINSTALL = \ - $(CMIFILESTOINSTALL) -ifeq '$(HASNATDYNLINK)' 'true' -DO_NATDYNLINK = yes -FINDLIBFILESTOINSTALL += $(CMXSFILES) $(CMXAFILES) $(CMOFILESTOINSTALL:.cmo=.cmx) -else -DO_NATDYNLINK = -endif - -ALLDFILES = $(addsuffix .d,$(ALLSRCFILES)) $(VDFILE) - -# Compilation targets ######################################################### - -all: - $(HIDE)$(MAKE) --no-print-directory -f "$(SELF)" pre-all - $(HIDE)$(MAKE) --no-print-directory -f "$(SELF)" real-all - $(HIDE)$(MAKE) --no-print-directory -f "$(SELF)" post-all -.PHONY: all - -all.timing.diff: - $(HIDE)$(MAKE) --no-print-directory -f "$(SELF)" pre-all - $(HIDE)$(MAKE) --no-print-directory -f "$(SELF)" real-all.timing.diff TIME_OF_PRETTY_BUILD_EXTRA_FILES="" - $(HIDE)$(MAKE) --no-print-directory -f "$(SELF)" post-all -.PHONY: all.timing.diff - -ifeq (0,$(TIMING_REAL)) -TIMING_REAL_ARG := -TIMING_USER_ARG := --user -else -ifeq (1,$(TIMING_REAL)) -TIMING_REAL_ARG := --real -TIMING_USER_ARG := -else -TIMING_REAL_ARG := -TIMING_USER_ARG := -endif -endif - -ifeq (0,$(TIMING_INCLUDE_MEM)) -TIMING_INCLUDE_MEM_ARG := --no-include-mem -else -TIMING_INCLUDE_MEM_ARG := -endif - -ifeq (1,$(TIMING_SORT_BY_MEM)) -TIMING_SORT_BY_MEM_ARG := --sort-by-mem -else -TIMING_SORT_BY_MEM_ARG := -endif - -make-pretty-timed-before:: TIME_OF_BUILD_FILE=$(TIME_OF_BUILD_BEFORE_FILE) -make-pretty-timed-after:: TIME_OF_BUILD_FILE=$(TIME_OF_BUILD_AFTER_FILE) -make-pretty-timed make-pretty-timed-before make-pretty-timed-after:: - $(HIDE)rm -f pretty-timed-success.ok - $(HIDE)($(MAKE) --no-print-directory -f "$(PARENT)" $(TGTS) TIMED=1 2>&1 && touch pretty-timed-success.ok) | tee -a $(TIME_OF_BUILD_FILE) - $(HIDE)rm pretty-timed-success.ok # must not be -f; must fail if the touch failed -print-pretty-timed:: - $(HIDE)$(COQMAKE_ONE_TIME_FILE) $(TIMING_INCLUDE_MEM_ARG) $(TIMING_SORT_BY_MEM_ARG) $(TIMING_REAL_ARG) $(TIME_OF_BUILD_FILE) $(TIME_OF_PRETTY_BUILD_FILE) $(TIME_OF_PRETTY_BUILD_EXTRA_FILES) -print-pretty-timed-diff:: - $(HIDE)$(COQMAKE_BOTH_TIME_FILES) --sort-by=$(TIMING_SORT_BY) $(TIMING_INCLUDE_MEM_ARG) $(TIMING_SORT_BY_MEM_ARG) $(TIMING_REAL_ARG) $(TIME_OF_BUILD_AFTER_FILE) $(TIME_OF_BUILD_BEFORE_FILE) $(TIME_OF_PRETTY_BOTH_BUILD_FILE) $(TIME_OF_PRETTY_BUILD_EXTRA_FILES) -ifeq (,$(BEFORE)) -print-pretty-single-time-diff:: - @echo 'Error: Usage: $(MAKE) print-pretty-single-time-diff AFTER=path/to/file.v.after-timing BEFORE=path/to/file.v.before-timing' - $(HIDE)false -else -ifeq (,$(AFTER)) -print-pretty-single-time-diff:: - @echo 'Error: Usage: $(MAKE) print-pretty-single-time-diff AFTER=path/to/file.v.after-timing BEFORE=path/to/file.v.before-timing' - $(HIDE)false -else -print-pretty-single-time-diff:: - $(HIDE)$(COQMAKE_BOTH_SINGLE_TIMING_FILES) --fuzz=$(TIMING_FUZZ) --sort-by=$(TIMING_SORT_BY) $(TIMING_USER_ARG) $(AFTER) $(BEFORE) $(TIME_OF_PRETTY_BUILD_FILE) $(TIME_OF_PRETTY_BUILD_EXTRA_FILES) -endif -endif -pretty-timed: - $(HIDE)$(MAKE) --no-print-directory -f "$(PARENT)" make-pretty-timed - $(HIDE)$(MAKE) --no-print-directory -f "$(SELF)" print-pretty-timed -.PHONY: pretty-timed make-pretty-timed make-pretty-timed-before make-pretty-timed-after print-pretty-timed print-pretty-timed-diff print-pretty-single-time-diff - -# Extension points for actions to be performed before/after the all target -pre-all:: - @# Extension point - $(HIDE)if [ "$(COQMAKEFILE_VERSION)" != "$(COQ_VERSION)" ]; then\ - echo "W: This Makefile was generated by Coq $(COQMAKEFILE_VERSION)";\ - echo "W: while the current Coq version is $(COQ_VERSION)";\ - fi -.PHONY: pre-all - -post-all:: - @# Extension point -.PHONY: post-all - -real-all: $(VOFILES) $(if $(USEBYTE),bytefiles,optfiles) -.PHONY: real-all - -real-all.timing.diff: $(VOFILES:.vo=.v.timing.diff) -.PHONY: real-all.timing.diff - -bytefiles: $(CMOFILES) $(CMAFILES) -.PHONY: bytefiles - -optfiles: $(if $(DO_NATDYNLINK),$(CMXSFILES)) -.PHONY: optfiles - -# FIXME, see Ralf's bugreport -# quick is deprecated, now renamed vio -vio: $(VOFILES:.vo=.vio) -.PHONY: vio -quick: vio - $(warning "'make quick' is deprecated, use 'make vio' or consider using 'vos' files") -.PHONY: quick - -vio2vo: - $(TIMER) $(COQC) $(COQDEBUG) $(COQFLAGS) $(COQLIBS) \ - -schedule-vio2vo $(J) $(VOFILES:%.vo=%.vio) -.PHONY: vio2vo - -# quick2vo is undocumented -quick2vo: - $(HIDE)make -j $(J) vio - $(HIDE)VIOFILES=$$(for vofile in $(VOFILES); do \ - viofile="$$(echo "$$vofile" | sed "s/\.vo$$/.vio/")"; \ - if [ "$$vofile" -ot "$$viofile" -o ! -e "$$vofile" ]; then printf "$$viofile "; fi; \ - done); \ - echo "VIO2VO: $$VIOFILES"; \ - if [ -n "$$VIOFILES" ]; then \ - $(TIMER) $(COQC) $(COQDEBUG) $(COQFLAGS) $(COQLIBS) -schedule-vio2vo $(J) $$VIOFILES; \ - fi -.PHONY: quick2vo - -checkproofs: - $(TIMER) $(COQC) $(COQDEBUG) $(COQFLAGS) $(COQLIBS) \ - -schedule-vio-checking $(J) $(VOFILES:%.vo=%.vio) -.PHONY: checkproofs - -vos: $(VOFILES:%.vo=%.vos) -.PHONY: vos - -vok: $(VOFILES:%.vo=%.vok) -.PHONY: vok - -validate: $(VOFILES) - $(TIMER) $(COQCHK) $(COQCHKFLAGS) $(COQLIBS_NOML) $^ -.PHONY: validate - -only: $(TGTS) -.PHONY: only - -# Documentation targets ####################################################### - -html: $(GLOBFILES) $(VFILES) - $(SHOW)'COQDOC -d html $(GAL)' - $(HIDE)mkdir -p html - $(HIDE)$(COQDOC) \ - -toc $(COQDOCFLAGS) -html $(GAL) $(COQDOCLIBS) -d html $(VFILES) - -mlihtml: $(MLIFILES:.mli=.cmi) - $(SHOW)'CAMLDOC -d $@' - $(HIDE)mkdir $@ || rm -rf $@/* - $(HIDE)$(CAMLDOC) -html \ - -d $@ -m A $(CAMLDEBUG) $(CAMLDOCFLAGS) $(MLIFILES) $(FINDLIBPKGS) - -all-mli.tex: $(MLIFILES:.mli=.cmi) - $(SHOW)'CAMLDOC -latex $@' - $(HIDE)$(CAMLDOC) -latex \ - -o $@ -m A $(CAMLDEBUG) $(CAMLDOCFLAGS) $(MLIFILES) $(FINDLIBPKGS) - -all.ps: $(VFILES) - $(SHOW)'COQDOC -ps $(GAL)' - $(HIDE)$(COQDOC) \ - -toc $(COQDOCFLAGS) -ps $(GAL) $(COQDOCLIBS) \ - -o $@ `$(COQDEP) -sort $(VFILES)` - -all.pdf: $(VFILES) - $(SHOW)'COQDOC -pdf $(GAL)' - $(HIDE)$(COQDOC) \ - -toc $(COQDOCFLAGS) -pdf $(GAL) $(COQDOCLIBS) \ - -o $@ `$(COQDEP) -sort $(VFILES)` - -# FIXME: not quite right, since the output name is different -gallinahtml: GAL=-g -gallinahtml: html - -all-gal.ps: GAL=-g -all-gal.ps: all.ps - -all-gal.pdf: GAL=-g -all-gal.pdf: all.pdf - -# ? -beautify: $(BEAUTYFILES) - for file in $^; do mv $${file%.beautified} $${file%beautified}old && mv $${file} $${file%.beautified}; done - @echo 'Do not do "make clean" until you are sure that everything went well!' - @echo 'If there were a problem, execute "for file in $$(find . -name \*.v.old -print); do mv $${file} $${file%.old}; done" in your shell/' -.PHONY: beautify - -# Installation targets ######################################################## -# -# There rules can be extended in CoqMakefile.local -# Extensions can't assume when they run. - -# findlib needs the package to not be installed, so we remove it before -# installing it (see the call to findlib_remove) -install: META - $(HIDE)code=0; for f in $(FILESTOINSTALL); do\ - if ! [ -f "$$f" ]; then >&2 echo $$f does not exist; code=1; fi \ - done; exit $$code - $(HIDE)for f in $(FILESTOINSTALL); do\ - df="`$(COQMKFILE) -destination-of "$$f" $(COQLIBS)`";\ - if [ "$$?" != "0" -o -z "$$df" ]; then\ - echo SKIP "$$f" since it has no logical path;\ - else\ - install -d "$(COQLIBINSTALL)/$$df" &&\ - install -m 0644 "$$f" "$(COQLIBINSTALL)/$$df" &&\ - echo INSTALL "$$f" "$(COQLIBINSTALL)/$$df";\ - fi;\ - done - $(call findlib_remove) - $(call findlib_install, META $(FINDLIBFILESTOINSTALL)) - $(HIDE)$(MAKE) install-extra -f "$(SELF)" -install-extra:: - @# Extension point -.PHONY: install install-extra - -META: $(METAFILE) - $(HIDE)if [ "$(METAFILE)" ]; then \ - cat "$(METAFILE)" | grep -v 'directory.*=.*' > META; \ - fi - -install-byte: - $(call findlib_install, $(CMAFILES) $(CMOFILESTOINSTALL), -add) - -install-doc:: html mlihtml - @# Extension point - $(HIDE)install -d "$(COQDOCINSTALL)/$(INSTALLCOQDOCROOT)/html" - $(HIDE)for i in html/*; do \ - dest="$(COQDOCINSTALL)/$(INSTALLCOQDOCROOT)/$$i";\ - install -m 0644 "$$i" "$$dest";\ - echo INSTALL "$$i" "$$dest";\ - done - $(HIDE)install -d \ - "$(COQDOCINSTALL)/$(INSTALLCOQDOCROOT)/mlihtml" - $(HIDE)for i in mlihtml/*; do \ - dest="$(COQDOCINSTALL)/$(INSTALLCOQDOCROOT)/$$i";\ - install -m 0644 "$$i" "$$dest";\ - echo INSTALL "$$i" "$$dest";\ - done -.PHONY: install-doc - -uninstall:: - @# Extension point - $(call findlib_remove) - $(HIDE)for f in $(FILESTOINSTALL); do \ - df="`$(COQMKFILE) -destination-of "$$f" $(COQLIBS)`" &&\ - instf="$(COQLIBINSTALL)/$$df/`basename $$f`" &&\ - rm -f "$$instf" &&\ - echo RM "$$instf" ;\ - done - $(HIDE)for f in $(FILESTOINSTALL); do \ - df="`$(COQMKFILE) -destination-of "$$f" $(COQLIBS)`" &&\ - echo RMDIR "$(COQLIBINSTALL)/$$df/" &&\ - (rmdir "$(COQLIBINSTALL)/$$df/" 2>/dev/null || true); \ - done - -.PHONY: uninstall - -uninstall-doc:: - @# Extension point - $(SHOW)'RM $(COQDOCINSTALL)/$(INSTALLCOQDOCROOT)/html' - $(HIDE)rm -rf "$(COQDOCINSTALL)/$(INSTALLCOQDOCROOT)/html" - $(SHOW)'RM $(COQDOCINSTALL)/$(INSTALLCOQDOCROOT)/mlihtml' - $(HIDE)rm -rf "$(COQDOCINSTALL)/$(INSTALLCOQDOCROOT)/mlihtml" - $(HIDE) rmdir "$(COQDOCINSTALL)/$(INSTALLCOQDOCROOT)/" || true -.PHONY: uninstall-doc - -# Cleaning #################################################################### -# -# There rules can be extended in CoqMakefile.local -# Extensions can't assume when they run. - -clean:: - @# Extension point - $(SHOW)'CLEAN' - $(HIDE)rm -f $(CMOFILES) - $(HIDE)rm -f $(CMIFILES) - $(HIDE)rm -f $(CMAFILES) - $(HIDE)rm -f $(CMXFILES) - $(HIDE)rm -f $(CMXAFILES) - $(HIDE)rm -f $(CMXSFILES) - $(HIDE)rm -f $(OFILES) - $(HIDE)rm -f $(CMXAFILES:.cmxa=.a) - $(HIDE)rm -f $(MLGFILES:.mlg=.ml) - $(HIDE)rm -f $(CMXFILES:.cmx=.cmt) - $(HIDE)rm -f $(MLIFILES:.mli=.cmti) - $(HIDE)rm -f $(ALLDFILES) - $(HIDE)rm -f $(NATIVEFILES) - $(HIDE)find . -name .coq-native -type d -empty -delete - $(HIDE)rm -f $(VOFILES) - $(HIDE)rm -f $(VOFILES:.vo=.vio) - $(HIDE)rm -f $(VOFILES:.vo=.vos) - $(HIDE)rm -f $(VOFILES:.vo=.vok) - $(HIDE)rm -f $(BEAUTYFILES) $(VFILES:=.old) - $(HIDE)rm -f all.ps all-gal.ps all.pdf all-gal.pdf all.glob all-mli.tex - $(HIDE)rm -f $(VFILES:.v=.glob) - $(HIDE)rm -f $(VFILES:.v=.tex) - $(HIDE)rm -f $(VFILES:.v=.g.tex) - $(HIDE)rm -f pretty-timed-success.ok - $(HIDE)rm -f META - $(HIDE)rm -rf html mlihtml -.PHONY: clean - -cleanall:: clean - @# Extension point - $(SHOW)'CLEAN *.aux *.timing' - $(HIDE)rm -f $(foreach f,$(VFILES:.v=),$(dir $(f)).$(notdir $(f)).aux) - $(HIDE)rm -f $(TIME_OF_BUILD_FILE) $(TIME_OF_BUILD_BEFORE_FILE) $(TIME_OF_BUILD_AFTER_FILE) $(TIME_OF_PRETTY_BUILD_FILE) $(TIME_OF_PRETTY_BOTH_BUILD_FILE) - $(HIDE)rm -f $(VOFILES:.vo=.v.timing) - $(HIDE)rm -f $(VOFILES:.vo=.v.before-timing) - $(HIDE)rm -f $(VOFILES:.vo=.v.after-timing) - $(HIDE)rm -f $(VOFILES:.vo=.v.timing.diff) - $(HIDE)rm -f .lia.cache .nia.cache -.PHONY: cleanall - -archclean:: - @# Extension point - $(SHOW)'CLEAN *.cmx *.o' - $(HIDE)rm -f $(NATIVEFILES) - $(HIDE)rm -f $(CMOFILES:%.cmo=%.cmx) -.PHONY: archclean - - -# Compilation rules ########################################################### - -$(MLIFILES:.mli=.cmi): %.cmi: %.mli - $(SHOW)'CAMLC -c $<' - $(HIDE)$(TIMER) $(CAMLC) $(CAMLDEBUG) $(CAMLFLAGS) $(FINDLIBPKGS) $< - -$(MLGFILES:.mlg=.ml): %.ml: %.mlg - $(SHOW)'COQPP $<' - $(HIDE)$(COQPP) $< - -# Stupid hack around a deficient syntax: we cannot concatenate two expansions -$(filter %.cmo, $(MLFILES:.ml=.cmo) $(MLGFILES:.mlg=.cmo)): %.cmo: %.ml - $(SHOW)'CAMLC -c $<' - $(HIDE)$(TIMER) $(CAMLC) $(CAMLDEBUG) $(CAMLFLAGS) $(FINDLIBPKGS) $< - -# Same hack -$(filter %.cmx, $(MLFILES:.ml=.cmx) $(MLGFILES:.mlg=.cmx)): %.cmx: %.ml - $(SHOW)'CAMLOPT -c $(FOR_PACK) $<' - $(HIDE)$(TIMER) $(CAMLOPTC) $(CAMLDEBUG) $(CAMLFLAGS) $(FINDLIBPKGS) $(FOR_PACK) $< - - -$(MLLIBFILES:.mllib=.cmxs): %.cmxs: %.cmxa - $(SHOW)'CAMLOPT -shared -o $@' - $(HIDE)$(TIMER) $(CAMLOPTLINK) $(CAMLDEBUG) $(CAMLFLAGS) $(FINDLIBPKGS) \ - -shared -o $@ $< - -$(MLLIBFILES:.mllib=.cma): %.cma: | %.mllib - $(SHOW)'CAMLC -a -o $@' - $(HIDE)$(TIMER) $(CAMLLINK) $(CAMLDEBUG) $(CAMLFLAGS) $(FINDLIBPKGS) -a -o $@ $^ - -$(MLLIBFILES:.mllib=.cmxa): %.cmxa: | %.mllib - $(SHOW)'CAMLOPT -a -o $@' - $(HIDE)$(TIMER) $(CAMLOPTLINK) $(CAMLDEBUG) $(CAMLFLAGS) $(FINDLIBPKGS) -a -o $@ $^ - - -$(MLPACKFILES:.mlpack=.cmxs): %.cmxs: %.cmxa - $(SHOW)'CAMLOPT -shared -o $@' - $(HIDE)$(TIMER) $(CAMLOPTLINK) $(CAMLDEBUG) $(CAMLFLAGS) $(FINDLIBPKGS) \ - -shared -o $@ $< - -$(MLPACKFILES:.mlpack=.cmxa): %.cmxa: %.cmx | %.mlpack - $(SHOW)'CAMLOPT -a -o $@' - $(HIDE)$(TIMER) $(CAMLOPTLINK) $(CAMLDEBUG) $(CAMLFLAGS) $(FINDLIBPKGS) -a -o $@ $< - -$(MLPACKFILES:.mlpack=.cma): %.cma: %.cmo | %.mlpack - $(SHOW)'CAMLC -a -o $@' - $(HIDE)$(TIMER) $(CAMLLINK) $(CAMLDEBUG) $(CAMLFLAGS) $(FINDLIBPKGS) -a -o $@ $^ - -$(MLPACKFILES:.mlpack=.cmo): %.cmo: | %.mlpack - $(SHOW)'CAMLC -pack -o $@' - $(HIDE)$(TIMER) $(CAMLLINK) $(CAMLDEBUG) $(CAMLFLAGS) $(FINDLIBPKGS) -pack -o $@ $^ - -$(MLPACKFILES:.mlpack=.cmx): %.cmx: | %.mlpack - $(SHOW)'CAMLOPT -pack -o $@' - $(HIDE)$(TIMER) $(CAMLOPTLINK) $(CAMLDEBUG) $(CAMLFLAGS) $(FINDLIBPKGS) -pack -o $@ $^ - -# This rule is for _CoqProject with no .mllib nor .mlpack -$(filter-out $(MLLIBFILES:.mllib=.cmxs) $(MLPACKFILES:.mlpack=.cmxs) $(addsuffix .cmxs,$(PACKEDFILES)) $(addsuffix .cmxs,$(LIBEDFILES)),$(MLFILES:.ml=.cmxs) $(MLGFILES:.mlg=.cmxs)): %.cmxs: %.cmx - $(SHOW)'[deprecated,use-mllib-or-mlpack] CAMLOPT -shared -o $@' - $(HIDE)$(TIMER) $(CAMLOPTLINK) $(CAMLDEBUG) $(CAMLFLAGS) $(FINDLIBPKGS) \ - -shared -o $@ $< - -ifneq (,$(TIMING)) -TIMING_EXTRA = > $<.$(TIMING_EXT) -else -TIMING_EXTRA = -endif - -# can't make -# https://www.gnu.org/software/make/manual/make.html#Static-Pattern -# work with multiple target rules -# so use eval in a loop instead -# with grouped targets https://www.gnu.org/software/make/manual/make.html#Multiple-Targets -# if available (GNU Make >= 4.3) -ifneq (,$(filter grouped-target,$(.FEATURES))) -define globvorule= - -# take care to $$ variables using $< etc - $(1).vo $(1).glob &: $(1).v | $(VDFILE) - $(SHOW)COQC $(1).v - $(HIDE)$$(TIMER) $(COQC) $(COQDEBUG) $(TIMING_ARG) $(COQFLAGS) $(COQLIBS) $(1).v $$(TIMING_EXTRA) -ifeq ($(COQDONATIVE), "yes") - $(SHOW)COQNATIVE $(1).vo - $(HIDE)$(call TIMER,$(1).vo.native) $(COQNATIVE) $(COQLIBS) $(1).vo -endif - -endef -else - -$(VOFILES): %.vo: %.v | $(VDFILE) - $(SHOW)COQC $< - $(HIDE)$(TIMER) $(COQC) $(COQDEBUG) $(TIMING_ARG) $(COQFLAGS) $(COQLIBS) $< $(TIMING_EXTRA) -ifeq ($(COQDONATIVE), "yes") - $(SHOW)COQNATIVE $@ - $(HIDE)$(call TIMER,$@.native) $(COQNATIVE) $(COQLIBS) $@ -endif - -# this is broken :( todo fix if we ever find a solution that doesn't need grouped targets -$(GLOBFILES): %.glob: %.v - $(SHOW)'COQC $< (for .glob)' - $(HIDE)$(TIMER) $(COQC) $(COQDEBUG) $(COQFLAGS) $(COQLIBS) $< - -endif - -$(foreach vfile,$(VFILES:.v=),$(eval $(call globvorule,$(vfile)))) - -$(VFILES:.v=.vio): %.vio: %.v - $(SHOW)COQC -vio $< - $(HIDE)$(TIMER) $(COQC) -vio $(COQDEBUG) $(COQFLAGS) $(COQLIBS) $< - -$(VFILES:.v=.vos): %.vos: %.v - $(SHOW)COQC -vos $< - $(HIDE)$(TIMER) $(COQC) -vos $(COQDEBUG) $(COQFLAGS) $(COQLIBS) $< - -$(VFILES:.v=.vok): %.vok: %.v - $(SHOW)COQC -vok $< - $(HIDE)$(TIMER) $(COQC) -vok $(COQDEBUG) $(COQFLAGS) $(COQLIBS) $< - -$(addsuffix .timing.diff,$(VFILES)): %.timing.diff : %.before-timing %.after-timing - $(SHOW)PYTHON TIMING-DIFF $*.{before,after}-timing - $(HIDE)$(MAKE) --no-print-directory -f "$(SELF)" print-pretty-single-time-diff BEFORE=$*.before-timing AFTER=$*.after-timing TIME_OF_PRETTY_BUILD_FILE="$@" - -$(BEAUTYFILES): %.v.beautified: %.v - $(SHOW)'BEAUTIFY $<' - $(HIDE)$(TIMER) $(COQC) $(COQDEBUG) $(COQFLAGS) $(COQLIBS) -beautify $< - -$(TEXFILES): %.tex: %.v - $(SHOW)'COQDOC -latex $<' - $(HIDE)$(COQDOC) $(COQDOCFLAGS) -latex $< -o $@ - -$(GTEXFILES): %.g.tex: %.v - $(SHOW)'COQDOC -latex -g $<' - $(HIDE)$(COQDOC) $(COQDOCFLAGS) -latex -g $< -o $@ - -$(HTMLFILES): %.html: %.v %.glob - $(SHOW)'COQDOC -html $<' - $(HIDE)$(COQDOC) $(COQDOCFLAGS) -html $< -o $@ - -$(GHTMLFILES): %.g.html: %.v %.glob - $(SHOW)'COQDOC -html -g $<' - $(HIDE)$(COQDOC) $(COQDOCFLAGS) -html -g $< -o $@ - -# Dependency files ############################################################ - -ifndef MAKECMDGOALS - -include $(ALLDFILES) -else - ifneq ($(filter-out archclean clean cleanall printenv make-pretty-timed make-pretty-timed-before make-pretty-timed-after print-pretty-timed print-pretty-timed-diff print-pretty-single-time-diff,$(MAKECMDGOALS)),) - -include $(ALLDFILES) - endif -endif - -.SECONDARY: $(ALLDFILES) - -redir_if_ok = > "$@" || ( RV=$$?; rm -f "$@"; exit $$RV ) - -GENMLFILES:=$(MLGFILES:.mlg=.ml) -$(addsuffix .d,$(ALLSRCFILES)): $(GENMLFILES) - -$(addsuffix .d,$(MLIFILES)): %.mli.d: %.mli - $(SHOW)'CAMLDEP $<' - $(HIDE)$(CAMLDEP) $(OCAMLLIBS) "$<" $(redir_if_ok) - -$(addsuffix .d,$(MLGFILES)): %.mlg.d: %.ml - $(SHOW)'CAMLDEP $<' - $(HIDE)$(CAMLDEP) $(OCAMLLIBS) "$<" $(redir_if_ok) - -$(addsuffix .d,$(MLFILES)): %.ml.d: %.ml - $(SHOW)'CAMLDEP $<' - $(HIDE)$(CAMLDEP) $(OCAMLLIBS) "$<" $(redir_if_ok) - -$(addsuffix .d,$(MLLIBFILES)): %.mllib.d: %.mllib - $(SHOW)'OCAMLLIBDEP $<' - $(HIDE)$(OCAMLLIBDEP) -c $(OCAMLLIBS) "$<" $(redir_if_ok) - -$(addsuffix .d,$(MLPACKFILES)): %.mlpack.d: %.mlpack - $(SHOW)'OCAMLLIBDEP $<' - $(HIDE)$(OCAMLLIBDEP) -c $(OCAMLLIBS) "$<" $(redir_if_ok) - -# If this makefile is created using a _CoqProject we have coqdep get -# options from it. This avoids argument length limits for pathological -# projects. Note that extra options might be on the command line. -VDFILE_FLAGS:=$(if _CoqProject,-f _CoqProject,) $(CMDLINE_COQLIBS) $(CMDLINE_VFILES) - -$(VDFILE): _CoqProject $(VFILES) - $(SHOW)'COQDEP VFILES' - $(HIDE)$(COQDEP) $(if $(strip $(METAFILE)),-m "$(METAFILE)") -vos -dyndep var $(VDFILE_FLAGS) $(redir_if_ok) - -# Misc ######################################################################## - -byte: - $(HIDE)$(MAKE) all "OPT:=-byte" -f "$(SELF)" -.PHONY: byte - -opt: - $(HIDE)$(MAKE) all "OPT:=-opt" -f "$(SELF)" -.PHONY: opt - -# This is deprecated. To extend this makefile use -# extension points and CoqMakefile.local -printenv:: - $(warning printenv is deprecated) - $(warning write extensions in CoqMakefile.local or include CoqMakefile.conf) - @echo 'COQLIB = $(COQLIB)' - @echo 'COQCORELIB = $(COQCORELIB)' - @echo 'DOCDIR = $(DOCDIR)' - @echo 'OCAMLFIND = $(OCAMLFIND)' - @echo 'HASNATDYNLINK = $(HASNATDYNLINK)' - @echo 'SRC_SUBDIRS = $(SRC_SUBDIRS)' - @echo 'COQ_SRC_SUBDIRS = $(COQ_SRC_SUBDIRS)' - @echo 'COQCORE_SRC_SUBDIRS = $(COQCORE_SRC_SUBDIRS)' - @echo 'OCAMLFIND = $(OCAMLFIND)' - @echo 'PP = $(PP)' - @echo 'COQFLAGS = $(COQFLAGS)' - @echo 'COQLIB = $(COQLIBS)' - @echo 'COQLIBINSTALL = $(COQLIBINSTALL)' - @echo 'COQDOCINSTALL = $(COQDOCINSTALL)' -.PHONY: printenv - -# Generate a .merlin file. If you need to append directives to this -# file you can extend the merlin-hook target in CoqMakefile.local -.merlin: - $(SHOW)'FILL .merlin' - $(HIDE)echo 'FLG $(COQMF_CAMLFLAGS)' > .merlin - $(HIDE)echo 'B $(COQCORELIB)' >> .merlin - $(HIDE)echo 'S $(COQCORELIB)' >> .merlin - $(HIDE)$(foreach d,$(COQCORE_SRC_SUBDIRS), \ - echo 'B $(COQCORELIB)$(d)' >> .merlin;) - $(HIDE)$(foreach d,$(COQ_SRC_SUBDIRS), \ - echo 'S $(COQLIB)$(d)' >> .merlin;) - $(HIDE)$(foreach d,$(SRC_SUBDIRS), echo 'B $(d)' >> .merlin;) - $(HIDE)$(foreach d,$(SRC_SUBDIRS), echo 'S $(d)' >> .merlin;) - $(HIDE)$(MAKE) merlin-hook -f "$(SELF)" -.PHONY: merlin - -merlin-hook:: - @# Extension point -.PHONY: merlin-hook - -# prints all variables -debug: - $(foreach v,\ - $(sort $(filter-out $(INITIAL_VARS) INITIAL_VARS,\ - $(.VARIABLES))),\ - $(info $(v) = $($(v)))) -.PHONY: debug - -.DEFAULT_GOAL := all - -# Users can create CoqMakefile.local-late to hook into double-colon rules -# or add other needed Makefile code, using defined -# variables if necessary. --include CoqMakefile.local-late - -# Local Variables: -# mode: makefile-gmake -# End: diff --git a/CoqOfPython/ethereum/arrow_glacier/bloom.v b/CoqOfPython/ethereum/arrow_glacier/bloom.v index 04b5d9f..04650ff 100644 --- a/CoqOfPython/ethereum/arrow_glacier/bloom.v +++ b/CoqOfPython/ethereum/arrow_glacier/bloom.v @@ -72,10 +72,7 @@ Definition add_to_bloom : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |):BinOp.add (| - M.get_name (| globals, "idx" |), - Constant.int 2 - |) |) + M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |) |) ], make_dict [] |), @@ -160,5 +157,4 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/fork.v b/CoqOfPython/ethereum/arrow_glacier/fork.v new file mode 100644 index 0000000..df8d355 --- /dev/null +++ b/CoqOfPython/ethereum/arrow_glacier/fork.v @@ -0,0 +1,2385 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Specification +^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Entry point for the Ethereum specification. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". + +Require ethereum.crypto.elliptic_curve. +Axiom ethereum_crypto_elliptic_curve_SECP256K1N : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.ethash. +Axiom ethereum_ethash_dataset_size : + IsGlobalAlias globals ethereum.ethash.globals "dataset_size". +Axiom ethereum_ethash_generate_cache : + IsGlobalAlias globals ethereum.ethash.globals "generate_cache". +Axiom ethereum_ethash_hashimoto_light : + IsGlobalAlias globals ethereum.ethash.globals "hashimoto_light". + +Require ethereum.exceptions. +Axiom ethereum_exceptions_InvalidBlock : + IsGlobalAlias globals ethereum.exceptions.globals "InvalidBlock". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U64 : + IsGlobalAlias globals base_types.globals "U64". +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_U256_CEIL_VALUE : + IsGlobalAlias globals base_types.globals "U256_CEIL_VALUE". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". + +Require __init__. +Axiom __init___vm : + IsGlobalAlias globals __init__.globals "vm". + +Require blocks. +Axiom blocks_Block : + IsGlobalAlias globals blocks.globals "Block". +Axiom blocks_Header : + IsGlobalAlias globals blocks.globals "Header". +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". +Axiom blocks_Receipt : + IsGlobalAlias globals blocks.globals "Receipt". + +Require bloom. +Axiom bloom_logs_bloom : + IsGlobalAlias globals bloom.globals "logs_bloom". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Require state. +Axiom state_State : + IsGlobalAlias globals state.globals "State". +Axiom state_account_exists_and_is_empty : + IsGlobalAlias globals state.globals "account_exists_and_is_empty". +Axiom state_create_ether : + IsGlobalAlias globals state.globals "create_ether". +Axiom state_destroy_account : + IsGlobalAlias globals state.globals "destroy_account". +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". +Axiom state_increment_nonce : + IsGlobalAlias globals state.globals "increment_nonce". +Axiom state_set_account_balance : + IsGlobalAlias globals state.globals "set_account_balance". +Axiom state_state_root : + IsGlobalAlias globals state.globals "state_root". + +Require transactions. +Axiom transactions_TX_ACCESS_LIST_ADDRESS_COST : + IsGlobalAlias globals transactions.globals "TX_ACCESS_LIST_ADDRESS_COST". +Axiom transactions_TX_ACCESS_LIST_STORAGE_KEY_COST : + IsGlobalAlias globals transactions.globals "TX_ACCESS_LIST_STORAGE_KEY_COST". +Axiom transactions_TX_BASE_COST : + IsGlobalAlias globals transactions.globals "TX_BASE_COST". +Axiom transactions_TX_CREATE_COST : + IsGlobalAlias globals transactions.globals "TX_CREATE_COST". +Axiom transactions_TX_DATA_COST_PER_NON_ZERO : + IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_NON_ZERO". +Axiom transactions_TX_DATA_COST_PER_ZERO : + IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_ZERO". +Axiom transactions_AccessListTransaction : + IsGlobalAlias globals transactions.globals "AccessListTransaction". +Axiom transactions_FeeMarketTransaction : + IsGlobalAlias globals transactions.globals "FeeMarketTransaction". +Axiom transactions_LegacyTransaction : + IsGlobalAlias globals transactions.globals "LegacyTransaction". +Axiom transactions_Transaction : + IsGlobalAlias globals transactions.globals "Transaction". +Axiom transactions_decode_transaction : + IsGlobalAlias globals transactions.globals "decode_transaction". +Axiom transactions_encode_transaction : + IsGlobalAlias globals transactions.globals "encode_transaction". + +Require trie. +Axiom trie_Trie : + IsGlobalAlias globals trie.globals "Trie". +Axiom trie_root : + IsGlobalAlias globals trie.globals "root". +Axiom trie_trie_set : + IsGlobalAlias globals trie.globals "trie_set". + +Require utils.message. +Axiom utils_message_prepare_message : + IsGlobalAlias globals utils.message.globals "prepare_message". + +Require vm.interpreter. +Axiom vm_interpreter_process_message_call : + IsGlobalAlias globals vm.interpreter.globals "process_message_call". + +Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mult (| + Constant.int 2, + BinOp.pow (| + Constant.int 10, + Constant.int 18 + |) + |) + ], + make_dict [] + |) +)). + +Definition BASE_FEE_MAX_CHANGE_DENOMINATOR : Value.t := M.run ltac:(M.monadic ( + Constant.int 8 +)). + +Definition ELASTICITY_MULTIPLIER : Value.t := M.run ltac:(M.monadic ( + Constant.int 2 +)). + +Definition GAS_LIMIT_ADJUSTMENT_FACTOR : Value.t := M.run ltac:(M.monadic ( + Constant.int 1024 +)). + +Definition GAS_LIMIT_MINIMUM : Value.t := M.run ltac:(M.monadic ( + Constant.int 5000 +)). + +Definition MINIMUM_DIFFICULTY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 131072 + ], + make_dict [] + |) +)). + +Definition MAX_OMMER_DEPTH : Value.t := M.run ltac:(M.monadic ( + Constant.int 6 +)). + +Definition BOMB_DELAY_BLOCKS : Value.t := M.run ltac:(M.monadic ( + Constant.int 10700000 +)). + +Definition EMPTY_OMMER_HASH : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_list [] + ], + make_dict [] + |) + ], + make_dict [] + |) +)). + +Definition BlockChain : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition apply_fork : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "old" ] |) in + let _ := Constant.str " + Transforms the state from the previous hard fork (`old`) into the block + chain object for this hard fork and returns it. + + When forks need to implement an irregular state transition, this function + is used to handle the irregularity. See the :ref:`DAO Fork ` for + an example. + + Parameters + ---------- + old : + Previous block chain object. + + Returns + ------- + new : `BlockChain` + Upgraded block chain object for this hard fork. + " in + let _ := M.return_ (| + M.get_name (| globals, "old" |) + M.pure Constant.None_)). + +Definition get_last_256_block_hashes : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "chain" ] |) in + let _ := Constant.str " + Obtain the list of hashes of the previous 256 blocks in order of + increasing block number. + + This function will return less hashes for the first 256 blocks. + + The ``BLOCKHASH`` opcode needs to access the latest hashes on the chain, + therefore this function retrieves them. + + Parameters + ---------- + chain : + History and current state. + + Returns + ------- + recent_block_hashes : `List[Hash32]` + Hashes of the recent 256 blocks in order of increasing block number. + " in + let recent_blocks := + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |) |) in + let _ := + M.pure Constant.None_ + )) |) in + let recent_block_hashes := + make_list [] in + For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_blocks" |) do + let prev_block_hash := + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), + make_list [ + M.get_name (| globals, "prev_block_hash" |) + ], + make_dict [] + |) in + EndFor. + let most_recent_block_hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_field (| M.get_subscript (| M.get_name (| globals, "recent_blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), + make_list [ + M.get_name (| globals, "most_recent_block_hash" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "recent_block_hashes" |) + M.pure Constant.None_)). + +Definition state_transition : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "chain"; "block" ] |) in + let _ := Constant.str " + Attempts to apply a block to an existing block chain. + + All parts of the block's contents need to be verified before being added + to the chain. Blocks are verified by ensuring that the contents of the + block make logical sense with the contents of the parent block. The + information in the block's header must also match the corresponding + information in the block. + + To implement Ethereum, in theory clients are only required to store the + most recent 255 blocks of the chain since as far as execution is + concerned, only those blocks are accessed. Practically, however, clients + should store more blocks to handle reorgs. + + Parameters + ---------- + chain : + History and current state. + block : + Block to apply to `chain`. + " in + let parent_header := + M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) in + let _ := M.call (| + M.get_name (| globals, "validate_header" |), + make_list [ + M.get_field (| M.get_name (| globals, "block" |), "header" |); + M.get_name (| globals, "parent_header" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "validate_ommers" |), + make_list [ + M.get_field (| M.get_name (| globals, "block" |), "ommers" |); + M.get_field (| M.get_name (| globals, "block" |), "header" |); + M.get_name (| globals, "chain" |) + ], + make_dict [] + |) in + let apply_body_output := + M.call (| + M.get_name (| globals, "apply_body" |), + make_list [ + M.get_field (| M.get_name (| globals, "chain" |), "state" |); + M.call (| + M.get_name (| globals, "get_last_256_block_hashes" |), + make_list [ + M.get_name (| globals, "chain" |) + ], + make_dict [] + |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "coinbase" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "number" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "base_fee_per_gas" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "gas_limit" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "timestamp" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "difficulty" |); + M.get_field (| M.get_name (| globals, "block" |), "transactions" |); + M.get_field (| M.get_name (| globals, "block" |), "ommers" |); + M.get_field (| M.get_name (| globals, "chain" |), "chain_id" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_gas_used" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "gas_used" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "transactions_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "transactions_root" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "state_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "state_root" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "receipt_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "receipt_root" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_logs_bloom" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "bloom" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), "append" |), + make_list [ + M.get_name (| globals, "block" |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "block_gas_limit"; "parent_gas_limit"; "parent_gas_used"; "parent_base_fee_per_gas" ] |) in + let _ := Constant.str " + Calculates the base fee per gas for the block. + + Parameters + ---------- + block_gas_limit : + Gas limit of the block for which the base fee is being calculated. + parent_gas_limit : + Gas limit of the parent block. + parent_gas_used : + Gas used in the parent block. + parent_base_fee_per_gas : + Base fee per gas of the parent block. + + Returns + ------- + base_fee_per_gas : `Uint` + Base fee per gas for the block. + " in + let parent_gas_target := + BinOp.floor_div (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "ELASTICITY_MULTIPLIER" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + M.call (| + M.get_name (| globals, "check_gas_limit" |), + make_list [ + M.get_name (| globals, "block_gas_limit" |); + M.get_name (| globals, "parent_gas_limit" |) + ], + make_dict [] + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := + let _ := + let gas_used_delta := + BinOp.sub (| + M.get_name (| globals, "parent_gas_target" |), + M.get_name (| globals, "parent_gas_used" |) + |) in + let parent_fee_gas_delta := + BinOp.mult (| + M.get_name (| globals, "parent_base_fee_per_gas" |), + M.get_name (| globals, "gas_used_delta" |) + |) in + let target_fee_gas_delta := + BinOp.floor_div (| + M.get_name (| globals, "parent_fee_gas_delta" |), + M.get_name (| globals, "parent_gas_target" |) + |) in + let base_fee_per_gas_delta := + BinOp.floor_div (| + M.get_name (| globals, "target_fee_gas_delta" |), + M.get_name (| globals, "BASE_FEE_MAX_CHANGE_DENOMINATOR" |) + |) in + let expected_base_fee_per_gas := + BinOp.sub (| + M.get_name (| globals, "parent_base_fee_per_gas" |), + M.get_name (| globals, "base_fee_per_gas_delta" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "expected_base_fee_per_gas" |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition validate_header : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header"; "parent_header" ] |) in + let _ := Constant.str " + Verifies a block header. + + In order to consider a block's header valid, the logic for the + quantities in the header should match the logic for the block itself. + For example the header timestamp should be greater than the block's parent + timestamp because the block was created *after* the parent block. + Additionally, the block's number should be directly following the parent + block's number since it is the next block in the sequence. + + Parameters + ---------- + header : + Header to check for correctness. + parent_header : + Parent Header of the header to check for correctness + " in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "header" |), "gas_used" |), + M.get_field (| M.get_name (| globals, "header" |), "gas_limit" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let expected_base_fee_per_gas := + M.call (| + M.get_name (| globals, "calculate_base_fee_per_gas" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "gas_limit" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "gas_limit" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "gas_used" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "base_fee_per_gas" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_name (| globals, "expected_base_fee_per_gas" |), + M.get_field (| M.get_name (| globals, "header" |), "base_fee_per_gas" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let parent_has_ommers := + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "parent_header" |), "ommers_hash" |), + M.get_name (| globals, "EMPTY_OMMER_HASH" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt (| + M.get_field (| M.get_name (| globals, "header" |), "timestamp" |), + M.get_field (| M.get_name (| globals, "parent_header" |), "timestamp" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "number" |), + BinOp.add (| + M.get_field (| M.get_name (| globals, "parent_header" |), "number" |), + Constant.int 1 + |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) + ], + make_dict [] + |), + Constant.int 32 + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let block_difficulty := + M.call (| + M.get_name (| globals, "calculate_block_difficulty" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "number" |); + M.get_field (| M.get_name (| globals, "header" |), "timestamp" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "timestamp" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "difficulty" |); + M.get_name (| globals, "parent_has_ommers" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "difficulty" |), + M.get_name (| globals, "block_difficulty" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let block_parent_hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "parent_header" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |), + M.get_name (| globals, "block_parent_hash" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "validate_proof_of_work" |), + make_list [ + M.get_name (| globals, "header" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header" ] |) in + let _ := Constant.str " + Generate rlp hash of the header which is to be used for Proof-of-Work + verification. + + In other words, the PoW artefacts `mix_digest` and `nonce` are ignored + while calculating this hash. + + A particular PoW is valid for a single hash, that hash is computed by + this function. The `nonce` and `mix_digest` are omitted from this hash + because they are being changed by miners in their search for a sufficient + proof-of-work. + + Parameters + ---------- + header : + The header object for which the hash is to be generated. + + Returns + ------- + hash : `Hash32` + The PoW valid rlp hash of the passed in header. + " in + let header_data_without_pow_artefacts := + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |); + M.get_field (| M.get_name (| globals, "header" |), "ommers_hash" |); + M.get_field (| M.get_name (| globals, "header" |), "coinbase" |); + M.get_field (| M.get_name (| globals, "header" |), "state_root" |); + M.get_field (| M.get_name (| globals, "header" |), "transactions_root" |); + M.get_field (| M.get_name (| globals, "header" |), "receipt_root" |); + M.get_field (| M.get_name (| globals, "header" |), "bloom" |); + M.get_field (| M.get_name (| globals, "header" |), "difficulty" |); + M.get_field (| M.get_name (| globals, "header" |), "number" |); + M.get_field (| M.get_name (| globals, "header" |), "gas_limit" |); + M.get_field (| M.get_name (| globals, "header" |), "gas_used" |); + M.get_field (| M.get_name (| globals, "header" |), "timestamp" |); + M.get_field (| M.get_name (| globals, "header" |), "extra_data" |); + M.get_field (| M.get_name (| globals, "header" |), "base_fee_per_gas" |) + ] in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "header_data_without_pow_artefacts" |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition validate_proof_of_work : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header" ] |) in + let _ := Constant.str " + Validates the Proof of Work constraints. + + In order to verify that a miner's proof-of-work is valid for a block, a + ``mix-digest`` and ``result`` are calculated using the ``hashimoto_light`` + hash function. The mix digest is a hash of the header and the nonce that + is passed through and it confirms whether or not proof-of-work was done + on the correct block. The result is the actual hash value of the block. + + Parameters + ---------- + header : + Header of interest. + " in + let header_hash := + M.call (| + M.get_name (| globals, "generate_header_hash_for_pow" |), + make_list [ + M.get_name (| globals, "header" |) + ], + make_dict [] + |) in + let cache := + M.call (| + M.get_name (| globals, "generate_cache" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "number" |) + ], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "mix_digest" |); M.get_name (| globals, "result" |) ], + M.call (| + M.get_name (| globals, "hashimoto_light" |), + make_list [ + M.get_name (| globals, "header_hash" |); + M.get_field (| M.get_name (| globals, "header" |), "nonce" |); + M.get_name (| globals, "cache" |); + M.call (| + M.get_name (| globals, "dataset_size" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "number" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_name (| globals, "mix_digest" |), + M.get_field (| M.get_name (| globals, "header" |), "mix_digest" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "result" |) + ], + make_dict [] + |), + BinOp.floor_div (| + M.get_name (| globals, "U256_CEIL_VALUE" |), + M.get_field (| M.get_name (| globals, "header" |), "difficulty" |) + |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition check_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx"; "base_fee_per_gas"; "gas_available"; "chain_id" ] |) in + let _ := Constant.str " + Check if the transaction is includable in the block. + + Parameters + ---------- + tx : + The transaction. + base_fee_per_gas : + The block base fee. + gas_available : + The gas remaining in the block. + chain_id : + The ID of the current chain. + + Returns + ------- + sender_address : + The sender of the transaction. + effective_gas_price : + The price to charge for gas when the transaction is executed. + + Raises + ------ + InvalidBlock : + If the transaction is not includable. + " in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_name (| globals, "gas_available" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let sender_address := + M.call (| + M.get_name (| globals, "recover_sender" |), + make_list [ + M.get_name (| globals, "chain_id" |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt_e (| + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |), + M.get_name (| globals, "base_fee_per_gas" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let effective_gas_price := + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + make_tuple [ M.get_name (| globals, "sender_address" |); M.get_name (| globals, "effective_gas_price" |) ] + M.pure Constant.None_)). + +Definition make_receipt : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx"; "error"; "cumulative_gas_used"; "logs" ] |) in + let _ := Constant.str " + Make the receipt for a transaction that was executed. + + Parameters + ---------- + tx : + The executed transaction. + error : + Error in the top level frame of the transaction, if any. + cumulative_gas_used : + The total gas used so far in the block after the transaction was + executed. + logs : + The logs produced by the transaction. + + Returns + ------- + receipt : + The receipt for the transaction. + " in + let receipt := + M.call (| + M.get_name (| globals, "Receipt" |), + make_list [], + make_dict [] + |) in + let _ := + let _ := + let _ := M.return_ (| + M.get_name (| globals, "receipt" |) + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition ApplyBodyOutput : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition apply_body : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "block_hashes"; "coinbase"; "block_number"; "base_fee_per_gas"; "block_gas_limit"; "block_time"; "block_difficulty"; "transactions"; "ommers"; "chain_id" ] |) in + let _ := Constant.str " + Executes a block. + + Many of the contents of a block are stored in data structures called + tries. There is a transactions trie which is similar to a ledger of the + transactions stored in the current block. There is also a receipts trie + which stores the results of executing a transaction, like the post state + and gas used. This function creates and executes the block that is to be + added to the chain. + + Parameters + ---------- + state : + Current account state. + block_hashes : + List of hashes of the previous 256 blocks in the order of + increasing block number. + coinbase : + Address of account which receives block reward and transaction fees. + block_number : + Position of the block within the chain. + base_fee_per_gas : + Base fee per gas of within the block. + block_gas_limit : + Initial amount of gas available for execution in this block. + block_time : + Time the block was produced, measured in seconds since the epoch. + block_difficulty : + Difficulty of the block. + transactions : + Transactions included in the block. + ommers : + Headers of ancestor blocks which are not direct parents (formerly + uncles.) + chain_id : + ID of the executing chain. + + Returns + ------- + apply_body_output : `ApplyBodyOutput` + Output of applying the block body to the state. + " in + let gas_available := + M.get_name (| globals, "block_gas_limit" |) in +(* At stmt: unsupported node type: AnnAssign *) +(* At stmt: unsupported node type: AnnAssign *) +(* At stmt: unsupported node type: AnnAssign *) + For make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "tx" |) ] in M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.call (| + M.get_name (| globals, "map" |), + make_list [ + M.get_name (| globals, "decode_transaction" |); + M.get_name (| globals, "transactions" |) + ], + make_dict [] + |) + ], + make_dict [] + |) do + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "transactions_trie" |); + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "i" |) + ], + make_dict [] + |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "encode_transaction" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "sender_address" |); M.get_name (| globals, "effective_gas_price" |) ], + M.call (| + M.get_name (| globals, "check_transaction" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "base_fee_per_gas" |); + M.get_name (| globals, "gas_available" |); + M.get_name (| globals, "chain_id" |) + ], + make_dict [] + |) + |) in + let env := + M.call (| + M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |); M.get_name (| globals, "error" |) ], + M.call (| + M.get_name (| globals, "process_transaction" |), + make_list [ + M.get_name (| globals, "env" |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) in + let gas_available := BinOp.sub + M.get_name (| globals, "gas_used" |) + M.get_name (| globals, "gas_used" |) in + let receipt := + M.call (| + M.get_name (| globals, "make_receipt" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "error" |); + BinOp.sub (| + M.get_name (| globals, "block_gas_limit" |), + M.get_name (| globals, "gas_available" |) + |); + M.get_name (| globals, "logs" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "receipts_trie" |); + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "i" |) + ], + make_dict [] + |) + ], + make_dict [] + |); + M.get_name (| globals, "receipt" |) + ], + make_dict [] + |) in + let block_logs := BinOp.add + M.get_name (| globals, "logs" |) + M.get_name (| globals, "logs" |) in + EndFor. + let _ := M.call (| + M.get_name (| globals, "pay_rewards" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "block_number" |); + M.get_name (| globals, "coinbase" |); + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |) in + let block_gas_used := + BinOp.sub (| + M.get_name (| globals, "block_gas_limit" |), + M.get_name (| globals, "gas_available" |) + |) in + let block_logs_bloom := + M.call (| + M.get_name (| globals, "logs_bloom" |), + make_list [ + M.get_name (| globals, "block_logs" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ApplyBodyOutput" |), + make_list [ + M.get_name (| globals, "block_gas_used" |); + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_name (| globals, "transactions_trie" |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_name (| globals, "receipts_trie" |) + ], + make_dict [] + |); + M.get_name (| globals, "block_logs_bloom" |); + M.call (| + M.get_name (| globals, "state_root" |), + make_list [ + M.get_name (| globals, "state" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition validate_ommers : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "ommers"; "block_header"; "chain" ] |) in + let _ := Constant.str " + Validates the ommers mentioned in the block. + + An ommer block is a block that wasn't canonically added to the + blockchain because it wasn't validated as fast as the canonical block + but was mined at the same time. + + To be considered valid, the ommers must adhere to the rules defined in + the Ethereum protocol. The maximum amount of ommers is 2 per block and + there cannot be duplicate ommers in a block. Many of the other ommer + constraints are listed in the in-line comments of this function. + + Parameters + ---------- + ommers : + List of ommers mentioned in the current block. + block_header: + The header of current block. + chain : + History and current state. + " in + let block_hash := + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "block_header" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + M.get_field (| M.get_name (| globals, "block_header" |), "ommers_hash" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.and (| + Compare.lt_e (| + Constant.int 1, + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |), + ltac:(M.monadic ( + Compare.lt (| + M.get_field (| M.get_name (| globals, "ommer" |), "number" |), + M.get_field (| M.get_name (| globals, "block_header" |), "number" |) + |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let ommer_parent_header := + M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), BinOp.sub (| + UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) |), + Constant.int 1 + |) |), "header" |) in + let _ := M.call (| + M.get_name (| globals, "validate_header" |), + make_list [ + M.get_name (| globals, "ommer" |); + M.get_name (| globals, "ommer_parent_header" |) + ], + make_dict [] + |) in + EndFor. + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + Constant.int 2 + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let ommers_hashes := + (* At expr: unsupported node type: ListComp *) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers_hashes" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_name (| globals, "set" |), + make_list [ + M.get_name (| globals, "ommers_hashes" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let recent_canonical_blocks := + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| BinOp.add (| + M.get_name (| globals, "MAX_OMMER_DEPTH" |), + Constant.int 1 + |) |) |) in + let recent_canonical_block_hashes := + (* At expr: unsupported node type: SetComp *) in +(* At stmt: unsupported node type: AnnAssign *) + For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_canonical_blocks" |) do + let recent_ommers_hashes := + M.call (| + M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), + make_list [ + (* At expr: unsupported node type: SetComp *) + ], + make_dict [] + |) in + EndFor. + For make_tuple [ M.get_name (| globals, "ommer_index" |); M.get_name (| globals, "ommer" |) ] in M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |) do + let ommer_hash := + M.get_subscript (| M.get_name (| globals, "ommers_hashes" |), M.get_name (| globals, "ommer_index" |) |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_eq (| + M.get_name (| globals, "ommer_hash" |), + M.get_name (| globals, "block_hash" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_in (| + M.get_name (| globals, "ommer_hash" |), + M.get_name (| globals, "recent_canonical_block_hashes" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_in (| + M.get_name (| globals, "ommer_hash" |), + M.get_name (| globals, "recent_ommers_hashes" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let ommer_age := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.and (| + Compare.lt_e (| + Constant.int 1, + M.get_name (| globals, "ommer_age" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_name (| globals, "ommer_age" |), + M.get_name (| globals, "MAX_OMMER_DEPTH" |) + |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.in (| + M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), + M.get_name (| globals, "recent_canonical_block_hashes" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), + M.get_field (| M.get_name (| globals, "block_header" |), "parent_hash" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_)). + +Definition pay_rewards : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "block_number"; "coinbase"; "ommers" ] |) in + let _ := Constant.str " + Pay rewards to the block miner as well as the ommers miners. + + The miner of the canonical block is rewarded with the predetermined + block reward, ``BLOCK_REWARD``, plus a variable award based off of the + number of ommer blocks that were mined around the same time, and included + in the canonical block's header. An ommer block is a block that wasn't + added to the canonical blockchain because it wasn't validated as fast as + the accepted block but was mined at the same time. Although not all blocks + that are mined are added to the canonical chain, miners are still paid a + reward for their efforts. This reward is called an ommer reward and is + calculated based on the number associated with the ommer block that they + mined. + + Parameters + ---------- + state : + Current account state. + block_number : + Position of the block within the chain. + coinbase : + Address of account which receives block reward and transaction fees. + ommers : + List of ommers mentioned in the current block. + " in + let miner_reward := + BinOp.add (| + M.get_name (| globals, "BLOCK_REWARD" |), + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + BinOp.floor_div (| + M.get_name (| globals, "BLOCK_REWARD" |), + Constant.int 32 + |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "create_ether" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "coinbase" |); + M.get_name (| globals, "miner_reward" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do + let ommer_age := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "block_number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) + ], + make_dict [] + |) in + let ommer_miner_reward := + BinOp.floor_div (| + BinOp.mult (| + BinOp.sub (| + Constant.int 8, + M.get_name (| globals, "ommer_age" |) + |), + M.get_name (| globals, "BLOCK_REWARD" |) + |), + Constant.int 8 + |) in + let _ := M.call (| + M.get_name (| globals, "create_ether" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_field (| M.get_name (| globals, "ommer" |), "coinbase" |); + M.get_name (| globals, "ommer_miner_reward" |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_)). + +Definition process_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "env"; "tx" ] |) in + let _ := Constant.str " + Execute a transaction against the provided environment. + + This function processes the actions needed to execute a transaction. + It decrements the sender's account after calculating the gas fee and + refunds them the proper amount after execution. Calling contracts, + deploying code, and incrementing nonces are all examples of actions that + happen within this function or from a call made within this function. + + Accounts that are marked for deletion are processed and destroyed after + execution. + + Parameters + ---------- + env : + Environment for the Ethereum Virtual Machine. + tx : + Transaction to execute. + + Returns + ------- + gas_left : `ethereum.base_types.U256` + Remaining gas after execution. + logs : `Tuple[ethereum.blocks.Log, ...]` + Logs generated during execution. + " in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + M.call (| + M.get_name (| globals, "validate_transaction" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let sender := + M.get_field (| M.get_name (| globals, "env" |), "origin" |) in + let sender_account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |) in + let _ := + let max_gas_fee := + BinOp.mult (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "sender_account" |), "nonce" |), + M.get_field (| M.get_name (| globals, "tx" |), "nonce" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt_e (| + M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), + BinOp.add (| + M.get_name (| globals, "max_gas_fee" |), + M.get_field (| M.get_name (| globals, "tx" |), "value" |) + |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "sender_account" |), "code" |), + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [], + make_dict [] + |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let effective_gas_fee := + BinOp.mult (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "env" |), "gas_price" |) + |) in + let gas := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.call (| + M.get_name (| globals, "calculate_intrinsic_cost" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) in + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |) in + let sender_balance_after_gas_fee := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), + M.get_name (| globals, "effective_gas_fee" |) + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |); + M.get_name (| globals, "sender_balance_after_gas_fee" |) + ], + make_dict [] + |) in + let preaccessed_addresses := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let preaccessed_storage_keys := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let message := + M.call (| + M.get_name (| globals, "prepare_message" |), + make_list [ + M.get_name (| globals, "sender" |); + M.get_field (| M.get_name (| globals, "tx" |), "to" |); + M.get_field (| M.get_name (| globals, "tx" |), "value" |); + M.get_field (| M.get_name (| globals, "tx" |), "data" |); + M.get_name (| globals, "gas" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let output := + M.call (| + M.get_name (| globals, "process_message_call" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let gas_used := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "output" |), "gas_left" |) + |) in + let gas_refund := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + BinOp.floor_div (| + M.get_name (| globals, "gas_used" |), + Constant.int 5 + |); + M.get_field (| M.get_name (| globals, "output" |), "refund_counter" |) + ], + make_dict [] + |) in + let gas_refund_amount := + BinOp.mult (| + BinOp.add (| + M.get_field (| M.get_name (| globals, "output" |), "gas_left" |), + M.get_name (| globals, "gas_refund" |) + |), + M.get_field (| M.get_name (| globals, "env" |), "gas_price" |) + |) in + let priority_fee_per_gas := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "env" |), "gas_price" |), + M.get_field (| M.get_name (| globals, "env" |), "base_fee_per_gas" |) + |) in + let transaction_fee := + BinOp.mult (| + BinOp.sub (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "output" |), "gas_left" |) + |), + M.get_name (| globals, "gas_refund" |) + |), + M.get_name (| globals, "priority_fee_per_gas" |) + |) in + let total_gas_used := + BinOp.sub (| + M.get_name (| globals, "gas_used" |), + M.get_name (| globals, "gas_refund" |) + |) in + let sender_balance_after_refund := + BinOp.add (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |), "balance" |), + M.get_name (| globals, "gas_refund_amount" |) + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |); + M.get_name (| globals, "sender_balance_after_refund" |) + ], + make_dict [] + |) in + let coinbase_balance_after_mining_fee := + BinOp.add (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |), "balance" |), + M.get_name (| globals, "transaction_fee" |) + |) in + let _ := + let _ := + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "accounts_to_delete" |) do + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + EndFor. + For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "touched_accounts" |) do + let _ := + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.return_ (| + make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |); M.get_field (| M.get_name (| globals, "output" |), "error" |) ] + M.pure Constant.None_)). + +Definition validate_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Verifies a transaction. + + The gas in a transaction gets used to pay for the intrinsic cost of + operations, therefore if there is insufficient gas then it would not + be possible to execute a transaction and it will be declared invalid. + + Additionally, the nonce of a transaction must not equal or exceed the + limit defined in `EIP-2681 `_. + In practice, defining the limit as ``2**64-1`` has no impact because + sending ``2**64-1`` transactions is improbable. It's not strictly + impossible though, ``2**64-1`` transactions is the entire capacity of the + Ethereum blockchain at 2022 gas limits for a little over 22 years. + + Parameters + ---------- + tx : + Transaction to validate. + + Returns + ------- + verified : `bool` + True if the transaction can be executed, or False otherwise. + " in + let _ := M.return_ (| + BoolOp.and (| + Compare.lt_e (| + M.call (| + M.get_name (| globals, "calculate_intrinsic_cost" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |), + M.get_field (| M.get_name (| globals, "tx" |), "gas" |) + |), + ltac:(M.monadic ( + Compare.lt (| + M.get_field (| M.get_name (| globals, "tx" |), "nonce" |), + BinOp.sub (| + BinOp.pow (| + Constant.int 2, + Constant.int 64 + |), + Constant.int 1 + |) + |) + )) + |) + M.pure Constant.None_)). + +Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Calculates the gas that is charged before execution is started. + + The intrinsic cost of the transaction is charged before execution has + begun. Functions/operations in the EVM cost money to execute so this + intrinsic cost is for the operations that need to be paid for as part of + the transaction. Data transfer, for example, is part of this intrinsic + cost. It costs ether to send data over the wire and that ether is + accounted for in the intrinsic cost calculated in this function. This + intrinsic cost must be calculated and paid for before execution in order + for all operations to be implemented. + + Parameters + ---------- + tx : + Transaction to compute the intrinsic cost of. + + Returns + ------- + verified : `ethereum.base_types.Uint` + The intrinsic cost of the transaction. + " in + let data_cost := + Constant.int 0 in + For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do + let _ := + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + M.pure Constant.None_ + )) |) in + EndFor. + let _ := + let create_cost := + Constant.int 0 in + M.pure Constant.None_ + )) |) in + let access_list_cost := + Constant.int 0 in + let _ := + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.add (| + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "TX_BASE_COST" |), + M.get_name (| globals, "data_cost" |) + |), + M.get_name (| globals, "create_cost" |) + |), + M.get_name (| globals, "access_list_cost" |) + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition recover_sender : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "chain_id"; "tx" ] |) in + let _ := Constant.str " + Extracts the sender address from a transaction. + + The v, r, and s values are the three parts that make up the signature + of a transaction. In order to recover the sender of a transaction the two + components needed are the signature (``v``, ``r``, and ``s``) and the + signing hash of the transaction. The sender's public key can be obtained + with these two values and therefore the sender address can be retrieved. + + Parameters + ---------- + tx : + Transaction of interest. + chain_id : + ID of the executing chain. + + Returns + ------- + sender : `ethereum.fork_types.Address` + The address of the account that signed the transaction. + " in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "r" |); M.get_name (| globals, "s" |) ], + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "r" |); M.get_field (| M.get_name (| globals, "tx" |), "s" |) ] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.and (| + Compare.lt (| + Constant.int 0, + M.get_name (| globals, "r" |) + |), + ltac:(M.monadic ( + Compare.lt (| + M.get_name (| globals, "r" |), + M.get_name (| globals, "SECP256K1N" |) + |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.and (| + Compare.lt (| + Constant.int 0, + M.get_name (| globals, "s" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_name (| globals, "s" |), + BinOp.floor_div (| + M.get_name (| globals, "SECP256K1N" |), + Constant.int 2 + |) + |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := + let _ := + let _ := + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_subscript (| M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), Constant.int 12 |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition signing_hash_pre155 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Compute the hash of a transaction used in a legacy (pre EIP 155) signature. + + Parameters + ---------- + tx : + Transaction of interest. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the transaction. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "nonce" |); M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |); M.get_field (| M.get_name (| globals, "tx" |), "gas" |); M.get_field (| M.get_name (| globals, "tx" |), "to" |); M.get_field (| M.get_name (| globals, "tx" |), "value" |); M.get_field (| M.get_name (| globals, "tx" |), "data" |) ] + ], + make_dict [] + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition signing_hash_155 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx"; "chain_id" ] |) in + let _ := Constant.str " + Compute the hash of a transaction used in a EIP 155 signature. + + Parameters + ---------- + tx : + Transaction of interest. + chain_id : + The id of the current chain. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the transaction. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "nonce" |); M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |); M.get_field (| M.get_name (| globals, "tx" |), "gas" |); M.get_field (| M.get_name (| globals, "tx" |), "to" |); M.get_field (| M.get_name (| globals, "tx" |), "value" |); M.get_field (| M.get_name (| globals, "tx" |), "data" |); M.get_name (| globals, "chain_id" |); M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) ] + ], + make_dict [] + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition signing_hash_2930 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Compute the hash of a transaction used in a EIP 2930 signature. + + Parameters + ---------- + tx : + Transaction of interest. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the transaction. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + BinOp.add (| + Constant.bytes "01", + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "chain_id" |); M.get_field (| M.get_name (| globals, "tx" |), "nonce" |); M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |); M.get_field (| M.get_name (| globals, "tx" |), "gas" |); M.get_field (| M.get_name (| globals, "tx" |), "to" |); M.get_field (| M.get_name (| globals, "tx" |), "value" |); M.get_field (| M.get_name (| globals, "tx" |), "data" |); M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) ] + ], + make_dict [] + |) + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition signing_hash_1559 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Compute the hash of a transaction used in a EIP 1559 signature. + + Parameters + ---------- + tx : + Transaction of interest. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the transaction. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + BinOp.add (| + Constant.bytes "02", + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "chain_id" |); M.get_field (| M.get_name (| globals, "tx" |), "nonce" |); M.get_field (| M.get_name (| globals, "tx" |), "max_priority_fee_per_gas" |); M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |); M.get_field (| M.get_name (| globals, "tx" |), "gas" |); M.get_field (| M.get_name (| globals, "tx" |), "to" |); M.get_field (| M.get_name (| globals, "tx" |), "value" |); M.get_field (| M.get_name (| globals, "tx" |), "data" |); M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) ] + ], + make_dict [] + |) + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition compute_header_hash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header" ] |) in + let _ := Constant.str " + Computes the hash of a block header. + + The header hash of a block is the canonical hash that is used to refer + to a specific block and completely distinguishes a block from another. + + ``keccak256`` is a function that produces a 256 bit hash of any input. + It also takes in any number of bytes as an input and produces a single + hash for them. A hash is a completely unique output for a single input. + So an input corresponds to one unique hash that can be used to identify + the input exactly. + + Prior to using the ``keccak256`` hash function, the header must be + encoded using the Recursive-Length Prefix. See :ref:`rlp`. + RLP encoding the header converts it into a space-efficient format that + allows for easy transfer of data between nodes. The purpose of RLP is to + encode arbitrarily nested arrays of binary data, and RLP is the primary + encoding method used to serialize objects in Ethereum's execution layer. + The only purpose of RLP is to encode structure; encoding specific data + types (e.g. strings, floats) is left up to higher-order protocols. + + Parameters + ---------- + header : + Header of interest. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the header. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "header" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition check_gas_limit : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "gas_limit"; "parent_gas_limit" ] |) in + let _ := Constant.str " + Validates the gas limit for a block. + + The bounds of the gas limit, ``max_adjustment_delta``, is set as the + quotient of the parent block's gas limit and the + ``GAS_LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is + passed through as a parameter is greater than or equal to the *sum* of + the parent's gas and the adjustment delta then the limit for gas is too + high and fails this function's check. Similarly, if the limit is less + than or equal to the *difference* of the parent's gas and the adjustment + delta *or* the predefined ``GAS_LIMIT_MINIMUM`` then this function's + check fails because the gas limit doesn't allow for a sufficient or + reasonable amount of gas to be used on a block. + + Parameters + ---------- + gas_limit : + Gas limit to validate. + + parent_gas_limit : + Gas limit of the parent block. + + Returns + ------- + check : `bool` + True if gas limit constraints are satisfied, False otherwise. + " in + let max_adjustment_delta := + BinOp.floor_div (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) + |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + Constant.bool true + M.pure Constant.None_)). + +Definition calculate_block_difficulty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "block_number"; "block_timestamp"; "parent_timestamp"; "parent_difficulty"; "parent_has_ommers" ] |) in + let _ := Constant.str " + Computes difficulty of a block using its header and parent header. + + The difficulty is determined by the time the block was created after its + parent. The ``offset`` is calculated using the parent block's difficulty, + ``parent_difficulty``, and the timestamp between blocks. This offset is + then added to the parent difficulty and is stored as the ``difficulty`` + variable. If the time between the block and its parent is too short, the + offset will result in a positive number thus making the sum of + ``parent_difficulty`` and ``offset`` to be a greater value in order to + avoid mass forking. But, if the time is long enough, then the offset + results in a negative value making the block less difficult than + its parent. + + The base standard for a block's difficulty is the predefined value + set for the genesis block since it has no parent. So, a block + can't be less difficult than the genesis block, therefore each block's + difficulty is set to the maximum value between the calculated + difficulty and the ``GENESIS_DIFFICULTY``. + + Parameters + ---------- + block_number : + Block number of the block. + block_timestamp : + Timestamp of the block. + parent_timestamp : + Timestamp of the parent block. + parent_difficulty : + difficulty of the parent block. + parent_has_ommers: + does the parent have ommers. + + Returns + ------- + difficulty : `ethereum.base_types.Uint` + Computed difficulty for a block. + " in + let offset := + BinOp.mult (| + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "parent_difficulty" |) + ], + make_dict [] + |), + Constant.int 2048 + |), + M.call (| + M.get_name (| globals, "max" |), + make_list [ + BinOp.sub (| + (* if *) +M.if_then_else (| + M.get_name (| globals, "parent_has_ommers" |), +(* then *) +ltac:(M.monadic ( +Constant.int 2, + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "block_timestamp" |), + M.get_name (| globals, "parent_timestamp" |) + |) + ], + make_dict [] + |), + Constant.int 9 + |) + |); + UnOp.sub (| Constant.int 99 |) + ], + make_dict [] + |) + |) in + let difficulty := + BinOp.add (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "parent_difficulty" |) + ], + make_dict [] + |), + M.get_name (| globals, "offset" |) + |) in + let num_bomb_periods := + BinOp.sub (| + BinOp.floor_div (| + BinOp.sub (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "block_number" |) + ], + make_dict [] + |), + M.get_name (| globals, "BOMB_DELAY_BLOCKS" |) + |), + Constant.int 100000 + |), + Constant.int 2 + |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "max" |), + make_list [ + M.get_name (| globals, "difficulty" |); + M.get_name (| globals, "MINIMUM_DIFFICULTY" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/fork_types.v b/CoqOfPython/ethereum/arrow_glacier/fork_types.v index d12953d..5c7dac3 100644 --- a/CoqOfPython/ethereum/arrow_glacier/fork_types.v +++ b/CoqOfPython/ethereum/arrow_glacier/fork_types.v @@ -98,5 +98,4 @@ Definition encode_account : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/state.v b/CoqOfPython/ethereum/arrow_glacier/state.v index 7b038e5..c3290a6 100644 --- a/CoqOfPython/ethereum/arrow_glacier/state.v +++ b/CoqOfPython/ethereum/arrow_glacier/state.v @@ -126,13 +126,7 @@ Definition begin_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) ], make_dict [] - |); {M.get_name (| globals, "k" |): M.call (| - M.get_name (| globals, "copy_trie" |), - make_list [ - M.get_name (| globals, "t" |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)} ] + |); (* At expr: unsupported node type: DictComp *) ] ], make_dict [] |) in @@ -155,19 +149,6 @@ Definition commit_transaction : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "clear" |), - make_list [], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -193,19 +174,6 @@ Definition rollback_transaction : Value.t -> Value.t -> M := |) |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "clear" |), - make_list [], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -242,27 +210,8 @@ Definition get_account : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "account" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "account" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_ACCOUNT" |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -297,7 +246,6 @@ Definition get_account_optional : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "account" |) - |) in M.pure Constant.None_)). Definition set_account : Value.t -> Value.t -> M := @@ -377,15 +325,6 @@ Definition destroy_storage : Value.t -> Value.t -> M := Address of account whose storage is to be deleted. " in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -448,23 +387,6 @@ Definition get_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let value := @@ -486,7 +408,6 @@ Definition get_storage : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "value" |) - |) in M.pure Constant.None_)). Definition set_storage : Value.t -> Value.t -> M := @@ -507,14 +428,17 @@ Definition set_storage : Value.t -> Value.t -> M := value : `U256` Value to set at the key. " in - let _ := M.assert (| Compare.is_not (| M.call (| - M.get_name (| globals, "trie_get" |), - make_list [ - M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), Constant.None_ |) |) in + let _ := M.assert (| Compare.is_not (| + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + Constant.None_ + |) |) in let trie := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), @@ -524,24 +448,6 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let trie := - M.call (| - M.get_name (| globals, "Trie" |), - make_list [], - make_dict [] - |) in - let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), - M.get_name (| globals, "trie" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -554,15 +460,6 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), {} |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -587,26 +484,8 @@ Definition storage_root : Value.t -> Value.t -> M := " in let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "root" |), - make_list [ - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_TRIE_ROOT" |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -637,7 +516,6 @@ Definition state_root : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition account_exists : Value.t -> Value.t -> M := @@ -659,15 +537,17 @@ Definition account_exists : Value.t -> Value.t -> M := True if account exists in the state trie, False otherwise " in let _ := M.return_ (| - Compare.is_not (| M.call (| - M.get_name (| globals, "get_account_optional" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), Constant.None_ |) - |) in + Compare.is_not (| + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + Constant.None_ + |) M.pure Constant.None_)). Definition account_has_code_or_nonce : Value.t -> Value.t -> M := @@ -700,18 +580,23 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := |) in let _ := M.return_ (| BoolOp.or (| - Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( - Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |) + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |) )) |) - |) in M.pure Constant.None_)). Definition is_account_empty : Value.t -> Value.t -> M := @@ -744,23 +629,31 @@ Definition is_account_empty : Value.t -> Value.t -> M := |) in let _ := M.return_ (| BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |), ltac:(M.monadic ( - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "balance" |), + Constant.int 0 + |) )) |) )) |) - |) in M.pure Constant.None_)). Definition account_exists_and_is_empty : Value.t -> Value.t -> M := @@ -794,28 +687,39 @@ Definition account_exists_and_is_empty : Value.t -> Value.t -> M := |) in let _ := M.return_ (| BoolOp.and (| - Compare.is_not (| M.get_name (| globals, "account" |), Constant.None_ |), + Compare.is_not (| + M.get_name (| globals, "account" |), + Constant.None_ + |), ltac:(M.monadic ( BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |), ltac:(M.monadic ( - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "balance" |), + Constant.int 0 + |) )) |) )) |) )) |) - |) in M.pure Constant.None_)). Definition is_account_alive : Value.t -> Value.t -> M := @@ -846,36 +750,33 @@ Definition is_account_alive : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "account" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.bool false - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| UnOp.not (| BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |), ltac:(M.monadic ( - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "balance" |), + Constant.int 0 + |) )) |) )) |) |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -983,30 +884,6 @@ Definition touch_account : Value.t -> Value.t -> M := The address of the account that need to initialised. " in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "account_exists" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "set_account" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |); - M.get_name (| globals, "EMPTY_ACCOUNT" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -1111,23 +988,6 @@ Definition get_storage_original : Value.t -> Value.t -> M := Key of the storage slot. " in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -1143,22 +1003,6 @@ Definition get_storage_original : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "original_account_trie" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let original_value := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let original_value := M.call (| M.get_name (| globals, "trie_get" |), @@ -1180,5 +1024,4 @@ Definition get_storage_original : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "original_value" |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/transactions.v b/CoqOfPython/ethereum/arrow_glacier/transactions.v index 56996d9..afa27ec 100644 --- a/CoqOfPython/ethereum/arrow_glacier/transactions.v +++ b/CoqOfPython/ethereum/arrow_glacier/transactions.v @@ -112,87 +112,15 @@ Definition encode_transaction : Value.t -> Value.t -> M := Encode a transaction. Needed because non-legacy transactions aren't RLP. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "LegacyTransaction" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "tx" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "AccessListTransaction" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - BinOp.add (| - (* At constant: unsupported node type: Constant *), - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "tx" |) - ], - make_dict [] - |) - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "FeeMarketTransaction" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - BinOp.add (| - (* At constant: unsupported node type: Constant *), - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "tx" |) - ], - make_dict [] - |) - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.call (| + let _ := M.raise (| Some(M.call (| M.get_name (| globals, "Exception" |), make_list [ (* At expr: unsupported node type: JoinedStr *) ], make_dict [] - |) |) in + |)) M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -208,67 +136,8 @@ Definition decode_transaction : Value.t -> Value.t -> M := Decode a transaction. Needed because non-legacy transactions aren't RLP. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "Bytes" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), Constant.int 1 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), - make_list [ - M.get_name (| globals, "AccessListTransaction" |); - M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 1:(* At expr: unsupported node type: NoneType *) |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), Constant.int 2 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), - make_list [ - M.get_name (| globals, "FeeMarketTransaction" |); - M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 1:(* At expr: unsupported node type: NoneType *) |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidBlock" |) |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "tx" |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/trie.v b/CoqOfPython/ethereum/arrow_glacier/trie.v index 7ef28ee..17d829e 100644 --- a/CoqOfPython/ethereum/arrow_glacier/trie.v +++ b/CoqOfPython/ethereum/arrow_glacier/trie.v @@ -202,96 +202,16 @@ Definition encode_internal_node : Value.t -> Value.t -> M := " in (* At stmt: unsupported node type: AnnAssign *) let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "node" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let unencoded := - (* At constant: unsupported node type: Constant *) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "LeafNode" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let unencoded := - make_tuple [ M.call (| - M.get_name (| globals, "nibble_list_to_compact" |), - make_list [ - M.get_field (| M.get_name (| globals, "node" |), "rest_of_key" |); - Constant.bool true - ], - make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "ExtensionNode" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let unencoded := - make_tuple [ M.call (| - M.get_name (| globals, "nibble_list_to_compact" |), - make_list [ - M.get_field (| M.get_name (| globals, "node" |), "key_segment" |); - Constant.bool false - ], - make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "BranchNode" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let unencoded := - BinOp.add (| - M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), - make_list [ - M.get_field (| M.get_name (| globals, "node" |), "value" |) - ] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.call (| + let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ (* At expr: unsupported node type: JoinedStr *) ], make_dict [] - |) |) in + |)) M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -309,23 +229,6 @@ Definition encode_internal_node : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "encoded" |) - ], - make_dict [] - |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "unencoded" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_name (| globals, "keccak256" |), @@ -334,7 +237,6 @@ Definition encode_internal_node : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -348,83 +250,8 @@ Definition encode_node : Value.t -> Value.t -> M := Currently mostly an unimplemented stub. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "storage_root" |), Constant.None_ |) |) in - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "encode_account" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "storage_root" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "U256" |) ] - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.call (| - M.get_name (| globals, "cast" |), - make_list [ - M.get_field (| M.get_name (| globals, "rlp" |), "RLP" |); - M.get_name (| globals, "node" |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "Bytes" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "node" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "previous_trie" |), "encode_node" |), @@ -434,7 +261,6 @@ Definition encode_node : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -486,7 +312,6 @@ Definition copy_trie : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition trie_set : Value.t -> Value.t -> M := @@ -508,26 +333,6 @@ Definition trie_set : Value.t -> Value.t -> M := Node to insert at `key`. " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "value" |), M.get_field (| M.get_name (| globals, "trie" |), "default" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "key" |), M.get_field (| M.get_name (| globals, "trie" |), "_data" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), M.get_name (| globals, "value" |) @@ -565,7 +370,6 @@ Definition trie_get : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition common_prefix_length : Value.t -> Value.t -> M := @@ -588,28 +392,6 @@ Definition common_prefix_length : Value.t -> Value.t -> M := make_dict [] |) do let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| M.get_name (| globals, "i" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "b" |) - ], - make_dict [] - |) |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "i" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -621,7 +403,6 @@ Definition common_prefix_length : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition nibble_list_to_compact : Value.t -> Value.t -> M := @@ -667,68 +448,6 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| BinOp.mod_ (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |), - Constant.int 2 - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_name (| globals, "compact" |), "append" |), - make_list [ - BinOp.mult (| - Constant.int 16, - BinOp.mult (| - Constant.int 2, - M.get_name (| globals, "is_leaf" |) - |) - |) - ], - make_dict [] - |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 0; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |); - Constant.int 2 - ], - make_dict [] - |) do - let _ := M.call (| - M.get_field (| M.get_name (| globals, "compact" |), "append" |), - make_list [ - BinOp.add (| - BinOp.mult (| - Constant.int 16, - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) - |), - M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) - |) - ], - make_dict [] - |) in - EndFor. - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ @@ -790,7 +509,6 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition bytes_to_nibble_list : Value.t -> Value.t -> M := @@ -868,7 +586,6 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition _prepare_trie : Value.t -> Value.t -> M := @@ -898,45 +615,6 @@ Definition _prepare_trie : Value.t -> Value.t -> M := make_dict [] |) do let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "value" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in - let address := - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in - let encoded_value := - M.call (| - M.get_name (| globals, "encode_node" |), - make_list [ - M.get_name (| globals, "value" |); - M.call (| - M.get_name (| globals, "get_storage_root" |), - make_list [ - M.get_name (| globals, "address" |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let encoded_value := M.call (| M.get_name (| globals, "encode_node" |), @@ -950,29 +628,16 @@ Definition _prepare_trie : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.not_eq (| M.get_name (| globals, "encoded_value" |), (* At constant: unsupported node type: Constant *) |); + Compare.not_eq (| + M.get_name (| globals, "encoded_value" |), + Constant.bytes "" + |); M.get_name (| globals, "AssertionError" |) ], make_dict [] |) in (* At stmt: unsupported node type: AnnAssign *) let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "trie" |), "secured" |), - (* then *) - ltac:(M.monadic ( - let key := - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let key := M.get_name (| globals, "preimage" |) in M.pure Constant.None_ @@ -990,7 +655,6 @@ Definition _prepare_trie : Value.t -> Value.t -> M := EndFor. let _ := M.return_ (| M.get_name (| globals, "mapped" |) - |) in M.pure Constant.None_)). Definition root : Value.t -> Value.t -> M := @@ -1044,41 +708,6 @@ Definition root : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "root_node" |) - ], - make_dict [] - |) - ], - make_dict [] - |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "root_node" |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -1095,7 +724,6 @@ Definition root : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -1122,23 +750,6 @@ Definition patricialize : Value.t -> Value.t -> M := Root node of `obj`. " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "obj" |) - ], - make_dict [] - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.None_ - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let arbitrary_key := @@ -1156,36 +767,10 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "obj" |) - ], - make_dict [] - |), Constant.int 1 |), - (* then *) - ltac:(M.monadic ( - let leaf := - M.call (| - M.get_name (| globals, "LeafNode" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |); - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) - ], - make_dict [] - |) in - let _ := M.return_ (| - M.get_name (| globals, "leaf" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let substring := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |) |) in let prefix_length := M.call (| M.get_name (| globals, "len" |), @@ -1204,7 +789,7 @@ Definition patricialize : Value.t -> Value.t -> M := M.get_name (| globals, "common_prefix_length" |), make_list [ M.get_name (| globals, "substring" |); - M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) + M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) ], make_dict [] |) @@ -1212,58 +797,10 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.break (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let prefix := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):BinOp.add (| - M.get_name (| globals, "level" |), - M.get_name (| globals, "prefix_length" |) - |) |) in - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "ExtensionNode" |), - make_list [ - M.get_name (| globals, "prefix" |); - M.call (| - M.get_name (| globals, "encode_internal_node" |), - make_list [ - M.call (| - M.get_name (| globals, "patricialize" |), - make_list [ - M.get_name (| globals, "obj" |); - BinOp.add (| - M.get_name (| globals, "level" |), - M.get_name (| globals, "prefix_length" |) - |) - ], - make_dict [] - |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) @@ -1283,44 +820,9 @@ Definition patricialize : Value.t -> Value.t -> M := |) in EndFor. let value := - (* At constant: unsupported node type: Constant *) in + Constant.bytes "" in For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "key" |) - ], - make_dict [] - |), M.get_name (| globals, "level" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); - make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "AssertionError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let value := - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) @@ -1332,26 +834,9 @@ Definition patricialize : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "BranchNode" |), make_list [ - [M.call (| - M.get_name (| globals, "encode_internal_node" |), - make_list [ - M.call (| - M.get_name (| globals, "patricialize" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "branches" |), M.get_name (| globals, "k" |) |); - BinOp.add (| - M.get_name (| globals, "level" |), - Constant.int 1 - |) - ], - make_dict [] - |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)]; + (* At expr: unsupported node type: ListComp *); M.get_name (| globals, "value" |) ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/utils/address.v b/CoqOfPython/ethereum/arrow_glacier/utils/address.v index 772eb53..c8bc7ba 100644 --- a/CoqOfPython/ethereum/arrow_glacier/utils/address.v +++ b/CoqOfPython/ethereum/arrow_glacier/utils/address.v @@ -70,11 +70,10 @@ Definition to_address : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), make_list [], make_dict [] - |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) + |), UnOp.sub (| Constant.int 20 |) |) ], make_dict [] |) - |) in M.pure Constant.None_)). Definition compute_contract_address : Value.t -> Value.t -> M := @@ -114,7 +113,7 @@ Definition compute_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -132,7 +131,6 @@ Definition compute_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition compute_create2_contract_address : Value.t -> Value.t -> M := @@ -160,7 +158,7 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := BinOp.add (| BinOp.add (| BinOp.add (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "ff", M.get_name (| globals, "address" |) |), M.get_name (| globals, "salt" |) @@ -182,7 +180,7 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -200,5 +198,4 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/utils/hexadecimal.v b/CoqOfPython/ethereum/arrow_glacier/utils/hexadecimal.v index 859b060..d6d904b 100644 --- a/CoqOfPython/ethereum/arrow_glacier/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/arrow_glacier/utils/hexadecimal.v @@ -66,7 +66,6 @@ Definition hex_to_root : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition hex_to_bloom : Value.t -> Value.t -> M := @@ -105,7 +104,6 @@ Definition hex_to_bloom : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition hex_to_address : Value.t -> Value.t -> M := @@ -151,5 +149,4 @@ Definition hex_to_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/utils/message.v b/CoqOfPython/ethereum/arrow_glacier/utils/message.v index 084c3b0..5f66705 100644 --- a/CoqOfPython/ethereum/arrow_glacier/utils/message.v +++ b/CoqOfPython/ethereum/arrow_glacier/utils/message.v @@ -103,105 +103,14 @@ Definition prepare_message : Value.t -> Value.t -> M := Items containing contract creation or message call specific data. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "target" |); - M.get_name (| globals, "Bytes0" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let current_target := - M.call (| - M.get_name (| globals, "compute_contract_address" |), - make_list [ - M.get_name (| globals, "caller" |); - BinOp.sub (| - M.get_field (| M.call (| - M.get_name (| globals, "get_account" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "caller" |) - ], - make_dict [] - |), "nonce" |), - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 1 - ], - make_dict [] - |) - |) - ], - make_dict [] - |) in - let msg_data := - M.call (| - M.get_name (| globals, "Bytes" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |) in - let code := - M.get_name (| globals, "data" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "target" |); - M.get_name (| globals, "Address" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let current_target := - M.get_name (| globals, "target" |) in - let msg_data := - M.get_name (| globals, "data" |) in - let code := - M.get_field (| M.call (| - M.get_name (| globals, "get_account" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "target" |) - ], - make_dict [] - |), "code" |) in - let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "code_address" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let code_address := - M.get_name (| globals, "target" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.call (| + let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "Target must be address or empty bytes" ], make_dict [] - |) |) in + |)) M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -250,5 +159,4 @@ Definition prepare_message : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/__init__.v b/CoqOfPython/ethereum/arrow_glacier/vm/__init__.v index 2ff63cd..49da5ae 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/__init__.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/__init__.v @@ -147,28 +147,6 @@ Definition incorporate_child_on_success : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); - M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -201,57 +179,9 @@ Definition incorporate_child_on_error : Value.t -> Value.t -> M := The child evm to incorporate. " in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "RIPEMD160_ADDRESS" |), M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), - make_list [ - M.get_name (| globals, "RIPEMD160_ADDRESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |), M.get_name (| globals, "RIPEMD160_ADDRESS" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); - M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), - make_list [ - M.get_name (| globals, "RIPEMD160_ADDRESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign_op (| diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/gas.v b/CoqOfPython/ethereum/arrow_glacier/vm/gas.v new file mode 100644 index 0000000..549060b --- /dev/null +++ b/CoqOfPython/ethereum/arrow_glacier/vm/gas.v @@ -0,0 +1,811 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Gas +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +EVM gas constants and calculators. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.trace. +Axiom ethereum_trace_GasAndRefund : + IsGlobalAlias globals ethereum.trace.globals "GasAndRefund". +Axiom ethereum_trace_evm_trace : + IsGlobalAlias globals ethereum.trace.globals "evm_trace". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". + +Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) +)). + +Definition GAS_BASE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 2 + ], + make_dict [] + |) +)). + +Definition GAS_VERY_LOW : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_STORAGE_SET : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 20000 + ], + make_dict [] + |) +)). + +Definition GAS_STORAGE_UPDATE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5000 + ], + make_dict [] + |) +)). + +Definition GAS_STORAGE_CLEAR_REFUND : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 4800 + ], + make_dict [] + |) +)). + +Definition GAS_LOW : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5 + ], + make_dict [] + |) +)). + +Definition GAS_MID : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 8 + ], + make_dict [] + |) +)). + +Definition GAS_HIGH : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 10 + ], + make_dict [] + |) +)). + +Definition GAS_EXPONENTIATION : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 10 + ], + make_dict [] + |) +)). + +Definition GAS_EXPONENTIATION_PER_BYTE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 50 + ], + make_dict [] + |) +)). + +Definition GAS_MEMORY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_KECCAK256 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 30 + ], + make_dict [] + |) +)). + +Definition GAS_KECCAK256_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 6 + ], + make_dict [] + |) +)). + +Definition GAS_COPY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_BLOCK_HASH : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 20 + ], + make_dict [] + |) +)). + +Definition GAS_LOG : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 375 + ], + make_dict [] + |) +)). + +Definition GAS_LOG_DATA : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 8 + ], + make_dict [] + |) +)). + +Definition GAS_LOG_TOPIC : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 375 + ], + make_dict [] + |) +)). + +Definition GAS_CREATE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 32000 + ], + make_dict [] + |) +)). + +Definition GAS_CODE_DEPOSIT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 200 + ], + make_dict [] + |) +)). + +Definition GAS_ZERO : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) +)). + +Definition GAS_NEW_ACCOUNT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 25000 + ], + make_dict [] + |) +)). + +Definition GAS_CALL_VALUE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 9000 + ], + make_dict [] + |) +)). + +Definition GAS_CALL_STIPEND : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 2300 + ], + make_dict [] + |) +)). + +Definition GAS_SELF_DESTRUCT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5000 + ], + make_dict [] + |) +)). + +Definition GAS_SELF_DESTRUCT_NEW_ACCOUNT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 25000 + ], + make_dict [] + |) +)). + +Definition GAS_ECRECOVER : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3000 + ], + make_dict [] + |) +)). + +Definition GAS_SHA256 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 60 + ], + make_dict [] + |) +)). + +Definition GAS_SHA256_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 12 + ], + make_dict [] + |) +)). + +Definition GAS_RIPEMD160 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 600 + ], + make_dict [] + |) +)). + +Definition GAS_RIPEMD160_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 120 + ], + make_dict [] + |) +)). + +Definition GAS_IDENTITY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 15 + ], + make_dict [] + |) +)). + +Definition GAS_IDENTITY_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_RETURN_DATA_COPY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_FAST_STEP : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5 + ], + make_dict [] + |) +)). + +Definition GAS_BLAKE2_PER_ROUND : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) +)). + +Definition GAS_COLD_SLOAD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 2100 + ], + make_dict [] + |) +)). + +Definition GAS_COLD_ACCOUNT_ACCESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 2600 + ], + make_dict [] + |) +)). + +Definition GAS_WARM_ACCESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 100 + ], + make_dict [] + |) +)). + +Definition ExtendMemory : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition MessageCallGas : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition charge_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "amount" ] |) in + let _ := Constant.str " + Subtracts `amount` from `evm.gas_left`. + + Parameters + ---------- + evm : + The current EVM. + amount : + The amount of gas the current operation requires. + + " in + let _ := M.call (| + M.get_name (| globals, "evm_trace" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "GasAndRefund" |), + make_list [ + M.get_name (| globals, "amount" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + let _ := M.assign_op (| + BinOp.sub, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "amount" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition calculate_memory_gas_cost : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "size_in_bytes" ] |) in + let _ := Constant.str " + Calculates the gas cost for allocating memory + to the smallest multiple of 32 bytes, + such that the allocated size is at least as big as the given size. + + Parameters + ---------- + size_in_bytes : + The size of the data in bytes. + + Returns + ------- + total_gas_cost : `ethereum.base_types.Uint` + The gas cost for storing data in memory. + " in + let size_in_words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "size_in_bytes" |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let linear_cost := + BinOp.mult (| + M.get_name (| globals, "size_in_words" |), + M.get_name (| globals, "GAS_MEMORY" |) + |) in + let quadratic_cost := + BinOp.floor_div (| + BinOp.pow (| + M.get_name (| globals, "size_in_words" |), + Constant.int 2 + |), + Constant.int 512 + |) in + let total_gas_cost := + BinOp.add (| + M.get_name (| globals, "linear_cost" |), + M.get_name (| globals, "quadratic_cost" |) + |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_)). + +Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "memory"; "extensions" ] |) in + let _ := Constant.str " + Calculates the gas amount to extend memory + + Parameters + ---------- + memory : + Memory contents of the EVM. + extensions: + List of extensions to be made to the memory. + Consists of a tuple of start position and size. + + Returns + ------- + extend_memory: `ExtendMemory` + " in + let size_to_extend := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let to_be_paid := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let current_size := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "memory" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + For make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ] in M.get_name (| globals, "extensions" |) do + let _ := + M.pure Constant.None_ + )) |) in + let before_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "current_size" |) + ], + make_dict [] + |) in + let after_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let size_to_extend := BinOp.add + BinOp.sub (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |) + BinOp.sub (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |) in + let already_paid := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "before_size" |) + ], + make_dict [] + |) in + let total_cost := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "after_size" |) + ], + make_dict [] + |) in + let to_be_paid := BinOp.add + BinOp.sub (| + M.get_name (| globals, "total_cost" |), + M.get_name (| globals, "already_paid" |) + |) + BinOp.sub (| + M.get_name (| globals, "total_cost" |), + M.get_name (| globals, "already_paid" |) + |) in + let current_size := + M.get_name (| globals, "after_size" |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ExtendMemory" |), + make_list [ + M.get_name (| globals, "to_be_paid" |); + M.get_name (| globals, "size_to_extend" |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition calculate_message_call_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "value"; "gas"; "gas_left"; "memory_cost"; "extra_gas"; "call_stipend" ] |) in + let _ := Constant.str " + Calculates the MessageCallGas (cost and stipend) for + executing call Opcodes. + + Parameters + ---------- + value: + The amount of `ETH` that needs to be transferred. + gas : + The amount of gas provided to the message-call. + gas_left : + The amount of gas left in the current frame. + memory_cost : + The amount needed to extend the memory in the current frame. + extra_gas : + The amount of gas needed for transferring value + creating a new + account inside a message call. + call_stipend : + The amount of stipend provided to a message call to execute code while + transferring value(ETH). + + Returns + ------- + message_call_gas: `MessageCallGas` + " in + let call_stipend := + (* if *) +M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let gas := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "max_message_call_gas" |), + make_list [ + BinOp.sub (| + BinOp.sub (| + M.get_name (| globals, "gas_left" |), + M.get_name (| globals, "memory_cost" |) + |), + M.get_name (| globals, "extra_gas" |) + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallGas" |), + make_list [ + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "extra_gas" |) + |); + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "call_stipend" |) + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition max_message_call_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "gas" ] |) in + let _ := Constant.str " + Calculates the maximum gas that is allowed for making a message call + + Parameters + ---------- + gas : + The amount of gas provided to the message-call. + + Returns + ------- + max_allowed_message_call_gas: `ethereum.base_types.Uint` + The maximum gas allowed for making the message-call. + " in + let _ := M.return_ (| + BinOp.sub (| + M.get_name (| globals, "gas" |), + BinOp.floor_div (| + M.get_name (| globals, "gas" |), + Constant.int 64 + |) + |) + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/arithmetic.v index a8b5c61..581ba5d 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/arithmetic.v @@ -273,22 +273,6 @@ Definition div : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let quotient := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let quotient := BinOp.floor_div (| M.get_name (| globals, "dividend" |), @@ -357,32 +341,7 @@ Definition sdiv : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let quotient := - Constant.int 0 in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_name (| globals, "dividend" |), UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "divisor" |), UnOp.sub (| Constant.int 1 |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let quotient := - UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let sign := M.call (| M.get_name (| globals, "get_sign" |), @@ -477,22 +436,6 @@ Definition mod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let remainder := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let remainder := BinOp.mod_ (| M.get_name (| globals, "x" |), @@ -561,16 +504,6 @@ Definition smod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let remainder := - Constant.int 0 in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let remainder := BinOp.mult (| M.call (| @@ -684,22 +617,6 @@ Definition addmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -795,22 +712,6 @@ Definition mulmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -980,16 +881,6 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "byte_num" |), Constant.int 31 |), - (* then *) - ltac:(M.monadic ( - let result := - M.get_name (| globals, "value" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let value_bytes := M.call (| M.get_name (| globals, "bytes" |), @@ -1012,29 +903,13 @@ Definition signextend : Value.t -> Value.t -> M := ], make_dict [] |) - |):(* At expr: unsupported node type: NoneType *) |) in + |) |) in let sign_bit := BinOp.r_shift (| M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), Constant.int 7 |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "sign_bit" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), - make_list [ - M.get_name (| globals, "value_bytes" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let num_bytes_prepend := BinOp.sub (| Constant.int 32, diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/bitwise.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/bitwise.v index 9f2f382..64cf120 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/bitwise.v @@ -287,22 +287,6 @@ Definition get_byte : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "byte_index" |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let extra_bytes_to_right := BinOp.sub (| Constant.int 31, @@ -382,28 +366,6 @@ Definition bitwise_shl : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - BinOp.mod_ (| - BinOp.l_shift (| - M.get_name (| globals, "value" |), - M.get_name (| globals, "shift" |) - |), - M.get_name (| globals, "U256_CEIL_VALUE" |) - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -465,19 +427,6 @@ Definition bitwise_shr : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), - (* then *) - ltac:(M.monadic ( - let result := - BinOp.r_shift (| - M.get_name (| globals, "value" |), - M.get_name (| globals, "shift" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -543,42 +492,7 @@ Definition bitwise_sar : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), - make_list [ - BinOp.r_shift (| - M.get_name (| globals, "signed_value" |), - M.get_name (| globals, "shift" |) - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "signed_value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/block.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/block.v index 26c73a7..f857b79 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/block.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/block.v @@ -69,24 +69,6 @@ Definition block_hash : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.lt_e (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), M.get_name (| globals, "block_number" |) |), - ltac:(M.monadic ( - Compare.gt (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), BinOp.add (| - M.get_name (| globals, "block_number" |), - Constant.int 256 - |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let hash := - (* At constant: unsupported node type: Constant *) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let hash := M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/comparison.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/comparison.v index fbc35f8..b8529d8 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/comparison.v @@ -78,7 +78,10 @@ Definition less_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.lt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -145,7 +148,10 @@ Definition signed_less_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.lt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -205,7 +211,10 @@ Definition greater_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.gt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -272,7 +281,10 @@ Definition signed_greater_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.gt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -332,7 +344,10 @@ Definition equal : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.eq (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.eq (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -384,7 +399,10 @@ Definition is_zero : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.eq (| M.get_name (| globals, "x" |), Constant.int 0 |) + Compare.eq (| + M.get_name (| globals, "x" |), + Constant.int 0 + |) ], make_dict [] |) in diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/control_flow.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/control_flow.v index 04a79d9..d4e4eae 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/control_flow.v @@ -109,15 +109,6 @@ Definition jump : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -177,29 +168,7 @@ Definition jumpi : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "conditional_value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let destination := - BinOp.add (| - M.get_field (| M.get_name (| globals, "evm" |), "pc" |), - Constant.int 1 - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let destination := M.get_name (| globals, "jump_dest" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/environment.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/environment.v index 530304e..10bc05b 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/environment.v @@ -156,22 +156,6 @@ Definition balance : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "charge_gas" |), - make_list [ - M.get_name (| globals, "evm" |); - M.get_name (| globals, "GAS_WARM_ACCESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -538,7 +522,7 @@ Definition calldatacopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -706,7 +690,7 @@ Definition codecopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -805,22 +789,6 @@ Definition extcodesize : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "charge_gas" |), - make_list [ - M.get_name (| globals, "evm" |); - M.get_name (| globals, "GAS_WARM_ACCESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -958,28 +926,6 @@ Definition extcodecopy : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "charge_gas" |), - make_list [ - M.get_name (| globals, "evm" |); - BinOp.add (| - BinOp.add (| - M.get_name (| globals, "GAS_WARM_ACCESS" |), - M.get_name (| globals, "copy_gas_cost" |) - |), - M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1007,7 +953,7 @@ Definition extcodecopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -1178,28 +1124,31 @@ Definition returndatacopy : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt_e (| BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "return_data_start_position" |) - ], - make_dict [] + Compare.lt_e (| + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "return_data_start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) |), M.call (| - M.get_name (| globals, "Uint" |), + M.get_name (| globals, "len" |), make_list [ - M.get_name (| globals, "size" |) + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |) ], make_dict [] |) - |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "return_data" |) - ], - make_dict [] - |) |); + |); M.get_name (| globals, "OutOfBoundsRead" |) ], make_dict [] @@ -1208,15 +1157,12 @@ Definition returndatacopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in let value := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |):BinOp.add (| - M.get_name (| globals, "return_data_start_position" |), - M.get_name (| globals, "size" |) - |) |) in + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |) |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -1258,22 +1204,6 @@ Definition extcodehash : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "charge_gas" |), - make_list [ - M.get_name (| globals, "evm" |); - M.get_name (| globals, "GAS_WARM_ACCESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1301,22 +1231,6 @@ Definition extcodehash : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "account" |), M.get_name (| globals, "EMPTY_ACCOUNT" |) |), - (* then *) - ltac:(M.monadic ( - let codehash := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let codehash := M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/keccak.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/keccak.v index cab9ffb..2c4b10e 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/keccak.v @@ -137,7 +137,7 @@ Definition keccak : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/log.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/log.v index 4891a4d..e084e59 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/log.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/log.v @@ -161,7 +161,7 @@ Definition log_n : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/memory.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/memory.v index 1e1c8b0..86ba742 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/memory.v @@ -121,7 +121,7 @@ Definition mstore : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -203,7 +203,7 @@ Definition mstore8 : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -288,7 +288,7 @@ Definition mload : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/stack.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/stack.v index 1eeda05..305af15 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/stack.v @@ -188,13 +188,16 @@ Definition dup_n : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] - |) |); + Compare.lt (| + M.get_name (| globals, "item_number" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + |); M.get_name (| globals, "StackUnderflowError" |) ], make_dict [] @@ -260,13 +263,16 @@ Definition swap_n : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] - |) |); + Compare.lt (| + M.get_name (| globals, "item_number" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + |); M.get_name (| globals, "StackUnderflowError" |) ], make_dict [] diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/storage.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/storage.v index 2f0a831..b3c4045 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/storage.v @@ -91,22 +91,6 @@ Definition sload : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "charge_gas" |), - make_list [ - M.get_name (| globals, "evm" |); - M.get_name (| globals, "GAS_WARM_ACCESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "add" |), make_list [ @@ -184,7 +168,10 @@ Definition sstore : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.gt (| M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), M.get_name (| globals, "GAS_CALL_STIPEND" |) |); + Compare.gt (| + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "GAS_CALL_STIPEND" |) + |); M.get_name (| globals, "OutOfGasError" |) ], make_dict [] @@ -218,189 +205,15 @@ Definition sstore : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_in (| make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "add" |), - make_list [ - make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ] - ], - make_dict [] - |) in - let gas_cost := BinOp.add - M.get_name (| globals, "GAS_COLD_SLOAD" |) - M.get_name (| globals, "GAS_COLD_SLOAD" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_name (| globals, "original_value" |), M.get_name (| globals, "current_value" |) |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_name (| globals, "current_value" |), M.get_name (| globals, "new_value" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let gas_cost := BinOp.add - M.get_name (| globals, "GAS_STORAGE_SET" |) - M.get_name (| globals, "GAS_STORAGE_SET" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let gas_cost := BinOp.add - BinOp.sub (| - M.get_name (| globals, "GAS_STORAGE_UPDATE" |), - M.get_name (| globals, "GAS_COLD_SLOAD" |) - |) - BinOp.sub (| - M.get_name (| globals, "GAS_STORAGE_UPDATE" |), - M.get_name (| globals, "GAS_COLD_SLOAD" |) - |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let gas_cost := BinOp.add M.get_name (| globals, "GAS_WARM_ACCESS" |) M.get_name (| globals, "GAS_WARM_ACCESS" |) in M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_eq (| M.get_name (| globals, "current_value" |), M.get_name (| globals, "new_value" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), - ltac:(M.monadic ( - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "new_value" |), Constant.int 0 |) - )) - |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), - M.call (| - M.get_name (| globals, "int" |), - make_list [ - M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.sub, - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), - M.call (| - M.get_name (| globals, "int" |), - make_list [ - M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "original_value" |), M.get_name (| globals, "new_value" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), - M.call (| - M.get_name (| globals, "int" |), - make_list [ - BinOp.sub (| - M.get_name (| globals, "GAS_STORAGE_SET" |), - M.get_name (| globals, "GAS_WARM_ACCESS" |) - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), - M.call (| - M.get_name (| globals, "int" |), - make_list [ - BinOp.sub (| - BinOp.sub (| - M.get_name (| globals, "GAS_STORAGE_UPDATE" |), - M.get_name (| globals, "GAS_COLD_SLOAD" |) - |), - M.get_name (| globals, "GAS_WARM_ACCESS" |) - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/system.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/system.v new file mode 100644 index 0000000..03931b2 --- /dev/null +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/system.v @@ -0,0 +1,1635 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) System Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM system related instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_account_exists_and_is_empty : + IsGlobalAlias globals state.globals "account_exists_and_is_empty". +Axiom state_account_has_code_or_nonce : + IsGlobalAlias globals state.globals "account_has_code_or_nonce". +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". +Axiom state_increment_nonce : + IsGlobalAlias globals state.globals "increment_nonce". +Axiom state_is_account_alive : + IsGlobalAlias globals state.globals "is_account_alive". +Axiom state_set_account_balance : + IsGlobalAlias globals state.globals "set_account_balance". + +Require utils.address. +Axiom utils_address_compute_contract_address : + IsGlobalAlias globals utils.address.globals "compute_contract_address". +Axiom utils_address_compute_create2_contract_address : + IsGlobalAlias globals utils.address.globals "compute_create2_contract_address". +Axiom utils_address_to_address : + IsGlobalAlias globals utils.address.globals "to_address". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". +Axiom __init___Message : + IsGlobalAlias globals __init__.globals "Message". +Axiom __init___incorporate_child_on_error : + IsGlobalAlias globals __init__.globals "incorporate_child_on_error". +Axiom __init___incorporate_child_on_success : + IsGlobalAlias globals __init__.globals "incorporate_child_on_success". + +Require exceptions. +Axiom exceptions_Revert : + IsGlobalAlias globals exceptions.globals "Revert". +Axiom exceptions_WriteInStaticContext : + IsGlobalAlias globals exceptions.globals "WriteInStaticContext". + +Require gas. +Axiom gas_GAS_CALL_VALUE : + IsGlobalAlias globals gas.globals "GAS_CALL_VALUE". +Axiom gas_GAS_COLD_ACCOUNT_ACCESS : + IsGlobalAlias globals gas.globals "GAS_COLD_ACCOUNT_ACCESS". +Axiom gas_GAS_CREATE : + IsGlobalAlias globals gas.globals "GAS_CREATE". +Axiom gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". +Axiom gas_GAS_NEW_ACCOUNT : + IsGlobalAlias globals gas.globals "GAS_NEW_ACCOUNT". +Axiom gas_GAS_SELF_DESTRUCT : + IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT". +Axiom gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : + IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". +Axiom gas_GAS_WARM_ACCESS : + IsGlobalAlias globals gas.globals "GAS_WARM_ACCESS". +Axiom gas_GAS_ZERO : + IsGlobalAlias globals gas.globals "GAS_ZERO". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_calculate_message_call_gas : + IsGlobalAlias globals gas.globals "calculate_message_call_gas". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". +Axiom gas_max_message_call_gas : + IsGlobalAlias globals gas.globals "max_message_call_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". +Axiom memory_memory_write : + IsGlobalAlias globals memory.globals "memory_write". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition generic_create : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "endowment"; "contract_address"; "memory_start_position"; "memory_size" ] |) in + let _ := Constant.str " + Core logic used by the `CREATE*` family of opcodes. + " in +(* At stmt: unsupported node type: ImportFrom *) + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "contract_address" |) + ], + make_dict [] + |) in + let create_message_gas := + M.call (| + M.get_name (| globals, "max_message_call_gas" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.sub, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "create_message_gas" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let sender_address := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in + let sender := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "sender_address" |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := + M.pure Constant.None_ + )) |) in + let call_data := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + let child_message := + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) in + let child_evm := + M.call (| + M.get_name (| globals, "process_create_message" |), + make_list [ + M.get_name (| globals, "child_message" |); + M.get_field (| M.get_name (| globals, "evm" |), "env" |) + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_success" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition create : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Creates a new account with associated code. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let endowment := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_position" |); M.get_name (| globals, "memory_size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_CREATE" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let contract_address := + M.call (| + M.get_name (| globals, "compute_contract_address" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "nonce" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "generic_create" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "endowment" |); + M.get_name (| globals, "contract_address" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition create2 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Creates a new account with associated code. + + It's similar to CREATE opcode except that the address of new account + depends on the init_code instead of the nonce of sender. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let endowment := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let salt := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_position" |); M.get_name (| globals, "memory_size" |) ] + ] + ], + make_dict [] + |) in + let call_data_words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_CREATE" |), + BinOp.mult (| + M.get_name (| globals, "GAS_KECCAK256_WORD" |), + M.get_name (| globals, "call_data_words" |) + |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let contract_address := + M.call (| + M.get_name (| globals, "compute_create2_contract_address" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "salt" |); + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "generic_create" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "endowment" |); + M.get_name (| globals, "contract_address" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition return_ : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Halts execution returning output data. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let memory_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_position" |); M.get_name (| globals, "memory_size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_ZERO" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "running" |), + Constant.bool false + |) in + let _ := M.pass (| |) in + M.pure Constant.None_)). + +Definition generic_call : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "gas"; "value"; "caller"; "to"; "code_address"; "should_transfer_value"; "is_staticcall"; "memory_input_start_position"; "memory_input_size"; "memory_output_start_position"; "memory_output_size" ] |) in + let _ := Constant.str " + Perform the core logic of the `CALL*` family of opcodes. + " in +(* At stmt: unsupported node type: ImportFrom *) + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let _ := + M.pure Constant.None_ + )) |) in + let call_data := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |) + ], + make_dict [] + |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "code_address" |) + ], + make_dict [] + |), "code" |) in + let child_message := + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) in + let child_evm := + M.call (| + M.get_name (| globals, "process_message" |), + make_list [ + M.get_name (| globals, "child_message" |); + M.get_field (| M.get_name (| globals, "evm" |), "env" |) + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_success" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let actual_output_size := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_name (| globals, "memory_output_size" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), Constant.None_:M.get_name (| globals, "actual_output_size" |) |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition call : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into an account. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let to := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "to" |) + ], + make_dict [] + |) in + let access_gas_cost := + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + M.pure Constant.None_ + )) |) in + let create_gas_cost := + (* if *) +M.if_then_else (| + BoolOp.or (| + M.call (| + M.get_name (| globals, "is_account_alive" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "to" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |) + )) + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let transfer_gas_cost := + (* if *) +M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "access_gas_cost" |), + M.get_name (| globals, "create_gas_cost" |) + |), + M.get_name (| globals, "transfer_gas_cost" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.or (| + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "value" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) + )) + |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let sender_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.get_name (| globals, "value" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "to" |); + Constant.bool true; + Constant.bool false; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition callcode : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into this account with alternative account’s code. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let code_address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let to := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "code_address" |) + ], + make_dict [] + |) in + let access_gas_cost := + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + M.pure Constant.None_ + )) |) in + let transfer_gas_cost := + (* if *) +M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + BinOp.add (| + M.get_name (| globals, "access_gas_cost" |), + M.get_name (| globals, "transfer_gas_cost" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let sender_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.get_name (| globals, "value" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "code_address" |); + Constant.bool true; + Constant.bool false; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition selfdestruct : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Halt execution and register account for later deletion. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let beneficiary := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let gas_cost := + M.get_name (| globals, "GAS_SELF_DESTRUCT" |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "gas_cost" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let originator := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in + let beneficiary_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |), "balance" |) in + let originator_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "originator" |) + ], + make_dict [] + |), "balance" |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |); + BinOp.add (| + M.get_name (| globals, "beneficiary_balance" |), + M.get_name (| globals, "originator_balance" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "originator" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |), "add" |), + make_list [ + M.get_name (| globals, "originator" |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "running" |), + Constant.bool false + |) in + let _ := M.pass (| |) in + M.pure Constant.None_)). + +Definition delegatecall : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into an account. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let code_address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "code_address" |) + ], + make_dict [] + |) in + let access_gas_cost := + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + M.pure Constant.None_ + )) |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + M.get_name (| globals, "access_gas_cost" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "value" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "caller" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "code_address" |); + Constant.bool false; + Constant.bool false; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition staticcall : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into an account. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let to := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "to" |) + ], + make_dict [] + |) in + let access_gas_cost := + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + M.pure Constant.None_ + )) |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + M.get_name (| globals, "access_gas_cost" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "to" |); + Constant.bool true; + Constant.bool true; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition revert : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stop execution and revert state changes, without consuming all provided gas + and also has the ability to return a reason + Parameters + ---------- + evm : + The current EVM frame. + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let output := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "bytes" |), + make_list [ + M.get_name (| globals, "output" |) + ], + make_dict [] + |) + |) in + let _ := M.raise (| Some(M.get_name (| globals, "Revert" |)) + let _ := M.pass (| |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/interpreter.v b/CoqOfPython/ethereum/arrow_glacier/vm/interpreter.v index 8179355..024d2d5 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/interpreter.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/interpreter.v @@ -184,91 +184,6 @@ Definition process_message_call : Value.t -> Value.t -> M := Output of the message call " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_name (| globals, "message" |), "target" |), M.call (| - M.get_name (| globals, "Bytes0" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let is_collision := - M.call (| - M.get_name (| globals, "account_has_code_or_nonce" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_field (| M.get_name (| globals, "message" |), "current_target" |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - M.get_name (| globals, "is_collision" |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "MessageCallOutput" |), - make_list [ - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |); - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |); - M.call (| - M.get_name (| globals, "tuple" |), - make_list [], - make_dict [] - |); - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |); - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |); - M.call (| - M.get_name (| globals, "AddressCollision" |), - make_list [], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let evm := - M.call (| - M.get_name (| globals, "process_create_message" |), - make_list [ - M.get_name (| globals, "message" |); - M.get_name (| globals, "env" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let evm := M.call (| M.get_name (| globals, "process_message" |), @@ -279,74 +194,11 @@ Definition process_message_call : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_field (| M.get_name (| globals, "message" |), "target" |) - ], - make_dict [] - |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), - make_list [ - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_field (| M.get_name (| globals, "message" |), "target" |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "evm" |), "error" |), - (* then *) - ltac:(M.monadic ( -(* At stmt: unsupported node type: AnnAssign *) - let accounts_to_delete := - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |) in - let touched_accounts := - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |) in - let refund_counter := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let logs := M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in let accounts_to_delete := @@ -390,7 +242,6 @@ Definition process_message_call : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). Definition process_create_message : Value.t -> Value.t -> M := @@ -452,28 +303,6 @@ Definition process_create_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), - (* then *) - ltac:(M.monadic ( - let contract_code := - M.get_field (| M.get_name (| globals, "evm" |), "output" |) in - let contract_code_gas := - BinOp.mult (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "contract_code" |) - ], - make_dict [] - |), - M.get_name (| globals, "GAS_CODE_DEPOSIT" |) - |) in -(* At stmt: unsupported node type: Try *) - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "rollback_transaction" |), make_list [ @@ -485,7 +314,6 @@ Definition process_create_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) - |) in M.pure Constant.None_)). Definition process_message : Value.t -> Value.t -> M := @@ -507,21 +335,6 @@ Definition process_message : Value.t -> Value.t -> M := Items containing execution specific objects " in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_field (| M.get_name (| globals, "message" |), "depth" |), M.get_name (| globals, "STACK_DEPTH_LIMIT" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "StackDepthLimitError" |), - make_list [ - Constant.str "Stack depth limit reached" - ], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -540,29 +353,6 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - M.get_field (| M.get_name (| globals, "message" |), "should_transfer_value" |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_field (| M.get_name (| globals, "message" |), "value" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "move_ether" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_field (| M.get_name (| globals, "message" |), "caller" |); - M.get_field (| M.get_name (| globals, "message" |), "current_target" |); - M.get_field (| M.get_name (| globals, "message" |), "value" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let evm := @@ -575,21 +365,6 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "evm" |), "error" |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "rollback_transaction" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "commit_transaction" |), make_list [ @@ -601,7 +376,6 @@ Definition process_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) - |) in M.pure Constant.None_)). Definition execute_code : Value.t -> Value.t -> M := @@ -641,5 +415,4 @@ Definition execute_code : Value.t -> Value.t -> M := (* At stmt: unsupported node type: Try *) let _ := M.return_ (| M.get_name (| globals, "evm" |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/memory.v b/CoqOfPython/ethereum/arrow_glacier/vm/memory.v index fa8d906..4b107fd 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/memory.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/memory.v @@ -45,22 +45,7 @@ Definition memory_write : Value.t -> Value.t -> M := Data to write to memory. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) - |) |), + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_)). @@ -86,23 +71,7 @@ Definition memory_read_bytes : Value.t -> Value.t -> M := Data read from memory. " in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |) - |) in + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |) M.pure Constant.None_)). Definition buffer_read : Value.t -> Value.t -> M := @@ -129,25 +98,9 @@ Definition buffer_read : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "right_pad_zero_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |); + M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |) |); M.get_name (| globals, "size" |) ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/alt_bn128.v index 19b83fc..abe4238 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/alt_bn128.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/alt_bn128.v @@ -210,15 +210,6 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) in For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ] do let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "i" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -362,15 +353,6 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) in For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ] do let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "i" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -443,24 +425,6 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_eq (| BinOp.mod_ (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "data" |) - ], - make_dict [] - |), - Constant.int 192 - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let result := @@ -509,32 +473,11 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := Constant.int 32, M.get_name (| globals, "j" |) |) - |):BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "i" |), - Constant.int 192 - |), - BinOp.mult (| - Constant.int 32, - BinOp.add (| - M.get_name (| globals, "j" |), - Constant.int 1 - |) - |) |) |) ], make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "value" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -555,17 +498,20 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.call (| - M.get_field (| M.get_name (| globals, "p" |), "mul_by" |), - make_list [ - M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) - ], - make_dict [] - |), M.call (| - M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) |); + Compare.eq (| + M.call (| + M.get_field (| M.get_name (| globals, "p" |), "mul_by" |), + make_list [ + M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) + ], + make_dict [] + |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |); M.get_name (| globals, "OutOfGasError" |) ], make_dict [] @@ -573,87 +519,29 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.call (| - M.get_field (| M.get_name (| globals, "q" |), "mul_by" |), - make_list [ - M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) - ], - make_dict [] - |), M.call (| - M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) |); + Compare.eq (| + M.call (| + M.get_field (| M.get_name (| globals, "q" |), "mul_by" |), + make_list [ + M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) + ], + make_dict [] + |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |); M.get_name (| globals, "OutOfGasError" |) ], make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "p" |), M.call (| - M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_name (| globals, "q" |), M.call (| - M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let result := - BinOp.mult (| - M.get_name (| globals, "result" |), - M.call (| - M.get_name (| globals, "pairing" |), - make_list [ - M.get_name (| globals, "q" |); - M.get_name (| globals, "p" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "result" |), M.call (| - M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), - make_list [ - Constant.int 1 - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign (| - M.get_field (| M.get_name (| globals, "evm" |), "output" |), - M.call (| - M.get_field (| M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 1 - ], - make_dict [] - |), "to_be_bytes32" |), - make_list [], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/blake2f.v b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/blake2f.v index 5903066..1647d48 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/blake2f.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/blake2f.v @@ -55,13 +55,16 @@ Definition blake2f : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "data" |) - ], - make_dict [] - |), Constant.int 213 |); + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 213 + |); M.get_name (| globals, "InvalidParameter" |) ], make_dict [] @@ -96,10 +99,13 @@ Definition blake2f : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.in (| M.get_name (| globals, "f" |), make_list [ - Constant.int 0; - Constant.int 1 - ] |); + Compare.in (| + M.get_name (| globals, "f" |), + make_list [ + Constant.int 0; + Constant.int 1 + ] + |); M.get_name (| globals, "InvalidParameter" |) ], make_dict [] diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/ecrecover.v index cc351b5..0cbcf16 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/ecrecover.v @@ -188,60 +188,12 @@ Definition ecrecover : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 27 |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 28 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| Constant.int 0, M.get_name (| globals, "r" |) |), - ltac:(M.monadic ( - Compare.gt_e (| M.get_name (| globals, "r" |), M.get_name (| globals, "SECP256K1N" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| Constant.int 0, M.get_name (| globals, "s" |) |), - ltac:(M.monadic ( - Compare.gt_e (| M.get_name (| globals, "s" |), M.get_name (| globals, "SECP256K1N" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: Try *) @@ -252,7 +204,7 @@ Definition ecrecover : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12:Constant.int 32 |) in + |), Constant.int 12 |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/modexp.v index 544949e..3505244 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/modexp.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/modexp.v @@ -192,30 +192,6 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_name (| globals, "base_length" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "modulus_length" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign (| - M.get_field (| M.get_name (| globals, "evm" |), "output" |), - M.call (| - M.get_name (| globals, "Bytes" |), - make_list [], - make_dict [] - |) - |) in - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let base := @@ -278,27 +254,6 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "modulus" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign (| - M.get_field (| M.get_name (| globals, "evm" |), "output" |), - BinOp.mult (| - M.call (| - M.get_name (| globals, "Bytes" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |), - M.get_name (| globals, "modulus_length" |) - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| @@ -383,7 +338,6 @@ Definition complexity : Value.t -> Value.t -> M := M.get_name (| globals, "words" |), Constant.int 2 |) - |) in M.pure Constant.None_)). Definition iterations : Value.t -> Value.t -> M := @@ -410,64 +364,7 @@ Definition iterations : Value.t -> Value.t -> M := Number of iterations. " in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.lt_e (| M.get_name (| globals, "exponent_length" |), Constant.int 32 |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "exponent_head" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let count := - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - Compare.lt_e (| M.get_name (| globals, "exponent_length" |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let bit_length := - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.call (| - M.get_field (| M.get_name (| globals, "exponent_head" |), "bit_length" |), - make_list [], - make_dict [] - |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "bit_length" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let bit_length := BinOp.sub - Constant.int 1 - Constant.int 1 in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let count := - M.get_name (| globals, "bit_length" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let length_part := BinOp.mult (| Constant.int 8, @@ -495,17 +392,6 @@ Definition iterations : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "bits_part" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let bits_part := BinOp.sub - Constant.int 1 - Constant.int 1 in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let count := @@ -532,7 +418,6 @@ Definition iterations : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition gas_cost : Value.t -> Value.t -> M := @@ -604,5 +489,4 @@ Definition gas_cost : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/runtime.v b/CoqOfPython/ethereum/arrow_glacier/vm/runtime.v index 835b46c..2cd7652 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/runtime.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/runtime.v @@ -67,50 +67,19 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := ], make_dict [] |) in - While Compare.lt (| M.get_name (| globals, "pc" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "code" |) - ], - make_dict [] - |) |) do + While Compare.lt (| + M.get_name (| globals, "pc" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) + |) do (* At stmt: unsupported node type: Try *) let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "current_opcode" |), M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), - make_list [ - M.get_name (| globals, "pc" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - (* At expr: unsupported node type: Compare *), - (* then *) - ltac:(M.monadic ( - let push_data_size := - BinOp.add (| - BinOp.sub (| - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) - |), - Constant.int 1 - |) in - let pc := BinOp.add - M.get_name (| globals, "push_data_size" |) - M.get_name (| globals, "push_data_size" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -121,5 +90,4 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := EndWhile. let _ := M.return_ (| M.get_name (| globals, "valid_jump_destinations" |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/stack.v b/CoqOfPython/ethereum/arrow_glacier/vm/stack.v index 42ea42d..ea778df 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/stack.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/stack.v @@ -49,21 +49,6 @@ Definition pop : Value.t -> Value.t -> M := " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "stack" |) - ], - make_dict [] - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "StackUnderflowError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -72,7 +57,6 @@ Definition pop : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). Definition push : Value.t -> Value.t -> M := @@ -91,21 +75,6 @@ Definition push : Value.t -> Value.t -> M := " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "stack" |) - ], - make_dict [] - |), Constant.int 1024 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "StackOverflowError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -116,5 +85,4 @@ Definition push : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/base_types.v b/CoqOfPython/ethereum/base_types.v index 66b442e..8ef03bf 100644 --- a/CoqOfPython/ethereum/base_types.v +++ b/CoqOfPython/ethereum/base_types.v @@ -118,7 +118,6 @@ Definition Uint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -144,7 +143,6 @@ Definition Uint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ) ] @@ -154,42 +152,9 @@ Definition Uint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "value" ] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "value" |); - M.get_name (| globals, "int" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "TypeError" |), - make_list [], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "OverflowError" |), - make_list [], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)) @@ -206,7 +171,6 @@ Definition Uint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -214,40 +178,9 @@ Definition Uint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "right" |); - M.get_name (| globals, "int" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "NotImplemented" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "right" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "OverflowError" |), - make_list [], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -266,7 +199,6 @@ Definition Uint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -281,7 +213,6 @@ Definition Uint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -289,45 +220,9 @@ Definition Uint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "right" |); - M.get_name (| globals, "int" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "NotImplemented" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.lt (| M.get_name (| globals, "right" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.lt (| M.get_name (| globals, "self" |), M.get_name (| globals, "right" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "OverflowError" |), - make_list [], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -346,7 +241,6 @@ Definition Uint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -354,45 +248,9 @@ Definition Uint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "left" ] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "left" |); - M.get_name (| globals, "int" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "NotImplemented" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.lt (| M.get_name (| globals, "left" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.gt (| M.get_name (| globals, "self" |), M.get_name (| globals, "left" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "OverflowError" |), - make_list [], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -411,7 +269,6 @@ Definition Uint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -426,7 +283,6 @@ Definition Uint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -434,40 +290,9 @@ Definition Uint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "right" |); - M.get_name (| globals, "int" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "NotImplemented" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "right" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "OverflowError" |), - make_list [], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -486,7 +311,6 @@ Definition Uint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -501,7 +325,6 @@ Definition Uint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -516,7 +339,6 @@ Definition Uint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -524,40 +346,9 @@ Definition Uint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "right" |); - M.get_name (| globals, "int" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "NotImplemented" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "right" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "OverflowError" |), - make_list [], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -576,7 +367,6 @@ Definition Uint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -584,40 +374,9 @@ Definition Uint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "left" ] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "left" |); - M.get_name (| globals, "int" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "NotImplemented" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "left" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "OverflowError" |), - make_list [], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -636,7 +395,6 @@ Definition Uint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -651,7 +409,6 @@ Definition Uint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -659,40 +416,9 @@ Definition Uint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "right" |); - M.get_name (| globals, "int" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "NotImplemented" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "right" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "OverflowError" |), - make_list [], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -711,7 +437,6 @@ Definition Uint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -719,40 +444,9 @@ Definition Uint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "left" ] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "left" |); - M.get_name (| globals, "int" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "NotImplemented" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "left" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "OverflowError" |), - make_list [], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -771,7 +465,6 @@ Definition Uint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -786,7 +479,6 @@ Definition Uint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -794,40 +486,9 @@ Definition Uint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "right" |); - M.get_name (| globals, "int" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "NotImplemented" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "right" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "OverflowError" |), - make_list [], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let result := @@ -855,7 +516,6 @@ Definition Uint : Value.t := ], make_dict [] |) ] - |) in M.pure Constant.None_)) ); ( @@ -863,40 +523,9 @@ Definition Uint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "left" ] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "left" |); - M.get_name (| globals, "int" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "NotImplemented" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "left" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "OverflowError" |), - make_list [], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let result := @@ -924,7 +553,6 @@ Definition Uint : Value.t := ], make_dict [] |) ] - |) in M.pure Constant.None_)) ); ( @@ -932,88 +560,12 @@ Definition Uint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right"; "modulo" ] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is_not (| M.get_name (| globals, "modulo" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "modulo" |); - M.get_name (| globals, "int" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "NotImplemented" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "modulo" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "OverflowError" |), - make_list [], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "right" |); - M.get_name (| globals, "int" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "NotImplemented" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "right" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "OverflowError" |), - make_list [], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1033,7 +585,6 @@ Definition Uint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -1041,88 +592,12 @@ Definition Uint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "left"; "modulo" ] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is_not (| M.get_name (| globals, "modulo" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "modulo" |); - M.get_name (| globals, "int" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "NotImplemented" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "modulo" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "OverflowError" |), - make_list [], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "left" |); - M.get_name (| globals, "int" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "NotImplemented" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "left" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "OverflowError" |), - make_list [], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1142,7 +617,6 @@ Definition Uint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -1158,7 +632,6 @@ Definition Uint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -1166,40 +639,9 @@ Definition Uint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "right" |); - M.get_name (| globals, "int" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "NotImplemented" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "right" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "OverflowError" |), - make_list [], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1218,7 +660,6 @@ Definition Uint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -1226,40 +667,9 @@ Definition Uint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "left" ] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "left" |); - M.get_name (| globals, "int" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "NotImplemented" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "left" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "OverflowError" |), - make_list [], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1278,7 +688,6 @@ Definition Uint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -1293,7 +702,6 @@ Definition Uint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -1319,7 +727,6 @@ Definition Uint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -1353,7 +760,6 @@ Definition Uint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -1365,28 +771,6 @@ Definition Uint : Value.t := representation, without padding. " in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "number_bytes" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let bit_length := - M.call (| - M.get_field (| M.get_name (| globals, "self" |), "bit_length" |), - make_list [], - make_dict [] - |) in - let number_bytes := - BinOp.floor_div (| - BinOp.add (| - M.get_name (| globals, "bit_length" |), - Constant.int 7 - |), - Constant.int 8 - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1398,7 +782,6 @@ Definition Uint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ) ]. @@ -1425,47 +808,9 @@ Definition FixedUint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "value" ] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "value" |); - M.get_name (| globals, "int" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "TypeError" |), - make_list [], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.lt (| M.get_name (| globals, "value" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.gt (| M.get_name (| globals, "value" |), M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "OverflowError" |), - make_list [], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)) @@ -1482,7 +827,6 @@ Definition FixedUint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -1490,24 +834,6 @@ Definition FixedUint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "right" |); - M.get_name (| globals, "int" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "NotImplemented" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let result := @@ -1520,24 +846,6 @@ Definition FixedUint : Value.t := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.lt (| M.get_name (| globals, "right" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.gt (| M.get_name (| globals, "result" |), M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "OverflowError" |), - make_list [], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1549,7 +857,6 @@ Definition FixedUint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -1566,45 +873,9 @@ Definition FixedUint : Value.t := [`MAX_VALUE`]: ref:ethereum.base_types.FixedUint.MAX_VALUE " in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "right" |); - M.get_name (| globals, "int" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "NotImplemented" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.lt (| M.get_name (| globals, "right" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.gt (| M.get_name (| globals, "right" |), M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "OverflowError" |), - make_list [], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1626,7 +897,6 @@ Definition FixedUint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -1641,7 +911,6 @@ Definition FixedUint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -1649,50 +918,9 @@ Definition FixedUint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "right" |); - M.get_name (| globals, "int" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "NotImplemented" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.lt (| M.get_name (| globals, "right" |), Constant.int 0 |), - ltac:(M.monadic ( - BoolOp.or (| - Compare.gt (| M.get_name (| globals, "right" |), M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) |), - ltac:(M.monadic ( - Compare.lt (| M.get_name (| globals, "self" |), M.get_name (| globals, "right" |) |) - )) - |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "OverflowError" |), - make_list [], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1711,7 +939,6 @@ Definition FixedUint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -1728,45 +955,9 @@ Definition FixedUint : Value.t := [`MAX_VALUE`]: ref:ethereum.base_types.FixedUint.MAX_VALUE " in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "right" |); - M.get_name (| globals, "int" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "NotImplemented" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.lt (| M.get_name (| globals, "right" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.gt (| M.get_name (| globals, "right" |), M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "OverflowError" |), - make_list [], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1788,7 +979,6 @@ Definition FixedUint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -1796,50 +986,9 @@ Definition FixedUint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "left" ] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "left" |); - M.get_name (| globals, "int" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "NotImplemented" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.lt (| M.get_name (| globals, "left" |), Constant.int 0 |), - ltac:(M.monadic ( - BoolOp.or (| - Compare.gt (| M.get_name (| globals, "left" |), M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) |), - ltac:(M.monadic ( - Compare.gt (| M.get_name (| globals, "self" |), M.get_name (| globals, "left" |) |) - )) - |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "OverflowError" |), - make_list [], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1858,7 +1007,6 @@ Definition FixedUint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -1873,7 +1021,6 @@ Definition FixedUint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -1881,24 +1028,6 @@ Definition FixedUint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "right" |); - M.get_name (| globals, "int" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "NotImplemented" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let result := @@ -1911,24 +1040,6 @@ Definition FixedUint : Value.t := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.lt (| M.get_name (| globals, "right" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.gt (| M.get_name (| globals, "result" |), M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "OverflowError" |), - make_list [], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1940,7 +1051,6 @@ Definition FixedUint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -1957,45 +1067,9 @@ Definition FixedUint : Value.t := [`MAX_VALUE`]: ref:ethereum.base_types.FixedUint.MAX_VALUE " in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "right" |); - M.get_name (| globals, "int" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "NotImplemented" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.lt (| M.get_name (| globals, "right" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.gt (| M.get_name (| globals, "right" |), M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "OverflowError" |), - make_list [], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -2017,7 +1091,6 @@ Definition FixedUint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -2032,7 +1105,6 @@ Definition FixedUint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -2047,7 +1119,6 @@ Definition FixedUint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -2055,45 +1126,9 @@ Definition FixedUint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "right" |); - M.get_name (| globals, "int" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "NotImplemented" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.lt (| M.get_name (| globals, "right" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.gt (| M.get_name (| globals, "right" |), M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "OverflowError" |), - make_list [], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -2112,7 +1147,6 @@ Definition FixedUint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -2120,45 +1154,9 @@ Definition FixedUint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "left" ] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "left" |); - M.get_name (| globals, "int" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "NotImplemented" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.lt (| M.get_name (| globals, "left" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.gt (| M.get_name (| globals, "left" |), M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "OverflowError" |), - make_list [], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -2177,7 +1175,6 @@ Definition FixedUint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -2192,7 +1189,6 @@ Definition FixedUint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -2200,45 +1196,9 @@ Definition FixedUint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "right" |); - M.get_name (| globals, "int" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "NotImplemented" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.lt (| M.get_name (| globals, "right" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.gt (| M.get_name (| globals, "right" |), M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "OverflowError" |), - make_list [], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -2257,7 +1217,6 @@ Definition FixedUint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -2265,45 +1224,9 @@ Definition FixedUint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "left" ] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "left" |); - M.get_name (| globals, "int" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "NotImplemented" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.lt (| M.get_name (| globals, "left" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.gt (| M.get_name (| globals, "left" |), M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "OverflowError" |), - make_list [], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -2322,7 +1245,6 @@ Definition FixedUint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -2337,7 +1259,6 @@ Definition FixedUint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -2345,45 +1266,9 @@ Definition FixedUint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "right" |); - M.get_name (| globals, "int" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "NotImplemented" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.lt (| M.get_name (| globals, "right" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.gt (| M.get_name (| globals, "right" |), M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "OverflowError" |), - make_list [], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let result := @@ -2417,7 +1302,6 @@ Definition FixedUint : Value.t := ], make_dict [] |) ] - |) in M.pure Constant.None_)) ); ( @@ -2425,45 +1309,9 @@ Definition FixedUint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "left" ] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "left" |); - M.get_name (| globals, "int" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "NotImplemented" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.lt (| M.get_name (| globals, "left" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.gt (| M.get_name (| globals, "left" |), M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "OverflowError" |), - make_list [], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let result := @@ -2497,7 +1345,6 @@ Definition FixedUint : Value.t := ], make_dict [] |) ] - |) in M.pure Constant.None_)) ); ( @@ -2505,77 +1352,9 @@ Definition FixedUint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right"; "modulo" ] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is_not (| M.get_name (| globals, "modulo" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "modulo" |); - M.get_name (| globals, "int" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "NotImplemented" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.lt (| M.get_name (| globals, "modulo" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.gt (| M.get_name (| globals, "modulo" |), M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "OverflowError" |), - make_list [], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "right" |); - M.get_name (| globals, "int" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "NotImplemented" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let result := @@ -2589,29 +1368,6 @@ Definition FixedUint : Value.t := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.lt (| M.get_name (| globals, "right" |), Constant.int 0 |), - ltac:(M.monadic ( - BoolOp.or (| - Compare.gt (| M.get_name (| globals, "right" |), M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) |), - ltac:(M.monadic ( - Compare.gt (| M.get_name (| globals, "result" |), M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) |) - )) - |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "OverflowError" |), - make_list [], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -2623,7 +1379,6 @@ Definition FixedUint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -2642,98 +1397,12 @@ Definition FixedUint : Value.t := [`MAX_VALUE`]: ref:ethereum.base_types.FixedUint.MAX_VALUE " in let _ := - (* if *) - M.if_then_else (| - Compare.is_not (| M.get_name (| globals, "modulo" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "modulo" |); - M.get_name (| globals, "int" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "NotImplemented" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.lt (| M.get_name (| globals, "modulo" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.gt (| M.get_name (| globals, "modulo" |), M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "OverflowError" |), - make_list [], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "right" |); - M.get_name (| globals, "int" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "NotImplemented" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.lt (| M.get_name (| globals, "right" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.gt (| M.get_name (| globals, "right" |), M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "OverflowError" |), - make_list [], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -2756,7 +1425,6 @@ Definition FixedUint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -2764,98 +1432,12 @@ Definition FixedUint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "left"; "modulo" ] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is_not (| M.get_name (| globals, "modulo" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "modulo" |); - M.get_name (| globals, "int" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "NotImplemented" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.lt (| M.get_name (| globals, "modulo" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.gt (| M.get_name (| globals, "modulo" |), M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "OverflowError" |), - make_list [], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "left" |); - M.get_name (| globals, "int" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "NotImplemented" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.lt (| M.get_name (| globals, "left" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.gt (| M.get_name (| globals, "left" |), M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "OverflowError" |), - make_list [], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -2875,7 +1457,6 @@ Definition FixedUint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -2891,7 +1472,6 @@ Definition FixedUint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -2899,45 +1479,9 @@ Definition FixedUint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "right" |); - M.get_name (| globals, "int" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "NotImplemented" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.lt (| M.get_name (| globals, "right" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.gt (| M.get_name (| globals, "right" |), M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "OverflowError" |), - make_list [], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -2956,7 +1500,6 @@ Definition FixedUint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -2964,45 +1507,9 @@ Definition FixedUint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "right" |); - M.get_name (| globals, "int" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "NotImplemented" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.lt (| M.get_name (| globals, "right" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.gt (| M.get_name (| globals, "right" |), M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "OverflowError" |), - make_list [], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -3021,7 +1528,6 @@ Definition FixedUint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -3029,45 +1535,9 @@ Definition FixedUint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "right" |); - M.get_name (| globals, "int" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "NotImplemented" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.lt (| M.get_name (| globals, "right" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.gt (| M.get_name (| globals, "right" |), M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "OverflowError" |), - make_list [], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -3086,7 +1556,6 @@ Definition FixedUint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -3094,45 +1563,9 @@ Definition FixedUint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "left" ] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "left" |); - M.get_name (| globals, "int" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "NotImplemented" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.lt (| M.get_name (| globals, "left" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.gt (| M.get_name (| globals, "left" |), M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "OverflowError" |), - make_list [], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -3151,7 +1584,6 @@ Definition FixedUint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -3166,7 +1598,6 @@ Definition FixedUint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -3191,7 +1622,6 @@ Definition FixedUint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -3199,24 +1629,6 @@ Definition FixedUint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "shift_by" ] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "shift_by" |); - M.get_name (| globals, "int" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "NotImplemented" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -3235,7 +1647,6 @@ Definition FixedUint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -3269,7 +1680,6 @@ Definition FixedUint : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ) ]. @@ -3287,25 +1697,6 @@ Definition U256 : Value.t := from its big endian representation. " in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "buffer" |) - ], - make_dict [] - |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "ValueError" |), - make_list [], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -3323,7 +1714,6 @@ Definition U256 : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -3335,23 +1725,6 @@ Definition U256 : Value.t := complement. " in let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "cls" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -3365,7 +1738,6 @@ Definition U256 : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ) ] @@ -3393,7 +1765,6 @@ Definition U256 : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -3404,27 +1775,6 @@ Definition U256 : Value.t := Decodes a signed integer from its two's complement representation. " in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.call (| - M.get_field (| M.get_name (| globals, "self" |), "bit_length" |), - make_list [], - make_dict [] - |), Constant.int 256 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "int" |), - make_list [ - M.get_name (| globals, "self" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -3438,7 +1788,6 @@ Definition U256 : Value.t := |), M.get_name (| globals, "U256_CEIL_VALUE" |) |) - |) in M.pure Constant.None_)) ) ]. @@ -3458,25 +1807,6 @@ Definition U32 : Value.t := from its little endian representation. " in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "buffer" |) - ], - make_dict [] - |), Constant.int 4 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "ValueError" |), - make_list [], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -3494,7 +1824,6 @@ Definition U32 : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ) ] @@ -3522,7 +1851,6 @@ Definition U32 : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -3556,7 +1884,6 @@ Definition U32 : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ) ]. @@ -3576,25 +1903,6 @@ Definition U64 : Value.t := from its little endian representation. " in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "buffer" |) - ], - make_dict [] - |), Constant.int 8 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "ValueError" |), - make_list [], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -3612,7 +1920,6 @@ Definition U64 : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -3624,25 +1931,6 @@ Definition U64 : Value.t := big endian representation. " in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "buffer" |) - ], - make_dict [] - |), Constant.int 8 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "ValueError" |), - make_list [], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -3660,7 +1948,6 @@ Definition U64 : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ) ] @@ -3688,7 +1975,6 @@ Definition U64 : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -3722,7 +2008,6 @@ Definition U64 : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ) ]. @@ -3787,32 +2072,10 @@ Definition FixedBytes : Value.t := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "result" |) - ], - make_dict [] - |), M.get_field (| M.get_name (| globals, "cls" |), "LENGTH" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "ValueError" |), - make_list [ - (* At expr: unsupported node type: JoinedStr *) - ], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| M.get_name (| globals, "result" |) - |) in M.pure Constant.None_)) ) ]. @@ -3910,29 +2173,6 @@ Definition _setattr_function : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "attr"; "value" ] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "getattr" |), - make_list [ - M.get_name (| globals, "self" |); - Constant.str "_frozen"; - Constant.None_ - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "Exception" |), - make_list [ - Constant.str "Mutating frozen dataclasses is not allowed." - ], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_name (| globals, "object" |), "__setattr__" |), make_list [ @@ -3950,21 +2190,6 @@ Definition _delattr_function : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "attr" ] |) in let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "self" |), "_frozen" |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "Exception" |), - make_list [ - Constant.str "Mutating frozen dataclasses is not allowed." - ], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_name (| globals, "object" |), "__delattr__" |), make_list [ @@ -3983,7 +2208,6 @@ Definition _make_init_function : Value.t -> Value.t -> M := (* At stmt: unsupported node type: FunctionDef *) let _ := M.return_ (| M.get_name (| globals, "init_function" |) - |) in M.pure Constant.None_)). Definition slotted_freezable : Value.t -> Value.t -> M := @@ -4049,7 +2273,6 @@ Definition slotted_freezable : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition S : Value.t := M.run ltac:(M.monadic ( @@ -4107,5 +2330,4 @@ Definition modify : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "new_obj" |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/bloom.v b/CoqOfPython/ethereum/berlin/bloom.v index 04b5d9f..04650ff 100644 --- a/CoqOfPython/ethereum/berlin/bloom.v +++ b/CoqOfPython/ethereum/berlin/bloom.v @@ -72,10 +72,7 @@ Definition add_to_bloom : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |):BinOp.add (| - M.get_name (| globals, "idx" |), - Constant.int 2 - |) |) + M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |) |) ], make_dict [] |), @@ -160,5 +157,4 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/fork.v b/CoqOfPython/ethereum/berlin/fork.v new file mode 100644 index 0000000..bcd2a23 --- /dev/null +++ b/CoqOfPython/ethereum/berlin/fork.v @@ -0,0 +1,2193 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Specification +^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Entry point for the Ethereum specification. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". + +Require ethereum.crypto.elliptic_curve. +Axiom ethereum_crypto_elliptic_curve_SECP256K1N : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.ethash. +Axiom ethereum_ethash_dataset_size : + IsGlobalAlias globals ethereum.ethash.globals "dataset_size". +Axiom ethereum_ethash_generate_cache : + IsGlobalAlias globals ethereum.ethash.globals "generate_cache". +Axiom ethereum_ethash_hashimoto_light : + IsGlobalAlias globals ethereum.ethash.globals "hashimoto_light". + +Require ethereum.exceptions. +Axiom ethereum_exceptions_InvalidBlock : + IsGlobalAlias globals ethereum.exceptions.globals "InvalidBlock". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U64 : + IsGlobalAlias globals base_types.globals "U64". +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_U256_CEIL_VALUE : + IsGlobalAlias globals base_types.globals "U256_CEIL_VALUE". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". + +Require __init__. +Axiom __init___vm : + IsGlobalAlias globals __init__.globals "vm". + +Require blocks. +Axiom blocks_Block : + IsGlobalAlias globals blocks.globals "Block". +Axiom blocks_Header : + IsGlobalAlias globals blocks.globals "Header". +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". +Axiom blocks_Receipt : + IsGlobalAlias globals blocks.globals "Receipt". + +Require bloom. +Axiom bloom_logs_bloom : + IsGlobalAlias globals bloom.globals "logs_bloom". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Require state. +Axiom state_State : + IsGlobalAlias globals state.globals "State". +Axiom state_account_exists_and_is_empty : + IsGlobalAlias globals state.globals "account_exists_and_is_empty". +Axiom state_create_ether : + IsGlobalAlias globals state.globals "create_ether". +Axiom state_destroy_account : + IsGlobalAlias globals state.globals "destroy_account". +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". +Axiom state_increment_nonce : + IsGlobalAlias globals state.globals "increment_nonce". +Axiom state_set_account_balance : + IsGlobalAlias globals state.globals "set_account_balance". +Axiom state_state_root : + IsGlobalAlias globals state.globals "state_root". + +Require transactions. +Axiom transactions_TX_ACCESS_LIST_ADDRESS_COST : + IsGlobalAlias globals transactions.globals "TX_ACCESS_LIST_ADDRESS_COST". +Axiom transactions_TX_ACCESS_LIST_STORAGE_KEY_COST : + IsGlobalAlias globals transactions.globals "TX_ACCESS_LIST_STORAGE_KEY_COST". +Axiom transactions_TX_BASE_COST : + IsGlobalAlias globals transactions.globals "TX_BASE_COST". +Axiom transactions_TX_CREATE_COST : + IsGlobalAlias globals transactions.globals "TX_CREATE_COST". +Axiom transactions_TX_DATA_COST_PER_NON_ZERO : + IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_NON_ZERO". +Axiom transactions_TX_DATA_COST_PER_ZERO : + IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_ZERO". +Axiom transactions_AccessListTransaction : + IsGlobalAlias globals transactions.globals "AccessListTransaction". +Axiom transactions_LegacyTransaction : + IsGlobalAlias globals transactions.globals "LegacyTransaction". +Axiom transactions_Transaction : + IsGlobalAlias globals transactions.globals "Transaction". +Axiom transactions_decode_transaction : + IsGlobalAlias globals transactions.globals "decode_transaction". +Axiom transactions_encode_transaction : + IsGlobalAlias globals transactions.globals "encode_transaction". + +Require trie. +Axiom trie_Trie : + IsGlobalAlias globals trie.globals "Trie". +Axiom trie_root : + IsGlobalAlias globals trie.globals "root". +Axiom trie_trie_set : + IsGlobalAlias globals trie.globals "trie_set". + +Require utils.message. +Axiom utils_message_prepare_message : + IsGlobalAlias globals utils.message.globals "prepare_message". + +Require vm.interpreter. +Axiom vm_interpreter_process_message_call : + IsGlobalAlias globals vm.interpreter.globals "process_message_call". + +Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mult (| + Constant.int 2, + BinOp.pow (| + Constant.int 10, + Constant.int 18 + |) + |) + ], + make_dict [] + |) +)). + +Definition GAS_LIMIT_ADJUSTMENT_FACTOR : Value.t := M.run ltac:(M.monadic ( + Constant.int 1024 +)). + +Definition GAS_LIMIT_MINIMUM : Value.t := M.run ltac:(M.monadic ( + Constant.int 5000 +)). + +Definition MINIMUM_DIFFICULTY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 131072 + ], + make_dict [] + |) +)). + +Definition MAX_OMMER_DEPTH : Value.t := M.run ltac:(M.monadic ( + Constant.int 6 +)). + +Definition BOMB_DELAY_BLOCKS : Value.t := M.run ltac:(M.monadic ( + Constant.int 9000000 +)). + +Definition EMPTY_OMMER_HASH : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_list [] + ], + make_dict [] + |) + ], + make_dict [] + |) +)). + +Definition BlockChain : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition apply_fork : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "old" ] |) in + let _ := Constant.str " + Transforms the state from the previous hard fork (`old`) into the block + chain object for this hard fork and returns it. + + When forks need to implement an irregular state transition, this function + is used to handle the irregularity. See the :ref:`DAO Fork ` for + an example. + + Parameters + ---------- + old : + Previous block chain object. + + Returns + ------- + new : `BlockChain` + Upgraded block chain object for this hard fork. + " in + let _ := M.return_ (| + M.get_name (| globals, "old" |) + M.pure Constant.None_)). + +Definition get_last_256_block_hashes : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "chain" ] |) in + let _ := Constant.str " + Obtain the list of hashes of the previous 256 blocks in order of + increasing block number. + + This function will return less hashes for the first 256 blocks. + + The ``BLOCKHASH`` opcode needs to access the latest hashes on the chain, + therefore this function retrieves them. + + Parameters + ---------- + chain : + History and current state. + + Returns + ------- + recent_block_hashes : `List[Hash32]` + Hashes of the recent 256 blocks in order of increasing block number. + " in + let recent_blocks := + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |) |) in + let _ := + M.pure Constant.None_ + )) |) in + let recent_block_hashes := + make_list [] in + For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_blocks" |) do + let prev_block_hash := + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), + make_list [ + M.get_name (| globals, "prev_block_hash" |) + ], + make_dict [] + |) in + EndFor. + let most_recent_block_hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_field (| M.get_subscript (| M.get_name (| globals, "recent_blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), + make_list [ + M.get_name (| globals, "most_recent_block_hash" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "recent_block_hashes" |) + M.pure Constant.None_)). + +Definition state_transition : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "chain"; "block" ] |) in + let _ := Constant.str " + Attempts to apply a block to an existing block chain. + + All parts of the block's contents need to be verified before being added + to the chain. Blocks are verified by ensuring that the contents of the + block make logical sense with the contents of the parent block. The + information in the block's header must also match the corresponding + information in the block. + + To implement Ethereum, in theory clients are only required to store the + most recent 255 blocks of the chain since as far as execution is + concerned, only those blocks are accessed. Practically, however, clients + should store more blocks to handle reorgs. + + Parameters + ---------- + chain : + History and current state. + block : + Block to apply to `chain`. + " in + let parent_header := + M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) in + let _ := M.call (| + M.get_name (| globals, "validate_header" |), + make_list [ + M.get_field (| M.get_name (| globals, "block" |), "header" |); + M.get_name (| globals, "parent_header" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "validate_ommers" |), + make_list [ + M.get_field (| M.get_name (| globals, "block" |), "ommers" |); + M.get_field (| M.get_name (| globals, "block" |), "header" |); + M.get_name (| globals, "chain" |) + ], + make_dict [] + |) in + let apply_body_output := + M.call (| + M.get_name (| globals, "apply_body" |), + make_list [ + M.get_field (| M.get_name (| globals, "chain" |), "state" |); + M.call (| + M.get_name (| globals, "get_last_256_block_hashes" |), + make_list [ + M.get_name (| globals, "chain" |) + ], + make_dict [] + |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "coinbase" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "number" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "gas_limit" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "timestamp" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "difficulty" |); + M.get_field (| M.get_name (| globals, "block" |), "transactions" |); + M.get_field (| M.get_name (| globals, "block" |), "ommers" |); + M.get_field (| M.get_name (| globals, "chain" |), "chain_id" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_gas_used" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "gas_used" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "transactions_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "transactions_root" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "state_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "state_root" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "receipt_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "receipt_root" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_logs_bloom" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "bloom" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), "append" |), + make_list [ + M.get_name (| globals, "block" |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition validate_header : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header"; "parent_header" ] |) in + let _ := Constant.str " + Verifies a block header. + + In order to consider a block's header valid, the logic for the + quantities in the header should match the logic for the block itself. + For example the header timestamp should be greater than the block's parent + timestamp because the block was created *after* the parent block. + Additionally, the block's number should be directly following the parent + block's number since it is the next block in the sequence. + + Parameters + ---------- + header : + Header to check for correctness. + parent_header : + Parent Header of the header to check for correctness + " in + let parent_has_ommers := + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "parent_header" |), "ommers_hash" |), + M.get_name (| globals, "EMPTY_OMMER_HASH" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt (| + M.get_field (| M.get_name (| globals, "header" |), "timestamp" |), + M.get_field (| M.get_name (| globals, "parent_header" |), "timestamp" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "number" |), + BinOp.add (| + M.get_field (| M.get_name (| globals, "parent_header" |), "number" |), + Constant.int 1 + |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + M.call (| + M.get_name (| globals, "check_gas_limit" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "gas_limit" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "gas_limit" |) + ], + make_dict [] + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) + ], + make_dict [] + |), + Constant.int 32 + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let block_difficulty := + M.call (| + M.get_name (| globals, "calculate_block_difficulty" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "number" |); + M.get_field (| M.get_name (| globals, "header" |), "timestamp" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "timestamp" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "difficulty" |); + M.get_name (| globals, "parent_has_ommers" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "difficulty" |), + M.get_name (| globals, "block_difficulty" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let block_parent_hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "parent_header" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |), + M.get_name (| globals, "block_parent_hash" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "validate_proof_of_work" |), + make_list [ + M.get_name (| globals, "header" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header" ] |) in + let _ := Constant.str " + Generate rlp hash of the header which is to be used for Proof-of-Work + verification. + + In other words, the PoW artefacts `mix_digest` and `nonce` are ignored + while calculating this hash. + + A particular PoW is valid for a single hash, that hash is computed by + this function. The `nonce` and `mix_digest` are omitted from this hash + because they are being changed by miners in their search for a sufficient + proof-of-work. + + Parameters + ---------- + header : + The header object for which the hash is to be generated. + + Returns + ------- + hash : `Hash32` + The PoW valid rlp hash of the passed in header. + " in + let header_data_without_pow_artefacts := + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |); + M.get_field (| M.get_name (| globals, "header" |), "ommers_hash" |); + M.get_field (| M.get_name (| globals, "header" |), "coinbase" |); + M.get_field (| M.get_name (| globals, "header" |), "state_root" |); + M.get_field (| M.get_name (| globals, "header" |), "transactions_root" |); + M.get_field (| M.get_name (| globals, "header" |), "receipt_root" |); + M.get_field (| M.get_name (| globals, "header" |), "bloom" |); + M.get_field (| M.get_name (| globals, "header" |), "difficulty" |); + M.get_field (| M.get_name (| globals, "header" |), "number" |); + M.get_field (| M.get_name (| globals, "header" |), "gas_limit" |); + M.get_field (| M.get_name (| globals, "header" |), "gas_used" |); + M.get_field (| M.get_name (| globals, "header" |), "timestamp" |); + M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) + ] in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "header_data_without_pow_artefacts" |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition validate_proof_of_work : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header" ] |) in + let _ := Constant.str " + Validates the Proof of Work constraints. + + In order to verify that a miner's proof-of-work is valid for a block, a + ``mix-digest`` and ``result`` are calculated using the ``hashimoto_light`` + hash function. The mix digest is a hash of the header and the nonce that + is passed through and it confirms whether or not proof-of-work was done + on the correct block. The result is the actual hash value of the block. + + Parameters + ---------- + header : + Header of interest. + " in + let header_hash := + M.call (| + M.get_name (| globals, "generate_header_hash_for_pow" |), + make_list [ + M.get_name (| globals, "header" |) + ], + make_dict [] + |) in + let cache := + M.call (| + M.get_name (| globals, "generate_cache" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "number" |) + ], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "mix_digest" |); M.get_name (| globals, "result" |) ], + M.call (| + M.get_name (| globals, "hashimoto_light" |), + make_list [ + M.get_name (| globals, "header_hash" |); + M.get_field (| M.get_name (| globals, "header" |), "nonce" |); + M.get_name (| globals, "cache" |); + M.call (| + M.get_name (| globals, "dataset_size" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "number" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_name (| globals, "mix_digest" |), + M.get_field (| M.get_name (| globals, "header" |), "mix_digest" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "result" |) + ], + make_dict [] + |), + BinOp.floor_div (| + M.get_name (| globals, "U256_CEIL_VALUE" |), + M.get_field (| M.get_name (| globals, "header" |), "difficulty" |) + |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition check_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx"; "gas_available"; "chain_id" ] |) in + let _ := Constant.str " + Check if the transaction is includable in the block. + + Parameters + ---------- + tx : + The transaction. + gas_available : + The gas remaining in the block. + chain_id : + The ID of the current chain. + + Returns + ------- + sender_address : + The sender of the transaction. + + Raises + ------ + InvalidBlock : + If the transaction is not includable. + " in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_name (| globals, "gas_available" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let sender_address := + M.call (| + M.get_name (| globals, "recover_sender" |), + make_list [ + M.get_name (| globals, "chain_id" |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "sender_address" |) + M.pure Constant.None_)). + +Definition make_receipt : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx"; "error"; "cumulative_gas_used"; "logs" ] |) in + let _ := Constant.str " + Make the receipt for a transaction that was executed. + + Parameters + ---------- + tx : + The executed transaction. + error : + Error in the top level frame of the transaction, if any. + cumulative_gas_used : + The total gas used so far in the block after the transaction was + executed. + logs : + The logs produced by the transaction. + + Returns + ------- + receipt : + The receipt for the transaction. + " in + let receipt := + M.call (| + M.get_name (| globals, "Receipt" |), + make_list [], + make_dict [] + |) in + let _ := + let _ := M.return_ (| + M.get_name (| globals, "receipt" |) + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition ApplyBodyOutput : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition apply_body : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "block_hashes"; "coinbase"; "block_number"; "block_gas_limit"; "block_time"; "block_difficulty"; "transactions"; "ommers"; "chain_id" ] |) in + let _ := Constant.str " + Executes a block. + + Many of the contents of a block are stored in data structures called + tries. There is a transactions trie which is similar to a ledger of the + transactions stored in the current block. There is also a receipts trie + which stores the results of executing a transaction, like the post state + and gas used. This function creates and executes the block that is to be + added to the chain. + + Parameters + ---------- + state : + Current account state. + block_hashes : + List of hashes of the previous 256 blocks in the order of + increasing block number. + coinbase : + Address of account which receives block reward and transaction fees. + block_number : + Position of the block within the chain. + block_gas_limit : + Initial amount of gas available for execution in this block. + block_time : + Time the block was produced, measured in seconds since the epoch. + block_difficulty : + Difficulty of the block. + transactions : + Transactions included in the block. + ommers : + Headers of ancestor blocks which are not direct parents (formerly + uncles.) + chain_id : + ID of the executing chain. + + Returns + ------- + apply_body_output : `ApplyBodyOutput` + Output of applying the block body to the state. + " in + let gas_available := + M.get_name (| globals, "block_gas_limit" |) in +(* At stmt: unsupported node type: AnnAssign *) +(* At stmt: unsupported node type: AnnAssign *) +(* At stmt: unsupported node type: AnnAssign *) + For make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "tx" |) ] in M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.call (| + M.get_name (| globals, "map" |), + make_list [ + M.get_name (| globals, "decode_transaction" |); + M.get_name (| globals, "transactions" |) + ], + make_dict [] + |) + ], + make_dict [] + |) do + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "transactions_trie" |); + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "i" |) + ], + make_dict [] + |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "encode_transaction" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let sender_address := + M.call (| + M.get_name (| globals, "check_transaction" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "gas_available" |); + M.get_name (| globals, "chain_id" |) + ], + make_dict [] + |) in + let env := + M.call (| + M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |); M.get_name (| globals, "error" |) ], + M.call (| + M.get_name (| globals, "process_transaction" |), + make_list [ + M.get_name (| globals, "env" |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) in + let gas_available := BinOp.sub + M.get_name (| globals, "gas_used" |) + M.get_name (| globals, "gas_used" |) in + let receipt := + M.call (| + M.get_name (| globals, "make_receipt" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "error" |); + BinOp.sub (| + M.get_name (| globals, "block_gas_limit" |), + M.get_name (| globals, "gas_available" |) + |); + M.get_name (| globals, "logs" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "receipts_trie" |); + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "i" |) + ], + make_dict [] + |) + ], + make_dict [] + |); + M.get_name (| globals, "receipt" |) + ], + make_dict [] + |) in + let block_logs := BinOp.add + M.get_name (| globals, "logs" |) + M.get_name (| globals, "logs" |) in + EndFor. + let _ := M.call (| + M.get_name (| globals, "pay_rewards" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "block_number" |); + M.get_name (| globals, "coinbase" |); + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |) in + let block_gas_used := + BinOp.sub (| + M.get_name (| globals, "block_gas_limit" |), + M.get_name (| globals, "gas_available" |) + |) in + let block_logs_bloom := + M.call (| + M.get_name (| globals, "logs_bloom" |), + make_list [ + M.get_name (| globals, "block_logs" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ApplyBodyOutput" |), + make_list [ + M.get_name (| globals, "block_gas_used" |); + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_name (| globals, "transactions_trie" |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_name (| globals, "receipts_trie" |) + ], + make_dict [] + |); + M.get_name (| globals, "block_logs_bloom" |); + M.call (| + M.get_name (| globals, "state_root" |), + make_list [ + M.get_name (| globals, "state" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition validate_ommers : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "ommers"; "block_header"; "chain" ] |) in + let _ := Constant.str " + Validates the ommers mentioned in the block. + + An ommer block is a block that wasn't canonically added to the + blockchain because it wasn't validated as fast as the canonical block + but was mined at the same time. + + To be considered valid, the ommers must adhere to the rules defined in + the Ethereum protocol. The maximum amount of ommers is 2 per block and + there cannot be duplicate ommers in a block. Many of the other ommer + constraints are listed in the in-line comments of this function. + + Parameters + ---------- + ommers : + List of ommers mentioned in the current block. + block_header: + The header of current block. + chain : + History and current state. + " in + let block_hash := + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "block_header" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + M.get_field (| M.get_name (| globals, "block_header" |), "ommers_hash" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.and (| + Compare.lt_e (| + Constant.int 1, + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |), + ltac:(M.monadic ( + Compare.lt (| + M.get_field (| M.get_name (| globals, "ommer" |), "number" |), + M.get_field (| M.get_name (| globals, "block_header" |), "number" |) + |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let ommer_parent_header := + M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), BinOp.sub (| + UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) |), + Constant.int 1 + |) |), "header" |) in + let _ := M.call (| + M.get_name (| globals, "validate_header" |), + make_list [ + M.get_name (| globals, "ommer" |); + M.get_name (| globals, "ommer_parent_header" |) + ], + make_dict [] + |) in + EndFor. + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + Constant.int 2 + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let ommers_hashes := + (* At expr: unsupported node type: ListComp *) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers_hashes" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_name (| globals, "set" |), + make_list [ + M.get_name (| globals, "ommers_hashes" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let recent_canonical_blocks := + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| BinOp.add (| + M.get_name (| globals, "MAX_OMMER_DEPTH" |), + Constant.int 1 + |) |) |) in + let recent_canonical_block_hashes := + (* At expr: unsupported node type: SetComp *) in +(* At stmt: unsupported node type: AnnAssign *) + For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_canonical_blocks" |) do + let recent_ommers_hashes := + M.call (| + M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), + make_list [ + (* At expr: unsupported node type: SetComp *) + ], + make_dict [] + |) in + EndFor. + For make_tuple [ M.get_name (| globals, "ommer_index" |); M.get_name (| globals, "ommer" |) ] in M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |) do + let ommer_hash := + M.get_subscript (| M.get_name (| globals, "ommers_hashes" |), M.get_name (| globals, "ommer_index" |) |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_eq (| + M.get_name (| globals, "ommer_hash" |), + M.get_name (| globals, "block_hash" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_in (| + M.get_name (| globals, "ommer_hash" |), + M.get_name (| globals, "recent_canonical_block_hashes" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_in (| + M.get_name (| globals, "ommer_hash" |), + M.get_name (| globals, "recent_ommers_hashes" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let ommer_age := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.and (| + Compare.lt_e (| + Constant.int 1, + M.get_name (| globals, "ommer_age" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_name (| globals, "ommer_age" |), + M.get_name (| globals, "MAX_OMMER_DEPTH" |) + |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.in (| + M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), + M.get_name (| globals, "recent_canonical_block_hashes" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), + M.get_field (| M.get_name (| globals, "block_header" |), "parent_hash" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_)). + +Definition pay_rewards : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "block_number"; "coinbase"; "ommers" ] |) in + let _ := Constant.str " + Pay rewards to the block miner as well as the ommers miners. + + The miner of the canonical block is rewarded with the predetermined + block reward, ``BLOCK_REWARD``, plus a variable award based off of the + number of ommer blocks that were mined around the same time, and included + in the canonical block's header. An ommer block is a block that wasn't + added to the canonical blockchain because it wasn't validated as fast as + the accepted block but was mined at the same time. Although not all blocks + that are mined are added to the canonical chain, miners are still paid a + reward for their efforts. This reward is called an ommer reward and is + calculated based on the number associated with the ommer block that they + mined. + + Parameters + ---------- + state : + Current account state. + block_number : + Position of the block within the chain. + coinbase : + Address of account which receives block reward and transaction fees. + ommers : + List of ommers mentioned in the current block. + " in + let miner_reward := + BinOp.add (| + M.get_name (| globals, "BLOCK_REWARD" |), + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + BinOp.floor_div (| + M.get_name (| globals, "BLOCK_REWARD" |), + Constant.int 32 + |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "create_ether" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "coinbase" |); + M.get_name (| globals, "miner_reward" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do + let ommer_age := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "block_number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) + ], + make_dict [] + |) in + let ommer_miner_reward := + BinOp.floor_div (| + BinOp.mult (| + BinOp.sub (| + Constant.int 8, + M.get_name (| globals, "ommer_age" |) + |), + M.get_name (| globals, "BLOCK_REWARD" |) + |), + Constant.int 8 + |) in + let _ := M.call (| + M.get_name (| globals, "create_ether" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_field (| M.get_name (| globals, "ommer" |), "coinbase" |); + M.get_name (| globals, "ommer_miner_reward" |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_)). + +Definition process_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "env"; "tx" ] |) in + let _ := Constant.str " + Execute a transaction against the provided environment. + + This function processes the actions needed to execute a transaction. + It decrements the sender's account after calculating the gas fee and + refunds them the proper amount after execution. Calling contracts, + deploying code, and incrementing nonces are all examples of actions that + happen within this function or from a call made within this function. + + Accounts that are marked for deletion are processed and destroyed after + execution. + + Parameters + ---------- + env : + Environment for the Ethereum Virtual Machine. + tx : + Transaction to execute. + + Returns + ------- + gas_left : `ethereum.base_types.U256` + Remaining gas after execution. + logs : `Tuple[ethereum.blocks.Log, ...]` + Logs generated during execution. + " in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + M.call (| + M.get_name (| globals, "validate_transaction" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let sender := + M.get_field (| M.get_name (| globals, "env" |), "origin" |) in + let sender_account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |) in + let gas_fee := + BinOp.mult (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "sender_account" |), "nonce" |), + M.get_field (| M.get_name (| globals, "tx" |), "nonce" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt_e (| + M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), + BinOp.add (| + M.get_name (| globals, "gas_fee" |), + M.get_field (| M.get_name (| globals, "tx" |), "value" |) + |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "sender_account" |), "code" |), + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [], + make_dict [] + |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let gas := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.call (| + M.get_name (| globals, "calculate_intrinsic_cost" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) in + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |) in + let sender_balance_after_gas_fee := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), + M.get_name (| globals, "gas_fee" |) + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |); + M.get_name (| globals, "sender_balance_after_gas_fee" |) + ], + make_dict [] + |) in + let preaccessed_addresses := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let preaccessed_storage_keys := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let message := + M.call (| + M.get_name (| globals, "prepare_message" |), + make_list [ + M.get_name (| globals, "sender" |); + M.get_field (| M.get_name (| globals, "tx" |), "to" |); + M.get_field (| M.get_name (| globals, "tx" |), "value" |); + M.get_field (| M.get_name (| globals, "tx" |), "data" |); + M.get_name (| globals, "gas" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let output := + M.call (| + M.get_name (| globals, "process_message_call" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let gas_used := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "output" |), "gas_left" |) + |) in + let gas_refund := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + BinOp.floor_div (| + M.get_name (| globals, "gas_used" |), + Constant.int 2 + |); + M.get_field (| M.get_name (| globals, "output" |), "refund_counter" |) + ], + make_dict [] + |) in + let gas_refund_amount := + BinOp.mult (| + BinOp.add (| + M.get_field (| M.get_name (| globals, "output" |), "gas_left" |), + M.get_name (| globals, "gas_refund" |) + |), + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) + |) in + let transaction_fee := + BinOp.mult (| + BinOp.sub (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "output" |), "gas_left" |) + |), + M.get_name (| globals, "gas_refund" |) + |), + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) + |) in + let total_gas_used := + BinOp.sub (| + M.get_name (| globals, "gas_used" |), + M.get_name (| globals, "gas_refund" |) + |) in + let sender_balance_after_refund := + BinOp.add (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |), "balance" |), + M.get_name (| globals, "gas_refund_amount" |) + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |); + M.get_name (| globals, "sender_balance_after_refund" |) + ], + make_dict [] + |) in + let coinbase_balance_after_mining_fee := + BinOp.add (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |), "balance" |), + M.get_name (| globals, "transaction_fee" |) + |) in + let _ := + let _ := + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "accounts_to_delete" |) do + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + EndFor. + For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "touched_accounts" |) do + let _ := + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.return_ (| + make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |); M.get_field (| M.get_name (| globals, "output" |), "error" |) ] + M.pure Constant.None_)). + +Definition validate_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Verifies a transaction. + + The gas in a transaction gets used to pay for the intrinsic cost of + operations, therefore if there is insufficient gas then it would not + be possible to execute a transaction and it will be declared invalid. + + Additionally, the nonce of a transaction must not equal or exceed the + limit defined in `EIP-2681 `_. + In practice, defining the limit as ``2**64-1`` has no impact because + sending ``2**64-1`` transactions is improbable. It's not strictly + impossible though, ``2**64-1`` transactions is the entire capacity of the + Ethereum blockchain at 2022 gas limits for a little over 22 years. + + Parameters + ---------- + tx : + Transaction to validate. + + Returns + ------- + verified : `bool` + True if the transaction can be executed, or False otherwise. + " in + let _ := M.return_ (| + BoolOp.and (| + Compare.lt_e (| + M.call (| + M.get_name (| globals, "calculate_intrinsic_cost" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |), + M.get_field (| M.get_name (| globals, "tx" |), "gas" |) + |), + ltac:(M.monadic ( + Compare.lt (| + M.get_field (| M.get_name (| globals, "tx" |), "nonce" |), + BinOp.sub (| + BinOp.pow (| + Constant.int 2, + Constant.int 64 + |), + Constant.int 1 + |) + |) + )) + |) + M.pure Constant.None_)). + +Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Calculates the gas that is charged before execution is started. + + The intrinsic cost of the transaction is charged before execution has + begun. Functions/operations in the EVM cost money to execute so this + intrinsic cost is for the operations that need to be paid for as part of + the transaction. Data transfer, for example, is part of this intrinsic + cost. It costs ether to send data over the wire and that ether is + accounted for in the intrinsic cost calculated in this function. This + intrinsic cost must be calculated and paid for before execution in order + for all operations to be implemented. + + Parameters + ---------- + tx : + Transaction to compute the intrinsic cost of. + + Returns + ------- + verified : `ethereum.base_types.Uint` + The intrinsic cost of the transaction. + " in + let data_cost := + Constant.int 0 in + For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do + let _ := + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + M.pure Constant.None_ + )) |) in + EndFor. + let _ := + let create_cost := + Constant.int 0 in + M.pure Constant.None_ + )) |) in + let access_list_cost := + Constant.int 0 in + let _ := + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.add (| + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "TX_BASE_COST" |), + M.get_name (| globals, "data_cost" |) + |), + M.get_name (| globals, "create_cost" |) + |), + M.get_name (| globals, "access_list_cost" |) + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition recover_sender : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "chain_id"; "tx" ] |) in + let _ := Constant.str " + Extracts the sender address from a transaction. + + The v, r, and s values are the three parts that make up the signature + of a transaction. In order to recover the sender of a transaction the two + components needed are the signature (``v``, ``r``, and ``s``) and the + signing hash of the transaction. The sender's public key can be obtained + with these two values and therefore the sender address can be retrieved. + + Parameters + ---------- + tx : + Transaction of interest. + chain_id : + ID of the executing chain. + + Returns + ------- + sender : `ethereum.fork_types.Address` + The address of the account that signed the transaction. + " in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "r" |); M.get_name (| globals, "s" |) ], + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "r" |); M.get_field (| M.get_name (| globals, "tx" |), "s" |) ] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.and (| + Compare.lt (| + Constant.int 0, + M.get_name (| globals, "r" |) + |), + ltac:(M.monadic ( + Compare.lt (| + M.get_name (| globals, "r" |), + M.get_name (| globals, "SECP256K1N" |) + |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.and (| + Compare.lt (| + Constant.int 0, + M.get_name (| globals, "s" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_name (| globals, "s" |), + BinOp.floor_div (| + M.get_name (| globals, "SECP256K1N" |), + Constant.int 2 + |) + |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := + let _ := + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_subscript (| M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), Constant.int 12 |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition signing_hash_pre155 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Compute the hash of a transaction used in a legacy (pre EIP 155) signature. + + Parameters + ---------- + tx : + Transaction of interest. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the transaction. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "nonce" |); M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |); M.get_field (| M.get_name (| globals, "tx" |), "gas" |); M.get_field (| M.get_name (| globals, "tx" |), "to" |); M.get_field (| M.get_name (| globals, "tx" |), "value" |); M.get_field (| M.get_name (| globals, "tx" |), "data" |) ] + ], + make_dict [] + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition signing_hash_155 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx"; "chain_id" ] |) in + let _ := Constant.str " + Compute the hash of a transaction used in a EIP 155 signature. + + Parameters + ---------- + tx : + Transaction of interest. + chain_id : + The id of the current chain. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the transaction. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "nonce" |); M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |); M.get_field (| M.get_name (| globals, "tx" |), "gas" |); M.get_field (| M.get_name (| globals, "tx" |), "to" |); M.get_field (| M.get_name (| globals, "tx" |), "value" |); M.get_field (| M.get_name (| globals, "tx" |), "data" |); M.get_name (| globals, "chain_id" |); M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) ] + ], + make_dict [] + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition signing_hash_2930 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Compute the hash of a transaction used in a EIP 2930 signature. + + Parameters + ---------- + tx : + Transaction of interest. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the transaction. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + BinOp.add (| + Constant.bytes "01", + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "chain_id" |); M.get_field (| M.get_name (| globals, "tx" |), "nonce" |); M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |); M.get_field (| M.get_name (| globals, "tx" |), "gas" |); M.get_field (| M.get_name (| globals, "tx" |), "to" |); M.get_field (| M.get_name (| globals, "tx" |), "value" |); M.get_field (| M.get_name (| globals, "tx" |), "data" |); M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) ] + ], + make_dict [] + |) + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition compute_header_hash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header" ] |) in + let _ := Constant.str " + Computes the hash of a block header. + + The header hash of a block is the canonical hash that is used to refer + to a specific block and completely distinguishes a block from another. + + ``keccak256`` is a function that produces a 256 bit hash of any input. + It also takes in any number of bytes as an input and produces a single + hash for them. A hash is a completely unique output for a single input. + So an input corresponds to one unique hash that can be used to identify + the input exactly. + + Prior to using the ``keccak256`` hash function, the header must be + encoded using the Recursive-Length Prefix. See :ref:`rlp`. + RLP encoding the header converts it into a space-efficient format that + allows for easy transfer of data between nodes. The purpose of RLP is to + encode arbitrarily nested arrays of binary data, and RLP is the primary + encoding method used to serialize objects in Ethereum's execution layer. + The only purpose of RLP is to encode structure; encoding specific data + types (e.g. strings, floats) is left up to higher-order protocols. + + Parameters + ---------- + header : + Header of interest. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the header. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "header" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition check_gas_limit : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "gas_limit"; "parent_gas_limit" ] |) in + let _ := Constant.str " + Validates the gas limit for a block. + + The bounds of the gas limit, ``max_adjustment_delta``, is set as the + quotient of the parent block's gas limit and the + ``GAS_LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is + passed through as a parameter is greater than or equal to the *sum* of + the parent's gas and the adjustment delta then the limit for gas is too + high and fails this function's check. Similarly, if the limit is less + than or equal to the *difference* of the parent's gas and the adjustment + delta *or* the predefined ``GAS_LIMIT_MINIMUM`` then this function's + check fails because the gas limit doesn't allow for a sufficient or + reasonable amount of gas to be used on a block. + + Parameters + ---------- + gas_limit : + Gas limit to validate. + + parent_gas_limit : + Gas limit of the parent block. + + Returns + ------- + check : `bool` + True if gas limit constraints are satisfied, False otherwise. + " in + let max_adjustment_delta := + BinOp.floor_div (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) + |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + Constant.bool true + M.pure Constant.None_)). + +Definition calculate_block_difficulty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "block_number"; "block_timestamp"; "parent_timestamp"; "parent_difficulty"; "parent_has_ommers" ] |) in + let _ := Constant.str " + Computes difficulty of a block using its header and parent header. + + The difficulty is determined by the time the block was created after its + parent. The ``offset`` is calculated using the parent block's difficulty, + ``parent_difficulty``, and the timestamp between blocks. This offset is + then added to the parent difficulty and is stored as the ``difficulty`` + variable. If the time between the block and its parent is too short, the + offset will result in a positive number thus making the sum of + ``parent_difficulty`` and ``offset`` to be a greater value in order to + avoid mass forking. But, if the time is long enough, then the offset + results in a negative value making the block less difficult than + its parent. + + The base standard for a block's difficulty is the predefined value + set for the genesis block since it has no parent. So, a block + can't be less difficult than the genesis block, therefore each block's + difficulty is set to the maximum value between the calculated + difficulty and the ``GENESIS_DIFFICULTY``. + + Parameters + ---------- + block_number : + Block number of the block. + block_timestamp : + Timestamp of the block. + parent_timestamp : + Timestamp of the parent block. + parent_difficulty : + difficulty of the parent block. + parent_has_ommers: + does the parent have ommers. + + Returns + ------- + difficulty : `ethereum.base_types.Uint` + Computed difficulty for a block. + " in + let offset := + BinOp.mult (| + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "parent_difficulty" |) + ], + make_dict [] + |), + Constant.int 2048 + |), + M.call (| + M.get_name (| globals, "max" |), + make_list [ + BinOp.sub (| + (* if *) +M.if_then_else (| + M.get_name (| globals, "parent_has_ommers" |), +(* then *) +ltac:(M.monadic ( +Constant.int 2, + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "block_timestamp" |), + M.get_name (| globals, "parent_timestamp" |) + |) + ], + make_dict [] + |), + Constant.int 9 + |) + |); + UnOp.sub (| Constant.int 99 |) + ], + make_dict [] + |) + |) in + let difficulty := + BinOp.add (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "parent_difficulty" |) + ], + make_dict [] + |), + M.get_name (| globals, "offset" |) + |) in + let num_bomb_periods := + BinOp.sub (| + BinOp.floor_div (| + BinOp.sub (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "block_number" |) + ], + make_dict [] + |), + M.get_name (| globals, "BOMB_DELAY_BLOCKS" |) + |), + Constant.int 100000 + |), + Constant.int 2 + |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "max" |), + make_list [ + M.get_name (| globals, "difficulty" |); + M.get_name (| globals, "MINIMUM_DIFFICULTY" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/fork_types.v b/CoqOfPython/ethereum/berlin/fork_types.v index d12953d..5c7dac3 100644 --- a/CoqOfPython/ethereum/berlin/fork_types.v +++ b/CoqOfPython/ethereum/berlin/fork_types.v @@ -98,5 +98,4 @@ Definition encode_account : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/state.v b/CoqOfPython/ethereum/berlin/state.v index 7b038e5..c3290a6 100644 --- a/CoqOfPython/ethereum/berlin/state.v +++ b/CoqOfPython/ethereum/berlin/state.v @@ -126,13 +126,7 @@ Definition begin_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) ], make_dict [] - |); {M.get_name (| globals, "k" |): M.call (| - M.get_name (| globals, "copy_trie" |), - make_list [ - M.get_name (| globals, "t" |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)} ] + |); (* At expr: unsupported node type: DictComp *) ] ], make_dict [] |) in @@ -155,19 +149,6 @@ Definition commit_transaction : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "clear" |), - make_list [], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -193,19 +174,6 @@ Definition rollback_transaction : Value.t -> Value.t -> M := |) |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "clear" |), - make_list [], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -242,27 +210,8 @@ Definition get_account : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "account" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "account" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_ACCOUNT" |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -297,7 +246,6 @@ Definition get_account_optional : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "account" |) - |) in M.pure Constant.None_)). Definition set_account : Value.t -> Value.t -> M := @@ -377,15 +325,6 @@ Definition destroy_storage : Value.t -> Value.t -> M := Address of account whose storage is to be deleted. " in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -448,23 +387,6 @@ Definition get_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let value := @@ -486,7 +408,6 @@ Definition get_storage : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "value" |) - |) in M.pure Constant.None_)). Definition set_storage : Value.t -> Value.t -> M := @@ -507,14 +428,17 @@ Definition set_storage : Value.t -> Value.t -> M := value : `U256` Value to set at the key. " in - let _ := M.assert (| Compare.is_not (| M.call (| - M.get_name (| globals, "trie_get" |), - make_list [ - M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), Constant.None_ |) |) in + let _ := M.assert (| Compare.is_not (| + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + Constant.None_ + |) |) in let trie := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), @@ -524,24 +448,6 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let trie := - M.call (| - M.get_name (| globals, "Trie" |), - make_list [], - make_dict [] - |) in - let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), - M.get_name (| globals, "trie" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -554,15 +460,6 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), {} |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -587,26 +484,8 @@ Definition storage_root : Value.t -> Value.t -> M := " in let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "root" |), - make_list [ - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_TRIE_ROOT" |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -637,7 +516,6 @@ Definition state_root : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition account_exists : Value.t -> Value.t -> M := @@ -659,15 +537,17 @@ Definition account_exists : Value.t -> Value.t -> M := True if account exists in the state trie, False otherwise " in let _ := M.return_ (| - Compare.is_not (| M.call (| - M.get_name (| globals, "get_account_optional" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), Constant.None_ |) - |) in + Compare.is_not (| + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + Constant.None_ + |) M.pure Constant.None_)). Definition account_has_code_or_nonce : Value.t -> Value.t -> M := @@ -700,18 +580,23 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := |) in let _ := M.return_ (| BoolOp.or (| - Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( - Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |) + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |) )) |) - |) in M.pure Constant.None_)). Definition is_account_empty : Value.t -> Value.t -> M := @@ -744,23 +629,31 @@ Definition is_account_empty : Value.t -> Value.t -> M := |) in let _ := M.return_ (| BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |), ltac:(M.monadic ( - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "balance" |), + Constant.int 0 + |) )) |) )) |) - |) in M.pure Constant.None_)). Definition account_exists_and_is_empty : Value.t -> Value.t -> M := @@ -794,28 +687,39 @@ Definition account_exists_and_is_empty : Value.t -> Value.t -> M := |) in let _ := M.return_ (| BoolOp.and (| - Compare.is_not (| M.get_name (| globals, "account" |), Constant.None_ |), + Compare.is_not (| + M.get_name (| globals, "account" |), + Constant.None_ + |), ltac:(M.monadic ( BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |), ltac:(M.monadic ( - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "balance" |), + Constant.int 0 + |) )) |) )) |) )) |) - |) in M.pure Constant.None_)). Definition is_account_alive : Value.t -> Value.t -> M := @@ -846,36 +750,33 @@ Definition is_account_alive : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "account" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.bool false - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| UnOp.not (| BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |), ltac:(M.monadic ( - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "balance" |), + Constant.int 0 + |) )) |) )) |) |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -983,30 +884,6 @@ Definition touch_account : Value.t -> Value.t -> M := The address of the account that need to initialised. " in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "account_exists" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "set_account" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |); - M.get_name (| globals, "EMPTY_ACCOUNT" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -1111,23 +988,6 @@ Definition get_storage_original : Value.t -> Value.t -> M := Key of the storage slot. " in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -1143,22 +1003,6 @@ Definition get_storage_original : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "original_account_trie" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let original_value := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let original_value := M.call (| M.get_name (| globals, "trie_get" |), @@ -1180,5 +1024,4 @@ Definition get_storage_original : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "original_value" |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/transactions.v b/CoqOfPython/ethereum/berlin/transactions.v index 624882c..2ded28b 100644 --- a/CoqOfPython/ethereum/berlin/transactions.v +++ b/CoqOfPython/ethereum/berlin/transactions.v @@ -106,59 +106,14 @@ Definition encode_transaction : Value.t -> Value.t -> M := Encode a transaction. Needed because non-legacy transactions aren't RLP. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "LegacyTransaction" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "tx" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "AccessListTransaction" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - BinOp.add (| - (* At constant: unsupported node type: Constant *), - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "tx" |) - ], - make_dict [] - |) - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.call (| + let _ := M.raise (| Some(M.call (| M.get_name (| globals, "Exception" |), make_list [ (* At expr: unsupported node type: JoinedStr *) ], make_dict [] - |) |) in + |)) M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -172,42 +127,8 @@ Definition decode_transaction : Value.t -> Value.t -> M := Decode a transaction. Needed because non-legacy transactions aren't RLP. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "Bytes" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "ensure" |), - make_list [ - Compare.eq (| M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), Constant.int 1 |); - M.get_name (| globals, "InvalidBlock" |) - ], - make_dict [] - |) in - let _ := M.return_ (| - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), - make_list [ - M.get_name (| globals, "AccessListTransaction" |); - M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 1:(* At expr: unsupported node type: NoneType *) |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "tx" |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/trie.v b/CoqOfPython/ethereum/berlin/trie.v index 9e5b907..6a34e8c 100644 --- a/CoqOfPython/ethereum/berlin/trie.v +++ b/CoqOfPython/ethereum/berlin/trie.v @@ -202,96 +202,16 @@ Definition encode_internal_node : Value.t -> Value.t -> M := " in (* At stmt: unsupported node type: AnnAssign *) let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "node" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let unencoded := - (* At constant: unsupported node type: Constant *) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "LeafNode" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let unencoded := - make_tuple [ M.call (| - M.get_name (| globals, "nibble_list_to_compact" |), - make_list [ - M.get_field (| M.get_name (| globals, "node" |), "rest_of_key" |); - Constant.bool true - ], - make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "ExtensionNode" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let unencoded := - make_tuple [ M.call (| - M.get_name (| globals, "nibble_list_to_compact" |), - make_list [ - M.get_field (| M.get_name (| globals, "node" |), "key_segment" |); - Constant.bool false - ], - make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "BranchNode" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let unencoded := - BinOp.add (| - M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), - make_list [ - M.get_field (| M.get_name (| globals, "node" |), "value" |) - ] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.call (| + let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ (* At expr: unsupported node type: JoinedStr *) ], make_dict [] - |) |) in + |)) M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -309,23 +229,6 @@ Definition encode_internal_node : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "encoded" |) - ], - make_dict [] - |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "unencoded" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_name (| globals, "keccak256" |), @@ -334,7 +237,6 @@ Definition encode_internal_node : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -348,83 +250,8 @@ Definition encode_node : Value.t -> Value.t -> M := Currently mostly an unimplemented stub. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "storage_root" |), Constant.None_ |) |) in - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "encode_account" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "storage_root" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "U256" |) ] - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.call (| - M.get_name (| globals, "cast" |), - make_list [ - M.get_field (| M.get_name (| globals, "rlp" |), "RLP" |); - M.get_name (| globals, "node" |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "Bytes" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "node" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "previous_trie" |), "encode_node" |), @@ -434,7 +261,6 @@ Definition encode_node : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -486,7 +312,6 @@ Definition copy_trie : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition trie_set : Value.t -> Value.t -> M := @@ -508,26 +333,6 @@ Definition trie_set : Value.t -> Value.t -> M := Node to insert at `key`. " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "value" |), M.get_field (| M.get_name (| globals, "trie" |), "default" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "key" |), M.get_field (| M.get_name (| globals, "trie" |), "_data" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), M.get_name (| globals, "value" |) @@ -565,7 +370,6 @@ Definition trie_get : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition common_prefix_length : Value.t -> Value.t -> M := @@ -588,28 +392,6 @@ Definition common_prefix_length : Value.t -> Value.t -> M := make_dict [] |) do let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| M.get_name (| globals, "i" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "b" |) - ], - make_dict [] - |) |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "i" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -621,7 +403,6 @@ Definition common_prefix_length : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition nibble_list_to_compact : Value.t -> Value.t -> M := @@ -667,68 +448,6 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| BinOp.mod_ (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |), - Constant.int 2 - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_name (| globals, "compact" |), "append" |), - make_list [ - BinOp.mult (| - Constant.int 16, - BinOp.mult (| - Constant.int 2, - M.get_name (| globals, "is_leaf" |) - |) - |) - ], - make_dict [] - |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 0; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |); - Constant.int 2 - ], - make_dict [] - |) do - let _ := M.call (| - M.get_field (| M.get_name (| globals, "compact" |), "append" |), - make_list [ - BinOp.add (| - BinOp.mult (| - Constant.int 16, - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) - |), - M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) - |) - ], - make_dict [] - |) in - EndFor. - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ @@ -790,7 +509,6 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition bytes_to_nibble_list : Value.t -> Value.t -> M := @@ -868,7 +586,6 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition _prepare_trie : Value.t -> Value.t -> M := @@ -898,45 +615,6 @@ Definition _prepare_trie : Value.t -> Value.t -> M := make_dict [] |) do let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "value" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in - let address := - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in - let encoded_value := - M.call (| - M.get_name (| globals, "encode_node" |), - make_list [ - M.get_name (| globals, "value" |); - M.call (| - M.get_name (| globals, "get_storage_root" |), - make_list [ - M.get_name (| globals, "address" |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let encoded_value := M.call (| M.get_name (| globals, "encode_node" |), @@ -950,29 +628,16 @@ Definition _prepare_trie : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.not_eq (| M.get_name (| globals, "encoded_value" |), (* At constant: unsupported node type: Constant *) |); + Compare.not_eq (| + M.get_name (| globals, "encoded_value" |), + Constant.bytes "" + |); M.get_name (| globals, "AssertionError" |) ], make_dict [] |) in (* At stmt: unsupported node type: AnnAssign *) let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "trie" |), "secured" |), - (* then *) - ltac:(M.monadic ( - let key := - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let key := M.get_name (| globals, "preimage" |) in M.pure Constant.None_ @@ -990,7 +655,6 @@ Definition _prepare_trie : Value.t -> Value.t -> M := EndFor. let _ := M.return_ (| M.get_name (| globals, "mapped" |) - |) in M.pure Constant.None_)). Definition root : Value.t -> Value.t -> M := @@ -1044,41 +708,6 @@ Definition root : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "root_node" |) - ], - make_dict [] - |) - ], - make_dict [] - |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "root_node" |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -1095,7 +724,6 @@ Definition root : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -1122,23 +750,6 @@ Definition patricialize : Value.t -> Value.t -> M := Root node of `obj`. " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "obj" |) - ], - make_dict [] - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.None_ - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let arbitrary_key := @@ -1156,36 +767,10 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "obj" |) - ], - make_dict [] - |), Constant.int 1 |), - (* then *) - ltac:(M.monadic ( - let leaf := - M.call (| - M.get_name (| globals, "LeafNode" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |); - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) - ], - make_dict [] - |) in - let _ := M.return_ (| - M.get_name (| globals, "leaf" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let substring := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |) |) in let prefix_length := M.call (| M.get_name (| globals, "len" |), @@ -1204,7 +789,7 @@ Definition patricialize : Value.t -> Value.t -> M := M.get_name (| globals, "common_prefix_length" |), make_list [ M.get_name (| globals, "substring" |); - M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) + M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) ], make_dict [] |) @@ -1212,58 +797,10 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.break (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let prefix := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):BinOp.add (| - M.get_name (| globals, "level" |), - M.get_name (| globals, "prefix_length" |) - |) |) in - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "ExtensionNode" |), - make_list [ - M.get_name (| globals, "prefix" |); - M.call (| - M.get_name (| globals, "encode_internal_node" |), - make_list [ - M.call (| - M.get_name (| globals, "patricialize" |), - make_list [ - M.get_name (| globals, "obj" |); - BinOp.add (| - M.get_name (| globals, "level" |), - M.get_name (| globals, "prefix_length" |) - |) - ], - make_dict [] - |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) @@ -1283,44 +820,9 @@ Definition patricialize : Value.t -> Value.t -> M := |) in EndFor. let value := - (* At constant: unsupported node type: Constant *) in + Constant.bytes "" in For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "key" |) - ], - make_dict [] - |), M.get_name (| globals, "level" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); - make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "AssertionError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let value := - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) @@ -1332,26 +834,9 @@ Definition patricialize : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "BranchNode" |), make_list [ - [M.call (| - M.get_name (| globals, "encode_internal_node" |), - make_list [ - M.call (| - M.get_name (| globals, "patricialize" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "branches" |), M.get_name (| globals, "k" |) |); - BinOp.add (| - M.get_name (| globals, "level" |), - Constant.int 1 - |) - ], - make_dict [] - |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)]; + (* At expr: unsupported node type: ListComp *); M.get_name (| globals, "value" |) ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/utils/address.v b/CoqOfPython/ethereum/berlin/utils/address.v index 7ff5b92..8f7acf4 100644 --- a/CoqOfPython/ethereum/berlin/utils/address.v +++ b/CoqOfPython/ethereum/berlin/utils/address.v @@ -70,11 +70,10 @@ Definition to_address : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), make_list [], make_dict [] - |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) + |), UnOp.sub (| Constant.int 20 |) |) ], make_dict [] |) - |) in M.pure Constant.None_)). Definition compute_contract_address : Value.t -> Value.t -> M := @@ -114,7 +113,7 @@ Definition compute_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -132,7 +131,6 @@ Definition compute_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition compute_create2_contract_address : Value.t -> Value.t -> M := @@ -160,7 +158,7 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := BinOp.add (| BinOp.add (| BinOp.add (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "ff", M.get_name (| globals, "address" |) |), M.get_name (| globals, "salt" |) @@ -182,7 +180,7 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -200,5 +198,4 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/utils/hexadecimal.v b/CoqOfPython/ethereum/berlin/utils/hexadecimal.v index 6f8dcdd..042f2a4 100644 --- a/CoqOfPython/ethereum/berlin/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/berlin/utils/hexadecimal.v @@ -66,7 +66,6 @@ Definition hex_to_root : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition hex_to_bloom : Value.t -> Value.t -> M := @@ -105,7 +104,6 @@ Definition hex_to_bloom : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition hex_to_address : Value.t -> Value.t -> M := @@ -151,5 +149,4 @@ Definition hex_to_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/utils/message.v b/CoqOfPython/ethereum/berlin/utils/message.v index 9b19085..5fddaaa 100644 --- a/CoqOfPython/ethereum/berlin/utils/message.v +++ b/CoqOfPython/ethereum/berlin/utils/message.v @@ -103,105 +103,14 @@ Definition prepare_message : Value.t -> Value.t -> M := Items containing contract creation or message call specific data. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "target" |); - M.get_name (| globals, "Bytes0" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let current_target := - M.call (| - M.get_name (| globals, "compute_contract_address" |), - make_list [ - M.get_name (| globals, "caller" |); - BinOp.sub (| - M.get_field (| M.call (| - M.get_name (| globals, "get_account" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "caller" |) - ], - make_dict [] - |), "nonce" |), - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 1 - ], - make_dict [] - |) - |) - ], - make_dict [] - |) in - let msg_data := - M.call (| - M.get_name (| globals, "Bytes" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |) in - let code := - M.get_name (| globals, "data" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "target" |); - M.get_name (| globals, "Address" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let current_target := - M.get_name (| globals, "target" |) in - let msg_data := - M.get_name (| globals, "data" |) in - let code := - M.get_field (| M.call (| - M.get_name (| globals, "get_account" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "target" |) - ], - make_dict [] - |), "code" |) in - let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "code_address" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let code_address := - M.get_name (| globals, "target" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.call (| + let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "Target must be address or empty bytes" ], make_dict [] - |) |) in + |)) M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -250,5 +159,4 @@ Definition prepare_message : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/vm/__init__.v b/CoqOfPython/ethereum/berlin/vm/__init__.v index 2ff63cd..49da5ae 100644 --- a/CoqOfPython/ethereum/berlin/vm/__init__.v +++ b/CoqOfPython/ethereum/berlin/vm/__init__.v @@ -147,28 +147,6 @@ Definition incorporate_child_on_success : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); - M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -201,57 +179,9 @@ Definition incorporate_child_on_error : Value.t -> Value.t -> M := The child evm to incorporate. " in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "RIPEMD160_ADDRESS" |), M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), - make_list [ - M.get_name (| globals, "RIPEMD160_ADDRESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |), M.get_name (| globals, "RIPEMD160_ADDRESS" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); - M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), - make_list [ - M.get_name (| globals, "RIPEMD160_ADDRESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign_op (| diff --git a/CoqOfPython/ethereum/berlin/vm/gas.v b/CoqOfPython/ethereum/berlin/vm/gas.v new file mode 100644 index 0000000..e5e241b --- /dev/null +++ b/CoqOfPython/ethereum/berlin/vm/gas.v @@ -0,0 +1,821 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Gas +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +EVM gas constants and calculators. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.trace. +Axiom ethereum_trace_GasAndRefund : + IsGlobalAlias globals ethereum.trace.globals "GasAndRefund". +Axiom ethereum_trace_evm_trace : + IsGlobalAlias globals ethereum.trace.globals "evm_trace". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". + +Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) +)). + +Definition GAS_BASE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 2 + ], + make_dict [] + |) +)). + +Definition GAS_VERY_LOW : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_STORAGE_SET : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 20000 + ], + make_dict [] + |) +)). + +Definition GAS_STORAGE_UPDATE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5000 + ], + make_dict [] + |) +)). + +Definition GAS_STORAGE_CLEAR_REFUND : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 15000 + ], + make_dict [] + |) +)). + +Definition GAS_LOW : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5 + ], + make_dict [] + |) +)). + +Definition GAS_MID : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 8 + ], + make_dict [] + |) +)). + +Definition GAS_HIGH : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 10 + ], + make_dict [] + |) +)). + +Definition GAS_EXPONENTIATION : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 10 + ], + make_dict [] + |) +)). + +Definition GAS_EXPONENTIATION_PER_BYTE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 50 + ], + make_dict [] + |) +)). + +Definition GAS_MEMORY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_KECCAK256 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 30 + ], + make_dict [] + |) +)). + +Definition GAS_KECCAK256_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 6 + ], + make_dict [] + |) +)). + +Definition GAS_COPY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_BLOCK_HASH : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 20 + ], + make_dict [] + |) +)). + +Definition GAS_LOG : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 375 + ], + make_dict [] + |) +)). + +Definition GAS_LOG_DATA : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 8 + ], + make_dict [] + |) +)). + +Definition GAS_LOG_TOPIC : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 375 + ], + make_dict [] + |) +)). + +Definition GAS_CREATE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 32000 + ], + make_dict [] + |) +)). + +Definition GAS_CODE_DEPOSIT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 200 + ], + make_dict [] + |) +)). + +Definition GAS_ZERO : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) +)). + +Definition GAS_NEW_ACCOUNT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 25000 + ], + make_dict [] + |) +)). + +Definition GAS_CALL_VALUE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 9000 + ], + make_dict [] + |) +)). + +Definition GAS_CALL_STIPEND : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 2300 + ], + make_dict [] + |) +)). + +Definition GAS_SELF_DESTRUCT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5000 + ], + make_dict [] + |) +)). + +Definition GAS_SELF_DESTRUCT_NEW_ACCOUNT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 25000 + ], + make_dict [] + |) +)). + +Definition REFUND_SELF_DESTRUCT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 24000 + ], + make_dict [] + |) +)). + +Definition GAS_ECRECOVER : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3000 + ], + make_dict [] + |) +)). + +Definition GAS_SHA256 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 60 + ], + make_dict [] + |) +)). + +Definition GAS_SHA256_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 12 + ], + make_dict [] + |) +)). + +Definition GAS_RIPEMD160 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 600 + ], + make_dict [] + |) +)). + +Definition GAS_RIPEMD160_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 120 + ], + make_dict [] + |) +)). + +Definition GAS_IDENTITY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 15 + ], + make_dict [] + |) +)). + +Definition GAS_IDENTITY_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_RETURN_DATA_COPY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_FAST_STEP : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5 + ], + make_dict [] + |) +)). + +Definition GAS_BLAKE2_PER_ROUND : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) +)). + +Definition GAS_COLD_SLOAD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 2100 + ], + make_dict [] + |) +)). + +Definition GAS_COLD_ACCOUNT_ACCESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 2600 + ], + make_dict [] + |) +)). + +Definition GAS_WARM_ACCESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 100 + ], + make_dict [] + |) +)). + +Definition ExtendMemory : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition MessageCallGas : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition charge_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "amount" ] |) in + let _ := Constant.str " + Subtracts `amount` from `evm.gas_left`. + + Parameters + ---------- + evm : + The current EVM. + amount : + The amount of gas the current operation requires. + + " in + let _ := M.call (| + M.get_name (| globals, "evm_trace" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "GasAndRefund" |), + make_list [ + M.get_name (| globals, "amount" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + let _ := M.assign_op (| + BinOp.sub, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "amount" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition calculate_memory_gas_cost : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "size_in_bytes" ] |) in + let _ := Constant.str " + Calculates the gas cost for allocating memory + to the smallest multiple of 32 bytes, + such that the allocated size is at least as big as the given size. + + Parameters + ---------- + size_in_bytes : + The size of the data in bytes. + + Returns + ------- + total_gas_cost : `ethereum.base_types.Uint` + The gas cost for storing data in memory. + " in + let size_in_words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "size_in_bytes" |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let linear_cost := + BinOp.mult (| + M.get_name (| globals, "size_in_words" |), + M.get_name (| globals, "GAS_MEMORY" |) + |) in + let quadratic_cost := + BinOp.floor_div (| + BinOp.pow (| + M.get_name (| globals, "size_in_words" |), + Constant.int 2 + |), + Constant.int 512 + |) in + let total_gas_cost := + BinOp.add (| + M.get_name (| globals, "linear_cost" |), + M.get_name (| globals, "quadratic_cost" |) + |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_)). + +Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "memory"; "extensions" ] |) in + let _ := Constant.str " + Calculates the gas amount to extend memory + + Parameters + ---------- + memory : + Memory contents of the EVM. + extensions: + List of extensions to be made to the memory. + Consists of a tuple of start position and size. + + Returns + ------- + extend_memory: `ExtendMemory` + " in + let size_to_extend := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let to_be_paid := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let current_size := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "memory" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + For make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ] in M.get_name (| globals, "extensions" |) do + let _ := + M.pure Constant.None_ + )) |) in + let before_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "current_size" |) + ], + make_dict [] + |) in + let after_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let size_to_extend := BinOp.add + BinOp.sub (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |) + BinOp.sub (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |) in + let already_paid := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "before_size" |) + ], + make_dict [] + |) in + let total_cost := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "after_size" |) + ], + make_dict [] + |) in + let to_be_paid := BinOp.add + BinOp.sub (| + M.get_name (| globals, "total_cost" |), + M.get_name (| globals, "already_paid" |) + |) + BinOp.sub (| + M.get_name (| globals, "total_cost" |), + M.get_name (| globals, "already_paid" |) + |) in + let current_size := + M.get_name (| globals, "after_size" |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ExtendMemory" |), + make_list [ + M.get_name (| globals, "to_be_paid" |); + M.get_name (| globals, "size_to_extend" |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition calculate_message_call_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "value"; "gas"; "gas_left"; "memory_cost"; "extra_gas"; "call_stipend" ] |) in + let _ := Constant.str " + Calculates the MessageCallGas (cost and stipend) for + executing call Opcodes. + + Parameters + ---------- + value: + The amount of `ETH` that needs to be transferred. + gas : + The amount of gas provided to the message-call. + gas_left : + The amount of gas left in the current frame. + memory_cost : + The amount needed to extend the memory in the current frame. + extra_gas : + The amount of gas needed for transferring value + creating a new + account inside a message call. + call_stipend : + The amount of stipend provided to a message call to execute code while + transferring value(ETH). + + Returns + ------- + message_call_gas: `MessageCallGas` + " in + let call_stipend := + (* if *) +M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let gas := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "max_message_call_gas" |), + make_list [ + BinOp.sub (| + BinOp.sub (| + M.get_name (| globals, "gas_left" |), + M.get_name (| globals, "memory_cost" |) + |), + M.get_name (| globals, "extra_gas" |) + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallGas" |), + make_list [ + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "extra_gas" |) + |); + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "call_stipend" |) + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition max_message_call_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "gas" ] |) in + let _ := Constant.str " + Calculates the maximum gas that is allowed for making a message call + + Parameters + ---------- + gas : + The amount of gas provided to the message-call. + + Returns + ------- + max_allowed_message_call_gas: `ethereum.base_types.Uint` + The maximum gas allowed for making the message-call. + " in + let _ := M.return_ (| + BinOp.sub (| + M.get_name (| globals, "gas" |), + BinOp.floor_div (| + M.get_name (| globals, "gas" |), + Constant.int 64 + |) + |) + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/berlin/vm/instructions/arithmetic.v index a8b5c61..581ba5d 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/arithmetic.v @@ -273,22 +273,6 @@ Definition div : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let quotient := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let quotient := BinOp.floor_div (| M.get_name (| globals, "dividend" |), @@ -357,32 +341,7 @@ Definition sdiv : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let quotient := - Constant.int 0 in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_name (| globals, "dividend" |), UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "divisor" |), UnOp.sub (| Constant.int 1 |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let quotient := - UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let sign := M.call (| M.get_name (| globals, "get_sign" |), @@ -477,22 +436,6 @@ Definition mod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let remainder := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let remainder := BinOp.mod_ (| M.get_name (| globals, "x" |), @@ -561,16 +504,6 @@ Definition smod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let remainder := - Constant.int 0 in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let remainder := BinOp.mult (| M.call (| @@ -684,22 +617,6 @@ Definition addmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -795,22 +712,6 @@ Definition mulmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -980,16 +881,6 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "byte_num" |), Constant.int 31 |), - (* then *) - ltac:(M.monadic ( - let result := - M.get_name (| globals, "value" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let value_bytes := M.call (| M.get_name (| globals, "bytes" |), @@ -1012,29 +903,13 @@ Definition signextend : Value.t -> Value.t -> M := ], make_dict [] |) - |):(* At expr: unsupported node type: NoneType *) |) in + |) |) in let sign_bit := BinOp.r_shift (| M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), Constant.int 7 |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "sign_bit" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), - make_list [ - M.get_name (| globals, "value_bytes" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let num_bytes_prepend := BinOp.sub (| Constant.int 32, diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/bitwise.v b/CoqOfPython/ethereum/berlin/vm/instructions/bitwise.v index 9f2f382..64cf120 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/bitwise.v @@ -287,22 +287,6 @@ Definition get_byte : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "byte_index" |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let extra_bytes_to_right := BinOp.sub (| Constant.int 31, @@ -382,28 +366,6 @@ Definition bitwise_shl : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - BinOp.mod_ (| - BinOp.l_shift (| - M.get_name (| globals, "value" |), - M.get_name (| globals, "shift" |) - |), - M.get_name (| globals, "U256_CEIL_VALUE" |) - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -465,19 +427,6 @@ Definition bitwise_shr : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), - (* then *) - ltac:(M.monadic ( - let result := - BinOp.r_shift (| - M.get_name (| globals, "value" |), - M.get_name (| globals, "shift" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -543,42 +492,7 @@ Definition bitwise_sar : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), - make_list [ - BinOp.r_shift (| - M.get_name (| globals, "signed_value" |), - M.get_name (| globals, "shift" |) - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "signed_value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/block.v b/CoqOfPython/ethereum/berlin/vm/instructions/block.v index 26c73a7..f857b79 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/block.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/block.v @@ -69,24 +69,6 @@ Definition block_hash : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.lt_e (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), M.get_name (| globals, "block_number" |) |), - ltac:(M.monadic ( - Compare.gt (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), BinOp.add (| - M.get_name (| globals, "block_number" |), - Constant.int 256 - |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let hash := - (* At constant: unsupported node type: Constant *) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let hash := M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/comparison.v b/CoqOfPython/ethereum/berlin/vm/instructions/comparison.v index fbc35f8..b8529d8 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/comparison.v @@ -78,7 +78,10 @@ Definition less_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.lt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -145,7 +148,10 @@ Definition signed_less_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.lt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -205,7 +211,10 @@ Definition greater_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.gt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -272,7 +281,10 @@ Definition signed_greater_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.gt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -332,7 +344,10 @@ Definition equal : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.eq (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.eq (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -384,7 +399,10 @@ Definition is_zero : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.eq (| M.get_name (| globals, "x" |), Constant.int 0 |) + Compare.eq (| + M.get_name (| globals, "x" |), + Constant.int 0 + |) ], make_dict [] |) in diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/control_flow.v b/CoqOfPython/ethereum/berlin/vm/instructions/control_flow.v index 04a79d9..d4e4eae 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/control_flow.v @@ -109,15 +109,6 @@ Definition jump : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -177,29 +168,7 @@ Definition jumpi : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "conditional_value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let destination := - BinOp.add (| - M.get_field (| M.get_name (| globals, "evm" |), "pc" |), - Constant.int 1 - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let destination := M.get_name (| globals, "jump_dest" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/environment.v b/CoqOfPython/ethereum/berlin/vm/instructions/environment.v index 05f8cdf..eefcb4f 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/environment.v @@ -156,22 +156,6 @@ Definition balance : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "charge_gas" |), - make_list [ - M.get_name (| globals, "evm" |); - M.get_name (| globals, "GAS_WARM_ACCESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -538,7 +522,7 @@ Definition calldatacopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -706,7 +690,7 @@ Definition codecopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -805,22 +789,6 @@ Definition extcodesize : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "charge_gas" |), - make_list [ - M.get_name (| globals, "evm" |); - M.get_name (| globals, "GAS_WARM_ACCESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -958,28 +926,6 @@ Definition extcodecopy : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "charge_gas" |), - make_list [ - M.get_name (| globals, "evm" |); - BinOp.add (| - BinOp.add (| - M.get_name (| globals, "GAS_WARM_ACCESS" |), - M.get_name (| globals, "copy_gas_cost" |) - |), - M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1007,7 +953,7 @@ Definition extcodecopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -1178,28 +1124,31 @@ Definition returndatacopy : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt_e (| BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "return_data_start_position" |) - ], - make_dict [] + Compare.lt_e (| + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "return_data_start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) |), M.call (| - M.get_name (| globals, "Uint" |), + M.get_name (| globals, "len" |), make_list [ - M.get_name (| globals, "size" |) + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |) ], make_dict [] |) - |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "return_data" |) - ], - make_dict [] - |) |); + |); M.get_name (| globals, "OutOfBoundsRead" |) ], make_dict [] @@ -1208,15 +1157,12 @@ Definition returndatacopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in let value := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |):BinOp.add (| - M.get_name (| globals, "return_data_start_position" |), - M.get_name (| globals, "size" |) - |) |) in + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |) |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -1258,22 +1204,6 @@ Definition extcodehash : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "charge_gas" |), - make_list [ - M.get_name (| globals, "evm" |); - M.get_name (| globals, "GAS_WARM_ACCESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1301,22 +1231,6 @@ Definition extcodehash : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "account" |), M.get_name (| globals, "EMPTY_ACCOUNT" |) |), - (* then *) - ltac:(M.monadic ( - let codehash := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let codehash := M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/keccak.v b/CoqOfPython/ethereum/berlin/vm/instructions/keccak.v index cab9ffb..2c4b10e 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/keccak.v @@ -137,7 +137,7 @@ Definition keccak : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/log.v b/CoqOfPython/ethereum/berlin/vm/instructions/log.v index 4891a4d..e084e59 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/log.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/log.v @@ -161,7 +161,7 @@ Definition log_n : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/memory.v b/CoqOfPython/ethereum/berlin/vm/instructions/memory.v index 1e1c8b0..86ba742 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/memory.v @@ -121,7 +121,7 @@ Definition mstore : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -203,7 +203,7 @@ Definition mstore8 : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -288,7 +288,7 @@ Definition mload : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/stack.v b/CoqOfPython/ethereum/berlin/vm/instructions/stack.v index 1eeda05..305af15 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/stack.v @@ -188,13 +188,16 @@ Definition dup_n : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] - |) |); + Compare.lt (| + M.get_name (| globals, "item_number" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + |); M.get_name (| globals, "StackUnderflowError" |) ], make_dict [] @@ -260,13 +263,16 @@ Definition swap_n : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] - |) |); + Compare.lt (| + M.get_name (| globals, "item_number" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + |); M.get_name (| globals, "StackUnderflowError" |) ], make_dict [] diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/storage.v b/CoqOfPython/ethereum/berlin/vm/instructions/storage.v index 2f0a831..b3c4045 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/storage.v @@ -91,22 +91,6 @@ Definition sload : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "charge_gas" |), - make_list [ - M.get_name (| globals, "evm" |); - M.get_name (| globals, "GAS_WARM_ACCESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "add" |), make_list [ @@ -184,7 +168,10 @@ Definition sstore : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.gt (| M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), M.get_name (| globals, "GAS_CALL_STIPEND" |) |); + Compare.gt (| + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "GAS_CALL_STIPEND" |) + |); M.get_name (| globals, "OutOfGasError" |) ], make_dict [] @@ -218,189 +205,15 @@ Definition sstore : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_in (| make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "add" |), - make_list [ - make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ] - ], - make_dict [] - |) in - let gas_cost := BinOp.add - M.get_name (| globals, "GAS_COLD_SLOAD" |) - M.get_name (| globals, "GAS_COLD_SLOAD" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_name (| globals, "original_value" |), M.get_name (| globals, "current_value" |) |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_name (| globals, "current_value" |), M.get_name (| globals, "new_value" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let gas_cost := BinOp.add - M.get_name (| globals, "GAS_STORAGE_SET" |) - M.get_name (| globals, "GAS_STORAGE_SET" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let gas_cost := BinOp.add - BinOp.sub (| - M.get_name (| globals, "GAS_STORAGE_UPDATE" |), - M.get_name (| globals, "GAS_COLD_SLOAD" |) - |) - BinOp.sub (| - M.get_name (| globals, "GAS_STORAGE_UPDATE" |), - M.get_name (| globals, "GAS_COLD_SLOAD" |) - |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let gas_cost := BinOp.add M.get_name (| globals, "GAS_WARM_ACCESS" |) M.get_name (| globals, "GAS_WARM_ACCESS" |) in M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_eq (| M.get_name (| globals, "current_value" |), M.get_name (| globals, "new_value" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), - ltac:(M.monadic ( - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "new_value" |), Constant.int 0 |) - )) - |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), - M.call (| - M.get_name (| globals, "int" |), - make_list [ - M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.sub, - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), - M.call (| - M.get_name (| globals, "int" |), - make_list [ - M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "original_value" |), M.get_name (| globals, "new_value" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), - M.call (| - M.get_name (| globals, "int" |), - make_list [ - BinOp.sub (| - M.get_name (| globals, "GAS_STORAGE_SET" |), - M.get_name (| globals, "GAS_WARM_ACCESS" |) - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), - M.call (| - M.get_name (| globals, "int" |), - make_list [ - BinOp.sub (| - BinOp.sub (| - M.get_name (| globals, "GAS_STORAGE_UPDATE" |), - M.get_name (| globals, "GAS_COLD_SLOAD" |) - |), - M.get_name (| globals, "GAS_WARM_ACCESS" |) - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/system.v b/CoqOfPython/ethereum/berlin/vm/instructions/system.v new file mode 100644 index 0000000..b5cf558 --- /dev/null +++ b/CoqOfPython/ethereum/berlin/vm/instructions/system.v @@ -0,0 +1,1658 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) System Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM system related instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_account_exists_and_is_empty : + IsGlobalAlias globals state.globals "account_exists_and_is_empty". +Axiom state_account_has_code_or_nonce : + IsGlobalAlias globals state.globals "account_has_code_or_nonce". +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". +Axiom state_increment_nonce : + IsGlobalAlias globals state.globals "increment_nonce". +Axiom state_is_account_alive : + IsGlobalAlias globals state.globals "is_account_alive". +Axiom state_set_account_balance : + IsGlobalAlias globals state.globals "set_account_balance". + +Require utils.address. +Axiom utils_address_compute_contract_address : + IsGlobalAlias globals utils.address.globals "compute_contract_address". +Axiom utils_address_compute_create2_contract_address : + IsGlobalAlias globals utils.address.globals "compute_create2_contract_address". +Axiom utils_address_to_address : + IsGlobalAlias globals utils.address.globals "to_address". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". +Axiom __init___Message : + IsGlobalAlias globals __init__.globals "Message". +Axiom __init___incorporate_child_on_error : + IsGlobalAlias globals __init__.globals "incorporate_child_on_error". +Axiom __init___incorporate_child_on_success : + IsGlobalAlias globals __init__.globals "incorporate_child_on_success". + +Require exceptions. +Axiom exceptions_Revert : + IsGlobalAlias globals exceptions.globals "Revert". +Axiom exceptions_WriteInStaticContext : + IsGlobalAlias globals exceptions.globals "WriteInStaticContext". + +Require gas. +Axiom gas_GAS_CALL_VALUE : + IsGlobalAlias globals gas.globals "GAS_CALL_VALUE". +Axiom gas_GAS_COLD_ACCOUNT_ACCESS : + IsGlobalAlias globals gas.globals "GAS_COLD_ACCOUNT_ACCESS". +Axiom gas_GAS_CREATE : + IsGlobalAlias globals gas.globals "GAS_CREATE". +Axiom gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". +Axiom gas_GAS_NEW_ACCOUNT : + IsGlobalAlias globals gas.globals "GAS_NEW_ACCOUNT". +Axiom gas_GAS_SELF_DESTRUCT : + IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT". +Axiom gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : + IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". +Axiom gas_GAS_WARM_ACCESS : + IsGlobalAlias globals gas.globals "GAS_WARM_ACCESS". +Axiom gas_GAS_ZERO : + IsGlobalAlias globals gas.globals "GAS_ZERO". +Axiom gas_REFUND_SELF_DESTRUCT : + IsGlobalAlias globals gas.globals "REFUND_SELF_DESTRUCT". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_calculate_message_call_gas : + IsGlobalAlias globals gas.globals "calculate_message_call_gas". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". +Axiom gas_max_message_call_gas : + IsGlobalAlias globals gas.globals "max_message_call_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". +Axiom memory_memory_write : + IsGlobalAlias globals memory.globals "memory_write". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition generic_create : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "endowment"; "contract_address"; "memory_start_position"; "memory_size" ] |) in + let _ := Constant.str " + Core logic used by the `CREATE*` family of opcodes. + " in +(* At stmt: unsupported node type: ImportFrom *) + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "contract_address" |) + ], + make_dict [] + |) in + let create_message_gas := + M.call (| + M.get_name (| globals, "max_message_call_gas" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.sub, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "create_message_gas" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let sender_address := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in + let sender := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "sender_address" |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := + M.pure Constant.None_ + )) |) in + let call_data := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + let child_message := + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) in + let child_evm := + M.call (| + M.get_name (| globals, "process_create_message" |), + make_list [ + M.get_name (| globals, "child_message" |); + M.get_field (| M.get_name (| globals, "evm" |), "env" |) + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_success" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition create : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Creates a new account with associated code. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let endowment := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_position" |); M.get_name (| globals, "memory_size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_CREATE" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let contract_address := + M.call (| + M.get_name (| globals, "compute_contract_address" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "nonce" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "generic_create" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "endowment" |); + M.get_name (| globals, "contract_address" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition create2 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Creates a new account with associated code. + + It's similar to CREATE opcode except that the address of new account + depends on the init_code instead of the nonce of sender. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let endowment := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let salt := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_position" |); M.get_name (| globals, "memory_size" |) ] + ] + ], + make_dict [] + |) in + let call_data_words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_CREATE" |), + BinOp.mult (| + M.get_name (| globals, "GAS_KECCAK256_WORD" |), + M.get_name (| globals, "call_data_words" |) + |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let contract_address := + M.call (| + M.get_name (| globals, "compute_create2_contract_address" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "salt" |); + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "generic_create" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "endowment" |); + M.get_name (| globals, "contract_address" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition return_ : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Halts execution returning output data. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let memory_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_position" |); M.get_name (| globals, "memory_size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_ZERO" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "running" |), + Constant.bool false + |) in + let _ := M.pass (| |) in + M.pure Constant.None_)). + +Definition generic_call : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "gas"; "value"; "caller"; "to"; "code_address"; "should_transfer_value"; "is_staticcall"; "memory_input_start_position"; "memory_input_size"; "memory_output_start_position"; "memory_output_size" ] |) in + let _ := Constant.str " + Perform the core logic of the `CALL*` family of opcodes. + " in +(* At stmt: unsupported node type: ImportFrom *) + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let _ := + M.pure Constant.None_ + )) |) in + let call_data := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |) + ], + make_dict [] + |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "code_address" |) + ], + make_dict [] + |), "code" |) in + let child_message := + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) in + let child_evm := + M.call (| + M.get_name (| globals, "process_message" |), + make_list [ + M.get_name (| globals, "child_message" |); + M.get_field (| M.get_name (| globals, "evm" |), "env" |) + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_success" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let actual_output_size := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_name (| globals, "memory_output_size" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), Constant.None_:M.get_name (| globals, "actual_output_size" |) |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition call : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into an account. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let to := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "to" |) + ], + make_dict [] + |) in + let access_gas_cost := + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + M.pure Constant.None_ + )) |) in + let create_gas_cost := + (* if *) +M.if_then_else (| + BoolOp.or (| + M.call (| + M.get_name (| globals, "is_account_alive" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "to" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |) + )) + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let transfer_gas_cost := + (* if *) +M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "access_gas_cost" |), + M.get_name (| globals, "create_gas_cost" |) + |), + M.get_name (| globals, "transfer_gas_cost" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.or (| + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "value" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) + )) + |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let sender_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.get_name (| globals, "value" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "to" |); + Constant.bool true; + Constant.bool false; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition callcode : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into this account with alternative account’s code. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let code_address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let to := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "code_address" |) + ], + make_dict [] + |) in + let access_gas_cost := + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + M.pure Constant.None_ + )) |) in + let transfer_gas_cost := + (* if *) +M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + BinOp.add (| + M.get_name (| globals, "access_gas_cost" |), + M.get_name (| globals, "transfer_gas_cost" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let sender_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.get_name (| globals, "value" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "code_address" |); + Constant.bool true; + Constant.bool false; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition selfdestruct : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Halt execution and register account for later deletion. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let beneficiary := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let gas_cost := + M.get_name (| globals, "GAS_SELF_DESTRUCT" |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := + M.pure Constant.None_ + )) |) in + let originator := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in + let refunded_accounts := + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in + let parent_evm := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "parent_evm" |) in + While Compare.is_not (| + M.get_name (| globals, "parent_evm" |), + Constant.None_ + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "refunded_accounts" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "parent_evm" |), "accounts_to_delete" |) + ], + make_dict [] + |) in + let parent_evm := + M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in + EndWhile. + let _ := + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "gas_cost" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let beneficiary_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |), "balance" |) in + let originator_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "originator" |) + ], + make_dict [] + |), "balance" |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |); + BinOp.add (| + M.get_name (| globals, "beneficiary_balance" |), + M.get_name (| globals, "originator_balance" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "originator" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |), "add" |), + make_list [ + M.get_name (| globals, "originator" |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "running" |), + Constant.bool false + |) in + let _ := M.pass (| |) in + M.pure Constant.None_)). + +Definition delegatecall : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into an account. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let code_address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "code_address" |) + ], + make_dict [] + |) in + let access_gas_cost := + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + M.pure Constant.None_ + )) |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + M.get_name (| globals, "access_gas_cost" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "value" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "caller" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "code_address" |); + Constant.bool false; + Constant.bool false; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition staticcall : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into an account. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let to := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "to" |) + ], + make_dict [] + |) in + let access_gas_cost := + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + M.pure Constant.None_ + )) |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + M.get_name (| globals, "access_gas_cost" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "to" |); + Constant.bool true; + Constant.bool true; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition revert : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stop execution and revert state changes, without consuming all provided gas + and also has the ability to return a reason + Parameters + ---------- + evm : + The current EVM frame. + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let output := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "bytes" |), + make_list [ + M.get_name (| globals, "output" |) + ], + make_dict [] + |) + |) in + let _ := M.raise (| Some(M.get_name (| globals, "Revert" |)) + let _ := M.pass (| |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/vm/interpreter.v b/CoqOfPython/ethereum/berlin/vm/interpreter.v index 401ea98..2869f71 100644 --- a/CoqOfPython/ethereum/berlin/vm/interpreter.v +++ b/CoqOfPython/ethereum/berlin/vm/interpreter.v @@ -182,91 +182,6 @@ Definition process_message_call : Value.t -> Value.t -> M := Output of the message call " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_name (| globals, "message" |), "target" |), M.call (| - M.get_name (| globals, "Bytes0" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let is_collision := - M.call (| - M.get_name (| globals, "account_has_code_or_nonce" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_field (| M.get_name (| globals, "message" |), "current_target" |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - M.get_name (| globals, "is_collision" |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "MessageCallOutput" |), - make_list [ - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |); - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |); - M.call (| - M.get_name (| globals, "tuple" |), - make_list [], - make_dict [] - |); - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |); - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |); - M.call (| - M.get_name (| globals, "AddressCollision" |), - make_list [], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let evm := - M.call (| - M.get_name (| globals, "process_create_message" |), - make_list [ - M.get_name (| globals, "message" |); - M.get_name (| globals, "env" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let evm := M.call (| M.get_name (| globals, "process_message" |), @@ -277,74 +192,11 @@ Definition process_message_call : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_field (| M.get_name (| globals, "message" |), "target" |) - ], - make_dict [] - |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), - make_list [ - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_field (| M.get_name (| globals, "message" |), "target" |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "evm" |), "error" |), - (* then *) - ltac:(M.monadic ( -(* At stmt: unsupported node type: AnnAssign *) - let accounts_to_delete := - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |) in - let touched_accounts := - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |) in - let refund_counter := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let logs := M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in let accounts_to_delete := @@ -388,7 +240,6 @@ Definition process_message_call : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). Definition process_create_message : Value.t -> Value.t -> M := @@ -450,28 +301,6 @@ Definition process_create_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), - (* then *) - ltac:(M.monadic ( - let contract_code := - M.get_field (| M.get_name (| globals, "evm" |), "output" |) in - let contract_code_gas := - BinOp.mult (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "contract_code" |) - ], - make_dict [] - |), - M.get_name (| globals, "GAS_CODE_DEPOSIT" |) - |) in -(* At stmt: unsupported node type: Try *) - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "rollback_transaction" |), make_list [ @@ -483,7 +312,6 @@ Definition process_create_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) - |) in M.pure Constant.None_)). Definition process_message : Value.t -> Value.t -> M := @@ -505,21 +333,6 @@ Definition process_message : Value.t -> Value.t -> M := Items containing execution specific objects " in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_field (| M.get_name (| globals, "message" |), "depth" |), M.get_name (| globals, "STACK_DEPTH_LIMIT" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "StackDepthLimitError" |), - make_list [ - Constant.str "Stack depth limit reached" - ], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -538,29 +351,6 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - M.get_field (| M.get_name (| globals, "message" |), "should_transfer_value" |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_field (| M.get_name (| globals, "message" |), "value" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "move_ether" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_field (| M.get_name (| globals, "message" |), "caller" |); - M.get_field (| M.get_name (| globals, "message" |), "current_target" |); - M.get_field (| M.get_name (| globals, "message" |), "value" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let evm := @@ -573,21 +363,6 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "evm" |), "error" |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "rollback_transaction" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "commit_transaction" |), make_list [ @@ -599,7 +374,6 @@ Definition process_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) - |) in M.pure Constant.None_)). Definition execute_code : Value.t -> Value.t -> M := @@ -639,5 +413,4 @@ Definition execute_code : Value.t -> Value.t -> M := (* At stmt: unsupported node type: Try *) let _ := M.return_ (| M.get_name (| globals, "evm" |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/vm/memory.v b/CoqOfPython/ethereum/berlin/vm/memory.v index fa8d906..4b107fd 100644 --- a/CoqOfPython/ethereum/berlin/vm/memory.v +++ b/CoqOfPython/ethereum/berlin/vm/memory.v @@ -45,22 +45,7 @@ Definition memory_write : Value.t -> Value.t -> M := Data to write to memory. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) - |) |), + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_)). @@ -86,23 +71,7 @@ Definition memory_read_bytes : Value.t -> Value.t -> M := Data read from memory. " in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |) - |) in + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |) M.pure Constant.None_)). Definition buffer_read : Value.t -> Value.t -> M := @@ -129,25 +98,9 @@ Definition buffer_read : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "right_pad_zero_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |); + M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |) |); M.get_name (| globals, "size" |) ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/alt_bn128.v index 19b83fc..abe4238 100644 --- a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/alt_bn128.v +++ b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/alt_bn128.v @@ -210,15 +210,6 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) in For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ] do let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "i" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -362,15 +353,6 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) in For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ] do let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "i" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -443,24 +425,6 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_eq (| BinOp.mod_ (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "data" |) - ], - make_dict [] - |), - Constant.int 192 - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let result := @@ -509,32 +473,11 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := Constant.int 32, M.get_name (| globals, "j" |) |) - |):BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "i" |), - Constant.int 192 - |), - BinOp.mult (| - Constant.int 32, - BinOp.add (| - M.get_name (| globals, "j" |), - Constant.int 1 - |) - |) |) |) ], make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "value" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -555,17 +498,20 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.call (| - M.get_field (| M.get_name (| globals, "p" |), "mul_by" |), - make_list [ - M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) - ], - make_dict [] - |), M.call (| - M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) |); + Compare.eq (| + M.call (| + M.get_field (| M.get_name (| globals, "p" |), "mul_by" |), + make_list [ + M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) + ], + make_dict [] + |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |); M.get_name (| globals, "OutOfGasError" |) ], make_dict [] @@ -573,87 +519,29 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.call (| - M.get_field (| M.get_name (| globals, "q" |), "mul_by" |), - make_list [ - M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) - ], - make_dict [] - |), M.call (| - M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) |); + Compare.eq (| + M.call (| + M.get_field (| M.get_name (| globals, "q" |), "mul_by" |), + make_list [ + M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) + ], + make_dict [] + |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |); M.get_name (| globals, "OutOfGasError" |) ], make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "p" |), M.call (| - M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_name (| globals, "q" |), M.call (| - M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let result := - BinOp.mult (| - M.get_name (| globals, "result" |), - M.call (| - M.get_name (| globals, "pairing" |), - make_list [ - M.get_name (| globals, "q" |); - M.get_name (| globals, "p" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "result" |), M.call (| - M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), - make_list [ - Constant.int 1 - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign (| - M.get_field (| M.get_name (| globals, "evm" |), "output" |), - M.call (| - M.get_field (| M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 1 - ], - make_dict [] - |), "to_be_bytes32" |), - make_list [], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| diff --git a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/blake2f.v b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/blake2f.v index 5903066..1647d48 100644 --- a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/blake2f.v +++ b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/blake2f.v @@ -55,13 +55,16 @@ Definition blake2f : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "data" |) - ], - make_dict [] - |), Constant.int 213 |); + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 213 + |); M.get_name (| globals, "InvalidParameter" |) ], make_dict [] @@ -96,10 +99,13 @@ Definition blake2f : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.in (| M.get_name (| globals, "f" |), make_list [ - Constant.int 0; - Constant.int 1 - ] |); + Compare.in (| + M.get_name (| globals, "f" |), + make_list [ + Constant.int 0; + Constant.int 1 + ] + |); M.get_name (| globals, "InvalidParameter" |) ], make_dict [] diff --git a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/ecrecover.v index cc351b5..0cbcf16 100644 --- a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/ecrecover.v @@ -188,60 +188,12 @@ Definition ecrecover : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 27 |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 28 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| Constant.int 0, M.get_name (| globals, "r" |) |), - ltac:(M.monadic ( - Compare.gt_e (| M.get_name (| globals, "r" |), M.get_name (| globals, "SECP256K1N" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| Constant.int 0, M.get_name (| globals, "s" |) |), - ltac:(M.monadic ( - Compare.gt_e (| M.get_name (| globals, "s" |), M.get_name (| globals, "SECP256K1N" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: Try *) @@ -252,7 +204,7 @@ Definition ecrecover : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12:Constant.int 32 |) in + |), Constant.int 12 |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/modexp.v index 544949e..3505244 100644 --- a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/modexp.v +++ b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/modexp.v @@ -192,30 +192,6 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_name (| globals, "base_length" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "modulus_length" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign (| - M.get_field (| M.get_name (| globals, "evm" |), "output" |), - M.call (| - M.get_name (| globals, "Bytes" |), - make_list [], - make_dict [] - |) - |) in - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let base := @@ -278,27 +254,6 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "modulus" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign (| - M.get_field (| M.get_name (| globals, "evm" |), "output" |), - BinOp.mult (| - M.call (| - M.get_name (| globals, "Bytes" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |), - M.get_name (| globals, "modulus_length" |) - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| @@ -383,7 +338,6 @@ Definition complexity : Value.t -> Value.t -> M := M.get_name (| globals, "words" |), Constant.int 2 |) - |) in M.pure Constant.None_)). Definition iterations : Value.t -> Value.t -> M := @@ -410,64 +364,7 @@ Definition iterations : Value.t -> Value.t -> M := Number of iterations. " in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.lt_e (| M.get_name (| globals, "exponent_length" |), Constant.int 32 |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "exponent_head" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let count := - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - Compare.lt_e (| M.get_name (| globals, "exponent_length" |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let bit_length := - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.call (| - M.get_field (| M.get_name (| globals, "exponent_head" |), "bit_length" |), - make_list [], - make_dict [] - |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "bit_length" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let bit_length := BinOp.sub - Constant.int 1 - Constant.int 1 in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let count := - M.get_name (| globals, "bit_length" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let length_part := BinOp.mult (| Constant.int 8, @@ -495,17 +392,6 @@ Definition iterations : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "bits_part" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let bits_part := BinOp.sub - Constant.int 1 - Constant.int 1 in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let count := @@ -532,7 +418,6 @@ Definition iterations : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition gas_cost : Value.t -> Value.t -> M := @@ -604,5 +489,4 @@ Definition gas_cost : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/vm/runtime.v b/CoqOfPython/ethereum/berlin/vm/runtime.v index 835b46c..2cd7652 100644 --- a/CoqOfPython/ethereum/berlin/vm/runtime.v +++ b/CoqOfPython/ethereum/berlin/vm/runtime.v @@ -67,50 +67,19 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := ], make_dict [] |) in - While Compare.lt (| M.get_name (| globals, "pc" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "code" |) - ], - make_dict [] - |) |) do + While Compare.lt (| + M.get_name (| globals, "pc" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) + |) do (* At stmt: unsupported node type: Try *) let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "current_opcode" |), M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), - make_list [ - M.get_name (| globals, "pc" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - (* At expr: unsupported node type: Compare *), - (* then *) - ltac:(M.monadic ( - let push_data_size := - BinOp.add (| - BinOp.sub (| - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) - |), - Constant.int 1 - |) in - let pc := BinOp.add - M.get_name (| globals, "push_data_size" |) - M.get_name (| globals, "push_data_size" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -121,5 +90,4 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := EndWhile. let _ := M.return_ (| M.get_name (| globals, "valid_jump_destinations" |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/vm/stack.v b/CoqOfPython/ethereum/berlin/vm/stack.v index 42ea42d..ea778df 100644 --- a/CoqOfPython/ethereum/berlin/vm/stack.v +++ b/CoqOfPython/ethereum/berlin/vm/stack.v @@ -49,21 +49,6 @@ Definition pop : Value.t -> Value.t -> M := " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "stack" |) - ], - make_dict [] - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "StackUnderflowError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -72,7 +57,6 @@ Definition pop : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). Definition push : Value.t -> Value.t -> M := @@ -91,21 +75,6 @@ Definition push : Value.t -> Value.t -> M := " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "stack" |) - ], - make_dict [] - |), Constant.int 1024 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "StackOverflowError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -116,5 +85,4 @@ Definition push : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/bloom.v b/CoqOfPython/ethereum/byzantium/bloom.v index 04b5d9f..04650ff 100644 --- a/CoqOfPython/ethereum/byzantium/bloom.v +++ b/CoqOfPython/ethereum/byzantium/bloom.v @@ -72,10 +72,7 @@ Definition add_to_bloom : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |):BinOp.add (| - M.get_name (| globals, "idx" |), - Constant.int 2 - |) |) + M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |) |) ], make_dict [] |), @@ -160,5 +157,4 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/fork.v b/CoqOfPython/ethereum/byzantium/fork.v new file mode 100644 index 0000000..1151a67 --- /dev/null +++ b/CoqOfPython/ethereum/byzantium/fork.v @@ -0,0 +1,2160 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Specification +^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Entry point for the Ethereum specification. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". + +Require ethereum.crypto.elliptic_curve. +Axiom ethereum_crypto_elliptic_curve_SECP256K1N : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.ethash. +Axiom ethereum_ethash_dataset_size : + IsGlobalAlias globals ethereum.ethash.globals "dataset_size". +Axiom ethereum_ethash_generate_cache : + IsGlobalAlias globals ethereum.ethash.globals "generate_cache". +Axiom ethereum_ethash_hashimoto_light : + IsGlobalAlias globals ethereum.ethash.globals "hashimoto_light". + +Require ethereum.exceptions. +Axiom ethereum_exceptions_InvalidBlock : + IsGlobalAlias globals ethereum.exceptions.globals "InvalidBlock". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U64 : + IsGlobalAlias globals base_types.globals "U64". +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_U256_CEIL_VALUE : + IsGlobalAlias globals base_types.globals "U256_CEIL_VALUE". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". + +Require __init__. +Axiom __init___vm : + IsGlobalAlias globals __init__.globals "vm". + +Require blocks. +Axiom blocks_Block : + IsGlobalAlias globals blocks.globals "Block". +Axiom blocks_Header : + IsGlobalAlias globals blocks.globals "Header". +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". +Axiom blocks_Receipt : + IsGlobalAlias globals blocks.globals "Receipt". + +Require bloom. +Axiom bloom_logs_bloom : + IsGlobalAlias globals bloom.globals "logs_bloom". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Require state. +Axiom state_State : + IsGlobalAlias globals state.globals "State". +Axiom state_account_exists_and_is_empty : + IsGlobalAlias globals state.globals "account_exists_and_is_empty". +Axiom state_create_ether : + IsGlobalAlias globals state.globals "create_ether". +Axiom state_destroy_account : + IsGlobalAlias globals state.globals "destroy_account". +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". +Axiom state_increment_nonce : + IsGlobalAlias globals state.globals "increment_nonce". +Axiom state_set_account_balance : + IsGlobalAlias globals state.globals "set_account_balance". +Axiom state_state_root : + IsGlobalAlias globals state.globals "state_root". + +Require transactions. +Axiom transactions_TX_BASE_COST : + IsGlobalAlias globals transactions.globals "TX_BASE_COST". +Axiom transactions_TX_CREATE_COST : + IsGlobalAlias globals transactions.globals "TX_CREATE_COST". +Axiom transactions_TX_DATA_COST_PER_NON_ZERO : + IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_NON_ZERO". +Axiom transactions_TX_DATA_COST_PER_ZERO : + IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_ZERO". +Axiom transactions_Transaction : + IsGlobalAlias globals transactions.globals "Transaction". + +Require trie. +Axiom trie_Trie : + IsGlobalAlias globals trie.globals "Trie". +Axiom trie_root : + IsGlobalAlias globals trie.globals "root". +Axiom trie_trie_set : + IsGlobalAlias globals trie.globals "trie_set". + +Require utils.message. +Axiom utils_message_prepare_message : + IsGlobalAlias globals utils.message.globals "prepare_message". + +Require vm.interpreter. +Axiom vm_interpreter_process_message_call : + IsGlobalAlias globals vm.interpreter.globals "process_message_call". + +Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mult (| + Constant.int 3, + BinOp.pow (| + Constant.int 10, + Constant.int 18 + |) + |) + ], + make_dict [] + |) +)). + +Definition GAS_LIMIT_ADJUSTMENT_FACTOR : Value.t := M.run ltac:(M.monadic ( + Constant.int 1024 +)). + +Definition GAS_LIMIT_MINIMUM : Value.t := M.run ltac:(M.monadic ( + Constant.int 5000 +)). + +Definition MINIMUM_DIFFICULTY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 131072 + ], + make_dict [] + |) +)). + +Definition MAX_OMMER_DEPTH : Value.t := M.run ltac:(M.monadic ( + Constant.int 6 +)). + +Definition BOMB_DELAY_BLOCKS : Value.t := M.run ltac:(M.monadic ( + Constant.int 3000000 +)). + +Definition EMPTY_OMMER_HASH : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_list [] + ], + make_dict [] + |) + ], + make_dict [] + |) +)). + +Definition BlockChain : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition apply_fork : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "old" ] |) in + let _ := Constant.str " + Transforms the state from the previous hard fork (`old`) into the block + chain object for this hard fork and returns it. + + When forks need to implement an irregular state transition, this function + is used to handle the irregularity. See the :ref:`DAO Fork ` for + an example. + + Parameters + ---------- + old : + Previous block chain object. + + Returns + ------- + new : `BlockChain` + Upgraded block chain object for this hard fork. + " in + let _ := M.return_ (| + M.get_name (| globals, "old" |) + M.pure Constant.None_)). + +Definition get_last_256_block_hashes : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "chain" ] |) in + let _ := Constant.str " + Obtain the list of hashes of the previous 256 blocks in order of + increasing block number. + + This function will return less hashes for the first 256 blocks. + + The ``BLOCKHASH`` opcode needs to access the latest hashes on the chain, + therefore this function retrieves them. + + Parameters + ---------- + chain : + History and current state. + + Returns + ------- + recent_block_hashes : `List[Hash32]` + Hashes of the recent 256 blocks in order of increasing block number. + " in + let recent_blocks := + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |) |) in + let _ := + M.pure Constant.None_ + )) |) in + let recent_block_hashes := + make_list [] in + For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_blocks" |) do + let prev_block_hash := + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), + make_list [ + M.get_name (| globals, "prev_block_hash" |) + ], + make_dict [] + |) in + EndFor. + let most_recent_block_hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_field (| M.get_subscript (| M.get_name (| globals, "recent_blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), + make_list [ + M.get_name (| globals, "most_recent_block_hash" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "recent_block_hashes" |) + M.pure Constant.None_)). + +Definition state_transition : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "chain"; "block" ] |) in + let _ := Constant.str " + Attempts to apply a block to an existing block chain. + + All parts of the block's contents need to be verified before being added + to the chain. Blocks are verified by ensuring that the contents of the + block make logical sense with the contents of the parent block. The + information in the block's header must also match the corresponding + information in the block. + + To implement Ethereum, in theory clients are only required to store the + most recent 255 blocks of the chain since as far as execution is + concerned, only those blocks are accessed. Practically, however, clients + should store more blocks to handle reorgs. + + Parameters + ---------- + chain : + History and current state. + block : + Block to apply to `chain`. + " in + let parent_header := + M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) in + let _ := M.call (| + M.get_name (| globals, "validate_header" |), + make_list [ + M.get_field (| M.get_name (| globals, "block" |), "header" |); + M.get_name (| globals, "parent_header" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "validate_ommers" |), + make_list [ + M.get_field (| M.get_name (| globals, "block" |), "ommers" |); + M.get_field (| M.get_name (| globals, "block" |), "header" |); + M.get_name (| globals, "chain" |) + ], + make_dict [] + |) in + let apply_body_output := + M.call (| + M.get_name (| globals, "apply_body" |), + make_list [ + M.get_field (| M.get_name (| globals, "chain" |), "state" |); + M.call (| + M.get_name (| globals, "get_last_256_block_hashes" |), + make_list [ + M.get_name (| globals, "chain" |) + ], + make_dict [] + |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "coinbase" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "number" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "gas_limit" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "timestamp" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "difficulty" |); + M.get_field (| M.get_name (| globals, "block" |), "transactions" |); + M.get_field (| M.get_name (| globals, "block" |), "ommers" |); + M.get_field (| M.get_name (| globals, "chain" |), "chain_id" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_gas_used" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "gas_used" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "transactions_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "transactions_root" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "state_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "state_root" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "receipt_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "receipt_root" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_logs_bloom" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "bloom" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), "append" |), + make_list [ + M.get_name (| globals, "block" |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition validate_header : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header"; "parent_header" ] |) in + let _ := Constant.str " + Verifies a block header. + + In order to consider a block's header valid, the logic for the + quantities in the header should match the logic for the block itself. + For example the header timestamp should be greater than the block's parent + timestamp because the block was created *after* the parent block. + Additionally, the block's number should be directly following the parent + block's number since it is the next block in the sequence. + + Parameters + ---------- + header : + Header to check for correctness. + parent_header : + Parent Header of the header to check for correctness + " in + let parent_has_ommers := + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "parent_header" |), "ommers_hash" |), + M.get_name (| globals, "EMPTY_OMMER_HASH" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt (| + M.get_field (| M.get_name (| globals, "header" |), "timestamp" |), + M.get_field (| M.get_name (| globals, "parent_header" |), "timestamp" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "number" |), + BinOp.add (| + M.get_field (| M.get_name (| globals, "parent_header" |), "number" |), + Constant.int 1 + |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + M.call (| + M.get_name (| globals, "check_gas_limit" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "gas_limit" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "gas_limit" |) + ], + make_dict [] + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) + ], + make_dict [] + |), + Constant.int 32 + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let block_difficulty := + M.call (| + M.get_name (| globals, "calculate_block_difficulty" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "number" |); + M.get_field (| M.get_name (| globals, "header" |), "timestamp" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "timestamp" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "difficulty" |); + M.get_name (| globals, "parent_has_ommers" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "difficulty" |), + M.get_name (| globals, "block_difficulty" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let block_parent_hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "parent_header" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |), + M.get_name (| globals, "block_parent_hash" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "validate_proof_of_work" |), + make_list [ + M.get_name (| globals, "header" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header" ] |) in + let _ := Constant.str " + Generate rlp hash of the header which is to be used for Proof-of-Work + verification. + + In other words, the PoW artefacts `mix_digest` and `nonce` are ignored + while calculating this hash. + + A particular PoW is valid for a single hash, that hash is computed by + this function. The `nonce` and `mix_digest` are omitted from this hash + because they are being changed by miners in their search for a sufficient + proof-of-work. + + Parameters + ---------- + header : + The header object for which the hash is to be generated. + + Returns + ------- + hash : `Hash32` + The PoW valid rlp hash of the passed in header. + " in + let header_data_without_pow_artefacts := + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |); + M.get_field (| M.get_name (| globals, "header" |), "ommers_hash" |); + M.get_field (| M.get_name (| globals, "header" |), "coinbase" |); + M.get_field (| M.get_name (| globals, "header" |), "state_root" |); + M.get_field (| M.get_name (| globals, "header" |), "transactions_root" |); + M.get_field (| M.get_name (| globals, "header" |), "receipt_root" |); + M.get_field (| M.get_name (| globals, "header" |), "bloom" |); + M.get_field (| M.get_name (| globals, "header" |), "difficulty" |); + M.get_field (| M.get_name (| globals, "header" |), "number" |); + M.get_field (| M.get_name (| globals, "header" |), "gas_limit" |); + M.get_field (| M.get_name (| globals, "header" |), "gas_used" |); + M.get_field (| M.get_name (| globals, "header" |), "timestamp" |); + M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) + ] in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "header_data_without_pow_artefacts" |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition validate_proof_of_work : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header" ] |) in + let _ := Constant.str " + Validates the Proof of Work constraints. + + In order to verify that a miner's proof-of-work is valid for a block, a + ``mix-digest`` and ``result`` are calculated using the ``hashimoto_light`` + hash function. The mix digest is a hash of the header and the nonce that + is passed through and it confirms whether or not proof-of-work was done + on the correct block. The result is the actual hash value of the block. + + Parameters + ---------- + header : + Header of interest. + " in + let header_hash := + M.call (| + M.get_name (| globals, "generate_header_hash_for_pow" |), + make_list [ + M.get_name (| globals, "header" |) + ], + make_dict [] + |) in + let cache := + M.call (| + M.get_name (| globals, "generate_cache" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "number" |) + ], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "mix_digest" |); M.get_name (| globals, "result" |) ], + M.call (| + M.get_name (| globals, "hashimoto_light" |), + make_list [ + M.get_name (| globals, "header_hash" |); + M.get_field (| M.get_name (| globals, "header" |), "nonce" |); + M.get_name (| globals, "cache" |); + M.call (| + M.get_name (| globals, "dataset_size" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "number" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_name (| globals, "mix_digest" |), + M.get_field (| M.get_name (| globals, "header" |), "mix_digest" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "result" |) + ], + make_dict [] + |), + BinOp.floor_div (| + M.get_name (| globals, "U256_CEIL_VALUE" |), + M.get_field (| M.get_name (| globals, "header" |), "difficulty" |) + |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition check_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx"; "gas_available"; "chain_id" ] |) in + let _ := Constant.str " + Check if the transaction is includable in the block. + + Parameters + ---------- + tx : + The transaction. + gas_available : + The gas remaining in the block. + chain_id : + The ID of the current chain. + + Returns + ------- + sender_address : + The sender of the transaction. + + Raises + ------ + InvalidBlock : + If the transaction is not includable. + " in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_name (| globals, "gas_available" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let sender_address := + M.call (| + M.get_name (| globals, "recover_sender" |), + make_list [ + M.get_name (| globals, "chain_id" |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "sender_address" |) + M.pure Constant.None_)). + +Definition make_receipt : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx"; "error"; "cumulative_gas_used"; "logs" ] |) in + let _ := Constant.str " + Make the receipt for a transaction that was executed. + + Parameters + ---------- + tx : + The executed transaction. + error : + Error in the top level frame of the transaction, if any. + cumulative_gas_used : + The total gas used so far in the block after the transaction was + executed. + logs : + The logs produced by the transaction. + + Returns + ------- + receipt : + The receipt for the transaction. + " in + let receipt := + M.call (| + M.get_name (| globals, "Receipt" |), + make_list [], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "receipt" |) + M.pure Constant.None_)). + +Definition ApplyBodyOutput : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition apply_body : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "block_hashes"; "coinbase"; "block_number"; "block_gas_limit"; "block_time"; "block_difficulty"; "transactions"; "ommers"; "chain_id" ] |) in + let _ := Constant.str " + Executes a block. + + Many of the contents of a block are stored in data structures called + tries. There is a transactions trie which is similar to a ledger of the + transactions stored in the current block. There is also a receipts trie + which stores the results of executing a transaction, like the post state + and gas used. This function creates and executes the block that is to be + added to the chain. + + Parameters + ---------- + state : + Current account state. + block_hashes : + List of hashes of the previous 256 blocks in the order of + increasing block number. + coinbase : + Address of account which receives block reward and transaction fees. + block_number : + Position of the block within the chain. + block_gas_limit : + Initial amount of gas available for execution in this block. + block_time : + Time the block was produced, measured in seconds since the epoch. + block_difficulty : + Difficulty of the block. + transactions : + Transactions included in the block. + ommers : + Headers of ancestor blocks which are not direct parents (formerly + uncles.) + chain_id : + ID of the executing chain. + + Returns + ------- + apply_body_output : `ApplyBodyOutput` + Output of applying the block body to the state. + " in + let gas_available := + M.get_name (| globals, "block_gas_limit" |) in +(* At stmt: unsupported node type: AnnAssign *) +(* At stmt: unsupported node type: AnnAssign *) +(* At stmt: unsupported node type: AnnAssign *) + For make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "tx" |) ] in M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "transactions" |) + ], + make_dict [] + |) do + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "transactions_trie" |); + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "i" |) + ], + make_dict [] + |) + ], + make_dict [] + |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) in + let sender_address := + M.call (| + M.get_name (| globals, "check_transaction" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "gas_available" |); + M.get_name (| globals, "chain_id" |) + ], + make_dict [] + |) in + let env := + M.call (| + M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |); M.get_name (| globals, "error" |) ], + M.call (| + M.get_name (| globals, "process_transaction" |), + make_list [ + M.get_name (| globals, "env" |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) in + let gas_available := BinOp.sub + M.get_name (| globals, "gas_used" |) + M.get_name (| globals, "gas_used" |) in + let receipt := + M.call (| + M.get_name (| globals, "make_receipt" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "error" |); + BinOp.sub (| + M.get_name (| globals, "block_gas_limit" |), + M.get_name (| globals, "gas_available" |) + |); + M.get_name (| globals, "logs" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "receipts_trie" |); + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "i" |) + ], + make_dict [] + |) + ], + make_dict [] + |); + M.get_name (| globals, "receipt" |) + ], + make_dict [] + |) in + let block_logs := BinOp.add + M.get_name (| globals, "logs" |) + M.get_name (| globals, "logs" |) in + EndFor. + let _ := M.call (| + M.get_name (| globals, "pay_rewards" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "block_number" |); + M.get_name (| globals, "coinbase" |); + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |) in + let block_gas_used := + BinOp.sub (| + M.get_name (| globals, "block_gas_limit" |), + M.get_name (| globals, "gas_available" |) + |) in + let block_logs_bloom := + M.call (| + M.get_name (| globals, "logs_bloom" |), + make_list [ + M.get_name (| globals, "block_logs" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ApplyBodyOutput" |), + make_list [ + M.get_name (| globals, "block_gas_used" |); + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_name (| globals, "transactions_trie" |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_name (| globals, "receipts_trie" |) + ], + make_dict [] + |); + M.get_name (| globals, "block_logs_bloom" |); + M.call (| + M.get_name (| globals, "state_root" |), + make_list [ + M.get_name (| globals, "state" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition validate_ommers : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "ommers"; "block_header"; "chain" ] |) in + let _ := Constant.str " + Validates the ommers mentioned in the block. + + An ommer block is a block that wasn't canonically added to the + blockchain because it wasn't validated as fast as the canonical block + but was mined at the same time. + + To be considered valid, the ommers must adhere to the rules defined in + the Ethereum protocol. The maximum amount of ommers is 2 per block and + there cannot be duplicate ommers in a block. Many of the other ommer + constraints are listed in the in-line comments of this function. + + Parameters + ---------- + ommers : + List of ommers mentioned in the current block. + block_header: + The header of current block. + chain : + History and current state. + " in + let block_hash := + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "block_header" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + M.get_field (| M.get_name (| globals, "block_header" |), "ommers_hash" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.and (| + Compare.lt_e (| + Constant.int 1, + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |), + ltac:(M.monadic ( + Compare.lt (| + M.get_field (| M.get_name (| globals, "ommer" |), "number" |), + M.get_field (| M.get_name (| globals, "block_header" |), "number" |) + |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let ommer_parent_header := + M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), BinOp.sub (| + UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) |), + Constant.int 1 + |) |), "header" |) in + let _ := M.call (| + M.get_name (| globals, "validate_header" |), + make_list [ + M.get_name (| globals, "ommer" |); + M.get_name (| globals, "ommer_parent_header" |) + ], + make_dict [] + |) in + EndFor. + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + Constant.int 2 + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let ommers_hashes := + (* At expr: unsupported node type: ListComp *) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers_hashes" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_name (| globals, "set" |), + make_list [ + M.get_name (| globals, "ommers_hashes" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let recent_canonical_blocks := + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| BinOp.add (| + M.get_name (| globals, "MAX_OMMER_DEPTH" |), + Constant.int 1 + |) |) |) in + let recent_canonical_block_hashes := + (* At expr: unsupported node type: SetComp *) in +(* At stmt: unsupported node type: AnnAssign *) + For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_canonical_blocks" |) do + let recent_ommers_hashes := + M.call (| + M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), + make_list [ + (* At expr: unsupported node type: SetComp *) + ], + make_dict [] + |) in + EndFor. + For make_tuple [ M.get_name (| globals, "ommer_index" |); M.get_name (| globals, "ommer" |) ] in M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |) do + let ommer_hash := + M.get_subscript (| M.get_name (| globals, "ommers_hashes" |), M.get_name (| globals, "ommer_index" |) |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_eq (| + M.get_name (| globals, "ommer_hash" |), + M.get_name (| globals, "block_hash" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_in (| + M.get_name (| globals, "ommer_hash" |), + M.get_name (| globals, "recent_canonical_block_hashes" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_in (| + M.get_name (| globals, "ommer_hash" |), + M.get_name (| globals, "recent_ommers_hashes" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let ommer_age := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.and (| + Compare.lt_e (| + Constant.int 1, + M.get_name (| globals, "ommer_age" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_name (| globals, "ommer_age" |), + M.get_name (| globals, "MAX_OMMER_DEPTH" |) + |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.in (| + M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), + M.get_name (| globals, "recent_canonical_block_hashes" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), + M.get_field (| M.get_name (| globals, "block_header" |), "parent_hash" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_)). + +Definition pay_rewards : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "block_number"; "coinbase"; "ommers" ] |) in + let _ := Constant.str " + Pay rewards to the block miner as well as the ommers miners. + + The miner of the canonical block is rewarded with the predetermined + block reward, ``BLOCK_REWARD``, plus a variable award based off of the + number of ommer blocks that were mined around the same time, and included + in the canonical block's header. An ommer block is a block that wasn't + added to the canonical blockchain because it wasn't validated as fast as + the accepted block but was mined at the same time. Although not all blocks + that are mined are added to the canonical chain, miners are still paid a + reward for their efforts. This reward is called an ommer reward and is + calculated based on the number associated with the ommer block that they + mined. + + Parameters + ---------- + state : + Current account state. + block_number : + Position of the block within the chain. + coinbase : + Address of account which receives block reward and transaction fees. + ommers : + List of ommers mentioned in the current block. + " in + let miner_reward := + BinOp.add (| + M.get_name (| globals, "BLOCK_REWARD" |), + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + BinOp.floor_div (| + M.get_name (| globals, "BLOCK_REWARD" |), + Constant.int 32 + |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "create_ether" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "coinbase" |); + M.get_name (| globals, "miner_reward" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do + let ommer_age := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "block_number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) + ], + make_dict [] + |) in + let ommer_miner_reward := + BinOp.floor_div (| + BinOp.mult (| + BinOp.sub (| + Constant.int 8, + M.get_name (| globals, "ommer_age" |) + |), + M.get_name (| globals, "BLOCK_REWARD" |) + |), + Constant.int 8 + |) in + let _ := M.call (| + M.get_name (| globals, "create_ether" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_field (| M.get_name (| globals, "ommer" |), "coinbase" |); + M.get_name (| globals, "ommer_miner_reward" |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_)). + +Definition process_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "env"; "tx" ] |) in + let _ := Constant.str " + Execute a transaction against the provided environment. + + This function processes the actions needed to execute a transaction. + It decrements the sender's account after calculating the gas fee and + refunds them the proper amount after execution. Calling contracts, + deploying code, and incrementing nonces are all examples of actions that + happen within this function or from a call made within this function. + + Accounts that are marked for deletion are processed and destroyed after + execution. + + Parameters + ---------- + env : + Environment for the Ethereum Virtual Machine. + tx : + Transaction to execute. + + Returns + ------- + gas_left : `ethereum.base_types.U256` + Remaining gas after execution. + logs : `Tuple[ethereum.blocks.Log, ...]` + Logs generated during execution. + " in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + M.call (| + M.get_name (| globals, "validate_transaction" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let sender := + M.get_field (| M.get_name (| globals, "env" |), "origin" |) in + let sender_account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |) in + let gas_fee := + BinOp.mult (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "sender_account" |), "nonce" |), + M.get_field (| M.get_name (| globals, "tx" |), "nonce" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt_e (| + M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), + BinOp.add (| + M.get_name (| globals, "gas_fee" |), + M.get_field (| M.get_name (| globals, "tx" |), "value" |) + |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "sender_account" |), "code" |), + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [], + make_dict [] + |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let gas := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.call (| + M.get_name (| globals, "calculate_intrinsic_cost" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) in + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |) in + let sender_balance_after_gas_fee := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), + M.get_name (| globals, "gas_fee" |) + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |); + M.get_name (| globals, "sender_balance_after_gas_fee" |) + ], + make_dict [] + |) in + let message := + M.call (| + M.get_name (| globals, "prepare_message" |), + make_list [ + M.get_name (| globals, "sender" |); + M.get_field (| M.get_name (| globals, "tx" |), "to" |); + M.get_field (| M.get_name (| globals, "tx" |), "value" |); + M.get_field (| M.get_name (| globals, "tx" |), "data" |); + M.get_name (| globals, "gas" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let output := + M.call (| + M.get_name (| globals, "process_message_call" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let gas_used := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "output" |), "gas_left" |) + |) in + let gas_refund := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + BinOp.floor_div (| + M.get_name (| globals, "gas_used" |), + Constant.int 2 + |); + M.get_field (| M.get_name (| globals, "output" |), "refund_counter" |) + ], + make_dict [] + |) in + let gas_refund_amount := + BinOp.mult (| + BinOp.add (| + M.get_field (| M.get_name (| globals, "output" |), "gas_left" |), + M.get_name (| globals, "gas_refund" |) + |), + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) + |) in + let transaction_fee := + BinOp.mult (| + BinOp.sub (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "output" |), "gas_left" |) + |), + M.get_name (| globals, "gas_refund" |) + |), + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) + |) in + let total_gas_used := + BinOp.sub (| + M.get_name (| globals, "gas_used" |), + M.get_name (| globals, "gas_refund" |) + |) in + let sender_balance_after_refund := + BinOp.add (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |), "balance" |), + M.get_name (| globals, "gas_refund_amount" |) + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |); + M.get_name (| globals, "sender_balance_after_refund" |) + ], + make_dict [] + |) in + let coinbase_balance_after_mining_fee := + BinOp.add (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |), "balance" |), + M.get_name (| globals, "transaction_fee" |) + |) in + let _ := + let _ := + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "accounts_to_delete" |) do + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + EndFor. + For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "touched_accounts" |) do + let _ := + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.return_ (| + make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |); M.get_field (| M.get_name (| globals, "output" |), "error" |) ] + M.pure Constant.None_)). + +Definition validate_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Verifies a transaction. + + The gas in a transaction gets used to pay for the intrinsic cost of + operations, therefore if there is insufficient gas then it would not + be possible to execute a transaction and it will be declared invalid. + + Additionally, the nonce of a transaction must not equal or exceed the + limit defined in `EIP-2681 `_. + In practice, defining the limit as ``2**64-1`` has no impact because + sending ``2**64-1`` transactions is improbable. It's not strictly + impossible though, ``2**64-1`` transactions is the entire capacity of the + Ethereum blockchain at 2022 gas limits for a little over 22 years. + + Parameters + ---------- + tx : + Transaction to validate. + + Returns + ------- + verified : `bool` + True if the transaction can be executed, or False otherwise. + " in + let _ := M.return_ (| + BoolOp.and (| + Compare.lt_e (| + M.call (| + M.get_name (| globals, "calculate_intrinsic_cost" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |), + M.get_field (| M.get_name (| globals, "tx" |), "gas" |) + |), + ltac:(M.monadic ( + Compare.lt (| + M.get_field (| M.get_name (| globals, "tx" |), "nonce" |), + BinOp.sub (| + BinOp.pow (| + Constant.int 2, + Constant.int 64 + |), + Constant.int 1 + |) + |) + )) + |) + M.pure Constant.None_)). + +Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Calculates the gas that is charged before execution is started. + + The intrinsic cost of the transaction is charged before execution has + begun. Functions/operations in the EVM cost money to execute so this + intrinsic cost is for the operations that need to be paid for as part of + the transaction. Data transfer, for example, is part of this intrinsic + cost. It costs ether to send data over the wire and that ether is + accounted for in the intrinsic cost calculated in this function. This + intrinsic cost must be calculated and paid for before execution in order + for all operations to be implemented. + + Parameters + ---------- + tx : + Transaction to compute the intrinsic cost of. + + Returns + ------- + verified : `ethereum.base_types.Uint` + The intrinsic cost of the transaction. + " in + let data_cost := + Constant.int 0 in + For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do + let _ := + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + M.pure Constant.None_ + )) |) in + EndFor. + let _ := + let create_cost := + Constant.int 0 in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "TX_BASE_COST" |), + M.get_name (| globals, "data_cost" |) + |), + M.get_name (| globals, "create_cost" |) + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition recover_sender : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "chain_id"; "tx" ] |) in + let _ := Constant.str " + Extracts the sender address from a transaction. + + The v, r, and s values are the three parts that make up the signature + of a transaction. In order to recover the sender of a transaction the two + components needed are the signature (``v``, ``r``, and ``s``) and the + signing hash of the transaction. The sender's public key can be obtained + with these two values and therefore the sender address can be retrieved. + + Parameters + ---------- + tx : + Transaction of interest. + chain_id : + ID of the executing chain. + + Returns + ------- + sender : `ethereum.fork_types.Address` + The address of the account that signed the transaction. + " in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "v" |); M.get_name (| globals, "r" |); M.get_name (| globals, "s" |) ], + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "v" |); M.get_field (| M.get_name (| globals, "tx" |), "r" |); M.get_field (| M.get_name (| globals, "tx" |), "s" |) ] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.and (| + Compare.lt (| + Constant.int 0, + M.get_name (| globals, "r" |) + |), + ltac:(M.monadic ( + Compare.lt (| + M.get_name (| globals, "r" |), + M.get_name (| globals, "SECP256K1N" |) + |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.and (| + Compare.lt (| + Constant.int 0, + M.get_name (| globals, "s" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_name (| globals, "s" |), + BinOp.floor_div (| + M.get_name (| globals, "SECP256K1N" |), + Constant.int 2 + |) + |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.or (| + Compare.eq (| + M.get_name (| globals, "v" |), + BinOp.add (| + Constant.int 35, + BinOp.mult (| + M.get_name (| globals, "chain_id" |), + Constant.int 2 + |) + |) + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "v" |), + BinOp.add (| + Constant.int 36, + BinOp.mult (| + M.get_name (| globals, "chain_id" |), + Constant.int 2 + |) + |) + |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + BinOp.sub (| + BinOp.sub (| + M.get_name (| globals, "v" |), + Constant.int 35 + |), + BinOp.mult (| + M.get_name (| globals, "chain_id" |), + Constant.int 2 + |) + |); + M.call (| + M.get_name (| globals, "signing_hash_155" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "chain_id" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_subscript (| M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), Constant.int 12 |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition signing_hash_pre155 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Compute the hash of a transaction used in a legacy (pre EIP 155) signature. + + Parameters + ---------- + tx : + Transaction of interest. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the transaction. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "nonce" |); M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |); M.get_field (| M.get_name (| globals, "tx" |), "gas" |); M.get_field (| M.get_name (| globals, "tx" |), "to" |); M.get_field (| M.get_name (| globals, "tx" |), "value" |); M.get_field (| M.get_name (| globals, "tx" |), "data" |) ] + ], + make_dict [] + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition signing_hash_155 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx"; "chain_id" ] |) in + let _ := Constant.str " + Compute the hash of a transaction used in a EIP 155 signature. + + Parameters + ---------- + tx : + Transaction of interest. + chain_id : + The id of the current chain. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the transaction. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "nonce" |); M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |); M.get_field (| M.get_name (| globals, "tx" |), "gas" |); M.get_field (| M.get_name (| globals, "tx" |), "to" |); M.get_field (| M.get_name (| globals, "tx" |), "value" |); M.get_field (| M.get_name (| globals, "tx" |), "data" |); M.get_name (| globals, "chain_id" |); M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) ] + ], + make_dict [] + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition compute_header_hash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header" ] |) in + let _ := Constant.str " + Computes the hash of a block header. + + The header hash of a block is the canonical hash that is used to refer + to a specific block and completely distinguishes a block from another. + + ``keccak256`` is a function that produces a 256 bit hash of any input. + It also takes in any number of bytes as an input and produces a single + hash for them. A hash is a completely unique output for a single input. + So an input corresponds to one unique hash that can be used to identify + the input exactly. + + Prior to using the ``keccak256`` hash function, the header must be + encoded using the Recursive-Length Prefix. See :ref:`rlp`. + RLP encoding the header converts it into a space-efficient format that + allows for easy transfer of data between nodes. The purpose of RLP is to + encode arbitrarily nested arrays of binary data, and RLP is the primary + encoding method used to serialize objects in Ethereum's execution layer. + The only purpose of RLP is to encode structure; encoding specific data + types (e.g. strings, floats) is left up to higher-order protocols. + + Parameters + ---------- + header : + Header of interest. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the header. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "header" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition check_gas_limit : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "gas_limit"; "parent_gas_limit" ] |) in + let _ := Constant.str " + Validates the gas limit for a block. + + The bounds of the gas limit, ``max_adjustment_delta``, is set as the + quotient of the parent block's gas limit and the + ``GAS_LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is + passed through as a parameter is greater than or equal to the *sum* of + the parent's gas and the adjustment delta then the limit for gas is too + high and fails this function's check. Similarly, if the limit is less + than or equal to the *difference* of the parent's gas and the adjustment + delta *or* the predefined ``GAS_LIMIT_MINIMUM`` then this function's + check fails because the gas limit doesn't allow for a sufficient or + reasonable amount of gas to be used on a block. + + Parameters + ---------- + gas_limit : + Gas limit to validate. + + parent_gas_limit : + Gas limit of the parent block. + + Returns + ------- + check : `bool` + True if gas limit constraints are satisfied, False otherwise. + " in + let max_adjustment_delta := + BinOp.floor_div (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) + |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + Constant.bool true + M.pure Constant.None_)). + +Definition calculate_block_difficulty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "block_number"; "block_timestamp"; "parent_timestamp"; "parent_difficulty"; "parent_has_ommers" ] |) in + let _ := Constant.str " + Computes difficulty of a block using its header and parent header. + + The difficulty is determined by the time the block was created after its + parent. The ``offset`` is calculated using the parent block's difficulty, + ``parent_difficulty``, and the timestamp between blocks. This offset is + then added to the parent difficulty and is stored as the ``difficulty`` + variable. If the time between the block and its parent is too short, the + offset will result in a positive number thus making the sum of + ``parent_difficulty`` and ``offset`` to be a greater value in order to + avoid mass forking. But, if the time is long enough, then the offset + results in a negative value making the block less difficult than + its parent. + + The base standard for a block's difficulty is the predefined value + set for the genesis block since it has no parent. So, a block + can't be less difficult than the genesis block, therefore each block's + difficulty is set to the maximum value between the calculated + difficulty and the ``GENESIS_DIFFICULTY``. + + Parameters + ---------- + block_number : + Block number of the block. + block_timestamp : + Timestamp of the block. + parent_timestamp : + Timestamp of the parent block. + parent_difficulty : + difficulty of the parent block. + parent_has_ommers: + does the parent have ommers. + + Returns + ------- + difficulty : `ethereum.base_types.Uint` + Computed difficulty for a block. + " in + let offset := + BinOp.mult (| + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "parent_difficulty" |) + ], + make_dict [] + |), + Constant.int 2048 + |), + M.call (| + M.get_name (| globals, "max" |), + make_list [ + BinOp.sub (| + (* if *) +M.if_then_else (| + M.get_name (| globals, "parent_has_ommers" |), +(* then *) +ltac:(M.monadic ( +Constant.int 2, + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "block_timestamp" |), + M.get_name (| globals, "parent_timestamp" |) + |) + ], + make_dict [] + |), + Constant.int 9 + |) + |); + UnOp.sub (| Constant.int 99 |) + ], + make_dict [] + |) + |) in + let difficulty := + BinOp.add (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "parent_difficulty" |) + ], + make_dict [] + |), + M.get_name (| globals, "offset" |) + |) in + let num_bomb_periods := + BinOp.sub (| + BinOp.floor_div (| + BinOp.sub (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "block_number" |) + ], + make_dict [] + |), + M.get_name (| globals, "BOMB_DELAY_BLOCKS" |) + |), + Constant.int 100000 + |), + Constant.int 2 + |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "max" |), + make_list [ + M.get_name (| globals, "difficulty" |); + M.get_name (| globals, "MINIMUM_DIFFICULTY" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/fork_types.v b/CoqOfPython/ethereum/byzantium/fork_types.v index d12953d..5c7dac3 100644 --- a/CoqOfPython/ethereum/byzantium/fork_types.v +++ b/CoqOfPython/ethereum/byzantium/fork_types.v @@ -98,5 +98,4 @@ Definition encode_account : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/state.v b/CoqOfPython/ethereum/byzantium/state.v index 53b3837..c5b604e 100644 --- a/CoqOfPython/ethereum/byzantium/state.v +++ b/CoqOfPython/ethereum/byzantium/state.v @@ -123,13 +123,7 @@ Definition begin_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) ], make_dict [] - |); {M.get_name (| globals, "k" |): M.call (| - M.get_name (| globals, "copy_trie" |), - make_list [ - M.get_name (| globals, "t" |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)} ] + |); (* At expr: unsupported node type: DictComp *) ] ], make_dict [] |) in @@ -207,27 +201,8 @@ Definition get_account : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "account" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "account" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_ACCOUNT" |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -262,7 +237,6 @@ Definition get_account_optional : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "account" |) - |) in M.pure Constant.None_)). Definition set_account : Value.t -> Value.t -> M := @@ -342,15 +316,6 @@ Definition destroy_storage : Value.t -> Value.t -> M := Address of account whose storage is to be deleted. " in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -385,23 +350,6 @@ Definition get_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let value := @@ -423,7 +371,6 @@ Definition get_storage : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "value" |) - |) in M.pure Constant.None_)). Definition set_storage : Value.t -> Value.t -> M := @@ -444,14 +391,17 @@ Definition set_storage : Value.t -> Value.t -> M := value : `U256` Value to set at the key. " in - let _ := M.assert (| Compare.is_not (| M.call (| - M.get_name (| globals, "trie_get" |), - make_list [ - M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), Constant.None_ |) |) in + let _ := M.assert (| Compare.is_not (| + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + Constant.None_ + |) |) in let trie := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), @@ -461,24 +411,6 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let trie := - M.call (| - M.get_name (| globals, "Trie" |), - make_list [], - make_dict [] - |) in - let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), - M.get_name (| globals, "trie" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -491,15 +423,6 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), {} |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -524,26 +447,8 @@ Definition storage_root : Value.t -> Value.t -> M := " in let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "root" |), - make_list [ - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_TRIE_ROOT" |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -574,7 +479,6 @@ Definition state_root : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition account_exists : Value.t -> Value.t -> M := @@ -596,15 +500,17 @@ Definition account_exists : Value.t -> Value.t -> M := True if account exists in the state trie, False otherwise " in let _ := M.return_ (| - Compare.is_not (| M.call (| - M.get_name (| globals, "get_account_optional" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), Constant.None_ |) - |) in + Compare.is_not (| + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + Constant.None_ + |) M.pure Constant.None_)). Definition account_has_code_or_nonce : Value.t -> Value.t -> M := @@ -637,18 +543,23 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := |) in let _ := M.return_ (| BoolOp.or (| - Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( - Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |) + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |) )) |) - |) in M.pure Constant.None_)). Definition is_account_empty : Value.t -> Value.t -> M := @@ -681,23 +592,31 @@ Definition is_account_empty : Value.t -> Value.t -> M := |) in let _ := M.return_ (| BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |), ltac:(M.monadic ( - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "balance" |), + Constant.int 0 + |) )) |) )) |) - |) in M.pure Constant.None_)). Definition account_exists_and_is_empty : Value.t -> Value.t -> M := @@ -731,28 +650,39 @@ Definition account_exists_and_is_empty : Value.t -> Value.t -> M := |) in let _ := M.return_ (| BoolOp.and (| - Compare.is_not (| M.get_name (| globals, "account" |), Constant.None_ |), + Compare.is_not (| + M.get_name (| globals, "account" |), + Constant.None_ + |), ltac:(M.monadic ( BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |), ltac:(M.monadic ( - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "balance" |), + Constant.int 0 + |) )) |) )) |) )) |) - |) in M.pure Constant.None_)). Definition is_account_alive : Value.t -> Value.t -> M := @@ -783,36 +713,33 @@ Definition is_account_alive : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "account" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.bool false - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| UnOp.not (| BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |), ltac:(M.monadic ( - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "balance" |), + Constant.int 0 + |) )) |) )) |) |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -920,30 +847,6 @@ Definition touch_account : Value.t -> Value.t -> M := The address of the account that need to initialised. " in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "account_exists" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "set_account" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |); - M.get_name (| globals, "EMPTY_ACCOUNT" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/trie.v b/CoqOfPython/ethereum/byzantium/trie.v index 6fbb787..37074d6 100644 --- a/CoqOfPython/ethereum/byzantium/trie.v +++ b/CoqOfPython/ethereum/byzantium/trie.v @@ -202,96 +202,16 @@ Definition encode_internal_node : Value.t -> Value.t -> M := " in (* At stmt: unsupported node type: AnnAssign *) let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "node" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let unencoded := - (* At constant: unsupported node type: Constant *) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "LeafNode" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let unencoded := - make_tuple [ M.call (| - M.get_name (| globals, "nibble_list_to_compact" |), - make_list [ - M.get_field (| M.get_name (| globals, "node" |), "rest_of_key" |); - Constant.bool true - ], - make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "ExtensionNode" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let unencoded := - make_tuple [ M.call (| - M.get_name (| globals, "nibble_list_to_compact" |), - make_list [ - M.get_field (| M.get_name (| globals, "node" |), "key_segment" |); - Constant.bool false - ], - make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "BranchNode" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let unencoded := - BinOp.add (| - M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), - make_list [ - M.get_field (| M.get_name (| globals, "node" |), "value" |) - ] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.call (| + let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ (* At expr: unsupported node type: JoinedStr *) ], make_dict [] - |) |) in + |)) M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -309,23 +229,6 @@ Definition encode_internal_node : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "encoded" |) - ], - make_dict [] - |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "unencoded" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_name (| globals, "keccak256" |), @@ -334,7 +237,6 @@ Definition encode_internal_node : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -348,83 +250,8 @@ Definition encode_node : Value.t -> Value.t -> M := Currently mostly an unimplemented stub. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "storage_root" |), Constant.None_ |) |) in - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "encode_account" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "storage_root" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - make_tuple [ M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "U256" |) ] - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.call (| - M.get_name (| globals, "cast" |), - make_list [ - M.get_field (| M.get_name (| globals, "rlp" |), "RLP" |); - M.get_name (| globals, "node" |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "Bytes" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "node" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "previous_trie" |), "encode_node" |), @@ -434,7 +261,6 @@ Definition encode_node : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -486,7 +312,6 @@ Definition copy_trie : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition trie_set : Value.t -> Value.t -> M := @@ -508,26 +333,6 @@ Definition trie_set : Value.t -> Value.t -> M := Node to insert at `key`. " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "value" |), M.get_field (| M.get_name (| globals, "trie" |), "default" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "key" |), M.get_field (| M.get_name (| globals, "trie" |), "_data" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), M.get_name (| globals, "value" |) @@ -565,7 +370,6 @@ Definition trie_get : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition common_prefix_length : Value.t -> Value.t -> M := @@ -588,28 +392,6 @@ Definition common_prefix_length : Value.t -> Value.t -> M := make_dict [] |) do let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| M.get_name (| globals, "i" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "b" |) - ], - make_dict [] - |) |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "i" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -621,7 +403,6 @@ Definition common_prefix_length : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition nibble_list_to_compact : Value.t -> Value.t -> M := @@ -667,68 +448,6 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| BinOp.mod_ (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |), - Constant.int 2 - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_name (| globals, "compact" |), "append" |), - make_list [ - BinOp.mult (| - Constant.int 16, - BinOp.mult (| - Constant.int 2, - M.get_name (| globals, "is_leaf" |) - |) - |) - ], - make_dict [] - |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 0; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |); - Constant.int 2 - ], - make_dict [] - |) do - let _ := M.call (| - M.get_field (| M.get_name (| globals, "compact" |), "append" |), - make_list [ - BinOp.add (| - BinOp.mult (| - Constant.int 16, - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) - |), - M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) - |) - ], - make_dict [] - |) in - EndFor. - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ @@ -790,7 +509,6 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition bytes_to_nibble_list : Value.t -> Value.t -> M := @@ -868,7 +586,6 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition _prepare_trie : Value.t -> Value.t -> M := @@ -898,45 +615,6 @@ Definition _prepare_trie : Value.t -> Value.t -> M := make_dict [] |) do let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "value" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in - let address := - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in - let encoded_value := - M.call (| - M.get_name (| globals, "encode_node" |), - make_list [ - M.get_name (| globals, "value" |); - M.call (| - M.get_name (| globals, "get_storage_root" |), - make_list [ - M.get_name (| globals, "address" |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let encoded_value := M.call (| M.get_name (| globals, "encode_node" |), @@ -950,29 +628,16 @@ Definition _prepare_trie : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.not_eq (| M.get_name (| globals, "encoded_value" |), (* At constant: unsupported node type: Constant *) |); + Compare.not_eq (| + M.get_name (| globals, "encoded_value" |), + Constant.bytes "" + |); M.get_name (| globals, "AssertionError" |) ], make_dict [] |) in (* At stmt: unsupported node type: AnnAssign *) let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "trie" |), "secured" |), - (* then *) - ltac:(M.monadic ( - let key := - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let key := M.get_name (| globals, "preimage" |) in M.pure Constant.None_ @@ -990,7 +655,6 @@ Definition _prepare_trie : Value.t -> Value.t -> M := EndFor. let _ := M.return_ (| M.get_name (| globals, "mapped" |) - |) in M.pure Constant.None_)). Definition root : Value.t -> Value.t -> M := @@ -1044,41 +708,6 @@ Definition root : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "root_node" |) - ], - make_dict [] - |) - ], - make_dict [] - |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "root_node" |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -1095,7 +724,6 @@ Definition root : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -1122,23 +750,6 @@ Definition patricialize : Value.t -> Value.t -> M := Root node of `obj`. " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "obj" |) - ], - make_dict [] - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.None_ - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let arbitrary_key := @@ -1156,36 +767,10 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "obj" |) - ], - make_dict [] - |), Constant.int 1 |), - (* then *) - ltac:(M.monadic ( - let leaf := - M.call (| - M.get_name (| globals, "LeafNode" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |); - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) - ], - make_dict [] - |) in - let _ := M.return_ (| - M.get_name (| globals, "leaf" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let substring := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |) |) in let prefix_length := M.call (| M.get_name (| globals, "len" |), @@ -1204,7 +789,7 @@ Definition patricialize : Value.t -> Value.t -> M := M.get_name (| globals, "common_prefix_length" |), make_list [ M.get_name (| globals, "substring" |); - M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) + M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) ], make_dict [] |) @@ -1212,58 +797,10 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.break (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let prefix := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):BinOp.add (| - M.get_name (| globals, "level" |), - M.get_name (| globals, "prefix_length" |) - |) |) in - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "ExtensionNode" |), - make_list [ - M.get_name (| globals, "prefix" |); - M.call (| - M.get_name (| globals, "encode_internal_node" |), - make_list [ - M.call (| - M.get_name (| globals, "patricialize" |), - make_list [ - M.get_name (| globals, "obj" |); - BinOp.add (| - M.get_name (| globals, "level" |), - M.get_name (| globals, "prefix_length" |) - |) - ], - make_dict [] - |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) @@ -1283,44 +820,9 @@ Definition patricialize : Value.t -> Value.t -> M := |) in EndFor. let value := - (* At constant: unsupported node type: Constant *) in + Constant.bytes "" in For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "key" |) - ], - make_dict [] - |), M.get_name (| globals, "level" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); - make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "AssertionError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let value := - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) @@ -1332,26 +834,9 @@ Definition patricialize : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "BranchNode" |), make_list [ - [M.call (| - M.get_name (| globals, "encode_internal_node" |), - make_list [ - M.call (| - M.get_name (| globals, "patricialize" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "branches" |), M.get_name (| globals, "k" |) |); - BinOp.add (| - M.get_name (| globals, "level" |), - Constant.int 1 - |) - ], - make_dict [] - |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)]; + (* At expr: unsupported node type: ListComp *); M.get_name (| globals, "value" |) ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/utils/address.v b/CoqOfPython/ethereum/byzantium/utils/address.v index ad3e93e..61cf3b1 100644 --- a/CoqOfPython/ethereum/byzantium/utils/address.v +++ b/CoqOfPython/ethereum/byzantium/utils/address.v @@ -68,11 +68,10 @@ Definition to_address : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), make_list [], make_dict [] - |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) + |), UnOp.sub (| Constant.int 20 |) |) ], make_dict [] |) - |) in M.pure Constant.None_)). Definition compute_contract_address : Value.t -> Value.t -> M := @@ -112,7 +111,7 @@ Definition compute_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -130,5 +129,4 @@ Definition compute_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/utils/hexadecimal.v b/CoqOfPython/ethereum/byzantium/utils/hexadecimal.v index 8e6273d..1c28bf7 100644 --- a/CoqOfPython/ethereum/byzantium/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/byzantium/utils/hexadecimal.v @@ -66,7 +66,6 @@ Definition hex_to_root : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition hex_to_bloom : Value.t -> Value.t -> M := @@ -105,7 +104,6 @@ Definition hex_to_bloom : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition hex_to_address : Value.t -> Value.t -> M := @@ -151,5 +149,4 @@ Definition hex_to_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/utils/message.v b/CoqOfPython/ethereum/byzantium/utils/message.v index 092862d..b9ae2bb 100644 --- a/CoqOfPython/ethereum/byzantium/utils/message.v +++ b/CoqOfPython/ethereum/byzantium/utils/message.v @@ -88,105 +88,14 @@ Definition prepare_message : Value.t -> Value.t -> M := Items containing contract creation or message call specific data. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "target" |); - M.get_name (| globals, "Bytes0" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let current_target := - M.call (| - M.get_name (| globals, "compute_contract_address" |), - make_list [ - M.get_name (| globals, "caller" |); - BinOp.sub (| - M.get_field (| M.call (| - M.get_name (| globals, "get_account" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "caller" |) - ], - make_dict [] - |), "nonce" |), - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 1 - ], - make_dict [] - |) - |) - ], - make_dict [] - |) in - let msg_data := - M.call (| - M.get_name (| globals, "Bytes" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |) in - let code := - M.get_name (| globals, "data" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "target" |); - M.get_name (| globals, "Address" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let current_target := - M.get_name (| globals, "target" |) in - let msg_data := - M.get_name (| globals, "data" |) in - let code := - M.get_field (| M.call (| - M.get_name (| globals, "get_account" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "target" |) - ], - make_dict [] - |), "code" |) in - let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "code_address" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let code_address := - M.get_name (| globals, "target" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.call (| + let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "Target must be address or empty bytes" ], make_dict [] - |) |) in + |)) M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -197,5 +106,4 @@ Definition prepare_message : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/vm/__init__.v b/CoqOfPython/ethereum/byzantium/vm/__init__.v index 520603e..8859cb4 100644 --- a/CoqOfPython/ethereum/byzantium/vm/__init__.v +++ b/CoqOfPython/ethereum/byzantium/vm/__init__.v @@ -143,28 +143,6 @@ Definition incorporate_child_on_success : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); - M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -183,57 +161,9 @@ Definition incorporate_child_on_error : Value.t -> Value.t -> M := The child evm to incorporate. " in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "RIPEMD160_ADDRESS" |), M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), - make_list [ - M.get_name (| globals, "RIPEMD160_ADDRESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |), M.get_name (| globals, "RIPEMD160_ADDRESS" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); - M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), - make_list [ - M.get_name (| globals, "RIPEMD160_ADDRESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign_op (| diff --git a/CoqOfPython/ethereum/byzantium/vm/gas.v b/CoqOfPython/ethereum/byzantium/vm/gas.v new file mode 100644 index 0000000..91436db --- /dev/null +++ b/CoqOfPython/ethereum/byzantium/vm/gas.v @@ -0,0 +1,811 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Gas +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +EVM gas constants and calculators. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.trace. +Axiom ethereum_trace_GasAndRefund : + IsGlobalAlias globals ethereum.trace.globals "GasAndRefund". +Axiom ethereum_trace_evm_trace : + IsGlobalAlias globals ethereum.trace.globals "evm_trace". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". + +Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) +)). + +Definition GAS_BASE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 2 + ], + make_dict [] + |) +)). + +Definition GAS_VERY_LOW : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_SLOAD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 200 + ], + make_dict [] + |) +)). + +Definition GAS_STORAGE_SET : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 20000 + ], + make_dict [] + |) +)). + +Definition GAS_STORAGE_UPDATE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5000 + ], + make_dict [] + |) +)). + +Definition GAS_STORAGE_CLEAR_REFUND : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 15000 + ], + make_dict [] + |) +)). + +Definition GAS_LOW : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5 + ], + make_dict [] + |) +)). + +Definition GAS_MID : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 8 + ], + make_dict [] + |) +)). + +Definition GAS_HIGH : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 10 + ], + make_dict [] + |) +)). + +Definition GAS_EXPONENTIATION : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 10 + ], + make_dict [] + |) +)). + +Definition GAS_EXPONENTIATION_PER_BYTE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 50 + ], + make_dict [] + |) +)). + +Definition GAS_MEMORY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_KECCAK256 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 30 + ], + make_dict [] + |) +)). + +Definition GAS_KECCAK256_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 6 + ], + make_dict [] + |) +)). + +Definition GAS_COPY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_BLOCK_HASH : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 20 + ], + make_dict [] + |) +)). + +Definition GAS_EXTERNAL : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 700 + ], + make_dict [] + |) +)). + +Definition GAS_BALANCE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 400 + ], + make_dict [] + |) +)). + +Definition GAS_LOG : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 375 + ], + make_dict [] + |) +)). + +Definition GAS_LOG_DATA : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 8 + ], + make_dict [] + |) +)). + +Definition GAS_LOG_TOPIC : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 375 + ], + make_dict [] + |) +)). + +Definition GAS_CREATE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 32000 + ], + make_dict [] + |) +)). + +Definition GAS_CODE_DEPOSIT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 200 + ], + make_dict [] + |) +)). + +Definition GAS_ZERO : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) +)). + +Definition GAS_CALL : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 700 + ], + make_dict [] + |) +)). + +Definition GAS_NEW_ACCOUNT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 25000 + ], + make_dict [] + |) +)). + +Definition GAS_CALL_VALUE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 9000 + ], + make_dict [] + |) +)). + +Definition GAS_CALL_STIPEND : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 2300 + ], + make_dict [] + |) +)). + +Definition GAS_SELF_DESTRUCT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5000 + ], + make_dict [] + |) +)). + +Definition GAS_SELF_DESTRUCT_NEW_ACCOUNT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 25000 + ], + make_dict [] + |) +)). + +Definition REFUND_SELF_DESTRUCT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 24000 + ], + make_dict [] + |) +)). + +Definition GAS_ECRECOVER : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3000 + ], + make_dict [] + |) +)). + +Definition GAS_SHA256 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 60 + ], + make_dict [] + |) +)). + +Definition GAS_SHA256_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 12 + ], + make_dict [] + |) +)). + +Definition GAS_RIPEMD160 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 600 + ], + make_dict [] + |) +)). + +Definition GAS_RIPEMD160_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 120 + ], + make_dict [] + |) +)). + +Definition GAS_IDENTITY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 15 + ], + make_dict [] + |) +)). + +Definition GAS_IDENTITY_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_RETURN_DATA_COPY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition ExtendMemory : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition MessageCallGas : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition charge_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "amount" ] |) in + let _ := Constant.str " + Subtracts `amount` from `evm.gas_left`. + + Parameters + ---------- + evm : + The current EVM. + amount : + The amount of gas the current operation requires. + + " in + let _ := M.call (| + M.get_name (| globals, "evm_trace" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "GasAndRefund" |), + make_list [ + M.get_name (| globals, "amount" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + let _ := M.assign_op (| + BinOp.sub, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "amount" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition calculate_memory_gas_cost : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "size_in_bytes" ] |) in + let _ := Constant.str " + Calculates the gas cost for allocating memory + to the smallest multiple of 32 bytes, + such that the allocated size is at least as big as the given size. + + Parameters + ---------- + size_in_bytes : + The size of the data in bytes. + + Returns + ------- + total_gas_cost : `ethereum.base_types.Uint` + The gas cost for storing data in memory. + " in + let size_in_words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "size_in_bytes" |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let linear_cost := + BinOp.mult (| + M.get_name (| globals, "size_in_words" |), + M.get_name (| globals, "GAS_MEMORY" |) + |) in + let quadratic_cost := + BinOp.floor_div (| + BinOp.pow (| + M.get_name (| globals, "size_in_words" |), + Constant.int 2 + |), + Constant.int 512 + |) in + let total_gas_cost := + BinOp.add (| + M.get_name (| globals, "linear_cost" |), + M.get_name (| globals, "quadratic_cost" |) + |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_)). + +Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "memory"; "extensions" ] |) in + let _ := Constant.str " + Calculates the gas amount to extend memory + + Parameters + ---------- + memory : + Memory contents of the EVM. + extensions: + List of extensions to be made to the memory. + Consists of a tuple of start position and size. + + Returns + ------- + extend_memory: `ExtendMemory` + " in + let size_to_extend := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let to_be_paid := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let current_size := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "memory" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + For make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ] in M.get_name (| globals, "extensions" |) do + let _ := + M.pure Constant.None_ + )) |) in + let before_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "current_size" |) + ], + make_dict [] + |) in + let after_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let size_to_extend := BinOp.add + BinOp.sub (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |) + BinOp.sub (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |) in + let already_paid := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "before_size" |) + ], + make_dict [] + |) in + let total_cost := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "after_size" |) + ], + make_dict [] + |) in + let to_be_paid := BinOp.add + BinOp.sub (| + M.get_name (| globals, "total_cost" |), + M.get_name (| globals, "already_paid" |) + |) + BinOp.sub (| + M.get_name (| globals, "total_cost" |), + M.get_name (| globals, "already_paid" |) + |) in + let current_size := + M.get_name (| globals, "after_size" |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ExtendMemory" |), + make_list [ + M.get_name (| globals, "to_be_paid" |); + M.get_name (| globals, "size_to_extend" |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition calculate_message_call_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "value"; "gas"; "gas_left"; "memory_cost"; "extra_gas"; "call_stipend" ] |) in + let _ := Constant.str " + Calculates the MessageCallGas (cost and stipend) for + executing call Opcodes. + + Parameters + ---------- + value: + The amount of `ETH` that needs to be transferred. + gas : + The amount of gas provided to the message-call. + gas_left : + The amount of gas left in the current frame. + memory_cost : + The amount needed to extend the memory in the current frame. + extra_gas : + The amount of gas needed for transferring value + creating a new + account inside a message call. + call_stipend : + The amount of stipend provided to a message call to execute code while + transferring value(ETH). + + Returns + ------- + message_call_gas: `MessageCallGas` + " in + let call_stipend := + (* if *) +M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let gas := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "max_message_call_gas" |), + make_list [ + BinOp.sub (| + BinOp.sub (| + M.get_name (| globals, "gas_left" |), + M.get_name (| globals, "memory_cost" |) + |), + M.get_name (| globals, "extra_gas" |) + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallGas" |), + make_list [ + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "extra_gas" |) + |); + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "call_stipend" |) + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition max_message_call_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "gas" ] |) in + let _ := Constant.str " + Calculates the maximum gas that is allowed for making a message call + + Parameters + ---------- + gas : + The amount of gas provided to the message-call. + + Returns + ------- + max_allowed_message_call_gas: `ethereum.base_types.Uint` + The maximum gas allowed for making the message-call. + " in + let _ := M.return_ (| + BinOp.sub (| + M.get_name (| globals, "gas" |), + BinOp.floor_div (| + M.get_name (| globals, "gas" |), + Constant.int 64 + |) + |) + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/byzantium/vm/instructions/arithmetic.v index a8b5c61..581ba5d 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/arithmetic.v @@ -273,22 +273,6 @@ Definition div : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let quotient := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let quotient := BinOp.floor_div (| M.get_name (| globals, "dividend" |), @@ -357,32 +341,7 @@ Definition sdiv : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let quotient := - Constant.int 0 in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_name (| globals, "dividend" |), UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "divisor" |), UnOp.sub (| Constant.int 1 |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let quotient := - UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let sign := M.call (| M.get_name (| globals, "get_sign" |), @@ -477,22 +436,6 @@ Definition mod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let remainder := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let remainder := BinOp.mod_ (| M.get_name (| globals, "x" |), @@ -561,16 +504,6 @@ Definition smod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let remainder := - Constant.int 0 in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let remainder := BinOp.mult (| M.call (| @@ -684,22 +617,6 @@ Definition addmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -795,22 +712,6 @@ Definition mulmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -980,16 +881,6 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "byte_num" |), Constant.int 31 |), - (* then *) - ltac:(M.monadic ( - let result := - M.get_name (| globals, "value" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let value_bytes := M.call (| M.get_name (| globals, "bytes" |), @@ -1012,29 +903,13 @@ Definition signextend : Value.t -> Value.t -> M := ], make_dict [] |) - |):(* At expr: unsupported node type: NoneType *) |) in + |) |) in let sign_bit := BinOp.r_shift (| M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), Constant.int 7 |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "sign_bit" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), - make_list [ - M.get_name (| globals, "value_bytes" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let num_bytes_prepend := BinOp.sub (| Constant.int 32, diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/bitwise.v b/CoqOfPython/ethereum/byzantium/vm/instructions/bitwise.v index b20a1e5..f38e7aa 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/bitwise.v @@ -285,22 +285,6 @@ Definition get_byte : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "byte_index" |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let extra_bytes_to_right := BinOp.sub (| Constant.int 31, diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/block.v b/CoqOfPython/ethereum/byzantium/vm/instructions/block.v index e5fa554..90be45c 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/block.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/block.v @@ -69,24 +69,6 @@ Definition block_hash : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.lt_e (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), M.get_name (| globals, "block_number" |) |), - ltac:(M.monadic ( - Compare.gt (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), BinOp.add (| - M.get_name (| globals, "block_number" |), - Constant.int 256 - |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let hash := - (* At constant: unsupported node type: Constant *) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let hash := M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/comparison.v b/CoqOfPython/ethereum/byzantium/vm/instructions/comparison.v index fbc35f8..b8529d8 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/comparison.v @@ -78,7 +78,10 @@ Definition less_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.lt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -145,7 +148,10 @@ Definition signed_less_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.lt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -205,7 +211,10 @@ Definition greater_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.gt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -272,7 +281,10 @@ Definition signed_greater_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.gt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -332,7 +344,10 @@ Definition equal : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.eq (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.eq (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -384,7 +399,10 @@ Definition is_zero : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.eq (| M.get_name (| globals, "x" |), Constant.int 0 |) + Compare.eq (| + M.get_name (| globals, "x" |), + Constant.int 0 + |) ], make_dict [] |) in diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/control_flow.v b/CoqOfPython/ethereum/byzantium/vm/instructions/control_flow.v index 04a79d9..d4e4eae 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/control_flow.v @@ -109,15 +109,6 @@ Definition jump : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -177,29 +168,7 @@ Definition jumpi : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "conditional_value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let destination := - BinOp.add (| - M.get_field (| M.get_name (| globals, "evm" |), "pc" |), - Constant.int 1 - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let destination := M.get_name (| globals, "jump_dest" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/environment.v b/CoqOfPython/ethereum/byzantium/vm/instructions/environment.v index 2929b1e..78c9e52 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/environment.v @@ -502,7 +502,7 @@ Definition calldatacopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -670,7 +670,7 @@ Definition codecopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -913,7 +913,7 @@ Definition extcodecopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -1084,28 +1084,31 @@ Definition returndatacopy : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt_e (| BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "return_data_start_position" |) - ], - make_dict [] + Compare.lt_e (| + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "return_data_start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) |), M.call (| - M.get_name (| globals, "Uint" |), + M.get_name (| globals, "len" |), make_list [ - M.get_name (| globals, "size" |) + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |) ], make_dict [] |) - |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "return_data" |) - ], - make_dict [] - |) |); + |); M.get_name (| globals, "OutOfBoundsRead" |) ], make_dict [] @@ -1114,15 +1117,12 @@ Definition returndatacopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in let value := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |):BinOp.add (| - M.get_name (| globals, "return_data_start_position" |), - M.get_name (| globals, "size" |) - |) |) in + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |) |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/keccak.v b/CoqOfPython/ethereum/byzantium/vm/instructions/keccak.v index cab9ffb..2c4b10e 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/keccak.v @@ -137,7 +137,7 @@ Definition keccak : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/log.v b/CoqOfPython/ethereum/byzantium/vm/instructions/log.v index 4891a4d..e084e59 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/log.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/log.v @@ -161,7 +161,7 @@ Definition log_n : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/memory.v b/CoqOfPython/ethereum/byzantium/vm/instructions/memory.v index 1e1c8b0..86ba742 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/memory.v @@ -121,7 +121,7 @@ Definition mstore : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -203,7 +203,7 @@ Definition mstore8 : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -288,7 +288,7 @@ Definition mload : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/stack.v b/CoqOfPython/ethereum/byzantium/vm/instructions/stack.v index 1eeda05..305af15 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/stack.v @@ -188,13 +188,16 @@ Definition dup_n : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] - |) |); + Compare.lt (| + M.get_name (| globals, "item_number" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + |); M.get_name (| globals, "StackUnderflowError" |) ], make_dict [] @@ -260,13 +263,16 @@ Definition swap_n : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] - |) |); + Compare.lt (| + M.get_name (| globals, "item_number" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + |); M.get_name (| globals, "StackUnderflowError" |) ], make_dict [] diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/storage.v b/CoqOfPython/ethereum/byzantium/vm/instructions/storage.v index 29ef235..fe33724 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/storage.v @@ -154,44 +154,11 @@ Definition sstore : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "new_value" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let gas_cost := - M.get_name (| globals, "GAS_STORAGE_SET" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let gas_cost := M.get_name (| globals, "GAS_STORAGE_UPDATE" |) in M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_name (| globals, "new_value" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), - M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/system.v b/CoqOfPython/ethereum/byzantium/vm/instructions/system.v new file mode 100644 index 0000000..013dec0 --- /dev/null +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/system.v @@ -0,0 +1,1432 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) System Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM system related instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_account_exists_and_is_empty : + IsGlobalAlias globals state.globals "account_exists_and_is_empty". +Axiom state_account_has_code_or_nonce : + IsGlobalAlias globals state.globals "account_has_code_or_nonce". +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". +Axiom state_increment_nonce : + IsGlobalAlias globals state.globals "increment_nonce". +Axiom state_is_account_alive : + IsGlobalAlias globals state.globals "is_account_alive". +Axiom state_set_account_balance : + IsGlobalAlias globals state.globals "set_account_balance". + +Require utils.address. +Axiom utils_address_compute_contract_address : + IsGlobalAlias globals utils.address.globals "compute_contract_address". +Axiom utils_address_to_address : + IsGlobalAlias globals utils.address.globals "to_address". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". +Axiom __init___Message : + IsGlobalAlias globals __init__.globals "Message". +Axiom __init___incorporate_child_on_error : + IsGlobalAlias globals __init__.globals "incorporate_child_on_error". +Axiom __init___incorporate_child_on_success : + IsGlobalAlias globals __init__.globals "incorporate_child_on_success". + +Require exceptions. +Axiom exceptions_Revert : + IsGlobalAlias globals exceptions.globals "Revert". +Axiom exceptions_WriteInStaticContext : + IsGlobalAlias globals exceptions.globals "WriteInStaticContext". + +Require gas. +Axiom gas_GAS_CALL : + IsGlobalAlias globals gas.globals "GAS_CALL". +Axiom gas_GAS_CALL_VALUE : + IsGlobalAlias globals gas.globals "GAS_CALL_VALUE". +Axiom gas_GAS_CREATE : + IsGlobalAlias globals gas.globals "GAS_CREATE". +Axiom gas_GAS_NEW_ACCOUNT : + IsGlobalAlias globals gas.globals "GAS_NEW_ACCOUNT". +Axiom gas_GAS_SELF_DESTRUCT : + IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT". +Axiom gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : + IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". +Axiom gas_GAS_ZERO : + IsGlobalAlias globals gas.globals "GAS_ZERO". +Axiom gas_REFUND_SELF_DESTRUCT : + IsGlobalAlias globals gas.globals "REFUND_SELF_DESTRUCT". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_calculate_message_call_gas : + IsGlobalAlias globals gas.globals "calculate_message_call_gas". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". +Axiom gas_max_message_call_gas : + IsGlobalAlias globals gas.globals "max_message_call_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". +Axiom memory_memory_write : + IsGlobalAlias globals memory.globals "memory_write". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition create : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Creates a new account with associated code. + + Parameters + ---------- + evm : + The current EVM frame. + " in +(* At stmt: unsupported node type: ImportFrom *) + let endowment := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_position" |); M.get_name (| globals, "memory_size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_CREATE" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let create_message_gas := + M.call (| + M.get_name (| globals, "max_message_call_gas" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.sub, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "create_message_gas" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let sender_address := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in + let sender := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "sender_address" |) + ], + make_dict [] + |) in + let contract_address := + M.call (| + M.get_name (| globals, "compute_contract_address" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "nonce" |) + ], + make_dict [] + |) in + let _ := + let _ := + let call_data := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + let child_message := + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) in + let child_evm := + M.call (| + M.get_name (| globals, "process_create_message" |), + make_list [ + M.get_name (| globals, "child_message" |); + M.get_field (| M.get_name (| globals, "evm" |), "env" |) + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_success" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition return_ : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Halts execution returning output data. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let memory_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_position" |); M.get_name (| globals, "memory_size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_ZERO" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "running" |), + Constant.bool false + |) in + let _ := M.pass (| |) in + M.pure Constant.None_)). + +Definition generic_call : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "gas"; "value"; "caller"; "to"; "code_address"; "should_transfer_value"; "is_staticcall"; "memory_input_start_position"; "memory_input_size"; "memory_output_start_position"; "memory_output_size" ] |) in + let _ := Constant.str " + Perform the core logic of the `CALL*` family of opcodes. + " in +(* At stmt: unsupported node type: ImportFrom *) + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let _ := + M.pure Constant.None_ + )) |) in + let call_data := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |) + ], + make_dict [] + |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "code_address" |) + ], + make_dict [] + |), "code" |) in + let child_message := + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) in + let child_evm := + M.call (| + M.get_name (| globals, "process_message" |), + make_list [ + M.get_name (| globals, "child_message" |); + M.get_field (| M.get_name (| globals, "evm" |), "env" |) + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_success" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let actual_output_size := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_name (| globals, "memory_output_size" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), Constant.None_:M.get_name (| globals, "actual_output_size" |) |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition call : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into an account. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let to := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let create_gas_cost := + (* if *) +M.if_then_else (| + BoolOp.or (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "is_account_alive" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "to" |) + ], + make_dict [] + |) + )) + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let transfer_gas_cost := + (* if *) +M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_CALL" |), + M.get_name (| globals, "create_gas_cost" |) + |), + M.get_name (| globals, "transfer_gas_cost" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.or (| + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "value" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) + )) + |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let sender_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.get_name (| globals, "value" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "to" |); + Constant.bool true; + Constant.bool false; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition callcode : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into this account with alternative account’s code. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let code_address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let to := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let transfer_gas_cost := + (* if *) +M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + BinOp.add (| + M.get_name (| globals, "GAS_CALL" |), + M.get_name (| globals, "transfer_gas_cost" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let sender_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.get_name (| globals, "value" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "code_address" |); + Constant.bool true; + Constant.bool false; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition selfdestruct : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Halt execution and register account for later deletion. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let beneficiary := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let gas_cost := + M.get_name (| globals, "GAS_SELF_DESTRUCT" |) in + let _ := + M.pure Constant.None_ + )) |) in + let originator := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in + let refunded_accounts := + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in + let parent_evm := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "parent_evm" |) in + While Compare.is_not (| + M.get_name (| globals, "parent_evm" |), + Constant.None_ + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "refunded_accounts" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "parent_evm" |), "accounts_to_delete" |) + ], + make_dict [] + |) in + let parent_evm := + M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in + EndWhile. + let _ := + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "gas_cost" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let beneficiary_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |), "balance" |) in + let originator_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "originator" |) + ], + make_dict [] + |), "balance" |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |); + BinOp.add (| + M.get_name (| globals, "beneficiary_balance" |), + M.get_name (| globals, "originator_balance" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "originator" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |), "add" |), + make_list [ + M.get_name (| globals, "originator" |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "running" |), + Constant.bool false + |) in + let _ := M.pass (| |) in + M.pure Constant.None_)). + +Definition delegatecall : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into an account. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let code_address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + M.get_name (| globals, "GAS_CALL" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "value" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "caller" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "code_address" |); + Constant.bool false; + Constant.bool false; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition staticcall : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into an account. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let to := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + M.get_name (| globals, "GAS_CALL" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "to" |); + Constant.bool true; + Constant.bool true; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition revert : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stop execution and revert state changes, without consuming all provided gas + and also has the ability to return a reason + Parameters + ---------- + evm : + The current EVM frame. + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let output := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "bytes" |), + make_list [ + M.get_name (| globals, "output" |) + ], + make_dict [] + |) + |) in + let _ := M.raise (| Some(M.get_name (| globals, "Revert" |)) + let _ := M.pass (| |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/vm/interpreter.v b/CoqOfPython/ethereum/byzantium/vm/interpreter.v index c9f61e0..252f4e7 100644 --- a/CoqOfPython/ethereum/byzantium/vm/interpreter.v +++ b/CoqOfPython/ethereum/byzantium/vm/interpreter.v @@ -180,91 +180,6 @@ Definition process_message_call : Value.t -> Value.t -> M := Output of the message call " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_name (| globals, "message" |), "target" |), M.call (| - M.get_name (| globals, "Bytes0" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let is_collision := - M.call (| - M.get_name (| globals, "account_has_code_or_nonce" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_field (| M.get_name (| globals, "message" |), "current_target" |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - M.get_name (| globals, "is_collision" |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "MessageCallOutput" |), - make_list [ - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |); - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |); - M.call (| - M.get_name (| globals, "tuple" |), - make_list [], - make_dict [] - |); - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |); - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |); - M.call (| - M.get_name (| globals, "AddressCollision" |), - make_list [], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let evm := - M.call (| - M.get_name (| globals, "process_create_message" |), - make_list [ - M.get_name (| globals, "message" |); - M.get_name (| globals, "env" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let evm := M.call (| M.get_name (| globals, "process_message" |), @@ -275,74 +190,11 @@ Definition process_message_call : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_field (| M.get_name (| globals, "message" |), "target" |) - ], - make_dict [] - |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), - make_list [ - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_field (| M.get_name (| globals, "message" |), "target" |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "evm" |), "error" |), - (* then *) - ltac:(M.monadic ( -(* At stmt: unsupported node type: AnnAssign *) - let accounts_to_delete := - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |) in - let touched_accounts := - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |) in - let refund_counter := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let logs := M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in let accounts_to_delete := @@ -380,7 +232,6 @@ Definition process_message_call : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). Definition process_create_message : Value.t -> Value.t -> M := @@ -434,28 +285,6 @@ Definition process_create_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), - (* then *) - ltac:(M.monadic ( - let contract_code := - M.get_field (| M.get_name (| globals, "evm" |), "output" |) in - let contract_code_gas := - BinOp.mult (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "contract_code" |) - ], - make_dict [] - |), - M.get_name (| globals, "GAS_CODE_DEPOSIT" |) - |) in -(* At stmt: unsupported node type: Try *) - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "rollback_transaction" |), make_list [ @@ -467,7 +296,6 @@ Definition process_create_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) - |) in M.pure Constant.None_)). Definition process_message : Value.t -> Value.t -> M := @@ -489,21 +317,6 @@ Definition process_message : Value.t -> Value.t -> M := Items containing execution specific objects " in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_field (| M.get_name (| globals, "message" |), "depth" |), M.get_name (| globals, "STACK_DEPTH_LIMIT" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "StackDepthLimitError" |), - make_list [ - Constant.str "Stack depth limit reached" - ], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -522,29 +335,6 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - M.get_field (| M.get_name (| globals, "message" |), "should_transfer_value" |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_field (| M.get_name (| globals, "message" |), "value" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "move_ether" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_field (| M.get_name (| globals, "message" |), "caller" |); - M.get_field (| M.get_name (| globals, "message" |), "current_target" |); - M.get_field (| M.get_name (| globals, "message" |), "value" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let evm := @@ -557,21 +347,6 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "evm" |), "error" |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "rollback_transaction" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "commit_transaction" |), make_list [ @@ -583,7 +358,6 @@ Definition process_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) - |) in M.pure Constant.None_)). Definition execute_code : Value.t -> Value.t -> M := @@ -623,5 +397,4 @@ Definition execute_code : Value.t -> Value.t -> M := (* At stmt: unsupported node type: Try *) let _ := M.return_ (| M.get_name (| globals, "evm" |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/vm/memory.v b/CoqOfPython/ethereum/byzantium/vm/memory.v index fa8d906..4b107fd 100644 --- a/CoqOfPython/ethereum/byzantium/vm/memory.v +++ b/CoqOfPython/ethereum/byzantium/vm/memory.v @@ -45,22 +45,7 @@ Definition memory_write : Value.t -> Value.t -> M := Data to write to memory. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) - |) |), + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_)). @@ -86,23 +71,7 @@ Definition memory_read_bytes : Value.t -> Value.t -> M := Data read from memory. " in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |) - |) in + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |) M.pure Constant.None_)). Definition buffer_read : Value.t -> Value.t -> M := @@ -129,25 +98,9 @@ Definition buffer_read : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "right_pad_zero_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |); + M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |) |); M.get_name (| globals, "size" |) ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/alt_bn128.v index 0823afa..90f245d 100644 --- a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/alt_bn128.v +++ b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/alt_bn128.v @@ -210,15 +210,6 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) in For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ] do let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "i" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -362,15 +353,6 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) in For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ] do let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "i" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -443,24 +425,6 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_eq (| BinOp.mod_ (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "data" |) - ], - make_dict [] - |), - Constant.int 192 - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let result := @@ -509,32 +473,11 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := Constant.int 32, M.get_name (| globals, "j" |) |) - |):BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "i" |), - Constant.int 192 - |), - BinOp.mult (| - Constant.int 32, - BinOp.add (| - M.get_name (| globals, "j" |), - Constant.int 1 - |) - |) |) |) ], make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "value" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -555,17 +498,20 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.call (| - M.get_field (| M.get_name (| globals, "p" |), "mul_by" |), - make_list [ - M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) - ], - make_dict [] - |), M.call (| - M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) |); + Compare.eq (| + M.call (| + M.get_field (| M.get_name (| globals, "p" |), "mul_by" |), + make_list [ + M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) + ], + make_dict [] + |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |); M.get_name (| globals, "OutOfGasError" |) ], make_dict [] @@ -573,87 +519,29 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.call (| - M.get_field (| M.get_name (| globals, "q" |), "mul_by" |), - make_list [ - M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) - ], - make_dict [] - |), M.call (| - M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) |); + Compare.eq (| + M.call (| + M.get_field (| M.get_name (| globals, "q" |), "mul_by" |), + make_list [ + M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) + ], + make_dict [] + |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |); M.get_name (| globals, "OutOfGasError" |) ], make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "p" |), M.call (| - M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_name (| globals, "q" |), M.call (| - M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let result := - BinOp.mult (| - M.get_name (| globals, "result" |), - M.call (| - M.get_name (| globals, "pairing" |), - make_list [ - M.get_name (| globals, "q" |); - M.get_name (| globals, "p" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "result" |), M.call (| - M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), - make_list [ - Constant.int 1 - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign (| - M.get_field (| M.get_name (| globals, "evm" |), "output" |), - M.call (| - M.get_field (| M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 1 - ], - make_dict [] - |), "to_be_bytes32" |), - make_list [], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| diff --git a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/ecrecover.v index cc351b5..0cbcf16 100644 --- a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/ecrecover.v @@ -188,60 +188,12 @@ Definition ecrecover : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 27 |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 28 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| Constant.int 0, M.get_name (| globals, "r" |) |), - ltac:(M.monadic ( - Compare.gt_e (| M.get_name (| globals, "r" |), M.get_name (| globals, "SECP256K1N" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| Constant.int 0, M.get_name (| globals, "s" |) |), - ltac:(M.monadic ( - Compare.gt_e (| M.get_name (| globals, "s" |), M.get_name (| globals, "SECP256K1N" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: Try *) @@ -252,7 +204,7 @@ Definition ecrecover : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12:Constant.int 32 |) in + |), Constant.int 12 |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/modexp.v index 39ce4f9..aff5b85 100644 --- a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/modexp.v +++ b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/modexp.v @@ -181,36 +181,6 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "exp_length" |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let adjusted_exp_length := - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.call (| - M.get_name (| globals, "max" |), - make_list [ - Constant.int 0; - BinOp.sub (| - M.call (| - M.get_field (| M.get_name (| globals, "exp_head" |), "bit_length" |), - make_list [], - make_dict [] - |), - Constant.int 1 - |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let adjusted_exp_length := M.call (| M.get_name (| globals, "Uint" |), @@ -297,30 +267,6 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_name (| globals, "base_length" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "modulus_length" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign (| - M.get_field (| M.get_name (| globals, "evm" |), "output" |), - M.call (| - M.get_name (| globals, "Bytes" |), - make_list [], - make_dict [] - |) - |) in - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let base := @@ -383,27 +329,6 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "modulus" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign (| - M.get_field (| M.get_name (| globals, "evm" |), "output" |), - BinOp.mult (| - M.call (| - M.get_name (| globals, "Bytes" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |), - M.get_name (| globals, "modulus_length" |) - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| @@ -440,47 +365,7 @@ Definition get_mult_complexity : Value.t -> Value.t -> M := Estimate the complexity of performing Karatsuba multiplication. " in let _ := - (* if *) - M.if_then_else (| - Compare.lt_e (| M.get_name (| globals, "x" |), Constant.int 64 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - BinOp.pow (| - M.get_name (| globals, "x" |), - Constant.int 2 - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - Compare.lt_e (| M.get_name (| globals, "x" |), Constant.int 1024 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - BinOp.sub (| - BinOp.add (| - BinOp.floor_div (| - BinOp.pow (| - M.get_name (| globals, "x" |), - Constant.int 2 - |), - Constant.int 4 - |), - BinOp.mult (| - Constant.int 96, - M.get_name (| globals, "x" |) - |) - |), - Constant.int 3072 - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| BinOp.sub (| BinOp.add (| @@ -498,7 +383,6 @@ Definition get_mult_complexity : Value.t -> Value.t -> M := |), Constant.int 199680 |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/byzantium/vm/runtime.v b/CoqOfPython/ethereum/byzantium/vm/runtime.v index 835b46c..2cd7652 100644 --- a/CoqOfPython/ethereum/byzantium/vm/runtime.v +++ b/CoqOfPython/ethereum/byzantium/vm/runtime.v @@ -67,50 +67,19 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := ], make_dict [] |) in - While Compare.lt (| M.get_name (| globals, "pc" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "code" |) - ], - make_dict [] - |) |) do + While Compare.lt (| + M.get_name (| globals, "pc" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) + |) do (* At stmt: unsupported node type: Try *) let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "current_opcode" |), M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), - make_list [ - M.get_name (| globals, "pc" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - (* At expr: unsupported node type: Compare *), - (* then *) - ltac:(M.monadic ( - let push_data_size := - BinOp.add (| - BinOp.sub (| - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) - |), - Constant.int 1 - |) in - let pc := BinOp.add - M.get_name (| globals, "push_data_size" |) - M.get_name (| globals, "push_data_size" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -121,5 +90,4 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := EndWhile. let _ := M.return_ (| M.get_name (| globals, "valid_jump_destinations" |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/vm/stack.v b/CoqOfPython/ethereum/byzantium/vm/stack.v index 42ea42d..ea778df 100644 --- a/CoqOfPython/ethereum/byzantium/vm/stack.v +++ b/CoqOfPython/ethereum/byzantium/vm/stack.v @@ -49,21 +49,6 @@ Definition pop : Value.t -> Value.t -> M := " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "stack" |) - ], - make_dict [] - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "StackUnderflowError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -72,7 +57,6 @@ Definition pop : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). Definition push : Value.t -> Value.t -> M := @@ -91,21 +75,6 @@ Definition push : Value.t -> Value.t -> M := " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "stack" |) - ], - make_dict [] - |), Constant.int 1024 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "StackOverflowError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -116,5 +85,4 @@ Definition push : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/bloom.v b/CoqOfPython/ethereum/cancun/bloom.v index 04b5d9f..04650ff 100644 --- a/CoqOfPython/ethereum/cancun/bloom.v +++ b/CoqOfPython/ethereum/cancun/bloom.v @@ -72,10 +72,7 @@ Definition add_to_bloom : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |):BinOp.add (| - M.get_name (| globals, "idx" |), - Constant.int 2 - |) |) + M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |) |) ], make_dict [] |), @@ -160,5 +157,4 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/fork.v b/CoqOfPython/ethereum/cancun/fork.v index 21f0a4f..1611eac 100644 --- a/CoqOfPython/ethereum/cancun/fork.v +++ b/CoqOfPython/ethereum/cancun/fork.v @@ -256,7 +256,7 @@ Definition MAX_BLOB_GAS_PER_BLOCK : Value.t := M.run ltac:(M.monadic ( )). Definition VERSIONED_HASH_VERSION_KZG : Value.t := M.run ltac:(M.monadic ( - (* At constant: unsupported node type: Constant *) + Constant.bytes "01" )). Definition BlockChain : Value.t := @@ -292,7 +292,6 @@ Definition apply_fork : Value.t -> Value.t -> M := " in let _ := M.return_ (| M.get_name (| globals, "old" |) - |) in M.pure Constant.None_)). Definition get_last_256_block_hashes : Value.t -> Value.t -> M := @@ -318,25 +317,8 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := Hashes of the recent 256 blocks in order of increasing block number. " in let recent_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |) |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "recent_blocks" |) - ], - make_dict [] - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - make_list [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let recent_block_hashes := @@ -375,7 +357,6 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "recent_block_hashes" |) - |) in M.pure Constant.None_)). Definition state_transition : Value.t -> Value.t -> M := @@ -415,7 +396,10 @@ Definition state_transition : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "excess_blob_gas" |), M.get_name (| globals, "excess_blob_gas" |) |); + Compare.eq (| + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "excess_blob_gas" |), + M.get_name (| globals, "excess_blob_gas" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -431,7 +415,10 @@ Definition state_transition : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "block" |), "ommers" |), make_tuple [ ] |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "block" |), "ommers" |), + make_tuple [ ] + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -465,7 +452,10 @@ Definition state_transition : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_gas_used" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "gas_used" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_gas_used" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "gas_used" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -473,7 +463,10 @@ Definition state_transition : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "transactions_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "transactions_root" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "transactions_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "transactions_root" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -481,7 +474,10 @@ Definition state_transition : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "state_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "state_root" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "state_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "state_root" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -489,7 +485,10 @@ Definition state_transition : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "receipt_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "receipt_root" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "receipt_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "receipt_root" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -497,7 +496,10 @@ Definition state_transition : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_logs_bloom" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "bloom" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_logs_bloom" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "bloom" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -505,7 +507,10 @@ Definition state_transition : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "withdrawals_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "withdrawals_root" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "withdrawals_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "withdrawals_root" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -513,7 +518,10 @@ Definition state_transition : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "blob_gas_used" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "blob_gas_used" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "blob_gas_used" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "blob_gas_used" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -526,24 +534,6 @@ Definition state_transition : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "chain" |), "blocks" |) - ], - make_dict [] - |), Constant.int 255 |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign (| - M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |):(* At expr: unsupported node type: NoneType *) |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -591,57 +581,7 @@ Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "parent_gas_used" |), M.get_name (| globals, "parent_gas_target" |) |), - (* then *) - ltac:(M.monadic ( - let expected_base_fee_per_gas := - M.get_name (| globals, "parent_base_fee_per_gas" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "parent_gas_used" |), M.get_name (| globals, "parent_gas_target" |) |), - (* then *) - ltac:(M.monadic ( - let gas_used_delta := - BinOp.sub (| - M.get_name (| globals, "parent_gas_used" |), - M.get_name (| globals, "parent_gas_target" |) - |) in - let parent_fee_gas_delta := - BinOp.mult (| - M.get_name (| globals, "parent_base_fee_per_gas" |), - M.get_name (| globals, "gas_used_delta" |) - |) in - let target_fee_gas_delta := - BinOp.floor_div (| - M.get_name (| globals, "parent_fee_gas_delta" |), - M.get_name (| globals, "parent_gas_target" |) - |) in - let base_fee_per_gas_delta := - M.call (| - M.get_name (| globals, "max" |), - make_list [ - BinOp.floor_div (| - M.get_name (| globals, "target_fee_gas_delta" |), - M.get_name (| globals, "BASE_FEE_MAX_CHANGE_DENOMINATOR" |) - |); - Constant.int 1 - ], - make_dict [] - |) in - let expected_base_fee_per_gas := - BinOp.add (| - M.get_name (| globals, "parent_base_fee_per_gas" |), - M.get_name (| globals, "base_fee_per_gas_delta" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let gas_used_delta := BinOp.sub (| M.get_name (| globals, "parent_gas_target" |), @@ -679,7 +619,6 @@ Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition validate_header : Value.t -> Value.t -> M := @@ -705,7 +644,10 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt_e (| M.get_field (| M.get_name (| globals, "header" |), "gas_used" |), M.get_field (| M.get_name (| globals, "header" |), "gas_limit" |) |); + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "header" |), "gas_used" |), + M.get_field (| M.get_name (| globals, "header" |), "gas_limit" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -724,7 +666,10 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_name (| globals, "expected_base_fee_per_gas" |), M.get_field (| M.get_name (| globals, "header" |), "base_fee_per_gas" |) |); + Compare.eq (| + M.get_name (| globals, "expected_base_fee_per_gas" |), + M.get_field (| M.get_name (| globals, "header" |), "base_fee_per_gas" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -732,7 +677,10 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.gt (| M.get_field (| M.get_name (| globals, "header" |), "timestamp" |), M.get_field (| M.get_name (| globals, "parent_header" |), "timestamp" |) |); + Compare.gt (| + M.get_field (| M.get_name (| globals, "header" |), "timestamp" |), + M.get_field (| M.get_name (| globals, "parent_header" |), "timestamp" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -740,10 +688,13 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "number" |), BinOp.add (| - M.get_field (| M.get_name (| globals, "parent_header" |), "number" |), - Constant.int 1 - |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "number" |), + BinOp.add (| + M.get_field (| M.get_name (| globals, "parent_header" |), "number" |), + Constant.int 1 + |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -751,13 +702,16 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt_e (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) - ], - make_dict [] - |), Constant.int 32 |); + Compare.lt_e (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) + ], + make_dict [] + |), + Constant.int 32 + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -765,7 +719,10 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "difficulty" |), Constant.int 0 |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "difficulty" |), + Constant.int 0 + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -773,7 +730,10 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "nonce" |), (* At constant: unsupported node type: Constant *) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "nonce" |), + Constant.bytes "0000000000000000" + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -781,7 +741,10 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "ommers_hash" |), M.get_name (| globals, "EMPTY_OMMER_HASH" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "ommers_hash" |), + M.get_name (| globals, "EMPTY_OMMER_HASH" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -803,7 +766,10 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |), M.get_name (| globals, "block_parent_hash" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |), + M.get_name (| globals, "block_parent_hash" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -846,83 +812,15 @@ Definition check_transaction : Value.t -> Value.t -> M := If the transaction is not includable. " in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.call (| - M.get_name (| globals, "calculate_intrinsic_cost" |), - make_list [ - M.get_name (| globals, "tx" |) - ], - make_dict [] - |), M.get_field (| M.get_name (| globals, "tx" |), "gas" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidBlock" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_field (| M.get_name (| globals, "tx" |), "nonce" |), BinOp.sub (| - BinOp.pow (| - Constant.int 2, - Constant.int 64 - |), - Constant.int 1 - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidBlock" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "tx" |), "to" |), M.call (| - M.get_name (| globals, "Bytes0" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |) |), - ltac:(M.monadic ( - Compare.gt (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "tx" |), "data" |) - ], - make_dict [] - |), BinOp.mult (| - Constant.int 2, - M.get_name (| globals, "MAX_CODE_SIZE" |) - |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidBlock" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_name (| globals, "gas_available" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidBlock" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let sender := @@ -944,77 +842,7 @@ Definition check_transaction : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - make_tuple [ M.get_name (| globals, "FeeMarketTransaction" |); M.get_name (| globals, "BlobTransaction" |) ] - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |), M.get_field (| M.get_name (| globals, "tx" |), "max_priority_fee_per_gas" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidBlock" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |), M.get_name (| globals, "base_fee_per_gas" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidBlock" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let priority_fee_per_gas := - M.call (| - M.get_name (| globals, "min" |), - make_list [ - M.get_field (| M.get_name (| globals, "tx" |), "max_priority_fee_per_gas" |); - BinOp.sub (| - M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |), - M.get_name (| globals, "base_fee_per_gas" |) - |) - ], - make_dict [] - |) in - let effective_gas_price := - BinOp.add (| - M.get_name (| globals, "priority_fee_per_gas" |), - M.get_name (| globals, "base_fee_per_gas" |) - |) in - let max_gas_fee := - BinOp.mult (| - M.get_field (| M.get_name (| globals, "tx" |), "gas" |), - M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |), M.get_name (| globals, "base_fee_per_gas" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidBlock" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let effective_gas_price := @@ -1027,113 +855,6 @@ Definition check_transaction : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "BlobTransaction" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_field (| M.get_name (| globals, "tx" |), "to" |); - M.get_name (| globals, "Address" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidBlock" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "tx" |), "blob_versioned_hashes" |) - ], - make_dict [] - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidBlock" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - For M.get_name (| globals, "blob_versioned_hash" |) in M.get_field (| M.get_name (| globals, "tx" |), "blob_versioned_hashes" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.not_eq (| M.get_subscript (| M.get_name (| globals, "blob_versioned_hash" |), Constant.int 0:Constant.int 1 |), M.get_name (| globals, "VERSIONED_HASH_VERSION_KZG" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidBlock" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - EndFor. - let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_blob_gas" |), M.call (| - M.get_name (| globals, "calculate_blob_gas_price" |), - make_list [ - M.get_name (| globals, "excess_blob_gas" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidBlock" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let max_gas_fee := BinOp.add - BinOp.mult (| - M.call (| - M.get_name (| globals, "calculate_total_blob_gas" |), - make_list [ - M.get_name (| globals, "tx" |) - ], - make_dict [] - |), - M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_blob_gas" |) - |) - BinOp.mult (| - M.call (| - M.get_name (| globals, "calculate_total_blob_gas" |), - make_list [ - M.get_name (| globals, "tx" |) - ], - make_dict [] - |), - M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_blob_gas" |) - |) in - let blob_versioned_hashes := - M.get_field (| M.get_name (| globals, "tx" |), "blob_versioned_hashes" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let blob_versioned_hashes := make_tuple [ ] in M.pure Constant.None_ @@ -1141,7 +862,10 @@ Definition check_transaction : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "sender_account" |), "nonce" |), M.get_field (| M.get_name (| globals, "tx" |), "nonce" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "sender_account" |), "nonce" |), + M.get_field (| M.get_name (| globals, "tx" |), "nonce" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1149,10 +873,13 @@ Definition check_transaction : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.gt_e (| M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), BinOp.add (| - M.get_name (| globals, "max_gas_fee" |), - M.get_field (| M.get_name (| globals, "tx" |), "value" |) - |) |); + Compare.gt_e (| + M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), + BinOp.add (| + M.get_name (| globals, "max_gas_fee" |), + M.get_field (| M.get_name (| globals, "tx" |), "value" |) + |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1160,18 +887,20 @@ Definition check_transaction : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "sender_account" |), "code" |), M.call (| - M.get_name (| globals, "bytearray" |), - make_list [], - make_dict [] - |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "sender_account" |), "code" |), + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [], + make_dict [] + |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] |) in let _ := M.return_ (| make_tuple [ M.get_name (| globals, "sender" |); M.get_name (| globals, "effective_gas_price" |); M.get_name (| globals, "blob_versioned_hashes" |) ] - |) in M.pure Constant.None_)). Definition make_receipt : Value.t -> Value.t -> M := @@ -1204,92 +933,10 @@ Definition make_receipt : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "AccessListTransaction" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - BinOp.add (| - (* At constant: unsupported node type: Constant *), - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "receipt" |) - ], - make_dict [] - |) - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "FeeMarketTransaction" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - BinOp.add (| - (* At constant: unsupported node type: Constant *), - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "receipt" |) - ], - make_dict [] - |) - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "BlobTransaction" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - BinOp.add (| - (* At constant: unsupported node type: Constant *), - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "receipt" |) - ], - make_dict [] - |) - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "receipt" |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -1544,7 +1191,10 @@ Definition apply_body : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt_e (| M.get_name (| globals, "blob_gas_used" |), M.get_name (| globals, "MAX_BLOB_GAS_PER_BLOCK" |) |); + Compare.lt_e (| + M.get_name (| globals, "blob_gas_used" |), + M.get_name (| globals, "MAX_BLOB_GAS_PER_BLOCK" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1605,29 +1255,6 @@ Definition apply_body : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_field (| M.get_name (| globals, "wd" |), "address" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "destroy_account" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_field (| M.get_name (| globals, "wd" |), "address" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -1669,7 +1296,6 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition process_transaction : Value.t -> Value.t -> M := @@ -1713,30 +1339,6 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "BlobTransaction" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let blob_gas_fee := - M.call (| - M.get_name (| globals, "calculate_data_fee" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "excess_blob_gas" |); - M.get_name (| globals, "tx" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let blob_gas_fee := M.call (| M.get_name (| globals, "Uint" |), @@ -1808,39 +1410,6 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - make_tuple [ M.get_name (| globals, "AccessListTransaction" |); M.get_name (| globals, "FeeMarketTransaction" |); M.get_name (| globals, "BlobTransaction" |) ] - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - For make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "keys" |) ] in M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) do - let _ := M.call (| - M.get_field (| M.get_name (| globals, "preaccessed_addresses" |), "add" |), - make_list [ - M.get_name (| globals, "address" |) - ], - make_dict [] - |) in - For M.get_name (| globals, "key" |) in M.get_name (| globals, "keys" |) do - let _ := M.call (| - M.get_field (| M.get_name (| globals, "preaccessed_storage_keys" |), "add" |), - make_list [ - make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "key" |) ] - ], - make_dict [] - |) in - EndFor. - EndFor. - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let message := @@ -1945,47 +1514,7 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "transaction_fee" |) |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_eq (| M.get_name (| globals, "coinbase_balance_after_mining_fee" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "set_account_balance" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_field (| M.get_name (| globals, "env" |), "coinbase" |); - M.get_name (| globals, "coinbase_balance_after_mining_fee" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "destroy_account" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -2010,7 +1539,6 @@ Definition process_transaction : Value.t -> Value.t -> M := |) in let _ := M.return_ (| make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |); M.get_field (| M.get_name (| globals, "output" |), "error" |) ] - |) in M.pure Constant.None_)). Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := @@ -2042,17 +1570,6 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := Constant.int 0 in For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "byte" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let data_cost := BinOp.add - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let data_cost := BinOp.add M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in @@ -2060,49 +1577,6 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := )) |) in EndFor. let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_name (| globals, "tx" |), "to" |), M.call (| - M.get_name (| globals, "Bytes0" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let create_cost := - BinOp.add (| - M.get_name (| globals, "TX_CREATE_COST" |), - M.call (| - M.get_name (| globals, "int" |), - make_list [ - M.call (| - M.get_name (| globals, "init_code_cost" |), - make_list [ - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "tx" |), "data" |) - ], - make_dict [] - |) - ], - make_dict [] - |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let create_cost := Constant.int 0 in M.pure Constant.None_ @@ -2110,47 +1584,6 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := let access_list_cost := Constant.int 0 in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - make_tuple [ M.get_name (| globals, "AccessListTransaction" |); M.get_name (| globals, "FeeMarketTransaction" |); M.get_name (| globals, "BlobTransaction" |) ] - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - For make_tuple [ M.get_name (| globals, "_address" |); M.get_name (| globals, "keys" |) ] in M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) do - let access_list_cost := BinOp.add - M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) - M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) in - let access_list_cost := BinOp.add - BinOp.mult (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "keys" |) - ], - make_dict [] - |), - M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) - |) - BinOp.mult (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "keys" |) - ], - make_dict [] - |), - M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) - |) in - EndFor. - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -2170,7 +1603,6 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition recover_sender : Value.t -> Value.t -> M := @@ -2205,9 +1637,15 @@ Definition recover_sender : Value.t -> Value.t -> M := M.get_name (| globals, "ensure" |), make_list [ BoolOp.and (| - Compare.lt (| Constant.int 0, M.get_name (| globals, "r" |) |), + Compare.lt (| + Constant.int 0, + M.get_name (| globals, "r" |) + |), ltac:(M.monadic ( - Compare.lt (| M.get_name (| globals, "r" |), M.get_name (| globals, "SECP256K1N" |) |) + Compare.lt (| + M.get_name (| globals, "r" |), + M.get_name (| globals, "SECP256K1N" |) + |) )) |); M.get_name (| globals, "InvalidBlock" |) @@ -2218,223 +1656,28 @@ Definition recover_sender : Value.t -> Value.t -> M := M.get_name (| globals, "ensure" |), make_list [ BoolOp.and (| - Compare.lt (| Constant.int 0, M.get_name (| globals, "s" |) |), + Compare.lt (| + Constant.int 0, + M.get_name (| globals, "s" |) + |), ltac:(M.monadic ( - Compare.lt_e (| M.get_name (| globals, "s" |), BinOp.floor_div (| + Compare.lt_e (| + M.get_name (| globals, "s" |), + BinOp.floor_div (| M.get_name (| globals, "SECP256K1N" |), Constant.int 2 - |) |) - )) - |); - M.get_name (| globals, "InvalidBlock" |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "LegacyTransaction" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let v := - M.get_field (| M.get_name (| globals, "tx" |), "v" |) in - let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.eq (| M.get_name (| globals, "v" |), Constant.int 27 |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "v" |), Constant.int 28 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let public_key := - M.call (| - M.get_name (| globals, "secp256k1_recover" |), - make_list [ - M.get_name (| globals, "r" |); - M.get_name (| globals, "s" |); - BinOp.sub (| - M.get_name (| globals, "v" |), - Constant.int 27 - |); - M.call (| - M.get_name (| globals, "signing_hash_pre155" |), - make_list [ - M.get_name (| globals, "tx" |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "ensure" |), - make_list [ - BoolOp.or (| - Compare.eq (| M.get_name (| globals, "v" |), BinOp.add (| - Constant.int 35, - BinOp.mult (| - M.get_name (| globals, "chain_id" |), - Constant.int 2 + |) |) - |) |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "v" |), BinOp.add (| - Constant.int 36, - BinOp.mult (| - M.get_name (| globals, "chain_id" |), - Constant.int 2 - |) - |) |) )) |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] |) in - let public_key := - M.call (| - M.get_name (| globals, "secp256k1_recover" |), - make_list [ - M.get_name (| globals, "r" |); - M.get_name (| globals, "s" |); - BinOp.sub (| - BinOp.sub (| - M.get_name (| globals, "v" |), - Constant.int 35 - |), - BinOp.mult (| - M.get_name (| globals, "chain_id" |), - Constant.int 2 - |) - |); - M.call (| - M.get_name (| globals, "signing_hash_155" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "chain_id" |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + let _ := let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "AccessListTransaction" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let public_key := - M.call (| - M.get_name (| globals, "secp256k1_recover" |), - make_list [ - M.get_name (| globals, "r" |); - M.get_name (| globals, "s" |); - M.get_field (| M.get_name (| globals, "tx" |), "y_parity" |); - M.call (| - M.get_name (| globals, "signing_hash_2930" |), - make_list [ - M.get_name (| globals, "tx" |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "FeeMarketTransaction" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let public_key := - M.call (| - M.get_name (| globals, "secp256k1_recover" |), - make_list [ - M.get_name (| globals, "r" |); - M.get_name (| globals, "s" |); - M.get_field (| M.get_name (| globals, "tx" |), "y_parity" |); - M.call (| - M.get_name (| globals, "signing_hash_1559" |), - make_list [ - M.get_name (| globals, "tx" |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "BlobTransaction" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let public_key := - M.call (| - M.get_name (| globals, "secp256k1_recover" |), - make_list [ - M.get_name (| globals, "r" |); - M.get_name (| globals, "s" |); - M.get_field (| M.get_name (| globals, "tx" |), "y_parity" |); - M.call (| - M.get_name (| globals, "signing_hash_4844" |), - make_list [ - M.get_name (| globals, "tx" |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -2453,11 +1696,10 @@ Definition recover_sender : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12:Constant.int 32 |) + |), Constant.int 12 |) ], make_dict [] |) - |) in M.pure Constant.None_)). Definition signing_hash_pre155 : Value.t -> Value.t -> M := @@ -2490,7 +1732,6 @@ Definition signing_hash_pre155 : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition signing_hash_155 : Value.t -> Value.t -> M := @@ -2537,7 +1778,6 @@ Definition signing_hash_155 : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition signing_hash_2930 : Value.t -> Value.t -> M := @@ -2561,7 +1801,7 @@ Definition signing_hash_2930 : Value.t -> Value.t -> M := M.get_name (| globals, "keccak256" |), make_list [ BinOp.add (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "01", M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), make_list [ @@ -2573,7 +1813,6 @@ Definition signing_hash_2930 : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition signing_hash_1559 : Value.t -> Value.t -> M := @@ -2597,7 +1836,7 @@ Definition signing_hash_1559 : Value.t -> Value.t -> M := M.get_name (| globals, "keccak256" |), make_list [ BinOp.add (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "02", M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), make_list [ @@ -2609,7 +1848,6 @@ Definition signing_hash_1559 : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition signing_hash_4844 : Value.t -> Value.t -> M := @@ -2633,7 +1871,7 @@ Definition signing_hash_4844 : Value.t -> Value.t -> M := M.get_name (| globals, "keccak256" |), make_list [ BinOp.add (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "03", M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), make_list [ @@ -2645,7 +1883,6 @@ Definition signing_hash_4844 : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition compute_header_hash : Value.t -> Value.t -> M := @@ -2696,7 +1933,6 @@ Definition compute_header_hash : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition check_gas_limit : Value.t -> Value.t -> M := @@ -2735,54 +1971,14 @@ Definition check_gas_limit : Value.t -> Value.t -> M := M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "gas_limit" |), BinOp.add (| - M.get_name (| globals, "parent_gas_limit" |), - M.get_name (| globals, "max_adjustment_delta" |) - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.bool false - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt_e (| M.get_name (| globals, "gas_limit" |), BinOp.sub (| - M.get_name (| globals, "parent_gas_limit" |), - M.get_name (| globals, "max_adjustment_delta" |) - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.bool false - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "gas_limit" |), M.get_name (| globals, "GAS_LIMIT_MINIMUM" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.bool false - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| Constant.bool true - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/fork_types.v b/CoqOfPython/ethereum/cancun/fork_types.v index d51b593..0ba557d 100644 --- a/CoqOfPython/ethereum/cancun/fork_types.v +++ b/CoqOfPython/ethereum/cancun/fork_types.v @@ -102,5 +102,4 @@ Definition encode_account : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/state.v b/CoqOfPython/ethereum/cancun/state.v index 504eebb..c26597c 100644 --- a/CoqOfPython/ethereum/cancun/state.v +++ b/CoqOfPython/ethereum/cancun/state.v @@ -144,26 +144,14 @@ Definition begin_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) ], make_dict [] - |); {M.get_name (| globals, "k" |): M.call (| - M.get_name (| globals, "copy_trie" |), - make_list [ - M.get_name (| globals, "t" |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)} ] + |); (* At expr: unsupported node type: DictComp *) ] ], make_dict [] |) in let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "transient_storage" |), "_snapshots" |), "append" |), make_list [ - {M.get_name (| globals, "k" |): M.call (| - M.get_name (| globals, "copy_trie" |), - make_list [ - M.get_name (| globals, "t" |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)} + (* At expr: unsupported node type: DictComp *) ], make_dict [] |) in @@ -188,19 +176,6 @@ Definition commit_transaction : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "created_accounts" |), "clear" |), - make_list [], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -233,19 +208,6 @@ Definition rollback_transaction : Value.t -> Value.t -> M := |) |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "created_accounts" |), "clear" |), - make_list [], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -290,27 +252,8 @@ Definition get_account : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "account" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "account" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_ACCOUNT" |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -345,7 +288,6 @@ Definition get_account_optional : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "account" |) - |) in M.pure Constant.None_)). Definition set_account : Value.t -> Value.t -> M := @@ -425,15 +367,6 @@ Definition destroy_storage : Value.t -> Value.t -> M := Address of account whose storage is to be deleted. " in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -496,23 +429,6 @@ Definition get_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let value := @@ -534,7 +450,6 @@ Definition get_storage : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "value" |) - |) in M.pure Constant.None_)). Definition set_storage : Value.t -> Value.t -> M := @@ -555,14 +470,17 @@ Definition set_storage : Value.t -> Value.t -> M := value : `U256` Value to set at the key. " in - let _ := M.assert (| Compare.is_not (| M.call (| - M.get_name (| globals, "trie_get" |), - make_list [ - M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), Constant.None_ |) |) in + let _ := M.assert (| Compare.is_not (| + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + Constant.None_ + |) |) in let trie := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), @@ -572,24 +490,6 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let trie := - M.call (| - M.get_name (| globals, "Trie" |), - make_list [], - make_dict [] - |) in - let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), - M.get_name (| globals, "trie" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -602,15 +502,6 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), {} |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -635,26 +526,8 @@ Definition storage_root : Value.t -> Value.t -> M := " in let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "root" |), - make_list [ - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_TRIE_ROOT" |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -685,7 +558,6 @@ Definition state_root : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition account_exists : Value.t -> Value.t -> M := @@ -707,15 +579,17 @@ Definition account_exists : Value.t -> Value.t -> M := True if account exists in the state trie, False otherwise " in let _ := M.return_ (| - Compare.is_not (| M.call (| - M.get_name (| globals, "get_account_optional" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), Constant.None_ |) - |) in + Compare.is_not (| + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + Constant.None_ + |) M.pure Constant.None_)). Definition account_has_code_or_nonce : Value.t -> Value.t -> M := @@ -748,18 +622,23 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := |) in let _ := M.return_ (| BoolOp.or (| - Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( - Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |) + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |) )) |) - |) in M.pure Constant.None_)). Definition is_account_empty : Value.t -> Value.t -> M := @@ -792,23 +671,31 @@ Definition is_account_empty : Value.t -> Value.t -> M := |) in let _ := M.return_ (| BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |), ltac:(M.monadic ( - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "balance" |), + Constant.int 0 + |) )) |) )) |) - |) in M.pure Constant.None_)). Definition account_exists_and_is_empty : Value.t -> Value.t -> M := @@ -842,28 +729,39 @@ Definition account_exists_and_is_empty : Value.t -> Value.t -> M := |) in let _ := M.return_ (| BoolOp.and (| - Compare.is_not (| M.get_name (| globals, "account" |), Constant.None_ |), + Compare.is_not (| + M.get_name (| globals, "account" |), + Constant.None_ + |), ltac:(M.monadic ( BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |), ltac:(M.monadic ( - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "balance" |), + Constant.int 0 + |) )) |) )) |) )) |) - |) in M.pure Constant.None_)). Definition is_account_alive : Value.t -> Value.t -> M := @@ -894,36 +792,33 @@ Definition is_account_alive : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "account" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.bool false - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| UnOp.not (| BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |), ltac:(M.monadic ( - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "balance" |), + Constant.int 0 + |) )) |) )) |) |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -1049,30 +944,6 @@ Definition touch_account : Value.t -> Value.t -> M := The address of the account that need to initialised. " in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "account_exists" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "set_account" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |); - M.get_name (| globals, "EMPTY_ACCOUNT" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -1150,23 +1021,6 @@ Definition get_storage_original : Value.t -> Value.t -> M := Key of the storage slot. " in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "created_accounts" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -1182,22 +1036,6 @@ Definition get_storage_original : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "original_account_trie" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let original_value := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let original_value := M.call (| M.get_name (| globals, "trie_get" |), @@ -1219,7 +1057,6 @@ Definition get_storage_original : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "original_value" |) - |) in M.pure Constant.None_)). Definition get_transient_storage : Value.t -> Value.t -> M := @@ -1250,23 +1087,6 @@ Definition get_transient_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let value := @@ -1288,7 +1108,6 @@ Definition get_transient_storage : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "value" |) - |) in M.pure Constant.None_)). Definition set_transient_storage : Value.t -> Value.t -> M := @@ -1317,24 +1136,6 @@ Definition set_transient_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let trie := - M.call (| - M.get_name (| globals, "Trie" |), - make_list [], - make_dict [] - |) in - let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "transient_storage" |), "_tries" |), M.get_name (| globals, "address" |) |), - M.get_name (| globals, "trie" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -1347,15 +1148,6 @@ Definition set_transient_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), {} |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "transient_storage" |), "_tries" |), M.get_name (| globals, "address" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -1374,29 +1166,6 @@ Definition destroy_touched_empty_accounts : Value.t -> Value.t -> M := " in For M.get_name (| globals, "address" |) in M.get_name (| globals, "touched_accounts" |) do let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "destroy_account" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. diff --git a/CoqOfPython/ethereum/cancun/transactions.v b/CoqOfPython/ethereum/cancun/transactions.v index 7829244..2038e2c 100644 --- a/CoqOfPython/ethereum/cancun/transactions.v +++ b/CoqOfPython/ethereum/cancun/transactions.v @@ -124,115 +124,16 @@ Definition encode_transaction : Value.t -> Value.t -> M := Encode a transaction. Needed because non-legacy transactions aren't RLP. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "LegacyTransaction" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "tx" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "AccessListTransaction" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - BinOp.add (| - (* At constant: unsupported node type: Constant *), - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "tx" |) - ], - make_dict [] - |) - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "FeeMarketTransaction" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - BinOp.add (| - (* At constant: unsupported node type: Constant *), - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "tx" |) - ], - make_dict [] - |) - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "BlobTransaction" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - BinOp.add (| - (* At constant: unsupported node type: Constant *), - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "tx" |) - ], - make_dict [] - |) - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.call (| + let _ := M.raise (| Some(M.call (| M.get_name (| globals, "Exception" |), make_list [ (* At expr: unsupported node type: JoinedStr *) ], make_dict [] - |) |) in + |)) M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -250,88 +151,8 @@ Definition decode_transaction : Value.t -> Value.t -> M := Decode a transaction. Needed because non-legacy transactions aren't RLP. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "Bytes" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), Constant.int 1 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), - make_list [ - M.get_name (| globals, "AccessListTransaction" |); - M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 1:(* At expr: unsupported node type: NoneType *) |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), Constant.int 2 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), - make_list [ - M.get_name (| globals, "FeeMarketTransaction" |); - M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 1:(* At expr: unsupported node type: NoneType *) |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), Constant.int 3 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), - make_list [ - M.get_name (| globals, "BlobTransaction" |); - M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 1:(* At expr: unsupported node type: NoneType *) |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidBlock" |) |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "tx" |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/trie.v b/CoqOfPython/ethereum/cancun/trie.v index c6fe5c3..b2f66e4 100644 --- a/CoqOfPython/ethereum/cancun/trie.v +++ b/CoqOfPython/ethereum/cancun/trie.v @@ -205,96 +205,16 @@ Definition encode_internal_node : Value.t -> Value.t -> M := " in (* At stmt: unsupported node type: AnnAssign *) let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "node" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let unencoded := - (* At constant: unsupported node type: Constant *) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "LeafNode" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let unencoded := - make_tuple [ M.call (| - M.get_name (| globals, "nibble_list_to_compact" |), - make_list [ - M.get_field (| M.get_name (| globals, "node" |), "rest_of_key" |); - Constant.bool true - ], - make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "ExtensionNode" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let unencoded := - make_tuple [ M.call (| - M.get_name (| globals, "nibble_list_to_compact" |), - make_list [ - M.get_field (| M.get_name (| globals, "node" |), "key_segment" |); - Constant.bool false - ], - make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "BranchNode" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let unencoded := - BinOp.add (| - M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), - make_list [ - M.get_field (| M.get_name (| globals, "node" |), "value" |) - ] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.call (| + let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ (* At expr: unsupported node type: JoinedStr *) ], make_dict [] - |) |) in + |)) M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -312,23 +232,6 @@ Definition encode_internal_node : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "encoded" |) - ], - make_dict [] - |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "unencoded" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_name (| globals, "keccak256" |), @@ -337,7 +240,6 @@ Definition encode_internal_node : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -351,83 +253,8 @@ Definition encode_node : Value.t -> Value.t -> M := Currently mostly an unimplemented stub. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "storage_root" |), Constant.None_ |) |) in - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "encode_account" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "storage_root" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Withdrawal" |); M.get_name (| globals, "U256" |) ] - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.call (| - M.get_name (| globals, "cast" |), - make_list [ - M.get_field (| M.get_name (| globals, "rlp" |), "RLP" |); - M.get_name (| globals, "node" |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "Bytes" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "node" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "previous_trie" |), "encode_node" |), @@ -437,7 +264,6 @@ Definition encode_node : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -489,7 +315,6 @@ Definition copy_trie : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition trie_set : Value.t -> Value.t -> M := @@ -511,26 +336,6 @@ Definition trie_set : Value.t -> Value.t -> M := Node to insert at `key`. " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "value" |), M.get_field (| M.get_name (| globals, "trie" |), "default" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "key" |), M.get_field (| M.get_name (| globals, "trie" |), "_data" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), M.get_name (| globals, "value" |) @@ -568,7 +373,6 @@ Definition trie_get : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition common_prefix_length : Value.t -> Value.t -> M := @@ -591,28 +395,6 @@ Definition common_prefix_length : Value.t -> Value.t -> M := make_dict [] |) do let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| M.get_name (| globals, "i" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "b" |) - ], - make_dict [] - |) |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "i" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -624,7 +406,6 @@ Definition common_prefix_length : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition nibble_list_to_compact : Value.t -> Value.t -> M := @@ -670,68 +451,6 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| BinOp.mod_ (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |), - Constant.int 2 - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_name (| globals, "compact" |), "append" |), - make_list [ - BinOp.mult (| - Constant.int 16, - BinOp.mult (| - Constant.int 2, - M.get_name (| globals, "is_leaf" |) - |) - |) - ], - make_dict [] - |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 0; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |); - Constant.int 2 - ], - make_dict [] - |) do - let _ := M.call (| - M.get_field (| M.get_name (| globals, "compact" |), "append" |), - make_list [ - BinOp.add (| - BinOp.mult (| - Constant.int 16, - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) - |), - M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) - |) - ], - make_dict [] - |) in - EndFor. - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ @@ -793,7 +512,6 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition bytes_to_nibble_list : Value.t -> Value.t -> M := @@ -871,7 +589,6 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition _prepare_trie : Value.t -> Value.t -> M := @@ -901,45 +618,6 @@ Definition _prepare_trie : Value.t -> Value.t -> M := make_dict [] |) do let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "value" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in - let address := - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in - let encoded_value := - M.call (| - M.get_name (| globals, "encode_node" |), - make_list [ - M.get_name (| globals, "value" |); - M.call (| - M.get_name (| globals, "get_storage_root" |), - make_list [ - M.get_name (| globals, "address" |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let encoded_value := M.call (| M.get_name (| globals, "encode_node" |), @@ -953,29 +631,16 @@ Definition _prepare_trie : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.not_eq (| M.get_name (| globals, "encoded_value" |), (* At constant: unsupported node type: Constant *) |); + Compare.not_eq (| + M.get_name (| globals, "encoded_value" |), + Constant.bytes "" + |); M.get_name (| globals, "AssertionError" |) ], make_dict [] |) in (* At stmt: unsupported node type: AnnAssign *) let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "trie" |), "secured" |), - (* then *) - ltac:(M.monadic ( - let key := - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let key := M.get_name (| globals, "preimage" |) in M.pure Constant.None_ @@ -993,7 +658,6 @@ Definition _prepare_trie : Value.t -> Value.t -> M := EndFor. let _ := M.return_ (| M.get_name (| globals, "mapped" |) - |) in M.pure Constant.None_)). Definition root : Value.t -> Value.t -> M := @@ -1047,41 +711,6 @@ Definition root : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "root_node" |) - ], - make_dict [] - |) - ], - make_dict [] - |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "root_node" |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -1098,7 +727,6 @@ Definition root : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -1125,23 +753,6 @@ Definition patricialize : Value.t -> Value.t -> M := Root node of `obj`. " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "obj" |) - ], - make_dict [] - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.None_ - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let arbitrary_key := @@ -1159,36 +770,10 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "obj" |) - ], - make_dict [] - |), Constant.int 1 |), - (* then *) - ltac:(M.monadic ( - let leaf := - M.call (| - M.get_name (| globals, "LeafNode" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |); - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) - ], - make_dict [] - |) in - let _ := M.return_ (| - M.get_name (| globals, "leaf" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let substring := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |) |) in let prefix_length := M.call (| M.get_name (| globals, "len" |), @@ -1207,7 +792,7 @@ Definition patricialize : Value.t -> Value.t -> M := M.get_name (| globals, "common_prefix_length" |), make_list [ M.get_name (| globals, "substring" |); - M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) + M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) ], make_dict [] |) @@ -1215,58 +800,10 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.break (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let prefix := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):BinOp.add (| - M.get_name (| globals, "level" |), - M.get_name (| globals, "prefix_length" |) - |) |) in - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "ExtensionNode" |), - make_list [ - M.get_name (| globals, "prefix" |); - M.call (| - M.get_name (| globals, "encode_internal_node" |), - make_list [ - M.call (| - M.get_name (| globals, "patricialize" |), - make_list [ - M.get_name (| globals, "obj" |); - BinOp.add (| - M.get_name (| globals, "level" |), - M.get_name (| globals, "prefix_length" |) - |) - ], - make_dict [] - |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) @@ -1286,44 +823,9 @@ Definition patricialize : Value.t -> Value.t -> M := |) in EndFor. let value := - (* At constant: unsupported node type: Constant *) in + Constant.bytes "" in For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "key" |) - ], - make_dict [] - |), M.get_name (| globals, "level" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); - make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "AssertionError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let value := - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) @@ -1335,26 +837,9 @@ Definition patricialize : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "BranchNode" |), make_list [ - [M.call (| - M.get_name (| globals, "encode_internal_node" |), - make_list [ - M.call (| - M.get_name (| globals, "patricialize" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "branches" |), M.get_name (| globals, "k" |) |); - BinOp.add (| - M.get_name (| globals, "level" |), - Constant.int 1 - |) - ], - make_dict [] - |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)]; + (* At expr: unsupported node type: ListComp *); M.get_name (| globals, "value" |) ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/utils/address.v b/CoqOfPython/ethereum/cancun/utils/address.v index 02c6d56..cbfe60a 100644 --- a/CoqOfPython/ethereum/cancun/utils/address.v +++ b/CoqOfPython/ethereum/cancun/utils/address.v @@ -70,11 +70,10 @@ Definition to_address : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), make_list [], make_dict [] - |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) + |), UnOp.sub (| Constant.int 20 |) |) ], make_dict [] |) - |) in M.pure Constant.None_)). Definition compute_contract_address : Value.t -> Value.t -> M := @@ -114,7 +113,7 @@ Definition compute_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -132,7 +131,6 @@ Definition compute_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition compute_create2_contract_address : Value.t -> Value.t -> M := @@ -160,7 +158,7 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := BinOp.add (| BinOp.add (| BinOp.add (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "ff", M.get_name (| globals, "address" |) |), M.get_name (| globals, "salt" |) @@ -182,7 +180,7 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -200,5 +198,4 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/utils/hexadecimal.v b/CoqOfPython/ethereum/cancun/utils/hexadecimal.v index 60d41d5..baf5d38 100644 --- a/CoqOfPython/ethereum/cancun/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/cancun/utils/hexadecimal.v @@ -66,7 +66,6 @@ Definition hex_to_root : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition hex_to_bloom : Value.t -> Value.t -> M := @@ -105,7 +104,6 @@ Definition hex_to_bloom : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition hex_to_address : Value.t -> Value.t -> M := @@ -151,5 +149,4 @@ Definition hex_to_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/utils/message.v b/CoqOfPython/ethereum/cancun/utils/message.v index 5794d05..8309846 100644 --- a/CoqOfPython/ethereum/cancun/utils/message.v +++ b/CoqOfPython/ethereum/cancun/utils/message.v @@ -103,105 +103,14 @@ Definition prepare_message : Value.t -> Value.t -> M := Items containing contract creation or message call specific data. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "target" |); - M.get_name (| globals, "Bytes0" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let current_target := - M.call (| - M.get_name (| globals, "compute_contract_address" |), - make_list [ - M.get_name (| globals, "caller" |); - BinOp.sub (| - M.get_field (| M.call (| - M.get_name (| globals, "get_account" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "caller" |) - ], - make_dict [] - |), "nonce" |), - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 1 - ], - make_dict [] - |) - |) - ], - make_dict [] - |) in - let msg_data := - M.call (| - M.get_name (| globals, "Bytes" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |) in - let code := - M.get_name (| globals, "data" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "target" |); - M.get_name (| globals, "Address" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let current_target := - M.get_name (| globals, "target" |) in - let msg_data := - M.get_name (| globals, "data" |) in - let code := - M.get_field (| M.call (| - M.get_name (| globals, "get_account" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "target" |) - ], - make_dict [] - |), "code" |) in - let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "code_address" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let code_address := - M.get_name (| globals, "target" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.call (| + let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "Target must be address or empty bytes" ], make_dict [] - |) |) in + |)) M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -250,5 +159,4 @@ Definition prepare_message : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/vm/__init__.v b/CoqOfPython/ethereum/cancun/vm/__init__.v index 874ad86..a5c3728 100644 --- a/CoqOfPython/ethereum/cancun/vm/__init__.v +++ b/CoqOfPython/ethereum/cancun/vm/__init__.v @@ -151,28 +151,6 @@ Definition incorporate_child_on_success : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); - M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -205,57 +183,9 @@ Definition incorporate_child_on_error : Value.t -> Value.t -> M := The child evm to incorporate. " in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "RIPEMD160_ADDRESS" |), M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), - make_list [ - M.get_name (| globals, "RIPEMD160_ADDRESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |), M.get_name (| globals, "RIPEMD160_ADDRESS" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); - M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), - make_list [ - M.get_name (| globals, "RIPEMD160_ADDRESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign_op (| diff --git a/CoqOfPython/ethereum/cancun/vm/gas.v b/CoqOfPython/ethereum/cancun/vm/gas.v new file mode 100644 index 0000000..22e85b8 --- /dev/null +++ b/CoqOfPython/ethereum/cancun/vm/gas.v @@ -0,0 +1,1058 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Gas +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +EVM gas constants and calculators. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_U64 : + IsGlobalAlias globals ethereum.base_types.globals "U64". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.trace. +Axiom ethereum_trace_GasAndRefund : + IsGlobalAlias globals ethereum.trace.globals "GasAndRefund". +Axiom ethereum_trace_evm_trace : + IsGlobalAlias globals ethereum.trace.globals "evm_trace". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_taylor_exponential : + IsGlobalAlias globals ethereum.utils.numeric.globals "taylor_exponential". + +Require blocks. +Axiom blocks_Header : + IsGlobalAlias globals blocks.globals "Header". + +Require transactions. +Axiom transactions_BlobTransaction : + IsGlobalAlias globals transactions.globals "BlobTransaction". +Axiom transactions_Transaction : + IsGlobalAlias globals transactions.globals "Transaction". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". + +Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) +)). + +Definition GAS_BASE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 2 + ], + make_dict [] + |) +)). + +Definition GAS_VERY_LOW : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_STORAGE_SET : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 20000 + ], + make_dict [] + |) +)). + +Definition GAS_STORAGE_UPDATE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5000 + ], + make_dict [] + |) +)). + +Definition GAS_STORAGE_CLEAR_REFUND : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 4800 + ], + make_dict [] + |) +)). + +Definition GAS_LOW : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5 + ], + make_dict [] + |) +)). + +Definition GAS_MID : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 8 + ], + make_dict [] + |) +)). + +Definition GAS_HIGH : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 10 + ], + make_dict [] + |) +)). + +Definition GAS_EXPONENTIATION : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 10 + ], + make_dict [] + |) +)). + +Definition GAS_EXPONENTIATION_PER_BYTE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 50 + ], + make_dict [] + |) +)). + +Definition GAS_MEMORY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_KECCAK256 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 30 + ], + make_dict [] + |) +)). + +Definition GAS_KECCAK256_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 6 + ], + make_dict [] + |) +)). + +Definition GAS_COPY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_BLOCK_HASH : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 20 + ], + make_dict [] + |) +)). + +Definition GAS_LOG : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 375 + ], + make_dict [] + |) +)). + +Definition GAS_LOG_DATA : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 8 + ], + make_dict [] + |) +)). + +Definition GAS_LOG_TOPIC : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 375 + ], + make_dict [] + |) +)). + +Definition GAS_CREATE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 32000 + ], + make_dict [] + |) +)). + +Definition GAS_CODE_DEPOSIT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 200 + ], + make_dict [] + |) +)). + +Definition GAS_ZERO : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) +)). + +Definition GAS_NEW_ACCOUNT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 25000 + ], + make_dict [] + |) +)). + +Definition GAS_CALL_VALUE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 9000 + ], + make_dict [] + |) +)). + +Definition GAS_CALL_STIPEND : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 2300 + ], + make_dict [] + |) +)). + +Definition GAS_SELF_DESTRUCT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5000 + ], + make_dict [] + |) +)). + +Definition GAS_SELF_DESTRUCT_NEW_ACCOUNT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 25000 + ], + make_dict [] + |) +)). + +Definition GAS_ECRECOVER : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3000 + ], + make_dict [] + |) +)). + +Definition GAS_SHA256 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 60 + ], + make_dict [] + |) +)). + +Definition GAS_SHA256_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 12 + ], + make_dict [] + |) +)). + +Definition GAS_RIPEMD160 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 600 + ], + make_dict [] + |) +)). + +Definition GAS_RIPEMD160_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 120 + ], + make_dict [] + |) +)). + +Definition GAS_IDENTITY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 15 + ], + make_dict [] + |) +)). + +Definition GAS_IDENTITY_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_RETURN_DATA_COPY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_FAST_STEP : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5 + ], + make_dict [] + |) +)). + +Definition GAS_BLAKE2_PER_ROUND : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) +)). + +Definition GAS_COLD_SLOAD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 2100 + ], + make_dict [] + |) +)). + +Definition GAS_COLD_ACCOUNT_ACCESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 2600 + ], + make_dict [] + |) +)). + +Definition GAS_WARM_ACCESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 100 + ], + make_dict [] + |) +)). + +Definition GAS_INIT_CODE_WORD_COST : Value.t := M.run ltac:(M.monadic ( + Constant.int 2 +)). + +Definition GAS_BLOBHASH_OPCODE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_POINT_EVALUATION : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 50000 + ], + make_dict [] + |) +)). + +Definition TARGET_BLOB_GAS_PER_BLOCK : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "U64" |), + make_list [ + Constant.int 393216 + ], + make_dict [] + |) +)). + +Definition GAS_PER_BLOB : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.pow (| + Constant.int 2, + Constant.int 17 + |) + ], + make_dict [] + |) +)). + +Definition MIN_BLOB_GASPRICE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) +)). + +Definition BLOB_GASPRICE_UPDATE_FRACTION : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3338477 + ], + make_dict [] + |) +)). + +Definition ExtendMemory : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition MessageCallGas : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition charge_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "amount" ] |) in + let _ := Constant.str " + Subtracts `amount` from `evm.gas_left`. + + Parameters + ---------- + evm : + The current EVM. + amount : + The amount of gas the current operation requires. + + " in + let _ := M.call (| + M.get_name (| globals, "evm_trace" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "GasAndRefund" |), + make_list [ + M.get_name (| globals, "amount" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + let _ := M.assign_op (| + BinOp.sub, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "amount" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition calculate_memory_gas_cost : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "size_in_bytes" ] |) in + let _ := Constant.str " + Calculates the gas cost for allocating memory + to the smallest multiple of 32 bytes, + such that the allocated size is at least as big as the given size. + + Parameters + ---------- + size_in_bytes : + The size of the data in bytes. + + Returns + ------- + total_gas_cost : `ethereum.base_types.Uint` + The gas cost for storing data in memory. + " in + let size_in_words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "size_in_bytes" |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let linear_cost := + BinOp.mult (| + M.get_name (| globals, "size_in_words" |), + M.get_name (| globals, "GAS_MEMORY" |) + |) in + let quadratic_cost := + BinOp.floor_div (| + BinOp.pow (| + M.get_name (| globals, "size_in_words" |), + Constant.int 2 + |), + Constant.int 512 + |) in + let total_gas_cost := + BinOp.add (| + M.get_name (| globals, "linear_cost" |), + M.get_name (| globals, "quadratic_cost" |) + |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_)). + +Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "memory"; "extensions" ] |) in + let _ := Constant.str " + Calculates the gas amount to extend memory + + Parameters + ---------- + memory : + Memory contents of the EVM. + extensions: + List of extensions to be made to the memory. + Consists of a tuple of start position and size. + + Returns + ------- + extend_memory: `ExtendMemory` + " in + let size_to_extend := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let to_be_paid := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let current_size := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "memory" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + For make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ] in M.get_name (| globals, "extensions" |) do + let _ := + M.pure Constant.None_ + )) |) in + let before_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "current_size" |) + ], + make_dict [] + |) in + let after_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let size_to_extend := BinOp.add + BinOp.sub (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |) + BinOp.sub (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |) in + let already_paid := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "before_size" |) + ], + make_dict [] + |) in + let total_cost := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "after_size" |) + ], + make_dict [] + |) in + let to_be_paid := BinOp.add + BinOp.sub (| + M.get_name (| globals, "total_cost" |), + M.get_name (| globals, "already_paid" |) + |) + BinOp.sub (| + M.get_name (| globals, "total_cost" |), + M.get_name (| globals, "already_paid" |) + |) in + let current_size := + M.get_name (| globals, "after_size" |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ExtendMemory" |), + make_list [ + M.get_name (| globals, "to_be_paid" |); + M.get_name (| globals, "size_to_extend" |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition calculate_message_call_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "value"; "gas"; "gas_left"; "memory_cost"; "extra_gas"; "call_stipend" ] |) in + let _ := Constant.str " + Calculates the MessageCallGas (cost and stipend) for + executing call Opcodes. + + Parameters + ---------- + value: + The amount of `ETH` that needs to be transferred. + gas : + The amount of gas provided to the message-call. + gas_left : + The amount of gas left in the current frame. + memory_cost : + The amount needed to extend the memory in the current frame. + extra_gas : + The amount of gas needed for transferring value + creating a new + account inside a message call. + call_stipend : + The amount of stipend provided to a message call to execute code while + transferring value(ETH). + + Returns + ------- + message_call_gas: `MessageCallGas` + " in + let call_stipend := + (* if *) +M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let gas := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "max_message_call_gas" |), + make_list [ + BinOp.sub (| + BinOp.sub (| + M.get_name (| globals, "gas_left" |), + M.get_name (| globals, "memory_cost" |) + |), + M.get_name (| globals, "extra_gas" |) + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallGas" |), + make_list [ + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "extra_gas" |) + |); + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "call_stipend" |) + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition max_message_call_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "gas" ] |) in + let _ := Constant.str " + Calculates the maximum gas that is allowed for making a message call + + Parameters + ---------- + gas : + The amount of gas provided to the message-call. + + Returns + ------- + max_allowed_message_call_gas: `ethereum.base_types.Uint` + The maximum gas allowed for making the message-call. + " in + let _ := M.return_ (| + BinOp.sub (| + M.get_name (| globals, "gas" |), + BinOp.floor_div (| + M.get_name (| globals, "gas" |), + Constant.int 64 + |) + |) + M.pure Constant.None_)). + +Definition init_code_cost : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "init_code_length" ] |) in + let _ := Constant.str " + Calculates the gas to be charged for the init code in CREAT* + opcodes as well as create transactions. + + Parameters + ---------- + init_code_length : + The length of the init code provided to the opcode + or a create transaction + + Returns + ------- + init_code_gas: `ethereum.base_types.Uint` + The gas to be charged for the init code. + " in + let _ := M.return_ (| + BinOp.floor_div (| + BinOp.mult (| + M.get_name (| globals, "GAS_INIT_CODE_WORD_COST" |), + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "init_code_length" |) + ], + make_dict [] + |) + |), + Constant.int 32 + |) + M.pure Constant.None_)). + +Definition calculate_excess_blob_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "parent_header" ] |) in + let _ := Constant.str " + Calculated the excess blob gas for the current block based + on the gas used in the parent block. + + Parameters + ---------- + parent_header : + The parent block of the current block. + + Returns + ------- + excess_blob_gas: `ethereum.base_types.U64` + The excess blob gas for the current block. + " in + let parent_blob_gas := + BinOp.add (| + M.get_field (| M.get_name (| globals, "parent_header" |), "excess_blob_gas" |), + M.get_field (| M.get_name (| globals, "parent_header" |), "blob_gas_used" |) + |) in + let _ := + let _ := M.return_ (| + BinOp.sub (| + M.get_name (| globals, "parent_blob_gas" |), + M.get_name (| globals, "TARGET_BLOB_GAS_PER_BLOCK" |) + |) + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition calculate_total_blob_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Calculate the total blob gas for a transaction. + + Parameters + ---------- + tx : + The transaction for which the blob gas is to be calculated. + + Returns + ------- + total_blob_gas: `ethereum.base_types.Uint` + The total blob gas for the transaction. + " in + let _ := + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition calculate_blob_gas_price : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "excess_blob_gas" ] |) in + let _ := Constant.str " + Calculate the blob gasprice for a block. + + Parameters + ---------- + excess_blob_gas : + The excess blob gas for the block. + + Returns + ------- + blob_gasprice: `Uint` + The blob gasprice. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "taylor_exponential" |), + make_list [ + M.get_name (| globals, "MIN_BLOB_GASPRICE" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "excess_blob_gas" |) + ], + make_dict [] + |); + M.get_name (| globals, "BLOB_GASPRICE_UPDATE_FRACTION" |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition calculate_data_fee : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "excess_blob_gas"; "tx" ] |) in + let _ := Constant.str " + Calculate the blob data fee for a transaction. + + Parameters + ---------- + excess_blob_gas : + The excess_blob_gas for the execution. + tx : + The transaction for which the blob data fee is to be calculated. + + Returns + ------- + data_fee: `Uint` + The blob data fee. + " in + let _ := M.return_ (| + BinOp.mult (| + M.call (| + M.get_name (| globals, "calculate_total_blob_gas" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "calculate_blob_gas_price" |), + make_list [ + M.get_name (| globals, "excess_blob_gas" |) + ], + make_dict [] + |) + |) + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/cancun/vm/instructions/arithmetic.v index a8b5c61..581ba5d 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/arithmetic.v @@ -273,22 +273,6 @@ Definition div : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let quotient := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let quotient := BinOp.floor_div (| M.get_name (| globals, "dividend" |), @@ -357,32 +341,7 @@ Definition sdiv : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let quotient := - Constant.int 0 in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_name (| globals, "dividend" |), UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "divisor" |), UnOp.sub (| Constant.int 1 |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let quotient := - UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let sign := M.call (| M.get_name (| globals, "get_sign" |), @@ -477,22 +436,6 @@ Definition mod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let remainder := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let remainder := BinOp.mod_ (| M.get_name (| globals, "x" |), @@ -561,16 +504,6 @@ Definition smod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let remainder := - Constant.int 0 in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let remainder := BinOp.mult (| M.call (| @@ -684,22 +617,6 @@ Definition addmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -795,22 +712,6 @@ Definition mulmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -980,16 +881,6 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "byte_num" |), Constant.int 31 |), - (* then *) - ltac:(M.monadic ( - let result := - M.get_name (| globals, "value" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let value_bytes := M.call (| M.get_name (| globals, "bytes" |), @@ -1012,29 +903,13 @@ Definition signextend : Value.t -> Value.t -> M := ], make_dict [] |) - |):(* At expr: unsupported node type: NoneType *) |) in + |) |) in let sign_bit := BinOp.r_shift (| M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), Constant.int 7 |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "sign_bit" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), - make_list [ - M.get_name (| globals, "value_bytes" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let num_bytes_prepend := BinOp.sub (| Constant.int 32, diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/bitwise.v b/CoqOfPython/ethereum/cancun/vm/instructions/bitwise.v index 9f2f382..64cf120 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/bitwise.v @@ -287,22 +287,6 @@ Definition get_byte : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "byte_index" |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let extra_bytes_to_right := BinOp.sub (| Constant.int 31, @@ -382,28 +366,6 @@ Definition bitwise_shl : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - BinOp.mod_ (| - BinOp.l_shift (| - M.get_name (| globals, "value" |), - M.get_name (| globals, "shift" |) - |), - M.get_name (| globals, "U256_CEIL_VALUE" |) - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -465,19 +427,6 @@ Definition bitwise_shr : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), - (* then *) - ltac:(M.monadic ( - let result := - BinOp.r_shift (| - M.get_name (| globals, "value" |), - M.get_name (| globals, "shift" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -543,42 +492,7 @@ Definition bitwise_sar : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), - make_list [ - BinOp.r_shift (| - M.get_name (| globals, "signed_value" |), - M.get_name (| globals, "shift" |) - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "signed_value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/block.v b/CoqOfPython/ethereum/cancun/vm/instructions/block.v index 27a38cb..6bcda3b 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/block.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/block.v @@ -75,24 +75,6 @@ Definition block_hash : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.lt_e (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), M.get_name (| globals, "block_number" |) |), - ltac:(M.monadic ( - Compare.gt (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), BinOp.add (| - M.get_name (| globals, "block_number" |), - Constant.int 256 - |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let hash := - (* At constant: unsupported node type: Constant *) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let hash := M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/comparison.v b/CoqOfPython/ethereum/cancun/vm/instructions/comparison.v index fbc35f8..b8529d8 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/comparison.v @@ -78,7 +78,10 @@ Definition less_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.lt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -145,7 +148,10 @@ Definition signed_less_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.lt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -205,7 +211,10 @@ Definition greater_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.gt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -272,7 +281,10 @@ Definition signed_greater_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.gt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -332,7 +344,10 @@ Definition equal : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.eq (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.eq (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -384,7 +399,10 @@ Definition is_zero : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.eq (| M.get_name (| globals, "x" |), Constant.int 0 |) + Compare.eq (| + M.get_name (| globals, "x" |), + Constant.int 0 + |) ], make_dict [] |) in diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/control_flow.v b/CoqOfPython/ethereum/cancun/vm/instructions/control_flow.v index 04a79d9..d4e4eae 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/control_flow.v @@ -109,15 +109,6 @@ Definition jump : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -177,29 +168,7 @@ Definition jumpi : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "conditional_value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let destination := - BinOp.add (| - M.get_field (| M.get_name (| globals, "evm" |), "pc" |), - Constant.int 1 - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let destination := M.get_name (| globals, "jump_dest" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/environment.v b/CoqOfPython/ethereum/cancun/vm/instructions/environment.v index 4ff61a8..3d62649 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/environment.v @@ -162,22 +162,6 @@ Definition balance : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "charge_gas" |), - make_list [ - M.get_name (| globals, "evm" |); - M.get_name (| globals, "GAS_WARM_ACCESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -544,7 +528,7 @@ Definition calldatacopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -712,7 +696,7 @@ Definition codecopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -811,22 +795,6 @@ Definition extcodesize : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "charge_gas" |), - make_list [ - M.get_name (| globals, "evm" |); - M.get_name (| globals, "GAS_WARM_ACCESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -964,28 +932,6 @@ Definition extcodecopy : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "charge_gas" |), - make_list [ - M.get_name (| globals, "evm" |); - BinOp.add (| - BinOp.add (| - M.get_name (| globals, "GAS_WARM_ACCESS" |), - M.get_name (| globals, "copy_gas_cost" |) - |), - M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1013,7 +959,7 @@ Definition extcodecopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -1184,28 +1130,31 @@ Definition returndatacopy : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt_e (| BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "return_data_start_position" |) - ], - make_dict [] + Compare.lt_e (| + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "return_data_start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) |), M.call (| - M.get_name (| globals, "Uint" |), + M.get_name (| globals, "len" |), make_list [ - M.get_name (| globals, "size" |) + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |) ], make_dict [] |) - |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "return_data" |) - ], - make_dict [] - |) |); + |); M.get_name (| globals, "OutOfBoundsRead" |) ], make_dict [] @@ -1214,15 +1163,12 @@ Definition returndatacopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in let value := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |):BinOp.add (| - M.get_name (| globals, "return_data_start_position" |), - M.get_name (| globals, "size" |) - |) |) in + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |) |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -1264,22 +1210,6 @@ Definition extcodehash : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "charge_gas" |), - make_list [ - M.get_name (| globals, "evm" |); - M.get_name (| globals, "GAS_WARM_ACCESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1307,22 +1237,6 @@ Definition extcodehash : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "account" |), M.get_name (| globals, "EMPTY_ACCOUNT" |) |), - (* then *) - ltac:(M.monadic ( - let codehash := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let codehash := M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), @@ -1470,28 +1384,12 @@ Definition blob_hash : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "index" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "blob_versioned_hashes" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let blob_hash := - M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "blob_versioned_hashes" |), M.get_name (| globals, "index" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let blob_hash := M.call (| M.get_name (| globals, "Bytes32" |), make_list [ BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", Constant.int 32 |) ], diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/keccak.v b/CoqOfPython/ethereum/cancun/vm/instructions/keccak.v index cab9ffb..2c4b10e 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/keccak.v @@ -137,7 +137,7 @@ Definition keccak : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/log.v b/CoqOfPython/ethereum/cancun/vm/instructions/log.v index 4891a4d..e084e59 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/log.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/log.v @@ -161,7 +161,7 @@ Definition log_n : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/memory.v b/CoqOfPython/ethereum/cancun/vm/instructions/memory.v index 9625fa6..dd6635e 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/memory.v @@ -129,7 +129,7 @@ Definition mstore : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -211,7 +211,7 @@ Definition mstore8 : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -296,7 +296,7 @@ Definition mload : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -473,7 +473,7 @@ Definition mcopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/stack.v b/CoqOfPython/ethereum/cancun/vm/instructions/stack.v index 46a91f6..aa085db 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/stack.v @@ -104,22 +104,6 @@ Definition push_n : Value.t -> Value.t -> M := " in let _ := M.pass (| |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "num_bytes" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "charge_gas" |), - make_list [ - M.get_name (| globals, "evm" |); - M.get_name (| globals, "GAS_BASE" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -207,13 +191,16 @@ Definition dup_n : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] - |) |); + Compare.lt (| + M.get_name (| globals, "item_number" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + |); M.get_name (| globals, "StackUnderflowError" |) ], make_dict [] @@ -279,13 +266,16 @@ Definition swap_n : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] - |) |); + Compare.lt (| + M.get_name (| globals, "item_number" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + |); M.get_name (| globals, "StackUnderflowError" |) ], make_dict [] diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/storage.v b/CoqOfPython/ethereum/cancun/vm/instructions/storage.v index 51a730d..b214ff1 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/storage.v @@ -95,22 +95,6 @@ Definition sload : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "charge_gas" |), - make_list [ - M.get_name (| globals, "evm" |); - M.get_name (| globals, "GAS_WARM_ACCESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "add" |), make_list [ @@ -188,7 +172,10 @@ Definition sstore : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.gt (| M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), M.get_name (| globals, "GAS_CALL_STIPEND" |) |); + Compare.gt (| + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "GAS_CALL_STIPEND" |) + |); M.get_name (| globals, "OutOfGasError" |) ], make_dict [] @@ -222,189 +209,15 @@ Definition sstore : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_in (| make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "add" |), - make_list [ - make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ] - ], - make_dict [] - |) in - let gas_cost := BinOp.add - M.get_name (| globals, "GAS_COLD_SLOAD" |) - M.get_name (| globals, "GAS_COLD_SLOAD" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_name (| globals, "original_value" |), M.get_name (| globals, "current_value" |) |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_name (| globals, "current_value" |), M.get_name (| globals, "new_value" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let gas_cost := BinOp.add - M.get_name (| globals, "GAS_STORAGE_SET" |) - M.get_name (| globals, "GAS_STORAGE_SET" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let gas_cost := BinOp.add - BinOp.sub (| - M.get_name (| globals, "GAS_STORAGE_UPDATE" |), - M.get_name (| globals, "GAS_COLD_SLOAD" |) - |) - BinOp.sub (| - M.get_name (| globals, "GAS_STORAGE_UPDATE" |), - M.get_name (| globals, "GAS_COLD_SLOAD" |) - |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let gas_cost := BinOp.add M.get_name (| globals, "GAS_WARM_ACCESS" |) M.get_name (| globals, "GAS_WARM_ACCESS" |) in M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_eq (| M.get_name (| globals, "current_value" |), M.get_name (| globals, "new_value" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), - ltac:(M.monadic ( - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "new_value" |), Constant.int 0 |) - )) - |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), - M.call (| - M.get_name (| globals, "int" |), - make_list [ - M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.sub, - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), - M.call (| - M.get_name (| globals, "int" |), - make_list [ - M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "original_value" |), M.get_name (| globals, "new_value" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), - M.call (| - M.get_name (| globals, "int" |), - make_list [ - BinOp.sub (| - M.get_name (| globals, "GAS_STORAGE_SET" |), - M.get_name (| globals, "GAS_WARM_ACCESS" |) - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), - M.call (| - M.get_name (| globals, "int" |), - make_list [ - BinOp.sub (| - BinOp.sub (| - M.get_name (| globals, "GAS_STORAGE_UPDATE" |), - M.get_name (| globals, "GAS_COLD_SLOAD" |) - |), - M.get_name (| globals, "GAS_WARM_ACCESS" |) - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/system.v b/CoqOfPython/ethereum/cancun/vm/instructions/system.v new file mode 100644 index 0000000..4ef7a77 --- /dev/null +++ b/CoqOfPython/ethereum/cancun/vm/instructions/system.v @@ -0,0 +1,1667 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) System Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM system related instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_account_exists_and_is_empty : + IsGlobalAlias globals state.globals "account_exists_and_is_empty". +Axiom state_account_has_code_or_nonce : + IsGlobalAlias globals state.globals "account_has_code_or_nonce". +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". +Axiom state_increment_nonce : + IsGlobalAlias globals state.globals "increment_nonce". +Axiom state_is_account_alive : + IsGlobalAlias globals state.globals "is_account_alive". +Axiom state_move_ether : + IsGlobalAlias globals state.globals "move_ether". +Axiom state_set_account_balance : + IsGlobalAlias globals state.globals "set_account_balance". + +Require utils.address. +Axiom utils_address_compute_contract_address : + IsGlobalAlias globals utils.address.globals "compute_contract_address". +Axiom utils_address_compute_create2_contract_address : + IsGlobalAlias globals utils.address.globals "compute_create2_contract_address". +Axiom utils_address_to_address : + IsGlobalAlias globals utils.address.globals "to_address". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". +Axiom __init___Message : + IsGlobalAlias globals __init__.globals "Message". +Axiom __init___incorporate_child_on_error : + IsGlobalAlias globals __init__.globals "incorporate_child_on_error". +Axiom __init___incorporate_child_on_success : + IsGlobalAlias globals __init__.globals "incorporate_child_on_success". + +Require exceptions. +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". +Axiom exceptions_Revert : + IsGlobalAlias globals exceptions.globals "Revert". +Axiom exceptions_WriteInStaticContext : + IsGlobalAlias globals exceptions.globals "WriteInStaticContext". + +Require gas. +Axiom gas_GAS_CALL_VALUE : + IsGlobalAlias globals gas.globals "GAS_CALL_VALUE". +Axiom gas_GAS_COLD_ACCOUNT_ACCESS : + IsGlobalAlias globals gas.globals "GAS_COLD_ACCOUNT_ACCESS". +Axiom gas_GAS_CREATE : + IsGlobalAlias globals gas.globals "GAS_CREATE". +Axiom gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". +Axiom gas_GAS_NEW_ACCOUNT : + IsGlobalAlias globals gas.globals "GAS_NEW_ACCOUNT". +Axiom gas_GAS_SELF_DESTRUCT : + IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT". +Axiom gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : + IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". +Axiom gas_GAS_WARM_ACCESS : + IsGlobalAlias globals gas.globals "GAS_WARM_ACCESS". +Axiom gas_GAS_ZERO : + IsGlobalAlias globals gas.globals "GAS_ZERO". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_calculate_message_call_gas : + IsGlobalAlias globals gas.globals "calculate_message_call_gas". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". +Axiom gas_init_code_cost : + IsGlobalAlias globals gas.globals "init_code_cost". +Axiom gas_max_message_call_gas : + IsGlobalAlias globals gas.globals "max_message_call_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". +Axiom memory_memory_write : + IsGlobalAlias globals memory.globals "memory_write". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition generic_create : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "endowment"; "contract_address"; "memory_start_position"; "memory_size"; "init_code_gas" ] |) in + let _ := Constant.str " + Core logic used by the `CREATE*` family of opcodes. + " in +(* At stmt: unsupported node type: ImportFrom *) + let call_data := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "call_data" |) + ], + make_dict [] + |), + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "MAX_CODE_SIZE" |) + |) + |); + M.get_name (| globals, "OutOfGasError" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "contract_address" |) + ], + make_dict [] + |) in + let create_message_gas := + M.call (| + M.get_name (| globals, "max_message_call_gas" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.sub, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "create_message_gas" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let sender_address := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in + let sender := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "sender_address" |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + let child_message := + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) in + let child_evm := + M.call (| + M.get_name (| globals, "process_create_message" |), + make_list [ + M.get_name (| globals, "child_message" |); + M.get_field (| M.get_name (| globals, "evm" |), "env" |) + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_success" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition create : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Creates a new account with associated code. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let endowment := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_position" |); M.get_name (| globals, "memory_size" |) ] + ] + ], + make_dict [] + |) in + let init_code_gas := + M.call (| + M.get_name (| globals, "init_code_cost" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_CREATE" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |), + M.get_name (| globals, "init_code_gas" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let contract_address := + M.call (| + M.get_name (| globals, "compute_contract_address" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "nonce" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "generic_create" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "endowment" |); + M.get_name (| globals, "contract_address" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |); + M.get_name (| globals, "init_code_gas" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition create2 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Creates a new account with associated code. + + It's similar to CREATE opcode except that the address of new account + depends on the init_code instead of the nonce of sender. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let endowment := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let salt := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_position" |); M.get_name (| globals, "memory_size" |) ] + ] + ], + make_dict [] + |) in + let call_data_words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let init_code_gas := + M.call (| + M.get_name (| globals, "init_code_cost" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_CREATE" |), + BinOp.mult (| + M.get_name (| globals, "GAS_KECCAK256_WORD" |), + M.get_name (| globals, "call_data_words" |) + |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |), + M.get_name (| globals, "init_code_gas" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let contract_address := + M.call (| + M.get_name (| globals, "compute_create2_contract_address" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "salt" |); + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "generic_create" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "endowment" |); + M.get_name (| globals, "contract_address" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |); + M.get_name (| globals, "init_code_gas" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition return_ : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Halts execution returning output data. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let memory_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_position" |); M.get_name (| globals, "memory_size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_ZERO" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "running" |), + Constant.bool false + |) in + let _ := M.pass (| |) in + M.pure Constant.None_)). + +Definition generic_call : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "gas"; "value"; "caller"; "to"; "code_address"; "should_transfer_value"; "is_staticcall"; "memory_input_start_position"; "memory_input_size"; "memory_output_start_position"; "memory_output_size" ] |) in + let _ := Constant.str " + Perform the core logic of the `CALL*` family of opcodes. + " in +(* At stmt: unsupported node type: ImportFrom *) + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let _ := + M.pure Constant.None_ + )) |) in + let call_data := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |) + ], + make_dict [] + |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "code_address" |) + ], + make_dict [] + |), "code" |) in + let child_message := + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) in + let child_evm := + M.call (| + M.get_name (| globals, "process_message" |), + make_list [ + M.get_name (| globals, "child_message" |); + M.get_field (| M.get_name (| globals, "evm" |), "env" |) + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_success" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let actual_output_size := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_name (| globals, "memory_output_size" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), Constant.None_:M.get_name (| globals, "actual_output_size" |) |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition call : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into an account. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let to := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "to" |) + ], + make_dict [] + |) in + let access_gas_cost := + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + M.pure Constant.None_ + )) |) in + let create_gas_cost := + (* if *) +M.if_then_else (| + BoolOp.or (| + M.call (| + M.get_name (| globals, "is_account_alive" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "to" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |) + )) + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let transfer_gas_cost := + (* if *) +M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "access_gas_cost" |), + M.get_name (| globals, "create_gas_cost" |) + |), + M.get_name (| globals, "transfer_gas_cost" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.or (| + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "value" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) + )) + |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let sender_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.get_name (| globals, "value" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "to" |); + Constant.bool true; + Constant.bool false; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition callcode : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into this account with alternative account’s code. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let code_address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let to := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "code_address" |) + ], + make_dict [] + |) in + let access_gas_cost := + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + M.pure Constant.None_ + )) |) in + let transfer_gas_cost := + (* if *) +M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + BinOp.add (| + M.get_name (| globals, "access_gas_cost" |), + M.get_name (| globals, "transfer_gas_cost" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let sender_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.get_name (| globals, "value" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "code_address" |); + Constant.bool true; + Constant.bool false; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition selfdestruct : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Halt execution and register account for later deletion. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let beneficiary := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let gas_cost := + M.get_name (| globals, "GAS_SELF_DESTRUCT" |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "gas_cost" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let originator := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in + let originator_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "originator" |) + ], + make_dict [] + |), "balance" |) in + let _ := M.call (| + M.get_name (| globals, "move_ether" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "originator" |); + M.get_name (| globals, "beneficiary" |); + M.get_name (| globals, "originator_balance" |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "running" |), + Constant.bool false + |) in + let _ := M.pass (| |) in + M.pure Constant.None_)). + +Definition delegatecall : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into an account. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let code_address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "code_address" |) + ], + make_dict [] + |) in + let access_gas_cost := + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + M.pure Constant.None_ + )) |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + M.get_name (| globals, "access_gas_cost" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "value" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "caller" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "code_address" |); + Constant.bool false; + Constant.bool false; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition staticcall : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into an account. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let to := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "to" |) + ], + make_dict [] + |) in + let access_gas_cost := + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + M.pure Constant.None_ + )) |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + M.get_name (| globals, "access_gas_cost" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "to" |); + Constant.bool true; + Constant.bool true; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition revert : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stop execution and revert state changes, without consuming all provided gas + and also has the ability to return a reason + Parameters + ---------- + evm : + The current EVM frame. + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let output := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "bytes" |), + make_list [ + M.get_name (| globals, "output" |) + ], + make_dict [] + |) + |) in + let _ := M.raise (| Some(M.get_name (| globals, "Revert" |)) + let _ := M.pass (| |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/vm/interpreter.v b/CoqOfPython/ethereum/cancun/vm/interpreter.v index e394207..9732c95 100644 --- a/CoqOfPython/ethereum/cancun/vm/interpreter.v +++ b/CoqOfPython/ethereum/cancun/vm/interpreter.v @@ -186,91 +186,6 @@ Definition process_message_call : Value.t -> Value.t -> M := Output of the message call " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_name (| globals, "message" |), "target" |), M.call (| - M.get_name (| globals, "Bytes0" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let is_collision := - M.call (| - M.get_name (| globals, "account_has_code_or_nonce" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_field (| M.get_name (| globals, "message" |), "current_target" |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - M.get_name (| globals, "is_collision" |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "MessageCallOutput" |), - make_list [ - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |); - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |); - M.call (| - M.get_name (| globals, "tuple" |), - make_list [], - make_dict [] - |); - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |); - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |); - M.call (| - M.get_name (| globals, "AddressCollision" |), - make_list [], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let evm := - M.call (| - M.get_name (| globals, "process_create_message" |), - make_list [ - M.get_name (| globals, "message" |); - M.get_name (| globals, "env" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let evm := M.call (| M.get_name (| globals, "process_message" |), @@ -281,74 +196,11 @@ Definition process_message_call : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_field (| M.get_name (| globals, "message" |), "target" |) - ], - make_dict [] - |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), - make_list [ - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_field (| M.get_name (| globals, "message" |), "target" |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "evm" |), "error" |), - (* then *) - ltac:(M.monadic ( -(* At stmt: unsupported node type: AnnAssign *) - let accounts_to_delete := - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |) in - let touched_accounts := - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |) in - let refund_counter := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let logs := M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in let accounts_to_delete := @@ -392,7 +244,6 @@ Definition process_message_call : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). Definition process_create_message : Value.t -> Value.t -> M := @@ -455,28 +306,6 @@ Definition process_create_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), - (* then *) - ltac:(M.monadic ( - let contract_code := - M.get_field (| M.get_name (| globals, "evm" |), "output" |) in - let contract_code_gas := - BinOp.mult (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "contract_code" |) - ], - make_dict [] - |), - M.get_name (| globals, "GAS_CODE_DEPOSIT" |) - |) in -(* At stmt: unsupported node type: Try *) - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "rollback_transaction" |), make_list [ @@ -489,7 +318,6 @@ Definition process_create_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) - |) in M.pure Constant.None_)). Definition process_message : Value.t -> Value.t -> M := @@ -511,21 +339,6 @@ Definition process_message : Value.t -> Value.t -> M := Items containing execution specific objects " in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_field (| M.get_name (| globals, "message" |), "depth" |), M.get_name (| globals, "STACK_DEPTH_LIMIT" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "StackDepthLimitError" |), - make_list [ - Constant.str "Stack depth limit reached" - ], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -545,29 +358,6 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - M.get_field (| M.get_name (| globals, "message" |), "should_transfer_value" |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_field (| M.get_name (| globals, "message" |), "value" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "move_ether" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_field (| M.get_name (| globals, "message" |), "caller" |); - M.get_field (| M.get_name (| globals, "message" |), "current_target" |); - M.get_field (| M.get_name (| globals, "message" |), "value" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let evm := @@ -580,22 +370,6 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "evm" |), "error" |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "rollback_transaction" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_field (| M.get_name (| globals, "env" |), "transient_storage" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "commit_transaction" |), make_list [ @@ -608,7 +382,6 @@ Definition process_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) - |) in M.pure Constant.None_)). Definition execute_code : Value.t -> Value.t -> M := @@ -648,5 +421,4 @@ Definition execute_code : Value.t -> Value.t -> M := (* At stmt: unsupported node type: Try *) let _ := M.return_ (| M.get_name (| globals, "evm" |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/vm/memory.v b/CoqOfPython/ethereum/cancun/vm/memory.v index fa8d906..4b107fd 100644 --- a/CoqOfPython/ethereum/cancun/vm/memory.v +++ b/CoqOfPython/ethereum/cancun/vm/memory.v @@ -45,22 +45,7 @@ Definition memory_write : Value.t -> Value.t -> M := Data to write to memory. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) - |) |), + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_)). @@ -86,23 +71,7 @@ Definition memory_read_bytes : Value.t -> Value.t -> M := Data read from memory. " in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |) - |) in + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |) M.pure Constant.None_)). Definition buffer_read : Value.t -> Value.t -> M := @@ -129,25 +98,9 @@ Definition buffer_read : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "right_pad_zero_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |); + M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |) |); M.get_name (| globals, "size" |) ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/alt_bn128.v index 19b83fc..abe4238 100644 --- a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/alt_bn128.v +++ b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/alt_bn128.v @@ -210,15 +210,6 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) in For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ] do let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "i" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -362,15 +353,6 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) in For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ] do let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "i" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -443,24 +425,6 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_eq (| BinOp.mod_ (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "data" |) - ], - make_dict [] - |), - Constant.int 192 - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let result := @@ -509,32 +473,11 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := Constant.int 32, M.get_name (| globals, "j" |) |) - |):BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "i" |), - Constant.int 192 - |), - BinOp.mult (| - Constant.int 32, - BinOp.add (| - M.get_name (| globals, "j" |), - Constant.int 1 - |) - |) |) |) ], make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "value" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -555,17 +498,20 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.call (| - M.get_field (| M.get_name (| globals, "p" |), "mul_by" |), - make_list [ - M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) - ], - make_dict [] - |), M.call (| - M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) |); + Compare.eq (| + M.call (| + M.get_field (| M.get_name (| globals, "p" |), "mul_by" |), + make_list [ + M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) + ], + make_dict [] + |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |); M.get_name (| globals, "OutOfGasError" |) ], make_dict [] @@ -573,87 +519,29 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.call (| - M.get_field (| M.get_name (| globals, "q" |), "mul_by" |), - make_list [ - M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) - ], - make_dict [] - |), M.call (| - M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) |); + Compare.eq (| + M.call (| + M.get_field (| M.get_name (| globals, "q" |), "mul_by" |), + make_list [ + M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) + ], + make_dict [] + |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |); M.get_name (| globals, "OutOfGasError" |) ], make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "p" |), M.call (| - M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_name (| globals, "q" |), M.call (| - M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let result := - BinOp.mult (| - M.get_name (| globals, "result" |), - M.call (| - M.get_name (| globals, "pairing" |), - make_list [ - M.get_name (| globals, "q" |); - M.get_name (| globals, "p" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "result" |), M.call (| - M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), - make_list [ - Constant.int 1 - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign (| - M.get_field (| M.get_name (| globals, "evm" |), "output" |), - M.call (| - M.get_field (| M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 1 - ], - make_dict [] - |), "to_be_bytes32" |), - make_list [], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| diff --git a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/blake2f.v b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/blake2f.v index 5903066..1647d48 100644 --- a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/blake2f.v +++ b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/blake2f.v @@ -55,13 +55,16 @@ Definition blake2f : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "data" |) - ], - make_dict [] - |), Constant.int 213 |); + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 213 + |); M.get_name (| globals, "InvalidParameter" |) ], make_dict [] @@ -96,10 +99,13 @@ Definition blake2f : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.in (| M.get_name (| globals, "f" |), make_list [ - Constant.int 0; - Constant.int 1 - ] |); + Compare.in (| + M.get_name (| globals, "f" |), + make_list [ + Constant.int 0; + Constant.int 1 + ] + |); M.get_name (| globals, "InvalidParameter" |) ], make_dict [] diff --git a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/ecrecover.v index cc351b5..0cbcf16 100644 --- a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/ecrecover.v @@ -188,60 +188,12 @@ Definition ecrecover : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 27 |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 28 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| Constant.int 0, M.get_name (| globals, "r" |) |), - ltac:(M.monadic ( - Compare.gt_e (| M.get_name (| globals, "r" |), M.get_name (| globals, "SECP256K1N" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| Constant.int 0, M.get_name (| globals, "s" |) |), - ltac:(M.monadic ( - Compare.gt_e (| M.get_name (| globals, "s" |), M.get_name (| globals, "SECP256K1N" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: Try *) @@ -252,7 +204,7 @@ Definition ecrecover : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12:Constant.int 32 |) in + |), Constant.int 12 |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/modexp.v index 544949e..3505244 100644 --- a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/modexp.v +++ b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/modexp.v @@ -192,30 +192,6 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_name (| globals, "base_length" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "modulus_length" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign (| - M.get_field (| M.get_name (| globals, "evm" |), "output" |), - M.call (| - M.get_name (| globals, "Bytes" |), - make_list [], - make_dict [] - |) - |) in - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let base := @@ -278,27 +254,6 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "modulus" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign (| - M.get_field (| M.get_name (| globals, "evm" |), "output" |), - BinOp.mult (| - M.call (| - M.get_name (| globals, "Bytes" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |), - M.get_name (| globals, "modulus_length" |) - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| @@ -383,7 +338,6 @@ Definition complexity : Value.t -> Value.t -> M := M.get_name (| globals, "words" |), Constant.int 2 |) - |) in M.pure Constant.None_)). Definition iterations : Value.t -> Value.t -> M := @@ -410,64 +364,7 @@ Definition iterations : Value.t -> Value.t -> M := Number of iterations. " in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.lt_e (| M.get_name (| globals, "exponent_length" |), Constant.int 32 |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "exponent_head" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let count := - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - Compare.lt_e (| M.get_name (| globals, "exponent_length" |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let bit_length := - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.call (| - M.get_field (| M.get_name (| globals, "exponent_head" |), "bit_length" |), - make_list [], - make_dict [] - |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "bit_length" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let bit_length := BinOp.sub - Constant.int 1 - Constant.int 1 in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let count := - M.get_name (| globals, "bit_length" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let length_part := BinOp.mult (| Constant.int 8, @@ -495,17 +392,6 @@ Definition iterations : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "bits_part" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let bits_part := BinOp.sub - Constant.int 1 - Constant.int 1 in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let count := @@ -532,7 +418,6 @@ Definition iterations : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition gas_cost : Value.t -> Value.t -> M := @@ -604,5 +489,4 @@ Definition gas_cost : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/point_evaluation.v b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/point_evaluation.v index d9af97f..741aab6 100644 --- a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/point_evaluation.v +++ b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/point_evaluation.v @@ -58,7 +58,7 @@ Definition BLS_MODULUS : Value.t := M.run ltac:(M.monadic ( )). Definition VERSIONED_HASH_VERSION_KZG : Value.t := M.run ltac:(M.monadic ( - (* At constant: unsupported node type: Constant *) + Constant.bytes "01" )). Definition point_evaluation : Value.t -> Value.t -> M := @@ -79,33 +79,36 @@ Definition point_evaluation : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "data" |) - ], - make_dict [] - |), Constant.int 192 |); + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 192 + |); M.get_name (| globals, "KZGProofError" |) ], make_dict [] |) in let versioned_hash := - M.get_subscript (| M.get_name (| globals, "data" |), (* At expr: unsupported node type: NoneType *):Constant.int 32 |) in + M.get_subscript (| M.get_name (| globals, "data" |), Constant.None_:Constant.int 32 |) in let z := - M.get_subscript (| M.get_name (| globals, "data" |), Constant.int 32:Constant.int 64 |) in + M.get_subscript (| M.get_name (| globals, "data" |), Constant.int 32 |) in let y := - M.get_subscript (| M.get_name (| globals, "data" |), Constant.int 64:Constant.int 96 |) in + M.get_subscript (| M.get_name (| globals, "data" |), Constant.int 64 |) in let commitment := M.call (| M.get_name (| globals, "KZGCommitment" |), make_list [ - M.get_subscript (| M.get_name (| globals, "data" |), Constant.int 96:Constant.int 144 |) + M.get_subscript (| M.get_name (| globals, "data" |), Constant.int 96 |) ], make_dict [] |) in let proof := - M.get_subscript (| M.get_name (| globals, "data" |), Constant.int 144:Constant.int 192 |) in + M.get_subscript (| M.get_name (| globals, "data" |), Constant.int 144 |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -117,13 +120,16 @@ Definition point_evaluation : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.call (| - M.get_name (| globals, "kzg_commitment_to_versioned_hash" |), - make_list [ - M.get_name (| globals, "commitment" |) - ], - make_dict [] - |), M.get_name (| globals, "versioned_hash" |) |); + Compare.eq (| + M.call (| + M.get_name (| globals, "kzg_commitment_to_versioned_hash" |), + make_list [ + M.get_name (| globals, "commitment" |) + ], + make_dict [] + |), + M.get_name (| globals, "versioned_hash" |) + |); M.get_name (| globals, "KZGProofError" |) ], make_dict [] diff --git a/CoqOfPython/ethereum/cancun/vm/runtime.v b/CoqOfPython/ethereum/cancun/vm/runtime.v index 835b46c..2cd7652 100644 --- a/CoqOfPython/ethereum/cancun/vm/runtime.v +++ b/CoqOfPython/ethereum/cancun/vm/runtime.v @@ -67,50 +67,19 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := ], make_dict [] |) in - While Compare.lt (| M.get_name (| globals, "pc" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "code" |) - ], - make_dict [] - |) |) do + While Compare.lt (| + M.get_name (| globals, "pc" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) + |) do (* At stmt: unsupported node type: Try *) let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "current_opcode" |), M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), - make_list [ - M.get_name (| globals, "pc" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - (* At expr: unsupported node type: Compare *), - (* then *) - ltac:(M.monadic ( - let push_data_size := - BinOp.add (| - BinOp.sub (| - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) - |), - Constant.int 1 - |) in - let pc := BinOp.add - M.get_name (| globals, "push_data_size" |) - M.get_name (| globals, "push_data_size" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -121,5 +90,4 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := EndWhile. let _ := M.return_ (| M.get_name (| globals, "valid_jump_destinations" |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/vm/stack.v b/CoqOfPython/ethereum/cancun/vm/stack.v index 42ea42d..ea778df 100644 --- a/CoqOfPython/ethereum/cancun/vm/stack.v +++ b/CoqOfPython/ethereum/cancun/vm/stack.v @@ -49,21 +49,6 @@ Definition pop : Value.t -> Value.t -> M := " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "stack" |) - ], - make_dict [] - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "StackUnderflowError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -72,7 +57,6 @@ Definition pop : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). Definition push : Value.t -> Value.t -> M := @@ -91,21 +75,6 @@ Definition push : Value.t -> Value.t -> M := " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "stack" |) - ], - make_dict [] - |), Constant.int 1024 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "StackOverflowError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -116,5 +85,4 @@ Definition push : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/bloom.v b/CoqOfPython/ethereum/constantinople/bloom.v index 04b5d9f..04650ff 100644 --- a/CoqOfPython/ethereum/constantinople/bloom.v +++ b/CoqOfPython/ethereum/constantinople/bloom.v @@ -72,10 +72,7 @@ Definition add_to_bloom : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |):BinOp.add (| - M.get_name (| globals, "idx" |), - Constant.int 2 - |) |) + M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |) |) ], make_dict [] |), @@ -160,5 +157,4 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/fork.v b/CoqOfPython/ethereum/constantinople/fork.v new file mode 100644 index 0000000..bd55602 --- /dev/null +++ b/CoqOfPython/ethereum/constantinople/fork.v @@ -0,0 +1,2160 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Specification +^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Entry point for the Ethereum specification. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". + +Require ethereum.crypto.elliptic_curve. +Axiom ethereum_crypto_elliptic_curve_SECP256K1N : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.ethash. +Axiom ethereum_ethash_dataset_size : + IsGlobalAlias globals ethereum.ethash.globals "dataset_size". +Axiom ethereum_ethash_generate_cache : + IsGlobalAlias globals ethereum.ethash.globals "generate_cache". +Axiom ethereum_ethash_hashimoto_light : + IsGlobalAlias globals ethereum.ethash.globals "hashimoto_light". + +Require ethereum.exceptions. +Axiom ethereum_exceptions_InvalidBlock : + IsGlobalAlias globals ethereum.exceptions.globals "InvalidBlock". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U64 : + IsGlobalAlias globals base_types.globals "U64". +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_U256_CEIL_VALUE : + IsGlobalAlias globals base_types.globals "U256_CEIL_VALUE". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". + +Require __init__. +Axiom __init___vm : + IsGlobalAlias globals __init__.globals "vm". + +Require blocks. +Axiom blocks_Block : + IsGlobalAlias globals blocks.globals "Block". +Axiom blocks_Header : + IsGlobalAlias globals blocks.globals "Header". +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". +Axiom blocks_Receipt : + IsGlobalAlias globals blocks.globals "Receipt". + +Require bloom. +Axiom bloom_logs_bloom : + IsGlobalAlias globals bloom.globals "logs_bloom". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Require state. +Axiom state_State : + IsGlobalAlias globals state.globals "State". +Axiom state_account_exists_and_is_empty : + IsGlobalAlias globals state.globals "account_exists_and_is_empty". +Axiom state_create_ether : + IsGlobalAlias globals state.globals "create_ether". +Axiom state_destroy_account : + IsGlobalAlias globals state.globals "destroy_account". +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". +Axiom state_increment_nonce : + IsGlobalAlias globals state.globals "increment_nonce". +Axiom state_set_account_balance : + IsGlobalAlias globals state.globals "set_account_balance". +Axiom state_state_root : + IsGlobalAlias globals state.globals "state_root". + +Require transactions. +Axiom transactions_TX_BASE_COST : + IsGlobalAlias globals transactions.globals "TX_BASE_COST". +Axiom transactions_TX_CREATE_COST : + IsGlobalAlias globals transactions.globals "TX_CREATE_COST". +Axiom transactions_TX_DATA_COST_PER_NON_ZERO : + IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_NON_ZERO". +Axiom transactions_TX_DATA_COST_PER_ZERO : + IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_ZERO". +Axiom transactions_Transaction : + IsGlobalAlias globals transactions.globals "Transaction". + +Require trie. +Axiom trie_Trie : + IsGlobalAlias globals trie.globals "Trie". +Axiom trie_root : + IsGlobalAlias globals trie.globals "root". +Axiom trie_trie_set : + IsGlobalAlias globals trie.globals "trie_set". + +Require utils.message. +Axiom utils_message_prepare_message : + IsGlobalAlias globals utils.message.globals "prepare_message". + +Require vm.interpreter. +Axiom vm_interpreter_process_message_call : + IsGlobalAlias globals vm.interpreter.globals "process_message_call". + +Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mult (| + Constant.int 2, + BinOp.pow (| + Constant.int 10, + Constant.int 18 + |) + |) + ], + make_dict [] + |) +)). + +Definition GAS_LIMIT_ADJUSTMENT_FACTOR : Value.t := M.run ltac:(M.monadic ( + Constant.int 1024 +)). + +Definition GAS_LIMIT_MINIMUM : Value.t := M.run ltac:(M.monadic ( + Constant.int 5000 +)). + +Definition MINIMUM_DIFFICULTY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 131072 + ], + make_dict [] + |) +)). + +Definition MAX_OMMER_DEPTH : Value.t := M.run ltac:(M.monadic ( + Constant.int 6 +)). + +Definition BOMB_DELAY_BLOCKS : Value.t := M.run ltac:(M.monadic ( + Constant.int 5000000 +)). + +Definition EMPTY_OMMER_HASH : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_list [] + ], + make_dict [] + |) + ], + make_dict [] + |) +)). + +Definition BlockChain : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition apply_fork : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "old" ] |) in + let _ := Constant.str " + Transforms the state from the previous hard fork (`old`) into the block + chain object for this hard fork and returns it. + + When forks need to implement an irregular state transition, this function + is used to handle the irregularity. See the :ref:`DAO Fork ` for + an example. + + Parameters + ---------- + old : + Previous block chain object. + + Returns + ------- + new : `BlockChain` + Upgraded block chain object for this hard fork. + " in + let _ := M.return_ (| + M.get_name (| globals, "old" |) + M.pure Constant.None_)). + +Definition get_last_256_block_hashes : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "chain" ] |) in + let _ := Constant.str " + Obtain the list of hashes of the previous 256 blocks in order of + increasing block number. + + This function will return less hashes for the first 256 blocks. + + The ``BLOCKHASH`` opcode needs to access the latest hashes on the chain, + therefore this function retrieves them. + + Parameters + ---------- + chain : + History and current state. + + Returns + ------- + recent_block_hashes : `List[Hash32]` + Hashes of the recent 256 blocks in order of increasing block number. + " in + let recent_blocks := + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |) |) in + let _ := + M.pure Constant.None_ + )) |) in + let recent_block_hashes := + make_list [] in + For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_blocks" |) do + let prev_block_hash := + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), + make_list [ + M.get_name (| globals, "prev_block_hash" |) + ], + make_dict [] + |) in + EndFor. + let most_recent_block_hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_field (| M.get_subscript (| M.get_name (| globals, "recent_blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), + make_list [ + M.get_name (| globals, "most_recent_block_hash" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "recent_block_hashes" |) + M.pure Constant.None_)). + +Definition state_transition : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "chain"; "block" ] |) in + let _ := Constant.str " + Attempts to apply a block to an existing block chain. + + All parts of the block's contents need to be verified before being added + to the chain. Blocks are verified by ensuring that the contents of the + block make logical sense with the contents of the parent block. The + information in the block's header must also match the corresponding + information in the block. + + To implement Ethereum, in theory clients are only required to store the + most recent 255 blocks of the chain since as far as execution is + concerned, only those blocks are accessed. Practically, however, clients + should store more blocks to handle reorgs. + + Parameters + ---------- + chain : + History and current state. + block : + Block to apply to `chain`. + " in + let parent_header := + M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) in + let _ := M.call (| + M.get_name (| globals, "validate_header" |), + make_list [ + M.get_field (| M.get_name (| globals, "block" |), "header" |); + M.get_name (| globals, "parent_header" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "validate_ommers" |), + make_list [ + M.get_field (| M.get_name (| globals, "block" |), "ommers" |); + M.get_field (| M.get_name (| globals, "block" |), "header" |); + M.get_name (| globals, "chain" |) + ], + make_dict [] + |) in + let apply_body_output := + M.call (| + M.get_name (| globals, "apply_body" |), + make_list [ + M.get_field (| M.get_name (| globals, "chain" |), "state" |); + M.call (| + M.get_name (| globals, "get_last_256_block_hashes" |), + make_list [ + M.get_name (| globals, "chain" |) + ], + make_dict [] + |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "coinbase" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "number" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "gas_limit" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "timestamp" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "difficulty" |); + M.get_field (| M.get_name (| globals, "block" |), "transactions" |); + M.get_field (| M.get_name (| globals, "block" |), "ommers" |); + M.get_field (| M.get_name (| globals, "chain" |), "chain_id" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_gas_used" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "gas_used" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "transactions_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "transactions_root" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "state_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "state_root" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "receipt_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "receipt_root" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_logs_bloom" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "bloom" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), "append" |), + make_list [ + M.get_name (| globals, "block" |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition validate_header : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header"; "parent_header" ] |) in + let _ := Constant.str " + Verifies a block header. + + In order to consider a block's header valid, the logic for the + quantities in the header should match the logic for the block itself. + For example the header timestamp should be greater than the block's parent + timestamp because the block was created *after* the parent block. + Additionally, the block's number should be directly following the parent + block's number since it is the next block in the sequence. + + Parameters + ---------- + header : + Header to check for correctness. + parent_header : + Parent Header of the header to check for correctness + " in + let parent_has_ommers := + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "parent_header" |), "ommers_hash" |), + M.get_name (| globals, "EMPTY_OMMER_HASH" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt (| + M.get_field (| M.get_name (| globals, "header" |), "timestamp" |), + M.get_field (| M.get_name (| globals, "parent_header" |), "timestamp" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "number" |), + BinOp.add (| + M.get_field (| M.get_name (| globals, "parent_header" |), "number" |), + Constant.int 1 + |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + M.call (| + M.get_name (| globals, "check_gas_limit" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "gas_limit" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "gas_limit" |) + ], + make_dict [] + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) + ], + make_dict [] + |), + Constant.int 32 + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let block_difficulty := + M.call (| + M.get_name (| globals, "calculate_block_difficulty" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "number" |); + M.get_field (| M.get_name (| globals, "header" |), "timestamp" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "timestamp" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "difficulty" |); + M.get_name (| globals, "parent_has_ommers" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "difficulty" |), + M.get_name (| globals, "block_difficulty" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let block_parent_hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "parent_header" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |), + M.get_name (| globals, "block_parent_hash" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "validate_proof_of_work" |), + make_list [ + M.get_name (| globals, "header" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header" ] |) in + let _ := Constant.str " + Generate rlp hash of the header which is to be used for Proof-of-Work + verification. + + In other words, the PoW artefacts `mix_digest` and `nonce` are ignored + while calculating this hash. + + A particular PoW is valid for a single hash, that hash is computed by + this function. The `nonce` and `mix_digest` are omitted from this hash + because they are being changed by miners in their search for a sufficient + proof-of-work. + + Parameters + ---------- + header : + The header object for which the hash is to be generated. + + Returns + ------- + hash : `Hash32` + The PoW valid rlp hash of the passed in header. + " in + let header_data_without_pow_artefacts := + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |); + M.get_field (| M.get_name (| globals, "header" |), "ommers_hash" |); + M.get_field (| M.get_name (| globals, "header" |), "coinbase" |); + M.get_field (| M.get_name (| globals, "header" |), "state_root" |); + M.get_field (| M.get_name (| globals, "header" |), "transactions_root" |); + M.get_field (| M.get_name (| globals, "header" |), "receipt_root" |); + M.get_field (| M.get_name (| globals, "header" |), "bloom" |); + M.get_field (| M.get_name (| globals, "header" |), "difficulty" |); + M.get_field (| M.get_name (| globals, "header" |), "number" |); + M.get_field (| M.get_name (| globals, "header" |), "gas_limit" |); + M.get_field (| M.get_name (| globals, "header" |), "gas_used" |); + M.get_field (| M.get_name (| globals, "header" |), "timestamp" |); + M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) + ] in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "header_data_without_pow_artefacts" |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition validate_proof_of_work : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header" ] |) in + let _ := Constant.str " + Validates the Proof of Work constraints. + + In order to verify that a miner's proof-of-work is valid for a block, a + ``mix-digest`` and ``result`` are calculated using the ``hashimoto_light`` + hash function. The mix digest is a hash of the header and the nonce that + is passed through and it confirms whether or not proof-of-work was done + on the correct block. The result is the actual hash value of the block. + + Parameters + ---------- + header : + Header of interest. + " in + let header_hash := + M.call (| + M.get_name (| globals, "generate_header_hash_for_pow" |), + make_list [ + M.get_name (| globals, "header" |) + ], + make_dict [] + |) in + let cache := + M.call (| + M.get_name (| globals, "generate_cache" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "number" |) + ], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "mix_digest" |); M.get_name (| globals, "result" |) ], + M.call (| + M.get_name (| globals, "hashimoto_light" |), + make_list [ + M.get_name (| globals, "header_hash" |); + M.get_field (| M.get_name (| globals, "header" |), "nonce" |); + M.get_name (| globals, "cache" |); + M.call (| + M.get_name (| globals, "dataset_size" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "number" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_name (| globals, "mix_digest" |), + M.get_field (| M.get_name (| globals, "header" |), "mix_digest" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "result" |) + ], + make_dict [] + |), + BinOp.floor_div (| + M.get_name (| globals, "U256_CEIL_VALUE" |), + M.get_field (| M.get_name (| globals, "header" |), "difficulty" |) + |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition check_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx"; "gas_available"; "chain_id" ] |) in + let _ := Constant.str " + Check if the transaction is includable in the block. + + Parameters + ---------- + tx : + The transaction. + gas_available : + The gas remaining in the block. + chain_id : + The ID of the current chain. + + Returns + ------- + sender_address : + The sender of the transaction. + + Raises + ------ + InvalidBlock : + If the transaction is not includable. + " in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_name (| globals, "gas_available" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let sender_address := + M.call (| + M.get_name (| globals, "recover_sender" |), + make_list [ + M.get_name (| globals, "chain_id" |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "sender_address" |) + M.pure Constant.None_)). + +Definition make_receipt : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx"; "error"; "cumulative_gas_used"; "logs" ] |) in + let _ := Constant.str " + Make the receipt for a transaction that was executed. + + Parameters + ---------- + tx : + The executed transaction. + error : + Error in the top level frame of the transaction, if any. + cumulative_gas_used : + The total gas used so far in the block after the transaction was + executed. + logs : + The logs produced by the transaction. + + Returns + ------- + receipt : + The receipt for the transaction. + " in + let receipt := + M.call (| + M.get_name (| globals, "Receipt" |), + make_list [], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "receipt" |) + M.pure Constant.None_)). + +Definition ApplyBodyOutput : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition apply_body : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "block_hashes"; "coinbase"; "block_number"; "block_gas_limit"; "block_time"; "block_difficulty"; "transactions"; "ommers"; "chain_id" ] |) in + let _ := Constant.str " + Executes a block. + + Many of the contents of a block are stored in data structures called + tries. There is a transactions trie which is similar to a ledger of the + transactions stored in the current block. There is also a receipts trie + which stores the results of executing a transaction, like the post state + and gas used. This function creates and executes the block that is to be + added to the chain. + + Parameters + ---------- + state : + Current account state. + block_hashes : + List of hashes of the previous 256 blocks in the order of + increasing block number. + coinbase : + Address of account which receives block reward and transaction fees. + block_number : + Position of the block within the chain. + block_gas_limit : + Initial amount of gas available for execution in this block. + block_time : + Time the block was produced, measured in seconds since the epoch. + block_difficulty : + Difficulty of the block. + transactions : + Transactions included in the block. + ommers : + Headers of ancestor blocks which are not direct parents (formerly + uncles.) + chain_id : + ID of the executing chain. + + Returns + ------- + apply_body_output : `ApplyBodyOutput` + Output of applying the block body to the state. + " in + let gas_available := + M.get_name (| globals, "block_gas_limit" |) in +(* At stmt: unsupported node type: AnnAssign *) +(* At stmt: unsupported node type: AnnAssign *) +(* At stmt: unsupported node type: AnnAssign *) + For make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "tx" |) ] in M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "transactions" |) + ], + make_dict [] + |) do + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "transactions_trie" |); + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "i" |) + ], + make_dict [] + |) + ], + make_dict [] + |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) in + let sender_address := + M.call (| + M.get_name (| globals, "check_transaction" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "gas_available" |); + M.get_name (| globals, "chain_id" |) + ], + make_dict [] + |) in + let env := + M.call (| + M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |); M.get_name (| globals, "error" |) ], + M.call (| + M.get_name (| globals, "process_transaction" |), + make_list [ + M.get_name (| globals, "env" |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) in + let gas_available := BinOp.sub + M.get_name (| globals, "gas_used" |) + M.get_name (| globals, "gas_used" |) in + let receipt := + M.call (| + M.get_name (| globals, "make_receipt" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "error" |); + BinOp.sub (| + M.get_name (| globals, "block_gas_limit" |), + M.get_name (| globals, "gas_available" |) + |); + M.get_name (| globals, "logs" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "receipts_trie" |); + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "i" |) + ], + make_dict [] + |) + ], + make_dict [] + |); + M.get_name (| globals, "receipt" |) + ], + make_dict [] + |) in + let block_logs := BinOp.add + M.get_name (| globals, "logs" |) + M.get_name (| globals, "logs" |) in + EndFor. + let _ := M.call (| + M.get_name (| globals, "pay_rewards" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "block_number" |); + M.get_name (| globals, "coinbase" |); + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |) in + let block_gas_used := + BinOp.sub (| + M.get_name (| globals, "block_gas_limit" |), + M.get_name (| globals, "gas_available" |) + |) in + let block_logs_bloom := + M.call (| + M.get_name (| globals, "logs_bloom" |), + make_list [ + M.get_name (| globals, "block_logs" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ApplyBodyOutput" |), + make_list [ + M.get_name (| globals, "block_gas_used" |); + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_name (| globals, "transactions_trie" |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_name (| globals, "receipts_trie" |) + ], + make_dict [] + |); + M.get_name (| globals, "block_logs_bloom" |); + M.call (| + M.get_name (| globals, "state_root" |), + make_list [ + M.get_name (| globals, "state" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition validate_ommers : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "ommers"; "block_header"; "chain" ] |) in + let _ := Constant.str " + Validates the ommers mentioned in the block. + + An ommer block is a block that wasn't canonically added to the + blockchain because it wasn't validated as fast as the canonical block + but was mined at the same time. + + To be considered valid, the ommers must adhere to the rules defined in + the Ethereum protocol. The maximum amount of ommers is 2 per block and + there cannot be duplicate ommers in a block. Many of the other ommer + constraints are listed in the in-line comments of this function. + + Parameters + ---------- + ommers : + List of ommers mentioned in the current block. + block_header: + The header of current block. + chain : + History and current state. + " in + let block_hash := + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "block_header" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + M.get_field (| M.get_name (| globals, "block_header" |), "ommers_hash" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.and (| + Compare.lt_e (| + Constant.int 1, + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |), + ltac:(M.monadic ( + Compare.lt (| + M.get_field (| M.get_name (| globals, "ommer" |), "number" |), + M.get_field (| M.get_name (| globals, "block_header" |), "number" |) + |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let ommer_parent_header := + M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), BinOp.sub (| + UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) |), + Constant.int 1 + |) |), "header" |) in + let _ := M.call (| + M.get_name (| globals, "validate_header" |), + make_list [ + M.get_name (| globals, "ommer" |); + M.get_name (| globals, "ommer_parent_header" |) + ], + make_dict [] + |) in + EndFor. + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + Constant.int 2 + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let ommers_hashes := + (* At expr: unsupported node type: ListComp *) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers_hashes" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_name (| globals, "set" |), + make_list [ + M.get_name (| globals, "ommers_hashes" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let recent_canonical_blocks := + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| BinOp.add (| + M.get_name (| globals, "MAX_OMMER_DEPTH" |), + Constant.int 1 + |) |) |) in + let recent_canonical_block_hashes := + (* At expr: unsupported node type: SetComp *) in +(* At stmt: unsupported node type: AnnAssign *) + For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_canonical_blocks" |) do + let recent_ommers_hashes := + M.call (| + M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), + make_list [ + (* At expr: unsupported node type: SetComp *) + ], + make_dict [] + |) in + EndFor. + For make_tuple [ M.get_name (| globals, "ommer_index" |); M.get_name (| globals, "ommer" |) ] in M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |) do + let ommer_hash := + M.get_subscript (| M.get_name (| globals, "ommers_hashes" |), M.get_name (| globals, "ommer_index" |) |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_eq (| + M.get_name (| globals, "ommer_hash" |), + M.get_name (| globals, "block_hash" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_in (| + M.get_name (| globals, "ommer_hash" |), + M.get_name (| globals, "recent_canonical_block_hashes" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_in (| + M.get_name (| globals, "ommer_hash" |), + M.get_name (| globals, "recent_ommers_hashes" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let ommer_age := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.and (| + Compare.lt_e (| + Constant.int 1, + M.get_name (| globals, "ommer_age" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_name (| globals, "ommer_age" |), + M.get_name (| globals, "MAX_OMMER_DEPTH" |) + |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.in (| + M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), + M.get_name (| globals, "recent_canonical_block_hashes" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), + M.get_field (| M.get_name (| globals, "block_header" |), "parent_hash" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_)). + +Definition pay_rewards : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "block_number"; "coinbase"; "ommers" ] |) in + let _ := Constant.str " + Pay rewards to the block miner as well as the ommers miners. + + The miner of the canonical block is rewarded with the predetermined + block reward, ``BLOCK_REWARD``, plus a variable award based off of the + number of ommer blocks that were mined around the same time, and included + in the canonical block's header. An ommer block is a block that wasn't + added to the canonical blockchain because it wasn't validated as fast as + the accepted block but was mined at the same time. Although not all blocks + that are mined are added to the canonical chain, miners are still paid a + reward for their efforts. This reward is called an ommer reward and is + calculated based on the number associated with the ommer block that they + mined. + + Parameters + ---------- + state : + Current account state. + block_number : + Position of the block within the chain. + coinbase : + Address of account which receives block reward and transaction fees. + ommers : + List of ommers mentioned in the current block. + " in + let miner_reward := + BinOp.add (| + M.get_name (| globals, "BLOCK_REWARD" |), + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + BinOp.floor_div (| + M.get_name (| globals, "BLOCK_REWARD" |), + Constant.int 32 + |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "create_ether" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "coinbase" |); + M.get_name (| globals, "miner_reward" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do + let ommer_age := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "block_number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) + ], + make_dict [] + |) in + let ommer_miner_reward := + BinOp.floor_div (| + BinOp.mult (| + BinOp.sub (| + Constant.int 8, + M.get_name (| globals, "ommer_age" |) + |), + M.get_name (| globals, "BLOCK_REWARD" |) + |), + Constant.int 8 + |) in + let _ := M.call (| + M.get_name (| globals, "create_ether" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_field (| M.get_name (| globals, "ommer" |), "coinbase" |); + M.get_name (| globals, "ommer_miner_reward" |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_)). + +Definition process_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "env"; "tx" ] |) in + let _ := Constant.str " + Execute a transaction against the provided environment. + + This function processes the actions needed to execute a transaction. + It decrements the sender's account after calculating the gas fee and + refunds them the proper amount after execution. Calling contracts, + deploying code, and incrementing nonces are all examples of actions that + happen within this function or from a call made within this function. + + Accounts that are marked for deletion are processed and destroyed after + execution. + + Parameters + ---------- + env : + Environment for the Ethereum Virtual Machine. + tx : + Transaction to execute. + + Returns + ------- + gas_left : `ethereum.base_types.U256` + Remaining gas after execution. + logs : `Tuple[ethereum.blocks.Log, ...]` + Logs generated during execution. + " in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + M.call (| + M.get_name (| globals, "validate_transaction" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let sender := + M.get_field (| M.get_name (| globals, "env" |), "origin" |) in + let sender_account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |) in + let gas_fee := + BinOp.mult (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "sender_account" |), "nonce" |), + M.get_field (| M.get_name (| globals, "tx" |), "nonce" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt_e (| + M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), + BinOp.add (| + M.get_name (| globals, "gas_fee" |), + M.get_field (| M.get_name (| globals, "tx" |), "value" |) + |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "sender_account" |), "code" |), + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [], + make_dict [] + |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let gas := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.call (| + M.get_name (| globals, "calculate_intrinsic_cost" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) in + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |) in + let sender_balance_after_gas_fee := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), + M.get_name (| globals, "gas_fee" |) + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |); + M.get_name (| globals, "sender_balance_after_gas_fee" |) + ], + make_dict [] + |) in + let message := + M.call (| + M.get_name (| globals, "prepare_message" |), + make_list [ + M.get_name (| globals, "sender" |); + M.get_field (| M.get_name (| globals, "tx" |), "to" |); + M.get_field (| M.get_name (| globals, "tx" |), "value" |); + M.get_field (| M.get_name (| globals, "tx" |), "data" |); + M.get_name (| globals, "gas" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let output := + M.call (| + M.get_name (| globals, "process_message_call" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let gas_used := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "output" |), "gas_left" |) + |) in + let gas_refund := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + BinOp.floor_div (| + M.get_name (| globals, "gas_used" |), + Constant.int 2 + |); + M.get_field (| M.get_name (| globals, "output" |), "refund_counter" |) + ], + make_dict [] + |) in + let gas_refund_amount := + BinOp.mult (| + BinOp.add (| + M.get_field (| M.get_name (| globals, "output" |), "gas_left" |), + M.get_name (| globals, "gas_refund" |) + |), + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) + |) in + let transaction_fee := + BinOp.mult (| + BinOp.sub (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "output" |), "gas_left" |) + |), + M.get_name (| globals, "gas_refund" |) + |), + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) + |) in + let total_gas_used := + BinOp.sub (| + M.get_name (| globals, "gas_used" |), + M.get_name (| globals, "gas_refund" |) + |) in + let sender_balance_after_refund := + BinOp.add (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |), "balance" |), + M.get_name (| globals, "gas_refund_amount" |) + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |); + M.get_name (| globals, "sender_balance_after_refund" |) + ], + make_dict [] + |) in + let coinbase_balance_after_mining_fee := + BinOp.add (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |), "balance" |), + M.get_name (| globals, "transaction_fee" |) + |) in + let _ := + let _ := + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "accounts_to_delete" |) do + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + EndFor. + For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "touched_accounts" |) do + let _ := + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.return_ (| + make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |); M.get_field (| M.get_name (| globals, "output" |), "error" |) ] + M.pure Constant.None_)). + +Definition validate_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Verifies a transaction. + + The gas in a transaction gets used to pay for the intrinsic cost of + operations, therefore if there is insufficient gas then it would not + be possible to execute a transaction and it will be declared invalid. + + Additionally, the nonce of a transaction must not equal or exceed the + limit defined in `EIP-2681 `_. + In practice, defining the limit as ``2**64-1`` has no impact because + sending ``2**64-1`` transactions is improbable. It's not strictly + impossible though, ``2**64-1`` transactions is the entire capacity of the + Ethereum blockchain at 2022 gas limits for a little over 22 years. + + Parameters + ---------- + tx : + Transaction to validate. + + Returns + ------- + verified : `bool` + True if the transaction can be executed, or False otherwise. + " in + let _ := M.return_ (| + BoolOp.and (| + Compare.lt_e (| + M.call (| + M.get_name (| globals, "calculate_intrinsic_cost" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |), + M.get_field (| M.get_name (| globals, "tx" |), "gas" |) + |), + ltac:(M.monadic ( + Compare.lt (| + M.get_field (| M.get_name (| globals, "tx" |), "nonce" |), + BinOp.sub (| + BinOp.pow (| + Constant.int 2, + Constant.int 64 + |), + Constant.int 1 + |) + |) + )) + |) + M.pure Constant.None_)). + +Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Calculates the gas that is charged before execution is started. + + The intrinsic cost of the transaction is charged before execution has + begun. Functions/operations in the EVM cost money to execute so this + intrinsic cost is for the operations that need to be paid for as part of + the transaction. Data transfer, for example, is part of this intrinsic + cost. It costs ether to send data over the wire and that ether is + accounted for in the intrinsic cost calculated in this function. This + intrinsic cost must be calculated and paid for before execution in order + for all operations to be implemented. + + Parameters + ---------- + tx : + Transaction to compute the intrinsic cost of. + + Returns + ------- + verified : `ethereum.base_types.Uint` + The intrinsic cost of the transaction. + " in + let data_cost := + Constant.int 0 in + For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do + let _ := + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + M.pure Constant.None_ + )) |) in + EndFor. + let _ := + let create_cost := + Constant.int 0 in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "TX_BASE_COST" |), + M.get_name (| globals, "data_cost" |) + |), + M.get_name (| globals, "create_cost" |) + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition recover_sender : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "chain_id"; "tx" ] |) in + let _ := Constant.str " + Extracts the sender address from a transaction. + + The v, r, and s values are the three parts that make up the signature + of a transaction. In order to recover the sender of a transaction the two + components needed are the signature (``v``, ``r``, and ``s``) and the + signing hash of the transaction. The sender's public key can be obtained + with these two values and therefore the sender address can be retrieved. + + Parameters + ---------- + tx : + Transaction of interest. + chain_id : + ID of the executing chain. + + Returns + ------- + sender : `ethereum.fork_types.Address` + The address of the account that signed the transaction. + " in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "v" |); M.get_name (| globals, "r" |); M.get_name (| globals, "s" |) ], + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "v" |); M.get_field (| M.get_name (| globals, "tx" |), "r" |); M.get_field (| M.get_name (| globals, "tx" |), "s" |) ] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.and (| + Compare.lt (| + Constant.int 0, + M.get_name (| globals, "r" |) + |), + ltac:(M.monadic ( + Compare.lt (| + M.get_name (| globals, "r" |), + M.get_name (| globals, "SECP256K1N" |) + |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.and (| + Compare.lt (| + Constant.int 0, + M.get_name (| globals, "s" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_name (| globals, "s" |), + BinOp.floor_div (| + M.get_name (| globals, "SECP256K1N" |), + Constant.int 2 + |) + |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.or (| + Compare.eq (| + M.get_name (| globals, "v" |), + BinOp.add (| + Constant.int 35, + BinOp.mult (| + M.get_name (| globals, "chain_id" |), + Constant.int 2 + |) + |) + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "v" |), + BinOp.add (| + Constant.int 36, + BinOp.mult (| + M.get_name (| globals, "chain_id" |), + Constant.int 2 + |) + |) + |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + BinOp.sub (| + BinOp.sub (| + M.get_name (| globals, "v" |), + Constant.int 35 + |), + BinOp.mult (| + M.get_name (| globals, "chain_id" |), + Constant.int 2 + |) + |); + M.call (| + M.get_name (| globals, "signing_hash_155" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "chain_id" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_subscript (| M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), Constant.int 12 |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition signing_hash_pre155 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Compute the hash of a transaction used in a legacy (pre EIP 155) signature. + + Parameters + ---------- + tx : + Transaction of interest. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the transaction. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "nonce" |); M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |); M.get_field (| M.get_name (| globals, "tx" |), "gas" |); M.get_field (| M.get_name (| globals, "tx" |), "to" |); M.get_field (| M.get_name (| globals, "tx" |), "value" |); M.get_field (| M.get_name (| globals, "tx" |), "data" |) ] + ], + make_dict [] + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition signing_hash_155 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx"; "chain_id" ] |) in + let _ := Constant.str " + Compute the hash of a transaction used in a EIP 155 signature. + + Parameters + ---------- + tx : + Transaction of interest. + chain_id : + The id of the current chain. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the transaction. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "nonce" |); M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |); M.get_field (| M.get_name (| globals, "tx" |), "gas" |); M.get_field (| M.get_name (| globals, "tx" |), "to" |); M.get_field (| M.get_name (| globals, "tx" |), "value" |); M.get_field (| M.get_name (| globals, "tx" |), "data" |); M.get_name (| globals, "chain_id" |); M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) ] + ], + make_dict [] + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition compute_header_hash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header" ] |) in + let _ := Constant.str " + Computes the hash of a block header. + + The header hash of a block is the canonical hash that is used to refer + to a specific block and completely distinguishes a block from another. + + ``keccak256`` is a function that produces a 256 bit hash of any input. + It also takes in any number of bytes as an input and produces a single + hash for them. A hash is a completely unique output for a single input. + So an input corresponds to one unique hash that can be used to identify + the input exactly. + + Prior to using the ``keccak256`` hash function, the header must be + encoded using the Recursive-Length Prefix. See :ref:`rlp`. + RLP encoding the header converts it into a space-efficient format that + allows for easy transfer of data between nodes. The purpose of RLP is to + encode arbitrarily nested arrays of binary data, and RLP is the primary + encoding method used to serialize objects in Ethereum's execution layer. + The only purpose of RLP is to encode structure; encoding specific data + types (e.g. strings, floats) is left up to higher-order protocols. + + Parameters + ---------- + header : + Header of interest. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the header. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "header" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition check_gas_limit : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "gas_limit"; "parent_gas_limit" ] |) in + let _ := Constant.str " + Validates the gas limit for a block. + + The bounds of the gas limit, ``max_adjustment_delta``, is set as the + quotient of the parent block's gas limit and the + ``GAS_LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is + passed through as a parameter is greater than or equal to the *sum* of + the parent's gas and the adjustment delta then the limit for gas is too + high and fails this function's check. Similarly, if the limit is less + than or equal to the *difference* of the parent's gas and the adjustment + delta *or* the predefined ``GAS_LIMIT_MINIMUM`` then this function's + check fails because the gas limit doesn't allow for a sufficient or + reasonable amount of gas to be used on a block. + + Parameters + ---------- + gas_limit : + Gas limit to validate. + + parent_gas_limit : + Gas limit of the parent block. + + Returns + ------- + check : `bool` + True if gas limit constraints are satisfied, False otherwise. + " in + let max_adjustment_delta := + BinOp.floor_div (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) + |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + Constant.bool true + M.pure Constant.None_)). + +Definition calculate_block_difficulty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "block_number"; "block_timestamp"; "parent_timestamp"; "parent_difficulty"; "parent_has_ommers" ] |) in + let _ := Constant.str " + Computes difficulty of a block using its header and parent header. + + The difficulty is determined by the time the block was created after its + parent. The ``offset`` is calculated using the parent block's difficulty, + ``parent_difficulty``, and the timestamp between blocks. This offset is + then added to the parent difficulty and is stored as the ``difficulty`` + variable. If the time between the block and its parent is too short, the + offset will result in a positive number thus making the sum of + ``parent_difficulty`` and ``offset`` to be a greater value in order to + avoid mass forking. But, if the time is long enough, then the offset + results in a negative value making the block less difficult than + its parent. + + The base standard for a block's difficulty is the predefined value + set for the genesis block since it has no parent. So, a block + can't be less difficult than the genesis block, therefore each block's + difficulty is set to the maximum value between the calculated + difficulty and the ``GENESIS_DIFFICULTY``. + + Parameters + ---------- + block_number : + Block number of the block. + block_timestamp : + Timestamp of the block. + parent_timestamp : + Timestamp of the parent block. + parent_difficulty : + difficulty of the parent block. + parent_has_ommers: + does the parent have ommers. + + Returns + ------- + difficulty : `ethereum.base_types.Uint` + Computed difficulty for a block. + " in + let offset := + BinOp.mult (| + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "parent_difficulty" |) + ], + make_dict [] + |), + Constant.int 2048 + |), + M.call (| + M.get_name (| globals, "max" |), + make_list [ + BinOp.sub (| + (* if *) +M.if_then_else (| + M.get_name (| globals, "parent_has_ommers" |), +(* then *) +ltac:(M.monadic ( +Constant.int 2, + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "block_timestamp" |), + M.get_name (| globals, "parent_timestamp" |) + |) + ], + make_dict [] + |), + Constant.int 9 + |) + |); + UnOp.sub (| Constant.int 99 |) + ], + make_dict [] + |) + |) in + let difficulty := + BinOp.add (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "parent_difficulty" |) + ], + make_dict [] + |), + M.get_name (| globals, "offset" |) + |) in + let num_bomb_periods := + BinOp.sub (| + BinOp.floor_div (| + BinOp.sub (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "block_number" |) + ], + make_dict [] + |), + M.get_name (| globals, "BOMB_DELAY_BLOCKS" |) + |), + Constant.int 100000 + |), + Constant.int 2 + |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "max" |), + make_list [ + M.get_name (| globals, "difficulty" |); + M.get_name (| globals, "MINIMUM_DIFFICULTY" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/fork_types.v b/CoqOfPython/ethereum/constantinople/fork_types.v index d12953d..5c7dac3 100644 --- a/CoqOfPython/ethereum/constantinople/fork_types.v +++ b/CoqOfPython/ethereum/constantinople/fork_types.v @@ -98,5 +98,4 @@ Definition encode_account : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/state.v b/CoqOfPython/ethereum/constantinople/state.v index 53b3837..c5b604e 100644 --- a/CoqOfPython/ethereum/constantinople/state.v +++ b/CoqOfPython/ethereum/constantinople/state.v @@ -123,13 +123,7 @@ Definition begin_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) ], make_dict [] - |); {M.get_name (| globals, "k" |): M.call (| - M.get_name (| globals, "copy_trie" |), - make_list [ - M.get_name (| globals, "t" |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)} ] + |); (* At expr: unsupported node type: DictComp *) ] ], make_dict [] |) in @@ -207,27 +201,8 @@ Definition get_account : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "account" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "account" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_ACCOUNT" |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -262,7 +237,6 @@ Definition get_account_optional : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "account" |) - |) in M.pure Constant.None_)). Definition set_account : Value.t -> Value.t -> M := @@ -342,15 +316,6 @@ Definition destroy_storage : Value.t -> Value.t -> M := Address of account whose storage is to be deleted. " in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -385,23 +350,6 @@ Definition get_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let value := @@ -423,7 +371,6 @@ Definition get_storage : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "value" |) - |) in M.pure Constant.None_)). Definition set_storage : Value.t -> Value.t -> M := @@ -444,14 +391,17 @@ Definition set_storage : Value.t -> Value.t -> M := value : `U256` Value to set at the key. " in - let _ := M.assert (| Compare.is_not (| M.call (| - M.get_name (| globals, "trie_get" |), - make_list [ - M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), Constant.None_ |) |) in + let _ := M.assert (| Compare.is_not (| + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + Constant.None_ + |) |) in let trie := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), @@ -461,24 +411,6 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let trie := - M.call (| - M.get_name (| globals, "Trie" |), - make_list [], - make_dict [] - |) in - let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), - M.get_name (| globals, "trie" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -491,15 +423,6 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), {} |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -524,26 +447,8 @@ Definition storage_root : Value.t -> Value.t -> M := " in let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "root" |), - make_list [ - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_TRIE_ROOT" |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -574,7 +479,6 @@ Definition state_root : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition account_exists : Value.t -> Value.t -> M := @@ -596,15 +500,17 @@ Definition account_exists : Value.t -> Value.t -> M := True if account exists in the state trie, False otherwise " in let _ := M.return_ (| - Compare.is_not (| M.call (| - M.get_name (| globals, "get_account_optional" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), Constant.None_ |) - |) in + Compare.is_not (| + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + Constant.None_ + |) M.pure Constant.None_)). Definition account_has_code_or_nonce : Value.t -> Value.t -> M := @@ -637,18 +543,23 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := |) in let _ := M.return_ (| BoolOp.or (| - Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( - Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |) + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |) )) |) - |) in M.pure Constant.None_)). Definition is_account_empty : Value.t -> Value.t -> M := @@ -681,23 +592,31 @@ Definition is_account_empty : Value.t -> Value.t -> M := |) in let _ := M.return_ (| BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |), ltac:(M.monadic ( - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "balance" |), + Constant.int 0 + |) )) |) )) |) - |) in M.pure Constant.None_)). Definition account_exists_and_is_empty : Value.t -> Value.t -> M := @@ -731,28 +650,39 @@ Definition account_exists_and_is_empty : Value.t -> Value.t -> M := |) in let _ := M.return_ (| BoolOp.and (| - Compare.is_not (| M.get_name (| globals, "account" |), Constant.None_ |), + Compare.is_not (| + M.get_name (| globals, "account" |), + Constant.None_ + |), ltac:(M.monadic ( BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |), ltac:(M.monadic ( - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "balance" |), + Constant.int 0 + |) )) |) )) |) )) |) - |) in M.pure Constant.None_)). Definition is_account_alive : Value.t -> Value.t -> M := @@ -783,36 +713,33 @@ Definition is_account_alive : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "account" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.bool false - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| UnOp.not (| BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |), ltac:(M.monadic ( - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "balance" |), + Constant.int 0 + |) )) |) )) |) |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -920,30 +847,6 @@ Definition touch_account : Value.t -> Value.t -> M := The address of the account that need to initialised. " in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "account_exists" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "set_account" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |); - M.get_name (| globals, "EMPTY_ACCOUNT" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/trie.v b/CoqOfPython/ethereum/constantinople/trie.v index 7210f99..f333170 100644 --- a/CoqOfPython/ethereum/constantinople/trie.v +++ b/CoqOfPython/ethereum/constantinople/trie.v @@ -202,96 +202,16 @@ Definition encode_internal_node : Value.t -> Value.t -> M := " in (* At stmt: unsupported node type: AnnAssign *) let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "node" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let unencoded := - (* At constant: unsupported node type: Constant *) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "LeafNode" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let unencoded := - make_tuple [ M.call (| - M.get_name (| globals, "nibble_list_to_compact" |), - make_list [ - M.get_field (| M.get_name (| globals, "node" |), "rest_of_key" |); - Constant.bool true - ], - make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "ExtensionNode" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let unencoded := - make_tuple [ M.call (| - M.get_name (| globals, "nibble_list_to_compact" |), - make_list [ - M.get_field (| M.get_name (| globals, "node" |), "key_segment" |); - Constant.bool false - ], - make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "BranchNode" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let unencoded := - BinOp.add (| - M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), - make_list [ - M.get_field (| M.get_name (| globals, "node" |), "value" |) - ] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.call (| + let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ (* At expr: unsupported node type: JoinedStr *) ], make_dict [] - |) |) in + |)) M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -309,23 +229,6 @@ Definition encode_internal_node : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "encoded" |) - ], - make_dict [] - |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "unencoded" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_name (| globals, "keccak256" |), @@ -334,7 +237,6 @@ Definition encode_internal_node : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -348,83 +250,8 @@ Definition encode_node : Value.t -> Value.t -> M := Currently mostly an unimplemented stub. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "storage_root" |), Constant.None_ |) |) in - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "encode_account" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "storage_root" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - make_tuple [ M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "U256" |) ] - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.call (| - M.get_name (| globals, "cast" |), - make_list [ - M.get_field (| M.get_name (| globals, "rlp" |), "RLP" |); - M.get_name (| globals, "node" |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "Bytes" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "node" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "previous_trie" |), "encode_node" |), @@ -434,7 +261,6 @@ Definition encode_node : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -486,7 +312,6 @@ Definition copy_trie : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition trie_set : Value.t -> Value.t -> M := @@ -508,26 +333,6 @@ Definition trie_set : Value.t -> Value.t -> M := Node to insert at `key`. " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "value" |), M.get_field (| M.get_name (| globals, "trie" |), "default" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "key" |), M.get_field (| M.get_name (| globals, "trie" |), "_data" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), M.get_name (| globals, "value" |) @@ -565,7 +370,6 @@ Definition trie_get : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition common_prefix_length : Value.t -> Value.t -> M := @@ -588,28 +392,6 @@ Definition common_prefix_length : Value.t -> Value.t -> M := make_dict [] |) do let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| M.get_name (| globals, "i" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "b" |) - ], - make_dict [] - |) |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "i" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -621,7 +403,6 @@ Definition common_prefix_length : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition nibble_list_to_compact : Value.t -> Value.t -> M := @@ -667,68 +448,6 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| BinOp.mod_ (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |), - Constant.int 2 - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_name (| globals, "compact" |), "append" |), - make_list [ - BinOp.mult (| - Constant.int 16, - BinOp.mult (| - Constant.int 2, - M.get_name (| globals, "is_leaf" |) - |) - |) - ], - make_dict [] - |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 0; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |); - Constant.int 2 - ], - make_dict [] - |) do - let _ := M.call (| - M.get_field (| M.get_name (| globals, "compact" |), "append" |), - make_list [ - BinOp.add (| - BinOp.mult (| - Constant.int 16, - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) - |), - M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) - |) - ], - make_dict [] - |) in - EndFor. - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ @@ -790,7 +509,6 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition bytes_to_nibble_list : Value.t -> Value.t -> M := @@ -868,7 +586,6 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition _prepare_trie : Value.t -> Value.t -> M := @@ -898,45 +615,6 @@ Definition _prepare_trie : Value.t -> Value.t -> M := make_dict [] |) do let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "value" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in - let address := - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in - let encoded_value := - M.call (| - M.get_name (| globals, "encode_node" |), - make_list [ - M.get_name (| globals, "value" |); - M.call (| - M.get_name (| globals, "get_storage_root" |), - make_list [ - M.get_name (| globals, "address" |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let encoded_value := M.call (| M.get_name (| globals, "encode_node" |), @@ -950,29 +628,16 @@ Definition _prepare_trie : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.not_eq (| M.get_name (| globals, "encoded_value" |), (* At constant: unsupported node type: Constant *) |); + Compare.not_eq (| + M.get_name (| globals, "encoded_value" |), + Constant.bytes "" + |); M.get_name (| globals, "AssertionError" |) ], make_dict [] |) in (* At stmt: unsupported node type: AnnAssign *) let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "trie" |), "secured" |), - (* then *) - ltac:(M.monadic ( - let key := - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let key := M.get_name (| globals, "preimage" |) in M.pure Constant.None_ @@ -990,7 +655,6 @@ Definition _prepare_trie : Value.t -> Value.t -> M := EndFor. let _ := M.return_ (| M.get_name (| globals, "mapped" |) - |) in M.pure Constant.None_)). Definition root : Value.t -> Value.t -> M := @@ -1044,41 +708,6 @@ Definition root : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "root_node" |) - ], - make_dict [] - |) - ], - make_dict [] - |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "root_node" |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -1095,7 +724,6 @@ Definition root : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -1122,23 +750,6 @@ Definition patricialize : Value.t -> Value.t -> M := Root node of `obj`. " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "obj" |) - ], - make_dict [] - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.None_ - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let arbitrary_key := @@ -1156,36 +767,10 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "obj" |) - ], - make_dict [] - |), Constant.int 1 |), - (* then *) - ltac:(M.monadic ( - let leaf := - M.call (| - M.get_name (| globals, "LeafNode" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |); - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) - ], - make_dict [] - |) in - let _ := M.return_ (| - M.get_name (| globals, "leaf" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let substring := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |) |) in let prefix_length := M.call (| M.get_name (| globals, "len" |), @@ -1204,7 +789,7 @@ Definition patricialize : Value.t -> Value.t -> M := M.get_name (| globals, "common_prefix_length" |), make_list [ M.get_name (| globals, "substring" |); - M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) + M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) ], make_dict [] |) @@ -1212,58 +797,10 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.break (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let prefix := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):BinOp.add (| - M.get_name (| globals, "level" |), - M.get_name (| globals, "prefix_length" |) - |) |) in - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "ExtensionNode" |), - make_list [ - M.get_name (| globals, "prefix" |); - M.call (| - M.get_name (| globals, "encode_internal_node" |), - make_list [ - M.call (| - M.get_name (| globals, "patricialize" |), - make_list [ - M.get_name (| globals, "obj" |); - BinOp.add (| - M.get_name (| globals, "level" |), - M.get_name (| globals, "prefix_length" |) - |) - ], - make_dict [] - |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) @@ -1283,44 +820,9 @@ Definition patricialize : Value.t -> Value.t -> M := |) in EndFor. let value := - (* At constant: unsupported node type: Constant *) in + Constant.bytes "" in For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "key" |) - ], - make_dict [] - |), M.get_name (| globals, "level" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); - make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "AssertionError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let value := - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) @@ -1332,26 +834,9 @@ Definition patricialize : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "BranchNode" |), make_list [ - [M.call (| - M.get_name (| globals, "encode_internal_node" |), - make_list [ - M.call (| - M.get_name (| globals, "patricialize" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "branches" |), M.get_name (| globals, "k" |) |); - BinOp.add (| - M.get_name (| globals, "level" |), - Constant.int 1 - |) - ], - make_dict [] - |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)]; + (* At expr: unsupported node type: ListComp *); M.get_name (| globals, "value" |) ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/utils/address.v b/CoqOfPython/ethereum/constantinople/utils/address.v index a0fd4e2..87c97e6 100644 --- a/CoqOfPython/ethereum/constantinople/utils/address.v +++ b/CoqOfPython/ethereum/constantinople/utils/address.v @@ -70,11 +70,10 @@ Definition to_address : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), make_list [], make_dict [] - |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) + |), UnOp.sub (| Constant.int 20 |) |) ], make_dict [] |) - |) in M.pure Constant.None_)). Definition compute_contract_address : Value.t -> Value.t -> M := @@ -114,7 +113,7 @@ Definition compute_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -132,7 +131,6 @@ Definition compute_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition compute_create2_contract_address : Value.t -> Value.t -> M := @@ -160,7 +158,7 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := BinOp.add (| BinOp.add (| BinOp.add (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "ff", M.get_name (| globals, "address" |) |), M.get_name (| globals, "salt" |) @@ -182,7 +180,7 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -200,5 +198,4 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/utils/hexadecimal.v b/CoqOfPython/ethereum/constantinople/utils/hexadecimal.v index 0e18043..4043ada 100644 --- a/CoqOfPython/ethereum/constantinople/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/constantinople/utils/hexadecimal.v @@ -66,7 +66,6 @@ Definition hex_to_root : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition hex_to_bloom : Value.t -> Value.t -> M := @@ -105,7 +104,6 @@ Definition hex_to_bloom : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition hex_to_address : Value.t -> Value.t -> M := @@ -151,5 +149,4 @@ Definition hex_to_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/utils/message.v b/CoqOfPython/ethereum/constantinople/utils/message.v index efb5e7c..9ef25a3 100644 --- a/CoqOfPython/ethereum/constantinople/utils/message.v +++ b/CoqOfPython/ethereum/constantinople/utils/message.v @@ -88,105 +88,14 @@ Definition prepare_message : Value.t -> Value.t -> M := Items containing contract creation or message call specific data. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "target" |); - M.get_name (| globals, "Bytes0" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let current_target := - M.call (| - M.get_name (| globals, "compute_contract_address" |), - make_list [ - M.get_name (| globals, "caller" |); - BinOp.sub (| - M.get_field (| M.call (| - M.get_name (| globals, "get_account" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "caller" |) - ], - make_dict [] - |), "nonce" |), - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 1 - ], - make_dict [] - |) - |) - ], - make_dict [] - |) in - let msg_data := - M.call (| - M.get_name (| globals, "Bytes" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |) in - let code := - M.get_name (| globals, "data" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "target" |); - M.get_name (| globals, "Address" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let current_target := - M.get_name (| globals, "target" |) in - let msg_data := - M.get_name (| globals, "data" |) in - let code := - M.get_field (| M.call (| - M.get_name (| globals, "get_account" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "target" |) - ], - make_dict [] - |), "code" |) in - let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "code_address" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let code_address := - M.get_name (| globals, "target" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.call (| + let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "Target must be address or empty bytes" ], make_dict [] - |) |) in + |)) M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -197,5 +106,4 @@ Definition prepare_message : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/vm/__init__.v b/CoqOfPython/ethereum/constantinople/vm/__init__.v index 520603e..8859cb4 100644 --- a/CoqOfPython/ethereum/constantinople/vm/__init__.v +++ b/CoqOfPython/ethereum/constantinople/vm/__init__.v @@ -143,28 +143,6 @@ Definition incorporate_child_on_success : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); - M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -183,57 +161,9 @@ Definition incorporate_child_on_error : Value.t -> Value.t -> M := The child evm to incorporate. " in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "RIPEMD160_ADDRESS" |), M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), - make_list [ - M.get_name (| globals, "RIPEMD160_ADDRESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |), M.get_name (| globals, "RIPEMD160_ADDRESS" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); - M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), - make_list [ - M.get_name (| globals, "RIPEMD160_ADDRESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign_op (| diff --git a/CoqOfPython/ethereum/constantinople/vm/gas.v b/CoqOfPython/ethereum/constantinople/vm/gas.v new file mode 100644 index 0000000..b6c7f26 --- /dev/null +++ b/CoqOfPython/ethereum/constantinople/vm/gas.v @@ -0,0 +1,821 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Gas +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +EVM gas constants and calculators. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.trace. +Axiom ethereum_trace_GasAndRefund : + IsGlobalAlias globals ethereum.trace.globals "GasAndRefund". +Axiom ethereum_trace_evm_trace : + IsGlobalAlias globals ethereum.trace.globals "evm_trace". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". + +Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) +)). + +Definition GAS_BASE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 2 + ], + make_dict [] + |) +)). + +Definition GAS_VERY_LOW : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_SLOAD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 200 + ], + make_dict [] + |) +)). + +Definition GAS_STORAGE_SET : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 20000 + ], + make_dict [] + |) +)). + +Definition GAS_STORAGE_UPDATE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5000 + ], + make_dict [] + |) +)). + +Definition GAS_STORAGE_CLEAR_REFUND : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 15000 + ], + make_dict [] + |) +)). + +Definition GAS_LOW : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5 + ], + make_dict [] + |) +)). + +Definition GAS_MID : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 8 + ], + make_dict [] + |) +)). + +Definition GAS_HIGH : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 10 + ], + make_dict [] + |) +)). + +Definition GAS_EXPONENTIATION : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 10 + ], + make_dict [] + |) +)). + +Definition GAS_EXPONENTIATION_PER_BYTE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 50 + ], + make_dict [] + |) +)). + +Definition GAS_MEMORY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_KECCAK256 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 30 + ], + make_dict [] + |) +)). + +Definition GAS_KECCAK256_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 6 + ], + make_dict [] + |) +)). + +Definition GAS_COPY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_BLOCK_HASH : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 20 + ], + make_dict [] + |) +)). + +Definition GAS_EXTERNAL : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 700 + ], + make_dict [] + |) +)). + +Definition GAS_BALANCE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 400 + ], + make_dict [] + |) +)). + +Definition GAS_LOG : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 375 + ], + make_dict [] + |) +)). + +Definition GAS_LOG_DATA : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 8 + ], + make_dict [] + |) +)). + +Definition GAS_LOG_TOPIC : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 375 + ], + make_dict [] + |) +)). + +Definition GAS_CREATE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 32000 + ], + make_dict [] + |) +)). + +Definition GAS_CODE_DEPOSIT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 200 + ], + make_dict [] + |) +)). + +Definition GAS_ZERO : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) +)). + +Definition GAS_CALL : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 700 + ], + make_dict [] + |) +)). + +Definition GAS_NEW_ACCOUNT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 25000 + ], + make_dict [] + |) +)). + +Definition GAS_CALL_VALUE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 9000 + ], + make_dict [] + |) +)). + +Definition GAS_CALL_STIPEND : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 2300 + ], + make_dict [] + |) +)). + +Definition GAS_SELF_DESTRUCT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5000 + ], + make_dict [] + |) +)). + +Definition GAS_SELF_DESTRUCT_NEW_ACCOUNT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 25000 + ], + make_dict [] + |) +)). + +Definition REFUND_SELF_DESTRUCT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 24000 + ], + make_dict [] + |) +)). + +Definition GAS_ECRECOVER : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3000 + ], + make_dict [] + |) +)). + +Definition GAS_SHA256 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 60 + ], + make_dict [] + |) +)). + +Definition GAS_SHA256_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 12 + ], + make_dict [] + |) +)). + +Definition GAS_RIPEMD160 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 600 + ], + make_dict [] + |) +)). + +Definition GAS_RIPEMD160_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 120 + ], + make_dict [] + |) +)). + +Definition GAS_IDENTITY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 15 + ], + make_dict [] + |) +)). + +Definition GAS_IDENTITY_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_RETURN_DATA_COPY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_CODE_HASH : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 400 + ], + make_dict [] + |) +)). + +Definition ExtendMemory : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition MessageCallGas : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition charge_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "amount" ] |) in + let _ := Constant.str " + Subtracts `amount` from `evm.gas_left`. + + Parameters + ---------- + evm : + The current EVM. + amount : + The amount of gas the current operation requires. + + " in + let _ := M.call (| + M.get_name (| globals, "evm_trace" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "GasAndRefund" |), + make_list [ + M.get_name (| globals, "amount" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + let _ := M.assign_op (| + BinOp.sub, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "amount" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition calculate_memory_gas_cost : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "size_in_bytes" ] |) in + let _ := Constant.str " + Calculates the gas cost for allocating memory + to the smallest multiple of 32 bytes, + such that the allocated size is at least as big as the given size. + + Parameters + ---------- + size_in_bytes : + The size of the data in bytes. + + Returns + ------- + total_gas_cost : `ethereum.base_types.Uint` + The gas cost for storing data in memory. + " in + let size_in_words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "size_in_bytes" |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let linear_cost := + BinOp.mult (| + M.get_name (| globals, "size_in_words" |), + M.get_name (| globals, "GAS_MEMORY" |) + |) in + let quadratic_cost := + BinOp.floor_div (| + BinOp.pow (| + M.get_name (| globals, "size_in_words" |), + Constant.int 2 + |), + Constant.int 512 + |) in + let total_gas_cost := + BinOp.add (| + M.get_name (| globals, "linear_cost" |), + M.get_name (| globals, "quadratic_cost" |) + |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_)). + +Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "memory"; "extensions" ] |) in + let _ := Constant.str " + Calculates the gas amount to extend memory + + Parameters + ---------- + memory : + Memory contents of the EVM. + extensions: + List of extensions to be made to the memory. + Consists of a tuple of start position and size. + + Returns + ------- + extend_memory: `ExtendMemory` + " in + let size_to_extend := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let to_be_paid := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let current_size := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "memory" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + For make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ] in M.get_name (| globals, "extensions" |) do + let _ := + M.pure Constant.None_ + )) |) in + let before_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "current_size" |) + ], + make_dict [] + |) in + let after_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let size_to_extend := BinOp.add + BinOp.sub (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |) + BinOp.sub (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |) in + let already_paid := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "before_size" |) + ], + make_dict [] + |) in + let total_cost := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "after_size" |) + ], + make_dict [] + |) in + let to_be_paid := BinOp.add + BinOp.sub (| + M.get_name (| globals, "total_cost" |), + M.get_name (| globals, "already_paid" |) + |) + BinOp.sub (| + M.get_name (| globals, "total_cost" |), + M.get_name (| globals, "already_paid" |) + |) in + let current_size := + M.get_name (| globals, "after_size" |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ExtendMemory" |), + make_list [ + M.get_name (| globals, "to_be_paid" |); + M.get_name (| globals, "size_to_extend" |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition calculate_message_call_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "value"; "gas"; "gas_left"; "memory_cost"; "extra_gas"; "call_stipend" ] |) in + let _ := Constant.str " + Calculates the MessageCallGas (cost and stipend) for + executing call Opcodes. + + Parameters + ---------- + value: + The amount of `ETH` that needs to be transferred. + gas : + The amount of gas provided to the message-call. + gas_left : + The amount of gas left in the current frame. + memory_cost : + The amount needed to extend the memory in the current frame. + extra_gas : + The amount of gas needed for transferring value + creating a new + account inside a message call. + call_stipend : + The amount of stipend provided to a message call to execute code while + transferring value(ETH). + + Returns + ------- + message_call_gas: `MessageCallGas` + " in + let call_stipend := + (* if *) +M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let gas := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "max_message_call_gas" |), + make_list [ + BinOp.sub (| + BinOp.sub (| + M.get_name (| globals, "gas_left" |), + M.get_name (| globals, "memory_cost" |) + |), + M.get_name (| globals, "extra_gas" |) + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallGas" |), + make_list [ + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "extra_gas" |) + |); + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "call_stipend" |) + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition max_message_call_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "gas" ] |) in + let _ := Constant.str " + Calculates the maximum gas that is allowed for making a message call + + Parameters + ---------- + gas : + The amount of gas provided to the message-call. + + Returns + ------- + max_allowed_message_call_gas: `ethereum.base_types.Uint` + The maximum gas allowed for making the message-call. + " in + let _ := M.return_ (| + BinOp.sub (| + M.get_name (| globals, "gas" |), + BinOp.floor_div (| + M.get_name (| globals, "gas" |), + Constant.int 64 + |) + |) + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/constantinople/vm/instructions/arithmetic.v index a8b5c61..581ba5d 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/arithmetic.v @@ -273,22 +273,6 @@ Definition div : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let quotient := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let quotient := BinOp.floor_div (| M.get_name (| globals, "dividend" |), @@ -357,32 +341,7 @@ Definition sdiv : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let quotient := - Constant.int 0 in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_name (| globals, "dividend" |), UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "divisor" |), UnOp.sub (| Constant.int 1 |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let quotient := - UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let sign := M.call (| M.get_name (| globals, "get_sign" |), @@ -477,22 +436,6 @@ Definition mod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let remainder := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let remainder := BinOp.mod_ (| M.get_name (| globals, "x" |), @@ -561,16 +504,6 @@ Definition smod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let remainder := - Constant.int 0 in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let remainder := BinOp.mult (| M.call (| @@ -684,22 +617,6 @@ Definition addmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -795,22 +712,6 @@ Definition mulmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -980,16 +881,6 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "byte_num" |), Constant.int 31 |), - (* then *) - ltac:(M.monadic ( - let result := - M.get_name (| globals, "value" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let value_bytes := M.call (| M.get_name (| globals, "bytes" |), @@ -1012,29 +903,13 @@ Definition signextend : Value.t -> Value.t -> M := ], make_dict [] |) - |):(* At expr: unsupported node type: NoneType *) |) in + |) |) in let sign_bit := BinOp.r_shift (| M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), Constant.int 7 |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "sign_bit" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), - make_list [ - M.get_name (| globals, "value_bytes" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let num_bytes_prepend := BinOp.sub (| Constant.int 32, diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/bitwise.v b/CoqOfPython/ethereum/constantinople/vm/instructions/bitwise.v index 9f2f382..64cf120 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/bitwise.v @@ -287,22 +287,6 @@ Definition get_byte : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "byte_index" |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let extra_bytes_to_right := BinOp.sub (| Constant.int 31, @@ -382,28 +366,6 @@ Definition bitwise_shl : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - BinOp.mod_ (| - BinOp.l_shift (| - M.get_name (| globals, "value" |), - M.get_name (| globals, "shift" |) - |), - M.get_name (| globals, "U256_CEIL_VALUE" |) - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -465,19 +427,6 @@ Definition bitwise_shr : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), - (* then *) - ltac:(M.monadic ( - let result := - BinOp.r_shift (| - M.get_name (| globals, "value" |), - M.get_name (| globals, "shift" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -543,42 +492,7 @@ Definition bitwise_sar : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), - make_list [ - BinOp.r_shift (| - M.get_name (| globals, "signed_value" |), - M.get_name (| globals, "shift" |) - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "signed_value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/block.v b/CoqOfPython/ethereum/constantinople/vm/instructions/block.v index e5fa554..90be45c 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/block.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/block.v @@ -69,24 +69,6 @@ Definition block_hash : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.lt_e (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), M.get_name (| globals, "block_number" |) |), - ltac:(M.monadic ( - Compare.gt (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), BinOp.add (| - M.get_name (| globals, "block_number" |), - Constant.int 256 - |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let hash := - (* At constant: unsupported node type: Constant *) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let hash := M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/comparison.v b/CoqOfPython/ethereum/constantinople/vm/instructions/comparison.v index fbc35f8..b8529d8 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/comparison.v @@ -78,7 +78,10 @@ Definition less_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.lt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -145,7 +148,10 @@ Definition signed_less_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.lt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -205,7 +211,10 @@ Definition greater_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.gt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -272,7 +281,10 @@ Definition signed_greater_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.gt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -332,7 +344,10 @@ Definition equal : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.eq (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.eq (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -384,7 +399,10 @@ Definition is_zero : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.eq (| M.get_name (| globals, "x" |), Constant.int 0 |) + Compare.eq (| + M.get_name (| globals, "x" |), + Constant.int 0 + |) ], make_dict [] |) in diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/control_flow.v b/CoqOfPython/ethereum/constantinople/vm/instructions/control_flow.v index 04a79d9..d4e4eae 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/control_flow.v @@ -109,15 +109,6 @@ Definition jump : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -177,29 +168,7 @@ Definition jumpi : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "conditional_value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let destination := - BinOp.add (| - M.get_field (| M.get_name (| globals, "evm" |), "pc" |), - Constant.int 1 - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let destination := M.get_name (| globals, "jump_dest" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/environment.v b/CoqOfPython/ethereum/constantinople/vm/instructions/environment.v index d0a3a8f..c1e94f6 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/environment.v @@ -512,7 +512,7 @@ Definition calldatacopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -680,7 +680,7 @@ Definition codecopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -923,7 +923,7 @@ Definition extcodecopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -1094,28 +1094,31 @@ Definition returndatacopy : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt_e (| BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "return_data_start_position" |) - ], - make_dict [] + Compare.lt_e (| + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "return_data_start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) |), M.call (| - M.get_name (| globals, "Uint" |), + M.get_name (| globals, "len" |), make_list [ - M.get_name (| globals, "size" |) + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |) ], make_dict [] |) - |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "return_data" |) - ], - make_dict [] - |) |); + |); M.get_name (| globals, "OutOfBoundsRead" |) ], make_dict [] @@ -1124,15 +1127,12 @@ Definition returndatacopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in let value := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |):BinOp.add (| - M.get_name (| globals, "return_data_start_position" |), - M.get_name (| globals, "size" |) - |) |) in + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |) |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -1191,22 +1191,6 @@ Definition extcodehash : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "account" |), M.get_name (| globals, "EMPTY_ACCOUNT" |) |), - (* then *) - ltac:(M.monadic ( - let codehash := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let codehash := M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/keccak.v b/CoqOfPython/ethereum/constantinople/vm/instructions/keccak.v index cab9ffb..2c4b10e 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/keccak.v @@ -137,7 +137,7 @@ Definition keccak : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/log.v b/CoqOfPython/ethereum/constantinople/vm/instructions/log.v index 4891a4d..e084e59 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/log.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/log.v @@ -161,7 +161,7 @@ Definition log_n : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/memory.v b/CoqOfPython/ethereum/constantinople/vm/instructions/memory.v index 1e1c8b0..86ba742 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/memory.v @@ -121,7 +121,7 @@ Definition mstore : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -203,7 +203,7 @@ Definition mstore8 : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -288,7 +288,7 @@ Definition mload : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/stack.v b/CoqOfPython/ethereum/constantinople/vm/instructions/stack.v index 1eeda05..305af15 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/stack.v @@ -188,13 +188,16 @@ Definition dup_n : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] - |) |); + Compare.lt (| + M.get_name (| globals, "item_number" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + |); M.get_name (| globals, "StackUnderflowError" |) ], make_dict [] @@ -260,13 +263,16 @@ Definition swap_n : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] - |) |); + Compare.lt (| + M.get_name (| globals, "item_number" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + |); M.get_name (| globals, "StackUnderflowError" |) ], make_dict [] diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/storage.v b/CoqOfPython/ethereum/constantinople/vm/instructions/storage.v index 29ef235..fe33724 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/storage.v @@ -154,44 +154,11 @@ Definition sstore : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "new_value" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let gas_cost := - M.get_name (| globals, "GAS_STORAGE_SET" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let gas_cost := M.get_name (| globals, "GAS_STORAGE_UPDATE" |) in M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_name (| globals, "new_value" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), - M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/system.v b/CoqOfPython/ethereum/constantinople/vm/instructions/system.v new file mode 100644 index 0000000..b850f84 --- /dev/null +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/system.v @@ -0,0 +1,1598 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) System Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM system related instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_account_exists_and_is_empty : + IsGlobalAlias globals state.globals "account_exists_and_is_empty". +Axiom state_account_has_code_or_nonce : + IsGlobalAlias globals state.globals "account_has_code_or_nonce". +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". +Axiom state_increment_nonce : + IsGlobalAlias globals state.globals "increment_nonce". +Axiom state_is_account_alive : + IsGlobalAlias globals state.globals "is_account_alive". +Axiom state_set_account_balance : + IsGlobalAlias globals state.globals "set_account_balance". + +Require utils.address. +Axiom utils_address_compute_contract_address : + IsGlobalAlias globals utils.address.globals "compute_contract_address". +Axiom utils_address_compute_create2_contract_address : + IsGlobalAlias globals utils.address.globals "compute_create2_contract_address". +Axiom utils_address_to_address : + IsGlobalAlias globals utils.address.globals "to_address". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". +Axiom __init___Message : + IsGlobalAlias globals __init__.globals "Message". +Axiom __init___incorporate_child_on_error : + IsGlobalAlias globals __init__.globals "incorporate_child_on_error". +Axiom __init___incorporate_child_on_success : + IsGlobalAlias globals __init__.globals "incorporate_child_on_success". + +Require exceptions. +Axiom exceptions_Revert : + IsGlobalAlias globals exceptions.globals "Revert". +Axiom exceptions_WriteInStaticContext : + IsGlobalAlias globals exceptions.globals "WriteInStaticContext". + +Require gas. +Axiom gas_GAS_CALL : + IsGlobalAlias globals gas.globals "GAS_CALL". +Axiom gas_GAS_CALL_VALUE : + IsGlobalAlias globals gas.globals "GAS_CALL_VALUE". +Axiom gas_GAS_CREATE : + IsGlobalAlias globals gas.globals "GAS_CREATE". +Axiom gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". +Axiom gas_GAS_NEW_ACCOUNT : + IsGlobalAlias globals gas.globals "GAS_NEW_ACCOUNT". +Axiom gas_GAS_SELF_DESTRUCT : + IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT". +Axiom gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : + IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". +Axiom gas_GAS_ZERO : + IsGlobalAlias globals gas.globals "GAS_ZERO". +Axiom gas_REFUND_SELF_DESTRUCT : + IsGlobalAlias globals gas.globals "REFUND_SELF_DESTRUCT". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_calculate_message_call_gas : + IsGlobalAlias globals gas.globals "calculate_message_call_gas". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". +Axiom gas_max_message_call_gas : + IsGlobalAlias globals gas.globals "max_message_call_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". +Axiom memory_memory_write : + IsGlobalAlias globals memory.globals "memory_write". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition generic_create : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "endowment"; "contract_address"; "memory_start_position"; "memory_size" ] |) in + let _ := Constant.str " + Core logic used by the `CREATE*` family of opcodes. + " in +(* At stmt: unsupported node type: ImportFrom *) + let create_message_gas := + M.call (| + M.get_name (| globals, "max_message_call_gas" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.sub, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "create_message_gas" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let sender_address := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in + let sender := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "sender_address" |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := + M.pure Constant.None_ + )) |) in + let call_data := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + let child_message := + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) in + let child_evm := + M.call (| + M.get_name (| globals, "process_create_message" |), + make_list [ + M.get_name (| globals, "child_message" |); + M.get_field (| M.get_name (| globals, "evm" |), "env" |) + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_success" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition create : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Creates a new account with associated code. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let endowment := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_position" |); M.get_name (| globals, "memory_size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_CREATE" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let contract_address := + M.call (| + M.get_name (| globals, "compute_contract_address" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "nonce" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "generic_create" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "endowment" |); + M.get_name (| globals, "contract_address" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition create2 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Creates a new account with associated code. + + It's similar to CREATE opcode except that the address of new account + depends on the init_code instead of the nonce of sender. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let endowment := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let salt := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_position" |); M.get_name (| globals, "memory_size" |) ] + ] + ], + make_dict [] + |) in + let call_data_words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_CREATE" |), + BinOp.mult (| + M.get_name (| globals, "GAS_KECCAK256_WORD" |), + M.get_name (| globals, "call_data_words" |) + |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let contract_address := + M.call (| + M.get_name (| globals, "compute_create2_contract_address" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "salt" |); + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "generic_create" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "endowment" |); + M.get_name (| globals, "contract_address" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition return_ : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Halts execution returning output data. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let memory_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_position" |); M.get_name (| globals, "memory_size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_ZERO" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "running" |), + Constant.bool false + |) in + let _ := M.pass (| |) in + M.pure Constant.None_)). + +Definition generic_call : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "gas"; "value"; "caller"; "to"; "code_address"; "should_transfer_value"; "is_staticcall"; "memory_input_start_position"; "memory_input_size"; "memory_output_start_position"; "memory_output_size" ] |) in + let _ := Constant.str " + Perform the core logic of the `CALL*` family of opcodes. + " in +(* At stmt: unsupported node type: ImportFrom *) + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let _ := + M.pure Constant.None_ + )) |) in + let call_data := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |) + ], + make_dict [] + |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "code_address" |) + ], + make_dict [] + |), "code" |) in + let child_message := + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) in + let child_evm := + M.call (| + M.get_name (| globals, "process_message" |), + make_list [ + M.get_name (| globals, "child_message" |); + M.get_field (| M.get_name (| globals, "evm" |), "env" |) + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_success" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let actual_output_size := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_name (| globals, "memory_output_size" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), Constant.None_:M.get_name (| globals, "actual_output_size" |) |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition call : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into an account. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let to := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let create_gas_cost := + (* if *) +M.if_then_else (| + BoolOp.or (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "is_account_alive" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "to" |) + ], + make_dict [] + |) + )) + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let transfer_gas_cost := + (* if *) +M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_CALL" |), + M.get_name (| globals, "create_gas_cost" |) + |), + M.get_name (| globals, "transfer_gas_cost" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.or (| + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "value" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) + )) + |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let sender_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.get_name (| globals, "value" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "to" |); + Constant.bool true; + Constant.bool false; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition callcode : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into this account with alternative account’s code. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let code_address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let to := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let transfer_gas_cost := + (* if *) +M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + BinOp.add (| + M.get_name (| globals, "GAS_CALL" |), + M.get_name (| globals, "transfer_gas_cost" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let sender_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.get_name (| globals, "value" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "code_address" |); + Constant.bool true; + Constant.bool false; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition selfdestruct : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Halt execution and register account for later deletion. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let beneficiary := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let gas_cost := + M.get_name (| globals, "GAS_SELF_DESTRUCT" |) in + let _ := + M.pure Constant.None_ + )) |) in + let originator := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in + let refunded_accounts := + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in + let parent_evm := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "parent_evm" |) in + While Compare.is_not (| + M.get_name (| globals, "parent_evm" |), + Constant.None_ + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "refunded_accounts" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "parent_evm" |), "accounts_to_delete" |) + ], + make_dict [] + |) in + let parent_evm := + M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in + EndWhile. + let _ := + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "gas_cost" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let beneficiary_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |), "balance" |) in + let originator_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "originator" |) + ], + make_dict [] + |), "balance" |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |); + BinOp.add (| + M.get_name (| globals, "beneficiary_balance" |), + M.get_name (| globals, "originator_balance" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "originator" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |), "add" |), + make_list [ + M.get_name (| globals, "originator" |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "running" |), + Constant.bool false + |) in + let _ := M.pass (| |) in + M.pure Constant.None_)). + +Definition delegatecall : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into an account. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let code_address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + M.get_name (| globals, "GAS_CALL" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "value" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "caller" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "code_address" |); + Constant.bool false; + Constant.bool false; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition staticcall : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into an account. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let to := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + M.get_name (| globals, "GAS_CALL" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "to" |); + Constant.bool true; + Constant.bool true; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition revert : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stop execution and revert state changes, without consuming all provided gas + and also has the ability to return a reason + Parameters + ---------- + evm : + The current EVM frame. + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let output := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "bytes" |), + make_list [ + M.get_name (| globals, "output" |) + ], + make_dict [] + |) + |) in + let _ := M.raise (| Some(M.get_name (| globals, "Revert" |)) + let _ := M.pass (| |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/vm/interpreter.v b/CoqOfPython/ethereum/constantinople/vm/interpreter.v index 309a7b7..1732d4d 100644 --- a/CoqOfPython/ethereum/constantinople/vm/interpreter.v +++ b/CoqOfPython/ethereum/constantinople/vm/interpreter.v @@ -180,91 +180,6 @@ Definition process_message_call : Value.t -> Value.t -> M := Output of the message call " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_name (| globals, "message" |), "target" |), M.call (| - M.get_name (| globals, "Bytes0" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let is_collision := - M.call (| - M.get_name (| globals, "account_has_code_or_nonce" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_field (| M.get_name (| globals, "message" |), "current_target" |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - M.get_name (| globals, "is_collision" |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "MessageCallOutput" |), - make_list [ - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |); - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |); - M.call (| - M.get_name (| globals, "tuple" |), - make_list [], - make_dict [] - |); - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |); - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |); - M.call (| - M.get_name (| globals, "AddressCollision" |), - make_list [], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let evm := - M.call (| - M.get_name (| globals, "process_create_message" |), - make_list [ - M.get_name (| globals, "message" |); - M.get_name (| globals, "env" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let evm := M.call (| M.get_name (| globals, "process_message" |), @@ -275,74 +190,11 @@ Definition process_message_call : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_field (| M.get_name (| globals, "message" |), "target" |) - ], - make_dict [] - |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), - make_list [ - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_field (| M.get_name (| globals, "message" |), "target" |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "evm" |), "error" |), - (* then *) - ltac:(M.monadic ( -(* At stmt: unsupported node type: AnnAssign *) - let accounts_to_delete := - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |) in - let touched_accounts := - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |) in - let refund_counter := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let logs := M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in let accounts_to_delete := @@ -380,7 +232,6 @@ Definition process_message_call : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). Definition process_create_message : Value.t -> Value.t -> M := @@ -434,28 +285,6 @@ Definition process_create_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), - (* then *) - ltac:(M.monadic ( - let contract_code := - M.get_field (| M.get_name (| globals, "evm" |), "output" |) in - let contract_code_gas := - BinOp.mult (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "contract_code" |) - ], - make_dict [] - |), - M.get_name (| globals, "GAS_CODE_DEPOSIT" |) - |) in -(* At stmt: unsupported node type: Try *) - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "rollback_transaction" |), make_list [ @@ -467,7 +296,6 @@ Definition process_create_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) - |) in M.pure Constant.None_)). Definition process_message : Value.t -> Value.t -> M := @@ -489,21 +317,6 @@ Definition process_message : Value.t -> Value.t -> M := Items containing execution specific objects " in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_field (| M.get_name (| globals, "message" |), "depth" |), M.get_name (| globals, "STACK_DEPTH_LIMIT" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "StackDepthLimitError" |), - make_list [ - Constant.str "Stack depth limit reached" - ], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -522,29 +335,6 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - M.get_field (| M.get_name (| globals, "message" |), "should_transfer_value" |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_field (| M.get_name (| globals, "message" |), "value" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "move_ether" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_field (| M.get_name (| globals, "message" |), "caller" |); - M.get_field (| M.get_name (| globals, "message" |), "current_target" |); - M.get_field (| M.get_name (| globals, "message" |), "value" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let evm := @@ -557,21 +347,6 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "evm" |), "error" |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "rollback_transaction" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "commit_transaction" |), make_list [ @@ -583,7 +358,6 @@ Definition process_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) - |) in M.pure Constant.None_)). Definition execute_code : Value.t -> Value.t -> M := @@ -623,5 +397,4 @@ Definition execute_code : Value.t -> Value.t -> M := (* At stmt: unsupported node type: Try *) let _ := M.return_ (| M.get_name (| globals, "evm" |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/vm/memory.v b/CoqOfPython/ethereum/constantinople/vm/memory.v index fa8d906..4b107fd 100644 --- a/CoqOfPython/ethereum/constantinople/vm/memory.v +++ b/CoqOfPython/ethereum/constantinople/vm/memory.v @@ -45,22 +45,7 @@ Definition memory_write : Value.t -> Value.t -> M := Data to write to memory. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) - |) |), + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_)). @@ -86,23 +71,7 @@ Definition memory_read_bytes : Value.t -> Value.t -> M := Data read from memory. " in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |) - |) in + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |) M.pure Constant.None_)). Definition buffer_read : Value.t -> Value.t -> M := @@ -129,25 +98,9 @@ Definition buffer_read : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "right_pad_zero_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |); + M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |) |); M.get_name (| globals, "size" |) ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/alt_bn128.v index 0823afa..90f245d 100644 --- a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/alt_bn128.v +++ b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/alt_bn128.v @@ -210,15 +210,6 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) in For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ] do let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "i" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -362,15 +353,6 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) in For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ] do let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "i" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -443,24 +425,6 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_eq (| BinOp.mod_ (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "data" |) - ], - make_dict [] - |), - Constant.int 192 - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let result := @@ -509,32 +473,11 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := Constant.int 32, M.get_name (| globals, "j" |) |) - |):BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "i" |), - Constant.int 192 - |), - BinOp.mult (| - Constant.int 32, - BinOp.add (| - M.get_name (| globals, "j" |), - Constant.int 1 - |) - |) |) |) ], make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "value" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -555,17 +498,20 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.call (| - M.get_field (| M.get_name (| globals, "p" |), "mul_by" |), - make_list [ - M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) - ], - make_dict [] - |), M.call (| - M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) |); + Compare.eq (| + M.call (| + M.get_field (| M.get_name (| globals, "p" |), "mul_by" |), + make_list [ + M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) + ], + make_dict [] + |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |); M.get_name (| globals, "OutOfGasError" |) ], make_dict [] @@ -573,87 +519,29 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.call (| - M.get_field (| M.get_name (| globals, "q" |), "mul_by" |), - make_list [ - M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) - ], - make_dict [] - |), M.call (| - M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) |); + Compare.eq (| + M.call (| + M.get_field (| M.get_name (| globals, "q" |), "mul_by" |), + make_list [ + M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) + ], + make_dict [] + |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |); M.get_name (| globals, "OutOfGasError" |) ], make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "p" |), M.call (| - M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_name (| globals, "q" |), M.call (| - M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let result := - BinOp.mult (| - M.get_name (| globals, "result" |), - M.call (| - M.get_name (| globals, "pairing" |), - make_list [ - M.get_name (| globals, "q" |); - M.get_name (| globals, "p" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "result" |), M.call (| - M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), - make_list [ - Constant.int 1 - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign (| - M.get_field (| M.get_name (| globals, "evm" |), "output" |), - M.call (| - M.get_field (| M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 1 - ], - make_dict [] - |), "to_be_bytes32" |), - make_list [], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| diff --git a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/ecrecover.v index cc351b5..0cbcf16 100644 --- a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/ecrecover.v @@ -188,60 +188,12 @@ Definition ecrecover : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 27 |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 28 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| Constant.int 0, M.get_name (| globals, "r" |) |), - ltac:(M.monadic ( - Compare.gt_e (| M.get_name (| globals, "r" |), M.get_name (| globals, "SECP256K1N" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| Constant.int 0, M.get_name (| globals, "s" |) |), - ltac:(M.monadic ( - Compare.gt_e (| M.get_name (| globals, "s" |), M.get_name (| globals, "SECP256K1N" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: Try *) @@ -252,7 +204,7 @@ Definition ecrecover : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12:Constant.int 32 |) in + |), Constant.int 12 |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/modexp.v index 39ce4f9..aff5b85 100644 --- a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/modexp.v +++ b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/modexp.v @@ -181,36 +181,6 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "exp_length" |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let adjusted_exp_length := - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.call (| - M.get_name (| globals, "max" |), - make_list [ - Constant.int 0; - BinOp.sub (| - M.call (| - M.get_field (| M.get_name (| globals, "exp_head" |), "bit_length" |), - make_list [], - make_dict [] - |), - Constant.int 1 - |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let adjusted_exp_length := M.call (| M.get_name (| globals, "Uint" |), @@ -297,30 +267,6 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_name (| globals, "base_length" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "modulus_length" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign (| - M.get_field (| M.get_name (| globals, "evm" |), "output" |), - M.call (| - M.get_name (| globals, "Bytes" |), - make_list [], - make_dict [] - |) - |) in - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let base := @@ -383,27 +329,6 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "modulus" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign (| - M.get_field (| M.get_name (| globals, "evm" |), "output" |), - BinOp.mult (| - M.call (| - M.get_name (| globals, "Bytes" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |), - M.get_name (| globals, "modulus_length" |) - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| @@ -440,47 +365,7 @@ Definition get_mult_complexity : Value.t -> Value.t -> M := Estimate the complexity of performing Karatsuba multiplication. " in let _ := - (* if *) - M.if_then_else (| - Compare.lt_e (| M.get_name (| globals, "x" |), Constant.int 64 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - BinOp.pow (| - M.get_name (| globals, "x" |), - Constant.int 2 - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - Compare.lt_e (| M.get_name (| globals, "x" |), Constant.int 1024 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - BinOp.sub (| - BinOp.add (| - BinOp.floor_div (| - BinOp.pow (| - M.get_name (| globals, "x" |), - Constant.int 2 - |), - Constant.int 4 - |), - BinOp.mult (| - Constant.int 96, - M.get_name (| globals, "x" |) - |) - |), - Constant.int 3072 - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| BinOp.sub (| BinOp.add (| @@ -498,7 +383,6 @@ Definition get_mult_complexity : Value.t -> Value.t -> M := |), Constant.int 199680 |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/constantinople/vm/runtime.v b/CoqOfPython/ethereum/constantinople/vm/runtime.v index 835b46c..2cd7652 100644 --- a/CoqOfPython/ethereum/constantinople/vm/runtime.v +++ b/CoqOfPython/ethereum/constantinople/vm/runtime.v @@ -67,50 +67,19 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := ], make_dict [] |) in - While Compare.lt (| M.get_name (| globals, "pc" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "code" |) - ], - make_dict [] - |) |) do + While Compare.lt (| + M.get_name (| globals, "pc" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) + |) do (* At stmt: unsupported node type: Try *) let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "current_opcode" |), M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), - make_list [ - M.get_name (| globals, "pc" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - (* At expr: unsupported node type: Compare *), - (* then *) - ltac:(M.monadic ( - let push_data_size := - BinOp.add (| - BinOp.sub (| - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) - |), - Constant.int 1 - |) in - let pc := BinOp.add - M.get_name (| globals, "push_data_size" |) - M.get_name (| globals, "push_data_size" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -121,5 +90,4 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := EndWhile. let _ := M.return_ (| M.get_name (| globals, "valid_jump_destinations" |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/vm/stack.v b/CoqOfPython/ethereum/constantinople/vm/stack.v index 42ea42d..ea778df 100644 --- a/CoqOfPython/ethereum/constantinople/vm/stack.v +++ b/CoqOfPython/ethereum/constantinople/vm/stack.v @@ -49,21 +49,6 @@ Definition pop : Value.t -> Value.t -> M := " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "stack" |) - ], - make_dict [] - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "StackUnderflowError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -72,7 +57,6 @@ Definition pop : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). Definition push : Value.t -> Value.t -> M := @@ -91,21 +75,6 @@ Definition push : Value.t -> Value.t -> M := " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "stack" |) - ], - make_dict [] - |), Constant.int 1024 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "StackOverflowError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -116,5 +85,4 @@ Definition push : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/crypto/alt_bn128.v b/CoqOfPython/ethereum/crypto/alt_bn128.v index 00b0acf..44ac0df 100644 --- a/CoqOfPython/ethereum/crypto/alt_bn128.v +++ b/CoqOfPython/ethereum/crypto/alt_bn128.v @@ -170,11 +170,10 @@ Definition BNF12 : Value.t := M.get_field (| M.get_name (| globals, "BNF12" |), "__new__" |), make_list [ M.get_name (| globals, "BNF12" |); - M.get_subscript (| M.get_name (| globals, "mul" |), (* At expr: unsupported node type: NoneType *):Constant.int 12 |) + M.get_subscript (| M.get_name (| globals, "mul" |), Constant.None_:Constant.int 12 |) ], make_dict [] |) - |) in M.pure Constant.None_)) ) ]. @@ -239,7 +238,6 @@ Definition bnf2_to_bnf12 : Value.t -> Value.t -> M := |) |) |) - |) in M.pure Constant.None_)). Definition bnp_to_bnp12 : Value.t -> Value.t -> M := @@ -281,7 +279,6 @@ Definition bnp_to_bnp12 : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition twist : Value.t -> Value.t -> M := @@ -323,7 +320,6 @@ Definition twist : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition linefunc : Value.t -> Value.t -> M := @@ -339,96 +335,12 @@ Definition linefunc : Value.t -> Value.t -> M := matter. " in let _ := - (* if *) - M.if_then_else (| - Compare.not_eq (| M.get_field (| M.get_name (| globals, "p1" |), "x" |), M.get_field (| M.get_name (| globals, "p2" |), "x" |) |), - (* then *) - ltac:(M.monadic ( - let lam := - BinOp.div (| - BinOp.sub (| - M.get_field (| M.get_name (| globals, "p2" |), "y" |), - M.get_field (| M.get_name (| globals, "p1" |), "y" |) - |), - BinOp.sub (| - M.get_field (| M.get_name (| globals, "p2" |), "x" |), - M.get_field (| M.get_name (| globals, "p1" |), "x" |) - |) - |) in - let _ := M.return_ (| - BinOp.sub (| - BinOp.mult (| - M.get_name (| globals, "lam" |), - BinOp.sub (| - M.get_field (| M.get_name (| globals, "t" |), "x" |), - M.get_field (| M.get_name (| globals, "p1" |), "x" |) - |) - |), - BinOp.sub (| - M.get_field (| M.get_name (| globals, "t" |), "y" |), - M.get_field (| M.get_name (| globals, "p1" |), "y" |) - |) - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_name (| globals, "p1" |), "y" |), M.get_field (| M.get_name (| globals, "p2" |), "y" |) |), - (* then *) - ltac:(M.monadic ( - let lam := - BinOp.div (| - BinOp.mult (| - M.call (| - M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), - make_list [ - Constant.int 3 - ], - make_dict [] - |), - BinOp.pow (| - M.get_field (| M.get_name (| globals, "p1" |), "x" |), - Constant.int 2 - |) - |), - BinOp.mult (| - M.call (| - M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), - make_list [ - Constant.int 2 - ], - make_dict [] - |), - M.get_field (| M.get_name (| globals, "p1" |), "y" |) - |) - |) in - let _ := M.return_ (| - BinOp.sub (| - BinOp.mult (| - M.get_name (| globals, "lam" |), - BinOp.sub (| - M.get_field (| M.get_name (| globals, "t" |), "x" |), - M.get_field (| M.get_name (| globals, "p1" |), "x" |) - |) - |), - BinOp.sub (| - M.get_field (| M.get_name (| globals, "t" |), "y" |), - M.get_field (| M.get_name (| globals, "p1" |), "y" |) - |) - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| BinOp.sub (| M.get_field (| M.get_name (| globals, "t" |), "x" |), M.get_field (| M.get_name (| globals, "p1" |), "x" |) |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -442,36 +354,6 @@ Definition miller_loop : Value.t -> Value.t -> M := The core of the pairing algorithm. " in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.eq (| M.get_name (| globals, "p" |), M.call (| - M.get_field (| M.get_name (| globals, "BNP12" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "q" |), M.call (| - M.get_field (| M.get_name (| globals, "BNP12" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), - make_list [ - Constant.int 1 - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let r := @@ -516,54 +398,22 @@ Definition miller_loop : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BinOp.bit_and (| - BinOp.sub (| - M.get_name (| globals, "ATE_PAIRING_COUNT" |), - Constant.int 1 - |), - BinOp.pow (| - Constant.int 2, - M.get_name (| globals, "i" |) - |) - |), - (* then *) - ltac:(M.monadic ( - let f := - BinOp.mult (| - M.get_name (| globals, "f" |), - M.call (| - M.get_name (| globals, "linefunc" |), - make_list [ - M.get_name (| globals, "r" |); - M.get_name (| globals, "q" |); - M.get_name (| globals, "p" |) - ], - make_dict [] - |) - |) in - let r := - BinOp.add (| - M.get_name (| globals, "r" |), - M.get_name (| globals, "q" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. - let _ := M.assert (| Compare.eq (| M.get_name (| globals, "r" |), M.call (| - M.get_field (| M.get_name (| globals, "q" |), "mul_by" |), - make_list [ - BinOp.sub (| - M.get_name (| globals, "ATE_PAIRING_COUNT" |), - Constant.int 1 - |) - ], - make_dict [] - |) |) |) in + let _ := M.assert (| Compare.eq (| + M.get_name (| globals, "r" |), + M.call (| + M.get_field (| M.get_name (| globals, "q" |), "mul_by" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "ATE_PAIRING_COUNT" |), + Constant.int 1 + |) + ], + make_dict [] + |) + |) |) in let q1 := M.call (| M.get_name (| globals, "BNP12" |), @@ -643,7 +493,6 @@ Definition miller_loop : Value.t -> Value.t -> M := M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) |) |) - |) in M.pure Constant.None_)). Definition pairing : Value.t -> Value.t -> M := @@ -673,5 +522,4 @@ Definition pairing : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/crypto/blake2.v b/CoqOfPython/ethereum/crypto/blake2.v index 68db13a..063cf6c 100644 --- a/CoqOfPython/ethereum/crypto/blake2.v +++ b/CoqOfPython/ethereum/crypto/blake2.v @@ -62,10 +62,7 @@ Definition spit_le_to_uint : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_le_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "data" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.get_name (| globals, "start_position" |), - Constant.int 8 - |) |) + M.get_subscript (| M.get_name (| globals, "data" |), M.get_name (| globals, "start_position" |) |) ], make_dict [] |) @@ -75,7 +72,6 @@ Definition spit_le_to_uint : Value.t -> Value.t -> M := EndFor. let _ := M.return_ (| M.get_name (| globals, "words" |) - |) in M.pure Constant.None_)). Definition Blake2 : Value.t := @@ -102,7 +98,7 @@ Definition Blake2 : Value.t := M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "data" |), (* At expr: unsupported node type: NoneType *):Constant.int 4 |) + M.get_subscript (| M.get_name (| globals, "data" |), Constant.None_:Constant.int 4 |) ], make_dict [] |) in @@ -142,13 +138,12 @@ Definition Blake2 : Value.t := M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "data" |), Constant.int 212:(* At expr: unsupported node type: NoneType *) |) + M.get_subscript (| M.get_name (| globals, "data" |), Constant.int 212 |) ], make_dict [] |) in let _ := M.return_ (| make_tuple [ M.get_name (| globals, "rounds" |); M.get_name (| globals, "h" |); M.get_name (| globals, "m" |); M.get_name (| globals, "t_0" |); M.get_name (| globals, "t_1" |); M.get_name (| globals, "f" |) ] - |) in M.pure Constant.None_)) ); ( @@ -304,7 +299,6 @@ Definition Blake2 : Value.t := |) in let _ := M.return_ (| M.get_name (| globals, "v" |) - |) in M.pure Constant.None_)) ); ( @@ -336,11 +330,11 @@ Definition Blake2 : Value.t := Constant.int 16 |) in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "v" |), Constant.int 0:Constant.int 8 |), + M.get_subscript (| M.get_name (| globals, "v" |), Constant.int 0 |), M.get_name (| globals, "h" |) |) in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "v" |), Constant.int 8:Constant.int 15 |), + M.get_subscript (| M.get_name (| globals, "v" |), Constant.int 8 |), M.get_field (| M.get_name (| globals, "self" |), "IV" |) |) in let _ := M.assign (| @@ -358,21 +352,6 @@ Definition Blake2 : Value.t := |) |) in let _ := - (* if *) - M.if_then_else (| - M.get_name (| globals, "f" |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "v" |), Constant.int 14 |), - BinOp.bit_xor (| - M.get_subscript (| M.get_name (| globals, "v" |), Constant.int 14 |), - M.get_field (| M.get_name (| globals, "self" |), "mask_bits" |) - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in For M.get_name (| globals, "r" |) in M.call (| @@ -501,16 +480,7 @@ Definition Blake2 : Value.t := |) in EndFor. let result_message_words := - (BinOp.bit_xor (| - BinOp.bit_xor (| - M.get_subscript (| M.get_name (| globals, "h" |), M.get_name (| globals, "i" |) |), - M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "i" |) |) - |), - M.get_subscript (| M.get_name (| globals, "v" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 8 - |) |) - |) for (* At expr: unsupported node type: list *)) in + (* At expr: unsupported node type: GeneratorExp *) in let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "struct" |), "pack" |), @@ -525,7 +495,6 @@ Definition Blake2 : Value.t := ] |), make_dict [] |) - |) in M.pure Constant.None_)) ) ]. diff --git a/CoqOfPython/ethereum/crypto/elliptic_curve.v b/CoqOfPython/ethereum/crypto/elliptic_curve.v index c0bae4d..5741aba 100644 --- a/CoqOfPython/ethereum/crypto/elliptic_curve.v +++ b/CoqOfPython/ethereum/crypto/elliptic_curve.v @@ -113,7 +113,7 @@ Definition secp256k1_recover : Value.t -> Value.t -> M := ], make_dict [] |) - |):Constant.int 32 |), + |) |), M.get_name (| globals, "r_bytes" |) |) in let _ := M.assign (| @@ -126,7 +126,7 @@ Definition secp256k1_recover : Value.t -> Value.t -> M := ], make_dict [] |) - |):Constant.int 64 |), + |) |), M.get_name (| globals, "s_bytes" |) |) in let _ := M.assign (| @@ -153,10 +153,9 @@ Definition secp256k1_recover : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "public_key" |), "format" |), make_list [], make_dict [] - |), Constant.int 1:(* At expr: unsupported node type: NoneType *) |) in + |), Constant.int 1 |) in let _ := M.return_ (| M.get_name (| globals, "public_key" |) - |) in M.pure Constant.None_)). Definition EllipticCurve : Value.t := @@ -192,7 +191,6 @@ Definition EllipticCurve : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ) ] @@ -223,7 +221,6 @@ Definition EllipticCurve : Value.t := |) in let _ := M.return_ (| M.get_name (| globals, "res" |) - |) in M.pure Constant.None_)) ); ( @@ -235,61 +232,6 @@ Definition EllipticCurve : Value.t := `__new__()` directly. " in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - BoolOp.or (| - Compare.not_eq (| M.get_name (| globals, "x" |), M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "self" |), "FIELD" |), "zero" |), - make_list [], - make_dict [] - |) |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_name (| globals, "y" |), M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "self" |), "FIELD" |), "zero" |), - make_list [], - make_dict [] - |) |) - )) - |), - ltac:(M.monadic ( - Compare.not_eq (| BinOp.sub (| - BinOp.sub (| - BinOp.sub (| - BinOp.pow (| - M.get_name (| globals, "y" |), - Constant.int 2 - |), - BinOp.pow (| - M.get_name (| globals, "x" |), - Constant.int 3 - |) - |), - BinOp.mult (| - M.get_field (| M.get_name (| globals, "self" |), "A" |), - M.get_name (| globals, "x" |) - |) - |), - M.get_field (| M.get_name (| globals, "self" |), "B" |) - |), M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "self" |), "FIELD" |), "zero" |), - make_list [], - make_dict [] - |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "ValueError" |), - make_list [ - Constant.str "Point not on curve" - ], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)) @@ -302,40 +244,21 @@ Definition EllipticCurve : Value.t := Test two points for equality. " in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "other" |); - M.call (| - M.get_name (| globals, "type" |), - make_list [ - M.get_name (| globals, "self" |) - ], - make_dict [] - |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.bool false - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "self" |), "x" |), M.get_field (| M.get_name (| globals, "other" |), "x" |) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "self" |), "x" |), + M.get_field (| M.get_name (| globals, "other" |), "x" |) + |), ltac:(M.monadic ( - Compare.eq (| M.get_field (| M.get_name (| globals, "self" |), "y" |), M.get_field (| M.get_name (| globals, "other" |), "y" |) |) + Compare.eq (| + M.get_field (| M.get_name (| globals, "self" |), "y" |), + M.get_field (| M.get_name (| globals, "other" |), "y" |) + |) )) |) - |) in M.pure Constant.None_)) ); ( @@ -353,7 +276,6 @@ Definition EllipticCurve : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -368,22 +290,6 @@ Definition EllipticCurve : Value.t := make_tuple [ M.get_field (| M.get_name (| globals, "self" |), "x" |); M.get_field (| M.get_name (| globals, "self" |), "y" |); M.get_field (| M.get_name (| globals, "self" |), "FIELD" |) ] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_name (| globals, "x" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "self" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let lam := @@ -453,7 +359,6 @@ Definition EllipticCurve : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -474,77 +379,12 @@ Definition EllipticCurve : Value.t := make_tuple [ M.get_field (| M.get_name (| globals, "self" |), "x" |); M.get_field (| M.get_name (| globals, "self" |), "y" |); M.get_field (| M.get_name (| globals, "other" |), "x" |); M.get_field (| M.get_name (| globals, "other" |), "y" |) ] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_name (| globals, "self_x" |), M.get_name (| globals, "ZERO" |) |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "self_y" |), M.get_name (| globals, "ZERO" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "other" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_name (| globals, "other_x" |), M.get_name (| globals, "ZERO" |) |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "other_y" |), M.get_name (| globals, "ZERO" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "self" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "self_x" |), M.get_name (| globals, "other_x" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "self_y" |), M.get_name (| globals, "other_y" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_field (| M.get_name (| globals, "self" |), "double" |), - make_list [], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_field (| M.get_name (| globals, "self" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) - |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let lam := @@ -596,7 +436,6 @@ Definition EllipticCurve : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -632,24 +471,11 @@ Definition EllipticCurve : Value.t := |) in let s := M.get_name (| globals, "self" |) in - While Compare.not_eq (| M.get_name (| globals, "n" |), Constant.int 0 |) do + While Compare.not_eq (| + M.get_name (| globals, "n" |), + Constant.int 0 + |) do let _ := - (* if *) - M.if_then_else (| - Compare.eq (| BinOp.mod_ (| - M.get_name (| globals, "n" |), - Constant.int 2 - |), Constant.int 1 |), - (* then *) - ltac:(M.monadic ( - let res := - BinOp.add (| - M.get_name (| globals, "res" |), - M.get_name (| globals, "s" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let s := @@ -663,7 +489,6 @@ Definition EllipticCurve : Value.t := EndWhile. let _ := M.return_ (| M.get_name (| globals, "res" |) - |) in M.pure Constant.None_)) ) ]. diff --git a/CoqOfPython/ethereum/crypto/finite_field.v b/CoqOfPython/ethereum/crypto/finite_field.v index 87dac3a..3707fb1 100644 --- a/CoqOfPython/ethereum/crypto/finite_field.v +++ b/CoqOfPython/ethereum/crypto/finite_field.v @@ -192,7 +192,6 @@ Definition PrimeField : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -208,7 +207,6 @@ Definition PrimeField : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -223,7 +221,6 @@ Definition PrimeField : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ) ] @@ -244,7 +241,6 @@ Definition PrimeField : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -259,7 +255,6 @@ Definition PrimeField : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -267,24 +262,6 @@ Definition PrimeField : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "right" |); - M.get_name (| globals, "int" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "NotImplemented" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -309,7 +286,6 @@ Definition PrimeField : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -324,7 +300,6 @@ Definition PrimeField : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -332,24 +307,6 @@ Definition PrimeField : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "right" |); - M.get_name (| globals, "int" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "NotImplemented" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -374,7 +331,6 @@ Definition PrimeField : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -382,24 +338,6 @@ Definition PrimeField : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "left" ] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "left" |); - M.get_name (| globals, "int" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "NotImplemented" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -424,7 +362,6 @@ Definition PrimeField : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -432,24 +369,6 @@ Definition PrimeField : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "right" |); - M.get_name (| globals, "int" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "NotImplemented" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -474,7 +393,6 @@ Definition PrimeField : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -489,7 +407,6 @@ Definition PrimeField : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -504,7 +421,6 @@ Definition PrimeField : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -540,7 +456,6 @@ Definition PrimeField : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -555,7 +470,6 @@ Definition PrimeField : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -583,7 +497,6 @@ Definition PrimeField : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -599,7 +512,6 @@ Definition PrimeField : Value.t := make_dict [] |) |) - |) in M.pure Constant.None_)) ); ( @@ -611,7 +523,6 @@ Definition PrimeField : Value.t := M.get_name (| globals, "self" |), UnOp.sub (| Constant.int 1 |) |) - |) in M.pure Constant.None_)) ); ( @@ -641,7 +552,6 @@ Definition PrimeField : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ) ]. @@ -684,7 +594,6 @@ Definition GaloisField : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -719,7 +628,6 @@ Definition GaloisField : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -787,7 +695,6 @@ Definition GaloisField : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ) ] @@ -801,29 +708,28 @@ Definition GaloisField : Value.t := M.get_field (| M.get_name (| globals, "tuple" |), "__new__" |), make_list [ M.get_name (| globals, "cls" |); - (BinOp.mod_ (| - M.get_name (| globals, "x" |), - M.get_field (| M.get_name (| globals, "cls" |), "PRIME" |) - |) for (* At expr: unsupported node type: list *)) + (* At expr: unsupported node type: GeneratorExp *) ], make_dict [] |) in - let _ := M.assert (| Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "self" |) - ], - make_dict [] - |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "cls" |), "MODULUS" |) - ], - make_dict [] - |) |) |) in + let _ := M.assert (| Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "self" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "cls" |), "MODULUS" |) + ], + make_dict [] + |) + |) |) in let _ := M.return_ (| M.get_name (| globals, "self" |) - |) in M.pure Constant.None_)) ); ( @@ -831,30 +737,6 @@ Definition GaloisField : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "right" |); - M.call (| - M.get_name (| globals, "type" |), - make_list [ - M.get_name (| globals, "self" |) - ], - make_dict [] - |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "NotImplemented" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -868,14 +750,10 @@ Definition GaloisField : Value.t := ], make_dict [] |); - (BinOp.add (| - M.get_name (| globals, "x" |), - M.get_name (| globals, "y" |) - |) for (* At expr: unsupported node type: list *)) + (* At expr: unsupported node type: GeneratorExp *) ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -890,7 +768,6 @@ Definition GaloisField : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -905,7 +782,6 @@ Definition GaloisField : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -913,30 +789,6 @@ Definition GaloisField : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "right" |); - M.call (| - M.get_name (| globals, "type" |), - make_list [ - M.get_name (| globals, "self" |) - ], - make_dict [] - |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "NotImplemented" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) @@ -952,14 +804,10 @@ Definition GaloisField : Value.t := ], make_dict [] |); - (BinOp.sub (| - M.get_name (| globals, "x" |), - M.get_name (| globals, "y" |) - |) for (* At expr: unsupported node type: list *)) + (* At expr: unsupported node type: GeneratorExp *) ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -967,30 +815,6 @@ Definition GaloisField : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "left" ] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "left" |); - M.call (| - M.get_name (| globals, "type" |), - make_list [ - M.get_name (| globals, "self" |) - ], - make_dict [] - |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "NotImplemented" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1004,14 +828,10 @@ Definition GaloisField : Value.t := ], make_dict [] |); - (BinOp.sub (| - M.get_name (| globals, "x" |), - M.get_name (| globals, "y" |) - |) for (* At expr: unsupported node type: list *)) + (* At expr: unsupported node type: GeneratorExp *) ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -1126,11 +946,10 @@ Definition GaloisField : Value.t := ], make_dict [] |); - M.get_subscript (| M.get_name (| globals, "mul" |), (* At expr: unsupported node type: NoneType *):M.get_name (| globals, "degree" |) |) + M.get_subscript (| M.get_name (| globals, "mul" |), Constant.None_:M.get_name (| globals, "degree" |) |) ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -1145,7 +964,6 @@ Definition GaloisField : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -1160,7 +978,6 @@ Definition GaloisField : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -1176,7 +993,6 @@ Definition GaloisField : Value.t := make_dict [] |) |) - |) in M.pure Constant.None_)) ); ( @@ -1194,11 +1010,10 @@ Definition GaloisField : Value.t := ], make_dict [] |); - (UnOp.sub (| M.get_name (| globals, "a" |) |) for (* At expr: unsupported node type: list *)) + (* At expr: unsupported node type: GeneratorExp *) ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -1220,14 +1035,10 @@ Definition GaloisField : Value.t := ], make_dict [] |); - (BinOp.mult (| - M.get_name (| globals, "x" |), - M.get_name (| globals, "n" |) - |) for (* At expr: unsupported node type: list *)) + (* At expr: unsupported node type: GeneratorExp *) ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -1256,27 +1067,16 @@ Definition GaloisField : Value.t := make_dict [] |) do let _ := - (* if *) - M.if_then_else (| - Compare.not_eq (| M.get_subscript (| M.get_name (| globals, "self" |), M.get_name (| globals, "i" |) |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "i" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. - let _ := M.raise (| M.call (| + let _ := M.raise (| Some(M.call (| M.get_name (| globals, "ValueError" |), make_list [ Constant.str "deg() does not support zero" ], make_dict [] - |) |) in + |)) M.pure Constant.None_)) ); ( @@ -1454,202 +1254,17 @@ Definition GaloisField : Value.t := make_dict [] |) do let _ := - (* if *) - M.if_then_else (| - Compare.not_eq (| M.get_subscript (| M.get_name (| globals, "x1" |), M.get_name (| globals, "i" |) |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let d1 := - M.get_name (| globals, "i" |) in - let _ := M.break (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. While Constant.bool true do let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "d1" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let ans := - M.get_name (| globals, "f1" |) in - let q := - M.call (| - M.get_name (| globals, "pow" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "x1" |), Constant.int 0 |); - UnOp.sub (| Constant.int 1 |); - M.get_field (| M.get_name (| globals, "self" |), "PRIME" |) - ], - make_dict [] - |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "ans" |) - ], - make_dict [] - |) - ], - make_dict [] - |) do - let _ := M.assign_op (| - BinOp.mult, - M.get_subscript (| M.get_name (| globals, "ans" |), M.get_name (| globals, "i" |) |), - M.get_name (| globals, "q" |) - |) in - EndFor. - let _ := M.break (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "d2" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let ans := - M.get_name (| globals, "f2" |) in - let q := - M.call (| - M.get_name (| globals, "pow" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "x2" |), Constant.int 0 |); - UnOp.sub (| Constant.int 1 |); - M.get_field (| M.get_name (| globals, "self" |), "PRIME" |) - ], - make_dict [] - |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "ans" |) - ], - make_dict [] - |) - ], - make_dict [] - |) do - let ans := BinOp.mult - M.get_name (| globals, "q" |) - M.get_name (| globals, "q" |) in - EndFor. - let _ := M.break (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "d1" |), M.get_name (| globals, "d2" |) |), - (* then *) - ltac:(M.monadic ( - let q := - BinOp.mult (| - M.get_subscript (| M.get_name (| globals, "x2" |), M.get_name (| globals, "d2" |) |), - M.call (| - M.get_name (| globals, "pow" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "x1" |), M.get_name (| globals, "d1" |) |); - UnOp.sub (| Constant.int 1 |); - M.get_field (| M.get_name (| globals, "self" |), "PRIME" |) - ], - make_dict [] - |) - |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - BinOp.sub (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "self" |), "MODULUS" |) - ], - make_dict [] - |), - BinOp.sub (| - M.get_name (| globals, "d2" |), - M.get_name (| globals, "d1" |) - |) - |) - ], - make_dict [] - |) do - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "x2" |), BinOp.add (| - M.get_name (| globals, "i" |), - BinOp.sub (| - M.get_name (| globals, "d2" |), - M.get_name (| globals, "d1" |) - |) - |) |), - BinOp.mod_ (| - BinOp.sub (| - M.get_subscript (| M.get_name (| globals, "x2" |), BinOp.add (| - M.get_name (| globals, "i" |), - BinOp.sub (| - M.get_name (| globals, "d2" |), - M.get_name (| globals, "d1" |) - |) - |) |), - BinOp.mult (| - M.get_name (| globals, "q" |), - M.get_subscript (| M.get_name (| globals, "x1" |), M.get_name (| globals, "i" |) |) - |) - |), - M.get_name (| globals, "p" |) - |) - |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "f2" |), BinOp.add (| - M.get_name (| globals, "i" |), - BinOp.sub (| - M.get_name (| globals, "d2" |), - M.get_name (| globals, "d1" |) - |) - |) |), - BinOp.mod_ (| - BinOp.sub (| - M.get_subscript (| M.get_name (| globals, "f2" |), BinOp.add (| - M.get_name (| globals, "i" |), - BinOp.sub (| - M.get_name (| globals, "d2" |), - M.get_name (| globals, "d1" |) - |) - |) |), - BinOp.mult (| - M.get_name (| globals, "q" |), - M.get_subscript (| M.get_name (| globals, "f1" |), M.get_name (| globals, "i" |) |) - |) - |), - M.get_name (| globals, "p" |) - |) - |) in - EndFor. - While Compare.eq (| M.get_subscript (| M.get_name (| globals, "x2" |), M.get_name (| globals, "d2" |) |), Constant.int 0 |) do - let d2 := BinOp.sub - Constant.int 1 - Constant.int 1 in - EndWhile. - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let q := BinOp.mult (| M.get_subscript (| M.get_name (| globals, "x1" |), M.get_name (| globals, "d1" |) |), @@ -1733,7 +1348,10 @@ Definition GaloisField : Value.t := |) |) in EndFor. - While Compare.eq (| M.get_subscript (| M.get_name (| globals, "x1" |), M.get_name (| globals, "d1" |) |), Constant.int 0 |) do + While Compare.eq (| + M.get_subscript (| M.get_name (| globals, "x1" |), M.get_name (| globals, "d1" |) |), + Constant.int 0 + |) do let d1 := BinOp.sub Constant.int 1 Constant.int 1 in @@ -1756,7 +1374,6 @@ Definition GaloisField : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -1772,22 +1389,6 @@ Definition GaloisField : Value.t := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "exponent" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let self := - M.call (| - M.get_field (| M.get_name (| globals, "self" |), "multiplicative_inverse" |), - make_list [], - make_dict [] - |) in - let exponent := - UnOp.sub (| M.get_name (| globals, "exponent" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let res := @@ -1820,22 +1421,11 @@ Definition GaloisField : Value.t := |) in let s := M.get_name (| globals, "self" |) in - While Compare.not_eq (| M.get_name (| globals, "exponent" |), Constant.int 0 |) do + While Compare.not_eq (| + M.get_name (| globals, "exponent" |), + Constant.int 0 + |) do let _ := - (* if *) - M.if_then_else (| - Compare.eq (| BinOp.mod_ (| - M.get_name (| globals, "exponent" |), - Constant.int 2 - |), Constant.int 1 |), - (* then *) - ltac:(M.monadic ( - let res := BinOp.mult - M.get_name (| globals, "s" |) - M.get_name (| globals, "s" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let s := BinOp.mult @@ -1847,7 +1437,6 @@ Definition GaloisField : Value.t := EndWhile. let _ := M.return_ (| M.get_name (| globals, "res" |) - |) in M.pure Constant.None_)) ); ( @@ -1862,7 +1451,6 @@ Definition GaloisField : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ); ( @@ -1923,7 +1511,6 @@ Definition GaloisField : Value.t := EndFor. let _ := M.return_ (| M.get_name (| globals, "ans" |) - |) in M.pure Constant.None_)) ) ]. diff --git a/CoqOfPython/ethereum/crypto/hash.v b/CoqOfPython/ethereum/crypto/hash.v index b7e39d0..fff054d 100644 --- a/CoqOfPython/ethereum/crypto/hash.v +++ b/CoqOfPython/ethereum/crypto/hash.v @@ -77,7 +77,6 @@ Definition keccak256 : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition keccak512 : Value.t -> Value.t -> M := @@ -120,5 +119,4 @@ Definition keccak512 : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/bloom.v b/CoqOfPython/ethereum/dao_fork/bloom.v index 04b5d9f..04650ff 100644 --- a/CoqOfPython/ethereum/dao_fork/bloom.v +++ b/CoqOfPython/ethereum/dao_fork/bloom.v @@ -72,10 +72,7 @@ Definition add_to_bloom : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |):BinOp.add (| - M.get_name (| globals, "idx" |), - Constant.int 2 - |) |) + M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |) |) ], make_dict [] |), @@ -160,5 +157,4 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/dao.v b/CoqOfPython/ethereum/dao_fork/dao.v index 047dd0d..cc4c36a 100644 --- a/CoqOfPython/ethereum/dao_fork/dao.v +++ b/CoqOfPython/ethereum/dao_fork/dao.v @@ -33,13 +33,7 @@ Axiom utils_hexadecimal_hex_to_address : IsGlobalAlias globals utils.hexadecimal.globals "hex_to_address". Definition DAO_ACCOUNTS : Value.t := M.run ltac:(M.monadic ( - [M.call (| - M.get_name (| globals, "hex_to_address" |), - make_list [ - M.get_name (| globals, "address" |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)] + (* At expr: unsupported node type: ListComp *) )). Definition DAO_RECOVERY : Value.t := M.run ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/dao_fork/fork.v b/CoqOfPython/ethereum/dao_fork/fork.v index b2ecaf9..7533ecd 100644 --- a/CoqOfPython/ethereum/dao_fork/fork.v +++ b/CoqOfPython/ethereum/dao_fork/fork.v @@ -244,7 +244,6 @@ Definition apply_fork : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "old" |) - |) in M.pure Constant.None_)). Definition get_last_256_block_hashes : Value.t -> Value.t -> M := @@ -270,25 +269,8 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := Hashes of the recent 256 blocks in order of increasing block number. " in let recent_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |) |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "recent_blocks" |) - ], - make_dict [] - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - make_list [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let recent_block_hashes := @@ -327,7 +309,6 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "recent_block_hashes" |) - |) in M.pure Constant.None_)). Definition state_transition : Value.t -> Value.t -> M := @@ -398,7 +379,10 @@ Definition state_transition : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_gas_used" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "gas_used" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_gas_used" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "gas_used" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -406,7 +390,10 @@ Definition state_transition : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "transactions_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "transactions_root" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "transactions_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "transactions_root" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -414,7 +401,10 @@ Definition state_transition : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "state_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "state_root" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "state_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "state_root" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -422,7 +412,10 @@ Definition state_transition : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "receipt_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "receipt_root" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "receipt_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "receipt_root" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -430,7 +423,10 @@ Definition state_transition : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_logs_bloom" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "bloom" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_logs_bloom" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "bloom" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -443,24 +439,6 @@ Definition state_transition : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "chain" |), "blocks" |) - ], - make_dict [] - |), Constant.int 255 |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign (| - M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |):(* At expr: unsupported node type: NoneType *) |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -488,7 +466,10 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.gt (| M.get_field (| M.get_name (| globals, "header" |), "timestamp" |), M.get_field (| M.get_name (| globals, "parent_header" |), "timestamp" |) |); + Compare.gt (| + M.get_field (| M.get_name (| globals, "header" |), "timestamp" |), + M.get_field (| M.get_name (| globals, "parent_header" |), "timestamp" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -496,10 +477,13 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "number" |), BinOp.add (| - M.get_field (| M.get_name (| globals, "parent_header" |), "number" |), - Constant.int 1 - |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "number" |), + BinOp.add (| + M.get_field (| M.get_name (| globals, "parent_header" |), "number" |), + Constant.int 1 + |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -522,13 +506,16 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt_e (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) - ], - make_dict [] - |), Constant.int 32 |); + Compare.lt_e (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) + ], + make_dict [] + |), + Constant.int 32 + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -547,7 +534,10 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "difficulty" |), M.get_name (| globals, "block_difficulty" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "difficulty" |), + M.get_name (| globals, "block_difficulty" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -569,36 +559,15 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |), M.get_name (| globals, "block_parent_hash" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |), + M.get_name (| globals, "block_parent_hash" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.gt_e (| M.get_field (| M.get_name (| globals, "header" |), "number" |), M.get_field (| M.get_name (| globals, "FORK_CRITERIA" |), "block_number" |) |), - ltac:(M.monadic ( - Compare.lt (| M.get_field (| M.get_name (| globals, "header" |), "number" |), BinOp.add (| - M.get_field (| M.get_name (| globals, "FORK_CRITERIA" |), "block_number" |), - Constant.int 10 - |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "ensure" |), - make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "extra_data" |), (* At constant: unsupported node type: Constant *) |); - M.get_name (| globals, "InvalidBlock" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -659,7 +628,6 @@ Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition validate_proof_of_work : Value.t -> Value.t -> M := @@ -717,7 +685,10 @@ Definition validate_proof_of_work : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_name (| globals, "mix_digest" |), M.get_field (| M.get_name (| globals, "header" |), "mix_digest" |) |); + Compare.eq (| + M.get_name (| globals, "mix_digest" |), + M.get_field (| M.get_name (| globals, "header" |), "mix_digest" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -725,16 +696,19 @@ Definition validate_proof_of_work : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt_e (| M.call (| - M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), - make_list [ - M.get_name (| globals, "result" |) - ], - make_dict [] - |), BinOp.floor_div (| - M.get_name (| globals, "U256_CEIL_VALUE" |), - M.get_field (| M.get_name (| globals, "header" |), "difficulty" |) - |) |); + Compare.lt_e (| + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "result" |) + ], + make_dict [] + |), + BinOp.floor_div (| + M.get_name (| globals, "U256_CEIL_VALUE" |), + M.get_field (| M.get_name (| globals, "header" |), "difficulty" |) + |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -767,7 +741,10 @@ Definition check_transaction : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt_e (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_name (| globals, "gas_available" |) |); + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_name (| globals, "gas_available" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -782,7 +759,6 @@ Definition check_transaction : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "sender_address" |) - |) in M.pure Constant.None_)). Definition make_receipt : Value.t -> Value.t -> M := @@ -816,7 +792,6 @@ Definition make_receipt : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "receipt" |) - |) in M.pure Constant.None_)). Definition ApplyBodyOutput : Value.t := @@ -1030,7 +1005,6 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition validate_ommers : Value.t -> Value.t -> M := @@ -1068,42 +1042,39 @@ Definition validate_ommers : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), - make_list [ - M.get_name (| globals, "ommers" |) - ], - make_dict [] - |), M.get_field (| M.get_name (| globals, "block_header" |), "ommers_hash" |) |); + Compare.eq (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + M.get_field (| M.get_name (| globals, "block_header" |), "ommers_hash" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "ommers" |) - ], - make_dict [] - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - (* At expr: unsupported node type: Compare *); + BoolOp.and (| + Compare.lt_e (| + Constant.int 1, + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |), + ltac:(M.monadic ( + Compare.lt (| + M.get_field (| M.get_name (| globals, "ommer" |), "number" |), + M.get_field (| M.get_name (| globals, "block_header" |), "number" |) + |) + )) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1128,47 +1099,47 @@ Definition validate_ommers : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt_e (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "ommers" |) - ], - make_dict [] - |), Constant.int 2 |); + Compare.lt_e (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + Constant.int 2 + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] |) in let ommers_hashes := - [M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), - make_list [ - M.get_name (| globals, "ommer" |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)] in + (* At expr: unsupported node type: ListComp *) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "ommers_hashes" |) - ], - make_dict [] - |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.call (| - M.get_name (| globals, "set" |), - make_list [ - M.get_name (| globals, "ommers_hashes" |) - ], - make_dict [] - |) - ], - make_dict [] - |) |); + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers_hashes" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_name (| globals, "set" |), + make_list [ + M.get_name (| globals, "ommers_hashes" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1177,28 +1148,16 @@ Definition validate_ommers : Value.t -> Value.t -> M := M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| BinOp.add (| M.get_name (| globals, "MAX_OMMER_DEPTH" |), Constant.int 1 - |) |):(* At expr: unsupported node type: NoneType *) |) in + |) |) |) in let recent_canonical_block_hashes := - {M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), - make_list [ - M.get_field (| M.get_name (| globals, "block" |), "header" |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)} in + (* At expr: unsupported node type: SetComp *) in (* At stmt: unsupported node type: AnnAssign *) For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_canonical_blocks" |) do let recent_ommers_hashes := M.call (| M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), make_list [ - {M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), - make_list [ - M.get_name (| globals, "ommer" |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)} + (* At expr: unsupported node type: SetComp *) ], make_dict [] |) in @@ -1215,7 +1174,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.not_eq (| M.get_name (| globals, "ommer_hash" |), M.get_name (| globals, "block_hash" |) |); + Compare.not_eq (| + M.get_name (| globals, "ommer_hash" |), + M.get_name (| globals, "block_hash" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1223,7 +1185,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.not_in (| M.get_name (| globals, "ommer_hash" |), M.get_name (| globals, "recent_canonical_block_hashes" |) |); + Compare.not_in (| + M.get_name (| globals, "ommer_hash" |), + M.get_name (| globals, "recent_canonical_block_hashes" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1231,7 +1196,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.not_in (| M.get_name (| globals, "ommer_hash" |), M.get_name (| globals, "recent_ommers_hashes" |) |); + Compare.not_in (| + M.get_name (| globals, "ommer_hash" |), + M.get_name (| globals, "recent_ommers_hashes" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1244,7 +1212,18 @@ Definition validate_ommers : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - (* At expr: unsupported node type: Compare *); + BoolOp.and (| + Compare.lt_e (| + Constant.int 1, + M.get_name (| globals, "ommer_age" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_name (| globals, "ommer_age" |), + M.get_name (| globals, "MAX_OMMER_DEPTH" |) + |) + )) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1252,7 +1231,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.in (| M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), M.get_name (| globals, "recent_canonical_block_hashes" |) |); + Compare.in (| + M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), + M.get_name (| globals, "recent_canonical_block_hashes" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1260,7 +1242,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.not_eq (| M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), M.get_field (| M.get_name (| globals, "block_header" |), "parent_hash" |) |); + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), + M.get_field (| M.get_name (| globals, "block_header" |), "parent_hash" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1419,7 +1404,10 @@ Definition process_transaction : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "sender_account" |), "nonce" |), M.get_field (| M.get_name (| globals, "tx" |), "nonce" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "sender_account" |), "nonce" |), + M.get_field (| M.get_name (| globals, "tx" |), "nonce" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1427,10 +1415,13 @@ Definition process_transaction : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.gt_e (| M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), BinOp.add (| - M.get_name (| globals, "gas_fee" |), - M.get_field (| M.get_name (| globals, "tx" |), "value" |) - |) |); + Compare.gt_e (| + M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), + BinOp.add (| + M.get_name (| globals, "gas_fee" |), + M.get_field (| M.get_name (| globals, "tx" |), "value" |) + |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1438,11 +1429,14 @@ Definition process_transaction : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "sender_account" |), "code" |), M.call (| - M.get_name (| globals, "bytearray" |), - make_list [], - make_dict [] - |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "sender_account" |), "code" |), + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [], + make_dict [] + |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1597,7 +1591,6 @@ Definition process_transaction : Value.t -> Value.t -> M := EndFor. let _ := M.return_ (| make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |) ] - |) in M.pure Constant.None_)). Definition validate_transaction : Value.t -> Value.t -> M := @@ -1629,24 +1622,29 @@ Definition validate_transaction : Value.t -> Value.t -> M := " in let _ := M.return_ (| BoolOp.and (| - Compare.lt_e (| M.call (| - M.get_name (| globals, "calculate_intrinsic_cost" |), - make_list [ - M.get_name (| globals, "tx" |) - ], - make_dict [] - |), M.get_field (| M.get_name (| globals, "tx" |), "gas" |) |), + Compare.lt_e (| + M.call (| + M.get_name (| globals, "calculate_intrinsic_cost" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |), + M.get_field (| M.get_name (| globals, "tx" |), "gas" |) + |), ltac:(M.monadic ( - Compare.lt (| M.get_field (| M.get_name (| globals, "tx" |), "nonce" |), BinOp.sub (| + Compare.lt (| + M.get_field (| M.get_name (| globals, "tx" |), "nonce" |), + BinOp.sub (| BinOp.pow (| Constant.int 2, Constant.int 64 |), Constant.int 1 - |) |) + |) + |) )) |) - |) in M.pure Constant.None_)). Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := @@ -1678,17 +1676,6 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := Constant.int 0 in For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "byte" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let data_cost := BinOp.add - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let data_cost := BinOp.add M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in @@ -1696,22 +1683,6 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := )) |) in EndFor. let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_name (| globals, "tx" |), "to" |), M.call (| - M.get_name (| globals, "Bytes0" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let create_cost := - M.get_name (| globals, "TX_CREATE_COST" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let create_cost := Constant.int 0 in M.pure Constant.None_ @@ -1730,7 +1701,6 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition recover_sender : Value.t -> Value.t -> M := @@ -1763,9 +1733,15 @@ Definition recover_sender : Value.t -> Value.t -> M := M.get_name (| globals, "ensure" |), make_list [ BoolOp.or (| - Compare.eq (| M.get_name (| globals, "v" |), Constant.int 27 |), + Compare.eq (| + M.get_name (| globals, "v" |), + Constant.int 27 + |), ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "v" |), Constant.int 28 |) + Compare.eq (| + M.get_name (| globals, "v" |), + Constant.int 28 + |) )) |); M.get_name (| globals, "InvalidBlock" |) @@ -1776,9 +1752,15 @@ Definition recover_sender : Value.t -> Value.t -> M := M.get_name (| globals, "ensure" |), make_list [ BoolOp.and (| - Compare.lt (| Constant.int 0, M.get_name (| globals, "r" |) |), + Compare.lt (| + Constant.int 0, + M.get_name (| globals, "r" |) + |), ltac:(M.monadic ( - Compare.lt (| M.get_name (| globals, "r" |), M.get_name (| globals, "SECP256K1N" |) |) + Compare.lt (| + M.get_name (| globals, "r" |), + M.get_name (| globals, "SECP256K1N" |) + |) )) |); M.get_name (| globals, "InvalidBlock" |) @@ -1789,12 +1771,18 @@ Definition recover_sender : Value.t -> Value.t -> M := M.get_name (| globals, "ensure" |), make_list [ BoolOp.and (| - Compare.lt (| Constant.int 0, M.get_name (| globals, "s" |) |), + Compare.lt (| + Constant.int 0, + M.get_name (| globals, "s" |) + |), ltac:(M.monadic ( - Compare.lt_e (| M.get_name (| globals, "s" |), BinOp.floor_div (| + Compare.lt_e (| + M.get_name (| globals, "s" |), + BinOp.floor_div (| M.get_name (| globals, "SECP256K1N" |), Constant.int 2 - |) |) + |) + |) )) |); M.get_name (| globals, "InvalidBlock" |) @@ -1831,11 +1819,10 @@ Definition recover_sender : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12:Constant.int 32 |) + |), Constant.int 12 |) ], make_dict [] |) - |) in M.pure Constant.None_)). Definition signing_hash : Value.t -> Value.t -> M := @@ -1872,7 +1859,6 @@ Definition signing_hash : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition compute_header_hash : Value.t -> Value.t -> M := @@ -1923,7 +1909,6 @@ Definition compute_header_hash : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition check_gas_limit : Value.t -> Value.t -> M := @@ -1962,56 +1947,16 @@ Definition check_gas_limit : Value.t -> Value.t -> M := M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "gas_limit" |), BinOp.add (| - M.get_name (| globals, "parent_gas_limit" |), - M.get_name (| globals, "max_adjustment_delta" |) - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.bool false - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt_e (| M.get_name (| globals, "gas_limit" |), BinOp.sub (| - M.get_name (| globals, "parent_gas_limit" |), - M.get_name (| globals, "max_adjustment_delta" |) - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.bool false - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "gas_limit" |), M.get_name (| globals, "GAS_LIMIT_MINIMUM" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.bool false - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| Constant.bool true - |) in M.pure Constant.None_)). Definition calculate_block_difficulty : Value.t -> Value.t -> M := @@ -2115,23 +2060,6 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := Constant.int 2 |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "num_bomb_periods" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let difficulty := BinOp.add - BinOp.pow (| - Constant.int 2, - M.get_name (| globals, "num_bomb_periods" |) - |) - BinOp.pow (| - Constant.int 2, - M.get_name (| globals, "num_bomb_periods" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -2149,5 +2077,4 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/fork_types.v b/CoqOfPython/ethereum/dao_fork/fork_types.v index d12953d..5c7dac3 100644 --- a/CoqOfPython/ethereum/dao_fork/fork_types.v +++ b/CoqOfPython/ethereum/dao_fork/fork_types.v @@ -98,5 +98,4 @@ Definition encode_account : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/state.v b/CoqOfPython/ethereum/dao_fork/state.v index 38fe9d1..2ba095e 100644 --- a/CoqOfPython/ethereum/dao_fork/state.v +++ b/CoqOfPython/ethereum/dao_fork/state.v @@ -123,13 +123,7 @@ Definition begin_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) ], make_dict [] - |); {M.get_name (| globals, "k" |): M.call (| - M.get_name (| globals, "copy_trie" |), - make_list [ - M.get_name (| globals, "t" |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)} ] + |); (* At expr: unsupported node type: DictComp *) ] ], make_dict [] |) in @@ -207,27 +201,8 @@ Definition get_account : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "account" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "account" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_ACCOUNT" |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -262,7 +237,6 @@ Definition get_account_optional : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "account" |) - |) in M.pure Constant.None_)). Definition set_account : Value.t -> Value.t -> M := @@ -342,15 +316,6 @@ Definition destroy_storage : Value.t -> Value.t -> M := Address of account whose storage is to be deleted. " in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -385,23 +350,6 @@ Definition get_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let value := @@ -423,7 +371,6 @@ Definition get_storage : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "value" |) - |) in M.pure Constant.None_)). Definition set_storage : Value.t -> Value.t -> M := @@ -444,14 +391,17 @@ Definition set_storage : Value.t -> Value.t -> M := value : `U256` Value to set at the key. " in - let _ := M.assert (| Compare.is_not (| M.call (| - M.get_name (| globals, "trie_get" |), - make_list [ - M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), Constant.None_ |) |) in + let _ := M.assert (| Compare.is_not (| + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + Constant.None_ + |) |) in let trie := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), @@ -461,24 +411,6 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let trie := - M.call (| - M.get_name (| globals, "Trie" |), - make_list [], - make_dict [] - |) in - let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), - M.get_name (| globals, "trie" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -491,15 +423,6 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), {} |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -524,26 +447,8 @@ Definition storage_root : Value.t -> Value.t -> M := " in let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "root" |), - make_list [ - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_TRIE_ROOT" |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -574,7 +479,6 @@ Definition state_root : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition account_exists : Value.t -> Value.t -> M := @@ -596,15 +500,17 @@ Definition account_exists : Value.t -> Value.t -> M := True if account exists in the state trie, False otherwise " in let _ := M.return_ (| - Compare.is_not (| M.call (| - M.get_name (| globals, "get_account_optional" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), Constant.None_ |) - |) in + Compare.is_not (| + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + Constant.None_ + |) M.pure Constant.None_)). Definition account_has_code_or_nonce : Value.t -> Value.t -> M := @@ -637,18 +543,23 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := |) in let _ := M.return_ (| BoolOp.or (| - Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( - Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |) + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |) )) |) - |) in M.pure Constant.None_)). Definition modify_state : Value.t -> Value.t -> M := @@ -754,30 +665,6 @@ Definition touch_account : Value.t -> Value.t -> M := The address of the account that need to initialised. " in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "account_exists" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "set_account" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |); - M.get_name (| globals, "EMPTY_ACCOUNT" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/trie.v b/CoqOfPython/ethereum/dao_fork/trie.v index 884333c..c119364 100644 --- a/CoqOfPython/ethereum/dao_fork/trie.v +++ b/CoqOfPython/ethereum/dao_fork/trie.v @@ -202,96 +202,16 @@ Definition encode_internal_node : Value.t -> Value.t -> M := " in (* At stmt: unsupported node type: AnnAssign *) let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "node" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let unencoded := - (* At constant: unsupported node type: Constant *) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "LeafNode" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let unencoded := - make_tuple [ M.call (| - M.get_name (| globals, "nibble_list_to_compact" |), - make_list [ - M.get_field (| M.get_name (| globals, "node" |), "rest_of_key" |); - Constant.bool true - ], - make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "ExtensionNode" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let unencoded := - make_tuple [ M.call (| - M.get_name (| globals, "nibble_list_to_compact" |), - make_list [ - M.get_field (| M.get_name (| globals, "node" |), "key_segment" |); - Constant.bool false - ], - make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "BranchNode" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let unencoded := - BinOp.add (| - M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), - make_list [ - M.get_field (| M.get_name (| globals, "node" |), "value" |) - ] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.call (| + let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ (* At expr: unsupported node type: JoinedStr *) ], make_dict [] - |) |) in + |)) M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -309,23 +229,6 @@ Definition encode_internal_node : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "encoded" |) - ], - make_dict [] - |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "unencoded" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_name (| globals, "keccak256" |), @@ -334,7 +237,6 @@ Definition encode_internal_node : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -348,83 +250,8 @@ Definition encode_node : Value.t -> Value.t -> M := Currently mostly an unimplemented stub. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "storage_root" |), Constant.None_ |) |) in - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "encode_account" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "storage_root" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - make_tuple [ M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "U256" |) ] - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.call (| - M.get_name (| globals, "cast" |), - make_list [ - M.get_field (| M.get_name (| globals, "rlp" |), "RLP" |); - M.get_name (| globals, "node" |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "Bytes" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "node" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "previous_trie" |), "encode_node" |), @@ -434,7 +261,6 @@ Definition encode_node : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -486,7 +312,6 @@ Definition copy_trie : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition trie_set : Value.t -> Value.t -> M := @@ -508,26 +333,6 @@ Definition trie_set : Value.t -> Value.t -> M := Node to insert at `key`. " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "value" |), M.get_field (| M.get_name (| globals, "trie" |), "default" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "key" |), M.get_field (| M.get_name (| globals, "trie" |), "_data" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), M.get_name (| globals, "value" |) @@ -565,7 +370,6 @@ Definition trie_get : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition common_prefix_length : Value.t -> Value.t -> M := @@ -588,28 +392,6 @@ Definition common_prefix_length : Value.t -> Value.t -> M := make_dict [] |) do let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| M.get_name (| globals, "i" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "b" |) - ], - make_dict [] - |) |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "i" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -621,7 +403,6 @@ Definition common_prefix_length : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition nibble_list_to_compact : Value.t -> Value.t -> M := @@ -667,68 +448,6 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| BinOp.mod_ (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |), - Constant.int 2 - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_name (| globals, "compact" |), "append" |), - make_list [ - BinOp.mult (| - Constant.int 16, - BinOp.mult (| - Constant.int 2, - M.get_name (| globals, "is_leaf" |) - |) - |) - ], - make_dict [] - |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 0; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |); - Constant.int 2 - ], - make_dict [] - |) do - let _ := M.call (| - M.get_field (| M.get_name (| globals, "compact" |), "append" |), - make_list [ - BinOp.add (| - BinOp.mult (| - Constant.int 16, - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) - |), - M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) - |) - ], - make_dict [] - |) in - EndFor. - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ @@ -790,7 +509,6 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition bytes_to_nibble_list : Value.t -> Value.t -> M := @@ -868,7 +586,6 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition _prepare_trie : Value.t -> Value.t -> M := @@ -898,45 +615,6 @@ Definition _prepare_trie : Value.t -> Value.t -> M := make_dict [] |) do let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "value" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in - let address := - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in - let encoded_value := - M.call (| - M.get_name (| globals, "encode_node" |), - make_list [ - M.get_name (| globals, "value" |); - M.call (| - M.get_name (| globals, "get_storage_root" |), - make_list [ - M.get_name (| globals, "address" |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let encoded_value := M.call (| M.get_name (| globals, "encode_node" |), @@ -950,29 +628,16 @@ Definition _prepare_trie : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.not_eq (| M.get_name (| globals, "encoded_value" |), (* At constant: unsupported node type: Constant *) |); + Compare.not_eq (| + M.get_name (| globals, "encoded_value" |), + Constant.bytes "" + |); M.get_name (| globals, "AssertionError" |) ], make_dict [] |) in (* At stmt: unsupported node type: AnnAssign *) let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "trie" |), "secured" |), - (* then *) - ltac:(M.monadic ( - let key := - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let key := M.get_name (| globals, "preimage" |) in M.pure Constant.None_ @@ -990,7 +655,6 @@ Definition _prepare_trie : Value.t -> Value.t -> M := EndFor. let _ := M.return_ (| M.get_name (| globals, "mapped" |) - |) in M.pure Constant.None_)). Definition root : Value.t -> Value.t -> M := @@ -1044,41 +708,6 @@ Definition root : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "root_node" |) - ], - make_dict [] - |) - ], - make_dict [] - |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "root_node" |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -1095,7 +724,6 @@ Definition root : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -1122,23 +750,6 @@ Definition patricialize : Value.t -> Value.t -> M := Root node of `obj`. " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "obj" |) - ], - make_dict [] - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.None_ - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let arbitrary_key := @@ -1156,36 +767,10 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "obj" |) - ], - make_dict [] - |), Constant.int 1 |), - (* then *) - ltac:(M.monadic ( - let leaf := - M.call (| - M.get_name (| globals, "LeafNode" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |); - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) - ], - make_dict [] - |) in - let _ := M.return_ (| - M.get_name (| globals, "leaf" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let substring := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |) |) in let prefix_length := M.call (| M.get_name (| globals, "len" |), @@ -1204,7 +789,7 @@ Definition patricialize : Value.t -> Value.t -> M := M.get_name (| globals, "common_prefix_length" |), make_list [ M.get_name (| globals, "substring" |); - M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) + M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) ], make_dict [] |) @@ -1212,58 +797,10 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.break (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let prefix := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):BinOp.add (| - M.get_name (| globals, "level" |), - M.get_name (| globals, "prefix_length" |) - |) |) in - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "ExtensionNode" |), - make_list [ - M.get_name (| globals, "prefix" |); - M.call (| - M.get_name (| globals, "encode_internal_node" |), - make_list [ - M.call (| - M.get_name (| globals, "patricialize" |), - make_list [ - M.get_name (| globals, "obj" |); - BinOp.add (| - M.get_name (| globals, "level" |), - M.get_name (| globals, "prefix_length" |) - |) - ], - make_dict [] - |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) @@ -1283,44 +820,9 @@ Definition patricialize : Value.t -> Value.t -> M := |) in EndFor. let value := - (* At constant: unsupported node type: Constant *) in + Constant.bytes "" in For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "key" |) - ], - make_dict [] - |), M.get_name (| globals, "level" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); - make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "AssertionError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let value := - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) @@ -1332,26 +834,9 @@ Definition patricialize : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "BranchNode" |), make_list [ - [M.call (| - M.get_name (| globals, "encode_internal_node" |), - make_list [ - M.call (| - M.get_name (| globals, "patricialize" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "branches" |), M.get_name (| globals, "k" |) |); - BinOp.add (| - M.get_name (| globals, "level" |), - Constant.int 1 - |) - ], - make_dict [] - |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)]; + (* At expr: unsupported node type: ListComp *); M.get_name (| globals, "value" |) ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/utils/address.v b/CoqOfPython/ethereum/dao_fork/utils/address.v index 460935f..03d5181 100644 --- a/CoqOfPython/ethereum/dao_fork/utils/address.v +++ b/CoqOfPython/ethereum/dao_fork/utils/address.v @@ -67,11 +67,10 @@ Definition to_address : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), make_list [], make_dict [] - |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) + |), UnOp.sub (| Constant.int 20 |) |) ], make_dict [] |) - |) in M.pure Constant.None_)). Definition compute_contract_address : Value.t -> Value.t -> M := @@ -111,7 +110,7 @@ Definition compute_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -129,5 +128,4 @@ Definition compute_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/utils/hexadecimal.v b/CoqOfPython/ethereum/dao_fork/utils/hexadecimal.v index ca91cac..1a063da 100644 --- a/CoqOfPython/ethereum/dao_fork/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/dao_fork/utils/hexadecimal.v @@ -66,7 +66,6 @@ Definition hex_to_root : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition hex_to_bloom : Value.t -> Value.t -> M := @@ -105,7 +104,6 @@ Definition hex_to_bloom : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition hex_to_address : Value.t -> Value.t -> M := @@ -151,5 +149,4 @@ Definition hex_to_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/utils/message.v b/CoqOfPython/ethereum/dao_fork/utils/message.v index a459724..bee1e25 100644 --- a/CoqOfPython/ethereum/dao_fork/utils/message.v +++ b/CoqOfPython/ethereum/dao_fork/utils/message.v @@ -84,105 +84,14 @@ Definition prepare_message : Value.t -> Value.t -> M := Items containing contract creation or message call specific data. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "target" |); - M.get_name (| globals, "Bytes0" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let current_target := - M.call (| - M.get_name (| globals, "compute_contract_address" |), - make_list [ - M.get_name (| globals, "caller" |); - BinOp.sub (| - M.get_field (| M.call (| - M.get_name (| globals, "get_account" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "caller" |) - ], - make_dict [] - |), "nonce" |), - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 1 - ], - make_dict [] - |) - |) - ], - make_dict [] - |) in - let msg_data := - M.call (| - M.get_name (| globals, "Bytes" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |) in - let code := - M.get_name (| globals, "data" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "target" |); - M.get_name (| globals, "Address" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let current_target := - M.get_name (| globals, "target" |) in - let msg_data := - M.get_name (| globals, "data" |) in - let code := - M.get_field (| M.call (| - M.get_name (| globals, "get_account" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "target" |) - ], - make_dict [] - |), "code" |) in - let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "code_address" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let code_address := - M.get_name (| globals, "target" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.call (| + let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "Target must be address or empty bytes" ], make_dict [] - |) |) in + |)) M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -193,5 +102,4 @@ Definition prepare_message : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/vm/gas.v b/CoqOfPython/ethereum/dao_fork/vm/gas.v new file mode 100644 index 0000000..eef500a --- /dev/null +++ b/CoqOfPython/ethereum/dao_fork/vm/gas.v @@ -0,0 +1,769 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Gas +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +EVM gas constants and calculators. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.trace. +Axiom ethereum_trace_GasAndRefund : + IsGlobalAlias globals ethereum.trace.globals "GasAndRefund". +Axiom ethereum_trace_evm_trace : + IsGlobalAlias globals ethereum.trace.globals "evm_trace". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_State : + IsGlobalAlias globals state.globals "State". +Axiom state_account_exists : + IsGlobalAlias globals state.globals "account_exists". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". + +Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) +)). + +Definition GAS_BASE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 2 + ], + make_dict [] + |) +)). + +Definition GAS_VERY_LOW : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_SLOAD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 50 + ], + make_dict [] + |) +)). + +Definition GAS_STORAGE_SET : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 20000 + ], + make_dict [] + |) +)). + +Definition GAS_STORAGE_UPDATE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5000 + ], + make_dict [] + |) +)). + +Definition GAS_STORAGE_CLEAR_REFUND : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 15000 + ], + make_dict [] + |) +)). + +Definition GAS_LOW : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5 + ], + make_dict [] + |) +)). + +Definition GAS_MID : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 8 + ], + make_dict [] + |) +)). + +Definition GAS_HIGH : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 10 + ], + make_dict [] + |) +)). + +Definition GAS_EXPONENTIATION : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 10 + ], + make_dict [] + |) +)). + +Definition GAS_EXPONENTIATION_PER_BYTE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 10 + ], + make_dict [] + |) +)). + +Definition GAS_MEMORY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_KECCAK256 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 30 + ], + make_dict [] + |) +)). + +Definition GAS_KECCAK256_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 6 + ], + make_dict [] + |) +)). + +Definition GAS_COPY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_BLOCK_HASH : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 20 + ], + make_dict [] + |) +)). + +Definition GAS_EXTERNAL : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 20 + ], + make_dict [] + |) +)). + +Definition GAS_BALANCE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 20 + ], + make_dict [] + |) +)). + +Definition GAS_LOG : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 375 + ], + make_dict [] + |) +)). + +Definition GAS_LOG_DATA : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 8 + ], + make_dict [] + |) +)). + +Definition GAS_LOG_TOPIC : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 375 + ], + make_dict [] + |) +)). + +Definition GAS_CREATE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 32000 + ], + make_dict [] + |) +)). + +Definition GAS_CODE_DEPOSIT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 200 + ], + make_dict [] + |) +)). + +Definition GAS_ZERO : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) +)). + +Definition GAS_CALL : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 40 + ], + make_dict [] + |) +)). + +Definition GAS_NEW_ACCOUNT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 25000 + ], + make_dict [] + |) +)). + +Definition GAS_CALL_VALUE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 9000 + ], + make_dict [] + |) +)). + +Definition GAS_CALL_STIPEND : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 2300 + ], + make_dict [] + |) +)). + +Definition REFUND_SELF_DESTRUCT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 24000 + ], + make_dict [] + |) +)). + +Definition GAS_ECRECOVER : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3000 + ], + make_dict [] + |) +)). + +Definition GAS_SHA256 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 60 + ], + make_dict [] + |) +)). + +Definition GAS_SHA256_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 12 + ], + make_dict [] + |) +)). + +Definition GAS_RIPEMD160 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 600 + ], + make_dict [] + |) +)). + +Definition GAS_RIPEMD160_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 120 + ], + make_dict [] + |) +)). + +Definition GAS_IDENTITY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 15 + ], + make_dict [] + |) +)). + +Definition GAS_IDENTITY_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition ExtendMemory : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition MessageCallGas : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition charge_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "amount" ] |) in + let _ := Constant.str " + Subtracts `amount` from `evm.gas_left`. + + Parameters + ---------- + evm : + The current EVM. + amount : + The amount of gas the current operation requires. + + " in + let _ := M.call (| + M.get_name (| globals, "evm_trace" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "GasAndRefund" |), + make_list [ + M.get_name (| globals, "amount" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + let _ := M.assign_op (| + BinOp.sub, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "amount" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition calculate_memory_gas_cost : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "size_in_bytes" ] |) in + let _ := Constant.str " + Calculates the gas cost for allocating memory + to the smallest multiple of 32 bytes, + such that the allocated size is at least as big as the given size. + + Parameters + ---------- + size_in_bytes : + The size of the data in bytes. + + Returns + ------- + total_gas_cost : `ethereum.base_types.Uint` + The gas cost for storing data in memory. + " in + let size_in_words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "size_in_bytes" |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let linear_cost := + BinOp.mult (| + M.get_name (| globals, "size_in_words" |), + M.get_name (| globals, "GAS_MEMORY" |) + |) in + let quadratic_cost := + BinOp.floor_div (| + BinOp.pow (| + M.get_name (| globals, "size_in_words" |), + Constant.int 2 + |), + Constant.int 512 + |) in + let total_gas_cost := + BinOp.add (| + M.get_name (| globals, "linear_cost" |), + M.get_name (| globals, "quadratic_cost" |) + |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_)). + +Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "memory"; "extensions" ] |) in + let _ := Constant.str " + Calculates the gas amount to extend memory + + Parameters + ---------- + memory : + Memory contents of the EVM. + extensions: + List of extensions to be made to the memory. + Consists of a tuple of start position and size. + + Returns + ------- + extend_memory: `ExtendMemory` + " in + let size_to_extend := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let to_be_paid := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let current_size := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "memory" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + For make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ] in M.get_name (| globals, "extensions" |) do + let _ := + M.pure Constant.None_ + )) |) in + let before_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "current_size" |) + ], + make_dict [] + |) in + let after_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let size_to_extend := BinOp.add + BinOp.sub (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |) + BinOp.sub (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |) in + let already_paid := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "before_size" |) + ], + make_dict [] + |) in + let total_cost := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "after_size" |) + ], + make_dict [] + |) in + let to_be_paid := BinOp.add + BinOp.sub (| + M.get_name (| globals, "total_cost" |), + M.get_name (| globals, "already_paid" |) + |) + BinOp.sub (| + M.get_name (| globals, "total_cost" |), + M.get_name (| globals, "already_paid" |) + |) in + let current_size := + M.get_name (| globals, "after_size" |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ExtendMemory" |), + make_list [ + M.get_name (| globals, "to_be_paid" |); + M.get_name (| globals, "size_to_extend" |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition calculate_message_call_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "gas"; "to"; "value" ] |) in + let _ := Constant.str " + Calculates the gas amount for executing Opcodes `CALL` and `CALLCODE`. + + Parameters + ---------- + state : + The current state. + gas : + The amount of gas provided to the message-call. + to: + The address of the recipient account. + value: + The amount of `ETH` that needs to be transferred. + + Returns + ------- + message_call_gas: `MessageCallGas` + " in + let create_gas_cost := + (* if *) +M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "to" |) + ], + make_dict [] + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let transfer_gas_cost := + (* if *) +M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let cost := + BinOp.add (| + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_CALL" |), + M.get_name (| globals, "gas" |) + |), + M.get_name (| globals, "create_gas_cost" |) + |), + M.get_name (| globals, "transfer_gas_cost" |) + |) in + let stipend := + (* if *) +M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), +(* then *) +ltac:(M.monadic ( +M.get_name (| globals, "gas" |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallGas" |), + make_list [ + M.get_name (| globals, "cost" |); + M.get_name (| globals, "stipend" |) + ], + make_dict [] + |) + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/arithmetic.v index a8b5c61..581ba5d 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/arithmetic.v @@ -273,22 +273,6 @@ Definition div : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let quotient := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let quotient := BinOp.floor_div (| M.get_name (| globals, "dividend" |), @@ -357,32 +341,7 @@ Definition sdiv : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let quotient := - Constant.int 0 in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_name (| globals, "dividend" |), UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "divisor" |), UnOp.sub (| Constant.int 1 |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let quotient := - UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let sign := M.call (| M.get_name (| globals, "get_sign" |), @@ -477,22 +436,6 @@ Definition mod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let remainder := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let remainder := BinOp.mod_ (| M.get_name (| globals, "x" |), @@ -561,16 +504,6 @@ Definition smod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let remainder := - Constant.int 0 in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let remainder := BinOp.mult (| M.call (| @@ -684,22 +617,6 @@ Definition addmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -795,22 +712,6 @@ Definition mulmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -980,16 +881,6 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "byte_num" |), Constant.int 31 |), - (* then *) - ltac:(M.monadic ( - let result := - M.get_name (| globals, "value" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let value_bytes := M.call (| M.get_name (| globals, "bytes" |), @@ -1012,29 +903,13 @@ Definition signextend : Value.t -> Value.t -> M := ], make_dict [] |) - |):(* At expr: unsupported node type: NoneType *) |) in + |) |) in let sign_bit := BinOp.r_shift (| M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), Constant.int 7 |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "sign_bit" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), - make_list [ - M.get_name (| globals, "value_bytes" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let num_bytes_prepend := BinOp.sub (| Constant.int 32, diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/bitwise.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/bitwise.v index b20a1e5..f38e7aa 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/bitwise.v @@ -285,22 +285,6 @@ Definition get_byte : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "byte_index" |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let extra_bytes_to_right := BinOp.sub (| Constant.int 31, diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/block.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/block.v index e5fa554..90be45c 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/block.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/block.v @@ -69,24 +69,6 @@ Definition block_hash : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.lt_e (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), M.get_name (| globals, "block_number" |) |), - ltac:(M.monadic ( - Compare.gt (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), BinOp.add (| - M.get_name (| globals, "block_number" |), - Constant.int 256 - |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let hash := - (* At constant: unsupported node type: Constant *) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let hash := M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/comparison.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/comparison.v index fbc35f8..b8529d8 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/comparison.v @@ -78,7 +78,10 @@ Definition less_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.lt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -145,7 +148,10 @@ Definition signed_less_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.lt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -205,7 +211,10 @@ Definition greater_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.gt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -272,7 +281,10 @@ Definition signed_greater_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.gt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -332,7 +344,10 @@ Definition equal : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.eq (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.eq (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -384,7 +399,10 @@ Definition is_zero : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.eq (| M.get_name (| globals, "x" |), Constant.int 0 |) + Compare.eq (| + M.get_name (| globals, "x" |), + Constant.int 0 + |) ], make_dict [] |) in diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/control_flow.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/control_flow.v index 04a79d9..d4e4eae 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/control_flow.v @@ -109,15 +109,6 @@ Definition jump : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -177,29 +168,7 @@ Definition jumpi : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "conditional_value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let destination := - BinOp.add (| - M.get_field (| M.get_name (| globals, "evm" |), "pc" |), - Constant.int 1 - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let destination := M.get_name (| globals, "jump_dest" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/environment.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/environment.v index 4d26a46..366e59a 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/environment.v @@ -492,7 +492,7 @@ Definition calldatacopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -660,7 +660,7 @@ Definition codecopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -903,7 +903,7 @@ Definition extcodecopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/keccak.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/keccak.v index cab9ffb..2c4b10e 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/keccak.v @@ -137,7 +137,7 @@ Definition keccak : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/log.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/log.v index f246f9d..ab196bc 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/log.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/log.v @@ -153,7 +153,7 @@ Definition log_n : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/memory.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/memory.v index 1e1c8b0..86ba742 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/memory.v @@ -121,7 +121,7 @@ Definition mstore : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -203,7 +203,7 @@ Definition mstore8 : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -288,7 +288,7 @@ Definition mload : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/stack.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/stack.v index 1eeda05..305af15 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/stack.v @@ -188,13 +188,16 @@ Definition dup_n : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] - |) |); + Compare.lt (| + M.get_name (| globals, "item_number" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + |); M.get_name (| globals, "StackUnderflowError" |) ], make_dict [] @@ -260,13 +263,16 @@ Definition swap_n : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] - |) |); + Compare.lt (| + M.get_name (| globals, "item_number" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + |); M.get_name (| globals, "StackUnderflowError" |) ], make_dict [] diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/storage.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/storage.v index 4292e3b..5250214 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/storage.v @@ -146,44 +146,11 @@ Definition sstore : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "new_value" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let gas_cost := - M.get_name (| globals, "GAS_STORAGE_SET" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let gas_cost := M.get_name (| globals, "GAS_STORAGE_UPDATE" |) in M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_name (| globals, "new_value" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), - M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/system.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/system.v index 335986d..d3dc734 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/system.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/system.v @@ -157,7 +157,7 @@ Definition create : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -189,96 +189,7 @@ Definition create : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.lt (| M.get_field (| M.get_name (| globals, "sender" |), "balance" |), M.get_name (| globals, "endowment" |) |), - ltac:(M.monadic ( - BoolOp.or (| - Compare.eq (| M.get_field (| M.get_name (| globals, "sender" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - BinOp.sub (| - BinOp.pow (| - Constant.int 2, - Constant.int 64 - |), - Constant.int 1 - |) - ], - make_dict [] - |) |), - ltac:(M.monadic ( - Compare.gt (| BinOp.add (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "depth" |), - Constant.int 1 - |), M.get_name (| globals, "STACK_DEPTH_LIMIT" |) |) - )) - |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "push" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |); - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) - ], - make_dict [] - |) in - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), - M.get_name (| globals, "create_message_gas" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_has_code_or_nonce" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); - M.get_name (| globals, "contract_address" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "increment_nonce" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) - ], - make_dict [] - |) in - let _ := M.call (| - M.get_name (| globals, "push" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |); - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let call_data := M.call (| M.get_name (| globals, "memory_read_bytes" |), @@ -313,36 +224,6 @@ Definition create : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "child_evm" |), "error" |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "incorporate_child_on_error" |), - make_list [ - M.get_name (| globals, "evm" |); - M.get_name (| globals, "child_evm" |) - ], - make_dict [] - |) in - let _ := M.call (| - M.get_name (| globals, "push" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |); - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "incorporate_child_on_success" |), make_list [ @@ -431,7 +312,7 @@ Definition return_ : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -462,39 +343,6 @@ Definition generic_call : Value.t -> Value.t -> M := " in (* At stmt: unsupported node type: ImportFrom *) let _ := - (* if *) - M.if_then_else (| - Compare.gt (| BinOp.add (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "depth" |), - Constant.int 1 - |), M.get_name (| globals, "STACK_DEPTH_LIMIT" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), - M.get_name (| globals, "gas" |) - |) in - let _ := M.call (| - M.get_name (| globals, "push" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |); - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) - ], - make_dict [] - |) in - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let call_data := @@ -532,36 +380,6 @@ Definition generic_call : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "child_evm" |), "error" |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "incorporate_child_on_error" |), - make_list [ - M.get_name (| globals, "evm" |); - M.get_name (| globals, "child_evm" |) - ], - make_dict [] - |) in - let _ := M.call (| - M.get_name (| globals, "push" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |); - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "incorporate_child_on_success" |), make_list [ @@ -612,7 +430,7 @@ Definition generic_call : Value.t -> Value.t -> M := make_list [ M.get_field (| M.get_name (| globals, "evm" |), "memory" |); M.get_name (| globals, "memory_output_start_position" |); - M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), (* At expr: unsupported node type: NoneType *):M.get_name (| globals, "actual_output_size" |) |) + M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), Constant.None_:M.get_name (| globals, "actual_output_size" |) |) ], make_dict [] |) in @@ -735,7 +553,7 @@ Definition call : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -749,33 +567,6 @@ Definition call : Value.t -> Value.t -> M := make_dict [] |), "balance" |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "sender_balance" |), M.get_name (| globals, "value" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "push" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |); - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) - ], - make_dict [] - |) in - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), - M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "generic_call" |), make_list [ @@ -921,7 +712,7 @@ Definition callcode : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -935,33 +726,6 @@ Definition callcode : Value.t -> Value.t -> M := make_dict [] |), "balance" |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "sender_balance" |), M.get_name (| globals, "value" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "push" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |); - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) - ], - make_dict [] - |) in - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), - M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "generic_call" |), make_list [ @@ -1021,7 +785,10 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in let parent_evm := M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "parent_evm" |) in - While Compare.is_not (| M.get_name (| globals, "parent_evm" |), Constant.None_ |) do + While Compare.is_not (| + M.get_name (| globals, "parent_evm" |), + Constant.None_ + |) do let _ := M.call (| M.get_field (| M.get_name (| globals, "refunded_accounts" |), "update" |), make_list [ @@ -1033,19 +800,6 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in EndWhile. let _ := - (* if *) - M.if_then_else (| - Compare.not_in (| M.get_name (| globals, "originator" |), M.get_name (| globals, "refunded_accounts" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), - M.get_name (| globals, "REFUND_SELF_DESTRUCT" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -1216,7 +970,7 @@ Definition delegatecall : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/dao_fork/vm/interpreter.v b/CoqOfPython/ethereum/dao_fork/vm/interpreter.v index 85a383f..c3c5b56 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/interpreter.v +++ b/CoqOfPython/ethereum/dao_fork/vm/interpreter.v @@ -162,86 +162,6 @@ Definition process_message_call : Value.t -> Value.t -> M := Output of the message call " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_name (| globals, "message" |), "target" |), M.call (| - M.get_name (| globals, "Bytes0" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let is_collision := - M.call (| - M.get_name (| globals, "account_has_code_or_nonce" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_field (| M.get_name (| globals, "message" |), "current_target" |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - M.get_name (| globals, "is_collision" |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "MessageCallOutput" |), - make_list [ - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |); - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |); - M.call (| - M.get_name (| globals, "tuple" |), - make_list [], - make_dict [] - |); - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |); - M.call (| - M.get_name (| globals, "AddressCollision" |), - make_list [], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let evm := - M.call (| - M.get_name (| globals, "process_create_message" |), - make_list [ - M.get_name (| globals, "message" |); - M.get_name (| globals, "env" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let evm := M.call (| M.get_name (| globals, "process_message" |), @@ -254,29 +174,6 @@ Definition process_message_call : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "evm" |), "error" |), - (* then *) - ltac:(M.monadic ( -(* At stmt: unsupported node type: AnnAssign *) - let accounts_to_delete := - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |) in - let refund_counter := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let logs := M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in let accounts_to_delete := @@ -312,7 +209,6 @@ Definition process_message_call : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). Definition process_create_message : Value.t -> Value.t -> M := @@ -350,28 +246,6 @@ Definition process_create_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), - (* then *) - ltac:(M.monadic ( - let contract_code := - M.get_field (| M.get_name (| globals, "evm" |), "output" |) in - let contract_code_gas := - BinOp.mult (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "contract_code" |) - ], - make_dict [] - |), - M.get_name (| globals, "GAS_CODE_DEPOSIT" |) - |) in -(* At stmt: unsupported node type: Try *) - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "rollback_transaction" |), make_list [ @@ -383,7 +257,6 @@ Definition process_create_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) - |) in M.pure Constant.None_)). Definition process_message : Value.t -> Value.t -> M := @@ -405,21 +278,6 @@ Definition process_message : Value.t -> Value.t -> M := Items containing execution specific objects " in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_field (| M.get_name (| globals, "message" |), "depth" |), M.get_name (| globals, "STACK_DEPTH_LIMIT" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "StackDepthLimitError" |), - make_list [ - Constant.str "Stack depth limit reached" - ], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -438,29 +296,6 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - M.get_field (| M.get_name (| globals, "message" |), "should_transfer_value" |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_field (| M.get_name (| globals, "message" |), "value" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "move_ether" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_field (| M.get_name (| globals, "message" |), "caller" |); - M.get_field (| M.get_name (| globals, "message" |), "current_target" |); - M.get_field (| M.get_name (| globals, "message" |), "value" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let evm := @@ -473,21 +308,6 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "evm" |), "error" |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "rollback_transaction" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "commit_transaction" |), make_list [ @@ -499,7 +319,6 @@ Definition process_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) - |) in M.pure Constant.None_)). Definition execute_code : Value.t -> Value.t -> M := @@ -539,5 +358,4 @@ Definition execute_code : Value.t -> Value.t -> M := (* At stmt: unsupported node type: Try *) let _ := M.return_ (| M.get_name (| globals, "evm" |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/vm/memory.v b/CoqOfPython/ethereum/dao_fork/vm/memory.v index fa8d906..4b107fd 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/memory.v +++ b/CoqOfPython/ethereum/dao_fork/vm/memory.v @@ -45,22 +45,7 @@ Definition memory_write : Value.t -> Value.t -> M := Data to write to memory. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) - |) |), + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_)). @@ -86,23 +71,7 @@ Definition memory_read_bytes : Value.t -> Value.t -> M := Data read from memory. " in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |) - |) in + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |) M.pure Constant.None_)). Definition buffer_read : Value.t -> Value.t -> M := @@ -129,25 +98,9 @@ Definition buffer_read : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "right_pad_zero_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |); + M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |) |); M.get_name (| globals, "size" |) ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/ecrecover.v index cc351b5..0cbcf16 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/ecrecover.v @@ -188,60 +188,12 @@ Definition ecrecover : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 27 |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 28 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| Constant.int 0, M.get_name (| globals, "r" |) |), - ltac:(M.monadic ( - Compare.gt_e (| M.get_name (| globals, "r" |), M.get_name (| globals, "SECP256K1N" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| Constant.int 0, M.get_name (| globals, "s" |) |), - ltac:(M.monadic ( - Compare.gt_e (| M.get_name (| globals, "s" |), M.get_name (| globals, "SECP256K1N" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: Try *) @@ -252,7 +204,7 @@ Definition ecrecover : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12:Constant.int 32 |) in + |), Constant.int 12 |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/dao_fork/vm/runtime.v b/CoqOfPython/ethereum/dao_fork/vm/runtime.v index 835b46c..2cd7652 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/runtime.v +++ b/CoqOfPython/ethereum/dao_fork/vm/runtime.v @@ -67,50 +67,19 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := ], make_dict [] |) in - While Compare.lt (| M.get_name (| globals, "pc" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "code" |) - ], - make_dict [] - |) |) do + While Compare.lt (| + M.get_name (| globals, "pc" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) + |) do (* At stmt: unsupported node type: Try *) let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "current_opcode" |), M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), - make_list [ - M.get_name (| globals, "pc" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - (* At expr: unsupported node type: Compare *), - (* then *) - ltac:(M.monadic ( - let push_data_size := - BinOp.add (| - BinOp.sub (| - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) - |), - Constant.int 1 - |) in - let pc := BinOp.add - M.get_name (| globals, "push_data_size" |) - M.get_name (| globals, "push_data_size" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -121,5 +90,4 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := EndWhile. let _ := M.return_ (| M.get_name (| globals, "valid_jump_destinations" |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/vm/stack.v b/CoqOfPython/ethereum/dao_fork/vm/stack.v index 42ea42d..ea778df 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/stack.v +++ b/CoqOfPython/ethereum/dao_fork/vm/stack.v @@ -49,21 +49,6 @@ Definition pop : Value.t -> Value.t -> M := " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "stack" |) - ], - make_dict [] - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "StackUnderflowError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -72,7 +57,6 @@ Definition pop : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). Definition push : Value.t -> Value.t -> M := @@ -91,21 +75,6 @@ Definition push : Value.t -> Value.t -> M := " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "stack" |) - ], - make_dict [] - |), Constant.int 1024 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "StackOverflowError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -116,5 +85,4 @@ Definition push : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/ethash.v b/CoqOfPython/ethereum/ethash.v index afff624..fffefb7 100644 --- a/CoqOfPython/ethereum/ethash.v +++ b/CoqOfPython/ethereum/ethash.v @@ -216,7 +216,6 @@ Definition epoch : Value.t -> Value.t -> M := M.get_name (| globals, "block_number" |), M.get_name (| globals, "EPOCH_SIZE" |) |) - |) in M.pure Constant.None_)). Definition cache_size : Value.t -> Value.t -> M := @@ -278,7 +277,6 @@ Definition cache_size : Value.t -> Value.t -> M := EndWhile. let _ := M.return_ (| M.get_name (| globals, "size" |) - |) in M.pure Constant.None_)). Definition dataset_size : Value.t -> Value.t -> M := @@ -342,7 +340,6 @@ Definition dataset_size : Value.t -> Value.t -> M := EndWhile. let _ := M.return_ (| M.get_name (| globals, "size" |) - |) in M.pure Constant.None_)). Definition generate_seed : Value.t -> Value.t -> M := @@ -364,10 +361,13 @@ Definition generate_seed : Value.t -> Value.t -> M := |) in let seed := BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", Constant.int 32 |) in - While Compare.not_eq (| M.get_name (| globals, "epoch_number" |), Constant.int 0 |) do + While Compare.not_eq (| + M.get_name (| globals, "epoch_number" |), + Constant.int 0 + |) do let seed := M.call (| M.get_name (| globals, "keccak256" |), @@ -388,7 +388,6 @@ Definition generate_seed : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition generate_cache : Value.t -> Value.t -> M := @@ -500,7 +499,7 @@ Definition generate_cache : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "U32" |), "from_le_bytes" |), make_list [ - M.get_subscript (| M.get_subscript (| M.get_name (| globals, "cache" |), M.get_name (| globals, "index" |) |), Constant.int 0:Constant.int 4 |) + M.get_subscript (| M.get_subscript (| M.get_name (| globals, "cache" |), M.get_name (| globals, "index" |) |), Constant.int 0 |) ], make_dict [] |), @@ -510,10 +509,7 @@ Definition generate_cache : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "bytes" |), make_list [ - [BinOp.bit_xor (| - M.get_name (| globals, "a" |), - M.get_name (| globals, "b" |) - |) for (* At expr: unsupported node type: list *)] + (* At expr: unsupported node type: ListComp *) ], make_dict [] |) in @@ -533,17 +529,10 @@ Definition generate_cache : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "tuple" |), make_list [ - (M.call (| - M.get_name (| globals, "le_bytes_to_uint32_sequence" |), - make_list [ - M.get_name (| globals, "cache_item" |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)) + (* At expr: unsupported node type: GeneratorExp *) ], make_dict [] |) - |) in M.pure Constant.None_)). Definition fnv : Value.t -> Value.t -> M := @@ -595,7 +584,6 @@ Definition fnv : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition fnv_hash : Value.t -> Value.t -> M := @@ -613,18 +601,10 @@ Definition fnv_hash : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "tuple" |), make_list [ - (M.call (| - M.get_name (| globals, "fnv" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "mix_integers" |), M.get_name (| globals, "i" |) |); - M.get_subscript (| M.get_name (| globals, "data" |), M.get_name (| globals, "i" |) |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)) + (* At expr: unsupported node type: GeneratorExp *) ], make_dict [] |) - |) in M.pure Constant.None_)). Definition generate_dataset_item : Value.t -> Value.t -> M := @@ -743,7 +723,6 @@ Definition generate_dataset_item : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition generate_dataset : Value.t -> Value.t -> M := @@ -761,24 +740,10 @@ Definition generate_dataset : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "tuple" |), make_list [ - (M.call (| - M.get_name (| globals, "generate_dataset_item" |), - make_list [ - M.get_name (| globals, "cache" |); - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "index" |) - ], - make_dict [] - |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)) + (* At expr: unsupported node type: GeneratorExp *) ], make_dict [] |) - |) in M.pure Constant.None_)). Definition hashimoto : Value.t -> Value.t -> M := @@ -834,7 +799,7 @@ Definition hashimoto : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "U32" |), "from_le_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "seed_hash" |), (* At expr: unsupported node type: NoneType *):Constant.int 4 |) + M.get_subscript (| M.get_name (| globals, "seed_hash" |), Constant.None_:Constant.int 4 |) ], make_dict [] |) in @@ -1025,7 +990,6 @@ Definition hashimoto : Value.t -> Value.t -> M := |) in let _ := M.return_ (| make_tuple [ M.get_name (| globals, "mix_digest" |); M.get_name (| globals, "result" |) ] - |) in M.pure Constant.None_)). Definition hashimoto_light : Value.t -> Value.t -> M := @@ -1065,5 +1029,4 @@ Definition hashimoto_light : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/fork_criteria.v b/CoqOfPython/ethereum/fork_criteria.v index 6614a4e..4d87501 100644 --- a/CoqOfPython/ethereum/fork_criteria.v +++ b/CoqOfPython/ethereum/fork_criteria.v @@ -46,29 +46,10 @@ Definition ForkCriteria : Value.t := Equality for fork criteria. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "other" |); - M.get_name (| globals, "ForkCriteria" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Compare.eq (| M.get_field (| M.get_name (| globals, "self" |), "_internal" |), M.get_field (| M.get_name (| globals, "other" |), "_internal" |) |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| M.get_name (| globals, "NotImplemented" |) - |) in M.pure Constant.None_)) ); ( @@ -80,29 +61,10 @@ Definition ForkCriteria : Value.t := forks and scheduled forks are before unscheduled forks. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "other" |); - M.get_name (| globals, "ForkCriteria" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Compare.lt (| M.get_field (| M.get_name (| globals, "self" |), "_internal" |), M.get_field (| M.get_name (| globals, "other" |), "_internal" |) |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| M.get_name (| globals, "NotImplemented" |) - |) in M.pure Constant.None_)) ); ( @@ -120,7 +82,6 @@ Definition ForkCriteria : Value.t := ], make_dict [] |) - |) in M.pure Constant.None_)) ) ]. @@ -154,8 +115,10 @@ Definition ByBlockNumber : Value.t := Check whether the block number has been reached. " in let _ := M.return_ (| - Compare.gt_e (| M.get_name (| globals, "block_number" |), M.get_field (| M.get_name (| globals, "self" |), "block_number" |) |) - |) in + Compare.gt_e (| + M.get_name (| globals, "block_number" |), + M.get_field (| M.get_name (| globals, "self" |), "block_number" |) + |) M.pure Constant.None_)) ); ( @@ -167,7 +130,6 @@ Definition ByBlockNumber : Value.t := " in let _ := M.return_ (| (* At expr: unsupported node type: JoinedStr *) - |) in M.pure Constant.None_)) ) ]. @@ -201,8 +163,10 @@ Definition ByTimestamp : Value.t := Check whether the timestamp has been reached. " in let _ := M.return_ (| - Compare.gt_e (| M.get_name (| globals, "timestamp" |), M.get_field (| M.get_name (| globals, "self" |), "timestamp" |) |) - |) in + Compare.gt_e (| + M.get_name (| globals, "timestamp" |), + M.get_field (| M.get_name (| globals, "self" |), "timestamp" |) + |) M.pure Constant.None_)) ); ( @@ -214,7 +178,6 @@ Definition ByTimestamp : Value.t := " in let _ := M.return_ (| (* At expr: unsupported node type: JoinedStr *) - |) in M.pure Constant.None_)) ) ]. @@ -245,7 +208,6 @@ Definition Unscheduled : Value.t := " in let _ := M.return_ (| Constant.bool false - |) in M.pure Constant.None_)) ); ( @@ -257,7 +219,6 @@ Definition Unscheduled : Value.t := " in let _ := M.return_ (| Constant.str "Unscheduled()" - |) in M.pure Constant.None_)) ) ]. diff --git a/CoqOfPython/ethereum/frontier/bloom.v b/CoqOfPython/ethereum/frontier/bloom.v index 04b5d9f..04650ff 100644 --- a/CoqOfPython/ethereum/frontier/bloom.v +++ b/CoqOfPython/ethereum/frontier/bloom.v @@ -72,10 +72,7 @@ Definition add_to_bloom : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |):BinOp.add (| - M.get_name (| globals, "idx" |), - Constant.int 2 - |) |) + M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |) |) ], make_dict [] |), @@ -160,5 +157,4 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/fork.v b/CoqOfPython/ethereum/frontier/fork.v index 2a44b1f..4ccf0a6 100644 --- a/CoqOfPython/ethereum/frontier/fork.v +++ b/CoqOfPython/ethereum/frontier/fork.v @@ -216,7 +216,6 @@ Definition apply_fork : Value.t -> Value.t -> M := " in let _ := M.return_ (| M.get_name (| globals, "old" |) - |) in M.pure Constant.None_)). Definition get_last_256_block_hashes : Value.t -> Value.t -> M := @@ -242,25 +241,8 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := Hashes of the recent 256 blocks in order of increasing block number. " in let recent_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |) |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "recent_blocks" |) - ], - make_dict [] - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - make_list [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let recent_block_hashes := @@ -299,7 +281,6 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "recent_block_hashes" |) - |) in M.pure Constant.None_)). Definition state_transition : Value.t -> Value.t -> M := @@ -370,7 +351,10 @@ Definition state_transition : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_gas_used" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "gas_used" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_gas_used" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "gas_used" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -378,7 +362,10 @@ Definition state_transition : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "transactions_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "transactions_root" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "transactions_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "transactions_root" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -386,7 +373,10 @@ Definition state_transition : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "state_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "state_root" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "state_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "state_root" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -394,7 +384,10 @@ Definition state_transition : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "receipt_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "receipt_root" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "receipt_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "receipt_root" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -402,7 +395,10 @@ Definition state_transition : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_logs_bloom" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "bloom" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_logs_bloom" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "bloom" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -415,24 +411,6 @@ Definition state_transition : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "chain" |), "blocks" |) - ], - make_dict [] - |), Constant.int 255 |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign (| - M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |):(* At expr: unsupported node type: NoneType *) |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -460,7 +438,10 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.gt (| M.get_field (| M.get_name (| globals, "header" |), "timestamp" |), M.get_field (| M.get_name (| globals, "parent_header" |), "timestamp" |) |); + Compare.gt (| + M.get_field (| M.get_name (| globals, "header" |), "timestamp" |), + M.get_field (| M.get_name (| globals, "parent_header" |), "timestamp" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -468,10 +449,13 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "number" |), BinOp.add (| - M.get_field (| M.get_name (| globals, "parent_header" |), "number" |), - Constant.int 1 - |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "number" |), + BinOp.add (| + M.get_field (| M.get_name (| globals, "parent_header" |), "number" |), + Constant.int 1 + |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -494,13 +478,16 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt_e (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) - ], - make_dict [] - |), Constant.int 32 |); + Compare.lt_e (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) + ], + make_dict [] + |), + Constant.int 32 + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -519,7 +506,10 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "difficulty" |), M.get_name (| globals, "block_difficulty" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "difficulty" |), + M.get_name (| globals, "block_difficulty" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -541,7 +531,10 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |), M.get_name (| globals, "block_parent_hash" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |), + M.get_name (| globals, "block_parent_hash" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -604,7 +597,6 @@ Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition validate_proof_of_work : Value.t -> Value.t -> M := @@ -662,7 +654,10 @@ Definition validate_proof_of_work : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_name (| globals, "mix_digest" |), M.get_field (| M.get_name (| globals, "header" |), "mix_digest" |) |); + Compare.eq (| + M.get_name (| globals, "mix_digest" |), + M.get_field (| M.get_name (| globals, "header" |), "mix_digest" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -670,16 +665,19 @@ Definition validate_proof_of_work : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt_e (| M.call (| - M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), - make_list [ - M.get_name (| globals, "result" |) - ], - make_dict [] - |), BinOp.floor_div (| - M.get_name (| globals, "U256_CEIL_VALUE" |), - M.get_field (| M.get_name (| globals, "header" |), "difficulty" |) - |) |); + Compare.lt_e (| + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "result" |) + ], + make_dict [] + |), + BinOp.floor_div (| + M.get_name (| globals, "U256_CEIL_VALUE" |), + M.get_field (| M.get_name (| globals, "header" |), "difficulty" |) + |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -712,7 +710,10 @@ Definition check_transaction : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt_e (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_name (| globals, "gas_available" |) |); + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_name (| globals, "gas_available" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -727,7 +728,6 @@ Definition check_transaction : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "sender_address" |) - |) in M.pure Constant.None_)). Definition make_receipt : Value.t -> Value.t -> M := @@ -761,7 +761,6 @@ Definition make_receipt : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "receipt" |) - |) in M.pure Constant.None_)). Definition ApplyBodyOutput : Value.t := @@ -975,7 +974,6 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition validate_ommers : Value.t -> Value.t -> M := @@ -1013,42 +1011,39 @@ Definition validate_ommers : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), - make_list [ - M.get_name (| globals, "ommers" |) - ], - make_dict [] - |), M.get_field (| M.get_name (| globals, "block_header" |), "ommers_hash" |) |); + Compare.eq (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + M.get_field (| M.get_name (| globals, "block_header" |), "ommers_hash" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "ommers" |) - ], - make_dict [] - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - (* At expr: unsupported node type: Compare *); + BoolOp.and (| + Compare.lt_e (| + Constant.int 1, + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |), + ltac:(M.monadic ( + Compare.lt (| + M.get_field (| M.get_name (| globals, "ommer" |), "number" |), + M.get_field (| M.get_name (| globals, "block_header" |), "number" |) + |) + )) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1073,47 +1068,47 @@ Definition validate_ommers : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt_e (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "ommers" |) - ], - make_dict [] - |), Constant.int 2 |); + Compare.lt_e (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + Constant.int 2 + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] |) in let ommers_hashes := - [M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), - make_list [ - M.get_name (| globals, "ommer" |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)] in + (* At expr: unsupported node type: ListComp *) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "ommers_hashes" |) - ], - make_dict [] - |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.call (| - M.get_name (| globals, "set" |), - make_list [ - M.get_name (| globals, "ommers_hashes" |) - ], - make_dict [] - |) - ], - make_dict [] - |) |); + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers_hashes" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_name (| globals, "set" |), + make_list [ + M.get_name (| globals, "ommers_hashes" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1122,28 +1117,16 @@ Definition validate_ommers : Value.t -> Value.t -> M := M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| BinOp.add (| M.get_name (| globals, "MAX_OMMER_DEPTH" |), Constant.int 1 - |) |):(* At expr: unsupported node type: NoneType *) |) in + |) |) |) in let recent_canonical_block_hashes := - {M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), - make_list [ - M.get_field (| M.get_name (| globals, "block" |), "header" |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)} in + (* At expr: unsupported node type: SetComp *) in (* At stmt: unsupported node type: AnnAssign *) For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_canonical_blocks" |) do let recent_ommers_hashes := M.call (| M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), make_list [ - {M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), - make_list [ - M.get_name (| globals, "ommer" |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)} + (* At expr: unsupported node type: SetComp *) ], make_dict [] |) in @@ -1160,7 +1143,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.not_eq (| M.get_name (| globals, "ommer_hash" |), M.get_name (| globals, "block_hash" |) |); + Compare.not_eq (| + M.get_name (| globals, "ommer_hash" |), + M.get_name (| globals, "block_hash" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1168,7 +1154,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.not_in (| M.get_name (| globals, "ommer_hash" |), M.get_name (| globals, "recent_canonical_block_hashes" |) |); + Compare.not_in (| + M.get_name (| globals, "ommer_hash" |), + M.get_name (| globals, "recent_canonical_block_hashes" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1176,7 +1165,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.not_in (| M.get_name (| globals, "ommer_hash" |), M.get_name (| globals, "recent_ommers_hashes" |) |); + Compare.not_in (| + M.get_name (| globals, "ommer_hash" |), + M.get_name (| globals, "recent_ommers_hashes" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1189,7 +1181,18 @@ Definition validate_ommers : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - (* At expr: unsupported node type: Compare *); + BoolOp.and (| + Compare.lt_e (| + Constant.int 1, + M.get_name (| globals, "ommer_age" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_name (| globals, "ommer_age" |), + M.get_name (| globals, "MAX_OMMER_DEPTH" |) + |) + )) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1197,7 +1200,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.in (| M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), M.get_name (| globals, "recent_canonical_block_hashes" |) |); + Compare.in (| + M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), + M.get_name (| globals, "recent_canonical_block_hashes" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1205,7 +1211,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.not_eq (| M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), M.get_field (| M.get_name (| globals, "block_header" |), "parent_hash" |) |); + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), + M.get_field (| M.get_name (| globals, "block_header" |), "parent_hash" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1364,7 +1373,10 @@ Definition process_transaction : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "sender_account" |), "nonce" |), M.get_field (| M.get_name (| globals, "tx" |), "nonce" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "sender_account" |), "nonce" |), + M.get_field (| M.get_name (| globals, "tx" |), "nonce" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1372,10 +1384,13 @@ Definition process_transaction : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.gt_e (| M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), BinOp.add (| - M.get_name (| globals, "gas_fee" |), - M.get_field (| M.get_name (| globals, "tx" |), "value" |) - |) |); + Compare.gt_e (| + M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), + BinOp.add (| + M.get_name (| globals, "gas_fee" |), + M.get_field (| M.get_name (| globals, "tx" |), "value" |) + |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1383,11 +1398,14 @@ Definition process_transaction : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "sender_account" |), "code" |), M.call (| - M.get_name (| globals, "bytearray" |), - make_list [], - make_dict [] - |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "sender_account" |), "code" |), + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [], + make_dict [] + |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1542,7 +1560,6 @@ Definition process_transaction : Value.t -> Value.t -> M := EndFor. let _ := M.return_ (| make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |) ] - |) in M.pure Constant.None_)). Definition validate_transaction : Value.t -> Value.t -> M := @@ -1574,24 +1591,29 @@ Definition validate_transaction : Value.t -> Value.t -> M := " in let _ := M.return_ (| BoolOp.and (| - Compare.lt_e (| M.call (| - M.get_name (| globals, "calculate_intrinsic_cost" |), - make_list [ - M.get_name (| globals, "tx" |) - ], - make_dict [] - |), M.get_field (| M.get_name (| globals, "tx" |), "gas" |) |), + Compare.lt_e (| + M.call (| + M.get_name (| globals, "calculate_intrinsic_cost" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |), + M.get_field (| M.get_name (| globals, "tx" |), "gas" |) + |), ltac:(M.monadic ( - Compare.lt (| M.get_field (| M.get_name (| globals, "tx" |), "nonce" |), BinOp.sub (| + Compare.lt (| + M.get_field (| M.get_name (| globals, "tx" |), "nonce" |), + BinOp.sub (| BinOp.pow (| Constant.int 2, Constant.int 64 |), Constant.int 1 - |) |) + |) + |) )) |) - |) in M.pure Constant.None_)). Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := @@ -1623,17 +1645,6 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := Constant.int 0 in For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "byte" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let data_cost := BinOp.add - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let data_cost := BinOp.add M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in @@ -1651,7 +1662,6 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition recover_sender : Value.t -> Value.t -> M := @@ -1684,9 +1694,15 @@ Definition recover_sender : Value.t -> Value.t -> M := M.get_name (| globals, "ensure" |), make_list [ BoolOp.or (| - Compare.eq (| M.get_name (| globals, "v" |), Constant.int 27 |), + Compare.eq (| + M.get_name (| globals, "v" |), + Constant.int 27 + |), ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "v" |), Constant.int 28 |) + Compare.eq (| + M.get_name (| globals, "v" |), + Constant.int 28 + |) )) |); M.get_name (| globals, "InvalidBlock" |) @@ -1697,9 +1713,15 @@ Definition recover_sender : Value.t -> Value.t -> M := M.get_name (| globals, "ensure" |), make_list [ BoolOp.and (| - Compare.lt (| Constant.int 0, M.get_name (| globals, "r" |) |), + Compare.lt (| + Constant.int 0, + M.get_name (| globals, "r" |) + |), ltac:(M.monadic ( - Compare.lt (| M.get_name (| globals, "r" |), M.get_name (| globals, "SECP256K1N" |) |) + Compare.lt (| + M.get_name (| globals, "r" |), + M.get_name (| globals, "SECP256K1N" |) + |) )) |); M.get_name (| globals, "InvalidBlock" |) @@ -1710,9 +1732,15 @@ Definition recover_sender : Value.t -> Value.t -> M := M.get_name (| globals, "ensure" |), make_list [ BoolOp.and (| - Compare.lt (| Constant.int 0, M.get_name (| globals, "s" |) |), + Compare.lt (| + Constant.int 0, + M.get_name (| globals, "s" |) + |), ltac:(M.monadic ( - Compare.lt (| M.get_name (| globals, "s" |), M.get_name (| globals, "SECP256K1N" |) |) + Compare.lt (| + M.get_name (| globals, "s" |), + M.get_name (| globals, "SECP256K1N" |) + |) )) |); M.get_name (| globals, "InvalidBlock" |) @@ -1749,11 +1777,10 @@ Definition recover_sender : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12:Constant.int 32 |) + |), Constant.int 12 |) ], make_dict [] |) - |) in M.pure Constant.None_)). Definition signing_hash : Value.t -> Value.t -> M := @@ -1790,7 +1817,6 @@ Definition signing_hash : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition compute_header_hash : Value.t -> Value.t -> M := @@ -1841,7 +1867,6 @@ Definition compute_header_hash : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition check_gas_limit : Value.t -> Value.t -> M := @@ -1880,56 +1905,16 @@ Definition check_gas_limit : Value.t -> Value.t -> M := M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "gas_limit" |), BinOp.add (| - M.get_name (| globals, "parent_gas_limit" |), - M.get_name (| globals, "max_adjustment_delta" |) - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.bool false - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt_e (| M.get_name (| globals, "gas_limit" |), BinOp.sub (| - M.get_name (| globals, "parent_gas_limit" |), - M.get_name (| globals, "max_adjustment_delta" |) - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.bool false - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "gas_limit" |), M.get_name (| globals, "GAS_LIMIT_MINIMUM" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.bool false - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| Constant.bool true - |) in M.pure Constant.None_)). Definition calculate_block_difficulty : Value.t -> Value.t -> M := @@ -1976,22 +1961,6 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := |) |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "block_timestamp" |), BinOp.add (| - M.get_name (| globals, "parent_timestamp" |), - Constant.int 13 - |) |), - (* then *) - ltac:(M.monadic ( - let difficulty := - BinOp.add (| - M.get_name (| globals, "parent_difficulty" |), - M.get_name (| globals, "max_adjustment_delta" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let difficulty := BinOp.sub (| M.get_name (| globals, "parent_difficulty" |), @@ -2014,23 +1983,6 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := Constant.int 2 |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "num_bomb_periods" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let difficulty := BinOp.add - BinOp.pow (| - Constant.int 2, - M.get_name (| globals, "num_bomb_periods" |) - |) - BinOp.pow (| - Constant.int 2, - M.get_name (| globals, "num_bomb_periods" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -2042,5 +1994,4 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/fork_types.v b/CoqOfPython/ethereum/frontier/fork_types.v index d12953d..5c7dac3 100644 --- a/CoqOfPython/ethereum/frontier/fork_types.v +++ b/CoqOfPython/ethereum/frontier/fork_types.v @@ -98,5 +98,4 @@ Definition encode_account : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/state.v b/CoqOfPython/ethereum/frontier/state.v index 38fe9d1..2ba095e 100644 --- a/CoqOfPython/ethereum/frontier/state.v +++ b/CoqOfPython/ethereum/frontier/state.v @@ -123,13 +123,7 @@ Definition begin_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) ], make_dict [] - |); {M.get_name (| globals, "k" |): M.call (| - M.get_name (| globals, "copy_trie" |), - make_list [ - M.get_name (| globals, "t" |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)} ] + |); (* At expr: unsupported node type: DictComp *) ] ], make_dict [] |) in @@ -207,27 +201,8 @@ Definition get_account : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "account" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "account" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_ACCOUNT" |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -262,7 +237,6 @@ Definition get_account_optional : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "account" |) - |) in M.pure Constant.None_)). Definition set_account : Value.t -> Value.t -> M := @@ -342,15 +316,6 @@ Definition destroy_storage : Value.t -> Value.t -> M := Address of account whose storage is to be deleted. " in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -385,23 +350,6 @@ Definition get_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let value := @@ -423,7 +371,6 @@ Definition get_storage : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "value" |) - |) in M.pure Constant.None_)). Definition set_storage : Value.t -> Value.t -> M := @@ -444,14 +391,17 @@ Definition set_storage : Value.t -> Value.t -> M := value : `U256` Value to set at the key. " in - let _ := M.assert (| Compare.is_not (| M.call (| - M.get_name (| globals, "trie_get" |), - make_list [ - M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), Constant.None_ |) |) in + let _ := M.assert (| Compare.is_not (| + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + Constant.None_ + |) |) in let trie := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), @@ -461,24 +411,6 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let trie := - M.call (| - M.get_name (| globals, "Trie" |), - make_list [], - make_dict [] - |) in - let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), - M.get_name (| globals, "trie" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -491,15 +423,6 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), {} |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -524,26 +447,8 @@ Definition storage_root : Value.t -> Value.t -> M := " in let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "root" |), - make_list [ - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_TRIE_ROOT" |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -574,7 +479,6 @@ Definition state_root : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition account_exists : Value.t -> Value.t -> M := @@ -596,15 +500,17 @@ Definition account_exists : Value.t -> Value.t -> M := True if account exists in the state trie, False otherwise " in let _ := M.return_ (| - Compare.is_not (| M.call (| - M.get_name (| globals, "get_account_optional" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), Constant.None_ |) - |) in + Compare.is_not (| + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + Constant.None_ + |) M.pure Constant.None_)). Definition account_has_code_or_nonce : Value.t -> Value.t -> M := @@ -637,18 +543,23 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := |) in let _ := M.return_ (| BoolOp.or (| - Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( - Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |) + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |) )) |) - |) in M.pure Constant.None_)). Definition modify_state : Value.t -> Value.t -> M := @@ -754,30 +665,6 @@ Definition touch_account : Value.t -> Value.t -> M := The address of the account that need to initialised. " in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "account_exists" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "set_account" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |); - M.get_name (| globals, "EMPTY_ACCOUNT" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/trie.v b/CoqOfPython/ethereum/frontier/trie.v index 85234ca..6805926 100644 --- a/CoqOfPython/ethereum/frontier/trie.v +++ b/CoqOfPython/ethereum/frontier/trie.v @@ -198,96 +198,16 @@ Definition encode_internal_node : Value.t -> Value.t -> M := " in (* At stmt: unsupported node type: AnnAssign *) let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "node" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let unencoded := - (* At constant: unsupported node type: Constant *) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "LeafNode" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let unencoded := - make_tuple [ M.call (| - M.get_name (| globals, "nibble_list_to_compact" |), - make_list [ - M.get_field (| M.get_name (| globals, "node" |), "rest_of_key" |); - Constant.bool true - ], - make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "ExtensionNode" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let unencoded := - make_tuple [ M.call (| - M.get_name (| globals, "nibble_list_to_compact" |), - make_list [ - M.get_field (| M.get_name (| globals, "node" |), "key_segment" |); - Constant.bool false - ], - make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "BranchNode" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let unencoded := - BinOp.add (| - M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), - make_list [ - M.get_field (| M.get_name (| globals, "node" |), "value" |) - ] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.call (| + let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ (* At expr: unsupported node type: JoinedStr *) ], make_dict [] - |) |) in + |)) M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -305,23 +225,6 @@ Definition encode_internal_node : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "encoded" |) - ], - make_dict [] - |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "unencoded" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_name (| globals, "keccak256" |), @@ -330,7 +233,6 @@ Definition encode_internal_node : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -344,90 +246,15 @@ Definition encode_node : Value.t -> Value.t -> M := Currently mostly an unimplemented stub. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "storage_root" |), Constant.None_ |) |) in - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "encode_account" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "storage_root" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - make_tuple [ M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "U256" |) ] - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.call (| - M.get_name (| globals, "cast" |), - make_list [ - M.get_field (| M.get_name (| globals, "rlp" |), "RLP" |); - M.get_name (| globals, "node" |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "Bytes" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "node" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.call (| + let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ (* At expr: unsupported node type: JoinedStr *) ], make_dict [] - |) |) in + |)) M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -479,7 +306,6 @@ Definition copy_trie : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition trie_set : Value.t -> Value.t -> M := @@ -501,26 +327,6 @@ Definition trie_set : Value.t -> Value.t -> M := Node to insert at `key`. " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "value" |), M.get_field (| M.get_name (| globals, "trie" |), "default" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "key" |), M.get_field (| M.get_name (| globals, "trie" |), "_data" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), M.get_name (| globals, "value" |) @@ -558,7 +364,6 @@ Definition trie_get : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition common_prefix_length : Value.t -> Value.t -> M := @@ -581,28 +386,6 @@ Definition common_prefix_length : Value.t -> Value.t -> M := make_dict [] |) do let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| M.get_name (| globals, "i" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "b" |) - ], - make_dict [] - |) |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "i" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -614,7 +397,6 @@ Definition common_prefix_length : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition nibble_list_to_compact : Value.t -> Value.t -> M := @@ -660,68 +442,6 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| BinOp.mod_ (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |), - Constant.int 2 - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_name (| globals, "compact" |), "append" |), - make_list [ - BinOp.mult (| - Constant.int 16, - BinOp.mult (| - Constant.int 2, - M.get_name (| globals, "is_leaf" |) - |) - |) - ], - make_dict [] - |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 0; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |); - Constant.int 2 - ], - make_dict [] - |) do - let _ := M.call (| - M.get_field (| M.get_name (| globals, "compact" |), "append" |), - make_list [ - BinOp.add (| - BinOp.mult (| - Constant.int 16, - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) - |), - M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) - |) - ], - make_dict [] - |) in - EndFor. - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ @@ -783,7 +503,6 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition bytes_to_nibble_list : Value.t -> Value.t -> M := @@ -861,7 +580,6 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition _prepare_trie : Value.t -> Value.t -> M := @@ -891,45 +609,6 @@ Definition _prepare_trie : Value.t -> Value.t -> M := make_dict [] |) do let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "value" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in - let address := - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in - let encoded_value := - M.call (| - M.get_name (| globals, "encode_node" |), - make_list [ - M.get_name (| globals, "value" |); - M.call (| - M.get_name (| globals, "get_storage_root" |), - make_list [ - M.get_name (| globals, "address" |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let encoded_value := M.call (| M.get_name (| globals, "encode_node" |), @@ -943,29 +622,16 @@ Definition _prepare_trie : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.not_eq (| M.get_name (| globals, "encoded_value" |), (* At constant: unsupported node type: Constant *) |); + Compare.not_eq (| + M.get_name (| globals, "encoded_value" |), + Constant.bytes "" + |); M.get_name (| globals, "AssertionError" |) ], make_dict [] |) in (* At stmt: unsupported node type: AnnAssign *) let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "trie" |), "secured" |), - (* then *) - ltac:(M.monadic ( - let key := - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let key := M.get_name (| globals, "preimage" |) in M.pure Constant.None_ @@ -983,7 +649,6 @@ Definition _prepare_trie : Value.t -> Value.t -> M := EndFor. let _ := M.return_ (| M.get_name (| globals, "mapped" |) - |) in M.pure Constant.None_)). Definition root : Value.t -> Value.t -> M := @@ -1037,41 +702,6 @@ Definition root : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "root_node" |) - ], - make_dict [] - |) - ], - make_dict [] - |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "root_node" |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -1088,7 +718,6 @@ Definition root : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -1115,23 +744,6 @@ Definition patricialize : Value.t -> Value.t -> M := Root node of `obj`. " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "obj" |) - ], - make_dict [] - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.None_ - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let arbitrary_key := @@ -1149,36 +761,10 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "obj" |) - ], - make_dict [] - |), Constant.int 1 |), - (* then *) - ltac:(M.monadic ( - let leaf := - M.call (| - M.get_name (| globals, "LeafNode" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |); - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) - ], - make_dict [] - |) in - let _ := M.return_ (| - M.get_name (| globals, "leaf" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let substring := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |) |) in let prefix_length := M.call (| M.get_name (| globals, "len" |), @@ -1197,7 +783,7 @@ Definition patricialize : Value.t -> Value.t -> M := M.get_name (| globals, "common_prefix_length" |), make_list [ M.get_name (| globals, "substring" |); - M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) + M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) ], make_dict [] |) @@ -1205,58 +791,10 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.break (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let prefix := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):BinOp.add (| - M.get_name (| globals, "level" |), - M.get_name (| globals, "prefix_length" |) - |) |) in - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "ExtensionNode" |), - make_list [ - M.get_name (| globals, "prefix" |); - M.call (| - M.get_name (| globals, "encode_internal_node" |), - make_list [ - M.call (| - M.get_name (| globals, "patricialize" |), - make_list [ - M.get_name (| globals, "obj" |); - BinOp.add (| - M.get_name (| globals, "level" |), - M.get_name (| globals, "prefix_length" |) - |) - ], - make_dict [] - |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) @@ -1276,44 +814,9 @@ Definition patricialize : Value.t -> Value.t -> M := |) in EndFor. let value := - (* At constant: unsupported node type: Constant *) in + Constant.bytes "" in For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "key" |) - ], - make_dict [] - |), M.get_name (| globals, "level" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); - make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "AssertionError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let value := - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) @@ -1325,26 +828,9 @@ Definition patricialize : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "BranchNode" |), make_list [ - [M.call (| - M.get_name (| globals, "encode_internal_node" |), - make_list [ - M.call (| - M.get_name (| globals, "patricialize" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "branches" |), M.get_name (| globals, "k" |) |); - BinOp.add (| - M.get_name (| globals, "level" |), - Constant.int 1 - |) - ], - make_dict [] - |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)]; + (* At expr: unsupported node type: ListComp *); M.get_name (| globals, "value" |) ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/utils/address.v b/CoqOfPython/ethereum/frontier/utils/address.v index 4ee1ff9..4ff0504 100644 --- a/CoqOfPython/ethereum/frontier/utils/address.v +++ b/CoqOfPython/ethereum/frontier/utils/address.v @@ -67,11 +67,10 @@ Definition to_address : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), make_list [], make_dict [] - |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) + |), UnOp.sub (| Constant.int 20 |) |) ], make_dict [] |) - |) in M.pure Constant.None_)). Definition compute_contract_address : Value.t -> Value.t -> M := @@ -111,7 +110,7 @@ Definition compute_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -129,5 +128,4 @@ Definition compute_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/utils/hexadecimal.v b/CoqOfPython/ethereum/frontier/utils/hexadecimal.v index 44b9f35..b471e39 100644 --- a/CoqOfPython/ethereum/frontier/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/frontier/utils/hexadecimal.v @@ -66,7 +66,6 @@ Definition hex_to_root : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition hex_to_bloom : Value.t -> Value.t -> M := @@ -105,7 +104,6 @@ Definition hex_to_bloom : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition hex_to_address : Value.t -> Value.t -> M := @@ -151,5 +149,4 @@ Definition hex_to_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/utils/message.v b/CoqOfPython/ethereum/frontier/utils/message.v index 6b13d93..c42bcc8 100644 --- a/CoqOfPython/ethereum/frontier/utils/message.v +++ b/CoqOfPython/ethereum/frontier/utils/message.v @@ -82,105 +82,14 @@ Definition prepare_message : Value.t -> Value.t -> M := Items containing contract creation or message call specific data. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "target" |); - M.get_name (| globals, "Bytes0" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let current_target := - M.call (| - M.get_name (| globals, "compute_contract_address" |), - make_list [ - M.get_name (| globals, "caller" |); - BinOp.sub (| - M.get_field (| M.call (| - M.get_name (| globals, "get_account" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "caller" |) - ], - make_dict [] - |), "nonce" |), - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 1 - ], - make_dict [] - |) - |) - ], - make_dict [] - |) in - let msg_data := - M.call (| - M.get_name (| globals, "Bytes" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |) in - let code := - M.get_name (| globals, "data" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "target" |); - M.get_name (| globals, "Address" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let current_target := - M.get_name (| globals, "target" |) in - let msg_data := - M.get_name (| globals, "data" |) in - let code := - M.get_field (| M.call (| - M.get_name (| globals, "get_account" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "target" |) - ], - make_dict [] - |), "code" |) in - let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "code_address" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let code_address := - M.get_name (| globals, "target" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.call (| + let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "Target must be address or empty bytes" ], make_dict [] - |) |) in + |)) M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -191,5 +100,4 @@ Definition prepare_message : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/vm/gas.v b/CoqOfPython/ethereum/frontier/vm/gas.v new file mode 100644 index 0000000..eef500a --- /dev/null +++ b/CoqOfPython/ethereum/frontier/vm/gas.v @@ -0,0 +1,769 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Gas +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +EVM gas constants and calculators. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.trace. +Axiom ethereum_trace_GasAndRefund : + IsGlobalAlias globals ethereum.trace.globals "GasAndRefund". +Axiom ethereum_trace_evm_trace : + IsGlobalAlias globals ethereum.trace.globals "evm_trace". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_State : + IsGlobalAlias globals state.globals "State". +Axiom state_account_exists : + IsGlobalAlias globals state.globals "account_exists". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". + +Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) +)). + +Definition GAS_BASE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 2 + ], + make_dict [] + |) +)). + +Definition GAS_VERY_LOW : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_SLOAD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 50 + ], + make_dict [] + |) +)). + +Definition GAS_STORAGE_SET : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 20000 + ], + make_dict [] + |) +)). + +Definition GAS_STORAGE_UPDATE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5000 + ], + make_dict [] + |) +)). + +Definition GAS_STORAGE_CLEAR_REFUND : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 15000 + ], + make_dict [] + |) +)). + +Definition GAS_LOW : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5 + ], + make_dict [] + |) +)). + +Definition GAS_MID : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 8 + ], + make_dict [] + |) +)). + +Definition GAS_HIGH : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 10 + ], + make_dict [] + |) +)). + +Definition GAS_EXPONENTIATION : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 10 + ], + make_dict [] + |) +)). + +Definition GAS_EXPONENTIATION_PER_BYTE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 10 + ], + make_dict [] + |) +)). + +Definition GAS_MEMORY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_KECCAK256 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 30 + ], + make_dict [] + |) +)). + +Definition GAS_KECCAK256_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 6 + ], + make_dict [] + |) +)). + +Definition GAS_COPY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_BLOCK_HASH : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 20 + ], + make_dict [] + |) +)). + +Definition GAS_EXTERNAL : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 20 + ], + make_dict [] + |) +)). + +Definition GAS_BALANCE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 20 + ], + make_dict [] + |) +)). + +Definition GAS_LOG : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 375 + ], + make_dict [] + |) +)). + +Definition GAS_LOG_DATA : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 8 + ], + make_dict [] + |) +)). + +Definition GAS_LOG_TOPIC : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 375 + ], + make_dict [] + |) +)). + +Definition GAS_CREATE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 32000 + ], + make_dict [] + |) +)). + +Definition GAS_CODE_DEPOSIT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 200 + ], + make_dict [] + |) +)). + +Definition GAS_ZERO : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) +)). + +Definition GAS_CALL : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 40 + ], + make_dict [] + |) +)). + +Definition GAS_NEW_ACCOUNT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 25000 + ], + make_dict [] + |) +)). + +Definition GAS_CALL_VALUE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 9000 + ], + make_dict [] + |) +)). + +Definition GAS_CALL_STIPEND : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 2300 + ], + make_dict [] + |) +)). + +Definition REFUND_SELF_DESTRUCT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 24000 + ], + make_dict [] + |) +)). + +Definition GAS_ECRECOVER : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3000 + ], + make_dict [] + |) +)). + +Definition GAS_SHA256 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 60 + ], + make_dict [] + |) +)). + +Definition GAS_SHA256_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 12 + ], + make_dict [] + |) +)). + +Definition GAS_RIPEMD160 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 600 + ], + make_dict [] + |) +)). + +Definition GAS_RIPEMD160_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 120 + ], + make_dict [] + |) +)). + +Definition GAS_IDENTITY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 15 + ], + make_dict [] + |) +)). + +Definition GAS_IDENTITY_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition ExtendMemory : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition MessageCallGas : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition charge_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "amount" ] |) in + let _ := Constant.str " + Subtracts `amount` from `evm.gas_left`. + + Parameters + ---------- + evm : + The current EVM. + amount : + The amount of gas the current operation requires. + + " in + let _ := M.call (| + M.get_name (| globals, "evm_trace" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "GasAndRefund" |), + make_list [ + M.get_name (| globals, "amount" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + let _ := M.assign_op (| + BinOp.sub, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "amount" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition calculate_memory_gas_cost : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "size_in_bytes" ] |) in + let _ := Constant.str " + Calculates the gas cost for allocating memory + to the smallest multiple of 32 bytes, + such that the allocated size is at least as big as the given size. + + Parameters + ---------- + size_in_bytes : + The size of the data in bytes. + + Returns + ------- + total_gas_cost : `ethereum.base_types.Uint` + The gas cost for storing data in memory. + " in + let size_in_words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "size_in_bytes" |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let linear_cost := + BinOp.mult (| + M.get_name (| globals, "size_in_words" |), + M.get_name (| globals, "GAS_MEMORY" |) + |) in + let quadratic_cost := + BinOp.floor_div (| + BinOp.pow (| + M.get_name (| globals, "size_in_words" |), + Constant.int 2 + |), + Constant.int 512 + |) in + let total_gas_cost := + BinOp.add (| + M.get_name (| globals, "linear_cost" |), + M.get_name (| globals, "quadratic_cost" |) + |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_)). + +Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "memory"; "extensions" ] |) in + let _ := Constant.str " + Calculates the gas amount to extend memory + + Parameters + ---------- + memory : + Memory contents of the EVM. + extensions: + List of extensions to be made to the memory. + Consists of a tuple of start position and size. + + Returns + ------- + extend_memory: `ExtendMemory` + " in + let size_to_extend := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let to_be_paid := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let current_size := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "memory" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + For make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ] in M.get_name (| globals, "extensions" |) do + let _ := + M.pure Constant.None_ + )) |) in + let before_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "current_size" |) + ], + make_dict [] + |) in + let after_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let size_to_extend := BinOp.add + BinOp.sub (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |) + BinOp.sub (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |) in + let already_paid := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "before_size" |) + ], + make_dict [] + |) in + let total_cost := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "after_size" |) + ], + make_dict [] + |) in + let to_be_paid := BinOp.add + BinOp.sub (| + M.get_name (| globals, "total_cost" |), + M.get_name (| globals, "already_paid" |) + |) + BinOp.sub (| + M.get_name (| globals, "total_cost" |), + M.get_name (| globals, "already_paid" |) + |) in + let current_size := + M.get_name (| globals, "after_size" |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ExtendMemory" |), + make_list [ + M.get_name (| globals, "to_be_paid" |); + M.get_name (| globals, "size_to_extend" |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition calculate_message_call_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "gas"; "to"; "value" ] |) in + let _ := Constant.str " + Calculates the gas amount for executing Opcodes `CALL` and `CALLCODE`. + + Parameters + ---------- + state : + The current state. + gas : + The amount of gas provided to the message-call. + to: + The address of the recipient account. + value: + The amount of `ETH` that needs to be transferred. + + Returns + ------- + message_call_gas: `MessageCallGas` + " in + let create_gas_cost := + (* if *) +M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "to" |) + ], + make_dict [] + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let transfer_gas_cost := + (* if *) +M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let cost := + BinOp.add (| + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_CALL" |), + M.get_name (| globals, "gas" |) + |), + M.get_name (| globals, "create_gas_cost" |) + |), + M.get_name (| globals, "transfer_gas_cost" |) + |) in + let stipend := + (* if *) +M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), +(* then *) +ltac:(M.monadic ( +M.get_name (| globals, "gas" |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallGas" |), + make_list [ + M.get_name (| globals, "cost" |); + M.get_name (| globals, "stipend" |) + ], + make_dict [] + |) + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/frontier/vm/instructions/arithmetic.v index a8b5c61..581ba5d 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/arithmetic.v @@ -273,22 +273,6 @@ Definition div : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let quotient := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let quotient := BinOp.floor_div (| M.get_name (| globals, "dividend" |), @@ -357,32 +341,7 @@ Definition sdiv : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let quotient := - Constant.int 0 in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_name (| globals, "dividend" |), UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "divisor" |), UnOp.sub (| Constant.int 1 |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let quotient := - UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let sign := M.call (| M.get_name (| globals, "get_sign" |), @@ -477,22 +436,6 @@ Definition mod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let remainder := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let remainder := BinOp.mod_ (| M.get_name (| globals, "x" |), @@ -561,16 +504,6 @@ Definition smod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let remainder := - Constant.int 0 in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let remainder := BinOp.mult (| M.call (| @@ -684,22 +617,6 @@ Definition addmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -795,22 +712,6 @@ Definition mulmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -980,16 +881,6 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "byte_num" |), Constant.int 31 |), - (* then *) - ltac:(M.monadic ( - let result := - M.get_name (| globals, "value" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let value_bytes := M.call (| M.get_name (| globals, "bytes" |), @@ -1012,29 +903,13 @@ Definition signextend : Value.t -> Value.t -> M := ], make_dict [] |) - |):(* At expr: unsupported node type: NoneType *) |) in + |) |) in let sign_bit := BinOp.r_shift (| M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), Constant.int 7 |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "sign_bit" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), - make_list [ - M.get_name (| globals, "value_bytes" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let num_bytes_prepend := BinOp.sub (| Constant.int 32, diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/bitwise.v b/CoqOfPython/ethereum/frontier/vm/instructions/bitwise.v index b20a1e5..f38e7aa 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/bitwise.v @@ -285,22 +285,6 @@ Definition get_byte : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "byte_index" |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let extra_bytes_to_right := BinOp.sub (| Constant.int 31, diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/block.v b/CoqOfPython/ethereum/frontier/vm/instructions/block.v index e5fa554..90be45c 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/block.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/block.v @@ -69,24 +69,6 @@ Definition block_hash : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.lt_e (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), M.get_name (| globals, "block_number" |) |), - ltac:(M.monadic ( - Compare.gt (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), BinOp.add (| - M.get_name (| globals, "block_number" |), - Constant.int 256 - |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let hash := - (* At constant: unsupported node type: Constant *) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let hash := M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/comparison.v b/CoqOfPython/ethereum/frontier/vm/instructions/comparison.v index fbc35f8..b8529d8 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/comparison.v @@ -78,7 +78,10 @@ Definition less_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.lt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -145,7 +148,10 @@ Definition signed_less_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.lt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -205,7 +211,10 @@ Definition greater_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.gt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -272,7 +281,10 @@ Definition signed_greater_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.gt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -332,7 +344,10 @@ Definition equal : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.eq (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.eq (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -384,7 +399,10 @@ Definition is_zero : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.eq (| M.get_name (| globals, "x" |), Constant.int 0 |) + Compare.eq (| + M.get_name (| globals, "x" |), + Constant.int 0 + |) ], make_dict [] |) in diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/control_flow.v b/CoqOfPython/ethereum/frontier/vm/instructions/control_flow.v index 04a79d9..d4e4eae 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/control_flow.v @@ -109,15 +109,6 @@ Definition jump : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -177,29 +168,7 @@ Definition jumpi : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "conditional_value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let destination := - BinOp.add (| - M.get_field (| M.get_name (| globals, "evm" |), "pc" |), - Constant.int 1 - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let destination := M.get_name (| globals, "jump_dest" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/environment.v b/CoqOfPython/ethereum/frontier/vm/instructions/environment.v index 4d26a46..366e59a 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/environment.v @@ -492,7 +492,7 @@ Definition calldatacopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -660,7 +660,7 @@ Definition codecopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -903,7 +903,7 @@ Definition extcodecopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/keccak.v b/CoqOfPython/ethereum/frontier/vm/instructions/keccak.v index cab9ffb..2c4b10e 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/keccak.v @@ -137,7 +137,7 @@ Definition keccak : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/log.v b/CoqOfPython/ethereum/frontier/vm/instructions/log.v index f246f9d..ab196bc 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/log.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/log.v @@ -153,7 +153,7 @@ Definition log_n : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/memory.v b/CoqOfPython/ethereum/frontier/vm/instructions/memory.v index 1e1c8b0..86ba742 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/memory.v @@ -121,7 +121,7 @@ Definition mstore : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -203,7 +203,7 @@ Definition mstore8 : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -288,7 +288,7 @@ Definition mload : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/stack.v b/CoqOfPython/ethereum/frontier/vm/instructions/stack.v index 1eeda05..305af15 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/stack.v @@ -188,13 +188,16 @@ Definition dup_n : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] - |) |); + Compare.lt (| + M.get_name (| globals, "item_number" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + |); M.get_name (| globals, "StackUnderflowError" |) ], make_dict [] @@ -260,13 +263,16 @@ Definition swap_n : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] - |) |); + Compare.lt (| + M.get_name (| globals, "item_number" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + |); M.get_name (| globals, "StackUnderflowError" |) ], make_dict [] diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/storage.v b/CoqOfPython/ethereum/frontier/vm/instructions/storage.v index 4292e3b..5250214 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/storage.v @@ -146,44 +146,11 @@ Definition sstore : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "new_value" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let gas_cost := - M.get_name (| globals, "GAS_STORAGE_SET" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let gas_cost := M.get_name (| globals, "GAS_STORAGE_UPDATE" |) in M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_name (| globals, "new_value" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), - M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/system.v b/CoqOfPython/ethereum/frontier/vm/instructions/system.v index 782fcdd..859f97f 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/system.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/system.v @@ -155,7 +155,7 @@ Definition create : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -187,96 +187,7 @@ Definition create : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.lt (| M.get_field (| M.get_name (| globals, "sender" |), "balance" |), M.get_name (| globals, "endowment" |) |), - ltac:(M.monadic ( - BoolOp.or (| - Compare.eq (| M.get_field (| M.get_name (| globals, "sender" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - BinOp.sub (| - BinOp.pow (| - Constant.int 2, - Constant.int 64 - |), - Constant.int 1 - |) - ], - make_dict [] - |) |), - ltac:(M.monadic ( - Compare.gt (| BinOp.add (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "depth" |), - Constant.int 1 - |), M.get_name (| globals, "STACK_DEPTH_LIMIT" |) |) - )) - |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "push" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |); - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) - ], - make_dict [] - |) in - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), - M.get_name (| globals, "create_message_gas" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_has_code_or_nonce" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); - M.get_name (| globals, "contract_address" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "increment_nonce" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) - ], - make_dict [] - |) in - let _ := M.call (| - M.get_name (| globals, "push" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |); - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let call_data := M.call (| M.get_name (| globals, "memory_read_bytes" |), @@ -311,36 +222,6 @@ Definition create : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "child_evm" |), "error" |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "incorporate_child_on_error" |), - make_list [ - M.get_name (| globals, "evm" |); - M.get_name (| globals, "child_evm" |) - ], - make_dict [] - |) in - let _ := M.call (| - M.get_name (| globals, "push" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |); - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "incorporate_child_on_success" |), make_list [ @@ -429,7 +310,7 @@ Definition return_ : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -460,39 +341,6 @@ Definition generic_call : Value.t -> Value.t -> M := " in (* At stmt: unsupported node type: ImportFrom *) let _ := - (* if *) - M.if_then_else (| - Compare.gt (| BinOp.add (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "depth" |), - Constant.int 1 - |), M.get_name (| globals, "STACK_DEPTH_LIMIT" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), - M.get_name (| globals, "gas" |) - |) in - let _ := M.call (| - M.get_name (| globals, "push" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |); - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) - ], - make_dict [] - |) in - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let call_data := @@ -530,36 +378,6 @@ Definition generic_call : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "child_evm" |), "error" |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "incorporate_child_on_error" |), - make_list [ - M.get_name (| globals, "evm" |); - M.get_name (| globals, "child_evm" |) - ], - make_dict [] - |) in - let _ := M.call (| - M.get_name (| globals, "push" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |); - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "incorporate_child_on_success" |), make_list [ @@ -610,7 +428,7 @@ Definition generic_call : Value.t -> Value.t -> M := make_list [ M.get_field (| M.get_name (| globals, "evm" |), "memory" |); M.get_name (| globals, "memory_output_start_position" |); - M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), (* At expr: unsupported node type: NoneType *):M.get_name (| globals, "actual_output_size" |) |) + M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), Constant.None_:M.get_name (| globals, "actual_output_size" |) |) ], make_dict [] |) in @@ -733,7 +551,7 @@ Definition call : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -747,33 +565,6 @@ Definition call : Value.t -> Value.t -> M := make_dict [] |), "balance" |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "sender_balance" |), M.get_name (| globals, "value" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "push" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |); - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) - ], - make_dict [] - |) in - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), - M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "generic_call" |), make_list [ @@ -918,7 +709,7 @@ Definition callcode : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -932,33 +723,6 @@ Definition callcode : Value.t -> Value.t -> M := make_dict [] |), "balance" |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "sender_balance" |), M.get_name (| globals, "value" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "push" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |); - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) - ], - make_dict [] - |) in - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), - M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "generic_call" |), make_list [ @@ -1017,7 +781,10 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in let parent_evm := M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "parent_evm" |) in - While Compare.is_not (| M.get_name (| globals, "parent_evm" |), Constant.None_ |) do + While Compare.is_not (| + M.get_name (| globals, "parent_evm" |), + Constant.None_ + |) do let _ := M.call (| M.get_field (| M.get_name (| globals, "refunded_accounts" |), "update" |), make_list [ @@ -1029,19 +796,6 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in EndWhile. let _ := - (* if *) - M.if_then_else (| - Compare.not_in (| M.get_name (| globals, "originator" |), M.get_name (| globals, "refunded_accounts" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), - M.get_name (| globals, "REFUND_SELF_DESTRUCT" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/frontier/vm/interpreter.v b/CoqOfPython/ethereum/frontier/vm/interpreter.v index 94f70de..7665575 100644 --- a/CoqOfPython/ethereum/frontier/vm/interpreter.v +++ b/CoqOfPython/ethereum/frontier/vm/interpreter.v @@ -162,86 +162,6 @@ Definition process_message_call : Value.t -> Value.t -> M := Output of the message call " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_name (| globals, "message" |), "target" |), M.call (| - M.get_name (| globals, "Bytes0" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let is_collision := - M.call (| - M.get_name (| globals, "account_has_code_or_nonce" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_field (| M.get_name (| globals, "message" |), "current_target" |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - M.get_name (| globals, "is_collision" |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "MessageCallOutput" |), - make_list [ - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |); - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |); - M.call (| - M.get_name (| globals, "tuple" |), - make_list [], - make_dict [] - |); - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |); - M.call (| - M.get_name (| globals, "AddressCollision" |), - make_list [], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let evm := - M.call (| - M.get_name (| globals, "process_create_message" |), - make_list [ - M.get_name (| globals, "message" |); - M.get_name (| globals, "env" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let evm := M.call (| M.get_name (| globals, "process_message" |), @@ -254,29 +174,6 @@ Definition process_message_call : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "evm" |), "error" |), - (* then *) - ltac:(M.monadic ( -(* At stmt: unsupported node type: AnnAssign *) - let accounts_to_delete := - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |) in - let refund_counter := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let logs := M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in let accounts_to_delete := @@ -312,7 +209,6 @@ Definition process_message_call : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). Definition process_create_message : Value.t -> Value.t -> M := @@ -358,35 +254,6 @@ Definition process_create_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), - (* then *) - ltac:(M.monadic ( - let contract_code := - M.get_field (| M.get_name (| globals, "evm" |), "output" |) in - let contract_code_gas := - BinOp.mult (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "contract_code" |) - ], - make_dict [] - |), - M.get_name (| globals, "GAS_CODE_DEPOSIT" |) - |) in -(* At stmt: unsupported node type: Try *) - let _ := M.call (| - M.get_name (| globals, "commit_transaction" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "rollback_transaction" |), make_list [ @@ -398,7 +265,6 @@ Definition process_create_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) - |) in M.pure Constant.None_)). Definition process_message : Value.t -> Value.t -> M := @@ -420,21 +286,6 @@ Definition process_message : Value.t -> Value.t -> M := Items containing execution specific objects " in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_field (| M.get_name (| globals, "message" |), "depth" |), M.get_name (| globals, "STACK_DEPTH_LIMIT" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "StackDepthLimitError" |), - make_list [ - Constant.str "Stack depth limit reached" - ], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -453,24 +304,6 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_eq (| M.get_field (| M.get_name (| globals, "message" |), "value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "move_ether" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_field (| M.get_name (| globals, "message" |), "caller" |); - M.get_field (| M.get_name (| globals, "message" |), "current_target" |); - M.get_field (| M.get_name (| globals, "message" |), "value" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let evm := @@ -483,21 +316,6 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "evm" |), "error" |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "rollback_transaction" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "commit_transaction" |), make_list [ @@ -509,7 +327,6 @@ Definition process_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) - |) in M.pure Constant.None_)). Definition execute_code : Value.t -> Value.t -> M := @@ -549,5 +366,4 @@ Definition execute_code : Value.t -> Value.t -> M := (* At stmt: unsupported node type: Try *) let _ := M.return_ (| M.get_name (| globals, "evm" |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/vm/memory.v b/CoqOfPython/ethereum/frontier/vm/memory.v index fa8d906..4b107fd 100644 --- a/CoqOfPython/ethereum/frontier/vm/memory.v +++ b/CoqOfPython/ethereum/frontier/vm/memory.v @@ -45,22 +45,7 @@ Definition memory_write : Value.t -> Value.t -> M := Data to write to memory. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) - |) |), + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_)). @@ -86,23 +71,7 @@ Definition memory_read_bytes : Value.t -> Value.t -> M := Data read from memory. " in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |) - |) in + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |) M.pure Constant.None_)). Definition buffer_read : Value.t -> Value.t -> M := @@ -129,25 +98,9 @@ Definition buffer_read : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "right_pad_zero_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |); + M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |) |); M.get_name (| globals, "size" |) ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/ecrecover.v index cc351b5..0cbcf16 100644 --- a/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/ecrecover.v @@ -188,60 +188,12 @@ Definition ecrecover : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 27 |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 28 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| Constant.int 0, M.get_name (| globals, "r" |) |), - ltac:(M.monadic ( - Compare.gt_e (| M.get_name (| globals, "r" |), M.get_name (| globals, "SECP256K1N" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| Constant.int 0, M.get_name (| globals, "s" |) |), - ltac:(M.monadic ( - Compare.gt_e (| M.get_name (| globals, "s" |), M.get_name (| globals, "SECP256K1N" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: Try *) @@ -252,7 +204,7 @@ Definition ecrecover : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12:Constant.int 32 |) in + |), Constant.int 12 |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/frontier/vm/runtime.v b/CoqOfPython/ethereum/frontier/vm/runtime.v index 835b46c..2cd7652 100644 --- a/CoqOfPython/ethereum/frontier/vm/runtime.v +++ b/CoqOfPython/ethereum/frontier/vm/runtime.v @@ -67,50 +67,19 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := ], make_dict [] |) in - While Compare.lt (| M.get_name (| globals, "pc" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "code" |) - ], - make_dict [] - |) |) do + While Compare.lt (| + M.get_name (| globals, "pc" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) + |) do (* At stmt: unsupported node type: Try *) let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "current_opcode" |), M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), - make_list [ - M.get_name (| globals, "pc" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - (* At expr: unsupported node type: Compare *), - (* then *) - ltac:(M.monadic ( - let push_data_size := - BinOp.add (| - BinOp.sub (| - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) - |), - Constant.int 1 - |) in - let pc := BinOp.add - M.get_name (| globals, "push_data_size" |) - M.get_name (| globals, "push_data_size" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -121,5 +90,4 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := EndWhile. let _ := M.return_ (| M.get_name (| globals, "valid_jump_destinations" |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/vm/stack.v b/CoqOfPython/ethereum/frontier/vm/stack.v index 42ea42d..ea778df 100644 --- a/CoqOfPython/ethereum/frontier/vm/stack.v +++ b/CoqOfPython/ethereum/frontier/vm/stack.v @@ -49,21 +49,6 @@ Definition pop : Value.t -> Value.t -> M := " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "stack" |) - ], - make_dict [] - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "StackUnderflowError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -72,7 +57,6 @@ Definition pop : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). Definition push : Value.t -> Value.t -> M := @@ -91,21 +75,6 @@ Definition push : Value.t -> Value.t -> M := " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "stack" |) - ], - make_dict [] - |), Constant.int 1024 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "StackOverflowError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -116,5 +85,4 @@ Definition push : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/genesis.v b/CoqOfPython/ethereum/genesis.v index b6dd143..2e1c5f8 100644 --- a/CoqOfPython/ethereum/genesis.v +++ b/CoqOfPython/ethereum/genesis.v @@ -133,7 +133,6 @@ Definition get_genesis_configuration : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). Definition hex_or_base_10_str_to_u256 : Value.t -> Value.t -> M := @@ -144,29 +143,6 @@ Definition hex_or_base_10_str_to_u256 : Value.t -> Value.t -> M := numbers or 0x prefixed hex. This function supports both. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_field (| M.get_name (| globals, "balance" |), "startswith" |), - make_list [ - Constant.str "0x" - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "hex_to_u256" |), - make_list [ - M.get_name (| globals, "balance" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_name (| globals, "U256" |), @@ -181,7 +157,6 @@ Definition hex_or_base_10_str_to_u256 : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -345,120 +320,15 @@ Definition add_genesis_block : Value.t -> Value.t -> M := EndFor. EndFor. let fields := - {Constant.str "parent_hash": M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "fork_types" |), "Hash32" |), - make_list [ - BinOp.mult (| - (* At constant: unsupported node type: Constant *), - Constant.int 32 - |) - ], - make_dict [] - |), Constant.str "ommers_hash": M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), - make_list [ - make_tuple [ ] - ], - make_dict [] - |), Constant.str "coinbase": M.call (| - M.get_name (| globals, "Address" |), - make_list [ - BinOp.mult (| - (* At constant: unsupported node type: Constant *), - Constant.int 20 - |) - ], - make_dict [] - |), Constant.str "state_root": M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "state" |), "state_root" |), - make_list [ - M.get_field (| M.get_name (| globals, "chain" |), "state" |) - ], - make_dict [] - |), Constant.str "transactions_root": M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "trie" |), "root" |), - make_list [ - M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "trie" |), "Trie" |), - make_list [ - Constant.bool false; - Constant.None_ - ], - make_dict [] - |) - ], - make_dict [] - |), Constant.str "receipt_root": M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "trie" |), "root" |), - make_list [ - M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "trie" |), "Trie" |), - make_list [ - Constant.bool false; - Constant.None_ - ], - make_dict [] - |) - ], - make_dict [] - |), Constant.str "bloom": M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "fork_types" |), "Bloom" |), - make_list [ - BinOp.mult (| - (* At constant: unsupported node type: Constant *), - Constant.int 256 - |) - ], - make_dict [] - |), Constant.str "difficulty": M.get_field (| M.get_name (| globals, "genesis" |), "difficulty" |), Constant.str "number": M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |), Constant.str "gas_limit": M.get_field (| M.get_name (| globals, "genesis" |), "gas_limit" |), Constant.str "gas_used": M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |), Constant.str "timestamp": M.get_field (| M.get_name (| globals, "genesis" |), "timestamp" |), Constant.str "extra_data": M.get_field (| M.get_name (| globals, "genesis" |), "extra_data" |), Constant.str "nonce": M.get_field (| M.get_name (| globals, "genesis" |), "nonce" |)} in + {Constant.str "parent_hash", Constant.str "ommers_hash", Constant.str "coinbase", Constant.str "state_root", Constant.str "transactions_root", Constant.str "receipt_root", Constant.str "bloom", Constant.str "difficulty", Constant.str "number", Constant.str "gas_limit", Constant.str "gas_used", Constant.str "timestamp", Constant.str "extra_data", Constant.str "nonce"} in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "hasattr" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "blocks" |), "Header" |); - Constant.str "mix_digest" - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "fields" |), Constant.str "mix_digest" |), - M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "fork_types" |), "Hash32" |), - make_list [ - BinOp.mult (| - (* At constant: unsupported node type: Constant *), - Constant.int 32 - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_name (| globals, "fields" |), Constant.str "prev_randao" |), M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "fork_types" |), "Hash32" |), make_list [ BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", Constant.int 32 |) ], @@ -468,34 +338,6 @@ Definition add_genesis_block : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "hasattr" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "blocks" |), "Header" |); - Constant.str "base_fee_per_gas" - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "fields" |), Constant.str "base_fee_per_gas" |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - BinOp.pow (| - Constant.int 10, - Constant.int 9 - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let genesis_header := diff --git a/CoqOfPython/ethereum/gray_glacier/bloom.v b/CoqOfPython/ethereum/gray_glacier/bloom.v index 04b5d9f..04650ff 100644 --- a/CoqOfPython/ethereum/gray_glacier/bloom.v +++ b/CoqOfPython/ethereum/gray_glacier/bloom.v @@ -72,10 +72,7 @@ Definition add_to_bloom : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |):BinOp.add (| - M.get_name (| globals, "idx" |), - Constant.int 2 - |) |) + M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |) |) ], make_dict [] |), @@ -160,5 +157,4 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/fork.v b/CoqOfPython/ethereum/gray_glacier/fork.v new file mode 100644 index 0000000..2b1b864 --- /dev/null +++ b/CoqOfPython/ethereum/gray_glacier/fork.v @@ -0,0 +1,2385 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Specification +^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Entry point for the Ethereum specification. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". + +Require ethereum.crypto.elliptic_curve. +Axiom ethereum_crypto_elliptic_curve_SECP256K1N : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.ethash. +Axiom ethereum_ethash_dataset_size : + IsGlobalAlias globals ethereum.ethash.globals "dataset_size". +Axiom ethereum_ethash_generate_cache : + IsGlobalAlias globals ethereum.ethash.globals "generate_cache". +Axiom ethereum_ethash_hashimoto_light : + IsGlobalAlias globals ethereum.ethash.globals "hashimoto_light". + +Require ethereum.exceptions. +Axiom ethereum_exceptions_InvalidBlock : + IsGlobalAlias globals ethereum.exceptions.globals "InvalidBlock". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U64 : + IsGlobalAlias globals base_types.globals "U64". +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_U256_CEIL_VALUE : + IsGlobalAlias globals base_types.globals "U256_CEIL_VALUE". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". + +Require __init__. +Axiom __init___vm : + IsGlobalAlias globals __init__.globals "vm". + +Require blocks. +Axiom blocks_Block : + IsGlobalAlias globals blocks.globals "Block". +Axiom blocks_Header : + IsGlobalAlias globals blocks.globals "Header". +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". +Axiom blocks_Receipt : + IsGlobalAlias globals blocks.globals "Receipt". + +Require bloom. +Axiom bloom_logs_bloom : + IsGlobalAlias globals bloom.globals "logs_bloom". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Require state. +Axiom state_State : + IsGlobalAlias globals state.globals "State". +Axiom state_account_exists_and_is_empty : + IsGlobalAlias globals state.globals "account_exists_and_is_empty". +Axiom state_create_ether : + IsGlobalAlias globals state.globals "create_ether". +Axiom state_destroy_account : + IsGlobalAlias globals state.globals "destroy_account". +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". +Axiom state_increment_nonce : + IsGlobalAlias globals state.globals "increment_nonce". +Axiom state_set_account_balance : + IsGlobalAlias globals state.globals "set_account_balance". +Axiom state_state_root : + IsGlobalAlias globals state.globals "state_root". + +Require transactions. +Axiom transactions_TX_ACCESS_LIST_ADDRESS_COST : + IsGlobalAlias globals transactions.globals "TX_ACCESS_LIST_ADDRESS_COST". +Axiom transactions_TX_ACCESS_LIST_STORAGE_KEY_COST : + IsGlobalAlias globals transactions.globals "TX_ACCESS_LIST_STORAGE_KEY_COST". +Axiom transactions_TX_BASE_COST : + IsGlobalAlias globals transactions.globals "TX_BASE_COST". +Axiom transactions_TX_CREATE_COST : + IsGlobalAlias globals transactions.globals "TX_CREATE_COST". +Axiom transactions_TX_DATA_COST_PER_NON_ZERO : + IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_NON_ZERO". +Axiom transactions_TX_DATA_COST_PER_ZERO : + IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_ZERO". +Axiom transactions_AccessListTransaction : + IsGlobalAlias globals transactions.globals "AccessListTransaction". +Axiom transactions_FeeMarketTransaction : + IsGlobalAlias globals transactions.globals "FeeMarketTransaction". +Axiom transactions_LegacyTransaction : + IsGlobalAlias globals transactions.globals "LegacyTransaction". +Axiom transactions_Transaction : + IsGlobalAlias globals transactions.globals "Transaction". +Axiom transactions_decode_transaction : + IsGlobalAlias globals transactions.globals "decode_transaction". +Axiom transactions_encode_transaction : + IsGlobalAlias globals transactions.globals "encode_transaction". + +Require trie. +Axiom trie_Trie : + IsGlobalAlias globals trie.globals "Trie". +Axiom trie_root : + IsGlobalAlias globals trie.globals "root". +Axiom trie_trie_set : + IsGlobalAlias globals trie.globals "trie_set". + +Require utils.message. +Axiom utils_message_prepare_message : + IsGlobalAlias globals utils.message.globals "prepare_message". + +Require vm.interpreter. +Axiom vm_interpreter_process_message_call : + IsGlobalAlias globals vm.interpreter.globals "process_message_call". + +Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mult (| + Constant.int 2, + BinOp.pow (| + Constant.int 10, + Constant.int 18 + |) + |) + ], + make_dict [] + |) +)). + +Definition BASE_FEE_MAX_CHANGE_DENOMINATOR : Value.t := M.run ltac:(M.monadic ( + Constant.int 8 +)). + +Definition ELASTICITY_MULTIPLIER : Value.t := M.run ltac:(M.monadic ( + Constant.int 2 +)). + +Definition GAS_LIMIT_ADJUSTMENT_FACTOR : Value.t := M.run ltac:(M.monadic ( + Constant.int 1024 +)). + +Definition GAS_LIMIT_MINIMUM : Value.t := M.run ltac:(M.monadic ( + Constant.int 5000 +)). + +Definition MINIMUM_DIFFICULTY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 131072 + ], + make_dict [] + |) +)). + +Definition MAX_OMMER_DEPTH : Value.t := M.run ltac:(M.monadic ( + Constant.int 6 +)). + +Definition BOMB_DELAY_BLOCKS : Value.t := M.run ltac:(M.monadic ( + Constant.int 11400000 +)). + +Definition EMPTY_OMMER_HASH : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_list [] + ], + make_dict [] + |) + ], + make_dict [] + |) +)). + +Definition BlockChain : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition apply_fork : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "old" ] |) in + let _ := Constant.str " + Transforms the state from the previous hard fork (`old`) into the block + chain object for this hard fork and returns it. + + When forks need to implement an irregular state transition, this function + is used to handle the irregularity. See the :ref:`DAO Fork ` for + an example. + + Parameters + ---------- + old : + Previous block chain object. + + Returns + ------- + new : `BlockChain` + Upgraded block chain object for this hard fork. + " in + let _ := M.return_ (| + M.get_name (| globals, "old" |) + M.pure Constant.None_)). + +Definition get_last_256_block_hashes : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "chain" ] |) in + let _ := Constant.str " + Obtain the list of hashes of the previous 256 blocks in order of + increasing block number. + + This function will return less hashes for the first 256 blocks. + + The ``BLOCKHASH`` opcode needs to access the latest hashes on the chain, + therefore this function retrieves them. + + Parameters + ---------- + chain : + History and current state. + + Returns + ------- + recent_block_hashes : `List[Hash32]` + Hashes of the recent 256 blocks in order of increasing block number. + " in + let recent_blocks := + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |) |) in + let _ := + M.pure Constant.None_ + )) |) in + let recent_block_hashes := + make_list [] in + For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_blocks" |) do + let prev_block_hash := + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), + make_list [ + M.get_name (| globals, "prev_block_hash" |) + ], + make_dict [] + |) in + EndFor. + let most_recent_block_hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_field (| M.get_subscript (| M.get_name (| globals, "recent_blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), + make_list [ + M.get_name (| globals, "most_recent_block_hash" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "recent_block_hashes" |) + M.pure Constant.None_)). + +Definition state_transition : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "chain"; "block" ] |) in + let _ := Constant.str " + Attempts to apply a block to an existing block chain. + + All parts of the block's contents need to be verified before being added + to the chain. Blocks are verified by ensuring that the contents of the + block make logical sense with the contents of the parent block. The + information in the block's header must also match the corresponding + information in the block. + + To implement Ethereum, in theory clients are only required to store the + most recent 255 blocks of the chain since as far as execution is + concerned, only those blocks are accessed. Practically, however, clients + should store more blocks to handle reorgs. + + Parameters + ---------- + chain : + History and current state. + block : + Block to apply to `chain`. + " in + let parent_header := + M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) in + let _ := M.call (| + M.get_name (| globals, "validate_header" |), + make_list [ + M.get_field (| M.get_name (| globals, "block" |), "header" |); + M.get_name (| globals, "parent_header" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "validate_ommers" |), + make_list [ + M.get_field (| M.get_name (| globals, "block" |), "ommers" |); + M.get_field (| M.get_name (| globals, "block" |), "header" |); + M.get_name (| globals, "chain" |) + ], + make_dict [] + |) in + let apply_body_output := + M.call (| + M.get_name (| globals, "apply_body" |), + make_list [ + M.get_field (| M.get_name (| globals, "chain" |), "state" |); + M.call (| + M.get_name (| globals, "get_last_256_block_hashes" |), + make_list [ + M.get_name (| globals, "chain" |) + ], + make_dict [] + |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "coinbase" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "number" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "base_fee_per_gas" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "gas_limit" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "timestamp" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "difficulty" |); + M.get_field (| M.get_name (| globals, "block" |), "transactions" |); + M.get_field (| M.get_name (| globals, "block" |), "ommers" |); + M.get_field (| M.get_name (| globals, "chain" |), "chain_id" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_gas_used" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "gas_used" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "transactions_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "transactions_root" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "state_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "state_root" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "receipt_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "receipt_root" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_logs_bloom" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "bloom" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), "append" |), + make_list [ + M.get_name (| globals, "block" |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "block_gas_limit"; "parent_gas_limit"; "parent_gas_used"; "parent_base_fee_per_gas" ] |) in + let _ := Constant.str " + Calculates the base fee per gas for the block. + + Parameters + ---------- + block_gas_limit : + Gas limit of the block for which the base fee is being calculated. + parent_gas_limit : + Gas limit of the parent block. + parent_gas_used : + Gas used in the parent block. + parent_base_fee_per_gas : + Base fee per gas of the parent block. + + Returns + ------- + base_fee_per_gas : `Uint` + Base fee per gas for the block. + " in + let parent_gas_target := + BinOp.floor_div (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "ELASTICITY_MULTIPLIER" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + M.call (| + M.get_name (| globals, "check_gas_limit" |), + make_list [ + M.get_name (| globals, "block_gas_limit" |); + M.get_name (| globals, "parent_gas_limit" |) + ], + make_dict [] + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := + let _ := + let gas_used_delta := + BinOp.sub (| + M.get_name (| globals, "parent_gas_target" |), + M.get_name (| globals, "parent_gas_used" |) + |) in + let parent_fee_gas_delta := + BinOp.mult (| + M.get_name (| globals, "parent_base_fee_per_gas" |), + M.get_name (| globals, "gas_used_delta" |) + |) in + let target_fee_gas_delta := + BinOp.floor_div (| + M.get_name (| globals, "parent_fee_gas_delta" |), + M.get_name (| globals, "parent_gas_target" |) + |) in + let base_fee_per_gas_delta := + BinOp.floor_div (| + M.get_name (| globals, "target_fee_gas_delta" |), + M.get_name (| globals, "BASE_FEE_MAX_CHANGE_DENOMINATOR" |) + |) in + let expected_base_fee_per_gas := + BinOp.sub (| + M.get_name (| globals, "parent_base_fee_per_gas" |), + M.get_name (| globals, "base_fee_per_gas_delta" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "expected_base_fee_per_gas" |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition validate_header : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header"; "parent_header" ] |) in + let _ := Constant.str " + Verifies a block header. + + In order to consider a block's header valid, the logic for the + quantities in the header should match the logic for the block itself. + For example the header timestamp should be greater than the block's parent + timestamp because the block was created *after* the parent block. + Additionally, the block's number should be directly following the parent + block's number since it is the next block in the sequence. + + Parameters + ---------- + header : + Header to check for correctness. + parent_header : + Parent Header of the header to check for correctness + " in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "header" |), "gas_used" |), + M.get_field (| M.get_name (| globals, "header" |), "gas_limit" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let expected_base_fee_per_gas := + M.call (| + M.get_name (| globals, "calculate_base_fee_per_gas" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "gas_limit" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "gas_limit" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "gas_used" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "base_fee_per_gas" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_name (| globals, "expected_base_fee_per_gas" |), + M.get_field (| M.get_name (| globals, "header" |), "base_fee_per_gas" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let parent_has_ommers := + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "parent_header" |), "ommers_hash" |), + M.get_name (| globals, "EMPTY_OMMER_HASH" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt (| + M.get_field (| M.get_name (| globals, "header" |), "timestamp" |), + M.get_field (| M.get_name (| globals, "parent_header" |), "timestamp" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "number" |), + BinOp.add (| + M.get_field (| M.get_name (| globals, "parent_header" |), "number" |), + Constant.int 1 + |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) + ], + make_dict [] + |), + Constant.int 32 + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let block_difficulty := + M.call (| + M.get_name (| globals, "calculate_block_difficulty" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "number" |); + M.get_field (| M.get_name (| globals, "header" |), "timestamp" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "timestamp" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "difficulty" |); + M.get_name (| globals, "parent_has_ommers" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "difficulty" |), + M.get_name (| globals, "block_difficulty" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let block_parent_hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "parent_header" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |), + M.get_name (| globals, "block_parent_hash" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "validate_proof_of_work" |), + make_list [ + M.get_name (| globals, "header" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header" ] |) in + let _ := Constant.str " + Generate rlp hash of the header which is to be used for Proof-of-Work + verification. + + In other words, the PoW artefacts `mix_digest` and `nonce` are ignored + while calculating this hash. + + A particular PoW is valid for a single hash, that hash is computed by + this function. The `nonce` and `mix_digest` are omitted from this hash + because they are being changed by miners in their search for a sufficient + proof-of-work. + + Parameters + ---------- + header : + The header object for which the hash is to be generated. + + Returns + ------- + hash : `Hash32` + The PoW valid rlp hash of the passed in header. + " in + let header_data_without_pow_artefacts := + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |); + M.get_field (| M.get_name (| globals, "header" |), "ommers_hash" |); + M.get_field (| M.get_name (| globals, "header" |), "coinbase" |); + M.get_field (| M.get_name (| globals, "header" |), "state_root" |); + M.get_field (| M.get_name (| globals, "header" |), "transactions_root" |); + M.get_field (| M.get_name (| globals, "header" |), "receipt_root" |); + M.get_field (| M.get_name (| globals, "header" |), "bloom" |); + M.get_field (| M.get_name (| globals, "header" |), "difficulty" |); + M.get_field (| M.get_name (| globals, "header" |), "number" |); + M.get_field (| M.get_name (| globals, "header" |), "gas_limit" |); + M.get_field (| M.get_name (| globals, "header" |), "gas_used" |); + M.get_field (| M.get_name (| globals, "header" |), "timestamp" |); + M.get_field (| M.get_name (| globals, "header" |), "extra_data" |); + M.get_field (| M.get_name (| globals, "header" |), "base_fee_per_gas" |) + ] in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "header_data_without_pow_artefacts" |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition validate_proof_of_work : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header" ] |) in + let _ := Constant.str " + Validates the Proof of Work constraints. + + In order to verify that a miner's proof-of-work is valid for a block, a + ``mix-digest`` and ``result`` are calculated using the ``hashimoto_light`` + hash function. The mix digest is a hash of the header and the nonce that + is passed through and it confirms whether or not proof-of-work was done + on the correct block. The result is the actual hash value of the block. + + Parameters + ---------- + header : + Header of interest. + " in + let header_hash := + M.call (| + M.get_name (| globals, "generate_header_hash_for_pow" |), + make_list [ + M.get_name (| globals, "header" |) + ], + make_dict [] + |) in + let cache := + M.call (| + M.get_name (| globals, "generate_cache" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "number" |) + ], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "mix_digest" |); M.get_name (| globals, "result" |) ], + M.call (| + M.get_name (| globals, "hashimoto_light" |), + make_list [ + M.get_name (| globals, "header_hash" |); + M.get_field (| M.get_name (| globals, "header" |), "nonce" |); + M.get_name (| globals, "cache" |); + M.call (| + M.get_name (| globals, "dataset_size" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "number" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_name (| globals, "mix_digest" |), + M.get_field (| M.get_name (| globals, "header" |), "mix_digest" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "result" |) + ], + make_dict [] + |), + BinOp.floor_div (| + M.get_name (| globals, "U256_CEIL_VALUE" |), + M.get_field (| M.get_name (| globals, "header" |), "difficulty" |) + |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition check_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx"; "base_fee_per_gas"; "gas_available"; "chain_id" ] |) in + let _ := Constant.str " + Check if the transaction is includable in the block. + + Parameters + ---------- + tx : + The transaction. + base_fee_per_gas : + The block base fee. + gas_available : + The gas remaining in the block. + chain_id : + The ID of the current chain. + + Returns + ------- + sender_address : + The sender of the transaction. + effective_gas_price : + The price to charge for gas when the transaction is executed. + + Raises + ------ + InvalidBlock : + If the transaction is not includable. + " in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_name (| globals, "gas_available" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let sender_address := + M.call (| + M.get_name (| globals, "recover_sender" |), + make_list [ + M.get_name (| globals, "chain_id" |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt_e (| + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |), + M.get_name (| globals, "base_fee_per_gas" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let effective_gas_price := + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + make_tuple [ M.get_name (| globals, "sender_address" |); M.get_name (| globals, "effective_gas_price" |) ] + M.pure Constant.None_)). + +Definition make_receipt : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx"; "error"; "cumulative_gas_used"; "logs" ] |) in + let _ := Constant.str " + Make the receipt for a transaction that was executed. + + Parameters + ---------- + tx : + The executed transaction. + error : + Error in the top level frame of the transaction, if any. + cumulative_gas_used : + The total gas used so far in the block after the transaction was + executed. + logs : + The logs produced by the transaction. + + Returns + ------- + receipt : + The receipt for the transaction. + " in + let receipt := + M.call (| + M.get_name (| globals, "Receipt" |), + make_list [], + make_dict [] + |) in + let _ := + let _ := + let _ := M.return_ (| + M.get_name (| globals, "receipt" |) + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition ApplyBodyOutput : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition apply_body : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "block_hashes"; "coinbase"; "block_number"; "base_fee_per_gas"; "block_gas_limit"; "block_time"; "block_difficulty"; "transactions"; "ommers"; "chain_id" ] |) in + let _ := Constant.str " + Executes a block. + + Many of the contents of a block are stored in data structures called + tries. There is a transactions trie which is similar to a ledger of the + transactions stored in the current block. There is also a receipts trie + which stores the results of executing a transaction, like the post state + and gas used. This function creates and executes the block that is to be + added to the chain. + + Parameters + ---------- + state : + Current account state. + block_hashes : + List of hashes of the previous 256 blocks in the order of + increasing block number. + coinbase : + Address of account which receives block reward and transaction fees. + block_number : + Position of the block within the chain. + base_fee_per_gas : + Base fee per gas of within the block. + block_gas_limit : + Initial amount of gas available for execution in this block. + block_time : + Time the block was produced, measured in seconds since the epoch. + block_difficulty : + Difficulty of the block. + transactions : + Transactions included in the block. + ommers : + Headers of ancestor blocks which are not direct parents (formerly + uncles.) + chain_id : + ID of the executing chain. + + Returns + ------- + apply_body_output : `ApplyBodyOutput` + Output of applying the block body to the state. + " in + let gas_available := + M.get_name (| globals, "block_gas_limit" |) in +(* At stmt: unsupported node type: AnnAssign *) +(* At stmt: unsupported node type: AnnAssign *) +(* At stmt: unsupported node type: AnnAssign *) + For make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "tx" |) ] in M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.call (| + M.get_name (| globals, "map" |), + make_list [ + M.get_name (| globals, "decode_transaction" |); + M.get_name (| globals, "transactions" |) + ], + make_dict [] + |) + ], + make_dict [] + |) do + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "transactions_trie" |); + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "i" |) + ], + make_dict [] + |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "encode_transaction" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "sender_address" |); M.get_name (| globals, "effective_gas_price" |) ], + M.call (| + M.get_name (| globals, "check_transaction" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "base_fee_per_gas" |); + M.get_name (| globals, "gas_available" |); + M.get_name (| globals, "chain_id" |) + ], + make_dict [] + |) + |) in + let env := + M.call (| + M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |); M.get_name (| globals, "error" |) ], + M.call (| + M.get_name (| globals, "process_transaction" |), + make_list [ + M.get_name (| globals, "env" |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) in + let gas_available := BinOp.sub + M.get_name (| globals, "gas_used" |) + M.get_name (| globals, "gas_used" |) in + let receipt := + M.call (| + M.get_name (| globals, "make_receipt" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "error" |); + BinOp.sub (| + M.get_name (| globals, "block_gas_limit" |), + M.get_name (| globals, "gas_available" |) + |); + M.get_name (| globals, "logs" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "receipts_trie" |); + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "i" |) + ], + make_dict [] + |) + ], + make_dict [] + |); + M.get_name (| globals, "receipt" |) + ], + make_dict [] + |) in + let block_logs := BinOp.add + M.get_name (| globals, "logs" |) + M.get_name (| globals, "logs" |) in + EndFor. + let _ := M.call (| + M.get_name (| globals, "pay_rewards" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "block_number" |); + M.get_name (| globals, "coinbase" |); + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |) in + let block_gas_used := + BinOp.sub (| + M.get_name (| globals, "block_gas_limit" |), + M.get_name (| globals, "gas_available" |) + |) in + let block_logs_bloom := + M.call (| + M.get_name (| globals, "logs_bloom" |), + make_list [ + M.get_name (| globals, "block_logs" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ApplyBodyOutput" |), + make_list [ + M.get_name (| globals, "block_gas_used" |); + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_name (| globals, "transactions_trie" |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_name (| globals, "receipts_trie" |) + ], + make_dict [] + |); + M.get_name (| globals, "block_logs_bloom" |); + M.call (| + M.get_name (| globals, "state_root" |), + make_list [ + M.get_name (| globals, "state" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition validate_ommers : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "ommers"; "block_header"; "chain" ] |) in + let _ := Constant.str " + Validates the ommers mentioned in the block. + + An ommer block is a block that wasn't canonically added to the + blockchain because it wasn't validated as fast as the canonical block + but was mined at the same time. + + To be considered valid, the ommers must adhere to the rules defined in + the Ethereum protocol. The maximum amount of ommers is 2 per block and + there cannot be duplicate ommers in a block. Many of the other ommer + constraints are listed in the in-line comments of this function. + + Parameters + ---------- + ommers : + List of ommers mentioned in the current block. + block_header: + The header of current block. + chain : + History and current state. + " in + let block_hash := + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "block_header" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + M.get_field (| M.get_name (| globals, "block_header" |), "ommers_hash" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.and (| + Compare.lt_e (| + Constant.int 1, + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |), + ltac:(M.monadic ( + Compare.lt (| + M.get_field (| M.get_name (| globals, "ommer" |), "number" |), + M.get_field (| M.get_name (| globals, "block_header" |), "number" |) + |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let ommer_parent_header := + M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), BinOp.sub (| + UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) |), + Constant.int 1 + |) |), "header" |) in + let _ := M.call (| + M.get_name (| globals, "validate_header" |), + make_list [ + M.get_name (| globals, "ommer" |); + M.get_name (| globals, "ommer_parent_header" |) + ], + make_dict [] + |) in + EndFor. + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + Constant.int 2 + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let ommers_hashes := + (* At expr: unsupported node type: ListComp *) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers_hashes" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_name (| globals, "set" |), + make_list [ + M.get_name (| globals, "ommers_hashes" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let recent_canonical_blocks := + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| BinOp.add (| + M.get_name (| globals, "MAX_OMMER_DEPTH" |), + Constant.int 1 + |) |) |) in + let recent_canonical_block_hashes := + (* At expr: unsupported node type: SetComp *) in +(* At stmt: unsupported node type: AnnAssign *) + For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_canonical_blocks" |) do + let recent_ommers_hashes := + M.call (| + M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), + make_list [ + (* At expr: unsupported node type: SetComp *) + ], + make_dict [] + |) in + EndFor. + For make_tuple [ M.get_name (| globals, "ommer_index" |); M.get_name (| globals, "ommer" |) ] in M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |) do + let ommer_hash := + M.get_subscript (| M.get_name (| globals, "ommers_hashes" |), M.get_name (| globals, "ommer_index" |) |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_eq (| + M.get_name (| globals, "ommer_hash" |), + M.get_name (| globals, "block_hash" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_in (| + M.get_name (| globals, "ommer_hash" |), + M.get_name (| globals, "recent_canonical_block_hashes" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_in (| + M.get_name (| globals, "ommer_hash" |), + M.get_name (| globals, "recent_ommers_hashes" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let ommer_age := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.and (| + Compare.lt_e (| + Constant.int 1, + M.get_name (| globals, "ommer_age" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_name (| globals, "ommer_age" |), + M.get_name (| globals, "MAX_OMMER_DEPTH" |) + |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.in (| + M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), + M.get_name (| globals, "recent_canonical_block_hashes" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), + M.get_field (| M.get_name (| globals, "block_header" |), "parent_hash" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_)). + +Definition pay_rewards : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "block_number"; "coinbase"; "ommers" ] |) in + let _ := Constant.str " + Pay rewards to the block miner as well as the ommers miners. + + The miner of the canonical block is rewarded with the predetermined + block reward, ``BLOCK_REWARD``, plus a variable award based off of the + number of ommer blocks that were mined around the same time, and included + in the canonical block's header. An ommer block is a block that wasn't + added to the canonical blockchain because it wasn't validated as fast as + the accepted block but was mined at the same time. Although not all blocks + that are mined are added to the canonical chain, miners are still paid a + reward for their efforts. This reward is called an ommer reward and is + calculated based on the number associated with the ommer block that they + mined. + + Parameters + ---------- + state : + Current account state. + block_number : + Position of the block within the chain. + coinbase : + Address of account which receives block reward and transaction fees. + ommers : + List of ommers mentioned in the current block. + " in + let miner_reward := + BinOp.add (| + M.get_name (| globals, "BLOCK_REWARD" |), + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + BinOp.floor_div (| + M.get_name (| globals, "BLOCK_REWARD" |), + Constant.int 32 + |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "create_ether" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "coinbase" |); + M.get_name (| globals, "miner_reward" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do + let ommer_age := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "block_number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) + ], + make_dict [] + |) in + let ommer_miner_reward := + BinOp.floor_div (| + BinOp.mult (| + BinOp.sub (| + Constant.int 8, + M.get_name (| globals, "ommer_age" |) + |), + M.get_name (| globals, "BLOCK_REWARD" |) + |), + Constant.int 8 + |) in + let _ := M.call (| + M.get_name (| globals, "create_ether" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_field (| M.get_name (| globals, "ommer" |), "coinbase" |); + M.get_name (| globals, "ommer_miner_reward" |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_)). + +Definition process_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "env"; "tx" ] |) in + let _ := Constant.str " + Execute a transaction against the provided environment. + + This function processes the actions needed to execute a transaction. + It decrements the sender's account after calculating the gas fee and + refunds them the proper amount after execution. Calling contracts, + deploying code, and incrementing nonces are all examples of actions that + happen within this function or from a call made within this function. + + Accounts that are marked for deletion are processed and destroyed after + execution. + + Parameters + ---------- + env : + Environment for the Ethereum Virtual Machine. + tx : + Transaction to execute. + + Returns + ------- + gas_left : `ethereum.base_types.U256` + Remaining gas after execution. + logs : `Tuple[ethereum.blocks.Log, ...]` + Logs generated during execution. + " in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + M.call (| + M.get_name (| globals, "validate_transaction" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let sender := + M.get_field (| M.get_name (| globals, "env" |), "origin" |) in + let sender_account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |) in + let _ := + let max_gas_fee := + BinOp.mult (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "sender_account" |), "nonce" |), + M.get_field (| M.get_name (| globals, "tx" |), "nonce" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt_e (| + M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), + BinOp.add (| + M.get_name (| globals, "max_gas_fee" |), + M.get_field (| M.get_name (| globals, "tx" |), "value" |) + |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "sender_account" |), "code" |), + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [], + make_dict [] + |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let effective_gas_fee := + BinOp.mult (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "env" |), "gas_price" |) + |) in + let gas := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.call (| + M.get_name (| globals, "calculate_intrinsic_cost" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) in + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |) in + let sender_balance_after_gas_fee := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), + M.get_name (| globals, "effective_gas_fee" |) + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |); + M.get_name (| globals, "sender_balance_after_gas_fee" |) + ], + make_dict [] + |) in + let preaccessed_addresses := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let preaccessed_storage_keys := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let message := + M.call (| + M.get_name (| globals, "prepare_message" |), + make_list [ + M.get_name (| globals, "sender" |); + M.get_field (| M.get_name (| globals, "tx" |), "to" |); + M.get_field (| M.get_name (| globals, "tx" |), "value" |); + M.get_field (| M.get_name (| globals, "tx" |), "data" |); + M.get_name (| globals, "gas" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let output := + M.call (| + M.get_name (| globals, "process_message_call" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let gas_used := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "output" |), "gas_left" |) + |) in + let gas_refund := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + BinOp.floor_div (| + M.get_name (| globals, "gas_used" |), + Constant.int 5 + |); + M.get_field (| M.get_name (| globals, "output" |), "refund_counter" |) + ], + make_dict [] + |) in + let gas_refund_amount := + BinOp.mult (| + BinOp.add (| + M.get_field (| M.get_name (| globals, "output" |), "gas_left" |), + M.get_name (| globals, "gas_refund" |) + |), + M.get_field (| M.get_name (| globals, "env" |), "gas_price" |) + |) in + let priority_fee_per_gas := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "env" |), "gas_price" |), + M.get_field (| M.get_name (| globals, "env" |), "base_fee_per_gas" |) + |) in + let transaction_fee := + BinOp.mult (| + BinOp.sub (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "output" |), "gas_left" |) + |), + M.get_name (| globals, "gas_refund" |) + |), + M.get_name (| globals, "priority_fee_per_gas" |) + |) in + let total_gas_used := + BinOp.sub (| + M.get_name (| globals, "gas_used" |), + M.get_name (| globals, "gas_refund" |) + |) in + let sender_balance_after_refund := + BinOp.add (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |), "balance" |), + M.get_name (| globals, "gas_refund_amount" |) + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |); + M.get_name (| globals, "sender_balance_after_refund" |) + ], + make_dict [] + |) in + let coinbase_balance_after_mining_fee := + BinOp.add (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |), "balance" |), + M.get_name (| globals, "transaction_fee" |) + |) in + let _ := + let _ := + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "accounts_to_delete" |) do + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + EndFor. + For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "touched_accounts" |) do + let _ := + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.return_ (| + make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |); M.get_field (| M.get_name (| globals, "output" |), "error" |) ] + M.pure Constant.None_)). + +Definition validate_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Verifies a transaction. + + The gas in a transaction gets used to pay for the intrinsic cost of + operations, therefore if there is insufficient gas then it would not + be possible to execute a transaction and it will be declared invalid. + + Additionally, the nonce of a transaction must not equal or exceed the + limit defined in `EIP-2681 `_. + In practice, defining the limit as ``2**64-1`` has no impact because + sending ``2**64-1`` transactions is improbable. It's not strictly + impossible though, ``2**64-1`` transactions is the entire capacity of the + Ethereum blockchain at 2022 gas limits for a little over 22 years. + + Parameters + ---------- + tx : + Transaction to validate. + + Returns + ------- + verified : `bool` + True if the transaction can be executed, or False otherwise. + " in + let _ := M.return_ (| + BoolOp.and (| + Compare.lt_e (| + M.call (| + M.get_name (| globals, "calculate_intrinsic_cost" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |), + M.get_field (| M.get_name (| globals, "tx" |), "gas" |) + |), + ltac:(M.monadic ( + Compare.lt (| + M.get_field (| M.get_name (| globals, "tx" |), "nonce" |), + BinOp.sub (| + BinOp.pow (| + Constant.int 2, + Constant.int 64 + |), + Constant.int 1 + |) + |) + )) + |) + M.pure Constant.None_)). + +Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Calculates the gas that is charged before execution is started. + + The intrinsic cost of the transaction is charged before execution has + begun. Functions/operations in the EVM cost money to execute so this + intrinsic cost is for the operations that need to be paid for as part of + the transaction. Data transfer, for example, is part of this intrinsic + cost. It costs ether to send data over the wire and that ether is + accounted for in the intrinsic cost calculated in this function. This + intrinsic cost must be calculated and paid for before execution in order + for all operations to be implemented. + + Parameters + ---------- + tx : + Transaction to compute the intrinsic cost of. + + Returns + ------- + verified : `ethereum.base_types.Uint` + The intrinsic cost of the transaction. + " in + let data_cost := + Constant.int 0 in + For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do + let _ := + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + M.pure Constant.None_ + )) |) in + EndFor. + let _ := + let create_cost := + Constant.int 0 in + M.pure Constant.None_ + )) |) in + let access_list_cost := + Constant.int 0 in + let _ := + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.add (| + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "TX_BASE_COST" |), + M.get_name (| globals, "data_cost" |) + |), + M.get_name (| globals, "create_cost" |) + |), + M.get_name (| globals, "access_list_cost" |) + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition recover_sender : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "chain_id"; "tx" ] |) in + let _ := Constant.str " + Extracts the sender address from a transaction. + + The v, r, and s values are the three parts that make up the signature + of a transaction. In order to recover the sender of a transaction the two + components needed are the signature (``v``, ``r``, and ``s``) and the + signing hash of the transaction. The sender's public key can be obtained + with these two values and therefore the sender address can be retrieved. + + Parameters + ---------- + tx : + Transaction of interest. + chain_id : + ID of the executing chain. + + Returns + ------- + sender : `ethereum.fork_types.Address` + The address of the account that signed the transaction. + " in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "r" |); M.get_name (| globals, "s" |) ], + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "r" |); M.get_field (| M.get_name (| globals, "tx" |), "s" |) ] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.and (| + Compare.lt (| + Constant.int 0, + M.get_name (| globals, "r" |) + |), + ltac:(M.monadic ( + Compare.lt (| + M.get_name (| globals, "r" |), + M.get_name (| globals, "SECP256K1N" |) + |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.and (| + Compare.lt (| + Constant.int 0, + M.get_name (| globals, "s" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_name (| globals, "s" |), + BinOp.floor_div (| + M.get_name (| globals, "SECP256K1N" |), + Constant.int 2 + |) + |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := + let _ := + let _ := + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_subscript (| M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), Constant.int 12 |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition signing_hash_pre155 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Compute the hash of a transaction used in a legacy (pre EIP 155) signature. + + Parameters + ---------- + tx : + Transaction of interest. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the transaction. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "nonce" |); M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |); M.get_field (| M.get_name (| globals, "tx" |), "gas" |); M.get_field (| M.get_name (| globals, "tx" |), "to" |); M.get_field (| M.get_name (| globals, "tx" |), "value" |); M.get_field (| M.get_name (| globals, "tx" |), "data" |) ] + ], + make_dict [] + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition signing_hash_155 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx"; "chain_id" ] |) in + let _ := Constant.str " + Compute the hash of a transaction used in a EIP 155 signature. + + Parameters + ---------- + tx : + Transaction of interest. + chain_id : + The id of the current chain. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the transaction. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "nonce" |); M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |); M.get_field (| M.get_name (| globals, "tx" |), "gas" |); M.get_field (| M.get_name (| globals, "tx" |), "to" |); M.get_field (| M.get_name (| globals, "tx" |), "value" |); M.get_field (| M.get_name (| globals, "tx" |), "data" |); M.get_name (| globals, "chain_id" |); M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) ] + ], + make_dict [] + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition signing_hash_2930 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Compute the hash of a transaction used in a EIP 2930 signature. + + Parameters + ---------- + tx : + Transaction of interest. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the transaction. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + BinOp.add (| + Constant.bytes "01", + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "chain_id" |); M.get_field (| M.get_name (| globals, "tx" |), "nonce" |); M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |); M.get_field (| M.get_name (| globals, "tx" |), "gas" |); M.get_field (| M.get_name (| globals, "tx" |), "to" |); M.get_field (| M.get_name (| globals, "tx" |), "value" |); M.get_field (| M.get_name (| globals, "tx" |), "data" |); M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) ] + ], + make_dict [] + |) + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition signing_hash_1559 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Compute the hash of a transaction used in a EIP 1559 signature. + + Parameters + ---------- + tx : + Transaction of interest. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the transaction. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + BinOp.add (| + Constant.bytes "02", + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "chain_id" |); M.get_field (| M.get_name (| globals, "tx" |), "nonce" |); M.get_field (| M.get_name (| globals, "tx" |), "max_priority_fee_per_gas" |); M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |); M.get_field (| M.get_name (| globals, "tx" |), "gas" |); M.get_field (| M.get_name (| globals, "tx" |), "to" |); M.get_field (| M.get_name (| globals, "tx" |), "value" |); M.get_field (| M.get_name (| globals, "tx" |), "data" |); M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) ] + ], + make_dict [] + |) + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition compute_header_hash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header" ] |) in + let _ := Constant.str " + Computes the hash of a block header. + + The header hash of a block is the canonical hash that is used to refer + to a specific block and completely distinguishes a block from another. + + ``keccak256`` is a function that produces a 256 bit hash of any input. + It also takes in any number of bytes as an input and produces a single + hash for them. A hash is a completely unique output for a single input. + So an input corresponds to one unique hash that can be used to identify + the input exactly. + + Prior to using the ``keccak256`` hash function, the header must be + encoded using the Recursive-Length Prefix. See :ref:`rlp`. + RLP encoding the header converts it into a space-efficient format that + allows for easy transfer of data between nodes. The purpose of RLP is to + encode arbitrarily nested arrays of binary data, and RLP is the primary + encoding method used to serialize objects in Ethereum's execution layer. + The only purpose of RLP is to encode structure; encoding specific data + types (e.g. strings, floats) is left up to higher-order protocols. + + Parameters + ---------- + header : + Header of interest. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the header. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "header" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition check_gas_limit : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "gas_limit"; "parent_gas_limit" ] |) in + let _ := Constant.str " + Validates the gas limit for a block. + + The bounds of the gas limit, ``max_adjustment_delta``, is set as the + quotient of the parent block's gas limit and the + ``GAS_LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is + passed through as a parameter is greater than or equal to the *sum* of + the parent's gas and the adjustment delta then the limit for gas is too + high and fails this function's check. Similarly, if the limit is less + than or equal to the *difference* of the parent's gas and the adjustment + delta *or* the predefined ``GAS_LIMIT_MINIMUM`` then this function's + check fails because the gas limit doesn't allow for a sufficient or + reasonable amount of gas to be used on a block. + + Parameters + ---------- + gas_limit : + Gas limit to validate. + + parent_gas_limit : + Gas limit of the parent block. + + Returns + ------- + check : `bool` + True if gas limit constraints are satisfied, False otherwise. + " in + let max_adjustment_delta := + BinOp.floor_div (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) + |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + Constant.bool true + M.pure Constant.None_)). + +Definition calculate_block_difficulty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "block_number"; "block_timestamp"; "parent_timestamp"; "parent_difficulty"; "parent_has_ommers" ] |) in + let _ := Constant.str " + Computes difficulty of a block using its header and parent header. + + The difficulty is determined by the time the block was created after its + parent. The ``offset`` is calculated using the parent block's difficulty, + ``parent_difficulty``, and the timestamp between blocks. This offset is + then added to the parent difficulty and is stored as the ``difficulty`` + variable. If the time between the block and its parent is too short, the + offset will result in a positive number thus making the sum of + ``parent_difficulty`` and ``offset`` to be a greater value in order to + avoid mass forking. But, if the time is long enough, then the offset + results in a negative value making the block less difficult than + its parent. + + The base standard for a block's difficulty is the predefined value + set for the genesis block since it has no parent. So, a block + can't be less difficult than the genesis block, therefore each block's + difficulty is set to the maximum value between the calculated + difficulty and the ``GENESIS_DIFFICULTY``. + + Parameters + ---------- + block_number : + Block number of the block. + block_timestamp : + Timestamp of the block. + parent_timestamp : + Timestamp of the parent block. + parent_difficulty : + difficulty of the parent block. + parent_has_ommers: + does the parent have ommers. + + Returns + ------- + difficulty : `ethereum.base_types.Uint` + Computed difficulty for a block. + " in + let offset := + BinOp.mult (| + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "parent_difficulty" |) + ], + make_dict [] + |), + Constant.int 2048 + |), + M.call (| + M.get_name (| globals, "max" |), + make_list [ + BinOp.sub (| + (* if *) +M.if_then_else (| + M.get_name (| globals, "parent_has_ommers" |), +(* then *) +ltac:(M.monadic ( +Constant.int 2, + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "block_timestamp" |), + M.get_name (| globals, "parent_timestamp" |) + |) + ], + make_dict [] + |), + Constant.int 9 + |) + |); + UnOp.sub (| Constant.int 99 |) + ], + make_dict [] + |) + |) in + let difficulty := + BinOp.add (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "parent_difficulty" |) + ], + make_dict [] + |), + M.get_name (| globals, "offset" |) + |) in + let num_bomb_periods := + BinOp.sub (| + BinOp.floor_div (| + BinOp.sub (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "block_number" |) + ], + make_dict [] + |), + M.get_name (| globals, "BOMB_DELAY_BLOCKS" |) + |), + Constant.int 100000 + |), + Constant.int 2 + |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "max" |), + make_list [ + M.get_name (| globals, "difficulty" |); + M.get_name (| globals, "MINIMUM_DIFFICULTY" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/fork_types.v b/CoqOfPython/ethereum/gray_glacier/fork_types.v index d12953d..5c7dac3 100644 --- a/CoqOfPython/ethereum/gray_glacier/fork_types.v +++ b/CoqOfPython/ethereum/gray_glacier/fork_types.v @@ -98,5 +98,4 @@ Definition encode_account : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/state.v b/CoqOfPython/ethereum/gray_glacier/state.v index 7b038e5..c3290a6 100644 --- a/CoqOfPython/ethereum/gray_glacier/state.v +++ b/CoqOfPython/ethereum/gray_glacier/state.v @@ -126,13 +126,7 @@ Definition begin_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) ], make_dict [] - |); {M.get_name (| globals, "k" |): M.call (| - M.get_name (| globals, "copy_trie" |), - make_list [ - M.get_name (| globals, "t" |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)} ] + |); (* At expr: unsupported node type: DictComp *) ] ], make_dict [] |) in @@ -155,19 +149,6 @@ Definition commit_transaction : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "clear" |), - make_list [], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -193,19 +174,6 @@ Definition rollback_transaction : Value.t -> Value.t -> M := |) |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "clear" |), - make_list [], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -242,27 +210,8 @@ Definition get_account : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "account" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "account" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_ACCOUNT" |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -297,7 +246,6 @@ Definition get_account_optional : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "account" |) - |) in M.pure Constant.None_)). Definition set_account : Value.t -> Value.t -> M := @@ -377,15 +325,6 @@ Definition destroy_storage : Value.t -> Value.t -> M := Address of account whose storage is to be deleted. " in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -448,23 +387,6 @@ Definition get_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let value := @@ -486,7 +408,6 @@ Definition get_storage : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "value" |) - |) in M.pure Constant.None_)). Definition set_storage : Value.t -> Value.t -> M := @@ -507,14 +428,17 @@ Definition set_storage : Value.t -> Value.t -> M := value : `U256` Value to set at the key. " in - let _ := M.assert (| Compare.is_not (| M.call (| - M.get_name (| globals, "trie_get" |), - make_list [ - M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), Constant.None_ |) |) in + let _ := M.assert (| Compare.is_not (| + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + Constant.None_ + |) |) in let trie := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), @@ -524,24 +448,6 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let trie := - M.call (| - M.get_name (| globals, "Trie" |), - make_list [], - make_dict [] - |) in - let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), - M.get_name (| globals, "trie" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -554,15 +460,6 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), {} |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -587,26 +484,8 @@ Definition storage_root : Value.t -> Value.t -> M := " in let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "root" |), - make_list [ - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_TRIE_ROOT" |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -637,7 +516,6 @@ Definition state_root : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition account_exists : Value.t -> Value.t -> M := @@ -659,15 +537,17 @@ Definition account_exists : Value.t -> Value.t -> M := True if account exists in the state trie, False otherwise " in let _ := M.return_ (| - Compare.is_not (| M.call (| - M.get_name (| globals, "get_account_optional" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), Constant.None_ |) - |) in + Compare.is_not (| + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + Constant.None_ + |) M.pure Constant.None_)). Definition account_has_code_or_nonce : Value.t -> Value.t -> M := @@ -700,18 +580,23 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := |) in let _ := M.return_ (| BoolOp.or (| - Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( - Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |) + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |) )) |) - |) in M.pure Constant.None_)). Definition is_account_empty : Value.t -> Value.t -> M := @@ -744,23 +629,31 @@ Definition is_account_empty : Value.t -> Value.t -> M := |) in let _ := M.return_ (| BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |), ltac:(M.monadic ( - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "balance" |), + Constant.int 0 + |) )) |) )) |) - |) in M.pure Constant.None_)). Definition account_exists_and_is_empty : Value.t -> Value.t -> M := @@ -794,28 +687,39 @@ Definition account_exists_and_is_empty : Value.t -> Value.t -> M := |) in let _ := M.return_ (| BoolOp.and (| - Compare.is_not (| M.get_name (| globals, "account" |), Constant.None_ |), + Compare.is_not (| + M.get_name (| globals, "account" |), + Constant.None_ + |), ltac:(M.monadic ( BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |), ltac:(M.monadic ( - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "balance" |), + Constant.int 0 + |) )) |) )) |) )) |) - |) in M.pure Constant.None_)). Definition is_account_alive : Value.t -> Value.t -> M := @@ -846,36 +750,33 @@ Definition is_account_alive : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "account" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.bool false - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| UnOp.not (| BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |), ltac:(M.monadic ( - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "balance" |), + Constant.int 0 + |) )) |) )) |) |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -983,30 +884,6 @@ Definition touch_account : Value.t -> Value.t -> M := The address of the account that need to initialised. " in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "account_exists" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "set_account" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |); - M.get_name (| globals, "EMPTY_ACCOUNT" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -1111,23 +988,6 @@ Definition get_storage_original : Value.t -> Value.t -> M := Key of the storage slot. " in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -1143,22 +1003,6 @@ Definition get_storage_original : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "original_account_trie" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let original_value := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let original_value := M.call (| M.get_name (| globals, "trie_get" |), @@ -1180,5 +1024,4 @@ Definition get_storage_original : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "original_value" |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/transactions.v b/CoqOfPython/ethereum/gray_glacier/transactions.v index 56996d9..afa27ec 100644 --- a/CoqOfPython/ethereum/gray_glacier/transactions.v +++ b/CoqOfPython/ethereum/gray_glacier/transactions.v @@ -112,87 +112,15 @@ Definition encode_transaction : Value.t -> Value.t -> M := Encode a transaction. Needed because non-legacy transactions aren't RLP. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "LegacyTransaction" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "tx" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "AccessListTransaction" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - BinOp.add (| - (* At constant: unsupported node type: Constant *), - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "tx" |) - ], - make_dict [] - |) - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "FeeMarketTransaction" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - BinOp.add (| - (* At constant: unsupported node type: Constant *), - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "tx" |) - ], - make_dict [] - |) - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.call (| + let _ := M.raise (| Some(M.call (| M.get_name (| globals, "Exception" |), make_list [ (* At expr: unsupported node type: JoinedStr *) ], make_dict [] - |) |) in + |)) M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -208,67 +136,8 @@ Definition decode_transaction : Value.t -> Value.t -> M := Decode a transaction. Needed because non-legacy transactions aren't RLP. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "Bytes" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), Constant.int 1 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), - make_list [ - M.get_name (| globals, "AccessListTransaction" |); - M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 1:(* At expr: unsupported node type: NoneType *) |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), Constant.int 2 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), - make_list [ - M.get_name (| globals, "FeeMarketTransaction" |); - M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 1:(* At expr: unsupported node type: NoneType *) |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidBlock" |) |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "tx" |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/trie.v b/CoqOfPython/ethereum/gray_glacier/trie.v index 75d7da2..8d425ef 100644 --- a/CoqOfPython/ethereum/gray_glacier/trie.v +++ b/CoqOfPython/ethereum/gray_glacier/trie.v @@ -202,96 +202,16 @@ Definition encode_internal_node : Value.t -> Value.t -> M := " in (* At stmt: unsupported node type: AnnAssign *) let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "node" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let unencoded := - (* At constant: unsupported node type: Constant *) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "LeafNode" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let unencoded := - make_tuple [ M.call (| - M.get_name (| globals, "nibble_list_to_compact" |), - make_list [ - M.get_field (| M.get_name (| globals, "node" |), "rest_of_key" |); - Constant.bool true - ], - make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "ExtensionNode" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let unencoded := - make_tuple [ M.call (| - M.get_name (| globals, "nibble_list_to_compact" |), - make_list [ - M.get_field (| M.get_name (| globals, "node" |), "key_segment" |); - Constant.bool false - ], - make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "BranchNode" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let unencoded := - BinOp.add (| - M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), - make_list [ - M.get_field (| M.get_name (| globals, "node" |), "value" |) - ] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.call (| + let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ (* At expr: unsupported node type: JoinedStr *) ], make_dict [] - |) |) in + |)) M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -309,23 +229,6 @@ Definition encode_internal_node : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "encoded" |) - ], - make_dict [] - |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "unencoded" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_name (| globals, "keccak256" |), @@ -334,7 +237,6 @@ Definition encode_internal_node : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -348,83 +250,8 @@ Definition encode_node : Value.t -> Value.t -> M := Currently mostly an unimplemented stub. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "storage_root" |), Constant.None_ |) |) in - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "encode_account" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "storage_root" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "U256" |) ] - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.call (| - M.get_name (| globals, "cast" |), - make_list [ - M.get_field (| M.get_name (| globals, "rlp" |), "RLP" |); - M.get_name (| globals, "node" |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "Bytes" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "node" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "previous_trie" |), "encode_node" |), @@ -434,7 +261,6 @@ Definition encode_node : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -486,7 +312,6 @@ Definition copy_trie : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition trie_set : Value.t -> Value.t -> M := @@ -508,26 +333,6 @@ Definition trie_set : Value.t -> Value.t -> M := Node to insert at `key`. " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "value" |), M.get_field (| M.get_name (| globals, "trie" |), "default" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "key" |), M.get_field (| M.get_name (| globals, "trie" |), "_data" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), M.get_name (| globals, "value" |) @@ -565,7 +370,6 @@ Definition trie_get : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition common_prefix_length : Value.t -> Value.t -> M := @@ -588,28 +392,6 @@ Definition common_prefix_length : Value.t -> Value.t -> M := make_dict [] |) do let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| M.get_name (| globals, "i" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "b" |) - ], - make_dict [] - |) |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "i" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -621,7 +403,6 @@ Definition common_prefix_length : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition nibble_list_to_compact : Value.t -> Value.t -> M := @@ -667,68 +448,6 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| BinOp.mod_ (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |), - Constant.int 2 - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_name (| globals, "compact" |), "append" |), - make_list [ - BinOp.mult (| - Constant.int 16, - BinOp.mult (| - Constant.int 2, - M.get_name (| globals, "is_leaf" |) - |) - |) - ], - make_dict [] - |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 0; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |); - Constant.int 2 - ], - make_dict [] - |) do - let _ := M.call (| - M.get_field (| M.get_name (| globals, "compact" |), "append" |), - make_list [ - BinOp.add (| - BinOp.mult (| - Constant.int 16, - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) - |), - M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) - |) - ], - make_dict [] - |) in - EndFor. - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ @@ -790,7 +509,6 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition bytes_to_nibble_list : Value.t -> Value.t -> M := @@ -868,7 +586,6 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition _prepare_trie : Value.t -> Value.t -> M := @@ -898,45 +615,6 @@ Definition _prepare_trie : Value.t -> Value.t -> M := make_dict [] |) do let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "value" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in - let address := - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in - let encoded_value := - M.call (| - M.get_name (| globals, "encode_node" |), - make_list [ - M.get_name (| globals, "value" |); - M.call (| - M.get_name (| globals, "get_storage_root" |), - make_list [ - M.get_name (| globals, "address" |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let encoded_value := M.call (| M.get_name (| globals, "encode_node" |), @@ -950,29 +628,16 @@ Definition _prepare_trie : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.not_eq (| M.get_name (| globals, "encoded_value" |), (* At constant: unsupported node type: Constant *) |); + Compare.not_eq (| + M.get_name (| globals, "encoded_value" |), + Constant.bytes "" + |); M.get_name (| globals, "AssertionError" |) ], make_dict [] |) in (* At stmt: unsupported node type: AnnAssign *) let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "trie" |), "secured" |), - (* then *) - ltac:(M.monadic ( - let key := - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let key := M.get_name (| globals, "preimage" |) in M.pure Constant.None_ @@ -990,7 +655,6 @@ Definition _prepare_trie : Value.t -> Value.t -> M := EndFor. let _ := M.return_ (| M.get_name (| globals, "mapped" |) - |) in M.pure Constant.None_)). Definition root : Value.t -> Value.t -> M := @@ -1044,41 +708,6 @@ Definition root : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "root_node" |) - ], - make_dict [] - |) - ], - make_dict [] - |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "root_node" |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -1095,7 +724,6 @@ Definition root : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -1122,23 +750,6 @@ Definition patricialize : Value.t -> Value.t -> M := Root node of `obj`. " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "obj" |) - ], - make_dict [] - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.None_ - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let arbitrary_key := @@ -1156,36 +767,10 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "obj" |) - ], - make_dict [] - |), Constant.int 1 |), - (* then *) - ltac:(M.monadic ( - let leaf := - M.call (| - M.get_name (| globals, "LeafNode" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |); - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) - ], - make_dict [] - |) in - let _ := M.return_ (| - M.get_name (| globals, "leaf" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let substring := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |) |) in let prefix_length := M.call (| M.get_name (| globals, "len" |), @@ -1204,7 +789,7 @@ Definition patricialize : Value.t -> Value.t -> M := M.get_name (| globals, "common_prefix_length" |), make_list [ M.get_name (| globals, "substring" |); - M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) + M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) ], make_dict [] |) @@ -1212,58 +797,10 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.break (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let prefix := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):BinOp.add (| - M.get_name (| globals, "level" |), - M.get_name (| globals, "prefix_length" |) - |) |) in - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "ExtensionNode" |), - make_list [ - M.get_name (| globals, "prefix" |); - M.call (| - M.get_name (| globals, "encode_internal_node" |), - make_list [ - M.call (| - M.get_name (| globals, "patricialize" |), - make_list [ - M.get_name (| globals, "obj" |); - BinOp.add (| - M.get_name (| globals, "level" |), - M.get_name (| globals, "prefix_length" |) - |) - ], - make_dict [] - |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) @@ -1283,44 +820,9 @@ Definition patricialize : Value.t -> Value.t -> M := |) in EndFor. let value := - (* At constant: unsupported node type: Constant *) in + Constant.bytes "" in For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "key" |) - ], - make_dict [] - |), M.get_name (| globals, "level" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); - make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "AssertionError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let value := - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) @@ -1332,26 +834,9 @@ Definition patricialize : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "BranchNode" |), make_list [ - [M.call (| - M.get_name (| globals, "encode_internal_node" |), - make_list [ - M.call (| - M.get_name (| globals, "patricialize" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "branches" |), M.get_name (| globals, "k" |) |); - BinOp.add (| - M.get_name (| globals, "level" |), - Constant.int 1 - |) - ], - make_dict [] - |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)]; + (* At expr: unsupported node type: ListComp *); M.get_name (| globals, "value" |) ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/utils/address.v b/CoqOfPython/ethereum/gray_glacier/utils/address.v index 60e2f15..25c52c0 100644 --- a/CoqOfPython/ethereum/gray_glacier/utils/address.v +++ b/CoqOfPython/ethereum/gray_glacier/utils/address.v @@ -70,11 +70,10 @@ Definition to_address : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), make_list [], make_dict [] - |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) + |), UnOp.sub (| Constant.int 20 |) |) ], make_dict [] |) - |) in M.pure Constant.None_)). Definition compute_contract_address : Value.t -> Value.t -> M := @@ -114,7 +113,7 @@ Definition compute_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -132,7 +131,6 @@ Definition compute_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition compute_create2_contract_address : Value.t -> Value.t -> M := @@ -160,7 +158,7 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := BinOp.add (| BinOp.add (| BinOp.add (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "ff", M.get_name (| globals, "address" |) |), M.get_name (| globals, "salt" |) @@ -182,7 +180,7 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -200,5 +198,4 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/utils/hexadecimal.v b/CoqOfPython/ethereum/gray_glacier/utils/hexadecimal.v index 3d948f3..8b66a3a 100644 --- a/CoqOfPython/ethereum/gray_glacier/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/gray_glacier/utils/hexadecimal.v @@ -66,7 +66,6 @@ Definition hex_to_root : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition hex_to_bloom : Value.t -> Value.t -> M := @@ -105,7 +104,6 @@ Definition hex_to_bloom : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition hex_to_address : Value.t -> Value.t -> M := @@ -151,5 +149,4 @@ Definition hex_to_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/utils/message.v b/CoqOfPython/ethereum/gray_glacier/utils/message.v index 148c61e..dead284 100644 --- a/CoqOfPython/ethereum/gray_glacier/utils/message.v +++ b/CoqOfPython/ethereum/gray_glacier/utils/message.v @@ -103,105 +103,14 @@ Definition prepare_message : Value.t -> Value.t -> M := Items containing contract creation or message call specific data. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "target" |); - M.get_name (| globals, "Bytes0" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let current_target := - M.call (| - M.get_name (| globals, "compute_contract_address" |), - make_list [ - M.get_name (| globals, "caller" |); - BinOp.sub (| - M.get_field (| M.call (| - M.get_name (| globals, "get_account" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "caller" |) - ], - make_dict [] - |), "nonce" |), - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 1 - ], - make_dict [] - |) - |) - ], - make_dict [] - |) in - let msg_data := - M.call (| - M.get_name (| globals, "Bytes" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |) in - let code := - M.get_name (| globals, "data" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "target" |); - M.get_name (| globals, "Address" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let current_target := - M.get_name (| globals, "target" |) in - let msg_data := - M.get_name (| globals, "data" |) in - let code := - M.get_field (| M.call (| - M.get_name (| globals, "get_account" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "target" |) - ], - make_dict [] - |), "code" |) in - let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "code_address" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let code_address := - M.get_name (| globals, "target" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.call (| + let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "Target must be address or empty bytes" ], make_dict [] - |) |) in + |)) M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -250,5 +159,4 @@ Definition prepare_message : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/vm/__init__.v b/CoqOfPython/ethereum/gray_glacier/vm/__init__.v index 2ff63cd..49da5ae 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/__init__.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/__init__.v @@ -147,28 +147,6 @@ Definition incorporate_child_on_success : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); - M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -201,57 +179,9 @@ Definition incorporate_child_on_error : Value.t -> Value.t -> M := The child evm to incorporate. " in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "RIPEMD160_ADDRESS" |), M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), - make_list [ - M.get_name (| globals, "RIPEMD160_ADDRESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |), M.get_name (| globals, "RIPEMD160_ADDRESS" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); - M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), - make_list [ - M.get_name (| globals, "RIPEMD160_ADDRESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign_op (| diff --git a/CoqOfPython/ethereum/gray_glacier/vm/gas.v b/CoqOfPython/ethereum/gray_glacier/vm/gas.v new file mode 100644 index 0000000..549060b --- /dev/null +++ b/CoqOfPython/ethereum/gray_glacier/vm/gas.v @@ -0,0 +1,811 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Gas +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +EVM gas constants and calculators. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.trace. +Axiom ethereum_trace_GasAndRefund : + IsGlobalAlias globals ethereum.trace.globals "GasAndRefund". +Axiom ethereum_trace_evm_trace : + IsGlobalAlias globals ethereum.trace.globals "evm_trace". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". + +Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) +)). + +Definition GAS_BASE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 2 + ], + make_dict [] + |) +)). + +Definition GAS_VERY_LOW : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_STORAGE_SET : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 20000 + ], + make_dict [] + |) +)). + +Definition GAS_STORAGE_UPDATE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5000 + ], + make_dict [] + |) +)). + +Definition GAS_STORAGE_CLEAR_REFUND : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 4800 + ], + make_dict [] + |) +)). + +Definition GAS_LOW : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5 + ], + make_dict [] + |) +)). + +Definition GAS_MID : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 8 + ], + make_dict [] + |) +)). + +Definition GAS_HIGH : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 10 + ], + make_dict [] + |) +)). + +Definition GAS_EXPONENTIATION : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 10 + ], + make_dict [] + |) +)). + +Definition GAS_EXPONENTIATION_PER_BYTE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 50 + ], + make_dict [] + |) +)). + +Definition GAS_MEMORY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_KECCAK256 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 30 + ], + make_dict [] + |) +)). + +Definition GAS_KECCAK256_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 6 + ], + make_dict [] + |) +)). + +Definition GAS_COPY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_BLOCK_HASH : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 20 + ], + make_dict [] + |) +)). + +Definition GAS_LOG : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 375 + ], + make_dict [] + |) +)). + +Definition GAS_LOG_DATA : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 8 + ], + make_dict [] + |) +)). + +Definition GAS_LOG_TOPIC : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 375 + ], + make_dict [] + |) +)). + +Definition GAS_CREATE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 32000 + ], + make_dict [] + |) +)). + +Definition GAS_CODE_DEPOSIT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 200 + ], + make_dict [] + |) +)). + +Definition GAS_ZERO : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) +)). + +Definition GAS_NEW_ACCOUNT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 25000 + ], + make_dict [] + |) +)). + +Definition GAS_CALL_VALUE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 9000 + ], + make_dict [] + |) +)). + +Definition GAS_CALL_STIPEND : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 2300 + ], + make_dict [] + |) +)). + +Definition GAS_SELF_DESTRUCT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5000 + ], + make_dict [] + |) +)). + +Definition GAS_SELF_DESTRUCT_NEW_ACCOUNT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 25000 + ], + make_dict [] + |) +)). + +Definition GAS_ECRECOVER : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3000 + ], + make_dict [] + |) +)). + +Definition GAS_SHA256 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 60 + ], + make_dict [] + |) +)). + +Definition GAS_SHA256_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 12 + ], + make_dict [] + |) +)). + +Definition GAS_RIPEMD160 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 600 + ], + make_dict [] + |) +)). + +Definition GAS_RIPEMD160_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 120 + ], + make_dict [] + |) +)). + +Definition GAS_IDENTITY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 15 + ], + make_dict [] + |) +)). + +Definition GAS_IDENTITY_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_RETURN_DATA_COPY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_FAST_STEP : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5 + ], + make_dict [] + |) +)). + +Definition GAS_BLAKE2_PER_ROUND : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) +)). + +Definition GAS_COLD_SLOAD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 2100 + ], + make_dict [] + |) +)). + +Definition GAS_COLD_ACCOUNT_ACCESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 2600 + ], + make_dict [] + |) +)). + +Definition GAS_WARM_ACCESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 100 + ], + make_dict [] + |) +)). + +Definition ExtendMemory : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition MessageCallGas : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition charge_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "amount" ] |) in + let _ := Constant.str " + Subtracts `amount` from `evm.gas_left`. + + Parameters + ---------- + evm : + The current EVM. + amount : + The amount of gas the current operation requires. + + " in + let _ := M.call (| + M.get_name (| globals, "evm_trace" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "GasAndRefund" |), + make_list [ + M.get_name (| globals, "amount" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + let _ := M.assign_op (| + BinOp.sub, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "amount" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition calculate_memory_gas_cost : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "size_in_bytes" ] |) in + let _ := Constant.str " + Calculates the gas cost for allocating memory + to the smallest multiple of 32 bytes, + such that the allocated size is at least as big as the given size. + + Parameters + ---------- + size_in_bytes : + The size of the data in bytes. + + Returns + ------- + total_gas_cost : `ethereum.base_types.Uint` + The gas cost for storing data in memory. + " in + let size_in_words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "size_in_bytes" |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let linear_cost := + BinOp.mult (| + M.get_name (| globals, "size_in_words" |), + M.get_name (| globals, "GAS_MEMORY" |) + |) in + let quadratic_cost := + BinOp.floor_div (| + BinOp.pow (| + M.get_name (| globals, "size_in_words" |), + Constant.int 2 + |), + Constant.int 512 + |) in + let total_gas_cost := + BinOp.add (| + M.get_name (| globals, "linear_cost" |), + M.get_name (| globals, "quadratic_cost" |) + |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_)). + +Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "memory"; "extensions" ] |) in + let _ := Constant.str " + Calculates the gas amount to extend memory + + Parameters + ---------- + memory : + Memory contents of the EVM. + extensions: + List of extensions to be made to the memory. + Consists of a tuple of start position and size. + + Returns + ------- + extend_memory: `ExtendMemory` + " in + let size_to_extend := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let to_be_paid := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let current_size := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "memory" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + For make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ] in M.get_name (| globals, "extensions" |) do + let _ := + M.pure Constant.None_ + )) |) in + let before_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "current_size" |) + ], + make_dict [] + |) in + let after_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let size_to_extend := BinOp.add + BinOp.sub (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |) + BinOp.sub (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |) in + let already_paid := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "before_size" |) + ], + make_dict [] + |) in + let total_cost := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "after_size" |) + ], + make_dict [] + |) in + let to_be_paid := BinOp.add + BinOp.sub (| + M.get_name (| globals, "total_cost" |), + M.get_name (| globals, "already_paid" |) + |) + BinOp.sub (| + M.get_name (| globals, "total_cost" |), + M.get_name (| globals, "already_paid" |) + |) in + let current_size := + M.get_name (| globals, "after_size" |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ExtendMemory" |), + make_list [ + M.get_name (| globals, "to_be_paid" |); + M.get_name (| globals, "size_to_extend" |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition calculate_message_call_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "value"; "gas"; "gas_left"; "memory_cost"; "extra_gas"; "call_stipend" ] |) in + let _ := Constant.str " + Calculates the MessageCallGas (cost and stipend) for + executing call Opcodes. + + Parameters + ---------- + value: + The amount of `ETH` that needs to be transferred. + gas : + The amount of gas provided to the message-call. + gas_left : + The amount of gas left in the current frame. + memory_cost : + The amount needed to extend the memory in the current frame. + extra_gas : + The amount of gas needed for transferring value + creating a new + account inside a message call. + call_stipend : + The amount of stipend provided to a message call to execute code while + transferring value(ETH). + + Returns + ------- + message_call_gas: `MessageCallGas` + " in + let call_stipend := + (* if *) +M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let gas := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "max_message_call_gas" |), + make_list [ + BinOp.sub (| + BinOp.sub (| + M.get_name (| globals, "gas_left" |), + M.get_name (| globals, "memory_cost" |) + |), + M.get_name (| globals, "extra_gas" |) + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallGas" |), + make_list [ + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "extra_gas" |) + |); + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "call_stipend" |) + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition max_message_call_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "gas" ] |) in + let _ := Constant.str " + Calculates the maximum gas that is allowed for making a message call + + Parameters + ---------- + gas : + The amount of gas provided to the message-call. + + Returns + ------- + max_allowed_message_call_gas: `ethereum.base_types.Uint` + The maximum gas allowed for making the message-call. + " in + let _ := M.return_ (| + BinOp.sub (| + M.get_name (| globals, "gas" |), + BinOp.floor_div (| + M.get_name (| globals, "gas" |), + Constant.int 64 + |) + |) + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/arithmetic.v index a8b5c61..581ba5d 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/arithmetic.v @@ -273,22 +273,6 @@ Definition div : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let quotient := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let quotient := BinOp.floor_div (| M.get_name (| globals, "dividend" |), @@ -357,32 +341,7 @@ Definition sdiv : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let quotient := - Constant.int 0 in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_name (| globals, "dividend" |), UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "divisor" |), UnOp.sub (| Constant.int 1 |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let quotient := - UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let sign := M.call (| M.get_name (| globals, "get_sign" |), @@ -477,22 +436,6 @@ Definition mod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let remainder := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let remainder := BinOp.mod_ (| M.get_name (| globals, "x" |), @@ -561,16 +504,6 @@ Definition smod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let remainder := - Constant.int 0 in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let remainder := BinOp.mult (| M.call (| @@ -684,22 +617,6 @@ Definition addmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -795,22 +712,6 @@ Definition mulmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -980,16 +881,6 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "byte_num" |), Constant.int 31 |), - (* then *) - ltac:(M.monadic ( - let result := - M.get_name (| globals, "value" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let value_bytes := M.call (| M.get_name (| globals, "bytes" |), @@ -1012,29 +903,13 @@ Definition signextend : Value.t -> Value.t -> M := ], make_dict [] |) - |):(* At expr: unsupported node type: NoneType *) |) in + |) |) in let sign_bit := BinOp.r_shift (| M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), Constant.int 7 |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "sign_bit" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), - make_list [ - M.get_name (| globals, "value_bytes" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let num_bytes_prepend := BinOp.sub (| Constant.int 32, diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/bitwise.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/bitwise.v index 9f2f382..64cf120 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/bitwise.v @@ -287,22 +287,6 @@ Definition get_byte : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "byte_index" |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let extra_bytes_to_right := BinOp.sub (| Constant.int 31, @@ -382,28 +366,6 @@ Definition bitwise_shl : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - BinOp.mod_ (| - BinOp.l_shift (| - M.get_name (| globals, "value" |), - M.get_name (| globals, "shift" |) - |), - M.get_name (| globals, "U256_CEIL_VALUE" |) - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -465,19 +427,6 @@ Definition bitwise_shr : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), - (* then *) - ltac:(M.monadic ( - let result := - BinOp.r_shift (| - M.get_name (| globals, "value" |), - M.get_name (| globals, "shift" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -543,42 +492,7 @@ Definition bitwise_sar : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), - make_list [ - BinOp.r_shift (| - M.get_name (| globals, "signed_value" |), - M.get_name (| globals, "shift" |) - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "signed_value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/block.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/block.v index 26c73a7..f857b79 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/block.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/block.v @@ -69,24 +69,6 @@ Definition block_hash : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.lt_e (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), M.get_name (| globals, "block_number" |) |), - ltac:(M.monadic ( - Compare.gt (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), BinOp.add (| - M.get_name (| globals, "block_number" |), - Constant.int 256 - |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let hash := - (* At constant: unsupported node type: Constant *) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let hash := M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/comparison.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/comparison.v index fbc35f8..b8529d8 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/comparison.v @@ -78,7 +78,10 @@ Definition less_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.lt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -145,7 +148,10 @@ Definition signed_less_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.lt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -205,7 +211,10 @@ Definition greater_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.gt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -272,7 +281,10 @@ Definition signed_greater_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.gt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -332,7 +344,10 @@ Definition equal : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.eq (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.eq (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -384,7 +399,10 @@ Definition is_zero : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.eq (| M.get_name (| globals, "x" |), Constant.int 0 |) + Compare.eq (| + M.get_name (| globals, "x" |), + Constant.int 0 + |) ], make_dict [] |) in diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/control_flow.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/control_flow.v index 04a79d9..d4e4eae 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/control_flow.v @@ -109,15 +109,6 @@ Definition jump : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -177,29 +168,7 @@ Definition jumpi : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "conditional_value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let destination := - BinOp.add (| - M.get_field (| M.get_name (| globals, "evm" |), "pc" |), - Constant.int 1 - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let destination := M.get_name (| globals, "jump_dest" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/environment.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/environment.v index 530304e..10bc05b 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/environment.v @@ -156,22 +156,6 @@ Definition balance : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "charge_gas" |), - make_list [ - M.get_name (| globals, "evm" |); - M.get_name (| globals, "GAS_WARM_ACCESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -538,7 +522,7 @@ Definition calldatacopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -706,7 +690,7 @@ Definition codecopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -805,22 +789,6 @@ Definition extcodesize : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "charge_gas" |), - make_list [ - M.get_name (| globals, "evm" |); - M.get_name (| globals, "GAS_WARM_ACCESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -958,28 +926,6 @@ Definition extcodecopy : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "charge_gas" |), - make_list [ - M.get_name (| globals, "evm" |); - BinOp.add (| - BinOp.add (| - M.get_name (| globals, "GAS_WARM_ACCESS" |), - M.get_name (| globals, "copy_gas_cost" |) - |), - M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1007,7 +953,7 @@ Definition extcodecopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -1178,28 +1124,31 @@ Definition returndatacopy : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt_e (| BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "return_data_start_position" |) - ], - make_dict [] + Compare.lt_e (| + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "return_data_start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) |), M.call (| - M.get_name (| globals, "Uint" |), + M.get_name (| globals, "len" |), make_list [ - M.get_name (| globals, "size" |) + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |) ], make_dict [] |) - |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "return_data" |) - ], - make_dict [] - |) |); + |); M.get_name (| globals, "OutOfBoundsRead" |) ], make_dict [] @@ -1208,15 +1157,12 @@ Definition returndatacopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in let value := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |):BinOp.add (| - M.get_name (| globals, "return_data_start_position" |), - M.get_name (| globals, "size" |) - |) |) in + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |) |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -1258,22 +1204,6 @@ Definition extcodehash : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "charge_gas" |), - make_list [ - M.get_name (| globals, "evm" |); - M.get_name (| globals, "GAS_WARM_ACCESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1301,22 +1231,6 @@ Definition extcodehash : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "account" |), M.get_name (| globals, "EMPTY_ACCOUNT" |) |), - (* then *) - ltac:(M.monadic ( - let codehash := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let codehash := M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/keccak.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/keccak.v index cab9ffb..2c4b10e 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/keccak.v @@ -137,7 +137,7 @@ Definition keccak : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/log.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/log.v index 4891a4d..e084e59 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/log.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/log.v @@ -161,7 +161,7 @@ Definition log_n : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/memory.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/memory.v index 1e1c8b0..86ba742 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/memory.v @@ -121,7 +121,7 @@ Definition mstore : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -203,7 +203,7 @@ Definition mstore8 : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -288,7 +288,7 @@ Definition mload : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/stack.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/stack.v index 1eeda05..305af15 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/stack.v @@ -188,13 +188,16 @@ Definition dup_n : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] - |) |); + Compare.lt (| + M.get_name (| globals, "item_number" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + |); M.get_name (| globals, "StackUnderflowError" |) ], make_dict [] @@ -260,13 +263,16 @@ Definition swap_n : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] - |) |); + Compare.lt (| + M.get_name (| globals, "item_number" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + |); M.get_name (| globals, "StackUnderflowError" |) ], make_dict [] diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/storage.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/storage.v index 2f0a831..b3c4045 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/storage.v @@ -91,22 +91,6 @@ Definition sload : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "charge_gas" |), - make_list [ - M.get_name (| globals, "evm" |); - M.get_name (| globals, "GAS_WARM_ACCESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "add" |), make_list [ @@ -184,7 +168,10 @@ Definition sstore : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.gt (| M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), M.get_name (| globals, "GAS_CALL_STIPEND" |) |); + Compare.gt (| + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "GAS_CALL_STIPEND" |) + |); M.get_name (| globals, "OutOfGasError" |) ], make_dict [] @@ -218,189 +205,15 @@ Definition sstore : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_in (| make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "add" |), - make_list [ - make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ] - ], - make_dict [] - |) in - let gas_cost := BinOp.add - M.get_name (| globals, "GAS_COLD_SLOAD" |) - M.get_name (| globals, "GAS_COLD_SLOAD" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_name (| globals, "original_value" |), M.get_name (| globals, "current_value" |) |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_name (| globals, "current_value" |), M.get_name (| globals, "new_value" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let gas_cost := BinOp.add - M.get_name (| globals, "GAS_STORAGE_SET" |) - M.get_name (| globals, "GAS_STORAGE_SET" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let gas_cost := BinOp.add - BinOp.sub (| - M.get_name (| globals, "GAS_STORAGE_UPDATE" |), - M.get_name (| globals, "GAS_COLD_SLOAD" |) - |) - BinOp.sub (| - M.get_name (| globals, "GAS_STORAGE_UPDATE" |), - M.get_name (| globals, "GAS_COLD_SLOAD" |) - |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let gas_cost := BinOp.add M.get_name (| globals, "GAS_WARM_ACCESS" |) M.get_name (| globals, "GAS_WARM_ACCESS" |) in M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_eq (| M.get_name (| globals, "current_value" |), M.get_name (| globals, "new_value" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), - ltac:(M.monadic ( - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "new_value" |), Constant.int 0 |) - )) - |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), - M.call (| - M.get_name (| globals, "int" |), - make_list [ - M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.sub, - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), - M.call (| - M.get_name (| globals, "int" |), - make_list [ - M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "original_value" |), M.get_name (| globals, "new_value" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), - M.call (| - M.get_name (| globals, "int" |), - make_list [ - BinOp.sub (| - M.get_name (| globals, "GAS_STORAGE_SET" |), - M.get_name (| globals, "GAS_WARM_ACCESS" |) - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), - M.call (| - M.get_name (| globals, "int" |), - make_list [ - BinOp.sub (| - BinOp.sub (| - M.get_name (| globals, "GAS_STORAGE_UPDATE" |), - M.get_name (| globals, "GAS_COLD_SLOAD" |) - |), - M.get_name (| globals, "GAS_WARM_ACCESS" |) - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/system.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/system.v new file mode 100644 index 0000000..03931b2 --- /dev/null +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/system.v @@ -0,0 +1,1635 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) System Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM system related instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_account_exists_and_is_empty : + IsGlobalAlias globals state.globals "account_exists_and_is_empty". +Axiom state_account_has_code_or_nonce : + IsGlobalAlias globals state.globals "account_has_code_or_nonce". +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". +Axiom state_increment_nonce : + IsGlobalAlias globals state.globals "increment_nonce". +Axiom state_is_account_alive : + IsGlobalAlias globals state.globals "is_account_alive". +Axiom state_set_account_balance : + IsGlobalAlias globals state.globals "set_account_balance". + +Require utils.address. +Axiom utils_address_compute_contract_address : + IsGlobalAlias globals utils.address.globals "compute_contract_address". +Axiom utils_address_compute_create2_contract_address : + IsGlobalAlias globals utils.address.globals "compute_create2_contract_address". +Axiom utils_address_to_address : + IsGlobalAlias globals utils.address.globals "to_address". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". +Axiom __init___Message : + IsGlobalAlias globals __init__.globals "Message". +Axiom __init___incorporate_child_on_error : + IsGlobalAlias globals __init__.globals "incorporate_child_on_error". +Axiom __init___incorporate_child_on_success : + IsGlobalAlias globals __init__.globals "incorporate_child_on_success". + +Require exceptions. +Axiom exceptions_Revert : + IsGlobalAlias globals exceptions.globals "Revert". +Axiom exceptions_WriteInStaticContext : + IsGlobalAlias globals exceptions.globals "WriteInStaticContext". + +Require gas. +Axiom gas_GAS_CALL_VALUE : + IsGlobalAlias globals gas.globals "GAS_CALL_VALUE". +Axiom gas_GAS_COLD_ACCOUNT_ACCESS : + IsGlobalAlias globals gas.globals "GAS_COLD_ACCOUNT_ACCESS". +Axiom gas_GAS_CREATE : + IsGlobalAlias globals gas.globals "GAS_CREATE". +Axiom gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". +Axiom gas_GAS_NEW_ACCOUNT : + IsGlobalAlias globals gas.globals "GAS_NEW_ACCOUNT". +Axiom gas_GAS_SELF_DESTRUCT : + IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT". +Axiom gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : + IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". +Axiom gas_GAS_WARM_ACCESS : + IsGlobalAlias globals gas.globals "GAS_WARM_ACCESS". +Axiom gas_GAS_ZERO : + IsGlobalAlias globals gas.globals "GAS_ZERO". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_calculate_message_call_gas : + IsGlobalAlias globals gas.globals "calculate_message_call_gas". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". +Axiom gas_max_message_call_gas : + IsGlobalAlias globals gas.globals "max_message_call_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". +Axiom memory_memory_write : + IsGlobalAlias globals memory.globals "memory_write". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition generic_create : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "endowment"; "contract_address"; "memory_start_position"; "memory_size" ] |) in + let _ := Constant.str " + Core logic used by the `CREATE*` family of opcodes. + " in +(* At stmt: unsupported node type: ImportFrom *) + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "contract_address" |) + ], + make_dict [] + |) in + let create_message_gas := + M.call (| + M.get_name (| globals, "max_message_call_gas" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.sub, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "create_message_gas" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let sender_address := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in + let sender := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "sender_address" |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := + M.pure Constant.None_ + )) |) in + let call_data := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + let child_message := + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) in + let child_evm := + M.call (| + M.get_name (| globals, "process_create_message" |), + make_list [ + M.get_name (| globals, "child_message" |); + M.get_field (| M.get_name (| globals, "evm" |), "env" |) + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_success" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition create : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Creates a new account with associated code. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let endowment := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_position" |); M.get_name (| globals, "memory_size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_CREATE" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let contract_address := + M.call (| + M.get_name (| globals, "compute_contract_address" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "nonce" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "generic_create" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "endowment" |); + M.get_name (| globals, "contract_address" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition create2 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Creates a new account with associated code. + + It's similar to CREATE opcode except that the address of new account + depends on the init_code instead of the nonce of sender. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let endowment := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let salt := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_position" |); M.get_name (| globals, "memory_size" |) ] + ] + ], + make_dict [] + |) in + let call_data_words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_CREATE" |), + BinOp.mult (| + M.get_name (| globals, "GAS_KECCAK256_WORD" |), + M.get_name (| globals, "call_data_words" |) + |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let contract_address := + M.call (| + M.get_name (| globals, "compute_create2_contract_address" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "salt" |); + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "generic_create" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "endowment" |); + M.get_name (| globals, "contract_address" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition return_ : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Halts execution returning output data. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let memory_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_position" |); M.get_name (| globals, "memory_size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_ZERO" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "running" |), + Constant.bool false + |) in + let _ := M.pass (| |) in + M.pure Constant.None_)). + +Definition generic_call : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "gas"; "value"; "caller"; "to"; "code_address"; "should_transfer_value"; "is_staticcall"; "memory_input_start_position"; "memory_input_size"; "memory_output_start_position"; "memory_output_size" ] |) in + let _ := Constant.str " + Perform the core logic of the `CALL*` family of opcodes. + " in +(* At stmt: unsupported node type: ImportFrom *) + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let _ := + M.pure Constant.None_ + )) |) in + let call_data := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |) + ], + make_dict [] + |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "code_address" |) + ], + make_dict [] + |), "code" |) in + let child_message := + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) in + let child_evm := + M.call (| + M.get_name (| globals, "process_message" |), + make_list [ + M.get_name (| globals, "child_message" |); + M.get_field (| M.get_name (| globals, "evm" |), "env" |) + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_success" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let actual_output_size := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_name (| globals, "memory_output_size" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), Constant.None_:M.get_name (| globals, "actual_output_size" |) |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition call : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into an account. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let to := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "to" |) + ], + make_dict [] + |) in + let access_gas_cost := + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + M.pure Constant.None_ + )) |) in + let create_gas_cost := + (* if *) +M.if_then_else (| + BoolOp.or (| + M.call (| + M.get_name (| globals, "is_account_alive" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "to" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |) + )) + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let transfer_gas_cost := + (* if *) +M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "access_gas_cost" |), + M.get_name (| globals, "create_gas_cost" |) + |), + M.get_name (| globals, "transfer_gas_cost" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.or (| + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "value" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) + )) + |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let sender_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.get_name (| globals, "value" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "to" |); + Constant.bool true; + Constant.bool false; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition callcode : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into this account with alternative account’s code. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let code_address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let to := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "code_address" |) + ], + make_dict [] + |) in + let access_gas_cost := + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + M.pure Constant.None_ + )) |) in + let transfer_gas_cost := + (* if *) +M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + BinOp.add (| + M.get_name (| globals, "access_gas_cost" |), + M.get_name (| globals, "transfer_gas_cost" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let sender_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.get_name (| globals, "value" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "code_address" |); + Constant.bool true; + Constant.bool false; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition selfdestruct : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Halt execution and register account for later deletion. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let beneficiary := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let gas_cost := + M.get_name (| globals, "GAS_SELF_DESTRUCT" |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "gas_cost" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let originator := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in + let beneficiary_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |), "balance" |) in + let originator_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "originator" |) + ], + make_dict [] + |), "balance" |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |); + BinOp.add (| + M.get_name (| globals, "beneficiary_balance" |), + M.get_name (| globals, "originator_balance" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "originator" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |), "add" |), + make_list [ + M.get_name (| globals, "originator" |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "running" |), + Constant.bool false + |) in + let _ := M.pass (| |) in + M.pure Constant.None_)). + +Definition delegatecall : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into an account. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let code_address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "code_address" |) + ], + make_dict [] + |) in + let access_gas_cost := + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + M.pure Constant.None_ + )) |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + M.get_name (| globals, "access_gas_cost" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "value" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "caller" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "code_address" |); + Constant.bool false; + Constant.bool false; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition staticcall : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into an account. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let to := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "to" |) + ], + make_dict [] + |) in + let access_gas_cost := + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + M.pure Constant.None_ + )) |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + M.get_name (| globals, "access_gas_cost" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "to" |); + Constant.bool true; + Constant.bool true; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition revert : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stop execution and revert state changes, without consuming all provided gas + and also has the ability to return a reason + Parameters + ---------- + evm : + The current EVM frame. + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let output := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "bytes" |), + make_list [ + M.get_name (| globals, "output" |) + ], + make_dict [] + |) + |) in + let _ := M.raise (| Some(M.get_name (| globals, "Revert" |)) + let _ := M.pass (| |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/vm/interpreter.v b/CoqOfPython/ethereum/gray_glacier/vm/interpreter.v index 8179355..024d2d5 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/interpreter.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/interpreter.v @@ -184,91 +184,6 @@ Definition process_message_call : Value.t -> Value.t -> M := Output of the message call " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_name (| globals, "message" |), "target" |), M.call (| - M.get_name (| globals, "Bytes0" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let is_collision := - M.call (| - M.get_name (| globals, "account_has_code_or_nonce" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_field (| M.get_name (| globals, "message" |), "current_target" |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - M.get_name (| globals, "is_collision" |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "MessageCallOutput" |), - make_list [ - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |); - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |); - M.call (| - M.get_name (| globals, "tuple" |), - make_list [], - make_dict [] - |); - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |); - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |); - M.call (| - M.get_name (| globals, "AddressCollision" |), - make_list [], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let evm := - M.call (| - M.get_name (| globals, "process_create_message" |), - make_list [ - M.get_name (| globals, "message" |); - M.get_name (| globals, "env" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let evm := M.call (| M.get_name (| globals, "process_message" |), @@ -279,74 +194,11 @@ Definition process_message_call : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_field (| M.get_name (| globals, "message" |), "target" |) - ], - make_dict [] - |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), - make_list [ - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_field (| M.get_name (| globals, "message" |), "target" |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "evm" |), "error" |), - (* then *) - ltac:(M.monadic ( -(* At stmt: unsupported node type: AnnAssign *) - let accounts_to_delete := - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |) in - let touched_accounts := - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |) in - let refund_counter := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let logs := M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in let accounts_to_delete := @@ -390,7 +242,6 @@ Definition process_message_call : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). Definition process_create_message : Value.t -> Value.t -> M := @@ -452,28 +303,6 @@ Definition process_create_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), - (* then *) - ltac:(M.monadic ( - let contract_code := - M.get_field (| M.get_name (| globals, "evm" |), "output" |) in - let contract_code_gas := - BinOp.mult (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "contract_code" |) - ], - make_dict [] - |), - M.get_name (| globals, "GAS_CODE_DEPOSIT" |) - |) in -(* At stmt: unsupported node type: Try *) - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "rollback_transaction" |), make_list [ @@ -485,7 +314,6 @@ Definition process_create_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) - |) in M.pure Constant.None_)). Definition process_message : Value.t -> Value.t -> M := @@ -507,21 +335,6 @@ Definition process_message : Value.t -> Value.t -> M := Items containing execution specific objects " in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_field (| M.get_name (| globals, "message" |), "depth" |), M.get_name (| globals, "STACK_DEPTH_LIMIT" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "StackDepthLimitError" |), - make_list [ - Constant.str "Stack depth limit reached" - ], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -540,29 +353,6 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - M.get_field (| M.get_name (| globals, "message" |), "should_transfer_value" |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_field (| M.get_name (| globals, "message" |), "value" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "move_ether" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_field (| M.get_name (| globals, "message" |), "caller" |); - M.get_field (| M.get_name (| globals, "message" |), "current_target" |); - M.get_field (| M.get_name (| globals, "message" |), "value" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let evm := @@ -575,21 +365,6 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "evm" |), "error" |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "rollback_transaction" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "commit_transaction" |), make_list [ @@ -601,7 +376,6 @@ Definition process_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) - |) in M.pure Constant.None_)). Definition execute_code : Value.t -> Value.t -> M := @@ -641,5 +415,4 @@ Definition execute_code : Value.t -> Value.t -> M := (* At stmt: unsupported node type: Try *) let _ := M.return_ (| M.get_name (| globals, "evm" |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/vm/memory.v b/CoqOfPython/ethereum/gray_glacier/vm/memory.v index fa8d906..4b107fd 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/memory.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/memory.v @@ -45,22 +45,7 @@ Definition memory_write : Value.t -> Value.t -> M := Data to write to memory. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) - |) |), + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_)). @@ -86,23 +71,7 @@ Definition memory_read_bytes : Value.t -> Value.t -> M := Data read from memory. " in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |) - |) in + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |) M.pure Constant.None_)). Definition buffer_read : Value.t -> Value.t -> M := @@ -129,25 +98,9 @@ Definition buffer_read : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "right_pad_zero_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |); + M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |) |); M.get_name (| globals, "size" |) ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/alt_bn128.v index 19b83fc..abe4238 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/alt_bn128.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/alt_bn128.v @@ -210,15 +210,6 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) in For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ] do let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "i" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -362,15 +353,6 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) in For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ] do let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "i" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -443,24 +425,6 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_eq (| BinOp.mod_ (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "data" |) - ], - make_dict [] - |), - Constant.int 192 - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let result := @@ -509,32 +473,11 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := Constant.int 32, M.get_name (| globals, "j" |) |) - |):BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "i" |), - Constant.int 192 - |), - BinOp.mult (| - Constant.int 32, - BinOp.add (| - M.get_name (| globals, "j" |), - Constant.int 1 - |) - |) |) |) ], make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "value" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -555,17 +498,20 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.call (| - M.get_field (| M.get_name (| globals, "p" |), "mul_by" |), - make_list [ - M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) - ], - make_dict [] - |), M.call (| - M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) |); + Compare.eq (| + M.call (| + M.get_field (| M.get_name (| globals, "p" |), "mul_by" |), + make_list [ + M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) + ], + make_dict [] + |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |); M.get_name (| globals, "OutOfGasError" |) ], make_dict [] @@ -573,87 +519,29 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.call (| - M.get_field (| M.get_name (| globals, "q" |), "mul_by" |), - make_list [ - M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) - ], - make_dict [] - |), M.call (| - M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) |); + Compare.eq (| + M.call (| + M.get_field (| M.get_name (| globals, "q" |), "mul_by" |), + make_list [ + M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) + ], + make_dict [] + |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |); M.get_name (| globals, "OutOfGasError" |) ], make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "p" |), M.call (| - M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_name (| globals, "q" |), M.call (| - M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let result := - BinOp.mult (| - M.get_name (| globals, "result" |), - M.call (| - M.get_name (| globals, "pairing" |), - make_list [ - M.get_name (| globals, "q" |); - M.get_name (| globals, "p" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "result" |), M.call (| - M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), - make_list [ - Constant.int 1 - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign (| - M.get_field (| M.get_name (| globals, "evm" |), "output" |), - M.call (| - M.get_field (| M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 1 - ], - make_dict [] - |), "to_be_bytes32" |), - make_list [], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| diff --git a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/blake2f.v b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/blake2f.v index 5903066..1647d48 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/blake2f.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/blake2f.v @@ -55,13 +55,16 @@ Definition blake2f : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "data" |) - ], - make_dict [] - |), Constant.int 213 |); + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 213 + |); M.get_name (| globals, "InvalidParameter" |) ], make_dict [] @@ -96,10 +99,13 @@ Definition blake2f : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.in (| M.get_name (| globals, "f" |), make_list [ - Constant.int 0; - Constant.int 1 - ] |); + Compare.in (| + M.get_name (| globals, "f" |), + make_list [ + Constant.int 0; + Constant.int 1 + ] + |); M.get_name (| globals, "InvalidParameter" |) ], make_dict [] diff --git a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/ecrecover.v index cc351b5..0cbcf16 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/ecrecover.v @@ -188,60 +188,12 @@ Definition ecrecover : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 27 |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 28 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| Constant.int 0, M.get_name (| globals, "r" |) |), - ltac:(M.monadic ( - Compare.gt_e (| M.get_name (| globals, "r" |), M.get_name (| globals, "SECP256K1N" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| Constant.int 0, M.get_name (| globals, "s" |) |), - ltac:(M.monadic ( - Compare.gt_e (| M.get_name (| globals, "s" |), M.get_name (| globals, "SECP256K1N" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: Try *) @@ -252,7 +204,7 @@ Definition ecrecover : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12:Constant.int 32 |) in + |), Constant.int 12 |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/modexp.v index 544949e..3505244 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/modexp.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/modexp.v @@ -192,30 +192,6 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_name (| globals, "base_length" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "modulus_length" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign (| - M.get_field (| M.get_name (| globals, "evm" |), "output" |), - M.call (| - M.get_name (| globals, "Bytes" |), - make_list [], - make_dict [] - |) - |) in - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let base := @@ -278,27 +254,6 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "modulus" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign (| - M.get_field (| M.get_name (| globals, "evm" |), "output" |), - BinOp.mult (| - M.call (| - M.get_name (| globals, "Bytes" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |), - M.get_name (| globals, "modulus_length" |) - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| @@ -383,7 +338,6 @@ Definition complexity : Value.t -> Value.t -> M := M.get_name (| globals, "words" |), Constant.int 2 |) - |) in M.pure Constant.None_)). Definition iterations : Value.t -> Value.t -> M := @@ -410,64 +364,7 @@ Definition iterations : Value.t -> Value.t -> M := Number of iterations. " in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.lt_e (| M.get_name (| globals, "exponent_length" |), Constant.int 32 |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "exponent_head" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let count := - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - Compare.lt_e (| M.get_name (| globals, "exponent_length" |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let bit_length := - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.call (| - M.get_field (| M.get_name (| globals, "exponent_head" |), "bit_length" |), - make_list [], - make_dict [] - |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "bit_length" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let bit_length := BinOp.sub - Constant.int 1 - Constant.int 1 in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let count := - M.get_name (| globals, "bit_length" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let length_part := BinOp.mult (| Constant.int 8, @@ -495,17 +392,6 @@ Definition iterations : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "bits_part" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let bits_part := BinOp.sub - Constant.int 1 - Constant.int 1 in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let count := @@ -532,7 +418,6 @@ Definition iterations : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition gas_cost : Value.t -> Value.t -> M := @@ -604,5 +489,4 @@ Definition gas_cost : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/vm/runtime.v b/CoqOfPython/ethereum/gray_glacier/vm/runtime.v index 835b46c..2cd7652 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/runtime.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/runtime.v @@ -67,50 +67,19 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := ], make_dict [] |) in - While Compare.lt (| M.get_name (| globals, "pc" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "code" |) - ], - make_dict [] - |) |) do + While Compare.lt (| + M.get_name (| globals, "pc" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) + |) do (* At stmt: unsupported node type: Try *) let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "current_opcode" |), M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), - make_list [ - M.get_name (| globals, "pc" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - (* At expr: unsupported node type: Compare *), - (* then *) - ltac:(M.monadic ( - let push_data_size := - BinOp.add (| - BinOp.sub (| - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) - |), - Constant.int 1 - |) in - let pc := BinOp.add - M.get_name (| globals, "push_data_size" |) - M.get_name (| globals, "push_data_size" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -121,5 +90,4 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := EndWhile. let _ := M.return_ (| M.get_name (| globals, "valid_jump_destinations" |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/vm/stack.v b/CoqOfPython/ethereum/gray_glacier/vm/stack.v index 42ea42d..ea778df 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/stack.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/stack.v @@ -49,21 +49,6 @@ Definition pop : Value.t -> Value.t -> M := " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "stack" |) - ], - make_dict [] - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "StackUnderflowError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -72,7 +57,6 @@ Definition pop : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). Definition push : Value.t -> Value.t -> M := @@ -91,21 +75,6 @@ Definition push : Value.t -> Value.t -> M := " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "stack" |) - ], - make_dict [] - |), Constant.int 1024 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "StackOverflowError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -116,5 +85,4 @@ Definition push : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/bloom.v b/CoqOfPython/ethereum/homestead/bloom.v index 04b5d9f..04650ff 100644 --- a/CoqOfPython/ethereum/homestead/bloom.v +++ b/CoqOfPython/ethereum/homestead/bloom.v @@ -72,10 +72,7 @@ Definition add_to_bloom : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |):BinOp.add (| - M.get_name (| globals, "idx" |), - Constant.int 2 - |) |) + M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |) |) ], make_dict [] |), @@ -160,5 +157,4 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/fork.v b/CoqOfPython/ethereum/homestead/fork.v index 951cae7..245eaa1 100644 --- a/CoqOfPython/ethereum/homestead/fork.v +++ b/CoqOfPython/ethereum/homestead/fork.v @@ -222,7 +222,6 @@ Definition apply_fork : Value.t -> Value.t -> M := " in let _ := M.return_ (| M.get_name (| globals, "old" |) - |) in M.pure Constant.None_)). Definition get_last_256_block_hashes : Value.t -> Value.t -> M := @@ -248,25 +247,8 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := Hashes of the recent 256 blocks in order of increasing block number. " in let recent_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |) |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "recent_blocks" |) - ], - make_dict [] - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - make_list [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let recent_block_hashes := @@ -305,7 +287,6 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "recent_block_hashes" |) - |) in M.pure Constant.None_)). Definition state_transition : Value.t -> Value.t -> M := @@ -376,7 +357,10 @@ Definition state_transition : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_gas_used" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "gas_used" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_gas_used" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "gas_used" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -384,7 +368,10 @@ Definition state_transition : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "transactions_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "transactions_root" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "transactions_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "transactions_root" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -392,7 +379,10 @@ Definition state_transition : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "state_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "state_root" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "state_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "state_root" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -400,7 +390,10 @@ Definition state_transition : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "receipt_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "receipt_root" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "receipt_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "receipt_root" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -408,7 +401,10 @@ Definition state_transition : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_logs_bloom" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "bloom" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_logs_bloom" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "bloom" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -421,24 +417,6 @@ Definition state_transition : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "chain" |), "blocks" |) - ], - make_dict [] - |), Constant.int 255 |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign (| - M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |):(* At expr: unsupported node type: NoneType *) |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -466,7 +444,10 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.gt (| M.get_field (| M.get_name (| globals, "header" |), "timestamp" |), M.get_field (| M.get_name (| globals, "parent_header" |), "timestamp" |) |); + Compare.gt (| + M.get_field (| M.get_name (| globals, "header" |), "timestamp" |), + M.get_field (| M.get_name (| globals, "parent_header" |), "timestamp" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -474,10 +455,13 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "number" |), BinOp.add (| - M.get_field (| M.get_name (| globals, "parent_header" |), "number" |), - Constant.int 1 - |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "number" |), + BinOp.add (| + M.get_field (| M.get_name (| globals, "parent_header" |), "number" |), + Constant.int 1 + |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -500,13 +484,16 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt_e (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) - ], - make_dict [] - |), Constant.int 32 |); + Compare.lt_e (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) + ], + make_dict [] + |), + Constant.int 32 + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -525,7 +512,10 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "difficulty" |), M.get_name (| globals, "block_difficulty" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "difficulty" |), + M.get_name (| globals, "block_difficulty" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -547,7 +537,10 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |), M.get_name (| globals, "block_parent_hash" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |), + M.get_name (| globals, "block_parent_hash" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -610,7 +603,6 @@ Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition validate_proof_of_work : Value.t -> Value.t -> M := @@ -668,7 +660,10 @@ Definition validate_proof_of_work : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_name (| globals, "mix_digest" |), M.get_field (| M.get_name (| globals, "header" |), "mix_digest" |) |); + Compare.eq (| + M.get_name (| globals, "mix_digest" |), + M.get_field (| M.get_name (| globals, "header" |), "mix_digest" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -676,16 +671,19 @@ Definition validate_proof_of_work : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt_e (| M.call (| - M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), - make_list [ - M.get_name (| globals, "result" |) - ], - make_dict [] - |), BinOp.floor_div (| - M.get_name (| globals, "U256_CEIL_VALUE" |), - M.get_field (| M.get_name (| globals, "header" |), "difficulty" |) - |) |); + Compare.lt_e (| + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "result" |) + ], + make_dict [] + |), + BinOp.floor_div (| + M.get_name (| globals, "U256_CEIL_VALUE" |), + M.get_field (| M.get_name (| globals, "header" |), "difficulty" |) + |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -718,7 +716,10 @@ Definition check_transaction : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt_e (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_name (| globals, "gas_available" |) |); + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_name (| globals, "gas_available" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -733,7 +734,6 @@ Definition check_transaction : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "sender_address" |) - |) in M.pure Constant.None_)). Definition make_receipt : Value.t -> Value.t -> M := @@ -767,7 +767,6 @@ Definition make_receipt : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "receipt" |) - |) in M.pure Constant.None_)). Definition ApplyBodyOutput : Value.t := @@ -981,7 +980,6 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition validate_ommers : Value.t -> Value.t -> M := @@ -1019,42 +1017,39 @@ Definition validate_ommers : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), - make_list [ - M.get_name (| globals, "ommers" |) - ], - make_dict [] - |), M.get_field (| M.get_name (| globals, "block_header" |), "ommers_hash" |) |); + Compare.eq (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + M.get_field (| M.get_name (| globals, "block_header" |), "ommers_hash" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "ommers" |) - ], - make_dict [] - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - (* At expr: unsupported node type: Compare *); + BoolOp.and (| + Compare.lt_e (| + Constant.int 1, + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |), + ltac:(M.monadic ( + Compare.lt (| + M.get_field (| M.get_name (| globals, "ommer" |), "number" |), + M.get_field (| M.get_name (| globals, "block_header" |), "number" |) + |) + )) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1079,47 +1074,47 @@ Definition validate_ommers : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt_e (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "ommers" |) - ], - make_dict [] - |), Constant.int 2 |); + Compare.lt_e (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + Constant.int 2 + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] |) in let ommers_hashes := - [M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), - make_list [ - M.get_name (| globals, "ommer" |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)] in + (* At expr: unsupported node type: ListComp *) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "ommers_hashes" |) - ], - make_dict [] - |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.call (| - M.get_name (| globals, "set" |), - make_list [ - M.get_name (| globals, "ommers_hashes" |) - ], - make_dict [] - |) - ], - make_dict [] - |) |); + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers_hashes" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_name (| globals, "set" |), + make_list [ + M.get_name (| globals, "ommers_hashes" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1128,28 +1123,16 @@ Definition validate_ommers : Value.t -> Value.t -> M := M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| BinOp.add (| M.get_name (| globals, "MAX_OMMER_DEPTH" |), Constant.int 1 - |) |):(* At expr: unsupported node type: NoneType *) |) in + |) |) |) in let recent_canonical_block_hashes := - {M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), - make_list [ - M.get_field (| M.get_name (| globals, "block" |), "header" |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)} in + (* At expr: unsupported node type: SetComp *) in (* At stmt: unsupported node type: AnnAssign *) For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_canonical_blocks" |) do let recent_ommers_hashes := M.call (| M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), make_list [ - {M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), - make_list [ - M.get_name (| globals, "ommer" |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)} + (* At expr: unsupported node type: SetComp *) ], make_dict [] |) in @@ -1166,7 +1149,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.not_eq (| M.get_name (| globals, "ommer_hash" |), M.get_name (| globals, "block_hash" |) |); + Compare.not_eq (| + M.get_name (| globals, "ommer_hash" |), + M.get_name (| globals, "block_hash" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1174,7 +1160,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.not_in (| M.get_name (| globals, "ommer_hash" |), M.get_name (| globals, "recent_canonical_block_hashes" |) |); + Compare.not_in (| + M.get_name (| globals, "ommer_hash" |), + M.get_name (| globals, "recent_canonical_block_hashes" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1182,7 +1171,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.not_in (| M.get_name (| globals, "ommer_hash" |), M.get_name (| globals, "recent_ommers_hashes" |) |); + Compare.not_in (| + M.get_name (| globals, "ommer_hash" |), + M.get_name (| globals, "recent_ommers_hashes" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1195,7 +1187,18 @@ Definition validate_ommers : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - (* At expr: unsupported node type: Compare *); + BoolOp.and (| + Compare.lt_e (| + Constant.int 1, + M.get_name (| globals, "ommer_age" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_name (| globals, "ommer_age" |), + M.get_name (| globals, "MAX_OMMER_DEPTH" |) + |) + )) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1203,7 +1206,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.in (| M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), M.get_name (| globals, "recent_canonical_block_hashes" |) |); + Compare.in (| + M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), + M.get_name (| globals, "recent_canonical_block_hashes" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1211,7 +1217,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.not_eq (| M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), M.get_field (| M.get_name (| globals, "block_header" |), "parent_hash" |) |); + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), + M.get_field (| M.get_name (| globals, "block_header" |), "parent_hash" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1370,7 +1379,10 @@ Definition process_transaction : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "sender_account" |), "nonce" |), M.get_field (| M.get_name (| globals, "tx" |), "nonce" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "sender_account" |), "nonce" |), + M.get_field (| M.get_name (| globals, "tx" |), "nonce" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1378,10 +1390,13 @@ Definition process_transaction : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.gt_e (| M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), BinOp.add (| - M.get_name (| globals, "gas_fee" |), - M.get_field (| M.get_name (| globals, "tx" |), "value" |) - |) |); + Compare.gt_e (| + M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), + BinOp.add (| + M.get_name (| globals, "gas_fee" |), + M.get_field (| M.get_name (| globals, "tx" |), "value" |) + |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1389,11 +1404,14 @@ Definition process_transaction : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "sender_account" |), "code" |), M.call (| - M.get_name (| globals, "bytearray" |), - make_list [], - make_dict [] - |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "sender_account" |), "code" |), + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [], + make_dict [] + |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1548,7 +1566,6 @@ Definition process_transaction : Value.t -> Value.t -> M := EndFor. let _ := M.return_ (| make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |) ] - |) in M.pure Constant.None_)). Definition validate_transaction : Value.t -> Value.t -> M := @@ -1580,24 +1597,29 @@ Definition validate_transaction : Value.t -> Value.t -> M := " in let _ := M.return_ (| BoolOp.and (| - Compare.lt_e (| M.call (| - M.get_name (| globals, "calculate_intrinsic_cost" |), - make_list [ - M.get_name (| globals, "tx" |) - ], - make_dict [] - |), M.get_field (| M.get_name (| globals, "tx" |), "gas" |) |), + Compare.lt_e (| + M.call (| + M.get_name (| globals, "calculate_intrinsic_cost" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |), + M.get_field (| M.get_name (| globals, "tx" |), "gas" |) + |), ltac:(M.monadic ( - Compare.lt (| M.get_field (| M.get_name (| globals, "tx" |), "nonce" |), BinOp.sub (| + Compare.lt (| + M.get_field (| M.get_name (| globals, "tx" |), "nonce" |), + BinOp.sub (| BinOp.pow (| Constant.int 2, Constant.int 64 |), Constant.int 1 - |) |) + |) + |) )) |) - |) in M.pure Constant.None_)). Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := @@ -1629,17 +1651,6 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := Constant.int 0 in For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "byte" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let data_cost := BinOp.add - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let data_cost := BinOp.add M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in @@ -1647,22 +1658,6 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := )) |) in EndFor. let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_name (| globals, "tx" |), "to" |), M.call (| - M.get_name (| globals, "Bytes0" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let create_cost := - M.get_name (| globals, "TX_CREATE_COST" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let create_cost := Constant.int 0 in M.pure Constant.None_ @@ -1681,7 +1676,6 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition recover_sender : Value.t -> Value.t -> M := @@ -1714,9 +1708,15 @@ Definition recover_sender : Value.t -> Value.t -> M := M.get_name (| globals, "ensure" |), make_list [ BoolOp.or (| - Compare.eq (| M.get_name (| globals, "v" |), Constant.int 27 |), + Compare.eq (| + M.get_name (| globals, "v" |), + Constant.int 27 + |), ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "v" |), Constant.int 28 |) + Compare.eq (| + M.get_name (| globals, "v" |), + Constant.int 28 + |) )) |); M.get_name (| globals, "InvalidBlock" |) @@ -1727,9 +1727,15 @@ Definition recover_sender : Value.t -> Value.t -> M := M.get_name (| globals, "ensure" |), make_list [ BoolOp.and (| - Compare.lt (| Constant.int 0, M.get_name (| globals, "r" |) |), + Compare.lt (| + Constant.int 0, + M.get_name (| globals, "r" |) + |), ltac:(M.monadic ( - Compare.lt (| M.get_name (| globals, "r" |), M.get_name (| globals, "SECP256K1N" |) |) + Compare.lt (| + M.get_name (| globals, "r" |), + M.get_name (| globals, "SECP256K1N" |) + |) )) |); M.get_name (| globals, "InvalidBlock" |) @@ -1740,12 +1746,18 @@ Definition recover_sender : Value.t -> Value.t -> M := M.get_name (| globals, "ensure" |), make_list [ BoolOp.and (| - Compare.lt (| Constant.int 0, M.get_name (| globals, "s" |) |), + Compare.lt (| + Constant.int 0, + M.get_name (| globals, "s" |) + |), ltac:(M.monadic ( - Compare.lt_e (| M.get_name (| globals, "s" |), BinOp.floor_div (| + Compare.lt_e (| + M.get_name (| globals, "s" |), + BinOp.floor_div (| M.get_name (| globals, "SECP256K1N" |), Constant.int 2 - |) |) + |) + |) )) |); M.get_name (| globals, "InvalidBlock" |) @@ -1782,11 +1794,10 @@ Definition recover_sender : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12:Constant.int 32 |) + |), Constant.int 12 |) ], make_dict [] |) - |) in M.pure Constant.None_)). Definition signing_hash : Value.t -> Value.t -> M := @@ -1823,7 +1834,6 @@ Definition signing_hash : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition compute_header_hash : Value.t -> Value.t -> M := @@ -1874,7 +1884,6 @@ Definition compute_header_hash : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition check_gas_limit : Value.t -> Value.t -> M := @@ -1913,56 +1922,16 @@ Definition check_gas_limit : Value.t -> Value.t -> M := M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "gas_limit" |), BinOp.add (| - M.get_name (| globals, "parent_gas_limit" |), - M.get_name (| globals, "max_adjustment_delta" |) - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.bool false - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt_e (| M.get_name (| globals, "gas_limit" |), BinOp.sub (| - M.get_name (| globals, "parent_gas_limit" |), - M.get_name (| globals, "max_adjustment_delta" |) - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.bool false - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "gas_limit" |), M.get_name (| globals, "GAS_LIMIT_MINIMUM" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.bool false - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| Constant.bool true - |) in M.pure Constant.None_)). Definition calculate_block_difficulty : Value.t -> Value.t -> M := @@ -2066,23 +2035,6 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := Constant.int 2 |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "num_bomb_periods" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let difficulty := BinOp.add - BinOp.pow (| - Constant.int 2, - M.get_name (| globals, "num_bomb_periods" |) - |) - BinOp.pow (| - Constant.int 2, - M.get_name (| globals, "num_bomb_periods" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -2100,5 +2052,4 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/fork_types.v b/CoqOfPython/ethereum/homestead/fork_types.v index d12953d..5c7dac3 100644 --- a/CoqOfPython/ethereum/homestead/fork_types.v +++ b/CoqOfPython/ethereum/homestead/fork_types.v @@ -98,5 +98,4 @@ Definition encode_account : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/state.v b/CoqOfPython/ethereum/homestead/state.v index 38fe9d1..2ba095e 100644 --- a/CoqOfPython/ethereum/homestead/state.v +++ b/CoqOfPython/ethereum/homestead/state.v @@ -123,13 +123,7 @@ Definition begin_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) ], make_dict [] - |); {M.get_name (| globals, "k" |): M.call (| - M.get_name (| globals, "copy_trie" |), - make_list [ - M.get_name (| globals, "t" |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)} ] + |); (* At expr: unsupported node type: DictComp *) ] ], make_dict [] |) in @@ -207,27 +201,8 @@ Definition get_account : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "account" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "account" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_ACCOUNT" |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -262,7 +237,6 @@ Definition get_account_optional : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "account" |) - |) in M.pure Constant.None_)). Definition set_account : Value.t -> Value.t -> M := @@ -342,15 +316,6 @@ Definition destroy_storage : Value.t -> Value.t -> M := Address of account whose storage is to be deleted. " in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -385,23 +350,6 @@ Definition get_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let value := @@ -423,7 +371,6 @@ Definition get_storage : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "value" |) - |) in M.pure Constant.None_)). Definition set_storage : Value.t -> Value.t -> M := @@ -444,14 +391,17 @@ Definition set_storage : Value.t -> Value.t -> M := value : `U256` Value to set at the key. " in - let _ := M.assert (| Compare.is_not (| M.call (| - M.get_name (| globals, "trie_get" |), - make_list [ - M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), Constant.None_ |) |) in + let _ := M.assert (| Compare.is_not (| + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + Constant.None_ + |) |) in let trie := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), @@ -461,24 +411,6 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let trie := - M.call (| - M.get_name (| globals, "Trie" |), - make_list [], - make_dict [] - |) in - let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), - M.get_name (| globals, "trie" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -491,15 +423,6 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), {} |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -524,26 +447,8 @@ Definition storage_root : Value.t -> Value.t -> M := " in let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "root" |), - make_list [ - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_TRIE_ROOT" |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -574,7 +479,6 @@ Definition state_root : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition account_exists : Value.t -> Value.t -> M := @@ -596,15 +500,17 @@ Definition account_exists : Value.t -> Value.t -> M := True if account exists in the state trie, False otherwise " in let _ := M.return_ (| - Compare.is_not (| M.call (| - M.get_name (| globals, "get_account_optional" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), Constant.None_ |) - |) in + Compare.is_not (| + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + Constant.None_ + |) M.pure Constant.None_)). Definition account_has_code_or_nonce : Value.t -> Value.t -> M := @@ -637,18 +543,23 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := |) in let _ := M.return_ (| BoolOp.or (| - Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( - Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |) + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |) )) |) - |) in M.pure Constant.None_)). Definition modify_state : Value.t -> Value.t -> M := @@ -754,30 +665,6 @@ Definition touch_account : Value.t -> Value.t -> M := The address of the account that need to initialised. " in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "account_exists" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "set_account" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |); - M.get_name (| globals, "EMPTY_ACCOUNT" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/trie.v b/CoqOfPython/ethereum/homestead/trie.v index a9cbb1f..e2ac401 100644 --- a/CoqOfPython/ethereum/homestead/trie.v +++ b/CoqOfPython/ethereum/homestead/trie.v @@ -202,96 +202,16 @@ Definition encode_internal_node : Value.t -> Value.t -> M := " in (* At stmt: unsupported node type: AnnAssign *) let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "node" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let unencoded := - (* At constant: unsupported node type: Constant *) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "LeafNode" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let unencoded := - make_tuple [ M.call (| - M.get_name (| globals, "nibble_list_to_compact" |), - make_list [ - M.get_field (| M.get_name (| globals, "node" |), "rest_of_key" |); - Constant.bool true - ], - make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "ExtensionNode" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let unencoded := - make_tuple [ M.call (| - M.get_name (| globals, "nibble_list_to_compact" |), - make_list [ - M.get_field (| M.get_name (| globals, "node" |), "key_segment" |); - Constant.bool false - ], - make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "BranchNode" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let unencoded := - BinOp.add (| - M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), - make_list [ - M.get_field (| M.get_name (| globals, "node" |), "value" |) - ] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.call (| + let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ (* At expr: unsupported node type: JoinedStr *) ], make_dict [] - |) |) in + |)) M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -309,23 +229,6 @@ Definition encode_internal_node : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "encoded" |) - ], - make_dict [] - |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "unencoded" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_name (| globals, "keccak256" |), @@ -334,7 +237,6 @@ Definition encode_internal_node : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -348,83 +250,8 @@ Definition encode_node : Value.t -> Value.t -> M := Currently mostly an unimplemented stub. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "storage_root" |), Constant.None_ |) |) in - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "encode_account" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "storage_root" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - make_tuple [ M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "U256" |) ] - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.call (| - M.get_name (| globals, "cast" |), - make_list [ - M.get_field (| M.get_name (| globals, "rlp" |), "RLP" |); - M.get_name (| globals, "node" |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "Bytes" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "node" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "previous_trie" |), "encode_node" |), @@ -434,7 +261,6 @@ Definition encode_node : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -486,7 +312,6 @@ Definition copy_trie : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition trie_set : Value.t -> Value.t -> M := @@ -508,26 +333,6 @@ Definition trie_set : Value.t -> Value.t -> M := Node to insert at `key`. " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "value" |), M.get_field (| M.get_name (| globals, "trie" |), "default" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "key" |), M.get_field (| M.get_name (| globals, "trie" |), "_data" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), M.get_name (| globals, "value" |) @@ -565,7 +370,6 @@ Definition trie_get : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition common_prefix_length : Value.t -> Value.t -> M := @@ -588,28 +392,6 @@ Definition common_prefix_length : Value.t -> Value.t -> M := make_dict [] |) do let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| M.get_name (| globals, "i" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "b" |) - ], - make_dict [] - |) |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "i" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -621,7 +403,6 @@ Definition common_prefix_length : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition nibble_list_to_compact : Value.t -> Value.t -> M := @@ -667,68 +448,6 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| BinOp.mod_ (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |), - Constant.int 2 - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_name (| globals, "compact" |), "append" |), - make_list [ - BinOp.mult (| - Constant.int 16, - BinOp.mult (| - Constant.int 2, - M.get_name (| globals, "is_leaf" |) - |) - |) - ], - make_dict [] - |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 0; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |); - Constant.int 2 - ], - make_dict [] - |) do - let _ := M.call (| - M.get_field (| M.get_name (| globals, "compact" |), "append" |), - make_list [ - BinOp.add (| - BinOp.mult (| - Constant.int 16, - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) - |), - M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) - |) - ], - make_dict [] - |) in - EndFor. - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ @@ -790,7 +509,6 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition bytes_to_nibble_list : Value.t -> Value.t -> M := @@ -868,7 +586,6 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition _prepare_trie : Value.t -> Value.t -> M := @@ -898,45 +615,6 @@ Definition _prepare_trie : Value.t -> Value.t -> M := make_dict [] |) do let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "value" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in - let address := - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in - let encoded_value := - M.call (| - M.get_name (| globals, "encode_node" |), - make_list [ - M.get_name (| globals, "value" |); - M.call (| - M.get_name (| globals, "get_storage_root" |), - make_list [ - M.get_name (| globals, "address" |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let encoded_value := M.call (| M.get_name (| globals, "encode_node" |), @@ -950,29 +628,16 @@ Definition _prepare_trie : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.not_eq (| M.get_name (| globals, "encoded_value" |), (* At constant: unsupported node type: Constant *) |); + Compare.not_eq (| + M.get_name (| globals, "encoded_value" |), + Constant.bytes "" + |); M.get_name (| globals, "AssertionError" |) ], make_dict [] |) in (* At stmt: unsupported node type: AnnAssign *) let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "trie" |), "secured" |), - (* then *) - ltac:(M.monadic ( - let key := - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let key := M.get_name (| globals, "preimage" |) in M.pure Constant.None_ @@ -990,7 +655,6 @@ Definition _prepare_trie : Value.t -> Value.t -> M := EndFor. let _ := M.return_ (| M.get_name (| globals, "mapped" |) - |) in M.pure Constant.None_)). Definition root : Value.t -> Value.t -> M := @@ -1044,41 +708,6 @@ Definition root : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "root_node" |) - ], - make_dict [] - |) - ], - make_dict [] - |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "root_node" |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -1095,7 +724,6 @@ Definition root : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -1122,23 +750,6 @@ Definition patricialize : Value.t -> Value.t -> M := Root node of `obj`. " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "obj" |) - ], - make_dict [] - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.None_ - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let arbitrary_key := @@ -1156,36 +767,10 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "obj" |) - ], - make_dict [] - |), Constant.int 1 |), - (* then *) - ltac:(M.monadic ( - let leaf := - M.call (| - M.get_name (| globals, "LeafNode" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |); - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) - ], - make_dict [] - |) in - let _ := M.return_ (| - M.get_name (| globals, "leaf" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let substring := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |) |) in let prefix_length := M.call (| M.get_name (| globals, "len" |), @@ -1204,7 +789,7 @@ Definition patricialize : Value.t -> Value.t -> M := M.get_name (| globals, "common_prefix_length" |), make_list [ M.get_name (| globals, "substring" |); - M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) + M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) ], make_dict [] |) @@ -1212,58 +797,10 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.break (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let prefix := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):BinOp.add (| - M.get_name (| globals, "level" |), - M.get_name (| globals, "prefix_length" |) - |) |) in - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "ExtensionNode" |), - make_list [ - M.get_name (| globals, "prefix" |); - M.call (| - M.get_name (| globals, "encode_internal_node" |), - make_list [ - M.call (| - M.get_name (| globals, "patricialize" |), - make_list [ - M.get_name (| globals, "obj" |); - BinOp.add (| - M.get_name (| globals, "level" |), - M.get_name (| globals, "prefix_length" |) - |) - ], - make_dict [] - |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) @@ -1283,44 +820,9 @@ Definition patricialize : Value.t -> Value.t -> M := |) in EndFor. let value := - (* At constant: unsupported node type: Constant *) in + Constant.bytes "" in For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "key" |) - ], - make_dict [] - |), M.get_name (| globals, "level" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); - make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "AssertionError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let value := - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) @@ -1332,26 +834,9 @@ Definition patricialize : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "BranchNode" |), make_list [ - [M.call (| - M.get_name (| globals, "encode_internal_node" |), - make_list [ - M.call (| - M.get_name (| globals, "patricialize" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "branches" |), M.get_name (| globals, "k" |) |); - BinOp.add (| - M.get_name (| globals, "level" |), - Constant.int 1 - |) - ], - make_dict [] - |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)]; + (* At expr: unsupported node type: ListComp *); M.get_name (| globals, "value" |) ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/utils/address.v b/CoqOfPython/ethereum/homestead/utils/address.v index e36c5e8..fef11f0 100644 --- a/CoqOfPython/ethereum/homestead/utils/address.v +++ b/CoqOfPython/ethereum/homestead/utils/address.v @@ -67,11 +67,10 @@ Definition to_address : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), make_list [], make_dict [] - |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) + |), UnOp.sub (| Constant.int 20 |) |) ], make_dict [] |) - |) in M.pure Constant.None_)). Definition compute_contract_address : Value.t -> Value.t -> M := @@ -111,7 +110,7 @@ Definition compute_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -129,5 +128,4 @@ Definition compute_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/utils/hexadecimal.v b/CoqOfPython/ethereum/homestead/utils/hexadecimal.v index 3d8c6ad..661eab7 100644 --- a/CoqOfPython/ethereum/homestead/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/homestead/utils/hexadecimal.v @@ -66,7 +66,6 @@ Definition hex_to_root : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition hex_to_bloom : Value.t -> Value.t -> M := @@ -105,7 +104,6 @@ Definition hex_to_bloom : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition hex_to_address : Value.t -> Value.t -> M := @@ -151,5 +149,4 @@ Definition hex_to_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/utils/message.v b/CoqOfPython/ethereum/homestead/utils/message.v index eb1c3a9..d43d092 100644 --- a/CoqOfPython/ethereum/homestead/utils/message.v +++ b/CoqOfPython/ethereum/homestead/utils/message.v @@ -84,105 +84,14 @@ Definition prepare_message : Value.t -> Value.t -> M := Items containing contract creation or message call specific data. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "target" |); - M.get_name (| globals, "Bytes0" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let current_target := - M.call (| - M.get_name (| globals, "compute_contract_address" |), - make_list [ - M.get_name (| globals, "caller" |); - BinOp.sub (| - M.get_field (| M.call (| - M.get_name (| globals, "get_account" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "caller" |) - ], - make_dict [] - |), "nonce" |), - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 1 - ], - make_dict [] - |) - |) - ], - make_dict [] - |) in - let msg_data := - M.call (| - M.get_name (| globals, "Bytes" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |) in - let code := - M.get_name (| globals, "data" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "target" |); - M.get_name (| globals, "Address" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let current_target := - M.get_name (| globals, "target" |) in - let msg_data := - M.get_name (| globals, "data" |) in - let code := - M.get_field (| M.call (| - M.get_name (| globals, "get_account" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "target" |) - ], - make_dict [] - |), "code" |) in - let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "code_address" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let code_address := - M.get_name (| globals, "target" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.call (| + let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "Target must be address or empty bytes" ], make_dict [] - |) |) in + |)) M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -193,5 +102,4 @@ Definition prepare_message : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/vm/gas.v b/CoqOfPython/ethereum/homestead/vm/gas.v new file mode 100644 index 0000000..eef500a --- /dev/null +++ b/CoqOfPython/ethereum/homestead/vm/gas.v @@ -0,0 +1,769 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Gas +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +EVM gas constants and calculators. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.trace. +Axiom ethereum_trace_GasAndRefund : + IsGlobalAlias globals ethereum.trace.globals "GasAndRefund". +Axiom ethereum_trace_evm_trace : + IsGlobalAlias globals ethereum.trace.globals "evm_trace". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_State : + IsGlobalAlias globals state.globals "State". +Axiom state_account_exists : + IsGlobalAlias globals state.globals "account_exists". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". + +Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) +)). + +Definition GAS_BASE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 2 + ], + make_dict [] + |) +)). + +Definition GAS_VERY_LOW : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_SLOAD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 50 + ], + make_dict [] + |) +)). + +Definition GAS_STORAGE_SET : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 20000 + ], + make_dict [] + |) +)). + +Definition GAS_STORAGE_UPDATE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5000 + ], + make_dict [] + |) +)). + +Definition GAS_STORAGE_CLEAR_REFUND : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 15000 + ], + make_dict [] + |) +)). + +Definition GAS_LOW : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5 + ], + make_dict [] + |) +)). + +Definition GAS_MID : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 8 + ], + make_dict [] + |) +)). + +Definition GAS_HIGH : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 10 + ], + make_dict [] + |) +)). + +Definition GAS_EXPONENTIATION : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 10 + ], + make_dict [] + |) +)). + +Definition GAS_EXPONENTIATION_PER_BYTE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 10 + ], + make_dict [] + |) +)). + +Definition GAS_MEMORY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_KECCAK256 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 30 + ], + make_dict [] + |) +)). + +Definition GAS_KECCAK256_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 6 + ], + make_dict [] + |) +)). + +Definition GAS_COPY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_BLOCK_HASH : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 20 + ], + make_dict [] + |) +)). + +Definition GAS_EXTERNAL : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 20 + ], + make_dict [] + |) +)). + +Definition GAS_BALANCE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 20 + ], + make_dict [] + |) +)). + +Definition GAS_LOG : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 375 + ], + make_dict [] + |) +)). + +Definition GAS_LOG_DATA : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 8 + ], + make_dict [] + |) +)). + +Definition GAS_LOG_TOPIC : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 375 + ], + make_dict [] + |) +)). + +Definition GAS_CREATE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 32000 + ], + make_dict [] + |) +)). + +Definition GAS_CODE_DEPOSIT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 200 + ], + make_dict [] + |) +)). + +Definition GAS_ZERO : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) +)). + +Definition GAS_CALL : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 40 + ], + make_dict [] + |) +)). + +Definition GAS_NEW_ACCOUNT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 25000 + ], + make_dict [] + |) +)). + +Definition GAS_CALL_VALUE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 9000 + ], + make_dict [] + |) +)). + +Definition GAS_CALL_STIPEND : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 2300 + ], + make_dict [] + |) +)). + +Definition REFUND_SELF_DESTRUCT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 24000 + ], + make_dict [] + |) +)). + +Definition GAS_ECRECOVER : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3000 + ], + make_dict [] + |) +)). + +Definition GAS_SHA256 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 60 + ], + make_dict [] + |) +)). + +Definition GAS_SHA256_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 12 + ], + make_dict [] + |) +)). + +Definition GAS_RIPEMD160 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 600 + ], + make_dict [] + |) +)). + +Definition GAS_RIPEMD160_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 120 + ], + make_dict [] + |) +)). + +Definition GAS_IDENTITY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 15 + ], + make_dict [] + |) +)). + +Definition GAS_IDENTITY_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition ExtendMemory : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition MessageCallGas : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition charge_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "amount" ] |) in + let _ := Constant.str " + Subtracts `amount` from `evm.gas_left`. + + Parameters + ---------- + evm : + The current EVM. + amount : + The amount of gas the current operation requires. + + " in + let _ := M.call (| + M.get_name (| globals, "evm_trace" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "GasAndRefund" |), + make_list [ + M.get_name (| globals, "amount" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + let _ := M.assign_op (| + BinOp.sub, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "amount" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition calculate_memory_gas_cost : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "size_in_bytes" ] |) in + let _ := Constant.str " + Calculates the gas cost for allocating memory + to the smallest multiple of 32 bytes, + such that the allocated size is at least as big as the given size. + + Parameters + ---------- + size_in_bytes : + The size of the data in bytes. + + Returns + ------- + total_gas_cost : `ethereum.base_types.Uint` + The gas cost for storing data in memory. + " in + let size_in_words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "size_in_bytes" |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let linear_cost := + BinOp.mult (| + M.get_name (| globals, "size_in_words" |), + M.get_name (| globals, "GAS_MEMORY" |) + |) in + let quadratic_cost := + BinOp.floor_div (| + BinOp.pow (| + M.get_name (| globals, "size_in_words" |), + Constant.int 2 + |), + Constant.int 512 + |) in + let total_gas_cost := + BinOp.add (| + M.get_name (| globals, "linear_cost" |), + M.get_name (| globals, "quadratic_cost" |) + |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_)). + +Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "memory"; "extensions" ] |) in + let _ := Constant.str " + Calculates the gas amount to extend memory + + Parameters + ---------- + memory : + Memory contents of the EVM. + extensions: + List of extensions to be made to the memory. + Consists of a tuple of start position and size. + + Returns + ------- + extend_memory: `ExtendMemory` + " in + let size_to_extend := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let to_be_paid := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let current_size := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "memory" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + For make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ] in M.get_name (| globals, "extensions" |) do + let _ := + M.pure Constant.None_ + )) |) in + let before_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "current_size" |) + ], + make_dict [] + |) in + let after_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let size_to_extend := BinOp.add + BinOp.sub (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |) + BinOp.sub (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |) in + let already_paid := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "before_size" |) + ], + make_dict [] + |) in + let total_cost := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "after_size" |) + ], + make_dict [] + |) in + let to_be_paid := BinOp.add + BinOp.sub (| + M.get_name (| globals, "total_cost" |), + M.get_name (| globals, "already_paid" |) + |) + BinOp.sub (| + M.get_name (| globals, "total_cost" |), + M.get_name (| globals, "already_paid" |) + |) in + let current_size := + M.get_name (| globals, "after_size" |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ExtendMemory" |), + make_list [ + M.get_name (| globals, "to_be_paid" |); + M.get_name (| globals, "size_to_extend" |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition calculate_message_call_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "gas"; "to"; "value" ] |) in + let _ := Constant.str " + Calculates the gas amount for executing Opcodes `CALL` and `CALLCODE`. + + Parameters + ---------- + state : + The current state. + gas : + The amount of gas provided to the message-call. + to: + The address of the recipient account. + value: + The amount of `ETH` that needs to be transferred. + + Returns + ------- + message_call_gas: `MessageCallGas` + " in + let create_gas_cost := + (* if *) +M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "to" |) + ], + make_dict [] + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let transfer_gas_cost := + (* if *) +M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let cost := + BinOp.add (| + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_CALL" |), + M.get_name (| globals, "gas" |) + |), + M.get_name (| globals, "create_gas_cost" |) + |), + M.get_name (| globals, "transfer_gas_cost" |) + |) in + let stipend := + (* if *) +M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), +(* then *) +ltac:(M.monadic ( +M.get_name (| globals, "gas" |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallGas" |), + make_list [ + M.get_name (| globals, "cost" |); + M.get_name (| globals, "stipend" |) + ], + make_dict [] + |) + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/homestead/vm/instructions/arithmetic.v index a8b5c61..581ba5d 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/arithmetic.v @@ -273,22 +273,6 @@ Definition div : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let quotient := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let quotient := BinOp.floor_div (| M.get_name (| globals, "dividend" |), @@ -357,32 +341,7 @@ Definition sdiv : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let quotient := - Constant.int 0 in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_name (| globals, "dividend" |), UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "divisor" |), UnOp.sub (| Constant.int 1 |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let quotient := - UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let sign := M.call (| M.get_name (| globals, "get_sign" |), @@ -477,22 +436,6 @@ Definition mod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let remainder := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let remainder := BinOp.mod_ (| M.get_name (| globals, "x" |), @@ -561,16 +504,6 @@ Definition smod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let remainder := - Constant.int 0 in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let remainder := BinOp.mult (| M.call (| @@ -684,22 +617,6 @@ Definition addmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -795,22 +712,6 @@ Definition mulmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -980,16 +881,6 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "byte_num" |), Constant.int 31 |), - (* then *) - ltac:(M.monadic ( - let result := - M.get_name (| globals, "value" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let value_bytes := M.call (| M.get_name (| globals, "bytes" |), @@ -1012,29 +903,13 @@ Definition signextend : Value.t -> Value.t -> M := ], make_dict [] |) - |):(* At expr: unsupported node type: NoneType *) |) in + |) |) in let sign_bit := BinOp.r_shift (| M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), Constant.int 7 |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "sign_bit" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), - make_list [ - M.get_name (| globals, "value_bytes" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let num_bytes_prepend := BinOp.sub (| Constant.int 32, diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/bitwise.v b/CoqOfPython/ethereum/homestead/vm/instructions/bitwise.v index b20a1e5..f38e7aa 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/bitwise.v @@ -285,22 +285,6 @@ Definition get_byte : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "byte_index" |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let extra_bytes_to_right := BinOp.sub (| Constant.int 31, diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/block.v b/CoqOfPython/ethereum/homestead/vm/instructions/block.v index e5fa554..90be45c 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/block.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/block.v @@ -69,24 +69,6 @@ Definition block_hash : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.lt_e (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), M.get_name (| globals, "block_number" |) |), - ltac:(M.monadic ( - Compare.gt (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), BinOp.add (| - M.get_name (| globals, "block_number" |), - Constant.int 256 - |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let hash := - (* At constant: unsupported node type: Constant *) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let hash := M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/comparison.v b/CoqOfPython/ethereum/homestead/vm/instructions/comparison.v index fbc35f8..b8529d8 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/comparison.v @@ -78,7 +78,10 @@ Definition less_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.lt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -145,7 +148,10 @@ Definition signed_less_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.lt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -205,7 +211,10 @@ Definition greater_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.gt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -272,7 +281,10 @@ Definition signed_greater_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.gt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -332,7 +344,10 @@ Definition equal : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.eq (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.eq (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -384,7 +399,10 @@ Definition is_zero : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.eq (| M.get_name (| globals, "x" |), Constant.int 0 |) + Compare.eq (| + M.get_name (| globals, "x" |), + Constant.int 0 + |) ], make_dict [] |) in diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/control_flow.v b/CoqOfPython/ethereum/homestead/vm/instructions/control_flow.v index 04a79d9..d4e4eae 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/control_flow.v @@ -109,15 +109,6 @@ Definition jump : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -177,29 +168,7 @@ Definition jumpi : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "conditional_value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let destination := - BinOp.add (| - M.get_field (| M.get_name (| globals, "evm" |), "pc" |), - Constant.int 1 - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let destination := M.get_name (| globals, "jump_dest" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/environment.v b/CoqOfPython/ethereum/homestead/vm/instructions/environment.v index 4d26a46..366e59a 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/environment.v @@ -492,7 +492,7 @@ Definition calldatacopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -660,7 +660,7 @@ Definition codecopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -903,7 +903,7 @@ Definition extcodecopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/keccak.v b/CoqOfPython/ethereum/homestead/vm/instructions/keccak.v index cab9ffb..2c4b10e 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/keccak.v @@ -137,7 +137,7 @@ Definition keccak : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/log.v b/CoqOfPython/ethereum/homestead/vm/instructions/log.v index f246f9d..ab196bc 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/log.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/log.v @@ -153,7 +153,7 @@ Definition log_n : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/memory.v b/CoqOfPython/ethereum/homestead/vm/instructions/memory.v index 1e1c8b0..86ba742 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/memory.v @@ -121,7 +121,7 @@ Definition mstore : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -203,7 +203,7 @@ Definition mstore8 : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -288,7 +288,7 @@ Definition mload : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/stack.v b/CoqOfPython/ethereum/homestead/vm/instructions/stack.v index 1eeda05..305af15 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/stack.v @@ -188,13 +188,16 @@ Definition dup_n : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] - |) |); + Compare.lt (| + M.get_name (| globals, "item_number" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + |); M.get_name (| globals, "StackUnderflowError" |) ], make_dict [] @@ -260,13 +263,16 @@ Definition swap_n : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] - |) |); + Compare.lt (| + M.get_name (| globals, "item_number" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + |); M.get_name (| globals, "StackUnderflowError" |) ], make_dict [] diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/storage.v b/CoqOfPython/ethereum/homestead/vm/instructions/storage.v index 4292e3b..5250214 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/storage.v @@ -146,44 +146,11 @@ Definition sstore : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "new_value" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let gas_cost := - M.get_name (| globals, "GAS_STORAGE_SET" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let gas_cost := M.get_name (| globals, "GAS_STORAGE_UPDATE" |) in M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_name (| globals, "new_value" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), - M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/system.v b/CoqOfPython/ethereum/homestead/vm/instructions/system.v index 335986d..d3dc734 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/system.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/system.v @@ -157,7 +157,7 @@ Definition create : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -189,96 +189,7 @@ Definition create : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.lt (| M.get_field (| M.get_name (| globals, "sender" |), "balance" |), M.get_name (| globals, "endowment" |) |), - ltac:(M.monadic ( - BoolOp.or (| - Compare.eq (| M.get_field (| M.get_name (| globals, "sender" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - BinOp.sub (| - BinOp.pow (| - Constant.int 2, - Constant.int 64 - |), - Constant.int 1 - |) - ], - make_dict [] - |) |), - ltac:(M.monadic ( - Compare.gt (| BinOp.add (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "depth" |), - Constant.int 1 - |), M.get_name (| globals, "STACK_DEPTH_LIMIT" |) |) - )) - |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "push" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |); - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) - ], - make_dict [] - |) in - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), - M.get_name (| globals, "create_message_gas" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_has_code_or_nonce" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); - M.get_name (| globals, "contract_address" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "increment_nonce" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) - ], - make_dict [] - |) in - let _ := M.call (| - M.get_name (| globals, "push" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |); - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let call_data := M.call (| M.get_name (| globals, "memory_read_bytes" |), @@ -313,36 +224,6 @@ Definition create : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "child_evm" |), "error" |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "incorporate_child_on_error" |), - make_list [ - M.get_name (| globals, "evm" |); - M.get_name (| globals, "child_evm" |) - ], - make_dict [] - |) in - let _ := M.call (| - M.get_name (| globals, "push" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |); - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "incorporate_child_on_success" |), make_list [ @@ -431,7 +312,7 @@ Definition return_ : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -462,39 +343,6 @@ Definition generic_call : Value.t -> Value.t -> M := " in (* At stmt: unsupported node type: ImportFrom *) let _ := - (* if *) - M.if_then_else (| - Compare.gt (| BinOp.add (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "depth" |), - Constant.int 1 - |), M.get_name (| globals, "STACK_DEPTH_LIMIT" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), - M.get_name (| globals, "gas" |) - |) in - let _ := M.call (| - M.get_name (| globals, "push" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |); - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) - ], - make_dict [] - |) in - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let call_data := @@ -532,36 +380,6 @@ Definition generic_call : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "child_evm" |), "error" |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "incorporate_child_on_error" |), - make_list [ - M.get_name (| globals, "evm" |); - M.get_name (| globals, "child_evm" |) - ], - make_dict [] - |) in - let _ := M.call (| - M.get_name (| globals, "push" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |); - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "incorporate_child_on_success" |), make_list [ @@ -612,7 +430,7 @@ Definition generic_call : Value.t -> Value.t -> M := make_list [ M.get_field (| M.get_name (| globals, "evm" |), "memory" |); M.get_name (| globals, "memory_output_start_position" |); - M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), (* At expr: unsupported node type: NoneType *):M.get_name (| globals, "actual_output_size" |) |) + M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), Constant.None_:M.get_name (| globals, "actual_output_size" |) |) ], make_dict [] |) in @@ -735,7 +553,7 @@ Definition call : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -749,33 +567,6 @@ Definition call : Value.t -> Value.t -> M := make_dict [] |), "balance" |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "sender_balance" |), M.get_name (| globals, "value" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "push" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |); - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) - ], - make_dict [] - |) in - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), - M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "generic_call" |), make_list [ @@ -921,7 +712,7 @@ Definition callcode : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -935,33 +726,6 @@ Definition callcode : Value.t -> Value.t -> M := make_dict [] |), "balance" |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "sender_balance" |), M.get_name (| globals, "value" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "push" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |); - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) - ], - make_dict [] - |) in - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), - M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "generic_call" |), make_list [ @@ -1021,7 +785,10 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in let parent_evm := M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "parent_evm" |) in - While Compare.is_not (| M.get_name (| globals, "parent_evm" |), Constant.None_ |) do + While Compare.is_not (| + M.get_name (| globals, "parent_evm" |), + Constant.None_ + |) do let _ := M.call (| M.get_field (| M.get_name (| globals, "refunded_accounts" |), "update" |), make_list [ @@ -1033,19 +800,6 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in EndWhile. let _ := - (* if *) - M.if_then_else (| - Compare.not_in (| M.get_name (| globals, "originator" |), M.get_name (| globals, "refunded_accounts" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), - M.get_name (| globals, "REFUND_SELF_DESTRUCT" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -1216,7 +970,7 @@ Definition delegatecall : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/homestead/vm/interpreter.v b/CoqOfPython/ethereum/homestead/vm/interpreter.v index b4e4a21..9a84535 100644 --- a/CoqOfPython/ethereum/homestead/vm/interpreter.v +++ b/CoqOfPython/ethereum/homestead/vm/interpreter.v @@ -162,86 +162,6 @@ Definition process_message_call : Value.t -> Value.t -> M := Output of the message call " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_name (| globals, "message" |), "target" |), M.call (| - M.get_name (| globals, "Bytes0" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let is_collision := - M.call (| - M.get_name (| globals, "account_has_code_or_nonce" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_field (| M.get_name (| globals, "message" |), "current_target" |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - M.get_name (| globals, "is_collision" |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "MessageCallOutput" |), - make_list [ - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |); - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |); - M.call (| - M.get_name (| globals, "tuple" |), - make_list [], - make_dict [] - |); - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |); - M.call (| - M.get_name (| globals, "AddressCollision" |), - make_list [], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let evm := - M.call (| - M.get_name (| globals, "process_create_message" |), - make_list [ - M.get_name (| globals, "message" |); - M.get_name (| globals, "env" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let evm := M.call (| M.get_name (| globals, "process_message" |), @@ -254,29 +174,6 @@ Definition process_message_call : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "evm" |), "error" |), - (* then *) - ltac:(M.monadic ( -(* At stmt: unsupported node type: AnnAssign *) - let accounts_to_delete := - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |) in - let refund_counter := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let logs := M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in let accounts_to_delete := @@ -312,7 +209,6 @@ Definition process_message_call : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). Definition process_create_message : Value.t -> Value.t -> M := @@ -358,28 +254,6 @@ Definition process_create_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), - (* then *) - ltac:(M.monadic ( - let contract_code := - M.get_field (| M.get_name (| globals, "evm" |), "output" |) in - let contract_code_gas := - BinOp.mult (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "contract_code" |) - ], - make_dict [] - |), - M.get_name (| globals, "GAS_CODE_DEPOSIT" |) - |) in -(* At stmt: unsupported node type: Try *) - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "rollback_transaction" |), make_list [ @@ -391,7 +265,6 @@ Definition process_create_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) - |) in M.pure Constant.None_)). Definition process_message : Value.t -> Value.t -> M := @@ -413,21 +286,6 @@ Definition process_message : Value.t -> Value.t -> M := Items containing execution specific objects " in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_field (| M.get_name (| globals, "message" |), "depth" |), M.get_name (| globals, "STACK_DEPTH_LIMIT" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "StackDepthLimitError" |), - make_list [ - Constant.str "Stack depth limit reached" - ], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -446,29 +304,6 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - M.get_field (| M.get_name (| globals, "message" |), "should_transfer_value" |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_field (| M.get_name (| globals, "message" |), "value" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "move_ether" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_field (| M.get_name (| globals, "message" |), "caller" |); - M.get_field (| M.get_name (| globals, "message" |), "current_target" |); - M.get_field (| M.get_name (| globals, "message" |), "value" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let evm := @@ -481,21 +316,6 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "evm" |), "error" |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "rollback_transaction" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "commit_transaction" |), make_list [ @@ -507,7 +327,6 @@ Definition process_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) - |) in M.pure Constant.None_)). Definition execute_code : Value.t -> Value.t -> M := @@ -547,5 +366,4 @@ Definition execute_code : Value.t -> Value.t -> M := (* At stmt: unsupported node type: Try *) let _ := M.return_ (| M.get_name (| globals, "evm" |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/vm/memory.v b/CoqOfPython/ethereum/homestead/vm/memory.v index fa8d906..4b107fd 100644 --- a/CoqOfPython/ethereum/homestead/vm/memory.v +++ b/CoqOfPython/ethereum/homestead/vm/memory.v @@ -45,22 +45,7 @@ Definition memory_write : Value.t -> Value.t -> M := Data to write to memory. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) - |) |), + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_)). @@ -86,23 +71,7 @@ Definition memory_read_bytes : Value.t -> Value.t -> M := Data read from memory. " in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |) - |) in + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |) M.pure Constant.None_)). Definition buffer_read : Value.t -> Value.t -> M := @@ -129,25 +98,9 @@ Definition buffer_read : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "right_pad_zero_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |); + M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |) |); M.get_name (| globals, "size" |) ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/ecrecover.v index cc351b5..0cbcf16 100644 --- a/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/ecrecover.v @@ -188,60 +188,12 @@ Definition ecrecover : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 27 |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 28 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| Constant.int 0, M.get_name (| globals, "r" |) |), - ltac:(M.monadic ( - Compare.gt_e (| M.get_name (| globals, "r" |), M.get_name (| globals, "SECP256K1N" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| Constant.int 0, M.get_name (| globals, "s" |) |), - ltac:(M.monadic ( - Compare.gt_e (| M.get_name (| globals, "s" |), M.get_name (| globals, "SECP256K1N" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: Try *) @@ -252,7 +204,7 @@ Definition ecrecover : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12:Constant.int 32 |) in + |), Constant.int 12 |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/homestead/vm/runtime.v b/CoqOfPython/ethereum/homestead/vm/runtime.v index 835b46c..2cd7652 100644 --- a/CoqOfPython/ethereum/homestead/vm/runtime.v +++ b/CoqOfPython/ethereum/homestead/vm/runtime.v @@ -67,50 +67,19 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := ], make_dict [] |) in - While Compare.lt (| M.get_name (| globals, "pc" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "code" |) - ], - make_dict [] - |) |) do + While Compare.lt (| + M.get_name (| globals, "pc" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) + |) do (* At stmt: unsupported node type: Try *) let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "current_opcode" |), M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), - make_list [ - M.get_name (| globals, "pc" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - (* At expr: unsupported node type: Compare *), - (* then *) - ltac:(M.monadic ( - let push_data_size := - BinOp.add (| - BinOp.sub (| - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) - |), - Constant.int 1 - |) in - let pc := BinOp.add - M.get_name (| globals, "push_data_size" |) - M.get_name (| globals, "push_data_size" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -121,5 +90,4 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := EndWhile. let _ := M.return_ (| M.get_name (| globals, "valid_jump_destinations" |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/vm/stack.v b/CoqOfPython/ethereum/homestead/vm/stack.v index 42ea42d..ea778df 100644 --- a/CoqOfPython/ethereum/homestead/vm/stack.v +++ b/CoqOfPython/ethereum/homestead/vm/stack.v @@ -49,21 +49,6 @@ Definition pop : Value.t -> Value.t -> M := " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "stack" |) - ], - make_dict [] - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "StackUnderflowError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -72,7 +57,6 @@ Definition pop : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). Definition push : Value.t -> Value.t -> M := @@ -91,21 +75,6 @@ Definition push : Value.t -> Value.t -> M := " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "stack" |) - ], - make_dict [] - |), Constant.int 1024 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "StackOverflowError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -116,5 +85,4 @@ Definition push : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/bloom.v b/CoqOfPython/ethereum/istanbul/bloom.v index 04b5d9f..04650ff 100644 --- a/CoqOfPython/ethereum/istanbul/bloom.v +++ b/CoqOfPython/ethereum/istanbul/bloom.v @@ -72,10 +72,7 @@ Definition add_to_bloom : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |):BinOp.add (| - M.get_name (| globals, "idx" |), - Constant.int 2 - |) |) + M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |) |) ], make_dict [] |), @@ -160,5 +157,4 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/fork.v b/CoqOfPython/ethereum/istanbul/fork.v new file mode 100644 index 0000000..bd55602 --- /dev/null +++ b/CoqOfPython/ethereum/istanbul/fork.v @@ -0,0 +1,2160 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Specification +^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Entry point for the Ethereum specification. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". + +Require ethereum.crypto.elliptic_curve. +Axiom ethereum_crypto_elliptic_curve_SECP256K1N : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.ethash. +Axiom ethereum_ethash_dataset_size : + IsGlobalAlias globals ethereum.ethash.globals "dataset_size". +Axiom ethereum_ethash_generate_cache : + IsGlobalAlias globals ethereum.ethash.globals "generate_cache". +Axiom ethereum_ethash_hashimoto_light : + IsGlobalAlias globals ethereum.ethash.globals "hashimoto_light". + +Require ethereum.exceptions. +Axiom ethereum_exceptions_InvalidBlock : + IsGlobalAlias globals ethereum.exceptions.globals "InvalidBlock". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U64 : + IsGlobalAlias globals base_types.globals "U64". +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_U256_CEIL_VALUE : + IsGlobalAlias globals base_types.globals "U256_CEIL_VALUE". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". + +Require __init__. +Axiom __init___vm : + IsGlobalAlias globals __init__.globals "vm". + +Require blocks. +Axiom blocks_Block : + IsGlobalAlias globals blocks.globals "Block". +Axiom blocks_Header : + IsGlobalAlias globals blocks.globals "Header". +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". +Axiom blocks_Receipt : + IsGlobalAlias globals blocks.globals "Receipt". + +Require bloom. +Axiom bloom_logs_bloom : + IsGlobalAlias globals bloom.globals "logs_bloom". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Require state. +Axiom state_State : + IsGlobalAlias globals state.globals "State". +Axiom state_account_exists_and_is_empty : + IsGlobalAlias globals state.globals "account_exists_and_is_empty". +Axiom state_create_ether : + IsGlobalAlias globals state.globals "create_ether". +Axiom state_destroy_account : + IsGlobalAlias globals state.globals "destroy_account". +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". +Axiom state_increment_nonce : + IsGlobalAlias globals state.globals "increment_nonce". +Axiom state_set_account_balance : + IsGlobalAlias globals state.globals "set_account_balance". +Axiom state_state_root : + IsGlobalAlias globals state.globals "state_root". + +Require transactions. +Axiom transactions_TX_BASE_COST : + IsGlobalAlias globals transactions.globals "TX_BASE_COST". +Axiom transactions_TX_CREATE_COST : + IsGlobalAlias globals transactions.globals "TX_CREATE_COST". +Axiom transactions_TX_DATA_COST_PER_NON_ZERO : + IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_NON_ZERO". +Axiom transactions_TX_DATA_COST_PER_ZERO : + IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_ZERO". +Axiom transactions_Transaction : + IsGlobalAlias globals transactions.globals "Transaction". + +Require trie. +Axiom trie_Trie : + IsGlobalAlias globals trie.globals "Trie". +Axiom trie_root : + IsGlobalAlias globals trie.globals "root". +Axiom trie_trie_set : + IsGlobalAlias globals trie.globals "trie_set". + +Require utils.message. +Axiom utils_message_prepare_message : + IsGlobalAlias globals utils.message.globals "prepare_message". + +Require vm.interpreter. +Axiom vm_interpreter_process_message_call : + IsGlobalAlias globals vm.interpreter.globals "process_message_call". + +Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mult (| + Constant.int 2, + BinOp.pow (| + Constant.int 10, + Constant.int 18 + |) + |) + ], + make_dict [] + |) +)). + +Definition GAS_LIMIT_ADJUSTMENT_FACTOR : Value.t := M.run ltac:(M.monadic ( + Constant.int 1024 +)). + +Definition GAS_LIMIT_MINIMUM : Value.t := M.run ltac:(M.monadic ( + Constant.int 5000 +)). + +Definition MINIMUM_DIFFICULTY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 131072 + ], + make_dict [] + |) +)). + +Definition MAX_OMMER_DEPTH : Value.t := M.run ltac:(M.monadic ( + Constant.int 6 +)). + +Definition BOMB_DELAY_BLOCKS : Value.t := M.run ltac:(M.monadic ( + Constant.int 5000000 +)). + +Definition EMPTY_OMMER_HASH : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_list [] + ], + make_dict [] + |) + ], + make_dict [] + |) +)). + +Definition BlockChain : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition apply_fork : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "old" ] |) in + let _ := Constant.str " + Transforms the state from the previous hard fork (`old`) into the block + chain object for this hard fork and returns it. + + When forks need to implement an irregular state transition, this function + is used to handle the irregularity. See the :ref:`DAO Fork ` for + an example. + + Parameters + ---------- + old : + Previous block chain object. + + Returns + ------- + new : `BlockChain` + Upgraded block chain object for this hard fork. + " in + let _ := M.return_ (| + M.get_name (| globals, "old" |) + M.pure Constant.None_)). + +Definition get_last_256_block_hashes : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "chain" ] |) in + let _ := Constant.str " + Obtain the list of hashes of the previous 256 blocks in order of + increasing block number. + + This function will return less hashes for the first 256 blocks. + + The ``BLOCKHASH`` opcode needs to access the latest hashes on the chain, + therefore this function retrieves them. + + Parameters + ---------- + chain : + History and current state. + + Returns + ------- + recent_block_hashes : `List[Hash32]` + Hashes of the recent 256 blocks in order of increasing block number. + " in + let recent_blocks := + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |) |) in + let _ := + M.pure Constant.None_ + )) |) in + let recent_block_hashes := + make_list [] in + For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_blocks" |) do + let prev_block_hash := + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), + make_list [ + M.get_name (| globals, "prev_block_hash" |) + ], + make_dict [] + |) in + EndFor. + let most_recent_block_hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_field (| M.get_subscript (| M.get_name (| globals, "recent_blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), + make_list [ + M.get_name (| globals, "most_recent_block_hash" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "recent_block_hashes" |) + M.pure Constant.None_)). + +Definition state_transition : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "chain"; "block" ] |) in + let _ := Constant.str " + Attempts to apply a block to an existing block chain. + + All parts of the block's contents need to be verified before being added + to the chain. Blocks are verified by ensuring that the contents of the + block make logical sense with the contents of the parent block. The + information in the block's header must also match the corresponding + information in the block. + + To implement Ethereum, in theory clients are only required to store the + most recent 255 blocks of the chain since as far as execution is + concerned, only those blocks are accessed. Practically, however, clients + should store more blocks to handle reorgs. + + Parameters + ---------- + chain : + History and current state. + block : + Block to apply to `chain`. + " in + let parent_header := + M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) in + let _ := M.call (| + M.get_name (| globals, "validate_header" |), + make_list [ + M.get_field (| M.get_name (| globals, "block" |), "header" |); + M.get_name (| globals, "parent_header" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "validate_ommers" |), + make_list [ + M.get_field (| M.get_name (| globals, "block" |), "ommers" |); + M.get_field (| M.get_name (| globals, "block" |), "header" |); + M.get_name (| globals, "chain" |) + ], + make_dict [] + |) in + let apply_body_output := + M.call (| + M.get_name (| globals, "apply_body" |), + make_list [ + M.get_field (| M.get_name (| globals, "chain" |), "state" |); + M.call (| + M.get_name (| globals, "get_last_256_block_hashes" |), + make_list [ + M.get_name (| globals, "chain" |) + ], + make_dict [] + |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "coinbase" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "number" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "gas_limit" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "timestamp" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "difficulty" |); + M.get_field (| M.get_name (| globals, "block" |), "transactions" |); + M.get_field (| M.get_name (| globals, "block" |), "ommers" |); + M.get_field (| M.get_name (| globals, "chain" |), "chain_id" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_gas_used" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "gas_used" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "transactions_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "transactions_root" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "state_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "state_root" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "receipt_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "receipt_root" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_logs_bloom" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "bloom" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), "append" |), + make_list [ + M.get_name (| globals, "block" |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition validate_header : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header"; "parent_header" ] |) in + let _ := Constant.str " + Verifies a block header. + + In order to consider a block's header valid, the logic for the + quantities in the header should match the logic for the block itself. + For example the header timestamp should be greater than the block's parent + timestamp because the block was created *after* the parent block. + Additionally, the block's number should be directly following the parent + block's number since it is the next block in the sequence. + + Parameters + ---------- + header : + Header to check for correctness. + parent_header : + Parent Header of the header to check for correctness + " in + let parent_has_ommers := + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "parent_header" |), "ommers_hash" |), + M.get_name (| globals, "EMPTY_OMMER_HASH" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt (| + M.get_field (| M.get_name (| globals, "header" |), "timestamp" |), + M.get_field (| M.get_name (| globals, "parent_header" |), "timestamp" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "number" |), + BinOp.add (| + M.get_field (| M.get_name (| globals, "parent_header" |), "number" |), + Constant.int 1 + |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + M.call (| + M.get_name (| globals, "check_gas_limit" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "gas_limit" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "gas_limit" |) + ], + make_dict [] + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) + ], + make_dict [] + |), + Constant.int 32 + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let block_difficulty := + M.call (| + M.get_name (| globals, "calculate_block_difficulty" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "number" |); + M.get_field (| M.get_name (| globals, "header" |), "timestamp" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "timestamp" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "difficulty" |); + M.get_name (| globals, "parent_has_ommers" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "difficulty" |), + M.get_name (| globals, "block_difficulty" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let block_parent_hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "parent_header" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |), + M.get_name (| globals, "block_parent_hash" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "validate_proof_of_work" |), + make_list [ + M.get_name (| globals, "header" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header" ] |) in + let _ := Constant.str " + Generate rlp hash of the header which is to be used for Proof-of-Work + verification. + + In other words, the PoW artefacts `mix_digest` and `nonce` are ignored + while calculating this hash. + + A particular PoW is valid for a single hash, that hash is computed by + this function. The `nonce` and `mix_digest` are omitted from this hash + because they are being changed by miners in their search for a sufficient + proof-of-work. + + Parameters + ---------- + header : + The header object for which the hash is to be generated. + + Returns + ------- + hash : `Hash32` + The PoW valid rlp hash of the passed in header. + " in + let header_data_without_pow_artefacts := + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |); + M.get_field (| M.get_name (| globals, "header" |), "ommers_hash" |); + M.get_field (| M.get_name (| globals, "header" |), "coinbase" |); + M.get_field (| M.get_name (| globals, "header" |), "state_root" |); + M.get_field (| M.get_name (| globals, "header" |), "transactions_root" |); + M.get_field (| M.get_name (| globals, "header" |), "receipt_root" |); + M.get_field (| M.get_name (| globals, "header" |), "bloom" |); + M.get_field (| M.get_name (| globals, "header" |), "difficulty" |); + M.get_field (| M.get_name (| globals, "header" |), "number" |); + M.get_field (| M.get_name (| globals, "header" |), "gas_limit" |); + M.get_field (| M.get_name (| globals, "header" |), "gas_used" |); + M.get_field (| M.get_name (| globals, "header" |), "timestamp" |); + M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) + ] in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "header_data_without_pow_artefacts" |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition validate_proof_of_work : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header" ] |) in + let _ := Constant.str " + Validates the Proof of Work constraints. + + In order to verify that a miner's proof-of-work is valid for a block, a + ``mix-digest`` and ``result`` are calculated using the ``hashimoto_light`` + hash function. The mix digest is a hash of the header and the nonce that + is passed through and it confirms whether or not proof-of-work was done + on the correct block. The result is the actual hash value of the block. + + Parameters + ---------- + header : + Header of interest. + " in + let header_hash := + M.call (| + M.get_name (| globals, "generate_header_hash_for_pow" |), + make_list [ + M.get_name (| globals, "header" |) + ], + make_dict [] + |) in + let cache := + M.call (| + M.get_name (| globals, "generate_cache" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "number" |) + ], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "mix_digest" |); M.get_name (| globals, "result" |) ], + M.call (| + M.get_name (| globals, "hashimoto_light" |), + make_list [ + M.get_name (| globals, "header_hash" |); + M.get_field (| M.get_name (| globals, "header" |), "nonce" |); + M.get_name (| globals, "cache" |); + M.call (| + M.get_name (| globals, "dataset_size" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "number" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_name (| globals, "mix_digest" |), + M.get_field (| M.get_name (| globals, "header" |), "mix_digest" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "result" |) + ], + make_dict [] + |), + BinOp.floor_div (| + M.get_name (| globals, "U256_CEIL_VALUE" |), + M.get_field (| M.get_name (| globals, "header" |), "difficulty" |) + |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition check_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx"; "gas_available"; "chain_id" ] |) in + let _ := Constant.str " + Check if the transaction is includable in the block. + + Parameters + ---------- + tx : + The transaction. + gas_available : + The gas remaining in the block. + chain_id : + The ID of the current chain. + + Returns + ------- + sender_address : + The sender of the transaction. + + Raises + ------ + InvalidBlock : + If the transaction is not includable. + " in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_name (| globals, "gas_available" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let sender_address := + M.call (| + M.get_name (| globals, "recover_sender" |), + make_list [ + M.get_name (| globals, "chain_id" |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "sender_address" |) + M.pure Constant.None_)). + +Definition make_receipt : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx"; "error"; "cumulative_gas_used"; "logs" ] |) in + let _ := Constant.str " + Make the receipt for a transaction that was executed. + + Parameters + ---------- + tx : + The executed transaction. + error : + Error in the top level frame of the transaction, if any. + cumulative_gas_used : + The total gas used so far in the block after the transaction was + executed. + logs : + The logs produced by the transaction. + + Returns + ------- + receipt : + The receipt for the transaction. + " in + let receipt := + M.call (| + M.get_name (| globals, "Receipt" |), + make_list [], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "receipt" |) + M.pure Constant.None_)). + +Definition ApplyBodyOutput : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition apply_body : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "block_hashes"; "coinbase"; "block_number"; "block_gas_limit"; "block_time"; "block_difficulty"; "transactions"; "ommers"; "chain_id" ] |) in + let _ := Constant.str " + Executes a block. + + Many of the contents of a block are stored in data structures called + tries. There is a transactions trie which is similar to a ledger of the + transactions stored in the current block. There is also a receipts trie + which stores the results of executing a transaction, like the post state + and gas used. This function creates and executes the block that is to be + added to the chain. + + Parameters + ---------- + state : + Current account state. + block_hashes : + List of hashes of the previous 256 blocks in the order of + increasing block number. + coinbase : + Address of account which receives block reward and transaction fees. + block_number : + Position of the block within the chain. + block_gas_limit : + Initial amount of gas available for execution in this block. + block_time : + Time the block was produced, measured in seconds since the epoch. + block_difficulty : + Difficulty of the block. + transactions : + Transactions included in the block. + ommers : + Headers of ancestor blocks which are not direct parents (formerly + uncles.) + chain_id : + ID of the executing chain. + + Returns + ------- + apply_body_output : `ApplyBodyOutput` + Output of applying the block body to the state. + " in + let gas_available := + M.get_name (| globals, "block_gas_limit" |) in +(* At stmt: unsupported node type: AnnAssign *) +(* At stmt: unsupported node type: AnnAssign *) +(* At stmt: unsupported node type: AnnAssign *) + For make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "tx" |) ] in M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "transactions" |) + ], + make_dict [] + |) do + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "transactions_trie" |); + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "i" |) + ], + make_dict [] + |) + ], + make_dict [] + |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) in + let sender_address := + M.call (| + M.get_name (| globals, "check_transaction" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "gas_available" |); + M.get_name (| globals, "chain_id" |) + ], + make_dict [] + |) in + let env := + M.call (| + M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |); M.get_name (| globals, "error" |) ], + M.call (| + M.get_name (| globals, "process_transaction" |), + make_list [ + M.get_name (| globals, "env" |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) in + let gas_available := BinOp.sub + M.get_name (| globals, "gas_used" |) + M.get_name (| globals, "gas_used" |) in + let receipt := + M.call (| + M.get_name (| globals, "make_receipt" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "error" |); + BinOp.sub (| + M.get_name (| globals, "block_gas_limit" |), + M.get_name (| globals, "gas_available" |) + |); + M.get_name (| globals, "logs" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "receipts_trie" |); + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "i" |) + ], + make_dict [] + |) + ], + make_dict [] + |); + M.get_name (| globals, "receipt" |) + ], + make_dict [] + |) in + let block_logs := BinOp.add + M.get_name (| globals, "logs" |) + M.get_name (| globals, "logs" |) in + EndFor. + let _ := M.call (| + M.get_name (| globals, "pay_rewards" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "block_number" |); + M.get_name (| globals, "coinbase" |); + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |) in + let block_gas_used := + BinOp.sub (| + M.get_name (| globals, "block_gas_limit" |), + M.get_name (| globals, "gas_available" |) + |) in + let block_logs_bloom := + M.call (| + M.get_name (| globals, "logs_bloom" |), + make_list [ + M.get_name (| globals, "block_logs" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ApplyBodyOutput" |), + make_list [ + M.get_name (| globals, "block_gas_used" |); + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_name (| globals, "transactions_trie" |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_name (| globals, "receipts_trie" |) + ], + make_dict [] + |); + M.get_name (| globals, "block_logs_bloom" |); + M.call (| + M.get_name (| globals, "state_root" |), + make_list [ + M.get_name (| globals, "state" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition validate_ommers : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "ommers"; "block_header"; "chain" ] |) in + let _ := Constant.str " + Validates the ommers mentioned in the block. + + An ommer block is a block that wasn't canonically added to the + blockchain because it wasn't validated as fast as the canonical block + but was mined at the same time. + + To be considered valid, the ommers must adhere to the rules defined in + the Ethereum protocol. The maximum amount of ommers is 2 per block and + there cannot be duplicate ommers in a block. Many of the other ommer + constraints are listed in the in-line comments of this function. + + Parameters + ---------- + ommers : + List of ommers mentioned in the current block. + block_header: + The header of current block. + chain : + History and current state. + " in + let block_hash := + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "block_header" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + M.get_field (| M.get_name (| globals, "block_header" |), "ommers_hash" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.and (| + Compare.lt_e (| + Constant.int 1, + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |), + ltac:(M.monadic ( + Compare.lt (| + M.get_field (| M.get_name (| globals, "ommer" |), "number" |), + M.get_field (| M.get_name (| globals, "block_header" |), "number" |) + |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let ommer_parent_header := + M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), BinOp.sub (| + UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) |), + Constant.int 1 + |) |), "header" |) in + let _ := M.call (| + M.get_name (| globals, "validate_header" |), + make_list [ + M.get_name (| globals, "ommer" |); + M.get_name (| globals, "ommer_parent_header" |) + ], + make_dict [] + |) in + EndFor. + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + Constant.int 2 + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let ommers_hashes := + (* At expr: unsupported node type: ListComp *) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers_hashes" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_name (| globals, "set" |), + make_list [ + M.get_name (| globals, "ommers_hashes" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let recent_canonical_blocks := + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| BinOp.add (| + M.get_name (| globals, "MAX_OMMER_DEPTH" |), + Constant.int 1 + |) |) |) in + let recent_canonical_block_hashes := + (* At expr: unsupported node type: SetComp *) in +(* At stmt: unsupported node type: AnnAssign *) + For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_canonical_blocks" |) do + let recent_ommers_hashes := + M.call (| + M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), + make_list [ + (* At expr: unsupported node type: SetComp *) + ], + make_dict [] + |) in + EndFor. + For make_tuple [ M.get_name (| globals, "ommer_index" |); M.get_name (| globals, "ommer" |) ] in M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |) do + let ommer_hash := + M.get_subscript (| M.get_name (| globals, "ommers_hashes" |), M.get_name (| globals, "ommer_index" |) |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_eq (| + M.get_name (| globals, "ommer_hash" |), + M.get_name (| globals, "block_hash" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_in (| + M.get_name (| globals, "ommer_hash" |), + M.get_name (| globals, "recent_canonical_block_hashes" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_in (| + M.get_name (| globals, "ommer_hash" |), + M.get_name (| globals, "recent_ommers_hashes" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let ommer_age := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.and (| + Compare.lt_e (| + Constant.int 1, + M.get_name (| globals, "ommer_age" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_name (| globals, "ommer_age" |), + M.get_name (| globals, "MAX_OMMER_DEPTH" |) + |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.in (| + M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), + M.get_name (| globals, "recent_canonical_block_hashes" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), + M.get_field (| M.get_name (| globals, "block_header" |), "parent_hash" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_)). + +Definition pay_rewards : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "block_number"; "coinbase"; "ommers" ] |) in + let _ := Constant.str " + Pay rewards to the block miner as well as the ommers miners. + + The miner of the canonical block is rewarded with the predetermined + block reward, ``BLOCK_REWARD``, plus a variable award based off of the + number of ommer blocks that were mined around the same time, and included + in the canonical block's header. An ommer block is a block that wasn't + added to the canonical blockchain because it wasn't validated as fast as + the accepted block but was mined at the same time. Although not all blocks + that are mined are added to the canonical chain, miners are still paid a + reward for their efforts. This reward is called an ommer reward and is + calculated based on the number associated with the ommer block that they + mined. + + Parameters + ---------- + state : + Current account state. + block_number : + Position of the block within the chain. + coinbase : + Address of account which receives block reward and transaction fees. + ommers : + List of ommers mentioned in the current block. + " in + let miner_reward := + BinOp.add (| + M.get_name (| globals, "BLOCK_REWARD" |), + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + BinOp.floor_div (| + M.get_name (| globals, "BLOCK_REWARD" |), + Constant.int 32 + |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "create_ether" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "coinbase" |); + M.get_name (| globals, "miner_reward" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do + let ommer_age := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "block_number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) + ], + make_dict [] + |) in + let ommer_miner_reward := + BinOp.floor_div (| + BinOp.mult (| + BinOp.sub (| + Constant.int 8, + M.get_name (| globals, "ommer_age" |) + |), + M.get_name (| globals, "BLOCK_REWARD" |) + |), + Constant.int 8 + |) in + let _ := M.call (| + M.get_name (| globals, "create_ether" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_field (| M.get_name (| globals, "ommer" |), "coinbase" |); + M.get_name (| globals, "ommer_miner_reward" |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_)). + +Definition process_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "env"; "tx" ] |) in + let _ := Constant.str " + Execute a transaction against the provided environment. + + This function processes the actions needed to execute a transaction. + It decrements the sender's account after calculating the gas fee and + refunds them the proper amount after execution. Calling contracts, + deploying code, and incrementing nonces are all examples of actions that + happen within this function or from a call made within this function. + + Accounts that are marked for deletion are processed and destroyed after + execution. + + Parameters + ---------- + env : + Environment for the Ethereum Virtual Machine. + tx : + Transaction to execute. + + Returns + ------- + gas_left : `ethereum.base_types.U256` + Remaining gas after execution. + logs : `Tuple[ethereum.blocks.Log, ...]` + Logs generated during execution. + " in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + M.call (| + M.get_name (| globals, "validate_transaction" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let sender := + M.get_field (| M.get_name (| globals, "env" |), "origin" |) in + let sender_account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |) in + let gas_fee := + BinOp.mult (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "sender_account" |), "nonce" |), + M.get_field (| M.get_name (| globals, "tx" |), "nonce" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt_e (| + M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), + BinOp.add (| + M.get_name (| globals, "gas_fee" |), + M.get_field (| M.get_name (| globals, "tx" |), "value" |) + |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "sender_account" |), "code" |), + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [], + make_dict [] + |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let gas := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.call (| + M.get_name (| globals, "calculate_intrinsic_cost" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) in + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |) in + let sender_balance_after_gas_fee := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), + M.get_name (| globals, "gas_fee" |) + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |); + M.get_name (| globals, "sender_balance_after_gas_fee" |) + ], + make_dict [] + |) in + let message := + M.call (| + M.get_name (| globals, "prepare_message" |), + make_list [ + M.get_name (| globals, "sender" |); + M.get_field (| M.get_name (| globals, "tx" |), "to" |); + M.get_field (| M.get_name (| globals, "tx" |), "value" |); + M.get_field (| M.get_name (| globals, "tx" |), "data" |); + M.get_name (| globals, "gas" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let output := + M.call (| + M.get_name (| globals, "process_message_call" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let gas_used := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "output" |), "gas_left" |) + |) in + let gas_refund := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + BinOp.floor_div (| + M.get_name (| globals, "gas_used" |), + Constant.int 2 + |); + M.get_field (| M.get_name (| globals, "output" |), "refund_counter" |) + ], + make_dict [] + |) in + let gas_refund_amount := + BinOp.mult (| + BinOp.add (| + M.get_field (| M.get_name (| globals, "output" |), "gas_left" |), + M.get_name (| globals, "gas_refund" |) + |), + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) + |) in + let transaction_fee := + BinOp.mult (| + BinOp.sub (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "output" |), "gas_left" |) + |), + M.get_name (| globals, "gas_refund" |) + |), + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) + |) in + let total_gas_used := + BinOp.sub (| + M.get_name (| globals, "gas_used" |), + M.get_name (| globals, "gas_refund" |) + |) in + let sender_balance_after_refund := + BinOp.add (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |), "balance" |), + M.get_name (| globals, "gas_refund_amount" |) + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |); + M.get_name (| globals, "sender_balance_after_refund" |) + ], + make_dict [] + |) in + let coinbase_balance_after_mining_fee := + BinOp.add (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |), "balance" |), + M.get_name (| globals, "transaction_fee" |) + |) in + let _ := + let _ := + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "accounts_to_delete" |) do + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + EndFor. + For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "touched_accounts" |) do + let _ := + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.return_ (| + make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |); M.get_field (| M.get_name (| globals, "output" |), "error" |) ] + M.pure Constant.None_)). + +Definition validate_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Verifies a transaction. + + The gas in a transaction gets used to pay for the intrinsic cost of + operations, therefore if there is insufficient gas then it would not + be possible to execute a transaction and it will be declared invalid. + + Additionally, the nonce of a transaction must not equal or exceed the + limit defined in `EIP-2681 `_. + In practice, defining the limit as ``2**64-1`` has no impact because + sending ``2**64-1`` transactions is improbable. It's not strictly + impossible though, ``2**64-1`` transactions is the entire capacity of the + Ethereum blockchain at 2022 gas limits for a little over 22 years. + + Parameters + ---------- + tx : + Transaction to validate. + + Returns + ------- + verified : `bool` + True if the transaction can be executed, or False otherwise. + " in + let _ := M.return_ (| + BoolOp.and (| + Compare.lt_e (| + M.call (| + M.get_name (| globals, "calculate_intrinsic_cost" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |), + M.get_field (| M.get_name (| globals, "tx" |), "gas" |) + |), + ltac:(M.monadic ( + Compare.lt (| + M.get_field (| M.get_name (| globals, "tx" |), "nonce" |), + BinOp.sub (| + BinOp.pow (| + Constant.int 2, + Constant.int 64 + |), + Constant.int 1 + |) + |) + )) + |) + M.pure Constant.None_)). + +Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Calculates the gas that is charged before execution is started. + + The intrinsic cost of the transaction is charged before execution has + begun. Functions/operations in the EVM cost money to execute so this + intrinsic cost is for the operations that need to be paid for as part of + the transaction. Data transfer, for example, is part of this intrinsic + cost. It costs ether to send data over the wire and that ether is + accounted for in the intrinsic cost calculated in this function. This + intrinsic cost must be calculated and paid for before execution in order + for all operations to be implemented. + + Parameters + ---------- + tx : + Transaction to compute the intrinsic cost of. + + Returns + ------- + verified : `ethereum.base_types.Uint` + The intrinsic cost of the transaction. + " in + let data_cost := + Constant.int 0 in + For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do + let _ := + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + M.pure Constant.None_ + )) |) in + EndFor. + let _ := + let create_cost := + Constant.int 0 in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "TX_BASE_COST" |), + M.get_name (| globals, "data_cost" |) + |), + M.get_name (| globals, "create_cost" |) + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition recover_sender : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "chain_id"; "tx" ] |) in + let _ := Constant.str " + Extracts the sender address from a transaction. + + The v, r, and s values are the three parts that make up the signature + of a transaction. In order to recover the sender of a transaction the two + components needed are the signature (``v``, ``r``, and ``s``) and the + signing hash of the transaction. The sender's public key can be obtained + with these two values and therefore the sender address can be retrieved. + + Parameters + ---------- + tx : + Transaction of interest. + chain_id : + ID of the executing chain. + + Returns + ------- + sender : `ethereum.fork_types.Address` + The address of the account that signed the transaction. + " in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "v" |); M.get_name (| globals, "r" |); M.get_name (| globals, "s" |) ], + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "v" |); M.get_field (| M.get_name (| globals, "tx" |), "r" |); M.get_field (| M.get_name (| globals, "tx" |), "s" |) ] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.and (| + Compare.lt (| + Constant.int 0, + M.get_name (| globals, "r" |) + |), + ltac:(M.monadic ( + Compare.lt (| + M.get_name (| globals, "r" |), + M.get_name (| globals, "SECP256K1N" |) + |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.and (| + Compare.lt (| + Constant.int 0, + M.get_name (| globals, "s" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_name (| globals, "s" |), + BinOp.floor_div (| + M.get_name (| globals, "SECP256K1N" |), + Constant.int 2 + |) + |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.or (| + Compare.eq (| + M.get_name (| globals, "v" |), + BinOp.add (| + Constant.int 35, + BinOp.mult (| + M.get_name (| globals, "chain_id" |), + Constant.int 2 + |) + |) + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "v" |), + BinOp.add (| + Constant.int 36, + BinOp.mult (| + M.get_name (| globals, "chain_id" |), + Constant.int 2 + |) + |) + |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + BinOp.sub (| + BinOp.sub (| + M.get_name (| globals, "v" |), + Constant.int 35 + |), + BinOp.mult (| + M.get_name (| globals, "chain_id" |), + Constant.int 2 + |) + |); + M.call (| + M.get_name (| globals, "signing_hash_155" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "chain_id" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_subscript (| M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), Constant.int 12 |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition signing_hash_pre155 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Compute the hash of a transaction used in a legacy (pre EIP 155) signature. + + Parameters + ---------- + tx : + Transaction of interest. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the transaction. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "nonce" |); M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |); M.get_field (| M.get_name (| globals, "tx" |), "gas" |); M.get_field (| M.get_name (| globals, "tx" |), "to" |); M.get_field (| M.get_name (| globals, "tx" |), "value" |); M.get_field (| M.get_name (| globals, "tx" |), "data" |) ] + ], + make_dict [] + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition signing_hash_155 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx"; "chain_id" ] |) in + let _ := Constant.str " + Compute the hash of a transaction used in a EIP 155 signature. + + Parameters + ---------- + tx : + Transaction of interest. + chain_id : + The id of the current chain. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the transaction. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "nonce" |); M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |); M.get_field (| M.get_name (| globals, "tx" |), "gas" |); M.get_field (| M.get_name (| globals, "tx" |), "to" |); M.get_field (| M.get_name (| globals, "tx" |), "value" |); M.get_field (| M.get_name (| globals, "tx" |), "data" |); M.get_name (| globals, "chain_id" |); M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) ] + ], + make_dict [] + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition compute_header_hash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header" ] |) in + let _ := Constant.str " + Computes the hash of a block header. + + The header hash of a block is the canonical hash that is used to refer + to a specific block and completely distinguishes a block from another. + + ``keccak256`` is a function that produces a 256 bit hash of any input. + It also takes in any number of bytes as an input and produces a single + hash for them. A hash is a completely unique output for a single input. + So an input corresponds to one unique hash that can be used to identify + the input exactly. + + Prior to using the ``keccak256`` hash function, the header must be + encoded using the Recursive-Length Prefix. See :ref:`rlp`. + RLP encoding the header converts it into a space-efficient format that + allows for easy transfer of data between nodes. The purpose of RLP is to + encode arbitrarily nested arrays of binary data, and RLP is the primary + encoding method used to serialize objects in Ethereum's execution layer. + The only purpose of RLP is to encode structure; encoding specific data + types (e.g. strings, floats) is left up to higher-order protocols. + + Parameters + ---------- + header : + Header of interest. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the header. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "header" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition check_gas_limit : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "gas_limit"; "parent_gas_limit" ] |) in + let _ := Constant.str " + Validates the gas limit for a block. + + The bounds of the gas limit, ``max_adjustment_delta``, is set as the + quotient of the parent block's gas limit and the + ``GAS_LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is + passed through as a parameter is greater than or equal to the *sum* of + the parent's gas and the adjustment delta then the limit for gas is too + high and fails this function's check. Similarly, if the limit is less + than or equal to the *difference* of the parent's gas and the adjustment + delta *or* the predefined ``GAS_LIMIT_MINIMUM`` then this function's + check fails because the gas limit doesn't allow for a sufficient or + reasonable amount of gas to be used on a block. + + Parameters + ---------- + gas_limit : + Gas limit to validate. + + parent_gas_limit : + Gas limit of the parent block. + + Returns + ------- + check : `bool` + True if gas limit constraints are satisfied, False otherwise. + " in + let max_adjustment_delta := + BinOp.floor_div (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) + |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + Constant.bool true + M.pure Constant.None_)). + +Definition calculate_block_difficulty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "block_number"; "block_timestamp"; "parent_timestamp"; "parent_difficulty"; "parent_has_ommers" ] |) in + let _ := Constant.str " + Computes difficulty of a block using its header and parent header. + + The difficulty is determined by the time the block was created after its + parent. The ``offset`` is calculated using the parent block's difficulty, + ``parent_difficulty``, and the timestamp between blocks. This offset is + then added to the parent difficulty and is stored as the ``difficulty`` + variable. If the time between the block and its parent is too short, the + offset will result in a positive number thus making the sum of + ``parent_difficulty`` and ``offset`` to be a greater value in order to + avoid mass forking. But, if the time is long enough, then the offset + results in a negative value making the block less difficult than + its parent. + + The base standard for a block's difficulty is the predefined value + set for the genesis block since it has no parent. So, a block + can't be less difficult than the genesis block, therefore each block's + difficulty is set to the maximum value between the calculated + difficulty and the ``GENESIS_DIFFICULTY``. + + Parameters + ---------- + block_number : + Block number of the block. + block_timestamp : + Timestamp of the block. + parent_timestamp : + Timestamp of the parent block. + parent_difficulty : + difficulty of the parent block. + parent_has_ommers: + does the parent have ommers. + + Returns + ------- + difficulty : `ethereum.base_types.Uint` + Computed difficulty for a block. + " in + let offset := + BinOp.mult (| + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "parent_difficulty" |) + ], + make_dict [] + |), + Constant.int 2048 + |), + M.call (| + M.get_name (| globals, "max" |), + make_list [ + BinOp.sub (| + (* if *) +M.if_then_else (| + M.get_name (| globals, "parent_has_ommers" |), +(* then *) +ltac:(M.monadic ( +Constant.int 2, + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "block_timestamp" |), + M.get_name (| globals, "parent_timestamp" |) + |) + ], + make_dict [] + |), + Constant.int 9 + |) + |); + UnOp.sub (| Constant.int 99 |) + ], + make_dict [] + |) + |) in + let difficulty := + BinOp.add (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "parent_difficulty" |) + ], + make_dict [] + |), + M.get_name (| globals, "offset" |) + |) in + let num_bomb_periods := + BinOp.sub (| + BinOp.floor_div (| + BinOp.sub (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "block_number" |) + ], + make_dict [] + |), + M.get_name (| globals, "BOMB_DELAY_BLOCKS" |) + |), + Constant.int 100000 + |), + Constant.int 2 + |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "max" |), + make_list [ + M.get_name (| globals, "difficulty" |); + M.get_name (| globals, "MINIMUM_DIFFICULTY" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/fork_types.v b/CoqOfPython/ethereum/istanbul/fork_types.v index d12953d..5c7dac3 100644 --- a/CoqOfPython/ethereum/istanbul/fork_types.v +++ b/CoqOfPython/ethereum/istanbul/fork_types.v @@ -98,5 +98,4 @@ Definition encode_account : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/state.v b/CoqOfPython/ethereum/istanbul/state.v index 7b038e5..c3290a6 100644 --- a/CoqOfPython/ethereum/istanbul/state.v +++ b/CoqOfPython/ethereum/istanbul/state.v @@ -126,13 +126,7 @@ Definition begin_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) ], make_dict [] - |); {M.get_name (| globals, "k" |): M.call (| - M.get_name (| globals, "copy_trie" |), - make_list [ - M.get_name (| globals, "t" |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)} ] + |); (* At expr: unsupported node type: DictComp *) ] ], make_dict [] |) in @@ -155,19 +149,6 @@ Definition commit_transaction : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "clear" |), - make_list [], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -193,19 +174,6 @@ Definition rollback_transaction : Value.t -> Value.t -> M := |) |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "clear" |), - make_list [], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -242,27 +210,8 @@ Definition get_account : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "account" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "account" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_ACCOUNT" |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -297,7 +246,6 @@ Definition get_account_optional : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "account" |) - |) in M.pure Constant.None_)). Definition set_account : Value.t -> Value.t -> M := @@ -377,15 +325,6 @@ Definition destroy_storage : Value.t -> Value.t -> M := Address of account whose storage is to be deleted. " in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -448,23 +387,6 @@ Definition get_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let value := @@ -486,7 +408,6 @@ Definition get_storage : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "value" |) - |) in M.pure Constant.None_)). Definition set_storage : Value.t -> Value.t -> M := @@ -507,14 +428,17 @@ Definition set_storage : Value.t -> Value.t -> M := value : `U256` Value to set at the key. " in - let _ := M.assert (| Compare.is_not (| M.call (| - M.get_name (| globals, "trie_get" |), - make_list [ - M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), Constant.None_ |) |) in + let _ := M.assert (| Compare.is_not (| + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + Constant.None_ + |) |) in let trie := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), @@ -524,24 +448,6 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let trie := - M.call (| - M.get_name (| globals, "Trie" |), - make_list [], - make_dict [] - |) in - let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), - M.get_name (| globals, "trie" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -554,15 +460,6 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), {} |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -587,26 +484,8 @@ Definition storage_root : Value.t -> Value.t -> M := " in let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "root" |), - make_list [ - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_TRIE_ROOT" |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -637,7 +516,6 @@ Definition state_root : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition account_exists : Value.t -> Value.t -> M := @@ -659,15 +537,17 @@ Definition account_exists : Value.t -> Value.t -> M := True if account exists in the state trie, False otherwise " in let _ := M.return_ (| - Compare.is_not (| M.call (| - M.get_name (| globals, "get_account_optional" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), Constant.None_ |) - |) in + Compare.is_not (| + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + Constant.None_ + |) M.pure Constant.None_)). Definition account_has_code_or_nonce : Value.t -> Value.t -> M := @@ -700,18 +580,23 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := |) in let _ := M.return_ (| BoolOp.or (| - Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( - Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |) + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |) )) |) - |) in M.pure Constant.None_)). Definition is_account_empty : Value.t -> Value.t -> M := @@ -744,23 +629,31 @@ Definition is_account_empty : Value.t -> Value.t -> M := |) in let _ := M.return_ (| BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |), ltac:(M.monadic ( - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "balance" |), + Constant.int 0 + |) )) |) )) |) - |) in M.pure Constant.None_)). Definition account_exists_and_is_empty : Value.t -> Value.t -> M := @@ -794,28 +687,39 @@ Definition account_exists_and_is_empty : Value.t -> Value.t -> M := |) in let _ := M.return_ (| BoolOp.and (| - Compare.is_not (| M.get_name (| globals, "account" |), Constant.None_ |), + Compare.is_not (| + M.get_name (| globals, "account" |), + Constant.None_ + |), ltac:(M.monadic ( BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |), ltac:(M.monadic ( - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "balance" |), + Constant.int 0 + |) )) |) )) |) )) |) - |) in M.pure Constant.None_)). Definition is_account_alive : Value.t -> Value.t -> M := @@ -846,36 +750,33 @@ Definition is_account_alive : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "account" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.bool false - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| UnOp.not (| BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |), ltac:(M.monadic ( - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "balance" |), + Constant.int 0 + |) )) |) )) |) |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -983,30 +884,6 @@ Definition touch_account : Value.t -> Value.t -> M := The address of the account that need to initialised. " in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "account_exists" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "set_account" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |); - M.get_name (| globals, "EMPTY_ACCOUNT" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -1111,23 +988,6 @@ Definition get_storage_original : Value.t -> Value.t -> M := Key of the storage slot. " in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -1143,22 +1003,6 @@ Definition get_storage_original : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "original_account_trie" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let original_value := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let original_value := M.call (| M.get_name (| globals, "trie_get" |), @@ -1180,5 +1024,4 @@ Definition get_storage_original : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "original_value" |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/trie.v b/CoqOfPython/ethereum/istanbul/trie.v index 3246619..0ae1030 100644 --- a/CoqOfPython/ethereum/istanbul/trie.v +++ b/CoqOfPython/ethereum/istanbul/trie.v @@ -202,96 +202,16 @@ Definition encode_internal_node : Value.t -> Value.t -> M := " in (* At stmt: unsupported node type: AnnAssign *) let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "node" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let unencoded := - (* At constant: unsupported node type: Constant *) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "LeafNode" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let unencoded := - make_tuple [ M.call (| - M.get_name (| globals, "nibble_list_to_compact" |), - make_list [ - M.get_field (| M.get_name (| globals, "node" |), "rest_of_key" |); - Constant.bool true - ], - make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "ExtensionNode" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let unencoded := - make_tuple [ M.call (| - M.get_name (| globals, "nibble_list_to_compact" |), - make_list [ - M.get_field (| M.get_name (| globals, "node" |), "key_segment" |); - Constant.bool false - ], - make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "BranchNode" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let unencoded := - BinOp.add (| - M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), - make_list [ - M.get_field (| M.get_name (| globals, "node" |), "value" |) - ] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.call (| + let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ (* At expr: unsupported node type: JoinedStr *) ], make_dict [] - |) |) in + |)) M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -309,23 +229,6 @@ Definition encode_internal_node : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "encoded" |) - ], - make_dict [] - |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "unencoded" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_name (| globals, "keccak256" |), @@ -334,7 +237,6 @@ Definition encode_internal_node : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -348,83 +250,8 @@ Definition encode_node : Value.t -> Value.t -> M := Currently mostly an unimplemented stub. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "storage_root" |), Constant.None_ |) |) in - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "encode_account" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "storage_root" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - make_tuple [ M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "U256" |) ] - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.call (| - M.get_name (| globals, "cast" |), - make_list [ - M.get_field (| M.get_name (| globals, "rlp" |), "RLP" |); - M.get_name (| globals, "node" |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "Bytes" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "node" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "previous_trie" |), "encode_node" |), @@ -434,7 +261,6 @@ Definition encode_node : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -486,7 +312,6 @@ Definition copy_trie : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition trie_set : Value.t -> Value.t -> M := @@ -508,26 +333,6 @@ Definition trie_set : Value.t -> Value.t -> M := Node to insert at `key`. " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "value" |), M.get_field (| M.get_name (| globals, "trie" |), "default" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "key" |), M.get_field (| M.get_name (| globals, "trie" |), "_data" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), M.get_name (| globals, "value" |) @@ -565,7 +370,6 @@ Definition trie_get : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition common_prefix_length : Value.t -> Value.t -> M := @@ -588,28 +392,6 @@ Definition common_prefix_length : Value.t -> Value.t -> M := make_dict [] |) do let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| M.get_name (| globals, "i" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "b" |) - ], - make_dict [] - |) |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "i" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -621,7 +403,6 @@ Definition common_prefix_length : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition nibble_list_to_compact : Value.t -> Value.t -> M := @@ -667,68 +448,6 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| BinOp.mod_ (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |), - Constant.int 2 - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_name (| globals, "compact" |), "append" |), - make_list [ - BinOp.mult (| - Constant.int 16, - BinOp.mult (| - Constant.int 2, - M.get_name (| globals, "is_leaf" |) - |) - |) - ], - make_dict [] - |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 0; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |); - Constant.int 2 - ], - make_dict [] - |) do - let _ := M.call (| - M.get_field (| M.get_name (| globals, "compact" |), "append" |), - make_list [ - BinOp.add (| - BinOp.mult (| - Constant.int 16, - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) - |), - M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) - |) - ], - make_dict [] - |) in - EndFor. - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ @@ -790,7 +509,6 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition bytes_to_nibble_list : Value.t -> Value.t -> M := @@ -868,7 +586,6 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition _prepare_trie : Value.t -> Value.t -> M := @@ -898,45 +615,6 @@ Definition _prepare_trie : Value.t -> Value.t -> M := make_dict [] |) do let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "value" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in - let address := - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in - let encoded_value := - M.call (| - M.get_name (| globals, "encode_node" |), - make_list [ - M.get_name (| globals, "value" |); - M.call (| - M.get_name (| globals, "get_storage_root" |), - make_list [ - M.get_name (| globals, "address" |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let encoded_value := M.call (| M.get_name (| globals, "encode_node" |), @@ -950,29 +628,16 @@ Definition _prepare_trie : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.not_eq (| M.get_name (| globals, "encoded_value" |), (* At constant: unsupported node type: Constant *) |); + Compare.not_eq (| + M.get_name (| globals, "encoded_value" |), + Constant.bytes "" + |); M.get_name (| globals, "AssertionError" |) ], make_dict [] |) in (* At stmt: unsupported node type: AnnAssign *) let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "trie" |), "secured" |), - (* then *) - ltac:(M.monadic ( - let key := - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let key := M.get_name (| globals, "preimage" |) in M.pure Constant.None_ @@ -990,7 +655,6 @@ Definition _prepare_trie : Value.t -> Value.t -> M := EndFor. let _ := M.return_ (| M.get_name (| globals, "mapped" |) - |) in M.pure Constant.None_)). Definition root : Value.t -> Value.t -> M := @@ -1044,41 +708,6 @@ Definition root : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "root_node" |) - ], - make_dict [] - |) - ], - make_dict [] - |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "root_node" |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -1095,7 +724,6 @@ Definition root : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -1122,23 +750,6 @@ Definition patricialize : Value.t -> Value.t -> M := Root node of `obj`. " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "obj" |) - ], - make_dict [] - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.None_ - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let arbitrary_key := @@ -1156,36 +767,10 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "obj" |) - ], - make_dict [] - |), Constant.int 1 |), - (* then *) - ltac:(M.monadic ( - let leaf := - M.call (| - M.get_name (| globals, "LeafNode" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |); - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) - ], - make_dict [] - |) in - let _ := M.return_ (| - M.get_name (| globals, "leaf" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let substring := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |) |) in let prefix_length := M.call (| M.get_name (| globals, "len" |), @@ -1204,7 +789,7 @@ Definition patricialize : Value.t -> Value.t -> M := M.get_name (| globals, "common_prefix_length" |), make_list [ M.get_name (| globals, "substring" |); - M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) + M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) ], make_dict [] |) @@ -1212,58 +797,10 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.break (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let prefix := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):BinOp.add (| - M.get_name (| globals, "level" |), - M.get_name (| globals, "prefix_length" |) - |) |) in - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "ExtensionNode" |), - make_list [ - M.get_name (| globals, "prefix" |); - M.call (| - M.get_name (| globals, "encode_internal_node" |), - make_list [ - M.call (| - M.get_name (| globals, "patricialize" |), - make_list [ - M.get_name (| globals, "obj" |); - BinOp.add (| - M.get_name (| globals, "level" |), - M.get_name (| globals, "prefix_length" |) - |) - ], - make_dict [] - |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) @@ -1283,44 +820,9 @@ Definition patricialize : Value.t -> Value.t -> M := |) in EndFor. let value := - (* At constant: unsupported node type: Constant *) in + Constant.bytes "" in For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "key" |) - ], - make_dict [] - |), M.get_name (| globals, "level" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); - make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "AssertionError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let value := - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) @@ -1332,26 +834,9 @@ Definition patricialize : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "BranchNode" |), make_list [ - [M.call (| - M.get_name (| globals, "encode_internal_node" |), - make_list [ - M.call (| - M.get_name (| globals, "patricialize" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "branches" |), M.get_name (| globals, "k" |) |); - BinOp.add (| - M.get_name (| globals, "level" |), - Constant.int 1 - |) - ], - make_dict [] - |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)]; + (* At expr: unsupported node type: ListComp *); M.get_name (| globals, "value" |) ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/utils/address.v b/CoqOfPython/ethereum/istanbul/utils/address.v index 22dc0b6..79125fa 100644 --- a/CoqOfPython/ethereum/istanbul/utils/address.v +++ b/CoqOfPython/ethereum/istanbul/utils/address.v @@ -70,11 +70,10 @@ Definition to_address : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), make_list [], make_dict [] - |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) + |), UnOp.sub (| Constant.int 20 |) |) ], make_dict [] |) - |) in M.pure Constant.None_)). Definition compute_contract_address : Value.t -> Value.t -> M := @@ -114,7 +113,7 @@ Definition compute_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -132,7 +131,6 @@ Definition compute_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition compute_create2_contract_address : Value.t -> Value.t -> M := @@ -160,7 +158,7 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := BinOp.add (| BinOp.add (| BinOp.add (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "ff", M.get_name (| globals, "address" |) |), M.get_name (| globals, "salt" |) @@ -182,7 +180,7 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -200,5 +198,4 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/utils/hexadecimal.v b/CoqOfPython/ethereum/istanbul/utils/hexadecimal.v index 0a09964..7db2240 100644 --- a/CoqOfPython/ethereum/istanbul/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/istanbul/utils/hexadecimal.v @@ -66,7 +66,6 @@ Definition hex_to_root : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition hex_to_bloom : Value.t -> Value.t -> M := @@ -105,7 +104,6 @@ Definition hex_to_bloom : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition hex_to_address : Value.t -> Value.t -> M := @@ -151,5 +149,4 @@ Definition hex_to_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/utils/message.v b/CoqOfPython/ethereum/istanbul/utils/message.v index 3a425ec..a66b0f2 100644 --- a/CoqOfPython/ethereum/istanbul/utils/message.v +++ b/CoqOfPython/ethereum/istanbul/utils/message.v @@ -88,105 +88,14 @@ Definition prepare_message : Value.t -> Value.t -> M := Items containing contract creation or message call specific data. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "target" |); - M.get_name (| globals, "Bytes0" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let current_target := - M.call (| - M.get_name (| globals, "compute_contract_address" |), - make_list [ - M.get_name (| globals, "caller" |); - BinOp.sub (| - M.get_field (| M.call (| - M.get_name (| globals, "get_account" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "caller" |) - ], - make_dict [] - |), "nonce" |), - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 1 - ], - make_dict [] - |) - |) - ], - make_dict [] - |) in - let msg_data := - M.call (| - M.get_name (| globals, "Bytes" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |) in - let code := - M.get_name (| globals, "data" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "target" |); - M.get_name (| globals, "Address" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let current_target := - M.get_name (| globals, "target" |) in - let msg_data := - M.get_name (| globals, "data" |) in - let code := - M.get_field (| M.call (| - M.get_name (| globals, "get_account" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "target" |) - ], - make_dict [] - |), "code" |) in - let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "code_address" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let code_address := - M.get_name (| globals, "target" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.call (| + let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "Target must be address or empty bytes" ], make_dict [] - |) |) in + |)) M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -197,5 +106,4 @@ Definition prepare_message : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/vm/__init__.v b/CoqOfPython/ethereum/istanbul/vm/__init__.v index d408aed..25f0a97 100644 --- a/CoqOfPython/ethereum/istanbul/vm/__init__.v +++ b/CoqOfPython/ethereum/istanbul/vm/__init__.v @@ -145,28 +145,6 @@ Definition incorporate_child_on_success : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); - M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -185,57 +163,9 @@ Definition incorporate_child_on_error : Value.t -> Value.t -> M := The child evm to incorporate. " in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "RIPEMD160_ADDRESS" |), M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), - make_list [ - M.get_name (| globals, "RIPEMD160_ADDRESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |), M.get_name (| globals, "RIPEMD160_ADDRESS" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); - M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), - make_list [ - M.get_name (| globals, "RIPEMD160_ADDRESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign_op (| diff --git a/CoqOfPython/ethereum/istanbul/vm/gas.v b/CoqOfPython/ethereum/istanbul/vm/gas.v new file mode 100644 index 0000000..765c5ef --- /dev/null +++ b/CoqOfPython/ethereum/istanbul/vm/gas.v @@ -0,0 +1,841 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Gas +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +EVM gas constants and calculators. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.trace. +Axiom ethereum_trace_GasAndRefund : + IsGlobalAlias globals ethereum.trace.globals "GasAndRefund". +Axiom ethereum_trace_evm_trace : + IsGlobalAlias globals ethereum.trace.globals "evm_trace". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". + +Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) +)). + +Definition GAS_BASE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 2 + ], + make_dict [] + |) +)). + +Definition GAS_VERY_LOW : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_SLOAD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 800 + ], + make_dict [] + |) +)). + +Definition GAS_STORAGE_SET : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 20000 + ], + make_dict [] + |) +)). + +Definition GAS_STORAGE_UPDATE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5000 + ], + make_dict [] + |) +)). + +Definition GAS_STORAGE_CLEAR_REFUND : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 15000 + ], + make_dict [] + |) +)). + +Definition GAS_LOW : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5 + ], + make_dict [] + |) +)). + +Definition GAS_MID : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 8 + ], + make_dict [] + |) +)). + +Definition GAS_HIGH : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 10 + ], + make_dict [] + |) +)). + +Definition GAS_EXPONENTIATION : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 10 + ], + make_dict [] + |) +)). + +Definition GAS_EXPONENTIATION_PER_BYTE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 50 + ], + make_dict [] + |) +)). + +Definition GAS_MEMORY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_KECCAK256 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 30 + ], + make_dict [] + |) +)). + +Definition GAS_KECCAK256_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 6 + ], + make_dict [] + |) +)). + +Definition GAS_COPY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_BLOCK_HASH : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 20 + ], + make_dict [] + |) +)). + +Definition GAS_EXTERNAL : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 700 + ], + make_dict [] + |) +)). + +Definition GAS_BALANCE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 700 + ], + make_dict [] + |) +)). + +Definition GAS_LOG : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 375 + ], + make_dict [] + |) +)). + +Definition GAS_LOG_DATA : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 8 + ], + make_dict [] + |) +)). + +Definition GAS_LOG_TOPIC : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 375 + ], + make_dict [] + |) +)). + +Definition GAS_CREATE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 32000 + ], + make_dict [] + |) +)). + +Definition GAS_CODE_DEPOSIT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 200 + ], + make_dict [] + |) +)). + +Definition GAS_ZERO : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) +)). + +Definition GAS_CALL : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 700 + ], + make_dict [] + |) +)). + +Definition GAS_NEW_ACCOUNT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 25000 + ], + make_dict [] + |) +)). + +Definition GAS_CALL_VALUE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 9000 + ], + make_dict [] + |) +)). + +Definition GAS_CALL_STIPEND : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 2300 + ], + make_dict [] + |) +)). + +Definition GAS_SELF_DESTRUCT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5000 + ], + make_dict [] + |) +)). + +Definition GAS_SELF_DESTRUCT_NEW_ACCOUNT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 25000 + ], + make_dict [] + |) +)). + +Definition REFUND_SELF_DESTRUCT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 24000 + ], + make_dict [] + |) +)). + +Definition GAS_ECRECOVER : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3000 + ], + make_dict [] + |) +)). + +Definition GAS_SHA256 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 60 + ], + make_dict [] + |) +)). + +Definition GAS_SHA256_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 12 + ], + make_dict [] + |) +)). + +Definition GAS_RIPEMD160 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 600 + ], + make_dict [] + |) +)). + +Definition GAS_RIPEMD160_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 120 + ], + make_dict [] + |) +)). + +Definition GAS_IDENTITY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 15 + ], + make_dict [] + |) +)). + +Definition GAS_IDENTITY_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_RETURN_DATA_COPY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_CODE_HASH : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 700 + ], + make_dict [] + |) +)). + +Definition GAS_FAST_STEP : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5 + ], + make_dict [] + |) +)). + +Definition GAS_BLAKE2_PER_ROUND : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) +)). + +Definition ExtendMemory : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition MessageCallGas : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition charge_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "amount" ] |) in + let _ := Constant.str " + Subtracts `amount` from `evm.gas_left`. + + Parameters + ---------- + evm : + The current EVM. + amount : + The amount of gas the current operation requires. + + " in + let _ := M.call (| + M.get_name (| globals, "evm_trace" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "GasAndRefund" |), + make_list [ + M.get_name (| globals, "amount" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + let _ := M.assign_op (| + BinOp.sub, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "amount" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition calculate_memory_gas_cost : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "size_in_bytes" ] |) in + let _ := Constant.str " + Calculates the gas cost for allocating memory + to the smallest multiple of 32 bytes, + such that the allocated size is at least as big as the given size. + + Parameters + ---------- + size_in_bytes : + The size of the data in bytes. + + Returns + ------- + total_gas_cost : `ethereum.base_types.Uint` + The gas cost for storing data in memory. + " in + let size_in_words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "size_in_bytes" |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let linear_cost := + BinOp.mult (| + M.get_name (| globals, "size_in_words" |), + M.get_name (| globals, "GAS_MEMORY" |) + |) in + let quadratic_cost := + BinOp.floor_div (| + BinOp.pow (| + M.get_name (| globals, "size_in_words" |), + Constant.int 2 + |), + Constant.int 512 + |) in + let total_gas_cost := + BinOp.add (| + M.get_name (| globals, "linear_cost" |), + M.get_name (| globals, "quadratic_cost" |) + |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_)). + +Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "memory"; "extensions" ] |) in + let _ := Constant.str " + Calculates the gas amount to extend memory + + Parameters + ---------- + memory : + Memory contents of the EVM. + extensions: + List of extensions to be made to the memory. + Consists of a tuple of start position and size. + + Returns + ------- + extend_memory: `ExtendMemory` + " in + let size_to_extend := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let to_be_paid := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let current_size := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "memory" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + For make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ] in M.get_name (| globals, "extensions" |) do + let _ := + M.pure Constant.None_ + )) |) in + let before_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "current_size" |) + ], + make_dict [] + |) in + let after_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let size_to_extend := BinOp.add + BinOp.sub (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |) + BinOp.sub (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |) in + let already_paid := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "before_size" |) + ], + make_dict [] + |) in + let total_cost := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "after_size" |) + ], + make_dict [] + |) in + let to_be_paid := BinOp.add + BinOp.sub (| + M.get_name (| globals, "total_cost" |), + M.get_name (| globals, "already_paid" |) + |) + BinOp.sub (| + M.get_name (| globals, "total_cost" |), + M.get_name (| globals, "already_paid" |) + |) in + let current_size := + M.get_name (| globals, "after_size" |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ExtendMemory" |), + make_list [ + M.get_name (| globals, "to_be_paid" |); + M.get_name (| globals, "size_to_extend" |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition calculate_message_call_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "value"; "gas"; "gas_left"; "memory_cost"; "extra_gas"; "call_stipend" ] |) in + let _ := Constant.str " + Calculates the MessageCallGas (cost and stipend) for + executing call Opcodes. + + Parameters + ---------- + value: + The amount of `ETH` that needs to be transferred. + gas : + The amount of gas provided to the message-call. + gas_left : + The amount of gas left in the current frame. + memory_cost : + The amount needed to extend the memory in the current frame. + extra_gas : + The amount of gas needed for transferring value + creating a new + account inside a message call. + call_stipend : + The amount of stipend provided to a message call to execute code while + transferring value(ETH). + + Returns + ------- + message_call_gas: `MessageCallGas` + " in + let call_stipend := + (* if *) +M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let gas := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "max_message_call_gas" |), + make_list [ + BinOp.sub (| + BinOp.sub (| + M.get_name (| globals, "gas_left" |), + M.get_name (| globals, "memory_cost" |) + |), + M.get_name (| globals, "extra_gas" |) + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallGas" |), + make_list [ + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "extra_gas" |) + |); + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "call_stipend" |) + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition max_message_call_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "gas" ] |) in + let _ := Constant.str " + Calculates the maximum gas that is allowed for making a message call + + Parameters + ---------- + gas : + The amount of gas provided to the message-call. + + Returns + ------- + max_allowed_message_call_gas: `ethereum.base_types.Uint` + The maximum gas allowed for making the message-call. + " in + let _ := M.return_ (| + BinOp.sub (| + M.get_name (| globals, "gas" |), + BinOp.floor_div (| + M.get_name (| globals, "gas" |), + Constant.int 64 + |) + |) + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/istanbul/vm/instructions/arithmetic.v index a8b5c61..581ba5d 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/arithmetic.v @@ -273,22 +273,6 @@ Definition div : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let quotient := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let quotient := BinOp.floor_div (| M.get_name (| globals, "dividend" |), @@ -357,32 +341,7 @@ Definition sdiv : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let quotient := - Constant.int 0 in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_name (| globals, "dividend" |), UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "divisor" |), UnOp.sub (| Constant.int 1 |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let quotient := - UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let sign := M.call (| M.get_name (| globals, "get_sign" |), @@ -477,22 +436,6 @@ Definition mod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let remainder := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let remainder := BinOp.mod_ (| M.get_name (| globals, "x" |), @@ -561,16 +504,6 @@ Definition smod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let remainder := - Constant.int 0 in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let remainder := BinOp.mult (| M.call (| @@ -684,22 +617,6 @@ Definition addmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -795,22 +712,6 @@ Definition mulmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -980,16 +881,6 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "byte_num" |), Constant.int 31 |), - (* then *) - ltac:(M.monadic ( - let result := - M.get_name (| globals, "value" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let value_bytes := M.call (| M.get_name (| globals, "bytes" |), @@ -1012,29 +903,13 @@ Definition signextend : Value.t -> Value.t -> M := ], make_dict [] |) - |):(* At expr: unsupported node type: NoneType *) |) in + |) |) in let sign_bit := BinOp.r_shift (| M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), Constant.int 7 |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "sign_bit" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), - make_list [ - M.get_name (| globals, "value_bytes" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let num_bytes_prepend := BinOp.sub (| Constant.int 32, diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/bitwise.v b/CoqOfPython/ethereum/istanbul/vm/instructions/bitwise.v index 9f2f382..64cf120 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/bitwise.v @@ -287,22 +287,6 @@ Definition get_byte : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "byte_index" |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let extra_bytes_to_right := BinOp.sub (| Constant.int 31, @@ -382,28 +366,6 @@ Definition bitwise_shl : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - BinOp.mod_ (| - BinOp.l_shift (| - M.get_name (| globals, "value" |), - M.get_name (| globals, "shift" |) - |), - M.get_name (| globals, "U256_CEIL_VALUE" |) - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -465,19 +427,6 @@ Definition bitwise_shr : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), - (* then *) - ltac:(M.monadic ( - let result := - BinOp.r_shift (| - M.get_name (| globals, "value" |), - M.get_name (| globals, "shift" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -543,42 +492,7 @@ Definition bitwise_sar : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), - make_list [ - BinOp.r_shift (| - M.get_name (| globals, "signed_value" |), - M.get_name (| globals, "shift" |) - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "signed_value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/block.v b/CoqOfPython/ethereum/istanbul/vm/instructions/block.v index 26c73a7..f857b79 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/block.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/block.v @@ -69,24 +69,6 @@ Definition block_hash : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.lt_e (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), M.get_name (| globals, "block_number" |) |), - ltac:(M.monadic ( - Compare.gt (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), BinOp.add (| - M.get_name (| globals, "block_number" |), - Constant.int 256 - |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let hash := - (* At constant: unsupported node type: Constant *) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let hash := M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/comparison.v b/CoqOfPython/ethereum/istanbul/vm/instructions/comparison.v index fbc35f8..b8529d8 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/comparison.v @@ -78,7 +78,10 @@ Definition less_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.lt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -145,7 +148,10 @@ Definition signed_less_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.lt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -205,7 +211,10 @@ Definition greater_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.gt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -272,7 +281,10 @@ Definition signed_greater_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.gt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -332,7 +344,10 @@ Definition equal : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.eq (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.eq (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -384,7 +399,10 @@ Definition is_zero : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.eq (| M.get_name (| globals, "x" |), Constant.int 0 |) + Compare.eq (| + M.get_name (| globals, "x" |), + Constant.int 0 + |) ], make_dict [] |) in diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/control_flow.v b/CoqOfPython/ethereum/istanbul/vm/instructions/control_flow.v index 04a79d9..d4e4eae 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/control_flow.v @@ -109,15 +109,6 @@ Definition jump : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -177,29 +168,7 @@ Definition jumpi : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "conditional_value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let destination := - BinOp.add (| - M.get_field (| M.get_name (| globals, "evm" |), "pc" |), - Constant.int 1 - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let destination := M.get_name (| globals, "jump_dest" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/environment.v b/CoqOfPython/ethereum/istanbul/vm/instructions/environment.v index d9b3151..02315c3 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/environment.v @@ -514,7 +514,7 @@ Definition calldatacopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -682,7 +682,7 @@ Definition codecopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -925,7 +925,7 @@ Definition extcodecopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -1096,28 +1096,31 @@ Definition returndatacopy : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt_e (| BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "return_data_start_position" |) - ], - make_dict [] + Compare.lt_e (| + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "return_data_start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) |), M.call (| - M.get_name (| globals, "Uint" |), + M.get_name (| globals, "len" |), make_list [ - M.get_name (| globals, "size" |) + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |) ], make_dict [] |) - |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "return_data" |) - ], - make_dict [] - |) |); + |); M.get_name (| globals, "OutOfBoundsRead" |) ], make_dict [] @@ -1126,15 +1129,12 @@ Definition returndatacopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in let value := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |):BinOp.add (| - M.get_name (| globals, "return_data_start_position" |), - M.get_name (| globals, "size" |) - |) |) in + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |) |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -1193,22 +1193,6 @@ Definition extcodehash : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "account" |), M.get_name (| globals, "EMPTY_ACCOUNT" |) |), - (* then *) - ltac:(M.monadic ( - let codehash := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let codehash := M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/keccak.v b/CoqOfPython/ethereum/istanbul/vm/instructions/keccak.v index cab9ffb..2c4b10e 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/keccak.v @@ -137,7 +137,7 @@ Definition keccak : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/log.v b/CoqOfPython/ethereum/istanbul/vm/instructions/log.v index 4891a4d..e084e59 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/log.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/log.v @@ -161,7 +161,7 @@ Definition log_n : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/memory.v b/CoqOfPython/ethereum/istanbul/vm/instructions/memory.v index 1e1c8b0..86ba742 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/memory.v @@ -121,7 +121,7 @@ Definition mstore : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -203,7 +203,7 @@ Definition mstore8 : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -288,7 +288,7 @@ Definition mload : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/stack.v b/CoqOfPython/ethereum/istanbul/vm/instructions/stack.v index 1eeda05..305af15 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/stack.v @@ -188,13 +188,16 @@ Definition dup_n : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] - |) |); + Compare.lt (| + M.get_name (| globals, "item_number" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + |); M.get_name (| globals, "StackUnderflowError" |) ], make_dict [] @@ -260,13 +263,16 @@ Definition swap_n : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] - |) |); + Compare.lt (| + M.get_name (| globals, "item_number" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + |); M.get_name (| globals, "StackUnderflowError" |) ], make_dict [] diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/storage.v b/CoqOfPython/ethereum/istanbul/vm/instructions/storage.v index 5f4c9f2..e55bb00 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/storage.v @@ -152,7 +152,10 @@ Definition sstore : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.gt (| M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), M.get_name (| globals, "GAS_CALL_STIPEND" |) |); + Compare.gt (| + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "GAS_CALL_STIPEND" |) + |); M.get_name (| globals, "OutOfGasError" |) ], make_dict [] @@ -178,156 +181,11 @@ Definition sstore : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_name (| globals, "original_value" |), M.get_name (| globals, "current_value" |) |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_name (| globals, "current_value" |), M.get_name (| globals, "new_value" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let gas_cost := - M.get_name (| globals, "GAS_STORAGE_SET" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let gas_cost := - M.get_name (| globals, "GAS_STORAGE_UPDATE" |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let gas_cost := M.get_name (| globals, "GAS_SLOAD" |) in M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_eq (| M.get_name (| globals, "current_value" |), M.get_name (| globals, "new_value" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), - ltac:(M.monadic ( - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "new_value" |), Constant.int 0 |) - )) - |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), - M.call (| - M.get_name (| globals, "int" |), - make_list [ - M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.sub, - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), - M.call (| - M.get_name (| globals, "int" |), - make_list [ - M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "original_value" |), M.get_name (| globals, "new_value" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), - M.call (| - M.get_name (| globals, "int" |), - make_list [ - BinOp.sub (| - M.get_name (| globals, "GAS_STORAGE_SET" |), - M.get_name (| globals, "GAS_SLOAD" |) - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), - M.call (| - M.get_name (| globals, "int" |), - make_list [ - BinOp.sub (| - M.get_name (| globals, "GAS_STORAGE_UPDATE" |), - M.get_name (| globals, "GAS_SLOAD" |) - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/system.v b/CoqOfPython/ethereum/istanbul/vm/instructions/system.v new file mode 100644 index 0000000..b850f84 --- /dev/null +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/system.v @@ -0,0 +1,1598 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) System Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM system related instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_account_exists_and_is_empty : + IsGlobalAlias globals state.globals "account_exists_and_is_empty". +Axiom state_account_has_code_or_nonce : + IsGlobalAlias globals state.globals "account_has_code_or_nonce". +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". +Axiom state_increment_nonce : + IsGlobalAlias globals state.globals "increment_nonce". +Axiom state_is_account_alive : + IsGlobalAlias globals state.globals "is_account_alive". +Axiom state_set_account_balance : + IsGlobalAlias globals state.globals "set_account_balance". + +Require utils.address. +Axiom utils_address_compute_contract_address : + IsGlobalAlias globals utils.address.globals "compute_contract_address". +Axiom utils_address_compute_create2_contract_address : + IsGlobalAlias globals utils.address.globals "compute_create2_contract_address". +Axiom utils_address_to_address : + IsGlobalAlias globals utils.address.globals "to_address". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". +Axiom __init___Message : + IsGlobalAlias globals __init__.globals "Message". +Axiom __init___incorporate_child_on_error : + IsGlobalAlias globals __init__.globals "incorporate_child_on_error". +Axiom __init___incorporate_child_on_success : + IsGlobalAlias globals __init__.globals "incorporate_child_on_success". + +Require exceptions. +Axiom exceptions_Revert : + IsGlobalAlias globals exceptions.globals "Revert". +Axiom exceptions_WriteInStaticContext : + IsGlobalAlias globals exceptions.globals "WriteInStaticContext". + +Require gas. +Axiom gas_GAS_CALL : + IsGlobalAlias globals gas.globals "GAS_CALL". +Axiom gas_GAS_CALL_VALUE : + IsGlobalAlias globals gas.globals "GAS_CALL_VALUE". +Axiom gas_GAS_CREATE : + IsGlobalAlias globals gas.globals "GAS_CREATE". +Axiom gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". +Axiom gas_GAS_NEW_ACCOUNT : + IsGlobalAlias globals gas.globals "GAS_NEW_ACCOUNT". +Axiom gas_GAS_SELF_DESTRUCT : + IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT". +Axiom gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : + IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". +Axiom gas_GAS_ZERO : + IsGlobalAlias globals gas.globals "GAS_ZERO". +Axiom gas_REFUND_SELF_DESTRUCT : + IsGlobalAlias globals gas.globals "REFUND_SELF_DESTRUCT". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_calculate_message_call_gas : + IsGlobalAlias globals gas.globals "calculate_message_call_gas". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". +Axiom gas_max_message_call_gas : + IsGlobalAlias globals gas.globals "max_message_call_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". +Axiom memory_memory_write : + IsGlobalAlias globals memory.globals "memory_write". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition generic_create : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "endowment"; "contract_address"; "memory_start_position"; "memory_size" ] |) in + let _ := Constant.str " + Core logic used by the `CREATE*` family of opcodes. + " in +(* At stmt: unsupported node type: ImportFrom *) + let create_message_gas := + M.call (| + M.get_name (| globals, "max_message_call_gas" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.sub, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "create_message_gas" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let sender_address := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in + let sender := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "sender_address" |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := + M.pure Constant.None_ + )) |) in + let call_data := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + let child_message := + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) in + let child_evm := + M.call (| + M.get_name (| globals, "process_create_message" |), + make_list [ + M.get_name (| globals, "child_message" |); + M.get_field (| M.get_name (| globals, "evm" |), "env" |) + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_success" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition create : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Creates a new account with associated code. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let endowment := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_position" |); M.get_name (| globals, "memory_size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_CREATE" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let contract_address := + M.call (| + M.get_name (| globals, "compute_contract_address" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "nonce" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "generic_create" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "endowment" |); + M.get_name (| globals, "contract_address" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition create2 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Creates a new account with associated code. + + It's similar to CREATE opcode except that the address of new account + depends on the init_code instead of the nonce of sender. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let endowment := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let salt := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_position" |); M.get_name (| globals, "memory_size" |) ] + ] + ], + make_dict [] + |) in + let call_data_words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_CREATE" |), + BinOp.mult (| + M.get_name (| globals, "GAS_KECCAK256_WORD" |), + M.get_name (| globals, "call_data_words" |) + |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let contract_address := + M.call (| + M.get_name (| globals, "compute_create2_contract_address" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "salt" |); + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "generic_create" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "endowment" |); + M.get_name (| globals, "contract_address" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition return_ : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Halts execution returning output data. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let memory_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_position" |); M.get_name (| globals, "memory_size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_ZERO" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "running" |), + Constant.bool false + |) in + let _ := M.pass (| |) in + M.pure Constant.None_)). + +Definition generic_call : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "gas"; "value"; "caller"; "to"; "code_address"; "should_transfer_value"; "is_staticcall"; "memory_input_start_position"; "memory_input_size"; "memory_output_start_position"; "memory_output_size" ] |) in + let _ := Constant.str " + Perform the core logic of the `CALL*` family of opcodes. + " in +(* At stmt: unsupported node type: ImportFrom *) + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let _ := + M.pure Constant.None_ + )) |) in + let call_data := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |) + ], + make_dict [] + |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "code_address" |) + ], + make_dict [] + |), "code" |) in + let child_message := + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) in + let child_evm := + M.call (| + M.get_name (| globals, "process_message" |), + make_list [ + M.get_name (| globals, "child_message" |); + M.get_field (| M.get_name (| globals, "evm" |), "env" |) + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_success" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let actual_output_size := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_name (| globals, "memory_output_size" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), Constant.None_:M.get_name (| globals, "actual_output_size" |) |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition call : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into an account. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let to := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let create_gas_cost := + (* if *) +M.if_then_else (| + BoolOp.or (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "is_account_alive" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "to" |) + ], + make_dict [] + |) + )) + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let transfer_gas_cost := + (* if *) +M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_CALL" |), + M.get_name (| globals, "create_gas_cost" |) + |), + M.get_name (| globals, "transfer_gas_cost" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.or (| + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "value" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) + )) + |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let sender_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.get_name (| globals, "value" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "to" |); + Constant.bool true; + Constant.bool false; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition callcode : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into this account with alternative account’s code. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let code_address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let to := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let transfer_gas_cost := + (* if *) +M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + BinOp.add (| + M.get_name (| globals, "GAS_CALL" |), + M.get_name (| globals, "transfer_gas_cost" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let sender_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.get_name (| globals, "value" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "code_address" |); + Constant.bool true; + Constant.bool false; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition selfdestruct : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Halt execution and register account for later deletion. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let beneficiary := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let gas_cost := + M.get_name (| globals, "GAS_SELF_DESTRUCT" |) in + let _ := + M.pure Constant.None_ + )) |) in + let originator := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in + let refunded_accounts := + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in + let parent_evm := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "parent_evm" |) in + While Compare.is_not (| + M.get_name (| globals, "parent_evm" |), + Constant.None_ + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "refunded_accounts" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "parent_evm" |), "accounts_to_delete" |) + ], + make_dict [] + |) in + let parent_evm := + M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in + EndWhile. + let _ := + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "gas_cost" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let beneficiary_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |), "balance" |) in + let originator_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "originator" |) + ], + make_dict [] + |), "balance" |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |); + BinOp.add (| + M.get_name (| globals, "beneficiary_balance" |), + M.get_name (| globals, "originator_balance" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "originator" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |), "add" |), + make_list [ + M.get_name (| globals, "originator" |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "running" |), + Constant.bool false + |) in + let _ := M.pass (| |) in + M.pure Constant.None_)). + +Definition delegatecall : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into an account. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let code_address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + M.get_name (| globals, "GAS_CALL" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "value" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "caller" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "code_address" |); + Constant.bool false; + Constant.bool false; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition staticcall : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into an account. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let to := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + M.get_name (| globals, "GAS_CALL" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "to" |); + Constant.bool true; + Constant.bool true; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition revert : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stop execution and revert state changes, without consuming all provided gas + and also has the ability to return a reason + Parameters + ---------- + evm : + The current EVM frame. + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let output := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "bytes" |), + make_list [ + M.get_name (| globals, "output" |) + ], + make_dict [] + |) + |) in + let _ := M.raise (| Some(M.get_name (| globals, "Revert" |)) + let _ := M.pass (| |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/vm/interpreter.v b/CoqOfPython/ethereum/istanbul/vm/interpreter.v index 26a41ed..dd5fceb 100644 --- a/CoqOfPython/ethereum/istanbul/vm/interpreter.v +++ b/CoqOfPython/ethereum/istanbul/vm/interpreter.v @@ -182,91 +182,6 @@ Definition process_message_call : Value.t -> Value.t -> M := Output of the message call " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_name (| globals, "message" |), "target" |), M.call (| - M.get_name (| globals, "Bytes0" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let is_collision := - M.call (| - M.get_name (| globals, "account_has_code_or_nonce" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_field (| M.get_name (| globals, "message" |), "current_target" |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - M.get_name (| globals, "is_collision" |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "MessageCallOutput" |), - make_list [ - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |); - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |); - M.call (| - M.get_name (| globals, "tuple" |), - make_list [], - make_dict [] - |); - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |); - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |); - M.call (| - M.get_name (| globals, "AddressCollision" |), - make_list [], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let evm := - M.call (| - M.get_name (| globals, "process_create_message" |), - make_list [ - M.get_name (| globals, "message" |); - M.get_name (| globals, "env" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let evm := M.call (| M.get_name (| globals, "process_message" |), @@ -277,74 +192,11 @@ Definition process_message_call : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_field (| M.get_name (| globals, "message" |), "target" |) - ], - make_dict [] - |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), - make_list [ - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_field (| M.get_name (| globals, "message" |), "target" |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "evm" |), "error" |), - (* then *) - ltac:(M.monadic ( -(* At stmt: unsupported node type: AnnAssign *) - let accounts_to_delete := - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |) in - let touched_accounts := - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |) in - let refund_counter := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let logs := M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in let accounts_to_delete := @@ -388,7 +240,6 @@ Definition process_message_call : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). Definition process_create_message : Value.t -> Value.t -> M := @@ -450,28 +301,6 @@ Definition process_create_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), - (* then *) - ltac:(M.monadic ( - let contract_code := - M.get_field (| M.get_name (| globals, "evm" |), "output" |) in - let contract_code_gas := - BinOp.mult (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "contract_code" |) - ], - make_dict [] - |), - M.get_name (| globals, "GAS_CODE_DEPOSIT" |) - |) in -(* At stmt: unsupported node type: Try *) - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "rollback_transaction" |), make_list [ @@ -483,7 +312,6 @@ Definition process_create_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) - |) in M.pure Constant.None_)). Definition process_message : Value.t -> Value.t -> M := @@ -505,21 +333,6 @@ Definition process_message : Value.t -> Value.t -> M := Items containing execution specific objects " in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_field (| M.get_name (| globals, "message" |), "depth" |), M.get_name (| globals, "STACK_DEPTH_LIMIT" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "StackDepthLimitError" |), - make_list [ - Constant.str "Stack depth limit reached" - ], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -538,29 +351,6 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - M.get_field (| M.get_name (| globals, "message" |), "should_transfer_value" |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_field (| M.get_name (| globals, "message" |), "value" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "move_ether" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_field (| M.get_name (| globals, "message" |), "caller" |); - M.get_field (| M.get_name (| globals, "message" |), "current_target" |); - M.get_field (| M.get_name (| globals, "message" |), "value" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let evm := @@ -573,21 +363,6 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "evm" |), "error" |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "rollback_transaction" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "commit_transaction" |), make_list [ @@ -599,7 +374,6 @@ Definition process_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) - |) in M.pure Constant.None_)). Definition execute_code : Value.t -> Value.t -> M := @@ -639,5 +413,4 @@ Definition execute_code : Value.t -> Value.t -> M := (* At stmt: unsupported node type: Try *) let _ := M.return_ (| M.get_name (| globals, "evm" |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/vm/memory.v b/CoqOfPython/ethereum/istanbul/vm/memory.v index fa8d906..4b107fd 100644 --- a/CoqOfPython/ethereum/istanbul/vm/memory.v +++ b/CoqOfPython/ethereum/istanbul/vm/memory.v @@ -45,22 +45,7 @@ Definition memory_write : Value.t -> Value.t -> M := Data to write to memory. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) - |) |), + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_)). @@ -86,23 +71,7 @@ Definition memory_read_bytes : Value.t -> Value.t -> M := Data read from memory. " in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |) - |) in + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |) M.pure Constant.None_)). Definition buffer_read : Value.t -> Value.t -> M := @@ -129,25 +98,9 @@ Definition buffer_read : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "right_pad_zero_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |); + M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |) |); M.get_name (| globals, "size" |) ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/alt_bn128.v index 19b83fc..abe4238 100644 --- a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/alt_bn128.v +++ b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/alt_bn128.v @@ -210,15 +210,6 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) in For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ] do let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "i" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -362,15 +353,6 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) in For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ] do let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "i" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -443,24 +425,6 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_eq (| BinOp.mod_ (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "data" |) - ], - make_dict [] - |), - Constant.int 192 - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let result := @@ -509,32 +473,11 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := Constant.int 32, M.get_name (| globals, "j" |) |) - |):BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "i" |), - Constant.int 192 - |), - BinOp.mult (| - Constant.int 32, - BinOp.add (| - M.get_name (| globals, "j" |), - Constant.int 1 - |) - |) |) |) ], make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "value" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -555,17 +498,20 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.call (| - M.get_field (| M.get_name (| globals, "p" |), "mul_by" |), - make_list [ - M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) - ], - make_dict [] - |), M.call (| - M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) |); + Compare.eq (| + M.call (| + M.get_field (| M.get_name (| globals, "p" |), "mul_by" |), + make_list [ + M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) + ], + make_dict [] + |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |); M.get_name (| globals, "OutOfGasError" |) ], make_dict [] @@ -573,87 +519,29 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.call (| - M.get_field (| M.get_name (| globals, "q" |), "mul_by" |), - make_list [ - M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) - ], - make_dict [] - |), M.call (| - M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) |); + Compare.eq (| + M.call (| + M.get_field (| M.get_name (| globals, "q" |), "mul_by" |), + make_list [ + M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) + ], + make_dict [] + |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |); M.get_name (| globals, "OutOfGasError" |) ], make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "p" |), M.call (| - M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_name (| globals, "q" |), M.call (| - M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let result := - BinOp.mult (| - M.get_name (| globals, "result" |), - M.call (| - M.get_name (| globals, "pairing" |), - make_list [ - M.get_name (| globals, "q" |); - M.get_name (| globals, "p" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "result" |), M.call (| - M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), - make_list [ - Constant.int 1 - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign (| - M.get_field (| M.get_name (| globals, "evm" |), "output" |), - M.call (| - M.get_field (| M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 1 - ], - make_dict [] - |), "to_be_bytes32" |), - make_list [], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| diff --git a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/blake2f.v b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/blake2f.v index 5903066..1647d48 100644 --- a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/blake2f.v +++ b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/blake2f.v @@ -55,13 +55,16 @@ Definition blake2f : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "data" |) - ], - make_dict [] - |), Constant.int 213 |); + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 213 + |); M.get_name (| globals, "InvalidParameter" |) ], make_dict [] @@ -96,10 +99,13 @@ Definition blake2f : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.in (| M.get_name (| globals, "f" |), make_list [ - Constant.int 0; - Constant.int 1 - ] |); + Compare.in (| + M.get_name (| globals, "f" |), + make_list [ + Constant.int 0; + Constant.int 1 + ] + |); M.get_name (| globals, "InvalidParameter" |) ], make_dict [] diff --git a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/ecrecover.v index cc351b5..0cbcf16 100644 --- a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/ecrecover.v @@ -188,60 +188,12 @@ Definition ecrecover : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 27 |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 28 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| Constant.int 0, M.get_name (| globals, "r" |) |), - ltac:(M.monadic ( - Compare.gt_e (| M.get_name (| globals, "r" |), M.get_name (| globals, "SECP256K1N" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| Constant.int 0, M.get_name (| globals, "s" |) |), - ltac:(M.monadic ( - Compare.gt_e (| M.get_name (| globals, "s" |), M.get_name (| globals, "SECP256K1N" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: Try *) @@ -252,7 +204,7 @@ Definition ecrecover : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12:Constant.int 32 |) in + |), Constant.int 12 |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/modexp.v index 39ce4f9..aff5b85 100644 --- a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/modexp.v +++ b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/modexp.v @@ -181,36 +181,6 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "exp_length" |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let adjusted_exp_length := - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.call (| - M.get_name (| globals, "max" |), - make_list [ - Constant.int 0; - BinOp.sub (| - M.call (| - M.get_field (| M.get_name (| globals, "exp_head" |), "bit_length" |), - make_list [], - make_dict [] - |), - Constant.int 1 - |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let adjusted_exp_length := M.call (| M.get_name (| globals, "Uint" |), @@ -297,30 +267,6 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_name (| globals, "base_length" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "modulus_length" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign (| - M.get_field (| M.get_name (| globals, "evm" |), "output" |), - M.call (| - M.get_name (| globals, "Bytes" |), - make_list [], - make_dict [] - |) - |) in - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let base := @@ -383,27 +329,6 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "modulus" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign (| - M.get_field (| M.get_name (| globals, "evm" |), "output" |), - BinOp.mult (| - M.call (| - M.get_name (| globals, "Bytes" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |), - M.get_name (| globals, "modulus_length" |) - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| @@ -440,47 +365,7 @@ Definition get_mult_complexity : Value.t -> Value.t -> M := Estimate the complexity of performing Karatsuba multiplication. " in let _ := - (* if *) - M.if_then_else (| - Compare.lt_e (| M.get_name (| globals, "x" |), Constant.int 64 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - BinOp.pow (| - M.get_name (| globals, "x" |), - Constant.int 2 - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - Compare.lt_e (| M.get_name (| globals, "x" |), Constant.int 1024 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - BinOp.sub (| - BinOp.add (| - BinOp.floor_div (| - BinOp.pow (| - M.get_name (| globals, "x" |), - Constant.int 2 - |), - Constant.int 4 - |), - BinOp.mult (| - Constant.int 96, - M.get_name (| globals, "x" |) - |) - |), - Constant.int 3072 - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| BinOp.sub (| BinOp.add (| @@ -498,7 +383,6 @@ Definition get_mult_complexity : Value.t -> Value.t -> M := |), Constant.int 199680 |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/istanbul/vm/runtime.v b/CoqOfPython/ethereum/istanbul/vm/runtime.v index 835b46c..2cd7652 100644 --- a/CoqOfPython/ethereum/istanbul/vm/runtime.v +++ b/CoqOfPython/ethereum/istanbul/vm/runtime.v @@ -67,50 +67,19 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := ], make_dict [] |) in - While Compare.lt (| M.get_name (| globals, "pc" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "code" |) - ], - make_dict [] - |) |) do + While Compare.lt (| + M.get_name (| globals, "pc" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) + |) do (* At stmt: unsupported node type: Try *) let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "current_opcode" |), M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), - make_list [ - M.get_name (| globals, "pc" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - (* At expr: unsupported node type: Compare *), - (* then *) - ltac:(M.monadic ( - let push_data_size := - BinOp.add (| - BinOp.sub (| - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) - |), - Constant.int 1 - |) in - let pc := BinOp.add - M.get_name (| globals, "push_data_size" |) - M.get_name (| globals, "push_data_size" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -121,5 +90,4 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := EndWhile. let _ := M.return_ (| M.get_name (| globals, "valid_jump_destinations" |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/vm/stack.v b/CoqOfPython/ethereum/istanbul/vm/stack.v index 42ea42d..ea778df 100644 --- a/CoqOfPython/ethereum/istanbul/vm/stack.v +++ b/CoqOfPython/ethereum/istanbul/vm/stack.v @@ -49,21 +49,6 @@ Definition pop : Value.t -> Value.t -> M := " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "stack" |) - ], - make_dict [] - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "StackUnderflowError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -72,7 +57,6 @@ Definition pop : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). Definition push : Value.t -> Value.t -> M := @@ -91,21 +75,6 @@ Definition push : Value.t -> Value.t -> M := " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "stack" |) - ], - make_dict [] - |), Constant.int 1024 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "StackOverflowError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -116,5 +85,4 @@ Definition push : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/bloom.v b/CoqOfPython/ethereum/london/bloom.v index 04b5d9f..04650ff 100644 --- a/CoqOfPython/ethereum/london/bloom.v +++ b/CoqOfPython/ethereum/london/bloom.v @@ -72,10 +72,7 @@ Definition add_to_bloom : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |):BinOp.add (| - M.get_name (| globals, "idx" |), - Constant.int 2 - |) |) + M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |) |) ], make_dict [] |), @@ -160,5 +157,4 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/fork.v b/CoqOfPython/ethereum/london/fork.v new file mode 100644 index 0000000..b448bed --- /dev/null +++ b/CoqOfPython/ethereum/london/fork.v @@ -0,0 +1,2402 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Specification +^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Entry point for the Ethereum specification. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_Union : + IsGlobalAlias globals typing.globals "Union". + +Require ethereum.base_types. +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". + +Require ethereum.crypto.elliptic_curve. +Axiom ethereum_crypto_elliptic_curve_SECP256K1N : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.ethash. +Axiom ethereum_ethash_dataset_size : + IsGlobalAlias globals ethereum.ethash.globals "dataset_size". +Axiom ethereum_ethash_generate_cache : + IsGlobalAlias globals ethereum.ethash.globals "generate_cache". +Axiom ethereum_ethash_hashimoto_light : + IsGlobalAlias globals ethereum.ethash.globals "hashimoto_light". + +Require ethereum.exceptions. +Axiom ethereum_exceptions_InvalidBlock : + IsGlobalAlias globals ethereum.exceptions.globals "InvalidBlock". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U64 : + IsGlobalAlias globals base_types.globals "U64". +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_U256_CEIL_VALUE : + IsGlobalAlias globals base_types.globals "U256_CEIL_VALUE". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". + +Require __init__. +Axiom __init___FORK_CRITERIA : + IsGlobalAlias globals __init__.globals "FORK_CRITERIA". +Axiom __init___vm : + IsGlobalAlias globals __init__.globals "vm". + +Require blocks. +Axiom blocks_Block : + IsGlobalAlias globals blocks.globals "Block". +Axiom blocks_Header : + IsGlobalAlias globals blocks.globals "Header". +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". +Axiom blocks_Receipt : + IsGlobalAlias globals blocks.globals "Receipt". + +Require bloom. +Axiom bloom_logs_bloom : + IsGlobalAlias globals bloom.globals "logs_bloom". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Require state. +Axiom state_State : + IsGlobalAlias globals state.globals "State". +Axiom state_account_exists_and_is_empty : + IsGlobalAlias globals state.globals "account_exists_and_is_empty". +Axiom state_create_ether : + IsGlobalAlias globals state.globals "create_ether". +Axiom state_destroy_account : + IsGlobalAlias globals state.globals "destroy_account". +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". +Axiom state_increment_nonce : + IsGlobalAlias globals state.globals "increment_nonce". +Axiom state_set_account_balance : + IsGlobalAlias globals state.globals "set_account_balance". +Axiom state_state_root : + IsGlobalAlias globals state.globals "state_root". + +Require transactions. +Axiom transactions_TX_ACCESS_LIST_ADDRESS_COST : + IsGlobalAlias globals transactions.globals "TX_ACCESS_LIST_ADDRESS_COST". +Axiom transactions_TX_ACCESS_LIST_STORAGE_KEY_COST : + IsGlobalAlias globals transactions.globals "TX_ACCESS_LIST_STORAGE_KEY_COST". +Axiom transactions_TX_BASE_COST : + IsGlobalAlias globals transactions.globals "TX_BASE_COST". +Axiom transactions_TX_CREATE_COST : + IsGlobalAlias globals transactions.globals "TX_CREATE_COST". +Axiom transactions_TX_DATA_COST_PER_NON_ZERO : + IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_NON_ZERO". +Axiom transactions_TX_DATA_COST_PER_ZERO : + IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_ZERO". +Axiom transactions_AccessListTransaction : + IsGlobalAlias globals transactions.globals "AccessListTransaction". +Axiom transactions_FeeMarketTransaction : + IsGlobalAlias globals transactions.globals "FeeMarketTransaction". +Axiom transactions_LegacyTransaction : + IsGlobalAlias globals transactions.globals "LegacyTransaction". +Axiom transactions_Transaction : + IsGlobalAlias globals transactions.globals "Transaction". +Axiom transactions_decode_transaction : + IsGlobalAlias globals transactions.globals "decode_transaction". +Axiom transactions_encode_transaction : + IsGlobalAlias globals transactions.globals "encode_transaction". + +Require trie. +Axiom trie_Trie : + IsGlobalAlias globals trie.globals "Trie". +Axiom trie_root : + IsGlobalAlias globals trie.globals "root". +Axiom trie_trie_set : + IsGlobalAlias globals trie.globals "trie_set". + +Require utils.message. +Axiom utils_message_prepare_message : + IsGlobalAlias globals utils.message.globals "prepare_message". + +Require vm.interpreter. +Axiom vm_interpreter_process_message_call : + IsGlobalAlias globals vm.interpreter.globals "process_message_call". + +Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mult (| + Constant.int 2, + BinOp.pow (| + Constant.int 10, + Constant.int 18 + |) + |) + ], + make_dict [] + |) +)). + +Definition BASE_FEE_MAX_CHANGE_DENOMINATOR : Value.t := M.run ltac:(M.monadic ( + Constant.int 8 +)). + +Definition ELASTICITY_MULTIPLIER : Value.t := M.run ltac:(M.monadic ( + Constant.int 2 +)). + +Definition GAS_LIMIT_ADJUSTMENT_FACTOR : Value.t := M.run ltac:(M.monadic ( + Constant.int 1024 +)). + +Definition GAS_LIMIT_MINIMUM : Value.t := M.run ltac:(M.monadic ( + Constant.int 5000 +)). + +Definition MINIMUM_DIFFICULTY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 131072 + ], + make_dict [] + |) +)). + +Definition INITIAL_BASE_FEE : Value.t := M.run ltac:(M.monadic ( + Constant.int 1000000000 +)). + +Definition MAX_OMMER_DEPTH : Value.t := M.run ltac:(M.monadic ( + Constant.int 6 +)). + +Definition BOMB_DELAY_BLOCKS : Value.t := M.run ltac:(M.monadic ( + Constant.int 9700000 +)). + +Definition EMPTY_OMMER_HASH : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_list [] + ], + make_dict [] + |) + ], + make_dict [] + |) +)). + +Definition BlockChain : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition apply_fork : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "old" ] |) in + let _ := Constant.str " + Transforms the state from the previous hard fork (`old`) into the block + chain object for this hard fork and returns it. + + When forks need to implement an irregular state transition, this function + is used to handle the irregularity. See the :ref:`DAO Fork ` for + an example. + + Parameters + ---------- + old : + Previous block chain object. + + Returns + ------- + new : `BlockChain` + Upgraded block chain object for this hard fork. + " in + let _ := M.return_ (| + M.get_name (| globals, "old" |) + M.pure Constant.None_)). + +Definition get_last_256_block_hashes : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "chain" ] |) in + let _ := Constant.str " + Obtain the list of hashes of the previous 256 blocks in order of + increasing block number. + + This function will return less hashes for the first 256 blocks. + + The ``BLOCKHASH`` opcode needs to access the latest hashes on the chain, + therefore this function retrieves them. + + Parameters + ---------- + chain : + History and current state. + + Returns + ------- + recent_block_hashes : `List[Hash32]` + Hashes of the recent 256 blocks in order of increasing block number. + " in + let recent_blocks := + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |) |) in + let _ := + M.pure Constant.None_ + )) |) in + let recent_block_hashes := + make_list [] in + For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_blocks" |) do + let prev_block_hash := + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), + make_list [ + M.get_name (| globals, "prev_block_hash" |) + ], + make_dict [] + |) in + EndFor. + let most_recent_block_hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_field (| M.get_subscript (| M.get_name (| globals, "recent_blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), + make_list [ + M.get_name (| globals, "most_recent_block_hash" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "recent_block_hashes" |) + M.pure Constant.None_)). + +Definition state_transition : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "chain"; "block" ] |) in + let _ := Constant.str " + Attempts to apply a block to an existing block chain. + + All parts of the block's contents need to be verified before being added + to the chain. Blocks are verified by ensuring that the contents of the + block make logical sense with the contents of the parent block. The + information in the block's header must also match the corresponding + information in the block. + + To implement Ethereum, in theory clients are only required to store the + most recent 255 blocks of the chain since as far as execution is + concerned, only those blocks are accessed. Practically, however, clients + should store more blocks to handle reorgs. + + Parameters + ---------- + chain : + History and current state. + block : + Block to apply to `chain`. + " in + let parent_header := + M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) in + let _ := M.call (| + M.get_name (| globals, "validate_header" |), + make_list [ + M.get_field (| M.get_name (| globals, "block" |), "header" |); + M.get_name (| globals, "parent_header" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "validate_ommers" |), + make_list [ + M.get_field (| M.get_name (| globals, "block" |), "ommers" |); + M.get_field (| M.get_name (| globals, "block" |), "header" |); + M.get_name (| globals, "chain" |) + ], + make_dict [] + |) in + let apply_body_output := + M.call (| + M.get_name (| globals, "apply_body" |), + make_list [ + M.get_field (| M.get_name (| globals, "chain" |), "state" |); + M.call (| + M.get_name (| globals, "get_last_256_block_hashes" |), + make_list [ + M.get_name (| globals, "chain" |) + ], + make_dict [] + |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "coinbase" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "number" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "base_fee_per_gas" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "gas_limit" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "timestamp" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "difficulty" |); + M.get_field (| M.get_name (| globals, "block" |), "transactions" |); + M.get_field (| M.get_name (| globals, "block" |), "ommers" |); + M.get_field (| M.get_name (| globals, "chain" |), "chain_id" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_gas_used" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "gas_used" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "transactions_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "transactions_root" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "state_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "state_root" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "receipt_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "receipt_root" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_logs_bloom" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "bloom" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), "append" |), + make_list [ + M.get_name (| globals, "block" |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "block_gas_limit"; "parent_gas_limit"; "parent_gas_used"; "parent_base_fee_per_gas"; "is_fork_block" ] |) in + let _ := Constant.str " + Calculates the base fee per gas for the block. + + Parameters + ---------- + block_gas_limit : + Gas limit of the block for which the base fee is being calculated. + parent_gas_limit : + Gas limit of the parent block. + parent_gas_used : + Gas used in the parent block. + parent_base_fee_per_gas : + Base fee per gas of the parent block. + is_fork_block : + Whether the block is the fork block. + + Returns + ------- + base_fee_per_gas : `Uint` + Base fee per gas for the block. + " in + let _ := + M.pure Constant.None_ + )) |) in + let parent_gas_target := + BinOp.floor_div (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "ELASTICITY_MULTIPLIER" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + M.call (| + M.get_name (| globals, "check_gas_limit" |), + make_list [ + M.get_name (| globals, "block_gas_limit" |); + M.get_name (| globals, "parent_gas_limit" |) + ], + make_dict [] + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := + let _ := + let gas_used_delta := + BinOp.sub (| + M.get_name (| globals, "parent_gas_target" |), + M.get_name (| globals, "parent_gas_used" |) + |) in + let parent_fee_gas_delta := + BinOp.mult (| + M.get_name (| globals, "parent_base_fee_per_gas" |), + M.get_name (| globals, "gas_used_delta" |) + |) in + let target_fee_gas_delta := + BinOp.floor_div (| + M.get_name (| globals, "parent_fee_gas_delta" |), + M.get_name (| globals, "parent_gas_target" |) + |) in + let base_fee_per_gas_delta := + BinOp.floor_div (| + M.get_name (| globals, "target_fee_gas_delta" |), + M.get_name (| globals, "BASE_FEE_MAX_CHANGE_DENOMINATOR" |) + |) in + let expected_base_fee_per_gas := + BinOp.sub (| + M.get_name (| globals, "parent_base_fee_per_gas" |), + M.get_name (| globals, "base_fee_per_gas_delta" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "expected_base_fee_per_gas" |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition validate_header : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header"; "parent_header" ] |) in + let _ := Constant.str " + Verifies a block header. + + In order to consider a block's header valid, the logic for the + quantities in the header should match the logic for the block itself. + For example the header timestamp should be greater than the block's parent + timestamp because the block was created *after* the parent block. + Additionally, the block's number should be directly following the parent + block's number since it is the next block in the sequence. + + Parameters + ---------- + header : + Header to check for correctness. + parent_header : + Parent Header of the header to check for correctness + " in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "header" |), "gas_used" |), + M.get_field (| M.get_name (| globals, "header" |), "gas_limit" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let is_fork_block := + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "number" |), + M.get_field (| M.get_name (| globals, "FORK_CRITERIA" |), "block_number" |) + |) in + let expected_base_fee_per_gas := + M.call (| + M.get_name (| globals, "calculate_base_fee_per_gas" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "gas_limit" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "gas_limit" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "gas_used" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "base_fee_per_gas" |); + M.get_name (| globals, "is_fork_block" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_name (| globals, "expected_base_fee_per_gas" |), + M.get_field (| M.get_name (| globals, "header" |), "base_fee_per_gas" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let parent_has_ommers := + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "parent_header" |), "ommers_hash" |), + M.get_name (| globals, "EMPTY_OMMER_HASH" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt (| + M.get_field (| M.get_name (| globals, "header" |), "timestamp" |), + M.get_field (| M.get_name (| globals, "parent_header" |), "timestamp" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "number" |), + BinOp.add (| + M.get_field (| M.get_name (| globals, "parent_header" |), "number" |), + Constant.int 1 + |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) + ], + make_dict [] + |), + Constant.int 32 + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let block_difficulty := + M.call (| + M.get_name (| globals, "calculate_block_difficulty" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "number" |); + M.get_field (| M.get_name (| globals, "header" |), "timestamp" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "timestamp" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "difficulty" |); + M.get_name (| globals, "parent_has_ommers" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "difficulty" |), + M.get_name (| globals, "block_difficulty" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let block_parent_hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "parent_header" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |), + M.get_name (| globals, "block_parent_hash" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "validate_proof_of_work" |), + make_list [ + M.get_name (| globals, "header" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header" ] |) in + let _ := Constant.str " + Generate rlp hash of the header which is to be used for Proof-of-Work + verification. + + In other words, the PoW artefacts `mix_digest` and `nonce` are ignored + while calculating this hash. + + A particular PoW is valid for a single hash, that hash is computed by + this function. The `nonce` and `mix_digest` are omitted from this hash + because they are being changed by miners in their search for a sufficient + proof-of-work. + + Parameters + ---------- + header : + The header object for which the hash is to be generated. + + Returns + ------- + hash : `Hash32` + The PoW valid rlp hash of the passed in header. + " in + let header_data_without_pow_artefacts := + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |); + M.get_field (| M.get_name (| globals, "header" |), "ommers_hash" |); + M.get_field (| M.get_name (| globals, "header" |), "coinbase" |); + M.get_field (| M.get_name (| globals, "header" |), "state_root" |); + M.get_field (| M.get_name (| globals, "header" |), "transactions_root" |); + M.get_field (| M.get_name (| globals, "header" |), "receipt_root" |); + M.get_field (| M.get_name (| globals, "header" |), "bloom" |); + M.get_field (| M.get_name (| globals, "header" |), "difficulty" |); + M.get_field (| M.get_name (| globals, "header" |), "number" |); + M.get_field (| M.get_name (| globals, "header" |), "gas_limit" |); + M.get_field (| M.get_name (| globals, "header" |), "gas_used" |); + M.get_field (| M.get_name (| globals, "header" |), "timestamp" |); + M.get_field (| M.get_name (| globals, "header" |), "extra_data" |); + M.get_field (| M.get_name (| globals, "header" |), "base_fee_per_gas" |) + ] in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "header_data_without_pow_artefacts" |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition validate_proof_of_work : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header" ] |) in + let _ := Constant.str " + Validates the Proof of Work constraints. + + In order to verify that a miner's proof-of-work is valid for a block, a + ``mix-digest`` and ``result`` are calculated using the ``hashimoto_light`` + hash function. The mix digest is a hash of the header and the nonce that + is passed through and it confirms whether or not proof-of-work was done + on the correct block. The result is the actual hash value of the block. + + Parameters + ---------- + header : + Header of interest. + " in + let header_hash := + M.call (| + M.get_name (| globals, "generate_header_hash_for_pow" |), + make_list [ + M.get_name (| globals, "header" |) + ], + make_dict [] + |) in + let cache := + M.call (| + M.get_name (| globals, "generate_cache" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "number" |) + ], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "mix_digest" |); M.get_name (| globals, "result" |) ], + M.call (| + M.get_name (| globals, "hashimoto_light" |), + make_list [ + M.get_name (| globals, "header_hash" |); + M.get_field (| M.get_name (| globals, "header" |), "nonce" |); + M.get_name (| globals, "cache" |); + M.call (| + M.get_name (| globals, "dataset_size" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "number" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_name (| globals, "mix_digest" |), + M.get_field (| M.get_name (| globals, "header" |), "mix_digest" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "result" |) + ], + make_dict [] + |), + BinOp.floor_div (| + M.get_name (| globals, "U256_CEIL_VALUE" |), + M.get_field (| M.get_name (| globals, "header" |), "difficulty" |) + |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition check_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx"; "base_fee_per_gas"; "gas_available"; "chain_id" ] |) in + let _ := Constant.str " + Check if the transaction is includable in the block. + + Parameters + ---------- + tx : + The transaction. + base_fee_per_gas : + The block base fee. + gas_available : + The gas remaining in the block. + chain_id : + The ID of the current chain. + + Returns + ------- + sender_address : + The sender of the transaction. + effective_gas_price : + The price to charge for gas when the transaction is executed. + + Raises + ------ + InvalidBlock : + If the transaction is not includable. + " in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_name (| globals, "gas_available" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let sender_address := + M.call (| + M.get_name (| globals, "recover_sender" |), + make_list [ + M.get_name (| globals, "chain_id" |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt_e (| + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |), + M.get_name (| globals, "base_fee_per_gas" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let effective_gas_price := + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + make_tuple [ M.get_name (| globals, "sender_address" |); M.get_name (| globals, "effective_gas_price" |) ] + M.pure Constant.None_)). + +Definition make_receipt : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx"; "error"; "cumulative_gas_used"; "logs" ] |) in + let _ := Constant.str " + Make the receipt for a transaction that was executed. + + Parameters + ---------- + tx : + The executed transaction. + error : + Error in the top level frame of the transaction, if any. + cumulative_gas_used : + The total gas used so far in the block after the transaction was + executed. + logs : + The logs produced by the transaction. + + Returns + ------- + receipt : + The receipt for the transaction. + " in + let receipt := + M.call (| + M.get_name (| globals, "Receipt" |), + make_list [], + make_dict [] + |) in + let _ := + let _ := + let _ := M.return_ (| + M.get_name (| globals, "receipt" |) + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition ApplyBodyOutput : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition apply_body : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "block_hashes"; "coinbase"; "block_number"; "base_fee_per_gas"; "block_gas_limit"; "block_time"; "block_difficulty"; "transactions"; "ommers"; "chain_id" ] |) in + let _ := Constant.str " + Executes a block. + + Many of the contents of a block are stored in data structures called + tries. There is a transactions trie which is similar to a ledger of the + transactions stored in the current block. There is also a receipts trie + which stores the results of executing a transaction, like the post state + and gas used. This function creates and executes the block that is to be + added to the chain. + + Parameters + ---------- + state : + Current account state. + block_hashes : + List of hashes of the previous 256 blocks in the order of + increasing block number. + coinbase : + Address of account which receives block reward and transaction fees. + block_number : + Position of the block within the chain. + base_fee_per_gas : + Base fee per gas of within the block. + block_gas_limit : + Initial amount of gas available for execution in this block. + block_time : + Time the block was produced, measured in seconds since the epoch. + block_difficulty : + Difficulty of the block. + transactions : + Transactions included in the block. + ommers : + Headers of ancestor blocks which are not direct parents (formerly + uncles.) + chain_id : + ID of the executing chain. + + Returns + ------- + apply_body_output : `ApplyBodyOutput` + Output of applying the block body to the state. + " in + let gas_available := + M.get_name (| globals, "block_gas_limit" |) in +(* At stmt: unsupported node type: AnnAssign *) +(* At stmt: unsupported node type: AnnAssign *) +(* At stmt: unsupported node type: AnnAssign *) + For make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "tx" |) ] in M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.call (| + M.get_name (| globals, "map" |), + make_list [ + M.get_name (| globals, "decode_transaction" |); + M.get_name (| globals, "transactions" |) + ], + make_dict [] + |) + ], + make_dict [] + |) do + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "transactions_trie" |); + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "i" |) + ], + make_dict [] + |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "encode_transaction" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "sender_address" |); M.get_name (| globals, "effective_gas_price" |) ], + M.call (| + M.get_name (| globals, "check_transaction" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "base_fee_per_gas" |); + M.get_name (| globals, "gas_available" |); + M.get_name (| globals, "chain_id" |) + ], + make_dict [] + |) + |) in + let env := + M.call (| + M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |); M.get_name (| globals, "error" |) ], + M.call (| + M.get_name (| globals, "process_transaction" |), + make_list [ + M.get_name (| globals, "env" |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) in + let gas_available := BinOp.sub + M.get_name (| globals, "gas_used" |) + M.get_name (| globals, "gas_used" |) in + let receipt := + M.call (| + M.get_name (| globals, "make_receipt" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "error" |); + BinOp.sub (| + M.get_name (| globals, "block_gas_limit" |), + M.get_name (| globals, "gas_available" |) + |); + M.get_name (| globals, "logs" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "receipts_trie" |); + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "i" |) + ], + make_dict [] + |) + ], + make_dict [] + |); + M.get_name (| globals, "receipt" |) + ], + make_dict [] + |) in + let block_logs := BinOp.add + M.get_name (| globals, "logs" |) + M.get_name (| globals, "logs" |) in + EndFor. + let _ := M.call (| + M.get_name (| globals, "pay_rewards" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "block_number" |); + M.get_name (| globals, "coinbase" |); + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |) in + let block_gas_used := + BinOp.sub (| + M.get_name (| globals, "block_gas_limit" |), + M.get_name (| globals, "gas_available" |) + |) in + let block_logs_bloom := + M.call (| + M.get_name (| globals, "logs_bloom" |), + make_list [ + M.get_name (| globals, "block_logs" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ApplyBodyOutput" |), + make_list [ + M.get_name (| globals, "block_gas_used" |); + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_name (| globals, "transactions_trie" |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_name (| globals, "receipts_trie" |) + ], + make_dict [] + |); + M.get_name (| globals, "block_logs_bloom" |); + M.call (| + M.get_name (| globals, "state_root" |), + make_list [ + M.get_name (| globals, "state" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition validate_ommers : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "ommers"; "block_header"; "chain" ] |) in + let _ := Constant.str " + Validates the ommers mentioned in the block. + + An ommer block is a block that wasn't canonically added to the + blockchain because it wasn't validated as fast as the canonical block + but was mined at the same time. + + To be considered valid, the ommers must adhere to the rules defined in + the Ethereum protocol. The maximum amount of ommers is 2 per block and + there cannot be duplicate ommers in a block. Many of the other ommer + constraints are listed in the in-line comments of this function. + + Parameters + ---------- + ommers : + List of ommers mentioned in the current block. + block_header: + The header of current block. + chain : + History and current state. + " in + let block_hash := + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "block_header" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + M.get_field (| M.get_name (| globals, "block_header" |), "ommers_hash" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.and (| + Compare.lt_e (| + Constant.int 1, + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |), + ltac:(M.monadic ( + Compare.lt (| + M.get_field (| M.get_name (| globals, "ommer" |), "number" |), + M.get_field (| M.get_name (| globals, "block_header" |), "number" |) + |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let ommer_parent_header := + M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), BinOp.sub (| + UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) |), + Constant.int 1 + |) |), "header" |) in + let _ := M.call (| + M.get_name (| globals, "validate_header" |), + make_list [ + M.get_name (| globals, "ommer" |); + M.get_name (| globals, "ommer_parent_header" |) + ], + make_dict [] + |) in + EndFor. + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + Constant.int 2 + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let ommers_hashes := + (* At expr: unsupported node type: ListComp *) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers_hashes" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_name (| globals, "set" |), + make_list [ + M.get_name (| globals, "ommers_hashes" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let recent_canonical_blocks := + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| BinOp.add (| + M.get_name (| globals, "MAX_OMMER_DEPTH" |), + Constant.int 1 + |) |) |) in + let recent_canonical_block_hashes := + (* At expr: unsupported node type: SetComp *) in +(* At stmt: unsupported node type: AnnAssign *) + For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_canonical_blocks" |) do + let recent_ommers_hashes := + M.call (| + M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), + make_list [ + (* At expr: unsupported node type: SetComp *) + ], + make_dict [] + |) in + EndFor. + For make_tuple [ M.get_name (| globals, "ommer_index" |); M.get_name (| globals, "ommer" |) ] in M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |) do + let ommer_hash := + M.get_subscript (| M.get_name (| globals, "ommers_hashes" |), M.get_name (| globals, "ommer_index" |) |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_eq (| + M.get_name (| globals, "ommer_hash" |), + M.get_name (| globals, "block_hash" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_in (| + M.get_name (| globals, "ommer_hash" |), + M.get_name (| globals, "recent_canonical_block_hashes" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_in (| + M.get_name (| globals, "ommer_hash" |), + M.get_name (| globals, "recent_ommers_hashes" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let ommer_age := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.and (| + Compare.lt_e (| + Constant.int 1, + M.get_name (| globals, "ommer_age" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_name (| globals, "ommer_age" |), + M.get_name (| globals, "MAX_OMMER_DEPTH" |) + |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.in (| + M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), + M.get_name (| globals, "recent_canonical_block_hashes" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), + M.get_field (| M.get_name (| globals, "block_header" |), "parent_hash" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_)). + +Definition pay_rewards : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "block_number"; "coinbase"; "ommers" ] |) in + let _ := Constant.str " + Pay rewards to the block miner as well as the ommers miners. + + The miner of the canonical block is rewarded with the predetermined + block reward, ``BLOCK_REWARD``, plus a variable award based off of the + number of ommer blocks that were mined around the same time, and included + in the canonical block's header. An ommer block is a block that wasn't + added to the canonical blockchain because it wasn't validated as fast as + the accepted block but was mined at the same time. Although not all blocks + that are mined are added to the canonical chain, miners are still paid a + reward for their efforts. This reward is called an ommer reward and is + calculated based on the number associated with the ommer block that they + mined. + + Parameters + ---------- + state : + Current account state. + block_number : + Position of the block within the chain. + coinbase : + Address of account which receives block reward and transaction fees. + ommers : + List of ommers mentioned in the current block. + " in + let miner_reward := + BinOp.add (| + M.get_name (| globals, "BLOCK_REWARD" |), + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + BinOp.floor_div (| + M.get_name (| globals, "BLOCK_REWARD" |), + Constant.int 32 + |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "create_ether" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "coinbase" |); + M.get_name (| globals, "miner_reward" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do + let ommer_age := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "block_number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) + ], + make_dict [] + |) in + let ommer_miner_reward := + BinOp.floor_div (| + BinOp.mult (| + BinOp.sub (| + Constant.int 8, + M.get_name (| globals, "ommer_age" |) + |), + M.get_name (| globals, "BLOCK_REWARD" |) + |), + Constant.int 8 + |) in + let _ := M.call (| + M.get_name (| globals, "create_ether" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_field (| M.get_name (| globals, "ommer" |), "coinbase" |); + M.get_name (| globals, "ommer_miner_reward" |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_)). + +Definition process_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "env"; "tx" ] |) in + let _ := Constant.str " + Execute a transaction against the provided environment. + + This function processes the actions needed to execute a transaction. + It decrements the sender's account after calculating the gas fee and + refunds them the proper amount after execution. Calling contracts, + deploying code, and incrementing nonces are all examples of actions that + happen within this function or from a call made within this function. + + Accounts that are marked for deletion are processed and destroyed after + execution. + + Parameters + ---------- + env : + Environment for the Ethereum Virtual Machine. + tx : + Transaction to execute. + + Returns + ------- + gas_left : `ethereum.base_types.U256` + Remaining gas after execution. + logs : `Tuple[ethereum.blocks.Log, ...]` + Logs generated during execution. + " in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + M.call (| + M.get_name (| globals, "validate_transaction" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let sender := + M.get_field (| M.get_name (| globals, "env" |), "origin" |) in + let sender_account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |) in + let _ := + let max_gas_fee := + BinOp.mult (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "sender_account" |), "nonce" |), + M.get_field (| M.get_name (| globals, "tx" |), "nonce" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt_e (| + M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), + BinOp.add (| + M.get_name (| globals, "max_gas_fee" |), + M.get_field (| M.get_name (| globals, "tx" |), "value" |) + |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "sender_account" |), "code" |), + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [], + make_dict [] + |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let effective_gas_fee := + BinOp.mult (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "env" |), "gas_price" |) + |) in + let gas := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.call (| + M.get_name (| globals, "calculate_intrinsic_cost" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) in + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |) in + let sender_balance_after_gas_fee := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), + M.get_name (| globals, "effective_gas_fee" |) + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |); + M.get_name (| globals, "sender_balance_after_gas_fee" |) + ], + make_dict [] + |) in + let preaccessed_addresses := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let preaccessed_storage_keys := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let message := + M.call (| + M.get_name (| globals, "prepare_message" |), + make_list [ + M.get_name (| globals, "sender" |); + M.get_field (| M.get_name (| globals, "tx" |), "to" |); + M.get_field (| M.get_name (| globals, "tx" |), "value" |); + M.get_field (| M.get_name (| globals, "tx" |), "data" |); + M.get_name (| globals, "gas" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let output := + M.call (| + M.get_name (| globals, "process_message_call" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let gas_used := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "output" |), "gas_left" |) + |) in + let gas_refund := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + BinOp.floor_div (| + M.get_name (| globals, "gas_used" |), + Constant.int 5 + |); + M.get_field (| M.get_name (| globals, "output" |), "refund_counter" |) + ], + make_dict [] + |) in + let gas_refund_amount := + BinOp.mult (| + BinOp.add (| + M.get_field (| M.get_name (| globals, "output" |), "gas_left" |), + M.get_name (| globals, "gas_refund" |) + |), + M.get_field (| M.get_name (| globals, "env" |), "gas_price" |) + |) in + let priority_fee_per_gas := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "env" |), "gas_price" |), + M.get_field (| M.get_name (| globals, "env" |), "base_fee_per_gas" |) + |) in + let transaction_fee := + BinOp.mult (| + BinOp.sub (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "output" |), "gas_left" |) + |), + M.get_name (| globals, "gas_refund" |) + |), + M.get_name (| globals, "priority_fee_per_gas" |) + |) in + let total_gas_used := + BinOp.sub (| + M.get_name (| globals, "gas_used" |), + M.get_name (| globals, "gas_refund" |) + |) in + let sender_balance_after_refund := + BinOp.add (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |), "balance" |), + M.get_name (| globals, "gas_refund_amount" |) + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |); + M.get_name (| globals, "sender_balance_after_refund" |) + ], + make_dict [] + |) in + let coinbase_balance_after_mining_fee := + BinOp.add (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |), "balance" |), + M.get_name (| globals, "transaction_fee" |) + |) in + let _ := + let _ := + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "accounts_to_delete" |) do + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + EndFor. + For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "touched_accounts" |) do + let _ := + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.return_ (| + make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |); M.get_field (| M.get_name (| globals, "output" |), "error" |) ] + M.pure Constant.None_)). + +Definition validate_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Verifies a transaction. + + The gas in a transaction gets used to pay for the intrinsic cost of + operations, therefore if there is insufficient gas then it would not + be possible to execute a transaction and it will be declared invalid. + + Additionally, the nonce of a transaction must not equal or exceed the + limit defined in `EIP-2681 `_. + In practice, defining the limit as ``2**64-1`` has no impact because + sending ``2**64-1`` transactions is improbable. It's not strictly + impossible though, ``2**64-1`` transactions is the entire capacity of the + Ethereum blockchain at 2022 gas limits for a little over 22 years. + + Parameters + ---------- + tx : + Transaction to validate. + + Returns + ------- + verified : `bool` + True if the transaction can be executed, or False otherwise. + " in + let _ := M.return_ (| + BoolOp.and (| + Compare.lt_e (| + M.call (| + M.get_name (| globals, "calculate_intrinsic_cost" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |), + M.get_field (| M.get_name (| globals, "tx" |), "gas" |) + |), + ltac:(M.monadic ( + Compare.lt (| + M.get_field (| M.get_name (| globals, "tx" |), "nonce" |), + BinOp.sub (| + BinOp.pow (| + Constant.int 2, + Constant.int 64 + |), + Constant.int 1 + |) + |) + )) + |) + M.pure Constant.None_)). + +Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Calculates the gas that is charged before execution is started. + + The intrinsic cost of the transaction is charged before execution has + begun. Functions/operations in the EVM cost money to execute so this + intrinsic cost is for the operations that need to be paid for as part of + the transaction. Data transfer, for example, is part of this intrinsic + cost. It costs ether to send data over the wire and that ether is + accounted for in the intrinsic cost calculated in this function. This + intrinsic cost must be calculated and paid for before execution in order + for all operations to be implemented. + + Parameters + ---------- + tx : + Transaction to compute the intrinsic cost of. + + Returns + ------- + verified : `ethereum.base_types.Uint` + The intrinsic cost of the transaction. + " in + let data_cost := + Constant.int 0 in + For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do + let _ := + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + M.pure Constant.None_ + )) |) in + EndFor. + let _ := + let create_cost := + Constant.int 0 in + M.pure Constant.None_ + )) |) in + let access_list_cost := + Constant.int 0 in + let _ := + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.add (| + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "TX_BASE_COST" |), + M.get_name (| globals, "data_cost" |) + |), + M.get_name (| globals, "create_cost" |) + |), + M.get_name (| globals, "access_list_cost" |) + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition recover_sender : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "chain_id"; "tx" ] |) in + let _ := Constant.str " + Extracts the sender address from a transaction. + + The v, r, and s values are the three parts that make up the signature + of a transaction. In order to recover the sender of a transaction the two + components needed are the signature (``v``, ``r``, and ``s``) and the + signing hash of the transaction. The sender's public key can be obtained + with these two values and therefore the sender address can be retrieved. + + Parameters + ---------- + tx : + Transaction of interest. + chain_id : + ID of the executing chain. + + Returns + ------- + sender : `ethereum.fork_types.Address` + The address of the account that signed the transaction. + " in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "r" |); M.get_name (| globals, "s" |) ], + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "r" |); M.get_field (| M.get_name (| globals, "tx" |), "s" |) ] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.and (| + Compare.lt (| + Constant.int 0, + M.get_name (| globals, "r" |) + |), + ltac:(M.monadic ( + Compare.lt (| + M.get_name (| globals, "r" |), + M.get_name (| globals, "SECP256K1N" |) + |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.and (| + Compare.lt (| + Constant.int 0, + M.get_name (| globals, "s" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_name (| globals, "s" |), + BinOp.floor_div (| + M.get_name (| globals, "SECP256K1N" |), + Constant.int 2 + |) + |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := + let _ := + let _ := + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_subscript (| M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), Constant.int 12 |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition signing_hash_pre155 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Compute the hash of a transaction used in a legacy (pre EIP 155) signature. + + Parameters + ---------- + tx : + Transaction of interest. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the transaction. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "nonce" |); M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |); M.get_field (| M.get_name (| globals, "tx" |), "gas" |); M.get_field (| M.get_name (| globals, "tx" |), "to" |); M.get_field (| M.get_name (| globals, "tx" |), "value" |); M.get_field (| M.get_name (| globals, "tx" |), "data" |) ] + ], + make_dict [] + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition signing_hash_155 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx"; "chain_id" ] |) in + let _ := Constant.str " + Compute the hash of a transaction used in a EIP 155 signature. + + Parameters + ---------- + tx : + Transaction of interest. + chain_id : + The id of the current chain. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the transaction. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "nonce" |); M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |); M.get_field (| M.get_name (| globals, "tx" |), "gas" |); M.get_field (| M.get_name (| globals, "tx" |), "to" |); M.get_field (| M.get_name (| globals, "tx" |), "value" |); M.get_field (| M.get_name (| globals, "tx" |), "data" |); M.get_name (| globals, "chain_id" |); M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) ] + ], + make_dict [] + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition signing_hash_2930 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Compute the hash of a transaction used in a EIP 2930 signature. + + Parameters + ---------- + tx : + Transaction of interest. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the transaction. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + BinOp.add (| + Constant.bytes "01", + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "chain_id" |); M.get_field (| M.get_name (| globals, "tx" |), "nonce" |); M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |); M.get_field (| M.get_name (| globals, "tx" |), "gas" |); M.get_field (| M.get_name (| globals, "tx" |), "to" |); M.get_field (| M.get_name (| globals, "tx" |), "value" |); M.get_field (| M.get_name (| globals, "tx" |), "data" |); M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) ] + ], + make_dict [] + |) + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition signing_hash_1559 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Compute the hash of a transaction used in a EIP 1559 signature. + + Parameters + ---------- + tx : + Transaction of interest. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the transaction. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + BinOp.add (| + Constant.bytes "02", + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "chain_id" |); M.get_field (| M.get_name (| globals, "tx" |), "nonce" |); M.get_field (| M.get_name (| globals, "tx" |), "max_priority_fee_per_gas" |); M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |); M.get_field (| M.get_name (| globals, "tx" |), "gas" |); M.get_field (| M.get_name (| globals, "tx" |), "to" |); M.get_field (| M.get_name (| globals, "tx" |), "value" |); M.get_field (| M.get_name (| globals, "tx" |), "data" |); M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) ] + ], + make_dict [] + |) + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition compute_header_hash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header" ] |) in + let _ := Constant.str " + Computes the hash of a block header. + + The header hash of a block is the canonical hash that is used to refer + to a specific block and completely distinguishes a block from another. + + ``keccak256`` is a function that produces a 256 bit hash of any input. + It also takes in any number of bytes as an input and produces a single + hash for them. A hash is a completely unique output for a single input. + So an input corresponds to one unique hash that can be used to identify + the input exactly. + + Prior to using the ``keccak256`` hash function, the header must be + encoded using the Recursive-Length Prefix. See :ref:`rlp`. + RLP encoding the header converts it into a space-efficient format that + allows for easy transfer of data between nodes. The purpose of RLP is to + encode arbitrarily nested arrays of binary data, and RLP is the primary + encoding method used to serialize objects in Ethereum's execution layer. + The only purpose of RLP is to encode structure; encoding specific data + types (e.g. strings, floats) is left up to higher-order protocols. + + Parameters + ---------- + header : + Header of interest. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the header. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "header" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition check_gas_limit : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "gas_limit"; "parent_gas_limit" ] |) in + let _ := Constant.str " + Validates the gas limit for a block. + + The bounds of the gas limit, ``max_adjustment_delta``, is set as the + quotient of the parent block's gas limit and the + ``GAS_LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is + passed through as a parameter is greater than or equal to the *sum* of + the parent's gas and the adjustment delta then the limit for gas is too + high and fails this function's check. Similarly, if the limit is less + than or equal to the *difference* of the parent's gas and the adjustment + delta *or* the predefined ``GAS_LIMIT_MINIMUM`` then this function's + check fails because the gas limit doesn't allow for a sufficient or + reasonable amount of gas to be used on a block. + + Parameters + ---------- + gas_limit : + Gas limit to validate. + + parent_gas_limit : + Gas limit of the parent block. + + Returns + ------- + check : `bool` + True if gas limit constraints are satisfied, False otherwise. + " in + let max_adjustment_delta := + BinOp.floor_div (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) + |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + Constant.bool true + M.pure Constant.None_)). + +Definition calculate_block_difficulty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "block_number"; "block_timestamp"; "parent_timestamp"; "parent_difficulty"; "parent_has_ommers" ] |) in + let _ := Constant.str " + Computes difficulty of a block using its header and parent header. + + The difficulty is determined by the time the block was created after its + parent. The ``offset`` is calculated using the parent block's difficulty, + ``parent_difficulty``, and the timestamp between blocks. This offset is + then added to the parent difficulty and is stored as the ``difficulty`` + variable. If the time between the block and its parent is too short, the + offset will result in a positive number thus making the sum of + ``parent_difficulty`` and ``offset`` to be a greater value in order to + avoid mass forking. But, if the time is long enough, then the offset + results in a negative value making the block less difficult than + its parent. + + The base standard for a block's difficulty is the predefined value + set for the genesis block since it has no parent. So, a block + can't be less difficult than the genesis block, therefore each block's + difficulty is set to the maximum value between the calculated + difficulty and the ``GENESIS_DIFFICULTY``. + + Parameters + ---------- + block_number : + Block number of the block. + block_timestamp : + Timestamp of the block. + parent_timestamp : + Timestamp of the parent block. + parent_difficulty : + difficulty of the parent block. + parent_has_ommers: + does the parent have ommers. + + Returns + ------- + difficulty : `ethereum.base_types.Uint` + Computed difficulty for a block. + " in + let offset := + BinOp.mult (| + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "parent_difficulty" |) + ], + make_dict [] + |), + Constant.int 2048 + |), + M.call (| + M.get_name (| globals, "max" |), + make_list [ + BinOp.sub (| + (* if *) +M.if_then_else (| + M.get_name (| globals, "parent_has_ommers" |), +(* then *) +ltac:(M.monadic ( +Constant.int 2, + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "block_timestamp" |), + M.get_name (| globals, "parent_timestamp" |) + |) + ], + make_dict [] + |), + Constant.int 9 + |) + |); + UnOp.sub (| Constant.int 99 |) + ], + make_dict [] + |) + |) in + let difficulty := + BinOp.add (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "parent_difficulty" |) + ], + make_dict [] + |), + M.get_name (| globals, "offset" |) + |) in + let num_bomb_periods := + BinOp.sub (| + BinOp.floor_div (| + BinOp.sub (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "block_number" |) + ], + make_dict [] + |), + M.get_name (| globals, "BOMB_DELAY_BLOCKS" |) + |), + Constant.int 100000 + |), + Constant.int 2 + |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "max" |), + make_list [ + M.get_name (| globals, "difficulty" |); + M.get_name (| globals, "MINIMUM_DIFFICULTY" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/fork_types.v b/CoqOfPython/ethereum/london/fork_types.v index d12953d..5c7dac3 100644 --- a/CoqOfPython/ethereum/london/fork_types.v +++ b/CoqOfPython/ethereum/london/fork_types.v @@ -98,5 +98,4 @@ Definition encode_account : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/state.v b/CoqOfPython/ethereum/london/state.v index 7b038e5..c3290a6 100644 --- a/CoqOfPython/ethereum/london/state.v +++ b/CoqOfPython/ethereum/london/state.v @@ -126,13 +126,7 @@ Definition begin_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) ], make_dict [] - |); {M.get_name (| globals, "k" |): M.call (| - M.get_name (| globals, "copy_trie" |), - make_list [ - M.get_name (| globals, "t" |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)} ] + |); (* At expr: unsupported node type: DictComp *) ] ], make_dict [] |) in @@ -155,19 +149,6 @@ Definition commit_transaction : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "clear" |), - make_list [], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -193,19 +174,6 @@ Definition rollback_transaction : Value.t -> Value.t -> M := |) |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "clear" |), - make_list [], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -242,27 +210,8 @@ Definition get_account : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "account" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "account" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_ACCOUNT" |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -297,7 +246,6 @@ Definition get_account_optional : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "account" |) - |) in M.pure Constant.None_)). Definition set_account : Value.t -> Value.t -> M := @@ -377,15 +325,6 @@ Definition destroy_storage : Value.t -> Value.t -> M := Address of account whose storage is to be deleted. " in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -448,23 +387,6 @@ Definition get_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let value := @@ -486,7 +408,6 @@ Definition get_storage : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "value" |) - |) in M.pure Constant.None_)). Definition set_storage : Value.t -> Value.t -> M := @@ -507,14 +428,17 @@ Definition set_storage : Value.t -> Value.t -> M := value : `U256` Value to set at the key. " in - let _ := M.assert (| Compare.is_not (| M.call (| - M.get_name (| globals, "trie_get" |), - make_list [ - M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), Constant.None_ |) |) in + let _ := M.assert (| Compare.is_not (| + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + Constant.None_ + |) |) in let trie := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), @@ -524,24 +448,6 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let trie := - M.call (| - M.get_name (| globals, "Trie" |), - make_list [], - make_dict [] - |) in - let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), - M.get_name (| globals, "trie" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -554,15 +460,6 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), {} |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -587,26 +484,8 @@ Definition storage_root : Value.t -> Value.t -> M := " in let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "root" |), - make_list [ - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_TRIE_ROOT" |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -637,7 +516,6 @@ Definition state_root : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition account_exists : Value.t -> Value.t -> M := @@ -659,15 +537,17 @@ Definition account_exists : Value.t -> Value.t -> M := True if account exists in the state trie, False otherwise " in let _ := M.return_ (| - Compare.is_not (| M.call (| - M.get_name (| globals, "get_account_optional" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), Constant.None_ |) - |) in + Compare.is_not (| + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + Constant.None_ + |) M.pure Constant.None_)). Definition account_has_code_or_nonce : Value.t -> Value.t -> M := @@ -700,18 +580,23 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := |) in let _ := M.return_ (| BoolOp.or (| - Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( - Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |) + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |) )) |) - |) in M.pure Constant.None_)). Definition is_account_empty : Value.t -> Value.t -> M := @@ -744,23 +629,31 @@ Definition is_account_empty : Value.t -> Value.t -> M := |) in let _ := M.return_ (| BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |), ltac:(M.monadic ( - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "balance" |), + Constant.int 0 + |) )) |) )) |) - |) in M.pure Constant.None_)). Definition account_exists_and_is_empty : Value.t -> Value.t -> M := @@ -794,28 +687,39 @@ Definition account_exists_and_is_empty : Value.t -> Value.t -> M := |) in let _ := M.return_ (| BoolOp.and (| - Compare.is_not (| M.get_name (| globals, "account" |), Constant.None_ |), + Compare.is_not (| + M.get_name (| globals, "account" |), + Constant.None_ + |), ltac:(M.monadic ( BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |), ltac:(M.monadic ( - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "balance" |), + Constant.int 0 + |) )) |) )) |) )) |) - |) in M.pure Constant.None_)). Definition is_account_alive : Value.t -> Value.t -> M := @@ -846,36 +750,33 @@ Definition is_account_alive : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "account" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.bool false - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| UnOp.not (| BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |), ltac:(M.monadic ( - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "balance" |), + Constant.int 0 + |) )) |) )) |) |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -983,30 +884,6 @@ Definition touch_account : Value.t -> Value.t -> M := The address of the account that need to initialised. " in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "account_exists" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "set_account" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |); - M.get_name (| globals, "EMPTY_ACCOUNT" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -1111,23 +988,6 @@ Definition get_storage_original : Value.t -> Value.t -> M := Key of the storage slot. " in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -1143,22 +1003,6 @@ Definition get_storage_original : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "original_account_trie" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let original_value := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let original_value := M.call (| M.get_name (| globals, "trie_get" |), @@ -1180,5 +1024,4 @@ Definition get_storage_original : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "original_value" |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/transactions.v b/CoqOfPython/ethereum/london/transactions.v index 56996d9..afa27ec 100644 --- a/CoqOfPython/ethereum/london/transactions.v +++ b/CoqOfPython/ethereum/london/transactions.v @@ -112,87 +112,15 @@ Definition encode_transaction : Value.t -> Value.t -> M := Encode a transaction. Needed because non-legacy transactions aren't RLP. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "LegacyTransaction" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "tx" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "AccessListTransaction" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - BinOp.add (| - (* At constant: unsupported node type: Constant *), - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "tx" |) - ], - make_dict [] - |) - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "FeeMarketTransaction" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - BinOp.add (| - (* At constant: unsupported node type: Constant *), - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "tx" |) - ], - make_dict [] - |) - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.call (| + let _ := M.raise (| Some(M.call (| M.get_name (| globals, "Exception" |), make_list [ (* At expr: unsupported node type: JoinedStr *) ], make_dict [] - |) |) in + |)) M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -208,67 +136,8 @@ Definition decode_transaction : Value.t -> Value.t -> M := Decode a transaction. Needed because non-legacy transactions aren't RLP. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "Bytes" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), Constant.int 1 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), - make_list [ - M.get_name (| globals, "AccessListTransaction" |); - M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 1:(* At expr: unsupported node type: NoneType *) |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), Constant.int 2 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), - make_list [ - M.get_name (| globals, "FeeMarketTransaction" |); - M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 1:(* At expr: unsupported node type: NoneType *) |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidBlock" |) |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "tx" |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/trie.v b/CoqOfPython/ethereum/london/trie.v index 3effadb..ad941ab 100644 --- a/CoqOfPython/ethereum/london/trie.v +++ b/CoqOfPython/ethereum/london/trie.v @@ -202,96 +202,16 @@ Definition encode_internal_node : Value.t -> Value.t -> M := " in (* At stmt: unsupported node type: AnnAssign *) let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "node" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let unencoded := - (* At constant: unsupported node type: Constant *) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "LeafNode" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let unencoded := - make_tuple [ M.call (| - M.get_name (| globals, "nibble_list_to_compact" |), - make_list [ - M.get_field (| M.get_name (| globals, "node" |), "rest_of_key" |); - Constant.bool true - ], - make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "ExtensionNode" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let unencoded := - make_tuple [ M.call (| - M.get_name (| globals, "nibble_list_to_compact" |), - make_list [ - M.get_field (| M.get_name (| globals, "node" |), "key_segment" |); - Constant.bool false - ], - make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "BranchNode" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let unencoded := - BinOp.add (| - M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), - make_list [ - M.get_field (| M.get_name (| globals, "node" |), "value" |) - ] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.call (| + let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ (* At expr: unsupported node type: JoinedStr *) ], make_dict [] - |) |) in + |)) M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -309,23 +229,6 @@ Definition encode_internal_node : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "encoded" |) - ], - make_dict [] - |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "unencoded" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_name (| globals, "keccak256" |), @@ -334,7 +237,6 @@ Definition encode_internal_node : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -348,83 +250,8 @@ Definition encode_node : Value.t -> Value.t -> M := Currently mostly an unimplemented stub. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "storage_root" |), Constant.None_ |) |) in - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "encode_account" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "storage_root" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "U256" |) ] - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.call (| - M.get_name (| globals, "cast" |), - make_list [ - M.get_field (| M.get_name (| globals, "rlp" |), "RLP" |); - M.get_name (| globals, "node" |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "Bytes" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "node" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "previous_trie" |), "encode_node" |), @@ -434,7 +261,6 @@ Definition encode_node : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -486,7 +312,6 @@ Definition copy_trie : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition trie_set : Value.t -> Value.t -> M := @@ -508,26 +333,6 @@ Definition trie_set : Value.t -> Value.t -> M := Node to insert at `key`. " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "value" |), M.get_field (| M.get_name (| globals, "trie" |), "default" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "key" |), M.get_field (| M.get_name (| globals, "trie" |), "_data" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), M.get_name (| globals, "value" |) @@ -565,7 +370,6 @@ Definition trie_get : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition common_prefix_length : Value.t -> Value.t -> M := @@ -588,28 +392,6 @@ Definition common_prefix_length : Value.t -> Value.t -> M := make_dict [] |) do let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| M.get_name (| globals, "i" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "b" |) - ], - make_dict [] - |) |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "i" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -621,7 +403,6 @@ Definition common_prefix_length : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition nibble_list_to_compact : Value.t -> Value.t -> M := @@ -667,68 +448,6 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| BinOp.mod_ (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |), - Constant.int 2 - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_name (| globals, "compact" |), "append" |), - make_list [ - BinOp.mult (| - Constant.int 16, - BinOp.mult (| - Constant.int 2, - M.get_name (| globals, "is_leaf" |) - |) - |) - ], - make_dict [] - |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 0; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |); - Constant.int 2 - ], - make_dict [] - |) do - let _ := M.call (| - M.get_field (| M.get_name (| globals, "compact" |), "append" |), - make_list [ - BinOp.add (| - BinOp.mult (| - Constant.int 16, - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) - |), - M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) - |) - ], - make_dict [] - |) in - EndFor. - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ @@ -790,7 +509,6 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition bytes_to_nibble_list : Value.t -> Value.t -> M := @@ -868,7 +586,6 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition _prepare_trie : Value.t -> Value.t -> M := @@ -898,45 +615,6 @@ Definition _prepare_trie : Value.t -> Value.t -> M := make_dict [] |) do let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "value" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in - let address := - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in - let encoded_value := - M.call (| - M.get_name (| globals, "encode_node" |), - make_list [ - M.get_name (| globals, "value" |); - M.call (| - M.get_name (| globals, "get_storage_root" |), - make_list [ - M.get_name (| globals, "address" |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let encoded_value := M.call (| M.get_name (| globals, "encode_node" |), @@ -950,29 +628,16 @@ Definition _prepare_trie : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.not_eq (| M.get_name (| globals, "encoded_value" |), (* At constant: unsupported node type: Constant *) |); + Compare.not_eq (| + M.get_name (| globals, "encoded_value" |), + Constant.bytes "" + |); M.get_name (| globals, "AssertionError" |) ], make_dict [] |) in (* At stmt: unsupported node type: AnnAssign *) let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "trie" |), "secured" |), - (* then *) - ltac:(M.monadic ( - let key := - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let key := M.get_name (| globals, "preimage" |) in M.pure Constant.None_ @@ -990,7 +655,6 @@ Definition _prepare_trie : Value.t -> Value.t -> M := EndFor. let _ := M.return_ (| M.get_name (| globals, "mapped" |) - |) in M.pure Constant.None_)). Definition root : Value.t -> Value.t -> M := @@ -1044,41 +708,6 @@ Definition root : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "root_node" |) - ], - make_dict [] - |) - ], - make_dict [] - |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "root_node" |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -1095,7 +724,6 @@ Definition root : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -1122,23 +750,6 @@ Definition patricialize : Value.t -> Value.t -> M := Root node of `obj`. " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "obj" |) - ], - make_dict [] - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.None_ - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let arbitrary_key := @@ -1156,36 +767,10 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "obj" |) - ], - make_dict [] - |), Constant.int 1 |), - (* then *) - ltac:(M.monadic ( - let leaf := - M.call (| - M.get_name (| globals, "LeafNode" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |); - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) - ], - make_dict [] - |) in - let _ := M.return_ (| - M.get_name (| globals, "leaf" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let substring := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |) |) in let prefix_length := M.call (| M.get_name (| globals, "len" |), @@ -1204,7 +789,7 @@ Definition patricialize : Value.t -> Value.t -> M := M.get_name (| globals, "common_prefix_length" |), make_list [ M.get_name (| globals, "substring" |); - M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) + M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) ], make_dict [] |) @@ -1212,58 +797,10 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.break (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let prefix := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):BinOp.add (| - M.get_name (| globals, "level" |), - M.get_name (| globals, "prefix_length" |) - |) |) in - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "ExtensionNode" |), - make_list [ - M.get_name (| globals, "prefix" |); - M.call (| - M.get_name (| globals, "encode_internal_node" |), - make_list [ - M.call (| - M.get_name (| globals, "patricialize" |), - make_list [ - M.get_name (| globals, "obj" |); - BinOp.add (| - M.get_name (| globals, "level" |), - M.get_name (| globals, "prefix_length" |) - |) - ], - make_dict [] - |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) @@ -1283,44 +820,9 @@ Definition patricialize : Value.t -> Value.t -> M := |) in EndFor. let value := - (* At constant: unsupported node type: Constant *) in + Constant.bytes "" in For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "key" |) - ], - make_dict [] - |), M.get_name (| globals, "level" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); - make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "AssertionError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let value := - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) @@ -1332,26 +834,9 @@ Definition patricialize : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "BranchNode" |), make_list [ - [M.call (| - M.get_name (| globals, "encode_internal_node" |), - make_list [ - M.call (| - M.get_name (| globals, "patricialize" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "branches" |), M.get_name (| globals, "k" |) |); - BinOp.add (| - M.get_name (| globals, "level" |), - Constant.int 1 - |) - ], - make_dict [] - |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)]; + (* At expr: unsupported node type: ListComp *); M.get_name (| globals, "value" |) ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/utils/address.v b/CoqOfPython/ethereum/london/utils/address.v index 03314ab..2389981 100644 --- a/CoqOfPython/ethereum/london/utils/address.v +++ b/CoqOfPython/ethereum/london/utils/address.v @@ -70,11 +70,10 @@ Definition to_address : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), make_list [], make_dict [] - |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) + |), UnOp.sub (| Constant.int 20 |) |) ], make_dict [] |) - |) in M.pure Constant.None_)). Definition compute_contract_address : Value.t -> Value.t -> M := @@ -114,7 +113,7 @@ Definition compute_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -132,7 +131,6 @@ Definition compute_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition compute_create2_contract_address : Value.t -> Value.t -> M := @@ -160,7 +158,7 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := BinOp.add (| BinOp.add (| BinOp.add (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "ff", M.get_name (| globals, "address" |) |), M.get_name (| globals, "salt" |) @@ -182,7 +180,7 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -200,5 +198,4 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/utils/hexadecimal.v b/CoqOfPython/ethereum/london/utils/hexadecimal.v index f9e532a..2681b61 100644 --- a/CoqOfPython/ethereum/london/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/london/utils/hexadecimal.v @@ -66,7 +66,6 @@ Definition hex_to_root : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition hex_to_bloom : Value.t -> Value.t -> M := @@ -105,7 +104,6 @@ Definition hex_to_bloom : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition hex_to_address : Value.t -> Value.t -> M := @@ -151,5 +149,4 @@ Definition hex_to_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/utils/message.v b/CoqOfPython/ethereum/london/utils/message.v index bd5a2d5..3688c04 100644 --- a/CoqOfPython/ethereum/london/utils/message.v +++ b/CoqOfPython/ethereum/london/utils/message.v @@ -103,105 +103,14 @@ Definition prepare_message : Value.t -> Value.t -> M := Items containing contract creation or message call specific data. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "target" |); - M.get_name (| globals, "Bytes0" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let current_target := - M.call (| - M.get_name (| globals, "compute_contract_address" |), - make_list [ - M.get_name (| globals, "caller" |); - BinOp.sub (| - M.get_field (| M.call (| - M.get_name (| globals, "get_account" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "caller" |) - ], - make_dict [] - |), "nonce" |), - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 1 - ], - make_dict [] - |) - |) - ], - make_dict [] - |) in - let msg_data := - M.call (| - M.get_name (| globals, "Bytes" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |) in - let code := - M.get_name (| globals, "data" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "target" |); - M.get_name (| globals, "Address" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let current_target := - M.get_name (| globals, "target" |) in - let msg_data := - M.get_name (| globals, "data" |) in - let code := - M.get_field (| M.call (| - M.get_name (| globals, "get_account" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "target" |) - ], - make_dict [] - |), "code" |) in - let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "code_address" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let code_address := - M.get_name (| globals, "target" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.call (| + let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "Target must be address or empty bytes" ], make_dict [] - |) |) in + |)) M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -250,5 +159,4 @@ Definition prepare_message : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/vm/__init__.v b/CoqOfPython/ethereum/london/vm/__init__.v index 2ff63cd..49da5ae 100644 --- a/CoqOfPython/ethereum/london/vm/__init__.v +++ b/CoqOfPython/ethereum/london/vm/__init__.v @@ -147,28 +147,6 @@ Definition incorporate_child_on_success : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); - M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -201,57 +179,9 @@ Definition incorporate_child_on_error : Value.t -> Value.t -> M := The child evm to incorporate. " in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "RIPEMD160_ADDRESS" |), M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), - make_list [ - M.get_name (| globals, "RIPEMD160_ADDRESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |), M.get_name (| globals, "RIPEMD160_ADDRESS" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); - M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), - make_list [ - M.get_name (| globals, "RIPEMD160_ADDRESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign_op (| diff --git a/CoqOfPython/ethereum/london/vm/gas.v b/CoqOfPython/ethereum/london/vm/gas.v new file mode 100644 index 0000000..549060b --- /dev/null +++ b/CoqOfPython/ethereum/london/vm/gas.v @@ -0,0 +1,811 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Gas +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +EVM gas constants and calculators. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.trace. +Axiom ethereum_trace_GasAndRefund : + IsGlobalAlias globals ethereum.trace.globals "GasAndRefund". +Axiom ethereum_trace_evm_trace : + IsGlobalAlias globals ethereum.trace.globals "evm_trace". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". + +Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) +)). + +Definition GAS_BASE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 2 + ], + make_dict [] + |) +)). + +Definition GAS_VERY_LOW : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_STORAGE_SET : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 20000 + ], + make_dict [] + |) +)). + +Definition GAS_STORAGE_UPDATE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5000 + ], + make_dict [] + |) +)). + +Definition GAS_STORAGE_CLEAR_REFUND : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 4800 + ], + make_dict [] + |) +)). + +Definition GAS_LOW : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5 + ], + make_dict [] + |) +)). + +Definition GAS_MID : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 8 + ], + make_dict [] + |) +)). + +Definition GAS_HIGH : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 10 + ], + make_dict [] + |) +)). + +Definition GAS_EXPONENTIATION : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 10 + ], + make_dict [] + |) +)). + +Definition GAS_EXPONENTIATION_PER_BYTE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 50 + ], + make_dict [] + |) +)). + +Definition GAS_MEMORY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_KECCAK256 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 30 + ], + make_dict [] + |) +)). + +Definition GAS_KECCAK256_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 6 + ], + make_dict [] + |) +)). + +Definition GAS_COPY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_BLOCK_HASH : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 20 + ], + make_dict [] + |) +)). + +Definition GAS_LOG : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 375 + ], + make_dict [] + |) +)). + +Definition GAS_LOG_DATA : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 8 + ], + make_dict [] + |) +)). + +Definition GAS_LOG_TOPIC : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 375 + ], + make_dict [] + |) +)). + +Definition GAS_CREATE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 32000 + ], + make_dict [] + |) +)). + +Definition GAS_CODE_DEPOSIT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 200 + ], + make_dict [] + |) +)). + +Definition GAS_ZERO : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) +)). + +Definition GAS_NEW_ACCOUNT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 25000 + ], + make_dict [] + |) +)). + +Definition GAS_CALL_VALUE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 9000 + ], + make_dict [] + |) +)). + +Definition GAS_CALL_STIPEND : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 2300 + ], + make_dict [] + |) +)). + +Definition GAS_SELF_DESTRUCT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5000 + ], + make_dict [] + |) +)). + +Definition GAS_SELF_DESTRUCT_NEW_ACCOUNT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 25000 + ], + make_dict [] + |) +)). + +Definition GAS_ECRECOVER : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3000 + ], + make_dict [] + |) +)). + +Definition GAS_SHA256 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 60 + ], + make_dict [] + |) +)). + +Definition GAS_SHA256_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 12 + ], + make_dict [] + |) +)). + +Definition GAS_RIPEMD160 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 600 + ], + make_dict [] + |) +)). + +Definition GAS_RIPEMD160_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 120 + ], + make_dict [] + |) +)). + +Definition GAS_IDENTITY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 15 + ], + make_dict [] + |) +)). + +Definition GAS_IDENTITY_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_RETURN_DATA_COPY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_FAST_STEP : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5 + ], + make_dict [] + |) +)). + +Definition GAS_BLAKE2_PER_ROUND : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) +)). + +Definition GAS_COLD_SLOAD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 2100 + ], + make_dict [] + |) +)). + +Definition GAS_COLD_ACCOUNT_ACCESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 2600 + ], + make_dict [] + |) +)). + +Definition GAS_WARM_ACCESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 100 + ], + make_dict [] + |) +)). + +Definition ExtendMemory : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition MessageCallGas : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition charge_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "amount" ] |) in + let _ := Constant.str " + Subtracts `amount` from `evm.gas_left`. + + Parameters + ---------- + evm : + The current EVM. + amount : + The amount of gas the current operation requires. + + " in + let _ := M.call (| + M.get_name (| globals, "evm_trace" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "GasAndRefund" |), + make_list [ + M.get_name (| globals, "amount" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + let _ := M.assign_op (| + BinOp.sub, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "amount" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition calculate_memory_gas_cost : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "size_in_bytes" ] |) in + let _ := Constant.str " + Calculates the gas cost for allocating memory + to the smallest multiple of 32 bytes, + such that the allocated size is at least as big as the given size. + + Parameters + ---------- + size_in_bytes : + The size of the data in bytes. + + Returns + ------- + total_gas_cost : `ethereum.base_types.Uint` + The gas cost for storing data in memory. + " in + let size_in_words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "size_in_bytes" |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let linear_cost := + BinOp.mult (| + M.get_name (| globals, "size_in_words" |), + M.get_name (| globals, "GAS_MEMORY" |) + |) in + let quadratic_cost := + BinOp.floor_div (| + BinOp.pow (| + M.get_name (| globals, "size_in_words" |), + Constant.int 2 + |), + Constant.int 512 + |) in + let total_gas_cost := + BinOp.add (| + M.get_name (| globals, "linear_cost" |), + M.get_name (| globals, "quadratic_cost" |) + |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_)). + +Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "memory"; "extensions" ] |) in + let _ := Constant.str " + Calculates the gas amount to extend memory + + Parameters + ---------- + memory : + Memory contents of the EVM. + extensions: + List of extensions to be made to the memory. + Consists of a tuple of start position and size. + + Returns + ------- + extend_memory: `ExtendMemory` + " in + let size_to_extend := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let to_be_paid := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let current_size := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "memory" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + For make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ] in M.get_name (| globals, "extensions" |) do + let _ := + M.pure Constant.None_ + )) |) in + let before_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "current_size" |) + ], + make_dict [] + |) in + let after_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let size_to_extend := BinOp.add + BinOp.sub (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |) + BinOp.sub (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |) in + let already_paid := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "before_size" |) + ], + make_dict [] + |) in + let total_cost := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "after_size" |) + ], + make_dict [] + |) in + let to_be_paid := BinOp.add + BinOp.sub (| + M.get_name (| globals, "total_cost" |), + M.get_name (| globals, "already_paid" |) + |) + BinOp.sub (| + M.get_name (| globals, "total_cost" |), + M.get_name (| globals, "already_paid" |) + |) in + let current_size := + M.get_name (| globals, "after_size" |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ExtendMemory" |), + make_list [ + M.get_name (| globals, "to_be_paid" |); + M.get_name (| globals, "size_to_extend" |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition calculate_message_call_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "value"; "gas"; "gas_left"; "memory_cost"; "extra_gas"; "call_stipend" ] |) in + let _ := Constant.str " + Calculates the MessageCallGas (cost and stipend) for + executing call Opcodes. + + Parameters + ---------- + value: + The amount of `ETH` that needs to be transferred. + gas : + The amount of gas provided to the message-call. + gas_left : + The amount of gas left in the current frame. + memory_cost : + The amount needed to extend the memory in the current frame. + extra_gas : + The amount of gas needed for transferring value + creating a new + account inside a message call. + call_stipend : + The amount of stipend provided to a message call to execute code while + transferring value(ETH). + + Returns + ------- + message_call_gas: `MessageCallGas` + " in + let call_stipend := + (* if *) +M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let gas := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "max_message_call_gas" |), + make_list [ + BinOp.sub (| + BinOp.sub (| + M.get_name (| globals, "gas_left" |), + M.get_name (| globals, "memory_cost" |) + |), + M.get_name (| globals, "extra_gas" |) + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallGas" |), + make_list [ + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "extra_gas" |) + |); + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "call_stipend" |) + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition max_message_call_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "gas" ] |) in + let _ := Constant.str " + Calculates the maximum gas that is allowed for making a message call + + Parameters + ---------- + gas : + The amount of gas provided to the message-call. + + Returns + ------- + max_allowed_message_call_gas: `ethereum.base_types.Uint` + The maximum gas allowed for making the message-call. + " in + let _ := M.return_ (| + BinOp.sub (| + M.get_name (| globals, "gas" |), + BinOp.floor_div (| + M.get_name (| globals, "gas" |), + Constant.int 64 + |) + |) + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/london/vm/instructions/arithmetic.v index a8b5c61..581ba5d 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/london/vm/instructions/arithmetic.v @@ -273,22 +273,6 @@ Definition div : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let quotient := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let quotient := BinOp.floor_div (| M.get_name (| globals, "dividend" |), @@ -357,32 +341,7 @@ Definition sdiv : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let quotient := - Constant.int 0 in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_name (| globals, "dividend" |), UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "divisor" |), UnOp.sub (| Constant.int 1 |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let quotient := - UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let sign := M.call (| M.get_name (| globals, "get_sign" |), @@ -477,22 +436,6 @@ Definition mod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let remainder := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let remainder := BinOp.mod_ (| M.get_name (| globals, "x" |), @@ -561,16 +504,6 @@ Definition smod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let remainder := - Constant.int 0 in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let remainder := BinOp.mult (| M.call (| @@ -684,22 +617,6 @@ Definition addmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -795,22 +712,6 @@ Definition mulmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -980,16 +881,6 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "byte_num" |), Constant.int 31 |), - (* then *) - ltac:(M.monadic ( - let result := - M.get_name (| globals, "value" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let value_bytes := M.call (| M.get_name (| globals, "bytes" |), @@ -1012,29 +903,13 @@ Definition signextend : Value.t -> Value.t -> M := ], make_dict [] |) - |):(* At expr: unsupported node type: NoneType *) |) in + |) |) in let sign_bit := BinOp.r_shift (| M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), Constant.int 7 |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "sign_bit" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), - make_list [ - M.get_name (| globals, "value_bytes" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let num_bytes_prepend := BinOp.sub (| Constant.int 32, diff --git a/CoqOfPython/ethereum/london/vm/instructions/bitwise.v b/CoqOfPython/ethereum/london/vm/instructions/bitwise.v index 9f2f382..64cf120 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/london/vm/instructions/bitwise.v @@ -287,22 +287,6 @@ Definition get_byte : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "byte_index" |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let extra_bytes_to_right := BinOp.sub (| Constant.int 31, @@ -382,28 +366,6 @@ Definition bitwise_shl : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - BinOp.mod_ (| - BinOp.l_shift (| - M.get_name (| globals, "value" |), - M.get_name (| globals, "shift" |) - |), - M.get_name (| globals, "U256_CEIL_VALUE" |) - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -465,19 +427,6 @@ Definition bitwise_shr : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), - (* then *) - ltac:(M.monadic ( - let result := - BinOp.r_shift (| - M.get_name (| globals, "value" |), - M.get_name (| globals, "shift" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -543,42 +492,7 @@ Definition bitwise_sar : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), - make_list [ - BinOp.r_shift (| - M.get_name (| globals, "signed_value" |), - M.get_name (| globals, "shift" |) - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "signed_value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/london/vm/instructions/block.v b/CoqOfPython/ethereum/london/vm/instructions/block.v index 26c73a7..f857b79 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/block.v +++ b/CoqOfPython/ethereum/london/vm/instructions/block.v @@ -69,24 +69,6 @@ Definition block_hash : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.lt_e (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), M.get_name (| globals, "block_number" |) |), - ltac:(M.monadic ( - Compare.gt (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), BinOp.add (| - M.get_name (| globals, "block_number" |), - Constant.int 256 - |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let hash := - (* At constant: unsupported node type: Constant *) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let hash := M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), diff --git a/CoqOfPython/ethereum/london/vm/instructions/comparison.v b/CoqOfPython/ethereum/london/vm/instructions/comparison.v index fbc35f8..b8529d8 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/london/vm/instructions/comparison.v @@ -78,7 +78,10 @@ Definition less_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.lt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -145,7 +148,10 @@ Definition signed_less_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.lt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -205,7 +211,10 @@ Definition greater_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.gt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -272,7 +281,10 @@ Definition signed_greater_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.gt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -332,7 +344,10 @@ Definition equal : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.eq (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.eq (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -384,7 +399,10 @@ Definition is_zero : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.eq (| M.get_name (| globals, "x" |), Constant.int 0 |) + Compare.eq (| + M.get_name (| globals, "x" |), + Constant.int 0 + |) ], make_dict [] |) in diff --git a/CoqOfPython/ethereum/london/vm/instructions/control_flow.v b/CoqOfPython/ethereum/london/vm/instructions/control_flow.v index 04a79d9..d4e4eae 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/london/vm/instructions/control_flow.v @@ -109,15 +109,6 @@ Definition jump : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -177,29 +168,7 @@ Definition jumpi : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "conditional_value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let destination := - BinOp.add (| - M.get_field (| M.get_name (| globals, "evm" |), "pc" |), - Constant.int 1 - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let destination := M.get_name (| globals, "jump_dest" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/london/vm/instructions/environment.v b/CoqOfPython/ethereum/london/vm/instructions/environment.v index 530304e..10bc05b 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/london/vm/instructions/environment.v @@ -156,22 +156,6 @@ Definition balance : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "charge_gas" |), - make_list [ - M.get_name (| globals, "evm" |); - M.get_name (| globals, "GAS_WARM_ACCESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -538,7 +522,7 @@ Definition calldatacopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -706,7 +690,7 @@ Definition codecopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -805,22 +789,6 @@ Definition extcodesize : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "charge_gas" |), - make_list [ - M.get_name (| globals, "evm" |); - M.get_name (| globals, "GAS_WARM_ACCESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -958,28 +926,6 @@ Definition extcodecopy : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "charge_gas" |), - make_list [ - M.get_name (| globals, "evm" |); - BinOp.add (| - BinOp.add (| - M.get_name (| globals, "GAS_WARM_ACCESS" |), - M.get_name (| globals, "copy_gas_cost" |) - |), - M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1007,7 +953,7 @@ Definition extcodecopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -1178,28 +1124,31 @@ Definition returndatacopy : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt_e (| BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "return_data_start_position" |) - ], - make_dict [] + Compare.lt_e (| + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "return_data_start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) |), M.call (| - M.get_name (| globals, "Uint" |), + M.get_name (| globals, "len" |), make_list [ - M.get_name (| globals, "size" |) + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |) ], make_dict [] |) - |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "return_data" |) - ], - make_dict [] - |) |); + |); M.get_name (| globals, "OutOfBoundsRead" |) ], make_dict [] @@ -1208,15 +1157,12 @@ Definition returndatacopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in let value := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |):BinOp.add (| - M.get_name (| globals, "return_data_start_position" |), - M.get_name (| globals, "size" |) - |) |) in + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |) |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -1258,22 +1204,6 @@ Definition extcodehash : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "charge_gas" |), - make_list [ - M.get_name (| globals, "evm" |); - M.get_name (| globals, "GAS_WARM_ACCESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1301,22 +1231,6 @@ Definition extcodehash : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "account" |), M.get_name (| globals, "EMPTY_ACCOUNT" |) |), - (* then *) - ltac:(M.monadic ( - let codehash := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let codehash := M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), diff --git a/CoqOfPython/ethereum/london/vm/instructions/keccak.v b/CoqOfPython/ethereum/london/vm/instructions/keccak.v index cab9ffb..2c4b10e 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/london/vm/instructions/keccak.v @@ -137,7 +137,7 @@ Definition keccak : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/london/vm/instructions/log.v b/CoqOfPython/ethereum/london/vm/instructions/log.v index 4891a4d..e084e59 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/log.v +++ b/CoqOfPython/ethereum/london/vm/instructions/log.v @@ -161,7 +161,7 @@ Definition log_n : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/london/vm/instructions/memory.v b/CoqOfPython/ethereum/london/vm/instructions/memory.v index 1e1c8b0..86ba742 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/london/vm/instructions/memory.v @@ -121,7 +121,7 @@ Definition mstore : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -203,7 +203,7 @@ Definition mstore8 : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -288,7 +288,7 @@ Definition mload : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/london/vm/instructions/stack.v b/CoqOfPython/ethereum/london/vm/instructions/stack.v index 1eeda05..305af15 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/london/vm/instructions/stack.v @@ -188,13 +188,16 @@ Definition dup_n : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] - |) |); + Compare.lt (| + M.get_name (| globals, "item_number" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + |); M.get_name (| globals, "StackUnderflowError" |) ], make_dict [] @@ -260,13 +263,16 @@ Definition swap_n : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] - |) |); + Compare.lt (| + M.get_name (| globals, "item_number" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + |); M.get_name (| globals, "StackUnderflowError" |) ], make_dict [] diff --git a/CoqOfPython/ethereum/london/vm/instructions/storage.v b/CoqOfPython/ethereum/london/vm/instructions/storage.v index 2f0a831..b3c4045 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/london/vm/instructions/storage.v @@ -91,22 +91,6 @@ Definition sload : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "charge_gas" |), - make_list [ - M.get_name (| globals, "evm" |); - M.get_name (| globals, "GAS_WARM_ACCESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "add" |), make_list [ @@ -184,7 +168,10 @@ Definition sstore : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.gt (| M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), M.get_name (| globals, "GAS_CALL_STIPEND" |) |); + Compare.gt (| + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "GAS_CALL_STIPEND" |) + |); M.get_name (| globals, "OutOfGasError" |) ], make_dict [] @@ -218,189 +205,15 @@ Definition sstore : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_in (| make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "add" |), - make_list [ - make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ] - ], - make_dict [] - |) in - let gas_cost := BinOp.add - M.get_name (| globals, "GAS_COLD_SLOAD" |) - M.get_name (| globals, "GAS_COLD_SLOAD" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_name (| globals, "original_value" |), M.get_name (| globals, "current_value" |) |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_name (| globals, "current_value" |), M.get_name (| globals, "new_value" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let gas_cost := BinOp.add - M.get_name (| globals, "GAS_STORAGE_SET" |) - M.get_name (| globals, "GAS_STORAGE_SET" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let gas_cost := BinOp.add - BinOp.sub (| - M.get_name (| globals, "GAS_STORAGE_UPDATE" |), - M.get_name (| globals, "GAS_COLD_SLOAD" |) - |) - BinOp.sub (| - M.get_name (| globals, "GAS_STORAGE_UPDATE" |), - M.get_name (| globals, "GAS_COLD_SLOAD" |) - |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let gas_cost := BinOp.add M.get_name (| globals, "GAS_WARM_ACCESS" |) M.get_name (| globals, "GAS_WARM_ACCESS" |) in M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_eq (| M.get_name (| globals, "current_value" |), M.get_name (| globals, "new_value" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), - ltac:(M.monadic ( - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "new_value" |), Constant.int 0 |) - )) - |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), - M.call (| - M.get_name (| globals, "int" |), - make_list [ - M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.sub, - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), - M.call (| - M.get_name (| globals, "int" |), - make_list [ - M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "original_value" |), M.get_name (| globals, "new_value" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), - M.call (| - M.get_name (| globals, "int" |), - make_list [ - BinOp.sub (| - M.get_name (| globals, "GAS_STORAGE_SET" |), - M.get_name (| globals, "GAS_WARM_ACCESS" |) - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), - M.call (| - M.get_name (| globals, "int" |), - make_list [ - BinOp.sub (| - BinOp.sub (| - M.get_name (| globals, "GAS_STORAGE_UPDATE" |), - M.get_name (| globals, "GAS_COLD_SLOAD" |) - |), - M.get_name (| globals, "GAS_WARM_ACCESS" |) - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/london/vm/instructions/system.v b/CoqOfPython/ethereum/london/vm/instructions/system.v new file mode 100644 index 0000000..03931b2 --- /dev/null +++ b/CoqOfPython/ethereum/london/vm/instructions/system.v @@ -0,0 +1,1635 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) System Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM system related instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_account_exists_and_is_empty : + IsGlobalAlias globals state.globals "account_exists_and_is_empty". +Axiom state_account_has_code_or_nonce : + IsGlobalAlias globals state.globals "account_has_code_or_nonce". +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". +Axiom state_increment_nonce : + IsGlobalAlias globals state.globals "increment_nonce". +Axiom state_is_account_alive : + IsGlobalAlias globals state.globals "is_account_alive". +Axiom state_set_account_balance : + IsGlobalAlias globals state.globals "set_account_balance". + +Require utils.address. +Axiom utils_address_compute_contract_address : + IsGlobalAlias globals utils.address.globals "compute_contract_address". +Axiom utils_address_compute_create2_contract_address : + IsGlobalAlias globals utils.address.globals "compute_create2_contract_address". +Axiom utils_address_to_address : + IsGlobalAlias globals utils.address.globals "to_address". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". +Axiom __init___Message : + IsGlobalAlias globals __init__.globals "Message". +Axiom __init___incorporate_child_on_error : + IsGlobalAlias globals __init__.globals "incorporate_child_on_error". +Axiom __init___incorporate_child_on_success : + IsGlobalAlias globals __init__.globals "incorporate_child_on_success". + +Require exceptions. +Axiom exceptions_Revert : + IsGlobalAlias globals exceptions.globals "Revert". +Axiom exceptions_WriteInStaticContext : + IsGlobalAlias globals exceptions.globals "WriteInStaticContext". + +Require gas. +Axiom gas_GAS_CALL_VALUE : + IsGlobalAlias globals gas.globals "GAS_CALL_VALUE". +Axiom gas_GAS_COLD_ACCOUNT_ACCESS : + IsGlobalAlias globals gas.globals "GAS_COLD_ACCOUNT_ACCESS". +Axiom gas_GAS_CREATE : + IsGlobalAlias globals gas.globals "GAS_CREATE". +Axiom gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". +Axiom gas_GAS_NEW_ACCOUNT : + IsGlobalAlias globals gas.globals "GAS_NEW_ACCOUNT". +Axiom gas_GAS_SELF_DESTRUCT : + IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT". +Axiom gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : + IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". +Axiom gas_GAS_WARM_ACCESS : + IsGlobalAlias globals gas.globals "GAS_WARM_ACCESS". +Axiom gas_GAS_ZERO : + IsGlobalAlias globals gas.globals "GAS_ZERO". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_calculate_message_call_gas : + IsGlobalAlias globals gas.globals "calculate_message_call_gas". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". +Axiom gas_max_message_call_gas : + IsGlobalAlias globals gas.globals "max_message_call_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". +Axiom memory_memory_write : + IsGlobalAlias globals memory.globals "memory_write". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition generic_create : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "endowment"; "contract_address"; "memory_start_position"; "memory_size" ] |) in + let _ := Constant.str " + Core logic used by the `CREATE*` family of opcodes. + " in +(* At stmt: unsupported node type: ImportFrom *) + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "contract_address" |) + ], + make_dict [] + |) in + let create_message_gas := + M.call (| + M.get_name (| globals, "max_message_call_gas" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.sub, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "create_message_gas" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let sender_address := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in + let sender := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "sender_address" |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := + M.pure Constant.None_ + )) |) in + let call_data := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + let child_message := + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) in + let child_evm := + M.call (| + M.get_name (| globals, "process_create_message" |), + make_list [ + M.get_name (| globals, "child_message" |); + M.get_field (| M.get_name (| globals, "evm" |), "env" |) + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_success" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition create : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Creates a new account with associated code. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let endowment := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_position" |); M.get_name (| globals, "memory_size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_CREATE" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let contract_address := + M.call (| + M.get_name (| globals, "compute_contract_address" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "nonce" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "generic_create" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "endowment" |); + M.get_name (| globals, "contract_address" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition create2 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Creates a new account with associated code. + + It's similar to CREATE opcode except that the address of new account + depends on the init_code instead of the nonce of sender. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let endowment := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let salt := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_position" |); M.get_name (| globals, "memory_size" |) ] + ] + ], + make_dict [] + |) in + let call_data_words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_CREATE" |), + BinOp.mult (| + M.get_name (| globals, "GAS_KECCAK256_WORD" |), + M.get_name (| globals, "call_data_words" |) + |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let contract_address := + M.call (| + M.get_name (| globals, "compute_create2_contract_address" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "salt" |); + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "generic_create" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "endowment" |); + M.get_name (| globals, "contract_address" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition return_ : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Halts execution returning output data. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let memory_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_position" |); M.get_name (| globals, "memory_size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_ZERO" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "running" |), + Constant.bool false + |) in + let _ := M.pass (| |) in + M.pure Constant.None_)). + +Definition generic_call : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "gas"; "value"; "caller"; "to"; "code_address"; "should_transfer_value"; "is_staticcall"; "memory_input_start_position"; "memory_input_size"; "memory_output_start_position"; "memory_output_size" ] |) in + let _ := Constant.str " + Perform the core logic of the `CALL*` family of opcodes. + " in +(* At stmt: unsupported node type: ImportFrom *) + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let _ := + M.pure Constant.None_ + )) |) in + let call_data := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |) + ], + make_dict [] + |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "code_address" |) + ], + make_dict [] + |), "code" |) in + let child_message := + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) in + let child_evm := + M.call (| + M.get_name (| globals, "process_message" |), + make_list [ + M.get_name (| globals, "child_message" |); + M.get_field (| M.get_name (| globals, "evm" |), "env" |) + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_success" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let actual_output_size := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_name (| globals, "memory_output_size" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), Constant.None_:M.get_name (| globals, "actual_output_size" |) |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition call : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into an account. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let to := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "to" |) + ], + make_dict [] + |) in + let access_gas_cost := + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + M.pure Constant.None_ + )) |) in + let create_gas_cost := + (* if *) +M.if_then_else (| + BoolOp.or (| + M.call (| + M.get_name (| globals, "is_account_alive" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "to" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |) + )) + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let transfer_gas_cost := + (* if *) +M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "access_gas_cost" |), + M.get_name (| globals, "create_gas_cost" |) + |), + M.get_name (| globals, "transfer_gas_cost" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.or (| + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "value" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) + )) + |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let sender_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.get_name (| globals, "value" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "to" |); + Constant.bool true; + Constant.bool false; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition callcode : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into this account with alternative account’s code. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let code_address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let to := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "code_address" |) + ], + make_dict [] + |) in + let access_gas_cost := + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + M.pure Constant.None_ + )) |) in + let transfer_gas_cost := + (* if *) +M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + BinOp.add (| + M.get_name (| globals, "access_gas_cost" |), + M.get_name (| globals, "transfer_gas_cost" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let sender_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.get_name (| globals, "value" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "code_address" |); + Constant.bool true; + Constant.bool false; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition selfdestruct : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Halt execution and register account for later deletion. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let beneficiary := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let gas_cost := + M.get_name (| globals, "GAS_SELF_DESTRUCT" |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "gas_cost" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let originator := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in + let beneficiary_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |), "balance" |) in + let originator_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "originator" |) + ], + make_dict [] + |), "balance" |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |); + BinOp.add (| + M.get_name (| globals, "beneficiary_balance" |), + M.get_name (| globals, "originator_balance" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "originator" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |), "add" |), + make_list [ + M.get_name (| globals, "originator" |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "running" |), + Constant.bool false + |) in + let _ := M.pass (| |) in + M.pure Constant.None_)). + +Definition delegatecall : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into an account. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let code_address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "code_address" |) + ], + make_dict [] + |) in + let access_gas_cost := + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + M.pure Constant.None_ + )) |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + M.get_name (| globals, "access_gas_cost" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "value" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "caller" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "code_address" |); + Constant.bool false; + Constant.bool false; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition staticcall : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into an account. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let to := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "to" |) + ], + make_dict [] + |) in + let access_gas_cost := + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + M.pure Constant.None_ + )) |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + M.get_name (| globals, "access_gas_cost" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "to" |); + Constant.bool true; + Constant.bool true; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition revert : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stop execution and revert state changes, without consuming all provided gas + and also has the ability to return a reason + Parameters + ---------- + evm : + The current EVM frame. + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let output := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "bytes" |), + make_list [ + M.get_name (| globals, "output" |) + ], + make_dict [] + |) + |) in + let _ := M.raise (| Some(M.get_name (| globals, "Revert" |)) + let _ := M.pass (| |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/vm/interpreter.v b/CoqOfPython/ethereum/london/vm/interpreter.v index 8179355..024d2d5 100644 --- a/CoqOfPython/ethereum/london/vm/interpreter.v +++ b/CoqOfPython/ethereum/london/vm/interpreter.v @@ -184,91 +184,6 @@ Definition process_message_call : Value.t -> Value.t -> M := Output of the message call " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_name (| globals, "message" |), "target" |), M.call (| - M.get_name (| globals, "Bytes0" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let is_collision := - M.call (| - M.get_name (| globals, "account_has_code_or_nonce" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_field (| M.get_name (| globals, "message" |), "current_target" |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - M.get_name (| globals, "is_collision" |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "MessageCallOutput" |), - make_list [ - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |); - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |); - M.call (| - M.get_name (| globals, "tuple" |), - make_list [], - make_dict [] - |); - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |); - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |); - M.call (| - M.get_name (| globals, "AddressCollision" |), - make_list [], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let evm := - M.call (| - M.get_name (| globals, "process_create_message" |), - make_list [ - M.get_name (| globals, "message" |); - M.get_name (| globals, "env" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let evm := M.call (| M.get_name (| globals, "process_message" |), @@ -279,74 +194,11 @@ Definition process_message_call : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_field (| M.get_name (| globals, "message" |), "target" |) - ], - make_dict [] - |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), - make_list [ - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_field (| M.get_name (| globals, "message" |), "target" |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "evm" |), "error" |), - (* then *) - ltac:(M.monadic ( -(* At stmt: unsupported node type: AnnAssign *) - let accounts_to_delete := - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |) in - let touched_accounts := - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |) in - let refund_counter := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let logs := M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in let accounts_to_delete := @@ -390,7 +242,6 @@ Definition process_message_call : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). Definition process_create_message : Value.t -> Value.t -> M := @@ -452,28 +303,6 @@ Definition process_create_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), - (* then *) - ltac:(M.monadic ( - let contract_code := - M.get_field (| M.get_name (| globals, "evm" |), "output" |) in - let contract_code_gas := - BinOp.mult (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "contract_code" |) - ], - make_dict [] - |), - M.get_name (| globals, "GAS_CODE_DEPOSIT" |) - |) in -(* At stmt: unsupported node type: Try *) - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "rollback_transaction" |), make_list [ @@ -485,7 +314,6 @@ Definition process_create_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) - |) in M.pure Constant.None_)). Definition process_message : Value.t -> Value.t -> M := @@ -507,21 +335,6 @@ Definition process_message : Value.t -> Value.t -> M := Items containing execution specific objects " in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_field (| M.get_name (| globals, "message" |), "depth" |), M.get_name (| globals, "STACK_DEPTH_LIMIT" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "StackDepthLimitError" |), - make_list [ - Constant.str "Stack depth limit reached" - ], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -540,29 +353,6 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - M.get_field (| M.get_name (| globals, "message" |), "should_transfer_value" |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_field (| M.get_name (| globals, "message" |), "value" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "move_ether" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_field (| M.get_name (| globals, "message" |), "caller" |); - M.get_field (| M.get_name (| globals, "message" |), "current_target" |); - M.get_field (| M.get_name (| globals, "message" |), "value" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let evm := @@ -575,21 +365,6 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "evm" |), "error" |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "rollback_transaction" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "commit_transaction" |), make_list [ @@ -601,7 +376,6 @@ Definition process_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) - |) in M.pure Constant.None_)). Definition execute_code : Value.t -> Value.t -> M := @@ -641,5 +415,4 @@ Definition execute_code : Value.t -> Value.t -> M := (* At stmt: unsupported node type: Try *) let _ := M.return_ (| M.get_name (| globals, "evm" |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/vm/memory.v b/CoqOfPython/ethereum/london/vm/memory.v index fa8d906..4b107fd 100644 --- a/CoqOfPython/ethereum/london/vm/memory.v +++ b/CoqOfPython/ethereum/london/vm/memory.v @@ -45,22 +45,7 @@ Definition memory_write : Value.t -> Value.t -> M := Data to write to memory. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) - |) |), + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_)). @@ -86,23 +71,7 @@ Definition memory_read_bytes : Value.t -> Value.t -> M := Data read from memory. " in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |) - |) in + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |) M.pure Constant.None_)). Definition buffer_read : Value.t -> Value.t -> M := @@ -129,25 +98,9 @@ Definition buffer_read : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "right_pad_zero_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |); + M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |) |); M.get_name (| globals, "size" |) ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/london/vm/precompiled_contracts/alt_bn128.v index 19b83fc..abe4238 100644 --- a/CoqOfPython/ethereum/london/vm/precompiled_contracts/alt_bn128.v +++ b/CoqOfPython/ethereum/london/vm/precompiled_contracts/alt_bn128.v @@ -210,15 +210,6 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) in For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ] do let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "i" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -362,15 +353,6 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) in For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ] do let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "i" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -443,24 +425,6 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_eq (| BinOp.mod_ (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "data" |) - ], - make_dict [] - |), - Constant.int 192 - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let result := @@ -509,32 +473,11 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := Constant.int 32, M.get_name (| globals, "j" |) |) - |):BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "i" |), - Constant.int 192 - |), - BinOp.mult (| - Constant.int 32, - BinOp.add (| - M.get_name (| globals, "j" |), - Constant.int 1 - |) - |) |) |) ], make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "value" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -555,17 +498,20 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.call (| - M.get_field (| M.get_name (| globals, "p" |), "mul_by" |), - make_list [ - M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) - ], - make_dict [] - |), M.call (| - M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) |); + Compare.eq (| + M.call (| + M.get_field (| M.get_name (| globals, "p" |), "mul_by" |), + make_list [ + M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) + ], + make_dict [] + |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |); M.get_name (| globals, "OutOfGasError" |) ], make_dict [] @@ -573,87 +519,29 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.call (| - M.get_field (| M.get_name (| globals, "q" |), "mul_by" |), - make_list [ - M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) - ], - make_dict [] - |), M.call (| - M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) |); + Compare.eq (| + M.call (| + M.get_field (| M.get_name (| globals, "q" |), "mul_by" |), + make_list [ + M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) + ], + make_dict [] + |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |); M.get_name (| globals, "OutOfGasError" |) ], make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "p" |), M.call (| - M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_name (| globals, "q" |), M.call (| - M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let result := - BinOp.mult (| - M.get_name (| globals, "result" |), - M.call (| - M.get_name (| globals, "pairing" |), - make_list [ - M.get_name (| globals, "q" |); - M.get_name (| globals, "p" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "result" |), M.call (| - M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), - make_list [ - Constant.int 1 - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign (| - M.get_field (| M.get_name (| globals, "evm" |), "output" |), - M.call (| - M.get_field (| M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 1 - ], - make_dict [] - |), "to_be_bytes32" |), - make_list [], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| diff --git a/CoqOfPython/ethereum/london/vm/precompiled_contracts/blake2f.v b/CoqOfPython/ethereum/london/vm/precompiled_contracts/blake2f.v index 5903066..1647d48 100644 --- a/CoqOfPython/ethereum/london/vm/precompiled_contracts/blake2f.v +++ b/CoqOfPython/ethereum/london/vm/precompiled_contracts/blake2f.v @@ -55,13 +55,16 @@ Definition blake2f : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "data" |) - ], - make_dict [] - |), Constant.int 213 |); + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 213 + |); M.get_name (| globals, "InvalidParameter" |) ], make_dict [] @@ -96,10 +99,13 @@ Definition blake2f : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.in (| M.get_name (| globals, "f" |), make_list [ - Constant.int 0; - Constant.int 1 - ] |); + Compare.in (| + M.get_name (| globals, "f" |), + make_list [ + Constant.int 0; + Constant.int 1 + ] + |); M.get_name (| globals, "InvalidParameter" |) ], make_dict [] diff --git a/CoqOfPython/ethereum/london/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/london/vm/precompiled_contracts/ecrecover.v index cc351b5..0cbcf16 100644 --- a/CoqOfPython/ethereum/london/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/london/vm/precompiled_contracts/ecrecover.v @@ -188,60 +188,12 @@ Definition ecrecover : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 27 |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 28 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| Constant.int 0, M.get_name (| globals, "r" |) |), - ltac:(M.monadic ( - Compare.gt_e (| M.get_name (| globals, "r" |), M.get_name (| globals, "SECP256K1N" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| Constant.int 0, M.get_name (| globals, "s" |) |), - ltac:(M.monadic ( - Compare.gt_e (| M.get_name (| globals, "s" |), M.get_name (| globals, "SECP256K1N" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: Try *) @@ -252,7 +204,7 @@ Definition ecrecover : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12:Constant.int 32 |) in + |), Constant.int 12 |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/london/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/london/vm/precompiled_contracts/modexp.v index 544949e..3505244 100644 --- a/CoqOfPython/ethereum/london/vm/precompiled_contracts/modexp.v +++ b/CoqOfPython/ethereum/london/vm/precompiled_contracts/modexp.v @@ -192,30 +192,6 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_name (| globals, "base_length" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "modulus_length" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign (| - M.get_field (| M.get_name (| globals, "evm" |), "output" |), - M.call (| - M.get_name (| globals, "Bytes" |), - make_list [], - make_dict [] - |) - |) in - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let base := @@ -278,27 +254,6 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "modulus" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign (| - M.get_field (| M.get_name (| globals, "evm" |), "output" |), - BinOp.mult (| - M.call (| - M.get_name (| globals, "Bytes" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |), - M.get_name (| globals, "modulus_length" |) - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| @@ -383,7 +338,6 @@ Definition complexity : Value.t -> Value.t -> M := M.get_name (| globals, "words" |), Constant.int 2 |) - |) in M.pure Constant.None_)). Definition iterations : Value.t -> Value.t -> M := @@ -410,64 +364,7 @@ Definition iterations : Value.t -> Value.t -> M := Number of iterations. " in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.lt_e (| M.get_name (| globals, "exponent_length" |), Constant.int 32 |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "exponent_head" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let count := - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - Compare.lt_e (| M.get_name (| globals, "exponent_length" |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let bit_length := - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.call (| - M.get_field (| M.get_name (| globals, "exponent_head" |), "bit_length" |), - make_list [], - make_dict [] - |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "bit_length" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let bit_length := BinOp.sub - Constant.int 1 - Constant.int 1 in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let count := - M.get_name (| globals, "bit_length" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let length_part := BinOp.mult (| Constant.int 8, @@ -495,17 +392,6 @@ Definition iterations : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "bits_part" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let bits_part := BinOp.sub - Constant.int 1 - Constant.int 1 in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let count := @@ -532,7 +418,6 @@ Definition iterations : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition gas_cost : Value.t -> Value.t -> M := @@ -604,5 +489,4 @@ Definition gas_cost : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/vm/runtime.v b/CoqOfPython/ethereum/london/vm/runtime.v index 835b46c..2cd7652 100644 --- a/CoqOfPython/ethereum/london/vm/runtime.v +++ b/CoqOfPython/ethereum/london/vm/runtime.v @@ -67,50 +67,19 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := ], make_dict [] |) in - While Compare.lt (| M.get_name (| globals, "pc" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "code" |) - ], - make_dict [] - |) |) do + While Compare.lt (| + M.get_name (| globals, "pc" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) + |) do (* At stmt: unsupported node type: Try *) let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "current_opcode" |), M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), - make_list [ - M.get_name (| globals, "pc" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - (* At expr: unsupported node type: Compare *), - (* then *) - ltac:(M.monadic ( - let push_data_size := - BinOp.add (| - BinOp.sub (| - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) - |), - Constant.int 1 - |) in - let pc := BinOp.add - M.get_name (| globals, "push_data_size" |) - M.get_name (| globals, "push_data_size" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -121,5 +90,4 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := EndWhile. let _ := M.return_ (| M.get_name (| globals, "valid_jump_destinations" |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/vm/stack.v b/CoqOfPython/ethereum/london/vm/stack.v index 42ea42d..ea778df 100644 --- a/CoqOfPython/ethereum/london/vm/stack.v +++ b/CoqOfPython/ethereum/london/vm/stack.v @@ -49,21 +49,6 @@ Definition pop : Value.t -> Value.t -> M := " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "stack" |) - ], - make_dict [] - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "StackUnderflowError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -72,7 +57,6 @@ Definition pop : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). Definition push : Value.t -> Value.t -> M := @@ -91,21 +75,6 @@ Definition push : Value.t -> Value.t -> M := " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "stack" |) - ], - make_dict [] - |), Constant.int 1024 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "StackOverflowError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -116,5 +85,4 @@ Definition push : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/bloom.v b/CoqOfPython/ethereum/muir_glacier/bloom.v index 04b5d9f..04650ff 100644 --- a/CoqOfPython/ethereum/muir_glacier/bloom.v +++ b/CoqOfPython/ethereum/muir_glacier/bloom.v @@ -72,10 +72,7 @@ Definition add_to_bloom : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |):BinOp.add (| - M.get_name (| globals, "idx" |), - Constant.int 2 - |) |) + M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |) |) ], make_dict [] |), @@ -160,5 +157,4 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/fork.v b/CoqOfPython/ethereum/muir_glacier/fork.v new file mode 100644 index 0000000..972e704 --- /dev/null +++ b/CoqOfPython/ethereum/muir_glacier/fork.v @@ -0,0 +1,2160 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Specification +^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Entry point for the Ethereum specification. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Optional : + IsGlobalAlias globals typing.globals "Optional". +Axiom typing_Set_ : + IsGlobalAlias globals typing.globals "Set_". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". + +Require ethereum.crypto.elliptic_curve. +Axiom ethereum_crypto_elliptic_curve_SECP256K1N : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : + IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". + +Require ethereum.ethash. +Axiom ethereum_ethash_dataset_size : + IsGlobalAlias globals ethereum.ethash.globals "dataset_size". +Axiom ethereum_ethash_generate_cache : + IsGlobalAlias globals ethereum.ethash.globals "generate_cache". +Axiom ethereum_ethash_hashimoto_light : + IsGlobalAlias globals ethereum.ethash.globals "hashimoto_light". + +Require ethereum.exceptions. +Axiom ethereum_exceptions_InvalidBlock : + IsGlobalAlias globals ethereum.exceptions.globals "InvalidBlock". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require __init__. +Axiom __init___rlp : + IsGlobalAlias globals __init__.globals "rlp". + +Require base_types. +Axiom base_types_U64 : + IsGlobalAlias globals base_types.globals "U64". +Axiom base_types_U256 : + IsGlobalAlias globals base_types.globals "U256". +Axiom base_types_U256_CEIL_VALUE : + IsGlobalAlias globals base_types.globals "U256_CEIL_VALUE". +Axiom base_types_Bytes : + IsGlobalAlias globals base_types.globals "Bytes". +Axiom base_types_Uint : + IsGlobalAlias globals base_types.globals "Uint". + +Require __init__. +Axiom __init___vm : + IsGlobalAlias globals __init__.globals "vm". + +Require blocks. +Axiom blocks_Block : + IsGlobalAlias globals blocks.globals "Block". +Axiom blocks_Header : + IsGlobalAlias globals blocks.globals "Header". +Axiom blocks_Log : + IsGlobalAlias globals blocks.globals "Log". +Axiom blocks_Receipt : + IsGlobalAlias globals blocks.globals "Receipt". + +Require bloom. +Axiom bloom_logs_bloom : + IsGlobalAlias globals bloom.globals "logs_bloom". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". +Axiom fork_types_Bloom : + IsGlobalAlias globals fork_types.globals "Bloom". +Axiom fork_types_Root : + IsGlobalAlias globals fork_types.globals "Root". + +Require state. +Axiom state_State : + IsGlobalAlias globals state.globals "State". +Axiom state_account_exists_and_is_empty : + IsGlobalAlias globals state.globals "account_exists_and_is_empty". +Axiom state_create_ether : + IsGlobalAlias globals state.globals "create_ether". +Axiom state_destroy_account : + IsGlobalAlias globals state.globals "destroy_account". +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". +Axiom state_increment_nonce : + IsGlobalAlias globals state.globals "increment_nonce". +Axiom state_set_account_balance : + IsGlobalAlias globals state.globals "set_account_balance". +Axiom state_state_root : + IsGlobalAlias globals state.globals "state_root". + +Require transactions. +Axiom transactions_TX_BASE_COST : + IsGlobalAlias globals transactions.globals "TX_BASE_COST". +Axiom transactions_TX_CREATE_COST : + IsGlobalAlias globals transactions.globals "TX_CREATE_COST". +Axiom transactions_TX_DATA_COST_PER_NON_ZERO : + IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_NON_ZERO". +Axiom transactions_TX_DATA_COST_PER_ZERO : + IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_ZERO". +Axiom transactions_Transaction : + IsGlobalAlias globals transactions.globals "Transaction". + +Require trie. +Axiom trie_Trie : + IsGlobalAlias globals trie.globals "Trie". +Axiom trie_root : + IsGlobalAlias globals trie.globals "root". +Axiom trie_trie_set : + IsGlobalAlias globals trie.globals "trie_set". + +Require utils.message. +Axiom utils_message_prepare_message : + IsGlobalAlias globals utils.message.globals "prepare_message". + +Require vm.interpreter. +Axiom vm_interpreter_process_message_call : + IsGlobalAlias globals vm.interpreter.globals "process_message_call". + +Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mult (| + Constant.int 2, + BinOp.pow (| + Constant.int 10, + Constant.int 18 + |) + |) + ], + make_dict [] + |) +)). + +Definition GAS_LIMIT_ADJUSTMENT_FACTOR : Value.t := M.run ltac:(M.monadic ( + Constant.int 1024 +)). + +Definition GAS_LIMIT_MINIMUM : Value.t := M.run ltac:(M.monadic ( + Constant.int 5000 +)). + +Definition MINIMUM_DIFFICULTY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 131072 + ], + make_dict [] + |) +)). + +Definition MAX_OMMER_DEPTH : Value.t := M.run ltac:(M.monadic ( + Constant.int 6 +)). + +Definition BOMB_DELAY_BLOCKS : Value.t := M.run ltac:(M.monadic ( + Constant.int 9000000 +)). + +Definition EMPTY_OMMER_HASH : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_list [] + ], + make_dict [] + |) + ], + make_dict [] + |) +)). + +Definition BlockChain : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition apply_fork : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "old" ] |) in + let _ := Constant.str " + Transforms the state from the previous hard fork (`old`) into the block + chain object for this hard fork and returns it. + + When forks need to implement an irregular state transition, this function + is used to handle the irregularity. See the :ref:`DAO Fork ` for + an example. + + Parameters + ---------- + old : + Previous block chain object. + + Returns + ------- + new : `BlockChain` + Upgraded block chain object for this hard fork. + " in + let _ := M.return_ (| + M.get_name (| globals, "old" |) + M.pure Constant.None_)). + +Definition get_last_256_block_hashes : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "chain" ] |) in + let _ := Constant.str " + Obtain the list of hashes of the previous 256 blocks in order of + increasing block number. + + This function will return less hashes for the first 256 blocks. + + The ``BLOCKHASH`` opcode needs to access the latest hashes on the chain, + therefore this function retrieves them. + + Parameters + ---------- + chain : + History and current state. + + Returns + ------- + recent_block_hashes : `List[Hash32]` + Hashes of the recent 256 blocks in order of increasing block number. + " in + let recent_blocks := + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |) |) in + let _ := + M.pure Constant.None_ + )) |) in + let recent_block_hashes := + make_list [] in + For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_blocks" |) do + let prev_block_hash := + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), + make_list [ + M.get_name (| globals, "prev_block_hash" |) + ], + make_dict [] + |) in + EndFor. + let most_recent_block_hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_field (| M.get_subscript (| M.get_name (| globals, "recent_blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), + make_list [ + M.get_name (| globals, "most_recent_block_hash" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "recent_block_hashes" |) + M.pure Constant.None_)). + +Definition state_transition : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "chain"; "block" ] |) in + let _ := Constant.str " + Attempts to apply a block to an existing block chain. + + All parts of the block's contents need to be verified before being added + to the chain. Blocks are verified by ensuring that the contents of the + block make logical sense with the contents of the parent block. The + information in the block's header must also match the corresponding + information in the block. + + To implement Ethereum, in theory clients are only required to store the + most recent 255 blocks of the chain since as far as execution is + concerned, only those blocks are accessed. Practically, however, clients + should store more blocks to handle reorgs. + + Parameters + ---------- + chain : + History and current state. + block : + Block to apply to `chain`. + " in + let parent_header := + M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) in + let _ := M.call (| + M.get_name (| globals, "validate_header" |), + make_list [ + M.get_field (| M.get_name (| globals, "block" |), "header" |); + M.get_name (| globals, "parent_header" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "validate_ommers" |), + make_list [ + M.get_field (| M.get_name (| globals, "block" |), "ommers" |); + M.get_field (| M.get_name (| globals, "block" |), "header" |); + M.get_name (| globals, "chain" |) + ], + make_dict [] + |) in + let apply_body_output := + M.call (| + M.get_name (| globals, "apply_body" |), + make_list [ + M.get_field (| M.get_name (| globals, "chain" |), "state" |); + M.call (| + M.get_name (| globals, "get_last_256_block_hashes" |), + make_list [ + M.get_name (| globals, "chain" |) + ], + make_dict [] + |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "coinbase" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "number" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "gas_limit" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "timestamp" |); + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "difficulty" |); + M.get_field (| M.get_name (| globals, "block" |), "transactions" |); + M.get_field (| M.get_name (| globals, "block" |), "ommers" |); + M.get_field (| M.get_name (| globals, "chain" |), "chain_id" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_gas_used" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "gas_used" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "transactions_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "transactions_root" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "state_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "state_root" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "receipt_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "receipt_root" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_logs_bloom" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "bloom" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), "append" |), + make_list [ + M.get_name (| globals, "block" |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition validate_header : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header"; "parent_header" ] |) in + let _ := Constant.str " + Verifies a block header. + + In order to consider a block's header valid, the logic for the + quantities in the header should match the logic for the block itself. + For example the header timestamp should be greater than the block's parent + timestamp because the block was created *after* the parent block. + Additionally, the block's number should be directly following the parent + block's number since it is the next block in the sequence. + + Parameters + ---------- + header : + Header to check for correctness. + parent_header : + Parent Header of the header to check for correctness + " in + let parent_has_ommers := + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "parent_header" |), "ommers_hash" |), + M.get_name (| globals, "EMPTY_OMMER_HASH" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt (| + M.get_field (| M.get_name (| globals, "header" |), "timestamp" |), + M.get_field (| M.get_name (| globals, "parent_header" |), "timestamp" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "number" |), + BinOp.add (| + M.get_field (| M.get_name (| globals, "parent_header" |), "number" |), + Constant.int 1 + |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + M.call (| + M.get_name (| globals, "check_gas_limit" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "gas_limit" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "gas_limit" |) + ], + make_dict [] + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) + ], + make_dict [] + |), + Constant.int 32 + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let block_difficulty := + M.call (| + M.get_name (| globals, "calculate_block_difficulty" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "number" |); + M.get_field (| M.get_name (| globals, "header" |), "timestamp" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "timestamp" |); + M.get_field (| M.get_name (| globals, "parent_header" |), "difficulty" |); + M.get_name (| globals, "parent_has_ommers" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "difficulty" |), + M.get_name (| globals, "block_difficulty" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let block_parent_hash := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "parent_header" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |), + M.get_name (| globals, "block_parent_hash" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "validate_proof_of_work" |), + make_list [ + M.get_name (| globals, "header" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header" ] |) in + let _ := Constant.str " + Generate rlp hash of the header which is to be used for Proof-of-Work + verification. + + In other words, the PoW artefacts `mix_digest` and `nonce` are ignored + while calculating this hash. + + A particular PoW is valid for a single hash, that hash is computed by + this function. The `nonce` and `mix_digest` are omitted from this hash + because they are being changed by miners in their search for a sufficient + proof-of-work. + + Parameters + ---------- + header : + The header object for which the hash is to be generated. + + Returns + ------- + hash : `Hash32` + The PoW valid rlp hash of the passed in header. + " in + let header_data_without_pow_artefacts := + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |); + M.get_field (| M.get_name (| globals, "header" |), "ommers_hash" |); + M.get_field (| M.get_name (| globals, "header" |), "coinbase" |); + M.get_field (| M.get_name (| globals, "header" |), "state_root" |); + M.get_field (| M.get_name (| globals, "header" |), "transactions_root" |); + M.get_field (| M.get_name (| globals, "header" |), "receipt_root" |); + M.get_field (| M.get_name (| globals, "header" |), "bloom" |); + M.get_field (| M.get_name (| globals, "header" |), "difficulty" |); + M.get_field (| M.get_name (| globals, "header" |), "number" |); + M.get_field (| M.get_name (| globals, "header" |), "gas_limit" |); + M.get_field (| M.get_name (| globals, "header" |), "gas_used" |); + M.get_field (| M.get_name (| globals, "header" |), "timestamp" |); + M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) + ] in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "header_data_without_pow_artefacts" |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition validate_proof_of_work : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header" ] |) in + let _ := Constant.str " + Validates the Proof of Work constraints. + + In order to verify that a miner's proof-of-work is valid for a block, a + ``mix-digest`` and ``result`` are calculated using the ``hashimoto_light`` + hash function. The mix digest is a hash of the header and the nonce that + is passed through and it confirms whether or not proof-of-work was done + on the correct block. The result is the actual hash value of the block. + + Parameters + ---------- + header : + Header of interest. + " in + let header_hash := + M.call (| + M.get_name (| globals, "generate_header_hash_for_pow" |), + make_list [ + M.get_name (| globals, "header" |) + ], + make_dict [] + |) in + let cache := + M.call (| + M.get_name (| globals, "generate_cache" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "number" |) + ], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "mix_digest" |); M.get_name (| globals, "result" |) ], + M.call (| + M.get_name (| globals, "hashimoto_light" |), + make_list [ + M.get_name (| globals, "header_hash" |); + M.get_field (| M.get_name (| globals, "header" |), "nonce" |); + M.get_name (| globals, "cache" |); + M.call (| + M.get_name (| globals, "dataset_size" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "number" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_name (| globals, "mix_digest" |), + M.get_field (| M.get_name (| globals, "header" |), "mix_digest" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "result" |) + ], + make_dict [] + |), + BinOp.floor_div (| + M.get_name (| globals, "U256_CEIL_VALUE" |), + M.get_field (| M.get_name (| globals, "header" |), "difficulty" |) + |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition check_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx"; "gas_available"; "chain_id" ] |) in + let _ := Constant.str " + Check if the transaction is includable in the block. + + Parameters + ---------- + tx : + The transaction. + gas_available : + The gas remaining in the block. + chain_id : + The ID of the current chain. + + Returns + ------- + sender_address : + The sender of the transaction. + + Raises + ------ + InvalidBlock : + If the transaction is not includable. + " in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_name (| globals, "gas_available" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let sender_address := + M.call (| + M.get_name (| globals, "recover_sender" |), + make_list [ + M.get_name (| globals, "chain_id" |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "sender_address" |) + M.pure Constant.None_)). + +Definition make_receipt : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx"; "error"; "cumulative_gas_used"; "logs" ] |) in + let _ := Constant.str " + Make the receipt for a transaction that was executed. + + Parameters + ---------- + tx : + The executed transaction. + error : + Error in the top level frame of the transaction, if any. + cumulative_gas_used : + The total gas used so far in the block after the transaction was + executed. + logs : + The logs produced by the transaction. + + Returns + ------- + receipt : + The receipt for the transaction. + " in + let receipt := + M.call (| + M.get_name (| globals, "Receipt" |), + make_list [], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "receipt" |) + M.pure Constant.None_)). + +Definition ApplyBodyOutput : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition apply_body : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "block_hashes"; "coinbase"; "block_number"; "block_gas_limit"; "block_time"; "block_difficulty"; "transactions"; "ommers"; "chain_id" ] |) in + let _ := Constant.str " + Executes a block. + + Many of the contents of a block are stored in data structures called + tries. There is a transactions trie which is similar to a ledger of the + transactions stored in the current block. There is also a receipts trie + which stores the results of executing a transaction, like the post state + and gas used. This function creates and executes the block that is to be + added to the chain. + + Parameters + ---------- + state : + Current account state. + block_hashes : + List of hashes of the previous 256 blocks in the order of + increasing block number. + coinbase : + Address of account which receives block reward and transaction fees. + block_number : + Position of the block within the chain. + block_gas_limit : + Initial amount of gas available for execution in this block. + block_time : + Time the block was produced, measured in seconds since the epoch. + block_difficulty : + Difficulty of the block. + transactions : + Transactions included in the block. + ommers : + Headers of ancestor blocks which are not direct parents (formerly + uncles.) + chain_id : + ID of the executing chain. + + Returns + ------- + apply_body_output : `ApplyBodyOutput` + Output of applying the block body to the state. + " in + let gas_available := + M.get_name (| globals, "block_gas_limit" |) in +(* At stmt: unsupported node type: AnnAssign *) +(* At stmt: unsupported node type: AnnAssign *) +(* At stmt: unsupported node type: AnnAssign *) + For make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "tx" |) ] in M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "transactions" |) + ], + make_dict [] + |) do + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "transactions_trie" |); + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "i" |) + ], + make_dict [] + |) + ], + make_dict [] + |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) in + let sender_address := + M.call (| + M.get_name (| globals, "check_transaction" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "gas_available" |); + M.get_name (| globals, "chain_id" |) + ], + make_dict [] + |) in + let env := + M.call (| + M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |); M.get_name (| globals, "error" |) ], + M.call (| + M.get_name (| globals, "process_transaction" |), + make_list [ + M.get_name (| globals, "env" |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) in + let gas_available := BinOp.sub + M.get_name (| globals, "gas_used" |) + M.get_name (| globals, "gas_used" |) in + let receipt := + M.call (| + M.get_name (| globals, "make_receipt" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "error" |); + BinOp.sub (| + M.get_name (| globals, "block_gas_limit" |), + M.get_name (| globals, "gas_available" |) + |); + M.get_name (| globals, "logs" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "trie_set" |), + make_list [ + M.get_name (| globals, "receipts_trie" |); + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "i" |) + ], + make_dict [] + |) + ], + make_dict [] + |); + M.get_name (| globals, "receipt" |) + ], + make_dict [] + |) in + let block_logs := BinOp.add + M.get_name (| globals, "logs" |) + M.get_name (| globals, "logs" |) in + EndFor. + let _ := M.call (| + M.get_name (| globals, "pay_rewards" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "block_number" |); + M.get_name (| globals, "coinbase" |); + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |) in + let block_gas_used := + BinOp.sub (| + M.get_name (| globals, "block_gas_limit" |), + M.get_name (| globals, "gas_available" |) + |) in + let block_logs_bloom := + M.call (| + M.get_name (| globals, "logs_bloom" |), + make_list [ + M.get_name (| globals, "block_logs" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ApplyBodyOutput" |), + make_list [ + M.get_name (| globals, "block_gas_used" |); + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_name (| globals, "transactions_trie" |) + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_name (| globals, "receipts_trie" |) + ], + make_dict [] + |); + M.get_name (| globals, "block_logs_bloom" |); + M.call (| + M.get_name (| globals, "state_root" |), + make_list [ + M.get_name (| globals, "state" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition validate_ommers : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "ommers"; "block_header"; "chain" ] |) in + let _ := Constant.str " + Validates the ommers mentioned in the block. + + An ommer block is a block that wasn't canonically added to the + blockchain because it wasn't validated as fast as the canonical block + but was mined at the same time. + + To be considered valid, the ommers must adhere to the rules defined in + the Ethereum protocol. The maximum amount of ommers is 2 per block and + there cannot be duplicate ommers in a block. Many of the other ommer + constraints are listed in the in-line comments of this function. + + Parameters + ---------- + ommers : + List of ommers mentioned in the current block. + block_header: + The header of current block. + chain : + History and current state. + " in + let block_hash := + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "block_header" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + M.get_field (| M.get_name (| globals, "block_header" |), "ommers_hash" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.and (| + Compare.lt_e (| + Constant.int 1, + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |), + ltac:(M.monadic ( + Compare.lt (| + M.get_field (| M.get_name (| globals, "ommer" |), "number" |), + M.get_field (| M.get_name (| globals, "block_header" |), "number" |) + |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let ommer_parent_header := + M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), BinOp.sub (| + UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) |), + Constant.int 1 + |) |), "header" |) in + let _ := M.call (| + M.get_name (| globals, "validate_header" |), + make_list [ + M.get_name (| globals, "ommer" |); + M.get_name (| globals, "ommer_parent_header" |) + ], + make_dict [] + |) in + EndFor. + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + Constant.int 2 + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let ommers_hashes := + (* At expr: unsupported node type: ListComp *) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers_hashes" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_name (| globals, "set" |), + make_list [ + M.get_name (| globals, "ommers_hashes" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let recent_canonical_blocks := + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| BinOp.add (| + M.get_name (| globals, "MAX_OMMER_DEPTH" |), + Constant.int 1 + |) |) |) in + let recent_canonical_block_hashes := + (* At expr: unsupported node type: SetComp *) in +(* At stmt: unsupported node type: AnnAssign *) + For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_canonical_blocks" |) do + let recent_ommers_hashes := + M.call (| + M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), + make_list [ + (* At expr: unsupported node type: SetComp *) + ], + make_dict [] + |) in + EndFor. + For make_tuple [ M.get_name (| globals, "ommer_index" |); M.get_name (| globals, "ommer" |) ] in M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |) do + let ommer_hash := + M.get_subscript (| M.get_name (| globals, "ommers_hashes" |), M.get_name (| globals, "ommer_index" |) |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_eq (| + M.get_name (| globals, "ommer_hash" |), + M.get_name (| globals, "block_hash" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_in (| + M.get_name (| globals, "ommer_hash" |), + M.get_name (| globals, "recent_canonical_block_hashes" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_in (| + M.get_name (| globals, "ommer_hash" |), + M.get_name (| globals, "recent_ommers_hashes" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let ommer_age := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.and (| + Compare.lt_e (| + Constant.int 1, + M.get_name (| globals, "ommer_age" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_name (| globals, "ommer_age" |), + M.get_name (| globals, "MAX_OMMER_DEPTH" |) + |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.in (| + M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), + M.get_name (| globals, "recent_canonical_block_hashes" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), + M.get_field (| M.get_name (| globals, "block_header" |), "parent_hash" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_)). + +Definition pay_rewards : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "state"; "block_number"; "coinbase"; "ommers" ] |) in + let _ := Constant.str " + Pay rewards to the block miner as well as the ommers miners. + + The miner of the canonical block is rewarded with the predetermined + block reward, ``BLOCK_REWARD``, plus a variable award based off of the + number of ommer blocks that were mined around the same time, and included + in the canonical block's header. An ommer block is a block that wasn't + added to the canonical blockchain because it wasn't validated as fast as + the accepted block but was mined at the same time. Although not all blocks + that are mined are added to the canonical chain, miners are still paid a + reward for their efforts. This reward is called an ommer reward and is + calculated based on the number associated with the ommer block that they + mined. + + Parameters + ---------- + state : + Current account state. + block_number : + Position of the block within the chain. + coinbase : + Address of account which receives block reward and transaction fees. + ommers : + List of ommers mentioned in the current block. + " in + let miner_reward := + BinOp.add (| + M.get_name (| globals, "BLOCK_REWARD" |), + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + BinOp.floor_div (| + M.get_name (| globals, "BLOCK_REWARD" |), + Constant.int 32 + |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "create_ether" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "coinbase" |); + M.get_name (| globals, "miner_reward" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do + let ommer_age := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "block_number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) + ], + make_dict [] + |) in + let ommer_miner_reward := + BinOp.floor_div (| + BinOp.mult (| + BinOp.sub (| + Constant.int 8, + M.get_name (| globals, "ommer_age" |) + |), + M.get_name (| globals, "BLOCK_REWARD" |) + |), + Constant.int 8 + |) in + let _ := M.call (| + M.get_name (| globals, "create_ether" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_field (| M.get_name (| globals, "ommer" |), "coinbase" |); + M.get_name (| globals, "ommer_miner_reward" |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_)). + +Definition process_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "env"; "tx" ] |) in + let _ := Constant.str " + Execute a transaction against the provided environment. + + This function processes the actions needed to execute a transaction. + It decrements the sender's account after calculating the gas fee and + refunds them the proper amount after execution. Calling contracts, + deploying code, and incrementing nonces are all examples of actions that + happen within this function or from a call made within this function. + + Accounts that are marked for deletion are processed and destroyed after + execution. + + Parameters + ---------- + env : + Environment for the Ethereum Virtual Machine. + tx : + Transaction to execute. + + Returns + ------- + gas_left : `ethereum.base_types.U256` + Remaining gas after execution. + logs : `Tuple[ethereum.blocks.Log, ...]` + Logs generated during execution. + " in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + M.call (| + M.get_name (| globals, "validate_transaction" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let sender := + M.get_field (| M.get_name (| globals, "env" |), "origin" |) in + let sender_account := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |) in + let gas_fee := + BinOp.mult (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "sender_account" |), "nonce" |), + M.get_field (| M.get_name (| globals, "tx" |), "nonce" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt_e (| + M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), + BinOp.add (| + M.get_name (| globals, "gas_fee" |), + M.get_field (| M.get_name (| globals, "tx" |), "value" |) + |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "sender_account" |), "code" |), + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [], + make_dict [] + |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let gas := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.call (| + M.get_name (| globals, "calculate_intrinsic_cost" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) in + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |) in + let sender_balance_after_gas_fee := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), + M.get_name (| globals, "gas_fee" |) + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |); + M.get_name (| globals, "sender_balance_after_gas_fee" |) + ], + make_dict [] + |) in + let message := + M.call (| + M.get_name (| globals, "prepare_message" |), + make_list [ + M.get_name (| globals, "sender" |); + M.get_field (| M.get_name (| globals, "tx" |), "to" |); + M.get_field (| M.get_name (| globals, "tx" |), "value" |); + M.get_field (| M.get_name (| globals, "tx" |), "data" |); + M.get_name (| globals, "gas" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let output := + M.call (| + M.get_name (| globals, "process_message_call" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + let gas_used := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "output" |), "gas_left" |) + |) in + let gas_refund := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + BinOp.floor_div (| + M.get_name (| globals, "gas_used" |), + Constant.int 2 + |); + M.get_field (| M.get_name (| globals, "output" |), "refund_counter" |) + ], + make_dict [] + |) in + let gas_refund_amount := + BinOp.mult (| + BinOp.add (| + M.get_field (| M.get_name (| globals, "output" |), "gas_left" |), + M.get_name (| globals, "gas_refund" |) + |), + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) + |) in + let transaction_fee := + BinOp.mult (| + BinOp.sub (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "output" |), "gas_left" |) + |), + M.get_name (| globals, "gas_refund" |) + |), + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) + |) in + let total_gas_used := + BinOp.sub (| + M.get_name (| globals, "gas_used" |), + M.get_name (| globals, "gas_refund" |) + |) in + let sender_balance_after_refund := + BinOp.add (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |) + ], + make_dict [] + |), "balance" |), + M.get_name (| globals, "gas_refund_amount" |) + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "sender" |); + M.get_name (| globals, "sender_balance_after_refund" |) + ], + make_dict [] + |) in + let coinbase_balance_after_mining_fee := + BinOp.add (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |), "balance" |), + M.get_name (| globals, "transaction_fee" |) + |) in + let _ := + let _ := + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "accounts_to_delete" |) do + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + EndFor. + For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "touched_accounts" |) do + let _ := + M.pure Constant.None_ + )) |) in + EndFor. + let _ := M.return_ (| + make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |); M.get_field (| M.get_name (| globals, "output" |), "error" |) ] + M.pure Constant.None_)). + +Definition validate_transaction : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Verifies a transaction. + + The gas in a transaction gets used to pay for the intrinsic cost of + operations, therefore if there is insufficient gas then it would not + be possible to execute a transaction and it will be declared invalid. + + Additionally, the nonce of a transaction must not equal or exceed the + limit defined in `EIP-2681 `_. + In practice, defining the limit as ``2**64-1`` has no impact because + sending ``2**64-1`` transactions is improbable. It's not strictly + impossible though, ``2**64-1`` transactions is the entire capacity of the + Ethereum blockchain at 2022 gas limits for a little over 22 years. + + Parameters + ---------- + tx : + Transaction to validate. + + Returns + ------- + verified : `bool` + True if the transaction can be executed, or False otherwise. + " in + let _ := M.return_ (| + BoolOp.and (| + Compare.lt_e (| + M.call (| + M.get_name (| globals, "calculate_intrinsic_cost" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |), + M.get_field (| M.get_name (| globals, "tx" |), "gas" |) + |), + ltac:(M.monadic ( + Compare.lt (| + M.get_field (| M.get_name (| globals, "tx" |), "nonce" |), + BinOp.sub (| + BinOp.pow (| + Constant.int 2, + Constant.int 64 + |), + Constant.int 1 + |) + |) + )) + |) + M.pure Constant.None_)). + +Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Calculates the gas that is charged before execution is started. + + The intrinsic cost of the transaction is charged before execution has + begun. Functions/operations in the EVM cost money to execute so this + intrinsic cost is for the operations that need to be paid for as part of + the transaction. Data transfer, for example, is part of this intrinsic + cost. It costs ether to send data over the wire and that ether is + accounted for in the intrinsic cost calculated in this function. This + intrinsic cost must be calculated and paid for before execution in order + for all operations to be implemented. + + Parameters + ---------- + tx : + Transaction to compute the intrinsic cost of. + + Returns + ------- + verified : `ethereum.base_types.Uint` + The intrinsic cost of the transaction. + " in + let data_cost := + Constant.int 0 in + For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do + let _ := + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + M.pure Constant.None_ + )) |) in + EndFor. + let _ := + let create_cost := + Constant.int 0 in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "TX_BASE_COST" |), + M.get_name (| globals, "data_cost" |) + |), + M.get_name (| globals, "create_cost" |) + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition recover_sender : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "chain_id"; "tx" ] |) in + let _ := Constant.str " + Extracts the sender address from a transaction. + + The v, r, and s values are the three parts that make up the signature + of a transaction. In order to recover the sender of a transaction the two + components needed are the signature (``v``, ``r``, and ``s``) and the + signing hash of the transaction. The sender's public key can be obtained + with these two values and therefore the sender address can be retrieved. + + Parameters + ---------- + tx : + Transaction of interest. + chain_id : + ID of the executing chain. + + Returns + ------- + sender : `ethereum.fork_types.Address` + The address of the account that signed the transaction. + " in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "v" |); M.get_name (| globals, "r" |); M.get_name (| globals, "s" |) ], + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "v" |); M.get_field (| M.get_name (| globals, "tx" |), "r" |); M.get_field (| M.get_name (| globals, "tx" |), "s" |) ] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.and (| + Compare.lt (| + Constant.int 0, + M.get_name (| globals, "r" |) + |), + ltac:(M.monadic ( + Compare.lt (| + M.get_name (| globals, "r" |), + M.get_name (| globals, "SECP256K1N" |) + |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.and (| + Compare.lt (| + Constant.int 0, + M.get_name (| globals, "s" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_name (| globals, "s" |), + BinOp.floor_div (| + M.get_name (| globals, "SECP256K1N" |), + Constant.int 2 + |) + |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.or (| + Compare.eq (| + M.get_name (| globals, "v" |), + BinOp.add (| + Constant.int 35, + BinOp.mult (| + M.get_name (| globals, "chain_id" |), + Constant.int 2 + |) + |) + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "v" |), + BinOp.add (| + Constant.int 36, + BinOp.mult (| + M.get_name (| globals, "chain_id" |), + Constant.int 2 + |) + |) + |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + BinOp.sub (| + BinOp.sub (| + M.get_name (| globals, "v" |), + Constant.int 35 + |), + BinOp.mult (| + M.get_name (| globals, "chain_id" |), + Constant.int 2 + |) + |); + M.call (| + M.get_name (| globals, "signing_hash_155" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "chain_id" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_subscript (| M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), Constant.int 12 |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition signing_hash_pre155 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx" ] |) in + let _ := Constant.str " + Compute the hash of a transaction used in a legacy (pre EIP 155) signature. + + Parameters + ---------- + tx : + Transaction of interest. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the transaction. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "nonce" |); M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |); M.get_field (| M.get_name (| globals, "tx" |), "gas" |); M.get_field (| M.get_name (| globals, "tx" |), "to" |); M.get_field (| M.get_name (| globals, "tx" |), "value" |); M.get_field (| M.get_name (| globals, "tx" |), "data" |) ] + ], + make_dict [] + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition signing_hash_155 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "tx"; "chain_id" ] |) in + let _ := Constant.str " + Compute the hash of a transaction used in a EIP 155 signature. + + Parameters + ---------- + tx : + Transaction of interest. + chain_id : + The id of the current chain. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the transaction. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + make_tuple [ M.get_field (| M.get_name (| globals, "tx" |), "nonce" |); M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |); M.get_field (| M.get_name (| globals, "tx" |), "gas" |); M.get_field (| M.get_name (| globals, "tx" |), "to" |); M.get_field (| M.get_name (| globals, "tx" |), "value" |); M.get_field (| M.get_name (| globals, "tx" |), "data" |); M.get_name (| globals, "chain_id" |); M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) ] + ], + make_dict [] + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition compute_header_hash : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "header" ] |) in + let _ := Constant.str " + Computes the hash of a block header. + + The header hash of a block is the canonical hash that is used to refer + to a specific block and completely distinguishes a block from another. + + ``keccak256`` is a function that produces a 256 bit hash of any input. + It also takes in any number of bytes as an input and produces a single + hash for them. A hash is a completely unique output for a single input. + So an input corresponds to one unique hash that can be used to identify + the input exactly. + + Prior to using the ``keccak256`` hash function, the header must be + encoded using the Recursive-Length Prefix. See :ref:`rlp`. + RLP encoding the header converts it into a space-efficient format that + allows for easy transfer of data between nodes. The purpose of RLP is to + encode arbitrarily nested arrays of binary data, and RLP is the primary + encoding method used to serialize objects in Ethereum's execution layer. + The only purpose of RLP is to encode structure; encoding specific data + types (e.g. strings, floats) is left up to higher-order protocols. + + Parameters + ---------- + header : + Header of interest. + + Returns + ------- + hash : `ethereum.crypto.hash.Hash32` + Hash of the header. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "header" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition check_gas_limit : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "gas_limit"; "parent_gas_limit" ] |) in + let _ := Constant.str " + Validates the gas limit for a block. + + The bounds of the gas limit, ``max_adjustment_delta``, is set as the + quotient of the parent block's gas limit and the + ``GAS_LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is + passed through as a parameter is greater than or equal to the *sum* of + the parent's gas and the adjustment delta then the limit for gas is too + high and fails this function's check. Similarly, if the limit is less + than or equal to the *difference* of the parent's gas and the adjustment + delta *or* the predefined ``GAS_LIMIT_MINIMUM`` then this function's + check fails because the gas limit doesn't allow for a sufficient or + reasonable amount of gas to be used on a block. + + Parameters + ---------- + gas_limit : + Gas limit to validate. + + parent_gas_limit : + Gas limit of the parent block. + + Returns + ------- + check : `bool` + True if gas limit constraints are satisfied, False otherwise. + " in + let max_adjustment_delta := + BinOp.floor_div (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) + |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + Constant.bool true + M.pure Constant.None_)). + +Definition calculate_block_difficulty : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "block_number"; "block_timestamp"; "parent_timestamp"; "parent_difficulty"; "parent_has_ommers" ] |) in + let _ := Constant.str " + Computes difficulty of a block using its header and parent header. + + The difficulty is determined by the time the block was created after its + parent. The ``offset`` is calculated using the parent block's difficulty, + ``parent_difficulty``, and the timestamp between blocks. This offset is + then added to the parent difficulty and is stored as the ``difficulty`` + variable. If the time between the block and its parent is too short, the + offset will result in a positive number thus making the sum of + ``parent_difficulty`` and ``offset`` to be a greater value in order to + avoid mass forking. But, if the time is long enough, then the offset + results in a negative value making the block less difficult than + its parent. + + The base standard for a block's difficulty is the predefined value + set for the genesis block since it has no parent. So, a block + can't be less difficult than the genesis block, therefore each block's + difficulty is set to the maximum value between the calculated + difficulty and the ``GENESIS_DIFFICULTY``. + + Parameters + ---------- + block_number : + Block number of the block. + block_timestamp : + Timestamp of the block. + parent_timestamp : + Timestamp of the parent block. + parent_difficulty : + difficulty of the parent block. + parent_has_ommers: + does the parent have ommers. + + Returns + ------- + difficulty : `ethereum.base_types.Uint` + Computed difficulty for a block. + " in + let offset := + BinOp.mult (| + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "parent_difficulty" |) + ], + make_dict [] + |), + Constant.int 2048 + |), + M.call (| + M.get_name (| globals, "max" |), + make_list [ + BinOp.sub (| + (* if *) +M.if_then_else (| + M.get_name (| globals, "parent_has_ommers" |), +(* then *) +ltac:(M.monadic ( +Constant.int 2, + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "block_timestamp" |), + M.get_name (| globals, "parent_timestamp" |) + |) + ], + make_dict [] + |), + Constant.int 9 + |) + |); + UnOp.sub (| Constant.int 99 |) + ], + make_dict [] + |) + |) in + let difficulty := + BinOp.add (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "parent_difficulty" |) + ], + make_dict [] + |), + M.get_name (| globals, "offset" |) + |) in + let num_bomb_periods := + BinOp.sub (| + BinOp.floor_div (| + BinOp.sub (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "block_number" |) + ], + make_dict [] + |), + M.get_name (| globals, "BOMB_DELAY_BLOCKS" |) + |), + Constant.int 100000 + |), + Constant.int 2 + |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "max" |), + make_list [ + M.get_name (| globals, "difficulty" |); + M.get_name (| globals, "MINIMUM_DIFFICULTY" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/fork_types.v b/CoqOfPython/ethereum/muir_glacier/fork_types.v index d12953d..5c7dac3 100644 --- a/CoqOfPython/ethereum/muir_glacier/fork_types.v +++ b/CoqOfPython/ethereum/muir_glacier/fork_types.v @@ -98,5 +98,4 @@ Definition encode_account : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/state.v b/CoqOfPython/ethereum/muir_glacier/state.v index 7b038e5..c3290a6 100644 --- a/CoqOfPython/ethereum/muir_glacier/state.v +++ b/CoqOfPython/ethereum/muir_glacier/state.v @@ -126,13 +126,7 @@ Definition begin_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) ], make_dict [] - |); {M.get_name (| globals, "k" |): M.call (| - M.get_name (| globals, "copy_trie" |), - make_list [ - M.get_name (| globals, "t" |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)} ] + |); (* At expr: unsupported node type: DictComp *) ] ], make_dict [] |) in @@ -155,19 +149,6 @@ Definition commit_transaction : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "clear" |), - make_list [], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -193,19 +174,6 @@ Definition rollback_transaction : Value.t -> Value.t -> M := |) |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "clear" |), - make_list [], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -242,27 +210,8 @@ Definition get_account : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "account" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "account" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_ACCOUNT" |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -297,7 +246,6 @@ Definition get_account_optional : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "account" |) - |) in M.pure Constant.None_)). Definition set_account : Value.t -> Value.t -> M := @@ -377,15 +325,6 @@ Definition destroy_storage : Value.t -> Value.t -> M := Address of account whose storage is to be deleted. " in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -448,23 +387,6 @@ Definition get_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let value := @@ -486,7 +408,6 @@ Definition get_storage : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "value" |) - |) in M.pure Constant.None_)). Definition set_storage : Value.t -> Value.t -> M := @@ -507,14 +428,17 @@ Definition set_storage : Value.t -> Value.t -> M := value : `U256` Value to set at the key. " in - let _ := M.assert (| Compare.is_not (| M.call (| - M.get_name (| globals, "trie_get" |), - make_list [ - M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), Constant.None_ |) |) in + let _ := M.assert (| Compare.is_not (| + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + Constant.None_ + |) |) in let trie := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), @@ -524,24 +448,6 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let trie := - M.call (| - M.get_name (| globals, "Trie" |), - make_list [], - make_dict [] - |) in - let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), - M.get_name (| globals, "trie" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -554,15 +460,6 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), {} |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -587,26 +484,8 @@ Definition storage_root : Value.t -> Value.t -> M := " in let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "root" |), - make_list [ - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_TRIE_ROOT" |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -637,7 +516,6 @@ Definition state_root : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition account_exists : Value.t -> Value.t -> M := @@ -659,15 +537,17 @@ Definition account_exists : Value.t -> Value.t -> M := True if account exists in the state trie, False otherwise " in let _ := M.return_ (| - Compare.is_not (| M.call (| - M.get_name (| globals, "get_account_optional" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), Constant.None_ |) - |) in + Compare.is_not (| + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + Constant.None_ + |) M.pure Constant.None_)). Definition account_has_code_or_nonce : Value.t -> Value.t -> M := @@ -700,18 +580,23 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := |) in let _ := M.return_ (| BoolOp.or (| - Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( - Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |) + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |) )) |) - |) in M.pure Constant.None_)). Definition is_account_empty : Value.t -> Value.t -> M := @@ -744,23 +629,31 @@ Definition is_account_empty : Value.t -> Value.t -> M := |) in let _ := M.return_ (| BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |), ltac:(M.monadic ( - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "balance" |), + Constant.int 0 + |) )) |) )) |) - |) in M.pure Constant.None_)). Definition account_exists_and_is_empty : Value.t -> Value.t -> M := @@ -794,28 +687,39 @@ Definition account_exists_and_is_empty : Value.t -> Value.t -> M := |) in let _ := M.return_ (| BoolOp.and (| - Compare.is_not (| M.get_name (| globals, "account" |), Constant.None_ |), + Compare.is_not (| + M.get_name (| globals, "account" |), + Constant.None_ + |), ltac:(M.monadic ( BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |), ltac:(M.monadic ( - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "balance" |), + Constant.int 0 + |) )) |) )) |) )) |) - |) in M.pure Constant.None_)). Definition is_account_alive : Value.t -> Value.t -> M := @@ -846,36 +750,33 @@ Definition is_account_alive : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "account" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.bool false - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| UnOp.not (| BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |), ltac:(M.monadic ( - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "balance" |), + Constant.int 0 + |) )) |) )) |) |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -983,30 +884,6 @@ Definition touch_account : Value.t -> Value.t -> M := The address of the account that need to initialised. " in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "account_exists" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "set_account" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |); - M.get_name (| globals, "EMPTY_ACCOUNT" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -1111,23 +988,6 @@ Definition get_storage_original : Value.t -> Value.t -> M := Key of the storage slot. " in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -1143,22 +1003,6 @@ Definition get_storage_original : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "original_account_trie" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let original_value := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let original_value := M.call (| M.get_name (| globals, "trie_get" |), @@ -1180,5 +1024,4 @@ Definition get_storage_original : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "original_value" |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/trie.v b/CoqOfPython/ethereum/muir_glacier/trie.v index 0a7e5af..22e6b66 100644 --- a/CoqOfPython/ethereum/muir_glacier/trie.v +++ b/CoqOfPython/ethereum/muir_glacier/trie.v @@ -202,96 +202,16 @@ Definition encode_internal_node : Value.t -> Value.t -> M := " in (* At stmt: unsupported node type: AnnAssign *) let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "node" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let unencoded := - (* At constant: unsupported node type: Constant *) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "LeafNode" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let unencoded := - make_tuple [ M.call (| - M.get_name (| globals, "nibble_list_to_compact" |), - make_list [ - M.get_field (| M.get_name (| globals, "node" |), "rest_of_key" |); - Constant.bool true - ], - make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "ExtensionNode" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let unencoded := - make_tuple [ M.call (| - M.get_name (| globals, "nibble_list_to_compact" |), - make_list [ - M.get_field (| M.get_name (| globals, "node" |), "key_segment" |); - Constant.bool false - ], - make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "BranchNode" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let unencoded := - BinOp.add (| - M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), - make_list [ - M.get_field (| M.get_name (| globals, "node" |), "value" |) - ] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.call (| + let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ (* At expr: unsupported node type: JoinedStr *) ], make_dict [] - |) |) in + |)) M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -309,23 +229,6 @@ Definition encode_internal_node : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "encoded" |) - ], - make_dict [] - |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "unencoded" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_name (| globals, "keccak256" |), @@ -334,7 +237,6 @@ Definition encode_internal_node : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -348,83 +250,8 @@ Definition encode_node : Value.t -> Value.t -> M := Currently mostly an unimplemented stub. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "storage_root" |), Constant.None_ |) |) in - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "encode_account" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "storage_root" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - make_tuple [ M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "U256" |) ] - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.call (| - M.get_name (| globals, "cast" |), - make_list [ - M.get_field (| M.get_name (| globals, "rlp" |), "RLP" |); - M.get_name (| globals, "node" |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "Bytes" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "node" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "previous_trie" |), "encode_node" |), @@ -434,7 +261,6 @@ Definition encode_node : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -486,7 +312,6 @@ Definition copy_trie : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition trie_set : Value.t -> Value.t -> M := @@ -508,26 +333,6 @@ Definition trie_set : Value.t -> Value.t -> M := Node to insert at `key`. " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "value" |), M.get_field (| M.get_name (| globals, "trie" |), "default" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "key" |), M.get_field (| M.get_name (| globals, "trie" |), "_data" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), M.get_name (| globals, "value" |) @@ -565,7 +370,6 @@ Definition trie_get : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition common_prefix_length : Value.t -> Value.t -> M := @@ -588,28 +392,6 @@ Definition common_prefix_length : Value.t -> Value.t -> M := make_dict [] |) do let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| M.get_name (| globals, "i" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "b" |) - ], - make_dict [] - |) |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "i" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -621,7 +403,6 @@ Definition common_prefix_length : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition nibble_list_to_compact : Value.t -> Value.t -> M := @@ -667,68 +448,6 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| BinOp.mod_ (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |), - Constant.int 2 - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_name (| globals, "compact" |), "append" |), - make_list [ - BinOp.mult (| - Constant.int 16, - BinOp.mult (| - Constant.int 2, - M.get_name (| globals, "is_leaf" |) - |) - |) - ], - make_dict [] - |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 0; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |); - Constant.int 2 - ], - make_dict [] - |) do - let _ := M.call (| - M.get_field (| M.get_name (| globals, "compact" |), "append" |), - make_list [ - BinOp.add (| - BinOp.mult (| - Constant.int 16, - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) - |), - M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) - |) - ], - make_dict [] - |) in - EndFor. - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ @@ -790,7 +509,6 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition bytes_to_nibble_list : Value.t -> Value.t -> M := @@ -868,7 +586,6 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition _prepare_trie : Value.t -> Value.t -> M := @@ -898,45 +615,6 @@ Definition _prepare_trie : Value.t -> Value.t -> M := make_dict [] |) do let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "value" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in - let address := - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in - let encoded_value := - M.call (| - M.get_name (| globals, "encode_node" |), - make_list [ - M.get_name (| globals, "value" |); - M.call (| - M.get_name (| globals, "get_storage_root" |), - make_list [ - M.get_name (| globals, "address" |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let encoded_value := M.call (| M.get_name (| globals, "encode_node" |), @@ -950,29 +628,16 @@ Definition _prepare_trie : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.not_eq (| M.get_name (| globals, "encoded_value" |), (* At constant: unsupported node type: Constant *) |); + Compare.not_eq (| + M.get_name (| globals, "encoded_value" |), + Constant.bytes "" + |); M.get_name (| globals, "AssertionError" |) ], make_dict [] |) in (* At stmt: unsupported node type: AnnAssign *) let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "trie" |), "secured" |), - (* then *) - ltac:(M.monadic ( - let key := - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let key := M.get_name (| globals, "preimage" |) in M.pure Constant.None_ @@ -990,7 +655,6 @@ Definition _prepare_trie : Value.t -> Value.t -> M := EndFor. let _ := M.return_ (| M.get_name (| globals, "mapped" |) - |) in M.pure Constant.None_)). Definition root : Value.t -> Value.t -> M := @@ -1044,41 +708,6 @@ Definition root : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "root_node" |) - ], - make_dict [] - |) - ], - make_dict [] - |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "root_node" |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -1095,7 +724,6 @@ Definition root : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -1122,23 +750,6 @@ Definition patricialize : Value.t -> Value.t -> M := Root node of `obj`. " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "obj" |) - ], - make_dict [] - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.None_ - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let arbitrary_key := @@ -1156,36 +767,10 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "obj" |) - ], - make_dict [] - |), Constant.int 1 |), - (* then *) - ltac:(M.monadic ( - let leaf := - M.call (| - M.get_name (| globals, "LeafNode" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |); - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) - ], - make_dict [] - |) in - let _ := M.return_ (| - M.get_name (| globals, "leaf" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let substring := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |) |) in let prefix_length := M.call (| M.get_name (| globals, "len" |), @@ -1204,7 +789,7 @@ Definition patricialize : Value.t -> Value.t -> M := M.get_name (| globals, "common_prefix_length" |), make_list [ M.get_name (| globals, "substring" |); - M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) + M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) ], make_dict [] |) @@ -1212,58 +797,10 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.break (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let prefix := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):BinOp.add (| - M.get_name (| globals, "level" |), - M.get_name (| globals, "prefix_length" |) - |) |) in - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "ExtensionNode" |), - make_list [ - M.get_name (| globals, "prefix" |); - M.call (| - M.get_name (| globals, "encode_internal_node" |), - make_list [ - M.call (| - M.get_name (| globals, "patricialize" |), - make_list [ - M.get_name (| globals, "obj" |); - BinOp.add (| - M.get_name (| globals, "level" |), - M.get_name (| globals, "prefix_length" |) - |) - ], - make_dict [] - |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) @@ -1283,44 +820,9 @@ Definition patricialize : Value.t -> Value.t -> M := |) in EndFor. let value := - (* At constant: unsupported node type: Constant *) in + Constant.bytes "" in For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "key" |) - ], - make_dict [] - |), M.get_name (| globals, "level" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); - make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "AssertionError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let value := - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) @@ -1332,26 +834,9 @@ Definition patricialize : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "BranchNode" |), make_list [ - [M.call (| - M.get_name (| globals, "encode_internal_node" |), - make_list [ - M.call (| - M.get_name (| globals, "patricialize" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "branches" |), M.get_name (| globals, "k" |) |); - BinOp.add (| - M.get_name (| globals, "level" |), - Constant.int 1 - |) - ], - make_dict [] - |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)]; + (* At expr: unsupported node type: ListComp *); M.get_name (| globals, "value" |) ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/utils/address.v b/CoqOfPython/ethereum/muir_glacier/utils/address.v index 9215bb2..1c77416 100644 --- a/CoqOfPython/ethereum/muir_glacier/utils/address.v +++ b/CoqOfPython/ethereum/muir_glacier/utils/address.v @@ -70,11 +70,10 @@ Definition to_address : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), make_list [], make_dict [] - |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) + |), UnOp.sub (| Constant.int 20 |) |) ], make_dict [] |) - |) in M.pure Constant.None_)). Definition compute_contract_address : Value.t -> Value.t -> M := @@ -114,7 +113,7 @@ Definition compute_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -132,7 +131,6 @@ Definition compute_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition compute_create2_contract_address : Value.t -> Value.t -> M := @@ -160,7 +158,7 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := BinOp.add (| BinOp.add (| BinOp.add (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "ff", M.get_name (| globals, "address" |) |), M.get_name (| globals, "salt" |) @@ -182,7 +180,7 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -200,5 +198,4 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/utils/hexadecimal.v b/CoqOfPython/ethereum/muir_glacier/utils/hexadecimal.v index 9b3030d..2934148 100644 --- a/CoqOfPython/ethereum/muir_glacier/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/muir_glacier/utils/hexadecimal.v @@ -66,7 +66,6 @@ Definition hex_to_root : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition hex_to_bloom : Value.t -> Value.t -> M := @@ -105,7 +104,6 @@ Definition hex_to_bloom : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition hex_to_address : Value.t -> Value.t -> M := @@ -151,5 +149,4 @@ Definition hex_to_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/utils/message.v b/CoqOfPython/ethereum/muir_glacier/utils/message.v index a226a3a..2798cb9 100644 --- a/CoqOfPython/ethereum/muir_glacier/utils/message.v +++ b/CoqOfPython/ethereum/muir_glacier/utils/message.v @@ -88,105 +88,14 @@ Definition prepare_message : Value.t -> Value.t -> M := Items containing contract creation or message call specific data. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "target" |); - M.get_name (| globals, "Bytes0" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let current_target := - M.call (| - M.get_name (| globals, "compute_contract_address" |), - make_list [ - M.get_name (| globals, "caller" |); - BinOp.sub (| - M.get_field (| M.call (| - M.get_name (| globals, "get_account" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "caller" |) - ], - make_dict [] - |), "nonce" |), - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 1 - ], - make_dict [] - |) - |) - ], - make_dict [] - |) in - let msg_data := - M.call (| - M.get_name (| globals, "Bytes" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |) in - let code := - M.get_name (| globals, "data" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "target" |); - M.get_name (| globals, "Address" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let current_target := - M.get_name (| globals, "target" |) in - let msg_data := - M.get_name (| globals, "data" |) in - let code := - M.get_field (| M.call (| - M.get_name (| globals, "get_account" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "target" |) - ], - make_dict [] - |), "code" |) in - let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "code_address" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let code_address := - M.get_name (| globals, "target" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.call (| + let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "Target must be address or empty bytes" ], make_dict [] - |) |) in + |)) M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -197,5 +106,4 @@ Definition prepare_message : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/vm/__init__.v b/CoqOfPython/ethereum/muir_glacier/vm/__init__.v index d408aed..25f0a97 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/__init__.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/__init__.v @@ -145,28 +145,6 @@ Definition incorporate_child_on_success : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); - M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -185,57 +163,9 @@ Definition incorporate_child_on_error : Value.t -> Value.t -> M := The child evm to incorporate. " in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "RIPEMD160_ADDRESS" |), M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), - make_list [ - M.get_name (| globals, "RIPEMD160_ADDRESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |), M.get_name (| globals, "RIPEMD160_ADDRESS" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); - M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), - make_list [ - M.get_name (| globals, "RIPEMD160_ADDRESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign_op (| diff --git a/CoqOfPython/ethereum/muir_glacier/vm/gas.v b/CoqOfPython/ethereum/muir_glacier/vm/gas.v new file mode 100644 index 0000000..765c5ef --- /dev/null +++ b/CoqOfPython/ethereum/muir_glacier/vm/gas.v @@ -0,0 +1,841 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Gas +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +EVM gas constants and calculators. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.trace. +Axiom ethereum_trace_GasAndRefund : + IsGlobalAlias globals ethereum.trace.globals "GasAndRefund". +Axiom ethereum_trace_evm_trace : + IsGlobalAlias globals ethereum.trace.globals "evm_trace". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". + +Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) +)). + +Definition GAS_BASE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 2 + ], + make_dict [] + |) +)). + +Definition GAS_VERY_LOW : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_SLOAD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 800 + ], + make_dict [] + |) +)). + +Definition GAS_STORAGE_SET : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 20000 + ], + make_dict [] + |) +)). + +Definition GAS_STORAGE_UPDATE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5000 + ], + make_dict [] + |) +)). + +Definition GAS_STORAGE_CLEAR_REFUND : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 15000 + ], + make_dict [] + |) +)). + +Definition GAS_LOW : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5 + ], + make_dict [] + |) +)). + +Definition GAS_MID : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 8 + ], + make_dict [] + |) +)). + +Definition GAS_HIGH : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 10 + ], + make_dict [] + |) +)). + +Definition GAS_EXPONENTIATION : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 10 + ], + make_dict [] + |) +)). + +Definition GAS_EXPONENTIATION_PER_BYTE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 50 + ], + make_dict [] + |) +)). + +Definition GAS_MEMORY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_KECCAK256 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 30 + ], + make_dict [] + |) +)). + +Definition GAS_KECCAK256_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 6 + ], + make_dict [] + |) +)). + +Definition GAS_COPY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_BLOCK_HASH : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 20 + ], + make_dict [] + |) +)). + +Definition GAS_EXTERNAL : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 700 + ], + make_dict [] + |) +)). + +Definition GAS_BALANCE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 700 + ], + make_dict [] + |) +)). + +Definition GAS_LOG : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 375 + ], + make_dict [] + |) +)). + +Definition GAS_LOG_DATA : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 8 + ], + make_dict [] + |) +)). + +Definition GAS_LOG_TOPIC : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 375 + ], + make_dict [] + |) +)). + +Definition GAS_CREATE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 32000 + ], + make_dict [] + |) +)). + +Definition GAS_CODE_DEPOSIT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 200 + ], + make_dict [] + |) +)). + +Definition GAS_ZERO : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) +)). + +Definition GAS_CALL : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 700 + ], + make_dict [] + |) +)). + +Definition GAS_NEW_ACCOUNT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 25000 + ], + make_dict [] + |) +)). + +Definition GAS_CALL_VALUE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 9000 + ], + make_dict [] + |) +)). + +Definition GAS_CALL_STIPEND : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 2300 + ], + make_dict [] + |) +)). + +Definition GAS_SELF_DESTRUCT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5000 + ], + make_dict [] + |) +)). + +Definition GAS_SELF_DESTRUCT_NEW_ACCOUNT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 25000 + ], + make_dict [] + |) +)). + +Definition REFUND_SELF_DESTRUCT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 24000 + ], + make_dict [] + |) +)). + +Definition GAS_ECRECOVER : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3000 + ], + make_dict [] + |) +)). + +Definition GAS_SHA256 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 60 + ], + make_dict [] + |) +)). + +Definition GAS_SHA256_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 12 + ], + make_dict [] + |) +)). + +Definition GAS_RIPEMD160 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 600 + ], + make_dict [] + |) +)). + +Definition GAS_RIPEMD160_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 120 + ], + make_dict [] + |) +)). + +Definition GAS_IDENTITY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 15 + ], + make_dict [] + |) +)). + +Definition GAS_IDENTITY_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_RETURN_DATA_COPY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_CODE_HASH : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 700 + ], + make_dict [] + |) +)). + +Definition GAS_FAST_STEP : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5 + ], + make_dict [] + |) +)). + +Definition GAS_BLAKE2_PER_ROUND : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) +)). + +Definition ExtendMemory : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition MessageCallGas : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition charge_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "amount" ] |) in + let _ := Constant.str " + Subtracts `amount` from `evm.gas_left`. + + Parameters + ---------- + evm : + The current EVM. + amount : + The amount of gas the current operation requires. + + " in + let _ := M.call (| + M.get_name (| globals, "evm_trace" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "GasAndRefund" |), + make_list [ + M.get_name (| globals, "amount" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + let _ := M.assign_op (| + BinOp.sub, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "amount" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition calculate_memory_gas_cost : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "size_in_bytes" ] |) in + let _ := Constant.str " + Calculates the gas cost for allocating memory + to the smallest multiple of 32 bytes, + such that the allocated size is at least as big as the given size. + + Parameters + ---------- + size_in_bytes : + The size of the data in bytes. + + Returns + ------- + total_gas_cost : `ethereum.base_types.Uint` + The gas cost for storing data in memory. + " in + let size_in_words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "size_in_bytes" |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let linear_cost := + BinOp.mult (| + M.get_name (| globals, "size_in_words" |), + M.get_name (| globals, "GAS_MEMORY" |) + |) in + let quadratic_cost := + BinOp.floor_div (| + BinOp.pow (| + M.get_name (| globals, "size_in_words" |), + Constant.int 2 + |), + Constant.int 512 + |) in + let total_gas_cost := + BinOp.add (| + M.get_name (| globals, "linear_cost" |), + M.get_name (| globals, "quadratic_cost" |) + |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_)). + +Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "memory"; "extensions" ] |) in + let _ := Constant.str " + Calculates the gas amount to extend memory + + Parameters + ---------- + memory : + Memory contents of the EVM. + extensions: + List of extensions to be made to the memory. + Consists of a tuple of start position and size. + + Returns + ------- + extend_memory: `ExtendMemory` + " in + let size_to_extend := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let to_be_paid := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let current_size := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "memory" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + For make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ] in M.get_name (| globals, "extensions" |) do + let _ := + M.pure Constant.None_ + )) |) in + let before_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "current_size" |) + ], + make_dict [] + |) in + let after_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let size_to_extend := BinOp.add + BinOp.sub (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |) + BinOp.sub (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |) in + let already_paid := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "before_size" |) + ], + make_dict [] + |) in + let total_cost := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "after_size" |) + ], + make_dict [] + |) in + let to_be_paid := BinOp.add + BinOp.sub (| + M.get_name (| globals, "total_cost" |), + M.get_name (| globals, "already_paid" |) + |) + BinOp.sub (| + M.get_name (| globals, "total_cost" |), + M.get_name (| globals, "already_paid" |) + |) in + let current_size := + M.get_name (| globals, "after_size" |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ExtendMemory" |), + make_list [ + M.get_name (| globals, "to_be_paid" |); + M.get_name (| globals, "size_to_extend" |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition calculate_message_call_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "value"; "gas"; "gas_left"; "memory_cost"; "extra_gas"; "call_stipend" ] |) in + let _ := Constant.str " + Calculates the MessageCallGas (cost and stipend) for + executing call Opcodes. + + Parameters + ---------- + value: + The amount of `ETH` that needs to be transferred. + gas : + The amount of gas provided to the message-call. + gas_left : + The amount of gas left in the current frame. + memory_cost : + The amount needed to extend the memory in the current frame. + extra_gas : + The amount of gas needed for transferring value + creating a new + account inside a message call. + call_stipend : + The amount of stipend provided to a message call to execute code while + transferring value(ETH). + + Returns + ------- + message_call_gas: `MessageCallGas` + " in + let call_stipend := + (* if *) +M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let gas := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "max_message_call_gas" |), + make_list [ + BinOp.sub (| + BinOp.sub (| + M.get_name (| globals, "gas_left" |), + M.get_name (| globals, "memory_cost" |) + |), + M.get_name (| globals, "extra_gas" |) + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallGas" |), + make_list [ + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "extra_gas" |) + |); + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "call_stipend" |) + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition max_message_call_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "gas" ] |) in + let _ := Constant.str " + Calculates the maximum gas that is allowed for making a message call + + Parameters + ---------- + gas : + The amount of gas provided to the message-call. + + Returns + ------- + max_allowed_message_call_gas: `ethereum.base_types.Uint` + The maximum gas allowed for making the message-call. + " in + let _ := M.return_ (| + BinOp.sub (| + M.get_name (| globals, "gas" |), + BinOp.floor_div (| + M.get_name (| globals, "gas" |), + Constant.int 64 + |) + |) + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/arithmetic.v index a8b5c61..581ba5d 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/arithmetic.v @@ -273,22 +273,6 @@ Definition div : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let quotient := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let quotient := BinOp.floor_div (| M.get_name (| globals, "dividend" |), @@ -357,32 +341,7 @@ Definition sdiv : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let quotient := - Constant.int 0 in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_name (| globals, "dividend" |), UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "divisor" |), UnOp.sub (| Constant.int 1 |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let quotient := - UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let sign := M.call (| M.get_name (| globals, "get_sign" |), @@ -477,22 +436,6 @@ Definition mod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let remainder := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let remainder := BinOp.mod_ (| M.get_name (| globals, "x" |), @@ -561,16 +504,6 @@ Definition smod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let remainder := - Constant.int 0 in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let remainder := BinOp.mult (| M.call (| @@ -684,22 +617,6 @@ Definition addmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -795,22 +712,6 @@ Definition mulmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -980,16 +881,6 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "byte_num" |), Constant.int 31 |), - (* then *) - ltac:(M.monadic ( - let result := - M.get_name (| globals, "value" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let value_bytes := M.call (| M.get_name (| globals, "bytes" |), @@ -1012,29 +903,13 @@ Definition signextend : Value.t -> Value.t -> M := ], make_dict [] |) - |):(* At expr: unsupported node type: NoneType *) |) in + |) |) in let sign_bit := BinOp.r_shift (| M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), Constant.int 7 |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "sign_bit" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), - make_list [ - M.get_name (| globals, "value_bytes" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let num_bytes_prepend := BinOp.sub (| Constant.int 32, diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/bitwise.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/bitwise.v index 9f2f382..64cf120 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/bitwise.v @@ -287,22 +287,6 @@ Definition get_byte : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "byte_index" |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let extra_bytes_to_right := BinOp.sub (| Constant.int 31, @@ -382,28 +366,6 @@ Definition bitwise_shl : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - BinOp.mod_ (| - BinOp.l_shift (| - M.get_name (| globals, "value" |), - M.get_name (| globals, "shift" |) - |), - M.get_name (| globals, "U256_CEIL_VALUE" |) - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -465,19 +427,6 @@ Definition bitwise_shr : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), - (* then *) - ltac:(M.monadic ( - let result := - BinOp.r_shift (| - M.get_name (| globals, "value" |), - M.get_name (| globals, "shift" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -543,42 +492,7 @@ Definition bitwise_sar : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), - make_list [ - BinOp.r_shift (| - M.get_name (| globals, "signed_value" |), - M.get_name (| globals, "shift" |) - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "signed_value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/block.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/block.v index 26c73a7..f857b79 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/block.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/block.v @@ -69,24 +69,6 @@ Definition block_hash : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.lt_e (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), M.get_name (| globals, "block_number" |) |), - ltac:(M.monadic ( - Compare.gt (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), BinOp.add (| - M.get_name (| globals, "block_number" |), - Constant.int 256 - |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let hash := - (* At constant: unsupported node type: Constant *) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let hash := M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/comparison.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/comparison.v index fbc35f8..b8529d8 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/comparison.v @@ -78,7 +78,10 @@ Definition less_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.lt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -145,7 +148,10 @@ Definition signed_less_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.lt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -205,7 +211,10 @@ Definition greater_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.gt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -272,7 +281,10 @@ Definition signed_greater_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.gt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -332,7 +344,10 @@ Definition equal : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.eq (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.eq (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -384,7 +399,10 @@ Definition is_zero : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.eq (| M.get_name (| globals, "x" |), Constant.int 0 |) + Compare.eq (| + M.get_name (| globals, "x" |), + Constant.int 0 + |) ], make_dict [] |) in diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/control_flow.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/control_flow.v index 04a79d9..d4e4eae 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/control_flow.v @@ -109,15 +109,6 @@ Definition jump : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -177,29 +168,7 @@ Definition jumpi : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "conditional_value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let destination := - BinOp.add (| - M.get_field (| M.get_name (| globals, "evm" |), "pc" |), - Constant.int 1 - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let destination := M.get_name (| globals, "jump_dest" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/environment.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/environment.v index d9b3151..02315c3 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/environment.v @@ -514,7 +514,7 @@ Definition calldatacopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -682,7 +682,7 @@ Definition codecopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -925,7 +925,7 @@ Definition extcodecopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -1096,28 +1096,31 @@ Definition returndatacopy : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt_e (| BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "return_data_start_position" |) - ], - make_dict [] + Compare.lt_e (| + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "return_data_start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) |), M.call (| - M.get_name (| globals, "Uint" |), + M.get_name (| globals, "len" |), make_list [ - M.get_name (| globals, "size" |) + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |) ], make_dict [] |) - |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "return_data" |) - ], - make_dict [] - |) |); + |); M.get_name (| globals, "OutOfBoundsRead" |) ], make_dict [] @@ -1126,15 +1129,12 @@ Definition returndatacopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in let value := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |):BinOp.add (| - M.get_name (| globals, "return_data_start_position" |), - M.get_name (| globals, "size" |) - |) |) in + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |) |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -1193,22 +1193,6 @@ Definition extcodehash : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "account" |), M.get_name (| globals, "EMPTY_ACCOUNT" |) |), - (* then *) - ltac:(M.monadic ( - let codehash := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let codehash := M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/keccak.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/keccak.v index cab9ffb..2c4b10e 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/keccak.v @@ -137,7 +137,7 @@ Definition keccak : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/log.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/log.v index 4891a4d..e084e59 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/log.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/log.v @@ -161,7 +161,7 @@ Definition log_n : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/memory.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/memory.v index 1e1c8b0..86ba742 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/memory.v @@ -121,7 +121,7 @@ Definition mstore : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -203,7 +203,7 @@ Definition mstore8 : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -288,7 +288,7 @@ Definition mload : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/stack.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/stack.v index 1eeda05..305af15 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/stack.v @@ -188,13 +188,16 @@ Definition dup_n : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] - |) |); + Compare.lt (| + M.get_name (| globals, "item_number" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + |); M.get_name (| globals, "StackUnderflowError" |) ], make_dict [] @@ -260,13 +263,16 @@ Definition swap_n : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] - |) |); + Compare.lt (| + M.get_name (| globals, "item_number" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + |); M.get_name (| globals, "StackUnderflowError" |) ], make_dict [] diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/storage.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/storage.v index 5f4c9f2..e55bb00 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/storage.v @@ -152,7 +152,10 @@ Definition sstore : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.gt (| M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), M.get_name (| globals, "GAS_CALL_STIPEND" |) |); + Compare.gt (| + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "GAS_CALL_STIPEND" |) + |); M.get_name (| globals, "OutOfGasError" |) ], make_dict [] @@ -178,156 +181,11 @@ Definition sstore : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_name (| globals, "original_value" |), M.get_name (| globals, "current_value" |) |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_name (| globals, "current_value" |), M.get_name (| globals, "new_value" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let gas_cost := - M.get_name (| globals, "GAS_STORAGE_SET" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let gas_cost := - M.get_name (| globals, "GAS_STORAGE_UPDATE" |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let gas_cost := M.get_name (| globals, "GAS_SLOAD" |) in M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_eq (| M.get_name (| globals, "current_value" |), M.get_name (| globals, "new_value" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), - ltac:(M.monadic ( - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "new_value" |), Constant.int 0 |) - )) - |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), - M.call (| - M.get_name (| globals, "int" |), - make_list [ - M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.sub, - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), - M.call (| - M.get_name (| globals, "int" |), - make_list [ - M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "original_value" |), M.get_name (| globals, "new_value" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), - M.call (| - M.get_name (| globals, "int" |), - make_list [ - BinOp.sub (| - M.get_name (| globals, "GAS_STORAGE_SET" |), - M.get_name (| globals, "GAS_SLOAD" |) - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), - M.call (| - M.get_name (| globals, "int" |), - make_list [ - BinOp.sub (| - M.get_name (| globals, "GAS_STORAGE_UPDATE" |), - M.get_name (| globals, "GAS_SLOAD" |) - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/system.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/system.v new file mode 100644 index 0000000..b850f84 --- /dev/null +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/system.v @@ -0,0 +1,1598 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) System Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM system related instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_account_exists_and_is_empty : + IsGlobalAlias globals state.globals "account_exists_and_is_empty". +Axiom state_account_has_code_or_nonce : + IsGlobalAlias globals state.globals "account_has_code_or_nonce". +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". +Axiom state_increment_nonce : + IsGlobalAlias globals state.globals "increment_nonce". +Axiom state_is_account_alive : + IsGlobalAlias globals state.globals "is_account_alive". +Axiom state_set_account_balance : + IsGlobalAlias globals state.globals "set_account_balance". + +Require utils.address. +Axiom utils_address_compute_contract_address : + IsGlobalAlias globals utils.address.globals "compute_contract_address". +Axiom utils_address_compute_create2_contract_address : + IsGlobalAlias globals utils.address.globals "compute_create2_contract_address". +Axiom utils_address_to_address : + IsGlobalAlias globals utils.address.globals "to_address". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". +Axiom __init___Message : + IsGlobalAlias globals __init__.globals "Message". +Axiom __init___incorporate_child_on_error : + IsGlobalAlias globals __init__.globals "incorporate_child_on_error". +Axiom __init___incorporate_child_on_success : + IsGlobalAlias globals __init__.globals "incorporate_child_on_success". + +Require exceptions. +Axiom exceptions_Revert : + IsGlobalAlias globals exceptions.globals "Revert". +Axiom exceptions_WriteInStaticContext : + IsGlobalAlias globals exceptions.globals "WriteInStaticContext". + +Require gas. +Axiom gas_GAS_CALL : + IsGlobalAlias globals gas.globals "GAS_CALL". +Axiom gas_GAS_CALL_VALUE : + IsGlobalAlias globals gas.globals "GAS_CALL_VALUE". +Axiom gas_GAS_CREATE : + IsGlobalAlias globals gas.globals "GAS_CREATE". +Axiom gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". +Axiom gas_GAS_NEW_ACCOUNT : + IsGlobalAlias globals gas.globals "GAS_NEW_ACCOUNT". +Axiom gas_GAS_SELF_DESTRUCT : + IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT". +Axiom gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : + IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". +Axiom gas_GAS_ZERO : + IsGlobalAlias globals gas.globals "GAS_ZERO". +Axiom gas_REFUND_SELF_DESTRUCT : + IsGlobalAlias globals gas.globals "REFUND_SELF_DESTRUCT". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_calculate_message_call_gas : + IsGlobalAlias globals gas.globals "calculate_message_call_gas". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". +Axiom gas_max_message_call_gas : + IsGlobalAlias globals gas.globals "max_message_call_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". +Axiom memory_memory_write : + IsGlobalAlias globals memory.globals "memory_write". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition generic_create : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "endowment"; "contract_address"; "memory_start_position"; "memory_size" ] |) in + let _ := Constant.str " + Core logic used by the `CREATE*` family of opcodes. + " in +(* At stmt: unsupported node type: ImportFrom *) + let create_message_gas := + M.call (| + M.get_name (| globals, "max_message_call_gas" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.sub, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "create_message_gas" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let sender_address := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in + let sender := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "sender_address" |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := + M.pure Constant.None_ + )) |) in + let call_data := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + let child_message := + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) in + let child_evm := + M.call (| + M.get_name (| globals, "process_create_message" |), + make_list [ + M.get_name (| globals, "child_message" |); + M.get_field (| M.get_name (| globals, "evm" |), "env" |) + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_success" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition create : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Creates a new account with associated code. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let endowment := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_position" |); M.get_name (| globals, "memory_size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_CREATE" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let contract_address := + M.call (| + M.get_name (| globals, "compute_contract_address" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "nonce" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "generic_create" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "endowment" |); + M.get_name (| globals, "contract_address" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition create2 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Creates a new account with associated code. + + It's similar to CREATE opcode except that the address of new account + depends on the init_code instead of the nonce of sender. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let endowment := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let salt := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_position" |); M.get_name (| globals, "memory_size" |) ] + ] + ], + make_dict [] + |) in + let call_data_words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_CREATE" |), + BinOp.mult (| + M.get_name (| globals, "GAS_KECCAK256_WORD" |), + M.get_name (| globals, "call_data_words" |) + |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let contract_address := + M.call (| + M.get_name (| globals, "compute_create2_contract_address" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "salt" |); + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "generic_create" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "endowment" |); + M.get_name (| globals, "contract_address" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition return_ : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Halts execution returning output data. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let memory_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_position" |); M.get_name (| globals, "memory_size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_ZERO" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "running" |), + Constant.bool false + |) in + let _ := M.pass (| |) in + M.pure Constant.None_)). + +Definition generic_call : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "gas"; "value"; "caller"; "to"; "code_address"; "should_transfer_value"; "is_staticcall"; "memory_input_start_position"; "memory_input_size"; "memory_output_start_position"; "memory_output_size" ] |) in + let _ := Constant.str " + Perform the core logic of the `CALL*` family of opcodes. + " in +(* At stmt: unsupported node type: ImportFrom *) + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let _ := + M.pure Constant.None_ + )) |) in + let call_data := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |) + ], + make_dict [] + |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "code_address" |) + ], + make_dict [] + |), "code" |) in + let child_message := + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) in + let child_evm := + M.call (| + M.get_name (| globals, "process_message" |), + make_list [ + M.get_name (| globals, "child_message" |); + M.get_field (| M.get_name (| globals, "evm" |), "env" |) + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_success" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let actual_output_size := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_name (| globals, "memory_output_size" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), Constant.None_:M.get_name (| globals, "actual_output_size" |) |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition call : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into an account. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let to := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let create_gas_cost := + (* if *) +M.if_then_else (| + BoolOp.or (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "is_account_alive" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "to" |) + ], + make_dict [] + |) + )) + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let transfer_gas_cost := + (* if *) +M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_CALL" |), + M.get_name (| globals, "create_gas_cost" |) + |), + M.get_name (| globals, "transfer_gas_cost" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.or (| + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "value" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) + )) + |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let sender_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.get_name (| globals, "value" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "to" |); + Constant.bool true; + Constant.bool false; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition callcode : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into this account with alternative account’s code. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let code_address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let to := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let transfer_gas_cost := + (* if *) +M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + BinOp.add (| + M.get_name (| globals, "GAS_CALL" |), + M.get_name (| globals, "transfer_gas_cost" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let sender_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.get_name (| globals, "value" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "code_address" |); + Constant.bool true; + Constant.bool false; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition selfdestruct : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Halt execution and register account for later deletion. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let beneficiary := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let gas_cost := + M.get_name (| globals, "GAS_SELF_DESTRUCT" |) in + let _ := + M.pure Constant.None_ + )) |) in + let originator := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in + let refunded_accounts := + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in + let parent_evm := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "parent_evm" |) in + While Compare.is_not (| + M.get_name (| globals, "parent_evm" |), + Constant.None_ + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "refunded_accounts" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "parent_evm" |), "accounts_to_delete" |) + ], + make_dict [] + |) in + let parent_evm := + M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in + EndWhile. + let _ := + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "gas_cost" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let beneficiary_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |), "balance" |) in + let originator_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "originator" |) + ], + make_dict [] + |), "balance" |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |); + BinOp.add (| + M.get_name (| globals, "beneficiary_balance" |), + M.get_name (| globals, "originator_balance" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "originator" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |), "add" |), + make_list [ + M.get_name (| globals, "originator" |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "running" |), + Constant.bool false + |) in + let _ := M.pass (| |) in + M.pure Constant.None_)). + +Definition delegatecall : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into an account. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let code_address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + M.get_name (| globals, "GAS_CALL" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "value" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "caller" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "code_address" |); + Constant.bool false; + Constant.bool false; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition staticcall : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into an account. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let to := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + M.get_name (| globals, "GAS_CALL" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "to" |); + Constant.bool true; + Constant.bool true; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition revert : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stop execution and revert state changes, without consuming all provided gas + and also has the ability to return a reason + Parameters + ---------- + evm : + The current EVM frame. + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let output := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "bytes" |), + make_list [ + M.get_name (| globals, "output" |) + ], + make_dict [] + |) + |) in + let _ := M.raise (| Some(M.get_name (| globals, "Revert" |)) + let _ := M.pass (| |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/vm/interpreter.v b/CoqOfPython/ethereum/muir_glacier/vm/interpreter.v index 5496638..5652c89 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/interpreter.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/interpreter.v @@ -182,91 +182,6 @@ Definition process_message_call : Value.t -> Value.t -> M := Output of the message call " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_name (| globals, "message" |), "target" |), M.call (| - M.get_name (| globals, "Bytes0" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let is_collision := - M.call (| - M.get_name (| globals, "account_has_code_or_nonce" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_field (| M.get_name (| globals, "message" |), "current_target" |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - M.get_name (| globals, "is_collision" |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "MessageCallOutput" |), - make_list [ - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |); - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |); - M.call (| - M.get_name (| globals, "tuple" |), - make_list [], - make_dict [] - |); - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |); - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |); - M.call (| - M.get_name (| globals, "AddressCollision" |), - make_list [], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let evm := - M.call (| - M.get_name (| globals, "process_create_message" |), - make_list [ - M.get_name (| globals, "message" |); - M.get_name (| globals, "env" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let evm := M.call (| M.get_name (| globals, "process_message" |), @@ -277,74 +192,11 @@ Definition process_message_call : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_field (| M.get_name (| globals, "message" |), "target" |) - ], - make_dict [] - |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), - make_list [ - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_field (| M.get_name (| globals, "message" |), "target" |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "evm" |), "error" |), - (* then *) - ltac:(M.monadic ( -(* At stmt: unsupported node type: AnnAssign *) - let accounts_to_delete := - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |) in - let touched_accounts := - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |) in - let refund_counter := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let logs := M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in let accounts_to_delete := @@ -388,7 +240,6 @@ Definition process_message_call : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). Definition process_create_message : Value.t -> Value.t -> M := @@ -450,28 +301,6 @@ Definition process_create_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), - (* then *) - ltac:(M.monadic ( - let contract_code := - M.get_field (| M.get_name (| globals, "evm" |), "output" |) in - let contract_code_gas := - BinOp.mult (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "contract_code" |) - ], - make_dict [] - |), - M.get_name (| globals, "GAS_CODE_DEPOSIT" |) - |) in -(* At stmt: unsupported node type: Try *) - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "rollback_transaction" |), make_list [ @@ -483,7 +312,6 @@ Definition process_create_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) - |) in M.pure Constant.None_)). Definition process_message : Value.t -> Value.t -> M := @@ -505,21 +333,6 @@ Definition process_message : Value.t -> Value.t -> M := Items containing execution specific objects " in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_field (| M.get_name (| globals, "message" |), "depth" |), M.get_name (| globals, "STACK_DEPTH_LIMIT" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "StackDepthLimitError" |), - make_list [ - Constant.str "Stack depth limit reached" - ], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -538,29 +351,6 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - M.get_field (| M.get_name (| globals, "message" |), "should_transfer_value" |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_field (| M.get_name (| globals, "message" |), "value" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "move_ether" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_field (| M.get_name (| globals, "message" |), "caller" |); - M.get_field (| M.get_name (| globals, "message" |), "current_target" |); - M.get_field (| M.get_name (| globals, "message" |), "value" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let evm := @@ -573,21 +363,6 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "evm" |), "error" |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "rollback_transaction" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "commit_transaction" |), make_list [ @@ -599,7 +374,6 @@ Definition process_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) - |) in M.pure Constant.None_)). Definition execute_code : Value.t -> Value.t -> M := @@ -639,5 +413,4 @@ Definition execute_code : Value.t -> Value.t -> M := (* At stmt: unsupported node type: Try *) let _ := M.return_ (| M.get_name (| globals, "evm" |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/vm/memory.v b/CoqOfPython/ethereum/muir_glacier/vm/memory.v index fa8d906..4b107fd 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/memory.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/memory.v @@ -45,22 +45,7 @@ Definition memory_write : Value.t -> Value.t -> M := Data to write to memory. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) - |) |), + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_)). @@ -86,23 +71,7 @@ Definition memory_read_bytes : Value.t -> Value.t -> M := Data read from memory. " in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |) - |) in + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |) M.pure Constant.None_)). Definition buffer_read : Value.t -> Value.t -> M := @@ -129,25 +98,9 @@ Definition buffer_read : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "right_pad_zero_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |); + M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |) |); M.get_name (| globals, "size" |) ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/alt_bn128.v index 19b83fc..abe4238 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/alt_bn128.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/alt_bn128.v @@ -210,15 +210,6 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) in For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ] do let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "i" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -362,15 +353,6 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) in For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ] do let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "i" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -443,24 +425,6 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_eq (| BinOp.mod_ (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "data" |) - ], - make_dict [] - |), - Constant.int 192 - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let result := @@ -509,32 +473,11 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := Constant.int 32, M.get_name (| globals, "j" |) |) - |):BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "i" |), - Constant.int 192 - |), - BinOp.mult (| - Constant.int 32, - BinOp.add (| - M.get_name (| globals, "j" |), - Constant.int 1 - |) - |) |) |) ], make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "value" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -555,17 +498,20 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.call (| - M.get_field (| M.get_name (| globals, "p" |), "mul_by" |), - make_list [ - M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) - ], - make_dict [] - |), M.call (| - M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) |); + Compare.eq (| + M.call (| + M.get_field (| M.get_name (| globals, "p" |), "mul_by" |), + make_list [ + M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) + ], + make_dict [] + |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |); M.get_name (| globals, "OutOfGasError" |) ], make_dict [] @@ -573,87 +519,29 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.call (| - M.get_field (| M.get_name (| globals, "q" |), "mul_by" |), - make_list [ - M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) - ], - make_dict [] - |), M.call (| - M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) |); + Compare.eq (| + M.call (| + M.get_field (| M.get_name (| globals, "q" |), "mul_by" |), + make_list [ + M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) + ], + make_dict [] + |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |); M.get_name (| globals, "OutOfGasError" |) ], make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "p" |), M.call (| - M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_name (| globals, "q" |), M.call (| - M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let result := - BinOp.mult (| - M.get_name (| globals, "result" |), - M.call (| - M.get_name (| globals, "pairing" |), - make_list [ - M.get_name (| globals, "q" |); - M.get_name (| globals, "p" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "result" |), M.call (| - M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), - make_list [ - Constant.int 1 - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign (| - M.get_field (| M.get_name (| globals, "evm" |), "output" |), - M.call (| - M.get_field (| M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 1 - ], - make_dict [] - |), "to_be_bytes32" |), - make_list [], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| diff --git a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/blake2f.v b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/blake2f.v index 5903066..1647d48 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/blake2f.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/blake2f.v @@ -55,13 +55,16 @@ Definition blake2f : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "data" |) - ], - make_dict [] - |), Constant.int 213 |); + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 213 + |); M.get_name (| globals, "InvalidParameter" |) ], make_dict [] @@ -96,10 +99,13 @@ Definition blake2f : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.in (| M.get_name (| globals, "f" |), make_list [ - Constant.int 0; - Constant.int 1 - ] |); + Compare.in (| + M.get_name (| globals, "f" |), + make_list [ + Constant.int 0; + Constant.int 1 + ] + |); M.get_name (| globals, "InvalidParameter" |) ], make_dict [] diff --git a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/ecrecover.v index cc351b5..0cbcf16 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/ecrecover.v @@ -188,60 +188,12 @@ Definition ecrecover : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 27 |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 28 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| Constant.int 0, M.get_name (| globals, "r" |) |), - ltac:(M.monadic ( - Compare.gt_e (| M.get_name (| globals, "r" |), M.get_name (| globals, "SECP256K1N" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| Constant.int 0, M.get_name (| globals, "s" |) |), - ltac:(M.monadic ( - Compare.gt_e (| M.get_name (| globals, "s" |), M.get_name (| globals, "SECP256K1N" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: Try *) @@ -252,7 +204,7 @@ Definition ecrecover : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12:Constant.int 32 |) in + |), Constant.int 12 |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/modexp.v index 39ce4f9..aff5b85 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/modexp.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/modexp.v @@ -181,36 +181,6 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "exp_length" |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let adjusted_exp_length := - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.call (| - M.get_name (| globals, "max" |), - make_list [ - Constant.int 0; - BinOp.sub (| - M.call (| - M.get_field (| M.get_name (| globals, "exp_head" |), "bit_length" |), - make_list [], - make_dict [] - |), - Constant.int 1 - |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let adjusted_exp_length := M.call (| M.get_name (| globals, "Uint" |), @@ -297,30 +267,6 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_name (| globals, "base_length" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "modulus_length" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign (| - M.get_field (| M.get_name (| globals, "evm" |), "output" |), - M.call (| - M.get_name (| globals, "Bytes" |), - make_list [], - make_dict [] - |) - |) in - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let base := @@ -383,27 +329,6 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "modulus" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign (| - M.get_field (| M.get_name (| globals, "evm" |), "output" |), - BinOp.mult (| - M.call (| - M.get_name (| globals, "Bytes" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |), - M.get_name (| globals, "modulus_length" |) - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| @@ -440,47 +365,7 @@ Definition get_mult_complexity : Value.t -> Value.t -> M := Estimate the complexity of performing Karatsuba multiplication. " in let _ := - (* if *) - M.if_then_else (| - Compare.lt_e (| M.get_name (| globals, "x" |), Constant.int 64 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - BinOp.pow (| - M.get_name (| globals, "x" |), - Constant.int 2 - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - Compare.lt_e (| M.get_name (| globals, "x" |), Constant.int 1024 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - BinOp.sub (| - BinOp.add (| - BinOp.floor_div (| - BinOp.pow (| - M.get_name (| globals, "x" |), - Constant.int 2 - |), - Constant.int 4 - |), - BinOp.mult (| - Constant.int 96, - M.get_name (| globals, "x" |) - |) - |), - Constant.int 3072 - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| BinOp.sub (| BinOp.add (| @@ -498,7 +383,6 @@ Definition get_mult_complexity : Value.t -> Value.t -> M := |), Constant.int 199680 |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/muir_glacier/vm/runtime.v b/CoqOfPython/ethereum/muir_glacier/vm/runtime.v index 835b46c..2cd7652 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/runtime.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/runtime.v @@ -67,50 +67,19 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := ], make_dict [] |) in - While Compare.lt (| M.get_name (| globals, "pc" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "code" |) - ], - make_dict [] - |) |) do + While Compare.lt (| + M.get_name (| globals, "pc" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) + |) do (* At stmt: unsupported node type: Try *) let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "current_opcode" |), M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), - make_list [ - M.get_name (| globals, "pc" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - (* At expr: unsupported node type: Compare *), - (* then *) - ltac:(M.monadic ( - let push_data_size := - BinOp.add (| - BinOp.sub (| - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) - |), - Constant.int 1 - |) in - let pc := BinOp.add - M.get_name (| globals, "push_data_size" |) - M.get_name (| globals, "push_data_size" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -121,5 +90,4 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := EndWhile. let _ := M.return_ (| M.get_name (| globals, "valid_jump_destinations" |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/vm/stack.v b/CoqOfPython/ethereum/muir_glacier/vm/stack.v index 42ea42d..ea778df 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/stack.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/stack.v @@ -49,21 +49,6 @@ Definition pop : Value.t -> Value.t -> M := " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "stack" |) - ], - make_dict [] - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "StackUnderflowError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -72,7 +57,6 @@ Definition pop : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). Definition push : Value.t -> Value.t -> M := @@ -91,21 +75,6 @@ Definition push : Value.t -> Value.t -> M := " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "stack" |) - ], - make_dict [] - |), Constant.int 1024 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "StackOverflowError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -116,5 +85,4 @@ Definition push : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/bloom.v b/CoqOfPython/ethereum/paris/bloom.v index 04b5d9f..04650ff 100644 --- a/CoqOfPython/ethereum/paris/bloom.v +++ b/CoqOfPython/ethereum/paris/bloom.v @@ -72,10 +72,7 @@ Definition add_to_bloom : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |):BinOp.add (| - M.get_name (| globals, "idx" |), - Constant.int 2 - |) |) + M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |) |) ], make_dict [] |), @@ -160,5 +157,4 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/fork.v b/CoqOfPython/ethereum/paris/fork.v index ec98469..9cb256a 100644 --- a/CoqOfPython/ethereum/paris/fork.v +++ b/CoqOfPython/ethereum/paris/fork.v @@ -220,7 +220,6 @@ Definition apply_fork : Value.t -> Value.t -> M := " in let _ := M.return_ (| M.get_name (| globals, "old" |) - |) in M.pure Constant.None_)). Definition get_last_256_block_hashes : Value.t -> Value.t -> M := @@ -246,25 +245,8 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := Hashes of the recent 256 blocks in order of increasing block number. " in let recent_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |) |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "recent_blocks" |) - ], - make_dict [] - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - make_list [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let recent_block_hashes := @@ -303,7 +285,6 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "recent_block_hashes" |) - |) in M.pure Constant.None_)). Definition state_transition : Value.t -> Value.t -> M := @@ -343,7 +324,10 @@ Definition state_transition : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "block" |), "ommers" |), make_tuple [ ] |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "block" |), "ommers" |), + make_tuple [ ] + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -374,7 +358,10 @@ Definition state_transition : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_gas_used" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "gas_used" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_gas_used" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "gas_used" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -382,7 +369,10 @@ Definition state_transition : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "transactions_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "transactions_root" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "transactions_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "transactions_root" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -390,7 +380,10 @@ Definition state_transition : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "state_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "state_root" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "state_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "state_root" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -398,7 +391,10 @@ Definition state_transition : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "receipt_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "receipt_root" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "receipt_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "receipt_root" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -406,7 +402,10 @@ Definition state_transition : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_logs_bloom" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "bloom" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_logs_bloom" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "bloom" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -419,24 +418,6 @@ Definition state_transition : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "chain" |), "blocks" |) - ], - make_dict [] - |), Constant.int 255 |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign (| - M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |):(* At expr: unsupported node type: NoneType *) |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -484,57 +465,7 @@ Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "parent_gas_used" |), M.get_name (| globals, "parent_gas_target" |) |), - (* then *) - ltac:(M.monadic ( - let expected_base_fee_per_gas := - M.get_name (| globals, "parent_base_fee_per_gas" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "parent_gas_used" |), M.get_name (| globals, "parent_gas_target" |) |), - (* then *) - ltac:(M.monadic ( - let gas_used_delta := - BinOp.sub (| - M.get_name (| globals, "parent_gas_used" |), - M.get_name (| globals, "parent_gas_target" |) - |) in - let parent_fee_gas_delta := - BinOp.mult (| - M.get_name (| globals, "parent_base_fee_per_gas" |), - M.get_name (| globals, "gas_used_delta" |) - |) in - let target_fee_gas_delta := - BinOp.floor_div (| - M.get_name (| globals, "parent_fee_gas_delta" |), - M.get_name (| globals, "parent_gas_target" |) - |) in - let base_fee_per_gas_delta := - M.call (| - M.get_name (| globals, "max" |), - make_list [ - BinOp.floor_div (| - M.get_name (| globals, "target_fee_gas_delta" |), - M.get_name (| globals, "BASE_FEE_MAX_CHANGE_DENOMINATOR" |) - |); - Constant.int 1 - ], - make_dict [] - |) in - let expected_base_fee_per_gas := - BinOp.add (| - M.get_name (| globals, "parent_base_fee_per_gas" |), - M.get_name (| globals, "base_fee_per_gas_delta" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let gas_used_delta := BinOp.sub (| M.get_name (| globals, "parent_gas_target" |), @@ -572,7 +503,6 @@ Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition validate_header : Value.t -> Value.t -> M := @@ -598,7 +528,10 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt_e (| M.get_field (| M.get_name (| globals, "header" |), "gas_used" |), M.get_field (| M.get_name (| globals, "header" |), "gas_limit" |) |); + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "header" |), "gas_used" |), + M.get_field (| M.get_name (| globals, "header" |), "gas_limit" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -617,7 +550,10 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_name (| globals, "expected_base_fee_per_gas" |), M.get_field (| M.get_name (| globals, "header" |), "base_fee_per_gas" |) |); + Compare.eq (| + M.get_name (| globals, "expected_base_fee_per_gas" |), + M.get_field (| M.get_name (| globals, "header" |), "base_fee_per_gas" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -625,7 +561,10 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.gt (| M.get_field (| M.get_name (| globals, "header" |), "timestamp" |), M.get_field (| M.get_name (| globals, "parent_header" |), "timestamp" |) |); + Compare.gt (| + M.get_field (| M.get_name (| globals, "header" |), "timestamp" |), + M.get_field (| M.get_name (| globals, "parent_header" |), "timestamp" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -633,10 +572,13 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "number" |), BinOp.add (| - M.get_field (| M.get_name (| globals, "parent_header" |), "number" |), - Constant.int 1 - |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "number" |), + BinOp.add (| + M.get_field (| M.get_name (| globals, "parent_header" |), "number" |), + Constant.int 1 + |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -644,13 +586,16 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt_e (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) - ], - make_dict [] - |), Constant.int 32 |); + Compare.lt_e (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) + ], + make_dict [] + |), + Constant.int 32 + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -658,7 +603,10 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "difficulty" |), Constant.int 0 |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "difficulty" |), + Constant.int 0 + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -666,7 +614,10 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "nonce" |), (* At constant: unsupported node type: Constant *) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "nonce" |), + Constant.bytes "0000000000000000" + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -674,7 +625,10 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "ommers_hash" |), M.get_name (| globals, "EMPTY_OMMER_HASH" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "ommers_hash" |), + M.get_name (| globals, "EMPTY_OMMER_HASH" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -696,7 +650,10 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |), M.get_name (| globals, "block_parent_hash" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |), + M.get_name (| globals, "block_parent_hash" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -735,7 +692,10 @@ Definition check_transaction : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt_e (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_name (| globals, "gas_available" |) |); + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_name (| globals, "gas_available" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -750,58 +710,13 @@ Definition check_transaction : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "FeeMarketTransaction" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "ensure" |), - make_list [ - Compare.gt_e (| M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |), M.get_field (| M.get_name (| globals, "tx" |), "max_priority_fee_per_gas" |) |); - M.get_name (| globals, "InvalidBlock" |) - ], - make_dict [] - |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.gt_e (| M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |), M.get_name (| globals, "base_fee_per_gas" |) |); - M.get_name (| globals, "InvalidBlock" |) - ], - make_dict [] - |) in - let priority_fee_per_gas := - M.call (| - M.get_name (| globals, "min" |), - make_list [ - M.get_field (| M.get_name (| globals, "tx" |), "max_priority_fee_per_gas" |); - BinOp.sub (| - M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |), - M.get_name (| globals, "base_fee_per_gas" |) - |) - ], - make_dict [] - |) in - let effective_gas_price := - BinOp.add (| - M.get_name (| globals, "priority_fee_per_gas" |), - M.get_name (| globals, "base_fee_per_gas" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "ensure" |), - make_list [ - Compare.gt_e (| M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |), M.get_name (| globals, "base_fee_per_gas" |) |); + Compare.gt_e (| + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |), + M.get_name (| globals, "base_fee_per_gas" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -812,7 +727,6 @@ Definition check_transaction : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| make_tuple [ M.get_name (| globals, "sender_address" |); M.get_name (| globals, "effective_gas_price" |) ] - |) in M.pure Constant.None_)). Definition make_receipt : Value.t -> Value.t -> M := @@ -845,64 +759,9 @@ Definition make_receipt : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "AccessListTransaction" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - BinOp.add (| - (* At constant: unsupported node type: Constant *), - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "receipt" |) - ], - make_dict [] - |) - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "FeeMarketTransaction" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - BinOp.add (| - (* At constant: unsupported node type: Constant *), - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "receipt" |) - ], - make_dict [] - |) - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "receipt" |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -1125,7 +984,6 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition process_transaction : Value.t -> Value.t -> M := @@ -1183,26 +1041,6 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "FeeMarketTransaction" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let max_gas_fee := - BinOp.mult (| - M.get_field (| M.get_name (| globals, "tx" |), "gas" |), - M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let max_gas_fee := BinOp.mult (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), @@ -1213,7 +1051,10 @@ Definition process_transaction : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "sender_account" |), "nonce" |), M.get_field (| M.get_name (| globals, "tx" |), "nonce" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "sender_account" |), "nonce" |), + M.get_field (| M.get_name (| globals, "tx" |), "nonce" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1221,10 +1062,13 @@ Definition process_transaction : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.gt_e (| M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), BinOp.add (| - M.get_name (| globals, "max_gas_fee" |), - M.get_field (| M.get_name (| globals, "tx" |), "value" |) - |) |); + Compare.gt_e (| + M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), + BinOp.add (| + M.get_name (| globals, "max_gas_fee" |), + M.get_field (| M.get_name (| globals, "tx" |), "value" |) + |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1232,11 +1076,14 @@ Definition process_transaction : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "sender_account" |), "code" |), M.call (| - M.get_name (| globals, "bytearray" |), - make_list [], - make_dict [] - |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "sender_account" |), "code" |), + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [], + make_dict [] + |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1292,39 +1139,6 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - make_tuple [ M.get_name (| globals, "AccessListTransaction" |); M.get_name (| globals, "FeeMarketTransaction" |) ] - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - For make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "keys" |) ] in M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) do - let _ := M.call (| - M.get_field (| M.get_name (| globals, "preaccessed_addresses" |), "add" |), - make_list [ - M.get_name (| globals, "address" |) - ], - make_dict [] - |) in - For M.get_name (| globals, "key" |) in M.get_name (| globals, "keys" |) do - let _ := M.call (| - M.get_field (| M.get_name (| globals, "preaccessed_storage_keys" |), "add" |), - make_list [ - make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "key" |) ] - ], - make_dict [] - |) in - EndFor. - EndFor. - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let message := @@ -1429,47 +1243,7 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "transaction_fee" |) |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_eq (| M.get_name (| globals, "coinbase_balance_after_mining_fee" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "set_account_balance" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_field (| M.get_name (| globals, "env" |), "coinbase" |); - M.get_name (| globals, "coinbase_balance_after_mining_fee" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "destroy_account" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -1486,35 +1260,11 @@ Definition process_transaction : Value.t -> Value.t -> M := EndFor. For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "touched_accounts" |) do let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "destroy_account" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := M.return_ (| make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |); M.get_field (| M.get_name (| globals, "output" |), "error" |) ] - |) in M.pure Constant.None_)). Definition validate_transaction : Value.t -> Value.t -> M := @@ -1546,24 +1296,29 @@ Definition validate_transaction : Value.t -> Value.t -> M := " in let _ := M.return_ (| BoolOp.and (| - Compare.lt_e (| M.call (| - M.get_name (| globals, "calculate_intrinsic_cost" |), - make_list [ - M.get_name (| globals, "tx" |) - ], - make_dict [] - |), M.get_field (| M.get_name (| globals, "tx" |), "gas" |) |), + Compare.lt_e (| + M.call (| + M.get_name (| globals, "calculate_intrinsic_cost" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |), + M.get_field (| M.get_name (| globals, "tx" |), "gas" |) + |), ltac:(M.monadic ( - Compare.lt (| M.get_field (| M.get_name (| globals, "tx" |), "nonce" |), BinOp.sub (| + Compare.lt (| + M.get_field (| M.get_name (| globals, "tx" |), "nonce" |), + BinOp.sub (| BinOp.pow (| Constant.int 2, Constant.int 64 |), Constant.int 1 - |) |) + |) + |) )) |) - |) in M.pure Constant.None_)). Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := @@ -1595,17 +1350,6 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := Constant.int 0 in For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "byte" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let data_cost := BinOp.add - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let data_cost := BinOp.add M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in @@ -1613,22 +1357,6 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := )) |) in EndFor. let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_name (| globals, "tx" |), "to" |), M.call (| - M.get_name (| globals, "Bytes0" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let create_cost := - M.get_name (| globals, "TX_CREATE_COST" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let create_cost := Constant.int 0 in M.pure Constant.None_ @@ -1636,47 +1364,6 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := let access_list_cost := Constant.int 0 in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - make_tuple [ M.get_name (| globals, "AccessListTransaction" |); M.get_name (| globals, "FeeMarketTransaction" |) ] - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - For make_tuple [ M.get_name (| globals, "_address" |); M.get_name (| globals, "keys" |) ] in M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) do - let access_list_cost := BinOp.add - M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) - M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) in - let access_list_cost := BinOp.add - BinOp.mult (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "keys" |) - ], - make_dict [] - |), - M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) - |) - BinOp.mult (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "keys" |) - ], - make_dict [] - |), - M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) - |) in - EndFor. - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1696,7 +1383,6 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition recover_sender : Value.t -> Value.t -> M := @@ -1731,9 +1417,15 @@ Definition recover_sender : Value.t -> Value.t -> M := M.get_name (| globals, "ensure" |), make_list [ BoolOp.and (| - Compare.lt (| Constant.int 0, M.get_name (| globals, "r" |) |), + Compare.lt (| + Constant.int 0, + M.get_name (| globals, "r" |) + |), ltac:(M.monadic ( - Compare.lt (| M.get_name (| globals, "r" |), M.get_name (| globals, "SECP256K1N" |) |) + Compare.lt (| + M.get_name (| globals, "r" |), + M.get_name (| globals, "SECP256K1N" |) + |) )) |); M.get_name (| globals, "InvalidBlock" |) @@ -1744,190 +1436,27 @@ Definition recover_sender : Value.t -> Value.t -> M := M.get_name (| globals, "ensure" |), make_list [ BoolOp.and (| - Compare.lt (| Constant.int 0, M.get_name (| globals, "s" |) |), + Compare.lt (| + Constant.int 0, + M.get_name (| globals, "s" |) + |), ltac:(M.monadic ( - Compare.lt_e (| M.get_name (| globals, "s" |), BinOp.floor_div (| + Compare.lt_e (| + M.get_name (| globals, "s" |), + BinOp.floor_div (| M.get_name (| globals, "SECP256K1N" |), Constant.int 2 - |) |) - )) - |); - M.get_name (| globals, "InvalidBlock" |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "LegacyTransaction" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let v := - M.get_field (| M.get_name (| globals, "tx" |), "v" |) in - let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.eq (| M.get_name (| globals, "v" |), Constant.int 27 |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "v" |), Constant.int 28 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let public_key := - M.call (| - M.get_name (| globals, "secp256k1_recover" |), - make_list [ - M.get_name (| globals, "r" |); - M.get_name (| globals, "s" |); - BinOp.sub (| - M.get_name (| globals, "v" |), - Constant.int 27 - |); - M.call (| - M.get_name (| globals, "signing_hash_pre155" |), - make_list [ - M.get_name (| globals, "tx" |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "ensure" |), - make_list [ - BoolOp.or (| - Compare.eq (| M.get_name (| globals, "v" |), BinOp.add (| - Constant.int 35, - BinOp.mult (| - M.get_name (| globals, "chain_id" |), - Constant.int 2 + |) |) - |) |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "v" |), BinOp.add (| - Constant.int 36, - BinOp.mult (| - M.get_name (| globals, "chain_id" |), - Constant.int 2 - |) - |) |) )) |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] |) in - let public_key := - M.call (| - M.get_name (| globals, "secp256k1_recover" |), - make_list [ - M.get_name (| globals, "r" |); - M.get_name (| globals, "s" |); - BinOp.sub (| - BinOp.sub (| - M.get_name (| globals, "v" |), - Constant.int 35 - |), - BinOp.mult (| - M.get_name (| globals, "chain_id" |), - Constant.int 2 - |) - |); - M.call (| - M.get_name (| globals, "signing_hash_155" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "chain_id" |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + let _ := let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "AccessListTransaction" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let public_key := - M.call (| - M.get_name (| globals, "secp256k1_recover" |), - make_list [ - M.get_name (| globals, "r" |); - M.get_name (| globals, "s" |); - M.get_field (| M.get_name (| globals, "tx" |), "y_parity" |); - M.call (| - M.get_name (| globals, "signing_hash_2930" |), - make_list [ - M.get_name (| globals, "tx" |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "FeeMarketTransaction" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let public_key := - M.call (| - M.get_name (| globals, "secp256k1_recover" |), - make_list [ - M.get_name (| globals, "r" |); - M.get_name (| globals, "s" |); - M.get_field (| M.get_name (| globals, "tx" |), "y_parity" |); - M.call (| - M.get_name (| globals, "signing_hash_1559" |), - make_list [ - M.get_name (| globals, "tx" |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -1944,11 +1473,10 @@ Definition recover_sender : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12:Constant.int 32 |) + |), Constant.int 12 |) ], make_dict [] |) - |) in M.pure Constant.None_)). Definition signing_hash_pre155 : Value.t -> Value.t -> M := @@ -1981,7 +1509,6 @@ Definition signing_hash_pre155 : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition signing_hash_155 : Value.t -> Value.t -> M := @@ -2028,7 +1555,6 @@ Definition signing_hash_155 : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition signing_hash_2930 : Value.t -> Value.t -> M := @@ -2052,7 +1578,7 @@ Definition signing_hash_2930 : Value.t -> Value.t -> M := M.get_name (| globals, "keccak256" |), make_list [ BinOp.add (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "01", M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), make_list [ @@ -2064,7 +1590,6 @@ Definition signing_hash_2930 : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition signing_hash_1559 : Value.t -> Value.t -> M := @@ -2088,7 +1613,7 @@ Definition signing_hash_1559 : Value.t -> Value.t -> M := M.get_name (| globals, "keccak256" |), make_list [ BinOp.add (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "02", M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), make_list [ @@ -2100,7 +1625,6 @@ Definition signing_hash_1559 : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition compute_header_hash : Value.t -> Value.t -> M := @@ -2151,7 +1675,6 @@ Definition compute_header_hash : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition check_gas_limit : Value.t -> Value.t -> M := @@ -2190,54 +1713,14 @@ Definition check_gas_limit : Value.t -> Value.t -> M := M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "gas_limit" |), BinOp.add (| - M.get_name (| globals, "parent_gas_limit" |), - M.get_name (| globals, "max_adjustment_delta" |) - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.bool false - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt_e (| M.get_name (| globals, "gas_limit" |), BinOp.sub (| - M.get_name (| globals, "parent_gas_limit" |), - M.get_name (| globals, "max_adjustment_delta" |) - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.bool false - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "gas_limit" |), M.get_name (| globals, "GAS_LIMIT_MINIMUM" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.bool false - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| Constant.bool true - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/fork_types.v b/CoqOfPython/ethereum/paris/fork_types.v index d12953d..5c7dac3 100644 --- a/CoqOfPython/ethereum/paris/fork_types.v +++ b/CoqOfPython/ethereum/paris/fork_types.v @@ -98,5 +98,4 @@ Definition encode_account : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/state.v b/CoqOfPython/ethereum/paris/state.v index 833879c..d814ed9 100644 --- a/CoqOfPython/ethereum/paris/state.v +++ b/CoqOfPython/ethereum/paris/state.v @@ -126,13 +126,7 @@ Definition begin_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) ], make_dict [] - |); {M.get_name (| globals, "k" |): M.call (| - M.get_name (| globals, "copy_trie" |), - make_list [ - M.get_name (| globals, "t" |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)} ] + |); (* At expr: unsupported node type: DictComp *) ] ], make_dict [] |) in @@ -155,19 +149,6 @@ Definition commit_transaction : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "clear" |), - make_list [], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -193,19 +174,6 @@ Definition rollback_transaction : Value.t -> Value.t -> M := |) |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "clear" |), - make_list [], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -242,27 +210,8 @@ Definition get_account : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "account" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "account" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_ACCOUNT" |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -297,7 +246,6 @@ Definition get_account_optional : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "account" |) - |) in M.pure Constant.None_)). Definition set_account : Value.t -> Value.t -> M := @@ -377,15 +325,6 @@ Definition destroy_storage : Value.t -> Value.t -> M := Address of account whose storage is to be deleted. " in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -448,23 +387,6 @@ Definition get_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let value := @@ -486,7 +408,6 @@ Definition get_storage : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "value" |) - |) in M.pure Constant.None_)). Definition set_storage : Value.t -> Value.t -> M := @@ -507,14 +428,17 @@ Definition set_storage : Value.t -> Value.t -> M := value : `U256` Value to set at the key. " in - let _ := M.assert (| Compare.is_not (| M.call (| - M.get_name (| globals, "trie_get" |), - make_list [ - M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), Constant.None_ |) |) in + let _ := M.assert (| Compare.is_not (| + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + Constant.None_ + |) |) in let trie := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), @@ -524,24 +448,6 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let trie := - M.call (| - M.get_name (| globals, "Trie" |), - make_list [], - make_dict [] - |) in - let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), - M.get_name (| globals, "trie" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -554,15 +460,6 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), {} |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -587,26 +484,8 @@ Definition storage_root : Value.t -> Value.t -> M := " in let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "root" |), - make_list [ - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_TRIE_ROOT" |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -637,7 +516,6 @@ Definition state_root : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition account_exists : Value.t -> Value.t -> M := @@ -659,15 +537,17 @@ Definition account_exists : Value.t -> Value.t -> M := True if account exists in the state trie, False otherwise " in let _ := M.return_ (| - Compare.is_not (| M.call (| - M.get_name (| globals, "get_account_optional" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), Constant.None_ |) - |) in + Compare.is_not (| + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + Constant.None_ + |) M.pure Constant.None_)). Definition account_has_code_or_nonce : Value.t -> Value.t -> M := @@ -700,18 +580,23 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := |) in let _ := M.return_ (| BoolOp.or (| - Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( - Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |) + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |) )) |) - |) in M.pure Constant.None_)). Definition is_account_empty : Value.t -> Value.t -> M := @@ -744,23 +629,31 @@ Definition is_account_empty : Value.t -> Value.t -> M := |) in let _ := M.return_ (| BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |), ltac:(M.monadic ( - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "balance" |), + Constant.int 0 + |) )) |) )) |) - |) in M.pure Constant.None_)). Definition account_exists_and_is_empty : Value.t -> Value.t -> M := @@ -794,28 +687,39 @@ Definition account_exists_and_is_empty : Value.t -> Value.t -> M := |) in let _ := M.return_ (| BoolOp.and (| - Compare.is_not (| M.get_name (| globals, "account" |), Constant.None_ |), + Compare.is_not (| + M.get_name (| globals, "account" |), + Constant.None_ + |), ltac:(M.monadic ( BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |), ltac:(M.monadic ( - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "balance" |), + Constant.int 0 + |) )) |) )) |) )) |) - |) in M.pure Constant.None_)). Definition is_account_alive : Value.t -> Value.t -> M := @@ -846,36 +750,33 @@ Definition is_account_alive : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "account" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.bool false - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| UnOp.not (| BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |), ltac:(M.monadic ( - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "balance" |), + Constant.int 0 + |) )) |) )) |) |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -983,30 +884,6 @@ Definition touch_account : Value.t -> Value.t -> M := The address of the account that need to initialised. " in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "account_exists" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "set_account" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |); - M.get_name (| globals, "EMPTY_ACCOUNT" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -1084,23 +961,6 @@ Definition get_storage_original : Value.t -> Value.t -> M := Key of the storage slot. " in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -1116,22 +976,6 @@ Definition get_storage_original : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "original_account_trie" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let original_value := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let original_value := M.call (| M.get_name (| globals, "trie_get" |), @@ -1153,5 +997,4 @@ Definition get_storage_original : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "original_value" |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/transactions.v b/CoqOfPython/ethereum/paris/transactions.v index 56996d9..afa27ec 100644 --- a/CoqOfPython/ethereum/paris/transactions.v +++ b/CoqOfPython/ethereum/paris/transactions.v @@ -112,87 +112,15 @@ Definition encode_transaction : Value.t -> Value.t -> M := Encode a transaction. Needed because non-legacy transactions aren't RLP. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "LegacyTransaction" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "tx" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "AccessListTransaction" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - BinOp.add (| - (* At constant: unsupported node type: Constant *), - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "tx" |) - ], - make_dict [] - |) - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "FeeMarketTransaction" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - BinOp.add (| - (* At constant: unsupported node type: Constant *), - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "tx" |) - ], - make_dict [] - |) - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.call (| + let _ := M.raise (| Some(M.call (| M.get_name (| globals, "Exception" |), make_list [ (* At expr: unsupported node type: JoinedStr *) ], make_dict [] - |) |) in + |)) M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -208,67 +136,8 @@ Definition decode_transaction : Value.t -> Value.t -> M := Decode a transaction. Needed because non-legacy transactions aren't RLP. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "Bytes" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), Constant.int 1 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), - make_list [ - M.get_name (| globals, "AccessListTransaction" |); - M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 1:(* At expr: unsupported node type: NoneType *) |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), Constant.int 2 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), - make_list [ - M.get_name (| globals, "FeeMarketTransaction" |); - M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 1:(* At expr: unsupported node type: NoneType *) |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidBlock" |) |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "tx" |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/trie.v b/CoqOfPython/ethereum/paris/trie.v index 3dbf56c..b383128 100644 --- a/CoqOfPython/ethereum/paris/trie.v +++ b/CoqOfPython/ethereum/paris/trie.v @@ -202,96 +202,16 @@ Definition encode_internal_node : Value.t -> Value.t -> M := " in (* At stmt: unsupported node type: AnnAssign *) let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "node" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let unencoded := - (* At constant: unsupported node type: Constant *) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "LeafNode" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let unencoded := - make_tuple [ M.call (| - M.get_name (| globals, "nibble_list_to_compact" |), - make_list [ - M.get_field (| M.get_name (| globals, "node" |), "rest_of_key" |); - Constant.bool true - ], - make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "ExtensionNode" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let unencoded := - make_tuple [ M.call (| - M.get_name (| globals, "nibble_list_to_compact" |), - make_list [ - M.get_field (| M.get_name (| globals, "node" |), "key_segment" |); - Constant.bool false - ], - make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "BranchNode" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let unencoded := - BinOp.add (| - M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), - make_list [ - M.get_field (| M.get_name (| globals, "node" |), "value" |) - ] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.call (| + let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ (* At expr: unsupported node type: JoinedStr *) ], make_dict [] - |) |) in + |)) M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -309,23 +229,6 @@ Definition encode_internal_node : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "encoded" |) - ], - make_dict [] - |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "unencoded" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_name (| globals, "keccak256" |), @@ -334,7 +237,6 @@ Definition encode_internal_node : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -348,83 +250,8 @@ Definition encode_node : Value.t -> Value.t -> M := Currently mostly an unimplemented stub. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "storage_root" |), Constant.None_ |) |) in - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "encode_account" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "storage_root" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "U256" |) ] - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.call (| - M.get_name (| globals, "cast" |), - make_list [ - M.get_field (| M.get_name (| globals, "rlp" |), "RLP" |); - M.get_name (| globals, "node" |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "Bytes" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "node" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "previous_trie" |), "encode_node" |), @@ -434,7 +261,6 @@ Definition encode_node : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -486,7 +312,6 @@ Definition copy_trie : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition trie_set : Value.t -> Value.t -> M := @@ -508,26 +333,6 @@ Definition trie_set : Value.t -> Value.t -> M := Node to insert at `key`. " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "value" |), M.get_field (| M.get_name (| globals, "trie" |), "default" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "key" |), M.get_field (| M.get_name (| globals, "trie" |), "_data" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), M.get_name (| globals, "value" |) @@ -565,7 +370,6 @@ Definition trie_get : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition common_prefix_length : Value.t -> Value.t -> M := @@ -588,28 +392,6 @@ Definition common_prefix_length : Value.t -> Value.t -> M := make_dict [] |) do let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| M.get_name (| globals, "i" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "b" |) - ], - make_dict [] - |) |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "i" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -621,7 +403,6 @@ Definition common_prefix_length : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition nibble_list_to_compact : Value.t -> Value.t -> M := @@ -667,68 +448,6 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| BinOp.mod_ (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |), - Constant.int 2 - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_name (| globals, "compact" |), "append" |), - make_list [ - BinOp.mult (| - Constant.int 16, - BinOp.mult (| - Constant.int 2, - M.get_name (| globals, "is_leaf" |) - |) - |) - ], - make_dict [] - |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 0; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |); - Constant.int 2 - ], - make_dict [] - |) do - let _ := M.call (| - M.get_field (| M.get_name (| globals, "compact" |), "append" |), - make_list [ - BinOp.add (| - BinOp.mult (| - Constant.int 16, - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) - |), - M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) - |) - ], - make_dict [] - |) in - EndFor. - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ @@ -790,7 +509,6 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition bytes_to_nibble_list : Value.t -> Value.t -> M := @@ -868,7 +586,6 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition _prepare_trie : Value.t -> Value.t -> M := @@ -898,45 +615,6 @@ Definition _prepare_trie : Value.t -> Value.t -> M := make_dict [] |) do let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "value" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in - let address := - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in - let encoded_value := - M.call (| - M.get_name (| globals, "encode_node" |), - make_list [ - M.get_name (| globals, "value" |); - M.call (| - M.get_name (| globals, "get_storage_root" |), - make_list [ - M.get_name (| globals, "address" |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let encoded_value := M.call (| M.get_name (| globals, "encode_node" |), @@ -950,29 +628,16 @@ Definition _prepare_trie : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.not_eq (| M.get_name (| globals, "encoded_value" |), (* At constant: unsupported node type: Constant *) |); + Compare.not_eq (| + M.get_name (| globals, "encoded_value" |), + Constant.bytes "" + |); M.get_name (| globals, "AssertionError" |) ], make_dict [] |) in (* At stmt: unsupported node type: AnnAssign *) let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "trie" |), "secured" |), - (* then *) - ltac:(M.monadic ( - let key := - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let key := M.get_name (| globals, "preimage" |) in M.pure Constant.None_ @@ -990,7 +655,6 @@ Definition _prepare_trie : Value.t -> Value.t -> M := EndFor. let _ := M.return_ (| M.get_name (| globals, "mapped" |) - |) in M.pure Constant.None_)). Definition root : Value.t -> Value.t -> M := @@ -1044,41 +708,6 @@ Definition root : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "root_node" |) - ], - make_dict [] - |) - ], - make_dict [] - |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "root_node" |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -1095,7 +724,6 @@ Definition root : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -1122,23 +750,6 @@ Definition patricialize : Value.t -> Value.t -> M := Root node of `obj`. " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "obj" |) - ], - make_dict [] - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.None_ - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let arbitrary_key := @@ -1156,36 +767,10 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "obj" |) - ], - make_dict [] - |), Constant.int 1 |), - (* then *) - ltac:(M.monadic ( - let leaf := - M.call (| - M.get_name (| globals, "LeafNode" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |); - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) - ], - make_dict [] - |) in - let _ := M.return_ (| - M.get_name (| globals, "leaf" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let substring := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |) |) in let prefix_length := M.call (| M.get_name (| globals, "len" |), @@ -1204,7 +789,7 @@ Definition patricialize : Value.t -> Value.t -> M := M.get_name (| globals, "common_prefix_length" |), make_list [ M.get_name (| globals, "substring" |); - M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) + M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) ], make_dict [] |) @@ -1212,58 +797,10 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.break (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let prefix := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):BinOp.add (| - M.get_name (| globals, "level" |), - M.get_name (| globals, "prefix_length" |) - |) |) in - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "ExtensionNode" |), - make_list [ - M.get_name (| globals, "prefix" |); - M.call (| - M.get_name (| globals, "encode_internal_node" |), - make_list [ - M.call (| - M.get_name (| globals, "patricialize" |), - make_list [ - M.get_name (| globals, "obj" |); - BinOp.add (| - M.get_name (| globals, "level" |), - M.get_name (| globals, "prefix_length" |) - |) - ], - make_dict [] - |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) @@ -1283,44 +820,9 @@ Definition patricialize : Value.t -> Value.t -> M := |) in EndFor. let value := - (* At constant: unsupported node type: Constant *) in + Constant.bytes "" in For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "key" |) - ], - make_dict [] - |), M.get_name (| globals, "level" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); - make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "AssertionError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let value := - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) @@ -1332,26 +834,9 @@ Definition patricialize : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "BranchNode" |), make_list [ - [M.call (| - M.get_name (| globals, "encode_internal_node" |), - make_list [ - M.call (| - M.get_name (| globals, "patricialize" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "branches" |), M.get_name (| globals, "k" |) |); - BinOp.add (| - M.get_name (| globals, "level" |), - Constant.int 1 - |) - ], - make_dict [] - |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)]; + (* At expr: unsupported node type: ListComp *); M.get_name (| globals, "value" |) ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/utils/address.v b/CoqOfPython/ethereum/paris/utils/address.v index cea4829..42f2c92 100644 --- a/CoqOfPython/ethereum/paris/utils/address.v +++ b/CoqOfPython/ethereum/paris/utils/address.v @@ -70,11 +70,10 @@ Definition to_address : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), make_list [], make_dict [] - |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) + |), UnOp.sub (| Constant.int 20 |) |) ], make_dict [] |) - |) in M.pure Constant.None_)). Definition compute_contract_address : Value.t -> Value.t -> M := @@ -114,7 +113,7 @@ Definition compute_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -132,7 +131,6 @@ Definition compute_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition compute_create2_contract_address : Value.t -> Value.t -> M := @@ -160,7 +158,7 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := BinOp.add (| BinOp.add (| BinOp.add (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "ff", M.get_name (| globals, "address" |) |), M.get_name (| globals, "salt" |) @@ -182,7 +180,7 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -200,5 +198,4 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/utils/hexadecimal.v b/CoqOfPython/ethereum/paris/utils/hexadecimal.v index b1bc56b..1735532 100644 --- a/CoqOfPython/ethereum/paris/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/paris/utils/hexadecimal.v @@ -66,7 +66,6 @@ Definition hex_to_root : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition hex_to_bloom : Value.t -> Value.t -> M := @@ -105,7 +104,6 @@ Definition hex_to_bloom : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition hex_to_address : Value.t -> Value.t -> M := @@ -151,5 +149,4 @@ Definition hex_to_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/utils/message.v b/CoqOfPython/ethereum/paris/utils/message.v index 416f071..e2d514f 100644 --- a/CoqOfPython/ethereum/paris/utils/message.v +++ b/CoqOfPython/ethereum/paris/utils/message.v @@ -103,105 +103,14 @@ Definition prepare_message : Value.t -> Value.t -> M := Items containing contract creation or message call specific data. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "target" |); - M.get_name (| globals, "Bytes0" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let current_target := - M.call (| - M.get_name (| globals, "compute_contract_address" |), - make_list [ - M.get_name (| globals, "caller" |); - BinOp.sub (| - M.get_field (| M.call (| - M.get_name (| globals, "get_account" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "caller" |) - ], - make_dict [] - |), "nonce" |), - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 1 - ], - make_dict [] - |) - |) - ], - make_dict [] - |) in - let msg_data := - M.call (| - M.get_name (| globals, "Bytes" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |) in - let code := - M.get_name (| globals, "data" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "target" |); - M.get_name (| globals, "Address" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let current_target := - M.get_name (| globals, "target" |) in - let msg_data := - M.get_name (| globals, "data" |) in - let code := - M.get_field (| M.call (| - M.get_name (| globals, "get_account" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "target" |) - ], - make_dict [] - |), "code" |) in - let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "code_address" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let code_address := - M.get_name (| globals, "target" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.call (| + let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "Target must be address or empty bytes" ], make_dict [] - |) |) in + |)) M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -250,5 +159,4 @@ Definition prepare_message : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/vm/__init__.v b/CoqOfPython/ethereum/paris/vm/__init__.v index 2ff63cd..49da5ae 100644 --- a/CoqOfPython/ethereum/paris/vm/__init__.v +++ b/CoqOfPython/ethereum/paris/vm/__init__.v @@ -147,28 +147,6 @@ Definition incorporate_child_on_success : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); - M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -201,57 +179,9 @@ Definition incorporate_child_on_error : Value.t -> Value.t -> M := The child evm to incorporate. " in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "RIPEMD160_ADDRESS" |), M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), - make_list [ - M.get_name (| globals, "RIPEMD160_ADDRESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |), M.get_name (| globals, "RIPEMD160_ADDRESS" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); - M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), - make_list [ - M.get_name (| globals, "RIPEMD160_ADDRESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign_op (| diff --git a/CoqOfPython/ethereum/paris/vm/gas.v b/CoqOfPython/ethereum/paris/vm/gas.v new file mode 100644 index 0000000..549060b --- /dev/null +++ b/CoqOfPython/ethereum/paris/vm/gas.v @@ -0,0 +1,811 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Gas +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +EVM gas constants and calculators. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.trace. +Axiom ethereum_trace_GasAndRefund : + IsGlobalAlias globals ethereum.trace.globals "GasAndRefund". +Axiom ethereum_trace_evm_trace : + IsGlobalAlias globals ethereum.trace.globals "evm_trace". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". + +Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) +)). + +Definition GAS_BASE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 2 + ], + make_dict [] + |) +)). + +Definition GAS_VERY_LOW : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_STORAGE_SET : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 20000 + ], + make_dict [] + |) +)). + +Definition GAS_STORAGE_UPDATE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5000 + ], + make_dict [] + |) +)). + +Definition GAS_STORAGE_CLEAR_REFUND : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 4800 + ], + make_dict [] + |) +)). + +Definition GAS_LOW : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5 + ], + make_dict [] + |) +)). + +Definition GAS_MID : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 8 + ], + make_dict [] + |) +)). + +Definition GAS_HIGH : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 10 + ], + make_dict [] + |) +)). + +Definition GAS_EXPONENTIATION : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 10 + ], + make_dict [] + |) +)). + +Definition GAS_EXPONENTIATION_PER_BYTE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 50 + ], + make_dict [] + |) +)). + +Definition GAS_MEMORY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_KECCAK256 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 30 + ], + make_dict [] + |) +)). + +Definition GAS_KECCAK256_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 6 + ], + make_dict [] + |) +)). + +Definition GAS_COPY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_BLOCK_HASH : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 20 + ], + make_dict [] + |) +)). + +Definition GAS_LOG : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 375 + ], + make_dict [] + |) +)). + +Definition GAS_LOG_DATA : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 8 + ], + make_dict [] + |) +)). + +Definition GAS_LOG_TOPIC : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 375 + ], + make_dict [] + |) +)). + +Definition GAS_CREATE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 32000 + ], + make_dict [] + |) +)). + +Definition GAS_CODE_DEPOSIT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 200 + ], + make_dict [] + |) +)). + +Definition GAS_ZERO : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) +)). + +Definition GAS_NEW_ACCOUNT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 25000 + ], + make_dict [] + |) +)). + +Definition GAS_CALL_VALUE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 9000 + ], + make_dict [] + |) +)). + +Definition GAS_CALL_STIPEND : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 2300 + ], + make_dict [] + |) +)). + +Definition GAS_SELF_DESTRUCT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5000 + ], + make_dict [] + |) +)). + +Definition GAS_SELF_DESTRUCT_NEW_ACCOUNT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 25000 + ], + make_dict [] + |) +)). + +Definition GAS_ECRECOVER : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3000 + ], + make_dict [] + |) +)). + +Definition GAS_SHA256 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 60 + ], + make_dict [] + |) +)). + +Definition GAS_SHA256_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 12 + ], + make_dict [] + |) +)). + +Definition GAS_RIPEMD160 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 600 + ], + make_dict [] + |) +)). + +Definition GAS_RIPEMD160_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 120 + ], + make_dict [] + |) +)). + +Definition GAS_IDENTITY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 15 + ], + make_dict [] + |) +)). + +Definition GAS_IDENTITY_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_RETURN_DATA_COPY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_FAST_STEP : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5 + ], + make_dict [] + |) +)). + +Definition GAS_BLAKE2_PER_ROUND : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) +)). + +Definition GAS_COLD_SLOAD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 2100 + ], + make_dict [] + |) +)). + +Definition GAS_COLD_ACCOUNT_ACCESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 2600 + ], + make_dict [] + |) +)). + +Definition GAS_WARM_ACCESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 100 + ], + make_dict [] + |) +)). + +Definition ExtendMemory : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition MessageCallGas : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition charge_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "amount" ] |) in + let _ := Constant.str " + Subtracts `amount` from `evm.gas_left`. + + Parameters + ---------- + evm : + The current EVM. + amount : + The amount of gas the current operation requires. + + " in + let _ := M.call (| + M.get_name (| globals, "evm_trace" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "GasAndRefund" |), + make_list [ + M.get_name (| globals, "amount" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + let _ := M.assign_op (| + BinOp.sub, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "amount" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition calculate_memory_gas_cost : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "size_in_bytes" ] |) in + let _ := Constant.str " + Calculates the gas cost for allocating memory + to the smallest multiple of 32 bytes, + such that the allocated size is at least as big as the given size. + + Parameters + ---------- + size_in_bytes : + The size of the data in bytes. + + Returns + ------- + total_gas_cost : `ethereum.base_types.Uint` + The gas cost for storing data in memory. + " in + let size_in_words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "size_in_bytes" |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let linear_cost := + BinOp.mult (| + M.get_name (| globals, "size_in_words" |), + M.get_name (| globals, "GAS_MEMORY" |) + |) in + let quadratic_cost := + BinOp.floor_div (| + BinOp.pow (| + M.get_name (| globals, "size_in_words" |), + Constant.int 2 + |), + Constant.int 512 + |) in + let total_gas_cost := + BinOp.add (| + M.get_name (| globals, "linear_cost" |), + M.get_name (| globals, "quadratic_cost" |) + |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_)). + +Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "memory"; "extensions" ] |) in + let _ := Constant.str " + Calculates the gas amount to extend memory + + Parameters + ---------- + memory : + Memory contents of the EVM. + extensions: + List of extensions to be made to the memory. + Consists of a tuple of start position and size. + + Returns + ------- + extend_memory: `ExtendMemory` + " in + let size_to_extend := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let to_be_paid := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let current_size := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "memory" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + For make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ] in M.get_name (| globals, "extensions" |) do + let _ := + M.pure Constant.None_ + )) |) in + let before_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "current_size" |) + ], + make_dict [] + |) in + let after_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let size_to_extend := BinOp.add + BinOp.sub (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |) + BinOp.sub (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |) in + let already_paid := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "before_size" |) + ], + make_dict [] + |) in + let total_cost := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "after_size" |) + ], + make_dict [] + |) in + let to_be_paid := BinOp.add + BinOp.sub (| + M.get_name (| globals, "total_cost" |), + M.get_name (| globals, "already_paid" |) + |) + BinOp.sub (| + M.get_name (| globals, "total_cost" |), + M.get_name (| globals, "already_paid" |) + |) in + let current_size := + M.get_name (| globals, "after_size" |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ExtendMemory" |), + make_list [ + M.get_name (| globals, "to_be_paid" |); + M.get_name (| globals, "size_to_extend" |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition calculate_message_call_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "value"; "gas"; "gas_left"; "memory_cost"; "extra_gas"; "call_stipend" ] |) in + let _ := Constant.str " + Calculates the MessageCallGas (cost and stipend) for + executing call Opcodes. + + Parameters + ---------- + value: + The amount of `ETH` that needs to be transferred. + gas : + The amount of gas provided to the message-call. + gas_left : + The amount of gas left in the current frame. + memory_cost : + The amount needed to extend the memory in the current frame. + extra_gas : + The amount of gas needed for transferring value + creating a new + account inside a message call. + call_stipend : + The amount of stipend provided to a message call to execute code while + transferring value(ETH). + + Returns + ------- + message_call_gas: `MessageCallGas` + " in + let call_stipend := + (* if *) +M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let gas := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "max_message_call_gas" |), + make_list [ + BinOp.sub (| + BinOp.sub (| + M.get_name (| globals, "gas_left" |), + M.get_name (| globals, "memory_cost" |) + |), + M.get_name (| globals, "extra_gas" |) + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallGas" |), + make_list [ + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "extra_gas" |) + |); + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "call_stipend" |) + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition max_message_call_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "gas" ] |) in + let _ := Constant.str " + Calculates the maximum gas that is allowed for making a message call + + Parameters + ---------- + gas : + The amount of gas provided to the message-call. + + Returns + ------- + max_allowed_message_call_gas: `ethereum.base_types.Uint` + The maximum gas allowed for making the message-call. + " in + let _ := M.return_ (| + BinOp.sub (| + M.get_name (| globals, "gas" |), + BinOp.floor_div (| + M.get_name (| globals, "gas" |), + Constant.int 64 + |) + |) + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/paris/vm/instructions/arithmetic.v index a8b5c61..581ba5d 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/arithmetic.v @@ -273,22 +273,6 @@ Definition div : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let quotient := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let quotient := BinOp.floor_div (| M.get_name (| globals, "dividend" |), @@ -357,32 +341,7 @@ Definition sdiv : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let quotient := - Constant.int 0 in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_name (| globals, "dividend" |), UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "divisor" |), UnOp.sub (| Constant.int 1 |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let quotient := - UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let sign := M.call (| M.get_name (| globals, "get_sign" |), @@ -477,22 +436,6 @@ Definition mod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let remainder := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let remainder := BinOp.mod_ (| M.get_name (| globals, "x" |), @@ -561,16 +504,6 @@ Definition smod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let remainder := - Constant.int 0 in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let remainder := BinOp.mult (| M.call (| @@ -684,22 +617,6 @@ Definition addmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -795,22 +712,6 @@ Definition mulmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -980,16 +881,6 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "byte_num" |), Constant.int 31 |), - (* then *) - ltac:(M.monadic ( - let result := - M.get_name (| globals, "value" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let value_bytes := M.call (| M.get_name (| globals, "bytes" |), @@ -1012,29 +903,13 @@ Definition signextend : Value.t -> Value.t -> M := ], make_dict [] |) - |):(* At expr: unsupported node type: NoneType *) |) in + |) |) in let sign_bit := BinOp.r_shift (| M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), Constant.int 7 |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "sign_bit" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), - make_list [ - M.get_name (| globals, "value_bytes" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let num_bytes_prepend := BinOp.sub (| Constant.int 32, diff --git a/CoqOfPython/ethereum/paris/vm/instructions/bitwise.v b/CoqOfPython/ethereum/paris/vm/instructions/bitwise.v index 9f2f382..64cf120 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/bitwise.v @@ -287,22 +287,6 @@ Definition get_byte : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "byte_index" |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let extra_bytes_to_right := BinOp.sub (| Constant.int 31, @@ -382,28 +366,6 @@ Definition bitwise_shl : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - BinOp.mod_ (| - BinOp.l_shift (| - M.get_name (| globals, "value" |), - M.get_name (| globals, "shift" |) - |), - M.get_name (| globals, "U256_CEIL_VALUE" |) - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -465,19 +427,6 @@ Definition bitwise_shr : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), - (* then *) - ltac:(M.monadic ( - let result := - BinOp.r_shift (| - M.get_name (| globals, "value" |), - M.get_name (| globals, "shift" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -543,42 +492,7 @@ Definition bitwise_sar : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), - make_list [ - BinOp.r_shift (| - M.get_name (| globals, "signed_value" |), - M.get_name (| globals, "shift" |) - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "signed_value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/paris/vm/instructions/block.v b/CoqOfPython/ethereum/paris/vm/instructions/block.v index c66d2d9..080a363 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/block.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/block.v @@ -75,24 +75,6 @@ Definition block_hash : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.lt_e (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), M.get_name (| globals, "block_number" |) |), - ltac:(M.monadic ( - Compare.gt (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), BinOp.add (| - M.get_name (| globals, "block_number" |), - Constant.int 256 - |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let hash := - (* At constant: unsupported node type: Constant *) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let hash := M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), diff --git a/CoqOfPython/ethereum/paris/vm/instructions/comparison.v b/CoqOfPython/ethereum/paris/vm/instructions/comparison.v index fbc35f8..b8529d8 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/comparison.v @@ -78,7 +78,10 @@ Definition less_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.lt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -145,7 +148,10 @@ Definition signed_less_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.lt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -205,7 +211,10 @@ Definition greater_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.gt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -272,7 +281,10 @@ Definition signed_greater_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.gt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -332,7 +344,10 @@ Definition equal : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.eq (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.eq (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -384,7 +399,10 @@ Definition is_zero : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.eq (| M.get_name (| globals, "x" |), Constant.int 0 |) + Compare.eq (| + M.get_name (| globals, "x" |), + Constant.int 0 + |) ], make_dict [] |) in diff --git a/CoqOfPython/ethereum/paris/vm/instructions/control_flow.v b/CoqOfPython/ethereum/paris/vm/instructions/control_flow.v index 04a79d9..d4e4eae 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/control_flow.v @@ -109,15 +109,6 @@ Definition jump : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -177,29 +168,7 @@ Definition jumpi : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "conditional_value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let destination := - BinOp.add (| - M.get_field (| M.get_name (| globals, "evm" |), "pc" |), - Constant.int 1 - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let destination := M.get_name (| globals, "jump_dest" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/paris/vm/instructions/environment.v b/CoqOfPython/ethereum/paris/vm/instructions/environment.v index 530304e..10bc05b 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/environment.v @@ -156,22 +156,6 @@ Definition balance : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "charge_gas" |), - make_list [ - M.get_name (| globals, "evm" |); - M.get_name (| globals, "GAS_WARM_ACCESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -538,7 +522,7 @@ Definition calldatacopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -706,7 +690,7 @@ Definition codecopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -805,22 +789,6 @@ Definition extcodesize : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "charge_gas" |), - make_list [ - M.get_name (| globals, "evm" |); - M.get_name (| globals, "GAS_WARM_ACCESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -958,28 +926,6 @@ Definition extcodecopy : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "charge_gas" |), - make_list [ - M.get_name (| globals, "evm" |); - BinOp.add (| - BinOp.add (| - M.get_name (| globals, "GAS_WARM_ACCESS" |), - M.get_name (| globals, "copy_gas_cost" |) - |), - M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1007,7 +953,7 @@ Definition extcodecopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -1178,28 +1124,31 @@ Definition returndatacopy : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt_e (| BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "return_data_start_position" |) - ], - make_dict [] + Compare.lt_e (| + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "return_data_start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) |), M.call (| - M.get_name (| globals, "Uint" |), + M.get_name (| globals, "len" |), make_list [ - M.get_name (| globals, "size" |) + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |) ], make_dict [] |) - |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "return_data" |) - ], - make_dict [] - |) |); + |); M.get_name (| globals, "OutOfBoundsRead" |) ], make_dict [] @@ -1208,15 +1157,12 @@ Definition returndatacopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in let value := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |):BinOp.add (| - M.get_name (| globals, "return_data_start_position" |), - M.get_name (| globals, "size" |) - |) |) in + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |) |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -1258,22 +1204,6 @@ Definition extcodehash : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "charge_gas" |), - make_list [ - M.get_name (| globals, "evm" |); - M.get_name (| globals, "GAS_WARM_ACCESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1301,22 +1231,6 @@ Definition extcodehash : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "account" |), M.get_name (| globals, "EMPTY_ACCOUNT" |) |), - (* then *) - ltac:(M.monadic ( - let codehash := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let codehash := M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), diff --git a/CoqOfPython/ethereum/paris/vm/instructions/keccak.v b/CoqOfPython/ethereum/paris/vm/instructions/keccak.v index cab9ffb..2c4b10e 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/keccak.v @@ -137,7 +137,7 @@ Definition keccak : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/paris/vm/instructions/log.v b/CoqOfPython/ethereum/paris/vm/instructions/log.v index 4891a4d..e084e59 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/log.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/log.v @@ -161,7 +161,7 @@ Definition log_n : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/paris/vm/instructions/memory.v b/CoqOfPython/ethereum/paris/vm/instructions/memory.v index 1e1c8b0..86ba742 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/memory.v @@ -121,7 +121,7 @@ Definition mstore : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -203,7 +203,7 @@ Definition mstore8 : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -288,7 +288,7 @@ Definition mload : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/paris/vm/instructions/stack.v b/CoqOfPython/ethereum/paris/vm/instructions/stack.v index 1eeda05..305af15 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/stack.v @@ -188,13 +188,16 @@ Definition dup_n : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] - |) |); + Compare.lt (| + M.get_name (| globals, "item_number" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + |); M.get_name (| globals, "StackUnderflowError" |) ], make_dict [] @@ -260,13 +263,16 @@ Definition swap_n : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] - |) |); + Compare.lt (| + M.get_name (| globals, "item_number" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + |); M.get_name (| globals, "StackUnderflowError" |) ], make_dict [] diff --git a/CoqOfPython/ethereum/paris/vm/instructions/storage.v b/CoqOfPython/ethereum/paris/vm/instructions/storage.v index 2f0a831..b3c4045 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/storage.v @@ -91,22 +91,6 @@ Definition sload : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "charge_gas" |), - make_list [ - M.get_name (| globals, "evm" |); - M.get_name (| globals, "GAS_WARM_ACCESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "add" |), make_list [ @@ -184,7 +168,10 @@ Definition sstore : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.gt (| M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), M.get_name (| globals, "GAS_CALL_STIPEND" |) |); + Compare.gt (| + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "GAS_CALL_STIPEND" |) + |); M.get_name (| globals, "OutOfGasError" |) ], make_dict [] @@ -218,189 +205,15 @@ Definition sstore : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_in (| make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "add" |), - make_list [ - make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ] - ], - make_dict [] - |) in - let gas_cost := BinOp.add - M.get_name (| globals, "GAS_COLD_SLOAD" |) - M.get_name (| globals, "GAS_COLD_SLOAD" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_name (| globals, "original_value" |), M.get_name (| globals, "current_value" |) |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_name (| globals, "current_value" |), M.get_name (| globals, "new_value" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let gas_cost := BinOp.add - M.get_name (| globals, "GAS_STORAGE_SET" |) - M.get_name (| globals, "GAS_STORAGE_SET" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let gas_cost := BinOp.add - BinOp.sub (| - M.get_name (| globals, "GAS_STORAGE_UPDATE" |), - M.get_name (| globals, "GAS_COLD_SLOAD" |) - |) - BinOp.sub (| - M.get_name (| globals, "GAS_STORAGE_UPDATE" |), - M.get_name (| globals, "GAS_COLD_SLOAD" |) - |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let gas_cost := BinOp.add M.get_name (| globals, "GAS_WARM_ACCESS" |) M.get_name (| globals, "GAS_WARM_ACCESS" |) in M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_eq (| M.get_name (| globals, "current_value" |), M.get_name (| globals, "new_value" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), - ltac:(M.monadic ( - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "new_value" |), Constant.int 0 |) - )) - |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), - M.call (| - M.get_name (| globals, "int" |), - make_list [ - M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.sub, - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), - M.call (| - M.get_name (| globals, "int" |), - make_list [ - M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "original_value" |), M.get_name (| globals, "new_value" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), - M.call (| - M.get_name (| globals, "int" |), - make_list [ - BinOp.sub (| - M.get_name (| globals, "GAS_STORAGE_SET" |), - M.get_name (| globals, "GAS_WARM_ACCESS" |) - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), - M.call (| - M.get_name (| globals, "int" |), - make_list [ - BinOp.sub (| - BinOp.sub (| - M.get_name (| globals, "GAS_STORAGE_UPDATE" |), - M.get_name (| globals, "GAS_COLD_SLOAD" |) - |), - M.get_name (| globals, "GAS_WARM_ACCESS" |) - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/paris/vm/instructions/system.v b/CoqOfPython/ethereum/paris/vm/instructions/system.v new file mode 100644 index 0000000..03931b2 --- /dev/null +++ b/CoqOfPython/ethereum/paris/vm/instructions/system.v @@ -0,0 +1,1635 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) System Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM system related instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_account_exists_and_is_empty : + IsGlobalAlias globals state.globals "account_exists_and_is_empty". +Axiom state_account_has_code_or_nonce : + IsGlobalAlias globals state.globals "account_has_code_or_nonce". +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". +Axiom state_increment_nonce : + IsGlobalAlias globals state.globals "increment_nonce". +Axiom state_is_account_alive : + IsGlobalAlias globals state.globals "is_account_alive". +Axiom state_set_account_balance : + IsGlobalAlias globals state.globals "set_account_balance". + +Require utils.address. +Axiom utils_address_compute_contract_address : + IsGlobalAlias globals utils.address.globals "compute_contract_address". +Axiom utils_address_compute_create2_contract_address : + IsGlobalAlias globals utils.address.globals "compute_create2_contract_address". +Axiom utils_address_to_address : + IsGlobalAlias globals utils.address.globals "to_address". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". +Axiom __init___Message : + IsGlobalAlias globals __init__.globals "Message". +Axiom __init___incorporate_child_on_error : + IsGlobalAlias globals __init__.globals "incorporate_child_on_error". +Axiom __init___incorporate_child_on_success : + IsGlobalAlias globals __init__.globals "incorporate_child_on_success". + +Require exceptions. +Axiom exceptions_Revert : + IsGlobalAlias globals exceptions.globals "Revert". +Axiom exceptions_WriteInStaticContext : + IsGlobalAlias globals exceptions.globals "WriteInStaticContext". + +Require gas. +Axiom gas_GAS_CALL_VALUE : + IsGlobalAlias globals gas.globals "GAS_CALL_VALUE". +Axiom gas_GAS_COLD_ACCOUNT_ACCESS : + IsGlobalAlias globals gas.globals "GAS_COLD_ACCOUNT_ACCESS". +Axiom gas_GAS_CREATE : + IsGlobalAlias globals gas.globals "GAS_CREATE". +Axiom gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". +Axiom gas_GAS_NEW_ACCOUNT : + IsGlobalAlias globals gas.globals "GAS_NEW_ACCOUNT". +Axiom gas_GAS_SELF_DESTRUCT : + IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT". +Axiom gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : + IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". +Axiom gas_GAS_WARM_ACCESS : + IsGlobalAlias globals gas.globals "GAS_WARM_ACCESS". +Axiom gas_GAS_ZERO : + IsGlobalAlias globals gas.globals "GAS_ZERO". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_calculate_message_call_gas : + IsGlobalAlias globals gas.globals "calculate_message_call_gas". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". +Axiom gas_max_message_call_gas : + IsGlobalAlias globals gas.globals "max_message_call_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". +Axiom memory_memory_write : + IsGlobalAlias globals memory.globals "memory_write". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition generic_create : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "endowment"; "contract_address"; "memory_start_position"; "memory_size" ] |) in + let _ := Constant.str " + Core logic used by the `CREATE*` family of opcodes. + " in +(* At stmt: unsupported node type: ImportFrom *) + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "contract_address" |) + ], + make_dict [] + |) in + let create_message_gas := + M.call (| + M.get_name (| globals, "max_message_call_gas" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.sub, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "create_message_gas" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let sender_address := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in + let sender := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "sender_address" |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := + M.pure Constant.None_ + )) |) in + let call_data := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + let child_message := + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) in + let child_evm := + M.call (| + M.get_name (| globals, "process_create_message" |), + make_list [ + M.get_name (| globals, "child_message" |); + M.get_field (| M.get_name (| globals, "evm" |), "env" |) + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_success" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition create : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Creates a new account with associated code. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let endowment := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_position" |); M.get_name (| globals, "memory_size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_CREATE" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let contract_address := + M.call (| + M.get_name (| globals, "compute_contract_address" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "nonce" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "generic_create" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "endowment" |); + M.get_name (| globals, "contract_address" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition create2 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Creates a new account with associated code. + + It's similar to CREATE opcode except that the address of new account + depends on the init_code instead of the nonce of sender. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let endowment := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let salt := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_position" |); M.get_name (| globals, "memory_size" |) ] + ] + ], + make_dict [] + |) in + let call_data_words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_CREATE" |), + BinOp.mult (| + M.get_name (| globals, "GAS_KECCAK256_WORD" |), + M.get_name (| globals, "call_data_words" |) + |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let contract_address := + M.call (| + M.get_name (| globals, "compute_create2_contract_address" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "salt" |); + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "generic_create" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "endowment" |); + M.get_name (| globals, "contract_address" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition return_ : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Halts execution returning output data. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let memory_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_position" |); M.get_name (| globals, "memory_size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_ZERO" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "running" |), + Constant.bool false + |) in + let _ := M.pass (| |) in + M.pure Constant.None_)). + +Definition generic_call : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "gas"; "value"; "caller"; "to"; "code_address"; "should_transfer_value"; "is_staticcall"; "memory_input_start_position"; "memory_input_size"; "memory_output_start_position"; "memory_output_size" ] |) in + let _ := Constant.str " + Perform the core logic of the `CALL*` family of opcodes. + " in +(* At stmt: unsupported node type: ImportFrom *) + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let _ := + M.pure Constant.None_ + )) |) in + let call_data := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |) + ], + make_dict [] + |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "code_address" |) + ], + make_dict [] + |), "code" |) in + let child_message := + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) in + let child_evm := + M.call (| + M.get_name (| globals, "process_message" |), + make_list [ + M.get_name (| globals, "child_message" |); + M.get_field (| M.get_name (| globals, "evm" |), "env" |) + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_success" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let actual_output_size := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_name (| globals, "memory_output_size" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), Constant.None_:M.get_name (| globals, "actual_output_size" |) |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition call : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into an account. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let to := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "to" |) + ], + make_dict [] + |) in + let access_gas_cost := + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + M.pure Constant.None_ + )) |) in + let create_gas_cost := + (* if *) +M.if_then_else (| + BoolOp.or (| + M.call (| + M.get_name (| globals, "is_account_alive" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "to" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |) + )) + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let transfer_gas_cost := + (* if *) +M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "access_gas_cost" |), + M.get_name (| globals, "create_gas_cost" |) + |), + M.get_name (| globals, "transfer_gas_cost" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.or (| + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "value" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) + )) + |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let sender_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.get_name (| globals, "value" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "to" |); + Constant.bool true; + Constant.bool false; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition callcode : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into this account with alternative account’s code. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let code_address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let to := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "code_address" |) + ], + make_dict [] + |) in + let access_gas_cost := + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + M.pure Constant.None_ + )) |) in + let transfer_gas_cost := + (* if *) +M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + BinOp.add (| + M.get_name (| globals, "access_gas_cost" |), + M.get_name (| globals, "transfer_gas_cost" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let sender_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.get_name (| globals, "value" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "code_address" |); + Constant.bool true; + Constant.bool false; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition selfdestruct : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Halt execution and register account for later deletion. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let beneficiary := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let gas_cost := + M.get_name (| globals, "GAS_SELF_DESTRUCT" |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "gas_cost" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let originator := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in + let beneficiary_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |), "balance" |) in + let originator_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "originator" |) + ], + make_dict [] + |), "balance" |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |); + BinOp.add (| + M.get_name (| globals, "beneficiary_balance" |), + M.get_name (| globals, "originator_balance" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "originator" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |), "add" |), + make_list [ + M.get_name (| globals, "originator" |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "running" |), + Constant.bool false + |) in + let _ := M.pass (| |) in + M.pure Constant.None_)). + +Definition delegatecall : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into an account. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let code_address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "code_address" |) + ], + make_dict [] + |) in + let access_gas_cost := + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + M.pure Constant.None_ + )) |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + M.get_name (| globals, "access_gas_cost" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "value" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "caller" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "code_address" |); + Constant.bool false; + Constant.bool false; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition staticcall : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into an account. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let to := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "to" |) + ], + make_dict [] + |) in + let access_gas_cost := + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + M.pure Constant.None_ + )) |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + M.get_name (| globals, "access_gas_cost" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "to" |); + Constant.bool true; + Constant.bool true; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition revert : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stop execution and revert state changes, without consuming all provided gas + and also has the ability to return a reason + Parameters + ---------- + evm : + The current EVM frame. + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let output := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "bytes" |), + make_list [ + M.get_name (| globals, "output" |) + ], + make_dict [] + |) + |) in + let _ := M.raise (| Some(M.get_name (| globals, "Revert" |)) + let _ := M.pass (| |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/vm/interpreter.v b/CoqOfPython/ethereum/paris/vm/interpreter.v index 121e62d..5bc6f30 100644 --- a/CoqOfPython/ethereum/paris/vm/interpreter.v +++ b/CoqOfPython/ethereum/paris/vm/interpreter.v @@ -186,91 +186,6 @@ Definition process_message_call : Value.t -> Value.t -> M := Output of the message call " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_name (| globals, "message" |), "target" |), M.call (| - M.get_name (| globals, "Bytes0" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let is_collision := - M.call (| - M.get_name (| globals, "account_has_code_or_nonce" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_field (| M.get_name (| globals, "message" |), "current_target" |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - M.get_name (| globals, "is_collision" |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "MessageCallOutput" |), - make_list [ - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |); - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |); - M.call (| - M.get_name (| globals, "tuple" |), - make_list [], - make_dict [] - |); - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |); - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |); - M.call (| - M.get_name (| globals, "AddressCollision" |), - make_list [], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let evm := - M.call (| - M.get_name (| globals, "process_create_message" |), - make_list [ - M.get_name (| globals, "message" |); - M.get_name (| globals, "env" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let evm := M.call (| M.get_name (| globals, "process_message" |), @@ -281,74 +196,11 @@ Definition process_message_call : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_field (| M.get_name (| globals, "message" |), "target" |) - ], - make_dict [] - |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), - make_list [ - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_field (| M.get_name (| globals, "message" |), "target" |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "evm" |), "error" |), - (* then *) - ltac:(M.monadic ( -(* At stmt: unsupported node type: AnnAssign *) - let accounts_to_delete := - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |) in - let touched_accounts := - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |) in - let refund_counter := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let logs := M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in let accounts_to_delete := @@ -392,7 +244,6 @@ Definition process_message_call : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). Definition process_create_message : Value.t -> Value.t -> M := @@ -454,28 +305,6 @@ Definition process_create_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), - (* then *) - ltac:(M.monadic ( - let contract_code := - M.get_field (| M.get_name (| globals, "evm" |), "output" |) in - let contract_code_gas := - BinOp.mult (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "contract_code" |) - ], - make_dict [] - |), - M.get_name (| globals, "GAS_CODE_DEPOSIT" |) - |) in -(* At stmt: unsupported node type: Try *) - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "rollback_transaction" |), make_list [ @@ -487,7 +316,6 @@ Definition process_create_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) - |) in M.pure Constant.None_)). Definition process_message : Value.t -> Value.t -> M := @@ -509,21 +337,6 @@ Definition process_message : Value.t -> Value.t -> M := Items containing execution specific objects " in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_field (| M.get_name (| globals, "message" |), "depth" |), M.get_name (| globals, "STACK_DEPTH_LIMIT" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "StackDepthLimitError" |), - make_list [ - Constant.str "Stack depth limit reached" - ], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -542,29 +355,6 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - M.get_field (| M.get_name (| globals, "message" |), "should_transfer_value" |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_field (| M.get_name (| globals, "message" |), "value" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "move_ether" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_field (| M.get_name (| globals, "message" |), "caller" |); - M.get_field (| M.get_name (| globals, "message" |), "current_target" |); - M.get_field (| M.get_name (| globals, "message" |), "value" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let evm := @@ -577,21 +367,6 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "evm" |), "error" |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "rollback_transaction" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "commit_transaction" |), make_list [ @@ -603,7 +378,6 @@ Definition process_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) - |) in M.pure Constant.None_)). Definition execute_code : Value.t -> Value.t -> M := @@ -643,5 +417,4 @@ Definition execute_code : Value.t -> Value.t -> M := (* At stmt: unsupported node type: Try *) let _ := M.return_ (| M.get_name (| globals, "evm" |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/vm/memory.v b/CoqOfPython/ethereum/paris/vm/memory.v index fa8d906..4b107fd 100644 --- a/CoqOfPython/ethereum/paris/vm/memory.v +++ b/CoqOfPython/ethereum/paris/vm/memory.v @@ -45,22 +45,7 @@ Definition memory_write : Value.t -> Value.t -> M := Data to write to memory. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) - |) |), + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_)). @@ -86,23 +71,7 @@ Definition memory_read_bytes : Value.t -> Value.t -> M := Data read from memory. " in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |) - |) in + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |) M.pure Constant.None_)). Definition buffer_read : Value.t -> Value.t -> M := @@ -129,25 +98,9 @@ Definition buffer_read : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "right_pad_zero_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |); + M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |) |); M.get_name (| globals, "size" |) ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/alt_bn128.v index 19b83fc..abe4238 100644 --- a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/alt_bn128.v +++ b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/alt_bn128.v @@ -210,15 +210,6 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) in For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ] do let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "i" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -362,15 +353,6 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) in For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ] do let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "i" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -443,24 +425,6 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_eq (| BinOp.mod_ (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "data" |) - ], - make_dict [] - |), - Constant.int 192 - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let result := @@ -509,32 +473,11 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := Constant.int 32, M.get_name (| globals, "j" |) |) - |):BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "i" |), - Constant.int 192 - |), - BinOp.mult (| - Constant.int 32, - BinOp.add (| - M.get_name (| globals, "j" |), - Constant.int 1 - |) - |) |) |) ], make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "value" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -555,17 +498,20 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.call (| - M.get_field (| M.get_name (| globals, "p" |), "mul_by" |), - make_list [ - M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) - ], - make_dict [] - |), M.call (| - M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) |); + Compare.eq (| + M.call (| + M.get_field (| M.get_name (| globals, "p" |), "mul_by" |), + make_list [ + M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) + ], + make_dict [] + |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |); M.get_name (| globals, "OutOfGasError" |) ], make_dict [] @@ -573,87 +519,29 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.call (| - M.get_field (| M.get_name (| globals, "q" |), "mul_by" |), - make_list [ - M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) - ], - make_dict [] - |), M.call (| - M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) |); + Compare.eq (| + M.call (| + M.get_field (| M.get_name (| globals, "q" |), "mul_by" |), + make_list [ + M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) + ], + make_dict [] + |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |); M.get_name (| globals, "OutOfGasError" |) ], make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "p" |), M.call (| - M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_name (| globals, "q" |), M.call (| - M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let result := - BinOp.mult (| - M.get_name (| globals, "result" |), - M.call (| - M.get_name (| globals, "pairing" |), - make_list [ - M.get_name (| globals, "q" |); - M.get_name (| globals, "p" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "result" |), M.call (| - M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), - make_list [ - Constant.int 1 - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign (| - M.get_field (| M.get_name (| globals, "evm" |), "output" |), - M.call (| - M.get_field (| M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 1 - ], - make_dict [] - |), "to_be_bytes32" |), - make_list [], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| diff --git a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/blake2f.v b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/blake2f.v index 5903066..1647d48 100644 --- a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/blake2f.v +++ b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/blake2f.v @@ -55,13 +55,16 @@ Definition blake2f : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "data" |) - ], - make_dict [] - |), Constant.int 213 |); + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 213 + |); M.get_name (| globals, "InvalidParameter" |) ], make_dict [] @@ -96,10 +99,13 @@ Definition blake2f : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.in (| M.get_name (| globals, "f" |), make_list [ - Constant.int 0; - Constant.int 1 - ] |); + Compare.in (| + M.get_name (| globals, "f" |), + make_list [ + Constant.int 0; + Constant.int 1 + ] + |); M.get_name (| globals, "InvalidParameter" |) ], make_dict [] diff --git a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/ecrecover.v index cc351b5..0cbcf16 100644 --- a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/ecrecover.v @@ -188,60 +188,12 @@ Definition ecrecover : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 27 |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 28 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| Constant.int 0, M.get_name (| globals, "r" |) |), - ltac:(M.monadic ( - Compare.gt_e (| M.get_name (| globals, "r" |), M.get_name (| globals, "SECP256K1N" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| Constant.int 0, M.get_name (| globals, "s" |) |), - ltac:(M.monadic ( - Compare.gt_e (| M.get_name (| globals, "s" |), M.get_name (| globals, "SECP256K1N" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: Try *) @@ -252,7 +204,7 @@ Definition ecrecover : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12:Constant.int 32 |) in + |), Constant.int 12 |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/modexp.v index 544949e..3505244 100644 --- a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/modexp.v +++ b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/modexp.v @@ -192,30 +192,6 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_name (| globals, "base_length" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "modulus_length" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign (| - M.get_field (| M.get_name (| globals, "evm" |), "output" |), - M.call (| - M.get_name (| globals, "Bytes" |), - make_list [], - make_dict [] - |) - |) in - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let base := @@ -278,27 +254,6 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "modulus" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign (| - M.get_field (| M.get_name (| globals, "evm" |), "output" |), - BinOp.mult (| - M.call (| - M.get_name (| globals, "Bytes" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |), - M.get_name (| globals, "modulus_length" |) - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| @@ -383,7 +338,6 @@ Definition complexity : Value.t -> Value.t -> M := M.get_name (| globals, "words" |), Constant.int 2 |) - |) in M.pure Constant.None_)). Definition iterations : Value.t -> Value.t -> M := @@ -410,64 +364,7 @@ Definition iterations : Value.t -> Value.t -> M := Number of iterations. " in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.lt_e (| M.get_name (| globals, "exponent_length" |), Constant.int 32 |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "exponent_head" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let count := - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - Compare.lt_e (| M.get_name (| globals, "exponent_length" |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let bit_length := - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.call (| - M.get_field (| M.get_name (| globals, "exponent_head" |), "bit_length" |), - make_list [], - make_dict [] - |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "bit_length" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let bit_length := BinOp.sub - Constant.int 1 - Constant.int 1 in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let count := - M.get_name (| globals, "bit_length" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let length_part := BinOp.mult (| Constant.int 8, @@ -495,17 +392,6 @@ Definition iterations : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "bits_part" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let bits_part := BinOp.sub - Constant.int 1 - Constant.int 1 in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let count := @@ -532,7 +418,6 @@ Definition iterations : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition gas_cost : Value.t -> Value.t -> M := @@ -604,5 +489,4 @@ Definition gas_cost : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/vm/runtime.v b/CoqOfPython/ethereum/paris/vm/runtime.v index 835b46c..2cd7652 100644 --- a/CoqOfPython/ethereum/paris/vm/runtime.v +++ b/CoqOfPython/ethereum/paris/vm/runtime.v @@ -67,50 +67,19 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := ], make_dict [] |) in - While Compare.lt (| M.get_name (| globals, "pc" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "code" |) - ], - make_dict [] - |) |) do + While Compare.lt (| + M.get_name (| globals, "pc" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) + |) do (* At stmt: unsupported node type: Try *) let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "current_opcode" |), M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), - make_list [ - M.get_name (| globals, "pc" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - (* At expr: unsupported node type: Compare *), - (* then *) - ltac:(M.monadic ( - let push_data_size := - BinOp.add (| - BinOp.sub (| - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) - |), - Constant.int 1 - |) in - let pc := BinOp.add - M.get_name (| globals, "push_data_size" |) - M.get_name (| globals, "push_data_size" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -121,5 +90,4 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := EndWhile. let _ := M.return_ (| M.get_name (| globals, "valid_jump_destinations" |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/vm/stack.v b/CoqOfPython/ethereum/paris/vm/stack.v index 42ea42d..ea778df 100644 --- a/CoqOfPython/ethereum/paris/vm/stack.v +++ b/CoqOfPython/ethereum/paris/vm/stack.v @@ -49,21 +49,6 @@ Definition pop : Value.t -> Value.t -> M := " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "stack" |) - ], - make_dict [] - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "StackUnderflowError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -72,7 +57,6 @@ Definition pop : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). Definition push : Value.t -> Value.t -> M := @@ -91,21 +75,6 @@ Definition push : Value.t -> Value.t -> M := " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "stack" |) - ], - make_dict [] - |), Constant.int 1024 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "StackOverflowError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -116,5 +85,4 @@ Definition push : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/rlp.v b/CoqOfPython/ethereum/rlp.v index 6479bf7..386cbf4 100644 --- a/CoqOfPython/ethereum/rlp.v +++ b/CoqOfPython/ethereum/rlp.v @@ -97,189 +97,12 @@ Definition encode : Value.t -> Value.t -> M := The RLP encoded bytes representing `raw_data`. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "raw_data" |); - make_tuple [ M.get_name (| globals, "bytearray" |); M.get_name (| globals, "bytes" |) ] - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "encode_bytes" |), - make_list [ - M.get_name (| globals, "raw_data" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "raw_data" |); - make_tuple [ M.get_name (| globals, "Uint" |); M.get_name (| globals, "FixedUint" |) ] - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "encode" |), - make_list [ - M.call (| - M.get_field (| M.get_name (| globals, "raw_data" |), "to_be_bytes" |), - make_list [], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "raw_data" |); - M.get_name (| globals, "str" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "encode_bytes" |), - make_list [ - M.call (| - M.get_field (| M.get_name (| globals, "raw_data" |), "encode" |), - make_list [], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "raw_data" |); - M.get_name (| globals, "bool" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - M.get_name (| globals, "raw_data" |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "encode_bytes" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "encode_bytes" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "raw_data" |); - M.get_name (| globals, "Sequence" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "encode_sequence" |), - make_list [ - M.get_name (| globals, "raw_data" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "is_dataclass" |), - make_list [ - M.get_name (| globals, "raw_data" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "encode" |), - make_list [ - M.call (| - M.get_name (| globals, "astuple" |), - make_list [ - M.get_name (| globals, "raw_data" |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.call (| + let _ := M.raise (| Some(M.call (| M.get_name (| globals, "RLPEncodingError" |), make_list [ M.call (| @@ -297,7 +120,7 @@ Definition encode : Value.t -> Value.t -> M := |) ], make_dict [] - |) |) in + |)) M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -343,48 +166,7 @@ Definition encode_bytes : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_name (| globals, "len_raw_data" |), Constant.int 1 |), - ltac:(M.monadic ( - Compare.lt (| M.get_subscript (| M.get_name (| globals, "raw_bytes" |), Constant.int 0 |), Constant.int 128 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "raw_bytes" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "len_raw_data" |), Constant.int 56 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - BinOp.add (| - M.call (| - M.get_name (| globals, "bytes" |), - make_list [ - make_list [ - BinOp.add (| - Constant.int 128, - M.get_name (| globals, "len_raw_data" |) - |) - ] - ], - make_dict [] - |), - M.get_name (| globals, "raw_bytes" |) - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let len_raw_data_as_be := M.call (| M.get_field (| M.get_name (| globals, "len_raw_data" |), "to_be_bytes" |), @@ -416,7 +198,6 @@ Definition encode_bytes : Value.t -> Value.t -> M := |), M.get_name (| globals, "raw_bytes" |) |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -462,31 +243,6 @@ Definition encode_sequence : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "len_joined_encodings" |), Constant.int 56 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - BinOp.add (| - M.call (| - M.get_name (| globals, "Bytes" |), - make_list [ - make_list [ - BinOp.add (| - Constant.int 192, - M.get_name (| globals, "len_joined_encodings" |) - |) - ] - ], - make_dict [] - |), - M.get_name (| globals, "joined_encodings" |) - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let len_joined_encodings_as_be := M.call (| M.get_field (| M.get_name (| globals, "len_joined_encodings" |), "to_be_bytes" |), @@ -518,7 +274,6 @@ Definition encode_sequence : Value.t -> Value.t -> M := |), M.get_name (| globals, "joined_encodings" |) |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -543,19 +298,12 @@ Definition get_joined_encodings : Value.t -> Value.t -> M := " in let _ := M.return_ (| M.call (| - M.get_field (| (* At constant: unsupported node type: Constant *), "join" |), + M.get_field (| Constant.bytes "", "join" |), make_list [ - (M.call (| - M.get_name (| globals, "encode" |), - make_list [ - M.get_name (| globals, "item" |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)) + (* At expr: unsupported node type: GeneratorExp *) ], make_dict [] |) - |) in M.pure Constant.None_)). Definition decode : Value.t -> Value.t -> M := @@ -578,13 +326,16 @@ Definition decode : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.gt (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "encoded_data" |) - ], - make_dict [] - |), Constant.int 0 |); + Compare.gt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded_data" |) + ], + make_dict [] + |), + Constant.int 0 + |); M.call (| M.get_name (| globals, "RLPDecodingError" |), make_list [ @@ -596,23 +347,6 @@ Definition decode : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt_e (| M.get_subscript (| M.get_name (| globals, "encoded_data" |), Constant.int 0 |), Constant.int 191 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "decode_to_bytes" |), - make_list [ - M.get_name (| globals, "encoded_data" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_name (| globals, "decode_to_sequence" |), @@ -621,7 +355,6 @@ Definition decode : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -670,7 +403,6 @@ Definition decode_to : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition _decode_to : Value.t -> Value.t -> M := @@ -694,904 +426,151 @@ Definition _decode_to : Value.t -> Value.t -> M := Object decoded from `encoded_data`. " in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "cls" |); - M.call (| - M.get_name (| globals, "type" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "Tuple" |), make_tuple [ M.get_name (| globals, "Uint" |); (* At constant: unsupported node type: Constant *) ] |) - ], - make_dict [] - |) - ], - make_dict [] - |), - ltac:(M.monadic ( - Compare.eq (| M.get_field (| M.get_name (| globals, "cls" |), "_name" |), Constant.str "Tuple" |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| + let _ := + let _ := + let _ := + let _ := + let _ := + let _ := + let _ := + let _ := + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "RLPDecodingError" |), + make_list [ + M.call (| + M.get_field (| Constant.str "RLP Decoding to type {} is not supported", "format" |), + make_list [ + M.get_name (| globals, "cls" |) + ], + make_dict [] + |) + ], + make_dict [] + |)) + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition decode_to_bytes : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "encoded_bytes" ] |) in + let _ := Constant.str " + Decodes a rlp encoded byte stream assuming that the decoded data + should be of type `bytes`. + + Parameters + ---------- + encoded_bytes : + RLP encoded byte stream. + + Returns + ------- + decoded : `ethereum.base_types.Bytes` + RLP decoded Bytes data + " in + let _ := + let _ := + let decoded_data_start_idx := + BinOp.sub (| + BinOp.add (| + Constant.int 1, + M.get_subscript (| M.get_name (| globals, "encoded_bytes" |), Constant.int 0 |) + |), + Constant.int 183 + |) in + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "raw_rlp" |); - M.get_name (| globals, "list" |) - ], - make_dict [] + Compare.lt (| + BinOp.sub (| + M.get_name (| globals, "decoded_data_start_idx" |), + Constant.int 1 + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded_bytes" |) + ], + make_dict [] + |) |); M.get_name (| globals, "RLPDecodingError" |) ], make_dict [] |) in - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_subscript (| M.get_field (| M.get_name (| globals, "cls" |), "__args__" |), Constant.int 1 |), (* At constant: unsupported node type: Constant *) |), - (* then *) - ltac:(M.monadic ( - let args := - make_list [] in - For M.get_name (| globals, "raw_item" |) in M.get_name (| globals, "raw_rlp" |) do - let _ := M.call (| - M.get_field (| M.get_name (| globals, "args" |), "append" |), + let _ := M.call (| + M.get_name (| globals, "ensure" |), make_list [ - M.call (| - M.get_name (| globals, "_decode_to" |), - make_list [ - M.get_subscript (| M.get_field (| M.get_name (| globals, "cls" |), "__args__" |), Constant.int 0 |); - M.get_name (| globals, "raw_item" |) - ], - make_dict [] - |) + Compare.not_eq (| + M.get_subscript (| M.get_name (| globals, "encoded_bytes" |), Constant.int 1 |), + Constant.int 0 + |); + M.get_name (| globals, "RLPDecodingError" |) ], make_dict [] |) in - EndFor. - let _ := M.return_ (| + let len_decoded_data := M.call (| - M.get_name (| globals, "tuple" |), + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ - M.get_name (| globals, "args" |) + M.get_subscript (| M.get_name (| globals, "encoded_bytes" |), Constant.int 1 |) ], make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let args := - make_list [] in + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "raw_rlp" |) - ], - make_dict [] - |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "cls" |), "__args__" |) - ], - make_dict [] - |) |); + Compare.gt_e (| + M.get_name (| globals, "len_decoded_data" |), + Constant.int 56 + |); M.get_name (| globals, "RLPDecodingError" |) ], make_dict [] |) in - For make_tuple [ M.get_name (| globals, "t" |); M.get_name (| globals, "raw_item" |) ] in M.call (| - M.get_name (| globals, "zip" |), - make_list [ - M.get_field (| M.get_name (| globals, "cls" |), "__args__" |); - M.get_name (| globals, "raw_rlp" |) - ], - make_dict [] - |) do - let _ := M.call (| - M.get_field (| M.get_name (| globals, "args" |), "append" |), - make_list [ - M.call (| - M.get_name (| globals, "_decode_to" |), - make_list [ - M.get_name (| globals, "t" |); - M.get_name (| globals, "raw_item" |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - EndFor. - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "tuple" |), - make_list [ - M.get_name (| globals, "args" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "cls" |), M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Bytes0" |); M.get_name (| globals, "Bytes20" |) ] |) |), - (* then *) - ltac:(M.monadic ( + let decoded_data_end_idx := + BinOp.add (| + M.get_name (| globals, "decoded_data_start_idx" |), + M.get_name (| globals, "len_decoded_data" |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "raw_rlp" |); - M.get_name (| globals, "Bytes" |) - ], - make_dict [] + Compare.lt (| + BinOp.sub (| + M.get_name (| globals, "decoded_data_end_idx" |), + Constant.int 1 + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded_bytes" |) + ], + make_dict [] + |) |); M.get_name (| globals, "RLPDecodingError" |) ], make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "raw_rlp" |) - ], - make_dict [] - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "Bytes0" |), - make_list [], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "raw_rlp" |) - ], - make_dict [] - |), Constant.int 20 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "Bytes20" |), - make_list [ - M.get_name (| globals, "raw_rlp" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "RLPDecodingError" |), - make_list [ - M.call (| - M.get_field (| Constant.str "Bytes has length {}, expected 0 or 20", "format" |), - make_list [ - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "raw_rlp" |) - ], - make_dict [] - |) - ], - make_dict [] - |) - ], - make_dict [] - |) |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "cls" |); - M.call (| - M.get_name (| globals, "type" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "List" |), M.get_name (| globals, "Bytes" |) |) - ], - make_dict [] - |) - ], - make_dict [] - |), - ltac:(M.monadic ( - Compare.eq (| M.get_field (| M.get_name (| globals, "cls" |), "_name" |), Constant.str "List" |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "ensure" |), - make_list [ - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "raw_rlp" |); - M.get_name (| globals, "list" |) - ], - make_dict [] - |); - M.get_name (| globals, "RLPDecodingError" |) - ], - make_dict [] - |) in - let items := - make_list [] in - For M.get_name (| globals, "raw_item" |) in M.get_name (| globals, "raw_rlp" |) do - let _ := M.call (| - M.get_field (| M.get_name (| globals, "items" |), "append" |), - make_list [ - M.call (| - M.get_name (| globals, "_decode_to" |), - make_list [ - M.get_subscript (| M.get_field (| M.get_name (| globals, "cls" |), "__args__" |), Constant.int 0 |); - M.get_name (| globals, "raw_item" |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - EndFor. - let _ := M.return_ (| - M.get_name (| globals, "items" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "cls" |); - M.call (| - M.get_name (| globals, "type" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Bytes" |); M.get_subscript (| M.get_name (| globals, "List" |), M.get_name (| globals, "Bytes" |) |) ] |) - ], - make_dict [] - |) - ], - make_dict [] - |), - ltac:(M.monadic ( - Compare.eq (| M.get_field (| M.get_name (| globals, "cls" |), "__origin__" |), M.get_name (| globals, "Union" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.not_eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "cls" |), "__args__" |) - ], - make_dict [] - |), Constant.int 2 |), - ltac:(M.monadic ( - Compare.not_in (| M.get_name (| globals, "Bytes" |), M.get_field (| M.get_name (| globals, "cls" |), "__args__" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "RLPDecodingError" |), - make_list [ - M.call (| - M.get_field (| Constant.str "RLP Decoding to type {} is not supported", "format" |), - make_list [ - M.get_name (| globals, "cls" |) - ], - make_dict [] - |) - ], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "raw_rlp" |); - M.get_name (| globals, "Bytes" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "raw_rlp" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_subscript (| M.get_field (| M.get_name (| globals, "cls" |), "__args__" |), Constant.int 0 |), M.get_name (| globals, "Bytes" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "_decode_to" |), - make_list [ - M.get_subscript (| M.get_field (| M.get_name (| globals, "cls" |), "__args__" |), Constant.int 1 |); - M.get_name (| globals, "raw_rlp" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "_decode_to" |), - make_list [ - M.get_subscript (| M.get_field (| M.get_name (| globals, "cls" |), "__args__" |), Constant.int 0 |); - M.get_name (| globals, "raw_rlp" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "issubclass" |), - make_list [ - M.get_name (| globals, "cls" |); - M.get_name (| globals, "bool" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "raw_rlp" |), (* At constant: unsupported node type: Constant *) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "cls" |), - make_list [ - Constant.bool true - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "raw_rlp" |), (* At constant: unsupported node type: Constant *) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "cls" |), - make_list [ - Constant.bool false - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "TypeError" |), - make_list [ - M.call (| - M.get_field (| Constant.str "Cannot decode {} as {}", "format" |), - make_list [ - M.get_name (| globals, "raw_rlp" |); - M.get_name (| globals, "cls" |) - ], - make_dict [] - |) - ], - make_dict [] - |) |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "issubclass" |), - make_list [ - M.get_name (| globals, "cls" |); - M.get_name (| globals, "FixedBytes" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "ensure" |), - make_list [ - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "raw_rlp" |); - M.get_name (| globals, "Bytes" |) - ], - make_dict [] - |); - M.get_name (| globals, "RLPDecodingError" |) - ], - make_dict [] - |) in - let _ := M.call (| - M.get_name (| globals, "ensure" |), - make_list [ - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "raw_rlp" |) - ], - make_dict [] - |), M.get_field (| M.get_name (| globals, "cls" |), "LENGTH" |) |); - M.get_name (| globals, "RLPDecodingError" |) - ], - make_dict [] - |) in - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "cls" |), - make_list [ - M.get_name (| globals, "raw_rlp" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "issubclass" |), - make_list [ - M.get_name (| globals, "cls" |); - M.get_name (| globals, "Bytes" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "ensure" |), - make_list [ - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "raw_rlp" |); - M.get_name (| globals, "Bytes" |) - ], - make_dict [] - |); - M.get_name (| globals, "RLPDecodingError" |) - ], - make_dict [] - |) in - let _ := M.return_ (| - M.get_name (| globals, "raw_rlp" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "issubclass" |), - make_list [ - M.get_name (| globals, "cls" |); - make_tuple [ M.get_name (| globals, "Uint" |); M.get_name (| globals, "FixedUint" |) ] - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "ensure" |), - make_list [ - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "raw_rlp" |); - M.get_name (| globals, "Bytes" |) - ], - make_dict [] - |); - M.get_name (| globals, "RLPDecodingError" |) - ], - make_dict [] - |) in -(* At stmt: unsupported node type: Try *) - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "is_dataclass" |), - make_list [ - M.get_name (| globals, "cls" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "ensure" |), - make_list [ - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "raw_rlp" |); - M.get_name (| globals, "list" |) - ], - make_dict [] - |); - M.get_name (| globals, "RLPDecodingError" |) - ], - make_dict [] - |) in - let _ := M.assert (| M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "raw_rlp" |); - M.get_name (| globals, "list" |) - ], - make_dict [] - |) |) in - let args := - make_list [] in - let _ := M.call (| - M.get_name (| globals, "ensure" |), - make_list [ - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.call (| - M.get_name (| globals, "fields" |), - make_list [ - M.get_name (| globals, "cls" |) - ], - make_dict [] - |) - ], - make_dict [] - |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "raw_rlp" |) - ], - make_dict [] - |) |); - M.get_name (| globals, "RLPDecodingError" |) - ], - make_dict [] - |) in - For make_tuple [ M.get_name (| globals, "field" |); M.get_name (| globals, "rlp_item" |) ] in M.call (| - M.get_name (| globals, "zip" |), - make_list [ - M.call (| - M.get_name (| globals, "fields" |), - make_list [ - M.get_name (| globals, "cls" |) - ], - make_dict [] - |); - M.get_name (| globals, "raw_rlp" |) - ], - make_dict [] - |) do - let _ := M.call (| - M.get_field (| M.get_name (| globals, "args" |), "append" |), - make_list [ - M.call (| - M.get_name (| globals, "_decode_to" |), - make_list [ - M.get_field (| M.get_name (| globals, "field" |), "type" |); - M.get_name (| globals, "rlp_item" |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - EndFor. - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "cast" |), - make_list [ - M.get_name (| globals, "T" |); - M.call (| - M.get_name (| globals, "cls" |), - M.get_name (| globals, "args" |), - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "RLPDecodingError" |), - make_list [ - M.call (| - M.get_field (| Constant.str "RLP Decoding to type {} is not supported", "format" |), - make_list [ - M.get_name (| globals, "cls" |) - ], - make_dict [] - |) - ], - make_dict [] - |) |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_)). - -Definition decode_to_bytes : Value.t -> Value.t -> M := - fun (args kwargs : Value.t) => ltac:(M.monadic ( - let _ := M.set_locals (| args, kwargs, [ "encoded_bytes" ] |) in - let _ := Constant.str " - Decodes a rlp encoded byte stream assuming that the decoded data - should be of type `bytes`. - - Parameters - ---------- - encoded_bytes : - RLP encoded byte stream. - - Returns - ------- - decoded : `ethereum.base_types.Bytes` - RLP decoded Bytes data - " in - let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "encoded_bytes" |) - ], - make_dict [] - |), Constant.int 1 |), - ltac:(M.monadic ( - Compare.lt (| M.get_subscript (| M.get_name (| globals, "encoded_bytes" |), Constant.int 0 |), Constant.int 128 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "encoded_bytes" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.lt_e (| M.get_subscript (| M.get_name (| globals, "encoded_bytes" |), Constant.int 0 |), Constant.int 183 |), - (* then *) - ltac:(M.monadic ( - let len_raw_data := - BinOp.sub (| - M.get_subscript (| M.get_name (| globals, "encoded_bytes" |), Constant.int 0 |), - Constant.int 128 - |) in - let _ := M.call (| - M.get_name (| globals, "ensure" |), - make_list [ - Compare.lt (| M.get_name (| globals, "len_raw_data" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "encoded_bytes" |) - ], - make_dict [] - |) |); - M.get_name (| globals, "RLPDecodingError" |) - ], - make_dict [] - |) in - let raw_data := - M.get_subscript (| M.get_name (| globals, "encoded_bytes" |), Constant.int 1:BinOp.add (| - Constant.int 1, - M.get_name (| globals, "len_raw_data" |) - |) |) in - let _ := M.call (| - M.get_name (| globals, "ensure" |), - make_list [ - UnOp.not (| BoolOp.and (| - Compare.eq (| M.get_name (| globals, "len_raw_data" |), Constant.int 1 |), - ltac:(M.monadic ( - Compare.lt (| M.get_subscript (| M.get_name (| globals, "raw_data" |), Constant.int 0 |), Constant.int 128 |) - )) - |) |); - M.get_name (| globals, "RLPDecodingError" |) - ], - make_dict [] - |) in - let _ := M.return_ (| - M.get_name (| globals, "raw_data" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let decoded_data_start_idx := - BinOp.sub (| - BinOp.add (| - Constant.int 1, - M.get_subscript (| M.get_name (| globals, "encoded_bytes" |), Constant.int 0 |) - |), - Constant.int 183 - |) in - let _ := M.call (| - M.get_name (| globals, "ensure" |), - make_list [ - Compare.lt (| BinOp.sub (| - M.get_name (| globals, "decoded_data_start_idx" |), - Constant.int 1 - |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "encoded_bytes" |) - ], - make_dict [] - |) |); - M.get_name (| globals, "RLPDecodingError" |) - ], - make_dict [] - |) in - let _ := M.call (| - M.get_name (| globals, "ensure" |), - make_list [ - Compare.not_eq (| M.get_subscript (| M.get_name (| globals, "encoded_bytes" |), Constant.int 1 |), Constant.int 0 |); - M.get_name (| globals, "RLPDecodingError" |) - ], - make_dict [] - |) in - let len_decoded_data := - M.call (| - M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "encoded_bytes" |), Constant.int 1:M.get_name (| globals, "decoded_data_start_idx" |) |) - ], - make_dict [] - |) in - let _ := M.call (| - M.get_name (| globals, "ensure" |), - make_list [ - Compare.gt_e (| M.get_name (| globals, "len_decoded_data" |), Constant.int 56 |); - M.get_name (| globals, "RLPDecodingError" |) - ], - make_dict [] - |) in - let decoded_data_end_idx := - BinOp.add (| - M.get_name (| globals, "decoded_data_start_idx" |), - M.get_name (| globals, "len_decoded_data" |) - |) in - let _ := M.call (| - M.get_name (| globals, "ensure" |), - make_list [ - Compare.lt (| BinOp.sub (| - M.get_name (| globals, "decoded_data_end_idx" |), - Constant.int 1 - |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "encoded_bytes" |) - ], - make_dict [] - |) |); - M.get_name (| globals, "RLPDecodingError" |) - ], - make_dict [] |) in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "encoded_bytes" |), M.get_name (| globals, "decoded_data_start_idx" |):M.get_name (| globals, "decoded_data_end_idx" |) |) - |) in + M.get_subscript (| M.get_name (| globals, "encoded_bytes" |), M.get_name (| globals, "decoded_data_start_idx" |) |) M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -1616,38 +595,6 @@ Definition decode_to_sequence : Value.t -> Value.t -> M := Sequence of objects decoded from `encoded_sequence`. " in let _ := - (* if *) - M.if_then_else (| - Compare.lt_e (| M.get_subscript (| M.get_name (| globals, "encoded_sequence" |), Constant.int 0 |), Constant.int 247 |), - (* then *) - ltac:(M.monadic ( - let len_joined_encodings := - BinOp.sub (| - M.get_subscript (| M.get_name (| globals, "encoded_sequence" |), Constant.int 0 |), - Constant.int 192 - |) in - let _ := M.call (| - M.get_name (| globals, "ensure" |), - make_list [ - Compare.lt (| M.get_name (| globals, "len_joined_encodings" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "encoded_sequence" |) - ], - make_dict [] - |) |); - M.get_name (| globals, "RLPDecodingError" |) - ], - make_dict [] - |) in - let joined_encodings := - M.get_subscript (| M.get_name (| globals, "encoded_sequence" |), Constant.int 1:BinOp.add (| - Constant.int 1, - M.get_name (| globals, "len_joined_encodings" |) - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let joined_encodings_start_idx := BinOp.sub (| BinOp.add (| @@ -1659,16 +606,19 @@ Definition decode_to_sequence : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt (| BinOp.sub (| - M.get_name (| globals, "joined_encodings_start_idx" |), - Constant.int 1 - |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "encoded_sequence" |) - ], - make_dict [] - |) |); + Compare.lt (| + BinOp.sub (| + M.get_name (| globals, "joined_encodings_start_idx" |), + Constant.int 1 + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded_sequence" |) + ], + make_dict [] + |) + |); M.get_name (| globals, "RLPDecodingError" |) ], make_dict [] @@ -1676,7 +626,10 @@ Definition decode_to_sequence : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.not_eq (| M.get_subscript (| M.get_name (| globals, "encoded_sequence" |), Constant.int 1 |), Constant.int 0 |); + Compare.not_eq (| + M.get_subscript (| M.get_name (| globals, "encoded_sequence" |), Constant.int 1 |), + Constant.int 0 + |); M.get_name (| globals, "RLPDecodingError" |) ], make_dict [] @@ -1685,14 +638,17 @@ Definition decode_to_sequence : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "encoded_sequence" |), Constant.int 1:M.get_name (| globals, "joined_encodings_start_idx" |) |) + M.get_subscript (| M.get_name (| globals, "encoded_sequence" |), Constant.int 1 |) ], make_dict [] |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.gt_e (| M.get_name (| globals, "len_joined_encodings" |), Constant.int 56 |); + Compare.gt_e (| + M.get_name (| globals, "len_joined_encodings" |), + Constant.int 56 + |); M.get_name (| globals, "RLPDecodingError" |) ], make_dict [] @@ -1705,22 +661,25 @@ Definition decode_to_sequence : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt (| BinOp.sub (| - M.get_name (| globals, "joined_encodings_end_idx" |), - Constant.int 1 - |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "encoded_sequence" |) - ], - make_dict [] - |) |); + Compare.lt (| + BinOp.sub (| + M.get_name (| globals, "joined_encodings_end_idx" |), + Constant.int 1 + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded_sequence" |) + ], + make_dict [] + |) + |); M.get_name (| globals, "RLPDecodingError" |) ], make_dict [] |) in let joined_encodings := - M.get_subscript (| M.get_name (| globals, "encoded_sequence" |), M.get_name (| globals, "joined_encodings_start_idx" |):M.get_name (| globals, "joined_encodings_end_idx" |) |) in + M.get_subscript (| M.get_name (| globals, "encoded_sequence" |), M.get_name (| globals, "joined_encodings_start_idx" |) |) in M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1731,7 +690,6 @@ Definition decode_to_sequence : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition decode_joined_encodings : Value.t -> Value.t -> M := @@ -1755,46 +713,49 @@ Definition decode_joined_encodings : Value.t -> Value.t -> M := make_list [] in let item_start_idx := Constant.int 0 in - While Compare.lt (| M.get_name (| globals, "item_start_idx" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "joined_encodings" |) - ], - make_dict [] - |) |) do + While Compare.lt (| + M.get_name (| globals, "item_start_idx" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "joined_encodings" |) + ], + make_dict [] + |) + |) do let encoded_item_length := M.call (| M.get_name (| globals, "decode_item_length" |), make_list [ - M.get_subscript (| M.get_name (| globals, "joined_encodings" |), M.get_name (| globals, "item_start_idx" |):(* At expr: unsupported node type: NoneType *) |) + M.get_subscript (| M.get_name (| globals, "joined_encodings" |), M.get_name (| globals, "item_start_idx" |) |) ], make_dict [] |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt (| BinOp.sub (| - BinOp.add (| - M.get_name (| globals, "item_start_idx" |), - M.get_name (| globals, "encoded_item_length" |) + Compare.lt (| + BinOp.sub (| + BinOp.add (| + M.get_name (| globals, "item_start_idx" |), + M.get_name (| globals, "encoded_item_length" |) + |), + Constant.int 1 |), - Constant.int 1 - |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "joined_encodings" |) - ], - make_dict [] - |) |); + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "joined_encodings" |) + ], + make_dict [] + |) + |); M.get_name (| globals, "RLPDecodingError" |) ], make_dict [] |) in let encoded_item := - M.get_subscript (| M.get_name (| globals, "joined_encodings" |), M.get_name (| globals, "item_start_idx" |):BinOp.add (| - M.get_name (| globals, "item_start_idx" |), - M.get_name (| globals, "encoded_item_length" |) - |) |) in + M.get_subscript (| M.get_name (| globals, "joined_encodings" |), M.get_name (| globals, "item_start_idx" |) |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "decoded_sequence" |), "append" |), make_list [ @@ -1814,7 +775,6 @@ Definition decode_joined_encodings : Value.t -> Value.t -> M := EndWhile. let _ := M.return_ (| M.get_name (| globals, "decoded_sequence" |) - |) in M.pure Constant.None_)). Definition decode_item_length : Value.t -> Value.t -> M := @@ -1842,13 +802,16 @@ Definition decode_item_length : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.gt (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "encoded_data" |) - ], - make_dict [] - |), Constant.int 0 |); + Compare.gt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded_data" |) + ], + make_dict [] + |), + Constant.int 0 + |); M.get_name (| globals, "RLPDecodingError" |) ], make_dict [] @@ -1872,139 +835,10 @@ Definition decode_item_length : Value.t -> Value.t -> M := let decoded_data_length := Constant.int 0 in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "first_rlp_byte" |), Constant.int 128 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.int 1 - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - Compare.lt_e (| M.get_name (| globals, "first_rlp_byte" |), Constant.int 183 |), - (* then *) - ltac:(M.monadic ( - let decoded_data_length := - BinOp.sub (| - M.get_name (| globals, "first_rlp_byte" |), - Constant.int 128 - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - Compare.lt_e (| M.get_name (| globals, "first_rlp_byte" |), Constant.int 191 |), - (* then *) - ltac:(M.monadic ( - let length_length := - BinOp.sub (| - M.get_name (| globals, "first_rlp_byte" |), - Constant.int 183 - |) in - let _ := M.call (| - M.get_name (| globals, "ensure" |), - make_list [ - Compare.lt (| M.get_name (| globals, "length_length" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "encoded_data" |) - ], - make_dict [] - |) |); - M.get_name (| globals, "RLPDecodingError" |) - ], - make_dict [] - |) in - let _ := M.call (| - M.get_name (| globals, "ensure" |), - make_list [ - Compare.not_eq (| M.get_subscript (| M.get_name (| globals, "encoded_data" |), Constant.int 1 |), Constant.int 0 |); - M.get_name (| globals, "RLPDecodingError" |) - ], - make_dict [] - |) in - let decoded_data_length := - M.call (| - M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "encoded_data" |), Constant.int 1:BinOp.add (| - Constant.int 1, - M.get_name (| globals, "length_length" |) - |) |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - Compare.lt_e (| M.get_name (| globals, "first_rlp_byte" |), Constant.int 247 |), - (* then *) - ltac:(M.monadic ( - let decoded_data_length := - BinOp.sub (| - M.get_name (| globals, "first_rlp_byte" |), - Constant.int 192 - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - Compare.lt_e (| M.get_name (| globals, "first_rlp_byte" |), Constant.int 255 |), - (* then *) - ltac:(M.monadic ( - let length_length := - BinOp.sub (| - M.get_name (| globals, "first_rlp_byte" |), - Constant.int 247 - |) in - let _ := M.call (| - M.get_name (| globals, "ensure" |), - make_list [ - Compare.lt (| M.get_name (| globals, "length_length" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "encoded_data" |) - ], - make_dict [] - |) |); - M.get_name (| globals, "RLPDecodingError" |) - ], - make_dict [] - |) in - let _ := M.call (| - M.get_name (| globals, "ensure" |), - make_list [ - Compare.not_eq (| M.get_subscript (| M.get_name (| globals, "encoded_data" |), Constant.int 1 |), Constant.int 0 |); - M.get_name (| globals, "RLPDecodingError" |) - ], - make_dict [] - |) in - let decoded_data_length := - M.call (| - M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "encoded_data" |), Constant.int 1:BinOp.add (| - Constant.int 1, - M.get_name (| globals, "length_length" |) - |) |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -2023,7 +857,6 @@ Definition decode_item_length : Value.t -> Value.t -> M := |), M.get_name (| globals, "decoded_data_length" |) |) - |) in M.pure Constant.None_)). Definition rlp_hash : Value.t -> Value.t -> M := @@ -2056,5 +889,4 @@ Definition rlp_hash : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/bloom.v b/CoqOfPython/ethereum/shanghai/bloom.v index 04b5d9f..04650ff 100644 --- a/CoqOfPython/ethereum/shanghai/bloom.v +++ b/CoqOfPython/ethereum/shanghai/bloom.v @@ -72,10 +72,7 @@ Definition add_to_bloom : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |):BinOp.add (| - M.get_name (| globals, "idx" |), - Constant.int 2 - |) |) + M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |) |) ], make_dict [] |), @@ -160,5 +157,4 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/fork.v b/CoqOfPython/ethereum/shanghai/fork.v index 50d8f50..be9d24a 100644 --- a/CoqOfPython/ethereum/shanghai/fork.v +++ b/CoqOfPython/ethereum/shanghai/fork.v @@ -230,7 +230,6 @@ Definition apply_fork : Value.t -> Value.t -> M := " in let _ := M.return_ (| M.get_name (| globals, "old" |) - |) in M.pure Constant.None_)). Definition get_last_256_block_hashes : Value.t -> Value.t -> M := @@ -256,25 +255,8 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := Hashes of the recent 256 blocks in order of increasing block number. " in let recent_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |) |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "recent_blocks" |) - ], - make_dict [] - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - make_list [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let recent_block_hashes := @@ -313,7 +295,6 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "recent_block_hashes" |) - |) in M.pure Constant.None_)). Definition state_transition : Value.t -> Value.t -> M := @@ -353,7 +334,10 @@ Definition state_transition : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "block" |), "ommers" |), make_tuple [ ] |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "block" |), "ommers" |), + make_tuple [ ] + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -385,7 +369,10 @@ Definition state_transition : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_gas_used" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "gas_used" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_gas_used" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "gas_used" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -393,7 +380,10 @@ Definition state_transition : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "transactions_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "transactions_root" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "transactions_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "transactions_root" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -401,7 +391,10 @@ Definition state_transition : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "state_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "state_root" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "state_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "state_root" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -409,7 +402,10 @@ Definition state_transition : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "receipt_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "receipt_root" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "receipt_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "receipt_root" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -417,7 +413,10 @@ Definition state_transition : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_logs_bloom" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "bloom" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_logs_bloom" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "bloom" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -425,7 +424,10 @@ Definition state_transition : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "withdrawals_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "withdrawals_root" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "withdrawals_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "withdrawals_root" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -438,24 +440,6 @@ Definition state_transition : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "chain" |), "blocks" |) - ], - make_dict [] - |), Constant.int 255 |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign (| - M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |):(* At expr: unsupported node type: NoneType *) |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -503,57 +487,7 @@ Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "parent_gas_used" |), M.get_name (| globals, "parent_gas_target" |) |), - (* then *) - ltac:(M.monadic ( - let expected_base_fee_per_gas := - M.get_name (| globals, "parent_base_fee_per_gas" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "parent_gas_used" |), M.get_name (| globals, "parent_gas_target" |) |), - (* then *) - ltac:(M.monadic ( - let gas_used_delta := - BinOp.sub (| - M.get_name (| globals, "parent_gas_used" |), - M.get_name (| globals, "parent_gas_target" |) - |) in - let parent_fee_gas_delta := - BinOp.mult (| - M.get_name (| globals, "parent_base_fee_per_gas" |), - M.get_name (| globals, "gas_used_delta" |) - |) in - let target_fee_gas_delta := - BinOp.floor_div (| - M.get_name (| globals, "parent_fee_gas_delta" |), - M.get_name (| globals, "parent_gas_target" |) - |) in - let base_fee_per_gas_delta := - M.call (| - M.get_name (| globals, "max" |), - make_list [ - BinOp.floor_div (| - M.get_name (| globals, "target_fee_gas_delta" |), - M.get_name (| globals, "BASE_FEE_MAX_CHANGE_DENOMINATOR" |) - |); - Constant.int 1 - ], - make_dict [] - |) in - let expected_base_fee_per_gas := - BinOp.add (| - M.get_name (| globals, "parent_base_fee_per_gas" |), - M.get_name (| globals, "base_fee_per_gas_delta" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let gas_used_delta := BinOp.sub (| M.get_name (| globals, "parent_gas_target" |), @@ -591,7 +525,6 @@ Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition validate_header : Value.t -> Value.t -> M := @@ -617,7 +550,10 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt_e (| M.get_field (| M.get_name (| globals, "header" |), "gas_used" |), M.get_field (| M.get_name (| globals, "header" |), "gas_limit" |) |); + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "header" |), "gas_used" |), + M.get_field (| M.get_name (| globals, "header" |), "gas_limit" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -636,7 +572,10 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_name (| globals, "expected_base_fee_per_gas" |), M.get_field (| M.get_name (| globals, "header" |), "base_fee_per_gas" |) |); + Compare.eq (| + M.get_name (| globals, "expected_base_fee_per_gas" |), + M.get_field (| M.get_name (| globals, "header" |), "base_fee_per_gas" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -644,7 +583,10 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.gt (| M.get_field (| M.get_name (| globals, "header" |), "timestamp" |), M.get_field (| M.get_name (| globals, "parent_header" |), "timestamp" |) |); + Compare.gt (| + M.get_field (| M.get_name (| globals, "header" |), "timestamp" |), + M.get_field (| M.get_name (| globals, "parent_header" |), "timestamp" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -652,10 +594,13 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "number" |), BinOp.add (| - M.get_field (| M.get_name (| globals, "parent_header" |), "number" |), - Constant.int 1 - |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "number" |), + BinOp.add (| + M.get_field (| M.get_name (| globals, "parent_header" |), "number" |), + Constant.int 1 + |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -663,13 +608,16 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt_e (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) - ], - make_dict [] - |), Constant.int 32 |); + Compare.lt_e (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) + ], + make_dict [] + |), + Constant.int 32 + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -677,7 +625,10 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "difficulty" |), Constant.int 0 |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "difficulty" |), + Constant.int 0 + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -685,7 +636,10 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "nonce" |), (* At constant: unsupported node type: Constant *) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "nonce" |), + Constant.bytes "0000000000000000" + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -693,7 +647,10 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "ommers_hash" |), M.get_name (| globals, "EMPTY_OMMER_HASH" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "ommers_hash" |), + M.get_name (| globals, "EMPTY_OMMER_HASH" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -715,7 +672,10 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |), M.get_name (| globals, "block_parent_hash" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |), + M.get_name (| globals, "block_parent_hash" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -754,7 +714,10 @@ Definition check_transaction : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt_e (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_name (| globals, "gas_available" |) |); + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_name (| globals, "gas_available" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -769,58 +732,13 @@ Definition check_transaction : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "FeeMarketTransaction" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.gt_e (| M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |), M.get_field (| M.get_name (| globals, "tx" |), "max_priority_fee_per_gas" |) |); - M.get_name (| globals, "InvalidBlock" |) - ], - make_dict [] - |) in - let _ := M.call (| - M.get_name (| globals, "ensure" |), - make_list [ - Compare.gt_e (| M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |), M.get_name (| globals, "base_fee_per_gas" |) |); - M.get_name (| globals, "InvalidBlock" |) - ], - make_dict [] - |) in - let priority_fee_per_gas := - M.call (| - M.get_name (| globals, "min" |), - make_list [ - M.get_field (| M.get_name (| globals, "tx" |), "max_priority_fee_per_gas" |); - BinOp.sub (| - M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |), - M.get_name (| globals, "base_fee_per_gas" |) - |) - ], - make_dict [] - |) in - let effective_gas_price := - BinOp.add (| - M.get_name (| globals, "priority_fee_per_gas" |), - M.get_name (| globals, "base_fee_per_gas" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "ensure" |), - make_list [ - Compare.gt_e (| M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |), M.get_name (| globals, "base_fee_per_gas" |) |); + Compare.gt_e (| + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |), + M.get_name (| globals, "base_fee_per_gas" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -831,7 +749,6 @@ Definition check_transaction : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| make_tuple [ M.get_name (| globals, "sender_address" |); M.get_name (| globals, "effective_gas_price" |) ] - |) in M.pure Constant.None_)). Definition make_receipt : Value.t -> Value.t -> M := @@ -864,64 +781,9 @@ Definition make_receipt : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "AccessListTransaction" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - BinOp.add (| - (* At constant: unsupported node type: Constant *), - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "receipt" |) - ], - make_dict [] - |) - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "FeeMarketTransaction" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - BinOp.add (| - (* At constant: unsupported node type: Constant *), - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "receipt" |) - ], - make_dict [] - |) - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "receipt" |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -1160,29 +1022,6 @@ Definition apply_body : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_field (| M.get_name (| globals, "wd" |), "address" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "destroy_account" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_field (| M.get_name (| globals, "wd" |), "address" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -1223,7 +1062,6 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition process_transaction : Value.t -> Value.t -> M := @@ -1281,26 +1119,6 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "FeeMarketTransaction" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let max_gas_fee := - BinOp.mult (| - M.get_field (| M.get_name (| globals, "tx" |), "gas" |), - M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let max_gas_fee := BinOp.mult (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), @@ -1311,7 +1129,10 @@ Definition process_transaction : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "sender_account" |), "nonce" |), M.get_field (| M.get_name (| globals, "tx" |), "nonce" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "sender_account" |), "nonce" |), + M.get_field (| M.get_name (| globals, "tx" |), "nonce" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1319,10 +1140,13 @@ Definition process_transaction : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.gt_e (| M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), BinOp.add (| - M.get_name (| globals, "max_gas_fee" |), - M.get_field (| M.get_name (| globals, "tx" |), "value" |) - |) |); + Compare.gt_e (| + M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), + BinOp.add (| + M.get_name (| globals, "max_gas_fee" |), + M.get_field (| M.get_name (| globals, "tx" |), "value" |) + |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1330,11 +1154,14 @@ Definition process_transaction : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "sender_account" |), "code" |), M.call (| - M.get_name (| globals, "bytearray" |), - make_list [], - make_dict [] - |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "sender_account" |), "code" |), + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [], + make_dict [] + |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1397,39 +1224,6 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - make_tuple [ M.get_name (| globals, "AccessListTransaction" |); M.get_name (| globals, "FeeMarketTransaction" |) ] - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - For make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "keys" |) ] in M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) do - let _ := M.call (| - M.get_field (| M.get_name (| globals, "preaccessed_addresses" |), "add" |), - make_list [ - M.get_name (| globals, "address" |) - ], - make_dict [] - |) in - For M.get_name (| globals, "key" |) in M.get_name (| globals, "keys" |) do - let _ := M.call (| - M.get_field (| M.get_name (| globals, "preaccessed_storage_keys" |), "add" |), - make_list [ - make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "key" |) ] - ], - make_dict [] - |) in - EndFor. - EndFor. - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let message := @@ -1534,47 +1328,7 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "transaction_fee" |) |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_eq (| M.get_name (| globals, "coinbase_balance_after_mining_fee" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "set_account_balance" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_field (| M.get_name (| globals, "env" |), "coinbase" |); - M.get_name (| globals, "coinbase_balance_after_mining_fee" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "destroy_account" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -1591,35 +1345,11 @@ Definition process_transaction : Value.t -> Value.t -> M := EndFor. For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "touched_accounts" |) do let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "destroy_account" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := M.return_ (| make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |); M.get_field (| M.get_name (| globals, "output" |), "error" |) ] - |) in M.pure Constant.None_)). Definition validate_transaction : Value.t -> Value.t -> M := @@ -1650,82 +1380,16 @@ Definition validate_transaction : Value.t -> Value.t -> M := True if the transaction can be executed, or False otherwise. " in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.call (| - M.get_name (| globals, "calculate_intrinsic_cost" |), - make_list [ - M.get_name (| globals, "tx" |) - ], - make_dict [] - |), M.get_field (| M.get_name (| globals, "tx" |), "gas" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.bool false - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_field (| M.get_name (| globals, "tx" |), "nonce" |), BinOp.sub (| - BinOp.pow (| - Constant.int 2, - Constant.int 64 - |), - Constant.int 1 - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.bool false - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "tx" |), "to" |), M.call (| - M.get_name (| globals, "Bytes0" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |) |), - ltac:(M.monadic ( - Compare.gt (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "tx" |), "data" |) - ], - make_dict [] - |), BinOp.mult (| - Constant.int 2, - M.get_name (| globals, "MAX_CODE_SIZE" |) - |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.bool false - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| Constant.bool true - |) in M.pure Constant.None_)). Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := @@ -1757,17 +1421,6 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := Constant.int 0 in For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "byte" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let data_cost := BinOp.add - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let data_cost := BinOp.add M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in @@ -1775,49 +1428,6 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := )) |) in EndFor. let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_name (| globals, "tx" |), "to" |), M.call (| - M.get_name (| globals, "Bytes0" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let create_cost := - BinOp.add (| - M.get_name (| globals, "TX_CREATE_COST" |), - M.call (| - M.get_name (| globals, "int" |), - make_list [ - M.call (| - M.get_name (| globals, "init_code_cost" |), - make_list [ - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "tx" |), "data" |) - ], - make_dict [] - |) - ], - make_dict [] - |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let create_cost := Constant.int 0 in M.pure Constant.None_ @@ -1825,47 +1435,6 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := let access_list_cost := Constant.int 0 in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - make_tuple [ M.get_name (| globals, "AccessListTransaction" |); M.get_name (| globals, "FeeMarketTransaction" |) ] - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - For make_tuple [ M.get_name (| globals, "_address" |); M.get_name (| globals, "keys" |) ] in M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) do - let access_list_cost := BinOp.add - M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) - M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) in - let access_list_cost := BinOp.add - BinOp.mult (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "keys" |) - ], - make_dict [] - |), - M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) - |) - BinOp.mult (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "keys" |) - ], - make_dict [] - |), - M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) - |) in - EndFor. - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1885,7 +1454,6 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition recover_sender : Value.t -> Value.t -> M := @@ -1920,9 +1488,15 @@ Definition recover_sender : Value.t -> Value.t -> M := M.get_name (| globals, "ensure" |), make_list [ BoolOp.and (| - Compare.lt (| Constant.int 0, M.get_name (| globals, "r" |) |), + Compare.lt (| + Constant.int 0, + M.get_name (| globals, "r" |) + |), ltac:(M.monadic ( - Compare.lt (| M.get_name (| globals, "r" |), M.get_name (| globals, "SECP256K1N" |) |) + Compare.lt (| + M.get_name (| globals, "r" |), + M.get_name (| globals, "SECP256K1N" |) + |) )) |); M.get_name (| globals, "InvalidBlock" |) @@ -1933,190 +1507,27 @@ Definition recover_sender : Value.t -> Value.t -> M := M.get_name (| globals, "ensure" |), make_list [ BoolOp.and (| - Compare.lt (| Constant.int 0, M.get_name (| globals, "s" |) |), + Compare.lt (| + Constant.int 0, + M.get_name (| globals, "s" |) + |), ltac:(M.monadic ( - Compare.lt_e (| M.get_name (| globals, "s" |), BinOp.floor_div (| + Compare.lt_e (| + M.get_name (| globals, "s" |), + BinOp.floor_div (| M.get_name (| globals, "SECP256K1N" |), Constant.int 2 - |) |) - )) - |); - M.get_name (| globals, "InvalidBlock" |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "LegacyTransaction" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let v := - M.get_field (| M.get_name (| globals, "tx" |), "v" |) in - let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.eq (| M.get_name (| globals, "v" |), Constant.int 27 |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "v" |), Constant.int 28 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let public_key := - M.call (| - M.get_name (| globals, "secp256k1_recover" |), - make_list [ - M.get_name (| globals, "r" |); - M.get_name (| globals, "s" |); - BinOp.sub (| - M.get_name (| globals, "v" |), - Constant.int 27 - |); - M.call (| - M.get_name (| globals, "signing_hash_pre155" |), - make_list [ - M.get_name (| globals, "tx" |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "ensure" |), - make_list [ - BoolOp.or (| - Compare.eq (| M.get_name (| globals, "v" |), BinOp.add (| - Constant.int 35, - BinOp.mult (| - M.get_name (| globals, "chain_id" |), - Constant.int 2 + |) |) - |) |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "v" |), BinOp.add (| - Constant.int 36, - BinOp.mult (| - M.get_name (| globals, "chain_id" |), - Constant.int 2 - |) - |) |) )) |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] |) in - let public_key := - M.call (| - M.get_name (| globals, "secp256k1_recover" |), - make_list [ - M.get_name (| globals, "r" |); - M.get_name (| globals, "s" |); - BinOp.sub (| - BinOp.sub (| - M.get_name (| globals, "v" |), - Constant.int 35 - |), - BinOp.mult (| - M.get_name (| globals, "chain_id" |), - Constant.int 2 - |) - |); - M.call (| - M.get_name (| globals, "signing_hash_155" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "chain_id" |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + let _ := let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "AccessListTransaction" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let public_key := - M.call (| - M.get_name (| globals, "secp256k1_recover" |), - make_list [ - M.get_name (| globals, "r" |); - M.get_name (| globals, "s" |); - M.get_field (| M.get_name (| globals, "tx" |), "y_parity" |); - M.call (| - M.get_name (| globals, "signing_hash_2930" |), - make_list [ - M.get_name (| globals, "tx" |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "FeeMarketTransaction" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let public_key := - M.call (| - M.get_name (| globals, "secp256k1_recover" |), - make_list [ - M.get_name (| globals, "r" |); - M.get_name (| globals, "s" |); - M.get_field (| M.get_name (| globals, "tx" |), "y_parity" |); - M.call (| - M.get_name (| globals, "signing_hash_1559" |), - make_list [ - M.get_name (| globals, "tx" |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -2133,11 +1544,10 @@ Definition recover_sender : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12:Constant.int 32 |) + |), Constant.int 12 |) ], make_dict [] |) - |) in M.pure Constant.None_)). Definition signing_hash_pre155 : Value.t -> Value.t -> M := @@ -2170,7 +1580,6 @@ Definition signing_hash_pre155 : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition signing_hash_155 : Value.t -> Value.t -> M := @@ -2217,7 +1626,6 @@ Definition signing_hash_155 : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition signing_hash_2930 : Value.t -> Value.t -> M := @@ -2241,7 +1649,7 @@ Definition signing_hash_2930 : Value.t -> Value.t -> M := M.get_name (| globals, "keccak256" |), make_list [ BinOp.add (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "01", M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), make_list [ @@ -2253,7 +1661,6 @@ Definition signing_hash_2930 : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition signing_hash_1559 : Value.t -> Value.t -> M := @@ -2277,7 +1684,7 @@ Definition signing_hash_1559 : Value.t -> Value.t -> M := M.get_name (| globals, "keccak256" |), make_list [ BinOp.add (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "02", M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), make_list [ @@ -2289,7 +1696,6 @@ Definition signing_hash_1559 : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition compute_header_hash : Value.t -> Value.t -> M := @@ -2340,7 +1746,6 @@ Definition compute_header_hash : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition check_gas_limit : Value.t -> Value.t -> M := @@ -2379,54 +1784,14 @@ Definition check_gas_limit : Value.t -> Value.t -> M := M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "gas_limit" |), BinOp.add (| - M.get_name (| globals, "parent_gas_limit" |), - M.get_name (| globals, "max_adjustment_delta" |) - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.bool false - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt_e (| M.get_name (| globals, "gas_limit" |), BinOp.sub (| - M.get_name (| globals, "parent_gas_limit" |), - M.get_name (| globals, "max_adjustment_delta" |) - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.bool false - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "gas_limit" |), M.get_name (| globals, "GAS_LIMIT_MINIMUM" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.bool false - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| Constant.bool true - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/fork_types.v b/CoqOfPython/ethereum/shanghai/fork_types.v index d12953d..5c7dac3 100644 --- a/CoqOfPython/ethereum/shanghai/fork_types.v +++ b/CoqOfPython/ethereum/shanghai/fork_types.v @@ -98,5 +98,4 @@ Definition encode_account : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/state.v b/CoqOfPython/ethereum/shanghai/state.v index a950e08..dfaae0d 100644 --- a/CoqOfPython/ethereum/shanghai/state.v +++ b/CoqOfPython/ethereum/shanghai/state.v @@ -130,13 +130,7 @@ Definition begin_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) ], make_dict [] - |); {M.get_name (| globals, "k" |): M.call (| - M.get_name (| globals, "copy_trie" |), - make_list [ - M.get_name (| globals, "t" |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)} ] + |); (* At expr: unsupported node type: DictComp *) ] ], make_dict [] |) in @@ -159,19 +153,6 @@ Definition commit_transaction : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "clear" |), - make_list [], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -197,19 +178,6 @@ Definition rollback_transaction : Value.t -> Value.t -> M := |) |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "clear" |), - make_list [], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -246,27 +214,8 @@ Definition get_account : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "account" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "account" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_ACCOUNT" |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -301,7 +250,6 @@ Definition get_account_optional : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "account" |) - |) in M.pure Constant.None_)). Definition set_account : Value.t -> Value.t -> M := @@ -381,15 +329,6 @@ Definition destroy_storage : Value.t -> Value.t -> M := Address of account whose storage is to be deleted. " in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -452,23 +391,6 @@ Definition get_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let value := @@ -490,7 +412,6 @@ Definition get_storage : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "value" |) - |) in M.pure Constant.None_)). Definition set_storage : Value.t -> Value.t -> M := @@ -511,14 +432,17 @@ Definition set_storage : Value.t -> Value.t -> M := value : `U256` Value to set at the key. " in - let _ := M.assert (| Compare.is_not (| M.call (| - M.get_name (| globals, "trie_get" |), - make_list [ - M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), Constant.None_ |) |) in + let _ := M.assert (| Compare.is_not (| + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + Constant.None_ + |) |) in let trie := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), @@ -528,24 +452,6 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let trie := - M.call (| - M.get_name (| globals, "Trie" |), - make_list [], - make_dict [] - |) in - let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), - M.get_name (| globals, "trie" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -558,15 +464,6 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), {} |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -591,26 +488,8 @@ Definition storage_root : Value.t -> Value.t -> M := " in let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "root" |), - make_list [ - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_TRIE_ROOT" |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -641,7 +520,6 @@ Definition state_root : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition account_exists : Value.t -> Value.t -> M := @@ -663,15 +541,17 @@ Definition account_exists : Value.t -> Value.t -> M := True if account exists in the state trie, False otherwise " in let _ := M.return_ (| - Compare.is_not (| M.call (| - M.get_name (| globals, "get_account_optional" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), Constant.None_ |) - |) in + Compare.is_not (| + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + Constant.None_ + |) M.pure Constant.None_)). Definition account_has_code_or_nonce : Value.t -> Value.t -> M := @@ -704,18 +584,23 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := |) in let _ := M.return_ (| BoolOp.or (| - Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( - Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |) + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |) )) |) - |) in M.pure Constant.None_)). Definition is_account_empty : Value.t -> Value.t -> M := @@ -748,23 +633,31 @@ Definition is_account_empty : Value.t -> Value.t -> M := |) in let _ := M.return_ (| BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |), ltac:(M.monadic ( - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "balance" |), + Constant.int 0 + |) )) |) )) |) - |) in M.pure Constant.None_)). Definition account_exists_and_is_empty : Value.t -> Value.t -> M := @@ -798,28 +691,39 @@ Definition account_exists_and_is_empty : Value.t -> Value.t -> M := |) in let _ := M.return_ (| BoolOp.and (| - Compare.is_not (| M.get_name (| globals, "account" |), Constant.None_ |), + Compare.is_not (| + M.get_name (| globals, "account" |), + Constant.None_ + |), ltac:(M.monadic ( BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |), ltac:(M.monadic ( - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "balance" |), + Constant.int 0 + |) )) |) )) |) )) |) - |) in M.pure Constant.None_)). Definition is_account_alive : Value.t -> Value.t -> M := @@ -850,36 +754,33 @@ Definition is_account_alive : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "account" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.bool false - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| UnOp.not (| BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |), ltac:(M.monadic ( - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "balance" |), + Constant.int 0 + |) )) |) )) |) |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -1005,30 +906,6 @@ Definition touch_account : Value.t -> Value.t -> M := The address of the account that need to initialised. " in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "account_exists" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "set_account" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |); - M.get_name (| globals, "EMPTY_ACCOUNT" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -1106,23 +983,6 @@ Definition get_storage_original : Value.t -> Value.t -> M := Key of the storage slot. " in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -1138,22 +998,6 @@ Definition get_storage_original : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "original_account_trie" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let original_value := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let original_value := M.call (| M.get_name (| globals, "trie_get" |), @@ -1175,5 +1019,4 @@ Definition get_storage_original : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "original_value" |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/transactions.v b/CoqOfPython/ethereum/shanghai/transactions.v index 56996d9..afa27ec 100644 --- a/CoqOfPython/ethereum/shanghai/transactions.v +++ b/CoqOfPython/ethereum/shanghai/transactions.v @@ -112,87 +112,15 @@ Definition encode_transaction : Value.t -> Value.t -> M := Encode a transaction. Needed because non-legacy transactions aren't RLP. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "LegacyTransaction" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "tx" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "AccessListTransaction" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - BinOp.add (| - (* At constant: unsupported node type: Constant *), - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "tx" |) - ], - make_dict [] - |) - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "FeeMarketTransaction" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - BinOp.add (| - (* At constant: unsupported node type: Constant *), - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "tx" |) - ], - make_dict [] - |) - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.call (| + let _ := M.raise (| Some(M.call (| M.get_name (| globals, "Exception" |), make_list [ (* At expr: unsupported node type: JoinedStr *) ], make_dict [] - |) |) in + |)) M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -208,67 +136,8 @@ Definition decode_transaction : Value.t -> Value.t -> M := Decode a transaction. Needed because non-legacy transactions aren't RLP. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "Bytes" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), Constant.int 1 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), - make_list [ - M.get_name (| globals, "AccessListTransaction" |); - M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 1:(* At expr: unsupported node type: NoneType *) |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), Constant.int 2 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), - make_list [ - M.get_name (| globals, "FeeMarketTransaction" |); - M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 1:(* At expr: unsupported node type: NoneType *) |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidBlock" |) |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "tx" |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/trie.v b/CoqOfPython/ethereum/shanghai/trie.v index fcb4569..3dafa10 100644 --- a/CoqOfPython/ethereum/shanghai/trie.v +++ b/CoqOfPython/ethereum/shanghai/trie.v @@ -205,96 +205,16 @@ Definition encode_internal_node : Value.t -> Value.t -> M := " in (* At stmt: unsupported node type: AnnAssign *) let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "node" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let unencoded := - (* At constant: unsupported node type: Constant *) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "LeafNode" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let unencoded := - make_tuple [ M.call (| - M.get_name (| globals, "nibble_list_to_compact" |), - make_list [ - M.get_field (| M.get_name (| globals, "node" |), "rest_of_key" |); - Constant.bool true - ], - make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "ExtensionNode" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let unencoded := - make_tuple [ M.call (| - M.get_name (| globals, "nibble_list_to_compact" |), - make_list [ - M.get_field (| M.get_name (| globals, "node" |), "key_segment" |); - Constant.bool false - ], - make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "BranchNode" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let unencoded := - BinOp.add (| - M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), - make_list [ - M.get_field (| M.get_name (| globals, "node" |), "value" |) - ] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.call (| + let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ (* At expr: unsupported node type: JoinedStr *) ], make_dict [] - |) |) in + |)) M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -312,23 +232,6 @@ Definition encode_internal_node : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "encoded" |) - ], - make_dict [] - |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "unencoded" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_name (| globals, "keccak256" |), @@ -337,7 +240,6 @@ Definition encode_internal_node : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -351,83 +253,8 @@ Definition encode_node : Value.t -> Value.t -> M := Currently mostly an unimplemented stub. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "storage_root" |), Constant.None_ |) |) in - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "encode_account" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "storage_root" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Withdrawal" |); M.get_name (| globals, "U256" |) ] - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.call (| - M.get_name (| globals, "cast" |), - make_list [ - M.get_field (| M.get_name (| globals, "rlp" |), "RLP" |); - M.get_name (| globals, "node" |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "Bytes" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "node" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "previous_trie" |), "encode_node" |), @@ -437,7 +264,6 @@ Definition encode_node : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -489,7 +315,6 @@ Definition copy_trie : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition trie_set : Value.t -> Value.t -> M := @@ -511,26 +336,6 @@ Definition trie_set : Value.t -> Value.t -> M := Node to insert at `key`. " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "value" |), M.get_field (| M.get_name (| globals, "trie" |), "default" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "key" |), M.get_field (| M.get_name (| globals, "trie" |), "_data" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), M.get_name (| globals, "value" |) @@ -568,7 +373,6 @@ Definition trie_get : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition common_prefix_length : Value.t -> Value.t -> M := @@ -591,28 +395,6 @@ Definition common_prefix_length : Value.t -> Value.t -> M := make_dict [] |) do let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| M.get_name (| globals, "i" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "b" |) - ], - make_dict [] - |) |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "i" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -624,7 +406,6 @@ Definition common_prefix_length : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition nibble_list_to_compact : Value.t -> Value.t -> M := @@ -670,68 +451,6 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| BinOp.mod_ (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |), - Constant.int 2 - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_name (| globals, "compact" |), "append" |), - make_list [ - BinOp.mult (| - Constant.int 16, - BinOp.mult (| - Constant.int 2, - M.get_name (| globals, "is_leaf" |) - |) - |) - ], - make_dict [] - |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 0; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |); - Constant.int 2 - ], - make_dict [] - |) do - let _ := M.call (| - M.get_field (| M.get_name (| globals, "compact" |), "append" |), - make_list [ - BinOp.add (| - BinOp.mult (| - Constant.int 16, - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) - |), - M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) - |) - ], - make_dict [] - |) in - EndFor. - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ @@ -793,7 +512,6 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition bytes_to_nibble_list : Value.t -> Value.t -> M := @@ -871,7 +589,6 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition _prepare_trie : Value.t -> Value.t -> M := @@ -901,45 +618,6 @@ Definition _prepare_trie : Value.t -> Value.t -> M := make_dict [] |) do let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "value" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in - let address := - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in - let encoded_value := - M.call (| - M.get_name (| globals, "encode_node" |), - make_list [ - M.get_name (| globals, "value" |); - M.call (| - M.get_name (| globals, "get_storage_root" |), - make_list [ - M.get_name (| globals, "address" |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let encoded_value := M.call (| M.get_name (| globals, "encode_node" |), @@ -953,29 +631,16 @@ Definition _prepare_trie : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.not_eq (| M.get_name (| globals, "encoded_value" |), (* At constant: unsupported node type: Constant *) |); + Compare.not_eq (| + M.get_name (| globals, "encoded_value" |), + Constant.bytes "" + |); M.get_name (| globals, "AssertionError" |) ], make_dict [] |) in (* At stmt: unsupported node type: AnnAssign *) let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "trie" |), "secured" |), - (* then *) - ltac:(M.monadic ( - let key := - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let key := M.get_name (| globals, "preimage" |) in M.pure Constant.None_ @@ -993,7 +658,6 @@ Definition _prepare_trie : Value.t -> Value.t -> M := EndFor. let _ := M.return_ (| M.get_name (| globals, "mapped" |) - |) in M.pure Constant.None_)). Definition root : Value.t -> Value.t -> M := @@ -1047,41 +711,6 @@ Definition root : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "root_node" |) - ], - make_dict [] - |) - ], - make_dict [] - |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "root_node" |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -1098,7 +727,6 @@ Definition root : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -1125,23 +753,6 @@ Definition patricialize : Value.t -> Value.t -> M := Root node of `obj`. " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "obj" |) - ], - make_dict [] - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.None_ - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let arbitrary_key := @@ -1159,36 +770,10 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "obj" |) - ], - make_dict [] - |), Constant.int 1 |), - (* then *) - ltac:(M.monadic ( - let leaf := - M.call (| - M.get_name (| globals, "LeafNode" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |); - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) - ], - make_dict [] - |) in - let _ := M.return_ (| - M.get_name (| globals, "leaf" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let substring := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |) |) in let prefix_length := M.call (| M.get_name (| globals, "len" |), @@ -1207,7 +792,7 @@ Definition patricialize : Value.t -> Value.t -> M := M.get_name (| globals, "common_prefix_length" |), make_list [ M.get_name (| globals, "substring" |); - M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) + M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) ], make_dict [] |) @@ -1215,58 +800,10 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.break (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let prefix := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):BinOp.add (| - M.get_name (| globals, "level" |), - M.get_name (| globals, "prefix_length" |) - |) |) in - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "ExtensionNode" |), - make_list [ - M.get_name (| globals, "prefix" |); - M.call (| - M.get_name (| globals, "encode_internal_node" |), - make_list [ - M.call (| - M.get_name (| globals, "patricialize" |), - make_list [ - M.get_name (| globals, "obj" |); - BinOp.add (| - M.get_name (| globals, "level" |), - M.get_name (| globals, "prefix_length" |) - |) - ], - make_dict [] - |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) @@ -1286,44 +823,9 @@ Definition patricialize : Value.t -> Value.t -> M := |) in EndFor. let value := - (* At constant: unsupported node type: Constant *) in + Constant.bytes "" in For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "key" |) - ], - make_dict [] - |), M.get_name (| globals, "level" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); - make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "AssertionError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let value := - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) @@ -1335,26 +837,9 @@ Definition patricialize : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "BranchNode" |), make_list [ - [M.call (| - M.get_name (| globals, "encode_internal_node" |), - make_list [ - M.call (| - M.get_name (| globals, "patricialize" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "branches" |), M.get_name (| globals, "k" |) |); - BinOp.add (| - M.get_name (| globals, "level" |), - Constant.int 1 - |) - ], - make_dict [] - |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)]; + (* At expr: unsupported node type: ListComp *); M.get_name (| globals, "value" |) ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/utils/address.v b/CoqOfPython/ethereum/shanghai/utils/address.v index e2cf508..ec03628 100644 --- a/CoqOfPython/ethereum/shanghai/utils/address.v +++ b/CoqOfPython/ethereum/shanghai/utils/address.v @@ -70,11 +70,10 @@ Definition to_address : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), make_list [], make_dict [] - |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) + |), UnOp.sub (| Constant.int 20 |) |) ], make_dict [] |) - |) in M.pure Constant.None_)). Definition compute_contract_address : Value.t -> Value.t -> M := @@ -114,7 +113,7 @@ Definition compute_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -132,7 +131,6 @@ Definition compute_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition compute_create2_contract_address : Value.t -> Value.t -> M := @@ -160,7 +158,7 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := BinOp.add (| BinOp.add (| BinOp.add (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "ff", M.get_name (| globals, "address" |) |), M.get_name (| globals, "salt" |) @@ -182,7 +180,7 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -200,5 +198,4 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/utils/hexadecimal.v b/CoqOfPython/ethereum/shanghai/utils/hexadecimal.v index a77e4e4..3f0eed6 100644 --- a/CoqOfPython/ethereum/shanghai/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/shanghai/utils/hexadecimal.v @@ -66,7 +66,6 @@ Definition hex_to_root : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition hex_to_bloom : Value.t -> Value.t -> M := @@ -105,7 +104,6 @@ Definition hex_to_bloom : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition hex_to_address : Value.t -> Value.t -> M := @@ -151,5 +149,4 @@ Definition hex_to_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/utils/message.v b/CoqOfPython/ethereum/shanghai/utils/message.v index a58178e..635f015 100644 --- a/CoqOfPython/ethereum/shanghai/utils/message.v +++ b/CoqOfPython/ethereum/shanghai/utils/message.v @@ -103,105 +103,14 @@ Definition prepare_message : Value.t -> Value.t -> M := Items containing contract creation or message call specific data. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "target" |); - M.get_name (| globals, "Bytes0" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let current_target := - M.call (| - M.get_name (| globals, "compute_contract_address" |), - make_list [ - M.get_name (| globals, "caller" |); - BinOp.sub (| - M.get_field (| M.call (| - M.get_name (| globals, "get_account" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "caller" |) - ], - make_dict [] - |), "nonce" |), - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 1 - ], - make_dict [] - |) - |) - ], - make_dict [] - |) in - let msg_data := - M.call (| - M.get_name (| globals, "Bytes" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |) in - let code := - M.get_name (| globals, "data" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "target" |); - M.get_name (| globals, "Address" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let current_target := - M.get_name (| globals, "target" |) in - let msg_data := - M.get_name (| globals, "data" |) in - let code := - M.get_field (| M.call (| - M.get_name (| globals, "get_account" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "target" |) - ], - make_dict [] - |), "code" |) in - let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "code_address" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let code_address := - M.get_name (| globals, "target" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.call (| + let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "Target must be address or empty bytes" ], make_dict [] - |) |) in + |)) M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -250,5 +159,4 @@ Definition prepare_message : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/vm/__init__.v b/CoqOfPython/ethereum/shanghai/vm/__init__.v index 2ff63cd..49da5ae 100644 --- a/CoqOfPython/ethereum/shanghai/vm/__init__.v +++ b/CoqOfPython/ethereum/shanghai/vm/__init__.v @@ -147,28 +147,6 @@ Definition incorporate_child_on_success : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); - M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -201,57 +179,9 @@ Definition incorporate_child_on_error : Value.t -> Value.t -> M := The child evm to incorporate. " in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "RIPEMD160_ADDRESS" |), M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), - make_list [ - M.get_name (| globals, "RIPEMD160_ADDRESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |), M.get_name (| globals, "RIPEMD160_ADDRESS" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); - M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), - make_list [ - M.get_name (| globals, "RIPEMD160_ADDRESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign_op (| diff --git a/CoqOfPython/ethereum/shanghai/vm/gas.v b/CoqOfPython/ethereum/shanghai/vm/gas.v new file mode 100644 index 0000000..b18e24c --- /dev/null +++ b/CoqOfPython/ethereum/shanghai/vm/gas.v @@ -0,0 +1,849 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Gas +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +EVM gas constants and calculators. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.trace. +Axiom ethereum_trace_GasAndRefund : + IsGlobalAlias globals ethereum.trace.globals "GasAndRefund". +Axiom ethereum_trace_evm_trace : + IsGlobalAlias globals ethereum.trace.globals "evm_trace". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". + +Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) +)). + +Definition GAS_BASE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 2 + ], + make_dict [] + |) +)). + +Definition GAS_VERY_LOW : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_STORAGE_SET : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 20000 + ], + make_dict [] + |) +)). + +Definition GAS_STORAGE_UPDATE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5000 + ], + make_dict [] + |) +)). + +Definition GAS_STORAGE_CLEAR_REFUND : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 4800 + ], + make_dict [] + |) +)). + +Definition GAS_LOW : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5 + ], + make_dict [] + |) +)). + +Definition GAS_MID : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 8 + ], + make_dict [] + |) +)). + +Definition GAS_HIGH : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 10 + ], + make_dict [] + |) +)). + +Definition GAS_EXPONENTIATION : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 10 + ], + make_dict [] + |) +)). + +Definition GAS_EXPONENTIATION_PER_BYTE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 50 + ], + make_dict [] + |) +)). + +Definition GAS_MEMORY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_KECCAK256 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 30 + ], + make_dict [] + |) +)). + +Definition GAS_KECCAK256_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 6 + ], + make_dict [] + |) +)). + +Definition GAS_COPY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_BLOCK_HASH : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 20 + ], + make_dict [] + |) +)). + +Definition GAS_LOG : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 375 + ], + make_dict [] + |) +)). + +Definition GAS_LOG_DATA : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 8 + ], + make_dict [] + |) +)). + +Definition GAS_LOG_TOPIC : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 375 + ], + make_dict [] + |) +)). + +Definition GAS_CREATE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 32000 + ], + make_dict [] + |) +)). + +Definition GAS_CODE_DEPOSIT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 200 + ], + make_dict [] + |) +)). + +Definition GAS_ZERO : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) +)). + +Definition GAS_NEW_ACCOUNT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 25000 + ], + make_dict [] + |) +)). + +Definition GAS_CALL_VALUE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 9000 + ], + make_dict [] + |) +)). + +Definition GAS_CALL_STIPEND : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 2300 + ], + make_dict [] + |) +)). + +Definition GAS_SELF_DESTRUCT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5000 + ], + make_dict [] + |) +)). + +Definition GAS_SELF_DESTRUCT_NEW_ACCOUNT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 25000 + ], + make_dict [] + |) +)). + +Definition GAS_ECRECOVER : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3000 + ], + make_dict [] + |) +)). + +Definition GAS_SHA256 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 60 + ], + make_dict [] + |) +)). + +Definition GAS_SHA256_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 12 + ], + make_dict [] + |) +)). + +Definition GAS_RIPEMD160 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 600 + ], + make_dict [] + |) +)). + +Definition GAS_RIPEMD160_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 120 + ], + make_dict [] + |) +)). + +Definition GAS_IDENTITY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 15 + ], + make_dict [] + |) +)). + +Definition GAS_IDENTITY_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_RETURN_DATA_COPY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_FAST_STEP : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5 + ], + make_dict [] + |) +)). + +Definition GAS_BLAKE2_PER_ROUND : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) +)). + +Definition GAS_COLD_SLOAD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 2100 + ], + make_dict [] + |) +)). + +Definition GAS_COLD_ACCOUNT_ACCESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 2600 + ], + make_dict [] + |) +)). + +Definition GAS_WARM_ACCESS : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 100 + ], + make_dict [] + |) +)). + +Definition GAS_INIT_CODE_WORD_COST : Value.t := M.run ltac:(M.monadic ( + Constant.int 2 +)). + +Definition ExtendMemory : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition MessageCallGas : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition charge_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "amount" ] |) in + let _ := Constant.str " + Subtracts `amount` from `evm.gas_left`. + + Parameters + ---------- + evm : + The current EVM. + amount : + The amount of gas the current operation requires. + + " in + let _ := M.call (| + M.get_name (| globals, "evm_trace" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "GasAndRefund" |), + make_list [ + M.get_name (| globals, "amount" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + let _ := M.assign_op (| + BinOp.sub, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "amount" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition calculate_memory_gas_cost : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "size_in_bytes" ] |) in + let _ := Constant.str " + Calculates the gas cost for allocating memory + to the smallest multiple of 32 bytes, + such that the allocated size is at least as big as the given size. + + Parameters + ---------- + size_in_bytes : + The size of the data in bytes. + + Returns + ------- + total_gas_cost : `ethereum.base_types.Uint` + The gas cost for storing data in memory. + " in + let size_in_words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "size_in_bytes" |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let linear_cost := + BinOp.mult (| + M.get_name (| globals, "size_in_words" |), + M.get_name (| globals, "GAS_MEMORY" |) + |) in + let quadratic_cost := + BinOp.floor_div (| + BinOp.pow (| + M.get_name (| globals, "size_in_words" |), + Constant.int 2 + |), + Constant.int 512 + |) in + let total_gas_cost := + BinOp.add (| + M.get_name (| globals, "linear_cost" |), + M.get_name (| globals, "quadratic_cost" |) + |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_)). + +Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "memory"; "extensions" ] |) in + let _ := Constant.str " + Calculates the gas amount to extend memory + + Parameters + ---------- + memory : + Memory contents of the EVM. + extensions: + List of extensions to be made to the memory. + Consists of a tuple of start position and size. + + Returns + ------- + extend_memory: `ExtendMemory` + " in + let size_to_extend := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let to_be_paid := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let current_size := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "memory" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + For make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ] in M.get_name (| globals, "extensions" |) do + let _ := + M.pure Constant.None_ + )) |) in + let before_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "current_size" |) + ], + make_dict [] + |) in + let after_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let size_to_extend := BinOp.add + BinOp.sub (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |) + BinOp.sub (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |) in + let already_paid := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "before_size" |) + ], + make_dict [] + |) in + let total_cost := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "after_size" |) + ], + make_dict [] + |) in + let to_be_paid := BinOp.add + BinOp.sub (| + M.get_name (| globals, "total_cost" |), + M.get_name (| globals, "already_paid" |) + |) + BinOp.sub (| + M.get_name (| globals, "total_cost" |), + M.get_name (| globals, "already_paid" |) + |) in + let current_size := + M.get_name (| globals, "after_size" |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ExtendMemory" |), + make_list [ + M.get_name (| globals, "to_be_paid" |); + M.get_name (| globals, "size_to_extend" |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition calculate_message_call_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "value"; "gas"; "gas_left"; "memory_cost"; "extra_gas"; "call_stipend" ] |) in + let _ := Constant.str " + Calculates the MessageCallGas (cost and stipend) for + executing call Opcodes. + + Parameters + ---------- + value: + The amount of `ETH` that needs to be transferred. + gas : + The amount of gas provided to the message-call. + gas_left : + The amount of gas left in the current frame. + memory_cost : + The amount needed to extend the memory in the current frame. + extra_gas : + The amount of gas needed for transferring value + creating a new + account inside a message call. + call_stipend : + The amount of stipend provided to a message call to execute code while + transferring value(ETH). + + Returns + ------- + message_call_gas: `MessageCallGas` + " in + let call_stipend := + (* if *) +M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let gas := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "max_message_call_gas" |), + make_list [ + BinOp.sub (| + BinOp.sub (| + M.get_name (| globals, "gas_left" |), + M.get_name (| globals, "memory_cost" |) + |), + M.get_name (| globals, "extra_gas" |) + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallGas" |), + make_list [ + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "extra_gas" |) + |); + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "call_stipend" |) + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition max_message_call_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "gas" ] |) in + let _ := Constant.str " + Calculates the maximum gas that is allowed for making a message call + + Parameters + ---------- + gas : + The amount of gas provided to the message-call. + + Returns + ------- + max_allowed_message_call_gas: `ethereum.base_types.Uint` + The maximum gas allowed for making the message-call. + " in + let _ := M.return_ (| + BinOp.sub (| + M.get_name (| globals, "gas" |), + BinOp.floor_div (| + M.get_name (| globals, "gas" |), + Constant.int 64 + |) + |) + M.pure Constant.None_)). + +Definition init_code_cost : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "init_code_length" ] |) in + let _ := Constant.str " + Calculates the gas to be charged for the init code in CREAT* + opcodes as well as create transactions. + + Parameters + ---------- + init_code_length : + The length of the init code provided to the opcode + or a create transaction + + Returns + ------- + init_code_gas: `ethereum.base_types.Uint` + The gas to be charged for the init code. + " in + let _ := M.return_ (| + BinOp.floor_div (| + BinOp.mult (| + M.get_name (| globals, "GAS_INIT_CODE_WORD_COST" |), + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "init_code_length" |) + ], + make_dict [] + |) + |), + Constant.int 32 + |) + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/shanghai/vm/instructions/arithmetic.v index a8b5c61..581ba5d 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/arithmetic.v @@ -273,22 +273,6 @@ Definition div : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let quotient := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let quotient := BinOp.floor_div (| M.get_name (| globals, "dividend" |), @@ -357,32 +341,7 @@ Definition sdiv : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let quotient := - Constant.int 0 in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_name (| globals, "dividend" |), UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "divisor" |), UnOp.sub (| Constant.int 1 |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let quotient := - UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let sign := M.call (| M.get_name (| globals, "get_sign" |), @@ -477,22 +436,6 @@ Definition mod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let remainder := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let remainder := BinOp.mod_ (| M.get_name (| globals, "x" |), @@ -561,16 +504,6 @@ Definition smod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let remainder := - Constant.int 0 in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let remainder := BinOp.mult (| M.call (| @@ -684,22 +617,6 @@ Definition addmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -795,22 +712,6 @@ Definition mulmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -980,16 +881,6 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "byte_num" |), Constant.int 31 |), - (* then *) - ltac:(M.monadic ( - let result := - M.get_name (| globals, "value" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let value_bytes := M.call (| M.get_name (| globals, "bytes" |), @@ -1012,29 +903,13 @@ Definition signextend : Value.t -> Value.t -> M := ], make_dict [] |) - |):(* At expr: unsupported node type: NoneType *) |) in + |) |) in let sign_bit := BinOp.r_shift (| M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), Constant.int 7 |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "sign_bit" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), - make_list [ - M.get_name (| globals, "value_bytes" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let num_bytes_prepend := BinOp.sub (| Constant.int 32, diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/bitwise.v b/CoqOfPython/ethereum/shanghai/vm/instructions/bitwise.v index 9f2f382..64cf120 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/bitwise.v @@ -287,22 +287,6 @@ Definition get_byte : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "byte_index" |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let extra_bytes_to_right := BinOp.sub (| Constant.int 31, @@ -382,28 +366,6 @@ Definition bitwise_shl : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - BinOp.mod_ (| - BinOp.l_shift (| - M.get_name (| globals, "value" |), - M.get_name (| globals, "shift" |) - |), - M.get_name (| globals, "U256_CEIL_VALUE" |) - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -465,19 +427,6 @@ Definition bitwise_shr : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), - (* then *) - ltac:(M.monadic ( - let result := - BinOp.r_shift (| - M.get_name (| globals, "value" |), - M.get_name (| globals, "shift" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -543,42 +492,7 @@ Definition bitwise_sar : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "shift" |), Constant.int 256 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), - make_list [ - BinOp.r_shift (| - M.get_name (| globals, "signed_value" |), - M.get_name (| globals, "shift" |) - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "signed_value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/block.v b/CoqOfPython/ethereum/shanghai/vm/instructions/block.v index 35d4735..4fa1205 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/block.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/block.v @@ -75,24 +75,6 @@ Definition block_hash : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.lt_e (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), M.get_name (| globals, "block_number" |) |), - ltac:(M.monadic ( - Compare.gt (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), BinOp.add (| - M.get_name (| globals, "block_number" |), - Constant.int 256 - |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let hash := - (* At constant: unsupported node type: Constant *) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let hash := M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/comparison.v b/CoqOfPython/ethereum/shanghai/vm/instructions/comparison.v index fbc35f8..b8529d8 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/comparison.v @@ -78,7 +78,10 @@ Definition less_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.lt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -145,7 +148,10 @@ Definition signed_less_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.lt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -205,7 +211,10 @@ Definition greater_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.gt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -272,7 +281,10 @@ Definition signed_greater_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.gt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -332,7 +344,10 @@ Definition equal : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.eq (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.eq (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -384,7 +399,10 @@ Definition is_zero : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.eq (| M.get_name (| globals, "x" |), Constant.int 0 |) + Compare.eq (| + M.get_name (| globals, "x" |), + Constant.int 0 + |) ], make_dict [] |) in diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/control_flow.v b/CoqOfPython/ethereum/shanghai/vm/instructions/control_flow.v index 04a79d9..d4e4eae 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/control_flow.v @@ -109,15 +109,6 @@ Definition jump : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -177,29 +168,7 @@ Definition jumpi : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "conditional_value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let destination := - BinOp.add (| - M.get_field (| M.get_name (| globals, "evm" |), "pc" |), - Constant.int 1 - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let destination := M.get_name (| globals, "jump_dest" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/environment.v b/CoqOfPython/ethereum/shanghai/vm/instructions/environment.v index 530304e..10bc05b 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/environment.v @@ -156,22 +156,6 @@ Definition balance : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "charge_gas" |), - make_list [ - M.get_name (| globals, "evm" |); - M.get_name (| globals, "GAS_WARM_ACCESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -538,7 +522,7 @@ Definition calldatacopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -706,7 +690,7 @@ Definition codecopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -805,22 +789,6 @@ Definition extcodesize : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "charge_gas" |), - make_list [ - M.get_name (| globals, "evm" |); - M.get_name (| globals, "GAS_WARM_ACCESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -958,28 +926,6 @@ Definition extcodecopy : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "charge_gas" |), - make_list [ - M.get_name (| globals, "evm" |); - BinOp.add (| - BinOp.add (| - M.get_name (| globals, "GAS_WARM_ACCESS" |), - M.get_name (| globals, "copy_gas_cost" |) - |), - M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1007,7 +953,7 @@ Definition extcodecopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -1178,28 +1124,31 @@ Definition returndatacopy : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt_e (| BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "return_data_start_position" |) - ], - make_dict [] + Compare.lt_e (| + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "return_data_start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) |), M.call (| - M.get_name (| globals, "Uint" |), + M.get_name (| globals, "len" |), make_list [ - M.get_name (| globals, "size" |) + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |) ], make_dict [] |) - |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "return_data" |) - ], - make_dict [] - |) |); + |); M.get_name (| globals, "OutOfBoundsRead" |) ], make_dict [] @@ -1208,15 +1157,12 @@ Definition returndatacopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in let value := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |):BinOp.add (| - M.get_name (| globals, "return_data_start_position" |), - M.get_name (| globals, "size" |) - |) |) in + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |) |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -1258,22 +1204,6 @@ Definition extcodehash : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "charge_gas" |), - make_list [ - M.get_name (| globals, "evm" |); - M.get_name (| globals, "GAS_WARM_ACCESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1301,22 +1231,6 @@ Definition extcodehash : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "account" |), M.get_name (| globals, "EMPTY_ACCOUNT" |) |), - (* then *) - ltac:(M.monadic ( - let codehash := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let codehash := M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/keccak.v b/CoqOfPython/ethereum/shanghai/vm/instructions/keccak.v index cab9ffb..2c4b10e 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/keccak.v @@ -137,7 +137,7 @@ Definition keccak : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/log.v b/CoqOfPython/ethereum/shanghai/vm/instructions/log.v index 4891a4d..e084e59 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/log.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/log.v @@ -161,7 +161,7 @@ Definition log_n : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/memory.v b/CoqOfPython/ethereum/shanghai/vm/instructions/memory.v index 1e1c8b0..86ba742 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/memory.v @@ -121,7 +121,7 @@ Definition mstore : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -203,7 +203,7 @@ Definition mstore8 : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -288,7 +288,7 @@ Definition mload : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/stack.v b/CoqOfPython/ethereum/shanghai/vm/instructions/stack.v index 46a91f6..aa085db 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/stack.v @@ -104,22 +104,6 @@ Definition push_n : Value.t -> Value.t -> M := " in let _ := M.pass (| |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "num_bytes" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "charge_gas" |), - make_list [ - M.get_name (| globals, "evm" |); - M.get_name (| globals, "GAS_BASE" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -207,13 +191,16 @@ Definition dup_n : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] - |) |); + Compare.lt (| + M.get_name (| globals, "item_number" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + |); M.get_name (| globals, "StackUnderflowError" |) ], make_dict [] @@ -279,13 +266,16 @@ Definition swap_n : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] - |) |); + Compare.lt (| + M.get_name (| globals, "item_number" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + |); M.get_name (| globals, "StackUnderflowError" |) ], make_dict [] diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/storage.v b/CoqOfPython/ethereum/shanghai/vm/instructions/storage.v index 2f0a831..b3c4045 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/storage.v @@ -91,22 +91,6 @@ Definition sload : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "charge_gas" |), - make_list [ - M.get_name (| globals, "evm" |); - M.get_name (| globals, "GAS_WARM_ACCESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "add" |), make_list [ @@ -184,7 +168,10 @@ Definition sstore : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.gt (| M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), M.get_name (| globals, "GAS_CALL_STIPEND" |) |); + Compare.gt (| + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "GAS_CALL_STIPEND" |) + |); M.get_name (| globals, "OutOfGasError" |) ], make_dict [] @@ -218,189 +205,15 @@ Definition sstore : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_in (| make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "add" |), - make_list [ - make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ] - ], - make_dict [] - |) in - let gas_cost := BinOp.add - M.get_name (| globals, "GAS_COLD_SLOAD" |) - M.get_name (| globals, "GAS_COLD_SLOAD" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_name (| globals, "original_value" |), M.get_name (| globals, "current_value" |) |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_name (| globals, "current_value" |), M.get_name (| globals, "new_value" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let gas_cost := BinOp.add - M.get_name (| globals, "GAS_STORAGE_SET" |) - M.get_name (| globals, "GAS_STORAGE_SET" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let gas_cost := BinOp.add - BinOp.sub (| - M.get_name (| globals, "GAS_STORAGE_UPDATE" |), - M.get_name (| globals, "GAS_COLD_SLOAD" |) - |) - BinOp.sub (| - M.get_name (| globals, "GAS_STORAGE_UPDATE" |), - M.get_name (| globals, "GAS_COLD_SLOAD" |) - |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let gas_cost := BinOp.add M.get_name (| globals, "GAS_WARM_ACCESS" |) M.get_name (| globals, "GAS_WARM_ACCESS" |) in M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_eq (| M.get_name (| globals, "current_value" |), M.get_name (| globals, "new_value" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), - ltac:(M.monadic ( - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "new_value" |), Constant.int 0 |) - )) - |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), - M.call (| - M.get_name (| globals, "int" |), - make_list [ - M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.sub, - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), - M.call (| - M.get_name (| globals, "int" |), - make_list [ - M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "original_value" |), M.get_name (| globals, "new_value" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "original_value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), - M.call (| - M.get_name (| globals, "int" |), - make_list [ - BinOp.sub (| - M.get_name (| globals, "GAS_STORAGE_SET" |), - M.get_name (| globals, "GAS_WARM_ACCESS" |) - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), - M.call (| - M.get_name (| globals, "int" |), - make_list [ - BinOp.sub (| - BinOp.sub (| - M.get_name (| globals, "GAS_STORAGE_UPDATE" |), - M.get_name (| globals, "GAS_COLD_SLOAD" |) - |), - M.get_name (| globals, "GAS_WARM_ACCESS" |) - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/system.v b/CoqOfPython/ethereum/shanghai/vm/instructions/system.v new file mode 100644 index 0000000..6b9c771 --- /dev/null +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/system.v @@ -0,0 +1,1695 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) System Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM system related instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_account_exists_and_is_empty : + IsGlobalAlias globals state.globals "account_exists_and_is_empty". +Axiom state_account_has_code_or_nonce : + IsGlobalAlias globals state.globals "account_has_code_or_nonce". +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". +Axiom state_increment_nonce : + IsGlobalAlias globals state.globals "increment_nonce". +Axiom state_is_account_alive : + IsGlobalAlias globals state.globals "is_account_alive". +Axiom state_set_account_balance : + IsGlobalAlias globals state.globals "set_account_balance". + +Require utils.address. +Axiom utils_address_compute_contract_address : + IsGlobalAlias globals utils.address.globals "compute_contract_address". +Axiom utils_address_compute_create2_contract_address : + IsGlobalAlias globals utils.address.globals "compute_create2_contract_address". +Axiom utils_address_to_address : + IsGlobalAlias globals utils.address.globals "to_address". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". +Axiom __init___Message : + IsGlobalAlias globals __init__.globals "Message". +Axiom __init___incorporate_child_on_error : + IsGlobalAlias globals __init__.globals "incorporate_child_on_error". +Axiom __init___incorporate_child_on_success : + IsGlobalAlias globals __init__.globals "incorporate_child_on_success". + +Require exceptions. +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". +Axiom exceptions_Revert : + IsGlobalAlias globals exceptions.globals "Revert". +Axiom exceptions_WriteInStaticContext : + IsGlobalAlias globals exceptions.globals "WriteInStaticContext". + +Require gas. +Axiom gas_GAS_CALL_VALUE : + IsGlobalAlias globals gas.globals "GAS_CALL_VALUE". +Axiom gas_GAS_COLD_ACCOUNT_ACCESS : + IsGlobalAlias globals gas.globals "GAS_COLD_ACCOUNT_ACCESS". +Axiom gas_GAS_CREATE : + IsGlobalAlias globals gas.globals "GAS_CREATE". +Axiom gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". +Axiom gas_GAS_NEW_ACCOUNT : + IsGlobalAlias globals gas.globals "GAS_NEW_ACCOUNT". +Axiom gas_GAS_SELF_DESTRUCT : + IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT". +Axiom gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : + IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". +Axiom gas_GAS_WARM_ACCESS : + IsGlobalAlias globals gas.globals "GAS_WARM_ACCESS". +Axiom gas_GAS_ZERO : + IsGlobalAlias globals gas.globals "GAS_ZERO". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_calculate_message_call_gas : + IsGlobalAlias globals gas.globals "calculate_message_call_gas". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". +Axiom gas_init_code_cost : + IsGlobalAlias globals gas.globals "init_code_cost". +Axiom gas_max_message_call_gas : + IsGlobalAlias globals gas.globals "max_message_call_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". +Axiom memory_memory_write : + IsGlobalAlias globals memory.globals "memory_write". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition generic_create : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "endowment"; "contract_address"; "memory_start_position"; "memory_size"; "init_code_gas" ] |) in + let _ := Constant.str " + Core logic used by the `CREATE*` family of opcodes. + " in +(* At stmt: unsupported node type: ImportFrom *) + let call_data := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt_e (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "call_data" |) + ], + make_dict [] + |), + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "MAX_CODE_SIZE" |) + |) + |); + M.get_name (| globals, "OutOfGasError" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "contract_address" |) + ], + make_dict [] + |) in + let create_message_gas := + M.call (| + M.get_name (| globals, "max_message_call_gas" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.sub, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "create_message_gas" |) + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let sender_address := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in + let sender := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "sender_address" |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + let child_message := + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) in + let child_evm := + M.call (| + M.get_name (| globals, "process_create_message" |), + make_list [ + M.get_name (| globals, "child_message" |); + M.get_field (| M.get_name (| globals, "evm" |), "env" |) + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_success" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition create : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Creates a new account with associated code. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let endowment := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_position" |); M.get_name (| globals, "memory_size" |) ] + ] + ], + make_dict [] + |) in + let init_code_gas := + M.call (| + M.get_name (| globals, "init_code_cost" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_CREATE" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |), + M.get_name (| globals, "init_code_gas" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let contract_address := + M.call (| + M.get_name (| globals, "compute_contract_address" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "nonce" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "generic_create" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "endowment" |); + M.get_name (| globals, "contract_address" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |); + M.get_name (| globals, "init_code_gas" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition create2 : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Creates a new account with associated code. + + It's similar to CREATE opcode except that the address of new account + depends on the init_code instead of the nonce of sender. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let endowment := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let salt := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_position" |); M.get_name (| globals, "memory_size" |) ] + ] + ], + make_dict [] + |) in + let call_data_words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let init_code_gas := + M.call (| + M.get_name (| globals, "init_code_cost" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_CREATE" |), + BinOp.mult (| + M.get_name (| globals, "GAS_KECCAK256_WORD" |), + M.get_name (| globals, "call_data_words" |) + |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |), + M.get_name (| globals, "init_code_gas" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let contract_address := + M.call (| + M.get_name (| globals, "compute_create2_contract_address" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "salt" |); + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "generic_create" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "endowment" |); + M.get_name (| globals, "contract_address" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |); + M.get_name (| globals, "init_code_gas" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition return_ : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Halts execution returning output data. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let memory_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_position" |); M.get_name (| globals, "memory_size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_ZERO" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "running" |), + Constant.bool false + |) in + let _ := M.pass (| |) in + M.pure Constant.None_)). + +Definition generic_call : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "gas"; "value"; "caller"; "to"; "code_address"; "should_transfer_value"; "is_staticcall"; "memory_input_start_position"; "memory_input_size"; "memory_output_start_position"; "memory_output_size" ] |) in + let _ := Constant.str " + Perform the core logic of the `CALL*` family of opcodes. + " in +(* At stmt: unsupported node type: ImportFrom *) + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let _ := + M.pure Constant.None_ + )) |) in + let call_data := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |) + ], + make_dict [] + |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "code_address" |) + ], + make_dict [] + |), "code" |) in + let child_message := + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) in + let child_evm := + M.call (| + M.get_name (| globals, "process_message" |), + make_list [ + M.get_name (| globals, "child_message" |); + M.get_field (| M.get_name (| globals, "evm" |), "env" |) + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_success" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let actual_output_size := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_name (| globals, "memory_output_size" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), Constant.None_:M.get_name (| globals, "actual_output_size" |) |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition call : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into an account. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let to := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "to" |) + ], + make_dict [] + |) in + let access_gas_cost := + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + M.pure Constant.None_ + )) |) in + let create_gas_cost := + (* if *) +M.if_then_else (| + BoolOp.or (| + M.call (| + M.get_name (| globals, "is_account_alive" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "to" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |) + )) + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let transfer_gas_cost := + (* if *) +M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "access_gas_cost" |), + M.get_name (| globals, "create_gas_cost" |) + |), + M.get_name (| globals, "transfer_gas_cost" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.or (| + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "value" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) + )) + |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let sender_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.get_name (| globals, "value" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "to" |); + Constant.bool true; + Constant.bool false; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition callcode : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into this account with alternative account’s code. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let code_address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let to := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "code_address" |) + ], + make_dict [] + |) in + let access_gas_cost := + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + M.pure Constant.None_ + )) |) in + let transfer_gas_cost := + (* if *) +M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + BinOp.add (| + M.get_name (| globals, "access_gas_cost" |), + M.get_name (| globals, "transfer_gas_cost" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let sender_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.get_name (| globals, "value" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "code_address" |); + Constant.bool true; + Constant.bool false; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition selfdestruct : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Halt execution and register account for later deletion. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let beneficiary := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let gas_cost := + M.get_name (| globals, "GAS_SELF_DESTRUCT" |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "gas_cost" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + UnOp.not (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "is_static" |) |); + M.get_name (| globals, "WriteInStaticContext" |) + ], + make_dict [] + |) in + let originator := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in + let beneficiary_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |), "balance" |) in + let originator_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "originator" |) + ], + make_dict [] + |), "balance" |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |); + BinOp.add (| + M.get_name (| globals, "beneficiary_balance" |), + M.get_name (| globals, "originator_balance" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "originator" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |), "add" |), + make_list [ + M.get_name (| globals, "originator" |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "running" |), + Constant.bool false + |) in + let _ := M.pass (| |) in + M.pure Constant.None_)). + +Definition delegatecall : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into an account. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let code_address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "code_address" |) + ], + make_dict [] + |) in + let access_gas_cost := + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + M.pure Constant.None_ + )) |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + M.get_name (| globals, "access_gas_cost" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "value" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "caller" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "code_address" |); + Constant.bool false; + Constant.bool false; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition staticcall : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into an account. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let to := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "to" |) + ], + make_dict [] + |) in + let access_gas_cost := + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + M.pure Constant.None_ + )) |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + M.get_name (| globals, "access_gas_cost" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "to" |); + Constant.bool true; + Constant.bool true; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition revert : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Stop execution and revert state changes, without consuming all provided gas + and also has the ability to return a reason + Parameters + ---------- + evm : + The current EVM frame. + " in + let memory_start_index := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_index" |); M.get_name (| globals, "size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let output := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_index" |); + M.get_name (| globals, "size" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "bytes" |), + make_list [ + M.get_name (| globals, "output" |) + ], + make_dict [] + |) + |) in + let _ := M.raise (| Some(M.get_name (| globals, "Revert" |)) + let _ := M.pass (| |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/vm/interpreter.v b/CoqOfPython/ethereum/shanghai/vm/interpreter.v index 903fa29..eee00d3 100644 --- a/CoqOfPython/ethereum/shanghai/vm/interpreter.v +++ b/CoqOfPython/ethereum/shanghai/vm/interpreter.v @@ -186,91 +186,6 @@ Definition process_message_call : Value.t -> Value.t -> M := Output of the message call " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_name (| globals, "message" |), "target" |), M.call (| - M.get_name (| globals, "Bytes0" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let is_collision := - M.call (| - M.get_name (| globals, "account_has_code_or_nonce" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_field (| M.get_name (| globals, "message" |), "current_target" |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - M.get_name (| globals, "is_collision" |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "MessageCallOutput" |), - make_list [ - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |); - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |); - M.call (| - M.get_name (| globals, "tuple" |), - make_list [], - make_dict [] - |); - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |); - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |); - M.call (| - M.get_name (| globals, "AddressCollision" |), - make_list [], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let evm := - M.call (| - M.get_name (| globals, "process_create_message" |), - make_list [ - M.get_name (| globals, "message" |); - M.get_name (| globals, "env" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let evm := M.call (| M.get_name (| globals, "process_message" |), @@ -281,74 +196,11 @@ Definition process_message_call : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_field (| M.get_name (| globals, "message" |), "target" |) - ], - make_dict [] - |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), - make_list [ - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_field (| M.get_name (| globals, "message" |), "target" |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "evm" |), "error" |), - (* then *) - ltac:(M.monadic ( -(* At stmt: unsupported node type: AnnAssign *) - let accounts_to_delete := - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |) in - let touched_accounts := - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |) in - let refund_counter := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let logs := M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in let accounts_to_delete := @@ -392,7 +244,6 @@ Definition process_message_call : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). Definition process_create_message : Value.t -> Value.t -> M := @@ -454,28 +305,6 @@ Definition process_create_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), - (* then *) - ltac:(M.monadic ( - let contract_code := - M.get_field (| M.get_name (| globals, "evm" |), "output" |) in - let contract_code_gas := - BinOp.mult (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "contract_code" |) - ], - make_dict [] - |), - M.get_name (| globals, "GAS_CODE_DEPOSIT" |) - |) in -(* At stmt: unsupported node type: Try *) - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "rollback_transaction" |), make_list [ @@ -487,7 +316,6 @@ Definition process_create_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) - |) in M.pure Constant.None_)). Definition process_message : Value.t -> Value.t -> M := @@ -509,21 +337,6 @@ Definition process_message : Value.t -> Value.t -> M := Items containing execution specific objects " in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_field (| M.get_name (| globals, "message" |), "depth" |), M.get_name (| globals, "STACK_DEPTH_LIMIT" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "StackDepthLimitError" |), - make_list [ - Constant.str "Stack depth limit reached" - ], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -542,29 +355,6 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - M.get_field (| M.get_name (| globals, "message" |), "should_transfer_value" |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_field (| M.get_name (| globals, "message" |), "value" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "move_ether" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_field (| M.get_name (| globals, "message" |), "caller" |); - M.get_field (| M.get_name (| globals, "message" |), "current_target" |); - M.get_field (| M.get_name (| globals, "message" |), "value" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let evm := @@ -577,21 +367,6 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "evm" |), "error" |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "rollback_transaction" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "commit_transaction" |), make_list [ @@ -603,7 +378,6 @@ Definition process_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) - |) in M.pure Constant.None_)). Definition execute_code : Value.t -> Value.t -> M := @@ -643,5 +417,4 @@ Definition execute_code : Value.t -> Value.t -> M := (* At stmt: unsupported node type: Try *) let _ := M.return_ (| M.get_name (| globals, "evm" |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/vm/memory.v b/CoqOfPython/ethereum/shanghai/vm/memory.v index fa8d906..4b107fd 100644 --- a/CoqOfPython/ethereum/shanghai/vm/memory.v +++ b/CoqOfPython/ethereum/shanghai/vm/memory.v @@ -45,22 +45,7 @@ Definition memory_write : Value.t -> Value.t -> M := Data to write to memory. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) - |) |), + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_)). @@ -86,23 +71,7 @@ Definition memory_read_bytes : Value.t -> Value.t -> M := Data read from memory. " in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |) - |) in + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |) M.pure Constant.None_)). Definition buffer_read : Value.t -> Value.t -> M := @@ -129,25 +98,9 @@ Definition buffer_read : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "right_pad_zero_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |); + M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |) |); M.get_name (| globals, "size" |) ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/alt_bn128.v index 19b83fc..abe4238 100644 --- a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/alt_bn128.v +++ b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/alt_bn128.v @@ -210,15 +210,6 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) in For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ] do let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "i" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -362,15 +353,6 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) in For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ] do let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "i" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -443,24 +425,6 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_eq (| BinOp.mod_ (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "data" |) - ], - make_dict [] - |), - Constant.int 192 - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let result := @@ -509,32 +473,11 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := Constant.int 32, M.get_name (| globals, "j" |) |) - |):BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "i" |), - Constant.int 192 - |), - BinOp.mult (| - Constant.int 32, - BinOp.add (| - M.get_name (| globals, "j" |), - Constant.int 1 - |) - |) |) |) ], make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "value" |), M.get_name (| globals, "ALT_BN128_PRIME" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "OutOfGasError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -555,17 +498,20 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.call (| - M.get_field (| M.get_name (| globals, "p" |), "mul_by" |), - make_list [ - M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) - ], - make_dict [] - |), M.call (| - M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) |); + Compare.eq (| + M.call (| + M.get_field (| M.get_name (| globals, "p" |), "mul_by" |), + make_list [ + M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) + ], + make_dict [] + |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |); M.get_name (| globals, "OutOfGasError" |) ], make_dict [] @@ -573,87 +519,29 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.call (| - M.get_field (| M.get_name (| globals, "q" |), "mul_by" |), - make_list [ - M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) - ], - make_dict [] - |), M.call (| - M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) |); + Compare.eq (| + M.call (| + M.get_field (| M.get_name (| globals, "q" |), "mul_by" |), + make_list [ + M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) + ], + make_dict [] + |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |); M.get_name (| globals, "OutOfGasError" |) ], make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "p" |), M.call (| - M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_name (| globals, "q" |), M.call (| - M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let result := - BinOp.mult (| - M.get_name (| globals, "result" |), - M.call (| - M.get_name (| globals, "pairing" |), - make_list [ - M.get_name (| globals, "q" |); - M.get_name (| globals, "p" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "result" |), M.call (| - M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), - make_list [ - Constant.int 1 - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign (| - M.get_field (| M.get_name (| globals, "evm" |), "output" |), - M.call (| - M.get_field (| M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 1 - ], - make_dict [] - |), "to_be_bytes32" |), - make_list [], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| diff --git a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/blake2f.v b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/blake2f.v index 5903066..1647d48 100644 --- a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/blake2f.v +++ b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/blake2f.v @@ -55,13 +55,16 @@ Definition blake2f : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "data" |) - ], - make_dict [] - |), Constant.int 213 |); + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 213 + |); M.get_name (| globals, "InvalidParameter" |) ], make_dict [] @@ -96,10 +99,13 @@ Definition blake2f : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.in (| M.get_name (| globals, "f" |), make_list [ - Constant.int 0; - Constant.int 1 - ] |); + Compare.in (| + M.get_name (| globals, "f" |), + make_list [ + Constant.int 0; + Constant.int 1 + ] + |); M.get_name (| globals, "InvalidParameter" |) ], make_dict [] diff --git a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/ecrecover.v index cc351b5..0cbcf16 100644 --- a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/ecrecover.v @@ -188,60 +188,12 @@ Definition ecrecover : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 27 |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 28 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| Constant.int 0, M.get_name (| globals, "r" |) |), - ltac:(M.monadic ( - Compare.gt_e (| M.get_name (| globals, "r" |), M.get_name (| globals, "SECP256K1N" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| Constant.int 0, M.get_name (| globals, "s" |) |), - ltac:(M.monadic ( - Compare.gt_e (| M.get_name (| globals, "s" |), M.get_name (| globals, "SECP256K1N" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: Try *) @@ -252,7 +204,7 @@ Definition ecrecover : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12:Constant.int 32 |) in + |), Constant.int 12 |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/modexp.v index 544949e..3505244 100644 --- a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/modexp.v +++ b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/modexp.v @@ -192,30 +192,6 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_name (| globals, "base_length" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "modulus_length" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign (| - M.get_field (| M.get_name (| globals, "evm" |), "output" |), - M.call (| - M.get_name (| globals, "Bytes" |), - make_list [], - make_dict [] - |) - |) in - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let base := @@ -278,27 +254,6 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "modulus" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign (| - M.get_field (| M.get_name (| globals, "evm" |), "output" |), - BinOp.mult (| - M.call (| - M.get_name (| globals, "Bytes" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |), - M.get_name (| globals, "modulus_length" |) - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| @@ -383,7 +338,6 @@ Definition complexity : Value.t -> Value.t -> M := M.get_name (| globals, "words" |), Constant.int 2 |) - |) in M.pure Constant.None_)). Definition iterations : Value.t -> Value.t -> M := @@ -410,64 +364,7 @@ Definition iterations : Value.t -> Value.t -> M := Number of iterations. " in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.lt_e (| M.get_name (| globals, "exponent_length" |), Constant.int 32 |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "exponent_head" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let count := - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - Compare.lt_e (| M.get_name (| globals, "exponent_length" |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let bit_length := - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.call (| - M.get_field (| M.get_name (| globals, "exponent_head" |), "bit_length" |), - make_list [], - make_dict [] - |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "bit_length" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let bit_length := BinOp.sub - Constant.int 1 - Constant.int 1 in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let count := - M.get_name (| globals, "bit_length" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let length_part := BinOp.mult (| Constant.int 8, @@ -495,17 +392,6 @@ Definition iterations : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "bits_part" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let bits_part := BinOp.sub - Constant.int 1 - Constant.int 1 in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let count := @@ -532,7 +418,6 @@ Definition iterations : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition gas_cost : Value.t -> Value.t -> M := @@ -604,5 +489,4 @@ Definition gas_cost : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/vm/runtime.v b/CoqOfPython/ethereum/shanghai/vm/runtime.v index 835b46c..2cd7652 100644 --- a/CoqOfPython/ethereum/shanghai/vm/runtime.v +++ b/CoqOfPython/ethereum/shanghai/vm/runtime.v @@ -67,50 +67,19 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := ], make_dict [] |) in - While Compare.lt (| M.get_name (| globals, "pc" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "code" |) - ], - make_dict [] - |) |) do + While Compare.lt (| + M.get_name (| globals, "pc" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) + |) do (* At stmt: unsupported node type: Try *) let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "current_opcode" |), M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), - make_list [ - M.get_name (| globals, "pc" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - (* At expr: unsupported node type: Compare *), - (* then *) - ltac:(M.monadic ( - let push_data_size := - BinOp.add (| - BinOp.sub (| - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) - |), - Constant.int 1 - |) in - let pc := BinOp.add - M.get_name (| globals, "push_data_size" |) - M.get_name (| globals, "push_data_size" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -121,5 +90,4 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := EndWhile. let _ := M.return_ (| M.get_name (| globals, "valid_jump_destinations" |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/vm/stack.v b/CoqOfPython/ethereum/shanghai/vm/stack.v index 42ea42d..ea778df 100644 --- a/CoqOfPython/ethereum/shanghai/vm/stack.v +++ b/CoqOfPython/ethereum/shanghai/vm/stack.v @@ -49,21 +49,6 @@ Definition pop : Value.t -> Value.t -> M := " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "stack" |) - ], - make_dict [] - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "StackUnderflowError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -72,7 +57,6 @@ Definition pop : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). Definition push : Value.t -> Value.t -> M := @@ -91,21 +75,6 @@ Definition push : Value.t -> Value.t -> M := " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "stack" |) - ], - make_dict [] - |), Constant.int 1024 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "StackOverflowError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -116,5 +85,4 @@ Definition push : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/bloom.v b/CoqOfPython/ethereum/spurious_dragon/bloom.v index 04b5d9f..04650ff 100644 --- a/CoqOfPython/ethereum/spurious_dragon/bloom.v +++ b/CoqOfPython/ethereum/spurious_dragon/bloom.v @@ -72,10 +72,7 @@ Definition add_to_bloom : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |):BinOp.add (| - M.get_name (| globals, "idx" |), - Constant.int 2 - |) |) + M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |) |) ], make_dict [] |), @@ -160,5 +157,4 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/fork.v b/CoqOfPython/ethereum/spurious_dragon/fork.v index 7799350..cadf255 100644 --- a/CoqOfPython/ethereum/spurious_dragon/fork.v +++ b/CoqOfPython/ethereum/spurious_dragon/fork.v @@ -224,7 +224,6 @@ Definition apply_fork : Value.t -> Value.t -> M := " in let _ := M.return_ (| M.get_name (| globals, "old" |) - |) in M.pure Constant.None_)). Definition get_last_256_block_hashes : Value.t -> Value.t -> M := @@ -250,25 +249,8 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := Hashes of the recent 256 blocks in order of increasing block number. " in let recent_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |) |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "recent_blocks" |) - ], - make_dict [] - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - make_list [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let recent_block_hashes := @@ -307,7 +289,6 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "recent_block_hashes" |) - |) in M.pure Constant.None_)). Definition state_transition : Value.t -> Value.t -> M := @@ -379,7 +360,10 @@ Definition state_transition : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_gas_used" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "gas_used" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_gas_used" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "gas_used" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -387,7 +371,10 @@ Definition state_transition : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "transactions_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "transactions_root" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "transactions_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "transactions_root" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -395,7 +382,10 @@ Definition state_transition : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "state_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "state_root" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "state_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "state_root" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -403,7 +393,10 @@ Definition state_transition : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "receipt_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "receipt_root" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "receipt_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "receipt_root" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -411,7 +404,10 @@ Definition state_transition : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_logs_bloom" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "bloom" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_logs_bloom" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "bloom" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -424,24 +420,6 @@ Definition state_transition : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "chain" |), "blocks" |) - ], - make_dict [] - |), Constant.int 255 |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign (| - M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |):(* At expr: unsupported node type: NoneType *) |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -469,7 +447,10 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.gt (| M.get_field (| M.get_name (| globals, "header" |), "timestamp" |), M.get_field (| M.get_name (| globals, "parent_header" |), "timestamp" |) |); + Compare.gt (| + M.get_field (| M.get_name (| globals, "header" |), "timestamp" |), + M.get_field (| M.get_name (| globals, "parent_header" |), "timestamp" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -477,10 +458,13 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "number" |), BinOp.add (| - M.get_field (| M.get_name (| globals, "parent_header" |), "number" |), - Constant.int 1 - |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "number" |), + BinOp.add (| + M.get_field (| M.get_name (| globals, "parent_header" |), "number" |), + Constant.int 1 + |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -503,13 +487,16 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt_e (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) - ], - make_dict [] - |), Constant.int 32 |); + Compare.lt_e (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) + ], + make_dict [] + |), + Constant.int 32 + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -528,7 +515,10 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "difficulty" |), M.get_name (| globals, "block_difficulty" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "difficulty" |), + M.get_name (| globals, "block_difficulty" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -550,7 +540,10 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |), M.get_name (| globals, "block_parent_hash" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |), + M.get_name (| globals, "block_parent_hash" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -613,7 +606,6 @@ Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition validate_proof_of_work : Value.t -> Value.t -> M := @@ -671,7 +663,10 @@ Definition validate_proof_of_work : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_name (| globals, "mix_digest" |), M.get_field (| M.get_name (| globals, "header" |), "mix_digest" |) |); + Compare.eq (| + M.get_name (| globals, "mix_digest" |), + M.get_field (| M.get_name (| globals, "header" |), "mix_digest" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -679,16 +674,19 @@ Definition validate_proof_of_work : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt_e (| M.call (| - M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), - make_list [ - M.get_name (| globals, "result" |) - ], - make_dict [] - |), BinOp.floor_div (| - M.get_name (| globals, "U256_CEIL_VALUE" |), - M.get_field (| M.get_name (| globals, "header" |), "difficulty" |) - |) |); + Compare.lt_e (| + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "result" |) + ], + make_dict [] + |), + BinOp.floor_div (| + M.get_name (| globals, "U256_CEIL_VALUE" |), + M.get_field (| M.get_name (| globals, "header" |), "difficulty" |) + |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -723,7 +721,10 @@ Definition check_transaction : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt_e (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_name (| globals, "gas_available" |) |); + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_name (| globals, "gas_available" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -739,7 +740,6 @@ Definition check_transaction : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "sender_address" |) - |) in M.pure Constant.None_)). Definition make_receipt : Value.t -> Value.t -> M := @@ -773,7 +773,6 @@ Definition make_receipt : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "receipt" |) - |) in M.pure Constant.None_)). Definition ApplyBodyOutput : Value.t := @@ -990,7 +989,6 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition validate_ommers : Value.t -> Value.t -> M := @@ -1028,42 +1026,39 @@ Definition validate_ommers : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), - make_list [ - M.get_name (| globals, "ommers" |) - ], - make_dict [] - |), M.get_field (| M.get_name (| globals, "block_header" |), "ommers_hash" |) |); + Compare.eq (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + M.get_field (| M.get_name (| globals, "block_header" |), "ommers_hash" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "ommers" |) - ], - make_dict [] - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - (* At expr: unsupported node type: Compare *); + BoolOp.and (| + Compare.lt_e (| + Constant.int 1, + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |), + ltac:(M.monadic ( + Compare.lt (| + M.get_field (| M.get_name (| globals, "ommer" |), "number" |), + M.get_field (| M.get_name (| globals, "block_header" |), "number" |) + |) + )) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1088,47 +1083,47 @@ Definition validate_ommers : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt_e (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "ommers" |) - ], - make_dict [] - |), Constant.int 2 |); + Compare.lt_e (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + Constant.int 2 + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] |) in let ommers_hashes := - [M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), - make_list [ - M.get_name (| globals, "ommer" |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)] in + (* At expr: unsupported node type: ListComp *) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "ommers_hashes" |) - ], - make_dict [] - |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.call (| - M.get_name (| globals, "set" |), - make_list [ - M.get_name (| globals, "ommers_hashes" |) - ], - make_dict [] - |) - ], - make_dict [] - |) |); + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers_hashes" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_name (| globals, "set" |), + make_list [ + M.get_name (| globals, "ommers_hashes" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1137,28 +1132,16 @@ Definition validate_ommers : Value.t -> Value.t -> M := M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| BinOp.add (| M.get_name (| globals, "MAX_OMMER_DEPTH" |), Constant.int 1 - |) |):(* At expr: unsupported node type: NoneType *) |) in + |) |) |) in let recent_canonical_block_hashes := - {M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), - make_list [ - M.get_field (| M.get_name (| globals, "block" |), "header" |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)} in + (* At expr: unsupported node type: SetComp *) in (* At stmt: unsupported node type: AnnAssign *) For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_canonical_blocks" |) do let recent_ommers_hashes := M.call (| M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), make_list [ - {M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), - make_list [ - M.get_name (| globals, "ommer" |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)} + (* At expr: unsupported node type: SetComp *) ], make_dict [] |) in @@ -1175,7 +1158,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.not_eq (| M.get_name (| globals, "ommer_hash" |), M.get_name (| globals, "block_hash" |) |); + Compare.not_eq (| + M.get_name (| globals, "ommer_hash" |), + M.get_name (| globals, "block_hash" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1183,7 +1169,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.not_in (| M.get_name (| globals, "ommer_hash" |), M.get_name (| globals, "recent_canonical_block_hashes" |) |); + Compare.not_in (| + M.get_name (| globals, "ommer_hash" |), + M.get_name (| globals, "recent_canonical_block_hashes" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1191,7 +1180,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.not_in (| M.get_name (| globals, "ommer_hash" |), M.get_name (| globals, "recent_ommers_hashes" |) |); + Compare.not_in (| + M.get_name (| globals, "ommer_hash" |), + M.get_name (| globals, "recent_ommers_hashes" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1204,7 +1196,18 @@ Definition validate_ommers : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - (* At expr: unsupported node type: Compare *); + BoolOp.and (| + Compare.lt_e (| + Constant.int 1, + M.get_name (| globals, "ommer_age" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_name (| globals, "ommer_age" |), + M.get_name (| globals, "MAX_OMMER_DEPTH" |) + |) + )) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1212,7 +1215,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.in (| M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), M.get_name (| globals, "recent_canonical_block_hashes" |) |); + Compare.in (| + M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), + M.get_name (| globals, "recent_canonical_block_hashes" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1220,7 +1226,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.not_eq (| M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), M.get_field (| M.get_name (| globals, "block_header" |), "parent_hash" |) |); + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), + M.get_field (| M.get_name (| globals, "block_header" |), "parent_hash" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1379,7 +1388,10 @@ Definition process_transaction : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "sender_account" |), "nonce" |), M.get_field (| M.get_name (| globals, "tx" |), "nonce" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "sender_account" |), "nonce" |), + M.get_field (| M.get_name (| globals, "tx" |), "nonce" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1387,10 +1399,13 @@ Definition process_transaction : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.gt_e (| M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), BinOp.add (| - M.get_name (| globals, "gas_fee" |), - M.get_field (| M.get_name (| globals, "tx" |), "value" |) - |) |); + Compare.gt_e (| + M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), + BinOp.add (| + M.get_name (| globals, "gas_fee" |), + M.get_field (| M.get_name (| globals, "tx" |), "value" |) + |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1398,11 +1413,14 @@ Definition process_transaction : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "sender_account" |), "code" |), M.call (| - M.get_name (| globals, "bytearray" |), - make_list [], - make_dict [] - |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "sender_account" |), "code" |), + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [], + make_dict [] + |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1537,47 +1555,7 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "transaction_fee" |) |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_eq (| M.get_name (| globals, "coinbase_balance_after_mining_fee" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "set_account_balance" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_field (| M.get_name (| globals, "env" |), "coinbase" |); - M.get_name (| globals, "coinbase_balance_after_mining_fee" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "destroy_account" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -1594,35 +1572,11 @@ Definition process_transaction : Value.t -> Value.t -> M := EndFor. For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "touched_accounts" |) do let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "destroy_account" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := M.return_ (| make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |) ] - |) in M.pure Constant.None_)). Definition validate_transaction : Value.t -> Value.t -> M := @@ -1654,24 +1608,29 @@ Definition validate_transaction : Value.t -> Value.t -> M := " in let _ := M.return_ (| BoolOp.and (| - Compare.lt_e (| M.call (| - M.get_name (| globals, "calculate_intrinsic_cost" |), - make_list [ - M.get_name (| globals, "tx" |) - ], - make_dict [] - |), M.get_field (| M.get_name (| globals, "tx" |), "gas" |) |), + Compare.lt_e (| + M.call (| + M.get_name (| globals, "calculate_intrinsic_cost" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |), + M.get_field (| M.get_name (| globals, "tx" |), "gas" |) + |), ltac:(M.monadic ( - Compare.lt (| M.get_field (| M.get_name (| globals, "tx" |), "nonce" |), BinOp.sub (| + Compare.lt (| + M.get_field (| M.get_name (| globals, "tx" |), "nonce" |), + BinOp.sub (| BinOp.pow (| Constant.int 2, Constant.int 64 |), Constant.int 1 - |) |) + |) + |) )) |) - |) in M.pure Constant.None_)). Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := @@ -1703,17 +1662,6 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := Constant.int 0 in For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "byte" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let data_cost := BinOp.add - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let data_cost := BinOp.add M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in @@ -1721,22 +1669,6 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := )) |) in EndFor. let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_name (| globals, "tx" |), "to" |), M.call (| - M.get_name (| globals, "Bytes0" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let create_cost := - M.get_name (| globals, "TX_CREATE_COST" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let create_cost := Constant.int 0 in M.pure Constant.None_ @@ -1755,7 +1687,6 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition recover_sender : Value.t -> Value.t -> M := @@ -1790,9 +1721,15 @@ Definition recover_sender : Value.t -> Value.t -> M := M.get_name (| globals, "ensure" |), make_list [ BoolOp.and (| - Compare.lt (| Constant.int 0, M.get_name (| globals, "r" |) |), + Compare.lt (| + Constant.int 0, + M.get_name (| globals, "r" |) + |), ltac:(M.monadic ( - Compare.lt (| M.get_name (| globals, "r" |), M.get_name (| globals, "SECP256K1N" |) |) + Compare.lt (| + M.get_name (| globals, "r" |), + M.get_name (| globals, "SECP256K1N" |) + |) )) |); M.get_name (| globals, "InvalidBlock" |) @@ -1803,12 +1740,18 @@ Definition recover_sender : Value.t -> Value.t -> M := M.get_name (| globals, "ensure" |), make_list [ BoolOp.and (| - Compare.lt (| Constant.int 0, M.get_name (| globals, "s" |) |), + Compare.lt (| + Constant.int 0, + M.get_name (| globals, "s" |) + |), ltac:(M.monadic ( - Compare.lt_e (| M.get_name (| globals, "s" |), BinOp.floor_div (| + Compare.lt_e (| + M.get_name (| globals, "s" |), + BinOp.floor_div (| M.get_name (| globals, "SECP256K1N" |), Constant.int 2 - |) |) + |) + |) )) |); M.get_name (| globals, "InvalidBlock" |) @@ -1816,58 +1759,31 @@ Definition recover_sender : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.eq (| M.get_name (| globals, "v" |), Constant.int 27 |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "v" |), Constant.int 28 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let public_key := - M.call (| - M.get_name (| globals, "secp256k1_recover" |), - make_list [ - M.get_name (| globals, "r" |); - M.get_name (| globals, "s" |); - BinOp.sub (| - M.get_name (| globals, "v" |), - Constant.int 27 - |); - M.call (| - M.get_name (| globals, "signing_hash_pre155" |), - make_list [ - M.get_name (| globals, "tx" |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ BoolOp.or (| - Compare.eq (| M.get_name (| globals, "v" |), BinOp.add (| - Constant.int 35, - BinOp.mult (| - M.get_name (| globals, "chain_id" |), - Constant.int 2 + Compare.eq (| + M.get_name (| globals, "v" |), + BinOp.add (| + Constant.int 35, + BinOp.mult (| + M.get_name (| globals, "chain_id" |), + Constant.int 2 + |) |) - |) |), + |), ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "v" |), BinOp.add (| + Compare.eq (| + M.get_name (| globals, "v" |), + BinOp.add (| Constant.int 36, BinOp.mult (| M.get_name (| globals, "chain_id" |), Constant.int 2 |) - |) |) + |) + |) )) |); M.get_name (| globals, "InvalidBlock" |) @@ -1913,11 +1829,10 @@ Definition recover_sender : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12:Constant.int 32 |) + |), Constant.int 12 |) ], make_dict [] |) - |) in M.pure Constant.None_)). Definition signing_hash_pre155 : Value.t -> Value.t -> M := @@ -1950,7 +1865,6 @@ Definition signing_hash_pre155 : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition signing_hash_155 : Value.t -> Value.t -> M := @@ -1997,7 +1911,6 @@ Definition signing_hash_155 : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition compute_header_hash : Value.t -> Value.t -> M := @@ -2048,7 +1961,6 @@ Definition compute_header_hash : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition check_gas_limit : Value.t -> Value.t -> M := @@ -2087,56 +1999,16 @@ Definition check_gas_limit : Value.t -> Value.t -> M := M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "gas_limit" |), BinOp.add (| - M.get_name (| globals, "parent_gas_limit" |), - M.get_name (| globals, "max_adjustment_delta" |) - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.bool false - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt_e (| M.get_name (| globals, "gas_limit" |), BinOp.sub (| - M.get_name (| globals, "parent_gas_limit" |), - M.get_name (| globals, "max_adjustment_delta" |) - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.bool false - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "gas_limit" |), M.get_name (| globals, "GAS_LIMIT_MINIMUM" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.bool false - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| Constant.bool true - |) in M.pure Constant.None_)). Definition calculate_block_difficulty : Value.t -> Value.t -> M := @@ -2240,23 +2112,6 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := Constant.int 2 |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "num_bomb_periods" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let difficulty := BinOp.add - BinOp.pow (| - Constant.int 2, - M.get_name (| globals, "num_bomb_periods" |) - |) - BinOp.pow (| - Constant.int 2, - M.get_name (| globals, "num_bomb_periods" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -2274,5 +2129,4 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/fork_types.v b/CoqOfPython/ethereum/spurious_dragon/fork_types.v index d12953d..5c7dac3 100644 --- a/CoqOfPython/ethereum/spurious_dragon/fork_types.v +++ b/CoqOfPython/ethereum/spurious_dragon/fork_types.v @@ -98,5 +98,4 @@ Definition encode_account : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/state.v b/CoqOfPython/ethereum/spurious_dragon/state.v index 53b3837..c5b604e 100644 --- a/CoqOfPython/ethereum/spurious_dragon/state.v +++ b/CoqOfPython/ethereum/spurious_dragon/state.v @@ -123,13 +123,7 @@ Definition begin_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) ], make_dict [] - |); {M.get_name (| globals, "k" |): M.call (| - M.get_name (| globals, "copy_trie" |), - make_list [ - M.get_name (| globals, "t" |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)} ] + |); (* At expr: unsupported node type: DictComp *) ] ], make_dict [] |) in @@ -207,27 +201,8 @@ Definition get_account : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "account" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "account" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_ACCOUNT" |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -262,7 +237,6 @@ Definition get_account_optional : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "account" |) - |) in M.pure Constant.None_)). Definition set_account : Value.t -> Value.t -> M := @@ -342,15 +316,6 @@ Definition destroy_storage : Value.t -> Value.t -> M := Address of account whose storage is to be deleted. " in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -385,23 +350,6 @@ Definition get_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let value := @@ -423,7 +371,6 @@ Definition get_storage : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "value" |) - |) in M.pure Constant.None_)). Definition set_storage : Value.t -> Value.t -> M := @@ -444,14 +391,17 @@ Definition set_storage : Value.t -> Value.t -> M := value : `U256` Value to set at the key. " in - let _ := M.assert (| Compare.is_not (| M.call (| - M.get_name (| globals, "trie_get" |), - make_list [ - M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), Constant.None_ |) |) in + let _ := M.assert (| Compare.is_not (| + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + Constant.None_ + |) |) in let trie := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), @@ -461,24 +411,6 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let trie := - M.call (| - M.get_name (| globals, "Trie" |), - make_list [], - make_dict [] - |) in - let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), - M.get_name (| globals, "trie" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -491,15 +423,6 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), {} |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -524,26 +447,8 @@ Definition storage_root : Value.t -> Value.t -> M := " in let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "root" |), - make_list [ - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_TRIE_ROOT" |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -574,7 +479,6 @@ Definition state_root : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition account_exists : Value.t -> Value.t -> M := @@ -596,15 +500,17 @@ Definition account_exists : Value.t -> Value.t -> M := True if account exists in the state trie, False otherwise " in let _ := M.return_ (| - Compare.is_not (| M.call (| - M.get_name (| globals, "get_account_optional" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), Constant.None_ |) - |) in + Compare.is_not (| + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + Constant.None_ + |) M.pure Constant.None_)). Definition account_has_code_or_nonce : Value.t -> Value.t -> M := @@ -637,18 +543,23 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := |) in let _ := M.return_ (| BoolOp.or (| - Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( - Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |) + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |) )) |) - |) in M.pure Constant.None_)). Definition is_account_empty : Value.t -> Value.t -> M := @@ -681,23 +592,31 @@ Definition is_account_empty : Value.t -> Value.t -> M := |) in let _ := M.return_ (| BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |), ltac:(M.monadic ( - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "balance" |), + Constant.int 0 + |) )) |) )) |) - |) in M.pure Constant.None_)). Definition account_exists_and_is_empty : Value.t -> Value.t -> M := @@ -731,28 +650,39 @@ Definition account_exists_and_is_empty : Value.t -> Value.t -> M := |) in let _ := M.return_ (| BoolOp.and (| - Compare.is_not (| M.get_name (| globals, "account" |), Constant.None_ |), + Compare.is_not (| + M.get_name (| globals, "account" |), + Constant.None_ + |), ltac:(M.monadic ( BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |), ltac:(M.monadic ( - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "balance" |), + Constant.int 0 + |) )) |) )) |) )) |) - |) in M.pure Constant.None_)). Definition is_account_alive : Value.t -> Value.t -> M := @@ -783,36 +713,33 @@ Definition is_account_alive : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "account" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.bool false - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| UnOp.not (| BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( BoolOp.and (| - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |), + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |), ltac:(M.monadic ( - Compare.eq (| M.get_field (| M.get_name (| globals, "account" |), "balance" |), Constant.int 0 |) + Compare.eq (| + M.get_field (| M.get_name (| globals, "account" |), "balance" |), + Constant.int 0 + |) )) |) )) |) |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -920,30 +847,6 @@ Definition touch_account : Value.t -> Value.t -> M := The address of the account that need to initialised. " in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "account_exists" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "set_account" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |); - M.get_name (| globals, "EMPTY_ACCOUNT" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/trie.v b/CoqOfPython/ethereum/spurious_dragon/trie.v index 8ec85fb..f88c794 100644 --- a/CoqOfPython/ethereum/spurious_dragon/trie.v +++ b/CoqOfPython/ethereum/spurious_dragon/trie.v @@ -202,96 +202,16 @@ Definition encode_internal_node : Value.t -> Value.t -> M := " in (* At stmt: unsupported node type: AnnAssign *) let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "node" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let unencoded := - (* At constant: unsupported node type: Constant *) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "LeafNode" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let unencoded := - make_tuple [ M.call (| - M.get_name (| globals, "nibble_list_to_compact" |), - make_list [ - M.get_field (| M.get_name (| globals, "node" |), "rest_of_key" |); - Constant.bool true - ], - make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "ExtensionNode" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let unencoded := - make_tuple [ M.call (| - M.get_name (| globals, "nibble_list_to_compact" |), - make_list [ - M.get_field (| M.get_name (| globals, "node" |), "key_segment" |); - Constant.bool false - ], - make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "BranchNode" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let unencoded := - BinOp.add (| - M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), - make_list [ - M.get_field (| M.get_name (| globals, "node" |), "value" |) - ] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.call (| + let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ (* At expr: unsupported node type: JoinedStr *) ], make_dict [] - |) |) in + |)) M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -309,23 +229,6 @@ Definition encode_internal_node : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "encoded" |) - ], - make_dict [] - |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "unencoded" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_name (| globals, "keccak256" |), @@ -334,7 +237,6 @@ Definition encode_internal_node : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -348,83 +250,8 @@ Definition encode_node : Value.t -> Value.t -> M := Currently mostly an unimplemented stub. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "storage_root" |), Constant.None_ |) |) in - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "encode_account" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "storage_root" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - make_tuple [ M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "U256" |) ] - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.call (| - M.get_name (| globals, "cast" |), - make_list [ - M.get_field (| M.get_name (| globals, "rlp" |), "RLP" |); - M.get_name (| globals, "node" |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "Bytes" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "node" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "previous_trie" |), "encode_node" |), @@ -434,7 +261,6 @@ Definition encode_node : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -486,7 +312,6 @@ Definition copy_trie : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition trie_set : Value.t -> Value.t -> M := @@ -508,26 +333,6 @@ Definition trie_set : Value.t -> Value.t -> M := Node to insert at `key`. " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "value" |), M.get_field (| M.get_name (| globals, "trie" |), "default" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "key" |), M.get_field (| M.get_name (| globals, "trie" |), "_data" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), M.get_name (| globals, "value" |) @@ -565,7 +370,6 @@ Definition trie_get : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition common_prefix_length : Value.t -> Value.t -> M := @@ -588,28 +392,6 @@ Definition common_prefix_length : Value.t -> Value.t -> M := make_dict [] |) do let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| M.get_name (| globals, "i" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "b" |) - ], - make_dict [] - |) |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "i" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -621,7 +403,6 @@ Definition common_prefix_length : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition nibble_list_to_compact : Value.t -> Value.t -> M := @@ -667,68 +448,6 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| BinOp.mod_ (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |), - Constant.int 2 - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_name (| globals, "compact" |), "append" |), - make_list [ - BinOp.mult (| - Constant.int 16, - BinOp.mult (| - Constant.int 2, - M.get_name (| globals, "is_leaf" |) - |) - |) - ], - make_dict [] - |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 0; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |); - Constant.int 2 - ], - make_dict [] - |) do - let _ := M.call (| - M.get_field (| M.get_name (| globals, "compact" |), "append" |), - make_list [ - BinOp.add (| - BinOp.mult (| - Constant.int 16, - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) - |), - M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) - |) - ], - make_dict [] - |) in - EndFor. - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ @@ -790,7 +509,6 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition bytes_to_nibble_list : Value.t -> Value.t -> M := @@ -868,7 +586,6 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition _prepare_trie : Value.t -> Value.t -> M := @@ -898,45 +615,6 @@ Definition _prepare_trie : Value.t -> Value.t -> M := make_dict [] |) do let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "value" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in - let address := - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in - let encoded_value := - M.call (| - M.get_name (| globals, "encode_node" |), - make_list [ - M.get_name (| globals, "value" |); - M.call (| - M.get_name (| globals, "get_storage_root" |), - make_list [ - M.get_name (| globals, "address" |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let encoded_value := M.call (| M.get_name (| globals, "encode_node" |), @@ -950,29 +628,16 @@ Definition _prepare_trie : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.not_eq (| M.get_name (| globals, "encoded_value" |), (* At constant: unsupported node type: Constant *) |); + Compare.not_eq (| + M.get_name (| globals, "encoded_value" |), + Constant.bytes "" + |); M.get_name (| globals, "AssertionError" |) ], make_dict [] |) in (* At stmt: unsupported node type: AnnAssign *) let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "trie" |), "secured" |), - (* then *) - ltac:(M.monadic ( - let key := - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let key := M.get_name (| globals, "preimage" |) in M.pure Constant.None_ @@ -990,7 +655,6 @@ Definition _prepare_trie : Value.t -> Value.t -> M := EndFor. let _ := M.return_ (| M.get_name (| globals, "mapped" |) - |) in M.pure Constant.None_)). Definition root : Value.t -> Value.t -> M := @@ -1044,41 +708,6 @@ Definition root : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "root_node" |) - ], - make_dict [] - |) - ], - make_dict [] - |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "root_node" |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -1095,7 +724,6 @@ Definition root : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -1122,23 +750,6 @@ Definition patricialize : Value.t -> Value.t -> M := Root node of `obj`. " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "obj" |) - ], - make_dict [] - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.None_ - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let arbitrary_key := @@ -1156,36 +767,10 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "obj" |) - ], - make_dict [] - |), Constant.int 1 |), - (* then *) - ltac:(M.monadic ( - let leaf := - M.call (| - M.get_name (| globals, "LeafNode" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |); - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) - ], - make_dict [] - |) in - let _ := M.return_ (| - M.get_name (| globals, "leaf" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let substring := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |) |) in let prefix_length := M.call (| M.get_name (| globals, "len" |), @@ -1204,7 +789,7 @@ Definition patricialize : Value.t -> Value.t -> M := M.get_name (| globals, "common_prefix_length" |), make_list [ M.get_name (| globals, "substring" |); - M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) + M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) ], make_dict [] |) @@ -1212,58 +797,10 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.break (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let prefix := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):BinOp.add (| - M.get_name (| globals, "level" |), - M.get_name (| globals, "prefix_length" |) - |) |) in - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "ExtensionNode" |), - make_list [ - M.get_name (| globals, "prefix" |); - M.call (| - M.get_name (| globals, "encode_internal_node" |), - make_list [ - M.call (| - M.get_name (| globals, "patricialize" |), - make_list [ - M.get_name (| globals, "obj" |); - BinOp.add (| - M.get_name (| globals, "level" |), - M.get_name (| globals, "prefix_length" |) - |) - ], - make_dict [] - |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) @@ -1283,44 +820,9 @@ Definition patricialize : Value.t -> Value.t -> M := |) in EndFor. let value := - (* At constant: unsupported node type: Constant *) in + Constant.bytes "" in For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "key" |) - ], - make_dict [] - |), M.get_name (| globals, "level" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); - make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "AssertionError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let value := - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) @@ -1332,26 +834,9 @@ Definition patricialize : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "BranchNode" |), make_list [ - [M.call (| - M.get_name (| globals, "encode_internal_node" |), - make_list [ - M.call (| - M.get_name (| globals, "patricialize" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "branches" |), M.get_name (| globals, "k" |) |); - BinOp.add (| - M.get_name (| globals, "level" |), - Constant.int 1 - |) - ], - make_dict [] - |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)]; + (* At expr: unsupported node type: ListComp *); M.get_name (| globals, "value" |) ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/utils/address.v b/CoqOfPython/ethereum/spurious_dragon/utils/address.v index 65b1ac7..502ba8e 100644 --- a/CoqOfPython/ethereum/spurious_dragon/utils/address.v +++ b/CoqOfPython/ethereum/spurious_dragon/utils/address.v @@ -68,11 +68,10 @@ Definition to_address : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), make_list [], make_dict [] - |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) + |), UnOp.sub (| Constant.int 20 |) |) ], make_dict [] |) - |) in M.pure Constant.None_)). Definition compute_contract_address : Value.t -> Value.t -> M := @@ -112,7 +111,7 @@ Definition compute_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -130,5 +129,4 @@ Definition compute_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/utils/hexadecimal.v b/CoqOfPython/ethereum/spurious_dragon/utils/hexadecimal.v index 0c93e84..879f5ca 100644 --- a/CoqOfPython/ethereum/spurious_dragon/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/spurious_dragon/utils/hexadecimal.v @@ -66,7 +66,6 @@ Definition hex_to_root : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition hex_to_bloom : Value.t -> Value.t -> M := @@ -105,7 +104,6 @@ Definition hex_to_bloom : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition hex_to_address : Value.t -> Value.t -> M := @@ -151,5 +149,4 @@ Definition hex_to_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/utils/message.v b/CoqOfPython/ethereum/spurious_dragon/utils/message.v index 11d0d76..c1d198a 100644 --- a/CoqOfPython/ethereum/spurious_dragon/utils/message.v +++ b/CoqOfPython/ethereum/spurious_dragon/utils/message.v @@ -85,105 +85,14 @@ Definition prepare_message : Value.t -> Value.t -> M := Items containing contract creation or message call specific data. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "target" |); - M.get_name (| globals, "Bytes0" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let current_target := - M.call (| - M.get_name (| globals, "compute_contract_address" |), - make_list [ - M.get_name (| globals, "caller" |); - BinOp.sub (| - M.get_field (| M.call (| - M.get_name (| globals, "get_account" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "caller" |) - ], - make_dict [] - |), "nonce" |), - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 1 - ], - make_dict [] - |) - |) - ], - make_dict [] - |) in - let msg_data := - M.call (| - M.get_name (| globals, "Bytes" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |) in - let code := - M.get_name (| globals, "data" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "target" |); - M.get_name (| globals, "Address" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let current_target := - M.get_name (| globals, "target" |) in - let msg_data := - M.get_name (| globals, "data" |) in - let code := - M.get_field (| M.call (| - M.get_name (| globals, "get_account" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "target" |) - ], - make_dict [] - |), "code" |) in - let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "code_address" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let code_address := - M.get_name (| globals, "target" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.call (| + let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "Target must be address or empty bytes" ], make_dict [] - |) |) in + |)) M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -194,5 +103,4 @@ Definition prepare_message : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/__init__.v b/CoqOfPython/ethereum/spurious_dragon/vm/__init__.v index 520603e..8859cb4 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/__init__.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/__init__.v @@ -143,28 +143,6 @@ Definition incorporate_child_on_success : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); - M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -183,57 +161,9 @@ Definition incorporate_child_on_error : Value.t -> Value.t -> M := The child evm to incorporate. " in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "RIPEMD160_ADDRESS" |), M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), - make_list [ - M.get_name (| globals, "RIPEMD160_ADDRESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |), M.get_name (| globals, "RIPEMD160_ADDRESS" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); - M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), - make_list [ - M.get_name (| globals, "RIPEMD160_ADDRESS" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign_op (| diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/gas.v b/CoqOfPython/ethereum/spurious_dragon/vm/gas.v new file mode 100644 index 0000000..0604b94 --- /dev/null +++ b/CoqOfPython/ethereum/spurious_dragon/vm/gas.v @@ -0,0 +1,801 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Gas +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +EVM gas constants and calculators. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.trace. +Axiom ethereum_trace_GasAndRefund : + IsGlobalAlias globals ethereum.trace.globals "GasAndRefund". +Axiom ethereum_trace_evm_trace : + IsGlobalAlias globals ethereum.trace.globals "evm_trace". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". + +Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) +)). + +Definition GAS_BASE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 2 + ], + make_dict [] + |) +)). + +Definition GAS_VERY_LOW : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_SLOAD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 200 + ], + make_dict [] + |) +)). + +Definition GAS_STORAGE_SET : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 20000 + ], + make_dict [] + |) +)). + +Definition GAS_STORAGE_UPDATE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5000 + ], + make_dict [] + |) +)). + +Definition GAS_STORAGE_CLEAR_REFUND : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 15000 + ], + make_dict [] + |) +)). + +Definition GAS_LOW : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5 + ], + make_dict [] + |) +)). + +Definition GAS_MID : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 8 + ], + make_dict [] + |) +)). + +Definition GAS_HIGH : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 10 + ], + make_dict [] + |) +)). + +Definition GAS_EXPONENTIATION : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 10 + ], + make_dict [] + |) +)). + +Definition GAS_EXPONENTIATION_PER_BYTE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 50 + ], + make_dict [] + |) +)). + +Definition GAS_MEMORY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_KECCAK256 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 30 + ], + make_dict [] + |) +)). + +Definition GAS_KECCAK256_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 6 + ], + make_dict [] + |) +)). + +Definition GAS_COPY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_BLOCK_HASH : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 20 + ], + make_dict [] + |) +)). + +Definition GAS_EXTERNAL : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 700 + ], + make_dict [] + |) +)). + +Definition GAS_BALANCE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 400 + ], + make_dict [] + |) +)). + +Definition GAS_LOG : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 375 + ], + make_dict [] + |) +)). + +Definition GAS_LOG_DATA : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 8 + ], + make_dict [] + |) +)). + +Definition GAS_LOG_TOPIC : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 375 + ], + make_dict [] + |) +)). + +Definition GAS_CREATE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 32000 + ], + make_dict [] + |) +)). + +Definition GAS_CODE_DEPOSIT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 200 + ], + make_dict [] + |) +)). + +Definition GAS_ZERO : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) +)). + +Definition GAS_CALL : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 700 + ], + make_dict [] + |) +)). + +Definition GAS_NEW_ACCOUNT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 25000 + ], + make_dict [] + |) +)). + +Definition GAS_CALL_VALUE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 9000 + ], + make_dict [] + |) +)). + +Definition GAS_CALL_STIPEND : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 2300 + ], + make_dict [] + |) +)). + +Definition GAS_SELF_DESTRUCT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5000 + ], + make_dict [] + |) +)). + +Definition GAS_SELF_DESTRUCT_NEW_ACCOUNT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 25000 + ], + make_dict [] + |) +)). + +Definition REFUND_SELF_DESTRUCT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 24000 + ], + make_dict [] + |) +)). + +Definition GAS_ECRECOVER : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3000 + ], + make_dict [] + |) +)). + +Definition GAS_SHA256 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 60 + ], + make_dict [] + |) +)). + +Definition GAS_SHA256_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 12 + ], + make_dict [] + |) +)). + +Definition GAS_RIPEMD160 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 600 + ], + make_dict [] + |) +)). + +Definition GAS_RIPEMD160_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 120 + ], + make_dict [] + |) +)). + +Definition GAS_IDENTITY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 15 + ], + make_dict [] + |) +)). + +Definition GAS_IDENTITY_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition ExtendMemory : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition MessageCallGas : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition charge_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "amount" ] |) in + let _ := Constant.str " + Subtracts `amount` from `evm.gas_left`. + + Parameters + ---------- + evm : + The current EVM. + amount : + The amount of gas the current operation requires. + + " in + let _ := M.call (| + M.get_name (| globals, "evm_trace" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "GasAndRefund" |), + make_list [ + M.get_name (| globals, "amount" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + let _ := M.assign_op (| + BinOp.sub, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "amount" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition calculate_memory_gas_cost : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "size_in_bytes" ] |) in + let _ := Constant.str " + Calculates the gas cost for allocating memory + to the smallest multiple of 32 bytes, + such that the allocated size is at least as big as the given size. + + Parameters + ---------- + size_in_bytes : + The size of the data in bytes. + + Returns + ------- + total_gas_cost : `ethereum.base_types.Uint` + The gas cost for storing data in memory. + " in + let size_in_words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "size_in_bytes" |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let linear_cost := + BinOp.mult (| + M.get_name (| globals, "size_in_words" |), + M.get_name (| globals, "GAS_MEMORY" |) + |) in + let quadratic_cost := + BinOp.floor_div (| + BinOp.pow (| + M.get_name (| globals, "size_in_words" |), + Constant.int 2 + |), + Constant.int 512 + |) in + let total_gas_cost := + BinOp.add (| + M.get_name (| globals, "linear_cost" |), + M.get_name (| globals, "quadratic_cost" |) + |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_)). + +Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "memory"; "extensions" ] |) in + let _ := Constant.str " + Calculates the gas amount to extend memory + + Parameters + ---------- + memory : + Memory contents of the EVM. + extensions: + List of extensions to be made to the memory. + Consists of a tuple of start position and size. + + Returns + ------- + extend_memory: `ExtendMemory` + " in + let size_to_extend := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let to_be_paid := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let current_size := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "memory" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + For make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ] in M.get_name (| globals, "extensions" |) do + let _ := + M.pure Constant.None_ + )) |) in + let before_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "current_size" |) + ], + make_dict [] + |) in + let after_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let size_to_extend := BinOp.add + BinOp.sub (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |) + BinOp.sub (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |) in + let already_paid := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "before_size" |) + ], + make_dict [] + |) in + let total_cost := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "after_size" |) + ], + make_dict [] + |) in + let to_be_paid := BinOp.add + BinOp.sub (| + M.get_name (| globals, "total_cost" |), + M.get_name (| globals, "already_paid" |) + |) + BinOp.sub (| + M.get_name (| globals, "total_cost" |), + M.get_name (| globals, "already_paid" |) + |) in + let current_size := + M.get_name (| globals, "after_size" |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ExtendMemory" |), + make_list [ + M.get_name (| globals, "to_be_paid" |); + M.get_name (| globals, "size_to_extend" |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition calculate_message_call_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "value"; "gas"; "gas_left"; "memory_cost"; "extra_gas"; "call_stipend" ] |) in + let _ := Constant.str " + Calculates the MessageCallGas (cost and stipend) for + executing call Opcodes. + + Parameters + ---------- + value: + The amount of `ETH` that needs to be transferred. + gas : + The amount of gas provided to the message-call. + gas_left : + The amount of gas left in the current frame. + memory_cost : + The amount needed to extend the memory in the current frame. + extra_gas : + The amount of gas needed for transferring value + creating a new + account inside a message call. + call_stipend : + The amount of stipend provided to a message call to execute code while + transferring value(ETH). + + Returns + ------- + message_call_gas: `MessageCallGas` + " in + let call_stipend := + (* if *) +M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let gas := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "max_message_call_gas" |), + make_list [ + BinOp.sub (| + BinOp.sub (| + M.get_name (| globals, "gas_left" |), + M.get_name (| globals, "memory_cost" |) + |), + M.get_name (| globals, "extra_gas" |) + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallGas" |), + make_list [ + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "extra_gas" |) + |); + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "call_stipend" |) + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition max_message_call_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "gas" ] |) in + let _ := Constant.str " + Calculates the maximum gas that is allowed for making a message call + + Parameters + ---------- + gas : + The amount of gas provided to the message-call. + + Returns + ------- + max_allowed_message_call_gas: `ethereum.base_types.Uint` + The maximum gas allowed for making the message-call. + " in + let _ := M.return_ (| + BinOp.sub (| + M.get_name (| globals, "gas" |), + BinOp.floor_div (| + M.get_name (| globals, "gas" |), + Constant.int 64 + |) + |) + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/arithmetic.v index a8b5c61..581ba5d 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/arithmetic.v @@ -273,22 +273,6 @@ Definition div : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let quotient := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let quotient := BinOp.floor_div (| M.get_name (| globals, "dividend" |), @@ -357,32 +341,7 @@ Definition sdiv : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let quotient := - Constant.int 0 in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_name (| globals, "dividend" |), UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "divisor" |), UnOp.sub (| Constant.int 1 |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let quotient := - UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let sign := M.call (| M.get_name (| globals, "get_sign" |), @@ -477,22 +436,6 @@ Definition mod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let remainder := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let remainder := BinOp.mod_ (| M.get_name (| globals, "x" |), @@ -561,16 +504,6 @@ Definition smod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let remainder := - Constant.int 0 in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let remainder := BinOp.mult (| M.call (| @@ -684,22 +617,6 @@ Definition addmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -795,22 +712,6 @@ Definition mulmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -980,16 +881,6 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "byte_num" |), Constant.int 31 |), - (* then *) - ltac:(M.monadic ( - let result := - M.get_name (| globals, "value" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let value_bytes := M.call (| M.get_name (| globals, "bytes" |), @@ -1012,29 +903,13 @@ Definition signextend : Value.t -> Value.t -> M := ], make_dict [] |) - |):(* At expr: unsupported node type: NoneType *) |) in + |) |) in let sign_bit := BinOp.r_shift (| M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), Constant.int 7 |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "sign_bit" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), - make_list [ - M.get_name (| globals, "value_bytes" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let num_bytes_prepend := BinOp.sub (| Constant.int 32, diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/bitwise.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/bitwise.v index b20a1e5..f38e7aa 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/bitwise.v @@ -285,22 +285,6 @@ Definition get_byte : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "byte_index" |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let extra_bytes_to_right := BinOp.sub (| Constant.int 31, diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/block.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/block.v index e5fa554..90be45c 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/block.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/block.v @@ -69,24 +69,6 @@ Definition block_hash : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.lt_e (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), M.get_name (| globals, "block_number" |) |), - ltac:(M.monadic ( - Compare.gt (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), BinOp.add (| - M.get_name (| globals, "block_number" |), - Constant.int 256 - |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let hash := - (* At constant: unsupported node type: Constant *) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let hash := M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/comparison.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/comparison.v index fbc35f8..b8529d8 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/comparison.v @@ -78,7 +78,10 @@ Definition less_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.lt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -145,7 +148,10 @@ Definition signed_less_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.lt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -205,7 +211,10 @@ Definition greater_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.gt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -272,7 +281,10 @@ Definition signed_greater_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.gt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -332,7 +344,10 @@ Definition equal : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.eq (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.eq (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -384,7 +399,10 @@ Definition is_zero : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.eq (| M.get_name (| globals, "x" |), Constant.int 0 |) + Compare.eq (| + M.get_name (| globals, "x" |), + Constant.int 0 + |) ], make_dict [] |) in diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/control_flow.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/control_flow.v index 04a79d9..d4e4eae 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/control_flow.v @@ -109,15 +109,6 @@ Definition jump : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -177,29 +168,7 @@ Definition jumpi : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "conditional_value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let destination := - BinOp.add (| - M.get_field (| M.get_name (| globals, "evm" |), "pc" |), - Constant.int 1 - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let destination := M.get_name (| globals, "jump_dest" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/environment.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/environment.v index 4d26a46..366e59a 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/environment.v @@ -492,7 +492,7 @@ Definition calldatacopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -660,7 +660,7 @@ Definition codecopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -903,7 +903,7 @@ Definition extcodecopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/keccak.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/keccak.v index cab9ffb..2c4b10e 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/keccak.v @@ -137,7 +137,7 @@ Definition keccak : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/log.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/log.v index f246f9d..ab196bc 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/log.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/log.v @@ -153,7 +153,7 @@ Definition log_n : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/memory.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/memory.v index 1e1c8b0..86ba742 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/memory.v @@ -121,7 +121,7 @@ Definition mstore : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -203,7 +203,7 @@ Definition mstore8 : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -288,7 +288,7 @@ Definition mload : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/stack.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/stack.v index 1eeda05..305af15 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/stack.v @@ -188,13 +188,16 @@ Definition dup_n : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] - |) |); + Compare.lt (| + M.get_name (| globals, "item_number" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + |); M.get_name (| globals, "StackUnderflowError" |) ], make_dict [] @@ -260,13 +263,16 @@ Definition swap_n : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] - |) |); + Compare.lt (| + M.get_name (| globals, "item_number" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + |); M.get_name (| globals, "StackUnderflowError" |) ], make_dict [] diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/storage.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/storage.v index 4292e3b..5250214 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/storage.v @@ -146,44 +146,11 @@ Definition sstore : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "new_value" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let gas_cost := - M.get_name (| globals, "GAS_STORAGE_SET" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let gas_cost := M.get_name (| globals, "GAS_STORAGE_UPDATE" |) in M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_name (| globals, "new_value" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), - M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/system.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/system.v new file mode 100644 index 0000000..1bde1ec --- /dev/null +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/system.v @@ -0,0 +1,1130 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) System Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM system related instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_account_exists_and_is_empty : + IsGlobalAlias globals state.globals "account_exists_and_is_empty". +Axiom state_account_has_code_or_nonce : + IsGlobalAlias globals state.globals "account_has_code_or_nonce". +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". +Axiom state_increment_nonce : + IsGlobalAlias globals state.globals "increment_nonce". +Axiom state_is_account_alive : + IsGlobalAlias globals state.globals "is_account_alive". +Axiom state_set_account_balance : + IsGlobalAlias globals state.globals "set_account_balance". + +Require utils.address. +Axiom utils_address_compute_contract_address : + IsGlobalAlias globals utils.address.globals "compute_contract_address". +Axiom utils_address_to_address : + IsGlobalAlias globals utils.address.globals "to_address". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". +Axiom __init___Message : + IsGlobalAlias globals __init__.globals "Message". +Axiom __init___incorporate_child_on_error : + IsGlobalAlias globals __init__.globals "incorporate_child_on_error". +Axiom __init___incorporate_child_on_success : + IsGlobalAlias globals __init__.globals "incorporate_child_on_success". + +Require gas. +Axiom gas_GAS_CALL : + IsGlobalAlias globals gas.globals "GAS_CALL". +Axiom gas_GAS_CALL_VALUE : + IsGlobalAlias globals gas.globals "GAS_CALL_VALUE". +Axiom gas_GAS_CREATE : + IsGlobalAlias globals gas.globals "GAS_CREATE". +Axiom gas_GAS_NEW_ACCOUNT : + IsGlobalAlias globals gas.globals "GAS_NEW_ACCOUNT". +Axiom gas_GAS_SELF_DESTRUCT : + IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT". +Axiom gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : + IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". +Axiom gas_GAS_ZERO : + IsGlobalAlias globals gas.globals "GAS_ZERO". +Axiom gas_REFUND_SELF_DESTRUCT : + IsGlobalAlias globals gas.globals "REFUND_SELF_DESTRUCT". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_calculate_message_call_gas : + IsGlobalAlias globals gas.globals "calculate_message_call_gas". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". +Axiom gas_max_message_call_gas : + IsGlobalAlias globals gas.globals "max_message_call_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". +Axiom memory_memory_write : + IsGlobalAlias globals memory.globals "memory_write". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition create : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Creates a new account with associated code. + + Parameters + ---------- + evm : + The current EVM frame. + " in +(* At stmt: unsupported node type: ImportFrom *) + let endowment := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_position" |); M.get_name (| globals, "memory_size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_CREATE" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let create_message_gas := + M.call (| + M.get_name (| globals, "max_message_call_gas" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.sub, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "create_message_gas" |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let sender_address := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in + let sender := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "sender_address" |) + ], + make_dict [] + |) in + let contract_address := + M.call (| + M.get_name (| globals, "compute_contract_address" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "nonce" |) + ], + make_dict [] + |) in + let _ := + let _ := + let call_data := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + let child_message := + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) in + let child_evm := + M.call (| + M.get_name (| globals, "process_create_message" |), + make_list [ + M.get_name (| globals, "child_message" |); + M.get_field (| M.get_name (| globals, "evm" |), "env" |) + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_success" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition return_ : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Halts execution returning output data. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let memory_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_position" |); M.get_name (| globals, "memory_size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_ZERO" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "running" |), + Constant.bool false + |) in + let _ := M.pass (| |) in + M.pure Constant.None_)). + +Definition generic_call : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "gas"; "value"; "caller"; "to"; "code_address"; "should_transfer_value"; "memory_input_start_position"; "memory_input_size"; "memory_output_start_position"; "memory_output_size" ] |) in + let _ := Constant.str " + Perform the core logic of the `CALL*` family of opcodes. + " in +(* At stmt: unsupported node type: ImportFrom *) + let _ := + M.pure Constant.None_ + )) |) in + let call_data := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |) + ], + make_dict [] + |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "code_address" |) + ], + make_dict [] + |), "code" |) in + let child_message := + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) in + let child_evm := + M.call (| + M.get_name (| globals, "process_message" |), + make_list [ + M.get_name (| globals, "child_message" |); + M.get_field (| M.get_name (| globals, "evm" |), "env" |) + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_success" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let actual_output_size := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_name (| globals, "memory_output_size" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), Constant.None_:M.get_name (| globals, "actual_output_size" |) |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition call : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into an account. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let to := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let create_gas_cost := + (* if *) +M.if_then_else (| + BoolOp.or (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "is_account_alive" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "to" |) + ], + make_dict [] + |) + )) + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let transfer_gas_cost := + (* if *) +M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_CALL" |), + M.get_name (| globals, "create_gas_cost" |) + |), + M.get_name (| globals, "transfer_gas_cost" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let sender_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.get_name (| globals, "value" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "to" |); + Constant.bool true; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition callcode : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into this account with alternative account’s code. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let code_address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let to := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let transfer_gas_cost := + (* if *) +M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + BinOp.add (| + M.get_name (| globals, "GAS_CALL" |), + M.get_name (| globals, "transfer_gas_cost" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let sender_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.get_name (| globals, "value" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "code_address" |); + Constant.bool true; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition selfdestruct : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Halt execution and register account for later deletion. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let beneficiary := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let gas_cost := + M.get_name (| globals, "GAS_SELF_DESTRUCT" |) in + let _ := + M.pure Constant.None_ + )) |) in + let originator := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in + let refunded_accounts := + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in + let parent_evm := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "parent_evm" |) in + While Compare.is_not (| + M.get_name (| globals, "parent_evm" |), + Constant.None_ + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "refunded_accounts" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "parent_evm" |), "accounts_to_delete" |) + ], + make_dict [] + |) in + let parent_evm := + M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in + EndWhile. + let _ := + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "gas_cost" |) + ], + make_dict [] + |) in + let beneficiary_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |), "balance" |) in + let originator_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "originator" |) + ], + make_dict [] + |), "balance" |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |); + BinOp.add (| + M.get_name (| globals, "beneficiary_balance" |), + M.get_name (| globals, "originator_balance" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "originator" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |), "add" |), + make_list [ + M.get_name (| globals, "originator" |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "running" |), + Constant.bool false + |) in + let _ := M.pass (| |) in + M.pure Constant.None_)). + +Definition delegatecall : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into an account. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let code_address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + M.get_name (| globals, "GAS_CALL" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "value" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "caller" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "code_address" |); + Constant.bool false; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/interpreter.v b/CoqOfPython/ethereum/spurious_dragon/vm/interpreter.v index f285aa8..259dc56 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/interpreter.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/interpreter.v @@ -178,91 +178,6 @@ Definition process_message_call : Value.t -> Value.t -> M := Output of the message call " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_name (| globals, "message" |), "target" |), M.call (| - M.get_name (| globals, "Bytes0" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let is_collision := - M.call (| - M.get_name (| globals, "account_has_code_or_nonce" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_field (| M.get_name (| globals, "message" |), "current_target" |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - M.get_name (| globals, "is_collision" |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "MessageCallOutput" |), - make_list [ - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |); - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |); - M.call (| - M.get_name (| globals, "tuple" |), - make_list [], - make_dict [] - |); - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |); - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |); - M.call (| - M.get_name (| globals, "AddressCollision" |), - make_list [], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let evm := - M.call (| - M.get_name (| globals, "process_create_message" |), - make_list [ - M.get_name (| globals, "message" |); - M.get_name (| globals, "env" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let evm := M.call (| M.get_name (| globals, "process_message" |), @@ -273,74 +188,11 @@ Definition process_message_call : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_field (| M.get_name (| globals, "message" |), "target" |) - ], - make_dict [] - |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), - make_list [ - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_field (| M.get_name (| globals, "message" |), "target" |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "evm" |), "error" |), - (* then *) - ltac:(M.monadic ( -(* At stmt: unsupported node type: AnnAssign *) - let accounts_to_delete := - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |) in - let touched_accounts := - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |) in - let refund_counter := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let logs := M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in let accounts_to_delete := @@ -378,7 +230,6 @@ Definition process_message_call : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). Definition process_create_message : Value.t -> Value.t -> M := @@ -432,28 +283,6 @@ Definition process_create_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), - (* then *) - ltac:(M.monadic ( - let contract_code := - M.get_field (| M.get_name (| globals, "evm" |), "output" |) in - let contract_code_gas := - BinOp.mult (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "contract_code" |) - ], - make_dict [] - |), - M.get_name (| globals, "GAS_CODE_DEPOSIT" |) - |) in -(* At stmt: unsupported node type: Try *) - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "rollback_transaction" |), make_list [ @@ -465,7 +294,6 @@ Definition process_create_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) - |) in M.pure Constant.None_)). Definition process_message : Value.t -> Value.t -> M := @@ -487,21 +315,6 @@ Definition process_message : Value.t -> Value.t -> M := Items containing execution specific objects " in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_field (| M.get_name (| globals, "message" |), "depth" |), M.get_name (| globals, "STACK_DEPTH_LIMIT" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "StackDepthLimitError" |), - make_list [ - Constant.str "Stack depth limit reached" - ], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -520,29 +333,6 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - M.get_field (| M.get_name (| globals, "message" |), "should_transfer_value" |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_field (| M.get_name (| globals, "message" |), "value" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "move_ether" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_field (| M.get_name (| globals, "message" |), "caller" |); - M.get_field (| M.get_name (| globals, "message" |), "current_target" |); - M.get_field (| M.get_name (| globals, "message" |), "value" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let evm := @@ -555,21 +345,6 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "evm" |), "error" |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "rollback_transaction" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "commit_transaction" |), make_list [ @@ -581,7 +356,6 @@ Definition process_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) - |) in M.pure Constant.None_)). Definition execute_code : Value.t -> Value.t -> M := @@ -621,5 +395,4 @@ Definition execute_code : Value.t -> Value.t -> M := (* At stmt: unsupported node type: Try *) let _ := M.return_ (| M.get_name (| globals, "evm" |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/memory.v b/CoqOfPython/ethereum/spurious_dragon/vm/memory.v index fa8d906..4b107fd 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/memory.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/memory.v @@ -45,22 +45,7 @@ Definition memory_write : Value.t -> Value.t -> M := Data to write to memory. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) - |) |), + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_)). @@ -86,23 +71,7 @@ Definition memory_read_bytes : Value.t -> Value.t -> M := Data read from memory. " in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |) - |) in + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |) M.pure Constant.None_)). Definition buffer_read : Value.t -> Value.t -> M := @@ -129,25 +98,9 @@ Definition buffer_read : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "right_pad_zero_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |); + M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |) |); M.get_name (| globals, "size" |) ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/ecrecover.v index cc351b5..0cbcf16 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/ecrecover.v @@ -188,60 +188,12 @@ Definition ecrecover : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 27 |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 28 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| Constant.int 0, M.get_name (| globals, "r" |) |), - ltac:(M.monadic ( - Compare.gt_e (| M.get_name (| globals, "r" |), M.get_name (| globals, "SECP256K1N" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| Constant.int 0, M.get_name (| globals, "s" |) |), - ltac:(M.monadic ( - Compare.gt_e (| M.get_name (| globals, "s" |), M.get_name (| globals, "SECP256K1N" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: Try *) @@ -252,7 +204,7 @@ Definition ecrecover : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12:Constant.int 32 |) in + |), Constant.int 12 |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/runtime.v b/CoqOfPython/ethereum/spurious_dragon/vm/runtime.v index 835b46c..2cd7652 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/runtime.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/runtime.v @@ -67,50 +67,19 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := ], make_dict [] |) in - While Compare.lt (| M.get_name (| globals, "pc" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "code" |) - ], - make_dict [] - |) |) do + While Compare.lt (| + M.get_name (| globals, "pc" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) + |) do (* At stmt: unsupported node type: Try *) let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "current_opcode" |), M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), - make_list [ - M.get_name (| globals, "pc" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - (* At expr: unsupported node type: Compare *), - (* then *) - ltac:(M.monadic ( - let push_data_size := - BinOp.add (| - BinOp.sub (| - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) - |), - Constant.int 1 - |) in - let pc := BinOp.add - M.get_name (| globals, "push_data_size" |) - M.get_name (| globals, "push_data_size" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -121,5 +90,4 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := EndWhile. let _ := M.return_ (| M.get_name (| globals, "valid_jump_destinations" |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/stack.v b/CoqOfPython/ethereum/spurious_dragon/vm/stack.v index 42ea42d..ea778df 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/stack.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/stack.v @@ -49,21 +49,6 @@ Definition pop : Value.t -> Value.t -> M := " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "stack" |) - ], - make_dict [] - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "StackUnderflowError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -72,7 +57,6 @@ Definition pop : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). Definition push : Value.t -> Value.t -> M := @@ -91,21 +75,6 @@ Definition push : Value.t -> Value.t -> M := " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "stack" |) - ], - make_dict [] - |), Constant.int 1024 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "StackOverflowError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -116,5 +85,4 @@ Definition push : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/bloom.v b/CoqOfPython/ethereum/tangerine_whistle/bloom.v index 04b5d9f..04650ff 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/bloom.v +++ b/CoqOfPython/ethereum/tangerine_whistle/bloom.v @@ -72,10 +72,7 @@ Definition add_to_bloom : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |):BinOp.add (| - M.get_name (| globals, "idx" |), - Constant.int 2 - |) |) + M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |) |) ], make_dict [] |), @@ -160,5 +157,4 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/fork.v b/CoqOfPython/ethereum/tangerine_whistle/fork.v index 951cae7..245eaa1 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/fork.v +++ b/CoqOfPython/ethereum/tangerine_whistle/fork.v @@ -222,7 +222,6 @@ Definition apply_fork : Value.t -> Value.t -> M := " in let _ := M.return_ (| M.get_name (| globals, "old" |) - |) in M.pure Constant.None_)). Definition get_last_256_block_hashes : Value.t -> Value.t -> M := @@ -248,25 +247,8 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := Hashes of the recent 256 blocks in order of increasing block number. " in let recent_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |) |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "recent_blocks" |) - ], - make_dict [] - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - make_list [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let recent_block_hashes := @@ -305,7 +287,6 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "recent_block_hashes" |) - |) in M.pure Constant.None_)). Definition state_transition : Value.t -> Value.t -> M := @@ -376,7 +357,10 @@ Definition state_transition : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_gas_used" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "gas_used" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_gas_used" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "gas_used" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -384,7 +368,10 @@ Definition state_transition : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "transactions_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "transactions_root" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "transactions_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "transactions_root" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -392,7 +379,10 @@ Definition state_transition : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "state_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "state_root" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "state_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "state_root" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -400,7 +390,10 @@ Definition state_transition : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "receipt_root" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "receipt_root" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "receipt_root" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "receipt_root" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -408,7 +401,10 @@ Definition state_transition : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_logs_bloom" |), M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "bloom" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "apply_body_output" |), "block_logs_bloom" |), + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "bloom" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -421,24 +417,6 @@ Definition state_transition : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "chain" |), "blocks" |) - ], - make_dict [] - |), Constant.int 255 |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign (| - M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |):(* At expr: unsupported node type: NoneType *) |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -466,7 +444,10 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.gt (| M.get_field (| M.get_name (| globals, "header" |), "timestamp" |), M.get_field (| M.get_name (| globals, "parent_header" |), "timestamp" |) |); + Compare.gt (| + M.get_field (| M.get_name (| globals, "header" |), "timestamp" |), + M.get_field (| M.get_name (| globals, "parent_header" |), "timestamp" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -474,10 +455,13 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "number" |), BinOp.add (| - M.get_field (| M.get_name (| globals, "parent_header" |), "number" |), - Constant.int 1 - |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "number" |), + BinOp.add (| + M.get_field (| M.get_name (| globals, "parent_header" |), "number" |), + Constant.int 1 + |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -500,13 +484,16 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt_e (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) - ], - make_dict [] - |), Constant.int 32 |); + Compare.lt_e (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) + ], + make_dict [] + |), + Constant.int 32 + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -525,7 +512,10 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "difficulty" |), M.get_name (| globals, "block_difficulty" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "difficulty" |), + M.get_name (| globals, "block_difficulty" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -547,7 +537,10 @@ Definition validate_header : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |), M.get_name (| globals, "block_parent_hash" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |), + M.get_name (| globals, "block_parent_hash" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -610,7 +603,6 @@ Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition validate_proof_of_work : Value.t -> Value.t -> M := @@ -668,7 +660,10 @@ Definition validate_proof_of_work : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_name (| globals, "mix_digest" |), M.get_field (| M.get_name (| globals, "header" |), "mix_digest" |) |); + Compare.eq (| + M.get_name (| globals, "mix_digest" |), + M.get_field (| M.get_name (| globals, "header" |), "mix_digest" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -676,16 +671,19 @@ Definition validate_proof_of_work : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt_e (| M.call (| - M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), - make_list [ - M.get_name (| globals, "result" |) - ], - make_dict [] - |), BinOp.floor_div (| - M.get_name (| globals, "U256_CEIL_VALUE" |), - M.get_field (| M.get_name (| globals, "header" |), "difficulty" |) - |) |); + Compare.lt_e (| + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "result" |) + ], + make_dict [] + |), + BinOp.floor_div (| + M.get_name (| globals, "U256_CEIL_VALUE" |), + M.get_field (| M.get_name (| globals, "header" |), "difficulty" |) + |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -718,7 +716,10 @@ Definition check_transaction : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt_e (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_name (| globals, "gas_available" |) |); + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_name (| globals, "gas_available" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -733,7 +734,6 @@ Definition check_transaction : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "sender_address" |) - |) in M.pure Constant.None_)). Definition make_receipt : Value.t -> Value.t -> M := @@ -767,7 +767,6 @@ Definition make_receipt : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "receipt" |) - |) in M.pure Constant.None_)). Definition ApplyBodyOutput : Value.t := @@ -981,7 +980,6 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition validate_ommers : Value.t -> Value.t -> M := @@ -1019,42 +1017,39 @@ Definition validate_ommers : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), - make_list [ - M.get_name (| globals, "ommers" |) - ], - make_dict [] - |), M.get_field (| M.get_name (| globals, "block_header" |), "ommers_hash" |) |); + Compare.eq (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + M.get_field (| M.get_name (| globals, "block_header" |), "ommers_hash" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "ommers" |) - ], - make_dict [] - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - (* At expr: unsupported node type: Compare *); + BoolOp.and (| + Compare.lt_e (| + Constant.int 1, + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |), + ltac:(M.monadic ( + Compare.lt (| + M.get_field (| M.get_name (| globals, "ommer" |), "number" |), + M.get_field (| M.get_name (| globals, "block_header" |), "number" |) + |) + )) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1079,47 +1074,47 @@ Definition validate_ommers : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt_e (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "ommers" |) - ], - make_dict [] - |), Constant.int 2 |); + Compare.lt_e (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + Constant.int 2 + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] |) in let ommers_hashes := - [M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), - make_list [ - M.get_name (| globals, "ommer" |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)] in + (* At expr: unsupported node type: ListComp *) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "ommers_hashes" |) - ], - make_dict [] - |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.call (| - M.get_name (| globals, "set" |), - make_list [ - M.get_name (| globals, "ommers_hashes" |) - ], - make_dict [] - |) - ], - make_dict [] - |) |); + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers_hashes" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_name (| globals, "set" |), + make_list [ + M.get_name (| globals, "ommers_hashes" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1128,28 +1123,16 @@ Definition validate_ommers : Value.t -> Value.t -> M := M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| BinOp.add (| M.get_name (| globals, "MAX_OMMER_DEPTH" |), Constant.int 1 - |) |):(* At expr: unsupported node type: NoneType *) |) in + |) |) |) in let recent_canonical_block_hashes := - {M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), - make_list [ - M.get_field (| M.get_name (| globals, "block" |), "header" |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)} in + (* At expr: unsupported node type: SetComp *) in (* At stmt: unsupported node type: AnnAssign *) For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_canonical_blocks" |) do let recent_ommers_hashes := M.call (| M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), make_list [ - {M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), - make_list [ - M.get_name (| globals, "ommer" |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)} + (* At expr: unsupported node type: SetComp *) ], make_dict [] |) in @@ -1166,7 +1149,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.not_eq (| M.get_name (| globals, "ommer_hash" |), M.get_name (| globals, "block_hash" |) |); + Compare.not_eq (| + M.get_name (| globals, "ommer_hash" |), + M.get_name (| globals, "block_hash" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1174,7 +1160,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.not_in (| M.get_name (| globals, "ommer_hash" |), M.get_name (| globals, "recent_canonical_block_hashes" |) |); + Compare.not_in (| + M.get_name (| globals, "ommer_hash" |), + M.get_name (| globals, "recent_canonical_block_hashes" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1182,7 +1171,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.not_in (| M.get_name (| globals, "ommer_hash" |), M.get_name (| globals, "recent_ommers_hashes" |) |); + Compare.not_in (| + M.get_name (| globals, "ommer_hash" |), + M.get_name (| globals, "recent_ommers_hashes" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1195,7 +1187,18 @@ Definition validate_ommers : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - (* At expr: unsupported node type: Compare *); + BoolOp.and (| + Compare.lt_e (| + Constant.int 1, + M.get_name (| globals, "ommer_age" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_name (| globals, "ommer_age" |), + M.get_name (| globals, "MAX_OMMER_DEPTH" |) + |) + )) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1203,7 +1206,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.in (| M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), M.get_name (| globals, "recent_canonical_block_hashes" |) |); + Compare.in (| + M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), + M.get_name (| globals, "recent_canonical_block_hashes" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1211,7 +1217,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.not_eq (| M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), M.get_field (| M.get_name (| globals, "block_header" |), "parent_hash" |) |); + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), + M.get_field (| M.get_name (| globals, "block_header" |), "parent_hash" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1370,7 +1379,10 @@ Definition process_transaction : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "sender_account" |), "nonce" |), M.get_field (| M.get_name (| globals, "tx" |), "nonce" |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "sender_account" |), "nonce" |), + M.get_field (| M.get_name (| globals, "tx" |), "nonce" |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1378,10 +1390,13 @@ Definition process_transaction : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.gt_e (| M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), BinOp.add (| - M.get_name (| globals, "gas_fee" |), - M.get_field (| M.get_name (| globals, "tx" |), "value" |) - |) |); + Compare.gt_e (| + M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), + BinOp.add (| + M.get_name (| globals, "gas_fee" |), + M.get_field (| M.get_name (| globals, "tx" |), "value" |) + |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1389,11 +1404,14 @@ Definition process_transaction : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.eq (| M.get_field (| M.get_name (| globals, "sender_account" |), "code" |), M.call (| - M.get_name (| globals, "bytearray" |), - make_list [], - make_dict [] - |) |); + Compare.eq (| + M.get_field (| M.get_name (| globals, "sender_account" |), "code" |), + M.call (| + M.get_name (| globals, "bytearray" |), + make_list [], + make_dict [] + |) + |); M.get_name (| globals, "InvalidBlock" |) ], make_dict [] @@ -1548,7 +1566,6 @@ Definition process_transaction : Value.t -> Value.t -> M := EndFor. let _ := M.return_ (| make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |) ] - |) in M.pure Constant.None_)). Definition validate_transaction : Value.t -> Value.t -> M := @@ -1580,24 +1597,29 @@ Definition validate_transaction : Value.t -> Value.t -> M := " in let _ := M.return_ (| BoolOp.and (| - Compare.lt_e (| M.call (| - M.get_name (| globals, "calculate_intrinsic_cost" |), - make_list [ - M.get_name (| globals, "tx" |) - ], - make_dict [] - |), M.get_field (| M.get_name (| globals, "tx" |), "gas" |) |), + Compare.lt_e (| + M.call (| + M.get_name (| globals, "calculate_intrinsic_cost" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |), + M.get_field (| M.get_name (| globals, "tx" |), "gas" |) + |), ltac:(M.monadic ( - Compare.lt (| M.get_field (| M.get_name (| globals, "tx" |), "nonce" |), BinOp.sub (| + Compare.lt (| + M.get_field (| M.get_name (| globals, "tx" |), "nonce" |), + BinOp.sub (| BinOp.pow (| Constant.int 2, Constant.int 64 |), Constant.int 1 - |) |) + |) + |) )) |) - |) in M.pure Constant.None_)). Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := @@ -1629,17 +1651,6 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := Constant.int 0 in For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "byte" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let data_cost := BinOp.add - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let data_cost := BinOp.add M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in @@ -1647,22 +1658,6 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := )) |) in EndFor. let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_name (| globals, "tx" |), "to" |), M.call (| - M.get_name (| globals, "Bytes0" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let create_cost := - M.get_name (| globals, "TX_CREATE_COST" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let create_cost := Constant.int 0 in M.pure Constant.None_ @@ -1681,7 +1676,6 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition recover_sender : Value.t -> Value.t -> M := @@ -1714,9 +1708,15 @@ Definition recover_sender : Value.t -> Value.t -> M := M.get_name (| globals, "ensure" |), make_list [ BoolOp.or (| - Compare.eq (| M.get_name (| globals, "v" |), Constant.int 27 |), + Compare.eq (| + M.get_name (| globals, "v" |), + Constant.int 27 + |), ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "v" |), Constant.int 28 |) + Compare.eq (| + M.get_name (| globals, "v" |), + Constant.int 28 + |) )) |); M.get_name (| globals, "InvalidBlock" |) @@ -1727,9 +1727,15 @@ Definition recover_sender : Value.t -> Value.t -> M := M.get_name (| globals, "ensure" |), make_list [ BoolOp.and (| - Compare.lt (| Constant.int 0, M.get_name (| globals, "r" |) |), + Compare.lt (| + Constant.int 0, + M.get_name (| globals, "r" |) + |), ltac:(M.monadic ( - Compare.lt (| M.get_name (| globals, "r" |), M.get_name (| globals, "SECP256K1N" |) |) + Compare.lt (| + M.get_name (| globals, "r" |), + M.get_name (| globals, "SECP256K1N" |) + |) )) |); M.get_name (| globals, "InvalidBlock" |) @@ -1740,12 +1746,18 @@ Definition recover_sender : Value.t -> Value.t -> M := M.get_name (| globals, "ensure" |), make_list [ BoolOp.and (| - Compare.lt (| Constant.int 0, M.get_name (| globals, "s" |) |), + Compare.lt (| + Constant.int 0, + M.get_name (| globals, "s" |) + |), ltac:(M.monadic ( - Compare.lt_e (| M.get_name (| globals, "s" |), BinOp.floor_div (| + Compare.lt_e (| + M.get_name (| globals, "s" |), + BinOp.floor_div (| M.get_name (| globals, "SECP256K1N" |), Constant.int 2 - |) |) + |) + |) )) |); M.get_name (| globals, "InvalidBlock" |) @@ -1782,11 +1794,10 @@ Definition recover_sender : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12:Constant.int 32 |) + |), Constant.int 12 |) ], make_dict [] |) - |) in M.pure Constant.None_)). Definition signing_hash : Value.t -> Value.t -> M := @@ -1823,7 +1834,6 @@ Definition signing_hash : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition compute_header_hash : Value.t -> Value.t -> M := @@ -1874,7 +1884,6 @@ Definition compute_header_hash : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition check_gas_limit : Value.t -> Value.t -> M := @@ -1913,56 +1922,16 @@ Definition check_gas_limit : Value.t -> Value.t -> M := M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "gas_limit" |), BinOp.add (| - M.get_name (| globals, "parent_gas_limit" |), - M.get_name (| globals, "max_adjustment_delta" |) - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.bool false - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt_e (| M.get_name (| globals, "gas_limit" |), BinOp.sub (| - M.get_name (| globals, "parent_gas_limit" |), - M.get_name (| globals, "max_adjustment_delta" |) - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.bool false - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "gas_limit" |), M.get_name (| globals, "GAS_LIMIT_MINIMUM" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.bool false - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| Constant.bool true - |) in M.pure Constant.None_)). Definition calculate_block_difficulty : Value.t -> Value.t -> M := @@ -2066,23 +2035,6 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := Constant.int 2 |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "num_bomb_periods" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let difficulty := BinOp.add - BinOp.pow (| - Constant.int 2, - M.get_name (| globals, "num_bomb_periods" |) - |) - BinOp.pow (| - Constant.int 2, - M.get_name (| globals, "num_bomb_periods" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -2100,5 +2052,4 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/fork_types.v b/CoqOfPython/ethereum/tangerine_whistle/fork_types.v index d12953d..5c7dac3 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/fork_types.v +++ b/CoqOfPython/ethereum/tangerine_whistle/fork_types.v @@ -98,5 +98,4 @@ Definition encode_account : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/state.v b/CoqOfPython/ethereum/tangerine_whistle/state.v index 38fe9d1..2ba095e 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/state.v +++ b/CoqOfPython/ethereum/tangerine_whistle/state.v @@ -123,13 +123,7 @@ Definition begin_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) ], make_dict [] - |); {M.get_name (| globals, "k" |): M.call (| - M.get_name (| globals, "copy_trie" |), - make_list [ - M.get_name (| globals, "t" |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)} ] + |); (* At expr: unsupported node type: DictComp *) ] ], make_dict [] |) in @@ -207,27 +201,8 @@ Definition get_account : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "account" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "account" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_ACCOUNT" |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -262,7 +237,6 @@ Definition get_account_optional : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "account" |) - |) in M.pure Constant.None_)). Definition set_account : Value.t -> Value.t -> M := @@ -342,15 +316,6 @@ Definition destroy_storage : Value.t -> Value.t -> M := Address of account whose storage is to be deleted. " in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -385,23 +350,6 @@ Definition get_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let value := @@ -423,7 +371,6 @@ Definition get_storage : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "value" |) - |) in M.pure Constant.None_)). Definition set_storage : Value.t -> Value.t -> M := @@ -444,14 +391,17 @@ Definition set_storage : Value.t -> Value.t -> M := value : `U256` Value to set at the key. " in - let _ := M.assert (| Compare.is_not (| M.call (| - M.get_name (| globals, "trie_get" |), - make_list [ - M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), Constant.None_ |) |) in + let _ := M.assert (| Compare.is_not (| + M.call (| + M.get_name (| globals, "trie_get" |), + make_list [ + M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + Constant.None_ + |) |) in let trie := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), @@ -461,24 +411,6 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "trie" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let trie := - M.call (| - M.get_name (| globals, "Trie" |), - make_list [], - make_dict [] - |) in - let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), - M.get_name (| globals, "trie" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -491,15 +423,6 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), {} |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -524,26 +447,8 @@ Definition storage_root : Value.t -> Value.t -> M := " in let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "root" |), - make_list [ - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_TRIE_ROOT" |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -574,7 +479,6 @@ Definition state_root : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition account_exists : Value.t -> Value.t -> M := @@ -596,15 +500,17 @@ Definition account_exists : Value.t -> Value.t -> M := True if account exists in the state trie, False otherwise " in let _ := M.return_ (| - Compare.is_not (| M.call (| - M.get_name (| globals, "get_account_optional" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), Constant.None_ |) - |) in + Compare.is_not (| + M.call (| + M.get_name (| globals, "get_account_optional" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + Constant.None_ + |) M.pure Constant.None_)). Definition account_has_code_or_nonce : Value.t -> Value.t -> M := @@ -637,18 +543,23 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := |) in let _ := M.return_ (| BoolOp.or (| - Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "nonce" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "account" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), ltac:(M.monadic ( - Compare.not_eq (| M.get_field (| M.get_name (| globals, "account" |), "code" |), (* At constant: unsupported node type: Constant *) |) + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "account" |), "code" |), + Constant.bytes "" + |) )) |) - |) in M.pure Constant.None_)). Definition modify_state : Value.t -> Value.t -> M := @@ -754,30 +665,6 @@ Definition touch_account : Value.t -> Value.t -> M := The address of the account that need to initialised. " in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.call (| - M.get_name (| globals, "account_exists" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "set_account" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |); - M.get_name (| globals, "EMPTY_ACCOUNT" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/trie.v b/CoqOfPython/ethereum/tangerine_whistle/trie.v index 9b3038d..d52469e 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/trie.v +++ b/CoqOfPython/ethereum/tangerine_whistle/trie.v @@ -202,96 +202,16 @@ Definition encode_internal_node : Value.t -> Value.t -> M := " in (* At stmt: unsupported node type: AnnAssign *) let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "node" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let unencoded := - (* At constant: unsupported node type: Constant *) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "LeafNode" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let unencoded := - make_tuple [ M.call (| - M.get_name (| globals, "nibble_list_to_compact" |), - make_list [ - M.get_field (| M.get_name (| globals, "node" |), "rest_of_key" |); - Constant.bool true - ], - make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "ExtensionNode" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let unencoded := - make_tuple [ M.call (| - M.get_name (| globals, "nibble_list_to_compact" |), - make_list [ - M.get_field (| M.get_name (| globals, "node" |), "key_segment" |); - Constant.bool false - ], - make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "BranchNode" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let unencoded := - BinOp.add (| - M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), - make_list [ - M.get_field (| M.get_name (| globals, "node" |), "value" |) - ] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.call (| + let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ (* At expr: unsupported node type: JoinedStr *) ], make_dict [] - |) |) in + |)) M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -309,23 +229,6 @@ Definition encode_internal_node : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "encoded" |) - ], - make_dict [] - |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "unencoded" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_name (| globals, "keccak256" |), @@ -334,7 +237,6 @@ Definition encode_internal_node : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -348,83 +250,8 @@ Definition encode_node : Value.t -> Value.t -> M := Currently mostly an unimplemented stub. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "storage_root" |), Constant.None_ |) |) in - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "encode_account" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "storage_root" |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - make_tuple [ M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "U256" |) ] - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.call (| - M.get_name (| globals, "cast" |), - make_list [ - M.get_field (| M.get_name (| globals, "rlp" |), "RLP" |); - M.get_name (| globals, "node" |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "node" |); - M.get_name (| globals, "Bytes" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "node" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "previous_trie" |), "encode_node" |), @@ -434,7 +261,6 @@ Definition encode_node : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -486,7 +312,6 @@ Definition copy_trie : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition trie_set : Value.t -> Value.t -> M := @@ -508,26 +333,6 @@ Definition trie_set : Value.t -> Value.t -> M := Node to insert at `key`. " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "value" |), M.get_field (| M.get_name (| globals, "trie" |), "default" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - Compare.in (| M.get_name (| globals, "key" |), M.get_field (| M.get_name (| globals, "trie" |), "_data" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), M.get_name (| globals, "value" |) @@ -565,7 +370,6 @@ Definition trie_get : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition common_prefix_length : Value.t -> Value.t -> M := @@ -588,28 +392,6 @@ Definition common_prefix_length : Value.t -> Value.t -> M := make_dict [] |) do let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| M.get_name (| globals, "i" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "b" |) - ], - make_dict [] - |) |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "i" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -621,7 +403,6 @@ Definition common_prefix_length : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition nibble_list_to_compact : Value.t -> Value.t -> M := @@ -667,68 +448,6 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| BinOp.mod_ (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |), - Constant.int 2 - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_name (| globals, "compact" |), "append" |), - make_list [ - BinOp.mult (| - Constant.int 16, - BinOp.mult (| - Constant.int 2, - M.get_name (| globals, "is_leaf" |) - |) - |) - ], - make_dict [] - |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 0; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |); - Constant.int 2 - ], - make_dict [] - |) do - let _ := M.call (| - M.get_field (| M.get_name (| globals, "compact" |), "append" |), - make_list [ - BinOp.add (| - BinOp.mult (| - Constant.int 16, - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) - |), - M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) - |) - ], - make_dict [] - |) in - EndFor. - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ @@ -790,7 +509,6 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition bytes_to_nibble_list : Value.t -> Value.t -> M := @@ -868,7 +586,6 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition _prepare_trie : Value.t -> Value.t -> M := @@ -898,45 +615,6 @@ Definition _prepare_trie : Value.t -> Value.t -> M := make_dict [] |) do let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "value" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in - let address := - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in - let encoded_value := - M.call (| - M.get_name (| globals, "encode_node" |), - make_list [ - M.get_name (| globals, "value" |); - M.call (| - M.get_name (| globals, "get_storage_root" |), - make_list [ - M.get_name (| globals, "address" |) - ], - make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let encoded_value := M.call (| M.get_name (| globals, "encode_node" |), @@ -950,29 +628,16 @@ Definition _prepare_trie : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.not_eq (| M.get_name (| globals, "encoded_value" |), (* At constant: unsupported node type: Constant *) |); + Compare.not_eq (| + M.get_name (| globals, "encoded_value" |), + Constant.bytes "" + |); M.get_name (| globals, "AssertionError" |) ], make_dict [] |) in (* At stmt: unsupported node type: AnnAssign *) let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "trie" |), "secured" |), - (* then *) - ltac:(M.monadic ( - let key := - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let key := M.get_name (| globals, "preimage" |) in M.pure Constant.None_ @@ -990,7 +655,6 @@ Definition _prepare_trie : Value.t -> Value.t -> M := EndFor. let _ := M.return_ (| M.get_name (| globals, "mapped" |) - |) in M.pure Constant.None_)). Definition root : Value.t -> Value.t -> M := @@ -1044,41 +708,6 @@ Definition root : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "root_node" |) - ], - make_dict [] - |) - ], - make_dict [] - |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), - make_list [ - M.get_name (| globals, "root_node" |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -1095,7 +724,6 @@ Definition root : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -1122,23 +750,6 @@ Definition patricialize : Value.t -> Value.t -> M := Root node of `obj`. " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "obj" |) - ], - make_dict [] - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.None_ - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let arbitrary_key := @@ -1156,36 +767,10 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "obj" |) - ], - make_dict [] - |), Constant.int 1 |), - (* then *) - ltac:(M.monadic ( - let leaf := - M.call (| - M.get_name (| globals, "LeafNode" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |); - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) - ], - make_dict [] - |) in - let _ := M.return_ (| - M.get_name (| globals, "leaf" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let substring := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |) |) in let prefix_length := M.call (| M.get_name (| globals, "len" |), @@ -1204,7 +789,7 @@ Definition patricialize : Value.t -> Value.t -> M := M.get_name (| globals, "common_prefix_length" |), make_list [ M.get_name (| globals, "substring" |); - M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |):(* At expr: unsupported node type: NoneType *) |) + M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) ], make_dict [] |) @@ -1212,58 +797,10 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.break (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "prefix_length" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let prefix := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |):BinOp.add (| - M.get_name (| globals, "level" |), - M.get_name (| globals, "prefix_length" |) - |) |) in - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "ExtensionNode" |), - make_list [ - M.get_name (| globals, "prefix" |); - M.call (| - M.get_name (| globals, "encode_internal_node" |), - make_list [ - M.call (| - M.get_name (| globals, "patricialize" |), - make_list [ - M.get_name (| globals, "obj" |); - BinOp.add (| - M.get_name (| globals, "level" |), - M.get_name (| globals, "prefix_length" |) - |) - ], - make_dict [] - |) - ], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) @@ -1283,44 +820,9 @@ Definition patricialize : Value.t -> Value.t -> M := |) in EndFor. let value := - (* At constant: unsupported node type: Constant *) in + Constant.bytes "" in For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "key" |) - ], - make_dict [] - |), M.get_name (| globals, "level" |) |), - (* then *) - ltac:(M.monadic ( - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); - make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "AssertionError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let value := - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) @@ -1332,26 +834,9 @@ Definition patricialize : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "BranchNode" |), make_list [ - [M.call (| - M.get_name (| globals, "encode_internal_node" |), - make_list [ - M.call (| - M.get_name (| globals, "patricialize" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "branches" |), M.get_name (| globals, "k" |) |); - BinOp.add (| - M.get_name (| globals, "level" |), - Constant.int 1 - |) - ], - make_dict [] - |) - ], - make_dict [] - |) for (* At expr: unsupported node type: list *)]; + (* At expr: unsupported node type: ListComp *); M.get_name (| globals, "value" |) ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/utils/address.v b/CoqOfPython/ethereum/tangerine_whistle/utils/address.v index a9446a6..a703595 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/utils/address.v +++ b/CoqOfPython/ethereum/tangerine_whistle/utils/address.v @@ -68,11 +68,10 @@ Definition to_address : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), make_list [], make_dict [] - |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) + |), UnOp.sub (| Constant.int 20 |) |) ], make_dict [] |) - |) in M.pure Constant.None_)). Definition compute_contract_address : Value.t -> Value.t -> M := @@ -112,7 +111,7 @@ Definition compute_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |):(* At expr: unsupported node type: NoneType *) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -130,5 +129,4 @@ Definition compute_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/utils/hexadecimal.v b/CoqOfPython/ethereum/tangerine_whistle/utils/hexadecimal.v index b6cbc45..5a965f6 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/tangerine_whistle/utils/hexadecimal.v @@ -66,7 +66,6 @@ Definition hex_to_root : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition hex_to_bloom : Value.t -> Value.t -> M := @@ -105,7 +104,6 @@ Definition hex_to_bloom : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition hex_to_address : Value.t -> Value.t -> M := @@ -151,5 +149,4 @@ Definition hex_to_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/utils/message.v b/CoqOfPython/ethereum/tangerine_whistle/utils/message.v index e687ac9..f714b67 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/utils/message.v +++ b/CoqOfPython/ethereum/tangerine_whistle/utils/message.v @@ -85,105 +85,14 @@ Definition prepare_message : Value.t -> Value.t -> M := Items containing contract creation or message call specific data. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "target" |); - M.get_name (| globals, "Bytes0" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let current_target := - M.call (| - M.get_name (| globals, "compute_contract_address" |), - make_list [ - M.get_name (| globals, "caller" |); - BinOp.sub (| - M.get_field (| M.call (| - M.get_name (| globals, "get_account" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "caller" |) - ], - make_dict [] - |), "nonce" |), - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 1 - ], - make_dict [] - |) - |) - ], - make_dict [] - |) in - let msg_data := - M.call (| - M.get_name (| globals, "Bytes" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |) in - let code := - M.get_name (| globals, "data" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "target" |); - M.get_name (| globals, "Address" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let current_target := - M.get_name (| globals, "target" |) in - let msg_data := - M.get_name (| globals, "data" |) in - let code := - M.get_field (| M.call (| - M.get_name (| globals, "get_account" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "target" |) - ], - make_dict [] - |), "code" |) in - let _ := - (* if *) - M.if_then_else (| - Compare.is (| M.get_name (| globals, "code_address" |), Constant.None_ |), - (* then *) - ltac:(M.monadic ( - let code_address := - M.get_name (| globals, "target" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.raise (| M.call (| + let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "Target must be address or empty bytes" ], make_dict [] - |) |) in + |)) M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -194,5 +103,4 @@ Definition prepare_message : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/gas.v b/CoqOfPython/ethereum/tangerine_whistle/vm/gas.v new file mode 100644 index 0000000..fddc9b4 --- /dev/null +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/gas.v @@ -0,0 +1,801 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) Gas +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +EVM gas constants and calculators. +". + +Require dataclasses. +Axiom dataclasses_dataclass : + IsGlobalAlias globals dataclasses.globals "dataclass". + +Require typing. +Axiom typing_List : + IsGlobalAlias globals typing.globals "List". +Axiom typing_Tuple : + IsGlobalAlias globals typing.globals "Tuple". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.trace. +Axiom ethereum_trace_GasAndRefund : + IsGlobalAlias globals ethereum.trace.globals "GasAndRefund". +Axiom ethereum_trace_evm_trace : + IsGlobalAlias globals ethereum.trace.globals "evm_trace". + +Require ethereum.utils.numeric. +Axiom ethereum_utils_numeric_ceil32 : + IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". + +Require exceptions. +Axiom exceptions_OutOfGasError : + IsGlobalAlias globals exceptions.globals "OutOfGasError". + +Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) +)). + +Definition GAS_BASE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 2 + ], + make_dict [] + |) +)). + +Definition GAS_VERY_LOW : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_SLOAD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 200 + ], + make_dict [] + |) +)). + +Definition GAS_STORAGE_SET : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 20000 + ], + make_dict [] + |) +)). + +Definition GAS_STORAGE_UPDATE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5000 + ], + make_dict [] + |) +)). + +Definition GAS_STORAGE_CLEAR_REFUND : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 15000 + ], + make_dict [] + |) +)). + +Definition GAS_LOW : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5 + ], + make_dict [] + |) +)). + +Definition GAS_MID : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 8 + ], + make_dict [] + |) +)). + +Definition GAS_HIGH : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 10 + ], + make_dict [] + |) +)). + +Definition GAS_EXPONENTIATION : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 10 + ], + make_dict [] + |) +)). + +Definition GAS_EXPONENTIATION_PER_BYTE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 10 + ], + make_dict [] + |) +)). + +Definition GAS_MEMORY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_KECCAK256 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 30 + ], + make_dict [] + |) +)). + +Definition GAS_KECCAK256_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 6 + ], + make_dict [] + |) +)). + +Definition GAS_COPY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition GAS_BLOCK_HASH : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 20 + ], + make_dict [] + |) +)). + +Definition GAS_EXTERNAL : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 700 + ], + make_dict [] + |) +)). + +Definition GAS_BALANCE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 400 + ], + make_dict [] + |) +)). + +Definition GAS_LOG : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 375 + ], + make_dict [] + |) +)). + +Definition GAS_LOG_DATA : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 8 + ], + make_dict [] + |) +)). + +Definition GAS_LOG_TOPIC : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 375 + ], + make_dict [] + |) +)). + +Definition GAS_CREATE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 32000 + ], + make_dict [] + |) +)). + +Definition GAS_CODE_DEPOSIT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 200 + ], + make_dict [] + |) +)). + +Definition GAS_ZERO : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) +)). + +Definition GAS_CALL : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 700 + ], + make_dict [] + |) +)). + +Definition GAS_NEW_ACCOUNT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 25000 + ], + make_dict [] + |) +)). + +Definition GAS_CALL_VALUE : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 9000 + ], + make_dict [] + |) +)). + +Definition GAS_CALL_STIPEND : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 2300 + ], + make_dict [] + |) +)). + +Definition GAS_SELF_DESTRUCT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 5000 + ], + make_dict [] + |) +)). + +Definition GAS_SELF_DESTRUCT_NEW_ACCOUNT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 25000 + ], + make_dict [] + |) +)). + +Definition REFUND_SELF_DESTRUCT : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 24000 + ], + make_dict [] + |) +)). + +Definition GAS_ECRECOVER : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3000 + ], + make_dict [] + |) +)). + +Definition GAS_SHA256 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 60 + ], + make_dict [] + |) +)). + +Definition GAS_SHA256_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 12 + ], + make_dict [] + |) +)). + +Definition GAS_RIPEMD160 : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 600 + ], + make_dict [] + |) +)). + +Definition GAS_RIPEMD160_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 120 + ], + make_dict [] + |) +)). + +Definition GAS_IDENTITY : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 15 + ], + make_dict [] + |) +)). + +Definition GAS_IDENTITY_WORD : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |) +)). + +Definition ExtendMemory : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition MessageCallGas : Value.t := + builtins.make_klass + [] + [ + + ] + [ + + ]. + +Definition charge_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "amount" ] |) in + let _ := Constant.str " + Subtracts `amount` from `evm.gas_left`. + + Parameters + ---------- + evm : + The current EVM. + amount : + The amount of gas the current operation requires. + + " in + let _ := M.call (| + M.get_name (| globals, "evm_trace" |), + make_list [ + M.get_name (| globals, "evm" |); + M.call (| + M.get_name (| globals, "GasAndRefund" |), + make_list [ + M.get_name (| globals, "amount" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + let _ := M.assign_op (| + BinOp.sub, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.get_name (| globals, "amount" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition calculate_memory_gas_cost : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "size_in_bytes" ] |) in + let _ := Constant.str " + Calculates the gas cost for allocating memory + to the smallest multiple of 32 bytes, + such that the allocated size is at least as big as the given size. + + Parameters + ---------- + size_in_bytes : + The size of the data in bytes. + + Returns + ------- + total_gas_cost : `ethereum.base_types.Uint` + The gas cost for storing data in memory. + " in + let size_in_words := + BinOp.floor_div (| + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "size_in_bytes" |) + ], + make_dict [] + |), + Constant.int 32 + |) in + let linear_cost := + BinOp.mult (| + M.get_name (| globals, "size_in_words" |), + M.get_name (| globals, "GAS_MEMORY" |) + |) in + let quadratic_cost := + BinOp.floor_div (| + BinOp.pow (| + M.get_name (| globals, "size_in_words" |), + Constant.int 2 + |), + Constant.int 512 + |) in + let total_gas_cost := + BinOp.add (| + M.get_name (| globals, "linear_cost" |), + M.get_name (| globals, "quadratic_cost" |) + |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_)). + +Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "memory"; "extensions" ] |) in + let _ := Constant.str " + Calculates the gas amount to extend memory + + Parameters + ---------- + memory : + Memory contents of the EVM. + extensions: + List of extensions to be made to the memory. + Consists of a tuple of start position and size. + + Returns + ------- + extend_memory: `ExtendMemory` + " in + let size_to_extend := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let to_be_paid := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let current_size := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "memory" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + For make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ] in M.get_name (| globals, "extensions" |) do + let _ := + M.pure Constant.None_ + )) |) in + let before_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "current_size" |) + ], + make_dict [] + |) in + let after_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let size_to_extend := BinOp.add + BinOp.sub (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |) + BinOp.sub (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |) in + let already_paid := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "before_size" |) + ], + make_dict [] + |) in + let total_cost := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "after_size" |) + ], + make_dict [] + |) in + let to_be_paid := BinOp.add + BinOp.sub (| + M.get_name (| globals, "total_cost" |), + M.get_name (| globals, "already_paid" |) + |) + BinOp.sub (| + M.get_name (| globals, "total_cost" |), + M.get_name (| globals, "already_paid" |) + |) in + let current_size := + M.get_name (| globals, "after_size" |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ExtendMemory" |), + make_list [ + M.get_name (| globals, "to_be_paid" |); + M.get_name (| globals, "size_to_extend" |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition calculate_message_call_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "value"; "gas"; "gas_left"; "memory_cost"; "extra_gas"; "call_stipend" ] |) in + let _ := Constant.str " + Calculates the MessageCallGas (cost and stipend) for + executing call Opcodes. + + Parameters + ---------- + value: + The amount of `ETH` that needs to be transferred. + gas : + The amount of gas provided to the message-call. + gas_left : + The amount of gas left in the current frame. + memory_cost : + The amount needed to extend the memory in the current frame. + extra_gas : + The amount of gas needed for transferring value + creating a new + account inside a message call. + call_stipend : + The amount of stipend provided to a message call to execute code while + transferring value(ETH). + + Returns + ------- + message_call_gas: `MessageCallGas` + " in + let call_stipend := + (* if *) +M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let _ := + M.pure Constant.None_ + )) |) in + let gas := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "max_message_call_gas" |), + make_list [ + BinOp.sub (| + BinOp.sub (| + M.get_name (| globals, "gas_left" |), + M.get_name (| globals, "memory_cost" |) + |), + M.get_name (| globals, "extra_gas" |) + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallGas" |), + make_list [ + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "extra_gas" |) + |); + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "call_stipend" |) + |) + ], + make_dict [] + |) + M.pure Constant.None_)). + +Definition max_message_call_gas : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "gas" ] |) in + let _ := Constant.str " + Calculates the maximum gas that is allowed for making a message call + + Parameters + ---------- + gas : + The amount of gas provided to the message-call. + + Returns + ------- + max_allowed_message_call_gas: `ethereum.base_types.Uint` + The maximum gas allowed for making the message-call. + " in + let _ := M.return_ (| + BinOp.sub (| + M.get_name (| globals, "gas" |), + BinOp.floor_div (| + M.get_name (| globals, "gas" |), + Constant.int 64 + |) + |) + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/arithmetic.v index a8b5c61..581ba5d 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/arithmetic.v @@ -273,22 +273,6 @@ Definition div : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let quotient := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let quotient := BinOp.floor_div (| M.get_name (| globals, "dividend" |), @@ -357,32 +341,7 @@ Definition sdiv : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "divisor" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let quotient := - Constant.int 0 in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_name (| globals, "dividend" |), UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "divisor" |), UnOp.sub (| Constant.int 1 |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let quotient := - UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let sign := M.call (| M.get_name (| globals, "get_sign" |), @@ -477,22 +436,6 @@ Definition mod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let remainder := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let remainder := BinOp.mod_ (| M.get_name (| globals, "x" |), @@ -561,16 +504,6 @@ Definition smod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "y" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let remainder := - Constant.int 0 in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let remainder := BinOp.mult (| M.call (| @@ -684,22 +617,6 @@ Definition addmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -795,22 +712,6 @@ Definition mulmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "z" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -980,16 +881,6 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_name (| globals, "byte_num" |), Constant.int 31 |), - (* then *) - ltac:(M.monadic ( - let result := - M.get_name (| globals, "value" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let value_bytes := M.call (| M.get_name (| globals, "bytes" |), @@ -1012,29 +903,13 @@ Definition signextend : Value.t -> Value.t -> M := ], make_dict [] |) - |):(* At expr: unsupported node type: NoneType *) |) in + |) |) in let sign_bit := BinOp.r_shift (| M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), Constant.int 7 |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "sign_bit" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), - make_list [ - M.get_name (| globals, "value_bytes" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let num_bytes_prepend := BinOp.sub (| Constant.int 32, diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/bitwise.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/bitwise.v index b20a1e5..f38e7aa 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/bitwise.v @@ -285,22 +285,6 @@ Definition get_byte : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| M.get_name (| globals, "byte_index" |), Constant.int 32 |), - (* then *) - ltac:(M.monadic ( - let result := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let extra_bytes_to_right := BinOp.sub (| Constant.int 31, diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/block.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/block.v index e5fa554..90be45c 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/block.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/block.v @@ -69,24 +69,6 @@ Definition block_hash : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.lt_e (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), M.get_name (| globals, "block_number" |) |), - ltac:(M.monadic ( - Compare.gt (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), BinOp.add (| - M.get_name (| globals, "block_number" |), - Constant.int 256 - |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let hash := - (* At constant: unsupported node type: Constant *) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let hash := M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/comparison.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/comparison.v index fbc35f8..b8529d8 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/comparison.v @@ -78,7 +78,10 @@ Definition less_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.lt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -145,7 +148,10 @@ Definition signed_less_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.lt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.lt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -205,7 +211,10 @@ Definition greater_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.gt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -272,7 +281,10 @@ Definition signed_greater_than : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.gt (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.gt (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -332,7 +344,10 @@ Definition equal : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.eq (| M.get_name (| globals, "left" |), M.get_name (| globals, "right" |) |) + Compare.eq (| + M.get_name (| globals, "left" |), + M.get_name (| globals, "right" |) + |) ], make_dict [] |) in @@ -384,7 +399,10 @@ Definition is_zero : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "U256" |), make_list [ - Compare.eq (| M.get_name (| globals, "x" |), Constant.int 0 |) + Compare.eq (| + M.get_name (| globals, "x" |), + Constant.int 0 + |) ], make_dict [] |) in diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/control_flow.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/control_flow.v index 04a79d9..d4e4eae 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/control_flow.v @@ -109,15 +109,6 @@ Definition jump : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -177,29 +168,7 @@ Definition jumpi : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "conditional_value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let destination := - BinOp.add (| - M.get_field (| M.get_name (| globals, "evm" |), "pc" |), - Constant.int 1 - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - Compare.not_in (| M.get_name (| globals, "jump_dest" |), M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "InvalidJumpDestError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let destination := M.get_name (| globals, "jump_dest" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/environment.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/environment.v index 4d26a46..366e59a 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/environment.v @@ -492,7 +492,7 @@ Definition calldatacopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -660,7 +660,7 @@ Definition codecopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -903,7 +903,7 @@ Definition extcodecopy : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/keccak.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/keccak.v index cab9ffb..2c4b10e 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/keccak.v @@ -137,7 +137,7 @@ Definition keccak : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/log.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/log.v index f246f9d..ab196bc 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/log.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/log.v @@ -153,7 +153,7 @@ Definition log_n : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/memory.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/memory.v index 1e1c8b0..86ba742 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/memory.v @@ -121,7 +121,7 @@ Definition mstore : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -203,7 +203,7 @@ Definition mstore8 : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in @@ -288,7 +288,7 @@ Definition mload : Value.t -> Value.t -> M := BinOp.add, M.get_field (| M.get_name (| globals, "evm" |), "memory" |), BinOp.mult (| - (* At constant: unsupported node type: Constant *), + Constant.bytes "00", M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/stack.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/stack.v index 1eeda05..305af15 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/stack.v @@ -188,13 +188,16 @@ Definition dup_n : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] - |) |); + Compare.lt (| + M.get_name (| globals, "item_number" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + |); M.get_name (| globals, "StackUnderflowError" |) ], make_dict [] @@ -260,13 +263,16 @@ Definition swap_n : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.lt (| M.get_name (| globals, "item_number" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] - |) |); + Compare.lt (| + M.get_name (| globals, "item_number" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + |); M.get_name (| globals, "StackUnderflowError" |) ], make_dict [] diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/storage.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/storage.v index 4292e3b..5250214 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/storage.v @@ -146,44 +146,11 @@ Definition sstore : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "new_value" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let gas_cost := - M.get_name (| globals, "GAS_STORAGE_SET" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let gas_cost := M.get_name (| globals, "GAS_STORAGE_UPDATE" |) in M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.eq (| M.get_name (| globals, "new_value" |), Constant.int 0 |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_name (| globals, "current_value" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.assign_op (| - BinOp.add, - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), - M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/system.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/system.v new file mode 100644 index 0000000..8f94208 --- /dev/null +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/system.v @@ -0,0 +1,1119 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. + +Definition expr_1 : Value.t := + Constant.str " +Ethereum Virtual Machine (EVM) System Instructions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. contents:: Table of Contents + :backlinks: none + :local: + +Introduction +------------ + +Implementations of the EVM system related instructions. +". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require fork_types. +Axiom fork_types_Address : + IsGlobalAlias globals fork_types.globals "Address". + +Require state. +Axiom state_account_exists : + IsGlobalAlias globals state.globals "account_exists". +Axiom state_account_has_code_or_nonce : + IsGlobalAlias globals state.globals "account_has_code_or_nonce". +Axiom state_get_account : + IsGlobalAlias globals state.globals "get_account". +Axiom state_increment_nonce : + IsGlobalAlias globals state.globals "increment_nonce". +Axiom state_set_account_balance : + IsGlobalAlias globals state.globals "set_account_balance". + +Require utils.address. +Axiom utils_address_compute_contract_address : + IsGlobalAlias globals utils.address.globals "compute_contract_address". +Axiom utils_address_to_address : + IsGlobalAlias globals utils.address.globals "to_address". + +Require __init__. +Axiom __init___Evm : + IsGlobalAlias globals __init__.globals "Evm". +Axiom __init___Message : + IsGlobalAlias globals __init__.globals "Message". +Axiom __init___incorporate_child_on_error : + IsGlobalAlias globals __init__.globals "incorporate_child_on_error". +Axiom __init___incorporate_child_on_success : + IsGlobalAlias globals __init__.globals "incorporate_child_on_success". + +Require gas. +Axiom gas_GAS_CALL : + IsGlobalAlias globals gas.globals "GAS_CALL". +Axiom gas_GAS_CALL_VALUE : + IsGlobalAlias globals gas.globals "GAS_CALL_VALUE". +Axiom gas_GAS_CREATE : + IsGlobalAlias globals gas.globals "GAS_CREATE". +Axiom gas_GAS_NEW_ACCOUNT : + IsGlobalAlias globals gas.globals "GAS_NEW_ACCOUNT". +Axiom gas_GAS_SELF_DESTRUCT : + IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT". +Axiom gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : + IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". +Axiom gas_GAS_ZERO : + IsGlobalAlias globals gas.globals "GAS_ZERO". +Axiom gas_REFUND_SELF_DESTRUCT : + IsGlobalAlias globals gas.globals "REFUND_SELF_DESTRUCT". +Axiom gas_calculate_gas_extend_memory : + IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". +Axiom gas_calculate_message_call_gas : + IsGlobalAlias globals gas.globals "calculate_message_call_gas". +Axiom gas_charge_gas : + IsGlobalAlias globals gas.globals "charge_gas". +Axiom gas_max_message_call_gas : + IsGlobalAlias globals gas.globals "max_message_call_gas". + +Require memory. +Axiom memory_memory_read_bytes : + IsGlobalAlias globals memory.globals "memory_read_bytes". +Axiom memory_memory_write : + IsGlobalAlias globals memory.globals "memory_write". + +Require stack. +Axiom stack_pop : + IsGlobalAlias globals stack.globals "pop". +Axiom stack_push : + IsGlobalAlias globals stack.globals "push". + +Definition create : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Creates a new account with associated code. + + Parameters + ---------- + evm : + The current EVM frame. + " in +(* At stmt: unsupported node type: ImportFrom *) + let endowment := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_position" |); M.get_name (| globals, "memory_size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_CREATE" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let create_message_gas := + M.call (| + M.get_name (| globals, "max_message_call_gas" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.sub, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "create_message_gas" |) + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let sender_address := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in + let sender := + M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "sender_address" |) + ], + make_dict [] + |) in + let contract_address := + M.call (| + M.get_name (| globals, "compute_contract_address" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "nonce" |) + ], + make_dict [] + |) in + let _ := + let _ := + let call_data := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + let child_message := + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) in + let child_evm := + M.call (| + M.get_name (| globals, "process_create_message" |), + make_list [ + M.get_name (| globals, "child_message" |); + M.get_field (| M.get_name (| globals, "evm" |), "env" |) + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_success" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition return_ : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Halts execution returning output data. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let memory_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_start_position" |); M.get_name (| globals, "memory_size" |) ] + ] + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_name (| globals, "GAS_ZERO" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_start_position" |); + M.get_name (| globals, "memory_size" |) + ], + make_dict [] + |) + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "running" |), + Constant.bool false + |) in + let _ := M.pass (| |) in + M.pure Constant.None_)). + +Definition generic_call : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm"; "gas"; "value"; "caller"; "to"; "code_address"; "should_transfer_value"; "memory_input_start_position"; "memory_input_size"; "memory_output_start_position"; "memory_output_size" ] |) in + let _ := Constant.str " + Perform the core logic of the `CALL*` family of opcodes. + " in +(* At stmt: unsupported node type: ImportFrom *) + let _ := + M.pure Constant.None_ + )) |) in + let call_data := + M.call (| + M.get_name (| globals, "memory_read_bytes" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |) + ], + make_dict [] + |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "code_address" |) + ], + make_dict [] + |), "code" |) in + let child_message := + M.call (| + M.get_name (| globals, "Message" |), + make_list [], + make_dict [] + |) in + let child_evm := + M.call (| + M.get_name (| globals, "process_message" |), + make_list [ + M.get_name (| globals, "child_message" |); + M.get_field (| M.get_name (| globals, "evm" |), "env" |) + ], + make_dict [] + |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_success" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let actual_output_size := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_name (| globals, "memory_output_size" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "memory_write" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), Constant.None_:M.get_name (| globals, "actual_output_size" |) |) + ], + make_dict [] + |) in + M.pure Constant.None_)). + +Definition call : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into an account. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let to := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let _account_exists := + M.call (| + M.get_name (| globals, "account_exists" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "to" |) + ], + make_dict [] + |) in + let create_gas_cost := + (* if *) +M.if_then_else (| + M.get_name (| globals, "_account_exists" |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let transfer_gas_cost := + (* if *) +M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_CALL" |), + M.get_name (| globals, "create_gas_cost" |) + |), + M.get_name (| globals, "transfer_gas_cost" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let sender_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.get_name (| globals, "value" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "to" |); + Constant.bool true; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition callcode : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into this account with alternative account’s code. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let code_address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let value := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let to := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let transfer_gas_cost := + (* if *) +M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), +(* then *) +ltac:(M.monadic ( +M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + BinOp.add (| + M.get_name (| globals, "GAS_CALL" |), + M.get_name (| globals, "transfer_gas_cost" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let sender_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |) in + let _ := + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.get_name (| globals, "value" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "to" |); + M.get_name (| globals, "code_address" |); + Constant.bool true; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). + +Definition selfdestruct : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Halt execution and register account for later deletion. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let beneficiary := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let gas_cost := + M.get_name (| globals, "GAS_SELF_DESTRUCT" |) in + let _ := + M.pure Constant.None_ + )) |) in + let originator := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in + let refunded_accounts := + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in + let parent_evm := + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "parent_evm" |) in + While Compare.is_not (| + M.get_name (| globals, "parent_evm" |), + Constant.None_ + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "refunded_accounts" |), "update" |), + make_list [ + M.get_field (| M.get_name (| globals, "parent_evm" |), "accounts_to_delete" |) + ], + make_dict [] + |) in + let parent_evm := + M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in + EndWhile. + let _ := + M.pure Constant.None_ + )) |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "gas_cost" |) + ], + make_dict [] + |) in + let beneficiary_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |), "balance" |) in + let originator_balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "originator" |) + ], + make_dict [] + |), "balance" |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |); + BinOp.add (| + M.get_name (| globals, "beneficiary_balance" |), + M.get_name (| globals, "originator_balance" |) + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "originator" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |), "add" |), + make_list [ + M.get_name (| globals, "originator" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "running" |), + Constant.bool false + |) in + let _ := M.pass (| |) in + M.pure Constant.None_)). + +Definition delegatecall : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in + let _ := Constant.str " + Message-call into an account. + + Parameters + ---------- + evm : + The current EVM frame. + " in + let gas := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let code_address := + M.call (| + M.get_name (| globals, "to_address" |), + make_list [ + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + let memory_input_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_input_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_start_position := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let memory_output_size := + M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |) in + let extend_memory := + M.call (| + M.get_name (| globals, "calculate_gas_extend_memory" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "memory" |); + make_list [ + make_tuple [ M.get_name (| globals, "memory_input_start_position" |); M.get_name (| globals, "memory_input_size" |) ]; + make_tuple [ M.get_name (| globals, "memory_output_start_position" |); M.get_name (| globals, "memory_output_size" |) ] + ] + ], + make_dict [] + |) in + let message_call_gas := + M.call (| + M.get_name (| globals, "calculate_message_call_gas" |), + make_list [ + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.get_name (| globals, "gas" |); + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + ], + make_dict [] + |); + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |); + M.get_name (| globals, "GAS_CALL" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + M.get_field (| M.get_name (| globals, "message_call_gas" |), "cost" |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "memory" |), + BinOp.mult (| + Constant.bytes "00", + M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) + |) + |) in + let _ := M.call (| + M.get_name (| globals, "generic_call" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "value" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "caller" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); + M.get_name (| globals, "code_address" |); + Constant.bool false; + M.get_name (| globals, "memory_input_start_position" |); + M.get_name (| globals, "memory_input_size" |); + M.get_name (| globals, "memory_output_start_position" |); + M.get_name (| globals, "memory_output_size" |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/interpreter.v b/CoqOfPython/ethereum/tangerine_whistle/vm/interpreter.v index 2aa7a4c..d8dd02b 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/interpreter.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/interpreter.v @@ -162,86 +162,6 @@ Definition process_message_call : Value.t -> Value.t -> M := Output of the message call " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_field (| M.get_name (| globals, "message" |), "target" |), M.call (| - M.get_name (| globals, "Bytes0" |), - make_list [ - (* At constant: unsupported node type: Constant *) - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let is_collision := - M.call (| - M.get_name (| globals, "account_has_code_or_nonce" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_field (| M.get_name (| globals, "message" |), "current_target" |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - M.get_name (| globals, "is_collision" |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "MessageCallOutput" |), - make_list [ - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |); - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |); - M.call (| - M.get_name (| globals, "tuple" |), - make_list [], - make_dict [] - |); - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |); - M.call (| - M.get_name (| globals, "AddressCollision" |), - make_list [], - make_dict [] - |) - ], - make_dict [] - |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let evm := - M.call (| - M.get_name (| globals, "process_create_message" |), - make_list [ - M.get_name (| globals, "message" |); - M.get_name (| globals, "env" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let evm := M.call (| M.get_name (| globals, "process_message" |), @@ -254,29 +174,6 @@ Definition process_message_call : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "evm" |), "error" |), - (* then *) - ltac:(M.monadic ( -(* At stmt: unsupported node type: AnnAssign *) - let accounts_to_delete := - M.call (| - M.get_name (| globals, "set" |), - make_list [], - make_dict [] - |) in - let refund_counter := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let logs := M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in let accounts_to_delete := @@ -312,7 +209,6 @@ Definition process_message_call : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). Definition process_create_message : Value.t -> Value.t -> M := @@ -358,28 +254,6 @@ Definition process_create_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), - (* then *) - ltac:(M.monadic ( - let contract_code := - M.get_field (| M.get_name (| globals, "evm" |), "output" |) in - let contract_code_gas := - BinOp.mult (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "contract_code" |) - ], - make_dict [] - |), - M.get_name (| globals, "GAS_CODE_DEPOSIT" |) - |) in -(* At stmt: unsupported node type: Try *) - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "rollback_transaction" |), make_list [ @@ -391,7 +265,6 @@ Definition process_create_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) - |) in M.pure Constant.None_)). Definition process_message : Value.t -> Value.t -> M := @@ -413,21 +286,6 @@ Definition process_message : Value.t -> Value.t -> M := Items containing execution specific objects " in let _ := - (* if *) - M.if_then_else (| - Compare.gt (| M.get_field (| M.get_name (| globals, "message" |), "depth" |), M.get_name (| globals, "STACK_DEPTH_LIMIT" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.call (| - M.get_name (| globals, "StackDepthLimitError" |), - make_list [ - Constant.str "Stack depth limit reached" - ], - make_dict [] - |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -446,29 +304,6 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - M.get_field (| M.get_name (| globals, "message" |), "should_transfer_value" |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_field (| M.get_name (| globals, "message" |), "value" |), Constant.int 0 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "move_ether" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_field (| M.get_name (| globals, "message" |), "caller" |); - M.get_field (| M.get_name (| globals, "message" |), "current_target" |); - M.get_field (| M.get_name (| globals, "message" |), "value" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let evm := @@ -481,21 +316,6 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "evm" |), "error" |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_name (| globals, "rollback_transaction" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "commit_transaction" |), make_list [ @@ -507,7 +327,6 @@ Definition process_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) - |) in M.pure Constant.None_)). Definition execute_code : Value.t -> Value.t -> M := @@ -547,5 +366,4 @@ Definition execute_code : Value.t -> Value.t -> M := (* At stmt: unsupported node type: Try *) let _ := M.return_ (| M.get_name (| globals, "evm" |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/memory.v b/CoqOfPython/ethereum/tangerine_whistle/vm/memory.v index fa8d906..4b107fd 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/memory.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/memory.v @@ -45,22 +45,7 @@ Definition memory_write : Value.t -> Value.t -> M := Data to write to memory. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) - |) |), + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_)). @@ -86,23 +71,7 @@ Definition memory_read_bytes : Value.t -> Value.t -> M := Data read from memory. " in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |) - |) in + M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |) M.pure Constant.None_)). Definition buffer_read : Value.t -> Value.t -> M := @@ -129,25 +98,9 @@ Definition buffer_read : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "right_pad_zero_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |):BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |); + M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |) |); M.get_name (| globals, "size" |) ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/ecrecover.v index cc351b5..0cbcf16 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/ecrecover.v @@ -188,60 +188,12 @@ Definition ecrecover : Value.t -> Value.t -> M := make_dict [] |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 27 |), - ltac:(M.monadic ( - Compare.not_eq (| M.get_name (| globals, "v" |), Constant.int 28 |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| Constant.int 0, M.get_name (| globals, "r" |) |), - ltac:(M.monadic ( - Compare.gt_e (| M.get_name (| globals, "r" |), M.get_name (| globals, "SECP256K1N" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| Constant.int 0, M.get_name (| globals, "s" |) |), - ltac:(M.monadic ( - Compare.gt_e (| M.get_name (| globals, "s" |), M.get_name (| globals, "SECP256K1N" |) |) - )) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: Try *) @@ -252,7 +204,7 @@ Definition ecrecover : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12:Constant.int 32 |) in + |), Constant.int 12 |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/runtime.v b/CoqOfPython/ethereum/tangerine_whistle/vm/runtime.v index 835b46c..2cd7652 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/runtime.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/runtime.v @@ -67,50 +67,19 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := ], make_dict [] |) in - While Compare.lt (| M.get_name (| globals, "pc" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "code" |) - ], - make_dict [] - |) |) do + While Compare.lt (| + M.get_name (| globals, "pc" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) + |) do (* At stmt: unsupported node type: Try *) let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "current_opcode" |), M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), - make_list [ - M.get_name (| globals, "pc" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - (* At expr: unsupported node type: Compare *), - (* then *) - ltac:(M.monadic ( - let push_data_size := - BinOp.add (| - BinOp.sub (| - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) - |), - Constant.int 1 - |) in - let pc := BinOp.add - M.get_name (| globals, "push_data_size" |) - M.get_name (| globals, "push_data_size" |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -121,5 +90,4 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := EndWhile. let _ := M.return_ (| M.get_name (| globals, "valid_jump_destinations" |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/stack.v b/CoqOfPython/ethereum/tangerine_whistle/vm/stack.v index 42ea42d..ea778df 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/stack.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/stack.v @@ -49,21 +49,6 @@ Definition pop : Value.t -> Value.t -> M := " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "stack" |) - ], - make_dict [] - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "StackUnderflowError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -72,7 +57,6 @@ Definition pop : Value.t -> Value.t -> M := make_list [], make_dict [] |) - |) in M.pure Constant.None_)). Definition push : Value.t -> Value.t -> M := @@ -91,21 +75,6 @@ Definition push : Value.t -> Value.t -> M := " in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "stack" |) - ], - make_dict [] - |), Constant.int 1024 |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| M.get_name (| globals, "StackOverflowError" |) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -116,5 +85,4 @@ Definition push : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/utils/byte.v b/CoqOfPython/ethereum/utils/byte.v index cdd16e1..e2af2e7 100644 --- a/CoqOfPython/ethereum/utils/byte.v +++ b/CoqOfPython/ethereum/utils/byte.v @@ -44,11 +44,10 @@ Definition left_pad_zero_bytes : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "value" |), "rjust" |), make_list [ M.get_name (| globals, "size" |); - (* At constant: unsupported node type: Constant *) + Constant.bytes "00" ], make_dict [] |) - |) in M.pure Constant.None_)). Definition right_pad_zero_bytes : Value.t -> Value.t -> M := @@ -74,9 +73,8 @@ Definition right_pad_zero_bytes : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "value" |), "ljust" |), make_list [ M.get_name (| globals, "size" |); - (* At constant: unsupported node type: Constant *) + Constant.bytes "00" ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/utils/ensure.v b/CoqOfPython/ethereum/utils/ensure.v index 4b8b1d8..6c42595 100644 --- a/CoqOfPython/ethereum/utils/ensure.v +++ b/CoqOfPython/ethereum/utils/ensure.v @@ -40,18 +40,7 @@ Definition ensure : Value.t -> Value.t -> M := Constructor for the exception to raise. " in let _ := - (* if *) - M.if_then_else (| - M.get_name (| globals, "value" |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - (* At expr: unsupported node type: NoneType *) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let _ := M.raise (| M.get_name (| globals, "exception" |) |) in + let _ := M.raise (| Some(M.get_name (| globals, "exception" |)) M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/utils/hexadecimal.v b/CoqOfPython/ethereum/utils/hexadecimal.v index 91ec2bc..ed68a01 100644 --- a/CoqOfPython/ethereum/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/utils/hexadecimal.v @@ -63,7 +63,6 @@ Definition has_hex_prefix : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition remove_hex_prefix : Value.t -> Value.t -> M := @@ -84,34 +83,10 @@ Definition remove_hex_prefix : Value.t -> Value.t -> M := The hexadecimal string with the 0x prefix removed if present. " in let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "has_hex_prefix" |), - make_list [ - M.get_name (| globals, "hex_string" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "hex_string" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - Constant.str "0x" - ], - make_dict [] - |):(* At expr: unsupported node type: NoneType *) |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| M.get_name (| globals, "hex_string" |) - |) in M.pure Constant.None_)). Definition hex_to_bytes : Value.t -> Value.t -> M := @@ -144,7 +119,6 @@ Definition hex_to_bytes : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition hex_to_bytes8 : Value.t -> Value.t -> M := @@ -190,7 +164,6 @@ Definition hex_to_bytes8 : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition hex_to_bytes20 : Value.t -> Value.t -> M := @@ -236,7 +209,6 @@ Definition hex_to_bytes20 : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition hex_to_bytes32 : Value.t -> Value.t -> M := @@ -282,7 +254,6 @@ Definition hex_to_bytes32 : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition hex_to_bytes256 : Value.t -> Value.t -> M := @@ -328,7 +299,6 @@ Definition hex_to_bytes256 : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition hex_to_hash : Value.t -> Value.t -> M := @@ -367,7 +337,6 @@ Definition hex_to_hash : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition hex_to_uint : Value.t -> Value.t -> M := @@ -407,7 +376,6 @@ Definition hex_to_uint : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition hex_to_u64 : Value.t -> Value.t -> M := @@ -447,7 +415,6 @@ Definition hex_to_u64 : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition hex_to_u256 : Value.t -> Value.t -> M := @@ -487,5 +454,4 @@ Definition hex_to_u256 : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/utils/numeric.v b/CoqOfPython/ethereum/utils/numeric.v index 6f209d8..d737980 100644 --- a/CoqOfPython/ethereum/utils/numeric.v +++ b/CoqOfPython/ethereum/utils/numeric.v @@ -47,32 +47,9 @@ Definition get_sign : Value.t -> Value.t -> M := The return value is based on math signum function. " in let _ := - (* if *) - M.if_then_else (| - Compare.lt (| M.get_name (| globals, "value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - UnOp.sub (| Constant.int 1 |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "value" |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.int 0 - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| Constant.int 1 - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -111,23 +88,6 @@ Definition ceil32 : Value.t -> Value.t -> M := M.get_name (| globals, "ceiling" |) |) in let _ := - (* if *) - M.if_then_else (| - Compare.eq (| M.get_name (| globals, "remainder" |), M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "value" |) - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( let _ := M.return_ (| BinOp.sub (| BinOp.add (| @@ -136,7 +96,6 @@ Definition ceil32 : Value.t -> Value.t -> M := |), M.get_name (| globals, "remainder" |) |) - |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -158,17 +117,6 @@ Definition is_prime : Value.t -> Value.t -> M := Boolean indicating if `number` is prime or not. " in let _ := - (* if *) - M.if_then_else (| - Compare.lt_e (| M.get_name (| globals, "number" |), Constant.int 1 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.bool false - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in For M.get_name (| globals, "x" |) in M.call (| @@ -192,26 +140,11 @@ Definition is_prime : Value.t -> Value.t -> M := make_dict [] |) do let _ := - (* if *) - M.if_then_else (| - Compare.eq (| BinOp.mod_ (| - M.get_name (| globals, "number" |), - M.get_name (| globals, "x" |) - |), Constant.int 0 |), - (* then *) - ltac:(M.monadic ( - let _ := M.return_ (| - Constant.bool false - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := M.return_ (| Constant.bool true - |) in M.pure Constant.None_)). Definition le_bytes_to_uint32_sequence : Value.t -> Value.t -> M := @@ -257,10 +190,7 @@ Definition le_bytes_to_uint32_sequence : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "U32" |), "from_le_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "data" |), M.get_name (| globals, "i" |):BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 4 - |) |) + M.get_subscript (| M.get_name (| globals, "data" |), M.get_name (| globals, "i" |) |) ], make_dict [] |) @@ -276,7 +206,6 @@ Definition le_bytes_to_uint32_sequence : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition le_uint32_sequence_to_bytes : Value.t -> Value.t -> M := @@ -307,7 +236,7 @@ Definition le_uint32_sequence_to_bytes : Value.t -> Value.t -> M := The byte stream obtained from the little endian U32 stream. " in let result_bytes := - (* At constant: unsupported node type: Constant *) in + Constant.bytes "" in For M.get_name (| globals, "item" |) in M.get_name (| globals, "sequence" |) do let result_bytes := BinOp.add M.call (| @@ -323,7 +252,6 @@ Definition le_uint32_sequence_to_bytes : Value.t -> Value.t -> M := EndFor. let _ := M.return_ (| M.get_name (| globals, "result_bytes" |) - |) in M.pure Constant.None_)). Definition le_uint32_sequence_to_uint : Value.t -> Value.t -> M := @@ -361,7 +289,6 @@ Definition le_uint32_sequence_to_uint : Value.t -> Value.t -> M := ], make_dict [] |) - |) in M.pure Constant.None_)). Definition taylor_exponential : Value.t -> Value.t -> M := @@ -395,7 +322,10 @@ Definition taylor_exponential : Value.t -> Value.t -> M := M.get_name (| globals, "factor" |), M.get_name (| globals, "denominator" |) |) in - While Compare.gt (| M.get_name (| globals, "numerator_accumulated" |), Constant.int 0 |) do + While Compare.gt (| + M.get_name (| globals, "numerator_accumulated" |), + Constant.int 0 + |) do let output := BinOp.add M.get_name (| globals, "numerator_accumulated" |) M.get_name (| globals, "numerator_accumulated" |) in @@ -419,5 +349,4 @@ Definition taylor_exponential : Value.t -> Value.t -> M := M.get_name (| globals, "output" |), M.get_name (| globals, "denominator" |) |) - |) in M.pure Constant.None_)). diff --git a/convert_all.py b/convert_all.py index e2f2122..6bd9380 100644 --- a/convert_all.py +++ b/convert_all.py @@ -10,8 +10,8 @@ if file.endswith(".py"): # convert the file full_path = root + "/" + file - # print("Converting file: " + full_path) short_path = full_path[(len(folder_to_convert) + 1):] + print("") print("Converting file: " + short_path) try: @@ -20,7 +20,7 @@ subprocess.run(command, shell=True, check=True) except subprocess.CalledProcessError as e: print(f"Error occurred: {e}") - # sys.exit(1) + sys.exit(1) except KeyboardInterrupt: print("Ctrl-C pressed, interrupting the script.") sys.exit(1) diff --git a/main.py b/main.py index 53334bd..707cdc4 100644 --- a/main.py +++ b/main.py @@ -58,11 +58,13 @@ def generate_constant(node, value): return f"Value.Float {str(value)}" elif isinstance(value, str): return "Constant.str \"" + value.replace("\"", "\"\"\"") + "\"" + elif isinstance(value, bytes): + return "Constant.bytes \"" + value.hex() + "\"" else: return generate_error("constant", node) -def generate_mod(node): +def generate_mod(node: ast.mod): if isinstance(node, ast.Module): return "\n\n".join(generate_top_level_stmt(stmt) for stmt in node.body) elif isinstance(node, ast.Interactive): @@ -75,7 +77,7 @@ def generate_mod(node): return generate_error("mod", node) -def generate_top_level_stmt(node): +def generate_top_level_stmt(node: ast.stmt): if isinstance(node, ast.FunctionDef): return f"Definition {node.name} : Value.t -> Value.t -> M :=\n" + \ generate_indent(1) + generate_function_def_body(1, node) + "." @@ -182,27 +184,38 @@ def generate_function_def_body(indent, node): body + "))" -def generate_if_then_else(indent, condition, success, error): +def generate_if_then_else( + indent, + condition: ast.expr, + success: ast.expr | list[ast.stmt], + error: ast.expr | list[ast.stmt] +): return generate_indent(indent) + "(* if *)\n" + \ generate_indent(indent) + "M.if_then_else (|\n" + \ generate_indent(indent + 1) + generate_expr(indent + 1, False, condition) + ",\n" + \ generate_indent(indent) + "(* then *)\n" + \ generate_indent(indent) + "ltac:(M.monadic (\n" + \ - generate_stmts(indent + 1, success) + "\n" + \ + generate_expr(indent + 1, False, success) \ + if isinstance(success, ast.expr) \ + else generate_stmts(indent + 1, success) + \ + "\n" + \ generate_indent(indent) + "(* else *)\n" + \ generate_indent(indent) + ")), ltac:(M.monadic (\n" + \ - generate_stmts(indent + 1, error) + "\n" + \ + generate_expr(indent + 1, False, error) \ + if isinstance(error, ast.expr) \ + else generate_stmts(indent + 1, error) + \ + "\n" + \ generate_indent(indent) + ")) |)" -def generate_stmts(indent, nodes): +def generate_stmts(indent, nodes: list[ast.stmt]): return "\n".join( [generate_stmt(indent, stmt) for stmt in nodes] + [generate_indent(indent) + "M.pure Constant.None_"] ) -def generate_stmt(indent, node): +def generate_stmt(indent, node: ast.stmt): if isinstance(node, ast.FunctionDef): return generate_error("stmt", node) elif isinstance(node, ast.AsyncFunctionDef): @@ -212,7 +225,10 @@ def generate_stmt(indent, node): elif isinstance(node, ast.Return): return generate_indent(indent) + "let _ := M.return_ (|\n" + \ generate_indent(indent + 1) + \ - generate_expr(indent + 1, False, node.value) + "\n" + \ + generate_expr(indent + 1, False, node.value) \ + if node.value is not None \ + else "Constant.None_" + \ + "\n" + \ generate_indent(indent) + "|) in" elif isinstance(node, ast.Delete): return "\n".join( @@ -277,7 +293,10 @@ def generate_stmt(indent, node): return generate_error("stmt", node) elif isinstance(node, ast.Raise): return generate_indent(indent) + "let _ := M.raise (| " + \ - generate_expr(indent, False, node.exc) + " |) in" + "Some(" + generate_expr(indent, False, node.exc) + ")" \ + if node.exc is not None \ + else "None" + \ + " |) in" elif isinstance(node, ast.Try): return generate_error("stmt", node) # elif isinstance(node, ast.TryStar): @@ -313,11 +332,11 @@ def generate_bool_op(indent, is_with_paren, op, nodes): if len(nodes) == 0: return generate_error("expr", nodes) elif len(nodes) == 1: - return generate_expr(indent + 1, False, nodes[0]) + return generate_expr(indent, False, nodes[0]) return paren( is_with_paren, - generate_boolop(op) + " (|\n" + + op + " (|\n" + generate_indent(indent + 1) + generate_expr(indent + 1, False, nodes[0]) + ",\n" + generate_indent(indent + 1) + "ltac:(M.monadic (\n" + @@ -328,6 +347,38 @@ def generate_bool_op(indent, is_with_paren, op, nodes): ) +def generate_compare(indent, is_with_paren, op, left, right): + return paren( + is_with_paren, + generate_cmpop(op) + " (|\n" + + generate_indent(indent + 1) + + generate_expr(indent + 1, False, left) + ",\n" + + generate_indent(indent + 1) + + generate_expr(indent + 1, False, right) + "\n" + + generate_indent(indent) + "|)" + ) + + +def generate_compares(indent, is_with_paren, left, ops, comparators): + if len(ops) == 0: + raise ValueError("No comparison operators provided") + elif len(ops) == 1: + return generate_compare(indent, is_with_paren, ops[0], left, comparators[0]) + + return paren( + is_with_paren, + "BoolOp.and (|\n" + + generate_indent(indent + 1) + + generate_compare(indent + 1, is_with_paren, ops[0], left, comparators[0]) + ",\n" + + generate_indent(indent + 1) + "ltac:(M.monadic (\n" + + generate_indent(indent + 2) + + generate_compares(indent + 2, False, comparators[0], ops[1:], comparators[1:]) + + "\n" + + generate_indent(indent + 1) + "))\n" + + generate_indent(indent) + "|)" + ) + + def generate_single_list_or_node(indent, is_with_paren, nodes): if isinstance(nodes, list): return paren( @@ -382,9 +433,11 @@ def generate_list(indent, is_with_paren, nodes): ) -def generate_expr(indent, is_with_paren, node): +def generate_expr(indent, is_with_paren, node: ast.expr): if isinstance(node, ast.BoolOp): - return generate_bool_op(indent, is_with_paren, node.op, node.values) + return generate_bool_op( + indent, is_with_paren, generate_boolop(node.op), node.values + ) elif isinstance(node, ast.NamedExpr): return generate_error("expr", node) elif isinstance(node, ast.BinOp): @@ -407,7 +460,7 @@ def generate_expr(indent, is_with_paren, node): elif isinstance(node, ast.Lambda): return paren( is_with_paren, - f"fun {generate_expr(indent, False, node.args)} => {generate_expr(indent, False, node.body)}" + f"fun (args kwargs : Value.t) => {generate_expr(indent, False, node.body)}" ) elif isinstance(node, ast.IfExp): return paren( @@ -415,17 +468,25 @@ def generate_expr(indent, is_with_paren, node): generate_if_then_else(0, node.test, node.body, node.orelse) ) elif isinstance(node, ast.Dict): - return "{" + ", ".join(generate_expr(indent, False, key) + ": " + generate_expr(indent, False, value) for key, value in zip(node.keys, node.values)) + "}" + return "{" + \ + ", ".join( + generate_expr(indent, False, key) + if key is not None + else "?" + + ": " + generate_expr(indent, False, value) + for key, value in zip(node.keys, node.values) + ) + \ + "}" elif isinstance(node, ast.Set): return "{" + ", ".join(generate_expr(indent, False, elt) for elt in node.elts) + "}" elif isinstance(node, ast.ListComp): - return f"[{generate_expr(indent, False, node.elt)} for {generate_expr(indent, False, node.generators)}]" + return generate_error("expr", node) elif isinstance(node, ast.SetComp): - return f"{{{generate_expr(indent, False, node.elt)} for {generate_expr(indent, False, node.generators)}}}" + return generate_error("expr", node) elif isinstance(node, ast.DictComp): - return f"{{{generate_expr(indent, False, node.key)}: {generate_expr(indent, False, node.value)} for {generate_expr(indent, False, node.generators)}}}" + return generate_error("expr", node) elif isinstance(node, ast.GeneratorExp): - return f"({generate_expr(indent, False, node.elt)} for {generate_expr(indent, False, node.generators)})" + return generate_error("expr", node) elif isinstance(node, ast.Await): return paren( is_with_paren, @@ -434,7 +495,11 @@ def generate_expr(indent, is_with_paren, node): elif isinstance(node, ast.Yield): return paren( is_with_paren, - f"M.yield (| {generate_expr(indent, False, node.value)} |)" + "M.yield (| " + + generate_expr(indent, False, node.value) + if node.value is not None + else "Constant.None_" + + " |)" ) elif isinstance(node, ast.YieldFrom): return paren( @@ -442,12 +507,8 @@ def generate_expr(indent, is_with_paren, node): f"M.yield_from (| {generate_expr(indent, False, node.value)} |)" ) elif isinstance(node, ast.Compare): - if len(node.ops) >= 2 or len(node.comparators) >= 2: - return generate_error("expr", node) - - return paren( - is_with_paren, - f"{generate_cmpop(node.ops[0])} (| {generate_expr(indent, False, node.left)}, {generate_expr(indent, False, node.comparators[0])} |)" + return generate_compares( + indent, is_with_paren, node.left, node.ops, node.comparators ) elif isinstance(node, ast.Call): return paren( @@ -499,7 +560,13 @@ def generate_expr(indent, is_with_paren, node): elif isinstance(node, ast.Slice): return paren( is_with_paren, - f"{generate_expr(indent, False, node.lower)}:{generate_expr(indent, False, node.upper)}" + generate_expr(indent, False, node.lower) + if node.lower is not None + else "Constant.None_" + + ":" + + generate_expr(indent, False, node.upper) + if node.upper is not None + else "Constant.None_" ) else: return generate_error("expr", node) From b575191be5964e308a1456f8e46aaf9f2fbec774 Mon Sep 17 00:00:00 2001 From: Guillaume Claret Date: Fri, 10 May 2024 17:40:38 +0200 Subject: [PATCH 3/6] Better handling of the Require paths --- CoqOfPython/ethereum/arrow_glacier/blocks.v | 58 +- CoqOfPython/ethereum/arrow_glacier/bloom.v | 18 +- CoqOfPython/ethereum/arrow_glacier/fork.v | 917 +++++++- .../ethereum/arrow_glacier/fork_types.v | 47 +- CoqOfPython/ethereum/arrow_glacier/state.v | 265 ++- .../ethereum/arrow_glacier/transactions.v | 195 +- CoqOfPython/ethereum/arrow_glacier/trie.v | 625 ++++- .../ethereum/arrow_glacier/utils/address.v | 21 +- .../arrow_glacier/utils/hexadecimal.v | 17 +- .../ethereum/arrow_glacier/utils/message.v | 131 +- .../ethereum/arrow_glacier/vm/__init__.v | 104 +- CoqOfPython/ethereum/arrow_glacier/vm/gas.v | 113 +- .../arrow_glacier/vm/instructions/__init__.v | 72 +- .../vm/instructions/arithmetic.v | 205 +- .../arrow_glacier/vm/instructions/bitwise.v | 127 +- .../arrow_glacier/vm/instructions/block.v | 58 +- .../vm/instructions/comparison.v | 26 +- .../vm/instructions/control_flow.v | 84 +- .../vm/instructions/environment.v | 208 +- .../arrow_glacier/vm/instructions/keccak.v | 46 +- .../arrow_glacier/vm/instructions/log.v | 62 +- .../arrow_glacier/vm/instructions/memory.v | 44 +- .../arrow_glacier/vm/instructions/stack.v | 42 +- .../arrow_glacier/vm/instructions/storage.v | 307 ++- .../arrow_glacier/vm/instructions/system.v | 676 ++++-- .../ethereum/arrow_glacier/vm/interpreter.v | 390 +++- .../ethereum/arrow_glacier/vm/memory.v | 67 +- .../vm/precompiled_contracts/__init__.v | 6 +- .../vm/precompiled_contracts/alt_bn128.v | 167 +- .../vm/precompiled_contracts/blake2f.v | 22 +- .../vm/precompiled_contracts/ecrecover.v | 90 +- .../vm/precompiled_contracts/identity.v | 20 +- .../vm/precompiled_contracts/mapping.v | 110 +- .../vm/precompiled_contracts/modexp.v | 158 +- .../vm/precompiled_contracts/ripemd160.v | 20 +- .../vm/precompiled_contracts/sha256.v | 20 +- .../ethereum/arrow_glacier/vm/runtime.v | 55 +- CoqOfPython/ethereum/arrow_glacier/vm/stack.v | 48 +- CoqOfPython/ethereum/base_types.v | 2027 +++++++++++++++++ CoqOfPython/ethereum/berlin/blocks.v | 58 +- CoqOfPython/ethereum/berlin/bloom.v | 18 +- CoqOfPython/ethereum/berlin/fork.v | 722 +++++- CoqOfPython/ethereum/berlin/fork_types.v | 47 +- CoqOfPython/ethereum/berlin/state.v | 265 ++- CoqOfPython/ethereum/berlin/transactions.v | 148 +- CoqOfPython/ethereum/berlin/trie.v | 625 ++++- CoqOfPython/ethereum/berlin/utils/address.v | 21 +- .../ethereum/berlin/utils/hexadecimal.v | 17 +- CoqOfPython/ethereum/berlin/utils/message.v | 131 +- CoqOfPython/ethereum/berlin/vm/__init__.v | 104 +- CoqOfPython/ethereum/berlin/vm/gas.v | 113 +- .../berlin/vm/instructions/__init__.v | 72 +- .../berlin/vm/instructions/arithmetic.v | 205 +- .../ethereum/berlin/vm/instructions/bitwise.v | 127 +- .../ethereum/berlin/vm/instructions/block.v | 58 +- .../berlin/vm/instructions/comparison.v | 26 +- .../berlin/vm/instructions/control_flow.v | 84 +- .../berlin/vm/instructions/environment.v | 208 +- .../ethereum/berlin/vm/instructions/keccak.v | 46 +- .../ethereum/berlin/vm/instructions/log.v | 62 +- .../ethereum/berlin/vm/instructions/memory.v | 44 +- .../ethereum/berlin/vm/instructions/stack.v | 42 +- .../ethereum/berlin/vm/instructions/storage.v | 307 ++- .../ethereum/berlin/vm/instructions/system.v | 696 ++++-- CoqOfPython/ethereum/berlin/vm/interpreter.v | 386 +++- CoqOfPython/ethereum/berlin/vm/memory.v | 67 +- .../vm/precompiled_contracts/__init__.v | 6 +- .../vm/precompiled_contracts/alt_bn128.v | 167 +- .../berlin/vm/precompiled_contracts/blake2f.v | 22 +- .../vm/precompiled_contracts/ecrecover.v | 90 +- .../vm/precompiled_contracts/identity.v | 20 +- .../berlin/vm/precompiled_contracts/mapping.v | 110 +- .../berlin/vm/precompiled_contracts/modexp.v | 158 +- .../vm/precompiled_contracts/ripemd160.v | 20 +- .../berlin/vm/precompiled_contracts/sha256.v | 20 +- CoqOfPython/ethereum/berlin/vm/runtime.v | 55 +- CoqOfPython/ethereum/berlin/vm/stack.v | 48 +- CoqOfPython/ethereum/byzantium/blocks.v | 58 +- CoqOfPython/ethereum/byzantium/bloom.v | 18 +- CoqOfPython/ethereum/byzantium/fork.v | 486 +++- CoqOfPython/ethereum/byzantium/fork_types.v | 47 +- CoqOfPython/ethereum/byzantium/state.v | 199 +- CoqOfPython/ethereum/byzantium/transactions.v | 30 +- CoqOfPython/ethereum/byzantium/trie.v | 625 ++++- .../ethereum/byzantium/utils/address.v | 18 +- .../ethereum/byzantium/utils/hexadecimal.v | 17 +- .../ethereum/byzantium/utils/message.v | 125 +- CoqOfPython/ethereum/byzantium/vm/__init__.v | 104 +- CoqOfPython/ethereum/byzantium/vm/gas.v | 113 +- .../byzantium/vm/instructions/__init__.v | 72 +- .../byzantium/vm/instructions/arithmetic.v | 205 +- .../byzantium/vm/instructions/bitwise.v | 45 +- .../byzantium/vm/instructions/block.v | 58 +- .../byzantium/vm/instructions/comparison.v | 26 +- .../byzantium/vm/instructions/control_flow.v | 84 +- .../byzantium/vm/instructions/environment.v | 83 +- .../byzantium/vm/instructions/keccak.v | 46 +- .../ethereum/byzantium/vm/instructions/log.v | 62 +- .../byzantium/vm/instructions/memory.v | 44 +- .../byzantium/vm/instructions/stack.v | 42 +- .../byzantium/vm/instructions/storage.v | 107 +- .../byzantium/vm/instructions/system.v | 605 ++++- .../ethereum/byzantium/vm/interpreter.v | 382 +++- CoqOfPython/ethereum/byzantium/vm/memory.v | 67 +- .../vm/precompiled_contracts/__init__.v | 6 +- .../vm/precompiled_contracts/alt_bn128.v | 167 +- .../vm/precompiled_contracts/ecrecover.v | 90 +- .../vm/precompiled_contracts/identity.v | 20 +- .../vm/precompiled_contracts/mapping.v | 84 +- .../vm/precompiled_contracts/modexp.v | 152 +- .../vm/precompiled_contracts/ripemd160.v | 20 +- .../vm/precompiled_contracts/sha256.v | 20 +- CoqOfPython/ethereum/byzantium/vm/runtime.v | 55 +- CoqOfPython/ethereum/byzantium/vm/stack.v | 48 +- CoqOfPython/ethereum/cancun/blocks.v | 62 +- CoqOfPython/ethereum/cancun/bloom.v | 18 +- CoqOfPython/ethereum/cancun/fork.v | 1223 ++++++++-- CoqOfPython/ethereum/cancun/fork_types.v | 47 +- CoqOfPython/ethereum/cancun/state.v | 352 ++- CoqOfPython/ethereum/cancun/transactions.v | 250 +- CoqOfPython/ethereum/cancun/trie.v | 629 ++++- CoqOfPython/ethereum/cancun/utils/address.v | 21 +- .../ethereum/cancun/utils/hexadecimal.v | 17 +- CoqOfPython/ethereum/cancun/utils/message.v | 131 +- CoqOfPython/ethereum/cancun/vm/__init__.v | 118 +- CoqOfPython/ethereum/cancun/vm/gas.v | 181 +- .../cancun/vm/instructions/__init__.v | 72 +- .../cancun/vm/instructions/arithmetic.v | 205 +- .../ethereum/cancun/vm/instructions/bitwise.v | 127 +- .../ethereum/cancun/vm/instructions/block.v | 58 +- .../cancun/vm/instructions/comparison.v | 26 +- .../cancun/vm/instructions/control_flow.v | 84 +- .../cancun/vm/instructions/environment.v | 235 +- .../ethereum/cancun/vm/instructions/keccak.v | 46 +- .../ethereum/cancun/vm/instructions/log.v | 62 +- .../ethereum/cancun/vm/instructions/memory.v | 48 +- .../ethereum/cancun/vm/instructions/stack.v | 61 +- .../ethereum/cancun/vm/instructions/storage.v | 307 ++- .../ethereum/cancun/vm/instructions/system.v | 721 ++++-- CoqOfPython/ethereum/cancun/vm/interpreter.v | 391 +++- CoqOfPython/ethereum/cancun/vm/memory.v | 67 +- .../vm/precompiled_contracts/__init__.v | 6 +- .../vm/precompiled_contracts/alt_bn128.v | 167 +- .../cancun/vm/precompiled_contracts/blake2f.v | 22 +- .../vm/precompiled_contracts/ecrecover.v | 90 +- .../vm/precompiled_contracts/identity.v | 20 +- .../cancun/vm/precompiled_contracts/mapping.v | 122 +- .../cancun/vm/precompiled_contracts/modexp.v | 158 +- .../precompiled_contracts/point_evaluation.v | 32 +- .../vm/precompiled_contracts/ripemd160.v | 20 +- .../cancun/vm/precompiled_contracts/sha256.v | 20 +- CoqOfPython/ethereum/cancun/vm/runtime.v | 55 +- CoqOfPython/ethereum/cancun/vm/stack.v | 48 +- CoqOfPython/ethereum/constantinople/blocks.v | 58 +- CoqOfPython/ethereum/constantinople/bloom.v | 18 +- CoqOfPython/ethereum/constantinople/fork.v | 486 +++- .../ethereum/constantinople/fork_types.v | 47 +- CoqOfPython/ethereum/constantinople/state.v | 199 +- .../ethereum/constantinople/transactions.v | 30 +- CoqOfPython/ethereum/constantinople/trie.v | 625 ++++- .../ethereum/constantinople/utils/address.v | 21 +- .../constantinople/utils/hexadecimal.v | 17 +- .../ethereum/constantinople/utils/message.v | 125 +- .../ethereum/constantinople/vm/__init__.v | 104 +- CoqOfPython/ethereum/constantinople/vm/gas.v | 113 +- .../constantinople/vm/instructions/__init__.v | 72 +- .../vm/instructions/arithmetic.v | 205 +- .../constantinople/vm/instructions/bitwise.v | 127 +- .../constantinople/vm/instructions/block.v | 58 +- .../vm/instructions/comparison.v | 26 +- .../vm/instructions/control_flow.v | 84 +- .../vm/instructions/environment.v | 112 +- .../constantinople/vm/instructions/keccak.v | 46 +- .../constantinople/vm/instructions/log.v | 62 +- .../constantinople/vm/instructions/memory.v | 44 +- .../constantinople/vm/instructions/stack.v | 42 +- .../constantinople/vm/instructions/storage.v | 107 +- .../constantinople/vm/instructions/system.v | 619 +++-- .../ethereum/constantinople/vm/interpreter.v | 382 +++- .../ethereum/constantinople/vm/memory.v | 67 +- .../vm/precompiled_contracts/__init__.v | 6 +- .../vm/precompiled_contracts/alt_bn128.v | 167 +- .../vm/precompiled_contracts/ecrecover.v | 90 +- .../vm/precompiled_contracts/identity.v | 20 +- .../vm/precompiled_contracts/mapping.v | 84 +- .../vm/precompiled_contracts/modexp.v | 152 +- .../vm/precompiled_contracts/ripemd160.v | 20 +- .../vm/precompiled_contracts/sha256.v | 20 +- .../ethereum/constantinople/vm/runtime.v | 55 +- .../ethereum/constantinople/vm/stack.v | 48 +- CoqOfPython/ethereum/crypto/alt_bn128.v | 179 +- CoqOfPython/ethereum/crypto/blake2.v | 34 +- CoqOfPython/ethereum/crypto/elliptic_curve.v | 252 +- CoqOfPython/ethereum/crypto/finite_field.v | 457 +++- CoqOfPython/ethereum/crypto/hash.v | 16 +- CoqOfPython/ethereum/dao_fork/blocks.v | 58 +- CoqOfPython/ethereum/dao_fork/bloom.v | 18 +- CoqOfPython/ethereum/dao_fork/dao.v | 22 +- CoqOfPython/ethereum/dao_fork/fork.v | 409 +++- CoqOfPython/ethereum/dao_fork/fork_types.v | 47 +- CoqOfPython/ethereum/dao_fork/state.v | 182 +- CoqOfPython/ethereum/dao_fork/transactions.v | 30 +- CoqOfPython/ethereum/dao_fork/trie.v | 625 ++++- CoqOfPython/ethereum/dao_fork/utils/address.v | 18 +- .../ethereum/dao_fork/utils/hexadecimal.v | 17 +- CoqOfPython/ethereum/dao_fork/utils/message.v | 125 +- CoqOfPython/ethereum/dao_fork/vm/__init__.v | 18 +- CoqOfPython/ethereum/dao_fork/vm/gas.v | 163 +- .../dao_fork/vm/instructions/__init__.v | 72 +- .../dao_fork/vm/instructions/arithmetic.v | 205 +- .../dao_fork/vm/instructions/bitwise.v | 45 +- .../ethereum/dao_fork/vm/instructions/block.v | 58 +- .../dao_fork/vm/instructions/comparison.v | 26 +- .../dao_fork/vm/instructions/control_flow.v | 84 +- .../dao_fork/vm/instructions/environment.v | 78 +- .../dao_fork/vm/instructions/keccak.v | 46 +- .../ethereum/dao_fork/vm/instructions/log.v | 54 +- .../dao_fork/vm/instructions/memory.v | 44 +- .../ethereum/dao_fork/vm/instructions/stack.v | 42 +- .../dao_fork/vm/instructions/storage.v | 93 +- .../dao_fork/vm/instructions/system.v | 374 ++- .../ethereum/dao_fork/vm/interpreter.v | 317 ++- CoqOfPython/ethereum/dao_fork/vm/memory.v | 67 +- .../vm/precompiled_contracts/__init__.v | 6 +- .../vm/precompiled_contracts/ecrecover.v | 90 +- .../vm/precompiled_contracts/identity.v | 20 +- .../vm/precompiled_contracts/mapping.v | 58 +- .../vm/precompiled_contracts/ripemd160.v | 20 +- .../vm/precompiled_contracts/sha256.v | 20 +- CoqOfPython/ethereum/dao_fork/vm/runtime.v | 55 +- CoqOfPython/ethereum/dao_fork/vm/stack.v | 48 +- CoqOfPython/ethereum/ethash.v | 34 +- CoqOfPython/ethereum/fork_criteria.v | 55 +- CoqOfPython/ethereum/frontier/blocks.v | 58 +- CoqOfPython/ethereum/frontier/bloom.v | 18 +- CoqOfPython/ethereum/frontier/fork.v | 360 ++- CoqOfPython/ethereum/frontier/fork_types.v | 47 +- CoqOfPython/ethereum/frontier/state.v | 182 +- CoqOfPython/ethereum/frontier/transactions.v | 30 +- CoqOfPython/ethereum/frontier/trie.v | 622 ++++- CoqOfPython/ethereum/frontier/utils/address.v | 18 +- .../ethereum/frontier/utils/hexadecimal.v | 17 +- CoqOfPython/ethereum/frontier/utils/message.v | 125 +- CoqOfPython/ethereum/frontier/vm/__init__.v | 18 +- CoqOfPython/ethereum/frontier/vm/gas.v | 163 +- .../frontier/vm/instructions/__init__.v | 72 +- .../frontier/vm/instructions/arithmetic.v | 205 +- .../frontier/vm/instructions/bitwise.v | 45 +- .../ethereum/frontier/vm/instructions/block.v | 58 +- .../frontier/vm/instructions/comparison.v | 26 +- .../frontier/vm/instructions/control_flow.v | 84 +- .../frontier/vm/instructions/environment.v | 78 +- .../frontier/vm/instructions/keccak.v | 46 +- .../ethereum/frontier/vm/instructions/log.v | 54 +- .../frontier/vm/instructions/memory.v | 44 +- .../ethereum/frontier/vm/instructions/stack.v | 42 +- .../frontier/vm/instructions/storage.v | 93 +- .../frontier/vm/instructions/system.v | 370 ++- .../ethereum/frontier/vm/interpreter.v | 323 ++- CoqOfPython/ethereum/frontier/vm/memory.v | 67 +- .../vm/precompiled_contracts/__init__.v | 6 +- .../vm/precompiled_contracts/ecrecover.v | 90 +- .../vm/precompiled_contracts/identity.v | 20 +- .../vm/precompiled_contracts/mapping.v | 58 +- .../vm/precompiled_contracts/ripemd160.v | 20 +- .../vm/precompiled_contracts/sha256.v | 20 +- CoqOfPython/ethereum/frontier/vm/runtime.v | 55 +- CoqOfPython/ethereum/frontier/vm/stack.v | 48 +- CoqOfPython/ethereum/genesis.v | 168 +- CoqOfPython/ethereum/gray_glacier/blocks.v | 58 +- CoqOfPython/ethereum/gray_glacier/bloom.v | 18 +- CoqOfPython/ethereum/gray_glacier/fork.v | 917 +++++++- .../ethereum/gray_glacier/fork_types.v | 47 +- CoqOfPython/ethereum/gray_glacier/state.v | 265 ++- .../ethereum/gray_glacier/transactions.v | 195 +- CoqOfPython/ethereum/gray_glacier/trie.v | 625 ++++- .../ethereum/gray_glacier/utils/address.v | 21 +- .../ethereum/gray_glacier/utils/hexadecimal.v | 17 +- .../ethereum/gray_glacier/utils/message.v | 131 +- .../ethereum/gray_glacier/vm/__init__.v | 104 +- CoqOfPython/ethereum/gray_glacier/vm/gas.v | 113 +- .../gray_glacier/vm/instructions/__init__.v | 72 +- .../gray_glacier/vm/instructions/arithmetic.v | 205 +- .../gray_glacier/vm/instructions/bitwise.v | 127 +- .../gray_glacier/vm/instructions/block.v | 58 +- .../gray_glacier/vm/instructions/comparison.v | 26 +- .../vm/instructions/control_flow.v | 84 +- .../vm/instructions/environment.v | 208 +- .../gray_glacier/vm/instructions/keccak.v | 46 +- .../gray_glacier/vm/instructions/log.v | 62 +- .../gray_glacier/vm/instructions/memory.v | 44 +- .../gray_glacier/vm/instructions/stack.v | 42 +- .../gray_glacier/vm/instructions/storage.v | 307 ++- .../gray_glacier/vm/instructions/system.v | 676 ++++-- .../ethereum/gray_glacier/vm/interpreter.v | 390 +++- CoqOfPython/ethereum/gray_glacier/vm/memory.v | 67 +- .../vm/precompiled_contracts/__init__.v | 6 +- .../vm/precompiled_contracts/alt_bn128.v | 167 +- .../vm/precompiled_contracts/blake2f.v | 22 +- .../vm/precompiled_contracts/ecrecover.v | 90 +- .../vm/precompiled_contracts/identity.v | 20 +- .../vm/precompiled_contracts/mapping.v | 110 +- .../vm/precompiled_contracts/modexp.v | 158 +- .../vm/precompiled_contracts/ripemd160.v | 20 +- .../vm/precompiled_contracts/sha256.v | 20 +- .../ethereum/gray_glacier/vm/runtime.v | 55 +- CoqOfPython/ethereum/gray_glacier/vm/stack.v | 48 +- CoqOfPython/ethereum/homestead/blocks.v | 58 +- CoqOfPython/ethereum/homestead/bloom.v | 18 +- CoqOfPython/ethereum/homestead/fork.v | 364 ++- CoqOfPython/ethereum/homestead/fork_types.v | 47 +- CoqOfPython/ethereum/homestead/state.v | 182 +- CoqOfPython/ethereum/homestead/transactions.v | 30 +- CoqOfPython/ethereum/homestead/trie.v | 625 ++++- .../ethereum/homestead/utils/address.v | 18 +- .../ethereum/homestead/utils/hexadecimal.v | 17 +- .../ethereum/homestead/utils/message.v | 125 +- CoqOfPython/ethereum/homestead/vm/__init__.v | 18 +- CoqOfPython/ethereum/homestead/vm/gas.v | 163 +- .../homestead/vm/instructions/__init__.v | 72 +- .../homestead/vm/instructions/arithmetic.v | 205 +- .../homestead/vm/instructions/bitwise.v | 45 +- .../homestead/vm/instructions/block.v | 58 +- .../homestead/vm/instructions/comparison.v | 26 +- .../homestead/vm/instructions/control_flow.v | 84 +- .../homestead/vm/instructions/environment.v | 78 +- .../homestead/vm/instructions/keccak.v | 46 +- .../ethereum/homestead/vm/instructions/log.v | 54 +- .../homestead/vm/instructions/memory.v | 44 +- .../homestead/vm/instructions/stack.v | 42 +- .../homestead/vm/instructions/storage.v | 93 +- .../homestead/vm/instructions/system.v | 374 ++- .../ethereum/homestead/vm/interpreter.v | 321 ++- CoqOfPython/ethereum/homestead/vm/memory.v | 67 +- .../vm/precompiled_contracts/__init__.v | 6 +- .../vm/precompiled_contracts/ecrecover.v | 90 +- .../vm/precompiled_contracts/identity.v | 20 +- .../vm/precompiled_contracts/mapping.v | 58 +- .../vm/precompiled_contracts/ripemd160.v | 20 +- .../vm/precompiled_contracts/sha256.v | 20 +- CoqOfPython/ethereum/homestead/vm/runtime.v | 55 +- CoqOfPython/ethereum/homestead/vm/stack.v | 48 +- CoqOfPython/ethereum/istanbul/blocks.v | 58 +- CoqOfPython/ethereum/istanbul/bloom.v | 18 +- CoqOfPython/ethereum/istanbul/fork.v | 486 +++- CoqOfPython/ethereum/istanbul/fork_types.v | 47 +- CoqOfPython/ethereum/istanbul/state.v | 265 ++- CoqOfPython/ethereum/istanbul/transactions.v | 30 +- CoqOfPython/ethereum/istanbul/trie.v | 625 ++++- CoqOfPython/ethereum/istanbul/utils/address.v | 21 +- .../ethereum/istanbul/utils/hexadecimal.v | 17 +- CoqOfPython/ethereum/istanbul/utils/message.v | 125 +- CoqOfPython/ethereum/istanbul/vm/__init__.v | 104 +- CoqOfPython/ethereum/istanbul/vm/gas.v | 113 +- .../istanbul/vm/instructions/__init__.v | 72 +- .../istanbul/vm/instructions/arithmetic.v | 205 +- .../istanbul/vm/instructions/bitwise.v | 127 +- .../ethereum/istanbul/vm/instructions/block.v | 58 +- .../istanbul/vm/instructions/comparison.v | 26 +- .../istanbul/vm/instructions/control_flow.v | 84 +- .../istanbul/vm/instructions/environment.v | 130 +- .../istanbul/vm/instructions/keccak.v | 46 +- .../ethereum/istanbul/vm/instructions/log.v | 62 +- .../istanbul/vm/instructions/memory.v | 44 +- .../ethereum/istanbul/vm/instructions/stack.v | 42 +- .../istanbul/vm/instructions/storage.v | 252 +- .../istanbul/vm/instructions/system.v | 619 +++-- .../ethereum/istanbul/vm/interpreter.v | 386 +++- CoqOfPython/ethereum/istanbul/vm/memory.v | 67 +- .../vm/precompiled_contracts/__init__.v | 6 +- .../vm/precompiled_contracts/alt_bn128.v | 167 +- .../vm/precompiled_contracts/blake2f.v | 22 +- .../vm/precompiled_contracts/ecrecover.v | 90 +- .../vm/precompiled_contracts/identity.v | 20 +- .../vm/precompiled_contracts/mapping.v | 110 +- .../vm/precompiled_contracts/modexp.v | 152 +- .../vm/precompiled_contracts/ripemd160.v | 20 +- .../vm/precompiled_contracts/sha256.v | 20 +- CoqOfPython/ethereum/istanbul/vm/runtime.v | 55 +- CoqOfPython/ethereum/istanbul/vm/stack.v | 48 +- CoqOfPython/ethereum/london/blocks.v | 58 +- CoqOfPython/ethereum/london/bloom.v | 18 +- CoqOfPython/ethereum/london/fork.v | 938 +++++++- CoqOfPython/ethereum/london/fork_types.v | 47 +- CoqOfPython/ethereum/london/state.v | 265 ++- CoqOfPython/ethereum/london/transactions.v | 195 +- CoqOfPython/ethereum/london/trie.v | 625 ++++- CoqOfPython/ethereum/london/utils/address.v | 21 +- .../ethereum/london/utils/hexadecimal.v | 17 +- CoqOfPython/ethereum/london/utils/message.v | 131 +- CoqOfPython/ethereum/london/vm/__init__.v | 104 +- CoqOfPython/ethereum/london/vm/gas.v | 113 +- .../london/vm/instructions/__init__.v | 72 +- .../london/vm/instructions/arithmetic.v | 205 +- .../ethereum/london/vm/instructions/bitwise.v | 127 +- .../ethereum/london/vm/instructions/block.v | 58 +- .../london/vm/instructions/comparison.v | 26 +- .../london/vm/instructions/control_flow.v | 84 +- .../london/vm/instructions/environment.v | 208 +- .../ethereum/london/vm/instructions/keccak.v | 46 +- .../ethereum/london/vm/instructions/log.v | 62 +- .../ethereum/london/vm/instructions/memory.v | 44 +- .../ethereum/london/vm/instructions/stack.v | 42 +- .../ethereum/london/vm/instructions/storage.v | 307 ++- .../ethereum/london/vm/instructions/system.v | 676 ++++-- CoqOfPython/ethereum/london/vm/interpreter.v | 390 +++- CoqOfPython/ethereum/london/vm/memory.v | 67 +- .../vm/precompiled_contracts/__init__.v | 6 +- .../vm/precompiled_contracts/alt_bn128.v | 167 +- .../london/vm/precompiled_contracts/blake2f.v | 22 +- .../vm/precompiled_contracts/ecrecover.v | 90 +- .../vm/precompiled_contracts/identity.v | 20 +- .../london/vm/precompiled_contracts/mapping.v | 110 +- .../london/vm/precompiled_contracts/modexp.v | 158 +- .../vm/precompiled_contracts/ripemd160.v | 20 +- .../london/vm/precompiled_contracts/sha256.v | 20 +- CoqOfPython/ethereum/london/vm/runtime.v | 55 +- CoqOfPython/ethereum/london/vm/stack.v | 48 +- CoqOfPython/ethereum/muir_glacier/blocks.v | 58 +- CoqOfPython/ethereum/muir_glacier/bloom.v | 18 +- CoqOfPython/ethereum/muir_glacier/fork.v | 486 +++- .../ethereum/muir_glacier/fork_types.v | 47 +- CoqOfPython/ethereum/muir_glacier/state.v | 265 ++- .../ethereum/muir_glacier/transactions.v | 30 +- CoqOfPython/ethereum/muir_glacier/trie.v | 625 ++++- .../ethereum/muir_glacier/utils/address.v | 21 +- .../ethereum/muir_glacier/utils/hexadecimal.v | 17 +- .../ethereum/muir_glacier/utils/message.v | 125 +- .../ethereum/muir_glacier/vm/__init__.v | 104 +- CoqOfPython/ethereum/muir_glacier/vm/gas.v | 113 +- .../muir_glacier/vm/instructions/__init__.v | 72 +- .../muir_glacier/vm/instructions/arithmetic.v | 205 +- .../muir_glacier/vm/instructions/bitwise.v | 127 +- .../muir_glacier/vm/instructions/block.v | 58 +- .../muir_glacier/vm/instructions/comparison.v | 26 +- .../vm/instructions/control_flow.v | 84 +- .../vm/instructions/environment.v | 130 +- .../muir_glacier/vm/instructions/keccak.v | 46 +- .../muir_glacier/vm/instructions/log.v | 62 +- .../muir_glacier/vm/instructions/memory.v | 44 +- .../muir_glacier/vm/instructions/stack.v | 42 +- .../muir_glacier/vm/instructions/storage.v | 252 +- .../muir_glacier/vm/instructions/system.v | 619 +++-- .../ethereum/muir_glacier/vm/interpreter.v | 386 +++- CoqOfPython/ethereum/muir_glacier/vm/memory.v | 67 +- .../vm/precompiled_contracts/__init__.v | 6 +- .../vm/precompiled_contracts/alt_bn128.v | 167 +- .../vm/precompiled_contracts/blake2f.v | 22 +- .../vm/precompiled_contracts/ecrecover.v | 90 +- .../vm/precompiled_contracts/identity.v | 20 +- .../vm/precompiled_contracts/mapping.v | 110 +- .../vm/precompiled_contracts/modexp.v | 152 +- .../vm/precompiled_contracts/ripemd160.v | 20 +- .../vm/precompiled_contracts/sha256.v | 20 +- .../ethereum/muir_glacier/vm/runtime.v | 55 +- CoqOfPython/ethereum/muir_glacier/vm/stack.v | 48 +- CoqOfPython/ethereum/paris/blocks.v | 58 +- CoqOfPython/ethereum/paris/bloom.v | 18 +- CoqOfPython/ethereum/paris/fork.v | 841 ++++++- CoqOfPython/ethereum/paris/fork_types.v | 47 +- CoqOfPython/ethereum/paris/state.v | 265 ++- CoqOfPython/ethereum/paris/transactions.v | 195 +- CoqOfPython/ethereum/paris/trie.v | 625 ++++- CoqOfPython/ethereum/paris/utils/address.v | 21 +- .../ethereum/paris/utils/hexadecimal.v | 17 +- CoqOfPython/ethereum/paris/utils/message.v | 131 +- CoqOfPython/ethereum/paris/vm/__init__.v | 104 +- CoqOfPython/ethereum/paris/vm/gas.v | 113 +- .../ethereum/paris/vm/instructions/__init__.v | 72 +- .../paris/vm/instructions/arithmetic.v | 205 +- .../ethereum/paris/vm/instructions/bitwise.v | 127 +- .../ethereum/paris/vm/instructions/block.v | 58 +- .../paris/vm/instructions/comparison.v | 26 +- .../paris/vm/instructions/control_flow.v | 84 +- .../paris/vm/instructions/environment.v | 208 +- .../ethereum/paris/vm/instructions/keccak.v | 46 +- .../ethereum/paris/vm/instructions/log.v | 62 +- .../ethereum/paris/vm/instructions/memory.v | 44 +- .../ethereum/paris/vm/instructions/stack.v | 42 +- .../ethereum/paris/vm/instructions/storage.v | 307 ++- .../ethereum/paris/vm/instructions/system.v | 676 ++++-- CoqOfPython/ethereum/paris/vm/interpreter.v | 390 +++- CoqOfPython/ethereum/paris/vm/memory.v | 67 +- .../paris/vm/precompiled_contracts/__init__.v | 6 +- .../vm/precompiled_contracts/alt_bn128.v | 167 +- .../paris/vm/precompiled_contracts/blake2f.v | 22 +- .../vm/precompiled_contracts/ecrecover.v | 90 +- .../paris/vm/precompiled_contracts/identity.v | 20 +- .../paris/vm/precompiled_contracts/mapping.v | 110 +- .../paris/vm/precompiled_contracts/modexp.v | 158 +- .../vm/precompiled_contracts/ripemd160.v | 20 +- .../paris/vm/precompiled_contracts/sha256.v | 20 +- CoqOfPython/ethereum/paris/vm/runtime.v | 55 +- CoqOfPython/ethereum/paris/vm/stack.v | 48 +- CoqOfPython/ethereum/rlp.v | 1529 ++++++++++++- CoqOfPython/ethereum/shanghai/blocks.v | 62 +- CoqOfPython/ethereum/shanghai/bloom.v | 18 +- CoqOfPython/ethereum/shanghai/fork.v | 988 +++++++- CoqOfPython/ethereum/shanghai/fork_types.v | 47 +- CoqOfPython/ethereum/shanghai/state.v | 273 ++- CoqOfPython/ethereum/shanghai/transactions.v | 195 +- CoqOfPython/ethereum/shanghai/trie.v | 629 ++++- CoqOfPython/ethereum/shanghai/utils/address.v | 21 +- .../ethereum/shanghai/utils/hexadecimal.v | 17 +- CoqOfPython/ethereum/shanghai/utils/message.v | 131 +- CoqOfPython/ethereum/shanghai/vm/__init__.v | 104 +- CoqOfPython/ethereum/shanghai/vm/gas.v | 114 +- .../shanghai/vm/instructions/__init__.v | 72 +- .../shanghai/vm/instructions/arithmetic.v | 205 +- .../shanghai/vm/instructions/bitwise.v | 127 +- .../ethereum/shanghai/vm/instructions/block.v | 58 +- .../shanghai/vm/instructions/comparison.v | 26 +- .../shanghai/vm/instructions/control_flow.v | 84 +- .../shanghai/vm/instructions/environment.v | 208 +- .../shanghai/vm/instructions/keccak.v | 46 +- .../ethereum/shanghai/vm/instructions/log.v | 62 +- .../shanghai/vm/instructions/memory.v | 44 +- .../ethereum/shanghai/vm/instructions/stack.v | 61 +- .../shanghai/vm/instructions/storage.v | 307 ++- .../shanghai/vm/instructions/system.v | 684 ++++-- .../ethereum/shanghai/vm/interpreter.v | 390 +++- CoqOfPython/ethereum/shanghai/vm/memory.v | 67 +- .../vm/precompiled_contracts/__init__.v | 6 +- .../vm/precompiled_contracts/alt_bn128.v | 167 +- .../vm/precompiled_contracts/blake2f.v | 22 +- .../vm/precompiled_contracts/ecrecover.v | 90 +- .../vm/precompiled_contracts/identity.v | 20 +- .../vm/precompiled_contracts/mapping.v | 110 +- .../vm/precompiled_contracts/modexp.v | 158 +- .../vm/precompiled_contracts/ripemd160.v | 20 +- .../vm/precompiled_contracts/sha256.v | 20 +- CoqOfPython/ethereum/shanghai/vm/runtime.v | 55 +- CoqOfPython/ethereum/shanghai/vm/stack.v | 48 +- CoqOfPython/ethereum/spurious_dragon/blocks.v | 58 +- CoqOfPython/ethereum/spurious_dragon/bloom.v | 18 +- CoqOfPython/ethereum/spurious_dragon/fork.v | 474 +++- .../ethereum/spurious_dragon/fork_types.v | 47 +- CoqOfPython/ethereum/spurious_dragon/state.v | 199 +- .../ethereum/spurious_dragon/transactions.v | 30 +- CoqOfPython/ethereum/spurious_dragon/trie.v | 625 ++++- .../ethereum/spurious_dragon/utils/address.v | 18 +- .../spurious_dragon/utils/hexadecimal.v | 17 +- .../ethereum/spurious_dragon/utils/message.v | 125 +- .../ethereum/spurious_dragon/vm/__init__.v | 104 +- CoqOfPython/ethereum/spurious_dragon/vm/gas.v | 113 +- .../vm/instructions/__init__.v | 72 +- .../vm/instructions/arithmetic.v | 205 +- .../spurious_dragon/vm/instructions/bitwise.v | 45 +- .../spurious_dragon/vm/instructions/block.v | 58 +- .../vm/instructions/comparison.v | 26 +- .../vm/instructions/control_flow.v | 84 +- .../vm/instructions/environment.v | 78 +- .../spurious_dragon/vm/instructions/keccak.v | 46 +- .../spurious_dragon/vm/instructions/log.v | 54 +- .../spurious_dragon/vm/instructions/memory.v | 44 +- .../spurious_dragon/vm/instructions/stack.v | 42 +- .../spurious_dragon/vm/instructions/storage.v | 93 +- .../spurious_dragon/vm/instructions/system.v | 577 ++++- .../ethereum/spurious_dragon/vm/interpreter.v | 378 ++- .../ethereum/spurious_dragon/vm/memory.v | 67 +- .../vm/precompiled_contracts/__init__.v | 6 +- .../vm/precompiled_contracts/ecrecover.v | 90 +- .../vm/precompiled_contracts/identity.v | 20 +- .../vm/precompiled_contracts/mapping.v | 58 +- .../vm/precompiled_contracts/ripemd160.v | 20 +- .../vm/precompiled_contracts/sha256.v | 20 +- .../ethereum/spurious_dragon/vm/runtime.v | 55 +- .../ethereum/spurious_dragon/vm/stack.v | 48 +- .../ethereum/tangerine_whistle/blocks.v | 58 +- .../ethereum/tangerine_whistle/bloom.v | 18 +- CoqOfPython/ethereum/tangerine_whistle/fork.v | 364 ++- .../ethereum/tangerine_whistle/fork_types.v | 47 +- .../ethereum/tangerine_whistle/state.v | 182 +- .../ethereum/tangerine_whistle/transactions.v | 30 +- CoqOfPython/ethereum/tangerine_whistle/trie.v | 625 ++++- .../tangerine_whistle/utils/address.v | 18 +- .../tangerine_whistle/utils/hexadecimal.v | 17 +- .../tangerine_whistle/utils/message.v | 125 +- .../ethereum/tangerine_whistle/vm/__init__.v | 18 +- .../ethereum/tangerine_whistle/vm/gas.v | 113 +- .../vm/instructions/__init__.v | 72 +- .../vm/instructions/arithmetic.v | 205 +- .../vm/instructions/bitwise.v | 45 +- .../tangerine_whistle/vm/instructions/block.v | 58 +- .../vm/instructions/comparison.v | 26 +- .../vm/instructions/control_flow.v | 84 +- .../vm/instructions/environment.v | 78 +- .../vm/instructions/keccak.v | 46 +- .../tangerine_whistle/vm/instructions/log.v | 54 +- .../vm/instructions/memory.v | 44 +- .../tangerine_whistle/vm/instructions/stack.v | 42 +- .../vm/instructions/storage.v | 93 +- .../vm/instructions/system.v | 506 +++- .../tangerine_whistle/vm/interpreter.v | 321 ++- .../ethereum/tangerine_whistle/vm/memory.v | 67 +- .../vm/precompiled_contracts/__init__.v | 6 +- .../vm/precompiled_contracts/ecrecover.v | 90 +- .../vm/precompiled_contracts/identity.v | 20 +- .../vm/precompiled_contracts/mapping.v | 58 +- .../vm/precompiled_contracts/ripemd160.v | 20 +- .../vm/precompiled_contracts/sha256.v | 20 +- .../ethereum/tangerine_whistle/vm/runtime.v | 55 +- .../ethereum/tangerine_whistle/vm/stack.v | 48 +- CoqOfPython/ethereum/utils/byte.v | 2 + CoqOfPython/ethereum/utils/ensure.v | 13 +- CoqOfPython/ethereum/utils/hexadecimal.v | 34 + CoqOfPython/ethereum/utils/numeric.v | 91 +- CoqOfPython/functools.v | 3 + CoqOfPython/typing_extensions.v | 3 + convert_all.py | 2 +- main.py | 101 +- 611 files changed, 66894 insertions(+), 15285 deletions(-) create mode 100644 CoqOfPython/functools.v create mode 100644 CoqOfPython/typing_extensions.v diff --git a/CoqOfPython/ethereum/arrow_glacier/blocks.v b/CoqOfPython/ethereum/arrow_glacier/blocks.v index a90217e..f65b16f 100644 --- a/CoqOfPython/ethereum/arrow_glacier/blocks.v +++ b/CoqOfPython/ethereum/arrow_glacier/blocks.v @@ -24,35 +24,35 @@ Axiom typing_Tuple : Axiom typing_Union : IsGlobalAlias globals typing.globals "Union". -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes8 : - IsGlobalAlias globals base_types.globals "Bytes8". -Axiom base_types_Bytes32 : - IsGlobalAlias globals base_types.globals "Bytes32". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require crypto.hash. -Axiom crypto_hash_Hash32 : - IsGlobalAlias globals crypto.hash.globals "Hash32". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". - -Require transactions. -Axiom transactions_LegacyTransaction : - IsGlobalAlias globals transactions.globals "LegacyTransaction". +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes8 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes8". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". + +Require ethereum.arrow_glacier.fork_types. +Axiom ethereum_arrow_glacier_fork_types_Address : + IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "Address". +Axiom ethereum_arrow_glacier_fork_types_Bloom : + IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "Bloom". +Axiom ethereum_arrow_glacier_fork_types_Root : + IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "Root". + +Require ethereum.arrow_glacier.transactions. +Axiom ethereum_arrow_glacier_transactions_LegacyTransaction : + IsGlobalAlias globals ethereum.arrow_glacier.transactions.globals "LegacyTransaction". Definition Header : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/arrow_glacier/bloom.v b/CoqOfPython/ethereum/arrow_glacier/bloom.v index 04650ff..de6ac5b 100644 --- a/CoqOfPython/ethereum/arrow_glacier/bloom.v +++ b/CoqOfPython/ethereum/arrow_glacier/bloom.v @@ -33,13 +33,13 @@ Require ethereum.crypto.hash. Axiom ethereum_crypto_hash_keccak256 : IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". +Require ethereum.arrow_glacier.blocks. +Axiom ethereum_arrow_glacier_blocks_Log : + IsGlobalAlias globals ethereum.arrow_glacier.blocks.globals "Log". -Require fork_types. -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". +Require ethereum.arrow_glacier.fork_types. +Axiom ethereum_arrow_glacier_fork_types_Bloom : + IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "Bloom". Definition add_to_bloom : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -72,7 +72,10 @@ Definition add_to_bloom : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |) |) + M.get_subscript (| M.get_name (| globals, "hash" |), M.slice (| M.get_name (| globals, "idx" |), BinOp.add (| + M.get_name (| globals, "idx" |), + Constant.int 2 + |) |) |) ], make_dict [] |), @@ -157,4 +160,5 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/fork.v b/CoqOfPython/ethereum/arrow_glacier/fork.v index df8d355..563f3b3 100644 --- a/CoqOfPython/ethereum/arrow_glacier/fork.v +++ b/CoqOfPython/ethereum/arrow_glacier/fork.v @@ -65,107 +65,107 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U64 : - IsGlobalAlias globals base_types.globals "U64". -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_U256_CEIL_VALUE : - IsGlobalAlias globals base_types.globals "U256_CEIL_VALUE". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". - -Require __init__. -Axiom __init___vm : - IsGlobalAlias globals __init__.globals "vm". - -Require blocks. -Axiom blocks_Block : - IsGlobalAlias globals blocks.globals "Block". -Axiom blocks_Header : - IsGlobalAlias globals blocks.globals "Header". -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". -Axiom blocks_Receipt : - IsGlobalAlias globals blocks.globals "Receipt". - -Require bloom. -Axiom bloom_logs_bloom : - IsGlobalAlias globals bloom.globals "logs_bloom". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". - -Require state. -Axiom state_State : - IsGlobalAlias globals state.globals "State". -Axiom state_account_exists_and_is_empty : - IsGlobalAlias globals state.globals "account_exists_and_is_empty". -Axiom state_create_ether : - IsGlobalAlias globals state.globals "create_ether". -Axiom state_destroy_account : - IsGlobalAlias globals state.globals "destroy_account". -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". -Axiom state_increment_nonce : - IsGlobalAlias globals state.globals "increment_nonce". -Axiom state_set_account_balance : - IsGlobalAlias globals state.globals "set_account_balance". -Axiom state_state_root : - IsGlobalAlias globals state.globals "state_root". - -Require transactions. -Axiom transactions_TX_ACCESS_LIST_ADDRESS_COST : - IsGlobalAlias globals transactions.globals "TX_ACCESS_LIST_ADDRESS_COST". -Axiom transactions_TX_ACCESS_LIST_STORAGE_KEY_COST : - IsGlobalAlias globals transactions.globals "TX_ACCESS_LIST_STORAGE_KEY_COST". -Axiom transactions_TX_BASE_COST : - IsGlobalAlias globals transactions.globals "TX_BASE_COST". -Axiom transactions_TX_CREATE_COST : - IsGlobalAlias globals transactions.globals "TX_CREATE_COST". -Axiom transactions_TX_DATA_COST_PER_NON_ZERO : - IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_NON_ZERO". -Axiom transactions_TX_DATA_COST_PER_ZERO : - IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_ZERO". -Axiom transactions_AccessListTransaction : - IsGlobalAlias globals transactions.globals "AccessListTransaction". -Axiom transactions_FeeMarketTransaction : - IsGlobalAlias globals transactions.globals "FeeMarketTransaction". -Axiom transactions_LegacyTransaction : - IsGlobalAlias globals transactions.globals "LegacyTransaction". -Axiom transactions_Transaction : - IsGlobalAlias globals transactions.globals "Transaction". -Axiom transactions_decode_transaction : - IsGlobalAlias globals transactions.globals "decode_transaction". -Axiom transactions_encode_transaction : - IsGlobalAlias globals transactions.globals "encode_transaction". - -Require trie. -Axiom trie_Trie : - IsGlobalAlias globals trie.globals "Trie". -Axiom trie_root : - IsGlobalAlias globals trie.globals "root". -Axiom trie_trie_set : - IsGlobalAlias globals trie.globals "trie_set". - -Require utils.message. -Axiom utils_message_prepare_message : - IsGlobalAlias globals utils.message.globals "prepare_message". - -Require vm.interpreter. -Axiom vm_interpreter_process_message_call : - IsGlobalAlias globals vm.interpreter.globals "process_message_call". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U64 : + IsGlobalAlias globals ethereum.base_types.globals "U64". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_U256_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.arrow_glacier.__init__. +Axiom ethereum_arrow_glacier___init___vm : + IsGlobalAlias globals ethereum.arrow_glacier.__init__.globals "vm". + +Require ethereum.arrow_glacier.blocks. +Axiom ethereum_arrow_glacier_blocks_Block : + IsGlobalAlias globals ethereum.arrow_glacier.blocks.globals "Block". +Axiom ethereum_arrow_glacier_blocks_Header : + IsGlobalAlias globals ethereum.arrow_glacier.blocks.globals "Header". +Axiom ethereum_arrow_glacier_blocks_Log : + IsGlobalAlias globals ethereum.arrow_glacier.blocks.globals "Log". +Axiom ethereum_arrow_glacier_blocks_Receipt : + IsGlobalAlias globals ethereum.arrow_glacier.blocks.globals "Receipt". + +Require ethereum.arrow_glacier.bloom. +Axiom ethereum_arrow_glacier_bloom_logs_bloom : + IsGlobalAlias globals ethereum.arrow_glacier.bloom.globals "logs_bloom". + +Require ethereum.arrow_glacier.fork_types. +Axiom ethereum_arrow_glacier_fork_types_Address : + IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "Address". +Axiom ethereum_arrow_glacier_fork_types_Bloom : + IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "Bloom". +Axiom ethereum_arrow_glacier_fork_types_Root : + IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "Root". + +Require ethereum.arrow_glacier.state. +Axiom ethereum_arrow_glacier_state_State : + IsGlobalAlias globals ethereum.arrow_glacier.state.globals "State". +Axiom ethereum_arrow_glacier_state_account_exists_and_is_empty : + IsGlobalAlias globals ethereum.arrow_glacier.state.globals "account_exists_and_is_empty". +Axiom ethereum_arrow_glacier_state_create_ether : + IsGlobalAlias globals ethereum.arrow_glacier.state.globals "create_ether". +Axiom ethereum_arrow_glacier_state_destroy_account : + IsGlobalAlias globals ethereum.arrow_glacier.state.globals "destroy_account". +Axiom ethereum_arrow_glacier_state_get_account : + IsGlobalAlias globals ethereum.arrow_glacier.state.globals "get_account". +Axiom ethereum_arrow_glacier_state_increment_nonce : + IsGlobalAlias globals ethereum.arrow_glacier.state.globals "increment_nonce". +Axiom ethereum_arrow_glacier_state_set_account_balance : + IsGlobalAlias globals ethereum.arrow_glacier.state.globals "set_account_balance". +Axiom ethereum_arrow_glacier_state_state_root : + IsGlobalAlias globals ethereum.arrow_glacier.state.globals "state_root". + +Require ethereum.arrow_glacier.transactions. +Axiom ethereum_arrow_glacier_transactions_TX_ACCESS_LIST_ADDRESS_COST : + IsGlobalAlias globals ethereum.arrow_glacier.transactions.globals "TX_ACCESS_LIST_ADDRESS_COST". +Axiom ethereum_arrow_glacier_transactions_TX_ACCESS_LIST_STORAGE_KEY_COST : + IsGlobalAlias globals ethereum.arrow_glacier.transactions.globals "TX_ACCESS_LIST_STORAGE_KEY_COST". +Axiom ethereum_arrow_glacier_transactions_TX_BASE_COST : + IsGlobalAlias globals ethereum.arrow_glacier.transactions.globals "TX_BASE_COST". +Axiom ethereum_arrow_glacier_transactions_TX_CREATE_COST : + IsGlobalAlias globals ethereum.arrow_glacier.transactions.globals "TX_CREATE_COST". +Axiom ethereum_arrow_glacier_transactions_TX_DATA_COST_PER_NON_ZERO : + IsGlobalAlias globals ethereum.arrow_glacier.transactions.globals "TX_DATA_COST_PER_NON_ZERO". +Axiom ethereum_arrow_glacier_transactions_TX_DATA_COST_PER_ZERO : + IsGlobalAlias globals ethereum.arrow_glacier.transactions.globals "TX_DATA_COST_PER_ZERO". +Axiom ethereum_arrow_glacier_transactions_AccessListTransaction : + IsGlobalAlias globals ethereum.arrow_glacier.transactions.globals "AccessListTransaction". +Axiom ethereum_arrow_glacier_transactions_FeeMarketTransaction : + IsGlobalAlias globals ethereum.arrow_glacier.transactions.globals "FeeMarketTransaction". +Axiom ethereum_arrow_glacier_transactions_LegacyTransaction : + IsGlobalAlias globals ethereum.arrow_glacier.transactions.globals "LegacyTransaction". +Axiom ethereum_arrow_glacier_transactions_Transaction : + IsGlobalAlias globals ethereum.arrow_glacier.transactions.globals "Transaction". +Axiom ethereum_arrow_glacier_transactions_decode_transaction : + IsGlobalAlias globals ethereum.arrow_glacier.transactions.globals "decode_transaction". +Axiom ethereum_arrow_glacier_transactions_encode_transaction : + IsGlobalAlias globals ethereum.arrow_glacier.transactions.globals "encode_transaction". + +Require ethereum.arrow_glacier.trie. +Axiom ethereum_arrow_glacier_trie_Trie : + IsGlobalAlias globals ethereum.arrow_glacier.trie.globals "Trie". +Axiom ethereum_arrow_glacier_trie_root : + IsGlobalAlias globals ethereum.arrow_glacier.trie.globals "root". +Axiom ethereum_arrow_glacier_trie_trie_set : + IsGlobalAlias globals ethereum.arrow_glacier.trie.globals "trie_set". + +Require ethereum.arrow_glacier.utils.message. +Axiom ethereum_arrow_glacier_utils_message_prepare_message : + IsGlobalAlias globals ethereum.arrow_glacier.utils.message.globals "prepare_message". + +Require ethereum.arrow_glacier.vm.interpreter. +Axiom ethereum_arrow_glacier_vm_interpreter_process_message_call : + IsGlobalAlias globals ethereum.arrow_glacier.vm.interpreter.globals "process_message_call". Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -266,6 +266,7 @@ Definition apply_fork : Value.t -> Value.t -> M := " in let _ := M.return_ (| M.get_name (| globals, "old" |) + |) in M.pure Constant.None_)). Definition get_last_256_block_hashes : Value.t -> Value.t -> M := @@ -291,8 +292,28 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := Hashes of the recent 256 blocks in order of increasing block number. " in let recent_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |) |) in + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "recent_blocks" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + make_list [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let recent_block_hashes := @@ -331,6 +352,7 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "recent_block_hashes" |) + |) in M.pure Constant.None_)). Definition state_transition : Value.t -> Value.t -> M := @@ -463,6 +485,27 @@ Definition state_transition : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |) + ], + make_dict [] + |), + Constant.int 255 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -510,7 +553,63 @@ Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "parent_gas_used" |), + M.get_name (| globals, "parent_gas_target" |) + |), + (* then *) + ltac:(M.monadic ( + let expected_base_fee_per_gas := + M.get_name (| globals, "parent_base_fee_per_gas" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "parent_gas_used" |), + M.get_name (| globals, "parent_gas_target" |) + |), + (* then *) + ltac:(M.monadic ( + let gas_used_delta := + BinOp.sub (| + M.get_name (| globals, "parent_gas_used" |), + M.get_name (| globals, "parent_gas_target" |) + |) in + let parent_fee_gas_delta := + BinOp.mult (| + M.get_name (| globals, "parent_base_fee_per_gas" |), + M.get_name (| globals, "gas_used_delta" |) + |) in + let target_fee_gas_delta := + BinOp.floor_div (| + M.get_name (| globals, "parent_fee_gas_delta" |), + M.get_name (| globals, "parent_gas_target" |) + |) in + let base_fee_per_gas_delta := + M.call (| + M.get_name (| globals, "max" |), + make_list [ + BinOp.floor_div (| + M.get_name (| globals, "target_fee_gas_delta" |), + M.get_name (| globals, "BASE_FEE_MAX_CHANGE_DENOMINATOR" |) + |); + Constant.int 1 + ], + make_dict [] + |) in + let expected_base_fee_per_gas := + BinOp.add (| + M.get_name (| globals, "parent_base_fee_per_gas" |), + M.get_name (| globals, "base_fee_per_gas_delta" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let gas_used_delta := BinOp.sub (| M.get_name (| globals, "parent_gas_target" |), @@ -548,6 +647,7 @@ Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition validate_header : Value.t -> Value.t -> M := @@ -757,6 +857,7 @@ Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition validate_proof_of_work : Value.t -> Value.t -> M := @@ -894,6 +995,60 @@ Definition check_transaction : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "FeeMarketTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt_e (| + M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |), + M.get_field (| M.get_name (| globals, "tx" |), "max_priority_fee_per_gas" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt_e (| + M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |), + M.get_name (| globals, "base_fee_per_gas" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let priority_fee_per_gas := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_field (| M.get_name (| globals, "tx" |), "max_priority_fee_per_gas" |); + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |), + M.get_name (| globals, "base_fee_per_gas" |) + |) + ], + make_dict [] + |) in + let effective_gas_price := + BinOp.add (| + M.get_name (| globals, "priority_fee_per_gas" |), + M.get_name (| globals, "base_fee_per_gas" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -911,6 +1066,7 @@ Definition check_transaction : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| make_tuple [ M.get_name (| globals, "sender_address" |); M.get_name (| globals, "effective_gas_price" |) ] + |) in M.pure Constant.None_)). Definition make_receipt : Value.t -> Value.t -> M := @@ -943,9 +1099,64 @@ Definition make_receipt : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "AccessListTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + Constant.bytes "01", + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "receipt" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "FeeMarketTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + Constant.bytes "02", + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "receipt" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "receipt" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -1178,6 +1389,7 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition validate_ommers : Value.t -> Value.t -> M := @@ -1230,6 +1442,26 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do @@ -1287,7 +1519,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let ommers_hashes := - (* At expr: unsupported node type: ListComp *) in + Constant.str "(* At expr: unsupported node type: ListComp *)" in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1318,19 +1550,19 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let recent_canonical_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| BinOp.add (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| BinOp.add (| M.get_name (| globals, "MAX_OMMER_DEPTH" |), Constant.int 1 - |) |) |) in + |) |), Constant.None_ |) |) in let recent_canonical_block_hashes := - (* At expr: unsupported node type: SetComp *) in + Constant.str "(* At expr: unsupported node type: SetComp *)" in (* At stmt: unsupported node type: AnnAssign *) For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_canonical_blocks" |) do let recent_ommers_hashes := M.call (| M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), make_list [ - (* At expr: unsupported node type: SetComp *) + Constant.str "(* At expr: unsupported node type: SetComp *)" ], make_dict [] |) in @@ -1570,6 +1802,26 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "FeeMarketTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let max_gas_fee := + BinOp.mult (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let max_gas_fee := BinOp.mult (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), @@ -1668,6 +1920,39 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + make_tuple [ M.get_name (| globals, "AccessListTransaction" |); M.get_name (| globals, "FeeMarketTransaction" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + For make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "keys" |) ] in M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "preaccessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "key" |) in M.get_name (| globals, "keys" |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "preaccessed_storage_keys" |), "add" |), + make_list [ + make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "key" |) ] + ], + make_dict [] + |) in + EndFor. + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let message := @@ -1772,7 +2057,50 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "transaction_fee" |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| + M.get_name (| globals, "coinbase_balance_after_mining_fee" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |); + M.get_name (| globals, "coinbase_balance_after_mining_fee" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -1789,11 +2117,35 @@ Definition process_transaction : Value.t -> Value.t -> M := EndFor. For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "touched_accounts" |) do let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := M.return_ (| make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |); M.get_field (| M.get_name (| globals, "output" |), "error" |) ] + |) in M.pure Constant.None_)). Definition validate_transaction : Value.t -> Value.t -> M := @@ -1848,6 +2200,7 @@ Definition validate_transaction : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := @@ -1879,6 +2232,20 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := Constant.int 0 in For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "byte" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let data_cost := BinOp.add M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in @@ -1886,6 +2253,25 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := )) |) in EndFor. let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "tx" |), "to" |), + M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) + |), + (* then *) + ltac:(M.monadic ( + let create_cost := + M.get_name (| globals, "TX_CREATE_COST" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let create_cost := Constant.int 0 in M.pure Constant.None_ @@ -1893,6 +2279,47 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := let access_list_cost := Constant.int 0 in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + make_tuple [ M.get_name (| globals, "AccessListTransaction" |); M.get_name (| globals, "FeeMarketTransaction" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + For make_tuple [ M.get_name (| globals, "_address" |); M.get_name (| globals, "keys" |) ] in M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) do + let access_list_cost := BinOp.add + M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) + M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) in + let access_list_cost := BinOp.add + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "keys" |) + ], + make_dict [] + |), + M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) + |) + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "keys" |) + ], + make_dict [] + |), + M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) + |) in + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1912,6 +2339,7 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition recover_sender : Value.t -> Value.t -> M := @@ -1984,8 +2412,189 @@ Definition recover_sender : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "LegacyTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let v := + M.get_field (| M.get_name (| globals, "tx" |), "v" |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.eq (| + M.get_name (| globals, "v" |), + Constant.int 27 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "v" |), + Constant.int 28 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + BinOp.sub (| + M.get_name (| globals, "v" |), + Constant.int 27 + |); + M.call (| + M.get_name (| globals, "signing_hash_pre155" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.or (| + Compare.eq (| + M.get_name (| globals, "v" |), + BinOp.add (| + Constant.int 35, + BinOp.mult (| + M.get_name (| globals, "chain_id" |), + Constant.int 2 + |) + |) + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "v" |), + BinOp.add (| + Constant.int 36, + BinOp.mult (| + M.get_name (| globals, "chain_id" |), + Constant.int 2 + |) + |) + |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + BinOp.sub (| + BinOp.sub (| + M.get_name (| globals, "v" |), + Constant.int 35 + |), + BinOp.mult (| + M.get_name (| globals, "chain_id" |), + Constant.int 2 + |) + |); + M.call (| + M.get_name (| globals, "signing_hash_155" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "chain_id" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "AccessListTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + M.get_field (| M.get_name (| globals, "tx" |), "y_parity" |); + M.call (| + M.get_name (| globals, "signing_hash_2930" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "FeeMarketTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + M.get_field (| M.get_name (| globals, "tx" |), "y_parity" |); + M.call (| + M.get_name (| globals, "signing_hash_1559" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -2002,10 +2611,11 @@ Definition recover_sender : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12 |) + |), M.slice (| Constant.int 12, Constant.int 32 |) |) ], make_dict [] |) + |) in M.pure Constant.None_)). Definition signing_hash_pre155 : Value.t -> Value.t -> M := @@ -2038,6 +2648,7 @@ Definition signing_hash_pre155 : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition signing_hash_155 : Value.t -> Value.t -> M := @@ -2084,6 +2695,7 @@ Definition signing_hash_155 : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition signing_hash_2930 : Value.t -> Value.t -> M := @@ -2119,6 +2731,7 @@ Definition signing_hash_2930 : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition signing_hash_1559 : Value.t -> Value.t -> M := @@ -2154,6 +2767,7 @@ Definition signing_hash_1559 : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition compute_header_hash : Value.t -> Value.t -> M := @@ -2204,6 +2818,7 @@ Definition compute_header_hash : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition check_gas_limit : Value.t -> Value.t -> M := @@ -2242,16 +2857,65 @@ Definition check_gas_limit : Value.t -> Value.t -> M := M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "gas_limit" |), + BinOp.add (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "gas_limit" |), + BinOp.sub (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "gas_limit" |), + M.get_name (| globals, "GAS_LIMIT_MINIMUM" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| Constant.bool true + |) in M.pure Constant.None_)). Definition calculate_block_difficulty : Value.t -> Value.t -> M := @@ -2311,12 +2975,16 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := M.get_name (| globals, "max" |), make_list [ BinOp.sub (| - (* if *) -M.if_then_else (| - M.get_name (| globals, "parent_has_ommers" |), -(* then *) -ltac:(M.monadic ( -Constant.int 2, + (* if *) + M.if_then_else (| + M.get_name (| globals, "parent_has_ommers" |), + (* then *) + ltac:(M.monadic ( +Constant.int 2 + (* else *) + )), ltac:(M.monadic ( +Constant.int 1 + )) |), BinOp.floor_div (| M.call (| M.get_name (| globals, "int" |), @@ -2365,6 +3033,26 @@ Constant.int 2, Constant.int 2 |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "num_bomb_periods" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let difficulty := BinOp.add + BinOp.pow (| + Constant.int 2, + M.get_name (| globals, "num_bomb_periods" |) + |) + BinOp.pow (| + Constant.int 2, + M.get_name (| globals, "num_bomb_periods" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -2382,4 +3070,5 @@ Constant.int 2, ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/fork_types.v b/CoqOfPython/ethereum/arrow_glacier/fork_types.v index 5c7dac3..cc8e4a1 100644 --- a/CoqOfPython/ethereum/arrow_glacier/fork_types.v +++ b/CoqOfPython/ethereum/arrow_glacier/fork_types.v @@ -21,29 +21,29 @@ Require dataclasses. Axiom dataclasses_dataclass : IsGlobalAlias globals dataclasses.globals "dataclass". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes20 : - IsGlobalAlias globals base_types.globals "Bytes20". -Axiom base_types_Bytes256 : - IsGlobalAlias globals base_types.globals "Bytes256". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require crypto.hash. -Axiom crypto_hash_Hash32 : - IsGlobalAlias globals crypto.hash.globals "Hash32". -Axiom crypto_hash_keccak256 : - IsGlobalAlias globals crypto.hash.globals "keccak256". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes20 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes20". +Axiom ethereum_base_types_Bytes256 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) @@ -98,4 +98,5 @@ Definition encode_account : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/state.v b/CoqOfPython/ethereum/arrow_glacier/state.v index c3290a6..54c9d2e 100644 --- a/CoqOfPython/ethereum/arrow_glacier/state.v +++ b/CoqOfPython/ethereum/arrow_glacier/state.v @@ -56,29 +56,29 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require fork_types. -Axiom fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". -Axiom fork_types_Account : - IsGlobalAlias globals fork_types.globals "Account". -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". - -Require trie. -Axiom trie_EMPTY_TRIE_ROOT : - IsGlobalAlias globals trie.globals "EMPTY_TRIE_ROOT". -Axiom trie_Trie : - IsGlobalAlias globals trie.globals "Trie". -Axiom trie_copy_trie : - IsGlobalAlias globals trie.globals "copy_trie". -Axiom trie_root : - IsGlobalAlias globals trie.globals "root". -Axiom trie_trie_get : - IsGlobalAlias globals trie.globals "trie_get". -Axiom trie_trie_set : - IsGlobalAlias globals trie.globals "trie_set". +Require ethereum.arrow_glacier.fork_types. +Axiom ethereum_arrow_glacier_fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "EMPTY_ACCOUNT". +Axiom ethereum_arrow_glacier_fork_types_Account : + IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "Account". +Axiom ethereum_arrow_glacier_fork_types_Address : + IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "Address". +Axiom ethereum_arrow_glacier_fork_types_Root : + IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "Root". + +Require ethereum.arrow_glacier.trie. +Axiom ethereum_arrow_glacier_trie_EMPTY_TRIE_ROOT : + IsGlobalAlias globals ethereum.arrow_glacier.trie.globals "EMPTY_TRIE_ROOT". +Axiom ethereum_arrow_glacier_trie_Trie : + IsGlobalAlias globals ethereum.arrow_glacier.trie.globals "Trie". +Axiom ethereum_arrow_glacier_trie_copy_trie : + IsGlobalAlias globals ethereum.arrow_glacier.trie.globals "copy_trie". +Axiom ethereum_arrow_glacier_trie_root : + IsGlobalAlias globals ethereum.arrow_glacier.trie.globals "root". +Axiom ethereum_arrow_glacier_trie_trie_get : + IsGlobalAlias globals ethereum.arrow_glacier.trie.globals "trie_get". +Axiom ethereum_arrow_glacier_trie_trie_set : + IsGlobalAlias globals ethereum.arrow_glacier.trie.globals "trie_set". Definition State : Value.t := builtins.make_klass @@ -126,7 +126,7 @@ Definition begin_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) ], make_dict [] - |); (* At expr: unsupported node type: DictComp *) ] + |); Constant.str "(* At expr: unsupported node type: DictComp *)" ] ], make_dict [] |) in @@ -149,6 +149,19 @@ Definition commit_transaction : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "clear" |), + make_list [], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -174,6 +187,19 @@ Definition rollback_transaction : Value.t -> Value.t -> M := |) |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "clear" |), + make_list [], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -210,8 +236,27 @@ Definition get_account : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "account" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "account" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_ACCOUNT" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -246,6 +291,7 @@ Definition get_account_optional : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "account" |) + |) in M.pure Constant.None_)). Definition set_account : Value.t -> Value.t -> M := @@ -325,6 +371,18 @@ Definition destroy_storage : Value.t -> Value.t -> M := Address of account whose storage is to be deleted. " in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -387,6 +445,26 @@ Definition get_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "trie" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let value := @@ -408,6 +486,7 @@ Definition get_storage : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "value" |) + |) in M.pure Constant.None_)). Definition set_storage : Value.t -> Value.t -> M := @@ -448,6 +527,27 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "trie" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let trie := + M.call (| + M.get_name (| globals, "Trie" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), + M.get_name (| globals, "trie" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -460,6 +560,18 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + {} + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -484,8 +596,29 @@ Definition storage_root : Value.t -> Value.t -> M := " in let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_TRIE_ROOT" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -516,6 +649,7 @@ Definition state_root : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition account_exists : Value.t -> Value.t -> M := @@ -548,6 +682,7 @@ Definition account_exists : Value.t -> Value.t -> M := |), Constant.None_ |) + |) in M.pure Constant.None_)). Definition account_has_code_or_nonce : Value.t -> Value.t -> M := @@ -597,6 +732,7 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition is_account_empty : Value.t -> Value.t -> M := @@ -654,6 +790,7 @@ Definition is_account_empty : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition account_exists_and_is_empty : Value.t -> Value.t -> M := @@ -720,6 +857,7 @@ Definition account_exists_and_is_empty : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition is_account_alive : Value.t -> Value.t -> M := @@ -750,6 +888,20 @@ Definition is_account_alive : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "account" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| UnOp.not (| BoolOp.and (| Compare.eq (| @@ -777,6 +929,7 @@ Definition is_account_alive : Value.t -> Value.t -> M := |) )) |) |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -884,6 +1037,30 @@ Definition touch_account : Value.t -> Value.t -> M := The address of the account that need to initialised. " in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "account_exists" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "EMPTY_ACCOUNT" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -988,6 +1165,26 @@ Definition get_storage_original : Value.t -> Value.t -> M := Key of the storage slot. " in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -1003,6 +1200,25 @@ Definition get_storage_original : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "original_account_trie" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let original_value := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let original_value := M.call (| M.get_name (| globals, "trie_get" |), @@ -1024,4 +1240,5 @@ Definition get_storage_original : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "original_value" |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/transactions.v b/CoqOfPython/ethereum/arrow_glacier/transactions.v index afa27ec..03937fc 100644 --- a/CoqOfPython/ethereum/arrow_glacier/transactions.v +++ b/CoqOfPython/ethereum/arrow_glacier/transactions.v @@ -19,33 +19,33 @@ Axiom typing_Tuple : Axiom typing_Union : IsGlobalAlias globals typing.globals "Union". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U64 : - IsGlobalAlias globals base_types.globals "U64". -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes0 : - IsGlobalAlias globals base_types.globals "Bytes0". -Axiom base_types_Bytes32 : - IsGlobalAlias globals base_types.globals "Bytes32". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require exceptions. -Axiom exceptions_InvalidBlock : - IsGlobalAlias globals exceptions.globals "InvalidBlock". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U64 : + IsGlobalAlias globals ethereum.base_types.globals "U64". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.exceptions. +Axiom ethereum_exceptions_InvalidBlock : + IsGlobalAlias globals ethereum.exceptions.globals "InvalidBlock". + +Require ethereum.arrow_glacier.fork_types. +Axiom ethereum_arrow_glacier_fork_types_Address : + IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "Address". Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( Constant.int 21000 @@ -112,15 +112,87 @@ Definition encode_transaction : Value.t -> Value.t -> M := Encode a transaction. Needed because non-legacy transactions aren't RLP. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "LegacyTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "tx" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "AccessListTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + Constant.bytes "01", + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "FeeMarketTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + Constant.bytes "02", + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.raise (| Some(M.call (| M.get_name (| globals, "Exception" |), make_list [ - (* At expr: unsupported node type: JoinedStr *) + Constant.str "(* At expr: unsupported node type: JoinedStr *)" ], make_dict [] - |)) + |)) |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -136,8 +208,73 @@ Definition decode_transaction : Value.t -> Value.t -> M := Decode a transaction. Needed because non-legacy transactions aren't RLP. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), + Constant.int 1 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), + make_list [ + M.get_name (| globals, "AccessListTransaction" |); + M.get_subscript (| M.get_name (| globals, "tx" |), M.slice (| Constant.int 1, Constant.None_ |) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), + Constant.int 2 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), + make_list [ + M.get_name (| globals, "FeeMarketTransaction" |); + M.get_subscript (| M.get_name (| globals, "tx" |), M.slice (| Constant.int 1, Constant.None_ |) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidBlock" |)) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "tx" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/trie.v b/CoqOfPython/ethereum/arrow_glacier/trie.v index 17d829e..ca56755 100644 --- a/CoqOfPython/ethereum/arrow_glacier/trie.v +++ b/CoqOfPython/ethereum/arrow_glacier/trie.v @@ -54,9 +54,9 @@ Require ethereum.crypto.hash. Axiom ethereum_crypto_hash_keccak256 : IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". -Require ethereum.london. -Axiom ethereum_london_trie : - IsGlobalAlias globals ethereum.london.globals "trie". +Require ethereum.london.__init__. +Axiom ethereum_london___init___trie : + IsGlobalAlias globals ethereum.london.__init__.globals "trie". Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : @@ -66,37 +66,37 @@ Require ethereum.utils.hexadecimal. Axiom ethereum_utils_hexadecimal_hex_to_bytes : IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require blocks. -Axiom blocks_Receipt : - IsGlobalAlias globals blocks.globals "Receipt". - -Require fork_types. -Axiom fork_types_Account : - IsGlobalAlias globals fork_types.globals "Account". -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". -Axiom fork_types_encode_account : - IsGlobalAlias globals fork_types.globals "encode_account". - -Require transactions. -Axiom transactions_LegacyTransaction : - IsGlobalAlias globals transactions.globals "LegacyTransaction". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.arrow_glacier.blocks. +Axiom ethereum_arrow_glacier_blocks_Receipt : + IsGlobalAlias globals ethereum.arrow_glacier.blocks.globals "Receipt". + +Require ethereum.arrow_glacier.fork_types. +Axiom ethereum_arrow_glacier_fork_types_Account : + IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "Account". +Axiom ethereum_arrow_glacier_fork_types_Address : + IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "Address". +Axiom ethereum_arrow_glacier_fork_types_Root : + IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "Root". +Axiom ethereum_arrow_glacier_fork_types_encode_account : + IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "encode_account". + +Require ethereum.arrow_glacier.transactions. +Axiom ethereum_arrow_glacier_transactions_LegacyTransaction : + IsGlobalAlias globals ethereum.arrow_glacier.transactions.globals "LegacyTransaction". Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -202,16 +202,99 @@ Definition encode_internal_node : Value.t -> Value.t -> M := " in (* At stmt: unsupported node type: AnnAssign *) let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "node" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + Constant.bytes "" in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "LeafNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "rest_of_key" |); + Constant.bool true + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "ExtensionNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "key_segment" |); + Constant.bool false + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "BranchNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + BinOp.add (| + M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "value" |) + ] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ - (* At expr: unsupported node type: JoinedStr *) + Constant.str "(* At expr: unsupported node type: JoinedStr *)" ], make_dict [] - |)) + |)) |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -229,6 +312,26 @@ Definition encode_internal_node : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded" |) + ], + make_dict [] + |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "unencoded" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_name (| globals, "keccak256" |), @@ -237,6 +340,7 @@ Definition encode_internal_node : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -250,8 +354,86 @@ Definition encode_node : Value.t -> Value.t -> M := Currently mostly an unimplemented stub. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| + M.get_name (| globals, "storage_root" |), + Constant.None_ + |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "encode_account" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "storage_root" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "U256" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "cast" |), + make_list [ + M.get_field (| M.get_name (| globals, "rlp" |), "RLP" |); + M.get_name (| globals, "node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "node" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "previous_trie" |), "encode_node" |), @@ -261,6 +443,7 @@ Definition encode_node : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -312,6 +495,7 @@ Definition copy_trie : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition trie_set : Value.t -> Value.t -> M := @@ -333,6 +517,32 @@ Definition trie_set : Value.t -> Value.t -> M := Node to insert at `key`. " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + M.get_field (| M.get_name (| globals, "trie" |), "default" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "key" |), + M.get_field (| M.get_name (| globals, "trie" |), "_data" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), M.get_name (| globals, "value" |) @@ -370,6 +580,7 @@ Definition trie_get : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition common_prefix_length : Value.t -> Value.t -> M := @@ -392,6 +603,34 @@ Definition common_prefix_length : Value.t -> Value.t -> M := make_dict [] |) do let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), + M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -403,6 +642,7 @@ Definition common_prefix_length : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition nibble_list_to_compact : Value.t -> Value.t -> M := @@ -448,6 +688,71 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + Constant.int 2 + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.mult (| + Constant.int 16, + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "is_leaf" |) + |) + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ @@ -509,6 +814,7 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition bytes_to_nibble_list : Value.t -> Value.t -> M := @@ -586,6 +892,7 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition _prepare_trie : Value.t -> Value.t -> M := @@ -615,6 +922,48 @@ Definition _prepare_trie : Value.t -> Value.t -> M := make_dict [] |) do let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| + M.get_name (| globals, "get_storage_root" |), + Constant.None_ + |) |) in + let address := + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |); + M.call (| + M.get_name (| globals, "get_storage_root" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let encoded_value := M.call (| M.get_name (| globals, "encode_node" |), @@ -638,6 +987,22 @@ Definition _prepare_trie : Value.t -> Value.t -> M := |) in (* At stmt: unsupported node type: AnnAssign *) let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "trie" |), "secured" |), + (* then *) + ltac:(M.monadic ( + let key := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let key := M.get_name (| globals, "preimage" |) in M.pure Constant.None_ @@ -655,6 +1020,7 @@ Definition _prepare_trie : Value.t -> Value.t -> M := EndFor. let _ := M.return_ (| M.get_name (| globals, "mapped" |) + |) in M.pure Constant.None_)). Definition root : Value.t -> Value.t -> M := @@ -708,6 +1074,44 @@ Definition root : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -724,6 +1128,7 @@ Definition root : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -750,6 +1155,26 @@ Definition patricialize : Value.t -> Value.t -> M := Root node of `obj`. " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let arbitrary_key := @@ -767,10 +1192,39 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), + Constant.int 1 + |), + (* then *) + ltac:(M.monadic ( + let leaf := + M.call (| + M.get_name (| globals, "LeafNode" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |); + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "leaf" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let substring := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |) |) in + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) in let prefix_length := M.call (| M.get_name (| globals, "len" |), @@ -789,7 +1243,7 @@ Definition patricialize : Value.t -> Value.t -> M := M.get_name (| globals, "common_prefix_length" |), make_list [ M.get_name (| globals, "substring" |); - M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) + M.get_subscript (| M.get_name (| globals, "key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) ], make_dict [] |) @@ -797,10 +1251,64 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "prefix_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "prefix_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let prefix := + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ExtensionNode" |), + make_list [ + M.get_name (| globals, "prefix" |); + M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_name (| globals, "obj" |); + BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) @@ -823,6 +1331,44 @@ Definition patricialize : Value.t -> Value.t -> M := Constant.bytes "" in For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |), + M.get_name (| globals, "level" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "AssertionError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) @@ -834,9 +1380,10 @@ Definition patricialize : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "BranchNode" |), make_list [ - (* At expr: unsupported node type: ListComp *); + Constant.str "(* At expr: unsupported node type: ListComp *)"; M.get_name (| globals, "value" |) ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/utils/address.v b/CoqOfPython/ethereum/arrow_glacier/utils/address.v index c8bc7ba..cb8b8d7 100644 --- a/CoqOfPython/ethereum/arrow_glacier/utils/address.v +++ b/CoqOfPython/ethereum/arrow_glacier/utils/address.v @@ -38,13 +38,13 @@ Require ethereum.utils.byte. Axiom ethereum_utils_byte_left_pad_zero_bytes : IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.arrow_glacier.fork_types. +Axiom ethereum_arrow_glacier_fork_types_Address : + IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "Address". Definition to_address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -70,10 +70,11 @@ Definition to_address : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), make_list [], make_dict [] - |), UnOp.sub (| Constant.int 20 |) |) + |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) ], make_dict [] |) + |) in M.pure Constant.None_)). Definition compute_contract_address : Value.t -> Value.t -> M := @@ -113,7 +114,7 @@ Definition compute_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -131,6 +132,7 @@ Definition compute_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition compute_create2_contract_address : Value.t -> Value.t -> M := @@ -180,7 +182,7 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -198,4 +200,5 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/utils/hexadecimal.v b/CoqOfPython/ethereum/arrow_glacier/utils/hexadecimal.v index d6d904b..e8806bd 100644 --- a/CoqOfPython/ethereum/arrow_glacier/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/arrow_glacier/utils/hexadecimal.v @@ -22,13 +22,13 @@ Require ethereum.utils.hexadecimal. Axiom ethereum_utils_hexadecimal_remove_hex_prefix : IsGlobalAlias globals ethereum.utils.hexadecimal.globals "remove_hex_prefix". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". +Require ethereum.arrow_glacier.fork_types. +Axiom ethereum_arrow_glacier_fork_types_Address : + IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "Address". +Axiom ethereum_arrow_glacier_fork_types_Bloom : + IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "Bloom". +Axiom ethereum_arrow_glacier_fork_types_Root : + IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "Root". Definition hex_to_root : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -66,6 +66,7 @@ Definition hex_to_root : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition hex_to_bloom : Value.t -> Value.t -> M := @@ -104,6 +105,7 @@ Definition hex_to_bloom : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition hex_to_address : Value.t -> Value.t -> M := @@ -149,4 +151,5 @@ Definition hex_to_address : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/utils/message.v b/CoqOfPython/ethereum/arrow_glacier/utils/message.v index 5f66705..82dc5af 100644 --- a/CoqOfPython/ethereum/arrow_glacier/utils/message.v +++ b/CoqOfPython/ethereum/arrow_glacier/utils/message.v @@ -40,27 +40,27 @@ Axiom ethereum_base_types_Bytes32 : Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.arrow_glacier.fork_types. +Axiom ethereum_arrow_glacier_fork_types_Address : + IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "Address". -Require state. -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". +Require ethereum.arrow_glacier.state. +Axiom ethereum_arrow_glacier_state_get_account : + IsGlobalAlias globals ethereum.arrow_glacier.state.globals "get_account". -Require vm. -Axiom vm_Environment : - IsGlobalAlias globals vm.globals "Environment". -Axiom vm_Message : - IsGlobalAlias globals vm.globals "Message". +Require ethereum.arrow_glacier.vm.__init__. +Axiom ethereum_arrow_glacier_vm___init___Environment : + IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Environment". +Axiom ethereum_arrow_glacier_vm___init___Message : + IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Message". -Require vm.precompiled_contracts.mapping. -Axiom vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : - IsGlobalAlias globals vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". +Require ethereum.arrow_glacier.vm.precompiled_contracts.mapping. +Axiom ethereum_arrow_glacier_vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : + IsGlobalAlias globals ethereum.arrow_glacier.vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". -Require address. -Axiom address_compute_contract_address : - IsGlobalAlias globals address.globals "compute_contract_address". +Require ethereum.arrow_glacier.utils.address. +Axiom ethereum_arrow_glacier_utils_address_compute_contract_address : + IsGlobalAlias globals ethereum.arrow_glacier.utils.address.globals "compute_contract_address". Definition prepare_message : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -103,14 +103,108 @@ Definition prepare_message : Value.t -> Value.t -> M := Items containing contract creation or message call specific data. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Bytes0" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.call (| + M.get_name (| globals, "compute_contract_address" |), + make_list [ + M.get_name (| globals, "caller" |); + BinOp.sub (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "caller" |) + ], + make_dict [] + |), "nonce" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let msg_data := + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) in + let code := + M.get_name (| globals, "data" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.get_name (| globals, "target" |) in + let msg_data := + M.get_name (| globals, "data" |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "target" |) + ], + make_dict [] + |), "code" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "code_address" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let code_address := + M.get_name (| globals, "target" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "Target must be address or empty bytes" ], make_dict [] - |)) + |)) |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -159,4 +253,5 @@ Definition prepare_message : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/__init__.v b/CoqOfPython/ethereum/arrow_glacier/vm/__init__.v index 49da5ae..e0347cb 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/__init__.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/__init__.v @@ -52,23 +52,23 @@ Require ethereum.crypto.hash. Axiom ethereum_crypto_hash_Hash32 : IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". +Require ethereum.arrow_glacier.blocks. +Axiom ethereum_arrow_glacier_blocks_Log : + IsGlobalAlias globals ethereum.arrow_glacier.blocks.globals "Log". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.arrow_glacier.fork_types. +Axiom ethereum_arrow_glacier_fork_types_Address : + IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "Address". -Require state. -Axiom state_State : - IsGlobalAlias globals state.globals "State". -Axiom state_account_exists_and_is_empty : - IsGlobalAlias globals state.globals "account_exists_and_is_empty". +Require ethereum.arrow_glacier.state. +Axiom ethereum_arrow_glacier_state_State : + IsGlobalAlias globals ethereum.arrow_glacier.state.globals "State". +Axiom ethereum_arrow_glacier_state_account_exists_and_is_empty : + IsGlobalAlias globals ethereum.arrow_glacier.state.globals "account_exists_and_is_empty". -Require precompiled_contracts. -Axiom precompiled_contracts_RIPEMD160_ADDRESS : - IsGlobalAlias globals precompiled_contracts.globals "RIPEMD160_ADDRESS". +Require ethereum.arrow_glacier.vm.precompiled_contracts.__init__. +Axiom ethereum_arrow_glacier_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : + IsGlobalAlias globals ethereum.arrow_glacier.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] @@ -147,6 +147,28 @@ Definition incorporate_child_on_success : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -179,9 +201,63 @@ Definition incorporate_child_on_error : Value.t -> Value.t -> M := The child evm to incorporate. " in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "RIPEMD160_ADDRESS" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |), + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign_op (| diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/gas.v b/CoqOfPython/ethereum/arrow_glacier/vm/gas.v index 549060b..0d66586 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/gas.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/gas.v @@ -43,13 +43,13 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.arrow_glacier.vm.__init__. +Axiom ethereum_arrow_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Evm". -Require exceptions. -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". +Require ethereum.arrow_glacier.vm.exceptions. +Axiom ethereum_arrow_glacier_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.arrow_glacier.vm.exceptions.globals "OutOfGasError". Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -500,6 +500,18 @@ Definition charge_gas : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "amount" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign_op (| BinOp.sub, M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), @@ -615,6 +627,18 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := |) in For make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ] in M.get_name (| globals, "extensions" |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "size" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let before_size := @@ -649,6 +673,18 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let size_to_extend := BinOp.add @@ -697,6 +733,7 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition calculate_message_call_gas : Value.t -> Value.t -> M := @@ -728,22 +765,56 @@ Definition calculate_message_call_gas : Value.t -> Value.t -> M := message_call_gas: `MessageCallGas` " in let call_stipend := - (* if *) -M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "call_stipend" |) + )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "gas_left" |), + BinOp.add (| + M.get_name (| globals, "extra_gas" |), + M.get_name (| globals, "memory_cost" |) + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallGas" |), + make_list [ + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "extra_gas" |) + |); + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "call_stipend" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let gas := @@ -782,6 +853,7 @@ M.call (| ], make_dict [] |) + |) in M.pure Constant.None_)). Definition max_message_call_gas : Value.t -> Value.t -> M := @@ -808,4 +880,5 @@ Definition max_message_call_gas : Value.t -> Value.t -> M := Constant.int 64 |) |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/__init__.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/__init__.v index e5bebd7..8c5c5d8 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/__init__.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/__init__.v @@ -26,53 +26,53 @@ Axiom typing_Callable : Axiom typing_Dict : IsGlobalAlias globals typing.globals "Dict". -Require __init__. -Axiom __init___arithmetic : - IsGlobalAlias globals __init__.globals "arithmetic". +Require ethereum.arrow_glacier.vm.instructions.__init__. +Axiom ethereum_arrow_glacier_vm_instructions___init___arithmetic : + IsGlobalAlias globals ethereum.arrow_glacier.vm.instructions.__init__.globals "arithmetic". -Require __init__. -Axiom __init___bitwise : - IsGlobalAlias globals __init__.globals "bitwise". +Require ethereum.arrow_glacier.vm.instructions.__init__. +Axiom ethereum_arrow_glacier_vm_instructions___init___bitwise : + IsGlobalAlias globals ethereum.arrow_glacier.vm.instructions.__init__.globals "bitwise". -Require __init__. -Axiom __init___block : - IsGlobalAlias globals __init__.globals "block". +Require ethereum.arrow_glacier.vm.instructions.__init__. +Axiom ethereum_arrow_glacier_vm_instructions___init___block : + IsGlobalAlias globals ethereum.arrow_glacier.vm.instructions.__init__.globals "block". -Require __init__. -Axiom __init___comparison : - IsGlobalAlias globals __init__.globals "comparison". +Require ethereum.arrow_glacier.vm.instructions.__init__. +Axiom ethereum_arrow_glacier_vm_instructions___init___comparison : + IsGlobalAlias globals ethereum.arrow_glacier.vm.instructions.__init__.globals "comparison". -Require __init__. -Axiom __init___control_flow : - IsGlobalAlias globals __init__.globals "control_flow". +Require ethereum.arrow_glacier.vm.instructions.__init__. +Axiom ethereum_arrow_glacier_vm_instructions___init___control_flow : + IsGlobalAlias globals ethereum.arrow_glacier.vm.instructions.__init__.globals "control_flow". -Require __init__. -Axiom __init___environment : - IsGlobalAlias globals __init__.globals "environment". +Require ethereum.arrow_glacier.vm.instructions.__init__. +Axiom ethereum_arrow_glacier_vm_instructions___init___environment : + IsGlobalAlias globals ethereum.arrow_glacier.vm.instructions.__init__.globals "environment". -Require __init__. -Axiom __init___keccak : - IsGlobalAlias globals __init__.globals "keccak". +Require ethereum.arrow_glacier.vm.instructions.__init__. +Axiom ethereum_arrow_glacier_vm_instructions___init___keccak : + IsGlobalAlias globals ethereum.arrow_glacier.vm.instructions.__init__.globals "keccak". -Require __init__. -Axiom __init___log : - IsGlobalAlias globals __init__.globals "log". +Require ethereum.arrow_glacier.vm.instructions.__init__. +Axiom ethereum_arrow_glacier_vm_instructions___init___log : + IsGlobalAlias globals ethereum.arrow_glacier.vm.instructions.__init__.globals "log". -Require __init__. -Axiom __init___memory : - IsGlobalAlias globals __init__.globals "memory". +Require ethereum.arrow_glacier.vm.instructions.__init__. +Axiom ethereum_arrow_glacier_vm_instructions___init___memory : + IsGlobalAlias globals ethereum.arrow_glacier.vm.instructions.__init__.globals "memory". -Require __init__. -Axiom __init___stack : - IsGlobalAlias globals __init__.globals "stack". +Require ethereum.arrow_glacier.vm.instructions.__init__. +Axiom ethereum_arrow_glacier_vm_instructions___init___stack : + IsGlobalAlias globals ethereum.arrow_glacier.vm.instructions.__init__.globals "stack". -Require __init__. -Axiom __init___storage : - IsGlobalAlias globals __init__.globals "storage". +Require ethereum.arrow_glacier.vm.instructions.__init__. +Axiom ethereum_arrow_glacier_vm_instructions___init___storage : + IsGlobalAlias globals ethereum.arrow_glacier.vm.instructions.__init__.globals "storage". -Require __init__. -Axiom __init___system : - IsGlobalAlias globals __init__.globals "system". +Require ethereum.arrow_glacier.vm.instructions.__init__. +Axiom ethereum_arrow_glacier_vm_instructions___init___system : + IsGlobalAlias globals ethereum.arrow_glacier.vm.instructions.__init__.globals "system". Definition Ops : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/arithmetic.v index 581ba5d..92193d8 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/arithmetic.v @@ -31,29 +31,29 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_get_sign : IsGlobalAlias globals ethereum.utils.numeric.globals "get_sign". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_EXPONENTIATION : - IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION". -Axiom gas_GAS_EXPONENTIATION_PER_BYTE : - IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION_PER_BYTE". -Axiom gas_GAS_LOW : - IsGlobalAlias globals gas.globals "GAS_LOW". -Axiom gas_GAS_MID : - IsGlobalAlias globals gas.globals "GAS_MID". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.arrow_glacier.vm.__init__. +Axiom ethereum_arrow_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Evm". + +Require ethereum.arrow_glacier.vm.gas. +Axiom ethereum_arrow_glacier_vm_gas_GAS_EXPONENTIATION : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_EXPONENTIATION". +Axiom ethereum_arrow_glacier_vm_gas_GAS_EXPONENTIATION_PER_BYTE : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_EXPONENTIATION_PER_BYTE". +Axiom ethereum_arrow_glacier_vm_gas_GAS_LOW : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_LOW". +Axiom ethereum_arrow_glacier_vm_gas_GAS_MID : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_MID". +Axiom ethereum_arrow_glacier_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_arrow_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "charge_gas". + +Require ethereum.arrow_glacier.vm.stack. +Axiom ethereum_arrow_glacier_vm_stack_pop : + IsGlobalAlias globals ethereum.arrow_glacier.vm.stack.globals "pop". +Axiom ethereum_arrow_glacier_vm_stack_push : + IsGlobalAlias globals ethereum.arrow_glacier.vm.stack.globals "push". Definition add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -273,6 +273,25 @@ Definition div : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "divisor" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let quotient := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let quotient := BinOp.floor_div (| M.get_name (| globals, "dividend" |), @@ -341,7 +360,41 @@ Definition sdiv : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "divisor" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let quotient := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_name (| globals, "dividend" |), + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "divisor" |), + UnOp.sub (| Constant.int 1 |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let quotient := + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let sign := M.call (| M.get_name (| globals, "get_sign" |), @@ -436,6 +489,25 @@ Definition mod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "y" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let remainder := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let remainder := BinOp.mod_ (| M.get_name (| globals, "x" |), @@ -504,6 +576,19 @@ Definition smod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "y" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let remainder := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let remainder := BinOp.mult (| M.call (| @@ -617,6 +702,25 @@ Definition addmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "z" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -712,6 +816,25 @@ Definition mulmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "z" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -881,6 +1004,19 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "byte_num" |), + Constant.int 31 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.get_name (| globals, "value" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let value_bytes := M.call (| M.get_name (| globals, "bytes" |), @@ -894,7 +1030,7 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let value_bytes := - M.get_subscript (| M.get_name (| globals, "value_bytes" |), BinOp.sub (| + M.get_subscript (| M.get_name (| globals, "value_bytes" |), M.slice (| BinOp.sub (| Constant.int 31, M.call (| M.get_name (| globals, "int" |), @@ -903,13 +1039,32 @@ Definition signextend : Value.t -> Value.t -> M := ], make_dict [] |) - |) |) in + |), Constant.None_ |) |) in let sign_bit := BinOp.r_shift (| M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), Constant.int 7 |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "sign_bit" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "value_bytes" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let num_bytes_prepend := BinOp.sub (| Constant.int 32, diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/bitwise.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/bitwise.v index 64cf120..40bbc07 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/bitwise.v @@ -23,21 +23,21 @@ Axiom ethereum_base_types_U256 : Axiom ethereum_base_types_U256_CEIL_VALUE : IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.arrow_glacier.vm.__init__. +Axiom ethereum_arrow_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.arrow_glacier.vm.gas. +Axiom ethereum_arrow_glacier_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_arrow_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "charge_gas". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.arrow_glacier.vm.stack. +Axiom ethereum_arrow_glacier_vm_stack_pop : + IsGlobalAlias globals ethereum.arrow_glacier.vm.stack.globals "pop". +Axiom ethereum_arrow_glacier_vm_stack_push : + IsGlobalAlias globals ethereum.arrow_glacier.vm.stack.globals "push". Definition bitwise_and : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -287,6 +287,25 @@ Definition get_byte : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "byte_index" |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let extra_bytes_to_right := BinOp.sub (| Constant.int 31, @@ -366,6 +385,31 @@ Definition bitwise_shl : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "shift" |), + Constant.int 256 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.l_shift (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "shift" |) + |), + M.get_name (| globals, "U256_CEIL_VALUE" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -427,6 +471,22 @@ Definition bitwise_shr : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "shift" |), + Constant.int 256 + |), + (* then *) + ltac:(M.monadic ( + let result := + BinOp.r_shift (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "shift" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -492,7 +552,48 @@ Definition bitwise_sar : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "shift" |), + Constant.int 256 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + BinOp.r_shift (| + M.get_name (| globals, "signed_value" |), + M.get_name (| globals, "shift" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "signed_value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/block.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/block.v index f857b79..7919a95 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/block.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/block.v @@ -21,23 +21,23 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_BLOCK_HASH : - IsGlobalAlias globals gas.globals "GAS_BLOCK_HASH". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.arrow_glacier.vm.__init__. +Axiom ethereum_arrow_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Evm". + +Require ethereum.arrow_glacier.vm.gas. +Axiom ethereum_arrow_glacier_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_BASE". +Axiom ethereum_arrow_glacier_vm_gas_GAS_BLOCK_HASH : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_BLOCK_HASH". +Axiom ethereum_arrow_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "charge_gas". + +Require ethereum.arrow_glacier.vm.stack. +Axiom ethereum_arrow_glacier_vm_stack_pop : + IsGlobalAlias globals ethereum.arrow_glacier.vm.stack.globals "pop". +Axiom ethereum_arrow_glacier_vm_stack_push : + IsGlobalAlias globals ethereum.arrow_glacier.vm.stack.globals "push". Definition block_hash : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -69,6 +69,30 @@ Definition block_hash : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt_e (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + M.get_name (| globals, "block_number" |) + |), + ltac:(M.monadic ( + Compare.gt (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + BinOp.add (| + M.get_name (| globals, "block_number" |), + Constant.int 256 + |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let hash := + Constant.bytes "00" in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let hash := M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/comparison.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/comparison.v index b8529d8..3d4f0ed 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/comparison.v @@ -21,21 +21,21 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.arrow_glacier.vm.__init__. +Axiom ethereum_arrow_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.arrow_glacier.vm.gas. +Axiom ethereum_arrow_glacier_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_arrow_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "charge_gas". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.arrow_glacier.vm.stack. +Axiom ethereum_arrow_glacier_vm_stack_pop : + IsGlobalAlias globals ethereum.arrow_glacier.vm.stack.globals "pop". +Axiom ethereum_arrow_glacier_vm_stack_push : + IsGlobalAlias globals ethereum.arrow_glacier.vm.stack.globals "push". Definition less_than : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/control_flow.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/control_flow.v index d4e4eae..e823801 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/control_flow.v @@ -23,31 +23,31 @@ Axiom ethereum_base_types_U256 : Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require vm.gas. -Axiom vm_gas_GAS_BASE : - IsGlobalAlias globals vm.gas.globals "GAS_BASE". -Axiom vm_gas_GAS_HIGH : - IsGlobalAlias globals vm.gas.globals "GAS_HIGH". -Axiom vm_gas_GAS_JUMPDEST : - IsGlobalAlias globals vm.gas.globals "GAS_JUMPDEST". -Axiom vm_gas_GAS_MID : - IsGlobalAlias globals vm.gas.globals "GAS_MID". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.arrow_glacier.vm.gas. +Axiom ethereum_arrow_glacier_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_BASE". +Axiom ethereum_arrow_glacier_vm_gas_GAS_HIGH : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_HIGH". +Axiom ethereum_arrow_glacier_vm_gas_GAS_JUMPDEST : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_JUMPDEST". +Axiom ethereum_arrow_glacier_vm_gas_GAS_MID : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_MID". +Axiom ethereum_arrow_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "charge_gas". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.arrow_glacier.vm.__init__. +Axiom ethereum_arrow_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Evm". -Require exceptions. -Axiom exceptions_InvalidJumpDestError : - IsGlobalAlias globals exceptions.globals "InvalidJumpDestError". +Require ethereum.arrow_glacier.vm.exceptions. +Axiom ethereum_arrow_glacier_vm_exceptions_InvalidJumpDestError : + IsGlobalAlias globals ethereum.arrow_glacier.vm.exceptions.globals "InvalidJumpDestError". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.arrow_glacier.vm.stack. +Axiom ethereum_arrow_glacier_vm_stack_pop : + IsGlobalAlias globals ethereum.arrow_glacier.vm.stack.globals "pop". +Axiom ethereum_arrow_glacier_vm_stack_push : + IsGlobalAlias globals ethereum.arrow_glacier.vm.stack.globals "push". Definition stop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -109,6 +109,18 @@ Definition jump : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "jump_dest" |), + M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -168,7 +180,35 @@ Definition jumpi : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "conditional_value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let destination := + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "jump_dest" |), + M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let destination := M.get_name (| globals, "jump_dest" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/environment.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/environment.v index 10bc05b..f09eb2f 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/environment.v @@ -35,57 +35,57 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require fork_types. -Axiom fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". - -Require state. -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". - -Require utils.address. -Axiom utils_address_to_address : - IsGlobalAlias globals utils.address.globals "to_address". - -Require vm.memory. -Axiom vm_memory_buffer_read : - IsGlobalAlias globals vm.memory.globals "buffer_read". -Axiom vm_memory_memory_write : - IsGlobalAlias globals vm.memory.globals "memory_write". - -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require exceptions. -Axiom exceptions_OutOfBoundsRead : - IsGlobalAlias globals exceptions.globals "OutOfBoundsRead". - -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_COLD_ACCOUNT_ACCESS : - IsGlobalAlias globals gas.globals "GAS_COLD_ACCOUNT_ACCESS". -Axiom gas_GAS_COPY : - IsGlobalAlias globals gas.globals "GAS_COPY". -Axiom gas_GAS_FAST_STEP : - IsGlobalAlias globals gas.globals "GAS_FAST_STEP". -Axiom gas_GAS_RETURN_DATA_COPY : - IsGlobalAlias globals gas.globals "GAS_RETURN_DATA_COPY". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_GAS_WARM_ACCESS : - IsGlobalAlias globals gas.globals "GAS_WARM_ACCESS". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.arrow_glacier.fork_types. +Axiom ethereum_arrow_glacier_fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "EMPTY_ACCOUNT". + +Require ethereum.arrow_glacier.state. +Axiom ethereum_arrow_glacier_state_get_account : + IsGlobalAlias globals ethereum.arrow_glacier.state.globals "get_account". + +Require ethereum.arrow_glacier.utils.address. +Axiom ethereum_arrow_glacier_utils_address_to_address : + IsGlobalAlias globals ethereum.arrow_glacier.utils.address.globals "to_address". + +Require ethereum.arrow_glacier.vm.memory. +Axiom ethereum_arrow_glacier_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.arrow_glacier.vm.memory.globals "buffer_read". +Axiom ethereum_arrow_glacier_vm_memory_memory_write : + IsGlobalAlias globals ethereum.arrow_glacier.vm.memory.globals "memory_write". + +Require ethereum.arrow_glacier.vm.__init__. +Axiom ethereum_arrow_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Evm". + +Require ethereum.arrow_glacier.vm.exceptions. +Axiom ethereum_arrow_glacier_vm_exceptions_OutOfBoundsRead : + IsGlobalAlias globals ethereum.arrow_glacier.vm.exceptions.globals "OutOfBoundsRead". + +Require ethereum.arrow_glacier.vm.gas. +Axiom ethereum_arrow_glacier_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_BASE". +Axiom ethereum_arrow_glacier_vm_gas_GAS_COLD_ACCOUNT_ACCESS : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_COLD_ACCOUNT_ACCESS". +Axiom ethereum_arrow_glacier_vm_gas_GAS_COPY : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_COPY". +Axiom ethereum_arrow_glacier_vm_gas_GAS_FAST_STEP : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_FAST_STEP". +Axiom ethereum_arrow_glacier_vm_gas_GAS_RETURN_DATA_COPY : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_RETURN_DATA_COPY". +Axiom ethereum_arrow_glacier_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_arrow_glacier_vm_gas_GAS_WARM_ACCESS : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_WARM_ACCESS". +Axiom ethereum_arrow_glacier_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_arrow_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "charge_gas". + +Require ethereum.arrow_glacier.vm.stack. +Axiom ethereum_arrow_glacier_vm_stack_pop : + IsGlobalAlias globals ethereum.arrow_glacier.vm.stack.globals "pop". +Axiom ethereum_arrow_glacier_vm_stack_push : + IsGlobalAlias globals ethereum.arrow_glacier.vm.stack.globals "push". Definition address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -156,6 +156,25 @@ Definition balance : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -789,6 +808,25 @@ Definition extcodesize : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -926,6 +964,31 @@ Definition extcodecopy : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_WARM_ACCESS" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1162,7 +1225,10 @@ Definition returndatacopy : Value.t -> Value.t -> M := |) |) in let value := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |) |) in + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.slice (| M.get_name (| globals, "return_data_start_position" |), BinOp.add (| + M.get_name (| globals, "return_data_start_position" |), + M.get_name (| globals, "size" |) + |) |) |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -1204,6 +1270,25 @@ Definition extcodehash : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1231,6 +1316,25 @@ Definition extcodehash : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "account" |), + M.get_name (| globals, "EMPTY_ACCOUNT" |) + |), + (* then *) + ltac:(M.monadic ( + let codehash := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let codehash := M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/keccak.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/keccak.v index 2c4b10e..7213fb1 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/keccak.v @@ -31,29 +31,29 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_KECCAK256 : - IsGlobalAlias globals gas.globals "GAS_KECCAK256". -Axiom gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.arrow_glacier.vm.__init__. +Axiom ethereum_arrow_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Evm". + +Require ethereum.arrow_glacier.vm.gas. +Axiom ethereum_arrow_glacier_vm_gas_GAS_KECCAK256 : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_KECCAK256". +Axiom ethereum_arrow_glacier_vm_gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_KECCAK256_WORD". +Axiom ethereum_arrow_glacier_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_arrow_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "charge_gas". + +Require ethereum.arrow_glacier.vm.memory. +Axiom ethereum_arrow_glacier_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.arrow_glacier.vm.memory.globals "memory_read_bytes". + +Require ethereum.arrow_glacier.vm.stack. +Axiom ethereum_arrow_glacier_vm_stack_pop : + IsGlobalAlias globals ethereum.arrow_glacier.vm.stack.globals "pop". +Axiom ethereum_arrow_glacier_vm_stack_push : + IsGlobalAlias globals ethereum.arrow_glacier.vm.stack.globals "push". Definition keccak : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/log.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/log.v index e084e59..c32fdb1 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/log.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/log.v @@ -29,37 +29,37 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". - -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require exceptions. -Axiom exceptions_WriteInStaticContext : - IsGlobalAlias globals exceptions.globals "WriteInStaticContext". - -Require gas. -Axiom gas_GAS_LOG : - IsGlobalAlias globals gas.globals "GAS_LOG". -Axiom gas_GAS_LOG_DATA : - IsGlobalAlias globals gas.globals "GAS_LOG_DATA". -Axiom gas_GAS_LOG_TOPIC : - IsGlobalAlias globals gas.globals "GAS_LOG_TOPIC". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". +Require ethereum.arrow_glacier.blocks. +Axiom ethereum_arrow_glacier_blocks_Log : + IsGlobalAlias globals ethereum.arrow_glacier.blocks.globals "Log". + +Require ethereum.arrow_glacier.vm.__init__. +Axiom ethereum_arrow_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Evm". + +Require ethereum.arrow_glacier.vm.exceptions. +Axiom ethereum_arrow_glacier_vm_exceptions_WriteInStaticContext : + IsGlobalAlias globals ethereum.arrow_glacier.vm.exceptions.globals "WriteInStaticContext". + +Require ethereum.arrow_glacier.vm.gas. +Axiom ethereum_arrow_glacier_vm_gas_GAS_LOG : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_LOG". +Axiom ethereum_arrow_glacier_vm_gas_GAS_LOG_DATA : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_LOG_DATA". +Axiom ethereum_arrow_glacier_vm_gas_GAS_LOG_TOPIC : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_LOG_TOPIC". +Axiom ethereum_arrow_glacier_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_arrow_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "charge_gas". + +Require ethereum.arrow_glacier.vm.memory. +Axiom ethereum_arrow_glacier_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.arrow_glacier.vm.memory.globals "memory_read_bytes". + +Require ethereum.arrow_glacier.vm.stack. +Axiom ethereum_arrow_glacier_vm_stack_pop : + IsGlobalAlias globals ethereum.arrow_glacier.vm.stack.globals "pop". Definition log_n : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/memory.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/memory.v index 86ba742..1ffde04 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/memory.v @@ -23,31 +23,31 @@ Axiom ethereum_base_types_U256 : Axiom ethereum_base_types_Bytes : IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.arrow_glacier.vm.__init__. +Axiom ethereum_arrow_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.arrow_glacier.vm.gas. +Axiom ethereum_arrow_glacier_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_BASE". +Axiom ethereum_arrow_glacier_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_arrow_glacier_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_arrow_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "charge_gas". -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". -Axiom memory_memory_write : - IsGlobalAlias globals memory.globals "memory_write". +Require ethereum.arrow_glacier.vm.memory. +Axiom ethereum_arrow_glacier_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.arrow_glacier.vm.memory.globals "memory_read_bytes". +Axiom ethereum_arrow_glacier_vm_memory_memory_write : + IsGlobalAlias globals ethereum.arrow_glacier.vm.memory.globals "memory_write". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.arrow_glacier.vm.stack. +Axiom ethereum_arrow_glacier_vm_stack_pop : + IsGlobalAlias globals ethereum.arrow_glacier.vm.stack.globals "pop". +Axiom ethereum_arrow_glacier_vm_stack_push : + IsGlobalAlias globals ethereum.arrow_glacier.vm.stack.globals "push". Definition mstore : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/stack.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/stack.v index 305af15..1e0f4d9 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/stack.v @@ -29,27 +29,27 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". -Axiom __init___stack : - IsGlobalAlias globals __init__.globals "stack". - -Require exceptions. -Axiom exceptions_StackUnderflowError : - IsGlobalAlias globals exceptions.globals "StackUnderflowError". - -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require memory. -Axiom memory_buffer_read : - IsGlobalAlias globals memory.globals "buffer_read". +Require ethereum.arrow_glacier.vm.__init__. +Axiom ethereum_arrow_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Evm". +Axiom ethereum_arrow_glacier_vm___init___stack : + IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "stack". + +Require ethereum.arrow_glacier.vm.exceptions. +Axiom ethereum_arrow_glacier_vm_exceptions_StackUnderflowError : + IsGlobalAlias globals ethereum.arrow_glacier.vm.exceptions.globals "StackUnderflowError". + +Require ethereum.arrow_glacier.vm.gas. +Axiom ethereum_arrow_glacier_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_BASE". +Axiom ethereum_arrow_glacier_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_arrow_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "charge_gas". + +Require ethereum.arrow_glacier.vm.memory. +Axiom ethereum_arrow_glacier_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.arrow_glacier.vm.memory.globals "buffer_read". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/storage.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/storage.v index b3c4045..d2ccb97 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/storage.v @@ -25,45 +25,45 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require state. -Axiom state_get_storage : - IsGlobalAlias globals state.globals "get_storage". -Axiom state_get_storage_original : - IsGlobalAlias globals state.globals "get_storage_original". -Axiom state_set_storage : - IsGlobalAlias globals state.globals "set_storage". - -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require exceptions. -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". -Axiom exceptions_WriteInStaticContext : - IsGlobalAlias globals exceptions.globals "WriteInStaticContext". - -Require gas. -Axiom gas_GAS_CALL_STIPEND : - IsGlobalAlias globals gas.globals "GAS_CALL_STIPEND". -Axiom gas_GAS_COLD_SLOAD : - IsGlobalAlias globals gas.globals "GAS_COLD_SLOAD". -Axiom gas_GAS_STORAGE_CLEAR_REFUND : - IsGlobalAlias globals gas.globals "GAS_STORAGE_CLEAR_REFUND". -Axiom gas_GAS_STORAGE_SET : - IsGlobalAlias globals gas.globals "GAS_STORAGE_SET". -Axiom gas_GAS_STORAGE_UPDATE : - IsGlobalAlias globals gas.globals "GAS_STORAGE_UPDATE". -Axiom gas_GAS_WARM_ACCESS : - IsGlobalAlias globals gas.globals "GAS_WARM_ACCESS". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.arrow_glacier.state. +Axiom ethereum_arrow_glacier_state_get_storage : + IsGlobalAlias globals ethereum.arrow_glacier.state.globals "get_storage". +Axiom ethereum_arrow_glacier_state_get_storage_original : + IsGlobalAlias globals ethereum.arrow_glacier.state.globals "get_storage_original". +Axiom ethereum_arrow_glacier_state_set_storage : + IsGlobalAlias globals ethereum.arrow_glacier.state.globals "set_storage". + +Require ethereum.arrow_glacier.vm.__init__. +Axiom ethereum_arrow_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Evm". + +Require ethereum.arrow_glacier.vm.exceptions. +Axiom ethereum_arrow_glacier_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.arrow_glacier.vm.exceptions.globals "OutOfGasError". +Axiom ethereum_arrow_glacier_vm_exceptions_WriteInStaticContext : + IsGlobalAlias globals ethereum.arrow_glacier.vm.exceptions.globals "WriteInStaticContext". + +Require ethereum.arrow_glacier.vm.gas. +Axiom ethereum_arrow_glacier_vm_gas_GAS_CALL_STIPEND : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_CALL_STIPEND". +Axiom ethereum_arrow_glacier_vm_gas_GAS_COLD_SLOAD : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_COLD_SLOAD". +Axiom ethereum_arrow_glacier_vm_gas_GAS_STORAGE_CLEAR_REFUND : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_STORAGE_CLEAR_REFUND". +Axiom ethereum_arrow_glacier_vm_gas_GAS_STORAGE_SET : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_STORAGE_SET". +Axiom ethereum_arrow_glacier_vm_gas_GAS_STORAGE_UPDATE : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_STORAGE_UPDATE". +Axiom ethereum_arrow_glacier_vm_gas_GAS_WARM_ACCESS : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_WARM_ACCESS". +Axiom ethereum_arrow_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "charge_gas". + +Require ethereum.arrow_glacier.vm.stack. +Axiom ethereum_arrow_glacier_vm_stack_pop : + IsGlobalAlias globals ethereum.arrow_glacier.vm.stack.globals "pop". +Axiom ethereum_arrow_glacier_vm_stack_push : + IsGlobalAlias globals ethereum.arrow_glacier.vm.stack.globals "push". Definition sload : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -91,6 +91,25 @@ Definition sload : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], + M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "add" |), make_list [ @@ -205,15 +224,225 @@ Definition sstore : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], + M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "add" |), + make_list [ + make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ] + ], + make_dict [] + |) in + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_COLD_SLOAD" |) + M.get_name (| globals, "GAS_COLD_SLOAD" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_name (| globals, "original_value" |), + M.get_name (| globals, "current_value" |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "current_value" |), + M.get_name (| globals, "new_value" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "original_value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_STORAGE_SET" |) + M.get_name (| globals, "GAS_STORAGE_SET" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let gas_cost := BinOp.add + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_UPDATE" |), + M.get_name (| globals, "GAS_COLD_SLOAD" |) + |) + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_UPDATE" |), + M.get_name (| globals, "GAS_COLD_SLOAD" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let gas_cost := BinOp.add M.get_name (| globals, "GAS_WARM_ACCESS" |) M.get_name (| globals, "GAS_WARM_ACCESS" |) in M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| + M.get_name (| globals, "current_value" |), + M.get_name (| globals, "new_value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "original_value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "current_value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "new_value" |), + Constant.int 0 + |) + )) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "original_value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "current_value" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.sub, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "original_value" |), + M.get_name (| globals, "new_value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "original_value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_SET" |), + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.sub (| + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_UPDATE" |), + M.get_name (| globals, "GAS_COLD_SLOAD" |) + |), + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/system.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/system.v index 03931b2..bebc28b 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/system.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/system.v @@ -33,87 +33,87 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.arrow_glacier.fork_types. +Axiom ethereum_arrow_glacier_fork_types_Address : + IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "Address". -Require state. -Axiom state_account_exists_and_is_empty : - IsGlobalAlias globals state.globals "account_exists_and_is_empty". -Axiom state_account_has_code_or_nonce : - IsGlobalAlias globals state.globals "account_has_code_or_nonce". -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". -Axiom state_increment_nonce : - IsGlobalAlias globals state.globals "increment_nonce". -Axiom state_is_account_alive : - IsGlobalAlias globals state.globals "is_account_alive". -Axiom state_set_account_balance : - IsGlobalAlias globals state.globals "set_account_balance". +Require ethereum.arrow_glacier.state. +Axiom ethereum_arrow_glacier_state_account_exists_and_is_empty : + IsGlobalAlias globals ethereum.arrow_glacier.state.globals "account_exists_and_is_empty". +Axiom ethereum_arrow_glacier_state_account_has_code_or_nonce : + IsGlobalAlias globals ethereum.arrow_glacier.state.globals "account_has_code_or_nonce". +Axiom ethereum_arrow_glacier_state_get_account : + IsGlobalAlias globals ethereum.arrow_glacier.state.globals "get_account". +Axiom ethereum_arrow_glacier_state_increment_nonce : + IsGlobalAlias globals ethereum.arrow_glacier.state.globals "increment_nonce". +Axiom ethereum_arrow_glacier_state_is_account_alive : + IsGlobalAlias globals ethereum.arrow_glacier.state.globals "is_account_alive". +Axiom ethereum_arrow_glacier_state_set_account_balance : + IsGlobalAlias globals ethereum.arrow_glacier.state.globals "set_account_balance". -Require utils.address. -Axiom utils_address_compute_contract_address : - IsGlobalAlias globals utils.address.globals "compute_contract_address". -Axiom utils_address_compute_create2_contract_address : - IsGlobalAlias globals utils.address.globals "compute_create2_contract_address". -Axiom utils_address_to_address : - IsGlobalAlias globals utils.address.globals "to_address". +Require ethereum.arrow_glacier.utils.address. +Axiom ethereum_arrow_glacier_utils_address_compute_contract_address : + IsGlobalAlias globals ethereum.arrow_glacier.utils.address.globals "compute_contract_address". +Axiom ethereum_arrow_glacier_utils_address_compute_create2_contract_address : + IsGlobalAlias globals ethereum.arrow_glacier.utils.address.globals "compute_create2_contract_address". +Axiom ethereum_arrow_glacier_utils_address_to_address : + IsGlobalAlias globals ethereum.arrow_glacier.utils.address.globals "to_address". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". -Axiom __init___Message : - IsGlobalAlias globals __init__.globals "Message". -Axiom __init___incorporate_child_on_error : - IsGlobalAlias globals __init__.globals "incorporate_child_on_error". -Axiom __init___incorporate_child_on_success : - IsGlobalAlias globals __init__.globals "incorporate_child_on_success". +Require ethereum.arrow_glacier.vm.__init__. +Axiom ethereum_arrow_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Evm". +Axiom ethereum_arrow_glacier_vm___init___Message : + IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Message". +Axiom ethereum_arrow_glacier_vm___init___incorporate_child_on_error : + IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "incorporate_child_on_error". +Axiom ethereum_arrow_glacier_vm___init___incorporate_child_on_success : + IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "incorporate_child_on_success". -Require exceptions. -Axiom exceptions_Revert : - IsGlobalAlias globals exceptions.globals "Revert". -Axiom exceptions_WriteInStaticContext : - IsGlobalAlias globals exceptions.globals "WriteInStaticContext". +Require ethereum.arrow_glacier.vm.exceptions. +Axiom ethereum_arrow_glacier_vm_exceptions_Revert : + IsGlobalAlias globals ethereum.arrow_glacier.vm.exceptions.globals "Revert". +Axiom ethereum_arrow_glacier_vm_exceptions_WriteInStaticContext : + IsGlobalAlias globals ethereum.arrow_glacier.vm.exceptions.globals "WriteInStaticContext". -Require gas. -Axiom gas_GAS_CALL_VALUE : - IsGlobalAlias globals gas.globals "GAS_CALL_VALUE". -Axiom gas_GAS_COLD_ACCOUNT_ACCESS : - IsGlobalAlias globals gas.globals "GAS_COLD_ACCOUNT_ACCESS". -Axiom gas_GAS_CREATE : - IsGlobalAlias globals gas.globals "GAS_CREATE". -Axiom gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". -Axiom gas_GAS_NEW_ACCOUNT : - IsGlobalAlias globals gas.globals "GAS_NEW_ACCOUNT". -Axiom gas_GAS_SELF_DESTRUCT : - IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT". -Axiom gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : - IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". -Axiom gas_GAS_WARM_ACCESS : - IsGlobalAlias globals gas.globals "GAS_WARM_ACCESS". -Axiom gas_GAS_ZERO : - IsGlobalAlias globals gas.globals "GAS_ZERO". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_calculate_message_call_gas : - IsGlobalAlias globals gas.globals "calculate_message_call_gas". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". -Axiom gas_max_message_call_gas : - IsGlobalAlias globals gas.globals "max_message_call_gas". +Require ethereum.arrow_glacier.vm.gas. +Axiom ethereum_arrow_glacier_vm_gas_GAS_CALL_VALUE : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_CALL_VALUE". +Axiom ethereum_arrow_glacier_vm_gas_GAS_COLD_ACCOUNT_ACCESS : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_COLD_ACCOUNT_ACCESS". +Axiom ethereum_arrow_glacier_vm_gas_GAS_CREATE : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_CREATE". +Axiom ethereum_arrow_glacier_vm_gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_KECCAK256_WORD". +Axiom ethereum_arrow_glacier_vm_gas_GAS_NEW_ACCOUNT : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_NEW_ACCOUNT". +Axiom ethereum_arrow_glacier_vm_gas_GAS_SELF_DESTRUCT : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_SELF_DESTRUCT". +Axiom ethereum_arrow_glacier_vm_gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". +Axiom ethereum_arrow_glacier_vm_gas_GAS_WARM_ACCESS : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_WARM_ACCESS". +Axiom ethereum_arrow_glacier_vm_gas_GAS_ZERO : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_ZERO". +Axiom ethereum_arrow_glacier_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_arrow_glacier_vm_gas_calculate_message_call_gas : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "calculate_message_call_gas". +Axiom ethereum_arrow_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "charge_gas". +Axiom ethereum_arrow_glacier_vm_gas_max_message_call_gas : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "max_message_call_gas". -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". -Axiom memory_memory_write : - IsGlobalAlias globals memory.globals "memory_write". +Require ethereum.arrow_glacier.vm.memory. +Axiom ethereum_arrow_glacier_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.arrow_glacier.vm.memory.globals "memory_read_bytes". +Axiom ethereum_arrow_glacier_vm_memory_memory_write : + IsGlobalAlias globals ethereum.arrow_glacier.vm.memory.globals "memory_write". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.arrow_glacier.vm.stack. +Axiom ethereum_arrow_glacier_vm_stack_pop : + IsGlobalAlias globals ethereum.arrow_glacier.vm.stack.globals "pop". +Axiom ethereum_arrow_glacier_vm_stack_push : + IsGlobalAlias globals ethereum.arrow_glacier.vm.stack.globals "push". Definition generic_create : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -172,9 +172,113 @@ Definition generic_create : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt (| + M.get_field (| M.get_name (| globals, "sender" |), "balance" |), + M.get_name (| globals, "endowment" |) + |), + ltac:(M.monadic ( + BoolOp.or (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "sender" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.sub (| + BinOp.pow (| + Constant.int 2, + Constant.int 64 + |), + Constant.int 1 + |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.gt (| + BinOp.add (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "depth" |), + Constant.int 1 + |), + M.get_name (| globals, "STACK_DEPTH_LIMIT" |) + |) + )) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "create_message_gas" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "contract_address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let call_data := @@ -211,6 +315,40 @@ Definition generic_create : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "child_evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_error" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "incorporate_child_on_success" |), make_list [ @@ -567,6 +705,42 @@ Definition generic_call : Value.t -> Value.t -> M := Constant.bytes "" |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + BinOp.add (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "depth" |), + Constant.int 1 + |), + M.get_name (| globals, "STACK_DEPTH_LIMIT" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "gas" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let call_data := @@ -604,6 +778,40 @@ Definition generic_call : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "child_evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_error" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "incorporate_child_on_success" |), make_list [ @@ -658,7 +866,7 @@ Definition generic_call : Value.t -> Value.t -> M := make_list [ M.get_field (| M.get_name (| globals, "evm" |), "memory" |); M.get_name (| globals, "memory_output_start_position" |); - M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), Constant.None_:M.get_name (| globals, "actual_output_size" |) |) + M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), M.slice (| Constant.None_, M.get_name (| globals, "actual_output_size" |) |) |) ], make_dict [] |) in @@ -756,6 +964,19 @@ Definition call : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "to" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let access_gas_cost := + M.get_name (| globals, "GAS_WARM_ACCESS" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -768,49 +989,57 @@ Definition call : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in let create_gas_cost := - (* if *) -M.if_then_else (| - BoolOp.or (| - M.call (| - M.get_name (| globals, "is_account_alive" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); - M.get_name (| globals, "to" |) - ], - make_dict [] - |), - ltac:(M.monadic ( - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |) - )) - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + BoolOp.or (| + M.call (| + M.get_name (| globals, "is_account_alive" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "to" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "GAS_NEW_ACCOUNT" |) + )) |) in let transfer_gas_cost := - (* if *) -M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "GAS_CALL_VALUE" |) + )) |) in let message_call_gas := M.call (| M.get_name (| globals, "calculate_message_call_gas" |), @@ -886,6 +1115,40 @@ M.call (| make_dict [] |), "balance" |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "sender_balance" |), + M.get_name (| globals, "value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "generic_call" |), make_list [ @@ -1007,6 +1270,19 @@ Definition callcode : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "code_address" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let access_gas_cost := + M.get_name (| globals, "GAS_WARM_ACCESS" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1019,21 +1295,25 @@ Definition callcode : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in let transfer_gas_cost := - (* if *) -M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "GAS_CALL_VALUE" |) + )) |) in let message_call_gas := M.call (| M.get_name (| globals, "calculate_message_call_gas" |), @@ -1084,6 +1364,40 @@ M.call (| make_dict [] |), "balance" |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "sender_balance" |), + M.get_name (| globals, "value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "generic_call" |), make_list [ @@ -1139,9 +1453,63 @@ Definition selfdestruct : Value.t -> Value.t -> M := let gas_cost := M.get_name (| globals, "GAS_SELF_DESTRUCT" |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "beneficiary" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |) in + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + UnOp.not (| M.call (| + M.get_name (| globals, "is_account_alive" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) + M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -1215,6 +1583,28 @@ Definition selfdestruct : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -1308,6 +1698,19 @@ Definition delegatecall : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "code_address" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let access_gas_cost := + M.get_name (| globals, "GAS_WARM_ACCESS" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1471,6 +1874,19 @@ Definition staticcall : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "to" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let access_gas_cost := + M.get_name (| globals, "GAS_WARM_ACCESS" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1630,6 +2046,6 @@ Definition revert : Value.t -> Value.t -> M := make_dict [] |) |) in - let _ := M.raise (| Some(M.get_name (| globals, "Revert" |)) + let _ := M.raise (| Some(M.get_name (| globals, "Revert" |)) |) in let _ := M.pass (| |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/interpreter.v b/CoqOfPython/ethereum/arrow_glacier/vm/interpreter.v index 024d2d5..4666c07 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/interpreter.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/interpreter.v @@ -61,83 +61,83 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". - -Require state. -Axiom state_account_exists_and_is_empty : - IsGlobalAlias globals state.globals "account_exists_and_is_empty". -Axiom state_account_has_code_or_nonce : - IsGlobalAlias globals state.globals "account_has_code_or_nonce". -Axiom state_begin_transaction : - IsGlobalAlias globals state.globals "begin_transaction". -Axiom state_commit_transaction : - IsGlobalAlias globals state.globals "commit_transaction". -Axiom state_destroy_storage : - IsGlobalAlias globals state.globals "destroy_storage". -Axiom state_increment_nonce : - IsGlobalAlias globals state.globals "increment_nonce". -Axiom state_mark_account_created : - IsGlobalAlias globals state.globals "mark_account_created". -Axiom state_move_ether : - IsGlobalAlias globals state.globals "move_ether". -Axiom state_rollback_transaction : - IsGlobalAlias globals state.globals "rollback_transaction". -Axiom state_set_code : - IsGlobalAlias globals state.globals "set_code". -Axiom state_touch_account : - IsGlobalAlias globals state.globals "touch_account". - -Require vm. -Axiom vm_Message : - IsGlobalAlias globals vm.globals "Message". - -Require vm.gas. -Axiom vm_gas_GAS_CODE_DEPOSIT : - IsGlobalAlias globals vm.gas.globals "GAS_CODE_DEPOSIT". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". - -Require vm.precompiled_contracts.mapping. -Axiom vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : - IsGlobalAlias globals vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". - -Require __init__. -Axiom __init___Environment : - IsGlobalAlias globals __init__.globals "Environment". -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require exceptions. -Axiom exceptions_AddressCollision : - IsGlobalAlias globals exceptions.globals "AddressCollision". -Axiom exceptions_ExceptionalHalt : - IsGlobalAlias globals exceptions.globals "ExceptionalHalt". -Axiom exceptions_InvalidContractPrefix : - IsGlobalAlias globals exceptions.globals "InvalidContractPrefix". -Axiom exceptions_InvalidOpcode : - IsGlobalAlias globals exceptions.globals "InvalidOpcode". -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". -Axiom exceptions_Revert : - IsGlobalAlias globals exceptions.globals "Revert". -Axiom exceptions_StackDepthLimitError : - IsGlobalAlias globals exceptions.globals "StackDepthLimitError". - -Require instructions. -Axiom instructions_Ops : - IsGlobalAlias globals instructions.globals "Ops". -Axiom instructions_op_implementation : - IsGlobalAlias globals instructions.globals "op_implementation". - -Require runtime. -Axiom runtime_get_valid_jump_destinations : - IsGlobalAlias globals runtime.globals "get_valid_jump_destinations". +Require ethereum.arrow_glacier.blocks. +Axiom ethereum_arrow_glacier_blocks_Log : + IsGlobalAlias globals ethereum.arrow_glacier.blocks.globals "Log". + +Require ethereum.arrow_glacier.fork_types. +Axiom ethereum_arrow_glacier_fork_types_Address : + IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "Address". + +Require ethereum.arrow_glacier.state. +Axiom ethereum_arrow_glacier_state_account_exists_and_is_empty : + IsGlobalAlias globals ethereum.arrow_glacier.state.globals "account_exists_and_is_empty". +Axiom ethereum_arrow_glacier_state_account_has_code_or_nonce : + IsGlobalAlias globals ethereum.arrow_glacier.state.globals "account_has_code_or_nonce". +Axiom ethereum_arrow_glacier_state_begin_transaction : + IsGlobalAlias globals ethereum.arrow_glacier.state.globals "begin_transaction". +Axiom ethereum_arrow_glacier_state_commit_transaction : + IsGlobalAlias globals ethereum.arrow_glacier.state.globals "commit_transaction". +Axiom ethereum_arrow_glacier_state_destroy_storage : + IsGlobalAlias globals ethereum.arrow_glacier.state.globals "destroy_storage". +Axiom ethereum_arrow_glacier_state_increment_nonce : + IsGlobalAlias globals ethereum.arrow_glacier.state.globals "increment_nonce". +Axiom ethereum_arrow_glacier_state_mark_account_created : + IsGlobalAlias globals ethereum.arrow_glacier.state.globals "mark_account_created". +Axiom ethereum_arrow_glacier_state_move_ether : + IsGlobalAlias globals ethereum.arrow_glacier.state.globals "move_ether". +Axiom ethereum_arrow_glacier_state_rollback_transaction : + IsGlobalAlias globals ethereum.arrow_glacier.state.globals "rollback_transaction". +Axiom ethereum_arrow_glacier_state_set_code : + IsGlobalAlias globals ethereum.arrow_glacier.state.globals "set_code". +Axiom ethereum_arrow_glacier_state_touch_account : + IsGlobalAlias globals ethereum.arrow_glacier.state.globals "touch_account". + +Require ethereum.arrow_glacier.vm.__init__. +Axiom ethereum_arrow_glacier_vm___init___Message : + IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Message". + +Require ethereum.arrow_glacier.vm.gas. +Axiom ethereum_arrow_glacier_vm_gas_GAS_CODE_DEPOSIT : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_CODE_DEPOSIT". +Axiom ethereum_arrow_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "charge_gas". + +Require ethereum.arrow_glacier.vm.precompiled_contracts.mapping. +Axiom ethereum_arrow_glacier_vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : + IsGlobalAlias globals ethereum.arrow_glacier.vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". + +Require ethereum.arrow_glacier.vm.__init__. +Axiom ethereum_arrow_glacier_vm___init___Environment : + IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Environment". +Axiom ethereum_arrow_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Evm". + +Require ethereum.arrow_glacier.vm.exceptions. +Axiom ethereum_arrow_glacier_vm_exceptions_AddressCollision : + IsGlobalAlias globals ethereum.arrow_glacier.vm.exceptions.globals "AddressCollision". +Axiom ethereum_arrow_glacier_vm_exceptions_ExceptionalHalt : + IsGlobalAlias globals ethereum.arrow_glacier.vm.exceptions.globals "ExceptionalHalt". +Axiom ethereum_arrow_glacier_vm_exceptions_InvalidContractPrefix : + IsGlobalAlias globals ethereum.arrow_glacier.vm.exceptions.globals "InvalidContractPrefix". +Axiom ethereum_arrow_glacier_vm_exceptions_InvalidOpcode : + IsGlobalAlias globals ethereum.arrow_glacier.vm.exceptions.globals "InvalidOpcode". +Axiom ethereum_arrow_glacier_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.arrow_glacier.vm.exceptions.globals "OutOfGasError". +Axiom ethereum_arrow_glacier_vm_exceptions_Revert : + IsGlobalAlias globals ethereum.arrow_glacier.vm.exceptions.globals "Revert". +Axiom ethereum_arrow_glacier_vm_exceptions_StackDepthLimitError : + IsGlobalAlias globals ethereum.arrow_glacier.vm.exceptions.globals "StackDepthLimitError". + +Require ethereum.arrow_glacier.vm.instructions.__init__. +Axiom ethereum_arrow_glacier_vm_instructions___init___Ops : + IsGlobalAlias globals ethereum.arrow_glacier.vm.instructions.__init__.globals "Ops". +Axiom ethereum_arrow_glacier_vm_instructions___init___op_implementation : + IsGlobalAlias globals ethereum.arrow_glacier.vm.instructions.__init__.globals "op_implementation". + +Require ethereum.arrow_glacier.vm.runtime. +Axiom ethereum_arrow_glacier_vm_runtime_get_valid_jump_destinations : + IsGlobalAlias globals ethereum.arrow_glacier.vm.runtime.globals "get_valid_jump_destinations". Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -184,6 +184,94 @@ Definition process_message_call : Value.t -> Value.t -> M := Output of the message call " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "message" |), "target" |), + M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) + |), + (* then *) + ltac:(M.monadic ( + let is_collision := + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_name (| globals, "is_collision" |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallOutput" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "tuple" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "AddressCollision" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let evm := + M.call (| + M.get_name (| globals, "process_create_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let evm := M.call (| M.get_name (| globals, "process_message" |), @@ -194,11 +282,74 @@ Definition process_message_call : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_field (| M.get_name (| globals, "message" |), "target" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_field (| M.get_name (| globals, "message" |), "target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( +(* At stmt: unsupported node type: AnnAssign *) + let accounts_to_delete := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let touched_accounts := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let refund_counter := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let logs := M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in let accounts_to_delete := @@ -242,6 +393,7 @@ Definition process_message_call : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). Definition process_create_message : Value.t -> Value.t -> M := @@ -303,6 +455,28 @@ Definition process_create_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), + (* then *) + ltac:(M.monadic ( + let contract_code := + M.get_field (| M.get_name (| globals, "evm" |), "output" |) in + let contract_code_gas := + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "contract_code" |) + ], + make_dict [] + |), + M.get_name (| globals, "GAS_CODE_DEPOSIT" |) + |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "rollback_transaction" |), make_list [ @@ -314,6 +488,7 @@ Definition process_create_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) + |) in M.pure Constant.None_)). Definition process_message : Value.t -> Value.t -> M := @@ -335,6 +510,24 @@ Definition process_message : Value.t -> Value.t -> M := Items containing execution specific objects " in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_field (| M.get_name (| globals, "message" |), "depth" |), + M.get_name (| globals, "STACK_DEPTH_LIMIT" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "StackDepthLimitError" |), + make_list [ + Constant.str "Stack depth limit reached" + ], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -353,6 +546,32 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + M.get_field (| M.get_name (| globals, "message" |), "should_transfer_value" |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "message" |), "value" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "move_ether" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "caller" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |); + M.get_field (| M.get_name (| globals, "message" |), "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let evm := @@ -365,6 +584,21 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "rollback_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "commit_transaction" |), make_list [ @@ -376,6 +610,7 @@ Definition process_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) + |) in M.pure Constant.None_)). Definition execute_code : Value.t -> Value.t -> M := @@ -415,4 +650,5 @@ Definition execute_code : Value.t -> Value.t -> M := (* At stmt: unsupported node type: Try *) let _ := M.return_ (| M.get_name (| globals, "evm" |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/memory.v b/CoqOfPython/ethereum/arrow_glacier/vm/memory.v index 4b107fd..08d2290 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/memory.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/memory.v @@ -21,13 +21,13 @@ Require ethereum.utils.byte. Axiom ethereum_utils_byte_right_pad_zero_bytes : IsGlobalAlias globals ethereum.utils.byte.globals "right_pad_zero_bytes". -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". Definition memory_write : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,7 +45,22 @@ Definition memory_write : Value.t -> Value.t -> M := Data to write to memory. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |), + M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) |) |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_)). @@ -71,7 +86,23 @@ Definition memory_read_bytes : Value.t -> Value.t -> M := Data read from memory. " in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |) + M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |) |) + |) in M.pure Constant.None_)). Definition buffer_read : Value.t -> Value.t -> M := @@ -98,9 +129,25 @@ Definition buffer_read : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "right_pad_zero_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |) |); + M.get_subscript (| M.get_name (| globals, "buffer" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |) |); M.get_name (| globals, "size" |) ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/__init__.v index ca49311..c8bcc33 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/__init__.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/__init__.v @@ -18,9 +18,9 @@ Addresses of precompiled contracts and mappings to their implementations. ". -Require utils.hexadecimal. -Axiom utils_hexadecimal_hex_to_address : - IsGlobalAlias globals utils.hexadecimal.globals "hex_to_address". +Require ethereum.arrow_glacier.utils.hexadecimal. +Axiom ethereum_arrow_glacier_utils_hexadecimal_hex_to_address : + IsGlobalAlias globals ethereum.arrow_glacier.utils.hexadecimal.globals "hex_to_address". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS"; Constant.str "MODEXP_ADDRESS"; Constant.str "ALT_BN128_ADD_ADDRESS"; Constant.str "ALT_BN128_MUL_ADDRESS"; Constant.str "ALT_BN128_PAIRING_CHECK_ADDRESS"; Constant.str "BLAKE2F_ADDRESS" ] diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/alt_bn128.v index abe4238..508a9a9 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/alt_bn128.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/alt_bn128.v @@ -45,21 +45,21 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.arrow_glacier.vm.__init__. +Axiom ethereum_arrow_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.arrow_glacier.vm.gas. +Axiom ethereum_arrow_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "charge_gas". -Require vm.memory. -Axiom vm_memory_buffer_read : - IsGlobalAlias globals vm.memory.globals "buffer_read". +Require ethereum.arrow_glacier.vm.memory. +Axiom ethereum_arrow_glacier_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.arrow_glacier.vm.memory.globals "buffer_read". -Require exceptions. -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". +Require ethereum.arrow_glacier.vm.exceptions. +Axiom ethereum_arrow_glacier_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.arrow_glacier.vm.exceptions.globals "OutOfGasError". Definition alt_bn128_add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -210,6 +210,18 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) in For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ] do let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -353,6 +365,18 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) in For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ] do let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -425,6 +449,27 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| + BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 192 + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let result := @@ -464,7 +509,7 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "data" |), BinOp.add (| + M.get_subscript (| M.get_name (| globals, "data" |), M.slice (| BinOp.add (| BinOp.mult (| M.get_name (| globals, "i" |), Constant.int 192 @@ -473,11 +518,35 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := Constant.int 32, M.get_name (| globals, "j" |) |) - |) |) + |), BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "j" |), + Constant.int 1 + |) + |) + |) |) |) ], make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -538,10 +607,80 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "p" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "q" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let result := + BinOp.mult (| + M.get_name (| globals, "result" |), + M.call (| + M.get_name (| globals, "pairing" |), + make_list [ + M.get_name (| globals, "q" |); + M.get_name (| globals, "p" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "result" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/blake2f.v b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/blake2f.v index 1647d48..3bc1b25 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/blake2f.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/blake2f.v @@ -25,19 +25,19 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.arrow_glacier.vm.__init__. +Axiom ethereum_arrow_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_BLAKE2_PER_ROUND : - IsGlobalAlias globals vm.gas.globals "GAS_BLAKE2_PER_ROUND". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.arrow_glacier.vm.gas. +Axiom ethereum_arrow_glacier_vm_gas_GAS_BLAKE2_PER_ROUND : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_BLAKE2_PER_ROUND". +Axiom ethereum_arrow_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "charge_gas". -Require exceptions. -Axiom exceptions_InvalidParameter : - IsGlobalAlias globals exceptions.globals "InvalidParameter". +Require ethereum.arrow_glacier.vm.exceptions. +Axiom ethereum_arrow_glacier_vm_exceptions_InvalidParameter : + IsGlobalAlias globals ethereum.arrow_glacier.vm.exceptions.globals "InvalidParameter". Definition blake2f : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/ecrecover.v index 0cbcf16..cb14fdc 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/ecrecover.v @@ -37,19 +37,19 @@ Require ethereum.utils.byte. Axiom ethereum_utils_byte_left_pad_zero_bytes : IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.arrow_glacier.vm.__init__. +Axiom ethereum_arrow_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_ECRECOVER : - IsGlobalAlias globals vm.gas.globals "GAS_ECRECOVER". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.arrow_glacier.vm.gas. +Axiom ethereum_arrow_glacier_vm_gas_GAS_ECRECOVER : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_ECRECOVER". +Axiom ethereum_arrow_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "charge_gas". -Require vm.memory. -Axiom vm_memory_buffer_read : - IsGlobalAlias globals vm.memory.globals "buffer_read". +Require ethereum.arrow_glacier.vm.memory. +Axiom ethereum_arrow_glacier_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.arrow_glacier.vm.memory.globals "buffer_read". Definition ecrecover : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -188,12 +188,78 @@ Definition ecrecover : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "v" |), + Constant.int 27 + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "v" |), + Constant.int 28 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + Constant.int 0, + M.get_name (| globals, "r" |) + |), + ltac:(M.monadic ( + Compare.gt_e (| + M.get_name (| globals, "r" |), + M.get_name (| globals, "SECP256K1N" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + Constant.int 0, + M.get_name (| globals, "s" |) + |), + ltac:(M.monadic ( + Compare.gt_e (| + M.get_name (| globals, "s" |), + M.get_name (| globals, "SECP256K1N" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: Try *) @@ -204,7 +270,7 @@ Definition ecrecover : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12 |) in + |), M.slice (| Constant.int 12, Constant.int 32 |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/identity.v index fa96704..b192d30 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/identity.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/identity.v @@ -25,17 +25,17 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.arrow_glacier.vm.__init__. +Axiom ethereum_arrow_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_IDENTITY : - IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY". -Axiom vm_gas_GAS_IDENTITY_WORD : - IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY_WORD". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.arrow_glacier.vm.gas. +Axiom ethereum_arrow_glacier_vm_gas_GAS_IDENTITY : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_IDENTITY". +Axiom ethereum_arrow_glacier_vm_gas_GAS_IDENTITY_WORD : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_IDENTITY_WORD". +Axiom ethereum_arrow_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "charge_gas". Definition identity : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/mapping.v index 8a2e2eb..3f3cbfc 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/mapping.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/mapping.v @@ -23,60 +23,60 @@ Axiom typing_Callable : Axiom typing_Dict : IsGlobalAlias globals typing.globals "Dict". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". - -Require __init__. -Axiom __init___ALT_BN128_ADD_ADDRESS : - IsGlobalAlias globals __init__.globals "ALT_BN128_ADD_ADDRESS". -Axiom __init___ALT_BN128_MUL_ADDRESS : - IsGlobalAlias globals __init__.globals "ALT_BN128_MUL_ADDRESS". -Axiom __init___ALT_BN128_PAIRING_CHECK_ADDRESS : - IsGlobalAlias globals __init__.globals "ALT_BN128_PAIRING_CHECK_ADDRESS". -Axiom __init___BLAKE2F_ADDRESS : - IsGlobalAlias globals __init__.globals "BLAKE2F_ADDRESS". -Axiom __init___ECRECOVER_ADDRESS : - IsGlobalAlias globals __init__.globals "ECRECOVER_ADDRESS". -Axiom __init___IDENTITY_ADDRESS : - IsGlobalAlias globals __init__.globals "IDENTITY_ADDRESS". -Axiom __init___MODEXP_ADDRESS : - IsGlobalAlias globals __init__.globals "MODEXP_ADDRESS". -Axiom __init___RIPEMD160_ADDRESS : - IsGlobalAlias globals __init__.globals "RIPEMD160_ADDRESS". -Axiom __init___SHA256_ADDRESS : - IsGlobalAlias globals __init__.globals "SHA256_ADDRESS". - -Require alt_bn128. -Axiom alt_bn128_alt_bn128_add : - IsGlobalAlias globals alt_bn128.globals "alt_bn128_add". -Axiom alt_bn128_alt_bn128_mul : - IsGlobalAlias globals alt_bn128.globals "alt_bn128_mul". -Axiom alt_bn128_alt_bn128_pairing_check : - IsGlobalAlias globals alt_bn128.globals "alt_bn128_pairing_check". - -Require blake2f. -Axiom blake2f_blake2f : - IsGlobalAlias globals blake2f.globals "blake2f". - -Require ecrecover. -Axiom ecrecover_ecrecover : - IsGlobalAlias globals ecrecover.globals "ecrecover". - -Require identity. -Axiom identity_identity : - IsGlobalAlias globals identity.globals "identity". - -Require modexp. -Axiom modexp_modexp : - IsGlobalAlias globals modexp.globals "modexp". - -Require ripemd160. -Axiom ripemd160_ripemd160 : - IsGlobalAlias globals ripemd160.globals "ripemd160". - -Require sha256. -Axiom sha256_sha256 : - IsGlobalAlias globals sha256.globals "sha256". +Require ethereum.arrow_glacier.fork_types. +Axiom ethereum_arrow_glacier_fork_types_Address : + IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "Address". + +Require ethereum.arrow_glacier.vm.precompiled_contracts.__init__. +Axiom ethereum_arrow_glacier_vm_precompiled_contracts___init___ALT_BN128_ADD_ADDRESS : + IsGlobalAlias globals ethereum.arrow_glacier.vm.precompiled_contracts.__init__.globals "ALT_BN128_ADD_ADDRESS". +Axiom ethereum_arrow_glacier_vm_precompiled_contracts___init___ALT_BN128_MUL_ADDRESS : + IsGlobalAlias globals ethereum.arrow_glacier.vm.precompiled_contracts.__init__.globals "ALT_BN128_MUL_ADDRESS". +Axiom ethereum_arrow_glacier_vm_precompiled_contracts___init___ALT_BN128_PAIRING_CHECK_ADDRESS : + IsGlobalAlias globals ethereum.arrow_glacier.vm.precompiled_contracts.__init__.globals "ALT_BN128_PAIRING_CHECK_ADDRESS". +Axiom ethereum_arrow_glacier_vm_precompiled_contracts___init___BLAKE2F_ADDRESS : + IsGlobalAlias globals ethereum.arrow_glacier.vm.precompiled_contracts.__init__.globals "BLAKE2F_ADDRESS". +Axiom ethereum_arrow_glacier_vm_precompiled_contracts___init___ECRECOVER_ADDRESS : + IsGlobalAlias globals ethereum.arrow_glacier.vm.precompiled_contracts.__init__.globals "ECRECOVER_ADDRESS". +Axiom ethereum_arrow_glacier_vm_precompiled_contracts___init___IDENTITY_ADDRESS : + IsGlobalAlias globals ethereum.arrow_glacier.vm.precompiled_contracts.__init__.globals "IDENTITY_ADDRESS". +Axiom ethereum_arrow_glacier_vm_precompiled_contracts___init___MODEXP_ADDRESS : + IsGlobalAlias globals ethereum.arrow_glacier.vm.precompiled_contracts.__init__.globals "MODEXP_ADDRESS". +Axiom ethereum_arrow_glacier_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : + IsGlobalAlias globals ethereum.arrow_glacier.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". +Axiom ethereum_arrow_glacier_vm_precompiled_contracts___init___SHA256_ADDRESS : + IsGlobalAlias globals ethereum.arrow_glacier.vm.precompiled_contracts.__init__.globals "SHA256_ADDRESS". + +Require ethereum.arrow_glacier.vm.precompiled_contracts.alt_bn128. +Axiom ethereum_arrow_glacier_vm_precompiled_contracts_alt_bn128_alt_bn128_add : + IsGlobalAlias globals ethereum.arrow_glacier.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_add". +Axiom ethereum_arrow_glacier_vm_precompiled_contracts_alt_bn128_alt_bn128_mul : + IsGlobalAlias globals ethereum.arrow_glacier.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_mul". +Axiom ethereum_arrow_glacier_vm_precompiled_contracts_alt_bn128_alt_bn128_pairing_check : + IsGlobalAlias globals ethereum.arrow_glacier.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_pairing_check". + +Require ethereum.arrow_glacier.vm.precompiled_contracts.blake2f. +Axiom ethereum_arrow_glacier_vm_precompiled_contracts_blake2f_blake2f : + IsGlobalAlias globals ethereum.arrow_glacier.vm.precompiled_contracts.blake2f.globals "blake2f". + +Require ethereum.arrow_glacier.vm.precompiled_contracts.ecrecover. +Axiom ethereum_arrow_glacier_vm_precompiled_contracts_ecrecover_ecrecover : + IsGlobalAlias globals ethereum.arrow_glacier.vm.precompiled_contracts.ecrecover.globals "ecrecover". + +Require ethereum.arrow_glacier.vm.precompiled_contracts.identity. +Axiom ethereum_arrow_glacier_vm_precompiled_contracts_identity_identity : + IsGlobalAlias globals ethereum.arrow_glacier.vm.precompiled_contracts.identity.globals "identity". + +Require ethereum.arrow_glacier.vm.precompiled_contracts.modexp. +Axiom ethereum_arrow_glacier_vm_precompiled_contracts_modexp_modexp : + IsGlobalAlias globals ethereum.arrow_glacier.vm.precompiled_contracts.modexp.globals "modexp". + +Require ethereum.arrow_glacier.vm.precompiled_contracts.ripemd160. +Axiom ethereum_arrow_glacier_vm_precompiled_contracts_ripemd160_ripemd160 : + IsGlobalAlias globals ethereum.arrow_glacier.vm.precompiled_contracts.ripemd160.globals "ripemd160". + +Require ethereum.arrow_glacier.vm.precompiled_contracts.sha256. +Axiom ethereum_arrow_glacier_vm_precompiled_contracts_sha256_sha256 : + IsGlobalAlias globals ethereum.arrow_glacier.vm.precompiled_contracts.sha256.globals "sha256". (* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/modexp.v index 3505244..4e1ef02 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/modexp.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/modexp.v @@ -25,17 +25,17 @@ Axiom ethereum_base_types_Bytes : Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.arrow_glacier.vm.__init__. +Axiom ethereum_arrow_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.arrow_glacier.vm.gas. +Axiom ethereum_arrow_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "charge_gas". -Require memory. -Axiom memory_buffer_read : - IsGlobalAlias globals memory.globals "buffer_read". +Require ethereum.arrow_glacier.vm.memory. +Axiom ethereum_arrow_glacier_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.arrow_glacier.vm.memory.globals "buffer_read". Definition GQUADDIVISOR : Value.t := M.run ltac:(M.monadic ( Constant.int 3 @@ -192,6 +192,36 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_name (| globals, "base_length" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "modulus_length" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [], + make_dict [] + |) + |) in + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let base := @@ -254,6 +284,30 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "modulus" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + BinOp.mult (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + Constant.bytes "00" + ], + make_dict [] + |), + M.get_name (| globals, "modulus_length" |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| @@ -338,6 +392,7 @@ Definition complexity : Value.t -> Value.t -> M := M.get_name (| globals, "words" |), Constant.int 2 |) + |) in M.pure Constant.None_)). Definition iterations : Value.t -> Value.t -> M := @@ -364,7 +419,76 @@ Definition iterations : Value.t -> Value.t -> M := Number of iterations. " in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.lt_e (| + M.get_name (| globals, "exponent_length" |), + Constant.int 32 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "exponent_head" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let count := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "exponent_length" |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let bit_length := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "exponent_head" |), "bit_length" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "bit_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let bit_length := BinOp.sub + Constant.int 1 + Constant.int 1 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let count := + M.get_name (| globals, "bit_length" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let length_part := BinOp.mult (| Constant.int 8, @@ -392,6 +516,20 @@ Definition iterations : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "bits_part" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let bits_part := BinOp.sub + Constant.int 1 + Constant.int 1 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let count := @@ -418,6 +556,7 @@ Definition iterations : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition gas_cost : Value.t -> Value.t -> M := @@ -489,4 +628,5 @@ Definition gas_cost : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/ripemd160.v index 96f8dcd..fa82312 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/ripemd160.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/ripemd160.v @@ -31,17 +31,17 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.arrow_glacier.vm.__init__. +Axiom ethereum_arrow_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_RIPEMD160 : - IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160". -Axiom vm_gas_GAS_RIPEMD160_WORD : - IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160_WORD". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.arrow_glacier.vm.gas. +Axiom ethereum_arrow_glacier_vm_gas_GAS_RIPEMD160 : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_RIPEMD160". +Axiom ethereum_arrow_glacier_vm_gas_GAS_RIPEMD160_WORD : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_RIPEMD160_WORD". +Axiom ethereum_arrow_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "charge_gas". Definition ripemd160 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/sha256.v index 9f6d2bf..155c6ec 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/sha256.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/sha256.v @@ -27,17 +27,17 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.arrow_glacier.vm.__init__. +Axiom ethereum_arrow_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_SHA256 : - IsGlobalAlias globals vm.gas.globals "GAS_SHA256". -Axiom vm_gas_GAS_SHA256_WORD : - IsGlobalAlias globals vm.gas.globals "GAS_SHA256_WORD". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.arrow_glacier.vm.gas. +Axiom ethereum_arrow_glacier_vm_gas_GAS_SHA256 : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_SHA256". +Axiom ethereum_arrow_glacier_vm_gas_GAS_SHA256_WORD : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_SHA256_WORD". +Axiom ethereum_arrow_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "charge_gas". Definition sha256 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/runtime.v b/CoqOfPython/ethereum/arrow_glacier/vm/runtime.v index 2cd7652..411564a 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/runtime.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/runtime.v @@ -25,9 +25,9 @@ Require ethereum.base_types. Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require instructions. -Axiom instructions_Ops : - IsGlobalAlias globals instructions.globals "Ops". +Require ethereum.arrow_glacier.vm.instructions.__init__. +Axiom ethereum_arrow_glacier_vm_instructions___init___Ops : + IsGlobalAlias globals ethereum.arrow_glacier.vm.instructions.__init__.globals "Ops". Definition get_valid_jump_destinations : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -79,7 +79,55 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := |) do (* At stmt: unsupported node type: Try *) let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "current_opcode" |), + M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), + make_list [ + M.get_name (| globals, "pc" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.lt_e (| + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |), + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH32" |), "value" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let push_data_size := + BinOp.add (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) + |), + Constant.int 1 + |) in + let pc := BinOp.add + M.get_name (| globals, "push_data_size" |) + M.get_name (| globals, "push_data_size" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -90,4 +138,5 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := EndWhile. let _ := M.return_ (| M.get_name (| globals, "valid_jump_destinations" |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/stack.v b/CoqOfPython/ethereum/arrow_glacier/vm/stack.v index ea778df..bfa5165 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/stack.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/stack.v @@ -25,11 +25,11 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require exceptions. -Axiom exceptions_StackOverflowError : - IsGlobalAlias globals exceptions.globals "StackOverflowError". -Axiom exceptions_StackUnderflowError : - IsGlobalAlias globals exceptions.globals "StackUnderflowError". +Require ethereum.arrow_glacier.vm.exceptions. +Axiom ethereum_arrow_glacier_vm_exceptions_StackOverflowError : + IsGlobalAlias globals ethereum.arrow_glacier.vm.exceptions.globals "StackOverflowError". +Axiom ethereum_arrow_glacier_vm_exceptions_StackUnderflowError : + IsGlobalAlias globals ethereum.arrow_glacier.vm.exceptions.globals "StackUnderflowError". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -49,6 +49,24 @@ Definition pop : Value.t -> Value.t -> M := " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "StackUnderflowError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -57,6 +75,7 @@ Definition pop : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). Definition push : Value.t -> Value.t -> M := @@ -75,6 +94,24 @@ Definition push : Value.t -> Value.t -> M := " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), + Constant.int 1024 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "StackOverflowError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -85,4 +122,5 @@ Definition push : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/base_types.v b/CoqOfPython/ethereum/base_types.v index 8ef03bf..78b29bc 100644 --- a/CoqOfPython/ethereum/base_types.v +++ b/CoqOfPython/ethereum/base_types.v @@ -118,6 +118,7 @@ Definition Uint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -143,6 +144,7 @@ Definition Uint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ) ] @@ -152,9 +154,45 @@ Definition Uint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "value" ] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "TypeError" |), + make_list [], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "OverflowError" |), + make_list [], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)) @@ -171,6 +209,7 @@ Definition Uint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -178,9 +217,43 @@ Definition Uint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "right" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "right" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "OverflowError" |), + make_list [], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -199,6 +272,7 @@ Definition Uint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -213,6 +287,7 @@ Definition Uint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -220,9 +295,51 @@ Definition Uint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "right" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt (| + M.get_name (| globals, "right" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.lt (| + M.get_name (| globals, "self" |), + M.get_name (| globals, "right" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "OverflowError" |), + make_list [], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -241,6 +358,7 @@ Definition Uint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -248,9 +366,51 @@ Definition Uint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "left" ] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "left" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt (| + M.get_name (| globals, "left" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.gt (| + M.get_name (| globals, "self" |), + M.get_name (| globals, "left" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "OverflowError" |), + make_list [], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -269,6 +429,7 @@ Definition Uint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -283,6 +444,7 @@ Definition Uint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -290,9 +452,43 @@ Definition Uint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "right" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "right" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "OverflowError" |), + make_list [], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -311,6 +507,7 @@ Definition Uint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -325,6 +522,7 @@ Definition Uint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -339,6 +537,7 @@ Definition Uint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -346,9 +545,43 @@ Definition Uint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "right" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "right" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "OverflowError" |), + make_list [], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -367,6 +600,7 @@ Definition Uint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -374,9 +608,43 @@ Definition Uint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "left" ] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "left" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "left" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "OverflowError" |), + make_list [], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -395,6 +663,7 @@ Definition Uint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -409,6 +678,7 @@ Definition Uint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -416,9 +686,43 @@ Definition Uint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "right" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "right" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "OverflowError" |), + make_list [], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -437,6 +741,7 @@ Definition Uint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -444,9 +749,43 @@ Definition Uint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "left" ] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "left" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "left" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "OverflowError" |), + make_list [], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -465,6 +804,7 @@ Definition Uint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -479,6 +819,7 @@ Definition Uint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -486,9 +827,43 @@ Definition Uint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "right" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "right" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "OverflowError" |), + make_list [], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let result := @@ -516,6 +891,7 @@ Definition Uint : Value.t := ], make_dict [] |) ] + |) in M.pure Constant.None_)) ); ( @@ -523,9 +899,43 @@ Definition Uint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "left" ] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "left" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "left" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "OverflowError" |), + make_list [], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let result := @@ -553,6 +963,7 @@ Definition Uint : Value.t := ], make_dict [] |) ] + |) in M.pure Constant.None_)) ); ( @@ -560,12 +971,97 @@ Definition Uint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right"; "modulo" ] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is_not (| + M.get_name (| globals, "modulo" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "modulo" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "modulo" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "OverflowError" |), + make_list [], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "right" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "right" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "OverflowError" |), + make_list [], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -585,6 +1081,7 @@ Definition Uint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -592,12 +1089,97 @@ Definition Uint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "left"; "modulo" ] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is_not (| + M.get_name (| globals, "modulo" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "modulo" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "modulo" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "OverflowError" |), + make_list [], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "left" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "left" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "OverflowError" |), + make_list [], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -617,6 +1199,7 @@ Definition Uint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -632,6 +1215,7 @@ Definition Uint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -639,9 +1223,43 @@ Definition Uint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "right" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "right" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "OverflowError" |), + make_list [], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -660,6 +1278,7 @@ Definition Uint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -667,9 +1286,43 @@ Definition Uint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "left" ] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "left" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "left" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "OverflowError" |), + make_list [], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -688,6 +1341,7 @@ Definition Uint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -702,6 +1356,7 @@ Definition Uint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -727,6 +1382,7 @@ Definition Uint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -760,6 +1416,7 @@ Definition Uint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -771,6 +1428,31 @@ Definition Uint : Value.t := representation, without padding. " in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "number_bytes" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let bit_length := + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "bit_length" |), + make_list [], + make_dict [] + |) in + let number_bytes := + BinOp.floor_div (| + BinOp.add (| + M.get_name (| globals, "bit_length" |), + Constant.int 7 + |), + Constant.int 8 + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -782,6 +1464,7 @@ Definition Uint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ) ]. @@ -808,9 +1491,53 @@ Definition FixedUint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "value" ] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "TypeError" |), + make_list [], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.gt (| + M.get_name (| globals, "value" |), + M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "OverflowError" |), + make_list [], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)) @@ -827,6 +1554,7 @@ Definition FixedUint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -834,6 +1562,24 @@ Definition FixedUint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "right" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let result := @@ -846,6 +1592,30 @@ Definition FixedUint : Value.t := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt (| + M.get_name (| globals, "right" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.gt (| + M.get_name (| globals, "result" |), + M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "OverflowError" |), + make_list [], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -857,6 +1627,7 @@ Definition FixedUint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -873,9 +1644,51 @@ Definition FixedUint : Value.t := [`MAX_VALUE`]: ref:ethereum.base_types.FixedUint.MAX_VALUE " in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "right" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt (| + M.get_name (| globals, "right" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.gt (| + M.get_name (| globals, "right" |), + M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "OverflowError" |), + make_list [], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -897,6 +1710,7 @@ Definition FixedUint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -911,6 +1725,7 @@ Definition FixedUint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -918,9 +1733,59 @@ Definition FixedUint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "right" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt (| + M.get_name (| globals, "right" |), + Constant.int 0 + |), + ltac:(M.monadic ( + BoolOp.or (| + Compare.gt (| + M.get_name (| globals, "right" |), + M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) + |), + ltac:(M.monadic ( + Compare.lt (| + M.get_name (| globals, "self" |), + M.get_name (| globals, "right" |) + |) + )) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "OverflowError" |), + make_list [], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -939,6 +1804,7 @@ Definition FixedUint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -955,9 +1821,51 @@ Definition FixedUint : Value.t := [`MAX_VALUE`]: ref:ethereum.base_types.FixedUint.MAX_VALUE " in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "right" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt (| + M.get_name (| globals, "right" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.gt (| + M.get_name (| globals, "right" |), + M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "OverflowError" |), + make_list [], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -979,6 +1887,7 @@ Definition FixedUint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -986,9 +1895,59 @@ Definition FixedUint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "left" ] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "left" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt (| + M.get_name (| globals, "left" |), + Constant.int 0 + |), + ltac:(M.monadic ( + BoolOp.or (| + Compare.gt (| + M.get_name (| globals, "left" |), + M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) + |), + ltac:(M.monadic ( + Compare.gt (| + M.get_name (| globals, "self" |), + M.get_name (| globals, "left" |) + |) + )) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "OverflowError" |), + make_list [], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1007,6 +1966,7 @@ Definition FixedUint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -1021,6 +1981,7 @@ Definition FixedUint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -1028,6 +1989,24 @@ Definition FixedUint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "right" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let result := @@ -1040,6 +2019,30 @@ Definition FixedUint : Value.t := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt (| + M.get_name (| globals, "right" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.gt (| + M.get_name (| globals, "result" |), + M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "OverflowError" |), + make_list [], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1051,6 +2054,7 @@ Definition FixedUint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -1067,9 +2071,51 @@ Definition FixedUint : Value.t := [`MAX_VALUE`]: ref:ethereum.base_types.FixedUint.MAX_VALUE " in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "right" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt (| + M.get_name (| globals, "right" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.gt (| + M.get_name (| globals, "right" |), + M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "OverflowError" |), + make_list [], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1091,6 +2137,7 @@ Definition FixedUint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -1105,6 +2152,7 @@ Definition FixedUint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -1119,6 +2167,7 @@ Definition FixedUint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -1126,9 +2175,51 @@ Definition FixedUint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "right" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt (| + M.get_name (| globals, "right" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.gt (| + M.get_name (| globals, "right" |), + M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "OverflowError" |), + make_list [], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1147,6 +2238,7 @@ Definition FixedUint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -1154,9 +2246,51 @@ Definition FixedUint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "left" ] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "left" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt (| + M.get_name (| globals, "left" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.gt (| + M.get_name (| globals, "left" |), + M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "OverflowError" |), + make_list [], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1175,6 +2309,7 @@ Definition FixedUint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -1189,6 +2324,7 @@ Definition FixedUint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -1196,9 +2332,51 @@ Definition FixedUint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "right" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt (| + M.get_name (| globals, "right" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.gt (| + M.get_name (| globals, "right" |), + M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "OverflowError" |), + make_list [], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1217,6 +2395,7 @@ Definition FixedUint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -1224,9 +2403,51 @@ Definition FixedUint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "left" ] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "left" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt (| + M.get_name (| globals, "left" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.gt (| + M.get_name (| globals, "left" |), + M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "OverflowError" |), + make_list [], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1245,6 +2466,7 @@ Definition FixedUint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -1259,6 +2481,7 @@ Definition FixedUint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -1266,9 +2489,51 @@ Definition FixedUint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "right" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt (| + M.get_name (| globals, "right" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.gt (| + M.get_name (| globals, "right" |), + M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "OverflowError" |), + make_list [], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let result := @@ -1302,6 +2567,7 @@ Definition FixedUint : Value.t := ], make_dict [] |) ] + |) in M.pure Constant.None_)) ); ( @@ -1309,9 +2575,51 @@ Definition FixedUint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "left" ] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "left" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt (| + M.get_name (| globals, "left" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.gt (| + M.get_name (| globals, "left" |), + M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "OverflowError" |), + make_list [], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let result := @@ -1345,6 +2653,7 @@ Definition FixedUint : Value.t := ], make_dict [] |) ] + |) in M.pure Constant.None_)) ); ( @@ -1352,9 +2661,86 @@ Definition FixedUint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right"; "modulo" ] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is_not (| + M.get_name (| globals, "modulo" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "modulo" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt (| + M.get_name (| globals, "modulo" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.gt (| + M.get_name (| globals, "modulo" |), + M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "OverflowError" |), + make_list [], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "right" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let result := @@ -1368,6 +2754,38 @@ Definition FixedUint : Value.t := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt (| + M.get_name (| globals, "right" |), + Constant.int 0 + |), + ltac:(M.monadic ( + BoolOp.or (| + Compare.gt (| + M.get_name (| globals, "right" |), + M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) + |), + ltac:(M.monadic ( + Compare.gt (| + M.get_name (| globals, "result" |), + M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) + |) + )) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "OverflowError" |), + make_list [], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1379,6 +2797,7 @@ Definition FixedUint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -1397,12 +2816,113 @@ Definition FixedUint : Value.t := [`MAX_VALUE`]: ref:ethereum.base_types.FixedUint.MAX_VALUE " in let _ := + (* if *) + M.if_then_else (| + Compare.is_not (| + M.get_name (| globals, "modulo" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "modulo" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt (| + M.get_name (| globals, "modulo" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.gt (| + M.get_name (| globals, "modulo" |), + M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "OverflowError" |), + make_list [], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "right" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt (| + M.get_name (| globals, "right" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.gt (| + M.get_name (| globals, "right" |), + M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "OverflowError" |), + make_list [], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1425,6 +2945,7 @@ Definition FixedUint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -1432,12 +2953,113 @@ Definition FixedUint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "left"; "modulo" ] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is_not (| + M.get_name (| globals, "modulo" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "modulo" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt (| + M.get_name (| globals, "modulo" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.gt (| + M.get_name (| globals, "modulo" |), + M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "OverflowError" |), + make_list [], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "left" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt (| + M.get_name (| globals, "left" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.gt (| + M.get_name (| globals, "left" |), + M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "OverflowError" |), + make_list [], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1457,6 +3079,7 @@ Definition FixedUint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -1472,6 +3095,7 @@ Definition FixedUint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -1479,9 +3103,51 @@ Definition FixedUint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "right" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt (| + M.get_name (| globals, "right" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.gt (| + M.get_name (| globals, "right" |), + M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "OverflowError" |), + make_list [], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1500,6 +3166,7 @@ Definition FixedUint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -1507,9 +3174,51 @@ Definition FixedUint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "right" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt (| + M.get_name (| globals, "right" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.gt (| + M.get_name (| globals, "right" |), + M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "OverflowError" |), + make_list [], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1528,6 +3237,7 @@ Definition FixedUint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -1535,9 +3245,51 @@ Definition FixedUint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "right" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt (| + M.get_name (| globals, "right" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.gt (| + M.get_name (| globals, "right" |), + M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "OverflowError" |), + make_list [], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1556,6 +3308,7 @@ Definition FixedUint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -1563,9 +3316,51 @@ Definition FixedUint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "left" ] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "left" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt (| + M.get_name (| globals, "left" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.gt (| + M.get_name (| globals, "left" |), + M.get_field (| M.get_name (| globals, "self" |), "MAX_VALUE" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "OverflowError" |), + make_list [], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1584,6 +3379,7 @@ Definition FixedUint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -1598,6 +3394,7 @@ Definition FixedUint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -1622,6 +3419,7 @@ Definition FixedUint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -1629,6 +3427,24 @@ Definition FixedUint : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "shift_by" ] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "shift_by" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1647,6 +3463,7 @@ Definition FixedUint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -1680,6 +3497,7 @@ Definition FixedUint : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ) ]. @@ -1697,6 +3515,28 @@ Definition U256 : Value.t := from its big endian representation. " in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "buffer" |) + ], + make_dict [] + |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "ValueError" |), + make_list [], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1714,6 +3554,7 @@ Definition U256 : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -1725,6 +3566,26 @@ Definition U256 : Value.t := complement. " in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "cls" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1738,6 +3599,7 @@ Definition U256 : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ) ] @@ -1765,6 +3627,7 @@ Definition U256 : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -1775,6 +3638,30 @@ Definition U256 : Value.t := Decodes a signed integer from its two's complement representation. " in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "bit_length" |), + make_list [], + make_dict [] + |), + Constant.int 256 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "self" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1788,6 +3675,7 @@ Definition U256 : Value.t := |), M.get_name (| globals, "U256_CEIL_VALUE" |) |) + |) in M.pure Constant.None_)) ) ]. @@ -1807,6 +3695,28 @@ Definition U32 : Value.t := from its little endian representation. " in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "buffer" |) + ], + make_dict [] + |), + Constant.int 4 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "ValueError" |), + make_list [], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1824,6 +3734,7 @@ Definition U32 : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ) ] @@ -1851,6 +3762,7 @@ Definition U32 : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -1884,6 +3796,7 @@ Definition U32 : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ) ]. @@ -1903,6 +3816,28 @@ Definition U64 : Value.t := from its little endian representation. " in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "buffer" |) + ], + make_dict [] + |), + Constant.int 8 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "ValueError" |), + make_list [], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1920,6 +3855,7 @@ Definition U64 : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -1931,6 +3867,28 @@ Definition U64 : Value.t := big endian representation. " in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "buffer" |) + ], + make_dict [] + |), + Constant.int 8 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "ValueError" |), + make_list [], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1948,6 +3906,7 @@ Definition U64 : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ) ] @@ -1975,6 +3934,7 @@ Definition U64 : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -2008,6 +3968,7 @@ Definition U64 : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ) ]. @@ -2072,10 +4033,35 @@ Definition FixedBytes : Value.t := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "result" |) + ], + make_dict [] + |), + M.get_field (| M.get_name (| globals, "cls" |), "LENGTH" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "ValueError" |), + make_list [ + Constant.str "(* At expr: unsupported node type: JoinedStr *)" + ], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| M.get_name (| globals, "result" |) + |) in M.pure Constant.None_)) ) ]. @@ -2173,6 +4159,29 @@ Definition _setattr_function : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "attr"; "value" ] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "getattr" |), + make_list [ + M.get_name (| globals, "self" |); + Constant.str "_frozen"; + Constant.None_ + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "Exception" |), + make_list [ + Constant.str "Mutating frozen dataclasses is not allowed." + ], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_name (| globals, "object" |), "__setattr__" |), make_list [ @@ -2190,6 +4199,21 @@ Definition _delattr_function : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "attr" ] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "self" |), "_frozen" |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "Exception" |), + make_list [ + Constant.str "Mutating frozen dataclasses is not allowed." + ], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_name (| globals, "object" |), "__delattr__" |), make_list [ @@ -2208,6 +4232,7 @@ Definition _make_init_function : Value.t -> Value.t -> M := (* At stmt: unsupported node type: FunctionDef *) let _ := M.return_ (| M.get_name (| globals, "init_function" |) + |) in M.pure Constant.None_)). Definition slotted_freezable : Value.t -> Value.t -> M := @@ -2273,6 +4298,7 @@ Definition slotted_freezable : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition S : Value.t := M.run ltac:(M.monadic ( @@ -2330,4 +4356,5 @@ Definition modify : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "new_obj" |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/blocks.v b/CoqOfPython/ethereum/berlin/blocks.v index a90217e..bb6556a 100644 --- a/CoqOfPython/ethereum/berlin/blocks.v +++ b/CoqOfPython/ethereum/berlin/blocks.v @@ -24,35 +24,35 @@ Axiom typing_Tuple : Axiom typing_Union : IsGlobalAlias globals typing.globals "Union". -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes8 : - IsGlobalAlias globals base_types.globals "Bytes8". -Axiom base_types_Bytes32 : - IsGlobalAlias globals base_types.globals "Bytes32". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require crypto.hash. -Axiom crypto_hash_Hash32 : - IsGlobalAlias globals crypto.hash.globals "Hash32". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". - -Require transactions. -Axiom transactions_LegacyTransaction : - IsGlobalAlias globals transactions.globals "LegacyTransaction". +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes8 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes8". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". + +Require ethereum.berlin.fork_types. +Axiom ethereum_berlin_fork_types_Address : + IsGlobalAlias globals ethereum.berlin.fork_types.globals "Address". +Axiom ethereum_berlin_fork_types_Bloom : + IsGlobalAlias globals ethereum.berlin.fork_types.globals "Bloom". +Axiom ethereum_berlin_fork_types_Root : + IsGlobalAlias globals ethereum.berlin.fork_types.globals "Root". + +Require ethereum.berlin.transactions. +Axiom ethereum_berlin_transactions_LegacyTransaction : + IsGlobalAlias globals ethereum.berlin.transactions.globals "LegacyTransaction". Definition Header : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/berlin/bloom.v b/CoqOfPython/ethereum/berlin/bloom.v index 04650ff..2fdbbee 100644 --- a/CoqOfPython/ethereum/berlin/bloom.v +++ b/CoqOfPython/ethereum/berlin/bloom.v @@ -33,13 +33,13 @@ Require ethereum.crypto.hash. Axiom ethereum_crypto_hash_keccak256 : IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". +Require ethereum.berlin.blocks. +Axiom ethereum_berlin_blocks_Log : + IsGlobalAlias globals ethereum.berlin.blocks.globals "Log". -Require fork_types. -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". +Require ethereum.berlin.fork_types. +Axiom ethereum_berlin_fork_types_Bloom : + IsGlobalAlias globals ethereum.berlin.fork_types.globals "Bloom". Definition add_to_bloom : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -72,7 +72,10 @@ Definition add_to_bloom : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |) |) + M.get_subscript (| M.get_name (| globals, "hash" |), M.slice (| M.get_name (| globals, "idx" |), BinOp.add (| + M.get_name (| globals, "idx" |), + Constant.int 2 + |) |) |) ], make_dict [] |), @@ -157,4 +160,5 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/fork.v b/CoqOfPython/ethereum/berlin/fork.v index bcd2a23..81d4348 100644 --- a/CoqOfPython/ethereum/berlin/fork.v +++ b/CoqOfPython/ethereum/berlin/fork.v @@ -65,105 +65,105 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U64 : - IsGlobalAlias globals base_types.globals "U64". -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_U256_CEIL_VALUE : - IsGlobalAlias globals base_types.globals "U256_CEIL_VALUE". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". - -Require __init__. -Axiom __init___vm : - IsGlobalAlias globals __init__.globals "vm". - -Require blocks. -Axiom blocks_Block : - IsGlobalAlias globals blocks.globals "Block". -Axiom blocks_Header : - IsGlobalAlias globals blocks.globals "Header". -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". -Axiom blocks_Receipt : - IsGlobalAlias globals blocks.globals "Receipt". - -Require bloom. -Axiom bloom_logs_bloom : - IsGlobalAlias globals bloom.globals "logs_bloom". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". - -Require state. -Axiom state_State : - IsGlobalAlias globals state.globals "State". -Axiom state_account_exists_and_is_empty : - IsGlobalAlias globals state.globals "account_exists_and_is_empty". -Axiom state_create_ether : - IsGlobalAlias globals state.globals "create_ether". -Axiom state_destroy_account : - IsGlobalAlias globals state.globals "destroy_account". -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". -Axiom state_increment_nonce : - IsGlobalAlias globals state.globals "increment_nonce". -Axiom state_set_account_balance : - IsGlobalAlias globals state.globals "set_account_balance". -Axiom state_state_root : - IsGlobalAlias globals state.globals "state_root". - -Require transactions. -Axiom transactions_TX_ACCESS_LIST_ADDRESS_COST : - IsGlobalAlias globals transactions.globals "TX_ACCESS_LIST_ADDRESS_COST". -Axiom transactions_TX_ACCESS_LIST_STORAGE_KEY_COST : - IsGlobalAlias globals transactions.globals "TX_ACCESS_LIST_STORAGE_KEY_COST". -Axiom transactions_TX_BASE_COST : - IsGlobalAlias globals transactions.globals "TX_BASE_COST". -Axiom transactions_TX_CREATE_COST : - IsGlobalAlias globals transactions.globals "TX_CREATE_COST". -Axiom transactions_TX_DATA_COST_PER_NON_ZERO : - IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_NON_ZERO". -Axiom transactions_TX_DATA_COST_PER_ZERO : - IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_ZERO". -Axiom transactions_AccessListTransaction : - IsGlobalAlias globals transactions.globals "AccessListTransaction". -Axiom transactions_LegacyTransaction : - IsGlobalAlias globals transactions.globals "LegacyTransaction". -Axiom transactions_Transaction : - IsGlobalAlias globals transactions.globals "Transaction". -Axiom transactions_decode_transaction : - IsGlobalAlias globals transactions.globals "decode_transaction". -Axiom transactions_encode_transaction : - IsGlobalAlias globals transactions.globals "encode_transaction". - -Require trie. -Axiom trie_Trie : - IsGlobalAlias globals trie.globals "Trie". -Axiom trie_root : - IsGlobalAlias globals trie.globals "root". -Axiom trie_trie_set : - IsGlobalAlias globals trie.globals "trie_set". - -Require utils.message. -Axiom utils_message_prepare_message : - IsGlobalAlias globals utils.message.globals "prepare_message". - -Require vm.interpreter. -Axiom vm_interpreter_process_message_call : - IsGlobalAlias globals vm.interpreter.globals "process_message_call". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U64 : + IsGlobalAlias globals ethereum.base_types.globals "U64". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_U256_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.berlin.__init__. +Axiom ethereum_berlin___init___vm : + IsGlobalAlias globals ethereum.berlin.__init__.globals "vm". + +Require ethereum.berlin.blocks. +Axiom ethereum_berlin_blocks_Block : + IsGlobalAlias globals ethereum.berlin.blocks.globals "Block". +Axiom ethereum_berlin_blocks_Header : + IsGlobalAlias globals ethereum.berlin.blocks.globals "Header". +Axiom ethereum_berlin_blocks_Log : + IsGlobalAlias globals ethereum.berlin.blocks.globals "Log". +Axiom ethereum_berlin_blocks_Receipt : + IsGlobalAlias globals ethereum.berlin.blocks.globals "Receipt". + +Require ethereum.berlin.bloom. +Axiom ethereum_berlin_bloom_logs_bloom : + IsGlobalAlias globals ethereum.berlin.bloom.globals "logs_bloom". + +Require ethereum.berlin.fork_types. +Axiom ethereum_berlin_fork_types_Address : + IsGlobalAlias globals ethereum.berlin.fork_types.globals "Address". +Axiom ethereum_berlin_fork_types_Bloom : + IsGlobalAlias globals ethereum.berlin.fork_types.globals "Bloom". +Axiom ethereum_berlin_fork_types_Root : + IsGlobalAlias globals ethereum.berlin.fork_types.globals "Root". + +Require ethereum.berlin.state. +Axiom ethereum_berlin_state_State : + IsGlobalAlias globals ethereum.berlin.state.globals "State". +Axiom ethereum_berlin_state_account_exists_and_is_empty : + IsGlobalAlias globals ethereum.berlin.state.globals "account_exists_and_is_empty". +Axiom ethereum_berlin_state_create_ether : + IsGlobalAlias globals ethereum.berlin.state.globals "create_ether". +Axiom ethereum_berlin_state_destroy_account : + IsGlobalAlias globals ethereum.berlin.state.globals "destroy_account". +Axiom ethereum_berlin_state_get_account : + IsGlobalAlias globals ethereum.berlin.state.globals "get_account". +Axiom ethereum_berlin_state_increment_nonce : + IsGlobalAlias globals ethereum.berlin.state.globals "increment_nonce". +Axiom ethereum_berlin_state_set_account_balance : + IsGlobalAlias globals ethereum.berlin.state.globals "set_account_balance". +Axiom ethereum_berlin_state_state_root : + IsGlobalAlias globals ethereum.berlin.state.globals "state_root". + +Require ethereum.berlin.transactions. +Axiom ethereum_berlin_transactions_TX_ACCESS_LIST_ADDRESS_COST : + IsGlobalAlias globals ethereum.berlin.transactions.globals "TX_ACCESS_LIST_ADDRESS_COST". +Axiom ethereum_berlin_transactions_TX_ACCESS_LIST_STORAGE_KEY_COST : + IsGlobalAlias globals ethereum.berlin.transactions.globals "TX_ACCESS_LIST_STORAGE_KEY_COST". +Axiom ethereum_berlin_transactions_TX_BASE_COST : + IsGlobalAlias globals ethereum.berlin.transactions.globals "TX_BASE_COST". +Axiom ethereum_berlin_transactions_TX_CREATE_COST : + IsGlobalAlias globals ethereum.berlin.transactions.globals "TX_CREATE_COST". +Axiom ethereum_berlin_transactions_TX_DATA_COST_PER_NON_ZERO : + IsGlobalAlias globals ethereum.berlin.transactions.globals "TX_DATA_COST_PER_NON_ZERO". +Axiom ethereum_berlin_transactions_TX_DATA_COST_PER_ZERO : + IsGlobalAlias globals ethereum.berlin.transactions.globals "TX_DATA_COST_PER_ZERO". +Axiom ethereum_berlin_transactions_AccessListTransaction : + IsGlobalAlias globals ethereum.berlin.transactions.globals "AccessListTransaction". +Axiom ethereum_berlin_transactions_LegacyTransaction : + IsGlobalAlias globals ethereum.berlin.transactions.globals "LegacyTransaction". +Axiom ethereum_berlin_transactions_Transaction : + IsGlobalAlias globals ethereum.berlin.transactions.globals "Transaction". +Axiom ethereum_berlin_transactions_decode_transaction : + IsGlobalAlias globals ethereum.berlin.transactions.globals "decode_transaction". +Axiom ethereum_berlin_transactions_encode_transaction : + IsGlobalAlias globals ethereum.berlin.transactions.globals "encode_transaction". + +Require ethereum.berlin.trie. +Axiom ethereum_berlin_trie_Trie : + IsGlobalAlias globals ethereum.berlin.trie.globals "Trie". +Axiom ethereum_berlin_trie_root : + IsGlobalAlias globals ethereum.berlin.trie.globals "root". +Axiom ethereum_berlin_trie_trie_set : + IsGlobalAlias globals ethereum.berlin.trie.globals "trie_set". + +Require ethereum.berlin.utils.message. +Axiom ethereum_berlin_utils_message_prepare_message : + IsGlobalAlias globals ethereum.berlin.utils.message.globals "prepare_message". + +Require ethereum.berlin.vm.interpreter. +Axiom ethereum_berlin_vm_interpreter_process_message_call : + IsGlobalAlias globals ethereum.berlin.vm.interpreter.globals "process_message_call". Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -256,6 +256,7 @@ Definition apply_fork : Value.t -> Value.t -> M := " in let _ := M.return_ (| M.get_name (| globals, "old" |) + |) in M.pure Constant.None_)). Definition get_last_256_block_hashes : Value.t -> Value.t -> M := @@ -281,8 +282,28 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := Hashes of the recent 256 blocks in order of increasing block number. " in let recent_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |) |) in + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "recent_blocks" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + make_list [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let recent_block_hashes := @@ -321,6 +342,7 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "recent_block_hashes" |) + |) in M.pure Constant.None_)). Definition state_transition : Value.t -> Value.t -> M := @@ -452,6 +474,27 @@ Definition state_transition : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |) + ], + make_dict [] + |), + Constant.int 255 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -644,6 +687,7 @@ Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition validate_proof_of_work : Value.t -> Value.t -> M := @@ -778,6 +822,7 @@ Definition check_transaction : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "sender_address" |) + |) in M.pure Constant.None_)). Definition make_receipt : Value.t -> Value.t -> M := @@ -810,8 +855,36 @@ Definition make_receipt : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "AccessListTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + Constant.bytes "01", + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "receipt" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "receipt" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -1037,6 +1110,7 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition validate_ommers : Value.t -> Value.t -> M := @@ -1089,6 +1163,26 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do @@ -1146,7 +1240,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let ommers_hashes := - (* At expr: unsupported node type: ListComp *) in + Constant.str "(* At expr: unsupported node type: ListComp *)" in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1177,19 +1271,19 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let recent_canonical_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| BinOp.add (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| BinOp.add (| M.get_name (| globals, "MAX_OMMER_DEPTH" |), Constant.int 1 - |) |) |) in + |) |), Constant.None_ |) |) in let recent_canonical_block_hashes := - (* At expr: unsupported node type: SetComp *) in + Constant.str "(* At expr: unsupported node type: SetComp *)" in (* At stmt: unsupported node type: AnnAssign *) For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_canonical_blocks" |) do let recent_ommers_hashes := M.call (| M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), make_list [ - (* At expr: unsupported node type: SetComp *) + Constant.str "(* At expr: unsupported node type: SetComp *)" ], make_dict [] |) in @@ -1519,6 +1613,39 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "AccessListTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + For make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "keys" |) ] in M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "preaccessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "key" |) in M.get_name (| globals, "keys" |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "preaccessed_storage_keys" |), "add" |), + make_list [ + make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "key" |) ] + ], + make_dict [] + |) in + EndFor. + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let message := @@ -1618,7 +1745,50 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "transaction_fee" |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| + M.get_name (| globals, "coinbase_balance_after_mining_fee" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |); + M.get_name (| globals, "coinbase_balance_after_mining_fee" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -1635,11 +1805,35 @@ Definition process_transaction : Value.t -> Value.t -> M := EndFor. For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "touched_accounts" |) do let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := M.return_ (| make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |); M.get_field (| M.get_name (| globals, "output" |), "error" |) ] + |) in M.pure Constant.None_)). Definition validate_transaction : Value.t -> Value.t -> M := @@ -1694,6 +1888,7 @@ Definition validate_transaction : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := @@ -1725,6 +1920,20 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := Constant.int 0 in For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "byte" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let data_cost := BinOp.add M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in @@ -1732,6 +1941,25 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := )) |) in EndFor. let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "tx" |), "to" |), + M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) + |), + (* then *) + ltac:(M.monadic ( + let create_cost := + M.get_name (| globals, "TX_CREATE_COST" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let create_cost := Constant.int 0 in M.pure Constant.None_ @@ -1739,6 +1967,47 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := let access_list_cost := Constant.int 0 in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "AccessListTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + For make_tuple [ M.get_name (| globals, "_address" |); M.get_name (| globals, "keys" |) ] in M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) do + let access_list_cost := BinOp.add + M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) + M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) in + let access_list_cost := BinOp.add + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "keys" |) + ], + make_dict [] + |), + M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) + |) + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "keys" |) + ], + make_dict [] + |), + M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) + |) in + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1758,6 +2027,7 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition recover_sender : Value.t -> Value.t -> M := @@ -1830,7 +2100,156 @@ Definition recover_sender : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "LegacyTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let v := + M.get_field (| M.get_name (| globals, "tx" |), "v" |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.eq (| + M.get_name (| globals, "v" |), + Constant.int 27 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "v" |), + Constant.int 28 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + BinOp.sub (| + M.get_name (| globals, "v" |), + Constant.int 27 + |); + M.call (| + M.get_name (| globals, "signing_hash_pre155" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.or (| + Compare.eq (| + M.get_name (| globals, "v" |), + BinOp.add (| + Constant.int 35, + BinOp.mult (| + M.get_name (| globals, "chain_id" |), + Constant.int 2 + |) + |) + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "v" |), + BinOp.add (| + Constant.int 36, + BinOp.mult (| + M.get_name (| globals, "chain_id" |), + Constant.int 2 + |) + |) + |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + BinOp.sub (| + BinOp.sub (| + M.get_name (| globals, "v" |), + Constant.int 35 + |), + BinOp.mult (| + M.get_name (| globals, "chain_id" |), + Constant.int 2 + |) + |); + M.call (| + M.get_name (| globals, "signing_hash_155" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "chain_id" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "AccessListTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + M.get_field (| M.get_name (| globals, "tx" |), "y_parity" |); + M.call (| + M.get_name (| globals, "signing_hash_2930" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -1845,10 +2264,11 @@ Definition recover_sender : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12 |) + |), M.slice (| Constant.int 12, Constant.int 32 |) |) ], make_dict [] |) + |) in M.pure Constant.None_)). Definition signing_hash_pre155 : Value.t -> Value.t -> M := @@ -1881,6 +2301,7 @@ Definition signing_hash_pre155 : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition signing_hash_155 : Value.t -> Value.t -> M := @@ -1927,6 +2348,7 @@ Definition signing_hash_155 : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition signing_hash_2930 : Value.t -> Value.t -> M := @@ -1962,6 +2384,7 @@ Definition signing_hash_2930 : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition compute_header_hash : Value.t -> Value.t -> M := @@ -2012,6 +2435,7 @@ Definition compute_header_hash : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition check_gas_limit : Value.t -> Value.t -> M := @@ -2050,16 +2474,65 @@ Definition check_gas_limit : Value.t -> Value.t -> M := M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "gas_limit" |), + BinOp.add (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "gas_limit" |), + BinOp.sub (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "gas_limit" |), + M.get_name (| globals, "GAS_LIMIT_MINIMUM" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| Constant.bool true + |) in M.pure Constant.None_)). Definition calculate_block_difficulty : Value.t -> Value.t -> M := @@ -2119,12 +2592,16 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := M.get_name (| globals, "max" |), make_list [ BinOp.sub (| - (* if *) -M.if_then_else (| - M.get_name (| globals, "parent_has_ommers" |), -(* then *) -ltac:(M.monadic ( -Constant.int 2, + (* if *) + M.if_then_else (| + M.get_name (| globals, "parent_has_ommers" |), + (* then *) + ltac:(M.monadic ( +Constant.int 2 + (* else *) + )), ltac:(M.monadic ( +Constant.int 1 + )) |), BinOp.floor_div (| M.call (| M.get_name (| globals, "int" |), @@ -2173,6 +2650,26 @@ Constant.int 2, Constant.int 2 |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "num_bomb_periods" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let difficulty := BinOp.add + BinOp.pow (| + Constant.int 2, + M.get_name (| globals, "num_bomb_periods" |) + |) + BinOp.pow (| + Constant.int 2, + M.get_name (| globals, "num_bomb_periods" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -2190,4 +2687,5 @@ Constant.int 2, ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/fork_types.v b/CoqOfPython/ethereum/berlin/fork_types.v index 5c7dac3..cc8e4a1 100644 --- a/CoqOfPython/ethereum/berlin/fork_types.v +++ b/CoqOfPython/ethereum/berlin/fork_types.v @@ -21,29 +21,29 @@ Require dataclasses. Axiom dataclasses_dataclass : IsGlobalAlias globals dataclasses.globals "dataclass". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes20 : - IsGlobalAlias globals base_types.globals "Bytes20". -Axiom base_types_Bytes256 : - IsGlobalAlias globals base_types.globals "Bytes256". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require crypto.hash. -Axiom crypto_hash_Hash32 : - IsGlobalAlias globals crypto.hash.globals "Hash32". -Axiom crypto_hash_keccak256 : - IsGlobalAlias globals crypto.hash.globals "keccak256". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes20 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes20". +Axiom ethereum_base_types_Bytes256 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) @@ -98,4 +98,5 @@ Definition encode_account : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/state.v b/CoqOfPython/ethereum/berlin/state.v index c3290a6..84f6db5 100644 --- a/CoqOfPython/ethereum/berlin/state.v +++ b/CoqOfPython/ethereum/berlin/state.v @@ -56,29 +56,29 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require fork_types. -Axiom fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". -Axiom fork_types_Account : - IsGlobalAlias globals fork_types.globals "Account". -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". - -Require trie. -Axiom trie_EMPTY_TRIE_ROOT : - IsGlobalAlias globals trie.globals "EMPTY_TRIE_ROOT". -Axiom trie_Trie : - IsGlobalAlias globals trie.globals "Trie". -Axiom trie_copy_trie : - IsGlobalAlias globals trie.globals "copy_trie". -Axiom trie_root : - IsGlobalAlias globals trie.globals "root". -Axiom trie_trie_get : - IsGlobalAlias globals trie.globals "trie_get". -Axiom trie_trie_set : - IsGlobalAlias globals trie.globals "trie_set". +Require ethereum.berlin.fork_types. +Axiom ethereum_berlin_fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals ethereum.berlin.fork_types.globals "EMPTY_ACCOUNT". +Axiom ethereum_berlin_fork_types_Account : + IsGlobalAlias globals ethereum.berlin.fork_types.globals "Account". +Axiom ethereum_berlin_fork_types_Address : + IsGlobalAlias globals ethereum.berlin.fork_types.globals "Address". +Axiom ethereum_berlin_fork_types_Root : + IsGlobalAlias globals ethereum.berlin.fork_types.globals "Root". + +Require ethereum.berlin.trie. +Axiom ethereum_berlin_trie_EMPTY_TRIE_ROOT : + IsGlobalAlias globals ethereum.berlin.trie.globals "EMPTY_TRIE_ROOT". +Axiom ethereum_berlin_trie_Trie : + IsGlobalAlias globals ethereum.berlin.trie.globals "Trie". +Axiom ethereum_berlin_trie_copy_trie : + IsGlobalAlias globals ethereum.berlin.trie.globals "copy_trie". +Axiom ethereum_berlin_trie_root : + IsGlobalAlias globals ethereum.berlin.trie.globals "root". +Axiom ethereum_berlin_trie_trie_get : + IsGlobalAlias globals ethereum.berlin.trie.globals "trie_get". +Axiom ethereum_berlin_trie_trie_set : + IsGlobalAlias globals ethereum.berlin.trie.globals "trie_set". Definition State : Value.t := builtins.make_klass @@ -126,7 +126,7 @@ Definition begin_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) ], make_dict [] - |); (* At expr: unsupported node type: DictComp *) ] + |); Constant.str "(* At expr: unsupported node type: DictComp *)" ] ], make_dict [] |) in @@ -149,6 +149,19 @@ Definition commit_transaction : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "clear" |), + make_list [], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -174,6 +187,19 @@ Definition rollback_transaction : Value.t -> Value.t -> M := |) |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "clear" |), + make_list [], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -210,8 +236,27 @@ Definition get_account : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "account" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "account" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_ACCOUNT" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -246,6 +291,7 @@ Definition get_account_optional : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "account" |) + |) in M.pure Constant.None_)). Definition set_account : Value.t -> Value.t -> M := @@ -325,6 +371,18 @@ Definition destroy_storage : Value.t -> Value.t -> M := Address of account whose storage is to be deleted. " in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -387,6 +445,26 @@ Definition get_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "trie" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let value := @@ -408,6 +486,7 @@ Definition get_storage : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "value" |) + |) in M.pure Constant.None_)). Definition set_storage : Value.t -> Value.t -> M := @@ -448,6 +527,27 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "trie" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let trie := + M.call (| + M.get_name (| globals, "Trie" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), + M.get_name (| globals, "trie" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -460,6 +560,18 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + {} + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -484,8 +596,29 @@ Definition storage_root : Value.t -> Value.t -> M := " in let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_TRIE_ROOT" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -516,6 +649,7 @@ Definition state_root : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition account_exists : Value.t -> Value.t -> M := @@ -548,6 +682,7 @@ Definition account_exists : Value.t -> Value.t -> M := |), Constant.None_ |) + |) in M.pure Constant.None_)). Definition account_has_code_or_nonce : Value.t -> Value.t -> M := @@ -597,6 +732,7 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition is_account_empty : Value.t -> Value.t -> M := @@ -654,6 +790,7 @@ Definition is_account_empty : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition account_exists_and_is_empty : Value.t -> Value.t -> M := @@ -720,6 +857,7 @@ Definition account_exists_and_is_empty : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition is_account_alive : Value.t -> Value.t -> M := @@ -750,6 +888,20 @@ Definition is_account_alive : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "account" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| UnOp.not (| BoolOp.and (| Compare.eq (| @@ -777,6 +929,7 @@ Definition is_account_alive : Value.t -> Value.t -> M := |) )) |) |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -884,6 +1037,30 @@ Definition touch_account : Value.t -> Value.t -> M := The address of the account that need to initialised. " in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "account_exists" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "EMPTY_ACCOUNT" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -988,6 +1165,26 @@ Definition get_storage_original : Value.t -> Value.t -> M := Key of the storage slot. " in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -1003,6 +1200,25 @@ Definition get_storage_original : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "original_account_trie" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let original_value := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let original_value := M.call (| M.get_name (| globals, "trie_get" |), @@ -1024,4 +1240,5 @@ Definition get_storage_original : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "original_value" |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/transactions.v b/CoqOfPython/ethereum/berlin/transactions.v index 2ded28b..a5e38fa 100644 --- a/CoqOfPython/ethereum/berlin/transactions.v +++ b/CoqOfPython/ethereum/berlin/transactions.v @@ -19,37 +19,37 @@ Axiom typing_Tuple : Axiom typing_Union : IsGlobalAlias globals typing.globals "Union". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U64 : - IsGlobalAlias globals base_types.globals "U64". -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes0 : - IsGlobalAlias globals base_types.globals "Bytes0". -Axiom base_types_Bytes32 : - IsGlobalAlias globals base_types.globals "Bytes32". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require exceptions. -Axiom exceptions_InvalidBlock : - IsGlobalAlias globals exceptions.globals "InvalidBlock". - -Require utils.ensure. -Axiom utils_ensure_ensure : - IsGlobalAlias globals utils.ensure.globals "ensure". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U64 : + IsGlobalAlias globals ethereum.base_types.globals "U64". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.exceptions. +Axiom ethereum_exceptions_InvalidBlock : + IsGlobalAlias globals ethereum.exceptions.globals "InvalidBlock". + +Require ethereum.utils.ensure. +Axiom ethereum_utils_ensure_ensure : + IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". + +Require ethereum.berlin.fork_types. +Axiom ethereum_berlin_fork_types_Address : + IsGlobalAlias globals ethereum.berlin.fork_types.globals "Address". Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( Constant.int 21000 @@ -106,14 +106,59 @@ Definition encode_transaction : Value.t -> Value.t -> M := Encode a transaction. Needed because non-legacy transactions aren't RLP. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "LegacyTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "tx" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "AccessListTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + Constant.bytes "01", + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.raise (| Some(M.call (| M.get_name (| globals, "Exception" |), make_list [ - (* At expr: unsupported node type: JoinedStr *) + Constant.str "(* At expr: unsupported node type: JoinedStr *)" ], make_dict [] - |)) + |)) |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -127,8 +172,45 @@ Definition decode_transaction : Value.t -> Value.t -> M := Decode a transaction. Needed because non-legacy transactions aren't RLP. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), + Constant.int 1 + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), + make_list [ + M.get_name (| globals, "AccessListTransaction" |); + M.get_subscript (| M.get_name (| globals, "tx" |), M.slice (| Constant.int 1, Constant.None_ |) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "tx" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/trie.v b/CoqOfPython/ethereum/berlin/trie.v index 6a34e8c..8a3cc9d 100644 --- a/CoqOfPython/ethereum/berlin/trie.v +++ b/CoqOfPython/ethereum/berlin/trie.v @@ -54,9 +54,9 @@ Require ethereum.crypto.hash. Axiom ethereum_crypto_hash_keccak256 : IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". -Require ethereum.muir_glacier. -Axiom ethereum_muir_glacier_trie : - IsGlobalAlias globals ethereum.muir_glacier.globals "trie". +Require ethereum.muir_glacier.__init__. +Axiom ethereum_muir_glacier___init___trie : + IsGlobalAlias globals ethereum.muir_glacier.__init__.globals "trie". Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : @@ -66,37 +66,37 @@ Require ethereum.utils.hexadecimal. Axiom ethereum_utils_hexadecimal_hex_to_bytes : IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require blocks. -Axiom blocks_Receipt : - IsGlobalAlias globals blocks.globals "Receipt". - -Require fork_types. -Axiom fork_types_Account : - IsGlobalAlias globals fork_types.globals "Account". -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". -Axiom fork_types_encode_account : - IsGlobalAlias globals fork_types.globals "encode_account". - -Require transactions. -Axiom transactions_LegacyTransaction : - IsGlobalAlias globals transactions.globals "LegacyTransaction". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.berlin.blocks. +Axiom ethereum_berlin_blocks_Receipt : + IsGlobalAlias globals ethereum.berlin.blocks.globals "Receipt". + +Require ethereum.berlin.fork_types. +Axiom ethereum_berlin_fork_types_Account : + IsGlobalAlias globals ethereum.berlin.fork_types.globals "Account". +Axiom ethereum_berlin_fork_types_Address : + IsGlobalAlias globals ethereum.berlin.fork_types.globals "Address". +Axiom ethereum_berlin_fork_types_Root : + IsGlobalAlias globals ethereum.berlin.fork_types.globals "Root". +Axiom ethereum_berlin_fork_types_encode_account : + IsGlobalAlias globals ethereum.berlin.fork_types.globals "encode_account". + +Require ethereum.berlin.transactions. +Axiom ethereum_berlin_transactions_LegacyTransaction : + IsGlobalAlias globals ethereum.berlin.transactions.globals "LegacyTransaction". Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -202,16 +202,99 @@ Definition encode_internal_node : Value.t -> Value.t -> M := " in (* At stmt: unsupported node type: AnnAssign *) let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "node" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + Constant.bytes "" in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "LeafNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "rest_of_key" |); + Constant.bool true + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "ExtensionNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "key_segment" |); + Constant.bool false + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "BranchNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + BinOp.add (| + M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "value" |) + ] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ - (* At expr: unsupported node type: JoinedStr *) + Constant.str "(* At expr: unsupported node type: JoinedStr *)" ], make_dict [] - |)) + |)) |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -229,6 +312,26 @@ Definition encode_internal_node : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded" |) + ], + make_dict [] + |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "unencoded" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_name (| globals, "keccak256" |), @@ -237,6 +340,7 @@ Definition encode_internal_node : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -250,8 +354,86 @@ Definition encode_node : Value.t -> Value.t -> M := Currently mostly an unimplemented stub. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| + M.get_name (| globals, "storage_root" |), + Constant.None_ + |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "encode_account" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "storage_root" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "U256" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "cast" |), + make_list [ + M.get_field (| M.get_name (| globals, "rlp" |), "RLP" |); + M.get_name (| globals, "node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "node" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "previous_trie" |), "encode_node" |), @@ -261,6 +443,7 @@ Definition encode_node : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -312,6 +495,7 @@ Definition copy_trie : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition trie_set : Value.t -> Value.t -> M := @@ -333,6 +517,32 @@ Definition trie_set : Value.t -> Value.t -> M := Node to insert at `key`. " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + M.get_field (| M.get_name (| globals, "trie" |), "default" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "key" |), + M.get_field (| M.get_name (| globals, "trie" |), "_data" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), M.get_name (| globals, "value" |) @@ -370,6 +580,7 @@ Definition trie_get : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition common_prefix_length : Value.t -> Value.t -> M := @@ -392,6 +603,34 @@ Definition common_prefix_length : Value.t -> Value.t -> M := make_dict [] |) do let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), + M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -403,6 +642,7 @@ Definition common_prefix_length : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition nibble_list_to_compact : Value.t -> Value.t -> M := @@ -448,6 +688,71 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + Constant.int 2 + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.mult (| + Constant.int 16, + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "is_leaf" |) + |) + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ @@ -509,6 +814,7 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition bytes_to_nibble_list : Value.t -> Value.t -> M := @@ -586,6 +892,7 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition _prepare_trie : Value.t -> Value.t -> M := @@ -615,6 +922,48 @@ Definition _prepare_trie : Value.t -> Value.t -> M := make_dict [] |) do let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| + M.get_name (| globals, "get_storage_root" |), + Constant.None_ + |) |) in + let address := + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |); + M.call (| + M.get_name (| globals, "get_storage_root" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let encoded_value := M.call (| M.get_name (| globals, "encode_node" |), @@ -638,6 +987,22 @@ Definition _prepare_trie : Value.t -> Value.t -> M := |) in (* At stmt: unsupported node type: AnnAssign *) let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "trie" |), "secured" |), + (* then *) + ltac:(M.monadic ( + let key := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let key := M.get_name (| globals, "preimage" |) in M.pure Constant.None_ @@ -655,6 +1020,7 @@ Definition _prepare_trie : Value.t -> Value.t -> M := EndFor. let _ := M.return_ (| M.get_name (| globals, "mapped" |) + |) in M.pure Constant.None_)). Definition root : Value.t -> Value.t -> M := @@ -708,6 +1074,44 @@ Definition root : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -724,6 +1128,7 @@ Definition root : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -750,6 +1155,26 @@ Definition patricialize : Value.t -> Value.t -> M := Root node of `obj`. " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let arbitrary_key := @@ -767,10 +1192,39 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), + Constant.int 1 + |), + (* then *) + ltac:(M.monadic ( + let leaf := + M.call (| + M.get_name (| globals, "LeafNode" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |); + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "leaf" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let substring := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |) |) in + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) in let prefix_length := M.call (| M.get_name (| globals, "len" |), @@ -789,7 +1243,7 @@ Definition patricialize : Value.t -> Value.t -> M := M.get_name (| globals, "common_prefix_length" |), make_list [ M.get_name (| globals, "substring" |); - M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) + M.get_subscript (| M.get_name (| globals, "key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) ], make_dict [] |) @@ -797,10 +1251,64 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "prefix_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "prefix_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let prefix := + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ExtensionNode" |), + make_list [ + M.get_name (| globals, "prefix" |); + M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_name (| globals, "obj" |); + BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) @@ -823,6 +1331,44 @@ Definition patricialize : Value.t -> Value.t -> M := Constant.bytes "" in For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |), + M.get_name (| globals, "level" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "AssertionError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) @@ -834,9 +1380,10 @@ Definition patricialize : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "BranchNode" |), make_list [ - (* At expr: unsupported node type: ListComp *); + Constant.str "(* At expr: unsupported node type: ListComp *)"; M.get_name (| globals, "value" |) ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/utils/address.v b/CoqOfPython/ethereum/berlin/utils/address.v index 8f7acf4..5bfce50 100644 --- a/CoqOfPython/ethereum/berlin/utils/address.v +++ b/CoqOfPython/ethereum/berlin/utils/address.v @@ -38,13 +38,13 @@ Require ethereum.utils.byte. Axiom ethereum_utils_byte_left_pad_zero_bytes : IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.berlin.fork_types. +Axiom ethereum_berlin_fork_types_Address : + IsGlobalAlias globals ethereum.berlin.fork_types.globals "Address". Definition to_address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -70,10 +70,11 @@ Definition to_address : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), make_list [], make_dict [] - |), UnOp.sub (| Constant.int 20 |) |) + |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) ], make_dict [] |) + |) in M.pure Constant.None_)). Definition compute_contract_address : Value.t -> Value.t -> M := @@ -113,7 +114,7 @@ Definition compute_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -131,6 +132,7 @@ Definition compute_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition compute_create2_contract_address : Value.t -> Value.t -> M := @@ -180,7 +182,7 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -198,4 +200,5 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/utils/hexadecimal.v b/CoqOfPython/ethereum/berlin/utils/hexadecimal.v index 042f2a4..0394245 100644 --- a/CoqOfPython/ethereum/berlin/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/berlin/utils/hexadecimal.v @@ -22,13 +22,13 @@ Require ethereum.utils.hexadecimal. Axiom ethereum_utils_hexadecimal_remove_hex_prefix : IsGlobalAlias globals ethereum.utils.hexadecimal.globals "remove_hex_prefix". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". +Require ethereum.berlin.fork_types. +Axiom ethereum_berlin_fork_types_Address : + IsGlobalAlias globals ethereum.berlin.fork_types.globals "Address". +Axiom ethereum_berlin_fork_types_Bloom : + IsGlobalAlias globals ethereum.berlin.fork_types.globals "Bloom". +Axiom ethereum_berlin_fork_types_Root : + IsGlobalAlias globals ethereum.berlin.fork_types.globals "Root". Definition hex_to_root : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -66,6 +66,7 @@ Definition hex_to_root : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition hex_to_bloom : Value.t -> Value.t -> M := @@ -104,6 +105,7 @@ Definition hex_to_bloom : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition hex_to_address : Value.t -> Value.t -> M := @@ -149,4 +151,5 @@ Definition hex_to_address : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/utils/message.v b/CoqOfPython/ethereum/berlin/utils/message.v index 5fddaaa..7ae8e81 100644 --- a/CoqOfPython/ethereum/berlin/utils/message.v +++ b/CoqOfPython/ethereum/berlin/utils/message.v @@ -40,27 +40,27 @@ Axiom ethereum_base_types_Bytes32 : Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.berlin.fork_types. +Axiom ethereum_berlin_fork_types_Address : + IsGlobalAlias globals ethereum.berlin.fork_types.globals "Address". -Require state. -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". +Require ethereum.berlin.state. +Axiom ethereum_berlin_state_get_account : + IsGlobalAlias globals ethereum.berlin.state.globals "get_account". -Require vm. -Axiom vm_Environment : - IsGlobalAlias globals vm.globals "Environment". -Axiom vm_Message : - IsGlobalAlias globals vm.globals "Message". +Require ethereum.berlin.vm.__init__. +Axiom ethereum_berlin_vm___init___Environment : + IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Environment". +Axiom ethereum_berlin_vm___init___Message : + IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Message". -Require vm.precompiled_contracts.mapping. -Axiom vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : - IsGlobalAlias globals vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". +Require ethereum.berlin.vm.precompiled_contracts.mapping. +Axiom ethereum_berlin_vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : + IsGlobalAlias globals ethereum.berlin.vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". -Require address. -Axiom address_compute_contract_address : - IsGlobalAlias globals address.globals "compute_contract_address". +Require ethereum.berlin.utils.address. +Axiom ethereum_berlin_utils_address_compute_contract_address : + IsGlobalAlias globals ethereum.berlin.utils.address.globals "compute_contract_address". Definition prepare_message : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -103,14 +103,108 @@ Definition prepare_message : Value.t -> Value.t -> M := Items containing contract creation or message call specific data. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Bytes0" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.call (| + M.get_name (| globals, "compute_contract_address" |), + make_list [ + M.get_name (| globals, "caller" |); + BinOp.sub (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "caller" |) + ], + make_dict [] + |), "nonce" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let msg_data := + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) in + let code := + M.get_name (| globals, "data" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.get_name (| globals, "target" |) in + let msg_data := + M.get_name (| globals, "data" |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "target" |) + ], + make_dict [] + |), "code" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "code_address" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let code_address := + M.get_name (| globals, "target" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "Target must be address or empty bytes" ], make_dict [] - |)) + |)) |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -159,4 +253,5 @@ Definition prepare_message : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/vm/__init__.v b/CoqOfPython/ethereum/berlin/vm/__init__.v index 49da5ae..28ae436 100644 --- a/CoqOfPython/ethereum/berlin/vm/__init__.v +++ b/CoqOfPython/ethereum/berlin/vm/__init__.v @@ -52,23 +52,23 @@ Require ethereum.crypto.hash. Axiom ethereum_crypto_hash_Hash32 : IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". +Require ethereum.berlin.blocks. +Axiom ethereum_berlin_blocks_Log : + IsGlobalAlias globals ethereum.berlin.blocks.globals "Log". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.berlin.fork_types. +Axiom ethereum_berlin_fork_types_Address : + IsGlobalAlias globals ethereum.berlin.fork_types.globals "Address". -Require state. -Axiom state_State : - IsGlobalAlias globals state.globals "State". -Axiom state_account_exists_and_is_empty : - IsGlobalAlias globals state.globals "account_exists_and_is_empty". +Require ethereum.berlin.state. +Axiom ethereum_berlin_state_State : + IsGlobalAlias globals ethereum.berlin.state.globals "State". +Axiom ethereum_berlin_state_account_exists_and_is_empty : + IsGlobalAlias globals ethereum.berlin.state.globals "account_exists_and_is_empty". -Require precompiled_contracts. -Axiom precompiled_contracts_RIPEMD160_ADDRESS : - IsGlobalAlias globals precompiled_contracts.globals "RIPEMD160_ADDRESS". +Require ethereum.berlin.vm.precompiled_contracts.__init__. +Axiom ethereum_berlin_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : + IsGlobalAlias globals ethereum.berlin.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] @@ -147,6 +147,28 @@ Definition incorporate_child_on_success : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -179,9 +201,63 @@ Definition incorporate_child_on_error : Value.t -> Value.t -> M := The child evm to incorporate. " in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "RIPEMD160_ADDRESS" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |), + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign_op (| diff --git a/CoqOfPython/ethereum/berlin/vm/gas.v b/CoqOfPython/ethereum/berlin/vm/gas.v index e5e241b..de7b9ff 100644 --- a/CoqOfPython/ethereum/berlin/vm/gas.v +++ b/CoqOfPython/ethereum/berlin/vm/gas.v @@ -43,13 +43,13 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.berlin.vm.__init__. +Axiom ethereum_berlin_vm___init___Evm : + IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Evm". -Require exceptions. -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". +Require ethereum.berlin.vm.exceptions. +Axiom ethereum_berlin_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.berlin.vm.exceptions.globals "OutOfGasError". Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -510,6 +510,18 @@ Definition charge_gas : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "amount" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign_op (| BinOp.sub, M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), @@ -625,6 +637,18 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := |) in For make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ] in M.get_name (| globals, "extensions" |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "size" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let before_size := @@ -659,6 +683,18 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let size_to_extend := BinOp.add @@ -707,6 +743,7 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition calculate_message_call_gas : Value.t -> Value.t -> M := @@ -738,22 +775,56 @@ Definition calculate_message_call_gas : Value.t -> Value.t -> M := message_call_gas: `MessageCallGas` " in let call_stipend := - (* if *) -M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "call_stipend" |) + )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "gas_left" |), + BinOp.add (| + M.get_name (| globals, "extra_gas" |), + M.get_name (| globals, "memory_cost" |) + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallGas" |), + make_list [ + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "extra_gas" |) + |); + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "call_stipend" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let gas := @@ -792,6 +863,7 @@ M.call (| ], make_dict [] |) + |) in M.pure Constant.None_)). Definition max_message_call_gas : Value.t -> Value.t -> M := @@ -818,4 +890,5 @@ Definition max_message_call_gas : Value.t -> Value.t -> M := Constant.int 64 |) |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/__init__.v b/CoqOfPython/ethereum/berlin/vm/instructions/__init__.v index e5bebd7..e872151 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/__init__.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/__init__.v @@ -26,53 +26,53 @@ Axiom typing_Callable : Axiom typing_Dict : IsGlobalAlias globals typing.globals "Dict". -Require __init__. -Axiom __init___arithmetic : - IsGlobalAlias globals __init__.globals "arithmetic". +Require ethereum.berlin.vm.instructions.__init__. +Axiom ethereum_berlin_vm_instructions___init___arithmetic : + IsGlobalAlias globals ethereum.berlin.vm.instructions.__init__.globals "arithmetic". -Require __init__. -Axiom __init___bitwise : - IsGlobalAlias globals __init__.globals "bitwise". +Require ethereum.berlin.vm.instructions.__init__. +Axiom ethereum_berlin_vm_instructions___init___bitwise : + IsGlobalAlias globals ethereum.berlin.vm.instructions.__init__.globals "bitwise". -Require __init__. -Axiom __init___block : - IsGlobalAlias globals __init__.globals "block". +Require ethereum.berlin.vm.instructions.__init__. +Axiom ethereum_berlin_vm_instructions___init___block : + IsGlobalAlias globals ethereum.berlin.vm.instructions.__init__.globals "block". -Require __init__. -Axiom __init___comparison : - IsGlobalAlias globals __init__.globals "comparison". +Require ethereum.berlin.vm.instructions.__init__. +Axiom ethereum_berlin_vm_instructions___init___comparison : + IsGlobalAlias globals ethereum.berlin.vm.instructions.__init__.globals "comparison". -Require __init__. -Axiom __init___control_flow : - IsGlobalAlias globals __init__.globals "control_flow". +Require ethereum.berlin.vm.instructions.__init__. +Axiom ethereum_berlin_vm_instructions___init___control_flow : + IsGlobalAlias globals ethereum.berlin.vm.instructions.__init__.globals "control_flow". -Require __init__. -Axiom __init___environment : - IsGlobalAlias globals __init__.globals "environment". +Require ethereum.berlin.vm.instructions.__init__. +Axiom ethereum_berlin_vm_instructions___init___environment : + IsGlobalAlias globals ethereum.berlin.vm.instructions.__init__.globals "environment". -Require __init__. -Axiom __init___keccak : - IsGlobalAlias globals __init__.globals "keccak". +Require ethereum.berlin.vm.instructions.__init__. +Axiom ethereum_berlin_vm_instructions___init___keccak : + IsGlobalAlias globals ethereum.berlin.vm.instructions.__init__.globals "keccak". -Require __init__. -Axiom __init___log : - IsGlobalAlias globals __init__.globals "log". +Require ethereum.berlin.vm.instructions.__init__. +Axiom ethereum_berlin_vm_instructions___init___log : + IsGlobalAlias globals ethereum.berlin.vm.instructions.__init__.globals "log". -Require __init__. -Axiom __init___memory : - IsGlobalAlias globals __init__.globals "memory". +Require ethereum.berlin.vm.instructions.__init__. +Axiom ethereum_berlin_vm_instructions___init___memory : + IsGlobalAlias globals ethereum.berlin.vm.instructions.__init__.globals "memory". -Require __init__. -Axiom __init___stack : - IsGlobalAlias globals __init__.globals "stack". +Require ethereum.berlin.vm.instructions.__init__. +Axiom ethereum_berlin_vm_instructions___init___stack : + IsGlobalAlias globals ethereum.berlin.vm.instructions.__init__.globals "stack". -Require __init__. -Axiom __init___storage : - IsGlobalAlias globals __init__.globals "storage". +Require ethereum.berlin.vm.instructions.__init__. +Axiom ethereum_berlin_vm_instructions___init___storage : + IsGlobalAlias globals ethereum.berlin.vm.instructions.__init__.globals "storage". -Require __init__. -Axiom __init___system : - IsGlobalAlias globals __init__.globals "system". +Require ethereum.berlin.vm.instructions.__init__. +Axiom ethereum_berlin_vm_instructions___init___system : + IsGlobalAlias globals ethereum.berlin.vm.instructions.__init__.globals "system". Definition Ops : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/berlin/vm/instructions/arithmetic.v index 581ba5d..b798ec7 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/arithmetic.v @@ -31,29 +31,29 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_get_sign : IsGlobalAlias globals ethereum.utils.numeric.globals "get_sign". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_EXPONENTIATION : - IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION". -Axiom gas_GAS_EXPONENTIATION_PER_BYTE : - IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION_PER_BYTE". -Axiom gas_GAS_LOW : - IsGlobalAlias globals gas.globals "GAS_LOW". -Axiom gas_GAS_MID : - IsGlobalAlias globals gas.globals "GAS_MID". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.berlin.vm.__init__. +Axiom ethereum_berlin_vm___init___Evm : + IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Evm". + +Require ethereum.berlin.vm.gas. +Axiom ethereum_berlin_vm_gas_GAS_EXPONENTIATION : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_EXPONENTIATION". +Axiom ethereum_berlin_vm_gas_GAS_EXPONENTIATION_PER_BYTE : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_EXPONENTIATION_PER_BYTE". +Axiom ethereum_berlin_vm_gas_GAS_LOW : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_LOW". +Axiom ethereum_berlin_vm_gas_GAS_MID : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_MID". +Axiom ethereum_berlin_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_berlin_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "charge_gas". + +Require ethereum.berlin.vm.stack. +Axiom ethereum_berlin_vm_stack_pop : + IsGlobalAlias globals ethereum.berlin.vm.stack.globals "pop". +Axiom ethereum_berlin_vm_stack_push : + IsGlobalAlias globals ethereum.berlin.vm.stack.globals "push". Definition add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -273,6 +273,25 @@ Definition div : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "divisor" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let quotient := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let quotient := BinOp.floor_div (| M.get_name (| globals, "dividend" |), @@ -341,7 +360,41 @@ Definition sdiv : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "divisor" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let quotient := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_name (| globals, "dividend" |), + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "divisor" |), + UnOp.sub (| Constant.int 1 |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let quotient := + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let sign := M.call (| M.get_name (| globals, "get_sign" |), @@ -436,6 +489,25 @@ Definition mod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "y" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let remainder := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let remainder := BinOp.mod_ (| M.get_name (| globals, "x" |), @@ -504,6 +576,19 @@ Definition smod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "y" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let remainder := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let remainder := BinOp.mult (| M.call (| @@ -617,6 +702,25 @@ Definition addmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "z" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -712,6 +816,25 @@ Definition mulmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "z" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -881,6 +1004,19 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "byte_num" |), + Constant.int 31 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.get_name (| globals, "value" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let value_bytes := M.call (| M.get_name (| globals, "bytes" |), @@ -894,7 +1030,7 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let value_bytes := - M.get_subscript (| M.get_name (| globals, "value_bytes" |), BinOp.sub (| + M.get_subscript (| M.get_name (| globals, "value_bytes" |), M.slice (| BinOp.sub (| Constant.int 31, M.call (| M.get_name (| globals, "int" |), @@ -903,13 +1039,32 @@ Definition signextend : Value.t -> Value.t -> M := ], make_dict [] |) - |) |) in + |), Constant.None_ |) |) in let sign_bit := BinOp.r_shift (| M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), Constant.int 7 |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "sign_bit" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "value_bytes" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let num_bytes_prepend := BinOp.sub (| Constant.int 32, diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/bitwise.v b/CoqOfPython/ethereum/berlin/vm/instructions/bitwise.v index 64cf120..ce34236 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/bitwise.v @@ -23,21 +23,21 @@ Axiom ethereum_base_types_U256 : Axiom ethereum_base_types_U256_CEIL_VALUE : IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.berlin.vm.__init__. +Axiom ethereum_berlin_vm___init___Evm : + IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.berlin.vm.gas. +Axiom ethereum_berlin_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_berlin_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "charge_gas". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.berlin.vm.stack. +Axiom ethereum_berlin_vm_stack_pop : + IsGlobalAlias globals ethereum.berlin.vm.stack.globals "pop". +Axiom ethereum_berlin_vm_stack_push : + IsGlobalAlias globals ethereum.berlin.vm.stack.globals "push". Definition bitwise_and : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -287,6 +287,25 @@ Definition get_byte : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "byte_index" |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let extra_bytes_to_right := BinOp.sub (| Constant.int 31, @@ -366,6 +385,31 @@ Definition bitwise_shl : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "shift" |), + Constant.int 256 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.l_shift (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "shift" |) + |), + M.get_name (| globals, "U256_CEIL_VALUE" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -427,6 +471,22 @@ Definition bitwise_shr : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "shift" |), + Constant.int 256 + |), + (* then *) + ltac:(M.monadic ( + let result := + BinOp.r_shift (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "shift" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -492,7 +552,48 @@ Definition bitwise_sar : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "shift" |), + Constant.int 256 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + BinOp.r_shift (| + M.get_name (| globals, "signed_value" |), + M.get_name (| globals, "shift" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "signed_value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/block.v b/CoqOfPython/ethereum/berlin/vm/instructions/block.v index f857b79..b13d40b 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/block.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/block.v @@ -21,23 +21,23 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_BLOCK_HASH : - IsGlobalAlias globals gas.globals "GAS_BLOCK_HASH". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.berlin.vm.__init__. +Axiom ethereum_berlin_vm___init___Evm : + IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Evm". + +Require ethereum.berlin.vm.gas. +Axiom ethereum_berlin_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_BASE". +Axiom ethereum_berlin_vm_gas_GAS_BLOCK_HASH : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_BLOCK_HASH". +Axiom ethereum_berlin_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "charge_gas". + +Require ethereum.berlin.vm.stack. +Axiom ethereum_berlin_vm_stack_pop : + IsGlobalAlias globals ethereum.berlin.vm.stack.globals "pop". +Axiom ethereum_berlin_vm_stack_push : + IsGlobalAlias globals ethereum.berlin.vm.stack.globals "push". Definition block_hash : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -69,6 +69,30 @@ Definition block_hash : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt_e (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + M.get_name (| globals, "block_number" |) + |), + ltac:(M.monadic ( + Compare.gt (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + BinOp.add (| + M.get_name (| globals, "block_number" |), + Constant.int 256 + |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let hash := + Constant.bytes "00" in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let hash := M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/comparison.v b/CoqOfPython/ethereum/berlin/vm/instructions/comparison.v index b8529d8..d7845ab 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/comparison.v @@ -21,21 +21,21 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.berlin.vm.__init__. +Axiom ethereum_berlin_vm___init___Evm : + IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.berlin.vm.gas. +Axiom ethereum_berlin_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_berlin_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "charge_gas". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.berlin.vm.stack. +Axiom ethereum_berlin_vm_stack_pop : + IsGlobalAlias globals ethereum.berlin.vm.stack.globals "pop". +Axiom ethereum_berlin_vm_stack_push : + IsGlobalAlias globals ethereum.berlin.vm.stack.globals "push". Definition less_than : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/control_flow.v b/CoqOfPython/ethereum/berlin/vm/instructions/control_flow.v index d4e4eae..bdc4e97 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/control_flow.v @@ -23,31 +23,31 @@ Axiom ethereum_base_types_U256 : Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require vm.gas. -Axiom vm_gas_GAS_BASE : - IsGlobalAlias globals vm.gas.globals "GAS_BASE". -Axiom vm_gas_GAS_HIGH : - IsGlobalAlias globals vm.gas.globals "GAS_HIGH". -Axiom vm_gas_GAS_JUMPDEST : - IsGlobalAlias globals vm.gas.globals "GAS_JUMPDEST". -Axiom vm_gas_GAS_MID : - IsGlobalAlias globals vm.gas.globals "GAS_MID". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.berlin.vm.gas. +Axiom ethereum_berlin_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_BASE". +Axiom ethereum_berlin_vm_gas_GAS_HIGH : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_HIGH". +Axiom ethereum_berlin_vm_gas_GAS_JUMPDEST : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_JUMPDEST". +Axiom ethereum_berlin_vm_gas_GAS_MID : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_MID". +Axiom ethereum_berlin_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "charge_gas". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.berlin.vm.__init__. +Axiom ethereum_berlin_vm___init___Evm : + IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Evm". -Require exceptions. -Axiom exceptions_InvalidJumpDestError : - IsGlobalAlias globals exceptions.globals "InvalidJumpDestError". +Require ethereum.berlin.vm.exceptions. +Axiom ethereum_berlin_vm_exceptions_InvalidJumpDestError : + IsGlobalAlias globals ethereum.berlin.vm.exceptions.globals "InvalidJumpDestError". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.berlin.vm.stack. +Axiom ethereum_berlin_vm_stack_pop : + IsGlobalAlias globals ethereum.berlin.vm.stack.globals "pop". +Axiom ethereum_berlin_vm_stack_push : + IsGlobalAlias globals ethereum.berlin.vm.stack.globals "push". Definition stop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -109,6 +109,18 @@ Definition jump : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "jump_dest" |), + M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -168,7 +180,35 @@ Definition jumpi : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "conditional_value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let destination := + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "jump_dest" |), + M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let destination := M.get_name (| globals, "jump_dest" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/environment.v b/CoqOfPython/ethereum/berlin/vm/instructions/environment.v index eefcb4f..ba42cac 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/environment.v @@ -35,57 +35,57 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require fork_types. -Axiom fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". - -Require state. -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". - -Require utils.address. -Axiom utils_address_to_address : - IsGlobalAlias globals utils.address.globals "to_address". - -Require vm.memory. -Axiom vm_memory_buffer_read : - IsGlobalAlias globals vm.memory.globals "buffer_read". -Axiom vm_memory_memory_write : - IsGlobalAlias globals vm.memory.globals "memory_write". - -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require exceptions. -Axiom exceptions_OutOfBoundsRead : - IsGlobalAlias globals exceptions.globals "OutOfBoundsRead". - -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_COLD_ACCOUNT_ACCESS : - IsGlobalAlias globals gas.globals "GAS_COLD_ACCOUNT_ACCESS". -Axiom gas_GAS_COPY : - IsGlobalAlias globals gas.globals "GAS_COPY". -Axiom gas_GAS_FAST_STEP : - IsGlobalAlias globals gas.globals "GAS_FAST_STEP". -Axiom gas_GAS_RETURN_DATA_COPY : - IsGlobalAlias globals gas.globals "GAS_RETURN_DATA_COPY". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_GAS_WARM_ACCESS : - IsGlobalAlias globals gas.globals "GAS_WARM_ACCESS". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.berlin.fork_types. +Axiom ethereum_berlin_fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals ethereum.berlin.fork_types.globals "EMPTY_ACCOUNT". + +Require ethereum.berlin.state. +Axiom ethereum_berlin_state_get_account : + IsGlobalAlias globals ethereum.berlin.state.globals "get_account". + +Require ethereum.berlin.utils.address. +Axiom ethereum_berlin_utils_address_to_address : + IsGlobalAlias globals ethereum.berlin.utils.address.globals "to_address". + +Require ethereum.berlin.vm.memory. +Axiom ethereum_berlin_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.berlin.vm.memory.globals "buffer_read". +Axiom ethereum_berlin_vm_memory_memory_write : + IsGlobalAlias globals ethereum.berlin.vm.memory.globals "memory_write". + +Require ethereum.berlin.vm.__init__. +Axiom ethereum_berlin_vm___init___Evm : + IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Evm". + +Require ethereum.berlin.vm.exceptions. +Axiom ethereum_berlin_vm_exceptions_OutOfBoundsRead : + IsGlobalAlias globals ethereum.berlin.vm.exceptions.globals "OutOfBoundsRead". + +Require ethereum.berlin.vm.gas. +Axiom ethereum_berlin_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_BASE". +Axiom ethereum_berlin_vm_gas_GAS_COLD_ACCOUNT_ACCESS : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_COLD_ACCOUNT_ACCESS". +Axiom ethereum_berlin_vm_gas_GAS_COPY : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_COPY". +Axiom ethereum_berlin_vm_gas_GAS_FAST_STEP : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_FAST_STEP". +Axiom ethereum_berlin_vm_gas_GAS_RETURN_DATA_COPY : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_RETURN_DATA_COPY". +Axiom ethereum_berlin_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_berlin_vm_gas_GAS_WARM_ACCESS : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_WARM_ACCESS". +Axiom ethereum_berlin_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_berlin_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "charge_gas". + +Require ethereum.berlin.vm.stack. +Axiom ethereum_berlin_vm_stack_pop : + IsGlobalAlias globals ethereum.berlin.vm.stack.globals "pop". +Axiom ethereum_berlin_vm_stack_push : + IsGlobalAlias globals ethereum.berlin.vm.stack.globals "push". Definition address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -156,6 +156,25 @@ Definition balance : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -789,6 +808,25 @@ Definition extcodesize : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -926,6 +964,31 @@ Definition extcodecopy : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_WARM_ACCESS" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1162,7 +1225,10 @@ Definition returndatacopy : Value.t -> Value.t -> M := |) |) in let value := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |) |) in + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.slice (| M.get_name (| globals, "return_data_start_position" |), BinOp.add (| + M.get_name (| globals, "return_data_start_position" |), + M.get_name (| globals, "size" |) + |) |) |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -1204,6 +1270,25 @@ Definition extcodehash : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1231,6 +1316,25 @@ Definition extcodehash : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "account" |), + M.get_name (| globals, "EMPTY_ACCOUNT" |) + |), + (* then *) + ltac:(M.monadic ( + let codehash := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let codehash := M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/keccak.v b/CoqOfPython/ethereum/berlin/vm/instructions/keccak.v index 2c4b10e..364d315 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/keccak.v @@ -31,29 +31,29 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_KECCAK256 : - IsGlobalAlias globals gas.globals "GAS_KECCAK256". -Axiom gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.berlin.vm.__init__. +Axiom ethereum_berlin_vm___init___Evm : + IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Evm". + +Require ethereum.berlin.vm.gas. +Axiom ethereum_berlin_vm_gas_GAS_KECCAK256 : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_KECCAK256". +Axiom ethereum_berlin_vm_gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_KECCAK256_WORD". +Axiom ethereum_berlin_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_berlin_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "charge_gas". + +Require ethereum.berlin.vm.memory. +Axiom ethereum_berlin_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.berlin.vm.memory.globals "memory_read_bytes". + +Require ethereum.berlin.vm.stack. +Axiom ethereum_berlin_vm_stack_pop : + IsGlobalAlias globals ethereum.berlin.vm.stack.globals "pop". +Axiom ethereum_berlin_vm_stack_push : + IsGlobalAlias globals ethereum.berlin.vm.stack.globals "push". Definition keccak : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/log.v b/CoqOfPython/ethereum/berlin/vm/instructions/log.v index e084e59..4f9705b 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/log.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/log.v @@ -29,37 +29,37 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". - -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require exceptions. -Axiom exceptions_WriteInStaticContext : - IsGlobalAlias globals exceptions.globals "WriteInStaticContext". - -Require gas. -Axiom gas_GAS_LOG : - IsGlobalAlias globals gas.globals "GAS_LOG". -Axiom gas_GAS_LOG_DATA : - IsGlobalAlias globals gas.globals "GAS_LOG_DATA". -Axiom gas_GAS_LOG_TOPIC : - IsGlobalAlias globals gas.globals "GAS_LOG_TOPIC". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". +Require ethereum.berlin.blocks. +Axiom ethereum_berlin_blocks_Log : + IsGlobalAlias globals ethereum.berlin.blocks.globals "Log". + +Require ethereum.berlin.vm.__init__. +Axiom ethereum_berlin_vm___init___Evm : + IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Evm". + +Require ethereum.berlin.vm.exceptions. +Axiom ethereum_berlin_vm_exceptions_WriteInStaticContext : + IsGlobalAlias globals ethereum.berlin.vm.exceptions.globals "WriteInStaticContext". + +Require ethereum.berlin.vm.gas. +Axiom ethereum_berlin_vm_gas_GAS_LOG : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_LOG". +Axiom ethereum_berlin_vm_gas_GAS_LOG_DATA : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_LOG_DATA". +Axiom ethereum_berlin_vm_gas_GAS_LOG_TOPIC : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_LOG_TOPIC". +Axiom ethereum_berlin_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_berlin_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "charge_gas". + +Require ethereum.berlin.vm.memory. +Axiom ethereum_berlin_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.berlin.vm.memory.globals "memory_read_bytes". + +Require ethereum.berlin.vm.stack. +Axiom ethereum_berlin_vm_stack_pop : + IsGlobalAlias globals ethereum.berlin.vm.stack.globals "pop". Definition log_n : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/memory.v b/CoqOfPython/ethereum/berlin/vm/instructions/memory.v index 86ba742..9d61e40 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/memory.v @@ -23,31 +23,31 @@ Axiom ethereum_base_types_U256 : Axiom ethereum_base_types_Bytes : IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.berlin.vm.__init__. +Axiom ethereum_berlin_vm___init___Evm : + IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.berlin.vm.gas. +Axiom ethereum_berlin_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_BASE". +Axiom ethereum_berlin_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_berlin_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_berlin_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "charge_gas". -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". -Axiom memory_memory_write : - IsGlobalAlias globals memory.globals "memory_write". +Require ethereum.berlin.vm.memory. +Axiom ethereum_berlin_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.berlin.vm.memory.globals "memory_read_bytes". +Axiom ethereum_berlin_vm_memory_memory_write : + IsGlobalAlias globals ethereum.berlin.vm.memory.globals "memory_write". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.berlin.vm.stack. +Axiom ethereum_berlin_vm_stack_pop : + IsGlobalAlias globals ethereum.berlin.vm.stack.globals "pop". +Axiom ethereum_berlin_vm_stack_push : + IsGlobalAlias globals ethereum.berlin.vm.stack.globals "push". Definition mstore : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/stack.v b/CoqOfPython/ethereum/berlin/vm/instructions/stack.v index 305af15..43211e8 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/stack.v @@ -29,27 +29,27 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". -Axiom __init___stack : - IsGlobalAlias globals __init__.globals "stack". - -Require exceptions. -Axiom exceptions_StackUnderflowError : - IsGlobalAlias globals exceptions.globals "StackUnderflowError". - -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require memory. -Axiom memory_buffer_read : - IsGlobalAlias globals memory.globals "buffer_read". +Require ethereum.berlin.vm.__init__. +Axiom ethereum_berlin_vm___init___Evm : + IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Evm". +Axiom ethereum_berlin_vm___init___stack : + IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "stack". + +Require ethereum.berlin.vm.exceptions. +Axiom ethereum_berlin_vm_exceptions_StackUnderflowError : + IsGlobalAlias globals ethereum.berlin.vm.exceptions.globals "StackUnderflowError". + +Require ethereum.berlin.vm.gas. +Axiom ethereum_berlin_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_BASE". +Axiom ethereum_berlin_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_berlin_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "charge_gas". + +Require ethereum.berlin.vm.memory. +Axiom ethereum_berlin_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.berlin.vm.memory.globals "buffer_read". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/storage.v b/CoqOfPython/ethereum/berlin/vm/instructions/storage.v index b3c4045..1245525 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/storage.v @@ -25,45 +25,45 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require state. -Axiom state_get_storage : - IsGlobalAlias globals state.globals "get_storage". -Axiom state_get_storage_original : - IsGlobalAlias globals state.globals "get_storage_original". -Axiom state_set_storage : - IsGlobalAlias globals state.globals "set_storage". - -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require exceptions. -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". -Axiom exceptions_WriteInStaticContext : - IsGlobalAlias globals exceptions.globals "WriteInStaticContext". - -Require gas. -Axiom gas_GAS_CALL_STIPEND : - IsGlobalAlias globals gas.globals "GAS_CALL_STIPEND". -Axiom gas_GAS_COLD_SLOAD : - IsGlobalAlias globals gas.globals "GAS_COLD_SLOAD". -Axiom gas_GAS_STORAGE_CLEAR_REFUND : - IsGlobalAlias globals gas.globals "GAS_STORAGE_CLEAR_REFUND". -Axiom gas_GAS_STORAGE_SET : - IsGlobalAlias globals gas.globals "GAS_STORAGE_SET". -Axiom gas_GAS_STORAGE_UPDATE : - IsGlobalAlias globals gas.globals "GAS_STORAGE_UPDATE". -Axiom gas_GAS_WARM_ACCESS : - IsGlobalAlias globals gas.globals "GAS_WARM_ACCESS". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.berlin.state. +Axiom ethereum_berlin_state_get_storage : + IsGlobalAlias globals ethereum.berlin.state.globals "get_storage". +Axiom ethereum_berlin_state_get_storage_original : + IsGlobalAlias globals ethereum.berlin.state.globals "get_storage_original". +Axiom ethereum_berlin_state_set_storage : + IsGlobalAlias globals ethereum.berlin.state.globals "set_storage". + +Require ethereum.berlin.vm.__init__. +Axiom ethereum_berlin_vm___init___Evm : + IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Evm". + +Require ethereum.berlin.vm.exceptions. +Axiom ethereum_berlin_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.berlin.vm.exceptions.globals "OutOfGasError". +Axiom ethereum_berlin_vm_exceptions_WriteInStaticContext : + IsGlobalAlias globals ethereum.berlin.vm.exceptions.globals "WriteInStaticContext". + +Require ethereum.berlin.vm.gas. +Axiom ethereum_berlin_vm_gas_GAS_CALL_STIPEND : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_CALL_STIPEND". +Axiom ethereum_berlin_vm_gas_GAS_COLD_SLOAD : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_COLD_SLOAD". +Axiom ethereum_berlin_vm_gas_GAS_STORAGE_CLEAR_REFUND : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_STORAGE_CLEAR_REFUND". +Axiom ethereum_berlin_vm_gas_GAS_STORAGE_SET : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_STORAGE_SET". +Axiom ethereum_berlin_vm_gas_GAS_STORAGE_UPDATE : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_STORAGE_UPDATE". +Axiom ethereum_berlin_vm_gas_GAS_WARM_ACCESS : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_WARM_ACCESS". +Axiom ethereum_berlin_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "charge_gas". + +Require ethereum.berlin.vm.stack. +Axiom ethereum_berlin_vm_stack_pop : + IsGlobalAlias globals ethereum.berlin.vm.stack.globals "pop". +Axiom ethereum_berlin_vm_stack_push : + IsGlobalAlias globals ethereum.berlin.vm.stack.globals "push". Definition sload : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -91,6 +91,25 @@ Definition sload : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], + M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "add" |), make_list [ @@ -205,15 +224,225 @@ Definition sstore : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], + M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "add" |), + make_list [ + make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ] + ], + make_dict [] + |) in + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_COLD_SLOAD" |) + M.get_name (| globals, "GAS_COLD_SLOAD" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_name (| globals, "original_value" |), + M.get_name (| globals, "current_value" |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "current_value" |), + M.get_name (| globals, "new_value" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "original_value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_STORAGE_SET" |) + M.get_name (| globals, "GAS_STORAGE_SET" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let gas_cost := BinOp.add + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_UPDATE" |), + M.get_name (| globals, "GAS_COLD_SLOAD" |) + |) + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_UPDATE" |), + M.get_name (| globals, "GAS_COLD_SLOAD" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let gas_cost := BinOp.add M.get_name (| globals, "GAS_WARM_ACCESS" |) M.get_name (| globals, "GAS_WARM_ACCESS" |) in M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| + M.get_name (| globals, "current_value" |), + M.get_name (| globals, "new_value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "original_value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "current_value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "new_value" |), + Constant.int 0 + |) + )) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "original_value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "current_value" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.sub, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "original_value" |), + M.get_name (| globals, "new_value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "original_value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_SET" |), + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.sub (| + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_UPDATE" |), + M.get_name (| globals, "GAS_COLD_SLOAD" |) + |), + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/system.v b/CoqOfPython/ethereum/berlin/vm/instructions/system.v index b5cf558..36ad346 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/system.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/system.v @@ -33,89 +33,89 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.berlin.fork_types. +Axiom ethereum_berlin_fork_types_Address : + IsGlobalAlias globals ethereum.berlin.fork_types.globals "Address". -Require state. -Axiom state_account_exists_and_is_empty : - IsGlobalAlias globals state.globals "account_exists_and_is_empty". -Axiom state_account_has_code_or_nonce : - IsGlobalAlias globals state.globals "account_has_code_or_nonce". -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". -Axiom state_increment_nonce : - IsGlobalAlias globals state.globals "increment_nonce". -Axiom state_is_account_alive : - IsGlobalAlias globals state.globals "is_account_alive". -Axiom state_set_account_balance : - IsGlobalAlias globals state.globals "set_account_balance". +Require ethereum.berlin.state. +Axiom ethereum_berlin_state_account_exists_and_is_empty : + IsGlobalAlias globals ethereum.berlin.state.globals "account_exists_and_is_empty". +Axiom ethereum_berlin_state_account_has_code_or_nonce : + IsGlobalAlias globals ethereum.berlin.state.globals "account_has_code_or_nonce". +Axiom ethereum_berlin_state_get_account : + IsGlobalAlias globals ethereum.berlin.state.globals "get_account". +Axiom ethereum_berlin_state_increment_nonce : + IsGlobalAlias globals ethereum.berlin.state.globals "increment_nonce". +Axiom ethereum_berlin_state_is_account_alive : + IsGlobalAlias globals ethereum.berlin.state.globals "is_account_alive". +Axiom ethereum_berlin_state_set_account_balance : + IsGlobalAlias globals ethereum.berlin.state.globals "set_account_balance". -Require utils.address. -Axiom utils_address_compute_contract_address : - IsGlobalAlias globals utils.address.globals "compute_contract_address". -Axiom utils_address_compute_create2_contract_address : - IsGlobalAlias globals utils.address.globals "compute_create2_contract_address". -Axiom utils_address_to_address : - IsGlobalAlias globals utils.address.globals "to_address". +Require ethereum.berlin.utils.address. +Axiom ethereum_berlin_utils_address_compute_contract_address : + IsGlobalAlias globals ethereum.berlin.utils.address.globals "compute_contract_address". +Axiom ethereum_berlin_utils_address_compute_create2_contract_address : + IsGlobalAlias globals ethereum.berlin.utils.address.globals "compute_create2_contract_address". +Axiom ethereum_berlin_utils_address_to_address : + IsGlobalAlias globals ethereum.berlin.utils.address.globals "to_address". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". -Axiom __init___Message : - IsGlobalAlias globals __init__.globals "Message". -Axiom __init___incorporate_child_on_error : - IsGlobalAlias globals __init__.globals "incorporate_child_on_error". -Axiom __init___incorporate_child_on_success : - IsGlobalAlias globals __init__.globals "incorporate_child_on_success". +Require ethereum.berlin.vm.__init__. +Axiom ethereum_berlin_vm___init___Evm : + IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Evm". +Axiom ethereum_berlin_vm___init___Message : + IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Message". +Axiom ethereum_berlin_vm___init___incorporate_child_on_error : + IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "incorporate_child_on_error". +Axiom ethereum_berlin_vm___init___incorporate_child_on_success : + IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "incorporate_child_on_success". -Require exceptions. -Axiom exceptions_Revert : - IsGlobalAlias globals exceptions.globals "Revert". -Axiom exceptions_WriteInStaticContext : - IsGlobalAlias globals exceptions.globals "WriteInStaticContext". +Require ethereum.berlin.vm.exceptions. +Axiom ethereum_berlin_vm_exceptions_Revert : + IsGlobalAlias globals ethereum.berlin.vm.exceptions.globals "Revert". +Axiom ethereum_berlin_vm_exceptions_WriteInStaticContext : + IsGlobalAlias globals ethereum.berlin.vm.exceptions.globals "WriteInStaticContext". -Require gas. -Axiom gas_GAS_CALL_VALUE : - IsGlobalAlias globals gas.globals "GAS_CALL_VALUE". -Axiom gas_GAS_COLD_ACCOUNT_ACCESS : - IsGlobalAlias globals gas.globals "GAS_COLD_ACCOUNT_ACCESS". -Axiom gas_GAS_CREATE : - IsGlobalAlias globals gas.globals "GAS_CREATE". -Axiom gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". -Axiom gas_GAS_NEW_ACCOUNT : - IsGlobalAlias globals gas.globals "GAS_NEW_ACCOUNT". -Axiom gas_GAS_SELF_DESTRUCT : - IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT". -Axiom gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : - IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". -Axiom gas_GAS_WARM_ACCESS : - IsGlobalAlias globals gas.globals "GAS_WARM_ACCESS". -Axiom gas_GAS_ZERO : - IsGlobalAlias globals gas.globals "GAS_ZERO". -Axiom gas_REFUND_SELF_DESTRUCT : - IsGlobalAlias globals gas.globals "REFUND_SELF_DESTRUCT". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_calculate_message_call_gas : - IsGlobalAlias globals gas.globals "calculate_message_call_gas". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". -Axiom gas_max_message_call_gas : - IsGlobalAlias globals gas.globals "max_message_call_gas". +Require ethereum.berlin.vm.gas. +Axiom ethereum_berlin_vm_gas_GAS_CALL_VALUE : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_CALL_VALUE". +Axiom ethereum_berlin_vm_gas_GAS_COLD_ACCOUNT_ACCESS : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_COLD_ACCOUNT_ACCESS". +Axiom ethereum_berlin_vm_gas_GAS_CREATE : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_CREATE". +Axiom ethereum_berlin_vm_gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_KECCAK256_WORD". +Axiom ethereum_berlin_vm_gas_GAS_NEW_ACCOUNT : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_NEW_ACCOUNT". +Axiom ethereum_berlin_vm_gas_GAS_SELF_DESTRUCT : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_SELF_DESTRUCT". +Axiom ethereum_berlin_vm_gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". +Axiom ethereum_berlin_vm_gas_GAS_WARM_ACCESS : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_WARM_ACCESS". +Axiom ethereum_berlin_vm_gas_GAS_ZERO : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_ZERO". +Axiom ethereum_berlin_vm_gas_REFUND_SELF_DESTRUCT : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "REFUND_SELF_DESTRUCT". +Axiom ethereum_berlin_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_berlin_vm_gas_calculate_message_call_gas : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "calculate_message_call_gas". +Axiom ethereum_berlin_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "charge_gas". +Axiom ethereum_berlin_vm_gas_max_message_call_gas : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "max_message_call_gas". -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". -Axiom memory_memory_write : - IsGlobalAlias globals memory.globals "memory_write". +Require ethereum.berlin.vm.memory. +Axiom ethereum_berlin_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.berlin.vm.memory.globals "memory_read_bytes". +Axiom ethereum_berlin_vm_memory_memory_write : + IsGlobalAlias globals ethereum.berlin.vm.memory.globals "memory_write". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.berlin.vm.stack. +Axiom ethereum_berlin_vm_stack_pop : + IsGlobalAlias globals ethereum.berlin.vm.stack.globals "pop". +Axiom ethereum_berlin_vm_stack_push : + IsGlobalAlias globals ethereum.berlin.vm.stack.globals "push". Definition generic_create : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -174,9 +174,113 @@ Definition generic_create : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt (| + M.get_field (| M.get_name (| globals, "sender" |), "balance" |), + M.get_name (| globals, "endowment" |) + |), + ltac:(M.monadic ( + BoolOp.or (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "sender" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.sub (| + BinOp.pow (| + Constant.int 2, + Constant.int 64 + |), + Constant.int 1 + |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.gt (| + BinOp.add (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "depth" |), + Constant.int 1 + |), + M.get_name (| globals, "STACK_DEPTH_LIMIT" |) + |) + )) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "create_message_gas" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "contract_address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let call_data := @@ -213,6 +317,40 @@ Definition generic_create : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "child_evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_error" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "incorporate_child_on_success" |), make_list [ @@ -569,6 +707,42 @@ Definition generic_call : Value.t -> Value.t -> M := Constant.bytes "" |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + BinOp.add (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "depth" |), + Constant.int 1 + |), + M.get_name (| globals, "STACK_DEPTH_LIMIT" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "gas" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let call_data := @@ -606,6 +780,40 @@ Definition generic_call : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "child_evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_error" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "incorporate_child_on_success" |), make_list [ @@ -660,7 +868,7 @@ Definition generic_call : Value.t -> Value.t -> M := make_list [ M.get_field (| M.get_name (| globals, "evm" |), "memory" |); M.get_name (| globals, "memory_output_start_position" |); - M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), Constant.None_:M.get_name (| globals, "actual_output_size" |) |) + M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), M.slice (| Constant.None_, M.get_name (| globals, "actual_output_size" |) |) |) ], make_dict [] |) in @@ -758,6 +966,19 @@ Definition call : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "to" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let access_gas_cost := + M.get_name (| globals, "GAS_WARM_ACCESS" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -770,49 +991,57 @@ Definition call : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in let create_gas_cost := - (* if *) -M.if_then_else (| - BoolOp.or (| - M.call (| - M.get_name (| globals, "is_account_alive" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); - M.get_name (| globals, "to" |) - ], - make_dict [] - |), - ltac:(M.monadic ( - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |) - )) - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + BoolOp.or (| + M.call (| + M.get_name (| globals, "is_account_alive" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "to" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "GAS_NEW_ACCOUNT" |) + )) |) in let transfer_gas_cost := - (* if *) -M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "GAS_CALL_VALUE" |) + )) |) in let message_call_gas := M.call (| M.get_name (| globals, "calculate_message_call_gas" |), @@ -888,6 +1117,40 @@ M.call (| make_dict [] |), "balance" |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "sender_balance" |), + M.get_name (| globals, "value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "generic_call" |), make_list [ @@ -1009,6 +1272,19 @@ Definition callcode : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "code_address" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let access_gas_cost := + M.get_name (| globals, "GAS_WARM_ACCESS" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1021,21 +1297,25 @@ Definition callcode : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in let transfer_gas_cost := - (* if *) -M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "GAS_CALL_VALUE" |) + )) |) in let message_call_gas := M.call (| M.get_name (| globals, "calculate_message_call_gas" |), @@ -1086,6 +1366,40 @@ M.call (| make_dict [] |), "balance" |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "sender_balance" |), + M.get_name (| globals, "value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "generic_call" |), make_list [ @@ -1141,9 +1455,63 @@ Definition selfdestruct : Value.t -> Value.t -> M := let gas_cost := M.get_name (| globals, "GAS_SELF_DESTRUCT" |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "beneficiary" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |) in + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + UnOp.not (| M.call (| + M.get_name (| globals, "is_account_alive" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) + M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let originator := @@ -1167,6 +1535,22 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in EndWhile. let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "originator" |), + M.get_name (| globals, "refunded_accounts" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.get_name (| globals, "REFUND_SELF_DESTRUCT" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -1238,6 +1622,28 @@ Definition selfdestruct : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -1331,6 +1737,19 @@ Definition delegatecall : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "code_address" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let access_gas_cost := + M.get_name (| globals, "GAS_WARM_ACCESS" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1494,6 +1913,19 @@ Definition staticcall : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "to" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let access_gas_cost := + M.get_name (| globals, "GAS_WARM_ACCESS" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1653,6 +2085,6 @@ Definition revert : Value.t -> Value.t -> M := make_dict [] |) |) in - let _ := M.raise (| Some(M.get_name (| globals, "Revert" |)) + let _ := M.raise (| Some(M.get_name (| globals, "Revert" |)) |) in let _ := M.pass (| |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/vm/interpreter.v b/CoqOfPython/ethereum/berlin/vm/interpreter.v index 2869f71..0989fe3 100644 --- a/CoqOfPython/ethereum/berlin/vm/interpreter.v +++ b/CoqOfPython/ethereum/berlin/vm/interpreter.v @@ -61,81 +61,81 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". - -Require state. -Axiom state_account_exists_and_is_empty : - IsGlobalAlias globals state.globals "account_exists_and_is_empty". -Axiom state_account_has_code_or_nonce : - IsGlobalAlias globals state.globals "account_has_code_or_nonce". -Axiom state_begin_transaction : - IsGlobalAlias globals state.globals "begin_transaction". -Axiom state_commit_transaction : - IsGlobalAlias globals state.globals "commit_transaction". -Axiom state_destroy_storage : - IsGlobalAlias globals state.globals "destroy_storage". -Axiom state_increment_nonce : - IsGlobalAlias globals state.globals "increment_nonce". -Axiom state_mark_account_created : - IsGlobalAlias globals state.globals "mark_account_created". -Axiom state_move_ether : - IsGlobalAlias globals state.globals "move_ether". -Axiom state_rollback_transaction : - IsGlobalAlias globals state.globals "rollback_transaction". -Axiom state_set_code : - IsGlobalAlias globals state.globals "set_code". -Axiom state_touch_account : - IsGlobalAlias globals state.globals "touch_account". - -Require vm. -Axiom vm_Message : - IsGlobalAlias globals vm.globals "Message". - -Require vm.gas. -Axiom vm_gas_GAS_CODE_DEPOSIT : - IsGlobalAlias globals vm.gas.globals "GAS_CODE_DEPOSIT". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". - -Require vm.precompiled_contracts.mapping. -Axiom vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : - IsGlobalAlias globals vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". - -Require __init__. -Axiom __init___Environment : - IsGlobalAlias globals __init__.globals "Environment". -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require exceptions. -Axiom exceptions_AddressCollision : - IsGlobalAlias globals exceptions.globals "AddressCollision". -Axiom exceptions_ExceptionalHalt : - IsGlobalAlias globals exceptions.globals "ExceptionalHalt". -Axiom exceptions_InvalidOpcode : - IsGlobalAlias globals exceptions.globals "InvalidOpcode". -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". -Axiom exceptions_Revert : - IsGlobalAlias globals exceptions.globals "Revert". -Axiom exceptions_StackDepthLimitError : - IsGlobalAlias globals exceptions.globals "StackDepthLimitError". - -Require instructions. -Axiom instructions_Ops : - IsGlobalAlias globals instructions.globals "Ops". -Axiom instructions_op_implementation : - IsGlobalAlias globals instructions.globals "op_implementation". - -Require runtime. -Axiom runtime_get_valid_jump_destinations : - IsGlobalAlias globals runtime.globals "get_valid_jump_destinations". +Require ethereum.berlin.blocks. +Axiom ethereum_berlin_blocks_Log : + IsGlobalAlias globals ethereum.berlin.blocks.globals "Log". + +Require ethereum.berlin.fork_types. +Axiom ethereum_berlin_fork_types_Address : + IsGlobalAlias globals ethereum.berlin.fork_types.globals "Address". + +Require ethereum.berlin.state. +Axiom ethereum_berlin_state_account_exists_and_is_empty : + IsGlobalAlias globals ethereum.berlin.state.globals "account_exists_and_is_empty". +Axiom ethereum_berlin_state_account_has_code_or_nonce : + IsGlobalAlias globals ethereum.berlin.state.globals "account_has_code_or_nonce". +Axiom ethereum_berlin_state_begin_transaction : + IsGlobalAlias globals ethereum.berlin.state.globals "begin_transaction". +Axiom ethereum_berlin_state_commit_transaction : + IsGlobalAlias globals ethereum.berlin.state.globals "commit_transaction". +Axiom ethereum_berlin_state_destroy_storage : + IsGlobalAlias globals ethereum.berlin.state.globals "destroy_storage". +Axiom ethereum_berlin_state_increment_nonce : + IsGlobalAlias globals ethereum.berlin.state.globals "increment_nonce". +Axiom ethereum_berlin_state_mark_account_created : + IsGlobalAlias globals ethereum.berlin.state.globals "mark_account_created". +Axiom ethereum_berlin_state_move_ether : + IsGlobalAlias globals ethereum.berlin.state.globals "move_ether". +Axiom ethereum_berlin_state_rollback_transaction : + IsGlobalAlias globals ethereum.berlin.state.globals "rollback_transaction". +Axiom ethereum_berlin_state_set_code : + IsGlobalAlias globals ethereum.berlin.state.globals "set_code". +Axiom ethereum_berlin_state_touch_account : + IsGlobalAlias globals ethereum.berlin.state.globals "touch_account". + +Require ethereum.berlin.vm.__init__. +Axiom ethereum_berlin_vm___init___Message : + IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Message". + +Require ethereum.berlin.vm.gas. +Axiom ethereum_berlin_vm_gas_GAS_CODE_DEPOSIT : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_CODE_DEPOSIT". +Axiom ethereum_berlin_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "charge_gas". + +Require ethereum.berlin.vm.precompiled_contracts.mapping. +Axiom ethereum_berlin_vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : + IsGlobalAlias globals ethereum.berlin.vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". + +Require ethereum.berlin.vm.__init__. +Axiom ethereum_berlin_vm___init___Environment : + IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Environment". +Axiom ethereum_berlin_vm___init___Evm : + IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Evm". + +Require ethereum.berlin.vm.exceptions. +Axiom ethereum_berlin_vm_exceptions_AddressCollision : + IsGlobalAlias globals ethereum.berlin.vm.exceptions.globals "AddressCollision". +Axiom ethereum_berlin_vm_exceptions_ExceptionalHalt : + IsGlobalAlias globals ethereum.berlin.vm.exceptions.globals "ExceptionalHalt". +Axiom ethereum_berlin_vm_exceptions_InvalidOpcode : + IsGlobalAlias globals ethereum.berlin.vm.exceptions.globals "InvalidOpcode". +Axiom ethereum_berlin_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.berlin.vm.exceptions.globals "OutOfGasError". +Axiom ethereum_berlin_vm_exceptions_Revert : + IsGlobalAlias globals ethereum.berlin.vm.exceptions.globals "Revert". +Axiom ethereum_berlin_vm_exceptions_StackDepthLimitError : + IsGlobalAlias globals ethereum.berlin.vm.exceptions.globals "StackDepthLimitError". + +Require ethereum.berlin.vm.instructions.__init__. +Axiom ethereum_berlin_vm_instructions___init___Ops : + IsGlobalAlias globals ethereum.berlin.vm.instructions.__init__.globals "Ops". +Axiom ethereum_berlin_vm_instructions___init___op_implementation : + IsGlobalAlias globals ethereum.berlin.vm.instructions.__init__.globals "op_implementation". + +Require ethereum.berlin.vm.runtime. +Axiom ethereum_berlin_vm_runtime_get_valid_jump_destinations : + IsGlobalAlias globals ethereum.berlin.vm.runtime.globals "get_valid_jump_destinations". Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -182,6 +182,94 @@ Definition process_message_call : Value.t -> Value.t -> M := Output of the message call " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "message" |), "target" |), + M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) + |), + (* then *) + ltac:(M.monadic ( + let is_collision := + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_name (| globals, "is_collision" |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallOutput" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "tuple" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "AddressCollision" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let evm := + M.call (| + M.get_name (| globals, "process_create_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let evm := M.call (| M.get_name (| globals, "process_message" |), @@ -192,11 +280,74 @@ Definition process_message_call : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_field (| M.get_name (| globals, "message" |), "target" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_field (| M.get_name (| globals, "message" |), "target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( +(* At stmt: unsupported node type: AnnAssign *) + let accounts_to_delete := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let touched_accounts := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let refund_counter := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let logs := M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in let accounts_to_delete := @@ -240,6 +391,7 @@ Definition process_message_call : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). Definition process_create_message : Value.t -> Value.t -> M := @@ -301,6 +453,28 @@ Definition process_create_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), + (* then *) + ltac:(M.monadic ( + let contract_code := + M.get_field (| M.get_name (| globals, "evm" |), "output" |) in + let contract_code_gas := + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "contract_code" |) + ], + make_dict [] + |), + M.get_name (| globals, "GAS_CODE_DEPOSIT" |) + |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "rollback_transaction" |), make_list [ @@ -312,6 +486,7 @@ Definition process_create_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) + |) in M.pure Constant.None_)). Definition process_message : Value.t -> Value.t -> M := @@ -333,6 +508,24 @@ Definition process_message : Value.t -> Value.t -> M := Items containing execution specific objects " in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_field (| M.get_name (| globals, "message" |), "depth" |), + M.get_name (| globals, "STACK_DEPTH_LIMIT" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "StackDepthLimitError" |), + make_list [ + Constant.str "Stack depth limit reached" + ], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -351,6 +544,32 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + M.get_field (| M.get_name (| globals, "message" |), "should_transfer_value" |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "message" |), "value" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "move_ether" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "caller" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |); + M.get_field (| M.get_name (| globals, "message" |), "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let evm := @@ -363,6 +582,21 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "rollback_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "commit_transaction" |), make_list [ @@ -374,6 +608,7 @@ Definition process_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) + |) in M.pure Constant.None_)). Definition execute_code : Value.t -> Value.t -> M := @@ -413,4 +648,5 @@ Definition execute_code : Value.t -> Value.t -> M := (* At stmt: unsupported node type: Try *) let _ := M.return_ (| M.get_name (| globals, "evm" |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/vm/memory.v b/CoqOfPython/ethereum/berlin/vm/memory.v index 4b107fd..08d2290 100644 --- a/CoqOfPython/ethereum/berlin/vm/memory.v +++ b/CoqOfPython/ethereum/berlin/vm/memory.v @@ -21,13 +21,13 @@ Require ethereum.utils.byte. Axiom ethereum_utils_byte_right_pad_zero_bytes : IsGlobalAlias globals ethereum.utils.byte.globals "right_pad_zero_bytes". -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". Definition memory_write : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,7 +45,22 @@ Definition memory_write : Value.t -> Value.t -> M := Data to write to memory. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |), + M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) |) |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_)). @@ -71,7 +86,23 @@ Definition memory_read_bytes : Value.t -> Value.t -> M := Data read from memory. " in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |) + M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |) |) + |) in M.pure Constant.None_)). Definition buffer_read : Value.t -> Value.t -> M := @@ -98,9 +129,25 @@ Definition buffer_read : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "right_pad_zero_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |) |); + M.get_subscript (| M.get_name (| globals, "buffer" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |) |); M.get_name (| globals, "size" |) ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/__init__.v index ca49311..5d1b58e 100644 --- a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/__init__.v +++ b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/__init__.v @@ -18,9 +18,9 @@ Addresses of precompiled contracts and mappings to their implementations. ". -Require utils.hexadecimal. -Axiom utils_hexadecimal_hex_to_address : - IsGlobalAlias globals utils.hexadecimal.globals "hex_to_address". +Require ethereum.berlin.utils.hexadecimal. +Axiom ethereum_berlin_utils_hexadecimal_hex_to_address : + IsGlobalAlias globals ethereum.berlin.utils.hexadecimal.globals "hex_to_address". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS"; Constant.str "MODEXP_ADDRESS"; Constant.str "ALT_BN128_ADD_ADDRESS"; Constant.str "ALT_BN128_MUL_ADDRESS"; Constant.str "ALT_BN128_PAIRING_CHECK_ADDRESS"; Constant.str "BLAKE2F_ADDRESS" ] diff --git a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/alt_bn128.v index abe4238..96fbd02 100644 --- a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/alt_bn128.v +++ b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/alt_bn128.v @@ -45,21 +45,21 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.berlin.vm.__init__. +Axiom ethereum_berlin_vm___init___Evm : + IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.berlin.vm.gas. +Axiom ethereum_berlin_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "charge_gas". -Require vm.memory. -Axiom vm_memory_buffer_read : - IsGlobalAlias globals vm.memory.globals "buffer_read". +Require ethereum.berlin.vm.memory. +Axiom ethereum_berlin_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.berlin.vm.memory.globals "buffer_read". -Require exceptions. -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". +Require ethereum.berlin.vm.exceptions. +Axiom ethereum_berlin_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.berlin.vm.exceptions.globals "OutOfGasError". Definition alt_bn128_add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -210,6 +210,18 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) in For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ] do let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -353,6 +365,18 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) in For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ] do let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -425,6 +449,27 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| + BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 192 + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let result := @@ -464,7 +509,7 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "data" |), BinOp.add (| + M.get_subscript (| M.get_name (| globals, "data" |), M.slice (| BinOp.add (| BinOp.mult (| M.get_name (| globals, "i" |), Constant.int 192 @@ -473,11 +518,35 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := Constant.int 32, M.get_name (| globals, "j" |) |) - |) |) + |), BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "j" |), + Constant.int 1 + |) + |) + |) |) |) ], make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -538,10 +607,80 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "p" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "q" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let result := + BinOp.mult (| + M.get_name (| globals, "result" |), + M.call (| + M.get_name (| globals, "pairing" |), + make_list [ + M.get_name (| globals, "q" |); + M.get_name (| globals, "p" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "result" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| diff --git a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/blake2f.v b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/blake2f.v index 1647d48..37bb13c 100644 --- a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/blake2f.v +++ b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/blake2f.v @@ -25,19 +25,19 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.berlin.vm.__init__. +Axiom ethereum_berlin_vm___init___Evm : + IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_BLAKE2_PER_ROUND : - IsGlobalAlias globals vm.gas.globals "GAS_BLAKE2_PER_ROUND". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.berlin.vm.gas. +Axiom ethereum_berlin_vm_gas_GAS_BLAKE2_PER_ROUND : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_BLAKE2_PER_ROUND". +Axiom ethereum_berlin_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "charge_gas". -Require exceptions. -Axiom exceptions_InvalidParameter : - IsGlobalAlias globals exceptions.globals "InvalidParameter". +Require ethereum.berlin.vm.exceptions. +Axiom ethereum_berlin_vm_exceptions_InvalidParameter : + IsGlobalAlias globals ethereum.berlin.vm.exceptions.globals "InvalidParameter". Definition blake2f : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/ecrecover.v index 0cbcf16..29ece73 100644 --- a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/ecrecover.v @@ -37,19 +37,19 @@ Require ethereum.utils.byte. Axiom ethereum_utils_byte_left_pad_zero_bytes : IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.berlin.vm.__init__. +Axiom ethereum_berlin_vm___init___Evm : + IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_ECRECOVER : - IsGlobalAlias globals vm.gas.globals "GAS_ECRECOVER". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.berlin.vm.gas. +Axiom ethereum_berlin_vm_gas_GAS_ECRECOVER : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_ECRECOVER". +Axiom ethereum_berlin_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "charge_gas". -Require vm.memory. -Axiom vm_memory_buffer_read : - IsGlobalAlias globals vm.memory.globals "buffer_read". +Require ethereum.berlin.vm.memory. +Axiom ethereum_berlin_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.berlin.vm.memory.globals "buffer_read". Definition ecrecover : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -188,12 +188,78 @@ Definition ecrecover : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "v" |), + Constant.int 27 + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "v" |), + Constant.int 28 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + Constant.int 0, + M.get_name (| globals, "r" |) + |), + ltac:(M.monadic ( + Compare.gt_e (| + M.get_name (| globals, "r" |), + M.get_name (| globals, "SECP256K1N" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + Constant.int 0, + M.get_name (| globals, "s" |) + |), + ltac:(M.monadic ( + Compare.gt_e (| + M.get_name (| globals, "s" |), + M.get_name (| globals, "SECP256K1N" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: Try *) @@ -204,7 +270,7 @@ Definition ecrecover : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12 |) in + |), M.slice (| Constant.int 12, Constant.int 32 |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/identity.v index fa96704..fec33fd 100644 --- a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/identity.v +++ b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/identity.v @@ -25,17 +25,17 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.berlin.vm.__init__. +Axiom ethereum_berlin_vm___init___Evm : + IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_IDENTITY : - IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY". -Axiom vm_gas_GAS_IDENTITY_WORD : - IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY_WORD". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.berlin.vm.gas. +Axiom ethereum_berlin_vm_gas_GAS_IDENTITY : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_IDENTITY". +Axiom ethereum_berlin_vm_gas_GAS_IDENTITY_WORD : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_IDENTITY_WORD". +Axiom ethereum_berlin_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "charge_gas". Definition identity : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/mapping.v index 8a2e2eb..eb0586d 100644 --- a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/mapping.v +++ b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/mapping.v @@ -23,60 +23,60 @@ Axiom typing_Callable : Axiom typing_Dict : IsGlobalAlias globals typing.globals "Dict". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". - -Require __init__. -Axiom __init___ALT_BN128_ADD_ADDRESS : - IsGlobalAlias globals __init__.globals "ALT_BN128_ADD_ADDRESS". -Axiom __init___ALT_BN128_MUL_ADDRESS : - IsGlobalAlias globals __init__.globals "ALT_BN128_MUL_ADDRESS". -Axiom __init___ALT_BN128_PAIRING_CHECK_ADDRESS : - IsGlobalAlias globals __init__.globals "ALT_BN128_PAIRING_CHECK_ADDRESS". -Axiom __init___BLAKE2F_ADDRESS : - IsGlobalAlias globals __init__.globals "BLAKE2F_ADDRESS". -Axiom __init___ECRECOVER_ADDRESS : - IsGlobalAlias globals __init__.globals "ECRECOVER_ADDRESS". -Axiom __init___IDENTITY_ADDRESS : - IsGlobalAlias globals __init__.globals "IDENTITY_ADDRESS". -Axiom __init___MODEXP_ADDRESS : - IsGlobalAlias globals __init__.globals "MODEXP_ADDRESS". -Axiom __init___RIPEMD160_ADDRESS : - IsGlobalAlias globals __init__.globals "RIPEMD160_ADDRESS". -Axiom __init___SHA256_ADDRESS : - IsGlobalAlias globals __init__.globals "SHA256_ADDRESS". - -Require alt_bn128. -Axiom alt_bn128_alt_bn128_add : - IsGlobalAlias globals alt_bn128.globals "alt_bn128_add". -Axiom alt_bn128_alt_bn128_mul : - IsGlobalAlias globals alt_bn128.globals "alt_bn128_mul". -Axiom alt_bn128_alt_bn128_pairing_check : - IsGlobalAlias globals alt_bn128.globals "alt_bn128_pairing_check". - -Require blake2f. -Axiom blake2f_blake2f : - IsGlobalAlias globals blake2f.globals "blake2f". - -Require ecrecover. -Axiom ecrecover_ecrecover : - IsGlobalAlias globals ecrecover.globals "ecrecover". - -Require identity. -Axiom identity_identity : - IsGlobalAlias globals identity.globals "identity". - -Require modexp. -Axiom modexp_modexp : - IsGlobalAlias globals modexp.globals "modexp". - -Require ripemd160. -Axiom ripemd160_ripemd160 : - IsGlobalAlias globals ripemd160.globals "ripemd160". - -Require sha256. -Axiom sha256_sha256 : - IsGlobalAlias globals sha256.globals "sha256". +Require ethereum.berlin.fork_types. +Axiom ethereum_berlin_fork_types_Address : + IsGlobalAlias globals ethereum.berlin.fork_types.globals "Address". + +Require ethereum.berlin.vm.precompiled_contracts.__init__. +Axiom ethereum_berlin_vm_precompiled_contracts___init___ALT_BN128_ADD_ADDRESS : + IsGlobalAlias globals ethereum.berlin.vm.precompiled_contracts.__init__.globals "ALT_BN128_ADD_ADDRESS". +Axiom ethereum_berlin_vm_precompiled_contracts___init___ALT_BN128_MUL_ADDRESS : + IsGlobalAlias globals ethereum.berlin.vm.precompiled_contracts.__init__.globals "ALT_BN128_MUL_ADDRESS". +Axiom ethereum_berlin_vm_precompiled_contracts___init___ALT_BN128_PAIRING_CHECK_ADDRESS : + IsGlobalAlias globals ethereum.berlin.vm.precompiled_contracts.__init__.globals "ALT_BN128_PAIRING_CHECK_ADDRESS". +Axiom ethereum_berlin_vm_precompiled_contracts___init___BLAKE2F_ADDRESS : + IsGlobalAlias globals ethereum.berlin.vm.precompiled_contracts.__init__.globals "BLAKE2F_ADDRESS". +Axiom ethereum_berlin_vm_precompiled_contracts___init___ECRECOVER_ADDRESS : + IsGlobalAlias globals ethereum.berlin.vm.precompiled_contracts.__init__.globals "ECRECOVER_ADDRESS". +Axiom ethereum_berlin_vm_precompiled_contracts___init___IDENTITY_ADDRESS : + IsGlobalAlias globals ethereum.berlin.vm.precompiled_contracts.__init__.globals "IDENTITY_ADDRESS". +Axiom ethereum_berlin_vm_precompiled_contracts___init___MODEXP_ADDRESS : + IsGlobalAlias globals ethereum.berlin.vm.precompiled_contracts.__init__.globals "MODEXP_ADDRESS". +Axiom ethereum_berlin_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : + IsGlobalAlias globals ethereum.berlin.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". +Axiom ethereum_berlin_vm_precompiled_contracts___init___SHA256_ADDRESS : + IsGlobalAlias globals ethereum.berlin.vm.precompiled_contracts.__init__.globals "SHA256_ADDRESS". + +Require ethereum.berlin.vm.precompiled_contracts.alt_bn128. +Axiom ethereum_berlin_vm_precompiled_contracts_alt_bn128_alt_bn128_add : + IsGlobalAlias globals ethereum.berlin.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_add". +Axiom ethereum_berlin_vm_precompiled_contracts_alt_bn128_alt_bn128_mul : + IsGlobalAlias globals ethereum.berlin.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_mul". +Axiom ethereum_berlin_vm_precompiled_contracts_alt_bn128_alt_bn128_pairing_check : + IsGlobalAlias globals ethereum.berlin.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_pairing_check". + +Require ethereum.berlin.vm.precompiled_contracts.blake2f. +Axiom ethereum_berlin_vm_precompiled_contracts_blake2f_blake2f : + IsGlobalAlias globals ethereum.berlin.vm.precompiled_contracts.blake2f.globals "blake2f". + +Require ethereum.berlin.vm.precompiled_contracts.ecrecover. +Axiom ethereum_berlin_vm_precompiled_contracts_ecrecover_ecrecover : + IsGlobalAlias globals ethereum.berlin.vm.precompiled_contracts.ecrecover.globals "ecrecover". + +Require ethereum.berlin.vm.precompiled_contracts.identity. +Axiom ethereum_berlin_vm_precompiled_contracts_identity_identity : + IsGlobalAlias globals ethereum.berlin.vm.precompiled_contracts.identity.globals "identity". + +Require ethereum.berlin.vm.precompiled_contracts.modexp. +Axiom ethereum_berlin_vm_precompiled_contracts_modexp_modexp : + IsGlobalAlias globals ethereum.berlin.vm.precompiled_contracts.modexp.globals "modexp". + +Require ethereum.berlin.vm.precompiled_contracts.ripemd160. +Axiom ethereum_berlin_vm_precompiled_contracts_ripemd160_ripemd160 : + IsGlobalAlias globals ethereum.berlin.vm.precompiled_contracts.ripemd160.globals "ripemd160". + +Require ethereum.berlin.vm.precompiled_contracts.sha256. +Axiom ethereum_berlin_vm_precompiled_contracts_sha256_sha256 : + IsGlobalAlias globals ethereum.berlin.vm.precompiled_contracts.sha256.globals "sha256". (* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/modexp.v index 3505244..87418ff 100644 --- a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/modexp.v +++ b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/modexp.v @@ -25,17 +25,17 @@ Axiom ethereum_base_types_Bytes : Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.berlin.vm.__init__. +Axiom ethereum_berlin_vm___init___Evm : + IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.berlin.vm.gas. +Axiom ethereum_berlin_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "charge_gas". -Require memory. -Axiom memory_buffer_read : - IsGlobalAlias globals memory.globals "buffer_read". +Require ethereum.berlin.vm.memory. +Axiom ethereum_berlin_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.berlin.vm.memory.globals "buffer_read". Definition GQUADDIVISOR : Value.t := M.run ltac:(M.monadic ( Constant.int 3 @@ -192,6 +192,36 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_name (| globals, "base_length" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "modulus_length" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [], + make_dict [] + |) + |) in + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let base := @@ -254,6 +284,30 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "modulus" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + BinOp.mult (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + Constant.bytes "00" + ], + make_dict [] + |), + M.get_name (| globals, "modulus_length" |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| @@ -338,6 +392,7 @@ Definition complexity : Value.t -> Value.t -> M := M.get_name (| globals, "words" |), Constant.int 2 |) + |) in M.pure Constant.None_)). Definition iterations : Value.t -> Value.t -> M := @@ -364,7 +419,76 @@ Definition iterations : Value.t -> Value.t -> M := Number of iterations. " in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.lt_e (| + M.get_name (| globals, "exponent_length" |), + Constant.int 32 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "exponent_head" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let count := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "exponent_length" |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let bit_length := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "exponent_head" |), "bit_length" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "bit_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let bit_length := BinOp.sub + Constant.int 1 + Constant.int 1 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let count := + M.get_name (| globals, "bit_length" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let length_part := BinOp.mult (| Constant.int 8, @@ -392,6 +516,20 @@ Definition iterations : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "bits_part" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let bits_part := BinOp.sub + Constant.int 1 + Constant.int 1 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let count := @@ -418,6 +556,7 @@ Definition iterations : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition gas_cost : Value.t -> Value.t -> M := @@ -489,4 +628,5 @@ Definition gas_cost : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/ripemd160.v index 96f8dcd..0ec622a 100644 --- a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/ripemd160.v +++ b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/ripemd160.v @@ -31,17 +31,17 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.berlin.vm.__init__. +Axiom ethereum_berlin_vm___init___Evm : + IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_RIPEMD160 : - IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160". -Axiom vm_gas_GAS_RIPEMD160_WORD : - IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160_WORD". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.berlin.vm.gas. +Axiom ethereum_berlin_vm_gas_GAS_RIPEMD160 : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_RIPEMD160". +Axiom ethereum_berlin_vm_gas_GAS_RIPEMD160_WORD : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_RIPEMD160_WORD". +Axiom ethereum_berlin_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "charge_gas". Definition ripemd160 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/sha256.v index 9f6d2bf..cd17f78 100644 --- a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/sha256.v +++ b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/sha256.v @@ -27,17 +27,17 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.berlin.vm.__init__. +Axiom ethereum_berlin_vm___init___Evm : + IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_SHA256 : - IsGlobalAlias globals vm.gas.globals "GAS_SHA256". -Axiom vm_gas_GAS_SHA256_WORD : - IsGlobalAlias globals vm.gas.globals "GAS_SHA256_WORD". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.berlin.vm.gas. +Axiom ethereum_berlin_vm_gas_GAS_SHA256 : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_SHA256". +Axiom ethereum_berlin_vm_gas_GAS_SHA256_WORD : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_SHA256_WORD". +Axiom ethereum_berlin_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.berlin.vm.gas.globals "charge_gas". Definition sha256 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/berlin/vm/runtime.v b/CoqOfPython/ethereum/berlin/vm/runtime.v index 2cd7652..b70ed0d 100644 --- a/CoqOfPython/ethereum/berlin/vm/runtime.v +++ b/CoqOfPython/ethereum/berlin/vm/runtime.v @@ -25,9 +25,9 @@ Require ethereum.base_types. Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require instructions. -Axiom instructions_Ops : - IsGlobalAlias globals instructions.globals "Ops". +Require ethereum.berlin.vm.instructions.__init__. +Axiom ethereum_berlin_vm_instructions___init___Ops : + IsGlobalAlias globals ethereum.berlin.vm.instructions.__init__.globals "Ops". Definition get_valid_jump_destinations : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -79,7 +79,55 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := |) do (* At stmt: unsupported node type: Try *) let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "current_opcode" |), + M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), + make_list [ + M.get_name (| globals, "pc" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.lt_e (| + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |), + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH32" |), "value" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let push_data_size := + BinOp.add (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) + |), + Constant.int 1 + |) in + let pc := BinOp.add + M.get_name (| globals, "push_data_size" |) + M.get_name (| globals, "push_data_size" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -90,4 +138,5 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := EndWhile. let _ := M.return_ (| M.get_name (| globals, "valid_jump_destinations" |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/vm/stack.v b/CoqOfPython/ethereum/berlin/vm/stack.v index ea778df..439d8f8 100644 --- a/CoqOfPython/ethereum/berlin/vm/stack.v +++ b/CoqOfPython/ethereum/berlin/vm/stack.v @@ -25,11 +25,11 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require exceptions. -Axiom exceptions_StackOverflowError : - IsGlobalAlias globals exceptions.globals "StackOverflowError". -Axiom exceptions_StackUnderflowError : - IsGlobalAlias globals exceptions.globals "StackUnderflowError". +Require ethereum.berlin.vm.exceptions. +Axiom ethereum_berlin_vm_exceptions_StackOverflowError : + IsGlobalAlias globals ethereum.berlin.vm.exceptions.globals "StackOverflowError". +Axiom ethereum_berlin_vm_exceptions_StackUnderflowError : + IsGlobalAlias globals ethereum.berlin.vm.exceptions.globals "StackUnderflowError". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -49,6 +49,24 @@ Definition pop : Value.t -> Value.t -> M := " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "StackUnderflowError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -57,6 +75,7 @@ Definition pop : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). Definition push : Value.t -> Value.t -> M := @@ -75,6 +94,24 @@ Definition push : Value.t -> Value.t -> M := " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), + Constant.int 1024 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "StackOverflowError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -85,4 +122,5 @@ Definition push : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/blocks.v b/CoqOfPython/ethereum/byzantium/blocks.v index 6501788..706b6cc 100644 --- a/CoqOfPython/ethereum/byzantium/blocks.v +++ b/CoqOfPython/ethereum/byzantium/blocks.v @@ -22,35 +22,35 @@ Require typing. Axiom typing_Tuple : IsGlobalAlias globals typing.globals "Tuple". -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes8 : - IsGlobalAlias globals base_types.globals "Bytes8". -Axiom base_types_Bytes32 : - IsGlobalAlias globals base_types.globals "Bytes32". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require crypto.hash. -Axiom crypto_hash_Hash32 : - IsGlobalAlias globals crypto.hash.globals "Hash32". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". - -Require transactions. -Axiom transactions_Transaction : - IsGlobalAlias globals transactions.globals "Transaction". +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes8 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes8". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". + +Require ethereum.byzantium.fork_types. +Axiom ethereum_byzantium_fork_types_Address : + IsGlobalAlias globals ethereum.byzantium.fork_types.globals "Address". +Axiom ethereum_byzantium_fork_types_Bloom : + IsGlobalAlias globals ethereum.byzantium.fork_types.globals "Bloom". +Axiom ethereum_byzantium_fork_types_Root : + IsGlobalAlias globals ethereum.byzantium.fork_types.globals "Root". + +Require ethereum.byzantium.transactions. +Axiom ethereum_byzantium_transactions_Transaction : + IsGlobalAlias globals ethereum.byzantium.transactions.globals "Transaction". Definition Header : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/byzantium/bloom.v b/CoqOfPython/ethereum/byzantium/bloom.v index 04650ff..7342ee7 100644 --- a/CoqOfPython/ethereum/byzantium/bloom.v +++ b/CoqOfPython/ethereum/byzantium/bloom.v @@ -33,13 +33,13 @@ Require ethereum.crypto.hash. Axiom ethereum_crypto_hash_keccak256 : IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". +Require ethereum.byzantium.blocks. +Axiom ethereum_byzantium_blocks_Log : + IsGlobalAlias globals ethereum.byzantium.blocks.globals "Log". -Require fork_types. -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". +Require ethereum.byzantium.fork_types. +Axiom ethereum_byzantium_fork_types_Bloom : + IsGlobalAlias globals ethereum.byzantium.fork_types.globals "Bloom". Definition add_to_bloom : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -72,7 +72,10 @@ Definition add_to_bloom : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |) |) + M.get_subscript (| M.get_name (| globals, "hash" |), M.slice (| M.get_name (| globals, "idx" |), BinOp.add (| + M.get_name (| globals, "idx" |), + Constant.int 2 + |) |) |) ], make_dict [] |), @@ -157,4 +160,5 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/fork.v b/CoqOfPython/ethereum/byzantium/fork.v index 1151a67..c956ddc 100644 --- a/CoqOfPython/ethereum/byzantium/fork.v +++ b/CoqOfPython/ethereum/byzantium/fork.v @@ -63,93 +63,93 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U64 : - IsGlobalAlias globals base_types.globals "U64". -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_U256_CEIL_VALUE : - IsGlobalAlias globals base_types.globals "U256_CEIL_VALUE". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". - -Require __init__. -Axiom __init___vm : - IsGlobalAlias globals __init__.globals "vm". - -Require blocks. -Axiom blocks_Block : - IsGlobalAlias globals blocks.globals "Block". -Axiom blocks_Header : - IsGlobalAlias globals blocks.globals "Header". -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". -Axiom blocks_Receipt : - IsGlobalAlias globals blocks.globals "Receipt". - -Require bloom. -Axiom bloom_logs_bloom : - IsGlobalAlias globals bloom.globals "logs_bloom". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". - -Require state. -Axiom state_State : - IsGlobalAlias globals state.globals "State". -Axiom state_account_exists_and_is_empty : - IsGlobalAlias globals state.globals "account_exists_and_is_empty". -Axiom state_create_ether : - IsGlobalAlias globals state.globals "create_ether". -Axiom state_destroy_account : - IsGlobalAlias globals state.globals "destroy_account". -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". -Axiom state_increment_nonce : - IsGlobalAlias globals state.globals "increment_nonce". -Axiom state_set_account_balance : - IsGlobalAlias globals state.globals "set_account_balance". -Axiom state_state_root : - IsGlobalAlias globals state.globals "state_root". - -Require transactions. -Axiom transactions_TX_BASE_COST : - IsGlobalAlias globals transactions.globals "TX_BASE_COST". -Axiom transactions_TX_CREATE_COST : - IsGlobalAlias globals transactions.globals "TX_CREATE_COST". -Axiom transactions_TX_DATA_COST_PER_NON_ZERO : - IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_NON_ZERO". -Axiom transactions_TX_DATA_COST_PER_ZERO : - IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_ZERO". -Axiom transactions_Transaction : - IsGlobalAlias globals transactions.globals "Transaction". - -Require trie. -Axiom trie_Trie : - IsGlobalAlias globals trie.globals "Trie". -Axiom trie_root : - IsGlobalAlias globals trie.globals "root". -Axiom trie_trie_set : - IsGlobalAlias globals trie.globals "trie_set". - -Require utils.message. -Axiom utils_message_prepare_message : - IsGlobalAlias globals utils.message.globals "prepare_message". - -Require vm.interpreter. -Axiom vm_interpreter_process_message_call : - IsGlobalAlias globals vm.interpreter.globals "process_message_call". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U64 : + IsGlobalAlias globals ethereum.base_types.globals "U64". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_U256_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.byzantium.__init__. +Axiom ethereum_byzantium___init___vm : + IsGlobalAlias globals ethereum.byzantium.__init__.globals "vm". + +Require ethereum.byzantium.blocks. +Axiom ethereum_byzantium_blocks_Block : + IsGlobalAlias globals ethereum.byzantium.blocks.globals "Block". +Axiom ethereum_byzantium_blocks_Header : + IsGlobalAlias globals ethereum.byzantium.blocks.globals "Header". +Axiom ethereum_byzantium_blocks_Log : + IsGlobalAlias globals ethereum.byzantium.blocks.globals "Log". +Axiom ethereum_byzantium_blocks_Receipt : + IsGlobalAlias globals ethereum.byzantium.blocks.globals "Receipt". + +Require ethereum.byzantium.bloom. +Axiom ethereum_byzantium_bloom_logs_bloom : + IsGlobalAlias globals ethereum.byzantium.bloom.globals "logs_bloom". + +Require ethereum.byzantium.fork_types. +Axiom ethereum_byzantium_fork_types_Address : + IsGlobalAlias globals ethereum.byzantium.fork_types.globals "Address". +Axiom ethereum_byzantium_fork_types_Bloom : + IsGlobalAlias globals ethereum.byzantium.fork_types.globals "Bloom". +Axiom ethereum_byzantium_fork_types_Root : + IsGlobalAlias globals ethereum.byzantium.fork_types.globals "Root". + +Require ethereum.byzantium.state. +Axiom ethereum_byzantium_state_State : + IsGlobalAlias globals ethereum.byzantium.state.globals "State". +Axiom ethereum_byzantium_state_account_exists_and_is_empty : + IsGlobalAlias globals ethereum.byzantium.state.globals "account_exists_and_is_empty". +Axiom ethereum_byzantium_state_create_ether : + IsGlobalAlias globals ethereum.byzantium.state.globals "create_ether". +Axiom ethereum_byzantium_state_destroy_account : + IsGlobalAlias globals ethereum.byzantium.state.globals "destroy_account". +Axiom ethereum_byzantium_state_get_account : + IsGlobalAlias globals ethereum.byzantium.state.globals "get_account". +Axiom ethereum_byzantium_state_increment_nonce : + IsGlobalAlias globals ethereum.byzantium.state.globals "increment_nonce". +Axiom ethereum_byzantium_state_set_account_balance : + IsGlobalAlias globals ethereum.byzantium.state.globals "set_account_balance". +Axiom ethereum_byzantium_state_state_root : + IsGlobalAlias globals ethereum.byzantium.state.globals "state_root". + +Require ethereum.byzantium.transactions. +Axiom ethereum_byzantium_transactions_TX_BASE_COST : + IsGlobalAlias globals ethereum.byzantium.transactions.globals "TX_BASE_COST". +Axiom ethereum_byzantium_transactions_TX_CREATE_COST : + IsGlobalAlias globals ethereum.byzantium.transactions.globals "TX_CREATE_COST". +Axiom ethereum_byzantium_transactions_TX_DATA_COST_PER_NON_ZERO : + IsGlobalAlias globals ethereum.byzantium.transactions.globals "TX_DATA_COST_PER_NON_ZERO". +Axiom ethereum_byzantium_transactions_TX_DATA_COST_PER_ZERO : + IsGlobalAlias globals ethereum.byzantium.transactions.globals "TX_DATA_COST_PER_ZERO". +Axiom ethereum_byzantium_transactions_Transaction : + IsGlobalAlias globals ethereum.byzantium.transactions.globals "Transaction". + +Require ethereum.byzantium.trie. +Axiom ethereum_byzantium_trie_Trie : + IsGlobalAlias globals ethereum.byzantium.trie.globals "Trie". +Axiom ethereum_byzantium_trie_root : + IsGlobalAlias globals ethereum.byzantium.trie.globals "root". +Axiom ethereum_byzantium_trie_trie_set : + IsGlobalAlias globals ethereum.byzantium.trie.globals "trie_set". + +Require ethereum.byzantium.utils.message. +Axiom ethereum_byzantium_utils_message_prepare_message : + IsGlobalAlias globals ethereum.byzantium.utils.message.globals "prepare_message". + +Require ethereum.byzantium.vm.interpreter. +Axiom ethereum_byzantium_vm_interpreter_process_message_call : + IsGlobalAlias globals ethereum.byzantium.vm.interpreter.globals "process_message_call". Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -242,6 +242,7 @@ Definition apply_fork : Value.t -> Value.t -> M := " in let _ := M.return_ (| M.get_name (| globals, "old" |) + |) in M.pure Constant.None_)). Definition get_last_256_block_hashes : Value.t -> Value.t -> M := @@ -267,8 +268,28 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := Hashes of the recent 256 blocks in order of increasing block number. " in let recent_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |) |) in + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "recent_blocks" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + make_list [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let recent_block_hashes := @@ -307,6 +328,7 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "recent_block_hashes" |) + |) in M.pure Constant.None_)). Definition state_transition : Value.t -> Value.t -> M := @@ -438,6 +460,27 @@ Definition state_transition : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |) + ], + make_dict [] + |), + Constant.int 255 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -630,6 +673,7 @@ Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition validate_proof_of_work : Value.t -> Value.t -> M := @@ -764,6 +808,7 @@ Definition check_transaction : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "sender_address" |) + |) in M.pure Constant.None_)). Definition make_receipt : Value.t -> Value.t -> M := @@ -797,6 +842,7 @@ Definition make_receipt : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "receipt" |) + |) in M.pure Constant.None_)). Definition ApplyBodyOutput : Value.t := @@ -1007,6 +1053,7 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition validate_ommers : Value.t -> Value.t -> M := @@ -1059,6 +1106,26 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do @@ -1116,7 +1183,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let ommers_hashes := - (* At expr: unsupported node type: ListComp *) in + Constant.str "(* At expr: unsupported node type: ListComp *)" in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1147,19 +1214,19 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let recent_canonical_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| BinOp.add (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| BinOp.add (| M.get_name (| globals, "MAX_OMMER_DEPTH" |), Constant.int 1 - |) |) |) in + |) |), Constant.None_ |) |) in let recent_canonical_block_hashes := - (* At expr: unsupported node type: SetComp *) in + Constant.str "(* At expr: unsupported node type: SetComp *)" in (* At stmt: unsupported node type: AnnAssign *) For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_canonical_blocks" |) do let recent_ommers_hashes := M.call (| M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), make_list [ - (* At expr: unsupported node type: SetComp *) + Constant.str "(* At expr: unsupported node type: SetComp *)" ], make_dict [] |) in @@ -1573,7 +1640,50 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "transaction_fee" |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| + M.get_name (| globals, "coinbase_balance_after_mining_fee" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |); + M.get_name (| globals, "coinbase_balance_after_mining_fee" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -1590,11 +1700,35 @@ Definition process_transaction : Value.t -> Value.t -> M := EndFor. For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "touched_accounts" |) do let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := M.return_ (| make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |); M.get_field (| M.get_name (| globals, "output" |), "error" |) ] + |) in M.pure Constant.None_)). Definition validate_transaction : Value.t -> Value.t -> M := @@ -1649,6 +1783,7 @@ Definition validate_transaction : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := @@ -1680,6 +1815,20 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := Constant.int 0 in For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "byte" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let data_cost := BinOp.add M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in @@ -1687,6 +1836,25 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := )) |) in EndFor. let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "tx" |), "to" |), + M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) + |), + (* then *) + ltac:(M.monadic ( + let create_cost := + M.get_name (| globals, "TX_CREATE_COST" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let create_cost := Constant.int 0 in M.pure Constant.None_ @@ -1705,6 +1873,7 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition recover_sender : Value.t -> Value.t -> M := @@ -1777,6 +1946,45 @@ Definition recover_sender : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.eq (| + M.get_name (| globals, "v" |), + Constant.int 27 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "v" |), + Constant.int 28 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + BinOp.sub (| + M.get_name (| globals, "v" |), + Constant.int 27 + |); + M.call (| + M.get_name (| globals, "signing_hash_pre155" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1847,10 +2055,11 @@ Definition recover_sender : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12 |) + |), M.slice (| Constant.int 12, Constant.int 32 |) |) ], make_dict [] |) + |) in M.pure Constant.None_)). Definition signing_hash_pre155 : Value.t -> Value.t -> M := @@ -1883,6 +2092,7 @@ Definition signing_hash_pre155 : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition signing_hash_155 : Value.t -> Value.t -> M := @@ -1929,6 +2139,7 @@ Definition signing_hash_155 : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition compute_header_hash : Value.t -> Value.t -> M := @@ -1979,6 +2190,7 @@ Definition compute_header_hash : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition check_gas_limit : Value.t -> Value.t -> M := @@ -2017,16 +2229,65 @@ Definition check_gas_limit : Value.t -> Value.t -> M := M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "gas_limit" |), + BinOp.add (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "gas_limit" |), + BinOp.sub (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "gas_limit" |), + M.get_name (| globals, "GAS_LIMIT_MINIMUM" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| Constant.bool true + |) in M.pure Constant.None_)). Definition calculate_block_difficulty : Value.t -> Value.t -> M := @@ -2086,12 +2347,16 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := M.get_name (| globals, "max" |), make_list [ BinOp.sub (| - (* if *) -M.if_then_else (| - M.get_name (| globals, "parent_has_ommers" |), -(* then *) -ltac:(M.monadic ( -Constant.int 2, + (* if *) + M.if_then_else (| + M.get_name (| globals, "parent_has_ommers" |), + (* then *) + ltac:(M.monadic ( +Constant.int 2 + (* else *) + )), ltac:(M.monadic ( +Constant.int 1 + )) |), BinOp.floor_div (| M.call (| M.get_name (| globals, "int" |), @@ -2140,6 +2405,26 @@ Constant.int 2, Constant.int 2 |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "num_bomb_periods" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let difficulty := BinOp.add + BinOp.pow (| + Constant.int 2, + M.get_name (| globals, "num_bomb_periods" |) + |) + BinOp.pow (| + Constant.int 2, + M.get_name (| globals, "num_bomb_periods" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -2157,4 +2442,5 @@ Constant.int 2, ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/fork_types.v b/CoqOfPython/ethereum/byzantium/fork_types.v index 5c7dac3..cc8e4a1 100644 --- a/CoqOfPython/ethereum/byzantium/fork_types.v +++ b/CoqOfPython/ethereum/byzantium/fork_types.v @@ -21,29 +21,29 @@ Require dataclasses. Axiom dataclasses_dataclass : IsGlobalAlias globals dataclasses.globals "dataclass". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes20 : - IsGlobalAlias globals base_types.globals "Bytes20". -Axiom base_types_Bytes256 : - IsGlobalAlias globals base_types.globals "Bytes256". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require crypto.hash. -Axiom crypto_hash_Hash32 : - IsGlobalAlias globals crypto.hash.globals "Hash32". -Axiom crypto_hash_keccak256 : - IsGlobalAlias globals crypto.hash.globals "keccak256". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes20 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes20". +Axiom ethereum_base_types_Bytes256 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) @@ -98,4 +98,5 @@ Definition encode_account : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/state.v b/CoqOfPython/ethereum/byzantium/state.v index c5b604e..1990b58 100644 --- a/CoqOfPython/ethereum/byzantium/state.v +++ b/CoqOfPython/ethereum/byzantium/state.v @@ -54,29 +54,29 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require fork_types. -Axiom fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". -Axiom fork_types_Account : - IsGlobalAlias globals fork_types.globals "Account". -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". - -Require trie. -Axiom trie_EMPTY_TRIE_ROOT : - IsGlobalAlias globals trie.globals "EMPTY_TRIE_ROOT". -Axiom trie_Trie : - IsGlobalAlias globals trie.globals "Trie". -Axiom trie_copy_trie : - IsGlobalAlias globals trie.globals "copy_trie". -Axiom trie_root : - IsGlobalAlias globals trie.globals "root". -Axiom trie_trie_get : - IsGlobalAlias globals trie.globals "trie_get". -Axiom trie_trie_set : - IsGlobalAlias globals trie.globals "trie_set". +Require ethereum.byzantium.fork_types. +Axiom ethereum_byzantium_fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals ethereum.byzantium.fork_types.globals "EMPTY_ACCOUNT". +Axiom ethereum_byzantium_fork_types_Account : + IsGlobalAlias globals ethereum.byzantium.fork_types.globals "Account". +Axiom ethereum_byzantium_fork_types_Address : + IsGlobalAlias globals ethereum.byzantium.fork_types.globals "Address". +Axiom ethereum_byzantium_fork_types_Root : + IsGlobalAlias globals ethereum.byzantium.fork_types.globals "Root". + +Require ethereum.byzantium.trie. +Axiom ethereum_byzantium_trie_EMPTY_TRIE_ROOT : + IsGlobalAlias globals ethereum.byzantium.trie.globals "EMPTY_TRIE_ROOT". +Axiom ethereum_byzantium_trie_Trie : + IsGlobalAlias globals ethereum.byzantium.trie.globals "Trie". +Axiom ethereum_byzantium_trie_copy_trie : + IsGlobalAlias globals ethereum.byzantium.trie.globals "copy_trie". +Axiom ethereum_byzantium_trie_root : + IsGlobalAlias globals ethereum.byzantium.trie.globals "root". +Axiom ethereum_byzantium_trie_trie_get : + IsGlobalAlias globals ethereum.byzantium.trie.globals "trie_get". +Axiom ethereum_byzantium_trie_trie_set : + IsGlobalAlias globals ethereum.byzantium.trie.globals "trie_set". Definition State : Value.t := builtins.make_klass @@ -123,7 +123,7 @@ Definition begin_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) ], make_dict [] - |); (* At expr: unsupported node type: DictComp *) ] + |); Constant.str "(* At expr: unsupported node type: DictComp *)" ] ], make_dict [] |) in @@ -201,8 +201,27 @@ Definition get_account : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "account" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "account" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_ACCOUNT" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -237,6 +256,7 @@ Definition get_account_optional : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "account" |) + |) in M.pure Constant.None_)). Definition set_account : Value.t -> Value.t -> M := @@ -316,6 +336,18 @@ Definition destroy_storage : Value.t -> Value.t -> M := Address of account whose storage is to be deleted. " in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -350,6 +382,26 @@ Definition get_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "trie" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let value := @@ -371,6 +423,7 @@ Definition get_storage : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "value" |) + |) in M.pure Constant.None_)). Definition set_storage : Value.t -> Value.t -> M := @@ -411,6 +464,27 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "trie" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let trie := + M.call (| + M.get_name (| globals, "Trie" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), + M.get_name (| globals, "trie" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -423,6 +497,18 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + {} + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -447,8 +533,29 @@ Definition storage_root : Value.t -> Value.t -> M := " in let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_TRIE_ROOT" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -479,6 +586,7 @@ Definition state_root : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition account_exists : Value.t -> Value.t -> M := @@ -511,6 +619,7 @@ Definition account_exists : Value.t -> Value.t -> M := |), Constant.None_ |) + |) in M.pure Constant.None_)). Definition account_has_code_or_nonce : Value.t -> Value.t -> M := @@ -560,6 +669,7 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition is_account_empty : Value.t -> Value.t -> M := @@ -617,6 +727,7 @@ Definition is_account_empty : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition account_exists_and_is_empty : Value.t -> Value.t -> M := @@ -683,6 +794,7 @@ Definition account_exists_and_is_empty : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition is_account_alive : Value.t -> Value.t -> M := @@ -713,6 +825,20 @@ Definition is_account_alive : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "account" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| UnOp.not (| BoolOp.and (| Compare.eq (| @@ -740,6 +866,7 @@ Definition is_account_alive : Value.t -> Value.t -> M := |) )) |) |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -847,6 +974,30 @@ Definition touch_account : Value.t -> Value.t -> M := The address of the account that need to initialised. " in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "account_exists" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "EMPTY_ACCOUNT" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/transactions.v b/CoqOfPython/ethereum/byzantium/transactions.v index 6d1bc6b..2627592 100644 --- a/CoqOfPython/ethereum/byzantium/transactions.v +++ b/CoqOfPython/ethereum/byzantium/transactions.v @@ -17,21 +17,21 @@ Require typing. Axiom typing_Union : IsGlobalAlias globals typing.globals "Union". -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes0 : - IsGlobalAlias globals base_types.globals "Bytes0". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.byzantium.fork_types. +Axiom ethereum_byzantium_fork_types_Address : + IsGlobalAlias globals ethereum.byzantium.fork_types.globals "Address". Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( Constant.int 21000 diff --git a/CoqOfPython/ethereum/byzantium/trie.v b/CoqOfPython/ethereum/byzantium/trie.v index 37074d6..1e0a81c 100644 --- a/CoqOfPython/ethereum/byzantium/trie.v +++ b/CoqOfPython/ethereum/byzantium/trie.v @@ -54,9 +54,9 @@ Require ethereum.crypto.hash. Axiom ethereum_crypto_hash_keccak256 : IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". -Require ethereum.spurious_dragon. -Axiom ethereum_spurious_dragon_trie : - IsGlobalAlias globals ethereum.spurious_dragon.globals "trie". +Require ethereum.spurious_dragon.__init__. +Axiom ethereum_spurious_dragon___init___trie : + IsGlobalAlias globals ethereum.spurious_dragon.__init__.globals "trie". Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : @@ -66,37 +66,37 @@ Require ethereum.utils.hexadecimal. Axiom ethereum_utils_hexadecimal_hex_to_bytes : IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require blocks. -Axiom blocks_Receipt : - IsGlobalAlias globals blocks.globals "Receipt". - -Require fork_types. -Axiom fork_types_Account : - IsGlobalAlias globals fork_types.globals "Account". -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". -Axiom fork_types_encode_account : - IsGlobalAlias globals fork_types.globals "encode_account". - -Require transactions. -Axiom transactions_Transaction : - IsGlobalAlias globals transactions.globals "Transaction". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.byzantium.blocks. +Axiom ethereum_byzantium_blocks_Receipt : + IsGlobalAlias globals ethereum.byzantium.blocks.globals "Receipt". + +Require ethereum.byzantium.fork_types. +Axiom ethereum_byzantium_fork_types_Account : + IsGlobalAlias globals ethereum.byzantium.fork_types.globals "Account". +Axiom ethereum_byzantium_fork_types_Address : + IsGlobalAlias globals ethereum.byzantium.fork_types.globals "Address". +Axiom ethereum_byzantium_fork_types_Root : + IsGlobalAlias globals ethereum.byzantium.fork_types.globals "Root". +Axiom ethereum_byzantium_fork_types_encode_account : + IsGlobalAlias globals ethereum.byzantium.fork_types.globals "encode_account". + +Require ethereum.byzantium.transactions. +Axiom ethereum_byzantium_transactions_Transaction : + IsGlobalAlias globals ethereum.byzantium.transactions.globals "Transaction". Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -202,16 +202,99 @@ Definition encode_internal_node : Value.t -> Value.t -> M := " in (* At stmt: unsupported node type: AnnAssign *) let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "node" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + Constant.bytes "" in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "LeafNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "rest_of_key" |); + Constant.bool true + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "ExtensionNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "key_segment" |); + Constant.bool false + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "BranchNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + BinOp.add (| + M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "value" |) + ] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ - (* At expr: unsupported node type: JoinedStr *) + Constant.str "(* At expr: unsupported node type: JoinedStr *)" ], make_dict [] - |)) + |)) |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -229,6 +312,26 @@ Definition encode_internal_node : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded" |) + ], + make_dict [] + |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "unencoded" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_name (| globals, "keccak256" |), @@ -237,6 +340,7 @@ Definition encode_internal_node : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -250,8 +354,86 @@ Definition encode_node : Value.t -> Value.t -> M := Currently mostly an unimplemented stub. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| + M.get_name (| globals, "storage_root" |), + Constant.None_ + |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "encode_account" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "storage_root" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + make_tuple [ M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "U256" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "cast" |), + make_list [ + M.get_field (| M.get_name (| globals, "rlp" |), "RLP" |); + M.get_name (| globals, "node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "node" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "previous_trie" |), "encode_node" |), @@ -261,6 +443,7 @@ Definition encode_node : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -312,6 +495,7 @@ Definition copy_trie : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition trie_set : Value.t -> Value.t -> M := @@ -333,6 +517,32 @@ Definition trie_set : Value.t -> Value.t -> M := Node to insert at `key`. " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + M.get_field (| M.get_name (| globals, "trie" |), "default" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "key" |), + M.get_field (| M.get_name (| globals, "trie" |), "_data" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), M.get_name (| globals, "value" |) @@ -370,6 +580,7 @@ Definition trie_get : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition common_prefix_length : Value.t -> Value.t -> M := @@ -392,6 +603,34 @@ Definition common_prefix_length : Value.t -> Value.t -> M := make_dict [] |) do let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), + M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -403,6 +642,7 @@ Definition common_prefix_length : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition nibble_list_to_compact : Value.t -> Value.t -> M := @@ -448,6 +688,71 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + Constant.int 2 + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.mult (| + Constant.int 16, + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "is_leaf" |) + |) + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ @@ -509,6 +814,7 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition bytes_to_nibble_list : Value.t -> Value.t -> M := @@ -586,6 +892,7 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition _prepare_trie : Value.t -> Value.t -> M := @@ -615,6 +922,48 @@ Definition _prepare_trie : Value.t -> Value.t -> M := make_dict [] |) do let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| + M.get_name (| globals, "get_storage_root" |), + Constant.None_ + |) |) in + let address := + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |); + M.call (| + M.get_name (| globals, "get_storage_root" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let encoded_value := M.call (| M.get_name (| globals, "encode_node" |), @@ -638,6 +987,22 @@ Definition _prepare_trie : Value.t -> Value.t -> M := |) in (* At stmt: unsupported node type: AnnAssign *) let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "trie" |), "secured" |), + (* then *) + ltac:(M.monadic ( + let key := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let key := M.get_name (| globals, "preimage" |) in M.pure Constant.None_ @@ -655,6 +1020,7 @@ Definition _prepare_trie : Value.t -> Value.t -> M := EndFor. let _ := M.return_ (| M.get_name (| globals, "mapped" |) + |) in M.pure Constant.None_)). Definition root : Value.t -> Value.t -> M := @@ -708,6 +1074,44 @@ Definition root : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -724,6 +1128,7 @@ Definition root : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -750,6 +1155,26 @@ Definition patricialize : Value.t -> Value.t -> M := Root node of `obj`. " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let arbitrary_key := @@ -767,10 +1192,39 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), + Constant.int 1 + |), + (* then *) + ltac:(M.monadic ( + let leaf := + M.call (| + M.get_name (| globals, "LeafNode" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |); + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "leaf" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let substring := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |) |) in + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) in let prefix_length := M.call (| M.get_name (| globals, "len" |), @@ -789,7 +1243,7 @@ Definition patricialize : Value.t -> Value.t -> M := M.get_name (| globals, "common_prefix_length" |), make_list [ M.get_name (| globals, "substring" |); - M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) + M.get_subscript (| M.get_name (| globals, "key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) ], make_dict [] |) @@ -797,10 +1251,64 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "prefix_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "prefix_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let prefix := + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ExtensionNode" |), + make_list [ + M.get_name (| globals, "prefix" |); + M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_name (| globals, "obj" |); + BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) @@ -823,6 +1331,44 @@ Definition patricialize : Value.t -> Value.t -> M := Constant.bytes "" in For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |), + M.get_name (| globals, "level" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "AssertionError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) @@ -834,9 +1380,10 @@ Definition patricialize : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "BranchNode" |), make_list [ - (* At expr: unsupported node type: ListComp *); + Constant.str "(* At expr: unsupported node type: ListComp *)"; M.get_name (| globals, "value" |) ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/utils/address.v b/CoqOfPython/ethereum/byzantium/utils/address.v index 61cf3b1..22d928a 100644 --- a/CoqOfPython/ethereum/byzantium/utils/address.v +++ b/CoqOfPython/ethereum/byzantium/utils/address.v @@ -36,13 +36,13 @@ Require ethereum.utils.byte. Axiom ethereum_utils_byte_left_pad_zero_bytes : IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.byzantium.fork_types. +Axiom ethereum_byzantium_fork_types_Address : + IsGlobalAlias globals ethereum.byzantium.fork_types.globals "Address". Definition to_address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -68,10 +68,11 @@ Definition to_address : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), make_list [], make_dict [] - |), UnOp.sub (| Constant.int 20 |) |) + |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) ], make_dict [] |) + |) in M.pure Constant.None_)). Definition compute_contract_address : Value.t -> Value.t -> M := @@ -111,7 +112,7 @@ Definition compute_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -129,4 +130,5 @@ Definition compute_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/utils/hexadecimal.v b/CoqOfPython/ethereum/byzantium/utils/hexadecimal.v index 1c28bf7..6847186 100644 --- a/CoqOfPython/ethereum/byzantium/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/byzantium/utils/hexadecimal.v @@ -22,13 +22,13 @@ Require ethereum.utils.hexadecimal. Axiom ethereum_utils_hexadecimal_remove_hex_prefix : IsGlobalAlias globals ethereum.utils.hexadecimal.globals "remove_hex_prefix". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". +Require ethereum.byzantium.fork_types. +Axiom ethereum_byzantium_fork_types_Address : + IsGlobalAlias globals ethereum.byzantium.fork_types.globals "Address". +Axiom ethereum_byzantium_fork_types_Bloom : + IsGlobalAlias globals ethereum.byzantium.fork_types.globals "Bloom". +Axiom ethereum_byzantium_fork_types_Root : + IsGlobalAlias globals ethereum.byzantium.fork_types.globals "Root". Definition hex_to_root : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -66,6 +66,7 @@ Definition hex_to_root : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition hex_to_bloom : Value.t -> Value.t -> M := @@ -104,6 +105,7 @@ Definition hex_to_bloom : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition hex_to_address : Value.t -> Value.t -> M := @@ -149,4 +151,5 @@ Definition hex_to_address : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/utils/message.v b/CoqOfPython/ethereum/byzantium/utils/message.v index b9ae2bb..f23befa 100644 --- a/CoqOfPython/ethereum/byzantium/utils/message.v +++ b/CoqOfPython/ethereum/byzantium/utils/message.v @@ -34,23 +34,23 @@ Axiom ethereum_base_types_Bytes0 : Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.byzantium.fork_types. +Axiom ethereum_byzantium_fork_types_Address : + IsGlobalAlias globals ethereum.byzantium.fork_types.globals "Address". -Require state. -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". +Require ethereum.byzantium.state. +Axiom ethereum_byzantium_state_get_account : + IsGlobalAlias globals ethereum.byzantium.state.globals "get_account". -Require vm. -Axiom vm_Environment : - IsGlobalAlias globals vm.globals "Environment". -Axiom vm_Message : - IsGlobalAlias globals vm.globals "Message". +Require ethereum.byzantium.vm.__init__. +Axiom ethereum_byzantium_vm___init___Environment : + IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Environment". +Axiom ethereum_byzantium_vm___init___Message : + IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Message". -Require address. -Axiom address_compute_contract_address : - IsGlobalAlias globals address.globals "compute_contract_address". +Require ethereum.byzantium.utils.address. +Axiom ethereum_byzantium_utils_address_compute_contract_address : + IsGlobalAlias globals ethereum.byzantium.utils.address.globals "compute_contract_address". Definition prepare_message : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -88,14 +88,108 @@ Definition prepare_message : Value.t -> Value.t -> M := Items containing contract creation or message call specific data. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Bytes0" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.call (| + M.get_name (| globals, "compute_contract_address" |), + make_list [ + M.get_name (| globals, "caller" |); + BinOp.sub (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "caller" |) + ], + make_dict [] + |), "nonce" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let msg_data := + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) in + let code := + M.get_name (| globals, "data" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.get_name (| globals, "target" |) in + let msg_data := + M.get_name (| globals, "data" |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "target" |) + ], + make_dict [] + |), "code" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "code_address" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let code_address := + M.get_name (| globals, "target" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "Target must be address or empty bytes" ], make_dict [] - |)) + |)) |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -106,4 +200,5 @@ Definition prepare_message : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/vm/__init__.v b/CoqOfPython/ethereum/byzantium/vm/__init__.v index 8859cb4..c26fa07 100644 --- a/CoqOfPython/ethereum/byzantium/vm/__init__.v +++ b/CoqOfPython/ethereum/byzantium/vm/__init__.v @@ -48,23 +48,23 @@ Require ethereum.crypto.hash. Axiom ethereum_crypto_hash_Hash32 : IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". +Require ethereum.byzantium.blocks. +Axiom ethereum_byzantium_blocks_Log : + IsGlobalAlias globals ethereum.byzantium.blocks.globals "Log". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.byzantium.fork_types. +Axiom ethereum_byzantium_fork_types_Address : + IsGlobalAlias globals ethereum.byzantium.fork_types.globals "Address". -Require state. -Axiom state_State : - IsGlobalAlias globals state.globals "State". -Axiom state_account_exists_and_is_empty : - IsGlobalAlias globals state.globals "account_exists_and_is_empty". +Require ethereum.byzantium.state. +Axiom ethereum_byzantium_state_State : + IsGlobalAlias globals ethereum.byzantium.state.globals "State". +Axiom ethereum_byzantium_state_account_exists_and_is_empty : + IsGlobalAlias globals ethereum.byzantium.state.globals "account_exists_and_is_empty". -Require precompiled_contracts. -Axiom precompiled_contracts_RIPEMD160_ADDRESS : - IsGlobalAlias globals precompiled_contracts.globals "RIPEMD160_ADDRESS". +Require ethereum.byzantium.vm.precompiled_contracts.__init__. +Axiom ethereum_byzantium_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : + IsGlobalAlias globals ethereum.byzantium.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] @@ -143,6 +143,28 @@ Definition incorporate_child_on_success : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -161,9 +183,63 @@ Definition incorporate_child_on_error : Value.t -> Value.t -> M := The child evm to incorporate. " in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "RIPEMD160_ADDRESS" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |), + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign_op (| diff --git a/CoqOfPython/ethereum/byzantium/vm/gas.v b/CoqOfPython/ethereum/byzantium/vm/gas.v index 91436db..90d9c68 100644 --- a/CoqOfPython/ethereum/byzantium/vm/gas.v +++ b/CoqOfPython/ethereum/byzantium/vm/gas.v @@ -43,13 +43,13 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.byzantium.vm.__init__. +Axiom ethereum_byzantium_vm___init___Evm : + IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Evm". -Require exceptions. -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". +Require ethereum.byzantium.vm.exceptions. +Axiom ethereum_byzantium_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.byzantium.vm.exceptions.globals "OutOfGasError". Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -500,6 +500,18 @@ Definition charge_gas : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "amount" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign_op (| BinOp.sub, M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), @@ -615,6 +627,18 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := |) in For make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ] in M.get_name (| globals, "extensions" |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "size" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let before_size := @@ -649,6 +673,18 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let size_to_extend := BinOp.add @@ -697,6 +733,7 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition calculate_message_call_gas : Value.t -> Value.t -> M := @@ -728,22 +765,56 @@ Definition calculate_message_call_gas : Value.t -> Value.t -> M := message_call_gas: `MessageCallGas` " in let call_stipend := - (* if *) -M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "call_stipend" |) + )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "gas_left" |), + BinOp.add (| + M.get_name (| globals, "extra_gas" |), + M.get_name (| globals, "memory_cost" |) + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallGas" |), + make_list [ + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "extra_gas" |) + |); + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "call_stipend" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let gas := @@ -782,6 +853,7 @@ M.call (| ], make_dict [] |) + |) in M.pure Constant.None_)). Definition max_message_call_gas : Value.t -> Value.t -> M := @@ -808,4 +880,5 @@ Definition max_message_call_gas : Value.t -> Value.t -> M := Constant.int 64 |) |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/__init__.v b/CoqOfPython/ethereum/byzantium/vm/instructions/__init__.v index e5bebd7..248e357 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/__init__.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/__init__.v @@ -26,53 +26,53 @@ Axiom typing_Callable : Axiom typing_Dict : IsGlobalAlias globals typing.globals "Dict". -Require __init__. -Axiom __init___arithmetic : - IsGlobalAlias globals __init__.globals "arithmetic". +Require ethereum.byzantium.vm.instructions.__init__. +Axiom ethereum_byzantium_vm_instructions___init___arithmetic : + IsGlobalAlias globals ethereum.byzantium.vm.instructions.__init__.globals "arithmetic". -Require __init__. -Axiom __init___bitwise : - IsGlobalAlias globals __init__.globals "bitwise". +Require ethereum.byzantium.vm.instructions.__init__. +Axiom ethereum_byzantium_vm_instructions___init___bitwise : + IsGlobalAlias globals ethereum.byzantium.vm.instructions.__init__.globals "bitwise". -Require __init__. -Axiom __init___block : - IsGlobalAlias globals __init__.globals "block". +Require ethereum.byzantium.vm.instructions.__init__. +Axiom ethereum_byzantium_vm_instructions___init___block : + IsGlobalAlias globals ethereum.byzantium.vm.instructions.__init__.globals "block". -Require __init__. -Axiom __init___comparison : - IsGlobalAlias globals __init__.globals "comparison". +Require ethereum.byzantium.vm.instructions.__init__. +Axiom ethereum_byzantium_vm_instructions___init___comparison : + IsGlobalAlias globals ethereum.byzantium.vm.instructions.__init__.globals "comparison". -Require __init__. -Axiom __init___control_flow : - IsGlobalAlias globals __init__.globals "control_flow". +Require ethereum.byzantium.vm.instructions.__init__. +Axiom ethereum_byzantium_vm_instructions___init___control_flow : + IsGlobalAlias globals ethereum.byzantium.vm.instructions.__init__.globals "control_flow". -Require __init__. -Axiom __init___environment : - IsGlobalAlias globals __init__.globals "environment". +Require ethereum.byzantium.vm.instructions.__init__. +Axiom ethereum_byzantium_vm_instructions___init___environment : + IsGlobalAlias globals ethereum.byzantium.vm.instructions.__init__.globals "environment". -Require __init__. -Axiom __init___keccak : - IsGlobalAlias globals __init__.globals "keccak". +Require ethereum.byzantium.vm.instructions.__init__. +Axiom ethereum_byzantium_vm_instructions___init___keccak : + IsGlobalAlias globals ethereum.byzantium.vm.instructions.__init__.globals "keccak". -Require __init__. -Axiom __init___log : - IsGlobalAlias globals __init__.globals "log". +Require ethereum.byzantium.vm.instructions.__init__. +Axiom ethereum_byzantium_vm_instructions___init___log : + IsGlobalAlias globals ethereum.byzantium.vm.instructions.__init__.globals "log". -Require __init__. -Axiom __init___memory : - IsGlobalAlias globals __init__.globals "memory". +Require ethereum.byzantium.vm.instructions.__init__. +Axiom ethereum_byzantium_vm_instructions___init___memory : + IsGlobalAlias globals ethereum.byzantium.vm.instructions.__init__.globals "memory". -Require __init__. -Axiom __init___stack : - IsGlobalAlias globals __init__.globals "stack". +Require ethereum.byzantium.vm.instructions.__init__. +Axiom ethereum_byzantium_vm_instructions___init___stack : + IsGlobalAlias globals ethereum.byzantium.vm.instructions.__init__.globals "stack". -Require __init__. -Axiom __init___storage : - IsGlobalAlias globals __init__.globals "storage". +Require ethereum.byzantium.vm.instructions.__init__. +Axiom ethereum_byzantium_vm_instructions___init___storage : + IsGlobalAlias globals ethereum.byzantium.vm.instructions.__init__.globals "storage". -Require __init__. -Axiom __init___system : - IsGlobalAlias globals __init__.globals "system". +Require ethereum.byzantium.vm.instructions.__init__. +Axiom ethereum_byzantium_vm_instructions___init___system : + IsGlobalAlias globals ethereum.byzantium.vm.instructions.__init__.globals "system". Definition Ops : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/byzantium/vm/instructions/arithmetic.v index 581ba5d..ae4fb95 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/arithmetic.v @@ -31,29 +31,29 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_get_sign : IsGlobalAlias globals ethereum.utils.numeric.globals "get_sign". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_EXPONENTIATION : - IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION". -Axiom gas_GAS_EXPONENTIATION_PER_BYTE : - IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION_PER_BYTE". -Axiom gas_GAS_LOW : - IsGlobalAlias globals gas.globals "GAS_LOW". -Axiom gas_GAS_MID : - IsGlobalAlias globals gas.globals "GAS_MID". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.byzantium.vm.__init__. +Axiom ethereum_byzantium_vm___init___Evm : + IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Evm". + +Require ethereum.byzantium.vm.gas. +Axiom ethereum_byzantium_vm_gas_GAS_EXPONENTIATION : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_EXPONENTIATION". +Axiom ethereum_byzantium_vm_gas_GAS_EXPONENTIATION_PER_BYTE : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_EXPONENTIATION_PER_BYTE". +Axiom ethereum_byzantium_vm_gas_GAS_LOW : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_LOW". +Axiom ethereum_byzantium_vm_gas_GAS_MID : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_MID". +Axiom ethereum_byzantium_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_byzantium_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "charge_gas". + +Require ethereum.byzantium.vm.stack. +Axiom ethereum_byzantium_vm_stack_pop : + IsGlobalAlias globals ethereum.byzantium.vm.stack.globals "pop". +Axiom ethereum_byzantium_vm_stack_push : + IsGlobalAlias globals ethereum.byzantium.vm.stack.globals "push". Definition add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -273,6 +273,25 @@ Definition div : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "divisor" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let quotient := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let quotient := BinOp.floor_div (| M.get_name (| globals, "dividend" |), @@ -341,7 +360,41 @@ Definition sdiv : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "divisor" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let quotient := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_name (| globals, "dividend" |), + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "divisor" |), + UnOp.sub (| Constant.int 1 |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let quotient := + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let sign := M.call (| M.get_name (| globals, "get_sign" |), @@ -436,6 +489,25 @@ Definition mod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "y" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let remainder := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let remainder := BinOp.mod_ (| M.get_name (| globals, "x" |), @@ -504,6 +576,19 @@ Definition smod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "y" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let remainder := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let remainder := BinOp.mult (| M.call (| @@ -617,6 +702,25 @@ Definition addmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "z" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -712,6 +816,25 @@ Definition mulmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "z" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -881,6 +1004,19 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "byte_num" |), + Constant.int 31 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.get_name (| globals, "value" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let value_bytes := M.call (| M.get_name (| globals, "bytes" |), @@ -894,7 +1030,7 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let value_bytes := - M.get_subscript (| M.get_name (| globals, "value_bytes" |), BinOp.sub (| + M.get_subscript (| M.get_name (| globals, "value_bytes" |), M.slice (| BinOp.sub (| Constant.int 31, M.call (| M.get_name (| globals, "int" |), @@ -903,13 +1039,32 @@ Definition signextend : Value.t -> Value.t -> M := ], make_dict [] |) - |) |) in + |), Constant.None_ |) |) in let sign_bit := BinOp.r_shift (| M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), Constant.int 7 |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "sign_bit" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "value_bytes" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let num_bytes_prepend := BinOp.sub (| Constant.int 32, diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/bitwise.v b/CoqOfPython/ethereum/byzantium/vm/instructions/bitwise.v index f38e7aa..e7643c3 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/bitwise.v @@ -21,21 +21,21 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.byzantium.vm.__init__. +Axiom ethereum_byzantium_vm___init___Evm : + IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.byzantium.vm.gas. +Axiom ethereum_byzantium_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_byzantium_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "charge_gas". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.byzantium.vm.stack. +Axiom ethereum_byzantium_vm_stack_pop : + IsGlobalAlias globals ethereum.byzantium.vm.stack.globals "pop". +Axiom ethereum_byzantium_vm_stack_push : + IsGlobalAlias globals ethereum.byzantium.vm.stack.globals "push". Definition bitwise_and : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -285,6 +285,25 @@ Definition get_byte : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "byte_index" |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let extra_bytes_to_right := BinOp.sub (| Constant.int 31, diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/block.v b/CoqOfPython/ethereum/byzantium/vm/instructions/block.v index 90be45c..d25412d 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/block.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/block.v @@ -21,23 +21,23 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_BLOCK_HASH : - IsGlobalAlias globals gas.globals "GAS_BLOCK_HASH". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.byzantium.vm.__init__. +Axiom ethereum_byzantium_vm___init___Evm : + IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Evm". + +Require ethereum.byzantium.vm.gas. +Axiom ethereum_byzantium_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_BASE". +Axiom ethereum_byzantium_vm_gas_GAS_BLOCK_HASH : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_BLOCK_HASH". +Axiom ethereum_byzantium_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "charge_gas". + +Require ethereum.byzantium.vm.stack. +Axiom ethereum_byzantium_vm_stack_pop : + IsGlobalAlias globals ethereum.byzantium.vm.stack.globals "pop". +Axiom ethereum_byzantium_vm_stack_push : + IsGlobalAlias globals ethereum.byzantium.vm.stack.globals "push". Definition block_hash : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -69,6 +69,30 @@ Definition block_hash : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt_e (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + M.get_name (| globals, "block_number" |) + |), + ltac:(M.monadic ( + Compare.gt (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + BinOp.add (| + M.get_name (| globals, "block_number" |), + Constant.int 256 + |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let hash := + Constant.bytes "00" in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let hash := M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/comparison.v b/CoqOfPython/ethereum/byzantium/vm/instructions/comparison.v index b8529d8..1f88ba2 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/comparison.v @@ -21,21 +21,21 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.byzantium.vm.__init__. +Axiom ethereum_byzantium_vm___init___Evm : + IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.byzantium.vm.gas. +Axiom ethereum_byzantium_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_byzantium_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "charge_gas". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.byzantium.vm.stack. +Axiom ethereum_byzantium_vm_stack_pop : + IsGlobalAlias globals ethereum.byzantium.vm.stack.globals "pop". +Axiom ethereum_byzantium_vm_stack_push : + IsGlobalAlias globals ethereum.byzantium.vm.stack.globals "push". Definition less_than : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/control_flow.v b/CoqOfPython/ethereum/byzantium/vm/instructions/control_flow.v index d4e4eae..ced2b03 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/control_flow.v @@ -23,31 +23,31 @@ Axiom ethereum_base_types_U256 : Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require vm.gas. -Axiom vm_gas_GAS_BASE : - IsGlobalAlias globals vm.gas.globals "GAS_BASE". -Axiom vm_gas_GAS_HIGH : - IsGlobalAlias globals vm.gas.globals "GAS_HIGH". -Axiom vm_gas_GAS_JUMPDEST : - IsGlobalAlias globals vm.gas.globals "GAS_JUMPDEST". -Axiom vm_gas_GAS_MID : - IsGlobalAlias globals vm.gas.globals "GAS_MID". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.byzantium.vm.gas. +Axiom ethereum_byzantium_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_BASE". +Axiom ethereum_byzantium_vm_gas_GAS_HIGH : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_HIGH". +Axiom ethereum_byzantium_vm_gas_GAS_JUMPDEST : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_JUMPDEST". +Axiom ethereum_byzantium_vm_gas_GAS_MID : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_MID". +Axiom ethereum_byzantium_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "charge_gas". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.byzantium.vm.__init__. +Axiom ethereum_byzantium_vm___init___Evm : + IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Evm". -Require exceptions. -Axiom exceptions_InvalidJumpDestError : - IsGlobalAlias globals exceptions.globals "InvalidJumpDestError". +Require ethereum.byzantium.vm.exceptions. +Axiom ethereum_byzantium_vm_exceptions_InvalidJumpDestError : + IsGlobalAlias globals ethereum.byzantium.vm.exceptions.globals "InvalidJumpDestError". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.byzantium.vm.stack. +Axiom ethereum_byzantium_vm_stack_pop : + IsGlobalAlias globals ethereum.byzantium.vm.stack.globals "pop". +Axiom ethereum_byzantium_vm_stack_push : + IsGlobalAlias globals ethereum.byzantium.vm.stack.globals "push". Definition stop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -109,6 +109,18 @@ Definition jump : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "jump_dest" |), + M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -168,7 +180,35 @@ Definition jumpi : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "conditional_value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let destination := + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "jump_dest" |), + M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let destination := M.get_name (| globals, "jump_dest" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/environment.v b/CoqOfPython/ethereum/byzantium/vm/instructions/environment.v index 78c9e52..9b8a11f 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/environment.v @@ -31,51 +31,51 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require state. -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". +Require ethereum.byzantium.state. +Axiom ethereum_byzantium_state_get_account : + IsGlobalAlias globals ethereum.byzantium.state.globals "get_account". -Require utils.address. -Axiom utils_address_to_address : - IsGlobalAlias globals utils.address.globals "to_address". +Require ethereum.byzantium.utils.address. +Axiom ethereum_byzantium_utils_address_to_address : + IsGlobalAlias globals ethereum.byzantium.utils.address.globals "to_address". -Require vm.memory. -Axiom vm_memory_buffer_read : - IsGlobalAlias globals vm.memory.globals "buffer_read". -Axiom vm_memory_memory_write : - IsGlobalAlias globals vm.memory.globals "memory_write". +Require ethereum.byzantium.vm.memory. +Axiom ethereum_byzantium_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.byzantium.vm.memory.globals "buffer_read". +Axiom ethereum_byzantium_vm_memory_memory_write : + IsGlobalAlias globals ethereum.byzantium.vm.memory.globals "memory_write". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.byzantium.vm.__init__. +Axiom ethereum_byzantium_vm___init___Evm : + IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Evm". -Require exceptions. -Axiom exceptions_OutOfBoundsRead : - IsGlobalAlias globals exceptions.globals "OutOfBoundsRead". +Require ethereum.byzantium.vm.exceptions. +Axiom ethereum_byzantium_vm_exceptions_OutOfBoundsRead : + IsGlobalAlias globals ethereum.byzantium.vm.exceptions.globals "OutOfBoundsRead". -Require gas. -Axiom gas_GAS_BALANCE : - IsGlobalAlias globals gas.globals "GAS_BALANCE". -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_COPY : - IsGlobalAlias globals gas.globals "GAS_COPY". -Axiom gas_GAS_EXTERNAL : - IsGlobalAlias globals gas.globals "GAS_EXTERNAL". -Axiom gas_GAS_RETURN_DATA_COPY : - IsGlobalAlias globals gas.globals "GAS_RETURN_DATA_COPY". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.byzantium.vm.gas. +Axiom ethereum_byzantium_vm_gas_GAS_BALANCE : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_BALANCE". +Axiom ethereum_byzantium_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_BASE". +Axiom ethereum_byzantium_vm_gas_GAS_COPY : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_COPY". +Axiom ethereum_byzantium_vm_gas_GAS_EXTERNAL : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_EXTERNAL". +Axiom ethereum_byzantium_vm_gas_GAS_RETURN_DATA_COPY : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_RETURN_DATA_COPY". +Axiom ethereum_byzantium_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_byzantium_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_byzantium_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "charge_gas". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.byzantium.vm.stack. +Axiom ethereum_byzantium_vm_stack_pop : + IsGlobalAlias globals ethereum.byzantium.vm.stack.globals "pop". +Axiom ethereum_byzantium_vm_stack_push : + IsGlobalAlias globals ethereum.byzantium.vm.stack.globals "push". Definition address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -1122,7 +1122,10 @@ Definition returndatacopy : Value.t -> Value.t -> M := |) |) in let value := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |) |) in + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.slice (| M.get_name (| globals, "return_data_start_position" |), BinOp.add (| + M.get_name (| globals, "return_data_start_position" |), + M.get_name (| globals, "size" |) + |) |) |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/keccak.v b/CoqOfPython/ethereum/byzantium/vm/instructions/keccak.v index 2c4b10e..a9e0538 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/keccak.v @@ -31,29 +31,29 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_KECCAK256 : - IsGlobalAlias globals gas.globals "GAS_KECCAK256". -Axiom gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.byzantium.vm.__init__. +Axiom ethereum_byzantium_vm___init___Evm : + IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Evm". + +Require ethereum.byzantium.vm.gas. +Axiom ethereum_byzantium_vm_gas_GAS_KECCAK256 : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_KECCAK256". +Axiom ethereum_byzantium_vm_gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_KECCAK256_WORD". +Axiom ethereum_byzantium_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_byzantium_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "charge_gas". + +Require ethereum.byzantium.vm.memory. +Axiom ethereum_byzantium_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.byzantium.vm.memory.globals "memory_read_bytes". + +Require ethereum.byzantium.vm.stack. +Axiom ethereum_byzantium_vm_stack_pop : + IsGlobalAlias globals ethereum.byzantium.vm.stack.globals "pop". +Axiom ethereum_byzantium_vm_stack_push : + IsGlobalAlias globals ethereum.byzantium.vm.stack.globals "push". Definition keccak : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/log.v b/CoqOfPython/ethereum/byzantium/vm/instructions/log.v index e084e59..7783692 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/log.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/log.v @@ -29,37 +29,37 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". - -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require exceptions. -Axiom exceptions_WriteInStaticContext : - IsGlobalAlias globals exceptions.globals "WriteInStaticContext". - -Require gas. -Axiom gas_GAS_LOG : - IsGlobalAlias globals gas.globals "GAS_LOG". -Axiom gas_GAS_LOG_DATA : - IsGlobalAlias globals gas.globals "GAS_LOG_DATA". -Axiom gas_GAS_LOG_TOPIC : - IsGlobalAlias globals gas.globals "GAS_LOG_TOPIC". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". +Require ethereum.byzantium.blocks. +Axiom ethereum_byzantium_blocks_Log : + IsGlobalAlias globals ethereum.byzantium.blocks.globals "Log". + +Require ethereum.byzantium.vm.__init__. +Axiom ethereum_byzantium_vm___init___Evm : + IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Evm". + +Require ethereum.byzantium.vm.exceptions. +Axiom ethereum_byzantium_vm_exceptions_WriteInStaticContext : + IsGlobalAlias globals ethereum.byzantium.vm.exceptions.globals "WriteInStaticContext". + +Require ethereum.byzantium.vm.gas. +Axiom ethereum_byzantium_vm_gas_GAS_LOG : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_LOG". +Axiom ethereum_byzantium_vm_gas_GAS_LOG_DATA : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_LOG_DATA". +Axiom ethereum_byzantium_vm_gas_GAS_LOG_TOPIC : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_LOG_TOPIC". +Axiom ethereum_byzantium_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_byzantium_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "charge_gas". + +Require ethereum.byzantium.vm.memory. +Axiom ethereum_byzantium_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.byzantium.vm.memory.globals "memory_read_bytes". + +Require ethereum.byzantium.vm.stack. +Axiom ethereum_byzantium_vm_stack_pop : + IsGlobalAlias globals ethereum.byzantium.vm.stack.globals "pop". Definition log_n : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/memory.v b/CoqOfPython/ethereum/byzantium/vm/instructions/memory.v index 86ba742..f2f5a5d 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/memory.v @@ -23,31 +23,31 @@ Axiom ethereum_base_types_U256 : Axiom ethereum_base_types_Bytes : IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.byzantium.vm.__init__. +Axiom ethereum_byzantium_vm___init___Evm : + IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.byzantium.vm.gas. +Axiom ethereum_byzantium_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_BASE". +Axiom ethereum_byzantium_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_byzantium_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_byzantium_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "charge_gas". -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". -Axiom memory_memory_write : - IsGlobalAlias globals memory.globals "memory_write". +Require ethereum.byzantium.vm.memory. +Axiom ethereum_byzantium_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.byzantium.vm.memory.globals "memory_read_bytes". +Axiom ethereum_byzantium_vm_memory_memory_write : + IsGlobalAlias globals ethereum.byzantium.vm.memory.globals "memory_write". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.byzantium.vm.stack. +Axiom ethereum_byzantium_vm_stack_pop : + IsGlobalAlias globals ethereum.byzantium.vm.stack.globals "pop". +Axiom ethereum_byzantium_vm_stack_push : + IsGlobalAlias globals ethereum.byzantium.vm.stack.globals "push". Definition mstore : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/stack.v b/CoqOfPython/ethereum/byzantium/vm/instructions/stack.v index 305af15..f9eec4b 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/stack.v @@ -29,27 +29,27 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". -Axiom __init___stack : - IsGlobalAlias globals __init__.globals "stack". - -Require exceptions. -Axiom exceptions_StackUnderflowError : - IsGlobalAlias globals exceptions.globals "StackUnderflowError". - -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require memory. -Axiom memory_buffer_read : - IsGlobalAlias globals memory.globals "buffer_read". +Require ethereum.byzantium.vm.__init__. +Axiom ethereum_byzantium_vm___init___Evm : + IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Evm". +Axiom ethereum_byzantium_vm___init___stack : + IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "stack". + +Require ethereum.byzantium.vm.exceptions. +Axiom ethereum_byzantium_vm_exceptions_StackUnderflowError : + IsGlobalAlias globals ethereum.byzantium.vm.exceptions.globals "StackUnderflowError". + +Require ethereum.byzantium.vm.gas. +Axiom ethereum_byzantium_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_BASE". +Axiom ethereum_byzantium_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_byzantium_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "charge_gas". + +Require ethereum.byzantium.vm.memory. +Axiom ethereum_byzantium_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.byzantium.vm.memory.globals "buffer_read". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/storage.v b/CoqOfPython/ethereum/byzantium/vm/instructions/storage.v index fe33724..9055a0d 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/storage.v @@ -21,37 +21,37 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require state. -Axiom state_get_storage : - IsGlobalAlias globals state.globals "get_storage". -Axiom state_set_storage : - IsGlobalAlias globals state.globals "set_storage". - -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require exceptions. -Axiom exceptions_WriteInStaticContext : - IsGlobalAlias globals exceptions.globals "WriteInStaticContext". - -Require gas. -Axiom gas_GAS_SLOAD : - IsGlobalAlias globals gas.globals "GAS_SLOAD". -Axiom gas_GAS_STORAGE_CLEAR_REFUND : - IsGlobalAlias globals gas.globals "GAS_STORAGE_CLEAR_REFUND". -Axiom gas_GAS_STORAGE_SET : - IsGlobalAlias globals gas.globals "GAS_STORAGE_SET". -Axiom gas_GAS_STORAGE_UPDATE : - IsGlobalAlias globals gas.globals "GAS_STORAGE_UPDATE". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.byzantium.state. +Axiom ethereum_byzantium_state_get_storage : + IsGlobalAlias globals ethereum.byzantium.state.globals "get_storage". +Axiom ethereum_byzantium_state_set_storage : + IsGlobalAlias globals ethereum.byzantium.state.globals "set_storage". + +Require ethereum.byzantium.vm.__init__. +Axiom ethereum_byzantium_vm___init___Evm : + IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Evm". + +Require ethereum.byzantium.vm.exceptions. +Axiom ethereum_byzantium_vm_exceptions_WriteInStaticContext : + IsGlobalAlias globals ethereum.byzantium.vm.exceptions.globals "WriteInStaticContext". + +Require ethereum.byzantium.vm.gas. +Axiom ethereum_byzantium_vm_gas_GAS_SLOAD : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_SLOAD". +Axiom ethereum_byzantium_vm_gas_GAS_STORAGE_CLEAR_REFUND : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_STORAGE_CLEAR_REFUND". +Axiom ethereum_byzantium_vm_gas_GAS_STORAGE_SET : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_STORAGE_SET". +Axiom ethereum_byzantium_vm_gas_GAS_STORAGE_UPDATE : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_STORAGE_UPDATE". +Axiom ethereum_byzantium_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "charge_gas". + +Require ethereum.byzantium.vm.stack. +Axiom ethereum_byzantium_vm_stack_pop : + IsGlobalAlias globals ethereum.byzantium.vm.stack.globals "pop". +Axiom ethereum_byzantium_vm_stack_push : + IsGlobalAlias globals ethereum.byzantium.vm.stack.globals "push". Definition sload : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -154,11 +154,56 @@ Definition sstore : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "new_value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "current_value" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let gas_cost := + M.get_name (| globals, "GAS_STORAGE_SET" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let gas_cost := M.get_name (| globals, "GAS_STORAGE_UPDATE" |) in M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_name (| globals, "new_value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "current_value" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/system.v b/CoqOfPython/ethereum/byzantium/vm/instructions/system.v index 013dec0..e48ab33 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/system.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/system.v @@ -29,83 +29,83 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.byzantium.fork_types. +Axiom ethereum_byzantium_fork_types_Address : + IsGlobalAlias globals ethereum.byzantium.fork_types.globals "Address". -Require state. -Axiom state_account_exists_and_is_empty : - IsGlobalAlias globals state.globals "account_exists_and_is_empty". -Axiom state_account_has_code_or_nonce : - IsGlobalAlias globals state.globals "account_has_code_or_nonce". -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". -Axiom state_increment_nonce : - IsGlobalAlias globals state.globals "increment_nonce". -Axiom state_is_account_alive : - IsGlobalAlias globals state.globals "is_account_alive". -Axiom state_set_account_balance : - IsGlobalAlias globals state.globals "set_account_balance". +Require ethereum.byzantium.state. +Axiom ethereum_byzantium_state_account_exists_and_is_empty : + IsGlobalAlias globals ethereum.byzantium.state.globals "account_exists_and_is_empty". +Axiom ethereum_byzantium_state_account_has_code_or_nonce : + IsGlobalAlias globals ethereum.byzantium.state.globals "account_has_code_or_nonce". +Axiom ethereum_byzantium_state_get_account : + IsGlobalAlias globals ethereum.byzantium.state.globals "get_account". +Axiom ethereum_byzantium_state_increment_nonce : + IsGlobalAlias globals ethereum.byzantium.state.globals "increment_nonce". +Axiom ethereum_byzantium_state_is_account_alive : + IsGlobalAlias globals ethereum.byzantium.state.globals "is_account_alive". +Axiom ethereum_byzantium_state_set_account_balance : + IsGlobalAlias globals ethereum.byzantium.state.globals "set_account_balance". -Require utils.address. -Axiom utils_address_compute_contract_address : - IsGlobalAlias globals utils.address.globals "compute_contract_address". -Axiom utils_address_to_address : - IsGlobalAlias globals utils.address.globals "to_address". +Require ethereum.byzantium.utils.address. +Axiom ethereum_byzantium_utils_address_compute_contract_address : + IsGlobalAlias globals ethereum.byzantium.utils.address.globals "compute_contract_address". +Axiom ethereum_byzantium_utils_address_to_address : + IsGlobalAlias globals ethereum.byzantium.utils.address.globals "to_address". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". -Axiom __init___Message : - IsGlobalAlias globals __init__.globals "Message". -Axiom __init___incorporate_child_on_error : - IsGlobalAlias globals __init__.globals "incorporate_child_on_error". -Axiom __init___incorporate_child_on_success : - IsGlobalAlias globals __init__.globals "incorporate_child_on_success". +Require ethereum.byzantium.vm.__init__. +Axiom ethereum_byzantium_vm___init___Evm : + IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Evm". +Axiom ethereum_byzantium_vm___init___Message : + IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Message". +Axiom ethereum_byzantium_vm___init___incorporate_child_on_error : + IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "incorporate_child_on_error". +Axiom ethereum_byzantium_vm___init___incorporate_child_on_success : + IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "incorporate_child_on_success". -Require exceptions. -Axiom exceptions_Revert : - IsGlobalAlias globals exceptions.globals "Revert". -Axiom exceptions_WriteInStaticContext : - IsGlobalAlias globals exceptions.globals "WriteInStaticContext". +Require ethereum.byzantium.vm.exceptions. +Axiom ethereum_byzantium_vm_exceptions_Revert : + IsGlobalAlias globals ethereum.byzantium.vm.exceptions.globals "Revert". +Axiom ethereum_byzantium_vm_exceptions_WriteInStaticContext : + IsGlobalAlias globals ethereum.byzantium.vm.exceptions.globals "WriteInStaticContext". -Require gas. -Axiom gas_GAS_CALL : - IsGlobalAlias globals gas.globals "GAS_CALL". -Axiom gas_GAS_CALL_VALUE : - IsGlobalAlias globals gas.globals "GAS_CALL_VALUE". -Axiom gas_GAS_CREATE : - IsGlobalAlias globals gas.globals "GAS_CREATE". -Axiom gas_GAS_NEW_ACCOUNT : - IsGlobalAlias globals gas.globals "GAS_NEW_ACCOUNT". -Axiom gas_GAS_SELF_DESTRUCT : - IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT". -Axiom gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : - IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". -Axiom gas_GAS_ZERO : - IsGlobalAlias globals gas.globals "GAS_ZERO". -Axiom gas_REFUND_SELF_DESTRUCT : - IsGlobalAlias globals gas.globals "REFUND_SELF_DESTRUCT". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_calculate_message_call_gas : - IsGlobalAlias globals gas.globals "calculate_message_call_gas". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". -Axiom gas_max_message_call_gas : - IsGlobalAlias globals gas.globals "max_message_call_gas". +Require ethereum.byzantium.vm.gas. +Axiom ethereum_byzantium_vm_gas_GAS_CALL : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_CALL". +Axiom ethereum_byzantium_vm_gas_GAS_CALL_VALUE : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_CALL_VALUE". +Axiom ethereum_byzantium_vm_gas_GAS_CREATE : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_CREATE". +Axiom ethereum_byzantium_vm_gas_GAS_NEW_ACCOUNT : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_NEW_ACCOUNT". +Axiom ethereum_byzantium_vm_gas_GAS_SELF_DESTRUCT : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_SELF_DESTRUCT". +Axiom ethereum_byzantium_vm_gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". +Axiom ethereum_byzantium_vm_gas_GAS_ZERO : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_ZERO". +Axiom ethereum_byzantium_vm_gas_REFUND_SELF_DESTRUCT : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "REFUND_SELF_DESTRUCT". +Axiom ethereum_byzantium_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_byzantium_vm_gas_calculate_message_call_gas : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "calculate_message_call_gas". +Axiom ethereum_byzantium_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "charge_gas". +Axiom ethereum_byzantium_vm_gas_max_message_call_gas : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "max_message_call_gas". -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". -Axiom memory_memory_write : - IsGlobalAlias globals memory.globals "memory_write". +Require ethereum.byzantium.vm.memory. +Axiom ethereum_byzantium_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.byzantium.vm.memory.globals "memory_read_bytes". +Axiom ethereum_byzantium_vm_memory_memory_write : + IsGlobalAlias globals ethereum.byzantium.vm.memory.globals "memory_write". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.byzantium.vm.stack. +Axiom ethereum_byzantium_vm_stack_pop : + IsGlobalAlias globals ethereum.byzantium.vm.stack.globals "pop". +Axiom ethereum_byzantium_vm_stack_push : + IsGlobalAlias globals ethereum.byzantium.vm.stack.globals "push". Definition create : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -232,7 +232,105 @@ Definition create : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt (| + M.get_field (| M.get_name (| globals, "sender" |), "balance" |), + M.get_name (| globals, "endowment" |) + |), + ltac:(M.monadic ( + BoolOp.or (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "sender" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.sub (| + BinOp.pow (| + Constant.int 2, + Constant.int 64 + |), + Constant.int 1 + |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.gt (| + BinOp.add (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "depth" |), + Constant.int 1 + |), + M.get_name (| globals, "STACK_DEPTH_LIMIT" |) + |) + )) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "create_message_gas" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "contract_address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let call_data := M.call (| M.get_name (| globals, "memory_read_bytes" |), @@ -267,6 +365,40 @@ Definition create : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "child_evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_error" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "incorporate_child_on_success" |), make_list [ @@ -394,6 +526,42 @@ Definition generic_call : Value.t -> Value.t -> M := Constant.bytes "" |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + BinOp.add (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "depth" |), + Constant.int 1 + |), + M.get_name (| globals, "STACK_DEPTH_LIMIT" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "gas" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let call_data := @@ -431,6 +599,40 @@ Definition generic_call : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "child_evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_error" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "incorporate_child_on_success" |), make_list [ @@ -485,7 +687,7 @@ Definition generic_call : Value.t -> Value.t -> M := make_list [ M.get_field (| M.get_name (| globals, "evm" |), "memory" |); M.get_name (| globals, "memory_output_start_position" |); - M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), Constant.None_:M.get_name (| globals, "actual_output_size" |) |) + M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), M.slice (| Constant.None_, M.get_name (| globals, "actual_output_size" |) |) |) ], make_dict [] |) in @@ -583,49 +785,57 @@ Definition call : Value.t -> Value.t -> M := make_dict [] |) in let create_gas_cost := - (* if *) -M.if_then_else (| - BoolOp.or (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), - ltac:(M.monadic ( - M.call (| - M.get_name (| globals, "is_account_alive" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); - M.get_name (| globals, "to" |) - ], - make_dict [] - |) - )) - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "is_account_alive" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "to" |) + ], + make_dict [] + |) + )) + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "GAS_NEW_ACCOUNT" |) + )) |) in let transfer_gas_cost := - (* if *) -M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "GAS_CALL_VALUE" |) + )) |) in let message_call_gas := M.call (| M.get_name (| globals, "calculate_message_call_gas" |), @@ -701,6 +911,40 @@ M.call (| make_dict [] |), "balance" |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "sender_balance" |), + M.get_name (| globals, "value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "generic_call" |), make_list [ @@ -822,21 +1066,25 @@ Definition callcode : Value.t -> Value.t -> M := make_dict [] |) in let transfer_gas_cost := - (* if *) -M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "GAS_CALL_VALUE" |) + )) |) in let message_call_gas := M.call (| M.get_name (| globals, "calculate_message_call_gas" |), @@ -887,6 +1135,40 @@ M.call (| make_dict [] |), "balance" |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "sender_balance" |), + M.get_name (| globals, "value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "generic_call" |), make_list [ @@ -942,6 +1224,39 @@ Definition selfdestruct : Value.t -> Value.t -> M := let gas_cost := M.get_name (| globals, "GAS_SELF_DESTRUCT" |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + UnOp.not (| M.call (| + M.get_name (| globals, "is_account_alive" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) + M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let originator := @@ -965,6 +1280,22 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in EndWhile. let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "originator" |), + M.get_name (| globals, "refunded_accounts" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.get_name (| globals, "REFUND_SELF_DESTRUCT" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -1036,6 +1367,28 @@ Definition selfdestruct : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -1427,6 +1780,6 @@ Definition revert : Value.t -> Value.t -> M := make_dict [] |) |) in - let _ := M.raise (| Some(M.get_name (| globals, "Revert" |)) + let _ := M.raise (| Some(M.get_name (| globals, "Revert" |)) |) in let _ := M.pass (| |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/vm/interpreter.v b/CoqOfPython/ethereum/byzantium/vm/interpreter.v index 252f4e7..0ee8639 100644 --- a/CoqOfPython/ethereum/byzantium/vm/interpreter.v +++ b/CoqOfPython/ethereum/byzantium/vm/interpreter.v @@ -61,79 +61,79 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". - -Require state. -Axiom state_account_exists_and_is_empty : - IsGlobalAlias globals state.globals "account_exists_and_is_empty". -Axiom state_account_has_code_or_nonce : - IsGlobalAlias globals state.globals "account_has_code_or_nonce". -Axiom state_begin_transaction : - IsGlobalAlias globals state.globals "begin_transaction". -Axiom state_commit_transaction : - IsGlobalAlias globals state.globals "commit_transaction". -Axiom state_destroy_storage : - IsGlobalAlias globals state.globals "destroy_storage". -Axiom state_increment_nonce : - IsGlobalAlias globals state.globals "increment_nonce". -Axiom state_move_ether : - IsGlobalAlias globals state.globals "move_ether". -Axiom state_rollback_transaction : - IsGlobalAlias globals state.globals "rollback_transaction". -Axiom state_set_code : - IsGlobalAlias globals state.globals "set_code". -Axiom state_touch_account : - IsGlobalAlias globals state.globals "touch_account". - -Require vm. -Axiom vm_Message : - IsGlobalAlias globals vm.globals "Message". - -Require vm.gas. -Axiom vm_gas_GAS_CODE_DEPOSIT : - IsGlobalAlias globals vm.gas.globals "GAS_CODE_DEPOSIT". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". - -Require vm.precompiled_contracts.mapping. -Axiom vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : - IsGlobalAlias globals vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". - -Require __init__. -Axiom __init___Environment : - IsGlobalAlias globals __init__.globals "Environment". -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require exceptions. -Axiom exceptions_AddressCollision : - IsGlobalAlias globals exceptions.globals "AddressCollision". -Axiom exceptions_ExceptionalHalt : - IsGlobalAlias globals exceptions.globals "ExceptionalHalt". -Axiom exceptions_InvalidOpcode : - IsGlobalAlias globals exceptions.globals "InvalidOpcode". -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". -Axiom exceptions_Revert : - IsGlobalAlias globals exceptions.globals "Revert". -Axiom exceptions_StackDepthLimitError : - IsGlobalAlias globals exceptions.globals "StackDepthLimitError". - -Require instructions. -Axiom instructions_Ops : - IsGlobalAlias globals instructions.globals "Ops". -Axiom instructions_op_implementation : - IsGlobalAlias globals instructions.globals "op_implementation". - -Require runtime. -Axiom runtime_get_valid_jump_destinations : - IsGlobalAlias globals runtime.globals "get_valid_jump_destinations". +Require ethereum.byzantium.blocks. +Axiom ethereum_byzantium_blocks_Log : + IsGlobalAlias globals ethereum.byzantium.blocks.globals "Log". + +Require ethereum.byzantium.fork_types. +Axiom ethereum_byzantium_fork_types_Address : + IsGlobalAlias globals ethereum.byzantium.fork_types.globals "Address". + +Require ethereum.byzantium.state. +Axiom ethereum_byzantium_state_account_exists_and_is_empty : + IsGlobalAlias globals ethereum.byzantium.state.globals "account_exists_and_is_empty". +Axiom ethereum_byzantium_state_account_has_code_or_nonce : + IsGlobalAlias globals ethereum.byzantium.state.globals "account_has_code_or_nonce". +Axiom ethereum_byzantium_state_begin_transaction : + IsGlobalAlias globals ethereum.byzantium.state.globals "begin_transaction". +Axiom ethereum_byzantium_state_commit_transaction : + IsGlobalAlias globals ethereum.byzantium.state.globals "commit_transaction". +Axiom ethereum_byzantium_state_destroy_storage : + IsGlobalAlias globals ethereum.byzantium.state.globals "destroy_storage". +Axiom ethereum_byzantium_state_increment_nonce : + IsGlobalAlias globals ethereum.byzantium.state.globals "increment_nonce". +Axiom ethereum_byzantium_state_move_ether : + IsGlobalAlias globals ethereum.byzantium.state.globals "move_ether". +Axiom ethereum_byzantium_state_rollback_transaction : + IsGlobalAlias globals ethereum.byzantium.state.globals "rollback_transaction". +Axiom ethereum_byzantium_state_set_code : + IsGlobalAlias globals ethereum.byzantium.state.globals "set_code". +Axiom ethereum_byzantium_state_touch_account : + IsGlobalAlias globals ethereum.byzantium.state.globals "touch_account". + +Require ethereum.byzantium.vm.__init__. +Axiom ethereum_byzantium_vm___init___Message : + IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Message". + +Require ethereum.byzantium.vm.gas. +Axiom ethereum_byzantium_vm_gas_GAS_CODE_DEPOSIT : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_CODE_DEPOSIT". +Axiom ethereum_byzantium_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "charge_gas". + +Require ethereum.byzantium.vm.precompiled_contracts.mapping. +Axiom ethereum_byzantium_vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : + IsGlobalAlias globals ethereum.byzantium.vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". + +Require ethereum.byzantium.vm.__init__. +Axiom ethereum_byzantium_vm___init___Environment : + IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Environment". +Axiom ethereum_byzantium_vm___init___Evm : + IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Evm". + +Require ethereum.byzantium.vm.exceptions. +Axiom ethereum_byzantium_vm_exceptions_AddressCollision : + IsGlobalAlias globals ethereum.byzantium.vm.exceptions.globals "AddressCollision". +Axiom ethereum_byzantium_vm_exceptions_ExceptionalHalt : + IsGlobalAlias globals ethereum.byzantium.vm.exceptions.globals "ExceptionalHalt". +Axiom ethereum_byzantium_vm_exceptions_InvalidOpcode : + IsGlobalAlias globals ethereum.byzantium.vm.exceptions.globals "InvalidOpcode". +Axiom ethereum_byzantium_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.byzantium.vm.exceptions.globals "OutOfGasError". +Axiom ethereum_byzantium_vm_exceptions_Revert : + IsGlobalAlias globals ethereum.byzantium.vm.exceptions.globals "Revert". +Axiom ethereum_byzantium_vm_exceptions_StackDepthLimitError : + IsGlobalAlias globals ethereum.byzantium.vm.exceptions.globals "StackDepthLimitError". + +Require ethereum.byzantium.vm.instructions.__init__. +Axiom ethereum_byzantium_vm_instructions___init___Ops : + IsGlobalAlias globals ethereum.byzantium.vm.instructions.__init__.globals "Ops". +Axiom ethereum_byzantium_vm_instructions___init___op_implementation : + IsGlobalAlias globals ethereum.byzantium.vm.instructions.__init__.globals "op_implementation". + +Require ethereum.byzantium.vm.runtime. +Axiom ethereum_byzantium_vm_runtime_get_valid_jump_destinations : + IsGlobalAlias globals ethereum.byzantium.vm.runtime.globals "get_valid_jump_destinations". Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -180,6 +180,94 @@ Definition process_message_call : Value.t -> Value.t -> M := Output of the message call " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "message" |), "target" |), + M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) + |), + (* then *) + ltac:(M.monadic ( + let is_collision := + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_name (| globals, "is_collision" |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallOutput" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "tuple" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "AddressCollision" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let evm := + M.call (| + M.get_name (| globals, "process_create_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let evm := M.call (| M.get_name (| globals, "process_message" |), @@ -190,11 +278,74 @@ Definition process_message_call : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_field (| M.get_name (| globals, "message" |), "target" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_field (| M.get_name (| globals, "message" |), "target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( +(* At stmt: unsupported node type: AnnAssign *) + let accounts_to_delete := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let touched_accounts := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let refund_counter := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let logs := M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in let accounts_to_delete := @@ -232,6 +383,7 @@ Definition process_message_call : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). Definition process_create_message : Value.t -> Value.t -> M := @@ -285,6 +437,28 @@ Definition process_create_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), + (* then *) + ltac:(M.monadic ( + let contract_code := + M.get_field (| M.get_name (| globals, "evm" |), "output" |) in + let contract_code_gas := + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "contract_code" |) + ], + make_dict [] + |), + M.get_name (| globals, "GAS_CODE_DEPOSIT" |) + |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "rollback_transaction" |), make_list [ @@ -296,6 +470,7 @@ Definition process_create_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) + |) in M.pure Constant.None_)). Definition process_message : Value.t -> Value.t -> M := @@ -317,6 +492,24 @@ Definition process_message : Value.t -> Value.t -> M := Items containing execution specific objects " in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_field (| M.get_name (| globals, "message" |), "depth" |), + M.get_name (| globals, "STACK_DEPTH_LIMIT" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "StackDepthLimitError" |), + make_list [ + Constant.str "Stack depth limit reached" + ], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -335,6 +528,32 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + M.get_field (| M.get_name (| globals, "message" |), "should_transfer_value" |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "message" |), "value" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "move_ether" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "caller" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |); + M.get_field (| M.get_name (| globals, "message" |), "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let evm := @@ -347,6 +566,21 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "rollback_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "commit_transaction" |), make_list [ @@ -358,6 +592,7 @@ Definition process_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) + |) in M.pure Constant.None_)). Definition execute_code : Value.t -> Value.t -> M := @@ -397,4 +632,5 @@ Definition execute_code : Value.t -> Value.t -> M := (* At stmt: unsupported node type: Try *) let _ := M.return_ (| M.get_name (| globals, "evm" |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/vm/memory.v b/CoqOfPython/ethereum/byzantium/vm/memory.v index 4b107fd..08d2290 100644 --- a/CoqOfPython/ethereum/byzantium/vm/memory.v +++ b/CoqOfPython/ethereum/byzantium/vm/memory.v @@ -21,13 +21,13 @@ Require ethereum.utils.byte. Axiom ethereum_utils_byte_right_pad_zero_bytes : IsGlobalAlias globals ethereum.utils.byte.globals "right_pad_zero_bytes". -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". Definition memory_write : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,7 +45,22 @@ Definition memory_write : Value.t -> Value.t -> M := Data to write to memory. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |), + M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) |) |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_)). @@ -71,7 +86,23 @@ Definition memory_read_bytes : Value.t -> Value.t -> M := Data read from memory. " in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |) + M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |) |) + |) in M.pure Constant.None_)). Definition buffer_read : Value.t -> Value.t -> M := @@ -98,9 +129,25 @@ Definition buffer_read : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "right_pad_zero_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |) |); + M.get_subscript (| M.get_name (| globals, "buffer" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |) |); M.get_name (| globals, "size" |) ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/__init__.v index 0210a12..070b8b2 100644 --- a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/__init__.v +++ b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/__init__.v @@ -18,9 +18,9 @@ Addresses of precompiled contracts and mappings to their implementations. ". -Require utils.hexadecimal. -Axiom utils_hexadecimal_hex_to_address : - IsGlobalAlias globals utils.hexadecimal.globals "hex_to_address". +Require ethereum.byzantium.utils.hexadecimal. +Axiom ethereum_byzantium_utils_hexadecimal_hex_to_address : + IsGlobalAlias globals ethereum.byzantium.utils.hexadecimal.globals "hex_to_address". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS"; Constant.str "MODEXP_ADDRESS"; Constant.str "ALT_BN128_ADD_ADDRESS"; Constant.str "ALT_BN128_MUL_ADDRESS"; Constant.str "ALT_BN128_PAIRING_CHECK_ADDRESS"; Constant.str "BLAKE2F_ADDRESS" ] diff --git a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/alt_bn128.v index 90f245d..c07bb35 100644 --- a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/alt_bn128.v +++ b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/alt_bn128.v @@ -45,21 +45,21 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.byzantium.vm.__init__. +Axiom ethereum_byzantium_vm___init___Evm : + IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.byzantium.vm.gas. +Axiom ethereum_byzantium_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "charge_gas". -Require vm.memory. -Axiom vm_memory_buffer_read : - IsGlobalAlias globals vm.memory.globals "buffer_read". +Require ethereum.byzantium.vm.memory. +Axiom ethereum_byzantium_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.byzantium.vm.memory.globals "buffer_read". -Require exceptions. -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". +Require ethereum.byzantium.vm.exceptions. +Axiom ethereum_byzantium_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.byzantium.vm.exceptions.globals "OutOfGasError". Definition alt_bn128_add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -210,6 +210,18 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) in For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ] do let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -353,6 +365,18 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) in For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ] do let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -425,6 +449,27 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| + BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 192 + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let result := @@ -464,7 +509,7 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "data" |), BinOp.add (| + M.get_subscript (| M.get_name (| globals, "data" |), M.slice (| BinOp.add (| BinOp.mult (| M.get_name (| globals, "i" |), Constant.int 192 @@ -473,11 +518,35 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := Constant.int 32, M.get_name (| globals, "j" |) |) - |) |) + |), BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "j" |), + Constant.int 1 + |) + |) + |) |) |) ], make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -538,10 +607,80 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "p" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "q" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let result := + BinOp.mult (| + M.get_name (| globals, "result" |), + M.call (| + M.get_name (| globals, "pairing" |), + make_list [ + M.get_name (| globals, "q" |); + M.get_name (| globals, "p" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "result" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| diff --git a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/ecrecover.v index 0cbcf16..347014f 100644 --- a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/ecrecover.v @@ -37,19 +37,19 @@ Require ethereum.utils.byte. Axiom ethereum_utils_byte_left_pad_zero_bytes : IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.byzantium.vm.__init__. +Axiom ethereum_byzantium_vm___init___Evm : + IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_ECRECOVER : - IsGlobalAlias globals vm.gas.globals "GAS_ECRECOVER". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.byzantium.vm.gas. +Axiom ethereum_byzantium_vm_gas_GAS_ECRECOVER : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_ECRECOVER". +Axiom ethereum_byzantium_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "charge_gas". -Require vm.memory. -Axiom vm_memory_buffer_read : - IsGlobalAlias globals vm.memory.globals "buffer_read". +Require ethereum.byzantium.vm.memory. +Axiom ethereum_byzantium_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.byzantium.vm.memory.globals "buffer_read". Definition ecrecover : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -188,12 +188,78 @@ Definition ecrecover : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "v" |), + Constant.int 27 + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "v" |), + Constant.int 28 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + Constant.int 0, + M.get_name (| globals, "r" |) + |), + ltac:(M.monadic ( + Compare.gt_e (| + M.get_name (| globals, "r" |), + M.get_name (| globals, "SECP256K1N" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + Constant.int 0, + M.get_name (| globals, "s" |) + |), + ltac:(M.monadic ( + Compare.gt_e (| + M.get_name (| globals, "s" |), + M.get_name (| globals, "SECP256K1N" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: Try *) @@ -204,7 +270,7 @@ Definition ecrecover : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12 |) in + |), M.slice (| Constant.int 12, Constant.int 32 |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/identity.v index fa96704..6601ede 100644 --- a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/identity.v +++ b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/identity.v @@ -25,17 +25,17 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.byzantium.vm.__init__. +Axiom ethereum_byzantium_vm___init___Evm : + IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_IDENTITY : - IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY". -Axiom vm_gas_GAS_IDENTITY_WORD : - IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY_WORD". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.byzantium.vm.gas. +Axiom ethereum_byzantium_vm_gas_GAS_IDENTITY : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_IDENTITY". +Axiom ethereum_byzantium_vm_gas_GAS_IDENTITY_WORD : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_IDENTITY_WORD". +Axiom ethereum_byzantium_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "charge_gas". Definition identity : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/mapping.v index b1a0ed3..4f7ca92 100644 --- a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/mapping.v +++ b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/mapping.v @@ -23,54 +23,54 @@ Axiom typing_Callable : Axiom typing_Dict : IsGlobalAlias globals typing.globals "Dict". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.byzantium.fork_types. +Axiom ethereum_byzantium_fork_types_Address : + IsGlobalAlias globals ethereum.byzantium.fork_types.globals "Address". -Require __init__. -Axiom __init___ALT_BN128_ADD_ADDRESS : - IsGlobalAlias globals __init__.globals "ALT_BN128_ADD_ADDRESS". -Axiom __init___ALT_BN128_MUL_ADDRESS : - IsGlobalAlias globals __init__.globals "ALT_BN128_MUL_ADDRESS". -Axiom __init___ALT_BN128_PAIRING_CHECK_ADDRESS : - IsGlobalAlias globals __init__.globals "ALT_BN128_PAIRING_CHECK_ADDRESS". -Axiom __init___ECRECOVER_ADDRESS : - IsGlobalAlias globals __init__.globals "ECRECOVER_ADDRESS". -Axiom __init___IDENTITY_ADDRESS : - IsGlobalAlias globals __init__.globals "IDENTITY_ADDRESS". -Axiom __init___MODEXP_ADDRESS : - IsGlobalAlias globals __init__.globals "MODEXP_ADDRESS". -Axiom __init___RIPEMD160_ADDRESS : - IsGlobalAlias globals __init__.globals "RIPEMD160_ADDRESS". -Axiom __init___SHA256_ADDRESS : - IsGlobalAlias globals __init__.globals "SHA256_ADDRESS". +Require ethereum.byzantium.vm.precompiled_contracts.__init__. +Axiom ethereum_byzantium_vm_precompiled_contracts___init___ALT_BN128_ADD_ADDRESS : + IsGlobalAlias globals ethereum.byzantium.vm.precompiled_contracts.__init__.globals "ALT_BN128_ADD_ADDRESS". +Axiom ethereum_byzantium_vm_precompiled_contracts___init___ALT_BN128_MUL_ADDRESS : + IsGlobalAlias globals ethereum.byzantium.vm.precompiled_contracts.__init__.globals "ALT_BN128_MUL_ADDRESS". +Axiom ethereum_byzantium_vm_precompiled_contracts___init___ALT_BN128_PAIRING_CHECK_ADDRESS : + IsGlobalAlias globals ethereum.byzantium.vm.precompiled_contracts.__init__.globals "ALT_BN128_PAIRING_CHECK_ADDRESS". +Axiom ethereum_byzantium_vm_precompiled_contracts___init___ECRECOVER_ADDRESS : + IsGlobalAlias globals ethereum.byzantium.vm.precompiled_contracts.__init__.globals "ECRECOVER_ADDRESS". +Axiom ethereum_byzantium_vm_precompiled_contracts___init___IDENTITY_ADDRESS : + IsGlobalAlias globals ethereum.byzantium.vm.precompiled_contracts.__init__.globals "IDENTITY_ADDRESS". +Axiom ethereum_byzantium_vm_precompiled_contracts___init___MODEXP_ADDRESS : + IsGlobalAlias globals ethereum.byzantium.vm.precompiled_contracts.__init__.globals "MODEXP_ADDRESS". +Axiom ethereum_byzantium_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : + IsGlobalAlias globals ethereum.byzantium.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". +Axiom ethereum_byzantium_vm_precompiled_contracts___init___SHA256_ADDRESS : + IsGlobalAlias globals ethereum.byzantium.vm.precompiled_contracts.__init__.globals "SHA256_ADDRESS". -Require alt_bn128. -Axiom alt_bn128_alt_bn128_add : - IsGlobalAlias globals alt_bn128.globals "alt_bn128_add". -Axiom alt_bn128_alt_bn128_mul : - IsGlobalAlias globals alt_bn128.globals "alt_bn128_mul". -Axiom alt_bn128_alt_bn128_pairing_check : - IsGlobalAlias globals alt_bn128.globals "alt_bn128_pairing_check". +Require ethereum.byzantium.vm.precompiled_contracts.alt_bn128. +Axiom ethereum_byzantium_vm_precompiled_contracts_alt_bn128_alt_bn128_add : + IsGlobalAlias globals ethereum.byzantium.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_add". +Axiom ethereum_byzantium_vm_precompiled_contracts_alt_bn128_alt_bn128_mul : + IsGlobalAlias globals ethereum.byzantium.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_mul". +Axiom ethereum_byzantium_vm_precompiled_contracts_alt_bn128_alt_bn128_pairing_check : + IsGlobalAlias globals ethereum.byzantium.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_pairing_check". -Require ecrecover. -Axiom ecrecover_ecrecover : - IsGlobalAlias globals ecrecover.globals "ecrecover". +Require ethereum.byzantium.vm.precompiled_contracts.ecrecover. +Axiom ethereum_byzantium_vm_precompiled_contracts_ecrecover_ecrecover : + IsGlobalAlias globals ethereum.byzantium.vm.precompiled_contracts.ecrecover.globals "ecrecover". -Require identity. -Axiom identity_identity : - IsGlobalAlias globals identity.globals "identity". +Require ethereum.byzantium.vm.precompiled_contracts.identity. +Axiom ethereum_byzantium_vm_precompiled_contracts_identity_identity : + IsGlobalAlias globals ethereum.byzantium.vm.precompiled_contracts.identity.globals "identity". -Require modexp. -Axiom modexp_modexp : - IsGlobalAlias globals modexp.globals "modexp". +Require ethereum.byzantium.vm.precompiled_contracts.modexp. +Axiom ethereum_byzantium_vm_precompiled_contracts_modexp_modexp : + IsGlobalAlias globals ethereum.byzantium.vm.precompiled_contracts.modexp.globals "modexp". -Require ripemd160. -Axiom ripemd160_ripemd160 : - IsGlobalAlias globals ripemd160.globals "ripemd160". +Require ethereum.byzantium.vm.precompiled_contracts.ripemd160. +Axiom ethereum_byzantium_vm_precompiled_contracts_ripemd160_ripemd160 : + IsGlobalAlias globals ethereum.byzantium.vm.precompiled_contracts.ripemd160.globals "ripemd160". -Require sha256. -Axiom sha256_sha256 : - IsGlobalAlias globals sha256.globals "sha256". +Require ethereum.byzantium.vm.precompiled_contracts.sha256. +Axiom ethereum_byzantium_vm_precompiled_contracts_sha256_sha256 : + IsGlobalAlias globals ethereum.byzantium.vm.precompiled_contracts.sha256.globals "sha256". (* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/modexp.v index aff5b85..b67c04e 100644 --- a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/modexp.v +++ b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/modexp.v @@ -25,17 +25,17 @@ Axiom ethereum_base_types_Bytes : Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.byzantium.vm.__init__. +Axiom ethereum_byzantium_vm___init___Evm : + IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.byzantium.vm.gas. +Axiom ethereum_byzantium_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "charge_gas". -Require memory. -Axiom memory_buffer_read : - IsGlobalAlias globals memory.globals "buffer_read". +Require ethereum.byzantium.vm.memory. +Axiom ethereum_byzantium_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.byzantium.vm.memory.globals "buffer_read". Definition GQUADDIVISOR : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -181,6 +181,39 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "exp_length" |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let adjusted_exp_length := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "max" |), + make_list [ + Constant.int 0; + BinOp.sub (| + M.call (| + M.get_field (| M.get_name (| globals, "exp_head" |), "bit_length" |), + make_list [], + make_dict [] + |), + Constant.int 1 + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let adjusted_exp_length := M.call (| M.get_name (| globals, "Uint" |), @@ -267,6 +300,36 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_name (| globals, "base_length" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "modulus_length" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [], + make_dict [] + |) + |) in + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let base := @@ -329,6 +392,30 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "modulus" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + BinOp.mult (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + Constant.bytes "00" + ], + make_dict [] + |), + M.get_name (| globals, "modulus_length" |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| @@ -365,7 +452,53 @@ Definition get_mult_complexity : Value.t -> Value.t -> M := Estimate the complexity of performing Karatsuba multiplication. " in let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "x" |), + Constant.int 64 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.pow (| + M.get_name (| globals, "x" |), + Constant.int 2 + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "x" |), + Constant.int 1024 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.sub (| + BinOp.add (| + BinOp.floor_div (| + BinOp.pow (| + M.get_name (| globals, "x" |), + Constant.int 2 + |), + Constant.int 4 + |), + BinOp.mult (| + Constant.int 96, + M.get_name (| globals, "x" |) + |) + |), + Constant.int 3072 + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| BinOp.sub (| BinOp.add (| @@ -383,6 +516,7 @@ Definition get_mult_complexity : Value.t -> Value.t -> M := |), Constant.int 199680 |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/ripemd160.v index 96f8dcd..ca3ec8b 100644 --- a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/ripemd160.v +++ b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/ripemd160.v @@ -31,17 +31,17 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.byzantium.vm.__init__. +Axiom ethereum_byzantium_vm___init___Evm : + IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_RIPEMD160 : - IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160". -Axiom vm_gas_GAS_RIPEMD160_WORD : - IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160_WORD". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.byzantium.vm.gas. +Axiom ethereum_byzantium_vm_gas_GAS_RIPEMD160 : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_RIPEMD160". +Axiom ethereum_byzantium_vm_gas_GAS_RIPEMD160_WORD : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_RIPEMD160_WORD". +Axiom ethereum_byzantium_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "charge_gas". Definition ripemd160 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/sha256.v index 9f6d2bf..ddcccf9 100644 --- a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/sha256.v +++ b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/sha256.v @@ -27,17 +27,17 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.byzantium.vm.__init__. +Axiom ethereum_byzantium_vm___init___Evm : + IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_SHA256 : - IsGlobalAlias globals vm.gas.globals "GAS_SHA256". -Axiom vm_gas_GAS_SHA256_WORD : - IsGlobalAlias globals vm.gas.globals "GAS_SHA256_WORD". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.byzantium.vm.gas. +Axiom ethereum_byzantium_vm_gas_GAS_SHA256 : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_SHA256". +Axiom ethereum_byzantium_vm_gas_GAS_SHA256_WORD : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_SHA256_WORD". +Axiom ethereum_byzantium_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "charge_gas". Definition sha256 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/byzantium/vm/runtime.v b/CoqOfPython/ethereum/byzantium/vm/runtime.v index 2cd7652..b3b5055 100644 --- a/CoqOfPython/ethereum/byzantium/vm/runtime.v +++ b/CoqOfPython/ethereum/byzantium/vm/runtime.v @@ -25,9 +25,9 @@ Require ethereum.base_types. Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require instructions. -Axiom instructions_Ops : - IsGlobalAlias globals instructions.globals "Ops". +Require ethereum.byzantium.vm.instructions.__init__. +Axiom ethereum_byzantium_vm_instructions___init___Ops : + IsGlobalAlias globals ethereum.byzantium.vm.instructions.__init__.globals "Ops". Definition get_valid_jump_destinations : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -79,7 +79,55 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := |) do (* At stmt: unsupported node type: Try *) let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "current_opcode" |), + M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), + make_list [ + M.get_name (| globals, "pc" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.lt_e (| + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |), + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH32" |), "value" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let push_data_size := + BinOp.add (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) + |), + Constant.int 1 + |) in + let pc := BinOp.add + M.get_name (| globals, "push_data_size" |) + M.get_name (| globals, "push_data_size" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -90,4 +138,5 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := EndWhile. let _ := M.return_ (| M.get_name (| globals, "valid_jump_destinations" |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/vm/stack.v b/CoqOfPython/ethereum/byzantium/vm/stack.v index ea778df..c6bc41e 100644 --- a/CoqOfPython/ethereum/byzantium/vm/stack.v +++ b/CoqOfPython/ethereum/byzantium/vm/stack.v @@ -25,11 +25,11 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require exceptions. -Axiom exceptions_StackOverflowError : - IsGlobalAlias globals exceptions.globals "StackOverflowError". -Axiom exceptions_StackUnderflowError : - IsGlobalAlias globals exceptions.globals "StackUnderflowError". +Require ethereum.byzantium.vm.exceptions. +Axiom ethereum_byzantium_vm_exceptions_StackOverflowError : + IsGlobalAlias globals ethereum.byzantium.vm.exceptions.globals "StackOverflowError". +Axiom ethereum_byzantium_vm_exceptions_StackUnderflowError : + IsGlobalAlias globals ethereum.byzantium.vm.exceptions.globals "StackUnderflowError". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -49,6 +49,24 @@ Definition pop : Value.t -> Value.t -> M := " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "StackUnderflowError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -57,6 +75,7 @@ Definition pop : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). Definition push : Value.t -> Value.t -> M := @@ -75,6 +94,24 @@ Definition push : Value.t -> Value.t -> M := " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), + Constant.int 1024 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "StackOverflowError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -85,4 +122,5 @@ Definition push : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/blocks.v b/CoqOfPython/ethereum/cancun/blocks.v index 2130667..d5c5e90 100644 --- a/CoqOfPython/ethereum/cancun/blocks.v +++ b/CoqOfPython/ethereum/cancun/blocks.v @@ -24,37 +24,37 @@ Axiom typing_Tuple : Axiom typing_Union : IsGlobalAlias globals typing.globals "Union". -Require base_types. -Axiom base_types_U64 : - IsGlobalAlias globals base_types.globals "U64". -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes8 : - IsGlobalAlias globals base_types.globals "Bytes8". -Axiom base_types_Bytes32 : - IsGlobalAlias globals base_types.globals "Bytes32". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require crypto.hash. -Axiom crypto_hash_Hash32 : - IsGlobalAlias globals crypto.hash.globals "Hash32". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". - -Require transactions. -Axiom transactions_LegacyTransaction : - IsGlobalAlias globals transactions.globals "LegacyTransaction". +Require ethereum.base_types. +Axiom ethereum_base_types_U64 : + IsGlobalAlias globals ethereum.base_types.globals "U64". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes8 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes8". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". + +Require ethereum.cancun.fork_types. +Axiom ethereum_cancun_fork_types_Address : + IsGlobalAlias globals ethereum.cancun.fork_types.globals "Address". +Axiom ethereum_cancun_fork_types_Bloom : + IsGlobalAlias globals ethereum.cancun.fork_types.globals "Bloom". +Axiom ethereum_cancun_fork_types_Root : + IsGlobalAlias globals ethereum.cancun.fork_types.globals "Root". + +Require ethereum.cancun.transactions. +Axiom ethereum_cancun_transactions_LegacyTransaction : + IsGlobalAlias globals ethereum.cancun.transactions.globals "LegacyTransaction". Definition Withdrawal : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/cancun/bloom.v b/CoqOfPython/ethereum/cancun/bloom.v index 04650ff..a9df591 100644 --- a/CoqOfPython/ethereum/cancun/bloom.v +++ b/CoqOfPython/ethereum/cancun/bloom.v @@ -33,13 +33,13 @@ Require ethereum.crypto.hash. Axiom ethereum_crypto_hash_keccak256 : IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". +Require ethereum.cancun.blocks. +Axiom ethereum_cancun_blocks_Log : + IsGlobalAlias globals ethereum.cancun.blocks.globals "Log". -Require fork_types. -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". +Require ethereum.cancun.fork_types. +Axiom ethereum_cancun_fork_types_Bloom : + IsGlobalAlias globals ethereum.cancun.fork_types.globals "Bloom". Definition add_to_bloom : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -72,7 +72,10 @@ Definition add_to_bloom : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |) |) + M.get_subscript (| M.get_name (| globals, "hash" |), M.slice (| M.get_name (| globals, "idx" |), BinOp.add (| + M.get_name (| globals, "idx" |), + Constant.int 2 + |) |) |) ], make_dict [] |), @@ -157,4 +160,5 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/fork.v b/CoqOfPython/ethereum/cancun/fork.v index 1611eac..2dd9a95 100644 --- a/CoqOfPython/ethereum/cancun/fork.v +++ b/CoqOfPython/ethereum/cancun/fork.v @@ -57,137 +57,137 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U64 : - IsGlobalAlias globals base_types.globals "U64". -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". - -Require __init__. -Axiom __init___vm : - IsGlobalAlias globals __init__.globals "vm". - -Require blocks. -Axiom blocks_Block : - IsGlobalAlias globals blocks.globals "Block". -Axiom blocks_Header : - IsGlobalAlias globals blocks.globals "Header". -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". -Axiom blocks_Receipt : - IsGlobalAlias globals blocks.globals "Receipt". -Axiom blocks_Withdrawal : - IsGlobalAlias globals blocks.globals "Withdrawal". - -Require bloom. -Axiom bloom_logs_bloom : - IsGlobalAlias globals bloom.globals "logs_bloom". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". -Axiom fork_types_VersionedHash : - IsGlobalAlias globals fork_types.globals "VersionedHash". - -Require state. -Axiom state_State : - IsGlobalAlias globals state.globals "State". -Axiom state_TransientStorage : - IsGlobalAlias globals state.globals "TransientStorage". -Axiom state_account_exists_and_is_empty : - IsGlobalAlias globals state.globals "account_exists_and_is_empty". -Axiom state_destroy_account : - IsGlobalAlias globals state.globals "destroy_account". -Axiom state_destroy_touched_empty_accounts : - IsGlobalAlias globals state.globals "destroy_touched_empty_accounts". -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". -Axiom state_increment_nonce : - IsGlobalAlias globals state.globals "increment_nonce". -Axiom state_process_withdrawal : - IsGlobalAlias globals state.globals "process_withdrawal". -Axiom state_set_account_balance : - IsGlobalAlias globals state.globals "set_account_balance". -Axiom state_state_root : - IsGlobalAlias globals state.globals "state_root". - -Require transactions. -Axiom transactions_TX_ACCESS_LIST_ADDRESS_COST : - IsGlobalAlias globals transactions.globals "TX_ACCESS_LIST_ADDRESS_COST". -Axiom transactions_TX_ACCESS_LIST_STORAGE_KEY_COST : - IsGlobalAlias globals transactions.globals "TX_ACCESS_LIST_STORAGE_KEY_COST". -Axiom transactions_TX_BASE_COST : - IsGlobalAlias globals transactions.globals "TX_BASE_COST". -Axiom transactions_TX_CREATE_COST : - IsGlobalAlias globals transactions.globals "TX_CREATE_COST". -Axiom transactions_TX_DATA_COST_PER_NON_ZERO : - IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_NON_ZERO". -Axiom transactions_TX_DATA_COST_PER_ZERO : - IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_ZERO". -Axiom transactions_AccessListTransaction : - IsGlobalAlias globals transactions.globals "AccessListTransaction". -Axiom transactions_BlobTransaction : - IsGlobalAlias globals transactions.globals "BlobTransaction". -Axiom transactions_FeeMarketTransaction : - IsGlobalAlias globals transactions.globals "FeeMarketTransaction". -Axiom transactions_LegacyTransaction : - IsGlobalAlias globals transactions.globals "LegacyTransaction". -Axiom transactions_Transaction : - IsGlobalAlias globals transactions.globals "Transaction". -Axiom transactions_decode_transaction : - IsGlobalAlias globals transactions.globals "decode_transaction". -Axiom transactions_encode_transaction : - IsGlobalAlias globals transactions.globals "encode_transaction". - -Require trie. -Axiom trie_Trie : - IsGlobalAlias globals trie.globals "Trie". -Axiom trie_root : - IsGlobalAlias globals trie.globals "root". -Axiom trie_trie_set : - IsGlobalAlias globals trie.globals "trie_set". - -Require utils.hexadecimal. -Axiom utils_hexadecimal_hex_to_address : - IsGlobalAlias globals utils.hexadecimal.globals "hex_to_address". - -Require utils.message. -Axiom utils_message_prepare_message : - IsGlobalAlias globals utils.message.globals "prepare_message". - -Require vm. -Axiom vm_Message : - IsGlobalAlias globals vm.globals "Message". - -Require vm.gas. -Axiom vm_gas_calculate_blob_gas_price : - IsGlobalAlias globals vm.gas.globals "calculate_blob_gas_price". -Axiom vm_gas_calculate_data_fee : - IsGlobalAlias globals vm.gas.globals "calculate_data_fee". -Axiom vm_gas_calculate_excess_blob_gas : - IsGlobalAlias globals vm.gas.globals "calculate_excess_blob_gas". -Axiom vm_gas_calculate_total_blob_gas : - IsGlobalAlias globals vm.gas.globals "calculate_total_blob_gas". -Axiom vm_gas_init_code_cost : - IsGlobalAlias globals vm.gas.globals "init_code_cost". - -Require vm.interpreter. -Axiom vm_interpreter_MAX_CODE_SIZE : - IsGlobalAlias globals vm.interpreter.globals "MAX_CODE_SIZE". -Axiom vm_interpreter_process_message_call : - IsGlobalAlias globals vm.interpreter.globals "process_message_call". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U64 : + IsGlobalAlias globals ethereum.base_types.globals "U64". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.cancun.__init__. +Axiom ethereum_cancun___init___vm : + IsGlobalAlias globals ethereum.cancun.__init__.globals "vm". + +Require ethereum.cancun.blocks. +Axiom ethereum_cancun_blocks_Block : + IsGlobalAlias globals ethereum.cancun.blocks.globals "Block". +Axiom ethereum_cancun_blocks_Header : + IsGlobalAlias globals ethereum.cancun.blocks.globals "Header". +Axiom ethereum_cancun_blocks_Log : + IsGlobalAlias globals ethereum.cancun.blocks.globals "Log". +Axiom ethereum_cancun_blocks_Receipt : + IsGlobalAlias globals ethereum.cancun.blocks.globals "Receipt". +Axiom ethereum_cancun_blocks_Withdrawal : + IsGlobalAlias globals ethereum.cancun.blocks.globals "Withdrawal". + +Require ethereum.cancun.bloom. +Axiom ethereum_cancun_bloom_logs_bloom : + IsGlobalAlias globals ethereum.cancun.bloom.globals "logs_bloom". + +Require ethereum.cancun.fork_types. +Axiom ethereum_cancun_fork_types_Address : + IsGlobalAlias globals ethereum.cancun.fork_types.globals "Address". +Axiom ethereum_cancun_fork_types_Bloom : + IsGlobalAlias globals ethereum.cancun.fork_types.globals "Bloom". +Axiom ethereum_cancun_fork_types_Root : + IsGlobalAlias globals ethereum.cancun.fork_types.globals "Root". +Axiom ethereum_cancun_fork_types_VersionedHash : + IsGlobalAlias globals ethereum.cancun.fork_types.globals "VersionedHash". + +Require ethereum.cancun.state. +Axiom ethereum_cancun_state_State : + IsGlobalAlias globals ethereum.cancun.state.globals "State". +Axiom ethereum_cancun_state_TransientStorage : + IsGlobalAlias globals ethereum.cancun.state.globals "TransientStorage". +Axiom ethereum_cancun_state_account_exists_and_is_empty : + IsGlobalAlias globals ethereum.cancun.state.globals "account_exists_and_is_empty". +Axiom ethereum_cancun_state_destroy_account : + IsGlobalAlias globals ethereum.cancun.state.globals "destroy_account". +Axiom ethereum_cancun_state_destroy_touched_empty_accounts : + IsGlobalAlias globals ethereum.cancun.state.globals "destroy_touched_empty_accounts". +Axiom ethereum_cancun_state_get_account : + IsGlobalAlias globals ethereum.cancun.state.globals "get_account". +Axiom ethereum_cancun_state_increment_nonce : + IsGlobalAlias globals ethereum.cancun.state.globals "increment_nonce". +Axiom ethereum_cancun_state_process_withdrawal : + IsGlobalAlias globals ethereum.cancun.state.globals "process_withdrawal". +Axiom ethereum_cancun_state_set_account_balance : + IsGlobalAlias globals ethereum.cancun.state.globals "set_account_balance". +Axiom ethereum_cancun_state_state_root : + IsGlobalAlias globals ethereum.cancun.state.globals "state_root". + +Require ethereum.cancun.transactions. +Axiom ethereum_cancun_transactions_TX_ACCESS_LIST_ADDRESS_COST : + IsGlobalAlias globals ethereum.cancun.transactions.globals "TX_ACCESS_LIST_ADDRESS_COST". +Axiom ethereum_cancun_transactions_TX_ACCESS_LIST_STORAGE_KEY_COST : + IsGlobalAlias globals ethereum.cancun.transactions.globals "TX_ACCESS_LIST_STORAGE_KEY_COST". +Axiom ethereum_cancun_transactions_TX_BASE_COST : + IsGlobalAlias globals ethereum.cancun.transactions.globals "TX_BASE_COST". +Axiom ethereum_cancun_transactions_TX_CREATE_COST : + IsGlobalAlias globals ethereum.cancun.transactions.globals "TX_CREATE_COST". +Axiom ethereum_cancun_transactions_TX_DATA_COST_PER_NON_ZERO : + IsGlobalAlias globals ethereum.cancun.transactions.globals "TX_DATA_COST_PER_NON_ZERO". +Axiom ethereum_cancun_transactions_TX_DATA_COST_PER_ZERO : + IsGlobalAlias globals ethereum.cancun.transactions.globals "TX_DATA_COST_PER_ZERO". +Axiom ethereum_cancun_transactions_AccessListTransaction : + IsGlobalAlias globals ethereum.cancun.transactions.globals "AccessListTransaction". +Axiom ethereum_cancun_transactions_BlobTransaction : + IsGlobalAlias globals ethereum.cancun.transactions.globals "BlobTransaction". +Axiom ethereum_cancun_transactions_FeeMarketTransaction : + IsGlobalAlias globals ethereum.cancun.transactions.globals "FeeMarketTransaction". +Axiom ethereum_cancun_transactions_LegacyTransaction : + IsGlobalAlias globals ethereum.cancun.transactions.globals "LegacyTransaction". +Axiom ethereum_cancun_transactions_Transaction : + IsGlobalAlias globals ethereum.cancun.transactions.globals "Transaction". +Axiom ethereum_cancun_transactions_decode_transaction : + IsGlobalAlias globals ethereum.cancun.transactions.globals "decode_transaction". +Axiom ethereum_cancun_transactions_encode_transaction : + IsGlobalAlias globals ethereum.cancun.transactions.globals "encode_transaction". + +Require ethereum.cancun.trie. +Axiom ethereum_cancun_trie_Trie : + IsGlobalAlias globals ethereum.cancun.trie.globals "Trie". +Axiom ethereum_cancun_trie_root : + IsGlobalAlias globals ethereum.cancun.trie.globals "root". +Axiom ethereum_cancun_trie_trie_set : + IsGlobalAlias globals ethereum.cancun.trie.globals "trie_set". + +Require ethereum.cancun.utils.hexadecimal. +Axiom ethereum_cancun_utils_hexadecimal_hex_to_address : + IsGlobalAlias globals ethereum.cancun.utils.hexadecimal.globals "hex_to_address". + +Require ethereum.cancun.utils.message. +Axiom ethereum_cancun_utils_message_prepare_message : + IsGlobalAlias globals ethereum.cancun.utils.message.globals "prepare_message". + +Require ethereum.cancun.vm.__init__. +Axiom ethereum_cancun_vm___init___Message : + IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Message". + +Require ethereum.cancun.vm.gas. +Axiom ethereum_cancun_vm_gas_calculate_blob_gas_price : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "calculate_blob_gas_price". +Axiom ethereum_cancun_vm_gas_calculate_data_fee : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "calculate_data_fee". +Axiom ethereum_cancun_vm_gas_calculate_excess_blob_gas : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "calculate_excess_blob_gas". +Axiom ethereum_cancun_vm_gas_calculate_total_blob_gas : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "calculate_total_blob_gas". +Axiom ethereum_cancun_vm_gas_init_code_cost : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "init_code_cost". + +Require ethereum.cancun.vm.interpreter. +Axiom ethereum_cancun_vm_interpreter_MAX_CODE_SIZE : + IsGlobalAlias globals ethereum.cancun.vm.interpreter.globals "MAX_CODE_SIZE". +Axiom ethereum_cancun_vm_interpreter_process_message_call : + IsGlobalAlias globals ethereum.cancun.vm.interpreter.globals "process_message_call". Definition BASE_FEE_MAX_CHANGE_DENOMINATOR : Value.t := M.run ltac:(M.monadic ( Constant.int 8 @@ -292,6 +292,7 @@ Definition apply_fork : Value.t -> Value.t -> M := " in let _ := M.return_ (| M.get_name (| globals, "old" |) + |) in M.pure Constant.None_)). Definition get_last_256_block_hashes : Value.t -> Value.t -> M := @@ -317,8 +318,28 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := Hashes of the recent 256 blocks in order of increasing block number. " in let recent_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |) |) in + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "recent_blocks" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + make_list [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let recent_block_hashes := @@ -357,6 +378,7 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "recent_block_hashes" |) + |) in M.pure Constant.None_)). Definition state_transition : Value.t -> Value.t -> M := @@ -534,6 +556,27 @@ Definition state_transition : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |) + ], + make_dict [] + |), + Constant.int 255 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -581,7 +624,63 @@ Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "parent_gas_used" |), + M.get_name (| globals, "parent_gas_target" |) + |), + (* then *) + ltac:(M.monadic ( + let expected_base_fee_per_gas := + M.get_name (| globals, "parent_base_fee_per_gas" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "parent_gas_used" |), + M.get_name (| globals, "parent_gas_target" |) + |), + (* then *) + ltac:(M.monadic ( + let gas_used_delta := + BinOp.sub (| + M.get_name (| globals, "parent_gas_used" |), + M.get_name (| globals, "parent_gas_target" |) + |) in + let parent_fee_gas_delta := + BinOp.mult (| + M.get_name (| globals, "parent_base_fee_per_gas" |), + M.get_name (| globals, "gas_used_delta" |) + |) in + let target_fee_gas_delta := + BinOp.floor_div (| + M.get_name (| globals, "parent_fee_gas_delta" |), + M.get_name (| globals, "parent_gas_target" |) + |) in + let base_fee_per_gas_delta := + M.call (| + M.get_name (| globals, "max" |), + make_list [ + BinOp.floor_div (| + M.get_name (| globals, "target_fee_gas_delta" |), + M.get_name (| globals, "BASE_FEE_MAX_CHANGE_DENOMINATOR" |) + |); + Constant.int 1 + ], + make_dict [] + |) in + let expected_base_fee_per_gas := + BinOp.add (| + M.get_name (| globals, "parent_base_fee_per_gas" |), + M.get_name (| globals, "base_fee_per_gas_delta" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let gas_used_delta := BinOp.sub (| M.get_name (| globals, "parent_gas_target" |), @@ -619,6 +718,7 @@ Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition validate_header : Value.t -> Value.t -> M := @@ -812,15 +912,98 @@ Definition check_transaction : Value.t -> Value.t -> M := If the transaction is not includable. " in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.call (| + M.get_name (| globals, "calculate_intrinsic_cost" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |), + M.get_field (| M.get_name (| globals, "tx" |), "gas" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidBlock" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_field (| M.get_name (| globals, "tx" |), "nonce" |), + BinOp.sub (| + BinOp.pow (| + Constant.int 2, + Constant.int 64 + |), + Constant.int 1 + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidBlock" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "tx" |), "to" |), + M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.gt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "tx" |), "data" |) + ], + make_dict [] + |), + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "MAX_CODE_SIZE" |) + |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidBlock" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_name (| globals, "gas_available" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidBlock" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let sender := @@ -842,7 +1025,86 @@ Definition check_transaction : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + make_tuple [ M.get_name (| globals, "FeeMarketTransaction" |); M.get_name (| globals, "BlobTransaction" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |), + M.get_field (| M.get_name (| globals, "tx" |), "max_priority_fee_per_gas" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidBlock" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |), + M.get_name (| globals, "base_fee_per_gas" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidBlock" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let priority_fee_per_gas := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_field (| M.get_name (| globals, "tx" |), "max_priority_fee_per_gas" |); + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |), + M.get_name (| globals, "base_fee_per_gas" |) + |) + ], + make_dict [] + |) in + let effective_gas_price := + BinOp.add (| + M.get_name (| globals, "priority_fee_per_gas" |), + M.get_name (| globals, "base_fee_per_gas" |) + |) in + let max_gas_fee := + BinOp.mult (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |), + M.get_name (| globals, "base_fee_per_gas" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidBlock" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let effective_gas_price := @@ -855,6 +1117,122 @@ Definition check_transaction : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "BlobTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_field (| M.get_name (| globals, "tx" |), "to" |); + M.get_name (| globals, "Address" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidBlock" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "tx" |), "blob_versioned_hashes" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidBlock" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + For M.get_name (| globals, "blob_versioned_hash" |) in M.get_field (| M.get_name (| globals, "tx" |), "blob_versioned_hashes" |) do + let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| + M.get_subscript (| M.get_name (| globals, "blob_versioned_hash" |), M.slice (| Constant.int 0, Constant.int 1 |) |), + M.get_name (| globals, "VERSIONED_HASH_VERSION_KZG" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidBlock" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + EndFor. + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_blob_gas" |), + M.call (| + M.get_name (| globals, "calculate_blob_gas_price" |), + make_list [ + M.get_name (| globals, "excess_blob_gas" |) + ], + make_dict [] + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidBlock" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let max_gas_fee := BinOp.add + BinOp.mult (| + M.call (| + M.get_name (| globals, "calculate_total_blob_gas" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |), + M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_blob_gas" |) + |) + BinOp.mult (| + M.call (| + M.get_name (| globals, "calculate_total_blob_gas" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |), + M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_blob_gas" |) + |) in + let blob_versioned_hashes := + M.get_field (| M.get_name (| globals, "tx" |), "blob_versioned_hashes" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let blob_versioned_hashes := make_tuple [ ] in M.pure Constant.None_ @@ -901,6 +1279,7 @@ Definition check_transaction : Value.t -> Value.t -> M := |) in let _ := M.return_ (| make_tuple [ M.get_name (| globals, "sender" |); M.get_name (| globals, "effective_gas_price" |); M.get_name (| globals, "blob_versioned_hashes" |) ] + |) in M.pure Constant.None_)). Definition make_receipt : Value.t -> Value.t -> M := @@ -933,10 +1312,92 @@ Definition make_receipt : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "AccessListTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + Constant.bytes "01", + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "receipt" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "FeeMarketTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + Constant.bytes "02", + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "receipt" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "BlobTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + Constant.bytes "03", + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "receipt" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "receipt" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -1255,6 +1716,29 @@ Definition apply_body : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_field (| M.get_name (| globals, "wd" |), "address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_field (| M.get_name (| globals, "wd" |), "address" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -1296,6 +1780,7 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition process_transaction : Value.t -> Value.t -> M := @@ -1339,6 +1824,30 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "BlobTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let blob_gas_fee := + M.call (| + M.get_name (| globals, "calculate_data_fee" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "excess_blob_gas" |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let blob_gas_fee := M.call (| M.get_name (| globals, "Uint" |), @@ -1410,6 +1919,39 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + make_tuple [ M.get_name (| globals, "AccessListTransaction" |); M.get_name (| globals, "FeeMarketTransaction" |); M.get_name (| globals, "BlobTransaction" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + For make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "keys" |) ] in M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "preaccessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "key" |) in M.get_name (| globals, "keys" |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "preaccessed_storage_keys" |), "add" |), + make_list [ + make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "key" |) ] + ], + make_dict [] + |) in + EndFor. + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let message := @@ -1514,7 +2056,50 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "transaction_fee" |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| + M.get_name (| globals, "coinbase_balance_after_mining_fee" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |); + M.get_name (| globals, "coinbase_balance_after_mining_fee" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -1539,6 +2124,7 @@ Definition process_transaction : Value.t -> Value.t -> M := |) in let _ := M.return_ (| make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |); M.get_field (| M.get_name (| globals, "output" |), "error" |) ] + |) in M.pure Constant.None_)). Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := @@ -1570,6 +2156,20 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := Constant.int 0 in For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "byte" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let data_cost := BinOp.add M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in @@ -1577,6 +2177,52 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := )) |) in EndFor. let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "tx" |), "to" |), + M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) + |), + (* then *) + ltac:(M.monadic ( + let create_cost := + BinOp.add (| + M.get_name (| globals, "TX_CREATE_COST" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.call (| + M.get_name (| globals, "init_code_cost" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "tx" |), "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let create_cost := Constant.int 0 in M.pure Constant.None_ @@ -1584,6 +2230,47 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := let access_list_cost := Constant.int 0 in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + make_tuple [ M.get_name (| globals, "AccessListTransaction" |); M.get_name (| globals, "FeeMarketTransaction" |); M.get_name (| globals, "BlobTransaction" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + For make_tuple [ M.get_name (| globals, "_address" |); M.get_name (| globals, "keys" |) ] in M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) do + let access_list_cost := BinOp.add + M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) + M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) in + let access_list_cost := BinOp.add + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "keys" |) + ], + make_dict [] + |), + M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) + |) + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "keys" |) + ], + make_dict [] + |), + M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) + |) in + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1603,6 +2290,7 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition recover_sender : Value.t -> Value.t -> M := @@ -1675,9 +2363,222 @@ Definition recover_sender : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "LegacyTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let v := + M.get_field (| M.get_name (| globals, "tx" |), "v" |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.eq (| + M.get_name (| globals, "v" |), + Constant.int 27 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "v" |), + Constant.int 28 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + BinOp.sub (| + M.get_name (| globals, "v" |), + Constant.int 27 + |); + M.call (| + M.get_name (| globals, "signing_hash_pre155" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.or (| + Compare.eq (| + M.get_name (| globals, "v" |), + BinOp.add (| + Constant.int 35, + BinOp.mult (| + M.get_name (| globals, "chain_id" |), + Constant.int 2 + |) + |) + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "v" |), + BinOp.add (| + Constant.int 36, + BinOp.mult (| + M.get_name (| globals, "chain_id" |), + Constant.int 2 + |) + |) + |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + BinOp.sub (| + BinOp.sub (| + M.get_name (| globals, "v" |), + Constant.int 35 + |), + BinOp.mult (| + M.get_name (| globals, "chain_id" |), + Constant.int 2 + |) + |); + M.call (| + M.get_name (| globals, "signing_hash_155" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "chain_id" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "AccessListTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + M.get_field (| M.get_name (| globals, "tx" |), "y_parity" |); + M.call (| + M.get_name (| globals, "signing_hash_2930" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "FeeMarketTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + M.get_field (| M.get_name (| globals, "tx" |), "y_parity" |); + M.call (| + M.get_name (| globals, "signing_hash_1559" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "BlobTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + M.get_field (| M.get_name (| globals, "tx" |), "y_parity" |); + M.call (| + M.get_name (| globals, "signing_hash_4844" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -1696,10 +2597,11 @@ Definition recover_sender : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12 |) + |), M.slice (| Constant.int 12, Constant.int 32 |) |) ], make_dict [] |) + |) in M.pure Constant.None_)). Definition signing_hash_pre155 : Value.t -> Value.t -> M := @@ -1732,6 +2634,7 @@ Definition signing_hash_pre155 : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition signing_hash_155 : Value.t -> Value.t -> M := @@ -1778,6 +2681,7 @@ Definition signing_hash_155 : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition signing_hash_2930 : Value.t -> Value.t -> M := @@ -1813,6 +2717,7 @@ Definition signing_hash_2930 : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition signing_hash_1559 : Value.t -> Value.t -> M := @@ -1848,6 +2753,7 @@ Definition signing_hash_1559 : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition signing_hash_4844 : Value.t -> Value.t -> M := @@ -1883,6 +2789,7 @@ Definition signing_hash_4844 : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition compute_header_hash : Value.t -> Value.t -> M := @@ -1933,6 +2840,7 @@ Definition compute_header_hash : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition check_gas_limit : Value.t -> Value.t -> M := @@ -1971,14 +2879,63 @@ Definition check_gas_limit : Value.t -> Value.t -> M := M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "gas_limit" |), + BinOp.add (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "gas_limit" |), + BinOp.sub (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "gas_limit" |), + M.get_name (| globals, "GAS_LIMIT_MINIMUM" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| Constant.bool true + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/fork_types.v b/CoqOfPython/ethereum/cancun/fork_types.v index 0ba557d..8fdada2 100644 --- a/CoqOfPython/ethereum/cancun/fork_types.v +++ b/CoqOfPython/ethereum/cancun/fork_types.v @@ -21,29 +21,29 @@ Require dataclasses. Axiom dataclasses_dataclass : IsGlobalAlias globals dataclasses.globals "dataclass". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes20 : - IsGlobalAlias globals base_types.globals "Bytes20". -Axiom base_types_Bytes256 : - IsGlobalAlias globals base_types.globals "Bytes256". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require crypto.hash. -Axiom crypto_hash_Hash32 : - IsGlobalAlias globals crypto.hash.globals "Hash32". -Axiom crypto_hash_keccak256 : - IsGlobalAlias globals crypto.hash.globals "keccak256". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes20 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes20". +Axiom ethereum_base_types_Bytes256 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) @@ -102,4 +102,5 @@ Definition encode_account : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/state.v b/CoqOfPython/ethereum/cancun/state.v index c26597c..6dcccea 100644 --- a/CoqOfPython/ethereum/cancun/state.v +++ b/CoqOfPython/ethereum/cancun/state.v @@ -58,33 +58,33 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require blocks. -Axiom blocks_Withdrawal : - IsGlobalAlias globals blocks.globals "Withdrawal". - -Require fork_types. -Axiom fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". -Axiom fork_types_Account : - IsGlobalAlias globals fork_types.globals "Account". -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". - -Require trie. -Axiom trie_EMPTY_TRIE_ROOT : - IsGlobalAlias globals trie.globals "EMPTY_TRIE_ROOT". -Axiom trie_Trie : - IsGlobalAlias globals trie.globals "Trie". -Axiom trie_copy_trie : - IsGlobalAlias globals trie.globals "copy_trie". -Axiom trie_root : - IsGlobalAlias globals trie.globals "root". -Axiom trie_trie_get : - IsGlobalAlias globals trie.globals "trie_get". -Axiom trie_trie_set : - IsGlobalAlias globals trie.globals "trie_set". +Require ethereum.cancun.blocks. +Axiom ethereum_cancun_blocks_Withdrawal : + IsGlobalAlias globals ethereum.cancun.blocks.globals "Withdrawal". + +Require ethereum.cancun.fork_types. +Axiom ethereum_cancun_fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals ethereum.cancun.fork_types.globals "EMPTY_ACCOUNT". +Axiom ethereum_cancun_fork_types_Account : + IsGlobalAlias globals ethereum.cancun.fork_types.globals "Account". +Axiom ethereum_cancun_fork_types_Address : + IsGlobalAlias globals ethereum.cancun.fork_types.globals "Address". +Axiom ethereum_cancun_fork_types_Root : + IsGlobalAlias globals ethereum.cancun.fork_types.globals "Root". + +Require ethereum.cancun.trie. +Axiom ethereum_cancun_trie_EMPTY_TRIE_ROOT : + IsGlobalAlias globals ethereum.cancun.trie.globals "EMPTY_TRIE_ROOT". +Axiom ethereum_cancun_trie_Trie : + IsGlobalAlias globals ethereum.cancun.trie.globals "Trie". +Axiom ethereum_cancun_trie_copy_trie : + IsGlobalAlias globals ethereum.cancun.trie.globals "copy_trie". +Axiom ethereum_cancun_trie_root : + IsGlobalAlias globals ethereum.cancun.trie.globals "root". +Axiom ethereum_cancun_trie_trie_get : + IsGlobalAlias globals ethereum.cancun.trie.globals "trie_get". +Axiom ethereum_cancun_trie_trie_set : + IsGlobalAlias globals ethereum.cancun.trie.globals "trie_set". Definition State : Value.t := builtins.make_klass @@ -144,14 +144,14 @@ Definition begin_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) ], make_dict [] - |); (* At expr: unsupported node type: DictComp *) ] + |); Constant.str "(* At expr: unsupported node type: DictComp *)" ] ], make_dict [] |) in let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "transient_storage" |), "_snapshots" |), "append" |), make_list [ - (* At expr: unsupported node type: DictComp *) + Constant.str "(* At expr: unsupported node type: DictComp *)" ], make_dict [] |) in @@ -176,6 +176,19 @@ Definition commit_transaction : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "created_accounts" |), "clear" |), + make_list [], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -208,6 +221,19 @@ Definition rollback_transaction : Value.t -> Value.t -> M := |) |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "created_accounts" |), "clear" |), + make_list [], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -252,8 +278,27 @@ Definition get_account : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "account" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "account" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_ACCOUNT" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -288,6 +333,7 @@ Definition get_account_optional : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "account" |) + |) in M.pure Constant.None_)). Definition set_account : Value.t -> Value.t -> M := @@ -367,6 +413,18 @@ Definition destroy_storage : Value.t -> Value.t -> M := Address of account whose storage is to be deleted. " in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -429,6 +487,26 @@ Definition get_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "trie" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let value := @@ -450,6 +528,7 @@ Definition get_storage : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "value" |) + |) in M.pure Constant.None_)). Definition set_storage : Value.t -> Value.t -> M := @@ -490,6 +569,27 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "trie" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let trie := + M.call (| + M.get_name (| globals, "Trie" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), + M.get_name (| globals, "trie" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -502,6 +602,18 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + {} + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -526,8 +638,29 @@ Definition storage_root : Value.t -> Value.t -> M := " in let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_TRIE_ROOT" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -558,6 +691,7 @@ Definition state_root : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition account_exists : Value.t -> Value.t -> M := @@ -590,6 +724,7 @@ Definition account_exists : Value.t -> Value.t -> M := |), Constant.None_ |) + |) in M.pure Constant.None_)). Definition account_has_code_or_nonce : Value.t -> Value.t -> M := @@ -639,6 +774,7 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition is_account_empty : Value.t -> Value.t -> M := @@ -696,6 +832,7 @@ Definition is_account_empty : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition account_exists_and_is_empty : Value.t -> Value.t -> M := @@ -762,6 +899,7 @@ Definition account_exists_and_is_empty : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition is_account_alive : Value.t -> Value.t -> M := @@ -792,6 +930,20 @@ Definition is_account_alive : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "account" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| UnOp.not (| BoolOp.and (| Compare.eq (| @@ -819,6 +971,7 @@ Definition is_account_alive : Value.t -> Value.t -> M := |) )) |) |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -944,6 +1097,30 @@ Definition touch_account : Value.t -> Value.t -> M := The address of the account that need to initialised. " in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "account_exists" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "EMPTY_ACCOUNT" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -1021,6 +1198,26 @@ Definition get_storage_original : Value.t -> Value.t -> M := Key of the storage slot. " in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "state" |), "created_accounts" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -1036,6 +1233,25 @@ Definition get_storage_original : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "original_account_trie" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let original_value := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let original_value := M.call (| M.get_name (| globals, "trie_get" |), @@ -1057,6 +1273,7 @@ Definition get_storage_original : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "original_value" |) + |) in M.pure Constant.None_)). Definition get_transient_storage : Value.t -> Value.t -> M := @@ -1087,6 +1304,26 @@ Definition get_transient_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "trie" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let value := @@ -1108,6 +1345,7 @@ Definition get_transient_storage : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "value" |) + |) in M.pure Constant.None_)). Definition set_transient_storage : Value.t -> Value.t -> M := @@ -1136,6 +1374,27 @@ Definition set_transient_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "trie" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let trie := + M.call (| + M.get_name (| globals, "Trie" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "transient_storage" |), "_tries" |), M.get_name (| globals, "address" |) |), + M.get_name (| globals, "trie" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -1148,6 +1407,18 @@ Definition set_transient_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + {} + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "transient_storage" |), "_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -1166,6 +1437,29 @@ Definition destroy_touched_empty_accounts : Value.t -> Value.t -> M := " in For M.get_name (| globals, "address" |) in M.get_name (| globals, "touched_accounts" |) do let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. diff --git a/CoqOfPython/ethereum/cancun/transactions.v b/CoqOfPython/ethereum/cancun/transactions.v index 2038e2c..e6fd77f 100644 --- a/CoqOfPython/ethereum/cancun/transactions.v +++ b/CoqOfPython/ethereum/cancun/transactions.v @@ -19,35 +19,35 @@ Axiom typing_Tuple : Axiom typing_Union : IsGlobalAlias globals typing.globals "Union". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U64 : - IsGlobalAlias globals base_types.globals "U64". -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes0 : - IsGlobalAlias globals base_types.globals "Bytes0". -Axiom base_types_Bytes32 : - IsGlobalAlias globals base_types.globals "Bytes32". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require exceptions. -Axiom exceptions_InvalidBlock : - IsGlobalAlias globals exceptions.globals "InvalidBlock". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_VersionedHash : - IsGlobalAlias globals fork_types.globals "VersionedHash". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U64 : + IsGlobalAlias globals ethereum.base_types.globals "U64". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.exceptions. +Axiom ethereum_exceptions_InvalidBlock : + IsGlobalAlias globals ethereum.exceptions.globals "InvalidBlock". + +Require ethereum.cancun.fork_types. +Axiom ethereum_cancun_fork_types_Address : + IsGlobalAlias globals ethereum.cancun.fork_types.globals "Address". +Axiom ethereum_cancun_fork_types_VersionedHash : + IsGlobalAlias globals ethereum.cancun.fork_types.globals "VersionedHash". Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( Constant.int 21000 @@ -124,16 +124,115 @@ Definition encode_transaction : Value.t -> Value.t -> M := Encode a transaction. Needed because non-legacy transactions aren't RLP. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "LegacyTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "tx" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "AccessListTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + Constant.bytes "01", + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "FeeMarketTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + Constant.bytes "02", + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "BlobTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + Constant.bytes "03", + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.raise (| Some(M.call (| M.get_name (| globals, "Exception" |), make_list [ - (* At expr: unsupported node type: JoinedStr *) + Constant.str "(* At expr: unsupported node type: JoinedStr *)" ], make_dict [] - |)) + |)) |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -151,8 +250,97 @@ Definition decode_transaction : Value.t -> Value.t -> M := Decode a transaction. Needed because non-legacy transactions aren't RLP. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), + Constant.int 1 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), + make_list [ + M.get_name (| globals, "AccessListTransaction" |); + M.get_subscript (| M.get_name (| globals, "tx" |), M.slice (| Constant.int 1, Constant.None_ |) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), + Constant.int 2 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), + make_list [ + M.get_name (| globals, "FeeMarketTransaction" |); + M.get_subscript (| M.get_name (| globals, "tx" |), M.slice (| Constant.int 1, Constant.None_ |) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), + Constant.int 3 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), + make_list [ + M.get_name (| globals, "BlobTransaction" |); + M.get_subscript (| M.get_name (| globals, "tx" |), M.slice (| Constant.int 1, Constant.None_ |) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidBlock" |)) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "tx" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/trie.v b/CoqOfPython/ethereum/cancun/trie.v index b2f66e4..87ec388 100644 --- a/CoqOfPython/ethereum/cancun/trie.v +++ b/CoqOfPython/ethereum/cancun/trie.v @@ -54,9 +54,9 @@ Require ethereum.crypto.hash. Axiom ethereum_crypto_hash_keccak256 : IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". -Require ethereum.shanghai. -Axiom ethereum_shanghai_trie : - IsGlobalAlias globals ethereum.shanghai.globals "trie". +Require ethereum.shanghai.__init__. +Axiom ethereum_shanghai___init___trie : + IsGlobalAlias globals ethereum.shanghai.__init__.globals "trie". Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : @@ -66,39 +66,39 @@ Require ethereum.utils.hexadecimal. Axiom ethereum_utils_hexadecimal_hex_to_bytes : IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require blocks. -Axiom blocks_Receipt : - IsGlobalAlias globals blocks.globals "Receipt". -Axiom blocks_Withdrawal : - IsGlobalAlias globals blocks.globals "Withdrawal". - -Require fork_types. -Axiom fork_types_Account : - IsGlobalAlias globals fork_types.globals "Account". -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". -Axiom fork_types_encode_account : - IsGlobalAlias globals fork_types.globals "encode_account". - -Require transactions. -Axiom transactions_LegacyTransaction : - IsGlobalAlias globals transactions.globals "LegacyTransaction". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.cancun.blocks. +Axiom ethereum_cancun_blocks_Receipt : + IsGlobalAlias globals ethereum.cancun.blocks.globals "Receipt". +Axiom ethereum_cancun_blocks_Withdrawal : + IsGlobalAlias globals ethereum.cancun.blocks.globals "Withdrawal". + +Require ethereum.cancun.fork_types. +Axiom ethereum_cancun_fork_types_Account : + IsGlobalAlias globals ethereum.cancun.fork_types.globals "Account". +Axiom ethereum_cancun_fork_types_Address : + IsGlobalAlias globals ethereum.cancun.fork_types.globals "Address". +Axiom ethereum_cancun_fork_types_Root : + IsGlobalAlias globals ethereum.cancun.fork_types.globals "Root". +Axiom ethereum_cancun_fork_types_encode_account : + IsGlobalAlias globals ethereum.cancun.fork_types.globals "encode_account". + +Require ethereum.cancun.transactions. +Axiom ethereum_cancun_transactions_LegacyTransaction : + IsGlobalAlias globals ethereum.cancun.transactions.globals "LegacyTransaction". Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -205,16 +205,99 @@ Definition encode_internal_node : Value.t -> Value.t -> M := " in (* At stmt: unsupported node type: AnnAssign *) let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "node" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + Constant.bytes "" in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "LeafNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "rest_of_key" |); + Constant.bool true + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "ExtensionNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "key_segment" |); + Constant.bool false + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "BranchNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + BinOp.add (| + M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "value" |) + ] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ - (* At expr: unsupported node type: JoinedStr *) + Constant.str "(* At expr: unsupported node type: JoinedStr *)" ], make_dict [] - |)) + |)) |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -232,6 +315,26 @@ Definition encode_internal_node : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded" |) + ], + make_dict [] + |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "unencoded" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_name (| globals, "keccak256" |), @@ -240,6 +343,7 @@ Definition encode_internal_node : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -253,8 +357,86 @@ Definition encode_node : Value.t -> Value.t -> M := Currently mostly an unimplemented stub. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| + M.get_name (| globals, "storage_root" |), + Constant.None_ + |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "encode_account" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "storage_root" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Withdrawal" |); M.get_name (| globals, "U256" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "cast" |), + make_list [ + M.get_field (| M.get_name (| globals, "rlp" |), "RLP" |); + M.get_name (| globals, "node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "node" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "previous_trie" |), "encode_node" |), @@ -264,6 +446,7 @@ Definition encode_node : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -315,6 +498,7 @@ Definition copy_trie : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition trie_set : Value.t -> Value.t -> M := @@ -336,6 +520,32 @@ Definition trie_set : Value.t -> Value.t -> M := Node to insert at `key`. " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + M.get_field (| M.get_name (| globals, "trie" |), "default" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "key" |), + M.get_field (| M.get_name (| globals, "trie" |), "_data" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), M.get_name (| globals, "value" |) @@ -373,6 +583,7 @@ Definition trie_get : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition common_prefix_length : Value.t -> Value.t -> M := @@ -395,6 +606,34 @@ Definition common_prefix_length : Value.t -> Value.t -> M := make_dict [] |) do let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), + M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -406,6 +645,7 @@ Definition common_prefix_length : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition nibble_list_to_compact : Value.t -> Value.t -> M := @@ -451,6 +691,71 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + Constant.int 2 + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.mult (| + Constant.int 16, + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "is_leaf" |) + |) + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ @@ -512,6 +817,7 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition bytes_to_nibble_list : Value.t -> Value.t -> M := @@ -589,6 +895,7 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition _prepare_trie : Value.t -> Value.t -> M := @@ -618,6 +925,48 @@ Definition _prepare_trie : Value.t -> Value.t -> M := make_dict [] |) do let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| + M.get_name (| globals, "get_storage_root" |), + Constant.None_ + |) |) in + let address := + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |); + M.call (| + M.get_name (| globals, "get_storage_root" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let encoded_value := M.call (| M.get_name (| globals, "encode_node" |), @@ -641,6 +990,22 @@ Definition _prepare_trie : Value.t -> Value.t -> M := |) in (* At stmt: unsupported node type: AnnAssign *) let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "trie" |), "secured" |), + (* then *) + ltac:(M.monadic ( + let key := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let key := M.get_name (| globals, "preimage" |) in M.pure Constant.None_ @@ -658,6 +1023,7 @@ Definition _prepare_trie : Value.t -> Value.t -> M := EndFor. let _ := M.return_ (| M.get_name (| globals, "mapped" |) + |) in M.pure Constant.None_)). Definition root : Value.t -> Value.t -> M := @@ -711,6 +1077,44 @@ Definition root : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -727,6 +1131,7 @@ Definition root : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -753,6 +1158,26 @@ Definition patricialize : Value.t -> Value.t -> M := Root node of `obj`. " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let arbitrary_key := @@ -770,10 +1195,39 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), + Constant.int 1 + |), + (* then *) + ltac:(M.monadic ( + let leaf := + M.call (| + M.get_name (| globals, "LeafNode" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |); + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "leaf" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let substring := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |) |) in + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) in let prefix_length := M.call (| M.get_name (| globals, "len" |), @@ -792,7 +1246,7 @@ Definition patricialize : Value.t -> Value.t -> M := M.get_name (| globals, "common_prefix_length" |), make_list [ M.get_name (| globals, "substring" |); - M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) + M.get_subscript (| M.get_name (| globals, "key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) ], make_dict [] |) @@ -800,10 +1254,64 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "prefix_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "prefix_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let prefix := + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ExtensionNode" |), + make_list [ + M.get_name (| globals, "prefix" |); + M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_name (| globals, "obj" |); + BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) @@ -826,6 +1334,44 @@ Definition patricialize : Value.t -> Value.t -> M := Constant.bytes "" in For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |), + M.get_name (| globals, "level" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "AssertionError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) @@ -837,9 +1383,10 @@ Definition patricialize : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "BranchNode" |), make_list [ - (* At expr: unsupported node type: ListComp *); + Constant.str "(* At expr: unsupported node type: ListComp *)"; M.get_name (| globals, "value" |) ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/utils/address.v b/CoqOfPython/ethereum/cancun/utils/address.v index cbfe60a..9d642c7 100644 --- a/CoqOfPython/ethereum/cancun/utils/address.v +++ b/CoqOfPython/ethereum/cancun/utils/address.v @@ -38,13 +38,13 @@ Require ethereum.utils.byte. Axiom ethereum_utils_byte_left_pad_zero_bytes : IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.cancun.fork_types. +Axiom ethereum_cancun_fork_types_Address : + IsGlobalAlias globals ethereum.cancun.fork_types.globals "Address". Definition to_address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -70,10 +70,11 @@ Definition to_address : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), make_list [], make_dict [] - |), UnOp.sub (| Constant.int 20 |) |) + |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) ], make_dict [] |) + |) in M.pure Constant.None_)). Definition compute_contract_address : Value.t -> Value.t -> M := @@ -113,7 +114,7 @@ Definition compute_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -131,6 +132,7 @@ Definition compute_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition compute_create2_contract_address : Value.t -> Value.t -> M := @@ -180,7 +182,7 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -198,4 +200,5 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/utils/hexadecimal.v b/CoqOfPython/ethereum/cancun/utils/hexadecimal.v index baf5d38..a10ce83 100644 --- a/CoqOfPython/ethereum/cancun/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/cancun/utils/hexadecimal.v @@ -22,13 +22,13 @@ Require ethereum.utils.hexadecimal. Axiom ethereum_utils_hexadecimal_remove_hex_prefix : IsGlobalAlias globals ethereum.utils.hexadecimal.globals "remove_hex_prefix". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". +Require ethereum.cancun.fork_types. +Axiom ethereum_cancun_fork_types_Address : + IsGlobalAlias globals ethereum.cancun.fork_types.globals "Address". +Axiom ethereum_cancun_fork_types_Bloom : + IsGlobalAlias globals ethereum.cancun.fork_types.globals "Bloom". +Axiom ethereum_cancun_fork_types_Root : + IsGlobalAlias globals ethereum.cancun.fork_types.globals "Root". Definition hex_to_root : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -66,6 +66,7 @@ Definition hex_to_root : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition hex_to_bloom : Value.t -> Value.t -> M := @@ -104,6 +105,7 @@ Definition hex_to_bloom : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition hex_to_address : Value.t -> Value.t -> M := @@ -149,4 +151,5 @@ Definition hex_to_address : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/utils/message.v b/CoqOfPython/ethereum/cancun/utils/message.v index 8309846..ce231f7 100644 --- a/CoqOfPython/ethereum/cancun/utils/message.v +++ b/CoqOfPython/ethereum/cancun/utils/message.v @@ -40,27 +40,27 @@ Axiom ethereum_base_types_Bytes32 : Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.cancun.fork_types. +Axiom ethereum_cancun_fork_types_Address : + IsGlobalAlias globals ethereum.cancun.fork_types.globals "Address". -Require state. -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". +Require ethereum.cancun.state. +Axiom ethereum_cancun_state_get_account : + IsGlobalAlias globals ethereum.cancun.state.globals "get_account". -Require vm. -Axiom vm_Environment : - IsGlobalAlias globals vm.globals "Environment". -Axiom vm_Message : - IsGlobalAlias globals vm.globals "Message". +Require ethereum.cancun.vm.__init__. +Axiom ethereum_cancun_vm___init___Environment : + IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Environment". +Axiom ethereum_cancun_vm___init___Message : + IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Message". -Require vm.precompiled_contracts.mapping. -Axiom vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : - IsGlobalAlias globals vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". +Require ethereum.cancun.vm.precompiled_contracts.mapping. +Axiom ethereum_cancun_vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : + IsGlobalAlias globals ethereum.cancun.vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". -Require address. -Axiom address_compute_contract_address : - IsGlobalAlias globals address.globals "compute_contract_address". +Require ethereum.cancun.utils.address. +Axiom ethereum_cancun_utils_address_compute_contract_address : + IsGlobalAlias globals ethereum.cancun.utils.address.globals "compute_contract_address". Definition prepare_message : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -103,14 +103,108 @@ Definition prepare_message : Value.t -> Value.t -> M := Items containing contract creation or message call specific data. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Bytes0" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.call (| + M.get_name (| globals, "compute_contract_address" |), + make_list [ + M.get_name (| globals, "caller" |); + BinOp.sub (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "caller" |) + ], + make_dict [] + |), "nonce" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let msg_data := + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) in + let code := + M.get_name (| globals, "data" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.get_name (| globals, "target" |) in + let msg_data := + M.get_name (| globals, "data" |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "target" |) + ], + make_dict [] + |), "code" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "code_address" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let code_address := + M.get_name (| globals, "target" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "Target must be address or empty bytes" ], make_dict [] - |)) + |)) |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -159,4 +253,5 @@ Definition prepare_message : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/vm/__init__.v b/CoqOfPython/ethereum/cancun/vm/__init__.v index a5c3728..a534ff3 100644 --- a/CoqOfPython/ethereum/cancun/vm/__init__.v +++ b/CoqOfPython/ethereum/cancun/vm/__init__.v @@ -52,27 +52,27 @@ Require ethereum.crypto.hash. Axiom ethereum_crypto_hash_Hash32 : IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_VersionedHash : - IsGlobalAlias globals fork_types.globals "VersionedHash". - -Require state. -Axiom state_State : - IsGlobalAlias globals state.globals "State". -Axiom state_TransientStorage : - IsGlobalAlias globals state.globals "TransientStorage". -Axiom state_account_exists_and_is_empty : - IsGlobalAlias globals state.globals "account_exists_and_is_empty". - -Require precompiled_contracts. -Axiom precompiled_contracts_RIPEMD160_ADDRESS : - IsGlobalAlias globals precompiled_contracts.globals "RIPEMD160_ADDRESS". +Require ethereum.cancun.blocks. +Axiom ethereum_cancun_blocks_Log : + IsGlobalAlias globals ethereum.cancun.blocks.globals "Log". + +Require ethereum.cancun.fork_types. +Axiom ethereum_cancun_fork_types_Address : + IsGlobalAlias globals ethereum.cancun.fork_types.globals "Address". +Axiom ethereum_cancun_fork_types_VersionedHash : + IsGlobalAlias globals ethereum.cancun.fork_types.globals "VersionedHash". + +Require ethereum.cancun.state. +Axiom ethereum_cancun_state_State : + IsGlobalAlias globals ethereum.cancun.state.globals "State". +Axiom ethereum_cancun_state_TransientStorage : + IsGlobalAlias globals ethereum.cancun.state.globals "TransientStorage". +Axiom ethereum_cancun_state_account_exists_and_is_empty : + IsGlobalAlias globals ethereum.cancun.state.globals "account_exists_and_is_empty". + +Require ethereum.cancun.vm.precompiled_contracts.__init__. +Axiom ethereum_cancun_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : + IsGlobalAlias globals ethereum.cancun.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] @@ -151,6 +151,28 @@ Definition incorporate_child_on_success : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -183,9 +205,63 @@ Definition incorporate_child_on_error : Value.t -> Value.t -> M := The child evm to incorporate. " in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "RIPEMD160_ADDRESS" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |), + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign_op (| diff --git a/CoqOfPython/ethereum/cancun/vm/gas.v b/CoqOfPython/ethereum/cancun/vm/gas.v index 22e85b8..ae28679 100644 --- a/CoqOfPython/ethereum/cancun/vm/gas.v +++ b/CoqOfPython/ethereum/cancun/vm/gas.v @@ -47,23 +47,23 @@ Axiom ethereum_utils_numeric_ceil32 : Axiom ethereum_utils_numeric_taylor_exponential : IsGlobalAlias globals ethereum.utils.numeric.globals "taylor_exponential". -Require blocks. -Axiom blocks_Header : - IsGlobalAlias globals blocks.globals "Header". +Require ethereum.cancun.blocks. +Axiom ethereum_cancun_blocks_Header : + IsGlobalAlias globals ethereum.cancun.blocks.globals "Header". -Require transactions. -Axiom transactions_BlobTransaction : - IsGlobalAlias globals transactions.globals "BlobTransaction". -Axiom transactions_Transaction : - IsGlobalAlias globals transactions.globals "Transaction". +Require ethereum.cancun.transactions. +Axiom ethereum_cancun_transactions_BlobTransaction : + IsGlobalAlias globals ethereum.cancun.transactions.globals "BlobTransaction". +Axiom ethereum_cancun_transactions_Transaction : + IsGlobalAlias globals ethereum.cancun.transactions.globals "Transaction". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.cancun.vm.__init__. +Axiom ethereum_cancun_vm___init___Evm : + IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Evm". -Require exceptions. -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". +Require ethereum.cancun.vm.exceptions. +Axiom ethereum_cancun_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.cancun.vm.exceptions.globals "OutOfGasError". Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -581,6 +581,18 @@ Definition charge_gas : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "amount" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign_op (| BinOp.sub, M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), @@ -696,6 +708,18 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := |) in For make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ] in M.get_name (| globals, "extensions" |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "size" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let before_size := @@ -730,6 +754,18 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let size_to_extend := BinOp.add @@ -778,6 +814,7 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition calculate_message_call_gas : Value.t -> Value.t -> M := @@ -809,22 +846,56 @@ Definition calculate_message_call_gas : Value.t -> Value.t -> M := message_call_gas: `MessageCallGas` " in let call_stipend := - (* if *) -M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "call_stipend" |) + )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "gas_left" |), + BinOp.add (| + M.get_name (| globals, "extra_gas" |), + M.get_name (| globals, "memory_cost" |) + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallGas" |), + make_list [ + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "extra_gas" |) + |); + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "call_stipend" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let gas := @@ -863,6 +934,7 @@ M.call (| ], make_dict [] |) + |) in M.pure Constant.None_)). Definition max_message_call_gas : Value.t -> Value.t -> M := @@ -889,6 +961,7 @@ Definition max_message_call_gas : Value.t -> Value.t -> M := Constant.int 64 |) |) + |) in M.pure Constant.None_)). Definition init_code_cost : Value.t -> Value.t -> M := @@ -923,6 +996,7 @@ Definition init_code_cost : Value.t -> Value.t -> M := |), Constant.int 32 |) + |) in M.pure Constant.None_)). Definition calculate_excess_blob_gas : Value.t -> Value.t -> M := @@ -948,11 +1022,32 @@ Definition calculate_excess_blob_gas : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "parent_header" |), "blob_gas_used" |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "parent_blob_gas" |), + M.get_name (| globals, "TARGET_BLOB_GAS_PER_BLOCK" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U64" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| BinOp.sub (| M.get_name (| globals, "parent_blob_gas" |), M.get_name (| globals, "TARGET_BLOB_GAS_PER_BLOCK" |) |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -974,6 +1069,33 @@ Definition calculate_total_blob_gas : Value.t -> Value.t -> M := The total blob gas for the transaction. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "BlobTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.mult (| + M.get_name (| globals, "GAS_PER_BLOB" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "tx" |), "blob_versioned_hashes" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_name (| globals, "Uint" |), @@ -982,6 +1104,7 @@ Definition calculate_total_blob_gas : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -1018,6 +1141,7 @@ Definition calculate_blob_gas_price : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition calculate_data_fee : Value.t -> Value.t -> M := @@ -1055,4 +1179,5 @@ Definition calculate_data_fee : Value.t -> Value.t -> M := make_dict [] |) |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/__init__.v b/CoqOfPython/ethereum/cancun/vm/instructions/__init__.v index e5bebd7..c88f1fb 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/__init__.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/__init__.v @@ -26,53 +26,53 @@ Axiom typing_Callable : Axiom typing_Dict : IsGlobalAlias globals typing.globals "Dict". -Require __init__. -Axiom __init___arithmetic : - IsGlobalAlias globals __init__.globals "arithmetic". +Require ethereum.cancun.vm.instructions.__init__. +Axiom ethereum_cancun_vm_instructions___init___arithmetic : + IsGlobalAlias globals ethereum.cancun.vm.instructions.__init__.globals "arithmetic". -Require __init__. -Axiom __init___bitwise : - IsGlobalAlias globals __init__.globals "bitwise". +Require ethereum.cancun.vm.instructions.__init__. +Axiom ethereum_cancun_vm_instructions___init___bitwise : + IsGlobalAlias globals ethereum.cancun.vm.instructions.__init__.globals "bitwise". -Require __init__. -Axiom __init___block : - IsGlobalAlias globals __init__.globals "block". +Require ethereum.cancun.vm.instructions.__init__. +Axiom ethereum_cancun_vm_instructions___init___block : + IsGlobalAlias globals ethereum.cancun.vm.instructions.__init__.globals "block". -Require __init__. -Axiom __init___comparison : - IsGlobalAlias globals __init__.globals "comparison". +Require ethereum.cancun.vm.instructions.__init__. +Axiom ethereum_cancun_vm_instructions___init___comparison : + IsGlobalAlias globals ethereum.cancun.vm.instructions.__init__.globals "comparison". -Require __init__. -Axiom __init___control_flow : - IsGlobalAlias globals __init__.globals "control_flow". +Require ethereum.cancun.vm.instructions.__init__. +Axiom ethereum_cancun_vm_instructions___init___control_flow : + IsGlobalAlias globals ethereum.cancun.vm.instructions.__init__.globals "control_flow". -Require __init__. -Axiom __init___environment : - IsGlobalAlias globals __init__.globals "environment". +Require ethereum.cancun.vm.instructions.__init__. +Axiom ethereum_cancun_vm_instructions___init___environment : + IsGlobalAlias globals ethereum.cancun.vm.instructions.__init__.globals "environment". -Require __init__. -Axiom __init___keccak : - IsGlobalAlias globals __init__.globals "keccak". +Require ethereum.cancun.vm.instructions.__init__. +Axiom ethereum_cancun_vm_instructions___init___keccak : + IsGlobalAlias globals ethereum.cancun.vm.instructions.__init__.globals "keccak". -Require __init__. -Axiom __init___log : - IsGlobalAlias globals __init__.globals "log". +Require ethereum.cancun.vm.instructions.__init__. +Axiom ethereum_cancun_vm_instructions___init___log : + IsGlobalAlias globals ethereum.cancun.vm.instructions.__init__.globals "log". -Require __init__. -Axiom __init___memory : - IsGlobalAlias globals __init__.globals "memory". +Require ethereum.cancun.vm.instructions.__init__. +Axiom ethereum_cancun_vm_instructions___init___memory : + IsGlobalAlias globals ethereum.cancun.vm.instructions.__init__.globals "memory". -Require __init__. -Axiom __init___stack : - IsGlobalAlias globals __init__.globals "stack". +Require ethereum.cancun.vm.instructions.__init__. +Axiom ethereum_cancun_vm_instructions___init___stack : + IsGlobalAlias globals ethereum.cancun.vm.instructions.__init__.globals "stack". -Require __init__. -Axiom __init___storage : - IsGlobalAlias globals __init__.globals "storage". +Require ethereum.cancun.vm.instructions.__init__. +Axiom ethereum_cancun_vm_instructions___init___storage : + IsGlobalAlias globals ethereum.cancun.vm.instructions.__init__.globals "storage". -Require __init__. -Axiom __init___system : - IsGlobalAlias globals __init__.globals "system". +Require ethereum.cancun.vm.instructions.__init__. +Axiom ethereum_cancun_vm_instructions___init___system : + IsGlobalAlias globals ethereum.cancun.vm.instructions.__init__.globals "system". Definition Ops : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/cancun/vm/instructions/arithmetic.v index 581ba5d..0b28cf8 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/arithmetic.v @@ -31,29 +31,29 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_get_sign : IsGlobalAlias globals ethereum.utils.numeric.globals "get_sign". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_EXPONENTIATION : - IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION". -Axiom gas_GAS_EXPONENTIATION_PER_BYTE : - IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION_PER_BYTE". -Axiom gas_GAS_LOW : - IsGlobalAlias globals gas.globals "GAS_LOW". -Axiom gas_GAS_MID : - IsGlobalAlias globals gas.globals "GAS_MID". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.cancun.vm.__init__. +Axiom ethereum_cancun_vm___init___Evm : + IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Evm". + +Require ethereum.cancun.vm.gas. +Axiom ethereum_cancun_vm_gas_GAS_EXPONENTIATION : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_EXPONENTIATION". +Axiom ethereum_cancun_vm_gas_GAS_EXPONENTIATION_PER_BYTE : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_EXPONENTIATION_PER_BYTE". +Axiom ethereum_cancun_vm_gas_GAS_LOW : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_LOW". +Axiom ethereum_cancun_vm_gas_GAS_MID : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_MID". +Axiom ethereum_cancun_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_cancun_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "charge_gas". + +Require ethereum.cancun.vm.stack. +Axiom ethereum_cancun_vm_stack_pop : + IsGlobalAlias globals ethereum.cancun.vm.stack.globals "pop". +Axiom ethereum_cancun_vm_stack_push : + IsGlobalAlias globals ethereum.cancun.vm.stack.globals "push". Definition add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -273,6 +273,25 @@ Definition div : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "divisor" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let quotient := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let quotient := BinOp.floor_div (| M.get_name (| globals, "dividend" |), @@ -341,7 +360,41 @@ Definition sdiv : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "divisor" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let quotient := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_name (| globals, "dividend" |), + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "divisor" |), + UnOp.sub (| Constant.int 1 |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let quotient := + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let sign := M.call (| M.get_name (| globals, "get_sign" |), @@ -436,6 +489,25 @@ Definition mod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "y" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let remainder := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let remainder := BinOp.mod_ (| M.get_name (| globals, "x" |), @@ -504,6 +576,19 @@ Definition smod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "y" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let remainder := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let remainder := BinOp.mult (| M.call (| @@ -617,6 +702,25 @@ Definition addmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "z" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -712,6 +816,25 @@ Definition mulmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "z" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -881,6 +1004,19 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "byte_num" |), + Constant.int 31 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.get_name (| globals, "value" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let value_bytes := M.call (| M.get_name (| globals, "bytes" |), @@ -894,7 +1030,7 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let value_bytes := - M.get_subscript (| M.get_name (| globals, "value_bytes" |), BinOp.sub (| + M.get_subscript (| M.get_name (| globals, "value_bytes" |), M.slice (| BinOp.sub (| Constant.int 31, M.call (| M.get_name (| globals, "int" |), @@ -903,13 +1039,32 @@ Definition signextend : Value.t -> Value.t -> M := ], make_dict [] |) - |) |) in + |), Constant.None_ |) |) in let sign_bit := BinOp.r_shift (| M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), Constant.int 7 |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "sign_bit" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "value_bytes" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let num_bytes_prepend := BinOp.sub (| Constant.int 32, diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/bitwise.v b/CoqOfPython/ethereum/cancun/vm/instructions/bitwise.v index 64cf120..09dde27 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/bitwise.v @@ -23,21 +23,21 @@ Axiom ethereum_base_types_U256 : Axiom ethereum_base_types_U256_CEIL_VALUE : IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.cancun.vm.__init__. +Axiom ethereum_cancun_vm___init___Evm : + IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.cancun.vm.gas. +Axiom ethereum_cancun_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_cancun_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "charge_gas". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.cancun.vm.stack. +Axiom ethereum_cancun_vm_stack_pop : + IsGlobalAlias globals ethereum.cancun.vm.stack.globals "pop". +Axiom ethereum_cancun_vm_stack_push : + IsGlobalAlias globals ethereum.cancun.vm.stack.globals "push". Definition bitwise_and : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -287,6 +287,25 @@ Definition get_byte : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "byte_index" |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let extra_bytes_to_right := BinOp.sub (| Constant.int 31, @@ -366,6 +385,31 @@ Definition bitwise_shl : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "shift" |), + Constant.int 256 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.l_shift (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "shift" |) + |), + M.get_name (| globals, "U256_CEIL_VALUE" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -427,6 +471,22 @@ Definition bitwise_shr : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "shift" |), + Constant.int 256 + |), + (* then *) + ltac:(M.monadic ( + let result := + BinOp.r_shift (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "shift" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -492,7 +552,48 @@ Definition bitwise_sar : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "shift" |), + Constant.int 256 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + BinOp.r_shift (| + M.get_name (| globals, "signed_value" |), + M.get_name (| globals, "shift" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "signed_value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/block.v b/CoqOfPython/ethereum/cancun/vm/instructions/block.v index 6bcda3b..9bd1ac0 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/block.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/block.v @@ -21,23 +21,23 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_BLOCK_HASH : - IsGlobalAlias globals gas.globals "GAS_BLOCK_HASH". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.cancun.vm.__init__. +Axiom ethereum_cancun_vm___init___Evm : + IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Evm". + +Require ethereum.cancun.vm.gas. +Axiom ethereum_cancun_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_BASE". +Axiom ethereum_cancun_vm_gas_GAS_BLOCK_HASH : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_BLOCK_HASH". +Axiom ethereum_cancun_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "charge_gas". + +Require ethereum.cancun.vm.stack. +Axiom ethereum_cancun_vm_stack_pop : + IsGlobalAlias globals ethereum.cancun.vm.stack.globals "pop". +Axiom ethereum_cancun_vm_stack_push : + IsGlobalAlias globals ethereum.cancun.vm.stack.globals "push". Definition block_hash : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -75,6 +75,30 @@ Definition block_hash : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt_e (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + M.get_name (| globals, "block_number" |) + |), + ltac:(M.monadic ( + Compare.gt (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + BinOp.add (| + M.get_name (| globals, "block_number" |), + Constant.int 256 + |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let hash := + Constant.bytes "00" in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let hash := M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/comparison.v b/CoqOfPython/ethereum/cancun/vm/instructions/comparison.v index b8529d8..d3ba649 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/comparison.v @@ -21,21 +21,21 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.cancun.vm.__init__. +Axiom ethereum_cancun_vm___init___Evm : + IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.cancun.vm.gas. +Axiom ethereum_cancun_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_cancun_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "charge_gas". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.cancun.vm.stack. +Axiom ethereum_cancun_vm_stack_pop : + IsGlobalAlias globals ethereum.cancun.vm.stack.globals "pop". +Axiom ethereum_cancun_vm_stack_push : + IsGlobalAlias globals ethereum.cancun.vm.stack.globals "push". Definition less_than : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/control_flow.v b/CoqOfPython/ethereum/cancun/vm/instructions/control_flow.v index d4e4eae..b44fd44 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/control_flow.v @@ -23,31 +23,31 @@ Axiom ethereum_base_types_U256 : Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require vm.gas. -Axiom vm_gas_GAS_BASE : - IsGlobalAlias globals vm.gas.globals "GAS_BASE". -Axiom vm_gas_GAS_HIGH : - IsGlobalAlias globals vm.gas.globals "GAS_HIGH". -Axiom vm_gas_GAS_JUMPDEST : - IsGlobalAlias globals vm.gas.globals "GAS_JUMPDEST". -Axiom vm_gas_GAS_MID : - IsGlobalAlias globals vm.gas.globals "GAS_MID". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.cancun.vm.gas. +Axiom ethereum_cancun_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_BASE". +Axiom ethereum_cancun_vm_gas_GAS_HIGH : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_HIGH". +Axiom ethereum_cancun_vm_gas_GAS_JUMPDEST : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_JUMPDEST". +Axiom ethereum_cancun_vm_gas_GAS_MID : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_MID". +Axiom ethereum_cancun_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "charge_gas". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.cancun.vm.__init__. +Axiom ethereum_cancun_vm___init___Evm : + IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Evm". -Require exceptions. -Axiom exceptions_InvalidJumpDestError : - IsGlobalAlias globals exceptions.globals "InvalidJumpDestError". +Require ethereum.cancun.vm.exceptions. +Axiom ethereum_cancun_vm_exceptions_InvalidJumpDestError : + IsGlobalAlias globals ethereum.cancun.vm.exceptions.globals "InvalidJumpDestError". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.cancun.vm.stack. +Axiom ethereum_cancun_vm_stack_pop : + IsGlobalAlias globals ethereum.cancun.vm.stack.globals "pop". +Axiom ethereum_cancun_vm_stack_push : + IsGlobalAlias globals ethereum.cancun.vm.stack.globals "push". Definition stop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -109,6 +109,18 @@ Definition jump : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "jump_dest" |), + M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -168,7 +180,35 @@ Definition jumpi : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "conditional_value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let destination := + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "jump_dest" |), + M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let destination := M.get_name (| globals, "jump_dest" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/environment.v b/CoqOfPython/ethereum/cancun/vm/instructions/environment.v index 3d62649..1403c17 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/environment.v @@ -37,61 +37,61 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require fork_types. -Axiom fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". - -Require state. -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". - -Require utils.address. -Axiom utils_address_to_address : - IsGlobalAlias globals utils.address.globals "to_address". - -Require vm.memory. -Axiom vm_memory_buffer_read : - IsGlobalAlias globals vm.memory.globals "buffer_read". -Axiom vm_memory_memory_write : - IsGlobalAlias globals vm.memory.globals "memory_write". - -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require exceptions. -Axiom exceptions_OutOfBoundsRead : - IsGlobalAlias globals exceptions.globals "OutOfBoundsRead". - -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_BLOBHASH_OPCODE : - IsGlobalAlias globals gas.globals "GAS_BLOBHASH_OPCODE". -Axiom gas_GAS_COLD_ACCOUNT_ACCESS : - IsGlobalAlias globals gas.globals "GAS_COLD_ACCOUNT_ACCESS". -Axiom gas_GAS_COPY : - IsGlobalAlias globals gas.globals "GAS_COPY". -Axiom gas_GAS_FAST_STEP : - IsGlobalAlias globals gas.globals "GAS_FAST_STEP". -Axiom gas_GAS_RETURN_DATA_COPY : - IsGlobalAlias globals gas.globals "GAS_RETURN_DATA_COPY". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_GAS_WARM_ACCESS : - IsGlobalAlias globals gas.globals "GAS_WARM_ACCESS". -Axiom gas_calculate_blob_gas_price : - IsGlobalAlias globals gas.globals "calculate_blob_gas_price". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.cancun.fork_types. +Axiom ethereum_cancun_fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals ethereum.cancun.fork_types.globals "EMPTY_ACCOUNT". + +Require ethereum.cancun.state. +Axiom ethereum_cancun_state_get_account : + IsGlobalAlias globals ethereum.cancun.state.globals "get_account". + +Require ethereum.cancun.utils.address. +Axiom ethereum_cancun_utils_address_to_address : + IsGlobalAlias globals ethereum.cancun.utils.address.globals "to_address". + +Require ethereum.cancun.vm.memory. +Axiom ethereum_cancun_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.cancun.vm.memory.globals "buffer_read". +Axiom ethereum_cancun_vm_memory_memory_write : + IsGlobalAlias globals ethereum.cancun.vm.memory.globals "memory_write". + +Require ethereum.cancun.vm.__init__. +Axiom ethereum_cancun_vm___init___Evm : + IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Evm". + +Require ethereum.cancun.vm.exceptions. +Axiom ethereum_cancun_vm_exceptions_OutOfBoundsRead : + IsGlobalAlias globals ethereum.cancun.vm.exceptions.globals "OutOfBoundsRead". + +Require ethereum.cancun.vm.gas. +Axiom ethereum_cancun_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_BASE". +Axiom ethereum_cancun_vm_gas_GAS_BLOBHASH_OPCODE : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_BLOBHASH_OPCODE". +Axiom ethereum_cancun_vm_gas_GAS_COLD_ACCOUNT_ACCESS : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_COLD_ACCOUNT_ACCESS". +Axiom ethereum_cancun_vm_gas_GAS_COPY : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_COPY". +Axiom ethereum_cancun_vm_gas_GAS_FAST_STEP : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_FAST_STEP". +Axiom ethereum_cancun_vm_gas_GAS_RETURN_DATA_COPY : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_RETURN_DATA_COPY". +Axiom ethereum_cancun_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_cancun_vm_gas_GAS_WARM_ACCESS : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_WARM_ACCESS". +Axiom ethereum_cancun_vm_gas_calculate_blob_gas_price : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "calculate_blob_gas_price". +Axiom ethereum_cancun_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_cancun_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "charge_gas". + +Require ethereum.cancun.vm.stack. +Axiom ethereum_cancun_vm_stack_pop : + IsGlobalAlias globals ethereum.cancun.vm.stack.globals "pop". +Axiom ethereum_cancun_vm_stack_push : + IsGlobalAlias globals ethereum.cancun.vm.stack.globals "push". Definition address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -162,6 +162,25 @@ Definition balance : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -795,6 +814,25 @@ Definition extcodesize : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -932,6 +970,31 @@ Definition extcodecopy : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_WARM_ACCESS" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1168,7 +1231,10 @@ Definition returndatacopy : Value.t -> Value.t -> M := |) |) in let value := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |) |) in + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.slice (| M.get_name (| globals, "return_data_start_position" |), BinOp.add (| + M.get_name (| globals, "return_data_start_position" |), + M.get_name (| globals, "size" |) + |) |) |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -1210,6 +1276,25 @@ Definition extcodehash : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1237,6 +1322,25 @@ Definition extcodehash : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "account" |), + M.get_name (| globals, "EMPTY_ACCOUNT" |) + |), + (* then *) + ltac:(M.monadic ( + let codehash := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let codehash := M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), @@ -1384,6 +1488,25 @@ Definition blob_hash : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "index" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "blob_versioned_hashes" |) + ], + make_dict [] + |) + |), + (* then *) + ltac:(M.monadic ( + let blob_hash := + M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "blob_versioned_hashes" |), M.get_name (| globals, "index" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let blob_hash := M.call (| M.get_name (| globals, "Bytes32" |), diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/keccak.v b/CoqOfPython/ethereum/cancun/vm/instructions/keccak.v index 2c4b10e..40fe147 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/keccak.v @@ -31,29 +31,29 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_KECCAK256 : - IsGlobalAlias globals gas.globals "GAS_KECCAK256". -Axiom gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.cancun.vm.__init__. +Axiom ethereum_cancun_vm___init___Evm : + IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Evm". + +Require ethereum.cancun.vm.gas. +Axiom ethereum_cancun_vm_gas_GAS_KECCAK256 : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_KECCAK256". +Axiom ethereum_cancun_vm_gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_KECCAK256_WORD". +Axiom ethereum_cancun_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_cancun_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "charge_gas". + +Require ethereum.cancun.vm.memory. +Axiom ethereum_cancun_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.cancun.vm.memory.globals "memory_read_bytes". + +Require ethereum.cancun.vm.stack. +Axiom ethereum_cancun_vm_stack_pop : + IsGlobalAlias globals ethereum.cancun.vm.stack.globals "pop". +Axiom ethereum_cancun_vm_stack_push : + IsGlobalAlias globals ethereum.cancun.vm.stack.globals "push". Definition keccak : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/log.v b/CoqOfPython/ethereum/cancun/vm/instructions/log.v index e084e59..d828499 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/log.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/log.v @@ -29,37 +29,37 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". - -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require exceptions. -Axiom exceptions_WriteInStaticContext : - IsGlobalAlias globals exceptions.globals "WriteInStaticContext". - -Require gas. -Axiom gas_GAS_LOG : - IsGlobalAlias globals gas.globals "GAS_LOG". -Axiom gas_GAS_LOG_DATA : - IsGlobalAlias globals gas.globals "GAS_LOG_DATA". -Axiom gas_GAS_LOG_TOPIC : - IsGlobalAlias globals gas.globals "GAS_LOG_TOPIC". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". +Require ethereum.cancun.blocks. +Axiom ethereum_cancun_blocks_Log : + IsGlobalAlias globals ethereum.cancun.blocks.globals "Log". + +Require ethereum.cancun.vm.__init__. +Axiom ethereum_cancun_vm___init___Evm : + IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Evm". + +Require ethereum.cancun.vm.exceptions. +Axiom ethereum_cancun_vm_exceptions_WriteInStaticContext : + IsGlobalAlias globals ethereum.cancun.vm.exceptions.globals "WriteInStaticContext". + +Require ethereum.cancun.vm.gas. +Axiom ethereum_cancun_vm_gas_GAS_LOG : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_LOG". +Axiom ethereum_cancun_vm_gas_GAS_LOG_DATA : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_LOG_DATA". +Axiom ethereum_cancun_vm_gas_GAS_LOG_TOPIC : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_LOG_TOPIC". +Axiom ethereum_cancun_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_cancun_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "charge_gas". + +Require ethereum.cancun.vm.memory. +Axiom ethereum_cancun_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.cancun.vm.memory.globals "memory_read_bytes". + +Require ethereum.cancun.vm.stack. +Axiom ethereum_cancun_vm_stack_pop : + IsGlobalAlias globals ethereum.cancun.vm.stack.globals "pop". Definition log_n : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/memory.v b/CoqOfPython/ethereum/cancun/vm/instructions/memory.v index dd6635e..d6b1b92 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/memory.v @@ -29,33 +29,33 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.cancun.vm.__init__. +Axiom ethereum_cancun_vm___init___Evm : + IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_COPY : - IsGlobalAlias globals gas.globals "GAS_COPY". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.cancun.vm.gas. +Axiom ethereum_cancun_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_BASE". +Axiom ethereum_cancun_vm_gas_GAS_COPY : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_COPY". +Axiom ethereum_cancun_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_cancun_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_cancun_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "charge_gas". -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". -Axiom memory_memory_write : - IsGlobalAlias globals memory.globals "memory_write". +Require ethereum.cancun.vm.memory. +Axiom ethereum_cancun_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.cancun.vm.memory.globals "memory_read_bytes". +Axiom ethereum_cancun_vm_memory_memory_write : + IsGlobalAlias globals ethereum.cancun.vm.memory.globals "memory_write". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.cancun.vm.stack. +Axiom ethereum_cancun_vm_stack_pop : + IsGlobalAlias globals ethereum.cancun.vm.stack.globals "pop". +Axiom ethereum_cancun_vm_stack_push : + IsGlobalAlias globals ethereum.cancun.vm.stack.globals "push". Definition mstore : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/stack.v b/CoqOfPython/ethereum/cancun/vm/instructions/stack.v index aa085db..a46eb79 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/stack.v @@ -29,27 +29,27 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". -Axiom __init___stack : - IsGlobalAlias globals __init__.globals "stack". - -Require exceptions. -Axiom exceptions_StackUnderflowError : - IsGlobalAlias globals exceptions.globals "StackUnderflowError". - -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require memory. -Axiom memory_buffer_read : - IsGlobalAlias globals memory.globals "buffer_read". +Require ethereum.cancun.vm.__init__. +Axiom ethereum_cancun_vm___init___Evm : + IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Evm". +Axiom ethereum_cancun_vm___init___stack : + IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "stack". + +Require ethereum.cancun.vm.exceptions. +Axiom ethereum_cancun_vm_exceptions_StackUnderflowError : + IsGlobalAlias globals ethereum.cancun.vm.exceptions.globals "StackUnderflowError". + +Require ethereum.cancun.vm.gas. +Axiom ethereum_cancun_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_BASE". +Axiom ethereum_cancun_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_cancun_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "charge_gas". + +Require ethereum.cancun.vm.memory. +Axiom ethereum_cancun_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.cancun.vm.memory.globals "buffer_read". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -104,6 +104,25 @@ Definition push_n : Value.t -> Value.t -> M := " in let _ := M.pass (| |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "num_bytes" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/storage.v b/CoqOfPython/ethereum/cancun/vm/instructions/storage.v index b214ff1..83ebab0 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/storage.v @@ -25,49 +25,49 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require state. -Axiom state_get_storage : - IsGlobalAlias globals state.globals "get_storage". -Axiom state_get_storage_original : - IsGlobalAlias globals state.globals "get_storage_original". -Axiom state_get_transient_storage : - IsGlobalAlias globals state.globals "get_transient_storage". -Axiom state_set_storage : - IsGlobalAlias globals state.globals "set_storage". -Axiom state_set_transient_storage : - IsGlobalAlias globals state.globals "set_transient_storage". +Require ethereum.cancun.state. +Axiom ethereum_cancun_state_get_storage : + IsGlobalAlias globals ethereum.cancun.state.globals "get_storage". +Axiom ethereum_cancun_state_get_storage_original : + IsGlobalAlias globals ethereum.cancun.state.globals "get_storage_original". +Axiom ethereum_cancun_state_get_transient_storage : + IsGlobalAlias globals ethereum.cancun.state.globals "get_transient_storage". +Axiom ethereum_cancun_state_set_storage : + IsGlobalAlias globals ethereum.cancun.state.globals "set_storage". +Axiom ethereum_cancun_state_set_transient_storage : + IsGlobalAlias globals ethereum.cancun.state.globals "set_transient_storage". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.cancun.vm.__init__. +Axiom ethereum_cancun_vm___init___Evm : + IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Evm". -Require exceptions. -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". -Axiom exceptions_WriteInStaticContext : - IsGlobalAlias globals exceptions.globals "WriteInStaticContext". +Require ethereum.cancun.vm.exceptions. +Axiom ethereum_cancun_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.cancun.vm.exceptions.globals "OutOfGasError". +Axiom ethereum_cancun_vm_exceptions_WriteInStaticContext : + IsGlobalAlias globals ethereum.cancun.vm.exceptions.globals "WriteInStaticContext". -Require gas. -Axiom gas_GAS_CALL_STIPEND : - IsGlobalAlias globals gas.globals "GAS_CALL_STIPEND". -Axiom gas_GAS_COLD_SLOAD : - IsGlobalAlias globals gas.globals "GAS_COLD_SLOAD". -Axiom gas_GAS_STORAGE_CLEAR_REFUND : - IsGlobalAlias globals gas.globals "GAS_STORAGE_CLEAR_REFUND". -Axiom gas_GAS_STORAGE_SET : - IsGlobalAlias globals gas.globals "GAS_STORAGE_SET". -Axiom gas_GAS_STORAGE_UPDATE : - IsGlobalAlias globals gas.globals "GAS_STORAGE_UPDATE". -Axiom gas_GAS_WARM_ACCESS : - IsGlobalAlias globals gas.globals "GAS_WARM_ACCESS". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.cancun.vm.gas. +Axiom ethereum_cancun_vm_gas_GAS_CALL_STIPEND : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_CALL_STIPEND". +Axiom ethereum_cancun_vm_gas_GAS_COLD_SLOAD : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_COLD_SLOAD". +Axiom ethereum_cancun_vm_gas_GAS_STORAGE_CLEAR_REFUND : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_STORAGE_CLEAR_REFUND". +Axiom ethereum_cancun_vm_gas_GAS_STORAGE_SET : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_STORAGE_SET". +Axiom ethereum_cancun_vm_gas_GAS_STORAGE_UPDATE : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_STORAGE_UPDATE". +Axiom ethereum_cancun_vm_gas_GAS_WARM_ACCESS : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_WARM_ACCESS". +Axiom ethereum_cancun_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "charge_gas". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.cancun.vm.stack. +Axiom ethereum_cancun_vm_stack_pop : + IsGlobalAlias globals ethereum.cancun.vm.stack.globals "pop". +Axiom ethereum_cancun_vm_stack_push : + IsGlobalAlias globals ethereum.cancun.vm.stack.globals "push". Definition sload : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -95,6 +95,25 @@ Definition sload : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], + M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "add" |), make_list [ @@ -209,15 +228,225 @@ Definition sstore : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], + M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "add" |), + make_list [ + make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ] + ], + make_dict [] + |) in + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_COLD_SLOAD" |) + M.get_name (| globals, "GAS_COLD_SLOAD" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_name (| globals, "original_value" |), + M.get_name (| globals, "current_value" |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "current_value" |), + M.get_name (| globals, "new_value" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "original_value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_STORAGE_SET" |) + M.get_name (| globals, "GAS_STORAGE_SET" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let gas_cost := BinOp.add + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_UPDATE" |), + M.get_name (| globals, "GAS_COLD_SLOAD" |) + |) + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_UPDATE" |), + M.get_name (| globals, "GAS_COLD_SLOAD" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let gas_cost := BinOp.add M.get_name (| globals, "GAS_WARM_ACCESS" |) M.get_name (| globals, "GAS_WARM_ACCESS" |) in M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| + M.get_name (| globals, "current_value" |), + M.get_name (| globals, "new_value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "original_value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "current_value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "new_value" |), + Constant.int 0 + |) + )) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "original_value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "current_value" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.sub, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "original_value" |), + M.get_name (| globals, "new_value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "original_value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_SET" |), + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.sub (| + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_UPDATE" |), + M.get_name (| globals, "GAS_COLD_SLOAD" |) + |), + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/system.v b/CoqOfPython/ethereum/cancun/vm/instructions/system.v index 4ef7a77..936f03b 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/system.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/system.v @@ -33,93 +33,93 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.cancun.fork_types. +Axiom ethereum_cancun_fork_types_Address : + IsGlobalAlias globals ethereum.cancun.fork_types.globals "Address". -Require state. -Axiom state_account_exists_and_is_empty : - IsGlobalAlias globals state.globals "account_exists_and_is_empty". -Axiom state_account_has_code_or_nonce : - IsGlobalAlias globals state.globals "account_has_code_or_nonce". -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". -Axiom state_increment_nonce : - IsGlobalAlias globals state.globals "increment_nonce". -Axiom state_is_account_alive : - IsGlobalAlias globals state.globals "is_account_alive". -Axiom state_move_ether : - IsGlobalAlias globals state.globals "move_ether". -Axiom state_set_account_balance : - IsGlobalAlias globals state.globals "set_account_balance". +Require ethereum.cancun.state. +Axiom ethereum_cancun_state_account_exists_and_is_empty : + IsGlobalAlias globals ethereum.cancun.state.globals "account_exists_and_is_empty". +Axiom ethereum_cancun_state_account_has_code_or_nonce : + IsGlobalAlias globals ethereum.cancun.state.globals "account_has_code_or_nonce". +Axiom ethereum_cancun_state_get_account : + IsGlobalAlias globals ethereum.cancun.state.globals "get_account". +Axiom ethereum_cancun_state_increment_nonce : + IsGlobalAlias globals ethereum.cancun.state.globals "increment_nonce". +Axiom ethereum_cancun_state_is_account_alive : + IsGlobalAlias globals ethereum.cancun.state.globals "is_account_alive". +Axiom ethereum_cancun_state_move_ether : + IsGlobalAlias globals ethereum.cancun.state.globals "move_ether". +Axiom ethereum_cancun_state_set_account_balance : + IsGlobalAlias globals ethereum.cancun.state.globals "set_account_balance". -Require utils.address. -Axiom utils_address_compute_contract_address : - IsGlobalAlias globals utils.address.globals "compute_contract_address". -Axiom utils_address_compute_create2_contract_address : - IsGlobalAlias globals utils.address.globals "compute_create2_contract_address". -Axiom utils_address_to_address : - IsGlobalAlias globals utils.address.globals "to_address". +Require ethereum.cancun.utils.address. +Axiom ethereum_cancun_utils_address_compute_contract_address : + IsGlobalAlias globals ethereum.cancun.utils.address.globals "compute_contract_address". +Axiom ethereum_cancun_utils_address_compute_create2_contract_address : + IsGlobalAlias globals ethereum.cancun.utils.address.globals "compute_create2_contract_address". +Axiom ethereum_cancun_utils_address_to_address : + IsGlobalAlias globals ethereum.cancun.utils.address.globals "to_address". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". -Axiom __init___Message : - IsGlobalAlias globals __init__.globals "Message". -Axiom __init___incorporate_child_on_error : - IsGlobalAlias globals __init__.globals "incorporate_child_on_error". -Axiom __init___incorporate_child_on_success : - IsGlobalAlias globals __init__.globals "incorporate_child_on_success". +Require ethereum.cancun.vm.__init__. +Axiom ethereum_cancun_vm___init___Evm : + IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Evm". +Axiom ethereum_cancun_vm___init___Message : + IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Message". +Axiom ethereum_cancun_vm___init___incorporate_child_on_error : + IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "incorporate_child_on_error". +Axiom ethereum_cancun_vm___init___incorporate_child_on_success : + IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "incorporate_child_on_success". -Require exceptions. -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". -Axiom exceptions_Revert : - IsGlobalAlias globals exceptions.globals "Revert". -Axiom exceptions_WriteInStaticContext : - IsGlobalAlias globals exceptions.globals "WriteInStaticContext". +Require ethereum.cancun.vm.exceptions. +Axiom ethereum_cancun_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.cancun.vm.exceptions.globals "OutOfGasError". +Axiom ethereum_cancun_vm_exceptions_Revert : + IsGlobalAlias globals ethereum.cancun.vm.exceptions.globals "Revert". +Axiom ethereum_cancun_vm_exceptions_WriteInStaticContext : + IsGlobalAlias globals ethereum.cancun.vm.exceptions.globals "WriteInStaticContext". -Require gas. -Axiom gas_GAS_CALL_VALUE : - IsGlobalAlias globals gas.globals "GAS_CALL_VALUE". -Axiom gas_GAS_COLD_ACCOUNT_ACCESS : - IsGlobalAlias globals gas.globals "GAS_COLD_ACCOUNT_ACCESS". -Axiom gas_GAS_CREATE : - IsGlobalAlias globals gas.globals "GAS_CREATE". -Axiom gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". -Axiom gas_GAS_NEW_ACCOUNT : - IsGlobalAlias globals gas.globals "GAS_NEW_ACCOUNT". -Axiom gas_GAS_SELF_DESTRUCT : - IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT". -Axiom gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : - IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". -Axiom gas_GAS_WARM_ACCESS : - IsGlobalAlias globals gas.globals "GAS_WARM_ACCESS". -Axiom gas_GAS_ZERO : - IsGlobalAlias globals gas.globals "GAS_ZERO". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_calculate_message_call_gas : - IsGlobalAlias globals gas.globals "calculate_message_call_gas". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". -Axiom gas_init_code_cost : - IsGlobalAlias globals gas.globals "init_code_cost". -Axiom gas_max_message_call_gas : - IsGlobalAlias globals gas.globals "max_message_call_gas". +Require ethereum.cancun.vm.gas. +Axiom ethereum_cancun_vm_gas_GAS_CALL_VALUE : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_CALL_VALUE". +Axiom ethereum_cancun_vm_gas_GAS_COLD_ACCOUNT_ACCESS : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_COLD_ACCOUNT_ACCESS". +Axiom ethereum_cancun_vm_gas_GAS_CREATE : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_CREATE". +Axiom ethereum_cancun_vm_gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_KECCAK256_WORD". +Axiom ethereum_cancun_vm_gas_GAS_NEW_ACCOUNT : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_NEW_ACCOUNT". +Axiom ethereum_cancun_vm_gas_GAS_SELF_DESTRUCT : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_SELF_DESTRUCT". +Axiom ethereum_cancun_vm_gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". +Axiom ethereum_cancun_vm_gas_GAS_WARM_ACCESS : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_WARM_ACCESS". +Axiom ethereum_cancun_vm_gas_GAS_ZERO : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_ZERO". +Axiom ethereum_cancun_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_cancun_vm_gas_calculate_message_call_gas : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "calculate_message_call_gas". +Axiom ethereum_cancun_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "charge_gas". +Axiom ethereum_cancun_vm_gas_init_code_cost : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "init_code_cost". +Axiom ethereum_cancun_vm_gas_max_message_call_gas : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "max_message_call_gas". -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". -Axiom memory_memory_write : - IsGlobalAlias globals memory.globals "memory_write". +Require ethereum.cancun.vm.memory. +Axiom ethereum_cancun_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.cancun.vm.memory.globals "memory_read_bytes". +Axiom ethereum_cancun_vm_memory_memory_write : + IsGlobalAlias globals ethereum.cancun.vm.memory.globals "memory_write". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.cancun.vm.stack. +Axiom ethereum_cancun_vm_stack_pop : + IsGlobalAlias globals ethereum.cancun.vm.stack.globals "pop". +Axiom ethereum_cancun_vm_stack_push : + IsGlobalAlias globals ethereum.cancun.vm.stack.globals "push". Definition generic_create : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -208,9 +208,113 @@ Definition generic_create : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt (| + M.get_field (| M.get_name (| globals, "sender" |), "balance" |), + M.get_name (| globals, "endowment" |) + |), + ltac:(M.monadic ( + BoolOp.or (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "sender" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.sub (| + BinOp.pow (| + Constant.int 2, + Constant.int 64 + |), + Constant.int 1 + |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.gt (| + BinOp.add (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "depth" |), + Constant.int 1 + |), + M.get_name (| globals, "STACK_DEPTH_LIMIT" |) + |) + )) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "create_message_gas" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "contract_address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -237,6 +341,40 @@ Definition generic_create : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "child_evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_error" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "incorporate_child_on_success" |), make_list [ @@ -629,6 +767,42 @@ Definition generic_call : Value.t -> Value.t -> M := Constant.bytes "" |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + BinOp.add (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "depth" |), + Constant.int 1 + |), + M.get_name (| globals, "STACK_DEPTH_LIMIT" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "gas" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let call_data := @@ -666,6 +840,40 @@ Definition generic_call : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "child_evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_error" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "incorporate_child_on_success" |), make_list [ @@ -720,7 +928,7 @@ Definition generic_call : Value.t -> Value.t -> M := make_list [ M.get_field (| M.get_name (| globals, "evm" |), "memory" |); M.get_name (| globals, "memory_output_start_position" |); - M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), Constant.None_:M.get_name (| globals, "actual_output_size" |) |) + M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), M.slice (| Constant.None_, M.get_name (| globals, "actual_output_size" |) |) |) ], make_dict [] |) in @@ -818,6 +1026,19 @@ Definition call : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "to" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let access_gas_cost := + M.get_name (| globals, "GAS_WARM_ACCESS" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -830,49 +1051,57 @@ Definition call : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in let create_gas_cost := - (* if *) -M.if_then_else (| - BoolOp.or (| - M.call (| - M.get_name (| globals, "is_account_alive" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); - M.get_name (| globals, "to" |) - ], - make_dict [] - |), - ltac:(M.monadic ( - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |) - )) - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + BoolOp.or (| + M.call (| + M.get_name (| globals, "is_account_alive" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "to" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "GAS_NEW_ACCOUNT" |) + )) |) in let transfer_gas_cost := - (* if *) -M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "GAS_CALL_VALUE" |) + )) |) in let message_call_gas := M.call (| M.get_name (| globals, "calculate_message_call_gas" |), @@ -948,6 +1177,40 @@ M.call (| make_dict [] |), "balance" |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "sender_balance" |), + M.get_name (| globals, "value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "generic_call" |), make_list [ @@ -1069,6 +1332,19 @@ Definition callcode : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "code_address" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let access_gas_cost := + M.get_name (| globals, "GAS_WARM_ACCESS" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1081,21 +1357,25 @@ Definition callcode : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in let transfer_gas_cost := - (* if *) -M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "GAS_CALL_VALUE" |) + )) |) in let message_call_gas := M.call (| M.get_name (| globals, "calculate_message_call_gas" |), @@ -1146,6 +1426,40 @@ M.call (| make_dict [] |), "balance" |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "sender_balance" |), + M.get_name (| globals, "value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "generic_call" |), make_list [ @@ -1201,9 +1515,63 @@ Definition selfdestruct : Value.t -> Value.t -> M := let gas_cost := M.get_name (| globals, "GAS_SELF_DESTRUCT" |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "beneficiary" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |) in + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + UnOp.not (| M.call (| + M.get_name (| globals, "is_account_alive" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) + M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -1244,9 +1612,64 @@ Definition selfdestruct : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "originator" |), + M.get_field (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |), "created_accounts" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "originator" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |), "add" |), + make_list [ + M.get_name (| globals, "originator" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -1340,6 +1763,19 @@ Definition delegatecall : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "code_address" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let access_gas_cost := + M.get_name (| globals, "GAS_WARM_ACCESS" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1503,6 +1939,19 @@ Definition staticcall : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "to" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let access_gas_cost := + M.get_name (| globals, "GAS_WARM_ACCESS" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1662,6 +2111,6 @@ Definition revert : Value.t -> Value.t -> M := make_dict [] |) |) in - let _ := M.raise (| Some(M.get_name (| globals, "Revert" |)) + let _ := M.raise (| Some(M.get_name (| globals, "Revert" |)) |) in let _ := M.pass (| |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/vm/interpreter.v b/CoqOfPython/ethereum/cancun/vm/interpreter.v index 9732c95..8ed4da9 100644 --- a/CoqOfPython/ethereum/cancun/vm/interpreter.v +++ b/CoqOfPython/ethereum/cancun/vm/interpreter.v @@ -63,83 +63,83 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". - -Require state. -Axiom state_account_exists_and_is_empty : - IsGlobalAlias globals state.globals "account_exists_and_is_empty". -Axiom state_account_has_code_or_nonce : - IsGlobalAlias globals state.globals "account_has_code_or_nonce". -Axiom state_begin_transaction : - IsGlobalAlias globals state.globals "begin_transaction". -Axiom state_commit_transaction : - IsGlobalAlias globals state.globals "commit_transaction". -Axiom state_destroy_storage : - IsGlobalAlias globals state.globals "destroy_storage". -Axiom state_increment_nonce : - IsGlobalAlias globals state.globals "increment_nonce". -Axiom state_mark_account_created : - IsGlobalAlias globals state.globals "mark_account_created". -Axiom state_move_ether : - IsGlobalAlias globals state.globals "move_ether". -Axiom state_rollback_transaction : - IsGlobalAlias globals state.globals "rollback_transaction". -Axiom state_set_code : - IsGlobalAlias globals state.globals "set_code". -Axiom state_touch_account : - IsGlobalAlias globals state.globals "touch_account". - -Require vm. -Axiom vm_Message : - IsGlobalAlias globals vm.globals "Message". - -Require vm.gas. -Axiom vm_gas_GAS_CODE_DEPOSIT : - IsGlobalAlias globals vm.gas.globals "GAS_CODE_DEPOSIT". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". - -Require vm.precompiled_contracts.mapping. -Axiom vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : - IsGlobalAlias globals vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". - -Require __init__. -Axiom __init___Environment : - IsGlobalAlias globals __init__.globals "Environment". -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require exceptions. -Axiom exceptions_AddressCollision : - IsGlobalAlias globals exceptions.globals "AddressCollision". -Axiom exceptions_ExceptionalHalt : - IsGlobalAlias globals exceptions.globals "ExceptionalHalt". -Axiom exceptions_InvalidContractPrefix : - IsGlobalAlias globals exceptions.globals "InvalidContractPrefix". -Axiom exceptions_InvalidOpcode : - IsGlobalAlias globals exceptions.globals "InvalidOpcode". -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". -Axiom exceptions_Revert : - IsGlobalAlias globals exceptions.globals "Revert". -Axiom exceptions_StackDepthLimitError : - IsGlobalAlias globals exceptions.globals "StackDepthLimitError". - -Require instructions. -Axiom instructions_Ops : - IsGlobalAlias globals instructions.globals "Ops". -Axiom instructions_op_implementation : - IsGlobalAlias globals instructions.globals "op_implementation". - -Require runtime. -Axiom runtime_get_valid_jump_destinations : - IsGlobalAlias globals runtime.globals "get_valid_jump_destinations". +Require ethereum.cancun.blocks. +Axiom ethereum_cancun_blocks_Log : + IsGlobalAlias globals ethereum.cancun.blocks.globals "Log". + +Require ethereum.cancun.fork_types. +Axiom ethereum_cancun_fork_types_Address : + IsGlobalAlias globals ethereum.cancun.fork_types.globals "Address". + +Require ethereum.cancun.state. +Axiom ethereum_cancun_state_account_exists_and_is_empty : + IsGlobalAlias globals ethereum.cancun.state.globals "account_exists_and_is_empty". +Axiom ethereum_cancun_state_account_has_code_or_nonce : + IsGlobalAlias globals ethereum.cancun.state.globals "account_has_code_or_nonce". +Axiom ethereum_cancun_state_begin_transaction : + IsGlobalAlias globals ethereum.cancun.state.globals "begin_transaction". +Axiom ethereum_cancun_state_commit_transaction : + IsGlobalAlias globals ethereum.cancun.state.globals "commit_transaction". +Axiom ethereum_cancun_state_destroy_storage : + IsGlobalAlias globals ethereum.cancun.state.globals "destroy_storage". +Axiom ethereum_cancun_state_increment_nonce : + IsGlobalAlias globals ethereum.cancun.state.globals "increment_nonce". +Axiom ethereum_cancun_state_mark_account_created : + IsGlobalAlias globals ethereum.cancun.state.globals "mark_account_created". +Axiom ethereum_cancun_state_move_ether : + IsGlobalAlias globals ethereum.cancun.state.globals "move_ether". +Axiom ethereum_cancun_state_rollback_transaction : + IsGlobalAlias globals ethereum.cancun.state.globals "rollback_transaction". +Axiom ethereum_cancun_state_set_code : + IsGlobalAlias globals ethereum.cancun.state.globals "set_code". +Axiom ethereum_cancun_state_touch_account : + IsGlobalAlias globals ethereum.cancun.state.globals "touch_account". + +Require ethereum.cancun.vm.__init__. +Axiom ethereum_cancun_vm___init___Message : + IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Message". + +Require ethereum.cancun.vm.gas. +Axiom ethereum_cancun_vm_gas_GAS_CODE_DEPOSIT : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_CODE_DEPOSIT". +Axiom ethereum_cancun_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "charge_gas". + +Require ethereum.cancun.vm.precompiled_contracts.mapping. +Axiom ethereum_cancun_vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : + IsGlobalAlias globals ethereum.cancun.vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". + +Require ethereum.cancun.vm.__init__. +Axiom ethereum_cancun_vm___init___Environment : + IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Environment". +Axiom ethereum_cancun_vm___init___Evm : + IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Evm". + +Require ethereum.cancun.vm.exceptions. +Axiom ethereum_cancun_vm_exceptions_AddressCollision : + IsGlobalAlias globals ethereum.cancun.vm.exceptions.globals "AddressCollision". +Axiom ethereum_cancun_vm_exceptions_ExceptionalHalt : + IsGlobalAlias globals ethereum.cancun.vm.exceptions.globals "ExceptionalHalt". +Axiom ethereum_cancun_vm_exceptions_InvalidContractPrefix : + IsGlobalAlias globals ethereum.cancun.vm.exceptions.globals "InvalidContractPrefix". +Axiom ethereum_cancun_vm_exceptions_InvalidOpcode : + IsGlobalAlias globals ethereum.cancun.vm.exceptions.globals "InvalidOpcode". +Axiom ethereum_cancun_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.cancun.vm.exceptions.globals "OutOfGasError". +Axiom ethereum_cancun_vm_exceptions_Revert : + IsGlobalAlias globals ethereum.cancun.vm.exceptions.globals "Revert". +Axiom ethereum_cancun_vm_exceptions_StackDepthLimitError : + IsGlobalAlias globals ethereum.cancun.vm.exceptions.globals "StackDepthLimitError". + +Require ethereum.cancun.vm.instructions.__init__. +Axiom ethereum_cancun_vm_instructions___init___Ops : + IsGlobalAlias globals ethereum.cancun.vm.instructions.__init__.globals "Ops". +Axiom ethereum_cancun_vm_instructions___init___op_implementation : + IsGlobalAlias globals ethereum.cancun.vm.instructions.__init__.globals "op_implementation". + +Require ethereum.cancun.vm.runtime. +Axiom ethereum_cancun_vm_runtime_get_valid_jump_destinations : + IsGlobalAlias globals ethereum.cancun.vm.runtime.globals "get_valid_jump_destinations". Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -186,6 +186,94 @@ Definition process_message_call : Value.t -> Value.t -> M := Output of the message call " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "message" |), "target" |), + M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) + |), + (* then *) + ltac:(M.monadic ( + let is_collision := + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_name (| globals, "is_collision" |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallOutput" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "tuple" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "AddressCollision" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let evm := + M.call (| + M.get_name (| globals, "process_create_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let evm := M.call (| M.get_name (| globals, "process_message" |), @@ -196,11 +284,74 @@ Definition process_message_call : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_field (| M.get_name (| globals, "message" |), "target" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_field (| M.get_name (| globals, "message" |), "target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( +(* At stmt: unsupported node type: AnnAssign *) + let accounts_to_delete := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let touched_accounts := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let refund_counter := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let logs := M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in let accounts_to_delete := @@ -244,6 +395,7 @@ Definition process_message_call : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). Definition process_create_message : Value.t -> Value.t -> M := @@ -306,6 +458,28 @@ Definition process_create_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), + (* then *) + ltac:(M.monadic ( + let contract_code := + M.get_field (| M.get_name (| globals, "evm" |), "output" |) in + let contract_code_gas := + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "contract_code" |) + ], + make_dict [] + |), + M.get_name (| globals, "GAS_CODE_DEPOSIT" |) + |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "rollback_transaction" |), make_list [ @@ -318,6 +492,7 @@ Definition process_create_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) + |) in M.pure Constant.None_)). Definition process_message : Value.t -> Value.t -> M := @@ -339,6 +514,24 @@ Definition process_message : Value.t -> Value.t -> M := Items containing execution specific objects " in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_field (| M.get_name (| globals, "message" |), "depth" |), + M.get_name (| globals, "STACK_DEPTH_LIMIT" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "StackDepthLimitError" |), + make_list [ + Constant.str "Stack depth limit reached" + ], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -358,6 +551,32 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + M.get_field (| M.get_name (| globals, "message" |), "should_transfer_value" |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "message" |), "value" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "move_ether" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "caller" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |); + M.get_field (| M.get_name (| globals, "message" |), "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let evm := @@ -370,6 +589,22 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "rollback_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "transient_storage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "commit_transaction" |), make_list [ @@ -382,6 +617,7 @@ Definition process_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) + |) in M.pure Constant.None_)). Definition execute_code : Value.t -> Value.t -> M := @@ -421,4 +657,5 @@ Definition execute_code : Value.t -> Value.t -> M := (* At stmt: unsupported node type: Try *) let _ := M.return_ (| M.get_name (| globals, "evm" |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/vm/memory.v b/CoqOfPython/ethereum/cancun/vm/memory.v index 4b107fd..08d2290 100644 --- a/CoqOfPython/ethereum/cancun/vm/memory.v +++ b/CoqOfPython/ethereum/cancun/vm/memory.v @@ -21,13 +21,13 @@ Require ethereum.utils.byte. Axiom ethereum_utils_byte_right_pad_zero_bytes : IsGlobalAlias globals ethereum.utils.byte.globals "right_pad_zero_bytes". -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". Definition memory_write : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,7 +45,22 @@ Definition memory_write : Value.t -> Value.t -> M := Data to write to memory. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |), + M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) |) |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_)). @@ -71,7 +86,23 @@ Definition memory_read_bytes : Value.t -> Value.t -> M := Data read from memory. " in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |) + M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |) |) + |) in M.pure Constant.None_)). Definition buffer_read : Value.t -> Value.t -> M := @@ -98,9 +129,25 @@ Definition buffer_read : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "right_pad_zero_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |) |); + M.get_subscript (| M.get_name (| globals, "buffer" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |) |); M.get_name (| globals, "size" |) ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/__init__.v index b78533a..93f0111 100644 --- a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/__init__.v +++ b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/__init__.v @@ -18,9 +18,9 @@ Addresses of precompiled contracts and mappings to their implementations. ". -Require utils.hexadecimal. -Axiom utils_hexadecimal_hex_to_address : - IsGlobalAlias globals utils.hexadecimal.globals "hex_to_address". +Require ethereum.cancun.utils.hexadecimal. +Axiom ethereum_cancun_utils_hexadecimal_hex_to_address : + IsGlobalAlias globals ethereum.cancun.utils.hexadecimal.globals "hex_to_address". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS"; Constant.str "MODEXP_ADDRESS"; Constant.str "ALT_BN128_ADD_ADDRESS"; Constant.str "ALT_BN128_MUL_ADDRESS"; Constant.str "ALT_BN128_PAIRING_CHECK_ADDRESS"; Constant.str "BLAKE2F_ADDRESS"; Constant.str "POINT_EVALUATION_ADDRESS" ] diff --git a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/alt_bn128.v index abe4238..b461c47 100644 --- a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/alt_bn128.v +++ b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/alt_bn128.v @@ -45,21 +45,21 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.cancun.vm.__init__. +Axiom ethereum_cancun_vm___init___Evm : + IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.cancun.vm.gas. +Axiom ethereum_cancun_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "charge_gas". -Require vm.memory. -Axiom vm_memory_buffer_read : - IsGlobalAlias globals vm.memory.globals "buffer_read". +Require ethereum.cancun.vm.memory. +Axiom ethereum_cancun_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.cancun.vm.memory.globals "buffer_read". -Require exceptions. -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". +Require ethereum.cancun.vm.exceptions. +Axiom ethereum_cancun_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.cancun.vm.exceptions.globals "OutOfGasError". Definition alt_bn128_add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -210,6 +210,18 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) in For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ] do let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -353,6 +365,18 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) in For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ] do let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -425,6 +449,27 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| + BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 192 + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let result := @@ -464,7 +509,7 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "data" |), BinOp.add (| + M.get_subscript (| M.get_name (| globals, "data" |), M.slice (| BinOp.add (| BinOp.mult (| M.get_name (| globals, "i" |), Constant.int 192 @@ -473,11 +518,35 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := Constant.int 32, M.get_name (| globals, "j" |) |) - |) |) + |), BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "j" |), + Constant.int 1 + |) + |) + |) |) |) ], make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -538,10 +607,80 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "p" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "q" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let result := + BinOp.mult (| + M.get_name (| globals, "result" |), + M.call (| + M.get_name (| globals, "pairing" |), + make_list [ + M.get_name (| globals, "q" |); + M.get_name (| globals, "p" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "result" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| diff --git a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/blake2f.v b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/blake2f.v index 1647d48..2d21cae 100644 --- a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/blake2f.v +++ b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/blake2f.v @@ -25,19 +25,19 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.cancun.vm.__init__. +Axiom ethereum_cancun_vm___init___Evm : + IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_BLAKE2_PER_ROUND : - IsGlobalAlias globals vm.gas.globals "GAS_BLAKE2_PER_ROUND". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.cancun.vm.gas. +Axiom ethereum_cancun_vm_gas_GAS_BLAKE2_PER_ROUND : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_BLAKE2_PER_ROUND". +Axiom ethereum_cancun_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "charge_gas". -Require exceptions. -Axiom exceptions_InvalidParameter : - IsGlobalAlias globals exceptions.globals "InvalidParameter". +Require ethereum.cancun.vm.exceptions. +Axiom ethereum_cancun_vm_exceptions_InvalidParameter : + IsGlobalAlias globals ethereum.cancun.vm.exceptions.globals "InvalidParameter". Definition blake2f : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/ecrecover.v index 0cbcf16..1fc12ba 100644 --- a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/ecrecover.v @@ -37,19 +37,19 @@ Require ethereum.utils.byte. Axiom ethereum_utils_byte_left_pad_zero_bytes : IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.cancun.vm.__init__. +Axiom ethereum_cancun_vm___init___Evm : + IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_ECRECOVER : - IsGlobalAlias globals vm.gas.globals "GAS_ECRECOVER". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.cancun.vm.gas. +Axiom ethereum_cancun_vm_gas_GAS_ECRECOVER : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_ECRECOVER". +Axiom ethereum_cancun_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "charge_gas". -Require vm.memory. -Axiom vm_memory_buffer_read : - IsGlobalAlias globals vm.memory.globals "buffer_read". +Require ethereum.cancun.vm.memory. +Axiom ethereum_cancun_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.cancun.vm.memory.globals "buffer_read". Definition ecrecover : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -188,12 +188,78 @@ Definition ecrecover : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "v" |), + Constant.int 27 + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "v" |), + Constant.int 28 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + Constant.int 0, + M.get_name (| globals, "r" |) + |), + ltac:(M.monadic ( + Compare.gt_e (| + M.get_name (| globals, "r" |), + M.get_name (| globals, "SECP256K1N" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + Constant.int 0, + M.get_name (| globals, "s" |) + |), + ltac:(M.monadic ( + Compare.gt_e (| + M.get_name (| globals, "s" |), + M.get_name (| globals, "SECP256K1N" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: Try *) @@ -204,7 +270,7 @@ Definition ecrecover : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12 |) in + |), M.slice (| Constant.int 12, Constant.int 32 |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/identity.v index fa96704..ce9b2e7 100644 --- a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/identity.v +++ b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/identity.v @@ -25,17 +25,17 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.cancun.vm.__init__. +Axiom ethereum_cancun_vm___init___Evm : + IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_IDENTITY : - IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY". -Axiom vm_gas_GAS_IDENTITY_WORD : - IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY_WORD". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.cancun.vm.gas. +Axiom ethereum_cancun_vm_gas_GAS_IDENTITY : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_IDENTITY". +Axiom ethereum_cancun_vm_gas_GAS_IDENTITY_WORD : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_IDENTITY_WORD". +Axiom ethereum_cancun_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "charge_gas". Definition identity : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/mapping.v index 062ec88..52973e3 100644 --- a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/mapping.v +++ b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/mapping.v @@ -23,66 +23,66 @@ Axiom typing_Callable : Axiom typing_Dict : IsGlobalAlias globals typing.globals "Dict". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". - -Require __init__. -Axiom __init___ALT_BN128_ADD_ADDRESS : - IsGlobalAlias globals __init__.globals "ALT_BN128_ADD_ADDRESS". -Axiom __init___ALT_BN128_MUL_ADDRESS : - IsGlobalAlias globals __init__.globals "ALT_BN128_MUL_ADDRESS". -Axiom __init___ALT_BN128_PAIRING_CHECK_ADDRESS : - IsGlobalAlias globals __init__.globals "ALT_BN128_PAIRING_CHECK_ADDRESS". -Axiom __init___BLAKE2F_ADDRESS : - IsGlobalAlias globals __init__.globals "BLAKE2F_ADDRESS". -Axiom __init___ECRECOVER_ADDRESS : - IsGlobalAlias globals __init__.globals "ECRECOVER_ADDRESS". -Axiom __init___IDENTITY_ADDRESS : - IsGlobalAlias globals __init__.globals "IDENTITY_ADDRESS". -Axiom __init___MODEXP_ADDRESS : - IsGlobalAlias globals __init__.globals "MODEXP_ADDRESS". -Axiom __init___POINT_EVALUATION_ADDRESS : - IsGlobalAlias globals __init__.globals "POINT_EVALUATION_ADDRESS". -Axiom __init___RIPEMD160_ADDRESS : - IsGlobalAlias globals __init__.globals "RIPEMD160_ADDRESS". -Axiom __init___SHA256_ADDRESS : - IsGlobalAlias globals __init__.globals "SHA256_ADDRESS". - -Require alt_bn128. -Axiom alt_bn128_alt_bn128_add : - IsGlobalAlias globals alt_bn128.globals "alt_bn128_add". -Axiom alt_bn128_alt_bn128_mul : - IsGlobalAlias globals alt_bn128.globals "alt_bn128_mul". -Axiom alt_bn128_alt_bn128_pairing_check : - IsGlobalAlias globals alt_bn128.globals "alt_bn128_pairing_check". - -Require blake2f. -Axiom blake2f_blake2f : - IsGlobalAlias globals blake2f.globals "blake2f". - -Require ecrecover. -Axiom ecrecover_ecrecover : - IsGlobalAlias globals ecrecover.globals "ecrecover". - -Require identity. -Axiom identity_identity : - IsGlobalAlias globals identity.globals "identity". - -Require modexp. -Axiom modexp_modexp : - IsGlobalAlias globals modexp.globals "modexp". - -Require point_evaluation. -Axiom point_evaluation_point_evaluation : - IsGlobalAlias globals point_evaluation.globals "point_evaluation". - -Require ripemd160. -Axiom ripemd160_ripemd160 : - IsGlobalAlias globals ripemd160.globals "ripemd160". - -Require sha256. -Axiom sha256_sha256 : - IsGlobalAlias globals sha256.globals "sha256". +Require ethereum.cancun.fork_types. +Axiom ethereum_cancun_fork_types_Address : + IsGlobalAlias globals ethereum.cancun.fork_types.globals "Address". + +Require ethereum.cancun.vm.precompiled_contracts.__init__. +Axiom ethereum_cancun_vm_precompiled_contracts___init___ALT_BN128_ADD_ADDRESS : + IsGlobalAlias globals ethereum.cancun.vm.precompiled_contracts.__init__.globals "ALT_BN128_ADD_ADDRESS". +Axiom ethereum_cancun_vm_precompiled_contracts___init___ALT_BN128_MUL_ADDRESS : + IsGlobalAlias globals ethereum.cancun.vm.precompiled_contracts.__init__.globals "ALT_BN128_MUL_ADDRESS". +Axiom ethereum_cancun_vm_precompiled_contracts___init___ALT_BN128_PAIRING_CHECK_ADDRESS : + IsGlobalAlias globals ethereum.cancun.vm.precompiled_contracts.__init__.globals "ALT_BN128_PAIRING_CHECK_ADDRESS". +Axiom ethereum_cancun_vm_precompiled_contracts___init___BLAKE2F_ADDRESS : + IsGlobalAlias globals ethereum.cancun.vm.precompiled_contracts.__init__.globals "BLAKE2F_ADDRESS". +Axiom ethereum_cancun_vm_precompiled_contracts___init___ECRECOVER_ADDRESS : + IsGlobalAlias globals ethereum.cancun.vm.precompiled_contracts.__init__.globals "ECRECOVER_ADDRESS". +Axiom ethereum_cancun_vm_precompiled_contracts___init___IDENTITY_ADDRESS : + IsGlobalAlias globals ethereum.cancun.vm.precompiled_contracts.__init__.globals "IDENTITY_ADDRESS". +Axiom ethereum_cancun_vm_precompiled_contracts___init___MODEXP_ADDRESS : + IsGlobalAlias globals ethereum.cancun.vm.precompiled_contracts.__init__.globals "MODEXP_ADDRESS". +Axiom ethereum_cancun_vm_precompiled_contracts___init___POINT_EVALUATION_ADDRESS : + IsGlobalAlias globals ethereum.cancun.vm.precompiled_contracts.__init__.globals "POINT_EVALUATION_ADDRESS". +Axiom ethereum_cancun_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : + IsGlobalAlias globals ethereum.cancun.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". +Axiom ethereum_cancun_vm_precompiled_contracts___init___SHA256_ADDRESS : + IsGlobalAlias globals ethereum.cancun.vm.precompiled_contracts.__init__.globals "SHA256_ADDRESS". + +Require ethereum.cancun.vm.precompiled_contracts.alt_bn128. +Axiom ethereum_cancun_vm_precompiled_contracts_alt_bn128_alt_bn128_add : + IsGlobalAlias globals ethereum.cancun.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_add". +Axiom ethereum_cancun_vm_precompiled_contracts_alt_bn128_alt_bn128_mul : + IsGlobalAlias globals ethereum.cancun.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_mul". +Axiom ethereum_cancun_vm_precompiled_contracts_alt_bn128_alt_bn128_pairing_check : + IsGlobalAlias globals ethereum.cancun.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_pairing_check". + +Require ethereum.cancun.vm.precompiled_contracts.blake2f. +Axiom ethereum_cancun_vm_precompiled_contracts_blake2f_blake2f : + IsGlobalAlias globals ethereum.cancun.vm.precompiled_contracts.blake2f.globals "blake2f". + +Require ethereum.cancun.vm.precompiled_contracts.ecrecover. +Axiom ethereum_cancun_vm_precompiled_contracts_ecrecover_ecrecover : + IsGlobalAlias globals ethereum.cancun.vm.precompiled_contracts.ecrecover.globals "ecrecover". + +Require ethereum.cancun.vm.precompiled_contracts.identity. +Axiom ethereum_cancun_vm_precompiled_contracts_identity_identity : + IsGlobalAlias globals ethereum.cancun.vm.precompiled_contracts.identity.globals "identity". + +Require ethereum.cancun.vm.precompiled_contracts.modexp. +Axiom ethereum_cancun_vm_precompiled_contracts_modexp_modexp : + IsGlobalAlias globals ethereum.cancun.vm.precompiled_contracts.modexp.globals "modexp". + +Require ethereum.cancun.vm.precompiled_contracts.point_evaluation. +Axiom ethereum_cancun_vm_precompiled_contracts_point_evaluation_point_evaluation : + IsGlobalAlias globals ethereum.cancun.vm.precompiled_contracts.point_evaluation.globals "point_evaluation". + +Require ethereum.cancun.vm.precompiled_contracts.ripemd160. +Axiom ethereum_cancun_vm_precompiled_contracts_ripemd160_ripemd160 : + IsGlobalAlias globals ethereum.cancun.vm.precompiled_contracts.ripemd160.globals "ripemd160". + +Require ethereum.cancun.vm.precompiled_contracts.sha256. +Axiom ethereum_cancun_vm_precompiled_contracts_sha256_sha256 : + IsGlobalAlias globals ethereum.cancun.vm.precompiled_contracts.sha256.globals "sha256". (* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/modexp.v index 3505244..b1c90a6 100644 --- a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/modexp.v +++ b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/modexp.v @@ -25,17 +25,17 @@ Axiom ethereum_base_types_Bytes : Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.cancun.vm.__init__. +Axiom ethereum_cancun_vm___init___Evm : + IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.cancun.vm.gas. +Axiom ethereum_cancun_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "charge_gas". -Require memory. -Axiom memory_buffer_read : - IsGlobalAlias globals memory.globals "buffer_read". +Require ethereum.cancun.vm.memory. +Axiom ethereum_cancun_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.cancun.vm.memory.globals "buffer_read". Definition GQUADDIVISOR : Value.t := M.run ltac:(M.monadic ( Constant.int 3 @@ -192,6 +192,36 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_name (| globals, "base_length" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "modulus_length" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [], + make_dict [] + |) + |) in + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let base := @@ -254,6 +284,30 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "modulus" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + BinOp.mult (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + Constant.bytes "00" + ], + make_dict [] + |), + M.get_name (| globals, "modulus_length" |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| @@ -338,6 +392,7 @@ Definition complexity : Value.t -> Value.t -> M := M.get_name (| globals, "words" |), Constant.int 2 |) + |) in M.pure Constant.None_)). Definition iterations : Value.t -> Value.t -> M := @@ -364,7 +419,76 @@ Definition iterations : Value.t -> Value.t -> M := Number of iterations. " in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.lt_e (| + M.get_name (| globals, "exponent_length" |), + Constant.int 32 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "exponent_head" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let count := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "exponent_length" |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let bit_length := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "exponent_head" |), "bit_length" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "bit_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let bit_length := BinOp.sub + Constant.int 1 + Constant.int 1 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let count := + M.get_name (| globals, "bit_length" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let length_part := BinOp.mult (| Constant.int 8, @@ -392,6 +516,20 @@ Definition iterations : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "bits_part" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let bits_part := BinOp.sub + Constant.int 1 + Constant.int 1 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let count := @@ -418,6 +556,7 @@ Definition iterations : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition gas_cost : Value.t -> Value.t -> M := @@ -489,4 +628,5 @@ Definition gas_cost : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/point_evaluation.v b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/point_evaluation.v index 741aab6..50fe7bc 100644 --- a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/point_evaluation.v +++ b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/point_evaluation.v @@ -35,19 +35,19 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.cancun.vm.__init__. +Axiom ethereum_cancun_vm___init___Evm : + IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Evm". -Require vm.exceptions. -Axiom vm_exceptions_KZGProofError : - IsGlobalAlias globals vm.exceptions.globals "KZGProofError". +Require ethereum.cancun.vm.exceptions. +Axiom ethereum_cancun_vm_exceptions_KZGProofError : + IsGlobalAlias globals ethereum.cancun.vm.exceptions.globals "KZGProofError". -Require vm.gas. -Axiom vm_gas_GAS_POINT_EVALUATION : - IsGlobalAlias globals vm.gas.globals "GAS_POINT_EVALUATION". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.cancun.vm.gas. +Axiom ethereum_cancun_vm_gas_GAS_POINT_EVALUATION : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_POINT_EVALUATION". +Axiom ethereum_cancun_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "charge_gas". Definition FIELD_ELEMENTS_PER_BLOB : Value.t := M.run ltac:(M.monadic ( Constant.int 4096 @@ -94,21 +94,21 @@ Definition point_evaluation : Value.t -> Value.t -> M := make_dict [] |) in let versioned_hash := - M.get_subscript (| M.get_name (| globals, "data" |), Constant.None_:Constant.int 32 |) in + M.get_subscript (| M.get_name (| globals, "data" |), M.slice (| Constant.None_, Constant.int 32 |) |) in let z := - M.get_subscript (| M.get_name (| globals, "data" |), Constant.int 32 |) in + M.get_subscript (| M.get_name (| globals, "data" |), M.slice (| Constant.int 32, Constant.int 64 |) |) in let y := - M.get_subscript (| M.get_name (| globals, "data" |), Constant.int 64 |) in + M.get_subscript (| M.get_name (| globals, "data" |), M.slice (| Constant.int 64, Constant.int 96 |) |) in let commitment := M.call (| M.get_name (| globals, "KZGCommitment" |), make_list [ - M.get_subscript (| M.get_name (| globals, "data" |), Constant.int 96 |) + M.get_subscript (| M.get_name (| globals, "data" |), M.slice (| Constant.int 96, Constant.int 144 |) |) ], make_dict [] |) in let proof := - M.get_subscript (| M.get_name (| globals, "data" |), Constant.int 144 |) in + M.get_subscript (| M.get_name (| globals, "data" |), M.slice (| Constant.int 144, Constant.int 192 |) |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ diff --git a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/ripemd160.v index 96f8dcd..03543d2 100644 --- a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/ripemd160.v +++ b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/ripemd160.v @@ -31,17 +31,17 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.cancun.vm.__init__. +Axiom ethereum_cancun_vm___init___Evm : + IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_RIPEMD160 : - IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160". -Axiom vm_gas_GAS_RIPEMD160_WORD : - IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160_WORD". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.cancun.vm.gas. +Axiom ethereum_cancun_vm_gas_GAS_RIPEMD160 : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_RIPEMD160". +Axiom ethereum_cancun_vm_gas_GAS_RIPEMD160_WORD : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_RIPEMD160_WORD". +Axiom ethereum_cancun_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "charge_gas". Definition ripemd160 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/sha256.v index 9f6d2bf..c1dd853 100644 --- a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/sha256.v +++ b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/sha256.v @@ -27,17 +27,17 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.cancun.vm.__init__. +Axiom ethereum_cancun_vm___init___Evm : + IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_SHA256 : - IsGlobalAlias globals vm.gas.globals "GAS_SHA256". -Axiom vm_gas_GAS_SHA256_WORD : - IsGlobalAlias globals vm.gas.globals "GAS_SHA256_WORD". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.cancun.vm.gas. +Axiom ethereum_cancun_vm_gas_GAS_SHA256 : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_SHA256". +Axiom ethereum_cancun_vm_gas_GAS_SHA256_WORD : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_SHA256_WORD". +Axiom ethereum_cancun_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.cancun.vm.gas.globals "charge_gas". Definition sha256 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/cancun/vm/runtime.v b/CoqOfPython/ethereum/cancun/vm/runtime.v index 2cd7652..238d0df 100644 --- a/CoqOfPython/ethereum/cancun/vm/runtime.v +++ b/CoqOfPython/ethereum/cancun/vm/runtime.v @@ -25,9 +25,9 @@ Require ethereum.base_types. Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require instructions. -Axiom instructions_Ops : - IsGlobalAlias globals instructions.globals "Ops". +Require ethereum.cancun.vm.instructions.__init__. +Axiom ethereum_cancun_vm_instructions___init___Ops : + IsGlobalAlias globals ethereum.cancun.vm.instructions.__init__.globals "Ops". Definition get_valid_jump_destinations : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -79,7 +79,55 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := |) do (* At stmt: unsupported node type: Try *) let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "current_opcode" |), + M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), + make_list [ + M.get_name (| globals, "pc" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.lt_e (| + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |), + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH32" |), "value" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let push_data_size := + BinOp.add (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) + |), + Constant.int 1 + |) in + let pc := BinOp.add + M.get_name (| globals, "push_data_size" |) + M.get_name (| globals, "push_data_size" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -90,4 +138,5 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := EndWhile. let _ := M.return_ (| M.get_name (| globals, "valid_jump_destinations" |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/vm/stack.v b/CoqOfPython/ethereum/cancun/vm/stack.v index ea778df..f6dfd56 100644 --- a/CoqOfPython/ethereum/cancun/vm/stack.v +++ b/CoqOfPython/ethereum/cancun/vm/stack.v @@ -25,11 +25,11 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require exceptions. -Axiom exceptions_StackOverflowError : - IsGlobalAlias globals exceptions.globals "StackOverflowError". -Axiom exceptions_StackUnderflowError : - IsGlobalAlias globals exceptions.globals "StackUnderflowError". +Require ethereum.cancun.vm.exceptions. +Axiom ethereum_cancun_vm_exceptions_StackOverflowError : + IsGlobalAlias globals ethereum.cancun.vm.exceptions.globals "StackOverflowError". +Axiom ethereum_cancun_vm_exceptions_StackUnderflowError : + IsGlobalAlias globals ethereum.cancun.vm.exceptions.globals "StackUnderflowError". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -49,6 +49,24 @@ Definition pop : Value.t -> Value.t -> M := " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "StackUnderflowError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -57,6 +75,7 @@ Definition pop : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). Definition push : Value.t -> Value.t -> M := @@ -75,6 +94,24 @@ Definition push : Value.t -> Value.t -> M := " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), + Constant.int 1024 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "StackOverflowError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -85,4 +122,5 @@ Definition push : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/blocks.v b/CoqOfPython/ethereum/constantinople/blocks.v index 6501788..ef524dc 100644 --- a/CoqOfPython/ethereum/constantinople/blocks.v +++ b/CoqOfPython/ethereum/constantinople/blocks.v @@ -22,35 +22,35 @@ Require typing. Axiom typing_Tuple : IsGlobalAlias globals typing.globals "Tuple". -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes8 : - IsGlobalAlias globals base_types.globals "Bytes8". -Axiom base_types_Bytes32 : - IsGlobalAlias globals base_types.globals "Bytes32". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require crypto.hash. -Axiom crypto_hash_Hash32 : - IsGlobalAlias globals crypto.hash.globals "Hash32". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". - -Require transactions. -Axiom transactions_Transaction : - IsGlobalAlias globals transactions.globals "Transaction". +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes8 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes8". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". + +Require ethereum.constantinople.fork_types. +Axiom ethereum_constantinople_fork_types_Address : + IsGlobalAlias globals ethereum.constantinople.fork_types.globals "Address". +Axiom ethereum_constantinople_fork_types_Bloom : + IsGlobalAlias globals ethereum.constantinople.fork_types.globals "Bloom". +Axiom ethereum_constantinople_fork_types_Root : + IsGlobalAlias globals ethereum.constantinople.fork_types.globals "Root". + +Require ethereum.constantinople.transactions. +Axiom ethereum_constantinople_transactions_Transaction : + IsGlobalAlias globals ethereum.constantinople.transactions.globals "Transaction". Definition Header : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/constantinople/bloom.v b/CoqOfPython/ethereum/constantinople/bloom.v index 04650ff..90f926e 100644 --- a/CoqOfPython/ethereum/constantinople/bloom.v +++ b/CoqOfPython/ethereum/constantinople/bloom.v @@ -33,13 +33,13 @@ Require ethereum.crypto.hash. Axiom ethereum_crypto_hash_keccak256 : IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". +Require ethereum.constantinople.blocks. +Axiom ethereum_constantinople_blocks_Log : + IsGlobalAlias globals ethereum.constantinople.blocks.globals "Log". -Require fork_types. -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". +Require ethereum.constantinople.fork_types. +Axiom ethereum_constantinople_fork_types_Bloom : + IsGlobalAlias globals ethereum.constantinople.fork_types.globals "Bloom". Definition add_to_bloom : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -72,7 +72,10 @@ Definition add_to_bloom : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |) |) + M.get_subscript (| M.get_name (| globals, "hash" |), M.slice (| M.get_name (| globals, "idx" |), BinOp.add (| + M.get_name (| globals, "idx" |), + Constant.int 2 + |) |) |) ], make_dict [] |), @@ -157,4 +160,5 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/fork.v b/CoqOfPython/ethereum/constantinople/fork.v index bd55602..7105bb0 100644 --- a/CoqOfPython/ethereum/constantinople/fork.v +++ b/CoqOfPython/ethereum/constantinople/fork.v @@ -63,93 +63,93 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U64 : - IsGlobalAlias globals base_types.globals "U64". -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_U256_CEIL_VALUE : - IsGlobalAlias globals base_types.globals "U256_CEIL_VALUE". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". - -Require __init__. -Axiom __init___vm : - IsGlobalAlias globals __init__.globals "vm". - -Require blocks. -Axiom blocks_Block : - IsGlobalAlias globals blocks.globals "Block". -Axiom blocks_Header : - IsGlobalAlias globals blocks.globals "Header". -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". -Axiom blocks_Receipt : - IsGlobalAlias globals blocks.globals "Receipt". - -Require bloom. -Axiom bloom_logs_bloom : - IsGlobalAlias globals bloom.globals "logs_bloom". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". - -Require state. -Axiom state_State : - IsGlobalAlias globals state.globals "State". -Axiom state_account_exists_and_is_empty : - IsGlobalAlias globals state.globals "account_exists_and_is_empty". -Axiom state_create_ether : - IsGlobalAlias globals state.globals "create_ether". -Axiom state_destroy_account : - IsGlobalAlias globals state.globals "destroy_account". -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". -Axiom state_increment_nonce : - IsGlobalAlias globals state.globals "increment_nonce". -Axiom state_set_account_balance : - IsGlobalAlias globals state.globals "set_account_balance". -Axiom state_state_root : - IsGlobalAlias globals state.globals "state_root". - -Require transactions. -Axiom transactions_TX_BASE_COST : - IsGlobalAlias globals transactions.globals "TX_BASE_COST". -Axiom transactions_TX_CREATE_COST : - IsGlobalAlias globals transactions.globals "TX_CREATE_COST". -Axiom transactions_TX_DATA_COST_PER_NON_ZERO : - IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_NON_ZERO". -Axiom transactions_TX_DATA_COST_PER_ZERO : - IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_ZERO". -Axiom transactions_Transaction : - IsGlobalAlias globals transactions.globals "Transaction". - -Require trie. -Axiom trie_Trie : - IsGlobalAlias globals trie.globals "Trie". -Axiom trie_root : - IsGlobalAlias globals trie.globals "root". -Axiom trie_trie_set : - IsGlobalAlias globals trie.globals "trie_set". - -Require utils.message. -Axiom utils_message_prepare_message : - IsGlobalAlias globals utils.message.globals "prepare_message". - -Require vm.interpreter. -Axiom vm_interpreter_process_message_call : - IsGlobalAlias globals vm.interpreter.globals "process_message_call". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U64 : + IsGlobalAlias globals ethereum.base_types.globals "U64". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_U256_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.constantinople.__init__. +Axiom ethereum_constantinople___init___vm : + IsGlobalAlias globals ethereum.constantinople.__init__.globals "vm". + +Require ethereum.constantinople.blocks. +Axiom ethereum_constantinople_blocks_Block : + IsGlobalAlias globals ethereum.constantinople.blocks.globals "Block". +Axiom ethereum_constantinople_blocks_Header : + IsGlobalAlias globals ethereum.constantinople.blocks.globals "Header". +Axiom ethereum_constantinople_blocks_Log : + IsGlobalAlias globals ethereum.constantinople.blocks.globals "Log". +Axiom ethereum_constantinople_blocks_Receipt : + IsGlobalAlias globals ethereum.constantinople.blocks.globals "Receipt". + +Require ethereum.constantinople.bloom. +Axiom ethereum_constantinople_bloom_logs_bloom : + IsGlobalAlias globals ethereum.constantinople.bloom.globals "logs_bloom". + +Require ethereum.constantinople.fork_types. +Axiom ethereum_constantinople_fork_types_Address : + IsGlobalAlias globals ethereum.constantinople.fork_types.globals "Address". +Axiom ethereum_constantinople_fork_types_Bloom : + IsGlobalAlias globals ethereum.constantinople.fork_types.globals "Bloom". +Axiom ethereum_constantinople_fork_types_Root : + IsGlobalAlias globals ethereum.constantinople.fork_types.globals "Root". + +Require ethereum.constantinople.state. +Axiom ethereum_constantinople_state_State : + IsGlobalAlias globals ethereum.constantinople.state.globals "State". +Axiom ethereum_constantinople_state_account_exists_and_is_empty : + IsGlobalAlias globals ethereum.constantinople.state.globals "account_exists_and_is_empty". +Axiom ethereum_constantinople_state_create_ether : + IsGlobalAlias globals ethereum.constantinople.state.globals "create_ether". +Axiom ethereum_constantinople_state_destroy_account : + IsGlobalAlias globals ethereum.constantinople.state.globals "destroy_account". +Axiom ethereum_constantinople_state_get_account : + IsGlobalAlias globals ethereum.constantinople.state.globals "get_account". +Axiom ethereum_constantinople_state_increment_nonce : + IsGlobalAlias globals ethereum.constantinople.state.globals "increment_nonce". +Axiom ethereum_constantinople_state_set_account_balance : + IsGlobalAlias globals ethereum.constantinople.state.globals "set_account_balance". +Axiom ethereum_constantinople_state_state_root : + IsGlobalAlias globals ethereum.constantinople.state.globals "state_root". + +Require ethereum.constantinople.transactions. +Axiom ethereum_constantinople_transactions_TX_BASE_COST : + IsGlobalAlias globals ethereum.constantinople.transactions.globals "TX_BASE_COST". +Axiom ethereum_constantinople_transactions_TX_CREATE_COST : + IsGlobalAlias globals ethereum.constantinople.transactions.globals "TX_CREATE_COST". +Axiom ethereum_constantinople_transactions_TX_DATA_COST_PER_NON_ZERO : + IsGlobalAlias globals ethereum.constantinople.transactions.globals "TX_DATA_COST_PER_NON_ZERO". +Axiom ethereum_constantinople_transactions_TX_DATA_COST_PER_ZERO : + IsGlobalAlias globals ethereum.constantinople.transactions.globals "TX_DATA_COST_PER_ZERO". +Axiom ethereum_constantinople_transactions_Transaction : + IsGlobalAlias globals ethereum.constantinople.transactions.globals "Transaction". + +Require ethereum.constantinople.trie. +Axiom ethereum_constantinople_trie_Trie : + IsGlobalAlias globals ethereum.constantinople.trie.globals "Trie". +Axiom ethereum_constantinople_trie_root : + IsGlobalAlias globals ethereum.constantinople.trie.globals "root". +Axiom ethereum_constantinople_trie_trie_set : + IsGlobalAlias globals ethereum.constantinople.trie.globals "trie_set". + +Require ethereum.constantinople.utils.message. +Axiom ethereum_constantinople_utils_message_prepare_message : + IsGlobalAlias globals ethereum.constantinople.utils.message.globals "prepare_message". + +Require ethereum.constantinople.vm.interpreter. +Axiom ethereum_constantinople_vm_interpreter_process_message_call : + IsGlobalAlias globals ethereum.constantinople.vm.interpreter.globals "process_message_call". Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -242,6 +242,7 @@ Definition apply_fork : Value.t -> Value.t -> M := " in let _ := M.return_ (| M.get_name (| globals, "old" |) + |) in M.pure Constant.None_)). Definition get_last_256_block_hashes : Value.t -> Value.t -> M := @@ -267,8 +268,28 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := Hashes of the recent 256 blocks in order of increasing block number. " in let recent_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |) |) in + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "recent_blocks" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + make_list [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let recent_block_hashes := @@ -307,6 +328,7 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "recent_block_hashes" |) + |) in M.pure Constant.None_)). Definition state_transition : Value.t -> Value.t -> M := @@ -438,6 +460,27 @@ Definition state_transition : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |) + ], + make_dict [] + |), + Constant.int 255 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -630,6 +673,7 @@ Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition validate_proof_of_work : Value.t -> Value.t -> M := @@ -764,6 +808,7 @@ Definition check_transaction : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "sender_address" |) + |) in M.pure Constant.None_)). Definition make_receipt : Value.t -> Value.t -> M := @@ -797,6 +842,7 @@ Definition make_receipt : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "receipt" |) + |) in M.pure Constant.None_)). Definition ApplyBodyOutput : Value.t := @@ -1007,6 +1053,7 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition validate_ommers : Value.t -> Value.t -> M := @@ -1059,6 +1106,26 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do @@ -1116,7 +1183,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let ommers_hashes := - (* At expr: unsupported node type: ListComp *) in + Constant.str "(* At expr: unsupported node type: ListComp *)" in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1147,19 +1214,19 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let recent_canonical_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| BinOp.add (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| BinOp.add (| M.get_name (| globals, "MAX_OMMER_DEPTH" |), Constant.int 1 - |) |) |) in + |) |), Constant.None_ |) |) in let recent_canonical_block_hashes := - (* At expr: unsupported node type: SetComp *) in + Constant.str "(* At expr: unsupported node type: SetComp *)" in (* At stmt: unsupported node type: AnnAssign *) For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_canonical_blocks" |) do let recent_ommers_hashes := M.call (| M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), make_list [ - (* At expr: unsupported node type: SetComp *) + Constant.str "(* At expr: unsupported node type: SetComp *)" ], make_dict [] |) in @@ -1573,7 +1640,50 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "transaction_fee" |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| + M.get_name (| globals, "coinbase_balance_after_mining_fee" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |); + M.get_name (| globals, "coinbase_balance_after_mining_fee" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -1590,11 +1700,35 @@ Definition process_transaction : Value.t -> Value.t -> M := EndFor. For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "touched_accounts" |) do let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := M.return_ (| make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |); M.get_field (| M.get_name (| globals, "output" |), "error" |) ] + |) in M.pure Constant.None_)). Definition validate_transaction : Value.t -> Value.t -> M := @@ -1649,6 +1783,7 @@ Definition validate_transaction : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := @@ -1680,6 +1815,20 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := Constant.int 0 in For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "byte" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let data_cost := BinOp.add M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in @@ -1687,6 +1836,25 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := )) |) in EndFor. let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "tx" |), "to" |), + M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) + |), + (* then *) + ltac:(M.monadic ( + let create_cost := + M.get_name (| globals, "TX_CREATE_COST" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let create_cost := Constant.int 0 in M.pure Constant.None_ @@ -1705,6 +1873,7 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition recover_sender : Value.t -> Value.t -> M := @@ -1777,6 +1946,45 @@ Definition recover_sender : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.eq (| + M.get_name (| globals, "v" |), + Constant.int 27 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "v" |), + Constant.int 28 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + BinOp.sub (| + M.get_name (| globals, "v" |), + Constant.int 27 + |); + M.call (| + M.get_name (| globals, "signing_hash_pre155" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1847,10 +2055,11 @@ Definition recover_sender : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12 |) + |), M.slice (| Constant.int 12, Constant.int 32 |) |) ], make_dict [] |) + |) in M.pure Constant.None_)). Definition signing_hash_pre155 : Value.t -> Value.t -> M := @@ -1883,6 +2092,7 @@ Definition signing_hash_pre155 : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition signing_hash_155 : Value.t -> Value.t -> M := @@ -1929,6 +2139,7 @@ Definition signing_hash_155 : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition compute_header_hash : Value.t -> Value.t -> M := @@ -1979,6 +2190,7 @@ Definition compute_header_hash : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition check_gas_limit : Value.t -> Value.t -> M := @@ -2017,16 +2229,65 @@ Definition check_gas_limit : Value.t -> Value.t -> M := M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "gas_limit" |), + BinOp.add (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "gas_limit" |), + BinOp.sub (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "gas_limit" |), + M.get_name (| globals, "GAS_LIMIT_MINIMUM" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| Constant.bool true + |) in M.pure Constant.None_)). Definition calculate_block_difficulty : Value.t -> Value.t -> M := @@ -2086,12 +2347,16 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := M.get_name (| globals, "max" |), make_list [ BinOp.sub (| - (* if *) -M.if_then_else (| - M.get_name (| globals, "parent_has_ommers" |), -(* then *) -ltac:(M.monadic ( -Constant.int 2, + (* if *) + M.if_then_else (| + M.get_name (| globals, "parent_has_ommers" |), + (* then *) + ltac:(M.monadic ( +Constant.int 2 + (* else *) + )), ltac:(M.monadic ( +Constant.int 1 + )) |), BinOp.floor_div (| M.call (| M.get_name (| globals, "int" |), @@ -2140,6 +2405,26 @@ Constant.int 2, Constant.int 2 |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "num_bomb_periods" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let difficulty := BinOp.add + BinOp.pow (| + Constant.int 2, + M.get_name (| globals, "num_bomb_periods" |) + |) + BinOp.pow (| + Constant.int 2, + M.get_name (| globals, "num_bomb_periods" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -2157,4 +2442,5 @@ Constant.int 2, ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/fork_types.v b/CoqOfPython/ethereum/constantinople/fork_types.v index 5c7dac3..cc8e4a1 100644 --- a/CoqOfPython/ethereum/constantinople/fork_types.v +++ b/CoqOfPython/ethereum/constantinople/fork_types.v @@ -21,29 +21,29 @@ Require dataclasses. Axiom dataclasses_dataclass : IsGlobalAlias globals dataclasses.globals "dataclass". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes20 : - IsGlobalAlias globals base_types.globals "Bytes20". -Axiom base_types_Bytes256 : - IsGlobalAlias globals base_types.globals "Bytes256". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require crypto.hash. -Axiom crypto_hash_Hash32 : - IsGlobalAlias globals crypto.hash.globals "Hash32". -Axiom crypto_hash_keccak256 : - IsGlobalAlias globals crypto.hash.globals "keccak256". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes20 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes20". +Axiom ethereum_base_types_Bytes256 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) @@ -98,4 +98,5 @@ Definition encode_account : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/state.v b/CoqOfPython/ethereum/constantinople/state.v index c5b604e..0d54e5a 100644 --- a/CoqOfPython/ethereum/constantinople/state.v +++ b/CoqOfPython/ethereum/constantinople/state.v @@ -54,29 +54,29 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require fork_types. -Axiom fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". -Axiom fork_types_Account : - IsGlobalAlias globals fork_types.globals "Account". -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". - -Require trie. -Axiom trie_EMPTY_TRIE_ROOT : - IsGlobalAlias globals trie.globals "EMPTY_TRIE_ROOT". -Axiom trie_Trie : - IsGlobalAlias globals trie.globals "Trie". -Axiom trie_copy_trie : - IsGlobalAlias globals trie.globals "copy_trie". -Axiom trie_root : - IsGlobalAlias globals trie.globals "root". -Axiom trie_trie_get : - IsGlobalAlias globals trie.globals "trie_get". -Axiom trie_trie_set : - IsGlobalAlias globals trie.globals "trie_set". +Require ethereum.constantinople.fork_types. +Axiom ethereum_constantinople_fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals ethereum.constantinople.fork_types.globals "EMPTY_ACCOUNT". +Axiom ethereum_constantinople_fork_types_Account : + IsGlobalAlias globals ethereum.constantinople.fork_types.globals "Account". +Axiom ethereum_constantinople_fork_types_Address : + IsGlobalAlias globals ethereum.constantinople.fork_types.globals "Address". +Axiom ethereum_constantinople_fork_types_Root : + IsGlobalAlias globals ethereum.constantinople.fork_types.globals "Root". + +Require ethereum.constantinople.trie. +Axiom ethereum_constantinople_trie_EMPTY_TRIE_ROOT : + IsGlobalAlias globals ethereum.constantinople.trie.globals "EMPTY_TRIE_ROOT". +Axiom ethereum_constantinople_trie_Trie : + IsGlobalAlias globals ethereum.constantinople.trie.globals "Trie". +Axiom ethereum_constantinople_trie_copy_trie : + IsGlobalAlias globals ethereum.constantinople.trie.globals "copy_trie". +Axiom ethereum_constantinople_trie_root : + IsGlobalAlias globals ethereum.constantinople.trie.globals "root". +Axiom ethereum_constantinople_trie_trie_get : + IsGlobalAlias globals ethereum.constantinople.trie.globals "trie_get". +Axiom ethereum_constantinople_trie_trie_set : + IsGlobalAlias globals ethereum.constantinople.trie.globals "trie_set". Definition State : Value.t := builtins.make_klass @@ -123,7 +123,7 @@ Definition begin_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) ], make_dict [] - |); (* At expr: unsupported node type: DictComp *) ] + |); Constant.str "(* At expr: unsupported node type: DictComp *)" ] ], make_dict [] |) in @@ -201,8 +201,27 @@ Definition get_account : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "account" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "account" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_ACCOUNT" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -237,6 +256,7 @@ Definition get_account_optional : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "account" |) + |) in M.pure Constant.None_)). Definition set_account : Value.t -> Value.t -> M := @@ -316,6 +336,18 @@ Definition destroy_storage : Value.t -> Value.t -> M := Address of account whose storage is to be deleted. " in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -350,6 +382,26 @@ Definition get_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "trie" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let value := @@ -371,6 +423,7 @@ Definition get_storage : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "value" |) + |) in M.pure Constant.None_)). Definition set_storage : Value.t -> Value.t -> M := @@ -411,6 +464,27 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "trie" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let trie := + M.call (| + M.get_name (| globals, "Trie" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), + M.get_name (| globals, "trie" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -423,6 +497,18 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + {} + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -447,8 +533,29 @@ Definition storage_root : Value.t -> Value.t -> M := " in let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_TRIE_ROOT" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -479,6 +586,7 @@ Definition state_root : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition account_exists : Value.t -> Value.t -> M := @@ -511,6 +619,7 @@ Definition account_exists : Value.t -> Value.t -> M := |), Constant.None_ |) + |) in M.pure Constant.None_)). Definition account_has_code_or_nonce : Value.t -> Value.t -> M := @@ -560,6 +669,7 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition is_account_empty : Value.t -> Value.t -> M := @@ -617,6 +727,7 @@ Definition is_account_empty : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition account_exists_and_is_empty : Value.t -> Value.t -> M := @@ -683,6 +794,7 @@ Definition account_exists_and_is_empty : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition is_account_alive : Value.t -> Value.t -> M := @@ -713,6 +825,20 @@ Definition is_account_alive : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "account" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| UnOp.not (| BoolOp.and (| Compare.eq (| @@ -740,6 +866,7 @@ Definition is_account_alive : Value.t -> Value.t -> M := |) )) |) |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -847,6 +974,30 @@ Definition touch_account : Value.t -> Value.t -> M := The address of the account that need to initialised. " in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "account_exists" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "EMPTY_ACCOUNT" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/transactions.v b/CoqOfPython/ethereum/constantinople/transactions.v index 6d1bc6b..e051e60 100644 --- a/CoqOfPython/ethereum/constantinople/transactions.v +++ b/CoqOfPython/ethereum/constantinople/transactions.v @@ -17,21 +17,21 @@ Require typing. Axiom typing_Union : IsGlobalAlias globals typing.globals "Union". -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes0 : - IsGlobalAlias globals base_types.globals "Bytes0". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.constantinople.fork_types. +Axiom ethereum_constantinople_fork_types_Address : + IsGlobalAlias globals ethereum.constantinople.fork_types.globals "Address". Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( Constant.int 21000 diff --git a/CoqOfPython/ethereum/constantinople/trie.v b/CoqOfPython/ethereum/constantinople/trie.v index f333170..cfed49d 100644 --- a/CoqOfPython/ethereum/constantinople/trie.v +++ b/CoqOfPython/ethereum/constantinople/trie.v @@ -50,9 +50,9 @@ Axiom typing_Union : Axiom typing_cast : IsGlobalAlias globals typing.globals "cast". -Require ethereum.byzantium. -Axiom ethereum_byzantium_trie : - IsGlobalAlias globals ethereum.byzantium.globals "trie". +Require ethereum.byzantium.__init__. +Axiom ethereum_byzantium___init___trie : + IsGlobalAlias globals ethereum.byzantium.__init__.globals "trie". Require ethereum.crypto.hash. Axiom ethereum_crypto_hash_keccak256 : @@ -66,37 +66,37 @@ Require ethereum.utils.hexadecimal. Axiom ethereum_utils_hexadecimal_hex_to_bytes : IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require blocks. -Axiom blocks_Receipt : - IsGlobalAlias globals blocks.globals "Receipt". - -Require fork_types. -Axiom fork_types_Account : - IsGlobalAlias globals fork_types.globals "Account". -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". -Axiom fork_types_encode_account : - IsGlobalAlias globals fork_types.globals "encode_account". - -Require transactions. -Axiom transactions_Transaction : - IsGlobalAlias globals transactions.globals "Transaction". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.constantinople.blocks. +Axiom ethereum_constantinople_blocks_Receipt : + IsGlobalAlias globals ethereum.constantinople.blocks.globals "Receipt". + +Require ethereum.constantinople.fork_types. +Axiom ethereum_constantinople_fork_types_Account : + IsGlobalAlias globals ethereum.constantinople.fork_types.globals "Account". +Axiom ethereum_constantinople_fork_types_Address : + IsGlobalAlias globals ethereum.constantinople.fork_types.globals "Address". +Axiom ethereum_constantinople_fork_types_Root : + IsGlobalAlias globals ethereum.constantinople.fork_types.globals "Root". +Axiom ethereum_constantinople_fork_types_encode_account : + IsGlobalAlias globals ethereum.constantinople.fork_types.globals "encode_account". + +Require ethereum.constantinople.transactions. +Axiom ethereum_constantinople_transactions_Transaction : + IsGlobalAlias globals ethereum.constantinople.transactions.globals "Transaction". Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -202,16 +202,99 @@ Definition encode_internal_node : Value.t -> Value.t -> M := " in (* At stmt: unsupported node type: AnnAssign *) let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "node" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + Constant.bytes "" in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "LeafNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "rest_of_key" |); + Constant.bool true + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "ExtensionNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "key_segment" |); + Constant.bool false + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "BranchNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + BinOp.add (| + M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "value" |) + ] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ - (* At expr: unsupported node type: JoinedStr *) + Constant.str "(* At expr: unsupported node type: JoinedStr *)" ], make_dict [] - |)) + |)) |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -229,6 +312,26 @@ Definition encode_internal_node : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded" |) + ], + make_dict [] + |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "unencoded" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_name (| globals, "keccak256" |), @@ -237,6 +340,7 @@ Definition encode_internal_node : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -250,8 +354,86 @@ Definition encode_node : Value.t -> Value.t -> M := Currently mostly an unimplemented stub. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| + M.get_name (| globals, "storage_root" |), + Constant.None_ + |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "encode_account" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "storage_root" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + make_tuple [ M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "U256" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "cast" |), + make_list [ + M.get_field (| M.get_name (| globals, "rlp" |), "RLP" |); + M.get_name (| globals, "node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "node" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "previous_trie" |), "encode_node" |), @@ -261,6 +443,7 @@ Definition encode_node : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -312,6 +495,7 @@ Definition copy_trie : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition trie_set : Value.t -> Value.t -> M := @@ -333,6 +517,32 @@ Definition trie_set : Value.t -> Value.t -> M := Node to insert at `key`. " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + M.get_field (| M.get_name (| globals, "trie" |), "default" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "key" |), + M.get_field (| M.get_name (| globals, "trie" |), "_data" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), M.get_name (| globals, "value" |) @@ -370,6 +580,7 @@ Definition trie_get : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition common_prefix_length : Value.t -> Value.t -> M := @@ -392,6 +603,34 @@ Definition common_prefix_length : Value.t -> Value.t -> M := make_dict [] |) do let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), + M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -403,6 +642,7 @@ Definition common_prefix_length : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition nibble_list_to_compact : Value.t -> Value.t -> M := @@ -448,6 +688,71 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + Constant.int 2 + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.mult (| + Constant.int 16, + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "is_leaf" |) + |) + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ @@ -509,6 +814,7 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition bytes_to_nibble_list : Value.t -> Value.t -> M := @@ -586,6 +892,7 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition _prepare_trie : Value.t -> Value.t -> M := @@ -615,6 +922,48 @@ Definition _prepare_trie : Value.t -> Value.t -> M := make_dict [] |) do let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| + M.get_name (| globals, "get_storage_root" |), + Constant.None_ + |) |) in + let address := + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |); + M.call (| + M.get_name (| globals, "get_storage_root" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let encoded_value := M.call (| M.get_name (| globals, "encode_node" |), @@ -638,6 +987,22 @@ Definition _prepare_trie : Value.t -> Value.t -> M := |) in (* At stmt: unsupported node type: AnnAssign *) let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "trie" |), "secured" |), + (* then *) + ltac:(M.monadic ( + let key := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let key := M.get_name (| globals, "preimage" |) in M.pure Constant.None_ @@ -655,6 +1020,7 @@ Definition _prepare_trie : Value.t -> Value.t -> M := EndFor. let _ := M.return_ (| M.get_name (| globals, "mapped" |) + |) in M.pure Constant.None_)). Definition root : Value.t -> Value.t -> M := @@ -708,6 +1074,44 @@ Definition root : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -724,6 +1128,7 @@ Definition root : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -750,6 +1155,26 @@ Definition patricialize : Value.t -> Value.t -> M := Root node of `obj`. " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let arbitrary_key := @@ -767,10 +1192,39 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), + Constant.int 1 + |), + (* then *) + ltac:(M.monadic ( + let leaf := + M.call (| + M.get_name (| globals, "LeafNode" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |); + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "leaf" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let substring := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |) |) in + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) in let prefix_length := M.call (| M.get_name (| globals, "len" |), @@ -789,7 +1243,7 @@ Definition patricialize : Value.t -> Value.t -> M := M.get_name (| globals, "common_prefix_length" |), make_list [ M.get_name (| globals, "substring" |); - M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) + M.get_subscript (| M.get_name (| globals, "key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) ], make_dict [] |) @@ -797,10 +1251,64 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "prefix_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "prefix_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let prefix := + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ExtensionNode" |), + make_list [ + M.get_name (| globals, "prefix" |); + M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_name (| globals, "obj" |); + BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) @@ -823,6 +1331,44 @@ Definition patricialize : Value.t -> Value.t -> M := Constant.bytes "" in For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |), + M.get_name (| globals, "level" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "AssertionError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) @@ -834,9 +1380,10 @@ Definition patricialize : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "BranchNode" |), make_list [ - (* At expr: unsupported node type: ListComp *); + Constant.str "(* At expr: unsupported node type: ListComp *)"; M.get_name (| globals, "value" |) ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/utils/address.v b/CoqOfPython/ethereum/constantinople/utils/address.v index 87c97e6..8240fa7 100644 --- a/CoqOfPython/ethereum/constantinople/utils/address.v +++ b/CoqOfPython/ethereum/constantinople/utils/address.v @@ -38,13 +38,13 @@ Require ethereum.utils.byte. Axiom ethereum_utils_byte_left_pad_zero_bytes : IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.constantinople.fork_types. +Axiom ethereum_constantinople_fork_types_Address : + IsGlobalAlias globals ethereum.constantinople.fork_types.globals "Address". Definition to_address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -70,10 +70,11 @@ Definition to_address : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), make_list [], make_dict [] - |), UnOp.sub (| Constant.int 20 |) |) + |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) ], make_dict [] |) + |) in M.pure Constant.None_)). Definition compute_contract_address : Value.t -> Value.t -> M := @@ -113,7 +114,7 @@ Definition compute_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -131,6 +132,7 @@ Definition compute_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition compute_create2_contract_address : Value.t -> Value.t -> M := @@ -180,7 +182,7 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -198,4 +200,5 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/utils/hexadecimal.v b/CoqOfPython/ethereum/constantinople/utils/hexadecimal.v index 4043ada..550399b 100644 --- a/CoqOfPython/ethereum/constantinople/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/constantinople/utils/hexadecimal.v @@ -22,13 +22,13 @@ Require ethereum.utils.hexadecimal. Axiom ethereum_utils_hexadecimal_remove_hex_prefix : IsGlobalAlias globals ethereum.utils.hexadecimal.globals "remove_hex_prefix". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". +Require ethereum.constantinople.fork_types. +Axiom ethereum_constantinople_fork_types_Address : + IsGlobalAlias globals ethereum.constantinople.fork_types.globals "Address". +Axiom ethereum_constantinople_fork_types_Bloom : + IsGlobalAlias globals ethereum.constantinople.fork_types.globals "Bloom". +Axiom ethereum_constantinople_fork_types_Root : + IsGlobalAlias globals ethereum.constantinople.fork_types.globals "Root". Definition hex_to_root : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -66,6 +66,7 @@ Definition hex_to_root : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition hex_to_bloom : Value.t -> Value.t -> M := @@ -104,6 +105,7 @@ Definition hex_to_bloom : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition hex_to_address : Value.t -> Value.t -> M := @@ -149,4 +151,5 @@ Definition hex_to_address : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/utils/message.v b/CoqOfPython/ethereum/constantinople/utils/message.v index 9ef25a3..d79ff6e 100644 --- a/CoqOfPython/ethereum/constantinople/utils/message.v +++ b/CoqOfPython/ethereum/constantinople/utils/message.v @@ -34,23 +34,23 @@ Axiom ethereum_base_types_Bytes0 : Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.constantinople.fork_types. +Axiom ethereum_constantinople_fork_types_Address : + IsGlobalAlias globals ethereum.constantinople.fork_types.globals "Address". -Require state. -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". +Require ethereum.constantinople.state. +Axiom ethereum_constantinople_state_get_account : + IsGlobalAlias globals ethereum.constantinople.state.globals "get_account". -Require vm. -Axiom vm_Environment : - IsGlobalAlias globals vm.globals "Environment". -Axiom vm_Message : - IsGlobalAlias globals vm.globals "Message". +Require ethereum.constantinople.vm.__init__. +Axiom ethereum_constantinople_vm___init___Environment : + IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Environment". +Axiom ethereum_constantinople_vm___init___Message : + IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Message". -Require address. -Axiom address_compute_contract_address : - IsGlobalAlias globals address.globals "compute_contract_address". +Require ethereum.constantinople.utils.address. +Axiom ethereum_constantinople_utils_address_compute_contract_address : + IsGlobalAlias globals ethereum.constantinople.utils.address.globals "compute_contract_address". Definition prepare_message : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -88,14 +88,108 @@ Definition prepare_message : Value.t -> Value.t -> M := Items containing contract creation or message call specific data. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Bytes0" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.call (| + M.get_name (| globals, "compute_contract_address" |), + make_list [ + M.get_name (| globals, "caller" |); + BinOp.sub (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "caller" |) + ], + make_dict [] + |), "nonce" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let msg_data := + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) in + let code := + M.get_name (| globals, "data" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.get_name (| globals, "target" |) in + let msg_data := + M.get_name (| globals, "data" |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "target" |) + ], + make_dict [] + |), "code" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "code_address" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let code_address := + M.get_name (| globals, "target" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "Target must be address or empty bytes" ], make_dict [] - |)) + |)) |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -106,4 +200,5 @@ Definition prepare_message : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/vm/__init__.v b/CoqOfPython/ethereum/constantinople/vm/__init__.v index 8859cb4..08b3c32 100644 --- a/CoqOfPython/ethereum/constantinople/vm/__init__.v +++ b/CoqOfPython/ethereum/constantinople/vm/__init__.v @@ -48,23 +48,23 @@ Require ethereum.crypto.hash. Axiom ethereum_crypto_hash_Hash32 : IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". +Require ethereum.constantinople.blocks. +Axiom ethereum_constantinople_blocks_Log : + IsGlobalAlias globals ethereum.constantinople.blocks.globals "Log". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.constantinople.fork_types. +Axiom ethereum_constantinople_fork_types_Address : + IsGlobalAlias globals ethereum.constantinople.fork_types.globals "Address". -Require state. -Axiom state_State : - IsGlobalAlias globals state.globals "State". -Axiom state_account_exists_and_is_empty : - IsGlobalAlias globals state.globals "account_exists_and_is_empty". +Require ethereum.constantinople.state. +Axiom ethereum_constantinople_state_State : + IsGlobalAlias globals ethereum.constantinople.state.globals "State". +Axiom ethereum_constantinople_state_account_exists_and_is_empty : + IsGlobalAlias globals ethereum.constantinople.state.globals "account_exists_and_is_empty". -Require precompiled_contracts. -Axiom precompiled_contracts_RIPEMD160_ADDRESS : - IsGlobalAlias globals precompiled_contracts.globals "RIPEMD160_ADDRESS". +Require ethereum.constantinople.vm.precompiled_contracts.__init__. +Axiom ethereum_constantinople_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : + IsGlobalAlias globals ethereum.constantinople.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] @@ -143,6 +143,28 @@ Definition incorporate_child_on_success : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -161,9 +183,63 @@ Definition incorporate_child_on_error : Value.t -> Value.t -> M := The child evm to incorporate. " in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "RIPEMD160_ADDRESS" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |), + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign_op (| diff --git a/CoqOfPython/ethereum/constantinople/vm/gas.v b/CoqOfPython/ethereum/constantinople/vm/gas.v index b6c7f26..c7efec9 100644 --- a/CoqOfPython/ethereum/constantinople/vm/gas.v +++ b/CoqOfPython/ethereum/constantinople/vm/gas.v @@ -43,13 +43,13 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.constantinople.vm.__init__. +Axiom ethereum_constantinople_vm___init___Evm : + IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Evm". -Require exceptions. -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". +Require ethereum.constantinople.vm.exceptions. +Axiom ethereum_constantinople_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.constantinople.vm.exceptions.globals "OutOfGasError". Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -510,6 +510,18 @@ Definition charge_gas : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "amount" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign_op (| BinOp.sub, M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), @@ -625,6 +637,18 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := |) in For make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ] in M.get_name (| globals, "extensions" |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "size" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let before_size := @@ -659,6 +683,18 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let size_to_extend := BinOp.add @@ -707,6 +743,7 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition calculate_message_call_gas : Value.t -> Value.t -> M := @@ -738,22 +775,56 @@ Definition calculate_message_call_gas : Value.t -> Value.t -> M := message_call_gas: `MessageCallGas` " in let call_stipend := - (* if *) -M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "call_stipend" |) + )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "gas_left" |), + BinOp.add (| + M.get_name (| globals, "extra_gas" |), + M.get_name (| globals, "memory_cost" |) + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallGas" |), + make_list [ + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "extra_gas" |) + |); + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "call_stipend" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let gas := @@ -792,6 +863,7 @@ M.call (| ], make_dict [] |) + |) in M.pure Constant.None_)). Definition max_message_call_gas : Value.t -> Value.t -> M := @@ -818,4 +890,5 @@ Definition max_message_call_gas : Value.t -> Value.t -> M := Constant.int 64 |) |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/__init__.v b/CoqOfPython/ethereum/constantinople/vm/instructions/__init__.v index e5bebd7..2025bc9 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/__init__.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/__init__.v @@ -26,53 +26,53 @@ Axiom typing_Callable : Axiom typing_Dict : IsGlobalAlias globals typing.globals "Dict". -Require __init__. -Axiom __init___arithmetic : - IsGlobalAlias globals __init__.globals "arithmetic". +Require ethereum.constantinople.vm.instructions.__init__. +Axiom ethereum_constantinople_vm_instructions___init___arithmetic : + IsGlobalAlias globals ethereum.constantinople.vm.instructions.__init__.globals "arithmetic". -Require __init__. -Axiom __init___bitwise : - IsGlobalAlias globals __init__.globals "bitwise". +Require ethereum.constantinople.vm.instructions.__init__. +Axiom ethereum_constantinople_vm_instructions___init___bitwise : + IsGlobalAlias globals ethereum.constantinople.vm.instructions.__init__.globals "bitwise". -Require __init__. -Axiom __init___block : - IsGlobalAlias globals __init__.globals "block". +Require ethereum.constantinople.vm.instructions.__init__. +Axiom ethereum_constantinople_vm_instructions___init___block : + IsGlobalAlias globals ethereum.constantinople.vm.instructions.__init__.globals "block". -Require __init__. -Axiom __init___comparison : - IsGlobalAlias globals __init__.globals "comparison". +Require ethereum.constantinople.vm.instructions.__init__. +Axiom ethereum_constantinople_vm_instructions___init___comparison : + IsGlobalAlias globals ethereum.constantinople.vm.instructions.__init__.globals "comparison". -Require __init__. -Axiom __init___control_flow : - IsGlobalAlias globals __init__.globals "control_flow". +Require ethereum.constantinople.vm.instructions.__init__. +Axiom ethereum_constantinople_vm_instructions___init___control_flow : + IsGlobalAlias globals ethereum.constantinople.vm.instructions.__init__.globals "control_flow". -Require __init__. -Axiom __init___environment : - IsGlobalAlias globals __init__.globals "environment". +Require ethereum.constantinople.vm.instructions.__init__. +Axiom ethereum_constantinople_vm_instructions___init___environment : + IsGlobalAlias globals ethereum.constantinople.vm.instructions.__init__.globals "environment". -Require __init__. -Axiom __init___keccak : - IsGlobalAlias globals __init__.globals "keccak". +Require ethereum.constantinople.vm.instructions.__init__. +Axiom ethereum_constantinople_vm_instructions___init___keccak : + IsGlobalAlias globals ethereum.constantinople.vm.instructions.__init__.globals "keccak". -Require __init__. -Axiom __init___log : - IsGlobalAlias globals __init__.globals "log". +Require ethereum.constantinople.vm.instructions.__init__. +Axiom ethereum_constantinople_vm_instructions___init___log : + IsGlobalAlias globals ethereum.constantinople.vm.instructions.__init__.globals "log". -Require __init__. -Axiom __init___memory : - IsGlobalAlias globals __init__.globals "memory". +Require ethereum.constantinople.vm.instructions.__init__. +Axiom ethereum_constantinople_vm_instructions___init___memory : + IsGlobalAlias globals ethereum.constantinople.vm.instructions.__init__.globals "memory". -Require __init__. -Axiom __init___stack : - IsGlobalAlias globals __init__.globals "stack". +Require ethereum.constantinople.vm.instructions.__init__. +Axiom ethereum_constantinople_vm_instructions___init___stack : + IsGlobalAlias globals ethereum.constantinople.vm.instructions.__init__.globals "stack". -Require __init__. -Axiom __init___storage : - IsGlobalAlias globals __init__.globals "storage". +Require ethereum.constantinople.vm.instructions.__init__. +Axiom ethereum_constantinople_vm_instructions___init___storage : + IsGlobalAlias globals ethereum.constantinople.vm.instructions.__init__.globals "storage". -Require __init__. -Axiom __init___system : - IsGlobalAlias globals __init__.globals "system". +Require ethereum.constantinople.vm.instructions.__init__. +Axiom ethereum_constantinople_vm_instructions___init___system : + IsGlobalAlias globals ethereum.constantinople.vm.instructions.__init__.globals "system". Definition Ops : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/constantinople/vm/instructions/arithmetic.v index 581ba5d..0ff304a 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/arithmetic.v @@ -31,29 +31,29 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_get_sign : IsGlobalAlias globals ethereum.utils.numeric.globals "get_sign". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_EXPONENTIATION : - IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION". -Axiom gas_GAS_EXPONENTIATION_PER_BYTE : - IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION_PER_BYTE". -Axiom gas_GAS_LOW : - IsGlobalAlias globals gas.globals "GAS_LOW". -Axiom gas_GAS_MID : - IsGlobalAlias globals gas.globals "GAS_MID". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.constantinople.vm.__init__. +Axiom ethereum_constantinople_vm___init___Evm : + IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Evm". + +Require ethereum.constantinople.vm.gas. +Axiom ethereum_constantinople_vm_gas_GAS_EXPONENTIATION : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_EXPONENTIATION". +Axiom ethereum_constantinople_vm_gas_GAS_EXPONENTIATION_PER_BYTE : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_EXPONENTIATION_PER_BYTE". +Axiom ethereum_constantinople_vm_gas_GAS_LOW : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_LOW". +Axiom ethereum_constantinople_vm_gas_GAS_MID : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_MID". +Axiom ethereum_constantinople_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_constantinople_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "charge_gas". + +Require ethereum.constantinople.vm.stack. +Axiom ethereum_constantinople_vm_stack_pop : + IsGlobalAlias globals ethereum.constantinople.vm.stack.globals "pop". +Axiom ethereum_constantinople_vm_stack_push : + IsGlobalAlias globals ethereum.constantinople.vm.stack.globals "push". Definition add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -273,6 +273,25 @@ Definition div : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "divisor" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let quotient := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let quotient := BinOp.floor_div (| M.get_name (| globals, "dividend" |), @@ -341,7 +360,41 @@ Definition sdiv : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "divisor" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let quotient := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_name (| globals, "dividend" |), + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "divisor" |), + UnOp.sub (| Constant.int 1 |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let quotient := + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let sign := M.call (| M.get_name (| globals, "get_sign" |), @@ -436,6 +489,25 @@ Definition mod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "y" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let remainder := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let remainder := BinOp.mod_ (| M.get_name (| globals, "x" |), @@ -504,6 +576,19 @@ Definition smod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "y" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let remainder := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let remainder := BinOp.mult (| M.call (| @@ -617,6 +702,25 @@ Definition addmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "z" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -712,6 +816,25 @@ Definition mulmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "z" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -881,6 +1004,19 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "byte_num" |), + Constant.int 31 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.get_name (| globals, "value" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let value_bytes := M.call (| M.get_name (| globals, "bytes" |), @@ -894,7 +1030,7 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let value_bytes := - M.get_subscript (| M.get_name (| globals, "value_bytes" |), BinOp.sub (| + M.get_subscript (| M.get_name (| globals, "value_bytes" |), M.slice (| BinOp.sub (| Constant.int 31, M.call (| M.get_name (| globals, "int" |), @@ -903,13 +1039,32 @@ Definition signextend : Value.t -> Value.t -> M := ], make_dict [] |) - |) |) in + |), Constant.None_ |) |) in let sign_bit := BinOp.r_shift (| M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), Constant.int 7 |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "sign_bit" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "value_bytes" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let num_bytes_prepend := BinOp.sub (| Constant.int 32, diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/bitwise.v b/CoqOfPython/ethereum/constantinople/vm/instructions/bitwise.v index 64cf120..46db25a 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/bitwise.v @@ -23,21 +23,21 @@ Axiom ethereum_base_types_U256 : Axiom ethereum_base_types_U256_CEIL_VALUE : IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.constantinople.vm.__init__. +Axiom ethereum_constantinople_vm___init___Evm : + IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.constantinople.vm.gas. +Axiom ethereum_constantinople_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_constantinople_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "charge_gas". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.constantinople.vm.stack. +Axiom ethereum_constantinople_vm_stack_pop : + IsGlobalAlias globals ethereum.constantinople.vm.stack.globals "pop". +Axiom ethereum_constantinople_vm_stack_push : + IsGlobalAlias globals ethereum.constantinople.vm.stack.globals "push". Definition bitwise_and : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -287,6 +287,25 @@ Definition get_byte : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "byte_index" |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let extra_bytes_to_right := BinOp.sub (| Constant.int 31, @@ -366,6 +385,31 @@ Definition bitwise_shl : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "shift" |), + Constant.int 256 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.l_shift (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "shift" |) + |), + M.get_name (| globals, "U256_CEIL_VALUE" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -427,6 +471,22 @@ Definition bitwise_shr : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "shift" |), + Constant.int 256 + |), + (* then *) + ltac:(M.monadic ( + let result := + BinOp.r_shift (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "shift" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -492,7 +552,48 @@ Definition bitwise_sar : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "shift" |), + Constant.int 256 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + BinOp.r_shift (| + M.get_name (| globals, "signed_value" |), + M.get_name (| globals, "shift" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "signed_value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/block.v b/CoqOfPython/ethereum/constantinople/vm/instructions/block.v index 90be45c..e83afd2 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/block.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/block.v @@ -21,23 +21,23 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_BLOCK_HASH : - IsGlobalAlias globals gas.globals "GAS_BLOCK_HASH". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.constantinople.vm.__init__. +Axiom ethereum_constantinople_vm___init___Evm : + IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Evm". + +Require ethereum.constantinople.vm.gas. +Axiom ethereum_constantinople_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_BASE". +Axiom ethereum_constantinople_vm_gas_GAS_BLOCK_HASH : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_BLOCK_HASH". +Axiom ethereum_constantinople_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "charge_gas". + +Require ethereum.constantinople.vm.stack. +Axiom ethereum_constantinople_vm_stack_pop : + IsGlobalAlias globals ethereum.constantinople.vm.stack.globals "pop". +Axiom ethereum_constantinople_vm_stack_push : + IsGlobalAlias globals ethereum.constantinople.vm.stack.globals "push". Definition block_hash : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -69,6 +69,30 @@ Definition block_hash : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt_e (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + M.get_name (| globals, "block_number" |) + |), + ltac:(M.monadic ( + Compare.gt (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + BinOp.add (| + M.get_name (| globals, "block_number" |), + Constant.int 256 + |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let hash := + Constant.bytes "00" in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let hash := M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/comparison.v b/CoqOfPython/ethereum/constantinople/vm/instructions/comparison.v index b8529d8..ed8e781 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/comparison.v @@ -21,21 +21,21 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.constantinople.vm.__init__. +Axiom ethereum_constantinople_vm___init___Evm : + IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.constantinople.vm.gas. +Axiom ethereum_constantinople_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_constantinople_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "charge_gas". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.constantinople.vm.stack. +Axiom ethereum_constantinople_vm_stack_pop : + IsGlobalAlias globals ethereum.constantinople.vm.stack.globals "pop". +Axiom ethereum_constantinople_vm_stack_push : + IsGlobalAlias globals ethereum.constantinople.vm.stack.globals "push". Definition less_than : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/control_flow.v b/CoqOfPython/ethereum/constantinople/vm/instructions/control_flow.v index d4e4eae..cae7d6b 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/control_flow.v @@ -23,31 +23,31 @@ Axiom ethereum_base_types_U256 : Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require vm.gas. -Axiom vm_gas_GAS_BASE : - IsGlobalAlias globals vm.gas.globals "GAS_BASE". -Axiom vm_gas_GAS_HIGH : - IsGlobalAlias globals vm.gas.globals "GAS_HIGH". -Axiom vm_gas_GAS_JUMPDEST : - IsGlobalAlias globals vm.gas.globals "GAS_JUMPDEST". -Axiom vm_gas_GAS_MID : - IsGlobalAlias globals vm.gas.globals "GAS_MID". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.constantinople.vm.gas. +Axiom ethereum_constantinople_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_BASE". +Axiom ethereum_constantinople_vm_gas_GAS_HIGH : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_HIGH". +Axiom ethereum_constantinople_vm_gas_GAS_JUMPDEST : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_JUMPDEST". +Axiom ethereum_constantinople_vm_gas_GAS_MID : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_MID". +Axiom ethereum_constantinople_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "charge_gas". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.constantinople.vm.__init__. +Axiom ethereum_constantinople_vm___init___Evm : + IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Evm". -Require exceptions. -Axiom exceptions_InvalidJumpDestError : - IsGlobalAlias globals exceptions.globals "InvalidJumpDestError". +Require ethereum.constantinople.vm.exceptions. +Axiom ethereum_constantinople_vm_exceptions_InvalidJumpDestError : + IsGlobalAlias globals ethereum.constantinople.vm.exceptions.globals "InvalidJumpDestError". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.constantinople.vm.stack. +Axiom ethereum_constantinople_vm_stack_pop : + IsGlobalAlias globals ethereum.constantinople.vm.stack.globals "pop". +Axiom ethereum_constantinople_vm_stack_push : + IsGlobalAlias globals ethereum.constantinople.vm.stack.globals "push". Definition stop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -109,6 +109,18 @@ Definition jump : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "jump_dest" |), + M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -168,7 +180,35 @@ Definition jumpi : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "conditional_value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let destination := + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "jump_dest" |), + M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let destination := M.get_name (| globals, "jump_dest" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/environment.v b/CoqOfPython/ethereum/constantinople/vm/instructions/environment.v index c1e94f6..4a58239 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/environment.v @@ -35,57 +35,57 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require fork_types. -Axiom fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". +Require ethereum.constantinople.fork_types. +Axiom ethereum_constantinople_fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals ethereum.constantinople.fork_types.globals "EMPTY_ACCOUNT". -Require state. -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". +Require ethereum.constantinople.state. +Axiom ethereum_constantinople_state_get_account : + IsGlobalAlias globals ethereum.constantinople.state.globals "get_account". -Require utils.address. -Axiom utils_address_to_address : - IsGlobalAlias globals utils.address.globals "to_address". +Require ethereum.constantinople.utils.address. +Axiom ethereum_constantinople_utils_address_to_address : + IsGlobalAlias globals ethereum.constantinople.utils.address.globals "to_address". -Require vm.memory. -Axiom vm_memory_buffer_read : - IsGlobalAlias globals vm.memory.globals "buffer_read". -Axiom vm_memory_memory_write : - IsGlobalAlias globals vm.memory.globals "memory_write". +Require ethereum.constantinople.vm.memory. +Axiom ethereum_constantinople_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.constantinople.vm.memory.globals "buffer_read". +Axiom ethereum_constantinople_vm_memory_memory_write : + IsGlobalAlias globals ethereum.constantinople.vm.memory.globals "memory_write". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.constantinople.vm.__init__. +Axiom ethereum_constantinople_vm___init___Evm : + IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Evm". -Require exceptions. -Axiom exceptions_OutOfBoundsRead : - IsGlobalAlias globals exceptions.globals "OutOfBoundsRead". +Require ethereum.constantinople.vm.exceptions. +Axiom ethereum_constantinople_vm_exceptions_OutOfBoundsRead : + IsGlobalAlias globals ethereum.constantinople.vm.exceptions.globals "OutOfBoundsRead". -Require gas. -Axiom gas_GAS_BALANCE : - IsGlobalAlias globals gas.globals "GAS_BALANCE". -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_CODE_HASH : - IsGlobalAlias globals gas.globals "GAS_CODE_HASH". -Axiom gas_GAS_COPY : - IsGlobalAlias globals gas.globals "GAS_COPY". -Axiom gas_GAS_EXTERNAL : - IsGlobalAlias globals gas.globals "GAS_EXTERNAL". -Axiom gas_GAS_RETURN_DATA_COPY : - IsGlobalAlias globals gas.globals "GAS_RETURN_DATA_COPY". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.constantinople.vm.gas. +Axiom ethereum_constantinople_vm_gas_GAS_BALANCE : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_BALANCE". +Axiom ethereum_constantinople_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_BASE". +Axiom ethereum_constantinople_vm_gas_GAS_CODE_HASH : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_CODE_HASH". +Axiom ethereum_constantinople_vm_gas_GAS_COPY : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_COPY". +Axiom ethereum_constantinople_vm_gas_GAS_EXTERNAL : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_EXTERNAL". +Axiom ethereum_constantinople_vm_gas_GAS_RETURN_DATA_COPY : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_RETURN_DATA_COPY". +Axiom ethereum_constantinople_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_constantinople_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_constantinople_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "charge_gas". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.constantinople.vm.stack. +Axiom ethereum_constantinople_vm_stack_pop : + IsGlobalAlias globals ethereum.constantinople.vm.stack.globals "pop". +Axiom ethereum_constantinople_vm_stack_push : + IsGlobalAlias globals ethereum.constantinople.vm.stack.globals "push". Definition address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -1132,7 +1132,10 @@ Definition returndatacopy : Value.t -> Value.t -> M := |) |) in let value := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |) |) in + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.slice (| M.get_name (| globals, "return_data_start_position" |), BinOp.add (| + M.get_name (| globals, "return_data_start_position" |), + M.get_name (| globals, "size" |) + |) |) |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -1191,6 +1194,25 @@ Definition extcodehash : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "account" |), + M.get_name (| globals, "EMPTY_ACCOUNT" |) + |), + (* then *) + ltac:(M.monadic ( + let codehash := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let codehash := M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/keccak.v b/CoqOfPython/ethereum/constantinople/vm/instructions/keccak.v index 2c4b10e..50fcd51 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/keccak.v @@ -31,29 +31,29 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_KECCAK256 : - IsGlobalAlias globals gas.globals "GAS_KECCAK256". -Axiom gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.constantinople.vm.__init__. +Axiom ethereum_constantinople_vm___init___Evm : + IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Evm". + +Require ethereum.constantinople.vm.gas. +Axiom ethereum_constantinople_vm_gas_GAS_KECCAK256 : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_KECCAK256". +Axiom ethereum_constantinople_vm_gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_KECCAK256_WORD". +Axiom ethereum_constantinople_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_constantinople_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "charge_gas". + +Require ethereum.constantinople.vm.memory. +Axiom ethereum_constantinople_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.constantinople.vm.memory.globals "memory_read_bytes". + +Require ethereum.constantinople.vm.stack. +Axiom ethereum_constantinople_vm_stack_pop : + IsGlobalAlias globals ethereum.constantinople.vm.stack.globals "pop". +Axiom ethereum_constantinople_vm_stack_push : + IsGlobalAlias globals ethereum.constantinople.vm.stack.globals "push". Definition keccak : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/log.v b/CoqOfPython/ethereum/constantinople/vm/instructions/log.v index e084e59..cc79a76 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/log.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/log.v @@ -29,37 +29,37 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". - -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require exceptions. -Axiom exceptions_WriteInStaticContext : - IsGlobalAlias globals exceptions.globals "WriteInStaticContext". - -Require gas. -Axiom gas_GAS_LOG : - IsGlobalAlias globals gas.globals "GAS_LOG". -Axiom gas_GAS_LOG_DATA : - IsGlobalAlias globals gas.globals "GAS_LOG_DATA". -Axiom gas_GAS_LOG_TOPIC : - IsGlobalAlias globals gas.globals "GAS_LOG_TOPIC". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". +Require ethereum.constantinople.blocks. +Axiom ethereum_constantinople_blocks_Log : + IsGlobalAlias globals ethereum.constantinople.blocks.globals "Log". + +Require ethereum.constantinople.vm.__init__. +Axiom ethereum_constantinople_vm___init___Evm : + IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Evm". + +Require ethereum.constantinople.vm.exceptions. +Axiom ethereum_constantinople_vm_exceptions_WriteInStaticContext : + IsGlobalAlias globals ethereum.constantinople.vm.exceptions.globals "WriteInStaticContext". + +Require ethereum.constantinople.vm.gas. +Axiom ethereum_constantinople_vm_gas_GAS_LOG : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_LOG". +Axiom ethereum_constantinople_vm_gas_GAS_LOG_DATA : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_LOG_DATA". +Axiom ethereum_constantinople_vm_gas_GAS_LOG_TOPIC : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_LOG_TOPIC". +Axiom ethereum_constantinople_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_constantinople_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "charge_gas". + +Require ethereum.constantinople.vm.memory. +Axiom ethereum_constantinople_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.constantinople.vm.memory.globals "memory_read_bytes". + +Require ethereum.constantinople.vm.stack. +Axiom ethereum_constantinople_vm_stack_pop : + IsGlobalAlias globals ethereum.constantinople.vm.stack.globals "pop". Definition log_n : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/memory.v b/CoqOfPython/ethereum/constantinople/vm/instructions/memory.v index 86ba742..b27af6c 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/memory.v @@ -23,31 +23,31 @@ Axiom ethereum_base_types_U256 : Axiom ethereum_base_types_Bytes : IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.constantinople.vm.__init__. +Axiom ethereum_constantinople_vm___init___Evm : + IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.constantinople.vm.gas. +Axiom ethereum_constantinople_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_BASE". +Axiom ethereum_constantinople_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_constantinople_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_constantinople_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "charge_gas". -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". -Axiom memory_memory_write : - IsGlobalAlias globals memory.globals "memory_write". +Require ethereum.constantinople.vm.memory. +Axiom ethereum_constantinople_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.constantinople.vm.memory.globals "memory_read_bytes". +Axiom ethereum_constantinople_vm_memory_memory_write : + IsGlobalAlias globals ethereum.constantinople.vm.memory.globals "memory_write". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.constantinople.vm.stack. +Axiom ethereum_constantinople_vm_stack_pop : + IsGlobalAlias globals ethereum.constantinople.vm.stack.globals "pop". +Axiom ethereum_constantinople_vm_stack_push : + IsGlobalAlias globals ethereum.constantinople.vm.stack.globals "push". Definition mstore : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/stack.v b/CoqOfPython/ethereum/constantinople/vm/instructions/stack.v index 305af15..414f00c 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/stack.v @@ -29,27 +29,27 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". -Axiom __init___stack : - IsGlobalAlias globals __init__.globals "stack". - -Require exceptions. -Axiom exceptions_StackUnderflowError : - IsGlobalAlias globals exceptions.globals "StackUnderflowError". - -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require memory. -Axiom memory_buffer_read : - IsGlobalAlias globals memory.globals "buffer_read". +Require ethereum.constantinople.vm.__init__. +Axiom ethereum_constantinople_vm___init___Evm : + IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Evm". +Axiom ethereum_constantinople_vm___init___stack : + IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "stack". + +Require ethereum.constantinople.vm.exceptions. +Axiom ethereum_constantinople_vm_exceptions_StackUnderflowError : + IsGlobalAlias globals ethereum.constantinople.vm.exceptions.globals "StackUnderflowError". + +Require ethereum.constantinople.vm.gas. +Axiom ethereum_constantinople_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_BASE". +Axiom ethereum_constantinople_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_constantinople_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "charge_gas". + +Require ethereum.constantinople.vm.memory. +Axiom ethereum_constantinople_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.constantinople.vm.memory.globals "buffer_read". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/storage.v b/CoqOfPython/ethereum/constantinople/vm/instructions/storage.v index fe33724..13af511 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/storage.v @@ -21,37 +21,37 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require state. -Axiom state_get_storage : - IsGlobalAlias globals state.globals "get_storage". -Axiom state_set_storage : - IsGlobalAlias globals state.globals "set_storage". - -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require exceptions. -Axiom exceptions_WriteInStaticContext : - IsGlobalAlias globals exceptions.globals "WriteInStaticContext". - -Require gas. -Axiom gas_GAS_SLOAD : - IsGlobalAlias globals gas.globals "GAS_SLOAD". -Axiom gas_GAS_STORAGE_CLEAR_REFUND : - IsGlobalAlias globals gas.globals "GAS_STORAGE_CLEAR_REFUND". -Axiom gas_GAS_STORAGE_SET : - IsGlobalAlias globals gas.globals "GAS_STORAGE_SET". -Axiom gas_GAS_STORAGE_UPDATE : - IsGlobalAlias globals gas.globals "GAS_STORAGE_UPDATE". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.constantinople.state. +Axiom ethereum_constantinople_state_get_storage : + IsGlobalAlias globals ethereum.constantinople.state.globals "get_storage". +Axiom ethereum_constantinople_state_set_storage : + IsGlobalAlias globals ethereum.constantinople.state.globals "set_storage". + +Require ethereum.constantinople.vm.__init__. +Axiom ethereum_constantinople_vm___init___Evm : + IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Evm". + +Require ethereum.constantinople.vm.exceptions. +Axiom ethereum_constantinople_vm_exceptions_WriteInStaticContext : + IsGlobalAlias globals ethereum.constantinople.vm.exceptions.globals "WriteInStaticContext". + +Require ethereum.constantinople.vm.gas. +Axiom ethereum_constantinople_vm_gas_GAS_SLOAD : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_SLOAD". +Axiom ethereum_constantinople_vm_gas_GAS_STORAGE_CLEAR_REFUND : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_STORAGE_CLEAR_REFUND". +Axiom ethereum_constantinople_vm_gas_GAS_STORAGE_SET : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_STORAGE_SET". +Axiom ethereum_constantinople_vm_gas_GAS_STORAGE_UPDATE : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_STORAGE_UPDATE". +Axiom ethereum_constantinople_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "charge_gas". + +Require ethereum.constantinople.vm.stack. +Axiom ethereum_constantinople_vm_stack_pop : + IsGlobalAlias globals ethereum.constantinople.vm.stack.globals "pop". +Axiom ethereum_constantinople_vm_stack_push : + IsGlobalAlias globals ethereum.constantinople.vm.stack.globals "push". Definition sload : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -154,11 +154,56 @@ Definition sstore : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "new_value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "current_value" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let gas_cost := + M.get_name (| globals, "GAS_STORAGE_SET" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let gas_cost := M.get_name (| globals, "GAS_STORAGE_UPDATE" |) in M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_name (| globals, "new_value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "current_value" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/system.v b/CoqOfPython/ethereum/constantinople/vm/instructions/system.v index b850f84..caef466 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/system.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/system.v @@ -33,87 +33,87 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.constantinople.fork_types. +Axiom ethereum_constantinople_fork_types_Address : + IsGlobalAlias globals ethereum.constantinople.fork_types.globals "Address". -Require state. -Axiom state_account_exists_and_is_empty : - IsGlobalAlias globals state.globals "account_exists_and_is_empty". -Axiom state_account_has_code_or_nonce : - IsGlobalAlias globals state.globals "account_has_code_or_nonce". -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". -Axiom state_increment_nonce : - IsGlobalAlias globals state.globals "increment_nonce". -Axiom state_is_account_alive : - IsGlobalAlias globals state.globals "is_account_alive". -Axiom state_set_account_balance : - IsGlobalAlias globals state.globals "set_account_balance". +Require ethereum.constantinople.state. +Axiom ethereum_constantinople_state_account_exists_and_is_empty : + IsGlobalAlias globals ethereum.constantinople.state.globals "account_exists_and_is_empty". +Axiom ethereum_constantinople_state_account_has_code_or_nonce : + IsGlobalAlias globals ethereum.constantinople.state.globals "account_has_code_or_nonce". +Axiom ethereum_constantinople_state_get_account : + IsGlobalAlias globals ethereum.constantinople.state.globals "get_account". +Axiom ethereum_constantinople_state_increment_nonce : + IsGlobalAlias globals ethereum.constantinople.state.globals "increment_nonce". +Axiom ethereum_constantinople_state_is_account_alive : + IsGlobalAlias globals ethereum.constantinople.state.globals "is_account_alive". +Axiom ethereum_constantinople_state_set_account_balance : + IsGlobalAlias globals ethereum.constantinople.state.globals "set_account_balance". -Require utils.address. -Axiom utils_address_compute_contract_address : - IsGlobalAlias globals utils.address.globals "compute_contract_address". -Axiom utils_address_compute_create2_contract_address : - IsGlobalAlias globals utils.address.globals "compute_create2_contract_address". -Axiom utils_address_to_address : - IsGlobalAlias globals utils.address.globals "to_address". +Require ethereum.constantinople.utils.address. +Axiom ethereum_constantinople_utils_address_compute_contract_address : + IsGlobalAlias globals ethereum.constantinople.utils.address.globals "compute_contract_address". +Axiom ethereum_constantinople_utils_address_compute_create2_contract_address : + IsGlobalAlias globals ethereum.constantinople.utils.address.globals "compute_create2_contract_address". +Axiom ethereum_constantinople_utils_address_to_address : + IsGlobalAlias globals ethereum.constantinople.utils.address.globals "to_address". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". -Axiom __init___Message : - IsGlobalAlias globals __init__.globals "Message". -Axiom __init___incorporate_child_on_error : - IsGlobalAlias globals __init__.globals "incorporate_child_on_error". -Axiom __init___incorporate_child_on_success : - IsGlobalAlias globals __init__.globals "incorporate_child_on_success". +Require ethereum.constantinople.vm.__init__. +Axiom ethereum_constantinople_vm___init___Evm : + IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Evm". +Axiom ethereum_constantinople_vm___init___Message : + IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Message". +Axiom ethereum_constantinople_vm___init___incorporate_child_on_error : + IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "incorporate_child_on_error". +Axiom ethereum_constantinople_vm___init___incorporate_child_on_success : + IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "incorporate_child_on_success". -Require exceptions. -Axiom exceptions_Revert : - IsGlobalAlias globals exceptions.globals "Revert". -Axiom exceptions_WriteInStaticContext : - IsGlobalAlias globals exceptions.globals "WriteInStaticContext". +Require ethereum.constantinople.vm.exceptions. +Axiom ethereum_constantinople_vm_exceptions_Revert : + IsGlobalAlias globals ethereum.constantinople.vm.exceptions.globals "Revert". +Axiom ethereum_constantinople_vm_exceptions_WriteInStaticContext : + IsGlobalAlias globals ethereum.constantinople.vm.exceptions.globals "WriteInStaticContext". -Require gas. -Axiom gas_GAS_CALL : - IsGlobalAlias globals gas.globals "GAS_CALL". -Axiom gas_GAS_CALL_VALUE : - IsGlobalAlias globals gas.globals "GAS_CALL_VALUE". -Axiom gas_GAS_CREATE : - IsGlobalAlias globals gas.globals "GAS_CREATE". -Axiom gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". -Axiom gas_GAS_NEW_ACCOUNT : - IsGlobalAlias globals gas.globals "GAS_NEW_ACCOUNT". -Axiom gas_GAS_SELF_DESTRUCT : - IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT". -Axiom gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : - IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". -Axiom gas_GAS_ZERO : - IsGlobalAlias globals gas.globals "GAS_ZERO". -Axiom gas_REFUND_SELF_DESTRUCT : - IsGlobalAlias globals gas.globals "REFUND_SELF_DESTRUCT". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_calculate_message_call_gas : - IsGlobalAlias globals gas.globals "calculate_message_call_gas". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". -Axiom gas_max_message_call_gas : - IsGlobalAlias globals gas.globals "max_message_call_gas". +Require ethereum.constantinople.vm.gas. +Axiom ethereum_constantinople_vm_gas_GAS_CALL : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_CALL". +Axiom ethereum_constantinople_vm_gas_GAS_CALL_VALUE : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_CALL_VALUE". +Axiom ethereum_constantinople_vm_gas_GAS_CREATE : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_CREATE". +Axiom ethereum_constantinople_vm_gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_KECCAK256_WORD". +Axiom ethereum_constantinople_vm_gas_GAS_NEW_ACCOUNT : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_NEW_ACCOUNT". +Axiom ethereum_constantinople_vm_gas_GAS_SELF_DESTRUCT : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_SELF_DESTRUCT". +Axiom ethereum_constantinople_vm_gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". +Axiom ethereum_constantinople_vm_gas_GAS_ZERO : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_ZERO". +Axiom ethereum_constantinople_vm_gas_REFUND_SELF_DESTRUCT : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "REFUND_SELF_DESTRUCT". +Axiom ethereum_constantinople_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_constantinople_vm_gas_calculate_message_call_gas : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "calculate_message_call_gas". +Axiom ethereum_constantinople_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "charge_gas". +Axiom ethereum_constantinople_vm_gas_max_message_call_gas : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "max_message_call_gas". -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". -Axiom memory_memory_write : - IsGlobalAlias globals memory.globals "memory_write". +Require ethereum.constantinople.vm.memory. +Axiom ethereum_constantinople_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.constantinople.vm.memory.globals "memory_read_bytes". +Axiom ethereum_constantinople_vm_memory_memory_write : + IsGlobalAlias globals ethereum.constantinople.vm.memory.globals "memory_write". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.constantinople.vm.stack. +Axiom ethereum_constantinople_vm_stack_pop : + IsGlobalAlias globals ethereum.constantinople.vm.stack.globals "pop". +Axiom ethereum_constantinople_vm_stack_push : + IsGlobalAlias globals ethereum.constantinople.vm.stack.globals "push". Definition generic_create : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -165,9 +165,113 @@ Definition generic_create : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt (| + M.get_field (| M.get_name (| globals, "sender" |), "balance" |), + M.get_name (| globals, "endowment" |) + |), + ltac:(M.monadic ( + BoolOp.or (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "sender" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.sub (| + BinOp.pow (| + Constant.int 2, + Constant.int 64 + |), + Constant.int 1 + |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.gt (| + BinOp.add (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "depth" |), + Constant.int 1 + |), + M.get_name (| globals, "STACK_DEPTH_LIMIT" |) + |) + )) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "create_message_gas" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "contract_address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let call_data := @@ -204,6 +308,40 @@ Definition generic_create : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "child_evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_error" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "incorporate_child_on_success" |), make_list [ @@ -560,6 +698,42 @@ Definition generic_call : Value.t -> Value.t -> M := Constant.bytes "" |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + BinOp.add (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "depth" |), + Constant.int 1 + |), + M.get_name (| globals, "STACK_DEPTH_LIMIT" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "gas" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let call_data := @@ -597,6 +771,40 @@ Definition generic_call : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "child_evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_error" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "incorporate_child_on_success" |), make_list [ @@ -651,7 +859,7 @@ Definition generic_call : Value.t -> Value.t -> M := make_list [ M.get_field (| M.get_name (| globals, "evm" |), "memory" |); M.get_name (| globals, "memory_output_start_position" |); - M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), Constant.None_:M.get_name (| globals, "actual_output_size" |) |) + M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), M.slice (| Constant.None_, M.get_name (| globals, "actual_output_size" |) |) |) ], make_dict [] |) in @@ -749,49 +957,57 @@ Definition call : Value.t -> Value.t -> M := make_dict [] |) in let create_gas_cost := - (* if *) -M.if_then_else (| - BoolOp.or (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), - ltac:(M.monadic ( - M.call (| - M.get_name (| globals, "is_account_alive" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); - M.get_name (| globals, "to" |) - ], - make_dict [] - |) - )) - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "is_account_alive" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "to" |) + ], + make_dict [] + |) + )) + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "GAS_NEW_ACCOUNT" |) + )) |) in let transfer_gas_cost := - (* if *) -M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "GAS_CALL_VALUE" |) + )) |) in let message_call_gas := M.call (| M.get_name (| globals, "calculate_message_call_gas" |), @@ -867,6 +1083,40 @@ M.call (| make_dict [] |), "balance" |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "sender_balance" |), + M.get_name (| globals, "value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "generic_call" |), make_list [ @@ -988,21 +1238,25 @@ Definition callcode : Value.t -> Value.t -> M := make_dict [] |) in let transfer_gas_cost := - (* if *) -M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "GAS_CALL_VALUE" |) + )) |) in let message_call_gas := M.call (| M.get_name (| globals, "calculate_message_call_gas" |), @@ -1053,6 +1307,40 @@ M.call (| make_dict [] |), "balance" |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "sender_balance" |), + M.get_name (| globals, "value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "generic_call" |), make_list [ @@ -1108,6 +1396,39 @@ Definition selfdestruct : Value.t -> Value.t -> M := let gas_cost := M.get_name (| globals, "GAS_SELF_DESTRUCT" |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + UnOp.not (| M.call (| + M.get_name (| globals, "is_account_alive" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) + M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let originator := @@ -1131,6 +1452,22 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in EndWhile. let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "originator" |), + M.get_name (| globals, "refunded_accounts" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.get_name (| globals, "REFUND_SELF_DESTRUCT" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -1202,6 +1539,28 @@ Definition selfdestruct : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -1593,6 +1952,6 @@ Definition revert : Value.t -> Value.t -> M := make_dict [] |) |) in - let _ := M.raise (| Some(M.get_name (| globals, "Revert" |)) + let _ := M.raise (| Some(M.get_name (| globals, "Revert" |)) |) in let _ := M.pass (| |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/vm/interpreter.v b/CoqOfPython/ethereum/constantinople/vm/interpreter.v index 1732d4d..5ca515a 100644 --- a/CoqOfPython/ethereum/constantinople/vm/interpreter.v +++ b/CoqOfPython/ethereum/constantinople/vm/interpreter.v @@ -61,79 +61,79 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". - -Require state. -Axiom state_account_exists_and_is_empty : - IsGlobalAlias globals state.globals "account_exists_and_is_empty". -Axiom state_account_has_code_or_nonce : - IsGlobalAlias globals state.globals "account_has_code_or_nonce". -Axiom state_begin_transaction : - IsGlobalAlias globals state.globals "begin_transaction". -Axiom state_commit_transaction : - IsGlobalAlias globals state.globals "commit_transaction". -Axiom state_destroy_storage : - IsGlobalAlias globals state.globals "destroy_storage". -Axiom state_increment_nonce : - IsGlobalAlias globals state.globals "increment_nonce". -Axiom state_move_ether : - IsGlobalAlias globals state.globals "move_ether". -Axiom state_rollback_transaction : - IsGlobalAlias globals state.globals "rollback_transaction". -Axiom state_set_code : - IsGlobalAlias globals state.globals "set_code". -Axiom state_touch_account : - IsGlobalAlias globals state.globals "touch_account". - -Require vm. -Axiom vm_Message : - IsGlobalAlias globals vm.globals "Message". - -Require vm.gas. -Axiom vm_gas_GAS_CODE_DEPOSIT : - IsGlobalAlias globals vm.gas.globals "GAS_CODE_DEPOSIT". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". - -Require vm.precompiled_contracts.mapping. -Axiom vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : - IsGlobalAlias globals vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". - -Require __init__. -Axiom __init___Environment : - IsGlobalAlias globals __init__.globals "Environment". -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require exceptions. -Axiom exceptions_AddressCollision : - IsGlobalAlias globals exceptions.globals "AddressCollision". -Axiom exceptions_ExceptionalHalt : - IsGlobalAlias globals exceptions.globals "ExceptionalHalt". -Axiom exceptions_InvalidOpcode : - IsGlobalAlias globals exceptions.globals "InvalidOpcode". -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". -Axiom exceptions_Revert : - IsGlobalAlias globals exceptions.globals "Revert". -Axiom exceptions_StackDepthLimitError : - IsGlobalAlias globals exceptions.globals "StackDepthLimitError". - -Require instructions. -Axiom instructions_Ops : - IsGlobalAlias globals instructions.globals "Ops". -Axiom instructions_op_implementation : - IsGlobalAlias globals instructions.globals "op_implementation". - -Require runtime. -Axiom runtime_get_valid_jump_destinations : - IsGlobalAlias globals runtime.globals "get_valid_jump_destinations". +Require ethereum.constantinople.blocks. +Axiom ethereum_constantinople_blocks_Log : + IsGlobalAlias globals ethereum.constantinople.blocks.globals "Log". + +Require ethereum.constantinople.fork_types. +Axiom ethereum_constantinople_fork_types_Address : + IsGlobalAlias globals ethereum.constantinople.fork_types.globals "Address". + +Require ethereum.constantinople.state. +Axiom ethereum_constantinople_state_account_exists_and_is_empty : + IsGlobalAlias globals ethereum.constantinople.state.globals "account_exists_and_is_empty". +Axiom ethereum_constantinople_state_account_has_code_or_nonce : + IsGlobalAlias globals ethereum.constantinople.state.globals "account_has_code_or_nonce". +Axiom ethereum_constantinople_state_begin_transaction : + IsGlobalAlias globals ethereum.constantinople.state.globals "begin_transaction". +Axiom ethereum_constantinople_state_commit_transaction : + IsGlobalAlias globals ethereum.constantinople.state.globals "commit_transaction". +Axiom ethereum_constantinople_state_destroy_storage : + IsGlobalAlias globals ethereum.constantinople.state.globals "destroy_storage". +Axiom ethereum_constantinople_state_increment_nonce : + IsGlobalAlias globals ethereum.constantinople.state.globals "increment_nonce". +Axiom ethereum_constantinople_state_move_ether : + IsGlobalAlias globals ethereum.constantinople.state.globals "move_ether". +Axiom ethereum_constantinople_state_rollback_transaction : + IsGlobalAlias globals ethereum.constantinople.state.globals "rollback_transaction". +Axiom ethereum_constantinople_state_set_code : + IsGlobalAlias globals ethereum.constantinople.state.globals "set_code". +Axiom ethereum_constantinople_state_touch_account : + IsGlobalAlias globals ethereum.constantinople.state.globals "touch_account". + +Require ethereum.constantinople.vm.__init__. +Axiom ethereum_constantinople_vm___init___Message : + IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Message". + +Require ethereum.constantinople.vm.gas. +Axiom ethereum_constantinople_vm_gas_GAS_CODE_DEPOSIT : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_CODE_DEPOSIT". +Axiom ethereum_constantinople_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "charge_gas". + +Require ethereum.constantinople.vm.precompiled_contracts.mapping. +Axiom ethereum_constantinople_vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : + IsGlobalAlias globals ethereum.constantinople.vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". + +Require ethereum.constantinople.vm.__init__. +Axiom ethereum_constantinople_vm___init___Environment : + IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Environment". +Axiom ethereum_constantinople_vm___init___Evm : + IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Evm". + +Require ethereum.constantinople.vm.exceptions. +Axiom ethereum_constantinople_vm_exceptions_AddressCollision : + IsGlobalAlias globals ethereum.constantinople.vm.exceptions.globals "AddressCollision". +Axiom ethereum_constantinople_vm_exceptions_ExceptionalHalt : + IsGlobalAlias globals ethereum.constantinople.vm.exceptions.globals "ExceptionalHalt". +Axiom ethereum_constantinople_vm_exceptions_InvalidOpcode : + IsGlobalAlias globals ethereum.constantinople.vm.exceptions.globals "InvalidOpcode". +Axiom ethereum_constantinople_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.constantinople.vm.exceptions.globals "OutOfGasError". +Axiom ethereum_constantinople_vm_exceptions_Revert : + IsGlobalAlias globals ethereum.constantinople.vm.exceptions.globals "Revert". +Axiom ethereum_constantinople_vm_exceptions_StackDepthLimitError : + IsGlobalAlias globals ethereum.constantinople.vm.exceptions.globals "StackDepthLimitError". + +Require ethereum.constantinople.vm.instructions.__init__. +Axiom ethereum_constantinople_vm_instructions___init___Ops : + IsGlobalAlias globals ethereum.constantinople.vm.instructions.__init__.globals "Ops". +Axiom ethereum_constantinople_vm_instructions___init___op_implementation : + IsGlobalAlias globals ethereum.constantinople.vm.instructions.__init__.globals "op_implementation". + +Require ethereum.constantinople.vm.runtime. +Axiom ethereum_constantinople_vm_runtime_get_valid_jump_destinations : + IsGlobalAlias globals ethereum.constantinople.vm.runtime.globals "get_valid_jump_destinations". Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -180,6 +180,94 @@ Definition process_message_call : Value.t -> Value.t -> M := Output of the message call " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "message" |), "target" |), + M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) + |), + (* then *) + ltac:(M.monadic ( + let is_collision := + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_name (| globals, "is_collision" |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallOutput" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "tuple" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "AddressCollision" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let evm := + M.call (| + M.get_name (| globals, "process_create_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let evm := M.call (| M.get_name (| globals, "process_message" |), @@ -190,11 +278,74 @@ Definition process_message_call : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_field (| M.get_name (| globals, "message" |), "target" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_field (| M.get_name (| globals, "message" |), "target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( +(* At stmt: unsupported node type: AnnAssign *) + let accounts_to_delete := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let touched_accounts := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let refund_counter := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let logs := M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in let accounts_to_delete := @@ -232,6 +383,7 @@ Definition process_message_call : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). Definition process_create_message : Value.t -> Value.t -> M := @@ -285,6 +437,28 @@ Definition process_create_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), + (* then *) + ltac:(M.monadic ( + let contract_code := + M.get_field (| M.get_name (| globals, "evm" |), "output" |) in + let contract_code_gas := + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "contract_code" |) + ], + make_dict [] + |), + M.get_name (| globals, "GAS_CODE_DEPOSIT" |) + |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "rollback_transaction" |), make_list [ @@ -296,6 +470,7 @@ Definition process_create_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) + |) in M.pure Constant.None_)). Definition process_message : Value.t -> Value.t -> M := @@ -317,6 +492,24 @@ Definition process_message : Value.t -> Value.t -> M := Items containing execution specific objects " in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_field (| M.get_name (| globals, "message" |), "depth" |), + M.get_name (| globals, "STACK_DEPTH_LIMIT" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "StackDepthLimitError" |), + make_list [ + Constant.str "Stack depth limit reached" + ], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -335,6 +528,32 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + M.get_field (| M.get_name (| globals, "message" |), "should_transfer_value" |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "message" |), "value" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "move_ether" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "caller" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |); + M.get_field (| M.get_name (| globals, "message" |), "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let evm := @@ -347,6 +566,21 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "rollback_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "commit_transaction" |), make_list [ @@ -358,6 +592,7 @@ Definition process_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) + |) in M.pure Constant.None_)). Definition execute_code : Value.t -> Value.t -> M := @@ -397,4 +632,5 @@ Definition execute_code : Value.t -> Value.t -> M := (* At stmt: unsupported node type: Try *) let _ := M.return_ (| M.get_name (| globals, "evm" |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/vm/memory.v b/CoqOfPython/ethereum/constantinople/vm/memory.v index 4b107fd..08d2290 100644 --- a/CoqOfPython/ethereum/constantinople/vm/memory.v +++ b/CoqOfPython/ethereum/constantinople/vm/memory.v @@ -21,13 +21,13 @@ Require ethereum.utils.byte. Axiom ethereum_utils_byte_right_pad_zero_bytes : IsGlobalAlias globals ethereum.utils.byte.globals "right_pad_zero_bytes". -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". Definition memory_write : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,7 +45,22 @@ Definition memory_write : Value.t -> Value.t -> M := Data to write to memory. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |), + M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) |) |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_)). @@ -71,7 +86,23 @@ Definition memory_read_bytes : Value.t -> Value.t -> M := Data read from memory. " in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |) + M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |) |) + |) in M.pure Constant.None_)). Definition buffer_read : Value.t -> Value.t -> M := @@ -98,9 +129,25 @@ Definition buffer_read : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "right_pad_zero_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |) |); + M.get_subscript (| M.get_name (| globals, "buffer" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |) |); M.get_name (| globals, "size" |) ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/__init__.v index 0210a12..3c7f471 100644 --- a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/__init__.v +++ b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/__init__.v @@ -18,9 +18,9 @@ Addresses of precompiled contracts and mappings to their implementations. ". -Require utils.hexadecimal. -Axiom utils_hexadecimal_hex_to_address : - IsGlobalAlias globals utils.hexadecimal.globals "hex_to_address". +Require ethereum.constantinople.utils.hexadecimal. +Axiom ethereum_constantinople_utils_hexadecimal_hex_to_address : + IsGlobalAlias globals ethereum.constantinople.utils.hexadecimal.globals "hex_to_address". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS"; Constant.str "MODEXP_ADDRESS"; Constant.str "ALT_BN128_ADD_ADDRESS"; Constant.str "ALT_BN128_MUL_ADDRESS"; Constant.str "ALT_BN128_PAIRING_CHECK_ADDRESS"; Constant.str "BLAKE2F_ADDRESS" ] diff --git a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/alt_bn128.v index 90f245d..f938fae 100644 --- a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/alt_bn128.v +++ b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/alt_bn128.v @@ -45,21 +45,21 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.constantinople.vm.__init__. +Axiom ethereum_constantinople_vm___init___Evm : + IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.constantinople.vm.gas. +Axiom ethereum_constantinople_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "charge_gas". -Require vm.memory. -Axiom vm_memory_buffer_read : - IsGlobalAlias globals vm.memory.globals "buffer_read". +Require ethereum.constantinople.vm.memory. +Axiom ethereum_constantinople_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.constantinople.vm.memory.globals "buffer_read". -Require exceptions. -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". +Require ethereum.constantinople.vm.exceptions. +Axiom ethereum_constantinople_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.constantinople.vm.exceptions.globals "OutOfGasError". Definition alt_bn128_add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -210,6 +210,18 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) in For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ] do let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -353,6 +365,18 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) in For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ] do let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -425,6 +449,27 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| + BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 192 + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let result := @@ -464,7 +509,7 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "data" |), BinOp.add (| + M.get_subscript (| M.get_name (| globals, "data" |), M.slice (| BinOp.add (| BinOp.mult (| M.get_name (| globals, "i" |), Constant.int 192 @@ -473,11 +518,35 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := Constant.int 32, M.get_name (| globals, "j" |) |) - |) |) + |), BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "j" |), + Constant.int 1 + |) + |) + |) |) |) ], make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -538,10 +607,80 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "p" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "q" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let result := + BinOp.mult (| + M.get_name (| globals, "result" |), + M.call (| + M.get_name (| globals, "pairing" |), + make_list [ + M.get_name (| globals, "q" |); + M.get_name (| globals, "p" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "result" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| diff --git a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/ecrecover.v index 0cbcf16..67d304b 100644 --- a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/ecrecover.v @@ -37,19 +37,19 @@ Require ethereum.utils.byte. Axiom ethereum_utils_byte_left_pad_zero_bytes : IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.constantinople.vm.__init__. +Axiom ethereum_constantinople_vm___init___Evm : + IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_ECRECOVER : - IsGlobalAlias globals vm.gas.globals "GAS_ECRECOVER". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.constantinople.vm.gas. +Axiom ethereum_constantinople_vm_gas_GAS_ECRECOVER : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_ECRECOVER". +Axiom ethereum_constantinople_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "charge_gas". -Require vm.memory. -Axiom vm_memory_buffer_read : - IsGlobalAlias globals vm.memory.globals "buffer_read". +Require ethereum.constantinople.vm.memory. +Axiom ethereum_constantinople_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.constantinople.vm.memory.globals "buffer_read". Definition ecrecover : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -188,12 +188,78 @@ Definition ecrecover : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "v" |), + Constant.int 27 + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "v" |), + Constant.int 28 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + Constant.int 0, + M.get_name (| globals, "r" |) + |), + ltac:(M.monadic ( + Compare.gt_e (| + M.get_name (| globals, "r" |), + M.get_name (| globals, "SECP256K1N" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + Constant.int 0, + M.get_name (| globals, "s" |) + |), + ltac:(M.monadic ( + Compare.gt_e (| + M.get_name (| globals, "s" |), + M.get_name (| globals, "SECP256K1N" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: Try *) @@ -204,7 +270,7 @@ Definition ecrecover : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12 |) in + |), M.slice (| Constant.int 12, Constant.int 32 |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/identity.v index fa96704..6a8eb62 100644 --- a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/identity.v +++ b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/identity.v @@ -25,17 +25,17 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.constantinople.vm.__init__. +Axiom ethereum_constantinople_vm___init___Evm : + IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_IDENTITY : - IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY". -Axiom vm_gas_GAS_IDENTITY_WORD : - IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY_WORD". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.constantinople.vm.gas. +Axiom ethereum_constantinople_vm_gas_GAS_IDENTITY : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_IDENTITY". +Axiom ethereum_constantinople_vm_gas_GAS_IDENTITY_WORD : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_IDENTITY_WORD". +Axiom ethereum_constantinople_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "charge_gas". Definition identity : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/mapping.v index b1a0ed3..f6570fb 100644 --- a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/mapping.v +++ b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/mapping.v @@ -23,54 +23,54 @@ Axiom typing_Callable : Axiom typing_Dict : IsGlobalAlias globals typing.globals "Dict". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.constantinople.fork_types. +Axiom ethereum_constantinople_fork_types_Address : + IsGlobalAlias globals ethereum.constantinople.fork_types.globals "Address". -Require __init__. -Axiom __init___ALT_BN128_ADD_ADDRESS : - IsGlobalAlias globals __init__.globals "ALT_BN128_ADD_ADDRESS". -Axiom __init___ALT_BN128_MUL_ADDRESS : - IsGlobalAlias globals __init__.globals "ALT_BN128_MUL_ADDRESS". -Axiom __init___ALT_BN128_PAIRING_CHECK_ADDRESS : - IsGlobalAlias globals __init__.globals "ALT_BN128_PAIRING_CHECK_ADDRESS". -Axiom __init___ECRECOVER_ADDRESS : - IsGlobalAlias globals __init__.globals "ECRECOVER_ADDRESS". -Axiom __init___IDENTITY_ADDRESS : - IsGlobalAlias globals __init__.globals "IDENTITY_ADDRESS". -Axiom __init___MODEXP_ADDRESS : - IsGlobalAlias globals __init__.globals "MODEXP_ADDRESS". -Axiom __init___RIPEMD160_ADDRESS : - IsGlobalAlias globals __init__.globals "RIPEMD160_ADDRESS". -Axiom __init___SHA256_ADDRESS : - IsGlobalAlias globals __init__.globals "SHA256_ADDRESS". +Require ethereum.constantinople.vm.precompiled_contracts.__init__. +Axiom ethereum_constantinople_vm_precompiled_contracts___init___ALT_BN128_ADD_ADDRESS : + IsGlobalAlias globals ethereum.constantinople.vm.precompiled_contracts.__init__.globals "ALT_BN128_ADD_ADDRESS". +Axiom ethereum_constantinople_vm_precompiled_contracts___init___ALT_BN128_MUL_ADDRESS : + IsGlobalAlias globals ethereum.constantinople.vm.precompiled_contracts.__init__.globals "ALT_BN128_MUL_ADDRESS". +Axiom ethereum_constantinople_vm_precompiled_contracts___init___ALT_BN128_PAIRING_CHECK_ADDRESS : + IsGlobalAlias globals ethereum.constantinople.vm.precompiled_contracts.__init__.globals "ALT_BN128_PAIRING_CHECK_ADDRESS". +Axiom ethereum_constantinople_vm_precompiled_contracts___init___ECRECOVER_ADDRESS : + IsGlobalAlias globals ethereum.constantinople.vm.precompiled_contracts.__init__.globals "ECRECOVER_ADDRESS". +Axiom ethereum_constantinople_vm_precompiled_contracts___init___IDENTITY_ADDRESS : + IsGlobalAlias globals ethereum.constantinople.vm.precompiled_contracts.__init__.globals "IDENTITY_ADDRESS". +Axiom ethereum_constantinople_vm_precompiled_contracts___init___MODEXP_ADDRESS : + IsGlobalAlias globals ethereum.constantinople.vm.precompiled_contracts.__init__.globals "MODEXP_ADDRESS". +Axiom ethereum_constantinople_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : + IsGlobalAlias globals ethereum.constantinople.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". +Axiom ethereum_constantinople_vm_precompiled_contracts___init___SHA256_ADDRESS : + IsGlobalAlias globals ethereum.constantinople.vm.precompiled_contracts.__init__.globals "SHA256_ADDRESS". -Require alt_bn128. -Axiom alt_bn128_alt_bn128_add : - IsGlobalAlias globals alt_bn128.globals "alt_bn128_add". -Axiom alt_bn128_alt_bn128_mul : - IsGlobalAlias globals alt_bn128.globals "alt_bn128_mul". -Axiom alt_bn128_alt_bn128_pairing_check : - IsGlobalAlias globals alt_bn128.globals "alt_bn128_pairing_check". +Require ethereum.constantinople.vm.precompiled_contracts.alt_bn128. +Axiom ethereum_constantinople_vm_precompiled_contracts_alt_bn128_alt_bn128_add : + IsGlobalAlias globals ethereum.constantinople.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_add". +Axiom ethereum_constantinople_vm_precompiled_contracts_alt_bn128_alt_bn128_mul : + IsGlobalAlias globals ethereum.constantinople.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_mul". +Axiom ethereum_constantinople_vm_precompiled_contracts_alt_bn128_alt_bn128_pairing_check : + IsGlobalAlias globals ethereum.constantinople.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_pairing_check". -Require ecrecover. -Axiom ecrecover_ecrecover : - IsGlobalAlias globals ecrecover.globals "ecrecover". +Require ethereum.constantinople.vm.precompiled_contracts.ecrecover. +Axiom ethereum_constantinople_vm_precompiled_contracts_ecrecover_ecrecover : + IsGlobalAlias globals ethereum.constantinople.vm.precompiled_contracts.ecrecover.globals "ecrecover". -Require identity. -Axiom identity_identity : - IsGlobalAlias globals identity.globals "identity". +Require ethereum.constantinople.vm.precompiled_contracts.identity. +Axiom ethereum_constantinople_vm_precompiled_contracts_identity_identity : + IsGlobalAlias globals ethereum.constantinople.vm.precompiled_contracts.identity.globals "identity". -Require modexp. -Axiom modexp_modexp : - IsGlobalAlias globals modexp.globals "modexp". +Require ethereum.constantinople.vm.precompiled_contracts.modexp. +Axiom ethereum_constantinople_vm_precompiled_contracts_modexp_modexp : + IsGlobalAlias globals ethereum.constantinople.vm.precompiled_contracts.modexp.globals "modexp". -Require ripemd160. -Axiom ripemd160_ripemd160 : - IsGlobalAlias globals ripemd160.globals "ripemd160". +Require ethereum.constantinople.vm.precompiled_contracts.ripemd160. +Axiom ethereum_constantinople_vm_precompiled_contracts_ripemd160_ripemd160 : + IsGlobalAlias globals ethereum.constantinople.vm.precompiled_contracts.ripemd160.globals "ripemd160". -Require sha256. -Axiom sha256_sha256 : - IsGlobalAlias globals sha256.globals "sha256". +Require ethereum.constantinople.vm.precompiled_contracts.sha256. +Axiom ethereum_constantinople_vm_precompiled_contracts_sha256_sha256 : + IsGlobalAlias globals ethereum.constantinople.vm.precompiled_contracts.sha256.globals "sha256". (* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/modexp.v index aff5b85..d688844 100644 --- a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/modexp.v +++ b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/modexp.v @@ -25,17 +25,17 @@ Axiom ethereum_base_types_Bytes : Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.constantinople.vm.__init__. +Axiom ethereum_constantinople_vm___init___Evm : + IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.constantinople.vm.gas. +Axiom ethereum_constantinople_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "charge_gas". -Require memory. -Axiom memory_buffer_read : - IsGlobalAlias globals memory.globals "buffer_read". +Require ethereum.constantinople.vm.memory. +Axiom ethereum_constantinople_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.constantinople.vm.memory.globals "buffer_read". Definition GQUADDIVISOR : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -181,6 +181,39 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "exp_length" |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let adjusted_exp_length := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "max" |), + make_list [ + Constant.int 0; + BinOp.sub (| + M.call (| + M.get_field (| M.get_name (| globals, "exp_head" |), "bit_length" |), + make_list [], + make_dict [] + |), + Constant.int 1 + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let adjusted_exp_length := M.call (| M.get_name (| globals, "Uint" |), @@ -267,6 +300,36 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_name (| globals, "base_length" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "modulus_length" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [], + make_dict [] + |) + |) in + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let base := @@ -329,6 +392,30 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "modulus" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + BinOp.mult (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + Constant.bytes "00" + ], + make_dict [] + |), + M.get_name (| globals, "modulus_length" |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| @@ -365,7 +452,53 @@ Definition get_mult_complexity : Value.t -> Value.t -> M := Estimate the complexity of performing Karatsuba multiplication. " in let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "x" |), + Constant.int 64 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.pow (| + M.get_name (| globals, "x" |), + Constant.int 2 + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "x" |), + Constant.int 1024 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.sub (| + BinOp.add (| + BinOp.floor_div (| + BinOp.pow (| + M.get_name (| globals, "x" |), + Constant.int 2 + |), + Constant.int 4 + |), + BinOp.mult (| + Constant.int 96, + M.get_name (| globals, "x" |) + |) + |), + Constant.int 3072 + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| BinOp.sub (| BinOp.add (| @@ -383,6 +516,7 @@ Definition get_mult_complexity : Value.t -> Value.t -> M := |), Constant.int 199680 |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/ripemd160.v index 96f8dcd..df42cbf 100644 --- a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/ripemd160.v +++ b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/ripemd160.v @@ -31,17 +31,17 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.constantinople.vm.__init__. +Axiom ethereum_constantinople_vm___init___Evm : + IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_RIPEMD160 : - IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160". -Axiom vm_gas_GAS_RIPEMD160_WORD : - IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160_WORD". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.constantinople.vm.gas. +Axiom ethereum_constantinople_vm_gas_GAS_RIPEMD160 : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_RIPEMD160". +Axiom ethereum_constantinople_vm_gas_GAS_RIPEMD160_WORD : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_RIPEMD160_WORD". +Axiom ethereum_constantinople_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "charge_gas". Definition ripemd160 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/sha256.v index 9f6d2bf..e89bb4b 100644 --- a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/sha256.v +++ b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/sha256.v @@ -27,17 +27,17 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.constantinople.vm.__init__. +Axiom ethereum_constantinople_vm___init___Evm : + IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_SHA256 : - IsGlobalAlias globals vm.gas.globals "GAS_SHA256". -Axiom vm_gas_GAS_SHA256_WORD : - IsGlobalAlias globals vm.gas.globals "GAS_SHA256_WORD". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.constantinople.vm.gas. +Axiom ethereum_constantinople_vm_gas_GAS_SHA256 : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_SHA256". +Axiom ethereum_constantinople_vm_gas_GAS_SHA256_WORD : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_SHA256_WORD". +Axiom ethereum_constantinople_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "charge_gas". Definition sha256 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/constantinople/vm/runtime.v b/CoqOfPython/ethereum/constantinople/vm/runtime.v index 2cd7652..90b65f5 100644 --- a/CoqOfPython/ethereum/constantinople/vm/runtime.v +++ b/CoqOfPython/ethereum/constantinople/vm/runtime.v @@ -25,9 +25,9 @@ Require ethereum.base_types. Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require instructions. -Axiom instructions_Ops : - IsGlobalAlias globals instructions.globals "Ops". +Require ethereum.constantinople.vm.instructions.__init__. +Axiom ethereum_constantinople_vm_instructions___init___Ops : + IsGlobalAlias globals ethereum.constantinople.vm.instructions.__init__.globals "Ops". Definition get_valid_jump_destinations : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -79,7 +79,55 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := |) do (* At stmt: unsupported node type: Try *) let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "current_opcode" |), + M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), + make_list [ + M.get_name (| globals, "pc" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.lt_e (| + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |), + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH32" |), "value" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let push_data_size := + BinOp.add (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) + |), + Constant.int 1 + |) in + let pc := BinOp.add + M.get_name (| globals, "push_data_size" |) + M.get_name (| globals, "push_data_size" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -90,4 +138,5 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := EndWhile. let _ := M.return_ (| M.get_name (| globals, "valid_jump_destinations" |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/vm/stack.v b/CoqOfPython/ethereum/constantinople/vm/stack.v index ea778df..04b1a75 100644 --- a/CoqOfPython/ethereum/constantinople/vm/stack.v +++ b/CoqOfPython/ethereum/constantinople/vm/stack.v @@ -25,11 +25,11 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require exceptions. -Axiom exceptions_StackOverflowError : - IsGlobalAlias globals exceptions.globals "StackOverflowError". -Axiom exceptions_StackUnderflowError : - IsGlobalAlias globals exceptions.globals "StackUnderflowError". +Require ethereum.constantinople.vm.exceptions. +Axiom ethereum_constantinople_vm_exceptions_StackOverflowError : + IsGlobalAlias globals ethereum.constantinople.vm.exceptions.globals "StackOverflowError". +Axiom ethereum_constantinople_vm_exceptions_StackUnderflowError : + IsGlobalAlias globals ethereum.constantinople.vm.exceptions.globals "StackUnderflowError". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -49,6 +49,24 @@ Definition pop : Value.t -> Value.t -> M := " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "StackUnderflowError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -57,6 +75,7 @@ Definition pop : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). Definition push : Value.t -> Value.t -> M := @@ -75,6 +94,24 @@ Definition push : Value.t -> Value.t -> M := " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), + Constant.int 1024 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "StackOverflowError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -85,4 +122,5 @@ Definition push : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/crypto/alt_bn128.v b/CoqOfPython/ethereum/crypto/alt_bn128.v index 44ac0df..f4ba848 100644 --- a/CoqOfPython/ethereum/crypto/alt_bn128.v +++ b/CoqOfPython/ethereum/crypto/alt_bn128.v @@ -8,11 +8,11 @@ The alt_bn128 curve ^^^^^^^^^^^^^^^^^^^ ". -Require __init__. -Axiom __init___elliptic_curve : - IsGlobalAlias globals __init__.globals "elliptic_curve". -Axiom __init___finite_field : - IsGlobalAlias globals __init__.globals "finite_field". +Require ethereum.crypto.__init__. +Axiom ethereum_crypto___init___elliptic_curve : + IsGlobalAlias globals ethereum.crypto.__init__.globals "elliptic_curve". +Axiom ethereum_crypto___init___finite_field : + IsGlobalAlias globals ethereum.crypto.__init__.globals "finite_field". Definition ALT_BN128_PRIME : Value.t := M.run ltac:(M.monadic ( Constant.int 21888242871839275222246405745257275088696311157297823662689037894645226208583 @@ -170,10 +170,11 @@ Definition BNF12 : Value.t := M.get_field (| M.get_name (| globals, "BNF12" |), "__new__" |), make_list [ M.get_name (| globals, "BNF12" |); - M.get_subscript (| M.get_name (| globals, "mul" |), Constant.None_:Constant.int 12 |) + M.get_subscript (| M.get_name (| globals, "mul" |), M.slice (| Constant.None_, Constant.int 12 |) |) ], make_dict [] |) + |) in M.pure Constant.None_)) ) ]. @@ -238,6 +239,7 @@ Definition bnf2_to_bnf12 : Value.t -> Value.t -> M := |) |) |) + |) in M.pure Constant.None_)). Definition bnp_to_bnp12 : Value.t -> Value.t -> M := @@ -279,6 +281,7 @@ Definition bnp_to_bnp12 : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition twist : Value.t -> Value.t -> M := @@ -320,6 +323,7 @@ Definition twist : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition linefunc : Value.t -> Value.t -> M := @@ -335,12 +339,102 @@ Definition linefunc : Value.t -> Value.t -> M := matter. " in let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "p1" |), "x" |), + M.get_field (| M.get_name (| globals, "p2" |), "x" |) + |), + (* then *) + ltac:(M.monadic ( + let lam := + BinOp.div (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "p2" |), "y" |), + M.get_field (| M.get_name (| globals, "p1" |), "y" |) + |), + BinOp.sub (| + M.get_field (| M.get_name (| globals, "p2" |), "x" |), + M.get_field (| M.get_name (| globals, "p1" |), "x" |) + |) + |) in + let _ := M.return_ (| + BinOp.sub (| + BinOp.mult (| + M.get_name (| globals, "lam" |), + BinOp.sub (| + M.get_field (| M.get_name (| globals, "t" |), "x" |), + M.get_field (| M.get_name (| globals, "p1" |), "x" |) + |) + |), + BinOp.sub (| + M.get_field (| M.get_name (| globals, "t" |), "y" |), + M.get_field (| M.get_name (| globals, "p1" |), "y" |) + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "p1" |), "y" |), + M.get_field (| M.get_name (| globals, "p2" |), "y" |) + |), + (* then *) + ltac:(M.monadic ( + let lam := + BinOp.div (| + BinOp.mult (| + M.call (| + M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), + make_list [ + Constant.int 3 + ], + make_dict [] + |), + BinOp.pow (| + M.get_field (| M.get_name (| globals, "p1" |), "x" |), + Constant.int 2 + |) + |), + BinOp.mult (| + M.call (| + M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), + make_list [ + Constant.int 2 + ], + make_dict [] + |), + M.get_field (| M.get_name (| globals, "p1" |), "y" |) + |) + |) in + let _ := M.return_ (| + BinOp.sub (| + BinOp.mult (| + M.get_name (| globals, "lam" |), + BinOp.sub (| + M.get_field (| M.get_name (| globals, "t" |), "x" |), + M.get_field (| M.get_name (| globals, "p1" |), "x" |) + |) + |), + BinOp.sub (| + M.get_field (| M.get_name (| globals, "t" |), "y" |), + M.get_field (| M.get_name (| globals, "p1" |), "y" |) + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| BinOp.sub (| M.get_field (| M.get_name (| globals, "t" |), "x" |), M.get_field (| M.get_name (| globals, "p1" |), "x" |) |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -354,6 +448,42 @@ Definition miller_loop : Value.t -> Value.t -> M := The core of the pairing algorithm. " in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.eq (| + M.get_name (| globals, "p" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP12" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "q" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP12" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let r := @@ -398,6 +528,41 @@ Definition miller_loop : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BinOp.bit_and (| + BinOp.sub (| + M.get_name (| globals, "ATE_PAIRING_COUNT" |), + Constant.int 1 + |), + BinOp.pow (| + Constant.int 2, + M.get_name (| globals, "i" |) + |) + |), + (* then *) + ltac:(M.monadic ( + let f := + BinOp.mult (| + M.get_name (| globals, "f" |), + M.call (| + M.get_name (| globals, "linefunc" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "q" |); + M.get_name (| globals, "p" |) + ], + make_dict [] + |) + |) in + let r := + BinOp.add (| + M.get_name (| globals, "r" |), + M.get_name (| globals, "q" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -493,6 +658,7 @@ Definition miller_loop : Value.t -> Value.t -> M := M.get_name (| globals, "ALT_BN128_CURVE_ORDER" |) |) |) + |) in M.pure Constant.None_)). Definition pairing : Value.t -> Value.t -> M := @@ -522,4 +688,5 @@ Definition pairing : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/crypto/blake2.v b/CoqOfPython/ethereum/crypto/blake2.v index 063cf6c..f00276b 100644 --- a/CoqOfPython/ethereum/crypto/blake2.v +++ b/CoqOfPython/ethereum/crypto/blake2.v @@ -62,7 +62,10 @@ Definition spit_le_to_uint : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_le_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "data" |), M.get_name (| globals, "start_position" |) |) + M.get_subscript (| M.get_name (| globals, "data" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.get_name (| globals, "start_position" |), + Constant.int 8 + |) |) |) ], make_dict [] |) @@ -72,6 +75,7 @@ Definition spit_le_to_uint : Value.t -> Value.t -> M := EndFor. let _ := M.return_ (| M.get_name (| globals, "words" |) + |) in M.pure Constant.None_)). Definition Blake2 : Value.t := @@ -98,7 +102,7 @@ Definition Blake2 : Value.t := M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "data" |), Constant.None_:Constant.int 4 |) + M.get_subscript (| M.get_name (| globals, "data" |), M.slice (| Constant.None_, Constant.int 4 |) |) ], make_dict [] |) in @@ -138,12 +142,13 @@ Definition Blake2 : Value.t := M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "data" |), Constant.int 212 |) + M.get_subscript (| M.get_name (| globals, "data" |), M.slice (| Constant.int 212, Constant.None_ |) |) ], make_dict [] |) in let _ := M.return_ (| make_tuple [ M.get_name (| globals, "rounds" |); M.get_name (| globals, "h" |); M.get_name (| globals, "m" |); M.get_name (| globals, "t_0" |); M.get_name (| globals, "t_1" |); M.get_name (| globals, "f" |) ] + |) in M.pure Constant.None_)) ); ( @@ -299,6 +304,7 @@ Definition Blake2 : Value.t := |) in let _ := M.return_ (| M.get_name (| globals, "v" |) + |) in M.pure Constant.None_)) ); ( @@ -330,11 +336,11 @@ Definition Blake2 : Value.t := Constant.int 16 |) in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "v" |), Constant.int 0 |), + M.get_subscript (| M.get_name (| globals, "v" |), M.slice (| Constant.int 0, Constant.int 8 |) |), M.get_name (| globals, "h" |) |) in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "v" |), Constant.int 8 |), + M.get_subscript (| M.get_name (| globals, "v" |), M.slice (| Constant.int 8, Constant.int 15 |) |), M.get_field (| M.get_name (| globals, "self" |), "IV" |) |) in let _ := M.assign (| @@ -352,6 +358,21 @@ Definition Blake2 : Value.t := |) |) in let _ := + (* if *) + M.if_then_else (| + M.get_name (| globals, "f" |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "v" |), Constant.int 14 |), + BinOp.bit_xor (| + M.get_subscript (| M.get_name (| globals, "v" |), Constant.int 14 |), + M.get_field (| M.get_name (| globals, "self" |), "mask_bits" |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in For M.get_name (| globals, "r" |) in M.call (| @@ -480,7 +501,7 @@ Definition Blake2 : Value.t := |) in EndFor. let result_message_words := - (* At expr: unsupported node type: GeneratorExp *) in + Constant.str "(* At expr: unsupported node type: GeneratorExp *)" in let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "struct" |), "pack" |), @@ -495,6 +516,7 @@ Definition Blake2 : Value.t := ] |), make_dict [] |) + |) in M.pure Constant.None_)) ) ]. diff --git a/CoqOfPython/ethereum/crypto/elliptic_curve.v b/CoqOfPython/ethereum/crypto/elliptic_curve.v index 5741aba..b70039d 100644 --- a/CoqOfPython/ethereum/crypto/elliptic_curve.v +++ b/CoqOfPython/ethereum/crypto/elliptic_curve.v @@ -18,19 +18,19 @@ Axiom typing_TypeVar : (* At top_level_stmt: unsupported node type: Import *) -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Require finite_field. -Axiom finite_field_Field : - IsGlobalAlias globals finite_field.globals "Field". +Require ethereum.crypto.finite_field. +Axiom ethereum_crypto_finite_field_Field : + IsGlobalAlias globals ethereum.crypto.finite_field.globals "Field". -Require hash. -Axiom hash_Hash32 : - IsGlobalAlias globals hash.globals "Hash32". +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". Definition SECP256K1N : Value.t := M.run ltac:(M.monadic ( Constant.int 115792089237316195423570985008687907852837564279074904382605163141518161494337 @@ -104,7 +104,7 @@ Definition secp256k1_recover : Value.t -> Value.t -> M := make_dict [] |) in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "signature" |), BinOp.sub (| + M.get_subscript (| M.get_name (| globals, "signature" |), M.slice (| BinOp.sub (| Constant.int 32, M.call (| M.get_name (| globals, "len" |), @@ -113,11 +113,11 @@ Definition secp256k1_recover : Value.t -> Value.t -> M := ], make_dict [] |) - |) |), + |), Constant.int 32 |) |), M.get_name (| globals, "r_bytes" |) |) in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "signature" |), BinOp.sub (| + M.get_subscript (| M.get_name (| globals, "signature" |), M.slice (| BinOp.sub (| Constant.int 64, M.call (| M.get_name (| globals, "len" |), @@ -126,7 +126,7 @@ Definition secp256k1_recover : Value.t -> Value.t -> M := ], make_dict [] |) - |) |), + |), Constant.int 64 |) |), M.get_name (| globals, "s_bytes" |) |) in let _ := M.assign (| @@ -153,9 +153,10 @@ Definition secp256k1_recover : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "public_key" |), "format" |), make_list [], make_dict [] - |), Constant.int 1 |) in + |), M.slice (| Constant.int 1, Constant.None_ |) |) in let _ := M.return_ (| M.get_name (| globals, "public_key" |) + |) in M.pure Constant.None_)). Definition EllipticCurve : Value.t := @@ -191,6 +192,7 @@ Definition EllipticCurve : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ) ] @@ -221,6 +223,7 @@ Definition EllipticCurve : Value.t := |) in let _ := M.return_ (| M.get_name (| globals, "res" |) + |) in M.pure Constant.None_)) ); ( @@ -232,6 +235,70 @@ Definition EllipticCurve : Value.t := `__new__()` directly. " in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + BoolOp.or (| + Compare.not_eq (| + M.get_name (| globals, "x" |), + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "self" |), "FIELD" |), "zero" |), + make_list [], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "y" |), + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "self" |), "FIELD" |), "zero" |), + make_list [], + make_dict [] + |) + |) + )) + |), + ltac:(M.monadic ( + Compare.not_eq (| + BinOp.sub (| + BinOp.sub (| + BinOp.sub (| + BinOp.pow (| + M.get_name (| globals, "y" |), + Constant.int 2 + |), + BinOp.pow (| + M.get_name (| globals, "x" |), + Constant.int 3 + |) + |), + BinOp.mult (| + M.get_field (| M.get_name (| globals, "self" |), "A" |), + M.get_name (| globals, "x" |) + |) + |), + M.get_field (| M.get_name (| globals, "self" |), "B" |) + |), + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "self" |), "FIELD" |), "zero" |), + make_list [], + make_dict [] + |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "ValueError" |), + make_list [ + Constant.str "Point not on curve" + ], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)) @@ -244,6 +311,30 @@ Definition EllipticCurve : Value.t := Test two points for equality. " in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "other" |); + M.call (| + M.get_name (| globals, "type" |), + make_list [ + M.get_name (| globals, "self" |) + ], + make_dict [] + |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -259,6 +350,7 @@ Definition EllipticCurve : Value.t := |) )) |) + |) in M.pure Constant.None_)) ); ( @@ -276,6 +368,7 @@ Definition EllipticCurve : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -290,6 +383,28 @@ Definition EllipticCurve : Value.t := make_tuple [ M.get_field (| M.get_name (| globals, "self" |), "x" |); M.get_field (| M.get_name (| globals, "self" |), "y" |); M.get_field (| M.get_name (| globals, "self" |), "FIELD" |) ] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_name (| globals, "x" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "y" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "self" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let lam := @@ -359,6 +474,7 @@ Definition EllipticCurve : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -379,12 +495,95 @@ Definition EllipticCurve : Value.t := make_tuple [ M.get_field (| M.get_name (| globals, "self" |), "x" |); M.get_field (| M.get_name (| globals, "self" |), "y" |); M.get_field (| M.get_name (| globals, "other" |), "x" |); M.get_field (| M.get_name (| globals, "other" |), "y" |) ] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_name (| globals, "self_x" |), + M.get_name (| globals, "ZERO" |) + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "self_y" |), + M.get_name (| globals, "ZERO" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "other" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_name (| globals, "other_x" |), + M.get_name (| globals, "ZERO" |) + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "other_y" |), + M.get_name (| globals, "ZERO" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "self" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "self_x" |), + M.get_name (| globals, "other_x" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "self_y" |), + M.get_name (| globals, "other_y" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "double" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let lam := @@ -436,6 +635,7 @@ Definition EllipticCurve : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -476,6 +676,25 @@ Definition EllipticCurve : Value.t := Constant.int 0 |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + BinOp.mod_ (| + M.get_name (| globals, "n" |), + Constant.int 2 + |), + Constant.int 1 + |), + (* then *) + ltac:(M.monadic ( + let res := + BinOp.add (| + M.get_name (| globals, "res" |), + M.get_name (| globals, "s" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let s := @@ -489,6 +708,7 @@ Definition EllipticCurve : Value.t := EndWhile. let _ := M.return_ (| M.get_name (| globals, "res" |) + |) in M.pure Constant.None_)) ) ]. diff --git a/CoqOfPython/ethereum/crypto/finite_field.v b/CoqOfPython/ethereum/crypto/finite_field.v index 3707fb1..c6a59cd 100644 --- a/CoqOfPython/ethereum/crypto/finite_field.v +++ b/CoqOfPython/ethereum/crypto/finite_field.v @@ -26,11 +26,11 @@ Require typing_extensions. Axiom typing_extensions_Protocol : IsGlobalAlias globals typing_extensions.globals "Protocol". -Require base_types. -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes32 : - IsGlobalAlias globals base_types.globals "Bytes32". +Require ethereum.base_types. +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". Definition F : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -192,6 +192,7 @@ Definition PrimeField : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -207,6 +208,7 @@ Definition PrimeField : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -221,6 +223,7 @@ Definition PrimeField : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ) ] @@ -241,6 +244,7 @@ Definition PrimeField : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -255,6 +259,7 @@ Definition PrimeField : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -262,6 +267,24 @@ Definition PrimeField : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "right" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -286,6 +309,7 @@ Definition PrimeField : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -300,6 +324,7 @@ Definition PrimeField : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -307,6 +332,24 @@ Definition PrimeField : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "right" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -331,6 +374,7 @@ Definition PrimeField : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -338,6 +382,24 @@ Definition PrimeField : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "left" ] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "left" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -362,6 +424,7 @@ Definition PrimeField : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -369,6 +432,24 @@ Definition PrimeField : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "right" |); + M.get_name (| globals, "int" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -393,6 +474,7 @@ Definition PrimeField : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -407,6 +489,7 @@ Definition PrimeField : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -421,6 +504,7 @@ Definition PrimeField : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -456,6 +540,7 @@ Definition PrimeField : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -470,6 +555,7 @@ Definition PrimeField : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -497,6 +583,7 @@ Definition PrimeField : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -512,6 +599,7 @@ Definition PrimeField : Value.t := make_dict [] |) |) + |) in M.pure Constant.None_)) ); ( @@ -523,6 +611,7 @@ Definition PrimeField : Value.t := M.get_name (| globals, "self" |), UnOp.sub (| Constant.int 1 |) |) + |) in M.pure Constant.None_)) ); ( @@ -552,6 +641,7 @@ Definition PrimeField : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ) ]. @@ -594,6 +684,7 @@ Definition GaloisField : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -628,6 +719,7 @@ Definition GaloisField : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -695,6 +787,7 @@ Definition GaloisField : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ) ] @@ -708,7 +801,7 @@ Definition GaloisField : Value.t := M.get_field (| M.get_name (| globals, "tuple" |), "__new__" |), make_list [ M.get_name (| globals, "cls" |); - (* At expr: unsupported node type: GeneratorExp *) + Constant.str "(* At expr: unsupported node type: GeneratorExp *)" ], make_dict [] |) in @@ -730,6 +823,7 @@ Definition GaloisField : Value.t := |) |) in let _ := M.return_ (| M.get_name (| globals, "self" |) + |) in M.pure Constant.None_)) ); ( @@ -737,6 +831,30 @@ Definition GaloisField : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "right" |); + M.call (| + M.get_name (| globals, "type" |), + make_list [ + M.get_name (| globals, "self" |) + ], + make_dict [] + |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -750,10 +868,11 @@ Definition GaloisField : Value.t := ], make_dict [] |); - (* At expr: unsupported node type: GeneratorExp *) + Constant.str "(* At expr: unsupported node type: GeneratorExp *)" ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -768,6 +887,7 @@ Definition GaloisField : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -782,6 +902,7 @@ Definition GaloisField : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -789,6 +910,30 @@ Definition GaloisField : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "right" |); + M.call (| + M.get_name (| globals, "type" |), + make_list [ + M.get_name (| globals, "self" |) + ], + make_dict [] + |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) @@ -804,10 +949,11 @@ Definition GaloisField : Value.t := ], make_dict [] |); - (* At expr: unsupported node type: GeneratorExp *) + Constant.str "(* At expr: unsupported node type: GeneratorExp *)" ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -815,6 +961,30 @@ Definition GaloisField : Value.t := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "left" ] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "left" |); + M.call (| + M.get_name (| globals, "type" |), + make_list [ + M.get_name (| globals, "self" |) + ], + make_dict [] + |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "NotImplemented" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -828,10 +998,11 @@ Definition GaloisField : Value.t := ], make_dict [] |); - (* At expr: unsupported node type: GeneratorExp *) + Constant.str "(* At expr: unsupported node type: GeneratorExp *)" ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -946,10 +1117,11 @@ Definition GaloisField : Value.t := ], make_dict [] |); - M.get_subscript (| M.get_name (| globals, "mul" |), Constant.None_:M.get_name (| globals, "degree" |) |) + M.get_subscript (| M.get_name (| globals, "mul" |), M.slice (| Constant.None_, M.get_name (| globals, "degree" |) |) |) ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -964,6 +1136,7 @@ Definition GaloisField : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -978,6 +1151,7 @@ Definition GaloisField : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -993,6 +1167,7 @@ Definition GaloisField : Value.t := make_dict [] |) |) + |) in M.pure Constant.None_)) ); ( @@ -1010,10 +1185,11 @@ Definition GaloisField : Value.t := ], make_dict [] |); - (* At expr: unsupported node type: GeneratorExp *) + Constant.str "(* At expr: unsupported node type: GeneratorExp *)" ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -1035,10 +1211,11 @@ Definition GaloisField : Value.t := ], make_dict [] |); - (* At expr: unsupported node type: GeneratorExp *) + Constant.str "(* At expr: unsupported node type: GeneratorExp *)" ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -1067,6 +1244,20 @@ Definition GaloisField : Value.t := make_dict [] |) do let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| + M.get_subscript (| M.get_name (| globals, "self" |), M.get_name (| globals, "i" |) |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -1076,7 +1267,7 @@ Definition GaloisField : Value.t := Constant.str "deg() does not support zero" ], make_dict [] - |)) + |)) |) in M.pure Constant.None_)) ); ( @@ -1254,17 +1445,217 @@ Definition GaloisField : Value.t := make_dict [] |) do let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| + M.get_subscript (| M.get_name (| globals, "x1" |), M.get_name (| globals, "i" |) |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let d1 := + M.get_name (| globals, "i" |) in + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. While Constant.bool true do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "d1" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let ans := + M.get_name (| globals, "f1" |) in + let q := + M.call (| + M.get_name (| globals, "pow" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "x1" |), Constant.int 0 |); + UnOp.sub (| Constant.int 1 |); + M.get_field (| M.get_name (| globals, "self" |), "PRIME" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ans" |) + ], + make_dict [] + |) + ], + make_dict [] + |) do + let _ := M.assign_op (| + BinOp.mult, + M.get_subscript (| M.get_name (| globals, "ans" |), M.get_name (| globals, "i" |) |), + M.get_name (| globals, "q" |) + |) in + EndFor. + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "d2" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let ans := + M.get_name (| globals, "f2" |) in + let q := + M.call (| + M.get_name (| globals, "pow" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "x2" |), Constant.int 0 |); + UnOp.sub (| Constant.int 1 |); + M.get_field (| M.get_name (| globals, "self" |), "PRIME" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ans" |) + ], + make_dict [] + |) + ], + make_dict [] + |) do + let ans := BinOp.mult + M.get_name (| globals, "q" |) + M.get_name (| globals, "q" |) in + EndFor. + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "d1" |), + M.get_name (| globals, "d2" |) + |), + (* then *) + ltac:(M.monadic ( + let q := + BinOp.mult (| + M.get_subscript (| M.get_name (| globals, "x2" |), M.get_name (| globals, "d2" |) |), + M.call (| + M.get_name (| globals, "pow" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "x1" |), M.get_name (| globals, "d1" |) |); + UnOp.sub (| Constant.int 1 |); + M.get_field (| M.get_name (| globals, "self" |), "PRIME" |) + ], + make_dict [] + |) + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + BinOp.sub (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "self" |), "MODULUS" |) + ], + make_dict [] + |), + BinOp.sub (| + M.get_name (| globals, "d2" |), + M.get_name (| globals, "d1" |) + |) + |) + ], + make_dict [] + |) do + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "x2" |), BinOp.add (| + M.get_name (| globals, "i" |), + BinOp.sub (| + M.get_name (| globals, "d2" |), + M.get_name (| globals, "d1" |) + |) + |) |), + BinOp.mod_ (| + BinOp.sub (| + M.get_subscript (| M.get_name (| globals, "x2" |), BinOp.add (| + M.get_name (| globals, "i" |), + BinOp.sub (| + M.get_name (| globals, "d2" |), + M.get_name (| globals, "d1" |) + |) + |) |), + BinOp.mult (| + M.get_name (| globals, "q" |), + M.get_subscript (| M.get_name (| globals, "x1" |), M.get_name (| globals, "i" |) |) + |) + |), + M.get_name (| globals, "p" |) + |) + |) in + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "f2" |), BinOp.add (| + M.get_name (| globals, "i" |), + BinOp.sub (| + M.get_name (| globals, "d2" |), + M.get_name (| globals, "d1" |) + |) + |) |), + BinOp.mod_ (| + BinOp.sub (| + M.get_subscript (| M.get_name (| globals, "f2" |), BinOp.add (| + M.get_name (| globals, "i" |), + BinOp.sub (| + M.get_name (| globals, "d2" |), + M.get_name (| globals, "d1" |) + |) + |) |), + BinOp.mult (| + M.get_name (| globals, "q" |), + M.get_subscript (| M.get_name (| globals, "f1" |), M.get_name (| globals, "i" |) |) + |) + |), + M.get_name (| globals, "p" |) + |) + |) in + EndFor. + While Compare.eq (| + M.get_subscript (| M.get_name (| globals, "x2" |), M.get_name (| globals, "d2" |) |), + Constant.int 0 + |) do + let d2 := BinOp.sub + Constant.int 1 + Constant.int 1 in + EndWhile. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let q := BinOp.mult (| M.get_subscript (| M.get_name (| globals, "x1" |), M.get_name (| globals, "d1" |) |), @@ -1374,6 +1765,7 @@ Definition GaloisField : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -1389,6 +1781,25 @@ Definition GaloisField : Value.t := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "exponent" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let self := + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "multiplicative_inverse" |), + make_list [], + make_dict [] + |) in + let exponent := + UnOp.sub (| M.get_name (| globals, "exponent" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let res := @@ -1426,6 +1837,23 @@ Definition GaloisField : Value.t := Constant.int 0 |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + BinOp.mod_ (| + M.get_name (| globals, "exponent" |), + Constant.int 2 + |), + Constant.int 1 + |), + (* then *) + ltac:(M.monadic ( + let res := BinOp.mult + M.get_name (| globals, "s" |) + M.get_name (| globals, "s" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let s := BinOp.mult @@ -1437,6 +1865,7 @@ Definition GaloisField : Value.t := EndWhile. let _ := M.return_ (| M.get_name (| globals, "res" |) + |) in M.pure Constant.None_)) ); ( @@ -1451,6 +1880,7 @@ Definition GaloisField : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ); ( @@ -1511,6 +1941,7 @@ Definition GaloisField : Value.t := EndFor. let _ := M.return_ (| M.get_name (| globals, "ans" |) + |) in M.pure Constant.None_)) ) ]. diff --git a/CoqOfPython/ethereum/crypto/hash.v b/CoqOfPython/ethereum/crypto/hash.v index fff054d..58d2b5d 100644 --- a/CoqOfPython/ethereum/crypto/hash.v +++ b/CoqOfPython/ethereum/crypto/hash.v @@ -21,13 +21,13 @@ Require Crypto.Hash. Axiom Crypto_Hash_keccak : IsGlobalAlias globals Crypto.Hash.globals "keccak". -Require base_types. -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes32 : - IsGlobalAlias globals base_types.globals "Bytes32". -Axiom base_types_Bytes64 : - IsGlobalAlias globals base_types.globals "Bytes64". +Require ethereum.base_types. +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Bytes64 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes64". Definition Hash32 : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes32" |) @@ -77,6 +77,7 @@ Definition keccak256 : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition keccak512 : Value.t -> Value.t -> M := @@ -119,4 +120,5 @@ Definition keccak512 : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/blocks.v b/CoqOfPython/ethereum/dao_fork/blocks.v index 6501788..b46e806 100644 --- a/CoqOfPython/ethereum/dao_fork/blocks.v +++ b/CoqOfPython/ethereum/dao_fork/blocks.v @@ -22,35 +22,35 @@ Require typing. Axiom typing_Tuple : IsGlobalAlias globals typing.globals "Tuple". -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes8 : - IsGlobalAlias globals base_types.globals "Bytes8". -Axiom base_types_Bytes32 : - IsGlobalAlias globals base_types.globals "Bytes32". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require crypto.hash. -Axiom crypto_hash_Hash32 : - IsGlobalAlias globals crypto.hash.globals "Hash32". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". - -Require transactions. -Axiom transactions_Transaction : - IsGlobalAlias globals transactions.globals "Transaction". +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes8 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes8". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". + +Require ethereum.dao_fork.fork_types. +Axiom ethereum_dao_fork_fork_types_Address : + IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "Address". +Axiom ethereum_dao_fork_fork_types_Bloom : + IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "Bloom". +Axiom ethereum_dao_fork_fork_types_Root : + IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "Root". + +Require ethereum.dao_fork.transactions. +Axiom ethereum_dao_fork_transactions_Transaction : + IsGlobalAlias globals ethereum.dao_fork.transactions.globals "Transaction". Definition Header : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/dao_fork/bloom.v b/CoqOfPython/ethereum/dao_fork/bloom.v index 04650ff..536d4e0 100644 --- a/CoqOfPython/ethereum/dao_fork/bloom.v +++ b/CoqOfPython/ethereum/dao_fork/bloom.v @@ -33,13 +33,13 @@ Require ethereum.crypto.hash. Axiom ethereum_crypto_hash_keccak256 : IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". +Require ethereum.dao_fork.blocks. +Axiom ethereum_dao_fork_blocks_Log : + IsGlobalAlias globals ethereum.dao_fork.blocks.globals "Log". -Require fork_types. -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". +Require ethereum.dao_fork.fork_types. +Axiom ethereum_dao_fork_fork_types_Bloom : + IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "Bloom". Definition add_to_bloom : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -72,7 +72,10 @@ Definition add_to_bloom : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |) |) + M.get_subscript (| M.get_name (| globals, "hash" |), M.slice (| M.get_name (| globals, "idx" |), BinOp.add (| + M.get_name (| globals, "idx" |), + Constant.int 2 + |) |) |) ], make_dict [] |), @@ -157,4 +160,5 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/dao.v b/CoqOfPython/ethereum/dao_fork/dao.v index cc4c36a..1b3d368 100644 --- a/CoqOfPython/ethereum/dao_fork/dao.v +++ b/CoqOfPython/ethereum/dao_fork/dao.v @@ -20,20 +20,20 @@ collection of accounts (The Dao and all its children) to a recovery contract. The recovery contract was previously created using normal contract deployment. ". -Require state. -Axiom state_State : - IsGlobalAlias globals state.globals "State". -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". -Axiom state_move_ether : - IsGlobalAlias globals state.globals "move_ether". +Require ethereum.dao_fork.state. +Axiom ethereum_dao_fork_state_State : + IsGlobalAlias globals ethereum.dao_fork.state.globals "State". +Axiom ethereum_dao_fork_state_get_account : + IsGlobalAlias globals ethereum.dao_fork.state.globals "get_account". +Axiom ethereum_dao_fork_state_move_ether : + IsGlobalAlias globals ethereum.dao_fork.state.globals "move_ether". -Require utils.hexadecimal. -Axiom utils_hexadecimal_hex_to_address : - IsGlobalAlias globals utils.hexadecimal.globals "hex_to_address". +Require ethereum.dao_fork.utils.hexadecimal. +Axiom ethereum_dao_fork_utils_hexadecimal_hex_to_address : + IsGlobalAlias globals ethereum.dao_fork.utils.hexadecimal.globals "hex_to_address". Definition DAO_ACCOUNTS : Value.t := M.run ltac:(M.monadic ( - (* At expr: unsupported node type: ListComp *) + Constant.str "(* At expr: unsupported node type: ListComp *)" )). Definition DAO_RECOVERY : Value.t := M.run ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/dao_fork/fork.v b/CoqOfPython/ethereum/dao_fork/fork.v index 7533ecd..bfac7ab 100644 --- a/CoqOfPython/ethereum/dao_fork/fork.v +++ b/CoqOfPython/ethereum/dao_fork/fork.v @@ -65,99 +65,99 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U64 : - IsGlobalAlias globals base_types.globals "U64". -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_U256_CEIL_VALUE : - IsGlobalAlias globals base_types.globals "U256_CEIL_VALUE". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes32 : - IsGlobalAlias globals base_types.globals "Bytes32". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". - -Require __init__. -Axiom __init___FORK_CRITERIA : - IsGlobalAlias globals __init__.globals "FORK_CRITERIA". -Axiom __init___vm : - IsGlobalAlias globals __init__.globals "vm". - -Require blocks. -Axiom blocks_Block : - IsGlobalAlias globals blocks.globals "Block". -Axiom blocks_Header : - IsGlobalAlias globals blocks.globals "Header". -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". -Axiom blocks_Receipt : - IsGlobalAlias globals blocks.globals "Receipt". - -Require bloom. -Axiom bloom_logs_bloom : - IsGlobalAlias globals bloom.globals "logs_bloom". - -Require dao. -Axiom dao_apply_dao : - IsGlobalAlias globals dao.globals "apply_dao". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". - -Require state. -Axiom state_State : - IsGlobalAlias globals state.globals "State". -Axiom state_create_ether : - IsGlobalAlias globals state.globals "create_ether". -Axiom state_destroy_account : - IsGlobalAlias globals state.globals "destroy_account". -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". -Axiom state_increment_nonce : - IsGlobalAlias globals state.globals "increment_nonce". -Axiom state_set_account_balance : - IsGlobalAlias globals state.globals "set_account_balance". -Axiom state_state_root : - IsGlobalAlias globals state.globals "state_root". - -Require transactions. -Axiom transactions_TX_BASE_COST : - IsGlobalAlias globals transactions.globals "TX_BASE_COST". -Axiom transactions_TX_CREATE_COST : - IsGlobalAlias globals transactions.globals "TX_CREATE_COST". -Axiom transactions_TX_DATA_COST_PER_NON_ZERO : - IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_NON_ZERO". -Axiom transactions_TX_DATA_COST_PER_ZERO : - IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_ZERO". -Axiom transactions_Transaction : - IsGlobalAlias globals transactions.globals "Transaction". - -Require trie. -Axiom trie_Trie : - IsGlobalAlias globals trie.globals "Trie". -Axiom trie_root : - IsGlobalAlias globals trie.globals "root". -Axiom trie_trie_set : - IsGlobalAlias globals trie.globals "trie_set". - -Require utils.message. -Axiom utils_message_prepare_message : - IsGlobalAlias globals utils.message.globals "prepare_message". - -Require vm.interpreter. -Axiom vm_interpreter_process_message_call : - IsGlobalAlias globals vm.interpreter.globals "process_message_call". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U64 : + IsGlobalAlias globals ethereum.base_types.globals "U64". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_U256_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.dao_fork.__init__. +Axiom ethereum_dao_fork___init___FORK_CRITERIA : + IsGlobalAlias globals ethereum.dao_fork.__init__.globals "FORK_CRITERIA". +Axiom ethereum_dao_fork___init___vm : + IsGlobalAlias globals ethereum.dao_fork.__init__.globals "vm". + +Require ethereum.dao_fork.blocks. +Axiom ethereum_dao_fork_blocks_Block : + IsGlobalAlias globals ethereum.dao_fork.blocks.globals "Block". +Axiom ethereum_dao_fork_blocks_Header : + IsGlobalAlias globals ethereum.dao_fork.blocks.globals "Header". +Axiom ethereum_dao_fork_blocks_Log : + IsGlobalAlias globals ethereum.dao_fork.blocks.globals "Log". +Axiom ethereum_dao_fork_blocks_Receipt : + IsGlobalAlias globals ethereum.dao_fork.blocks.globals "Receipt". + +Require ethereum.dao_fork.bloom. +Axiom ethereum_dao_fork_bloom_logs_bloom : + IsGlobalAlias globals ethereum.dao_fork.bloom.globals "logs_bloom". + +Require ethereum.dao_fork.dao. +Axiom ethereum_dao_fork_dao_apply_dao : + IsGlobalAlias globals ethereum.dao_fork.dao.globals "apply_dao". + +Require ethereum.dao_fork.fork_types. +Axiom ethereum_dao_fork_fork_types_Address : + IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "Address". +Axiom ethereum_dao_fork_fork_types_Bloom : + IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "Bloom". +Axiom ethereum_dao_fork_fork_types_Root : + IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "Root". + +Require ethereum.dao_fork.state. +Axiom ethereum_dao_fork_state_State : + IsGlobalAlias globals ethereum.dao_fork.state.globals "State". +Axiom ethereum_dao_fork_state_create_ether : + IsGlobalAlias globals ethereum.dao_fork.state.globals "create_ether". +Axiom ethereum_dao_fork_state_destroy_account : + IsGlobalAlias globals ethereum.dao_fork.state.globals "destroy_account". +Axiom ethereum_dao_fork_state_get_account : + IsGlobalAlias globals ethereum.dao_fork.state.globals "get_account". +Axiom ethereum_dao_fork_state_increment_nonce : + IsGlobalAlias globals ethereum.dao_fork.state.globals "increment_nonce". +Axiom ethereum_dao_fork_state_set_account_balance : + IsGlobalAlias globals ethereum.dao_fork.state.globals "set_account_balance". +Axiom ethereum_dao_fork_state_state_root : + IsGlobalAlias globals ethereum.dao_fork.state.globals "state_root". + +Require ethereum.dao_fork.transactions. +Axiom ethereum_dao_fork_transactions_TX_BASE_COST : + IsGlobalAlias globals ethereum.dao_fork.transactions.globals "TX_BASE_COST". +Axiom ethereum_dao_fork_transactions_TX_CREATE_COST : + IsGlobalAlias globals ethereum.dao_fork.transactions.globals "TX_CREATE_COST". +Axiom ethereum_dao_fork_transactions_TX_DATA_COST_PER_NON_ZERO : + IsGlobalAlias globals ethereum.dao_fork.transactions.globals "TX_DATA_COST_PER_NON_ZERO". +Axiom ethereum_dao_fork_transactions_TX_DATA_COST_PER_ZERO : + IsGlobalAlias globals ethereum.dao_fork.transactions.globals "TX_DATA_COST_PER_ZERO". +Axiom ethereum_dao_fork_transactions_Transaction : + IsGlobalAlias globals ethereum.dao_fork.transactions.globals "Transaction". + +Require ethereum.dao_fork.trie. +Axiom ethereum_dao_fork_trie_Trie : + IsGlobalAlias globals ethereum.dao_fork.trie.globals "Trie". +Axiom ethereum_dao_fork_trie_root : + IsGlobalAlias globals ethereum.dao_fork.trie.globals "root". +Axiom ethereum_dao_fork_trie_trie_set : + IsGlobalAlias globals ethereum.dao_fork.trie.globals "trie_set". + +Require ethereum.dao_fork.utils.message. +Axiom ethereum_dao_fork_utils_message_prepare_message : + IsGlobalAlias globals ethereum.dao_fork.utils.message.globals "prepare_message". + +Require ethereum.dao_fork.vm.interpreter. +Axiom ethereum_dao_fork_vm_interpreter_process_message_call : + IsGlobalAlias globals ethereum.dao_fork.vm.interpreter.globals "process_message_call". Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -244,6 +244,7 @@ Definition apply_fork : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "old" |) + |) in M.pure Constant.None_)). Definition get_last_256_block_hashes : Value.t -> Value.t -> M := @@ -269,8 +270,28 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := Hashes of the recent 256 blocks in order of increasing block number. " in let recent_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |) |) in + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "recent_blocks" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + make_list [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let recent_block_hashes := @@ -309,6 +330,7 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "recent_block_hashes" |) + |) in M.pure Constant.None_)). Definition state_transition : Value.t -> Value.t -> M := @@ -439,6 +461,27 @@ Definition state_transition : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |) + ], + make_dict [] + |), + Constant.int 255 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -568,6 +611,39 @@ Definition validate_header : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.gt_e (| + M.get_field (| M.get_name (| globals, "header" |), "number" |), + M.get_field (| M.get_name (| globals, "FORK_CRITERIA" |), "block_number" |) + |), + ltac:(M.monadic ( + Compare.lt (| + M.get_field (| M.get_name (| globals, "header" |), "number" |), + BinOp.add (| + M.get_field (| M.get_name (| globals, "FORK_CRITERIA" |), "block_number" |), + Constant.int 10 + |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.get_field (| M.get_name (| globals, "header" |), "extra_data" |), + Constant.bytes "64616f2d686172642d666f726b" + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -628,6 +704,7 @@ Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition validate_proof_of_work : Value.t -> Value.t -> M := @@ -759,6 +836,7 @@ Definition check_transaction : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "sender_address" |) + |) in M.pure Constant.None_)). Definition make_receipt : Value.t -> Value.t -> M := @@ -792,6 +870,7 @@ Definition make_receipt : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "receipt" |) + |) in M.pure Constant.None_)). Definition ApplyBodyOutput : Value.t := @@ -1005,6 +1084,7 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition validate_ommers : Value.t -> Value.t -> M := @@ -1057,6 +1137,26 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do @@ -1114,7 +1214,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let ommers_hashes := - (* At expr: unsupported node type: ListComp *) in + Constant.str "(* At expr: unsupported node type: ListComp *)" in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1145,19 +1245,19 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let recent_canonical_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| BinOp.add (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| BinOp.add (| M.get_name (| globals, "MAX_OMMER_DEPTH" |), Constant.int 1 - |) |) |) in + |) |), Constant.None_ |) |) in let recent_canonical_block_hashes := - (* At expr: unsupported node type: SetComp *) in + Constant.str "(* At expr: unsupported node type: SetComp *)" in (* At stmt: unsupported node type: AnnAssign *) For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_canonical_blocks" |) do let recent_ommers_hashes := M.call (| M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), make_list [ - (* At expr: unsupported node type: SetComp *) + Constant.str "(* At expr: unsupported node type: SetComp *)" ], make_dict [] |) in @@ -1591,6 +1691,7 @@ Definition process_transaction : Value.t -> Value.t -> M := EndFor. let _ := M.return_ (| make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |) ] + |) in M.pure Constant.None_)). Definition validate_transaction : Value.t -> Value.t -> M := @@ -1645,6 +1746,7 @@ Definition validate_transaction : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := @@ -1676,6 +1778,20 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := Constant.int 0 in For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "byte" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let data_cost := BinOp.add M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in @@ -1683,6 +1799,25 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := )) |) in EndFor. let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "tx" |), "to" |), + M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) + |), + (* then *) + ltac:(M.monadic ( + let create_cost := + M.get_name (| globals, "TX_CREATE_COST" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let create_cost := Constant.int 0 in M.pure Constant.None_ @@ -1701,6 +1836,7 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition recover_sender : Value.t -> Value.t -> M := @@ -1819,10 +1955,11 @@ Definition recover_sender : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12 |) + |), M.slice (| Constant.int 12, Constant.int 32 |) |) ], make_dict [] |) + |) in M.pure Constant.None_)). Definition signing_hash : Value.t -> Value.t -> M := @@ -1859,6 +1996,7 @@ Definition signing_hash : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition compute_header_hash : Value.t -> Value.t -> M := @@ -1909,6 +2047,7 @@ Definition compute_header_hash : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition check_gas_limit : Value.t -> Value.t -> M := @@ -1947,16 +2086,65 @@ Definition check_gas_limit : Value.t -> Value.t -> M := M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "gas_limit" |), + BinOp.add (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "gas_limit" |), + BinOp.sub (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "gas_limit" |), + M.get_name (| globals, "GAS_LIMIT_MINIMUM" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| Constant.bool true + |) in M.pure Constant.None_)). Definition calculate_block_difficulty : Value.t -> Value.t -> M := @@ -2060,6 +2248,26 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := Constant.int 2 |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "num_bomb_periods" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let difficulty := BinOp.add + BinOp.pow (| + Constant.int 2, + M.get_name (| globals, "num_bomb_periods" |) + |) + BinOp.pow (| + Constant.int 2, + M.get_name (| globals, "num_bomb_periods" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -2077,4 +2285,5 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/fork_types.v b/CoqOfPython/ethereum/dao_fork/fork_types.v index 5c7dac3..cc8e4a1 100644 --- a/CoqOfPython/ethereum/dao_fork/fork_types.v +++ b/CoqOfPython/ethereum/dao_fork/fork_types.v @@ -21,29 +21,29 @@ Require dataclasses. Axiom dataclasses_dataclass : IsGlobalAlias globals dataclasses.globals "dataclass". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes20 : - IsGlobalAlias globals base_types.globals "Bytes20". -Axiom base_types_Bytes256 : - IsGlobalAlias globals base_types.globals "Bytes256". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require crypto.hash. -Axiom crypto_hash_Hash32 : - IsGlobalAlias globals crypto.hash.globals "Hash32". -Axiom crypto_hash_keccak256 : - IsGlobalAlias globals crypto.hash.globals "keccak256". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes20 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes20". +Axiom ethereum_base_types_Bytes256 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) @@ -98,4 +98,5 @@ Definition encode_account : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/state.v b/CoqOfPython/ethereum/dao_fork/state.v index 2ba095e..efaf955 100644 --- a/CoqOfPython/ethereum/dao_fork/state.v +++ b/CoqOfPython/ethereum/dao_fork/state.v @@ -54,29 +54,29 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require fork_types. -Axiom fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". -Axiom fork_types_Account : - IsGlobalAlias globals fork_types.globals "Account". -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". - -Require trie. -Axiom trie_EMPTY_TRIE_ROOT : - IsGlobalAlias globals trie.globals "EMPTY_TRIE_ROOT". -Axiom trie_Trie : - IsGlobalAlias globals trie.globals "Trie". -Axiom trie_copy_trie : - IsGlobalAlias globals trie.globals "copy_trie". -Axiom trie_root : - IsGlobalAlias globals trie.globals "root". -Axiom trie_trie_get : - IsGlobalAlias globals trie.globals "trie_get". -Axiom trie_trie_set : - IsGlobalAlias globals trie.globals "trie_set". +Require ethereum.dao_fork.fork_types. +Axiom ethereum_dao_fork_fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "EMPTY_ACCOUNT". +Axiom ethereum_dao_fork_fork_types_Account : + IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "Account". +Axiom ethereum_dao_fork_fork_types_Address : + IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "Address". +Axiom ethereum_dao_fork_fork_types_Root : + IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "Root". + +Require ethereum.dao_fork.trie. +Axiom ethereum_dao_fork_trie_EMPTY_TRIE_ROOT : + IsGlobalAlias globals ethereum.dao_fork.trie.globals "EMPTY_TRIE_ROOT". +Axiom ethereum_dao_fork_trie_Trie : + IsGlobalAlias globals ethereum.dao_fork.trie.globals "Trie". +Axiom ethereum_dao_fork_trie_copy_trie : + IsGlobalAlias globals ethereum.dao_fork.trie.globals "copy_trie". +Axiom ethereum_dao_fork_trie_root : + IsGlobalAlias globals ethereum.dao_fork.trie.globals "root". +Axiom ethereum_dao_fork_trie_trie_get : + IsGlobalAlias globals ethereum.dao_fork.trie.globals "trie_get". +Axiom ethereum_dao_fork_trie_trie_set : + IsGlobalAlias globals ethereum.dao_fork.trie.globals "trie_set". Definition State : Value.t := builtins.make_klass @@ -123,7 +123,7 @@ Definition begin_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) ], make_dict [] - |); (* At expr: unsupported node type: DictComp *) ] + |); Constant.str "(* At expr: unsupported node type: DictComp *)" ] ], make_dict [] |) in @@ -201,8 +201,27 @@ Definition get_account : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "account" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "account" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_ACCOUNT" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -237,6 +256,7 @@ Definition get_account_optional : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "account" |) + |) in M.pure Constant.None_)). Definition set_account : Value.t -> Value.t -> M := @@ -316,6 +336,18 @@ Definition destroy_storage : Value.t -> Value.t -> M := Address of account whose storage is to be deleted. " in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -350,6 +382,26 @@ Definition get_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "trie" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let value := @@ -371,6 +423,7 @@ Definition get_storage : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "value" |) + |) in M.pure Constant.None_)). Definition set_storage : Value.t -> Value.t -> M := @@ -411,6 +464,27 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "trie" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let trie := + M.call (| + M.get_name (| globals, "Trie" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), + M.get_name (| globals, "trie" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -423,6 +497,18 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + {} + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -447,8 +533,29 @@ Definition storage_root : Value.t -> Value.t -> M := " in let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_TRIE_ROOT" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -479,6 +586,7 @@ Definition state_root : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition account_exists : Value.t -> Value.t -> M := @@ -511,6 +619,7 @@ Definition account_exists : Value.t -> Value.t -> M := |), Constant.None_ |) + |) in M.pure Constant.None_)). Definition account_has_code_or_nonce : Value.t -> Value.t -> M := @@ -560,6 +669,7 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition modify_state : Value.t -> Value.t -> M := @@ -665,6 +775,30 @@ Definition touch_account : Value.t -> Value.t -> M := The address of the account that need to initialised. " in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "account_exists" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "EMPTY_ACCOUNT" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/transactions.v b/CoqOfPython/ethereum/dao_fork/transactions.v index 6d1bc6b..25df68a 100644 --- a/CoqOfPython/ethereum/dao_fork/transactions.v +++ b/CoqOfPython/ethereum/dao_fork/transactions.v @@ -17,21 +17,21 @@ Require typing. Axiom typing_Union : IsGlobalAlias globals typing.globals "Union". -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes0 : - IsGlobalAlias globals base_types.globals "Bytes0". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.dao_fork.fork_types. +Axiom ethereum_dao_fork_fork_types_Address : + IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "Address". Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( Constant.int 21000 diff --git a/CoqOfPython/ethereum/dao_fork/trie.v b/CoqOfPython/ethereum/dao_fork/trie.v index c119364..0755f51 100644 --- a/CoqOfPython/ethereum/dao_fork/trie.v +++ b/CoqOfPython/ethereum/dao_fork/trie.v @@ -54,9 +54,9 @@ Require ethereum.crypto.hash. Axiom ethereum_crypto_hash_keccak256 : IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". -Require ethereum.homestead. -Axiom ethereum_homestead_trie : - IsGlobalAlias globals ethereum.homestead.globals "trie". +Require ethereum.homestead.__init__. +Axiom ethereum_homestead___init___trie : + IsGlobalAlias globals ethereum.homestead.__init__.globals "trie". Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : @@ -66,37 +66,37 @@ Require ethereum.utils.hexadecimal. Axiom ethereum_utils_hexadecimal_hex_to_bytes : IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require blocks. -Axiom blocks_Receipt : - IsGlobalAlias globals blocks.globals "Receipt". - -Require fork_types. -Axiom fork_types_Account : - IsGlobalAlias globals fork_types.globals "Account". -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". -Axiom fork_types_encode_account : - IsGlobalAlias globals fork_types.globals "encode_account". - -Require transactions. -Axiom transactions_Transaction : - IsGlobalAlias globals transactions.globals "Transaction". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.dao_fork.blocks. +Axiom ethereum_dao_fork_blocks_Receipt : + IsGlobalAlias globals ethereum.dao_fork.blocks.globals "Receipt". + +Require ethereum.dao_fork.fork_types. +Axiom ethereum_dao_fork_fork_types_Account : + IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "Account". +Axiom ethereum_dao_fork_fork_types_Address : + IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "Address". +Axiom ethereum_dao_fork_fork_types_Root : + IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "Root". +Axiom ethereum_dao_fork_fork_types_encode_account : + IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "encode_account". + +Require ethereum.dao_fork.transactions. +Axiom ethereum_dao_fork_transactions_Transaction : + IsGlobalAlias globals ethereum.dao_fork.transactions.globals "Transaction". Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -202,16 +202,99 @@ Definition encode_internal_node : Value.t -> Value.t -> M := " in (* At stmt: unsupported node type: AnnAssign *) let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "node" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + Constant.bytes "" in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "LeafNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "rest_of_key" |); + Constant.bool true + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "ExtensionNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "key_segment" |); + Constant.bool false + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "BranchNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + BinOp.add (| + M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "value" |) + ] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ - (* At expr: unsupported node type: JoinedStr *) + Constant.str "(* At expr: unsupported node type: JoinedStr *)" ], make_dict [] - |)) + |)) |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -229,6 +312,26 @@ Definition encode_internal_node : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded" |) + ], + make_dict [] + |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "unencoded" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_name (| globals, "keccak256" |), @@ -237,6 +340,7 @@ Definition encode_internal_node : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -250,8 +354,86 @@ Definition encode_node : Value.t -> Value.t -> M := Currently mostly an unimplemented stub. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| + M.get_name (| globals, "storage_root" |), + Constant.None_ + |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "encode_account" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "storage_root" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + make_tuple [ M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "U256" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "cast" |), + make_list [ + M.get_field (| M.get_name (| globals, "rlp" |), "RLP" |); + M.get_name (| globals, "node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "node" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "previous_trie" |), "encode_node" |), @@ -261,6 +443,7 @@ Definition encode_node : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -312,6 +495,7 @@ Definition copy_trie : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition trie_set : Value.t -> Value.t -> M := @@ -333,6 +517,32 @@ Definition trie_set : Value.t -> Value.t -> M := Node to insert at `key`. " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + M.get_field (| M.get_name (| globals, "trie" |), "default" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "key" |), + M.get_field (| M.get_name (| globals, "trie" |), "_data" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), M.get_name (| globals, "value" |) @@ -370,6 +580,7 @@ Definition trie_get : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition common_prefix_length : Value.t -> Value.t -> M := @@ -392,6 +603,34 @@ Definition common_prefix_length : Value.t -> Value.t -> M := make_dict [] |) do let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), + M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -403,6 +642,7 @@ Definition common_prefix_length : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition nibble_list_to_compact : Value.t -> Value.t -> M := @@ -448,6 +688,71 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + Constant.int 2 + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.mult (| + Constant.int 16, + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "is_leaf" |) + |) + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ @@ -509,6 +814,7 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition bytes_to_nibble_list : Value.t -> Value.t -> M := @@ -586,6 +892,7 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition _prepare_trie : Value.t -> Value.t -> M := @@ -615,6 +922,48 @@ Definition _prepare_trie : Value.t -> Value.t -> M := make_dict [] |) do let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| + M.get_name (| globals, "get_storage_root" |), + Constant.None_ + |) |) in + let address := + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |); + M.call (| + M.get_name (| globals, "get_storage_root" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let encoded_value := M.call (| M.get_name (| globals, "encode_node" |), @@ -638,6 +987,22 @@ Definition _prepare_trie : Value.t -> Value.t -> M := |) in (* At stmt: unsupported node type: AnnAssign *) let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "trie" |), "secured" |), + (* then *) + ltac:(M.monadic ( + let key := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let key := M.get_name (| globals, "preimage" |) in M.pure Constant.None_ @@ -655,6 +1020,7 @@ Definition _prepare_trie : Value.t -> Value.t -> M := EndFor. let _ := M.return_ (| M.get_name (| globals, "mapped" |) + |) in M.pure Constant.None_)). Definition root : Value.t -> Value.t -> M := @@ -708,6 +1074,44 @@ Definition root : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -724,6 +1128,7 @@ Definition root : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -750,6 +1155,26 @@ Definition patricialize : Value.t -> Value.t -> M := Root node of `obj`. " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let arbitrary_key := @@ -767,10 +1192,39 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), + Constant.int 1 + |), + (* then *) + ltac:(M.monadic ( + let leaf := + M.call (| + M.get_name (| globals, "LeafNode" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |); + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "leaf" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let substring := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |) |) in + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) in let prefix_length := M.call (| M.get_name (| globals, "len" |), @@ -789,7 +1243,7 @@ Definition patricialize : Value.t -> Value.t -> M := M.get_name (| globals, "common_prefix_length" |), make_list [ M.get_name (| globals, "substring" |); - M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) + M.get_subscript (| M.get_name (| globals, "key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) ], make_dict [] |) @@ -797,10 +1251,64 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "prefix_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "prefix_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let prefix := + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ExtensionNode" |), + make_list [ + M.get_name (| globals, "prefix" |); + M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_name (| globals, "obj" |); + BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) @@ -823,6 +1331,44 @@ Definition patricialize : Value.t -> Value.t -> M := Constant.bytes "" in For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |), + M.get_name (| globals, "level" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "AssertionError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) @@ -834,9 +1380,10 @@ Definition patricialize : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "BranchNode" |), make_list [ - (* At expr: unsupported node type: ListComp *); + Constant.str "(* At expr: unsupported node type: ListComp *)"; M.get_name (| globals, "value" |) ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/utils/address.v b/CoqOfPython/ethereum/dao_fork/utils/address.v index 03d5181..5cb49df 100644 --- a/CoqOfPython/ethereum/dao_fork/utils/address.v +++ b/CoqOfPython/ethereum/dao_fork/utils/address.v @@ -35,13 +35,13 @@ Require ethereum.utils.byte. Axiom ethereum_utils_byte_left_pad_zero_bytes : IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.dao_fork.fork_types. +Axiom ethereum_dao_fork_fork_types_Address : + IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "Address". Definition to_address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -67,10 +67,11 @@ Definition to_address : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), make_list [], make_dict [] - |), UnOp.sub (| Constant.int 20 |) |) + |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) ], make_dict [] |) + |) in M.pure Constant.None_)). Definition compute_contract_address : Value.t -> Value.t -> M := @@ -110,7 +111,7 @@ Definition compute_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -128,4 +129,5 @@ Definition compute_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/utils/hexadecimal.v b/CoqOfPython/ethereum/dao_fork/utils/hexadecimal.v index 1a063da..df224a7 100644 --- a/CoqOfPython/ethereum/dao_fork/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/dao_fork/utils/hexadecimal.v @@ -22,13 +22,13 @@ Require ethereum.utils.hexadecimal. Axiom ethereum_utils_hexadecimal_remove_hex_prefix : IsGlobalAlias globals ethereum.utils.hexadecimal.globals "remove_hex_prefix". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". +Require ethereum.dao_fork.fork_types. +Axiom ethereum_dao_fork_fork_types_Address : + IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "Address". +Axiom ethereum_dao_fork_fork_types_Bloom : + IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "Bloom". +Axiom ethereum_dao_fork_fork_types_Root : + IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "Root". Definition hex_to_root : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -66,6 +66,7 @@ Definition hex_to_root : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition hex_to_bloom : Value.t -> Value.t -> M := @@ -104,6 +105,7 @@ Definition hex_to_bloom : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition hex_to_address : Value.t -> Value.t -> M := @@ -149,4 +151,5 @@ Definition hex_to_address : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/utils/message.v b/CoqOfPython/ethereum/dao_fork/utils/message.v index bee1e25..759d611 100644 --- a/CoqOfPython/ethereum/dao_fork/utils/message.v +++ b/CoqOfPython/ethereum/dao_fork/utils/message.v @@ -33,23 +33,23 @@ Axiom ethereum_base_types_Bytes0 : Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.dao_fork.fork_types. +Axiom ethereum_dao_fork_fork_types_Address : + IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "Address". -Require state. -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". +Require ethereum.dao_fork.state. +Axiom ethereum_dao_fork_state_get_account : + IsGlobalAlias globals ethereum.dao_fork.state.globals "get_account". -Require vm. -Axiom vm_Environment : - IsGlobalAlias globals vm.globals "Environment". -Axiom vm_Message : - IsGlobalAlias globals vm.globals "Message". +Require ethereum.dao_fork.vm.__init__. +Axiom ethereum_dao_fork_vm___init___Environment : + IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "Environment". +Axiom ethereum_dao_fork_vm___init___Message : + IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "Message". -Require address. -Axiom address_compute_contract_address : - IsGlobalAlias globals address.globals "compute_contract_address". +Require ethereum.dao_fork.utils.address. +Axiom ethereum_dao_fork_utils_address_compute_contract_address : + IsGlobalAlias globals ethereum.dao_fork.utils.address.globals "compute_contract_address". Definition prepare_message : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -84,14 +84,108 @@ Definition prepare_message : Value.t -> Value.t -> M := Items containing contract creation or message call specific data. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Bytes0" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.call (| + M.get_name (| globals, "compute_contract_address" |), + make_list [ + M.get_name (| globals, "caller" |); + BinOp.sub (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "caller" |) + ], + make_dict [] + |), "nonce" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let msg_data := + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) in + let code := + M.get_name (| globals, "data" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.get_name (| globals, "target" |) in + let msg_data := + M.get_name (| globals, "data" |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "target" |) + ], + make_dict [] + |), "code" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "code_address" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let code_address := + M.get_name (| globals, "target" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "Target must be address or empty bytes" ], make_dict [] - |)) + |)) |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -102,4 +196,5 @@ Definition prepare_message : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/vm/__init__.v b/CoqOfPython/ethereum/dao_fork/vm/__init__.v index 4a6d18f..1b240a8 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/__init__.v +++ b/CoqOfPython/ethereum/dao_fork/vm/__init__.v @@ -48,17 +48,17 @@ Require ethereum.crypto.hash. Axiom ethereum_crypto_hash_Hash32 : IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". +Require ethereum.dao_fork.blocks. +Axiom ethereum_dao_fork_blocks_Log : + IsGlobalAlias globals ethereum.dao_fork.blocks.globals "Log". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.dao_fork.fork_types. +Axiom ethereum_dao_fork_fork_types_Address : + IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "Address". -Require state. -Axiom state_State : - IsGlobalAlias globals state.globals "State". +Require ethereum.dao_fork.state. +Axiom ethereum_dao_fork_state_State : + IsGlobalAlias globals ethereum.dao_fork.state.globals "State". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] diff --git a/CoqOfPython/ethereum/dao_fork/vm/gas.v b/CoqOfPython/ethereum/dao_fork/vm/gas.v index eef500a..62ff7dc 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/gas.v +++ b/CoqOfPython/ethereum/dao_fork/vm/gas.v @@ -43,23 +43,23 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.dao_fork.fork_types. +Axiom ethereum_dao_fork_fork_types_Address : + IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "Address". -Require state. -Axiom state_State : - IsGlobalAlias globals state.globals "State". -Axiom state_account_exists : - IsGlobalAlias globals state.globals "account_exists". +Require ethereum.dao_fork.state. +Axiom ethereum_dao_fork_state_State : + IsGlobalAlias globals ethereum.dao_fork.state.globals "State". +Axiom ethereum_dao_fork_state_account_exists : + IsGlobalAlias globals ethereum.dao_fork.state.globals "account_exists". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.dao_fork.vm.__init__. +Axiom ethereum_dao_fork_vm___init___Evm : + IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "Evm". -Require exceptions. -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". +Require ethereum.dao_fork.vm.exceptions. +Axiom ethereum_dao_fork_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.dao_fork.vm.exceptions.globals "OutOfGasError". Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -480,6 +480,18 @@ Definition charge_gas : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "amount" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign_op (| BinOp.sub, M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), @@ -595,6 +607,18 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := |) in For make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ] in M.get_name (| globals, "extensions" |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "size" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let before_size := @@ -629,6 +653,18 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let size_to_extend := BinOp.add @@ -677,6 +713,7 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition calculate_message_call_gas : Value.t -> Value.t -> M := @@ -701,41 +738,49 @@ Definition calculate_message_call_gas : Value.t -> Value.t -> M := message_call_gas: `MessageCallGas` " in let create_gas_cost := - (* if *) -M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "to" |) - ], - make_dict [] - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "to" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "GAS_NEW_ACCOUNT" |) + )) |) in let transfer_gas_cost := - (* if *) -M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "GAS_CALL_VALUE" |) + )) |) in let cost := BinOp.add (| BinOp.add (| @@ -748,15 +793,22 @@ M.call (| M.get_name (| globals, "transfer_gas_cost" |) |) in let stipend := - (* if *) -M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), -(* then *) -ltac:(M.monadic ( -M.get_name (| globals, "gas" |) in + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( +M.get_name (| globals, "gas" |) + (* else *) + )), ltac:(M.monadic ( +BinOp.add (| + M.get_name (| globals, "GAS_CALL_STIPEND" |), + M.get_name (| globals, "gas" |) + |) + )) |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "MessageCallGas" |), @@ -766,4 +818,5 @@ M.get_name (| globals, "gas" |) in ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/__init__.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/__init__.v index e5bebd7..08d558b 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/__init__.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/__init__.v @@ -26,53 +26,53 @@ Axiom typing_Callable : Axiom typing_Dict : IsGlobalAlias globals typing.globals "Dict". -Require __init__. -Axiom __init___arithmetic : - IsGlobalAlias globals __init__.globals "arithmetic". +Require ethereum.dao_fork.vm.instructions.__init__. +Axiom ethereum_dao_fork_vm_instructions___init___arithmetic : + IsGlobalAlias globals ethereum.dao_fork.vm.instructions.__init__.globals "arithmetic". -Require __init__. -Axiom __init___bitwise : - IsGlobalAlias globals __init__.globals "bitwise". +Require ethereum.dao_fork.vm.instructions.__init__. +Axiom ethereum_dao_fork_vm_instructions___init___bitwise : + IsGlobalAlias globals ethereum.dao_fork.vm.instructions.__init__.globals "bitwise". -Require __init__. -Axiom __init___block : - IsGlobalAlias globals __init__.globals "block". +Require ethereum.dao_fork.vm.instructions.__init__. +Axiom ethereum_dao_fork_vm_instructions___init___block : + IsGlobalAlias globals ethereum.dao_fork.vm.instructions.__init__.globals "block". -Require __init__. -Axiom __init___comparison : - IsGlobalAlias globals __init__.globals "comparison". +Require ethereum.dao_fork.vm.instructions.__init__. +Axiom ethereum_dao_fork_vm_instructions___init___comparison : + IsGlobalAlias globals ethereum.dao_fork.vm.instructions.__init__.globals "comparison". -Require __init__. -Axiom __init___control_flow : - IsGlobalAlias globals __init__.globals "control_flow". +Require ethereum.dao_fork.vm.instructions.__init__. +Axiom ethereum_dao_fork_vm_instructions___init___control_flow : + IsGlobalAlias globals ethereum.dao_fork.vm.instructions.__init__.globals "control_flow". -Require __init__. -Axiom __init___environment : - IsGlobalAlias globals __init__.globals "environment". +Require ethereum.dao_fork.vm.instructions.__init__. +Axiom ethereum_dao_fork_vm_instructions___init___environment : + IsGlobalAlias globals ethereum.dao_fork.vm.instructions.__init__.globals "environment". -Require __init__. -Axiom __init___keccak : - IsGlobalAlias globals __init__.globals "keccak". +Require ethereum.dao_fork.vm.instructions.__init__. +Axiom ethereum_dao_fork_vm_instructions___init___keccak : + IsGlobalAlias globals ethereum.dao_fork.vm.instructions.__init__.globals "keccak". -Require __init__. -Axiom __init___log : - IsGlobalAlias globals __init__.globals "log". +Require ethereum.dao_fork.vm.instructions.__init__. +Axiom ethereum_dao_fork_vm_instructions___init___log : + IsGlobalAlias globals ethereum.dao_fork.vm.instructions.__init__.globals "log". -Require __init__. -Axiom __init___memory : - IsGlobalAlias globals __init__.globals "memory". +Require ethereum.dao_fork.vm.instructions.__init__. +Axiom ethereum_dao_fork_vm_instructions___init___memory : + IsGlobalAlias globals ethereum.dao_fork.vm.instructions.__init__.globals "memory". -Require __init__. -Axiom __init___stack : - IsGlobalAlias globals __init__.globals "stack". +Require ethereum.dao_fork.vm.instructions.__init__. +Axiom ethereum_dao_fork_vm_instructions___init___stack : + IsGlobalAlias globals ethereum.dao_fork.vm.instructions.__init__.globals "stack". -Require __init__. -Axiom __init___storage : - IsGlobalAlias globals __init__.globals "storage". +Require ethereum.dao_fork.vm.instructions.__init__. +Axiom ethereum_dao_fork_vm_instructions___init___storage : + IsGlobalAlias globals ethereum.dao_fork.vm.instructions.__init__.globals "storage". -Require __init__. -Axiom __init___system : - IsGlobalAlias globals __init__.globals "system". +Require ethereum.dao_fork.vm.instructions.__init__. +Axiom ethereum_dao_fork_vm_instructions___init___system : + IsGlobalAlias globals ethereum.dao_fork.vm.instructions.__init__.globals "system". Definition Ops : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/arithmetic.v index 581ba5d..2decdb1 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/arithmetic.v @@ -31,29 +31,29 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_get_sign : IsGlobalAlias globals ethereum.utils.numeric.globals "get_sign". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_EXPONENTIATION : - IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION". -Axiom gas_GAS_EXPONENTIATION_PER_BYTE : - IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION_PER_BYTE". -Axiom gas_GAS_LOW : - IsGlobalAlias globals gas.globals "GAS_LOW". -Axiom gas_GAS_MID : - IsGlobalAlias globals gas.globals "GAS_MID". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.dao_fork.vm.__init__. +Axiom ethereum_dao_fork_vm___init___Evm : + IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "Evm". + +Require ethereum.dao_fork.vm.gas. +Axiom ethereum_dao_fork_vm_gas_GAS_EXPONENTIATION : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_EXPONENTIATION". +Axiom ethereum_dao_fork_vm_gas_GAS_EXPONENTIATION_PER_BYTE : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_EXPONENTIATION_PER_BYTE". +Axiom ethereum_dao_fork_vm_gas_GAS_LOW : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_LOW". +Axiom ethereum_dao_fork_vm_gas_GAS_MID : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_MID". +Axiom ethereum_dao_fork_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_dao_fork_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "charge_gas". + +Require ethereum.dao_fork.vm.stack. +Axiom ethereum_dao_fork_vm_stack_pop : + IsGlobalAlias globals ethereum.dao_fork.vm.stack.globals "pop". +Axiom ethereum_dao_fork_vm_stack_push : + IsGlobalAlias globals ethereum.dao_fork.vm.stack.globals "push". Definition add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -273,6 +273,25 @@ Definition div : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "divisor" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let quotient := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let quotient := BinOp.floor_div (| M.get_name (| globals, "dividend" |), @@ -341,7 +360,41 @@ Definition sdiv : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "divisor" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let quotient := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_name (| globals, "dividend" |), + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "divisor" |), + UnOp.sub (| Constant.int 1 |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let quotient := + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let sign := M.call (| M.get_name (| globals, "get_sign" |), @@ -436,6 +489,25 @@ Definition mod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "y" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let remainder := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let remainder := BinOp.mod_ (| M.get_name (| globals, "x" |), @@ -504,6 +576,19 @@ Definition smod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "y" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let remainder := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let remainder := BinOp.mult (| M.call (| @@ -617,6 +702,25 @@ Definition addmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "z" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -712,6 +816,25 @@ Definition mulmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "z" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -881,6 +1004,19 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "byte_num" |), + Constant.int 31 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.get_name (| globals, "value" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let value_bytes := M.call (| M.get_name (| globals, "bytes" |), @@ -894,7 +1030,7 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let value_bytes := - M.get_subscript (| M.get_name (| globals, "value_bytes" |), BinOp.sub (| + M.get_subscript (| M.get_name (| globals, "value_bytes" |), M.slice (| BinOp.sub (| Constant.int 31, M.call (| M.get_name (| globals, "int" |), @@ -903,13 +1039,32 @@ Definition signextend : Value.t -> Value.t -> M := ], make_dict [] |) - |) |) in + |), Constant.None_ |) |) in let sign_bit := BinOp.r_shift (| M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), Constant.int 7 |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "sign_bit" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "value_bytes" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let num_bytes_prepend := BinOp.sub (| Constant.int 32, diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/bitwise.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/bitwise.v index f38e7aa..1f50216 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/bitwise.v @@ -21,21 +21,21 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.dao_fork.vm.__init__. +Axiom ethereum_dao_fork_vm___init___Evm : + IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.dao_fork.vm.gas. +Axiom ethereum_dao_fork_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_dao_fork_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "charge_gas". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.dao_fork.vm.stack. +Axiom ethereum_dao_fork_vm_stack_pop : + IsGlobalAlias globals ethereum.dao_fork.vm.stack.globals "pop". +Axiom ethereum_dao_fork_vm_stack_push : + IsGlobalAlias globals ethereum.dao_fork.vm.stack.globals "push". Definition bitwise_and : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -285,6 +285,25 @@ Definition get_byte : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "byte_index" |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let extra_bytes_to_right := BinOp.sub (| Constant.int 31, diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/block.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/block.v index 90be45c..2a83909 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/block.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/block.v @@ -21,23 +21,23 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_BLOCK_HASH : - IsGlobalAlias globals gas.globals "GAS_BLOCK_HASH". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.dao_fork.vm.__init__. +Axiom ethereum_dao_fork_vm___init___Evm : + IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "Evm". + +Require ethereum.dao_fork.vm.gas. +Axiom ethereum_dao_fork_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_BASE". +Axiom ethereum_dao_fork_vm_gas_GAS_BLOCK_HASH : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_BLOCK_HASH". +Axiom ethereum_dao_fork_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "charge_gas". + +Require ethereum.dao_fork.vm.stack. +Axiom ethereum_dao_fork_vm_stack_pop : + IsGlobalAlias globals ethereum.dao_fork.vm.stack.globals "pop". +Axiom ethereum_dao_fork_vm_stack_push : + IsGlobalAlias globals ethereum.dao_fork.vm.stack.globals "push". Definition block_hash : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -69,6 +69,30 @@ Definition block_hash : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt_e (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + M.get_name (| globals, "block_number" |) + |), + ltac:(M.monadic ( + Compare.gt (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + BinOp.add (| + M.get_name (| globals, "block_number" |), + Constant.int 256 + |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let hash := + Constant.bytes "00" in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let hash := M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/comparison.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/comparison.v index b8529d8..a81fe64 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/comparison.v @@ -21,21 +21,21 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.dao_fork.vm.__init__. +Axiom ethereum_dao_fork_vm___init___Evm : + IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.dao_fork.vm.gas. +Axiom ethereum_dao_fork_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_dao_fork_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "charge_gas". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.dao_fork.vm.stack. +Axiom ethereum_dao_fork_vm_stack_pop : + IsGlobalAlias globals ethereum.dao_fork.vm.stack.globals "pop". +Axiom ethereum_dao_fork_vm_stack_push : + IsGlobalAlias globals ethereum.dao_fork.vm.stack.globals "push". Definition less_than : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/control_flow.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/control_flow.v index d4e4eae..598db3e 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/control_flow.v @@ -23,31 +23,31 @@ Axiom ethereum_base_types_U256 : Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require vm.gas. -Axiom vm_gas_GAS_BASE : - IsGlobalAlias globals vm.gas.globals "GAS_BASE". -Axiom vm_gas_GAS_HIGH : - IsGlobalAlias globals vm.gas.globals "GAS_HIGH". -Axiom vm_gas_GAS_JUMPDEST : - IsGlobalAlias globals vm.gas.globals "GAS_JUMPDEST". -Axiom vm_gas_GAS_MID : - IsGlobalAlias globals vm.gas.globals "GAS_MID". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.dao_fork.vm.gas. +Axiom ethereum_dao_fork_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_BASE". +Axiom ethereum_dao_fork_vm_gas_GAS_HIGH : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_HIGH". +Axiom ethereum_dao_fork_vm_gas_GAS_JUMPDEST : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_JUMPDEST". +Axiom ethereum_dao_fork_vm_gas_GAS_MID : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_MID". +Axiom ethereum_dao_fork_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "charge_gas". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.dao_fork.vm.__init__. +Axiom ethereum_dao_fork_vm___init___Evm : + IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "Evm". -Require exceptions. -Axiom exceptions_InvalidJumpDestError : - IsGlobalAlias globals exceptions.globals "InvalidJumpDestError". +Require ethereum.dao_fork.vm.exceptions. +Axiom ethereum_dao_fork_vm_exceptions_InvalidJumpDestError : + IsGlobalAlias globals ethereum.dao_fork.vm.exceptions.globals "InvalidJumpDestError". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.dao_fork.vm.stack. +Axiom ethereum_dao_fork_vm_stack_pop : + IsGlobalAlias globals ethereum.dao_fork.vm.stack.globals "pop". +Axiom ethereum_dao_fork_vm_stack_push : + IsGlobalAlias globals ethereum.dao_fork.vm.stack.globals "push". Definition stop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -109,6 +109,18 @@ Definition jump : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "jump_dest" |), + M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -168,7 +180,35 @@ Definition jumpi : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "conditional_value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let destination := + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "jump_dest" |), + M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let destination := M.get_name (| globals, "jump_dest" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/environment.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/environment.v index 366e59a..f6aad83 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/environment.v @@ -27,45 +27,45 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require state. -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". - -Require utils.address. -Axiom utils_address_to_address : - IsGlobalAlias globals utils.address.globals "to_address". - -Require vm.memory. -Axiom vm_memory_buffer_read : - IsGlobalAlias globals vm.memory.globals "buffer_read". -Axiom vm_memory_memory_write : - IsGlobalAlias globals vm.memory.globals "memory_write". - -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_BALANCE : - IsGlobalAlias globals gas.globals "GAS_BALANCE". -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_COPY : - IsGlobalAlias globals gas.globals "GAS_COPY". -Axiom gas_GAS_EXTERNAL : - IsGlobalAlias globals gas.globals "GAS_EXTERNAL". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.dao_fork.state. +Axiom ethereum_dao_fork_state_get_account : + IsGlobalAlias globals ethereum.dao_fork.state.globals "get_account". + +Require ethereum.dao_fork.utils.address. +Axiom ethereum_dao_fork_utils_address_to_address : + IsGlobalAlias globals ethereum.dao_fork.utils.address.globals "to_address". + +Require ethereum.dao_fork.vm.memory. +Axiom ethereum_dao_fork_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.dao_fork.vm.memory.globals "buffer_read". +Axiom ethereum_dao_fork_vm_memory_memory_write : + IsGlobalAlias globals ethereum.dao_fork.vm.memory.globals "memory_write". + +Require ethereum.dao_fork.vm.__init__. +Axiom ethereum_dao_fork_vm___init___Evm : + IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "Evm". + +Require ethereum.dao_fork.vm.gas. +Axiom ethereum_dao_fork_vm_gas_GAS_BALANCE : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_BALANCE". +Axiom ethereum_dao_fork_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_BASE". +Axiom ethereum_dao_fork_vm_gas_GAS_COPY : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_COPY". +Axiom ethereum_dao_fork_vm_gas_GAS_EXTERNAL : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_EXTERNAL". +Axiom ethereum_dao_fork_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_dao_fork_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_dao_fork_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "charge_gas". + +Require ethereum.dao_fork.vm.stack. +Axiom ethereum_dao_fork_vm_stack_pop : + IsGlobalAlias globals ethereum.dao_fork.vm.stack.globals "pop". +Axiom ethereum_dao_fork_vm_stack_push : + IsGlobalAlias globals ethereum.dao_fork.vm.stack.globals "push". Definition address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/keccak.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/keccak.v index 2c4b10e..7653850 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/keccak.v @@ -31,29 +31,29 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_KECCAK256 : - IsGlobalAlias globals gas.globals "GAS_KECCAK256". -Axiom gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.dao_fork.vm.__init__. +Axiom ethereum_dao_fork_vm___init___Evm : + IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "Evm". + +Require ethereum.dao_fork.vm.gas. +Axiom ethereum_dao_fork_vm_gas_GAS_KECCAK256 : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_KECCAK256". +Axiom ethereum_dao_fork_vm_gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_KECCAK256_WORD". +Axiom ethereum_dao_fork_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_dao_fork_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "charge_gas". + +Require ethereum.dao_fork.vm.memory. +Axiom ethereum_dao_fork_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.dao_fork.vm.memory.globals "memory_read_bytes". + +Require ethereum.dao_fork.vm.stack. +Axiom ethereum_dao_fork_vm_stack_pop : + IsGlobalAlias globals ethereum.dao_fork.vm.stack.globals "pop". +Axiom ethereum_dao_fork_vm_stack_push : + IsGlobalAlias globals ethereum.dao_fork.vm.stack.globals "push". Definition keccak : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/log.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/log.v index ab196bc..a148c90 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/log.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/log.v @@ -25,33 +25,33 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". - -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_LOG : - IsGlobalAlias globals gas.globals "GAS_LOG". -Axiom gas_GAS_LOG_DATA : - IsGlobalAlias globals gas.globals "GAS_LOG_DATA". -Axiom gas_GAS_LOG_TOPIC : - IsGlobalAlias globals gas.globals "GAS_LOG_TOPIC". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". +Require ethereum.dao_fork.blocks. +Axiom ethereum_dao_fork_blocks_Log : + IsGlobalAlias globals ethereum.dao_fork.blocks.globals "Log". + +Require ethereum.dao_fork.vm.__init__. +Axiom ethereum_dao_fork_vm___init___Evm : + IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "Evm". + +Require ethereum.dao_fork.vm.gas. +Axiom ethereum_dao_fork_vm_gas_GAS_LOG : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_LOG". +Axiom ethereum_dao_fork_vm_gas_GAS_LOG_DATA : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_LOG_DATA". +Axiom ethereum_dao_fork_vm_gas_GAS_LOG_TOPIC : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_LOG_TOPIC". +Axiom ethereum_dao_fork_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_dao_fork_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "charge_gas". + +Require ethereum.dao_fork.vm.memory. +Axiom ethereum_dao_fork_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.dao_fork.vm.memory.globals "memory_read_bytes". + +Require ethereum.dao_fork.vm.stack. +Axiom ethereum_dao_fork_vm_stack_pop : + IsGlobalAlias globals ethereum.dao_fork.vm.stack.globals "pop". Definition log_n : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/memory.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/memory.v index 86ba742..0165398 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/memory.v @@ -23,31 +23,31 @@ Axiom ethereum_base_types_U256 : Axiom ethereum_base_types_Bytes : IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.dao_fork.vm.__init__. +Axiom ethereum_dao_fork_vm___init___Evm : + IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.dao_fork.vm.gas. +Axiom ethereum_dao_fork_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_BASE". +Axiom ethereum_dao_fork_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_dao_fork_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_dao_fork_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "charge_gas". -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". -Axiom memory_memory_write : - IsGlobalAlias globals memory.globals "memory_write". +Require ethereum.dao_fork.vm.memory. +Axiom ethereum_dao_fork_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.dao_fork.vm.memory.globals "memory_read_bytes". +Axiom ethereum_dao_fork_vm_memory_memory_write : + IsGlobalAlias globals ethereum.dao_fork.vm.memory.globals "memory_write". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.dao_fork.vm.stack. +Axiom ethereum_dao_fork_vm_stack_pop : + IsGlobalAlias globals ethereum.dao_fork.vm.stack.globals "pop". +Axiom ethereum_dao_fork_vm_stack_push : + IsGlobalAlias globals ethereum.dao_fork.vm.stack.globals "push". Definition mstore : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/stack.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/stack.v index 305af15..bfd40cc 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/stack.v @@ -29,27 +29,27 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". -Axiom __init___stack : - IsGlobalAlias globals __init__.globals "stack". - -Require exceptions. -Axiom exceptions_StackUnderflowError : - IsGlobalAlias globals exceptions.globals "StackUnderflowError". - -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require memory. -Axiom memory_buffer_read : - IsGlobalAlias globals memory.globals "buffer_read". +Require ethereum.dao_fork.vm.__init__. +Axiom ethereum_dao_fork_vm___init___Evm : + IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "Evm". +Axiom ethereum_dao_fork_vm___init___stack : + IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "stack". + +Require ethereum.dao_fork.vm.exceptions. +Axiom ethereum_dao_fork_vm_exceptions_StackUnderflowError : + IsGlobalAlias globals ethereum.dao_fork.vm.exceptions.globals "StackUnderflowError". + +Require ethereum.dao_fork.vm.gas. +Axiom ethereum_dao_fork_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_BASE". +Axiom ethereum_dao_fork_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_dao_fork_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "charge_gas". + +Require ethereum.dao_fork.vm.memory. +Axiom ethereum_dao_fork_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.dao_fork.vm.memory.globals "buffer_read". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/storage.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/storage.v index 5250214..aca2f43 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/storage.v @@ -17,33 +17,33 @@ Introduction Implementations of the EVM storage related instructions. ". -Require state. -Axiom state_get_storage : - IsGlobalAlias globals state.globals "get_storage". -Axiom state_set_storage : - IsGlobalAlias globals state.globals "set_storage". +Require ethereum.dao_fork.state. +Axiom ethereum_dao_fork_state_get_storage : + IsGlobalAlias globals ethereum.dao_fork.state.globals "get_storage". +Axiom ethereum_dao_fork_state_set_storage : + IsGlobalAlias globals ethereum.dao_fork.state.globals "set_storage". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.dao_fork.vm.__init__. +Axiom ethereum_dao_fork_vm___init___Evm : + IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_SLOAD : - IsGlobalAlias globals gas.globals "GAS_SLOAD". -Axiom gas_GAS_STORAGE_CLEAR_REFUND : - IsGlobalAlias globals gas.globals "GAS_STORAGE_CLEAR_REFUND". -Axiom gas_GAS_STORAGE_SET : - IsGlobalAlias globals gas.globals "GAS_STORAGE_SET". -Axiom gas_GAS_STORAGE_UPDATE : - IsGlobalAlias globals gas.globals "GAS_STORAGE_UPDATE". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.dao_fork.vm.gas. +Axiom ethereum_dao_fork_vm_gas_GAS_SLOAD : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_SLOAD". +Axiom ethereum_dao_fork_vm_gas_GAS_STORAGE_CLEAR_REFUND : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_STORAGE_CLEAR_REFUND". +Axiom ethereum_dao_fork_vm_gas_GAS_STORAGE_SET : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_STORAGE_SET". +Axiom ethereum_dao_fork_vm_gas_GAS_STORAGE_UPDATE : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_STORAGE_UPDATE". +Axiom ethereum_dao_fork_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "charge_gas". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.dao_fork.vm.stack. +Axiom ethereum_dao_fork_vm_stack_pop : + IsGlobalAlias globals ethereum.dao_fork.vm.stack.globals "pop". +Axiom ethereum_dao_fork_vm_stack_push : + IsGlobalAlias globals ethereum.dao_fork.vm.stack.globals "push". Definition sload : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -146,11 +146,56 @@ Definition sstore : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "new_value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "current_value" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let gas_cost := + M.get_name (| globals, "GAS_STORAGE_SET" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let gas_cost := M.get_name (| globals, "GAS_STORAGE_UPDATE" |) in M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_name (| globals, "new_value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "current_value" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/system.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/system.v index d3dc734..45307ce 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/system.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/system.v @@ -25,63 +25,63 @@ Axiom ethereum_base_types_Bytes0 : Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.dao_fork.fork_types. +Axiom ethereum_dao_fork_fork_types_Address : + IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "Address". -Require state. -Axiom state_account_has_code_or_nonce : - IsGlobalAlias globals state.globals "account_has_code_or_nonce". -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". -Axiom state_increment_nonce : - IsGlobalAlias globals state.globals "increment_nonce". -Axiom state_set_account_balance : - IsGlobalAlias globals state.globals "set_account_balance". +Require ethereum.dao_fork.state. +Axiom ethereum_dao_fork_state_account_has_code_or_nonce : + IsGlobalAlias globals ethereum.dao_fork.state.globals "account_has_code_or_nonce". +Axiom ethereum_dao_fork_state_get_account : + IsGlobalAlias globals ethereum.dao_fork.state.globals "get_account". +Axiom ethereum_dao_fork_state_increment_nonce : + IsGlobalAlias globals ethereum.dao_fork.state.globals "increment_nonce". +Axiom ethereum_dao_fork_state_set_account_balance : + IsGlobalAlias globals ethereum.dao_fork.state.globals "set_account_balance". -Require utils.address. -Axiom utils_address_compute_contract_address : - IsGlobalAlias globals utils.address.globals "compute_contract_address". -Axiom utils_address_to_address : - IsGlobalAlias globals utils.address.globals "to_address". +Require ethereum.dao_fork.utils.address. +Axiom ethereum_dao_fork_utils_address_compute_contract_address : + IsGlobalAlias globals ethereum.dao_fork.utils.address.globals "compute_contract_address". +Axiom ethereum_dao_fork_utils_address_to_address : + IsGlobalAlias globals ethereum.dao_fork.utils.address.globals "to_address". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". -Axiom __init___Message : - IsGlobalAlias globals __init__.globals "Message". -Axiom __init___incorporate_child_on_error : - IsGlobalAlias globals __init__.globals "incorporate_child_on_error". -Axiom __init___incorporate_child_on_success : - IsGlobalAlias globals __init__.globals "incorporate_child_on_success". +Require ethereum.dao_fork.vm.__init__. +Axiom ethereum_dao_fork_vm___init___Evm : + IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "Evm". +Axiom ethereum_dao_fork_vm___init___Message : + IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "Message". +Axiom ethereum_dao_fork_vm___init___incorporate_child_on_error : + IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "incorporate_child_on_error". +Axiom ethereum_dao_fork_vm___init___incorporate_child_on_success : + IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "incorporate_child_on_success". -Require gas. -Axiom gas_GAS_CALL : - IsGlobalAlias globals gas.globals "GAS_CALL". -Axiom gas_GAS_CREATE : - IsGlobalAlias globals gas.globals "GAS_CREATE". -Axiom gas_GAS_ZERO : - IsGlobalAlias globals gas.globals "GAS_ZERO". -Axiom gas_REFUND_SELF_DESTRUCT : - IsGlobalAlias globals gas.globals "REFUND_SELF_DESTRUCT". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_calculate_message_call_gas : - IsGlobalAlias globals gas.globals "calculate_message_call_gas". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.dao_fork.vm.gas. +Axiom ethereum_dao_fork_vm_gas_GAS_CALL : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_CALL". +Axiom ethereum_dao_fork_vm_gas_GAS_CREATE : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_CREATE". +Axiom ethereum_dao_fork_vm_gas_GAS_ZERO : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_ZERO". +Axiom ethereum_dao_fork_vm_gas_REFUND_SELF_DESTRUCT : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "REFUND_SELF_DESTRUCT". +Axiom ethereum_dao_fork_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_dao_fork_vm_gas_calculate_message_call_gas : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "calculate_message_call_gas". +Axiom ethereum_dao_fork_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "charge_gas". -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". -Axiom memory_memory_write : - IsGlobalAlias globals memory.globals "memory_write". +Require ethereum.dao_fork.vm.memory. +Axiom ethereum_dao_fork_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.dao_fork.vm.memory.globals "memory_read_bytes". +Axiom ethereum_dao_fork_vm_memory_memory_write : + IsGlobalAlias globals ethereum.dao_fork.vm.memory.globals "memory_write". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.dao_fork.vm.stack. +Axiom ethereum_dao_fork_vm_stack_pop : + IsGlobalAlias globals ethereum.dao_fork.vm.stack.globals "pop". +Axiom ethereum_dao_fork_vm_stack_push : + IsGlobalAlias globals ethereum.dao_fork.vm.stack.globals "push". Definition create : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -189,7 +189,105 @@ Definition create : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt (| + M.get_field (| M.get_name (| globals, "sender" |), "balance" |), + M.get_name (| globals, "endowment" |) + |), + ltac:(M.monadic ( + BoolOp.or (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "sender" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.sub (| + BinOp.pow (| + Constant.int 2, + Constant.int 64 + |), + Constant.int 1 + |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.gt (| + BinOp.add (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "depth" |), + Constant.int 1 + |), + M.get_name (| globals, "STACK_DEPTH_LIMIT" |) + |) + )) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "create_message_gas" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "contract_address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let call_data := M.call (| M.get_name (| globals, "memory_read_bytes" |), @@ -224,6 +322,36 @@ Definition create : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "child_evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_error" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "incorporate_child_on_success" |), make_list [ @@ -343,6 +471,42 @@ Definition generic_call : Value.t -> Value.t -> M := " in (* At stmt: unsupported node type: ImportFrom *) let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + BinOp.add (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "depth" |), + Constant.int 1 + |), + M.get_name (| globals, "STACK_DEPTH_LIMIT" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "gas" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let call_data := @@ -380,6 +544,36 @@ Definition generic_call : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "child_evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_error" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "incorporate_child_on_success" |), make_list [ @@ -430,7 +624,7 @@ Definition generic_call : Value.t -> Value.t -> M := make_list [ M.get_field (| M.get_name (| globals, "evm" |), "memory" |); M.get_name (| globals, "memory_output_start_position" |); - M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), Constant.None_:M.get_name (| globals, "actual_output_size" |) |) + M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), M.slice (| Constant.None_, M.get_name (| globals, "actual_output_size" |) |) |) ], make_dict [] |) in @@ -567,6 +761,36 @@ Definition call : Value.t -> Value.t -> M := make_dict [] |), "balance" |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "sender_balance" |), + M.get_name (| globals, "value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "generic_call" |), make_list [ @@ -726,6 +950,36 @@ Definition callcode : Value.t -> Value.t -> M := make_dict [] |), "balance" |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "sender_balance" |), + M.get_name (| globals, "value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "generic_call" |), make_list [ @@ -800,6 +1054,22 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in EndWhile. let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "originator" |), + M.get_name (| globals, "refunded_accounts" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.get_name (| globals, "REFUND_SELF_DESTRUCT" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/dao_fork/vm/interpreter.v b/CoqOfPython/ethereum/dao_fork/vm/interpreter.v index c3c5b56..7ed4c77 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/interpreter.v +++ b/CoqOfPython/ethereum/dao_fork/vm/interpreter.v @@ -57,69 +57,69 @@ Axiom ethereum_trace_TransactionEnd : Axiom ethereum_trace_evm_trace : IsGlobalAlias globals ethereum.trace.globals "evm_trace". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". - -Require state. -Axiom state_account_has_code_or_nonce : - IsGlobalAlias globals state.globals "account_has_code_or_nonce". -Axiom state_begin_transaction : - IsGlobalAlias globals state.globals "begin_transaction". -Axiom state_commit_transaction : - IsGlobalAlias globals state.globals "commit_transaction". -Axiom state_move_ether : - IsGlobalAlias globals state.globals "move_ether". -Axiom state_rollback_transaction : - IsGlobalAlias globals state.globals "rollback_transaction". -Axiom state_set_code : - IsGlobalAlias globals state.globals "set_code". -Axiom state_touch_account : - IsGlobalAlias globals state.globals "touch_account". - -Require vm. -Axiom vm_Message : - IsGlobalAlias globals vm.globals "Message". - -Require vm.gas. -Axiom vm_gas_GAS_CODE_DEPOSIT : - IsGlobalAlias globals vm.gas.globals "GAS_CODE_DEPOSIT". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". - -Require vm.precompiled_contracts.mapping. -Axiom vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : - IsGlobalAlias globals vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". - -Require __init__. -Axiom __init___Environment : - IsGlobalAlias globals __init__.globals "Environment". -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require exceptions. -Axiom exceptions_AddressCollision : - IsGlobalAlias globals exceptions.globals "AddressCollision". -Axiom exceptions_ExceptionalHalt : - IsGlobalAlias globals exceptions.globals "ExceptionalHalt". -Axiom exceptions_InvalidOpcode : - IsGlobalAlias globals exceptions.globals "InvalidOpcode". -Axiom exceptions_StackDepthLimitError : - IsGlobalAlias globals exceptions.globals "StackDepthLimitError". - -Require instructions. -Axiom instructions_Ops : - IsGlobalAlias globals instructions.globals "Ops". -Axiom instructions_op_implementation : - IsGlobalAlias globals instructions.globals "op_implementation". - -Require runtime. -Axiom runtime_get_valid_jump_destinations : - IsGlobalAlias globals runtime.globals "get_valid_jump_destinations". +Require ethereum.dao_fork.blocks. +Axiom ethereum_dao_fork_blocks_Log : + IsGlobalAlias globals ethereum.dao_fork.blocks.globals "Log". + +Require ethereum.dao_fork.fork_types. +Axiom ethereum_dao_fork_fork_types_Address : + IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "Address". + +Require ethereum.dao_fork.state. +Axiom ethereum_dao_fork_state_account_has_code_or_nonce : + IsGlobalAlias globals ethereum.dao_fork.state.globals "account_has_code_or_nonce". +Axiom ethereum_dao_fork_state_begin_transaction : + IsGlobalAlias globals ethereum.dao_fork.state.globals "begin_transaction". +Axiom ethereum_dao_fork_state_commit_transaction : + IsGlobalAlias globals ethereum.dao_fork.state.globals "commit_transaction". +Axiom ethereum_dao_fork_state_move_ether : + IsGlobalAlias globals ethereum.dao_fork.state.globals "move_ether". +Axiom ethereum_dao_fork_state_rollback_transaction : + IsGlobalAlias globals ethereum.dao_fork.state.globals "rollback_transaction". +Axiom ethereum_dao_fork_state_set_code : + IsGlobalAlias globals ethereum.dao_fork.state.globals "set_code". +Axiom ethereum_dao_fork_state_touch_account : + IsGlobalAlias globals ethereum.dao_fork.state.globals "touch_account". + +Require ethereum.dao_fork.vm.__init__. +Axiom ethereum_dao_fork_vm___init___Message : + IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "Message". + +Require ethereum.dao_fork.vm.gas. +Axiom ethereum_dao_fork_vm_gas_GAS_CODE_DEPOSIT : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_CODE_DEPOSIT". +Axiom ethereum_dao_fork_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "charge_gas". + +Require ethereum.dao_fork.vm.precompiled_contracts.mapping. +Axiom ethereum_dao_fork_vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : + IsGlobalAlias globals ethereum.dao_fork.vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". + +Require ethereum.dao_fork.vm.__init__. +Axiom ethereum_dao_fork_vm___init___Environment : + IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "Environment". +Axiom ethereum_dao_fork_vm___init___Evm : + IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "Evm". + +Require ethereum.dao_fork.vm.exceptions. +Axiom ethereum_dao_fork_vm_exceptions_AddressCollision : + IsGlobalAlias globals ethereum.dao_fork.vm.exceptions.globals "AddressCollision". +Axiom ethereum_dao_fork_vm_exceptions_ExceptionalHalt : + IsGlobalAlias globals ethereum.dao_fork.vm.exceptions.globals "ExceptionalHalt". +Axiom ethereum_dao_fork_vm_exceptions_InvalidOpcode : + IsGlobalAlias globals ethereum.dao_fork.vm.exceptions.globals "InvalidOpcode". +Axiom ethereum_dao_fork_vm_exceptions_StackDepthLimitError : + IsGlobalAlias globals ethereum.dao_fork.vm.exceptions.globals "StackDepthLimitError". + +Require ethereum.dao_fork.vm.instructions.__init__. +Axiom ethereum_dao_fork_vm_instructions___init___Ops : + IsGlobalAlias globals ethereum.dao_fork.vm.instructions.__init__.globals "Ops". +Axiom ethereum_dao_fork_vm_instructions___init___op_implementation : + IsGlobalAlias globals ethereum.dao_fork.vm.instructions.__init__.globals "op_implementation". + +Require ethereum.dao_fork.vm.runtime. +Axiom ethereum_dao_fork_vm_runtime_get_valid_jump_destinations : + IsGlobalAlias globals ethereum.dao_fork.vm.runtime.globals "get_valid_jump_destinations". Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -162,6 +162,89 @@ Definition process_message_call : Value.t -> Value.t -> M := Output of the message call " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "message" |), "target" |), + M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) + |), + (* then *) + ltac:(M.monadic ( + let is_collision := + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_name (| globals, "is_collision" |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallOutput" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "tuple" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "AddressCollision" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let evm := + M.call (| + M.get_name (| globals, "process_create_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let evm := M.call (| M.get_name (| globals, "process_message" |), @@ -174,6 +257,29 @@ Definition process_message_call : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( +(* At stmt: unsupported node type: AnnAssign *) + let accounts_to_delete := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let refund_counter := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let logs := M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in let accounts_to_delete := @@ -209,6 +315,7 @@ Definition process_message_call : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). Definition process_create_message : Value.t -> Value.t -> M := @@ -246,6 +353,28 @@ Definition process_create_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), + (* then *) + ltac:(M.monadic ( + let contract_code := + M.get_field (| M.get_name (| globals, "evm" |), "output" |) in + let contract_code_gas := + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "contract_code" |) + ], + make_dict [] + |), + M.get_name (| globals, "GAS_CODE_DEPOSIT" |) + |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "rollback_transaction" |), make_list [ @@ -257,6 +386,7 @@ Definition process_create_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) + |) in M.pure Constant.None_)). Definition process_message : Value.t -> Value.t -> M := @@ -278,6 +408,24 @@ Definition process_message : Value.t -> Value.t -> M := Items containing execution specific objects " in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_field (| M.get_name (| globals, "message" |), "depth" |), + M.get_name (| globals, "STACK_DEPTH_LIMIT" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "StackDepthLimitError" |), + make_list [ + Constant.str "Stack depth limit reached" + ], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -296,6 +444,32 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + M.get_field (| M.get_name (| globals, "message" |), "should_transfer_value" |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "message" |), "value" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "move_ether" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "caller" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |); + M.get_field (| M.get_name (| globals, "message" |), "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let evm := @@ -308,6 +482,21 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "rollback_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "commit_transaction" |), make_list [ @@ -319,6 +508,7 @@ Definition process_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) + |) in M.pure Constant.None_)). Definition execute_code : Value.t -> Value.t -> M := @@ -358,4 +548,5 @@ Definition execute_code : Value.t -> Value.t -> M := (* At stmt: unsupported node type: Try *) let _ := M.return_ (| M.get_name (| globals, "evm" |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/vm/memory.v b/CoqOfPython/ethereum/dao_fork/vm/memory.v index 4b107fd..08d2290 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/memory.v +++ b/CoqOfPython/ethereum/dao_fork/vm/memory.v @@ -21,13 +21,13 @@ Require ethereum.utils.byte. Axiom ethereum_utils_byte_right_pad_zero_bytes : IsGlobalAlias globals ethereum.utils.byte.globals "right_pad_zero_bytes". -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". Definition memory_write : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,7 +45,22 @@ Definition memory_write : Value.t -> Value.t -> M := Data to write to memory. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |), + M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) |) |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_)). @@ -71,7 +86,23 @@ Definition memory_read_bytes : Value.t -> Value.t -> M := Data read from memory. " in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |) + M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |) |) + |) in M.pure Constant.None_)). Definition buffer_read : Value.t -> Value.t -> M := @@ -98,9 +129,25 @@ Definition buffer_read : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "right_pad_zero_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |) |); + M.get_subscript (| M.get_name (| globals, "buffer" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |) |); M.get_name (| globals, "size" |) ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/__init__.v index 422f670..e4c6e92 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/__init__.v +++ b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/__init__.v @@ -18,9 +18,9 @@ Addresses of precompiled contracts and mappings to their implementations. ". -Require utils.hexadecimal. -Axiom utils_hexadecimal_hex_to_address : - IsGlobalAlias globals utils.hexadecimal.globals "hex_to_address". +Require ethereum.dao_fork.utils.hexadecimal. +Axiom ethereum_dao_fork_utils_hexadecimal_hex_to_address : + IsGlobalAlias globals ethereum.dao_fork.utils.hexadecimal.globals "hex_to_address". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS" ] diff --git a/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/ecrecover.v index 0cbcf16..c43db35 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/ecrecover.v @@ -37,19 +37,19 @@ Require ethereum.utils.byte. Axiom ethereum_utils_byte_left_pad_zero_bytes : IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.dao_fork.vm.__init__. +Axiom ethereum_dao_fork_vm___init___Evm : + IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_ECRECOVER : - IsGlobalAlias globals vm.gas.globals "GAS_ECRECOVER". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.dao_fork.vm.gas. +Axiom ethereum_dao_fork_vm_gas_GAS_ECRECOVER : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_ECRECOVER". +Axiom ethereum_dao_fork_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "charge_gas". -Require vm.memory. -Axiom vm_memory_buffer_read : - IsGlobalAlias globals vm.memory.globals "buffer_read". +Require ethereum.dao_fork.vm.memory. +Axiom ethereum_dao_fork_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.dao_fork.vm.memory.globals "buffer_read". Definition ecrecover : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -188,12 +188,78 @@ Definition ecrecover : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "v" |), + Constant.int 27 + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "v" |), + Constant.int 28 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + Constant.int 0, + M.get_name (| globals, "r" |) + |), + ltac:(M.monadic ( + Compare.gt_e (| + M.get_name (| globals, "r" |), + M.get_name (| globals, "SECP256K1N" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + Constant.int 0, + M.get_name (| globals, "s" |) + |), + ltac:(M.monadic ( + Compare.gt_e (| + M.get_name (| globals, "s" |), + M.get_name (| globals, "SECP256K1N" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: Try *) @@ -204,7 +270,7 @@ Definition ecrecover : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12 |) in + |), M.slice (| Constant.int 12, Constant.int 32 |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/identity.v index fa96704..e935160 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/identity.v +++ b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/identity.v @@ -25,17 +25,17 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.dao_fork.vm.__init__. +Axiom ethereum_dao_fork_vm___init___Evm : + IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_IDENTITY : - IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY". -Axiom vm_gas_GAS_IDENTITY_WORD : - IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY_WORD". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.dao_fork.vm.gas. +Axiom ethereum_dao_fork_vm_gas_GAS_IDENTITY : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_IDENTITY". +Axiom ethereum_dao_fork_vm_gas_GAS_IDENTITY_WORD : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_IDENTITY_WORD". +Axiom ethereum_dao_fork_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "charge_gas". Definition identity : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/mapping.v index 710457d..c487428 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/mapping.v +++ b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/mapping.v @@ -23,34 +23,34 @@ Axiom typing_Callable : Axiom typing_Dict : IsGlobalAlias globals typing.globals "Dict". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". - -Require __init__. -Axiom __init___ECRECOVER_ADDRESS : - IsGlobalAlias globals __init__.globals "ECRECOVER_ADDRESS". -Axiom __init___IDENTITY_ADDRESS : - IsGlobalAlias globals __init__.globals "IDENTITY_ADDRESS". -Axiom __init___RIPEMD160_ADDRESS : - IsGlobalAlias globals __init__.globals "RIPEMD160_ADDRESS". -Axiom __init___SHA256_ADDRESS : - IsGlobalAlias globals __init__.globals "SHA256_ADDRESS". - -Require ecrecover. -Axiom ecrecover_ecrecover : - IsGlobalAlias globals ecrecover.globals "ecrecover". - -Require identity. -Axiom identity_identity : - IsGlobalAlias globals identity.globals "identity". - -Require ripemd160. -Axiom ripemd160_ripemd160 : - IsGlobalAlias globals ripemd160.globals "ripemd160". - -Require sha256. -Axiom sha256_sha256 : - IsGlobalAlias globals sha256.globals "sha256". +Require ethereum.dao_fork.fork_types. +Axiom ethereum_dao_fork_fork_types_Address : + IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "Address". + +Require ethereum.dao_fork.vm.precompiled_contracts.__init__. +Axiom ethereum_dao_fork_vm_precompiled_contracts___init___ECRECOVER_ADDRESS : + IsGlobalAlias globals ethereum.dao_fork.vm.precompiled_contracts.__init__.globals "ECRECOVER_ADDRESS". +Axiom ethereum_dao_fork_vm_precompiled_contracts___init___IDENTITY_ADDRESS : + IsGlobalAlias globals ethereum.dao_fork.vm.precompiled_contracts.__init__.globals "IDENTITY_ADDRESS". +Axiom ethereum_dao_fork_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : + IsGlobalAlias globals ethereum.dao_fork.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". +Axiom ethereum_dao_fork_vm_precompiled_contracts___init___SHA256_ADDRESS : + IsGlobalAlias globals ethereum.dao_fork.vm.precompiled_contracts.__init__.globals "SHA256_ADDRESS". + +Require ethereum.dao_fork.vm.precompiled_contracts.ecrecover. +Axiom ethereum_dao_fork_vm_precompiled_contracts_ecrecover_ecrecover : + IsGlobalAlias globals ethereum.dao_fork.vm.precompiled_contracts.ecrecover.globals "ecrecover". + +Require ethereum.dao_fork.vm.precompiled_contracts.identity. +Axiom ethereum_dao_fork_vm_precompiled_contracts_identity_identity : + IsGlobalAlias globals ethereum.dao_fork.vm.precompiled_contracts.identity.globals "identity". + +Require ethereum.dao_fork.vm.precompiled_contracts.ripemd160. +Axiom ethereum_dao_fork_vm_precompiled_contracts_ripemd160_ripemd160 : + IsGlobalAlias globals ethereum.dao_fork.vm.precompiled_contracts.ripemd160.globals "ripemd160". + +Require ethereum.dao_fork.vm.precompiled_contracts.sha256. +Axiom ethereum_dao_fork_vm_precompiled_contracts_sha256_sha256 : + IsGlobalAlias globals ethereum.dao_fork.vm.precompiled_contracts.sha256.globals "sha256". (* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/ripemd160.v index 96f8dcd..ef25944 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/ripemd160.v +++ b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/ripemd160.v @@ -31,17 +31,17 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.dao_fork.vm.__init__. +Axiom ethereum_dao_fork_vm___init___Evm : + IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_RIPEMD160 : - IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160". -Axiom vm_gas_GAS_RIPEMD160_WORD : - IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160_WORD". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.dao_fork.vm.gas. +Axiom ethereum_dao_fork_vm_gas_GAS_RIPEMD160 : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_RIPEMD160". +Axiom ethereum_dao_fork_vm_gas_GAS_RIPEMD160_WORD : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_RIPEMD160_WORD". +Axiom ethereum_dao_fork_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "charge_gas". Definition ripemd160 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/sha256.v index 9f6d2bf..464c763 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/sha256.v +++ b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/sha256.v @@ -27,17 +27,17 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.dao_fork.vm.__init__. +Axiom ethereum_dao_fork_vm___init___Evm : + IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_SHA256 : - IsGlobalAlias globals vm.gas.globals "GAS_SHA256". -Axiom vm_gas_GAS_SHA256_WORD : - IsGlobalAlias globals vm.gas.globals "GAS_SHA256_WORD". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.dao_fork.vm.gas. +Axiom ethereum_dao_fork_vm_gas_GAS_SHA256 : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_SHA256". +Axiom ethereum_dao_fork_vm_gas_GAS_SHA256_WORD : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_SHA256_WORD". +Axiom ethereum_dao_fork_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "charge_gas". Definition sha256 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/dao_fork/vm/runtime.v b/CoqOfPython/ethereum/dao_fork/vm/runtime.v index 2cd7652..4d10050 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/runtime.v +++ b/CoqOfPython/ethereum/dao_fork/vm/runtime.v @@ -25,9 +25,9 @@ Require ethereum.base_types. Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require instructions. -Axiom instructions_Ops : - IsGlobalAlias globals instructions.globals "Ops". +Require ethereum.dao_fork.vm.instructions.__init__. +Axiom ethereum_dao_fork_vm_instructions___init___Ops : + IsGlobalAlias globals ethereum.dao_fork.vm.instructions.__init__.globals "Ops". Definition get_valid_jump_destinations : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -79,7 +79,55 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := |) do (* At stmt: unsupported node type: Try *) let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "current_opcode" |), + M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), + make_list [ + M.get_name (| globals, "pc" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.lt_e (| + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |), + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH32" |), "value" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let push_data_size := + BinOp.add (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) + |), + Constant.int 1 + |) in + let pc := BinOp.add + M.get_name (| globals, "push_data_size" |) + M.get_name (| globals, "push_data_size" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -90,4 +138,5 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := EndWhile. let _ := M.return_ (| M.get_name (| globals, "valid_jump_destinations" |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/vm/stack.v b/CoqOfPython/ethereum/dao_fork/vm/stack.v index ea778df..ce376ae 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/stack.v +++ b/CoqOfPython/ethereum/dao_fork/vm/stack.v @@ -25,11 +25,11 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require exceptions. -Axiom exceptions_StackOverflowError : - IsGlobalAlias globals exceptions.globals "StackOverflowError". -Axiom exceptions_StackUnderflowError : - IsGlobalAlias globals exceptions.globals "StackUnderflowError". +Require ethereum.dao_fork.vm.exceptions. +Axiom ethereum_dao_fork_vm_exceptions_StackOverflowError : + IsGlobalAlias globals ethereum.dao_fork.vm.exceptions.globals "StackOverflowError". +Axiom ethereum_dao_fork_vm_exceptions_StackUnderflowError : + IsGlobalAlias globals ethereum.dao_fork.vm.exceptions.globals "StackUnderflowError". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -49,6 +49,24 @@ Definition pop : Value.t -> Value.t -> M := " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "StackUnderflowError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -57,6 +75,7 @@ Definition pop : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). Definition push : Value.t -> Value.t -> M := @@ -75,6 +94,24 @@ Definition push : Value.t -> Value.t -> M := " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), + Constant.int 1024 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "StackOverflowError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -85,4 +122,5 @@ Definition push : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/ethash.v b/CoqOfPython/ethereum/ethash.v index fffefb7..07fc2e3 100644 --- a/CoqOfPython/ethereum/ethash.v +++ b/CoqOfPython/ethereum/ethash.v @@ -13,15 +13,6 @@ header, while the set itself is changed every [`epoch`]. At a high level, the Ethash algorithm is as follows: -1. Create a **seed** value, generated with [`generate_seed`] and based on the - preceding block numbers. -1. From the seed, compute a pseudorandom **cache** with [`generate_cache`]. -1. From the cache, generate a **dataset** with [`generate_dataset`]. The - dataset grows over time based on [`DATASET_EPOCH_GROWTH_SIZE`]. -1. Miners hash slices of the dataset together, which is where the memory - hardness is introduced. Verification of the proof-of-work only requires the - cache to be able to recompute a much smaller subset of the full dataset. - [`DATASET_EPOCH_GROWTH_SIZE`]: ref:ethereum.ethash.DATASET_EPOCH_GROWTH_SIZE [`generate_dataset`]: ref:ethereum.ethash.generate_dataset [`generate_cache`]: ref:ethereum.ethash.generate_cache @@ -216,6 +207,7 @@ Definition epoch : Value.t -> Value.t -> M := M.get_name (| globals, "block_number" |), M.get_name (| globals, "EPOCH_SIZE" |) |) + |) in M.pure Constant.None_)). Definition cache_size : Value.t -> Value.t -> M := @@ -277,6 +269,7 @@ Definition cache_size : Value.t -> Value.t -> M := EndWhile. let _ := M.return_ (| M.get_name (| globals, "size" |) + |) in M.pure Constant.None_)). Definition dataset_size : Value.t -> Value.t -> M := @@ -340,6 +333,7 @@ Definition dataset_size : Value.t -> Value.t -> M := EndWhile. let _ := M.return_ (| M.get_name (| globals, "size" |) + |) in M.pure Constant.None_)). Definition generate_seed : Value.t -> Value.t -> M := @@ -388,6 +382,7 @@ Definition generate_seed : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition generate_cache : Value.t -> Value.t -> M := @@ -499,7 +494,7 @@ Definition generate_cache : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "U32" |), "from_le_bytes" |), make_list [ - M.get_subscript (| M.get_subscript (| M.get_name (| globals, "cache" |), M.get_name (| globals, "index" |) |), Constant.int 0 |) + M.get_subscript (| M.get_subscript (| M.get_name (| globals, "cache" |), M.get_name (| globals, "index" |) |), M.slice (| Constant.int 0, Constant.int 4 |) |) ], make_dict [] |), @@ -509,7 +504,7 @@ Definition generate_cache : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "bytes" |), make_list [ - (* At expr: unsupported node type: ListComp *) + Constant.str "(* At expr: unsupported node type: ListComp *)" ], make_dict [] |) in @@ -529,10 +524,11 @@ Definition generate_cache : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "tuple" |), make_list [ - (* At expr: unsupported node type: GeneratorExp *) + Constant.str "(* At expr: unsupported node type: GeneratorExp *)" ], make_dict [] |) + |) in M.pure Constant.None_)). Definition fnv : Value.t -> Value.t -> M := @@ -584,6 +580,7 @@ Definition fnv : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition fnv_hash : Value.t -> Value.t -> M := @@ -601,10 +598,11 @@ Definition fnv_hash : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "tuple" |), make_list [ - (* At expr: unsupported node type: GeneratorExp *) + Constant.str "(* At expr: unsupported node type: GeneratorExp *)" ], - make_dict [] + make_dict [ ] |) + |) in M.pure Constant.None_)). Definition generate_dataset_item : Value.t -> Value.t -> M := @@ -723,6 +721,7 @@ Definition generate_dataset_item : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition generate_dataset : Value.t -> Value.t -> M := @@ -740,10 +739,11 @@ Definition generate_dataset : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "tuple" |), make_list [ - (* At expr: unsupported node type: GeneratorExp *) + Constant.str "(* At expr: unsupported node type: GeneratorExp *)" ], make_dict [] |) + |) in M.pure Constant.None_)). Definition hashimoto : Value.t -> Value.t -> M := @@ -799,7 +799,7 @@ Definition hashimoto : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "U32" |), "from_le_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "seed_hash" |), Constant.None_:Constant.int 4 |) + M.get_subscript (| M.get_name (| globals, "seed_hash" |), M.slice (| Constant.None_, Constant.int 4 |) |) ], make_dict [] |) in @@ -990,6 +990,7 @@ Definition hashimoto : Value.t -> Value.t -> M := |) in let _ := M.return_ (| make_tuple [ M.get_name (| globals, "mix_digest" |); M.get_name (| globals, "result" |) ] + |) in M.pure Constant.None_)). Definition hashimoto_light : Value.t -> Value.t -> M := @@ -1029,4 +1030,5 @@ Definition hashimoto_light : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/fork_criteria.v b/CoqOfPython/ethereum/fork_criteria.v index 4d87501..819e702 100644 --- a/CoqOfPython/ethereum/fork_criteria.v +++ b/CoqOfPython/ethereum/fork_criteria.v @@ -46,10 +46,32 @@ Definition ForkCriteria : Value.t := Equality for fork criteria. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "other" |); + M.get_name (| globals, "ForkCriteria" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "self" |), "_internal" |), + M.get_field (| M.get_name (| globals, "other" |), "_internal" |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| M.get_name (| globals, "NotImplemented" |) + |) in M.pure Constant.None_)) ); ( @@ -61,10 +83,32 @@ Definition ForkCriteria : Value.t := forks and scheduled forks are before unscheduled forks. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "other" |); + M.get_name (| globals, "ForkCriteria" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Compare.lt (| + M.get_field (| M.get_name (| globals, "self" |), "_internal" |), + M.get_field (| M.get_name (| globals, "other" |), "_internal" |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| M.get_name (| globals, "NotImplemented" |) + |) in M.pure Constant.None_)) ); ( @@ -82,6 +126,7 @@ Definition ForkCriteria : Value.t := ], make_dict [] |) + |) in M.pure Constant.None_)) ) ]. @@ -119,6 +164,7 @@ Definition ByBlockNumber : Value.t := M.get_name (| globals, "block_number" |), M.get_field (| M.get_name (| globals, "self" |), "block_number" |) |) + |) in M.pure Constant.None_)) ); ( @@ -129,7 +175,8 @@ Definition ByBlockNumber : Value.t := String representation of this object. " in let _ := M.return_ (| - (* At expr: unsupported node type: JoinedStr *) + Constant.str "(* At expr: unsupported node type: JoinedStr *)" + |) in M.pure Constant.None_)) ) ]. @@ -167,6 +214,7 @@ Definition ByTimestamp : Value.t := M.get_name (| globals, "timestamp" |), M.get_field (| M.get_name (| globals, "self" |), "timestamp" |) |) + |) in M.pure Constant.None_)) ); ( @@ -177,7 +225,8 @@ Definition ByTimestamp : Value.t := String representation of this object. " in let _ := M.return_ (| - (* At expr: unsupported node type: JoinedStr *) + Constant.str "(* At expr: unsupported node type: JoinedStr *)" + |) in M.pure Constant.None_)) ) ]. @@ -208,6 +257,7 @@ Definition Unscheduled : Value.t := " in let _ := M.return_ (| Constant.bool false + |) in M.pure Constant.None_)) ); ( @@ -219,6 +269,7 @@ Definition Unscheduled : Value.t := " in let _ := M.return_ (| Constant.str "Unscheduled()" + |) in M.pure Constant.None_)) ) ]. diff --git a/CoqOfPython/ethereum/frontier/blocks.v b/CoqOfPython/ethereum/frontier/blocks.v index 6501788..3ed662a 100644 --- a/CoqOfPython/ethereum/frontier/blocks.v +++ b/CoqOfPython/ethereum/frontier/blocks.v @@ -22,35 +22,35 @@ Require typing. Axiom typing_Tuple : IsGlobalAlias globals typing.globals "Tuple". -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes8 : - IsGlobalAlias globals base_types.globals "Bytes8". -Axiom base_types_Bytes32 : - IsGlobalAlias globals base_types.globals "Bytes32". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require crypto.hash. -Axiom crypto_hash_Hash32 : - IsGlobalAlias globals crypto.hash.globals "Hash32". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". - -Require transactions. -Axiom transactions_Transaction : - IsGlobalAlias globals transactions.globals "Transaction". +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes8 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes8". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". + +Require ethereum.frontier.fork_types. +Axiom ethereum_frontier_fork_types_Address : + IsGlobalAlias globals ethereum.frontier.fork_types.globals "Address". +Axiom ethereum_frontier_fork_types_Bloom : + IsGlobalAlias globals ethereum.frontier.fork_types.globals "Bloom". +Axiom ethereum_frontier_fork_types_Root : + IsGlobalAlias globals ethereum.frontier.fork_types.globals "Root". + +Require ethereum.frontier.transactions. +Axiom ethereum_frontier_transactions_Transaction : + IsGlobalAlias globals ethereum.frontier.transactions.globals "Transaction". Definition Header : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/frontier/bloom.v b/CoqOfPython/ethereum/frontier/bloom.v index 04650ff..cc6bb49 100644 --- a/CoqOfPython/ethereum/frontier/bloom.v +++ b/CoqOfPython/ethereum/frontier/bloom.v @@ -33,13 +33,13 @@ Require ethereum.crypto.hash. Axiom ethereum_crypto_hash_keccak256 : IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". +Require ethereum.frontier.blocks. +Axiom ethereum_frontier_blocks_Log : + IsGlobalAlias globals ethereum.frontier.blocks.globals "Log". -Require fork_types. -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". +Require ethereum.frontier.fork_types. +Axiom ethereum_frontier_fork_types_Bloom : + IsGlobalAlias globals ethereum.frontier.fork_types.globals "Bloom". Definition add_to_bloom : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -72,7 +72,10 @@ Definition add_to_bloom : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |) |) + M.get_subscript (| M.get_name (| globals, "hash" |), M.slice (| M.get_name (| globals, "idx" |), BinOp.add (| + M.get_name (| globals, "idx" |), + Constant.int 2 + |) |) |) ], make_dict [] |), @@ -157,4 +160,5 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/fork.v b/CoqOfPython/ethereum/frontier/fork.v index 4ccf0a6..732bbc8 100644 --- a/CoqOfPython/ethereum/frontier/fork.v +++ b/CoqOfPython/ethereum/frontier/fork.v @@ -59,91 +59,91 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U64 : - IsGlobalAlias globals base_types.globals "U64". -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_U256_CEIL_VALUE : - IsGlobalAlias globals base_types.globals "U256_CEIL_VALUE". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes32 : - IsGlobalAlias globals base_types.globals "Bytes32". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". - -Require __init__. -Axiom __init___vm : - IsGlobalAlias globals __init__.globals "vm". - -Require blocks. -Axiom blocks_Block : - IsGlobalAlias globals blocks.globals "Block". -Axiom blocks_Header : - IsGlobalAlias globals blocks.globals "Header". -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". -Axiom blocks_Receipt : - IsGlobalAlias globals blocks.globals "Receipt". - -Require bloom. -Axiom bloom_logs_bloom : - IsGlobalAlias globals bloom.globals "logs_bloom". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". - -Require state. -Axiom state_State : - IsGlobalAlias globals state.globals "State". -Axiom state_create_ether : - IsGlobalAlias globals state.globals "create_ether". -Axiom state_destroy_account : - IsGlobalAlias globals state.globals "destroy_account". -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". -Axiom state_increment_nonce : - IsGlobalAlias globals state.globals "increment_nonce". -Axiom state_set_account_balance : - IsGlobalAlias globals state.globals "set_account_balance". -Axiom state_state_root : - IsGlobalAlias globals state.globals "state_root". - -Require transactions. -Axiom transactions_TX_BASE_COST : - IsGlobalAlias globals transactions.globals "TX_BASE_COST". -Axiom transactions_TX_DATA_COST_PER_NON_ZERO : - IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_NON_ZERO". -Axiom transactions_TX_DATA_COST_PER_ZERO : - IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_ZERO". -Axiom transactions_Transaction : - IsGlobalAlias globals transactions.globals "Transaction". - -Require trie. -Axiom trie_Trie : - IsGlobalAlias globals trie.globals "Trie". -Axiom trie_root : - IsGlobalAlias globals trie.globals "root". -Axiom trie_trie_set : - IsGlobalAlias globals trie.globals "trie_set". - -Require utils.message. -Axiom utils_message_prepare_message : - IsGlobalAlias globals utils.message.globals "prepare_message". - -Require vm.interpreter. -Axiom vm_interpreter_process_message_call : - IsGlobalAlias globals vm.interpreter.globals "process_message_call". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U64 : + IsGlobalAlias globals ethereum.base_types.globals "U64". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_U256_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.frontier.__init__. +Axiom ethereum_frontier___init___vm : + IsGlobalAlias globals ethereum.frontier.__init__.globals "vm". + +Require ethereum.frontier.blocks. +Axiom ethereum_frontier_blocks_Block : + IsGlobalAlias globals ethereum.frontier.blocks.globals "Block". +Axiom ethereum_frontier_blocks_Header : + IsGlobalAlias globals ethereum.frontier.blocks.globals "Header". +Axiom ethereum_frontier_blocks_Log : + IsGlobalAlias globals ethereum.frontier.blocks.globals "Log". +Axiom ethereum_frontier_blocks_Receipt : + IsGlobalAlias globals ethereum.frontier.blocks.globals "Receipt". + +Require ethereum.frontier.bloom. +Axiom ethereum_frontier_bloom_logs_bloom : + IsGlobalAlias globals ethereum.frontier.bloom.globals "logs_bloom". + +Require ethereum.frontier.fork_types. +Axiom ethereum_frontier_fork_types_Address : + IsGlobalAlias globals ethereum.frontier.fork_types.globals "Address". +Axiom ethereum_frontier_fork_types_Bloom : + IsGlobalAlias globals ethereum.frontier.fork_types.globals "Bloom". +Axiom ethereum_frontier_fork_types_Root : + IsGlobalAlias globals ethereum.frontier.fork_types.globals "Root". + +Require ethereum.frontier.state. +Axiom ethereum_frontier_state_State : + IsGlobalAlias globals ethereum.frontier.state.globals "State". +Axiom ethereum_frontier_state_create_ether : + IsGlobalAlias globals ethereum.frontier.state.globals "create_ether". +Axiom ethereum_frontier_state_destroy_account : + IsGlobalAlias globals ethereum.frontier.state.globals "destroy_account". +Axiom ethereum_frontier_state_get_account : + IsGlobalAlias globals ethereum.frontier.state.globals "get_account". +Axiom ethereum_frontier_state_increment_nonce : + IsGlobalAlias globals ethereum.frontier.state.globals "increment_nonce". +Axiom ethereum_frontier_state_set_account_balance : + IsGlobalAlias globals ethereum.frontier.state.globals "set_account_balance". +Axiom ethereum_frontier_state_state_root : + IsGlobalAlias globals ethereum.frontier.state.globals "state_root". + +Require ethereum.frontier.transactions. +Axiom ethereum_frontier_transactions_TX_BASE_COST : + IsGlobalAlias globals ethereum.frontier.transactions.globals "TX_BASE_COST". +Axiom ethereum_frontier_transactions_TX_DATA_COST_PER_NON_ZERO : + IsGlobalAlias globals ethereum.frontier.transactions.globals "TX_DATA_COST_PER_NON_ZERO". +Axiom ethereum_frontier_transactions_TX_DATA_COST_PER_ZERO : + IsGlobalAlias globals ethereum.frontier.transactions.globals "TX_DATA_COST_PER_ZERO". +Axiom ethereum_frontier_transactions_Transaction : + IsGlobalAlias globals ethereum.frontier.transactions.globals "Transaction". + +Require ethereum.frontier.trie. +Axiom ethereum_frontier_trie_Trie : + IsGlobalAlias globals ethereum.frontier.trie.globals "Trie". +Axiom ethereum_frontier_trie_root : + IsGlobalAlias globals ethereum.frontier.trie.globals "root". +Axiom ethereum_frontier_trie_trie_set : + IsGlobalAlias globals ethereum.frontier.trie.globals "trie_set". + +Require ethereum.frontier.utils.message. +Axiom ethereum_frontier_utils_message_prepare_message : + IsGlobalAlias globals ethereum.frontier.utils.message.globals "prepare_message". + +Require ethereum.frontier.vm.interpreter. +Axiom ethereum_frontier_vm_interpreter_process_message_call : + IsGlobalAlias globals ethereum.frontier.vm.interpreter.globals "process_message_call". Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -216,6 +216,7 @@ Definition apply_fork : Value.t -> Value.t -> M := " in let _ := M.return_ (| M.get_name (| globals, "old" |) + |) in M.pure Constant.None_)). Definition get_last_256_block_hashes : Value.t -> Value.t -> M := @@ -241,8 +242,28 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := Hashes of the recent 256 blocks in order of increasing block number. " in let recent_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |) |) in + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "recent_blocks" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + make_list [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let recent_block_hashes := @@ -281,6 +302,7 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "recent_block_hashes" |) + |) in M.pure Constant.None_)). Definition state_transition : Value.t -> Value.t -> M := @@ -411,6 +433,27 @@ Definition state_transition : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |) + ], + make_dict [] + |), + Constant.int 255 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -597,6 +640,7 @@ Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition validate_proof_of_work : Value.t -> Value.t -> M := @@ -728,6 +772,7 @@ Definition check_transaction : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "sender_address" |) + |) in M.pure Constant.None_)). Definition make_receipt : Value.t -> Value.t -> M := @@ -761,6 +806,7 @@ Definition make_receipt : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "receipt" |) + |) in M.pure Constant.None_)). Definition ApplyBodyOutput : Value.t := @@ -974,6 +1020,7 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition validate_ommers : Value.t -> Value.t -> M := @@ -1026,6 +1073,26 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do @@ -1083,7 +1150,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let ommers_hashes := - (* At expr: unsupported node type: ListComp *) in + Constant.str "(* At expr: unsupported node type: ListComp *)" in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1114,19 +1181,19 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let recent_canonical_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| BinOp.add (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| BinOp.add (| M.get_name (| globals, "MAX_OMMER_DEPTH" |), Constant.int 1 - |) |) |) in + |) |), Constant.None_ |) |) in let recent_canonical_block_hashes := - (* At expr: unsupported node type: SetComp *) in + Constant.str "(* At expr: unsupported node type: SetComp *)" in (* At stmt: unsupported node type: AnnAssign *) For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_canonical_blocks" |) do let recent_ommers_hashes := M.call (| M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), make_list [ - (* At expr: unsupported node type: SetComp *) + Constant.str "(* At expr: unsupported node type: SetComp *)" ], make_dict [] |) in @@ -1560,6 +1627,7 @@ Definition process_transaction : Value.t -> Value.t -> M := EndFor. let _ := M.return_ (| make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |) ] + |) in M.pure Constant.None_)). Definition validate_transaction : Value.t -> Value.t -> M := @@ -1614,6 +1682,7 @@ Definition validate_transaction : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := @@ -1645,6 +1714,20 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := Constant.int 0 in For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "byte" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let data_cost := BinOp.add M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in @@ -1662,6 +1745,7 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition recover_sender : Value.t -> Value.t -> M := @@ -1777,10 +1861,11 @@ Definition recover_sender : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12 |) + |), M.slice (| Constant.int 12, Constant.int 32 |) |) ], make_dict [] |) + |) in M.pure Constant.None_)). Definition signing_hash : Value.t -> Value.t -> M := @@ -1817,6 +1902,7 @@ Definition signing_hash : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition compute_header_hash : Value.t -> Value.t -> M := @@ -1867,6 +1953,7 @@ Definition compute_header_hash : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition check_gas_limit : Value.t -> Value.t -> M := @@ -1905,16 +1992,65 @@ Definition check_gas_limit : Value.t -> Value.t -> M := M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "gas_limit" |), + BinOp.add (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "gas_limit" |), + BinOp.sub (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "gas_limit" |), + M.get_name (| globals, "GAS_LIMIT_MINIMUM" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| Constant.bool true + |) in M.pure Constant.None_)). Definition calculate_block_difficulty : Value.t -> Value.t -> M := @@ -1961,6 +2097,25 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "block_timestamp" |), + BinOp.add (| + M.get_name (| globals, "parent_timestamp" |), + Constant.int 13 + |) + |), + (* then *) + ltac:(M.monadic ( + let difficulty := + BinOp.add (| + M.get_name (| globals, "parent_difficulty" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let difficulty := BinOp.sub (| M.get_name (| globals, "parent_difficulty" |), @@ -1983,6 +2138,26 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := Constant.int 2 |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "num_bomb_periods" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let difficulty := BinOp.add + BinOp.pow (| + Constant.int 2, + M.get_name (| globals, "num_bomb_periods" |) + |) + BinOp.pow (| + Constant.int 2, + M.get_name (| globals, "num_bomb_periods" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1994,4 +2169,5 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/fork_types.v b/CoqOfPython/ethereum/frontier/fork_types.v index 5c7dac3..cc8e4a1 100644 --- a/CoqOfPython/ethereum/frontier/fork_types.v +++ b/CoqOfPython/ethereum/frontier/fork_types.v @@ -21,29 +21,29 @@ Require dataclasses. Axiom dataclasses_dataclass : IsGlobalAlias globals dataclasses.globals "dataclass". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes20 : - IsGlobalAlias globals base_types.globals "Bytes20". -Axiom base_types_Bytes256 : - IsGlobalAlias globals base_types.globals "Bytes256". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require crypto.hash. -Axiom crypto_hash_Hash32 : - IsGlobalAlias globals crypto.hash.globals "Hash32". -Axiom crypto_hash_keccak256 : - IsGlobalAlias globals crypto.hash.globals "keccak256". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes20 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes20". +Axiom ethereum_base_types_Bytes256 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) @@ -98,4 +98,5 @@ Definition encode_account : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/state.v b/CoqOfPython/ethereum/frontier/state.v index 2ba095e..e984742 100644 --- a/CoqOfPython/ethereum/frontier/state.v +++ b/CoqOfPython/ethereum/frontier/state.v @@ -54,29 +54,29 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require fork_types. -Axiom fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". -Axiom fork_types_Account : - IsGlobalAlias globals fork_types.globals "Account". -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". - -Require trie. -Axiom trie_EMPTY_TRIE_ROOT : - IsGlobalAlias globals trie.globals "EMPTY_TRIE_ROOT". -Axiom trie_Trie : - IsGlobalAlias globals trie.globals "Trie". -Axiom trie_copy_trie : - IsGlobalAlias globals trie.globals "copy_trie". -Axiom trie_root : - IsGlobalAlias globals trie.globals "root". -Axiom trie_trie_get : - IsGlobalAlias globals trie.globals "trie_get". -Axiom trie_trie_set : - IsGlobalAlias globals trie.globals "trie_set". +Require ethereum.frontier.fork_types. +Axiom ethereum_frontier_fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals ethereum.frontier.fork_types.globals "EMPTY_ACCOUNT". +Axiom ethereum_frontier_fork_types_Account : + IsGlobalAlias globals ethereum.frontier.fork_types.globals "Account". +Axiom ethereum_frontier_fork_types_Address : + IsGlobalAlias globals ethereum.frontier.fork_types.globals "Address". +Axiom ethereum_frontier_fork_types_Root : + IsGlobalAlias globals ethereum.frontier.fork_types.globals "Root". + +Require ethereum.frontier.trie. +Axiom ethereum_frontier_trie_EMPTY_TRIE_ROOT : + IsGlobalAlias globals ethereum.frontier.trie.globals "EMPTY_TRIE_ROOT". +Axiom ethereum_frontier_trie_Trie : + IsGlobalAlias globals ethereum.frontier.trie.globals "Trie". +Axiom ethereum_frontier_trie_copy_trie : + IsGlobalAlias globals ethereum.frontier.trie.globals "copy_trie". +Axiom ethereum_frontier_trie_root : + IsGlobalAlias globals ethereum.frontier.trie.globals "root". +Axiom ethereum_frontier_trie_trie_get : + IsGlobalAlias globals ethereum.frontier.trie.globals "trie_get". +Axiom ethereum_frontier_trie_trie_set : + IsGlobalAlias globals ethereum.frontier.trie.globals "trie_set". Definition State : Value.t := builtins.make_klass @@ -123,7 +123,7 @@ Definition begin_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) ], make_dict [] - |); (* At expr: unsupported node type: DictComp *) ] + |); Constant.str "(* At expr: unsupported node type: DictComp *)" ] ], make_dict [] |) in @@ -201,8 +201,27 @@ Definition get_account : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "account" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "account" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_ACCOUNT" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -237,6 +256,7 @@ Definition get_account_optional : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "account" |) + |) in M.pure Constant.None_)). Definition set_account : Value.t -> Value.t -> M := @@ -316,6 +336,18 @@ Definition destroy_storage : Value.t -> Value.t -> M := Address of account whose storage is to be deleted. " in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -350,6 +382,26 @@ Definition get_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "trie" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let value := @@ -371,6 +423,7 @@ Definition get_storage : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "value" |) + |) in M.pure Constant.None_)). Definition set_storage : Value.t -> Value.t -> M := @@ -411,6 +464,27 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "trie" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let trie := + M.call (| + M.get_name (| globals, "Trie" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), + M.get_name (| globals, "trie" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -423,6 +497,18 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + {} + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -447,8 +533,29 @@ Definition storage_root : Value.t -> Value.t -> M := " in let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_TRIE_ROOT" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -479,6 +586,7 @@ Definition state_root : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition account_exists : Value.t -> Value.t -> M := @@ -511,6 +619,7 @@ Definition account_exists : Value.t -> Value.t -> M := |), Constant.None_ |) + |) in M.pure Constant.None_)). Definition account_has_code_or_nonce : Value.t -> Value.t -> M := @@ -560,6 +669,7 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition modify_state : Value.t -> Value.t -> M := @@ -665,6 +775,30 @@ Definition touch_account : Value.t -> Value.t -> M := The address of the account that need to initialised. " in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "account_exists" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "EMPTY_ACCOUNT" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/transactions.v b/CoqOfPython/ethereum/frontier/transactions.v index c9ea3bf..bbcdf4d 100644 --- a/CoqOfPython/ethereum/frontier/transactions.v +++ b/CoqOfPython/ethereum/frontier/transactions.v @@ -17,21 +17,21 @@ Require typing. Axiom typing_Union : IsGlobalAlias globals typing.globals "Union". -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes0 : - IsGlobalAlias globals base_types.globals "Bytes0". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.frontier.fork_types. +Axiom ethereum_frontier_fork_types_Address : + IsGlobalAlias globals ethereum.frontier.fork_types.globals "Address". Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( Constant.int 21000 diff --git a/CoqOfPython/ethereum/frontier/trie.v b/CoqOfPython/ethereum/frontier/trie.v index 6805926..509578c 100644 --- a/CoqOfPython/ethereum/frontier/trie.v +++ b/CoqOfPython/ethereum/frontier/trie.v @@ -62,37 +62,37 @@ Require ethereum.utils.hexadecimal. Axiom ethereum_utils_hexadecimal_hex_to_bytes : IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require blocks. -Axiom blocks_Receipt : - IsGlobalAlias globals blocks.globals "Receipt". - -Require fork_types. -Axiom fork_types_Account : - IsGlobalAlias globals fork_types.globals "Account". -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". -Axiom fork_types_encode_account : - IsGlobalAlias globals fork_types.globals "encode_account". - -Require transactions. -Axiom transactions_Transaction : - IsGlobalAlias globals transactions.globals "Transaction". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.frontier.blocks. +Axiom ethereum_frontier_blocks_Receipt : + IsGlobalAlias globals ethereum.frontier.blocks.globals "Receipt". + +Require ethereum.frontier.fork_types. +Axiom ethereum_frontier_fork_types_Account : + IsGlobalAlias globals ethereum.frontier.fork_types.globals "Account". +Axiom ethereum_frontier_fork_types_Address : + IsGlobalAlias globals ethereum.frontier.fork_types.globals "Address". +Axiom ethereum_frontier_fork_types_Root : + IsGlobalAlias globals ethereum.frontier.fork_types.globals "Root". +Axiom ethereum_frontier_fork_types_encode_account : + IsGlobalAlias globals ethereum.frontier.fork_types.globals "encode_account". + +Require ethereum.frontier.transactions. +Axiom ethereum_frontier_transactions_Transaction : + IsGlobalAlias globals ethereum.frontier.transactions.globals "Transaction". Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -198,16 +198,99 @@ Definition encode_internal_node : Value.t -> Value.t -> M := " in (* At stmt: unsupported node type: AnnAssign *) let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "node" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + Constant.bytes "" in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "LeafNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "rest_of_key" |); + Constant.bool true + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "ExtensionNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "key_segment" |); + Constant.bool false + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "BranchNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + BinOp.add (| + M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "value" |) + ] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ - (* At expr: unsupported node type: JoinedStr *) + Constant.str "(* At expr: unsupported node type: JoinedStr *)" ], make_dict [] - |)) + |)) |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -225,6 +308,26 @@ Definition encode_internal_node : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded" |) + ], + make_dict [] + |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "unencoded" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_name (| globals, "keccak256" |), @@ -233,6 +336,7 @@ Definition encode_internal_node : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -246,15 +350,93 @@ Definition encode_node : Value.t -> Value.t -> M := Currently mostly an unimplemented stub. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| + M.get_name (| globals, "storage_root" |), + Constant.None_ + |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "encode_account" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "storage_root" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + make_tuple [ M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "U256" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "cast" |), + make_list [ + M.get_field (| M.get_name (| globals, "rlp" |), "RLP" |); + M.get_name (| globals, "node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "node" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ - (* At expr: unsupported node type: JoinedStr *) + Constant.str "(* At expr: unsupported node type: JoinedStr *)" ], make_dict [] - |)) + |)) |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -306,6 +488,7 @@ Definition copy_trie : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition trie_set : Value.t -> Value.t -> M := @@ -327,6 +510,32 @@ Definition trie_set : Value.t -> Value.t -> M := Node to insert at `key`. " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + M.get_field (| M.get_name (| globals, "trie" |), "default" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "key" |), + M.get_field (| M.get_name (| globals, "trie" |), "_data" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), M.get_name (| globals, "value" |) @@ -364,6 +573,7 @@ Definition trie_get : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition common_prefix_length : Value.t -> Value.t -> M := @@ -386,6 +596,34 @@ Definition common_prefix_length : Value.t -> Value.t -> M := make_dict [] |) do let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), + M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -397,6 +635,7 @@ Definition common_prefix_length : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition nibble_list_to_compact : Value.t -> Value.t -> M := @@ -442,6 +681,71 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + Constant.int 2 + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.mult (| + Constant.int 16, + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "is_leaf" |) + |) + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ @@ -503,6 +807,7 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition bytes_to_nibble_list : Value.t -> Value.t -> M := @@ -580,6 +885,7 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition _prepare_trie : Value.t -> Value.t -> M := @@ -609,6 +915,48 @@ Definition _prepare_trie : Value.t -> Value.t -> M := make_dict [] |) do let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| + M.get_name (| globals, "get_storage_root" |), + Constant.None_ + |) |) in + let address := + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |); + M.call (| + M.get_name (| globals, "get_storage_root" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let encoded_value := M.call (| M.get_name (| globals, "encode_node" |), @@ -632,6 +980,22 @@ Definition _prepare_trie : Value.t -> Value.t -> M := |) in (* At stmt: unsupported node type: AnnAssign *) let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "trie" |), "secured" |), + (* then *) + ltac:(M.monadic ( + let key := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let key := M.get_name (| globals, "preimage" |) in M.pure Constant.None_ @@ -649,6 +1013,7 @@ Definition _prepare_trie : Value.t -> Value.t -> M := EndFor. let _ := M.return_ (| M.get_name (| globals, "mapped" |) + |) in M.pure Constant.None_)). Definition root : Value.t -> Value.t -> M := @@ -702,6 +1067,44 @@ Definition root : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -718,6 +1121,7 @@ Definition root : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -744,6 +1148,26 @@ Definition patricialize : Value.t -> Value.t -> M := Root node of `obj`. " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let arbitrary_key := @@ -761,10 +1185,39 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), + Constant.int 1 + |), + (* then *) + ltac:(M.monadic ( + let leaf := + M.call (| + M.get_name (| globals, "LeafNode" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |); + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "leaf" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let substring := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |) |) in + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) in let prefix_length := M.call (| M.get_name (| globals, "len" |), @@ -783,7 +1236,7 @@ Definition patricialize : Value.t -> Value.t -> M := M.get_name (| globals, "common_prefix_length" |), make_list [ M.get_name (| globals, "substring" |); - M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) + M.get_subscript (| M.get_name (| globals, "key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) ], make_dict [] |) @@ -791,10 +1244,64 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "prefix_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "prefix_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let prefix := + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ExtensionNode" |), + make_list [ + M.get_name (| globals, "prefix" |); + M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_name (| globals, "obj" |); + BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) @@ -817,6 +1324,44 @@ Definition patricialize : Value.t -> Value.t -> M := Constant.bytes "" in For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |), + M.get_name (| globals, "level" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "AssertionError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) @@ -828,9 +1373,10 @@ Definition patricialize : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "BranchNode" |), make_list [ - (* At expr: unsupported node type: ListComp *); + Constant.str "(* At expr: unsupported node type: ListComp *)"; M.get_name (| globals, "value" |) ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/utils/address.v b/CoqOfPython/ethereum/frontier/utils/address.v index 4ff0504..6d1f67a 100644 --- a/CoqOfPython/ethereum/frontier/utils/address.v +++ b/CoqOfPython/ethereum/frontier/utils/address.v @@ -35,13 +35,13 @@ Require ethereum.utils.byte. Axiom ethereum_utils_byte_left_pad_zero_bytes : IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.frontier.fork_types. +Axiom ethereum_frontier_fork_types_Address : + IsGlobalAlias globals ethereum.frontier.fork_types.globals "Address". Definition to_address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -67,10 +67,11 @@ Definition to_address : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), make_list [], make_dict [] - |), UnOp.sub (| Constant.int 20 |) |) + |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) ], make_dict [] |) + |) in M.pure Constant.None_)). Definition compute_contract_address : Value.t -> Value.t -> M := @@ -110,7 +111,7 @@ Definition compute_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -128,4 +129,5 @@ Definition compute_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/utils/hexadecimal.v b/CoqOfPython/ethereum/frontier/utils/hexadecimal.v index b471e39..c2f05ff 100644 --- a/CoqOfPython/ethereum/frontier/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/frontier/utils/hexadecimal.v @@ -22,13 +22,13 @@ Require ethereum.utils.hexadecimal. Axiom ethereum_utils_hexadecimal_remove_hex_prefix : IsGlobalAlias globals ethereum.utils.hexadecimal.globals "remove_hex_prefix". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". +Require ethereum.frontier.fork_types. +Axiom ethereum_frontier_fork_types_Address : + IsGlobalAlias globals ethereum.frontier.fork_types.globals "Address". +Axiom ethereum_frontier_fork_types_Bloom : + IsGlobalAlias globals ethereum.frontier.fork_types.globals "Bloom". +Axiom ethereum_frontier_fork_types_Root : + IsGlobalAlias globals ethereum.frontier.fork_types.globals "Root". Definition hex_to_root : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -66,6 +66,7 @@ Definition hex_to_root : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition hex_to_bloom : Value.t -> Value.t -> M := @@ -104,6 +105,7 @@ Definition hex_to_bloom : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition hex_to_address : Value.t -> Value.t -> M := @@ -149,4 +151,5 @@ Definition hex_to_address : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/utils/message.v b/CoqOfPython/ethereum/frontier/utils/message.v index c42bcc8..86d0cf9 100644 --- a/CoqOfPython/ethereum/frontier/utils/message.v +++ b/CoqOfPython/ethereum/frontier/utils/message.v @@ -33,23 +33,23 @@ Axiom ethereum_base_types_Bytes0 : Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.frontier.fork_types. +Axiom ethereum_frontier_fork_types_Address : + IsGlobalAlias globals ethereum.frontier.fork_types.globals "Address". -Require state. -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". +Require ethereum.frontier.state. +Axiom ethereum_frontier_state_get_account : + IsGlobalAlias globals ethereum.frontier.state.globals "get_account". -Require vm. -Axiom vm_Environment : - IsGlobalAlias globals vm.globals "Environment". -Axiom vm_Message : - IsGlobalAlias globals vm.globals "Message". +Require ethereum.frontier.vm.__init__. +Axiom ethereum_frontier_vm___init___Environment : + IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "Environment". +Axiom ethereum_frontier_vm___init___Message : + IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "Message". -Require address. -Axiom address_compute_contract_address : - IsGlobalAlias globals address.globals "compute_contract_address". +Require ethereum.frontier.utils.address. +Axiom ethereum_frontier_utils_address_compute_contract_address : + IsGlobalAlias globals ethereum.frontier.utils.address.globals "compute_contract_address". Definition prepare_message : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -82,14 +82,108 @@ Definition prepare_message : Value.t -> Value.t -> M := Items containing contract creation or message call specific data. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Bytes0" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.call (| + M.get_name (| globals, "compute_contract_address" |), + make_list [ + M.get_name (| globals, "caller" |); + BinOp.sub (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "caller" |) + ], + make_dict [] + |), "nonce" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let msg_data := + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) in + let code := + M.get_name (| globals, "data" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.get_name (| globals, "target" |) in + let msg_data := + M.get_name (| globals, "data" |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "target" |) + ], + make_dict [] + |), "code" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "code_address" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let code_address := + M.get_name (| globals, "target" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "Target must be address or empty bytes" ], make_dict [] - |)) + |)) |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -100,4 +194,5 @@ Definition prepare_message : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/vm/__init__.v b/CoqOfPython/ethereum/frontier/vm/__init__.v index 49bcb40..1680b9c 100644 --- a/CoqOfPython/ethereum/frontier/vm/__init__.v +++ b/CoqOfPython/ethereum/frontier/vm/__init__.v @@ -48,17 +48,17 @@ Require ethereum.crypto.hash. Axiom ethereum_crypto_hash_Hash32 : IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". +Require ethereum.frontier.blocks. +Axiom ethereum_frontier_blocks_Log : + IsGlobalAlias globals ethereum.frontier.blocks.globals "Log". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.frontier.fork_types. +Axiom ethereum_frontier_fork_types_Address : + IsGlobalAlias globals ethereum.frontier.fork_types.globals "Address". -Require state. -Axiom state_State : - IsGlobalAlias globals state.globals "State". +Require ethereum.frontier.state. +Axiom ethereum_frontier_state_State : + IsGlobalAlias globals ethereum.frontier.state.globals "State". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] diff --git a/CoqOfPython/ethereum/frontier/vm/gas.v b/CoqOfPython/ethereum/frontier/vm/gas.v index eef500a..63b538c 100644 --- a/CoqOfPython/ethereum/frontier/vm/gas.v +++ b/CoqOfPython/ethereum/frontier/vm/gas.v @@ -43,23 +43,23 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.frontier.fork_types. +Axiom ethereum_frontier_fork_types_Address : + IsGlobalAlias globals ethereum.frontier.fork_types.globals "Address". -Require state. -Axiom state_State : - IsGlobalAlias globals state.globals "State". -Axiom state_account_exists : - IsGlobalAlias globals state.globals "account_exists". +Require ethereum.frontier.state. +Axiom ethereum_frontier_state_State : + IsGlobalAlias globals ethereum.frontier.state.globals "State". +Axiom ethereum_frontier_state_account_exists : + IsGlobalAlias globals ethereum.frontier.state.globals "account_exists". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.frontier.vm.__init__. +Axiom ethereum_frontier_vm___init___Evm : + IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "Evm". -Require exceptions. -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". +Require ethereum.frontier.vm.exceptions. +Axiom ethereum_frontier_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.frontier.vm.exceptions.globals "OutOfGasError". Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -480,6 +480,18 @@ Definition charge_gas : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "amount" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign_op (| BinOp.sub, M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), @@ -595,6 +607,18 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := |) in For make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ] in M.get_name (| globals, "extensions" |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "size" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let before_size := @@ -629,6 +653,18 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let size_to_extend := BinOp.add @@ -677,6 +713,7 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition calculate_message_call_gas : Value.t -> Value.t -> M := @@ -701,41 +738,49 @@ Definition calculate_message_call_gas : Value.t -> Value.t -> M := message_call_gas: `MessageCallGas` " in let create_gas_cost := - (* if *) -M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "to" |) - ], - make_dict [] - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "to" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "GAS_NEW_ACCOUNT" |) + )) |) in let transfer_gas_cost := - (* if *) -M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "GAS_CALL_VALUE" |) + )) |) in let cost := BinOp.add (| BinOp.add (| @@ -748,15 +793,22 @@ M.call (| M.get_name (| globals, "transfer_gas_cost" |) |) in let stipend := - (* if *) -M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), -(* then *) -ltac:(M.monadic ( -M.get_name (| globals, "gas" |) in + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( +M.get_name (| globals, "gas" |) + (* else *) + )), ltac:(M.monadic ( +BinOp.add (| + M.get_name (| globals, "GAS_CALL_STIPEND" |), + M.get_name (| globals, "gas" |) + |) + )) |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "MessageCallGas" |), @@ -766,4 +818,5 @@ M.get_name (| globals, "gas" |) in ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/__init__.v b/CoqOfPython/ethereum/frontier/vm/instructions/__init__.v index e5bebd7..46647fa 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/__init__.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/__init__.v @@ -26,53 +26,53 @@ Axiom typing_Callable : Axiom typing_Dict : IsGlobalAlias globals typing.globals "Dict". -Require __init__. -Axiom __init___arithmetic : - IsGlobalAlias globals __init__.globals "arithmetic". +Require ethereum.frontier.vm.instructions.__init__. +Axiom ethereum_frontier_vm_instructions___init___arithmetic : + IsGlobalAlias globals ethereum.frontier.vm.instructions.__init__.globals "arithmetic". -Require __init__. -Axiom __init___bitwise : - IsGlobalAlias globals __init__.globals "bitwise". +Require ethereum.frontier.vm.instructions.__init__. +Axiom ethereum_frontier_vm_instructions___init___bitwise : + IsGlobalAlias globals ethereum.frontier.vm.instructions.__init__.globals "bitwise". -Require __init__. -Axiom __init___block : - IsGlobalAlias globals __init__.globals "block". +Require ethereum.frontier.vm.instructions.__init__. +Axiom ethereum_frontier_vm_instructions___init___block : + IsGlobalAlias globals ethereum.frontier.vm.instructions.__init__.globals "block". -Require __init__. -Axiom __init___comparison : - IsGlobalAlias globals __init__.globals "comparison". +Require ethereum.frontier.vm.instructions.__init__. +Axiom ethereum_frontier_vm_instructions___init___comparison : + IsGlobalAlias globals ethereum.frontier.vm.instructions.__init__.globals "comparison". -Require __init__. -Axiom __init___control_flow : - IsGlobalAlias globals __init__.globals "control_flow". +Require ethereum.frontier.vm.instructions.__init__. +Axiom ethereum_frontier_vm_instructions___init___control_flow : + IsGlobalAlias globals ethereum.frontier.vm.instructions.__init__.globals "control_flow". -Require __init__. -Axiom __init___environment : - IsGlobalAlias globals __init__.globals "environment". +Require ethereum.frontier.vm.instructions.__init__. +Axiom ethereum_frontier_vm_instructions___init___environment : + IsGlobalAlias globals ethereum.frontier.vm.instructions.__init__.globals "environment". -Require __init__. -Axiom __init___keccak : - IsGlobalAlias globals __init__.globals "keccak". +Require ethereum.frontier.vm.instructions.__init__. +Axiom ethereum_frontier_vm_instructions___init___keccak : + IsGlobalAlias globals ethereum.frontier.vm.instructions.__init__.globals "keccak". -Require __init__. -Axiom __init___log : - IsGlobalAlias globals __init__.globals "log". +Require ethereum.frontier.vm.instructions.__init__. +Axiom ethereum_frontier_vm_instructions___init___log : + IsGlobalAlias globals ethereum.frontier.vm.instructions.__init__.globals "log". -Require __init__. -Axiom __init___memory : - IsGlobalAlias globals __init__.globals "memory". +Require ethereum.frontier.vm.instructions.__init__. +Axiom ethereum_frontier_vm_instructions___init___memory : + IsGlobalAlias globals ethereum.frontier.vm.instructions.__init__.globals "memory". -Require __init__. -Axiom __init___stack : - IsGlobalAlias globals __init__.globals "stack". +Require ethereum.frontier.vm.instructions.__init__. +Axiom ethereum_frontier_vm_instructions___init___stack : + IsGlobalAlias globals ethereum.frontier.vm.instructions.__init__.globals "stack". -Require __init__. -Axiom __init___storage : - IsGlobalAlias globals __init__.globals "storage". +Require ethereum.frontier.vm.instructions.__init__. +Axiom ethereum_frontier_vm_instructions___init___storage : + IsGlobalAlias globals ethereum.frontier.vm.instructions.__init__.globals "storage". -Require __init__. -Axiom __init___system : - IsGlobalAlias globals __init__.globals "system". +Require ethereum.frontier.vm.instructions.__init__. +Axiom ethereum_frontier_vm_instructions___init___system : + IsGlobalAlias globals ethereum.frontier.vm.instructions.__init__.globals "system". Definition Ops : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/frontier/vm/instructions/arithmetic.v index 581ba5d..ad992d8 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/arithmetic.v @@ -31,29 +31,29 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_get_sign : IsGlobalAlias globals ethereum.utils.numeric.globals "get_sign". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_EXPONENTIATION : - IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION". -Axiom gas_GAS_EXPONENTIATION_PER_BYTE : - IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION_PER_BYTE". -Axiom gas_GAS_LOW : - IsGlobalAlias globals gas.globals "GAS_LOW". -Axiom gas_GAS_MID : - IsGlobalAlias globals gas.globals "GAS_MID". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.frontier.vm.__init__. +Axiom ethereum_frontier_vm___init___Evm : + IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "Evm". + +Require ethereum.frontier.vm.gas. +Axiom ethereum_frontier_vm_gas_GAS_EXPONENTIATION : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_EXPONENTIATION". +Axiom ethereum_frontier_vm_gas_GAS_EXPONENTIATION_PER_BYTE : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_EXPONENTIATION_PER_BYTE". +Axiom ethereum_frontier_vm_gas_GAS_LOW : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_LOW". +Axiom ethereum_frontier_vm_gas_GAS_MID : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_MID". +Axiom ethereum_frontier_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_frontier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "charge_gas". + +Require ethereum.frontier.vm.stack. +Axiom ethereum_frontier_vm_stack_pop : + IsGlobalAlias globals ethereum.frontier.vm.stack.globals "pop". +Axiom ethereum_frontier_vm_stack_push : + IsGlobalAlias globals ethereum.frontier.vm.stack.globals "push". Definition add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -273,6 +273,25 @@ Definition div : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "divisor" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let quotient := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let quotient := BinOp.floor_div (| M.get_name (| globals, "dividend" |), @@ -341,7 +360,41 @@ Definition sdiv : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "divisor" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let quotient := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_name (| globals, "dividend" |), + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "divisor" |), + UnOp.sub (| Constant.int 1 |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let quotient := + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let sign := M.call (| M.get_name (| globals, "get_sign" |), @@ -436,6 +489,25 @@ Definition mod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "y" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let remainder := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let remainder := BinOp.mod_ (| M.get_name (| globals, "x" |), @@ -504,6 +576,19 @@ Definition smod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "y" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let remainder := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let remainder := BinOp.mult (| M.call (| @@ -617,6 +702,25 @@ Definition addmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "z" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -712,6 +816,25 @@ Definition mulmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "z" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -881,6 +1004,19 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "byte_num" |), + Constant.int 31 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.get_name (| globals, "value" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let value_bytes := M.call (| M.get_name (| globals, "bytes" |), @@ -894,7 +1030,7 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let value_bytes := - M.get_subscript (| M.get_name (| globals, "value_bytes" |), BinOp.sub (| + M.get_subscript (| M.get_name (| globals, "value_bytes" |), M.slice (| BinOp.sub (| Constant.int 31, M.call (| M.get_name (| globals, "int" |), @@ -903,13 +1039,32 @@ Definition signextend : Value.t -> Value.t -> M := ], make_dict [] |) - |) |) in + |), Constant.None_ |) |) in let sign_bit := BinOp.r_shift (| M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), Constant.int 7 |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "sign_bit" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "value_bytes" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let num_bytes_prepend := BinOp.sub (| Constant.int 32, diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/bitwise.v b/CoqOfPython/ethereum/frontier/vm/instructions/bitwise.v index f38e7aa..a640fd7 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/bitwise.v @@ -21,21 +21,21 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.frontier.vm.__init__. +Axiom ethereum_frontier_vm___init___Evm : + IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.frontier.vm.gas. +Axiom ethereum_frontier_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_frontier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "charge_gas". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.frontier.vm.stack. +Axiom ethereum_frontier_vm_stack_pop : + IsGlobalAlias globals ethereum.frontier.vm.stack.globals "pop". +Axiom ethereum_frontier_vm_stack_push : + IsGlobalAlias globals ethereum.frontier.vm.stack.globals "push". Definition bitwise_and : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -285,6 +285,25 @@ Definition get_byte : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "byte_index" |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let extra_bytes_to_right := BinOp.sub (| Constant.int 31, diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/block.v b/CoqOfPython/ethereum/frontier/vm/instructions/block.v index 90be45c..64df956 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/block.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/block.v @@ -21,23 +21,23 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_BLOCK_HASH : - IsGlobalAlias globals gas.globals "GAS_BLOCK_HASH". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.frontier.vm.__init__. +Axiom ethereum_frontier_vm___init___Evm : + IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "Evm". + +Require ethereum.frontier.vm.gas. +Axiom ethereum_frontier_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_BASE". +Axiom ethereum_frontier_vm_gas_GAS_BLOCK_HASH : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_BLOCK_HASH". +Axiom ethereum_frontier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "charge_gas". + +Require ethereum.frontier.vm.stack. +Axiom ethereum_frontier_vm_stack_pop : + IsGlobalAlias globals ethereum.frontier.vm.stack.globals "pop". +Axiom ethereum_frontier_vm_stack_push : + IsGlobalAlias globals ethereum.frontier.vm.stack.globals "push". Definition block_hash : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -69,6 +69,30 @@ Definition block_hash : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt_e (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + M.get_name (| globals, "block_number" |) + |), + ltac:(M.monadic ( + Compare.gt (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + BinOp.add (| + M.get_name (| globals, "block_number" |), + Constant.int 256 + |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let hash := + Constant.bytes "00" in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let hash := M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/comparison.v b/CoqOfPython/ethereum/frontier/vm/instructions/comparison.v index b8529d8..f809174 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/comparison.v @@ -21,21 +21,21 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.frontier.vm.__init__. +Axiom ethereum_frontier_vm___init___Evm : + IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.frontier.vm.gas. +Axiom ethereum_frontier_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_frontier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "charge_gas". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.frontier.vm.stack. +Axiom ethereum_frontier_vm_stack_pop : + IsGlobalAlias globals ethereum.frontier.vm.stack.globals "pop". +Axiom ethereum_frontier_vm_stack_push : + IsGlobalAlias globals ethereum.frontier.vm.stack.globals "push". Definition less_than : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/control_flow.v b/CoqOfPython/ethereum/frontier/vm/instructions/control_flow.v index d4e4eae..bc51f99 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/control_flow.v @@ -23,31 +23,31 @@ Axiom ethereum_base_types_U256 : Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require vm.gas. -Axiom vm_gas_GAS_BASE : - IsGlobalAlias globals vm.gas.globals "GAS_BASE". -Axiom vm_gas_GAS_HIGH : - IsGlobalAlias globals vm.gas.globals "GAS_HIGH". -Axiom vm_gas_GAS_JUMPDEST : - IsGlobalAlias globals vm.gas.globals "GAS_JUMPDEST". -Axiom vm_gas_GAS_MID : - IsGlobalAlias globals vm.gas.globals "GAS_MID". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.frontier.vm.gas. +Axiom ethereum_frontier_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_BASE". +Axiom ethereum_frontier_vm_gas_GAS_HIGH : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_HIGH". +Axiom ethereum_frontier_vm_gas_GAS_JUMPDEST : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_JUMPDEST". +Axiom ethereum_frontier_vm_gas_GAS_MID : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_MID". +Axiom ethereum_frontier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "charge_gas". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.frontier.vm.__init__. +Axiom ethereum_frontier_vm___init___Evm : + IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "Evm". -Require exceptions. -Axiom exceptions_InvalidJumpDestError : - IsGlobalAlias globals exceptions.globals "InvalidJumpDestError". +Require ethereum.frontier.vm.exceptions. +Axiom ethereum_frontier_vm_exceptions_InvalidJumpDestError : + IsGlobalAlias globals ethereum.frontier.vm.exceptions.globals "InvalidJumpDestError". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.frontier.vm.stack. +Axiom ethereum_frontier_vm_stack_pop : + IsGlobalAlias globals ethereum.frontier.vm.stack.globals "pop". +Axiom ethereum_frontier_vm_stack_push : + IsGlobalAlias globals ethereum.frontier.vm.stack.globals "push". Definition stop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -109,6 +109,18 @@ Definition jump : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "jump_dest" |), + M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -168,7 +180,35 @@ Definition jumpi : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "conditional_value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let destination := + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "jump_dest" |), + M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let destination := M.get_name (| globals, "jump_dest" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/environment.v b/CoqOfPython/ethereum/frontier/vm/instructions/environment.v index 366e59a..02d92cd 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/environment.v @@ -27,45 +27,45 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require state. -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". - -Require utils.address. -Axiom utils_address_to_address : - IsGlobalAlias globals utils.address.globals "to_address". - -Require vm.memory. -Axiom vm_memory_buffer_read : - IsGlobalAlias globals vm.memory.globals "buffer_read". -Axiom vm_memory_memory_write : - IsGlobalAlias globals vm.memory.globals "memory_write". - -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_BALANCE : - IsGlobalAlias globals gas.globals "GAS_BALANCE". -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_COPY : - IsGlobalAlias globals gas.globals "GAS_COPY". -Axiom gas_GAS_EXTERNAL : - IsGlobalAlias globals gas.globals "GAS_EXTERNAL". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.frontier.state. +Axiom ethereum_frontier_state_get_account : + IsGlobalAlias globals ethereum.frontier.state.globals "get_account". + +Require ethereum.frontier.utils.address. +Axiom ethereum_frontier_utils_address_to_address : + IsGlobalAlias globals ethereum.frontier.utils.address.globals "to_address". + +Require ethereum.frontier.vm.memory. +Axiom ethereum_frontier_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.frontier.vm.memory.globals "buffer_read". +Axiom ethereum_frontier_vm_memory_memory_write : + IsGlobalAlias globals ethereum.frontier.vm.memory.globals "memory_write". + +Require ethereum.frontier.vm.__init__. +Axiom ethereum_frontier_vm___init___Evm : + IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "Evm". + +Require ethereum.frontier.vm.gas. +Axiom ethereum_frontier_vm_gas_GAS_BALANCE : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_BALANCE". +Axiom ethereum_frontier_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_BASE". +Axiom ethereum_frontier_vm_gas_GAS_COPY : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_COPY". +Axiom ethereum_frontier_vm_gas_GAS_EXTERNAL : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_EXTERNAL". +Axiom ethereum_frontier_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_frontier_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_frontier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "charge_gas". + +Require ethereum.frontier.vm.stack. +Axiom ethereum_frontier_vm_stack_pop : + IsGlobalAlias globals ethereum.frontier.vm.stack.globals "pop". +Axiom ethereum_frontier_vm_stack_push : + IsGlobalAlias globals ethereum.frontier.vm.stack.globals "push". Definition address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/keccak.v b/CoqOfPython/ethereum/frontier/vm/instructions/keccak.v index 2c4b10e..9ed220d 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/keccak.v @@ -31,29 +31,29 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_KECCAK256 : - IsGlobalAlias globals gas.globals "GAS_KECCAK256". -Axiom gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.frontier.vm.__init__. +Axiom ethereum_frontier_vm___init___Evm : + IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "Evm". + +Require ethereum.frontier.vm.gas. +Axiom ethereum_frontier_vm_gas_GAS_KECCAK256 : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_KECCAK256". +Axiom ethereum_frontier_vm_gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_KECCAK256_WORD". +Axiom ethereum_frontier_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_frontier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "charge_gas". + +Require ethereum.frontier.vm.memory. +Axiom ethereum_frontier_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.frontier.vm.memory.globals "memory_read_bytes". + +Require ethereum.frontier.vm.stack. +Axiom ethereum_frontier_vm_stack_pop : + IsGlobalAlias globals ethereum.frontier.vm.stack.globals "pop". +Axiom ethereum_frontier_vm_stack_push : + IsGlobalAlias globals ethereum.frontier.vm.stack.globals "push". Definition keccak : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/log.v b/CoqOfPython/ethereum/frontier/vm/instructions/log.v index ab196bc..51783fc 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/log.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/log.v @@ -25,33 +25,33 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". - -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_LOG : - IsGlobalAlias globals gas.globals "GAS_LOG". -Axiom gas_GAS_LOG_DATA : - IsGlobalAlias globals gas.globals "GAS_LOG_DATA". -Axiom gas_GAS_LOG_TOPIC : - IsGlobalAlias globals gas.globals "GAS_LOG_TOPIC". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". +Require ethereum.frontier.blocks. +Axiom ethereum_frontier_blocks_Log : + IsGlobalAlias globals ethereum.frontier.blocks.globals "Log". + +Require ethereum.frontier.vm.__init__. +Axiom ethereum_frontier_vm___init___Evm : + IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "Evm". + +Require ethereum.frontier.vm.gas. +Axiom ethereum_frontier_vm_gas_GAS_LOG : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_LOG". +Axiom ethereum_frontier_vm_gas_GAS_LOG_DATA : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_LOG_DATA". +Axiom ethereum_frontier_vm_gas_GAS_LOG_TOPIC : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_LOG_TOPIC". +Axiom ethereum_frontier_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_frontier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "charge_gas". + +Require ethereum.frontier.vm.memory. +Axiom ethereum_frontier_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.frontier.vm.memory.globals "memory_read_bytes". + +Require ethereum.frontier.vm.stack. +Axiom ethereum_frontier_vm_stack_pop : + IsGlobalAlias globals ethereum.frontier.vm.stack.globals "pop". Definition log_n : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/memory.v b/CoqOfPython/ethereum/frontier/vm/instructions/memory.v index 86ba742..3cb3f30 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/memory.v @@ -23,31 +23,31 @@ Axiom ethereum_base_types_U256 : Axiom ethereum_base_types_Bytes : IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.frontier.vm.__init__. +Axiom ethereum_frontier_vm___init___Evm : + IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.frontier.vm.gas. +Axiom ethereum_frontier_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_BASE". +Axiom ethereum_frontier_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_frontier_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_frontier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "charge_gas". -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". -Axiom memory_memory_write : - IsGlobalAlias globals memory.globals "memory_write". +Require ethereum.frontier.vm.memory. +Axiom ethereum_frontier_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.frontier.vm.memory.globals "memory_read_bytes". +Axiom ethereum_frontier_vm_memory_memory_write : + IsGlobalAlias globals ethereum.frontier.vm.memory.globals "memory_write". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.frontier.vm.stack. +Axiom ethereum_frontier_vm_stack_pop : + IsGlobalAlias globals ethereum.frontier.vm.stack.globals "pop". +Axiom ethereum_frontier_vm_stack_push : + IsGlobalAlias globals ethereum.frontier.vm.stack.globals "push". Definition mstore : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/stack.v b/CoqOfPython/ethereum/frontier/vm/instructions/stack.v index 305af15..8fb1c4c 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/stack.v @@ -29,27 +29,27 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". -Axiom __init___stack : - IsGlobalAlias globals __init__.globals "stack". - -Require exceptions. -Axiom exceptions_StackUnderflowError : - IsGlobalAlias globals exceptions.globals "StackUnderflowError". - -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require memory. -Axiom memory_buffer_read : - IsGlobalAlias globals memory.globals "buffer_read". +Require ethereum.frontier.vm.__init__. +Axiom ethereum_frontier_vm___init___Evm : + IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "Evm". +Axiom ethereum_frontier_vm___init___stack : + IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "stack". + +Require ethereum.frontier.vm.exceptions. +Axiom ethereum_frontier_vm_exceptions_StackUnderflowError : + IsGlobalAlias globals ethereum.frontier.vm.exceptions.globals "StackUnderflowError". + +Require ethereum.frontier.vm.gas. +Axiom ethereum_frontier_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_BASE". +Axiom ethereum_frontier_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_frontier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "charge_gas". + +Require ethereum.frontier.vm.memory. +Axiom ethereum_frontier_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.frontier.vm.memory.globals "buffer_read". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/storage.v b/CoqOfPython/ethereum/frontier/vm/instructions/storage.v index 5250214..6899add 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/storage.v @@ -17,33 +17,33 @@ Introduction Implementations of the EVM storage related instructions. ". -Require state. -Axiom state_get_storage : - IsGlobalAlias globals state.globals "get_storage". -Axiom state_set_storage : - IsGlobalAlias globals state.globals "set_storage". +Require ethereum.frontier.state. +Axiom ethereum_frontier_state_get_storage : + IsGlobalAlias globals ethereum.frontier.state.globals "get_storage". +Axiom ethereum_frontier_state_set_storage : + IsGlobalAlias globals ethereum.frontier.state.globals "set_storage". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.frontier.vm.__init__. +Axiom ethereum_frontier_vm___init___Evm : + IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_SLOAD : - IsGlobalAlias globals gas.globals "GAS_SLOAD". -Axiom gas_GAS_STORAGE_CLEAR_REFUND : - IsGlobalAlias globals gas.globals "GAS_STORAGE_CLEAR_REFUND". -Axiom gas_GAS_STORAGE_SET : - IsGlobalAlias globals gas.globals "GAS_STORAGE_SET". -Axiom gas_GAS_STORAGE_UPDATE : - IsGlobalAlias globals gas.globals "GAS_STORAGE_UPDATE". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.frontier.vm.gas. +Axiom ethereum_frontier_vm_gas_GAS_SLOAD : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_SLOAD". +Axiom ethereum_frontier_vm_gas_GAS_STORAGE_CLEAR_REFUND : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_STORAGE_CLEAR_REFUND". +Axiom ethereum_frontier_vm_gas_GAS_STORAGE_SET : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_STORAGE_SET". +Axiom ethereum_frontier_vm_gas_GAS_STORAGE_UPDATE : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_STORAGE_UPDATE". +Axiom ethereum_frontier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "charge_gas". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.frontier.vm.stack. +Axiom ethereum_frontier_vm_stack_pop : + IsGlobalAlias globals ethereum.frontier.vm.stack.globals "pop". +Axiom ethereum_frontier_vm_stack_push : + IsGlobalAlias globals ethereum.frontier.vm.stack.globals "push". Definition sload : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -146,11 +146,56 @@ Definition sstore : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "new_value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "current_value" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let gas_cost := + M.get_name (| globals, "GAS_STORAGE_SET" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let gas_cost := M.get_name (| globals, "GAS_STORAGE_UPDATE" |) in M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_name (| globals, "new_value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "current_value" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/system.v b/CoqOfPython/ethereum/frontier/vm/instructions/system.v index 859f97f..4ef9cd6 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/system.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/system.v @@ -25,61 +25,61 @@ Axiom ethereum_base_types_Bytes0 : Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.frontier.fork_types. +Axiom ethereum_frontier_fork_types_Address : + IsGlobalAlias globals ethereum.frontier.fork_types.globals "Address". -Require state. -Axiom state_account_has_code_or_nonce : - IsGlobalAlias globals state.globals "account_has_code_or_nonce". -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". -Axiom state_increment_nonce : - IsGlobalAlias globals state.globals "increment_nonce". -Axiom state_set_account_balance : - IsGlobalAlias globals state.globals "set_account_balance". +Require ethereum.frontier.state. +Axiom ethereum_frontier_state_account_has_code_or_nonce : + IsGlobalAlias globals ethereum.frontier.state.globals "account_has_code_or_nonce". +Axiom ethereum_frontier_state_get_account : + IsGlobalAlias globals ethereum.frontier.state.globals "get_account". +Axiom ethereum_frontier_state_increment_nonce : + IsGlobalAlias globals ethereum.frontier.state.globals "increment_nonce". +Axiom ethereum_frontier_state_set_account_balance : + IsGlobalAlias globals ethereum.frontier.state.globals "set_account_balance". -Require utils.address. -Axiom utils_address_compute_contract_address : - IsGlobalAlias globals utils.address.globals "compute_contract_address". -Axiom utils_address_to_address : - IsGlobalAlias globals utils.address.globals "to_address". +Require ethereum.frontier.utils.address. +Axiom ethereum_frontier_utils_address_compute_contract_address : + IsGlobalAlias globals ethereum.frontier.utils.address.globals "compute_contract_address". +Axiom ethereum_frontier_utils_address_to_address : + IsGlobalAlias globals ethereum.frontier.utils.address.globals "to_address". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". -Axiom __init___Message : - IsGlobalAlias globals __init__.globals "Message". -Axiom __init___incorporate_child_on_error : - IsGlobalAlias globals __init__.globals "incorporate_child_on_error". -Axiom __init___incorporate_child_on_success : - IsGlobalAlias globals __init__.globals "incorporate_child_on_success". +Require ethereum.frontier.vm.__init__. +Axiom ethereum_frontier_vm___init___Evm : + IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "Evm". +Axiom ethereum_frontier_vm___init___Message : + IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "Message". +Axiom ethereum_frontier_vm___init___incorporate_child_on_error : + IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "incorporate_child_on_error". +Axiom ethereum_frontier_vm___init___incorporate_child_on_success : + IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "incorporate_child_on_success". -Require gas. -Axiom gas_GAS_CREATE : - IsGlobalAlias globals gas.globals "GAS_CREATE". -Axiom gas_GAS_ZERO : - IsGlobalAlias globals gas.globals "GAS_ZERO". -Axiom gas_REFUND_SELF_DESTRUCT : - IsGlobalAlias globals gas.globals "REFUND_SELF_DESTRUCT". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_calculate_message_call_gas : - IsGlobalAlias globals gas.globals "calculate_message_call_gas". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.frontier.vm.gas. +Axiom ethereum_frontier_vm_gas_GAS_CREATE : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_CREATE". +Axiom ethereum_frontier_vm_gas_GAS_ZERO : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_ZERO". +Axiom ethereum_frontier_vm_gas_REFUND_SELF_DESTRUCT : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "REFUND_SELF_DESTRUCT". +Axiom ethereum_frontier_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_frontier_vm_gas_calculate_message_call_gas : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "calculate_message_call_gas". +Axiom ethereum_frontier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "charge_gas". -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". -Axiom memory_memory_write : - IsGlobalAlias globals memory.globals "memory_write". +Require ethereum.frontier.vm.memory. +Axiom ethereum_frontier_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.frontier.vm.memory.globals "memory_read_bytes". +Axiom ethereum_frontier_vm_memory_memory_write : + IsGlobalAlias globals ethereum.frontier.vm.memory.globals "memory_write". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.frontier.vm.stack. +Axiom ethereum_frontier_vm_stack_pop : + IsGlobalAlias globals ethereum.frontier.vm.stack.globals "pop". +Axiom ethereum_frontier_vm_stack_push : + IsGlobalAlias globals ethereum.frontier.vm.stack.globals "push". Definition create : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -187,7 +187,105 @@ Definition create : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt (| + M.get_field (| M.get_name (| globals, "sender" |), "balance" |), + M.get_name (| globals, "endowment" |) + |), + ltac:(M.monadic ( + BoolOp.or (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "sender" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.sub (| + BinOp.pow (| + Constant.int 2, + Constant.int 64 + |), + Constant.int 1 + |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.gt (| + BinOp.add (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "depth" |), + Constant.int 1 + |), + M.get_name (| globals, "STACK_DEPTH_LIMIT" |) + |) + )) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "create_message_gas" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "contract_address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let call_data := M.call (| M.get_name (| globals, "memory_read_bytes" |), @@ -222,6 +320,36 @@ Definition create : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "child_evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_error" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "incorporate_child_on_success" |), make_list [ @@ -341,6 +469,42 @@ Definition generic_call : Value.t -> Value.t -> M := " in (* At stmt: unsupported node type: ImportFrom *) let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + BinOp.add (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "depth" |), + Constant.int 1 + |), + M.get_name (| globals, "STACK_DEPTH_LIMIT" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "gas" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let call_data := @@ -378,6 +542,36 @@ Definition generic_call : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "child_evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_error" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "incorporate_child_on_success" |), make_list [ @@ -428,7 +622,7 @@ Definition generic_call : Value.t -> Value.t -> M := make_list [ M.get_field (| M.get_name (| globals, "evm" |), "memory" |); M.get_name (| globals, "memory_output_start_position" |); - M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), Constant.None_:M.get_name (| globals, "actual_output_size" |) |) + M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), M.slice (| Constant.None_, M.get_name (| globals, "actual_output_size" |) |) |) ], make_dict [] |) in @@ -565,6 +759,36 @@ Definition call : Value.t -> Value.t -> M := make_dict [] |), "balance" |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "sender_balance" |), + M.get_name (| globals, "value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "generic_call" |), make_list [ @@ -723,6 +947,36 @@ Definition callcode : Value.t -> Value.t -> M := make_dict [] |), "balance" |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "sender_balance" |), + M.get_name (| globals, "value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "generic_call" |), make_list [ @@ -796,6 +1050,22 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in EndWhile. let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "originator" |), + M.get_name (| globals, "refunded_accounts" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.get_name (| globals, "REFUND_SELF_DESTRUCT" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/frontier/vm/interpreter.v b/CoqOfPython/ethereum/frontier/vm/interpreter.v index 7665575..68fa407 100644 --- a/CoqOfPython/ethereum/frontier/vm/interpreter.v +++ b/CoqOfPython/ethereum/frontier/vm/interpreter.v @@ -55,71 +55,71 @@ Axiom ethereum_trace_TransactionEnd : Axiom ethereum_trace_evm_trace : IsGlobalAlias globals ethereum.trace.globals "evm_trace". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". - -Require state. -Axiom state_account_has_code_or_nonce : - IsGlobalAlias globals state.globals "account_has_code_or_nonce". -Axiom state_begin_transaction : - IsGlobalAlias globals state.globals "begin_transaction". -Axiom state_commit_transaction : - IsGlobalAlias globals state.globals "commit_transaction". -Axiom state_destroy_storage : - IsGlobalAlias globals state.globals "destroy_storage". -Axiom state_move_ether : - IsGlobalAlias globals state.globals "move_ether". -Axiom state_rollback_transaction : - IsGlobalAlias globals state.globals "rollback_transaction". -Axiom state_set_code : - IsGlobalAlias globals state.globals "set_code". -Axiom state_touch_account : - IsGlobalAlias globals state.globals "touch_account". - -Require vm. -Axiom vm_Message : - IsGlobalAlias globals vm.globals "Message". - -Require vm.gas. -Axiom vm_gas_GAS_CODE_DEPOSIT : - IsGlobalAlias globals vm.gas.globals "GAS_CODE_DEPOSIT". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". - -Require vm.precompiled_contracts.mapping. -Axiom vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : - IsGlobalAlias globals vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". - -Require __init__. -Axiom __init___Environment : - IsGlobalAlias globals __init__.globals "Environment". -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require exceptions. -Axiom exceptions_AddressCollision : - IsGlobalAlias globals exceptions.globals "AddressCollision". -Axiom exceptions_ExceptionalHalt : - IsGlobalAlias globals exceptions.globals "ExceptionalHalt". -Axiom exceptions_InvalidOpcode : - IsGlobalAlias globals exceptions.globals "InvalidOpcode". -Axiom exceptions_StackDepthLimitError : - IsGlobalAlias globals exceptions.globals "StackDepthLimitError". - -Require instructions. -Axiom instructions_Ops : - IsGlobalAlias globals instructions.globals "Ops". -Axiom instructions_op_implementation : - IsGlobalAlias globals instructions.globals "op_implementation". - -Require runtime. -Axiom runtime_get_valid_jump_destinations : - IsGlobalAlias globals runtime.globals "get_valid_jump_destinations". +Require ethereum.frontier.blocks. +Axiom ethereum_frontier_blocks_Log : + IsGlobalAlias globals ethereum.frontier.blocks.globals "Log". + +Require ethereum.frontier.fork_types. +Axiom ethereum_frontier_fork_types_Address : + IsGlobalAlias globals ethereum.frontier.fork_types.globals "Address". + +Require ethereum.frontier.state. +Axiom ethereum_frontier_state_account_has_code_or_nonce : + IsGlobalAlias globals ethereum.frontier.state.globals "account_has_code_or_nonce". +Axiom ethereum_frontier_state_begin_transaction : + IsGlobalAlias globals ethereum.frontier.state.globals "begin_transaction". +Axiom ethereum_frontier_state_commit_transaction : + IsGlobalAlias globals ethereum.frontier.state.globals "commit_transaction". +Axiom ethereum_frontier_state_destroy_storage : + IsGlobalAlias globals ethereum.frontier.state.globals "destroy_storage". +Axiom ethereum_frontier_state_move_ether : + IsGlobalAlias globals ethereum.frontier.state.globals "move_ether". +Axiom ethereum_frontier_state_rollback_transaction : + IsGlobalAlias globals ethereum.frontier.state.globals "rollback_transaction". +Axiom ethereum_frontier_state_set_code : + IsGlobalAlias globals ethereum.frontier.state.globals "set_code". +Axiom ethereum_frontier_state_touch_account : + IsGlobalAlias globals ethereum.frontier.state.globals "touch_account". + +Require ethereum.frontier.vm.__init__. +Axiom ethereum_frontier_vm___init___Message : + IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "Message". + +Require ethereum.frontier.vm.gas. +Axiom ethereum_frontier_vm_gas_GAS_CODE_DEPOSIT : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_CODE_DEPOSIT". +Axiom ethereum_frontier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "charge_gas". + +Require ethereum.frontier.vm.precompiled_contracts.mapping. +Axiom ethereum_frontier_vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : + IsGlobalAlias globals ethereum.frontier.vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". + +Require ethereum.frontier.vm.__init__. +Axiom ethereum_frontier_vm___init___Environment : + IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "Environment". +Axiom ethereum_frontier_vm___init___Evm : + IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "Evm". + +Require ethereum.frontier.vm.exceptions. +Axiom ethereum_frontier_vm_exceptions_AddressCollision : + IsGlobalAlias globals ethereum.frontier.vm.exceptions.globals "AddressCollision". +Axiom ethereum_frontier_vm_exceptions_ExceptionalHalt : + IsGlobalAlias globals ethereum.frontier.vm.exceptions.globals "ExceptionalHalt". +Axiom ethereum_frontier_vm_exceptions_InvalidOpcode : + IsGlobalAlias globals ethereum.frontier.vm.exceptions.globals "InvalidOpcode". +Axiom ethereum_frontier_vm_exceptions_StackDepthLimitError : + IsGlobalAlias globals ethereum.frontier.vm.exceptions.globals "StackDepthLimitError". + +Require ethereum.frontier.vm.instructions.__init__. +Axiom ethereum_frontier_vm_instructions___init___Ops : + IsGlobalAlias globals ethereum.frontier.vm.instructions.__init__.globals "Ops". +Axiom ethereum_frontier_vm_instructions___init___op_implementation : + IsGlobalAlias globals ethereum.frontier.vm.instructions.__init__.globals "op_implementation". + +Require ethereum.frontier.vm.runtime. +Axiom ethereum_frontier_vm_runtime_get_valid_jump_destinations : + IsGlobalAlias globals ethereum.frontier.vm.runtime.globals "get_valid_jump_destinations". Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -162,6 +162,89 @@ Definition process_message_call : Value.t -> Value.t -> M := Output of the message call " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "message" |), "target" |), + M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) + |), + (* then *) + ltac:(M.monadic ( + let is_collision := + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_name (| globals, "is_collision" |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallOutput" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "tuple" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "AddressCollision" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let evm := + M.call (| + M.get_name (| globals, "process_create_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let evm := M.call (| M.get_name (| globals, "process_message" |), @@ -174,6 +257,29 @@ Definition process_message_call : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( +(* At stmt: unsupported node type: AnnAssign *) + let accounts_to_delete := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let refund_counter := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let logs := M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in let accounts_to_delete := @@ -209,6 +315,7 @@ Definition process_message_call : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). Definition process_create_message : Value.t -> Value.t -> M := @@ -254,6 +361,35 @@ Definition process_create_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), + (* then *) + ltac:(M.monadic ( + let contract_code := + M.get_field (| M.get_name (| globals, "evm" |), "output" |) in + let contract_code_gas := + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "contract_code" |) + ], + make_dict [] + |), + M.get_name (| globals, "GAS_CODE_DEPOSIT" |) + |) in +(* At stmt: unsupported node type: Try *) + let _ := M.call (| + M.get_name (| globals, "commit_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "rollback_transaction" |), make_list [ @@ -265,6 +401,7 @@ Definition process_create_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) + |) in M.pure Constant.None_)). Definition process_message : Value.t -> Value.t -> M := @@ -286,6 +423,24 @@ Definition process_message : Value.t -> Value.t -> M := Items containing execution specific objects " in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_field (| M.get_name (| globals, "message" |), "depth" |), + M.get_name (| globals, "STACK_DEPTH_LIMIT" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "StackDepthLimitError" |), + make_list [ + Constant.str "Stack depth limit reached" + ], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -304,6 +459,27 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "message" |), "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "move_ether" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "caller" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |); + M.get_field (| M.get_name (| globals, "message" |), "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let evm := @@ -316,6 +492,21 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "rollback_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "commit_transaction" |), make_list [ @@ -327,6 +518,7 @@ Definition process_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) + |) in M.pure Constant.None_)). Definition execute_code : Value.t -> Value.t -> M := @@ -366,4 +558,5 @@ Definition execute_code : Value.t -> Value.t -> M := (* At stmt: unsupported node type: Try *) let _ := M.return_ (| M.get_name (| globals, "evm" |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/vm/memory.v b/CoqOfPython/ethereum/frontier/vm/memory.v index 4b107fd..08d2290 100644 --- a/CoqOfPython/ethereum/frontier/vm/memory.v +++ b/CoqOfPython/ethereum/frontier/vm/memory.v @@ -21,13 +21,13 @@ Require ethereum.utils.byte. Axiom ethereum_utils_byte_right_pad_zero_bytes : IsGlobalAlias globals ethereum.utils.byte.globals "right_pad_zero_bytes". -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". Definition memory_write : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,7 +45,22 @@ Definition memory_write : Value.t -> Value.t -> M := Data to write to memory. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |), + M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) |) |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_)). @@ -71,7 +86,23 @@ Definition memory_read_bytes : Value.t -> Value.t -> M := Data read from memory. " in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |) + M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |) |) + |) in M.pure Constant.None_)). Definition buffer_read : Value.t -> Value.t -> M := @@ -98,9 +129,25 @@ Definition buffer_read : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "right_pad_zero_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |) |); + M.get_subscript (| M.get_name (| globals, "buffer" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |) |); M.get_name (| globals, "size" |) ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/__init__.v index 422f670..b0d967f 100644 --- a/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/__init__.v +++ b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/__init__.v @@ -18,9 +18,9 @@ Addresses of precompiled contracts and mappings to their implementations. ". -Require utils.hexadecimal. -Axiom utils_hexadecimal_hex_to_address : - IsGlobalAlias globals utils.hexadecimal.globals "hex_to_address". +Require ethereum.frontier.utils.hexadecimal. +Axiom ethereum_frontier_utils_hexadecimal_hex_to_address : + IsGlobalAlias globals ethereum.frontier.utils.hexadecimal.globals "hex_to_address". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS" ] diff --git a/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/ecrecover.v index 0cbcf16..e54178a 100644 --- a/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/ecrecover.v @@ -37,19 +37,19 @@ Require ethereum.utils.byte. Axiom ethereum_utils_byte_left_pad_zero_bytes : IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.frontier.vm.__init__. +Axiom ethereum_frontier_vm___init___Evm : + IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_ECRECOVER : - IsGlobalAlias globals vm.gas.globals "GAS_ECRECOVER". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.frontier.vm.gas. +Axiom ethereum_frontier_vm_gas_GAS_ECRECOVER : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_ECRECOVER". +Axiom ethereum_frontier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "charge_gas". -Require vm.memory. -Axiom vm_memory_buffer_read : - IsGlobalAlias globals vm.memory.globals "buffer_read". +Require ethereum.frontier.vm.memory. +Axiom ethereum_frontier_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.frontier.vm.memory.globals "buffer_read". Definition ecrecover : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -188,12 +188,78 @@ Definition ecrecover : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "v" |), + Constant.int 27 + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "v" |), + Constant.int 28 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + Constant.int 0, + M.get_name (| globals, "r" |) + |), + ltac:(M.monadic ( + Compare.gt_e (| + M.get_name (| globals, "r" |), + M.get_name (| globals, "SECP256K1N" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + Constant.int 0, + M.get_name (| globals, "s" |) + |), + ltac:(M.monadic ( + Compare.gt_e (| + M.get_name (| globals, "s" |), + M.get_name (| globals, "SECP256K1N" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: Try *) @@ -204,7 +270,7 @@ Definition ecrecover : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12 |) in + |), M.slice (| Constant.int 12, Constant.int 32 |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/identity.v index fa96704..6e7b4d3 100644 --- a/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/identity.v +++ b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/identity.v @@ -25,17 +25,17 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.frontier.vm.__init__. +Axiom ethereum_frontier_vm___init___Evm : + IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_IDENTITY : - IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY". -Axiom vm_gas_GAS_IDENTITY_WORD : - IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY_WORD". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.frontier.vm.gas. +Axiom ethereum_frontier_vm_gas_GAS_IDENTITY : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_IDENTITY". +Axiom ethereum_frontier_vm_gas_GAS_IDENTITY_WORD : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_IDENTITY_WORD". +Axiom ethereum_frontier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "charge_gas". Definition identity : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/mapping.v index 710457d..a482e4b 100644 --- a/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/mapping.v +++ b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/mapping.v @@ -23,34 +23,34 @@ Axiom typing_Callable : Axiom typing_Dict : IsGlobalAlias globals typing.globals "Dict". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". - -Require __init__. -Axiom __init___ECRECOVER_ADDRESS : - IsGlobalAlias globals __init__.globals "ECRECOVER_ADDRESS". -Axiom __init___IDENTITY_ADDRESS : - IsGlobalAlias globals __init__.globals "IDENTITY_ADDRESS". -Axiom __init___RIPEMD160_ADDRESS : - IsGlobalAlias globals __init__.globals "RIPEMD160_ADDRESS". -Axiom __init___SHA256_ADDRESS : - IsGlobalAlias globals __init__.globals "SHA256_ADDRESS". - -Require ecrecover. -Axiom ecrecover_ecrecover : - IsGlobalAlias globals ecrecover.globals "ecrecover". - -Require identity. -Axiom identity_identity : - IsGlobalAlias globals identity.globals "identity". - -Require ripemd160. -Axiom ripemd160_ripemd160 : - IsGlobalAlias globals ripemd160.globals "ripemd160". - -Require sha256. -Axiom sha256_sha256 : - IsGlobalAlias globals sha256.globals "sha256". +Require ethereum.frontier.fork_types. +Axiom ethereum_frontier_fork_types_Address : + IsGlobalAlias globals ethereum.frontier.fork_types.globals "Address". + +Require ethereum.frontier.vm.precompiled_contracts.__init__. +Axiom ethereum_frontier_vm_precompiled_contracts___init___ECRECOVER_ADDRESS : + IsGlobalAlias globals ethereum.frontier.vm.precompiled_contracts.__init__.globals "ECRECOVER_ADDRESS". +Axiom ethereum_frontier_vm_precompiled_contracts___init___IDENTITY_ADDRESS : + IsGlobalAlias globals ethereum.frontier.vm.precompiled_contracts.__init__.globals "IDENTITY_ADDRESS". +Axiom ethereum_frontier_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : + IsGlobalAlias globals ethereum.frontier.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". +Axiom ethereum_frontier_vm_precompiled_contracts___init___SHA256_ADDRESS : + IsGlobalAlias globals ethereum.frontier.vm.precompiled_contracts.__init__.globals "SHA256_ADDRESS". + +Require ethereum.frontier.vm.precompiled_contracts.ecrecover. +Axiom ethereum_frontier_vm_precompiled_contracts_ecrecover_ecrecover : + IsGlobalAlias globals ethereum.frontier.vm.precompiled_contracts.ecrecover.globals "ecrecover". + +Require ethereum.frontier.vm.precompiled_contracts.identity. +Axiom ethereum_frontier_vm_precompiled_contracts_identity_identity : + IsGlobalAlias globals ethereum.frontier.vm.precompiled_contracts.identity.globals "identity". + +Require ethereum.frontier.vm.precompiled_contracts.ripemd160. +Axiom ethereum_frontier_vm_precompiled_contracts_ripemd160_ripemd160 : + IsGlobalAlias globals ethereum.frontier.vm.precompiled_contracts.ripemd160.globals "ripemd160". + +Require ethereum.frontier.vm.precompiled_contracts.sha256. +Axiom ethereum_frontier_vm_precompiled_contracts_sha256_sha256 : + IsGlobalAlias globals ethereum.frontier.vm.precompiled_contracts.sha256.globals "sha256". (* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/ripemd160.v index 96f8dcd..2d0a6cc 100644 --- a/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/ripemd160.v +++ b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/ripemd160.v @@ -31,17 +31,17 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.frontier.vm.__init__. +Axiom ethereum_frontier_vm___init___Evm : + IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_RIPEMD160 : - IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160". -Axiom vm_gas_GAS_RIPEMD160_WORD : - IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160_WORD". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.frontier.vm.gas. +Axiom ethereum_frontier_vm_gas_GAS_RIPEMD160 : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_RIPEMD160". +Axiom ethereum_frontier_vm_gas_GAS_RIPEMD160_WORD : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_RIPEMD160_WORD". +Axiom ethereum_frontier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "charge_gas". Definition ripemd160 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/sha256.v index 9f6d2bf..ce63204 100644 --- a/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/sha256.v +++ b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/sha256.v @@ -27,17 +27,17 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.frontier.vm.__init__. +Axiom ethereum_frontier_vm___init___Evm : + IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_SHA256 : - IsGlobalAlias globals vm.gas.globals "GAS_SHA256". -Axiom vm_gas_GAS_SHA256_WORD : - IsGlobalAlias globals vm.gas.globals "GAS_SHA256_WORD". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.frontier.vm.gas. +Axiom ethereum_frontier_vm_gas_GAS_SHA256 : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_SHA256". +Axiom ethereum_frontier_vm_gas_GAS_SHA256_WORD : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_SHA256_WORD". +Axiom ethereum_frontier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.frontier.vm.gas.globals "charge_gas". Definition sha256 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/frontier/vm/runtime.v b/CoqOfPython/ethereum/frontier/vm/runtime.v index 2cd7652..21656f1 100644 --- a/CoqOfPython/ethereum/frontier/vm/runtime.v +++ b/CoqOfPython/ethereum/frontier/vm/runtime.v @@ -25,9 +25,9 @@ Require ethereum.base_types. Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require instructions. -Axiom instructions_Ops : - IsGlobalAlias globals instructions.globals "Ops". +Require ethereum.frontier.vm.instructions.__init__. +Axiom ethereum_frontier_vm_instructions___init___Ops : + IsGlobalAlias globals ethereum.frontier.vm.instructions.__init__.globals "Ops". Definition get_valid_jump_destinations : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -79,7 +79,55 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := |) do (* At stmt: unsupported node type: Try *) let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "current_opcode" |), + M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), + make_list [ + M.get_name (| globals, "pc" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.lt_e (| + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |), + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH32" |), "value" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let push_data_size := + BinOp.add (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) + |), + Constant.int 1 + |) in + let pc := BinOp.add + M.get_name (| globals, "push_data_size" |) + M.get_name (| globals, "push_data_size" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -90,4 +138,5 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := EndWhile. let _ := M.return_ (| M.get_name (| globals, "valid_jump_destinations" |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/frontier/vm/stack.v b/CoqOfPython/ethereum/frontier/vm/stack.v index ea778df..b7f149b 100644 --- a/CoqOfPython/ethereum/frontier/vm/stack.v +++ b/CoqOfPython/ethereum/frontier/vm/stack.v @@ -25,11 +25,11 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require exceptions. -Axiom exceptions_StackOverflowError : - IsGlobalAlias globals exceptions.globals "StackOverflowError". -Axiom exceptions_StackUnderflowError : - IsGlobalAlias globals exceptions.globals "StackUnderflowError". +Require ethereum.frontier.vm.exceptions. +Axiom ethereum_frontier_vm_exceptions_StackOverflowError : + IsGlobalAlias globals ethereum.frontier.vm.exceptions.globals "StackOverflowError". +Axiom ethereum_frontier_vm_exceptions_StackUnderflowError : + IsGlobalAlias globals ethereum.frontier.vm.exceptions.globals "StackUnderflowError". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -49,6 +49,24 @@ Definition pop : Value.t -> Value.t -> M := " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "StackUnderflowError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -57,6 +75,7 @@ Definition pop : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). Definition push : Value.t -> Value.t -> M := @@ -75,6 +94,24 @@ Definition push : Value.t -> Value.t -> M := " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), + Constant.int 1024 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "StackOverflowError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -85,4 +122,5 @@ Definition push : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/genesis.v b/CoqOfPython/ethereum/genesis.v index 2e1c5f8..41faa5c 100644 --- a/CoqOfPython/ethereum/genesis.v +++ b/CoqOfPython/ethereum/genesis.v @@ -34,9 +34,9 @@ Axiom typing_Dict : Axiom typing_cast : IsGlobalAlias globals typing.globals "cast". -Require ethereum. -Axiom ethereum_rlp : - IsGlobalAlias globals ethereum.globals "rlp". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". Require ethereum.base_types. Axiom ethereum_base_types_U64 : @@ -109,7 +109,7 @@ Definition get_genesis_configuration : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "pkgutil" |), "get_data" |), make_list [ Constant.str "ethereum"; - (* At expr: unsupported node type: JoinedStr *) + Constant.str "(* At expr: unsupported node type: JoinedStr *)" ], make_dict [] |) @@ -133,6 +133,7 @@ Definition get_genesis_configuration : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). Definition hex_or_base_10_str_to_u256 : Value.t -> Value.t -> M := @@ -143,6 +144,29 @@ Definition hex_or_base_10_str_to_u256 : Value.t -> Value.t -> M := numbers or 0x prefixed hex. This function supports both. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_field (| M.get_name (| globals, "balance" |), "startswith" |), + make_list [ + Constant.str "0x" + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "hex_to_u256" |), + make_list [ + M.get_name (| globals, "balance" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_name (| globals, "U256" |), @@ -157,6 +181,7 @@ Definition hex_or_base_10_str_to_u256 : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -320,8 +345,113 @@ Definition add_genesis_block : Value.t -> Value.t -> M := EndFor. EndFor. let fields := - {Constant.str "parent_hash", Constant.str "ommers_hash", Constant.str "coinbase", Constant.str "state_root", Constant.str "transactions_root", Constant.str "receipt_root", Constant.str "bloom", Constant.str "difficulty", Constant.str "number", Constant.str "gas_limit", Constant.str "gas_used", Constant.str "timestamp", Constant.str "extra_data", Constant.str "nonce"} in + {Constant.str "parent_hash": M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "fork_types" |), "Hash32" |), + make_list [ + BinOp.mult (| + Constant.bytes "00", + Constant.int 32 + |) + ], + make_dict [] + |), Constant.str "ommers_hash": M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), + make_list [ + make_tuple [ ] + ], + make_dict [] + |), Constant.str "coinbase": M.call (| + M.get_name (| globals, "Address" |), + make_list [ + BinOp.mult (| + Constant.bytes "00", + Constant.int 20 + |) + ], + make_dict [] + |), Constant.str "state_root": M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "state" |), "state_root" |), + make_list [ + M.get_field (| M.get_name (| globals, "chain" |), "state" |) + ], + make_dict [] + |), Constant.str "transactions_root": M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "trie" |), "root" |), + make_list [ + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "trie" |), "Trie" |), + make_list [ + Constant.bool false; + Constant.None_ + ], + make_dict [] + |) + ], + make_dict [] + |), Constant.str "receipt_root": M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "trie" |), "root" |), + make_list [ + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "trie" |), "Trie" |), + make_list [ + Constant.bool false; + Constant.None_ + ], + make_dict [] + |) + ], + make_dict [] + |), Constant.str "bloom": M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "fork_types" |), "Bloom" |), + make_list [ + BinOp.mult (| + Constant.bytes "00", + Constant.int 256 + |) + ], + make_dict [] + |), Constant.str "difficulty": M.get_field (| M.get_name (| globals, "genesis" |), "difficulty" |), Constant.str "number": M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |), Constant.str "gas_limit": M.get_field (| M.get_name (| globals, "genesis" |), "gas_limit" |), Constant.str "gas_used": M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |), Constant.str "timestamp": M.get_field (| M.get_name (| globals, "genesis" |), "timestamp" |), Constant.str "extra_data": M.get_field (| M.get_name (| globals, "genesis" |), "extra_data" |), Constant.str "nonce": M.get_field (| M.get_name (| globals, "genesis" |), "nonce" |)} in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "hasattr" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "blocks" |), "Header" |); + Constant.str "mix_digest" + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "fields" |), Constant.str "mix_digest" |), + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "fork_types" |), "Hash32" |), + make_list [ + BinOp.mult (| + Constant.bytes "00", + Constant.int 32 + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_name (| globals, "fields" |), Constant.str "prev_randao" |), M.call (| @@ -338,6 +468,34 @@ Definition add_genesis_block : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "hasattr" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "blocks" |), "Header" |); + Constant.str "base_fee_per_gas" + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| M.get_name (| globals, "fields" |), Constant.str "base_fee_per_gas" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.pow (| + Constant.int 10, + Constant.int 9 + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let genesis_header := diff --git a/CoqOfPython/ethereum/gray_glacier/blocks.v b/CoqOfPython/ethereum/gray_glacier/blocks.v index a90217e..7656b6a 100644 --- a/CoqOfPython/ethereum/gray_glacier/blocks.v +++ b/CoqOfPython/ethereum/gray_glacier/blocks.v @@ -24,35 +24,35 @@ Axiom typing_Tuple : Axiom typing_Union : IsGlobalAlias globals typing.globals "Union". -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes8 : - IsGlobalAlias globals base_types.globals "Bytes8". -Axiom base_types_Bytes32 : - IsGlobalAlias globals base_types.globals "Bytes32". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require crypto.hash. -Axiom crypto_hash_Hash32 : - IsGlobalAlias globals crypto.hash.globals "Hash32". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". - -Require transactions. -Axiom transactions_LegacyTransaction : - IsGlobalAlias globals transactions.globals "LegacyTransaction". +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes8 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes8". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". + +Require ethereum.gray_glacier.fork_types. +Axiom ethereum_gray_glacier_fork_types_Address : + IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "Address". +Axiom ethereum_gray_glacier_fork_types_Bloom : + IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "Bloom". +Axiom ethereum_gray_glacier_fork_types_Root : + IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "Root". + +Require ethereum.gray_glacier.transactions. +Axiom ethereum_gray_glacier_transactions_LegacyTransaction : + IsGlobalAlias globals ethereum.gray_glacier.transactions.globals "LegacyTransaction". Definition Header : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/gray_glacier/bloom.v b/CoqOfPython/ethereum/gray_glacier/bloom.v index 04650ff..fb2d5b0 100644 --- a/CoqOfPython/ethereum/gray_glacier/bloom.v +++ b/CoqOfPython/ethereum/gray_glacier/bloom.v @@ -33,13 +33,13 @@ Require ethereum.crypto.hash. Axiom ethereum_crypto_hash_keccak256 : IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". +Require ethereum.gray_glacier.blocks. +Axiom ethereum_gray_glacier_blocks_Log : + IsGlobalAlias globals ethereum.gray_glacier.blocks.globals "Log". -Require fork_types. -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". +Require ethereum.gray_glacier.fork_types. +Axiom ethereum_gray_glacier_fork_types_Bloom : + IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "Bloom". Definition add_to_bloom : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -72,7 +72,10 @@ Definition add_to_bloom : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |) |) + M.get_subscript (| M.get_name (| globals, "hash" |), M.slice (| M.get_name (| globals, "idx" |), BinOp.add (| + M.get_name (| globals, "idx" |), + Constant.int 2 + |) |) |) ], make_dict [] |), @@ -157,4 +160,5 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/fork.v b/CoqOfPython/ethereum/gray_glacier/fork.v index 2b1b864..a0c2cc6 100644 --- a/CoqOfPython/ethereum/gray_glacier/fork.v +++ b/CoqOfPython/ethereum/gray_glacier/fork.v @@ -65,107 +65,107 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U64 : - IsGlobalAlias globals base_types.globals "U64". -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_U256_CEIL_VALUE : - IsGlobalAlias globals base_types.globals "U256_CEIL_VALUE". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". - -Require __init__. -Axiom __init___vm : - IsGlobalAlias globals __init__.globals "vm". - -Require blocks. -Axiom blocks_Block : - IsGlobalAlias globals blocks.globals "Block". -Axiom blocks_Header : - IsGlobalAlias globals blocks.globals "Header". -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". -Axiom blocks_Receipt : - IsGlobalAlias globals blocks.globals "Receipt". - -Require bloom. -Axiom bloom_logs_bloom : - IsGlobalAlias globals bloom.globals "logs_bloom". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". - -Require state. -Axiom state_State : - IsGlobalAlias globals state.globals "State". -Axiom state_account_exists_and_is_empty : - IsGlobalAlias globals state.globals "account_exists_and_is_empty". -Axiom state_create_ether : - IsGlobalAlias globals state.globals "create_ether". -Axiom state_destroy_account : - IsGlobalAlias globals state.globals "destroy_account". -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". -Axiom state_increment_nonce : - IsGlobalAlias globals state.globals "increment_nonce". -Axiom state_set_account_balance : - IsGlobalAlias globals state.globals "set_account_balance". -Axiom state_state_root : - IsGlobalAlias globals state.globals "state_root". - -Require transactions. -Axiom transactions_TX_ACCESS_LIST_ADDRESS_COST : - IsGlobalAlias globals transactions.globals "TX_ACCESS_LIST_ADDRESS_COST". -Axiom transactions_TX_ACCESS_LIST_STORAGE_KEY_COST : - IsGlobalAlias globals transactions.globals "TX_ACCESS_LIST_STORAGE_KEY_COST". -Axiom transactions_TX_BASE_COST : - IsGlobalAlias globals transactions.globals "TX_BASE_COST". -Axiom transactions_TX_CREATE_COST : - IsGlobalAlias globals transactions.globals "TX_CREATE_COST". -Axiom transactions_TX_DATA_COST_PER_NON_ZERO : - IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_NON_ZERO". -Axiom transactions_TX_DATA_COST_PER_ZERO : - IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_ZERO". -Axiom transactions_AccessListTransaction : - IsGlobalAlias globals transactions.globals "AccessListTransaction". -Axiom transactions_FeeMarketTransaction : - IsGlobalAlias globals transactions.globals "FeeMarketTransaction". -Axiom transactions_LegacyTransaction : - IsGlobalAlias globals transactions.globals "LegacyTransaction". -Axiom transactions_Transaction : - IsGlobalAlias globals transactions.globals "Transaction". -Axiom transactions_decode_transaction : - IsGlobalAlias globals transactions.globals "decode_transaction". -Axiom transactions_encode_transaction : - IsGlobalAlias globals transactions.globals "encode_transaction". - -Require trie. -Axiom trie_Trie : - IsGlobalAlias globals trie.globals "Trie". -Axiom trie_root : - IsGlobalAlias globals trie.globals "root". -Axiom trie_trie_set : - IsGlobalAlias globals trie.globals "trie_set". - -Require utils.message. -Axiom utils_message_prepare_message : - IsGlobalAlias globals utils.message.globals "prepare_message". - -Require vm.interpreter. -Axiom vm_interpreter_process_message_call : - IsGlobalAlias globals vm.interpreter.globals "process_message_call". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U64 : + IsGlobalAlias globals ethereum.base_types.globals "U64". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_U256_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.gray_glacier.__init__. +Axiom ethereum_gray_glacier___init___vm : + IsGlobalAlias globals ethereum.gray_glacier.__init__.globals "vm". + +Require ethereum.gray_glacier.blocks. +Axiom ethereum_gray_glacier_blocks_Block : + IsGlobalAlias globals ethereum.gray_glacier.blocks.globals "Block". +Axiom ethereum_gray_glacier_blocks_Header : + IsGlobalAlias globals ethereum.gray_glacier.blocks.globals "Header". +Axiom ethereum_gray_glacier_blocks_Log : + IsGlobalAlias globals ethereum.gray_glacier.blocks.globals "Log". +Axiom ethereum_gray_glacier_blocks_Receipt : + IsGlobalAlias globals ethereum.gray_glacier.blocks.globals "Receipt". + +Require ethereum.gray_glacier.bloom. +Axiom ethereum_gray_glacier_bloom_logs_bloom : + IsGlobalAlias globals ethereum.gray_glacier.bloom.globals "logs_bloom". + +Require ethereum.gray_glacier.fork_types. +Axiom ethereum_gray_glacier_fork_types_Address : + IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "Address". +Axiom ethereum_gray_glacier_fork_types_Bloom : + IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "Bloom". +Axiom ethereum_gray_glacier_fork_types_Root : + IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "Root". + +Require ethereum.gray_glacier.state. +Axiom ethereum_gray_glacier_state_State : + IsGlobalAlias globals ethereum.gray_glacier.state.globals "State". +Axiom ethereum_gray_glacier_state_account_exists_and_is_empty : + IsGlobalAlias globals ethereum.gray_glacier.state.globals "account_exists_and_is_empty". +Axiom ethereum_gray_glacier_state_create_ether : + IsGlobalAlias globals ethereum.gray_glacier.state.globals "create_ether". +Axiom ethereum_gray_glacier_state_destroy_account : + IsGlobalAlias globals ethereum.gray_glacier.state.globals "destroy_account". +Axiom ethereum_gray_glacier_state_get_account : + IsGlobalAlias globals ethereum.gray_glacier.state.globals "get_account". +Axiom ethereum_gray_glacier_state_increment_nonce : + IsGlobalAlias globals ethereum.gray_glacier.state.globals "increment_nonce". +Axiom ethereum_gray_glacier_state_set_account_balance : + IsGlobalAlias globals ethereum.gray_glacier.state.globals "set_account_balance". +Axiom ethereum_gray_glacier_state_state_root : + IsGlobalAlias globals ethereum.gray_glacier.state.globals "state_root". + +Require ethereum.gray_glacier.transactions. +Axiom ethereum_gray_glacier_transactions_TX_ACCESS_LIST_ADDRESS_COST : + IsGlobalAlias globals ethereum.gray_glacier.transactions.globals "TX_ACCESS_LIST_ADDRESS_COST". +Axiom ethereum_gray_glacier_transactions_TX_ACCESS_LIST_STORAGE_KEY_COST : + IsGlobalAlias globals ethereum.gray_glacier.transactions.globals "TX_ACCESS_LIST_STORAGE_KEY_COST". +Axiom ethereum_gray_glacier_transactions_TX_BASE_COST : + IsGlobalAlias globals ethereum.gray_glacier.transactions.globals "TX_BASE_COST". +Axiom ethereum_gray_glacier_transactions_TX_CREATE_COST : + IsGlobalAlias globals ethereum.gray_glacier.transactions.globals "TX_CREATE_COST". +Axiom ethereum_gray_glacier_transactions_TX_DATA_COST_PER_NON_ZERO : + IsGlobalAlias globals ethereum.gray_glacier.transactions.globals "TX_DATA_COST_PER_NON_ZERO". +Axiom ethereum_gray_glacier_transactions_TX_DATA_COST_PER_ZERO : + IsGlobalAlias globals ethereum.gray_glacier.transactions.globals "TX_DATA_COST_PER_ZERO". +Axiom ethereum_gray_glacier_transactions_AccessListTransaction : + IsGlobalAlias globals ethereum.gray_glacier.transactions.globals "AccessListTransaction". +Axiom ethereum_gray_glacier_transactions_FeeMarketTransaction : + IsGlobalAlias globals ethereum.gray_glacier.transactions.globals "FeeMarketTransaction". +Axiom ethereum_gray_glacier_transactions_LegacyTransaction : + IsGlobalAlias globals ethereum.gray_glacier.transactions.globals "LegacyTransaction". +Axiom ethereum_gray_glacier_transactions_Transaction : + IsGlobalAlias globals ethereum.gray_glacier.transactions.globals "Transaction". +Axiom ethereum_gray_glacier_transactions_decode_transaction : + IsGlobalAlias globals ethereum.gray_glacier.transactions.globals "decode_transaction". +Axiom ethereum_gray_glacier_transactions_encode_transaction : + IsGlobalAlias globals ethereum.gray_glacier.transactions.globals "encode_transaction". + +Require ethereum.gray_glacier.trie. +Axiom ethereum_gray_glacier_trie_Trie : + IsGlobalAlias globals ethereum.gray_glacier.trie.globals "Trie". +Axiom ethereum_gray_glacier_trie_root : + IsGlobalAlias globals ethereum.gray_glacier.trie.globals "root". +Axiom ethereum_gray_glacier_trie_trie_set : + IsGlobalAlias globals ethereum.gray_glacier.trie.globals "trie_set". + +Require ethereum.gray_glacier.utils.message. +Axiom ethereum_gray_glacier_utils_message_prepare_message : + IsGlobalAlias globals ethereum.gray_glacier.utils.message.globals "prepare_message". + +Require ethereum.gray_glacier.vm.interpreter. +Axiom ethereum_gray_glacier_vm_interpreter_process_message_call : + IsGlobalAlias globals ethereum.gray_glacier.vm.interpreter.globals "process_message_call". Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -266,6 +266,7 @@ Definition apply_fork : Value.t -> Value.t -> M := " in let _ := M.return_ (| M.get_name (| globals, "old" |) + |) in M.pure Constant.None_)). Definition get_last_256_block_hashes : Value.t -> Value.t -> M := @@ -291,8 +292,28 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := Hashes of the recent 256 blocks in order of increasing block number. " in let recent_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |) |) in + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "recent_blocks" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + make_list [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let recent_block_hashes := @@ -331,6 +352,7 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "recent_block_hashes" |) + |) in M.pure Constant.None_)). Definition state_transition : Value.t -> Value.t -> M := @@ -463,6 +485,27 @@ Definition state_transition : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |) + ], + make_dict [] + |), + Constant.int 255 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -510,7 +553,63 @@ Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "parent_gas_used" |), + M.get_name (| globals, "parent_gas_target" |) + |), + (* then *) + ltac:(M.monadic ( + let expected_base_fee_per_gas := + M.get_name (| globals, "parent_base_fee_per_gas" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "parent_gas_used" |), + M.get_name (| globals, "parent_gas_target" |) + |), + (* then *) + ltac:(M.monadic ( + let gas_used_delta := + BinOp.sub (| + M.get_name (| globals, "parent_gas_used" |), + M.get_name (| globals, "parent_gas_target" |) + |) in + let parent_fee_gas_delta := + BinOp.mult (| + M.get_name (| globals, "parent_base_fee_per_gas" |), + M.get_name (| globals, "gas_used_delta" |) + |) in + let target_fee_gas_delta := + BinOp.floor_div (| + M.get_name (| globals, "parent_fee_gas_delta" |), + M.get_name (| globals, "parent_gas_target" |) + |) in + let base_fee_per_gas_delta := + M.call (| + M.get_name (| globals, "max" |), + make_list [ + BinOp.floor_div (| + M.get_name (| globals, "target_fee_gas_delta" |), + M.get_name (| globals, "BASE_FEE_MAX_CHANGE_DENOMINATOR" |) + |); + Constant.int 1 + ], + make_dict [] + |) in + let expected_base_fee_per_gas := + BinOp.add (| + M.get_name (| globals, "parent_base_fee_per_gas" |), + M.get_name (| globals, "base_fee_per_gas_delta" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let gas_used_delta := BinOp.sub (| M.get_name (| globals, "parent_gas_target" |), @@ -548,6 +647,7 @@ Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition validate_header : Value.t -> Value.t -> M := @@ -757,6 +857,7 @@ Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition validate_proof_of_work : Value.t -> Value.t -> M := @@ -894,6 +995,60 @@ Definition check_transaction : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "FeeMarketTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt_e (| + M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |), + M.get_field (| M.get_name (| globals, "tx" |), "max_priority_fee_per_gas" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt_e (| + M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |), + M.get_name (| globals, "base_fee_per_gas" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let priority_fee_per_gas := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_field (| M.get_name (| globals, "tx" |), "max_priority_fee_per_gas" |); + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |), + M.get_name (| globals, "base_fee_per_gas" |) + |) + ], + make_dict [] + |) in + let effective_gas_price := + BinOp.add (| + M.get_name (| globals, "priority_fee_per_gas" |), + M.get_name (| globals, "base_fee_per_gas" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -911,6 +1066,7 @@ Definition check_transaction : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| make_tuple [ M.get_name (| globals, "sender_address" |); M.get_name (| globals, "effective_gas_price" |) ] + |) in M.pure Constant.None_)). Definition make_receipt : Value.t -> Value.t -> M := @@ -943,9 +1099,64 @@ Definition make_receipt : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "AccessListTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + Constant.bytes "01", + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "receipt" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "FeeMarketTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + Constant.bytes "02", + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "receipt" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "receipt" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -1178,6 +1389,7 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition validate_ommers : Value.t -> Value.t -> M := @@ -1230,6 +1442,26 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do @@ -1287,7 +1519,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let ommers_hashes := - (* At expr: unsupported node type: ListComp *) in + Constant.str "(* At expr: unsupported node type: ListComp *)" in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1318,19 +1550,19 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let recent_canonical_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| BinOp.add (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| BinOp.add (| M.get_name (| globals, "MAX_OMMER_DEPTH" |), Constant.int 1 - |) |) |) in + |) |), Constant.None_ |) |) in let recent_canonical_block_hashes := - (* At expr: unsupported node type: SetComp *) in + Constant.str "(* At expr: unsupported node type: SetComp *)" in (* At stmt: unsupported node type: AnnAssign *) For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_canonical_blocks" |) do let recent_ommers_hashes := M.call (| M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), make_list [ - (* At expr: unsupported node type: SetComp *) + Constant.str "(* At expr: unsupported node type: SetComp *)" ], make_dict [] |) in @@ -1570,6 +1802,26 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "FeeMarketTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let max_gas_fee := + BinOp.mult (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let max_gas_fee := BinOp.mult (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), @@ -1668,6 +1920,39 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + make_tuple [ M.get_name (| globals, "AccessListTransaction" |); M.get_name (| globals, "FeeMarketTransaction" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + For make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "keys" |) ] in M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "preaccessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "key" |) in M.get_name (| globals, "keys" |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "preaccessed_storage_keys" |), "add" |), + make_list [ + make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "key" |) ] + ], + make_dict [] + |) in + EndFor. + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let message := @@ -1772,7 +2057,50 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "transaction_fee" |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| + M.get_name (| globals, "coinbase_balance_after_mining_fee" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |); + M.get_name (| globals, "coinbase_balance_after_mining_fee" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -1789,11 +2117,35 @@ Definition process_transaction : Value.t -> Value.t -> M := EndFor. For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "touched_accounts" |) do let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := M.return_ (| make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |); M.get_field (| M.get_name (| globals, "output" |), "error" |) ] + |) in M.pure Constant.None_)). Definition validate_transaction : Value.t -> Value.t -> M := @@ -1848,6 +2200,7 @@ Definition validate_transaction : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := @@ -1879,6 +2232,20 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := Constant.int 0 in For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "byte" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let data_cost := BinOp.add M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in @@ -1886,6 +2253,25 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := )) |) in EndFor. let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "tx" |), "to" |), + M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) + |), + (* then *) + ltac:(M.monadic ( + let create_cost := + M.get_name (| globals, "TX_CREATE_COST" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let create_cost := Constant.int 0 in M.pure Constant.None_ @@ -1893,6 +2279,47 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := let access_list_cost := Constant.int 0 in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + make_tuple [ M.get_name (| globals, "AccessListTransaction" |); M.get_name (| globals, "FeeMarketTransaction" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + For make_tuple [ M.get_name (| globals, "_address" |); M.get_name (| globals, "keys" |) ] in M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) do + let access_list_cost := BinOp.add + M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) + M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) in + let access_list_cost := BinOp.add + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "keys" |) + ], + make_dict [] + |), + M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) + |) + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "keys" |) + ], + make_dict [] + |), + M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) + |) in + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1912,6 +2339,7 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition recover_sender : Value.t -> Value.t -> M := @@ -1984,8 +2412,189 @@ Definition recover_sender : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "LegacyTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let v := + M.get_field (| M.get_name (| globals, "tx" |), "v" |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.eq (| + M.get_name (| globals, "v" |), + Constant.int 27 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "v" |), + Constant.int 28 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + BinOp.sub (| + M.get_name (| globals, "v" |), + Constant.int 27 + |); + M.call (| + M.get_name (| globals, "signing_hash_pre155" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.or (| + Compare.eq (| + M.get_name (| globals, "v" |), + BinOp.add (| + Constant.int 35, + BinOp.mult (| + M.get_name (| globals, "chain_id" |), + Constant.int 2 + |) + |) + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "v" |), + BinOp.add (| + Constant.int 36, + BinOp.mult (| + M.get_name (| globals, "chain_id" |), + Constant.int 2 + |) + |) + |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + BinOp.sub (| + BinOp.sub (| + M.get_name (| globals, "v" |), + Constant.int 35 + |), + BinOp.mult (| + M.get_name (| globals, "chain_id" |), + Constant.int 2 + |) + |); + M.call (| + M.get_name (| globals, "signing_hash_155" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "chain_id" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "AccessListTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + M.get_field (| M.get_name (| globals, "tx" |), "y_parity" |); + M.call (| + M.get_name (| globals, "signing_hash_2930" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "FeeMarketTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + M.get_field (| M.get_name (| globals, "tx" |), "y_parity" |); + M.call (| + M.get_name (| globals, "signing_hash_1559" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -2002,10 +2611,11 @@ Definition recover_sender : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12 |) + |), M.slice (| Constant.int 12, Constant.int 32 |) |) ], make_dict [] |) + |) in M.pure Constant.None_)). Definition signing_hash_pre155 : Value.t -> Value.t -> M := @@ -2038,6 +2648,7 @@ Definition signing_hash_pre155 : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition signing_hash_155 : Value.t -> Value.t -> M := @@ -2084,6 +2695,7 @@ Definition signing_hash_155 : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition signing_hash_2930 : Value.t -> Value.t -> M := @@ -2119,6 +2731,7 @@ Definition signing_hash_2930 : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition signing_hash_1559 : Value.t -> Value.t -> M := @@ -2154,6 +2767,7 @@ Definition signing_hash_1559 : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition compute_header_hash : Value.t -> Value.t -> M := @@ -2204,6 +2818,7 @@ Definition compute_header_hash : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition check_gas_limit : Value.t -> Value.t -> M := @@ -2242,16 +2857,65 @@ Definition check_gas_limit : Value.t -> Value.t -> M := M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "gas_limit" |), + BinOp.add (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "gas_limit" |), + BinOp.sub (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "gas_limit" |), + M.get_name (| globals, "GAS_LIMIT_MINIMUM" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| Constant.bool true + |) in M.pure Constant.None_)). Definition calculate_block_difficulty : Value.t -> Value.t -> M := @@ -2311,12 +2975,16 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := M.get_name (| globals, "max" |), make_list [ BinOp.sub (| - (* if *) -M.if_then_else (| - M.get_name (| globals, "parent_has_ommers" |), -(* then *) -ltac:(M.monadic ( -Constant.int 2, + (* if *) + M.if_then_else (| + M.get_name (| globals, "parent_has_ommers" |), + (* then *) + ltac:(M.monadic ( +Constant.int 2 + (* else *) + )), ltac:(M.monadic ( +Constant.int 1 + )) |), BinOp.floor_div (| M.call (| M.get_name (| globals, "int" |), @@ -2365,6 +3033,26 @@ Constant.int 2, Constant.int 2 |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "num_bomb_periods" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let difficulty := BinOp.add + BinOp.pow (| + Constant.int 2, + M.get_name (| globals, "num_bomb_periods" |) + |) + BinOp.pow (| + Constant.int 2, + M.get_name (| globals, "num_bomb_periods" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -2382,4 +3070,5 @@ Constant.int 2, ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/fork_types.v b/CoqOfPython/ethereum/gray_glacier/fork_types.v index 5c7dac3..cc8e4a1 100644 --- a/CoqOfPython/ethereum/gray_glacier/fork_types.v +++ b/CoqOfPython/ethereum/gray_glacier/fork_types.v @@ -21,29 +21,29 @@ Require dataclasses. Axiom dataclasses_dataclass : IsGlobalAlias globals dataclasses.globals "dataclass". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes20 : - IsGlobalAlias globals base_types.globals "Bytes20". -Axiom base_types_Bytes256 : - IsGlobalAlias globals base_types.globals "Bytes256". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require crypto.hash. -Axiom crypto_hash_Hash32 : - IsGlobalAlias globals crypto.hash.globals "Hash32". -Axiom crypto_hash_keccak256 : - IsGlobalAlias globals crypto.hash.globals "keccak256". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes20 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes20". +Axiom ethereum_base_types_Bytes256 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) @@ -98,4 +98,5 @@ Definition encode_account : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/state.v b/CoqOfPython/ethereum/gray_glacier/state.v index c3290a6..8dc2148 100644 --- a/CoqOfPython/ethereum/gray_glacier/state.v +++ b/CoqOfPython/ethereum/gray_glacier/state.v @@ -56,29 +56,29 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require fork_types. -Axiom fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". -Axiom fork_types_Account : - IsGlobalAlias globals fork_types.globals "Account". -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". - -Require trie. -Axiom trie_EMPTY_TRIE_ROOT : - IsGlobalAlias globals trie.globals "EMPTY_TRIE_ROOT". -Axiom trie_Trie : - IsGlobalAlias globals trie.globals "Trie". -Axiom trie_copy_trie : - IsGlobalAlias globals trie.globals "copy_trie". -Axiom trie_root : - IsGlobalAlias globals trie.globals "root". -Axiom trie_trie_get : - IsGlobalAlias globals trie.globals "trie_get". -Axiom trie_trie_set : - IsGlobalAlias globals trie.globals "trie_set". +Require ethereum.gray_glacier.fork_types. +Axiom ethereum_gray_glacier_fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "EMPTY_ACCOUNT". +Axiom ethereum_gray_glacier_fork_types_Account : + IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "Account". +Axiom ethereum_gray_glacier_fork_types_Address : + IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "Address". +Axiom ethereum_gray_glacier_fork_types_Root : + IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "Root". + +Require ethereum.gray_glacier.trie. +Axiom ethereum_gray_glacier_trie_EMPTY_TRIE_ROOT : + IsGlobalAlias globals ethereum.gray_glacier.trie.globals "EMPTY_TRIE_ROOT". +Axiom ethereum_gray_glacier_trie_Trie : + IsGlobalAlias globals ethereum.gray_glacier.trie.globals "Trie". +Axiom ethereum_gray_glacier_trie_copy_trie : + IsGlobalAlias globals ethereum.gray_glacier.trie.globals "copy_trie". +Axiom ethereum_gray_glacier_trie_root : + IsGlobalAlias globals ethereum.gray_glacier.trie.globals "root". +Axiom ethereum_gray_glacier_trie_trie_get : + IsGlobalAlias globals ethereum.gray_glacier.trie.globals "trie_get". +Axiom ethereum_gray_glacier_trie_trie_set : + IsGlobalAlias globals ethereum.gray_glacier.trie.globals "trie_set". Definition State : Value.t := builtins.make_klass @@ -126,7 +126,7 @@ Definition begin_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) ], make_dict [] - |); (* At expr: unsupported node type: DictComp *) ] + |); Constant.str "(* At expr: unsupported node type: DictComp *)" ] ], make_dict [] |) in @@ -149,6 +149,19 @@ Definition commit_transaction : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "clear" |), + make_list [], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -174,6 +187,19 @@ Definition rollback_transaction : Value.t -> Value.t -> M := |) |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "clear" |), + make_list [], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -210,8 +236,27 @@ Definition get_account : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "account" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "account" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_ACCOUNT" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -246,6 +291,7 @@ Definition get_account_optional : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "account" |) + |) in M.pure Constant.None_)). Definition set_account : Value.t -> Value.t -> M := @@ -325,6 +371,18 @@ Definition destroy_storage : Value.t -> Value.t -> M := Address of account whose storage is to be deleted. " in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -387,6 +445,26 @@ Definition get_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "trie" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let value := @@ -408,6 +486,7 @@ Definition get_storage : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "value" |) + |) in M.pure Constant.None_)). Definition set_storage : Value.t -> Value.t -> M := @@ -448,6 +527,27 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "trie" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let trie := + M.call (| + M.get_name (| globals, "Trie" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), + M.get_name (| globals, "trie" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -460,6 +560,18 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + {} + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -484,8 +596,29 @@ Definition storage_root : Value.t -> Value.t -> M := " in let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_TRIE_ROOT" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -516,6 +649,7 @@ Definition state_root : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition account_exists : Value.t -> Value.t -> M := @@ -548,6 +682,7 @@ Definition account_exists : Value.t -> Value.t -> M := |), Constant.None_ |) + |) in M.pure Constant.None_)). Definition account_has_code_or_nonce : Value.t -> Value.t -> M := @@ -597,6 +732,7 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition is_account_empty : Value.t -> Value.t -> M := @@ -654,6 +790,7 @@ Definition is_account_empty : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition account_exists_and_is_empty : Value.t -> Value.t -> M := @@ -720,6 +857,7 @@ Definition account_exists_and_is_empty : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition is_account_alive : Value.t -> Value.t -> M := @@ -750,6 +888,20 @@ Definition is_account_alive : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "account" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| UnOp.not (| BoolOp.and (| Compare.eq (| @@ -777,6 +929,7 @@ Definition is_account_alive : Value.t -> Value.t -> M := |) )) |) |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -884,6 +1037,30 @@ Definition touch_account : Value.t -> Value.t -> M := The address of the account that need to initialised. " in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "account_exists" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "EMPTY_ACCOUNT" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -988,6 +1165,26 @@ Definition get_storage_original : Value.t -> Value.t -> M := Key of the storage slot. " in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -1003,6 +1200,25 @@ Definition get_storage_original : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "original_account_trie" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let original_value := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let original_value := M.call (| M.get_name (| globals, "trie_get" |), @@ -1024,4 +1240,5 @@ Definition get_storage_original : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "original_value" |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/transactions.v b/CoqOfPython/ethereum/gray_glacier/transactions.v index afa27ec..6057c15 100644 --- a/CoqOfPython/ethereum/gray_glacier/transactions.v +++ b/CoqOfPython/ethereum/gray_glacier/transactions.v @@ -19,33 +19,33 @@ Axiom typing_Tuple : Axiom typing_Union : IsGlobalAlias globals typing.globals "Union". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U64 : - IsGlobalAlias globals base_types.globals "U64". -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes0 : - IsGlobalAlias globals base_types.globals "Bytes0". -Axiom base_types_Bytes32 : - IsGlobalAlias globals base_types.globals "Bytes32". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require exceptions. -Axiom exceptions_InvalidBlock : - IsGlobalAlias globals exceptions.globals "InvalidBlock". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U64 : + IsGlobalAlias globals ethereum.base_types.globals "U64". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.exceptions. +Axiom ethereum_exceptions_InvalidBlock : + IsGlobalAlias globals ethereum.exceptions.globals "InvalidBlock". + +Require ethereum.gray_glacier.fork_types. +Axiom ethereum_gray_glacier_fork_types_Address : + IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "Address". Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( Constant.int 21000 @@ -112,15 +112,87 @@ Definition encode_transaction : Value.t -> Value.t -> M := Encode a transaction. Needed because non-legacy transactions aren't RLP. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "LegacyTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "tx" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "AccessListTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + Constant.bytes "01", + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "FeeMarketTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + Constant.bytes "02", + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.raise (| Some(M.call (| M.get_name (| globals, "Exception" |), make_list [ - (* At expr: unsupported node type: JoinedStr *) + Constant.str "(* At expr: unsupported node type: JoinedStr *)" ], make_dict [] - |)) + |)) |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -136,8 +208,73 @@ Definition decode_transaction : Value.t -> Value.t -> M := Decode a transaction. Needed because non-legacy transactions aren't RLP. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), + Constant.int 1 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), + make_list [ + M.get_name (| globals, "AccessListTransaction" |); + M.get_subscript (| M.get_name (| globals, "tx" |), M.slice (| Constant.int 1, Constant.None_ |) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), + Constant.int 2 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), + make_list [ + M.get_name (| globals, "FeeMarketTransaction" |); + M.get_subscript (| M.get_name (| globals, "tx" |), M.slice (| Constant.int 1, Constant.None_ |) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidBlock" |)) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "tx" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/trie.v b/CoqOfPython/ethereum/gray_glacier/trie.v index 8d425ef..abd999e 100644 --- a/CoqOfPython/ethereum/gray_glacier/trie.v +++ b/CoqOfPython/ethereum/gray_glacier/trie.v @@ -50,9 +50,9 @@ Axiom typing_Union : Axiom typing_cast : IsGlobalAlias globals typing.globals "cast". -Require ethereum.arrow_glacier. -Axiom ethereum_arrow_glacier_trie : - IsGlobalAlias globals ethereum.arrow_glacier.globals "trie". +Require ethereum.arrow_glacier.__init__. +Axiom ethereum_arrow_glacier___init___trie : + IsGlobalAlias globals ethereum.arrow_glacier.__init__.globals "trie". Require ethereum.crypto.hash. Axiom ethereum_crypto_hash_keccak256 : @@ -66,37 +66,37 @@ Require ethereum.utils.hexadecimal. Axiom ethereum_utils_hexadecimal_hex_to_bytes : IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require blocks. -Axiom blocks_Receipt : - IsGlobalAlias globals blocks.globals "Receipt". - -Require fork_types. -Axiom fork_types_Account : - IsGlobalAlias globals fork_types.globals "Account". -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". -Axiom fork_types_encode_account : - IsGlobalAlias globals fork_types.globals "encode_account". - -Require transactions. -Axiom transactions_LegacyTransaction : - IsGlobalAlias globals transactions.globals "LegacyTransaction". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.gray_glacier.blocks. +Axiom ethereum_gray_glacier_blocks_Receipt : + IsGlobalAlias globals ethereum.gray_glacier.blocks.globals "Receipt". + +Require ethereum.gray_glacier.fork_types. +Axiom ethereum_gray_glacier_fork_types_Account : + IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "Account". +Axiom ethereum_gray_glacier_fork_types_Address : + IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "Address". +Axiom ethereum_gray_glacier_fork_types_Root : + IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "Root". +Axiom ethereum_gray_glacier_fork_types_encode_account : + IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "encode_account". + +Require ethereum.gray_glacier.transactions. +Axiom ethereum_gray_glacier_transactions_LegacyTransaction : + IsGlobalAlias globals ethereum.gray_glacier.transactions.globals "LegacyTransaction". Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -202,16 +202,99 @@ Definition encode_internal_node : Value.t -> Value.t -> M := " in (* At stmt: unsupported node type: AnnAssign *) let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "node" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + Constant.bytes "" in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "LeafNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "rest_of_key" |); + Constant.bool true + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "ExtensionNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "key_segment" |); + Constant.bool false + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "BranchNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + BinOp.add (| + M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "value" |) + ] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ - (* At expr: unsupported node type: JoinedStr *) + Constant.str "(* At expr: unsupported node type: JoinedStr *)" ], make_dict [] - |)) + |)) |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -229,6 +312,26 @@ Definition encode_internal_node : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded" |) + ], + make_dict [] + |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "unencoded" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_name (| globals, "keccak256" |), @@ -237,6 +340,7 @@ Definition encode_internal_node : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -250,8 +354,86 @@ Definition encode_node : Value.t -> Value.t -> M := Currently mostly an unimplemented stub. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| + M.get_name (| globals, "storage_root" |), + Constant.None_ + |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "encode_account" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "storage_root" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "U256" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "cast" |), + make_list [ + M.get_field (| M.get_name (| globals, "rlp" |), "RLP" |); + M.get_name (| globals, "node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "node" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "previous_trie" |), "encode_node" |), @@ -261,6 +443,7 @@ Definition encode_node : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -312,6 +495,7 @@ Definition copy_trie : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition trie_set : Value.t -> Value.t -> M := @@ -333,6 +517,32 @@ Definition trie_set : Value.t -> Value.t -> M := Node to insert at `key`. " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + M.get_field (| M.get_name (| globals, "trie" |), "default" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "key" |), + M.get_field (| M.get_name (| globals, "trie" |), "_data" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), M.get_name (| globals, "value" |) @@ -370,6 +580,7 @@ Definition trie_get : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition common_prefix_length : Value.t -> Value.t -> M := @@ -392,6 +603,34 @@ Definition common_prefix_length : Value.t -> Value.t -> M := make_dict [] |) do let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), + M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -403,6 +642,7 @@ Definition common_prefix_length : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition nibble_list_to_compact : Value.t -> Value.t -> M := @@ -448,6 +688,71 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + Constant.int 2 + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.mult (| + Constant.int 16, + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "is_leaf" |) + |) + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ @@ -509,6 +814,7 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition bytes_to_nibble_list : Value.t -> Value.t -> M := @@ -586,6 +892,7 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition _prepare_trie : Value.t -> Value.t -> M := @@ -615,6 +922,48 @@ Definition _prepare_trie : Value.t -> Value.t -> M := make_dict [] |) do let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| + M.get_name (| globals, "get_storage_root" |), + Constant.None_ + |) |) in + let address := + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |); + M.call (| + M.get_name (| globals, "get_storage_root" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let encoded_value := M.call (| M.get_name (| globals, "encode_node" |), @@ -638,6 +987,22 @@ Definition _prepare_trie : Value.t -> Value.t -> M := |) in (* At stmt: unsupported node type: AnnAssign *) let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "trie" |), "secured" |), + (* then *) + ltac:(M.monadic ( + let key := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let key := M.get_name (| globals, "preimage" |) in M.pure Constant.None_ @@ -655,6 +1020,7 @@ Definition _prepare_trie : Value.t -> Value.t -> M := EndFor. let _ := M.return_ (| M.get_name (| globals, "mapped" |) + |) in M.pure Constant.None_)). Definition root : Value.t -> Value.t -> M := @@ -708,6 +1074,44 @@ Definition root : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -724,6 +1128,7 @@ Definition root : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -750,6 +1155,26 @@ Definition patricialize : Value.t -> Value.t -> M := Root node of `obj`. " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let arbitrary_key := @@ -767,10 +1192,39 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), + Constant.int 1 + |), + (* then *) + ltac:(M.monadic ( + let leaf := + M.call (| + M.get_name (| globals, "LeafNode" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |); + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "leaf" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let substring := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |) |) in + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) in let prefix_length := M.call (| M.get_name (| globals, "len" |), @@ -789,7 +1243,7 @@ Definition patricialize : Value.t -> Value.t -> M := M.get_name (| globals, "common_prefix_length" |), make_list [ M.get_name (| globals, "substring" |); - M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) + M.get_subscript (| M.get_name (| globals, "key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) ], make_dict [] |) @@ -797,10 +1251,64 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "prefix_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "prefix_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let prefix := + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ExtensionNode" |), + make_list [ + M.get_name (| globals, "prefix" |); + M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_name (| globals, "obj" |); + BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) @@ -823,6 +1331,44 @@ Definition patricialize : Value.t -> Value.t -> M := Constant.bytes "" in For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |), + M.get_name (| globals, "level" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "AssertionError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) @@ -834,9 +1380,10 @@ Definition patricialize : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "BranchNode" |), make_list [ - (* At expr: unsupported node type: ListComp *); + Constant.str "(* At expr: unsupported node type: ListComp *)"; M.get_name (| globals, "value" |) ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/utils/address.v b/CoqOfPython/ethereum/gray_glacier/utils/address.v index 25c52c0..c9d4f44 100644 --- a/CoqOfPython/ethereum/gray_glacier/utils/address.v +++ b/CoqOfPython/ethereum/gray_glacier/utils/address.v @@ -38,13 +38,13 @@ Require ethereum.utils.byte. Axiom ethereum_utils_byte_left_pad_zero_bytes : IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.gray_glacier.fork_types. +Axiom ethereum_gray_glacier_fork_types_Address : + IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "Address". Definition to_address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -70,10 +70,11 @@ Definition to_address : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), make_list [], make_dict [] - |), UnOp.sub (| Constant.int 20 |) |) + |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) ], make_dict [] |) + |) in M.pure Constant.None_)). Definition compute_contract_address : Value.t -> Value.t -> M := @@ -113,7 +114,7 @@ Definition compute_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -131,6 +132,7 @@ Definition compute_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition compute_create2_contract_address : Value.t -> Value.t -> M := @@ -180,7 +182,7 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -198,4 +200,5 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/utils/hexadecimal.v b/CoqOfPython/ethereum/gray_glacier/utils/hexadecimal.v index 8b66a3a..09a3916 100644 --- a/CoqOfPython/ethereum/gray_glacier/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/gray_glacier/utils/hexadecimal.v @@ -22,13 +22,13 @@ Require ethereum.utils.hexadecimal. Axiom ethereum_utils_hexadecimal_remove_hex_prefix : IsGlobalAlias globals ethereum.utils.hexadecimal.globals "remove_hex_prefix". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". +Require ethereum.gray_glacier.fork_types. +Axiom ethereum_gray_glacier_fork_types_Address : + IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "Address". +Axiom ethereum_gray_glacier_fork_types_Bloom : + IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "Bloom". +Axiom ethereum_gray_glacier_fork_types_Root : + IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "Root". Definition hex_to_root : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -66,6 +66,7 @@ Definition hex_to_root : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition hex_to_bloom : Value.t -> Value.t -> M := @@ -104,6 +105,7 @@ Definition hex_to_bloom : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition hex_to_address : Value.t -> Value.t -> M := @@ -149,4 +151,5 @@ Definition hex_to_address : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/utils/message.v b/CoqOfPython/ethereum/gray_glacier/utils/message.v index dead284..3775172 100644 --- a/CoqOfPython/ethereum/gray_glacier/utils/message.v +++ b/CoqOfPython/ethereum/gray_glacier/utils/message.v @@ -40,27 +40,27 @@ Axiom ethereum_base_types_Bytes32 : Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.gray_glacier.fork_types. +Axiom ethereum_gray_glacier_fork_types_Address : + IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "Address". -Require state. -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". +Require ethereum.gray_glacier.state. +Axiom ethereum_gray_glacier_state_get_account : + IsGlobalAlias globals ethereum.gray_glacier.state.globals "get_account". -Require vm. -Axiom vm_Environment : - IsGlobalAlias globals vm.globals "Environment". -Axiom vm_Message : - IsGlobalAlias globals vm.globals "Message". +Require ethereum.gray_glacier.vm.__init__. +Axiom ethereum_gray_glacier_vm___init___Environment : + IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Environment". +Axiom ethereum_gray_glacier_vm___init___Message : + IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Message". -Require vm.precompiled_contracts.mapping. -Axiom vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : - IsGlobalAlias globals vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". +Require ethereum.gray_glacier.vm.precompiled_contracts.mapping. +Axiom ethereum_gray_glacier_vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : + IsGlobalAlias globals ethereum.gray_glacier.vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". -Require address. -Axiom address_compute_contract_address : - IsGlobalAlias globals address.globals "compute_contract_address". +Require ethereum.gray_glacier.utils.address. +Axiom ethereum_gray_glacier_utils_address_compute_contract_address : + IsGlobalAlias globals ethereum.gray_glacier.utils.address.globals "compute_contract_address". Definition prepare_message : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -103,14 +103,108 @@ Definition prepare_message : Value.t -> Value.t -> M := Items containing contract creation or message call specific data. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Bytes0" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.call (| + M.get_name (| globals, "compute_contract_address" |), + make_list [ + M.get_name (| globals, "caller" |); + BinOp.sub (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "caller" |) + ], + make_dict [] + |), "nonce" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let msg_data := + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) in + let code := + M.get_name (| globals, "data" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.get_name (| globals, "target" |) in + let msg_data := + M.get_name (| globals, "data" |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "target" |) + ], + make_dict [] + |), "code" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "code_address" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let code_address := + M.get_name (| globals, "target" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "Target must be address or empty bytes" ], make_dict [] - |)) + |)) |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -159,4 +253,5 @@ Definition prepare_message : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/vm/__init__.v b/CoqOfPython/ethereum/gray_glacier/vm/__init__.v index 49da5ae..2aa9a09 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/__init__.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/__init__.v @@ -52,23 +52,23 @@ Require ethereum.crypto.hash. Axiom ethereum_crypto_hash_Hash32 : IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". +Require ethereum.gray_glacier.blocks. +Axiom ethereum_gray_glacier_blocks_Log : + IsGlobalAlias globals ethereum.gray_glacier.blocks.globals "Log". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.gray_glacier.fork_types. +Axiom ethereum_gray_glacier_fork_types_Address : + IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "Address". -Require state. -Axiom state_State : - IsGlobalAlias globals state.globals "State". -Axiom state_account_exists_and_is_empty : - IsGlobalAlias globals state.globals "account_exists_and_is_empty". +Require ethereum.gray_glacier.state. +Axiom ethereum_gray_glacier_state_State : + IsGlobalAlias globals ethereum.gray_glacier.state.globals "State". +Axiom ethereum_gray_glacier_state_account_exists_and_is_empty : + IsGlobalAlias globals ethereum.gray_glacier.state.globals "account_exists_and_is_empty". -Require precompiled_contracts. -Axiom precompiled_contracts_RIPEMD160_ADDRESS : - IsGlobalAlias globals precompiled_contracts.globals "RIPEMD160_ADDRESS". +Require ethereum.gray_glacier.vm.precompiled_contracts.__init__. +Axiom ethereum_gray_glacier_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : + IsGlobalAlias globals ethereum.gray_glacier.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] @@ -147,6 +147,28 @@ Definition incorporate_child_on_success : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -179,9 +201,63 @@ Definition incorporate_child_on_error : Value.t -> Value.t -> M := The child evm to incorporate. " in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "RIPEMD160_ADDRESS" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |), + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign_op (| diff --git a/CoqOfPython/ethereum/gray_glacier/vm/gas.v b/CoqOfPython/ethereum/gray_glacier/vm/gas.v index 549060b..640b543 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/gas.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/gas.v @@ -43,13 +43,13 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.gray_glacier.vm.__init__. +Axiom ethereum_gray_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Evm". -Require exceptions. -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". +Require ethereum.gray_glacier.vm.exceptions. +Axiom ethereum_gray_glacier_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.gray_glacier.vm.exceptions.globals "OutOfGasError". Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -500,6 +500,18 @@ Definition charge_gas : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "amount" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign_op (| BinOp.sub, M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), @@ -615,6 +627,18 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := |) in For make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ] in M.get_name (| globals, "extensions" |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "size" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let before_size := @@ -649,6 +673,18 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let size_to_extend := BinOp.add @@ -697,6 +733,7 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition calculate_message_call_gas : Value.t -> Value.t -> M := @@ -728,22 +765,56 @@ Definition calculate_message_call_gas : Value.t -> Value.t -> M := message_call_gas: `MessageCallGas` " in let call_stipend := - (* if *) -M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "call_stipend" |) + )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "gas_left" |), + BinOp.add (| + M.get_name (| globals, "extra_gas" |), + M.get_name (| globals, "memory_cost" |) + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallGas" |), + make_list [ + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "extra_gas" |) + |); + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "call_stipend" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let gas := @@ -782,6 +853,7 @@ M.call (| ], make_dict [] |) + |) in M.pure Constant.None_)). Definition max_message_call_gas : Value.t -> Value.t -> M := @@ -808,4 +880,5 @@ Definition max_message_call_gas : Value.t -> Value.t -> M := Constant.int 64 |) |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/__init__.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/__init__.v index e5bebd7..27d60b9 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/__init__.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/__init__.v @@ -26,53 +26,53 @@ Axiom typing_Callable : Axiom typing_Dict : IsGlobalAlias globals typing.globals "Dict". -Require __init__. -Axiom __init___arithmetic : - IsGlobalAlias globals __init__.globals "arithmetic". +Require ethereum.gray_glacier.vm.instructions.__init__. +Axiom ethereum_gray_glacier_vm_instructions___init___arithmetic : + IsGlobalAlias globals ethereum.gray_glacier.vm.instructions.__init__.globals "arithmetic". -Require __init__. -Axiom __init___bitwise : - IsGlobalAlias globals __init__.globals "bitwise". +Require ethereum.gray_glacier.vm.instructions.__init__. +Axiom ethereum_gray_glacier_vm_instructions___init___bitwise : + IsGlobalAlias globals ethereum.gray_glacier.vm.instructions.__init__.globals "bitwise". -Require __init__. -Axiom __init___block : - IsGlobalAlias globals __init__.globals "block". +Require ethereum.gray_glacier.vm.instructions.__init__. +Axiom ethereum_gray_glacier_vm_instructions___init___block : + IsGlobalAlias globals ethereum.gray_glacier.vm.instructions.__init__.globals "block". -Require __init__. -Axiom __init___comparison : - IsGlobalAlias globals __init__.globals "comparison". +Require ethereum.gray_glacier.vm.instructions.__init__. +Axiom ethereum_gray_glacier_vm_instructions___init___comparison : + IsGlobalAlias globals ethereum.gray_glacier.vm.instructions.__init__.globals "comparison". -Require __init__. -Axiom __init___control_flow : - IsGlobalAlias globals __init__.globals "control_flow". +Require ethereum.gray_glacier.vm.instructions.__init__. +Axiom ethereum_gray_glacier_vm_instructions___init___control_flow : + IsGlobalAlias globals ethereum.gray_glacier.vm.instructions.__init__.globals "control_flow". -Require __init__. -Axiom __init___environment : - IsGlobalAlias globals __init__.globals "environment". +Require ethereum.gray_glacier.vm.instructions.__init__. +Axiom ethereum_gray_glacier_vm_instructions___init___environment : + IsGlobalAlias globals ethereum.gray_glacier.vm.instructions.__init__.globals "environment". -Require __init__. -Axiom __init___keccak : - IsGlobalAlias globals __init__.globals "keccak". +Require ethereum.gray_glacier.vm.instructions.__init__. +Axiom ethereum_gray_glacier_vm_instructions___init___keccak : + IsGlobalAlias globals ethereum.gray_glacier.vm.instructions.__init__.globals "keccak". -Require __init__. -Axiom __init___log : - IsGlobalAlias globals __init__.globals "log". +Require ethereum.gray_glacier.vm.instructions.__init__. +Axiom ethereum_gray_glacier_vm_instructions___init___log : + IsGlobalAlias globals ethereum.gray_glacier.vm.instructions.__init__.globals "log". -Require __init__. -Axiom __init___memory : - IsGlobalAlias globals __init__.globals "memory". +Require ethereum.gray_glacier.vm.instructions.__init__. +Axiom ethereum_gray_glacier_vm_instructions___init___memory : + IsGlobalAlias globals ethereum.gray_glacier.vm.instructions.__init__.globals "memory". -Require __init__. -Axiom __init___stack : - IsGlobalAlias globals __init__.globals "stack". +Require ethereum.gray_glacier.vm.instructions.__init__. +Axiom ethereum_gray_glacier_vm_instructions___init___stack : + IsGlobalAlias globals ethereum.gray_glacier.vm.instructions.__init__.globals "stack". -Require __init__. -Axiom __init___storage : - IsGlobalAlias globals __init__.globals "storage". +Require ethereum.gray_glacier.vm.instructions.__init__. +Axiom ethereum_gray_glacier_vm_instructions___init___storage : + IsGlobalAlias globals ethereum.gray_glacier.vm.instructions.__init__.globals "storage". -Require __init__. -Axiom __init___system : - IsGlobalAlias globals __init__.globals "system". +Require ethereum.gray_glacier.vm.instructions.__init__. +Axiom ethereum_gray_glacier_vm_instructions___init___system : + IsGlobalAlias globals ethereum.gray_glacier.vm.instructions.__init__.globals "system". Definition Ops : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/arithmetic.v index 581ba5d..3a30545 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/arithmetic.v @@ -31,29 +31,29 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_get_sign : IsGlobalAlias globals ethereum.utils.numeric.globals "get_sign". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_EXPONENTIATION : - IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION". -Axiom gas_GAS_EXPONENTIATION_PER_BYTE : - IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION_PER_BYTE". -Axiom gas_GAS_LOW : - IsGlobalAlias globals gas.globals "GAS_LOW". -Axiom gas_GAS_MID : - IsGlobalAlias globals gas.globals "GAS_MID". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.gray_glacier.vm.__init__. +Axiom ethereum_gray_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Evm". + +Require ethereum.gray_glacier.vm.gas. +Axiom ethereum_gray_glacier_vm_gas_GAS_EXPONENTIATION : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_EXPONENTIATION". +Axiom ethereum_gray_glacier_vm_gas_GAS_EXPONENTIATION_PER_BYTE : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_EXPONENTIATION_PER_BYTE". +Axiom ethereum_gray_glacier_vm_gas_GAS_LOW : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_LOW". +Axiom ethereum_gray_glacier_vm_gas_GAS_MID : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_MID". +Axiom ethereum_gray_glacier_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_gray_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "charge_gas". + +Require ethereum.gray_glacier.vm.stack. +Axiom ethereum_gray_glacier_vm_stack_pop : + IsGlobalAlias globals ethereum.gray_glacier.vm.stack.globals "pop". +Axiom ethereum_gray_glacier_vm_stack_push : + IsGlobalAlias globals ethereum.gray_glacier.vm.stack.globals "push". Definition add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -273,6 +273,25 @@ Definition div : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "divisor" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let quotient := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let quotient := BinOp.floor_div (| M.get_name (| globals, "dividend" |), @@ -341,7 +360,41 @@ Definition sdiv : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "divisor" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let quotient := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_name (| globals, "dividend" |), + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "divisor" |), + UnOp.sub (| Constant.int 1 |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let quotient := + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let sign := M.call (| M.get_name (| globals, "get_sign" |), @@ -436,6 +489,25 @@ Definition mod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "y" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let remainder := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let remainder := BinOp.mod_ (| M.get_name (| globals, "x" |), @@ -504,6 +576,19 @@ Definition smod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "y" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let remainder := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let remainder := BinOp.mult (| M.call (| @@ -617,6 +702,25 @@ Definition addmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "z" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -712,6 +816,25 @@ Definition mulmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "z" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -881,6 +1004,19 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "byte_num" |), + Constant.int 31 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.get_name (| globals, "value" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let value_bytes := M.call (| M.get_name (| globals, "bytes" |), @@ -894,7 +1030,7 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let value_bytes := - M.get_subscript (| M.get_name (| globals, "value_bytes" |), BinOp.sub (| + M.get_subscript (| M.get_name (| globals, "value_bytes" |), M.slice (| BinOp.sub (| Constant.int 31, M.call (| M.get_name (| globals, "int" |), @@ -903,13 +1039,32 @@ Definition signextend : Value.t -> Value.t -> M := ], make_dict [] |) - |) |) in + |), Constant.None_ |) |) in let sign_bit := BinOp.r_shift (| M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), Constant.int 7 |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "sign_bit" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "value_bytes" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let num_bytes_prepend := BinOp.sub (| Constant.int 32, diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/bitwise.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/bitwise.v index 64cf120..196ce46 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/bitwise.v @@ -23,21 +23,21 @@ Axiom ethereum_base_types_U256 : Axiom ethereum_base_types_U256_CEIL_VALUE : IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.gray_glacier.vm.__init__. +Axiom ethereum_gray_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.gray_glacier.vm.gas. +Axiom ethereum_gray_glacier_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_gray_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "charge_gas". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.gray_glacier.vm.stack. +Axiom ethereum_gray_glacier_vm_stack_pop : + IsGlobalAlias globals ethereum.gray_glacier.vm.stack.globals "pop". +Axiom ethereum_gray_glacier_vm_stack_push : + IsGlobalAlias globals ethereum.gray_glacier.vm.stack.globals "push". Definition bitwise_and : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -287,6 +287,25 @@ Definition get_byte : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "byte_index" |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let extra_bytes_to_right := BinOp.sub (| Constant.int 31, @@ -366,6 +385,31 @@ Definition bitwise_shl : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "shift" |), + Constant.int 256 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.l_shift (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "shift" |) + |), + M.get_name (| globals, "U256_CEIL_VALUE" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -427,6 +471,22 @@ Definition bitwise_shr : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "shift" |), + Constant.int 256 + |), + (* then *) + ltac:(M.monadic ( + let result := + BinOp.r_shift (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "shift" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -492,7 +552,48 @@ Definition bitwise_sar : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "shift" |), + Constant.int 256 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + BinOp.r_shift (| + M.get_name (| globals, "signed_value" |), + M.get_name (| globals, "shift" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "signed_value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/block.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/block.v index f857b79..ef75123 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/block.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/block.v @@ -21,23 +21,23 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_BLOCK_HASH : - IsGlobalAlias globals gas.globals "GAS_BLOCK_HASH". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.gray_glacier.vm.__init__. +Axiom ethereum_gray_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Evm". + +Require ethereum.gray_glacier.vm.gas. +Axiom ethereum_gray_glacier_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_BASE". +Axiom ethereum_gray_glacier_vm_gas_GAS_BLOCK_HASH : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_BLOCK_HASH". +Axiom ethereum_gray_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "charge_gas". + +Require ethereum.gray_glacier.vm.stack. +Axiom ethereum_gray_glacier_vm_stack_pop : + IsGlobalAlias globals ethereum.gray_glacier.vm.stack.globals "pop". +Axiom ethereum_gray_glacier_vm_stack_push : + IsGlobalAlias globals ethereum.gray_glacier.vm.stack.globals "push". Definition block_hash : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -69,6 +69,30 @@ Definition block_hash : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt_e (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + M.get_name (| globals, "block_number" |) + |), + ltac:(M.monadic ( + Compare.gt (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + BinOp.add (| + M.get_name (| globals, "block_number" |), + Constant.int 256 + |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let hash := + Constant.bytes "00" in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let hash := M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/comparison.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/comparison.v index b8529d8..cebb228 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/comparison.v @@ -21,21 +21,21 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.gray_glacier.vm.__init__. +Axiom ethereum_gray_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.gray_glacier.vm.gas. +Axiom ethereum_gray_glacier_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_gray_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "charge_gas". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.gray_glacier.vm.stack. +Axiom ethereum_gray_glacier_vm_stack_pop : + IsGlobalAlias globals ethereum.gray_glacier.vm.stack.globals "pop". +Axiom ethereum_gray_glacier_vm_stack_push : + IsGlobalAlias globals ethereum.gray_glacier.vm.stack.globals "push". Definition less_than : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/control_flow.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/control_flow.v index d4e4eae..781ffd8 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/control_flow.v @@ -23,31 +23,31 @@ Axiom ethereum_base_types_U256 : Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require vm.gas. -Axiom vm_gas_GAS_BASE : - IsGlobalAlias globals vm.gas.globals "GAS_BASE". -Axiom vm_gas_GAS_HIGH : - IsGlobalAlias globals vm.gas.globals "GAS_HIGH". -Axiom vm_gas_GAS_JUMPDEST : - IsGlobalAlias globals vm.gas.globals "GAS_JUMPDEST". -Axiom vm_gas_GAS_MID : - IsGlobalAlias globals vm.gas.globals "GAS_MID". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.gray_glacier.vm.gas. +Axiom ethereum_gray_glacier_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_BASE". +Axiom ethereum_gray_glacier_vm_gas_GAS_HIGH : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_HIGH". +Axiom ethereum_gray_glacier_vm_gas_GAS_JUMPDEST : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_JUMPDEST". +Axiom ethereum_gray_glacier_vm_gas_GAS_MID : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_MID". +Axiom ethereum_gray_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "charge_gas". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.gray_glacier.vm.__init__. +Axiom ethereum_gray_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Evm". -Require exceptions. -Axiom exceptions_InvalidJumpDestError : - IsGlobalAlias globals exceptions.globals "InvalidJumpDestError". +Require ethereum.gray_glacier.vm.exceptions. +Axiom ethereum_gray_glacier_vm_exceptions_InvalidJumpDestError : + IsGlobalAlias globals ethereum.gray_glacier.vm.exceptions.globals "InvalidJumpDestError". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.gray_glacier.vm.stack. +Axiom ethereum_gray_glacier_vm_stack_pop : + IsGlobalAlias globals ethereum.gray_glacier.vm.stack.globals "pop". +Axiom ethereum_gray_glacier_vm_stack_push : + IsGlobalAlias globals ethereum.gray_glacier.vm.stack.globals "push". Definition stop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -109,6 +109,18 @@ Definition jump : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "jump_dest" |), + M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -168,7 +180,35 @@ Definition jumpi : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "conditional_value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let destination := + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "jump_dest" |), + M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let destination := M.get_name (| globals, "jump_dest" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/environment.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/environment.v index 10bc05b..d4843ce 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/environment.v @@ -35,57 +35,57 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require fork_types. -Axiom fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". - -Require state. -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". - -Require utils.address. -Axiom utils_address_to_address : - IsGlobalAlias globals utils.address.globals "to_address". - -Require vm.memory. -Axiom vm_memory_buffer_read : - IsGlobalAlias globals vm.memory.globals "buffer_read". -Axiom vm_memory_memory_write : - IsGlobalAlias globals vm.memory.globals "memory_write". - -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require exceptions. -Axiom exceptions_OutOfBoundsRead : - IsGlobalAlias globals exceptions.globals "OutOfBoundsRead". - -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_COLD_ACCOUNT_ACCESS : - IsGlobalAlias globals gas.globals "GAS_COLD_ACCOUNT_ACCESS". -Axiom gas_GAS_COPY : - IsGlobalAlias globals gas.globals "GAS_COPY". -Axiom gas_GAS_FAST_STEP : - IsGlobalAlias globals gas.globals "GAS_FAST_STEP". -Axiom gas_GAS_RETURN_DATA_COPY : - IsGlobalAlias globals gas.globals "GAS_RETURN_DATA_COPY". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_GAS_WARM_ACCESS : - IsGlobalAlias globals gas.globals "GAS_WARM_ACCESS". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.gray_glacier.fork_types. +Axiom ethereum_gray_glacier_fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "EMPTY_ACCOUNT". + +Require ethereum.gray_glacier.state. +Axiom ethereum_gray_glacier_state_get_account : + IsGlobalAlias globals ethereum.gray_glacier.state.globals "get_account". + +Require ethereum.gray_glacier.utils.address. +Axiom ethereum_gray_glacier_utils_address_to_address : + IsGlobalAlias globals ethereum.gray_glacier.utils.address.globals "to_address". + +Require ethereum.gray_glacier.vm.memory. +Axiom ethereum_gray_glacier_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.gray_glacier.vm.memory.globals "buffer_read". +Axiom ethereum_gray_glacier_vm_memory_memory_write : + IsGlobalAlias globals ethereum.gray_glacier.vm.memory.globals "memory_write". + +Require ethereum.gray_glacier.vm.__init__. +Axiom ethereum_gray_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Evm". + +Require ethereum.gray_glacier.vm.exceptions. +Axiom ethereum_gray_glacier_vm_exceptions_OutOfBoundsRead : + IsGlobalAlias globals ethereum.gray_glacier.vm.exceptions.globals "OutOfBoundsRead". + +Require ethereum.gray_glacier.vm.gas. +Axiom ethereum_gray_glacier_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_BASE". +Axiom ethereum_gray_glacier_vm_gas_GAS_COLD_ACCOUNT_ACCESS : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_COLD_ACCOUNT_ACCESS". +Axiom ethereum_gray_glacier_vm_gas_GAS_COPY : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_COPY". +Axiom ethereum_gray_glacier_vm_gas_GAS_FAST_STEP : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_FAST_STEP". +Axiom ethereum_gray_glacier_vm_gas_GAS_RETURN_DATA_COPY : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_RETURN_DATA_COPY". +Axiom ethereum_gray_glacier_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_gray_glacier_vm_gas_GAS_WARM_ACCESS : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_WARM_ACCESS". +Axiom ethereum_gray_glacier_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_gray_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "charge_gas". + +Require ethereum.gray_glacier.vm.stack. +Axiom ethereum_gray_glacier_vm_stack_pop : + IsGlobalAlias globals ethereum.gray_glacier.vm.stack.globals "pop". +Axiom ethereum_gray_glacier_vm_stack_push : + IsGlobalAlias globals ethereum.gray_glacier.vm.stack.globals "push". Definition address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -156,6 +156,25 @@ Definition balance : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -789,6 +808,25 @@ Definition extcodesize : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -926,6 +964,31 @@ Definition extcodecopy : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_WARM_ACCESS" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1162,7 +1225,10 @@ Definition returndatacopy : Value.t -> Value.t -> M := |) |) in let value := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |) |) in + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.slice (| M.get_name (| globals, "return_data_start_position" |), BinOp.add (| + M.get_name (| globals, "return_data_start_position" |), + M.get_name (| globals, "size" |) + |) |) |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -1204,6 +1270,25 @@ Definition extcodehash : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1231,6 +1316,25 @@ Definition extcodehash : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "account" |), + M.get_name (| globals, "EMPTY_ACCOUNT" |) + |), + (* then *) + ltac:(M.monadic ( + let codehash := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let codehash := M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/keccak.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/keccak.v index 2c4b10e..dc92c68 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/keccak.v @@ -31,29 +31,29 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_KECCAK256 : - IsGlobalAlias globals gas.globals "GAS_KECCAK256". -Axiom gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.gray_glacier.vm.__init__. +Axiom ethereum_gray_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Evm". + +Require ethereum.gray_glacier.vm.gas. +Axiom ethereum_gray_glacier_vm_gas_GAS_KECCAK256 : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_KECCAK256". +Axiom ethereum_gray_glacier_vm_gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_KECCAK256_WORD". +Axiom ethereum_gray_glacier_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_gray_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "charge_gas". + +Require ethereum.gray_glacier.vm.memory. +Axiom ethereum_gray_glacier_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.gray_glacier.vm.memory.globals "memory_read_bytes". + +Require ethereum.gray_glacier.vm.stack. +Axiom ethereum_gray_glacier_vm_stack_pop : + IsGlobalAlias globals ethereum.gray_glacier.vm.stack.globals "pop". +Axiom ethereum_gray_glacier_vm_stack_push : + IsGlobalAlias globals ethereum.gray_glacier.vm.stack.globals "push". Definition keccak : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/log.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/log.v index e084e59..d7f8075 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/log.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/log.v @@ -29,37 +29,37 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". - -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require exceptions. -Axiom exceptions_WriteInStaticContext : - IsGlobalAlias globals exceptions.globals "WriteInStaticContext". - -Require gas. -Axiom gas_GAS_LOG : - IsGlobalAlias globals gas.globals "GAS_LOG". -Axiom gas_GAS_LOG_DATA : - IsGlobalAlias globals gas.globals "GAS_LOG_DATA". -Axiom gas_GAS_LOG_TOPIC : - IsGlobalAlias globals gas.globals "GAS_LOG_TOPIC". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". +Require ethereum.gray_glacier.blocks. +Axiom ethereum_gray_glacier_blocks_Log : + IsGlobalAlias globals ethereum.gray_glacier.blocks.globals "Log". + +Require ethereum.gray_glacier.vm.__init__. +Axiom ethereum_gray_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Evm". + +Require ethereum.gray_glacier.vm.exceptions. +Axiom ethereum_gray_glacier_vm_exceptions_WriteInStaticContext : + IsGlobalAlias globals ethereum.gray_glacier.vm.exceptions.globals "WriteInStaticContext". + +Require ethereum.gray_glacier.vm.gas. +Axiom ethereum_gray_glacier_vm_gas_GAS_LOG : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_LOG". +Axiom ethereum_gray_glacier_vm_gas_GAS_LOG_DATA : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_LOG_DATA". +Axiom ethereum_gray_glacier_vm_gas_GAS_LOG_TOPIC : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_LOG_TOPIC". +Axiom ethereum_gray_glacier_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_gray_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "charge_gas". + +Require ethereum.gray_glacier.vm.memory. +Axiom ethereum_gray_glacier_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.gray_glacier.vm.memory.globals "memory_read_bytes". + +Require ethereum.gray_glacier.vm.stack. +Axiom ethereum_gray_glacier_vm_stack_pop : + IsGlobalAlias globals ethereum.gray_glacier.vm.stack.globals "pop". Definition log_n : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/memory.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/memory.v index 86ba742..a2a84f5 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/memory.v @@ -23,31 +23,31 @@ Axiom ethereum_base_types_U256 : Axiom ethereum_base_types_Bytes : IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.gray_glacier.vm.__init__. +Axiom ethereum_gray_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.gray_glacier.vm.gas. +Axiom ethereum_gray_glacier_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_BASE". +Axiom ethereum_gray_glacier_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_gray_glacier_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_gray_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "charge_gas". -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". -Axiom memory_memory_write : - IsGlobalAlias globals memory.globals "memory_write". +Require ethereum.gray_glacier.vm.memory. +Axiom ethereum_gray_glacier_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.gray_glacier.vm.memory.globals "memory_read_bytes". +Axiom ethereum_gray_glacier_vm_memory_memory_write : + IsGlobalAlias globals ethereum.gray_glacier.vm.memory.globals "memory_write". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.gray_glacier.vm.stack. +Axiom ethereum_gray_glacier_vm_stack_pop : + IsGlobalAlias globals ethereum.gray_glacier.vm.stack.globals "pop". +Axiom ethereum_gray_glacier_vm_stack_push : + IsGlobalAlias globals ethereum.gray_glacier.vm.stack.globals "push". Definition mstore : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/stack.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/stack.v index 305af15..4ff75c7 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/stack.v @@ -29,27 +29,27 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". -Axiom __init___stack : - IsGlobalAlias globals __init__.globals "stack". - -Require exceptions. -Axiom exceptions_StackUnderflowError : - IsGlobalAlias globals exceptions.globals "StackUnderflowError". - -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require memory. -Axiom memory_buffer_read : - IsGlobalAlias globals memory.globals "buffer_read". +Require ethereum.gray_glacier.vm.__init__. +Axiom ethereum_gray_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Evm". +Axiom ethereum_gray_glacier_vm___init___stack : + IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "stack". + +Require ethereum.gray_glacier.vm.exceptions. +Axiom ethereum_gray_glacier_vm_exceptions_StackUnderflowError : + IsGlobalAlias globals ethereum.gray_glacier.vm.exceptions.globals "StackUnderflowError". + +Require ethereum.gray_glacier.vm.gas. +Axiom ethereum_gray_glacier_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_BASE". +Axiom ethereum_gray_glacier_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_gray_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "charge_gas". + +Require ethereum.gray_glacier.vm.memory. +Axiom ethereum_gray_glacier_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.gray_glacier.vm.memory.globals "buffer_read". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/storage.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/storage.v index b3c4045..846db44 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/storage.v @@ -25,45 +25,45 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require state. -Axiom state_get_storage : - IsGlobalAlias globals state.globals "get_storage". -Axiom state_get_storage_original : - IsGlobalAlias globals state.globals "get_storage_original". -Axiom state_set_storage : - IsGlobalAlias globals state.globals "set_storage". - -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require exceptions. -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". -Axiom exceptions_WriteInStaticContext : - IsGlobalAlias globals exceptions.globals "WriteInStaticContext". - -Require gas. -Axiom gas_GAS_CALL_STIPEND : - IsGlobalAlias globals gas.globals "GAS_CALL_STIPEND". -Axiom gas_GAS_COLD_SLOAD : - IsGlobalAlias globals gas.globals "GAS_COLD_SLOAD". -Axiom gas_GAS_STORAGE_CLEAR_REFUND : - IsGlobalAlias globals gas.globals "GAS_STORAGE_CLEAR_REFUND". -Axiom gas_GAS_STORAGE_SET : - IsGlobalAlias globals gas.globals "GAS_STORAGE_SET". -Axiom gas_GAS_STORAGE_UPDATE : - IsGlobalAlias globals gas.globals "GAS_STORAGE_UPDATE". -Axiom gas_GAS_WARM_ACCESS : - IsGlobalAlias globals gas.globals "GAS_WARM_ACCESS". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.gray_glacier.state. +Axiom ethereum_gray_glacier_state_get_storage : + IsGlobalAlias globals ethereum.gray_glacier.state.globals "get_storage". +Axiom ethereum_gray_glacier_state_get_storage_original : + IsGlobalAlias globals ethereum.gray_glacier.state.globals "get_storage_original". +Axiom ethereum_gray_glacier_state_set_storage : + IsGlobalAlias globals ethereum.gray_glacier.state.globals "set_storage". + +Require ethereum.gray_glacier.vm.__init__. +Axiom ethereum_gray_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Evm". + +Require ethereum.gray_glacier.vm.exceptions. +Axiom ethereum_gray_glacier_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.gray_glacier.vm.exceptions.globals "OutOfGasError". +Axiom ethereum_gray_glacier_vm_exceptions_WriteInStaticContext : + IsGlobalAlias globals ethereum.gray_glacier.vm.exceptions.globals "WriteInStaticContext". + +Require ethereum.gray_glacier.vm.gas. +Axiom ethereum_gray_glacier_vm_gas_GAS_CALL_STIPEND : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_CALL_STIPEND". +Axiom ethereum_gray_glacier_vm_gas_GAS_COLD_SLOAD : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_COLD_SLOAD". +Axiom ethereum_gray_glacier_vm_gas_GAS_STORAGE_CLEAR_REFUND : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_STORAGE_CLEAR_REFUND". +Axiom ethereum_gray_glacier_vm_gas_GAS_STORAGE_SET : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_STORAGE_SET". +Axiom ethereum_gray_glacier_vm_gas_GAS_STORAGE_UPDATE : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_STORAGE_UPDATE". +Axiom ethereum_gray_glacier_vm_gas_GAS_WARM_ACCESS : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_WARM_ACCESS". +Axiom ethereum_gray_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "charge_gas". + +Require ethereum.gray_glacier.vm.stack. +Axiom ethereum_gray_glacier_vm_stack_pop : + IsGlobalAlias globals ethereum.gray_glacier.vm.stack.globals "pop". +Axiom ethereum_gray_glacier_vm_stack_push : + IsGlobalAlias globals ethereum.gray_glacier.vm.stack.globals "push". Definition sload : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -91,6 +91,25 @@ Definition sload : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], + M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "add" |), make_list [ @@ -205,15 +224,225 @@ Definition sstore : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], + M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "add" |), + make_list [ + make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ] + ], + make_dict [] + |) in + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_COLD_SLOAD" |) + M.get_name (| globals, "GAS_COLD_SLOAD" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_name (| globals, "original_value" |), + M.get_name (| globals, "current_value" |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "current_value" |), + M.get_name (| globals, "new_value" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "original_value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_STORAGE_SET" |) + M.get_name (| globals, "GAS_STORAGE_SET" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let gas_cost := BinOp.add + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_UPDATE" |), + M.get_name (| globals, "GAS_COLD_SLOAD" |) + |) + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_UPDATE" |), + M.get_name (| globals, "GAS_COLD_SLOAD" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let gas_cost := BinOp.add M.get_name (| globals, "GAS_WARM_ACCESS" |) M.get_name (| globals, "GAS_WARM_ACCESS" |) in M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| + M.get_name (| globals, "current_value" |), + M.get_name (| globals, "new_value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "original_value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "current_value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "new_value" |), + Constant.int 0 + |) + )) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "original_value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "current_value" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.sub, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "original_value" |), + M.get_name (| globals, "new_value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "original_value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_SET" |), + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.sub (| + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_UPDATE" |), + M.get_name (| globals, "GAS_COLD_SLOAD" |) + |), + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/system.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/system.v index 03931b2..5df4fd8 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/system.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/system.v @@ -33,87 +33,87 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.gray_glacier.fork_types. +Axiom ethereum_gray_glacier_fork_types_Address : + IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "Address". -Require state. -Axiom state_account_exists_and_is_empty : - IsGlobalAlias globals state.globals "account_exists_and_is_empty". -Axiom state_account_has_code_or_nonce : - IsGlobalAlias globals state.globals "account_has_code_or_nonce". -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". -Axiom state_increment_nonce : - IsGlobalAlias globals state.globals "increment_nonce". -Axiom state_is_account_alive : - IsGlobalAlias globals state.globals "is_account_alive". -Axiom state_set_account_balance : - IsGlobalAlias globals state.globals "set_account_balance". +Require ethereum.gray_glacier.state. +Axiom ethereum_gray_glacier_state_account_exists_and_is_empty : + IsGlobalAlias globals ethereum.gray_glacier.state.globals "account_exists_and_is_empty". +Axiom ethereum_gray_glacier_state_account_has_code_or_nonce : + IsGlobalAlias globals ethereum.gray_glacier.state.globals "account_has_code_or_nonce". +Axiom ethereum_gray_glacier_state_get_account : + IsGlobalAlias globals ethereum.gray_glacier.state.globals "get_account". +Axiom ethereum_gray_glacier_state_increment_nonce : + IsGlobalAlias globals ethereum.gray_glacier.state.globals "increment_nonce". +Axiom ethereum_gray_glacier_state_is_account_alive : + IsGlobalAlias globals ethereum.gray_glacier.state.globals "is_account_alive". +Axiom ethereum_gray_glacier_state_set_account_balance : + IsGlobalAlias globals ethereum.gray_glacier.state.globals "set_account_balance". -Require utils.address. -Axiom utils_address_compute_contract_address : - IsGlobalAlias globals utils.address.globals "compute_contract_address". -Axiom utils_address_compute_create2_contract_address : - IsGlobalAlias globals utils.address.globals "compute_create2_contract_address". -Axiom utils_address_to_address : - IsGlobalAlias globals utils.address.globals "to_address". +Require ethereum.gray_glacier.utils.address. +Axiom ethereum_gray_glacier_utils_address_compute_contract_address : + IsGlobalAlias globals ethereum.gray_glacier.utils.address.globals "compute_contract_address". +Axiom ethereum_gray_glacier_utils_address_compute_create2_contract_address : + IsGlobalAlias globals ethereum.gray_glacier.utils.address.globals "compute_create2_contract_address". +Axiom ethereum_gray_glacier_utils_address_to_address : + IsGlobalAlias globals ethereum.gray_glacier.utils.address.globals "to_address". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". -Axiom __init___Message : - IsGlobalAlias globals __init__.globals "Message". -Axiom __init___incorporate_child_on_error : - IsGlobalAlias globals __init__.globals "incorporate_child_on_error". -Axiom __init___incorporate_child_on_success : - IsGlobalAlias globals __init__.globals "incorporate_child_on_success". +Require ethereum.gray_glacier.vm.__init__. +Axiom ethereum_gray_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Evm". +Axiom ethereum_gray_glacier_vm___init___Message : + IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Message". +Axiom ethereum_gray_glacier_vm___init___incorporate_child_on_error : + IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "incorporate_child_on_error". +Axiom ethereum_gray_glacier_vm___init___incorporate_child_on_success : + IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "incorporate_child_on_success". -Require exceptions. -Axiom exceptions_Revert : - IsGlobalAlias globals exceptions.globals "Revert". -Axiom exceptions_WriteInStaticContext : - IsGlobalAlias globals exceptions.globals "WriteInStaticContext". +Require ethereum.gray_glacier.vm.exceptions. +Axiom ethereum_gray_glacier_vm_exceptions_Revert : + IsGlobalAlias globals ethereum.gray_glacier.vm.exceptions.globals "Revert". +Axiom ethereum_gray_glacier_vm_exceptions_WriteInStaticContext : + IsGlobalAlias globals ethereum.gray_glacier.vm.exceptions.globals "WriteInStaticContext". -Require gas. -Axiom gas_GAS_CALL_VALUE : - IsGlobalAlias globals gas.globals "GAS_CALL_VALUE". -Axiom gas_GAS_COLD_ACCOUNT_ACCESS : - IsGlobalAlias globals gas.globals "GAS_COLD_ACCOUNT_ACCESS". -Axiom gas_GAS_CREATE : - IsGlobalAlias globals gas.globals "GAS_CREATE". -Axiom gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". -Axiom gas_GAS_NEW_ACCOUNT : - IsGlobalAlias globals gas.globals "GAS_NEW_ACCOUNT". -Axiom gas_GAS_SELF_DESTRUCT : - IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT". -Axiom gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : - IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". -Axiom gas_GAS_WARM_ACCESS : - IsGlobalAlias globals gas.globals "GAS_WARM_ACCESS". -Axiom gas_GAS_ZERO : - IsGlobalAlias globals gas.globals "GAS_ZERO". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_calculate_message_call_gas : - IsGlobalAlias globals gas.globals "calculate_message_call_gas". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". -Axiom gas_max_message_call_gas : - IsGlobalAlias globals gas.globals "max_message_call_gas". +Require ethereum.gray_glacier.vm.gas. +Axiom ethereum_gray_glacier_vm_gas_GAS_CALL_VALUE : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_CALL_VALUE". +Axiom ethereum_gray_glacier_vm_gas_GAS_COLD_ACCOUNT_ACCESS : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_COLD_ACCOUNT_ACCESS". +Axiom ethereum_gray_glacier_vm_gas_GAS_CREATE : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_CREATE". +Axiom ethereum_gray_glacier_vm_gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_KECCAK256_WORD". +Axiom ethereum_gray_glacier_vm_gas_GAS_NEW_ACCOUNT : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_NEW_ACCOUNT". +Axiom ethereum_gray_glacier_vm_gas_GAS_SELF_DESTRUCT : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_SELF_DESTRUCT". +Axiom ethereum_gray_glacier_vm_gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". +Axiom ethereum_gray_glacier_vm_gas_GAS_WARM_ACCESS : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_WARM_ACCESS". +Axiom ethereum_gray_glacier_vm_gas_GAS_ZERO : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_ZERO". +Axiom ethereum_gray_glacier_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_gray_glacier_vm_gas_calculate_message_call_gas : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "calculate_message_call_gas". +Axiom ethereum_gray_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "charge_gas". +Axiom ethereum_gray_glacier_vm_gas_max_message_call_gas : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "max_message_call_gas". -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". -Axiom memory_memory_write : - IsGlobalAlias globals memory.globals "memory_write". +Require ethereum.gray_glacier.vm.memory. +Axiom ethereum_gray_glacier_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.gray_glacier.vm.memory.globals "memory_read_bytes". +Axiom ethereum_gray_glacier_vm_memory_memory_write : + IsGlobalAlias globals ethereum.gray_glacier.vm.memory.globals "memory_write". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.gray_glacier.vm.stack. +Axiom ethereum_gray_glacier_vm_stack_pop : + IsGlobalAlias globals ethereum.gray_glacier.vm.stack.globals "pop". +Axiom ethereum_gray_glacier_vm_stack_push : + IsGlobalAlias globals ethereum.gray_glacier.vm.stack.globals "push". Definition generic_create : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -172,9 +172,113 @@ Definition generic_create : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt (| + M.get_field (| M.get_name (| globals, "sender" |), "balance" |), + M.get_name (| globals, "endowment" |) + |), + ltac:(M.monadic ( + BoolOp.or (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "sender" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.sub (| + BinOp.pow (| + Constant.int 2, + Constant.int 64 + |), + Constant.int 1 + |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.gt (| + BinOp.add (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "depth" |), + Constant.int 1 + |), + M.get_name (| globals, "STACK_DEPTH_LIMIT" |) + |) + )) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "create_message_gas" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "contract_address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let call_data := @@ -211,6 +315,40 @@ Definition generic_create : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "child_evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_error" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "incorporate_child_on_success" |), make_list [ @@ -567,6 +705,42 @@ Definition generic_call : Value.t -> Value.t -> M := Constant.bytes "" |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + BinOp.add (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "depth" |), + Constant.int 1 + |), + M.get_name (| globals, "STACK_DEPTH_LIMIT" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "gas" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let call_data := @@ -604,6 +778,40 @@ Definition generic_call : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "child_evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_error" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "incorporate_child_on_success" |), make_list [ @@ -658,7 +866,7 @@ Definition generic_call : Value.t -> Value.t -> M := make_list [ M.get_field (| M.get_name (| globals, "evm" |), "memory" |); M.get_name (| globals, "memory_output_start_position" |); - M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), Constant.None_:M.get_name (| globals, "actual_output_size" |) |) + M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), M.slice (| Constant.None_, M.get_name (| globals, "actual_output_size" |) |) |) ], make_dict [] |) in @@ -756,6 +964,19 @@ Definition call : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "to" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let access_gas_cost := + M.get_name (| globals, "GAS_WARM_ACCESS" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -768,49 +989,57 @@ Definition call : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in let create_gas_cost := - (* if *) -M.if_then_else (| - BoolOp.or (| - M.call (| - M.get_name (| globals, "is_account_alive" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); - M.get_name (| globals, "to" |) - ], - make_dict [] - |), - ltac:(M.monadic ( - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |) - )) - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + BoolOp.or (| + M.call (| + M.get_name (| globals, "is_account_alive" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "to" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "GAS_NEW_ACCOUNT" |) + )) |) in let transfer_gas_cost := - (* if *) -M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "GAS_CALL_VALUE" |) + )) |) in let message_call_gas := M.call (| M.get_name (| globals, "calculate_message_call_gas" |), @@ -886,6 +1115,40 @@ M.call (| make_dict [] |), "balance" |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "sender_balance" |), + M.get_name (| globals, "value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "generic_call" |), make_list [ @@ -1007,6 +1270,19 @@ Definition callcode : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "code_address" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let access_gas_cost := + M.get_name (| globals, "GAS_WARM_ACCESS" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1019,21 +1295,25 @@ Definition callcode : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in let transfer_gas_cost := - (* if *) -M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "GAS_CALL_VALUE" |) + )) |) in let message_call_gas := M.call (| M.get_name (| globals, "calculate_message_call_gas" |), @@ -1084,6 +1364,40 @@ M.call (| make_dict [] |), "balance" |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "sender_balance" |), + M.get_name (| globals, "value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "generic_call" |), make_list [ @@ -1139,9 +1453,63 @@ Definition selfdestruct : Value.t -> Value.t -> M := let gas_cost := M.get_name (| globals, "GAS_SELF_DESTRUCT" |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "beneficiary" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |) in + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + UnOp.not (| M.call (| + M.get_name (| globals, "is_account_alive" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) + M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -1215,6 +1583,28 @@ Definition selfdestruct : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -1308,6 +1698,19 @@ Definition delegatecall : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "code_address" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let access_gas_cost := + M.get_name (| globals, "GAS_WARM_ACCESS" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1471,6 +1874,19 @@ Definition staticcall : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "to" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let access_gas_cost := + M.get_name (| globals, "GAS_WARM_ACCESS" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1630,6 +2046,6 @@ Definition revert : Value.t -> Value.t -> M := make_dict [] |) |) in - let _ := M.raise (| Some(M.get_name (| globals, "Revert" |)) + let _ := M.raise (| Some(M.get_name (| globals, "Revert" |)) |) in let _ := M.pass (| |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/vm/interpreter.v b/CoqOfPython/ethereum/gray_glacier/vm/interpreter.v index 024d2d5..fe17b9d 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/interpreter.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/interpreter.v @@ -61,83 +61,83 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". - -Require state. -Axiom state_account_exists_and_is_empty : - IsGlobalAlias globals state.globals "account_exists_and_is_empty". -Axiom state_account_has_code_or_nonce : - IsGlobalAlias globals state.globals "account_has_code_or_nonce". -Axiom state_begin_transaction : - IsGlobalAlias globals state.globals "begin_transaction". -Axiom state_commit_transaction : - IsGlobalAlias globals state.globals "commit_transaction". -Axiom state_destroy_storage : - IsGlobalAlias globals state.globals "destroy_storage". -Axiom state_increment_nonce : - IsGlobalAlias globals state.globals "increment_nonce". -Axiom state_mark_account_created : - IsGlobalAlias globals state.globals "mark_account_created". -Axiom state_move_ether : - IsGlobalAlias globals state.globals "move_ether". -Axiom state_rollback_transaction : - IsGlobalAlias globals state.globals "rollback_transaction". -Axiom state_set_code : - IsGlobalAlias globals state.globals "set_code". -Axiom state_touch_account : - IsGlobalAlias globals state.globals "touch_account". - -Require vm. -Axiom vm_Message : - IsGlobalAlias globals vm.globals "Message". - -Require vm.gas. -Axiom vm_gas_GAS_CODE_DEPOSIT : - IsGlobalAlias globals vm.gas.globals "GAS_CODE_DEPOSIT". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". - -Require vm.precompiled_contracts.mapping. -Axiom vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : - IsGlobalAlias globals vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". - -Require __init__. -Axiom __init___Environment : - IsGlobalAlias globals __init__.globals "Environment". -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require exceptions. -Axiom exceptions_AddressCollision : - IsGlobalAlias globals exceptions.globals "AddressCollision". -Axiom exceptions_ExceptionalHalt : - IsGlobalAlias globals exceptions.globals "ExceptionalHalt". -Axiom exceptions_InvalidContractPrefix : - IsGlobalAlias globals exceptions.globals "InvalidContractPrefix". -Axiom exceptions_InvalidOpcode : - IsGlobalAlias globals exceptions.globals "InvalidOpcode". -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". -Axiom exceptions_Revert : - IsGlobalAlias globals exceptions.globals "Revert". -Axiom exceptions_StackDepthLimitError : - IsGlobalAlias globals exceptions.globals "StackDepthLimitError". - -Require instructions. -Axiom instructions_Ops : - IsGlobalAlias globals instructions.globals "Ops". -Axiom instructions_op_implementation : - IsGlobalAlias globals instructions.globals "op_implementation". - -Require runtime. -Axiom runtime_get_valid_jump_destinations : - IsGlobalAlias globals runtime.globals "get_valid_jump_destinations". +Require ethereum.gray_glacier.blocks. +Axiom ethereum_gray_glacier_blocks_Log : + IsGlobalAlias globals ethereum.gray_glacier.blocks.globals "Log". + +Require ethereum.gray_glacier.fork_types. +Axiom ethereum_gray_glacier_fork_types_Address : + IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "Address". + +Require ethereum.gray_glacier.state. +Axiom ethereum_gray_glacier_state_account_exists_and_is_empty : + IsGlobalAlias globals ethereum.gray_glacier.state.globals "account_exists_and_is_empty". +Axiom ethereum_gray_glacier_state_account_has_code_or_nonce : + IsGlobalAlias globals ethereum.gray_glacier.state.globals "account_has_code_or_nonce". +Axiom ethereum_gray_glacier_state_begin_transaction : + IsGlobalAlias globals ethereum.gray_glacier.state.globals "begin_transaction". +Axiom ethereum_gray_glacier_state_commit_transaction : + IsGlobalAlias globals ethereum.gray_glacier.state.globals "commit_transaction". +Axiom ethereum_gray_glacier_state_destroy_storage : + IsGlobalAlias globals ethereum.gray_glacier.state.globals "destroy_storage". +Axiom ethereum_gray_glacier_state_increment_nonce : + IsGlobalAlias globals ethereum.gray_glacier.state.globals "increment_nonce". +Axiom ethereum_gray_glacier_state_mark_account_created : + IsGlobalAlias globals ethereum.gray_glacier.state.globals "mark_account_created". +Axiom ethereum_gray_glacier_state_move_ether : + IsGlobalAlias globals ethereum.gray_glacier.state.globals "move_ether". +Axiom ethereum_gray_glacier_state_rollback_transaction : + IsGlobalAlias globals ethereum.gray_glacier.state.globals "rollback_transaction". +Axiom ethereum_gray_glacier_state_set_code : + IsGlobalAlias globals ethereum.gray_glacier.state.globals "set_code". +Axiom ethereum_gray_glacier_state_touch_account : + IsGlobalAlias globals ethereum.gray_glacier.state.globals "touch_account". + +Require ethereum.gray_glacier.vm.__init__. +Axiom ethereum_gray_glacier_vm___init___Message : + IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Message". + +Require ethereum.gray_glacier.vm.gas. +Axiom ethereum_gray_glacier_vm_gas_GAS_CODE_DEPOSIT : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_CODE_DEPOSIT". +Axiom ethereum_gray_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "charge_gas". + +Require ethereum.gray_glacier.vm.precompiled_contracts.mapping. +Axiom ethereum_gray_glacier_vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : + IsGlobalAlias globals ethereum.gray_glacier.vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". + +Require ethereum.gray_glacier.vm.__init__. +Axiom ethereum_gray_glacier_vm___init___Environment : + IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Environment". +Axiom ethereum_gray_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Evm". + +Require ethereum.gray_glacier.vm.exceptions. +Axiom ethereum_gray_glacier_vm_exceptions_AddressCollision : + IsGlobalAlias globals ethereum.gray_glacier.vm.exceptions.globals "AddressCollision". +Axiom ethereum_gray_glacier_vm_exceptions_ExceptionalHalt : + IsGlobalAlias globals ethereum.gray_glacier.vm.exceptions.globals "ExceptionalHalt". +Axiom ethereum_gray_glacier_vm_exceptions_InvalidContractPrefix : + IsGlobalAlias globals ethereum.gray_glacier.vm.exceptions.globals "InvalidContractPrefix". +Axiom ethereum_gray_glacier_vm_exceptions_InvalidOpcode : + IsGlobalAlias globals ethereum.gray_glacier.vm.exceptions.globals "InvalidOpcode". +Axiom ethereum_gray_glacier_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.gray_glacier.vm.exceptions.globals "OutOfGasError". +Axiom ethereum_gray_glacier_vm_exceptions_Revert : + IsGlobalAlias globals ethereum.gray_glacier.vm.exceptions.globals "Revert". +Axiom ethereum_gray_glacier_vm_exceptions_StackDepthLimitError : + IsGlobalAlias globals ethereum.gray_glacier.vm.exceptions.globals "StackDepthLimitError". + +Require ethereum.gray_glacier.vm.instructions.__init__. +Axiom ethereum_gray_glacier_vm_instructions___init___Ops : + IsGlobalAlias globals ethereum.gray_glacier.vm.instructions.__init__.globals "Ops". +Axiom ethereum_gray_glacier_vm_instructions___init___op_implementation : + IsGlobalAlias globals ethereum.gray_glacier.vm.instructions.__init__.globals "op_implementation". + +Require ethereum.gray_glacier.vm.runtime. +Axiom ethereum_gray_glacier_vm_runtime_get_valid_jump_destinations : + IsGlobalAlias globals ethereum.gray_glacier.vm.runtime.globals "get_valid_jump_destinations". Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -184,6 +184,94 @@ Definition process_message_call : Value.t -> Value.t -> M := Output of the message call " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "message" |), "target" |), + M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) + |), + (* then *) + ltac:(M.monadic ( + let is_collision := + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_name (| globals, "is_collision" |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallOutput" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "tuple" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "AddressCollision" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let evm := + M.call (| + M.get_name (| globals, "process_create_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let evm := M.call (| M.get_name (| globals, "process_message" |), @@ -194,11 +282,74 @@ Definition process_message_call : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_field (| M.get_name (| globals, "message" |), "target" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_field (| M.get_name (| globals, "message" |), "target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( +(* At stmt: unsupported node type: AnnAssign *) + let accounts_to_delete := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let touched_accounts := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let refund_counter := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let logs := M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in let accounts_to_delete := @@ -242,6 +393,7 @@ Definition process_message_call : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). Definition process_create_message : Value.t -> Value.t -> M := @@ -303,6 +455,28 @@ Definition process_create_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), + (* then *) + ltac:(M.monadic ( + let contract_code := + M.get_field (| M.get_name (| globals, "evm" |), "output" |) in + let contract_code_gas := + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "contract_code" |) + ], + make_dict [] + |), + M.get_name (| globals, "GAS_CODE_DEPOSIT" |) + |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "rollback_transaction" |), make_list [ @@ -314,6 +488,7 @@ Definition process_create_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) + |) in M.pure Constant.None_)). Definition process_message : Value.t -> Value.t -> M := @@ -335,6 +510,24 @@ Definition process_message : Value.t -> Value.t -> M := Items containing execution specific objects " in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_field (| M.get_name (| globals, "message" |), "depth" |), + M.get_name (| globals, "STACK_DEPTH_LIMIT" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "StackDepthLimitError" |), + make_list [ + Constant.str "Stack depth limit reached" + ], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -353,6 +546,32 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + M.get_field (| M.get_name (| globals, "message" |), "should_transfer_value" |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "message" |), "value" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "move_ether" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "caller" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |); + M.get_field (| M.get_name (| globals, "message" |), "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let evm := @@ -365,6 +584,21 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "rollback_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "commit_transaction" |), make_list [ @@ -376,6 +610,7 @@ Definition process_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) + |) in M.pure Constant.None_)). Definition execute_code : Value.t -> Value.t -> M := @@ -415,4 +650,5 @@ Definition execute_code : Value.t -> Value.t -> M := (* At stmt: unsupported node type: Try *) let _ := M.return_ (| M.get_name (| globals, "evm" |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/vm/memory.v b/CoqOfPython/ethereum/gray_glacier/vm/memory.v index 4b107fd..08d2290 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/memory.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/memory.v @@ -21,13 +21,13 @@ Require ethereum.utils.byte. Axiom ethereum_utils_byte_right_pad_zero_bytes : IsGlobalAlias globals ethereum.utils.byte.globals "right_pad_zero_bytes". -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". Definition memory_write : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,7 +45,22 @@ Definition memory_write : Value.t -> Value.t -> M := Data to write to memory. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |), + M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) |) |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_)). @@ -71,7 +86,23 @@ Definition memory_read_bytes : Value.t -> Value.t -> M := Data read from memory. " in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |) + M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |) |) + |) in M.pure Constant.None_)). Definition buffer_read : Value.t -> Value.t -> M := @@ -98,9 +129,25 @@ Definition buffer_read : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "right_pad_zero_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |) |); + M.get_subscript (| M.get_name (| globals, "buffer" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |) |); M.get_name (| globals, "size" |) ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/__init__.v index ca49311..6658651 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/__init__.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/__init__.v @@ -18,9 +18,9 @@ Addresses of precompiled contracts and mappings to their implementations. ". -Require utils.hexadecimal. -Axiom utils_hexadecimal_hex_to_address : - IsGlobalAlias globals utils.hexadecimal.globals "hex_to_address". +Require ethereum.gray_glacier.utils.hexadecimal. +Axiom ethereum_gray_glacier_utils_hexadecimal_hex_to_address : + IsGlobalAlias globals ethereum.gray_glacier.utils.hexadecimal.globals "hex_to_address". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS"; Constant.str "MODEXP_ADDRESS"; Constant.str "ALT_BN128_ADD_ADDRESS"; Constant.str "ALT_BN128_MUL_ADDRESS"; Constant.str "ALT_BN128_PAIRING_CHECK_ADDRESS"; Constant.str "BLAKE2F_ADDRESS" ] diff --git a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/alt_bn128.v index abe4238..d7ca245 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/alt_bn128.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/alt_bn128.v @@ -45,21 +45,21 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.gray_glacier.vm.__init__. +Axiom ethereum_gray_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.gray_glacier.vm.gas. +Axiom ethereum_gray_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "charge_gas". -Require vm.memory. -Axiom vm_memory_buffer_read : - IsGlobalAlias globals vm.memory.globals "buffer_read". +Require ethereum.gray_glacier.vm.memory. +Axiom ethereum_gray_glacier_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.gray_glacier.vm.memory.globals "buffer_read". -Require exceptions. -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". +Require ethereum.gray_glacier.vm.exceptions. +Axiom ethereum_gray_glacier_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.gray_glacier.vm.exceptions.globals "OutOfGasError". Definition alt_bn128_add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -210,6 +210,18 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) in For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ] do let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -353,6 +365,18 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) in For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ] do let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -425,6 +449,27 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| + BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 192 + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let result := @@ -464,7 +509,7 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "data" |), BinOp.add (| + M.get_subscript (| M.get_name (| globals, "data" |), M.slice (| BinOp.add (| BinOp.mult (| M.get_name (| globals, "i" |), Constant.int 192 @@ -473,11 +518,35 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := Constant.int 32, M.get_name (| globals, "j" |) |) - |) |) + |), BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "j" |), + Constant.int 1 + |) + |) + |) |) |) ], make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -538,10 +607,80 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "p" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "q" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let result := + BinOp.mult (| + M.get_name (| globals, "result" |), + M.call (| + M.get_name (| globals, "pairing" |), + make_list [ + M.get_name (| globals, "q" |); + M.get_name (| globals, "p" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "result" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| diff --git a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/blake2f.v b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/blake2f.v index 1647d48..8bfd578 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/blake2f.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/blake2f.v @@ -25,19 +25,19 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.gray_glacier.vm.__init__. +Axiom ethereum_gray_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_BLAKE2_PER_ROUND : - IsGlobalAlias globals vm.gas.globals "GAS_BLAKE2_PER_ROUND". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.gray_glacier.vm.gas. +Axiom ethereum_gray_glacier_vm_gas_GAS_BLAKE2_PER_ROUND : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_BLAKE2_PER_ROUND". +Axiom ethereum_gray_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "charge_gas". -Require exceptions. -Axiom exceptions_InvalidParameter : - IsGlobalAlias globals exceptions.globals "InvalidParameter". +Require ethereum.gray_glacier.vm.exceptions. +Axiom ethereum_gray_glacier_vm_exceptions_InvalidParameter : + IsGlobalAlias globals ethereum.gray_glacier.vm.exceptions.globals "InvalidParameter". Definition blake2f : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/ecrecover.v index 0cbcf16..0819bfd 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/ecrecover.v @@ -37,19 +37,19 @@ Require ethereum.utils.byte. Axiom ethereum_utils_byte_left_pad_zero_bytes : IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.gray_glacier.vm.__init__. +Axiom ethereum_gray_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_ECRECOVER : - IsGlobalAlias globals vm.gas.globals "GAS_ECRECOVER". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.gray_glacier.vm.gas. +Axiom ethereum_gray_glacier_vm_gas_GAS_ECRECOVER : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_ECRECOVER". +Axiom ethereum_gray_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "charge_gas". -Require vm.memory. -Axiom vm_memory_buffer_read : - IsGlobalAlias globals vm.memory.globals "buffer_read". +Require ethereum.gray_glacier.vm.memory. +Axiom ethereum_gray_glacier_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.gray_glacier.vm.memory.globals "buffer_read". Definition ecrecover : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -188,12 +188,78 @@ Definition ecrecover : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "v" |), + Constant.int 27 + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "v" |), + Constant.int 28 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + Constant.int 0, + M.get_name (| globals, "r" |) + |), + ltac:(M.monadic ( + Compare.gt_e (| + M.get_name (| globals, "r" |), + M.get_name (| globals, "SECP256K1N" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + Constant.int 0, + M.get_name (| globals, "s" |) + |), + ltac:(M.monadic ( + Compare.gt_e (| + M.get_name (| globals, "s" |), + M.get_name (| globals, "SECP256K1N" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: Try *) @@ -204,7 +270,7 @@ Definition ecrecover : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12 |) in + |), M.slice (| Constant.int 12, Constant.int 32 |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/identity.v index fa96704..024d1db 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/identity.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/identity.v @@ -25,17 +25,17 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.gray_glacier.vm.__init__. +Axiom ethereum_gray_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_IDENTITY : - IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY". -Axiom vm_gas_GAS_IDENTITY_WORD : - IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY_WORD". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.gray_glacier.vm.gas. +Axiom ethereum_gray_glacier_vm_gas_GAS_IDENTITY : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_IDENTITY". +Axiom ethereum_gray_glacier_vm_gas_GAS_IDENTITY_WORD : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_IDENTITY_WORD". +Axiom ethereum_gray_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "charge_gas". Definition identity : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/mapping.v index 8a2e2eb..1eade51 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/mapping.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/mapping.v @@ -23,60 +23,60 @@ Axiom typing_Callable : Axiom typing_Dict : IsGlobalAlias globals typing.globals "Dict". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". - -Require __init__. -Axiom __init___ALT_BN128_ADD_ADDRESS : - IsGlobalAlias globals __init__.globals "ALT_BN128_ADD_ADDRESS". -Axiom __init___ALT_BN128_MUL_ADDRESS : - IsGlobalAlias globals __init__.globals "ALT_BN128_MUL_ADDRESS". -Axiom __init___ALT_BN128_PAIRING_CHECK_ADDRESS : - IsGlobalAlias globals __init__.globals "ALT_BN128_PAIRING_CHECK_ADDRESS". -Axiom __init___BLAKE2F_ADDRESS : - IsGlobalAlias globals __init__.globals "BLAKE2F_ADDRESS". -Axiom __init___ECRECOVER_ADDRESS : - IsGlobalAlias globals __init__.globals "ECRECOVER_ADDRESS". -Axiom __init___IDENTITY_ADDRESS : - IsGlobalAlias globals __init__.globals "IDENTITY_ADDRESS". -Axiom __init___MODEXP_ADDRESS : - IsGlobalAlias globals __init__.globals "MODEXP_ADDRESS". -Axiom __init___RIPEMD160_ADDRESS : - IsGlobalAlias globals __init__.globals "RIPEMD160_ADDRESS". -Axiom __init___SHA256_ADDRESS : - IsGlobalAlias globals __init__.globals "SHA256_ADDRESS". - -Require alt_bn128. -Axiom alt_bn128_alt_bn128_add : - IsGlobalAlias globals alt_bn128.globals "alt_bn128_add". -Axiom alt_bn128_alt_bn128_mul : - IsGlobalAlias globals alt_bn128.globals "alt_bn128_mul". -Axiom alt_bn128_alt_bn128_pairing_check : - IsGlobalAlias globals alt_bn128.globals "alt_bn128_pairing_check". - -Require blake2f. -Axiom blake2f_blake2f : - IsGlobalAlias globals blake2f.globals "blake2f". - -Require ecrecover. -Axiom ecrecover_ecrecover : - IsGlobalAlias globals ecrecover.globals "ecrecover". - -Require identity. -Axiom identity_identity : - IsGlobalAlias globals identity.globals "identity". - -Require modexp. -Axiom modexp_modexp : - IsGlobalAlias globals modexp.globals "modexp". - -Require ripemd160. -Axiom ripemd160_ripemd160 : - IsGlobalAlias globals ripemd160.globals "ripemd160". - -Require sha256. -Axiom sha256_sha256 : - IsGlobalAlias globals sha256.globals "sha256". +Require ethereum.gray_glacier.fork_types. +Axiom ethereum_gray_glacier_fork_types_Address : + IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "Address". + +Require ethereum.gray_glacier.vm.precompiled_contracts.__init__. +Axiom ethereum_gray_glacier_vm_precompiled_contracts___init___ALT_BN128_ADD_ADDRESS : + IsGlobalAlias globals ethereum.gray_glacier.vm.precompiled_contracts.__init__.globals "ALT_BN128_ADD_ADDRESS". +Axiom ethereum_gray_glacier_vm_precompiled_contracts___init___ALT_BN128_MUL_ADDRESS : + IsGlobalAlias globals ethereum.gray_glacier.vm.precompiled_contracts.__init__.globals "ALT_BN128_MUL_ADDRESS". +Axiom ethereum_gray_glacier_vm_precompiled_contracts___init___ALT_BN128_PAIRING_CHECK_ADDRESS : + IsGlobalAlias globals ethereum.gray_glacier.vm.precompiled_contracts.__init__.globals "ALT_BN128_PAIRING_CHECK_ADDRESS". +Axiom ethereum_gray_glacier_vm_precompiled_contracts___init___BLAKE2F_ADDRESS : + IsGlobalAlias globals ethereum.gray_glacier.vm.precompiled_contracts.__init__.globals "BLAKE2F_ADDRESS". +Axiom ethereum_gray_glacier_vm_precompiled_contracts___init___ECRECOVER_ADDRESS : + IsGlobalAlias globals ethereum.gray_glacier.vm.precompiled_contracts.__init__.globals "ECRECOVER_ADDRESS". +Axiom ethereum_gray_glacier_vm_precompiled_contracts___init___IDENTITY_ADDRESS : + IsGlobalAlias globals ethereum.gray_glacier.vm.precompiled_contracts.__init__.globals "IDENTITY_ADDRESS". +Axiom ethereum_gray_glacier_vm_precompiled_contracts___init___MODEXP_ADDRESS : + IsGlobalAlias globals ethereum.gray_glacier.vm.precompiled_contracts.__init__.globals "MODEXP_ADDRESS". +Axiom ethereum_gray_glacier_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : + IsGlobalAlias globals ethereum.gray_glacier.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". +Axiom ethereum_gray_glacier_vm_precompiled_contracts___init___SHA256_ADDRESS : + IsGlobalAlias globals ethereum.gray_glacier.vm.precompiled_contracts.__init__.globals "SHA256_ADDRESS". + +Require ethereum.gray_glacier.vm.precompiled_contracts.alt_bn128. +Axiom ethereum_gray_glacier_vm_precompiled_contracts_alt_bn128_alt_bn128_add : + IsGlobalAlias globals ethereum.gray_glacier.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_add". +Axiom ethereum_gray_glacier_vm_precompiled_contracts_alt_bn128_alt_bn128_mul : + IsGlobalAlias globals ethereum.gray_glacier.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_mul". +Axiom ethereum_gray_glacier_vm_precompiled_contracts_alt_bn128_alt_bn128_pairing_check : + IsGlobalAlias globals ethereum.gray_glacier.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_pairing_check". + +Require ethereum.gray_glacier.vm.precompiled_contracts.blake2f. +Axiom ethereum_gray_glacier_vm_precompiled_contracts_blake2f_blake2f : + IsGlobalAlias globals ethereum.gray_glacier.vm.precompiled_contracts.blake2f.globals "blake2f". + +Require ethereum.gray_glacier.vm.precompiled_contracts.ecrecover. +Axiom ethereum_gray_glacier_vm_precompiled_contracts_ecrecover_ecrecover : + IsGlobalAlias globals ethereum.gray_glacier.vm.precompiled_contracts.ecrecover.globals "ecrecover". + +Require ethereum.gray_glacier.vm.precompiled_contracts.identity. +Axiom ethereum_gray_glacier_vm_precompiled_contracts_identity_identity : + IsGlobalAlias globals ethereum.gray_glacier.vm.precompiled_contracts.identity.globals "identity". + +Require ethereum.gray_glacier.vm.precompiled_contracts.modexp. +Axiom ethereum_gray_glacier_vm_precompiled_contracts_modexp_modexp : + IsGlobalAlias globals ethereum.gray_glacier.vm.precompiled_contracts.modexp.globals "modexp". + +Require ethereum.gray_glacier.vm.precompiled_contracts.ripemd160. +Axiom ethereum_gray_glacier_vm_precompiled_contracts_ripemd160_ripemd160 : + IsGlobalAlias globals ethereum.gray_glacier.vm.precompiled_contracts.ripemd160.globals "ripemd160". + +Require ethereum.gray_glacier.vm.precompiled_contracts.sha256. +Axiom ethereum_gray_glacier_vm_precompiled_contracts_sha256_sha256 : + IsGlobalAlias globals ethereum.gray_glacier.vm.precompiled_contracts.sha256.globals "sha256". (* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/modexp.v index 3505244..40654e2 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/modexp.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/modexp.v @@ -25,17 +25,17 @@ Axiom ethereum_base_types_Bytes : Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.gray_glacier.vm.__init__. +Axiom ethereum_gray_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.gray_glacier.vm.gas. +Axiom ethereum_gray_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "charge_gas". -Require memory. -Axiom memory_buffer_read : - IsGlobalAlias globals memory.globals "buffer_read". +Require ethereum.gray_glacier.vm.memory. +Axiom ethereum_gray_glacier_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.gray_glacier.vm.memory.globals "buffer_read". Definition GQUADDIVISOR : Value.t := M.run ltac:(M.monadic ( Constant.int 3 @@ -192,6 +192,36 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_name (| globals, "base_length" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "modulus_length" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [], + make_dict [] + |) + |) in + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let base := @@ -254,6 +284,30 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "modulus" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + BinOp.mult (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + Constant.bytes "00" + ], + make_dict [] + |), + M.get_name (| globals, "modulus_length" |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| @@ -338,6 +392,7 @@ Definition complexity : Value.t -> Value.t -> M := M.get_name (| globals, "words" |), Constant.int 2 |) + |) in M.pure Constant.None_)). Definition iterations : Value.t -> Value.t -> M := @@ -364,7 +419,76 @@ Definition iterations : Value.t -> Value.t -> M := Number of iterations. " in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.lt_e (| + M.get_name (| globals, "exponent_length" |), + Constant.int 32 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "exponent_head" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let count := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "exponent_length" |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let bit_length := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "exponent_head" |), "bit_length" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "bit_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let bit_length := BinOp.sub + Constant.int 1 + Constant.int 1 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let count := + M.get_name (| globals, "bit_length" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let length_part := BinOp.mult (| Constant.int 8, @@ -392,6 +516,20 @@ Definition iterations : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "bits_part" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let bits_part := BinOp.sub + Constant.int 1 + Constant.int 1 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let count := @@ -418,6 +556,7 @@ Definition iterations : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition gas_cost : Value.t -> Value.t -> M := @@ -489,4 +628,5 @@ Definition gas_cost : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/ripemd160.v index 96f8dcd..88a93f9 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/ripemd160.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/ripemd160.v @@ -31,17 +31,17 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.gray_glacier.vm.__init__. +Axiom ethereum_gray_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_RIPEMD160 : - IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160". -Axiom vm_gas_GAS_RIPEMD160_WORD : - IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160_WORD". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.gray_glacier.vm.gas. +Axiom ethereum_gray_glacier_vm_gas_GAS_RIPEMD160 : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_RIPEMD160". +Axiom ethereum_gray_glacier_vm_gas_GAS_RIPEMD160_WORD : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_RIPEMD160_WORD". +Axiom ethereum_gray_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "charge_gas". Definition ripemd160 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/sha256.v index 9f6d2bf..4d0cb65 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/sha256.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/sha256.v @@ -27,17 +27,17 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.gray_glacier.vm.__init__. +Axiom ethereum_gray_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_SHA256 : - IsGlobalAlias globals vm.gas.globals "GAS_SHA256". -Axiom vm_gas_GAS_SHA256_WORD : - IsGlobalAlias globals vm.gas.globals "GAS_SHA256_WORD". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.gray_glacier.vm.gas. +Axiom ethereum_gray_glacier_vm_gas_GAS_SHA256 : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_SHA256". +Axiom ethereum_gray_glacier_vm_gas_GAS_SHA256_WORD : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_SHA256_WORD". +Axiom ethereum_gray_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "charge_gas". Definition sha256 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/gray_glacier/vm/runtime.v b/CoqOfPython/ethereum/gray_glacier/vm/runtime.v index 2cd7652..10332e5 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/runtime.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/runtime.v @@ -25,9 +25,9 @@ Require ethereum.base_types. Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require instructions. -Axiom instructions_Ops : - IsGlobalAlias globals instructions.globals "Ops". +Require ethereum.gray_glacier.vm.instructions.__init__. +Axiom ethereum_gray_glacier_vm_instructions___init___Ops : + IsGlobalAlias globals ethereum.gray_glacier.vm.instructions.__init__.globals "Ops". Definition get_valid_jump_destinations : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -79,7 +79,55 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := |) do (* At stmt: unsupported node type: Try *) let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "current_opcode" |), + M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), + make_list [ + M.get_name (| globals, "pc" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.lt_e (| + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |), + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH32" |), "value" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let push_data_size := + BinOp.add (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) + |), + Constant.int 1 + |) in + let pc := BinOp.add + M.get_name (| globals, "push_data_size" |) + M.get_name (| globals, "push_data_size" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -90,4 +138,5 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := EndWhile. let _ := M.return_ (| M.get_name (| globals, "valid_jump_destinations" |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/vm/stack.v b/CoqOfPython/ethereum/gray_glacier/vm/stack.v index ea778df..274024e 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/stack.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/stack.v @@ -25,11 +25,11 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require exceptions. -Axiom exceptions_StackOverflowError : - IsGlobalAlias globals exceptions.globals "StackOverflowError". -Axiom exceptions_StackUnderflowError : - IsGlobalAlias globals exceptions.globals "StackUnderflowError". +Require ethereum.gray_glacier.vm.exceptions. +Axiom ethereum_gray_glacier_vm_exceptions_StackOverflowError : + IsGlobalAlias globals ethereum.gray_glacier.vm.exceptions.globals "StackOverflowError". +Axiom ethereum_gray_glacier_vm_exceptions_StackUnderflowError : + IsGlobalAlias globals ethereum.gray_glacier.vm.exceptions.globals "StackUnderflowError". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -49,6 +49,24 @@ Definition pop : Value.t -> Value.t -> M := " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "StackUnderflowError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -57,6 +75,7 @@ Definition pop : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). Definition push : Value.t -> Value.t -> M := @@ -75,6 +94,24 @@ Definition push : Value.t -> Value.t -> M := " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), + Constant.int 1024 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "StackOverflowError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -85,4 +122,5 @@ Definition push : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/blocks.v b/CoqOfPython/ethereum/homestead/blocks.v index 6501788..f541174 100644 --- a/CoqOfPython/ethereum/homestead/blocks.v +++ b/CoqOfPython/ethereum/homestead/blocks.v @@ -22,35 +22,35 @@ Require typing. Axiom typing_Tuple : IsGlobalAlias globals typing.globals "Tuple". -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes8 : - IsGlobalAlias globals base_types.globals "Bytes8". -Axiom base_types_Bytes32 : - IsGlobalAlias globals base_types.globals "Bytes32". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require crypto.hash. -Axiom crypto_hash_Hash32 : - IsGlobalAlias globals crypto.hash.globals "Hash32". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". - -Require transactions. -Axiom transactions_Transaction : - IsGlobalAlias globals transactions.globals "Transaction". +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes8 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes8". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". + +Require ethereum.homestead.fork_types. +Axiom ethereum_homestead_fork_types_Address : + IsGlobalAlias globals ethereum.homestead.fork_types.globals "Address". +Axiom ethereum_homestead_fork_types_Bloom : + IsGlobalAlias globals ethereum.homestead.fork_types.globals "Bloom". +Axiom ethereum_homestead_fork_types_Root : + IsGlobalAlias globals ethereum.homestead.fork_types.globals "Root". + +Require ethereum.homestead.transactions. +Axiom ethereum_homestead_transactions_Transaction : + IsGlobalAlias globals ethereum.homestead.transactions.globals "Transaction". Definition Header : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/homestead/bloom.v b/CoqOfPython/ethereum/homestead/bloom.v index 04650ff..638e95a 100644 --- a/CoqOfPython/ethereum/homestead/bloom.v +++ b/CoqOfPython/ethereum/homestead/bloom.v @@ -33,13 +33,13 @@ Require ethereum.crypto.hash. Axiom ethereum_crypto_hash_keccak256 : IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". +Require ethereum.homestead.blocks. +Axiom ethereum_homestead_blocks_Log : + IsGlobalAlias globals ethereum.homestead.blocks.globals "Log". -Require fork_types. -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". +Require ethereum.homestead.fork_types. +Axiom ethereum_homestead_fork_types_Bloom : + IsGlobalAlias globals ethereum.homestead.fork_types.globals "Bloom". Definition add_to_bloom : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -72,7 +72,10 @@ Definition add_to_bloom : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |) |) + M.get_subscript (| M.get_name (| globals, "hash" |), M.slice (| M.get_name (| globals, "idx" |), BinOp.add (| + M.get_name (| globals, "idx" |), + Constant.int 2 + |) |) |) ], make_dict [] |), @@ -157,4 +160,5 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/fork.v b/CoqOfPython/ethereum/homestead/fork.v index 245eaa1..80befd6 100644 --- a/CoqOfPython/ethereum/homestead/fork.v +++ b/CoqOfPython/ethereum/homestead/fork.v @@ -63,93 +63,93 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U64 : - IsGlobalAlias globals base_types.globals "U64". -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_U256_CEIL_VALUE : - IsGlobalAlias globals base_types.globals "U256_CEIL_VALUE". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes32 : - IsGlobalAlias globals base_types.globals "Bytes32". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". - -Require __init__. -Axiom __init___vm : - IsGlobalAlias globals __init__.globals "vm". - -Require blocks. -Axiom blocks_Block : - IsGlobalAlias globals blocks.globals "Block". -Axiom blocks_Header : - IsGlobalAlias globals blocks.globals "Header". -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". -Axiom blocks_Receipt : - IsGlobalAlias globals blocks.globals "Receipt". - -Require bloom. -Axiom bloom_logs_bloom : - IsGlobalAlias globals bloom.globals "logs_bloom". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". - -Require state. -Axiom state_State : - IsGlobalAlias globals state.globals "State". -Axiom state_create_ether : - IsGlobalAlias globals state.globals "create_ether". -Axiom state_destroy_account : - IsGlobalAlias globals state.globals "destroy_account". -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". -Axiom state_increment_nonce : - IsGlobalAlias globals state.globals "increment_nonce". -Axiom state_set_account_balance : - IsGlobalAlias globals state.globals "set_account_balance". -Axiom state_state_root : - IsGlobalAlias globals state.globals "state_root". - -Require transactions. -Axiom transactions_TX_BASE_COST : - IsGlobalAlias globals transactions.globals "TX_BASE_COST". -Axiom transactions_TX_CREATE_COST : - IsGlobalAlias globals transactions.globals "TX_CREATE_COST". -Axiom transactions_TX_DATA_COST_PER_NON_ZERO : - IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_NON_ZERO". -Axiom transactions_TX_DATA_COST_PER_ZERO : - IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_ZERO". -Axiom transactions_Transaction : - IsGlobalAlias globals transactions.globals "Transaction". - -Require trie. -Axiom trie_Trie : - IsGlobalAlias globals trie.globals "Trie". -Axiom trie_root : - IsGlobalAlias globals trie.globals "root". -Axiom trie_trie_set : - IsGlobalAlias globals trie.globals "trie_set". - -Require utils.message. -Axiom utils_message_prepare_message : - IsGlobalAlias globals utils.message.globals "prepare_message". - -Require vm.interpreter. -Axiom vm_interpreter_process_message_call : - IsGlobalAlias globals vm.interpreter.globals "process_message_call". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U64 : + IsGlobalAlias globals ethereum.base_types.globals "U64". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_U256_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.homestead.__init__. +Axiom ethereum_homestead___init___vm : + IsGlobalAlias globals ethereum.homestead.__init__.globals "vm". + +Require ethereum.homestead.blocks. +Axiom ethereum_homestead_blocks_Block : + IsGlobalAlias globals ethereum.homestead.blocks.globals "Block". +Axiom ethereum_homestead_blocks_Header : + IsGlobalAlias globals ethereum.homestead.blocks.globals "Header". +Axiom ethereum_homestead_blocks_Log : + IsGlobalAlias globals ethereum.homestead.blocks.globals "Log". +Axiom ethereum_homestead_blocks_Receipt : + IsGlobalAlias globals ethereum.homestead.blocks.globals "Receipt". + +Require ethereum.homestead.bloom. +Axiom ethereum_homestead_bloom_logs_bloom : + IsGlobalAlias globals ethereum.homestead.bloom.globals "logs_bloom". + +Require ethereum.homestead.fork_types. +Axiom ethereum_homestead_fork_types_Address : + IsGlobalAlias globals ethereum.homestead.fork_types.globals "Address". +Axiom ethereum_homestead_fork_types_Bloom : + IsGlobalAlias globals ethereum.homestead.fork_types.globals "Bloom". +Axiom ethereum_homestead_fork_types_Root : + IsGlobalAlias globals ethereum.homestead.fork_types.globals "Root". + +Require ethereum.homestead.state. +Axiom ethereum_homestead_state_State : + IsGlobalAlias globals ethereum.homestead.state.globals "State". +Axiom ethereum_homestead_state_create_ether : + IsGlobalAlias globals ethereum.homestead.state.globals "create_ether". +Axiom ethereum_homestead_state_destroy_account : + IsGlobalAlias globals ethereum.homestead.state.globals "destroy_account". +Axiom ethereum_homestead_state_get_account : + IsGlobalAlias globals ethereum.homestead.state.globals "get_account". +Axiom ethereum_homestead_state_increment_nonce : + IsGlobalAlias globals ethereum.homestead.state.globals "increment_nonce". +Axiom ethereum_homestead_state_set_account_balance : + IsGlobalAlias globals ethereum.homestead.state.globals "set_account_balance". +Axiom ethereum_homestead_state_state_root : + IsGlobalAlias globals ethereum.homestead.state.globals "state_root". + +Require ethereum.homestead.transactions. +Axiom ethereum_homestead_transactions_TX_BASE_COST : + IsGlobalAlias globals ethereum.homestead.transactions.globals "TX_BASE_COST". +Axiom ethereum_homestead_transactions_TX_CREATE_COST : + IsGlobalAlias globals ethereum.homestead.transactions.globals "TX_CREATE_COST". +Axiom ethereum_homestead_transactions_TX_DATA_COST_PER_NON_ZERO : + IsGlobalAlias globals ethereum.homestead.transactions.globals "TX_DATA_COST_PER_NON_ZERO". +Axiom ethereum_homestead_transactions_TX_DATA_COST_PER_ZERO : + IsGlobalAlias globals ethereum.homestead.transactions.globals "TX_DATA_COST_PER_ZERO". +Axiom ethereum_homestead_transactions_Transaction : + IsGlobalAlias globals ethereum.homestead.transactions.globals "Transaction". + +Require ethereum.homestead.trie. +Axiom ethereum_homestead_trie_Trie : + IsGlobalAlias globals ethereum.homestead.trie.globals "Trie". +Axiom ethereum_homestead_trie_root : + IsGlobalAlias globals ethereum.homestead.trie.globals "root". +Axiom ethereum_homestead_trie_trie_set : + IsGlobalAlias globals ethereum.homestead.trie.globals "trie_set". + +Require ethereum.homestead.utils.message. +Axiom ethereum_homestead_utils_message_prepare_message : + IsGlobalAlias globals ethereum.homestead.utils.message.globals "prepare_message". + +Require ethereum.homestead.vm.interpreter. +Axiom ethereum_homestead_vm_interpreter_process_message_call : + IsGlobalAlias globals ethereum.homestead.vm.interpreter.globals "process_message_call". Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -222,6 +222,7 @@ Definition apply_fork : Value.t -> Value.t -> M := " in let _ := M.return_ (| M.get_name (| globals, "old" |) + |) in M.pure Constant.None_)). Definition get_last_256_block_hashes : Value.t -> Value.t -> M := @@ -247,8 +248,28 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := Hashes of the recent 256 blocks in order of increasing block number. " in let recent_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |) |) in + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "recent_blocks" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + make_list [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let recent_block_hashes := @@ -287,6 +308,7 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "recent_block_hashes" |) + |) in M.pure Constant.None_)). Definition state_transition : Value.t -> Value.t -> M := @@ -417,6 +439,27 @@ Definition state_transition : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |) + ], + make_dict [] + |), + Constant.int 255 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -603,6 +646,7 @@ Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition validate_proof_of_work : Value.t -> Value.t -> M := @@ -734,6 +778,7 @@ Definition check_transaction : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "sender_address" |) + |) in M.pure Constant.None_)). Definition make_receipt : Value.t -> Value.t -> M := @@ -767,6 +812,7 @@ Definition make_receipt : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "receipt" |) + |) in M.pure Constant.None_)). Definition ApplyBodyOutput : Value.t := @@ -980,6 +1026,7 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition validate_ommers : Value.t -> Value.t -> M := @@ -1032,6 +1079,26 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do @@ -1089,7 +1156,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let ommers_hashes := - (* At expr: unsupported node type: ListComp *) in + Constant.str "(* At expr: unsupported node type: ListComp *)" in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1120,19 +1187,19 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let recent_canonical_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| BinOp.add (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| BinOp.add (| M.get_name (| globals, "MAX_OMMER_DEPTH" |), Constant.int 1 - |) |) |) in + |) |), Constant.None_ |) |) in let recent_canonical_block_hashes := - (* At expr: unsupported node type: SetComp *) in + Constant.str "(* At expr: unsupported node type: SetComp *)" in (* At stmt: unsupported node type: AnnAssign *) For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_canonical_blocks" |) do let recent_ommers_hashes := M.call (| M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), make_list [ - (* At expr: unsupported node type: SetComp *) + Constant.str "(* At expr: unsupported node type: SetComp *)" ], make_dict [] |) in @@ -1566,6 +1633,7 @@ Definition process_transaction : Value.t -> Value.t -> M := EndFor. let _ := M.return_ (| make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |) ] + |) in M.pure Constant.None_)). Definition validate_transaction : Value.t -> Value.t -> M := @@ -1620,6 +1688,7 @@ Definition validate_transaction : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := @@ -1651,6 +1720,20 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := Constant.int 0 in For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "byte" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let data_cost := BinOp.add M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in @@ -1658,6 +1741,25 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := )) |) in EndFor. let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "tx" |), "to" |), + M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) + |), + (* then *) + ltac:(M.monadic ( + let create_cost := + M.get_name (| globals, "TX_CREATE_COST" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let create_cost := Constant.int 0 in M.pure Constant.None_ @@ -1676,6 +1778,7 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition recover_sender : Value.t -> Value.t -> M := @@ -1794,10 +1897,11 @@ Definition recover_sender : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12 |) + |), M.slice (| Constant.int 12, Constant.int 32 |) |) ], make_dict [] |) + |) in M.pure Constant.None_)). Definition signing_hash : Value.t -> Value.t -> M := @@ -1834,6 +1938,7 @@ Definition signing_hash : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition compute_header_hash : Value.t -> Value.t -> M := @@ -1884,6 +1989,7 @@ Definition compute_header_hash : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition check_gas_limit : Value.t -> Value.t -> M := @@ -1922,16 +2028,65 @@ Definition check_gas_limit : Value.t -> Value.t -> M := M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "gas_limit" |), + BinOp.add (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "gas_limit" |), + BinOp.sub (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "gas_limit" |), + M.get_name (| globals, "GAS_LIMIT_MINIMUM" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| Constant.bool true + |) in M.pure Constant.None_)). Definition calculate_block_difficulty : Value.t -> Value.t -> M := @@ -2035,6 +2190,26 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := Constant.int 2 |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "num_bomb_periods" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let difficulty := BinOp.add + BinOp.pow (| + Constant.int 2, + M.get_name (| globals, "num_bomb_periods" |) + |) + BinOp.pow (| + Constant.int 2, + M.get_name (| globals, "num_bomb_periods" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -2052,4 +2227,5 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/fork_types.v b/CoqOfPython/ethereum/homestead/fork_types.v index 5c7dac3..cc8e4a1 100644 --- a/CoqOfPython/ethereum/homestead/fork_types.v +++ b/CoqOfPython/ethereum/homestead/fork_types.v @@ -21,29 +21,29 @@ Require dataclasses. Axiom dataclasses_dataclass : IsGlobalAlias globals dataclasses.globals "dataclass". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes20 : - IsGlobalAlias globals base_types.globals "Bytes20". -Axiom base_types_Bytes256 : - IsGlobalAlias globals base_types.globals "Bytes256". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require crypto.hash. -Axiom crypto_hash_Hash32 : - IsGlobalAlias globals crypto.hash.globals "Hash32". -Axiom crypto_hash_keccak256 : - IsGlobalAlias globals crypto.hash.globals "keccak256". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes20 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes20". +Axiom ethereum_base_types_Bytes256 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) @@ -98,4 +98,5 @@ Definition encode_account : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/state.v b/CoqOfPython/ethereum/homestead/state.v index 2ba095e..576dfb0 100644 --- a/CoqOfPython/ethereum/homestead/state.v +++ b/CoqOfPython/ethereum/homestead/state.v @@ -54,29 +54,29 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require fork_types. -Axiom fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". -Axiom fork_types_Account : - IsGlobalAlias globals fork_types.globals "Account". -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". - -Require trie. -Axiom trie_EMPTY_TRIE_ROOT : - IsGlobalAlias globals trie.globals "EMPTY_TRIE_ROOT". -Axiom trie_Trie : - IsGlobalAlias globals trie.globals "Trie". -Axiom trie_copy_trie : - IsGlobalAlias globals trie.globals "copy_trie". -Axiom trie_root : - IsGlobalAlias globals trie.globals "root". -Axiom trie_trie_get : - IsGlobalAlias globals trie.globals "trie_get". -Axiom trie_trie_set : - IsGlobalAlias globals trie.globals "trie_set". +Require ethereum.homestead.fork_types. +Axiom ethereum_homestead_fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals ethereum.homestead.fork_types.globals "EMPTY_ACCOUNT". +Axiom ethereum_homestead_fork_types_Account : + IsGlobalAlias globals ethereum.homestead.fork_types.globals "Account". +Axiom ethereum_homestead_fork_types_Address : + IsGlobalAlias globals ethereum.homestead.fork_types.globals "Address". +Axiom ethereum_homestead_fork_types_Root : + IsGlobalAlias globals ethereum.homestead.fork_types.globals "Root". + +Require ethereum.homestead.trie. +Axiom ethereum_homestead_trie_EMPTY_TRIE_ROOT : + IsGlobalAlias globals ethereum.homestead.trie.globals "EMPTY_TRIE_ROOT". +Axiom ethereum_homestead_trie_Trie : + IsGlobalAlias globals ethereum.homestead.trie.globals "Trie". +Axiom ethereum_homestead_trie_copy_trie : + IsGlobalAlias globals ethereum.homestead.trie.globals "copy_trie". +Axiom ethereum_homestead_trie_root : + IsGlobalAlias globals ethereum.homestead.trie.globals "root". +Axiom ethereum_homestead_trie_trie_get : + IsGlobalAlias globals ethereum.homestead.trie.globals "trie_get". +Axiom ethereum_homestead_trie_trie_set : + IsGlobalAlias globals ethereum.homestead.trie.globals "trie_set". Definition State : Value.t := builtins.make_klass @@ -123,7 +123,7 @@ Definition begin_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) ], make_dict [] - |); (* At expr: unsupported node type: DictComp *) ] + |); Constant.str "(* At expr: unsupported node type: DictComp *)" ] ], make_dict [] |) in @@ -201,8 +201,27 @@ Definition get_account : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "account" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "account" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_ACCOUNT" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -237,6 +256,7 @@ Definition get_account_optional : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "account" |) + |) in M.pure Constant.None_)). Definition set_account : Value.t -> Value.t -> M := @@ -316,6 +336,18 @@ Definition destroy_storage : Value.t -> Value.t -> M := Address of account whose storage is to be deleted. " in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -350,6 +382,26 @@ Definition get_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "trie" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let value := @@ -371,6 +423,7 @@ Definition get_storage : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "value" |) + |) in M.pure Constant.None_)). Definition set_storage : Value.t -> Value.t -> M := @@ -411,6 +464,27 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "trie" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let trie := + M.call (| + M.get_name (| globals, "Trie" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), + M.get_name (| globals, "trie" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -423,6 +497,18 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + {} + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -447,8 +533,29 @@ Definition storage_root : Value.t -> Value.t -> M := " in let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_TRIE_ROOT" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -479,6 +586,7 @@ Definition state_root : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition account_exists : Value.t -> Value.t -> M := @@ -511,6 +619,7 @@ Definition account_exists : Value.t -> Value.t -> M := |), Constant.None_ |) + |) in M.pure Constant.None_)). Definition account_has_code_or_nonce : Value.t -> Value.t -> M := @@ -560,6 +669,7 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition modify_state : Value.t -> Value.t -> M := @@ -665,6 +775,30 @@ Definition touch_account : Value.t -> Value.t -> M := The address of the account that need to initialised. " in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "account_exists" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "EMPTY_ACCOUNT" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/transactions.v b/CoqOfPython/ethereum/homestead/transactions.v index 6d1bc6b..3db6fc4 100644 --- a/CoqOfPython/ethereum/homestead/transactions.v +++ b/CoqOfPython/ethereum/homestead/transactions.v @@ -17,21 +17,21 @@ Require typing. Axiom typing_Union : IsGlobalAlias globals typing.globals "Union". -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes0 : - IsGlobalAlias globals base_types.globals "Bytes0". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.homestead.fork_types. +Axiom ethereum_homestead_fork_types_Address : + IsGlobalAlias globals ethereum.homestead.fork_types.globals "Address". Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( Constant.int 21000 diff --git a/CoqOfPython/ethereum/homestead/trie.v b/CoqOfPython/ethereum/homestead/trie.v index e2ac401..a1932cd 100644 --- a/CoqOfPython/ethereum/homestead/trie.v +++ b/CoqOfPython/ethereum/homestead/trie.v @@ -54,9 +54,9 @@ Require ethereum.crypto.hash. Axiom ethereum_crypto_hash_keccak256 : IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". -Require ethereum.frontier. -Axiom ethereum_frontier_trie : - IsGlobalAlias globals ethereum.frontier.globals "trie". +Require ethereum.frontier.__init__. +Axiom ethereum_frontier___init___trie : + IsGlobalAlias globals ethereum.frontier.__init__.globals "trie". Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : @@ -66,37 +66,37 @@ Require ethereum.utils.hexadecimal. Axiom ethereum_utils_hexadecimal_hex_to_bytes : IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require blocks. -Axiom blocks_Receipt : - IsGlobalAlias globals blocks.globals "Receipt". - -Require fork_types. -Axiom fork_types_Account : - IsGlobalAlias globals fork_types.globals "Account". -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". -Axiom fork_types_encode_account : - IsGlobalAlias globals fork_types.globals "encode_account". - -Require transactions. -Axiom transactions_Transaction : - IsGlobalAlias globals transactions.globals "Transaction". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.homestead.blocks. +Axiom ethereum_homestead_blocks_Receipt : + IsGlobalAlias globals ethereum.homestead.blocks.globals "Receipt". + +Require ethereum.homestead.fork_types. +Axiom ethereum_homestead_fork_types_Account : + IsGlobalAlias globals ethereum.homestead.fork_types.globals "Account". +Axiom ethereum_homestead_fork_types_Address : + IsGlobalAlias globals ethereum.homestead.fork_types.globals "Address". +Axiom ethereum_homestead_fork_types_Root : + IsGlobalAlias globals ethereum.homestead.fork_types.globals "Root". +Axiom ethereum_homestead_fork_types_encode_account : + IsGlobalAlias globals ethereum.homestead.fork_types.globals "encode_account". + +Require ethereum.homestead.transactions. +Axiom ethereum_homestead_transactions_Transaction : + IsGlobalAlias globals ethereum.homestead.transactions.globals "Transaction". Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -202,16 +202,99 @@ Definition encode_internal_node : Value.t -> Value.t -> M := " in (* At stmt: unsupported node type: AnnAssign *) let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "node" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + Constant.bytes "" in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "LeafNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "rest_of_key" |); + Constant.bool true + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "ExtensionNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "key_segment" |); + Constant.bool false + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "BranchNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + BinOp.add (| + M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "value" |) + ] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ - (* At expr: unsupported node type: JoinedStr *) + Constant.str "(* At expr: unsupported node type: JoinedStr *)" ], make_dict [] - |)) + |)) |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -229,6 +312,26 @@ Definition encode_internal_node : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded" |) + ], + make_dict [] + |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "unencoded" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_name (| globals, "keccak256" |), @@ -237,6 +340,7 @@ Definition encode_internal_node : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -250,8 +354,86 @@ Definition encode_node : Value.t -> Value.t -> M := Currently mostly an unimplemented stub. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| + M.get_name (| globals, "storage_root" |), + Constant.None_ + |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "encode_account" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "storage_root" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + make_tuple [ M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "U256" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "cast" |), + make_list [ + M.get_field (| M.get_name (| globals, "rlp" |), "RLP" |); + M.get_name (| globals, "node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "node" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "previous_trie" |), "encode_node" |), @@ -261,6 +443,7 @@ Definition encode_node : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -312,6 +495,7 @@ Definition copy_trie : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition trie_set : Value.t -> Value.t -> M := @@ -333,6 +517,32 @@ Definition trie_set : Value.t -> Value.t -> M := Node to insert at `key`. " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + M.get_field (| M.get_name (| globals, "trie" |), "default" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "key" |), + M.get_field (| M.get_name (| globals, "trie" |), "_data" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), M.get_name (| globals, "value" |) @@ -370,6 +580,7 @@ Definition trie_get : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition common_prefix_length : Value.t -> Value.t -> M := @@ -392,6 +603,34 @@ Definition common_prefix_length : Value.t -> Value.t -> M := make_dict [] |) do let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), + M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -403,6 +642,7 @@ Definition common_prefix_length : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition nibble_list_to_compact : Value.t -> Value.t -> M := @@ -448,6 +688,71 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + Constant.int 2 + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.mult (| + Constant.int 16, + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "is_leaf" |) + |) + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ @@ -509,6 +814,7 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition bytes_to_nibble_list : Value.t -> Value.t -> M := @@ -586,6 +892,7 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition _prepare_trie : Value.t -> Value.t -> M := @@ -615,6 +922,48 @@ Definition _prepare_trie : Value.t -> Value.t -> M := make_dict [] |) do let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| + M.get_name (| globals, "get_storage_root" |), + Constant.None_ + |) |) in + let address := + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |); + M.call (| + M.get_name (| globals, "get_storage_root" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let encoded_value := M.call (| M.get_name (| globals, "encode_node" |), @@ -638,6 +987,22 @@ Definition _prepare_trie : Value.t -> Value.t -> M := |) in (* At stmt: unsupported node type: AnnAssign *) let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "trie" |), "secured" |), + (* then *) + ltac:(M.monadic ( + let key := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let key := M.get_name (| globals, "preimage" |) in M.pure Constant.None_ @@ -655,6 +1020,7 @@ Definition _prepare_trie : Value.t -> Value.t -> M := EndFor. let _ := M.return_ (| M.get_name (| globals, "mapped" |) + |) in M.pure Constant.None_)). Definition root : Value.t -> Value.t -> M := @@ -708,6 +1074,44 @@ Definition root : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -724,6 +1128,7 @@ Definition root : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -750,6 +1155,26 @@ Definition patricialize : Value.t -> Value.t -> M := Root node of `obj`. " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let arbitrary_key := @@ -767,10 +1192,39 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), + Constant.int 1 + |), + (* then *) + ltac:(M.monadic ( + let leaf := + M.call (| + M.get_name (| globals, "LeafNode" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |); + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "leaf" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let substring := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |) |) in + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) in let prefix_length := M.call (| M.get_name (| globals, "len" |), @@ -789,7 +1243,7 @@ Definition patricialize : Value.t -> Value.t -> M := M.get_name (| globals, "common_prefix_length" |), make_list [ M.get_name (| globals, "substring" |); - M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) + M.get_subscript (| M.get_name (| globals, "key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) ], make_dict [] |) @@ -797,10 +1251,64 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "prefix_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "prefix_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let prefix := + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ExtensionNode" |), + make_list [ + M.get_name (| globals, "prefix" |); + M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_name (| globals, "obj" |); + BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) @@ -823,6 +1331,44 @@ Definition patricialize : Value.t -> Value.t -> M := Constant.bytes "" in For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |), + M.get_name (| globals, "level" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "AssertionError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) @@ -834,9 +1380,10 @@ Definition patricialize : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "BranchNode" |), make_list [ - (* At expr: unsupported node type: ListComp *); + Constant.str "(* At expr: unsupported node type: ListComp *)"; M.get_name (| globals, "value" |) ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/utils/address.v b/CoqOfPython/ethereum/homestead/utils/address.v index fef11f0..793d8bd 100644 --- a/CoqOfPython/ethereum/homestead/utils/address.v +++ b/CoqOfPython/ethereum/homestead/utils/address.v @@ -35,13 +35,13 @@ Require ethereum.utils.byte. Axiom ethereum_utils_byte_left_pad_zero_bytes : IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.homestead.fork_types. +Axiom ethereum_homestead_fork_types_Address : + IsGlobalAlias globals ethereum.homestead.fork_types.globals "Address". Definition to_address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -67,10 +67,11 @@ Definition to_address : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), make_list [], make_dict [] - |), UnOp.sub (| Constant.int 20 |) |) + |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) ], make_dict [] |) + |) in M.pure Constant.None_)). Definition compute_contract_address : Value.t -> Value.t -> M := @@ -110,7 +111,7 @@ Definition compute_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -128,4 +129,5 @@ Definition compute_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/utils/hexadecimal.v b/CoqOfPython/ethereum/homestead/utils/hexadecimal.v index 661eab7..cb864a9 100644 --- a/CoqOfPython/ethereum/homestead/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/homestead/utils/hexadecimal.v @@ -22,13 +22,13 @@ Require ethereum.utils.hexadecimal. Axiom ethereum_utils_hexadecimal_remove_hex_prefix : IsGlobalAlias globals ethereum.utils.hexadecimal.globals "remove_hex_prefix". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". +Require ethereum.homestead.fork_types. +Axiom ethereum_homestead_fork_types_Address : + IsGlobalAlias globals ethereum.homestead.fork_types.globals "Address". +Axiom ethereum_homestead_fork_types_Bloom : + IsGlobalAlias globals ethereum.homestead.fork_types.globals "Bloom". +Axiom ethereum_homestead_fork_types_Root : + IsGlobalAlias globals ethereum.homestead.fork_types.globals "Root". Definition hex_to_root : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -66,6 +66,7 @@ Definition hex_to_root : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition hex_to_bloom : Value.t -> Value.t -> M := @@ -104,6 +105,7 @@ Definition hex_to_bloom : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition hex_to_address : Value.t -> Value.t -> M := @@ -149,4 +151,5 @@ Definition hex_to_address : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/utils/message.v b/CoqOfPython/ethereum/homestead/utils/message.v index d43d092..e72658e 100644 --- a/CoqOfPython/ethereum/homestead/utils/message.v +++ b/CoqOfPython/ethereum/homestead/utils/message.v @@ -33,23 +33,23 @@ Axiom ethereum_base_types_Bytes0 : Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.homestead.fork_types. +Axiom ethereum_homestead_fork_types_Address : + IsGlobalAlias globals ethereum.homestead.fork_types.globals "Address". -Require state. -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". +Require ethereum.homestead.state. +Axiom ethereum_homestead_state_get_account : + IsGlobalAlias globals ethereum.homestead.state.globals "get_account". -Require vm. -Axiom vm_Environment : - IsGlobalAlias globals vm.globals "Environment". -Axiom vm_Message : - IsGlobalAlias globals vm.globals "Message". +Require ethereum.homestead.vm.__init__. +Axiom ethereum_homestead_vm___init___Environment : + IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "Environment". +Axiom ethereum_homestead_vm___init___Message : + IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "Message". -Require address. -Axiom address_compute_contract_address : - IsGlobalAlias globals address.globals "compute_contract_address". +Require ethereum.homestead.utils.address. +Axiom ethereum_homestead_utils_address_compute_contract_address : + IsGlobalAlias globals ethereum.homestead.utils.address.globals "compute_contract_address". Definition prepare_message : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -84,14 +84,108 @@ Definition prepare_message : Value.t -> Value.t -> M := Items containing contract creation or message call specific data. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Bytes0" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.call (| + M.get_name (| globals, "compute_contract_address" |), + make_list [ + M.get_name (| globals, "caller" |); + BinOp.sub (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "caller" |) + ], + make_dict [] + |), "nonce" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let msg_data := + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) in + let code := + M.get_name (| globals, "data" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.get_name (| globals, "target" |) in + let msg_data := + M.get_name (| globals, "data" |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "target" |) + ], + make_dict [] + |), "code" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "code_address" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let code_address := + M.get_name (| globals, "target" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "Target must be address or empty bytes" ], make_dict [] - |)) + |)) |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -102,4 +196,5 @@ Definition prepare_message : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/vm/__init__.v b/CoqOfPython/ethereum/homestead/vm/__init__.v index 49bcb40..11ebd54 100644 --- a/CoqOfPython/ethereum/homestead/vm/__init__.v +++ b/CoqOfPython/ethereum/homestead/vm/__init__.v @@ -48,17 +48,17 @@ Require ethereum.crypto.hash. Axiom ethereum_crypto_hash_Hash32 : IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". +Require ethereum.homestead.blocks. +Axiom ethereum_homestead_blocks_Log : + IsGlobalAlias globals ethereum.homestead.blocks.globals "Log". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.homestead.fork_types. +Axiom ethereum_homestead_fork_types_Address : + IsGlobalAlias globals ethereum.homestead.fork_types.globals "Address". -Require state. -Axiom state_State : - IsGlobalAlias globals state.globals "State". +Require ethereum.homestead.state. +Axiom ethereum_homestead_state_State : + IsGlobalAlias globals ethereum.homestead.state.globals "State". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] diff --git a/CoqOfPython/ethereum/homestead/vm/gas.v b/CoqOfPython/ethereum/homestead/vm/gas.v index eef500a..0403b1e 100644 --- a/CoqOfPython/ethereum/homestead/vm/gas.v +++ b/CoqOfPython/ethereum/homestead/vm/gas.v @@ -43,23 +43,23 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.homestead.fork_types. +Axiom ethereum_homestead_fork_types_Address : + IsGlobalAlias globals ethereum.homestead.fork_types.globals "Address". -Require state. -Axiom state_State : - IsGlobalAlias globals state.globals "State". -Axiom state_account_exists : - IsGlobalAlias globals state.globals "account_exists". +Require ethereum.homestead.state. +Axiom ethereum_homestead_state_State : + IsGlobalAlias globals ethereum.homestead.state.globals "State". +Axiom ethereum_homestead_state_account_exists : + IsGlobalAlias globals ethereum.homestead.state.globals "account_exists". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.homestead.vm.__init__. +Axiom ethereum_homestead_vm___init___Evm : + IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "Evm". -Require exceptions. -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". +Require ethereum.homestead.vm.exceptions. +Axiom ethereum_homestead_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.homestead.vm.exceptions.globals "OutOfGasError". Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -480,6 +480,18 @@ Definition charge_gas : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "amount" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign_op (| BinOp.sub, M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), @@ -595,6 +607,18 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := |) in For make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ] in M.get_name (| globals, "extensions" |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "size" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let before_size := @@ -629,6 +653,18 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let size_to_extend := BinOp.add @@ -677,6 +713,7 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition calculate_message_call_gas : Value.t -> Value.t -> M := @@ -701,41 +738,49 @@ Definition calculate_message_call_gas : Value.t -> Value.t -> M := message_call_gas: `MessageCallGas` " in let create_gas_cost := - (* if *) -M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "to" |) - ], - make_dict [] - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "to" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "GAS_NEW_ACCOUNT" |) + )) |) in let transfer_gas_cost := - (* if *) -M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "GAS_CALL_VALUE" |) + )) |) in let cost := BinOp.add (| BinOp.add (| @@ -748,15 +793,22 @@ M.call (| M.get_name (| globals, "transfer_gas_cost" |) |) in let stipend := - (* if *) -M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), -(* then *) -ltac:(M.monadic ( -M.get_name (| globals, "gas" |) in + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( +M.get_name (| globals, "gas" |) + (* else *) + )), ltac:(M.monadic ( +BinOp.add (| + M.get_name (| globals, "GAS_CALL_STIPEND" |), + M.get_name (| globals, "gas" |) + |) + )) |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "MessageCallGas" |), @@ -766,4 +818,5 @@ M.get_name (| globals, "gas" |) in ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/__init__.v b/CoqOfPython/ethereum/homestead/vm/instructions/__init__.v index e5bebd7..4398890 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/__init__.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/__init__.v @@ -26,53 +26,53 @@ Axiom typing_Callable : Axiom typing_Dict : IsGlobalAlias globals typing.globals "Dict". -Require __init__. -Axiom __init___arithmetic : - IsGlobalAlias globals __init__.globals "arithmetic". +Require ethereum.homestead.vm.instructions.__init__. +Axiom ethereum_homestead_vm_instructions___init___arithmetic : + IsGlobalAlias globals ethereum.homestead.vm.instructions.__init__.globals "arithmetic". -Require __init__. -Axiom __init___bitwise : - IsGlobalAlias globals __init__.globals "bitwise". +Require ethereum.homestead.vm.instructions.__init__. +Axiom ethereum_homestead_vm_instructions___init___bitwise : + IsGlobalAlias globals ethereum.homestead.vm.instructions.__init__.globals "bitwise". -Require __init__. -Axiom __init___block : - IsGlobalAlias globals __init__.globals "block". +Require ethereum.homestead.vm.instructions.__init__. +Axiom ethereum_homestead_vm_instructions___init___block : + IsGlobalAlias globals ethereum.homestead.vm.instructions.__init__.globals "block". -Require __init__. -Axiom __init___comparison : - IsGlobalAlias globals __init__.globals "comparison". +Require ethereum.homestead.vm.instructions.__init__. +Axiom ethereum_homestead_vm_instructions___init___comparison : + IsGlobalAlias globals ethereum.homestead.vm.instructions.__init__.globals "comparison". -Require __init__. -Axiom __init___control_flow : - IsGlobalAlias globals __init__.globals "control_flow". +Require ethereum.homestead.vm.instructions.__init__. +Axiom ethereum_homestead_vm_instructions___init___control_flow : + IsGlobalAlias globals ethereum.homestead.vm.instructions.__init__.globals "control_flow". -Require __init__. -Axiom __init___environment : - IsGlobalAlias globals __init__.globals "environment". +Require ethereum.homestead.vm.instructions.__init__. +Axiom ethereum_homestead_vm_instructions___init___environment : + IsGlobalAlias globals ethereum.homestead.vm.instructions.__init__.globals "environment". -Require __init__. -Axiom __init___keccak : - IsGlobalAlias globals __init__.globals "keccak". +Require ethereum.homestead.vm.instructions.__init__. +Axiom ethereum_homestead_vm_instructions___init___keccak : + IsGlobalAlias globals ethereum.homestead.vm.instructions.__init__.globals "keccak". -Require __init__. -Axiom __init___log : - IsGlobalAlias globals __init__.globals "log". +Require ethereum.homestead.vm.instructions.__init__. +Axiom ethereum_homestead_vm_instructions___init___log : + IsGlobalAlias globals ethereum.homestead.vm.instructions.__init__.globals "log". -Require __init__. -Axiom __init___memory : - IsGlobalAlias globals __init__.globals "memory". +Require ethereum.homestead.vm.instructions.__init__. +Axiom ethereum_homestead_vm_instructions___init___memory : + IsGlobalAlias globals ethereum.homestead.vm.instructions.__init__.globals "memory". -Require __init__. -Axiom __init___stack : - IsGlobalAlias globals __init__.globals "stack". +Require ethereum.homestead.vm.instructions.__init__. +Axiom ethereum_homestead_vm_instructions___init___stack : + IsGlobalAlias globals ethereum.homestead.vm.instructions.__init__.globals "stack". -Require __init__. -Axiom __init___storage : - IsGlobalAlias globals __init__.globals "storage". +Require ethereum.homestead.vm.instructions.__init__. +Axiom ethereum_homestead_vm_instructions___init___storage : + IsGlobalAlias globals ethereum.homestead.vm.instructions.__init__.globals "storage". -Require __init__. -Axiom __init___system : - IsGlobalAlias globals __init__.globals "system". +Require ethereum.homestead.vm.instructions.__init__. +Axiom ethereum_homestead_vm_instructions___init___system : + IsGlobalAlias globals ethereum.homestead.vm.instructions.__init__.globals "system". Definition Ops : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/homestead/vm/instructions/arithmetic.v index 581ba5d..f3ce972 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/arithmetic.v @@ -31,29 +31,29 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_get_sign : IsGlobalAlias globals ethereum.utils.numeric.globals "get_sign". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_EXPONENTIATION : - IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION". -Axiom gas_GAS_EXPONENTIATION_PER_BYTE : - IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION_PER_BYTE". -Axiom gas_GAS_LOW : - IsGlobalAlias globals gas.globals "GAS_LOW". -Axiom gas_GAS_MID : - IsGlobalAlias globals gas.globals "GAS_MID". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.homestead.vm.__init__. +Axiom ethereum_homestead_vm___init___Evm : + IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "Evm". + +Require ethereum.homestead.vm.gas. +Axiom ethereum_homestead_vm_gas_GAS_EXPONENTIATION : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_EXPONENTIATION". +Axiom ethereum_homestead_vm_gas_GAS_EXPONENTIATION_PER_BYTE : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_EXPONENTIATION_PER_BYTE". +Axiom ethereum_homestead_vm_gas_GAS_LOW : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_LOW". +Axiom ethereum_homestead_vm_gas_GAS_MID : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_MID". +Axiom ethereum_homestead_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_homestead_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "charge_gas". + +Require ethereum.homestead.vm.stack. +Axiom ethereum_homestead_vm_stack_pop : + IsGlobalAlias globals ethereum.homestead.vm.stack.globals "pop". +Axiom ethereum_homestead_vm_stack_push : + IsGlobalAlias globals ethereum.homestead.vm.stack.globals "push". Definition add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -273,6 +273,25 @@ Definition div : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "divisor" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let quotient := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let quotient := BinOp.floor_div (| M.get_name (| globals, "dividend" |), @@ -341,7 +360,41 @@ Definition sdiv : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "divisor" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let quotient := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_name (| globals, "dividend" |), + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "divisor" |), + UnOp.sub (| Constant.int 1 |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let quotient := + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let sign := M.call (| M.get_name (| globals, "get_sign" |), @@ -436,6 +489,25 @@ Definition mod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "y" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let remainder := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let remainder := BinOp.mod_ (| M.get_name (| globals, "x" |), @@ -504,6 +576,19 @@ Definition smod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "y" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let remainder := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let remainder := BinOp.mult (| M.call (| @@ -617,6 +702,25 @@ Definition addmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "z" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -712,6 +816,25 @@ Definition mulmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "z" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -881,6 +1004,19 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "byte_num" |), + Constant.int 31 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.get_name (| globals, "value" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let value_bytes := M.call (| M.get_name (| globals, "bytes" |), @@ -894,7 +1030,7 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let value_bytes := - M.get_subscript (| M.get_name (| globals, "value_bytes" |), BinOp.sub (| + M.get_subscript (| M.get_name (| globals, "value_bytes" |), M.slice (| BinOp.sub (| Constant.int 31, M.call (| M.get_name (| globals, "int" |), @@ -903,13 +1039,32 @@ Definition signextend : Value.t -> Value.t -> M := ], make_dict [] |) - |) |) in + |), Constant.None_ |) |) in let sign_bit := BinOp.r_shift (| M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), Constant.int 7 |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "sign_bit" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "value_bytes" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let num_bytes_prepend := BinOp.sub (| Constant.int 32, diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/bitwise.v b/CoqOfPython/ethereum/homestead/vm/instructions/bitwise.v index f38e7aa..623316d 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/bitwise.v @@ -21,21 +21,21 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.homestead.vm.__init__. +Axiom ethereum_homestead_vm___init___Evm : + IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.homestead.vm.gas. +Axiom ethereum_homestead_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_homestead_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "charge_gas". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.homestead.vm.stack. +Axiom ethereum_homestead_vm_stack_pop : + IsGlobalAlias globals ethereum.homestead.vm.stack.globals "pop". +Axiom ethereum_homestead_vm_stack_push : + IsGlobalAlias globals ethereum.homestead.vm.stack.globals "push". Definition bitwise_and : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -285,6 +285,25 @@ Definition get_byte : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "byte_index" |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let extra_bytes_to_right := BinOp.sub (| Constant.int 31, diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/block.v b/CoqOfPython/ethereum/homestead/vm/instructions/block.v index 90be45c..0c0fa2b 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/block.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/block.v @@ -21,23 +21,23 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_BLOCK_HASH : - IsGlobalAlias globals gas.globals "GAS_BLOCK_HASH". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.homestead.vm.__init__. +Axiom ethereum_homestead_vm___init___Evm : + IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "Evm". + +Require ethereum.homestead.vm.gas. +Axiom ethereum_homestead_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_BASE". +Axiom ethereum_homestead_vm_gas_GAS_BLOCK_HASH : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_BLOCK_HASH". +Axiom ethereum_homestead_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "charge_gas". + +Require ethereum.homestead.vm.stack. +Axiom ethereum_homestead_vm_stack_pop : + IsGlobalAlias globals ethereum.homestead.vm.stack.globals "pop". +Axiom ethereum_homestead_vm_stack_push : + IsGlobalAlias globals ethereum.homestead.vm.stack.globals "push". Definition block_hash : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -69,6 +69,30 @@ Definition block_hash : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt_e (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + M.get_name (| globals, "block_number" |) + |), + ltac:(M.monadic ( + Compare.gt (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + BinOp.add (| + M.get_name (| globals, "block_number" |), + Constant.int 256 + |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let hash := + Constant.bytes "00" in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let hash := M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/comparison.v b/CoqOfPython/ethereum/homestead/vm/instructions/comparison.v index b8529d8..55d09e3 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/comparison.v @@ -21,21 +21,21 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.homestead.vm.__init__. +Axiom ethereum_homestead_vm___init___Evm : + IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.homestead.vm.gas. +Axiom ethereum_homestead_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_homestead_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "charge_gas". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.homestead.vm.stack. +Axiom ethereum_homestead_vm_stack_pop : + IsGlobalAlias globals ethereum.homestead.vm.stack.globals "pop". +Axiom ethereum_homestead_vm_stack_push : + IsGlobalAlias globals ethereum.homestead.vm.stack.globals "push". Definition less_than : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/control_flow.v b/CoqOfPython/ethereum/homestead/vm/instructions/control_flow.v index d4e4eae..8be3532 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/control_flow.v @@ -23,31 +23,31 @@ Axiom ethereum_base_types_U256 : Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require vm.gas. -Axiom vm_gas_GAS_BASE : - IsGlobalAlias globals vm.gas.globals "GAS_BASE". -Axiom vm_gas_GAS_HIGH : - IsGlobalAlias globals vm.gas.globals "GAS_HIGH". -Axiom vm_gas_GAS_JUMPDEST : - IsGlobalAlias globals vm.gas.globals "GAS_JUMPDEST". -Axiom vm_gas_GAS_MID : - IsGlobalAlias globals vm.gas.globals "GAS_MID". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.homestead.vm.gas. +Axiom ethereum_homestead_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_BASE". +Axiom ethereum_homestead_vm_gas_GAS_HIGH : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_HIGH". +Axiom ethereum_homestead_vm_gas_GAS_JUMPDEST : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_JUMPDEST". +Axiom ethereum_homestead_vm_gas_GAS_MID : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_MID". +Axiom ethereum_homestead_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "charge_gas". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.homestead.vm.__init__. +Axiom ethereum_homestead_vm___init___Evm : + IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "Evm". -Require exceptions. -Axiom exceptions_InvalidJumpDestError : - IsGlobalAlias globals exceptions.globals "InvalidJumpDestError". +Require ethereum.homestead.vm.exceptions. +Axiom ethereum_homestead_vm_exceptions_InvalidJumpDestError : + IsGlobalAlias globals ethereum.homestead.vm.exceptions.globals "InvalidJumpDestError". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.homestead.vm.stack. +Axiom ethereum_homestead_vm_stack_pop : + IsGlobalAlias globals ethereum.homestead.vm.stack.globals "pop". +Axiom ethereum_homestead_vm_stack_push : + IsGlobalAlias globals ethereum.homestead.vm.stack.globals "push". Definition stop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -109,6 +109,18 @@ Definition jump : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "jump_dest" |), + M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -168,7 +180,35 @@ Definition jumpi : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "conditional_value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let destination := + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "jump_dest" |), + M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let destination := M.get_name (| globals, "jump_dest" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/environment.v b/CoqOfPython/ethereum/homestead/vm/instructions/environment.v index 366e59a..dfa51f1 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/environment.v @@ -27,45 +27,45 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require state. -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". - -Require utils.address. -Axiom utils_address_to_address : - IsGlobalAlias globals utils.address.globals "to_address". - -Require vm.memory. -Axiom vm_memory_buffer_read : - IsGlobalAlias globals vm.memory.globals "buffer_read". -Axiom vm_memory_memory_write : - IsGlobalAlias globals vm.memory.globals "memory_write". - -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_BALANCE : - IsGlobalAlias globals gas.globals "GAS_BALANCE". -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_COPY : - IsGlobalAlias globals gas.globals "GAS_COPY". -Axiom gas_GAS_EXTERNAL : - IsGlobalAlias globals gas.globals "GAS_EXTERNAL". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.homestead.state. +Axiom ethereum_homestead_state_get_account : + IsGlobalAlias globals ethereum.homestead.state.globals "get_account". + +Require ethereum.homestead.utils.address. +Axiom ethereum_homestead_utils_address_to_address : + IsGlobalAlias globals ethereum.homestead.utils.address.globals "to_address". + +Require ethereum.homestead.vm.memory. +Axiom ethereum_homestead_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.homestead.vm.memory.globals "buffer_read". +Axiom ethereum_homestead_vm_memory_memory_write : + IsGlobalAlias globals ethereum.homestead.vm.memory.globals "memory_write". + +Require ethereum.homestead.vm.__init__. +Axiom ethereum_homestead_vm___init___Evm : + IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "Evm". + +Require ethereum.homestead.vm.gas. +Axiom ethereum_homestead_vm_gas_GAS_BALANCE : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_BALANCE". +Axiom ethereum_homestead_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_BASE". +Axiom ethereum_homestead_vm_gas_GAS_COPY : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_COPY". +Axiom ethereum_homestead_vm_gas_GAS_EXTERNAL : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_EXTERNAL". +Axiom ethereum_homestead_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_homestead_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_homestead_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "charge_gas". + +Require ethereum.homestead.vm.stack. +Axiom ethereum_homestead_vm_stack_pop : + IsGlobalAlias globals ethereum.homestead.vm.stack.globals "pop". +Axiom ethereum_homestead_vm_stack_push : + IsGlobalAlias globals ethereum.homestead.vm.stack.globals "push". Definition address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/keccak.v b/CoqOfPython/ethereum/homestead/vm/instructions/keccak.v index 2c4b10e..6a6a593 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/keccak.v @@ -31,29 +31,29 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_KECCAK256 : - IsGlobalAlias globals gas.globals "GAS_KECCAK256". -Axiom gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.homestead.vm.__init__. +Axiom ethereum_homestead_vm___init___Evm : + IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "Evm". + +Require ethereum.homestead.vm.gas. +Axiom ethereum_homestead_vm_gas_GAS_KECCAK256 : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_KECCAK256". +Axiom ethereum_homestead_vm_gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_KECCAK256_WORD". +Axiom ethereum_homestead_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_homestead_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "charge_gas". + +Require ethereum.homestead.vm.memory. +Axiom ethereum_homestead_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.homestead.vm.memory.globals "memory_read_bytes". + +Require ethereum.homestead.vm.stack. +Axiom ethereum_homestead_vm_stack_pop : + IsGlobalAlias globals ethereum.homestead.vm.stack.globals "pop". +Axiom ethereum_homestead_vm_stack_push : + IsGlobalAlias globals ethereum.homestead.vm.stack.globals "push". Definition keccak : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/log.v b/CoqOfPython/ethereum/homestead/vm/instructions/log.v index ab196bc..1c37f23 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/log.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/log.v @@ -25,33 +25,33 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". - -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_LOG : - IsGlobalAlias globals gas.globals "GAS_LOG". -Axiom gas_GAS_LOG_DATA : - IsGlobalAlias globals gas.globals "GAS_LOG_DATA". -Axiom gas_GAS_LOG_TOPIC : - IsGlobalAlias globals gas.globals "GAS_LOG_TOPIC". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". +Require ethereum.homestead.blocks. +Axiom ethereum_homestead_blocks_Log : + IsGlobalAlias globals ethereum.homestead.blocks.globals "Log". + +Require ethereum.homestead.vm.__init__. +Axiom ethereum_homestead_vm___init___Evm : + IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "Evm". + +Require ethereum.homestead.vm.gas. +Axiom ethereum_homestead_vm_gas_GAS_LOG : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_LOG". +Axiom ethereum_homestead_vm_gas_GAS_LOG_DATA : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_LOG_DATA". +Axiom ethereum_homestead_vm_gas_GAS_LOG_TOPIC : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_LOG_TOPIC". +Axiom ethereum_homestead_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_homestead_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "charge_gas". + +Require ethereum.homestead.vm.memory. +Axiom ethereum_homestead_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.homestead.vm.memory.globals "memory_read_bytes". + +Require ethereum.homestead.vm.stack. +Axiom ethereum_homestead_vm_stack_pop : + IsGlobalAlias globals ethereum.homestead.vm.stack.globals "pop". Definition log_n : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/memory.v b/CoqOfPython/ethereum/homestead/vm/instructions/memory.v index 86ba742..3631aa5 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/memory.v @@ -23,31 +23,31 @@ Axiom ethereum_base_types_U256 : Axiom ethereum_base_types_Bytes : IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.homestead.vm.__init__. +Axiom ethereum_homestead_vm___init___Evm : + IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.homestead.vm.gas. +Axiom ethereum_homestead_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_BASE". +Axiom ethereum_homestead_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_homestead_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_homestead_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "charge_gas". -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". -Axiom memory_memory_write : - IsGlobalAlias globals memory.globals "memory_write". +Require ethereum.homestead.vm.memory. +Axiom ethereum_homestead_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.homestead.vm.memory.globals "memory_read_bytes". +Axiom ethereum_homestead_vm_memory_memory_write : + IsGlobalAlias globals ethereum.homestead.vm.memory.globals "memory_write". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.homestead.vm.stack. +Axiom ethereum_homestead_vm_stack_pop : + IsGlobalAlias globals ethereum.homestead.vm.stack.globals "pop". +Axiom ethereum_homestead_vm_stack_push : + IsGlobalAlias globals ethereum.homestead.vm.stack.globals "push". Definition mstore : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/stack.v b/CoqOfPython/ethereum/homestead/vm/instructions/stack.v index 305af15..8498137 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/stack.v @@ -29,27 +29,27 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". -Axiom __init___stack : - IsGlobalAlias globals __init__.globals "stack". - -Require exceptions. -Axiom exceptions_StackUnderflowError : - IsGlobalAlias globals exceptions.globals "StackUnderflowError". - -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require memory. -Axiom memory_buffer_read : - IsGlobalAlias globals memory.globals "buffer_read". +Require ethereum.homestead.vm.__init__. +Axiom ethereum_homestead_vm___init___Evm : + IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "Evm". +Axiom ethereum_homestead_vm___init___stack : + IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "stack". + +Require ethereum.homestead.vm.exceptions. +Axiom ethereum_homestead_vm_exceptions_StackUnderflowError : + IsGlobalAlias globals ethereum.homestead.vm.exceptions.globals "StackUnderflowError". + +Require ethereum.homestead.vm.gas. +Axiom ethereum_homestead_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_BASE". +Axiom ethereum_homestead_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_homestead_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "charge_gas". + +Require ethereum.homestead.vm.memory. +Axiom ethereum_homestead_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.homestead.vm.memory.globals "buffer_read". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/storage.v b/CoqOfPython/ethereum/homestead/vm/instructions/storage.v index 5250214..3b90027 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/storage.v @@ -17,33 +17,33 @@ Introduction Implementations of the EVM storage related instructions. ". -Require state. -Axiom state_get_storage : - IsGlobalAlias globals state.globals "get_storage". -Axiom state_set_storage : - IsGlobalAlias globals state.globals "set_storage". +Require ethereum.homestead.state. +Axiom ethereum_homestead_state_get_storage : + IsGlobalAlias globals ethereum.homestead.state.globals "get_storage". +Axiom ethereum_homestead_state_set_storage : + IsGlobalAlias globals ethereum.homestead.state.globals "set_storage". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.homestead.vm.__init__. +Axiom ethereum_homestead_vm___init___Evm : + IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_SLOAD : - IsGlobalAlias globals gas.globals "GAS_SLOAD". -Axiom gas_GAS_STORAGE_CLEAR_REFUND : - IsGlobalAlias globals gas.globals "GAS_STORAGE_CLEAR_REFUND". -Axiom gas_GAS_STORAGE_SET : - IsGlobalAlias globals gas.globals "GAS_STORAGE_SET". -Axiom gas_GAS_STORAGE_UPDATE : - IsGlobalAlias globals gas.globals "GAS_STORAGE_UPDATE". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.homestead.vm.gas. +Axiom ethereum_homestead_vm_gas_GAS_SLOAD : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_SLOAD". +Axiom ethereum_homestead_vm_gas_GAS_STORAGE_CLEAR_REFUND : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_STORAGE_CLEAR_REFUND". +Axiom ethereum_homestead_vm_gas_GAS_STORAGE_SET : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_STORAGE_SET". +Axiom ethereum_homestead_vm_gas_GAS_STORAGE_UPDATE : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_STORAGE_UPDATE". +Axiom ethereum_homestead_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "charge_gas". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.homestead.vm.stack. +Axiom ethereum_homestead_vm_stack_pop : + IsGlobalAlias globals ethereum.homestead.vm.stack.globals "pop". +Axiom ethereum_homestead_vm_stack_push : + IsGlobalAlias globals ethereum.homestead.vm.stack.globals "push". Definition sload : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -146,11 +146,56 @@ Definition sstore : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "new_value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "current_value" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let gas_cost := + M.get_name (| globals, "GAS_STORAGE_SET" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let gas_cost := M.get_name (| globals, "GAS_STORAGE_UPDATE" |) in M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_name (| globals, "new_value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "current_value" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/system.v b/CoqOfPython/ethereum/homestead/vm/instructions/system.v index d3dc734..c2af944 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/system.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/system.v @@ -25,63 +25,63 @@ Axiom ethereum_base_types_Bytes0 : Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.homestead.fork_types. +Axiom ethereum_homestead_fork_types_Address : + IsGlobalAlias globals ethereum.homestead.fork_types.globals "Address". -Require state. -Axiom state_account_has_code_or_nonce : - IsGlobalAlias globals state.globals "account_has_code_or_nonce". -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". -Axiom state_increment_nonce : - IsGlobalAlias globals state.globals "increment_nonce". -Axiom state_set_account_balance : - IsGlobalAlias globals state.globals "set_account_balance". +Require ethereum.homestead.state. +Axiom ethereum_homestead_state_account_has_code_or_nonce : + IsGlobalAlias globals ethereum.homestead.state.globals "account_has_code_or_nonce". +Axiom ethereum_homestead_state_get_account : + IsGlobalAlias globals ethereum.homestead.state.globals "get_account". +Axiom ethereum_homestead_state_increment_nonce : + IsGlobalAlias globals ethereum.homestead.state.globals "increment_nonce". +Axiom ethereum_homestead_state_set_account_balance : + IsGlobalAlias globals ethereum.homestead.state.globals "set_account_balance". -Require utils.address. -Axiom utils_address_compute_contract_address : - IsGlobalAlias globals utils.address.globals "compute_contract_address". -Axiom utils_address_to_address : - IsGlobalAlias globals utils.address.globals "to_address". +Require ethereum.homestead.utils.address. +Axiom ethereum_homestead_utils_address_compute_contract_address : + IsGlobalAlias globals ethereum.homestead.utils.address.globals "compute_contract_address". +Axiom ethereum_homestead_utils_address_to_address : + IsGlobalAlias globals ethereum.homestead.utils.address.globals "to_address". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". -Axiom __init___Message : - IsGlobalAlias globals __init__.globals "Message". -Axiom __init___incorporate_child_on_error : - IsGlobalAlias globals __init__.globals "incorporate_child_on_error". -Axiom __init___incorporate_child_on_success : - IsGlobalAlias globals __init__.globals "incorporate_child_on_success". +Require ethereum.homestead.vm.__init__. +Axiom ethereum_homestead_vm___init___Evm : + IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "Evm". +Axiom ethereum_homestead_vm___init___Message : + IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "Message". +Axiom ethereum_homestead_vm___init___incorporate_child_on_error : + IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "incorporate_child_on_error". +Axiom ethereum_homestead_vm___init___incorporate_child_on_success : + IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "incorporate_child_on_success". -Require gas. -Axiom gas_GAS_CALL : - IsGlobalAlias globals gas.globals "GAS_CALL". -Axiom gas_GAS_CREATE : - IsGlobalAlias globals gas.globals "GAS_CREATE". -Axiom gas_GAS_ZERO : - IsGlobalAlias globals gas.globals "GAS_ZERO". -Axiom gas_REFUND_SELF_DESTRUCT : - IsGlobalAlias globals gas.globals "REFUND_SELF_DESTRUCT". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_calculate_message_call_gas : - IsGlobalAlias globals gas.globals "calculate_message_call_gas". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.homestead.vm.gas. +Axiom ethereum_homestead_vm_gas_GAS_CALL : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_CALL". +Axiom ethereum_homestead_vm_gas_GAS_CREATE : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_CREATE". +Axiom ethereum_homestead_vm_gas_GAS_ZERO : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_ZERO". +Axiom ethereum_homestead_vm_gas_REFUND_SELF_DESTRUCT : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "REFUND_SELF_DESTRUCT". +Axiom ethereum_homestead_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_homestead_vm_gas_calculate_message_call_gas : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "calculate_message_call_gas". +Axiom ethereum_homestead_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "charge_gas". -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". -Axiom memory_memory_write : - IsGlobalAlias globals memory.globals "memory_write". +Require ethereum.homestead.vm.memory. +Axiom ethereum_homestead_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.homestead.vm.memory.globals "memory_read_bytes". +Axiom ethereum_homestead_vm_memory_memory_write : + IsGlobalAlias globals ethereum.homestead.vm.memory.globals "memory_write". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.homestead.vm.stack. +Axiom ethereum_homestead_vm_stack_pop : + IsGlobalAlias globals ethereum.homestead.vm.stack.globals "pop". +Axiom ethereum_homestead_vm_stack_push : + IsGlobalAlias globals ethereum.homestead.vm.stack.globals "push". Definition create : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -189,7 +189,105 @@ Definition create : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt (| + M.get_field (| M.get_name (| globals, "sender" |), "balance" |), + M.get_name (| globals, "endowment" |) + |), + ltac:(M.monadic ( + BoolOp.or (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "sender" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.sub (| + BinOp.pow (| + Constant.int 2, + Constant.int 64 + |), + Constant.int 1 + |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.gt (| + BinOp.add (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "depth" |), + Constant.int 1 + |), + M.get_name (| globals, "STACK_DEPTH_LIMIT" |) + |) + )) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "create_message_gas" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "contract_address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let call_data := M.call (| M.get_name (| globals, "memory_read_bytes" |), @@ -224,6 +322,36 @@ Definition create : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "child_evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_error" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "incorporate_child_on_success" |), make_list [ @@ -343,6 +471,42 @@ Definition generic_call : Value.t -> Value.t -> M := " in (* At stmt: unsupported node type: ImportFrom *) let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + BinOp.add (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "depth" |), + Constant.int 1 + |), + M.get_name (| globals, "STACK_DEPTH_LIMIT" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "gas" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let call_data := @@ -380,6 +544,36 @@ Definition generic_call : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "child_evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_error" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "incorporate_child_on_success" |), make_list [ @@ -430,7 +624,7 @@ Definition generic_call : Value.t -> Value.t -> M := make_list [ M.get_field (| M.get_name (| globals, "evm" |), "memory" |); M.get_name (| globals, "memory_output_start_position" |); - M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), Constant.None_:M.get_name (| globals, "actual_output_size" |) |) + M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), M.slice (| Constant.None_, M.get_name (| globals, "actual_output_size" |) |) |) ], make_dict [] |) in @@ -567,6 +761,36 @@ Definition call : Value.t -> Value.t -> M := make_dict [] |), "balance" |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "sender_balance" |), + M.get_name (| globals, "value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "generic_call" |), make_list [ @@ -726,6 +950,36 @@ Definition callcode : Value.t -> Value.t -> M := make_dict [] |), "balance" |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "sender_balance" |), + M.get_name (| globals, "value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "generic_call" |), make_list [ @@ -800,6 +1054,22 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in EndWhile. let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "originator" |), + M.get_name (| globals, "refunded_accounts" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.get_name (| globals, "REFUND_SELF_DESTRUCT" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/homestead/vm/interpreter.v b/CoqOfPython/ethereum/homestead/vm/interpreter.v index 9a84535..2f09635 100644 --- a/CoqOfPython/ethereum/homestead/vm/interpreter.v +++ b/CoqOfPython/ethereum/homestead/vm/interpreter.v @@ -55,71 +55,71 @@ Axiom ethereum_trace_TransactionEnd : Axiom ethereum_trace_evm_trace : IsGlobalAlias globals ethereum.trace.globals "evm_trace". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". - -Require state. -Axiom state_account_has_code_or_nonce : - IsGlobalAlias globals state.globals "account_has_code_or_nonce". -Axiom state_begin_transaction : - IsGlobalAlias globals state.globals "begin_transaction". -Axiom state_commit_transaction : - IsGlobalAlias globals state.globals "commit_transaction". -Axiom state_destroy_storage : - IsGlobalAlias globals state.globals "destroy_storage". -Axiom state_move_ether : - IsGlobalAlias globals state.globals "move_ether". -Axiom state_rollback_transaction : - IsGlobalAlias globals state.globals "rollback_transaction". -Axiom state_set_code : - IsGlobalAlias globals state.globals "set_code". -Axiom state_touch_account : - IsGlobalAlias globals state.globals "touch_account". - -Require vm. -Axiom vm_Message : - IsGlobalAlias globals vm.globals "Message". - -Require vm.gas. -Axiom vm_gas_GAS_CODE_DEPOSIT : - IsGlobalAlias globals vm.gas.globals "GAS_CODE_DEPOSIT". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". - -Require vm.precompiled_contracts.mapping. -Axiom vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : - IsGlobalAlias globals vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". - -Require __init__. -Axiom __init___Environment : - IsGlobalAlias globals __init__.globals "Environment". -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require exceptions. -Axiom exceptions_AddressCollision : - IsGlobalAlias globals exceptions.globals "AddressCollision". -Axiom exceptions_ExceptionalHalt : - IsGlobalAlias globals exceptions.globals "ExceptionalHalt". -Axiom exceptions_InvalidOpcode : - IsGlobalAlias globals exceptions.globals "InvalidOpcode". -Axiom exceptions_StackDepthLimitError : - IsGlobalAlias globals exceptions.globals "StackDepthLimitError". - -Require instructions. -Axiom instructions_Ops : - IsGlobalAlias globals instructions.globals "Ops". -Axiom instructions_op_implementation : - IsGlobalAlias globals instructions.globals "op_implementation". - -Require runtime. -Axiom runtime_get_valid_jump_destinations : - IsGlobalAlias globals runtime.globals "get_valid_jump_destinations". +Require ethereum.homestead.blocks. +Axiom ethereum_homestead_blocks_Log : + IsGlobalAlias globals ethereum.homestead.blocks.globals "Log". + +Require ethereum.homestead.fork_types. +Axiom ethereum_homestead_fork_types_Address : + IsGlobalAlias globals ethereum.homestead.fork_types.globals "Address". + +Require ethereum.homestead.state. +Axiom ethereum_homestead_state_account_has_code_or_nonce : + IsGlobalAlias globals ethereum.homestead.state.globals "account_has_code_or_nonce". +Axiom ethereum_homestead_state_begin_transaction : + IsGlobalAlias globals ethereum.homestead.state.globals "begin_transaction". +Axiom ethereum_homestead_state_commit_transaction : + IsGlobalAlias globals ethereum.homestead.state.globals "commit_transaction". +Axiom ethereum_homestead_state_destroy_storage : + IsGlobalAlias globals ethereum.homestead.state.globals "destroy_storage". +Axiom ethereum_homestead_state_move_ether : + IsGlobalAlias globals ethereum.homestead.state.globals "move_ether". +Axiom ethereum_homestead_state_rollback_transaction : + IsGlobalAlias globals ethereum.homestead.state.globals "rollback_transaction". +Axiom ethereum_homestead_state_set_code : + IsGlobalAlias globals ethereum.homestead.state.globals "set_code". +Axiom ethereum_homestead_state_touch_account : + IsGlobalAlias globals ethereum.homestead.state.globals "touch_account". + +Require ethereum.homestead.vm.__init__. +Axiom ethereum_homestead_vm___init___Message : + IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "Message". + +Require ethereum.homestead.vm.gas. +Axiom ethereum_homestead_vm_gas_GAS_CODE_DEPOSIT : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_CODE_DEPOSIT". +Axiom ethereum_homestead_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "charge_gas". + +Require ethereum.homestead.vm.precompiled_contracts.mapping. +Axiom ethereum_homestead_vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : + IsGlobalAlias globals ethereum.homestead.vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". + +Require ethereum.homestead.vm.__init__. +Axiom ethereum_homestead_vm___init___Environment : + IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "Environment". +Axiom ethereum_homestead_vm___init___Evm : + IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "Evm". + +Require ethereum.homestead.vm.exceptions. +Axiom ethereum_homestead_vm_exceptions_AddressCollision : + IsGlobalAlias globals ethereum.homestead.vm.exceptions.globals "AddressCollision". +Axiom ethereum_homestead_vm_exceptions_ExceptionalHalt : + IsGlobalAlias globals ethereum.homestead.vm.exceptions.globals "ExceptionalHalt". +Axiom ethereum_homestead_vm_exceptions_InvalidOpcode : + IsGlobalAlias globals ethereum.homestead.vm.exceptions.globals "InvalidOpcode". +Axiom ethereum_homestead_vm_exceptions_StackDepthLimitError : + IsGlobalAlias globals ethereum.homestead.vm.exceptions.globals "StackDepthLimitError". + +Require ethereum.homestead.vm.instructions.__init__. +Axiom ethereum_homestead_vm_instructions___init___Ops : + IsGlobalAlias globals ethereum.homestead.vm.instructions.__init__.globals "Ops". +Axiom ethereum_homestead_vm_instructions___init___op_implementation : + IsGlobalAlias globals ethereum.homestead.vm.instructions.__init__.globals "op_implementation". + +Require ethereum.homestead.vm.runtime. +Axiom ethereum_homestead_vm_runtime_get_valid_jump_destinations : + IsGlobalAlias globals ethereum.homestead.vm.runtime.globals "get_valid_jump_destinations". Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -162,6 +162,89 @@ Definition process_message_call : Value.t -> Value.t -> M := Output of the message call " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "message" |), "target" |), + M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) + |), + (* then *) + ltac:(M.monadic ( + let is_collision := + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_name (| globals, "is_collision" |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallOutput" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "tuple" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "AddressCollision" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let evm := + M.call (| + M.get_name (| globals, "process_create_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let evm := M.call (| M.get_name (| globals, "process_message" |), @@ -174,6 +257,29 @@ Definition process_message_call : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( +(* At stmt: unsupported node type: AnnAssign *) + let accounts_to_delete := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let refund_counter := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let logs := M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in let accounts_to_delete := @@ -209,6 +315,7 @@ Definition process_message_call : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). Definition process_create_message : Value.t -> Value.t -> M := @@ -254,6 +361,28 @@ Definition process_create_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), + (* then *) + ltac:(M.monadic ( + let contract_code := + M.get_field (| M.get_name (| globals, "evm" |), "output" |) in + let contract_code_gas := + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "contract_code" |) + ], + make_dict [] + |), + M.get_name (| globals, "GAS_CODE_DEPOSIT" |) + |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "rollback_transaction" |), make_list [ @@ -265,6 +394,7 @@ Definition process_create_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) + |) in M.pure Constant.None_)). Definition process_message : Value.t -> Value.t -> M := @@ -286,6 +416,24 @@ Definition process_message : Value.t -> Value.t -> M := Items containing execution specific objects " in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_field (| M.get_name (| globals, "message" |), "depth" |), + M.get_name (| globals, "STACK_DEPTH_LIMIT" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "StackDepthLimitError" |), + make_list [ + Constant.str "Stack depth limit reached" + ], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -304,6 +452,32 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + M.get_field (| M.get_name (| globals, "message" |), "should_transfer_value" |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "message" |), "value" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "move_ether" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "caller" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |); + M.get_field (| M.get_name (| globals, "message" |), "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let evm := @@ -316,6 +490,21 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "rollback_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "commit_transaction" |), make_list [ @@ -327,6 +516,7 @@ Definition process_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) + |) in M.pure Constant.None_)). Definition execute_code : Value.t -> Value.t -> M := @@ -366,4 +556,5 @@ Definition execute_code : Value.t -> Value.t -> M := (* At stmt: unsupported node type: Try *) let _ := M.return_ (| M.get_name (| globals, "evm" |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/vm/memory.v b/CoqOfPython/ethereum/homestead/vm/memory.v index 4b107fd..08d2290 100644 --- a/CoqOfPython/ethereum/homestead/vm/memory.v +++ b/CoqOfPython/ethereum/homestead/vm/memory.v @@ -21,13 +21,13 @@ Require ethereum.utils.byte. Axiom ethereum_utils_byte_right_pad_zero_bytes : IsGlobalAlias globals ethereum.utils.byte.globals "right_pad_zero_bytes". -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". Definition memory_write : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,7 +45,22 @@ Definition memory_write : Value.t -> Value.t -> M := Data to write to memory. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |), + M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) |) |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_)). @@ -71,7 +86,23 @@ Definition memory_read_bytes : Value.t -> Value.t -> M := Data read from memory. " in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |) + M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |) |) + |) in M.pure Constant.None_)). Definition buffer_read : Value.t -> Value.t -> M := @@ -98,9 +129,25 @@ Definition buffer_read : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "right_pad_zero_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |) |); + M.get_subscript (| M.get_name (| globals, "buffer" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |) |); M.get_name (| globals, "size" |) ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/__init__.v index 422f670..8a37e98 100644 --- a/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/__init__.v +++ b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/__init__.v @@ -18,9 +18,9 @@ Addresses of precompiled contracts and mappings to their implementations. ". -Require utils.hexadecimal. -Axiom utils_hexadecimal_hex_to_address : - IsGlobalAlias globals utils.hexadecimal.globals "hex_to_address". +Require ethereum.homestead.utils.hexadecimal. +Axiom ethereum_homestead_utils_hexadecimal_hex_to_address : + IsGlobalAlias globals ethereum.homestead.utils.hexadecimal.globals "hex_to_address". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS" ] diff --git a/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/ecrecover.v index 0cbcf16..d269a09 100644 --- a/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/ecrecover.v @@ -37,19 +37,19 @@ Require ethereum.utils.byte. Axiom ethereum_utils_byte_left_pad_zero_bytes : IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.homestead.vm.__init__. +Axiom ethereum_homestead_vm___init___Evm : + IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_ECRECOVER : - IsGlobalAlias globals vm.gas.globals "GAS_ECRECOVER". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.homestead.vm.gas. +Axiom ethereum_homestead_vm_gas_GAS_ECRECOVER : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_ECRECOVER". +Axiom ethereum_homestead_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "charge_gas". -Require vm.memory. -Axiom vm_memory_buffer_read : - IsGlobalAlias globals vm.memory.globals "buffer_read". +Require ethereum.homestead.vm.memory. +Axiom ethereum_homestead_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.homestead.vm.memory.globals "buffer_read". Definition ecrecover : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -188,12 +188,78 @@ Definition ecrecover : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "v" |), + Constant.int 27 + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "v" |), + Constant.int 28 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + Constant.int 0, + M.get_name (| globals, "r" |) + |), + ltac:(M.monadic ( + Compare.gt_e (| + M.get_name (| globals, "r" |), + M.get_name (| globals, "SECP256K1N" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + Constant.int 0, + M.get_name (| globals, "s" |) + |), + ltac:(M.monadic ( + Compare.gt_e (| + M.get_name (| globals, "s" |), + M.get_name (| globals, "SECP256K1N" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: Try *) @@ -204,7 +270,7 @@ Definition ecrecover : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12 |) in + |), M.slice (| Constant.int 12, Constant.int 32 |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/identity.v index fa96704..74c03df 100644 --- a/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/identity.v +++ b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/identity.v @@ -25,17 +25,17 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.homestead.vm.__init__. +Axiom ethereum_homestead_vm___init___Evm : + IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_IDENTITY : - IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY". -Axiom vm_gas_GAS_IDENTITY_WORD : - IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY_WORD". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.homestead.vm.gas. +Axiom ethereum_homestead_vm_gas_GAS_IDENTITY : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_IDENTITY". +Axiom ethereum_homestead_vm_gas_GAS_IDENTITY_WORD : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_IDENTITY_WORD". +Axiom ethereum_homestead_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "charge_gas". Definition identity : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/mapping.v index 710457d..f519b0e 100644 --- a/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/mapping.v +++ b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/mapping.v @@ -23,34 +23,34 @@ Axiom typing_Callable : Axiom typing_Dict : IsGlobalAlias globals typing.globals "Dict". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". - -Require __init__. -Axiom __init___ECRECOVER_ADDRESS : - IsGlobalAlias globals __init__.globals "ECRECOVER_ADDRESS". -Axiom __init___IDENTITY_ADDRESS : - IsGlobalAlias globals __init__.globals "IDENTITY_ADDRESS". -Axiom __init___RIPEMD160_ADDRESS : - IsGlobalAlias globals __init__.globals "RIPEMD160_ADDRESS". -Axiom __init___SHA256_ADDRESS : - IsGlobalAlias globals __init__.globals "SHA256_ADDRESS". - -Require ecrecover. -Axiom ecrecover_ecrecover : - IsGlobalAlias globals ecrecover.globals "ecrecover". - -Require identity. -Axiom identity_identity : - IsGlobalAlias globals identity.globals "identity". - -Require ripemd160. -Axiom ripemd160_ripemd160 : - IsGlobalAlias globals ripemd160.globals "ripemd160". - -Require sha256. -Axiom sha256_sha256 : - IsGlobalAlias globals sha256.globals "sha256". +Require ethereum.homestead.fork_types. +Axiom ethereum_homestead_fork_types_Address : + IsGlobalAlias globals ethereum.homestead.fork_types.globals "Address". + +Require ethereum.homestead.vm.precompiled_contracts.__init__. +Axiom ethereum_homestead_vm_precompiled_contracts___init___ECRECOVER_ADDRESS : + IsGlobalAlias globals ethereum.homestead.vm.precompiled_contracts.__init__.globals "ECRECOVER_ADDRESS". +Axiom ethereum_homestead_vm_precompiled_contracts___init___IDENTITY_ADDRESS : + IsGlobalAlias globals ethereum.homestead.vm.precompiled_contracts.__init__.globals "IDENTITY_ADDRESS". +Axiom ethereum_homestead_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : + IsGlobalAlias globals ethereum.homestead.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". +Axiom ethereum_homestead_vm_precompiled_contracts___init___SHA256_ADDRESS : + IsGlobalAlias globals ethereum.homestead.vm.precompiled_contracts.__init__.globals "SHA256_ADDRESS". + +Require ethereum.homestead.vm.precompiled_contracts.ecrecover. +Axiom ethereum_homestead_vm_precompiled_contracts_ecrecover_ecrecover : + IsGlobalAlias globals ethereum.homestead.vm.precompiled_contracts.ecrecover.globals "ecrecover". + +Require ethereum.homestead.vm.precompiled_contracts.identity. +Axiom ethereum_homestead_vm_precompiled_contracts_identity_identity : + IsGlobalAlias globals ethereum.homestead.vm.precompiled_contracts.identity.globals "identity". + +Require ethereum.homestead.vm.precompiled_contracts.ripemd160. +Axiom ethereum_homestead_vm_precompiled_contracts_ripemd160_ripemd160 : + IsGlobalAlias globals ethereum.homestead.vm.precompiled_contracts.ripemd160.globals "ripemd160". + +Require ethereum.homestead.vm.precompiled_contracts.sha256. +Axiom ethereum_homestead_vm_precompiled_contracts_sha256_sha256 : + IsGlobalAlias globals ethereum.homestead.vm.precompiled_contracts.sha256.globals "sha256". (* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/ripemd160.v index 96f8dcd..471df33 100644 --- a/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/ripemd160.v +++ b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/ripemd160.v @@ -31,17 +31,17 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.homestead.vm.__init__. +Axiom ethereum_homestead_vm___init___Evm : + IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_RIPEMD160 : - IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160". -Axiom vm_gas_GAS_RIPEMD160_WORD : - IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160_WORD". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.homestead.vm.gas. +Axiom ethereum_homestead_vm_gas_GAS_RIPEMD160 : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_RIPEMD160". +Axiom ethereum_homestead_vm_gas_GAS_RIPEMD160_WORD : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_RIPEMD160_WORD". +Axiom ethereum_homestead_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "charge_gas". Definition ripemd160 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/sha256.v index 9f6d2bf..af87e60 100644 --- a/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/sha256.v +++ b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/sha256.v @@ -27,17 +27,17 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.homestead.vm.__init__. +Axiom ethereum_homestead_vm___init___Evm : + IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_SHA256 : - IsGlobalAlias globals vm.gas.globals "GAS_SHA256". -Axiom vm_gas_GAS_SHA256_WORD : - IsGlobalAlias globals vm.gas.globals "GAS_SHA256_WORD". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.homestead.vm.gas. +Axiom ethereum_homestead_vm_gas_GAS_SHA256 : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_SHA256". +Axiom ethereum_homestead_vm_gas_GAS_SHA256_WORD : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_SHA256_WORD". +Axiom ethereum_homestead_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.homestead.vm.gas.globals "charge_gas". Definition sha256 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/homestead/vm/runtime.v b/CoqOfPython/ethereum/homestead/vm/runtime.v index 2cd7652..b4e2487 100644 --- a/CoqOfPython/ethereum/homestead/vm/runtime.v +++ b/CoqOfPython/ethereum/homestead/vm/runtime.v @@ -25,9 +25,9 @@ Require ethereum.base_types. Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require instructions. -Axiom instructions_Ops : - IsGlobalAlias globals instructions.globals "Ops". +Require ethereum.homestead.vm.instructions.__init__. +Axiom ethereum_homestead_vm_instructions___init___Ops : + IsGlobalAlias globals ethereum.homestead.vm.instructions.__init__.globals "Ops". Definition get_valid_jump_destinations : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -79,7 +79,55 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := |) do (* At stmt: unsupported node type: Try *) let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "current_opcode" |), + M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), + make_list [ + M.get_name (| globals, "pc" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.lt_e (| + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |), + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH32" |), "value" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let push_data_size := + BinOp.add (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) + |), + Constant.int 1 + |) in + let pc := BinOp.add + M.get_name (| globals, "push_data_size" |) + M.get_name (| globals, "push_data_size" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -90,4 +138,5 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := EndWhile. let _ := M.return_ (| M.get_name (| globals, "valid_jump_destinations" |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/homestead/vm/stack.v b/CoqOfPython/ethereum/homestead/vm/stack.v index ea778df..6acecf3 100644 --- a/CoqOfPython/ethereum/homestead/vm/stack.v +++ b/CoqOfPython/ethereum/homestead/vm/stack.v @@ -25,11 +25,11 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require exceptions. -Axiom exceptions_StackOverflowError : - IsGlobalAlias globals exceptions.globals "StackOverflowError". -Axiom exceptions_StackUnderflowError : - IsGlobalAlias globals exceptions.globals "StackUnderflowError". +Require ethereum.homestead.vm.exceptions. +Axiom ethereum_homestead_vm_exceptions_StackOverflowError : + IsGlobalAlias globals ethereum.homestead.vm.exceptions.globals "StackOverflowError". +Axiom ethereum_homestead_vm_exceptions_StackUnderflowError : + IsGlobalAlias globals ethereum.homestead.vm.exceptions.globals "StackUnderflowError". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -49,6 +49,24 @@ Definition pop : Value.t -> Value.t -> M := " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "StackUnderflowError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -57,6 +75,7 @@ Definition pop : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). Definition push : Value.t -> Value.t -> M := @@ -75,6 +94,24 @@ Definition push : Value.t -> Value.t -> M := " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), + Constant.int 1024 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "StackOverflowError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -85,4 +122,5 @@ Definition push : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/blocks.v b/CoqOfPython/ethereum/istanbul/blocks.v index 6501788..0375d8d 100644 --- a/CoqOfPython/ethereum/istanbul/blocks.v +++ b/CoqOfPython/ethereum/istanbul/blocks.v @@ -22,35 +22,35 @@ Require typing. Axiom typing_Tuple : IsGlobalAlias globals typing.globals "Tuple". -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes8 : - IsGlobalAlias globals base_types.globals "Bytes8". -Axiom base_types_Bytes32 : - IsGlobalAlias globals base_types.globals "Bytes32". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require crypto.hash. -Axiom crypto_hash_Hash32 : - IsGlobalAlias globals crypto.hash.globals "Hash32". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". - -Require transactions. -Axiom transactions_Transaction : - IsGlobalAlias globals transactions.globals "Transaction". +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes8 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes8". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". + +Require ethereum.istanbul.fork_types. +Axiom ethereum_istanbul_fork_types_Address : + IsGlobalAlias globals ethereum.istanbul.fork_types.globals "Address". +Axiom ethereum_istanbul_fork_types_Bloom : + IsGlobalAlias globals ethereum.istanbul.fork_types.globals "Bloom". +Axiom ethereum_istanbul_fork_types_Root : + IsGlobalAlias globals ethereum.istanbul.fork_types.globals "Root". + +Require ethereum.istanbul.transactions. +Axiom ethereum_istanbul_transactions_Transaction : + IsGlobalAlias globals ethereum.istanbul.transactions.globals "Transaction". Definition Header : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/istanbul/bloom.v b/CoqOfPython/ethereum/istanbul/bloom.v index 04650ff..e9ff47e 100644 --- a/CoqOfPython/ethereum/istanbul/bloom.v +++ b/CoqOfPython/ethereum/istanbul/bloom.v @@ -33,13 +33,13 @@ Require ethereum.crypto.hash. Axiom ethereum_crypto_hash_keccak256 : IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". +Require ethereum.istanbul.blocks. +Axiom ethereum_istanbul_blocks_Log : + IsGlobalAlias globals ethereum.istanbul.blocks.globals "Log". -Require fork_types. -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". +Require ethereum.istanbul.fork_types. +Axiom ethereum_istanbul_fork_types_Bloom : + IsGlobalAlias globals ethereum.istanbul.fork_types.globals "Bloom". Definition add_to_bloom : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -72,7 +72,10 @@ Definition add_to_bloom : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |) |) + M.get_subscript (| M.get_name (| globals, "hash" |), M.slice (| M.get_name (| globals, "idx" |), BinOp.add (| + M.get_name (| globals, "idx" |), + Constant.int 2 + |) |) |) ], make_dict [] |), @@ -157,4 +160,5 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/fork.v b/CoqOfPython/ethereum/istanbul/fork.v index bd55602..8c0dbe2 100644 --- a/CoqOfPython/ethereum/istanbul/fork.v +++ b/CoqOfPython/ethereum/istanbul/fork.v @@ -63,93 +63,93 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U64 : - IsGlobalAlias globals base_types.globals "U64". -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_U256_CEIL_VALUE : - IsGlobalAlias globals base_types.globals "U256_CEIL_VALUE". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". - -Require __init__. -Axiom __init___vm : - IsGlobalAlias globals __init__.globals "vm". - -Require blocks. -Axiom blocks_Block : - IsGlobalAlias globals blocks.globals "Block". -Axiom blocks_Header : - IsGlobalAlias globals blocks.globals "Header". -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". -Axiom blocks_Receipt : - IsGlobalAlias globals blocks.globals "Receipt". - -Require bloom. -Axiom bloom_logs_bloom : - IsGlobalAlias globals bloom.globals "logs_bloom". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". - -Require state. -Axiom state_State : - IsGlobalAlias globals state.globals "State". -Axiom state_account_exists_and_is_empty : - IsGlobalAlias globals state.globals "account_exists_and_is_empty". -Axiom state_create_ether : - IsGlobalAlias globals state.globals "create_ether". -Axiom state_destroy_account : - IsGlobalAlias globals state.globals "destroy_account". -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". -Axiom state_increment_nonce : - IsGlobalAlias globals state.globals "increment_nonce". -Axiom state_set_account_balance : - IsGlobalAlias globals state.globals "set_account_balance". -Axiom state_state_root : - IsGlobalAlias globals state.globals "state_root". - -Require transactions. -Axiom transactions_TX_BASE_COST : - IsGlobalAlias globals transactions.globals "TX_BASE_COST". -Axiom transactions_TX_CREATE_COST : - IsGlobalAlias globals transactions.globals "TX_CREATE_COST". -Axiom transactions_TX_DATA_COST_PER_NON_ZERO : - IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_NON_ZERO". -Axiom transactions_TX_DATA_COST_PER_ZERO : - IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_ZERO". -Axiom transactions_Transaction : - IsGlobalAlias globals transactions.globals "Transaction". - -Require trie. -Axiom trie_Trie : - IsGlobalAlias globals trie.globals "Trie". -Axiom trie_root : - IsGlobalAlias globals trie.globals "root". -Axiom trie_trie_set : - IsGlobalAlias globals trie.globals "trie_set". - -Require utils.message. -Axiom utils_message_prepare_message : - IsGlobalAlias globals utils.message.globals "prepare_message". - -Require vm.interpreter. -Axiom vm_interpreter_process_message_call : - IsGlobalAlias globals vm.interpreter.globals "process_message_call". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U64 : + IsGlobalAlias globals ethereum.base_types.globals "U64". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_U256_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.istanbul.__init__. +Axiom ethereum_istanbul___init___vm : + IsGlobalAlias globals ethereum.istanbul.__init__.globals "vm". + +Require ethereum.istanbul.blocks. +Axiom ethereum_istanbul_blocks_Block : + IsGlobalAlias globals ethereum.istanbul.blocks.globals "Block". +Axiom ethereum_istanbul_blocks_Header : + IsGlobalAlias globals ethereum.istanbul.blocks.globals "Header". +Axiom ethereum_istanbul_blocks_Log : + IsGlobalAlias globals ethereum.istanbul.blocks.globals "Log". +Axiom ethereum_istanbul_blocks_Receipt : + IsGlobalAlias globals ethereum.istanbul.blocks.globals "Receipt". + +Require ethereum.istanbul.bloom. +Axiom ethereum_istanbul_bloom_logs_bloom : + IsGlobalAlias globals ethereum.istanbul.bloom.globals "logs_bloom". + +Require ethereum.istanbul.fork_types. +Axiom ethereum_istanbul_fork_types_Address : + IsGlobalAlias globals ethereum.istanbul.fork_types.globals "Address". +Axiom ethereum_istanbul_fork_types_Bloom : + IsGlobalAlias globals ethereum.istanbul.fork_types.globals "Bloom". +Axiom ethereum_istanbul_fork_types_Root : + IsGlobalAlias globals ethereum.istanbul.fork_types.globals "Root". + +Require ethereum.istanbul.state. +Axiom ethereum_istanbul_state_State : + IsGlobalAlias globals ethereum.istanbul.state.globals "State". +Axiom ethereum_istanbul_state_account_exists_and_is_empty : + IsGlobalAlias globals ethereum.istanbul.state.globals "account_exists_and_is_empty". +Axiom ethereum_istanbul_state_create_ether : + IsGlobalAlias globals ethereum.istanbul.state.globals "create_ether". +Axiom ethereum_istanbul_state_destroy_account : + IsGlobalAlias globals ethereum.istanbul.state.globals "destroy_account". +Axiom ethereum_istanbul_state_get_account : + IsGlobalAlias globals ethereum.istanbul.state.globals "get_account". +Axiom ethereum_istanbul_state_increment_nonce : + IsGlobalAlias globals ethereum.istanbul.state.globals "increment_nonce". +Axiom ethereum_istanbul_state_set_account_balance : + IsGlobalAlias globals ethereum.istanbul.state.globals "set_account_balance". +Axiom ethereum_istanbul_state_state_root : + IsGlobalAlias globals ethereum.istanbul.state.globals "state_root". + +Require ethereum.istanbul.transactions. +Axiom ethereum_istanbul_transactions_TX_BASE_COST : + IsGlobalAlias globals ethereum.istanbul.transactions.globals "TX_BASE_COST". +Axiom ethereum_istanbul_transactions_TX_CREATE_COST : + IsGlobalAlias globals ethereum.istanbul.transactions.globals "TX_CREATE_COST". +Axiom ethereum_istanbul_transactions_TX_DATA_COST_PER_NON_ZERO : + IsGlobalAlias globals ethereum.istanbul.transactions.globals "TX_DATA_COST_PER_NON_ZERO". +Axiom ethereum_istanbul_transactions_TX_DATA_COST_PER_ZERO : + IsGlobalAlias globals ethereum.istanbul.transactions.globals "TX_DATA_COST_PER_ZERO". +Axiom ethereum_istanbul_transactions_Transaction : + IsGlobalAlias globals ethereum.istanbul.transactions.globals "Transaction". + +Require ethereum.istanbul.trie. +Axiom ethereum_istanbul_trie_Trie : + IsGlobalAlias globals ethereum.istanbul.trie.globals "Trie". +Axiom ethereum_istanbul_trie_root : + IsGlobalAlias globals ethereum.istanbul.trie.globals "root". +Axiom ethereum_istanbul_trie_trie_set : + IsGlobalAlias globals ethereum.istanbul.trie.globals "trie_set". + +Require ethereum.istanbul.utils.message. +Axiom ethereum_istanbul_utils_message_prepare_message : + IsGlobalAlias globals ethereum.istanbul.utils.message.globals "prepare_message". + +Require ethereum.istanbul.vm.interpreter. +Axiom ethereum_istanbul_vm_interpreter_process_message_call : + IsGlobalAlias globals ethereum.istanbul.vm.interpreter.globals "process_message_call". Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -242,6 +242,7 @@ Definition apply_fork : Value.t -> Value.t -> M := " in let _ := M.return_ (| M.get_name (| globals, "old" |) + |) in M.pure Constant.None_)). Definition get_last_256_block_hashes : Value.t -> Value.t -> M := @@ -267,8 +268,28 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := Hashes of the recent 256 blocks in order of increasing block number. " in let recent_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |) |) in + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "recent_blocks" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + make_list [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let recent_block_hashes := @@ -307,6 +328,7 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "recent_block_hashes" |) + |) in M.pure Constant.None_)). Definition state_transition : Value.t -> Value.t -> M := @@ -438,6 +460,27 @@ Definition state_transition : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |) + ], + make_dict [] + |), + Constant.int 255 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -630,6 +673,7 @@ Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition validate_proof_of_work : Value.t -> Value.t -> M := @@ -764,6 +808,7 @@ Definition check_transaction : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "sender_address" |) + |) in M.pure Constant.None_)). Definition make_receipt : Value.t -> Value.t -> M := @@ -797,6 +842,7 @@ Definition make_receipt : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "receipt" |) + |) in M.pure Constant.None_)). Definition ApplyBodyOutput : Value.t := @@ -1007,6 +1053,7 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition validate_ommers : Value.t -> Value.t -> M := @@ -1059,6 +1106,26 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do @@ -1116,7 +1183,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let ommers_hashes := - (* At expr: unsupported node type: ListComp *) in + Constant.str "(* At expr: unsupported node type: ListComp *)" in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1147,19 +1214,19 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let recent_canonical_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| BinOp.add (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| BinOp.add (| M.get_name (| globals, "MAX_OMMER_DEPTH" |), Constant.int 1 - |) |) |) in + |) |), Constant.None_ |) |) in let recent_canonical_block_hashes := - (* At expr: unsupported node type: SetComp *) in + Constant.str "(* At expr: unsupported node type: SetComp *)" in (* At stmt: unsupported node type: AnnAssign *) For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_canonical_blocks" |) do let recent_ommers_hashes := M.call (| M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), make_list [ - (* At expr: unsupported node type: SetComp *) + Constant.str "(* At expr: unsupported node type: SetComp *)" ], make_dict [] |) in @@ -1573,7 +1640,50 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "transaction_fee" |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| + M.get_name (| globals, "coinbase_balance_after_mining_fee" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |); + M.get_name (| globals, "coinbase_balance_after_mining_fee" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -1590,11 +1700,35 @@ Definition process_transaction : Value.t -> Value.t -> M := EndFor. For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "touched_accounts" |) do let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := M.return_ (| make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |); M.get_field (| M.get_name (| globals, "output" |), "error" |) ] + |) in M.pure Constant.None_)). Definition validate_transaction : Value.t -> Value.t -> M := @@ -1649,6 +1783,7 @@ Definition validate_transaction : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := @@ -1680,6 +1815,20 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := Constant.int 0 in For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "byte" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let data_cost := BinOp.add M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in @@ -1687,6 +1836,25 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := )) |) in EndFor. let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "tx" |), "to" |), + M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) + |), + (* then *) + ltac:(M.monadic ( + let create_cost := + M.get_name (| globals, "TX_CREATE_COST" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let create_cost := Constant.int 0 in M.pure Constant.None_ @@ -1705,6 +1873,7 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition recover_sender : Value.t -> Value.t -> M := @@ -1777,6 +1946,45 @@ Definition recover_sender : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.eq (| + M.get_name (| globals, "v" |), + Constant.int 27 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "v" |), + Constant.int 28 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + BinOp.sub (| + M.get_name (| globals, "v" |), + Constant.int 27 + |); + M.call (| + M.get_name (| globals, "signing_hash_pre155" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1847,10 +2055,11 @@ Definition recover_sender : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12 |) + |), M.slice (| Constant.int 12, Constant.int 32 |) |) ], make_dict [] |) + |) in M.pure Constant.None_)). Definition signing_hash_pre155 : Value.t -> Value.t -> M := @@ -1883,6 +2092,7 @@ Definition signing_hash_pre155 : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition signing_hash_155 : Value.t -> Value.t -> M := @@ -1929,6 +2139,7 @@ Definition signing_hash_155 : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition compute_header_hash : Value.t -> Value.t -> M := @@ -1979,6 +2190,7 @@ Definition compute_header_hash : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition check_gas_limit : Value.t -> Value.t -> M := @@ -2017,16 +2229,65 @@ Definition check_gas_limit : Value.t -> Value.t -> M := M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "gas_limit" |), + BinOp.add (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "gas_limit" |), + BinOp.sub (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "gas_limit" |), + M.get_name (| globals, "GAS_LIMIT_MINIMUM" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| Constant.bool true + |) in M.pure Constant.None_)). Definition calculate_block_difficulty : Value.t -> Value.t -> M := @@ -2086,12 +2347,16 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := M.get_name (| globals, "max" |), make_list [ BinOp.sub (| - (* if *) -M.if_then_else (| - M.get_name (| globals, "parent_has_ommers" |), -(* then *) -ltac:(M.monadic ( -Constant.int 2, + (* if *) + M.if_then_else (| + M.get_name (| globals, "parent_has_ommers" |), + (* then *) + ltac:(M.monadic ( +Constant.int 2 + (* else *) + )), ltac:(M.monadic ( +Constant.int 1 + )) |), BinOp.floor_div (| M.call (| M.get_name (| globals, "int" |), @@ -2140,6 +2405,26 @@ Constant.int 2, Constant.int 2 |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "num_bomb_periods" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let difficulty := BinOp.add + BinOp.pow (| + Constant.int 2, + M.get_name (| globals, "num_bomb_periods" |) + |) + BinOp.pow (| + Constant.int 2, + M.get_name (| globals, "num_bomb_periods" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -2157,4 +2442,5 @@ Constant.int 2, ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/fork_types.v b/CoqOfPython/ethereum/istanbul/fork_types.v index 5c7dac3..cc8e4a1 100644 --- a/CoqOfPython/ethereum/istanbul/fork_types.v +++ b/CoqOfPython/ethereum/istanbul/fork_types.v @@ -21,29 +21,29 @@ Require dataclasses. Axiom dataclasses_dataclass : IsGlobalAlias globals dataclasses.globals "dataclass". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes20 : - IsGlobalAlias globals base_types.globals "Bytes20". -Axiom base_types_Bytes256 : - IsGlobalAlias globals base_types.globals "Bytes256". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require crypto.hash. -Axiom crypto_hash_Hash32 : - IsGlobalAlias globals crypto.hash.globals "Hash32". -Axiom crypto_hash_keccak256 : - IsGlobalAlias globals crypto.hash.globals "keccak256". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes20 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes20". +Axiom ethereum_base_types_Bytes256 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) @@ -98,4 +98,5 @@ Definition encode_account : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/state.v b/CoqOfPython/ethereum/istanbul/state.v index c3290a6..a592b4e 100644 --- a/CoqOfPython/ethereum/istanbul/state.v +++ b/CoqOfPython/ethereum/istanbul/state.v @@ -56,29 +56,29 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require fork_types. -Axiom fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". -Axiom fork_types_Account : - IsGlobalAlias globals fork_types.globals "Account". -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". - -Require trie. -Axiom trie_EMPTY_TRIE_ROOT : - IsGlobalAlias globals trie.globals "EMPTY_TRIE_ROOT". -Axiom trie_Trie : - IsGlobalAlias globals trie.globals "Trie". -Axiom trie_copy_trie : - IsGlobalAlias globals trie.globals "copy_trie". -Axiom trie_root : - IsGlobalAlias globals trie.globals "root". -Axiom trie_trie_get : - IsGlobalAlias globals trie.globals "trie_get". -Axiom trie_trie_set : - IsGlobalAlias globals trie.globals "trie_set". +Require ethereum.istanbul.fork_types. +Axiom ethereum_istanbul_fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals ethereum.istanbul.fork_types.globals "EMPTY_ACCOUNT". +Axiom ethereum_istanbul_fork_types_Account : + IsGlobalAlias globals ethereum.istanbul.fork_types.globals "Account". +Axiom ethereum_istanbul_fork_types_Address : + IsGlobalAlias globals ethereum.istanbul.fork_types.globals "Address". +Axiom ethereum_istanbul_fork_types_Root : + IsGlobalAlias globals ethereum.istanbul.fork_types.globals "Root". + +Require ethereum.istanbul.trie. +Axiom ethereum_istanbul_trie_EMPTY_TRIE_ROOT : + IsGlobalAlias globals ethereum.istanbul.trie.globals "EMPTY_TRIE_ROOT". +Axiom ethereum_istanbul_trie_Trie : + IsGlobalAlias globals ethereum.istanbul.trie.globals "Trie". +Axiom ethereum_istanbul_trie_copy_trie : + IsGlobalAlias globals ethereum.istanbul.trie.globals "copy_trie". +Axiom ethereum_istanbul_trie_root : + IsGlobalAlias globals ethereum.istanbul.trie.globals "root". +Axiom ethereum_istanbul_trie_trie_get : + IsGlobalAlias globals ethereum.istanbul.trie.globals "trie_get". +Axiom ethereum_istanbul_trie_trie_set : + IsGlobalAlias globals ethereum.istanbul.trie.globals "trie_set". Definition State : Value.t := builtins.make_klass @@ -126,7 +126,7 @@ Definition begin_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) ], make_dict [] - |); (* At expr: unsupported node type: DictComp *) ] + |); Constant.str "(* At expr: unsupported node type: DictComp *)" ] ], make_dict [] |) in @@ -149,6 +149,19 @@ Definition commit_transaction : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "clear" |), + make_list [], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -174,6 +187,19 @@ Definition rollback_transaction : Value.t -> Value.t -> M := |) |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "clear" |), + make_list [], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -210,8 +236,27 @@ Definition get_account : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "account" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "account" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_ACCOUNT" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -246,6 +291,7 @@ Definition get_account_optional : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "account" |) + |) in M.pure Constant.None_)). Definition set_account : Value.t -> Value.t -> M := @@ -325,6 +371,18 @@ Definition destroy_storage : Value.t -> Value.t -> M := Address of account whose storage is to be deleted. " in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -387,6 +445,26 @@ Definition get_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "trie" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let value := @@ -408,6 +486,7 @@ Definition get_storage : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "value" |) + |) in M.pure Constant.None_)). Definition set_storage : Value.t -> Value.t -> M := @@ -448,6 +527,27 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "trie" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let trie := + M.call (| + M.get_name (| globals, "Trie" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), + M.get_name (| globals, "trie" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -460,6 +560,18 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + {} + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -484,8 +596,29 @@ Definition storage_root : Value.t -> Value.t -> M := " in let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_TRIE_ROOT" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -516,6 +649,7 @@ Definition state_root : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition account_exists : Value.t -> Value.t -> M := @@ -548,6 +682,7 @@ Definition account_exists : Value.t -> Value.t -> M := |), Constant.None_ |) + |) in M.pure Constant.None_)). Definition account_has_code_or_nonce : Value.t -> Value.t -> M := @@ -597,6 +732,7 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition is_account_empty : Value.t -> Value.t -> M := @@ -654,6 +790,7 @@ Definition is_account_empty : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition account_exists_and_is_empty : Value.t -> Value.t -> M := @@ -720,6 +857,7 @@ Definition account_exists_and_is_empty : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition is_account_alive : Value.t -> Value.t -> M := @@ -750,6 +888,20 @@ Definition is_account_alive : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "account" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| UnOp.not (| BoolOp.and (| Compare.eq (| @@ -777,6 +929,7 @@ Definition is_account_alive : Value.t -> Value.t -> M := |) )) |) |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -884,6 +1037,30 @@ Definition touch_account : Value.t -> Value.t -> M := The address of the account that need to initialised. " in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "account_exists" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "EMPTY_ACCOUNT" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -988,6 +1165,26 @@ Definition get_storage_original : Value.t -> Value.t -> M := Key of the storage slot. " in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -1003,6 +1200,25 @@ Definition get_storage_original : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "original_account_trie" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let original_value := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let original_value := M.call (| M.get_name (| globals, "trie_get" |), @@ -1024,4 +1240,5 @@ Definition get_storage_original : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "original_value" |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/transactions.v b/CoqOfPython/ethereum/istanbul/transactions.v index f94a3bd..e6d51bd 100644 --- a/CoqOfPython/ethereum/istanbul/transactions.v +++ b/CoqOfPython/ethereum/istanbul/transactions.v @@ -17,21 +17,21 @@ Require typing. Axiom typing_Union : IsGlobalAlias globals typing.globals "Union". -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes0 : - IsGlobalAlias globals base_types.globals "Bytes0". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.istanbul.fork_types. +Axiom ethereum_istanbul_fork_types_Address : + IsGlobalAlias globals ethereum.istanbul.fork_types.globals "Address". Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( Constant.int 21000 diff --git a/CoqOfPython/ethereum/istanbul/trie.v b/CoqOfPython/ethereum/istanbul/trie.v index 0ae1030..83f3e40 100644 --- a/CoqOfPython/ethereum/istanbul/trie.v +++ b/CoqOfPython/ethereum/istanbul/trie.v @@ -50,9 +50,9 @@ Axiom typing_Union : Axiom typing_cast : IsGlobalAlias globals typing.globals "cast". -Require ethereum.constantinople. -Axiom ethereum_constantinople_trie : - IsGlobalAlias globals ethereum.constantinople.globals "trie". +Require ethereum.constantinople.__init__. +Axiom ethereum_constantinople___init___trie : + IsGlobalAlias globals ethereum.constantinople.__init__.globals "trie". Require ethereum.crypto.hash. Axiom ethereum_crypto_hash_keccak256 : @@ -66,37 +66,37 @@ Require ethereum.utils.hexadecimal. Axiom ethereum_utils_hexadecimal_hex_to_bytes : IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require blocks. -Axiom blocks_Receipt : - IsGlobalAlias globals blocks.globals "Receipt". - -Require fork_types. -Axiom fork_types_Account : - IsGlobalAlias globals fork_types.globals "Account". -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". -Axiom fork_types_encode_account : - IsGlobalAlias globals fork_types.globals "encode_account". - -Require transactions. -Axiom transactions_Transaction : - IsGlobalAlias globals transactions.globals "Transaction". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.istanbul.blocks. +Axiom ethereum_istanbul_blocks_Receipt : + IsGlobalAlias globals ethereum.istanbul.blocks.globals "Receipt". + +Require ethereum.istanbul.fork_types. +Axiom ethereum_istanbul_fork_types_Account : + IsGlobalAlias globals ethereum.istanbul.fork_types.globals "Account". +Axiom ethereum_istanbul_fork_types_Address : + IsGlobalAlias globals ethereum.istanbul.fork_types.globals "Address". +Axiom ethereum_istanbul_fork_types_Root : + IsGlobalAlias globals ethereum.istanbul.fork_types.globals "Root". +Axiom ethereum_istanbul_fork_types_encode_account : + IsGlobalAlias globals ethereum.istanbul.fork_types.globals "encode_account". + +Require ethereum.istanbul.transactions. +Axiom ethereum_istanbul_transactions_Transaction : + IsGlobalAlias globals ethereum.istanbul.transactions.globals "Transaction". Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -202,16 +202,99 @@ Definition encode_internal_node : Value.t -> Value.t -> M := " in (* At stmt: unsupported node type: AnnAssign *) let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "node" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + Constant.bytes "" in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "LeafNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "rest_of_key" |); + Constant.bool true + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "ExtensionNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "key_segment" |); + Constant.bool false + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "BranchNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + BinOp.add (| + M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "value" |) + ] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ - (* At expr: unsupported node type: JoinedStr *) + Constant.str "(* At expr: unsupported node type: JoinedStr *)" ], make_dict [] - |)) + |)) |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -229,6 +312,26 @@ Definition encode_internal_node : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded" |) + ], + make_dict [] + |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "unencoded" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_name (| globals, "keccak256" |), @@ -237,6 +340,7 @@ Definition encode_internal_node : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -250,8 +354,86 @@ Definition encode_node : Value.t -> Value.t -> M := Currently mostly an unimplemented stub. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| + M.get_name (| globals, "storage_root" |), + Constant.None_ + |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "encode_account" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "storage_root" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + make_tuple [ M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "U256" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "cast" |), + make_list [ + M.get_field (| M.get_name (| globals, "rlp" |), "RLP" |); + M.get_name (| globals, "node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "node" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "previous_trie" |), "encode_node" |), @@ -261,6 +443,7 @@ Definition encode_node : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -312,6 +495,7 @@ Definition copy_trie : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition trie_set : Value.t -> Value.t -> M := @@ -333,6 +517,32 @@ Definition trie_set : Value.t -> Value.t -> M := Node to insert at `key`. " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + M.get_field (| M.get_name (| globals, "trie" |), "default" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "key" |), + M.get_field (| M.get_name (| globals, "trie" |), "_data" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), M.get_name (| globals, "value" |) @@ -370,6 +580,7 @@ Definition trie_get : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition common_prefix_length : Value.t -> Value.t -> M := @@ -392,6 +603,34 @@ Definition common_prefix_length : Value.t -> Value.t -> M := make_dict [] |) do let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), + M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -403,6 +642,7 @@ Definition common_prefix_length : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition nibble_list_to_compact : Value.t -> Value.t -> M := @@ -448,6 +688,71 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + Constant.int 2 + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.mult (| + Constant.int 16, + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "is_leaf" |) + |) + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ @@ -509,6 +814,7 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition bytes_to_nibble_list : Value.t -> Value.t -> M := @@ -586,6 +892,7 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition _prepare_trie : Value.t -> Value.t -> M := @@ -615,6 +922,48 @@ Definition _prepare_trie : Value.t -> Value.t -> M := make_dict [] |) do let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| + M.get_name (| globals, "get_storage_root" |), + Constant.None_ + |) |) in + let address := + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |); + M.call (| + M.get_name (| globals, "get_storage_root" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let encoded_value := M.call (| M.get_name (| globals, "encode_node" |), @@ -638,6 +987,22 @@ Definition _prepare_trie : Value.t -> Value.t -> M := |) in (* At stmt: unsupported node type: AnnAssign *) let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "trie" |), "secured" |), + (* then *) + ltac:(M.monadic ( + let key := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let key := M.get_name (| globals, "preimage" |) in M.pure Constant.None_ @@ -655,6 +1020,7 @@ Definition _prepare_trie : Value.t -> Value.t -> M := EndFor. let _ := M.return_ (| M.get_name (| globals, "mapped" |) + |) in M.pure Constant.None_)). Definition root : Value.t -> Value.t -> M := @@ -708,6 +1074,44 @@ Definition root : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -724,6 +1128,7 @@ Definition root : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -750,6 +1155,26 @@ Definition patricialize : Value.t -> Value.t -> M := Root node of `obj`. " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let arbitrary_key := @@ -767,10 +1192,39 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), + Constant.int 1 + |), + (* then *) + ltac:(M.monadic ( + let leaf := + M.call (| + M.get_name (| globals, "LeafNode" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |); + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "leaf" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let substring := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |) |) in + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) in let prefix_length := M.call (| M.get_name (| globals, "len" |), @@ -789,7 +1243,7 @@ Definition patricialize : Value.t -> Value.t -> M := M.get_name (| globals, "common_prefix_length" |), make_list [ M.get_name (| globals, "substring" |); - M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) + M.get_subscript (| M.get_name (| globals, "key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) ], make_dict [] |) @@ -797,10 +1251,64 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "prefix_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "prefix_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let prefix := + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ExtensionNode" |), + make_list [ + M.get_name (| globals, "prefix" |); + M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_name (| globals, "obj" |); + BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) @@ -823,6 +1331,44 @@ Definition patricialize : Value.t -> Value.t -> M := Constant.bytes "" in For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |), + M.get_name (| globals, "level" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "AssertionError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) @@ -834,9 +1380,10 @@ Definition patricialize : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "BranchNode" |), make_list [ - (* At expr: unsupported node type: ListComp *); + Constant.str "(* At expr: unsupported node type: ListComp *)"; M.get_name (| globals, "value" |) ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/utils/address.v b/CoqOfPython/ethereum/istanbul/utils/address.v index 79125fa..2de5bfb 100644 --- a/CoqOfPython/ethereum/istanbul/utils/address.v +++ b/CoqOfPython/ethereum/istanbul/utils/address.v @@ -38,13 +38,13 @@ Require ethereum.utils.byte. Axiom ethereum_utils_byte_left_pad_zero_bytes : IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.istanbul.fork_types. +Axiom ethereum_istanbul_fork_types_Address : + IsGlobalAlias globals ethereum.istanbul.fork_types.globals "Address". Definition to_address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -70,10 +70,11 @@ Definition to_address : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), make_list [], make_dict [] - |), UnOp.sub (| Constant.int 20 |) |) + |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) ], make_dict [] |) + |) in M.pure Constant.None_)). Definition compute_contract_address : Value.t -> Value.t -> M := @@ -113,7 +114,7 @@ Definition compute_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -131,6 +132,7 @@ Definition compute_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition compute_create2_contract_address : Value.t -> Value.t -> M := @@ -180,7 +182,7 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -198,4 +200,5 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/utils/hexadecimal.v b/CoqOfPython/ethereum/istanbul/utils/hexadecimal.v index 7db2240..7acfddf 100644 --- a/CoqOfPython/ethereum/istanbul/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/istanbul/utils/hexadecimal.v @@ -22,13 +22,13 @@ Require ethereum.utils.hexadecimal. Axiom ethereum_utils_hexadecimal_remove_hex_prefix : IsGlobalAlias globals ethereum.utils.hexadecimal.globals "remove_hex_prefix". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". +Require ethereum.istanbul.fork_types. +Axiom ethereum_istanbul_fork_types_Address : + IsGlobalAlias globals ethereum.istanbul.fork_types.globals "Address". +Axiom ethereum_istanbul_fork_types_Bloom : + IsGlobalAlias globals ethereum.istanbul.fork_types.globals "Bloom". +Axiom ethereum_istanbul_fork_types_Root : + IsGlobalAlias globals ethereum.istanbul.fork_types.globals "Root". Definition hex_to_root : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -66,6 +66,7 @@ Definition hex_to_root : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition hex_to_bloom : Value.t -> Value.t -> M := @@ -104,6 +105,7 @@ Definition hex_to_bloom : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition hex_to_address : Value.t -> Value.t -> M := @@ -149,4 +151,5 @@ Definition hex_to_address : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/utils/message.v b/CoqOfPython/ethereum/istanbul/utils/message.v index a66b0f2..da02502 100644 --- a/CoqOfPython/ethereum/istanbul/utils/message.v +++ b/CoqOfPython/ethereum/istanbul/utils/message.v @@ -34,23 +34,23 @@ Axiom ethereum_base_types_Bytes0 : Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.istanbul.fork_types. +Axiom ethereum_istanbul_fork_types_Address : + IsGlobalAlias globals ethereum.istanbul.fork_types.globals "Address". -Require state. -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". +Require ethereum.istanbul.state. +Axiom ethereum_istanbul_state_get_account : + IsGlobalAlias globals ethereum.istanbul.state.globals "get_account". -Require vm. -Axiom vm_Environment : - IsGlobalAlias globals vm.globals "Environment". -Axiom vm_Message : - IsGlobalAlias globals vm.globals "Message". +Require ethereum.istanbul.vm.__init__. +Axiom ethereum_istanbul_vm___init___Environment : + IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Environment". +Axiom ethereum_istanbul_vm___init___Message : + IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Message". -Require address. -Axiom address_compute_contract_address : - IsGlobalAlias globals address.globals "compute_contract_address". +Require ethereum.istanbul.utils.address. +Axiom ethereum_istanbul_utils_address_compute_contract_address : + IsGlobalAlias globals ethereum.istanbul.utils.address.globals "compute_contract_address". Definition prepare_message : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -88,14 +88,108 @@ Definition prepare_message : Value.t -> Value.t -> M := Items containing contract creation or message call specific data. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Bytes0" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.call (| + M.get_name (| globals, "compute_contract_address" |), + make_list [ + M.get_name (| globals, "caller" |); + BinOp.sub (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "caller" |) + ], + make_dict [] + |), "nonce" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let msg_data := + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) in + let code := + M.get_name (| globals, "data" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.get_name (| globals, "target" |) in + let msg_data := + M.get_name (| globals, "data" |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "target" |) + ], + make_dict [] + |), "code" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "code_address" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let code_address := + M.get_name (| globals, "target" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "Target must be address or empty bytes" ], make_dict [] - |)) + |)) |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -106,4 +200,5 @@ Definition prepare_message : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/vm/__init__.v b/CoqOfPython/ethereum/istanbul/vm/__init__.v index 25f0a97..0614167 100644 --- a/CoqOfPython/ethereum/istanbul/vm/__init__.v +++ b/CoqOfPython/ethereum/istanbul/vm/__init__.v @@ -50,23 +50,23 @@ Require ethereum.crypto.hash. Axiom ethereum_crypto_hash_Hash32 : IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". +Require ethereum.istanbul.blocks. +Axiom ethereum_istanbul_blocks_Log : + IsGlobalAlias globals ethereum.istanbul.blocks.globals "Log". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.istanbul.fork_types. +Axiom ethereum_istanbul_fork_types_Address : + IsGlobalAlias globals ethereum.istanbul.fork_types.globals "Address". -Require state. -Axiom state_State : - IsGlobalAlias globals state.globals "State". -Axiom state_account_exists_and_is_empty : - IsGlobalAlias globals state.globals "account_exists_and_is_empty". +Require ethereum.istanbul.state. +Axiom ethereum_istanbul_state_State : + IsGlobalAlias globals ethereum.istanbul.state.globals "State". +Axiom ethereum_istanbul_state_account_exists_and_is_empty : + IsGlobalAlias globals ethereum.istanbul.state.globals "account_exists_and_is_empty". -Require precompiled_contracts. -Axiom precompiled_contracts_RIPEMD160_ADDRESS : - IsGlobalAlias globals precompiled_contracts.globals "RIPEMD160_ADDRESS". +Require ethereum.istanbul.vm.precompiled_contracts.__init__. +Axiom ethereum_istanbul_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : + IsGlobalAlias globals ethereum.istanbul.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] @@ -145,6 +145,28 @@ Definition incorporate_child_on_success : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -163,9 +185,63 @@ Definition incorporate_child_on_error : Value.t -> Value.t -> M := The child evm to incorporate. " in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "RIPEMD160_ADDRESS" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |), + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign_op (| diff --git a/CoqOfPython/ethereum/istanbul/vm/gas.v b/CoqOfPython/ethereum/istanbul/vm/gas.v index 765c5ef..216b412 100644 --- a/CoqOfPython/ethereum/istanbul/vm/gas.v +++ b/CoqOfPython/ethereum/istanbul/vm/gas.v @@ -43,13 +43,13 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.istanbul.vm.__init__. +Axiom ethereum_istanbul_vm___init___Evm : + IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Evm". -Require exceptions. -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". +Require ethereum.istanbul.vm.exceptions. +Axiom ethereum_istanbul_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.istanbul.vm.exceptions.globals "OutOfGasError". Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -530,6 +530,18 @@ Definition charge_gas : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "amount" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign_op (| BinOp.sub, M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), @@ -645,6 +657,18 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := |) in For make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ] in M.get_name (| globals, "extensions" |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "size" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let before_size := @@ -679,6 +703,18 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let size_to_extend := BinOp.add @@ -727,6 +763,7 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition calculate_message_call_gas : Value.t -> Value.t -> M := @@ -758,22 +795,56 @@ Definition calculate_message_call_gas : Value.t -> Value.t -> M := message_call_gas: `MessageCallGas` " in let call_stipend := - (* if *) -M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "call_stipend" |) + )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "gas_left" |), + BinOp.add (| + M.get_name (| globals, "extra_gas" |), + M.get_name (| globals, "memory_cost" |) + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallGas" |), + make_list [ + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "extra_gas" |) + |); + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "call_stipend" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let gas := @@ -812,6 +883,7 @@ M.call (| ], make_dict [] |) + |) in M.pure Constant.None_)). Definition max_message_call_gas : Value.t -> Value.t -> M := @@ -838,4 +910,5 @@ Definition max_message_call_gas : Value.t -> Value.t -> M := Constant.int 64 |) |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/__init__.v b/CoqOfPython/ethereum/istanbul/vm/instructions/__init__.v index e5bebd7..4aa92f7 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/__init__.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/__init__.v @@ -26,53 +26,53 @@ Axiom typing_Callable : Axiom typing_Dict : IsGlobalAlias globals typing.globals "Dict". -Require __init__. -Axiom __init___arithmetic : - IsGlobalAlias globals __init__.globals "arithmetic". +Require ethereum.istanbul.vm.instructions.__init__. +Axiom ethereum_istanbul_vm_instructions___init___arithmetic : + IsGlobalAlias globals ethereum.istanbul.vm.instructions.__init__.globals "arithmetic". -Require __init__. -Axiom __init___bitwise : - IsGlobalAlias globals __init__.globals "bitwise". +Require ethereum.istanbul.vm.instructions.__init__. +Axiom ethereum_istanbul_vm_instructions___init___bitwise : + IsGlobalAlias globals ethereum.istanbul.vm.instructions.__init__.globals "bitwise". -Require __init__. -Axiom __init___block : - IsGlobalAlias globals __init__.globals "block". +Require ethereum.istanbul.vm.instructions.__init__. +Axiom ethereum_istanbul_vm_instructions___init___block : + IsGlobalAlias globals ethereum.istanbul.vm.instructions.__init__.globals "block". -Require __init__. -Axiom __init___comparison : - IsGlobalAlias globals __init__.globals "comparison". +Require ethereum.istanbul.vm.instructions.__init__. +Axiom ethereum_istanbul_vm_instructions___init___comparison : + IsGlobalAlias globals ethereum.istanbul.vm.instructions.__init__.globals "comparison". -Require __init__. -Axiom __init___control_flow : - IsGlobalAlias globals __init__.globals "control_flow". +Require ethereum.istanbul.vm.instructions.__init__. +Axiom ethereum_istanbul_vm_instructions___init___control_flow : + IsGlobalAlias globals ethereum.istanbul.vm.instructions.__init__.globals "control_flow". -Require __init__. -Axiom __init___environment : - IsGlobalAlias globals __init__.globals "environment". +Require ethereum.istanbul.vm.instructions.__init__. +Axiom ethereum_istanbul_vm_instructions___init___environment : + IsGlobalAlias globals ethereum.istanbul.vm.instructions.__init__.globals "environment". -Require __init__. -Axiom __init___keccak : - IsGlobalAlias globals __init__.globals "keccak". +Require ethereum.istanbul.vm.instructions.__init__. +Axiom ethereum_istanbul_vm_instructions___init___keccak : + IsGlobalAlias globals ethereum.istanbul.vm.instructions.__init__.globals "keccak". -Require __init__. -Axiom __init___log : - IsGlobalAlias globals __init__.globals "log". +Require ethereum.istanbul.vm.instructions.__init__. +Axiom ethereum_istanbul_vm_instructions___init___log : + IsGlobalAlias globals ethereum.istanbul.vm.instructions.__init__.globals "log". -Require __init__. -Axiom __init___memory : - IsGlobalAlias globals __init__.globals "memory". +Require ethereum.istanbul.vm.instructions.__init__. +Axiom ethereum_istanbul_vm_instructions___init___memory : + IsGlobalAlias globals ethereum.istanbul.vm.instructions.__init__.globals "memory". -Require __init__. -Axiom __init___stack : - IsGlobalAlias globals __init__.globals "stack". +Require ethereum.istanbul.vm.instructions.__init__. +Axiom ethereum_istanbul_vm_instructions___init___stack : + IsGlobalAlias globals ethereum.istanbul.vm.instructions.__init__.globals "stack". -Require __init__. -Axiom __init___storage : - IsGlobalAlias globals __init__.globals "storage". +Require ethereum.istanbul.vm.instructions.__init__. +Axiom ethereum_istanbul_vm_instructions___init___storage : + IsGlobalAlias globals ethereum.istanbul.vm.instructions.__init__.globals "storage". -Require __init__. -Axiom __init___system : - IsGlobalAlias globals __init__.globals "system". +Require ethereum.istanbul.vm.instructions.__init__. +Axiom ethereum_istanbul_vm_instructions___init___system : + IsGlobalAlias globals ethereum.istanbul.vm.instructions.__init__.globals "system". Definition Ops : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/istanbul/vm/instructions/arithmetic.v index 581ba5d..a7893ea 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/arithmetic.v @@ -31,29 +31,29 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_get_sign : IsGlobalAlias globals ethereum.utils.numeric.globals "get_sign". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_EXPONENTIATION : - IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION". -Axiom gas_GAS_EXPONENTIATION_PER_BYTE : - IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION_PER_BYTE". -Axiom gas_GAS_LOW : - IsGlobalAlias globals gas.globals "GAS_LOW". -Axiom gas_GAS_MID : - IsGlobalAlias globals gas.globals "GAS_MID". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.istanbul.vm.__init__. +Axiom ethereum_istanbul_vm___init___Evm : + IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Evm". + +Require ethereum.istanbul.vm.gas. +Axiom ethereum_istanbul_vm_gas_GAS_EXPONENTIATION : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_EXPONENTIATION". +Axiom ethereum_istanbul_vm_gas_GAS_EXPONENTIATION_PER_BYTE : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_EXPONENTIATION_PER_BYTE". +Axiom ethereum_istanbul_vm_gas_GAS_LOW : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_LOW". +Axiom ethereum_istanbul_vm_gas_GAS_MID : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_MID". +Axiom ethereum_istanbul_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_istanbul_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "charge_gas". + +Require ethereum.istanbul.vm.stack. +Axiom ethereum_istanbul_vm_stack_pop : + IsGlobalAlias globals ethereum.istanbul.vm.stack.globals "pop". +Axiom ethereum_istanbul_vm_stack_push : + IsGlobalAlias globals ethereum.istanbul.vm.stack.globals "push". Definition add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -273,6 +273,25 @@ Definition div : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "divisor" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let quotient := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let quotient := BinOp.floor_div (| M.get_name (| globals, "dividend" |), @@ -341,7 +360,41 @@ Definition sdiv : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "divisor" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let quotient := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_name (| globals, "dividend" |), + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "divisor" |), + UnOp.sub (| Constant.int 1 |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let quotient := + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let sign := M.call (| M.get_name (| globals, "get_sign" |), @@ -436,6 +489,25 @@ Definition mod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "y" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let remainder := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let remainder := BinOp.mod_ (| M.get_name (| globals, "x" |), @@ -504,6 +576,19 @@ Definition smod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "y" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let remainder := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let remainder := BinOp.mult (| M.call (| @@ -617,6 +702,25 @@ Definition addmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "z" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -712,6 +816,25 @@ Definition mulmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "z" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -881,6 +1004,19 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "byte_num" |), + Constant.int 31 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.get_name (| globals, "value" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let value_bytes := M.call (| M.get_name (| globals, "bytes" |), @@ -894,7 +1030,7 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let value_bytes := - M.get_subscript (| M.get_name (| globals, "value_bytes" |), BinOp.sub (| + M.get_subscript (| M.get_name (| globals, "value_bytes" |), M.slice (| BinOp.sub (| Constant.int 31, M.call (| M.get_name (| globals, "int" |), @@ -903,13 +1039,32 @@ Definition signextend : Value.t -> Value.t -> M := ], make_dict [] |) - |) |) in + |), Constant.None_ |) |) in let sign_bit := BinOp.r_shift (| M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), Constant.int 7 |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "sign_bit" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "value_bytes" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let num_bytes_prepend := BinOp.sub (| Constant.int 32, diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/bitwise.v b/CoqOfPython/ethereum/istanbul/vm/instructions/bitwise.v index 64cf120..4a55db3 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/bitwise.v @@ -23,21 +23,21 @@ Axiom ethereum_base_types_U256 : Axiom ethereum_base_types_U256_CEIL_VALUE : IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.istanbul.vm.__init__. +Axiom ethereum_istanbul_vm___init___Evm : + IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.istanbul.vm.gas. +Axiom ethereum_istanbul_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_istanbul_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "charge_gas". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.istanbul.vm.stack. +Axiom ethereum_istanbul_vm_stack_pop : + IsGlobalAlias globals ethereum.istanbul.vm.stack.globals "pop". +Axiom ethereum_istanbul_vm_stack_push : + IsGlobalAlias globals ethereum.istanbul.vm.stack.globals "push". Definition bitwise_and : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -287,6 +287,25 @@ Definition get_byte : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "byte_index" |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let extra_bytes_to_right := BinOp.sub (| Constant.int 31, @@ -366,6 +385,31 @@ Definition bitwise_shl : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "shift" |), + Constant.int 256 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.l_shift (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "shift" |) + |), + M.get_name (| globals, "U256_CEIL_VALUE" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -427,6 +471,22 @@ Definition bitwise_shr : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "shift" |), + Constant.int 256 + |), + (* then *) + ltac:(M.monadic ( + let result := + BinOp.r_shift (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "shift" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -492,7 +552,48 @@ Definition bitwise_sar : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "shift" |), + Constant.int 256 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + BinOp.r_shift (| + M.get_name (| globals, "signed_value" |), + M.get_name (| globals, "shift" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "signed_value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/block.v b/CoqOfPython/ethereum/istanbul/vm/instructions/block.v index f857b79..8411c2b 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/block.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/block.v @@ -21,23 +21,23 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_BLOCK_HASH : - IsGlobalAlias globals gas.globals "GAS_BLOCK_HASH". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.istanbul.vm.__init__. +Axiom ethereum_istanbul_vm___init___Evm : + IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Evm". + +Require ethereum.istanbul.vm.gas. +Axiom ethereum_istanbul_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_BASE". +Axiom ethereum_istanbul_vm_gas_GAS_BLOCK_HASH : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_BLOCK_HASH". +Axiom ethereum_istanbul_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "charge_gas". + +Require ethereum.istanbul.vm.stack. +Axiom ethereum_istanbul_vm_stack_pop : + IsGlobalAlias globals ethereum.istanbul.vm.stack.globals "pop". +Axiom ethereum_istanbul_vm_stack_push : + IsGlobalAlias globals ethereum.istanbul.vm.stack.globals "push". Definition block_hash : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -69,6 +69,30 @@ Definition block_hash : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt_e (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + M.get_name (| globals, "block_number" |) + |), + ltac:(M.monadic ( + Compare.gt (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + BinOp.add (| + M.get_name (| globals, "block_number" |), + Constant.int 256 + |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let hash := + Constant.bytes "00" in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let hash := M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/comparison.v b/CoqOfPython/ethereum/istanbul/vm/instructions/comparison.v index b8529d8..fcf5c15 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/comparison.v @@ -21,21 +21,21 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.istanbul.vm.__init__. +Axiom ethereum_istanbul_vm___init___Evm : + IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.istanbul.vm.gas. +Axiom ethereum_istanbul_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_istanbul_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "charge_gas". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.istanbul.vm.stack. +Axiom ethereum_istanbul_vm_stack_pop : + IsGlobalAlias globals ethereum.istanbul.vm.stack.globals "pop". +Axiom ethereum_istanbul_vm_stack_push : + IsGlobalAlias globals ethereum.istanbul.vm.stack.globals "push". Definition less_than : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/control_flow.v b/CoqOfPython/ethereum/istanbul/vm/instructions/control_flow.v index d4e4eae..5b19ce0 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/control_flow.v @@ -23,31 +23,31 @@ Axiom ethereum_base_types_U256 : Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require vm.gas. -Axiom vm_gas_GAS_BASE : - IsGlobalAlias globals vm.gas.globals "GAS_BASE". -Axiom vm_gas_GAS_HIGH : - IsGlobalAlias globals vm.gas.globals "GAS_HIGH". -Axiom vm_gas_GAS_JUMPDEST : - IsGlobalAlias globals vm.gas.globals "GAS_JUMPDEST". -Axiom vm_gas_GAS_MID : - IsGlobalAlias globals vm.gas.globals "GAS_MID". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.istanbul.vm.gas. +Axiom ethereum_istanbul_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_BASE". +Axiom ethereum_istanbul_vm_gas_GAS_HIGH : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_HIGH". +Axiom ethereum_istanbul_vm_gas_GAS_JUMPDEST : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_JUMPDEST". +Axiom ethereum_istanbul_vm_gas_GAS_MID : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_MID". +Axiom ethereum_istanbul_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "charge_gas". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.istanbul.vm.__init__. +Axiom ethereum_istanbul_vm___init___Evm : + IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Evm". -Require exceptions. -Axiom exceptions_InvalidJumpDestError : - IsGlobalAlias globals exceptions.globals "InvalidJumpDestError". +Require ethereum.istanbul.vm.exceptions. +Axiom ethereum_istanbul_vm_exceptions_InvalidJumpDestError : + IsGlobalAlias globals ethereum.istanbul.vm.exceptions.globals "InvalidJumpDestError". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.istanbul.vm.stack. +Axiom ethereum_istanbul_vm_stack_pop : + IsGlobalAlias globals ethereum.istanbul.vm.stack.globals "pop". +Axiom ethereum_istanbul_vm_stack_push : + IsGlobalAlias globals ethereum.istanbul.vm.stack.globals "push". Definition stop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -109,6 +109,18 @@ Definition jump : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "jump_dest" |), + M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -168,7 +180,35 @@ Definition jumpi : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "conditional_value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let destination := + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "jump_dest" |), + M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let destination := M.get_name (| globals, "jump_dest" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/environment.v b/CoqOfPython/ethereum/istanbul/vm/instructions/environment.v index 02315c3..2ae1498 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/environment.v @@ -35,59 +35,59 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require fork_types. -Axiom fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". - -Require state. -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". - -Require utils.address. -Axiom utils_address_to_address : - IsGlobalAlias globals utils.address.globals "to_address". - -Require vm.memory. -Axiom vm_memory_buffer_read : - IsGlobalAlias globals vm.memory.globals "buffer_read". -Axiom vm_memory_memory_write : - IsGlobalAlias globals vm.memory.globals "memory_write". - -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require exceptions. -Axiom exceptions_OutOfBoundsRead : - IsGlobalAlias globals exceptions.globals "OutOfBoundsRead". - -Require gas. -Axiom gas_GAS_BALANCE : - IsGlobalAlias globals gas.globals "GAS_BALANCE". -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_CODE_HASH : - IsGlobalAlias globals gas.globals "GAS_CODE_HASH". -Axiom gas_GAS_COPY : - IsGlobalAlias globals gas.globals "GAS_COPY". -Axiom gas_GAS_EXTERNAL : - IsGlobalAlias globals gas.globals "GAS_EXTERNAL". -Axiom gas_GAS_FAST_STEP : - IsGlobalAlias globals gas.globals "GAS_FAST_STEP". -Axiom gas_GAS_RETURN_DATA_COPY : - IsGlobalAlias globals gas.globals "GAS_RETURN_DATA_COPY". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.istanbul.fork_types. +Axiom ethereum_istanbul_fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals ethereum.istanbul.fork_types.globals "EMPTY_ACCOUNT". + +Require ethereum.istanbul.state. +Axiom ethereum_istanbul_state_get_account : + IsGlobalAlias globals ethereum.istanbul.state.globals "get_account". + +Require ethereum.istanbul.utils.address. +Axiom ethereum_istanbul_utils_address_to_address : + IsGlobalAlias globals ethereum.istanbul.utils.address.globals "to_address". + +Require ethereum.istanbul.vm.memory. +Axiom ethereum_istanbul_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.istanbul.vm.memory.globals "buffer_read". +Axiom ethereum_istanbul_vm_memory_memory_write : + IsGlobalAlias globals ethereum.istanbul.vm.memory.globals "memory_write". + +Require ethereum.istanbul.vm.__init__. +Axiom ethereum_istanbul_vm___init___Evm : + IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Evm". + +Require ethereum.istanbul.vm.exceptions. +Axiom ethereum_istanbul_vm_exceptions_OutOfBoundsRead : + IsGlobalAlias globals ethereum.istanbul.vm.exceptions.globals "OutOfBoundsRead". + +Require ethereum.istanbul.vm.gas. +Axiom ethereum_istanbul_vm_gas_GAS_BALANCE : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_BALANCE". +Axiom ethereum_istanbul_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_BASE". +Axiom ethereum_istanbul_vm_gas_GAS_CODE_HASH : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_CODE_HASH". +Axiom ethereum_istanbul_vm_gas_GAS_COPY : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_COPY". +Axiom ethereum_istanbul_vm_gas_GAS_EXTERNAL : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_EXTERNAL". +Axiom ethereum_istanbul_vm_gas_GAS_FAST_STEP : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_FAST_STEP". +Axiom ethereum_istanbul_vm_gas_GAS_RETURN_DATA_COPY : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_RETURN_DATA_COPY". +Axiom ethereum_istanbul_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_istanbul_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_istanbul_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "charge_gas". + +Require ethereum.istanbul.vm.stack. +Axiom ethereum_istanbul_vm_stack_pop : + IsGlobalAlias globals ethereum.istanbul.vm.stack.globals "pop". +Axiom ethereum_istanbul_vm_stack_push : + IsGlobalAlias globals ethereum.istanbul.vm.stack.globals "push". Definition address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -1134,7 +1134,10 @@ Definition returndatacopy : Value.t -> Value.t -> M := |) |) in let value := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |) |) in + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.slice (| M.get_name (| globals, "return_data_start_position" |), BinOp.add (| + M.get_name (| globals, "return_data_start_position" |), + M.get_name (| globals, "size" |) + |) |) |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -1193,6 +1196,25 @@ Definition extcodehash : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "account" |), + M.get_name (| globals, "EMPTY_ACCOUNT" |) + |), + (* then *) + ltac:(M.monadic ( + let codehash := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let codehash := M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/keccak.v b/CoqOfPython/ethereum/istanbul/vm/instructions/keccak.v index 2c4b10e..4b2ee32 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/keccak.v @@ -31,29 +31,29 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_KECCAK256 : - IsGlobalAlias globals gas.globals "GAS_KECCAK256". -Axiom gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.istanbul.vm.__init__. +Axiom ethereum_istanbul_vm___init___Evm : + IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Evm". + +Require ethereum.istanbul.vm.gas. +Axiom ethereum_istanbul_vm_gas_GAS_KECCAK256 : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_KECCAK256". +Axiom ethereum_istanbul_vm_gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_KECCAK256_WORD". +Axiom ethereum_istanbul_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_istanbul_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "charge_gas". + +Require ethereum.istanbul.vm.memory. +Axiom ethereum_istanbul_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.istanbul.vm.memory.globals "memory_read_bytes". + +Require ethereum.istanbul.vm.stack. +Axiom ethereum_istanbul_vm_stack_pop : + IsGlobalAlias globals ethereum.istanbul.vm.stack.globals "pop". +Axiom ethereum_istanbul_vm_stack_push : + IsGlobalAlias globals ethereum.istanbul.vm.stack.globals "push". Definition keccak : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/log.v b/CoqOfPython/ethereum/istanbul/vm/instructions/log.v index e084e59..902c053 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/log.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/log.v @@ -29,37 +29,37 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". - -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require exceptions. -Axiom exceptions_WriteInStaticContext : - IsGlobalAlias globals exceptions.globals "WriteInStaticContext". - -Require gas. -Axiom gas_GAS_LOG : - IsGlobalAlias globals gas.globals "GAS_LOG". -Axiom gas_GAS_LOG_DATA : - IsGlobalAlias globals gas.globals "GAS_LOG_DATA". -Axiom gas_GAS_LOG_TOPIC : - IsGlobalAlias globals gas.globals "GAS_LOG_TOPIC". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". +Require ethereum.istanbul.blocks. +Axiom ethereum_istanbul_blocks_Log : + IsGlobalAlias globals ethereum.istanbul.blocks.globals "Log". + +Require ethereum.istanbul.vm.__init__. +Axiom ethereum_istanbul_vm___init___Evm : + IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Evm". + +Require ethereum.istanbul.vm.exceptions. +Axiom ethereum_istanbul_vm_exceptions_WriteInStaticContext : + IsGlobalAlias globals ethereum.istanbul.vm.exceptions.globals "WriteInStaticContext". + +Require ethereum.istanbul.vm.gas. +Axiom ethereum_istanbul_vm_gas_GAS_LOG : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_LOG". +Axiom ethereum_istanbul_vm_gas_GAS_LOG_DATA : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_LOG_DATA". +Axiom ethereum_istanbul_vm_gas_GAS_LOG_TOPIC : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_LOG_TOPIC". +Axiom ethereum_istanbul_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_istanbul_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "charge_gas". + +Require ethereum.istanbul.vm.memory. +Axiom ethereum_istanbul_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.istanbul.vm.memory.globals "memory_read_bytes". + +Require ethereum.istanbul.vm.stack. +Axiom ethereum_istanbul_vm_stack_pop : + IsGlobalAlias globals ethereum.istanbul.vm.stack.globals "pop". Definition log_n : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/memory.v b/CoqOfPython/ethereum/istanbul/vm/instructions/memory.v index 86ba742..dcb6ab0 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/memory.v @@ -23,31 +23,31 @@ Axiom ethereum_base_types_U256 : Axiom ethereum_base_types_Bytes : IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.istanbul.vm.__init__. +Axiom ethereum_istanbul_vm___init___Evm : + IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.istanbul.vm.gas. +Axiom ethereum_istanbul_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_BASE". +Axiom ethereum_istanbul_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_istanbul_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_istanbul_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "charge_gas". -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". -Axiom memory_memory_write : - IsGlobalAlias globals memory.globals "memory_write". +Require ethereum.istanbul.vm.memory. +Axiom ethereum_istanbul_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.istanbul.vm.memory.globals "memory_read_bytes". +Axiom ethereum_istanbul_vm_memory_memory_write : + IsGlobalAlias globals ethereum.istanbul.vm.memory.globals "memory_write". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.istanbul.vm.stack. +Axiom ethereum_istanbul_vm_stack_pop : + IsGlobalAlias globals ethereum.istanbul.vm.stack.globals "pop". +Axiom ethereum_istanbul_vm_stack_push : + IsGlobalAlias globals ethereum.istanbul.vm.stack.globals "push". Definition mstore : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/stack.v b/CoqOfPython/ethereum/istanbul/vm/instructions/stack.v index 305af15..14f5374 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/stack.v @@ -29,27 +29,27 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". -Axiom __init___stack : - IsGlobalAlias globals __init__.globals "stack". - -Require exceptions. -Axiom exceptions_StackUnderflowError : - IsGlobalAlias globals exceptions.globals "StackUnderflowError". - -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require memory. -Axiom memory_buffer_read : - IsGlobalAlias globals memory.globals "buffer_read". +Require ethereum.istanbul.vm.__init__. +Axiom ethereum_istanbul_vm___init___Evm : + IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Evm". +Axiom ethereum_istanbul_vm___init___stack : + IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "stack". + +Require ethereum.istanbul.vm.exceptions. +Axiom ethereum_istanbul_vm_exceptions_StackUnderflowError : + IsGlobalAlias globals ethereum.istanbul.vm.exceptions.globals "StackUnderflowError". + +Require ethereum.istanbul.vm.gas. +Axiom ethereum_istanbul_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_BASE". +Axiom ethereum_istanbul_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_istanbul_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "charge_gas". + +Require ethereum.istanbul.vm.memory. +Axiom ethereum_istanbul_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.istanbul.vm.memory.globals "buffer_read". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/storage.v b/CoqOfPython/ethereum/istanbul/vm/instructions/storage.v index e55bb00..a5cb2f2 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/storage.v @@ -21,43 +21,43 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require state. -Axiom state_get_storage : - IsGlobalAlias globals state.globals "get_storage". -Axiom state_get_storage_original : - IsGlobalAlias globals state.globals "get_storage_original". -Axiom state_set_storage : - IsGlobalAlias globals state.globals "set_storage". - -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require exceptions. -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". -Axiom exceptions_WriteInStaticContext : - IsGlobalAlias globals exceptions.globals "WriteInStaticContext". - -Require gas. -Axiom gas_GAS_CALL_STIPEND : - IsGlobalAlias globals gas.globals "GAS_CALL_STIPEND". -Axiom gas_GAS_SLOAD : - IsGlobalAlias globals gas.globals "GAS_SLOAD". -Axiom gas_GAS_STORAGE_CLEAR_REFUND : - IsGlobalAlias globals gas.globals "GAS_STORAGE_CLEAR_REFUND". -Axiom gas_GAS_STORAGE_SET : - IsGlobalAlias globals gas.globals "GAS_STORAGE_SET". -Axiom gas_GAS_STORAGE_UPDATE : - IsGlobalAlias globals gas.globals "GAS_STORAGE_UPDATE". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.istanbul.state. +Axiom ethereum_istanbul_state_get_storage : + IsGlobalAlias globals ethereum.istanbul.state.globals "get_storage". +Axiom ethereum_istanbul_state_get_storage_original : + IsGlobalAlias globals ethereum.istanbul.state.globals "get_storage_original". +Axiom ethereum_istanbul_state_set_storage : + IsGlobalAlias globals ethereum.istanbul.state.globals "set_storage". + +Require ethereum.istanbul.vm.__init__. +Axiom ethereum_istanbul_vm___init___Evm : + IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Evm". + +Require ethereum.istanbul.vm.exceptions. +Axiom ethereum_istanbul_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.istanbul.vm.exceptions.globals "OutOfGasError". +Axiom ethereum_istanbul_vm_exceptions_WriteInStaticContext : + IsGlobalAlias globals ethereum.istanbul.vm.exceptions.globals "WriteInStaticContext". + +Require ethereum.istanbul.vm.gas. +Axiom ethereum_istanbul_vm_gas_GAS_CALL_STIPEND : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_CALL_STIPEND". +Axiom ethereum_istanbul_vm_gas_GAS_SLOAD : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_SLOAD". +Axiom ethereum_istanbul_vm_gas_GAS_STORAGE_CLEAR_REFUND : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_STORAGE_CLEAR_REFUND". +Axiom ethereum_istanbul_vm_gas_GAS_STORAGE_SET : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_STORAGE_SET". +Axiom ethereum_istanbul_vm_gas_GAS_STORAGE_UPDATE : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_STORAGE_UPDATE". +Axiom ethereum_istanbul_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "charge_gas". + +Require ethereum.istanbul.vm.stack. +Axiom ethereum_istanbul_vm_stack_pop : + IsGlobalAlias globals ethereum.istanbul.vm.stack.globals "pop". +Axiom ethereum_istanbul_vm_stack_push : + IsGlobalAlias globals ethereum.istanbul.vm.stack.globals "push". Definition sload : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -181,11 +181,189 @@ Definition sstore : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_name (| globals, "original_value" |), + M.get_name (| globals, "current_value" |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "current_value" |), + M.get_name (| globals, "new_value" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "original_value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let gas_cost := + M.get_name (| globals, "GAS_STORAGE_SET" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let gas_cost := + M.get_name (| globals, "GAS_STORAGE_UPDATE" |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let gas_cost := M.get_name (| globals, "GAS_SLOAD" |) in M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| + M.get_name (| globals, "current_value" |), + M.get_name (| globals, "new_value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "original_value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "current_value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "new_value" |), + Constant.int 0 + |) + )) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "original_value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "current_value" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.sub, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "original_value" |), + M.get_name (| globals, "new_value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "original_value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_SET" |), + M.get_name (| globals, "GAS_SLOAD" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_UPDATE" |), + M.get_name (| globals, "GAS_SLOAD" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/system.v b/CoqOfPython/ethereum/istanbul/vm/instructions/system.v index b850f84..7ef15d4 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/system.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/system.v @@ -33,87 +33,87 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.istanbul.fork_types. +Axiom ethereum_istanbul_fork_types_Address : + IsGlobalAlias globals ethereum.istanbul.fork_types.globals "Address". -Require state. -Axiom state_account_exists_and_is_empty : - IsGlobalAlias globals state.globals "account_exists_and_is_empty". -Axiom state_account_has_code_or_nonce : - IsGlobalAlias globals state.globals "account_has_code_or_nonce". -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". -Axiom state_increment_nonce : - IsGlobalAlias globals state.globals "increment_nonce". -Axiom state_is_account_alive : - IsGlobalAlias globals state.globals "is_account_alive". -Axiom state_set_account_balance : - IsGlobalAlias globals state.globals "set_account_balance". +Require ethereum.istanbul.state. +Axiom ethereum_istanbul_state_account_exists_and_is_empty : + IsGlobalAlias globals ethereum.istanbul.state.globals "account_exists_and_is_empty". +Axiom ethereum_istanbul_state_account_has_code_or_nonce : + IsGlobalAlias globals ethereum.istanbul.state.globals "account_has_code_or_nonce". +Axiom ethereum_istanbul_state_get_account : + IsGlobalAlias globals ethereum.istanbul.state.globals "get_account". +Axiom ethereum_istanbul_state_increment_nonce : + IsGlobalAlias globals ethereum.istanbul.state.globals "increment_nonce". +Axiom ethereum_istanbul_state_is_account_alive : + IsGlobalAlias globals ethereum.istanbul.state.globals "is_account_alive". +Axiom ethereum_istanbul_state_set_account_balance : + IsGlobalAlias globals ethereum.istanbul.state.globals "set_account_balance". -Require utils.address. -Axiom utils_address_compute_contract_address : - IsGlobalAlias globals utils.address.globals "compute_contract_address". -Axiom utils_address_compute_create2_contract_address : - IsGlobalAlias globals utils.address.globals "compute_create2_contract_address". -Axiom utils_address_to_address : - IsGlobalAlias globals utils.address.globals "to_address". +Require ethereum.istanbul.utils.address. +Axiom ethereum_istanbul_utils_address_compute_contract_address : + IsGlobalAlias globals ethereum.istanbul.utils.address.globals "compute_contract_address". +Axiom ethereum_istanbul_utils_address_compute_create2_contract_address : + IsGlobalAlias globals ethereum.istanbul.utils.address.globals "compute_create2_contract_address". +Axiom ethereum_istanbul_utils_address_to_address : + IsGlobalAlias globals ethereum.istanbul.utils.address.globals "to_address". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". -Axiom __init___Message : - IsGlobalAlias globals __init__.globals "Message". -Axiom __init___incorporate_child_on_error : - IsGlobalAlias globals __init__.globals "incorporate_child_on_error". -Axiom __init___incorporate_child_on_success : - IsGlobalAlias globals __init__.globals "incorporate_child_on_success". +Require ethereum.istanbul.vm.__init__. +Axiom ethereum_istanbul_vm___init___Evm : + IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Evm". +Axiom ethereum_istanbul_vm___init___Message : + IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Message". +Axiom ethereum_istanbul_vm___init___incorporate_child_on_error : + IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "incorporate_child_on_error". +Axiom ethereum_istanbul_vm___init___incorporate_child_on_success : + IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "incorporate_child_on_success". -Require exceptions. -Axiom exceptions_Revert : - IsGlobalAlias globals exceptions.globals "Revert". -Axiom exceptions_WriteInStaticContext : - IsGlobalAlias globals exceptions.globals "WriteInStaticContext". +Require ethereum.istanbul.vm.exceptions. +Axiom ethereum_istanbul_vm_exceptions_Revert : + IsGlobalAlias globals ethereum.istanbul.vm.exceptions.globals "Revert". +Axiom ethereum_istanbul_vm_exceptions_WriteInStaticContext : + IsGlobalAlias globals ethereum.istanbul.vm.exceptions.globals "WriteInStaticContext". -Require gas. -Axiom gas_GAS_CALL : - IsGlobalAlias globals gas.globals "GAS_CALL". -Axiom gas_GAS_CALL_VALUE : - IsGlobalAlias globals gas.globals "GAS_CALL_VALUE". -Axiom gas_GAS_CREATE : - IsGlobalAlias globals gas.globals "GAS_CREATE". -Axiom gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". -Axiom gas_GAS_NEW_ACCOUNT : - IsGlobalAlias globals gas.globals "GAS_NEW_ACCOUNT". -Axiom gas_GAS_SELF_DESTRUCT : - IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT". -Axiom gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : - IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". -Axiom gas_GAS_ZERO : - IsGlobalAlias globals gas.globals "GAS_ZERO". -Axiom gas_REFUND_SELF_DESTRUCT : - IsGlobalAlias globals gas.globals "REFUND_SELF_DESTRUCT". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_calculate_message_call_gas : - IsGlobalAlias globals gas.globals "calculate_message_call_gas". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". -Axiom gas_max_message_call_gas : - IsGlobalAlias globals gas.globals "max_message_call_gas". +Require ethereum.istanbul.vm.gas. +Axiom ethereum_istanbul_vm_gas_GAS_CALL : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_CALL". +Axiom ethereum_istanbul_vm_gas_GAS_CALL_VALUE : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_CALL_VALUE". +Axiom ethereum_istanbul_vm_gas_GAS_CREATE : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_CREATE". +Axiom ethereum_istanbul_vm_gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_KECCAK256_WORD". +Axiom ethereum_istanbul_vm_gas_GAS_NEW_ACCOUNT : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_NEW_ACCOUNT". +Axiom ethereum_istanbul_vm_gas_GAS_SELF_DESTRUCT : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_SELF_DESTRUCT". +Axiom ethereum_istanbul_vm_gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". +Axiom ethereum_istanbul_vm_gas_GAS_ZERO : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_ZERO". +Axiom ethereum_istanbul_vm_gas_REFUND_SELF_DESTRUCT : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "REFUND_SELF_DESTRUCT". +Axiom ethereum_istanbul_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_istanbul_vm_gas_calculate_message_call_gas : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "calculate_message_call_gas". +Axiom ethereum_istanbul_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "charge_gas". +Axiom ethereum_istanbul_vm_gas_max_message_call_gas : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "max_message_call_gas". -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". -Axiom memory_memory_write : - IsGlobalAlias globals memory.globals "memory_write". +Require ethereum.istanbul.vm.memory. +Axiom ethereum_istanbul_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.istanbul.vm.memory.globals "memory_read_bytes". +Axiom ethereum_istanbul_vm_memory_memory_write : + IsGlobalAlias globals ethereum.istanbul.vm.memory.globals "memory_write". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.istanbul.vm.stack. +Axiom ethereum_istanbul_vm_stack_pop : + IsGlobalAlias globals ethereum.istanbul.vm.stack.globals "pop". +Axiom ethereum_istanbul_vm_stack_push : + IsGlobalAlias globals ethereum.istanbul.vm.stack.globals "push". Definition generic_create : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -165,9 +165,113 @@ Definition generic_create : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt (| + M.get_field (| M.get_name (| globals, "sender" |), "balance" |), + M.get_name (| globals, "endowment" |) + |), + ltac:(M.monadic ( + BoolOp.or (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "sender" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.sub (| + BinOp.pow (| + Constant.int 2, + Constant.int 64 + |), + Constant.int 1 + |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.gt (| + BinOp.add (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "depth" |), + Constant.int 1 + |), + M.get_name (| globals, "STACK_DEPTH_LIMIT" |) + |) + )) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "create_message_gas" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "contract_address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let call_data := @@ -204,6 +308,40 @@ Definition generic_create : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "child_evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_error" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "incorporate_child_on_success" |), make_list [ @@ -560,6 +698,42 @@ Definition generic_call : Value.t -> Value.t -> M := Constant.bytes "" |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + BinOp.add (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "depth" |), + Constant.int 1 + |), + M.get_name (| globals, "STACK_DEPTH_LIMIT" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "gas" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let call_data := @@ -597,6 +771,40 @@ Definition generic_call : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "child_evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_error" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "incorporate_child_on_success" |), make_list [ @@ -651,7 +859,7 @@ Definition generic_call : Value.t -> Value.t -> M := make_list [ M.get_field (| M.get_name (| globals, "evm" |), "memory" |); M.get_name (| globals, "memory_output_start_position" |); - M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), Constant.None_:M.get_name (| globals, "actual_output_size" |) |) + M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), M.slice (| Constant.None_, M.get_name (| globals, "actual_output_size" |) |) |) ], make_dict [] |) in @@ -749,49 +957,57 @@ Definition call : Value.t -> Value.t -> M := make_dict [] |) in let create_gas_cost := - (* if *) -M.if_then_else (| - BoolOp.or (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), - ltac:(M.monadic ( - M.call (| - M.get_name (| globals, "is_account_alive" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); - M.get_name (| globals, "to" |) - ], - make_dict [] - |) - )) - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "is_account_alive" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "to" |) + ], + make_dict [] + |) + )) + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "GAS_NEW_ACCOUNT" |) + )) |) in let transfer_gas_cost := - (* if *) -M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "GAS_CALL_VALUE" |) + )) |) in let message_call_gas := M.call (| M.get_name (| globals, "calculate_message_call_gas" |), @@ -867,6 +1083,40 @@ M.call (| make_dict [] |), "balance" |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "sender_balance" |), + M.get_name (| globals, "value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "generic_call" |), make_list [ @@ -988,21 +1238,25 @@ Definition callcode : Value.t -> Value.t -> M := make_dict [] |) in let transfer_gas_cost := - (* if *) -M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "GAS_CALL_VALUE" |) + )) |) in let message_call_gas := M.call (| M.get_name (| globals, "calculate_message_call_gas" |), @@ -1053,6 +1307,40 @@ M.call (| make_dict [] |), "balance" |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "sender_balance" |), + M.get_name (| globals, "value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "generic_call" |), make_list [ @@ -1108,6 +1396,39 @@ Definition selfdestruct : Value.t -> Value.t -> M := let gas_cost := M.get_name (| globals, "GAS_SELF_DESTRUCT" |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + UnOp.not (| M.call (| + M.get_name (| globals, "is_account_alive" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) + M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let originator := @@ -1131,6 +1452,22 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in EndWhile. let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "originator" |), + M.get_name (| globals, "refunded_accounts" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.get_name (| globals, "REFUND_SELF_DESTRUCT" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -1202,6 +1539,28 @@ Definition selfdestruct : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -1593,6 +1952,6 @@ Definition revert : Value.t -> Value.t -> M := make_dict [] |) |) in - let _ := M.raise (| Some(M.get_name (| globals, "Revert" |)) + let _ := M.raise (| Some(M.get_name (| globals, "Revert" |)) |) in let _ := M.pass (| |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/vm/interpreter.v b/CoqOfPython/ethereum/istanbul/vm/interpreter.v index dd5fceb..145b4d1 100644 --- a/CoqOfPython/ethereum/istanbul/vm/interpreter.v +++ b/CoqOfPython/ethereum/istanbul/vm/interpreter.v @@ -61,81 +61,81 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". - -Require state. -Axiom state_account_exists_and_is_empty : - IsGlobalAlias globals state.globals "account_exists_and_is_empty". -Axiom state_account_has_code_or_nonce : - IsGlobalAlias globals state.globals "account_has_code_or_nonce". -Axiom state_begin_transaction : - IsGlobalAlias globals state.globals "begin_transaction". -Axiom state_commit_transaction : - IsGlobalAlias globals state.globals "commit_transaction". -Axiom state_destroy_storage : - IsGlobalAlias globals state.globals "destroy_storage". -Axiom state_increment_nonce : - IsGlobalAlias globals state.globals "increment_nonce". -Axiom state_mark_account_created : - IsGlobalAlias globals state.globals "mark_account_created". -Axiom state_move_ether : - IsGlobalAlias globals state.globals "move_ether". -Axiom state_rollback_transaction : - IsGlobalAlias globals state.globals "rollback_transaction". -Axiom state_set_code : - IsGlobalAlias globals state.globals "set_code". -Axiom state_touch_account : - IsGlobalAlias globals state.globals "touch_account". - -Require vm. -Axiom vm_Message : - IsGlobalAlias globals vm.globals "Message". - -Require vm.gas. -Axiom vm_gas_GAS_CODE_DEPOSIT : - IsGlobalAlias globals vm.gas.globals "GAS_CODE_DEPOSIT". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". - -Require vm.precompiled_contracts.mapping. -Axiom vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : - IsGlobalAlias globals vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". - -Require __init__. -Axiom __init___Environment : - IsGlobalAlias globals __init__.globals "Environment". -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require exceptions. -Axiom exceptions_AddressCollision : - IsGlobalAlias globals exceptions.globals "AddressCollision". -Axiom exceptions_ExceptionalHalt : - IsGlobalAlias globals exceptions.globals "ExceptionalHalt". -Axiom exceptions_InvalidOpcode : - IsGlobalAlias globals exceptions.globals "InvalidOpcode". -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". -Axiom exceptions_Revert : - IsGlobalAlias globals exceptions.globals "Revert". -Axiom exceptions_StackDepthLimitError : - IsGlobalAlias globals exceptions.globals "StackDepthLimitError". - -Require instructions. -Axiom instructions_Ops : - IsGlobalAlias globals instructions.globals "Ops". -Axiom instructions_op_implementation : - IsGlobalAlias globals instructions.globals "op_implementation". - -Require runtime. -Axiom runtime_get_valid_jump_destinations : - IsGlobalAlias globals runtime.globals "get_valid_jump_destinations". +Require ethereum.istanbul.blocks. +Axiom ethereum_istanbul_blocks_Log : + IsGlobalAlias globals ethereum.istanbul.blocks.globals "Log". + +Require ethereum.istanbul.fork_types. +Axiom ethereum_istanbul_fork_types_Address : + IsGlobalAlias globals ethereum.istanbul.fork_types.globals "Address". + +Require ethereum.istanbul.state. +Axiom ethereum_istanbul_state_account_exists_and_is_empty : + IsGlobalAlias globals ethereum.istanbul.state.globals "account_exists_and_is_empty". +Axiom ethereum_istanbul_state_account_has_code_or_nonce : + IsGlobalAlias globals ethereum.istanbul.state.globals "account_has_code_or_nonce". +Axiom ethereum_istanbul_state_begin_transaction : + IsGlobalAlias globals ethereum.istanbul.state.globals "begin_transaction". +Axiom ethereum_istanbul_state_commit_transaction : + IsGlobalAlias globals ethereum.istanbul.state.globals "commit_transaction". +Axiom ethereum_istanbul_state_destroy_storage : + IsGlobalAlias globals ethereum.istanbul.state.globals "destroy_storage". +Axiom ethereum_istanbul_state_increment_nonce : + IsGlobalAlias globals ethereum.istanbul.state.globals "increment_nonce". +Axiom ethereum_istanbul_state_mark_account_created : + IsGlobalAlias globals ethereum.istanbul.state.globals "mark_account_created". +Axiom ethereum_istanbul_state_move_ether : + IsGlobalAlias globals ethereum.istanbul.state.globals "move_ether". +Axiom ethereum_istanbul_state_rollback_transaction : + IsGlobalAlias globals ethereum.istanbul.state.globals "rollback_transaction". +Axiom ethereum_istanbul_state_set_code : + IsGlobalAlias globals ethereum.istanbul.state.globals "set_code". +Axiom ethereum_istanbul_state_touch_account : + IsGlobalAlias globals ethereum.istanbul.state.globals "touch_account". + +Require ethereum.istanbul.vm.__init__. +Axiom ethereum_istanbul_vm___init___Message : + IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Message". + +Require ethereum.istanbul.vm.gas. +Axiom ethereum_istanbul_vm_gas_GAS_CODE_DEPOSIT : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_CODE_DEPOSIT". +Axiom ethereum_istanbul_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "charge_gas". + +Require ethereum.istanbul.vm.precompiled_contracts.mapping. +Axiom ethereum_istanbul_vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : + IsGlobalAlias globals ethereum.istanbul.vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". + +Require ethereum.istanbul.vm.__init__. +Axiom ethereum_istanbul_vm___init___Environment : + IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Environment". +Axiom ethereum_istanbul_vm___init___Evm : + IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Evm". + +Require ethereum.istanbul.vm.exceptions. +Axiom ethereum_istanbul_vm_exceptions_AddressCollision : + IsGlobalAlias globals ethereum.istanbul.vm.exceptions.globals "AddressCollision". +Axiom ethereum_istanbul_vm_exceptions_ExceptionalHalt : + IsGlobalAlias globals ethereum.istanbul.vm.exceptions.globals "ExceptionalHalt". +Axiom ethereum_istanbul_vm_exceptions_InvalidOpcode : + IsGlobalAlias globals ethereum.istanbul.vm.exceptions.globals "InvalidOpcode". +Axiom ethereum_istanbul_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.istanbul.vm.exceptions.globals "OutOfGasError". +Axiom ethereum_istanbul_vm_exceptions_Revert : + IsGlobalAlias globals ethereum.istanbul.vm.exceptions.globals "Revert". +Axiom ethereum_istanbul_vm_exceptions_StackDepthLimitError : + IsGlobalAlias globals ethereum.istanbul.vm.exceptions.globals "StackDepthLimitError". + +Require ethereum.istanbul.vm.instructions.__init__. +Axiom ethereum_istanbul_vm_instructions___init___Ops : + IsGlobalAlias globals ethereum.istanbul.vm.instructions.__init__.globals "Ops". +Axiom ethereum_istanbul_vm_instructions___init___op_implementation : + IsGlobalAlias globals ethereum.istanbul.vm.instructions.__init__.globals "op_implementation". + +Require ethereum.istanbul.vm.runtime. +Axiom ethereum_istanbul_vm_runtime_get_valid_jump_destinations : + IsGlobalAlias globals ethereum.istanbul.vm.runtime.globals "get_valid_jump_destinations". Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -182,6 +182,94 @@ Definition process_message_call : Value.t -> Value.t -> M := Output of the message call " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "message" |), "target" |), + M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) + |), + (* then *) + ltac:(M.monadic ( + let is_collision := + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_name (| globals, "is_collision" |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallOutput" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "tuple" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "AddressCollision" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let evm := + M.call (| + M.get_name (| globals, "process_create_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let evm := M.call (| M.get_name (| globals, "process_message" |), @@ -192,11 +280,74 @@ Definition process_message_call : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_field (| M.get_name (| globals, "message" |), "target" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_field (| M.get_name (| globals, "message" |), "target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( +(* At stmt: unsupported node type: AnnAssign *) + let accounts_to_delete := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let touched_accounts := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let refund_counter := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let logs := M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in let accounts_to_delete := @@ -240,6 +391,7 @@ Definition process_message_call : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). Definition process_create_message : Value.t -> Value.t -> M := @@ -301,6 +453,28 @@ Definition process_create_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), + (* then *) + ltac:(M.monadic ( + let contract_code := + M.get_field (| M.get_name (| globals, "evm" |), "output" |) in + let contract_code_gas := + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "contract_code" |) + ], + make_dict [] + |), + M.get_name (| globals, "GAS_CODE_DEPOSIT" |) + |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "rollback_transaction" |), make_list [ @@ -312,6 +486,7 @@ Definition process_create_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) + |) in M.pure Constant.None_)). Definition process_message : Value.t -> Value.t -> M := @@ -333,6 +508,24 @@ Definition process_message : Value.t -> Value.t -> M := Items containing execution specific objects " in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_field (| M.get_name (| globals, "message" |), "depth" |), + M.get_name (| globals, "STACK_DEPTH_LIMIT" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "StackDepthLimitError" |), + make_list [ + Constant.str "Stack depth limit reached" + ], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -351,6 +544,32 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + M.get_field (| M.get_name (| globals, "message" |), "should_transfer_value" |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "message" |), "value" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "move_ether" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "caller" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |); + M.get_field (| M.get_name (| globals, "message" |), "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let evm := @@ -363,6 +582,21 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "rollback_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "commit_transaction" |), make_list [ @@ -374,6 +608,7 @@ Definition process_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) + |) in M.pure Constant.None_)). Definition execute_code : Value.t -> Value.t -> M := @@ -413,4 +648,5 @@ Definition execute_code : Value.t -> Value.t -> M := (* At stmt: unsupported node type: Try *) let _ := M.return_ (| M.get_name (| globals, "evm" |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/vm/memory.v b/CoqOfPython/ethereum/istanbul/vm/memory.v index 4b107fd..08d2290 100644 --- a/CoqOfPython/ethereum/istanbul/vm/memory.v +++ b/CoqOfPython/ethereum/istanbul/vm/memory.v @@ -21,13 +21,13 @@ Require ethereum.utils.byte. Axiom ethereum_utils_byte_right_pad_zero_bytes : IsGlobalAlias globals ethereum.utils.byte.globals "right_pad_zero_bytes". -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". Definition memory_write : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,7 +45,22 @@ Definition memory_write : Value.t -> Value.t -> M := Data to write to memory. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |), + M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) |) |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_)). @@ -71,7 +86,23 @@ Definition memory_read_bytes : Value.t -> Value.t -> M := Data read from memory. " in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |) + M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |) |) + |) in M.pure Constant.None_)). Definition buffer_read : Value.t -> Value.t -> M := @@ -98,9 +129,25 @@ Definition buffer_read : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "right_pad_zero_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |) |); + M.get_subscript (| M.get_name (| globals, "buffer" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |) |); M.get_name (| globals, "size" |) ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/__init__.v index ca49311..4ecabfb 100644 --- a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/__init__.v +++ b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/__init__.v @@ -18,9 +18,9 @@ Addresses of precompiled contracts and mappings to their implementations. ". -Require utils.hexadecimal. -Axiom utils_hexadecimal_hex_to_address : - IsGlobalAlias globals utils.hexadecimal.globals "hex_to_address". +Require ethereum.istanbul.utils.hexadecimal. +Axiom ethereum_istanbul_utils_hexadecimal_hex_to_address : + IsGlobalAlias globals ethereum.istanbul.utils.hexadecimal.globals "hex_to_address". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS"; Constant.str "MODEXP_ADDRESS"; Constant.str "ALT_BN128_ADD_ADDRESS"; Constant.str "ALT_BN128_MUL_ADDRESS"; Constant.str "ALT_BN128_PAIRING_CHECK_ADDRESS"; Constant.str "BLAKE2F_ADDRESS" ] diff --git a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/alt_bn128.v index abe4238..2ac2172 100644 --- a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/alt_bn128.v +++ b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/alt_bn128.v @@ -45,21 +45,21 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.istanbul.vm.__init__. +Axiom ethereum_istanbul_vm___init___Evm : + IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.istanbul.vm.gas. +Axiom ethereum_istanbul_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "charge_gas". -Require vm.memory. -Axiom vm_memory_buffer_read : - IsGlobalAlias globals vm.memory.globals "buffer_read". +Require ethereum.istanbul.vm.memory. +Axiom ethereum_istanbul_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.istanbul.vm.memory.globals "buffer_read". -Require exceptions. -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". +Require ethereum.istanbul.vm.exceptions. +Axiom ethereum_istanbul_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.istanbul.vm.exceptions.globals "OutOfGasError". Definition alt_bn128_add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -210,6 +210,18 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) in For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ] do let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -353,6 +365,18 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) in For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ] do let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -425,6 +449,27 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| + BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 192 + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let result := @@ -464,7 +509,7 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "data" |), BinOp.add (| + M.get_subscript (| M.get_name (| globals, "data" |), M.slice (| BinOp.add (| BinOp.mult (| M.get_name (| globals, "i" |), Constant.int 192 @@ -473,11 +518,35 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := Constant.int 32, M.get_name (| globals, "j" |) |) - |) |) + |), BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "j" |), + Constant.int 1 + |) + |) + |) |) |) ], make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -538,10 +607,80 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "p" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "q" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let result := + BinOp.mult (| + M.get_name (| globals, "result" |), + M.call (| + M.get_name (| globals, "pairing" |), + make_list [ + M.get_name (| globals, "q" |); + M.get_name (| globals, "p" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "result" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| diff --git a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/blake2f.v b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/blake2f.v index 1647d48..a0c873b 100644 --- a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/blake2f.v +++ b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/blake2f.v @@ -25,19 +25,19 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.istanbul.vm.__init__. +Axiom ethereum_istanbul_vm___init___Evm : + IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_BLAKE2_PER_ROUND : - IsGlobalAlias globals vm.gas.globals "GAS_BLAKE2_PER_ROUND". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.istanbul.vm.gas. +Axiom ethereum_istanbul_vm_gas_GAS_BLAKE2_PER_ROUND : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_BLAKE2_PER_ROUND". +Axiom ethereum_istanbul_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "charge_gas". -Require exceptions. -Axiom exceptions_InvalidParameter : - IsGlobalAlias globals exceptions.globals "InvalidParameter". +Require ethereum.istanbul.vm.exceptions. +Axiom ethereum_istanbul_vm_exceptions_InvalidParameter : + IsGlobalAlias globals ethereum.istanbul.vm.exceptions.globals "InvalidParameter". Definition blake2f : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/ecrecover.v index 0cbcf16..25c8238 100644 --- a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/ecrecover.v @@ -37,19 +37,19 @@ Require ethereum.utils.byte. Axiom ethereum_utils_byte_left_pad_zero_bytes : IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.istanbul.vm.__init__. +Axiom ethereum_istanbul_vm___init___Evm : + IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_ECRECOVER : - IsGlobalAlias globals vm.gas.globals "GAS_ECRECOVER". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.istanbul.vm.gas. +Axiom ethereum_istanbul_vm_gas_GAS_ECRECOVER : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_ECRECOVER". +Axiom ethereum_istanbul_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "charge_gas". -Require vm.memory. -Axiom vm_memory_buffer_read : - IsGlobalAlias globals vm.memory.globals "buffer_read". +Require ethereum.istanbul.vm.memory. +Axiom ethereum_istanbul_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.istanbul.vm.memory.globals "buffer_read". Definition ecrecover : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -188,12 +188,78 @@ Definition ecrecover : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "v" |), + Constant.int 27 + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "v" |), + Constant.int 28 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + Constant.int 0, + M.get_name (| globals, "r" |) + |), + ltac:(M.monadic ( + Compare.gt_e (| + M.get_name (| globals, "r" |), + M.get_name (| globals, "SECP256K1N" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + Constant.int 0, + M.get_name (| globals, "s" |) + |), + ltac:(M.monadic ( + Compare.gt_e (| + M.get_name (| globals, "s" |), + M.get_name (| globals, "SECP256K1N" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: Try *) @@ -204,7 +270,7 @@ Definition ecrecover : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12 |) in + |), M.slice (| Constant.int 12, Constant.int 32 |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/identity.v index fa96704..3e2007a 100644 --- a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/identity.v +++ b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/identity.v @@ -25,17 +25,17 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.istanbul.vm.__init__. +Axiom ethereum_istanbul_vm___init___Evm : + IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_IDENTITY : - IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY". -Axiom vm_gas_GAS_IDENTITY_WORD : - IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY_WORD". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.istanbul.vm.gas. +Axiom ethereum_istanbul_vm_gas_GAS_IDENTITY : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_IDENTITY". +Axiom ethereum_istanbul_vm_gas_GAS_IDENTITY_WORD : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_IDENTITY_WORD". +Axiom ethereum_istanbul_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "charge_gas". Definition identity : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/mapping.v index 8a2e2eb..2dfb4a0 100644 --- a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/mapping.v +++ b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/mapping.v @@ -23,60 +23,60 @@ Axiom typing_Callable : Axiom typing_Dict : IsGlobalAlias globals typing.globals "Dict". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". - -Require __init__. -Axiom __init___ALT_BN128_ADD_ADDRESS : - IsGlobalAlias globals __init__.globals "ALT_BN128_ADD_ADDRESS". -Axiom __init___ALT_BN128_MUL_ADDRESS : - IsGlobalAlias globals __init__.globals "ALT_BN128_MUL_ADDRESS". -Axiom __init___ALT_BN128_PAIRING_CHECK_ADDRESS : - IsGlobalAlias globals __init__.globals "ALT_BN128_PAIRING_CHECK_ADDRESS". -Axiom __init___BLAKE2F_ADDRESS : - IsGlobalAlias globals __init__.globals "BLAKE2F_ADDRESS". -Axiom __init___ECRECOVER_ADDRESS : - IsGlobalAlias globals __init__.globals "ECRECOVER_ADDRESS". -Axiom __init___IDENTITY_ADDRESS : - IsGlobalAlias globals __init__.globals "IDENTITY_ADDRESS". -Axiom __init___MODEXP_ADDRESS : - IsGlobalAlias globals __init__.globals "MODEXP_ADDRESS". -Axiom __init___RIPEMD160_ADDRESS : - IsGlobalAlias globals __init__.globals "RIPEMD160_ADDRESS". -Axiom __init___SHA256_ADDRESS : - IsGlobalAlias globals __init__.globals "SHA256_ADDRESS". - -Require alt_bn128. -Axiom alt_bn128_alt_bn128_add : - IsGlobalAlias globals alt_bn128.globals "alt_bn128_add". -Axiom alt_bn128_alt_bn128_mul : - IsGlobalAlias globals alt_bn128.globals "alt_bn128_mul". -Axiom alt_bn128_alt_bn128_pairing_check : - IsGlobalAlias globals alt_bn128.globals "alt_bn128_pairing_check". - -Require blake2f. -Axiom blake2f_blake2f : - IsGlobalAlias globals blake2f.globals "blake2f". - -Require ecrecover. -Axiom ecrecover_ecrecover : - IsGlobalAlias globals ecrecover.globals "ecrecover". - -Require identity. -Axiom identity_identity : - IsGlobalAlias globals identity.globals "identity". - -Require modexp. -Axiom modexp_modexp : - IsGlobalAlias globals modexp.globals "modexp". - -Require ripemd160. -Axiom ripemd160_ripemd160 : - IsGlobalAlias globals ripemd160.globals "ripemd160". - -Require sha256. -Axiom sha256_sha256 : - IsGlobalAlias globals sha256.globals "sha256". +Require ethereum.istanbul.fork_types. +Axiom ethereum_istanbul_fork_types_Address : + IsGlobalAlias globals ethereum.istanbul.fork_types.globals "Address". + +Require ethereum.istanbul.vm.precompiled_contracts.__init__. +Axiom ethereum_istanbul_vm_precompiled_contracts___init___ALT_BN128_ADD_ADDRESS : + IsGlobalAlias globals ethereum.istanbul.vm.precompiled_contracts.__init__.globals "ALT_BN128_ADD_ADDRESS". +Axiom ethereum_istanbul_vm_precompiled_contracts___init___ALT_BN128_MUL_ADDRESS : + IsGlobalAlias globals ethereum.istanbul.vm.precompiled_contracts.__init__.globals "ALT_BN128_MUL_ADDRESS". +Axiom ethereum_istanbul_vm_precompiled_contracts___init___ALT_BN128_PAIRING_CHECK_ADDRESS : + IsGlobalAlias globals ethereum.istanbul.vm.precompiled_contracts.__init__.globals "ALT_BN128_PAIRING_CHECK_ADDRESS". +Axiom ethereum_istanbul_vm_precompiled_contracts___init___BLAKE2F_ADDRESS : + IsGlobalAlias globals ethereum.istanbul.vm.precompiled_contracts.__init__.globals "BLAKE2F_ADDRESS". +Axiom ethereum_istanbul_vm_precompiled_contracts___init___ECRECOVER_ADDRESS : + IsGlobalAlias globals ethereum.istanbul.vm.precompiled_contracts.__init__.globals "ECRECOVER_ADDRESS". +Axiom ethereum_istanbul_vm_precompiled_contracts___init___IDENTITY_ADDRESS : + IsGlobalAlias globals ethereum.istanbul.vm.precompiled_contracts.__init__.globals "IDENTITY_ADDRESS". +Axiom ethereum_istanbul_vm_precompiled_contracts___init___MODEXP_ADDRESS : + IsGlobalAlias globals ethereum.istanbul.vm.precompiled_contracts.__init__.globals "MODEXP_ADDRESS". +Axiom ethereum_istanbul_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : + IsGlobalAlias globals ethereum.istanbul.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". +Axiom ethereum_istanbul_vm_precompiled_contracts___init___SHA256_ADDRESS : + IsGlobalAlias globals ethereum.istanbul.vm.precompiled_contracts.__init__.globals "SHA256_ADDRESS". + +Require ethereum.istanbul.vm.precompiled_contracts.alt_bn128. +Axiom ethereum_istanbul_vm_precompiled_contracts_alt_bn128_alt_bn128_add : + IsGlobalAlias globals ethereum.istanbul.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_add". +Axiom ethereum_istanbul_vm_precompiled_contracts_alt_bn128_alt_bn128_mul : + IsGlobalAlias globals ethereum.istanbul.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_mul". +Axiom ethereum_istanbul_vm_precompiled_contracts_alt_bn128_alt_bn128_pairing_check : + IsGlobalAlias globals ethereum.istanbul.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_pairing_check". + +Require ethereum.istanbul.vm.precompiled_contracts.blake2f. +Axiom ethereum_istanbul_vm_precompiled_contracts_blake2f_blake2f : + IsGlobalAlias globals ethereum.istanbul.vm.precompiled_contracts.blake2f.globals "blake2f". + +Require ethereum.istanbul.vm.precompiled_contracts.ecrecover. +Axiom ethereum_istanbul_vm_precompiled_contracts_ecrecover_ecrecover : + IsGlobalAlias globals ethereum.istanbul.vm.precompiled_contracts.ecrecover.globals "ecrecover". + +Require ethereum.istanbul.vm.precompiled_contracts.identity. +Axiom ethereum_istanbul_vm_precompiled_contracts_identity_identity : + IsGlobalAlias globals ethereum.istanbul.vm.precompiled_contracts.identity.globals "identity". + +Require ethereum.istanbul.vm.precompiled_contracts.modexp. +Axiom ethereum_istanbul_vm_precompiled_contracts_modexp_modexp : + IsGlobalAlias globals ethereum.istanbul.vm.precompiled_contracts.modexp.globals "modexp". + +Require ethereum.istanbul.vm.precompiled_contracts.ripemd160. +Axiom ethereum_istanbul_vm_precompiled_contracts_ripemd160_ripemd160 : + IsGlobalAlias globals ethereum.istanbul.vm.precompiled_contracts.ripemd160.globals "ripemd160". + +Require ethereum.istanbul.vm.precompiled_contracts.sha256. +Axiom ethereum_istanbul_vm_precompiled_contracts_sha256_sha256 : + IsGlobalAlias globals ethereum.istanbul.vm.precompiled_contracts.sha256.globals "sha256". (* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/modexp.v index aff5b85..2eb27a5 100644 --- a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/modexp.v +++ b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/modexp.v @@ -25,17 +25,17 @@ Axiom ethereum_base_types_Bytes : Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.istanbul.vm.__init__. +Axiom ethereum_istanbul_vm___init___Evm : + IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.istanbul.vm.gas. +Axiom ethereum_istanbul_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "charge_gas". -Require memory. -Axiom memory_buffer_read : - IsGlobalAlias globals memory.globals "buffer_read". +Require ethereum.istanbul.vm.memory. +Axiom ethereum_istanbul_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.istanbul.vm.memory.globals "buffer_read". Definition GQUADDIVISOR : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -181,6 +181,39 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "exp_length" |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let adjusted_exp_length := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "max" |), + make_list [ + Constant.int 0; + BinOp.sub (| + M.call (| + M.get_field (| M.get_name (| globals, "exp_head" |), "bit_length" |), + make_list [], + make_dict [] + |), + Constant.int 1 + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let adjusted_exp_length := M.call (| M.get_name (| globals, "Uint" |), @@ -267,6 +300,36 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_name (| globals, "base_length" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "modulus_length" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [], + make_dict [] + |) + |) in + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let base := @@ -329,6 +392,30 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "modulus" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + BinOp.mult (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + Constant.bytes "00" + ], + make_dict [] + |), + M.get_name (| globals, "modulus_length" |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| @@ -365,7 +452,53 @@ Definition get_mult_complexity : Value.t -> Value.t -> M := Estimate the complexity of performing Karatsuba multiplication. " in let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "x" |), + Constant.int 64 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.pow (| + M.get_name (| globals, "x" |), + Constant.int 2 + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "x" |), + Constant.int 1024 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.sub (| + BinOp.add (| + BinOp.floor_div (| + BinOp.pow (| + M.get_name (| globals, "x" |), + Constant.int 2 + |), + Constant.int 4 + |), + BinOp.mult (| + Constant.int 96, + M.get_name (| globals, "x" |) + |) + |), + Constant.int 3072 + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| BinOp.sub (| BinOp.add (| @@ -383,6 +516,7 @@ Definition get_mult_complexity : Value.t -> Value.t -> M := |), Constant.int 199680 |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/ripemd160.v index 96f8dcd..7725002 100644 --- a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/ripemd160.v +++ b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/ripemd160.v @@ -31,17 +31,17 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.istanbul.vm.__init__. +Axiom ethereum_istanbul_vm___init___Evm : + IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_RIPEMD160 : - IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160". -Axiom vm_gas_GAS_RIPEMD160_WORD : - IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160_WORD". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.istanbul.vm.gas. +Axiom ethereum_istanbul_vm_gas_GAS_RIPEMD160 : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_RIPEMD160". +Axiom ethereum_istanbul_vm_gas_GAS_RIPEMD160_WORD : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_RIPEMD160_WORD". +Axiom ethereum_istanbul_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "charge_gas". Definition ripemd160 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/sha256.v index 9f6d2bf..14ebf99 100644 --- a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/sha256.v +++ b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/sha256.v @@ -27,17 +27,17 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.istanbul.vm.__init__. +Axiom ethereum_istanbul_vm___init___Evm : + IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_SHA256 : - IsGlobalAlias globals vm.gas.globals "GAS_SHA256". -Axiom vm_gas_GAS_SHA256_WORD : - IsGlobalAlias globals vm.gas.globals "GAS_SHA256_WORD". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.istanbul.vm.gas. +Axiom ethereum_istanbul_vm_gas_GAS_SHA256 : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_SHA256". +Axiom ethereum_istanbul_vm_gas_GAS_SHA256_WORD : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_SHA256_WORD". +Axiom ethereum_istanbul_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "charge_gas". Definition sha256 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/istanbul/vm/runtime.v b/CoqOfPython/ethereum/istanbul/vm/runtime.v index 2cd7652..77cb330 100644 --- a/CoqOfPython/ethereum/istanbul/vm/runtime.v +++ b/CoqOfPython/ethereum/istanbul/vm/runtime.v @@ -25,9 +25,9 @@ Require ethereum.base_types. Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require instructions. -Axiom instructions_Ops : - IsGlobalAlias globals instructions.globals "Ops". +Require ethereum.istanbul.vm.instructions.__init__. +Axiom ethereum_istanbul_vm_instructions___init___Ops : + IsGlobalAlias globals ethereum.istanbul.vm.instructions.__init__.globals "Ops". Definition get_valid_jump_destinations : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -79,7 +79,55 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := |) do (* At stmt: unsupported node type: Try *) let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "current_opcode" |), + M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), + make_list [ + M.get_name (| globals, "pc" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.lt_e (| + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |), + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH32" |), "value" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let push_data_size := + BinOp.add (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) + |), + Constant.int 1 + |) in + let pc := BinOp.add + M.get_name (| globals, "push_data_size" |) + M.get_name (| globals, "push_data_size" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -90,4 +138,5 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := EndWhile. let _ := M.return_ (| M.get_name (| globals, "valid_jump_destinations" |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/vm/stack.v b/CoqOfPython/ethereum/istanbul/vm/stack.v index ea778df..f9af452 100644 --- a/CoqOfPython/ethereum/istanbul/vm/stack.v +++ b/CoqOfPython/ethereum/istanbul/vm/stack.v @@ -25,11 +25,11 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require exceptions. -Axiom exceptions_StackOverflowError : - IsGlobalAlias globals exceptions.globals "StackOverflowError". -Axiom exceptions_StackUnderflowError : - IsGlobalAlias globals exceptions.globals "StackUnderflowError". +Require ethereum.istanbul.vm.exceptions. +Axiom ethereum_istanbul_vm_exceptions_StackOverflowError : + IsGlobalAlias globals ethereum.istanbul.vm.exceptions.globals "StackOverflowError". +Axiom ethereum_istanbul_vm_exceptions_StackUnderflowError : + IsGlobalAlias globals ethereum.istanbul.vm.exceptions.globals "StackUnderflowError". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -49,6 +49,24 @@ Definition pop : Value.t -> Value.t -> M := " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "StackUnderflowError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -57,6 +75,7 @@ Definition pop : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). Definition push : Value.t -> Value.t -> M := @@ -75,6 +94,24 @@ Definition push : Value.t -> Value.t -> M := " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), + Constant.int 1024 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "StackOverflowError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -85,4 +122,5 @@ Definition push : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/blocks.v b/CoqOfPython/ethereum/london/blocks.v index a90217e..1b30d27 100644 --- a/CoqOfPython/ethereum/london/blocks.v +++ b/CoqOfPython/ethereum/london/blocks.v @@ -24,35 +24,35 @@ Axiom typing_Tuple : Axiom typing_Union : IsGlobalAlias globals typing.globals "Union". -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes8 : - IsGlobalAlias globals base_types.globals "Bytes8". -Axiom base_types_Bytes32 : - IsGlobalAlias globals base_types.globals "Bytes32". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require crypto.hash. -Axiom crypto_hash_Hash32 : - IsGlobalAlias globals crypto.hash.globals "Hash32". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". - -Require transactions. -Axiom transactions_LegacyTransaction : - IsGlobalAlias globals transactions.globals "LegacyTransaction". +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes8 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes8". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". + +Require ethereum.london.fork_types. +Axiom ethereum_london_fork_types_Address : + IsGlobalAlias globals ethereum.london.fork_types.globals "Address". +Axiom ethereum_london_fork_types_Bloom : + IsGlobalAlias globals ethereum.london.fork_types.globals "Bloom". +Axiom ethereum_london_fork_types_Root : + IsGlobalAlias globals ethereum.london.fork_types.globals "Root". + +Require ethereum.london.transactions. +Axiom ethereum_london_transactions_LegacyTransaction : + IsGlobalAlias globals ethereum.london.transactions.globals "LegacyTransaction". Definition Header : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/london/bloom.v b/CoqOfPython/ethereum/london/bloom.v index 04650ff..afe8e98 100644 --- a/CoqOfPython/ethereum/london/bloom.v +++ b/CoqOfPython/ethereum/london/bloom.v @@ -33,13 +33,13 @@ Require ethereum.crypto.hash. Axiom ethereum_crypto_hash_keccak256 : IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". +Require ethereum.london.blocks. +Axiom ethereum_london_blocks_Log : + IsGlobalAlias globals ethereum.london.blocks.globals "Log". -Require fork_types. -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". +Require ethereum.london.fork_types. +Axiom ethereum_london_fork_types_Bloom : + IsGlobalAlias globals ethereum.london.fork_types.globals "Bloom". Definition add_to_bloom : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -72,7 +72,10 @@ Definition add_to_bloom : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |) |) + M.get_subscript (| M.get_name (| globals, "hash" |), M.slice (| M.get_name (| globals, "idx" |), BinOp.add (| + M.get_name (| globals, "idx" |), + Constant.int 2 + |) |) |) ], make_dict [] |), @@ -157,4 +160,5 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/fork.v b/CoqOfPython/ethereum/london/fork.v index b448bed..5904b9f 100644 --- a/CoqOfPython/ethereum/london/fork.v +++ b/CoqOfPython/ethereum/london/fork.v @@ -65,109 +65,109 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U64 : - IsGlobalAlias globals base_types.globals "U64". -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_U256_CEIL_VALUE : - IsGlobalAlias globals base_types.globals "U256_CEIL_VALUE". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". - -Require __init__. -Axiom __init___FORK_CRITERIA : - IsGlobalAlias globals __init__.globals "FORK_CRITERIA". -Axiom __init___vm : - IsGlobalAlias globals __init__.globals "vm". - -Require blocks. -Axiom blocks_Block : - IsGlobalAlias globals blocks.globals "Block". -Axiom blocks_Header : - IsGlobalAlias globals blocks.globals "Header". -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". -Axiom blocks_Receipt : - IsGlobalAlias globals blocks.globals "Receipt". - -Require bloom. -Axiom bloom_logs_bloom : - IsGlobalAlias globals bloom.globals "logs_bloom". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". - -Require state. -Axiom state_State : - IsGlobalAlias globals state.globals "State". -Axiom state_account_exists_and_is_empty : - IsGlobalAlias globals state.globals "account_exists_and_is_empty". -Axiom state_create_ether : - IsGlobalAlias globals state.globals "create_ether". -Axiom state_destroy_account : - IsGlobalAlias globals state.globals "destroy_account". -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". -Axiom state_increment_nonce : - IsGlobalAlias globals state.globals "increment_nonce". -Axiom state_set_account_balance : - IsGlobalAlias globals state.globals "set_account_balance". -Axiom state_state_root : - IsGlobalAlias globals state.globals "state_root". - -Require transactions. -Axiom transactions_TX_ACCESS_LIST_ADDRESS_COST : - IsGlobalAlias globals transactions.globals "TX_ACCESS_LIST_ADDRESS_COST". -Axiom transactions_TX_ACCESS_LIST_STORAGE_KEY_COST : - IsGlobalAlias globals transactions.globals "TX_ACCESS_LIST_STORAGE_KEY_COST". -Axiom transactions_TX_BASE_COST : - IsGlobalAlias globals transactions.globals "TX_BASE_COST". -Axiom transactions_TX_CREATE_COST : - IsGlobalAlias globals transactions.globals "TX_CREATE_COST". -Axiom transactions_TX_DATA_COST_PER_NON_ZERO : - IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_NON_ZERO". -Axiom transactions_TX_DATA_COST_PER_ZERO : - IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_ZERO". -Axiom transactions_AccessListTransaction : - IsGlobalAlias globals transactions.globals "AccessListTransaction". -Axiom transactions_FeeMarketTransaction : - IsGlobalAlias globals transactions.globals "FeeMarketTransaction". -Axiom transactions_LegacyTransaction : - IsGlobalAlias globals transactions.globals "LegacyTransaction". -Axiom transactions_Transaction : - IsGlobalAlias globals transactions.globals "Transaction". -Axiom transactions_decode_transaction : - IsGlobalAlias globals transactions.globals "decode_transaction". -Axiom transactions_encode_transaction : - IsGlobalAlias globals transactions.globals "encode_transaction". - -Require trie. -Axiom trie_Trie : - IsGlobalAlias globals trie.globals "Trie". -Axiom trie_root : - IsGlobalAlias globals trie.globals "root". -Axiom trie_trie_set : - IsGlobalAlias globals trie.globals "trie_set". - -Require utils.message. -Axiom utils_message_prepare_message : - IsGlobalAlias globals utils.message.globals "prepare_message". - -Require vm.interpreter. -Axiom vm_interpreter_process_message_call : - IsGlobalAlias globals vm.interpreter.globals "process_message_call". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U64 : + IsGlobalAlias globals ethereum.base_types.globals "U64". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_U256_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.london.__init__. +Axiom ethereum_london___init___FORK_CRITERIA : + IsGlobalAlias globals ethereum.london.__init__.globals "FORK_CRITERIA". +Axiom ethereum_london___init___vm : + IsGlobalAlias globals ethereum.london.__init__.globals "vm". + +Require ethereum.london.blocks. +Axiom ethereum_london_blocks_Block : + IsGlobalAlias globals ethereum.london.blocks.globals "Block". +Axiom ethereum_london_blocks_Header : + IsGlobalAlias globals ethereum.london.blocks.globals "Header". +Axiom ethereum_london_blocks_Log : + IsGlobalAlias globals ethereum.london.blocks.globals "Log". +Axiom ethereum_london_blocks_Receipt : + IsGlobalAlias globals ethereum.london.blocks.globals "Receipt". + +Require ethereum.london.bloom. +Axiom ethereum_london_bloom_logs_bloom : + IsGlobalAlias globals ethereum.london.bloom.globals "logs_bloom". + +Require ethereum.london.fork_types. +Axiom ethereum_london_fork_types_Address : + IsGlobalAlias globals ethereum.london.fork_types.globals "Address". +Axiom ethereum_london_fork_types_Bloom : + IsGlobalAlias globals ethereum.london.fork_types.globals "Bloom". +Axiom ethereum_london_fork_types_Root : + IsGlobalAlias globals ethereum.london.fork_types.globals "Root". + +Require ethereum.london.state. +Axiom ethereum_london_state_State : + IsGlobalAlias globals ethereum.london.state.globals "State". +Axiom ethereum_london_state_account_exists_and_is_empty : + IsGlobalAlias globals ethereum.london.state.globals "account_exists_and_is_empty". +Axiom ethereum_london_state_create_ether : + IsGlobalAlias globals ethereum.london.state.globals "create_ether". +Axiom ethereum_london_state_destroy_account : + IsGlobalAlias globals ethereum.london.state.globals "destroy_account". +Axiom ethereum_london_state_get_account : + IsGlobalAlias globals ethereum.london.state.globals "get_account". +Axiom ethereum_london_state_increment_nonce : + IsGlobalAlias globals ethereum.london.state.globals "increment_nonce". +Axiom ethereum_london_state_set_account_balance : + IsGlobalAlias globals ethereum.london.state.globals "set_account_balance". +Axiom ethereum_london_state_state_root : + IsGlobalAlias globals ethereum.london.state.globals "state_root". + +Require ethereum.london.transactions. +Axiom ethereum_london_transactions_TX_ACCESS_LIST_ADDRESS_COST : + IsGlobalAlias globals ethereum.london.transactions.globals "TX_ACCESS_LIST_ADDRESS_COST". +Axiom ethereum_london_transactions_TX_ACCESS_LIST_STORAGE_KEY_COST : + IsGlobalAlias globals ethereum.london.transactions.globals "TX_ACCESS_LIST_STORAGE_KEY_COST". +Axiom ethereum_london_transactions_TX_BASE_COST : + IsGlobalAlias globals ethereum.london.transactions.globals "TX_BASE_COST". +Axiom ethereum_london_transactions_TX_CREATE_COST : + IsGlobalAlias globals ethereum.london.transactions.globals "TX_CREATE_COST". +Axiom ethereum_london_transactions_TX_DATA_COST_PER_NON_ZERO : + IsGlobalAlias globals ethereum.london.transactions.globals "TX_DATA_COST_PER_NON_ZERO". +Axiom ethereum_london_transactions_TX_DATA_COST_PER_ZERO : + IsGlobalAlias globals ethereum.london.transactions.globals "TX_DATA_COST_PER_ZERO". +Axiom ethereum_london_transactions_AccessListTransaction : + IsGlobalAlias globals ethereum.london.transactions.globals "AccessListTransaction". +Axiom ethereum_london_transactions_FeeMarketTransaction : + IsGlobalAlias globals ethereum.london.transactions.globals "FeeMarketTransaction". +Axiom ethereum_london_transactions_LegacyTransaction : + IsGlobalAlias globals ethereum.london.transactions.globals "LegacyTransaction". +Axiom ethereum_london_transactions_Transaction : + IsGlobalAlias globals ethereum.london.transactions.globals "Transaction". +Axiom ethereum_london_transactions_decode_transaction : + IsGlobalAlias globals ethereum.london.transactions.globals "decode_transaction". +Axiom ethereum_london_transactions_encode_transaction : + IsGlobalAlias globals ethereum.london.transactions.globals "encode_transaction". + +Require ethereum.london.trie. +Axiom ethereum_london_trie_Trie : + IsGlobalAlias globals ethereum.london.trie.globals "Trie". +Axiom ethereum_london_trie_root : + IsGlobalAlias globals ethereum.london.trie.globals "root". +Axiom ethereum_london_trie_trie_set : + IsGlobalAlias globals ethereum.london.trie.globals "trie_set". + +Require ethereum.london.utils.message. +Axiom ethereum_london_utils_message_prepare_message : + IsGlobalAlias globals ethereum.london.utils.message.globals "prepare_message". + +Require ethereum.london.vm.interpreter. +Axiom ethereum_london_vm_interpreter_process_message_call : + IsGlobalAlias globals ethereum.london.vm.interpreter.globals "process_message_call". Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -272,6 +272,7 @@ Definition apply_fork : Value.t -> Value.t -> M := " in let _ := M.return_ (| M.get_name (| globals, "old" |) + |) in M.pure Constant.None_)). Definition get_last_256_block_hashes : Value.t -> Value.t -> M := @@ -297,8 +298,28 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := Hashes of the recent 256 blocks in order of increasing block number. " in let recent_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |) |) in + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "recent_blocks" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + make_list [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let recent_block_hashes := @@ -337,6 +358,7 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "recent_block_hashes" |) + |) in M.pure Constant.None_)). Definition state_transition : Value.t -> Value.t -> M := @@ -469,6 +491,27 @@ Definition state_transition : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |) + ], + make_dict [] + |), + Constant.int 255 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -498,6 +541,23 @@ Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := Base fee per gas for the block. " in let _ := + (* if *) + M.if_then_else (| + M.get_name (| globals, "is_fork_block" |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "INITIAL_BASE_FEE" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let parent_gas_target := @@ -521,7 +581,63 @@ Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "parent_gas_used" |), + M.get_name (| globals, "parent_gas_target" |) + |), + (* then *) + ltac:(M.monadic ( + let expected_base_fee_per_gas := + M.get_name (| globals, "parent_base_fee_per_gas" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "parent_gas_used" |), + M.get_name (| globals, "parent_gas_target" |) + |), + (* then *) + ltac:(M.monadic ( + let gas_used_delta := + BinOp.sub (| + M.get_name (| globals, "parent_gas_used" |), + M.get_name (| globals, "parent_gas_target" |) + |) in + let parent_fee_gas_delta := + BinOp.mult (| + M.get_name (| globals, "parent_base_fee_per_gas" |), + M.get_name (| globals, "gas_used_delta" |) + |) in + let target_fee_gas_delta := + BinOp.floor_div (| + M.get_name (| globals, "parent_fee_gas_delta" |), + M.get_name (| globals, "parent_gas_target" |) + |) in + let base_fee_per_gas_delta := + M.call (| + M.get_name (| globals, "max" |), + make_list [ + BinOp.floor_div (| + M.get_name (| globals, "target_fee_gas_delta" |), + M.get_name (| globals, "BASE_FEE_MAX_CHANGE_DENOMINATOR" |) + |); + Constant.int 1 + ], + make_dict [] + |) in + let expected_base_fee_per_gas := + BinOp.add (| + M.get_name (| globals, "parent_base_fee_per_gas" |), + M.get_name (| globals, "base_fee_per_gas_delta" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let gas_used_delta := BinOp.sub (| M.get_name (| globals, "parent_gas_target" |), @@ -559,6 +675,7 @@ Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition validate_header : Value.t -> Value.t -> M := @@ -774,6 +891,7 @@ Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition validate_proof_of_work : Value.t -> Value.t -> M := @@ -911,6 +1029,60 @@ Definition check_transaction : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "FeeMarketTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt_e (| + M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |), + M.get_field (| M.get_name (| globals, "tx" |), "max_priority_fee_per_gas" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt_e (| + M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |), + M.get_name (| globals, "base_fee_per_gas" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let priority_fee_per_gas := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_field (| M.get_name (| globals, "tx" |), "max_priority_fee_per_gas" |); + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |), + M.get_name (| globals, "base_fee_per_gas" |) + |) + ], + make_dict [] + |) in + let effective_gas_price := + BinOp.add (| + M.get_name (| globals, "priority_fee_per_gas" |), + M.get_name (| globals, "base_fee_per_gas" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -928,6 +1100,7 @@ Definition check_transaction : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| make_tuple [ M.get_name (| globals, "sender_address" |); M.get_name (| globals, "effective_gas_price" |) ] + |) in M.pure Constant.None_)). Definition make_receipt : Value.t -> Value.t -> M := @@ -960,9 +1133,64 @@ Definition make_receipt : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "AccessListTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + Constant.bytes "01", + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "receipt" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "FeeMarketTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + Constant.bytes "02", + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "receipt" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "receipt" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -1195,6 +1423,7 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition validate_ommers : Value.t -> Value.t -> M := @@ -1247,6 +1476,26 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do @@ -1304,7 +1553,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let ommers_hashes := - (* At expr: unsupported node type: ListComp *) in + Constant.str "(* At expr: unsupported node type: ListComp *)" in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1335,19 +1584,19 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let recent_canonical_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| BinOp.add (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| BinOp.add (| M.get_name (| globals, "MAX_OMMER_DEPTH" |), Constant.int 1 - |) |) |) in + |) |), Constant.None_ |) |) in let recent_canonical_block_hashes := - (* At expr: unsupported node type: SetComp *) in + Constant.str "(* At expr: unsupported node type: SetComp *)" in (* At stmt: unsupported node type: AnnAssign *) For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_canonical_blocks" |) do let recent_ommers_hashes := M.call (| M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), make_list [ - (* At expr: unsupported node type: SetComp *) + Constant.str "(* At expr: unsupported node type: SetComp *)" ], make_dict [] |) in @@ -1587,6 +1836,26 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "FeeMarketTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let max_gas_fee := + BinOp.mult (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let max_gas_fee := BinOp.mult (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), @@ -1685,6 +1954,39 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + make_tuple [ M.get_name (| globals, "AccessListTransaction" |); M.get_name (| globals, "FeeMarketTransaction" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + For make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "keys" |) ] in M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "preaccessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "key" |) in M.get_name (| globals, "keys" |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "preaccessed_storage_keys" |), "add" |), + make_list [ + make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "key" |) ] + ], + make_dict [] + |) in + EndFor. + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let message := @@ -1789,7 +2091,50 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "transaction_fee" |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| + M.get_name (| globals, "coinbase_balance_after_mining_fee" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |); + M.get_name (| globals, "coinbase_balance_after_mining_fee" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -1806,11 +2151,35 @@ Definition process_transaction : Value.t -> Value.t -> M := EndFor. For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "touched_accounts" |) do let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := M.return_ (| make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |); M.get_field (| M.get_name (| globals, "output" |), "error" |) ] + |) in M.pure Constant.None_)). Definition validate_transaction : Value.t -> Value.t -> M := @@ -1865,6 +2234,7 @@ Definition validate_transaction : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := @@ -1896,6 +2266,20 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := Constant.int 0 in For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "byte" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let data_cost := BinOp.add M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in @@ -1903,6 +2287,25 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := )) |) in EndFor. let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "tx" |), "to" |), + M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) + |), + (* then *) + ltac:(M.monadic ( + let create_cost := + M.get_name (| globals, "TX_CREATE_COST" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let create_cost := Constant.int 0 in M.pure Constant.None_ @@ -1910,6 +2313,47 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := let access_list_cost := Constant.int 0 in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + make_tuple [ M.get_name (| globals, "AccessListTransaction" |); M.get_name (| globals, "FeeMarketTransaction" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + For make_tuple [ M.get_name (| globals, "_address" |); M.get_name (| globals, "keys" |) ] in M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) do + let access_list_cost := BinOp.add + M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) + M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) in + let access_list_cost := BinOp.add + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "keys" |) + ], + make_dict [] + |), + M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) + |) + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "keys" |) + ], + make_dict [] + |), + M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) + |) in + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1929,6 +2373,7 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition recover_sender : Value.t -> Value.t -> M := @@ -2001,8 +2446,189 @@ Definition recover_sender : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "LegacyTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let v := + M.get_field (| M.get_name (| globals, "tx" |), "v" |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.eq (| + M.get_name (| globals, "v" |), + Constant.int 27 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "v" |), + Constant.int 28 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + BinOp.sub (| + M.get_name (| globals, "v" |), + Constant.int 27 + |); + M.call (| + M.get_name (| globals, "signing_hash_pre155" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.or (| + Compare.eq (| + M.get_name (| globals, "v" |), + BinOp.add (| + Constant.int 35, + BinOp.mult (| + M.get_name (| globals, "chain_id" |), + Constant.int 2 + |) + |) + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "v" |), + BinOp.add (| + Constant.int 36, + BinOp.mult (| + M.get_name (| globals, "chain_id" |), + Constant.int 2 + |) + |) + |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + BinOp.sub (| + BinOp.sub (| + M.get_name (| globals, "v" |), + Constant.int 35 + |), + BinOp.mult (| + M.get_name (| globals, "chain_id" |), + Constant.int 2 + |) + |); + M.call (| + M.get_name (| globals, "signing_hash_155" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "chain_id" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "AccessListTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + M.get_field (| M.get_name (| globals, "tx" |), "y_parity" |); + M.call (| + M.get_name (| globals, "signing_hash_2930" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "FeeMarketTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + M.get_field (| M.get_name (| globals, "tx" |), "y_parity" |); + M.call (| + M.get_name (| globals, "signing_hash_1559" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -2019,10 +2645,11 @@ Definition recover_sender : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12 |) + |), M.slice (| Constant.int 12, Constant.int 32 |) |) ], make_dict [] |) + |) in M.pure Constant.None_)). Definition signing_hash_pre155 : Value.t -> Value.t -> M := @@ -2055,6 +2682,7 @@ Definition signing_hash_pre155 : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition signing_hash_155 : Value.t -> Value.t -> M := @@ -2101,6 +2729,7 @@ Definition signing_hash_155 : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition signing_hash_2930 : Value.t -> Value.t -> M := @@ -2136,6 +2765,7 @@ Definition signing_hash_2930 : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition signing_hash_1559 : Value.t -> Value.t -> M := @@ -2171,6 +2801,7 @@ Definition signing_hash_1559 : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition compute_header_hash : Value.t -> Value.t -> M := @@ -2221,6 +2852,7 @@ Definition compute_header_hash : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition check_gas_limit : Value.t -> Value.t -> M := @@ -2259,16 +2891,65 @@ Definition check_gas_limit : Value.t -> Value.t -> M := M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "gas_limit" |), + BinOp.add (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "gas_limit" |), + BinOp.sub (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "gas_limit" |), + M.get_name (| globals, "GAS_LIMIT_MINIMUM" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| Constant.bool true + |) in M.pure Constant.None_)). Definition calculate_block_difficulty : Value.t -> Value.t -> M := @@ -2328,12 +3009,16 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := M.get_name (| globals, "max" |), make_list [ BinOp.sub (| - (* if *) -M.if_then_else (| - M.get_name (| globals, "parent_has_ommers" |), -(* then *) -ltac:(M.monadic ( -Constant.int 2, + (* if *) + M.if_then_else (| + M.get_name (| globals, "parent_has_ommers" |), + (* then *) + ltac:(M.monadic ( +Constant.int 2 + (* else *) + )), ltac:(M.monadic ( +Constant.int 1 + )) |), BinOp.floor_div (| M.call (| M.get_name (| globals, "int" |), @@ -2382,6 +3067,26 @@ Constant.int 2, Constant.int 2 |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "num_bomb_periods" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let difficulty := BinOp.add + BinOp.pow (| + Constant.int 2, + M.get_name (| globals, "num_bomb_periods" |) + |) + BinOp.pow (| + Constant.int 2, + M.get_name (| globals, "num_bomb_periods" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -2399,4 +3104,5 @@ Constant.int 2, ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/fork_types.v b/CoqOfPython/ethereum/london/fork_types.v index 5c7dac3..cc8e4a1 100644 --- a/CoqOfPython/ethereum/london/fork_types.v +++ b/CoqOfPython/ethereum/london/fork_types.v @@ -21,29 +21,29 @@ Require dataclasses. Axiom dataclasses_dataclass : IsGlobalAlias globals dataclasses.globals "dataclass". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes20 : - IsGlobalAlias globals base_types.globals "Bytes20". -Axiom base_types_Bytes256 : - IsGlobalAlias globals base_types.globals "Bytes256". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require crypto.hash. -Axiom crypto_hash_Hash32 : - IsGlobalAlias globals crypto.hash.globals "Hash32". -Axiom crypto_hash_keccak256 : - IsGlobalAlias globals crypto.hash.globals "keccak256". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes20 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes20". +Axiom ethereum_base_types_Bytes256 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) @@ -98,4 +98,5 @@ Definition encode_account : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/state.v b/CoqOfPython/ethereum/london/state.v index c3290a6..ce927a1 100644 --- a/CoqOfPython/ethereum/london/state.v +++ b/CoqOfPython/ethereum/london/state.v @@ -56,29 +56,29 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require fork_types. -Axiom fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". -Axiom fork_types_Account : - IsGlobalAlias globals fork_types.globals "Account". -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". - -Require trie. -Axiom trie_EMPTY_TRIE_ROOT : - IsGlobalAlias globals trie.globals "EMPTY_TRIE_ROOT". -Axiom trie_Trie : - IsGlobalAlias globals trie.globals "Trie". -Axiom trie_copy_trie : - IsGlobalAlias globals trie.globals "copy_trie". -Axiom trie_root : - IsGlobalAlias globals trie.globals "root". -Axiom trie_trie_get : - IsGlobalAlias globals trie.globals "trie_get". -Axiom trie_trie_set : - IsGlobalAlias globals trie.globals "trie_set". +Require ethereum.london.fork_types. +Axiom ethereum_london_fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals ethereum.london.fork_types.globals "EMPTY_ACCOUNT". +Axiom ethereum_london_fork_types_Account : + IsGlobalAlias globals ethereum.london.fork_types.globals "Account". +Axiom ethereum_london_fork_types_Address : + IsGlobalAlias globals ethereum.london.fork_types.globals "Address". +Axiom ethereum_london_fork_types_Root : + IsGlobalAlias globals ethereum.london.fork_types.globals "Root". + +Require ethereum.london.trie. +Axiom ethereum_london_trie_EMPTY_TRIE_ROOT : + IsGlobalAlias globals ethereum.london.trie.globals "EMPTY_TRIE_ROOT". +Axiom ethereum_london_trie_Trie : + IsGlobalAlias globals ethereum.london.trie.globals "Trie". +Axiom ethereum_london_trie_copy_trie : + IsGlobalAlias globals ethereum.london.trie.globals "copy_trie". +Axiom ethereum_london_trie_root : + IsGlobalAlias globals ethereum.london.trie.globals "root". +Axiom ethereum_london_trie_trie_get : + IsGlobalAlias globals ethereum.london.trie.globals "trie_get". +Axiom ethereum_london_trie_trie_set : + IsGlobalAlias globals ethereum.london.trie.globals "trie_set". Definition State : Value.t := builtins.make_klass @@ -126,7 +126,7 @@ Definition begin_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) ], make_dict [] - |); (* At expr: unsupported node type: DictComp *) ] + |); Constant.str "(* At expr: unsupported node type: DictComp *)" ] ], make_dict [] |) in @@ -149,6 +149,19 @@ Definition commit_transaction : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "clear" |), + make_list [], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -174,6 +187,19 @@ Definition rollback_transaction : Value.t -> Value.t -> M := |) |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "clear" |), + make_list [], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -210,8 +236,27 @@ Definition get_account : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "account" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "account" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_ACCOUNT" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -246,6 +291,7 @@ Definition get_account_optional : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "account" |) + |) in M.pure Constant.None_)). Definition set_account : Value.t -> Value.t -> M := @@ -325,6 +371,18 @@ Definition destroy_storage : Value.t -> Value.t -> M := Address of account whose storage is to be deleted. " in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -387,6 +445,26 @@ Definition get_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "trie" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let value := @@ -408,6 +486,7 @@ Definition get_storage : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "value" |) + |) in M.pure Constant.None_)). Definition set_storage : Value.t -> Value.t -> M := @@ -448,6 +527,27 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "trie" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let trie := + M.call (| + M.get_name (| globals, "Trie" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), + M.get_name (| globals, "trie" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -460,6 +560,18 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + {} + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -484,8 +596,29 @@ Definition storage_root : Value.t -> Value.t -> M := " in let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_TRIE_ROOT" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -516,6 +649,7 @@ Definition state_root : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition account_exists : Value.t -> Value.t -> M := @@ -548,6 +682,7 @@ Definition account_exists : Value.t -> Value.t -> M := |), Constant.None_ |) + |) in M.pure Constant.None_)). Definition account_has_code_or_nonce : Value.t -> Value.t -> M := @@ -597,6 +732,7 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition is_account_empty : Value.t -> Value.t -> M := @@ -654,6 +790,7 @@ Definition is_account_empty : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition account_exists_and_is_empty : Value.t -> Value.t -> M := @@ -720,6 +857,7 @@ Definition account_exists_and_is_empty : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition is_account_alive : Value.t -> Value.t -> M := @@ -750,6 +888,20 @@ Definition is_account_alive : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "account" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| UnOp.not (| BoolOp.and (| Compare.eq (| @@ -777,6 +929,7 @@ Definition is_account_alive : Value.t -> Value.t -> M := |) )) |) |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -884,6 +1037,30 @@ Definition touch_account : Value.t -> Value.t -> M := The address of the account that need to initialised. " in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "account_exists" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "EMPTY_ACCOUNT" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -988,6 +1165,26 @@ Definition get_storage_original : Value.t -> Value.t -> M := Key of the storage slot. " in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -1003,6 +1200,25 @@ Definition get_storage_original : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "original_account_trie" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let original_value := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let original_value := M.call (| M.get_name (| globals, "trie_get" |), @@ -1024,4 +1240,5 @@ Definition get_storage_original : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "original_value" |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/transactions.v b/CoqOfPython/ethereum/london/transactions.v index afa27ec..1e68477 100644 --- a/CoqOfPython/ethereum/london/transactions.v +++ b/CoqOfPython/ethereum/london/transactions.v @@ -19,33 +19,33 @@ Axiom typing_Tuple : Axiom typing_Union : IsGlobalAlias globals typing.globals "Union". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U64 : - IsGlobalAlias globals base_types.globals "U64". -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes0 : - IsGlobalAlias globals base_types.globals "Bytes0". -Axiom base_types_Bytes32 : - IsGlobalAlias globals base_types.globals "Bytes32". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require exceptions. -Axiom exceptions_InvalidBlock : - IsGlobalAlias globals exceptions.globals "InvalidBlock". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U64 : + IsGlobalAlias globals ethereum.base_types.globals "U64". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.exceptions. +Axiom ethereum_exceptions_InvalidBlock : + IsGlobalAlias globals ethereum.exceptions.globals "InvalidBlock". + +Require ethereum.london.fork_types. +Axiom ethereum_london_fork_types_Address : + IsGlobalAlias globals ethereum.london.fork_types.globals "Address". Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( Constant.int 21000 @@ -112,15 +112,87 @@ Definition encode_transaction : Value.t -> Value.t -> M := Encode a transaction. Needed because non-legacy transactions aren't RLP. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "LegacyTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "tx" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "AccessListTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + Constant.bytes "01", + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "FeeMarketTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + Constant.bytes "02", + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.raise (| Some(M.call (| M.get_name (| globals, "Exception" |), make_list [ - (* At expr: unsupported node type: JoinedStr *) + Constant.str "(* At expr: unsupported node type: JoinedStr *)" ], make_dict [] - |)) + |)) |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -136,8 +208,73 @@ Definition decode_transaction : Value.t -> Value.t -> M := Decode a transaction. Needed because non-legacy transactions aren't RLP. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), + Constant.int 1 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), + make_list [ + M.get_name (| globals, "AccessListTransaction" |); + M.get_subscript (| M.get_name (| globals, "tx" |), M.slice (| Constant.int 1, Constant.None_ |) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), + Constant.int 2 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), + make_list [ + M.get_name (| globals, "FeeMarketTransaction" |); + M.get_subscript (| M.get_name (| globals, "tx" |), M.slice (| Constant.int 1, Constant.None_ |) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidBlock" |)) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "tx" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/trie.v b/CoqOfPython/ethereum/london/trie.v index ad941ab..6bf9385 100644 --- a/CoqOfPython/ethereum/london/trie.v +++ b/CoqOfPython/ethereum/london/trie.v @@ -50,9 +50,9 @@ Axiom typing_Union : Axiom typing_cast : IsGlobalAlias globals typing.globals "cast". -Require ethereum.berlin. -Axiom ethereum_berlin_trie : - IsGlobalAlias globals ethereum.berlin.globals "trie". +Require ethereum.berlin.__init__. +Axiom ethereum_berlin___init___trie : + IsGlobalAlias globals ethereum.berlin.__init__.globals "trie". Require ethereum.crypto.hash. Axiom ethereum_crypto_hash_keccak256 : @@ -66,37 +66,37 @@ Require ethereum.utils.hexadecimal. Axiom ethereum_utils_hexadecimal_hex_to_bytes : IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require blocks. -Axiom blocks_Receipt : - IsGlobalAlias globals blocks.globals "Receipt". - -Require fork_types. -Axiom fork_types_Account : - IsGlobalAlias globals fork_types.globals "Account". -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". -Axiom fork_types_encode_account : - IsGlobalAlias globals fork_types.globals "encode_account". - -Require transactions. -Axiom transactions_LegacyTransaction : - IsGlobalAlias globals transactions.globals "LegacyTransaction". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.london.blocks. +Axiom ethereum_london_blocks_Receipt : + IsGlobalAlias globals ethereum.london.blocks.globals "Receipt". + +Require ethereum.london.fork_types. +Axiom ethereum_london_fork_types_Account : + IsGlobalAlias globals ethereum.london.fork_types.globals "Account". +Axiom ethereum_london_fork_types_Address : + IsGlobalAlias globals ethereum.london.fork_types.globals "Address". +Axiom ethereum_london_fork_types_Root : + IsGlobalAlias globals ethereum.london.fork_types.globals "Root". +Axiom ethereum_london_fork_types_encode_account : + IsGlobalAlias globals ethereum.london.fork_types.globals "encode_account". + +Require ethereum.london.transactions. +Axiom ethereum_london_transactions_LegacyTransaction : + IsGlobalAlias globals ethereum.london.transactions.globals "LegacyTransaction". Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -202,16 +202,99 @@ Definition encode_internal_node : Value.t -> Value.t -> M := " in (* At stmt: unsupported node type: AnnAssign *) let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "node" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + Constant.bytes "" in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "LeafNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "rest_of_key" |); + Constant.bool true + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "ExtensionNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "key_segment" |); + Constant.bool false + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "BranchNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + BinOp.add (| + M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "value" |) + ] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ - (* At expr: unsupported node type: JoinedStr *) + Constant.str "(* At expr: unsupported node type: JoinedStr *)" ], make_dict [] - |)) + |)) |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -229,6 +312,26 @@ Definition encode_internal_node : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded" |) + ], + make_dict [] + |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "unencoded" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_name (| globals, "keccak256" |), @@ -237,6 +340,7 @@ Definition encode_internal_node : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -250,8 +354,86 @@ Definition encode_node : Value.t -> Value.t -> M := Currently mostly an unimplemented stub. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| + M.get_name (| globals, "storage_root" |), + Constant.None_ + |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "encode_account" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "storage_root" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "U256" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "cast" |), + make_list [ + M.get_field (| M.get_name (| globals, "rlp" |), "RLP" |); + M.get_name (| globals, "node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "node" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "previous_trie" |), "encode_node" |), @@ -261,6 +443,7 @@ Definition encode_node : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -312,6 +495,7 @@ Definition copy_trie : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition trie_set : Value.t -> Value.t -> M := @@ -333,6 +517,32 @@ Definition trie_set : Value.t -> Value.t -> M := Node to insert at `key`. " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + M.get_field (| M.get_name (| globals, "trie" |), "default" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "key" |), + M.get_field (| M.get_name (| globals, "trie" |), "_data" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), M.get_name (| globals, "value" |) @@ -370,6 +580,7 @@ Definition trie_get : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition common_prefix_length : Value.t -> Value.t -> M := @@ -392,6 +603,34 @@ Definition common_prefix_length : Value.t -> Value.t -> M := make_dict [] |) do let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), + M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -403,6 +642,7 @@ Definition common_prefix_length : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition nibble_list_to_compact : Value.t -> Value.t -> M := @@ -448,6 +688,71 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + Constant.int 2 + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.mult (| + Constant.int 16, + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "is_leaf" |) + |) + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ @@ -509,6 +814,7 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition bytes_to_nibble_list : Value.t -> Value.t -> M := @@ -586,6 +892,7 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition _prepare_trie : Value.t -> Value.t -> M := @@ -615,6 +922,48 @@ Definition _prepare_trie : Value.t -> Value.t -> M := make_dict [] |) do let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| + M.get_name (| globals, "get_storage_root" |), + Constant.None_ + |) |) in + let address := + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |); + M.call (| + M.get_name (| globals, "get_storage_root" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let encoded_value := M.call (| M.get_name (| globals, "encode_node" |), @@ -638,6 +987,22 @@ Definition _prepare_trie : Value.t -> Value.t -> M := |) in (* At stmt: unsupported node type: AnnAssign *) let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "trie" |), "secured" |), + (* then *) + ltac:(M.monadic ( + let key := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let key := M.get_name (| globals, "preimage" |) in M.pure Constant.None_ @@ -655,6 +1020,7 @@ Definition _prepare_trie : Value.t -> Value.t -> M := EndFor. let _ := M.return_ (| M.get_name (| globals, "mapped" |) + |) in M.pure Constant.None_)). Definition root : Value.t -> Value.t -> M := @@ -708,6 +1074,44 @@ Definition root : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -724,6 +1128,7 @@ Definition root : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -750,6 +1155,26 @@ Definition patricialize : Value.t -> Value.t -> M := Root node of `obj`. " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let arbitrary_key := @@ -767,10 +1192,39 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), + Constant.int 1 + |), + (* then *) + ltac:(M.monadic ( + let leaf := + M.call (| + M.get_name (| globals, "LeafNode" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |); + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "leaf" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let substring := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |) |) in + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) in let prefix_length := M.call (| M.get_name (| globals, "len" |), @@ -789,7 +1243,7 @@ Definition patricialize : Value.t -> Value.t -> M := M.get_name (| globals, "common_prefix_length" |), make_list [ M.get_name (| globals, "substring" |); - M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) + M.get_subscript (| M.get_name (| globals, "key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) ], make_dict [] |) @@ -797,10 +1251,64 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "prefix_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "prefix_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let prefix := + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ExtensionNode" |), + make_list [ + M.get_name (| globals, "prefix" |); + M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_name (| globals, "obj" |); + BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) @@ -823,6 +1331,44 @@ Definition patricialize : Value.t -> Value.t -> M := Constant.bytes "" in For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |), + M.get_name (| globals, "level" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "AssertionError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) @@ -834,9 +1380,10 @@ Definition patricialize : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "BranchNode" |), make_list [ - (* At expr: unsupported node type: ListComp *); + Constant.str "(* At expr: unsupported node type: ListComp *)"; M.get_name (| globals, "value" |) ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/utils/address.v b/CoqOfPython/ethereum/london/utils/address.v index 2389981..4affa6d 100644 --- a/CoqOfPython/ethereum/london/utils/address.v +++ b/CoqOfPython/ethereum/london/utils/address.v @@ -38,13 +38,13 @@ Require ethereum.utils.byte. Axiom ethereum_utils_byte_left_pad_zero_bytes : IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.london.fork_types. +Axiom ethereum_london_fork_types_Address : + IsGlobalAlias globals ethereum.london.fork_types.globals "Address". Definition to_address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -70,10 +70,11 @@ Definition to_address : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), make_list [], make_dict [] - |), UnOp.sub (| Constant.int 20 |) |) + |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) ], make_dict [] |) + |) in M.pure Constant.None_)). Definition compute_contract_address : Value.t -> Value.t -> M := @@ -113,7 +114,7 @@ Definition compute_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -131,6 +132,7 @@ Definition compute_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition compute_create2_contract_address : Value.t -> Value.t -> M := @@ -180,7 +182,7 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -198,4 +200,5 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/utils/hexadecimal.v b/CoqOfPython/ethereum/london/utils/hexadecimal.v index 2681b61..0798912 100644 --- a/CoqOfPython/ethereum/london/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/london/utils/hexadecimal.v @@ -22,13 +22,13 @@ Require ethereum.utils.hexadecimal. Axiom ethereum_utils_hexadecimal_remove_hex_prefix : IsGlobalAlias globals ethereum.utils.hexadecimal.globals "remove_hex_prefix". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". +Require ethereum.london.fork_types. +Axiom ethereum_london_fork_types_Address : + IsGlobalAlias globals ethereum.london.fork_types.globals "Address". +Axiom ethereum_london_fork_types_Bloom : + IsGlobalAlias globals ethereum.london.fork_types.globals "Bloom". +Axiom ethereum_london_fork_types_Root : + IsGlobalAlias globals ethereum.london.fork_types.globals "Root". Definition hex_to_root : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -66,6 +66,7 @@ Definition hex_to_root : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition hex_to_bloom : Value.t -> Value.t -> M := @@ -104,6 +105,7 @@ Definition hex_to_bloom : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition hex_to_address : Value.t -> Value.t -> M := @@ -149,4 +151,5 @@ Definition hex_to_address : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/utils/message.v b/CoqOfPython/ethereum/london/utils/message.v index 3688c04..0570427 100644 --- a/CoqOfPython/ethereum/london/utils/message.v +++ b/CoqOfPython/ethereum/london/utils/message.v @@ -40,27 +40,27 @@ Axiom ethereum_base_types_Bytes32 : Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.london.fork_types. +Axiom ethereum_london_fork_types_Address : + IsGlobalAlias globals ethereum.london.fork_types.globals "Address". -Require state. -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". +Require ethereum.london.state. +Axiom ethereum_london_state_get_account : + IsGlobalAlias globals ethereum.london.state.globals "get_account". -Require vm. -Axiom vm_Environment : - IsGlobalAlias globals vm.globals "Environment". -Axiom vm_Message : - IsGlobalAlias globals vm.globals "Message". +Require ethereum.london.vm.__init__. +Axiom ethereum_london_vm___init___Environment : + IsGlobalAlias globals ethereum.london.vm.__init__.globals "Environment". +Axiom ethereum_london_vm___init___Message : + IsGlobalAlias globals ethereum.london.vm.__init__.globals "Message". -Require vm.precompiled_contracts.mapping. -Axiom vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : - IsGlobalAlias globals vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". +Require ethereum.london.vm.precompiled_contracts.mapping. +Axiom ethereum_london_vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : + IsGlobalAlias globals ethereum.london.vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". -Require address. -Axiom address_compute_contract_address : - IsGlobalAlias globals address.globals "compute_contract_address". +Require ethereum.london.utils.address. +Axiom ethereum_london_utils_address_compute_contract_address : + IsGlobalAlias globals ethereum.london.utils.address.globals "compute_contract_address". Definition prepare_message : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -103,14 +103,108 @@ Definition prepare_message : Value.t -> Value.t -> M := Items containing contract creation or message call specific data. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Bytes0" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.call (| + M.get_name (| globals, "compute_contract_address" |), + make_list [ + M.get_name (| globals, "caller" |); + BinOp.sub (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "caller" |) + ], + make_dict [] + |), "nonce" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let msg_data := + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) in + let code := + M.get_name (| globals, "data" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.get_name (| globals, "target" |) in + let msg_data := + M.get_name (| globals, "data" |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "target" |) + ], + make_dict [] + |), "code" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "code_address" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let code_address := + M.get_name (| globals, "target" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "Target must be address or empty bytes" ], make_dict [] - |)) + |)) |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -159,4 +253,5 @@ Definition prepare_message : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/vm/__init__.v b/CoqOfPython/ethereum/london/vm/__init__.v index 49da5ae..57f8791 100644 --- a/CoqOfPython/ethereum/london/vm/__init__.v +++ b/CoqOfPython/ethereum/london/vm/__init__.v @@ -52,23 +52,23 @@ Require ethereum.crypto.hash. Axiom ethereum_crypto_hash_Hash32 : IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". +Require ethereum.london.blocks. +Axiom ethereum_london_blocks_Log : + IsGlobalAlias globals ethereum.london.blocks.globals "Log". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.london.fork_types. +Axiom ethereum_london_fork_types_Address : + IsGlobalAlias globals ethereum.london.fork_types.globals "Address". -Require state. -Axiom state_State : - IsGlobalAlias globals state.globals "State". -Axiom state_account_exists_and_is_empty : - IsGlobalAlias globals state.globals "account_exists_and_is_empty". +Require ethereum.london.state. +Axiom ethereum_london_state_State : + IsGlobalAlias globals ethereum.london.state.globals "State". +Axiom ethereum_london_state_account_exists_and_is_empty : + IsGlobalAlias globals ethereum.london.state.globals "account_exists_and_is_empty". -Require precompiled_contracts. -Axiom precompiled_contracts_RIPEMD160_ADDRESS : - IsGlobalAlias globals precompiled_contracts.globals "RIPEMD160_ADDRESS". +Require ethereum.london.vm.precompiled_contracts.__init__. +Axiom ethereum_london_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : + IsGlobalAlias globals ethereum.london.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] @@ -147,6 +147,28 @@ Definition incorporate_child_on_success : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -179,9 +201,63 @@ Definition incorporate_child_on_error : Value.t -> Value.t -> M := The child evm to incorporate. " in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "RIPEMD160_ADDRESS" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |), + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign_op (| diff --git a/CoqOfPython/ethereum/london/vm/gas.v b/CoqOfPython/ethereum/london/vm/gas.v index 549060b..da5f5b4 100644 --- a/CoqOfPython/ethereum/london/vm/gas.v +++ b/CoqOfPython/ethereum/london/vm/gas.v @@ -43,13 +43,13 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.london.vm.__init__. +Axiom ethereum_london_vm___init___Evm : + IsGlobalAlias globals ethereum.london.vm.__init__.globals "Evm". -Require exceptions. -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". +Require ethereum.london.vm.exceptions. +Axiom ethereum_london_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.london.vm.exceptions.globals "OutOfGasError". Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -500,6 +500,18 @@ Definition charge_gas : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "amount" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign_op (| BinOp.sub, M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), @@ -615,6 +627,18 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := |) in For make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ] in M.get_name (| globals, "extensions" |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "size" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let before_size := @@ -649,6 +673,18 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let size_to_extend := BinOp.add @@ -697,6 +733,7 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition calculate_message_call_gas : Value.t -> Value.t -> M := @@ -728,22 +765,56 @@ Definition calculate_message_call_gas : Value.t -> Value.t -> M := message_call_gas: `MessageCallGas` " in let call_stipend := - (* if *) -M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "call_stipend" |) + )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "gas_left" |), + BinOp.add (| + M.get_name (| globals, "extra_gas" |), + M.get_name (| globals, "memory_cost" |) + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallGas" |), + make_list [ + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "extra_gas" |) + |); + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "call_stipend" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let gas := @@ -782,6 +853,7 @@ M.call (| ], make_dict [] |) + |) in M.pure Constant.None_)). Definition max_message_call_gas : Value.t -> Value.t -> M := @@ -808,4 +880,5 @@ Definition max_message_call_gas : Value.t -> Value.t -> M := Constant.int 64 |) |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/vm/instructions/__init__.v b/CoqOfPython/ethereum/london/vm/instructions/__init__.v index e5bebd7..a7f4e82 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/__init__.v +++ b/CoqOfPython/ethereum/london/vm/instructions/__init__.v @@ -26,53 +26,53 @@ Axiom typing_Callable : Axiom typing_Dict : IsGlobalAlias globals typing.globals "Dict". -Require __init__. -Axiom __init___arithmetic : - IsGlobalAlias globals __init__.globals "arithmetic". +Require ethereum.london.vm.instructions.__init__. +Axiom ethereum_london_vm_instructions___init___arithmetic : + IsGlobalAlias globals ethereum.london.vm.instructions.__init__.globals "arithmetic". -Require __init__. -Axiom __init___bitwise : - IsGlobalAlias globals __init__.globals "bitwise". +Require ethereum.london.vm.instructions.__init__. +Axiom ethereum_london_vm_instructions___init___bitwise : + IsGlobalAlias globals ethereum.london.vm.instructions.__init__.globals "bitwise". -Require __init__. -Axiom __init___block : - IsGlobalAlias globals __init__.globals "block". +Require ethereum.london.vm.instructions.__init__. +Axiom ethereum_london_vm_instructions___init___block : + IsGlobalAlias globals ethereum.london.vm.instructions.__init__.globals "block". -Require __init__. -Axiom __init___comparison : - IsGlobalAlias globals __init__.globals "comparison". +Require ethereum.london.vm.instructions.__init__. +Axiom ethereum_london_vm_instructions___init___comparison : + IsGlobalAlias globals ethereum.london.vm.instructions.__init__.globals "comparison". -Require __init__. -Axiom __init___control_flow : - IsGlobalAlias globals __init__.globals "control_flow". +Require ethereum.london.vm.instructions.__init__. +Axiom ethereum_london_vm_instructions___init___control_flow : + IsGlobalAlias globals ethereum.london.vm.instructions.__init__.globals "control_flow". -Require __init__. -Axiom __init___environment : - IsGlobalAlias globals __init__.globals "environment". +Require ethereum.london.vm.instructions.__init__. +Axiom ethereum_london_vm_instructions___init___environment : + IsGlobalAlias globals ethereum.london.vm.instructions.__init__.globals "environment". -Require __init__. -Axiom __init___keccak : - IsGlobalAlias globals __init__.globals "keccak". +Require ethereum.london.vm.instructions.__init__. +Axiom ethereum_london_vm_instructions___init___keccak : + IsGlobalAlias globals ethereum.london.vm.instructions.__init__.globals "keccak". -Require __init__. -Axiom __init___log : - IsGlobalAlias globals __init__.globals "log". +Require ethereum.london.vm.instructions.__init__. +Axiom ethereum_london_vm_instructions___init___log : + IsGlobalAlias globals ethereum.london.vm.instructions.__init__.globals "log". -Require __init__. -Axiom __init___memory : - IsGlobalAlias globals __init__.globals "memory". +Require ethereum.london.vm.instructions.__init__. +Axiom ethereum_london_vm_instructions___init___memory : + IsGlobalAlias globals ethereum.london.vm.instructions.__init__.globals "memory". -Require __init__. -Axiom __init___stack : - IsGlobalAlias globals __init__.globals "stack". +Require ethereum.london.vm.instructions.__init__. +Axiom ethereum_london_vm_instructions___init___stack : + IsGlobalAlias globals ethereum.london.vm.instructions.__init__.globals "stack". -Require __init__. -Axiom __init___storage : - IsGlobalAlias globals __init__.globals "storage". +Require ethereum.london.vm.instructions.__init__. +Axiom ethereum_london_vm_instructions___init___storage : + IsGlobalAlias globals ethereum.london.vm.instructions.__init__.globals "storage". -Require __init__. -Axiom __init___system : - IsGlobalAlias globals __init__.globals "system". +Require ethereum.london.vm.instructions.__init__. +Axiom ethereum_london_vm_instructions___init___system : + IsGlobalAlias globals ethereum.london.vm.instructions.__init__.globals "system". Definition Ops : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/london/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/london/vm/instructions/arithmetic.v index 581ba5d..73a3005 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/london/vm/instructions/arithmetic.v @@ -31,29 +31,29 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_get_sign : IsGlobalAlias globals ethereum.utils.numeric.globals "get_sign". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_EXPONENTIATION : - IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION". -Axiom gas_GAS_EXPONENTIATION_PER_BYTE : - IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION_PER_BYTE". -Axiom gas_GAS_LOW : - IsGlobalAlias globals gas.globals "GAS_LOW". -Axiom gas_GAS_MID : - IsGlobalAlias globals gas.globals "GAS_MID". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.london.vm.__init__. +Axiom ethereum_london_vm___init___Evm : + IsGlobalAlias globals ethereum.london.vm.__init__.globals "Evm". + +Require ethereum.london.vm.gas. +Axiom ethereum_london_vm_gas_GAS_EXPONENTIATION : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_EXPONENTIATION". +Axiom ethereum_london_vm_gas_GAS_EXPONENTIATION_PER_BYTE : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_EXPONENTIATION_PER_BYTE". +Axiom ethereum_london_vm_gas_GAS_LOW : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_LOW". +Axiom ethereum_london_vm_gas_GAS_MID : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_MID". +Axiom ethereum_london_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_london_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.london.vm.gas.globals "charge_gas". + +Require ethereum.london.vm.stack. +Axiom ethereum_london_vm_stack_pop : + IsGlobalAlias globals ethereum.london.vm.stack.globals "pop". +Axiom ethereum_london_vm_stack_push : + IsGlobalAlias globals ethereum.london.vm.stack.globals "push". Definition add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -273,6 +273,25 @@ Definition div : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "divisor" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let quotient := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let quotient := BinOp.floor_div (| M.get_name (| globals, "dividend" |), @@ -341,7 +360,41 @@ Definition sdiv : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "divisor" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let quotient := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_name (| globals, "dividend" |), + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "divisor" |), + UnOp.sub (| Constant.int 1 |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let quotient := + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let sign := M.call (| M.get_name (| globals, "get_sign" |), @@ -436,6 +489,25 @@ Definition mod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "y" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let remainder := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let remainder := BinOp.mod_ (| M.get_name (| globals, "x" |), @@ -504,6 +576,19 @@ Definition smod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "y" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let remainder := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let remainder := BinOp.mult (| M.call (| @@ -617,6 +702,25 @@ Definition addmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "z" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -712,6 +816,25 @@ Definition mulmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "z" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -881,6 +1004,19 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "byte_num" |), + Constant.int 31 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.get_name (| globals, "value" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let value_bytes := M.call (| M.get_name (| globals, "bytes" |), @@ -894,7 +1030,7 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let value_bytes := - M.get_subscript (| M.get_name (| globals, "value_bytes" |), BinOp.sub (| + M.get_subscript (| M.get_name (| globals, "value_bytes" |), M.slice (| BinOp.sub (| Constant.int 31, M.call (| M.get_name (| globals, "int" |), @@ -903,13 +1039,32 @@ Definition signextend : Value.t -> Value.t -> M := ], make_dict [] |) - |) |) in + |), Constant.None_ |) |) in let sign_bit := BinOp.r_shift (| M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), Constant.int 7 |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "sign_bit" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "value_bytes" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let num_bytes_prepend := BinOp.sub (| Constant.int 32, diff --git a/CoqOfPython/ethereum/london/vm/instructions/bitwise.v b/CoqOfPython/ethereum/london/vm/instructions/bitwise.v index 64cf120..867a104 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/london/vm/instructions/bitwise.v @@ -23,21 +23,21 @@ Axiom ethereum_base_types_U256 : Axiom ethereum_base_types_U256_CEIL_VALUE : IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.london.vm.__init__. +Axiom ethereum_london_vm___init___Evm : + IsGlobalAlias globals ethereum.london.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.london.vm.gas. +Axiom ethereum_london_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_london_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.london.vm.gas.globals "charge_gas". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.london.vm.stack. +Axiom ethereum_london_vm_stack_pop : + IsGlobalAlias globals ethereum.london.vm.stack.globals "pop". +Axiom ethereum_london_vm_stack_push : + IsGlobalAlias globals ethereum.london.vm.stack.globals "push". Definition bitwise_and : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -287,6 +287,25 @@ Definition get_byte : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "byte_index" |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let extra_bytes_to_right := BinOp.sub (| Constant.int 31, @@ -366,6 +385,31 @@ Definition bitwise_shl : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "shift" |), + Constant.int 256 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.l_shift (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "shift" |) + |), + M.get_name (| globals, "U256_CEIL_VALUE" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -427,6 +471,22 @@ Definition bitwise_shr : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "shift" |), + Constant.int 256 + |), + (* then *) + ltac:(M.monadic ( + let result := + BinOp.r_shift (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "shift" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -492,7 +552,48 @@ Definition bitwise_sar : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "shift" |), + Constant.int 256 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + BinOp.r_shift (| + M.get_name (| globals, "signed_value" |), + M.get_name (| globals, "shift" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "signed_value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/london/vm/instructions/block.v b/CoqOfPython/ethereum/london/vm/instructions/block.v index f857b79..b3ed746 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/block.v +++ b/CoqOfPython/ethereum/london/vm/instructions/block.v @@ -21,23 +21,23 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_BLOCK_HASH : - IsGlobalAlias globals gas.globals "GAS_BLOCK_HASH". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.london.vm.__init__. +Axiom ethereum_london_vm___init___Evm : + IsGlobalAlias globals ethereum.london.vm.__init__.globals "Evm". + +Require ethereum.london.vm.gas. +Axiom ethereum_london_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_BASE". +Axiom ethereum_london_vm_gas_GAS_BLOCK_HASH : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_BLOCK_HASH". +Axiom ethereum_london_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.london.vm.gas.globals "charge_gas". + +Require ethereum.london.vm.stack. +Axiom ethereum_london_vm_stack_pop : + IsGlobalAlias globals ethereum.london.vm.stack.globals "pop". +Axiom ethereum_london_vm_stack_push : + IsGlobalAlias globals ethereum.london.vm.stack.globals "push". Definition block_hash : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -69,6 +69,30 @@ Definition block_hash : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt_e (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + M.get_name (| globals, "block_number" |) + |), + ltac:(M.monadic ( + Compare.gt (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + BinOp.add (| + M.get_name (| globals, "block_number" |), + Constant.int 256 + |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let hash := + Constant.bytes "00" in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let hash := M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), diff --git a/CoqOfPython/ethereum/london/vm/instructions/comparison.v b/CoqOfPython/ethereum/london/vm/instructions/comparison.v index b8529d8..5eb7b4e 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/london/vm/instructions/comparison.v @@ -21,21 +21,21 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.london.vm.__init__. +Axiom ethereum_london_vm___init___Evm : + IsGlobalAlias globals ethereum.london.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.london.vm.gas. +Axiom ethereum_london_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_london_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.london.vm.gas.globals "charge_gas". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.london.vm.stack. +Axiom ethereum_london_vm_stack_pop : + IsGlobalAlias globals ethereum.london.vm.stack.globals "pop". +Axiom ethereum_london_vm_stack_push : + IsGlobalAlias globals ethereum.london.vm.stack.globals "push". Definition less_than : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/london/vm/instructions/control_flow.v b/CoqOfPython/ethereum/london/vm/instructions/control_flow.v index d4e4eae..5996ffc 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/london/vm/instructions/control_flow.v @@ -23,31 +23,31 @@ Axiom ethereum_base_types_U256 : Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require vm.gas. -Axiom vm_gas_GAS_BASE : - IsGlobalAlias globals vm.gas.globals "GAS_BASE". -Axiom vm_gas_GAS_HIGH : - IsGlobalAlias globals vm.gas.globals "GAS_HIGH". -Axiom vm_gas_GAS_JUMPDEST : - IsGlobalAlias globals vm.gas.globals "GAS_JUMPDEST". -Axiom vm_gas_GAS_MID : - IsGlobalAlias globals vm.gas.globals "GAS_MID". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.london.vm.gas. +Axiom ethereum_london_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_BASE". +Axiom ethereum_london_vm_gas_GAS_HIGH : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_HIGH". +Axiom ethereum_london_vm_gas_GAS_JUMPDEST : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_JUMPDEST". +Axiom ethereum_london_vm_gas_GAS_MID : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_MID". +Axiom ethereum_london_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.london.vm.gas.globals "charge_gas". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.london.vm.__init__. +Axiom ethereum_london_vm___init___Evm : + IsGlobalAlias globals ethereum.london.vm.__init__.globals "Evm". -Require exceptions. -Axiom exceptions_InvalidJumpDestError : - IsGlobalAlias globals exceptions.globals "InvalidJumpDestError". +Require ethereum.london.vm.exceptions. +Axiom ethereum_london_vm_exceptions_InvalidJumpDestError : + IsGlobalAlias globals ethereum.london.vm.exceptions.globals "InvalidJumpDestError". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.london.vm.stack. +Axiom ethereum_london_vm_stack_pop : + IsGlobalAlias globals ethereum.london.vm.stack.globals "pop". +Axiom ethereum_london_vm_stack_push : + IsGlobalAlias globals ethereum.london.vm.stack.globals "push". Definition stop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -109,6 +109,18 @@ Definition jump : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "jump_dest" |), + M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -168,7 +180,35 @@ Definition jumpi : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "conditional_value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let destination := + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "jump_dest" |), + M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let destination := M.get_name (| globals, "jump_dest" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/london/vm/instructions/environment.v b/CoqOfPython/ethereum/london/vm/instructions/environment.v index 10bc05b..d570179 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/london/vm/instructions/environment.v @@ -35,57 +35,57 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require fork_types. -Axiom fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". - -Require state. -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". - -Require utils.address. -Axiom utils_address_to_address : - IsGlobalAlias globals utils.address.globals "to_address". - -Require vm.memory. -Axiom vm_memory_buffer_read : - IsGlobalAlias globals vm.memory.globals "buffer_read". -Axiom vm_memory_memory_write : - IsGlobalAlias globals vm.memory.globals "memory_write". - -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require exceptions. -Axiom exceptions_OutOfBoundsRead : - IsGlobalAlias globals exceptions.globals "OutOfBoundsRead". - -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_COLD_ACCOUNT_ACCESS : - IsGlobalAlias globals gas.globals "GAS_COLD_ACCOUNT_ACCESS". -Axiom gas_GAS_COPY : - IsGlobalAlias globals gas.globals "GAS_COPY". -Axiom gas_GAS_FAST_STEP : - IsGlobalAlias globals gas.globals "GAS_FAST_STEP". -Axiom gas_GAS_RETURN_DATA_COPY : - IsGlobalAlias globals gas.globals "GAS_RETURN_DATA_COPY". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_GAS_WARM_ACCESS : - IsGlobalAlias globals gas.globals "GAS_WARM_ACCESS". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.london.fork_types. +Axiom ethereum_london_fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals ethereum.london.fork_types.globals "EMPTY_ACCOUNT". + +Require ethereum.london.state. +Axiom ethereum_london_state_get_account : + IsGlobalAlias globals ethereum.london.state.globals "get_account". + +Require ethereum.london.utils.address. +Axiom ethereum_london_utils_address_to_address : + IsGlobalAlias globals ethereum.london.utils.address.globals "to_address". + +Require ethereum.london.vm.memory. +Axiom ethereum_london_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.london.vm.memory.globals "buffer_read". +Axiom ethereum_london_vm_memory_memory_write : + IsGlobalAlias globals ethereum.london.vm.memory.globals "memory_write". + +Require ethereum.london.vm.__init__. +Axiom ethereum_london_vm___init___Evm : + IsGlobalAlias globals ethereum.london.vm.__init__.globals "Evm". + +Require ethereum.london.vm.exceptions. +Axiom ethereum_london_vm_exceptions_OutOfBoundsRead : + IsGlobalAlias globals ethereum.london.vm.exceptions.globals "OutOfBoundsRead". + +Require ethereum.london.vm.gas. +Axiom ethereum_london_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_BASE". +Axiom ethereum_london_vm_gas_GAS_COLD_ACCOUNT_ACCESS : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_COLD_ACCOUNT_ACCESS". +Axiom ethereum_london_vm_gas_GAS_COPY : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_COPY". +Axiom ethereum_london_vm_gas_GAS_FAST_STEP : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_FAST_STEP". +Axiom ethereum_london_vm_gas_GAS_RETURN_DATA_COPY : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_RETURN_DATA_COPY". +Axiom ethereum_london_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_london_vm_gas_GAS_WARM_ACCESS : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_WARM_ACCESS". +Axiom ethereum_london_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.london.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_london_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.london.vm.gas.globals "charge_gas". + +Require ethereum.london.vm.stack. +Axiom ethereum_london_vm_stack_pop : + IsGlobalAlias globals ethereum.london.vm.stack.globals "pop". +Axiom ethereum_london_vm_stack_push : + IsGlobalAlias globals ethereum.london.vm.stack.globals "push". Definition address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -156,6 +156,25 @@ Definition balance : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -789,6 +808,25 @@ Definition extcodesize : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -926,6 +964,31 @@ Definition extcodecopy : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_WARM_ACCESS" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1162,7 +1225,10 @@ Definition returndatacopy : Value.t -> Value.t -> M := |) |) in let value := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |) |) in + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.slice (| M.get_name (| globals, "return_data_start_position" |), BinOp.add (| + M.get_name (| globals, "return_data_start_position" |), + M.get_name (| globals, "size" |) + |) |) |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -1204,6 +1270,25 @@ Definition extcodehash : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1231,6 +1316,25 @@ Definition extcodehash : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "account" |), + M.get_name (| globals, "EMPTY_ACCOUNT" |) + |), + (* then *) + ltac:(M.monadic ( + let codehash := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let codehash := M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), diff --git a/CoqOfPython/ethereum/london/vm/instructions/keccak.v b/CoqOfPython/ethereum/london/vm/instructions/keccak.v index 2c4b10e..7fd6db8 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/london/vm/instructions/keccak.v @@ -31,29 +31,29 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_KECCAK256 : - IsGlobalAlias globals gas.globals "GAS_KECCAK256". -Axiom gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.london.vm.__init__. +Axiom ethereum_london_vm___init___Evm : + IsGlobalAlias globals ethereum.london.vm.__init__.globals "Evm". + +Require ethereum.london.vm.gas. +Axiom ethereum_london_vm_gas_GAS_KECCAK256 : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_KECCAK256". +Axiom ethereum_london_vm_gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_KECCAK256_WORD". +Axiom ethereum_london_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.london.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_london_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.london.vm.gas.globals "charge_gas". + +Require ethereum.london.vm.memory. +Axiom ethereum_london_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.london.vm.memory.globals "memory_read_bytes". + +Require ethereum.london.vm.stack. +Axiom ethereum_london_vm_stack_pop : + IsGlobalAlias globals ethereum.london.vm.stack.globals "pop". +Axiom ethereum_london_vm_stack_push : + IsGlobalAlias globals ethereum.london.vm.stack.globals "push". Definition keccak : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/london/vm/instructions/log.v b/CoqOfPython/ethereum/london/vm/instructions/log.v index e084e59..70e1f3d 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/log.v +++ b/CoqOfPython/ethereum/london/vm/instructions/log.v @@ -29,37 +29,37 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". - -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require exceptions. -Axiom exceptions_WriteInStaticContext : - IsGlobalAlias globals exceptions.globals "WriteInStaticContext". - -Require gas. -Axiom gas_GAS_LOG : - IsGlobalAlias globals gas.globals "GAS_LOG". -Axiom gas_GAS_LOG_DATA : - IsGlobalAlias globals gas.globals "GAS_LOG_DATA". -Axiom gas_GAS_LOG_TOPIC : - IsGlobalAlias globals gas.globals "GAS_LOG_TOPIC". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". +Require ethereum.london.blocks. +Axiom ethereum_london_blocks_Log : + IsGlobalAlias globals ethereum.london.blocks.globals "Log". + +Require ethereum.london.vm.__init__. +Axiom ethereum_london_vm___init___Evm : + IsGlobalAlias globals ethereum.london.vm.__init__.globals "Evm". + +Require ethereum.london.vm.exceptions. +Axiom ethereum_london_vm_exceptions_WriteInStaticContext : + IsGlobalAlias globals ethereum.london.vm.exceptions.globals "WriteInStaticContext". + +Require ethereum.london.vm.gas. +Axiom ethereum_london_vm_gas_GAS_LOG : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_LOG". +Axiom ethereum_london_vm_gas_GAS_LOG_DATA : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_LOG_DATA". +Axiom ethereum_london_vm_gas_GAS_LOG_TOPIC : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_LOG_TOPIC". +Axiom ethereum_london_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.london.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_london_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.london.vm.gas.globals "charge_gas". + +Require ethereum.london.vm.memory. +Axiom ethereum_london_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.london.vm.memory.globals "memory_read_bytes". + +Require ethereum.london.vm.stack. +Axiom ethereum_london_vm_stack_pop : + IsGlobalAlias globals ethereum.london.vm.stack.globals "pop". Definition log_n : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/london/vm/instructions/memory.v b/CoqOfPython/ethereum/london/vm/instructions/memory.v index 86ba742..e508c08 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/london/vm/instructions/memory.v @@ -23,31 +23,31 @@ Axiom ethereum_base_types_U256 : Axiom ethereum_base_types_Bytes : IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.london.vm.__init__. +Axiom ethereum_london_vm___init___Evm : + IsGlobalAlias globals ethereum.london.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.london.vm.gas. +Axiom ethereum_london_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_BASE". +Axiom ethereum_london_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_london_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.london.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_london_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.london.vm.gas.globals "charge_gas". -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". -Axiom memory_memory_write : - IsGlobalAlias globals memory.globals "memory_write". +Require ethereum.london.vm.memory. +Axiom ethereum_london_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.london.vm.memory.globals "memory_read_bytes". +Axiom ethereum_london_vm_memory_memory_write : + IsGlobalAlias globals ethereum.london.vm.memory.globals "memory_write". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.london.vm.stack. +Axiom ethereum_london_vm_stack_pop : + IsGlobalAlias globals ethereum.london.vm.stack.globals "pop". +Axiom ethereum_london_vm_stack_push : + IsGlobalAlias globals ethereum.london.vm.stack.globals "push". Definition mstore : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/london/vm/instructions/stack.v b/CoqOfPython/ethereum/london/vm/instructions/stack.v index 305af15..ac9633a 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/london/vm/instructions/stack.v @@ -29,27 +29,27 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". -Axiom __init___stack : - IsGlobalAlias globals __init__.globals "stack". - -Require exceptions. -Axiom exceptions_StackUnderflowError : - IsGlobalAlias globals exceptions.globals "StackUnderflowError". - -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require memory. -Axiom memory_buffer_read : - IsGlobalAlias globals memory.globals "buffer_read". +Require ethereum.london.vm.__init__. +Axiom ethereum_london_vm___init___Evm : + IsGlobalAlias globals ethereum.london.vm.__init__.globals "Evm". +Axiom ethereum_london_vm___init___stack : + IsGlobalAlias globals ethereum.london.vm.__init__.globals "stack". + +Require ethereum.london.vm.exceptions. +Axiom ethereum_london_vm_exceptions_StackUnderflowError : + IsGlobalAlias globals ethereum.london.vm.exceptions.globals "StackUnderflowError". + +Require ethereum.london.vm.gas. +Axiom ethereum_london_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_BASE". +Axiom ethereum_london_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_london_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.london.vm.gas.globals "charge_gas". + +Require ethereum.london.vm.memory. +Axiom ethereum_london_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.london.vm.memory.globals "buffer_read". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/london/vm/instructions/storage.v b/CoqOfPython/ethereum/london/vm/instructions/storage.v index b3c4045..8cfa118 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/london/vm/instructions/storage.v @@ -25,45 +25,45 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require state. -Axiom state_get_storage : - IsGlobalAlias globals state.globals "get_storage". -Axiom state_get_storage_original : - IsGlobalAlias globals state.globals "get_storage_original". -Axiom state_set_storage : - IsGlobalAlias globals state.globals "set_storage". - -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require exceptions. -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". -Axiom exceptions_WriteInStaticContext : - IsGlobalAlias globals exceptions.globals "WriteInStaticContext". - -Require gas. -Axiom gas_GAS_CALL_STIPEND : - IsGlobalAlias globals gas.globals "GAS_CALL_STIPEND". -Axiom gas_GAS_COLD_SLOAD : - IsGlobalAlias globals gas.globals "GAS_COLD_SLOAD". -Axiom gas_GAS_STORAGE_CLEAR_REFUND : - IsGlobalAlias globals gas.globals "GAS_STORAGE_CLEAR_REFUND". -Axiom gas_GAS_STORAGE_SET : - IsGlobalAlias globals gas.globals "GAS_STORAGE_SET". -Axiom gas_GAS_STORAGE_UPDATE : - IsGlobalAlias globals gas.globals "GAS_STORAGE_UPDATE". -Axiom gas_GAS_WARM_ACCESS : - IsGlobalAlias globals gas.globals "GAS_WARM_ACCESS". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.london.state. +Axiom ethereum_london_state_get_storage : + IsGlobalAlias globals ethereum.london.state.globals "get_storage". +Axiom ethereum_london_state_get_storage_original : + IsGlobalAlias globals ethereum.london.state.globals "get_storage_original". +Axiom ethereum_london_state_set_storage : + IsGlobalAlias globals ethereum.london.state.globals "set_storage". + +Require ethereum.london.vm.__init__. +Axiom ethereum_london_vm___init___Evm : + IsGlobalAlias globals ethereum.london.vm.__init__.globals "Evm". + +Require ethereum.london.vm.exceptions. +Axiom ethereum_london_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.london.vm.exceptions.globals "OutOfGasError". +Axiom ethereum_london_vm_exceptions_WriteInStaticContext : + IsGlobalAlias globals ethereum.london.vm.exceptions.globals "WriteInStaticContext". + +Require ethereum.london.vm.gas. +Axiom ethereum_london_vm_gas_GAS_CALL_STIPEND : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_CALL_STIPEND". +Axiom ethereum_london_vm_gas_GAS_COLD_SLOAD : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_COLD_SLOAD". +Axiom ethereum_london_vm_gas_GAS_STORAGE_CLEAR_REFUND : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_STORAGE_CLEAR_REFUND". +Axiom ethereum_london_vm_gas_GAS_STORAGE_SET : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_STORAGE_SET". +Axiom ethereum_london_vm_gas_GAS_STORAGE_UPDATE : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_STORAGE_UPDATE". +Axiom ethereum_london_vm_gas_GAS_WARM_ACCESS : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_WARM_ACCESS". +Axiom ethereum_london_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.london.vm.gas.globals "charge_gas". + +Require ethereum.london.vm.stack. +Axiom ethereum_london_vm_stack_pop : + IsGlobalAlias globals ethereum.london.vm.stack.globals "pop". +Axiom ethereum_london_vm_stack_push : + IsGlobalAlias globals ethereum.london.vm.stack.globals "push". Definition sload : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -91,6 +91,25 @@ Definition sload : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], + M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "add" |), make_list [ @@ -205,15 +224,225 @@ Definition sstore : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], + M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "add" |), + make_list [ + make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ] + ], + make_dict [] + |) in + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_COLD_SLOAD" |) + M.get_name (| globals, "GAS_COLD_SLOAD" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_name (| globals, "original_value" |), + M.get_name (| globals, "current_value" |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "current_value" |), + M.get_name (| globals, "new_value" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "original_value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_STORAGE_SET" |) + M.get_name (| globals, "GAS_STORAGE_SET" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let gas_cost := BinOp.add + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_UPDATE" |), + M.get_name (| globals, "GAS_COLD_SLOAD" |) + |) + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_UPDATE" |), + M.get_name (| globals, "GAS_COLD_SLOAD" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let gas_cost := BinOp.add M.get_name (| globals, "GAS_WARM_ACCESS" |) M.get_name (| globals, "GAS_WARM_ACCESS" |) in M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| + M.get_name (| globals, "current_value" |), + M.get_name (| globals, "new_value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "original_value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "current_value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "new_value" |), + Constant.int 0 + |) + )) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "original_value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "current_value" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.sub, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "original_value" |), + M.get_name (| globals, "new_value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "original_value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_SET" |), + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.sub (| + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_UPDATE" |), + M.get_name (| globals, "GAS_COLD_SLOAD" |) + |), + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/london/vm/instructions/system.v b/CoqOfPython/ethereum/london/vm/instructions/system.v index 03931b2..41bdf93 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/system.v +++ b/CoqOfPython/ethereum/london/vm/instructions/system.v @@ -33,87 +33,87 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.london.fork_types. +Axiom ethereum_london_fork_types_Address : + IsGlobalAlias globals ethereum.london.fork_types.globals "Address". -Require state. -Axiom state_account_exists_and_is_empty : - IsGlobalAlias globals state.globals "account_exists_and_is_empty". -Axiom state_account_has_code_or_nonce : - IsGlobalAlias globals state.globals "account_has_code_or_nonce". -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". -Axiom state_increment_nonce : - IsGlobalAlias globals state.globals "increment_nonce". -Axiom state_is_account_alive : - IsGlobalAlias globals state.globals "is_account_alive". -Axiom state_set_account_balance : - IsGlobalAlias globals state.globals "set_account_balance". +Require ethereum.london.state. +Axiom ethereum_london_state_account_exists_and_is_empty : + IsGlobalAlias globals ethereum.london.state.globals "account_exists_and_is_empty". +Axiom ethereum_london_state_account_has_code_or_nonce : + IsGlobalAlias globals ethereum.london.state.globals "account_has_code_or_nonce". +Axiom ethereum_london_state_get_account : + IsGlobalAlias globals ethereum.london.state.globals "get_account". +Axiom ethereum_london_state_increment_nonce : + IsGlobalAlias globals ethereum.london.state.globals "increment_nonce". +Axiom ethereum_london_state_is_account_alive : + IsGlobalAlias globals ethereum.london.state.globals "is_account_alive". +Axiom ethereum_london_state_set_account_balance : + IsGlobalAlias globals ethereum.london.state.globals "set_account_balance". -Require utils.address. -Axiom utils_address_compute_contract_address : - IsGlobalAlias globals utils.address.globals "compute_contract_address". -Axiom utils_address_compute_create2_contract_address : - IsGlobalAlias globals utils.address.globals "compute_create2_contract_address". -Axiom utils_address_to_address : - IsGlobalAlias globals utils.address.globals "to_address". +Require ethereum.london.utils.address. +Axiom ethereum_london_utils_address_compute_contract_address : + IsGlobalAlias globals ethereum.london.utils.address.globals "compute_contract_address". +Axiom ethereum_london_utils_address_compute_create2_contract_address : + IsGlobalAlias globals ethereum.london.utils.address.globals "compute_create2_contract_address". +Axiom ethereum_london_utils_address_to_address : + IsGlobalAlias globals ethereum.london.utils.address.globals "to_address". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". -Axiom __init___Message : - IsGlobalAlias globals __init__.globals "Message". -Axiom __init___incorporate_child_on_error : - IsGlobalAlias globals __init__.globals "incorporate_child_on_error". -Axiom __init___incorporate_child_on_success : - IsGlobalAlias globals __init__.globals "incorporate_child_on_success". +Require ethereum.london.vm.__init__. +Axiom ethereum_london_vm___init___Evm : + IsGlobalAlias globals ethereum.london.vm.__init__.globals "Evm". +Axiom ethereum_london_vm___init___Message : + IsGlobalAlias globals ethereum.london.vm.__init__.globals "Message". +Axiom ethereum_london_vm___init___incorporate_child_on_error : + IsGlobalAlias globals ethereum.london.vm.__init__.globals "incorporate_child_on_error". +Axiom ethereum_london_vm___init___incorporate_child_on_success : + IsGlobalAlias globals ethereum.london.vm.__init__.globals "incorporate_child_on_success". -Require exceptions. -Axiom exceptions_Revert : - IsGlobalAlias globals exceptions.globals "Revert". -Axiom exceptions_WriteInStaticContext : - IsGlobalAlias globals exceptions.globals "WriteInStaticContext". +Require ethereum.london.vm.exceptions. +Axiom ethereum_london_vm_exceptions_Revert : + IsGlobalAlias globals ethereum.london.vm.exceptions.globals "Revert". +Axiom ethereum_london_vm_exceptions_WriteInStaticContext : + IsGlobalAlias globals ethereum.london.vm.exceptions.globals "WriteInStaticContext". -Require gas. -Axiom gas_GAS_CALL_VALUE : - IsGlobalAlias globals gas.globals "GAS_CALL_VALUE". -Axiom gas_GAS_COLD_ACCOUNT_ACCESS : - IsGlobalAlias globals gas.globals "GAS_COLD_ACCOUNT_ACCESS". -Axiom gas_GAS_CREATE : - IsGlobalAlias globals gas.globals "GAS_CREATE". -Axiom gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". -Axiom gas_GAS_NEW_ACCOUNT : - IsGlobalAlias globals gas.globals "GAS_NEW_ACCOUNT". -Axiom gas_GAS_SELF_DESTRUCT : - IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT". -Axiom gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : - IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". -Axiom gas_GAS_WARM_ACCESS : - IsGlobalAlias globals gas.globals "GAS_WARM_ACCESS". -Axiom gas_GAS_ZERO : - IsGlobalAlias globals gas.globals "GAS_ZERO". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_calculate_message_call_gas : - IsGlobalAlias globals gas.globals "calculate_message_call_gas". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". -Axiom gas_max_message_call_gas : - IsGlobalAlias globals gas.globals "max_message_call_gas". +Require ethereum.london.vm.gas. +Axiom ethereum_london_vm_gas_GAS_CALL_VALUE : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_CALL_VALUE". +Axiom ethereum_london_vm_gas_GAS_COLD_ACCOUNT_ACCESS : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_COLD_ACCOUNT_ACCESS". +Axiom ethereum_london_vm_gas_GAS_CREATE : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_CREATE". +Axiom ethereum_london_vm_gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_KECCAK256_WORD". +Axiom ethereum_london_vm_gas_GAS_NEW_ACCOUNT : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_NEW_ACCOUNT". +Axiom ethereum_london_vm_gas_GAS_SELF_DESTRUCT : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_SELF_DESTRUCT". +Axiom ethereum_london_vm_gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". +Axiom ethereum_london_vm_gas_GAS_WARM_ACCESS : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_WARM_ACCESS". +Axiom ethereum_london_vm_gas_GAS_ZERO : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_ZERO". +Axiom ethereum_london_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.london.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_london_vm_gas_calculate_message_call_gas : + IsGlobalAlias globals ethereum.london.vm.gas.globals "calculate_message_call_gas". +Axiom ethereum_london_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.london.vm.gas.globals "charge_gas". +Axiom ethereum_london_vm_gas_max_message_call_gas : + IsGlobalAlias globals ethereum.london.vm.gas.globals "max_message_call_gas". -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". -Axiom memory_memory_write : - IsGlobalAlias globals memory.globals "memory_write". +Require ethereum.london.vm.memory. +Axiom ethereum_london_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.london.vm.memory.globals "memory_read_bytes". +Axiom ethereum_london_vm_memory_memory_write : + IsGlobalAlias globals ethereum.london.vm.memory.globals "memory_write". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.london.vm.stack. +Axiom ethereum_london_vm_stack_pop : + IsGlobalAlias globals ethereum.london.vm.stack.globals "pop". +Axiom ethereum_london_vm_stack_push : + IsGlobalAlias globals ethereum.london.vm.stack.globals "push". Definition generic_create : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -172,9 +172,113 @@ Definition generic_create : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt (| + M.get_field (| M.get_name (| globals, "sender" |), "balance" |), + M.get_name (| globals, "endowment" |) + |), + ltac:(M.monadic ( + BoolOp.or (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "sender" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.sub (| + BinOp.pow (| + Constant.int 2, + Constant.int 64 + |), + Constant.int 1 + |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.gt (| + BinOp.add (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "depth" |), + Constant.int 1 + |), + M.get_name (| globals, "STACK_DEPTH_LIMIT" |) + |) + )) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "create_message_gas" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "contract_address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let call_data := @@ -211,6 +315,40 @@ Definition generic_create : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "child_evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_error" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "incorporate_child_on_success" |), make_list [ @@ -567,6 +705,42 @@ Definition generic_call : Value.t -> Value.t -> M := Constant.bytes "" |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + BinOp.add (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "depth" |), + Constant.int 1 + |), + M.get_name (| globals, "STACK_DEPTH_LIMIT" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "gas" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let call_data := @@ -604,6 +778,40 @@ Definition generic_call : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "child_evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_error" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "incorporate_child_on_success" |), make_list [ @@ -658,7 +866,7 @@ Definition generic_call : Value.t -> Value.t -> M := make_list [ M.get_field (| M.get_name (| globals, "evm" |), "memory" |); M.get_name (| globals, "memory_output_start_position" |); - M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), Constant.None_:M.get_name (| globals, "actual_output_size" |) |) + M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), M.slice (| Constant.None_, M.get_name (| globals, "actual_output_size" |) |) |) ], make_dict [] |) in @@ -756,6 +964,19 @@ Definition call : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "to" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let access_gas_cost := + M.get_name (| globals, "GAS_WARM_ACCESS" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -768,49 +989,57 @@ Definition call : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in let create_gas_cost := - (* if *) -M.if_then_else (| - BoolOp.or (| - M.call (| - M.get_name (| globals, "is_account_alive" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); - M.get_name (| globals, "to" |) - ], - make_dict [] - |), - ltac:(M.monadic ( - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |) - )) - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + BoolOp.or (| + M.call (| + M.get_name (| globals, "is_account_alive" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "to" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "GAS_NEW_ACCOUNT" |) + )) |) in let transfer_gas_cost := - (* if *) -M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "GAS_CALL_VALUE" |) + )) |) in let message_call_gas := M.call (| M.get_name (| globals, "calculate_message_call_gas" |), @@ -886,6 +1115,40 @@ M.call (| make_dict [] |), "balance" |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "sender_balance" |), + M.get_name (| globals, "value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "generic_call" |), make_list [ @@ -1007,6 +1270,19 @@ Definition callcode : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "code_address" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let access_gas_cost := + M.get_name (| globals, "GAS_WARM_ACCESS" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1019,21 +1295,25 @@ Definition callcode : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in let transfer_gas_cost := - (* if *) -M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "GAS_CALL_VALUE" |) + )) |) in let message_call_gas := M.call (| M.get_name (| globals, "calculate_message_call_gas" |), @@ -1084,6 +1364,40 @@ M.call (| make_dict [] |), "balance" |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "sender_balance" |), + M.get_name (| globals, "value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "generic_call" |), make_list [ @@ -1139,9 +1453,63 @@ Definition selfdestruct : Value.t -> Value.t -> M := let gas_cost := M.get_name (| globals, "GAS_SELF_DESTRUCT" |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "beneficiary" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |) in + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + UnOp.not (| M.call (| + M.get_name (| globals, "is_account_alive" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) + M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -1215,6 +1583,28 @@ Definition selfdestruct : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -1308,6 +1698,19 @@ Definition delegatecall : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "code_address" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let access_gas_cost := + M.get_name (| globals, "GAS_WARM_ACCESS" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1471,6 +1874,19 @@ Definition staticcall : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "to" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let access_gas_cost := + M.get_name (| globals, "GAS_WARM_ACCESS" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1630,6 +2046,6 @@ Definition revert : Value.t -> Value.t -> M := make_dict [] |) |) in - let _ := M.raise (| Some(M.get_name (| globals, "Revert" |)) + let _ := M.raise (| Some(M.get_name (| globals, "Revert" |)) |) in let _ := M.pass (| |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/vm/interpreter.v b/CoqOfPython/ethereum/london/vm/interpreter.v index 024d2d5..085e5dd 100644 --- a/CoqOfPython/ethereum/london/vm/interpreter.v +++ b/CoqOfPython/ethereum/london/vm/interpreter.v @@ -61,83 +61,83 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". - -Require state. -Axiom state_account_exists_and_is_empty : - IsGlobalAlias globals state.globals "account_exists_and_is_empty". -Axiom state_account_has_code_or_nonce : - IsGlobalAlias globals state.globals "account_has_code_or_nonce". -Axiom state_begin_transaction : - IsGlobalAlias globals state.globals "begin_transaction". -Axiom state_commit_transaction : - IsGlobalAlias globals state.globals "commit_transaction". -Axiom state_destroy_storage : - IsGlobalAlias globals state.globals "destroy_storage". -Axiom state_increment_nonce : - IsGlobalAlias globals state.globals "increment_nonce". -Axiom state_mark_account_created : - IsGlobalAlias globals state.globals "mark_account_created". -Axiom state_move_ether : - IsGlobalAlias globals state.globals "move_ether". -Axiom state_rollback_transaction : - IsGlobalAlias globals state.globals "rollback_transaction". -Axiom state_set_code : - IsGlobalAlias globals state.globals "set_code". -Axiom state_touch_account : - IsGlobalAlias globals state.globals "touch_account". - -Require vm. -Axiom vm_Message : - IsGlobalAlias globals vm.globals "Message". - -Require vm.gas. -Axiom vm_gas_GAS_CODE_DEPOSIT : - IsGlobalAlias globals vm.gas.globals "GAS_CODE_DEPOSIT". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". - -Require vm.precompiled_contracts.mapping. -Axiom vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : - IsGlobalAlias globals vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". - -Require __init__. -Axiom __init___Environment : - IsGlobalAlias globals __init__.globals "Environment". -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require exceptions. -Axiom exceptions_AddressCollision : - IsGlobalAlias globals exceptions.globals "AddressCollision". -Axiom exceptions_ExceptionalHalt : - IsGlobalAlias globals exceptions.globals "ExceptionalHalt". -Axiom exceptions_InvalidContractPrefix : - IsGlobalAlias globals exceptions.globals "InvalidContractPrefix". -Axiom exceptions_InvalidOpcode : - IsGlobalAlias globals exceptions.globals "InvalidOpcode". -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". -Axiom exceptions_Revert : - IsGlobalAlias globals exceptions.globals "Revert". -Axiom exceptions_StackDepthLimitError : - IsGlobalAlias globals exceptions.globals "StackDepthLimitError". - -Require instructions. -Axiom instructions_Ops : - IsGlobalAlias globals instructions.globals "Ops". -Axiom instructions_op_implementation : - IsGlobalAlias globals instructions.globals "op_implementation". - -Require runtime. -Axiom runtime_get_valid_jump_destinations : - IsGlobalAlias globals runtime.globals "get_valid_jump_destinations". +Require ethereum.london.blocks. +Axiom ethereum_london_blocks_Log : + IsGlobalAlias globals ethereum.london.blocks.globals "Log". + +Require ethereum.london.fork_types. +Axiom ethereum_london_fork_types_Address : + IsGlobalAlias globals ethereum.london.fork_types.globals "Address". + +Require ethereum.london.state. +Axiom ethereum_london_state_account_exists_and_is_empty : + IsGlobalAlias globals ethereum.london.state.globals "account_exists_and_is_empty". +Axiom ethereum_london_state_account_has_code_or_nonce : + IsGlobalAlias globals ethereum.london.state.globals "account_has_code_or_nonce". +Axiom ethereum_london_state_begin_transaction : + IsGlobalAlias globals ethereum.london.state.globals "begin_transaction". +Axiom ethereum_london_state_commit_transaction : + IsGlobalAlias globals ethereum.london.state.globals "commit_transaction". +Axiom ethereum_london_state_destroy_storage : + IsGlobalAlias globals ethereum.london.state.globals "destroy_storage". +Axiom ethereum_london_state_increment_nonce : + IsGlobalAlias globals ethereum.london.state.globals "increment_nonce". +Axiom ethereum_london_state_mark_account_created : + IsGlobalAlias globals ethereum.london.state.globals "mark_account_created". +Axiom ethereum_london_state_move_ether : + IsGlobalAlias globals ethereum.london.state.globals "move_ether". +Axiom ethereum_london_state_rollback_transaction : + IsGlobalAlias globals ethereum.london.state.globals "rollback_transaction". +Axiom ethereum_london_state_set_code : + IsGlobalAlias globals ethereum.london.state.globals "set_code". +Axiom ethereum_london_state_touch_account : + IsGlobalAlias globals ethereum.london.state.globals "touch_account". + +Require ethereum.london.vm.__init__. +Axiom ethereum_london_vm___init___Message : + IsGlobalAlias globals ethereum.london.vm.__init__.globals "Message". + +Require ethereum.london.vm.gas. +Axiom ethereum_london_vm_gas_GAS_CODE_DEPOSIT : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_CODE_DEPOSIT". +Axiom ethereum_london_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.london.vm.gas.globals "charge_gas". + +Require ethereum.london.vm.precompiled_contracts.mapping. +Axiom ethereum_london_vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : + IsGlobalAlias globals ethereum.london.vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". + +Require ethereum.london.vm.__init__. +Axiom ethereum_london_vm___init___Environment : + IsGlobalAlias globals ethereum.london.vm.__init__.globals "Environment". +Axiom ethereum_london_vm___init___Evm : + IsGlobalAlias globals ethereum.london.vm.__init__.globals "Evm". + +Require ethereum.london.vm.exceptions. +Axiom ethereum_london_vm_exceptions_AddressCollision : + IsGlobalAlias globals ethereum.london.vm.exceptions.globals "AddressCollision". +Axiom ethereum_london_vm_exceptions_ExceptionalHalt : + IsGlobalAlias globals ethereum.london.vm.exceptions.globals "ExceptionalHalt". +Axiom ethereum_london_vm_exceptions_InvalidContractPrefix : + IsGlobalAlias globals ethereum.london.vm.exceptions.globals "InvalidContractPrefix". +Axiom ethereum_london_vm_exceptions_InvalidOpcode : + IsGlobalAlias globals ethereum.london.vm.exceptions.globals "InvalidOpcode". +Axiom ethereum_london_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.london.vm.exceptions.globals "OutOfGasError". +Axiom ethereum_london_vm_exceptions_Revert : + IsGlobalAlias globals ethereum.london.vm.exceptions.globals "Revert". +Axiom ethereum_london_vm_exceptions_StackDepthLimitError : + IsGlobalAlias globals ethereum.london.vm.exceptions.globals "StackDepthLimitError". + +Require ethereum.london.vm.instructions.__init__. +Axiom ethereum_london_vm_instructions___init___Ops : + IsGlobalAlias globals ethereum.london.vm.instructions.__init__.globals "Ops". +Axiom ethereum_london_vm_instructions___init___op_implementation : + IsGlobalAlias globals ethereum.london.vm.instructions.__init__.globals "op_implementation". + +Require ethereum.london.vm.runtime. +Axiom ethereum_london_vm_runtime_get_valid_jump_destinations : + IsGlobalAlias globals ethereum.london.vm.runtime.globals "get_valid_jump_destinations". Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -184,6 +184,94 @@ Definition process_message_call : Value.t -> Value.t -> M := Output of the message call " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "message" |), "target" |), + M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) + |), + (* then *) + ltac:(M.monadic ( + let is_collision := + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_name (| globals, "is_collision" |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallOutput" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "tuple" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "AddressCollision" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let evm := + M.call (| + M.get_name (| globals, "process_create_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let evm := M.call (| M.get_name (| globals, "process_message" |), @@ -194,11 +282,74 @@ Definition process_message_call : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_field (| M.get_name (| globals, "message" |), "target" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_field (| M.get_name (| globals, "message" |), "target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( +(* At stmt: unsupported node type: AnnAssign *) + let accounts_to_delete := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let touched_accounts := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let refund_counter := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let logs := M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in let accounts_to_delete := @@ -242,6 +393,7 @@ Definition process_message_call : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). Definition process_create_message : Value.t -> Value.t -> M := @@ -303,6 +455,28 @@ Definition process_create_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), + (* then *) + ltac:(M.monadic ( + let contract_code := + M.get_field (| M.get_name (| globals, "evm" |), "output" |) in + let contract_code_gas := + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "contract_code" |) + ], + make_dict [] + |), + M.get_name (| globals, "GAS_CODE_DEPOSIT" |) + |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "rollback_transaction" |), make_list [ @@ -314,6 +488,7 @@ Definition process_create_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) + |) in M.pure Constant.None_)). Definition process_message : Value.t -> Value.t -> M := @@ -335,6 +510,24 @@ Definition process_message : Value.t -> Value.t -> M := Items containing execution specific objects " in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_field (| M.get_name (| globals, "message" |), "depth" |), + M.get_name (| globals, "STACK_DEPTH_LIMIT" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "StackDepthLimitError" |), + make_list [ + Constant.str "Stack depth limit reached" + ], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -353,6 +546,32 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + M.get_field (| M.get_name (| globals, "message" |), "should_transfer_value" |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "message" |), "value" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "move_ether" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "caller" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |); + M.get_field (| M.get_name (| globals, "message" |), "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let evm := @@ -365,6 +584,21 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "rollback_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "commit_transaction" |), make_list [ @@ -376,6 +610,7 @@ Definition process_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) + |) in M.pure Constant.None_)). Definition execute_code : Value.t -> Value.t -> M := @@ -415,4 +650,5 @@ Definition execute_code : Value.t -> Value.t -> M := (* At stmt: unsupported node type: Try *) let _ := M.return_ (| M.get_name (| globals, "evm" |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/vm/memory.v b/CoqOfPython/ethereum/london/vm/memory.v index 4b107fd..08d2290 100644 --- a/CoqOfPython/ethereum/london/vm/memory.v +++ b/CoqOfPython/ethereum/london/vm/memory.v @@ -21,13 +21,13 @@ Require ethereum.utils.byte. Axiom ethereum_utils_byte_right_pad_zero_bytes : IsGlobalAlias globals ethereum.utils.byte.globals "right_pad_zero_bytes". -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". Definition memory_write : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,7 +45,22 @@ Definition memory_write : Value.t -> Value.t -> M := Data to write to memory. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |), + M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) |) |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_)). @@ -71,7 +86,23 @@ Definition memory_read_bytes : Value.t -> Value.t -> M := Data read from memory. " in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |) + M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |) |) + |) in M.pure Constant.None_)). Definition buffer_read : Value.t -> Value.t -> M := @@ -98,9 +129,25 @@ Definition buffer_read : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "right_pad_zero_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |) |); + M.get_subscript (| M.get_name (| globals, "buffer" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |) |); M.get_name (| globals, "size" |) ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/london/vm/precompiled_contracts/__init__.v index ca49311..37fddad 100644 --- a/CoqOfPython/ethereum/london/vm/precompiled_contracts/__init__.v +++ b/CoqOfPython/ethereum/london/vm/precompiled_contracts/__init__.v @@ -18,9 +18,9 @@ Addresses of precompiled contracts and mappings to their implementations. ". -Require utils.hexadecimal. -Axiom utils_hexadecimal_hex_to_address : - IsGlobalAlias globals utils.hexadecimal.globals "hex_to_address". +Require ethereum.london.utils.hexadecimal. +Axiom ethereum_london_utils_hexadecimal_hex_to_address : + IsGlobalAlias globals ethereum.london.utils.hexadecimal.globals "hex_to_address". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS"; Constant.str "MODEXP_ADDRESS"; Constant.str "ALT_BN128_ADD_ADDRESS"; Constant.str "ALT_BN128_MUL_ADDRESS"; Constant.str "ALT_BN128_PAIRING_CHECK_ADDRESS"; Constant.str "BLAKE2F_ADDRESS" ] diff --git a/CoqOfPython/ethereum/london/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/london/vm/precompiled_contracts/alt_bn128.v index abe4238..43f2cec 100644 --- a/CoqOfPython/ethereum/london/vm/precompiled_contracts/alt_bn128.v +++ b/CoqOfPython/ethereum/london/vm/precompiled_contracts/alt_bn128.v @@ -45,21 +45,21 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.london.vm.__init__. +Axiom ethereum_london_vm___init___Evm : + IsGlobalAlias globals ethereum.london.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.london.vm.gas. +Axiom ethereum_london_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.london.vm.gas.globals "charge_gas". -Require vm.memory. -Axiom vm_memory_buffer_read : - IsGlobalAlias globals vm.memory.globals "buffer_read". +Require ethereum.london.vm.memory. +Axiom ethereum_london_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.london.vm.memory.globals "buffer_read". -Require exceptions. -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". +Require ethereum.london.vm.exceptions. +Axiom ethereum_london_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.london.vm.exceptions.globals "OutOfGasError". Definition alt_bn128_add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -210,6 +210,18 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) in For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ] do let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -353,6 +365,18 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) in For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ] do let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -425,6 +449,27 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| + BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 192 + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let result := @@ -464,7 +509,7 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "data" |), BinOp.add (| + M.get_subscript (| M.get_name (| globals, "data" |), M.slice (| BinOp.add (| BinOp.mult (| M.get_name (| globals, "i" |), Constant.int 192 @@ -473,11 +518,35 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := Constant.int 32, M.get_name (| globals, "j" |) |) - |) |) + |), BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "j" |), + Constant.int 1 + |) + |) + |) |) |) ], make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -538,10 +607,80 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "p" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "q" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let result := + BinOp.mult (| + M.get_name (| globals, "result" |), + M.call (| + M.get_name (| globals, "pairing" |), + make_list [ + M.get_name (| globals, "q" |); + M.get_name (| globals, "p" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "result" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| diff --git a/CoqOfPython/ethereum/london/vm/precompiled_contracts/blake2f.v b/CoqOfPython/ethereum/london/vm/precompiled_contracts/blake2f.v index 1647d48..7a133d3 100644 --- a/CoqOfPython/ethereum/london/vm/precompiled_contracts/blake2f.v +++ b/CoqOfPython/ethereum/london/vm/precompiled_contracts/blake2f.v @@ -25,19 +25,19 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.london.vm.__init__. +Axiom ethereum_london_vm___init___Evm : + IsGlobalAlias globals ethereum.london.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_BLAKE2_PER_ROUND : - IsGlobalAlias globals vm.gas.globals "GAS_BLAKE2_PER_ROUND". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.london.vm.gas. +Axiom ethereum_london_vm_gas_GAS_BLAKE2_PER_ROUND : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_BLAKE2_PER_ROUND". +Axiom ethereum_london_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.london.vm.gas.globals "charge_gas". -Require exceptions. -Axiom exceptions_InvalidParameter : - IsGlobalAlias globals exceptions.globals "InvalidParameter". +Require ethereum.london.vm.exceptions. +Axiom ethereum_london_vm_exceptions_InvalidParameter : + IsGlobalAlias globals ethereum.london.vm.exceptions.globals "InvalidParameter". Definition blake2f : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/london/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/london/vm/precompiled_contracts/ecrecover.v index 0cbcf16..e9ca1bc 100644 --- a/CoqOfPython/ethereum/london/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/london/vm/precompiled_contracts/ecrecover.v @@ -37,19 +37,19 @@ Require ethereum.utils.byte. Axiom ethereum_utils_byte_left_pad_zero_bytes : IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.london.vm.__init__. +Axiom ethereum_london_vm___init___Evm : + IsGlobalAlias globals ethereum.london.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_ECRECOVER : - IsGlobalAlias globals vm.gas.globals "GAS_ECRECOVER". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.london.vm.gas. +Axiom ethereum_london_vm_gas_GAS_ECRECOVER : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_ECRECOVER". +Axiom ethereum_london_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.london.vm.gas.globals "charge_gas". -Require vm.memory. -Axiom vm_memory_buffer_read : - IsGlobalAlias globals vm.memory.globals "buffer_read". +Require ethereum.london.vm.memory. +Axiom ethereum_london_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.london.vm.memory.globals "buffer_read". Definition ecrecover : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -188,12 +188,78 @@ Definition ecrecover : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "v" |), + Constant.int 27 + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "v" |), + Constant.int 28 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + Constant.int 0, + M.get_name (| globals, "r" |) + |), + ltac:(M.monadic ( + Compare.gt_e (| + M.get_name (| globals, "r" |), + M.get_name (| globals, "SECP256K1N" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + Constant.int 0, + M.get_name (| globals, "s" |) + |), + ltac:(M.monadic ( + Compare.gt_e (| + M.get_name (| globals, "s" |), + M.get_name (| globals, "SECP256K1N" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: Try *) @@ -204,7 +270,7 @@ Definition ecrecover : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12 |) in + |), M.slice (| Constant.int 12, Constant.int 32 |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/london/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/london/vm/precompiled_contracts/identity.v index fa96704..31f2698 100644 --- a/CoqOfPython/ethereum/london/vm/precompiled_contracts/identity.v +++ b/CoqOfPython/ethereum/london/vm/precompiled_contracts/identity.v @@ -25,17 +25,17 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.london.vm.__init__. +Axiom ethereum_london_vm___init___Evm : + IsGlobalAlias globals ethereum.london.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_IDENTITY : - IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY". -Axiom vm_gas_GAS_IDENTITY_WORD : - IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY_WORD". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.london.vm.gas. +Axiom ethereum_london_vm_gas_GAS_IDENTITY : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_IDENTITY". +Axiom ethereum_london_vm_gas_GAS_IDENTITY_WORD : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_IDENTITY_WORD". +Axiom ethereum_london_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.london.vm.gas.globals "charge_gas". Definition identity : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/london/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/london/vm/precompiled_contracts/mapping.v index 8a2e2eb..47a552e 100644 --- a/CoqOfPython/ethereum/london/vm/precompiled_contracts/mapping.v +++ b/CoqOfPython/ethereum/london/vm/precompiled_contracts/mapping.v @@ -23,60 +23,60 @@ Axiom typing_Callable : Axiom typing_Dict : IsGlobalAlias globals typing.globals "Dict". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". - -Require __init__. -Axiom __init___ALT_BN128_ADD_ADDRESS : - IsGlobalAlias globals __init__.globals "ALT_BN128_ADD_ADDRESS". -Axiom __init___ALT_BN128_MUL_ADDRESS : - IsGlobalAlias globals __init__.globals "ALT_BN128_MUL_ADDRESS". -Axiom __init___ALT_BN128_PAIRING_CHECK_ADDRESS : - IsGlobalAlias globals __init__.globals "ALT_BN128_PAIRING_CHECK_ADDRESS". -Axiom __init___BLAKE2F_ADDRESS : - IsGlobalAlias globals __init__.globals "BLAKE2F_ADDRESS". -Axiom __init___ECRECOVER_ADDRESS : - IsGlobalAlias globals __init__.globals "ECRECOVER_ADDRESS". -Axiom __init___IDENTITY_ADDRESS : - IsGlobalAlias globals __init__.globals "IDENTITY_ADDRESS". -Axiom __init___MODEXP_ADDRESS : - IsGlobalAlias globals __init__.globals "MODEXP_ADDRESS". -Axiom __init___RIPEMD160_ADDRESS : - IsGlobalAlias globals __init__.globals "RIPEMD160_ADDRESS". -Axiom __init___SHA256_ADDRESS : - IsGlobalAlias globals __init__.globals "SHA256_ADDRESS". - -Require alt_bn128. -Axiom alt_bn128_alt_bn128_add : - IsGlobalAlias globals alt_bn128.globals "alt_bn128_add". -Axiom alt_bn128_alt_bn128_mul : - IsGlobalAlias globals alt_bn128.globals "alt_bn128_mul". -Axiom alt_bn128_alt_bn128_pairing_check : - IsGlobalAlias globals alt_bn128.globals "alt_bn128_pairing_check". - -Require blake2f. -Axiom blake2f_blake2f : - IsGlobalAlias globals blake2f.globals "blake2f". - -Require ecrecover. -Axiom ecrecover_ecrecover : - IsGlobalAlias globals ecrecover.globals "ecrecover". - -Require identity. -Axiom identity_identity : - IsGlobalAlias globals identity.globals "identity". - -Require modexp. -Axiom modexp_modexp : - IsGlobalAlias globals modexp.globals "modexp". - -Require ripemd160. -Axiom ripemd160_ripemd160 : - IsGlobalAlias globals ripemd160.globals "ripemd160". - -Require sha256. -Axiom sha256_sha256 : - IsGlobalAlias globals sha256.globals "sha256". +Require ethereum.london.fork_types. +Axiom ethereum_london_fork_types_Address : + IsGlobalAlias globals ethereum.london.fork_types.globals "Address". + +Require ethereum.london.vm.precompiled_contracts.__init__. +Axiom ethereum_london_vm_precompiled_contracts___init___ALT_BN128_ADD_ADDRESS : + IsGlobalAlias globals ethereum.london.vm.precompiled_contracts.__init__.globals "ALT_BN128_ADD_ADDRESS". +Axiom ethereum_london_vm_precompiled_contracts___init___ALT_BN128_MUL_ADDRESS : + IsGlobalAlias globals ethereum.london.vm.precompiled_contracts.__init__.globals "ALT_BN128_MUL_ADDRESS". +Axiom ethereum_london_vm_precompiled_contracts___init___ALT_BN128_PAIRING_CHECK_ADDRESS : + IsGlobalAlias globals ethereum.london.vm.precompiled_contracts.__init__.globals "ALT_BN128_PAIRING_CHECK_ADDRESS". +Axiom ethereum_london_vm_precompiled_contracts___init___BLAKE2F_ADDRESS : + IsGlobalAlias globals ethereum.london.vm.precompiled_contracts.__init__.globals "BLAKE2F_ADDRESS". +Axiom ethereum_london_vm_precompiled_contracts___init___ECRECOVER_ADDRESS : + IsGlobalAlias globals ethereum.london.vm.precompiled_contracts.__init__.globals "ECRECOVER_ADDRESS". +Axiom ethereum_london_vm_precompiled_contracts___init___IDENTITY_ADDRESS : + IsGlobalAlias globals ethereum.london.vm.precompiled_contracts.__init__.globals "IDENTITY_ADDRESS". +Axiom ethereum_london_vm_precompiled_contracts___init___MODEXP_ADDRESS : + IsGlobalAlias globals ethereum.london.vm.precompiled_contracts.__init__.globals "MODEXP_ADDRESS". +Axiom ethereum_london_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : + IsGlobalAlias globals ethereum.london.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". +Axiom ethereum_london_vm_precompiled_contracts___init___SHA256_ADDRESS : + IsGlobalAlias globals ethereum.london.vm.precompiled_contracts.__init__.globals "SHA256_ADDRESS". + +Require ethereum.london.vm.precompiled_contracts.alt_bn128. +Axiom ethereum_london_vm_precompiled_contracts_alt_bn128_alt_bn128_add : + IsGlobalAlias globals ethereum.london.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_add". +Axiom ethereum_london_vm_precompiled_contracts_alt_bn128_alt_bn128_mul : + IsGlobalAlias globals ethereum.london.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_mul". +Axiom ethereum_london_vm_precompiled_contracts_alt_bn128_alt_bn128_pairing_check : + IsGlobalAlias globals ethereum.london.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_pairing_check". + +Require ethereum.london.vm.precompiled_contracts.blake2f. +Axiom ethereum_london_vm_precompiled_contracts_blake2f_blake2f : + IsGlobalAlias globals ethereum.london.vm.precompiled_contracts.blake2f.globals "blake2f". + +Require ethereum.london.vm.precompiled_contracts.ecrecover. +Axiom ethereum_london_vm_precompiled_contracts_ecrecover_ecrecover : + IsGlobalAlias globals ethereum.london.vm.precompiled_contracts.ecrecover.globals "ecrecover". + +Require ethereum.london.vm.precompiled_contracts.identity. +Axiom ethereum_london_vm_precompiled_contracts_identity_identity : + IsGlobalAlias globals ethereum.london.vm.precompiled_contracts.identity.globals "identity". + +Require ethereum.london.vm.precompiled_contracts.modexp. +Axiom ethereum_london_vm_precompiled_contracts_modexp_modexp : + IsGlobalAlias globals ethereum.london.vm.precompiled_contracts.modexp.globals "modexp". + +Require ethereum.london.vm.precompiled_contracts.ripemd160. +Axiom ethereum_london_vm_precompiled_contracts_ripemd160_ripemd160 : + IsGlobalAlias globals ethereum.london.vm.precompiled_contracts.ripemd160.globals "ripemd160". + +Require ethereum.london.vm.precompiled_contracts.sha256. +Axiom ethereum_london_vm_precompiled_contracts_sha256_sha256 : + IsGlobalAlias globals ethereum.london.vm.precompiled_contracts.sha256.globals "sha256". (* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/london/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/london/vm/precompiled_contracts/modexp.v index 3505244..87dc90c 100644 --- a/CoqOfPython/ethereum/london/vm/precompiled_contracts/modexp.v +++ b/CoqOfPython/ethereum/london/vm/precompiled_contracts/modexp.v @@ -25,17 +25,17 @@ Axiom ethereum_base_types_Bytes : Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.london.vm.__init__. +Axiom ethereum_london_vm___init___Evm : + IsGlobalAlias globals ethereum.london.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.london.vm.gas. +Axiom ethereum_london_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.london.vm.gas.globals "charge_gas". -Require memory. -Axiom memory_buffer_read : - IsGlobalAlias globals memory.globals "buffer_read". +Require ethereum.london.vm.memory. +Axiom ethereum_london_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.london.vm.memory.globals "buffer_read". Definition GQUADDIVISOR : Value.t := M.run ltac:(M.monadic ( Constant.int 3 @@ -192,6 +192,36 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_name (| globals, "base_length" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "modulus_length" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [], + make_dict [] + |) + |) in + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let base := @@ -254,6 +284,30 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "modulus" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + BinOp.mult (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + Constant.bytes "00" + ], + make_dict [] + |), + M.get_name (| globals, "modulus_length" |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| @@ -338,6 +392,7 @@ Definition complexity : Value.t -> Value.t -> M := M.get_name (| globals, "words" |), Constant.int 2 |) + |) in M.pure Constant.None_)). Definition iterations : Value.t -> Value.t -> M := @@ -364,7 +419,76 @@ Definition iterations : Value.t -> Value.t -> M := Number of iterations. " in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.lt_e (| + M.get_name (| globals, "exponent_length" |), + Constant.int 32 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "exponent_head" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let count := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "exponent_length" |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let bit_length := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "exponent_head" |), "bit_length" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "bit_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let bit_length := BinOp.sub + Constant.int 1 + Constant.int 1 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let count := + M.get_name (| globals, "bit_length" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let length_part := BinOp.mult (| Constant.int 8, @@ -392,6 +516,20 @@ Definition iterations : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "bits_part" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let bits_part := BinOp.sub + Constant.int 1 + Constant.int 1 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let count := @@ -418,6 +556,7 @@ Definition iterations : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition gas_cost : Value.t -> Value.t -> M := @@ -489,4 +628,5 @@ Definition gas_cost : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/london/vm/precompiled_contracts/ripemd160.v index 96f8dcd..48bc733 100644 --- a/CoqOfPython/ethereum/london/vm/precompiled_contracts/ripemd160.v +++ b/CoqOfPython/ethereum/london/vm/precompiled_contracts/ripemd160.v @@ -31,17 +31,17 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.london.vm.__init__. +Axiom ethereum_london_vm___init___Evm : + IsGlobalAlias globals ethereum.london.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_RIPEMD160 : - IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160". -Axiom vm_gas_GAS_RIPEMD160_WORD : - IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160_WORD". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.london.vm.gas. +Axiom ethereum_london_vm_gas_GAS_RIPEMD160 : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_RIPEMD160". +Axiom ethereum_london_vm_gas_GAS_RIPEMD160_WORD : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_RIPEMD160_WORD". +Axiom ethereum_london_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.london.vm.gas.globals "charge_gas". Definition ripemd160 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/london/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/london/vm/precompiled_contracts/sha256.v index 9f6d2bf..f345af0 100644 --- a/CoqOfPython/ethereum/london/vm/precompiled_contracts/sha256.v +++ b/CoqOfPython/ethereum/london/vm/precompiled_contracts/sha256.v @@ -27,17 +27,17 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.london.vm.__init__. +Axiom ethereum_london_vm___init___Evm : + IsGlobalAlias globals ethereum.london.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_SHA256 : - IsGlobalAlias globals vm.gas.globals "GAS_SHA256". -Axiom vm_gas_GAS_SHA256_WORD : - IsGlobalAlias globals vm.gas.globals "GAS_SHA256_WORD". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.london.vm.gas. +Axiom ethereum_london_vm_gas_GAS_SHA256 : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_SHA256". +Axiom ethereum_london_vm_gas_GAS_SHA256_WORD : + IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_SHA256_WORD". +Axiom ethereum_london_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.london.vm.gas.globals "charge_gas". Definition sha256 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/london/vm/runtime.v b/CoqOfPython/ethereum/london/vm/runtime.v index 2cd7652..8cbf8ad 100644 --- a/CoqOfPython/ethereum/london/vm/runtime.v +++ b/CoqOfPython/ethereum/london/vm/runtime.v @@ -25,9 +25,9 @@ Require ethereum.base_types. Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require instructions. -Axiom instructions_Ops : - IsGlobalAlias globals instructions.globals "Ops". +Require ethereum.london.vm.instructions.__init__. +Axiom ethereum_london_vm_instructions___init___Ops : + IsGlobalAlias globals ethereum.london.vm.instructions.__init__.globals "Ops". Definition get_valid_jump_destinations : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -79,7 +79,55 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := |) do (* At stmt: unsupported node type: Try *) let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "current_opcode" |), + M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), + make_list [ + M.get_name (| globals, "pc" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.lt_e (| + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |), + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH32" |), "value" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let push_data_size := + BinOp.add (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) + |), + Constant.int 1 + |) in + let pc := BinOp.add + M.get_name (| globals, "push_data_size" |) + M.get_name (| globals, "push_data_size" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -90,4 +138,5 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := EndWhile. let _ := M.return_ (| M.get_name (| globals, "valid_jump_destinations" |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/vm/stack.v b/CoqOfPython/ethereum/london/vm/stack.v index ea778df..6460116 100644 --- a/CoqOfPython/ethereum/london/vm/stack.v +++ b/CoqOfPython/ethereum/london/vm/stack.v @@ -25,11 +25,11 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require exceptions. -Axiom exceptions_StackOverflowError : - IsGlobalAlias globals exceptions.globals "StackOverflowError". -Axiom exceptions_StackUnderflowError : - IsGlobalAlias globals exceptions.globals "StackUnderflowError". +Require ethereum.london.vm.exceptions. +Axiom ethereum_london_vm_exceptions_StackOverflowError : + IsGlobalAlias globals ethereum.london.vm.exceptions.globals "StackOverflowError". +Axiom ethereum_london_vm_exceptions_StackUnderflowError : + IsGlobalAlias globals ethereum.london.vm.exceptions.globals "StackUnderflowError". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -49,6 +49,24 @@ Definition pop : Value.t -> Value.t -> M := " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "StackUnderflowError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -57,6 +75,7 @@ Definition pop : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). Definition push : Value.t -> Value.t -> M := @@ -75,6 +94,24 @@ Definition push : Value.t -> Value.t -> M := " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), + Constant.int 1024 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "StackOverflowError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -85,4 +122,5 @@ Definition push : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/blocks.v b/CoqOfPython/ethereum/muir_glacier/blocks.v index 6501788..40922ea 100644 --- a/CoqOfPython/ethereum/muir_glacier/blocks.v +++ b/CoqOfPython/ethereum/muir_glacier/blocks.v @@ -22,35 +22,35 @@ Require typing. Axiom typing_Tuple : IsGlobalAlias globals typing.globals "Tuple". -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes8 : - IsGlobalAlias globals base_types.globals "Bytes8". -Axiom base_types_Bytes32 : - IsGlobalAlias globals base_types.globals "Bytes32". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require crypto.hash. -Axiom crypto_hash_Hash32 : - IsGlobalAlias globals crypto.hash.globals "Hash32". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". - -Require transactions. -Axiom transactions_Transaction : - IsGlobalAlias globals transactions.globals "Transaction". +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes8 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes8". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". + +Require ethereum.muir_glacier.fork_types. +Axiom ethereum_muir_glacier_fork_types_Address : + IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "Address". +Axiom ethereum_muir_glacier_fork_types_Bloom : + IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "Bloom". +Axiom ethereum_muir_glacier_fork_types_Root : + IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "Root". + +Require ethereum.muir_glacier.transactions. +Axiom ethereum_muir_glacier_transactions_Transaction : + IsGlobalAlias globals ethereum.muir_glacier.transactions.globals "Transaction". Definition Header : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/muir_glacier/bloom.v b/CoqOfPython/ethereum/muir_glacier/bloom.v index 04650ff..4332553 100644 --- a/CoqOfPython/ethereum/muir_glacier/bloom.v +++ b/CoqOfPython/ethereum/muir_glacier/bloom.v @@ -33,13 +33,13 @@ Require ethereum.crypto.hash. Axiom ethereum_crypto_hash_keccak256 : IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". +Require ethereum.muir_glacier.blocks. +Axiom ethereum_muir_glacier_blocks_Log : + IsGlobalAlias globals ethereum.muir_glacier.blocks.globals "Log". -Require fork_types. -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". +Require ethereum.muir_glacier.fork_types. +Axiom ethereum_muir_glacier_fork_types_Bloom : + IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "Bloom". Definition add_to_bloom : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -72,7 +72,10 @@ Definition add_to_bloom : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |) |) + M.get_subscript (| M.get_name (| globals, "hash" |), M.slice (| M.get_name (| globals, "idx" |), BinOp.add (| + M.get_name (| globals, "idx" |), + Constant.int 2 + |) |) |) ], make_dict [] |), @@ -157,4 +160,5 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/fork.v b/CoqOfPython/ethereum/muir_glacier/fork.v index 972e704..d4c2985 100644 --- a/CoqOfPython/ethereum/muir_glacier/fork.v +++ b/CoqOfPython/ethereum/muir_glacier/fork.v @@ -63,93 +63,93 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U64 : - IsGlobalAlias globals base_types.globals "U64". -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_U256_CEIL_VALUE : - IsGlobalAlias globals base_types.globals "U256_CEIL_VALUE". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". - -Require __init__. -Axiom __init___vm : - IsGlobalAlias globals __init__.globals "vm". - -Require blocks. -Axiom blocks_Block : - IsGlobalAlias globals blocks.globals "Block". -Axiom blocks_Header : - IsGlobalAlias globals blocks.globals "Header". -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". -Axiom blocks_Receipt : - IsGlobalAlias globals blocks.globals "Receipt". - -Require bloom. -Axiom bloom_logs_bloom : - IsGlobalAlias globals bloom.globals "logs_bloom". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". - -Require state. -Axiom state_State : - IsGlobalAlias globals state.globals "State". -Axiom state_account_exists_and_is_empty : - IsGlobalAlias globals state.globals "account_exists_and_is_empty". -Axiom state_create_ether : - IsGlobalAlias globals state.globals "create_ether". -Axiom state_destroy_account : - IsGlobalAlias globals state.globals "destroy_account". -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". -Axiom state_increment_nonce : - IsGlobalAlias globals state.globals "increment_nonce". -Axiom state_set_account_balance : - IsGlobalAlias globals state.globals "set_account_balance". -Axiom state_state_root : - IsGlobalAlias globals state.globals "state_root". - -Require transactions. -Axiom transactions_TX_BASE_COST : - IsGlobalAlias globals transactions.globals "TX_BASE_COST". -Axiom transactions_TX_CREATE_COST : - IsGlobalAlias globals transactions.globals "TX_CREATE_COST". -Axiom transactions_TX_DATA_COST_PER_NON_ZERO : - IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_NON_ZERO". -Axiom transactions_TX_DATA_COST_PER_ZERO : - IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_ZERO". -Axiom transactions_Transaction : - IsGlobalAlias globals transactions.globals "Transaction". - -Require trie. -Axiom trie_Trie : - IsGlobalAlias globals trie.globals "Trie". -Axiom trie_root : - IsGlobalAlias globals trie.globals "root". -Axiom trie_trie_set : - IsGlobalAlias globals trie.globals "trie_set". - -Require utils.message. -Axiom utils_message_prepare_message : - IsGlobalAlias globals utils.message.globals "prepare_message". - -Require vm.interpreter. -Axiom vm_interpreter_process_message_call : - IsGlobalAlias globals vm.interpreter.globals "process_message_call". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U64 : + IsGlobalAlias globals ethereum.base_types.globals "U64". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_U256_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.muir_glacier.__init__. +Axiom ethereum_muir_glacier___init___vm : + IsGlobalAlias globals ethereum.muir_glacier.__init__.globals "vm". + +Require ethereum.muir_glacier.blocks. +Axiom ethereum_muir_glacier_blocks_Block : + IsGlobalAlias globals ethereum.muir_glacier.blocks.globals "Block". +Axiom ethereum_muir_glacier_blocks_Header : + IsGlobalAlias globals ethereum.muir_glacier.blocks.globals "Header". +Axiom ethereum_muir_glacier_blocks_Log : + IsGlobalAlias globals ethereum.muir_glacier.blocks.globals "Log". +Axiom ethereum_muir_glacier_blocks_Receipt : + IsGlobalAlias globals ethereum.muir_glacier.blocks.globals "Receipt". + +Require ethereum.muir_glacier.bloom. +Axiom ethereum_muir_glacier_bloom_logs_bloom : + IsGlobalAlias globals ethereum.muir_glacier.bloom.globals "logs_bloom". + +Require ethereum.muir_glacier.fork_types. +Axiom ethereum_muir_glacier_fork_types_Address : + IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "Address". +Axiom ethereum_muir_glacier_fork_types_Bloom : + IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "Bloom". +Axiom ethereum_muir_glacier_fork_types_Root : + IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "Root". + +Require ethereum.muir_glacier.state. +Axiom ethereum_muir_glacier_state_State : + IsGlobalAlias globals ethereum.muir_glacier.state.globals "State". +Axiom ethereum_muir_glacier_state_account_exists_and_is_empty : + IsGlobalAlias globals ethereum.muir_glacier.state.globals "account_exists_and_is_empty". +Axiom ethereum_muir_glacier_state_create_ether : + IsGlobalAlias globals ethereum.muir_glacier.state.globals "create_ether". +Axiom ethereum_muir_glacier_state_destroy_account : + IsGlobalAlias globals ethereum.muir_glacier.state.globals "destroy_account". +Axiom ethereum_muir_glacier_state_get_account : + IsGlobalAlias globals ethereum.muir_glacier.state.globals "get_account". +Axiom ethereum_muir_glacier_state_increment_nonce : + IsGlobalAlias globals ethereum.muir_glacier.state.globals "increment_nonce". +Axiom ethereum_muir_glacier_state_set_account_balance : + IsGlobalAlias globals ethereum.muir_glacier.state.globals "set_account_balance". +Axiom ethereum_muir_glacier_state_state_root : + IsGlobalAlias globals ethereum.muir_glacier.state.globals "state_root". + +Require ethereum.muir_glacier.transactions. +Axiom ethereum_muir_glacier_transactions_TX_BASE_COST : + IsGlobalAlias globals ethereum.muir_glacier.transactions.globals "TX_BASE_COST". +Axiom ethereum_muir_glacier_transactions_TX_CREATE_COST : + IsGlobalAlias globals ethereum.muir_glacier.transactions.globals "TX_CREATE_COST". +Axiom ethereum_muir_glacier_transactions_TX_DATA_COST_PER_NON_ZERO : + IsGlobalAlias globals ethereum.muir_glacier.transactions.globals "TX_DATA_COST_PER_NON_ZERO". +Axiom ethereum_muir_glacier_transactions_TX_DATA_COST_PER_ZERO : + IsGlobalAlias globals ethereum.muir_glacier.transactions.globals "TX_DATA_COST_PER_ZERO". +Axiom ethereum_muir_glacier_transactions_Transaction : + IsGlobalAlias globals ethereum.muir_glacier.transactions.globals "Transaction". + +Require ethereum.muir_glacier.trie. +Axiom ethereum_muir_glacier_trie_Trie : + IsGlobalAlias globals ethereum.muir_glacier.trie.globals "Trie". +Axiom ethereum_muir_glacier_trie_root : + IsGlobalAlias globals ethereum.muir_glacier.trie.globals "root". +Axiom ethereum_muir_glacier_trie_trie_set : + IsGlobalAlias globals ethereum.muir_glacier.trie.globals "trie_set". + +Require ethereum.muir_glacier.utils.message. +Axiom ethereum_muir_glacier_utils_message_prepare_message : + IsGlobalAlias globals ethereum.muir_glacier.utils.message.globals "prepare_message". + +Require ethereum.muir_glacier.vm.interpreter. +Axiom ethereum_muir_glacier_vm_interpreter_process_message_call : + IsGlobalAlias globals ethereum.muir_glacier.vm.interpreter.globals "process_message_call". Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -242,6 +242,7 @@ Definition apply_fork : Value.t -> Value.t -> M := " in let _ := M.return_ (| M.get_name (| globals, "old" |) + |) in M.pure Constant.None_)). Definition get_last_256_block_hashes : Value.t -> Value.t -> M := @@ -267,8 +268,28 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := Hashes of the recent 256 blocks in order of increasing block number. " in let recent_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |) |) in + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "recent_blocks" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + make_list [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let recent_block_hashes := @@ -307,6 +328,7 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "recent_block_hashes" |) + |) in M.pure Constant.None_)). Definition state_transition : Value.t -> Value.t -> M := @@ -438,6 +460,27 @@ Definition state_transition : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |) + ], + make_dict [] + |), + Constant.int 255 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -630,6 +673,7 @@ Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition validate_proof_of_work : Value.t -> Value.t -> M := @@ -764,6 +808,7 @@ Definition check_transaction : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "sender_address" |) + |) in M.pure Constant.None_)). Definition make_receipt : Value.t -> Value.t -> M := @@ -797,6 +842,7 @@ Definition make_receipt : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "receipt" |) + |) in M.pure Constant.None_)). Definition ApplyBodyOutput : Value.t := @@ -1007,6 +1053,7 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition validate_ommers : Value.t -> Value.t -> M := @@ -1059,6 +1106,26 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do @@ -1116,7 +1183,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let ommers_hashes := - (* At expr: unsupported node type: ListComp *) in + Constant.str "(* At expr: unsupported node type: ListComp *)" in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1147,19 +1214,19 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let recent_canonical_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| BinOp.add (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| BinOp.add (| M.get_name (| globals, "MAX_OMMER_DEPTH" |), Constant.int 1 - |) |) |) in + |) |), Constant.None_ |) |) in let recent_canonical_block_hashes := - (* At expr: unsupported node type: SetComp *) in + Constant.str "(* At expr: unsupported node type: SetComp *)" in (* At stmt: unsupported node type: AnnAssign *) For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_canonical_blocks" |) do let recent_ommers_hashes := M.call (| M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), make_list [ - (* At expr: unsupported node type: SetComp *) + Constant.str "(* At expr: unsupported node type: SetComp *)" ], make_dict [] |) in @@ -1573,7 +1640,50 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "transaction_fee" |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| + M.get_name (| globals, "coinbase_balance_after_mining_fee" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |); + M.get_name (| globals, "coinbase_balance_after_mining_fee" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -1590,11 +1700,35 @@ Definition process_transaction : Value.t -> Value.t -> M := EndFor. For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "touched_accounts" |) do let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := M.return_ (| make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |); M.get_field (| M.get_name (| globals, "output" |), "error" |) ] + |) in M.pure Constant.None_)). Definition validate_transaction : Value.t -> Value.t -> M := @@ -1649,6 +1783,7 @@ Definition validate_transaction : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := @@ -1680,6 +1815,20 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := Constant.int 0 in For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "byte" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let data_cost := BinOp.add M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in @@ -1687,6 +1836,25 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := )) |) in EndFor. let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "tx" |), "to" |), + M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) + |), + (* then *) + ltac:(M.monadic ( + let create_cost := + M.get_name (| globals, "TX_CREATE_COST" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let create_cost := Constant.int 0 in M.pure Constant.None_ @@ -1705,6 +1873,7 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition recover_sender : Value.t -> Value.t -> M := @@ -1777,6 +1946,45 @@ Definition recover_sender : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.eq (| + M.get_name (| globals, "v" |), + Constant.int 27 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "v" |), + Constant.int 28 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + BinOp.sub (| + M.get_name (| globals, "v" |), + Constant.int 27 + |); + M.call (| + M.get_name (| globals, "signing_hash_pre155" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1847,10 +2055,11 @@ Definition recover_sender : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12 |) + |), M.slice (| Constant.int 12, Constant.int 32 |) |) ], make_dict [] |) + |) in M.pure Constant.None_)). Definition signing_hash_pre155 : Value.t -> Value.t -> M := @@ -1883,6 +2092,7 @@ Definition signing_hash_pre155 : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition signing_hash_155 : Value.t -> Value.t -> M := @@ -1929,6 +2139,7 @@ Definition signing_hash_155 : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition compute_header_hash : Value.t -> Value.t -> M := @@ -1979,6 +2190,7 @@ Definition compute_header_hash : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition check_gas_limit : Value.t -> Value.t -> M := @@ -2017,16 +2229,65 @@ Definition check_gas_limit : Value.t -> Value.t -> M := M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "gas_limit" |), + BinOp.add (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "gas_limit" |), + BinOp.sub (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "gas_limit" |), + M.get_name (| globals, "GAS_LIMIT_MINIMUM" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| Constant.bool true + |) in M.pure Constant.None_)). Definition calculate_block_difficulty : Value.t -> Value.t -> M := @@ -2086,12 +2347,16 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := M.get_name (| globals, "max" |), make_list [ BinOp.sub (| - (* if *) -M.if_then_else (| - M.get_name (| globals, "parent_has_ommers" |), -(* then *) -ltac:(M.monadic ( -Constant.int 2, + (* if *) + M.if_then_else (| + M.get_name (| globals, "parent_has_ommers" |), + (* then *) + ltac:(M.monadic ( +Constant.int 2 + (* else *) + )), ltac:(M.monadic ( +Constant.int 1 + )) |), BinOp.floor_div (| M.call (| M.get_name (| globals, "int" |), @@ -2140,6 +2405,26 @@ Constant.int 2, Constant.int 2 |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "num_bomb_periods" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let difficulty := BinOp.add + BinOp.pow (| + Constant.int 2, + M.get_name (| globals, "num_bomb_periods" |) + |) + BinOp.pow (| + Constant.int 2, + M.get_name (| globals, "num_bomb_periods" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -2157,4 +2442,5 @@ Constant.int 2, ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/fork_types.v b/CoqOfPython/ethereum/muir_glacier/fork_types.v index 5c7dac3..cc8e4a1 100644 --- a/CoqOfPython/ethereum/muir_glacier/fork_types.v +++ b/CoqOfPython/ethereum/muir_glacier/fork_types.v @@ -21,29 +21,29 @@ Require dataclasses. Axiom dataclasses_dataclass : IsGlobalAlias globals dataclasses.globals "dataclass". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes20 : - IsGlobalAlias globals base_types.globals "Bytes20". -Axiom base_types_Bytes256 : - IsGlobalAlias globals base_types.globals "Bytes256". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require crypto.hash. -Axiom crypto_hash_Hash32 : - IsGlobalAlias globals crypto.hash.globals "Hash32". -Axiom crypto_hash_keccak256 : - IsGlobalAlias globals crypto.hash.globals "keccak256". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes20 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes20". +Axiom ethereum_base_types_Bytes256 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) @@ -98,4 +98,5 @@ Definition encode_account : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/state.v b/CoqOfPython/ethereum/muir_glacier/state.v index c3290a6..d83d177 100644 --- a/CoqOfPython/ethereum/muir_glacier/state.v +++ b/CoqOfPython/ethereum/muir_glacier/state.v @@ -56,29 +56,29 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require fork_types. -Axiom fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". -Axiom fork_types_Account : - IsGlobalAlias globals fork_types.globals "Account". -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". - -Require trie. -Axiom trie_EMPTY_TRIE_ROOT : - IsGlobalAlias globals trie.globals "EMPTY_TRIE_ROOT". -Axiom trie_Trie : - IsGlobalAlias globals trie.globals "Trie". -Axiom trie_copy_trie : - IsGlobalAlias globals trie.globals "copy_trie". -Axiom trie_root : - IsGlobalAlias globals trie.globals "root". -Axiom trie_trie_get : - IsGlobalAlias globals trie.globals "trie_get". -Axiom trie_trie_set : - IsGlobalAlias globals trie.globals "trie_set". +Require ethereum.muir_glacier.fork_types. +Axiom ethereum_muir_glacier_fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "EMPTY_ACCOUNT". +Axiom ethereum_muir_glacier_fork_types_Account : + IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "Account". +Axiom ethereum_muir_glacier_fork_types_Address : + IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "Address". +Axiom ethereum_muir_glacier_fork_types_Root : + IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "Root". + +Require ethereum.muir_glacier.trie. +Axiom ethereum_muir_glacier_trie_EMPTY_TRIE_ROOT : + IsGlobalAlias globals ethereum.muir_glacier.trie.globals "EMPTY_TRIE_ROOT". +Axiom ethereum_muir_glacier_trie_Trie : + IsGlobalAlias globals ethereum.muir_glacier.trie.globals "Trie". +Axiom ethereum_muir_glacier_trie_copy_trie : + IsGlobalAlias globals ethereum.muir_glacier.trie.globals "copy_trie". +Axiom ethereum_muir_glacier_trie_root : + IsGlobalAlias globals ethereum.muir_glacier.trie.globals "root". +Axiom ethereum_muir_glacier_trie_trie_get : + IsGlobalAlias globals ethereum.muir_glacier.trie.globals "trie_get". +Axiom ethereum_muir_glacier_trie_trie_set : + IsGlobalAlias globals ethereum.muir_glacier.trie.globals "trie_set". Definition State : Value.t := builtins.make_klass @@ -126,7 +126,7 @@ Definition begin_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) ], make_dict [] - |); (* At expr: unsupported node type: DictComp *) ] + |); Constant.str "(* At expr: unsupported node type: DictComp *)" ] ], make_dict [] |) in @@ -149,6 +149,19 @@ Definition commit_transaction : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "clear" |), + make_list [], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -174,6 +187,19 @@ Definition rollback_transaction : Value.t -> Value.t -> M := |) |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "clear" |), + make_list [], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -210,8 +236,27 @@ Definition get_account : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "account" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "account" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_ACCOUNT" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -246,6 +291,7 @@ Definition get_account_optional : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "account" |) + |) in M.pure Constant.None_)). Definition set_account : Value.t -> Value.t -> M := @@ -325,6 +371,18 @@ Definition destroy_storage : Value.t -> Value.t -> M := Address of account whose storage is to be deleted. " in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -387,6 +445,26 @@ Definition get_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "trie" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let value := @@ -408,6 +486,7 @@ Definition get_storage : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "value" |) + |) in M.pure Constant.None_)). Definition set_storage : Value.t -> Value.t -> M := @@ -448,6 +527,27 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "trie" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let trie := + M.call (| + M.get_name (| globals, "Trie" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), + M.get_name (| globals, "trie" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -460,6 +560,18 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + {} + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -484,8 +596,29 @@ Definition storage_root : Value.t -> Value.t -> M := " in let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_TRIE_ROOT" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -516,6 +649,7 @@ Definition state_root : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition account_exists : Value.t -> Value.t -> M := @@ -548,6 +682,7 @@ Definition account_exists : Value.t -> Value.t -> M := |), Constant.None_ |) + |) in M.pure Constant.None_)). Definition account_has_code_or_nonce : Value.t -> Value.t -> M := @@ -597,6 +732,7 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition is_account_empty : Value.t -> Value.t -> M := @@ -654,6 +790,7 @@ Definition is_account_empty : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition account_exists_and_is_empty : Value.t -> Value.t -> M := @@ -720,6 +857,7 @@ Definition account_exists_and_is_empty : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition is_account_alive : Value.t -> Value.t -> M := @@ -750,6 +888,20 @@ Definition is_account_alive : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "account" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| UnOp.not (| BoolOp.and (| Compare.eq (| @@ -777,6 +929,7 @@ Definition is_account_alive : Value.t -> Value.t -> M := |) )) |) |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -884,6 +1037,30 @@ Definition touch_account : Value.t -> Value.t -> M := The address of the account that need to initialised. " in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "account_exists" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "EMPTY_ACCOUNT" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -988,6 +1165,26 @@ Definition get_storage_original : Value.t -> Value.t -> M := Key of the storage slot. " in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -1003,6 +1200,25 @@ Definition get_storage_original : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "original_account_trie" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let original_value := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let original_value := M.call (| M.get_name (| globals, "trie_get" |), @@ -1024,4 +1240,5 @@ Definition get_storage_original : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "original_value" |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/transactions.v b/CoqOfPython/ethereum/muir_glacier/transactions.v index f94a3bd..26455ec 100644 --- a/CoqOfPython/ethereum/muir_glacier/transactions.v +++ b/CoqOfPython/ethereum/muir_glacier/transactions.v @@ -17,21 +17,21 @@ Require typing. Axiom typing_Union : IsGlobalAlias globals typing.globals "Union". -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes0 : - IsGlobalAlias globals base_types.globals "Bytes0". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.muir_glacier.fork_types. +Axiom ethereum_muir_glacier_fork_types_Address : + IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "Address". Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( Constant.int 21000 diff --git a/CoqOfPython/ethereum/muir_glacier/trie.v b/CoqOfPython/ethereum/muir_glacier/trie.v index 22e6b66..a29e0e3 100644 --- a/CoqOfPython/ethereum/muir_glacier/trie.v +++ b/CoqOfPython/ethereum/muir_glacier/trie.v @@ -54,9 +54,9 @@ Require ethereum.crypto.hash. Axiom ethereum_crypto_hash_keccak256 : IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". -Require ethereum.istanbul. -Axiom ethereum_istanbul_trie : - IsGlobalAlias globals ethereum.istanbul.globals "trie". +Require ethereum.istanbul.__init__. +Axiom ethereum_istanbul___init___trie : + IsGlobalAlias globals ethereum.istanbul.__init__.globals "trie". Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : @@ -66,37 +66,37 @@ Require ethereum.utils.hexadecimal. Axiom ethereum_utils_hexadecimal_hex_to_bytes : IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require blocks. -Axiom blocks_Receipt : - IsGlobalAlias globals blocks.globals "Receipt". - -Require fork_types. -Axiom fork_types_Account : - IsGlobalAlias globals fork_types.globals "Account". -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". -Axiom fork_types_encode_account : - IsGlobalAlias globals fork_types.globals "encode_account". - -Require transactions. -Axiom transactions_Transaction : - IsGlobalAlias globals transactions.globals "Transaction". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.muir_glacier.blocks. +Axiom ethereum_muir_glacier_blocks_Receipt : + IsGlobalAlias globals ethereum.muir_glacier.blocks.globals "Receipt". + +Require ethereum.muir_glacier.fork_types. +Axiom ethereum_muir_glacier_fork_types_Account : + IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "Account". +Axiom ethereum_muir_glacier_fork_types_Address : + IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "Address". +Axiom ethereum_muir_glacier_fork_types_Root : + IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "Root". +Axiom ethereum_muir_glacier_fork_types_encode_account : + IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "encode_account". + +Require ethereum.muir_glacier.transactions. +Axiom ethereum_muir_glacier_transactions_Transaction : + IsGlobalAlias globals ethereum.muir_glacier.transactions.globals "Transaction". Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -202,16 +202,99 @@ Definition encode_internal_node : Value.t -> Value.t -> M := " in (* At stmt: unsupported node type: AnnAssign *) let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "node" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + Constant.bytes "" in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "LeafNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "rest_of_key" |); + Constant.bool true + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "ExtensionNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "key_segment" |); + Constant.bool false + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "BranchNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + BinOp.add (| + M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "value" |) + ] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ - (* At expr: unsupported node type: JoinedStr *) + Constant.str "(* At expr: unsupported node type: JoinedStr *)" ], make_dict [] - |)) + |)) |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -229,6 +312,26 @@ Definition encode_internal_node : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded" |) + ], + make_dict [] + |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "unencoded" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_name (| globals, "keccak256" |), @@ -237,6 +340,7 @@ Definition encode_internal_node : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -250,8 +354,86 @@ Definition encode_node : Value.t -> Value.t -> M := Currently mostly an unimplemented stub. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| + M.get_name (| globals, "storage_root" |), + Constant.None_ + |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "encode_account" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "storage_root" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + make_tuple [ M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "U256" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "cast" |), + make_list [ + M.get_field (| M.get_name (| globals, "rlp" |), "RLP" |); + M.get_name (| globals, "node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "node" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "previous_trie" |), "encode_node" |), @@ -261,6 +443,7 @@ Definition encode_node : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -312,6 +495,7 @@ Definition copy_trie : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition trie_set : Value.t -> Value.t -> M := @@ -333,6 +517,32 @@ Definition trie_set : Value.t -> Value.t -> M := Node to insert at `key`. " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + M.get_field (| M.get_name (| globals, "trie" |), "default" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "key" |), + M.get_field (| M.get_name (| globals, "trie" |), "_data" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), M.get_name (| globals, "value" |) @@ -370,6 +580,7 @@ Definition trie_get : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition common_prefix_length : Value.t -> Value.t -> M := @@ -392,6 +603,34 @@ Definition common_prefix_length : Value.t -> Value.t -> M := make_dict [] |) do let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), + M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -403,6 +642,7 @@ Definition common_prefix_length : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition nibble_list_to_compact : Value.t -> Value.t -> M := @@ -448,6 +688,71 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + Constant.int 2 + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.mult (| + Constant.int 16, + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "is_leaf" |) + |) + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ @@ -509,6 +814,7 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition bytes_to_nibble_list : Value.t -> Value.t -> M := @@ -586,6 +892,7 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition _prepare_trie : Value.t -> Value.t -> M := @@ -615,6 +922,48 @@ Definition _prepare_trie : Value.t -> Value.t -> M := make_dict [] |) do let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| + M.get_name (| globals, "get_storage_root" |), + Constant.None_ + |) |) in + let address := + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |); + M.call (| + M.get_name (| globals, "get_storage_root" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let encoded_value := M.call (| M.get_name (| globals, "encode_node" |), @@ -638,6 +987,22 @@ Definition _prepare_trie : Value.t -> Value.t -> M := |) in (* At stmt: unsupported node type: AnnAssign *) let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "trie" |), "secured" |), + (* then *) + ltac:(M.monadic ( + let key := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let key := M.get_name (| globals, "preimage" |) in M.pure Constant.None_ @@ -655,6 +1020,7 @@ Definition _prepare_trie : Value.t -> Value.t -> M := EndFor. let _ := M.return_ (| M.get_name (| globals, "mapped" |) + |) in M.pure Constant.None_)). Definition root : Value.t -> Value.t -> M := @@ -708,6 +1074,44 @@ Definition root : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -724,6 +1128,7 @@ Definition root : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -750,6 +1155,26 @@ Definition patricialize : Value.t -> Value.t -> M := Root node of `obj`. " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let arbitrary_key := @@ -767,10 +1192,39 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), + Constant.int 1 + |), + (* then *) + ltac:(M.monadic ( + let leaf := + M.call (| + M.get_name (| globals, "LeafNode" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |); + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "leaf" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let substring := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |) |) in + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) in let prefix_length := M.call (| M.get_name (| globals, "len" |), @@ -789,7 +1243,7 @@ Definition patricialize : Value.t -> Value.t -> M := M.get_name (| globals, "common_prefix_length" |), make_list [ M.get_name (| globals, "substring" |); - M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) + M.get_subscript (| M.get_name (| globals, "key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) ], make_dict [] |) @@ -797,10 +1251,64 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "prefix_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "prefix_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let prefix := + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ExtensionNode" |), + make_list [ + M.get_name (| globals, "prefix" |); + M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_name (| globals, "obj" |); + BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) @@ -823,6 +1331,44 @@ Definition patricialize : Value.t -> Value.t -> M := Constant.bytes "" in For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |), + M.get_name (| globals, "level" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "AssertionError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) @@ -834,9 +1380,10 @@ Definition patricialize : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "BranchNode" |), make_list [ - (* At expr: unsupported node type: ListComp *); + Constant.str "(* At expr: unsupported node type: ListComp *)"; M.get_name (| globals, "value" |) ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/utils/address.v b/CoqOfPython/ethereum/muir_glacier/utils/address.v index 1c77416..5e9649a 100644 --- a/CoqOfPython/ethereum/muir_glacier/utils/address.v +++ b/CoqOfPython/ethereum/muir_glacier/utils/address.v @@ -38,13 +38,13 @@ Require ethereum.utils.byte. Axiom ethereum_utils_byte_left_pad_zero_bytes : IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.muir_glacier.fork_types. +Axiom ethereum_muir_glacier_fork_types_Address : + IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "Address". Definition to_address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -70,10 +70,11 @@ Definition to_address : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), make_list [], make_dict [] - |), UnOp.sub (| Constant.int 20 |) |) + |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) ], make_dict [] |) + |) in M.pure Constant.None_)). Definition compute_contract_address : Value.t -> Value.t -> M := @@ -113,7 +114,7 @@ Definition compute_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -131,6 +132,7 @@ Definition compute_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition compute_create2_contract_address : Value.t -> Value.t -> M := @@ -180,7 +182,7 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -198,4 +200,5 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/utils/hexadecimal.v b/CoqOfPython/ethereum/muir_glacier/utils/hexadecimal.v index 2934148..267f06f 100644 --- a/CoqOfPython/ethereum/muir_glacier/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/muir_glacier/utils/hexadecimal.v @@ -22,13 +22,13 @@ Require ethereum.utils.hexadecimal. Axiom ethereum_utils_hexadecimal_remove_hex_prefix : IsGlobalAlias globals ethereum.utils.hexadecimal.globals "remove_hex_prefix". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". +Require ethereum.muir_glacier.fork_types. +Axiom ethereum_muir_glacier_fork_types_Address : + IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "Address". +Axiom ethereum_muir_glacier_fork_types_Bloom : + IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "Bloom". +Axiom ethereum_muir_glacier_fork_types_Root : + IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "Root". Definition hex_to_root : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -66,6 +66,7 @@ Definition hex_to_root : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition hex_to_bloom : Value.t -> Value.t -> M := @@ -104,6 +105,7 @@ Definition hex_to_bloom : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition hex_to_address : Value.t -> Value.t -> M := @@ -149,4 +151,5 @@ Definition hex_to_address : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/utils/message.v b/CoqOfPython/ethereum/muir_glacier/utils/message.v index 2798cb9..47321ef 100644 --- a/CoqOfPython/ethereum/muir_glacier/utils/message.v +++ b/CoqOfPython/ethereum/muir_glacier/utils/message.v @@ -34,23 +34,23 @@ Axiom ethereum_base_types_Bytes0 : Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.muir_glacier.fork_types. +Axiom ethereum_muir_glacier_fork_types_Address : + IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "Address". -Require state. -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". +Require ethereum.muir_glacier.state. +Axiom ethereum_muir_glacier_state_get_account : + IsGlobalAlias globals ethereum.muir_glacier.state.globals "get_account". -Require vm. -Axiom vm_Environment : - IsGlobalAlias globals vm.globals "Environment". -Axiom vm_Message : - IsGlobalAlias globals vm.globals "Message". +Require ethereum.muir_glacier.vm.__init__. +Axiom ethereum_muir_glacier_vm___init___Environment : + IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Environment". +Axiom ethereum_muir_glacier_vm___init___Message : + IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Message". -Require address. -Axiom address_compute_contract_address : - IsGlobalAlias globals address.globals "compute_contract_address". +Require ethereum.muir_glacier.utils.address. +Axiom ethereum_muir_glacier_utils_address_compute_contract_address : + IsGlobalAlias globals ethereum.muir_glacier.utils.address.globals "compute_contract_address". Definition prepare_message : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -88,14 +88,108 @@ Definition prepare_message : Value.t -> Value.t -> M := Items containing contract creation or message call specific data. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Bytes0" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.call (| + M.get_name (| globals, "compute_contract_address" |), + make_list [ + M.get_name (| globals, "caller" |); + BinOp.sub (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "caller" |) + ], + make_dict [] + |), "nonce" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let msg_data := + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) in + let code := + M.get_name (| globals, "data" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.get_name (| globals, "target" |) in + let msg_data := + M.get_name (| globals, "data" |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "target" |) + ], + make_dict [] + |), "code" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "code_address" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let code_address := + M.get_name (| globals, "target" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "Target must be address or empty bytes" ], make_dict [] - |)) + |)) |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -106,4 +200,5 @@ Definition prepare_message : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/vm/__init__.v b/CoqOfPython/ethereum/muir_glacier/vm/__init__.v index 25f0a97..48b9cbd 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/__init__.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/__init__.v @@ -50,23 +50,23 @@ Require ethereum.crypto.hash. Axiom ethereum_crypto_hash_Hash32 : IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". +Require ethereum.muir_glacier.blocks. +Axiom ethereum_muir_glacier_blocks_Log : + IsGlobalAlias globals ethereum.muir_glacier.blocks.globals "Log". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.muir_glacier.fork_types. +Axiom ethereum_muir_glacier_fork_types_Address : + IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "Address". -Require state. -Axiom state_State : - IsGlobalAlias globals state.globals "State". -Axiom state_account_exists_and_is_empty : - IsGlobalAlias globals state.globals "account_exists_and_is_empty". +Require ethereum.muir_glacier.state. +Axiom ethereum_muir_glacier_state_State : + IsGlobalAlias globals ethereum.muir_glacier.state.globals "State". +Axiom ethereum_muir_glacier_state_account_exists_and_is_empty : + IsGlobalAlias globals ethereum.muir_glacier.state.globals "account_exists_and_is_empty". -Require precompiled_contracts. -Axiom precompiled_contracts_RIPEMD160_ADDRESS : - IsGlobalAlias globals precompiled_contracts.globals "RIPEMD160_ADDRESS". +Require ethereum.muir_glacier.vm.precompiled_contracts.__init__. +Axiom ethereum_muir_glacier_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : + IsGlobalAlias globals ethereum.muir_glacier.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] @@ -145,6 +145,28 @@ Definition incorporate_child_on_success : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -163,9 +185,63 @@ Definition incorporate_child_on_error : Value.t -> Value.t -> M := The child evm to incorporate. " in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "RIPEMD160_ADDRESS" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |), + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign_op (| diff --git a/CoqOfPython/ethereum/muir_glacier/vm/gas.v b/CoqOfPython/ethereum/muir_glacier/vm/gas.v index 765c5ef..3c89b66 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/gas.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/gas.v @@ -43,13 +43,13 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.muir_glacier.vm.__init__. +Axiom ethereum_muir_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Evm". -Require exceptions. -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". +Require ethereum.muir_glacier.vm.exceptions. +Axiom ethereum_muir_glacier_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.muir_glacier.vm.exceptions.globals "OutOfGasError". Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -530,6 +530,18 @@ Definition charge_gas : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "amount" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign_op (| BinOp.sub, M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), @@ -645,6 +657,18 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := |) in For make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ] in M.get_name (| globals, "extensions" |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "size" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let before_size := @@ -679,6 +703,18 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let size_to_extend := BinOp.add @@ -727,6 +763,7 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition calculate_message_call_gas : Value.t -> Value.t -> M := @@ -758,22 +795,56 @@ Definition calculate_message_call_gas : Value.t -> Value.t -> M := message_call_gas: `MessageCallGas` " in let call_stipend := - (* if *) -M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "call_stipend" |) + )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "gas_left" |), + BinOp.add (| + M.get_name (| globals, "extra_gas" |), + M.get_name (| globals, "memory_cost" |) + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallGas" |), + make_list [ + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "extra_gas" |) + |); + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "call_stipend" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let gas := @@ -812,6 +883,7 @@ M.call (| ], make_dict [] |) + |) in M.pure Constant.None_)). Definition max_message_call_gas : Value.t -> Value.t -> M := @@ -838,4 +910,5 @@ Definition max_message_call_gas : Value.t -> Value.t -> M := Constant.int 64 |) |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/__init__.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/__init__.v index e5bebd7..a916d0e 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/__init__.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/__init__.v @@ -26,53 +26,53 @@ Axiom typing_Callable : Axiom typing_Dict : IsGlobalAlias globals typing.globals "Dict". -Require __init__. -Axiom __init___arithmetic : - IsGlobalAlias globals __init__.globals "arithmetic". +Require ethereum.muir_glacier.vm.instructions.__init__. +Axiom ethereum_muir_glacier_vm_instructions___init___arithmetic : + IsGlobalAlias globals ethereum.muir_glacier.vm.instructions.__init__.globals "arithmetic". -Require __init__. -Axiom __init___bitwise : - IsGlobalAlias globals __init__.globals "bitwise". +Require ethereum.muir_glacier.vm.instructions.__init__. +Axiom ethereum_muir_glacier_vm_instructions___init___bitwise : + IsGlobalAlias globals ethereum.muir_glacier.vm.instructions.__init__.globals "bitwise". -Require __init__. -Axiom __init___block : - IsGlobalAlias globals __init__.globals "block". +Require ethereum.muir_glacier.vm.instructions.__init__. +Axiom ethereum_muir_glacier_vm_instructions___init___block : + IsGlobalAlias globals ethereum.muir_glacier.vm.instructions.__init__.globals "block". -Require __init__. -Axiom __init___comparison : - IsGlobalAlias globals __init__.globals "comparison". +Require ethereum.muir_glacier.vm.instructions.__init__. +Axiom ethereum_muir_glacier_vm_instructions___init___comparison : + IsGlobalAlias globals ethereum.muir_glacier.vm.instructions.__init__.globals "comparison". -Require __init__. -Axiom __init___control_flow : - IsGlobalAlias globals __init__.globals "control_flow". +Require ethereum.muir_glacier.vm.instructions.__init__. +Axiom ethereum_muir_glacier_vm_instructions___init___control_flow : + IsGlobalAlias globals ethereum.muir_glacier.vm.instructions.__init__.globals "control_flow". -Require __init__. -Axiom __init___environment : - IsGlobalAlias globals __init__.globals "environment". +Require ethereum.muir_glacier.vm.instructions.__init__. +Axiom ethereum_muir_glacier_vm_instructions___init___environment : + IsGlobalAlias globals ethereum.muir_glacier.vm.instructions.__init__.globals "environment". -Require __init__. -Axiom __init___keccak : - IsGlobalAlias globals __init__.globals "keccak". +Require ethereum.muir_glacier.vm.instructions.__init__. +Axiom ethereum_muir_glacier_vm_instructions___init___keccak : + IsGlobalAlias globals ethereum.muir_glacier.vm.instructions.__init__.globals "keccak". -Require __init__. -Axiom __init___log : - IsGlobalAlias globals __init__.globals "log". +Require ethereum.muir_glacier.vm.instructions.__init__. +Axiom ethereum_muir_glacier_vm_instructions___init___log : + IsGlobalAlias globals ethereum.muir_glacier.vm.instructions.__init__.globals "log". -Require __init__. -Axiom __init___memory : - IsGlobalAlias globals __init__.globals "memory". +Require ethereum.muir_glacier.vm.instructions.__init__. +Axiom ethereum_muir_glacier_vm_instructions___init___memory : + IsGlobalAlias globals ethereum.muir_glacier.vm.instructions.__init__.globals "memory". -Require __init__. -Axiom __init___stack : - IsGlobalAlias globals __init__.globals "stack". +Require ethereum.muir_glacier.vm.instructions.__init__. +Axiom ethereum_muir_glacier_vm_instructions___init___stack : + IsGlobalAlias globals ethereum.muir_glacier.vm.instructions.__init__.globals "stack". -Require __init__. -Axiom __init___storage : - IsGlobalAlias globals __init__.globals "storage". +Require ethereum.muir_glacier.vm.instructions.__init__. +Axiom ethereum_muir_glacier_vm_instructions___init___storage : + IsGlobalAlias globals ethereum.muir_glacier.vm.instructions.__init__.globals "storage". -Require __init__. -Axiom __init___system : - IsGlobalAlias globals __init__.globals "system". +Require ethereum.muir_glacier.vm.instructions.__init__. +Axiom ethereum_muir_glacier_vm_instructions___init___system : + IsGlobalAlias globals ethereum.muir_glacier.vm.instructions.__init__.globals "system". Definition Ops : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/arithmetic.v index 581ba5d..704eed9 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/arithmetic.v @@ -31,29 +31,29 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_get_sign : IsGlobalAlias globals ethereum.utils.numeric.globals "get_sign". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_EXPONENTIATION : - IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION". -Axiom gas_GAS_EXPONENTIATION_PER_BYTE : - IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION_PER_BYTE". -Axiom gas_GAS_LOW : - IsGlobalAlias globals gas.globals "GAS_LOW". -Axiom gas_GAS_MID : - IsGlobalAlias globals gas.globals "GAS_MID". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.muir_glacier.vm.__init__. +Axiom ethereum_muir_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Evm". + +Require ethereum.muir_glacier.vm.gas. +Axiom ethereum_muir_glacier_vm_gas_GAS_EXPONENTIATION : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_EXPONENTIATION". +Axiom ethereum_muir_glacier_vm_gas_GAS_EXPONENTIATION_PER_BYTE : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_EXPONENTIATION_PER_BYTE". +Axiom ethereum_muir_glacier_vm_gas_GAS_LOW : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_LOW". +Axiom ethereum_muir_glacier_vm_gas_GAS_MID : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_MID". +Axiom ethereum_muir_glacier_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_muir_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "charge_gas". + +Require ethereum.muir_glacier.vm.stack. +Axiom ethereum_muir_glacier_vm_stack_pop : + IsGlobalAlias globals ethereum.muir_glacier.vm.stack.globals "pop". +Axiom ethereum_muir_glacier_vm_stack_push : + IsGlobalAlias globals ethereum.muir_glacier.vm.stack.globals "push". Definition add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -273,6 +273,25 @@ Definition div : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "divisor" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let quotient := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let quotient := BinOp.floor_div (| M.get_name (| globals, "dividend" |), @@ -341,7 +360,41 @@ Definition sdiv : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "divisor" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let quotient := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_name (| globals, "dividend" |), + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "divisor" |), + UnOp.sub (| Constant.int 1 |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let quotient := + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let sign := M.call (| M.get_name (| globals, "get_sign" |), @@ -436,6 +489,25 @@ Definition mod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "y" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let remainder := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let remainder := BinOp.mod_ (| M.get_name (| globals, "x" |), @@ -504,6 +576,19 @@ Definition smod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "y" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let remainder := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let remainder := BinOp.mult (| M.call (| @@ -617,6 +702,25 @@ Definition addmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "z" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -712,6 +816,25 @@ Definition mulmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "z" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -881,6 +1004,19 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "byte_num" |), + Constant.int 31 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.get_name (| globals, "value" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let value_bytes := M.call (| M.get_name (| globals, "bytes" |), @@ -894,7 +1030,7 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let value_bytes := - M.get_subscript (| M.get_name (| globals, "value_bytes" |), BinOp.sub (| + M.get_subscript (| M.get_name (| globals, "value_bytes" |), M.slice (| BinOp.sub (| Constant.int 31, M.call (| M.get_name (| globals, "int" |), @@ -903,13 +1039,32 @@ Definition signextend : Value.t -> Value.t -> M := ], make_dict [] |) - |) |) in + |), Constant.None_ |) |) in let sign_bit := BinOp.r_shift (| M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), Constant.int 7 |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "sign_bit" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "value_bytes" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let num_bytes_prepend := BinOp.sub (| Constant.int 32, diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/bitwise.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/bitwise.v index 64cf120..a13ee9e 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/bitwise.v @@ -23,21 +23,21 @@ Axiom ethereum_base_types_U256 : Axiom ethereum_base_types_U256_CEIL_VALUE : IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.muir_glacier.vm.__init__. +Axiom ethereum_muir_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.muir_glacier.vm.gas. +Axiom ethereum_muir_glacier_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_muir_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "charge_gas". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.muir_glacier.vm.stack. +Axiom ethereum_muir_glacier_vm_stack_pop : + IsGlobalAlias globals ethereum.muir_glacier.vm.stack.globals "pop". +Axiom ethereum_muir_glacier_vm_stack_push : + IsGlobalAlias globals ethereum.muir_glacier.vm.stack.globals "push". Definition bitwise_and : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -287,6 +287,25 @@ Definition get_byte : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "byte_index" |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let extra_bytes_to_right := BinOp.sub (| Constant.int 31, @@ -366,6 +385,31 @@ Definition bitwise_shl : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "shift" |), + Constant.int 256 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.l_shift (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "shift" |) + |), + M.get_name (| globals, "U256_CEIL_VALUE" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -427,6 +471,22 @@ Definition bitwise_shr : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "shift" |), + Constant.int 256 + |), + (* then *) + ltac:(M.monadic ( + let result := + BinOp.r_shift (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "shift" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -492,7 +552,48 @@ Definition bitwise_sar : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "shift" |), + Constant.int 256 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + BinOp.r_shift (| + M.get_name (| globals, "signed_value" |), + M.get_name (| globals, "shift" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "signed_value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/block.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/block.v index f857b79..378f5fb 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/block.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/block.v @@ -21,23 +21,23 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_BLOCK_HASH : - IsGlobalAlias globals gas.globals "GAS_BLOCK_HASH". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.muir_glacier.vm.__init__. +Axiom ethereum_muir_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Evm". + +Require ethereum.muir_glacier.vm.gas. +Axiom ethereum_muir_glacier_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_BASE". +Axiom ethereum_muir_glacier_vm_gas_GAS_BLOCK_HASH : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_BLOCK_HASH". +Axiom ethereum_muir_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "charge_gas". + +Require ethereum.muir_glacier.vm.stack. +Axiom ethereum_muir_glacier_vm_stack_pop : + IsGlobalAlias globals ethereum.muir_glacier.vm.stack.globals "pop". +Axiom ethereum_muir_glacier_vm_stack_push : + IsGlobalAlias globals ethereum.muir_glacier.vm.stack.globals "push". Definition block_hash : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -69,6 +69,30 @@ Definition block_hash : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt_e (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + M.get_name (| globals, "block_number" |) + |), + ltac:(M.monadic ( + Compare.gt (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + BinOp.add (| + M.get_name (| globals, "block_number" |), + Constant.int 256 + |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let hash := + Constant.bytes "00" in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let hash := M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/comparison.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/comparison.v index b8529d8..07e7c06 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/comparison.v @@ -21,21 +21,21 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.muir_glacier.vm.__init__. +Axiom ethereum_muir_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.muir_glacier.vm.gas. +Axiom ethereum_muir_glacier_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_muir_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "charge_gas". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.muir_glacier.vm.stack. +Axiom ethereum_muir_glacier_vm_stack_pop : + IsGlobalAlias globals ethereum.muir_glacier.vm.stack.globals "pop". +Axiom ethereum_muir_glacier_vm_stack_push : + IsGlobalAlias globals ethereum.muir_glacier.vm.stack.globals "push". Definition less_than : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/control_flow.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/control_flow.v index d4e4eae..09e43fc 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/control_flow.v @@ -23,31 +23,31 @@ Axiom ethereum_base_types_U256 : Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require vm.gas. -Axiom vm_gas_GAS_BASE : - IsGlobalAlias globals vm.gas.globals "GAS_BASE". -Axiom vm_gas_GAS_HIGH : - IsGlobalAlias globals vm.gas.globals "GAS_HIGH". -Axiom vm_gas_GAS_JUMPDEST : - IsGlobalAlias globals vm.gas.globals "GAS_JUMPDEST". -Axiom vm_gas_GAS_MID : - IsGlobalAlias globals vm.gas.globals "GAS_MID". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.muir_glacier.vm.gas. +Axiom ethereum_muir_glacier_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_BASE". +Axiom ethereum_muir_glacier_vm_gas_GAS_HIGH : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_HIGH". +Axiom ethereum_muir_glacier_vm_gas_GAS_JUMPDEST : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_JUMPDEST". +Axiom ethereum_muir_glacier_vm_gas_GAS_MID : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_MID". +Axiom ethereum_muir_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "charge_gas". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.muir_glacier.vm.__init__. +Axiom ethereum_muir_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Evm". -Require exceptions. -Axiom exceptions_InvalidJumpDestError : - IsGlobalAlias globals exceptions.globals "InvalidJumpDestError". +Require ethereum.muir_glacier.vm.exceptions. +Axiom ethereum_muir_glacier_vm_exceptions_InvalidJumpDestError : + IsGlobalAlias globals ethereum.muir_glacier.vm.exceptions.globals "InvalidJumpDestError". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.muir_glacier.vm.stack. +Axiom ethereum_muir_glacier_vm_stack_pop : + IsGlobalAlias globals ethereum.muir_glacier.vm.stack.globals "pop". +Axiom ethereum_muir_glacier_vm_stack_push : + IsGlobalAlias globals ethereum.muir_glacier.vm.stack.globals "push". Definition stop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -109,6 +109,18 @@ Definition jump : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "jump_dest" |), + M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -168,7 +180,35 @@ Definition jumpi : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "conditional_value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let destination := + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "jump_dest" |), + M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let destination := M.get_name (| globals, "jump_dest" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/environment.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/environment.v index 02315c3..b766ae2 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/environment.v @@ -35,59 +35,59 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require fork_types. -Axiom fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". - -Require state. -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". - -Require utils.address. -Axiom utils_address_to_address : - IsGlobalAlias globals utils.address.globals "to_address". - -Require vm.memory. -Axiom vm_memory_buffer_read : - IsGlobalAlias globals vm.memory.globals "buffer_read". -Axiom vm_memory_memory_write : - IsGlobalAlias globals vm.memory.globals "memory_write". - -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require exceptions. -Axiom exceptions_OutOfBoundsRead : - IsGlobalAlias globals exceptions.globals "OutOfBoundsRead". - -Require gas. -Axiom gas_GAS_BALANCE : - IsGlobalAlias globals gas.globals "GAS_BALANCE". -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_CODE_HASH : - IsGlobalAlias globals gas.globals "GAS_CODE_HASH". -Axiom gas_GAS_COPY : - IsGlobalAlias globals gas.globals "GAS_COPY". -Axiom gas_GAS_EXTERNAL : - IsGlobalAlias globals gas.globals "GAS_EXTERNAL". -Axiom gas_GAS_FAST_STEP : - IsGlobalAlias globals gas.globals "GAS_FAST_STEP". -Axiom gas_GAS_RETURN_DATA_COPY : - IsGlobalAlias globals gas.globals "GAS_RETURN_DATA_COPY". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.muir_glacier.fork_types. +Axiom ethereum_muir_glacier_fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "EMPTY_ACCOUNT". + +Require ethereum.muir_glacier.state. +Axiom ethereum_muir_glacier_state_get_account : + IsGlobalAlias globals ethereum.muir_glacier.state.globals "get_account". + +Require ethereum.muir_glacier.utils.address. +Axiom ethereum_muir_glacier_utils_address_to_address : + IsGlobalAlias globals ethereum.muir_glacier.utils.address.globals "to_address". + +Require ethereum.muir_glacier.vm.memory. +Axiom ethereum_muir_glacier_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.muir_glacier.vm.memory.globals "buffer_read". +Axiom ethereum_muir_glacier_vm_memory_memory_write : + IsGlobalAlias globals ethereum.muir_glacier.vm.memory.globals "memory_write". + +Require ethereum.muir_glacier.vm.__init__. +Axiom ethereum_muir_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Evm". + +Require ethereum.muir_glacier.vm.exceptions. +Axiom ethereum_muir_glacier_vm_exceptions_OutOfBoundsRead : + IsGlobalAlias globals ethereum.muir_glacier.vm.exceptions.globals "OutOfBoundsRead". + +Require ethereum.muir_glacier.vm.gas. +Axiom ethereum_muir_glacier_vm_gas_GAS_BALANCE : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_BALANCE". +Axiom ethereum_muir_glacier_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_BASE". +Axiom ethereum_muir_glacier_vm_gas_GAS_CODE_HASH : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_CODE_HASH". +Axiom ethereum_muir_glacier_vm_gas_GAS_COPY : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_COPY". +Axiom ethereum_muir_glacier_vm_gas_GAS_EXTERNAL : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_EXTERNAL". +Axiom ethereum_muir_glacier_vm_gas_GAS_FAST_STEP : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_FAST_STEP". +Axiom ethereum_muir_glacier_vm_gas_GAS_RETURN_DATA_COPY : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_RETURN_DATA_COPY". +Axiom ethereum_muir_glacier_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_muir_glacier_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_muir_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "charge_gas". + +Require ethereum.muir_glacier.vm.stack. +Axiom ethereum_muir_glacier_vm_stack_pop : + IsGlobalAlias globals ethereum.muir_glacier.vm.stack.globals "pop". +Axiom ethereum_muir_glacier_vm_stack_push : + IsGlobalAlias globals ethereum.muir_glacier.vm.stack.globals "push". Definition address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -1134,7 +1134,10 @@ Definition returndatacopy : Value.t -> Value.t -> M := |) |) in let value := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |) |) in + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.slice (| M.get_name (| globals, "return_data_start_position" |), BinOp.add (| + M.get_name (| globals, "return_data_start_position" |), + M.get_name (| globals, "size" |) + |) |) |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -1193,6 +1196,25 @@ Definition extcodehash : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "account" |), + M.get_name (| globals, "EMPTY_ACCOUNT" |) + |), + (* then *) + ltac:(M.monadic ( + let codehash := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let codehash := M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/keccak.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/keccak.v index 2c4b10e..22153d9 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/keccak.v @@ -31,29 +31,29 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_KECCAK256 : - IsGlobalAlias globals gas.globals "GAS_KECCAK256". -Axiom gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.muir_glacier.vm.__init__. +Axiom ethereum_muir_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Evm". + +Require ethereum.muir_glacier.vm.gas. +Axiom ethereum_muir_glacier_vm_gas_GAS_KECCAK256 : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_KECCAK256". +Axiom ethereum_muir_glacier_vm_gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_KECCAK256_WORD". +Axiom ethereum_muir_glacier_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_muir_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "charge_gas". + +Require ethereum.muir_glacier.vm.memory. +Axiom ethereum_muir_glacier_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.muir_glacier.vm.memory.globals "memory_read_bytes". + +Require ethereum.muir_glacier.vm.stack. +Axiom ethereum_muir_glacier_vm_stack_pop : + IsGlobalAlias globals ethereum.muir_glacier.vm.stack.globals "pop". +Axiom ethereum_muir_glacier_vm_stack_push : + IsGlobalAlias globals ethereum.muir_glacier.vm.stack.globals "push". Definition keccak : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/log.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/log.v index e084e59..592dfcf 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/log.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/log.v @@ -29,37 +29,37 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". - -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require exceptions. -Axiom exceptions_WriteInStaticContext : - IsGlobalAlias globals exceptions.globals "WriteInStaticContext". - -Require gas. -Axiom gas_GAS_LOG : - IsGlobalAlias globals gas.globals "GAS_LOG". -Axiom gas_GAS_LOG_DATA : - IsGlobalAlias globals gas.globals "GAS_LOG_DATA". -Axiom gas_GAS_LOG_TOPIC : - IsGlobalAlias globals gas.globals "GAS_LOG_TOPIC". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". +Require ethereum.muir_glacier.blocks. +Axiom ethereum_muir_glacier_blocks_Log : + IsGlobalAlias globals ethereum.muir_glacier.blocks.globals "Log". + +Require ethereum.muir_glacier.vm.__init__. +Axiom ethereum_muir_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Evm". + +Require ethereum.muir_glacier.vm.exceptions. +Axiom ethereum_muir_glacier_vm_exceptions_WriteInStaticContext : + IsGlobalAlias globals ethereum.muir_glacier.vm.exceptions.globals "WriteInStaticContext". + +Require ethereum.muir_glacier.vm.gas. +Axiom ethereum_muir_glacier_vm_gas_GAS_LOG : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_LOG". +Axiom ethereum_muir_glacier_vm_gas_GAS_LOG_DATA : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_LOG_DATA". +Axiom ethereum_muir_glacier_vm_gas_GAS_LOG_TOPIC : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_LOG_TOPIC". +Axiom ethereum_muir_glacier_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_muir_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "charge_gas". + +Require ethereum.muir_glacier.vm.memory. +Axiom ethereum_muir_glacier_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.muir_glacier.vm.memory.globals "memory_read_bytes". + +Require ethereum.muir_glacier.vm.stack. +Axiom ethereum_muir_glacier_vm_stack_pop : + IsGlobalAlias globals ethereum.muir_glacier.vm.stack.globals "pop". Definition log_n : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/memory.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/memory.v index 86ba742..93d2906 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/memory.v @@ -23,31 +23,31 @@ Axiom ethereum_base_types_U256 : Axiom ethereum_base_types_Bytes : IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.muir_glacier.vm.__init__. +Axiom ethereum_muir_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.muir_glacier.vm.gas. +Axiom ethereum_muir_glacier_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_BASE". +Axiom ethereum_muir_glacier_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_muir_glacier_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_muir_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "charge_gas". -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". -Axiom memory_memory_write : - IsGlobalAlias globals memory.globals "memory_write". +Require ethereum.muir_glacier.vm.memory. +Axiom ethereum_muir_glacier_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.muir_glacier.vm.memory.globals "memory_read_bytes". +Axiom ethereum_muir_glacier_vm_memory_memory_write : + IsGlobalAlias globals ethereum.muir_glacier.vm.memory.globals "memory_write". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.muir_glacier.vm.stack. +Axiom ethereum_muir_glacier_vm_stack_pop : + IsGlobalAlias globals ethereum.muir_glacier.vm.stack.globals "pop". +Axiom ethereum_muir_glacier_vm_stack_push : + IsGlobalAlias globals ethereum.muir_glacier.vm.stack.globals "push". Definition mstore : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/stack.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/stack.v index 305af15..8103c7f 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/stack.v @@ -29,27 +29,27 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". -Axiom __init___stack : - IsGlobalAlias globals __init__.globals "stack". - -Require exceptions. -Axiom exceptions_StackUnderflowError : - IsGlobalAlias globals exceptions.globals "StackUnderflowError". - -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require memory. -Axiom memory_buffer_read : - IsGlobalAlias globals memory.globals "buffer_read". +Require ethereum.muir_glacier.vm.__init__. +Axiom ethereum_muir_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Evm". +Axiom ethereum_muir_glacier_vm___init___stack : + IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "stack". + +Require ethereum.muir_glacier.vm.exceptions. +Axiom ethereum_muir_glacier_vm_exceptions_StackUnderflowError : + IsGlobalAlias globals ethereum.muir_glacier.vm.exceptions.globals "StackUnderflowError". + +Require ethereum.muir_glacier.vm.gas. +Axiom ethereum_muir_glacier_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_BASE". +Axiom ethereum_muir_glacier_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_muir_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "charge_gas". + +Require ethereum.muir_glacier.vm.memory. +Axiom ethereum_muir_glacier_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.muir_glacier.vm.memory.globals "buffer_read". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/storage.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/storage.v index e55bb00..5169683 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/storage.v @@ -21,43 +21,43 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require state. -Axiom state_get_storage : - IsGlobalAlias globals state.globals "get_storage". -Axiom state_get_storage_original : - IsGlobalAlias globals state.globals "get_storage_original". -Axiom state_set_storage : - IsGlobalAlias globals state.globals "set_storage". - -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require exceptions. -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". -Axiom exceptions_WriteInStaticContext : - IsGlobalAlias globals exceptions.globals "WriteInStaticContext". - -Require gas. -Axiom gas_GAS_CALL_STIPEND : - IsGlobalAlias globals gas.globals "GAS_CALL_STIPEND". -Axiom gas_GAS_SLOAD : - IsGlobalAlias globals gas.globals "GAS_SLOAD". -Axiom gas_GAS_STORAGE_CLEAR_REFUND : - IsGlobalAlias globals gas.globals "GAS_STORAGE_CLEAR_REFUND". -Axiom gas_GAS_STORAGE_SET : - IsGlobalAlias globals gas.globals "GAS_STORAGE_SET". -Axiom gas_GAS_STORAGE_UPDATE : - IsGlobalAlias globals gas.globals "GAS_STORAGE_UPDATE". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.muir_glacier.state. +Axiom ethereum_muir_glacier_state_get_storage : + IsGlobalAlias globals ethereum.muir_glacier.state.globals "get_storage". +Axiom ethereum_muir_glacier_state_get_storage_original : + IsGlobalAlias globals ethereum.muir_glacier.state.globals "get_storage_original". +Axiom ethereum_muir_glacier_state_set_storage : + IsGlobalAlias globals ethereum.muir_glacier.state.globals "set_storage". + +Require ethereum.muir_glacier.vm.__init__. +Axiom ethereum_muir_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Evm". + +Require ethereum.muir_glacier.vm.exceptions. +Axiom ethereum_muir_glacier_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.muir_glacier.vm.exceptions.globals "OutOfGasError". +Axiom ethereum_muir_glacier_vm_exceptions_WriteInStaticContext : + IsGlobalAlias globals ethereum.muir_glacier.vm.exceptions.globals "WriteInStaticContext". + +Require ethereum.muir_glacier.vm.gas. +Axiom ethereum_muir_glacier_vm_gas_GAS_CALL_STIPEND : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_CALL_STIPEND". +Axiom ethereum_muir_glacier_vm_gas_GAS_SLOAD : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_SLOAD". +Axiom ethereum_muir_glacier_vm_gas_GAS_STORAGE_CLEAR_REFUND : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_STORAGE_CLEAR_REFUND". +Axiom ethereum_muir_glacier_vm_gas_GAS_STORAGE_SET : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_STORAGE_SET". +Axiom ethereum_muir_glacier_vm_gas_GAS_STORAGE_UPDATE : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_STORAGE_UPDATE". +Axiom ethereum_muir_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "charge_gas". + +Require ethereum.muir_glacier.vm.stack. +Axiom ethereum_muir_glacier_vm_stack_pop : + IsGlobalAlias globals ethereum.muir_glacier.vm.stack.globals "pop". +Axiom ethereum_muir_glacier_vm_stack_push : + IsGlobalAlias globals ethereum.muir_glacier.vm.stack.globals "push". Definition sload : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -181,11 +181,189 @@ Definition sstore : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_name (| globals, "original_value" |), + M.get_name (| globals, "current_value" |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "current_value" |), + M.get_name (| globals, "new_value" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "original_value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let gas_cost := + M.get_name (| globals, "GAS_STORAGE_SET" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let gas_cost := + M.get_name (| globals, "GAS_STORAGE_UPDATE" |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let gas_cost := M.get_name (| globals, "GAS_SLOAD" |) in M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| + M.get_name (| globals, "current_value" |), + M.get_name (| globals, "new_value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "original_value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "current_value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "new_value" |), + Constant.int 0 + |) + )) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "original_value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "current_value" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.sub, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "original_value" |), + M.get_name (| globals, "new_value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "original_value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_SET" |), + M.get_name (| globals, "GAS_SLOAD" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_UPDATE" |), + M.get_name (| globals, "GAS_SLOAD" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/system.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/system.v index b850f84..1697cea 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/system.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/system.v @@ -33,87 +33,87 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.muir_glacier.fork_types. +Axiom ethereum_muir_glacier_fork_types_Address : + IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "Address". -Require state. -Axiom state_account_exists_and_is_empty : - IsGlobalAlias globals state.globals "account_exists_and_is_empty". -Axiom state_account_has_code_or_nonce : - IsGlobalAlias globals state.globals "account_has_code_or_nonce". -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". -Axiom state_increment_nonce : - IsGlobalAlias globals state.globals "increment_nonce". -Axiom state_is_account_alive : - IsGlobalAlias globals state.globals "is_account_alive". -Axiom state_set_account_balance : - IsGlobalAlias globals state.globals "set_account_balance". +Require ethereum.muir_glacier.state. +Axiom ethereum_muir_glacier_state_account_exists_and_is_empty : + IsGlobalAlias globals ethereum.muir_glacier.state.globals "account_exists_and_is_empty". +Axiom ethereum_muir_glacier_state_account_has_code_or_nonce : + IsGlobalAlias globals ethereum.muir_glacier.state.globals "account_has_code_or_nonce". +Axiom ethereum_muir_glacier_state_get_account : + IsGlobalAlias globals ethereum.muir_glacier.state.globals "get_account". +Axiom ethereum_muir_glacier_state_increment_nonce : + IsGlobalAlias globals ethereum.muir_glacier.state.globals "increment_nonce". +Axiom ethereum_muir_glacier_state_is_account_alive : + IsGlobalAlias globals ethereum.muir_glacier.state.globals "is_account_alive". +Axiom ethereum_muir_glacier_state_set_account_balance : + IsGlobalAlias globals ethereum.muir_glacier.state.globals "set_account_balance". -Require utils.address. -Axiom utils_address_compute_contract_address : - IsGlobalAlias globals utils.address.globals "compute_contract_address". -Axiom utils_address_compute_create2_contract_address : - IsGlobalAlias globals utils.address.globals "compute_create2_contract_address". -Axiom utils_address_to_address : - IsGlobalAlias globals utils.address.globals "to_address". +Require ethereum.muir_glacier.utils.address. +Axiom ethereum_muir_glacier_utils_address_compute_contract_address : + IsGlobalAlias globals ethereum.muir_glacier.utils.address.globals "compute_contract_address". +Axiom ethereum_muir_glacier_utils_address_compute_create2_contract_address : + IsGlobalAlias globals ethereum.muir_glacier.utils.address.globals "compute_create2_contract_address". +Axiom ethereum_muir_glacier_utils_address_to_address : + IsGlobalAlias globals ethereum.muir_glacier.utils.address.globals "to_address". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". -Axiom __init___Message : - IsGlobalAlias globals __init__.globals "Message". -Axiom __init___incorporate_child_on_error : - IsGlobalAlias globals __init__.globals "incorporate_child_on_error". -Axiom __init___incorporate_child_on_success : - IsGlobalAlias globals __init__.globals "incorporate_child_on_success". +Require ethereum.muir_glacier.vm.__init__. +Axiom ethereum_muir_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Evm". +Axiom ethereum_muir_glacier_vm___init___Message : + IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Message". +Axiom ethereum_muir_glacier_vm___init___incorporate_child_on_error : + IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "incorporate_child_on_error". +Axiom ethereum_muir_glacier_vm___init___incorporate_child_on_success : + IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "incorporate_child_on_success". -Require exceptions. -Axiom exceptions_Revert : - IsGlobalAlias globals exceptions.globals "Revert". -Axiom exceptions_WriteInStaticContext : - IsGlobalAlias globals exceptions.globals "WriteInStaticContext". +Require ethereum.muir_glacier.vm.exceptions. +Axiom ethereum_muir_glacier_vm_exceptions_Revert : + IsGlobalAlias globals ethereum.muir_glacier.vm.exceptions.globals "Revert". +Axiom ethereum_muir_glacier_vm_exceptions_WriteInStaticContext : + IsGlobalAlias globals ethereum.muir_glacier.vm.exceptions.globals "WriteInStaticContext". -Require gas. -Axiom gas_GAS_CALL : - IsGlobalAlias globals gas.globals "GAS_CALL". -Axiom gas_GAS_CALL_VALUE : - IsGlobalAlias globals gas.globals "GAS_CALL_VALUE". -Axiom gas_GAS_CREATE : - IsGlobalAlias globals gas.globals "GAS_CREATE". -Axiom gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". -Axiom gas_GAS_NEW_ACCOUNT : - IsGlobalAlias globals gas.globals "GAS_NEW_ACCOUNT". -Axiom gas_GAS_SELF_DESTRUCT : - IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT". -Axiom gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : - IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". -Axiom gas_GAS_ZERO : - IsGlobalAlias globals gas.globals "GAS_ZERO". -Axiom gas_REFUND_SELF_DESTRUCT : - IsGlobalAlias globals gas.globals "REFUND_SELF_DESTRUCT". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_calculate_message_call_gas : - IsGlobalAlias globals gas.globals "calculate_message_call_gas". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". -Axiom gas_max_message_call_gas : - IsGlobalAlias globals gas.globals "max_message_call_gas". +Require ethereum.muir_glacier.vm.gas. +Axiom ethereum_muir_glacier_vm_gas_GAS_CALL : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_CALL". +Axiom ethereum_muir_glacier_vm_gas_GAS_CALL_VALUE : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_CALL_VALUE". +Axiom ethereum_muir_glacier_vm_gas_GAS_CREATE : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_CREATE". +Axiom ethereum_muir_glacier_vm_gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_KECCAK256_WORD". +Axiom ethereum_muir_glacier_vm_gas_GAS_NEW_ACCOUNT : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_NEW_ACCOUNT". +Axiom ethereum_muir_glacier_vm_gas_GAS_SELF_DESTRUCT : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_SELF_DESTRUCT". +Axiom ethereum_muir_glacier_vm_gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". +Axiom ethereum_muir_glacier_vm_gas_GAS_ZERO : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_ZERO". +Axiom ethereum_muir_glacier_vm_gas_REFUND_SELF_DESTRUCT : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "REFUND_SELF_DESTRUCT". +Axiom ethereum_muir_glacier_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_muir_glacier_vm_gas_calculate_message_call_gas : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "calculate_message_call_gas". +Axiom ethereum_muir_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "charge_gas". +Axiom ethereum_muir_glacier_vm_gas_max_message_call_gas : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "max_message_call_gas". -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". -Axiom memory_memory_write : - IsGlobalAlias globals memory.globals "memory_write". +Require ethereum.muir_glacier.vm.memory. +Axiom ethereum_muir_glacier_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.muir_glacier.vm.memory.globals "memory_read_bytes". +Axiom ethereum_muir_glacier_vm_memory_memory_write : + IsGlobalAlias globals ethereum.muir_glacier.vm.memory.globals "memory_write". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.muir_glacier.vm.stack. +Axiom ethereum_muir_glacier_vm_stack_pop : + IsGlobalAlias globals ethereum.muir_glacier.vm.stack.globals "pop". +Axiom ethereum_muir_glacier_vm_stack_push : + IsGlobalAlias globals ethereum.muir_glacier.vm.stack.globals "push". Definition generic_create : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -165,9 +165,113 @@ Definition generic_create : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt (| + M.get_field (| M.get_name (| globals, "sender" |), "balance" |), + M.get_name (| globals, "endowment" |) + |), + ltac:(M.monadic ( + BoolOp.or (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "sender" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.sub (| + BinOp.pow (| + Constant.int 2, + Constant.int 64 + |), + Constant.int 1 + |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.gt (| + BinOp.add (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "depth" |), + Constant.int 1 + |), + M.get_name (| globals, "STACK_DEPTH_LIMIT" |) + |) + )) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "create_message_gas" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "contract_address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let call_data := @@ -204,6 +308,40 @@ Definition generic_create : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "child_evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_error" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "incorporate_child_on_success" |), make_list [ @@ -560,6 +698,42 @@ Definition generic_call : Value.t -> Value.t -> M := Constant.bytes "" |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + BinOp.add (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "depth" |), + Constant.int 1 + |), + M.get_name (| globals, "STACK_DEPTH_LIMIT" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "gas" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let call_data := @@ -597,6 +771,40 @@ Definition generic_call : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "child_evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_error" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "incorporate_child_on_success" |), make_list [ @@ -651,7 +859,7 @@ Definition generic_call : Value.t -> Value.t -> M := make_list [ M.get_field (| M.get_name (| globals, "evm" |), "memory" |); M.get_name (| globals, "memory_output_start_position" |); - M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), Constant.None_:M.get_name (| globals, "actual_output_size" |) |) + M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), M.slice (| Constant.None_, M.get_name (| globals, "actual_output_size" |) |) |) ], make_dict [] |) in @@ -749,49 +957,57 @@ Definition call : Value.t -> Value.t -> M := make_dict [] |) in let create_gas_cost := - (* if *) -M.if_then_else (| - BoolOp.or (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), - ltac:(M.monadic ( - M.call (| - M.get_name (| globals, "is_account_alive" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); - M.get_name (| globals, "to" |) - ], - make_dict [] - |) - )) - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "is_account_alive" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "to" |) + ], + make_dict [] + |) + )) + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "GAS_NEW_ACCOUNT" |) + )) |) in let transfer_gas_cost := - (* if *) -M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "GAS_CALL_VALUE" |) + )) |) in let message_call_gas := M.call (| M.get_name (| globals, "calculate_message_call_gas" |), @@ -867,6 +1083,40 @@ M.call (| make_dict [] |), "balance" |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "sender_balance" |), + M.get_name (| globals, "value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "generic_call" |), make_list [ @@ -988,21 +1238,25 @@ Definition callcode : Value.t -> Value.t -> M := make_dict [] |) in let transfer_gas_cost := - (* if *) -M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "GAS_CALL_VALUE" |) + )) |) in let message_call_gas := M.call (| M.get_name (| globals, "calculate_message_call_gas" |), @@ -1053,6 +1307,40 @@ M.call (| make_dict [] |), "balance" |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "sender_balance" |), + M.get_name (| globals, "value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "generic_call" |), make_list [ @@ -1108,6 +1396,39 @@ Definition selfdestruct : Value.t -> Value.t -> M := let gas_cost := M.get_name (| globals, "GAS_SELF_DESTRUCT" |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + UnOp.not (| M.call (| + M.get_name (| globals, "is_account_alive" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) + M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let originator := @@ -1131,6 +1452,22 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in EndWhile. let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "originator" |), + M.get_name (| globals, "refunded_accounts" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.get_name (| globals, "REFUND_SELF_DESTRUCT" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -1202,6 +1539,28 @@ Definition selfdestruct : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -1593,6 +1952,6 @@ Definition revert : Value.t -> Value.t -> M := make_dict [] |) |) in - let _ := M.raise (| Some(M.get_name (| globals, "Revert" |)) + let _ := M.raise (| Some(M.get_name (| globals, "Revert" |)) |) in let _ := M.pass (| |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/vm/interpreter.v b/CoqOfPython/ethereum/muir_glacier/vm/interpreter.v index 5652c89..ec729e3 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/interpreter.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/interpreter.v @@ -61,81 +61,81 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". - -Require state. -Axiom state_account_exists_and_is_empty : - IsGlobalAlias globals state.globals "account_exists_and_is_empty". -Axiom state_account_has_code_or_nonce : - IsGlobalAlias globals state.globals "account_has_code_or_nonce". -Axiom state_begin_transaction : - IsGlobalAlias globals state.globals "begin_transaction". -Axiom state_commit_transaction : - IsGlobalAlias globals state.globals "commit_transaction". -Axiom state_destroy_storage : - IsGlobalAlias globals state.globals "destroy_storage". -Axiom state_increment_nonce : - IsGlobalAlias globals state.globals "increment_nonce". -Axiom state_mark_account_created : - IsGlobalAlias globals state.globals "mark_account_created". -Axiom state_move_ether : - IsGlobalAlias globals state.globals "move_ether". -Axiom state_rollback_transaction : - IsGlobalAlias globals state.globals "rollback_transaction". -Axiom state_set_code : - IsGlobalAlias globals state.globals "set_code". -Axiom state_touch_account : - IsGlobalAlias globals state.globals "touch_account". - -Require vm. -Axiom vm_Message : - IsGlobalAlias globals vm.globals "Message". - -Require vm.gas. -Axiom vm_gas_GAS_CODE_DEPOSIT : - IsGlobalAlias globals vm.gas.globals "GAS_CODE_DEPOSIT". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". - -Require vm.precompiled_contracts.mapping. -Axiom vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : - IsGlobalAlias globals vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". - -Require __init__. -Axiom __init___Environment : - IsGlobalAlias globals __init__.globals "Environment". -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require exceptions. -Axiom exceptions_AddressCollision : - IsGlobalAlias globals exceptions.globals "AddressCollision". -Axiom exceptions_ExceptionalHalt : - IsGlobalAlias globals exceptions.globals "ExceptionalHalt". -Axiom exceptions_InvalidOpcode : - IsGlobalAlias globals exceptions.globals "InvalidOpcode". -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". -Axiom exceptions_Revert : - IsGlobalAlias globals exceptions.globals "Revert". -Axiom exceptions_StackDepthLimitError : - IsGlobalAlias globals exceptions.globals "StackDepthLimitError". - -Require instructions. -Axiom instructions_Ops : - IsGlobalAlias globals instructions.globals "Ops". -Axiom instructions_op_implementation : - IsGlobalAlias globals instructions.globals "op_implementation". - -Require runtime. -Axiom runtime_get_valid_jump_destinations : - IsGlobalAlias globals runtime.globals "get_valid_jump_destinations". +Require ethereum.muir_glacier.blocks. +Axiom ethereum_muir_glacier_blocks_Log : + IsGlobalAlias globals ethereum.muir_glacier.blocks.globals "Log". + +Require ethereum.muir_glacier.fork_types. +Axiom ethereum_muir_glacier_fork_types_Address : + IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "Address". + +Require ethereum.muir_glacier.state. +Axiom ethereum_muir_glacier_state_account_exists_and_is_empty : + IsGlobalAlias globals ethereum.muir_glacier.state.globals "account_exists_and_is_empty". +Axiom ethereum_muir_glacier_state_account_has_code_or_nonce : + IsGlobalAlias globals ethereum.muir_glacier.state.globals "account_has_code_or_nonce". +Axiom ethereum_muir_glacier_state_begin_transaction : + IsGlobalAlias globals ethereum.muir_glacier.state.globals "begin_transaction". +Axiom ethereum_muir_glacier_state_commit_transaction : + IsGlobalAlias globals ethereum.muir_glacier.state.globals "commit_transaction". +Axiom ethereum_muir_glacier_state_destroy_storage : + IsGlobalAlias globals ethereum.muir_glacier.state.globals "destroy_storage". +Axiom ethereum_muir_glacier_state_increment_nonce : + IsGlobalAlias globals ethereum.muir_glacier.state.globals "increment_nonce". +Axiom ethereum_muir_glacier_state_mark_account_created : + IsGlobalAlias globals ethereum.muir_glacier.state.globals "mark_account_created". +Axiom ethereum_muir_glacier_state_move_ether : + IsGlobalAlias globals ethereum.muir_glacier.state.globals "move_ether". +Axiom ethereum_muir_glacier_state_rollback_transaction : + IsGlobalAlias globals ethereum.muir_glacier.state.globals "rollback_transaction". +Axiom ethereum_muir_glacier_state_set_code : + IsGlobalAlias globals ethereum.muir_glacier.state.globals "set_code". +Axiom ethereum_muir_glacier_state_touch_account : + IsGlobalAlias globals ethereum.muir_glacier.state.globals "touch_account". + +Require ethereum.muir_glacier.vm.__init__. +Axiom ethereum_muir_glacier_vm___init___Message : + IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Message". + +Require ethereum.muir_glacier.vm.gas. +Axiom ethereum_muir_glacier_vm_gas_GAS_CODE_DEPOSIT : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_CODE_DEPOSIT". +Axiom ethereum_muir_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "charge_gas". + +Require ethereum.muir_glacier.vm.precompiled_contracts.mapping. +Axiom ethereum_muir_glacier_vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : + IsGlobalAlias globals ethereum.muir_glacier.vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". + +Require ethereum.muir_glacier.vm.__init__. +Axiom ethereum_muir_glacier_vm___init___Environment : + IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Environment". +Axiom ethereum_muir_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Evm". + +Require ethereum.muir_glacier.vm.exceptions. +Axiom ethereum_muir_glacier_vm_exceptions_AddressCollision : + IsGlobalAlias globals ethereum.muir_glacier.vm.exceptions.globals "AddressCollision". +Axiom ethereum_muir_glacier_vm_exceptions_ExceptionalHalt : + IsGlobalAlias globals ethereum.muir_glacier.vm.exceptions.globals "ExceptionalHalt". +Axiom ethereum_muir_glacier_vm_exceptions_InvalidOpcode : + IsGlobalAlias globals ethereum.muir_glacier.vm.exceptions.globals "InvalidOpcode". +Axiom ethereum_muir_glacier_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.muir_glacier.vm.exceptions.globals "OutOfGasError". +Axiom ethereum_muir_glacier_vm_exceptions_Revert : + IsGlobalAlias globals ethereum.muir_glacier.vm.exceptions.globals "Revert". +Axiom ethereum_muir_glacier_vm_exceptions_StackDepthLimitError : + IsGlobalAlias globals ethereum.muir_glacier.vm.exceptions.globals "StackDepthLimitError". + +Require ethereum.muir_glacier.vm.instructions.__init__. +Axiom ethereum_muir_glacier_vm_instructions___init___Ops : + IsGlobalAlias globals ethereum.muir_glacier.vm.instructions.__init__.globals "Ops". +Axiom ethereum_muir_glacier_vm_instructions___init___op_implementation : + IsGlobalAlias globals ethereum.muir_glacier.vm.instructions.__init__.globals "op_implementation". + +Require ethereum.muir_glacier.vm.runtime. +Axiom ethereum_muir_glacier_vm_runtime_get_valid_jump_destinations : + IsGlobalAlias globals ethereum.muir_glacier.vm.runtime.globals "get_valid_jump_destinations". Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -182,6 +182,94 @@ Definition process_message_call : Value.t -> Value.t -> M := Output of the message call " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "message" |), "target" |), + M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) + |), + (* then *) + ltac:(M.monadic ( + let is_collision := + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_name (| globals, "is_collision" |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallOutput" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "tuple" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "AddressCollision" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let evm := + M.call (| + M.get_name (| globals, "process_create_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let evm := M.call (| M.get_name (| globals, "process_message" |), @@ -192,11 +280,74 @@ Definition process_message_call : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_field (| M.get_name (| globals, "message" |), "target" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_field (| M.get_name (| globals, "message" |), "target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( +(* At stmt: unsupported node type: AnnAssign *) + let accounts_to_delete := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let touched_accounts := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let refund_counter := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let logs := M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in let accounts_to_delete := @@ -240,6 +391,7 @@ Definition process_message_call : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). Definition process_create_message : Value.t -> Value.t -> M := @@ -301,6 +453,28 @@ Definition process_create_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), + (* then *) + ltac:(M.monadic ( + let contract_code := + M.get_field (| M.get_name (| globals, "evm" |), "output" |) in + let contract_code_gas := + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "contract_code" |) + ], + make_dict [] + |), + M.get_name (| globals, "GAS_CODE_DEPOSIT" |) + |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "rollback_transaction" |), make_list [ @@ -312,6 +486,7 @@ Definition process_create_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) + |) in M.pure Constant.None_)). Definition process_message : Value.t -> Value.t -> M := @@ -333,6 +508,24 @@ Definition process_message : Value.t -> Value.t -> M := Items containing execution specific objects " in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_field (| M.get_name (| globals, "message" |), "depth" |), + M.get_name (| globals, "STACK_DEPTH_LIMIT" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "StackDepthLimitError" |), + make_list [ + Constant.str "Stack depth limit reached" + ], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -351,6 +544,32 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + M.get_field (| M.get_name (| globals, "message" |), "should_transfer_value" |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "message" |), "value" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "move_ether" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "caller" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |); + M.get_field (| M.get_name (| globals, "message" |), "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let evm := @@ -363,6 +582,21 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "rollback_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "commit_transaction" |), make_list [ @@ -374,6 +608,7 @@ Definition process_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) + |) in M.pure Constant.None_)). Definition execute_code : Value.t -> Value.t -> M := @@ -413,4 +648,5 @@ Definition execute_code : Value.t -> Value.t -> M := (* At stmt: unsupported node type: Try *) let _ := M.return_ (| M.get_name (| globals, "evm" |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/vm/memory.v b/CoqOfPython/ethereum/muir_glacier/vm/memory.v index 4b107fd..08d2290 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/memory.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/memory.v @@ -21,13 +21,13 @@ Require ethereum.utils.byte. Axiom ethereum_utils_byte_right_pad_zero_bytes : IsGlobalAlias globals ethereum.utils.byte.globals "right_pad_zero_bytes". -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". Definition memory_write : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,7 +45,22 @@ Definition memory_write : Value.t -> Value.t -> M := Data to write to memory. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |), + M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) |) |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_)). @@ -71,7 +86,23 @@ Definition memory_read_bytes : Value.t -> Value.t -> M := Data read from memory. " in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |) + M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |) |) + |) in M.pure Constant.None_)). Definition buffer_read : Value.t -> Value.t -> M := @@ -98,9 +129,25 @@ Definition buffer_read : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "right_pad_zero_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |) |); + M.get_subscript (| M.get_name (| globals, "buffer" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |) |); M.get_name (| globals, "size" |) ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/__init__.v index ca49311..afe08fc 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/__init__.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/__init__.v @@ -18,9 +18,9 @@ Addresses of precompiled contracts and mappings to their implementations. ". -Require utils.hexadecimal. -Axiom utils_hexadecimal_hex_to_address : - IsGlobalAlias globals utils.hexadecimal.globals "hex_to_address". +Require ethereum.muir_glacier.utils.hexadecimal. +Axiom ethereum_muir_glacier_utils_hexadecimal_hex_to_address : + IsGlobalAlias globals ethereum.muir_glacier.utils.hexadecimal.globals "hex_to_address". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS"; Constant.str "MODEXP_ADDRESS"; Constant.str "ALT_BN128_ADD_ADDRESS"; Constant.str "ALT_BN128_MUL_ADDRESS"; Constant.str "ALT_BN128_PAIRING_CHECK_ADDRESS"; Constant.str "BLAKE2F_ADDRESS" ] diff --git a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/alt_bn128.v index abe4238..5eb4a47 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/alt_bn128.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/alt_bn128.v @@ -45,21 +45,21 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.muir_glacier.vm.__init__. +Axiom ethereum_muir_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.muir_glacier.vm.gas. +Axiom ethereum_muir_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "charge_gas". -Require vm.memory. -Axiom vm_memory_buffer_read : - IsGlobalAlias globals vm.memory.globals "buffer_read". +Require ethereum.muir_glacier.vm.memory. +Axiom ethereum_muir_glacier_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.muir_glacier.vm.memory.globals "buffer_read". -Require exceptions. -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". +Require ethereum.muir_glacier.vm.exceptions. +Axiom ethereum_muir_glacier_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.muir_glacier.vm.exceptions.globals "OutOfGasError". Definition alt_bn128_add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -210,6 +210,18 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) in For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ] do let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -353,6 +365,18 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) in For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ] do let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -425,6 +449,27 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| + BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 192 + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let result := @@ -464,7 +509,7 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "data" |), BinOp.add (| + M.get_subscript (| M.get_name (| globals, "data" |), M.slice (| BinOp.add (| BinOp.mult (| M.get_name (| globals, "i" |), Constant.int 192 @@ -473,11 +518,35 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := Constant.int 32, M.get_name (| globals, "j" |) |) - |) |) + |), BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "j" |), + Constant.int 1 + |) + |) + |) |) |) ], make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -538,10 +607,80 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "p" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "q" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let result := + BinOp.mult (| + M.get_name (| globals, "result" |), + M.call (| + M.get_name (| globals, "pairing" |), + make_list [ + M.get_name (| globals, "q" |); + M.get_name (| globals, "p" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "result" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| diff --git a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/blake2f.v b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/blake2f.v index 1647d48..05a1fea 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/blake2f.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/blake2f.v @@ -25,19 +25,19 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.muir_glacier.vm.__init__. +Axiom ethereum_muir_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_BLAKE2_PER_ROUND : - IsGlobalAlias globals vm.gas.globals "GAS_BLAKE2_PER_ROUND". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.muir_glacier.vm.gas. +Axiom ethereum_muir_glacier_vm_gas_GAS_BLAKE2_PER_ROUND : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_BLAKE2_PER_ROUND". +Axiom ethereum_muir_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "charge_gas". -Require exceptions. -Axiom exceptions_InvalidParameter : - IsGlobalAlias globals exceptions.globals "InvalidParameter". +Require ethereum.muir_glacier.vm.exceptions. +Axiom ethereum_muir_glacier_vm_exceptions_InvalidParameter : + IsGlobalAlias globals ethereum.muir_glacier.vm.exceptions.globals "InvalidParameter". Definition blake2f : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/ecrecover.v index 0cbcf16..d2dc0ee 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/ecrecover.v @@ -37,19 +37,19 @@ Require ethereum.utils.byte. Axiom ethereum_utils_byte_left_pad_zero_bytes : IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.muir_glacier.vm.__init__. +Axiom ethereum_muir_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_ECRECOVER : - IsGlobalAlias globals vm.gas.globals "GAS_ECRECOVER". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.muir_glacier.vm.gas. +Axiom ethereum_muir_glacier_vm_gas_GAS_ECRECOVER : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_ECRECOVER". +Axiom ethereum_muir_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "charge_gas". -Require vm.memory. -Axiom vm_memory_buffer_read : - IsGlobalAlias globals vm.memory.globals "buffer_read". +Require ethereum.muir_glacier.vm.memory. +Axiom ethereum_muir_glacier_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.muir_glacier.vm.memory.globals "buffer_read". Definition ecrecover : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -188,12 +188,78 @@ Definition ecrecover : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "v" |), + Constant.int 27 + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "v" |), + Constant.int 28 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + Constant.int 0, + M.get_name (| globals, "r" |) + |), + ltac:(M.monadic ( + Compare.gt_e (| + M.get_name (| globals, "r" |), + M.get_name (| globals, "SECP256K1N" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + Constant.int 0, + M.get_name (| globals, "s" |) + |), + ltac:(M.monadic ( + Compare.gt_e (| + M.get_name (| globals, "s" |), + M.get_name (| globals, "SECP256K1N" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: Try *) @@ -204,7 +270,7 @@ Definition ecrecover : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12 |) in + |), M.slice (| Constant.int 12, Constant.int 32 |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/identity.v index fa96704..6963212 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/identity.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/identity.v @@ -25,17 +25,17 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.muir_glacier.vm.__init__. +Axiom ethereum_muir_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_IDENTITY : - IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY". -Axiom vm_gas_GAS_IDENTITY_WORD : - IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY_WORD". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.muir_glacier.vm.gas. +Axiom ethereum_muir_glacier_vm_gas_GAS_IDENTITY : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_IDENTITY". +Axiom ethereum_muir_glacier_vm_gas_GAS_IDENTITY_WORD : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_IDENTITY_WORD". +Axiom ethereum_muir_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "charge_gas". Definition identity : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/mapping.v index 8a2e2eb..ba41ecf 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/mapping.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/mapping.v @@ -23,60 +23,60 @@ Axiom typing_Callable : Axiom typing_Dict : IsGlobalAlias globals typing.globals "Dict". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". - -Require __init__. -Axiom __init___ALT_BN128_ADD_ADDRESS : - IsGlobalAlias globals __init__.globals "ALT_BN128_ADD_ADDRESS". -Axiom __init___ALT_BN128_MUL_ADDRESS : - IsGlobalAlias globals __init__.globals "ALT_BN128_MUL_ADDRESS". -Axiom __init___ALT_BN128_PAIRING_CHECK_ADDRESS : - IsGlobalAlias globals __init__.globals "ALT_BN128_PAIRING_CHECK_ADDRESS". -Axiom __init___BLAKE2F_ADDRESS : - IsGlobalAlias globals __init__.globals "BLAKE2F_ADDRESS". -Axiom __init___ECRECOVER_ADDRESS : - IsGlobalAlias globals __init__.globals "ECRECOVER_ADDRESS". -Axiom __init___IDENTITY_ADDRESS : - IsGlobalAlias globals __init__.globals "IDENTITY_ADDRESS". -Axiom __init___MODEXP_ADDRESS : - IsGlobalAlias globals __init__.globals "MODEXP_ADDRESS". -Axiom __init___RIPEMD160_ADDRESS : - IsGlobalAlias globals __init__.globals "RIPEMD160_ADDRESS". -Axiom __init___SHA256_ADDRESS : - IsGlobalAlias globals __init__.globals "SHA256_ADDRESS". - -Require alt_bn128. -Axiom alt_bn128_alt_bn128_add : - IsGlobalAlias globals alt_bn128.globals "alt_bn128_add". -Axiom alt_bn128_alt_bn128_mul : - IsGlobalAlias globals alt_bn128.globals "alt_bn128_mul". -Axiom alt_bn128_alt_bn128_pairing_check : - IsGlobalAlias globals alt_bn128.globals "alt_bn128_pairing_check". - -Require blake2f. -Axiom blake2f_blake2f : - IsGlobalAlias globals blake2f.globals "blake2f". - -Require ecrecover. -Axiom ecrecover_ecrecover : - IsGlobalAlias globals ecrecover.globals "ecrecover". - -Require identity. -Axiom identity_identity : - IsGlobalAlias globals identity.globals "identity". - -Require modexp. -Axiom modexp_modexp : - IsGlobalAlias globals modexp.globals "modexp". - -Require ripemd160. -Axiom ripemd160_ripemd160 : - IsGlobalAlias globals ripemd160.globals "ripemd160". - -Require sha256. -Axiom sha256_sha256 : - IsGlobalAlias globals sha256.globals "sha256". +Require ethereum.muir_glacier.fork_types. +Axiom ethereum_muir_glacier_fork_types_Address : + IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "Address". + +Require ethereum.muir_glacier.vm.precompiled_contracts.__init__. +Axiom ethereum_muir_glacier_vm_precompiled_contracts___init___ALT_BN128_ADD_ADDRESS : + IsGlobalAlias globals ethereum.muir_glacier.vm.precompiled_contracts.__init__.globals "ALT_BN128_ADD_ADDRESS". +Axiom ethereum_muir_glacier_vm_precompiled_contracts___init___ALT_BN128_MUL_ADDRESS : + IsGlobalAlias globals ethereum.muir_glacier.vm.precompiled_contracts.__init__.globals "ALT_BN128_MUL_ADDRESS". +Axiom ethereum_muir_glacier_vm_precompiled_contracts___init___ALT_BN128_PAIRING_CHECK_ADDRESS : + IsGlobalAlias globals ethereum.muir_glacier.vm.precompiled_contracts.__init__.globals "ALT_BN128_PAIRING_CHECK_ADDRESS". +Axiom ethereum_muir_glacier_vm_precompiled_contracts___init___BLAKE2F_ADDRESS : + IsGlobalAlias globals ethereum.muir_glacier.vm.precompiled_contracts.__init__.globals "BLAKE2F_ADDRESS". +Axiom ethereum_muir_glacier_vm_precompiled_contracts___init___ECRECOVER_ADDRESS : + IsGlobalAlias globals ethereum.muir_glacier.vm.precompiled_contracts.__init__.globals "ECRECOVER_ADDRESS". +Axiom ethereum_muir_glacier_vm_precompiled_contracts___init___IDENTITY_ADDRESS : + IsGlobalAlias globals ethereum.muir_glacier.vm.precompiled_contracts.__init__.globals "IDENTITY_ADDRESS". +Axiom ethereum_muir_glacier_vm_precompiled_contracts___init___MODEXP_ADDRESS : + IsGlobalAlias globals ethereum.muir_glacier.vm.precompiled_contracts.__init__.globals "MODEXP_ADDRESS". +Axiom ethereum_muir_glacier_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : + IsGlobalAlias globals ethereum.muir_glacier.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". +Axiom ethereum_muir_glacier_vm_precompiled_contracts___init___SHA256_ADDRESS : + IsGlobalAlias globals ethereum.muir_glacier.vm.precompiled_contracts.__init__.globals "SHA256_ADDRESS". + +Require ethereum.muir_glacier.vm.precompiled_contracts.alt_bn128. +Axiom ethereum_muir_glacier_vm_precompiled_contracts_alt_bn128_alt_bn128_add : + IsGlobalAlias globals ethereum.muir_glacier.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_add". +Axiom ethereum_muir_glacier_vm_precompiled_contracts_alt_bn128_alt_bn128_mul : + IsGlobalAlias globals ethereum.muir_glacier.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_mul". +Axiom ethereum_muir_glacier_vm_precompiled_contracts_alt_bn128_alt_bn128_pairing_check : + IsGlobalAlias globals ethereum.muir_glacier.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_pairing_check". + +Require ethereum.muir_glacier.vm.precompiled_contracts.blake2f. +Axiom ethereum_muir_glacier_vm_precompiled_contracts_blake2f_blake2f : + IsGlobalAlias globals ethereum.muir_glacier.vm.precompiled_contracts.blake2f.globals "blake2f". + +Require ethereum.muir_glacier.vm.precompiled_contracts.ecrecover. +Axiom ethereum_muir_glacier_vm_precompiled_contracts_ecrecover_ecrecover : + IsGlobalAlias globals ethereum.muir_glacier.vm.precompiled_contracts.ecrecover.globals "ecrecover". + +Require ethereum.muir_glacier.vm.precompiled_contracts.identity. +Axiom ethereum_muir_glacier_vm_precompiled_contracts_identity_identity : + IsGlobalAlias globals ethereum.muir_glacier.vm.precompiled_contracts.identity.globals "identity". + +Require ethereum.muir_glacier.vm.precompiled_contracts.modexp. +Axiom ethereum_muir_glacier_vm_precompiled_contracts_modexp_modexp : + IsGlobalAlias globals ethereum.muir_glacier.vm.precompiled_contracts.modexp.globals "modexp". + +Require ethereum.muir_glacier.vm.precompiled_contracts.ripemd160. +Axiom ethereum_muir_glacier_vm_precompiled_contracts_ripemd160_ripemd160 : + IsGlobalAlias globals ethereum.muir_glacier.vm.precompiled_contracts.ripemd160.globals "ripemd160". + +Require ethereum.muir_glacier.vm.precompiled_contracts.sha256. +Axiom ethereum_muir_glacier_vm_precompiled_contracts_sha256_sha256 : + IsGlobalAlias globals ethereum.muir_glacier.vm.precompiled_contracts.sha256.globals "sha256". (* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/modexp.v index aff5b85..70c6865 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/modexp.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/modexp.v @@ -25,17 +25,17 @@ Axiom ethereum_base_types_Bytes : Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.muir_glacier.vm.__init__. +Axiom ethereum_muir_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.muir_glacier.vm.gas. +Axiom ethereum_muir_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "charge_gas". -Require memory. -Axiom memory_buffer_read : - IsGlobalAlias globals memory.globals "buffer_read". +Require ethereum.muir_glacier.vm.memory. +Axiom ethereum_muir_glacier_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.muir_glacier.vm.memory.globals "buffer_read". Definition GQUADDIVISOR : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -181,6 +181,39 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "exp_length" |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let adjusted_exp_length := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "max" |), + make_list [ + Constant.int 0; + BinOp.sub (| + M.call (| + M.get_field (| M.get_name (| globals, "exp_head" |), "bit_length" |), + make_list [], + make_dict [] + |), + Constant.int 1 + |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let adjusted_exp_length := M.call (| M.get_name (| globals, "Uint" |), @@ -267,6 +300,36 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_name (| globals, "base_length" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "modulus_length" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [], + make_dict [] + |) + |) in + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let base := @@ -329,6 +392,30 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "modulus" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + BinOp.mult (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + Constant.bytes "00" + ], + make_dict [] + |), + M.get_name (| globals, "modulus_length" |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| @@ -365,7 +452,53 @@ Definition get_mult_complexity : Value.t -> Value.t -> M := Estimate the complexity of performing Karatsuba multiplication. " in let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "x" |), + Constant.int 64 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.pow (| + M.get_name (| globals, "x" |), + Constant.int 2 + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "x" |), + Constant.int 1024 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.sub (| + BinOp.add (| + BinOp.floor_div (| + BinOp.pow (| + M.get_name (| globals, "x" |), + Constant.int 2 + |), + Constant.int 4 + |), + BinOp.mult (| + Constant.int 96, + M.get_name (| globals, "x" |) + |) + |), + Constant.int 3072 + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| BinOp.sub (| BinOp.add (| @@ -383,6 +516,7 @@ Definition get_mult_complexity : Value.t -> Value.t -> M := |), Constant.int 199680 |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/ripemd160.v index 96f8dcd..8a809b6 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/ripemd160.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/ripemd160.v @@ -31,17 +31,17 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.muir_glacier.vm.__init__. +Axiom ethereum_muir_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_RIPEMD160 : - IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160". -Axiom vm_gas_GAS_RIPEMD160_WORD : - IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160_WORD". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.muir_glacier.vm.gas. +Axiom ethereum_muir_glacier_vm_gas_GAS_RIPEMD160 : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_RIPEMD160". +Axiom ethereum_muir_glacier_vm_gas_GAS_RIPEMD160_WORD : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_RIPEMD160_WORD". +Axiom ethereum_muir_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "charge_gas". Definition ripemd160 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/sha256.v index 9f6d2bf..80a1266 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/sha256.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/sha256.v @@ -27,17 +27,17 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.muir_glacier.vm.__init__. +Axiom ethereum_muir_glacier_vm___init___Evm : + IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_SHA256 : - IsGlobalAlias globals vm.gas.globals "GAS_SHA256". -Axiom vm_gas_GAS_SHA256_WORD : - IsGlobalAlias globals vm.gas.globals "GAS_SHA256_WORD". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.muir_glacier.vm.gas. +Axiom ethereum_muir_glacier_vm_gas_GAS_SHA256 : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_SHA256". +Axiom ethereum_muir_glacier_vm_gas_GAS_SHA256_WORD : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_SHA256_WORD". +Axiom ethereum_muir_glacier_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "charge_gas". Definition sha256 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/muir_glacier/vm/runtime.v b/CoqOfPython/ethereum/muir_glacier/vm/runtime.v index 2cd7652..092b217 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/runtime.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/runtime.v @@ -25,9 +25,9 @@ Require ethereum.base_types. Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require instructions. -Axiom instructions_Ops : - IsGlobalAlias globals instructions.globals "Ops". +Require ethereum.muir_glacier.vm.instructions.__init__. +Axiom ethereum_muir_glacier_vm_instructions___init___Ops : + IsGlobalAlias globals ethereum.muir_glacier.vm.instructions.__init__.globals "Ops". Definition get_valid_jump_destinations : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -79,7 +79,55 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := |) do (* At stmt: unsupported node type: Try *) let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "current_opcode" |), + M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), + make_list [ + M.get_name (| globals, "pc" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.lt_e (| + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |), + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH32" |), "value" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let push_data_size := + BinOp.add (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) + |), + Constant.int 1 + |) in + let pc := BinOp.add + M.get_name (| globals, "push_data_size" |) + M.get_name (| globals, "push_data_size" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -90,4 +138,5 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := EndWhile. let _ := M.return_ (| M.get_name (| globals, "valid_jump_destinations" |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/vm/stack.v b/CoqOfPython/ethereum/muir_glacier/vm/stack.v index ea778df..7130027 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/stack.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/stack.v @@ -25,11 +25,11 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require exceptions. -Axiom exceptions_StackOverflowError : - IsGlobalAlias globals exceptions.globals "StackOverflowError". -Axiom exceptions_StackUnderflowError : - IsGlobalAlias globals exceptions.globals "StackUnderflowError". +Require ethereum.muir_glacier.vm.exceptions. +Axiom ethereum_muir_glacier_vm_exceptions_StackOverflowError : + IsGlobalAlias globals ethereum.muir_glacier.vm.exceptions.globals "StackOverflowError". +Axiom ethereum_muir_glacier_vm_exceptions_StackUnderflowError : + IsGlobalAlias globals ethereum.muir_glacier.vm.exceptions.globals "StackUnderflowError". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -49,6 +49,24 @@ Definition pop : Value.t -> Value.t -> M := " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "StackUnderflowError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -57,6 +75,7 @@ Definition pop : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). Definition push : Value.t -> Value.t -> M := @@ -75,6 +94,24 @@ Definition push : Value.t -> Value.t -> M := " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), + Constant.int 1024 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "StackOverflowError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -85,4 +122,5 @@ Definition push : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/blocks.v b/CoqOfPython/ethereum/paris/blocks.v index a90217e..667f555 100644 --- a/CoqOfPython/ethereum/paris/blocks.v +++ b/CoqOfPython/ethereum/paris/blocks.v @@ -24,35 +24,35 @@ Axiom typing_Tuple : Axiom typing_Union : IsGlobalAlias globals typing.globals "Union". -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes8 : - IsGlobalAlias globals base_types.globals "Bytes8". -Axiom base_types_Bytes32 : - IsGlobalAlias globals base_types.globals "Bytes32". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require crypto.hash. -Axiom crypto_hash_Hash32 : - IsGlobalAlias globals crypto.hash.globals "Hash32". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". - -Require transactions. -Axiom transactions_LegacyTransaction : - IsGlobalAlias globals transactions.globals "LegacyTransaction". +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes8 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes8". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". + +Require ethereum.paris.fork_types. +Axiom ethereum_paris_fork_types_Address : + IsGlobalAlias globals ethereum.paris.fork_types.globals "Address". +Axiom ethereum_paris_fork_types_Bloom : + IsGlobalAlias globals ethereum.paris.fork_types.globals "Bloom". +Axiom ethereum_paris_fork_types_Root : + IsGlobalAlias globals ethereum.paris.fork_types.globals "Root". + +Require ethereum.paris.transactions. +Axiom ethereum_paris_transactions_LegacyTransaction : + IsGlobalAlias globals ethereum.paris.transactions.globals "LegacyTransaction". Definition Header : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/paris/bloom.v b/CoqOfPython/ethereum/paris/bloom.v index 04650ff..91a6d9d 100644 --- a/CoqOfPython/ethereum/paris/bloom.v +++ b/CoqOfPython/ethereum/paris/bloom.v @@ -33,13 +33,13 @@ Require ethereum.crypto.hash. Axiom ethereum_crypto_hash_keccak256 : IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". +Require ethereum.paris.blocks. +Axiom ethereum_paris_blocks_Log : + IsGlobalAlias globals ethereum.paris.blocks.globals "Log". -Require fork_types. -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". +Require ethereum.paris.fork_types. +Axiom ethereum_paris_fork_types_Bloom : + IsGlobalAlias globals ethereum.paris.fork_types.globals "Bloom". Definition add_to_bloom : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -72,7 +72,10 @@ Definition add_to_bloom : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |) |) + M.get_subscript (| M.get_name (| globals, "hash" |), M.slice (| M.get_name (| globals, "idx" |), BinOp.add (| + M.get_name (| globals, "idx" |), + Constant.int 2 + |) |) |) ], make_dict [] |), @@ -157,4 +160,5 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/fork.v b/CoqOfPython/ethereum/paris/fork.v index 9cb256a..0dd3260 100644 --- a/CoqOfPython/ethereum/paris/fork.v +++ b/CoqOfPython/ethereum/paris/fork.v @@ -57,103 +57,103 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U64 : - IsGlobalAlias globals base_types.globals "U64". -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". - -Require __init__. -Axiom __init___vm : - IsGlobalAlias globals __init__.globals "vm". - -Require blocks. -Axiom blocks_Block : - IsGlobalAlias globals blocks.globals "Block". -Axiom blocks_Header : - IsGlobalAlias globals blocks.globals "Header". -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". -Axiom blocks_Receipt : - IsGlobalAlias globals blocks.globals "Receipt". - -Require bloom. -Axiom bloom_logs_bloom : - IsGlobalAlias globals bloom.globals "logs_bloom". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". - -Require state. -Axiom state_State : - IsGlobalAlias globals state.globals "State". -Axiom state_account_exists_and_is_empty : - IsGlobalAlias globals state.globals "account_exists_and_is_empty". -Axiom state_destroy_account : - IsGlobalAlias globals state.globals "destroy_account". -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". -Axiom state_increment_nonce : - IsGlobalAlias globals state.globals "increment_nonce". -Axiom state_set_account_balance : - IsGlobalAlias globals state.globals "set_account_balance". -Axiom state_state_root : - IsGlobalAlias globals state.globals "state_root". - -Require transactions. -Axiom transactions_TX_ACCESS_LIST_ADDRESS_COST : - IsGlobalAlias globals transactions.globals "TX_ACCESS_LIST_ADDRESS_COST". -Axiom transactions_TX_ACCESS_LIST_STORAGE_KEY_COST : - IsGlobalAlias globals transactions.globals "TX_ACCESS_LIST_STORAGE_KEY_COST". -Axiom transactions_TX_BASE_COST : - IsGlobalAlias globals transactions.globals "TX_BASE_COST". -Axiom transactions_TX_CREATE_COST : - IsGlobalAlias globals transactions.globals "TX_CREATE_COST". -Axiom transactions_TX_DATA_COST_PER_NON_ZERO : - IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_NON_ZERO". -Axiom transactions_TX_DATA_COST_PER_ZERO : - IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_ZERO". -Axiom transactions_AccessListTransaction : - IsGlobalAlias globals transactions.globals "AccessListTransaction". -Axiom transactions_FeeMarketTransaction : - IsGlobalAlias globals transactions.globals "FeeMarketTransaction". -Axiom transactions_LegacyTransaction : - IsGlobalAlias globals transactions.globals "LegacyTransaction". -Axiom transactions_Transaction : - IsGlobalAlias globals transactions.globals "Transaction". -Axiom transactions_decode_transaction : - IsGlobalAlias globals transactions.globals "decode_transaction". -Axiom transactions_encode_transaction : - IsGlobalAlias globals transactions.globals "encode_transaction". - -Require trie. -Axiom trie_Trie : - IsGlobalAlias globals trie.globals "Trie". -Axiom trie_root : - IsGlobalAlias globals trie.globals "root". -Axiom trie_trie_set : - IsGlobalAlias globals trie.globals "trie_set". - -Require utils.message. -Axiom utils_message_prepare_message : - IsGlobalAlias globals utils.message.globals "prepare_message". - -Require vm.interpreter. -Axiom vm_interpreter_process_message_call : - IsGlobalAlias globals vm.interpreter.globals "process_message_call". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U64 : + IsGlobalAlias globals ethereum.base_types.globals "U64". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.paris.__init__. +Axiom ethereum_paris___init___vm : + IsGlobalAlias globals ethereum.paris.__init__.globals "vm". + +Require ethereum.paris.blocks. +Axiom ethereum_paris_blocks_Block : + IsGlobalAlias globals ethereum.paris.blocks.globals "Block". +Axiom ethereum_paris_blocks_Header : + IsGlobalAlias globals ethereum.paris.blocks.globals "Header". +Axiom ethereum_paris_blocks_Log : + IsGlobalAlias globals ethereum.paris.blocks.globals "Log". +Axiom ethereum_paris_blocks_Receipt : + IsGlobalAlias globals ethereum.paris.blocks.globals "Receipt". + +Require ethereum.paris.bloom. +Axiom ethereum_paris_bloom_logs_bloom : + IsGlobalAlias globals ethereum.paris.bloom.globals "logs_bloom". + +Require ethereum.paris.fork_types. +Axiom ethereum_paris_fork_types_Address : + IsGlobalAlias globals ethereum.paris.fork_types.globals "Address". +Axiom ethereum_paris_fork_types_Bloom : + IsGlobalAlias globals ethereum.paris.fork_types.globals "Bloom". +Axiom ethereum_paris_fork_types_Root : + IsGlobalAlias globals ethereum.paris.fork_types.globals "Root". + +Require ethereum.paris.state. +Axiom ethereum_paris_state_State : + IsGlobalAlias globals ethereum.paris.state.globals "State". +Axiom ethereum_paris_state_account_exists_and_is_empty : + IsGlobalAlias globals ethereum.paris.state.globals "account_exists_and_is_empty". +Axiom ethereum_paris_state_destroy_account : + IsGlobalAlias globals ethereum.paris.state.globals "destroy_account". +Axiom ethereum_paris_state_get_account : + IsGlobalAlias globals ethereum.paris.state.globals "get_account". +Axiom ethereum_paris_state_increment_nonce : + IsGlobalAlias globals ethereum.paris.state.globals "increment_nonce". +Axiom ethereum_paris_state_set_account_balance : + IsGlobalAlias globals ethereum.paris.state.globals "set_account_balance". +Axiom ethereum_paris_state_state_root : + IsGlobalAlias globals ethereum.paris.state.globals "state_root". + +Require ethereum.paris.transactions. +Axiom ethereum_paris_transactions_TX_ACCESS_LIST_ADDRESS_COST : + IsGlobalAlias globals ethereum.paris.transactions.globals "TX_ACCESS_LIST_ADDRESS_COST". +Axiom ethereum_paris_transactions_TX_ACCESS_LIST_STORAGE_KEY_COST : + IsGlobalAlias globals ethereum.paris.transactions.globals "TX_ACCESS_LIST_STORAGE_KEY_COST". +Axiom ethereum_paris_transactions_TX_BASE_COST : + IsGlobalAlias globals ethereum.paris.transactions.globals "TX_BASE_COST". +Axiom ethereum_paris_transactions_TX_CREATE_COST : + IsGlobalAlias globals ethereum.paris.transactions.globals "TX_CREATE_COST". +Axiom ethereum_paris_transactions_TX_DATA_COST_PER_NON_ZERO : + IsGlobalAlias globals ethereum.paris.transactions.globals "TX_DATA_COST_PER_NON_ZERO". +Axiom ethereum_paris_transactions_TX_DATA_COST_PER_ZERO : + IsGlobalAlias globals ethereum.paris.transactions.globals "TX_DATA_COST_PER_ZERO". +Axiom ethereum_paris_transactions_AccessListTransaction : + IsGlobalAlias globals ethereum.paris.transactions.globals "AccessListTransaction". +Axiom ethereum_paris_transactions_FeeMarketTransaction : + IsGlobalAlias globals ethereum.paris.transactions.globals "FeeMarketTransaction". +Axiom ethereum_paris_transactions_LegacyTransaction : + IsGlobalAlias globals ethereum.paris.transactions.globals "LegacyTransaction". +Axiom ethereum_paris_transactions_Transaction : + IsGlobalAlias globals ethereum.paris.transactions.globals "Transaction". +Axiom ethereum_paris_transactions_decode_transaction : + IsGlobalAlias globals ethereum.paris.transactions.globals "decode_transaction". +Axiom ethereum_paris_transactions_encode_transaction : + IsGlobalAlias globals ethereum.paris.transactions.globals "encode_transaction". + +Require ethereum.paris.trie. +Axiom ethereum_paris_trie_Trie : + IsGlobalAlias globals ethereum.paris.trie.globals "Trie". +Axiom ethereum_paris_trie_root : + IsGlobalAlias globals ethereum.paris.trie.globals "root". +Axiom ethereum_paris_trie_trie_set : + IsGlobalAlias globals ethereum.paris.trie.globals "trie_set". + +Require ethereum.paris.utils.message. +Axiom ethereum_paris_utils_message_prepare_message : + IsGlobalAlias globals ethereum.paris.utils.message.globals "prepare_message". + +Require ethereum.paris.vm.interpreter. +Axiom ethereum_paris_vm_interpreter_process_message_call : + IsGlobalAlias globals ethereum.paris.vm.interpreter.globals "process_message_call". Definition BASE_FEE_MAX_CHANGE_DENOMINATOR : Value.t := M.run ltac:(M.monadic ( Constant.int 8 @@ -220,6 +220,7 @@ Definition apply_fork : Value.t -> Value.t -> M := " in let _ := M.return_ (| M.get_name (| globals, "old" |) + |) in M.pure Constant.None_)). Definition get_last_256_block_hashes : Value.t -> Value.t -> M := @@ -245,8 +246,28 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := Hashes of the recent 256 blocks in order of increasing block number. " in let recent_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |) |) in + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "recent_blocks" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + make_list [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let recent_block_hashes := @@ -285,6 +306,7 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "recent_block_hashes" |) + |) in M.pure Constant.None_)). Definition state_transition : Value.t -> Value.t -> M := @@ -418,6 +440,27 @@ Definition state_transition : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |) + ], + make_dict [] + |), + Constant.int 255 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -465,7 +508,63 @@ Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "parent_gas_used" |), + M.get_name (| globals, "parent_gas_target" |) + |), + (* then *) + ltac:(M.monadic ( + let expected_base_fee_per_gas := + M.get_name (| globals, "parent_base_fee_per_gas" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "parent_gas_used" |), + M.get_name (| globals, "parent_gas_target" |) + |), + (* then *) + ltac:(M.monadic ( + let gas_used_delta := + BinOp.sub (| + M.get_name (| globals, "parent_gas_used" |), + M.get_name (| globals, "parent_gas_target" |) + |) in + let parent_fee_gas_delta := + BinOp.mult (| + M.get_name (| globals, "parent_base_fee_per_gas" |), + M.get_name (| globals, "gas_used_delta" |) + |) in + let target_fee_gas_delta := + BinOp.floor_div (| + M.get_name (| globals, "parent_fee_gas_delta" |), + M.get_name (| globals, "parent_gas_target" |) + |) in + let base_fee_per_gas_delta := + M.call (| + M.get_name (| globals, "max" |), + make_list [ + BinOp.floor_div (| + M.get_name (| globals, "target_fee_gas_delta" |), + M.get_name (| globals, "BASE_FEE_MAX_CHANGE_DENOMINATOR" |) + |); + Constant.int 1 + ], + make_dict [] + |) in + let expected_base_fee_per_gas := + BinOp.add (| + M.get_name (| globals, "parent_base_fee_per_gas" |), + M.get_name (| globals, "base_fee_per_gas_delta" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let gas_used_delta := BinOp.sub (| M.get_name (| globals, "parent_gas_target" |), @@ -503,6 +602,7 @@ Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition validate_header : Value.t -> Value.t -> M := @@ -710,6 +810,60 @@ Definition check_transaction : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "FeeMarketTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt_e (| + M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |), + M.get_field (| M.get_name (| globals, "tx" |), "max_priority_fee_per_gas" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt_e (| + M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |), + M.get_name (| globals, "base_fee_per_gas" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let priority_fee_per_gas := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_field (| M.get_name (| globals, "tx" |), "max_priority_fee_per_gas" |); + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |), + M.get_name (| globals, "base_fee_per_gas" |) + |) + ], + make_dict [] + |) in + let effective_gas_price := + BinOp.add (| + M.get_name (| globals, "priority_fee_per_gas" |), + M.get_name (| globals, "base_fee_per_gas" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -727,6 +881,7 @@ Definition check_transaction : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| make_tuple [ M.get_name (| globals, "sender_address" |); M.get_name (| globals, "effective_gas_price" |) ] + |) in M.pure Constant.None_)). Definition make_receipt : Value.t -> Value.t -> M := @@ -759,9 +914,64 @@ Definition make_receipt : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "AccessListTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + Constant.bytes "01", + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "receipt" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "FeeMarketTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + Constant.bytes "02", + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "receipt" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "receipt" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -984,6 +1194,7 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition process_transaction : Value.t -> Value.t -> M := @@ -1041,6 +1252,26 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "FeeMarketTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let max_gas_fee := + BinOp.mult (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let max_gas_fee := BinOp.mult (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), @@ -1139,6 +1370,39 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + make_tuple [ M.get_name (| globals, "AccessListTransaction" |); M.get_name (| globals, "FeeMarketTransaction" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + For make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "keys" |) ] in M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "preaccessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "key" |) in M.get_name (| globals, "keys" |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "preaccessed_storage_keys" |), "add" |), + make_list [ + make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "key" |) ] + ], + make_dict [] + |) in + EndFor. + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let message := @@ -1243,7 +1507,50 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "transaction_fee" |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| + M.get_name (| globals, "coinbase_balance_after_mining_fee" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |); + M.get_name (| globals, "coinbase_balance_after_mining_fee" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -1260,11 +1567,35 @@ Definition process_transaction : Value.t -> Value.t -> M := EndFor. For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "touched_accounts" |) do let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := M.return_ (| make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |); M.get_field (| M.get_name (| globals, "output" |), "error" |) ] + |) in M.pure Constant.None_)). Definition validate_transaction : Value.t -> Value.t -> M := @@ -1319,6 +1650,7 @@ Definition validate_transaction : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := @@ -1350,6 +1682,20 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := Constant.int 0 in For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "byte" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let data_cost := BinOp.add M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in @@ -1357,6 +1703,25 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := )) |) in EndFor. let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "tx" |), "to" |), + M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) + |), + (* then *) + ltac:(M.monadic ( + let create_cost := + M.get_name (| globals, "TX_CREATE_COST" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let create_cost := Constant.int 0 in M.pure Constant.None_ @@ -1364,6 +1729,47 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := let access_list_cost := Constant.int 0 in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + make_tuple [ M.get_name (| globals, "AccessListTransaction" |); M.get_name (| globals, "FeeMarketTransaction" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + For make_tuple [ M.get_name (| globals, "_address" |); M.get_name (| globals, "keys" |) ] in M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) do + let access_list_cost := BinOp.add + M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) + M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) in + let access_list_cost := BinOp.add + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "keys" |) + ], + make_dict [] + |), + M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) + |) + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "keys" |) + ], + make_dict [] + |), + M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) + |) in + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1383,6 +1789,7 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition recover_sender : Value.t -> Value.t -> M := @@ -1455,8 +1862,189 @@ Definition recover_sender : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "LegacyTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let v := + M.get_field (| M.get_name (| globals, "tx" |), "v" |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.eq (| + M.get_name (| globals, "v" |), + Constant.int 27 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "v" |), + Constant.int 28 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + BinOp.sub (| + M.get_name (| globals, "v" |), + Constant.int 27 + |); + M.call (| + M.get_name (| globals, "signing_hash_pre155" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.or (| + Compare.eq (| + M.get_name (| globals, "v" |), + BinOp.add (| + Constant.int 35, + BinOp.mult (| + M.get_name (| globals, "chain_id" |), + Constant.int 2 + |) + |) + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "v" |), + BinOp.add (| + Constant.int 36, + BinOp.mult (| + M.get_name (| globals, "chain_id" |), + Constant.int 2 + |) + |) + |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + BinOp.sub (| + BinOp.sub (| + M.get_name (| globals, "v" |), + Constant.int 35 + |), + BinOp.mult (| + M.get_name (| globals, "chain_id" |), + Constant.int 2 + |) + |); + M.call (| + M.get_name (| globals, "signing_hash_155" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "chain_id" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "AccessListTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + M.get_field (| M.get_name (| globals, "tx" |), "y_parity" |); + M.call (| + M.get_name (| globals, "signing_hash_2930" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "FeeMarketTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + M.get_field (| M.get_name (| globals, "tx" |), "y_parity" |); + M.call (| + M.get_name (| globals, "signing_hash_1559" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -1473,10 +2061,11 @@ Definition recover_sender : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12 |) + |), M.slice (| Constant.int 12, Constant.int 32 |) |) ], make_dict [] |) + |) in M.pure Constant.None_)). Definition signing_hash_pre155 : Value.t -> Value.t -> M := @@ -1509,6 +2098,7 @@ Definition signing_hash_pre155 : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition signing_hash_155 : Value.t -> Value.t -> M := @@ -1555,6 +2145,7 @@ Definition signing_hash_155 : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition signing_hash_2930 : Value.t -> Value.t -> M := @@ -1590,6 +2181,7 @@ Definition signing_hash_2930 : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition signing_hash_1559 : Value.t -> Value.t -> M := @@ -1625,6 +2217,7 @@ Definition signing_hash_1559 : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition compute_header_hash : Value.t -> Value.t -> M := @@ -1675,6 +2268,7 @@ Definition compute_header_hash : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition check_gas_limit : Value.t -> Value.t -> M := @@ -1713,14 +2307,63 @@ Definition check_gas_limit : Value.t -> Value.t -> M := M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "gas_limit" |), + BinOp.add (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "gas_limit" |), + BinOp.sub (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "gas_limit" |), + M.get_name (| globals, "GAS_LIMIT_MINIMUM" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| Constant.bool true + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/fork_types.v b/CoqOfPython/ethereum/paris/fork_types.v index 5c7dac3..cc8e4a1 100644 --- a/CoqOfPython/ethereum/paris/fork_types.v +++ b/CoqOfPython/ethereum/paris/fork_types.v @@ -21,29 +21,29 @@ Require dataclasses. Axiom dataclasses_dataclass : IsGlobalAlias globals dataclasses.globals "dataclass". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes20 : - IsGlobalAlias globals base_types.globals "Bytes20". -Axiom base_types_Bytes256 : - IsGlobalAlias globals base_types.globals "Bytes256". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require crypto.hash. -Axiom crypto_hash_Hash32 : - IsGlobalAlias globals crypto.hash.globals "Hash32". -Axiom crypto_hash_keccak256 : - IsGlobalAlias globals crypto.hash.globals "keccak256". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes20 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes20". +Axiom ethereum_base_types_Bytes256 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) @@ -98,4 +98,5 @@ Definition encode_account : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/state.v b/CoqOfPython/ethereum/paris/state.v index d814ed9..e044783 100644 --- a/CoqOfPython/ethereum/paris/state.v +++ b/CoqOfPython/ethereum/paris/state.v @@ -56,29 +56,29 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require fork_types. -Axiom fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". -Axiom fork_types_Account : - IsGlobalAlias globals fork_types.globals "Account". -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". - -Require trie. -Axiom trie_EMPTY_TRIE_ROOT : - IsGlobalAlias globals trie.globals "EMPTY_TRIE_ROOT". -Axiom trie_Trie : - IsGlobalAlias globals trie.globals "Trie". -Axiom trie_copy_trie : - IsGlobalAlias globals trie.globals "copy_trie". -Axiom trie_root : - IsGlobalAlias globals trie.globals "root". -Axiom trie_trie_get : - IsGlobalAlias globals trie.globals "trie_get". -Axiom trie_trie_set : - IsGlobalAlias globals trie.globals "trie_set". +Require ethereum.paris.fork_types. +Axiom ethereum_paris_fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals ethereum.paris.fork_types.globals "EMPTY_ACCOUNT". +Axiom ethereum_paris_fork_types_Account : + IsGlobalAlias globals ethereum.paris.fork_types.globals "Account". +Axiom ethereum_paris_fork_types_Address : + IsGlobalAlias globals ethereum.paris.fork_types.globals "Address". +Axiom ethereum_paris_fork_types_Root : + IsGlobalAlias globals ethereum.paris.fork_types.globals "Root". + +Require ethereum.paris.trie. +Axiom ethereum_paris_trie_EMPTY_TRIE_ROOT : + IsGlobalAlias globals ethereum.paris.trie.globals "EMPTY_TRIE_ROOT". +Axiom ethereum_paris_trie_Trie : + IsGlobalAlias globals ethereum.paris.trie.globals "Trie". +Axiom ethereum_paris_trie_copy_trie : + IsGlobalAlias globals ethereum.paris.trie.globals "copy_trie". +Axiom ethereum_paris_trie_root : + IsGlobalAlias globals ethereum.paris.trie.globals "root". +Axiom ethereum_paris_trie_trie_get : + IsGlobalAlias globals ethereum.paris.trie.globals "trie_get". +Axiom ethereum_paris_trie_trie_set : + IsGlobalAlias globals ethereum.paris.trie.globals "trie_set". Definition State : Value.t := builtins.make_klass @@ -126,7 +126,7 @@ Definition begin_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) ], make_dict [] - |); (* At expr: unsupported node type: DictComp *) ] + |); Constant.str "(* At expr: unsupported node type: DictComp *)" ] ], make_dict [] |) in @@ -149,6 +149,19 @@ Definition commit_transaction : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "clear" |), + make_list [], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -174,6 +187,19 @@ Definition rollback_transaction : Value.t -> Value.t -> M := |) |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "clear" |), + make_list [], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -210,8 +236,27 @@ Definition get_account : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "account" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "account" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_ACCOUNT" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -246,6 +291,7 @@ Definition get_account_optional : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "account" |) + |) in M.pure Constant.None_)). Definition set_account : Value.t -> Value.t -> M := @@ -325,6 +371,18 @@ Definition destroy_storage : Value.t -> Value.t -> M := Address of account whose storage is to be deleted. " in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -387,6 +445,26 @@ Definition get_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "trie" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let value := @@ -408,6 +486,7 @@ Definition get_storage : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "value" |) + |) in M.pure Constant.None_)). Definition set_storage : Value.t -> Value.t -> M := @@ -448,6 +527,27 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "trie" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let trie := + M.call (| + M.get_name (| globals, "Trie" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), + M.get_name (| globals, "trie" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -460,6 +560,18 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + {} + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -484,8 +596,29 @@ Definition storage_root : Value.t -> Value.t -> M := " in let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_TRIE_ROOT" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -516,6 +649,7 @@ Definition state_root : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition account_exists : Value.t -> Value.t -> M := @@ -548,6 +682,7 @@ Definition account_exists : Value.t -> Value.t -> M := |), Constant.None_ |) + |) in M.pure Constant.None_)). Definition account_has_code_or_nonce : Value.t -> Value.t -> M := @@ -597,6 +732,7 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition is_account_empty : Value.t -> Value.t -> M := @@ -654,6 +790,7 @@ Definition is_account_empty : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition account_exists_and_is_empty : Value.t -> Value.t -> M := @@ -720,6 +857,7 @@ Definition account_exists_and_is_empty : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition is_account_alive : Value.t -> Value.t -> M := @@ -750,6 +888,20 @@ Definition is_account_alive : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "account" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| UnOp.not (| BoolOp.and (| Compare.eq (| @@ -777,6 +929,7 @@ Definition is_account_alive : Value.t -> Value.t -> M := |) )) |) |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -884,6 +1037,30 @@ Definition touch_account : Value.t -> Value.t -> M := The address of the account that need to initialised. " in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "account_exists" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "EMPTY_ACCOUNT" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -961,6 +1138,26 @@ Definition get_storage_original : Value.t -> Value.t -> M := Key of the storage slot. " in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -976,6 +1173,25 @@ Definition get_storage_original : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "original_account_trie" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let original_value := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let original_value := M.call (| M.get_name (| globals, "trie_get" |), @@ -997,4 +1213,5 @@ Definition get_storage_original : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "original_value" |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/transactions.v b/CoqOfPython/ethereum/paris/transactions.v index afa27ec..d16cff9 100644 --- a/CoqOfPython/ethereum/paris/transactions.v +++ b/CoqOfPython/ethereum/paris/transactions.v @@ -19,33 +19,33 @@ Axiom typing_Tuple : Axiom typing_Union : IsGlobalAlias globals typing.globals "Union". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U64 : - IsGlobalAlias globals base_types.globals "U64". -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes0 : - IsGlobalAlias globals base_types.globals "Bytes0". -Axiom base_types_Bytes32 : - IsGlobalAlias globals base_types.globals "Bytes32". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require exceptions. -Axiom exceptions_InvalidBlock : - IsGlobalAlias globals exceptions.globals "InvalidBlock". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U64 : + IsGlobalAlias globals ethereum.base_types.globals "U64". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.exceptions. +Axiom ethereum_exceptions_InvalidBlock : + IsGlobalAlias globals ethereum.exceptions.globals "InvalidBlock". + +Require ethereum.paris.fork_types. +Axiom ethereum_paris_fork_types_Address : + IsGlobalAlias globals ethereum.paris.fork_types.globals "Address". Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( Constant.int 21000 @@ -112,15 +112,87 @@ Definition encode_transaction : Value.t -> Value.t -> M := Encode a transaction. Needed because non-legacy transactions aren't RLP. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "LegacyTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "tx" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "AccessListTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + Constant.bytes "01", + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "FeeMarketTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + Constant.bytes "02", + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.raise (| Some(M.call (| M.get_name (| globals, "Exception" |), make_list [ - (* At expr: unsupported node type: JoinedStr *) + Constant.str "(* At expr: unsupported node type: JoinedStr *)" ], make_dict [] - |)) + |)) |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -136,8 +208,73 @@ Definition decode_transaction : Value.t -> Value.t -> M := Decode a transaction. Needed because non-legacy transactions aren't RLP. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), + Constant.int 1 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), + make_list [ + M.get_name (| globals, "AccessListTransaction" |); + M.get_subscript (| M.get_name (| globals, "tx" |), M.slice (| Constant.int 1, Constant.None_ |) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), + Constant.int 2 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), + make_list [ + M.get_name (| globals, "FeeMarketTransaction" |); + M.get_subscript (| M.get_name (| globals, "tx" |), M.slice (| Constant.int 1, Constant.None_ |) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidBlock" |)) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "tx" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/trie.v b/CoqOfPython/ethereum/paris/trie.v index b383128..41d8641 100644 --- a/CoqOfPython/ethereum/paris/trie.v +++ b/CoqOfPython/ethereum/paris/trie.v @@ -54,9 +54,9 @@ Require ethereum.crypto.hash. Axiom ethereum_crypto_hash_keccak256 : IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". -Require ethereum.gray_glacier. -Axiom ethereum_gray_glacier_trie : - IsGlobalAlias globals ethereum.gray_glacier.globals "trie". +Require ethereum.gray_glacier.__init__. +Axiom ethereum_gray_glacier___init___trie : + IsGlobalAlias globals ethereum.gray_glacier.__init__.globals "trie". Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : @@ -66,37 +66,37 @@ Require ethereum.utils.hexadecimal. Axiom ethereum_utils_hexadecimal_hex_to_bytes : IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require blocks. -Axiom blocks_Receipt : - IsGlobalAlias globals blocks.globals "Receipt". - -Require fork_types. -Axiom fork_types_Account : - IsGlobalAlias globals fork_types.globals "Account". -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". -Axiom fork_types_encode_account : - IsGlobalAlias globals fork_types.globals "encode_account". - -Require transactions. -Axiom transactions_LegacyTransaction : - IsGlobalAlias globals transactions.globals "LegacyTransaction". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.paris.blocks. +Axiom ethereum_paris_blocks_Receipt : + IsGlobalAlias globals ethereum.paris.blocks.globals "Receipt". + +Require ethereum.paris.fork_types. +Axiom ethereum_paris_fork_types_Account : + IsGlobalAlias globals ethereum.paris.fork_types.globals "Account". +Axiom ethereum_paris_fork_types_Address : + IsGlobalAlias globals ethereum.paris.fork_types.globals "Address". +Axiom ethereum_paris_fork_types_Root : + IsGlobalAlias globals ethereum.paris.fork_types.globals "Root". +Axiom ethereum_paris_fork_types_encode_account : + IsGlobalAlias globals ethereum.paris.fork_types.globals "encode_account". + +Require ethereum.paris.transactions. +Axiom ethereum_paris_transactions_LegacyTransaction : + IsGlobalAlias globals ethereum.paris.transactions.globals "LegacyTransaction". Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -202,16 +202,99 @@ Definition encode_internal_node : Value.t -> Value.t -> M := " in (* At stmt: unsupported node type: AnnAssign *) let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "node" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + Constant.bytes "" in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "LeafNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "rest_of_key" |); + Constant.bool true + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "ExtensionNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "key_segment" |); + Constant.bool false + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "BranchNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + BinOp.add (| + M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "value" |) + ] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ - (* At expr: unsupported node type: JoinedStr *) + Constant.str "(* At expr: unsupported node type: JoinedStr *)" ], make_dict [] - |)) + |)) |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -229,6 +312,26 @@ Definition encode_internal_node : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded" |) + ], + make_dict [] + |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "unencoded" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_name (| globals, "keccak256" |), @@ -237,6 +340,7 @@ Definition encode_internal_node : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -250,8 +354,86 @@ Definition encode_node : Value.t -> Value.t -> M := Currently mostly an unimplemented stub. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| + M.get_name (| globals, "storage_root" |), + Constant.None_ + |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "encode_account" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "storage_root" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "U256" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "cast" |), + make_list [ + M.get_field (| M.get_name (| globals, "rlp" |), "RLP" |); + M.get_name (| globals, "node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "node" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "previous_trie" |), "encode_node" |), @@ -261,6 +443,7 @@ Definition encode_node : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -312,6 +495,7 @@ Definition copy_trie : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition trie_set : Value.t -> Value.t -> M := @@ -333,6 +517,32 @@ Definition trie_set : Value.t -> Value.t -> M := Node to insert at `key`. " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + M.get_field (| M.get_name (| globals, "trie" |), "default" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "key" |), + M.get_field (| M.get_name (| globals, "trie" |), "_data" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), M.get_name (| globals, "value" |) @@ -370,6 +580,7 @@ Definition trie_get : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition common_prefix_length : Value.t -> Value.t -> M := @@ -392,6 +603,34 @@ Definition common_prefix_length : Value.t -> Value.t -> M := make_dict [] |) do let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), + M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -403,6 +642,7 @@ Definition common_prefix_length : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition nibble_list_to_compact : Value.t -> Value.t -> M := @@ -448,6 +688,71 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + Constant.int 2 + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.mult (| + Constant.int 16, + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "is_leaf" |) + |) + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ @@ -509,6 +814,7 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition bytes_to_nibble_list : Value.t -> Value.t -> M := @@ -586,6 +892,7 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition _prepare_trie : Value.t -> Value.t -> M := @@ -615,6 +922,48 @@ Definition _prepare_trie : Value.t -> Value.t -> M := make_dict [] |) do let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| + M.get_name (| globals, "get_storage_root" |), + Constant.None_ + |) |) in + let address := + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |); + M.call (| + M.get_name (| globals, "get_storage_root" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let encoded_value := M.call (| M.get_name (| globals, "encode_node" |), @@ -638,6 +987,22 @@ Definition _prepare_trie : Value.t -> Value.t -> M := |) in (* At stmt: unsupported node type: AnnAssign *) let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "trie" |), "secured" |), + (* then *) + ltac:(M.monadic ( + let key := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let key := M.get_name (| globals, "preimage" |) in M.pure Constant.None_ @@ -655,6 +1020,7 @@ Definition _prepare_trie : Value.t -> Value.t -> M := EndFor. let _ := M.return_ (| M.get_name (| globals, "mapped" |) + |) in M.pure Constant.None_)). Definition root : Value.t -> Value.t -> M := @@ -708,6 +1074,44 @@ Definition root : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -724,6 +1128,7 @@ Definition root : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -750,6 +1155,26 @@ Definition patricialize : Value.t -> Value.t -> M := Root node of `obj`. " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let arbitrary_key := @@ -767,10 +1192,39 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), + Constant.int 1 + |), + (* then *) + ltac:(M.monadic ( + let leaf := + M.call (| + M.get_name (| globals, "LeafNode" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |); + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "leaf" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let substring := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |) |) in + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) in let prefix_length := M.call (| M.get_name (| globals, "len" |), @@ -789,7 +1243,7 @@ Definition patricialize : Value.t -> Value.t -> M := M.get_name (| globals, "common_prefix_length" |), make_list [ M.get_name (| globals, "substring" |); - M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) + M.get_subscript (| M.get_name (| globals, "key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) ], make_dict [] |) @@ -797,10 +1251,64 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "prefix_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "prefix_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let prefix := + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ExtensionNode" |), + make_list [ + M.get_name (| globals, "prefix" |); + M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_name (| globals, "obj" |); + BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) @@ -823,6 +1331,44 @@ Definition patricialize : Value.t -> Value.t -> M := Constant.bytes "" in For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |), + M.get_name (| globals, "level" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "AssertionError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) @@ -834,9 +1380,10 @@ Definition patricialize : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "BranchNode" |), make_list [ - (* At expr: unsupported node type: ListComp *); + Constant.str "(* At expr: unsupported node type: ListComp *)"; M.get_name (| globals, "value" |) ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/utils/address.v b/CoqOfPython/ethereum/paris/utils/address.v index 42f2c92..c6ea8ef 100644 --- a/CoqOfPython/ethereum/paris/utils/address.v +++ b/CoqOfPython/ethereum/paris/utils/address.v @@ -38,13 +38,13 @@ Require ethereum.utils.byte. Axiom ethereum_utils_byte_left_pad_zero_bytes : IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.paris.fork_types. +Axiom ethereum_paris_fork_types_Address : + IsGlobalAlias globals ethereum.paris.fork_types.globals "Address". Definition to_address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -70,10 +70,11 @@ Definition to_address : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), make_list [], make_dict [] - |), UnOp.sub (| Constant.int 20 |) |) + |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) ], make_dict [] |) + |) in M.pure Constant.None_)). Definition compute_contract_address : Value.t -> Value.t -> M := @@ -113,7 +114,7 @@ Definition compute_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -131,6 +132,7 @@ Definition compute_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition compute_create2_contract_address : Value.t -> Value.t -> M := @@ -180,7 +182,7 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -198,4 +200,5 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/utils/hexadecimal.v b/CoqOfPython/ethereum/paris/utils/hexadecimal.v index 1735532..45cda10 100644 --- a/CoqOfPython/ethereum/paris/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/paris/utils/hexadecimal.v @@ -22,13 +22,13 @@ Require ethereum.utils.hexadecimal. Axiom ethereum_utils_hexadecimal_remove_hex_prefix : IsGlobalAlias globals ethereum.utils.hexadecimal.globals "remove_hex_prefix". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". +Require ethereum.paris.fork_types. +Axiom ethereum_paris_fork_types_Address : + IsGlobalAlias globals ethereum.paris.fork_types.globals "Address". +Axiom ethereum_paris_fork_types_Bloom : + IsGlobalAlias globals ethereum.paris.fork_types.globals "Bloom". +Axiom ethereum_paris_fork_types_Root : + IsGlobalAlias globals ethereum.paris.fork_types.globals "Root". Definition hex_to_root : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -66,6 +66,7 @@ Definition hex_to_root : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition hex_to_bloom : Value.t -> Value.t -> M := @@ -104,6 +105,7 @@ Definition hex_to_bloom : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition hex_to_address : Value.t -> Value.t -> M := @@ -149,4 +151,5 @@ Definition hex_to_address : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/utils/message.v b/CoqOfPython/ethereum/paris/utils/message.v index e2d514f..80999f8 100644 --- a/CoqOfPython/ethereum/paris/utils/message.v +++ b/CoqOfPython/ethereum/paris/utils/message.v @@ -40,27 +40,27 @@ Axiom ethereum_base_types_Bytes32 : Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.paris.fork_types. +Axiom ethereum_paris_fork_types_Address : + IsGlobalAlias globals ethereum.paris.fork_types.globals "Address". -Require state. -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". +Require ethereum.paris.state. +Axiom ethereum_paris_state_get_account : + IsGlobalAlias globals ethereum.paris.state.globals "get_account". -Require vm. -Axiom vm_Environment : - IsGlobalAlias globals vm.globals "Environment". -Axiom vm_Message : - IsGlobalAlias globals vm.globals "Message". +Require ethereum.paris.vm.__init__. +Axiom ethereum_paris_vm___init___Environment : + IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Environment". +Axiom ethereum_paris_vm___init___Message : + IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Message". -Require vm.precompiled_contracts.mapping. -Axiom vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : - IsGlobalAlias globals vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". +Require ethereum.paris.vm.precompiled_contracts.mapping. +Axiom ethereum_paris_vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : + IsGlobalAlias globals ethereum.paris.vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". -Require address. -Axiom address_compute_contract_address : - IsGlobalAlias globals address.globals "compute_contract_address". +Require ethereum.paris.utils.address. +Axiom ethereum_paris_utils_address_compute_contract_address : + IsGlobalAlias globals ethereum.paris.utils.address.globals "compute_contract_address". Definition prepare_message : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -103,14 +103,108 @@ Definition prepare_message : Value.t -> Value.t -> M := Items containing contract creation or message call specific data. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Bytes0" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.call (| + M.get_name (| globals, "compute_contract_address" |), + make_list [ + M.get_name (| globals, "caller" |); + BinOp.sub (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "caller" |) + ], + make_dict [] + |), "nonce" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let msg_data := + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) in + let code := + M.get_name (| globals, "data" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.get_name (| globals, "target" |) in + let msg_data := + M.get_name (| globals, "data" |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "target" |) + ], + make_dict [] + |), "code" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "code_address" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let code_address := + M.get_name (| globals, "target" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "Target must be address or empty bytes" ], make_dict [] - |)) + |)) |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -159,4 +253,5 @@ Definition prepare_message : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/vm/__init__.v b/CoqOfPython/ethereum/paris/vm/__init__.v index 49da5ae..f46ba2a 100644 --- a/CoqOfPython/ethereum/paris/vm/__init__.v +++ b/CoqOfPython/ethereum/paris/vm/__init__.v @@ -52,23 +52,23 @@ Require ethereum.crypto.hash. Axiom ethereum_crypto_hash_Hash32 : IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". +Require ethereum.paris.blocks. +Axiom ethereum_paris_blocks_Log : + IsGlobalAlias globals ethereum.paris.blocks.globals "Log". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.paris.fork_types. +Axiom ethereum_paris_fork_types_Address : + IsGlobalAlias globals ethereum.paris.fork_types.globals "Address". -Require state. -Axiom state_State : - IsGlobalAlias globals state.globals "State". -Axiom state_account_exists_and_is_empty : - IsGlobalAlias globals state.globals "account_exists_and_is_empty". +Require ethereum.paris.state. +Axiom ethereum_paris_state_State : + IsGlobalAlias globals ethereum.paris.state.globals "State". +Axiom ethereum_paris_state_account_exists_and_is_empty : + IsGlobalAlias globals ethereum.paris.state.globals "account_exists_and_is_empty". -Require precompiled_contracts. -Axiom precompiled_contracts_RIPEMD160_ADDRESS : - IsGlobalAlias globals precompiled_contracts.globals "RIPEMD160_ADDRESS". +Require ethereum.paris.vm.precompiled_contracts.__init__. +Axiom ethereum_paris_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : + IsGlobalAlias globals ethereum.paris.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] @@ -147,6 +147,28 @@ Definition incorporate_child_on_success : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -179,9 +201,63 @@ Definition incorporate_child_on_error : Value.t -> Value.t -> M := The child evm to incorporate. " in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "RIPEMD160_ADDRESS" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |), + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign_op (| diff --git a/CoqOfPython/ethereum/paris/vm/gas.v b/CoqOfPython/ethereum/paris/vm/gas.v index 549060b..e20e15c 100644 --- a/CoqOfPython/ethereum/paris/vm/gas.v +++ b/CoqOfPython/ethereum/paris/vm/gas.v @@ -43,13 +43,13 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.paris.vm.__init__. +Axiom ethereum_paris_vm___init___Evm : + IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Evm". -Require exceptions. -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". +Require ethereum.paris.vm.exceptions. +Axiom ethereum_paris_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.paris.vm.exceptions.globals "OutOfGasError". Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -500,6 +500,18 @@ Definition charge_gas : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "amount" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign_op (| BinOp.sub, M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), @@ -615,6 +627,18 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := |) in For make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ] in M.get_name (| globals, "extensions" |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "size" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let before_size := @@ -649,6 +673,18 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let size_to_extend := BinOp.add @@ -697,6 +733,7 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition calculate_message_call_gas : Value.t -> Value.t -> M := @@ -728,22 +765,56 @@ Definition calculate_message_call_gas : Value.t -> Value.t -> M := message_call_gas: `MessageCallGas` " in let call_stipend := - (* if *) -M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "call_stipend" |) + )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "gas_left" |), + BinOp.add (| + M.get_name (| globals, "extra_gas" |), + M.get_name (| globals, "memory_cost" |) + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallGas" |), + make_list [ + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "extra_gas" |) + |); + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "call_stipend" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let gas := @@ -782,6 +853,7 @@ M.call (| ], make_dict [] |) + |) in M.pure Constant.None_)). Definition max_message_call_gas : Value.t -> Value.t -> M := @@ -808,4 +880,5 @@ Definition max_message_call_gas : Value.t -> Value.t -> M := Constant.int 64 |) |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/vm/instructions/__init__.v b/CoqOfPython/ethereum/paris/vm/instructions/__init__.v index e5bebd7..7cd4d8a 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/__init__.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/__init__.v @@ -26,53 +26,53 @@ Axiom typing_Callable : Axiom typing_Dict : IsGlobalAlias globals typing.globals "Dict". -Require __init__. -Axiom __init___arithmetic : - IsGlobalAlias globals __init__.globals "arithmetic". +Require ethereum.paris.vm.instructions.__init__. +Axiom ethereum_paris_vm_instructions___init___arithmetic : + IsGlobalAlias globals ethereum.paris.vm.instructions.__init__.globals "arithmetic". -Require __init__. -Axiom __init___bitwise : - IsGlobalAlias globals __init__.globals "bitwise". +Require ethereum.paris.vm.instructions.__init__. +Axiom ethereum_paris_vm_instructions___init___bitwise : + IsGlobalAlias globals ethereum.paris.vm.instructions.__init__.globals "bitwise". -Require __init__. -Axiom __init___block : - IsGlobalAlias globals __init__.globals "block". +Require ethereum.paris.vm.instructions.__init__. +Axiom ethereum_paris_vm_instructions___init___block : + IsGlobalAlias globals ethereum.paris.vm.instructions.__init__.globals "block". -Require __init__. -Axiom __init___comparison : - IsGlobalAlias globals __init__.globals "comparison". +Require ethereum.paris.vm.instructions.__init__. +Axiom ethereum_paris_vm_instructions___init___comparison : + IsGlobalAlias globals ethereum.paris.vm.instructions.__init__.globals "comparison". -Require __init__. -Axiom __init___control_flow : - IsGlobalAlias globals __init__.globals "control_flow". +Require ethereum.paris.vm.instructions.__init__. +Axiom ethereum_paris_vm_instructions___init___control_flow : + IsGlobalAlias globals ethereum.paris.vm.instructions.__init__.globals "control_flow". -Require __init__. -Axiom __init___environment : - IsGlobalAlias globals __init__.globals "environment". +Require ethereum.paris.vm.instructions.__init__. +Axiom ethereum_paris_vm_instructions___init___environment : + IsGlobalAlias globals ethereum.paris.vm.instructions.__init__.globals "environment". -Require __init__. -Axiom __init___keccak : - IsGlobalAlias globals __init__.globals "keccak". +Require ethereum.paris.vm.instructions.__init__. +Axiom ethereum_paris_vm_instructions___init___keccak : + IsGlobalAlias globals ethereum.paris.vm.instructions.__init__.globals "keccak". -Require __init__. -Axiom __init___log : - IsGlobalAlias globals __init__.globals "log". +Require ethereum.paris.vm.instructions.__init__. +Axiom ethereum_paris_vm_instructions___init___log : + IsGlobalAlias globals ethereum.paris.vm.instructions.__init__.globals "log". -Require __init__. -Axiom __init___memory : - IsGlobalAlias globals __init__.globals "memory". +Require ethereum.paris.vm.instructions.__init__. +Axiom ethereum_paris_vm_instructions___init___memory : + IsGlobalAlias globals ethereum.paris.vm.instructions.__init__.globals "memory". -Require __init__. -Axiom __init___stack : - IsGlobalAlias globals __init__.globals "stack". +Require ethereum.paris.vm.instructions.__init__. +Axiom ethereum_paris_vm_instructions___init___stack : + IsGlobalAlias globals ethereum.paris.vm.instructions.__init__.globals "stack". -Require __init__. -Axiom __init___storage : - IsGlobalAlias globals __init__.globals "storage". +Require ethereum.paris.vm.instructions.__init__. +Axiom ethereum_paris_vm_instructions___init___storage : + IsGlobalAlias globals ethereum.paris.vm.instructions.__init__.globals "storage". -Require __init__. -Axiom __init___system : - IsGlobalAlias globals __init__.globals "system". +Require ethereum.paris.vm.instructions.__init__. +Axiom ethereum_paris_vm_instructions___init___system : + IsGlobalAlias globals ethereum.paris.vm.instructions.__init__.globals "system". Definition Ops : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/paris/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/paris/vm/instructions/arithmetic.v index 581ba5d..aa1d6e0 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/arithmetic.v @@ -31,29 +31,29 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_get_sign : IsGlobalAlias globals ethereum.utils.numeric.globals "get_sign". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_EXPONENTIATION : - IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION". -Axiom gas_GAS_EXPONENTIATION_PER_BYTE : - IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION_PER_BYTE". -Axiom gas_GAS_LOW : - IsGlobalAlias globals gas.globals "GAS_LOW". -Axiom gas_GAS_MID : - IsGlobalAlias globals gas.globals "GAS_MID". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.paris.vm.__init__. +Axiom ethereum_paris_vm___init___Evm : + IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Evm". + +Require ethereum.paris.vm.gas. +Axiom ethereum_paris_vm_gas_GAS_EXPONENTIATION : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_EXPONENTIATION". +Axiom ethereum_paris_vm_gas_GAS_EXPONENTIATION_PER_BYTE : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_EXPONENTIATION_PER_BYTE". +Axiom ethereum_paris_vm_gas_GAS_LOW : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_LOW". +Axiom ethereum_paris_vm_gas_GAS_MID : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_MID". +Axiom ethereum_paris_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_paris_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "charge_gas". + +Require ethereum.paris.vm.stack. +Axiom ethereum_paris_vm_stack_pop : + IsGlobalAlias globals ethereum.paris.vm.stack.globals "pop". +Axiom ethereum_paris_vm_stack_push : + IsGlobalAlias globals ethereum.paris.vm.stack.globals "push". Definition add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -273,6 +273,25 @@ Definition div : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "divisor" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let quotient := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let quotient := BinOp.floor_div (| M.get_name (| globals, "dividend" |), @@ -341,7 +360,41 @@ Definition sdiv : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "divisor" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let quotient := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_name (| globals, "dividend" |), + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "divisor" |), + UnOp.sub (| Constant.int 1 |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let quotient := + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let sign := M.call (| M.get_name (| globals, "get_sign" |), @@ -436,6 +489,25 @@ Definition mod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "y" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let remainder := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let remainder := BinOp.mod_ (| M.get_name (| globals, "x" |), @@ -504,6 +576,19 @@ Definition smod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "y" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let remainder := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let remainder := BinOp.mult (| M.call (| @@ -617,6 +702,25 @@ Definition addmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "z" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -712,6 +816,25 @@ Definition mulmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "z" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -881,6 +1004,19 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "byte_num" |), + Constant.int 31 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.get_name (| globals, "value" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let value_bytes := M.call (| M.get_name (| globals, "bytes" |), @@ -894,7 +1030,7 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let value_bytes := - M.get_subscript (| M.get_name (| globals, "value_bytes" |), BinOp.sub (| + M.get_subscript (| M.get_name (| globals, "value_bytes" |), M.slice (| BinOp.sub (| Constant.int 31, M.call (| M.get_name (| globals, "int" |), @@ -903,13 +1039,32 @@ Definition signextend : Value.t -> Value.t -> M := ], make_dict [] |) - |) |) in + |), Constant.None_ |) |) in let sign_bit := BinOp.r_shift (| M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), Constant.int 7 |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "sign_bit" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "value_bytes" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let num_bytes_prepend := BinOp.sub (| Constant.int 32, diff --git a/CoqOfPython/ethereum/paris/vm/instructions/bitwise.v b/CoqOfPython/ethereum/paris/vm/instructions/bitwise.v index 64cf120..0527ef4 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/bitwise.v @@ -23,21 +23,21 @@ Axiom ethereum_base_types_U256 : Axiom ethereum_base_types_U256_CEIL_VALUE : IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.paris.vm.__init__. +Axiom ethereum_paris_vm___init___Evm : + IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.paris.vm.gas. +Axiom ethereum_paris_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_paris_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "charge_gas". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.paris.vm.stack. +Axiom ethereum_paris_vm_stack_pop : + IsGlobalAlias globals ethereum.paris.vm.stack.globals "pop". +Axiom ethereum_paris_vm_stack_push : + IsGlobalAlias globals ethereum.paris.vm.stack.globals "push". Definition bitwise_and : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -287,6 +287,25 @@ Definition get_byte : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "byte_index" |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let extra_bytes_to_right := BinOp.sub (| Constant.int 31, @@ -366,6 +385,31 @@ Definition bitwise_shl : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "shift" |), + Constant.int 256 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.l_shift (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "shift" |) + |), + M.get_name (| globals, "U256_CEIL_VALUE" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -427,6 +471,22 @@ Definition bitwise_shr : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "shift" |), + Constant.int 256 + |), + (* then *) + ltac:(M.monadic ( + let result := + BinOp.r_shift (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "shift" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -492,7 +552,48 @@ Definition bitwise_sar : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "shift" |), + Constant.int 256 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + BinOp.r_shift (| + M.get_name (| globals, "signed_value" |), + M.get_name (| globals, "shift" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "signed_value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/paris/vm/instructions/block.v b/CoqOfPython/ethereum/paris/vm/instructions/block.v index 080a363..b3c359e 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/block.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/block.v @@ -21,23 +21,23 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_BLOCK_HASH : - IsGlobalAlias globals gas.globals "GAS_BLOCK_HASH". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.paris.vm.__init__. +Axiom ethereum_paris_vm___init___Evm : + IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Evm". + +Require ethereum.paris.vm.gas. +Axiom ethereum_paris_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_BASE". +Axiom ethereum_paris_vm_gas_GAS_BLOCK_HASH : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_BLOCK_HASH". +Axiom ethereum_paris_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "charge_gas". + +Require ethereum.paris.vm.stack. +Axiom ethereum_paris_vm_stack_pop : + IsGlobalAlias globals ethereum.paris.vm.stack.globals "pop". +Axiom ethereum_paris_vm_stack_push : + IsGlobalAlias globals ethereum.paris.vm.stack.globals "push". Definition block_hash : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -75,6 +75,30 @@ Definition block_hash : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt_e (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + M.get_name (| globals, "block_number" |) + |), + ltac:(M.monadic ( + Compare.gt (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + BinOp.add (| + M.get_name (| globals, "block_number" |), + Constant.int 256 + |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let hash := + Constant.bytes "00" in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let hash := M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), diff --git a/CoqOfPython/ethereum/paris/vm/instructions/comparison.v b/CoqOfPython/ethereum/paris/vm/instructions/comparison.v index b8529d8..6c08576 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/comparison.v @@ -21,21 +21,21 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.paris.vm.__init__. +Axiom ethereum_paris_vm___init___Evm : + IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.paris.vm.gas. +Axiom ethereum_paris_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_paris_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "charge_gas". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.paris.vm.stack. +Axiom ethereum_paris_vm_stack_pop : + IsGlobalAlias globals ethereum.paris.vm.stack.globals "pop". +Axiom ethereum_paris_vm_stack_push : + IsGlobalAlias globals ethereum.paris.vm.stack.globals "push". Definition less_than : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/paris/vm/instructions/control_flow.v b/CoqOfPython/ethereum/paris/vm/instructions/control_flow.v index d4e4eae..44bff2b 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/control_flow.v @@ -23,31 +23,31 @@ Axiom ethereum_base_types_U256 : Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require vm.gas. -Axiom vm_gas_GAS_BASE : - IsGlobalAlias globals vm.gas.globals "GAS_BASE". -Axiom vm_gas_GAS_HIGH : - IsGlobalAlias globals vm.gas.globals "GAS_HIGH". -Axiom vm_gas_GAS_JUMPDEST : - IsGlobalAlias globals vm.gas.globals "GAS_JUMPDEST". -Axiom vm_gas_GAS_MID : - IsGlobalAlias globals vm.gas.globals "GAS_MID". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.paris.vm.gas. +Axiom ethereum_paris_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_BASE". +Axiom ethereum_paris_vm_gas_GAS_HIGH : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_HIGH". +Axiom ethereum_paris_vm_gas_GAS_JUMPDEST : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_JUMPDEST". +Axiom ethereum_paris_vm_gas_GAS_MID : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_MID". +Axiom ethereum_paris_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "charge_gas". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.paris.vm.__init__. +Axiom ethereum_paris_vm___init___Evm : + IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Evm". -Require exceptions. -Axiom exceptions_InvalidJumpDestError : - IsGlobalAlias globals exceptions.globals "InvalidJumpDestError". +Require ethereum.paris.vm.exceptions. +Axiom ethereum_paris_vm_exceptions_InvalidJumpDestError : + IsGlobalAlias globals ethereum.paris.vm.exceptions.globals "InvalidJumpDestError". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.paris.vm.stack. +Axiom ethereum_paris_vm_stack_pop : + IsGlobalAlias globals ethereum.paris.vm.stack.globals "pop". +Axiom ethereum_paris_vm_stack_push : + IsGlobalAlias globals ethereum.paris.vm.stack.globals "push". Definition stop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -109,6 +109,18 @@ Definition jump : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "jump_dest" |), + M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -168,7 +180,35 @@ Definition jumpi : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "conditional_value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let destination := + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "jump_dest" |), + M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let destination := M.get_name (| globals, "jump_dest" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/paris/vm/instructions/environment.v b/CoqOfPython/ethereum/paris/vm/instructions/environment.v index 10bc05b..94f1204 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/environment.v @@ -35,57 +35,57 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require fork_types. -Axiom fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". - -Require state. -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". - -Require utils.address. -Axiom utils_address_to_address : - IsGlobalAlias globals utils.address.globals "to_address". - -Require vm.memory. -Axiom vm_memory_buffer_read : - IsGlobalAlias globals vm.memory.globals "buffer_read". -Axiom vm_memory_memory_write : - IsGlobalAlias globals vm.memory.globals "memory_write". - -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require exceptions. -Axiom exceptions_OutOfBoundsRead : - IsGlobalAlias globals exceptions.globals "OutOfBoundsRead". - -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_COLD_ACCOUNT_ACCESS : - IsGlobalAlias globals gas.globals "GAS_COLD_ACCOUNT_ACCESS". -Axiom gas_GAS_COPY : - IsGlobalAlias globals gas.globals "GAS_COPY". -Axiom gas_GAS_FAST_STEP : - IsGlobalAlias globals gas.globals "GAS_FAST_STEP". -Axiom gas_GAS_RETURN_DATA_COPY : - IsGlobalAlias globals gas.globals "GAS_RETURN_DATA_COPY". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_GAS_WARM_ACCESS : - IsGlobalAlias globals gas.globals "GAS_WARM_ACCESS". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.paris.fork_types. +Axiom ethereum_paris_fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals ethereum.paris.fork_types.globals "EMPTY_ACCOUNT". + +Require ethereum.paris.state. +Axiom ethereum_paris_state_get_account : + IsGlobalAlias globals ethereum.paris.state.globals "get_account". + +Require ethereum.paris.utils.address. +Axiom ethereum_paris_utils_address_to_address : + IsGlobalAlias globals ethereum.paris.utils.address.globals "to_address". + +Require ethereum.paris.vm.memory. +Axiom ethereum_paris_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.paris.vm.memory.globals "buffer_read". +Axiom ethereum_paris_vm_memory_memory_write : + IsGlobalAlias globals ethereum.paris.vm.memory.globals "memory_write". + +Require ethereum.paris.vm.__init__. +Axiom ethereum_paris_vm___init___Evm : + IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Evm". + +Require ethereum.paris.vm.exceptions. +Axiom ethereum_paris_vm_exceptions_OutOfBoundsRead : + IsGlobalAlias globals ethereum.paris.vm.exceptions.globals "OutOfBoundsRead". + +Require ethereum.paris.vm.gas. +Axiom ethereum_paris_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_BASE". +Axiom ethereum_paris_vm_gas_GAS_COLD_ACCOUNT_ACCESS : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_COLD_ACCOUNT_ACCESS". +Axiom ethereum_paris_vm_gas_GAS_COPY : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_COPY". +Axiom ethereum_paris_vm_gas_GAS_FAST_STEP : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_FAST_STEP". +Axiom ethereum_paris_vm_gas_GAS_RETURN_DATA_COPY : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_RETURN_DATA_COPY". +Axiom ethereum_paris_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_paris_vm_gas_GAS_WARM_ACCESS : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_WARM_ACCESS". +Axiom ethereum_paris_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_paris_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "charge_gas". + +Require ethereum.paris.vm.stack. +Axiom ethereum_paris_vm_stack_pop : + IsGlobalAlias globals ethereum.paris.vm.stack.globals "pop". +Axiom ethereum_paris_vm_stack_push : + IsGlobalAlias globals ethereum.paris.vm.stack.globals "push". Definition address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -156,6 +156,25 @@ Definition balance : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -789,6 +808,25 @@ Definition extcodesize : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -926,6 +964,31 @@ Definition extcodecopy : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_WARM_ACCESS" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1162,7 +1225,10 @@ Definition returndatacopy : Value.t -> Value.t -> M := |) |) in let value := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |) |) in + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.slice (| M.get_name (| globals, "return_data_start_position" |), BinOp.add (| + M.get_name (| globals, "return_data_start_position" |), + M.get_name (| globals, "size" |) + |) |) |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -1204,6 +1270,25 @@ Definition extcodehash : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1231,6 +1316,25 @@ Definition extcodehash : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "account" |), + M.get_name (| globals, "EMPTY_ACCOUNT" |) + |), + (* then *) + ltac:(M.monadic ( + let codehash := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let codehash := M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), diff --git a/CoqOfPython/ethereum/paris/vm/instructions/keccak.v b/CoqOfPython/ethereum/paris/vm/instructions/keccak.v index 2c4b10e..635fe27 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/keccak.v @@ -31,29 +31,29 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_KECCAK256 : - IsGlobalAlias globals gas.globals "GAS_KECCAK256". -Axiom gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.paris.vm.__init__. +Axiom ethereum_paris_vm___init___Evm : + IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Evm". + +Require ethereum.paris.vm.gas. +Axiom ethereum_paris_vm_gas_GAS_KECCAK256 : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_KECCAK256". +Axiom ethereum_paris_vm_gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_KECCAK256_WORD". +Axiom ethereum_paris_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_paris_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "charge_gas". + +Require ethereum.paris.vm.memory. +Axiom ethereum_paris_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.paris.vm.memory.globals "memory_read_bytes". + +Require ethereum.paris.vm.stack. +Axiom ethereum_paris_vm_stack_pop : + IsGlobalAlias globals ethereum.paris.vm.stack.globals "pop". +Axiom ethereum_paris_vm_stack_push : + IsGlobalAlias globals ethereum.paris.vm.stack.globals "push". Definition keccak : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/paris/vm/instructions/log.v b/CoqOfPython/ethereum/paris/vm/instructions/log.v index e084e59..df4a2fe 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/log.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/log.v @@ -29,37 +29,37 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". - -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require exceptions. -Axiom exceptions_WriteInStaticContext : - IsGlobalAlias globals exceptions.globals "WriteInStaticContext". - -Require gas. -Axiom gas_GAS_LOG : - IsGlobalAlias globals gas.globals "GAS_LOG". -Axiom gas_GAS_LOG_DATA : - IsGlobalAlias globals gas.globals "GAS_LOG_DATA". -Axiom gas_GAS_LOG_TOPIC : - IsGlobalAlias globals gas.globals "GAS_LOG_TOPIC". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". +Require ethereum.paris.blocks. +Axiom ethereum_paris_blocks_Log : + IsGlobalAlias globals ethereum.paris.blocks.globals "Log". + +Require ethereum.paris.vm.__init__. +Axiom ethereum_paris_vm___init___Evm : + IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Evm". + +Require ethereum.paris.vm.exceptions. +Axiom ethereum_paris_vm_exceptions_WriteInStaticContext : + IsGlobalAlias globals ethereum.paris.vm.exceptions.globals "WriteInStaticContext". + +Require ethereum.paris.vm.gas. +Axiom ethereum_paris_vm_gas_GAS_LOG : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_LOG". +Axiom ethereum_paris_vm_gas_GAS_LOG_DATA : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_LOG_DATA". +Axiom ethereum_paris_vm_gas_GAS_LOG_TOPIC : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_LOG_TOPIC". +Axiom ethereum_paris_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_paris_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "charge_gas". + +Require ethereum.paris.vm.memory. +Axiom ethereum_paris_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.paris.vm.memory.globals "memory_read_bytes". + +Require ethereum.paris.vm.stack. +Axiom ethereum_paris_vm_stack_pop : + IsGlobalAlias globals ethereum.paris.vm.stack.globals "pop". Definition log_n : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/paris/vm/instructions/memory.v b/CoqOfPython/ethereum/paris/vm/instructions/memory.v index 86ba742..119554e 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/memory.v @@ -23,31 +23,31 @@ Axiom ethereum_base_types_U256 : Axiom ethereum_base_types_Bytes : IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.paris.vm.__init__. +Axiom ethereum_paris_vm___init___Evm : + IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.paris.vm.gas. +Axiom ethereum_paris_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_BASE". +Axiom ethereum_paris_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_paris_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_paris_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "charge_gas". -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". -Axiom memory_memory_write : - IsGlobalAlias globals memory.globals "memory_write". +Require ethereum.paris.vm.memory. +Axiom ethereum_paris_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.paris.vm.memory.globals "memory_read_bytes". +Axiom ethereum_paris_vm_memory_memory_write : + IsGlobalAlias globals ethereum.paris.vm.memory.globals "memory_write". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.paris.vm.stack. +Axiom ethereum_paris_vm_stack_pop : + IsGlobalAlias globals ethereum.paris.vm.stack.globals "pop". +Axiom ethereum_paris_vm_stack_push : + IsGlobalAlias globals ethereum.paris.vm.stack.globals "push". Definition mstore : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/paris/vm/instructions/stack.v b/CoqOfPython/ethereum/paris/vm/instructions/stack.v index 305af15..e7dd5b9 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/stack.v @@ -29,27 +29,27 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". -Axiom __init___stack : - IsGlobalAlias globals __init__.globals "stack". - -Require exceptions. -Axiom exceptions_StackUnderflowError : - IsGlobalAlias globals exceptions.globals "StackUnderflowError". - -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require memory. -Axiom memory_buffer_read : - IsGlobalAlias globals memory.globals "buffer_read". +Require ethereum.paris.vm.__init__. +Axiom ethereum_paris_vm___init___Evm : + IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Evm". +Axiom ethereum_paris_vm___init___stack : + IsGlobalAlias globals ethereum.paris.vm.__init__.globals "stack". + +Require ethereum.paris.vm.exceptions. +Axiom ethereum_paris_vm_exceptions_StackUnderflowError : + IsGlobalAlias globals ethereum.paris.vm.exceptions.globals "StackUnderflowError". + +Require ethereum.paris.vm.gas. +Axiom ethereum_paris_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_BASE". +Axiom ethereum_paris_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_paris_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "charge_gas". + +Require ethereum.paris.vm.memory. +Axiom ethereum_paris_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.paris.vm.memory.globals "buffer_read". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/paris/vm/instructions/storage.v b/CoqOfPython/ethereum/paris/vm/instructions/storage.v index b3c4045..945f785 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/storage.v @@ -25,45 +25,45 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require state. -Axiom state_get_storage : - IsGlobalAlias globals state.globals "get_storage". -Axiom state_get_storage_original : - IsGlobalAlias globals state.globals "get_storage_original". -Axiom state_set_storage : - IsGlobalAlias globals state.globals "set_storage". - -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require exceptions. -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". -Axiom exceptions_WriteInStaticContext : - IsGlobalAlias globals exceptions.globals "WriteInStaticContext". - -Require gas. -Axiom gas_GAS_CALL_STIPEND : - IsGlobalAlias globals gas.globals "GAS_CALL_STIPEND". -Axiom gas_GAS_COLD_SLOAD : - IsGlobalAlias globals gas.globals "GAS_COLD_SLOAD". -Axiom gas_GAS_STORAGE_CLEAR_REFUND : - IsGlobalAlias globals gas.globals "GAS_STORAGE_CLEAR_REFUND". -Axiom gas_GAS_STORAGE_SET : - IsGlobalAlias globals gas.globals "GAS_STORAGE_SET". -Axiom gas_GAS_STORAGE_UPDATE : - IsGlobalAlias globals gas.globals "GAS_STORAGE_UPDATE". -Axiom gas_GAS_WARM_ACCESS : - IsGlobalAlias globals gas.globals "GAS_WARM_ACCESS". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.paris.state. +Axiom ethereum_paris_state_get_storage : + IsGlobalAlias globals ethereum.paris.state.globals "get_storage". +Axiom ethereum_paris_state_get_storage_original : + IsGlobalAlias globals ethereum.paris.state.globals "get_storage_original". +Axiom ethereum_paris_state_set_storage : + IsGlobalAlias globals ethereum.paris.state.globals "set_storage". + +Require ethereum.paris.vm.__init__. +Axiom ethereum_paris_vm___init___Evm : + IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Evm". + +Require ethereum.paris.vm.exceptions. +Axiom ethereum_paris_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.paris.vm.exceptions.globals "OutOfGasError". +Axiom ethereum_paris_vm_exceptions_WriteInStaticContext : + IsGlobalAlias globals ethereum.paris.vm.exceptions.globals "WriteInStaticContext". + +Require ethereum.paris.vm.gas. +Axiom ethereum_paris_vm_gas_GAS_CALL_STIPEND : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_CALL_STIPEND". +Axiom ethereum_paris_vm_gas_GAS_COLD_SLOAD : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_COLD_SLOAD". +Axiom ethereum_paris_vm_gas_GAS_STORAGE_CLEAR_REFUND : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_STORAGE_CLEAR_REFUND". +Axiom ethereum_paris_vm_gas_GAS_STORAGE_SET : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_STORAGE_SET". +Axiom ethereum_paris_vm_gas_GAS_STORAGE_UPDATE : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_STORAGE_UPDATE". +Axiom ethereum_paris_vm_gas_GAS_WARM_ACCESS : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_WARM_ACCESS". +Axiom ethereum_paris_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "charge_gas". + +Require ethereum.paris.vm.stack. +Axiom ethereum_paris_vm_stack_pop : + IsGlobalAlias globals ethereum.paris.vm.stack.globals "pop". +Axiom ethereum_paris_vm_stack_push : + IsGlobalAlias globals ethereum.paris.vm.stack.globals "push". Definition sload : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -91,6 +91,25 @@ Definition sload : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], + M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "add" |), make_list [ @@ -205,15 +224,225 @@ Definition sstore : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], + M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "add" |), + make_list [ + make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ] + ], + make_dict [] + |) in + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_COLD_SLOAD" |) + M.get_name (| globals, "GAS_COLD_SLOAD" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_name (| globals, "original_value" |), + M.get_name (| globals, "current_value" |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "current_value" |), + M.get_name (| globals, "new_value" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "original_value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_STORAGE_SET" |) + M.get_name (| globals, "GAS_STORAGE_SET" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let gas_cost := BinOp.add + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_UPDATE" |), + M.get_name (| globals, "GAS_COLD_SLOAD" |) + |) + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_UPDATE" |), + M.get_name (| globals, "GAS_COLD_SLOAD" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let gas_cost := BinOp.add M.get_name (| globals, "GAS_WARM_ACCESS" |) M.get_name (| globals, "GAS_WARM_ACCESS" |) in M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| + M.get_name (| globals, "current_value" |), + M.get_name (| globals, "new_value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "original_value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "current_value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "new_value" |), + Constant.int 0 + |) + )) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "original_value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "current_value" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.sub, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "original_value" |), + M.get_name (| globals, "new_value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "original_value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_SET" |), + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.sub (| + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_UPDATE" |), + M.get_name (| globals, "GAS_COLD_SLOAD" |) + |), + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/paris/vm/instructions/system.v b/CoqOfPython/ethereum/paris/vm/instructions/system.v index 03931b2..2c3b610 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/system.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/system.v @@ -33,87 +33,87 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.paris.fork_types. +Axiom ethereum_paris_fork_types_Address : + IsGlobalAlias globals ethereum.paris.fork_types.globals "Address". -Require state. -Axiom state_account_exists_and_is_empty : - IsGlobalAlias globals state.globals "account_exists_and_is_empty". -Axiom state_account_has_code_or_nonce : - IsGlobalAlias globals state.globals "account_has_code_or_nonce". -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". -Axiom state_increment_nonce : - IsGlobalAlias globals state.globals "increment_nonce". -Axiom state_is_account_alive : - IsGlobalAlias globals state.globals "is_account_alive". -Axiom state_set_account_balance : - IsGlobalAlias globals state.globals "set_account_balance". +Require ethereum.paris.state. +Axiom ethereum_paris_state_account_exists_and_is_empty : + IsGlobalAlias globals ethereum.paris.state.globals "account_exists_and_is_empty". +Axiom ethereum_paris_state_account_has_code_or_nonce : + IsGlobalAlias globals ethereum.paris.state.globals "account_has_code_or_nonce". +Axiom ethereum_paris_state_get_account : + IsGlobalAlias globals ethereum.paris.state.globals "get_account". +Axiom ethereum_paris_state_increment_nonce : + IsGlobalAlias globals ethereum.paris.state.globals "increment_nonce". +Axiom ethereum_paris_state_is_account_alive : + IsGlobalAlias globals ethereum.paris.state.globals "is_account_alive". +Axiom ethereum_paris_state_set_account_balance : + IsGlobalAlias globals ethereum.paris.state.globals "set_account_balance". -Require utils.address. -Axiom utils_address_compute_contract_address : - IsGlobalAlias globals utils.address.globals "compute_contract_address". -Axiom utils_address_compute_create2_contract_address : - IsGlobalAlias globals utils.address.globals "compute_create2_contract_address". -Axiom utils_address_to_address : - IsGlobalAlias globals utils.address.globals "to_address". +Require ethereum.paris.utils.address. +Axiom ethereum_paris_utils_address_compute_contract_address : + IsGlobalAlias globals ethereum.paris.utils.address.globals "compute_contract_address". +Axiom ethereum_paris_utils_address_compute_create2_contract_address : + IsGlobalAlias globals ethereum.paris.utils.address.globals "compute_create2_contract_address". +Axiom ethereum_paris_utils_address_to_address : + IsGlobalAlias globals ethereum.paris.utils.address.globals "to_address". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". -Axiom __init___Message : - IsGlobalAlias globals __init__.globals "Message". -Axiom __init___incorporate_child_on_error : - IsGlobalAlias globals __init__.globals "incorporate_child_on_error". -Axiom __init___incorporate_child_on_success : - IsGlobalAlias globals __init__.globals "incorporate_child_on_success". +Require ethereum.paris.vm.__init__. +Axiom ethereum_paris_vm___init___Evm : + IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Evm". +Axiom ethereum_paris_vm___init___Message : + IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Message". +Axiom ethereum_paris_vm___init___incorporate_child_on_error : + IsGlobalAlias globals ethereum.paris.vm.__init__.globals "incorporate_child_on_error". +Axiom ethereum_paris_vm___init___incorporate_child_on_success : + IsGlobalAlias globals ethereum.paris.vm.__init__.globals "incorporate_child_on_success". -Require exceptions. -Axiom exceptions_Revert : - IsGlobalAlias globals exceptions.globals "Revert". -Axiom exceptions_WriteInStaticContext : - IsGlobalAlias globals exceptions.globals "WriteInStaticContext". +Require ethereum.paris.vm.exceptions. +Axiom ethereum_paris_vm_exceptions_Revert : + IsGlobalAlias globals ethereum.paris.vm.exceptions.globals "Revert". +Axiom ethereum_paris_vm_exceptions_WriteInStaticContext : + IsGlobalAlias globals ethereum.paris.vm.exceptions.globals "WriteInStaticContext". -Require gas. -Axiom gas_GAS_CALL_VALUE : - IsGlobalAlias globals gas.globals "GAS_CALL_VALUE". -Axiom gas_GAS_COLD_ACCOUNT_ACCESS : - IsGlobalAlias globals gas.globals "GAS_COLD_ACCOUNT_ACCESS". -Axiom gas_GAS_CREATE : - IsGlobalAlias globals gas.globals "GAS_CREATE". -Axiom gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". -Axiom gas_GAS_NEW_ACCOUNT : - IsGlobalAlias globals gas.globals "GAS_NEW_ACCOUNT". -Axiom gas_GAS_SELF_DESTRUCT : - IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT". -Axiom gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : - IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". -Axiom gas_GAS_WARM_ACCESS : - IsGlobalAlias globals gas.globals "GAS_WARM_ACCESS". -Axiom gas_GAS_ZERO : - IsGlobalAlias globals gas.globals "GAS_ZERO". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_calculate_message_call_gas : - IsGlobalAlias globals gas.globals "calculate_message_call_gas". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". -Axiom gas_max_message_call_gas : - IsGlobalAlias globals gas.globals "max_message_call_gas". +Require ethereum.paris.vm.gas. +Axiom ethereum_paris_vm_gas_GAS_CALL_VALUE : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_CALL_VALUE". +Axiom ethereum_paris_vm_gas_GAS_COLD_ACCOUNT_ACCESS : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_COLD_ACCOUNT_ACCESS". +Axiom ethereum_paris_vm_gas_GAS_CREATE : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_CREATE". +Axiom ethereum_paris_vm_gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_KECCAK256_WORD". +Axiom ethereum_paris_vm_gas_GAS_NEW_ACCOUNT : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_NEW_ACCOUNT". +Axiom ethereum_paris_vm_gas_GAS_SELF_DESTRUCT : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_SELF_DESTRUCT". +Axiom ethereum_paris_vm_gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". +Axiom ethereum_paris_vm_gas_GAS_WARM_ACCESS : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_WARM_ACCESS". +Axiom ethereum_paris_vm_gas_GAS_ZERO : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_ZERO". +Axiom ethereum_paris_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_paris_vm_gas_calculate_message_call_gas : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "calculate_message_call_gas". +Axiom ethereum_paris_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "charge_gas". +Axiom ethereum_paris_vm_gas_max_message_call_gas : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "max_message_call_gas". -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". -Axiom memory_memory_write : - IsGlobalAlias globals memory.globals "memory_write". +Require ethereum.paris.vm.memory. +Axiom ethereum_paris_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.paris.vm.memory.globals "memory_read_bytes". +Axiom ethereum_paris_vm_memory_memory_write : + IsGlobalAlias globals ethereum.paris.vm.memory.globals "memory_write". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.paris.vm.stack. +Axiom ethereum_paris_vm_stack_pop : + IsGlobalAlias globals ethereum.paris.vm.stack.globals "pop". +Axiom ethereum_paris_vm_stack_push : + IsGlobalAlias globals ethereum.paris.vm.stack.globals "push". Definition generic_create : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -172,9 +172,113 @@ Definition generic_create : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt (| + M.get_field (| M.get_name (| globals, "sender" |), "balance" |), + M.get_name (| globals, "endowment" |) + |), + ltac:(M.monadic ( + BoolOp.or (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "sender" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.sub (| + BinOp.pow (| + Constant.int 2, + Constant.int 64 + |), + Constant.int 1 + |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.gt (| + BinOp.add (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "depth" |), + Constant.int 1 + |), + M.get_name (| globals, "STACK_DEPTH_LIMIT" |) + |) + )) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "create_message_gas" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "contract_address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let call_data := @@ -211,6 +315,40 @@ Definition generic_create : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "child_evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_error" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "incorporate_child_on_success" |), make_list [ @@ -567,6 +705,42 @@ Definition generic_call : Value.t -> Value.t -> M := Constant.bytes "" |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + BinOp.add (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "depth" |), + Constant.int 1 + |), + M.get_name (| globals, "STACK_DEPTH_LIMIT" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "gas" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let call_data := @@ -604,6 +778,40 @@ Definition generic_call : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "child_evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_error" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "incorporate_child_on_success" |), make_list [ @@ -658,7 +866,7 @@ Definition generic_call : Value.t -> Value.t -> M := make_list [ M.get_field (| M.get_name (| globals, "evm" |), "memory" |); M.get_name (| globals, "memory_output_start_position" |); - M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), Constant.None_:M.get_name (| globals, "actual_output_size" |) |) + M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), M.slice (| Constant.None_, M.get_name (| globals, "actual_output_size" |) |) |) ], make_dict [] |) in @@ -756,6 +964,19 @@ Definition call : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "to" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let access_gas_cost := + M.get_name (| globals, "GAS_WARM_ACCESS" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -768,49 +989,57 @@ Definition call : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in let create_gas_cost := - (* if *) -M.if_then_else (| - BoolOp.or (| - M.call (| - M.get_name (| globals, "is_account_alive" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); - M.get_name (| globals, "to" |) - ], - make_dict [] - |), - ltac:(M.monadic ( - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |) - )) - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + BoolOp.or (| + M.call (| + M.get_name (| globals, "is_account_alive" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "to" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "GAS_NEW_ACCOUNT" |) + )) |) in let transfer_gas_cost := - (* if *) -M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "GAS_CALL_VALUE" |) + )) |) in let message_call_gas := M.call (| M.get_name (| globals, "calculate_message_call_gas" |), @@ -886,6 +1115,40 @@ M.call (| make_dict [] |), "balance" |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "sender_balance" |), + M.get_name (| globals, "value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "generic_call" |), make_list [ @@ -1007,6 +1270,19 @@ Definition callcode : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "code_address" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let access_gas_cost := + M.get_name (| globals, "GAS_WARM_ACCESS" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1019,21 +1295,25 @@ Definition callcode : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in let transfer_gas_cost := - (* if *) -M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "GAS_CALL_VALUE" |) + )) |) in let message_call_gas := M.call (| M.get_name (| globals, "calculate_message_call_gas" |), @@ -1084,6 +1364,40 @@ M.call (| make_dict [] |), "balance" |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "sender_balance" |), + M.get_name (| globals, "value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "generic_call" |), make_list [ @@ -1139,9 +1453,63 @@ Definition selfdestruct : Value.t -> Value.t -> M := let gas_cost := M.get_name (| globals, "GAS_SELF_DESTRUCT" |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "beneficiary" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |) in + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + UnOp.not (| M.call (| + M.get_name (| globals, "is_account_alive" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) + M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -1215,6 +1583,28 @@ Definition selfdestruct : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -1308,6 +1698,19 @@ Definition delegatecall : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "code_address" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let access_gas_cost := + M.get_name (| globals, "GAS_WARM_ACCESS" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1471,6 +1874,19 @@ Definition staticcall : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "to" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let access_gas_cost := + M.get_name (| globals, "GAS_WARM_ACCESS" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1630,6 +2046,6 @@ Definition revert : Value.t -> Value.t -> M := make_dict [] |) |) in - let _ := M.raise (| Some(M.get_name (| globals, "Revert" |)) + let _ := M.raise (| Some(M.get_name (| globals, "Revert" |)) |) in let _ := M.pass (| |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/vm/interpreter.v b/CoqOfPython/ethereum/paris/vm/interpreter.v index 5bc6f30..0c037cb 100644 --- a/CoqOfPython/ethereum/paris/vm/interpreter.v +++ b/CoqOfPython/ethereum/paris/vm/interpreter.v @@ -63,83 +63,83 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". - -Require state. -Axiom state_account_exists_and_is_empty : - IsGlobalAlias globals state.globals "account_exists_and_is_empty". -Axiom state_account_has_code_or_nonce : - IsGlobalAlias globals state.globals "account_has_code_or_nonce". -Axiom state_begin_transaction : - IsGlobalAlias globals state.globals "begin_transaction". -Axiom state_commit_transaction : - IsGlobalAlias globals state.globals "commit_transaction". -Axiom state_destroy_storage : - IsGlobalAlias globals state.globals "destroy_storage". -Axiom state_increment_nonce : - IsGlobalAlias globals state.globals "increment_nonce". -Axiom state_mark_account_created : - IsGlobalAlias globals state.globals "mark_account_created". -Axiom state_move_ether : - IsGlobalAlias globals state.globals "move_ether". -Axiom state_rollback_transaction : - IsGlobalAlias globals state.globals "rollback_transaction". -Axiom state_set_code : - IsGlobalAlias globals state.globals "set_code". -Axiom state_touch_account : - IsGlobalAlias globals state.globals "touch_account". - -Require vm. -Axiom vm_Message : - IsGlobalAlias globals vm.globals "Message". - -Require vm.gas. -Axiom vm_gas_GAS_CODE_DEPOSIT : - IsGlobalAlias globals vm.gas.globals "GAS_CODE_DEPOSIT". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". - -Require vm.precompiled_contracts.mapping. -Axiom vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : - IsGlobalAlias globals vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". - -Require __init__. -Axiom __init___Environment : - IsGlobalAlias globals __init__.globals "Environment". -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require exceptions. -Axiom exceptions_AddressCollision : - IsGlobalAlias globals exceptions.globals "AddressCollision". -Axiom exceptions_ExceptionalHalt : - IsGlobalAlias globals exceptions.globals "ExceptionalHalt". -Axiom exceptions_InvalidContractPrefix : - IsGlobalAlias globals exceptions.globals "InvalidContractPrefix". -Axiom exceptions_InvalidOpcode : - IsGlobalAlias globals exceptions.globals "InvalidOpcode". -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". -Axiom exceptions_Revert : - IsGlobalAlias globals exceptions.globals "Revert". -Axiom exceptions_StackDepthLimitError : - IsGlobalAlias globals exceptions.globals "StackDepthLimitError". - -Require instructions. -Axiom instructions_Ops : - IsGlobalAlias globals instructions.globals "Ops". -Axiom instructions_op_implementation : - IsGlobalAlias globals instructions.globals "op_implementation". - -Require runtime. -Axiom runtime_get_valid_jump_destinations : - IsGlobalAlias globals runtime.globals "get_valid_jump_destinations". +Require ethereum.paris.blocks. +Axiom ethereum_paris_blocks_Log : + IsGlobalAlias globals ethereum.paris.blocks.globals "Log". + +Require ethereum.paris.fork_types. +Axiom ethereum_paris_fork_types_Address : + IsGlobalAlias globals ethereum.paris.fork_types.globals "Address". + +Require ethereum.paris.state. +Axiom ethereum_paris_state_account_exists_and_is_empty : + IsGlobalAlias globals ethereum.paris.state.globals "account_exists_and_is_empty". +Axiom ethereum_paris_state_account_has_code_or_nonce : + IsGlobalAlias globals ethereum.paris.state.globals "account_has_code_or_nonce". +Axiom ethereum_paris_state_begin_transaction : + IsGlobalAlias globals ethereum.paris.state.globals "begin_transaction". +Axiom ethereum_paris_state_commit_transaction : + IsGlobalAlias globals ethereum.paris.state.globals "commit_transaction". +Axiom ethereum_paris_state_destroy_storage : + IsGlobalAlias globals ethereum.paris.state.globals "destroy_storage". +Axiom ethereum_paris_state_increment_nonce : + IsGlobalAlias globals ethereum.paris.state.globals "increment_nonce". +Axiom ethereum_paris_state_mark_account_created : + IsGlobalAlias globals ethereum.paris.state.globals "mark_account_created". +Axiom ethereum_paris_state_move_ether : + IsGlobalAlias globals ethereum.paris.state.globals "move_ether". +Axiom ethereum_paris_state_rollback_transaction : + IsGlobalAlias globals ethereum.paris.state.globals "rollback_transaction". +Axiom ethereum_paris_state_set_code : + IsGlobalAlias globals ethereum.paris.state.globals "set_code". +Axiom ethereum_paris_state_touch_account : + IsGlobalAlias globals ethereum.paris.state.globals "touch_account". + +Require ethereum.paris.vm.__init__. +Axiom ethereum_paris_vm___init___Message : + IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Message". + +Require ethereum.paris.vm.gas. +Axiom ethereum_paris_vm_gas_GAS_CODE_DEPOSIT : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_CODE_DEPOSIT". +Axiom ethereum_paris_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "charge_gas". + +Require ethereum.paris.vm.precompiled_contracts.mapping. +Axiom ethereum_paris_vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : + IsGlobalAlias globals ethereum.paris.vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". + +Require ethereum.paris.vm.__init__. +Axiom ethereum_paris_vm___init___Environment : + IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Environment". +Axiom ethereum_paris_vm___init___Evm : + IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Evm". + +Require ethereum.paris.vm.exceptions. +Axiom ethereum_paris_vm_exceptions_AddressCollision : + IsGlobalAlias globals ethereum.paris.vm.exceptions.globals "AddressCollision". +Axiom ethereum_paris_vm_exceptions_ExceptionalHalt : + IsGlobalAlias globals ethereum.paris.vm.exceptions.globals "ExceptionalHalt". +Axiom ethereum_paris_vm_exceptions_InvalidContractPrefix : + IsGlobalAlias globals ethereum.paris.vm.exceptions.globals "InvalidContractPrefix". +Axiom ethereum_paris_vm_exceptions_InvalidOpcode : + IsGlobalAlias globals ethereum.paris.vm.exceptions.globals "InvalidOpcode". +Axiom ethereum_paris_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.paris.vm.exceptions.globals "OutOfGasError". +Axiom ethereum_paris_vm_exceptions_Revert : + IsGlobalAlias globals ethereum.paris.vm.exceptions.globals "Revert". +Axiom ethereum_paris_vm_exceptions_StackDepthLimitError : + IsGlobalAlias globals ethereum.paris.vm.exceptions.globals "StackDepthLimitError". + +Require ethereum.paris.vm.instructions.__init__. +Axiom ethereum_paris_vm_instructions___init___Ops : + IsGlobalAlias globals ethereum.paris.vm.instructions.__init__.globals "Ops". +Axiom ethereum_paris_vm_instructions___init___op_implementation : + IsGlobalAlias globals ethereum.paris.vm.instructions.__init__.globals "op_implementation". + +Require ethereum.paris.vm.runtime. +Axiom ethereum_paris_vm_runtime_get_valid_jump_destinations : + IsGlobalAlias globals ethereum.paris.vm.runtime.globals "get_valid_jump_destinations". Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -186,6 +186,94 @@ Definition process_message_call : Value.t -> Value.t -> M := Output of the message call " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "message" |), "target" |), + M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) + |), + (* then *) + ltac:(M.monadic ( + let is_collision := + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_name (| globals, "is_collision" |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallOutput" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "tuple" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "AddressCollision" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let evm := + M.call (| + M.get_name (| globals, "process_create_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let evm := M.call (| M.get_name (| globals, "process_message" |), @@ -196,11 +284,74 @@ Definition process_message_call : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_field (| M.get_name (| globals, "message" |), "target" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_field (| M.get_name (| globals, "message" |), "target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( +(* At stmt: unsupported node type: AnnAssign *) + let accounts_to_delete := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let touched_accounts := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let refund_counter := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let logs := M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in let accounts_to_delete := @@ -244,6 +395,7 @@ Definition process_message_call : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). Definition process_create_message : Value.t -> Value.t -> M := @@ -305,6 +457,28 @@ Definition process_create_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), + (* then *) + ltac:(M.monadic ( + let contract_code := + M.get_field (| M.get_name (| globals, "evm" |), "output" |) in + let contract_code_gas := + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "contract_code" |) + ], + make_dict [] + |), + M.get_name (| globals, "GAS_CODE_DEPOSIT" |) + |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "rollback_transaction" |), make_list [ @@ -316,6 +490,7 @@ Definition process_create_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) + |) in M.pure Constant.None_)). Definition process_message : Value.t -> Value.t -> M := @@ -337,6 +512,24 @@ Definition process_message : Value.t -> Value.t -> M := Items containing execution specific objects " in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_field (| M.get_name (| globals, "message" |), "depth" |), + M.get_name (| globals, "STACK_DEPTH_LIMIT" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "StackDepthLimitError" |), + make_list [ + Constant.str "Stack depth limit reached" + ], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -355,6 +548,32 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + M.get_field (| M.get_name (| globals, "message" |), "should_transfer_value" |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "message" |), "value" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "move_ether" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "caller" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |); + M.get_field (| M.get_name (| globals, "message" |), "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let evm := @@ -367,6 +586,21 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "rollback_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "commit_transaction" |), make_list [ @@ -378,6 +612,7 @@ Definition process_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) + |) in M.pure Constant.None_)). Definition execute_code : Value.t -> Value.t -> M := @@ -417,4 +652,5 @@ Definition execute_code : Value.t -> Value.t -> M := (* At stmt: unsupported node type: Try *) let _ := M.return_ (| M.get_name (| globals, "evm" |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/vm/memory.v b/CoqOfPython/ethereum/paris/vm/memory.v index 4b107fd..08d2290 100644 --- a/CoqOfPython/ethereum/paris/vm/memory.v +++ b/CoqOfPython/ethereum/paris/vm/memory.v @@ -21,13 +21,13 @@ Require ethereum.utils.byte. Axiom ethereum_utils_byte_right_pad_zero_bytes : IsGlobalAlias globals ethereum.utils.byte.globals "right_pad_zero_bytes". -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". Definition memory_write : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,7 +45,22 @@ Definition memory_write : Value.t -> Value.t -> M := Data to write to memory. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |), + M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) |) |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_)). @@ -71,7 +86,23 @@ Definition memory_read_bytes : Value.t -> Value.t -> M := Data read from memory. " in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |) + M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |) |) + |) in M.pure Constant.None_)). Definition buffer_read : Value.t -> Value.t -> M := @@ -98,9 +129,25 @@ Definition buffer_read : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "right_pad_zero_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |) |); + M.get_subscript (| M.get_name (| globals, "buffer" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |) |); M.get_name (| globals, "size" |) ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/__init__.v index ca49311..d1d68ef 100644 --- a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/__init__.v +++ b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/__init__.v @@ -18,9 +18,9 @@ Addresses of precompiled contracts and mappings to their implementations. ". -Require utils.hexadecimal. -Axiom utils_hexadecimal_hex_to_address : - IsGlobalAlias globals utils.hexadecimal.globals "hex_to_address". +Require ethereum.paris.utils.hexadecimal. +Axiom ethereum_paris_utils_hexadecimal_hex_to_address : + IsGlobalAlias globals ethereum.paris.utils.hexadecimal.globals "hex_to_address". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS"; Constant.str "MODEXP_ADDRESS"; Constant.str "ALT_BN128_ADD_ADDRESS"; Constant.str "ALT_BN128_MUL_ADDRESS"; Constant.str "ALT_BN128_PAIRING_CHECK_ADDRESS"; Constant.str "BLAKE2F_ADDRESS" ] diff --git a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/alt_bn128.v index abe4238..996ca5a 100644 --- a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/alt_bn128.v +++ b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/alt_bn128.v @@ -45,21 +45,21 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.paris.vm.__init__. +Axiom ethereum_paris_vm___init___Evm : + IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.paris.vm.gas. +Axiom ethereum_paris_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "charge_gas". -Require vm.memory. -Axiom vm_memory_buffer_read : - IsGlobalAlias globals vm.memory.globals "buffer_read". +Require ethereum.paris.vm.memory. +Axiom ethereum_paris_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.paris.vm.memory.globals "buffer_read". -Require exceptions. -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". +Require ethereum.paris.vm.exceptions. +Axiom ethereum_paris_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.paris.vm.exceptions.globals "OutOfGasError". Definition alt_bn128_add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -210,6 +210,18 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) in For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ] do let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -353,6 +365,18 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) in For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ] do let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -425,6 +449,27 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| + BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 192 + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let result := @@ -464,7 +509,7 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "data" |), BinOp.add (| + M.get_subscript (| M.get_name (| globals, "data" |), M.slice (| BinOp.add (| BinOp.mult (| M.get_name (| globals, "i" |), Constant.int 192 @@ -473,11 +518,35 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := Constant.int 32, M.get_name (| globals, "j" |) |) - |) |) + |), BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "j" |), + Constant.int 1 + |) + |) + |) |) |) ], make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -538,10 +607,80 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "p" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "q" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let result := + BinOp.mult (| + M.get_name (| globals, "result" |), + M.call (| + M.get_name (| globals, "pairing" |), + make_list [ + M.get_name (| globals, "q" |); + M.get_name (| globals, "p" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "result" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| diff --git a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/blake2f.v b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/blake2f.v index 1647d48..3a5e5fd 100644 --- a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/blake2f.v +++ b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/blake2f.v @@ -25,19 +25,19 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.paris.vm.__init__. +Axiom ethereum_paris_vm___init___Evm : + IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_BLAKE2_PER_ROUND : - IsGlobalAlias globals vm.gas.globals "GAS_BLAKE2_PER_ROUND". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.paris.vm.gas. +Axiom ethereum_paris_vm_gas_GAS_BLAKE2_PER_ROUND : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_BLAKE2_PER_ROUND". +Axiom ethereum_paris_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "charge_gas". -Require exceptions. -Axiom exceptions_InvalidParameter : - IsGlobalAlias globals exceptions.globals "InvalidParameter". +Require ethereum.paris.vm.exceptions. +Axiom ethereum_paris_vm_exceptions_InvalidParameter : + IsGlobalAlias globals ethereum.paris.vm.exceptions.globals "InvalidParameter". Definition blake2f : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/ecrecover.v index 0cbcf16..7ac3491 100644 --- a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/ecrecover.v @@ -37,19 +37,19 @@ Require ethereum.utils.byte. Axiom ethereum_utils_byte_left_pad_zero_bytes : IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.paris.vm.__init__. +Axiom ethereum_paris_vm___init___Evm : + IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_ECRECOVER : - IsGlobalAlias globals vm.gas.globals "GAS_ECRECOVER". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.paris.vm.gas. +Axiom ethereum_paris_vm_gas_GAS_ECRECOVER : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_ECRECOVER". +Axiom ethereum_paris_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "charge_gas". -Require vm.memory. -Axiom vm_memory_buffer_read : - IsGlobalAlias globals vm.memory.globals "buffer_read". +Require ethereum.paris.vm.memory. +Axiom ethereum_paris_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.paris.vm.memory.globals "buffer_read". Definition ecrecover : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -188,12 +188,78 @@ Definition ecrecover : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "v" |), + Constant.int 27 + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "v" |), + Constant.int 28 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + Constant.int 0, + M.get_name (| globals, "r" |) + |), + ltac:(M.monadic ( + Compare.gt_e (| + M.get_name (| globals, "r" |), + M.get_name (| globals, "SECP256K1N" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + Constant.int 0, + M.get_name (| globals, "s" |) + |), + ltac:(M.monadic ( + Compare.gt_e (| + M.get_name (| globals, "s" |), + M.get_name (| globals, "SECP256K1N" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: Try *) @@ -204,7 +270,7 @@ Definition ecrecover : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12 |) in + |), M.slice (| Constant.int 12, Constant.int 32 |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/identity.v index fa96704..5bd5e8c 100644 --- a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/identity.v +++ b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/identity.v @@ -25,17 +25,17 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.paris.vm.__init__. +Axiom ethereum_paris_vm___init___Evm : + IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_IDENTITY : - IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY". -Axiom vm_gas_GAS_IDENTITY_WORD : - IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY_WORD". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.paris.vm.gas. +Axiom ethereum_paris_vm_gas_GAS_IDENTITY : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_IDENTITY". +Axiom ethereum_paris_vm_gas_GAS_IDENTITY_WORD : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_IDENTITY_WORD". +Axiom ethereum_paris_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "charge_gas". Definition identity : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/mapping.v index 8a2e2eb..428d10c 100644 --- a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/mapping.v +++ b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/mapping.v @@ -23,60 +23,60 @@ Axiom typing_Callable : Axiom typing_Dict : IsGlobalAlias globals typing.globals "Dict". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". - -Require __init__. -Axiom __init___ALT_BN128_ADD_ADDRESS : - IsGlobalAlias globals __init__.globals "ALT_BN128_ADD_ADDRESS". -Axiom __init___ALT_BN128_MUL_ADDRESS : - IsGlobalAlias globals __init__.globals "ALT_BN128_MUL_ADDRESS". -Axiom __init___ALT_BN128_PAIRING_CHECK_ADDRESS : - IsGlobalAlias globals __init__.globals "ALT_BN128_PAIRING_CHECK_ADDRESS". -Axiom __init___BLAKE2F_ADDRESS : - IsGlobalAlias globals __init__.globals "BLAKE2F_ADDRESS". -Axiom __init___ECRECOVER_ADDRESS : - IsGlobalAlias globals __init__.globals "ECRECOVER_ADDRESS". -Axiom __init___IDENTITY_ADDRESS : - IsGlobalAlias globals __init__.globals "IDENTITY_ADDRESS". -Axiom __init___MODEXP_ADDRESS : - IsGlobalAlias globals __init__.globals "MODEXP_ADDRESS". -Axiom __init___RIPEMD160_ADDRESS : - IsGlobalAlias globals __init__.globals "RIPEMD160_ADDRESS". -Axiom __init___SHA256_ADDRESS : - IsGlobalAlias globals __init__.globals "SHA256_ADDRESS". - -Require alt_bn128. -Axiom alt_bn128_alt_bn128_add : - IsGlobalAlias globals alt_bn128.globals "alt_bn128_add". -Axiom alt_bn128_alt_bn128_mul : - IsGlobalAlias globals alt_bn128.globals "alt_bn128_mul". -Axiom alt_bn128_alt_bn128_pairing_check : - IsGlobalAlias globals alt_bn128.globals "alt_bn128_pairing_check". - -Require blake2f. -Axiom blake2f_blake2f : - IsGlobalAlias globals blake2f.globals "blake2f". - -Require ecrecover. -Axiom ecrecover_ecrecover : - IsGlobalAlias globals ecrecover.globals "ecrecover". - -Require identity. -Axiom identity_identity : - IsGlobalAlias globals identity.globals "identity". - -Require modexp. -Axiom modexp_modexp : - IsGlobalAlias globals modexp.globals "modexp". - -Require ripemd160. -Axiom ripemd160_ripemd160 : - IsGlobalAlias globals ripemd160.globals "ripemd160". - -Require sha256. -Axiom sha256_sha256 : - IsGlobalAlias globals sha256.globals "sha256". +Require ethereum.paris.fork_types. +Axiom ethereum_paris_fork_types_Address : + IsGlobalAlias globals ethereum.paris.fork_types.globals "Address". + +Require ethereum.paris.vm.precompiled_contracts.__init__. +Axiom ethereum_paris_vm_precompiled_contracts___init___ALT_BN128_ADD_ADDRESS : + IsGlobalAlias globals ethereum.paris.vm.precompiled_contracts.__init__.globals "ALT_BN128_ADD_ADDRESS". +Axiom ethereum_paris_vm_precompiled_contracts___init___ALT_BN128_MUL_ADDRESS : + IsGlobalAlias globals ethereum.paris.vm.precompiled_contracts.__init__.globals "ALT_BN128_MUL_ADDRESS". +Axiom ethereum_paris_vm_precompiled_contracts___init___ALT_BN128_PAIRING_CHECK_ADDRESS : + IsGlobalAlias globals ethereum.paris.vm.precompiled_contracts.__init__.globals "ALT_BN128_PAIRING_CHECK_ADDRESS". +Axiom ethereum_paris_vm_precompiled_contracts___init___BLAKE2F_ADDRESS : + IsGlobalAlias globals ethereum.paris.vm.precompiled_contracts.__init__.globals "BLAKE2F_ADDRESS". +Axiom ethereum_paris_vm_precompiled_contracts___init___ECRECOVER_ADDRESS : + IsGlobalAlias globals ethereum.paris.vm.precompiled_contracts.__init__.globals "ECRECOVER_ADDRESS". +Axiom ethereum_paris_vm_precompiled_contracts___init___IDENTITY_ADDRESS : + IsGlobalAlias globals ethereum.paris.vm.precompiled_contracts.__init__.globals "IDENTITY_ADDRESS". +Axiom ethereum_paris_vm_precompiled_contracts___init___MODEXP_ADDRESS : + IsGlobalAlias globals ethereum.paris.vm.precompiled_contracts.__init__.globals "MODEXP_ADDRESS". +Axiom ethereum_paris_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : + IsGlobalAlias globals ethereum.paris.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". +Axiom ethereum_paris_vm_precompiled_contracts___init___SHA256_ADDRESS : + IsGlobalAlias globals ethereum.paris.vm.precompiled_contracts.__init__.globals "SHA256_ADDRESS". + +Require ethereum.paris.vm.precompiled_contracts.alt_bn128. +Axiom ethereum_paris_vm_precompiled_contracts_alt_bn128_alt_bn128_add : + IsGlobalAlias globals ethereum.paris.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_add". +Axiom ethereum_paris_vm_precompiled_contracts_alt_bn128_alt_bn128_mul : + IsGlobalAlias globals ethereum.paris.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_mul". +Axiom ethereum_paris_vm_precompiled_contracts_alt_bn128_alt_bn128_pairing_check : + IsGlobalAlias globals ethereum.paris.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_pairing_check". + +Require ethereum.paris.vm.precompiled_contracts.blake2f. +Axiom ethereum_paris_vm_precompiled_contracts_blake2f_blake2f : + IsGlobalAlias globals ethereum.paris.vm.precompiled_contracts.blake2f.globals "blake2f". + +Require ethereum.paris.vm.precompiled_contracts.ecrecover. +Axiom ethereum_paris_vm_precompiled_contracts_ecrecover_ecrecover : + IsGlobalAlias globals ethereum.paris.vm.precompiled_contracts.ecrecover.globals "ecrecover". + +Require ethereum.paris.vm.precompiled_contracts.identity. +Axiom ethereum_paris_vm_precompiled_contracts_identity_identity : + IsGlobalAlias globals ethereum.paris.vm.precompiled_contracts.identity.globals "identity". + +Require ethereum.paris.vm.precompiled_contracts.modexp. +Axiom ethereum_paris_vm_precompiled_contracts_modexp_modexp : + IsGlobalAlias globals ethereum.paris.vm.precompiled_contracts.modexp.globals "modexp". + +Require ethereum.paris.vm.precompiled_contracts.ripemd160. +Axiom ethereum_paris_vm_precompiled_contracts_ripemd160_ripemd160 : + IsGlobalAlias globals ethereum.paris.vm.precompiled_contracts.ripemd160.globals "ripemd160". + +Require ethereum.paris.vm.precompiled_contracts.sha256. +Axiom ethereum_paris_vm_precompiled_contracts_sha256_sha256 : + IsGlobalAlias globals ethereum.paris.vm.precompiled_contracts.sha256.globals "sha256". (* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/modexp.v index 3505244..5056a4d 100644 --- a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/modexp.v +++ b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/modexp.v @@ -25,17 +25,17 @@ Axiom ethereum_base_types_Bytes : Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.paris.vm.__init__. +Axiom ethereum_paris_vm___init___Evm : + IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.paris.vm.gas. +Axiom ethereum_paris_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "charge_gas". -Require memory. -Axiom memory_buffer_read : - IsGlobalAlias globals memory.globals "buffer_read". +Require ethereum.paris.vm.memory. +Axiom ethereum_paris_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.paris.vm.memory.globals "buffer_read". Definition GQUADDIVISOR : Value.t := M.run ltac:(M.monadic ( Constant.int 3 @@ -192,6 +192,36 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_name (| globals, "base_length" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "modulus_length" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [], + make_dict [] + |) + |) in + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let base := @@ -254,6 +284,30 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "modulus" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + BinOp.mult (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + Constant.bytes "00" + ], + make_dict [] + |), + M.get_name (| globals, "modulus_length" |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| @@ -338,6 +392,7 @@ Definition complexity : Value.t -> Value.t -> M := M.get_name (| globals, "words" |), Constant.int 2 |) + |) in M.pure Constant.None_)). Definition iterations : Value.t -> Value.t -> M := @@ -364,7 +419,76 @@ Definition iterations : Value.t -> Value.t -> M := Number of iterations. " in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.lt_e (| + M.get_name (| globals, "exponent_length" |), + Constant.int 32 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "exponent_head" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let count := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "exponent_length" |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let bit_length := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "exponent_head" |), "bit_length" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "bit_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let bit_length := BinOp.sub + Constant.int 1 + Constant.int 1 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let count := + M.get_name (| globals, "bit_length" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let length_part := BinOp.mult (| Constant.int 8, @@ -392,6 +516,20 @@ Definition iterations : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "bits_part" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let bits_part := BinOp.sub + Constant.int 1 + Constant.int 1 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let count := @@ -418,6 +556,7 @@ Definition iterations : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition gas_cost : Value.t -> Value.t -> M := @@ -489,4 +628,5 @@ Definition gas_cost : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/ripemd160.v index 96f8dcd..93fdcfc 100644 --- a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/ripemd160.v +++ b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/ripemd160.v @@ -31,17 +31,17 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.paris.vm.__init__. +Axiom ethereum_paris_vm___init___Evm : + IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_RIPEMD160 : - IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160". -Axiom vm_gas_GAS_RIPEMD160_WORD : - IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160_WORD". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.paris.vm.gas. +Axiom ethereum_paris_vm_gas_GAS_RIPEMD160 : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_RIPEMD160". +Axiom ethereum_paris_vm_gas_GAS_RIPEMD160_WORD : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_RIPEMD160_WORD". +Axiom ethereum_paris_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "charge_gas". Definition ripemd160 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/sha256.v index 9f6d2bf..f6e9c6c 100644 --- a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/sha256.v +++ b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/sha256.v @@ -27,17 +27,17 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.paris.vm.__init__. +Axiom ethereum_paris_vm___init___Evm : + IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_SHA256 : - IsGlobalAlias globals vm.gas.globals "GAS_SHA256". -Axiom vm_gas_GAS_SHA256_WORD : - IsGlobalAlias globals vm.gas.globals "GAS_SHA256_WORD". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.paris.vm.gas. +Axiom ethereum_paris_vm_gas_GAS_SHA256 : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_SHA256". +Axiom ethereum_paris_vm_gas_GAS_SHA256_WORD : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_SHA256_WORD". +Axiom ethereum_paris_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.paris.vm.gas.globals "charge_gas". Definition sha256 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/paris/vm/runtime.v b/CoqOfPython/ethereum/paris/vm/runtime.v index 2cd7652..ee592a8 100644 --- a/CoqOfPython/ethereum/paris/vm/runtime.v +++ b/CoqOfPython/ethereum/paris/vm/runtime.v @@ -25,9 +25,9 @@ Require ethereum.base_types. Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require instructions. -Axiom instructions_Ops : - IsGlobalAlias globals instructions.globals "Ops". +Require ethereum.paris.vm.instructions.__init__. +Axiom ethereum_paris_vm_instructions___init___Ops : + IsGlobalAlias globals ethereum.paris.vm.instructions.__init__.globals "Ops". Definition get_valid_jump_destinations : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -79,7 +79,55 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := |) do (* At stmt: unsupported node type: Try *) let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "current_opcode" |), + M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), + make_list [ + M.get_name (| globals, "pc" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.lt_e (| + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |), + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH32" |), "value" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let push_data_size := + BinOp.add (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) + |), + Constant.int 1 + |) in + let pc := BinOp.add + M.get_name (| globals, "push_data_size" |) + M.get_name (| globals, "push_data_size" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -90,4 +138,5 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := EndWhile. let _ := M.return_ (| M.get_name (| globals, "valid_jump_destinations" |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/vm/stack.v b/CoqOfPython/ethereum/paris/vm/stack.v index ea778df..cc70502 100644 --- a/CoqOfPython/ethereum/paris/vm/stack.v +++ b/CoqOfPython/ethereum/paris/vm/stack.v @@ -25,11 +25,11 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require exceptions. -Axiom exceptions_StackOverflowError : - IsGlobalAlias globals exceptions.globals "StackOverflowError". -Axiom exceptions_StackUnderflowError : - IsGlobalAlias globals exceptions.globals "StackUnderflowError". +Require ethereum.paris.vm.exceptions. +Axiom ethereum_paris_vm_exceptions_StackOverflowError : + IsGlobalAlias globals ethereum.paris.vm.exceptions.globals "StackOverflowError". +Axiom ethereum_paris_vm_exceptions_StackUnderflowError : + IsGlobalAlias globals ethereum.paris.vm.exceptions.globals "StackUnderflowError". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -49,6 +49,24 @@ Definition pop : Value.t -> Value.t -> M := " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "StackUnderflowError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -57,6 +75,7 @@ Definition pop : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). Definition push : Value.t -> Value.t -> M := @@ -75,6 +94,24 @@ Definition push : Value.t -> Value.t -> M := " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), + Constant.int 1024 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "StackOverflowError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -85,4 +122,5 @@ Definition push : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/rlp.v b/CoqOfPython/ethereum/rlp.v index 386cbf4..65abb6f 100644 --- a/CoqOfPython/ethereum/rlp.v +++ b/CoqOfPython/ethereum/rlp.v @@ -61,19 +61,19 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require base_types. -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes0 : - IsGlobalAlias globals base_types.globals "Bytes0". -Axiom base_types_Bytes20 : - IsGlobalAlias globals base_types.globals "Bytes20". -Axiom base_types_FixedBytes : - IsGlobalAlias globals base_types.globals "FixedBytes". -Axiom base_types_FixedUint : - IsGlobalAlias globals base_types.globals "FixedUint". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". +Require ethereum.base_types. +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Bytes20 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes20". +Axiom ethereum_base_types_FixedBytes : + IsGlobalAlias globals ethereum.base_types.globals "FixedBytes". +Axiom ethereum_base_types_FixedUint : + IsGlobalAlias globals ethereum.base_types.globals "FixedUint". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". Definition RLP : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Any" |) @@ -97,11 +97,188 @@ Definition encode : Value.t -> Value.t -> M := The RLP encoded bytes representing `raw_data`. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "raw_data" |); + make_tuple [ M.get_name (| globals, "bytearray" |); M.get_name (| globals, "bytes" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "encode_bytes" |), + make_list [ + M.get_name (| globals, "raw_data" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "raw_data" |); + make_tuple [ M.get_name (| globals, "Uint" |); M.get_name (| globals, "FixedUint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "encode" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "raw_data" |), "to_be_bytes" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "raw_data" |); + M.get_name (| globals, "str" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "encode_bytes" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "raw_data" |), "encode" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "raw_data" |); + M.get_name (| globals, "bool" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.get_name (| globals, "raw_data" |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "encode_bytes" |), + make_list [ + Constant.bytes "01" + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "encode_bytes" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "raw_data" |); + M.get_name (| globals, "Sequence" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "encode_sequence" |), + make_list [ + M.get_name (| globals, "raw_data" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "is_dataclass" |), + make_list [ + M.get_name (| globals, "raw_data" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "astuple" |), + make_list [ + M.get_name (| globals, "raw_data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.raise (| Some(M.call (| M.get_name (| globals, "RLPEncodingError" |), make_list [ @@ -120,7 +297,7 @@ Definition encode : Value.t -> Value.t -> M := |) ], make_dict [] - |)) + |)) |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -166,7 +343,57 @@ Definition encode_bytes : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_name (| globals, "len_raw_data" |), + Constant.int 1 + |), + ltac:(M.monadic ( + Compare.lt (| + M.get_subscript (| M.get_name (| globals, "raw_bytes" |), Constant.int 0 |), + Constant.int 128 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "raw_bytes" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "len_raw_data" |), + Constant.int 56 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + M.call (| + M.get_name (| globals, "bytes" |), + make_list [ + make_list [ + BinOp.add (| + Constant.int 128, + M.get_name (| globals, "len_raw_data" |) + |) + ] + ], + make_dict [] + |), + M.get_name (| globals, "raw_bytes" |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let len_raw_data_as_be := M.call (| M.get_field (| M.get_name (| globals, "len_raw_data" |), "to_be_bytes" |), @@ -198,6 +425,7 @@ Definition encode_bytes : Value.t -> Value.t -> M := |), M.get_name (| globals, "raw_bytes" |) |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -243,6 +471,34 @@ Definition encode_sequence : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "len_joined_encodings" |), + Constant.int 56 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + make_list [ + BinOp.add (| + Constant.int 192, + M.get_name (| globals, "len_joined_encodings" |) + |) + ] + ], + make_dict [] + |), + M.get_name (| globals, "joined_encodings" |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let len_joined_encodings_as_be := M.call (| M.get_field (| M.get_name (| globals, "len_joined_encodings" |), "to_be_bytes" |), @@ -274,6 +530,7 @@ Definition encode_sequence : Value.t -> Value.t -> M := |), M.get_name (| globals, "joined_encodings" |) |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -300,10 +557,11 @@ Definition get_joined_encodings : Value.t -> Value.t -> M := M.call (| M.get_field (| Constant.bytes "", "join" |), make_list [ - (* At expr: unsupported node type: GeneratorExp *) + Constant.str "(* At expr: unsupported node type: GeneratorExp *)" ], make_dict [] |) + |) in M.pure Constant.None_)). Definition decode : Value.t -> Value.t -> M := @@ -326,114 +584,875 @@ Definition decode : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.gt (| + Compare.gt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded_data" |) + ], + make_dict [] + |), + Constant.int 0 + |); + M.call (| + M.get_name (| globals, "RLPDecodingError" |), + make_list [ + Constant.str "Cannot decode empty bytestring" + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_subscript (| M.get_name (| globals, "encoded_data" |), Constant.int 0 |), + Constant.int 191 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "decode_to_bytes" |), + make_list [ + M.get_name (| globals, "encoded_data" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "decode_to_sequence" |), + make_list [ + M.get_name (| globals, "encoded_data" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_)). + +Definition T : Value.t := M.run ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "TypeVar" |), + make_list [ + Constant.str "T" + ], + make_dict [] + |) +)). + +Definition decode_to : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "cls"; "encoded_data" ] |) in + let _ := Constant.str " + Decode the bytes in `encoded_data` to an object of type `cls`. `cls` can be + a `Bytes` subclass, a dataclass, `Uint`, `U256` or `Tuple[cls]`. + + Parameters + ---------- + cls: `Type[T]` + The type to decode to. + encoded_data : + A sequence of bytes, in RLP form. + + Returns + ------- + decoded_data : `T` + Object decoded from `encoded_data`. + " in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "_decode_to" |), + make_list [ + M.get_name (| globals, "cls" |); + M.call (| + M.get_name (| globals, "decode" |), + make_list [ + M.get_name (| globals, "encoded_data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_)). + +Definition _decode_to : Value.t -> Value.t -> M := + fun (args kwargs : Value.t) => ltac:(M.monadic ( + let _ := M.set_locals (| args, kwargs, [ "cls"; "raw_rlp" ] |) in + let _ := Constant.str " + Decode the rlp structure in `encoded_data` to an object of type `cls`. + `cls` can be a `Bytes` subclass, a dataclass, `Uint`, `U256`, + `Tuple[cls, ...]`, `Tuple[cls1, cls2]` or `Union[Bytes, cls]`. + + Parameters + ---------- + cls: `Type[T]` + The type to decode to. + raw_rlp : + A decoded rlp structure. + + Returns + ------- + decoded_data : `T` + Object decoded from `encoded_data`. + " in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "cls" |); + M.call (| + M.get_name (| globals, "type" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "Tuple" |), make_tuple [ M.get_name (| globals, "Uint" |); (* At constant: unsupported node type: Constant *) ] |) + ], + make_dict [] + |) + ], + make_dict [] + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_field (| M.get_name (| globals, "cls" |), "_name" |), + Constant.str "Tuple" + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "raw_rlp" |); + M.get_name (| globals, "list" |) + ], + make_dict [] + |); + M.get_name (| globals, "RLPDecodingError" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "cls" |), "__args__" |), Constant.int 1 |), + (* At constant: unsupported node type: Constant *) + |), + (* then *) + ltac:(M.monadic ( + let args := + make_list [] in + For M.get_name (| globals, "raw_item" |) in M.get_name (| globals, "raw_rlp" |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "args" |), "append" |), + make_list [ + M.call (| + M.get_name (| globals, "_decode_to" |), + make_list [ + M.get_subscript (| M.get_field (| M.get_name (| globals, "cls" |), "__args__" |), Constant.int 0 |); + M.get_name (| globals, "raw_item" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "tuple" |), + make_list [ + M.get_name (| globals, "args" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let args := + make_list [] in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "raw_rlp" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "cls" |), "__args__" |) + ], + make_dict [] + |) + |); + M.get_name (| globals, "RLPDecodingError" |) + ], + make_dict [] + |) in + For make_tuple [ M.get_name (| globals, "t" |); M.get_name (| globals, "raw_item" |) ] in M.call (| + M.get_name (| globals, "zip" |), + make_list [ + M.get_field (| M.get_name (| globals, "cls" |), "__args__" |); + M.get_name (| globals, "raw_rlp" |) + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "args" |), "append" |), + make_list [ + M.call (| + M.get_name (| globals, "_decode_to" |), + make_list [ + M.get_name (| globals, "t" |); + M.get_name (| globals, "raw_item" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "tuple" |), + make_list [ + M.get_name (| globals, "args" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "cls" |), + M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Bytes0" |); M.get_name (| globals, "Bytes20" |) ] |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "raw_rlp" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |); + M.get_name (| globals, "RLPDecodingError" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "raw_rlp" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "raw_rlp" |) + ], + make_dict [] + |), + Constant.int 20 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "Bytes20" |), + make_list [ + M.get_name (| globals, "raw_rlp" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "RLPDecodingError" |), + make_list [ + M.call (| + M.get_field (| Constant.str "Bytes has length {}, expected 0 or 20", "format" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "raw_rlp" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |)) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "cls" |); + M.call (| + M.get_name (| globals, "type" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "List" |), M.get_name (| globals, "Bytes" |) |) + ], + make_dict [] + |) + ], + make_dict [] + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_field (| M.get_name (| globals, "cls" |), "_name" |), + Constant.str "List" + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "raw_rlp" |); + M.get_name (| globals, "list" |) + ], + make_dict [] + |); + M.get_name (| globals, "RLPDecodingError" |) + ], + make_dict [] + |) in + let items := + make_list [] in + For M.get_name (| globals, "raw_item" |) in M.get_name (| globals, "raw_rlp" |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "items" |), "append" |), + make_list [ + M.call (| + M.get_name (| globals, "_decode_to" |), + make_list [ + M.get_subscript (| M.get_field (| M.get_name (| globals, "cls" |), "__args__" |), Constant.int 0 |); + M.get_name (| globals, "raw_item" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + EndFor. + let _ := M.return_ (| + M.get_name (| globals, "items" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "cls" |); + M.call (| + M.get_name (| globals, "type" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Bytes" |); M.get_subscript (| M.get_name (| globals, "List" |), M.get_name (| globals, "Bytes" |) |) ] |) + ], + make_dict [] + |) + ], + make_dict [] + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_field (| M.get_name (| globals, "cls" |), "__origin__" |), + M.get_name (| globals, "Union" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.not_eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "cls" |), "__args__" |) + ], + make_dict [] + |), + Constant.int 2 + |), + ltac:(M.monadic ( + Compare.not_in (| + M.get_name (| globals, "Bytes" |), + M.get_field (| M.get_name (| globals, "cls" |), "__args__" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "RLPDecodingError" |), + make_list [ + M.call (| + M.get_field (| Constant.str "RLP Decoding to type {} is not supported", "format" |), + make_list [ + M.get_name (| globals, "cls" |) + ], + make_dict [] + |) + ], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "raw_rlp" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "raw_rlp" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "cls" |), "__args__" |), Constant.int 0 |), + M.get_name (| globals, "Bytes" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "_decode_to" |), + make_list [ + M.get_subscript (| M.get_field (| M.get_name (| globals, "cls" |), "__args__" |), Constant.int 1 |); + M.get_name (| globals, "raw_rlp" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "_decode_to" |), + make_list [ + M.get_subscript (| M.get_field (| M.get_name (| globals, "cls" |), "__args__" |), Constant.int 0 |); + M.get_name (| globals, "raw_rlp" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "issubclass" |), + make_list [ + M.get_name (| globals, "cls" |); + M.get_name (| globals, "bool" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "raw_rlp" |), + Constant.bytes "01" + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "cls" |), + make_list [ + Constant.bool true + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "raw_rlp" |), + Constant.bytes "" + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "cls" |), + make_list [ + Constant.bool false + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "TypeError" |), + make_list [ + M.call (| + M.get_field (| Constant.str "Cannot decode {} as {}", "format" |), + make_list [ + M.get_name (| globals, "raw_rlp" |); + M.get_name (| globals, "cls" |) + ], + make_dict [] + |) + ], + make_dict [] + |)) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "issubclass" |), + make_list [ + M.get_name (| globals, "cls" |); + M.get_name (| globals, "FixedBytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "raw_rlp" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |); + M.get_name (| globals, "RLPDecodingError" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "raw_rlp" |) + ], + make_dict [] + |), + M.get_field (| M.get_name (| globals, "cls" |), "LENGTH" |) + |); + M.get_name (| globals, "RLPDecodingError" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "cls" |), + make_list [ + M.get_name (| globals, "raw_rlp" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "issubclass" |), + make_list [ + M.get_name (| globals, "cls" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "raw_rlp" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |); + M.get_name (| globals, "RLPDecodingError" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "raw_rlp" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "issubclass" |), + make_list [ + M.get_name (| globals, "cls" |); + make_tuple [ M.get_name (| globals, "Uint" |); M.get_name (| globals, "FixedUint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "raw_rlp" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |); + M.get_name (| globals, "RLPDecodingError" |) + ], + make_dict [] + |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "is_dataclass" |), + make_list [ + M.get_name (| globals, "cls" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "raw_rlp" |); + M.get_name (| globals, "list" |) + ], + make_dict [] + |); + M.get_name (| globals, "RLPDecodingError" |) + ], + make_dict [] + |) in + let _ := M.assert (| M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "raw_rlp" |); + M.get_name (| globals, "list" |) + ], + make_dict [] + |) |) in + let args := + make_list [] in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.eq (| M.call (| M.get_name (| globals, "len" |), make_list [ - M.get_name (| globals, "encoded_data" |) + M.call (| + M.get_name (| globals, "fields" |), + make_list [ + M.get_name (| globals, "cls" |) + ], + make_dict [] + |) ], make_dict [] |), - Constant.int 0 + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "raw_rlp" |) + ], + make_dict [] + |) |); + M.get_name (| globals, "RLPDecodingError" |) + ], + make_dict [] + |) in + For make_tuple [ M.get_name (| globals, "field" |); M.get_name (| globals, "rlp_item" |) ] in M.call (| + M.get_name (| globals, "zip" |), + make_list [ M.call (| - M.get_name (| globals, "RLPDecodingError" |), + M.get_name (| globals, "fields" |), make_list [ - Constant.str "Cannot decode empty bytestring" + M.get_name (| globals, "cls" |) ], make_dict [] - |) + |); + M.get_name (| globals, "raw_rlp" |) ], make_dict [] - |) in - let _ := - let _ := M.return_ (| - M.call (| - M.get_name (| globals, "decode_to_sequence" |), - make_list [ - M.get_name (| globals, "encoded_data" |) - ], - make_dict [] - |) - M.pure Constant.None_ - )) |) in - M.pure Constant.None_)). - -Definition T : Value.t := M.run ltac:(M.monadic ( - M.call (| - M.get_name (| globals, "TypeVar" |), + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "args" |), "append" |), make_list [ - Constant.str "T" - ], - make_dict [] - |) -)). - -Definition decode_to : Value.t -> Value.t -> M := - fun (args kwargs : Value.t) => ltac:(M.monadic ( - let _ := M.set_locals (| args, kwargs, [ "cls"; "encoded_data" ] |) in - let _ := Constant.str " - Decode the bytes in `encoded_data` to an object of type `cls`. `cls` can be - a `Bytes` subclass, a dataclass, `Uint`, `U256` or `Tuple[cls]`. - - Parameters - ---------- - cls: `Type[T]` - The type to decode to. - encoded_data : - A sequence of bytes, in RLP form. - - Returns - ------- - decoded_data : `T` - Object decoded from `encoded_data`. - " in - let _ := M.return_ (| M.call (| M.get_name (| globals, "_decode_to" |), make_list [ - M.get_name (| globals, "cls" |); - M.call (| - M.get_name (| globals, "decode" |), - make_list [ - M.get_name (| globals, "encoded_data" |) - ], - make_dict [] - |) + M.get_field (| M.get_name (| globals, "field" |), "type" |); + M.get_name (| globals, "rlp_item" |) ], make_dict [] |) - M.pure Constant.None_)). - -Definition _decode_to : Value.t -> Value.t -> M := - fun (args kwargs : Value.t) => ltac:(M.monadic ( - let _ := M.set_locals (| args, kwargs, [ "cls"; "raw_rlp" ] |) in - let _ := Constant.str " - Decode the rlp structure in `encoded_data` to an object of type `cls`. - `cls` can be a `Bytes` subclass, a dataclass, `Uint`, `U256`, - `Tuple[cls, ...]`, `Tuple[cls1, cls2]` or `Union[Bytes, cls]`. - - Parameters - ---------- - cls: `Type[T]` - The type to decode to. - raw_rlp : - A decoded rlp structure. - - Returns - ------- - decoded_data : `T` - Object decoded from `encoded_data`. - " in - let _ := - let _ := - let _ := - let _ := - let _ := - let _ := - let _ := - let _ := - let _ := + ], + make_dict [] + |) in + EndFor. + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "cast" |), + make_list [ + M.get_name (| globals, "T" |); + M.call (| + M.get_name (| globals, "cls" |), + M.get_name (| globals, "args" |), + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.raise (| Some(M.call (| M.get_name (| globals, "RLPDecodingError" |), make_list [ @@ -446,7 +1465,7 @@ Definition _decode_to : Value.t -> Value.t -> M := |) ], make_dict [] - |)) + |)) |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -485,7 +1504,95 @@ Definition decode_to_bytes : Value.t -> Value.t -> M := RLP decoded Bytes data " in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded_bytes" |) + ], + make_dict [] + |), + Constant.int 1 + |), + ltac:(M.monadic ( + Compare.lt (| + M.get_subscript (| M.get_name (| globals, "encoded_bytes" |), Constant.int 0 |), + Constant.int 128 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "encoded_bytes" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_subscript (| M.get_name (| globals, "encoded_bytes" |), Constant.int 0 |), + Constant.int 183 + |), + (* then *) + ltac:(M.monadic ( + let len_raw_data := + BinOp.sub (| + M.get_subscript (| M.get_name (| globals, "encoded_bytes" |), Constant.int 0 |), + Constant.int 128 + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt (| + M.get_name (| globals, "len_raw_data" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded_bytes" |) + ], + make_dict [] + |) + |); + M.get_name (| globals, "RLPDecodingError" |) + ], + make_dict [] + |) in + let raw_data := + M.get_subscript (| M.get_name (| globals, "encoded_bytes" |), M.slice (| Constant.int 1, BinOp.add (| + Constant.int 1, + M.get_name (| globals, "len_raw_data" |) + |) |) |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + UnOp.not (| BoolOp.and (| + Compare.eq (| + M.get_name (| globals, "len_raw_data" |), + Constant.int 1 + |), + ltac:(M.monadic ( + Compare.lt (| + M.get_subscript (| M.get_name (| globals, "raw_data" |), Constant.int 0 |), + Constant.int 128 + |) + )) + |) |); + M.get_name (| globals, "RLPDecodingError" |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "raw_data" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let decoded_data_start_idx := BinOp.sub (| BinOp.add (| @@ -529,7 +1636,7 @@ Definition decode_to_bytes : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "encoded_bytes" |), Constant.int 1 |) + M.get_subscript (| M.get_name (| globals, "encoded_bytes" |), M.slice (| Constant.int 1, M.get_name (| globals, "decoded_data_start_idx" |) |) |) ], make_dict [] |) in @@ -570,7 +1677,8 @@ Definition decode_to_bytes : Value.t -> Value.t -> M := make_dict [] |) in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "encoded_bytes" |), M.get_name (| globals, "decoded_data_start_idx" |) |) + M.get_subscript (| M.get_name (| globals, "encoded_bytes" |), M.slice (| M.get_name (| globals, "decoded_data_start_idx" |), M.get_name (| globals, "decoded_data_end_idx" |) |) |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -595,6 +1703,44 @@ Definition decode_to_sequence : Value.t -> Value.t -> M := Sequence of objects decoded from `encoded_sequence`. " in let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_subscript (| M.get_name (| globals, "encoded_sequence" |), Constant.int 0 |), + Constant.int 247 + |), + (* then *) + ltac:(M.monadic ( + let len_joined_encodings := + BinOp.sub (| + M.get_subscript (| M.get_name (| globals, "encoded_sequence" |), Constant.int 0 |), + Constant.int 192 + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt (| + M.get_name (| globals, "len_joined_encodings" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded_sequence" |) + ], + make_dict [] + |) + |); + M.get_name (| globals, "RLPDecodingError" |) + ], + make_dict [] + |) in + let joined_encodings := + M.get_subscript (| M.get_name (| globals, "encoded_sequence" |), M.slice (| Constant.int 1, BinOp.add (| + Constant.int 1, + M.get_name (| globals, "len_joined_encodings" |) + |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let joined_encodings_start_idx := BinOp.sub (| BinOp.add (| @@ -638,7 +1784,7 @@ Definition decode_to_sequence : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "encoded_sequence" |), Constant.int 1 |) + M.get_subscript (| M.get_name (| globals, "encoded_sequence" |), M.slice (| Constant.int 1, M.get_name (| globals, "joined_encodings_start_idx" |) |) |) ], make_dict [] |) in @@ -679,7 +1825,7 @@ Definition decode_to_sequence : Value.t -> Value.t -> M := make_dict [] |) in let joined_encodings := - M.get_subscript (| M.get_name (| globals, "encoded_sequence" |), M.get_name (| globals, "joined_encodings_start_idx" |) |) in + M.get_subscript (| M.get_name (| globals, "encoded_sequence" |), M.slice (| M.get_name (| globals, "joined_encodings_start_idx" |), M.get_name (| globals, "joined_encodings_end_idx" |) |) |) in M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -690,6 +1836,7 @@ Definition decode_to_sequence : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition decode_joined_encodings : Value.t -> Value.t -> M := @@ -727,7 +1874,7 @@ Definition decode_joined_encodings : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "decode_item_length" |), make_list [ - M.get_subscript (| M.get_name (| globals, "joined_encodings" |), M.get_name (| globals, "item_start_idx" |) |) + M.get_subscript (| M.get_name (| globals, "joined_encodings" |), M.slice (| M.get_name (| globals, "item_start_idx" |), Constant.None_ |) |) ], make_dict [] |) in @@ -755,7 +1902,10 @@ Definition decode_joined_encodings : Value.t -> Value.t -> M := make_dict [] |) in let encoded_item := - M.get_subscript (| M.get_name (| globals, "joined_encodings" |), M.get_name (| globals, "item_start_idx" |) |) in + M.get_subscript (| M.get_name (| globals, "joined_encodings" |), M.slice (| M.get_name (| globals, "item_start_idx" |), BinOp.add (| + M.get_name (| globals, "item_start_idx" |), + M.get_name (| globals, "encoded_item_length" |) + |) |) |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "decoded_sequence" |), "append" |), make_list [ @@ -775,6 +1925,7 @@ Definition decode_joined_encodings : Value.t -> Value.t -> M := EndWhile. let _ := M.return_ (| M.get_name (| globals, "decoded_sequence" |) + |) in M.pure Constant.None_)). Definition decode_item_length : Value.t -> Value.t -> M := @@ -835,10 +1986,166 @@ Definition decode_item_length : Value.t -> Value.t -> M := let decoded_data_length := Constant.int 0 in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "first_rlp_byte" |), + Constant.int 128 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.int 1 + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "first_rlp_byte" |), + Constant.int 183 + |), + (* then *) + ltac:(M.monadic ( + let decoded_data_length := + BinOp.sub (| + M.get_name (| globals, "first_rlp_byte" |), + Constant.int 128 + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "first_rlp_byte" |), + Constant.int 191 + |), + (* then *) + ltac:(M.monadic ( + let length_length := + BinOp.sub (| + M.get_name (| globals, "first_rlp_byte" |), + Constant.int 183 + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt (| + M.get_name (| globals, "length_length" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded_data" |) + ], + make_dict [] + |) + |); + M.get_name (| globals, "RLPDecodingError" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_eq (| + M.get_subscript (| M.get_name (| globals, "encoded_data" |), Constant.int 1 |), + Constant.int 0 + |); + M.get_name (| globals, "RLPDecodingError" |) + ], + make_dict [] + |) in + let decoded_data_length := + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "encoded_data" |), M.slice (| Constant.int 1, BinOp.add (| + Constant.int 1, + M.get_name (| globals, "length_length" |) + |) |) |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "first_rlp_byte" |), + Constant.int 247 + |), + (* then *) + ltac:(M.monadic ( + let decoded_data_length := + BinOp.sub (| + M.get_name (| globals, "first_rlp_byte" |), + Constant.int 192 + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "first_rlp_byte" |), + Constant.int 255 + |), + (* then *) + ltac:(M.monadic ( + let length_length := + BinOp.sub (| + M.get_name (| globals, "first_rlp_byte" |), + Constant.int 247 + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.lt (| + M.get_name (| globals, "length_length" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded_data" |) + ], + make_dict [] + |) + |); + M.get_name (| globals, "RLPDecodingError" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.not_eq (| + M.get_subscript (| M.get_name (| globals, "encoded_data" |), Constant.int 1 |), + Constant.int 0 + |); + M.get_name (| globals, "RLPDecodingError" |) + ], + make_dict [] + |) in + let decoded_data_length := + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "encoded_data" |), M.slice (| Constant.int 1, BinOp.add (| + Constant.int 1, + M.get_name (| globals, "length_length" |) + |) |) |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -857,6 +2164,7 @@ Definition decode_item_length : Value.t -> Value.t -> M := |), M.get_name (| globals, "decoded_data_length" |) |) + |) in M.pure Constant.None_)). Definition rlp_hash : Value.t -> Value.t -> M := @@ -889,4 +2197,5 @@ Definition rlp_hash : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/blocks.v b/CoqOfPython/ethereum/shanghai/blocks.v index 2130667..74717c4 100644 --- a/CoqOfPython/ethereum/shanghai/blocks.v +++ b/CoqOfPython/ethereum/shanghai/blocks.v @@ -24,37 +24,37 @@ Axiom typing_Tuple : Axiom typing_Union : IsGlobalAlias globals typing.globals "Union". -Require base_types. -Axiom base_types_U64 : - IsGlobalAlias globals base_types.globals "U64". -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes8 : - IsGlobalAlias globals base_types.globals "Bytes8". -Axiom base_types_Bytes32 : - IsGlobalAlias globals base_types.globals "Bytes32". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require crypto.hash. -Axiom crypto_hash_Hash32 : - IsGlobalAlias globals crypto.hash.globals "Hash32". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". - -Require transactions. -Axiom transactions_LegacyTransaction : - IsGlobalAlias globals transactions.globals "LegacyTransaction". +Require ethereum.base_types. +Axiom ethereum_base_types_U64 : + IsGlobalAlias globals ethereum.base_types.globals "U64". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes8 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes8". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". + +Require ethereum.shanghai.fork_types. +Axiom ethereum_shanghai_fork_types_Address : + IsGlobalAlias globals ethereum.shanghai.fork_types.globals "Address". +Axiom ethereum_shanghai_fork_types_Bloom : + IsGlobalAlias globals ethereum.shanghai.fork_types.globals "Bloom". +Axiom ethereum_shanghai_fork_types_Root : + IsGlobalAlias globals ethereum.shanghai.fork_types.globals "Root". + +Require ethereum.shanghai.transactions. +Axiom ethereum_shanghai_transactions_LegacyTransaction : + IsGlobalAlias globals ethereum.shanghai.transactions.globals "LegacyTransaction". Definition Withdrawal : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/shanghai/bloom.v b/CoqOfPython/ethereum/shanghai/bloom.v index 04650ff..32d85e3 100644 --- a/CoqOfPython/ethereum/shanghai/bloom.v +++ b/CoqOfPython/ethereum/shanghai/bloom.v @@ -33,13 +33,13 @@ Require ethereum.crypto.hash. Axiom ethereum_crypto_hash_keccak256 : IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". +Require ethereum.shanghai.blocks. +Axiom ethereum_shanghai_blocks_Log : + IsGlobalAlias globals ethereum.shanghai.blocks.globals "Log". -Require fork_types. -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". +Require ethereum.shanghai.fork_types. +Axiom ethereum_shanghai_fork_types_Bloom : + IsGlobalAlias globals ethereum.shanghai.fork_types.globals "Bloom". Definition add_to_bloom : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -72,7 +72,10 @@ Definition add_to_bloom : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |) |) + M.get_subscript (| M.get_name (| globals, "hash" |), M.slice (| M.get_name (| globals, "idx" |), BinOp.add (| + M.get_name (| globals, "idx" |), + Constant.int 2 + |) |) |) ], make_dict [] |), @@ -157,4 +160,5 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/fork.v b/CoqOfPython/ethereum/shanghai/fork.v index be9d24a..35598b8 100644 --- a/CoqOfPython/ethereum/shanghai/fork.v +++ b/CoqOfPython/ethereum/shanghai/fork.v @@ -57,113 +57,113 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U64 : - IsGlobalAlias globals base_types.globals "U64". -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". - -Require __init__. -Axiom __init___vm : - IsGlobalAlias globals __init__.globals "vm". - -Require blocks. -Axiom blocks_Block : - IsGlobalAlias globals blocks.globals "Block". -Axiom blocks_Header : - IsGlobalAlias globals blocks.globals "Header". -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". -Axiom blocks_Receipt : - IsGlobalAlias globals blocks.globals "Receipt". -Axiom blocks_Withdrawal : - IsGlobalAlias globals blocks.globals "Withdrawal". - -Require bloom. -Axiom bloom_logs_bloom : - IsGlobalAlias globals bloom.globals "logs_bloom". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". - -Require state. -Axiom state_State : - IsGlobalAlias globals state.globals "State". -Axiom state_account_exists_and_is_empty : - IsGlobalAlias globals state.globals "account_exists_and_is_empty". -Axiom state_destroy_account : - IsGlobalAlias globals state.globals "destroy_account". -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". -Axiom state_increment_nonce : - IsGlobalAlias globals state.globals "increment_nonce". -Axiom state_process_withdrawal : - IsGlobalAlias globals state.globals "process_withdrawal". -Axiom state_set_account_balance : - IsGlobalAlias globals state.globals "set_account_balance". -Axiom state_state_root : - IsGlobalAlias globals state.globals "state_root". - -Require transactions. -Axiom transactions_TX_ACCESS_LIST_ADDRESS_COST : - IsGlobalAlias globals transactions.globals "TX_ACCESS_LIST_ADDRESS_COST". -Axiom transactions_TX_ACCESS_LIST_STORAGE_KEY_COST : - IsGlobalAlias globals transactions.globals "TX_ACCESS_LIST_STORAGE_KEY_COST". -Axiom transactions_TX_BASE_COST : - IsGlobalAlias globals transactions.globals "TX_BASE_COST". -Axiom transactions_TX_CREATE_COST : - IsGlobalAlias globals transactions.globals "TX_CREATE_COST". -Axiom transactions_TX_DATA_COST_PER_NON_ZERO : - IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_NON_ZERO". -Axiom transactions_TX_DATA_COST_PER_ZERO : - IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_ZERO". -Axiom transactions_AccessListTransaction : - IsGlobalAlias globals transactions.globals "AccessListTransaction". -Axiom transactions_FeeMarketTransaction : - IsGlobalAlias globals transactions.globals "FeeMarketTransaction". -Axiom transactions_LegacyTransaction : - IsGlobalAlias globals transactions.globals "LegacyTransaction". -Axiom transactions_Transaction : - IsGlobalAlias globals transactions.globals "Transaction". -Axiom transactions_decode_transaction : - IsGlobalAlias globals transactions.globals "decode_transaction". -Axiom transactions_encode_transaction : - IsGlobalAlias globals transactions.globals "encode_transaction". - -Require trie. -Axiom trie_Trie : - IsGlobalAlias globals trie.globals "Trie". -Axiom trie_root : - IsGlobalAlias globals trie.globals "root". -Axiom trie_trie_set : - IsGlobalAlias globals trie.globals "trie_set". - -Require utils.message. -Axiom utils_message_prepare_message : - IsGlobalAlias globals utils.message.globals "prepare_message". - -Require vm.gas. -Axiom vm_gas_init_code_cost : - IsGlobalAlias globals vm.gas.globals "init_code_cost". - -Require vm.interpreter. -Axiom vm_interpreter_MAX_CODE_SIZE : - IsGlobalAlias globals vm.interpreter.globals "MAX_CODE_SIZE". -Axiom vm_interpreter_process_message_call : - IsGlobalAlias globals vm.interpreter.globals "process_message_call". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U64 : + IsGlobalAlias globals ethereum.base_types.globals "U64". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.shanghai.__init__. +Axiom ethereum_shanghai___init___vm : + IsGlobalAlias globals ethereum.shanghai.__init__.globals "vm". + +Require ethereum.shanghai.blocks. +Axiom ethereum_shanghai_blocks_Block : + IsGlobalAlias globals ethereum.shanghai.blocks.globals "Block". +Axiom ethereum_shanghai_blocks_Header : + IsGlobalAlias globals ethereum.shanghai.blocks.globals "Header". +Axiom ethereum_shanghai_blocks_Log : + IsGlobalAlias globals ethereum.shanghai.blocks.globals "Log". +Axiom ethereum_shanghai_blocks_Receipt : + IsGlobalAlias globals ethereum.shanghai.blocks.globals "Receipt". +Axiom ethereum_shanghai_blocks_Withdrawal : + IsGlobalAlias globals ethereum.shanghai.blocks.globals "Withdrawal". + +Require ethereum.shanghai.bloom. +Axiom ethereum_shanghai_bloom_logs_bloom : + IsGlobalAlias globals ethereum.shanghai.bloom.globals "logs_bloom". + +Require ethereum.shanghai.fork_types. +Axiom ethereum_shanghai_fork_types_Address : + IsGlobalAlias globals ethereum.shanghai.fork_types.globals "Address". +Axiom ethereum_shanghai_fork_types_Bloom : + IsGlobalAlias globals ethereum.shanghai.fork_types.globals "Bloom". +Axiom ethereum_shanghai_fork_types_Root : + IsGlobalAlias globals ethereum.shanghai.fork_types.globals "Root". + +Require ethereum.shanghai.state. +Axiom ethereum_shanghai_state_State : + IsGlobalAlias globals ethereum.shanghai.state.globals "State". +Axiom ethereum_shanghai_state_account_exists_and_is_empty : + IsGlobalAlias globals ethereum.shanghai.state.globals "account_exists_and_is_empty". +Axiom ethereum_shanghai_state_destroy_account : + IsGlobalAlias globals ethereum.shanghai.state.globals "destroy_account". +Axiom ethereum_shanghai_state_get_account : + IsGlobalAlias globals ethereum.shanghai.state.globals "get_account". +Axiom ethereum_shanghai_state_increment_nonce : + IsGlobalAlias globals ethereum.shanghai.state.globals "increment_nonce". +Axiom ethereum_shanghai_state_process_withdrawal : + IsGlobalAlias globals ethereum.shanghai.state.globals "process_withdrawal". +Axiom ethereum_shanghai_state_set_account_balance : + IsGlobalAlias globals ethereum.shanghai.state.globals "set_account_balance". +Axiom ethereum_shanghai_state_state_root : + IsGlobalAlias globals ethereum.shanghai.state.globals "state_root". + +Require ethereum.shanghai.transactions. +Axiom ethereum_shanghai_transactions_TX_ACCESS_LIST_ADDRESS_COST : + IsGlobalAlias globals ethereum.shanghai.transactions.globals "TX_ACCESS_LIST_ADDRESS_COST". +Axiom ethereum_shanghai_transactions_TX_ACCESS_LIST_STORAGE_KEY_COST : + IsGlobalAlias globals ethereum.shanghai.transactions.globals "TX_ACCESS_LIST_STORAGE_KEY_COST". +Axiom ethereum_shanghai_transactions_TX_BASE_COST : + IsGlobalAlias globals ethereum.shanghai.transactions.globals "TX_BASE_COST". +Axiom ethereum_shanghai_transactions_TX_CREATE_COST : + IsGlobalAlias globals ethereum.shanghai.transactions.globals "TX_CREATE_COST". +Axiom ethereum_shanghai_transactions_TX_DATA_COST_PER_NON_ZERO : + IsGlobalAlias globals ethereum.shanghai.transactions.globals "TX_DATA_COST_PER_NON_ZERO". +Axiom ethereum_shanghai_transactions_TX_DATA_COST_PER_ZERO : + IsGlobalAlias globals ethereum.shanghai.transactions.globals "TX_DATA_COST_PER_ZERO". +Axiom ethereum_shanghai_transactions_AccessListTransaction : + IsGlobalAlias globals ethereum.shanghai.transactions.globals "AccessListTransaction". +Axiom ethereum_shanghai_transactions_FeeMarketTransaction : + IsGlobalAlias globals ethereum.shanghai.transactions.globals "FeeMarketTransaction". +Axiom ethereum_shanghai_transactions_LegacyTransaction : + IsGlobalAlias globals ethereum.shanghai.transactions.globals "LegacyTransaction". +Axiom ethereum_shanghai_transactions_Transaction : + IsGlobalAlias globals ethereum.shanghai.transactions.globals "Transaction". +Axiom ethereum_shanghai_transactions_decode_transaction : + IsGlobalAlias globals ethereum.shanghai.transactions.globals "decode_transaction". +Axiom ethereum_shanghai_transactions_encode_transaction : + IsGlobalAlias globals ethereum.shanghai.transactions.globals "encode_transaction". + +Require ethereum.shanghai.trie. +Axiom ethereum_shanghai_trie_Trie : + IsGlobalAlias globals ethereum.shanghai.trie.globals "Trie". +Axiom ethereum_shanghai_trie_root : + IsGlobalAlias globals ethereum.shanghai.trie.globals "root". +Axiom ethereum_shanghai_trie_trie_set : + IsGlobalAlias globals ethereum.shanghai.trie.globals "trie_set". + +Require ethereum.shanghai.utils.message. +Axiom ethereum_shanghai_utils_message_prepare_message : + IsGlobalAlias globals ethereum.shanghai.utils.message.globals "prepare_message". + +Require ethereum.shanghai.vm.gas. +Axiom ethereum_shanghai_vm_gas_init_code_cost : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "init_code_cost". + +Require ethereum.shanghai.vm.interpreter. +Axiom ethereum_shanghai_vm_interpreter_MAX_CODE_SIZE : + IsGlobalAlias globals ethereum.shanghai.vm.interpreter.globals "MAX_CODE_SIZE". +Axiom ethereum_shanghai_vm_interpreter_process_message_call : + IsGlobalAlias globals ethereum.shanghai.vm.interpreter.globals "process_message_call". Definition BASE_FEE_MAX_CHANGE_DENOMINATOR : Value.t := M.run ltac:(M.monadic ( Constant.int 8 @@ -230,6 +230,7 @@ Definition apply_fork : Value.t -> Value.t -> M := " in let _ := M.return_ (| M.get_name (| globals, "old" |) + |) in M.pure Constant.None_)). Definition get_last_256_block_hashes : Value.t -> Value.t -> M := @@ -255,8 +256,28 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := Hashes of the recent 256 blocks in order of increasing block number. " in let recent_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |) |) in + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "recent_blocks" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + make_list [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let recent_block_hashes := @@ -295,6 +316,7 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "recent_block_hashes" |) + |) in M.pure Constant.None_)). Definition state_transition : Value.t -> Value.t -> M := @@ -440,6 +462,27 @@ Definition state_transition : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |) + ], + make_dict [] + |), + Constant.int 255 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -487,7 +530,63 @@ Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "parent_gas_used" |), + M.get_name (| globals, "parent_gas_target" |) + |), + (* then *) + ltac:(M.monadic ( + let expected_base_fee_per_gas := + M.get_name (| globals, "parent_base_fee_per_gas" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "parent_gas_used" |), + M.get_name (| globals, "parent_gas_target" |) + |), + (* then *) + ltac:(M.monadic ( + let gas_used_delta := + BinOp.sub (| + M.get_name (| globals, "parent_gas_used" |), + M.get_name (| globals, "parent_gas_target" |) + |) in + let parent_fee_gas_delta := + BinOp.mult (| + M.get_name (| globals, "parent_base_fee_per_gas" |), + M.get_name (| globals, "gas_used_delta" |) + |) in + let target_fee_gas_delta := + BinOp.floor_div (| + M.get_name (| globals, "parent_fee_gas_delta" |), + M.get_name (| globals, "parent_gas_target" |) + |) in + let base_fee_per_gas_delta := + M.call (| + M.get_name (| globals, "max" |), + make_list [ + BinOp.floor_div (| + M.get_name (| globals, "target_fee_gas_delta" |), + M.get_name (| globals, "BASE_FEE_MAX_CHANGE_DENOMINATOR" |) + |); + Constant.int 1 + ], + make_dict [] + |) in + let expected_base_fee_per_gas := + BinOp.add (| + M.get_name (| globals, "parent_base_fee_per_gas" |), + M.get_name (| globals, "base_fee_per_gas_delta" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let gas_used_delta := BinOp.sub (| M.get_name (| globals, "parent_gas_target" |), @@ -525,6 +624,7 @@ Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition validate_header : Value.t -> Value.t -> M := @@ -732,6 +832,60 @@ Definition check_transaction : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "FeeMarketTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt_e (| + M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |), + M.get_field (| M.get_name (| globals, "tx" |), "max_priority_fee_per_gas" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + Compare.gt_e (| + M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |), + M.get_name (| globals, "base_fee_per_gas" |) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let priority_fee_per_gas := + M.call (| + M.get_name (| globals, "min" |), + make_list [ + M.get_field (| M.get_name (| globals, "tx" |), "max_priority_fee_per_gas" |); + BinOp.sub (| + M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |), + M.get_name (| globals, "base_fee_per_gas" |) + |) + ], + make_dict [] + |) in + let effective_gas_price := + BinOp.add (| + M.get_name (| globals, "priority_fee_per_gas" |), + M.get_name (| globals, "base_fee_per_gas" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -749,6 +903,7 @@ Definition check_transaction : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| make_tuple [ M.get_name (| globals, "sender_address" |); M.get_name (| globals, "effective_gas_price" |) ] + |) in M.pure Constant.None_)). Definition make_receipt : Value.t -> Value.t -> M := @@ -781,9 +936,64 @@ Definition make_receipt : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "AccessListTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + Constant.bytes "01", + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "receipt" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "FeeMarketTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + Constant.bytes "02", + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "receipt" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "receipt" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -1022,6 +1232,29 @@ Definition apply_body : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_field (| M.get_name (| globals, "wd" |), "address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_field (| M.get_name (| globals, "wd" |), "address" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -1062,6 +1295,7 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition process_transaction : Value.t -> Value.t -> M := @@ -1119,6 +1353,26 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "FeeMarketTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let max_gas_fee := + BinOp.mult (| + M.get_field (| M.get_name (| globals, "tx" |), "gas" |), + M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let max_gas_fee := BinOp.mult (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), @@ -1224,6 +1478,39 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + make_tuple [ M.get_name (| globals, "AccessListTransaction" |); M.get_name (| globals, "FeeMarketTransaction" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + For make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "keys" |) ] in M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "preaccessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + For M.get_name (| globals, "key" |) in M.get_name (| globals, "keys" |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "preaccessed_storage_keys" |), "add" |), + make_list [ + make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "key" |) ] + ], + make_dict [] + |) in + EndFor. + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let message := @@ -1328,7 +1615,50 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "transaction_fee" |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| + M.get_name (| globals, "coinbase_balance_after_mining_fee" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |); + M.get_name (| globals, "coinbase_balance_after_mining_fee" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -1345,11 +1675,35 @@ Definition process_transaction : Value.t -> Value.t -> M := EndFor. For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "touched_accounts" |) do let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := M.return_ (| make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |); M.get_field (| M.get_name (| globals, "output" |), "error" |) ] + |) in M.pure Constant.None_)). Definition validate_transaction : Value.t -> Value.t -> M := @@ -1380,16 +1734,94 @@ Definition validate_transaction : Value.t -> Value.t -> M := True if the transaction can be executed, or False otherwise. " in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.call (| + M.get_name (| globals, "calculate_intrinsic_cost" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |), + M.get_field (| M.get_name (| globals, "tx" |), "gas" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_field (| M.get_name (| globals, "tx" |), "nonce" |), + BinOp.sub (| + BinOp.pow (| + Constant.int 2, + Constant.int 64 + |), + Constant.int 1 + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "tx" |), "to" |), + M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.gt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "tx" |), "data" |) + ], + make_dict [] + |), + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "MAX_CODE_SIZE" |) + |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| Constant.bool true + |) in M.pure Constant.None_)). Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := @@ -1421,6 +1853,20 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := Constant.int 0 in For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "byte" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let data_cost := BinOp.add M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in @@ -1428,6 +1874,52 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := )) |) in EndFor. let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "tx" |), "to" |), + M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) + |), + (* then *) + ltac:(M.monadic ( + let create_cost := + BinOp.add (| + M.get_name (| globals, "TX_CREATE_COST" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.call (| + M.get_name (| globals, "init_code_cost" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "tx" |), "data" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let create_cost := Constant.int 0 in M.pure Constant.None_ @@ -1435,6 +1927,47 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := let access_list_cost := Constant.int 0 in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + make_tuple [ M.get_name (| globals, "AccessListTransaction" |); M.get_name (| globals, "FeeMarketTransaction" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + For make_tuple [ M.get_name (| globals, "_address" |); M.get_name (| globals, "keys" |) ] in M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) do + let access_list_cost := BinOp.add + M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) + M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) in + let access_list_cost := BinOp.add + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "keys" |) + ], + make_dict [] + |), + M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) + |) + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "keys" |) + ], + make_dict [] + |), + M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) + |) in + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1454,6 +1987,7 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition recover_sender : Value.t -> Value.t -> M := @@ -1526,8 +2060,189 @@ Definition recover_sender : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "LegacyTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let v := + M.get_field (| M.get_name (| globals, "tx" |), "v" |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.eq (| + M.get_name (| globals, "v" |), + Constant.int 27 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "v" |), + Constant.int 28 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + BinOp.sub (| + M.get_name (| globals, "v" |), + Constant.int 27 + |); + M.call (| + M.get_name (| globals, "signing_hash_pre155" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "ensure" |), + make_list [ + BoolOp.or (| + Compare.eq (| + M.get_name (| globals, "v" |), + BinOp.add (| + Constant.int 35, + BinOp.mult (| + M.get_name (| globals, "chain_id" |), + Constant.int 2 + |) + |) + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "v" |), + BinOp.add (| + Constant.int 36, + BinOp.mult (| + M.get_name (| globals, "chain_id" |), + Constant.int 2 + |) + |) + |) + )) + |); + M.get_name (| globals, "InvalidBlock" |) + ], + make_dict [] + |) in + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + BinOp.sub (| + BinOp.sub (| + M.get_name (| globals, "v" |), + Constant.int 35 + |), + BinOp.mult (| + M.get_name (| globals, "chain_id" |), + Constant.int 2 + |) + |); + M.call (| + M.get_name (| globals, "signing_hash_155" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "chain_id" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "AccessListTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + M.get_field (| M.get_name (| globals, "tx" |), "y_parity" |); + M.call (| + M.get_name (| globals, "signing_hash_2930" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "FeeMarketTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + M.get_field (| M.get_name (| globals, "tx" |), "y_parity" |); + M.call (| + M.get_name (| globals, "signing_hash_1559" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -1544,10 +2259,11 @@ Definition recover_sender : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12 |) + |), M.slice (| Constant.int 12, Constant.int 32 |) |) ], make_dict [] |) + |) in M.pure Constant.None_)). Definition signing_hash_pre155 : Value.t -> Value.t -> M := @@ -1580,6 +2296,7 @@ Definition signing_hash_pre155 : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition signing_hash_155 : Value.t -> Value.t -> M := @@ -1626,6 +2343,7 @@ Definition signing_hash_155 : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition signing_hash_2930 : Value.t -> Value.t -> M := @@ -1661,6 +2379,7 @@ Definition signing_hash_2930 : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition signing_hash_1559 : Value.t -> Value.t -> M := @@ -1696,6 +2415,7 @@ Definition signing_hash_1559 : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition compute_header_hash : Value.t -> Value.t -> M := @@ -1746,6 +2466,7 @@ Definition compute_header_hash : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition check_gas_limit : Value.t -> Value.t -> M := @@ -1784,14 +2505,63 @@ Definition check_gas_limit : Value.t -> Value.t -> M := M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "gas_limit" |), + BinOp.add (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "gas_limit" |), + BinOp.sub (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "gas_limit" |), + M.get_name (| globals, "GAS_LIMIT_MINIMUM" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| Constant.bool true + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/fork_types.v b/CoqOfPython/ethereum/shanghai/fork_types.v index 5c7dac3..cc8e4a1 100644 --- a/CoqOfPython/ethereum/shanghai/fork_types.v +++ b/CoqOfPython/ethereum/shanghai/fork_types.v @@ -21,29 +21,29 @@ Require dataclasses. Axiom dataclasses_dataclass : IsGlobalAlias globals dataclasses.globals "dataclass". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes20 : - IsGlobalAlias globals base_types.globals "Bytes20". -Axiom base_types_Bytes256 : - IsGlobalAlias globals base_types.globals "Bytes256". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require crypto.hash. -Axiom crypto_hash_Hash32 : - IsGlobalAlias globals crypto.hash.globals "Hash32". -Axiom crypto_hash_keccak256 : - IsGlobalAlias globals crypto.hash.globals "keccak256". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes20 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes20". +Axiom ethereum_base_types_Bytes256 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) @@ -98,4 +98,5 @@ Definition encode_account : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/state.v b/CoqOfPython/ethereum/shanghai/state.v index dfaae0d..2feb225 100644 --- a/CoqOfPython/ethereum/shanghai/state.v +++ b/CoqOfPython/ethereum/shanghai/state.v @@ -56,33 +56,33 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require blocks. -Axiom blocks_Withdrawal : - IsGlobalAlias globals blocks.globals "Withdrawal". - -Require fork_types. -Axiom fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". -Axiom fork_types_Account : - IsGlobalAlias globals fork_types.globals "Account". -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". - -Require trie. -Axiom trie_EMPTY_TRIE_ROOT : - IsGlobalAlias globals trie.globals "EMPTY_TRIE_ROOT". -Axiom trie_Trie : - IsGlobalAlias globals trie.globals "Trie". -Axiom trie_copy_trie : - IsGlobalAlias globals trie.globals "copy_trie". -Axiom trie_root : - IsGlobalAlias globals trie.globals "root". -Axiom trie_trie_get : - IsGlobalAlias globals trie.globals "trie_get". -Axiom trie_trie_set : - IsGlobalAlias globals trie.globals "trie_set". +Require ethereum.shanghai.blocks. +Axiom ethereum_shanghai_blocks_Withdrawal : + IsGlobalAlias globals ethereum.shanghai.blocks.globals "Withdrawal". + +Require ethereum.shanghai.fork_types. +Axiom ethereum_shanghai_fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals ethereum.shanghai.fork_types.globals "EMPTY_ACCOUNT". +Axiom ethereum_shanghai_fork_types_Account : + IsGlobalAlias globals ethereum.shanghai.fork_types.globals "Account". +Axiom ethereum_shanghai_fork_types_Address : + IsGlobalAlias globals ethereum.shanghai.fork_types.globals "Address". +Axiom ethereum_shanghai_fork_types_Root : + IsGlobalAlias globals ethereum.shanghai.fork_types.globals "Root". + +Require ethereum.shanghai.trie. +Axiom ethereum_shanghai_trie_EMPTY_TRIE_ROOT : + IsGlobalAlias globals ethereum.shanghai.trie.globals "EMPTY_TRIE_ROOT". +Axiom ethereum_shanghai_trie_Trie : + IsGlobalAlias globals ethereum.shanghai.trie.globals "Trie". +Axiom ethereum_shanghai_trie_copy_trie : + IsGlobalAlias globals ethereum.shanghai.trie.globals "copy_trie". +Axiom ethereum_shanghai_trie_root : + IsGlobalAlias globals ethereum.shanghai.trie.globals "root". +Axiom ethereum_shanghai_trie_trie_get : + IsGlobalAlias globals ethereum.shanghai.trie.globals "trie_get". +Axiom ethereum_shanghai_trie_trie_set : + IsGlobalAlias globals ethereum.shanghai.trie.globals "trie_set". Definition State : Value.t := builtins.make_klass @@ -130,7 +130,7 @@ Definition begin_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) ], make_dict [] - |); (* At expr: unsupported node type: DictComp *) ] + |); Constant.str "(* At expr: unsupported node type: DictComp *)" ] ], make_dict [] |) in @@ -153,6 +153,19 @@ Definition commit_transaction : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "clear" |), + make_list [], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -178,6 +191,19 @@ Definition rollback_transaction : Value.t -> Value.t -> M := |) |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |), "clear" |), + make_list [], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -214,8 +240,27 @@ Definition get_account : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "account" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "account" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_ACCOUNT" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -250,6 +295,7 @@ Definition get_account_optional : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "account" |) + |) in M.pure Constant.None_)). Definition set_account : Value.t -> Value.t -> M := @@ -329,6 +375,18 @@ Definition destroy_storage : Value.t -> Value.t -> M := Address of account whose storage is to be deleted. " in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -391,6 +449,26 @@ Definition get_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "trie" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let value := @@ -412,6 +490,7 @@ Definition get_storage : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "value" |) + |) in M.pure Constant.None_)). Definition set_storage : Value.t -> Value.t -> M := @@ -452,6 +531,27 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "trie" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let trie := + M.call (| + M.get_name (| globals, "Trie" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), + M.get_name (| globals, "trie" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -464,6 +564,18 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + {} + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -488,8 +600,29 @@ Definition storage_root : Value.t -> Value.t -> M := " in let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_TRIE_ROOT" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -520,6 +653,7 @@ Definition state_root : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition account_exists : Value.t -> Value.t -> M := @@ -552,6 +686,7 @@ Definition account_exists : Value.t -> Value.t -> M := |), Constant.None_ |) + |) in M.pure Constant.None_)). Definition account_has_code_or_nonce : Value.t -> Value.t -> M := @@ -601,6 +736,7 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition is_account_empty : Value.t -> Value.t -> M := @@ -658,6 +794,7 @@ Definition is_account_empty : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition account_exists_and_is_empty : Value.t -> Value.t -> M := @@ -724,6 +861,7 @@ Definition account_exists_and_is_empty : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition is_account_alive : Value.t -> Value.t -> M := @@ -754,6 +892,20 @@ Definition is_account_alive : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "account" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| UnOp.not (| BoolOp.and (| Compare.eq (| @@ -781,6 +933,7 @@ Definition is_account_alive : Value.t -> Value.t -> M := |) )) |) |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -906,6 +1059,30 @@ Definition touch_account : Value.t -> Value.t -> M := The address of the account that need to initialised. " in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "account_exists" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "EMPTY_ACCOUNT" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -983,6 +1160,26 @@ Definition get_storage_original : Value.t -> Value.t -> M := Key of the storage slot. " in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -998,6 +1195,25 @@ Definition get_storage_original : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "original_account_trie" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let original_value := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let original_value := M.call (| M.get_name (| globals, "trie_get" |), @@ -1019,4 +1235,5 @@ Definition get_storage_original : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "original_value" |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/transactions.v b/CoqOfPython/ethereum/shanghai/transactions.v index afa27ec..5dda66e 100644 --- a/CoqOfPython/ethereum/shanghai/transactions.v +++ b/CoqOfPython/ethereum/shanghai/transactions.v @@ -19,33 +19,33 @@ Axiom typing_Tuple : Axiom typing_Union : IsGlobalAlias globals typing.globals "Union". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U64 : - IsGlobalAlias globals base_types.globals "U64". -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes0 : - IsGlobalAlias globals base_types.globals "Bytes0". -Axiom base_types_Bytes32 : - IsGlobalAlias globals base_types.globals "Bytes32". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require exceptions. -Axiom exceptions_InvalidBlock : - IsGlobalAlias globals exceptions.globals "InvalidBlock". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U64 : + IsGlobalAlias globals ethereum.base_types.globals "U64". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.exceptions. +Axiom ethereum_exceptions_InvalidBlock : + IsGlobalAlias globals ethereum.exceptions.globals "InvalidBlock". + +Require ethereum.shanghai.fork_types. +Axiom ethereum_shanghai_fork_types_Address : + IsGlobalAlias globals ethereum.shanghai.fork_types.globals "Address". Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( Constant.int 21000 @@ -112,15 +112,87 @@ Definition encode_transaction : Value.t -> Value.t -> M := Encode a transaction. Needed because non-legacy transactions aren't RLP. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "LegacyTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "tx" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "AccessListTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + Constant.bytes "01", + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "FeeMarketTransaction" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + BinOp.add (| + Constant.bytes "02", + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.raise (| Some(M.call (| M.get_name (| globals, "Exception" |), make_list [ - (* At expr: unsupported node type: JoinedStr *) + Constant.str "(* At expr: unsupported node type: JoinedStr *)" ], make_dict [] - |)) + |)) |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -136,8 +208,73 @@ Definition decode_transaction : Value.t -> Value.t -> M := Decode a transaction. Needed because non-legacy transactions aren't RLP. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), + Constant.int 1 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), + make_list [ + M.get_name (| globals, "AccessListTransaction" |); + M.get_subscript (| M.get_name (| globals, "tx" |), M.slice (| Constant.int 1, Constant.None_ |) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), + Constant.int 2 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), + make_list [ + M.get_name (| globals, "FeeMarketTransaction" |); + M.get_subscript (| M.get_name (| globals, "tx" |), M.slice (| Constant.int 1, Constant.None_ |) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidBlock" |)) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "tx" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/trie.v b/CoqOfPython/ethereum/shanghai/trie.v index 3dafa10..506e584 100644 --- a/CoqOfPython/ethereum/shanghai/trie.v +++ b/CoqOfPython/ethereum/shanghai/trie.v @@ -54,9 +54,9 @@ Require ethereum.crypto.hash. Axiom ethereum_crypto_hash_keccak256 : IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". -Require ethereum.paris. -Axiom ethereum_paris_trie : - IsGlobalAlias globals ethereum.paris.globals "trie". +Require ethereum.paris.__init__. +Axiom ethereum_paris___init___trie : + IsGlobalAlias globals ethereum.paris.__init__.globals "trie". Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : @@ -66,39 +66,39 @@ Require ethereum.utils.hexadecimal. Axiom ethereum_utils_hexadecimal_hex_to_bytes : IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require blocks. -Axiom blocks_Receipt : - IsGlobalAlias globals blocks.globals "Receipt". -Axiom blocks_Withdrawal : - IsGlobalAlias globals blocks.globals "Withdrawal". - -Require fork_types. -Axiom fork_types_Account : - IsGlobalAlias globals fork_types.globals "Account". -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". -Axiom fork_types_encode_account : - IsGlobalAlias globals fork_types.globals "encode_account". - -Require transactions. -Axiom transactions_LegacyTransaction : - IsGlobalAlias globals transactions.globals "LegacyTransaction". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.shanghai.blocks. +Axiom ethereum_shanghai_blocks_Receipt : + IsGlobalAlias globals ethereum.shanghai.blocks.globals "Receipt". +Axiom ethereum_shanghai_blocks_Withdrawal : + IsGlobalAlias globals ethereum.shanghai.blocks.globals "Withdrawal". + +Require ethereum.shanghai.fork_types. +Axiom ethereum_shanghai_fork_types_Account : + IsGlobalAlias globals ethereum.shanghai.fork_types.globals "Account". +Axiom ethereum_shanghai_fork_types_Address : + IsGlobalAlias globals ethereum.shanghai.fork_types.globals "Address". +Axiom ethereum_shanghai_fork_types_Root : + IsGlobalAlias globals ethereum.shanghai.fork_types.globals "Root". +Axiom ethereum_shanghai_fork_types_encode_account : + IsGlobalAlias globals ethereum.shanghai.fork_types.globals "encode_account". + +Require ethereum.shanghai.transactions. +Axiom ethereum_shanghai_transactions_LegacyTransaction : + IsGlobalAlias globals ethereum.shanghai.transactions.globals "LegacyTransaction". Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -205,16 +205,99 @@ Definition encode_internal_node : Value.t -> Value.t -> M := " in (* At stmt: unsupported node type: AnnAssign *) let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "node" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + Constant.bytes "" in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "LeafNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "rest_of_key" |); + Constant.bool true + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "ExtensionNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "key_segment" |); + Constant.bool false + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "BranchNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + BinOp.add (| + M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "value" |) + ] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ - (* At expr: unsupported node type: JoinedStr *) + Constant.str "(* At expr: unsupported node type: JoinedStr *)" ], make_dict [] - |)) + |)) |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -232,6 +315,26 @@ Definition encode_internal_node : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded" |) + ], + make_dict [] + |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "unencoded" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_name (| globals, "keccak256" |), @@ -240,6 +343,7 @@ Definition encode_internal_node : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -253,8 +357,86 @@ Definition encode_node : Value.t -> Value.t -> M := Currently mostly an unimplemented stub. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| + M.get_name (| globals, "storage_root" |), + Constant.None_ + |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "encode_account" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "storage_root" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Withdrawal" |); M.get_name (| globals, "U256" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "cast" |), + make_list [ + M.get_field (| M.get_name (| globals, "rlp" |), "RLP" |); + M.get_name (| globals, "node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "node" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "previous_trie" |), "encode_node" |), @@ -264,6 +446,7 @@ Definition encode_node : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -315,6 +498,7 @@ Definition copy_trie : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition trie_set : Value.t -> Value.t -> M := @@ -336,6 +520,32 @@ Definition trie_set : Value.t -> Value.t -> M := Node to insert at `key`. " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + M.get_field (| M.get_name (| globals, "trie" |), "default" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "key" |), + M.get_field (| M.get_name (| globals, "trie" |), "_data" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), M.get_name (| globals, "value" |) @@ -373,6 +583,7 @@ Definition trie_get : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition common_prefix_length : Value.t -> Value.t -> M := @@ -395,6 +606,34 @@ Definition common_prefix_length : Value.t -> Value.t -> M := make_dict [] |) do let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), + M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -406,6 +645,7 @@ Definition common_prefix_length : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition nibble_list_to_compact : Value.t -> Value.t -> M := @@ -451,6 +691,71 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + Constant.int 2 + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.mult (| + Constant.int 16, + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "is_leaf" |) + |) + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ @@ -512,6 +817,7 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition bytes_to_nibble_list : Value.t -> Value.t -> M := @@ -589,6 +895,7 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition _prepare_trie : Value.t -> Value.t -> M := @@ -618,6 +925,48 @@ Definition _prepare_trie : Value.t -> Value.t -> M := make_dict [] |) do let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| + M.get_name (| globals, "get_storage_root" |), + Constant.None_ + |) |) in + let address := + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |); + M.call (| + M.get_name (| globals, "get_storage_root" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let encoded_value := M.call (| M.get_name (| globals, "encode_node" |), @@ -641,6 +990,22 @@ Definition _prepare_trie : Value.t -> Value.t -> M := |) in (* At stmt: unsupported node type: AnnAssign *) let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "trie" |), "secured" |), + (* then *) + ltac:(M.monadic ( + let key := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let key := M.get_name (| globals, "preimage" |) in M.pure Constant.None_ @@ -658,6 +1023,7 @@ Definition _prepare_trie : Value.t -> Value.t -> M := EndFor. let _ := M.return_ (| M.get_name (| globals, "mapped" |) + |) in M.pure Constant.None_)). Definition root : Value.t -> Value.t -> M := @@ -711,6 +1077,44 @@ Definition root : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -727,6 +1131,7 @@ Definition root : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -753,6 +1158,26 @@ Definition patricialize : Value.t -> Value.t -> M := Root node of `obj`. " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let arbitrary_key := @@ -770,10 +1195,39 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), + Constant.int 1 + |), + (* then *) + ltac:(M.monadic ( + let leaf := + M.call (| + M.get_name (| globals, "LeafNode" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |); + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "leaf" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let substring := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |) |) in + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) in let prefix_length := M.call (| M.get_name (| globals, "len" |), @@ -792,7 +1246,7 @@ Definition patricialize : Value.t -> Value.t -> M := M.get_name (| globals, "common_prefix_length" |), make_list [ M.get_name (| globals, "substring" |); - M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) + M.get_subscript (| M.get_name (| globals, "key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) ], make_dict [] |) @@ -800,10 +1254,64 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "prefix_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "prefix_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let prefix := + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ExtensionNode" |), + make_list [ + M.get_name (| globals, "prefix" |); + M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_name (| globals, "obj" |); + BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) @@ -826,6 +1334,44 @@ Definition patricialize : Value.t -> Value.t -> M := Constant.bytes "" in For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |), + M.get_name (| globals, "level" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "AssertionError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) @@ -837,9 +1383,10 @@ Definition patricialize : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "BranchNode" |), make_list [ - (* At expr: unsupported node type: ListComp *); + Constant.str "(* At expr: unsupported node type: ListComp *)"; M.get_name (| globals, "value" |) ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/utils/address.v b/CoqOfPython/ethereum/shanghai/utils/address.v index ec03628..460b28c 100644 --- a/CoqOfPython/ethereum/shanghai/utils/address.v +++ b/CoqOfPython/ethereum/shanghai/utils/address.v @@ -38,13 +38,13 @@ Require ethereum.utils.byte. Axiom ethereum_utils_byte_left_pad_zero_bytes : IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.shanghai.fork_types. +Axiom ethereum_shanghai_fork_types_Address : + IsGlobalAlias globals ethereum.shanghai.fork_types.globals "Address". Definition to_address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -70,10 +70,11 @@ Definition to_address : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), make_list [], make_dict [] - |), UnOp.sub (| Constant.int 20 |) |) + |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) ], make_dict [] |) + |) in M.pure Constant.None_)). Definition compute_contract_address : Value.t -> Value.t -> M := @@ -113,7 +114,7 @@ Definition compute_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -131,6 +132,7 @@ Definition compute_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition compute_create2_contract_address : Value.t -> Value.t -> M := @@ -180,7 +182,7 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -198,4 +200,5 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/utils/hexadecimal.v b/CoqOfPython/ethereum/shanghai/utils/hexadecimal.v index 3f0eed6..10b0f37 100644 --- a/CoqOfPython/ethereum/shanghai/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/shanghai/utils/hexadecimal.v @@ -22,13 +22,13 @@ Require ethereum.utils.hexadecimal. Axiom ethereum_utils_hexadecimal_remove_hex_prefix : IsGlobalAlias globals ethereum.utils.hexadecimal.globals "remove_hex_prefix". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". +Require ethereum.shanghai.fork_types. +Axiom ethereum_shanghai_fork_types_Address : + IsGlobalAlias globals ethereum.shanghai.fork_types.globals "Address". +Axiom ethereum_shanghai_fork_types_Bloom : + IsGlobalAlias globals ethereum.shanghai.fork_types.globals "Bloom". +Axiom ethereum_shanghai_fork_types_Root : + IsGlobalAlias globals ethereum.shanghai.fork_types.globals "Root". Definition hex_to_root : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -66,6 +66,7 @@ Definition hex_to_root : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition hex_to_bloom : Value.t -> Value.t -> M := @@ -104,6 +105,7 @@ Definition hex_to_bloom : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition hex_to_address : Value.t -> Value.t -> M := @@ -149,4 +151,5 @@ Definition hex_to_address : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/utils/message.v b/CoqOfPython/ethereum/shanghai/utils/message.v index 635f015..a473e7e 100644 --- a/CoqOfPython/ethereum/shanghai/utils/message.v +++ b/CoqOfPython/ethereum/shanghai/utils/message.v @@ -40,27 +40,27 @@ Axiom ethereum_base_types_Bytes32 : Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.shanghai.fork_types. +Axiom ethereum_shanghai_fork_types_Address : + IsGlobalAlias globals ethereum.shanghai.fork_types.globals "Address". -Require state. -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". +Require ethereum.shanghai.state. +Axiom ethereum_shanghai_state_get_account : + IsGlobalAlias globals ethereum.shanghai.state.globals "get_account". -Require vm. -Axiom vm_Environment : - IsGlobalAlias globals vm.globals "Environment". -Axiom vm_Message : - IsGlobalAlias globals vm.globals "Message". +Require ethereum.shanghai.vm.__init__. +Axiom ethereum_shanghai_vm___init___Environment : + IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Environment". +Axiom ethereum_shanghai_vm___init___Message : + IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Message". -Require vm.precompiled_contracts.mapping. -Axiom vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : - IsGlobalAlias globals vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". +Require ethereum.shanghai.vm.precompiled_contracts.mapping. +Axiom ethereum_shanghai_vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : + IsGlobalAlias globals ethereum.shanghai.vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". -Require address. -Axiom address_compute_contract_address : - IsGlobalAlias globals address.globals "compute_contract_address". +Require ethereum.shanghai.utils.address. +Axiom ethereum_shanghai_utils_address_compute_contract_address : + IsGlobalAlias globals ethereum.shanghai.utils.address.globals "compute_contract_address". Definition prepare_message : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -103,14 +103,108 @@ Definition prepare_message : Value.t -> Value.t -> M := Items containing contract creation or message call specific data. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Bytes0" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.call (| + M.get_name (| globals, "compute_contract_address" |), + make_list [ + M.get_name (| globals, "caller" |); + BinOp.sub (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "caller" |) + ], + make_dict [] + |), "nonce" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let msg_data := + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) in + let code := + M.get_name (| globals, "data" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.get_name (| globals, "target" |) in + let msg_data := + M.get_name (| globals, "data" |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "target" |) + ], + make_dict [] + |), "code" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "code_address" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let code_address := + M.get_name (| globals, "target" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "Target must be address or empty bytes" ], make_dict [] - |)) + |)) |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -159,4 +253,5 @@ Definition prepare_message : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/vm/__init__.v b/CoqOfPython/ethereum/shanghai/vm/__init__.v index 49da5ae..95d7c55 100644 --- a/CoqOfPython/ethereum/shanghai/vm/__init__.v +++ b/CoqOfPython/ethereum/shanghai/vm/__init__.v @@ -52,23 +52,23 @@ Require ethereum.crypto.hash. Axiom ethereum_crypto_hash_Hash32 : IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". +Require ethereum.shanghai.blocks. +Axiom ethereum_shanghai_blocks_Log : + IsGlobalAlias globals ethereum.shanghai.blocks.globals "Log". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.shanghai.fork_types. +Axiom ethereum_shanghai_fork_types_Address : + IsGlobalAlias globals ethereum.shanghai.fork_types.globals "Address". -Require state. -Axiom state_State : - IsGlobalAlias globals state.globals "State". -Axiom state_account_exists_and_is_empty : - IsGlobalAlias globals state.globals "account_exists_and_is_empty". +Require ethereum.shanghai.state. +Axiom ethereum_shanghai_state_State : + IsGlobalAlias globals ethereum.shanghai.state.globals "State". +Axiom ethereum_shanghai_state_account_exists_and_is_empty : + IsGlobalAlias globals ethereum.shanghai.state.globals "account_exists_and_is_empty". -Require precompiled_contracts. -Axiom precompiled_contracts_RIPEMD160_ADDRESS : - IsGlobalAlias globals precompiled_contracts.globals "RIPEMD160_ADDRESS". +Require ethereum.shanghai.vm.precompiled_contracts.__init__. +Axiom ethereum_shanghai_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : + IsGlobalAlias globals ethereum.shanghai.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] @@ -147,6 +147,28 @@ Definition incorporate_child_on_success : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -179,9 +201,63 @@ Definition incorporate_child_on_error : Value.t -> Value.t -> M := The child evm to incorporate. " in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "RIPEMD160_ADDRESS" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |), + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign_op (| diff --git a/CoqOfPython/ethereum/shanghai/vm/gas.v b/CoqOfPython/ethereum/shanghai/vm/gas.v index b18e24c..f066a72 100644 --- a/CoqOfPython/ethereum/shanghai/vm/gas.v +++ b/CoqOfPython/ethereum/shanghai/vm/gas.v @@ -43,13 +43,13 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.shanghai.vm.__init__. +Axiom ethereum_shanghai_vm___init___Evm : + IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Evm". -Require exceptions. -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". +Require ethereum.shanghai.vm.exceptions. +Axiom ethereum_shanghai_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.shanghai.vm.exceptions.globals "OutOfGasError". Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -504,6 +504,18 @@ Definition charge_gas : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "amount" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign_op (| BinOp.sub, M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), @@ -619,6 +631,18 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := |) in For make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ] in M.get_name (| globals, "extensions" |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "size" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let before_size := @@ -653,6 +677,18 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let size_to_extend := BinOp.add @@ -701,6 +737,7 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition calculate_message_call_gas : Value.t -> Value.t -> M := @@ -732,22 +769,56 @@ Definition calculate_message_call_gas : Value.t -> Value.t -> M := message_call_gas: `MessageCallGas` " in let call_stipend := - (* if *) -M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "call_stipend" |) + )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "gas_left" |), + BinOp.add (| + M.get_name (| globals, "extra_gas" |), + M.get_name (| globals, "memory_cost" |) + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallGas" |), + make_list [ + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "extra_gas" |) + |); + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "call_stipend" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let gas := @@ -786,6 +857,7 @@ M.call (| ], make_dict [] |) + |) in M.pure Constant.None_)). Definition max_message_call_gas : Value.t -> Value.t -> M := @@ -812,6 +884,7 @@ Definition max_message_call_gas : Value.t -> Value.t -> M := Constant.int 64 |) |) + |) in M.pure Constant.None_)). Definition init_code_cost : Value.t -> Value.t -> M := @@ -846,4 +919,5 @@ Definition init_code_cost : Value.t -> Value.t -> M := |), Constant.int 32 |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/__init__.v b/CoqOfPython/ethereum/shanghai/vm/instructions/__init__.v index e5bebd7..cd917fc 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/__init__.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/__init__.v @@ -26,53 +26,53 @@ Axiom typing_Callable : Axiom typing_Dict : IsGlobalAlias globals typing.globals "Dict". -Require __init__. -Axiom __init___arithmetic : - IsGlobalAlias globals __init__.globals "arithmetic". +Require ethereum.shanghai.vm.instructions.__init__. +Axiom ethereum_shanghai_vm_instructions___init___arithmetic : + IsGlobalAlias globals ethereum.shanghai.vm.instructions.__init__.globals "arithmetic". -Require __init__. -Axiom __init___bitwise : - IsGlobalAlias globals __init__.globals "bitwise". +Require ethereum.shanghai.vm.instructions.__init__. +Axiom ethereum_shanghai_vm_instructions___init___bitwise : + IsGlobalAlias globals ethereum.shanghai.vm.instructions.__init__.globals "bitwise". -Require __init__. -Axiom __init___block : - IsGlobalAlias globals __init__.globals "block". +Require ethereum.shanghai.vm.instructions.__init__. +Axiom ethereum_shanghai_vm_instructions___init___block : + IsGlobalAlias globals ethereum.shanghai.vm.instructions.__init__.globals "block". -Require __init__. -Axiom __init___comparison : - IsGlobalAlias globals __init__.globals "comparison". +Require ethereum.shanghai.vm.instructions.__init__. +Axiom ethereum_shanghai_vm_instructions___init___comparison : + IsGlobalAlias globals ethereum.shanghai.vm.instructions.__init__.globals "comparison". -Require __init__. -Axiom __init___control_flow : - IsGlobalAlias globals __init__.globals "control_flow". +Require ethereum.shanghai.vm.instructions.__init__. +Axiom ethereum_shanghai_vm_instructions___init___control_flow : + IsGlobalAlias globals ethereum.shanghai.vm.instructions.__init__.globals "control_flow". -Require __init__. -Axiom __init___environment : - IsGlobalAlias globals __init__.globals "environment". +Require ethereum.shanghai.vm.instructions.__init__. +Axiom ethereum_shanghai_vm_instructions___init___environment : + IsGlobalAlias globals ethereum.shanghai.vm.instructions.__init__.globals "environment". -Require __init__. -Axiom __init___keccak : - IsGlobalAlias globals __init__.globals "keccak". +Require ethereum.shanghai.vm.instructions.__init__. +Axiom ethereum_shanghai_vm_instructions___init___keccak : + IsGlobalAlias globals ethereum.shanghai.vm.instructions.__init__.globals "keccak". -Require __init__. -Axiom __init___log : - IsGlobalAlias globals __init__.globals "log". +Require ethereum.shanghai.vm.instructions.__init__. +Axiom ethereum_shanghai_vm_instructions___init___log : + IsGlobalAlias globals ethereum.shanghai.vm.instructions.__init__.globals "log". -Require __init__. -Axiom __init___memory : - IsGlobalAlias globals __init__.globals "memory". +Require ethereum.shanghai.vm.instructions.__init__. +Axiom ethereum_shanghai_vm_instructions___init___memory : + IsGlobalAlias globals ethereum.shanghai.vm.instructions.__init__.globals "memory". -Require __init__. -Axiom __init___stack : - IsGlobalAlias globals __init__.globals "stack". +Require ethereum.shanghai.vm.instructions.__init__. +Axiom ethereum_shanghai_vm_instructions___init___stack : + IsGlobalAlias globals ethereum.shanghai.vm.instructions.__init__.globals "stack". -Require __init__. -Axiom __init___storage : - IsGlobalAlias globals __init__.globals "storage". +Require ethereum.shanghai.vm.instructions.__init__. +Axiom ethereum_shanghai_vm_instructions___init___storage : + IsGlobalAlias globals ethereum.shanghai.vm.instructions.__init__.globals "storage". -Require __init__. -Axiom __init___system : - IsGlobalAlias globals __init__.globals "system". +Require ethereum.shanghai.vm.instructions.__init__. +Axiom ethereum_shanghai_vm_instructions___init___system : + IsGlobalAlias globals ethereum.shanghai.vm.instructions.__init__.globals "system". Definition Ops : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/shanghai/vm/instructions/arithmetic.v index 581ba5d..e63147d 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/arithmetic.v @@ -31,29 +31,29 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_get_sign : IsGlobalAlias globals ethereum.utils.numeric.globals "get_sign". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_EXPONENTIATION : - IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION". -Axiom gas_GAS_EXPONENTIATION_PER_BYTE : - IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION_PER_BYTE". -Axiom gas_GAS_LOW : - IsGlobalAlias globals gas.globals "GAS_LOW". -Axiom gas_GAS_MID : - IsGlobalAlias globals gas.globals "GAS_MID". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.shanghai.vm.__init__. +Axiom ethereum_shanghai_vm___init___Evm : + IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Evm". + +Require ethereum.shanghai.vm.gas. +Axiom ethereum_shanghai_vm_gas_GAS_EXPONENTIATION : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_EXPONENTIATION". +Axiom ethereum_shanghai_vm_gas_GAS_EXPONENTIATION_PER_BYTE : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_EXPONENTIATION_PER_BYTE". +Axiom ethereum_shanghai_vm_gas_GAS_LOW : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_LOW". +Axiom ethereum_shanghai_vm_gas_GAS_MID : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_MID". +Axiom ethereum_shanghai_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_shanghai_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "charge_gas". + +Require ethereum.shanghai.vm.stack. +Axiom ethereum_shanghai_vm_stack_pop : + IsGlobalAlias globals ethereum.shanghai.vm.stack.globals "pop". +Axiom ethereum_shanghai_vm_stack_push : + IsGlobalAlias globals ethereum.shanghai.vm.stack.globals "push". Definition add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -273,6 +273,25 @@ Definition div : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "divisor" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let quotient := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let quotient := BinOp.floor_div (| M.get_name (| globals, "dividend" |), @@ -341,7 +360,41 @@ Definition sdiv : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "divisor" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let quotient := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_name (| globals, "dividend" |), + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "divisor" |), + UnOp.sub (| Constant.int 1 |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let quotient := + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let sign := M.call (| M.get_name (| globals, "get_sign" |), @@ -436,6 +489,25 @@ Definition mod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "y" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let remainder := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let remainder := BinOp.mod_ (| M.get_name (| globals, "x" |), @@ -504,6 +576,19 @@ Definition smod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "y" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let remainder := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let remainder := BinOp.mult (| M.call (| @@ -617,6 +702,25 @@ Definition addmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "z" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -712,6 +816,25 @@ Definition mulmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "z" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -881,6 +1004,19 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "byte_num" |), + Constant.int 31 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.get_name (| globals, "value" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let value_bytes := M.call (| M.get_name (| globals, "bytes" |), @@ -894,7 +1030,7 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let value_bytes := - M.get_subscript (| M.get_name (| globals, "value_bytes" |), BinOp.sub (| + M.get_subscript (| M.get_name (| globals, "value_bytes" |), M.slice (| BinOp.sub (| Constant.int 31, M.call (| M.get_name (| globals, "int" |), @@ -903,13 +1039,32 @@ Definition signextend : Value.t -> Value.t -> M := ], make_dict [] |) - |) |) in + |), Constant.None_ |) |) in let sign_bit := BinOp.r_shift (| M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), Constant.int 7 |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "sign_bit" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "value_bytes" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let num_bytes_prepend := BinOp.sub (| Constant.int 32, diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/bitwise.v b/CoqOfPython/ethereum/shanghai/vm/instructions/bitwise.v index 64cf120..614db14 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/bitwise.v @@ -23,21 +23,21 @@ Axiom ethereum_base_types_U256 : Axiom ethereum_base_types_U256_CEIL_VALUE : IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.shanghai.vm.__init__. +Axiom ethereum_shanghai_vm___init___Evm : + IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.shanghai.vm.gas. +Axiom ethereum_shanghai_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_shanghai_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "charge_gas". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.shanghai.vm.stack. +Axiom ethereum_shanghai_vm_stack_pop : + IsGlobalAlias globals ethereum.shanghai.vm.stack.globals "pop". +Axiom ethereum_shanghai_vm_stack_push : + IsGlobalAlias globals ethereum.shanghai.vm.stack.globals "push". Definition bitwise_and : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -287,6 +287,25 @@ Definition get_byte : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "byte_index" |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let extra_bytes_to_right := BinOp.sub (| Constant.int 31, @@ -366,6 +385,31 @@ Definition bitwise_shl : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "shift" |), + Constant.int 256 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.mod_ (| + BinOp.l_shift (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "shift" |) + |), + M.get_name (| globals, "U256_CEIL_VALUE" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -427,6 +471,22 @@ Definition bitwise_shr : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "shift" |), + Constant.int 256 + |), + (* then *) + ltac:(M.monadic ( + let result := + BinOp.r_shift (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "shift" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -492,7 +552,48 @@ Definition bitwise_sar : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "shift" |), + Constant.int 256 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), + make_list [ + BinOp.r_shift (| + M.get_name (| globals, "signed_value" |), + M.get_name (| globals, "shift" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "signed_value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/block.v b/CoqOfPython/ethereum/shanghai/vm/instructions/block.v index 4fa1205..92c2662 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/block.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/block.v @@ -21,23 +21,23 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_BLOCK_HASH : - IsGlobalAlias globals gas.globals "GAS_BLOCK_HASH". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.shanghai.vm.__init__. +Axiom ethereum_shanghai_vm___init___Evm : + IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Evm". + +Require ethereum.shanghai.vm.gas. +Axiom ethereum_shanghai_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_BASE". +Axiom ethereum_shanghai_vm_gas_GAS_BLOCK_HASH : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_BLOCK_HASH". +Axiom ethereum_shanghai_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "charge_gas". + +Require ethereum.shanghai.vm.stack. +Axiom ethereum_shanghai_vm_stack_pop : + IsGlobalAlias globals ethereum.shanghai.vm.stack.globals "pop". +Axiom ethereum_shanghai_vm_stack_push : + IsGlobalAlias globals ethereum.shanghai.vm.stack.globals "push". Definition block_hash : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -75,6 +75,30 @@ Definition block_hash : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt_e (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + M.get_name (| globals, "block_number" |) + |), + ltac:(M.monadic ( + Compare.gt (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + BinOp.add (| + M.get_name (| globals, "block_number" |), + Constant.int 256 + |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let hash := + Constant.bytes "00" in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let hash := M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/comparison.v b/CoqOfPython/ethereum/shanghai/vm/instructions/comparison.v index b8529d8..40c05f4 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/comparison.v @@ -21,21 +21,21 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.shanghai.vm.__init__. +Axiom ethereum_shanghai_vm___init___Evm : + IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.shanghai.vm.gas. +Axiom ethereum_shanghai_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_shanghai_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "charge_gas". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.shanghai.vm.stack. +Axiom ethereum_shanghai_vm_stack_pop : + IsGlobalAlias globals ethereum.shanghai.vm.stack.globals "pop". +Axiom ethereum_shanghai_vm_stack_push : + IsGlobalAlias globals ethereum.shanghai.vm.stack.globals "push". Definition less_than : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/control_flow.v b/CoqOfPython/ethereum/shanghai/vm/instructions/control_flow.v index d4e4eae..360ca46 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/control_flow.v @@ -23,31 +23,31 @@ Axiom ethereum_base_types_U256 : Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require vm.gas. -Axiom vm_gas_GAS_BASE : - IsGlobalAlias globals vm.gas.globals "GAS_BASE". -Axiom vm_gas_GAS_HIGH : - IsGlobalAlias globals vm.gas.globals "GAS_HIGH". -Axiom vm_gas_GAS_JUMPDEST : - IsGlobalAlias globals vm.gas.globals "GAS_JUMPDEST". -Axiom vm_gas_GAS_MID : - IsGlobalAlias globals vm.gas.globals "GAS_MID". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.shanghai.vm.gas. +Axiom ethereum_shanghai_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_BASE". +Axiom ethereum_shanghai_vm_gas_GAS_HIGH : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_HIGH". +Axiom ethereum_shanghai_vm_gas_GAS_JUMPDEST : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_JUMPDEST". +Axiom ethereum_shanghai_vm_gas_GAS_MID : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_MID". +Axiom ethereum_shanghai_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "charge_gas". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.shanghai.vm.__init__. +Axiom ethereum_shanghai_vm___init___Evm : + IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Evm". -Require exceptions. -Axiom exceptions_InvalidJumpDestError : - IsGlobalAlias globals exceptions.globals "InvalidJumpDestError". +Require ethereum.shanghai.vm.exceptions. +Axiom ethereum_shanghai_vm_exceptions_InvalidJumpDestError : + IsGlobalAlias globals ethereum.shanghai.vm.exceptions.globals "InvalidJumpDestError". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.shanghai.vm.stack. +Axiom ethereum_shanghai_vm_stack_pop : + IsGlobalAlias globals ethereum.shanghai.vm.stack.globals "pop". +Axiom ethereum_shanghai_vm_stack_push : + IsGlobalAlias globals ethereum.shanghai.vm.stack.globals "push". Definition stop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -109,6 +109,18 @@ Definition jump : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "jump_dest" |), + M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -168,7 +180,35 @@ Definition jumpi : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "conditional_value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let destination := + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "jump_dest" |), + M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let destination := M.get_name (| globals, "jump_dest" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/environment.v b/CoqOfPython/ethereum/shanghai/vm/instructions/environment.v index 10bc05b..488eeda 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/environment.v @@ -35,57 +35,57 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require fork_types. -Axiom fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". - -Require state. -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". - -Require utils.address. -Axiom utils_address_to_address : - IsGlobalAlias globals utils.address.globals "to_address". - -Require vm.memory. -Axiom vm_memory_buffer_read : - IsGlobalAlias globals vm.memory.globals "buffer_read". -Axiom vm_memory_memory_write : - IsGlobalAlias globals vm.memory.globals "memory_write". - -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require exceptions. -Axiom exceptions_OutOfBoundsRead : - IsGlobalAlias globals exceptions.globals "OutOfBoundsRead". - -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_COLD_ACCOUNT_ACCESS : - IsGlobalAlias globals gas.globals "GAS_COLD_ACCOUNT_ACCESS". -Axiom gas_GAS_COPY : - IsGlobalAlias globals gas.globals "GAS_COPY". -Axiom gas_GAS_FAST_STEP : - IsGlobalAlias globals gas.globals "GAS_FAST_STEP". -Axiom gas_GAS_RETURN_DATA_COPY : - IsGlobalAlias globals gas.globals "GAS_RETURN_DATA_COPY". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_GAS_WARM_ACCESS : - IsGlobalAlias globals gas.globals "GAS_WARM_ACCESS". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.shanghai.fork_types. +Axiom ethereum_shanghai_fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals ethereum.shanghai.fork_types.globals "EMPTY_ACCOUNT". + +Require ethereum.shanghai.state. +Axiom ethereum_shanghai_state_get_account : + IsGlobalAlias globals ethereum.shanghai.state.globals "get_account". + +Require ethereum.shanghai.utils.address. +Axiom ethereum_shanghai_utils_address_to_address : + IsGlobalAlias globals ethereum.shanghai.utils.address.globals "to_address". + +Require ethereum.shanghai.vm.memory. +Axiom ethereum_shanghai_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.shanghai.vm.memory.globals "buffer_read". +Axiom ethereum_shanghai_vm_memory_memory_write : + IsGlobalAlias globals ethereum.shanghai.vm.memory.globals "memory_write". + +Require ethereum.shanghai.vm.__init__. +Axiom ethereum_shanghai_vm___init___Evm : + IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Evm". + +Require ethereum.shanghai.vm.exceptions. +Axiom ethereum_shanghai_vm_exceptions_OutOfBoundsRead : + IsGlobalAlias globals ethereum.shanghai.vm.exceptions.globals "OutOfBoundsRead". + +Require ethereum.shanghai.vm.gas. +Axiom ethereum_shanghai_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_BASE". +Axiom ethereum_shanghai_vm_gas_GAS_COLD_ACCOUNT_ACCESS : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_COLD_ACCOUNT_ACCESS". +Axiom ethereum_shanghai_vm_gas_GAS_COPY : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_COPY". +Axiom ethereum_shanghai_vm_gas_GAS_FAST_STEP : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_FAST_STEP". +Axiom ethereum_shanghai_vm_gas_GAS_RETURN_DATA_COPY : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_RETURN_DATA_COPY". +Axiom ethereum_shanghai_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_shanghai_vm_gas_GAS_WARM_ACCESS : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_WARM_ACCESS". +Axiom ethereum_shanghai_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_shanghai_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "charge_gas". + +Require ethereum.shanghai.vm.stack. +Axiom ethereum_shanghai_vm_stack_pop : + IsGlobalAlias globals ethereum.shanghai.vm.stack.globals "pop". +Axiom ethereum_shanghai_vm_stack_push : + IsGlobalAlias globals ethereum.shanghai.vm.stack.globals "push". Definition address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -156,6 +156,25 @@ Definition balance : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -789,6 +808,25 @@ Definition extcodesize : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -926,6 +964,31 @@ Definition extcodecopy : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + BinOp.add (| + BinOp.add (| + M.get_name (| globals, "GAS_WARM_ACCESS" |), + M.get_name (| globals, "copy_gas_cost" |) + |), + M.get_field (| M.get_name (| globals, "extend_memory" |), "cost" |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1162,7 +1225,10 @@ Definition returndatacopy : Value.t -> Value.t -> M := |) |) in let value := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |) |) in + M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.slice (| M.get_name (| globals, "return_data_start_position" |), BinOp.add (| + M.get_name (| globals, "return_data_start_position" |), + M.get_name (| globals, "size" |) + |) |) |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -1204,6 +1270,25 @@ Definition extcodehash : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1231,6 +1316,25 @@ Definition extcodehash : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "account" |), + M.get_name (| globals, "EMPTY_ACCOUNT" |) + |), + (* then *) + ltac:(M.monadic ( + let codehash := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let codehash := M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/keccak.v b/CoqOfPython/ethereum/shanghai/vm/instructions/keccak.v index 2c4b10e..5c8d48d 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/keccak.v @@ -31,29 +31,29 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_KECCAK256 : - IsGlobalAlias globals gas.globals "GAS_KECCAK256". -Axiom gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.shanghai.vm.__init__. +Axiom ethereum_shanghai_vm___init___Evm : + IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Evm". + +Require ethereum.shanghai.vm.gas. +Axiom ethereum_shanghai_vm_gas_GAS_KECCAK256 : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_KECCAK256". +Axiom ethereum_shanghai_vm_gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_KECCAK256_WORD". +Axiom ethereum_shanghai_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_shanghai_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "charge_gas". + +Require ethereum.shanghai.vm.memory. +Axiom ethereum_shanghai_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.shanghai.vm.memory.globals "memory_read_bytes". + +Require ethereum.shanghai.vm.stack. +Axiom ethereum_shanghai_vm_stack_pop : + IsGlobalAlias globals ethereum.shanghai.vm.stack.globals "pop". +Axiom ethereum_shanghai_vm_stack_push : + IsGlobalAlias globals ethereum.shanghai.vm.stack.globals "push". Definition keccak : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/log.v b/CoqOfPython/ethereum/shanghai/vm/instructions/log.v index e084e59..06c53da 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/log.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/log.v @@ -29,37 +29,37 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". - -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require exceptions. -Axiom exceptions_WriteInStaticContext : - IsGlobalAlias globals exceptions.globals "WriteInStaticContext". - -Require gas. -Axiom gas_GAS_LOG : - IsGlobalAlias globals gas.globals "GAS_LOG". -Axiom gas_GAS_LOG_DATA : - IsGlobalAlias globals gas.globals "GAS_LOG_DATA". -Axiom gas_GAS_LOG_TOPIC : - IsGlobalAlias globals gas.globals "GAS_LOG_TOPIC". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". +Require ethereum.shanghai.blocks. +Axiom ethereum_shanghai_blocks_Log : + IsGlobalAlias globals ethereum.shanghai.blocks.globals "Log". + +Require ethereum.shanghai.vm.__init__. +Axiom ethereum_shanghai_vm___init___Evm : + IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Evm". + +Require ethereum.shanghai.vm.exceptions. +Axiom ethereum_shanghai_vm_exceptions_WriteInStaticContext : + IsGlobalAlias globals ethereum.shanghai.vm.exceptions.globals "WriteInStaticContext". + +Require ethereum.shanghai.vm.gas. +Axiom ethereum_shanghai_vm_gas_GAS_LOG : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_LOG". +Axiom ethereum_shanghai_vm_gas_GAS_LOG_DATA : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_LOG_DATA". +Axiom ethereum_shanghai_vm_gas_GAS_LOG_TOPIC : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_LOG_TOPIC". +Axiom ethereum_shanghai_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_shanghai_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "charge_gas". + +Require ethereum.shanghai.vm.memory. +Axiom ethereum_shanghai_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.shanghai.vm.memory.globals "memory_read_bytes". + +Require ethereum.shanghai.vm.stack. +Axiom ethereum_shanghai_vm_stack_pop : + IsGlobalAlias globals ethereum.shanghai.vm.stack.globals "pop". Definition log_n : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/memory.v b/CoqOfPython/ethereum/shanghai/vm/instructions/memory.v index 86ba742..d516fdf 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/memory.v @@ -23,31 +23,31 @@ Axiom ethereum_base_types_U256 : Axiom ethereum_base_types_Bytes : IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.shanghai.vm.__init__. +Axiom ethereum_shanghai_vm___init___Evm : + IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.shanghai.vm.gas. +Axiom ethereum_shanghai_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_BASE". +Axiom ethereum_shanghai_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_shanghai_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_shanghai_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "charge_gas". -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". -Axiom memory_memory_write : - IsGlobalAlias globals memory.globals "memory_write". +Require ethereum.shanghai.vm.memory. +Axiom ethereum_shanghai_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.shanghai.vm.memory.globals "memory_read_bytes". +Axiom ethereum_shanghai_vm_memory_memory_write : + IsGlobalAlias globals ethereum.shanghai.vm.memory.globals "memory_write". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.shanghai.vm.stack. +Axiom ethereum_shanghai_vm_stack_pop : + IsGlobalAlias globals ethereum.shanghai.vm.stack.globals "pop". +Axiom ethereum_shanghai_vm_stack_push : + IsGlobalAlias globals ethereum.shanghai.vm.stack.globals "push". Definition mstore : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/stack.v b/CoqOfPython/ethereum/shanghai/vm/instructions/stack.v index aa085db..3b72bc8 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/stack.v @@ -29,27 +29,27 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". -Axiom __init___stack : - IsGlobalAlias globals __init__.globals "stack". - -Require exceptions. -Axiom exceptions_StackUnderflowError : - IsGlobalAlias globals exceptions.globals "StackUnderflowError". - -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require memory. -Axiom memory_buffer_read : - IsGlobalAlias globals memory.globals "buffer_read". +Require ethereum.shanghai.vm.__init__. +Axiom ethereum_shanghai_vm___init___Evm : + IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Evm". +Axiom ethereum_shanghai_vm___init___stack : + IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "stack". + +Require ethereum.shanghai.vm.exceptions. +Axiom ethereum_shanghai_vm_exceptions_StackUnderflowError : + IsGlobalAlias globals ethereum.shanghai.vm.exceptions.globals "StackUnderflowError". + +Require ethereum.shanghai.vm.gas. +Axiom ethereum_shanghai_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_BASE". +Axiom ethereum_shanghai_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_shanghai_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "charge_gas". + +Require ethereum.shanghai.vm.memory. +Axiom ethereum_shanghai_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.shanghai.vm.memory.globals "buffer_read". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -104,6 +104,25 @@ Definition push_n : Value.t -> Value.t -> M := " in let _ := M.pass (| |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "num_bytes" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_BASE" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/storage.v b/CoqOfPython/ethereum/shanghai/vm/instructions/storage.v index b3c4045..3ed65d5 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/storage.v @@ -25,45 +25,45 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require state. -Axiom state_get_storage : - IsGlobalAlias globals state.globals "get_storage". -Axiom state_get_storage_original : - IsGlobalAlias globals state.globals "get_storage_original". -Axiom state_set_storage : - IsGlobalAlias globals state.globals "set_storage". - -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require exceptions. -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". -Axiom exceptions_WriteInStaticContext : - IsGlobalAlias globals exceptions.globals "WriteInStaticContext". - -Require gas. -Axiom gas_GAS_CALL_STIPEND : - IsGlobalAlias globals gas.globals "GAS_CALL_STIPEND". -Axiom gas_GAS_COLD_SLOAD : - IsGlobalAlias globals gas.globals "GAS_COLD_SLOAD". -Axiom gas_GAS_STORAGE_CLEAR_REFUND : - IsGlobalAlias globals gas.globals "GAS_STORAGE_CLEAR_REFUND". -Axiom gas_GAS_STORAGE_SET : - IsGlobalAlias globals gas.globals "GAS_STORAGE_SET". -Axiom gas_GAS_STORAGE_UPDATE : - IsGlobalAlias globals gas.globals "GAS_STORAGE_UPDATE". -Axiom gas_GAS_WARM_ACCESS : - IsGlobalAlias globals gas.globals "GAS_WARM_ACCESS". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.shanghai.state. +Axiom ethereum_shanghai_state_get_storage : + IsGlobalAlias globals ethereum.shanghai.state.globals "get_storage". +Axiom ethereum_shanghai_state_get_storage_original : + IsGlobalAlias globals ethereum.shanghai.state.globals "get_storage_original". +Axiom ethereum_shanghai_state_set_storage : + IsGlobalAlias globals ethereum.shanghai.state.globals "set_storage". + +Require ethereum.shanghai.vm.__init__. +Axiom ethereum_shanghai_vm___init___Evm : + IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Evm". + +Require ethereum.shanghai.vm.exceptions. +Axiom ethereum_shanghai_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.shanghai.vm.exceptions.globals "OutOfGasError". +Axiom ethereum_shanghai_vm_exceptions_WriteInStaticContext : + IsGlobalAlias globals ethereum.shanghai.vm.exceptions.globals "WriteInStaticContext". + +Require ethereum.shanghai.vm.gas. +Axiom ethereum_shanghai_vm_gas_GAS_CALL_STIPEND : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_CALL_STIPEND". +Axiom ethereum_shanghai_vm_gas_GAS_COLD_SLOAD : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_COLD_SLOAD". +Axiom ethereum_shanghai_vm_gas_GAS_STORAGE_CLEAR_REFUND : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_STORAGE_CLEAR_REFUND". +Axiom ethereum_shanghai_vm_gas_GAS_STORAGE_SET : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_STORAGE_SET". +Axiom ethereum_shanghai_vm_gas_GAS_STORAGE_UPDATE : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_STORAGE_UPDATE". +Axiom ethereum_shanghai_vm_gas_GAS_WARM_ACCESS : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_WARM_ACCESS". +Axiom ethereum_shanghai_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "charge_gas". + +Require ethereum.shanghai.vm.stack. +Axiom ethereum_shanghai_vm_stack_pop : + IsGlobalAlias globals ethereum.shanghai.vm.stack.globals "pop". +Axiom ethereum_shanghai_vm_stack_push : + IsGlobalAlias globals ethereum.shanghai.vm.stack.globals "push". Definition sload : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -91,6 +91,25 @@ Definition sload : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], + M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "charge_gas" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "GAS_WARM_ACCESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "add" |), make_list [ @@ -205,15 +224,225 @@ Definition sstore : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], + M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |), "add" |), + make_list [ + make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ] + ], + make_dict [] + |) in + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_COLD_SLOAD" |) + M.get_name (| globals, "GAS_COLD_SLOAD" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_name (| globals, "original_value" |), + M.get_name (| globals, "current_value" |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "current_value" |), + M.get_name (| globals, "new_value" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "original_value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_STORAGE_SET" |) + M.get_name (| globals, "GAS_STORAGE_SET" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let gas_cost := BinOp.add + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_UPDATE" |), + M.get_name (| globals, "GAS_COLD_SLOAD" |) + |) + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_UPDATE" |), + M.get_name (| globals, "GAS_COLD_SLOAD" |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let gas_cost := BinOp.add M.get_name (| globals, "GAS_WARM_ACCESS" |) M.get_name (| globals, "GAS_WARM_ACCESS" |) in M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| + M.get_name (| globals, "current_value" |), + M.get_name (| globals, "new_value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "original_value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "current_value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "new_value" |), + Constant.int 0 + |) + )) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "original_value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "current_value" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.sub, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "original_value" |), + M.get_name (| globals, "new_value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "original_value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_SET" |), + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.sub (| + BinOp.sub (| + M.get_name (| globals, "GAS_STORAGE_UPDATE" |), + M.get_name (| globals, "GAS_COLD_SLOAD" |) + |), + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/system.v b/CoqOfPython/ethereum/shanghai/vm/instructions/system.v index 6b9c771..e38459d 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/system.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/system.v @@ -33,91 +33,91 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.shanghai.fork_types. +Axiom ethereum_shanghai_fork_types_Address : + IsGlobalAlias globals ethereum.shanghai.fork_types.globals "Address". -Require state. -Axiom state_account_exists_and_is_empty : - IsGlobalAlias globals state.globals "account_exists_and_is_empty". -Axiom state_account_has_code_or_nonce : - IsGlobalAlias globals state.globals "account_has_code_or_nonce". -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". -Axiom state_increment_nonce : - IsGlobalAlias globals state.globals "increment_nonce". -Axiom state_is_account_alive : - IsGlobalAlias globals state.globals "is_account_alive". -Axiom state_set_account_balance : - IsGlobalAlias globals state.globals "set_account_balance". +Require ethereum.shanghai.state. +Axiom ethereum_shanghai_state_account_exists_and_is_empty : + IsGlobalAlias globals ethereum.shanghai.state.globals "account_exists_and_is_empty". +Axiom ethereum_shanghai_state_account_has_code_or_nonce : + IsGlobalAlias globals ethereum.shanghai.state.globals "account_has_code_or_nonce". +Axiom ethereum_shanghai_state_get_account : + IsGlobalAlias globals ethereum.shanghai.state.globals "get_account". +Axiom ethereum_shanghai_state_increment_nonce : + IsGlobalAlias globals ethereum.shanghai.state.globals "increment_nonce". +Axiom ethereum_shanghai_state_is_account_alive : + IsGlobalAlias globals ethereum.shanghai.state.globals "is_account_alive". +Axiom ethereum_shanghai_state_set_account_balance : + IsGlobalAlias globals ethereum.shanghai.state.globals "set_account_balance". -Require utils.address. -Axiom utils_address_compute_contract_address : - IsGlobalAlias globals utils.address.globals "compute_contract_address". -Axiom utils_address_compute_create2_contract_address : - IsGlobalAlias globals utils.address.globals "compute_create2_contract_address". -Axiom utils_address_to_address : - IsGlobalAlias globals utils.address.globals "to_address". +Require ethereum.shanghai.utils.address. +Axiom ethereum_shanghai_utils_address_compute_contract_address : + IsGlobalAlias globals ethereum.shanghai.utils.address.globals "compute_contract_address". +Axiom ethereum_shanghai_utils_address_compute_create2_contract_address : + IsGlobalAlias globals ethereum.shanghai.utils.address.globals "compute_create2_contract_address". +Axiom ethereum_shanghai_utils_address_to_address : + IsGlobalAlias globals ethereum.shanghai.utils.address.globals "to_address". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". -Axiom __init___Message : - IsGlobalAlias globals __init__.globals "Message". -Axiom __init___incorporate_child_on_error : - IsGlobalAlias globals __init__.globals "incorporate_child_on_error". -Axiom __init___incorporate_child_on_success : - IsGlobalAlias globals __init__.globals "incorporate_child_on_success". +Require ethereum.shanghai.vm.__init__. +Axiom ethereum_shanghai_vm___init___Evm : + IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Evm". +Axiom ethereum_shanghai_vm___init___Message : + IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Message". +Axiom ethereum_shanghai_vm___init___incorporate_child_on_error : + IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "incorporate_child_on_error". +Axiom ethereum_shanghai_vm___init___incorporate_child_on_success : + IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "incorporate_child_on_success". -Require exceptions. -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". -Axiom exceptions_Revert : - IsGlobalAlias globals exceptions.globals "Revert". -Axiom exceptions_WriteInStaticContext : - IsGlobalAlias globals exceptions.globals "WriteInStaticContext". +Require ethereum.shanghai.vm.exceptions. +Axiom ethereum_shanghai_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.shanghai.vm.exceptions.globals "OutOfGasError". +Axiom ethereum_shanghai_vm_exceptions_Revert : + IsGlobalAlias globals ethereum.shanghai.vm.exceptions.globals "Revert". +Axiom ethereum_shanghai_vm_exceptions_WriteInStaticContext : + IsGlobalAlias globals ethereum.shanghai.vm.exceptions.globals "WriteInStaticContext". -Require gas. -Axiom gas_GAS_CALL_VALUE : - IsGlobalAlias globals gas.globals "GAS_CALL_VALUE". -Axiom gas_GAS_COLD_ACCOUNT_ACCESS : - IsGlobalAlias globals gas.globals "GAS_COLD_ACCOUNT_ACCESS". -Axiom gas_GAS_CREATE : - IsGlobalAlias globals gas.globals "GAS_CREATE". -Axiom gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". -Axiom gas_GAS_NEW_ACCOUNT : - IsGlobalAlias globals gas.globals "GAS_NEW_ACCOUNT". -Axiom gas_GAS_SELF_DESTRUCT : - IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT". -Axiom gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : - IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". -Axiom gas_GAS_WARM_ACCESS : - IsGlobalAlias globals gas.globals "GAS_WARM_ACCESS". -Axiom gas_GAS_ZERO : - IsGlobalAlias globals gas.globals "GAS_ZERO". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_calculate_message_call_gas : - IsGlobalAlias globals gas.globals "calculate_message_call_gas". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". -Axiom gas_init_code_cost : - IsGlobalAlias globals gas.globals "init_code_cost". -Axiom gas_max_message_call_gas : - IsGlobalAlias globals gas.globals "max_message_call_gas". +Require ethereum.shanghai.vm.gas. +Axiom ethereum_shanghai_vm_gas_GAS_CALL_VALUE : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_CALL_VALUE". +Axiom ethereum_shanghai_vm_gas_GAS_COLD_ACCOUNT_ACCESS : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_COLD_ACCOUNT_ACCESS". +Axiom ethereum_shanghai_vm_gas_GAS_CREATE : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_CREATE". +Axiom ethereum_shanghai_vm_gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_KECCAK256_WORD". +Axiom ethereum_shanghai_vm_gas_GAS_NEW_ACCOUNT : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_NEW_ACCOUNT". +Axiom ethereum_shanghai_vm_gas_GAS_SELF_DESTRUCT : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_SELF_DESTRUCT". +Axiom ethereum_shanghai_vm_gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". +Axiom ethereum_shanghai_vm_gas_GAS_WARM_ACCESS : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_WARM_ACCESS". +Axiom ethereum_shanghai_vm_gas_GAS_ZERO : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_ZERO". +Axiom ethereum_shanghai_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_shanghai_vm_gas_calculate_message_call_gas : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "calculate_message_call_gas". +Axiom ethereum_shanghai_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "charge_gas". +Axiom ethereum_shanghai_vm_gas_init_code_cost : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "init_code_cost". +Axiom ethereum_shanghai_vm_gas_max_message_call_gas : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "max_message_call_gas". -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". -Axiom memory_memory_write : - IsGlobalAlias globals memory.globals "memory_write". +Require ethereum.shanghai.vm.memory. +Axiom ethereum_shanghai_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.shanghai.vm.memory.globals "memory_read_bytes". +Axiom ethereum_shanghai_vm_memory_memory_write : + IsGlobalAlias globals ethereum.shanghai.vm.memory.globals "memory_write". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.shanghai.vm.stack. +Axiom ethereum_shanghai_vm_stack_pop : + IsGlobalAlias globals ethereum.shanghai.vm.stack.globals "pop". +Axiom ethereum_shanghai_vm_stack_push : + IsGlobalAlias globals ethereum.shanghai.vm.stack.globals "push". Definition generic_create : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -206,9 +206,113 @@ Definition generic_create : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt (| + M.get_field (| M.get_name (| globals, "sender" |), "balance" |), + M.get_name (| globals, "endowment" |) + |), + ltac:(M.monadic ( + BoolOp.or (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "sender" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.sub (| + BinOp.pow (| + Constant.int 2, + Constant.int 64 + |), + Constant.int 1 + |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.gt (| + BinOp.add (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "depth" |), + Constant.int 1 + |), + M.get_name (| globals, "STACK_DEPTH_LIMIT" |) + |) + )) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "create_message_gas" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "contract_address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -235,6 +339,40 @@ Definition generic_create : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "child_evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_error" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "incorporate_child_on_success" |), make_list [ @@ -627,6 +765,42 @@ Definition generic_call : Value.t -> Value.t -> M := Constant.bytes "" |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + BinOp.add (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "depth" |), + Constant.int 1 + |), + M.get_name (| globals, "STACK_DEPTH_LIMIT" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "gas" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let call_data := @@ -664,6 +838,40 @@ Definition generic_call : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "child_evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_error" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "incorporate_child_on_success" |), make_list [ @@ -718,7 +926,7 @@ Definition generic_call : Value.t -> Value.t -> M := make_list [ M.get_field (| M.get_name (| globals, "evm" |), "memory" |); M.get_name (| globals, "memory_output_start_position" |); - M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), Constant.None_:M.get_name (| globals, "actual_output_size" |) |) + M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), M.slice (| Constant.None_, M.get_name (| globals, "actual_output_size" |) |) |) ], make_dict [] |) in @@ -816,6 +1024,19 @@ Definition call : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "to" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let access_gas_cost := + M.get_name (| globals, "GAS_WARM_ACCESS" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -828,49 +1049,57 @@ Definition call : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in let create_gas_cost := - (* if *) -M.if_then_else (| - BoolOp.or (| - M.call (| - M.get_name (| globals, "is_account_alive" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); - M.get_name (| globals, "to" |) - ], - make_dict [] - |), - ltac:(M.monadic ( - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |) - )) - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + BoolOp.or (| + M.call (| + M.get_name (| globals, "is_account_alive" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "to" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "GAS_NEW_ACCOUNT" |) + )) |) in let transfer_gas_cost := - (* if *) -M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "GAS_CALL_VALUE" |) + )) |) in let message_call_gas := M.call (| M.get_name (| globals, "calculate_message_call_gas" |), @@ -946,6 +1175,40 @@ M.call (| make_dict [] |), "balance" |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "sender_balance" |), + M.get_name (| globals, "value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "generic_call" |), make_list [ @@ -1067,6 +1330,19 @@ Definition callcode : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "code_address" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let access_gas_cost := + M.get_name (| globals, "GAS_WARM_ACCESS" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1079,21 +1355,25 @@ Definition callcode : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in let transfer_gas_cost := - (* if *) -M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "GAS_CALL_VALUE" |) + )) |) in let message_call_gas := M.call (| M.get_name (| globals, "calculate_message_call_gas" |), @@ -1144,6 +1424,40 @@ M.call (| make_dict [] |), "balance" |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "sender_balance" |), + M.get_name (| globals, "value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), + Constant.bytes "" + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "generic_call" |), make_list [ @@ -1199,9 +1513,63 @@ Definition selfdestruct : Value.t -> Value.t -> M := let gas_cost := M.get_name (| globals, "GAS_SELF_DESTRUCT" |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "beneficiary" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), + make_list [ + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |) in + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + UnOp.not (| M.call (| + M.get_name (| globals, "is_account_alive" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) + M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -1275,6 +1643,28 @@ Definition selfdestruct : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -1368,6 +1758,19 @@ Definition delegatecall : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "code_address" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let access_gas_cost := + M.get_name (| globals, "GAS_WARM_ACCESS" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1531,6 +1934,19 @@ Definition staticcall : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "to" |), + M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) + |), + (* then *) + ltac:(M.monadic ( + let access_gas_cost := + M.get_name (| globals, "GAS_WARM_ACCESS" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |), "add" |), make_list [ @@ -1690,6 +2106,6 @@ Definition revert : Value.t -> Value.t -> M := make_dict [] |) |) in - let _ := M.raise (| Some(M.get_name (| globals, "Revert" |)) + let _ := M.raise (| Some(M.get_name (| globals, "Revert" |)) |) in let _ := M.pass (| |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/vm/interpreter.v b/CoqOfPython/ethereum/shanghai/vm/interpreter.v index eee00d3..a5b78df 100644 --- a/CoqOfPython/ethereum/shanghai/vm/interpreter.v +++ b/CoqOfPython/ethereum/shanghai/vm/interpreter.v @@ -63,83 +63,83 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". - -Require state. -Axiom state_account_exists_and_is_empty : - IsGlobalAlias globals state.globals "account_exists_and_is_empty". -Axiom state_account_has_code_or_nonce : - IsGlobalAlias globals state.globals "account_has_code_or_nonce". -Axiom state_begin_transaction : - IsGlobalAlias globals state.globals "begin_transaction". -Axiom state_commit_transaction : - IsGlobalAlias globals state.globals "commit_transaction". -Axiom state_destroy_storage : - IsGlobalAlias globals state.globals "destroy_storage". -Axiom state_increment_nonce : - IsGlobalAlias globals state.globals "increment_nonce". -Axiom state_mark_account_created : - IsGlobalAlias globals state.globals "mark_account_created". -Axiom state_move_ether : - IsGlobalAlias globals state.globals "move_ether". -Axiom state_rollback_transaction : - IsGlobalAlias globals state.globals "rollback_transaction". -Axiom state_set_code : - IsGlobalAlias globals state.globals "set_code". -Axiom state_touch_account : - IsGlobalAlias globals state.globals "touch_account". - -Require vm. -Axiom vm_Message : - IsGlobalAlias globals vm.globals "Message". - -Require vm.gas. -Axiom vm_gas_GAS_CODE_DEPOSIT : - IsGlobalAlias globals vm.gas.globals "GAS_CODE_DEPOSIT". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". - -Require vm.precompiled_contracts.mapping. -Axiom vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : - IsGlobalAlias globals vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". - -Require __init__. -Axiom __init___Environment : - IsGlobalAlias globals __init__.globals "Environment". -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require exceptions. -Axiom exceptions_AddressCollision : - IsGlobalAlias globals exceptions.globals "AddressCollision". -Axiom exceptions_ExceptionalHalt : - IsGlobalAlias globals exceptions.globals "ExceptionalHalt". -Axiom exceptions_InvalidContractPrefix : - IsGlobalAlias globals exceptions.globals "InvalidContractPrefix". -Axiom exceptions_InvalidOpcode : - IsGlobalAlias globals exceptions.globals "InvalidOpcode". -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". -Axiom exceptions_Revert : - IsGlobalAlias globals exceptions.globals "Revert". -Axiom exceptions_StackDepthLimitError : - IsGlobalAlias globals exceptions.globals "StackDepthLimitError". - -Require instructions. -Axiom instructions_Ops : - IsGlobalAlias globals instructions.globals "Ops". -Axiom instructions_op_implementation : - IsGlobalAlias globals instructions.globals "op_implementation". - -Require runtime. -Axiom runtime_get_valid_jump_destinations : - IsGlobalAlias globals runtime.globals "get_valid_jump_destinations". +Require ethereum.shanghai.blocks. +Axiom ethereum_shanghai_blocks_Log : + IsGlobalAlias globals ethereum.shanghai.blocks.globals "Log". + +Require ethereum.shanghai.fork_types. +Axiom ethereum_shanghai_fork_types_Address : + IsGlobalAlias globals ethereum.shanghai.fork_types.globals "Address". + +Require ethereum.shanghai.state. +Axiom ethereum_shanghai_state_account_exists_and_is_empty : + IsGlobalAlias globals ethereum.shanghai.state.globals "account_exists_and_is_empty". +Axiom ethereum_shanghai_state_account_has_code_or_nonce : + IsGlobalAlias globals ethereum.shanghai.state.globals "account_has_code_or_nonce". +Axiom ethereum_shanghai_state_begin_transaction : + IsGlobalAlias globals ethereum.shanghai.state.globals "begin_transaction". +Axiom ethereum_shanghai_state_commit_transaction : + IsGlobalAlias globals ethereum.shanghai.state.globals "commit_transaction". +Axiom ethereum_shanghai_state_destroy_storage : + IsGlobalAlias globals ethereum.shanghai.state.globals "destroy_storage". +Axiom ethereum_shanghai_state_increment_nonce : + IsGlobalAlias globals ethereum.shanghai.state.globals "increment_nonce". +Axiom ethereum_shanghai_state_mark_account_created : + IsGlobalAlias globals ethereum.shanghai.state.globals "mark_account_created". +Axiom ethereum_shanghai_state_move_ether : + IsGlobalAlias globals ethereum.shanghai.state.globals "move_ether". +Axiom ethereum_shanghai_state_rollback_transaction : + IsGlobalAlias globals ethereum.shanghai.state.globals "rollback_transaction". +Axiom ethereum_shanghai_state_set_code : + IsGlobalAlias globals ethereum.shanghai.state.globals "set_code". +Axiom ethereum_shanghai_state_touch_account : + IsGlobalAlias globals ethereum.shanghai.state.globals "touch_account". + +Require ethereum.shanghai.vm.__init__. +Axiom ethereum_shanghai_vm___init___Message : + IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Message". + +Require ethereum.shanghai.vm.gas. +Axiom ethereum_shanghai_vm_gas_GAS_CODE_DEPOSIT : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_CODE_DEPOSIT". +Axiom ethereum_shanghai_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "charge_gas". + +Require ethereum.shanghai.vm.precompiled_contracts.mapping. +Axiom ethereum_shanghai_vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : + IsGlobalAlias globals ethereum.shanghai.vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". + +Require ethereum.shanghai.vm.__init__. +Axiom ethereum_shanghai_vm___init___Environment : + IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Environment". +Axiom ethereum_shanghai_vm___init___Evm : + IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Evm". + +Require ethereum.shanghai.vm.exceptions. +Axiom ethereum_shanghai_vm_exceptions_AddressCollision : + IsGlobalAlias globals ethereum.shanghai.vm.exceptions.globals "AddressCollision". +Axiom ethereum_shanghai_vm_exceptions_ExceptionalHalt : + IsGlobalAlias globals ethereum.shanghai.vm.exceptions.globals "ExceptionalHalt". +Axiom ethereum_shanghai_vm_exceptions_InvalidContractPrefix : + IsGlobalAlias globals ethereum.shanghai.vm.exceptions.globals "InvalidContractPrefix". +Axiom ethereum_shanghai_vm_exceptions_InvalidOpcode : + IsGlobalAlias globals ethereum.shanghai.vm.exceptions.globals "InvalidOpcode". +Axiom ethereum_shanghai_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.shanghai.vm.exceptions.globals "OutOfGasError". +Axiom ethereum_shanghai_vm_exceptions_Revert : + IsGlobalAlias globals ethereum.shanghai.vm.exceptions.globals "Revert". +Axiom ethereum_shanghai_vm_exceptions_StackDepthLimitError : + IsGlobalAlias globals ethereum.shanghai.vm.exceptions.globals "StackDepthLimitError". + +Require ethereum.shanghai.vm.instructions.__init__. +Axiom ethereum_shanghai_vm_instructions___init___Ops : + IsGlobalAlias globals ethereum.shanghai.vm.instructions.__init__.globals "Ops". +Axiom ethereum_shanghai_vm_instructions___init___op_implementation : + IsGlobalAlias globals ethereum.shanghai.vm.instructions.__init__.globals "op_implementation". + +Require ethereum.shanghai.vm.runtime. +Axiom ethereum_shanghai_vm_runtime_get_valid_jump_destinations : + IsGlobalAlias globals ethereum.shanghai.vm.runtime.globals "get_valid_jump_destinations". Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -186,6 +186,94 @@ Definition process_message_call : Value.t -> Value.t -> M := Output of the message call " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "message" |), "target" |), + M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) + |), + (* then *) + ltac:(M.monadic ( + let is_collision := + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_name (| globals, "is_collision" |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallOutput" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "tuple" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "AddressCollision" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let evm := + M.call (| + M.get_name (| globals, "process_create_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let evm := M.call (| M.get_name (| globals, "process_message" |), @@ -196,11 +284,74 @@ Definition process_message_call : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_field (| M.get_name (| globals, "message" |), "target" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_field (| M.get_name (| globals, "message" |), "target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( +(* At stmt: unsupported node type: AnnAssign *) + let accounts_to_delete := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let touched_accounts := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let refund_counter := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let logs := M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in let accounts_to_delete := @@ -244,6 +395,7 @@ Definition process_message_call : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). Definition process_create_message : Value.t -> Value.t -> M := @@ -305,6 +457,28 @@ Definition process_create_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), + (* then *) + ltac:(M.monadic ( + let contract_code := + M.get_field (| M.get_name (| globals, "evm" |), "output" |) in + let contract_code_gas := + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "contract_code" |) + ], + make_dict [] + |), + M.get_name (| globals, "GAS_CODE_DEPOSIT" |) + |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "rollback_transaction" |), make_list [ @@ -316,6 +490,7 @@ Definition process_create_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) + |) in M.pure Constant.None_)). Definition process_message : Value.t -> Value.t -> M := @@ -337,6 +512,24 @@ Definition process_message : Value.t -> Value.t -> M := Items containing execution specific objects " in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_field (| M.get_name (| globals, "message" |), "depth" |), + M.get_name (| globals, "STACK_DEPTH_LIMIT" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "StackDepthLimitError" |), + make_list [ + Constant.str "Stack depth limit reached" + ], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -355,6 +548,32 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + M.get_field (| M.get_name (| globals, "message" |), "should_transfer_value" |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "message" |), "value" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "move_ether" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "caller" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |); + M.get_field (| M.get_name (| globals, "message" |), "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let evm := @@ -367,6 +586,21 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "rollback_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "commit_transaction" |), make_list [ @@ -378,6 +612,7 @@ Definition process_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) + |) in M.pure Constant.None_)). Definition execute_code : Value.t -> Value.t -> M := @@ -417,4 +652,5 @@ Definition execute_code : Value.t -> Value.t -> M := (* At stmt: unsupported node type: Try *) let _ := M.return_ (| M.get_name (| globals, "evm" |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/vm/memory.v b/CoqOfPython/ethereum/shanghai/vm/memory.v index 4b107fd..08d2290 100644 --- a/CoqOfPython/ethereum/shanghai/vm/memory.v +++ b/CoqOfPython/ethereum/shanghai/vm/memory.v @@ -21,13 +21,13 @@ Require ethereum.utils.byte. Axiom ethereum_utils_byte_right_pad_zero_bytes : IsGlobalAlias globals ethereum.utils.byte.globals "right_pad_zero_bytes". -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". Definition memory_write : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,7 +45,22 @@ Definition memory_write : Value.t -> Value.t -> M := Data to write to memory. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |), + M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) |) |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_)). @@ -71,7 +86,23 @@ Definition memory_read_bytes : Value.t -> Value.t -> M := Data read from memory. " in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |) + M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |) |) + |) in M.pure Constant.None_)). Definition buffer_read : Value.t -> Value.t -> M := @@ -98,9 +129,25 @@ Definition buffer_read : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "right_pad_zero_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |) |); + M.get_subscript (| M.get_name (| globals, "buffer" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |) |); M.get_name (| globals, "size" |) ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/__init__.v index ca49311..4ef50e8 100644 --- a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/__init__.v +++ b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/__init__.v @@ -18,9 +18,9 @@ Addresses of precompiled contracts and mappings to their implementations. ". -Require utils.hexadecimal. -Axiom utils_hexadecimal_hex_to_address : - IsGlobalAlias globals utils.hexadecimal.globals "hex_to_address". +Require ethereum.shanghai.utils.hexadecimal. +Axiom ethereum_shanghai_utils_hexadecimal_hex_to_address : + IsGlobalAlias globals ethereum.shanghai.utils.hexadecimal.globals "hex_to_address". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS"; Constant.str "MODEXP_ADDRESS"; Constant.str "ALT_BN128_ADD_ADDRESS"; Constant.str "ALT_BN128_MUL_ADDRESS"; Constant.str "ALT_BN128_PAIRING_CHECK_ADDRESS"; Constant.str "BLAKE2F_ADDRESS" ] diff --git a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/alt_bn128.v index abe4238..53543aa 100644 --- a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/alt_bn128.v +++ b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/alt_bn128.v @@ -45,21 +45,21 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.shanghai.vm.__init__. +Axiom ethereum_shanghai_vm___init___Evm : + IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.shanghai.vm.gas. +Axiom ethereum_shanghai_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "charge_gas". -Require vm.memory. -Axiom vm_memory_buffer_read : - IsGlobalAlias globals vm.memory.globals "buffer_read". +Require ethereum.shanghai.vm.memory. +Axiom ethereum_shanghai_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.shanghai.vm.memory.globals "buffer_read". -Require exceptions. -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". +Require ethereum.shanghai.vm.exceptions. +Axiom ethereum_shanghai_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.shanghai.vm.exceptions.globals "OutOfGasError". Definition alt_bn128_add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -210,6 +210,18 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) in For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ] do let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -353,6 +365,18 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) in For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ] do let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -425,6 +449,27 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| + BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |), + Constant.int 192 + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let result := @@ -464,7 +509,7 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "data" |), BinOp.add (| + M.get_subscript (| M.get_name (| globals, "data" |), M.slice (| BinOp.add (| BinOp.mult (| M.get_name (| globals, "i" |), Constant.int 192 @@ -473,11 +518,35 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := Constant.int 32, M.get_name (| globals, "j" |) |) - |) |) + |), BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "j" |), + Constant.int 1 + |) + |) + |) |) |) ], make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -538,10 +607,80 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "p" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "q" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let result := + BinOp.mult (| + M.get_name (| globals, "result" |), + M.call (| + M.get_name (| globals, "pairing" |), + make_list [ + M.get_name (| globals, "q" |); + M.get_name (| globals, "p" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "result" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| diff --git a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/blake2f.v b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/blake2f.v index 1647d48..f9d1f0b 100644 --- a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/blake2f.v +++ b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/blake2f.v @@ -25,19 +25,19 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.shanghai.vm.__init__. +Axiom ethereum_shanghai_vm___init___Evm : + IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_BLAKE2_PER_ROUND : - IsGlobalAlias globals vm.gas.globals "GAS_BLAKE2_PER_ROUND". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.shanghai.vm.gas. +Axiom ethereum_shanghai_vm_gas_GAS_BLAKE2_PER_ROUND : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_BLAKE2_PER_ROUND". +Axiom ethereum_shanghai_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "charge_gas". -Require exceptions. -Axiom exceptions_InvalidParameter : - IsGlobalAlias globals exceptions.globals "InvalidParameter". +Require ethereum.shanghai.vm.exceptions. +Axiom ethereum_shanghai_vm_exceptions_InvalidParameter : + IsGlobalAlias globals ethereum.shanghai.vm.exceptions.globals "InvalidParameter". Definition blake2f : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/ecrecover.v index 0cbcf16..42d4132 100644 --- a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/ecrecover.v @@ -37,19 +37,19 @@ Require ethereum.utils.byte. Axiom ethereum_utils_byte_left_pad_zero_bytes : IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.shanghai.vm.__init__. +Axiom ethereum_shanghai_vm___init___Evm : + IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_ECRECOVER : - IsGlobalAlias globals vm.gas.globals "GAS_ECRECOVER". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.shanghai.vm.gas. +Axiom ethereum_shanghai_vm_gas_GAS_ECRECOVER : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_ECRECOVER". +Axiom ethereum_shanghai_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "charge_gas". -Require vm.memory. -Axiom vm_memory_buffer_read : - IsGlobalAlias globals vm.memory.globals "buffer_read". +Require ethereum.shanghai.vm.memory. +Axiom ethereum_shanghai_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.shanghai.vm.memory.globals "buffer_read". Definition ecrecover : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -188,12 +188,78 @@ Definition ecrecover : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "v" |), + Constant.int 27 + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "v" |), + Constant.int 28 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + Constant.int 0, + M.get_name (| globals, "r" |) + |), + ltac:(M.monadic ( + Compare.gt_e (| + M.get_name (| globals, "r" |), + M.get_name (| globals, "SECP256K1N" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + Constant.int 0, + M.get_name (| globals, "s" |) + |), + ltac:(M.monadic ( + Compare.gt_e (| + M.get_name (| globals, "s" |), + M.get_name (| globals, "SECP256K1N" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: Try *) @@ -204,7 +270,7 @@ Definition ecrecover : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12 |) in + |), M.slice (| Constant.int 12, Constant.int 32 |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/identity.v index fa96704..67d5eb2 100644 --- a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/identity.v +++ b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/identity.v @@ -25,17 +25,17 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.shanghai.vm.__init__. +Axiom ethereum_shanghai_vm___init___Evm : + IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_IDENTITY : - IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY". -Axiom vm_gas_GAS_IDENTITY_WORD : - IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY_WORD". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.shanghai.vm.gas. +Axiom ethereum_shanghai_vm_gas_GAS_IDENTITY : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_IDENTITY". +Axiom ethereum_shanghai_vm_gas_GAS_IDENTITY_WORD : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_IDENTITY_WORD". +Axiom ethereum_shanghai_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "charge_gas". Definition identity : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/mapping.v index 8a2e2eb..535a24a 100644 --- a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/mapping.v +++ b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/mapping.v @@ -23,60 +23,60 @@ Axiom typing_Callable : Axiom typing_Dict : IsGlobalAlias globals typing.globals "Dict". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". - -Require __init__. -Axiom __init___ALT_BN128_ADD_ADDRESS : - IsGlobalAlias globals __init__.globals "ALT_BN128_ADD_ADDRESS". -Axiom __init___ALT_BN128_MUL_ADDRESS : - IsGlobalAlias globals __init__.globals "ALT_BN128_MUL_ADDRESS". -Axiom __init___ALT_BN128_PAIRING_CHECK_ADDRESS : - IsGlobalAlias globals __init__.globals "ALT_BN128_PAIRING_CHECK_ADDRESS". -Axiom __init___BLAKE2F_ADDRESS : - IsGlobalAlias globals __init__.globals "BLAKE2F_ADDRESS". -Axiom __init___ECRECOVER_ADDRESS : - IsGlobalAlias globals __init__.globals "ECRECOVER_ADDRESS". -Axiom __init___IDENTITY_ADDRESS : - IsGlobalAlias globals __init__.globals "IDENTITY_ADDRESS". -Axiom __init___MODEXP_ADDRESS : - IsGlobalAlias globals __init__.globals "MODEXP_ADDRESS". -Axiom __init___RIPEMD160_ADDRESS : - IsGlobalAlias globals __init__.globals "RIPEMD160_ADDRESS". -Axiom __init___SHA256_ADDRESS : - IsGlobalAlias globals __init__.globals "SHA256_ADDRESS". - -Require alt_bn128. -Axiom alt_bn128_alt_bn128_add : - IsGlobalAlias globals alt_bn128.globals "alt_bn128_add". -Axiom alt_bn128_alt_bn128_mul : - IsGlobalAlias globals alt_bn128.globals "alt_bn128_mul". -Axiom alt_bn128_alt_bn128_pairing_check : - IsGlobalAlias globals alt_bn128.globals "alt_bn128_pairing_check". - -Require blake2f. -Axiom blake2f_blake2f : - IsGlobalAlias globals blake2f.globals "blake2f". - -Require ecrecover. -Axiom ecrecover_ecrecover : - IsGlobalAlias globals ecrecover.globals "ecrecover". - -Require identity. -Axiom identity_identity : - IsGlobalAlias globals identity.globals "identity". - -Require modexp. -Axiom modexp_modexp : - IsGlobalAlias globals modexp.globals "modexp". - -Require ripemd160. -Axiom ripemd160_ripemd160 : - IsGlobalAlias globals ripemd160.globals "ripemd160". - -Require sha256. -Axiom sha256_sha256 : - IsGlobalAlias globals sha256.globals "sha256". +Require ethereum.shanghai.fork_types. +Axiom ethereum_shanghai_fork_types_Address : + IsGlobalAlias globals ethereum.shanghai.fork_types.globals "Address". + +Require ethereum.shanghai.vm.precompiled_contracts.__init__. +Axiom ethereum_shanghai_vm_precompiled_contracts___init___ALT_BN128_ADD_ADDRESS : + IsGlobalAlias globals ethereum.shanghai.vm.precompiled_contracts.__init__.globals "ALT_BN128_ADD_ADDRESS". +Axiom ethereum_shanghai_vm_precompiled_contracts___init___ALT_BN128_MUL_ADDRESS : + IsGlobalAlias globals ethereum.shanghai.vm.precompiled_contracts.__init__.globals "ALT_BN128_MUL_ADDRESS". +Axiom ethereum_shanghai_vm_precompiled_contracts___init___ALT_BN128_PAIRING_CHECK_ADDRESS : + IsGlobalAlias globals ethereum.shanghai.vm.precompiled_contracts.__init__.globals "ALT_BN128_PAIRING_CHECK_ADDRESS". +Axiom ethereum_shanghai_vm_precompiled_contracts___init___BLAKE2F_ADDRESS : + IsGlobalAlias globals ethereum.shanghai.vm.precompiled_contracts.__init__.globals "BLAKE2F_ADDRESS". +Axiom ethereum_shanghai_vm_precompiled_contracts___init___ECRECOVER_ADDRESS : + IsGlobalAlias globals ethereum.shanghai.vm.precompiled_contracts.__init__.globals "ECRECOVER_ADDRESS". +Axiom ethereum_shanghai_vm_precompiled_contracts___init___IDENTITY_ADDRESS : + IsGlobalAlias globals ethereum.shanghai.vm.precompiled_contracts.__init__.globals "IDENTITY_ADDRESS". +Axiom ethereum_shanghai_vm_precompiled_contracts___init___MODEXP_ADDRESS : + IsGlobalAlias globals ethereum.shanghai.vm.precompiled_contracts.__init__.globals "MODEXP_ADDRESS". +Axiom ethereum_shanghai_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : + IsGlobalAlias globals ethereum.shanghai.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". +Axiom ethereum_shanghai_vm_precompiled_contracts___init___SHA256_ADDRESS : + IsGlobalAlias globals ethereum.shanghai.vm.precompiled_contracts.__init__.globals "SHA256_ADDRESS". + +Require ethereum.shanghai.vm.precompiled_contracts.alt_bn128. +Axiom ethereum_shanghai_vm_precompiled_contracts_alt_bn128_alt_bn128_add : + IsGlobalAlias globals ethereum.shanghai.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_add". +Axiom ethereum_shanghai_vm_precompiled_contracts_alt_bn128_alt_bn128_mul : + IsGlobalAlias globals ethereum.shanghai.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_mul". +Axiom ethereum_shanghai_vm_precompiled_contracts_alt_bn128_alt_bn128_pairing_check : + IsGlobalAlias globals ethereum.shanghai.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_pairing_check". + +Require ethereum.shanghai.vm.precompiled_contracts.blake2f. +Axiom ethereum_shanghai_vm_precompiled_contracts_blake2f_blake2f : + IsGlobalAlias globals ethereum.shanghai.vm.precompiled_contracts.blake2f.globals "blake2f". + +Require ethereum.shanghai.vm.precompiled_contracts.ecrecover. +Axiom ethereum_shanghai_vm_precompiled_contracts_ecrecover_ecrecover : + IsGlobalAlias globals ethereum.shanghai.vm.precompiled_contracts.ecrecover.globals "ecrecover". + +Require ethereum.shanghai.vm.precompiled_contracts.identity. +Axiom ethereum_shanghai_vm_precompiled_contracts_identity_identity : + IsGlobalAlias globals ethereum.shanghai.vm.precompiled_contracts.identity.globals "identity". + +Require ethereum.shanghai.vm.precompiled_contracts.modexp. +Axiom ethereum_shanghai_vm_precompiled_contracts_modexp_modexp : + IsGlobalAlias globals ethereum.shanghai.vm.precompiled_contracts.modexp.globals "modexp". + +Require ethereum.shanghai.vm.precompiled_contracts.ripemd160. +Axiom ethereum_shanghai_vm_precompiled_contracts_ripemd160_ripemd160 : + IsGlobalAlias globals ethereum.shanghai.vm.precompiled_contracts.ripemd160.globals "ripemd160". + +Require ethereum.shanghai.vm.precompiled_contracts.sha256. +Axiom ethereum_shanghai_vm_precompiled_contracts_sha256_sha256 : + IsGlobalAlias globals ethereum.shanghai.vm.precompiled_contracts.sha256.globals "sha256". (* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/modexp.v index 3505244..48cbbe9 100644 --- a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/modexp.v +++ b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/modexp.v @@ -25,17 +25,17 @@ Axiom ethereum_base_types_Bytes : Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.shanghai.vm.__init__. +Axiom ethereum_shanghai_vm___init___Evm : + IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.shanghai.vm.gas. +Axiom ethereum_shanghai_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "charge_gas". -Require memory. -Axiom memory_buffer_read : - IsGlobalAlias globals memory.globals "buffer_read". +Require ethereum.shanghai.vm.memory. +Axiom ethereum_shanghai_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.shanghai.vm.memory.globals "buffer_read". Definition GQUADDIVISOR : Value.t := M.run ltac:(M.monadic ( Constant.int 3 @@ -192,6 +192,36 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_name (| globals, "base_length" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "modulus_length" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [], + make_dict [] + |) + |) in + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let base := @@ -254,6 +284,30 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "modulus" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "evm" |), "output" |), + BinOp.mult (| + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + Constant.bytes "00" + ], + make_dict [] + |), + M.get_name (| globals, "modulus_length" |) + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| @@ -338,6 +392,7 @@ Definition complexity : Value.t -> Value.t -> M := M.get_name (| globals, "words" |), Constant.int 2 |) + |) in M.pure Constant.None_)). Definition iterations : Value.t -> Value.t -> M := @@ -364,7 +419,76 @@ Definition iterations : Value.t -> Value.t -> M := Number of iterations. " in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.lt_e (| + M.get_name (| globals, "exponent_length" |), + Constant.int 32 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "exponent_head" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let count := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "exponent_length" |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let bit_length := + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "exponent_head" |), "bit_length" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "bit_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let bit_length := BinOp.sub + Constant.int 1 + Constant.int 1 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let count := + M.get_name (| globals, "bit_length" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let length_part := BinOp.mult (| Constant.int 8, @@ -392,6 +516,20 @@ Definition iterations : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "bits_part" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let bits_part := BinOp.sub + Constant.int 1 + Constant.int 1 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let count := @@ -418,6 +556,7 @@ Definition iterations : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition gas_cost : Value.t -> Value.t -> M := @@ -489,4 +628,5 @@ Definition gas_cost : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/ripemd160.v index 96f8dcd..49c91d6 100644 --- a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/ripemd160.v +++ b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/ripemd160.v @@ -31,17 +31,17 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.shanghai.vm.__init__. +Axiom ethereum_shanghai_vm___init___Evm : + IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_RIPEMD160 : - IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160". -Axiom vm_gas_GAS_RIPEMD160_WORD : - IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160_WORD". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.shanghai.vm.gas. +Axiom ethereum_shanghai_vm_gas_GAS_RIPEMD160 : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_RIPEMD160". +Axiom ethereum_shanghai_vm_gas_GAS_RIPEMD160_WORD : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_RIPEMD160_WORD". +Axiom ethereum_shanghai_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "charge_gas". Definition ripemd160 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/sha256.v index 9f6d2bf..80beec5 100644 --- a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/sha256.v +++ b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/sha256.v @@ -27,17 +27,17 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.shanghai.vm.__init__. +Axiom ethereum_shanghai_vm___init___Evm : + IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_SHA256 : - IsGlobalAlias globals vm.gas.globals "GAS_SHA256". -Axiom vm_gas_GAS_SHA256_WORD : - IsGlobalAlias globals vm.gas.globals "GAS_SHA256_WORD". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.shanghai.vm.gas. +Axiom ethereum_shanghai_vm_gas_GAS_SHA256 : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_SHA256". +Axiom ethereum_shanghai_vm_gas_GAS_SHA256_WORD : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_SHA256_WORD". +Axiom ethereum_shanghai_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "charge_gas". Definition sha256 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/shanghai/vm/runtime.v b/CoqOfPython/ethereum/shanghai/vm/runtime.v index 2cd7652..0b06bfb 100644 --- a/CoqOfPython/ethereum/shanghai/vm/runtime.v +++ b/CoqOfPython/ethereum/shanghai/vm/runtime.v @@ -25,9 +25,9 @@ Require ethereum.base_types. Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require instructions. -Axiom instructions_Ops : - IsGlobalAlias globals instructions.globals "Ops". +Require ethereum.shanghai.vm.instructions.__init__. +Axiom ethereum_shanghai_vm_instructions___init___Ops : + IsGlobalAlias globals ethereum.shanghai.vm.instructions.__init__.globals "Ops". Definition get_valid_jump_destinations : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -79,7 +79,55 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := |) do (* At stmt: unsupported node type: Try *) let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "current_opcode" |), + M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), + make_list [ + M.get_name (| globals, "pc" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.lt_e (| + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |), + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH32" |), "value" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let push_data_size := + BinOp.add (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) + |), + Constant.int 1 + |) in + let pc := BinOp.add + M.get_name (| globals, "push_data_size" |) + M.get_name (| globals, "push_data_size" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -90,4 +138,5 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := EndWhile. let _ := M.return_ (| M.get_name (| globals, "valid_jump_destinations" |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/vm/stack.v b/CoqOfPython/ethereum/shanghai/vm/stack.v index ea778df..aa9f4c0 100644 --- a/CoqOfPython/ethereum/shanghai/vm/stack.v +++ b/CoqOfPython/ethereum/shanghai/vm/stack.v @@ -25,11 +25,11 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require exceptions. -Axiom exceptions_StackOverflowError : - IsGlobalAlias globals exceptions.globals "StackOverflowError". -Axiom exceptions_StackUnderflowError : - IsGlobalAlias globals exceptions.globals "StackUnderflowError". +Require ethereum.shanghai.vm.exceptions. +Axiom ethereum_shanghai_vm_exceptions_StackOverflowError : + IsGlobalAlias globals ethereum.shanghai.vm.exceptions.globals "StackOverflowError". +Axiom ethereum_shanghai_vm_exceptions_StackUnderflowError : + IsGlobalAlias globals ethereum.shanghai.vm.exceptions.globals "StackUnderflowError". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -49,6 +49,24 @@ Definition pop : Value.t -> Value.t -> M := " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "StackUnderflowError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -57,6 +75,7 @@ Definition pop : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). Definition push : Value.t -> Value.t -> M := @@ -75,6 +94,24 @@ Definition push : Value.t -> Value.t -> M := " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), + Constant.int 1024 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "StackOverflowError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -85,4 +122,5 @@ Definition push : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/blocks.v b/CoqOfPython/ethereum/spurious_dragon/blocks.v index 6501788..f0b2003 100644 --- a/CoqOfPython/ethereum/spurious_dragon/blocks.v +++ b/CoqOfPython/ethereum/spurious_dragon/blocks.v @@ -22,35 +22,35 @@ Require typing. Axiom typing_Tuple : IsGlobalAlias globals typing.globals "Tuple". -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes8 : - IsGlobalAlias globals base_types.globals "Bytes8". -Axiom base_types_Bytes32 : - IsGlobalAlias globals base_types.globals "Bytes32". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require crypto.hash. -Axiom crypto_hash_Hash32 : - IsGlobalAlias globals crypto.hash.globals "Hash32". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". - -Require transactions. -Axiom transactions_Transaction : - IsGlobalAlias globals transactions.globals "Transaction". +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes8 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes8". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". + +Require ethereum.spurious_dragon.fork_types. +Axiom ethereum_spurious_dragon_fork_types_Address : + IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "Address". +Axiom ethereum_spurious_dragon_fork_types_Bloom : + IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "Bloom". +Axiom ethereum_spurious_dragon_fork_types_Root : + IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "Root". + +Require ethereum.spurious_dragon.transactions. +Axiom ethereum_spurious_dragon_transactions_Transaction : + IsGlobalAlias globals ethereum.spurious_dragon.transactions.globals "Transaction". Definition Header : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/spurious_dragon/bloom.v b/CoqOfPython/ethereum/spurious_dragon/bloom.v index 04650ff..ba1a08f 100644 --- a/CoqOfPython/ethereum/spurious_dragon/bloom.v +++ b/CoqOfPython/ethereum/spurious_dragon/bloom.v @@ -33,13 +33,13 @@ Require ethereum.crypto.hash. Axiom ethereum_crypto_hash_keccak256 : IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". +Require ethereum.spurious_dragon.blocks. +Axiom ethereum_spurious_dragon_blocks_Log : + IsGlobalAlias globals ethereum.spurious_dragon.blocks.globals "Log". -Require fork_types. -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". +Require ethereum.spurious_dragon.fork_types. +Axiom ethereum_spurious_dragon_fork_types_Bloom : + IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "Bloom". Definition add_to_bloom : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -72,7 +72,10 @@ Definition add_to_bloom : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |) |) + M.get_subscript (| M.get_name (| globals, "hash" |), M.slice (| M.get_name (| globals, "idx" |), BinOp.add (| + M.get_name (| globals, "idx" |), + Constant.int 2 + |) |) |) ], make_dict [] |), @@ -157,4 +160,5 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/fork.v b/CoqOfPython/ethereum/spurious_dragon/fork.v index cadf255..be54a14 100644 --- a/CoqOfPython/ethereum/spurious_dragon/fork.v +++ b/CoqOfPython/ethereum/spurious_dragon/fork.v @@ -63,95 +63,95 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U64 : - IsGlobalAlias globals base_types.globals "U64". -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_U256_CEIL_VALUE : - IsGlobalAlias globals base_types.globals "U256_CEIL_VALUE". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes32 : - IsGlobalAlias globals base_types.globals "Bytes32". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". - -Require __init__. -Axiom __init___vm : - IsGlobalAlias globals __init__.globals "vm". - -Require blocks. -Axiom blocks_Block : - IsGlobalAlias globals blocks.globals "Block". -Axiom blocks_Header : - IsGlobalAlias globals blocks.globals "Header". -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". -Axiom blocks_Receipt : - IsGlobalAlias globals blocks.globals "Receipt". - -Require bloom. -Axiom bloom_logs_bloom : - IsGlobalAlias globals bloom.globals "logs_bloom". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". - -Require state. -Axiom state_State : - IsGlobalAlias globals state.globals "State". -Axiom state_account_exists_and_is_empty : - IsGlobalAlias globals state.globals "account_exists_and_is_empty". -Axiom state_create_ether : - IsGlobalAlias globals state.globals "create_ether". -Axiom state_destroy_account : - IsGlobalAlias globals state.globals "destroy_account". -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". -Axiom state_increment_nonce : - IsGlobalAlias globals state.globals "increment_nonce". -Axiom state_set_account_balance : - IsGlobalAlias globals state.globals "set_account_balance". -Axiom state_state_root : - IsGlobalAlias globals state.globals "state_root". - -Require transactions. -Axiom transactions_TX_BASE_COST : - IsGlobalAlias globals transactions.globals "TX_BASE_COST". -Axiom transactions_TX_CREATE_COST : - IsGlobalAlias globals transactions.globals "TX_CREATE_COST". -Axiom transactions_TX_DATA_COST_PER_NON_ZERO : - IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_NON_ZERO". -Axiom transactions_TX_DATA_COST_PER_ZERO : - IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_ZERO". -Axiom transactions_Transaction : - IsGlobalAlias globals transactions.globals "Transaction". - -Require trie. -Axiom trie_Trie : - IsGlobalAlias globals trie.globals "Trie". -Axiom trie_root : - IsGlobalAlias globals trie.globals "root". -Axiom trie_trie_set : - IsGlobalAlias globals trie.globals "trie_set". - -Require utils.message. -Axiom utils_message_prepare_message : - IsGlobalAlias globals utils.message.globals "prepare_message". - -Require vm.interpreter. -Axiom vm_interpreter_process_message_call : - IsGlobalAlias globals vm.interpreter.globals "process_message_call". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U64 : + IsGlobalAlias globals ethereum.base_types.globals "U64". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_U256_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.spurious_dragon.__init__. +Axiom ethereum_spurious_dragon___init___vm : + IsGlobalAlias globals ethereum.spurious_dragon.__init__.globals "vm". + +Require ethereum.spurious_dragon.blocks. +Axiom ethereum_spurious_dragon_blocks_Block : + IsGlobalAlias globals ethereum.spurious_dragon.blocks.globals "Block". +Axiom ethereum_spurious_dragon_blocks_Header : + IsGlobalAlias globals ethereum.spurious_dragon.blocks.globals "Header". +Axiom ethereum_spurious_dragon_blocks_Log : + IsGlobalAlias globals ethereum.spurious_dragon.blocks.globals "Log". +Axiom ethereum_spurious_dragon_blocks_Receipt : + IsGlobalAlias globals ethereum.spurious_dragon.blocks.globals "Receipt". + +Require ethereum.spurious_dragon.bloom. +Axiom ethereum_spurious_dragon_bloom_logs_bloom : + IsGlobalAlias globals ethereum.spurious_dragon.bloom.globals "logs_bloom". + +Require ethereum.spurious_dragon.fork_types. +Axiom ethereum_spurious_dragon_fork_types_Address : + IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "Address". +Axiom ethereum_spurious_dragon_fork_types_Bloom : + IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "Bloom". +Axiom ethereum_spurious_dragon_fork_types_Root : + IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "Root". + +Require ethereum.spurious_dragon.state. +Axiom ethereum_spurious_dragon_state_State : + IsGlobalAlias globals ethereum.spurious_dragon.state.globals "State". +Axiom ethereum_spurious_dragon_state_account_exists_and_is_empty : + IsGlobalAlias globals ethereum.spurious_dragon.state.globals "account_exists_and_is_empty". +Axiom ethereum_spurious_dragon_state_create_ether : + IsGlobalAlias globals ethereum.spurious_dragon.state.globals "create_ether". +Axiom ethereum_spurious_dragon_state_destroy_account : + IsGlobalAlias globals ethereum.spurious_dragon.state.globals "destroy_account". +Axiom ethereum_spurious_dragon_state_get_account : + IsGlobalAlias globals ethereum.spurious_dragon.state.globals "get_account". +Axiom ethereum_spurious_dragon_state_increment_nonce : + IsGlobalAlias globals ethereum.spurious_dragon.state.globals "increment_nonce". +Axiom ethereum_spurious_dragon_state_set_account_balance : + IsGlobalAlias globals ethereum.spurious_dragon.state.globals "set_account_balance". +Axiom ethereum_spurious_dragon_state_state_root : + IsGlobalAlias globals ethereum.spurious_dragon.state.globals "state_root". + +Require ethereum.spurious_dragon.transactions. +Axiom ethereum_spurious_dragon_transactions_TX_BASE_COST : + IsGlobalAlias globals ethereum.spurious_dragon.transactions.globals "TX_BASE_COST". +Axiom ethereum_spurious_dragon_transactions_TX_CREATE_COST : + IsGlobalAlias globals ethereum.spurious_dragon.transactions.globals "TX_CREATE_COST". +Axiom ethereum_spurious_dragon_transactions_TX_DATA_COST_PER_NON_ZERO : + IsGlobalAlias globals ethereum.spurious_dragon.transactions.globals "TX_DATA_COST_PER_NON_ZERO". +Axiom ethereum_spurious_dragon_transactions_TX_DATA_COST_PER_ZERO : + IsGlobalAlias globals ethereum.spurious_dragon.transactions.globals "TX_DATA_COST_PER_ZERO". +Axiom ethereum_spurious_dragon_transactions_Transaction : + IsGlobalAlias globals ethereum.spurious_dragon.transactions.globals "Transaction". + +Require ethereum.spurious_dragon.trie. +Axiom ethereum_spurious_dragon_trie_Trie : + IsGlobalAlias globals ethereum.spurious_dragon.trie.globals "Trie". +Axiom ethereum_spurious_dragon_trie_root : + IsGlobalAlias globals ethereum.spurious_dragon.trie.globals "root". +Axiom ethereum_spurious_dragon_trie_trie_set : + IsGlobalAlias globals ethereum.spurious_dragon.trie.globals "trie_set". + +Require ethereum.spurious_dragon.utils.message. +Axiom ethereum_spurious_dragon_utils_message_prepare_message : + IsGlobalAlias globals ethereum.spurious_dragon.utils.message.globals "prepare_message". + +Require ethereum.spurious_dragon.vm.interpreter. +Axiom ethereum_spurious_dragon_vm_interpreter_process_message_call : + IsGlobalAlias globals ethereum.spurious_dragon.vm.interpreter.globals "process_message_call". Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -224,6 +224,7 @@ Definition apply_fork : Value.t -> Value.t -> M := " in let _ := M.return_ (| M.get_name (| globals, "old" |) + |) in M.pure Constant.None_)). Definition get_last_256_block_hashes : Value.t -> Value.t -> M := @@ -249,8 +250,28 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := Hashes of the recent 256 blocks in order of increasing block number. " in let recent_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |) |) in + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "recent_blocks" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + make_list [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let recent_block_hashes := @@ -289,6 +310,7 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "recent_block_hashes" |) + |) in M.pure Constant.None_)). Definition state_transition : Value.t -> Value.t -> M := @@ -420,6 +442,27 @@ Definition state_transition : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |) + ], + make_dict [] + |), + Constant.int 255 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -606,6 +649,7 @@ Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition validate_proof_of_work : Value.t -> Value.t -> M := @@ -740,6 +784,7 @@ Definition check_transaction : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "sender_address" |) + |) in M.pure Constant.None_)). Definition make_receipt : Value.t -> Value.t -> M := @@ -773,6 +818,7 @@ Definition make_receipt : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "receipt" |) + |) in M.pure Constant.None_)). Definition ApplyBodyOutput : Value.t := @@ -989,6 +1035,7 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition validate_ommers : Value.t -> Value.t -> M := @@ -1041,6 +1088,26 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do @@ -1098,7 +1165,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let ommers_hashes := - (* At expr: unsupported node type: ListComp *) in + Constant.str "(* At expr: unsupported node type: ListComp *)" in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1129,19 +1196,19 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let recent_canonical_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| BinOp.add (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| BinOp.add (| M.get_name (| globals, "MAX_OMMER_DEPTH" |), Constant.int 1 - |) |) |) in + |) |), Constant.None_ |) |) in let recent_canonical_block_hashes := - (* At expr: unsupported node type: SetComp *) in + Constant.str "(* At expr: unsupported node type: SetComp *)" in (* At stmt: unsupported node type: AnnAssign *) For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_canonical_blocks" |) do let recent_ommers_hashes := M.call (| M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), make_list [ - (* At expr: unsupported node type: SetComp *) + Constant.str "(* At expr: unsupported node type: SetComp *)" ], make_dict [] |) in @@ -1555,7 +1622,50 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "transaction_fee" |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| + M.get_name (| globals, "coinbase_balance_after_mining_fee" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account_balance" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |); + M.get_name (| globals, "coinbase_balance_after_mining_fee" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "env" |), "coinbase" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -1572,11 +1682,35 @@ Definition process_transaction : Value.t -> Value.t -> M := EndFor. For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "touched_accounts" |) do let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "destroy_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := M.return_ (| make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |) ] + |) in M.pure Constant.None_)). Definition validate_transaction : Value.t -> Value.t -> M := @@ -1631,6 +1765,7 @@ Definition validate_transaction : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := @@ -1662,6 +1797,20 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := Constant.int 0 in For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "byte" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let data_cost := BinOp.add M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in @@ -1669,6 +1818,25 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := )) |) in EndFor. let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "tx" |), "to" |), + M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) + |), + (* then *) + ltac:(M.monadic ( + let create_cost := + M.get_name (| globals, "TX_CREATE_COST" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let create_cost := Constant.int 0 in M.pure Constant.None_ @@ -1687,6 +1855,7 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition recover_sender : Value.t -> Value.t -> M := @@ -1759,6 +1928,45 @@ Definition recover_sender : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.eq (| + M.get_name (| globals, "v" |), + Constant.int 27 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "v" |), + Constant.int 28 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let public_key := + M.call (| + M.get_name (| globals, "secp256k1_recover" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "s" |); + BinOp.sub (| + M.get_name (| globals, "v" |), + Constant.int 27 + |); + M.call (| + M.get_name (| globals, "signing_hash_pre155" |), + make_list [ + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1829,10 +2037,11 @@ Definition recover_sender : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12 |) + |), M.slice (| Constant.int 12, Constant.int 32 |) |) ], make_dict [] |) + |) in M.pure Constant.None_)). Definition signing_hash_pre155 : Value.t -> Value.t -> M := @@ -1865,6 +2074,7 @@ Definition signing_hash_pre155 : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition signing_hash_155 : Value.t -> Value.t -> M := @@ -1911,6 +2121,7 @@ Definition signing_hash_155 : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition compute_header_hash : Value.t -> Value.t -> M := @@ -1961,6 +2172,7 @@ Definition compute_header_hash : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition check_gas_limit : Value.t -> Value.t -> M := @@ -1999,16 +2211,65 @@ Definition check_gas_limit : Value.t -> Value.t -> M := M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "gas_limit" |), + BinOp.add (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "gas_limit" |), + BinOp.sub (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "gas_limit" |), + M.get_name (| globals, "GAS_LIMIT_MINIMUM" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| Constant.bool true + |) in M.pure Constant.None_)). Definition calculate_block_difficulty : Value.t -> Value.t -> M := @@ -2112,6 +2373,26 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := Constant.int 2 |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "num_bomb_periods" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let difficulty := BinOp.add + BinOp.pow (| + Constant.int 2, + M.get_name (| globals, "num_bomb_periods" |) + |) + BinOp.pow (| + Constant.int 2, + M.get_name (| globals, "num_bomb_periods" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -2129,4 +2410,5 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/fork_types.v b/CoqOfPython/ethereum/spurious_dragon/fork_types.v index 5c7dac3..cc8e4a1 100644 --- a/CoqOfPython/ethereum/spurious_dragon/fork_types.v +++ b/CoqOfPython/ethereum/spurious_dragon/fork_types.v @@ -21,29 +21,29 @@ Require dataclasses. Axiom dataclasses_dataclass : IsGlobalAlias globals dataclasses.globals "dataclass". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes20 : - IsGlobalAlias globals base_types.globals "Bytes20". -Axiom base_types_Bytes256 : - IsGlobalAlias globals base_types.globals "Bytes256". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require crypto.hash. -Axiom crypto_hash_Hash32 : - IsGlobalAlias globals crypto.hash.globals "Hash32". -Axiom crypto_hash_keccak256 : - IsGlobalAlias globals crypto.hash.globals "keccak256". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes20 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes20". +Axiom ethereum_base_types_Bytes256 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) @@ -98,4 +98,5 @@ Definition encode_account : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/state.v b/CoqOfPython/ethereum/spurious_dragon/state.v index c5b604e..3a25070 100644 --- a/CoqOfPython/ethereum/spurious_dragon/state.v +++ b/CoqOfPython/ethereum/spurious_dragon/state.v @@ -54,29 +54,29 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require fork_types. -Axiom fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". -Axiom fork_types_Account : - IsGlobalAlias globals fork_types.globals "Account". -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". - -Require trie. -Axiom trie_EMPTY_TRIE_ROOT : - IsGlobalAlias globals trie.globals "EMPTY_TRIE_ROOT". -Axiom trie_Trie : - IsGlobalAlias globals trie.globals "Trie". -Axiom trie_copy_trie : - IsGlobalAlias globals trie.globals "copy_trie". -Axiom trie_root : - IsGlobalAlias globals trie.globals "root". -Axiom trie_trie_get : - IsGlobalAlias globals trie.globals "trie_get". -Axiom trie_trie_set : - IsGlobalAlias globals trie.globals "trie_set". +Require ethereum.spurious_dragon.fork_types. +Axiom ethereum_spurious_dragon_fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "EMPTY_ACCOUNT". +Axiom ethereum_spurious_dragon_fork_types_Account : + IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "Account". +Axiom ethereum_spurious_dragon_fork_types_Address : + IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "Address". +Axiom ethereum_spurious_dragon_fork_types_Root : + IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "Root". + +Require ethereum.spurious_dragon.trie. +Axiom ethereum_spurious_dragon_trie_EMPTY_TRIE_ROOT : + IsGlobalAlias globals ethereum.spurious_dragon.trie.globals "EMPTY_TRIE_ROOT". +Axiom ethereum_spurious_dragon_trie_Trie : + IsGlobalAlias globals ethereum.spurious_dragon.trie.globals "Trie". +Axiom ethereum_spurious_dragon_trie_copy_trie : + IsGlobalAlias globals ethereum.spurious_dragon.trie.globals "copy_trie". +Axiom ethereum_spurious_dragon_trie_root : + IsGlobalAlias globals ethereum.spurious_dragon.trie.globals "root". +Axiom ethereum_spurious_dragon_trie_trie_get : + IsGlobalAlias globals ethereum.spurious_dragon.trie.globals "trie_get". +Axiom ethereum_spurious_dragon_trie_trie_set : + IsGlobalAlias globals ethereum.spurious_dragon.trie.globals "trie_set". Definition State : Value.t := builtins.make_klass @@ -123,7 +123,7 @@ Definition begin_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) ], make_dict [] - |); (* At expr: unsupported node type: DictComp *) ] + |); Constant.str "(* At expr: unsupported node type: DictComp *)" ] ], make_dict [] |) in @@ -201,8 +201,27 @@ Definition get_account : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "account" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "account" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_ACCOUNT" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -237,6 +256,7 @@ Definition get_account_optional : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "account" |) + |) in M.pure Constant.None_)). Definition set_account : Value.t -> Value.t -> M := @@ -316,6 +336,18 @@ Definition destroy_storage : Value.t -> Value.t -> M := Address of account whose storage is to be deleted. " in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -350,6 +382,26 @@ Definition get_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "trie" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let value := @@ -371,6 +423,7 @@ Definition get_storage : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "value" |) + |) in M.pure Constant.None_)). Definition set_storage : Value.t -> Value.t -> M := @@ -411,6 +464,27 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "trie" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let trie := + M.call (| + M.get_name (| globals, "Trie" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), + M.get_name (| globals, "trie" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -423,6 +497,18 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + {} + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -447,8 +533,29 @@ Definition storage_root : Value.t -> Value.t -> M := " in let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_TRIE_ROOT" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -479,6 +586,7 @@ Definition state_root : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition account_exists : Value.t -> Value.t -> M := @@ -511,6 +619,7 @@ Definition account_exists : Value.t -> Value.t -> M := |), Constant.None_ |) + |) in M.pure Constant.None_)). Definition account_has_code_or_nonce : Value.t -> Value.t -> M := @@ -560,6 +669,7 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition is_account_empty : Value.t -> Value.t -> M := @@ -617,6 +727,7 @@ Definition is_account_empty : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition account_exists_and_is_empty : Value.t -> Value.t -> M := @@ -683,6 +794,7 @@ Definition account_exists_and_is_empty : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition is_account_alive : Value.t -> Value.t -> M := @@ -713,6 +825,20 @@ Definition is_account_alive : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "account" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| UnOp.not (| BoolOp.and (| Compare.eq (| @@ -740,6 +866,7 @@ Definition is_account_alive : Value.t -> Value.t -> M := |) )) |) |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -847,6 +974,30 @@ Definition touch_account : Value.t -> Value.t -> M := The address of the account that need to initialised. " in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "account_exists" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "EMPTY_ACCOUNT" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/transactions.v b/CoqOfPython/ethereum/spurious_dragon/transactions.v index 6d1bc6b..f6ba300 100644 --- a/CoqOfPython/ethereum/spurious_dragon/transactions.v +++ b/CoqOfPython/ethereum/spurious_dragon/transactions.v @@ -17,21 +17,21 @@ Require typing. Axiom typing_Union : IsGlobalAlias globals typing.globals "Union". -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes0 : - IsGlobalAlias globals base_types.globals "Bytes0". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.spurious_dragon.fork_types. +Axiom ethereum_spurious_dragon_fork_types_Address : + IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "Address". Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( Constant.int 21000 diff --git a/CoqOfPython/ethereum/spurious_dragon/trie.v b/CoqOfPython/ethereum/spurious_dragon/trie.v index f88c794..1e2dee1 100644 --- a/CoqOfPython/ethereum/spurious_dragon/trie.v +++ b/CoqOfPython/ethereum/spurious_dragon/trie.v @@ -54,9 +54,9 @@ Require ethereum.crypto.hash. Axiom ethereum_crypto_hash_keccak256 : IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". -Require ethereum.tangerine_whistle. -Axiom ethereum_tangerine_whistle_trie : - IsGlobalAlias globals ethereum.tangerine_whistle.globals "trie". +Require ethereum.tangerine_whistle.__init__. +Axiom ethereum_tangerine_whistle___init___trie : + IsGlobalAlias globals ethereum.tangerine_whistle.__init__.globals "trie". Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : @@ -66,37 +66,37 @@ Require ethereum.utils.hexadecimal. Axiom ethereum_utils_hexadecimal_hex_to_bytes : IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require blocks. -Axiom blocks_Receipt : - IsGlobalAlias globals blocks.globals "Receipt". - -Require fork_types. -Axiom fork_types_Account : - IsGlobalAlias globals fork_types.globals "Account". -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". -Axiom fork_types_encode_account : - IsGlobalAlias globals fork_types.globals "encode_account". - -Require transactions. -Axiom transactions_Transaction : - IsGlobalAlias globals transactions.globals "Transaction". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.spurious_dragon.blocks. +Axiom ethereum_spurious_dragon_blocks_Receipt : + IsGlobalAlias globals ethereum.spurious_dragon.blocks.globals "Receipt". + +Require ethereum.spurious_dragon.fork_types. +Axiom ethereum_spurious_dragon_fork_types_Account : + IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "Account". +Axiom ethereum_spurious_dragon_fork_types_Address : + IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "Address". +Axiom ethereum_spurious_dragon_fork_types_Root : + IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "Root". +Axiom ethereum_spurious_dragon_fork_types_encode_account : + IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "encode_account". + +Require ethereum.spurious_dragon.transactions. +Axiom ethereum_spurious_dragon_transactions_Transaction : + IsGlobalAlias globals ethereum.spurious_dragon.transactions.globals "Transaction". Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -202,16 +202,99 @@ Definition encode_internal_node : Value.t -> Value.t -> M := " in (* At stmt: unsupported node type: AnnAssign *) let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "node" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + Constant.bytes "" in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "LeafNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "rest_of_key" |); + Constant.bool true + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "ExtensionNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "key_segment" |); + Constant.bool false + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "BranchNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + BinOp.add (| + M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "value" |) + ] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ - (* At expr: unsupported node type: JoinedStr *) + Constant.str "(* At expr: unsupported node type: JoinedStr *)" ], make_dict [] - |)) + |)) |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -229,6 +312,26 @@ Definition encode_internal_node : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded" |) + ], + make_dict [] + |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "unencoded" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_name (| globals, "keccak256" |), @@ -237,6 +340,7 @@ Definition encode_internal_node : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -250,8 +354,86 @@ Definition encode_node : Value.t -> Value.t -> M := Currently mostly an unimplemented stub. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| + M.get_name (| globals, "storage_root" |), + Constant.None_ + |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "encode_account" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "storage_root" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + make_tuple [ M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "U256" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "cast" |), + make_list [ + M.get_field (| M.get_name (| globals, "rlp" |), "RLP" |); + M.get_name (| globals, "node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "node" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "previous_trie" |), "encode_node" |), @@ -261,6 +443,7 @@ Definition encode_node : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -312,6 +495,7 @@ Definition copy_trie : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition trie_set : Value.t -> Value.t -> M := @@ -333,6 +517,32 @@ Definition trie_set : Value.t -> Value.t -> M := Node to insert at `key`. " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + M.get_field (| M.get_name (| globals, "trie" |), "default" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "key" |), + M.get_field (| M.get_name (| globals, "trie" |), "_data" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), M.get_name (| globals, "value" |) @@ -370,6 +580,7 @@ Definition trie_get : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition common_prefix_length : Value.t -> Value.t -> M := @@ -392,6 +603,34 @@ Definition common_prefix_length : Value.t -> Value.t -> M := make_dict [] |) do let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), + M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -403,6 +642,7 @@ Definition common_prefix_length : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition nibble_list_to_compact : Value.t -> Value.t -> M := @@ -448,6 +688,71 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + Constant.int 2 + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.mult (| + Constant.int 16, + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "is_leaf" |) + |) + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ @@ -509,6 +814,7 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition bytes_to_nibble_list : Value.t -> Value.t -> M := @@ -586,6 +892,7 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition _prepare_trie : Value.t -> Value.t -> M := @@ -615,6 +922,48 @@ Definition _prepare_trie : Value.t -> Value.t -> M := make_dict [] |) do let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| + M.get_name (| globals, "get_storage_root" |), + Constant.None_ + |) |) in + let address := + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |); + M.call (| + M.get_name (| globals, "get_storage_root" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let encoded_value := M.call (| M.get_name (| globals, "encode_node" |), @@ -638,6 +987,22 @@ Definition _prepare_trie : Value.t -> Value.t -> M := |) in (* At stmt: unsupported node type: AnnAssign *) let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "trie" |), "secured" |), + (* then *) + ltac:(M.monadic ( + let key := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let key := M.get_name (| globals, "preimage" |) in M.pure Constant.None_ @@ -655,6 +1020,7 @@ Definition _prepare_trie : Value.t -> Value.t -> M := EndFor. let _ := M.return_ (| M.get_name (| globals, "mapped" |) + |) in M.pure Constant.None_)). Definition root : Value.t -> Value.t -> M := @@ -708,6 +1074,44 @@ Definition root : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -724,6 +1128,7 @@ Definition root : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -750,6 +1155,26 @@ Definition patricialize : Value.t -> Value.t -> M := Root node of `obj`. " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let arbitrary_key := @@ -767,10 +1192,39 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), + Constant.int 1 + |), + (* then *) + ltac:(M.monadic ( + let leaf := + M.call (| + M.get_name (| globals, "LeafNode" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |); + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "leaf" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let substring := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |) |) in + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) in let prefix_length := M.call (| M.get_name (| globals, "len" |), @@ -789,7 +1243,7 @@ Definition patricialize : Value.t -> Value.t -> M := M.get_name (| globals, "common_prefix_length" |), make_list [ M.get_name (| globals, "substring" |); - M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) + M.get_subscript (| M.get_name (| globals, "key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) ], make_dict [] |) @@ -797,10 +1251,64 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "prefix_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "prefix_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let prefix := + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ExtensionNode" |), + make_list [ + M.get_name (| globals, "prefix" |); + M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_name (| globals, "obj" |); + BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) @@ -823,6 +1331,44 @@ Definition patricialize : Value.t -> Value.t -> M := Constant.bytes "" in For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |), + M.get_name (| globals, "level" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "AssertionError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) @@ -834,9 +1380,10 @@ Definition patricialize : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "BranchNode" |), make_list [ - (* At expr: unsupported node type: ListComp *); + Constant.str "(* At expr: unsupported node type: ListComp *)"; M.get_name (| globals, "value" |) ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/utils/address.v b/CoqOfPython/ethereum/spurious_dragon/utils/address.v index 502ba8e..33ae415 100644 --- a/CoqOfPython/ethereum/spurious_dragon/utils/address.v +++ b/CoqOfPython/ethereum/spurious_dragon/utils/address.v @@ -36,13 +36,13 @@ Require ethereum.utils.byte. Axiom ethereum_utils_byte_left_pad_zero_bytes : IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.spurious_dragon.fork_types. +Axiom ethereum_spurious_dragon_fork_types_Address : + IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "Address". Definition to_address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -68,10 +68,11 @@ Definition to_address : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), make_list [], make_dict [] - |), UnOp.sub (| Constant.int 20 |) |) + |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) ], make_dict [] |) + |) in M.pure Constant.None_)). Definition compute_contract_address : Value.t -> Value.t -> M := @@ -111,7 +112,7 @@ Definition compute_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -129,4 +130,5 @@ Definition compute_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/utils/hexadecimal.v b/CoqOfPython/ethereum/spurious_dragon/utils/hexadecimal.v index 879f5ca..f1b941c 100644 --- a/CoqOfPython/ethereum/spurious_dragon/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/spurious_dragon/utils/hexadecimal.v @@ -22,13 +22,13 @@ Require ethereum.utils.hexadecimal. Axiom ethereum_utils_hexadecimal_remove_hex_prefix : IsGlobalAlias globals ethereum.utils.hexadecimal.globals "remove_hex_prefix". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". +Require ethereum.spurious_dragon.fork_types. +Axiom ethereum_spurious_dragon_fork_types_Address : + IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "Address". +Axiom ethereum_spurious_dragon_fork_types_Bloom : + IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "Bloom". +Axiom ethereum_spurious_dragon_fork_types_Root : + IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "Root". Definition hex_to_root : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -66,6 +66,7 @@ Definition hex_to_root : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition hex_to_bloom : Value.t -> Value.t -> M := @@ -104,6 +105,7 @@ Definition hex_to_bloom : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition hex_to_address : Value.t -> Value.t -> M := @@ -149,4 +151,5 @@ Definition hex_to_address : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/utils/message.v b/CoqOfPython/ethereum/spurious_dragon/utils/message.v index c1d198a..2cab620 100644 --- a/CoqOfPython/ethereum/spurious_dragon/utils/message.v +++ b/CoqOfPython/ethereum/spurious_dragon/utils/message.v @@ -34,23 +34,23 @@ Axiom ethereum_base_types_Bytes0 : Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.spurious_dragon.fork_types. +Axiom ethereum_spurious_dragon_fork_types_Address : + IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "Address". -Require state. -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". +Require ethereum.spurious_dragon.state. +Axiom ethereum_spurious_dragon_state_get_account : + IsGlobalAlias globals ethereum.spurious_dragon.state.globals "get_account". -Require vm. -Axiom vm_Environment : - IsGlobalAlias globals vm.globals "Environment". -Axiom vm_Message : - IsGlobalAlias globals vm.globals "Message". +Require ethereum.spurious_dragon.vm.__init__. +Axiom ethereum_spurious_dragon_vm___init___Environment : + IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "Environment". +Axiom ethereum_spurious_dragon_vm___init___Message : + IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "Message". -Require address. -Axiom address_compute_contract_address : - IsGlobalAlias globals address.globals "compute_contract_address". +Require ethereum.spurious_dragon.utils.address. +Axiom ethereum_spurious_dragon_utils_address_compute_contract_address : + IsGlobalAlias globals ethereum.spurious_dragon.utils.address.globals "compute_contract_address". Definition prepare_message : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -85,14 +85,108 @@ Definition prepare_message : Value.t -> Value.t -> M := Items containing contract creation or message call specific data. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Bytes0" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.call (| + M.get_name (| globals, "compute_contract_address" |), + make_list [ + M.get_name (| globals, "caller" |); + BinOp.sub (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "caller" |) + ], + make_dict [] + |), "nonce" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let msg_data := + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) in + let code := + M.get_name (| globals, "data" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.get_name (| globals, "target" |) in + let msg_data := + M.get_name (| globals, "data" |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "target" |) + ], + make_dict [] + |), "code" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "code_address" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let code_address := + M.get_name (| globals, "target" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "Target must be address or empty bytes" ], make_dict [] - |)) + |)) |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -103,4 +197,5 @@ Definition prepare_message : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/__init__.v b/CoqOfPython/ethereum/spurious_dragon/vm/__init__.v index 8859cb4..d66c0b1 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/__init__.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/__init__.v @@ -48,23 +48,23 @@ Require ethereum.crypto.hash. Axiom ethereum_crypto_hash_Hash32 : IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". +Require ethereum.spurious_dragon.blocks. +Axiom ethereum_spurious_dragon_blocks_Log : + IsGlobalAlias globals ethereum.spurious_dragon.blocks.globals "Log". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.spurious_dragon.fork_types. +Axiom ethereum_spurious_dragon_fork_types_Address : + IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "Address". -Require state. -Axiom state_State : - IsGlobalAlias globals state.globals "State". -Axiom state_account_exists_and_is_empty : - IsGlobalAlias globals state.globals "account_exists_and_is_empty". +Require ethereum.spurious_dragon.state. +Axiom ethereum_spurious_dragon_state_State : + IsGlobalAlias globals ethereum.spurious_dragon.state.globals "State". +Axiom ethereum_spurious_dragon_state_account_exists_and_is_empty : + IsGlobalAlias globals ethereum.spurious_dragon.state.globals "account_exists_and_is_empty". -Require precompiled_contracts. -Axiom precompiled_contracts_RIPEMD160_ADDRESS : - IsGlobalAlias globals precompiled_contracts.globals "RIPEMD160_ADDRESS". +Require ethereum.spurious_dragon.vm.precompiled_contracts.__init__. +Axiom ethereum_spurious_dragon_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : + IsGlobalAlias globals ethereum.spurious_dragon.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] @@ -143,6 +143,28 @@ Definition incorporate_child_on_success : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -161,9 +183,63 @@ Definition incorporate_child_on_error : Value.t -> Value.t -> M := The child evm to incorporate. " in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "RIPEMD160_ADDRESS" |), + M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |), + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "child_evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "RIPEMD160_ADDRESS" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign_op (| diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/gas.v b/CoqOfPython/ethereum/spurious_dragon/vm/gas.v index 0604b94..6923f48 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/gas.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/gas.v @@ -43,13 +43,13 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.spurious_dragon.vm.__init__. +Axiom ethereum_spurious_dragon_vm___init___Evm : + IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "Evm". -Require exceptions. -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". +Require ethereum.spurious_dragon.vm.exceptions. +Axiom ethereum_spurious_dragon_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.spurious_dragon.vm.exceptions.globals "OutOfGasError". Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -490,6 +490,18 @@ Definition charge_gas : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "amount" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign_op (| BinOp.sub, M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), @@ -605,6 +617,18 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := |) in For make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ] in M.get_name (| globals, "extensions" |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "size" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let before_size := @@ -639,6 +663,18 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let size_to_extend := BinOp.add @@ -687,6 +723,7 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition calculate_message_call_gas : Value.t -> Value.t -> M := @@ -718,22 +755,56 @@ Definition calculate_message_call_gas : Value.t -> Value.t -> M := message_call_gas: `MessageCallGas` " in let call_stipend := - (* if *) -M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "call_stipend" |) + )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "gas_left" |), + BinOp.add (| + M.get_name (| globals, "extra_gas" |), + M.get_name (| globals, "memory_cost" |) + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallGas" |), + make_list [ + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "extra_gas" |) + |); + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "call_stipend" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let gas := @@ -772,6 +843,7 @@ M.call (| ], make_dict [] |) + |) in M.pure Constant.None_)). Definition max_message_call_gas : Value.t -> Value.t -> M := @@ -798,4 +870,5 @@ Definition max_message_call_gas : Value.t -> Value.t -> M := Constant.int 64 |) |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/__init__.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/__init__.v index e5bebd7..60f3b2f 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/__init__.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/__init__.v @@ -26,53 +26,53 @@ Axiom typing_Callable : Axiom typing_Dict : IsGlobalAlias globals typing.globals "Dict". -Require __init__. -Axiom __init___arithmetic : - IsGlobalAlias globals __init__.globals "arithmetic". +Require ethereum.spurious_dragon.vm.instructions.__init__. +Axiom ethereum_spurious_dragon_vm_instructions___init___arithmetic : + IsGlobalAlias globals ethereum.spurious_dragon.vm.instructions.__init__.globals "arithmetic". -Require __init__. -Axiom __init___bitwise : - IsGlobalAlias globals __init__.globals "bitwise". +Require ethereum.spurious_dragon.vm.instructions.__init__. +Axiom ethereum_spurious_dragon_vm_instructions___init___bitwise : + IsGlobalAlias globals ethereum.spurious_dragon.vm.instructions.__init__.globals "bitwise". -Require __init__. -Axiom __init___block : - IsGlobalAlias globals __init__.globals "block". +Require ethereum.spurious_dragon.vm.instructions.__init__. +Axiom ethereum_spurious_dragon_vm_instructions___init___block : + IsGlobalAlias globals ethereum.spurious_dragon.vm.instructions.__init__.globals "block". -Require __init__. -Axiom __init___comparison : - IsGlobalAlias globals __init__.globals "comparison". +Require ethereum.spurious_dragon.vm.instructions.__init__. +Axiom ethereum_spurious_dragon_vm_instructions___init___comparison : + IsGlobalAlias globals ethereum.spurious_dragon.vm.instructions.__init__.globals "comparison". -Require __init__. -Axiom __init___control_flow : - IsGlobalAlias globals __init__.globals "control_flow". +Require ethereum.spurious_dragon.vm.instructions.__init__. +Axiom ethereum_spurious_dragon_vm_instructions___init___control_flow : + IsGlobalAlias globals ethereum.spurious_dragon.vm.instructions.__init__.globals "control_flow". -Require __init__. -Axiom __init___environment : - IsGlobalAlias globals __init__.globals "environment". +Require ethereum.spurious_dragon.vm.instructions.__init__. +Axiom ethereum_spurious_dragon_vm_instructions___init___environment : + IsGlobalAlias globals ethereum.spurious_dragon.vm.instructions.__init__.globals "environment". -Require __init__. -Axiom __init___keccak : - IsGlobalAlias globals __init__.globals "keccak". +Require ethereum.spurious_dragon.vm.instructions.__init__. +Axiom ethereum_spurious_dragon_vm_instructions___init___keccak : + IsGlobalAlias globals ethereum.spurious_dragon.vm.instructions.__init__.globals "keccak". -Require __init__. -Axiom __init___log : - IsGlobalAlias globals __init__.globals "log". +Require ethereum.spurious_dragon.vm.instructions.__init__. +Axiom ethereum_spurious_dragon_vm_instructions___init___log : + IsGlobalAlias globals ethereum.spurious_dragon.vm.instructions.__init__.globals "log". -Require __init__. -Axiom __init___memory : - IsGlobalAlias globals __init__.globals "memory". +Require ethereum.spurious_dragon.vm.instructions.__init__. +Axiom ethereum_spurious_dragon_vm_instructions___init___memory : + IsGlobalAlias globals ethereum.spurious_dragon.vm.instructions.__init__.globals "memory". -Require __init__. -Axiom __init___stack : - IsGlobalAlias globals __init__.globals "stack". +Require ethereum.spurious_dragon.vm.instructions.__init__. +Axiom ethereum_spurious_dragon_vm_instructions___init___stack : + IsGlobalAlias globals ethereum.spurious_dragon.vm.instructions.__init__.globals "stack". -Require __init__. -Axiom __init___storage : - IsGlobalAlias globals __init__.globals "storage". +Require ethereum.spurious_dragon.vm.instructions.__init__. +Axiom ethereum_spurious_dragon_vm_instructions___init___storage : + IsGlobalAlias globals ethereum.spurious_dragon.vm.instructions.__init__.globals "storage". -Require __init__. -Axiom __init___system : - IsGlobalAlias globals __init__.globals "system". +Require ethereum.spurious_dragon.vm.instructions.__init__. +Axiom ethereum_spurious_dragon_vm_instructions___init___system : + IsGlobalAlias globals ethereum.spurious_dragon.vm.instructions.__init__.globals "system". Definition Ops : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/arithmetic.v index 581ba5d..80f960f 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/arithmetic.v @@ -31,29 +31,29 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_get_sign : IsGlobalAlias globals ethereum.utils.numeric.globals "get_sign". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_EXPONENTIATION : - IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION". -Axiom gas_GAS_EXPONENTIATION_PER_BYTE : - IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION_PER_BYTE". -Axiom gas_GAS_LOW : - IsGlobalAlias globals gas.globals "GAS_LOW". -Axiom gas_GAS_MID : - IsGlobalAlias globals gas.globals "GAS_MID". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.spurious_dragon.vm.__init__. +Axiom ethereum_spurious_dragon_vm___init___Evm : + IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "Evm". + +Require ethereum.spurious_dragon.vm.gas. +Axiom ethereum_spurious_dragon_vm_gas_GAS_EXPONENTIATION : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_EXPONENTIATION". +Axiom ethereum_spurious_dragon_vm_gas_GAS_EXPONENTIATION_PER_BYTE : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_EXPONENTIATION_PER_BYTE". +Axiom ethereum_spurious_dragon_vm_gas_GAS_LOW : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_LOW". +Axiom ethereum_spurious_dragon_vm_gas_GAS_MID : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_MID". +Axiom ethereum_spurious_dragon_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_spurious_dragon_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "charge_gas". + +Require ethereum.spurious_dragon.vm.stack. +Axiom ethereum_spurious_dragon_vm_stack_pop : + IsGlobalAlias globals ethereum.spurious_dragon.vm.stack.globals "pop". +Axiom ethereum_spurious_dragon_vm_stack_push : + IsGlobalAlias globals ethereum.spurious_dragon.vm.stack.globals "push". Definition add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -273,6 +273,25 @@ Definition div : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "divisor" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let quotient := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let quotient := BinOp.floor_div (| M.get_name (| globals, "dividend" |), @@ -341,7 +360,41 @@ Definition sdiv : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "divisor" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let quotient := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_name (| globals, "dividend" |), + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "divisor" |), + UnOp.sub (| Constant.int 1 |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let quotient := + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let sign := M.call (| M.get_name (| globals, "get_sign" |), @@ -436,6 +489,25 @@ Definition mod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "y" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let remainder := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let remainder := BinOp.mod_ (| M.get_name (| globals, "x" |), @@ -504,6 +576,19 @@ Definition smod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "y" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let remainder := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let remainder := BinOp.mult (| M.call (| @@ -617,6 +702,25 @@ Definition addmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "z" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -712,6 +816,25 @@ Definition mulmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "z" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -881,6 +1004,19 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "byte_num" |), + Constant.int 31 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.get_name (| globals, "value" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let value_bytes := M.call (| M.get_name (| globals, "bytes" |), @@ -894,7 +1030,7 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let value_bytes := - M.get_subscript (| M.get_name (| globals, "value_bytes" |), BinOp.sub (| + M.get_subscript (| M.get_name (| globals, "value_bytes" |), M.slice (| BinOp.sub (| Constant.int 31, M.call (| M.get_name (| globals, "int" |), @@ -903,13 +1039,32 @@ Definition signextend : Value.t -> Value.t -> M := ], make_dict [] |) - |) |) in + |), Constant.None_ |) |) in let sign_bit := BinOp.r_shift (| M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), Constant.int 7 |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "sign_bit" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "value_bytes" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let num_bytes_prepend := BinOp.sub (| Constant.int 32, diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/bitwise.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/bitwise.v index f38e7aa..cc2404d 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/bitwise.v @@ -21,21 +21,21 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.spurious_dragon.vm.__init__. +Axiom ethereum_spurious_dragon_vm___init___Evm : + IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.spurious_dragon.vm.gas. +Axiom ethereum_spurious_dragon_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_spurious_dragon_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "charge_gas". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.spurious_dragon.vm.stack. +Axiom ethereum_spurious_dragon_vm_stack_pop : + IsGlobalAlias globals ethereum.spurious_dragon.vm.stack.globals "pop". +Axiom ethereum_spurious_dragon_vm_stack_push : + IsGlobalAlias globals ethereum.spurious_dragon.vm.stack.globals "push". Definition bitwise_and : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -285,6 +285,25 @@ Definition get_byte : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "byte_index" |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let extra_bytes_to_right := BinOp.sub (| Constant.int 31, diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/block.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/block.v index 90be45c..6a7737d 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/block.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/block.v @@ -21,23 +21,23 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_BLOCK_HASH : - IsGlobalAlias globals gas.globals "GAS_BLOCK_HASH". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.spurious_dragon.vm.__init__. +Axiom ethereum_spurious_dragon_vm___init___Evm : + IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "Evm". + +Require ethereum.spurious_dragon.vm.gas. +Axiom ethereum_spurious_dragon_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_BASE". +Axiom ethereum_spurious_dragon_vm_gas_GAS_BLOCK_HASH : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_BLOCK_HASH". +Axiom ethereum_spurious_dragon_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "charge_gas". + +Require ethereum.spurious_dragon.vm.stack. +Axiom ethereum_spurious_dragon_vm_stack_pop : + IsGlobalAlias globals ethereum.spurious_dragon.vm.stack.globals "pop". +Axiom ethereum_spurious_dragon_vm_stack_push : + IsGlobalAlias globals ethereum.spurious_dragon.vm.stack.globals "push". Definition block_hash : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -69,6 +69,30 @@ Definition block_hash : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt_e (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + M.get_name (| globals, "block_number" |) + |), + ltac:(M.monadic ( + Compare.gt (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + BinOp.add (| + M.get_name (| globals, "block_number" |), + Constant.int 256 + |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let hash := + Constant.bytes "00" in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let hash := M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/comparison.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/comparison.v index b8529d8..2c803bf 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/comparison.v @@ -21,21 +21,21 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.spurious_dragon.vm.__init__. +Axiom ethereum_spurious_dragon_vm___init___Evm : + IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.spurious_dragon.vm.gas. +Axiom ethereum_spurious_dragon_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_spurious_dragon_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "charge_gas". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.spurious_dragon.vm.stack. +Axiom ethereum_spurious_dragon_vm_stack_pop : + IsGlobalAlias globals ethereum.spurious_dragon.vm.stack.globals "pop". +Axiom ethereum_spurious_dragon_vm_stack_push : + IsGlobalAlias globals ethereum.spurious_dragon.vm.stack.globals "push". Definition less_than : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/control_flow.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/control_flow.v index d4e4eae..bfc9c53 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/control_flow.v @@ -23,31 +23,31 @@ Axiom ethereum_base_types_U256 : Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require vm.gas. -Axiom vm_gas_GAS_BASE : - IsGlobalAlias globals vm.gas.globals "GAS_BASE". -Axiom vm_gas_GAS_HIGH : - IsGlobalAlias globals vm.gas.globals "GAS_HIGH". -Axiom vm_gas_GAS_JUMPDEST : - IsGlobalAlias globals vm.gas.globals "GAS_JUMPDEST". -Axiom vm_gas_GAS_MID : - IsGlobalAlias globals vm.gas.globals "GAS_MID". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.spurious_dragon.vm.gas. +Axiom ethereum_spurious_dragon_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_BASE". +Axiom ethereum_spurious_dragon_vm_gas_GAS_HIGH : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_HIGH". +Axiom ethereum_spurious_dragon_vm_gas_GAS_JUMPDEST : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_JUMPDEST". +Axiom ethereum_spurious_dragon_vm_gas_GAS_MID : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_MID". +Axiom ethereum_spurious_dragon_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "charge_gas". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.spurious_dragon.vm.__init__. +Axiom ethereum_spurious_dragon_vm___init___Evm : + IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "Evm". -Require exceptions. -Axiom exceptions_InvalidJumpDestError : - IsGlobalAlias globals exceptions.globals "InvalidJumpDestError". +Require ethereum.spurious_dragon.vm.exceptions. +Axiom ethereum_spurious_dragon_vm_exceptions_InvalidJumpDestError : + IsGlobalAlias globals ethereum.spurious_dragon.vm.exceptions.globals "InvalidJumpDestError". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.spurious_dragon.vm.stack. +Axiom ethereum_spurious_dragon_vm_stack_pop : + IsGlobalAlias globals ethereum.spurious_dragon.vm.stack.globals "pop". +Axiom ethereum_spurious_dragon_vm_stack_push : + IsGlobalAlias globals ethereum.spurious_dragon.vm.stack.globals "push". Definition stop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -109,6 +109,18 @@ Definition jump : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "jump_dest" |), + M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -168,7 +180,35 @@ Definition jumpi : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "conditional_value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let destination := + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "jump_dest" |), + M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let destination := M.get_name (| globals, "jump_dest" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/environment.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/environment.v index 366e59a..fbfdca2 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/environment.v @@ -27,45 +27,45 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require state. -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". - -Require utils.address. -Axiom utils_address_to_address : - IsGlobalAlias globals utils.address.globals "to_address". - -Require vm.memory. -Axiom vm_memory_buffer_read : - IsGlobalAlias globals vm.memory.globals "buffer_read". -Axiom vm_memory_memory_write : - IsGlobalAlias globals vm.memory.globals "memory_write". - -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_BALANCE : - IsGlobalAlias globals gas.globals "GAS_BALANCE". -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_COPY : - IsGlobalAlias globals gas.globals "GAS_COPY". -Axiom gas_GAS_EXTERNAL : - IsGlobalAlias globals gas.globals "GAS_EXTERNAL". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.spurious_dragon.state. +Axiom ethereum_spurious_dragon_state_get_account : + IsGlobalAlias globals ethereum.spurious_dragon.state.globals "get_account". + +Require ethereum.spurious_dragon.utils.address. +Axiom ethereum_spurious_dragon_utils_address_to_address : + IsGlobalAlias globals ethereum.spurious_dragon.utils.address.globals "to_address". + +Require ethereum.spurious_dragon.vm.memory. +Axiom ethereum_spurious_dragon_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.spurious_dragon.vm.memory.globals "buffer_read". +Axiom ethereum_spurious_dragon_vm_memory_memory_write : + IsGlobalAlias globals ethereum.spurious_dragon.vm.memory.globals "memory_write". + +Require ethereum.spurious_dragon.vm.__init__. +Axiom ethereum_spurious_dragon_vm___init___Evm : + IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "Evm". + +Require ethereum.spurious_dragon.vm.gas. +Axiom ethereum_spurious_dragon_vm_gas_GAS_BALANCE : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_BALANCE". +Axiom ethereum_spurious_dragon_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_BASE". +Axiom ethereum_spurious_dragon_vm_gas_GAS_COPY : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_COPY". +Axiom ethereum_spurious_dragon_vm_gas_GAS_EXTERNAL : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_EXTERNAL". +Axiom ethereum_spurious_dragon_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_spurious_dragon_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_spurious_dragon_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "charge_gas". + +Require ethereum.spurious_dragon.vm.stack. +Axiom ethereum_spurious_dragon_vm_stack_pop : + IsGlobalAlias globals ethereum.spurious_dragon.vm.stack.globals "pop". +Axiom ethereum_spurious_dragon_vm_stack_push : + IsGlobalAlias globals ethereum.spurious_dragon.vm.stack.globals "push". Definition address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/keccak.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/keccak.v index 2c4b10e..723443a 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/keccak.v @@ -31,29 +31,29 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_KECCAK256 : - IsGlobalAlias globals gas.globals "GAS_KECCAK256". -Axiom gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.spurious_dragon.vm.__init__. +Axiom ethereum_spurious_dragon_vm___init___Evm : + IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "Evm". + +Require ethereum.spurious_dragon.vm.gas. +Axiom ethereum_spurious_dragon_vm_gas_GAS_KECCAK256 : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_KECCAK256". +Axiom ethereum_spurious_dragon_vm_gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_KECCAK256_WORD". +Axiom ethereum_spurious_dragon_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_spurious_dragon_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "charge_gas". + +Require ethereum.spurious_dragon.vm.memory. +Axiom ethereum_spurious_dragon_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.spurious_dragon.vm.memory.globals "memory_read_bytes". + +Require ethereum.spurious_dragon.vm.stack. +Axiom ethereum_spurious_dragon_vm_stack_pop : + IsGlobalAlias globals ethereum.spurious_dragon.vm.stack.globals "pop". +Axiom ethereum_spurious_dragon_vm_stack_push : + IsGlobalAlias globals ethereum.spurious_dragon.vm.stack.globals "push". Definition keccak : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/log.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/log.v index ab196bc..463486d 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/log.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/log.v @@ -25,33 +25,33 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". - -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_LOG : - IsGlobalAlias globals gas.globals "GAS_LOG". -Axiom gas_GAS_LOG_DATA : - IsGlobalAlias globals gas.globals "GAS_LOG_DATA". -Axiom gas_GAS_LOG_TOPIC : - IsGlobalAlias globals gas.globals "GAS_LOG_TOPIC". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". +Require ethereum.spurious_dragon.blocks. +Axiom ethereum_spurious_dragon_blocks_Log : + IsGlobalAlias globals ethereum.spurious_dragon.blocks.globals "Log". + +Require ethereum.spurious_dragon.vm.__init__. +Axiom ethereum_spurious_dragon_vm___init___Evm : + IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "Evm". + +Require ethereum.spurious_dragon.vm.gas. +Axiom ethereum_spurious_dragon_vm_gas_GAS_LOG : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_LOG". +Axiom ethereum_spurious_dragon_vm_gas_GAS_LOG_DATA : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_LOG_DATA". +Axiom ethereum_spurious_dragon_vm_gas_GAS_LOG_TOPIC : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_LOG_TOPIC". +Axiom ethereum_spurious_dragon_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_spurious_dragon_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "charge_gas". + +Require ethereum.spurious_dragon.vm.memory. +Axiom ethereum_spurious_dragon_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.spurious_dragon.vm.memory.globals "memory_read_bytes". + +Require ethereum.spurious_dragon.vm.stack. +Axiom ethereum_spurious_dragon_vm_stack_pop : + IsGlobalAlias globals ethereum.spurious_dragon.vm.stack.globals "pop". Definition log_n : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/memory.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/memory.v index 86ba742..408e328 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/memory.v @@ -23,31 +23,31 @@ Axiom ethereum_base_types_U256 : Axiom ethereum_base_types_Bytes : IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.spurious_dragon.vm.__init__. +Axiom ethereum_spurious_dragon_vm___init___Evm : + IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.spurious_dragon.vm.gas. +Axiom ethereum_spurious_dragon_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_BASE". +Axiom ethereum_spurious_dragon_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_spurious_dragon_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_spurious_dragon_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "charge_gas". -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". -Axiom memory_memory_write : - IsGlobalAlias globals memory.globals "memory_write". +Require ethereum.spurious_dragon.vm.memory. +Axiom ethereum_spurious_dragon_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.spurious_dragon.vm.memory.globals "memory_read_bytes". +Axiom ethereum_spurious_dragon_vm_memory_memory_write : + IsGlobalAlias globals ethereum.spurious_dragon.vm.memory.globals "memory_write". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.spurious_dragon.vm.stack. +Axiom ethereum_spurious_dragon_vm_stack_pop : + IsGlobalAlias globals ethereum.spurious_dragon.vm.stack.globals "pop". +Axiom ethereum_spurious_dragon_vm_stack_push : + IsGlobalAlias globals ethereum.spurious_dragon.vm.stack.globals "push". Definition mstore : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/stack.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/stack.v index 305af15..bd63cf7 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/stack.v @@ -29,27 +29,27 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". -Axiom __init___stack : - IsGlobalAlias globals __init__.globals "stack". - -Require exceptions. -Axiom exceptions_StackUnderflowError : - IsGlobalAlias globals exceptions.globals "StackUnderflowError". - -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require memory. -Axiom memory_buffer_read : - IsGlobalAlias globals memory.globals "buffer_read". +Require ethereum.spurious_dragon.vm.__init__. +Axiom ethereum_spurious_dragon_vm___init___Evm : + IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "Evm". +Axiom ethereum_spurious_dragon_vm___init___stack : + IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "stack". + +Require ethereum.spurious_dragon.vm.exceptions. +Axiom ethereum_spurious_dragon_vm_exceptions_StackUnderflowError : + IsGlobalAlias globals ethereum.spurious_dragon.vm.exceptions.globals "StackUnderflowError". + +Require ethereum.spurious_dragon.vm.gas. +Axiom ethereum_spurious_dragon_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_BASE". +Axiom ethereum_spurious_dragon_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_spurious_dragon_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "charge_gas". + +Require ethereum.spurious_dragon.vm.memory. +Axiom ethereum_spurious_dragon_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.spurious_dragon.vm.memory.globals "buffer_read". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/storage.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/storage.v index 5250214..df5345c 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/storage.v @@ -17,33 +17,33 @@ Introduction Implementations of the EVM storage related instructions. ". -Require state. -Axiom state_get_storage : - IsGlobalAlias globals state.globals "get_storage". -Axiom state_set_storage : - IsGlobalAlias globals state.globals "set_storage". +Require ethereum.spurious_dragon.state. +Axiom ethereum_spurious_dragon_state_get_storage : + IsGlobalAlias globals ethereum.spurious_dragon.state.globals "get_storage". +Axiom ethereum_spurious_dragon_state_set_storage : + IsGlobalAlias globals ethereum.spurious_dragon.state.globals "set_storage". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.spurious_dragon.vm.__init__. +Axiom ethereum_spurious_dragon_vm___init___Evm : + IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_SLOAD : - IsGlobalAlias globals gas.globals "GAS_SLOAD". -Axiom gas_GAS_STORAGE_CLEAR_REFUND : - IsGlobalAlias globals gas.globals "GAS_STORAGE_CLEAR_REFUND". -Axiom gas_GAS_STORAGE_SET : - IsGlobalAlias globals gas.globals "GAS_STORAGE_SET". -Axiom gas_GAS_STORAGE_UPDATE : - IsGlobalAlias globals gas.globals "GAS_STORAGE_UPDATE". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.spurious_dragon.vm.gas. +Axiom ethereum_spurious_dragon_vm_gas_GAS_SLOAD : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_SLOAD". +Axiom ethereum_spurious_dragon_vm_gas_GAS_STORAGE_CLEAR_REFUND : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_STORAGE_CLEAR_REFUND". +Axiom ethereum_spurious_dragon_vm_gas_GAS_STORAGE_SET : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_STORAGE_SET". +Axiom ethereum_spurious_dragon_vm_gas_GAS_STORAGE_UPDATE : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_STORAGE_UPDATE". +Axiom ethereum_spurious_dragon_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "charge_gas". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.spurious_dragon.vm.stack. +Axiom ethereum_spurious_dragon_vm_stack_pop : + IsGlobalAlias globals ethereum.spurious_dragon.vm.stack.globals "pop". +Axiom ethereum_spurious_dragon_vm_stack_push : + IsGlobalAlias globals ethereum.spurious_dragon.vm.stack.globals "push". Definition sload : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -146,11 +146,56 @@ Definition sstore : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "new_value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "current_value" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let gas_cost := + M.get_name (| globals, "GAS_STORAGE_SET" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let gas_cost := M.get_name (| globals, "GAS_STORAGE_UPDATE" |) in M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_name (| globals, "new_value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "current_value" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/system.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/system.v index 1bde1ec..a1b98c5 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/system.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/system.v @@ -25,77 +25,77 @@ Axiom ethereum_base_types_Bytes0 : Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.spurious_dragon.fork_types. +Axiom ethereum_spurious_dragon_fork_types_Address : + IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "Address". -Require state. -Axiom state_account_exists_and_is_empty : - IsGlobalAlias globals state.globals "account_exists_and_is_empty". -Axiom state_account_has_code_or_nonce : - IsGlobalAlias globals state.globals "account_has_code_or_nonce". -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". -Axiom state_increment_nonce : - IsGlobalAlias globals state.globals "increment_nonce". -Axiom state_is_account_alive : - IsGlobalAlias globals state.globals "is_account_alive". -Axiom state_set_account_balance : - IsGlobalAlias globals state.globals "set_account_balance". +Require ethereum.spurious_dragon.state. +Axiom ethereum_spurious_dragon_state_account_exists_and_is_empty : + IsGlobalAlias globals ethereum.spurious_dragon.state.globals "account_exists_and_is_empty". +Axiom ethereum_spurious_dragon_state_account_has_code_or_nonce : + IsGlobalAlias globals ethereum.spurious_dragon.state.globals "account_has_code_or_nonce". +Axiom ethereum_spurious_dragon_state_get_account : + IsGlobalAlias globals ethereum.spurious_dragon.state.globals "get_account". +Axiom ethereum_spurious_dragon_state_increment_nonce : + IsGlobalAlias globals ethereum.spurious_dragon.state.globals "increment_nonce". +Axiom ethereum_spurious_dragon_state_is_account_alive : + IsGlobalAlias globals ethereum.spurious_dragon.state.globals "is_account_alive". +Axiom ethereum_spurious_dragon_state_set_account_balance : + IsGlobalAlias globals ethereum.spurious_dragon.state.globals "set_account_balance". -Require utils.address. -Axiom utils_address_compute_contract_address : - IsGlobalAlias globals utils.address.globals "compute_contract_address". -Axiom utils_address_to_address : - IsGlobalAlias globals utils.address.globals "to_address". +Require ethereum.spurious_dragon.utils.address. +Axiom ethereum_spurious_dragon_utils_address_compute_contract_address : + IsGlobalAlias globals ethereum.spurious_dragon.utils.address.globals "compute_contract_address". +Axiom ethereum_spurious_dragon_utils_address_to_address : + IsGlobalAlias globals ethereum.spurious_dragon.utils.address.globals "to_address". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". -Axiom __init___Message : - IsGlobalAlias globals __init__.globals "Message". -Axiom __init___incorporate_child_on_error : - IsGlobalAlias globals __init__.globals "incorporate_child_on_error". -Axiom __init___incorporate_child_on_success : - IsGlobalAlias globals __init__.globals "incorporate_child_on_success". +Require ethereum.spurious_dragon.vm.__init__. +Axiom ethereum_spurious_dragon_vm___init___Evm : + IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "Evm". +Axiom ethereum_spurious_dragon_vm___init___Message : + IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "Message". +Axiom ethereum_spurious_dragon_vm___init___incorporate_child_on_error : + IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "incorporate_child_on_error". +Axiom ethereum_spurious_dragon_vm___init___incorporate_child_on_success : + IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "incorporate_child_on_success". -Require gas. -Axiom gas_GAS_CALL : - IsGlobalAlias globals gas.globals "GAS_CALL". -Axiom gas_GAS_CALL_VALUE : - IsGlobalAlias globals gas.globals "GAS_CALL_VALUE". -Axiom gas_GAS_CREATE : - IsGlobalAlias globals gas.globals "GAS_CREATE". -Axiom gas_GAS_NEW_ACCOUNT : - IsGlobalAlias globals gas.globals "GAS_NEW_ACCOUNT". -Axiom gas_GAS_SELF_DESTRUCT : - IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT". -Axiom gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : - IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". -Axiom gas_GAS_ZERO : - IsGlobalAlias globals gas.globals "GAS_ZERO". -Axiom gas_REFUND_SELF_DESTRUCT : - IsGlobalAlias globals gas.globals "REFUND_SELF_DESTRUCT". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_calculate_message_call_gas : - IsGlobalAlias globals gas.globals "calculate_message_call_gas". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". -Axiom gas_max_message_call_gas : - IsGlobalAlias globals gas.globals "max_message_call_gas". +Require ethereum.spurious_dragon.vm.gas. +Axiom ethereum_spurious_dragon_vm_gas_GAS_CALL : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_CALL". +Axiom ethereum_spurious_dragon_vm_gas_GAS_CALL_VALUE : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_CALL_VALUE". +Axiom ethereum_spurious_dragon_vm_gas_GAS_CREATE : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_CREATE". +Axiom ethereum_spurious_dragon_vm_gas_GAS_NEW_ACCOUNT : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_NEW_ACCOUNT". +Axiom ethereum_spurious_dragon_vm_gas_GAS_SELF_DESTRUCT : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_SELF_DESTRUCT". +Axiom ethereum_spurious_dragon_vm_gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". +Axiom ethereum_spurious_dragon_vm_gas_GAS_ZERO : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_ZERO". +Axiom ethereum_spurious_dragon_vm_gas_REFUND_SELF_DESTRUCT : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "REFUND_SELF_DESTRUCT". +Axiom ethereum_spurious_dragon_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_spurious_dragon_vm_gas_calculate_message_call_gas : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "calculate_message_call_gas". +Axiom ethereum_spurious_dragon_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "charge_gas". +Axiom ethereum_spurious_dragon_vm_gas_max_message_call_gas : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "max_message_call_gas". -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". -Axiom memory_memory_write : - IsGlobalAlias globals memory.globals "memory_write". +Require ethereum.spurious_dragon.vm.memory. +Axiom ethereum_spurious_dragon_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.spurious_dragon.vm.memory.globals "memory_read_bytes". +Axiom ethereum_spurious_dragon_vm_memory_memory_write : + IsGlobalAlias globals ethereum.spurious_dragon.vm.memory.globals "memory_write". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.spurious_dragon.vm.stack. +Axiom ethereum_spurious_dragon_vm_stack_pop : + IsGlobalAlias globals ethereum.spurious_dragon.vm.stack.globals "pop". +Axiom ethereum_spurious_dragon_vm_stack_push : + IsGlobalAlias globals ethereum.spurious_dragon.vm.stack.globals "push". Definition create : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -210,7 +210,105 @@ Definition create : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt (| + M.get_field (| M.get_name (| globals, "sender" |), "balance" |), + M.get_name (| globals, "endowment" |) + |), + ltac:(M.monadic ( + BoolOp.or (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "sender" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.sub (| + BinOp.pow (| + Constant.int 2, + Constant.int 64 + |), + Constant.int 1 + |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.gt (| + BinOp.add (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "depth" |), + Constant.int 1 + |), + M.get_name (| globals, "STACK_DEPTH_LIMIT" |) + |) + )) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "create_message_gas" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "contract_address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let call_data := M.call (| M.get_name (| globals, "memory_read_bytes" |), @@ -245,6 +343,36 @@ Definition create : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "child_evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_error" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "incorporate_child_on_success" |), make_list [ @@ -364,6 +492,42 @@ Definition generic_call : Value.t -> Value.t -> M := " in (* At stmt: unsupported node type: ImportFrom *) let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + BinOp.add (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "depth" |), + Constant.int 1 + |), + M.get_name (| globals, "STACK_DEPTH_LIMIT" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "gas" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let call_data := @@ -401,6 +565,36 @@ Definition generic_call : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "child_evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_error" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "incorporate_child_on_success" |), make_list [ @@ -451,7 +645,7 @@ Definition generic_call : Value.t -> Value.t -> M := make_list [ M.get_field (| M.get_name (| globals, "evm" |), "memory" |); M.get_name (| globals, "memory_output_start_position" |); - M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), Constant.None_:M.get_name (| globals, "actual_output_size" |) |) + M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), M.slice (| Constant.None_, M.get_name (| globals, "actual_output_size" |) |) |) ], make_dict [] |) in @@ -549,49 +743,57 @@ Definition call : Value.t -> Value.t -> M := make_dict [] |) in let create_gas_cost := - (* if *) -M.if_then_else (| - BoolOp.or (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), - ltac:(M.monadic ( - M.call (| - M.get_name (| globals, "is_account_alive" |), - make_list [ - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); - M.get_name (| globals, "to" |) - ], - make_dict [] - |) - )) - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + M.call (| + M.get_name (| globals, "is_account_alive" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "to" |) + ], + make_dict [] + |) + )) + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "GAS_NEW_ACCOUNT" |) + )) |) in let transfer_gas_cost := - (* if *) -M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "GAS_CALL_VALUE" |) + )) |) in let message_call_gas := M.call (| M.get_name (| globals, "calculate_message_call_gas" |), @@ -645,6 +847,36 @@ M.call (| make_dict [] |), "balance" |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "sender_balance" |), + M.get_name (| globals, "value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "generic_call" |), make_list [ @@ -765,21 +997,25 @@ Definition callcode : Value.t -> Value.t -> M := make_dict [] |) in let transfer_gas_cost := - (* if *) -M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "GAS_CALL_VALUE" |) + )) |) in let message_call_gas := M.call (| M.get_name (| globals, "calculate_message_call_gas" |), @@ -830,6 +1066,36 @@ M.call (| make_dict [] |), "balance" |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "sender_balance" |), + M.get_name (| globals, "value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "generic_call" |), make_list [ @@ -884,6 +1150,39 @@ Definition selfdestruct : Value.t -> Value.t -> M := let gas_cost := M.get_name (| globals, "GAS_SELF_DESTRUCT" |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + UnOp.not (| M.call (| + M.get_name (| globals, "is_account_alive" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |) |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |), "balance" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) + M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let originator := @@ -907,6 +1206,22 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in EndWhile. let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "originator" |), + M.get_name (| globals, "refunded_accounts" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.get_name (| globals, "REFUND_SELF_DESTRUCT" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -970,6 +1285,28 @@ Definition selfdestruct : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/interpreter.v b/CoqOfPython/ethereum/spurious_dragon/vm/interpreter.v index 259dc56..78aae7a 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/interpreter.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/interpreter.v @@ -61,77 +61,77 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". - -Require state. -Axiom state_account_exists_and_is_empty : - IsGlobalAlias globals state.globals "account_exists_and_is_empty". -Axiom state_account_has_code_or_nonce : - IsGlobalAlias globals state.globals "account_has_code_or_nonce". -Axiom state_begin_transaction : - IsGlobalAlias globals state.globals "begin_transaction". -Axiom state_commit_transaction : - IsGlobalAlias globals state.globals "commit_transaction". -Axiom state_destroy_storage : - IsGlobalAlias globals state.globals "destroy_storage". -Axiom state_increment_nonce : - IsGlobalAlias globals state.globals "increment_nonce". -Axiom state_move_ether : - IsGlobalAlias globals state.globals "move_ether". -Axiom state_rollback_transaction : - IsGlobalAlias globals state.globals "rollback_transaction". -Axiom state_set_code : - IsGlobalAlias globals state.globals "set_code". -Axiom state_touch_account : - IsGlobalAlias globals state.globals "touch_account". - -Require vm. -Axiom vm_Message : - IsGlobalAlias globals vm.globals "Message". - -Require vm.gas. -Axiom vm_gas_GAS_CODE_DEPOSIT : - IsGlobalAlias globals vm.gas.globals "GAS_CODE_DEPOSIT". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". - -Require vm.precompiled_contracts.mapping. -Axiom vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : - IsGlobalAlias globals vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". - -Require __init__. -Axiom __init___Environment : - IsGlobalAlias globals __init__.globals "Environment". -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require exceptions. -Axiom exceptions_AddressCollision : - IsGlobalAlias globals exceptions.globals "AddressCollision". -Axiom exceptions_ExceptionalHalt : - IsGlobalAlias globals exceptions.globals "ExceptionalHalt". -Axiom exceptions_InvalidOpcode : - IsGlobalAlias globals exceptions.globals "InvalidOpcode". -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". -Axiom exceptions_StackDepthLimitError : - IsGlobalAlias globals exceptions.globals "StackDepthLimitError". - -Require instructions. -Axiom instructions_Ops : - IsGlobalAlias globals instructions.globals "Ops". -Axiom instructions_op_implementation : - IsGlobalAlias globals instructions.globals "op_implementation". - -Require runtime. -Axiom runtime_get_valid_jump_destinations : - IsGlobalAlias globals runtime.globals "get_valid_jump_destinations". +Require ethereum.spurious_dragon.blocks. +Axiom ethereum_spurious_dragon_blocks_Log : + IsGlobalAlias globals ethereum.spurious_dragon.blocks.globals "Log". + +Require ethereum.spurious_dragon.fork_types. +Axiom ethereum_spurious_dragon_fork_types_Address : + IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "Address". + +Require ethereum.spurious_dragon.state. +Axiom ethereum_spurious_dragon_state_account_exists_and_is_empty : + IsGlobalAlias globals ethereum.spurious_dragon.state.globals "account_exists_and_is_empty". +Axiom ethereum_spurious_dragon_state_account_has_code_or_nonce : + IsGlobalAlias globals ethereum.spurious_dragon.state.globals "account_has_code_or_nonce". +Axiom ethereum_spurious_dragon_state_begin_transaction : + IsGlobalAlias globals ethereum.spurious_dragon.state.globals "begin_transaction". +Axiom ethereum_spurious_dragon_state_commit_transaction : + IsGlobalAlias globals ethereum.spurious_dragon.state.globals "commit_transaction". +Axiom ethereum_spurious_dragon_state_destroy_storage : + IsGlobalAlias globals ethereum.spurious_dragon.state.globals "destroy_storage". +Axiom ethereum_spurious_dragon_state_increment_nonce : + IsGlobalAlias globals ethereum.spurious_dragon.state.globals "increment_nonce". +Axiom ethereum_spurious_dragon_state_move_ether : + IsGlobalAlias globals ethereum.spurious_dragon.state.globals "move_ether". +Axiom ethereum_spurious_dragon_state_rollback_transaction : + IsGlobalAlias globals ethereum.spurious_dragon.state.globals "rollback_transaction". +Axiom ethereum_spurious_dragon_state_set_code : + IsGlobalAlias globals ethereum.spurious_dragon.state.globals "set_code". +Axiom ethereum_spurious_dragon_state_touch_account : + IsGlobalAlias globals ethereum.spurious_dragon.state.globals "touch_account". + +Require ethereum.spurious_dragon.vm.__init__. +Axiom ethereum_spurious_dragon_vm___init___Message : + IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "Message". + +Require ethereum.spurious_dragon.vm.gas. +Axiom ethereum_spurious_dragon_vm_gas_GAS_CODE_DEPOSIT : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_CODE_DEPOSIT". +Axiom ethereum_spurious_dragon_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "charge_gas". + +Require ethereum.spurious_dragon.vm.precompiled_contracts.mapping. +Axiom ethereum_spurious_dragon_vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : + IsGlobalAlias globals ethereum.spurious_dragon.vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". + +Require ethereum.spurious_dragon.vm.__init__. +Axiom ethereum_spurious_dragon_vm___init___Environment : + IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "Environment". +Axiom ethereum_spurious_dragon_vm___init___Evm : + IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "Evm". + +Require ethereum.spurious_dragon.vm.exceptions. +Axiom ethereum_spurious_dragon_vm_exceptions_AddressCollision : + IsGlobalAlias globals ethereum.spurious_dragon.vm.exceptions.globals "AddressCollision". +Axiom ethereum_spurious_dragon_vm_exceptions_ExceptionalHalt : + IsGlobalAlias globals ethereum.spurious_dragon.vm.exceptions.globals "ExceptionalHalt". +Axiom ethereum_spurious_dragon_vm_exceptions_InvalidOpcode : + IsGlobalAlias globals ethereum.spurious_dragon.vm.exceptions.globals "InvalidOpcode". +Axiom ethereum_spurious_dragon_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.spurious_dragon.vm.exceptions.globals "OutOfGasError". +Axiom ethereum_spurious_dragon_vm_exceptions_StackDepthLimitError : + IsGlobalAlias globals ethereum.spurious_dragon.vm.exceptions.globals "StackDepthLimitError". + +Require ethereum.spurious_dragon.vm.instructions.__init__. +Axiom ethereum_spurious_dragon_vm_instructions___init___Ops : + IsGlobalAlias globals ethereum.spurious_dragon.vm.instructions.__init__.globals "Ops". +Axiom ethereum_spurious_dragon_vm_instructions___init___op_implementation : + IsGlobalAlias globals ethereum.spurious_dragon.vm.instructions.__init__.globals "op_implementation". + +Require ethereum.spurious_dragon.vm.runtime. +Axiom ethereum_spurious_dragon_vm_runtime_get_valid_jump_destinations : + IsGlobalAlias globals ethereum.spurious_dragon.vm.runtime.globals "get_valid_jump_destinations". Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -178,6 +178,94 @@ Definition process_message_call : Value.t -> Value.t -> M := Output of the message call " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "message" |), "target" |), + M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) + |), + (* then *) + ltac:(M.monadic ( + let is_collision := + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_name (| globals, "is_collision" |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallOutput" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "tuple" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "AddressCollision" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let evm := + M.call (| + M.get_name (| globals, "process_create_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let evm := M.call (| M.get_name (| globals, "process_message" |), @@ -188,11 +276,74 @@ Definition process_message_call : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_field (| M.get_name (| globals, "message" |), "target" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |), "add" |), + make_list [ + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_field (| M.get_name (| globals, "message" |), "target" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( +(* At stmt: unsupported node type: AnnAssign *) + let accounts_to_delete := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let touched_accounts := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let refund_counter := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let logs := M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in let accounts_to_delete := @@ -230,6 +381,7 @@ Definition process_message_call : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). Definition process_create_message : Value.t -> Value.t -> M := @@ -283,6 +435,28 @@ Definition process_create_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), + (* then *) + ltac:(M.monadic ( + let contract_code := + M.get_field (| M.get_name (| globals, "evm" |), "output" |) in + let contract_code_gas := + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "contract_code" |) + ], + make_dict [] + |), + M.get_name (| globals, "GAS_CODE_DEPOSIT" |) + |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "rollback_transaction" |), make_list [ @@ -294,6 +468,7 @@ Definition process_create_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) + |) in M.pure Constant.None_)). Definition process_message : Value.t -> Value.t -> M := @@ -315,6 +490,24 @@ Definition process_message : Value.t -> Value.t -> M := Items containing execution specific objects " in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_field (| M.get_name (| globals, "message" |), "depth" |), + M.get_name (| globals, "STACK_DEPTH_LIMIT" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "StackDepthLimitError" |), + make_list [ + Constant.str "Stack depth limit reached" + ], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -333,6 +526,32 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + M.get_field (| M.get_name (| globals, "message" |), "should_transfer_value" |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "message" |), "value" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "move_ether" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "caller" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |); + M.get_field (| M.get_name (| globals, "message" |), "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let evm := @@ -345,6 +564,21 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "rollback_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "commit_transaction" |), make_list [ @@ -356,6 +590,7 @@ Definition process_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) + |) in M.pure Constant.None_)). Definition execute_code : Value.t -> Value.t -> M := @@ -395,4 +630,5 @@ Definition execute_code : Value.t -> Value.t -> M := (* At stmt: unsupported node type: Try *) let _ := M.return_ (| M.get_name (| globals, "evm" |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/memory.v b/CoqOfPython/ethereum/spurious_dragon/vm/memory.v index 4b107fd..08d2290 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/memory.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/memory.v @@ -21,13 +21,13 @@ Require ethereum.utils.byte. Axiom ethereum_utils_byte_right_pad_zero_bytes : IsGlobalAlias globals ethereum.utils.byte.globals "right_pad_zero_bytes". -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". Definition memory_write : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,7 +45,22 @@ Definition memory_write : Value.t -> Value.t -> M := Data to write to memory. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |), + M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) |) |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_)). @@ -71,7 +86,23 @@ Definition memory_read_bytes : Value.t -> Value.t -> M := Data read from memory. " in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |) + M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |) |) + |) in M.pure Constant.None_)). Definition buffer_read : Value.t -> Value.t -> M := @@ -98,9 +129,25 @@ Definition buffer_read : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "right_pad_zero_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |) |); + M.get_subscript (| M.get_name (| globals, "buffer" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |) |); M.get_name (| globals, "size" |) ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/__init__.v index 422f670..8d64b76 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/__init__.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/__init__.v @@ -18,9 +18,9 @@ Addresses of precompiled contracts and mappings to their implementations. ". -Require utils.hexadecimal. -Axiom utils_hexadecimal_hex_to_address : - IsGlobalAlias globals utils.hexadecimal.globals "hex_to_address". +Require ethereum.spurious_dragon.utils.hexadecimal. +Axiom ethereum_spurious_dragon_utils_hexadecimal_hex_to_address : + IsGlobalAlias globals ethereum.spurious_dragon.utils.hexadecimal.globals "hex_to_address". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS" ] diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/ecrecover.v index 0cbcf16..c304229 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/ecrecover.v @@ -37,19 +37,19 @@ Require ethereum.utils.byte. Axiom ethereum_utils_byte_left_pad_zero_bytes : IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.spurious_dragon.vm.__init__. +Axiom ethereum_spurious_dragon_vm___init___Evm : + IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_ECRECOVER : - IsGlobalAlias globals vm.gas.globals "GAS_ECRECOVER". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.spurious_dragon.vm.gas. +Axiom ethereum_spurious_dragon_vm_gas_GAS_ECRECOVER : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_ECRECOVER". +Axiom ethereum_spurious_dragon_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "charge_gas". -Require vm.memory. -Axiom vm_memory_buffer_read : - IsGlobalAlias globals vm.memory.globals "buffer_read". +Require ethereum.spurious_dragon.vm.memory. +Axiom ethereum_spurious_dragon_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.spurious_dragon.vm.memory.globals "buffer_read". Definition ecrecover : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -188,12 +188,78 @@ Definition ecrecover : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "v" |), + Constant.int 27 + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "v" |), + Constant.int 28 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + Constant.int 0, + M.get_name (| globals, "r" |) + |), + ltac:(M.monadic ( + Compare.gt_e (| + M.get_name (| globals, "r" |), + M.get_name (| globals, "SECP256K1N" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + Constant.int 0, + M.get_name (| globals, "s" |) + |), + ltac:(M.monadic ( + Compare.gt_e (| + M.get_name (| globals, "s" |), + M.get_name (| globals, "SECP256K1N" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: Try *) @@ -204,7 +270,7 @@ Definition ecrecover : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12 |) in + |), M.slice (| Constant.int 12, Constant.int 32 |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/identity.v index fa96704..a3cf5a9 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/identity.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/identity.v @@ -25,17 +25,17 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.spurious_dragon.vm.__init__. +Axiom ethereum_spurious_dragon_vm___init___Evm : + IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_IDENTITY : - IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY". -Axiom vm_gas_GAS_IDENTITY_WORD : - IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY_WORD". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.spurious_dragon.vm.gas. +Axiom ethereum_spurious_dragon_vm_gas_GAS_IDENTITY : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_IDENTITY". +Axiom ethereum_spurious_dragon_vm_gas_GAS_IDENTITY_WORD : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_IDENTITY_WORD". +Axiom ethereum_spurious_dragon_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "charge_gas". Definition identity : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/mapping.v index 710457d..b0e598a 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/mapping.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/mapping.v @@ -23,34 +23,34 @@ Axiom typing_Callable : Axiom typing_Dict : IsGlobalAlias globals typing.globals "Dict". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". - -Require __init__. -Axiom __init___ECRECOVER_ADDRESS : - IsGlobalAlias globals __init__.globals "ECRECOVER_ADDRESS". -Axiom __init___IDENTITY_ADDRESS : - IsGlobalAlias globals __init__.globals "IDENTITY_ADDRESS". -Axiom __init___RIPEMD160_ADDRESS : - IsGlobalAlias globals __init__.globals "RIPEMD160_ADDRESS". -Axiom __init___SHA256_ADDRESS : - IsGlobalAlias globals __init__.globals "SHA256_ADDRESS". - -Require ecrecover. -Axiom ecrecover_ecrecover : - IsGlobalAlias globals ecrecover.globals "ecrecover". - -Require identity. -Axiom identity_identity : - IsGlobalAlias globals identity.globals "identity". - -Require ripemd160. -Axiom ripemd160_ripemd160 : - IsGlobalAlias globals ripemd160.globals "ripemd160". - -Require sha256. -Axiom sha256_sha256 : - IsGlobalAlias globals sha256.globals "sha256". +Require ethereum.spurious_dragon.fork_types. +Axiom ethereum_spurious_dragon_fork_types_Address : + IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "Address". + +Require ethereum.spurious_dragon.vm.precompiled_contracts.__init__. +Axiom ethereum_spurious_dragon_vm_precompiled_contracts___init___ECRECOVER_ADDRESS : + IsGlobalAlias globals ethereum.spurious_dragon.vm.precompiled_contracts.__init__.globals "ECRECOVER_ADDRESS". +Axiom ethereum_spurious_dragon_vm_precompiled_contracts___init___IDENTITY_ADDRESS : + IsGlobalAlias globals ethereum.spurious_dragon.vm.precompiled_contracts.__init__.globals "IDENTITY_ADDRESS". +Axiom ethereum_spurious_dragon_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : + IsGlobalAlias globals ethereum.spurious_dragon.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". +Axiom ethereum_spurious_dragon_vm_precompiled_contracts___init___SHA256_ADDRESS : + IsGlobalAlias globals ethereum.spurious_dragon.vm.precompiled_contracts.__init__.globals "SHA256_ADDRESS". + +Require ethereum.spurious_dragon.vm.precompiled_contracts.ecrecover. +Axiom ethereum_spurious_dragon_vm_precompiled_contracts_ecrecover_ecrecover : + IsGlobalAlias globals ethereum.spurious_dragon.vm.precompiled_contracts.ecrecover.globals "ecrecover". + +Require ethereum.spurious_dragon.vm.precompiled_contracts.identity. +Axiom ethereum_spurious_dragon_vm_precompiled_contracts_identity_identity : + IsGlobalAlias globals ethereum.spurious_dragon.vm.precompiled_contracts.identity.globals "identity". + +Require ethereum.spurious_dragon.vm.precompiled_contracts.ripemd160. +Axiom ethereum_spurious_dragon_vm_precompiled_contracts_ripemd160_ripemd160 : + IsGlobalAlias globals ethereum.spurious_dragon.vm.precompiled_contracts.ripemd160.globals "ripemd160". + +Require ethereum.spurious_dragon.vm.precompiled_contracts.sha256. +Axiom ethereum_spurious_dragon_vm_precompiled_contracts_sha256_sha256 : + IsGlobalAlias globals ethereum.spurious_dragon.vm.precompiled_contracts.sha256.globals "sha256". (* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/ripemd160.v index 96f8dcd..a6246db 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/ripemd160.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/ripemd160.v @@ -31,17 +31,17 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.spurious_dragon.vm.__init__. +Axiom ethereum_spurious_dragon_vm___init___Evm : + IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_RIPEMD160 : - IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160". -Axiom vm_gas_GAS_RIPEMD160_WORD : - IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160_WORD". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.spurious_dragon.vm.gas. +Axiom ethereum_spurious_dragon_vm_gas_GAS_RIPEMD160 : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_RIPEMD160". +Axiom ethereum_spurious_dragon_vm_gas_GAS_RIPEMD160_WORD : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_RIPEMD160_WORD". +Axiom ethereum_spurious_dragon_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "charge_gas". Definition ripemd160 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/sha256.v index 9f6d2bf..fd8aa4b 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/sha256.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/sha256.v @@ -27,17 +27,17 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.spurious_dragon.vm.__init__. +Axiom ethereum_spurious_dragon_vm___init___Evm : + IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_SHA256 : - IsGlobalAlias globals vm.gas.globals "GAS_SHA256". -Axiom vm_gas_GAS_SHA256_WORD : - IsGlobalAlias globals vm.gas.globals "GAS_SHA256_WORD". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.spurious_dragon.vm.gas. +Axiom ethereum_spurious_dragon_vm_gas_GAS_SHA256 : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_SHA256". +Axiom ethereum_spurious_dragon_vm_gas_GAS_SHA256_WORD : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_SHA256_WORD". +Axiom ethereum_spurious_dragon_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "charge_gas". Definition sha256 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/runtime.v b/CoqOfPython/ethereum/spurious_dragon/vm/runtime.v index 2cd7652..70b1b41 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/runtime.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/runtime.v @@ -25,9 +25,9 @@ Require ethereum.base_types. Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require instructions. -Axiom instructions_Ops : - IsGlobalAlias globals instructions.globals "Ops". +Require ethereum.spurious_dragon.vm.instructions.__init__. +Axiom ethereum_spurious_dragon_vm_instructions___init___Ops : + IsGlobalAlias globals ethereum.spurious_dragon.vm.instructions.__init__.globals "Ops". Definition get_valid_jump_destinations : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -79,7 +79,55 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := |) do (* At stmt: unsupported node type: Try *) let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "current_opcode" |), + M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), + make_list [ + M.get_name (| globals, "pc" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.lt_e (| + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |), + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH32" |), "value" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let push_data_size := + BinOp.add (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) + |), + Constant.int 1 + |) in + let pc := BinOp.add + M.get_name (| globals, "push_data_size" |) + M.get_name (| globals, "push_data_size" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -90,4 +138,5 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := EndWhile. let _ := M.return_ (| M.get_name (| globals, "valid_jump_destinations" |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/stack.v b/CoqOfPython/ethereum/spurious_dragon/vm/stack.v index ea778df..1c3b5a2 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/stack.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/stack.v @@ -25,11 +25,11 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require exceptions. -Axiom exceptions_StackOverflowError : - IsGlobalAlias globals exceptions.globals "StackOverflowError". -Axiom exceptions_StackUnderflowError : - IsGlobalAlias globals exceptions.globals "StackUnderflowError". +Require ethereum.spurious_dragon.vm.exceptions. +Axiom ethereum_spurious_dragon_vm_exceptions_StackOverflowError : + IsGlobalAlias globals ethereum.spurious_dragon.vm.exceptions.globals "StackOverflowError". +Axiom ethereum_spurious_dragon_vm_exceptions_StackUnderflowError : + IsGlobalAlias globals ethereum.spurious_dragon.vm.exceptions.globals "StackUnderflowError". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -49,6 +49,24 @@ Definition pop : Value.t -> Value.t -> M := " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "StackUnderflowError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -57,6 +75,7 @@ Definition pop : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). Definition push : Value.t -> Value.t -> M := @@ -75,6 +94,24 @@ Definition push : Value.t -> Value.t -> M := " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), + Constant.int 1024 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "StackOverflowError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -85,4 +122,5 @@ Definition push : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/blocks.v b/CoqOfPython/ethereum/tangerine_whistle/blocks.v index 6501788..57ca486 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/blocks.v +++ b/CoqOfPython/ethereum/tangerine_whistle/blocks.v @@ -22,35 +22,35 @@ Require typing. Axiom typing_Tuple : IsGlobalAlias globals typing.globals "Tuple". -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes8 : - IsGlobalAlias globals base_types.globals "Bytes8". -Axiom base_types_Bytes32 : - IsGlobalAlias globals base_types.globals "Bytes32". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require crypto.hash. -Axiom crypto_hash_Hash32 : - IsGlobalAlias globals crypto.hash.globals "Hash32". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". - -Require transactions. -Axiom transactions_Transaction : - IsGlobalAlias globals transactions.globals "Transaction". +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes8 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes8". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". + +Require ethereum.tangerine_whistle.fork_types. +Axiom ethereum_tangerine_whistle_fork_types_Address : + IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "Address". +Axiom ethereum_tangerine_whistle_fork_types_Bloom : + IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "Bloom". +Axiom ethereum_tangerine_whistle_fork_types_Root : + IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "Root". + +Require ethereum.tangerine_whistle.transactions. +Axiom ethereum_tangerine_whistle_transactions_Transaction : + IsGlobalAlias globals ethereum.tangerine_whistle.transactions.globals "Transaction". Definition Header : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/tangerine_whistle/bloom.v b/CoqOfPython/ethereum/tangerine_whistle/bloom.v index 04650ff..4c9e15e 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/bloom.v +++ b/CoqOfPython/ethereum/tangerine_whistle/bloom.v @@ -33,13 +33,13 @@ Require ethereum.crypto.hash. Axiom ethereum_crypto_hash_keccak256 : IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". +Require ethereum.tangerine_whistle.blocks. +Axiom ethereum_tangerine_whistle_blocks_Log : + IsGlobalAlias globals ethereum.tangerine_whistle.blocks.globals "Log". -Require fork_types. -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". +Require ethereum.tangerine_whistle.fork_types. +Axiom ethereum_tangerine_whistle_fork_types_Bloom : + IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "Bloom". Definition add_to_bloom : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -72,7 +72,10 @@ Definition add_to_bloom : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "hash" |), M.get_name (| globals, "idx" |) |) + M.get_subscript (| M.get_name (| globals, "hash" |), M.slice (| M.get_name (| globals, "idx" |), BinOp.add (| + M.get_name (| globals, "idx" |), + Constant.int 2 + |) |) |) ], make_dict [] |), @@ -157,4 +160,5 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/fork.v b/CoqOfPython/ethereum/tangerine_whistle/fork.v index 245eaa1..c59f022 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/fork.v +++ b/CoqOfPython/ethereum/tangerine_whistle/fork.v @@ -63,93 +63,93 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U64 : - IsGlobalAlias globals base_types.globals "U64". -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_U256_CEIL_VALUE : - IsGlobalAlias globals base_types.globals "U256_CEIL_VALUE". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes32 : - IsGlobalAlias globals base_types.globals "Bytes32". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". - -Require __init__. -Axiom __init___vm : - IsGlobalAlias globals __init__.globals "vm". - -Require blocks. -Axiom blocks_Block : - IsGlobalAlias globals blocks.globals "Block". -Axiom blocks_Header : - IsGlobalAlias globals blocks.globals "Header". -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". -Axiom blocks_Receipt : - IsGlobalAlias globals blocks.globals "Receipt". - -Require bloom. -Axiom bloom_logs_bloom : - IsGlobalAlias globals bloom.globals "logs_bloom". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". - -Require state. -Axiom state_State : - IsGlobalAlias globals state.globals "State". -Axiom state_create_ether : - IsGlobalAlias globals state.globals "create_ether". -Axiom state_destroy_account : - IsGlobalAlias globals state.globals "destroy_account". -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". -Axiom state_increment_nonce : - IsGlobalAlias globals state.globals "increment_nonce". -Axiom state_set_account_balance : - IsGlobalAlias globals state.globals "set_account_balance". -Axiom state_state_root : - IsGlobalAlias globals state.globals "state_root". - -Require transactions. -Axiom transactions_TX_BASE_COST : - IsGlobalAlias globals transactions.globals "TX_BASE_COST". -Axiom transactions_TX_CREATE_COST : - IsGlobalAlias globals transactions.globals "TX_CREATE_COST". -Axiom transactions_TX_DATA_COST_PER_NON_ZERO : - IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_NON_ZERO". -Axiom transactions_TX_DATA_COST_PER_ZERO : - IsGlobalAlias globals transactions.globals "TX_DATA_COST_PER_ZERO". -Axiom transactions_Transaction : - IsGlobalAlias globals transactions.globals "Transaction". - -Require trie. -Axiom trie_Trie : - IsGlobalAlias globals trie.globals "Trie". -Axiom trie_root : - IsGlobalAlias globals trie.globals "root". -Axiom trie_trie_set : - IsGlobalAlias globals trie.globals "trie_set". - -Require utils.message. -Axiom utils_message_prepare_message : - IsGlobalAlias globals utils.message.globals "prepare_message". - -Require vm.interpreter. -Axiom vm_interpreter_process_message_call : - IsGlobalAlias globals vm.interpreter.globals "process_message_call". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U64 : + IsGlobalAlias globals ethereum.base_types.globals "U64". +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_U256_CEIL_VALUE : + IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes32 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". + +Require ethereum.tangerine_whistle.__init__. +Axiom ethereum_tangerine_whistle___init___vm : + IsGlobalAlias globals ethereum.tangerine_whistle.__init__.globals "vm". + +Require ethereum.tangerine_whistle.blocks. +Axiom ethereum_tangerine_whistle_blocks_Block : + IsGlobalAlias globals ethereum.tangerine_whistle.blocks.globals "Block". +Axiom ethereum_tangerine_whistle_blocks_Header : + IsGlobalAlias globals ethereum.tangerine_whistle.blocks.globals "Header". +Axiom ethereum_tangerine_whistle_blocks_Log : + IsGlobalAlias globals ethereum.tangerine_whistle.blocks.globals "Log". +Axiom ethereum_tangerine_whistle_blocks_Receipt : + IsGlobalAlias globals ethereum.tangerine_whistle.blocks.globals "Receipt". + +Require ethereum.tangerine_whistle.bloom. +Axiom ethereum_tangerine_whistle_bloom_logs_bloom : + IsGlobalAlias globals ethereum.tangerine_whistle.bloom.globals "logs_bloom". + +Require ethereum.tangerine_whistle.fork_types. +Axiom ethereum_tangerine_whistle_fork_types_Address : + IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "Address". +Axiom ethereum_tangerine_whistle_fork_types_Bloom : + IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "Bloom". +Axiom ethereum_tangerine_whistle_fork_types_Root : + IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "Root". + +Require ethereum.tangerine_whistle.state. +Axiom ethereum_tangerine_whistle_state_State : + IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "State". +Axiom ethereum_tangerine_whistle_state_create_ether : + IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "create_ether". +Axiom ethereum_tangerine_whistle_state_destroy_account : + IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "destroy_account". +Axiom ethereum_tangerine_whistle_state_get_account : + IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "get_account". +Axiom ethereum_tangerine_whistle_state_increment_nonce : + IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "increment_nonce". +Axiom ethereum_tangerine_whistle_state_set_account_balance : + IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "set_account_balance". +Axiom ethereum_tangerine_whistle_state_state_root : + IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "state_root". + +Require ethereum.tangerine_whistle.transactions. +Axiom ethereum_tangerine_whistle_transactions_TX_BASE_COST : + IsGlobalAlias globals ethereum.tangerine_whistle.transactions.globals "TX_BASE_COST". +Axiom ethereum_tangerine_whistle_transactions_TX_CREATE_COST : + IsGlobalAlias globals ethereum.tangerine_whistle.transactions.globals "TX_CREATE_COST". +Axiom ethereum_tangerine_whistle_transactions_TX_DATA_COST_PER_NON_ZERO : + IsGlobalAlias globals ethereum.tangerine_whistle.transactions.globals "TX_DATA_COST_PER_NON_ZERO". +Axiom ethereum_tangerine_whistle_transactions_TX_DATA_COST_PER_ZERO : + IsGlobalAlias globals ethereum.tangerine_whistle.transactions.globals "TX_DATA_COST_PER_ZERO". +Axiom ethereum_tangerine_whistle_transactions_Transaction : + IsGlobalAlias globals ethereum.tangerine_whistle.transactions.globals "Transaction". + +Require ethereum.tangerine_whistle.trie. +Axiom ethereum_tangerine_whistle_trie_Trie : + IsGlobalAlias globals ethereum.tangerine_whistle.trie.globals "Trie". +Axiom ethereum_tangerine_whistle_trie_root : + IsGlobalAlias globals ethereum.tangerine_whistle.trie.globals "root". +Axiom ethereum_tangerine_whistle_trie_trie_set : + IsGlobalAlias globals ethereum.tangerine_whistle.trie.globals "trie_set". + +Require ethereum.tangerine_whistle.utils.message. +Axiom ethereum_tangerine_whistle_utils_message_prepare_message : + IsGlobalAlias globals ethereum.tangerine_whistle.utils.message.globals "prepare_message". + +Require ethereum.tangerine_whistle.vm.interpreter. +Axiom ethereum_tangerine_whistle_vm_interpreter_process_message_call : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.interpreter.globals "process_message_call". Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -222,6 +222,7 @@ Definition apply_fork : Value.t -> Value.t -> M := " in let _ := M.return_ (| M.get_name (| globals, "old" |) + |) in M.pure Constant.None_)). Definition get_last_256_block_hashes : Value.t -> Value.t -> M := @@ -247,8 +248,28 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := Hashes of the recent 256 blocks in order of increasing block number. " in let recent_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |) |) in + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "recent_blocks" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + make_list [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let recent_block_hashes := @@ -287,6 +308,7 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "recent_block_hashes" |) + |) in M.pure Constant.None_)). Definition state_transition : Value.t -> Value.t -> M := @@ -417,6 +439,27 @@ Definition state_transition : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |) + ], + make_dict [] + |), + Constant.int 255 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -603,6 +646,7 @@ Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition validate_proof_of_work : Value.t -> Value.t -> M := @@ -734,6 +778,7 @@ Definition check_transaction : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "sender_address" |) + |) in M.pure Constant.None_)). Definition make_receipt : Value.t -> Value.t -> M := @@ -767,6 +812,7 @@ Definition make_receipt : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "receipt" |) + |) in M.pure Constant.None_)). Definition ApplyBodyOutput : Value.t := @@ -980,6 +1026,7 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition validate_ommers : Value.t -> Value.t -> M := @@ -1032,6 +1079,26 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do @@ -1089,7 +1156,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let ommers_hashes := - (* At expr: unsupported node type: ListComp *) in + Constant.str "(* At expr: unsupported node type: ListComp *)" in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1120,19 +1187,19 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let recent_canonical_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| BinOp.add (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| BinOp.add (| M.get_name (| globals, "MAX_OMMER_DEPTH" |), Constant.int 1 - |) |) |) in + |) |), Constant.None_ |) |) in let recent_canonical_block_hashes := - (* At expr: unsupported node type: SetComp *) in + Constant.str "(* At expr: unsupported node type: SetComp *)" in (* At stmt: unsupported node type: AnnAssign *) For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_canonical_blocks" |) do let recent_ommers_hashes := M.call (| M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), make_list [ - (* At expr: unsupported node type: SetComp *) + Constant.str "(* At expr: unsupported node type: SetComp *)" ], make_dict [] |) in @@ -1566,6 +1633,7 @@ Definition process_transaction : Value.t -> Value.t -> M := EndFor. let _ := M.return_ (| make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |) ] + |) in M.pure Constant.None_)). Definition validate_transaction : Value.t -> Value.t -> M := @@ -1620,6 +1688,7 @@ Definition validate_transaction : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := @@ -1651,6 +1720,20 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := Constant.int 0 in For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "byte" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let data_cost := BinOp.add M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in @@ -1658,6 +1741,25 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := )) |) in EndFor. let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "tx" |), "to" |), + M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) + |), + (* then *) + ltac:(M.monadic ( + let create_cost := + M.get_name (| globals, "TX_CREATE_COST" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let create_cost := Constant.int 0 in M.pure Constant.None_ @@ -1676,6 +1778,7 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition recover_sender : Value.t -> Value.t -> M := @@ -1794,10 +1897,11 @@ Definition recover_sender : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12 |) + |), M.slice (| Constant.int 12, Constant.int 32 |) |) ], make_dict [] |) + |) in M.pure Constant.None_)). Definition signing_hash : Value.t -> Value.t -> M := @@ -1834,6 +1938,7 @@ Definition signing_hash : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition compute_header_hash : Value.t -> Value.t -> M := @@ -1884,6 +1989,7 @@ Definition compute_header_hash : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition check_gas_limit : Value.t -> Value.t -> M := @@ -1922,16 +2028,65 @@ Definition check_gas_limit : Value.t -> Value.t -> M := M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "gas_limit" |), + BinOp.add (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "gas_limit" |), + BinOp.sub (| + M.get_name (| globals, "parent_gas_limit" |), + M.get_name (| globals, "max_adjustment_delta" |) + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "gas_limit" |), + M.get_name (| globals, "GAS_LIMIT_MINIMUM" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| Constant.bool true + |) in M.pure Constant.None_)). Definition calculate_block_difficulty : Value.t -> Value.t -> M := @@ -2035,6 +2190,26 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := Constant.int 2 |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "num_bomb_periods" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let difficulty := BinOp.add + BinOp.pow (| + Constant.int 2, + M.get_name (| globals, "num_bomb_periods" |) + |) + BinOp.pow (| + Constant.int 2, + M.get_name (| globals, "num_bomb_periods" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -2052,4 +2227,5 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/fork_types.v b/CoqOfPython/ethereum/tangerine_whistle/fork_types.v index 5c7dac3..cc8e4a1 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/fork_types.v +++ b/CoqOfPython/ethereum/tangerine_whistle/fork_types.v @@ -21,29 +21,29 @@ Require dataclasses. Axiom dataclasses_dataclass : IsGlobalAlias globals dataclasses.globals "dataclass". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes20 : - IsGlobalAlias globals base_types.globals "Bytes20". -Axiom base_types_Bytes256 : - IsGlobalAlias globals base_types.globals "Bytes256". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require crypto.hash. -Axiom crypto_hash_Hash32 : - IsGlobalAlias globals crypto.hash.globals "Hash32". -Axiom crypto_hash_keccak256 : - IsGlobalAlias globals crypto.hash.globals "keccak256". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes20 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes20". +Axiom ethereum_base_types_Bytes256 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes256". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.crypto.hash. +Axiom ethereum_crypto_hash_Hash32 : + IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_keccak256 : + IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) @@ -98,4 +98,5 @@ Definition encode_account : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/state.v b/CoqOfPython/ethereum/tangerine_whistle/state.v index 2ba095e..3b6122d 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/state.v +++ b/CoqOfPython/ethereum/tangerine_whistle/state.v @@ -54,29 +54,29 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require fork_types. -Axiom fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals fork_types.globals "EMPTY_ACCOUNT". -Axiom fork_types_Account : - IsGlobalAlias globals fork_types.globals "Account". -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". - -Require trie. -Axiom trie_EMPTY_TRIE_ROOT : - IsGlobalAlias globals trie.globals "EMPTY_TRIE_ROOT". -Axiom trie_Trie : - IsGlobalAlias globals trie.globals "Trie". -Axiom trie_copy_trie : - IsGlobalAlias globals trie.globals "copy_trie". -Axiom trie_root : - IsGlobalAlias globals trie.globals "root". -Axiom trie_trie_get : - IsGlobalAlias globals trie.globals "trie_get". -Axiom trie_trie_set : - IsGlobalAlias globals trie.globals "trie_set". +Require ethereum.tangerine_whistle.fork_types. +Axiom ethereum_tangerine_whistle_fork_types_EMPTY_ACCOUNT : + IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "EMPTY_ACCOUNT". +Axiom ethereum_tangerine_whistle_fork_types_Account : + IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "Account". +Axiom ethereum_tangerine_whistle_fork_types_Address : + IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "Address". +Axiom ethereum_tangerine_whistle_fork_types_Root : + IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "Root". + +Require ethereum.tangerine_whistle.trie. +Axiom ethereum_tangerine_whistle_trie_EMPTY_TRIE_ROOT : + IsGlobalAlias globals ethereum.tangerine_whistle.trie.globals "EMPTY_TRIE_ROOT". +Axiom ethereum_tangerine_whistle_trie_Trie : + IsGlobalAlias globals ethereum.tangerine_whistle.trie.globals "Trie". +Axiom ethereum_tangerine_whistle_trie_copy_trie : + IsGlobalAlias globals ethereum.tangerine_whistle.trie.globals "copy_trie". +Axiom ethereum_tangerine_whistle_trie_root : + IsGlobalAlias globals ethereum.tangerine_whistle.trie.globals "root". +Axiom ethereum_tangerine_whistle_trie_trie_get : + IsGlobalAlias globals ethereum.tangerine_whistle.trie.globals "trie_get". +Axiom ethereum_tangerine_whistle_trie_trie_set : + IsGlobalAlias globals ethereum.tangerine_whistle.trie.globals "trie_set". Definition State : Value.t := builtins.make_klass @@ -123,7 +123,7 @@ Definition begin_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "state" |), "_main_trie" |) ], make_dict [] - |); (* At expr: unsupported node type: DictComp *) ] + |); Constant.str "(* At expr: unsupported node type: DictComp *)" ] ], make_dict [] |) in @@ -201,8 +201,27 @@ Definition get_account : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "account" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "account" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_ACCOUNT" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -237,6 +256,7 @@ Definition get_account_optional : Value.t -> Value.t -> M := |) in let _ := M.return_ (| M.get_name (| globals, "account" |) + |) in M.pure Constant.None_)). Definition set_account : Value.t -> Value.t -> M := @@ -316,6 +336,18 @@ Definition destroy_storage : Value.t -> Value.t -> M := Address of account whose storage is to be deleted. " in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -350,6 +382,26 @@ Definition get_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "trie" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let value := @@ -371,6 +423,7 @@ Definition get_storage : Value.t -> Value.t -> M := |) |) in let _ := M.return_ (| M.get_name (| globals, "value" |) + |) in M.pure Constant.None_)). Definition set_storage : Value.t -> Value.t -> M := @@ -411,6 +464,27 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "trie" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let trie := + M.call (| + M.get_name (| globals, "Trie" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), + M.get_name (| globals, "trie" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -423,6 +497,18 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + {} + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -447,8 +533,29 @@ Definition storage_root : Value.t -> Value.t -> M := " in let _ := M.assert (| UnOp.not (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |) |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "root" |), + make_list [ + M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.get_name (| globals, "EMPTY_TRIE_ROOT" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -479,6 +586,7 @@ Definition state_root : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition account_exists : Value.t -> Value.t -> M := @@ -511,6 +619,7 @@ Definition account_exists : Value.t -> Value.t -> M := |), Constant.None_ |) + |) in M.pure Constant.None_)). Definition account_has_code_or_nonce : Value.t -> Value.t -> M := @@ -560,6 +669,7 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := |) )) |) + |) in M.pure Constant.None_)). Definition modify_state : Value.t -> Value.t -> M := @@ -665,6 +775,30 @@ Definition touch_account : Value.t -> Value.t -> M := The address of the account that need to initialised. " in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "account_exists" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "set_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |); + M.get_name (| globals, "EMPTY_ACCOUNT" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/transactions.v b/CoqOfPython/ethereum/tangerine_whistle/transactions.v index 6d1bc6b..4d58502 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/transactions.v +++ b/CoqOfPython/ethereum/tangerine_whistle/transactions.v @@ -17,21 +17,21 @@ Require typing. Axiom typing_Union : IsGlobalAlias globals typing.globals "Union". -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Bytes0 : - IsGlobalAlias globals base_types.globals "Bytes0". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Bytes0 : + IsGlobalAlias globals ethereum.base_types.globals "Bytes0". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.tangerine_whistle.fork_types. +Axiom ethereum_tangerine_whistle_fork_types_Address : + IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "Address". Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( Constant.int 21000 diff --git a/CoqOfPython/ethereum/tangerine_whistle/trie.v b/CoqOfPython/ethereum/tangerine_whistle/trie.v index d52469e..77642c6 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/trie.v +++ b/CoqOfPython/ethereum/tangerine_whistle/trie.v @@ -54,9 +54,9 @@ Require ethereum.crypto.hash. Axiom ethereum_crypto_hash_keccak256 : IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". -Require ethereum.dao_fork. -Axiom ethereum_dao_fork_trie : - IsGlobalAlias globals ethereum.dao_fork.globals "trie". +Require ethereum.dao_fork.__init__. +Axiom ethereum_dao_fork___init___trie : + IsGlobalAlias globals ethereum.dao_fork.__init__.globals "trie". Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : @@ -66,37 +66,37 @@ Require ethereum.utils.hexadecimal. Axiom ethereum_utils_hexadecimal_hex_to_bytes : IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". - -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". -Axiom base_types_slotted_freezable : - IsGlobalAlias globals base_types.globals "slotted_freezable". - -Require blocks. -Axiom blocks_Receipt : - IsGlobalAlias globals blocks.globals "Receipt". - -Require fork_types. -Axiom fork_types_Account : - IsGlobalAlias globals fork_types.globals "Account". -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". -Axiom fork_types_encode_account : - IsGlobalAlias globals fork_types.globals "encode_account". - -Require transactions. -Axiom transactions_Transaction : - IsGlobalAlias globals transactions.globals "Transaction". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". + +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_slotted_freezable : + IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". + +Require ethereum.tangerine_whistle.blocks. +Axiom ethereum_tangerine_whistle_blocks_Receipt : + IsGlobalAlias globals ethereum.tangerine_whistle.blocks.globals "Receipt". + +Require ethereum.tangerine_whistle.fork_types. +Axiom ethereum_tangerine_whistle_fork_types_Account : + IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "Account". +Axiom ethereum_tangerine_whistle_fork_types_Address : + IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "Address". +Axiom ethereum_tangerine_whistle_fork_types_Root : + IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "Root". +Axiom ethereum_tangerine_whistle_fork_types_encode_account : + IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "encode_account". + +Require ethereum.tangerine_whistle.transactions. +Axiom ethereum_tangerine_whistle_transactions_Transaction : + IsGlobalAlias globals ethereum.tangerine_whistle.transactions.globals "Transaction". Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -202,16 +202,99 @@ Definition encode_internal_node : Value.t -> Value.t -> M := " in (* At stmt: unsupported node type: AnnAssign *) let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "node" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + Constant.bytes "" in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "LeafNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "rest_of_key" |); + Constant.bool true + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "ExtensionNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + make_tuple [ M.call (| + M.get_name (| globals, "nibble_list_to_compact" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "key_segment" |); + Constant.bool false + ], + make_dict [] + |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "BranchNode" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let unencoded := + BinOp.add (| + M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), + make_list [ + M.get_field (| M.get_name (| globals, "node" |), "value" |) + ] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ - (* At expr: unsupported node type: JoinedStr *) + Constant.str "(* At expr: unsupported node type: JoinedStr *)" ], make_dict [] - |)) + |)) |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -229,6 +312,26 @@ Definition encode_internal_node : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "encoded" |) + ], + make_dict [] + |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "unencoded" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_name (| globals, "keccak256" |), @@ -237,6 +340,7 @@ Definition encode_internal_node : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -250,8 +354,86 @@ Definition encode_node : Value.t -> Value.t -> M := Currently mostly an unimplemented stub. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| + M.get_name (| globals, "storage_root" |), + Constant.None_ + |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "encode_account" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "storage_root" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + make_tuple [ M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "U256" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.call (| + M.get_name (| globals, "cast" |), + make_list [ + M.get_field (| M.get_name (| globals, "rlp" |), "RLP" |); + M.get_name (| globals, "node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "node" |); + M.get_name (| globals, "Bytes" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "node" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "previous_trie" |), "encode_node" |), @@ -261,6 +443,7 @@ Definition encode_node : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -312,6 +495,7 @@ Definition copy_trie : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition trie_set : Value.t -> Value.t -> M := @@ -333,6 +517,32 @@ Definition trie_set : Value.t -> Value.t -> M := Node to insert at `key`. " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + M.get_field (| M.get_name (| globals, "trie" |), "default" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.in (| + M.get_name (| globals, "key" |), + M.get_field (| M.get_name (| globals, "trie" |), "_data" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), M.get_name (| globals, "value" |) @@ -370,6 +580,7 @@ Definition trie_get : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition common_prefix_length : Value.t -> Value.t -> M := @@ -392,6 +603,34 @@ Definition common_prefix_length : Value.t -> Value.t -> M := make_dict [] |) do let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), + M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. @@ -403,6 +642,7 @@ Definition common_prefix_length : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition nibble_list_to_compact : Value.t -> Value.t -> M := @@ -448,6 +688,71 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + BinOp.mod_ (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |), + Constant.int 2 + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.mult (| + Constant.int 16, + BinOp.mult (| + Constant.int 2, + M.get_name (| globals, "is_leaf" |) + |) + |) + ], + make_dict [] + |) in + For M.get_name (| globals, "i" |) in M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |) do + let _ := M.call (| + M.get_field (| M.get_name (| globals, "compact" |), "append" |), + make_list [ + BinOp.add (| + BinOp.mult (| + Constant.int 16, + M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + |), + M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) |) + |) + ], + make_dict [] + |) in + EndFor. + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ @@ -509,6 +814,7 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition bytes_to_nibble_list : Value.t -> Value.t -> M := @@ -586,6 +892,7 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition _prepare_trie : Value.t -> Value.t -> M := @@ -615,6 +922,48 @@ Definition _prepare_trie : Value.t -> Value.t -> M := make_dict [] |) do let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| + M.get_name (| globals, "get_storage_root" |), + Constant.None_ + |) |) in + let address := + M.call (| + M.get_name (| globals, "Address" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |); + M.call (| + M.get_name (| globals, "get_storage_root" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let encoded_value := M.call (| M.get_name (| globals, "encode_node" |), @@ -638,6 +987,22 @@ Definition _prepare_trie : Value.t -> Value.t -> M := |) in (* At stmt: unsupported node type: AnnAssign *) let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "trie" |), "secured" |), + (* then *) + ltac:(M.monadic ( + let key := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let key := M.get_name (| globals, "preimage" |) in M.pure Constant.None_ @@ -655,6 +1020,7 @@ Definition _prepare_trie : Value.t -> Value.t -> M := EndFor. let _ := M.return_ (| M.get_name (| globals, "mapped" |) + |) in M.pure Constant.None_)). Definition root : Value.t -> Value.t -> M := @@ -708,6 +1074,44 @@ Definition root : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.call (| + M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), + make_list [ + M.get_name (| globals, "root_node" |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -724,6 +1128,7 @@ Definition root : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -750,6 +1155,26 @@ Definition patricialize : Value.t -> Value.t -> M := Root node of `obj`. " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let arbitrary_key := @@ -767,10 +1192,39 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "obj" |) + ], + make_dict [] + |), + Constant.int 1 + |), + (* then *) + ltac:(M.monadic ( + let leaf := + M.call (| + M.get_name (| globals, "LeafNode" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |); + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) + ], + make_dict [] + |) in + let _ := M.return_ (| + M.get_name (| globals, "leaf" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let substring := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |) |) in + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) in let prefix_length := M.call (| M.get_name (| globals, "len" |), @@ -789,7 +1243,7 @@ Definition patricialize : Value.t -> Value.t -> M := M.get_name (| globals, "common_prefix_length" |), make_list [ M.get_name (| globals, "substring" |); - M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) + M.get_subscript (| M.get_name (| globals, "key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) ], make_dict [] |) @@ -797,10 +1251,64 @@ Definition patricialize : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "prefix_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "prefix_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let prefix := + M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) |) |) in + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "ExtensionNode" |), + make_list [ + M.get_name (| globals, "prefix" |); + M.call (| + M.get_name (| globals, "encode_internal_node" |), + make_list [ + M.call (| + M.get_name (| globals, "patricialize" |), + make_list [ + M.get_name (| globals, "obj" |); + BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) @@ -823,6 +1331,44 @@ Definition patricialize : Value.t -> Value.t -> M := Constant.bytes "" in For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |), + M.get_name (| globals, "level" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "AssertionError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign (| M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) @@ -834,9 +1380,10 @@ Definition patricialize : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "BranchNode" |), make_list [ - (* At expr: unsupported node type: ListComp *); + Constant.str "(* At expr: unsupported node type: ListComp *)"; M.get_name (| globals, "value" |) ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/utils/address.v b/CoqOfPython/ethereum/tangerine_whistle/utils/address.v index a703595..bed9575 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/utils/address.v +++ b/CoqOfPython/ethereum/tangerine_whistle/utils/address.v @@ -36,13 +36,13 @@ Require ethereum.utils.byte. Axiom ethereum_utils_byte_left_pad_zero_bytes : IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". -Require __init__. -Axiom __init___rlp : - IsGlobalAlias globals __init__.globals "rlp". +Require ethereum.__init__. +Axiom ethereum___init___rlp : + IsGlobalAlias globals ethereum.__init__.globals "rlp". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.tangerine_whistle.fork_types. +Axiom ethereum_tangerine_whistle_fork_types_Address : + IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "Address". Definition to_address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -68,10 +68,11 @@ Definition to_address : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), make_list [], make_dict [] - |), UnOp.sub (| Constant.int 20 |) |) + |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) ], make_dict [] |) + |) in M.pure Constant.None_)). Definition compute_contract_address : Value.t -> Value.t -> M := @@ -111,7 +112,7 @@ Definition compute_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |) |) in + M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -129,4 +130,5 @@ Definition compute_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/utils/hexadecimal.v b/CoqOfPython/ethereum/tangerine_whistle/utils/hexadecimal.v index 5a965f6..7c15918 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/tangerine_whistle/utils/hexadecimal.v @@ -22,13 +22,13 @@ Require ethereum.utils.hexadecimal. Axiom ethereum_utils_hexadecimal_remove_hex_prefix : IsGlobalAlias globals ethereum.utils.hexadecimal.globals "remove_hex_prefix". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". -Axiom fork_types_Bloom : - IsGlobalAlias globals fork_types.globals "Bloom". -Axiom fork_types_Root : - IsGlobalAlias globals fork_types.globals "Root". +Require ethereum.tangerine_whistle.fork_types. +Axiom ethereum_tangerine_whistle_fork_types_Address : + IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "Address". +Axiom ethereum_tangerine_whistle_fork_types_Bloom : + IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "Bloom". +Axiom ethereum_tangerine_whistle_fork_types_Root : + IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "Root". Definition hex_to_root : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -66,6 +66,7 @@ Definition hex_to_root : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition hex_to_bloom : Value.t -> Value.t -> M := @@ -104,6 +105,7 @@ Definition hex_to_bloom : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition hex_to_address : Value.t -> Value.t -> M := @@ -149,4 +151,5 @@ Definition hex_to_address : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/utils/message.v b/CoqOfPython/ethereum/tangerine_whistle/utils/message.v index f714b67..0cf6875 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/utils/message.v +++ b/CoqOfPython/ethereum/tangerine_whistle/utils/message.v @@ -34,23 +34,23 @@ Axiom ethereum_base_types_Bytes0 : Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.tangerine_whistle.fork_types. +Axiom ethereum_tangerine_whistle_fork_types_Address : + IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "Address". -Require state. -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". +Require ethereum.tangerine_whistle.state. +Axiom ethereum_tangerine_whistle_state_get_account : + IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "get_account". -Require vm. -Axiom vm_Environment : - IsGlobalAlias globals vm.globals "Environment". -Axiom vm_Message : - IsGlobalAlias globals vm.globals "Message". +Require ethereum.tangerine_whistle.vm.__init__. +Axiom ethereum_tangerine_whistle_vm___init___Environment : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "Environment". +Axiom ethereum_tangerine_whistle_vm___init___Message : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "Message". -Require address. -Axiom address_compute_contract_address : - IsGlobalAlias globals address.globals "compute_contract_address". +Require ethereum.tangerine_whistle.utils.address. +Axiom ethereum_tangerine_whistle_utils_address_compute_contract_address : + IsGlobalAlias globals ethereum.tangerine_whistle.utils.address.globals "compute_contract_address". Definition prepare_message : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -85,14 +85,108 @@ Definition prepare_message : Value.t -> Value.t -> M := Items containing contract creation or message call specific data. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Bytes0" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.call (| + M.get_name (| globals, "compute_contract_address" |), + make_list [ + M.get_name (| globals, "caller" |); + BinOp.sub (| + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "caller" |) + ], + make_dict [] + |), "nonce" |), + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 1 + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let msg_data := + M.call (| + M.get_name (| globals, "Bytes" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) in + let code := + M.get_name (| globals, "data" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "target" |); + M.get_name (| globals, "Address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let current_target := + M.get_name (| globals, "target" |) in + let msg_data := + M.get_name (| globals, "data" |) in + let code := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "target" |) + ], + make_dict [] + |), "code" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.is (| + M.get_name (| globals, "code_address" |), + Constant.None_ + |), + (* then *) + ltac:(M.monadic ( + let code_address := + M.get_name (| globals, "target" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.raise (| Some(M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "Target must be address or empty bytes" ], make_dict [] - |)) + |)) |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -103,4 +197,5 @@ Definition prepare_message : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/__init__.v b/CoqOfPython/ethereum/tangerine_whistle/vm/__init__.v index 49bcb40..3d7480a 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/__init__.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/__init__.v @@ -48,17 +48,17 @@ Require ethereum.crypto.hash. Axiom ethereum_crypto_hash_Hash32 : IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". +Require ethereum.tangerine_whistle.blocks. +Axiom ethereum_tangerine_whistle_blocks_Log : + IsGlobalAlias globals ethereum.tangerine_whistle.blocks.globals "Log". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.tangerine_whistle.fork_types. +Axiom ethereum_tangerine_whistle_fork_types_Address : + IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "Address". -Require state. -Axiom state_State : - IsGlobalAlias globals state.globals "State". +Require ethereum.tangerine_whistle.state. +Axiom ethereum_tangerine_whistle_state_State : + IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "State". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/gas.v b/CoqOfPython/ethereum/tangerine_whistle/vm/gas.v index fddc9b4..9009607 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/gas.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/gas.v @@ -43,13 +43,13 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.tangerine_whistle.vm.__init__. +Axiom ethereum_tangerine_whistle_vm___init___Evm : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "Evm". -Require exceptions. -Axiom exceptions_OutOfGasError : - IsGlobalAlias globals exceptions.globals "OutOfGasError". +Require ethereum.tangerine_whistle.vm.exceptions. +Axiom ethereum_tangerine_whistle_vm_exceptions_OutOfGasError : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.exceptions.globals "OutOfGasError". Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -490,6 +490,18 @@ Definition charge_gas : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "amount" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.assign_op (| BinOp.sub, M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), @@ -605,6 +617,18 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := |) in For make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ] in M.get_name (| globals, "extensions" |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "size" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let before_size := @@ -639,6 +663,18 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let size_to_extend := BinOp.add @@ -687,6 +723,7 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition calculate_message_call_gas : Value.t -> Value.t -> M := @@ -718,22 +755,56 @@ Definition calculate_message_call_gas : Value.t -> Value.t -> M := message_call_gas: `MessageCallGas` " in let call_stipend := - (* if *) -M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "call_stipend" |) + )) |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "gas_left" |), + BinOp.add (| + M.get_name (| globals, "extra_gas" |), + M.get_name (| globals, "memory_cost" |) + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallGas" |), + make_list [ + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "extra_gas" |) + |); + BinOp.add (| + M.get_name (| globals, "gas" |), + M.get_name (| globals, "call_stipend" |) + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let gas := @@ -772,6 +843,7 @@ M.call (| ], make_dict [] |) + |) in M.pure Constant.None_)). Definition max_message_call_gas : Value.t -> Value.t -> M := @@ -798,4 +870,5 @@ Definition max_message_call_gas : Value.t -> Value.t -> M := Constant.int 64 |) |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/__init__.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/__init__.v index e5bebd7..2df87cd 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/__init__.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/__init__.v @@ -26,53 +26,53 @@ Axiom typing_Callable : Axiom typing_Dict : IsGlobalAlias globals typing.globals "Dict". -Require __init__. -Axiom __init___arithmetic : - IsGlobalAlias globals __init__.globals "arithmetic". +Require ethereum.tangerine_whistle.vm.instructions.__init__. +Axiom ethereum_tangerine_whistle_vm_instructions___init___arithmetic : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.instructions.__init__.globals "arithmetic". -Require __init__. -Axiom __init___bitwise : - IsGlobalAlias globals __init__.globals "bitwise". +Require ethereum.tangerine_whistle.vm.instructions.__init__. +Axiom ethereum_tangerine_whistle_vm_instructions___init___bitwise : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.instructions.__init__.globals "bitwise". -Require __init__. -Axiom __init___block : - IsGlobalAlias globals __init__.globals "block". +Require ethereum.tangerine_whistle.vm.instructions.__init__. +Axiom ethereum_tangerine_whistle_vm_instructions___init___block : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.instructions.__init__.globals "block". -Require __init__. -Axiom __init___comparison : - IsGlobalAlias globals __init__.globals "comparison". +Require ethereum.tangerine_whistle.vm.instructions.__init__. +Axiom ethereum_tangerine_whistle_vm_instructions___init___comparison : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.instructions.__init__.globals "comparison". -Require __init__. -Axiom __init___control_flow : - IsGlobalAlias globals __init__.globals "control_flow". +Require ethereum.tangerine_whistle.vm.instructions.__init__. +Axiom ethereum_tangerine_whistle_vm_instructions___init___control_flow : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.instructions.__init__.globals "control_flow". -Require __init__. -Axiom __init___environment : - IsGlobalAlias globals __init__.globals "environment". +Require ethereum.tangerine_whistle.vm.instructions.__init__. +Axiom ethereum_tangerine_whistle_vm_instructions___init___environment : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.instructions.__init__.globals "environment". -Require __init__. -Axiom __init___keccak : - IsGlobalAlias globals __init__.globals "keccak". +Require ethereum.tangerine_whistle.vm.instructions.__init__. +Axiom ethereum_tangerine_whistle_vm_instructions___init___keccak : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.instructions.__init__.globals "keccak". -Require __init__. -Axiom __init___log : - IsGlobalAlias globals __init__.globals "log". +Require ethereum.tangerine_whistle.vm.instructions.__init__. +Axiom ethereum_tangerine_whistle_vm_instructions___init___log : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.instructions.__init__.globals "log". -Require __init__. -Axiom __init___memory : - IsGlobalAlias globals __init__.globals "memory". +Require ethereum.tangerine_whistle.vm.instructions.__init__. +Axiom ethereum_tangerine_whistle_vm_instructions___init___memory : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.instructions.__init__.globals "memory". -Require __init__. -Axiom __init___stack : - IsGlobalAlias globals __init__.globals "stack". +Require ethereum.tangerine_whistle.vm.instructions.__init__. +Axiom ethereum_tangerine_whistle_vm_instructions___init___stack : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.instructions.__init__.globals "stack". -Require __init__. -Axiom __init___storage : - IsGlobalAlias globals __init__.globals "storage". +Require ethereum.tangerine_whistle.vm.instructions.__init__. +Axiom ethereum_tangerine_whistle_vm_instructions___init___storage : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.instructions.__init__.globals "storage". -Require __init__. -Axiom __init___system : - IsGlobalAlias globals __init__.globals "system". +Require ethereum.tangerine_whistle.vm.instructions.__init__. +Axiom ethereum_tangerine_whistle_vm_instructions___init___system : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.instructions.__init__.globals "system". Definition Ops : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/arithmetic.v index 581ba5d..5b28b51 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/arithmetic.v @@ -31,29 +31,29 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_get_sign : IsGlobalAlias globals ethereum.utils.numeric.globals "get_sign". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_EXPONENTIATION : - IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION". -Axiom gas_GAS_EXPONENTIATION_PER_BYTE : - IsGlobalAlias globals gas.globals "GAS_EXPONENTIATION_PER_BYTE". -Axiom gas_GAS_LOW : - IsGlobalAlias globals gas.globals "GAS_LOW". -Axiom gas_GAS_MID : - IsGlobalAlias globals gas.globals "GAS_MID". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.tangerine_whistle.vm.__init__. +Axiom ethereum_tangerine_whistle_vm___init___Evm : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "Evm". + +Require ethereum.tangerine_whistle.vm.gas. +Axiom ethereum_tangerine_whistle_vm_gas_GAS_EXPONENTIATION : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_EXPONENTIATION". +Axiom ethereum_tangerine_whistle_vm_gas_GAS_EXPONENTIATION_PER_BYTE : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_EXPONENTIATION_PER_BYTE". +Axiom ethereum_tangerine_whistle_vm_gas_GAS_LOW : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_LOW". +Axiom ethereum_tangerine_whistle_vm_gas_GAS_MID : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_MID". +Axiom ethereum_tangerine_whistle_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_tangerine_whistle_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "charge_gas". + +Require ethereum.tangerine_whistle.vm.stack. +Axiom ethereum_tangerine_whistle_vm_stack_pop : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.stack.globals "pop". +Axiom ethereum_tangerine_whistle_vm_stack_push : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.stack.globals "push". Definition add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -273,6 +273,25 @@ Definition div : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "divisor" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let quotient := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let quotient := BinOp.floor_div (| M.get_name (| globals, "dividend" |), @@ -341,7 +360,41 @@ Definition sdiv : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "divisor" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let quotient := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_name (| globals, "dividend" |), + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "divisor" |), + UnOp.sub (| Constant.int 1 |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let quotient := + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let sign := M.call (| M.get_name (| globals, "get_sign" |), @@ -436,6 +489,25 @@ Definition mod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "y" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let remainder := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let remainder := BinOp.mod_ (| M.get_name (| globals, "x" |), @@ -504,6 +576,19 @@ Definition smod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "y" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let remainder := + Constant.int 0 in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let remainder := BinOp.mult (| M.call (| @@ -617,6 +702,25 @@ Definition addmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "z" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -712,6 +816,25 @@ Definition mulmod : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "z" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let result := M.call (| M.get_name (| globals, "U256" |), @@ -881,6 +1004,19 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_name (| globals, "byte_num" |), + Constant.int 31 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.get_name (| globals, "value" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let value_bytes := M.call (| M.get_name (| globals, "bytes" |), @@ -894,7 +1030,7 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let value_bytes := - M.get_subscript (| M.get_name (| globals, "value_bytes" |), BinOp.sub (| + M.get_subscript (| M.get_name (| globals, "value_bytes" |), M.slice (| BinOp.sub (| Constant.int 31, M.call (| M.get_name (| globals, "int" |), @@ -903,13 +1039,32 @@ Definition signextend : Value.t -> Value.t -> M := ], make_dict [] |) - |) |) in + |), Constant.None_ |) |) in let sign_bit := BinOp.r_shift (| M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), Constant.int 7 |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "sign_bit" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.get_name (| globals, "value_bytes" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let num_bytes_prepend := BinOp.sub (| Constant.int 32, diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/bitwise.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/bitwise.v index f38e7aa..179a578 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/bitwise.v @@ -21,21 +21,21 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.tangerine_whistle.vm.__init__. +Axiom ethereum_tangerine_whistle_vm___init___Evm : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.tangerine_whistle.vm.gas. +Axiom ethereum_tangerine_whistle_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_tangerine_whistle_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "charge_gas". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.tangerine_whistle.vm.stack. +Axiom ethereum_tangerine_whistle_vm_stack_pop : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.stack.globals "pop". +Axiom ethereum_tangerine_whistle_vm_stack_push : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.stack.globals "push". Definition bitwise_and : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -285,6 +285,25 @@ Definition get_byte : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "byte_index" |), + Constant.int 32 + |), + (* then *) + ltac:(M.monadic ( + let result := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let extra_bytes_to_right := BinOp.sub (| Constant.int 31, diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/block.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/block.v index 90be45c..c3f2b4d 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/block.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/block.v @@ -21,23 +21,23 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_BLOCK_HASH : - IsGlobalAlias globals gas.globals "GAS_BLOCK_HASH". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.tangerine_whistle.vm.__init__. +Axiom ethereum_tangerine_whistle_vm___init___Evm : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "Evm". + +Require ethereum.tangerine_whistle.vm.gas. +Axiom ethereum_tangerine_whistle_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_BASE". +Axiom ethereum_tangerine_whistle_vm_gas_GAS_BLOCK_HASH : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_BLOCK_HASH". +Axiom ethereum_tangerine_whistle_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "charge_gas". + +Require ethereum.tangerine_whistle.vm.stack. +Axiom ethereum_tangerine_whistle_vm_stack_pop : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.stack.globals "pop". +Axiom ethereum_tangerine_whistle_vm_stack_push : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.stack.globals "push". Definition block_hash : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -69,6 +69,30 @@ Definition block_hash : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt_e (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + M.get_name (| globals, "block_number" |) + |), + ltac:(M.monadic ( + Compare.gt (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + BinOp.add (| + M.get_name (| globals, "block_number" |), + Constant.int 256 + |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let hash := + Constant.bytes "00" in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let hash := M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/comparison.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/comparison.v index b8529d8..e99a53f 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/comparison.v @@ -21,21 +21,21 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.tangerine_whistle.vm.__init__. +Axiom ethereum_tangerine_whistle_vm___init___Evm : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.tangerine_whistle.vm.gas. +Axiom ethereum_tangerine_whistle_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_tangerine_whistle_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "charge_gas". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.tangerine_whistle.vm.stack. +Axiom ethereum_tangerine_whistle_vm_stack_pop : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.stack.globals "pop". +Axiom ethereum_tangerine_whistle_vm_stack_push : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.stack.globals "push". Definition less_than : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/control_flow.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/control_flow.v index d4e4eae..5aa8895 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/control_flow.v @@ -23,31 +23,31 @@ Axiom ethereum_base_types_U256 : Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require vm.gas. -Axiom vm_gas_GAS_BASE : - IsGlobalAlias globals vm.gas.globals "GAS_BASE". -Axiom vm_gas_GAS_HIGH : - IsGlobalAlias globals vm.gas.globals "GAS_HIGH". -Axiom vm_gas_GAS_JUMPDEST : - IsGlobalAlias globals vm.gas.globals "GAS_JUMPDEST". -Axiom vm_gas_GAS_MID : - IsGlobalAlias globals vm.gas.globals "GAS_MID". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.tangerine_whistle.vm.gas. +Axiom ethereum_tangerine_whistle_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_BASE". +Axiom ethereum_tangerine_whistle_vm_gas_GAS_HIGH : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_HIGH". +Axiom ethereum_tangerine_whistle_vm_gas_GAS_JUMPDEST : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_JUMPDEST". +Axiom ethereum_tangerine_whistle_vm_gas_GAS_MID : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_MID". +Axiom ethereum_tangerine_whistle_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "charge_gas". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.tangerine_whistle.vm.__init__. +Axiom ethereum_tangerine_whistle_vm___init___Evm : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "Evm". -Require exceptions. -Axiom exceptions_InvalidJumpDestError : - IsGlobalAlias globals exceptions.globals "InvalidJumpDestError". +Require ethereum.tangerine_whistle.vm.exceptions. +Axiom ethereum_tangerine_whistle_vm_exceptions_InvalidJumpDestError : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.exceptions.globals "InvalidJumpDestError". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.tangerine_whistle.vm.stack. +Axiom ethereum_tangerine_whistle_vm_stack_pop : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.stack.globals "pop". +Axiom ethereum_tangerine_whistle_vm_stack_push : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.stack.globals "push". Definition stop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -109,6 +109,18 @@ Definition jump : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "jump_dest" |), + M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -168,7 +180,35 @@ Definition jumpi : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "conditional_value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let destination := + BinOp.add (| + M.get_field (| M.get_name (| globals, "evm" |), "pc" |), + Constant.int 1 + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "jump_dest" |), + M.get_field (| M.get_name (| globals, "evm" |), "valid_jump_destinations" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let destination := M.get_name (| globals, "jump_dest" |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/environment.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/environment.v index 366e59a..ec9d582 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/environment.v @@ -27,45 +27,45 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require state. -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". - -Require utils.address. -Axiom utils_address_to_address : - IsGlobalAlias globals utils.address.globals "to_address". - -Require vm.memory. -Axiom vm_memory_buffer_read : - IsGlobalAlias globals vm.memory.globals "buffer_read". -Axiom vm_memory_memory_write : - IsGlobalAlias globals vm.memory.globals "memory_write". - -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_BALANCE : - IsGlobalAlias globals gas.globals "GAS_BALANCE". -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_COPY : - IsGlobalAlias globals gas.globals "GAS_COPY". -Axiom gas_GAS_EXTERNAL : - IsGlobalAlias globals gas.globals "GAS_EXTERNAL". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.tangerine_whistle.state. +Axiom ethereum_tangerine_whistle_state_get_account : + IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "get_account". + +Require ethereum.tangerine_whistle.utils.address. +Axiom ethereum_tangerine_whistle_utils_address_to_address : + IsGlobalAlias globals ethereum.tangerine_whistle.utils.address.globals "to_address". + +Require ethereum.tangerine_whistle.vm.memory. +Axiom ethereum_tangerine_whistle_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.memory.globals "buffer_read". +Axiom ethereum_tangerine_whistle_vm_memory_memory_write : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.memory.globals "memory_write". + +Require ethereum.tangerine_whistle.vm.__init__. +Axiom ethereum_tangerine_whistle_vm___init___Evm : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "Evm". + +Require ethereum.tangerine_whistle.vm.gas. +Axiom ethereum_tangerine_whistle_vm_gas_GAS_BALANCE : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_BALANCE". +Axiom ethereum_tangerine_whistle_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_BASE". +Axiom ethereum_tangerine_whistle_vm_gas_GAS_COPY : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_COPY". +Axiom ethereum_tangerine_whistle_vm_gas_GAS_EXTERNAL : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_EXTERNAL". +Axiom ethereum_tangerine_whistle_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_tangerine_whistle_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_tangerine_whistle_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "charge_gas". + +Require ethereum.tangerine_whistle.vm.stack. +Axiom ethereum_tangerine_whistle_vm_stack_pop : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.stack.globals "pop". +Axiom ethereum_tangerine_whistle_vm_stack_push : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.stack.globals "push". Definition address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/keccak.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/keccak.v index 2c4b10e..6ca60b6 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/keccak.v @@ -31,29 +31,29 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_KECCAK256 : - IsGlobalAlias globals gas.globals "GAS_KECCAK256". -Axiom gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals gas.globals "GAS_KECCAK256_WORD". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.tangerine_whistle.vm.__init__. +Axiom ethereum_tangerine_whistle_vm___init___Evm : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "Evm". + +Require ethereum.tangerine_whistle.vm.gas. +Axiom ethereum_tangerine_whistle_vm_gas_GAS_KECCAK256 : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_KECCAK256". +Axiom ethereum_tangerine_whistle_vm_gas_GAS_KECCAK256_WORD : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_KECCAK256_WORD". +Axiom ethereum_tangerine_whistle_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_tangerine_whistle_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "charge_gas". + +Require ethereum.tangerine_whistle.vm.memory. +Axiom ethereum_tangerine_whistle_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.memory.globals "memory_read_bytes". + +Require ethereum.tangerine_whistle.vm.stack. +Axiom ethereum_tangerine_whistle_vm_stack_pop : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.stack.globals "pop". +Axiom ethereum_tangerine_whistle_vm_stack_push : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.stack.globals "push". Definition keccak : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/log.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/log.v index ab196bc..cd9aa02 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/log.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/log.v @@ -25,33 +25,33 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". - -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require gas. -Axiom gas_GAS_LOG : - IsGlobalAlias globals gas.globals "GAS_LOG". -Axiom gas_GAS_LOG_DATA : - IsGlobalAlias globals gas.globals "GAS_LOG_DATA". -Axiom gas_GAS_LOG_TOPIC : - IsGlobalAlias globals gas.globals "GAS_LOG_TOPIC". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". - -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". +Require ethereum.tangerine_whistle.blocks. +Axiom ethereum_tangerine_whistle_blocks_Log : + IsGlobalAlias globals ethereum.tangerine_whistle.blocks.globals "Log". + +Require ethereum.tangerine_whistle.vm.__init__. +Axiom ethereum_tangerine_whistle_vm___init___Evm : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "Evm". + +Require ethereum.tangerine_whistle.vm.gas. +Axiom ethereum_tangerine_whistle_vm_gas_GAS_LOG : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_LOG". +Axiom ethereum_tangerine_whistle_vm_gas_GAS_LOG_DATA : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_LOG_DATA". +Axiom ethereum_tangerine_whistle_vm_gas_GAS_LOG_TOPIC : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_LOG_TOPIC". +Axiom ethereum_tangerine_whistle_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_tangerine_whistle_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "charge_gas". + +Require ethereum.tangerine_whistle.vm.memory. +Axiom ethereum_tangerine_whistle_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.memory.globals "memory_read_bytes". + +Require ethereum.tangerine_whistle.vm.stack. +Axiom ethereum_tangerine_whistle_vm_stack_pop : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.stack.globals "pop". Definition log_n : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/memory.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/memory.v index 86ba742..13a2715 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/memory.v @@ -23,31 +23,31 @@ Axiom ethereum_base_types_U256 : Axiom ethereum_base_types_Bytes : IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.tangerine_whistle.vm.__init__. +Axiom ethereum_tangerine_whistle_vm___init___Evm : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.tangerine_whistle.vm.gas. +Axiom ethereum_tangerine_whistle_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_BASE". +Axiom ethereum_tangerine_whistle_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_tangerine_whistle_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_tangerine_whistle_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "charge_gas". -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". -Axiom memory_memory_write : - IsGlobalAlias globals memory.globals "memory_write". +Require ethereum.tangerine_whistle.vm.memory. +Axiom ethereum_tangerine_whistle_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.memory.globals "memory_read_bytes". +Axiom ethereum_tangerine_whistle_vm_memory_memory_write : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.memory.globals "memory_write". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.tangerine_whistle.vm.stack. +Axiom ethereum_tangerine_whistle_vm_stack_pop : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.stack.globals "pop". +Axiom ethereum_tangerine_whistle_vm_stack_push : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.stack.globals "push". Definition mstore : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/stack.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/stack.v index 305af15..1e06082 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/stack.v @@ -29,27 +29,27 @@ Require ethereum.utils.ensure. Axiom ethereum_utils_ensure_ensure : IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". -Axiom __init___stack : - IsGlobalAlias globals __init__.globals "stack". - -Require exceptions. -Axiom exceptions_StackUnderflowError : - IsGlobalAlias globals exceptions.globals "StackUnderflowError". - -Require gas. -Axiom gas_GAS_BASE : - IsGlobalAlias globals gas.globals "GAS_BASE". -Axiom gas_GAS_VERY_LOW : - IsGlobalAlias globals gas.globals "GAS_VERY_LOW". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". - -Require memory. -Axiom memory_buffer_read : - IsGlobalAlias globals memory.globals "buffer_read". +Require ethereum.tangerine_whistle.vm.__init__. +Axiom ethereum_tangerine_whistle_vm___init___Evm : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "Evm". +Axiom ethereum_tangerine_whistle_vm___init___stack : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "stack". + +Require ethereum.tangerine_whistle.vm.exceptions. +Axiom ethereum_tangerine_whistle_vm_exceptions_StackUnderflowError : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.exceptions.globals "StackUnderflowError". + +Require ethereum.tangerine_whistle.vm.gas. +Axiom ethereum_tangerine_whistle_vm_gas_GAS_BASE : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_BASE". +Axiom ethereum_tangerine_whistle_vm_gas_GAS_VERY_LOW : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_VERY_LOW". +Axiom ethereum_tangerine_whistle_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "charge_gas". + +Require ethereum.tangerine_whistle.vm.memory. +Axiom ethereum_tangerine_whistle_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.memory.globals "buffer_read". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/storage.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/storage.v index 5250214..e0288ec 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/storage.v @@ -17,33 +17,33 @@ Introduction Implementations of the EVM storage related instructions. ". -Require state. -Axiom state_get_storage : - IsGlobalAlias globals state.globals "get_storage". -Axiom state_set_storage : - IsGlobalAlias globals state.globals "set_storage". +Require ethereum.tangerine_whistle.state. +Axiom ethereum_tangerine_whistle_state_get_storage : + IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "get_storage". +Axiom ethereum_tangerine_whistle_state_set_storage : + IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "set_storage". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". +Require ethereum.tangerine_whistle.vm.__init__. +Axiom ethereum_tangerine_whistle_vm___init___Evm : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "Evm". -Require gas. -Axiom gas_GAS_SLOAD : - IsGlobalAlias globals gas.globals "GAS_SLOAD". -Axiom gas_GAS_STORAGE_CLEAR_REFUND : - IsGlobalAlias globals gas.globals "GAS_STORAGE_CLEAR_REFUND". -Axiom gas_GAS_STORAGE_SET : - IsGlobalAlias globals gas.globals "GAS_STORAGE_SET". -Axiom gas_GAS_STORAGE_UPDATE : - IsGlobalAlias globals gas.globals "GAS_STORAGE_UPDATE". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". +Require ethereum.tangerine_whistle.vm.gas. +Axiom ethereum_tangerine_whistle_vm_gas_GAS_SLOAD : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_SLOAD". +Axiom ethereum_tangerine_whistle_vm_gas_GAS_STORAGE_CLEAR_REFUND : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_STORAGE_CLEAR_REFUND". +Axiom ethereum_tangerine_whistle_vm_gas_GAS_STORAGE_SET : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_STORAGE_SET". +Axiom ethereum_tangerine_whistle_vm_gas_GAS_STORAGE_UPDATE : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_STORAGE_UPDATE". +Axiom ethereum_tangerine_whistle_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "charge_gas". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.tangerine_whistle.vm.stack. +Axiom ethereum_tangerine_whistle_vm_stack_pop : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.stack.globals "pop". +Axiom ethereum_tangerine_whistle_vm_stack_push : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.stack.globals "push". Definition sload : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -146,11 +146,56 @@ Definition sstore : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "new_value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.eq (| + M.get_name (| globals, "current_value" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let gas_cost := + M.get_name (| globals, "GAS_STORAGE_SET" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let gas_cost := M.get_name (| globals, "GAS_STORAGE_UPDATE" |) in M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.eq (| + M.get_name (| globals, "new_value" |), + Constant.int 0 + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "current_value" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.get_name (| globals, "GAS_STORAGE_CLEAR_REFUND" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/system.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/system.v index 8f94208..5ecb81f 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/system.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/system.v @@ -25,75 +25,75 @@ Axiom ethereum_base_types_Bytes0 : Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". +Require ethereum.tangerine_whistle.fork_types. +Axiom ethereum_tangerine_whistle_fork_types_Address : + IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "Address". -Require state. -Axiom state_account_exists : - IsGlobalAlias globals state.globals "account_exists". -Axiom state_account_has_code_or_nonce : - IsGlobalAlias globals state.globals "account_has_code_or_nonce". -Axiom state_get_account : - IsGlobalAlias globals state.globals "get_account". -Axiom state_increment_nonce : - IsGlobalAlias globals state.globals "increment_nonce". -Axiom state_set_account_balance : - IsGlobalAlias globals state.globals "set_account_balance". +Require ethereum.tangerine_whistle.state. +Axiom ethereum_tangerine_whistle_state_account_exists : + IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "account_exists". +Axiom ethereum_tangerine_whistle_state_account_has_code_or_nonce : + IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "account_has_code_or_nonce". +Axiom ethereum_tangerine_whistle_state_get_account : + IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "get_account". +Axiom ethereum_tangerine_whistle_state_increment_nonce : + IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "increment_nonce". +Axiom ethereum_tangerine_whistle_state_set_account_balance : + IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "set_account_balance". -Require utils.address. -Axiom utils_address_compute_contract_address : - IsGlobalAlias globals utils.address.globals "compute_contract_address". -Axiom utils_address_to_address : - IsGlobalAlias globals utils.address.globals "to_address". +Require ethereum.tangerine_whistle.utils.address. +Axiom ethereum_tangerine_whistle_utils_address_compute_contract_address : + IsGlobalAlias globals ethereum.tangerine_whistle.utils.address.globals "compute_contract_address". +Axiom ethereum_tangerine_whistle_utils_address_to_address : + IsGlobalAlias globals ethereum.tangerine_whistle.utils.address.globals "to_address". -Require __init__. -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". -Axiom __init___Message : - IsGlobalAlias globals __init__.globals "Message". -Axiom __init___incorporate_child_on_error : - IsGlobalAlias globals __init__.globals "incorporate_child_on_error". -Axiom __init___incorporate_child_on_success : - IsGlobalAlias globals __init__.globals "incorporate_child_on_success". +Require ethereum.tangerine_whistle.vm.__init__. +Axiom ethereum_tangerine_whistle_vm___init___Evm : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "Evm". +Axiom ethereum_tangerine_whistle_vm___init___Message : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "Message". +Axiom ethereum_tangerine_whistle_vm___init___incorporate_child_on_error : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "incorporate_child_on_error". +Axiom ethereum_tangerine_whistle_vm___init___incorporate_child_on_success : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "incorporate_child_on_success". -Require gas. -Axiom gas_GAS_CALL : - IsGlobalAlias globals gas.globals "GAS_CALL". -Axiom gas_GAS_CALL_VALUE : - IsGlobalAlias globals gas.globals "GAS_CALL_VALUE". -Axiom gas_GAS_CREATE : - IsGlobalAlias globals gas.globals "GAS_CREATE". -Axiom gas_GAS_NEW_ACCOUNT : - IsGlobalAlias globals gas.globals "GAS_NEW_ACCOUNT". -Axiom gas_GAS_SELF_DESTRUCT : - IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT". -Axiom gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : - IsGlobalAlias globals gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". -Axiom gas_GAS_ZERO : - IsGlobalAlias globals gas.globals "GAS_ZERO". -Axiom gas_REFUND_SELF_DESTRUCT : - IsGlobalAlias globals gas.globals "REFUND_SELF_DESTRUCT". -Axiom gas_calculate_gas_extend_memory : - IsGlobalAlias globals gas.globals "calculate_gas_extend_memory". -Axiom gas_calculate_message_call_gas : - IsGlobalAlias globals gas.globals "calculate_message_call_gas". -Axiom gas_charge_gas : - IsGlobalAlias globals gas.globals "charge_gas". -Axiom gas_max_message_call_gas : - IsGlobalAlias globals gas.globals "max_message_call_gas". +Require ethereum.tangerine_whistle.vm.gas. +Axiom ethereum_tangerine_whistle_vm_gas_GAS_CALL : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_CALL". +Axiom ethereum_tangerine_whistle_vm_gas_GAS_CALL_VALUE : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_CALL_VALUE". +Axiom ethereum_tangerine_whistle_vm_gas_GAS_CREATE : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_CREATE". +Axiom ethereum_tangerine_whistle_vm_gas_GAS_NEW_ACCOUNT : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_NEW_ACCOUNT". +Axiom ethereum_tangerine_whistle_vm_gas_GAS_SELF_DESTRUCT : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_SELF_DESTRUCT". +Axiom ethereum_tangerine_whistle_vm_gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". +Axiom ethereum_tangerine_whistle_vm_gas_GAS_ZERO : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_ZERO". +Axiom ethereum_tangerine_whistle_vm_gas_REFUND_SELF_DESTRUCT : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "REFUND_SELF_DESTRUCT". +Axiom ethereum_tangerine_whistle_vm_gas_calculate_gas_extend_memory : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "calculate_gas_extend_memory". +Axiom ethereum_tangerine_whistle_vm_gas_calculate_message_call_gas : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "calculate_message_call_gas". +Axiom ethereum_tangerine_whistle_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "charge_gas". +Axiom ethereum_tangerine_whistle_vm_gas_max_message_call_gas : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "max_message_call_gas". -Require memory. -Axiom memory_memory_read_bytes : - IsGlobalAlias globals memory.globals "memory_read_bytes". -Axiom memory_memory_write : - IsGlobalAlias globals memory.globals "memory_write". +Require ethereum.tangerine_whistle.vm.memory. +Axiom ethereum_tangerine_whistle_vm_memory_memory_read_bytes : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.memory.globals "memory_read_bytes". +Axiom ethereum_tangerine_whistle_vm_memory_memory_write : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.memory.globals "memory_write". -Require stack. -Axiom stack_pop : - IsGlobalAlias globals stack.globals "pop". -Axiom stack_push : - IsGlobalAlias globals stack.globals "push". +Require ethereum.tangerine_whistle.vm.stack. +Axiom ethereum_tangerine_whistle_vm_stack_pop : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.stack.globals "pop". +Axiom ethereum_tangerine_whistle_vm_stack_push : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.stack.globals "push". Definition create : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -208,7 +208,105 @@ Definition create : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.lt (| + M.get_field (| M.get_name (| globals, "sender" |), "balance" |), + M.get_name (| globals, "endowment" |) + |), + ltac:(M.monadic ( + BoolOp.or (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "sender" |), "nonce" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + BinOp.sub (| + BinOp.pow (| + Constant.int 2, + Constant.int 64 + |), + Constant.int 1 + |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.gt (| + BinOp.add (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "depth" |), + Constant.int 1 + |), + M.get_name (| globals, "STACK_DEPTH_LIMIT" |) + |) + )) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "create_message_gas" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "contract_address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "increment_nonce" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let call_data := M.call (| M.get_name (| globals, "memory_read_bytes" |), @@ -243,6 +341,36 @@ Definition create : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "child_evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_error" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "incorporate_child_on_success" |), make_list [ @@ -362,6 +490,42 @@ Definition generic_call : Value.t -> Value.t -> M := " in (* At stmt: unsupported node type: ImportFrom *) let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + BinOp.add (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "depth" |), + Constant.int 1 + |), + M.get_name (| globals, "STACK_DEPTH_LIMIT" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_name (| globals, "gas" |) + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let call_data := @@ -399,6 +563,36 @@ Definition generic_call : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "child_evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "incorporate_child_on_error" |), + make_list [ + M.get_name (| globals, "evm" |); + M.get_name (| globals, "child_evm" |) + ], + make_dict [] + |) in + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "incorporate_child_on_success" |), make_list [ @@ -449,7 +643,7 @@ Definition generic_call : Value.t -> Value.t -> M := make_list [ M.get_field (| M.get_name (| globals, "evm" |), "memory" |); M.get_name (| globals, "memory_output_start_position" |); - M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), Constant.None_:M.get_name (| globals, "actual_output_size" |) |) + M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), M.slice (| Constant.None_, M.get_name (| globals, "actual_output_size" |) |) |) ], make_dict [] |) in @@ -556,34 +750,42 @@ Definition call : Value.t -> Value.t -> M := make_dict [] |) in let create_gas_cost := - (* if *) -M.if_then_else (| - M.get_name (| globals, "_account_exists" |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + M.get_name (| globals, "_account_exists" |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "GAS_NEW_ACCOUNT" |) + )) |) in let transfer_gas_cost := - (* if *) -M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "GAS_CALL_VALUE" |) + )) |) in let message_call_gas := M.call (| M.get_name (| globals, "calculate_message_call_gas" |), @@ -637,6 +839,36 @@ M.call (| make_dict [] |), "balance" |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "sender_balance" |), + M.get_name (| globals, "value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "generic_call" |), make_list [ @@ -757,21 +989,25 @@ Definition callcode : Value.t -> Value.t -> M := make_dict [] |) in let transfer_gas_cost := - (* if *) -M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "value" |), - Constant.int 0 - |), -(* then *) -ltac:(M.monadic ( + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |) in + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + (* else *) + )), ltac:(M.monadic ( +M.get_name (| globals, "GAS_CALL_VALUE" |) + )) |) in let message_call_gas := M.call (| M.get_name (| globals, "calculate_message_call_gas" |), @@ -822,6 +1058,36 @@ M.call (| make_dict [] |), "balance" |) in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "sender_balance" |), + M.get_name (| globals, "value" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "push" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + ], + make_dict [] + |) in + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), + M.get_field (| M.get_name (| globals, "message_call_gas" |), "stipend" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "generic_call" |), make_list [ @@ -876,6 +1142,24 @@ Definition selfdestruct : Value.t -> Value.t -> M := let gas_cost := M.get_name (| globals, "GAS_SELF_DESTRUCT" |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.call (| + M.get_name (| globals, "account_exists" |), + make_list [ + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |); + M.get_name (| globals, "beneficiary" |) + ], + make_dict [] + |) |), + (* then *) + ltac:(M.monadic ( + let gas_cost := BinOp.add + M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) + M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let originator := @@ -899,6 +1183,22 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in EndWhile. let _ := + (* if *) + M.if_then_else (| + Compare.not_in (| + M.get_name (| globals, "originator" |), + M.get_name (| globals, "refunded_accounts" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |), + M.get_name (| globals, "REFUND_SELF_DESTRUCT" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/interpreter.v b/CoqOfPython/ethereum/tangerine_whistle/vm/interpreter.v index d8dd02b..6c9b819 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/interpreter.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/interpreter.v @@ -55,71 +55,71 @@ Axiom ethereum_trace_TransactionEnd : Axiom ethereum_trace_evm_trace : IsGlobalAlias globals ethereum.trace.globals "evm_trace". -Require blocks. -Axiom blocks_Log : - IsGlobalAlias globals blocks.globals "Log". - -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". - -Require state. -Axiom state_account_has_code_or_nonce : - IsGlobalAlias globals state.globals "account_has_code_or_nonce". -Axiom state_begin_transaction : - IsGlobalAlias globals state.globals "begin_transaction". -Axiom state_commit_transaction : - IsGlobalAlias globals state.globals "commit_transaction". -Axiom state_destroy_storage : - IsGlobalAlias globals state.globals "destroy_storage". -Axiom state_move_ether : - IsGlobalAlias globals state.globals "move_ether". -Axiom state_rollback_transaction : - IsGlobalAlias globals state.globals "rollback_transaction". -Axiom state_set_code : - IsGlobalAlias globals state.globals "set_code". -Axiom state_touch_account : - IsGlobalAlias globals state.globals "touch_account". - -Require vm. -Axiom vm_Message : - IsGlobalAlias globals vm.globals "Message". - -Require vm.gas. -Axiom vm_gas_GAS_CODE_DEPOSIT : - IsGlobalAlias globals vm.gas.globals "GAS_CODE_DEPOSIT". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". - -Require vm.precompiled_contracts.mapping. -Axiom vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : - IsGlobalAlias globals vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". - -Require __init__. -Axiom __init___Environment : - IsGlobalAlias globals __init__.globals "Environment". -Axiom __init___Evm : - IsGlobalAlias globals __init__.globals "Evm". - -Require exceptions. -Axiom exceptions_AddressCollision : - IsGlobalAlias globals exceptions.globals "AddressCollision". -Axiom exceptions_ExceptionalHalt : - IsGlobalAlias globals exceptions.globals "ExceptionalHalt". -Axiom exceptions_InvalidOpcode : - IsGlobalAlias globals exceptions.globals "InvalidOpcode". -Axiom exceptions_StackDepthLimitError : - IsGlobalAlias globals exceptions.globals "StackDepthLimitError". - -Require instructions. -Axiom instructions_Ops : - IsGlobalAlias globals instructions.globals "Ops". -Axiom instructions_op_implementation : - IsGlobalAlias globals instructions.globals "op_implementation". - -Require runtime. -Axiom runtime_get_valid_jump_destinations : - IsGlobalAlias globals runtime.globals "get_valid_jump_destinations". +Require ethereum.tangerine_whistle.blocks. +Axiom ethereum_tangerine_whistle_blocks_Log : + IsGlobalAlias globals ethereum.tangerine_whistle.blocks.globals "Log". + +Require ethereum.tangerine_whistle.fork_types. +Axiom ethereum_tangerine_whistle_fork_types_Address : + IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "Address". + +Require ethereum.tangerine_whistle.state. +Axiom ethereum_tangerine_whistle_state_account_has_code_or_nonce : + IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "account_has_code_or_nonce". +Axiom ethereum_tangerine_whistle_state_begin_transaction : + IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "begin_transaction". +Axiom ethereum_tangerine_whistle_state_commit_transaction : + IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "commit_transaction". +Axiom ethereum_tangerine_whistle_state_destroy_storage : + IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "destroy_storage". +Axiom ethereum_tangerine_whistle_state_move_ether : + IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "move_ether". +Axiom ethereum_tangerine_whistle_state_rollback_transaction : + IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "rollback_transaction". +Axiom ethereum_tangerine_whistle_state_set_code : + IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "set_code". +Axiom ethereum_tangerine_whistle_state_touch_account : + IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "touch_account". + +Require ethereum.tangerine_whistle.vm.__init__. +Axiom ethereum_tangerine_whistle_vm___init___Message : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "Message". + +Require ethereum.tangerine_whistle.vm.gas. +Axiom ethereum_tangerine_whistle_vm_gas_GAS_CODE_DEPOSIT : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_CODE_DEPOSIT". +Axiom ethereum_tangerine_whistle_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "charge_gas". + +Require ethereum.tangerine_whistle.vm.precompiled_contracts.mapping. +Axiom ethereum_tangerine_whistle_vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". + +Require ethereum.tangerine_whistle.vm.__init__. +Axiom ethereum_tangerine_whistle_vm___init___Environment : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "Environment". +Axiom ethereum_tangerine_whistle_vm___init___Evm : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "Evm". + +Require ethereum.tangerine_whistle.vm.exceptions. +Axiom ethereum_tangerine_whistle_vm_exceptions_AddressCollision : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.exceptions.globals "AddressCollision". +Axiom ethereum_tangerine_whistle_vm_exceptions_ExceptionalHalt : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.exceptions.globals "ExceptionalHalt". +Axiom ethereum_tangerine_whistle_vm_exceptions_InvalidOpcode : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.exceptions.globals "InvalidOpcode". +Axiom ethereum_tangerine_whistle_vm_exceptions_StackDepthLimitError : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.exceptions.globals "StackDepthLimitError". + +Require ethereum.tangerine_whistle.vm.instructions.__init__. +Axiom ethereum_tangerine_whistle_vm_instructions___init___Ops : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.instructions.__init__.globals "Ops". +Axiom ethereum_tangerine_whistle_vm_instructions___init___op_implementation : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.instructions.__init__.globals "op_implementation". + +Require ethereum.tangerine_whistle.vm.runtime. +Axiom ethereum_tangerine_whistle_vm_runtime_get_valid_jump_destinations : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.runtime.globals "get_valid_jump_destinations". Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -162,6 +162,89 @@ Definition process_message_call : Value.t -> Value.t -> M := Output of the message call " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_field (| M.get_name (| globals, "message" |), "target" |), + M.call (| + M.get_name (| globals, "Bytes0" |), + make_list [ + Constant.bytes "" + ], + make_dict [] + |) + |), + (* then *) + ltac:(M.monadic ( + let is_collision := + M.call (| + M.get_name (| globals, "account_has_code_or_nonce" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + M.get_name (| globals, "is_collision" |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.call (| + M.get_name (| globals, "MessageCallOutput" |), + make_list [ + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |); + M.call (| + M.get_name (| globals, "tuple" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |); + M.call (| + M.get_name (| globals, "AddressCollision" |), + make_list [], + make_dict [] + |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let evm := + M.call (| + M.get_name (| globals, "process_create_message" |), + make_list [ + M.get_name (| globals, "message" |); + M.get_name (| globals, "env" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let evm := M.call (| M.get_name (| globals, "process_message" |), @@ -174,6 +257,29 @@ Definition process_message_call : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( +(* At stmt: unsupported node type: AnnAssign *) + let accounts_to_delete := + M.call (| + M.get_name (| globals, "set" |), + make_list [], + make_dict [] + |) in + let refund_counter := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let logs := M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in let accounts_to_delete := @@ -209,6 +315,7 @@ Definition process_message_call : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). Definition process_create_message : Value.t -> Value.t -> M := @@ -254,6 +361,28 @@ Definition process_create_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), + (* then *) + ltac:(M.monadic ( + let contract_code := + M.get_field (| M.get_name (| globals, "evm" |), "output" |) in + let contract_code_gas := + BinOp.mult (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "contract_code" |) + ], + make_dict [] + |), + M.get_name (| globals, "GAS_CODE_DEPOSIT" |) + |) in +(* At stmt: unsupported node type: Try *) + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "rollback_transaction" |), make_list [ @@ -265,6 +394,7 @@ Definition process_create_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) + |) in M.pure Constant.None_)). Definition process_message : Value.t -> Value.t -> M := @@ -286,6 +416,24 @@ Definition process_message : Value.t -> Value.t -> M := Items containing execution specific objects " in let _ := + (* if *) + M.if_then_else (| + Compare.gt (| + M.get_field (| M.get_name (| globals, "message" |), "depth" |), + M.get_name (| globals, "STACK_DEPTH_LIMIT" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.call (| + M.get_name (| globals, "StackDepthLimitError" |), + make_list [ + Constant.str "Stack depth limit reached" + ], + make_dict [] + |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.call (| @@ -304,6 +452,32 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + M.get_field (| M.get_name (| globals, "message" |), "should_transfer_value" |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_field (| M.get_name (| globals, "message" |), "value" |), + Constant.int 0 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "move_ether" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_field (| M.get_name (| globals, "message" |), "caller" |); + M.get_field (| M.get_name (| globals, "message" |), "current_target" |); + M.get_field (| M.get_name (| globals, "message" |), "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let evm := @@ -316,6 +490,21 @@ Definition process_message : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "evm" |), "error" |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_name (| globals, "rollback_transaction" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.call (| M.get_name (| globals, "commit_transaction" |), make_list [ @@ -327,6 +516,7 @@ Definition process_message : Value.t -> Value.t -> M := )) |) in let _ := M.return_ (| M.get_name (| globals, "evm" |) + |) in M.pure Constant.None_)). Definition execute_code : Value.t -> Value.t -> M := @@ -366,4 +556,5 @@ Definition execute_code : Value.t -> Value.t -> M := (* At stmt: unsupported node type: Try *) let _ := M.return_ (| M.get_name (| globals, "evm" |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/memory.v b/CoqOfPython/ethereum/tangerine_whistle/vm/memory.v index 4b107fd..08d2290 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/memory.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/memory.v @@ -21,13 +21,13 @@ Require ethereum.utils.byte. Axiom ethereum_utils_byte_right_pad_zero_bytes : IsGlobalAlias globals ethereum.utils.byte.globals "right_pad_zero_bytes". -Require base_types. -Axiom base_types_U256 : - IsGlobalAlias globals base_types.globals "U256". -Axiom base_types_Bytes : - IsGlobalAlias globals base_types.globals "Bytes". -Axiom base_types_Uint : - IsGlobalAlias globals base_types.globals "Uint". +Require ethereum.base_types. +Axiom ethereum_base_types_U256 : + IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_Bytes : + IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_Uint : + IsGlobalAlias globals ethereum.base_types.globals "Uint". Definition memory_write : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,7 +45,22 @@ Definition memory_write : Value.t -> Value.t -> M := Data to write to memory. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |), + M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) + |) |) |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_)). @@ -71,7 +86,23 @@ Definition memory_read_bytes : Value.t -> Value.t -> M := Data read from memory. " in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.get_name (| globals, "start_position" |) |) + M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |) |) + |) in M.pure Constant.None_)). Definition buffer_read : Value.t -> Value.t -> M := @@ -98,9 +129,25 @@ Definition buffer_read : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "right_pad_zero_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "buffer" |), M.get_name (| globals, "start_position" |) |); + M.get_subscript (| M.get_name (| globals, "buffer" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) |) |); M.get_name (| globals, "size" |) ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/__init__.v index 422f670..4e1e63a 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/__init__.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/__init__.v @@ -18,9 +18,9 @@ Addresses of precompiled contracts and mappings to their implementations. ". -Require utils.hexadecimal. -Axiom utils_hexadecimal_hex_to_address : - IsGlobalAlias globals utils.hexadecimal.globals "hex_to_address". +Require ethereum.tangerine_whistle.utils.hexadecimal. +Axiom ethereum_tangerine_whistle_utils_hexadecimal_hex_to_address : + IsGlobalAlias globals ethereum.tangerine_whistle.utils.hexadecimal.globals "hex_to_address". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS" ] diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/ecrecover.v index 0cbcf16..63cef4d 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/ecrecover.v @@ -37,19 +37,19 @@ Require ethereum.utils.byte. Axiom ethereum_utils_byte_left_pad_zero_bytes : IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.tangerine_whistle.vm.__init__. +Axiom ethereum_tangerine_whistle_vm___init___Evm : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_ECRECOVER : - IsGlobalAlias globals vm.gas.globals "GAS_ECRECOVER". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.tangerine_whistle.vm.gas. +Axiom ethereum_tangerine_whistle_vm_gas_GAS_ECRECOVER : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_ECRECOVER". +Axiom ethereum_tangerine_whistle_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "charge_gas". -Require vm.memory. -Axiom vm_memory_buffer_read : - IsGlobalAlias globals vm.memory.globals "buffer_read". +Require ethereum.tangerine_whistle.vm.memory. +Axiom ethereum_tangerine_whistle_vm_memory_buffer_read : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.memory.globals "buffer_read". Definition ecrecover : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -188,12 +188,78 @@ Definition ecrecover : Value.t -> Value.t -> M := make_dict [] |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "v" |), + Constant.int 27 + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "v" |), + Constant.int 28 + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + Constant.int 0, + M.get_name (| globals, "r" |) + |), + ltac:(M.monadic ( + Compare.gt_e (| + M.get_name (| globals, "r" |), + M.get_name (| globals, "SECP256K1N" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + Constant.int 0, + M.get_name (| globals, "s" |) + |), + ltac:(M.monadic ( + Compare.gt_e (| + M.get_name (| globals, "s" |), + M.get_name (| globals, "SECP256K1N" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: Try *) @@ -204,7 +270,7 @@ Definition ecrecover : Value.t -> Value.t -> M := M.get_name (| globals, "public_key" |) ], make_dict [] - |), Constant.int 12 |) in + |), M.slice (| Constant.int 12, Constant.int 32 |) |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/identity.v index fa96704..68036e2 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/identity.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/identity.v @@ -25,17 +25,17 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.tangerine_whistle.vm.__init__. +Axiom ethereum_tangerine_whistle_vm___init___Evm : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_IDENTITY : - IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY". -Axiom vm_gas_GAS_IDENTITY_WORD : - IsGlobalAlias globals vm.gas.globals "GAS_IDENTITY_WORD". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.tangerine_whistle.vm.gas. +Axiom ethereum_tangerine_whistle_vm_gas_GAS_IDENTITY : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_IDENTITY". +Axiom ethereum_tangerine_whistle_vm_gas_GAS_IDENTITY_WORD : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_IDENTITY_WORD". +Axiom ethereum_tangerine_whistle_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "charge_gas". Definition identity : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/mapping.v index 710457d..5f05c47 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/mapping.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/mapping.v @@ -23,34 +23,34 @@ Axiom typing_Callable : Axiom typing_Dict : IsGlobalAlias globals typing.globals "Dict". -Require fork_types. -Axiom fork_types_Address : - IsGlobalAlias globals fork_types.globals "Address". - -Require __init__. -Axiom __init___ECRECOVER_ADDRESS : - IsGlobalAlias globals __init__.globals "ECRECOVER_ADDRESS". -Axiom __init___IDENTITY_ADDRESS : - IsGlobalAlias globals __init__.globals "IDENTITY_ADDRESS". -Axiom __init___RIPEMD160_ADDRESS : - IsGlobalAlias globals __init__.globals "RIPEMD160_ADDRESS". -Axiom __init___SHA256_ADDRESS : - IsGlobalAlias globals __init__.globals "SHA256_ADDRESS". - -Require ecrecover. -Axiom ecrecover_ecrecover : - IsGlobalAlias globals ecrecover.globals "ecrecover". - -Require identity. -Axiom identity_identity : - IsGlobalAlias globals identity.globals "identity". - -Require ripemd160. -Axiom ripemd160_ripemd160 : - IsGlobalAlias globals ripemd160.globals "ripemd160". - -Require sha256. -Axiom sha256_sha256 : - IsGlobalAlias globals sha256.globals "sha256". +Require ethereum.tangerine_whistle.fork_types. +Axiom ethereum_tangerine_whistle_fork_types_Address : + IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "Address". + +Require ethereum.tangerine_whistle.vm.precompiled_contracts.__init__. +Axiom ethereum_tangerine_whistle_vm_precompiled_contracts___init___ECRECOVER_ADDRESS : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.precompiled_contracts.__init__.globals "ECRECOVER_ADDRESS". +Axiom ethereum_tangerine_whistle_vm_precompiled_contracts___init___IDENTITY_ADDRESS : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.precompiled_contracts.__init__.globals "IDENTITY_ADDRESS". +Axiom ethereum_tangerine_whistle_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". +Axiom ethereum_tangerine_whistle_vm_precompiled_contracts___init___SHA256_ADDRESS : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.precompiled_contracts.__init__.globals "SHA256_ADDRESS". + +Require ethereum.tangerine_whistle.vm.precompiled_contracts.ecrecover. +Axiom ethereum_tangerine_whistle_vm_precompiled_contracts_ecrecover_ecrecover : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.precompiled_contracts.ecrecover.globals "ecrecover". + +Require ethereum.tangerine_whistle.vm.precompiled_contracts.identity. +Axiom ethereum_tangerine_whistle_vm_precompiled_contracts_identity_identity : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.precompiled_contracts.identity.globals "identity". + +Require ethereum.tangerine_whistle.vm.precompiled_contracts.ripemd160. +Axiom ethereum_tangerine_whistle_vm_precompiled_contracts_ripemd160_ripemd160 : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.precompiled_contracts.ripemd160.globals "ripemd160". + +Require ethereum.tangerine_whistle.vm.precompiled_contracts.sha256. +Axiom ethereum_tangerine_whistle_vm_precompiled_contracts_sha256_sha256 : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.precompiled_contracts.sha256.globals "sha256". (* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/ripemd160.v index 96f8dcd..c2f4b20 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/ripemd160.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/ripemd160.v @@ -31,17 +31,17 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.tangerine_whistle.vm.__init__. +Axiom ethereum_tangerine_whistle_vm___init___Evm : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_RIPEMD160 : - IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160". -Axiom vm_gas_GAS_RIPEMD160_WORD : - IsGlobalAlias globals vm.gas.globals "GAS_RIPEMD160_WORD". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.tangerine_whistle.vm.gas. +Axiom ethereum_tangerine_whistle_vm_gas_GAS_RIPEMD160 : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_RIPEMD160". +Axiom ethereum_tangerine_whistle_vm_gas_GAS_RIPEMD160_WORD : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_RIPEMD160_WORD". +Axiom ethereum_tangerine_whistle_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "charge_gas". Definition ripemd160 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/sha256.v index 9f6d2bf..c2ff5d8 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/sha256.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/sha256.v @@ -27,17 +27,17 @@ Require ethereum.utils.numeric. Axiom ethereum_utils_numeric_ceil32 : IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Require vm. -Axiom vm_Evm : - IsGlobalAlias globals vm.globals "Evm". +Require ethereum.tangerine_whistle.vm.__init__. +Axiom ethereum_tangerine_whistle_vm___init___Evm : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "Evm". -Require vm.gas. -Axiom vm_gas_GAS_SHA256 : - IsGlobalAlias globals vm.gas.globals "GAS_SHA256". -Axiom vm_gas_GAS_SHA256_WORD : - IsGlobalAlias globals vm.gas.globals "GAS_SHA256_WORD". -Axiom vm_gas_charge_gas : - IsGlobalAlias globals vm.gas.globals "charge_gas". +Require ethereum.tangerine_whistle.vm.gas. +Axiom ethereum_tangerine_whistle_vm_gas_GAS_SHA256 : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_SHA256". +Axiom ethereum_tangerine_whistle_vm_gas_GAS_SHA256_WORD : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_SHA256_WORD". +Axiom ethereum_tangerine_whistle_vm_gas_charge_gas : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "charge_gas". Definition sha256 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/runtime.v b/CoqOfPython/ethereum/tangerine_whistle/vm/runtime.v index 2cd7652..7ff8cc5 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/runtime.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/runtime.v @@ -25,9 +25,9 @@ Require ethereum.base_types. Axiom ethereum_base_types_Uint : IsGlobalAlias globals ethereum.base_types.globals "Uint". -Require instructions. -Axiom instructions_Ops : - IsGlobalAlias globals instructions.globals "Ops". +Require ethereum.tangerine_whistle.vm.instructions.__init__. +Axiom ethereum_tangerine_whistle_vm_instructions___init___Ops : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.instructions.__init__.globals "Ops". Definition get_valid_jump_destinations : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -79,7 +79,55 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := |) do (* At stmt: unsupported node type: Try *) let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "current_opcode" |), + M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| + M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), + make_list [ + M.get_name (| globals, "pc" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.lt_e (| + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |), + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH32" |), "value" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let push_data_size := + BinOp.add (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) + |), + Constant.int 1 + |) in + let pc := BinOp.add + M.get_name (| globals, "push_data_size" |) + M.get_name (| globals, "push_data_size" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -90,4 +138,5 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := EndWhile. let _ := M.return_ (| M.get_name (| globals, "valid_jump_destinations" |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/stack.v b/CoqOfPython/ethereum/tangerine_whistle/vm/stack.v index ea778df..8123c16 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/stack.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/stack.v @@ -25,11 +25,11 @@ Require ethereum.base_types. Axiom ethereum_base_types_U256 : IsGlobalAlias globals ethereum.base_types.globals "U256". -Require exceptions. -Axiom exceptions_StackOverflowError : - IsGlobalAlias globals exceptions.globals "StackOverflowError". -Axiom exceptions_StackUnderflowError : - IsGlobalAlias globals exceptions.globals "StackUnderflowError". +Require ethereum.tangerine_whistle.vm.exceptions. +Axiom ethereum_tangerine_whistle_vm_exceptions_StackOverflowError : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.exceptions.globals "StackOverflowError". +Axiom ethereum_tangerine_whistle_vm_exceptions_StackUnderflowError : + IsGlobalAlias globals ethereum.tangerine_whistle.vm.exceptions.globals "StackUnderflowError". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -49,6 +49,24 @@ Definition pop : Value.t -> Value.t -> M := " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "StackUnderflowError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -57,6 +75,7 @@ Definition pop : Value.t -> Value.t -> M := make_list [], make_dict [] |) + |) in M.pure Constant.None_)). Definition push : Value.t -> Value.t -> M := @@ -75,6 +94,24 @@ Definition push : Value.t -> Value.t -> M := " in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "stack" |) + ], + make_dict [] + |), + Constant.int 1024 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some(M.get_name (| globals, "StackOverflowError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -85,4 +122,5 @@ Definition push : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/utils/byte.v b/CoqOfPython/ethereum/utils/byte.v index e2af2e7..50eac5b 100644 --- a/CoqOfPython/ethereum/utils/byte.v +++ b/CoqOfPython/ethereum/utils/byte.v @@ -48,6 +48,7 @@ Definition left_pad_zero_bytes : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition right_pad_zero_bytes : Value.t -> Value.t -> M := @@ -77,4 +78,5 @@ Definition right_pad_zero_bytes : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/utils/ensure.v b/CoqOfPython/ethereum/utils/ensure.v index 6c42595..58534bc 100644 --- a/CoqOfPython/ethereum/utils/ensure.v +++ b/CoqOfPython/ethereum/utils/ensure.v @@ -40,7 +40,18 @@ Definition ensure : Value.t -> Value.t -> M := Constructor for the exception to raise. " in let _ := + (* if *) + M.if_then_else (| + M.get_name (| globals, "value" |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.None_ + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let _ := M.raise (| Some(M.get_name (| globals, "exception" |)) + let _ := M.raise (| Some(M.get_name (| globals, "exception" |)) |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/utils/hexadecimal.v b/CoqOfPython/ethereum/utils/hexadecimal.v index ed68a01..18fc6f1 100644 --- a/CoqOfPython/ethereum/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/utils/hexadecimal.v @@ -63,6 +63,7 @@ Definition has_hex_prefix : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition remove_hex_prefix : Value.t -> Value.t -> M := @@ -83,10 +84,34 @@ Definition remove_hex_prefix : Value.t -> Value.t -> M := The hexadecimal string with the 0x prefix removed if present. " in let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "has_hex_prefix" |), + make_list [ + M.get_name (| globals, "hex_string" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_subscript (| M.get_name (| globals, "hex_string" |), M.slice (| M.call (| + M.get_name (| globals, "len" |), + make_list [ + Constant.str "0x" + ], + make_dict [] + |), Constant.None_ |) |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in let _ := M.return_ (| M.get_name (| globals, "hex_string" |) + |) in M.pure Constant.None_)). Definition hex_to_bytes : Value.t -> Value.t -> M := @@ -119,6 +144,7 @@ Definition hex_to_bytes : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition hex_to_bytes8 : Value.t -> Value.t -> M := @@ -164,6 +190,7 @@ Definition hex_to_bytes8 : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition hex_to_bytes20 : Value.t -> Value.t -> M := @@ -209,6 +236,7 @@ Definition hex_to_bytes20 : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition hex_to_bytes32 : Value.t -> Value.t -> M := @@ -254,6 +282,7 @@ Definition hex_to_bytes32 : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition hex_to_bytes256 : Value.t -> Value.t -> M := @@ -299,6 +328,7 @@ Definition hex_to_bytes256 : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition hex_to_hash : Value.t -> Value.t -> M := @@ -337,6 +367,7 @@ Definition hex_to_hash : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition hex_to_uint : Value.t -> Value.t -> M := @@ -376,6 +407,7 @@ Definition hex_to_uint : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition hex_to_u64 : Value.t -> Value.t -> M := @@ -415,6 +447,7 @@ Definition hex_to_u64 : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition hex_to_u256 : Value.t -> Value.t -> M := @@ -454,4 +487,5 @@ Definition hex_to_u256 : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/utils/numeric.v b/CoqOfPython/ethereum/utils/numeric.v index d737980..b31bf33 100644 --- a/CoqOfPython/ethereum/utils/numeric.v +++ b/CoqOfPython/ethereum/utils/numeric.v @@ -47,9 +47,38 @@ Definition get_sign : Value.t -> Value.t -> M := The return value is based on math signum function. " in let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + UnOp.sub (| Constant.int 1 |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "value" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.int 0 + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| Constant.int 1 + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -88,6 +117,26 @@ Definition ceil32 : Value.t -> Value.t -> M := M.get_name (| globals, "ceiling" |) |) in let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "remainder" |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + Constant.int 0 + ], + make_dict [] + |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "value" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( let _ := M.return_ (| BinOp.sub (| BinOp.add (| @@ -96,6 +145,7 @@ Definition ceil32 : Value.t -> Value.t -> M := |), M.get_name (| globals, "remainder" |) |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_)). @@ -117,6 +167,20 @@ Definition is_prime : Value.t -> Value.t -> M := Boolean indicating if `number` is prime or not. " in let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "number" |), + Constant.int 1 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in For M.get_name (| globals, "x" |) in M.call (| @@ -140,11 +204,29 @@ Definition is_prime : Value.t -> Value.t -> M := make_dict [] |) do let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + BinOp.mod_ (| + M.get_name (| globals, "number" |), + M.get_name (| globals, "x" |) + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in EndFor. let _ := M.return_ (| Constant.bool true + |) in M.pure Constant.None_)). Definition le_bytes_to_uint32_sequence : Value.t -> Value.t -> M := @@ -190,7 +272,10 @@ Definition le_bytes_to_uint32_sequence : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "U32" |), "from_le_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "data" |), M.get_name (| globals, "i" |) |) + M.get_subscript (| M.get_name (| globals, "data" |), M.slice (| M.get_name (| globals, "i" |), BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 4 + |) |) |) ], make_dict [] |) @@ -206,6 +291,7 @@ Definition le_bytes_to_uint32_sequence : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition le_uint32_sequence_to_bytes : Value.t -> Value.t -> M := @@ -252,6 +338,7 @@ Definition le_uint32_sequence_to_bytes : Value.t -> Value.t -> M := EndFor. let _ := M.return_ (| M.get_name (| globals, "result_bytes" |) + |) in M.pure Constant.None_)). Definition le_uint32_sequence_to_uint : Value.t -> Value.t -> M := @@ -289,6 +376,7 @@ Definition le_uint32_sequence_to_uint : Value.t -> Value.t -> M := ], make_dict [] |) + |) in M.pure Constant.None_)). Definition taylor_exponential : Value.t -> Value.t -> M := @@ -349,4 +437,5 @@ Definition taylor_exponential : Value.t -> Value.t -> M := M.get_name (| globals, "output" |), M.get_name (| globals, "denominator" |) |) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/functools.v b/CoqOfPython/functools.v new file mode 100644 index 0000000..98750ac --- /dev/null +++ b/CoqOfPython/functools.v @@ -0,0 +1,3 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. diff --git a/CoqOfPython/typing_extensions.v b/CoqOfPython/typing_extensions.v new file mode 100644 index 0000000..98750ac --- /dev/null +++ b/CoqOfPython/typing_extensions.v @@ -0,0 +1,3 @@ +Require Import CoqOfPython.CoqOfPython. + +Inductive globals : Set :=. diff --git a/convert_all.py b/convert_all.py index 6bd9380..5e85864 100644 --- a/convert_all.py +++ b/convert_all.py @@ -15,7 +15,7 @@ print("Converting file: " + short_path) try: - command = "python main.py " + short_path + command = "python main.py " + folder_to_convert + " " + short_path print(command) subprocess.run(command, shell=True, check=True) except subprocess.CalledProcessError as e: diff --git a/main.py b/main.py index 707cdc4..d4db1da 100644 --- a/main.py +++ b/main.py @@ -15,6 +15,9 @@ def generate_error(kind, node): print(message, file=sys.stderr) + if kind == "expr": + return f"Constant.str \"{message}\"" + return message @@ -77,6 +80,38 @@ def generate_mod(node: ast.mod): return generate_error("mod", node) +def get_require_path_from_path(path: str) -> str: + # Check if it is a folder + if os.path.isdir(path): + require_path = path + "/__init__" + else: + require_path = path + + return require_path.replace("/", ".") + + +def get_require_path(node: ast.ImportFrom) -> str: + module = node.module.replace(".", "/") if node.module is not None else "" + + # If this is an external package + if node.level == 0 and module.split("/")[0] != "ethereum": + return module.replace("/", ".") + + # Otherwise we map the module to an actual file system path + # Absolute path + if node.level == 0: + return get_require_path_from_path(module) + + # Relative path + actual_path = input_file_name + for _ in range(node.level): + actual_path = os.path.dirname(actual_path) + if module != "": + actual_path += "/" + module + + return get_require_path_from_path(actual_path) + + def generate_top_level_stmt(node: ast.stmt): if isinstance(node, ast.FunctionDef): return f"Definition {node.name} : Value.t -> Value.t -> M :=\n" + \ @@ -85,8 +120,7 @@ def generate_top_level_stmt(node: ast.stmt): return generate_error("top_level_stmt", node) elif isinstance(node, ast.ClassDef): text = f"Definition {generate_name(node.name)} : Value.t :=\n" - text += generate_indent(1) + \ - "builtins.make_klass\n" + text += generate_indent(1) + "builtins.make_klass\n" # Bases text += generate_indent(2) + "[" @@ -152,7 +186,7 @@ def generate_top_level_stmt(node: ast.stmt): elif isinstance(node, ast.Import): return generate_error("top_level_stmt", node) elif isinstance(node, ast.ImportFrom): - module = node.module if node.module is not None else "__init__" + module = get_require_path(node) snake_module = module.replace(".", "_") return f"Require {module}.\n" + \ @@ -188,22 +222,22 @@ def generate_if_then_else( indent, condition: ast.expr, success: ast.expr | list[ast.stmt], - error: ast.expr | list[ast.stmt] + error: ast.expr | list[ast.stmt], ): return generate_indent(indent) + "(* if *)\n" + \ generate_indent(indent) + "M.if_then_else (|\n" + \ generate_indent(indent + 1) + generate_expr(indent + 1, False, condition) + ",\n" + \ generate_indent(indent) + "(* then *)\n" + \ generate_indent(indent) + "ltac:(M.monadic (\n" + \ - generate_expr(indent + 1, False, success) \ - if isinstance(success, ast.expr) \ - else generate_stmts(indent + 1, success) + \ + (generate_expr(indent + 1, False, success) + if isinstance(success, ast.expr) + else generate_stmts(indent + 1, success)) + \ "\n" + \ generate_indent(indent) + "(* else *)\n" + \ generate_indent(indent) + ")), ltac:(M.monadic (\n" + \ - generate_expr(indent + 1, False, error) \ - if isinstance(error, ast.expr) \ - else generate_stmts(indent + 1, error) + \ + (generate_expr(indent + 1, False, error) + if isinstance(error, ast.expr) + else generate_stmts(indent + 1, error)) + \ "\n" + \ generate_indent(indent) + ")) |)" @@ -225,9 +259,9 @@ def generate_stmt(indent, node: ast.stmt): elif isinstance(node, ast.Return): return generate_indent(indent) + "let _ := M.return_ (|\n" + \ generate_indent(indent + 1) + \ - generate_expr(indent + 1, False, node.value) \ - if node.value is not None \ - else "Constant.None_" + \ + (generate_expr(indent + 1, False, node.value) + if node.value is not None + else "Constant.None_") + \ "\n" + \ generate_indent(indent) + "|) in" elif isinstance(node, ast.Delete): @@ -293,9 +327,9 @@ def generate_stmt(indent, node: ast.stmt): return generate_error("stmt", node) elif isinstance(node, ast.Raise): return generate_indent(indent) + "let _ := M.raise (| " + \ - "Some(" + generate_expr(indent, False, node.exc) + ")" \ - if node.exc is not None \ - else "None" + \ + ("Some(" + generate_expr(indent, False, node.exc) + ")" + if node.exc is not None + else "None") + \ " |) in" elif isinstance(node, ast.Try): return generate_error("stmt", node) @@ -465,14 +499,14 @@ def generate_expr(indent, is_with_paren, node: ast.expr): elif isinstance(node, ast.IfExp): return paren( is_with_paren, - generate_if_then_else(0, node.test, node.body, node.orelse) + generate_if_then_else(indent, node.test, node.body, node.orelse) ) elif isinstance(node, ast.Dict): return "{" + \ ", ".join( - generate_expr(indent, False, key) - if key is not None - else "?" + + (generate_expr(indent, False, key) + if key is not None + else "?") + ": " + generate_expr(indent, False, value) for key, value in zip(node.keys, node.values) ) + \ @@ -496,9 +530,9 @@ def generate_expr(indent, is_with_paren, node: ast.expr): return paren( is_with_paren, "M.yield (| " + - generate_expr(indent, False, node.value) - if node.value is not None - else "Constant.None_" + + (generate_expr(indent, False, node.value) + if node.value is not None + else "Constant.None_") + " |)" ) elif isinstance(node, ast.YieldFrom): @@ -560,13 +594,15 @@ def generate_expr(indent, is_with_paren, node: ast.expr): elif isinstance(node, ast.Slice): return paren( is_with_paren, - generate_expr(indent, False, node.lower) - if node.lower is not None - else "Constant.None_" + - ":" + - generate_expr(indent, False, node.upper) - if node.upper is not None - else "Constant.None_" + "M.slice (| " + + (generate_expr(indent, False, node.lower) + if node.lower is not None + else "Constant.None_") + + ", " + + (generate_expr(indent, False, node.upper) + if node.upper is not None + else "Constant.None_") + + " |)" ) else: return generate_error("expr", node) @@ -654,8 +690,9 @@ def generate_arg(node): return generate_name(node.arg) -input_file_name = "../execution-specs/src/ethereum/" + sys.argv[1] -output_file_name = "CoqOfPython/ethereum/" + sys.argv[1].replace(".py", ".v") +input_file_name = sys.argv[1] +output_file_name = "../../translate-ethereum-specs/CoqOfPython/" + \ + input_file_name.replace(".py", ".v") file_content = open(input_file_name).read() parsed_tree = ast.parse(file_content) From ca2ba29dacd62128d722bb218bfce62ab60ba0a8 Mon Sep 17 00:00:00 2001 From: Guillaume Claret Date: Fri, 10 May 2024 19:30:38 +0200 Subject: [PATCH 4/6] Translate more code --- CoqOfPython/CoqOfPython.v | 48 +- CoqOfPython/blacklist.txt | 1 + CoqOfPython/ethereum/__init__.v | 2 +- CoqOfPython/ethereum/arrow_glacier/__init__.v | 7 +- CoqOfPython/ethereum/arrow_glacier/blocks.v | 58 +- CoqOfPython/ethereum/arrow_glacier/bloom.v | 159 +- CoqOfPython/ethereum/arrow_glacier/fork.v | 765 ++++----- .../ethereum/arrow_glacier/fork_types.v | 40 +- CoqOfPython/ethereum/arrow_glacier/state.v | 107 +- .../ethereum/arrow_glacier/transactions.v | 79 +- CoqOfPython/ethereum/arrow_glacier/trie.v | 858 ++++++----- .../ethereum/arrow_glacier/utils/__init__.v | 2 +- .../ethereum/arrow_glacier/utils/address.v | 65 +- .../arrow_glacier/utils/hexadecimal.v | 18 +- .../ethereum/arrow_glacier/utils/message.v | 55 +- .../ethereum/arrow_glacier/vm/__init__.v | 64 +- .../ethereum/arrow_glacier/vm/exceptions.v | 7 +- CoqOfPython/ethereum/arrow_glacier/vm/gas.v | 224 ++- .../arrow_glacier/vm/instructions/__init__.v | 69 +- .../vm/instructions/arithmetic.v | 75 +- .../arrow_glacier/vm/instructions/bitwise.v | 28 +- .../arrow_glacier/vm/instructions/block.v | 39 +- .../vm/instructions/comparison.v | 26 +- .../vm/instructions/control_flow.v | 43 +- .../vm/instructions/environment.v | 125 +- .../arrow_glacier/vm/instructions/keccak.v | 59 +- .../arrow_glacier/vm/instructions/log.v | 120 +- .../arrow_glacier/vm/instructions/memory.v | 39 +- .../arrow_glacier/vm/instructions/stack.v | 96 +- .../arrow_glacier/vm/instructions/storage.v | 59 +- .../arrow_glacier/vm/instructions/system.v | 128 +- .../ethereum/arrow_glacier/vm/interpreter.v | 169 +- .../ethereum/arrow_glacier/vm/memory.v | 121 +- .../vm/precompiled_contracts/__init__.v | 7 +- .../vm/precompiled_contracts/alt_bn128.v | 368 ++--- .../vm/precompiled_contracts/blake2f.v | 31 +- .../vm/precompiled_contracts/ecrecover.v | 62 +- .../vm/precompiled_contracts/identity.v | 26 +- .../vm/precompiled_contracts/mapping.v | 92 +- .../vm/precompiled_contracts/modexp.v | 26 +- .../vm/precompiled_contracts/ripemd160.v | 31 +- .../vm/precompiled_contracts/sha256.v | 26 +- .../ethereum/arrow_glacier/vm/runtime.v | 137 +- CoqOfPython/ethereum/arrow_glacier/vm/stack.v | 23 +- CoqOfPython/ethereum/base_types.v | 170 +- CoqOfPython/ethereum/berlin/__init__.v | 7 +- CoqOfPython/ethereum/berlin/blocks.v | 58 +- CoqOfPython/ethereum/berlin/bloom.v | 159 +- CoqOfPython/ethereum/berlin/fork.v | 757 ++++----- CoqOfPython/ethereum/berlin/fork_types.v | 40 +- CoqOfPython/ethereum/berlin/state.v | 107 +- CoqOfPython/ethereum/berlin/transactions.v | 82 +- CoqOfPython/ethereum/berlin/trie.v | 858 ++++++----- CoqOfPython/ethereum/berlin/utils/__init__.v | 2 +- CoqOfPython/ethereum/berlin/utils/address.v | 65 +- .../ethereum/berlin/utils/hexadecimal.v | 18 +- CoqOfPython/ethereum/berlin/utils/message.v | 55 +- CoqOfPython/ethereum/berlin/vm/__init__.v | 64 +- CoqOfPython/ethereum/berlin/vm/exceptions.v | 7 +- CoqOfPython/ethereum/berlin/vm/gas.v | 224 ++- .../berlin/vm/instructions/__init__.v | 69 +- .../berlin/vm/instructions/arithmetic.v | 75 +- .../ethereum/berlin/vm/instructions/bitwise.v | 28 +- .../ethereum/berlin/vm/instructions/block.v | 39 +- .../berlin/vm/instructions/comparison.v | 26 +- .../berlin/vm/instructions/control_flow.v | 43 +- .../berlin/vm/instructions/environment.v | 125 +- .../ethereum/berlin/vm/instructions/keccak.v | 59 +- .../ethereum/berlin/vm/instructions/log.v | 120 +- .../ethereum/berlin/vm/instructions/memory.v | 39 +- .../ethereum/berlin/vm/instructions/stack.v | 96 +- .../ethereum/berlin/vm/instructions/storage.v | 59 +- .../ethereum/berlin/vm/instructions/system.v | 154 +- CoqOfPython/ethereum/berlin/vm/interpreter.v | 167 +- CoqOfPython/ethereum/berlin/vm/memory.v | 121 +- .../vm/precompiled_contracts/__init__.v | 7 +- .../vm/precompiled_contracts/alt_bn128.v | 368 ++--- .../berlin/vm/precompiled_contracts/blake2f.v | 31 +- .../vm/precompiled_contracts/ecrecover.v | 62 +- .../vm/precompiled_contracts/identity.v | 26 +- .../berlin/vm/precompiled_contracts/mapping.v | 92 +- .../berlin/vm/precompiled_contracts/modexp.v | 26 +- .../vm/precompiled_contracts/ripemd160.v | 31 +- .../berlin/vm/precompiled_contracts/sha256.v | 26 +- CoqOfPython/ethereum/berlin/vm/runtime.v | 137 +- CoqOfPython/ethereum/berlin/vm/stack.v | 23 +- CoqOfPython/ethereum/byzantium/__init__.v | 7 +- CoqOfPython/ethereum/byzantium/blocks.v | 56 +- CoqOfPython/ethereum/byzantium/bloom.v | 159 +- CoqOfPython/ethereum/byzantium/fork.v | 674 ++++---- CoqOfPython/ethereum/byzantium/fork_types.v | 40 +- CoqOfPython/ethereum/byzantium/state.v | 98 +- CoqOfPython/ethereum/byzantium/transactions.v | 36 +- CoqOfPython/ethereum/byzantium/trie.v | 852 +++++----- .../ethereum/byzantium/utils/__init__.v | 2 +- .../ethereum/byzantium/utils/address.v | 56 +- .../ethereum/byzantium/utils/hexadecimal.v | 18 +- .../ethereum/byzantium/utils/message.v | 44 +- CoqOfPython/ethereum/byzantium/vm/__init__.v | 74 +- .../ethereum/byzantium/vm/exceptions.v | 7 +- CoqOfPython/ethereum/byzantium/vm/gas.v | 224 ++- .../byzantium/vm/instructions/__init__.v | 69 +- .../byzantium/vm/instructions/arithmetic.v | 75 +- .../byzantium/vm/instructions/bitwise.v | 26 +- .../byzantium/vm/instructions/block.v | 39 +- .../byzantium/vm/instructions/comparison.v | 26 +- .../byzantium/vm/instructions/control_flow.v | 43 +- .../byzantium/vm/instructions/environment.v | 83 +- .../byzantium/vm/instructions/keccak.v | 59 +- .../ethereum/byzantium/vm/instructions/log.v | 120 +- .../byzantium/vm/instructions/memory.v | 39 +- .../byzantium/vm/instructions/stack.v | 96 +- .../byzantium/vm/instructions/storage.v | 54 +- .../byzantium/vm/instructions/system.v | 135 +- .../ethereum/byzantium/vm/interpreter.v | 165 +- CoqOfPython/ethereum/byzantium/vm/memory.v | 121 +- .../vm/precompiled_contracts/__init__.v | 7 +- .../vm/precompiled_contracts/alt_bn128.v | 368 ++--- .../vm/precompiled_contracts/ecrecover.v | 62 +- .../vm/precompiled_contracts/identity.v | 26 +- .../vm/precompiled_contracts/mapping.v | 67 +- .../vm/precompiled_contracts/modexp.v | 26 +- .../vm/precompiled_contracts/ripemd160.v | 31 +- .../vm/precompiled_contracts/sha256.v | 26 +- CoqOfPython/ethereum/byzantium/vm/runtime.v | 137 +- CoqOfPython/ethereum/byzantium/vm/stack.v | 23 +- CoqOfPython/ethereum/cancun/__init__.v | 7 +- CoqOfPython/ethereum/cancun/blocks.v | 60 +- CoqOfPython/ethereum/cancun/bloom.v | 159 +- CoqOfPython/ethereum/cancun/fork.v | 692 +++++---- CoqOfPython/ethereum/cancun/fork_types.v | 40 +- CoqOfPython/ethereum/cancun/state.v | 171 +- CoqOfPython/ethereum/cancun/transactions.v | 93 +- CoqOfPython/ethereum/cancun/trie.v | 868 ++++++----- CoqOfPython/ethereum/cancun/utils/__init__.v | 2 +- CoqOfPython/ethereum/cancun/utils/address.v | 65 +- .../ethereum/cancun/utils/hexadecimal.v | 18 +- CoqOfPython/ethereum/cancun/utils/message.v | 55 +- CoqOfPython/ethereum/cancun/vm/__init__.v | 68 +- CoqOfPython/ethereum/cancun/vm/exceptions.v | 7 +- CoqOfPython/ethereum/cancun/vm/gas.v | 256 ++- .../cancun/vm/instructions/__init__.v | 69 +- .../cancun/vm/instructions/arithmetic.v | 75 +- .../ethereum/cancun/vm/instructions/bitwise.v | 28 +- .../ethereum/cancun/vm/instructions/block.v | 39 +- .../cancun/vm/instructions/comparison.v | 26 +- .../cancun/vm/instructions/control_flow.v | 43 +- .../cancun/vm/instructions/environment.v | 136 +- .../ethereum/cancun/vm/instructions/keccak.v | 59 +- .../ethereum/cancun/vm/instructions/log.v | 120 +- .../ethereum/cancun/vm/instructions/memory.v | 48 +- .../ethereum/cancun/vm/instructions/stack.v | 96 +- .../ethereum/cancun/vm/instructions/storage.v | 63 +- .../ethereum/cancun/vm/instructions/system.v | 136 +- CoqOfPython/ethereum/cancun/vm/interpreter.v | 171 +- CoqOfPython/ethereum/cancun/vm/memory.v | 121 +- .../vm/precompiled_contracts/__init__.v | 7 +- .../vm/precompiled_contracts/alt_bn128.v | 368 ++--- .../cancun/vm/precompiled_contracts/blake2f.v | 31 +- .../vm/precompiled_contracts/ecrecover.v | 62 +- .../vm/precompiled_contracts/identity.v | 26 +- .../cancun/vm/precompiled_contracts/mapping.v | 101 +- .../cancun/vm/precompiled_contracts/modexp.v | 26 +- .../precompiled_contracts/point_evaluation.v | 85 +- .../vm/precompiled_contracts/ripemd160.v | 31 +- .../cancun/vm/precompiled_contracts/sha256.v | 26 +- CoqOfPython/ethereum/cancun/vm/runtime.v | 137 +- CoqOfPython/ethereum/cancun/vm/stack.v | 23 +- .../ethereum/constantinople/__init__.v | 7 +- CoqOfPython/ethereum/constantinople/blocks.v | 56 +- CoqOfPython/ethereum/constantinople/bloom.v | 159 +- CoqOfPython/ethereum/constantinople/fork.v | 674 ++++---- .../ethereum/constantinople/fork_types.v | 40 +- CoqOfPython/ethereum/constantinople/state.v | 98 +- .../ethereum/constantinople/transactions.v | 36 +- CoqOfPython/ethereum/constantinople/trie.v | 852 +++++----- .../ethereum/constantinople/utils/__init__.v | 2 +- .../ethereum/constantinople/utils/address.v | 65 +- .../constantinople/utils/hexadecimal.v | 18 +- .../ethereum/constantinople/utils/message.v | 44 +- .../ethereum/constantinople/vm/__init__.v | 74 +- .../ethereum/constantinople/vm/exceptions.v | 7 +- CoqOfPython/ethereum/constantinople/vm/gas.v | 224 ++- .../constantinople/vm/instructions/__init__.v | 69 +- .../vm/instructions/arithmetic.v | 75 +- .../constantinople/vm/instructions/bitwise.v | 28 +- .../constantinople/vm/instructions/block.v | 39 +- .../vm/instructions/comparison.v | 26 +- .../vm/instructions/control_flow.v | 43 +- .../vm/instructions/environment.v | 95 +- .../constantinople/vm/instructions/keccak.v | 59 +- .../constantinople/vm/instructions/log.v | 120 +- .../constantinople/vm/instructions/memory.v | 39 +- .../constantinople/vm/instructions/stack.v | 96 +- .../constantinople/vm/instructions/storage.v | 54 +- .../constantinople/vm/instructions/system.v | 144 +- .../ethereum/constantinople/vm/interpreter.v | 165 +- .../ethereum/constantinople/vm/memory.v | 121 +- .../vm/precompiled_contracts/__init__.v | 7 +- .../vm/precompiled_contracts/alt_bn128.v | 368 ++--- .../vm/precompiled_contracts/ecrecover.v | 62 +- .../vm/precompiled_contracts/identity.v | 26 +- .../vm/precompiled_contracts/mapping.v | 67 +- .../vm/precompiled_contracts/modexp.v | 26 +- .../vm/precompiled_contracts/ripemd160.v | 31 +- .../vm/precompiled_contracts/sha256.v | 26 +- .../ethereum/constantinople/vm/runtime.v | 137 +- .../ethereum/constantinople/vm/stack.v | 23 +- CoqOfPython/ethereum/crypto/__init__.v | 2 +- CoqOfPython/ethereum/crypto/alt_bn128.v | 297 ++-- CoqOfPython/ethereum/crypto/blake2.v | 647 +++++--- CoqOfPython/ethereum/crypto/elliptic_curve.v | 162 +- CoqOfPython/ethereum/crypto/finite_field.v | 1370 ++++++++++------- CoqOfPython/ethereum/crypto/hash.v | 16 +- CoqOfPython/ethereum/dao_fork/__init__.v | 7 +- CoqOfPython/ethereum/dao_fork/blocks.v | 56 +- CoqOfPython/ethereum/dao_fork/bloom.v | 159 +- CoqOfPython/ethereum/dao_fork/dao.v | 49 +- CoqOfPython/ethereum/dao_fork/fork.v | 640 ++++---- CoqOfPython/ethereum/dao_fork/fork_types.v | 40 +- CoqOfPython/ethereum/dao_fork/state.v | 98 +- CoqOfPython/ethereum/dao_fork/transactions.v | 36 +- CoqOfPython/ethereum/dao_fork/trie.v | 852 +++++----- .../ethereum/dao_fork/utils/__init__.v | 2 +- CoqOfPython/ethereum/dao_fork/utils/address.v | 56 +- .../ethereum/dao_fork/utils/hexadecimal.v | 18 +- CoqOfPython/ethereum/dao_fork/utils/message.v | 44 +- CoqOfPython/ethereum/dao_fork/vm/__init__.v | 63 +- CoqOfPython/ethereum/dao_fork/vm/exceptions.v | 7 +- CoqOfPython/ethereum/dao_fork/vm/gas.v | 252 ++- .../dao_fork/vm/instructions/__init__.v | 69 +- .../dao_fork/vm/instructions/arithmetic.v | 75 +- .../dao_fork/vm/instructions/bitwise.v | 26 +- .../ethereum/dao_fork/vm/instructions/block.v | 39 +- .../dao_fork/vm/instructions/comparison.v | 26 +- .../dao_fork/vm/instructions/control_flow.v | 43 +- .../dao_fork/vm/instructions/environment.v | 74 +- .../dao_fork/vm/instructions/keccak.v | 59 +- .../ethereum/dao_fork/vm/instructions/log.v | 106 +- .../dao_fork/vm/instructions/memory.v | 39 +- .../ethereum/dao_fork/vm/instructions/stack.v | 96 +- .../dao_fork/vm/instructions/storage.v | 34 +- .../dao_fork/vm/instructions/system.v | 107 +- .../ethereum/dao_fork/vm/interpreter.v | 148 +- CoqOfPython/ethereum/dao_fork/vm/memory.v | 121 +- .../vm/precompiled_contracts/__init__.v | 7 +- .../vm/precompiled_contracts/ecrecover.v | 62 +- .../vm/precompiled_contracts/identity.v | 26 +- .../vm/precompiled_contracts/mapping.v | 57 +- .../vm/precompiled_contracts/ripemd160.v | 31 +- .../vm/precompiled_contracts/sha256.v | 26 +- CoqOfPython/ethereum/dao_fork/vm/runtime.v | 137 +- CoqOfPython/ethereum/dao_fork/vm/stack.v | 23 +- CoqOfPython/ethereum/ethash.v | 706 +++++---- CoqOfPython/ethereum/exceptions.v | 2 +- CoqOfPython/ethereum/fork_criteria.v | 16 +- CoqOfPython/ethereum/frontier/__init__.v | 7 +- CoqOfPython/ethereum/frontier/blocks.v | 56 +- CoqOfPython/ethereum/frontier/bloom.v | 159 +- CoqOfPython/ethereum/frontier/fork.v | 622 ++++---- CoqOfPython/ethereum/frontier/fork_types.v | 40 +- CoqOfPython/ethereum/frontier/state.v | 98 +- CoqOfPython/ethereum/frontier/transactions.v | 36 +- CoqOfPython/ethereum/frontier/trie.v | 847 +++++----- .../ethereum/frontier/utils/__init__.v | 2 +- CoqOfPython/ethereum/frontier/utils/address.v | 56 +- .../ethereum/frontier/utils/hexadecimal.v | 18 +- CoqOfPython/ethereum/frontier/utils/message.v | 44 +- CoqOfPython/ethereum/frontier/vm/__init__.v | 63 +- CoqOfPython/ethereum/frontier/vm/exceptions.v | 7 +- CoqOfPython/ethereum/frontier/vm/gas.v | 252 ++- .../frontier/vm/instructions/__init__.v | 69 +- .../frontier/vm/instructions/arithmetic.v | 75 +- .../frontier/vm/instructions/bitwise.v | 26 +- .../ethereum/frontier/vm/instructions/block.v | 39 +- .../frontier/vm/instructions/comparison.v | 26 +- .../frontier/vm/instructions/control_flow.v | 43 +- .../frontier/vm/instructions/environment.v | 74 +- .../frontier/vm/instructions/keccak.v | 59 +- .../ethereum/frontier/vm/instructions/log.v | 106 +- .../frontier/vm/instructions/memory.v | 39 +- .../ethereum/frontier/vm/instructions/stack.v | 96 +- .../frontier/vm/instructions/storage.v | 34 +- .../frontier/vm/instructions/system.v | 105 +- .../ethereum/frontier/vm/interpreter.v | 148 +- CoqOfPython/ethereum/frontier/vm/memory.v | 121 +- .../vm/precompiled_contracts/__init__.v | 7 +- .../vm/precompiled_contracts/ecrecover.v | 62 +- .../vm/precompiled_contracts/identity.v | 26 +- .../vm/precompiled_contracts/mapping.v | 57 +- .../vm/precompiled_contracts/ripemd160.v | 31 +- .../vm/precompiled_contracts/sha256.v | 26 +- CoqOfPython/ethereum/frontier/vm/runtime.v | 137 +- CoqOfPython/ethereum/frontier/vm/stack.v | 23 +- CoqOfPython/ethereum/genesis.v | 138 +- CoqOfPython/ethereum/gray_glacier/__init__.v | 7 +- CoqOfPython/ethereum/gray_glacier/blocks.v | 58 +- CoqOfPython/ethereum/gray_glacier/bloom.v | 159 +- CoqOfPython/ethereum/gray_glacier/fork.v | 765 ++++----- .../ethereum/gray_glacier/fork_types.v | 40 +- CoqOfPython/ethereum/gray_glacier/state.v | 107 +- .../ethereum/gray_glacier/transactions.v | 79 +- CoqOfPython/ethereum/gray_glacier/trie.v | 858 ++++++----- .../ethereum/gray_glacier/utils/__init__.v | 2 +- .../ethereum/gray_glacier/utils/address.v | 65 +- .../ethereum/gray_glacier/utils/hexadecimal.v | 18 +- .../ethereum/gray_glacier/utils/message.v | 55 +- .../ethereum/gray_glacier/vm/__init__.v | 64 +- .../ethereum/gray_glacier/vm/exceptions.v | 7 +- CoqOfPython/ethereum/gray_glacier/vm/gas.v | 224 ++- .../gray_glacier/vm/instructions/__init__.v | 69 +- .../gray_glacier/vm/instructions/arithmetic.v | 75 +- .../gray_glacier/vm/instructions/bitwise.v | 28 +- .../gray_glacier/vm/instructions/block.v | 39 +- .../gray_glacier/vm/instructions/comparison.v | 26 +- .../vm/instructions/control_flow.v | 43 +- .../vm/instructions/environment.v | 125 +- .../gray_glacier/vm/instructions/keccak.v | 59 +- .../gray_glacier/vm/instructions/log.v | 120 +- .../gray_glacier/vm/instructions/memory.v | 39 +- .../gray_glacier/vm/instructions/stack.v | 96 +- .../gray_glacier/vm/instructions/storage.v | 59 +- .../gray_glacier/vm/instructions/system.v | 128 +- .../ethereum/gray_glacier/vm/interpreter.v | 169 +- CoqOfPython/ethereum/gray_glacier/vm/memory.v | 121 +- .../vm/precompiled_contracts/__init__.v | 7 +- .../vm/precompiled_contracts/alt_bn128.v | 368 ++--- .../vm/precompiled_contracts/blake2f.v | 31 +- .../vm/precompiled_contracts/ecrecover.v | 62 +- .../vm/precompiled_contracts/identity.v | 26 +- .../vm/precompiled_contracts/mapping.v | 92 +- .../vm/precompiled_contracts/modexp.v | 26 +- .../vm/precompiled_contracts/ripemd160.v | 31 +- .../vm/precompiled_contracts/sha256.v | 26 +- .../ethereum/gray_glacier/vm/runtime.v | 137 +- CoqOfPython/ethereum/gray_glacier/vm/stack.v | 23 +- CoqOfPython/ethereum/homestead/__init__.v | 7 +- CoqOfPython/ethereum/homestead/blocks.v | 56 +- CoqOfPython/ethereum/homestead/bloom.v | 159 +- CoqOfPython/ethereum/homestead/fork.v | 631 ++++---- CoqOfPython/ethereum/homestead/fork_types.v | 40 +- CoqOfPython/ethereum/homestead/state.v | 98 +- CoqOfPython/ethereum/homestead/transactions.v | 36 +- CoqOfPython/ethereum/homestead/trie.v | 852 +++++----- .../ethereum/homestead/utils/__init__.v | 2 +- .../ethereum/homestead/utils/address.v | 56 +- .../ethereum/homestead/utils/hexadecimal.v | 18 +- .../ethereum/homestead/utils/message.v | 44 +- CoqOfPython/ethereum/homestead/vm/__init__.v | 63 +- .../ethereum/homestead/vm/exceptions.v | 7 +- CoqOfPython/ethereum/homestead/vm/gas.v | 252 ++- .../homestead/vm/instructions/__init__.v | 69 +- .../homestead/vm/instructions/arithmetic.v | 75 +- .../homestead/vm/instructions/bitwise.v | 26 +- .../homestead/vm/instructions/block.v | 39 +- .../homestead/vm/instructions/comparison.v | 26 +- .../homestead/vm/instructions/control_flow.v | 43 +- .../homestead/vm/instructions/environment.v | 74 +- .../homestead/vm/instructions/keccak.v | 59 +- .../ethereum/homestead/vm/instructions/log.v | 106 +- .../homestead/vm/instructions/memory.v | 39 +- .../homestead/vm/instructions/stack.v | 96 +- .../homestead/vm/instructions/storage.v | 34 +- .../homestead/vm/instructions/system.v | 107 +- .../ethereum/homestead/vm/interpreter.v | 148 +- CoqOfPython/ethereum/homestead/vm/memory.v | 121 +- .../vm/precompiled_contracts/__init__.v | 7 +- .../vm/precompiled_contracts/ecrecover.v | 62 +- .../vm/precompiled_contracts/identity.v | 26 +- .../vm/precompiled_contracts/mapping.v | 57 +- .../vm/precompiled_contracts/ripemd160.v | 31 +- .../vm/precompiled_contracts/sha256.v | 26 +- CoqOfPython/ethereum/homestead/vm/runtime.v | 137 +- CoqOfPython/ethereum/homestead/vm/stack.v | 23 +- CoqOfPython/ethereum/istanbul/__init__.v | 7 +- CoqOfPython/ethereum/istanbul/blocks.v | 56 +- CoqOfPython/ethereum/istanbul/bloom.v | 159 +- CoqOfPython/ethereum/istanbul/fork.v | 674 ++++---- CoqOfPython/ethereum/istanbul/fork_types.v | 40 +- CoqOfPython/ethereum/istanbul/state.v | 107 +- CoqOfPython/ethereum/istanbul/transactions.v | 36 +- CoqOfPython/ethereum/istanbul/trie.v | 852 +++++----- .../ethereum/istanbul/utils/__init__.v | 2 +- CoqOfPython/ethereum/istanbul/utils/address.v | 65 +- .../ethereum/istanbul/utils/hexadecimal.v | 18 +- CoqOfPython/ethereum/istanbul/utils/message.v | 44 +- CoqOfPython/ethereum/istanbul/vm/__init__.v | 76 +- CoqOfPython/ethereum/istanbul/vm/exceptions.v | 7 +- CoqOfPython/ethereum/istanbul/vm/gas.v | 224 ++- .../istanbul/vm/instructions/__init__.v | 69 +- .../istanbul/vm/instructions/arithmetic.v | 75 +- .../istanbul/vm/instructions/bitwise.v | 28 +- .../ethereum/istanbul/vm/instructions/block.v | 39 +- .../istanbul/vm/instructions/comparison.v | 26 +- .../istanbul/vm/instructions/control_flow.v | 43 +- .../istanbul/vm/instructions/environment.v | 119 +- .../istanbul/vm/instructions/keccak.v | 59 +- .../ethereum/istanbul/vm/instructions/log.v | 120 +- .../istanbul/vm/instructions/memory.v | 39 +- .../ethereum/istanbul/vm/instructions/stack.v | 96 +- .../istanbul/vm/instructions/storage.v | 50 +- .../istanbul/vm/instructions/system.v | 144 +- .../ethereum/istanbul/vm/interpreter.v | 167 +- CoqOfPython/ethereum/istanbul/vm/memory.v | 121 +- .../vm/precompiled_contracts/__init__.v | 7 +- .../vm/precompiled_contracts/alt_bn128.v | 368 ++--- .../vm/precompiled_contracts/blake2f.v | 31 +- .../vm/precompiled_contracts/ecrecover.v | 62 +- .../vm/precompiled_contracts/identity.v | 26 +- .../vm/precompiled_contracts/mapping.v | 92 +- .../vm/precompiled_contracts/modexp.v | 26 +- .../vm/precompiled_contracts/ripemd160.v | 31 +- .../vm/precompiled_contracts/sha256.v | 26 +- CoqOfPython/ethereum/istanbul/vm/runtime.v | 137 +- CoqOfPython/ethereum/istanbul/vm/stack.v | 23 +- CoqOfPython/ethereum/london/__init__.v | 7 +- CoqOfPython/ethereum/london/blocks.v | 58 +- CoqOfPython/ethereum/london/bloom.v | 159 +- CoqOfPython/ethereum/london/fork.v | 767 ++++----- CoqOfPython/ethereum/london/fork_types.v | 40 +- CoqOfPython/ethereum/london/state.v | 107 +- CoqOfPython/ethereum/london/transactions.v | 79 +- CoqOfPython/ethereum/london/trie.v | 858 ++++++----- CoqOfPython/ethereum/london/utils/__init__.v | 2 +- CoqOfPython/ethereum/london/utils/address.v | 65 +- .../ethereum/london/utils/hexadecimal.v | 18 +- CoqOfPython/ethereum/london/utils/message.v | 55 +- CoqOfPython/ethereum/london/vm/__init__.v | 64 +- CoqOfPython/ethereum/london/vm/exceptions.v | 7 +- CoqOfPython/ethereum/london/vm/gas.v | 224 ++- .../london/vm/instructions/__init__.v | 69 +- .../london/vm/instructions/arithmetic.v | 75 +- .../ethereum/london/vm/instructions/bitwise.v | 28 +- .../ethereum/london/vm/instructions/block.v | 39 +- .../london/vm/instructions/comparison.v | 26 +- .../london/vm/instructions/control_flow.v | 43 +- .../london/vm/instructions/environment.v | 125 +- .../ethereum/london/vm/instructions/keccak.v | 59 +- .../ethereum/london/vm/instructions/log.v | 120 +- .../ethereum/london/vm/instructions/memory.v | 39 +- .../ethereum/london/vm/instructions/stack.v | 96 +- .../ethereum/london/vm/instructions/storage.v | 59 +- .../ethereum/london/vm/instructions/system.v | 128 +- CoqOfPython/ethereum/london/vm/interpreter.v | 169 +- CoqOfPython/ethereum/london/vm/memory.v | 121 +- .../vm/precompiled_contracts/__init__.v | 7 +- .../vm/precompiled_contracts/alt_bn128.v | 368 ++--- .../london/vm/precompiled_contracts/blake2f.v | 31 +- .../vm/precompiled_contracts/ecrecover.v | 62 +- .../vm/precompiled_contracts/identity.v | 26 +- .../london/vm/precompiled_contracts/mapping.v | 92 +- .../london/vm/precompiled_contracts/modexp.v | 26 +- .../vm/precompiled_contracts/ripemd160.v | 31 +- .../london/vm/precompiled_contracts/sha256.v | 26 +- CoqOfPython/ethereum/london/vm/runtime.v | 137 +- CoqOfPython/ethereum/london/vm/stack.v | 23 +- CoqOfPython/ethereum/muir_glacier/__init__.v | 7 +- CoqOfPython/ethereum/muir_glacier/blocks.v | 56 +- CoqOfPython/ethereum/muir_glacier/bloom.v | 159 +- CoqOfPython/ethereum/muir_glacier/fork.v | 674 ++++---- .../ethereum/muir_glacier/fork_types.v | 40 +- CoqOfPython/ethereum/muir_glacier/state.v | 107 +- .../ethereum/muir_glacier/transactions.v | 36 +- CoqOfPython/ethereum/muir_glacier/trie.v | 852 +++++----- .../ethereum/muir_glacier/utils/__init__.v | 2 +- .../ethereum/muir_glacier/utils/address.v | 65 +- .../ethereum/muir_glacier/utils/hexadecimal.v | 18 +- .../ethereum/muir_glacier/utils/message.v | 44 +- .../ethereum/muir_glacier/vm/__init__.v | 76 +- .../ethereum/muir_glacier/vm/exceptions.v | 7 +- CoqOfPython/ethereum/muir_glacier/vm/gas.v | 224 ++- .../muir_glacier/vm/instructions/__init__.v | 69 +- .../muir_glacier/vm/instructions/arithmetic.v | 75 +- .../muir_glacier/vm/instructions/bitwise.v | 28 +- .../muir_glacier/vm/instructions/block.v | 39 +- .../muir_glacier/vm/instructions/comparison.v | 26 +- .../vm/instructions/control_flow.v | 43 +- .../vm/instructions/environment.v | 119 +- .../muir_glacier/vm/instructions/keccak.v | 59 +- .../muir_glacier/vm/instructions/log.v | 120 +- .../muir_glacier/vm/instructions/memory.v | 39 +- .../muir_glacier/vm/instructions/stack.v | 96 +- .../muir_glacier/vm/instructions/storage.v | 50 +- .../muir_glacier/vm/instructions/system.v | 144 +- .../ethereum/muir_glacier/vm/interpreter.v | 167 +- CoqOfPython/ethereum/muir_glacier/vm/memory.v | 121 +- .../vm/precompiled_contracts/__init__.v | 7 +- .../vm/precompiled_contracts/alt_bn128.v | 368 ++--- .../vm/precompiled_contracts/blake2f.v | 31 +- .../vm/precompiled_contracts/ecrecover.v | 62 +- .../vm/precompiled_contracts/identity.v | 26 +- .../vm/precompiled_contracts/mapping.v | 92 +- .../vm/precompiled_contracts/modexp.v | 26 +- .../vm/precompiled_contracts/ripemd160.v | 31 +- .../vm/precompiled_contracts/sha256.v | 26 +- .../ethereum/muir_glacier/vm/runtime.v | 137 +- CoqOfPython/ethereum/muir_glacier/vm/stack.v | 23 +- CoqOfPython/ethereum/paris/__init__.v | 7 +- CoqOfPython/ethereum/paris/blocks.v | 58 +- CoqOfPython/ethereum/paris/bloom.v | 159 +- CoqOfPython/ethereum/paris/fork.v | 559 +++---- CoqOfPython/ethereum/paris/fork_types.v | 40 +- CoqOfPython/ethereum/paris/state.v | 107 +- CoqOfPython/ethereum/paris/transactions.v | 79 +- CoqOfPython/ethereum/paris/trie.v | 858 ++++++----- CoqOfPython/ethereum/paris/utils/__init__.v | 2 +- CoqOfPython/ethereum/paris/utils/address.v | 65 +- .../ethereum/paris/utils/hexadecimal.v | 18 +- CoqOfPython/ethereum/paris/utils/message.v | 55 +- CoqOfPython/ethereum/paris/vm/__init__.v | 64 +- CoqOfPython/ethereum/paris/vm/exceptions.v | 7 +- CoqOfPython/ethereum/paris/vm/gas.v | 224 ++- .../ethereum/paris/vm/instructions/__init__.v | 69 +- .../paris/vm/instructions/arithmetic.v | 75 +- .../ethereum/paris/vm/instructions/bitwise.v | 28 +- .../ethereum/paris/vm/instructions/block.v | 39 +- .../paris/vm/instructions/comparison.v | 26 +- .../paris/vm/instructions/control_flow.v | 43 +- .../paris/vm/instructions/environment.v | 125 +- .../ethereum/paris/vm/instructions/keccak.v | 59 +- .../ethereum/paris/vm/instructions/log.v | 120 +- .../ethereum/paris/vm/instructions/memory.v | 39 +- .../ethereum/paris/vm/instructions/stack.v | 96 +- .../ethereum/paris/vm/instructions/storage.v | 59 +- .../ethereum/paris/vm/instructions/system.v | 128 +- CoqOfPython/ethereum/paris/vm/interpreter.v | 171 +- CoqOfPython/ethereum/paris/vm/memory.v | 121 +- .../paris/vm/precompiled_contracts/__init__.v | 7 +- .../vm/precompiled_contracts/alt_bn128.v | 368 ++--- .../paris/vm/precompiled_contracts/blake2f.v | 31 +- .../vm/precompiled_contracts/ecrecover.v | 62 +- .../paris/vm/precompiled_contracts/identity.v | 26 +- .../paris/vm/precompiled_contracts/mapping.v | 92 +- .../paris/vm/precompiled_contracts/modexp.v | 26 +- .../vm/precompiled_contracts/ripemd160.v | 31 +- .../paris/vm/precompiled_contracts/sha256.v | 26 +- CoqOfPython/ethereum/paris/vm/runtime.v | 137 +- CoqOfPython/ethereum/paris/vm/stack.v | 23 +- CoqOfPython/ethereum/rlp.v | 450 ++++-- CoqOfPython/ethereum/shanghai/__init__.v | 7 +- CoqOfPython/ethereum/shanghai/blocks.v | 60 +- CoqOfPython/ethereum/shanghai/bloom.v | 159 +- CoqOfPython/ethereum/shanghai/fork.v | 635 ++++---- CoqOfPython/ethereum/shanghai/fork_types.v | 40 +- CoqOfPython/ethereum/shanghai/state.v | 114 +- CoqOfPython/ethereum/shanghai/transactions.v | 79 +- CoqOfPython/ethereum/shanghai/trie.v | 868 ++++++----- .../ethereum/shanghai/utils/__init__.v | 2 +- CoqOfPython/ethereum/shanghai/utils/address.v | 65 +- .../ethereum/shanghai/utils/hexadecimal.v | 18 +- CoqOfPython/ethereum/shanghai/utils/message.v | 55 +- CoqOfPython/ethereum/shanghai/vm/__init__.v | 64 +- CoqOfPython/ethereum/shanghai/vm/exceptions.v | 7 +- CoqOfPython/ethereum/shanghai/vm/gas.v | 224 ++- .../shanghai/vm/instructions/__init__.v | 69 +- .../shanghai/vm/instructions/arithmetic.v | 75 +- .../shanghai/vm/instructions/bitwise.v | 28 +- .../ethereum/shanghai/vm/instructions/block.v | 39 +- .../shanghai/vm/instructions/comparison.v | 26 +- .../shanghai/vm/instructions/control_flow.v | 43 +- .../shanghai/vm/instructions/environment.v | 125 +- .../shanghai/vm/instructions/keccak.v | 59 +- .../ethereum/shanghai/vm/instructions/log.v | 120 +- .../shanghai/vm/instructions/memory.v | 39 +- .../ethereum/shanghai/vm/instructions/stack.v | 96 +- .../shanghai/vm/instructions/storage.v | 59 +- .../shanghai/vm/instructions/system.v | 132 +- .../ethereum/shanghai/vm/interpreter.v | 171 +- CoqOfPython/ethereum/shanghai/vm/memory.v | 121 +- .../vm/precompiled_contracts/__init__.v | 7 +- .../vm/precompiled_contracts/alt_bn128.v | 368 ++--- .../vm/precompiled_contracts/blake2f.v | 31 +- .../vm/precompiled_contracts/ecrecover.v | 62 +- .../vm/precompiled_contracts/identity.v | 26 +- .../vm/precompiled_contracts/mapping.v | 92 +- .../vm/precompiled_contracts/modexp.v | 26 +- .../vm/precompiled_contracts/ripemd160.v | 31 +- .../vm/precompiled_contracts/sha256.v | 26 +- CoqOfPython/ethereum/shanghai/vm/runtime.v | 137 +- CoqOfPython/ethereum/shanghai/vm/stack.v | 23 +- .../ethereum/spurious_dragon/__init__.v | 7 +- CoqOfPython/ethereum/spurious_dragon/blocks.v | 56 +- CoqOfPython/ethereum/spurious_dragon/bloom.v | 159 +- CoqOfPython/ethereum/spurious_dragon/fork.v | 680 ++++---- .../ethereum/spurious_dragon/fork_types.v | 40 +- CoqOfPython/ethereum/spurious_dragon/state.v | 98 +- .../ethereum/spurious_dragon/transactions.v | 36 +- CoqOfPython/ethereum/spurious_dragon/trie.v | 852 +++++----- .../ethereum/spurious_dragon/utils/__init__.v | 2 +- .../ethereum/spurious_dragon/utils/address.v | 56 +- .../spurious_dragon/utils/hexadecimal.v | 18 +- .../ethereum/spurious_dragon/utils/message.v | 44 +- .../ethereum/spurious_dragon/vm/__init__.v | 74 +- .../ethereum/spurious_dragon/vm/exceptions.v | 7 +- CoqOfPython/ethereum/spurious_dragon/vm/gas.v | 224 ++- .../vm/instructions/__init__.v | 69 +- .../vm/instructions/arithmetic.v | 75 +- .../spurious_dragon/vm/instructions/bitwise.v | 26 +- .../spurious_dragon/vm/instructions/block.v | 39 +- .../vm/instructions/comparison.v | 26 +- .../vm/instructions/control_flow.v | 43 +- .../vm/instructions/environment.v | 74 +- .../spurious_dragon/vm/instructions/keccak.v | 59 +- .../spurious_dragon/vm/instructions/log.v | 106 +- .../spurious_dragon/vm/instructions/memory.v | 39 +- .../spurious_dragon/vm/instructions/stack.v | 96 +- .../spurious_dragon/vm/instructions/storage.v | 34 +- .../spurious_dragon/vm/instructions/system.v | 121 +- .../ethereum/spurious_dragon/vm/interpreter.v | 163 +- .../ethereum/spurious_dragon/vm/memory.v | 121 +- .../vm/precompiled_contracts/__init__.v | 7 +- .../vm/precompiled_contracts/ecrecover.v | 62 +- .../vm/precompiled_contracts/identity.v | 26 +- .../vm/precompiled_contracts/mapping.v | 57 +- .../vm/precompiled_contracts/ripemd160.v | 31 +- .../vm/precompiled_contracts/sha256.v | 26 +- .../ethereum/spurious_dragon/vm/runtime.v | 137 +- .../ethereum/spurious_dragon/vm/stack.v | 23 +- .../ethereum/tangerine_whistle/__init__.v | 7 +- .../ethereum/tangerine_whistle/blocks.v | 56 +- .../ethereum/tangerine_whistle/bloom.v | 159 +- CoqOfPython/ethereum/tangerine_whistle/fork.v | 631 ++++---- .../ethereum/tangerine_whistle/fork_types.v | 40 +- .../ethereum/tangerine_whistle/state.v | 98 +- .../ethereum/tangerine_whistle/transactions.v | 36 +- CoqOfPython/ethereum/tangerine_whistle/trie.v | 852 +++++----- .../tangerine_whistle/utils/__init__.v | 2 +- .../tangerine_whistle/utils/address.v | 56 +- .../tangerine_whistle/utils/hexadecimal.v | 18 +- .../tangerine_whistle/utils/message.v | 44 +- .../ethereum/tangerine_whistle/vm/__init__.v | 63 +- .../tangerine_whistle/vm/exceptions.v | 7 +- .../ethereum/tangerine_whistle/vm/gas.v | 224 ++- .../vm/instructions/__init__.v | 69 +- .../vm/instructions/arithmetic.v | 75 +- .../vm/instructions/bitwise.v | 26 +- .../tangerine_whistle/vm/instructions/block.v | 39 +- .../vm/instructions/comparison.v | 26 +- .../vm/instructions/control_flow.v | 43 +- .../vm/instructions/environment.v | 74 +- .../vm/instructions/keccak.v | 59 +- .../tangerine_whistle/vm/instructions/log.v | 106 +- .../vm/instructions/memory.v | 39 +- .../tangerine_whistle/vm/instructions/stack.v | 96 +- .../vm/instructions/storage.v | 34 +- .../vm/instructions/system.v | 119 +- .../tangerine_whistle/vm/interpreter.v | 148 +- .../ethereum/tangerine_whistle/vm/memory.v | 121 +- .../vm/precompiled_contracts/__init__.v | 7 +- .../vm/precompiled_contracts/ecrecover.v | 62 +- .../vm/precompiled_contracts/identity.v | 26 +- .../vm/precompiled_contracts/mapping.v | 57 +- .../vm/precompiled_contracts/ripemd160.v | 31 +- .../vm/precompiled_contracts/sha256.v | 26 +- .../ethereum/tangerine_whistle/vm/runtime.v | 137 +- .../ethereum/tangerine_whistle/vm/stack.v | 23 +- CoqOfPython/ethereum/trace.v | 19 +- CoqOfPython/ethereum/utils/__init__.v | 2 +- CoqOfPython/ethereum/utils/byte.v | 7 +- CoqOfPython/ethereum/utils/ensure.v | 11 +- CoqOfPython/ethereum/utils/hexadecimal.v | 47 +- CoqOfPython/ethereum/utils/numeric.v | 222 +-- CoqOfPython/ethereum/utils/safe_arithmetic.v | 23 +- main.py | 113 +- 664 files changed, 34469 insertions(+), 37827 deletions(-) diff --git a/CoqOfPython/CoqOfPython.v b/CoqOfPython/CoqOfPython.v index 487e316..58cd3e7 100644 --- a/CoqOfPython/CoqOfPython.v +++ b/CoqOfPython/CoqOfPython.v @@ -31,7 +31,7 @@ Module Data. | Dict (dict : list (string * Value)) | Closure {Value M : Set} (f : Value -> Value -> M) | Klass {Value M : Set} - (bases : list (Set * string)) + (bases : list (string * string)) (class_methods : list (string * (Value -> Value -> M))) (methods : list (string * (Value -> Value -> M))). Arguments Bool {_}. @@ -71,17 +71,14 @@ End Pointer. Module Value. Inductive t : Set := - | Make (globals : Set) (klass : string) (value : Pointer.t t). + | Make (globals : string) (klass : string) (value : Pointer.t t). End Value. Parameter M : Set. -Parameter IsInGlobals : Set -> Value.t -> string -> Prop. +Parameter IsInGlobals : string -> Value.t -> string -> Prop. -Definition IsGlobalAlias (globals required_globals : Set) (name : string) : Prop := - forall (value : Value.t), - IsInGlobals required_globals value name -> - IsInGlobals globals value name. +Parameter AreImported : string -> string -> list string -> Prop. Module M. Parameter pure : Value.t -> M. @@ -95,15 +92,27 @@ Module M. (** For the `x[i]` syntax. *) Parameter get_subscript : Value.t -> Value.t -> M. - Parameter get_name : Set -> string -> M. + Parameter slice : Value.t -> Value.t -> Value.t -> Value.t -> M. + + Parameter get_name : string -> string -> M. Parameter set_locals : Value.t -> Value.t -> list string -> M. Parameter assign : Value.t -> Value.t -> M. + Parameter assign_op : (Value.t -> Value.t -> M) -> Value.t -> Value.t -> M. + + Parameter delete : Value.t -> M. + Parameter return_ : Value.t -> M. - Parameter raise : Value.t -> M. + Parameter pass : M. + + Parameter break : M. + + Parameter continue : M. + + Parameter raise : option Value.t -> M. Parameter assert : Value.t -> M. @@ -111,6 +120,10 @@ Module M. Parameter if_then_else : Value.t -> M -> M -> M. + Parameter for_ : Value.t -> Value.t -> M -> M -> M. + + Parameter while : Value.t -> M -> M -> M. + Parameter run : M -> Value.t. Module Notations. @@ -118,7 +131,7 @@ Module M. (run ((.. (e e1) ..) en)) (at level 100). - Notation "e (||)" := + Notation "e (| |)" := (run e) (at level 100). End Notations. @@ -168,7 +181,7 @@ End M. Export M.Notations. -Parameter Inherit : Set -> Set -> Prop. +Parameter Inherit : string -> string -> Prop. Module BoolOp. Parameter and : Value.t -> M -> M. @@ -183,7 +196,7 @@ Module BinOp. Parameter mult : Value.t -> Value.t -> M. - Parameter matmult : Value.t -> Value.t -> M. + Parameter mat_mult : Value.t -> Value.t -> M. Parameter div : Value.t -> Value.t -> M. @@ -191,9 +204,9 @@ Module BinOp. Parameter pow : Value.t -> Value.t -> M. - Parameter lshift : Value.t -> Value.t -> M. + Parameter l_shift : Value.t -> Value.t -> M. - Parameter rshift : Value.t -> Value.t -> M. + Parameter r_shift : Value.t -> Value.t -> M. Parameter bit_or : Value.t -> Value.t -> M. @@ -238,10 +251,10 @@ End Compare. (** ** Builtins *) Module builtins. - Inductive globals : Set :=. + Definition globals : string := "builtins". Definition make_klass - (bases : list (Set * string)) + (bases : list (string * string)) (class_methods : list (string * (Value.t -> Value.t -> M))) (methods : list (string * (Value.t -> Value.t -> M))) : Value.t := @@ -277,6 +290,9 @@ Module Constant. Definition str (s : string) : Value.t := Value.Make builtins.globals "str" (Pointer.Imm (Object.wrapper (Data.String s))). + + Definition bytes (b : string) : Value.t := + Value.Make builtins.globals "bytes" (Pointer.Imm (Object.wrapper (Data.String b))). End Constant. Definition make_tuple (items : list Value.t) : Value.t := diff --git a/CoqOfPython/blacklist.txt b/CoqOfPython/blacklist.txt index e69de29..1cb514b 100644 --- a/CoqOfPython/blacklist.txt +++ b/CoqOfPython/blacklist.txt @@ -0,0 +1 @@ +ethereum/ethash.v diff --git a/CoqOfPython/ethereum/__init__.v b/CoqOfPython/ethereum/__init__.v index b5c42e6..e1c92c1 100644 --- a/CoqOfPython/ethereum/__init__.v +++ b/CoqOfPython/ethereum/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.__init__". Definition expr_1 : Value.t := Constant.str " diff --git a/CoqOfPython/ethereum/arrow_glacier/__init__.v b/CoqOfPython/ethereum/arrow_glacier/__init__.v index d26a14d..daac7b6 100644 --- a/CoqOfPython/ethereum/arrow_glacier/__init__.v +++ b/CoqOfPython/ethereum/arrow_glacier/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.arrow_glacier.__init__". Definition expr_1 : Value.t := Constant.str " @@ -8,9 +8,8 @@ The Arrow Glacier fork delays the difficulty bomb. There are no other changes in this fork. ". -Require ethereum.fork_criteria. -Axiom ethereum_fork_criteria_ByBlockNumber : - IsGlobalAlias globals ethereum.fork_criteria.globals "ByBlockNumber". +Axiom ethereum_fork_criteria_imports : + AreImported globals "ethereum.fork_criteria" [ "ByBlockNumber" ]. Definition FORK_CRITERIA : Value.t := M.run ltac:(M.monadic ( M.call (| diff --git a/CoqOfPython/ethereum/arrow_glacier/blocks.v b/CoqOfPython/ethereum/arrow_glacier/blocks.v index f65b16f..353d9e0 100644 --- a/CoqOfPython/ethereum/arrow_glacier/blocks.v +++ b/CoqOfPython/ethereum/arrow_glacier/blocks.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.arrow_glacier.blocks". Definition expr_1 : Value.t := Constant.str " @@ -14,45 +14,23 @@ history of all state transitions that have happened since the genesis of the chain. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes8 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes8". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". - -Require ethereum.arrow_glacier.fork_types. -Axiom ethereum_arrow_glacier_fork_types_Address : - IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "Address". -Axiom ethereum_arrow_glacier_fork_types_Bloom : - IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "Bloom". -Axiom ethereum_arrow_glacier_fork_types_Root : - IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "Root". - -Require ethereum.arrow_glacier.transactions. -Axiom ethereum_arrow_glacier_transactions_LegacyTransaction : - IsGlobalAlias globals ethereum.arrow_glacier.transactions.globals "LegacyTransaction". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Tuple"; "Union" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes8"; "Bytes32"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. + +Axiom ethereum_arrow_glacier_fork_types_imports : + AreImported globals "ethereum.arrow_glacier.fork_types" [ "Address"; "Bloom"; "Root" ]. + +Axiom ethereum_arrow_glacier_transactions_imports : + AreImported globals "ethereum.arrow_glacier.transactions" [ "LegacyTransaction" ]. Definition Header : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/arrow_glacier/bloom.v b/CoqOfPython/ethereum/arrow_glacier/bloom.v index de6ac5b..0b959bb 100644 --- a/CoqOfPython/ethereum/arrow_glacier/bloom.v +++ b/CoqOfPython/ethereum/arrow_glacier/bloom.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.arrow_glacier.bloom". Definition expr_1 : Value.t := Constant.str " @@ -21,25 +21,20 @@ for efficient searching of logs by address and/or topic, by rapidly eliminating blocks and receipts from their search. ". -Require typing. -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_imports : + AreImported globals "typing" [ "Tuple" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. -Require ethereum.arrow_glacier.blocks. -Axiom ethereum_arrow_glacier_blocks_Log : - IsGlobalAlias globals ethereum.arrow_glacier.blocks.globals "Log". +Axiom ethereum_arrow_glacier_blocks_imports : + AreImported globals "ethereum.arrow_glacier.blocks" [ "Log" ]. -Require ethereum.arrow_glacier.fork_types. -Axiom ethereum_arrow_glacier_fork_types_Bloom : - IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "Bloom". +Axiom ethereum_arrow_glacier_fork_types_imports : + AreImported globals "ethereum.arrow_glacier.fork_types" [ "Bloom" ]. Definition add_to_bloom : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -66,50 +61,70 @@ Definition add_to_bloom : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "idx" |) in make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ] do - let bit_to_set := - BinOp.bit_and (| - M.call (| - M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "hash" |), M.slice (| M.get_name (| globals, "idx" |), BinOp.add (| - M.get_name (| globals, "idx" |), - Constant.int 2 - |) |) |) - ], - make_dict [] - |), - Constant.int 2047 - |) in - let bit_index := - BinOp.sub (| - Constant.int 2047, - M.get_name (| globals, "bit_to_set" |) - |) in - let byte_index := - BinOp.floor_div (| - M.get_name (| globals, "bit_index" |), - Constant.int 8 - |) in - let bit_value := - BinOp.l_shift (| - Constant.int 1, - BinOp.sub (| - Constant.int 7, - BinOp.mod_ (| + let _ := + M.for_ (| + M.get_name (| globals, "idx" |), + make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ], + ltac:(M.monadic ( + let bit_to_set := + BinOp.bit_and (| + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.slice (| + M.get_name (| globals, "hash" |), + M.get_name (| globals, "idx" |), + BinOp.add (| + M.get_name (| globals, "idx" |), + Constant.int 2 + |), + Constant.None_ + |) + ], + make_dict [] + |), + Constant.int 2047 + |) in + let bit_index := + BinOp.sub (| + Constant.int 2047, + M.get_name (| globals, "bit_to_set" |) + |) in + let byte_index := + BinOp.floor_div (| M.get_name (| globals, "bit_index" |), Constant.int 8 + |) in + let bit_value := + BinOp.l_shift (| + Constant.int 1, + BinOp.sub (| + Constant.int 7, + BinOp.mod_ (| + M.get_name (| globals, "bit_index" |), + Constant.int 8 + |) + |) + |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "bloom" |), + M.get_name (| globals, "byte_index" |) + |), + BinOp.bit_or (| + M.get_subscript (| + M.get_name (| globals, "bloom" |), + M.get_name (| globals, "byte_index" |) + |), + M.get_name (| globals, "bit_value" |) |) - |) - |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), - BinOp.bit_or (| - M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), - M.get_name (| globals, "bit_value" |) - |) - |) in - EndFor. + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_)). Definition logs_bloom : Value.t -> Value.t -> M := @@ -132,8 +147,12 @@ Definition logs_bloom : Value.t -> Value.t -> M := the caller address and the log topics. " in (* At stmt: unsupported node type: AnnAssign *) - For M.get_name (| globals, "log" |) in M.get_name (| globals, "logs" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "log" |), + M.get_name (| globals, "logs" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "add_to_bloom" |), make_list [ M.get_name (| globals, "bloom" |); @@ -141,8 +160,12 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "topic" |) in M.get_field (| M.get_name (| globals, "log" |), "topics" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "topic" |), + M.get_field (| M.get_name (| globals, "log" |), "topics" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "add_to_bloom" |), make_list [ M.get_name (| globals, "bloom" |); @@ -150,8 +173,18 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Bloom" |), diff --git a/CoqOfPython/ethereum/arrow_glacier/fork.v b/CoqOfPython/ethereum/arrow_glacier/fork.v index 563f3b3..225bbee 100644 --- a/CoqOfPython/ethereum/arrow_glacier/fork.v +++ b/CoqOfPython/ethereum/arrow_glacier/fork.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.arrow_glacier.fork". Definition expr_1 : Value.t := Constant.str " @@ -17,155 +17,62 @@ Introduction Entry point for the Ethereum specification. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". - -Require ethereum.base_types. -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". - -Require ethereum.crypto.elliptic_curve. -Axiom ethereum_crypto_elliptic_curve_SECP256K1N : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". -Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.ethash. -Axiom ethereum_ethash_dataset_size : - IsGlobalAlias globals ethereum.ethash.globals "dataset_size". -Axiom ethereum_ethash_generate_cache : - IsGlobalAlias globals ethereum.ethash.globals "generate_cache". -Axiom ethereum_ethash_hashimoto_light : - IsGlobalAlias globals ethereum.ethash.globals "hashimoto_light". - -Require ethereum.exceptions. -Axiom ethereum_exceptions_InvalidBlock : - IsGlobalAlias globals ethereum.exceptions.globals "InvalidBlock". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U64 : - IsGlobalAlias globals ethereum.base_types.globals "U64". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_U256_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.arrow_glacier.__init__. -Axiom ethereum_arrow_glacier___init___vm : - IsGlobalAlias globals ethereum.arrow_glacier.__init__.globals "vm". - -Require ethereum.arrow_glacier.blocks. -Axiom ethereum_arrow_glacier_blocks_Block : - IsGlobalAlias globals ethereum.arrow_glacier.blocks.globals "Block". -Axiom ethereum_arrow_glacier_blocks_Header : - IsGlobalAlias globals ethereum.arrow_glacier.blocks.globals "Header". -Axiom ethereum_arrow_glacier_blocks_Log : - IsGlobalAlias globals ethereum.arrow_glacier.blocks.globals "Log". -Axiom ethereum_arrow_glacier_blocks_Receipt : - IsGlobalAlias globals ethereum.arrow_glacier.blocks.globals "Receipt". - -Require ethereum.arrow_glacier.bloom. -Axiom ethereum_arrow_glacier_bloom_logs_bloom : - IsGlobalAlias globals ethereum.arrow_glacier.bloom.globals "logs_bloom". - -Require ethereum.arrow_glacier.fork_types. -Axiom ethereum_arrow_glacier_fork_types_Address : - IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "Address". -Axiom ethereum_arrow_glacier_fork_types_Bloom : - IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "Bloom". -Axiom ethereum_arrow_glacier_fork_types_Root : - IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "Root". - -Require ethereum.arrow_glacier.state. -Axiom ethereum_arrow_glacier_state_State : - IsGlobalAlias globals ethereum.arrow_glacier.state.globals "State". -Axiom ethereum_arrow_glacier_state_account_exists_and_is_empty : - IsGlobalAlias globals ethereum.arrow_glacier.state.globals "account_exists_and_is_empty". -Axiom ethereum_arrow_glacier_state_create_ether : - IsGlobalAlias globals ethereum.arrow_glacier.state.globals "create_ether". -Axiom ethereum_arrow_glacier_state_destroy_account : - IsGlobalAlias globals ethereum.arrow_glacier.state.globals "destroy_account". -Axiom ethereum_arrow_glacier_state_get_account : - IsGlobalAlias globals ethereum.arrow_glacier.state.globals "get_account". -Axiom ethereum_arrow_glacier_state_increment_nonce : - IsGlobalAlias globals ethereum.arrow_glacier.state.globals "increment_nonce". -Axiom ethereum_arrow_glacier_state_set_account_balance : - IsGlobalAlias globals ethereum.arrow_glacier.state.globals "set_account_balance". -Axiom ethereum_arrow_glacier_state_state_root : - IsGlobalAlias globals ethereum.arrow_glacier.state.globals "state_root". - -Require ethereum.arrow_glacier.transactions. -Axiom ethereum_arrow_glacier_transactions_TX_ACCESS_LIST_ADDRESS_COST : - IsGlobalAlias globals ethereum.arrow_glacier.transactions.globals "TX_ACCESS_LIST_ADDRESS_COST". -Axiom ethereum_arrow_glacier_transactions_TX_ACCESS_LIST_STORAGE_KEY_COST : - IsGlobalAlias globals ethereum.arrow_glacier.transactions.globals "TX_ACCESS_LIST_STORAGE_KEY_COST". -Axiom ethereum_arrow_glacier_transactions_TX_BASE_COST : - IsGlobalAlias globals ethereum.arrow_glacier.transactions.globals "TX_BASE_COST". -Axiom ethereum_arrow_glacier_transactions_TX_CREATE_COST : - IsGlobalAlias globals ethereum.arrow_glacier.transactions.globals "TX_CREATE_COST". -Axiom ethereum_arrow_glacier_transactions_TX_DATA_COST_PER_NON_ZERO : - IsGlobalAlias globals ethereum.arrow_glacier.transactions.globals "TX_DATA_COST_PER_NON_ZERO". -Axiom ethereum_arrow_glacier_transactions_TX_DATA_COST_PER_ZERO : - IsGlobalAlias globals ethereum.arrow_glacier.transactions.globals "TX_DATA_COST_PER_ZERO". -Axiom ethereum_arrow_glacier_transactions_AccessListTransaction : - IsGlobalAlias globals ethereum.arrow_glacier.transactions.globals "AccessListTransaction". -Axiom ethereum_arrow_glacier_transactions_FeeMarketTransaction : - IsGlobalAlias globals ethereum.arrow_glacier.transactions.globals "FeeMarketTransaction". -Axiom ethereum_arrow_glacier_transactions_LegacyTransaction : - IsGlobalAlias globals ethereum.arrow_glacier.transactions.globals "LegacyTransaction". -Axiom ethereum_arrow_glacier_transactions_Transaction : - IsGlobalAlias globals ethereum.arrow_glacier.transactions.globals "Transaction". -Axiom ethereum_arrow_glacier_transactions_decode_transaction : - IsGlobalAlias globals ethereum.arrow_glacier.transactions.globals "decode_transaction". -Axiom ethereum_arrow_glacier_transactions_encode_transaction : - IsGlobalAlias globals ethereum.arrow_glacier.transactions.globals "encode_transaction". - -Require ethereum.arrow_glacier.trie. -Axiom ethereum_arrow_glacier_trie_Trie : - IsGlobalAlias globals ethereum.arrow_glacier.trie.globals "Trie". -Axiom ethereum_arrow_glacier_trie_root : - IsGlobalAlias globals ethereum.arrow_glacier.trie.globals "root". -Axiom ethereum_arrow_glacier_trie_trie_set : - IsGlobalAlias globals ethereum.arrow_glacier.trie.globals "trie_set". - -Require ethereum.arrow_glacier.utils.message. -Axiom ethereum_arrow_glacier_utils_message_prepare_message : - IsGlobalAlias globals ethereum.arrow_glacier.utils.message.globals "prepare_message". - -Require ethereum.arrow_glacier.vm.interpreter. -Axiom ethereum_arrow_glacier_vm_interpreter_process_message_call : - IsGlobalAlias globals ethereum.arrow_glacier.vm.interpreter.globals "process_message_call". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple"; "Union" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Bytes0" ]. + +Axiom ethereum_crypto_elliptic_curve_imports : + AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. + +Axiom ethereum_ethash_imports : + AreImported globals "ethereum.ethash" [ "dataset_size"; "generate_cache"; "hashimoto_light" ]. + +Axiom ethereum_exceptions_imports : + AreImported globals "ethereum.exceptions" [ "InvalidBlock" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U64"; "U256"; "U256_CEIL_VALUE"; "Bytes"; "Uint" ]. + +Axiom ethereum_arrow_glacier_imports : + AreImported globals "ethereum.arrow_glacier" [ "vm" ]. + +Axiom ethereum_arrow_glacier_blocks_imports : + AreImported globals "ethereum.arrow_glacier.blocks" [ "Block"; "Header"; "Log"; "Receipt" ]. + +Axiom ethereum_arrow_glacier_bloom_imports : + AreImported globals "ethereum.arrow_glacier.bloom" [ "logs_bloom" ]. + +Axiom ethereum_arrow_glacier_fork_types_imports : + AreImported globals "ethereum.arrow_glacier.fork_types" [ "Address"; "Bloom"; "Root" ]. + +Axiom ethereum_arrow_glacier_state_imports : + AreImported globals "ethereum.arrow_glacier.state" [ "State"; "account_exists_and_is_empty"; "create_ether"; "destroy_account"; "get_account"; "increment_nonce"; "set_account_balance"; "state_root" ]. + +Axiom ethereum_arrow_glacier_transactions_imports : + AreImported globals "ethereum.arrow_glacier.transactions" [ "TX_ACCESS_LIST_ADDRESS_COST"; "TX_ACCESS_LIST_STORAGE_KEY_COST"; "TX_BASE_COST"; "TX_CREATE_COST"; "TX_DATA_COST_PER_NON_ZERO"; "TX_DATA_COST_PER_ZERO"; "AccessListTransaction"; "FeeMarketTransaction"; "LegacyTransaction"; "Transaction"; "decode_transaction"; "encode_transaction" ]. + +Axiom ethereum_arrow_glacier_trie_imports : + AreImported globals "ethereum.arrow_glacier.trie" [ "Trie"; "root"; "trie_set" ]. + +Axiom ethereum_arrow_glacier_utils_message_imports : + AreImported globals "ethereum.arrow_glacier.utils.message" [ "prepare_message" ]. + +Axiom ethereum_arrow_glacier_vm_interpreter_imports : + AreImported globals "ethereum.arrow_glacier.vm.interpreter" [ "process_message_call" ]. Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -292,7 +199,12 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := Hashes of the recent 256 blocks in order of increasing block number. " in let recent_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) in + M.slice (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| Constant.int 255 |), + Constant.None_, + Constant.None_ + |) in let _ := (* if *) M.if_then_else (| @@ -318,17 +230,26 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := )) |) in let recent_block_hashes := make_list [] in - For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_blocks" |) do - let prev_block_hash := - M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "block" |), + M.get_name (| globals, "recent_blocks" |), + ltac:(M.monadic ( + let prev_block_hash := + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in + let _ := M.call (| M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), make_list [ M.get_name (| globals, "prev_block_hash" |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let most_recent_block_hash := M.call (| M.get_name (| globals, "keccak256" |), @@ -336,7 +257,10 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), make_list [ - M.get_field (| M.get_subscript (| M.get_name (| globals, "recent_blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) + M.get_field (| M.get_subscript (| + M.get_name (| globals, "recent_blocks" |), + UnOp.sub (| Constant.int 1 |) + |), "header" |) ], make_dict [] |) @@ -380,7 +304,10 @@ Definition state_transition : Value.t -> Value.t -> M := Block to apply to `chain`. " in let parent_header := - M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) in + M.get_field (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| Constant.int 1 |) + |), "header" |) in let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ @@ -501,7 +428,12 @@ Definition state_transition : Value.t -> Value.t -> M := ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) + M.slice (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| Constant.int 255 |), + Constant.None_, + Constant.None_ + |) |) in M.pure Constant.None_ (* else *) @@ -1223,21 +1155,25 @@ Definition apply_body : Value.t -> Value.t -> M := (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) - For make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "tx" |) ] in M.call (| - M.get_name (| globals, "enumerate" |), - make_list [ - M.call (| - M.get_name (| globals, "map" |), - make_list [ - M.get_name (| globals, "decode_transaction" |); - M.get_name (| globals, "transactions" |) - ], - make_dict [] - |) - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "tx" |) ], + M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.call (| + M.get_name (| globals, "map" |), + make_list [ + M.get_name (| globals, "decode_transaction" |); + M.get_name (| globals, "transactions" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ M.get_name (| globals, "transactions_trie" |); @@ -1264,54 +1200,54 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.assign (| - make_tuple [ M.get_name (| globals, "sender_address" |); M.get_name (| globals, "effective_gas_price" |) ], - M.call (| - M.get_name (| globals, "check_transaction" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "base_fee_per_gas" |); - M.get_name (| globals, "gas_available" |); - M.get_name (| globals, "chain_id" |) - ], - make_dict [] - |) - |) in - let env := - M.call (| - M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), - make_list [], - make_dict [] - |) in - let _ := M.assign (| - make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |); M.get_name (| globals, "error" |) ], - M.call (| - M.get_name (| globals, "process_transaction" |), - make_list [ - M.get_name (| globals, "env" |); - M.get_name (| globals, "tx" |) - ], - make_dict [] - |) - |) in - let gas_available := BinOp.sub - M.get_name (| globals, "gas_used" |) - M.get_name (| globals, "gas_used" |) in - let receipt := - M.call (| - M.get_name (| globals, "make_receipt" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "error" |); - BinOp.sub (| - M.get_name (| globals, "block_gas_limit" |), - M.get_name (| globals, "gas_available" |) - |); - M.get_name (| globals, "logs" |) - ], - make_dict [] - |) in - let _ := M.call (| + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "sender_address" |); M.get_name (| globals, "effective_gas_price" |) ], + M.call (| + M.get_name (| globals, "check_transaction" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "base_fee_per_gas" |); + M.get_name (| globals, "gas_available" |); + M.get_name (| globals, "chain_id" |) + ], + make_dict [] + |) + |) in + let env := + M.call (| + M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |); M.get_name (| globals, "error" |) ], + M.call (| + M.get_name (| globals, "process_transaction" |), + make_list [ + M.get_name (| globals, "env" |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) in + let gas_available := BinOp.sub + M.get_name (| globals, "gas_used" |) + M.get_name (| globals, "gas_used" |) in + let receipt := + M.call (| + M.get_name (| globals, "make_receipt" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "error" |); + BinOp.sub (| + M.get_name (| globals, "block_gas_limit" |), + M.get_name (| globals, "gas_available" |) + |); + M.get_name (| globals, "logs" |) + ], + make_dict [] + |) in + let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ M.get_name (| globals, "receipts_trie" |); @@ -1332,10 +1268,15 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_logs := BinOp.add - M.get_name (| globals, "logs" |) - M.get_name (| globals, "logs" |) in - EndFor. + let block_logs := BinOp.add + M.get_name (| globals, "logs" |) + M.get_name (| globals, "logs" |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.call (| M.get_name (| globals, "pay_rewards" |), make_list [ @@ -1464,8 +1405,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "ommer" |), + M.get_name (| globals, "ommers" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ BoolOp.and (| @@ -1484,15 +1429,18 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_parent_header := - M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), BinOp.sub (| - UnOp.sub (| BinOp.sub (| - M.get_field (| M.get_name (| globals, "block_header" |), "number" |), - M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) |), - Constant.int 1 - |) |), "header" |) in - let _ := M.call (| + let ommer_parent_header := + M.get_field (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + BinOp.sub (| + UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) |), + Constant.int 1 + |) + |), "header" |) in + let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ M.get_name (| globals, "ommer" |); @@ -1500,7 +1448,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1550,33 +1503,54 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let recent_canonical_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| BinOp.add (| - M.get_name (| globals, "MAX_OMMER_DEPTH" |), - Constant.int 1 - |) |), Constant.None_ |) |) in + M.slice (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| BinOp.add (| + M.get_name (| globals, "MAX_OMMER_DEPTH" |), + Constant.int 1 + |) |), + Constant.None_, + Constant.None_ + |) in let recent_canonical_block_hashes := Constant.str "(* At expr: unsupported node type: SetComp *)" in (* At stmt: unsupported node type: AnnAssign *) - For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_canonical_blocks" |) do - let recent_ommers_hashes := + let _ := + M.for_ (| + M.get_name (| globals, "block" |), + M.get_name (| globals, "recent_canonical_blocks" |), + ltac:(M.monadic ( + let recent_ommers_hashes := + M.call (| + M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), + make_list [ + Constant.str "(* At expr: unsupported node type: SetComp *)" + ], + make_dict [] + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "ommer_index" |); M.get_name (| globals, "ommer" |) ], M.call (| - M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), - make_list [ - Constant.str "(* At expr: unsupported node type: SetComp *)" - ], - make_dict [] - |) in - EndFor. - For make_tuple [ M.get_name (| globals, "ommer_index" |); M.get_name (| globals, "ommer" |) ] in M.call (| - M.get_name (| globals, "enumerate" |), - make_list [ - M.get_name (| globals, "ommers" |) - ], - make_dict [] - |) do - let ommer_hash := - M.get_subscript (| M.get_name (| globals, "ommers_hashes" |), M.get_name (| globals, "ommer_index" |) |) in - let _ := M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let ommer_hash := + M.get_subscript (| + M.get_name (| globals, "ommers_hashes" |), + M.get_name (| globals, "ommer_index" |) + |) in + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_eq (| @@ -1587,7 +1561,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_in (| @@ -1598,7 +1572,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_in (| @@ -1609,12 +1583,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_age := - BinOp.sub (| - M.get_field (| M.get_name (| globals, "block_header" |), "number" |), - M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) in - let _ := M.call (| + let ommer_age := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) in + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ BoolOp.and (| @@ -1633,10 +1607,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.in (| + Compare.in_ (| M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), M.get_name (| globals, "recent_canonical_block_hashes" |) |); @@ -1644,7 +1618,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_eq (| @@ -1655,7 +1629,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_)). Definition pay_rewards : Value.t -> Value.t -> M := @@ -1712,30 +1691,34 @@ Definition pay_rewards : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do - let ommer_age := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - BinOp.sub (| - M.get_name (| globals, "block_number" |), - M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) - ], - make_dict [] - |) in - let ommer_miner_reward := - BinOp.floor_div (| - BinOp.mult (| - BinOp.sub (| - Constant.int 8, - M.get_name (| globals, "ommer_age" |) - |), - M.get_name (| globals, "BLOCK_REWARD" |) - |), - Constant.int 8 - |) in - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "ommer" |), + M.get_name (| globals, "ommers" |), + ltac:(M.monadic ( + let ommer_age := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "block_number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) + ], + make_dict [] + |) in + let ommer_miner_reward := + BinOp.floor_div (| + BinOp.mult (| + BinOp.sub (| + Constant.int 8, + M.get_name (| globals, "ommer_age" |) + |), + M.get_name (| globals, "BLOCK_REWARD" |) + |), + Constant.int 8 + |) in + let _ := M.call (| M.get_name (| globals, "create_ether" |), make_list [ M.get_name (| globals, "state" |); @@ -1744,7 +1727,12 @@ Definition pay_rewards : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_)). Definition process_transaction : Value.t -> Value.t -> M := @@ -1932,24 +1920,42 @@ Definition process_transaction : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - For make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "keys" |) ] in M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) do - let _ := M.call (| + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "keys" |) ], + M.get_field (| M.get_name (| globals, "tx" |), "access_list" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "preaccessed_addresses" |), "add" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] |) in - For M.get_name (| globals, "key" |) in M.get_name (| globals, "keys" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "keys" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "preaccessed_storage_keys" |), "add" |), make_list [ make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "key" |) ] ], make_dict [] |) in - EndFor. - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -2105,8 +2111,12 @@ Definition process_transaction : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "accounts_to_delete" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "output" |), "accounts_to_delete" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "destroy_account" |), make_list [ M.get_field (| M.get_name (| globals, "env" |), "state" |); @@ -2114,22 +2124,31 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. - For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "touched_accounts" |) do - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), - (* then *) + M.pure Constant.None_ + )), ltac:(M.monadic ( - let _ := M.call (| + M.pure Constant.None_ + )) + |) in + let _ := + M.for_ (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "output" |), "touched_accounts" |), + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "destroy_account" |), make_list [ M.get_field (| M.get_name (| globals, "env" |), "state" |); @@ -2137,12 +2156,17 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := M.return_ (| make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |); M.get_field (| M.get_name (| globals, "output" |), "error" |) ] |) in @@ -2230,28 +2254,37 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := " in let data_cost := Constant.int 0 in - For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "byte" |), - Constant.int 0 - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "byte" |), + M.get_field (| M.get_name (| globals, "tx" |), "data" |), ltac:(M.monadic ( - let data_cost := BinOp.add - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "byte" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let data_cost := BinOp.add - M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := (* if *) M.if_then_else (| @@ -2291,12 +2324,16 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - For make_tuple [ M.get_name (| globals, "_address" |); M.get_name (| globals, "keys" |) ] in M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) do - let access_list_cost := BinOp.add - M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) - M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) in - let access_list_cost := BinOp.add - BinOp.mult (| + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "_address" |); M.get_name (| globals, "keys" |) ], + M.get_field (| M.get_name (| globals, "tx" |), "access_list" |), + ltac:(M.monadic ( + let access_list_cost := BinOp.add + M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) + M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) in + let access_list_cost := BinOp.add + BinOp.mult (| M.call (| M.get_name (| globals, "len" |), make_list [ @@ -2306,7 +2343,7 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) |) - BinOp.mult (| + BinOp.mult (| M.call (| M.get_name (| globals, "len" |), make_list [ @@ -2316,7 +2353,12 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -2605,13 +2647,18 @@ Definition recover_sender : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "Address" |), make_list [ - M.get_subscript (| M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "public_key" |) - ], - make_dict [] - |), M.slice (| Constant.int 12, Constant.int 32 |) |) + M.slice (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), + Constant.int 12, + Constant.int 32, + Constant.None_ + |) ], make_dict [] |) diff --git a/CoqOfPython/ethereum/arrow_glacier/fork_types.v b/CoqOfPython/ethereum/arrow_glacier/fork_types.v index cc8e4a1..d08565d 100644 --- a/CoqOfPython/ethereum/arrow_glacier/fork_types.v +++ b/CoqOfPython/ethereum/arrow_glacier/fork_types.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.arrow_glacier.fork_types". Definition expr_1 : Value.t := Constant.str " @@ -17,33 +17,17 @@ Introduction Types re-used throughout the specification, which are specific to Ethereum. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes20 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes20". -Axiom ethereum_base_types_Bytes256 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes20"; "Bytes256"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) diff --git a/CoqOfPython/ethereum/arrow_glacier/state.v b/CoqOfPython/ethereum/arrow_glacier/state.v index 54c9d2e..18088d3 100644 --- a/CoqOfPython/ethereum/arrow_glacier/state.v +++ b/CoqOfPython/ethereum/arrow_glacier/state.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.arrow_glacier.state". Definition expr_1 : Value.t := Constant.str " @@ -22,63 +22,23 @@ There is a distinction between an account that does not exist and `EMPTY_ACCOUNT`. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". -Axiom dataclasses_field : - IsGlobalAlias globals dataclasses.globals "field". - -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_modify : - IsGlobalAlias globals ethereum.base_types.globals "modify". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.arrow_glacier.fork_types. -Axiom ethereum_arrow_glacier_fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "EMPTY_ACCOUNT". -Axiom ethereum_arrow_glacier_fork_types_Account : - IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "Account". -Axiom ethereum_arrow_glacier_fork_types_Address : - IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "Address". -Axiom ethereum_arrow_glacier_fork_types_Root : - IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "Root". - -Require ethereum.arrow_glacier.trie. -Axiom ethereum_arrow_glacier_trie_EMPTY_TRIE_ROOT : - IsGlobalAlias globals ethereum.arrow_glacier.trie.globals "EMPTY_TRIE_ROOT". -Axiom ethereum_arrow_glacier_trie_Trie : - IsGlobalAlias globals ethereum.arrow_glacier.trie.globals "Trie". -Axiom ethereum_arrow_glacier_trie_copy_trie : - IsGlobalAlias globals ethereum.arrow_glacier.trie.globals "copy_trie". -Axiom ethereum_arrow_glacier_trie_root : - IsGlobalAlias globals ethereum.arrow_glacier.trie.globals "root". -Axiom ethereum_arrow_glacier_trie_trie_get : - IsGlobalAlias globals ethereum.arrow_glacier.trie.globals "trie_get". -Axiom ethereum_arrow_glacier_trie_trie_set : - IsGlobalAlias globals ethereum.arrow_glacier.trie.globals "trie_set". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass"; "field" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict"; "List"; "Optional"; "Set"; "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "modify" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_arrow_glacier_fork_types_imports : + AreImported globals "ethereum.arrow_glacier.fork_types" [ "EMPTY_ACCOUNT"; "Account"; "Address"; "Root" ]. + +Axiom ethereum_arrow_glacier_trie_imports : + AreImported globals "ethereum.arrow_glacier.trie" [ "EMPTY_TRIE_ROOT"; "Trie"; "copy_trie"; "root"; "trie_get"; "trie_set" ]. Definition State : Value.t := builtins.make_klass @@ -373,13 +333,16 @@ Definition destroy_storage : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -542,7 +505,10 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), + M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |), M.get_name (| globals, "trie" |) |) in M.pure Constant.None_ @@ -568,7 +534,10 @@ Definition set_storage : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -598,7 +567,7 @@ Definition storage_root : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), @@ -608,7 +577,10 @@ Definition storage_root : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "root" |), make_list [ - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) + M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |) ], make_dict [] |) @@ -1167,7 +1139,7 @@ Definition get_storage_original : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |) |), @@ -1189,7 +1161,10 @@ Definition get_storage_original : Value.t -> Value.t -> M := )) |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "_" |); M.get_name (| globals, "original_trie" |) ], - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), Constant.int 0 |) + M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), + Constant.int 0 + |) |) in let original_account_trie := M.call (| diff --git a/CoqOfPython/ethereum/arrow_glacier/transactions.v b/CoqOfPython/ethereum/arrow_glacier/transactions.v index 03937fc..770e331 100644 --- a/CoqOfPython/ethereum/arrow_glacier/transactions.v +++ b/CoqOfPython/ethereum/arrow_glacier/transactions.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.arrow_glacier.transactions". Definition expr_1 : Value.t := Constant.str " @@ -9,43 +9,23 @@ submitted to be executed. If Ethereum is viewed as a state machine, transactions are the events that move between states. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. -Require typing. -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". +Axiom typing_imports : + AreImported globals "typing" [ "Tuple"; "Union" ]. -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U64 : - IsGlobalAlias globals ethereum.base_types.globals "U64". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U64"; "U256"; "Bytes"; "Bytes0"; "Bytes32"; "Uint"; "slotted_freezable" ]. -Require ethereum.exceptions. -Axiom ethereum_exceptions_InvalidBlock : - IsGlobalAlias globals ethereum.exceptions.globals "InvalidBlock". +Axiom ethereum_exceptions_imports : + AreImported globals "ethereum.exceptions" [ "InvalidBlock" ]. -Require ethereum.arrow_glacier.fork_types. -Axiom ethereum_arrow_glacier_fork_types_Address : - IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "Address". +Axiom ethereum_arrow_glacier_fork_types_imports : + AreImported globals "ethereum.arrow_glacier.fork_types" [ "Address" ]. Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( Constant.int 21000 @@ -102,7 +82,10 @@ Definition FeeMarketTransaction : Value.t := ]. Definition Transaction : Value.t := M.run ltac:(M.monadic ( - M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "AccessListTransaction" |); M.get_name (| globals, "FeeMarketTransaction" |) ] |) + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "AccessListTransaction" |); M.get_name (| globals, "FeeMarketTransaction" |) ] + |) )). Definition encode_transaction : Value.t -> Value.t -> M := @@ -186,7 +169,7 @@ Definition encode_transaction : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "Exception" |), make_list [ Constant.str "(* At expr: unsupported node type: JoinedStr *)" @@ -224,7 +207,10 @@ Definition decode_transaction : Value.t -> Value.t -> M := (* if *) M.if_then_else (| Compare.eq (| - M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), + M.get_subscript (| + M.get_name (| globals, "tx" |), + Constant.int 0 + |), Constant.int 1 |), (* then *) @@ -234,7 +220,12 @@ Definition decode_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), make_list [ M.get_name (| globals, "AccessListTransaction" |); - M.get_subscript (| M.get_name (| globals, "tx" |), M.slice (| Constant.int 1, Constant.None_ |) |) + M.slice (| + M.get_name (| globals, "tx" |), + Constant.int 1, + Constant.None_, + Constant.None_ + |) ], make_dict [] |) @@ -246,7 +237,10 @@ Definition decode_transaction : Value.t -> Value.t -> M := (* if *) M.if_then_else (| Compare.eq (| - M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), + M.get_subscript (| + M.get_name (| globals, "tx" |), + Constant.int 0 + |), Constant.int 2 |), (* then *) @@ -256,7 +250,12 @@ Definition decode_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), make_list [ M.get_name (| globals, "FeeMarketTransaction" |); - M.get_subscript (| M.get_name (| globals, "tx" |), M.slice (| Constant.int 1, Constant.None_ |) |) + M.slice (| + M.get_name (| globals, "tx" |), + Constant.int 1, + Constant.None_, + Constant.None_ + |) ], make_dict [] |) @@ -264,7 +263,7 @@ Definition decode_transaction : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidBlock" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "InvalidBlock" |)) |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/arrow_glacier/trie.v b/CoqOfPython/ethereum/arrow_glacier/trie.v index ca56755..022a627 100644 --- a/CoqOfPython/ethereum/arrow_glacier/trie.v +++ b/CoqOfPython/ethereum/arrow_glacier/trie.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.arrow_glacier.trie". Definition expr_1 : Value.t := Constant.str " @@ -20,83 +20,38 @@ The state trie is the structure responsible for storing (* At top_level_stmt: unsupported node type: Import *) -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". -Axiom dataclasses_field : - IsGlobalAlias globals dataclasses.globals "field". - -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". -Axiom typing_Generic : - IsGlobalAlias globals typing.globals "Generic". -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Mapping : - IsGlobalAlias globals typing.globals "Mapping". -Axiom typing_MutableMapping : - IsGlobalAlias globals typing.globals "MutableMapping". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Sequence : - IsGlobalAlias globals typing.globals "Sequence". -Axiom typing_TypeVar : - IsGlobalAlias globals typing.globals "TypeVar". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". -Axiom typing_cast : - IsGlobalAlias globals typing.globals "cast". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.london.__init__. -Axiom ethereum_london___init___trie : - IsGlobalAlias globals ethereum.london.__init__.globals "trie". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.utils.hexadecimal. -Axiom ethereum_utils_hexadecimal_hex_to_bytes : - IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.arrow_glacier.blocks. -Axiom ethereum_arrow_glacier_blocks_Receipt : - IsGlobalAlias globals ethereum.arrow_glacier.blocks.globals "Receipt". - -Require ethereum.arrow_glacier.fork_types. -Axiom ethereum_arrow_glacier_fork_types_Account : - IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "Account". -Axiom ethereum_arrow_glacier_fork_types_Address : - IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "Address". -Axiom ethereum_arrow_glacier_fork_types_Root : - IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "Root". -Axiom ethereum_arrow_glacier_fork_types_encode_account : - IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "encode_account". - -Require ethereum.arrow_glacier.transactions. -Axiom ethereum_arrow_glacier_transactions_LegacyTransaction : - IsGlobalAlias globals ethereum.arrow_glacier.transactions.globals "LegacyTransaction". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass"; "field" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict"; "Generic"; "List"; "Mapping"; "MutableMapping"; "Optional"; "Sequence"; "TypeVar"; "Union"; "cast" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. + +Axiom ethereum_london_imports : + AreImported globals "ethereum.london" [ "trie" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_utils_hexadecimal_imports : + AreImported globals "ethereum.utils.hexadecimal" [ "hex_to_bytes" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_arrow_glacier_blocks_imports : + AreImported globals "ethereum.arrow_glacier.blocks" [ "Receipt" ]. + +Axiom ethereum_arrow_glacier_fork_types_imports : + AreImported globals "ethereum.arrow_glacier.fork_types" [ "Account"; "Address"; "Root"; "encode_account" ]. + +Axiom ethereum_arrow_glacier_transactions_imports : + AreImported globals "ethereum.arrow_glacier.transactions" [ "LegacyTransaction" ]. Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -115,7 +70,10 @@ Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( )). Definition Node : Value.t := M.run ltac:(M.monadic ( - M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Bytes" |); M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |); Constant.None_ ] |) + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Bytes" |); M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |); Constant.None_ ] + |) )). Definition K : Value.t := M.run ltac:(M.monadic ( @@ -133,11 +91,29 @@ Definition V : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "TypeVar" |), make_list [ Constant.str "V"; - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Account" |) |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Bytes" |) |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Account" |) + |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Bytes" |) + |); M.get_name (| globals, "Bytes" |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Bytes" |) ] |) |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Bytes" |) ] |) |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Bytes" |) ] + |) + |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Bytes" |) ] + |) + |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |) ], @@ -176,7 +152,10 @@ Definition BranchNode : Value.t := ]. Definition InternalNode : Value.t := M.run ltac:(M.monadic ( - M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LeafNode" |); M.get_name (| globals, "ExtensionNode" |); M.get_name (| globals, "BranchNode" |) ] |) + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "LeafNode" |); M.get_name (| globals, "ExtensionNode" |); M.get_name (| globals, "BranchNode" |) ] + |) )). Definition encode_internal_node : Value.t -> Value.t -> M := @@ -288,7 +267,7 @@ Definition encode_internal_node : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "(* At expr: unsupported node type: JoinedStr *)" @@ -528,13 +507,16 @@ Definition trie_set : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "key" |), M.get_field (| M.get_name (| globals, "trie" |), "_data" |) |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + M.get_name (| globals, "key" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -544,7 +526,10 @@ Definition trie_set : Value.t -> Value.t -> M := (* else *) )), ltac:(M.monadic ( let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), + M.get_subscript (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + M.get_name (| globals, "key" |) + |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_ @@ -589,51 +574,66 @@ Definition common_prefix_length : Value.t -> Value.t -> M := let _ := Constant.str " Find the longest common prefix of two sequences. " in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "a" |) - ], - make_dict [] - |) - ], - make_dict [] - |) do - let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| - M.get_name (| globals, "i" |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "b" |) - ], - make_dict [] - |) - |), - ltac:(M.monadic ( - Compare.not_eq (| - M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), - M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) - |) - )) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + ], + make_dict [] + |), ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "i" |) - |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_subscript (| + M.get_name (| globals, "a" |), + M.get_name (| globals, "i" |) + |), + M.get_subscript (| + M.get_name (| globals, "b" |), + M.get_name (| globals, "i" |) + |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "len" |), @@ -718,38 +718,53 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 0; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |); - Constant.int 2 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ BinOp.add (| BinOp.mult (| Constant.int 16, - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "i" |) + |) |), - M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) + |) |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -767,43 +782,61 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := Constant.int 1 |) |), - M.get_subscript (| M.get_name (| globals, "x" |), Constant.int 0 |) + M.get_subscript (| + M.get_name (| globals, "x" |), + Constant.int 0 + |) |) ], make_dict [] |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 1; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |); - Constant.int 2 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 1; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ BinOp.add (| BinOp.mult (| Constant.int 16, - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "i" |) + |) |), - M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) + |) |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -850,40 +883,55 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := ], make_dict [] |) in - For make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ] in M.call (| - M.get_name (| globals, "enumerate" |), - make_list [ - M.get_name (| globals, "bytes_" |) - ], - make_dict [] - |) do - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.mult (| - M.get_name (| globals, "byte_index" |), - Constant.int 2 - |) |), - BinOp.r_shift (| - BinOp.bit_and (| - M.get_name (| globals, "byte" |), - Constant.int 240 - |), - Constant.int 4 - |) - |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "byte_index" |), - Constant.int 2 - |), - Constant.int 1 - |) |), - BinOp.bit_and (| - M.get_name (| globals, "byte" |), - Constant.int 15 - |) - |) in - EndFor. + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ], + M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "bytes_" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "nibble_list" |), + BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |) + |), + BinOp.r_shift (| + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 240 + |), + Constant.int 4 + |) + |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "nibble_list" |), + BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |), + Constant.int 1 + |) + |), + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 15 + |) + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Bytes" |), @@ -916,65 +964,69 @@ Definition _prepare_trie : Value.t -> Value.t -> M := Object with keys mapped to nibble-byte form. " in (* At stmt: unsupported node type: AnnAssign *) - For make_tuple [ M.get_name (| globals, "preimage" |); M.get_name (| globals, "value" |) ] in M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "items" |), - make_list [], - make_dict [] - |) do - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "value" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "preimage" |); M.get_name (| globals, "value" |) ], + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "items" |), + make_list [], + make_dict [] + |), ltac:(M.monadic ( - let _ := M.assert (| Compare.is_not (| + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in - let address := - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in - let encoded_value := - M.call (| - M.get_name (| globals, "encode_node" |), - make_list [ - M.get_name (| globals, "value" |); + let address := M.call (| - M.get_name (| globals, "get_storage_root" |), + M.get_name (| globals, "Address" |), make_list [ - M.get_name (| globals, "address" |) + M.get_name (| globals, "preimage" |) ], make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let encoded_value := - M.call (| - M.get_name (| globals, "encode_node" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - )) |) in - let _ := M.call (| + |) in + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |); + M.call (| + M.get_name (| globals, "get_storage_root" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_eq (| @@ -986,38 +1038,46 @@ Definition _prepare_trie : Value.t -> Value.t -> M := make_dict [] |) in (* At stmt: unsupported node type: AnnAssign *) - let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "trie" |), "secured" |), - (* then *) - ltac:(M.monadic ( - let key := - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "trie" |), "secured" |), + (* then *) + ltac:(M.monadic ( + let key := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let key := + M.get_name (| globals, "preimage" |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "mapped" |), + M.call (| + M.get_name (| globals, "bytes_to_nibble_list" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |) + |), + M.get_name (| globals, "encoded_value" |) + |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let key := - M.get_name (| globals, "preimage" |) in + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "mapped" |), M.call (| - M.get_name (| globals, "bytes_to_nibble_list" |), - make_list [ - M.get_name (| globals, "key" |) - ], - make_dict [] - |) |), - M.get_name (| globals, "encoded_value" |) - |) in - EndFor. + )) + |) in let _ := M.return_ (| M.get_name (| globals, "mapped" |) |) in @@ -1210,8 +1270,16 @@ Definition patricialize : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "LeafNode" |), make_list [ - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |); - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) + M.slice (| + M.get_name (| globals, "arbitrary_key" |), + M.get_name (| globals, "level" |), + Constant.None_, + Constant.None_ + |); + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "arbitrary_key" |) + |) ], make_dict [] |) in @@ -1224,7 +1292,12 @@ Definition patricialize : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in let substring := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "arbitrary_key" |), + M.get_name (| globals, "level" |), + Constant.None_, + Constant.None_ + |) in let prefix_length := M.call (| M.get_name (| globals, "len" |), @@ -1233,39 +1306,53 @@ Definition patricialize : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do - let prefix_length := - M.call (| - M.get_name (| globals, "min" |), - make_list [ - M.get_name (| globals, "prefix_length" |); + let _ := + M.for_ (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "obj" |), + ltac:(M.monadic ( + let prefix_length := M.call (| - M.get_name (| globals, "common_prefix_length" |), + M.get_name (| globals, "min" |), make_list [ - M.get_name (| globals, "substring" |); - M.get_subscript (| M.get_name (| globals, "key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) + M.get_name (| globals, "prefix_length" |); + M.call (| + M.get_name (| globals, "common_prefix_length" |), + make_list [ + M.get_name (| globals, "substring" |); + M.slice (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "level" |), + Constant.None_, + Constant.None_ + |) + ], + make_dict [] + |) ], make_dict [] - |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "prefix_length" |), - Constant.int 0 - |), - (* then *) - ltac:(M.monadic ( - let _ := M.break (| |) in + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "prefix_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := (* if *) M.if_then_else (| @@ -1276,10 +1363,15 @@ Definition patricialize : Value.t -> Value.t -> M := (* then *) ltac:(M.monadic ( let prefix := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), BinOp.add (| + M.slice (| + M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |), - M.get_name (| globals, "prefix_length" |) - |) |) |) in + BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |), + Constant.None_ + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ExtensionNode" |), @@ -1312,70 +1404,106 @@ Definition patricialize : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) - For M.get_name (| globals, "_" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 16 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "_" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 16 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "branches" |), "append" |), make_list [ {} ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let value := Constant.bytes "" in - For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "key" |) - ], - make_dict [] - |), - M.get_name (| globals, "level" |) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "obj" |), ltac:(M.monadic ( let _ := (* if *) M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); - make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] - ], - make_dict [] + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |), + M.get_name (| globals, "level" |) |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "AssertionError" |)) |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "key" |) + |); + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "AssertionError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "key" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| + M.get_subscript (| + M.get_name (| globals, "branches" |), + M.get_subscript (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "level" |) + |) + |), + M.get_name (| globals, "key" |) + |), + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "key" |) + |) + |) in M.pure Constant.None_ )) |) in - let value := - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.assign (| - M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) - |) in + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "BranchNode" |), diff --git a/CoqOfPython/ethereum/arrow_glacier/utils/__init__.v b/CoqOfPython/ethereum/arrow_glacier/utils/__init__.v index 1baedea..15ee17f 100644 --- a/CoqOfPython/ethereum/arrow_glacier/utils/__init__.v +++ b/CoqOfPython/ethereum/arrow_glacier/utils/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.arrow_glacier.utils.__init__". Definition expr_1 : Value.t := Constant.str " diff --git a/CoqOfPython/ethereum/arrow_glacier/utils/address.v b/CoqOfPython/ethereum/arrow_glacier/utils/address.v index cb8b8d7..8f6b436 100644 --- a/CoqOfPython/ethereum/arrow_glacier/utils/address.v +++ b/CoqOfPython/ethereum/arrow_glacier/utils/address.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.arrow_glacier.utils.address". Definition expr_1 : Value.t := Constant.str " @@ -18,33 +18,23 @@ Address specific functions used in this arrow_glacier version of specification. ". -Require typing. -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". +Axiom typing_imports : + AreImported globals "typing" [ "Union" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes32"; "Uint" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_left_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. -Require ethereum.arrow_glacier.fork_types. -Axiom ethereum_arrow_glacier_fork_types_Address : - IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "Address". +Axiom ethereum_arrow_glacier_fork_types_imports : + AreImported globals "ethereum.arrow_glacier.fork_types" [ "Address" ]. Definition to_address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -66,11 +56,16 @@ Definition to_address : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "Address" |), make_list [ - M.get_subscript (| M.call (| - M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), - make_list [], - make_dict [] - |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) + M.slice (| + M.call (| + M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), + UnOp.sub (| Constant.int 20 |), + Constant.None_, + Constant.None_ + |) ], make_dict [] |) @@ -114,7 +109,12 @@ Definition compute_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "computed_address" |), + UnOp.sub (| Constant.int 20 |), + Constant.None_, + Constant.None_ + |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -182,7 +182,12 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "computed_address" |), + UnOp.sub (| Constant.int 20 |), + Constant.None_, + Constant.None_ + |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/arrow_glacier/utils/hexadecimal.v b/CoqOfPython/ethereum/arrow_glacier/utils/hexadecimal.v index e8806bd..d87dde9 100644 --- a/CoqOfPython/ethereum/arrow_glacier/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/arrow_glacier/utils/hexadecimal.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.arrow_glacier.utils.hexadecimal". Definition expr_1 : Value.t := Constant.str " @@ -18,17 +18,11 @@ Hexadecimal utility functions used in this specification, specific to Arrow Glacier types. ". -Require ethereum.utils.hexadecimal. -Axiom ethereum_utils_hexadecimal_remove_hex_prefix : - IsGlobalAlias globals ethereum.utils.hexadecimal.globals "remove_hex_prefix". - -Require ethereum.arrow_glacier.fork_types. -Axiom ethereum_arrow_glacier_fork_types_Address : - IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "Address". -Axiom ethereum_arrow_glacier_fork_types_Bloom : - IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "Bloom". -Axiom ethereum_arrow_glacier_fork_types_Root : - IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "Root". +Axiom ethereum_utils_hexadecimal_imports : + AreImported globals "ethereum.utils.hexadecimal" [ "remove_hex_prefix" ]. + +Axiom ethereum_arrow_glacier_fork_types_imports : + AreImported globals "ethereum.arrow_glacier.fork_types" [ "Address"; "Bloom"; "Root" ]. Definition hex_to_root : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/arrow_glacier/utils/message.v b/CoqOfPython/ethereum/arrow_glacier/utils/message.v index 82dc5af..2b5423f 100644 --- a/CoqOfPython/ethereum/arrow_glacier/utils/message.v +++ b/CoqOfPython/ethereum/arrow_glacier/utils/message.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.arrow_glacier.utils.message". Definition expr_1 : Value.t := Constant.str " @@ -18,49 +18,26 @@ Message specific functions used in this arrow_glacier version of specification. ". -Require typing. -Axiom typing_FrozenSet : - IsGlobalAlias globals typing.globals "FrozenSet". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". +Axiom typing_imports : + AreImported globals "typing" [ "FrozenSet"; "Optional"; "Tuple"; "Union" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Bytes32"; "Uint" ]. -Require ethereum.arrow_glacier.fork_types. -Axiom ethereum_arrow_glacier_fork_types_Address : - IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "Address". +Axiom ethereum_arrow_glacier_fork_types_imports : + AreImported globals "ethereum.arrow_glacier.fork_types" [ "Address" ]. -Require ethereum.arrow_glacier.state. -Axiom ethereum_arrow_glacier_state_get_account : - IsGlobalAlias globals ethereum.arrow_glacier.state.globals "get_account". +Axiom ethereum_arrow_glacier_state_imports : + AreImported globals "ethereum.arrow_glacier.state" [ "get_account" ]. -Require ethereum.arrow_glacier.vm.__init__. -Axiom ethereum_arrow_glacier_vm___init___Environment : - IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Environment". -Axiom ethereum_arrow_glacier_vm___init___Message : - IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Message". +Axiom ethereum_arrow_glacier_vm_imports : + AreImported globals "ethereum.arrow_glacier.vm" [ "Environment"; "Message" ]. -Require ethereum.arrow_glacier.vm.precompiled_contracts.mapping. -Axiom ethereum_arrow_glacier_vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : - IsGlobalAlias globals ethereum.arrow_glacier.vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". +Axiom ethereum_arrow_glacier_vm_precompiled_contracts_mapping_imports : + AreImported globals "ethereum.arrow_glacier.vm.precompiled_contracts.mapping" [ "PRE_COMPILED_CONTRACTS" ]. -Require ethereum.arrow_glacier.utils.address. -Axiom ethereum_arrow_glacier_utils_address_compute_contract_address : - IsGlobalAlias globals ethereum.arrow_glacier.utils.address.globals "compute_contract_address". +Axiom ethereum_arrow_glacier_utils_address_imports : + AreImported globals "ethereum.arrow_glacier.utils.address" [ "compute_contract_address" ]. Definition prepare_message : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -198,7 +175,7 @@ Definition prepare_message : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "Target must be address or empty bytes" diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/__init__.v b/CoqOfPython/ethereum/arrow_glacier/vm/__init__.v index e0347cb..c0cf9bf 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/__init__.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.arrow_glacier.vm.__init__". Definition expr_1 : Value.t := Constant.str " @@ -18,57 +18,29 @@ The abstract computer which runs the code stored in an `.fork_types.Account`. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple"; "Union" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U64 : - IsGlobalAlias globals ethereum.base_types.globals "U64". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U64"; "U256"; "Bytes"; "Bytes0"; "Bytes32"; "Uint" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. -Require ethereum.arrow_glacier.blocks. -Axiom ethereum_arrow_glacier_blocks_Log : - IsGlobalAlias globals ethereum.arrow_glacier.blocks.globals "Log". +Axiom ethereum_arrow_glacier_blocks_imports : + AreImported globals "ethereum.arrow_glacier.blocks" [ "Log" ]. -Require ethereum.arrow_glacier.fork_types. -Axiom ethereum_arrow_glacier_fork_types_Address : - IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "Address". +Axiom ethereum_arrow_glacier_fork_types_imports : + AreImported globals "ethereum.arrow_glacier.fork_types" [ "Address" ]. -Require ethereum.arrow_glacier.state. -Axiom ethereum_arrow_glacier_state_State : - IsGlobalAlias globals ethereum.arrow_glacier.state.globals "State". -Axiom ethereum_arrow_glacier_state_account_exists_and_is_empty : - IsGlobalAlias globals ethereum.arrow_glacier.state.globals "account_exists_and_is_empty". +Axiom ethereum_arrow_glacier_state_imports : + AreImported globals "ethereum.arrow_glacier.state" [ "State"; "account_exists_and_is_empty" ]. -Require ethereum.arrow_glacier.vm.precompiled_contracts.__init__. -Axiom ethereum_arrow_glacier_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : - IsGlobalAlias globals ethereum.arrow_glacier.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". +Axiom ethereum_arrow_glacier_vm_precompiled_contracts_imports : + AreImported globals "ethereum.arrow_glacier.vm.precompiled_contracts" [ "RIPEMD160_ADDRESS" ]. Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] @@ -203,7 +175,7 @@ Definition incorporate_child_on_error : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "RIPEMD160_ADDRESS" |), M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) |), diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/exceptions.v b/CoqOfPython/ethereum/arrow_glacier/vm/exceptions.v index 1f4363d..4f9d6c0 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/exceptions.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/exceptions.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.arrow_glacier.vm.exceptions". Definition expr_1 : Value.t := Constant.str " @@ -17,9 +17,8 @@ Introduction Exceptions which cause the EVM to halt exceptionally. ". -Require ethereum.exceptions. -Axiom ethereum_exceptions_EthereumException : - IsGlobalAlias globals ethereum.exceptions.globals "EthereumException". +Axiom ethereum_exceptions_imports : + AreImported globals "ethereum.exceptions" [ "EthereumException" ]. Definition ExceptionalHalt : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/gas.v b/CoqOfPython/ethereum/arrow_glacier/vm/gas.v index 0d66586..2dbc7ef 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/gas.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/gas.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.arrow_glacier.vm.gas". Definition expr_1 : Value.t := Constant.str " @@ -17,39 +17,26 @@ Introduction EVM gas constants and calculators. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Tuple" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. -Require ethereum.trace. -Axiom ethereum_trace_GasAndRefund : - IsGlobalAlias globals ethereum.trace.globals "GasAndRefund". -Axiom ethereum_trace_evm_trace : - IsGlobalAlias globals ethereum.trace.globals "evm_trace". +Axiom ethereum_trace_imports : + AreImported globals "ethereum.trace" [ "GasAndRefund"; "evm_trace" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.arrow_glacier.vm.__init__. -Axiom ethereum_arrow_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Evm". +Axiom ethereum_arrow_glacier_vm_imports : + AreImported globals "ethereum.arrow_glacier.vm" [ "Evm" ]. -Require ethereum.arrow_glacier.vm.exceptions. -Axiom ethereum_arrow_glacier_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.arrow_glacier.vm.exceptions.globals "OutOfGasError". +Axiom ethereum_arrow_glacier_vm_exceptions_imports : + AreImported globals "ethereum.arrow_glacier.vm.exceptions" [ "OutOfGasError" ]. Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -508,7 +495,7 @@ Definition charge_gas : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -625,105 +612,114 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := ], make_dict [] |) in - For make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ] in M.get_name (| globals, "extensions" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "size" |), - Constant.int 0 - |), - (* then *) + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ], + M.get_name (| globals, "extensions" |), ltac:(M.monadic ( - let _ := M.continue (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let before_size := - M.call (| - M.get_name (| globals, "ceil32" |), - make_list [ - M.get_name (| globals, "current_size" |) - ], - make_dict [] - |) in - let after_size := - M.call (| - M.get_name (| globals, "ceil32" |), - make_list [ - BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "size" |), + Constant.int 0 |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.lt_e (| - M.get_name (| globals, "after_size" |), - M.get_name (| globals, "before_size" |) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.continue (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let size_to_extend := BinOp.add - BinOp.sub (| + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let before_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "current_size" |) + ], + make_dict [] + |) in + let after_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let size_to_extend := BinOp.add + BinOp.sub (| M.get_name (| globals, "after_size" |), M.get_name (| globals, "before_size" |) |) - BinOp.sub (| + BinOp.sub (| M.get_name (| globals, "after_size" |), M.get_name (| globals, "before_size" |) |) in - let already_paid := - M.call (| - M.get_name (| globals, "calculate_memory_gas_cost" |), - make_list [ - M.get_name (| globals, "before_size" |) - ], - make_dict [] - |) in - let total_cost := - M.call (| - M.get_name (| globals, "calculate_memory_gas_cost" |), - make_list [ - M.get_name (| globals, "after_size" |) - ], - make_dict [] - |) in - let to_be_paid := BinOp.add - BinOp.sub (| + let already_paid := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "before_size" |) + ], + make_dict [] + |) in + let total_cost := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "after_size" |) + ], + make_dict [] + |) in + let to_be_paid := BinOp.add + BinOp.sub (| M.get_name (| globals, "total_cost" |), M.get_name (| globals, "already_paid" |) |) - BinOp.sub (| + BinOp.sub (| M.get_name (| globals, "total_cost" |), M.get_name (| globals, "already_paid" |) |) in - let current_size := - M.get_name (| globals, "after_size" |) in - EndFor. + let current_size := + M.get_name (| globals, "after_size" |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ExtendMemory" |), diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/__init__.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/__init__.v index 8c5c5d8..40358e1 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/__init__.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.arrow_glacier.vm.instructions.__init__". Definition expr_1 : Value.t := Constant.str " @@ -20,59 +20,44 @@ implementations. (* At top_level_stmt: unsupported node type: Import *) -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict" ]. -Require ethereum.arrow_glacier.vm.instructions.__init__. -Axiom ethereum_arrow_glacier_vm_instructions___init___arithmetic : - IsGlobalAlias globals ethereum.arrow_glacier.vm.instructions.__init__.globals "arithmetic". +Axiom ethereum_arrow_glacier_vm_instructions_imports : + AreImported globals "ethereum.arrow_glacier.vm.instructions" [ "arithmetic" ]. -Require ethereum.arrow_glacier.vm.instructions.__init__. -Axiom ethereum_arrow_glacier_vm_instructions___init___bitwise : - IsGlobalAlias globals ethereum.arrow_glacier.vm.instructions.__init__.globals "bitwise". +Axiom ethereum_arrow_glacier_vm_instructions_imports : + AreImported globals "ethereum.arrow_glacier.vm.instructions" [ "bitwise" ]. -Require ethereum.arrow_glacier.vm.instructions.__init__. -Axiom ethereum_arrow_glacier_vm_instructions___init___block : - IsGlobalAlias globals ethereum.arrow_glacier.vm.instructions.__init__.globals "block". +Axiom ethereum_arrow_glacier_vm_instructions_imports : + AreImported globals "ethereum.arrow_glacier.vm.instructions" [ "block" ]. -Require ethereum.arrow_glacier.vm.instructions.__init__. -Axiom ethereum_arrow_glacier_vm_instructions___init___comparison : - IsGlobalAlias globals ethereum.arrow_glacier.vm.instructions.__init__.globals "comparison". +Axiom ethereum_arrow_glacier_vm_instructions_imports : + AreImported globals "ethereum.arrow_glacier.vm.instructions" [ "comparison" ]. -Require ethereum.arrow_glacier.vm.instructions.__init__. -Axiom ethereum_arrow_glacier_vm_instructions___init___control_flow : - IsGlobalAlias globals ethereum.arrow_glacier.vm.instructions.__init__.globals "control_flow". +Axiom ethereum_arrow_glacier_vm_instructions_imports : + AreImported globals "ethereum.arrow_glacier.vm.instructions" [ "control_flow" ]. -Require ethereum.arrow_glacier.vm.instructions.__init__. -Axiom ethereum_arrow_glacier_vm_instructions___init___environment : - IsGlobalAlias globals ethereum.arrow_glacier.vm.instructions.__init__.globals "environment". +Axiom ethereum_arrow_glacier_vm_instructions_imports : + AreImported globals "ethereum.arrow_glacier.vm.instructions" [ "environment" ]. -Require ethereum.arrow_glacier.vm.instructions.__init__. -Axiom ethereum_arrow_glacier_vm_instructions___init___keccak : - IsGlobalAlias globals ethereum.arrow_glacier.vm.instructions.__init__.globals "keccak". +Axiom ethereum_arrow_glacier_vm_instructions_imports : + AreImported globals "ethereum.arrow_glacier.vm.instructions" [ "keccak" ]. -Require ethereum.arrow_glacier.vm.instructions.__init__. -Axiom ethereum_arrow_glacier_vm_instructions___init___log : - IsGlobalAlias globals ethereum.arrow_glacier.vm.instructions.__init__.globals "log". +Axiom ethereum_arrow_glacier_vm_instructions_imports : + AreImported globals "ethereum.arrow_glacier.vm.instructions" [ "log" ]. -Require ethereum.arrow_glacier.vm.instructions.__init__. -Axiom ethereum_arrow_glacier_vm_instructions___init___memory : - IsGlobalAlias globals ethereum.arrow_glacier.vm.instructions.__init__.globals "memory". +Axiom ethereum_arrow_glacier_vm_instructions_imports : + AreImported globals "ethereum.arrow_glacier.vm.instructions" [ "memory" ]. -Require ethereum.arrow_glacier.vm.instructions.__init__. -Axiom ethereum_arrow_glacier_vm_instructions___init___stack : - IsGlobalAlias globals ethereum.arrow_glacier.vm.instructions.__init__.globals "stack". +Axiom ethereum_arrow_glacier_vm_instructions_imports : + AreImported globals "ethereum.arrow_glacier.vm.instructions" [ "stack" ]. -Require ethereum.arrow_glacier.vm.instructions.__init__. -Axiom ethereum_arrow_glacier_vm_instructions___init___storage : - IsGlobalAlias globals ethereum.arrow_glacier.vm.instructions.__init__.globals "storage". +Axiom ethereum_arrow_glacier_vm_instructions_imports : + AreImported globals "ethereum.arrow_glacier.vm.instructions" [ "storage" ]. -Require ethereum.arrow_glacier.vm.instructions.__init__. -Axiom ethereum_arrow_glacier_vm_instructions___init___system : - IsGlobalAlias globals ethereum.arrow_glacier.vm.instructions.__init__.globals "system". +Axiom ethereum_arrow_glacier_vm_instructions_imports : + AreImported globals "ethereum.arrow_glacier.vm.instructions" [ "system" ]. Definition Ops : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/arithmetic.v index 92193d8..6a7fa74 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/arithmetic.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.arrow_glacier.vm.instructions.arithmetic". Definition expr_1 : Value.t := Constant.str " @@ -17,43 +17,20 @@ Introduction Implementations of the EVM Arithmetic instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U255_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U255_CEIL_VALUE". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_U256_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U255_CEIL_VALUE"; "U256"; "U256_CEIL_VALUE"; "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_get_sign : - IsGlobalAlias globals ethereum.utils.numeric.globals "get_sign". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "get_sign" ]. -Require ethereum.arrow_glacier.vm.__init__. -Axiom ethereum_arrow_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Evm". +Axiom ethereum_arrow_glacier_vm_imports : + AreImported globals "ethereum.arrow_glacier.vm" [ "Evm" ]. -Require ethereum.arrow_glacier.vm.gas. -Axiom ethereum_arrow_glacier_vm_gas_GAS_EXPONENTIATION : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_EXPONENTIATION". -Axiom ethereum_arrow_glacier_vm_gas_GAS_EXPONENTIATION_PER_BYTE : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_EXPONENTIATION_PER_BYTE". -Axiom ethereum_arrow_glacier_vm_gas_GAS_LOW : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_LOW". -Axiom ethereum_arrow_glacier_vm_gas_GAS_MID : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_MID". -Axiom ethereum_arrow_glacier_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_arrow_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "charge_gas". +Axiom ethereum_arrow_glacier_vm_gas_imports : + AreImported globals "ethereum.arrow_glacier.vm.gas" [ "GAS_EXPONENTIATION"; "GAS_EXPONENTIATION_PER_BYTE"; "GAS_LOW"; "GAS_MID"; "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.arrow_glacier.vm.stack. -Axiom ethereum_arrow_glacier_vm_stack_pop : - IsGlobalAlias globals ethereum.arrow_glacier.vm.stack.globals "pop". -Axiom ethereum_arrow_glacier_vm_stack_push : - IsGlobalAlias globals ethereum.arrow_glacier.vm.stack.globals "push". +Axiom ethereum_arrow_glacier_vm_stack_imports : + AreImported globals "ethereum.arrow_glacier.vm.stack" [ "pop"; "push" ]. Definition add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -1030,19 +1007,27 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let value_bytes := - M.get_subscript (| M.get_name (| globals, "value_bytes" |), M.slice (| BinOp.sub (| - Constant.int 31, - M.call (| - M.get_name (| globals, "int" |), - make_list [ - M.get_name (| globals, "byte_num" |) - ], - make_dict [] - |) - |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "value_bytes" |), + BinOp.sub (| + Constant.int 31, + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "byte_num" |) + ], + make_dict [] + |) + |), + Constant.None_, + Constant.None_ + |) in let sign_bit := BinOp.r_shift (| - M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), + M.get_subscript (| + M.get_name (| globals, "value_bytes" |), + Constant.int 0 + |), Constant.int 7 |) in let _ := diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/bitwise.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/bitwise.v index 40bbc07..74b4347 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/bitwise.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.arrow_glacier.vm.instructions.bitwise". Definition expr_1 : Value.t := Constant.str " @@ -17,27 +17,17 @@ Introduction Implementations of the EVM bitwise instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_U256_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "U256_CEIL_VALUE" ]. -Require ethereum.arrow_glacier.vm.__init__. -Axiom ethereum_arrow_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Evm". +Axiom ethereum_arrow_glacier_vm_imports : + AreImported globals "ethereum.arrow_glacier.vm" [ "Evm" ]. -Require ethereum.arrow_glacier.vm.gas. -Axiom ethereum_arrow_glacier_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_arrow_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "charge_gas". +Axiom ethereum_arrow_glacier_vm_gas_imports : + AreImported globals "ethereum.arrow_glacier.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.arrow_glacier.vm.stack. -Axiom ethereum_arrow_glacier_vm_stack_pop : - IsGlobalAlias globals ethereum.arrow_glacier.vm.stack.globals "pop". -Axiom ethereum_arrow_glacier_vm_stack_push : - IsGlobalAlias globals ethereum.arrow_glacier.vm.stack.globals "push". +Axiom ethereum_arrow_glacier_vm_stack_imports : + AreImported globals "ethereum.arrow_glacier.vm.stack" [ "pop"; "push" ]. Definition bitwise_and : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/block.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/block.v index 7919a95..f8e1a78 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/block.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/block.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.arrow_glacier.vm.instructions.block". Definition expr_1 : Value.t := Constant.str " @@ -17,27 +17,17 @@ Introduction Implementations of the EVM block instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.arrow_glacier.vm.__init__. -Axiom ethereum_arrow_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Evm". +Axiom ethereum_arrow_glacier_vm_imports : + AreImported globals "ethereum.arrow_glacier.vm" [ "Evm" ]. -Require ethereum.arrow_glacier.vm.gas. -Axiom ethereum_arrow_glacier_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_BASE". -Axiom ethereum_arrow_glacier_vm_gas_GAS_BLOCK_HASH : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_BLOCK_HASH". -Axiom ethereum_arrow_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "charge_gas". +Axiom ethereum_arrow_glacier_vm_gas_imports : + AreImported globals "ethereum.arrow_glacier.vm.gas" [ "GAS_BASE"; "GAS_BLOCK_HASH"; "charge_gas" ]. -Require ethereum.arrow_glacier.vm.stack. -Axiom ethereum_arrow_glacier_vm_stack_pop : - IsGlobalAlias globals ethereum.arrow_glacier.vm.stack.globals "pop". -Axiom ethereum_arrow_glacier_vm_stack_push : - IsGlobalAlias globals ethereum.arrow_glacier.vm.stack.globals "push". +Axiom ethereum_arrow_glacier_vm_stack_imports : + AreImported globals "ethereum.arrow_glacier.vm.stack" [ "pop"; "push" ]. Definition block_hash : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -94,10 +84,13 @@ Definition block_hash : Value.t -> Value.t -> M := (* else *) )), ltac:(M.monadic ( let hash := - M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), - M.get_name (| globals, "block_number" |) - |) |) |) in + M.get_subscript (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), + UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + M.get_name (| globals, "block_number" |) + |) |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/comparison.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/comparison.v index 3d4f0ed..889bbc1 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/comparison.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.arrow_glacier.vm.instructions.comparison". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementations of the EVM Comparison instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.arrow_glacier.vm.__init__. -Axiom ethereum_arrow_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Evm". +Axiom ethereum_arrow_glacier_vm_imports : + AreImported globals "ethereum.arrow_glacier.vm" [ "Evm" ]. -Require ethereum.arrow_glacier.vm.gas. -Axiom ethereum_arrow_glacier_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_arrow_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "charge_gas". +Axiom ethereum_arrow_glacier_vm_gas_imports : + AreImported globals "ethereum.arrow_glacier.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.arrow_glacier.vm.stack. -Axiom ethereum_arrow_glacier_vm_stack_pop : - IsGlobalAlias globals ethereum.arrow_glacier.vm.stack.globals "pop". -Axiom ethereum_arrow_glacier_vm_stack_push : - IsGlobalAlias globals ethereum.arrow_glacier.vm.stack.globals "push". +Axiom ethereum_arrow_glacier_vm_stack_imports : + AreImported globals "ethereum.arrow_glacier.vm.stack" [ "pop"; "push" ]. Definition less_than : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/control_flow.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/control_flow.v index e823801..836b022 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/control_flow.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.arrow_glacier.vm.instructions.control_flow". Definition expr_1 : Value.t := Constant.str " @@ -17,37 +17,20 @@ Introduction Implementations of the EVM control flow instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. -Require ethereum.arrow_glacier.vm.gas. -Axiom ethereum_arrow_glacier_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_BASE". -Axiom ethereum_arrow_glacier_vm_gas_GAS_HIGH : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_HIGH". -Axiom ethereum_arrow_glacier_vm_gas_GAS_JUMPDEST : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_JUMPDEST". -Axiom ethereum_arrow_glacier_vm_gas_GAS_MID : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_MID". -Axiom ethereum_arrow_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "charge_gas". +Axiom ethereum_arrow_glacier_vm_gas_imports : + AreImported globals "ethereum.arrow_glacier.vm.gas" [ "GAS_BASE"; "GAS_HIGH"; "GAS_JUMPDEST"; "GAS_MID"; "charge_gas" ]. -Require ethereum.arrow_glacier.vm.__init__. -Axiom ethereum_arrow_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Evm". +Axiom ethereum_arrow_glacier_vm_imports : + AreImported globals "ethereum.arrow_glacier.vm" [ "Evm" ]. -Require ethereum.arrow_glacier.vm.exceptions. -Axiom ethereum_arrow_glacier_vm_exceptions_InvalidJumpDestError : - IsGlobalAlias globals ethereum.arrow_glacier.vm.exceptions.globals "InvalidJumpDestError". +Axiom ethereum_arrow_glacier_vm_exceptions_imports : + AreImported globals "ethereum.arrow_glacier.vm.exceptions" [ "InvalidJumpDestError" ]. -Require ethereum.arrow_glacier.vm.stack. -Axiom ethereum_arrow_glacier_vm_stack_pop : - IsGlobalAlias globals ethereum.arrow_glacier.vm.stack.globals "pop". -Axiom ethereum_arrow_glacier_vm_stack_push : - IsGlobalAlias globals ethereum.arrow_glacier.vm.stack.globals "push". +Axiom ethereum_arrow_glacier_vm_stack_imports : + AreImported globals "ethereum.arrow_glacier.vm.stack" [ "pop"; "push" ]. Definition stop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -117,7 +100,7 @@ Definition jump : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "InvalidJumpDestError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -205,7 +188,7 @@ Definition jumpi : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "InvalidJumpDestError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/environment.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/environment.v index f09eb2f..a537125 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/environment.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.arrow_glacier.vm.instructions.environment". Definition expr_1 : Value.t := Constant.str " @@ -17,75 +17,41 @@ Introduction Implementations of the EVM environment related instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". - -Require ethereum.arrow_glacier.fork_types. -Axiom ethereum_arrow_glacier_fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "EMPTY_ACCOUNT". - -Require ethereum.arrow_glacier.state. -Axiom ethereum_arrow_glacier_state_get_account : - IsGlobalAlias globals ethereum.arrow_glacier.state.globals "get_account". - -Require ethereum.arrow_glacier.utils.address. -Axiom ethereum_arrow_glacier_utils_address_to_address : - IsGlobalAlias globals ethereum.arrow_glacier.utils.address.globals "to_address". - -Require ethereum.arrow_glacier.vm.memory. -Axiom ethereum_arrow_glacier_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.arrow_glacier.vm.memory.globals "buffer_read". -Axiom ethereum_arrow_glacier_vm_memory_memory_write : - IsGlobalAlias globals ethereum.arrow_glacier.vm.memory.globals "memory_write". - -Require ethereum.arrow_glacier.vm.__init__. -Axiom ethereum_arrow_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Evm". - -Require ethereum.arrow_glacier.vm.exceptions. -Axiom ethereum_arrow_glacier_vm_exceptions_OutOfBoundsRead : - IsGlobalAlias globals ethereum.arrow_glacier.vm.exceptions.globals "OutOfBoundsRead". - -Require ethereum.arrow_glacier.vm.gas. -Axiom ethereum_arrow_glacier_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_BASE". -Axiom ethereum_arrow_glacier_vm_gas_GAS_COLD_ACCOUNT_ACCESS : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_COLD_ACCOUNT_ACCESS". -Axiom ethereum_arrow_glacier_vm_gas_GAS_COPY : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_COPY". -Axiom ethereum_arrow_glacier_vm_gas_GAS_FAST_STEP : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_FAST_STEP". -Axiom ethereum_arrow_glacier_vm_gas_GAS_RETURN_DATA_COPY : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_RETURN_DATA_COPY". -Axiom ethereum_arrow_glacier_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_arrow_glacier_vm_gas_GAS_WARM_ACCESS : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_WARM_ACCESS". -Axiom ethereum_arrow_glacier_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_arrow_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "charge_gas". - -Require ethereum.arrow_glacier.vm.stack. -Axiom ethereum_arrow_glacier_vm_stack_pop : - IsGlobalAlias globals ethereum.arrow_glacier.vm.stack.globals "pop". -Axiom ethereum_arrow_glacier_vm_stack_push : - IsGlobalAlias globals ethereum.arrow_glacier.vm.stack.globals "push". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. + +Axiom ethereum_arrow_glacier_fork_types_imports : + AreImported globals "ethereum.arrow_glacier.fork_types" [ "EMPTY_ACCOUNT" ]. + +Axiom ethereum_arrow_glacier_state_imports : + AreImported globals "ethereum.arrow_glacier.state" [ "get_account" ]. + +Axiom ethereum_arrow_glacier_utils_address_imports : + AreImported globals "ethereum.arrow_glacier.utils.address" [ "to_address" ]. + +Axiom ethereum_arrow_glacier_vm_memory_imports : + AreImported globals "ethereum.arrow_glacier.vm.memory" [ "buffer_read"; "memory_write" ]. + +Axiom ethereum_arrow_glacier_vm_imports : + AreImported globals "ethereum.arrow_glacier.vm" [ "Evm" ]. + +Axiom ethereum_arrow_glacier_vm_exceptions_imports : + AreImported globals "ethereum.arrow_glacier.vm.exceptions" [ "OutOfBoundsRead" ]. + +Axiom ethereum_arrow_glacier_vm_gas_imports : + AreImported globals "ethereum.arrow_glacier.vm.gas" [ "GAS_BASE"; "GAS_COLD_ACCOUNT_ACCESS"; "GAS_COPY"; "GAS_FAST_STEP"; "GAS_RETURN_DATA_COPY"; "GAS_VERY_LOW"; "GAS_WARM_ACCESS"; "calculate_gas_extend_memory"; "charge_gas" ]. + +Axiom ethereum_arrow_glacier_vm_stack_imports : + AreImported globals "ethereum.arrow_glacier.vm.stack" [ "pop"; "push" ]. Definition address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -158,7 +124,7 @@ Definition balance : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -810,7 +776,7 @@ Definition extcodesize : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -966,7 +932,7 @@ Definition extcodecopy : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -1225,10 +1191,15 @@ Definition returndatacopy : Value.t -> Value.t -> M := |) |) in let value := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.slice (| M.get_name (| globals, "return_data_start_position" |), BinOp.add (| + M.slice (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |), - M.get_name (| globals, "size" |) - |) |) |) in + BinOp.add (| + M.get_name (| globals, "return_data_start_position" |), + M.get_name (| globals, "size" |) + |), + Constant.None_ + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -1272,7 +1243,7 @@ Definition extcodehash : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/keccak.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/keccak.v index 7213fb1..fbda431 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/keccak.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.arrow_glacier.vm.instructions.keccak". Definition expr_1 : Value.t := Constant.str " @@ -17,43 +17,26 @@ Introduction Implementations of the EVM keccak instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". - -Require ethereum.arrow_glacier.vm.__init__. -Axiom ethereum_arrow_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Evm". - -Require ethereum.arrow_glacier.vm.gas. -Axiom ethereum_arrow_glacier_vm_gas_GAS_KECCAK256 : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_KECCAK256". -Axiom ethereum_arrow_glacier_vm_gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_KECCAK256_WORD". -Axiom ethereum_arrow_glacier_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_arrow_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "charge_gas". - -Require ethereum.arrow_glacier.vm.memory. -Axiom ethereum_arrow_glacier_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.arrow_glacier.vm.memory.globals "memory_read_bytes". - -Require ethereum.arrow_glacier.vm.stack. -Axiom ethereum_arrow_glacier_vm_stack_pop : - IsGlobalAlias globals ethereum.arrow_glacier.vm.stack.globals "pop". -Axiom ethereum_arrow_glacier_vm_stack_push : - IsGlobalAlias globals ethereum.arrow_glacier.vm.stack.globals "push". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. + +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. + +Axiom ethereum_arrow_glacier_vm_imports : + AreImported globals "ethereum.arrow_glacier.vm" [ "Evm" ]. + +Axiom ethereum_arrow_glacier_vm_gas_imports : + AreImported globals "ethereum.arrow_glacier.vm.gas" [ "GAS_KECCAK256"; "GAS_KECCAK256_WORD"; "calculate_gas_extend_memory"; "charge_gas" ]. + +Axiom ethereum_arrow_glacier_vm_memory_imports : + AreImported globals "ethereum.arrow_glacier.vm.memory" [ "memory_read_bytes" ]. + +Axiom ethereum_arrow_glacier_vm_stack_imports : + AreImported globals "ethereum.arrow_glacier.vm.stack" [ "pop"; "push" ]. Definition keccak : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/log.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/log.v index c32fdb1..d687001 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/log.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/log.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.arrow_glacier.vm.instructions.log". Definition expr_1 : Value.t := Constant.str " @@ -17,49 +17,32 @@ Introduction Implementations of the EVM logging instructions. ". -Require functools. -Axiom functools_partial : - IsGlobalAlias globals functools.globals "partial". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.arrow_glacier.blocks. -Axiom ethereum_arrow_glacier_blocks_Log : - IsGlobalAlias globals ethereum.arrow_glacier.blocks.globals "Log". - -Require ethereum.arrow_glacier.vm.__init__. -Axiom ethereum_arrow_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Evm". - -Require ethereum.arrow_glacier.vm.exceptions. -Axiom ethereum_arrow_glacier_vm_exceptions_WriteInStaticContext : - IsGlobalAlias globals ethereum.arrow_glacier.vm.exceptions.globals "WriteInStaticContext". - -Require ethereum.arrow_glacier.vm.gas. -Axiom ethereum_arrow_glacier_vm_gas_GAS_LOG : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_LOG". -Axiom ethereum_arrow_glacier_vm_gas_GAS_LOG_DATA : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_LOG_DATA". -Axiom ethereum_arrow_glacier_vm_gas_GAS_LOG_TOPIC : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_LOG_TOPIC". -Axiom ethereum_arrow_glacier_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_arrow_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "charge_gas". - -Require ethereum.arrow_glacier.vm.memory. -Axiom ethereum_arrow_glacier_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.arrow_glacier.vm.memory.globals "memory_read_bytes". - -Require ethereum.arrow_glacier.vm.stack. -Axiom ethereum_arrow_glacier_vm_stack_pop : - IsGlobalAlias globals ethereum.arrow_glacier.vm.stack.globals "pop". +Axiom functools_imports : + AreImported globals "functools" [ "partial" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_arrow_glacier_blocks_imports : + AreImported globals "ethereum.arrow_glacier.blocks" [ "Log" ]. + +Axiom ethereum_arrow_glacier_vm_imports : + AreImported globals "ethereum.arrow_glacier.vm" [ "Evm" ]. + +Axiom ethereum_arrow_glacier_vm_exceptions_imports : + AreImported globals "ethereum.arrow_glacier.vm.exceptions" [ "WriteInStaticContext" ]. + +Axiom ethereum_arrow_glacier_vm_gas_imports : + AreImported globals "ethereum.arrow_glacier.vm.gas" [ "GAS_LOG"; "GAS_LOG_DATA"; "GAS_LOG_TOPIC"; "calculate_gas_extend_memory"; "charge_gas" ]. + +Axiom ethereum_arrow_glacier_vm_memory_imports : + AreImported globals "ethereum.arrow_glacier.vm.memory" [ "memory_read_bytes" ]. + +Axiom ethereum_arrow_glacier_vm_stack_imports : + AreImported globals "ethereum.arrow_glacier.vm.stack" [ "pop" ]. Definition log_n : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -96,33 +79,42 @@ Definition log_n : Value.t -> Value.t -> M := |) in let topics := make_list [] in - For M.get_name (| globals, "_" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - M.get_name (| globals, "num_topics" |) - ], - make_dict [] - |) do - let topic := + let _ := + M.for_ (| + M.get_name (| globals, "_" |), M.call (| - M.get_field (| M.call (| - M.get_name (| globals, "pop" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] - |), "to_be_bytes32" |), - make_list [], - make_dict [] - |) in - let _ := M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "num_topics" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let topic := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| M.get_field (| M.get_name (| globals, "topics" |), "append" |), make_list [ M.get_name (| globals, "topic" |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let extend_memory := M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/memory.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/memory.v index 1ffde04..05d47e6 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/memory.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.arrow_glacier.vm.instructions.memory". Definition expr_1 : Value.t := Constant.str " @@ -17,37 +17,20 @@ Introduction Implementations of the EVM Memory instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes" ]. -Require ethereum.arrow_glacier.vm.__init__. -Axiom ethereum_arrow_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Evm". +Axiom ethereum_arrow_glacier_vm_imports : + AreImported globals "ethereum.arrow_glacier.vm" [ "Evm" ]. -Require ethereum.arrow_glacier.vm.gas. -Axiom ethereum_arrow_glacier_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_BASE". -Axiom ethereum_arrow_glacier_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_arrow_glacier_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_arrow_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "charge_gas". +Axiom ethereum_arrow_glacier_vm_gas_imports : + AreImported globals "ethereum.arrow_glacier.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. -Require ethereum.arrow_glacier.vm.memory. -Axiom ethereum_arrow_glacier_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.arrow_glacier.vm.memory.globals "memory_read_bytes". -Axiom ethereum_arrow_glacier_vm_memory_memory_write : - IsGlobalAlias globals ethereum.arrow_glacier.vm.memory.globals "memory_write". +Axiom ethereum_arrow_glacier_vm_memory_imports : + AreImported globals "ethereum.arrow_glacier.vm.memory" [ "memory_read_bytes"; "memory_write" ]. -Require ethereum.arrow_glacier.vm.stack. -Axiom ethereum_arrow_glacier_vm_stack_pop : - IsGlobalAlias globals ethereum.arrow_glacier.vm.stack.globals "pop". -Axiom ethereum_arrow_glacier_vm_stack_push : - IsGlobalAlias globals ethereum.arrow_glacier.vm.stack.globals "push". +Axiom ethereum_arrow_glacier_vm_stack_imports : + AreImported globals "ethereum.arrow_glacier.vm.stack" [ "pop"; "push" ]. Definition mstore : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/stack.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/stack.v index 1e0f4d9..3115267 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/stack.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.arrow_glacier.vm.instructions.stack". Definition expr_1 : Value.t := Constant.str " @@ -17,39 +17,26 @@ Introduction Implementations of the EVM stack related instructions. ". -Require functools. -Axiom functools_partial : - IsGlobalAlias globals functools.globals "partial". +Axiom functools_imports : + AreImported globals "functools" [ "partial" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.arrow_glacier.vm.__init__. -Axiom ethereum_arrow_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Evm". -Axiom ethereum_arrow_glacier_vm___init___stack : - IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "stack". +Axiom ethereum_arrow_glacier_vm_imports : + AreImported globals "ethereum.arrow_glacier.vm" [ "Evm"; "stack" ]. -Require ethereum.arrow_glacier.vm.exceptions. -Axiom ethereum_arrow_glacier_vm_exceptions_StackUnderflowError : - IsGlobalAlias globals ethereum.arrow_glacier.vm.exceptions.globals "StackUnderflowError". +Axiom ethereum_arrow_glacier_vm_exceptions_imports : + AreImported globals "ethereum.arrow_glacier.vm.exceptions" [ "StackUnderflowError" ]. -Require ethereum.arrow_glacier.vm.gas. -Axiom ethereum_arrow_glacier_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_BASE". -Axiom ethereum_arrow_glacier_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_arrow_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "charge_gas". +Axiom ethereum_arrow_glacier_vm_gas_imports : + AreImported globals "ethereum.arrow_glacier.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.arrow_glacier.vm.memory. -Axiom ethereum_arrow_glacier_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.arrow_glacier.vm.memory.globals "buffer_read". +Axiom ethereum_arrow_glacier_vm_memory_imports : + AreImported globals "ethereum.arrow_glacier.vm.memory" [ "buffer_read" ]. Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -203,19 +190,22 @@ Definition dup_n : Value.t -> Value.t -> M := make_dict [] |) in let data_to_duplicate := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] + BinOp.sub (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), + Constant.int 1 |), - Constant.int 1 - |), - M.get_name (| globals, "item_number" |) - |) |) in + M.get_name (| globals, "item_number" |) + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "stack" |), "push" |), make_list [ @@ -278,14 +268,26 @@ Definition swap_n : Value.t -> Value.t -> M := make_dict [] |) in let _ := M.assign (| - make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| - UnOp.sub (| Constant.int 1 |), - M.get_name (| globals, "item_number" |) - |) |) ], - make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| - UnOp.sub (| Constant.int 1 |), - M.get_name (| globals, "item_number" |) - |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |) ] + make_tuple [ M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + UnOp.sub (| Constant.int 1 |) + |); M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) + |) ], + make_tuple [ M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) + |); M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + UnOp.sub (| Constant.int 1 |) + |) ] |) in let _ := M.assign_op (| BinOp.add, diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/storage.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/storage.v index d2ccb97..a8e32f7 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/storage.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.arrow_glacier.vm.instructions.storage". Definition expr_1 : Value.t := Constant.str " @@ -17,53 +17,26 @@ Introduction Implementations of the EVM storage related instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.arrow_glacier.state. -Axiom ethereum_arrow_glacier_state_get_storage : - IsGlobalAlias globals ethereum.arrow_glacier.state.globals "get_storage". -Axiom ethereum_arrow_glacier_state_get_storage_original : - IsGlobalAlias globals ethereum.arrow_glacier.state.globals "get_storage_original". -Axiom ethereum_arrow_glacier_state_set_storage : - IsGlobalAlias globals ethereum.arrow_glacier.state.globals "set_storage". +Axiom ethereum_arrow_glacier_state_imports : + AreImported globals "ethereum.arrow_glacier.state" [ "get_storage"; "get_storage_original"; "set_storage" ]. -Require ethereum.arrow_glacier.vm.__init__. -Axiom ethereum_arrow_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Evm". +Axiom ethereum_arrow_glacier_vm_imports : + AreImported globals "ethereum.arrow_glacier.vm" [ "Evm" ]. -Require ethereum.arrow_glacier.vm.exceptions. -Axiom ethereum_arrow_glacier_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.arrow_glacier.vm.exceptions.globals "OutOfGasError". -Axiom ethereum_arrow_glacier_vm_exceptions_WriteInStaticContext : - IsGlobalAlias globals ethereum.arrow_glacier.vm.exceptions.globals "WriteInStaticContext". +Axiom ethereum_arrow_glacier_vm_exceptions_imports : + AreImported globals "ethereum.arrow_glacier.vm.exceptions" [ "OutOfGasError"; "WriteInStaticContext" ]. -Require ethereum.arrow_glacier.vm.gas. -Axiom ethereum_arrow_glacier_vm_gas_GAS_CALL_STIPEND : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_CALL_STIPEND". -Axiom ethereum_arrow_glacier_vm_gas_GAS_COLD_SLOAD : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_COLD_SLOAD". -Axiom ethereum_arrow_glacier_vm_gas_GAS_STORAGE_CLEAR_REFUND : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_STORAGE_CLEAR_REFUND". -Axiom ethereum_arrow_glacier_vm_gas_GAS_STORAGE_SET : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_STORAGE_SET". -Axiom ethereum_arrow_glacier_vm_gas_GAS_STORAGE_UPDATE : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_STORAGE_UPDATE". -Axiom ethereum_arrow_glacier_vm_gas_GAS_WARM_ACCESS : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_WARM_ACCESS". -Axiom ethereum_arrow_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "charge_gas". +Axiom ethereum_arrow_glacier_vm_gas_imports : + AreImported globals "ethereum.arrow_glacier.vm.gas" [ "GAS_CALL_STIPEND"; "GAS_COLD_SLOAD"; "GAS_STORAGE_CLEAR_REFUND"; "GAS_STORAGE_SET"; "GAS_STORAGE_UPDATE"; "GAS_WARM_ACCESS"; "charge_gas" ]. -Require ethereum.arrow_glacier.vm.stack. -Axiom ethereum_arrow_glacier_vm_stack_pop : - IsGlobalAlias globals ethereum.arrow_glacier.vm.stack.globals "pop". -Axiom ethereum_arrow_glacier_vm_stack_push : - IsGlobalAlias globals ethereum.arrow_glacier.vm.stack.globals "push". +Axiom ethereum_arrow_glacier_vm_stack_imports : + AreImported globals "ethereum.arrow_glacier.vm.stack" [ "pop"; "push" ]. Definition sload : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -93,7 +66,7 @@ Definition sload : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) |), diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/system.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/system.v index bebc28b..a4cc36e 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/system.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/system.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.arrow_glacier.vm.instructions.system". Definition expr_1 : Value.t := Constant.str " @@ -17,103 +17,38 @@ Introduction Implementations of the EVM system related instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.arrow_glacier.fork_types. -Axiom ethereum_arrow_glacier_fork_types_Address : - IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "Address". +Axiom ethereum_arrow_glacier_fork_types_imports : + AreImported globals "ethereum.arrow_glacier.fork_types" [ "Address" ]. -Require ethereum.arrow_glacier.state. -Axiom ethereum_arrow_glacier_state_account_exists_and_is_empty : - IsGlobalAlias globals ethereum.arrow_glacier.state.globals "account_exists_and_is_empty". -Axiom ethereum_arrow_glacier_state_account_has_code_or_nonce : - IsGlobalAlias globals ethereum.arrow_glacier.state.globals "account_has_code_or_nonce". -Axiom ethereum_arrow_glacier_state_get_account : - IsGlobalAlias globals ethereum.arrow_glacier.state.globals "get_account". -Axiom ethereum_arrow_glacier_state_increment_nonce : - IsGlobalAlias globals ethereum.arrow_glacier.state.globals "increment_nonce". -Axiom ethereum_arrow_glacier_state_is_account_alive : - IsGlobalAlias globals ethereum.arrow_glacier.state.globals "is_account_alive". -Axiom ethereum_arrow_glacier_state_set_account_balance : - IsGlobalAlias globals ethereum.arrow_glacier.state.globals "set_account_balance". +Axiom ethereum_arrow_glacier_state_imports : + AreImported globals "ethereum.arrow_glacier.state" [ "account_exists_and_is_empty"; "account_has_code_or_nonce"; "get_account"; "increment_nonce"; "is_account_alive"; "set_account_balance" ]. -Require ethereum.arrow_glacier.utils.address. -Axiom ethereum_arrow_glacier_utils_address_compute_contract_address : - IsGlobalAlias globals ethereum.arrow_glacier.utils.address.globals "compute_contract_address". -Axiom ethereum_arrow_glacier_utils_address_compute_create2_contract_address : - IsGlobalAlias globals ethereum.arrow_glacier.utils.address.globals "compute_create2_contract_address". -Axiom ethereum_arrow_glacier_utils_address_to_address : - IsGlobalAlias globals ethereum.arrow_glacier.utils.address.globals "to_address". +Axiom ethereum_arrow_glacier_utils_address_imports : + AreImported globals "ethereum.arrow_glacier.utils.address" [ "compute_contract_address"; "compute_create2_contract_address"; "to_address" ]. -Require ethereum.arrow_glacier.vm.__init__. -Axiom ethereum_arrow_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Evm". -Axiom ethereum_arrow_glacier_vm___init___Message : - IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Message". -Axiom ethereum_arrow_glacier_vm___init___incorporate_child_on_error : - IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "incorporate_child_on_error". -Axiom ethereum_arrow_glacier_vm___init___incorporate_child_on_success : - IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "incorporate_child_on_success". +Axiom ethereum_arrow_glacier_vm_imports : + AreImported globals "ethereum.arrow_glacier.vm" [ "Evm"; "Message"; "incorporate_child_on_error"; "incorporate_child_on_success" ]. -Require ethereum.arrow_glacier.vm.exceptions. -Axiom ethereum_arrow_glacier_vm_exceptions_Revert : - IsGlobalAlias globals ethereum.arrow_glacier.vm.exceptions.globals "Revert". -Axiom ethereum_arrow_glacier_vm_exceptions_WriteInStaticContext : - IsGlobalAlias globals ethereum.arrow_glacier.vm.exceptions.globals "WriteInStaticContext". +Axiom ethereum_arrow_glacier_vm_exceptions_imports : + AreImported globals "ethereum.arrow_glacier.vm.exceptions" [ "Revert"; "WriteInStaticContext" ]. -Require ethereum.arrow_glacier.vm.gas. -Axiom ethereum_arrow_glacier_vm_gas_GAS_CALL_VALUE : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_CALL_VALUE". -Axiom ethereum_arrow_glacier_vm_gas_GAS_COLD_ACCOUNT_ACCESS : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_COLD_ACCOUNT_ACCESS". -Axiom ethereum_arrow_glacier_vm_gas_GAS_CREATE : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_CREATE". -Axiom ethereum_arrow_glacier_vm_gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_KECCAK256_WORD". -Axiom ethereum_arrow_glacier_vm_gas_GAS_NEW_ACCOUNT : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_NEW_ACCOUNT". -Axiom ethereum_arrow_glacier_vm_gas_GAS_SELF_DESTRUCT : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_SELF_DESTRUCT". -Axiom ethereum_arrow_glacier_vm_gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". -Axiom ethereum_arrow_glacier_vm_gas_GAS_WARM_ACCESS : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_WARM_ACCESS". -Axiom ethereum_arrow_glacier_vm_gas_GAS_ZERO : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_ZERO". -Axiom ethereum_arrow_glacier_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_arrow_glacier_vm_gas_calculate_message_call_gas : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "calculate_message_call_gas". -Axiom ethereum_arrow_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "charge_gas". -Axiom ethereum_arrow_glacier_vm_gas_max_message_call_gas : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "max_message_call_gas". +Axiom ethereum_arrow_glacier_vm_gas_imports : + AreImported globals "ethereum.arrow_glacier.vm.gas" [ "GAS_CALL_VALUE"; "GAS_COLD_ACCOUNT_ACCESS"; "GAS_CREATE"; "GAS_KECCAK256_WORD"; "GAS_NEW_ACCOUNT"; "GAS_SELF_DESTRUCT"; "GAS_SELF_DESTRUCT_NEW_ACCOUNT"; "GAS_WARM_ACCESS"; "GAS_ZERO"; "calculate_gas_extend_memory"; "calculate_message_call_gas"; "charge_gas"; "max_message_call_gas" ]. -Require ethereum.arrow_glacier.vm.memory. -Axiom ethereum_arrow_glacier_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.arrow_glacier.vm.memory.globals "memory_read_bytes". -Axiom ethereum_arrow_glacier_vm_memory_memory_write : - IsGlobalAlias globals ethereum.arrow_glacier.vm.memory.globals "memory_write". +Axiom ethereum_arrow_glacier_vm_memory_imports : + AreImported globals "ethereum.arrow_glacier.vm.memory" [ "memory_read_bytes"; "memory_write" ]. -Require ethereum.arrow_glacier.vm.stack. -Axiom ethereum_arrow_glacier_vm_stack_pop : - IsGlobalAlias globals ethereum.arrow_glacier.vm.stack.globals "pop". -Axiom ethereum_arrow_glacier_vm_stack_push : - IsGlobalAlias globals ethereum.arrow_glacier.vm.stack.globals "push". +Axiom ethereum_arrow_glacier_vm_stack_imports : + AreImported globals "ethereum.arrow_glacier.vm.stack" [ "pop"; "push" ]. Definition generic_create : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -866,7 +801,12 @@ Definition generic_call : Value.t -> Value.t -> M := make_list [ M.get_field (| M.get_name (| globals, "evm" |), "memory" |); M.get_name (| globals, "memory_output_start_position" |); - M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), M.slice (| Constant.None_, M.get_name (| globals, "actual_output_size" |) |) |) + M.slice (| + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), + Constant.None_, + M.get_name (| globals, "actual_output_size" |), + Constant.None_ + |) ], make_dict [] |) in @@ -966,7 +906,7 @@ Definition call : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "to" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -1272,7 +1212,7 @@ Definition callcode : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "code_address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -1700,7 +1640,7 @@ Definition delegatecall : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "code_address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -1876,7 +1816,7 @@ Definition staticcall : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "to" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -2046,6 +1986,6 @@ Definition revert : Value.t -> Value.t -> M := make_dict [] |) |) in - let _ := M.raise (| Some(M.get_name (| globals, "Revert" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "Revert" |)) |) in let _ := M.pass (| |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/interpreter.v b/CoqOfPython/ethereum/arrow_glacier/vm/interpreter.v index 4666c07..5b61da7 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/interpreter.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/interpreter.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.arrow_glacier.vm.interpreter". Definition expr_1 : Value.t := Constant.str " @@ -17,127 +17,50 @@ Introduction A straightforward interpreter that executes EVM code. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_Iterable : - IsGlobalAlias globals typing.globals "Iterable". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.trace. -Axiom ethereum_trace_EvmStop : - IsGlobalAlias globals ethereum.trace.globals "EvmStop". -Axiom ethereum_trace_OpEnd : - IsGlobalAlias globals ethereum.trace.globals "OpEnd". -Axiom ethereum_trace_OpException : - IsGlobalAlias globals ethereum.trace.globals "OpException". -Axiom ethereum_trace_OpStart : - IsGlobalAlias globals ethereum.trace.globals "OpStart". -Axiom ethereum_trace_PrecompileEnd : - IsGlobalAlias globals ethereum.trace.globals "PrecompileEnd". -Axiom ethereum_trace_PrecompileStart : - IsGlobalAlias globals ethereum.trace.globals "PrecompileStart". -Axiom ethereum_trace_TransactionEnd : - IsGlobalAlias globals ethereum.trace.globals "TransactionEnd". -Axiom ethereum_trace_evm_trace : - IsGlobalAlias globals ethereum.trace.globals "evm_trace". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.arrow_glacier.blocks. -Axiom ethereum_arrow_glacier_blocks_Log : - IsGlobalAlias globals ethereum.arrow_glacier.blocks.globals "Log". - -Require ethereum.arrow_glacier.fork_types. -Axiom ethereum_arrow_glacier_fork_types_Address : - IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "Address". - -Require ethereum.arrow_glacier.state. -Axiom ethereum_arrow_glacier_state_account_exists_and_is_empty : - IsGlobalAlias globals ethereum.arrow_glacier.state.globals "account_exists_and_is_empty". -Axiom ethereum_arrow_glacier_state_account_has_code_or_nonce : - IsGlobalAlias globals ethereum.arrow_glacier.state.globals "account_has_code_or_nonce". -Axiom ethereum_arrow_glacier_state_begin_transaction : - IsGlobalAlias globals ethereum.arrow_glacier.state.globals "begin_transaction". -Axiom ethereum_arrow_glacier_state_commit_transaction : - IsGlobalAlias globals ethereum.arrow_glacier.state.globals "commit_transaction". -Axiom ethereum_arrow_glacier_state_destroy_storage : - IsGlobalAlias globals ethereum.arrow_glacier.state.globals "destroy_storage". -Axiom ethereum_arrow_glacier_state_increment_nonce : - IsGlobalAlias globals ethereum.arrow_glacier.state.globals "increment_nonce". -Axiom ethereum_arrow_glacier_state_mark_account_created : - IsGlobalAlias globals ethereum.arrow_glacier.state.globals "mark_account_created". -Axiom ethereum_arrow_glacier_state_move_ether : - IsGlobalAlias globals ethereum.arrow_glacier.state.globals "move_ether". -Axiom ethereum_arrow_glacier_state_rollback_transaction : - IsGlobalAlias globals ethereum.arrow_glacier.state.globals "rollback_transaction". -Axiom ethereum_arrow_glacier_state_set_code : - IsGlobalAlias globals ethereum.arrow_glacier.state.globals "set_code". -Axiom ethereum_arrow_glacier_state_touch_account : - IsGlobalAlias globals ethereum.arrow_glacier.state.globals "touch_account". - -Require ethereum.arrow_glacier.vm.__init__. -Axiom ethereum_arrow_glacier_vm___init___Message : - IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Message". - -Require ethereum.arrow_glacier.vm.gas. -Axiom ethereum_arrow_glacier_vm_gas_GAS_CODE_DEPOSIT : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_CODE_DEPOSIT". -Axiom ethereum_arrow_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "charge_gas". - -Require ethereum.arrow_glacier.vm.precompiled_contracts.mapping. -Axiom ethereum_arrow_glacier_vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : - IsGlobalAlias globals ethereum.arrow_glacier.vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". - -Require ethereum.arrow_glacier.vm.__init__. -Axiom ethereum_arrow_glacier_vm___init___Environment : - IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Environment". -Axiom ethereum_arrow_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Evm". - -Require ethereum.arrow_glacier.vm.exceptions. -Axiom ethereum_arrow_glacier_vm_exceptions_AddressCollision : - IsGlobalAlias globals ethereum.arrow_glacier.vm.exceptions.globals "AddressCollision". -Axiom ethereum_arrow_glacier_vm_exceptions_ExceptionalHalt : - IsGlobalAlias globals ethereum.arrow_glacier.vm.exceptions.globals "ExceptionalHalt". -Axiom ethereum_arrow_glacier_vm_exceptions_InvalidContractPrefix : - IsGlobalAlias globals ethereum.arrow_glacier.vm.exceptions.globals "InvalidContractPrefix". -Axiom ethereum_arrow_glacier_vm_exceptions_InvalidOpcode : - IsGlobalAlias globals ethereum.arrow_glacier.vm.exceptions.globals "InvalidOpcode". -Axiom ethereum_arrow_glacier_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.arrow_glacier.vm.exceptions.globals "OutOfGasError". -Axiom ethereum_arrow_glacier_vm_exceptions_Revert : - IsGlobalAlias globals ethereum.arrow_glacier.vm.exceptions.globals "Revert". -Axiom ethereum_arrow_glacier_vm_exceptions_StackDepthLimitError : - IsGlobalAlias globals ethereum.arrow_glacier.vm.exceptions.globals "StackDepthLimitError". - -Require ethereum.arrow_glacier.vm.instructions.__init__. -Axiom ethereum_arrow_glacier_vm_instructions___init___Ops : - IsGlobalAlias globals ethereum.arrow_glacier.vm.instructions.__init__.globals "Ops". -Axiom ethereum_arrow_glacier_vm_instructions___init___op_implementation : - IsGlobalAlias globals ethereum.arrow_glacier.vm.instructions.__init__.globals "op_implementation". - -Require ethereum.arrow_glacier.vm.runtime. -Axiom ethereum_arrow_glacier_vm_runtime_get_valid_jump_destinations : - IsGlobalAlias globals ethereum.arrow_glacier.vm.runtime.globals "get_valid_jump_destinations". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Iterable"; "Optional"; "Set"; "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. + +Axiom ethereum_trace_imports : + AreImported globals "ethereum.trace" [ "EvmStop"; "OpEnd"; "OpException"; "OpStart"; "PrecompileEnd"; "PrecompileStart"; "TransactionEnd"; "evm_trace" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_arrow_glacier_blocks_imports : + AreImported globals "ethereum.arrow_glacier.blocks" [ "Log" ]. + +Axiom ethereum_arrow_glacier_fork_types_imports : + AreImported globals "ethereum.arrow_glacier.fork_types" [ "Address" ]. + +Axiom ethereum_arrow_glacier_state_imports : + AreImported globals "ethereum.arrow_glacier.state" [ "account_exists_and_is_empty"; "account_has_code_or_nonce"; "begin_transaction"; "commit_transaction"; "destroy_storage"; "increment_nonce"; "mark_account_created"; "move_ether"; "rollback_transaction"; "set_code"; "touch_account" ]. + +Axiom ethereum_arrow_glacier_vm_imports : + AreImported globals "ethereum.arrow_glacier.vm" [ "Message" ]. + +Axiom ethereum_arrow_glacier_vm_gas_imports : + AreImported globals "ethereum.arrow_glacier.vm.gas" [ "GAS_CODE_DEPOSIT"; "charge_gas" ]. + +Axiom ethereum_arrow_glacier_vm_precompiled_contracts_mapping_imports : + AreImported globals "ethereum.arrow_glacier.vm.precompiled_contracts.mapping" [ "PRE_COMPILED_CONTRACTS" ]. + +Axiom ethereum_arrow_glacier_vm_imports : + AreImported globals "ethereum.arrow_glacier.vm" [ "Environment"; "Evm" ]. + +Axiom ethereum_arrow_glacier_vm_exceptions_imports : + AreImported globals "ethereum.arrow_glacier.vm.exceptions" [ "AddressCollision"; "ExceptionalHalt"; "InvalidContractPrefix"; "InvalidOpcode"; "OutOfGasError"; "Revert"; "StackDepthLimitError" ]. + +Axiom ethereum_arrow_glacier_vm_instructions_imports : + AreImported globals "ethereum.arrow_glacier.vm.instructions" [ "Ops"; "op_implementation" ]. + +Axiom ethereum_arrow_glacier_vm_runtime_imports : + AreImported globals "ethereum.arrow_glacier.vm.runtime" [ "get_valid_jump_destinations" ]. Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -518,7 +441,7 @@ Definition process_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "StackDepthLimitError" |), make_list [ Constant.str "Stack depth limit reached" diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/memory.v b/CoqOfPython/ethereum/arrow_glacier/vm/memory.v index 08d2290..acbe8bd 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/memory.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/memory.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.arrow_glacier.vm.memory". Definition expr_1 : Value.t := Constant.str " @@ -17,17 +17,11 @@ Introduction EVM memory operations. ". -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_right_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "right_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "right_pad_zero_bytes" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. Definition memory_write : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,22 +39,27 @@ Definition memory_write : Value.t -> Value.t -> M := Data to write to memory. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + M.slice (| + M.get_name (| globals, "memory" |), + M.get_name (| globals, "start_position" |), + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) - |) |) |), + Constant.None_ + |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_)). @@ -86,22 +85,27 @@ Definition memory_read_bytes : Value.t -> Value.t -> M := Data read from memory. " in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + M.slice (| + M.get_name (| globals, "memory" |), + M.get_name (| globals, "start_position" |), + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |) |) + Constant.None_ + |) |) in M.pure Constant.None_)). @@ -129,22 +133,27 @@ Definition buffer_read : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "right_pad_zero_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "buffer" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + M.slice (| + M.get_name (| globals, "buffer" |), + M.get_name (| globals, "start_position" |), + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |) |); + Constant.None_ + |); M.get_name (| globals, "size" |) ], make_dict [] diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/__init__.v index c8bcc33..5d06ae3 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/__init__.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.arrow_glacier.vm.precompiled_contracts.__init__". Definition expr_1 : Value.t := Constant.str " @@ -18,9 +18,8 @@ Addresses of precompiled contracts and mappings to their implementations. ". -Require ethereum.arrow_glacier.utils.hexadecimal. -Axiom ethereum_arrow_glacier_utils_hexadecimal_hex_to_address : - IsGlobalAlias globals ethereum.arrow_glacier.utils.hexadecimal.globals "hex_to_address". +Axiom ethereum_arrow_glacier_utils_hexadecimal_imports : + AreImported globals "ethereum.arrow_glacier.utils.hexadecimal" [ "hex_to_address" ]. Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS"; Constant.str "MODEXP_ADDRESS"; Constant.str "ALT_BN128_ADD_ADDRESS"; Constant.str "ALT_BN128_MUL_ADDRESS"; Constant.str "ALT_BN128_PAIRING_CHECK_ADDRESS"; Constant.str "BLAKE2F_ADDRESS" ] diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/alt_bn128.v index 508a9a9..3b43930 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/alt_bn128.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/alt_bn128.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.arrow_glacier.vm.precompiled_contracts.alt_bn128". Definition expr_1 : Value.t := Constant.str " @@ -17,49 +17,26 @@ Introduction Implementation of the ALT_BN128 precompiled contracts. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. -Require ethereum.crypto.alt_bn128. -Axiom ethereum_crypto_alt_bn128_ALT_BN128_CURVE_ORDER : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "ALT_BN128_CURVE_ORDER". -Axiom ethereum_crypto_alt_bn128_ALT_BN128_PRIME : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "ALT_BN128_PRIME". -Axiom ethereum_crypto_alt_bn128_BNF : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF". -Axiom ethereum_crypto_alt_bn128_BNF2 : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF2". -Axiom ethereum_crypto_alt_bn128_BNF12 : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF12". -Axiom ethereum_crypto_alt_bn128_BNP : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNP". -Axiom ethereum_crypto_alt_bn128_BNP2 : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNP2". -Axiom ethereum_crypto_alt_bn128_pairing : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "pairing". +Axiom ethereum_crypto_alt_bn128_imports : + AreImported globals "ethereum.crypto.alt_bn128" [ "ALT_BN128_CURVE_ORDER"; "ALT_BN128_PRIME"; "BNF"; "BNF2"; "BNF12"; "BNP"; "BNP2"; "pairing" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.arrow_glacier.vm.__init__. -Axiom ethereum_arrow_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Evm". +Axiom ethereum_arrow_glacier_vm_imports : + AreImported globals "ethereum.arrow_glacier.vm" [ "Evm" ]. -Require ethereum.arrow_glacier.vm.gas. -Axiom ethereum_arrow_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "charge_gas". +Axiom ethereum_arrow_glacier_vm_gas_imports : + AreImported globals "ethereum.arrow_glacier.vm.gas" [ "charge_gas" ]. -Require ethereum.arrow_glacier.vm.memory. -Axiom ethereum_arrow_glacier_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.arrow_glacier.vm.memory.globals "buffer_read". +Axiom ethereum_arrow_glacier_vm_memory_imports : + AreImported globals "ethereum.arrow_glacier.vm.memory" [ "buffer_read" ]. -Require ethereum.arrow_glacier.vm.exceptions. -Axiom ethereum_arrow_glacier_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.arrow_glacier.vm.exceptions.globals "OutOfGasError". +Axiom ethereum_arrow_glacier_vm_exceptions_imports : + AreImported globals "ethereum.arrow_glacier.vm.exceptions" [ "OutOfGasError" ]. Definition alt_bn128_add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -208,23 +185,32 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ] do - let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| - M.get_name (| globals, "i" |), - M.get_name (| globals, "ALT_BN128_PRIME" |) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ], ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in (* At stmt: unsupported node type: Try *) let p := BinOp.add (| @@ -363,23 +349,32 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ] do - let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| - M.get_name (| globals, "i" |), - M.get_name (| globals, "ALT_BN128_PRIME" |) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ], ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in (* At stmt: unsupported node type: Try *) let p := M.call (| @@ -466,7 +461,7 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -480,76 +475,89 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - BinOp.floor_div (| + let _ := + M.for_ (| + M.get_name (| globals, "i" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "data" |) - ], - make_dict [] - |), - Constant.int 192 - |) - ], - make_dict [] - |) do - let values := - make_list [] in - For M.get_name (| globals, "j" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 6 - ], - make_dict [] - |) do - let value := + M.get_name (| globals, "range" |), + make_list [ + BinOp.floor_div (| M.call (| - M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + M.get_name (| globals, "len" |), make_list [ - M.get_subscript (| M.get_name (| globals, "data" |), M.slice (| BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "i" |), - Constant.int 192 - |), - BinOp.mult (| - Constant.int 32, - M.get_name (| globals, "j" |) - |) - |), BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "i" |), - Constant.int 192 - |), - BinOp.mult (| - Constant.int 32, - BinOp.add (| - M.get_name (| globals, "j" |), - Constant.int 1 - |) - |) - |) |) |) + M.get_name (| globals, "data" |) ], make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| - M.get_name (| globals, "value" |), - M.get_name (| globals, "ALT_BN128_PRIME" |) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let _ := M.call (| + |), + Constant.int 192 + |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let values := + make_list [] in + let _ := + M.for_ (| + M.get_name (| globals, "j" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 6 + ], + make_dict [] + |), + ltac:(M.monadic ( + let value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.slice (| + M.get_name (| globals, "data" |), + BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + M.get_name (| globals, "j" |) + |) + |), + BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "j" |), + Constant.int 1 + |) + |) + |), + Constant.None_ + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| M.get_field (| M.get_name (| globals, "values" |), "append" |), make_list [ M.call (| @@ -562,9 +570,14 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in (* At stmt: unsupported node type: Try *) - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.eq (| @@ -585,7 +598,7 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.eq (| @@ -606,49 +619,54 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| - M.get_name (| globals, "p" |), - M.call (| - M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) - |), + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "p" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "q" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |) + )) + |), + (* then *) ltac:(M.monadic ( - Compare.not_eq (| - M.get_name (| globals, "q" |), - M.call (| - M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) - |) - )) - |), - (* then *) - ltac:(M.monadic ( - let result := - BinOp.mult (| - M.get_name (| globals, "result" |), - M.call (| - M.get_name (| globals, "pairing" |), - make_list [ - M.get_name (| globals, "q" |); - M.get_name (| globals, "p" |) - ], - make_dict [] - |) - |) in + let result := + BinOp.mult (| + M.get_name (| globals, "result" |), + M.call (| + M.get_name (| globals, "pairing" |), + make_list [ + M.get_name (| globals, "q" |); + M.get_name (| globals, "p" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := (* if *) M.if_then_else (| diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/blake2f.v b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/blake2f.v index 3bc1b25..bf62e5e 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/blake2f.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/blake2f.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.arrow_glacier.vm.precompiled_contracts.blake2f". Definition expr_1 : Value.t := Constant.str " @@ -17,27 +17,20 @@ Introduction Implementation of the `Blake2` precompiled contract. ". -Require ethereum.crypto.blake2. -Axiom ethereum_crypto_blake2_Blake2b : - IsGlobalAlias globals ethereum.crypto.blake2.globals "Blake2b". +Axiom ethereum_crypto_blake2_imports : + AreImported globals "ethereum.crypto.blake2" [ "Blake2b" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.arrow_glacier.vm.__init__. -Axiom ethereum_arrow_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Evm". +Axiom ethereum_arrow_glacier_vm_imports : + AreImported globals "ethereum.arrow_glacier.vm" [ "Evm" ]. -Require ethereum.arrow_glacier.vm.gas. -Axiom ethereum_arrow_glacier_vm_gas_GAS_BLAKE2_PER_ROUND : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_BLAKE2_PER_ROUND". -Axiom ethereum_arrow_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "charge_gas". +Axiom ethereum_arrow_glacier_vm_gas_imports : + AreImported globals "ethereum.arrow_glacier.vm.gas" [ "GAS_BLAKE2_PER_ROUND"; "charge_gas" ]. -Require ethereum.arrow_glacier.vm.exceptions. -Axiom ethereum_arrow_glacier_vm_exceptions_InvalidParameter : - IsGlobalAlias globals ethereum.arrow_glacier.vm.exceptions.globals "InvalidParameter". +Axiom ethereum_arrow_glacier_vm_exceptions_imports : + AreImported globals "ethereum.arrow_glacier.vm.exceptions" [ "InvalidParameter" ]. Definition blake2f : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -99,7 +92,7 @@ Definition blake2f : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.in (| + Compare.in_ (| M.get_name (| globals, "f" |), make_list [ Constant.int 0; diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/ecrecover.v index cb14fdc..5b0a066 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/ecrecover.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.arrow_glacier.vm.precompiled_contracts.ecrecover". Definition expr_1 : Value.t := Constant.str " @@ -17,39 +17,26 @@ Introduction Implementation of the ECRECOVER precompiled contract. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.crypto.elliptic_curve. -Axiom ethereum_crypto_elliptic_curve_SECP256K1N : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". -Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". +Axiom ethereum_crypto_elliptic_curve_imports : + AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_left_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. -Require ethereum.arrow_glacier.vm.__init__. -Axiom ethereum_arrow_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Evm". +Axiom ethereum_arrow_glacier_vm_imports : + AreImported globals "ethereum.arrow_glacier.vm" [ "Evm" ]. -Require ethereum.arrow_glacier.vm.gas. -Axiom ethereum_arrow_glacier_vm_gas_GAS_ECRECOVER : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_ECRECOVER". -Axiom ethereum_arrow_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "charge_gas". +Axiom ethereum_arrow_glacier_vm_gas_imports : + AreImported globals "ethereum.arrow_glacier.vm.gas" [ "GAS_ECRECOVER"; "charge_gas" ]. -Require ethereum.arrow_glacier.vm.memory. -Axiom ethereum_arrow_glacier_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.arrow_glacier.vm.memory.globals "buffer_read". +Axiom ethereum_arrow_glacier_vm_memory_imports : + AreImported globals "ethereum.arrow_glacier.vm.memory" [ "buffer_read" ]. Definition ecrecover : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -264,13 +251,18 @@ Definition ecrecover : Value.t -> Value.t -> M := )) |) in (* At stmt: unsupported node type: Try *) let address := - M.get_subscript (| M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "public_key" |) - ], - make_dict [] - |), M.slice (| Constant.int 12, Constant.int 32 |) |) in + M.slice (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), + Constant.int 12, + Constant.int 32, + Constant.None_ + |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/identity.v index b192d30..9032a82 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/identity.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/identity.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.arrow_glacier.vm.precompiled_contracts.identity". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementation of the `IDENTITY` precompiled contract. ". -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.arrow_glacier.vm.__init__. -Axiom ethereum_arrow_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Evm". +Axiom ethereum_arrow_glacier_vm_imports : + AreImported globals "ethereum.arrow_glacier.vm" [ "Evm" ]. -Require ethereum.arrow_glacier.vm.gas. -Axiom ethereum_arrow_glacier_vm_gas_GAS_IDENTITY : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_IDENTITY". -Axiom ethereum_arrow_glacier_vm_gas_GAS_IDENTITY_WORD : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_IDENTITY_WORD". -Axiom ethereum_arrow_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "charge_gas". +Axiom ethereum_arrow_glacier_vm_gas_imports : + AreImported globals "ethereum.arrow_glacier.vm.gas" [ "GAS_IDENTITY"; "GAS_IDENTITY_WORD"; "charge_gas" ]. Definition identity : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/mapping.v index 3f3cbfc..b43b508 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/mapping.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/mapping.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.arrow_glacier.vm.precompiled_contracts.mapping". Definition expr_1 : Value.t := Constant.str " @@ -17,66 +17,34 @@ Introduction Mapping of precompiled contracts their implementations. ". -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". - -Require ethereum.arrow_glacier.fork_types. -Axiom ethereum_arrow_glacier_fork_types_Address : - IsGlobalAlias globals ethereum.arrow_glacier.fork_types.globals "Address". - -Require ethereum.arrow_glacier.vm.precompiled_contracts.__init__. -Axiom ethereum_arrow_glacier_vm_precompiled_contracts___init___ALT_BN128_ADD_ADDRESS : - IsGlobalAlias globals ethereum.arrow_glacier.vm.precompiled_contracts.__init__.globals "ALT_BN128_ADD_ADDRESS". -Axiom ethereum_arrow_glacier_vm_precompiled_contracts___init___ALT_BN128_MUL_ADDRESS : - IsGlobalAlias globals ethereum.arrow_glacier.vm.precompiled_contracts.__init__.globals "ALT_BN128_MUL_ADDRESS". -Axiom ethereum_arrow_glacier_vm_precompiled_contracts___init___ALT_BN128_PAIRING_CHECK_ADDRESS : - IsGlobalAlias globals ethereum.arrow_glacier.vm.precompiled_contracts.__init__.globals "ALT_BN128_PAIRING_CHECK_ADDRESS". -Axiom ethereum_arrow_glacier_vm_precompiled_contracts___init___BLAKE2F_ADDRESS : - IsGlobalAlias globals ethereum.arrow_glacier.vm.precompiled_contracts.__init__.globals "BLAKE2F_ADDRESS". -Axiom ethereum_arrow_glacier_vm_precompiled_contracts___init___ECRECOVER_ADDRESS : - IsGlobalAlias globals ethereum.arrow_glacier.vm.precompiled_contracts.__init__.globals "ECRECOVER_ADDRESS". -Axiom ethereum_arrow_glacier_vm_precompiled_contracts___init___IDENTITY_ADDRESS : - IsGlobalAlias globals ethereum.arrow_glacier.vm.precompiled_contracts.__init__.globals "IDENTITY_ADDRESS". -Axiom ethereum_arrow_glacier_vm_precompiled_contracts___init___MODEXP_ADDRESS : - IsGlobalAlias globals ethereum.arrow_glacier.vm.precompiled_contracts.__init__.globals "MODEXP_ADDRESS". -Axiom ethereum_arrow_glacier_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : - IsGlobalAlias globals ethereum.arrow_glacier.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". -Axiom ethereum_arrow_glacier_vm_precompiled_contracts___init___SHA256_ADDRESS : - IsGlobalAlias globals ethereum.arrow_glacier.vm.precompiled_contracts.__init__.globals "SHA256_ADDRESS". - -Require ethereum.arrow_glacier.vm.precompiled_contracts.alt_bn128. -Axiom ethereum_arrow_glacier_vm_precompiled_contracts_alt_bn128_alt_bn128_add : - IsGlobalAlias globals ethereum.arrow_glacier.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_add". -Axiom ethereum_arrow_glacier_vm_precompiled_contracts_alt_bn128_alt_bn128_mul : - IsGlobalAlias globals ethereum.arrow_glacier.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_mul". -Axiom ethereum_arrow_glacier_vm_precompiled_contracts_alt_bn128_alt_bn128_pairing_check : - IsGlobalAlias globals ethereum.arrow_glacier.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_pairing_check". - -Require ethereum.arrow_glacier.vm.precompiled_contracts.blake2f. -Axiom ethereum_arrow_glacier_vm_precompiled_contracts_blake2f_blake2f : - IsGlobalAlias globals ethereum.arrow_glacier.vm.precompiled_contracts.blake2f.globals "blake2f". - -Require ethereum.arrow_glacier.vm.precompiled_contracts.ecrecover. -Axiom ethereum_arrow_glacier_vm_precompiled_contracts_ecrecover_ecrecover : - IsGlobalAlias globals ethereum.arrow_glacier.vm.precompiled_contracts.ecrecover.globals "ecrecover". - -Require ethereum.arrow_glacier.vm.precompiled_contracts.identity. -Axiom ethereum_arrow_glacier_vm_precompiled_contracts_identity_identity : - IsGlobalAlias globals ethereum.arrow_glacier.vm.precompiled_contracts.identity.globals "identity". - -Require ethereum.arrow_glacier.vm.precompiled_contracts.modexp. -Axiom ethereum_arrow_glacier_vm_precompiled_contracts_modexp_modexp : - IsGlobalAlias globals ethereum.arrow_glacier.vm.precompiled_contracts.modexp.globals "modexp". - -Require ethereum.arrow_glacier.vm.precompiled_contracts.ripemd160. -Axiom ethereum_arrow_glacier_vm_precompiled_contracts_ripemd160_ripemd160 : - IsGlobalAlias globals ethereum.arrow_glacier.vm.precompiled_contracts.ripemd160.globals "ripemd160". - -Require ethereum.arrow_glacier.vm.precompiled_contracts.sha256. -Axiom ethereum_arrow_glacier_vm_precompiled_contracts_sha256_sha256 : - IsGlobalAlias globals ethereum.arrow_glacier.vm.precompiled_contracts.sha256.globals "sha256". +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict" ]. + +Axiom ethereum_arrow_glacier_fork_types_imports : + AreImported globals "ethereum.arrow_glacier.fork_types" [ "Address" ]. + +Axiom ethereum_arrow_glacier_vm_precompiled_contracts_imports : + AreImported globals "ethereum.arrow_glacier.vm.precompiled_contracts" [ "ALT_BN128_ADD_ADDRESS"; "ALT_BN128_MUL_ADDRESS"; "ALT_BN128_PAIRING_CHECK_ADDRESS"; "BLAKE2F_ADDRESS"; "ECRECOVER_ADDRESS"; "IDENTITY_ADDRESS"; "MODEXP_ADDRESS"; "RIPEMD160_ADDRESS"; "SHA256_ADDRESS" ]. + +Axiom ethereum_arrow_glacier_vm_precompiled_contracts_alt_bn128_imports : + AreImported globals "ethereum.arrow_glacier.vm.precompiled_contracts.alt_bn128" [ "alt_bn128_add"; "alt_bn128_mul"; "alt_bn128_pairing_check" ]. + +Axiom ethereum_arrow_glacier_vm_precompiled_contracts_blake2f_imports : + AreImported globals "ethereum.arrow_glacier.vm.precompiled_contracts.blake2f" [ "blake2f" ]. + +Axiom ethereum_arrow_glacier_vm_precompiled_contracts_ecrecover_imports : + AreImported globals "ethereum.arrow_glacier.vm.precompiled_contracts.ecrecover" [ "ecrecover" ]. + +Axiom ethereum_arrow_glacier_vm_precompiled_contracts_identity_imports : + AreImported globals "ethereum.arrow_glacier.vm.precompiled_contracts.identity" [ "identity" ]. + +Axiom ethereum_arrow_glacier_vm_precompiled_contracts_modexp_imports : + AreImported globals "ethereum.arrow_glacier.vm.precompiled_contracts.modexp" [ "modexp" ]. + +Axiom ethereum_arrow_glacier_vm_precompiled_contracts_ripemd160_imports : + AreImported globals "ethereum.arrow_glacier.vm.precompiled_contracts.ripemd160" [ "ripemd160" ]. + +Axiom ethereum_arrow_glacier_vm_precompiled_contracts_sha256_imports : + AreImported globals "ethereum.arrow_glacier.vm.precompiled_contracts.sha256" [ "sha256" ]. (* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/modexp.v index 4e1ef02..7471ac7 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/modexp.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/modexp.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.arrow_glacier.vm.precompiled_contracts.modexp". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementation of the `MODEXP` precompiled contract. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. -Require ethereum.arrow_glacier.vm.__init__. -Axiom ethereum_arrow_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Evm". +Axiom ethereum_arrow_glacier_vm_imports : + AreImported globals "ethereum.arrow_glacier.vm" [ "Evm" ]. -Require ethereum.arrow_glacier.vm.gas. -Axiom ethereum_arrow_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "charge_gas". +Axiom ethereum_arrow_glacier_vm_gas_imports : + AreImported globals "ethereum.arrow_glacier.vm.gas" [ "charge_gas" ]. -Require ethereum.arrow_glacier.vm.memory. -Axiom ethereum_arrow_glacier_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.arrow_glacier.vm.memory.globals "buffer_read". +Axiom ethereum_arrow_glacier_vm_memory_imports : + AreImported globals "ethereum.arrow_glacier.vm.memory" [ "buffer_read" ]. Definition GQUADDIVISOR : Value.t := M.run ltac:(M.monadic ( Constant.int 3 diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/ripemd160.v index fa82312..57fafeb 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/ripemd160.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/ripemd160.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.arrow_glacier.vm.precompiled_contracts.ripemd160". Definition expr_1 : Value.t := Constant.str " @@ -19,29 +19,20 @@ Implementation of the `RIPEMD160` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_left_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.arrow_glacier.vm.__init__. -Axiom ethereum_arrow_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Evm". +Axiom ethereum_arrow_glacier_vm_imports : + AreImported globals "ethereum.arrow_glacier.vm" [ "Evm" ]. -Require ethereum.arrow_glacier.vm.gas. -Axiom ethereum_arrow_glacier_vm_gas_GAS_RIPEMD160 : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_RIPEMD160". -Axiom ethereum_arrow_glacier_vm_gas_GAS_RIPEMD160_WORD : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_RIPEMD160_WORD". -Axiom ethereum_arrow_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "charge_gas". +Axiom ethereum_arrow_glacier_vm_gas_imports : + AreImported globals "ethereum.arrow_glacier.vm.gas" [ "GAS_RIPEMD160"; "GAS_RIPEMD160_WORD"; "charge_gas" ]. Definition ripemd160 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/sha256.v index 155c6ec..97d3445 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/sha256.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/sha256.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.arrow_glacier.vm.precompiled_contracts.sha256". Definition expr_1 : Value.t := Constant.str " @@ -19,25 +19,17 @@ Implementation of the `SHA256` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.arrow_glacier.vm.__init__. -Axiom ethereum_arrow_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.arrow_glacier.vm.__init__.globals "Evm". +Axiom ethereum_arrow_glacier_vm_imports : + AreImported globals "ethereum.arrow_glacier.vm" [ "Evm" ]. -Require ethereum.arrow_glacier.vm.gas. -Axiom ethereum_arrow_glacier_vm_gas_GAS_SHA256 : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_SHA256". -Axiom ethereum_arrow_glacier_vm_gas_GAS_SHA256_WORD : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "GAS_SHA256_WORD". -Axiom ethereum_arrow_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.arrow_glacier.vm.gas.globals "charge_gas". +Axiom ethereum_arrow_glacier_vm_gas_imports : + AreImported globals "ethereum.arrow_glacier.vm.gas" [ "GAS_SHA256"; "GAS_SHA256_WORD"; "charge_gas" ]. Definition sha256 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/runtime.v b/CoqOfPython/ethereum/arrow_glacier/vm/runtime.v index 411564a..f45a90f 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/runtime.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/runtime.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.arrow_glacier.vm.runtime". Definition expr_1 : Value.t := Constant.str " @@ -17,17 +17,14 @@ Introduction Runtime related operations used while executing EVM code. ". -Require typing. -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". +Axiom typing_imports : + AreImported globals "typing" [ "Set" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.arrow_glacier.vm.instructions.__init__. -Axiom ethereum_arrow_glacier_vm_instructions___init___Ops : - IsGlobalAlias globals ethereum.arrow_glacier.vm.instructions.__init__.globals "Ops". +Axiom ethereum_arrow_glacier_vm_instructions_imports : + AreImported globals "ethereum.arrow_glacier.vm.instructions" [ "Ops" ]. Definition get_valid_jump_destinations : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -67,75 +64,83 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := ], make_dict [] |) in - While Compare.lt (| - M.get_name (| globals, "pc" |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "code" |) - ], - make_dict [] - |) - |) do -(* At stmt: unsupported node type: Try *) - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "current_opcode" |), - M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) - |), - (* then *) + let _ := + M.while (| + Compare.lt (| + M.get_name (| globals, "pc" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) + |), ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), - make_list [ - M.get_name (| globals, "pc" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( +(* At stmt: unsupported node type: Try *) let _ := (* if *) M.if_then_else (| - BoolOp.and (| - Compare.lt_e (| - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |), - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |) - |), - ltac:(M.monadic ( - Compare.lt_e (| - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH32" |), "value" |) - |) - )) + Compare.eq (| + M.get_name (| globals, "current_opcode" |), + M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) |), (* then *) ltac:(M.monadic ( - let push_data_size := - BinOp.add (| - BinOp.sub (| - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) - |), - Constant.int 1 - |) in - let pc := BinOp.add - M.get_name (| globals, "push_data_size" |) - M.get_name (| globals, "push_data_size" |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), + make_list [ + M.get_name (| globals, "pc" |) + ], + make_dict [] + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.lt_e (| + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |), + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH32" |), "value" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let push_data_size := + BinOp.add (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) + |), + Constant.int 1 + |) in + let pc := BinOp.add + M.get_name (| globals, "push_data_size" |) + M.get_name (| globals, "push_data_size" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ )) |) in + let pc := BinOp.add + Constant.int 1 + Constant.int 1 in M.pure Constant.None_ - )) |) in - let pc := BinOp.add - Constant.int 1 - Constant.int 1 in - EndWhile. + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.get_name (| globals, "valid_jump_destinations" |) |) in diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/stack.v b/CoqOfPython/ethereum/arrow_glacier/vm/stack.v index bfa5165..e0be079 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/stack.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/stack.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.arrow_glacier.vm.stack". Definition expr_1 : Value.t := Constant.str " @@ -17,19 +17,14 @@ Introduction Implementation of the stack operators for the EVM. ". -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". +Axiom typing_imports : + AreImported globals "typing" [ "List" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.arrow_glacier.vm.exceptions. -Axiom ethereum_arrow_glacier_vm_exceptions_StackOverflowError : - IsGlobalAlias globals ethereum.arrow_glacier.vm.exceptions.globals "StackOverflowError". -Axiom ethereum_arrow_glacier_vm_exceptions_StackUnderflowError : - IsGlobalAlias globals ethereum.arrow_glacier.vm.exceptions.globals "StackUnderflowError". +Axiom ethereum_arrow_glacier_vm_exceptions_imports : + AreImported globals "ethereum.arrow_glacier.vm.exceptions" [ "StackOverflowError"; "StackUnderflowError" ]. Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -63,7 +58,7 @@ Definition pop : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "StackUnderflowError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "StackUnderflowError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -108,7 +103,7 @@ Definition push : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "StackOverflowError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "StackOverflowError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/base_types.v b/CoqOfPython/ethereum/base_types.v index 78b29bc..970976c 100644 --- a/CoqOfPython/ethereum/base_types.v +++ b/CoqOfPython/ethereum/base_types.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.base_types". Definition expr_1 : Value.t := Constant.str " @@ -24,31 +24,11 @@ sequences containing an exact number of bytes. [`Bytes64`]: ref:ethereum.base_types.Bytes64 ". -Require dataclasses. -Axiom dataclasses_is_dataclass : - IsGlobalAlias globals dataclasses.globals "is_dataclass". -Axiom dataclasses_replace : - IsGlobalAlias globals dataclasses.globals "replace". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "is_dataclass"; "replace" ]. -Require typing. -Axiom typing_Any : - IsGlobalAlias globals typing.globals "Any". -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_ClassVar : - IsGlobalAlias globals typing.globals "ClassVar". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Protocol : - IsGlobalAlias globals typing.globals "Protocol". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Type_ : - IsGlobalAlias globals typing.globals "Type_". -Axiom typing_TypeVar : - IsGlobalAlias globals typing.globals "TypeVar". -Axiom typing_runtime_checkable : - IsGlobalAlias globals typing.globals "runtime_checkable". +Axiom typing_imports : + AreImported globals "typing" [ "Any"; "Callable"; "ClassVar"; "Optional"; "Protocol"; "Tuple"; "Type"; "TypeVar"; "runtime_checkable" ]. Definition SlottedFreezable : Value.t := builtins.make_klass @@ -166,7 +146,7 @@ Definition Uint : Value.t := |) |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "TypeError" |), make_list [], make_dict [] @@ -185,7 +165,7 @@ Definition Uint : Value.t := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "OverflowError" |), make_list [], make_dict [] @@ -246,7 +226,7 @@ Definition Uint : Value.t := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "OverflowError" |), make_list [], make_dict [] @@ -332,7 +312,7 @@ Definition Uint : Value.t := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "OverflowError" |), make_list [], make_dict [] @@ -403,7 +383,7 @@ Definition Uint : Value.t := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "OverflowError" |), make_list [], make_dict [] @@ -481,7 +461,7 @@ Definition Uint : Value.t := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "OverflowError" |), make_list [], make_dict [] @@ -574,7 +554,7 @@ Definition Uint : Value.t := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "OverflowError" |), make_list [], make_dict [] @@ -637,7 +617,7 @@ Definition Uint : Value.t := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "OverflowError" |), make_list [], make_dict [] @@ -715,7 +695,7 @@ Definition Uint : Value.t := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "OverflowError" |), make_list [], make_dict [] @@ -778,7 +758,7 @@ Definition Uint : Value.t := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "OverflowError" |), make_list [], make_dict [] @@ -856,7 +836,7 @@ Definition Uint : Value.t := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "OverflowError" |), make_list [], make_dict [] @@ -880,14 +860,20 @@ Definition Uint : Value.t := M.get_field (| M.get_name (| globals, "int" |), "__new__" |), make_list [ M.get_field (| M.get_name (| globals, "self" |), "__class__" |); - M.get_subscript (| M.get_name (| globals, "result" |), Constant.int 0 |) + M.get_subscript (| + M.get_name (| globals, "result" |), + Constant.int 0 + |) ], make_dict [] |); M.call (| M.get_field (| M.get_name (| globals, "int" |), "__new__" |), make_list [ M.get_field (| M.get_name (| globals, "self" |), "__class__" |); - M.get_subscript (| M.get_name (| globals, "result" |), Constant.int 1 |) + M.get_subscript (| + M.get_name (| globals, "result" |), + Constant.int 1 + |) ], make_dict [] |) ] @@ -928,7 +914,7 @@ Definition Uint : Value.t := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "OverflowError" |), make_list [], make_dict [] @@ -952,14 +938,20 @@ Definition Uint : Value.t := M.get_field (| M.get_name (| globals, "int" |), "__new__" |), make_list [ M.get_field (| M.get_name (| globals, "self" |), "__class__" |); - M.get_subscript (| M.get_name (| globals, "result" |), Constant.int 0 |) + M.get_subscript (| + M.get_name (| globals, "result" |), + Constant.int 0 + |) ], make_dict [] |); M.call (| M.get_field (| M.get_name (| globals, "int" |), "__new__" |), make_list [ M.get_field (| M.get_name (| globals, "self" |), "__class__" |); - M.get_subscript (| M.get_name (| globals, "result" |), Constant.int 1 |) + M.get_subscript (| + M.get_name (| globals, "result" |), + Constant.int 1 + |) ], make_dict [] |) ] @@ -1009,7 +1001,7 @@ Definition Uint : Value.t := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "OverflowError" |), make_list [], make_dict [] @@ -1054,7 +1046,7 @@ Definition Uint : Value.t := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "OverflowError" |), make_list [], make_dict [] @@ -1127,7 +1119,7 @@ Definition Uint : Value.t := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "OverflowError" |), make_list [], make_dict [] @@ -1172,7 +1164,7 @@ Definition Uint : Value.t := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "OverflowError" |), make_list [], make_dict [] @@ -1252,7 +1244,7 @@ Definition Uint : Value.t := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "OverflowError" |), make_list [], make_dict [] @@ -1315,7 +1307,7 @@ Definition Uint : Value.t := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "OverflowError" |), make_list [], make_dict [] @@ -1503,7 +1495,7 @@ Definition FixedUint : Value.t := |) |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "TypeError" |), make_list [], make_dict [] @@ -1530,7 +1522,7 @@ Definition FixedUint : Value.t := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "OverflowError" |), make_list [], make_dict [] @@ -1608,7 +1600,7 @@ Definition FixedUint : Value.t := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "OverflowError" |), make_list [], make_dict [] @@ -1681,7 +1673,7 @@ Definition FixedUint : Value.t := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "OverflowError" |), make_list [], make_dict [] @@ -1778,7 +1770,7 @@ Definition FixedUint : Value.t := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "OverflowError" |), make_list [], make_dict [] @@ -1858,7 +1850,7 @@ Definition FixedUint : Value.t := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "OverflowError" |), make_list [], make_dict [] @@ -1940,7 +1932,7 @@ Definition FixedUint : Value.t := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "OverflowError" |), make_list [], make_dict [] @@ -2035,7 +2027,7 @@ Definition FixedUint : Value.t := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "OverflowError" |), make_list [], make_dict [] @@ -2108,7 +2100,7 @@ Definition FixedUint : Value.t := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "OverflowError" |), make_list [], make_dict [] @@ -2212,7 +2204,7 @@ Definition FixedUint : Value.t := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "OverflowError" |), make_list [], make_dict [] @@ -2283,7 +2275,7 @@ Definition FixedUint : Value.t := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "OverflowError" |), make_list [], make_dict [] @@ -2369,7 +2361,7 @@ Definition FixedUint : Value.t := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "OverflowError" |), make_list [], make_dict [] @@ -2440,7 +2432,7 @@ Definition FixedUint : Value.t := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "OverflowError" |), make_list [], make_dict [] @@ -2526,7 +2518,7 @@ Definition FixedUint : Value.t := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "OverflowError" |), make_list [], make_dict [] @@ -2556,14 +2548,20 @@ Definition FixedUint : Value.t := M.get_field (| M.get_name (| globals, "int" |), "__new__" |), make_list [ M.get_field (| M.get_name (| globals, "self" |), "__class__" |); - M.get_subscript (| M.get_name (| globals, "result" |), Constant.int 0 |) + M.get_subscript (| + M.get_name (| globals, "result" |), + Constant.int 0 + |) ], make_dict [] |); M.call (| M.get_field (| M.get_name (| globals, "int" |), "__new__" |), make_list [ M.get_field (| M.get_name (| globals, "self" |), "__class__" |); - M.get_subscript (| M.get_name (| globals, "result" |), Constant.int 1 |) + M.get_subscript (| + M.get_name (| globals, "result" |), + Constant.int 1 + |) ], make_dict [] |) ] @@ -2612,7 +2610,7 @@ Definition FixedUint : Value.t := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "OverflowError" |), make_list [], make_dict [] @@ -2642,14 +2640,20 @@ Definition FixedUint : Value.t := M.get_field (| M.get_name (| globals, "int" |), "__new__" |), make_list [ M.get_field (| M.get_name (| globals, "self" |), "__class__" |); - M.get_subscript (| M.get_name (| globals, "result" |), Constant.int 0 |) + M.get_subscript (| + M.get_name (| globals, "result" |), + Constant.int 0 + |) ], make_dict [] |); M.call (| M.get_field (| M.get_name (| globals, "int" |), "__new__" |), make_list [ M.get_field (| M.get_name (| globals, "self" |), "__class__" |); - M.get_subscript (| M.get_name (| globals, "result" |), Constant.int 1 |) + M.get_subscript (| + M.get_name (| globals, "result" |), + Constant.int 1 + |) ], make_dict [] |) ] @@ -2707,7 +2711,7 @@ Definition FixedUint : Value.t := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "OverflowError" |), make_list [], make_dict [] @@ -2778,7 +2782,7 @@ Definition FixedUint : Value.t := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "OverflowError" |), make_list [], make_dict [] @@ -2862,7 +2866,7 @@ Definition FixedUint : Value.t := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "OverflowError" |), make_list [], make_dict [] @@ -2915,7 +2919,7 @@ Definition FixedUint : Value.t := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "OverflowError" |), make_list [], make_dict [] @@ -2999,7 +3003,7 @@ Definition FixedUint : Value.t := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "OverflowError" |), make_list [], make_dict [] @@ -3052,7 +3056,7 @@ Definition FixedUint : Value.t := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "OverflowError" |), make_list [], make_dict [] @@ -3140,7 +3144,7 @@ Definition FixedUint : Value.t := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "OverflowError" |), make_list [], make_dict [] @@ -3211,7 +3215,7 @@ Definition FixedUint : Value.t := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "OverflowError" |), make_list [], make_dict [] @@ -3282,7 +3286,7 @@ Definition FixedUint : Value.t := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "OverflowError" |), make_list [], make_dict [] @@ -3353,7 +3357,7 @@ Definition FixedUint : Value.t := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "OverflowError" |), make_list [], make_dict [] @@ -3529,7 +3533,7 @@ Definition U256 : Value.t := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "ValueError" |), make_list [], make_dict [] @@ -3709,7 +3713,7 @@ Definition U32 : Value.t := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "ValueError" |), make_list [], make_dict [] @@ -3830,7 +3834,7 @@ Definition U64 : Value.t := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "ValueError" |), make_list [], make_dict [] @@ -3881,7 +3885,7 @@ Definition U64 : Value.t := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "ValueError" |), make_list [], make_dict [] @@ -4047,7 +4051,7 @@ Definition FixedBytes : Value.t := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "ValueError" |), make_list [ Constant.str "(* At expr: unsupported node type: JoinedStr *)" @@ -4172,7 +4176,7 @@ Definition _setattr_function : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "Exception" |), make_list [ Constant.str "Mutating frozen dataclasses is not allowed." @@ -4204,7 +4208,7 @@ Definition _delattr_function : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "self" |), "_frozen" |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "Exception" |), make_list [ Constant.str "Mutating frozen dataclasses is not allowed." diff --git a/CoqOfPython/ethereum/berlin/__init__.v b/CoqOfPython/ethereum/berlin/__init__.v index 4a8bbc8..efe0a00 100644 --- a/CoqOfPython/ethereum/berlin/__init__.v +++ b/CoqOfPython/ethereum/berlin/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.berlin.__init__". Definition expr_1 : Value.t := Constant.str " @@ -9,9 +9,8 @@ state access EVM instructions, introduces typed transaction envelopes along with the first new transaction type—optional access lists. ". -Require ethereum.fork_criteria. -Axiom ethereum_fork_criteria_ByBlockNumber : - IsGlobalAlias globals ethereum.fork_criteria.globals "ByBlockNumber". +Axiom ethereum_fork_criteria_imports : + AreImported globals "ethereum.fork_criteria" [ "ByBlockNumber" ]. Definition FORK_CRITERIA : Value.t := M.run ltac:(M.monadic ( M.call (| diff --git a/CoqOfPython/ethereum/berlin/blocks.v b/CoqOfPython/ethereum/berlin/blocks.v index bb6556a..daec5a3 100644 --- a/CoqOfPython/ethereum/berlin/blocks.v +++ b/CoqOfPython/ethereum/berlin/blocks.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.berlin.blocks". Definition expr_1 : Value.t := Constant.str " @@ -14,45 +14,23 @@ history of all state transitions that have happened since the genesis of the chain. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes8 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes8". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". - -Require ethereum.berlin.fork_types. -Axiom ethereum_berlin_fork_types_Address : - IsGlobalAlias globals ethereum.berlin.fork_types.globals "Address". -Axiom ethereum_berlin_fork_types_Bloom : - IsGlobalAlias globals ethereum.berlin.fork_types.globals "Bloom". -Axiom ethereum_berlin_fork_types_Root : - IsGlobalAlias globals ethereum.berlin.fork_types.globals "Root". - -Require ethereum.berlin.transactions. -Axiom ethereum_berlin_transactions_LegacyTransaction : - IsGlobalAlias globals ethereum.berlin.transactions.globals "LegacyTransaction". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Tuple"; "Union" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes8"; "Bytes32"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. + +Axiom ethereum_berlin_fork_types_imports : + AreImported globals "ethereum.berlin.fork_types" [ "Address"; "Bloom"; "Root" ]. + +Axiom ethereum_berlin_transactions_imports : + AreImported globals "ethereum.berlin.transactions" [ "LegacyTransaction" ]. Definition Header : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/berlin/bloom.v b/CoqOfPython/ethereum/berlin/bloom.v index 2fdbbee..8356dcc 100644 --- a/CoqOfPython/ethereum/berlin/bloom.v +++ b/CoqOfPython/ethereum/berlin/bloom.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.berlin.bloom". Definition expr_1 : Value.t := Constant.str " @@ -21,25 +21,20 @@ for efficient searching of logs by address and/or topic, by rapidly eliminating blocks and receipts from their search. ". -Require typing. -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_imports : + AreImported globals "typing" [ "Tuple" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. -Require ethereum.berlin.blocks. -Axiom ethereum_berlin_blocks_Log : - IsGlobalAlias globals ethereum.berlin.blocks.globals "Log". +Axiom ethereum_berlin_blocks_imports : + AreImported globals "ethereum.berlin.blocks" [ "Log" ]. -Require ethereum.berlin.fork_types. -Axiom ethereum_berlin_fork_types_Bloom : - IsGlobalAlias globals ethereum.berlin.fork_types.globals "Bloom". +Axiom ethereum_berlin_fork_types_imports : + AreImported globals "ethereum.berlin.fork_types" [ "Bloom" ]. Definition add_to_bloom : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -66,50 +61,70 @@ Definition add_to_bloom : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "idx" |) in make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ] do - let bit_to_set := - BinOp.bit_and (| - M.call (| - M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "hash" |), M.slice (| M.get_name (| globals, "idx" |), BinOp.add (| - M.get_name (| globals, "idx" |), - Constant.int 2 - |) |) |) - ], - make_dict [] - |), - Constant.int 2047 - |) in - let bit_index := - BinOp.sub (| - Constant.int 2047, - M.get_name (| globals, "bit_to_set" |) - |) in - let byte_index := - BinOp.floor_div (| - M.get_name (| globals, "bit_index" |), - Constant.int 8 - |) in - let bit_value := - BinOp.l_shift (| - Constant.int 1, - BinOp.sub (| - Constant.int 7, - BinOp.mod_ (| + let _ := + M.for_ (| + M.get_name (| globals, "idx" |), + make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ], + ltac:(M.monadic ( + let bit_to_set := + BinOp.bit_and (| + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.slice (| + M.get_name (| globals, "hash" |), + M.get_name (| globals, "idx" |), + BinOp.add (| + M.get_name (| globals, "idx" |), + Constant.int 2 + |), + Constant.None_ + |) + ], + make_dict [] + |), + Constant.int 2047 + |) in + let bit_index := + BinOp.sub (| + Constant.int 2047, + M.get_name (| globals, "bit_to_set" |) + |) in + let byte_index := + BinOp.floor_div (| M.get_name (| globals, "bit_index" |), Constant.int 8 + |) in + let bit_value := + BinOp.l_shift (| + Constant.int 1, + BinOp.sub (| + Constant.int 7, + BinOp.mod_ (| + M.get_name (| globals, "bit_index" |), + Constant.int 8 + |) + |) + |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "bloom" |), + M.get_name (| globals, "byte_index" |) + |), + BinOp.bit_or (| + M.get_subscript (| + M.get_name (| globals, "bloom" |), + M.get_name (| globals, "byte_index" |) + |), + M.get_name (| globals, "bit_value" |) |) - |) - |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), - BinOp.bit_or (| - M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), - M.get_name (| globals, "bit_value" |) - |) - |) in - EndFor. + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_)). Definition logs_bloom : Value.t -> Value.t -> M := @@ -132,8 +147,12 @@ Definition logs_bloom : Value.t -> Value.t -> M := the caller address and the log topics. " in (* At stmt: unsupported node type: AnnAssign *) - For M.get_name (| globals, "log" |) in M.get_name (| globals, "logs" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "log" |), + M.get_name (| globals, "logs" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "add_to_bloom" |), make_list [ M.get_name (| globals, "bloom" |); @@ -141,8 +160,12 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "topic" |) in M.get_field (| M.get_name (| globals, "log" |), "topics" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "topic" |), + M.get_field (| M.get_name (| globals, "log" |), "topics" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "add_to_bloom" |), make_list [ M.get_name (| globals, "bloom" |); @@ -150,8 +173,18 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Bloom" |), diff --git a/CoqOfPython/ethereum/berlin/fork.v b/CoqOfPython/ethereum/berlin/fork.v index 81d4348..d79219b 100644 --- a/CoqOfPython/ethereum/berlin/fork.v +++ b/CoqOfPython/ethereum/berlin/fork.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.berlin.fork". Definition expr_1 : Value.t := Constant.str " @@ -17,153 +17,62 @@ Introduction Entry point for the Ethereum specification. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". - -Require ethereum.base_types. -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". - -Require ethereum.crypto.elliptic_curve. -Axiom ethereum_crypto_elliptic_curve_SECP256K1N : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". -Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.ethash. -Axiom ethereum_ethash_dataset_size : - IsGlobalAlias globals ethereum.ethash.globals "dataset_size". -Axiom ethereum_ethash_generate_cache : - IsGlobalAlias globals ethereum.ethash.globals "generate_cache". -Axiom ethereum_ethash_hashimoto_light : - IsGlobalAlias globals ethereum.ethash.globals "hashimoto_light". - -Require ethereum.exceptions. -Axiom ethereum_exceptions_InvalidBlock : - IsGlobalAlias globals ethereum.exceptions.globals "InvalidBlock". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U64 : - IsGlobalAlias globals ethereum.base_types.globals "U64". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_U256_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.berlin.__init__. -Axiom ethereum_berlin___init___vm : - IsGlobalAlias globals ethereum.berlin.__init__.globals "vm". - -Require ethereum.berlin.blocks. -Axiom ethereum_berlin_blocks_Block : - IsGlobalAlias globals ethereum.berlin.blocks.globals "Block". -Axiom ethereum_berlin_blocks_Header : - IsGlobalAlias globals ethereum.berlin.blocks.globals "Header". -Axiom ethereum_berlin_blocks_Log : - IsGlobalAlias globals ethereum.berlin.blocks.globals "Log". -Axiom ethereum_berlin_blocks_Receipt : - IsGlobalAlias globals ethereum.berlin.blocks.globals "Receipt". - -Require ethereum.berlin.bloom. -Axiom ethereum_berlin_bloom_logs_bloom : - IsGlobalAlias globals ethereum.berlin.bloom.globals "logs_bloom". - -Require ethereum.berlin.fork_types. -Axiom ethereum_berlin_fork_types_Address : - IsGlobalAlias globals ethereum.berlin.fork_types.globals "Address". -Axiom ethereum_berlin_fork_types_Bloom : - IsGlobalAlias globals ethereum.berlin.fork_types.globals "Bloom". -Axiom ethereum_berlin_fork_types_Root : - IsGlobalAlias globals ethereum.berlin.fork_types.globals "Root". - -Require ethereum.berlin.state. -Axiom ethereum_berlin_state_State : - IsGlobalAlias globals ethereum.berlin.state.globals "State". -Axiom ethereum_berlin_state_account_exists_and_is_empty : - IsGlobalAlias globals ethereum.berlin.state.globals "account_exists_and_is_empty". -Axiom ethereum_berlin_state_create_ether : - IsGlobalAlias globals ethereum.berlin.state.globals "create_ether". -Axiom ethereum_berlin_state_destroy_account : - IsGlobalAlias globals ethereum.berlin.state.globals "destroy_account". -Axiom ethereum_berlin_state_get_account : - IsGlobalAlias globals ethereum.berlin.state.globals "get_account". -Axiom ethereum_berlin_state_increment_nonce : - IsGlobalAlias globals ethereum.berlin.state.globals "increment_nonce". -Axiom ethereum_berlin_state_set_account_balance : - IsGlobalAlias globals ethereum.berlin.state.globals "set_account_balance". -Axiom ethereum_berlin_state_state_root : - IsGlobalAlias globals ethereum.berlin.state.globals "state_root". - -Require ethereum.berlin.transactions. -Axiom ethereum_berlin_transactions_TX_ACCESS_LIST_ADDRESS_COST : - IsGlobalAlias globals ethereum.berlin.transactions.globals "TX_ACCESS_LIST_ADDRESS_COST". -Axiom ethereum_berlin_transactions_TX_ACCESS_LIST_STORAGE_KEY_COST : - IsGlobalAlias globals ethereum.berlin.transactions.globals "TX_ACCESS_LIST_STORAGE_KEY_COST". -Axiom ethereum_berlin_transactions_TX_BASE_COST : - IsGlobalAlias globals ethereum.berlin.transactions.globals "TX_BASE_COST". -Axiom ethereum_berlin_transactions_TX_CREATE_COST : - IsGlobalAlias globals ethereum.berlin.transactions.globals "TX_CREATE_COST". -Axiom ethereum_berlin_transactions_TX_DATA_COST_PER_NON_ZERO : - IsGlobalAlias globals ethereum.berlin.transactions.globals "TX_DATA_COST_PER_NON_ZERO". -Axiom ethereum_berlin_transactions_TX_DATA_COST_PER_ZERO : - IsGlobalAlias globals ethereum.berlin.transactions.globals "TX_DATA_COST_PER_ZERO". -Axiom ethereum_berlin_transactions_AccessListTransaction : - IsGlobalAlias globals ethereum.berlin.transactions.globals "AccessListTransaction". -Axiom ethereum_berlin_transactions_LegacyTransaction : - IsGlobalAlias globals ethereum.berlin.transactions.globals "LegacyTransaction". -Axiom ethereum_berlin_transactions_Transaction : - IsGlobalAlias globals ethereum.berlin.transactions.globals "Transaction". -Axiom ethereum_berlin_transactions_decode_transaction : - IsGlobalAlias globals ethereum.berlin.transactions.globals "decode_transaction". -Axiom ethereum_berlin_transactions_encode_transaction : - IsGlobalAlias globals ethereum.berlin.transactions.globals "encode_transaction". - -Require ethereum.berlin.trie. -Axiom ethereum_berlin_trie_Trie : - IsGlobalAlias globals ethereum.berlin.trie.globals "Trie". -Axiom ethereum_berlin_trie_root : - IsGlobalAlias globals ethereum.berlin.trie.globals "root". -Axiom ethereum_berlin_trie_trie_set : - IsGlobalAlias globals ethereum.berlin.trie.globals "trie_set". - -Require ethereum.berlin.utils.message. -Axiom ethereum_berlin_utils_message_prepare_message : - IsGlobalAlias globals ethereum.berlin.utils.message.globals "prepare_message". - -Require ethereum.berlin.vm.interpreter. -Axiom ethereum_berlin_vm_interpreter_process_message_call : - IsGlobalAlias globals ethereum.berlin.vm.interpreter.globals "process_message_call". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple"; "Union" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Bytes0" ]. + +Axiom ethereum_crypto_elliptic_curve_imports : + AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. + +Axiom ethereum_ethash_imports : + AreImported globals "ethereum.ethash" [ "dataset_size"; "generate_cache"; "hashimoto_light" ]. + +Axiom ethereum_exceptions_imports : + AreImported globals "ethereum.exceptions" [ "InvalidBlock" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U64"; "U256"; "U256_CEIL_VALUE"; "Bytes"; "Uint" ]. + +Axiom ethereum_berlin_imports : + AreImported globals "ethereum.berlin" [ "vm" ]. + +Axiom ethereum_berlin_blocks_imports : + AreImported globals "ethereum.berlin.blocks" [ "Block"; "Header"; "Log"; "Receipt" ]. + +Axiom ethereum_berlin_bloom_imports : + AreImported globals "ethereum.berlin.bloom" [ "logs_bloom" ]. + +Axiom ethereum_berlin_fork_types_imports : + AreImported globals "ethereum.berlin.fork_types" [ "Address"; "Bloom"; "Root" ]. + +Axiom ethereum_berlin_state_imports : + AreImported globals "ethereum.berlin.state" [ "State"; "account_exists_and_is_empty"; "create_ether"; "destroy_account"; "get_account"; "increment_nonce"; "set_account_balance"; "state_root" ]. + +Axiom ethereum_berlin_transactions_imports : + AreImported globals "ethereum.berlin.transactions" [ "TX_ACCESS_LIST_ADDRESS_COST"; "TX_ACCESS_LIST_STORAGE_KEY_COST"; "TX_BASE_COST"; "TX_CREATE_COST"; "TX_DATA_COST_PER_NON_ZERO"; "TX_DATA_COST_PER_ZERO"; "AccessListTransaction"; "LegacyTransaction"; "Transaction"; "decode_transaction"; "encode_transaction" ]. + +Axiom ethereum_berlin_trie_imports : + AreImported globals "ethereum.berlin.trie" [ "Trie"; "root"; "trie_set" ]. + +Axiom ethereum_berlin_utils_message_imports : + AreImported globals "ethereum.berlin.utils.message" [ "prepare_message" ]. + +Axiom ethereum_berlin_vm_interpreter_imports : + AreImported globals "ethereum.berlin.vm.interpreter" [ "process_message_call" ]. Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -282,7 +191,12 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := Hashes of the recent 256 blocks in order of increasing block number. " in let recent_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) in + M.slice (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| Constant.int 255 |), + Constant.None_, + Constant.None_ + |) in let _ := (* if *) M.if_then_else (| @@ -308,17 +222,26 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := )) |) in let recent_block_hashes := make_list [] in - For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_blocks" |) do - let prev_block_hash := - M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "block" |), + M.get_name (| globals, "recent_blocks" |), + ltac:(M.monadic ( + let prev_block_hash := + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in + let _ := M.call (| M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), make_list [ M.get_name (| globals, "prev_block_hash" |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let most_recent_block_hash := M.call (| M.get_name (| globals, "keccak256" |), @@ -326,7 +249,10 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), make_list [ - M.get_field (| M.get_subscript (| M.get_name (| globals, "recent_blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) + M.get_field (| M.get_subscript (| + M.get_name (| globals, "recent_blocks" |), + UnOp.sub (| Constant.int 1 |) + |), "header" |) ], make_dict [] |) @@ -370,7 +296,10 @@ Definition state_transition : Value.t -> Value.t -> M := Block to apply to `chain`. " in let parent_header := - M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) in + M.get_field (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| Constant.int 1 |) + |), "header" |) in let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ @@ -490,7 +419,12 @@ Definition state_transition : Value.t -> Value.t -> M := ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) + M.slice (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| Constant.int 255 |), + Constant.None_, + Constant.None_ + |) |) in M.pure Constant.None_ (* else *) @@ -947,21 +881,25 @@ Definition apply_body : Value.t -> Value.t -> M := (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) - For make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "tx" |) ] in M.call (| - M.get_name (| globals, "enumerate" |), - make_list [ - M.call (| - M.get_name (| globals, "map" |), - make_list [ - M.get_name (| globals, "decode_transaction" |); - M.get_name (| globals, "transactions" |) - ], - make_dict [] - |) - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "tx" |) ], + M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.call (| + M.get_name (| globals, "map" |), + make_list [ + M.get_name (| globals, "decode_transaction" |); + M.get_name (| globals, "transactions" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ M.get_name (| globals, "transactions_trie" |); @@ -988,51 +926,51 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_address := - M.call (| - M.get_name (| globals, "check_transaction" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "gas_available" |); - M.get_name (| globals, "chain_id" |) - ], - make_dict [] - |) in - let env := - M.call (| - M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), - make_list [], - make_dict [] - |) in - let _ := M.assign (| - make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |); M.get_name (| globals, "error" |) ], - M.call (| - M.get_name (| globals, "process_transaction" |), - make_list [ - M.get_name (| globals, "env" |); - M.get_name (| globals, "tx" |) - ], - make_dict [] - |) - |) in - let gas_available := BinOp.sub - M.get_name (| globals, "gas_used" |) - M.get_name (| globals, "gas_used" |) in - let receipt := - M.call (| - M.get_name (| globals, "make_receipt" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "error" |); - BinOp.sub (| - M.get_name (| globals, "block_gas_limit" |), - M.get_name (| globals, "gas_available" |) - |); - M.get_name (| globals, "logs" |) - ], - make_dict [] - |) in - let _ := M.call (| + let sender_address := + M.call (| + M.get_name (| globals, "check_transaction" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "gas_available" |); + M.get_name (| globals, "chain_id" |) + ], + make_dict [] + |) in + let env := + M.call (| + M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |); M.get_name (| globals, "error" |) ], + M.call (| + M.get_name (| globals, "process_transaction" |), + make_list [ + M.get_name (| globals, "env" |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) in + let gas_available := BinOp.sub + M.get_name (| globals, "gas_used" |) + M.get_name (| globals, "gas_used" |) in + let receipt := + M.call (| + M.get_name (| globals, "make_receipt" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "error" |); + BinOp.sub (| + M.get_name (| globals, "block_gas_limit" |), + M.get_name (| globals, "gas_available" |) + |); + M.get_name (| globals, "logs" |) + ], + make_dict [] + |) in + let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ M.get_name (| globals, "receipts_trie" |); @@ -1053,10 +991,15 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_logs := BinOp.add - M.get_name (| globals, "logs" |) - M.get_name (| globals, "logs" |) in - EndFor. + let block_logs := BinOp.add + M.get_name (| globals, "logs" |) + M.get_name (| globals, "logs" |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.call (| M.get_name (| globals, "pay_rewards" |), make_list [ @@ -1185,8 +1128,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "ommer" |), + M.get_name (| globals, "ommers" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ BoolOp.and (| @@ -1205,15 +1152,18 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_parent_header := - M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), BinOp.sub (| - UnOp.sub (| BinOp.sub (| - M.get_field (| M.get_name (| globals, "block_header" |), "number" |), - M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) |), - Constant.int 1 - |) |), "header" |) in - let _ := M.call (| + let ommer_parent_header := + M.get_field (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + BinOp.sub (| + UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) |), + Constant.int 1 + |) + |), "header" |) in + let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ M.get_name (| globals, "ommer" |); @@ -1221,7 +1171,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1271,33 +1226,54 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let recent_canonical_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| BinOp.add (| - M.get_name (| globals, "MAX_OMMER_DEPTH" |), - Constant.int 1 - |) |), Constant.None_ |) |) in + M.slice (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| BinOp.add (| + M.get_name (| globals, "MAX_OMMER_DEPTH" |), + Constant.int 1 + |) |), + Constant.None_, + Constant.None_ + |) in let recent_canonical_block_hashes := Constant.str "(* At expr: unsupported node type: SetComp *)" in (* At stmt: unsupported node type: AnnAssign *) - For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_canonical_blocks" |) do - let recent_ommers_hashes := + let _ := + M.for_ (| + M.get_name (| globals, "block" |), + M.get_name (| globals, "recent_canonical_blocks" |), + ltac:(M.monadic ( + let recent_ommers_hashes := + M.call (| + M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), + make_list [ + Constant.str "(* At expr: unsupported node type: SetComp *)" + ], + make_dict [] + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "ommer_index" |); M.get_name (| globals, "ommer" |) ], M.call (| - M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), - make_list [ - Constant.str "(* At expr: unsupported node type: SetComp *)" - ], - make_dict [] - |) in - EndFor. - For make_tuple [ M.get_name (| globals, "ommer_index" |); M.get_name (| globals, "ommer" |) ] in M.call (| - M.get_name (| globals, "enumerate" |), - make_list [ - M.get_name (| globals, "ommers" |) - ], - make_dict [] - |) do - let ommer_hash := - M.get_subscript (| M.get_name (| globals, "ommers_hashes" |), M.get_name (| globals, "ommer_index" |) |) in - let _ := M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let ommer_hash := + M.get_subscript (| + M.get_name (| globals, "ommers_hashes" |), + M.get_name (| globals, "ommer_index" |) + |) in + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_eq (| @@ -1308,7 +1284,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_in (| @@ -1319,7 +1295,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_in (| @@ -1330,12 +1306,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_age := - BinOp.sub (| - M.get_field (| M.get_name (| globals, "block_header" |), "number" |), - M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) in - let _ := M.call (| + let ommer_age := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) in + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ BoolOp.and (| @@ -1354,10 +1330,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.in (| + Compare.in_ (| M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), M.get_name (| globals, "recent_canonical_block_hashes" |) |); @@ -1365,7 +1341,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_eq (| @@ -1376,7 +1352,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_)). Definition pay_rewards : Value.t -> Value.t -> M := @@ -1433,30 +1414,34 @@ Definition pay_rewards : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do - let ommer_age := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - BinOp.sub (| - M.get_name (| globals, "block_number" |), - M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) - ], - make_dict [] - |) in - let ommer_miner_reward := - BinOp.floor_div (| - BinOp.mult (| - BinOp.sub (| - Constant.int 8, - M.get_name (| globals, "ommer_age" |) - |), - M.get_name (| globals, "BLOCK_REWARD" |) - |), - Constant.int 8 - |) in - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "ommer" |), + M.get_name (| globals, "ommers" |), + ltac:(M.monadic ( + let ommer_age := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "block_number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) + ], + make_dict [] + |) in + let ommer_miner_reward := + BinOp.floor_div (| + BinOp.mult (| + BinOp.sub (| + Constant.int 8, + M.get_name (| globals, "ommer_age" |) + |), + M.get_name (| globals, "BLOCK_REWARD" |) + |), + Constant.int 8 + |) in + let _ := M.call (| M.get_name (| globals, "create_ether" |), make_list [ M.get_name (| globals, "state" |); @@ -1465,7 +1450,12 @@ Definition pay_rewards : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_)). Definition process_transaction : Value.t -> Value.t -> M := @@ -1625,24 +1615,42 @@ Definition process_transaction : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - For make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "keys" |) ] in M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) do - let _ := M.call (| + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "keys" |) ], + M.get_field (| M.get_name (| globals, "tx" |), "access_list" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "preaccessed_addresses" |), "add" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] |) in - For M.get_name (| globals, "key" |) in M.get_name (| globals, "keys" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "keys" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "preaccessed_storage_keys" |), "add" |), make_list [ make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "key" |) ] ], make_dict [] |) in - EndFor. - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1793,8 +1801,12 @@ Definition process_transaction : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "accounts_to_delete" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "output" |), "accounts_to_delete" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "destroy_account" |), make_list [ M.get_field (| M.get_name (| globals, "env" |), "state" |); @@ -1802,22 +1814,31 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. - For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "touched_accounts" |) do - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), - (* then *) + M.pure Constant.None_ + )), ltac:(M.monadic ( - let _ := M.call (| + M.pure Constant.None_ + )) + |) in + let _ := + M.for_ (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "output" |), "touched_accounts" |), + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "destroy_account" |), make_list [ M.get_field (| M.get_name (| globals, "env" |), "state" |); @@ -1825,12 +1846,17 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := M.return_ (| make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |); M.get_field (| M.get_name (| globals, "output" |), "error" |) ] |) in @@ -1918,28 +1944,37 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := " in let data_cost := Constant.int 0 in - For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "byte" |), - Constant.int 0 - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "byte" |), + M.get_field (| M.get_name (| globals, "tx" |), "data" |), ltac:(M.monadic ( - let data_cost := BinOp.add - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "byte" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let data_cost := BinOp.add - M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := (* if *) M.if_then_else (| @@ -1979,12 +2014,16 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - For make_tuple [ M.get_name (| globals, "_address" |); M.get_name (| globals, "keys" |) ] in M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) do - let access_list_cost := BinOp.add - M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) - M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) in - let access_list_cost := BinOp.add - BinOp.mult (| + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "_address" |); M.get_name (| globals, "keys" |) ], + M.get_field (| M.get_name (| globals, "tx" |), "access_list" |), + ltac:(M.monadic ( + let access_list_cost := BinOp.add + M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) + M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) in + let access_list_cost := BinOp.add + BinOp.mult (| M.call (| M.get_name (| globals, "len" |), make_list [ @@ -1994,7 +2033,7 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) |) - BinOp.mult (| + BinOp.mult (| M.call (| M.get_name (| globals, "len" |), make_list [ @@ -2004,7 +2043,12 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -2258,13 +2302,18 @@ Definition recover_sender : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "Address" |), make_list [ - M.get_subscript (| M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "public_key" |) - ], - make_dict [] - |), M.slice (| Constant.int 12, Constant.int 32 |) |) + M.slice (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), + Constant.int 12, + Constant.int 32, + Constant.None_ + |) ], make_dict [] |) diff --git a/CoqOfPython/ethereum/berlin/fork_types.v b/CoqOfPython/ethereum/berlin/fork_types.v index cc8e4a1..d7e9e4d 100644 --- a/CoqOfPython/ethereum/berlin/fork_types.v +++ b/CoqOfPython/ethereum/berlin/fork_types.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.berlin.fork_types". Definition expr_1 : Value.t := Constant.str " @@ -17,33 +17,17 @@ Introduction Types re-used throughout the specification, which are specific to Ethereum. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes20 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes20". -Axiom ethereum_base_types_Bytes256 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes20"; "Bytes256"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) diff --git a/CoqOfPython/ethereum/berlin/state.v b/CoqOfPython/ethereum/berlin/state.v index 84f6db5..ce7be41 100644 --- a/CoqOfPython/ethereum/berlin/state.v +++ b/CoqOfPython/ethereum/berlin/state.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.berlin.state". Definition expr_1 : Value.t := Constant.str " @@ -22,63 +22,23 @@ There is a distinction between an account that does not exist and `EMPTY_ACCOUNT`. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". -Axiom dataclasses_field : - IsGlobalAlias globals dataclasses.globals "field". - -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_modify : - IsGlobalAlias globals ethereum.base_types.globals "modify". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.berlin.fork_types. -Axiom ethereum_berlin_fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals ethereum.berlin.fork_types.globals "EMPTY_ACCOUNT". -Axiom ethereum_berlin_fork_types_Account : - IsGlobalAlias globals ethereum.berlin.fork_types.globals "Account". -Axiom ethereum_berlin_fork_types_Address : - IsGlobalAlias globals ethereum.berlin.fork_types.globals "Address". -Axiom ethereum_berlin_fork_types_Root : - IsGlobalAlias globals ethereum.berlin.fork_types.globals "Root". - -Require ethereum.berlin.trie. -Axiom ethereum_berlin_trie_EMPTY_TRIE_ROOT : - IsGlobalAlias globals ethereum.berlin.trie.globals "EMPTY_TRIE_ROOT". -Axiom ethereum_berlin_trie_Trie : - IsGlobalAlias globals ethereum.berlin.trie.globals "Trie". -Axiom ethereum_berlin_trie_copy_trie : - IsGlobalAlias globals ethereum.berlin.trie.globals "copy_trie". -Axiom ethereum_berlin_trie_root : - IsGlobalAlias globals ethereum.berlin.trie.globals "root". -Axiom ethereum_berlin_trie_trie_get : - IsGlobalAlias globals ethereum.berlin.trie.globals "trie_get". -Axiom ethereum_berlin_trie_trie_set : - IsGlobalAlias globals ethereum.berlin.trie.globals "trie_set". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass"; "field" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict"; "List"; "Optional"; "Set"; "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "modify" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_berlin_fork_types_imports : + AreImported globals "ethereum.berlin.fork_types" [ "EMPTY_ACCOUNT"; "Account"; "Address"; "Root" ]. + +Axiom ethereum_berlin_trie_imports : + AreImported globals "ethereum.berlin.trie" [ "EMPTY_TRIE_ROOT"; "Trie"; "copy_trie"; "root"; "trie_get"; "trie_set" ]. Definition State : Value.t := builtins.make_klass @@ -373,13 +333,16 @@ Definition destroy_storage : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -542,7 +505,10 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), + M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |), M.get_name (| globals, "trie" |) |) in M.pure Constant.None_ @@ -568,7 +534,10 @@ Definition set_storage : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -598,7 +567,7 @@ Definition storage_root : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), @@ -608,7 +577,10 @@ Definition storage_root : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "root" |), make_list [ - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) + M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |) ], make_dict [] |) @@ -1167,7 +1139,7 @@ Definition get_storage_original : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |) |), @@ -1189,7 +1161,10 @@ Definition get_storage_original : Value.t -> Value.t -> M := )) |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "_" |); M.get_name (| globals, "original_trie" |) ], - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), Constant.int 0 |) + M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), + Constant.int 0 + |) |) in let original_account_trie := M.call (| diff --git a/CoqOfPython/ethereum/berlin/transactions.v b/CoqOfPython/ethereum/berlin/transactions.v index a5e38fa..3671146 100644 --- a/CoqOfPython/ethereum/berlin/transactions.v +++ b/CoqOfPython/ethereum/berlin/transactions.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.berlin.transactions". Definition expr_1 : Value.t := Constant.str " @@ -9,47 +9,26 @@ submitted to be executed. If Ethereum is viewed as a state machine, transactions are the events that move between states. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U64 : - IsGlobalAlias globals ethereum.base_types.globals "U64". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.exceptions. -Axiom ethereum_exceptions_InvalidBlock : - IsGlobalAlias globals ethereum.exceptions.globals "InvalidBlock". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.berlin.fork_types. -Axiom ethereum_berlin_fork_types_Address : - IsGlobalAlias globals ethereum.berlin.fork_types.globals "Address". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Tuple"; "Union" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U64"; "U256"; "Bytes"; "Bytes0"; "Bytes32"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_exceptions_imports : + AreImported globals "ethereum.exceptions" [ "InvalidBlock" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_berlin_fork_types_imports : + AreImported globals "ethereum.berlin.fork_types" [ "Address" ]. Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( Constant.int 21000 @@ -96,7 +75,10 @@ Definition AccessListTransaction : Value.t := ]. Definition Transaction : Value.t := M.run ltac:(M.monadic ( - M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "AccessListTransaction" |) ] |) + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "AccessListTransaction" |) ] + |) )). Definition encode_transaction : Value.t -> Value.t -> M := @@ -152,7 +134,7 @@ Definition encode_transaction : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "Exception" |), make_list [ Constant.str "(* At expr: unsupported node type: JoinedStr *)" @@ -188,7 +170,10 @@ Definition decode_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "ensure" |), make_list [ Compare.eq (| - M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), + M.get_subscript (| + M.get_name (| globals, "tx" |), + Constant.int 0 + |), Constant.int 1 |); M.get_name (| globals, "InvalidBlock" |) @@ -200,7 +185,12 @@ Definition decode_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), make_list [ M.get_name (| globals, "AccessListTransaction" |); - M.get_subscript (| M.get_name (| globals, "tx" |), M.slice (| Constant.int 1, Constant.None_ |) |) + M.slice (| + M.get_name (| globals, "tx" |), + Constant.int 1, + Constant.None_, + Constant.None_ + |) ], make_dict [] |) diff --git a/CoqOfPython/ethereum/berlin/trie.v b/CoqOfPython/ethereum/berlin/trie.v index 8a3cc9d..55618f0 100644 --- a/CoqOfPython/ethereum/berlin/trie.v +++ b/CoqOfPython/ethereum/berlin/trie.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.berlin.trie". Definition expr_1 : Value.t := Constant.str " @@ -20,83 +20,38 @@ The state trie is the structure responsible for storing (* At top_level_stmt: unsupported node type: Import *) -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". -Axiom dataclasses_field : - IsGlobalAlias globals dataclasses.globals "field". - -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". -Axiom typing_Generic : - IsGlobalAlias globals typing.globals "Generic". -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Mapping : - IsGlobalAlias globals typing.globals "Mapping". -Axiom typing_MutableMapping : - IsGlobalAlias globals typing.globals "MutableMapping". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Sequence : - IsGlobalAlias globals typing.globals "Sequence". -Axiom typing_TypeVar : - IsGlobalAlias globals typing.globals "TypeVar". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". -Axiom typing_cast : - IsGlobalAlias globals typing.globals "cast". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.muir_glacier.__init__. -Axiom ethereum_muir_glacier___init___trie : - IsGlobalAlias globals ethereum.muir_glacier.__init__.globals "trie". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.utils.hexadecimal. -Axiom ethereum_utils_hexadecimal_hex_to_bytes : - IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.berlin.blocks. -Axiom ethereum_berlin_blocks_Receipt : - IsGlobalAlias globals ethereum.berlin.blocks.globals "Receipt". - -Require ethereum.berlin.fork_types. -Axiom ethereum_berlin_fork_types_Account : - IsGlobalAlias globals ethereum.berlin.fork_types.globals "Account". -Axiom ethereum_berlin_fork_types_Address : - IsGlobalAlias globals ethereum.berlin.fork_types.globals "Address". -Axiom ethereum_berlin_fork_types_Root : - IsGlobalAlias globals ethereum.berlin.fork_types.globals "Root". -Axiom ethereum_berlin_fork_types_encode_account : - IsGlobalAlias globals ethereum.berlin.fork_types.globals "encode_account". - -Require ethereum.berlin.transactions. -Axiom ethereum_berlin_transactions_LegacyTransaction : - IsGlobalAlias globals ethereum.berlin.transactions.globals "LegacyTransaction". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass"; "field" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict"; "Generic"; "List"; "Mapping"; "MutableMapping"; "Optional"; "Sequence"; "TypeVar"; "Union"; "cast" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. + +Axiom ethereum_muir_glacier_imports : + AreImported globals "ethereum.muir_glacier" [ "trie" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_utils_hexadecimal_imports : + AreImported globals "ethereum.utils.hexadecimal" [ "hex_to_bytes" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_berlin_blocks_imports : + AreImported globals "ethereum.berlin.blocks" [ "Receipt" ]. + +Axiom ethereum_berlin_fork_types_imports : + AreImported globals "ethereum.berlin.fork_types" [ "Account"; "Address"; "Root"; "encode_account" ]. + +Axiom ethereum_berlin_transactions_imports : + AreImported globals "ethereum.berlin.transactions" [ "LegacyTransaction" ]. Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -115,7 +70,10 @@ Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( )). Definition Node : Value.t := M.run ltac:(M.monadic ( - M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Bytes" |); M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |); Constant.None_ ] |) + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Bytes" |); M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |); Constant.None_ ] + |) )). Definition K : Value.t := M.run ltac:(M.monadic ( @@ -133,11 +91,29 @@ Definition V : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "TypeVar" |), make_list [ Constant.str "V"; - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Account" |) |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Bytes" |) |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Account" |) + |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Bytes" |) + |); M.get_name (| globals, "Bytes" |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Bytes" |) ] |) |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Bytes" |) ] |) |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Bytes" |) ] + |) + |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Bytes" |) ] + |) + |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |) ], @@ -176,7 +152,10 @@ Definition BranchNode : Value.t := ]. Definition InternalNode : Value.t := M.run ltac:(M.monadic ( - M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LeafNode" |); M.get_name (| globals, "ExtensionNode" |); M.get_name (| globals, "BranchNode" |) ] |) + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "LeafNode" |); M.get_name (| globals, "ExtensionNode" |); M.get_name (| globals, "BranchNode" |) ] + |) )). Definition encode_internal_node : Value.t -> Value.t -> M := @@ -288,7 +267,7 @@ Definition encode_internal_node : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "(* At expr: unsupported node type: JoinedStr *)" @@ -528,13 +507,16 @@ Definition trie_set : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "key" |), M.get_field (| M.get_name (| globals, "trie" |), "_data" |) |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + M.get_name (| globals, "key" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -544,7 +526,10 @@ Definition trie_set : Value.t -> Value.t -> M := (* else *) )), ltac:(M.monadic ( let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), + M.get_subscript (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + M.get_name (| globals, "key" |) + |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_ @@ -589,51 +574,66 @@ Definition common_prefix_length : Value.t -> Value.t -> M := let _ := Constant.str " Find the longest common prefix of two sequences. " in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "a" |) - ], - make_dict [] - |) - ], - make_dict [] - |) do - let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| - M.get_name (| globals, "i" |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "b" |) - ], - make_dict [] - |) - |), - ltac:(M.monadic ( - Compare.not_eq (| - M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), - M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) - |) - )) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + ], + make_dict [] + |), ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "i" |) - |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_subscript (| + M.get_name (| globals, "a" |), + M.get_name (| globals, "i" |) + |), + M.get_subscript (| + M.get_name (| globals, "b" |), + M.get_name (| globals, "i" |) + |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "len" |), @@ -718,38 +718,53 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 0; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |); - Constant.int 2 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ BinOp.add (| BinOp.mult (| Constant.int 16, - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "i" |) + |) |), - M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) + |) |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -767,43 +782,61 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := Constant.int 1 |) |), - M.get_subscript (| M.get_name (| globals, "x" |), Constant.int 0 |) + M.get_subscript (| + M.get_name (| globals, "x" |), + Constant.int 0 + |) |) ], make_dict [] |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 1; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |); - Constant.int 2 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 1; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ BinOp.add (| BinOp.mult (| Constant.int 16, - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "i" |) + |) |), - M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) + |) |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -850,40 +883,55 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := ], make_dict [] |) in - For make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ] in M.call (| - M.get_name (| globals, "enumerate" |), - make_list [ - M.get_name (| globals, "bytes_" |) - ], - make_dict [] - |) do - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.mult (| - M.get_name (| globals, "byte_index" |), - Constant.int 2 - |) |), - BinOp.r_shift (| - BinOp.bit_and (| - M.get_name (| globals, "byte" |), - Constant.int 240 - |), - Constant.int 4 - |) - |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "byte_index" |), - Constant.int 2 - |), - Constant.int 1 - |) |), - BinOp.bit_and (| - M.get_name (| globals, "byte" |), - Constant.int 15 - |) - |) in - EndFor. + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ], + M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "bytes_" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "nibble_list" |), + BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |) + |), + BinOp.r_shift (| + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 240 + |), + Constant.int 4 + |) + |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "nibble_list" |), + BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |), + Constant.int 1 + |) + |), + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 15 + |) + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Bytes" |), @@ -916,65 +964,69 @@ Definition _prepare_trie : Value.t -> Value.t -> M := Object with keys mapped to nibble-byte form. " in (* At stmt: unsupported node type: AnnAssign *) - For make_tuple [ M.get_name (| globals, "preimage" |); M.get_name (| globals, "value" |) ] in M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "items" |), - make_list [], - make_dict [] - |) do - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "value" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "preimage" |); M.get_name (| globals, "value" |) ], + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "items" |), + make_list [], + make_dict [] + |), ltac:(M.monadic ( - let _ := M.assert (| Compare.is_not (| + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in - let address := - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in - let encoded_value := - M.call (| - M.get_name (| globals, "encode_node" |), - make_list [ - M.get_name (| globals, "value" |); + let address := M.call (| - M.get_name (| globals, "get_storage_root" |), + M.get_name (| globals, "Address" |), make_list [ - M.get_name (| globals, "address" |) + M.get_name (| globals, "preimage" |) ], make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let encoded_value := - M.call (| - M.get_name (| globals, "encode_node" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - )) |) in - let _ := M.call (| + |) in + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |); + M.call (| + M.get_name (| globals, "get_storage_root" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_eq (| @@ -986,38 +1038,46 @@ Definition _prepare_trie : Value.t -> Value.t -> M := make_dict [] |) in (* At stmt: unsupported node type: AnnAssign *) - let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "trie" |), "secured" |), - (* then *) - ltac:(M.monadic ( - let key := - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "trie" |), "secured" |), + (* then *) + ltac:(M.monadic ( + let key := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let key := + M.get_name (| globals, "preimage" |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "mapped" |), + M.call (| + M.get_name (| globals, "bytes_to_nibble_list" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |) + |), + M.get_name (| globals, "encoded_value" |) + |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let key := - M.get_name (| globals, "preimage" |) in + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "mapped" |), M.call (| - M.get_name (| globals, "bytes_to_nibble_list" |), - make_list [ - M.get_name (| globals, "key" |) - ], - make_dict [] - |) |), - M.get_name (| globals, "encoded_value" |) - |) in - EndFor. + )) + |) in let _ := M.return_ (| M.get_name (| globals, "mapped" |) |) in @@ -1210,8 +1270,16 @@ Definition patricialize : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "LeafNode" |), make_list [ - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |); - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) + M.slice (| + M.get_name (| globals, "arbitrary_key" |), + M.get_name (| globals, "level" |), + Constant.None_, + Constant.None_ + |); + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "arbitrary_key" |) + |) ], make_dict [] |) in @@ -1224,7 +1292,12 @@ Definition patricialize : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in let substring := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "arbitrary_key" |), + M.get_name (| globals, "level" |), + Constant.None_, + Constant.None_ + |) in let prefix_length := M.call (| M.get_name (| globals, "len" |), @@ -1233,39 +1306,53 @@ Definition patricialize : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do - let prefix_length := - M.call (| - M.get_name (| globals, "min" |), - make_list [ - M.get_name (| globals, "prefix_length" |); + let _ := + M.for_ (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "obj" |), + ltac:(M.monadic ( + let prefix_length := M.call (| - M.get_name (| globals, "common_prefix_length" |), + M.get_name (| globals, "min" |), make_list [ - M.get_name (| globals, "substring" |); - M.get_subscript (| M.get_name (| globals, "key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) + M.get_name (| globals, "prefix_length" |); + M.call (| + M.get_name (| globals, "common_prefix_length" |), + make_list [ + M.get_name (| globals, "substring" |); + M.slice (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "level" |), + Constant.None_, + Constant.None_ + |) + ], + make_dict [] + |) ], make_dict [] - |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "prefix_length" |), - Constant.int 0 - |), - (* then *) - ltac:(M.monadic ( - let _ := M.break (| |) in + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "prefix_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := (* if *) M.if_then_else (| @@ -1276,10 +1363,15 @@ Definition patricialize : Value.t -> Value.t -> M := (* then *) ltac:(M.monadic ( let prefix := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), BinOp.add (| + M.slice (| + M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |), - M.get_name (| globals, "prefix_length" |) - |) |) |) in + BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |), + Constant.None_ + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ExtensionNode" |), @@ -1312,70 +1404,106 @@ Definition patricialize : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) - For M.get_name (| globals, "_" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 16 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "_" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 16 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "branches" |), "append" |), make_list [ {} ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let value := Constant.bytes "" in - For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "key" |) - ], - make_dict [] - |), - M.get_name (| globals, "level" |) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "obj" |), ltac:(M.monadic ( let _ := (* if *) M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); - make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] - ], - make_dict [] + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |), + M.get_name (| globals, "level" |) |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "AssertionError" |)) |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "key" |) + |); + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "AssertionError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "key" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| + M.get_subscript (| + M.get_name (| globals, "branches" |), + M.get_subscript (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "level" |) + |) + |), + M.get_name (| globals, "key" |) + |), + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "key" |) + |) + |) in M.pure Constant.None_ )) |) in - let value := - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.assign (| - M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) - |) in + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "BranchNode" |), diff --git a/CoqOfPython/ethereum/berlin/utils/__init__.v b/CoqOfPython/ethereum/berlin/utils/__init__.v index 1baedea..0c0263a 100644 --- a/CoqOfPython/ethereum/berlin/utils/__init__.v +++ b/CoqOfPython/ethereum/berlin/utils/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.berlin.utils.__init__". Definition expr_1 : Value.t := Constant.str " diff --git a/CoqOfPython/ethereum/berlin/utils/address.v b/CoqOfPython/ethereum/berlin/utils/address.v index 5bfce50..d42cde7 100644 --- a/CoqOfPython/ethereum/berlin/utils/address.v +++ b/CoqOfPython/ethereum/berlin/utils/address.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.berlin.utils.address". Definition expr_1 : Value.t := Constant.str " @@ -18,33 +18,23 @@ Address specific functions used in this berlin version of specification. ". -Require typing. -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". +Axiom typing_imports : + AreImported globals "typing" [ "Union" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes32"; "Uint" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_left_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. -Require ethereum.berlin.fork_types. -Axiom ethereum_berlin_fork_types_Address : - IsGlobalAlias globals ethereum.berlin.fork_types.globals "Address". +Axiom ethereum_berlin_fork_types_imports : + AreImported globals "ethereum.berlin.fork_types" [ "Address" ]. Definition to_address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -66,11 +56,16 @@ Definition to_address : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "Address" |), make_list [ - M.get_subscript (| M.call (| - M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), - make_list [], - make_dict [] - |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) + M.slice (| + M.call (| + M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), + UnOp.sub (| Constant.int 20 |), + Constant.None_, + Constant.None_ + |) ], make_dict [] |) @@ -114,7 +109,12 @@ Definition compute_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "computed_address" |), + UnOp.sub (| Constant.int 20 |), + Constant.None_, + Constant.None_ + |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -182,7 +182,12 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "computed_address" |), + UnOp.sub (| Constant.int 20 |), + Constant.None_, + Constant.None_ + |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/berlin/utils/hexadecimal.v b/CoqOfPython/ethereum/berlin/utils/hexadecimal.v index 0394245..b713703 100644 --- a/CoqOfPython/ethereum/berlin/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/berlin/utils/hexadecimal.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.berlin.utils.hexadecimal". Definition expr_1 : Value.t := Constant.str " @@ -18,17 +18,11 @@ Hexadecimal utility functions used in this specification, specific to Berlin types. ". -Require ethereum.utils.hexadecimal. -Axiom ethereum_utils_hexadecimal_remove_hex_prefix : - IsGlobalAlias globals ethereum.utils.hexadecimal.globals "remove_hex_prefix". - -Require ethereum.berlin.fork_types. -Axiom ethereum_berlin_fork_types_Address : - IsGlobalAlias globals ethereum.berlin.fork_types.globals "Address". -Axiom ethereum_berlin_fork_types_Bloom : - IsGlobalAlias globals ethereum.berlin.fork_types.globals "Bloom". -Axiom ethereum_berlin_fork_types_Root : - IsGlobalAlias globals ethereum.berlin.fork_types.globals "Root". +Axiom ethereum_utils_hexadecimal_imports : + AreImported globals "ethereum.utils.hexadecimal" [ "remove_hex_prefix" ]. + +Axiom ethereum_berlin_fork_types_imports : + AreImported globals "ethereum.berlin.fork_types" [ "Address"; "Bloom"; "Root" ]. Definition hex_to_root : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/berlin/utils/message.v b/CoqOfPython/ethereum/berlin/utils/message.v index 7ae8e81..44ab863 100644 --- a/CoqOfPython/ethereum/berlin/utils/message.v +++ b/CoqOfPython/ethereum/berlin/utils/message.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.berlin.utils.message". Definition expr_1 : Value.t := Constant.str " @@ -18,49 +18,26 @@ Message specific functions used in this berlin version of specification. ". -Require typing. -Axiom typing_FrozenSet : - IsGlobalAlias globals typing.globals "FrozenSet". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". +Axiom typing_imports : + AreImported globals "typing" [ "FrozenSet"; "Optional"; "Tuple"; "Union" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Bytes32"; "Uint" ]. -Require ethereum.berlin.fork_types. -Axiom ethereum_berlin_fork_types_Address : - IsGlobalAlias globals ethereum.berlin.fork_types.globals "Address". +Axiom ethereum_berlin_fork_types_imports : + AreImported globals "ethereum.berlin.fork_types" [ "Address" ]. -Require ethereum.berlin.state. -Axiom ethereum_berlin_state_get_account : - IsGlobalAlias globals ethereum.berlin.state.globals "get_account". +Axiom ethereum_berlin_state_imports : + AreImported globals "ethereum.berlin.state" [ "get_account" ]. -Require ethereum.berlin.vm.__init__. -Axiom ethereum_berlin_vm___init___Environment : - IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Environment". -Axiom ethereum_berlin_vm___init___Message : - IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Message". +Axiom ethereum_berlin_vm_imports : + AreImported globals "ethereum.berlin.vm" [ "Environment"; "Message" ]. -Require ethereum.berlin.vm.precompiled_contracts.mapping. -Axiom ethereum_berlin_vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : - IsGlobalAlias globals ethereum.berlin.vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". +Axiom ethereum_berlin_vm_precompiled_contracts_mapping_imports : + AreImported globals "ethereum.berlin.vm.precompiled_contracts.mapping" [ "PRE_COMPILED_CONTRACTS" ]. -Require ethereum.berlin.utils.address. -Axiom ethereum_berlin_utils_address_compute_contract_address : - IsGlobalAlias globals ethereum.berlin.utils.address.globals "compute_contract_address". +Axiom ethereum_berlin_utils_address_imports : + AreImported globals "ethereum.berlin.utils.address" [ "compute_contract_address" ]. Definition prepare_message : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -198,7 +175,7 @@ Definition prepare_message : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "Target must be address or empty bytes" diff --git a/CoqOfPython/ethereum/berlin/vm/__init__.v b/CoqOfPython/ethereum/berlin/vm/__init__.v index 28ae436..a846849 100644 --- a/CoqOfPython/ethereum/berlin/vm/__init__.v +++ b/CoqOfPython/ethereum/berlin/vm/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.berlin.vm.__init__". Definition expr_1 : Value.t := Constant.str " @@ -18,57 +18,29 @@ The abstract computer which runs the code stored in an `.fork_types.Account`. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple"; "Union" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U64 : - IsGlobalAlias globals ethereum.base_types.globals "U64". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U64"; "U256"; "Bytes"; "Bytes0"; "Bytes32"; "Uint" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. -Require ethereum.berlin.blocks. -Axiom ethereum_berlin_blocks_Log : - IsGlobalAlias globals ethereum.berlin.blocks.globals "Log". +Axiom ethereum_berlin_blocks_imports : + AreImported globals "ethereum.berlin.blocks" [ "Log" ]. -Require ethereum.berlin.fork_types. -Axiom ethereum_berlin_fork_types_Address : - IsGlobalAlias globals ethereum.berlin.fork_types.globals "Address". +Axiom ethereum_berlin_fork_types_imports : + AreImported globals "ethereum.berlin.fork_types" [ "Address" ]. -Require ethereum.berlin.state. -Axiom ethereum_berlin_state_State : - IsGlobalAlias globals ethereum.berlin.state.globals "State". -Axiom ethereum_berlin_state_account_exists_and_is_empty : - IsGlobalAlias globals ethereum.berlin.state.globals "account_exists_and_is_empty". +Axiom ethereum_berlin_state_imports : + AreImported globals "ethereum.berlin.state" [ "State"; "account_exists_and_is_empty" ]. -Require ethereum.berlin.vm.precompiled_contracts.__init__. -Axiom ethereum_berlin_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : - IsGlobalAlias globals ethereum.berlin.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". +Axiom ethereum_berlin_vm_precompiled_contracts_imports : + AreImported globals "ethereum.berlin.vm.precompiled_contracts" [ "RIPEMD160_ADDRESS" ]. Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] @@ -203,7 +175,7 @@ Definition incorporate_child_on_error : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "RIPEMD160_ADDRESS" |), M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) |), diff --git a/CoqOfPython/ethereum/berlin/vm/exceptions.v b/CoqOfPython/ethereum/berlin/vm/exceptions.v index 8560cef..63d8cdd 100644 --- a/CoqOfPython/ethereum/berlin/vm/exceptions.v +++ b/CoqOfPython/ethereum/berlin/vm/exceptions.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.berlin.vm.exceptions". Definition expr_1 : Value.t := Constant.str " @@ -17,9 +17,8 @@ Introduction Exceptions which cause the EVM to halt exceptionally. ". -Require ethereum.exceptions. -Axiom ethereum_exceptions_EthereumException : - IsGlobalAlias globals ethereum.exceptions.globals "EthereumException". +Axiom ethereum_exceptions_imports : + AreImported globals "ethereum.exceptions" [ "EthereumException" ]. Definition ExceptionalHalt : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/berlin/vm/gas.v b/CoqOfPython/ethereum/berlin/vm/gas.v index de7b9ff..bbc5275 100644 --- a/CoqOfPython/ethereum/berlin/vm/gas.v +++ b/CoqOfPython/ethereum/berlin/vm/gas.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.berlin.vm.gas". Definition expr_1 : Value.t := Constant.str " @@ -17,39 +17,26 @@ Introduction EVM gas constants and calculators. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Tuple" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. -Require ethereum.trace. -Axiom ethereum_trace_GasAndRefund : - IsGlobalAlias globals ethereum.trace.globals "GasAndRefund". -Axiom ethereum_trace_evm_trace : - IsGlobalAlias globals ethereum.trace.globals "evm_trace". +Axiom ethereum_trace_imports : + AreImported globals "ethereum.trace" [ "GasAndRefund"; "evm_trace" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.berlin.vm.__init__. -Axiom ethereum_berlin_vm___init___Evm : - IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Evm". +Axiom ethereum_berlin_vm_imports : + AreImported globals "ethereum.berlin.vm" [ "Evm" ]. -Require ethereum.berlin.vm.exceptions. -Axiom ethereum_berlin_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.berlin.vm.exceptions.globals "OutOfGasError". +Axiom ethereum_berlin_vm_exceptions_imports : + AreImported globals "ethereum.berlin.vm.exceptions" [ "OutOfGasError" ]. Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -518,7 +505,7 @@ Definition charge_gas : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -635,105 +622,114 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := ], make_dict [] |) in - For make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ] in M.get_name (| globals, "extensions" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "size" |), - Constant.int 0 - |), - (* then *) + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ], + M.get_name (| globals, "extensions" |), ltac:(M.monadic ( - let _ := M.continue (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let before_size := - M.call (| - M.get_name (| globals, "ceil32" |), - make_list [ - M.get_name (| globals, "current_size" |) - ], - make_dict [] - |) in - let after_size := - M.call (| - M.get_name (| globals, "ceil32" |), - make_list [ - BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "size" |), + Constant.int 0 |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.lt_e (| - M.get_name (| globals, "after_size" |), - M.get_name (| globals, "before_size" |) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.continue (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let size_to_extend := BinOp.add - BinOp.sub (| + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let before_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "current_size" |) + ], + make_dict [] + |) in + let after_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let size_to_extend := BinOp.add + BinOp.sub (| M.get_name (| globals, "after_size" |), M.get_name (| globals, "before_size" |) |) - BinOp.sub (| + BinOp.sub (| M.get_name (| globals, "after_size" |), M.get_name (| globals, "before_size" |) |) in - let already_paid := - M.call (| - M.get_name (| globals, "calculate_memory_gas_cost" |), - make_list [ - M.get_name (| globals, "before_size" |) - ], - make_dict [] - |) in - let total_cost := - M.call (| - M.get_name (| globals, "calculate_memory_gas_cost" |), - make_list [ - M.get_name (| globals, "after_size" |) - ], - make_dict [] - |) in - let to_be_paid := BinOp.add - BinOp.sub (| + let already_paid := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "before_size" |) + ], + make_dict [] + |) in + let total_cost := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "after_size" |) + ], + make_dict [] + |) in + let to_be_paid := BinOp.add + BinOp.sub (| M.get_name (| globals, "total_cost" |), M.get_name (| globals, "already_paid" |) |) - BinOp.sub (| + BinOp.sub (| M.get_name (| globals, "total_cost" |), M.get_name (| globals, "already_paid" |) |) in - let current_size := - M.get_name (| globals, "after_size" |) in - EndFor. + let current_size := + M.get_name (| globals, "after_size" |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ExtendMemory" |), diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/__init__.v b/CoqOfPython/ethereum/berlin/vm/instructions/__init__.v index e872151..c077623 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/__init__.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.berlin.vm.instructions.__init__". Definition expr_1 : Value.t := Constant.str " @@ -20,59 +20,44 @@ implementations. (* At top_level_stmt: unsupported node type: Import *) -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict" ]. -Require ethereum.berlin.vm.instructions.__init__. -Axiom ethereum_berlin_vm_instructions___init___arithmetic : - IsGlobalAlias globals ethereum.berlin.vm.instructions.__init__.globals "arithmetic". +Axiom ethereum_berlin_vm_instructions_imports : + AreImported globals "ethereum.berlin.vm.instructions" [ "arithmetic" ]. -Require ethereum.berlin.vm.instructions.__init__. -Axiom ethereum_berlin_vm_instructions___init___bitwise : - IsGlobalAlias globals ethereum.berlin.vm.instructions.__init__.globals "bitwise". +Axiom ethereum_berlin_vm_instructions_imports : + AreImported globals "ethereum.berlin.vm.instructions" [ "bitwise" ]. -Require ethereum.berlin.vm.instructions.__init__. -Axiom ethereum_berlin_vm_instructions___init___block : - IsGlobalAlias globals ethereum.berlin.vm.instructions.__init__.globals "block". +Axiom ethereum_berlin_vm_instructions_imports : + AreImported globals "ethereum.berlin.vm.instructions" [ "block" ]. -Require ethereum.berlin.vm.instructions.__init__. -Axiom ethereum_berlin_vm_instructions___init___comparison : - IsGlobalAlias globals ethereum.berlin.vm.instructions.__init__.globals "comparison". +Axiom ethereum_berlin_vm_instructions_imports : + AreImported globals "ethereum.berlin.vm.instructions" [ "comparison" ]. -Require ethereum.berlin.vm.instructions.__init__. -Axiom ethereum_berlin_vm_instructions___init___control_flow : - IsGlobalAlias globals ethereum.berlin.vm.instructions.__init__.globals "control_flow". +Axiom ethereum_berlin_vm_instructions_imports : + AreImported globals "ethereum.berlin.vm.instructions" [ "control_flow" ]. -Require ethereum.berlin.vm.instructions.__init__. -Axiom ethereum_berlin_vm_instructions___init___environment : - IsGlobalAlias globals ethereum.berlin.vm.instructions.__init__.globals "environment". +Axiom ethereum_berlin_vm_instructions_imports : + AreImported globals "ethereum.berlin.vm.instructions" [ "environment" ]. -Require ethereum.berlin.vm.instructions.__init__. -Axiom ethereum_berlin_vm_instructions___init___keccak : - IsGlobalAlias globals ethereum.berlin.vm.instructions.__init__.globals "keccak". +Axiom ethereum_berlin_vm_instructions_imports : + AreImported globals "ethereum.berlin.vm.instructions" [ "keccak" ]. -Require ethereum.berlin.vm.instructions.__init__. -Axiom ethereum_berlin_vm_instructions___init___log : - IsGlobalAlias globals ethereum.berlin.vm.instructions.__init__.globals "log". +Axiom ethereum_berlin_vm_instructions_imports : + AreImported globals "ethereum.berlin.vm.instructions" [ "log" ]. -Require ethereum.berlin.vm.instructions.__init__. -Axiom ethereum_berlin_vm_instructions___init___memory : - IsGlobalAlias globals ethereum.berlin.vm.instructions.__init__.globals "memory". +Axiom ethereum_berlin_vm_instructions_imports : + AreImported globals "ethereum.berlin.vm.instructions" [ "memory" ]. -Require ethereum.berlin.vm.instructions.__init__. -Axiom ethereum_berlin_vm_instructions___init___stack : - IsGlobalAlias globals ethereum.berlin.vm.instructions.__init__.globals "stack". +Axiom ethereum_berlin_vm_instructions_imports : + AreImported globals "ethereum.berlin.vm.instructions" [ "stack" ]. -Require ethereum.berlin.vm.instructions.__init__. -Axiom ethereum_berlin_vm_instructions___init___storage : - IsGlobalAlias globals ethereum.berlin.vm.instructions.__init__.globals "storage". +Axiom ethereum_berlin_vm_instructions_imports : + AreImported globals "ethereum.berlin.vm.instructions" [ "storage" ]. -Require ethereum.berlin.vm.instructions.__init__. -Axiom ethereum_berlin_vm_instructions___init___system : - IsGlobalAlias globals ethereum.berlin.vm.instructions.__init__.globals "system". +Axiom ethereum_berlin_vm_instructions_imports : + AreImported globals "ethereum.berlin.vm.instructions" [ "system" ]. Definition Ops : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/berlin/vm/instructions/arithmetic.v index b798ec7..25123e3 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/arithmetic.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.berlin.vm.instructions.arithmetic". Definition expr_1 : Value.t := Constant.str " @@ -17,43 +17,20 @@ Introduction Implementations of the EVM Arithmetic instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U255_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U255_CEIL_VALUE". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_U256_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U255_CEIL_VALUE"; "U256"; "U256_CEIL_VALUE"; "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_get_sign : - IsGlobalAlias globals ethereum.utils.numeric.globals "get_sign". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "get_sign" ]. -Require ethereum.berlin.vm.__init__. -Axiom ethereum_berlin_vm___init___Evm : - IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Evm". +Axiom ethereum_berlin_vm_imports : + AreImported globals "ethereum.berlin.vm" [ "Evm" ]. -Require ethereum.berlin.vm.gas. -Axiom ethereum_berlin_vm_gas_GAS_EXPONENTIATION : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_EXPONENTIATION". -Axiom ethereum_berlin_vm_gas_GAS_EXPONENTIATION_PER_BYTE : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_EXPONENTIATION_PER_BYTE". -Axiom ethereum_berlin_vm_gas_GAS_LOW : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_LOW". -Axiom ethereum_berlin_vm_gas_GAS_MID : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_MID". -Axiom ethereum_berlin_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_berlin_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "charge_gas". +Axiom ethereum_berlin_vm_gas_imports : + AreImported globals "ethereum.berlin.vm.gas" [ "GAS_EXPONENTIATION"; "GAS_EXPONENTIATION_PER_BYTE"; "GAS_LOW"; "GAS_MID"; "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.berlin.vm.stack. -Axiom ethereum_berlin_vm_stack_pop : - IsGlobalAlias globals ethereum.berlin.vm.stack.globals "pop". -Axiom ethereum_berlin_vm_stack_push : - IsGlobalAlias globals ethereum.berlin.vm.stack.globals "push". +Axiom ethereum_berlin_vm_stack_imports : + AreImported globals "ethereum.berlin.vm.stack" [ "pop"; "push" ]. Definition add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -1030,19 +1007,27 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let value_bytes := - M.get_subscript (| M.get_name (| globals, "value_bytes" |), M.slice (| BinOp.sub (| - Constant.int 31, - M.call (| - M.get_name (| globals, "int" |), - make_list [ - M.get_name (| globals, "byte_num" |) - ], - make_dict [] - |) - |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "value_bytes" |), + BinOp.sub (| + Constant.int 31, + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "byte_num" |) + ], + make_dict [] + |) + |), + Constant.None_, + Constant.None_ + |) in let sign_bit := BinOp.r_shift (| - M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), + M.get_subscript (| + M.get_name (| globals, "value_bytes" |), + Constant.int 0 + |), Constant.int 7 |) in let _ := diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/bitwise.v b/CoqOfPython/ethereum/berlin/vm/instructions/bitwise.v index ce34236..01a7c3e 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/bitwise.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.berlin.vm.instructions.bitwise". Definition expr_1 : Value.t := Constant.str " @@ -17,27 +17,17 @@ Introduction Implementations of the EVM bitwise instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_U256_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "U256_CEIL_VALUE" ]. -Require ethereum.berlin.vm.__init__. -Axiom ethereum_berlin_vm___init___Evm : - IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Evm". +Axiom ethereum_berlin_vm_imports : + AreImported globals "ethereum.berlin.vm" [ "Evm" ]. -Require ethereum.berlin.vm.gas. -Axiom ethereum_berlin_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_berlin_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "charge_gas". +Axiom ethereum_berlin_vm_gas_imports : + AreImported globals "ethereum.berlin.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.berlin.vm.stack. -Axiom ethereum_berlin_vm_stack_pop : - IsGlobalAlias globals ethereum.berlin.vm.stack.globals "pop". -Axiom ethereum_berlin_vm_stack_push : - IsGlobalAlias globals ethereum.berlin.vm.stack.globals "push". +Axiom ethereum_berlin_vm_stack_imports : + AreImported globals "ethereum.berlin.vm.stack" [ "pop"; "push" ]. Definition bitwise_and : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/block.v b/CoqOfPython/ethereum/berlin/vm/instructions/block.v index b13d40b..f835701 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/block.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/block.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.berlin.vm.instructions.block". Definition expr_1 : Value.t := Constant.str " @@ -17,27 +17,17 @@ Introduction Implementations of the EVM block instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.berlin.vm.__init__. -Axiom ethereum_berlin_vm___init___Evm : - IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Evm". +Axiom ethereum_berlin_vm_imports : + AreImported globals "ethereum.berlin.vm" [ "Evm" ]. -Require ethereum.berlin.vm.gas. -Axiom ethereum_berlin_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_BASE". -Axiom ethereum_berlin_vm_gas_GAS_BLOCK_HASH : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_BLOCK_HASH". -Axiom ethereum_berlin_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "charge_gas". +Axiom ethereum_berlin_vm_gas_imports : + AreImported globals "ethereum.berlin.vm.gas" [ "GAS_BASE"; "GAS_BLOCK_HASH"; "charge_gas" ]. -Require ethereum.berlin.vm.stack. -Axiom ethereum_berlin_vm_stack_pop : - IsGlobalAlias globals ethereum.berlin.vm.stack.globals "pop". -Axiom ethereum_berlin_vm_stack_push : - IsGlobalAlias globals ethereum.berlin.vm.stack.globals "push". +Axiom ethereum_berlin_vm_stack_imports : + AreImported globals "ethereum.berlin.vm.stack" [ "pop"; "push" ]. Definition block_hash : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -94,10 +84,13 @@ Definition block_hash : Value.t -> Value.t -> M := (* else *) )), ltac:(M.monadic ( let hash := - M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), - M.get_name (| globals, "block_number" |) - |) |) |) in + M.get_subscript (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), + UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + M.get_name (| globals, "block_number" |) + |) |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/comparison.v b/CoqOfPython/ethereum/berlin/vm/instructions/comparison.v index d7845ab..bc46aed 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/comparison.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.berlin.vm.instructions.comparison". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementations of the EVM Comparison instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.berlin.vm.__init__. -Axiom ethereum_berlin_vm___init___Evm : - IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Evm". +Axiom ethereum_berlin_vm_imports : + AreImported globals "ethereum.berlin.vm" [ "Evm" ]. -Require ethereum.berlin.vm.gas. -Axiom ethereum_berlin_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_berlin_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "charge_gas". +Axiom ethereum_berlin_vm_gas_imports : + AreImported globals "ethereum.berlin.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.berlin.vm.stack. -Axiom ethereum_berlin_vm_stack_pop : - IsGlobalAlias globals ethereum.berlin.vm.stack.globals "pop". -Axiom ethereum_berlin_vm_stack_push : - IsGlobalAlias globals ethereum.berlin.vm.stack.globals "push". +Axiom ethereum_berlin_vm_stack_imports : + AreImported globals "ethereum.berlin.vm.stack" [ "pop"; "push" ]. Definition less_than : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/control_flow.v b/CoqOfPython/ethereum/berlin/vm/instructions/control_flow.v index bdc4e97..3829375 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/control_flow.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.berlin.vm.instructions.control_flow". Definition expr_1 : Value.t := Constant.str " @@ -17,37 +17,20 @@ Introduction Implementations of the EVM control flow instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. -Require ethereum.berlin.vm.gas. -Axiom ethereum_berlin_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_BASE". -Axiom ethereum_berlin_vm_gas_GAS_HIGH : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_HIGH". -Axiom ethereum_berlin_vm_gas_GAS_JUMPDEST : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_JUMPDEST". -Axiom ethereum_berlin_vm_gas_GAS_MID : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_MID". -Axiom ethereum_berlin_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "charge_gas". +Axiom ethereum_berlin_vm_gas_imports : + AreImported globals "ethereum.berlin.vm.gas" [ "GAS_BASE"; "GAS_HIGH"; "GAS_JUMPDEST"; "GAS_MID"; "charge_gas" ]. -Require ethereum.berlin.vm.__init__. -Axiom ethereum_berlin_vm___init___Evm : - IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Evm". +Axiom ethereum_berlin_vm_imports : + AreImported globals "ethereum.berlin.vm" [ "Evm" ]. -Require ethereum.berlin.vm.exceptions. -Axiom ethereum_berlin_vm_exceptions_InvalidJumpDestError : - IsGlobalAlias globals ethereum.berlin.vm.exceptions.globals "InvalidJumpDestError". +Axiom ethereum_berlin_vm_exceptions_imports : + AreImported globals "ethereum.berlin.vm.exceptions" [ "InvalidJumpDestError" ]. -Require ethereum.berlin.vm.stack. -Axiom ethereum_berlin_vm_stack_pop : - IsGlobalAlias globals ethereum.berlin.vm.stack.globals "pop". -Axiom ethereum_berlin_vm_stack_push : - IsGlobalAlias globals ethereum.berlin.vm.stack.globals "push". +Axiom ethereum_berlin_vm_stack_imports : + AreImported globals "ethereum.berlin.vm.stack" [ "pop"; "push" ]. Definition stop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -117,7 +100,7 @@ Definition jump : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "InvalidJumpDestError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -205,7 +188,7 @@ Definition jumpi : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "InvalidJumpDestError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/environment.v b/CoqOfPython/ethereum/berlin/vm/instructions/environment.v index ba42cac..428b5dc 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/environment.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.berlin.vm.instructions.environment". Definition expr_1 : Value.t := Constant.str " @@ -17,75 +17,41 @@ Introduction Implementations of the EVM environment related instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". - -Require ethereum.berlin.fork_types. -Axiom ethereum_berlin_fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals ethereum.berlin.fork_types.globals "EMPTY_ACCOUNT". - -Require ethereum.berlin.state. -Axiom ethereum_berlin_state_get_account : - IsGlobalAlias globals ethereum.berlin.state.globals "get_account". - -Require ethereum.berlin.utils.address. -Axiom ethereum_berlin_utils_address_to_address : - IsGlobalAlias globals ethereum.berlin.utils.address.globals "to_address". - -Require ethereum.berlin.vm.memory. -Axiom ethereum_berlin_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.berlin.vm.memory.globals "buffer_read". -Axiom ethereum_berlin_vm_memory_memory_write : - IsGlobalAlias globals ethereum.berlin.vm.memory.globals "memory_write". - -Require ethereum.berlin.vm.__init__. -Axiom ethereum_berlin_vm___init___Evm : - IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Evm". - -Require ethereum.berlin.vm.exceptions. -Axiom ethereum_berlin_vm_exceptions_OutOfBoundsRead : - IsGlobalAlias globals ethereum.berlin.vm.exceptions.globals "OutOfBoundsRead". - -Require ethereum.berlin.vm.gas. -Axiom ethereum_berlin_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_BASE". -Axiom ethereum_berlin_vm_gas_GAS_COLD_ACCOUNT_ACCESS : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_COLD_ACCOUNT_ACCESS". -Axiom ethereum_berlin_vm_gas_GAS_COPY : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_COPY". -Axiom ethereum_berlin_vm_gas_GAS_FAST_STEP : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_FAST_STEP". -Axiom ethereum_berlin_vm_gas_GAS_RETURN_DATA_COPY : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_RETURN_DATA_COPY". -Axiom ethereum_berlin_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_berlin_vm_gas_GAS_WARM_ACCESS : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_WARM_ACCESS". -Axiom ethereum_berlin_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_berlin_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "charge_gas". - -Require ethereum.berlin.vm.stack. -Axiom ethereum_berlin_vm_stack_pop : - IsGlobalAlias globals ethereum.berlin.vm.stack.globals "pop". -Axiom ethereum_berlin_vm_stack_push : - IsGlobalAlias globals ethereum.berlin.vm.stack.globals "push". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. + +Axiom ethereum_berlin_fork_types_imports : + AreImported globals "ethereum.berlin.fork_types" [ "EMPTY_ACCOUNT" ]. + +Axiom ethereum_berlin_state_imports : + AreImported globals "ethereum.berlin.state" [ "get_account" ]. + +Axiom ethereum_berlin_utils_address_imports : + AreImported globals "ethereum.berlin.utils.address" [ "to_address" ]. + +Axiom ethereum_berlin_vm_memory_imports : + AreImported globals "ethereum.berlin.vm.memory" [ "buffer_read"; "memory_write" ]. + +Axiom ethereum_berlin_vm_imports : + AreImported globals "ethereum.berlin.vm" [ "Evm" ]. + +Axiom ethereum_berlin_vm_exceptions_imports : + AreImported globals "ethereum.berlin.vm.exceptions" [ "OutOfBoundsRead" ]. + +Axiom ethereum_berlin_vm_gas_imports : + AreImported globals "ethereum.berlin.vm.gas" [ "GAS_BASE"; "GAS_COLD_ACCOUNT_ACCESS"; "GAS_COPY"; "GAS_FAST_STEP"; "GAS_RETURN_DATA_COPY"; "GAS_VERY_LOW"; "GAS_WARM_ACCESS"; "calculate_gas_extend_memory"; "charge_gas" ]. + +Axiom ethereum_berlin_vm_stack_imports : + AreImported globals "ethereum.berlin.vm.stack" [ "pop"; "push" ]. Definition address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -158,7 +124,7 @@ Definition balance : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -810,7 +776,7 @@ Definition extcodesize : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -966,7 +932,7 @@ Definition extcodecopy : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -1225,10 +1191,15 @@ Definition returndatacopy : Value.t -> Value.t -> M := |) |) in let value := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.slice (| M.get_name (| globals, "return_data_start_position" |), BinOp.add (| + M.slice (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |), - M.get_name (| globals, "size" |) - |) |) |) in + BinOp.add (| + M.get_name (| globals, "return_data_start_position" |), + M.get_name (| globals, "size" |) + |), + Constant.None_ + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -1272,7 +1243,7 @@ Definition extcodehash : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/keccak.v b/CoqOfPython/ethereum/berlin/vm/instructions/keccak.v index 364d315..6ff1f5f 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/keccak.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.berlin.vm.instructions.keccak". Definition expr_1 : Value.t := Constant.str " @@ -17,43 +17,26 @@ Introduction Implementations of the EVM keccak instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". - -Require ethereum.berlin.vm.__init__. -Axiom ethereum_berlin_vm___init___Evm : - IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Evm". - -Require ethereum.berlin.vm.gas. -Axiom ethereum_berlin_vm_gas_GAS_KECCAK256 : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_KECCAK256". -Axiom ethereum_berlin_vm_gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_KECCAK256_WORD". -Axiom ethereum_berlin_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_berlin_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "charge_gas". - -Require ethereum.berlin.vm.memory. -Axiom ethereum_berlin_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.berlin.vm.memory.globals "memory_read_bytes". - -Require ethereum.berlin.vm.stack. -Axiom ethereum_berlin_vm_stack_pop : - IsGlobalAlias globals ethereum.berlin.vm.stack.globals "pop". -Axiom ethereum_berlin_vm_stack_push : - IsGlobalAlias globals ethereum.berlin.vm.stack.globals "push". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. + +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. + +Axiom ethereum_berlin_vm_imports : + AreImported globals "ethereum.berlin.vm" [ "Evm" ]. + +Axiom ethereum_berlin_vm_gas_imports : + AreImported globals "ethereum.berlin.vm.gas" [ "GAS_KECCAK256"; "GAS_KECCAK256_WORD"; "calculate_gas_extend_memory"; "charge_gas" ]. + +Axiom ethereum_berlin_vm_memory_imports : + AreImported globals "ethereum.berlin.vm.memory" [ "memory_read_bytes" ]. + +Axiom ethereum_berlin_vm_stack_imports : + AreImported globals "ethereum.berlin.vm.stack" [ "pop"; "push" ]. Definition keccak : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/log.v b/CoqOfPython/ethereum/berlin/vm/instructions/log.v index 4f9705b..c97a508 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/log.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/log.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.berlin.vm.instructions.log". Definition expr_1 : Value.t := Constant.str " @@ -17,49 +17,32 @@ Introduction Implementations of the EVM logging instructions. ". -Require functools. -Axiom functools_partial : - IsGlobalAlias globals functools.globals "partial". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.berlin.blocks. -Axiom ethereum_berlin_blocks_Log : - IsGlobalAlias globals ethereum.berlin.blocks.globals "Log". - -Require ethereum.berlin.vm.__init__. -Axiom ethereum_berlin_vm___init___Evm : - IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Evm". - -Require ethereum.berlin.vm.exceptions. -Axiom ethereum_berlin_vm_exceptions_WriteInStaticContext : - IsGlobalAlias globals ethereum.berlin.vm.exceptions.globals "WriteInStaticContext". - -Require ethereum.berlin.vm.gas. -Axiom ethereum_berlin_vm_gas_GAS_LOG : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_LOG". -Axiom ethereum_berlin_vm_gas_GAS_LOG_DATA : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_LOG_DATA". -Axiom ethereum_berlin_vm_gas_GAS_LOG_TOPIC : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_LOG_TOPIC". -Axiom ethereum_berlin_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_berlin_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "charge_gas". - -Require ethereum.berlin.vm.memory. -Axiom ethereum_berlin_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.berlin.vm.memory.globals "memory_read_bytes". - -Require ethereum.berlin.vm.stack. -Axiom ethereum_berlin_vm_stack_pop : - IsGlobalAlias globals ethereum.berlin.vm.stack.globals "pop". +Axiom functools_imports : + AreImported globals "functools" [ "partial" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_berlin_blocks_imports : + AreImported globals "ethereum.berlin.blocks" [ "Log" ]. + +Axiom ethereum_berlin_vm_imports : + AreImported globals "ethereum.berlin.vm" [ "Evm" ]. + +Axiom ethereum_berlin_vm_exceptions_imports : + AreImported globals "ethereum.berlin.vm.exceptions" [ "WriteInStaticContext" ]. + +Axiom ethereum_berlin_vm_gas_imports : + AreImported globals "ethereum.berlin.vm.gas" [ "GAS_LOG"; "GAS_LOG_DATA"; "GAS_LOG_TOPIC"; "calculate_gas_extend_memory"; "charge_gas" ]. + +Axiom ethereum_berlin_vm_memory_imports : + AreImported globals "ethereum.berlin.vm.memory" [ "memory_read_bytes" ]. + +Axiom ethereum_berlin_vm_stack_imports : + AreImported globals "ethereum.berlin.vm.stack" [ "pop" ]. Definition log_n : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -96,33 +79,42 @@ Definition log_n : Value.t -> Value.t -> M := |) in let topics := make_list [] in - For M.get_name (| globals, "_" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - M.get_name (| globals, "num_topics" |) - ], - make_dict [] - |) do - let topic := + let _ := + M.for_ (| + M.get_name (| globals, "_" |), M.call (| - M.get_field (| M.call (| - M.get_name (| globals, "pop" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] - |), "to_be_bytes32" |), - make_list [], - make_dict [] - |) in - let _ := M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "num_topics" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let topic := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| M.get_field (| M.get_name (| globals, "topics" |), "append" |), make_list [ M.get_name (| globals, "topic" |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let extend_memory := M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/memory.v b/CoqOfPython/ethereum/berlin/vm/instructions/memory.v index 9d61e40..349ccdb 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/memory.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.berlin.vm.instructions.memory". Definition expr_1 : Value.t := Constant.str " @@ -17,37 +17,20 @@ Introduction Implementations of the EVM Memory instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes" ]. -Require ethereum.berlin.vm.__init__. -Axiom ethereum_berlin_vm___init___Evm : - IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Evm". +Axiom ethereum_berlin_vm_imports : + AreImported globals "ethereum.berlin.vm" [ "Evm" ]. -Require ethereum.berlin.vm.gas. -Axiom ethereum_berlin_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_BASE". -Axiom ethereum_berlin_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_berlin_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_berlin_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "charge_gas". +Axiom ethereum_berlin_vm_gas_imports : + AreImported globals "ethereum.berlin.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. -Require ethereum.berlin.vm.memory. -Axiom ethereum_berlin_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.berlin.vm.memory.globals "memory_read_bytes". -Axiom ethereum_berlin_vm_memory_memory_write : - IsGlobalAlias globals ethereum.berlin.vm.memory.globals "memory_write". +Axiom ethereum_berlin_vm_memory_imports : + AreImported globals "ethereum.berlin.vm.memory" [ "memory_read_bytes"; "memory_write" ]. -Require ethereum.berlin.vm.stack. -Axiom ethereum_berlin_vm_stack_pop : - IsGlobalAlias globals ethereum.berlin.vm.stack.globals "pop". -Axiom ethereum_berlin_vm_stack_push : - IsGlobalAlias globals ethereum.berlin.vm.stack.globals "push". +Axiom ethereum_berlin_vm_stack_imports : + AreImported globals "ethereum.berlin.vm.stack" [ "pop"; "push" ]. Definition mstore : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/stack.v b/CoqOfPython/ethereum/berlin/vm/instructions/stack.v index 43211e8..a570734 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/stack.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.berlin.vm.instructions.stack". Definition expr_1 : Value.t := Constant.str " @@ -17,39 +17,26 @@ Introduction Implementations of the EVM stack related instructions. ". -Require functools. -Axiom functools_partial : - IsGlobalAlias globals functools.globals "partial". +Axiom functools_imports : + AreImported globals "functools" [ "partial" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.berlin.vm.__init__. -Axiom ethereum_berlin_vm___init___Evm : - IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Evm". -Axiom ethereum_berlin_vm___init___stack : - IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "stack". +Axiom ethereum_berlin_vm_imports : + AreImported globals "ethereum.berlin.vm" [ "Evm"; "stack" ]. -Require ethereum.berlin.vm.exceptions. -Axiom ethereum_berlin_vm_exceptions_StackUnderflowError : - IsGlobalAlias globals ethereum.berlin.vm.exceptions.globals "StackUnderflowError". +Axiom ethereum_berlin_vm_exceptions_imports : + AreImported globals "ethereum.berlin.vm.exceptions" [ "StackUnderflowError" ]. -Require ethereum.berlin.vm.gas. -Axiom ethereum_berlin_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_BASE". -Axiom ethereum_berlin_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_berlin_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "charge_gas". +Axiom ethereum_berlin_vm_gas_imports : + AreImported globals "ethereum.berlin.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.berlin.vm.memory. -Axiom ethereum_berlin_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.berlin.vm.memory.globals "buffer_read". +Axiom ethereum_berlin_vm_memory_imports : + AreImported globals "ethereum.berlin.vm.memory" [ "buffer_read" ]. Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -203,19 +190,22 @@ Definition dup_n : Value.t -> Value.t -> M := make_dict [] |) in let data_to_duplicate := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] + BinOp.sub (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), + Constant.int 1 |), - Constant.int 1 - |), - M.get_name (| globals, "item_number" |) - |) |) in + M.get_name (| globals, "item_number" |) + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "stack" |), "push" |), make_list [ @@ -278,14 +268,26 @@ Definition swap_n : Value.t -> Value.t -> M := make_dict [] |) in let _ := M.assign (| - make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| - UnOp.sub (| Constant.int 1 |), - M.get_name (| globals, "item_number" |) - |) |) ], - make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| - UnOp.sub (| Constant.int 1 |), - M.get_name (| globals, "item_number" |) - |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |) ] + make_tuple [ M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + UnOp.sub (| Constant.int 1 |) + |); M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) + |) ], + make_tuple [ M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) + |); M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + UnOp.sub (| Constant.int 1 |) + |) ] |) in let _ := M.assign_op (| BinOp.add, diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/storage.v b/CoqOfPython/ethereum/berlin/vm/instructions/storage.v index 1245525..0670357 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/storage.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.berlin.vm.instructions.storage". Definition expr_1 : Value.t := Constant.str " @@ -17,53 +17,26 @@ Introduction Implementations of the EVM storage related instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.berlin.state. -Axiom ethereum_berlin_state_get_storage : - IsGlobalAlias globals ethereum.berlin.state.globals "get_storage". -Axiom ethereum_berlin_state_get_storage_original : - IsGlobalAlias globals ethereum.berlin.state.globals "get_storage_original". -Axiom ethereum_berlin_state_set_storage : - IsGlobalAlias globals ethereum.berlin.state.globals "set_storage". +Axiom ethereum_berlin_state_imports : + AreImported globals "ethereum.berlin.state" [ "get_storage"; "get_storage_original"; "set_storage" ]. -Require ethereum.berlin.vm.__init__. -Axiom ethereum_berlin_vm___init___Evm : - IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Evm". +Axiom ethereum_berlin_vm_imports : + AreImported globals "ethereum.berlin.vm" [ "Evm" ]. -Require ethereum.berlin.vm.exceptions. -Axiom ethereum_berlin_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.berlin.vm.exceptions.globals "OutOfGasError". -Axiom ethereum_berlin_vm_exceptions_WriteInStaticContext : - IsGlobalAlias globals ethereum.berlin.vm.exceptions.globals "WriteInStaticContext". +Axiom ethereum_berlin_vm_exceptions_imports : + AreImported globals "ethereum.berlin.vm.exceptions" [ "OutOfGasError"; "WriteInStaticContext" ]. -Require ethereum.berlin.vm.gas. -Axiom ethereum_berlin_vm_gas_GAS_CALL_STIPEND : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_CALL_STIPEND". -Axiom ethereum_berlin_vm_gas_GAS_COLD_SLOAD : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_COLD_SLOAD". -Axiom ethereum_berlin_vm_gas_GAS_STORAGE_CLEAR_REFUND : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_STORAGE_CLEAR_REFUND". -Axiom ethereum_berlin_vm_gas_GAS_STORAGE_SET : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_STORAGE_SET". -Axiom ethereum_berlin_vm_gas_GAS_STORAGE_UPDATE : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_STORAGE_UPDATE". -Axiom ethereum_berlin_vm_gas_GAS_WARM_ACCESS : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_WARM_ACCESS". -Axiom ethereum_berlin_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "charge_gas". +Axiom ethereum_berlin_vm_gas_imports : + AreImported globals "ethereum.berlin.vm.gas" [ "GAS_CALL_STIPEND"; "GAS_COLD_SLOAD"; "GAS_STORAGE_CLEAR_REFUND"; "GAS_STORAGE_SET"; "GAS_STORAGE_UPDATE"; "GAS_WARM_ACCESS"; "charge_gas" ]. -Require ethereum.berlin.vm.stack. -Axiom ethereum_berlin_vm_stack_pop : - IsGlobalAlias globals ethereum.berlin.vm.stack.globals "pop". -Axiom ethereum_berlin_vm_stack_push : - IsGlobalAlias globals ethereum.berlin.vm.stack.globals "push". +Axiom ethereum_berlin_vm_stack_imports : + AreImported globals "ethereum.berlin.vm.stack" [ "pop"; "push" ]. Definition sload : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -93,7 +66,7 @@ Definition sload : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) |), diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/system.v b/CoqOfPython/ethereum/berlin/vm/instructions/system.v index 36ad346..c6d9c82 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/system.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/system.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.berlin.vm.instructions.system". Definition expr_1 : Value.t := Constant.str " @@ -17,105 +17,38 @@ Introduction Implementations of the EVM system related instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.berlin.fork_types. -Axiom ethereum_berlin_fork_types_Address : - IsGlobalAlias globals ethereum.berlin.fork_types.globals "Address". +Axiom ethereum_berlin_fork_types_imports : + AreImported globals "ethereum.berlin.fork_types" [ "Address" ]. -Require ethereum.berlin.state. -Axiom ethereum_berlin_state_account_exists_and_is_empty : - IsGlobalAlias globals ethereum.berlin.state.globals "account_exists_and_is_empty". -Axiom ethereum_berlin_state_account_has_code_or_nonce : - IsGlobalAlias globals ethereum.berlin.state.globals "account_has_code_or_nonce". -Axiom ethereum_berlin_state_get_account : - IsGlobalAlias globals ethereum.berlin.state.globals "get_account". -Axiom ethereum_berlin_state_increment_nonce : - IsGlobalAlias globals ethereum.berlin.state.globals "increment_nonce". -Axiom ethereum_berlin_state_is_account_alive : - IsGlobalAlias globals ethereum.berlin.state.globals "is_account_alive". -Axiom ethereum_berlin_state_set_account_balance : - IsGlobalAlias globals ethereum.berlin.state.globals "set_account_balance". +Axiom ethereum_berlin_state_imports : + AreImported globals "ethereum.berlin.state" [ "account_exists_and_is_empty"; "account_has_code_or_nonce"; "get_account"; "increment_nonce"; "is_account_alive"; "set_account_balance" ]. -Require ethereum.berlin.utils.address. -Axiom ethereum_berlin_utils_address_compute_contract_address : - IsGlobalAlias globals ethereum.berlin.utils.address.globals "compute_contract_address". -Axiom ethereum_berlin_utils_address_compute_create2_contract_address : - IsGlobalAlias globals ethereum.berlin.utils.address.globals "compute_create2_contract_address". -Axiom ethereum_berlin_utils_address_to_address : - IsGlobalAlias globals ethereum.berlin.utils.address.globals "to_address". +Axiom ethereum_berlin_utils_address_imports : + AreImported globals "ethereum.berlin.utils.address" [ "compute_contract_address"; "compute_create2_contract_address"; "to_address" ]. -Require ethereum.berlin.vm.__init__. -Axiom ethereum_berlin_vm___init___Evm : - IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Evm". -Axiom ethereum_berlin_vm___init___Message : - IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Message". -Axiom ethereum_berlin_vm___init___incorporate_child_on_error : - IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "incorporate_child_on_error". -Axiom ethereum_berlin_vm___init___incorporate_child_on_success : - IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "incorporate_child_on_success". +Axiom ethereum_berlin_vm_imports : + AreImported globals "ethereum.berlin.vm" [ "Evm"; "Message"; "incorporate_child_on_error"; "incorporate_child_on_success" ]. -Require ethereum.berlin.vm.exceptions. -Axiom ethereum_berlin_vm_exceptions_Revert : - IsGlobalAlias globals ethereum.berlin.vm.exceptions.globals "Revert". -Axiom ethereum_berlin_vm_exceptions_WriteInStaticContext : - IsGlobalAlias globals ethereum.berlin.vm.exceptions.globals "WriteInStaticContext". +Axiom ethereum_berlin_vm_exceptions_imports : + AreImported globals "ethereum.berlin.vm.exceptions" [ "Revert"; "WriteInStaticContext" ]. -Require ethereum.berlin.vm.gas. -Axiom ethereum_berlin_vm_gas_GAS_CALL_VALUE : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_CALL_VALUE". -Axiom ethereum_berlin_vm_gas_GAS_COLD_ACCOUNT_ACCESS : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_COLD_ACCOUNT_ACCESS". -Axiom ethereum_berlin_vm_gas_GAS_CREATE : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_CREATE". -Axiom ethereum_berlin_vm_gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_KECCAK256_WORD". -Axiom ethereum_berlin_vm_gas_GAS_NEW_ACCOUNT : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_NEW_ACCOUNT". -Axiom ethereum_berlin_vm_gas_GAS_SELF_DESTRUCT : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_SELF_DESTRUCT". -Axiom ethereum_berlin_vm_gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". -Axiom ethereum_berlin_vm_gas_GAS_WARM_ACCESS : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_WARM_ACCESS". -Axiom ethereum_berlin_vm_gas_GAS_ZERO : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_ZERO". -Axiom ethereum_berlin_vm_gas_REFUND_SELF_DESTRUCT : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "REFUND_SELF_DESTRUCT". -Axiom ethereum_berlin_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_berlin_vm_gas_calculate_message_call_gas : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "calculate_message_call_gas". -Axiom ethereum_berlin_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "charge_gas". -Axiom ethereum_berlin_vm_gas_max_message_call_gas : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "max_message_call_gas". +Axiom ethereum_berlin_vm_gas_imports : + AreImported globals "ethereum.berlin.vm.gas" [ "GAS_CALL_VALUE"; "GAS_COLD_ACCOUNT_ACCESS"; "GAS_CREATE"; "GAS_KECCAK256_WORD"; "GAS_NEW_ACCOUNT"; "GAS_SELF_DESTRUCT"; "GAS_SELF_DESTRUCT_NEW_ACCOUNT"; "GAS_WARM_ACCESS"; "GAS_ZERO"; "REFUND_SELF_DESTRUCT"; "calculate_gas_extend_memory"; "calculate_message_call_gas"; "charge_gas"; "max_message_call_gas" ]. -Require ethereum.berlin.vm.memory. -Axiom ethereum_berlin_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.berlin.vm.memory.globals "memory_read_bytes". -Axiom ethereum_berlin_vm_memory_memory_write : - IsGlobalAlias globals ethereum.berlin.vm.memory.globals "memory_write". +Axiom ethereum_berlin_vm_memory_imports : + AreImported globals "ethereum.berlin.vm.memory" [ "memory_read_bytes"; "memory_write" ]. -Require ethereum.berlin.vm.stack. -Axiom ethereum_berlin_vm_stack_pop : - IsGlobalAlias globals ethereum.berlin.vm.stack.globals "pop". -Axiom ethereum_berlin_vm_stack_push : - IsGlobalAlias globals ethereum.berlin.vm.stack.globals "push". +Axiom ethereum_berlin_vm_stack_imports : + AreImported globals "ethereum.berlin.vm.stack" [ "pop"; "push" ]. Definition generic_create : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -868,7 +801,12 @@ Definition generic_call : Value.t -> Value.t -> M := make_list [ M.get_field (| M.get_name (| globals, "evm" |), "memory" |); M.get_name (| globals, "memory_output_start_position" |); - M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), M.slice (| Constant.None_, M.get_name (| globals, "actual_output_size" |) |) |) + M.slice (| + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), + Constant.None_, + M.get_name (| globals, "actual_output_size" |), + Constant.None_ + |) ], make_dict [] |) in @@ -968,7 +906,7 @@ Definition call : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "to" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -1274,7 +1212,7 @@ Definition callcode : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "code_address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -1520,20 +1458,28 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in let parent_evm := M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "parent_evm" |) in - While Compare.is_not (| - M.get_name (| globals, "parent_evm" |), - Constant.None_ - |) do - let _ := M.call (| + let _ := + M.while (| + Compare.is_not (| + M.get_name (| globals, "parent_evm" |), + Constant.None_ + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "refunded_accounts" |), "update" |), make_list [ M.get_field (| M.get_name (| globals, "parent_evm" |), "accounts_to_delete" |) ], make_dict [] |) in - let parent_evm := - M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in - EndWhile. + let parent_evm := + M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := (* if *) M.if_then_else (| @@ -1739,7 +1685,7 @@ Definition delegatecall : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "code_address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -1915,7 +1861,7 @@ Definition staticcall : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "to" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -2085,6 +2031,6 @@ Definition revert : Value.t -> Value.t -> M := make_dict [] |) |) in - let _ := M.raise (| Some(M.get_name (| globals, "Revert" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "Revert" |)) |) in let _ := M.pass (| |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/berlin/vm/interpreter.v b/CoqOfPython/ethereum/berlin/vm/interpreter.v index 0989fe3..4100220 100644 --- a/CoqOfPython/ethereum/berlin/vm/interpreter.v +++ b/CoqOfPython/ethereum/berlin/vm/interpreter.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.berlin.vm.interpreter". Definition expr_1 : Value.t := Constant.str " @@ -17,125 +17,50 @@ Introduction A straightforward interpreter that executes EVM code. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_Iterable : - IsGlobalAlias globals typing.globals "Iterable". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.trace. -Axiom ethereum_trace_EvmStop : - IsGlobalAlias globals ethereum.trace.globals "EvmStop". -Axiom ethereum_trace_OpEnd : - IsGlobalAlias globals ethereum.trace.globals "OpEnd". -Axiom ethereum_trace_OpException : - IsGlobalAlias globals ethereum.trace.globals "OpException". -Axiom ethereum_trace_OpStart : - IsGlobalAlias globals ethereum.trace.globals "OpStart". -Axiom ethereum_trace_PrecompileEnd : - IsGlobalAlias globals ethereum.trace.globals "PrecompileEnd". -Axiom ethereum_trace_PrecompileStart : - IsGlobalAlias globals ethereum.trace.globals "PrecompileStart". -Axiom ethereum_trace_TransactionEnd : - IsGlobalAlias globals ethereum.trace.globals "TransactionEnd". -Axiom ethereum_trace_evm_trace : - IsGlobalAlias globals ethereum.trace.globals "evm_trace". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.berlin.blocks. -Axiom ethereum_berlin_blocks_Log : - IsGlobalAlias globals ethereum.berlin.blocks.globals "Log". - -Require ethereum.berlin.fork_types. -Axiom ethereum_berlin_fork_types_Address : - IsGlobalAlias globals ethereum.berlin.fork_types.globals "Address". - -Require ethereum.berlin.state. -Axiom ethereum_berlin_state_account_exists_and_is_empty : - IsGlobalAlias globals ethereum.berlin.state.globals "account_exists_and_is_empty". -Axiom ethereum_berlin_state_account_has_code_or_nonce : - IsGlobalAlias globals ethereum.berlin.state.globals "account_has_code_or_nonce". -Axiom ethereum_berlin_state_begin_transaction : - IsGlobalAlias globals ethereum.berlin.state.globals "begin_transaction". -Axiom ethereum_berlin_state_commit_transaction : - IsGlobalAlias globals ethereum.berlin.state.globals "commit_transaction". -Axiom ethereum_berlin_state_destroy_storage : - IsGlobalAlias globals ethereum.berlin.state.globals "destroy_storage". -Axiom ethereum_berlin_state_increment_nonce : - IsGlobalAlias globals ethereum.berlin.state.globals "increment_nonce". -Axiom ethereum_berlin_state_mark_account_created : - IsGlobalAlias globals ethereum.berlin.state.globals "mark_account_created". -Axiom ethereum_berlin_state_move_ether : - IsGlobalAlias globals ethereum.berlin.state.globals "move_ether". -Axiom ethereum_berlin_state_rollback_transaction : - IsGlobalAlias globals ethereum.berlin.state.globals "rollback_transaction". -Axiom ethereum_berlin_state_set_code : - IsGlobalAlias globals ethereum.berlin.state.globals "set_code". -Axiom ethereum_berlin_state_touch_account : - IsGlobalAlias globals ethereum.berlin.state.globals "touch_account". - -Require ethereum.berlin.vm.__init__. -Axiom ethereum_berlin_vm___init___Message : - IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Message". - -Require ethereum.berlin.vm.gas. -Axiom ethereum_berlin_vm_gas_GAS_CODE_DEPOSIT : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_CODE_DEPOSIT". -Axiom ethereum_berlin_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "charge_gas". - -Require ethereum.berlin.vm.precompiled_contracts.mapping. -Axiom ethereum_berlin_vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : - IsGlobalAlias globals ethereum.berlin.vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". - -Require ethereum.berlin.vm.__init__. -Axiom ethereum_berlin_vm___init___Environment : - IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Environment". -Axiom ethereum_berlin_vm___init___Evm : - IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Evm". - -Require ethereum.berlin.vm.exceptions. -Axiom ethereum_berlin_vm_exceptions_AddressCollision : - IsGlobalAlias globals ethereum.berlin.vm.exceptions.globals "AddressCollision". -Axiom ethereum_berlin_vm_exceptions_ExceptionalHalt : - IsGlobalAlias globals ethereum.berlin.vm.exceptions.globals "ExceptionalHalt". -Axiom ethereum_berlin_vm_exceptions_InvalidOpcode : - IsGlobalAlias globals ethereum.berlin.vm.exceptions.globals "InvalidOpcode". -Axiom ethereum_berlin_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.berlin.vm.exceptions.globals "OutOfGasError". -Axiom ethereum_berlin_vm_exceptions_Revert : - IsGlobalAlias globals ethereum.berlin.vm.exceptions.globals "Revert". -Axiom ethereum_berlin_vm_exceptions_StackDepthLimitError : - IsGlobalAlias globals ethereum.berlin.vm.exceptions.globals "StackDepthLimitError". - -Require ethereum.berlin.vm.instructions.__init__. -Axiom ethereum_berlin_vm_instructions___init___Ops : - IsGlobalAlias globals ethereum.berlin.vm.instructions.__init__.globals "Ops". -Axiom ethereum_berlin_vm_instructions___init___op_implementation : - IsGlobalAlias globals ethereum.berlin.vm.instructions.__init__.globals "op_implementation". - -Require ethereum.berlin.vm.runtime. -Axiom ethereum_berlin_vm_runtime_get_valid_jump_destinations : - IsGlobalAlias globals ethereum.berlin.vm.runtime.globals "get_valid_jump_destinations". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Iterable"; "Optional"; "Set"; "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. + +Axiom ethereum_trace_imports : + AreImported globals "ethereum.trace" [ "EvmStop"; "OpEnd"; "OpException"; "OpStart"; "PrecompileEnd"; "PrecompileStart"; "TransactionEnd"; "evm_trace" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_berlin_blocks_imports : + AreImported globals "ethereum.berlin.blocks" [ "Log" ]. + +Axiom ethereum_berlin_fork_types_imports : + AreImported globals "ethereum.berlin.fork_types" [ "Address" ]. + +Axiom ethereum_berlin_state_imports : + AreImported globals "ethereum.berlin.state" [ "account_exists_and_is_empty"; "account_has_code_or_nonce"; "begin_transaction"; "commit_transaction"; "destroy_storage"; "increment_nonce"; "mark_account_created"; "move_ether"; "rollback_transaction"; "set_code"; "touch_account" ]. + +Axiom ethereum_berlin_vm_imports : + AreImported globals "ethereum.berlin.vm" [ "Message" ]. + +Axiom ethereum_berlin_vm_gas_imports : + AreImported globals "ethereum.berlin.vm.gas" [ "GAS_CODE_DEPOSIT"; "charge_gas" ]. + +Axiom ethereum_berlin_vm_precompiled_contracts_mapping_imports : + AreImported globals "ethereum.berlin.vm.precompiled_contracts.mapping" [ "PRE_COMPILED_CONTRACTS" ]. + +Axiom ethereum_berlin_vm_imports : + AreImported globals "ethereum.berlin.vm" [ "Environment"; "Evm" ]. + +Axiom ethereum_berlin_vm_exceptions_imports : + AreImported globals "ethereum.berlin.vm.exceptions" [ "AddressCollision"; "ExceptionalHalt"; "InvalidOpcode"; "OutOfGasError"; "Revert"; "StackDepthLimitError" ]. + +Axiom ethereum_berlin_vm_instructions_imports : + AreImported globals "ethereum.berlin.vm.instructions" [ "Ops"; "op_implementation" ]. + +Axiom ethereum_berlin_vm_runtime_imports : + AreImported globals "ethereum.berlin.vm.runtime" [ "get_valid_jump_destinations" ]. Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -516,7 +441,7 @@ Definition process_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "StackDepthLimitError" |), make_list [ Constant.str "Stack depth limit reached" diff --git a/CoqOfPython/ethereum/berlin/vm/memory.v b/CoqOfPython/ethereum/berlin/vm/memory.v index 08d2290..b747f84 100644 --- a/CoqOfPython/ethereum/berlin/vm/memory.v +++ b/CoqOfPython/ethereum/berlin/vm/memory.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.berlin.vm.memory". Definition expr_1 : Value.t := Constant.str " @@ -17,17 +17,11 @@ Introduction EVM memory operations. ". -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_right_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "right_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "right_pad_zero_bytes" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. Definition memory_write : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,22 +39,27 @@ Definition memory_write : Value.t -> Value.t -> M := Data to write to memory. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + M.slice (| + M.get_name (| globals, "memory" |), + M.get_name (| globals, "start_position" |), + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) - |) |) |), + Constant.None_ + |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_)). @@ -86,22 +85,27 @@ Definition memory_read_bytes : Value.t -> Value.t -> M := Data read from memory. " in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + M.slice (| + M.get_name (| globals, "memory" |), + M.get_name (| globals, "start_position" |), + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |) |) + Constant.None_ + |) |) in M.pure Constant.None_)). @@ -129,22 +133,27 @@ Definition buffer_read : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "right_pad_zero_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "buffer" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + M.slice (| + M.get_name (| globals, "buffer" |), + M.get_name (| globals, "start_position" |), + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |) |); + Constant.None_ + |); M.get_name (| globals, "size" |) ], make_dict [] diff --git a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/__init__.v index 5d1b58e..3bd7f40 100644 --- a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/__init__.v +++ b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.berlin.vm.precompiled_contracts.__init__". Definition expr_1 : Value.t := Constant.str " @@ -18,9 +18,8 @@ Addresses of precompiled contracts and mappings to their implementations. ". -Require ethereum.berlin.utils.hexadecimal. -Axiom ethereum_berlin_utils_hexadecimal_hex_to_address : - IsGlobalAlias globals ethereum.berlin.utils.hexadecimal.globals "hex_to_address". +Axiom ethereum_berlin_utils_hexadecimal_imports : + AreImported globals "ethereum.berlin.utils.hexadecimal" [ "hex_to_address" ]. Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS"; Constant.str "MODEXP_ADDRESS"; Constant.str "ALT_BN128_ADD_ADDRESS"; Constant.str "ALT_BN128_MUL_ADDRESS"; Constant.str "ALT_BN128_PAIRING_CHECK_ADDRESS"; Constant.str "BLAKE2F_ADDRESS" ] diff --git a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/alt_bn128.v index 96fbd02..9bd81c6 100644 --- a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/alt_bn128.v +++ b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/alt_bn128.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.berlin.vm.precompiled_contracts.alt_bn128". Definition expr_1 : Value.t := Constant.str " @@ -17,49 +17,26 @@ Introduction Implementation of the ALT_BN128 precompiled contracts. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. -Require ethereum.crypto.alt_bn128. -Axiom ethereum_crypto_alt_bn128_ALT_BN128_CURVE_ORDER : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "ALT_BN128_CURVE_ORDER". -Axiom ethereum_crypto_alt_bn128_ALT_BN128_PRIME : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "ALT_BN128_PRIME". -Axiom ethereum_crypto_alt_bn128_BNF : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF". -Axiom ethereum_crypto_alt_bn128_BNF2 : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF2". -Axiom ethereum_crypto_alt_bn128_BNF12 : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF12". -Axiom ethereum_crypto_alt_bn128_BNP : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNP". -Axiom ethereum_crypto_alt_bn128_BNP2 : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNP2". -Axiom ethereum_crypto_alt_bn128_pairing : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "pairing". +Axiom ethereum_crypto_alt_bn128_imports : + AreImported globals "ethereum.crypto.alt_bn128" [ "ALT_BN128_CURVE_ORDER"; "ALT_BN128_PRIME"; "BNF"; "BNF2"; "BNF12"; "BNP"; "BNP2"; "pairing" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.berlin.vm.__init__. -Axiom ethereum_berlin_vm___init___Evm : - IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Evm". +Axiom ethereum_berlin_vm_imports : + AreImported globals "ethereum.berlin.vm" [ "Evm" ]. -Require ethereum.berlin.vm.gas. -Axiom ethereum_berlin_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "charge_gas". +Axiom ethereum_berlin_vm_gas_imports : + AreImported globals "ethereum.berlin.vm.gas" [ "charge_gas" ]. -Require ethereum.berlin.vm.memory. -Axiom ethereum_berlin_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.berlin.vm.memory.globals "buffer_read". +Axiom ethereum_berlin_vm_memory_imports : + AreImported globals "ethereum.berlin.vm.memory" [ "buffer_read" ]. -Require ethereum.berlin.vm.exceptions. -Axiom ethereum_berlin_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.berlin.vm.exceptions.globals "OutOfGasError". +Axiom ethereum_berlin_vm_exceptions_imports : + AreImported globals "ethereum.berlin.vm.exceptions" [ "OutOfGasError" ]. Definition alt_bn128_add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -208,23 +185,32 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ] do - let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| - M.get_name (| globals, "i" |), - M.get_name (| globals, "ALT_BN128_PRIME" |) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ], ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in (* At stmt: unsupported node type: Try *) let p := BinOp.add (| @@ -363,23 +349,32 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ] do - let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| - M.get_name (| globals, "i" |), - M.get_name (| globals, "ALT_BN128_PRIME" |) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ], ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in (* At stmt: unsupported node type: Try *) let p := M.call (| @@ -466,7 +461,7 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -480,76 +475,89 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - BinOp.floor_div (| + let _ := + M.for_ (| + M.get_name (| globals, "i" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "data" |) - ], - make_dict [] - |), - Constant.int 192 - |) - ], - make_dict [] - |) do - let values := - make_list [] in - For M.get_name (| globals, "j" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 6 - ], - make_dict [] - |) do - let value := + M.get_name (| globals, "range" |), + make_list [ + BinOp.floor_div (| M.call (| - M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + M.get_name (| globals, "len" |), make_list [ - M.get_subscript (| M.get_name (| globals, "data" |), M.slice (| BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "i" |), - Constant.int 192 - |), - BinOp.mult (| - Constant.int 32, - M.get_name (| globals, "j" |) - |) - |), BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "i" |), - Constant.int 192 - |), - BinOp.mult (| - Constant.int 32, - BinOp.add (| - M.get_name (| globals, "j" |), - Constant.int 1 - |) - |) - |) |) |) + M.get_name (| globals, "data" |) ], make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| - M.get_name (| globals, "value" |), - M.get_name (| globals, "ALT_BN128_PRIME" |) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let _ := M.call (| + |), + Constant.int 192 + |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let values := + make_list [] in + let _ := + M.for_ (| + M.get_name (| globals, "j" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 6 + ], + make_dict [] + |), + ltac:(M.monadic ( + let value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.slice (| + M.get_name (| globals, "data" |), + BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + M.get_name (| globals, "j" |) + |) + |), + BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "j" |), + Constant.int 1 + |) + |) + |), + Constant.None_ + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| M.get_field (| M.get_name (| globals, "values" |), "append" |), make_list [ M.call (| @@ -562,9 +570,14 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in (* At stmt: unsupported node type: Try *) - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.eq (| @@ -585,7 +598,7 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.eq (| @@ -606,49 +619,54 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| - M.get_name (| globals, "p" |), - M.call (| - M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) - |), + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "p" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "q" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |) + )) + |), + (* then *) ltac:(M.monadic ( - Compare.not_eq (| - M.get_name (| globals, "q" |), - M.call (| - M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) - |) - )) - |), - (* then *) - ltac:(M.monadic ( - let result := - BinOp.mult (| - M.get_name (| globals, "result" |), - M.call (| - M.get_name (| globals, "pairing" |), - make_list [ - M.get_name (| globals, "q" |); - M.get_name (| globals, "p" |) - ], - make_dict [] - |) - |) in + let result := + BinOp.mult (| + M.get_name (| globals, "result" |), + M.call (| + M.get_name (| globals, "pairing" |), + make_list [ + M.get_name (| globals, "q" |); + M.get_name (| globals, "p" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := (* if *) M.if_then_else (| diff --git a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/blake2f.v b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/blake2f.v index 37bb13c..163d93c 100644 --- a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/blake2f.v +++ b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/blake2f.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.berlin.vm.precompiled_contracts.blake2f". Definition expr_1 : Value.t := Constant.str " @@ -17,27 +17,20 @@ Introduction Implementation of the `Blake2` precompiled contract. ". -Require ethereum.crypto.blake2. -Axiom ethereum_crypto_blake2_Blake2b : - IsGlobalAlias globals ethereum.crypto.blake2.globals "Blake2b". +Axiom ethereum_crypto_blake2_imports : + AreImported globals "ethereum.crypto.blake2" [ "Blake2b" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.berlin.vm.__init__. -Axiom ethereum_berlin_vm___init___Evm : - IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Evm". +Axiom ethereum_berlin_vm_imports : + AreImported globals "ethereum.berlin.vm" [ "Evm" ]. -Require ethereum.berlin.vm.gas. -Axiom ethereum_berlin_vm_gas_GAS_BLAKE2_PER_ROUND : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_BLAKE2_PER_ROUND". -Axiom ethereum_berlin_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "charge_gas". +Axiom ethereum_berlin_vm_gas_imports : + AreImported globals "ethereum.berlin.vm.gas" [ "GAS_BLAKE2_PER_ROUND"; "charge_gas" ]. -Require ethereum.berlin.vm.exceptions. -Axiom ethereum_berlin_vm_exceptions_InvalidParameter : - IsGlobalAlias globals ethereum.berlin.vm.exceptions.globals "InvalidParameter". +Axiom ethereum_berlin_vm_exceptions_imports : + AreImported globals "ethereum.berlin.vm.exceptions" [ "InvalidParameter" ]. Definition blake2f : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -99,7 +92,7 @@ Definition blake2f : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.in (| + Compare.in_ (| M.get_name (| globals, "f" |), make_list [ Constant.int 0; diff --git a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/ecrecover.v index 29ece73..1fe04ba 100644 --- a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/ecrecover.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.berlin.vm.precompiled_contracts.ecrecover". Definition expr_1 : Value.t := Constant.str " @@ -17,39 +17,26 @@ Introduction Implementation of the ECRECOVER precompiled contract. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.crypto.elliptic_curve. -Axiom ethereum_crypto_elliptic_curve_SECP256K1N : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". -Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". +Axiom ethereum_crypto_elliptic_curve_imports : + AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_left_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. -Require ethereum.berlin.vm.__init__. -Axiom ethereum_berlin_vm___init___Evm : - IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Evm". +Axiom ethereum_berlin_vm_imports : + AreImported globals "ethereum.berlin.vm" [ "Evm" ]. -Require ethereum.berlin.vm.gas. -Axiom ethereum_berlin_vm_gas_GAS_ECRECOVER : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_ECRECOVER". -Axiom ethereum_berlin_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "charge_gas". +Axiom ethereum_berlin_vm_gas_imports : + AreImported globals "ethereum.berlin.vm.gas" [ "GAS_ECRECOVER"; "charge_gas" ]. -Require ethereum.berlin.vm.memory. -Axiom ethereum_berlin_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.berlin.vm.memory.globals "buffer_read". +Axiom ethereum_berlin_vm_memory_imports : + AreImported globals "ethereum.berlin.vm.memory" [ "buffer_read" ]. Definition ecrecover : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -264,13 +251,18 @@ Definition ecrecover : Value.t -> Value.t -> M := )) |) in (* At stmt: unsupported node type: Try *) let address := - M.get_subscript (| M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "public_key" |) - ], - make_dict [] - |), M.slice (| Constant.int 12, Constant.int 32 |) |) in + M.slice (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), + Constant.int 12, + Constant.int 32, + Constant.None_ + |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/identity.v index fec33fd..71f6812 100644 --- a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/identity.v +++ b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/identity.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.berlin.vm.precompiled_contracts.identity". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementation of the `IDENTITY` precompiled contract. ". -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.berlin.vm.__init__. -Axiom ethereum_berlin_vm___init___Evm : - IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Evm". +Axiom ethereum_berlin_vm_imports : + AreImported globals "ethereum.berlin.vm" [ "Evm" ]. -Require ethereum.berlin.vm.gas. -Axiom ethereum_berlin_vm_gas_GAS_IDENTITY : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_IDENTITY". -Axiom ethereum_berlin_vm_gas_GAS_IDENTITY_WORD : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_IDENTITY_WORD". -Axiom ethereum_berlin_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "charge_gas". +Axiom ethereum_berlin_vm_gas_imports : + AreImported globals "ethereum.berlin.vm.gas" [ "GAS_IDENTITY"; "GAS_IDENTITY_WORD"; "charge_gas" ]. Definition identity : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/mapping.v index eb0586d..b95e81e 100644 --- a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/mapping.v +++ b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/mapping.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.berlin.vm.precompiled_contracts.mapping". Definition expr_1 : Value.t := Constant.str " @@ -17,66 +17,34 @@ Introduction Mapping of precompiled contracts their implementations. ". -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". - -Require ethereum.berlin.fork_types. -Axiom ethereum_berlin_fork_types_Address : - IsGlobalAlias globals ethereum.berlin.fork_types.globals "Address". - -Require ethereum.berlin.vm.precompiled_contracts.__init__. -Axiom ethereum_berlin_vm_precompiled_contracts___init___ALT_BN128_ADD_ADDRESS : - IsGlobalAlias globals ethereum.berlin.vm.precompiled_contracts.__init__.globals "ALT_BN128_ADD_ADDRESS". -Axiom ethereum_berlin_vm_precompiled_contracts___init___ALT_BN128_MUL_ADDRESS : - IsGlobalAlias globals ethereum.berlin.vm.precompiled_contracts.__init__.globals "ALT_BN128_MUL_ADDRESS". -Axiom ethereum_berlin_vm_precompiled_contracts___init___ALT_BN128_PAIRING_CHECK_ADDRESS : - IsGlobalAlias globals ethereum.berlin.vm.precompiled_contracts.__init__.globals "ALT_BN128_PAIRING_CHECK_ADDRESS". -Axiom ethereum_berlin_vm_precompiled_contracts___init___BLAKE2F_ADDRESS : - IsGlobalAlias globals ethereum.berlin.vm.precompiled_contracts.__init__.globals "BLAKE2F_ADDRESS". -Axiom ethereum_berlin_vm_precompiled_contracts___init___ECRECOVER_ADDRESS : - IsGlobalAlias globals ethereum.berlin.vm.precompiled_contracts.__init__.globals "ECRECOVER_ADDRESS". -Axiom ethereum_berlin_vm_precompiled_contracts___init___IDENTITY_ADDRESS : - IsGlobalAlias globals ethereum.berlin.vm.precompiled_contracts.__init__.globals "IDENTITY_ADDRESS". -Axiom ethereum_berlin_vm_precompiled_contracts___init___MODEXP_ADDRESS : - IsGlobalAlias globals ethereum.berlin.vm.precompiled_contracts.__init__.globals "MODEXP_ADDRESS". -Axiom ethereum_berlin_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : - IsGlobalAlias globals ethereum.berlin.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". -Axiom ethereum_berlin_vm_precompiled_contracts___init___SHA256_ADDRESS : - IsGlobalAlias globals ethereum.berlin.vm.precompiled_contracts.__init__.globals "SHA256_ADDRESS". - -Require ethereum.berlin.vm.precompiled_contracts.alt_bn128. -Axiom ethereum_berlin_vm_precompiled_contracts_alt_bn128_alt_bn128_add : - IsGlobalAlias globals ethereum.berlin.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_add". -Axiom ethereum_berlin_vm_precompiled_contracts_alt_bn128_alt_bn128_mul : - IsGlobalAlias globals ethereum.berlin.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_mul". -Axiom ethereum_berlin_vm_precompiled_contracts_alt_bn128_alt_bn128_pairing_check : - IsGlobalAlias globals ethereum.berlin.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_pairing_check". - -Require ethereum.berlin.vm.precompiled_contracts.blake2f. -Axiom ethereum_berlin_vm_precompiled_contracts_blake2f_blake2f : - IsGlobalAlias globals ethereum.berlin.vm.precompiled_contracts.blake2f.globals "blake2f". - -Require ethereum.berlin.vm.precompiled_contracts.ecrecover. -Axiom ethereum_berlin_vm_precompiled_contracts_ecrecover_ecrecover : - IsGlobalAlias globals ethereum.berlin.vm.precompiled_contracts.ecrecover.globals "ecrecover". - -Require ethereum.berlin.vm.precompiled_contracts.identity. -Axiom ethereum_berlin_vm_precompiled_contracts_identity_identity : - IsGlobalAlias globals ethereum.berlin.vm.precompiled_contracts.identity.globals "identity". - -Require ethereum.berlin.vm.precompiled_contracts.modexp. -Axiom ethereum_berlin_vm_precompiled_contracts_modexp_modexp : - IsGlobalAlias globals ethereum.berlin.vm.precompiled_contracts.modexp.globals "modexp". - -Require ethereum.berlin.vm.precompiled_contracts.ripemd160. -Axiom ethereum_berlin_vm_precompiled_contracts_ripemd160_ripemd160 : - IsGlobalAlias globals ethereum.berlin.vm.precompiled_contracts.ripemd160.globals "ripemd160". - -Require ethereum.berlin.vm.precompiled_contracts.sha256. -Axiom ethereum_berlin_vm_precompiled_contracts_sha256_sha256 : - IsGlobalAlias globals ethereum.berlin.vm.precompiled_contracts.sha256.globals "sha256". +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict" ]. + +Axiom ethereum_berlin_fork_types_imports : + AreImported globals "ethereum.berlin.fork_types" [ "Address" ]. + +Axiom ethereum_berlin_vm_precompiled_contracts_imports : + AreImported globals "ethereum.berlin.vm.precompiled_contracts" [ "ALT_BN128_ADD_ADDRESS"; "ALT_BN128_MUL_ADDRESS"; "ALT_BN128_PAIRING_CHECK_ADDRESS"; "BLAKE2F_ADDRESS"; "ECRECOVER_ADDRESS"; "IDENTITY_ADDRESS"; "MODEXP_ADDRESS"; "RIPEMD160_ADDRESS"; "SHA256_ADDRESS" ]. + +Axiom ethereum_berlin_vm_precompiled_contracts_alt_bn128_imports : + AreImported globals "ethereum.berlin.vm.precompiled_contracts.alt_bn128" [ "alt_bn128_add"; "alt_bn128_mul"; "alt_bn128_pairing_check" ]. + +Axiom ethereum_berlin_vm_precompiled_contracts_blake2f_imports : + AreImported globals "ethereum.berlin.vm.precompiled_contracts.blake2f" [ "blake2f" ]. + +Axiom ethereum_berlin_vm_precompiled_contracts_ecrecover_imports : + AreImported globals "ethereum.berlin.vm.precompiled_contracts.ecrecover" [ "ecrecover" ]. + +Axiom ethereum_berlin_vm_precompiled_contracts_identity_imports : + AreImported globals "ethereum.berlin.vm.precompiled_contracts.identity" [ "identity" ]. + +Axiom ethereum_berlin_vm_precompiled_contracts_modexp_imports : + AreImported globals "ethereum.berlin.vm.precompiled_contracts.modexp" [ "modexp" ]. + +Axiom ethereum_berlin_vm_precompiled_contracts_ripemd160_imports : + AreImported globals "ethereum.berlin.vm.precompiled_contracts.ripemd160" [ "ripemd160" ]. + +Axiom ethereum_berlin_vm_precompiled_contracts_sha256_imports : + AreImported globals "ethereum.berlin.vm.precompiled_contracts.sha256" [ "sha256" ]. (* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/modexp.v index 87418ff..70acad8 100644 --- a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/modexp.v +++ b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/modexp.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.berlin.vm.precompiled_contracts.modexp". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementation of the `MODEXP` precompiled contract. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. -Require ethereum.berlin.vm.__init__. -Axiom ethereum_berlin_vm___init___Evm : - IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Evm". +Axiom ethereum_berlin_vm_imports : + AreImported globals "ethereum.berlin.vm" [ "Evm" ]. -Require ethereum.berlin.vm.gas. -Axiom ethereum_berlin_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "charge_gas". +Axiom ethereum_berlin_vm_gas_imports : + AreImported globals "ethereum.berlin.vm.gas" [ "charge_gas" ]. -Require ethereum.berlin.vm.memory. -Axiom ethereum_berlin_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.berlin.vm.memory.globals "buffer_read". +Axiom ethereum_berlin_vm_memory_imports : + AreImported globals "ethereum.berlin.vm.memory" [ "buffer_read" ]. Definition GQUADDIVISOR : Value.t := M.run ltac:(M.monadic ( Constant.int 3 diff --git a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/ripemd160.v index 0ec622a..279665c 100644 --- a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/ripemd160.v +++ b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/ripemd160.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.berlin.vm.precompiled_contracts.ripemd160". Definition expr_1 : Value.t := Constant.str " @@ -19,29 +19,20 @@ Implementation of the `RIPEMD160` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_left_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.berlin.vm.__init__. -Axiom ethereum_berlin_vm___init___Evm : - IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Evm". +Axiom ethereum_berlin_vm_imports : + AreImported globals "ethereum.berlin.vm" [ "Evm" ]. -Require ethereum.berlin.vm.gas. -Axiom ethereum_berlin_vm_gas_GAS_RIPEMD160 : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_RIPEMD160". -Axiom ethereum_berlin_vm_gas_GAS_RIPEMD160_WORD : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_RIPEMD160_WORD". -Axiom ethereum_berlin_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "charge_gas". +Axiom ethereum_berlin_vm_gas_imports : + AreImported globals "ethereum.berlin.vm.gas" [ "GAS_RIPEMD160"; "GAS_RIPEMD160_WORD"; "charge_gas" ]. Definition ripemd160 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/sha256.v index cd17f78..6d0aeb8 100644 --- a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/sha256.v +++ b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/sha256.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.berlin.vm.precompiled_contracts.sha256". Definition expr_1 : Value.t := Constant.str " @@ -19,25 +19,17 @@ Implementation of the `SHA256` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.berlin.vm.__init__. -Axiom ethereum_berlin_vm___init___Evm : - IsGlobalAlias globals ethereum.berlin.vm.__init__.globals "Evm". +Axiom ethereum_berlin_vm_imports : + AreImported globals "ethereum.berlin.vm" [ "Evm" ]. -Require ethereum.berlin.vm.gas. -Axiom ethereum_berlin_vm_gas_GAS_SHA256 : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_SHA256". -Axiom ethereum_berlin_vm_gas_GAS_SHA256_WORD : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "GAS_SHA256_WORD". -Axiom ethereum_berlin_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.berlin.vm.gas.globals "charge_gas". +Axiom ethereum_berlin_vm_gas_imports : + AreImported globals "ethereum.berlin.vm.gas" [ "GAS_SHA256"; "GAS_SHA256_WORD"; "charge_gas" ]. Definition sha256 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/berlin/vm/runtime.v b/CoqOfPython/ethereum/berlin/vm/runtime.v index b70ed0d..3594c2e 100644 --- a/CoqOfPython/ethereum/berlin/vm/runtime.v +++ b/CoqOfPython/ethereum/berlin/vm/runtime.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.berlin.vm.runtime". Definition expr_1 : Value.t := Constant.str " @@ -17,17 +17,14 @@ Introduction Runtime related operations used while executing EVM code. ". -Require typing. -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". +Axiom typing_imports : + AreImported globals "typing" [ "Set" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.berlin.vm.instructions.__init__. -Axiom ethereum_berlin_vm_instructions___init___Ops : - IsGlobalAlias globals ethereum.berlin.vm.instructions.__init__.globals "Ops". +Axiom ethereum_berlin_vm_instructions_imports : + AreImported globals "ethereum.berlin.vm.instructions" [ "Ops" ]. Definition get_valid_jump_destinations : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -67,75 +64,83 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := ], make_dict [] |) in - While Compare.lt (| - M.get_name (| globals, "pc" |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "code" |) - ], - make_dict [] - |) - |) do -(* At stmt: unsupported node type: Try *) - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "current_opcode" |), - M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) - |), - (* then *) + let _ := + M.while (| + Compare.lt (| + M.get_name (| globals, "pc" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) + |), ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), - make_list [ - M.get_name (| globals, "pc" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( +(* At stmt: unsupported node type: Try *) let _ := (* if *) M.if_then_else (| - BoolOp.and (| - Compare.lt_e (| - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |), - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |) - |), - ltac:(M.monadic ( - Compare.lt_e (| - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH32" |), "value" |) - |) - )) + Compare.eq (| + M.get_name (| globals, "current_opcode" |), + M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) |), (* then *) ltac:(M.monadic ( - let push_data_size := - BinOp.add (| - BinOp.sub (| - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) - |), - Constant.int 1 - |) in - let pc := BinOp.add - M.get_name (| globals, "push_data_size" |) - M.get_name (| globals, "push_data_size" |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), + make_list [ + M.get_name (| globals, "pc" |) + ], + make_dict [] + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.lt_e (| + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |), + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH32" |), "value" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let push_data_size := + BinOp.add (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) + |), + Constant.int 1 + |) in + let pc := BinOp.add + M.get_name (| globals, "push_data_size" |) + M.get_name (| globals, "push_data_size" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ )) |) in + let pc := BinOp.add + Constant.int 1 + Constant.int 1 in M.pure Constant.None_ - )) |) in - let pc := BinOp.add - Constant.int 1 - Constant.int 1 in - EndWhile. + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.get_name (| globals, "valid_jump_destinations" |) |) in diff --git a/CoqOfPython/ethereum/berlin/vm/stack.v b/CoqOfPython/ethereum/berlin/vm/stack.v index 439d8f8..7371cbc 100644 --- a/CoqOfPython/ethereum/berlin/vm/stack.v +++ b/CoqOfPython/ethereum/berlin/vm/stack.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.berlin.vm.stack". Definition expr_1 : Value.t := Constant.str " @@ -17,19 +17,14 @@ Introduction Implementation of the stack operators for the EVM. ". -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". +Axiom typing_imports : + AreImported globals "typing" [ "List" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.berlin.vm.exceptions. -Axiom ethereum_berlin_vm_exceptions_StackOverflowError : - IsGlobalAlias globals ethereum.berlin.vm.exceptions.globals "StackOverflowError". -Axiom ethereum_berlin_vm_exceptions_StackUnderflowError : - IsGlobalAlias globals ethereum.berlin.vm.exceptions.globals "StackUnderflowError". +Axiom ethereum_berlin_vm_exceptions_imports : + AreImported globals "ethereum.berlin.vm.exceptions" [ "StackOverflowError"; "StackUnderflowError" ]. Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -63,7 +58,7 @@ Definition pop : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "StackUnderflowError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "StackUnderflowError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -108,7 +103,7 @@ Definition push : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "StackOverflowError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "StackOverflowError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/byzantium/__init__.v b/CoqOfPython/ethereum/byzantium/__init__.v index ee39b1c..f918721 100644 --- a/CoqOfPython/ethereum/byzantium/__init__.v +++ b/CoqOfPython/ethereum/byzantium/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.byzantium.__init__". Definition expr_1 : Value.t := Constant.str " @@ -9,9 +9,8 @@ lets contracts make non-state-changing calls to other contracts, and adds cryptographic primitives for layer 2 scaling. ". -Require ethereum.fork_criteria. -Axiom ethereum_fork_criteria_ByBlockNumber : - IsGlobalAlias globals ethereum.fork_criteria.globals "ByBlockNumber". +Axiom ethereum_fork_criteria_imports : + AreImported globals "ethereum.fork_criteria" [ "ByBlockNumber" ]. Definition FORK_CRITERIA : Value.t := M.run ltac:(M.monadic ( M.call (| diff --git a/CoqOfPython/ethereum/byzantium/blocks.v b/CoqOfPython/ethereum/byzantium/blocks.v index 706b6cc..a4c1ca1 100644 --- a/CoqOfPython/ethereum/byzantium/blocks.v +++ b/CoqOfPython/ethereum/byzantium/blocks.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.byzantium.blocks". Definition expr_1 : Value.t := Constant.str " @@ -14,43 +14,23 @@ history of all state transitions that have happened since the genesis of the chain. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes8 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes8". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". - -Require ethereum.byzantium.fork_types. -Axiom ethereum_byzantium_fork_types_Address : - IsGlobalAlias globals ethereum.byzantium.fork_types.globals "Address". -Axiom ethereum_byzantium_fork_types_Bloom : - IsGlobalAlias globals ethereum.byzantium.fork_types.globals "Bloom". -Axiom ethereum_byzantium_fork_types_Root : - IsGlobalAlias globals ethereum.byzantium.fork_types.globals "Root". - -Require ethereum.byzantium.transactions. -Axiom ethereum_byzantium_transactions_Transaction : - IsGlobalAlias globals ethereum.byzantium.transactions.globals "Transaction". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes8"; "Bytes32"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. + +Axiom ethereum_byzantium_fork_types_imports : + AreImported globals "ethereum.byzantium.fork_types" [ "Address"; "Bloom"; "Root" ]. + +Axiom ethereum_byzantium_transactions_imports : + AreImported globals "ethereum.byzantium.transactions" [ "Transaction" ]. Definition Header : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/byzantium/bloom.v b/CoqOfPython/ethereum/byzantium/bloom.v index 7342ee7..a89f7bc 100644 --- a/CoqOfPython/ethereum/byzantium/bloom.v +++ b/CoqOfPython/ethereum/byzantium/bloom.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.byzantium.bloom". Definition expr_1 : Value.t := Constant.str " @@ -21,25 +21,20 @@ for efficient searching of logs by address and/or topic, by rapidly eliminating blocks and receipts from their search. ". -Require typing. -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_imports : + AreImported globals "typing" [ "Tuple" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. -Require ethereum.byzantium.blocks. -Axiom ethereum_byzantium_blocks_Log : - IsGlobalAlias globals ethereum.byzantium.blocks.globals "Log". +Axiom ethereum_byzantium_blocks_imports : + AreImported globals "ethereum.byzantium.blocks" [ "Log" ]. -Require ethereum.byzantium.fork_types. -Axiom ethereum_byzantium_fork_types_Bloom : - IsGlobalAlias globals ethereum.byzantium.fork_types.globals "Bloom". +Axiom ethereum_byzantium_fork_types_imports : + AreImported globals "ethereum.byzantium.fork_types" [ "Bloom" ]. Definition add_to_bloom : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -66,50 +61,70 @@ Definition add_to_bloom : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "idx" |) in make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ] do - let bit_to_set := - BinOp.bit_and (| - M.call (| - M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "hash" |), M.slice (| M.get_name (| globals, "idx" |), BinOp.add (| - M.get_name (| globals, "idx" |), - Constant.int 2 - |) |) |) - ], - make_dict [] - |), - Constant.int 2047 - |) in - let bit_index := - BinOp.sub (| - Constant.int 2047, - M.get_name (| globals, "bit_to_set" |) - |) in - let byte_index := - BinOp.floor_div (| - M.get_name (| globals, "bit_index" |), - Constant.int 8 - |) in - let bit_value := - BinOp.l_shift (| - Constant.int 1, - BinOp.sub (| - Constant.int 7, - BinOp.mod_ (| + let _ := + M.for_ (| + M.get_name (| globals, "idx" |), + make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ], + ltac:(M.monadic ( + let bit_to_set := + BinOp.bit_and (| + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.slice (| + M.get_name (| globals, "hash" |), + M.get_name (| globals, "idx" |), + BinOp.add (| + M.get_name (| globals, "idx" |), + Constant.int 2 + |), + Constant.None_ + |) + ], + make_dict [] + |), + Constant.int 2047 + |) in + let bit_index := + BinOp.sub (| + Constant.int 2047, + M.get_name (| globals, "bit_to_set" |) + |) in + let byte_index := + BinOp.floor_div (| M.get_name (| globals, "bit_index" |), Constant.int 8 + |) in + let bit_value := + BinOp.l_shift (| + Constant.int 1, + BinOp.sub (| + Constant.int 7, + BinOp.mod_ (| + M.get_name (| globals, "bit_index" |), + Constant.int 8 + |) + |) + |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "bloom" |), + M.get_name (| globals, "byte_index" |) + |), + BinOp.bit_or (| + M.get_subscript (| + M.get_name (| globals, "bloom" |), + M.get_name (| globals, "byte_index" |) + |), + M.get_name (| globals, "bit_value" |) |) - |) - |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), - BinOp.bit_or (| - M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), - M.get_name (| globals, "bit_value" |) - |) - |) in - EndFor. + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_)). Definition logs_bloom : Value.t -> Value.t -> M := @@ -132,8 +147,12 @@ Definition logs_bloom : Value.t -> Value.t -> M := the caller address and the log topics. " in (* At stmt: unsupported node type: AnnAssign *) - For M.get_name (| globals, "log" |) in M.get_name (| globals, "logs" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "log" |), + M.get_name (| globals, "logs" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "add_to_bloom" |), make_list [ M.get_name (| globals, "bloom" |); @@ -141,8 +160,12 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "topic" |) in M.get_field (| M.get_name (| globals, "log" |), "topics" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "topic" |), + M.get_field (| M.get_name (| globals, "log" |), "topics" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "add_to_bloom" |), make_list [ M.get_name (| globals, "bloom" |); @@ -150,8 +173,18 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Bloom" |), diff --git a/CoqOfPython/ethereum/byzantium/fork.v b/CoqOfPython/ethereum/byzantium/fork.v index c956ddc..ed39b3d 100644 --- a/CoqOfPython/ethereum/byzantium/fork.v +++ b/CoqOfPython/ethereum/byzantium/fork.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.byzantium.fork". Definition expr_1 : Value.t := Constant.str " @@ -17,139 +17,62 @@ Introduction Entry point for the Ethereum specification. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". - -Require ethereum.crypto.elliptic_curve. -Axiom ethereum_crypto_elliptic_curve_SECP256K1N : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". -Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.ethash. -Axiom ethereum_ethash_dataset_size : - IsGlobalAlias globals ethereum.ethash.globals "dataset_size". -Axiom ethereum_ethash_generate_cache : - IsGlobalAlias globals ethereum.ethash.globals "generate_cache". -Axiom ethereum_ethash_hashimoto_light : - IsGlobalAlias globals ethereum.ethash.globals "hashimoto_light". - -Require ethereum.exceptions. -Axiom ethereum_exceptions_InvalidBlock : - IsGlobalAlias globals ethereum.exceptions.globals "InvalidBlock". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U64 : - IsGlobalAlias globals ethereum.base_types.globals "U64". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_U256_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.byzantium.__init__. -Axiom ethereum_byzantium___init___vm : - IsGlobalAlias globals ethereum.byzantium.__init__.globals "vm". - -Require ethereum.byzantium.blocks. -Axiom ethereum_byzantium_blocks_Block : - IsGlobalAlias globals ethereum.byzantium.blocks.globals "Block". -Axiom ethereum_byzantium_blocks_Header : - IsGlobalAlias globals ethereum.byzantium.blocks.globals "Header". -Axiom ethereum_byzantium_blocks_Log : - IsGlobalAlias globals ethereum.byzantium.blocks.globals "Log". -Axiom ethereum_byzantium_blocks_Receipt : - IsGlobalAlias globals ethereum.byzantium.blocks.globals "Receipt". - -Require ethereum.byzantium.bloom. -Axiom ethereum_byzantium_bloom_logs_bloom : - IsGlobalAlias globals ethereum.byzantium.bloom.globals "logs_bloom". - -Require ethereum.byzantium.fork_types. -Axiom ethereum_byzantium_fork_types_Address : - IsGlobalAlias globals ethereum.byzantium.fork_types.globals "Address". -Axiom ethereum_byzantium_fork_types_Bloom : - IsGlobalAlias globals ethereum.byzantium.fork_types.globals "Bloom". -Axiom ethereum_byzantium_fork_types_Root : - IsGlobalAlias globals ethereum.byzantium.fork_types.globals "Root". - -Require ethereum.byzantium.state. -Axiom ethereum_byzantium_state_State : - IsGlobalAlias globals ethereum.byzantium.state.globals "State". -Axiom ethereum_byzantium_state_account_exists_and_is_empty : - IsGlobalAlias globals ethereum.byzantium.state.globals "account_exists_and_is_empty". -Axiom ethereum_byzantium_state_create_ether : - IsGlobalAlias globals ethereum.byzantium.state.globals "create_ether". -Axiom ethereum_byzantium_state_destroy_account : - IsGlobalAlias globals ethereum.byzantium.state.globals "destroy_account". -Axiom ethereum_byzantium_state_get_account : - IsGlobalAlias globals ethereum.byzantium.state.globals "get_account". -Axiom ethereum_byzantium_state_increment_nonce : - IsGlobalAlias globals ethereum.byzantium.state.globals "increment_nonce". -Axiom ethereum_byzantium_state_set_account_balance : - IsGlobalAlias globals ethereum.byzantium.state.globals "set_account_balance". -Axiom ethereum_byzantium_state_state_root : - IsGlobalAlias globals ethereum.byzantium.state.globals "state_root". - -Require ethereum.byzantium.transactions. -Axiom ethereum_byzantium_transactions_TX_BASE_COST : - IsGlobalAlias globals ethereum.byzantium.transactions.globals "TX_BASE_COST". -Axiom ethereum_byzantium_transactions_TX_CREATE_COST : - IsGlobalAlias globals ethereum.byzantium.transactions.globals "TX_CREATE_COST". -Axiom ethereum_byzantium_transactions_TX_DATA_COST_PER_NON_ZERO : - IsGlobalAlias globals ethereum.byzantium.transactions.globals "TX_DATA_COST_PER_NON_ZERO". -Axiom ethereum_byzantium_transactions_TX_DATA_COST_PER_ZERO : - IsGlobalAlias globals ethereum.byzantium.transactions.globals "TX_DATA_COST_PER_ZERO". -Axiom ethereum_byzantium_transactions_Transaction : - IsGlobalAlias globals ethereum.byzantium.transactions.globals "Transaction". - -Require ethereum.byzantium.trie. -Axiom ethereum_byzantium_trie_Trie : - IsGlobalAlias globals ethereum.byzantium.trie.globals "Trie". -Axiom ethereum_byzantium_trie_root : - IsGlobalAlias globals ethereum.byzantium.trie.globals "root". -Axiom ethereum_byzantium_trie_trie_set : - IsGlobalAlias globals ethereum.byzantium.trie.globals "trie_set". - -Require ethereum.byzantium.utils.message. -Axiom ethereum_byzantium_utils_message_prepare_message : - IsGlobalAlias globals ethereum.byzantium.utils.message.globals "prepare_message". - -Require ethereum.byzantium.vm.interpreter. -Axiom ethereum_byzantium_vm_interpreter_process_message_call : - IsGlobalAlias globals ethereum.byzantium.vm.interpreter.globals "process_message_call". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Bytes0" ]. + +Axiom ethereum_crypto_elliptic_curve_imports : + AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. + +Axiom ethereum_ethash_imports : + AreImported globals "ethereum.ethash" [ "dataset_size"; "generate_cache"; "hashimoto_light" ]. + +Axiom ethereum_exceptions_imports : + AreImported globals "ethereum.exceptions" [ "InvalidBlock" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U64"; "U256"; "U256_CEIL_VALUE"; "Bytes"; "Uint" ]. + +Axiom ethereum_byzantium_imports : + AreImported globals "ethereum.byzantium" [ "vm" ]. + +Axiom ethereum_byzantium_blocks_imports : + AreImported globals "ethereum.byzantium.blocks" [ "Block"; "Header"; "Log"; "Receipt" ]. + +Axiom ethereum_byzantium_bloom_imports : + AreImported globals "ethereum.byzantium.bloom" [ "logs_bloom" ]. + +Axiom ethereum_byzantium_fork_types_imports : + AreImported globals "ethereum.byzantium.fork_types" [ "Address"; "Bloom"; "Root" ]. + +Axiom ethereum_byzantium_state_imports : + AreImported globals "ethereum.byzantium.state" [ "State"; "account_exists_and_is_empty"; "create_ether"; "destroy_account"; "get_account"; "increment_nonce"; "set_account_balance"; "state_root" ]. + +Axiom ethereum_byzantium_transactions_imports : + AreImported globals "ethereum.byzantium.transactions" [ "TX_BASE_COST"; "TX_CREATE_COST"; "TX_DATA_COST_PER_NON_ZERO"; "TX_DATA_COST_PER_ZERO"; "Transaction" ]. + +Axiom ethereum_byzantium_trie_imports : + AreImported globals "ethereum.byzantium.trie" [ "Trie"; "root"; "trie_set" ]. + +Axiom ethereum_byzantium_utils_message_imports : + AreImported globals "ethereum.byzantium.utils.message" [ "prepare_message" ]. + +Axiom ethereum_byzantium_vm_interpreter_imports : + AreImported globals "ethereum.byzantium.vm.interpreter" [ "process_message_call" ]. Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -268,7 +191,12 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := Hashes of the recent 256 blocks in order of increasing block number. " in let recent_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) in + M.slice (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| Constant.int 255 |), + Constant.None_, + Constant.None_ + |) in let _ := (* if *) M.if_then_else (| @@ -294,17 +222,26 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := )) |) in let recent_block_hashes := make_list [] in - For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_blocks" |) do - let prev_block_hash := - M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "block" |), + M.get_name (| globals, "recent_blocks" |), + ltac:(M.monadic ( + let prev_block_hash := + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in + let _ := M.call (| M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), make_list [ M.get_name (| globals, "prev_block_hash" |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let most_recent_block_hash := M.call (| M.get_name (| globals, "keccak256" |), @@ -312,7 +249,10 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), make_list [ - M.get_field (| M.get_subscript (| M.get_name (| globals, "recent_blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) + M.get_field (| M.get_subscript (| + M.get_name (| globals, "recent_blocks" |), + UnOp.sub (| Constant.int 1 |) + |), "header" |) ], make_dict [] |) @@ -356,7 +296,10 @@ Definition state_transition : Value.t -> Value.t -> M := Block to apply to `chain`. " in let parent_header := - M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) in + M.get_field (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| Constant.int 1 |) + |), "header" |) in let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ @@ -476,7 +419,12 @@ Definition state_transition : Value.t -> Value.t -> M := ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) + M.slice (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| Constant.int 255 |), + Constant.None_, + Constant.None_ + |) |) in M.pure Constant.None_ (* else *) @@ -903,14 +851,18 @@ Definition apply_body : Value.t -> Value.t -> M := (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) - For make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "tx" |) ] in M.call (| - M.get_name (| globals, "enumerate" |), - make_list [ - M.get_name (| globals, "transactions" |) - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "tx" |) ], + M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "transactions" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ M.get_name (| globals, "transactions_trie" |); @@ -931,51 +883,51 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_address := - M.call (| - M.get_name (| globals, "check_transaction" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "gas_available" |); - M.get_name (| globals, "chain_id" |) - ], - make_dict [] - |) in - let env := - M.call (| - M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), - make_list [], - make_dict [] - |) in - let _ := M.assign (| - make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |); M.get_name (| globals, "error" |) ], - M.call (| - M.get_name (| globals, "process_transaction" |), - make_list [ - M.get_name (| globals, "env" |); - M.get_name (| globals, "tx" |) - ], - make_dict [] - |) - |) in - let gas_available := BinOp.sub - M.get_name (| globals, "gas_used" |) - M.get_name (| globals, "gas_used" |) in - let receipt := - M.call (| - M.get_name (| globals, "make_receipt" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "error" |); - BinOp.sub (| - M.get_name (| globals, "block_gas_limit" |), - M.get_name (| globals, "gas_available" |) - |); - M.get_name (| globals, "logs" |) - ], - make_dict [] - |) in - let _ := M.call (| + let sender_address := + M.call (| + M.get_name (| globals, "check_transaction" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "gas_available" |); + M.get_name (| globals, "chain_id" |) + ], + make_dict [] + |) in + let env := + M.call (| + M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |); M.get_name (| globals, "error" |) ], + M.call (| + M.get_name (| globals, "process_transaction" |), + make_list [ + M.get_name (| globals, "env" |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) in + let gas_available := BinOp.sub + M.get_name (| globals, "gas_used" |) + M.get_name (| globals, "gas_used" |) in + let receipt := + M.call (| + M.get_name (| globals, "make_receipt" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "error" |); + BinOp.sub (| + M.get_name (| globals, "block_gas_limit" |), + M.get_name (| globals, "gas_available" |) + |); + M.get_name (| globals, "logs" |) + ], + make_dict [] + |) in + let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ M.get_name (| globals, "receipts_trie" |); @@ -996,10 +948,15 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_logs := BinOp.add - M.get_name (| globals, "logs" |) - M.get_name (| globals, "logs" |) in - EndFor. + let block_logs := BinOp.add + M.get_name (| globals, "logs" |) + M.get_name (| globals, "logs" |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.call (| M.get_name (| globals, "pay_rewards" |), make_list [ @@ -1128,8 +1085,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "ommer" |), + M.get_name (| globals, "ommers" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ BoolOp.and (| @@ -1148,15 +1109,18 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_parent_header := - M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), BinOp.sub (| - UnOp.sub (| BinOp.sub (| - M.get_field (| M.get_name (| globals, "block_header" |), "number" |), - M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) |), - Constant.int 1 - |) |), "header" |) in - let _ := M.call (| + let ommer_parent_header := + M.get_field (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + BinOp.sub (| + UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) |), + Constant.int 1 + |) + |), "header" |) in + let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ M.get_name (| globals, "ommer" |); @@ -1164,7 +1128,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1214,33 +1183,54 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let recent_canonical_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| BinOp.add (| - M.get_name (| globals, "MAX_OMMER_DEPTH" |), - Constant.int 1 - |) |), Constant.None_ |) |) in + M.slice (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| BinOp.add (| + M.get_name (| globals, "MAX_OMMER_DEPTH" |), + Constant.int 1 + |) |), + Constant.None_, + Constant.None_ + |) in let recent_canonical_block_hashes := Constant.str "(* At expr: unsupported node type: SetComp *)" in (* At stmt: unsupported node type: AnnAssign *) - For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_canonical_blocks" |) do - let recent_ommers_hashes := + let _ := + M.for_ (| + M.get_name (| globals, "block" |), + M.get_name (| globals, "recent_canonical_blocks" |), + ltac:(M.monadic ( + let recent_ommers_hashes := + M.call (| + M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), + make_list [ + Constant.str "(* At expr: unsupported node type: SetComp *)" + ], + make_dict [] + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "ommer_index" |); M.get_name (| globals, "ommer" |) ], M.call (| - M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), - make_list [ - Constant.str "(* At expr: unsupported node type: SetComp *)" - ], - make_dict [] - |) in - EndFor. - For make_tuple [ M.get_name (| globals, "ommer_index" |); M.get_name (| globals, "ommer" |) ] in M.call (| - M.get_name (| globals, "enumerate" |), - make_list [ - M.get_name (| globals, "ommers" |) - ], - make_dict [] - |) do - let ommer_hash := - M.get_subscript (| M.get_name (| globals, "ommers_hashes" |), M.get_name (| globals, "ommer_index" |) |) in - let _ := M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let ommer_hash := + M.get_subscript (| + M.get_name (| globals, "ommers_hashes" |), + M.get_name (| globals, "ommer_index" |) + |) in + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_eq (| @@ -1251,7 +1241,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_in (| @@ -1262,7 +1252,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_in (| @@ -1273,12 +1263,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_age := - BinOp.sub (| - M.get_field (| M.get_name (| globals, "block_header" |), "number" |), - M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) in - let _ := M.call (| + let ommer_age := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) in + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ BoolOp.and (| @@ -1297,10 +1287,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.in (| + Compare.in_ (| M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), M.get_name (| globals, "recent_canonical_block_hashes" |) |); @@ -1308,7 +1298,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_eq (| @@ -1319,7 +1309,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_)). Definition pay_rewards : Value.t -> Value.t -> M := @@ -1376,30 +1371,34 @@ Definition pay_rewards : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do - let ommer_age := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - BinOp.sub (| - M.get_name (| globals, "block_number" |), - M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) - ], - make_dict [] - |) in - let ommer_miner_reward := - BinOp.floor_div (| - BinOp.mult (| - BinOp.sub (| - Constant.int 8, - M.get_name (| globals, "ommer_age" |) - |), - M.get_name (| globals, "BLOCK_REWARD" |) - |), - Constant.int 8 - |) in - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "ommer" |), + M.get_name (| globals, "ommers" |), + ltac:(M.monadic ( + let ommer_age := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "block_number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) + ], + make_dict [] + |) in + let ommer_miner_reward := + BinOp.floor_div (| + BinOp.mult (| + BinOp.sub (| + Constant.int 8, + M.get_name (| globals, "ommer_age" |) + |), + M.get_name (| globals, "BLOCK_REWARD" |) + |), + Constant.int 8 + |) in + let _ := M.call (| M.get_name (| globals, "create_ether" |), make_list [ M.get_name (| globals, "state" |); @@ -1408,7 +1407,12 @@ Definition pay_rewards : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_)). Definition process_transaction : Value.t -> Value.t -> M := @@ -1688,8 +1692,12 @@ Definition process_transaction : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "accounts_to_delete" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "output" |), "accounts_to_delete" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "destroy_account" |), make_list [ M.get_field (| M.get_name (| globals, "env" |), "state" |); @@ -1697,22 +1705,31 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. - For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "touched_accounts" |) do - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), - (* then *) + M.pure Constant.None_ + )), ltac:(M.monadic ( - let _ := M.call (| + M.pure Constant.None_ + )) + |) in + let _ := + M.for_ (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "output" |), "touched_accounts" |), + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "destroy_account" |), make_list [ M.get_field (| M.get_name (| globals, "env" |), "state" |); @@ -1720,12 +1737,17 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := M.return_ (| make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |); M.get_field (| M.get_name (| globals, "output" |), "error" |) ] |) in @@ -1813,28 +1835,37 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := " in let data_cost := Constant.int 0 in - For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "byte" |), - Constant.int 0 - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "byte" |), + M.get_field (| M.get_name (| globals, "tx" |), "data" |), ltac:(M.monadic ( - let data_cost := BinOp.add - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "byte" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let data_cost := BinOp.add - M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := (* if *) M.if_then_else (| @@ -2049,13 +2080,18 @@ Definition recover_sender : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "Address" |), make_list [ - M.get_subscript (| M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "public_key" |) - ], - make_dict [] - |), M.slice (| Constant.int 12, Constant.int 32 |) |) + M.slice (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), + Constant.int 12, + Constant.int 32, + Constant.None_ + |) ], make_dict [] |) diff --git a/CoqOfPython/ethereum/byzantium/fork_types.v b/CoqOfPython/ethereum/byzantium/fork_types.v index cc8e4a1..40d441b 100644 --- a/CoqOfPython/ethereum/byzantium/fork_types.v +++ b/CoqOfPython/ethereum/byzantium/fork_types.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.byzantium.fork_types". Definition expr_1 : Value.t := Constant.str " @@ -17,33 +17,17 @@ Introduction Types re-used throughout the specification, which are specific to Ethereum. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes20 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes20". -Axiom ethereum_base_types_Bytes256 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes20"; "Bytes256"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) diff --git a/CoqOfPython/ethereum/byzantium/state.v b/CoqOfPython/ethereum/byzantium/state.v index 1990b58..038c479 100644 --- a/CoqOfPython/ethereum/byzantium/state.v +++ b/CoqOfPython/ethereum/byzantium/state.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.byzantium.state". Definition expr_1 : Value.t := Constant.str " @@ -22,61 +22,23 @@ There is a distinction between an account that does not exist and `EMPTY_ACCOUNT`. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". -Axiom dataclasses_field : - IsGlobalAlias globals dataclasses.globals "field". - -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_modify : - IsGlobalAlias globals ethereum.base_types.globals "modify". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.byzantium.fork_types. -Axiom ethereum_byzantium_fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals ethereum.byzantium.fork_types.globals "EMPTY_ACCOUNT". -Axiom ethereum_byzantium_fork_types_Account : - IsGlobalAlias globals ethereum.byzantium.fork_types.globals "Account". -Axiom ethereum_byzantium_fork_types_Address : - IsGlobalAlias globals ethereum.byzantium.fork_types.globals "Address". -Axiom ethereum_byzantium_fork_types_Root : - IsGlobalAlias globals ethereum.byzantium.fork_types.globals "Root". - -Require ethereum.byzantium.trie. -Axiom ethereum_byzantium_trie_EMPTY_TRIE_ROOT : - IsGlobalAlias globals ethereum.byzantium.trie.globals "EMPTY_TRIE_ROOT". -Axiom ethereum_byzantium_trie_Trie : - IsGlobalAlias globals ethereum.byzantium.trie.globals "Trie". -Axiom ethereum_byzantium_trie_copy_trie : - IsGlobalAlias globals ethereum.byzantium.trie.globals "copy_trie". -Axiom ethereum_byzantium_trie_root : - IsGlobalAlias globals ethereum.byzantium.trie.globals "root". -Axiom ethereum_byzantium_trie_trie_get : - IsGlobalAlias globals ethereum.byzantium.trie.globals "trie_get". -Axiom ethereum_byzantium_trie_trie_set : - IsGlobalAlias globals ethereum.byzantium.trie.globals "trie_set". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass"; "field" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict"; "List"; "Optional"; "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "modify" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_byzantium_fork_types_imports : + AreImported globals "ethereum.byzantium.fork_types" [ "EMPTY_ACCOUNT"; "Account"; "Address"; "Root" ]. + +Axiom ethereum_byzantium_trie_imports : + AreImported globals "ethereum.byzantium.trie" [ "EMPTY_TRIE_ROOT"; "Trie"; "copy_trie"; "root"; "trie_get"; "trie_set" ]. Definition State : Value.t := builtins.make_klass @@ -338,13 +300,16 @@ Definition destroy_storage : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -479,7 +444,10 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), + M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |), M.get_name (| globals, "trie" |) |) in M.pure Constant.None_ @@ -505,7 +473,10 @@ Definition set_storage : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -535,7 +506,7 @@ Definition storage_root : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), @@ -545,7 +516,10 @@ Definition storage_root : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "root" |), make_list [ - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) + M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |) ], make_dict [] |) diff --git a/CoqOfPython/ethereum/byzantium/transactions.v b/CoqOfPython/ethereum/byzantium/transactions.v index 2627592..a47dce9 100644 --- a/CoqOfPython/ethereum/byzantium/transactions.v +++ b/CoqOfPython/ethereum/byzantium/transactions.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.byzantium.transactions". Definition expr_1 : Value.t := Constant.str " @@ -9,29 +9,17 @@ submitted to be executed. If Ethereum is viewed as a state machine, transactions are the events that move between states. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.byzantium.fork_types. -Axiom ethereum_byzantium_fork_types_Address : - IsGlobalAlias globals ethereum.byzantium.fork_types.globals "Address". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Union" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_byzantium_fork_types_imports : + AreImported globals "ethereum.byzantium.fork_types" [ "Address" ]. Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( Constant.int 21000 diff --git a/CoqOfPython/ethereum/byzantium/trie.v b/CoqOfPython/ethereum/byzantium/trie.v index 1e0a81c..93b8822 100644 --- a/CoqOfPython/ethereum/byzantium/trie.v +++ b/CoqOfPython/ethereum/byzantium/trie.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.byzantium.trie". Definition expr_1 : Value.t := Constant.str " @@ -20,83 +20,38 @@ The state trie is the structure responsible for storing (* At top_level_stmt: unsupported node type: Import *) -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". -Axiom dataclasses_field : - IsGlobalAlias globals dataclasses.globals "field". - -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". -Axiom typing_Generic : - IsGlobalAlias globals typing.globals "Generic". -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Mapping : - IsGlobalAlias globals typing.globals "Mapping". -Axiom typing_MutableMapping : - IsGlobalAlias globals typing.globals "MutableMapping". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Sequence : - IsGlobalAlias globals typing.globals "Sequence". -Axiom typing_TypeVar : - IsGlobalAlias globals typing.globals "TypeVar". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". -Axiom typing_cast : - IsGlobalAlias globals typing.globals "cast". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.spurious_dragon.__init__. -Axiom ethereum_spurious_dragon___init___trie : - IsGlobalAlias globals ethereum.spurious_dragon.__init__.globals "trie". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.utils.hexadecimal. -Axiom ethereum_utils_hexadecimal_hex_to_bytes : - IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.byzantium.blocks. -Axiom ethereum_byzantium_blocks_Receipt : - IsGlobalAlias globals ethereum.byzantium.blocks.globals "Receipt". - -Require ethereum.byzantium.fork_types. -Axiom ethereum_byzantium_fork_types_Account : - IsGlobalAlias globals ethereum.byzantium.fork_types.globals "Account". -Axiom ethereum_byzantium_fork_types_Address : - IsGlobalAlias globals ethereum.byzantium.fork_types.globals "Address". -Axiom ethereum_byzantium_fork_types_Root : - IsGlobalAlias globals ethereum.byzantium.fork_types.globals "Root". -Axiom ethereum_byzantium_fork_types_encode_account : - IsGlobalAlias globals ethereum.byzantium.fork_types.globals "encode_account". - -Require ethereum.byzantium.transactions. -Axiom ethereum_byzantium_transactions_Transaction : - IsGlobalAlias globals ethereum.byzantium.transactions.globals "Transaction". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass"; "field" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict"; "Generic"; "List"; "Mapping"; "MutableMapping"; "Optional"; "Sequence"; "TypeVar"; "Union"; "cast" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. + +Axiom ethereum_spurious_dragon_imports : + AreImported globals "ethereum.spurious_dragon" [ "trie" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_utils_hexadecimal_imports : + AreImported globals "ethereum.utils.hexadecimal" [ "hex_to_bytes" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_byzantium_blocks_imports : + AreImported globals "ethereum.byzantium.blocks" [ "Receipt" ]. + +Axiom ethereum_byzantium_fork_types_imports : + AreImported globals "ethereum.byzantium.fork_types" [ "Account"; "Address"; "Root"; "encode_account" ]. + +Axiom ethereum_byzantium_transactions_imports : + AreImported globals "ethereum.byzantium.transactions" [ "Transaction" ]. Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -115,7 +70,10 @@ Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( )). Definition Node : Value.t := M.run ltac:(M.monadic ( - M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Bytes" |); M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |); Constant.None_ ] |) + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Bytes" |); M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |); Constant.None_ ] + |) )). Definition K : Value.t := M.run ltac:(M.monadic ( @@ -133,11 +91,23 @@ Definition V : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "TypeVar" |), make_list [ Constant.str "V"; - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Account" |) |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Bytes" |) |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Account" |) + |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Bytes" |) + |); M.get_name (| globals, "Bytes" |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Transaction" |) |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Receipt" |) |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Transaction" |) + |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Receipt" |) + |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |) ], @@ -176,7 +146,10 @@ Definition BranchNode : Value.t := ]. Definition InternalNode : Value.t := M.run ltac:(M.monadic ( - M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LeafNode" |); M.get_name (| globals, "ExtensionNode" |); M.get_name (| globals, "BranchNode" |) ] |) + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "LeafNode" |); M.get_name (| globals, "ExtensionNode" |); M.get_name (| globals, "BranchNode" |) ] + |) )). Definition encode_internal_node : Value.t -> Value.t -> M := @@ -288,7 +261,7 @@ Definition encode_internal_node : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "(* At expr: unsupported node type: JoinedStr *)" @@ -528,13 +501,16 @@ Definition trie_set : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "key" |), M.get_field (| M.get_name (| globals, "trie" |), "_data" |) |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + M.get_name (| globals, "key" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -544,7 +520,10 @@ Definition trie_set : Value.t -> Value.t -> M := (* else *) )), ltac:(M.monadic ( let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), + M.get_subscript (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + M.get_name (| globals, "key" |) + |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_ @@ -589,51 +568,66 @@ Definition common_prefix_length : Value.t -> Value.t -> M := let _ := Constant.str " Find the longest common prefix of two sequences. " in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "a" |) - ], - make_dict [] - |) - ], - make_dict [] - |) do - let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| - M.get_name (| globals, "i" |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "b" |) - ], - make_dict [] - |) - |), - ltac:(M.monadic ( - Compare.not_eq (| - M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), - M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) - |) - )) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + ], + make_dict [] + |), ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "i" |) - |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_subscript (| + M.get_name (| globals, "a" |), + M.get_name (| globals, "i" |) + |), + M.get_subscript (| + M.get_name (| globals, "b" |), + M.get_name (| globals, "i" |) + |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "len" |), @@ -718,38 +712,53 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 0; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |); - Constant.int 2 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ BinOp.add (| BinOp.mult (| Constant.int 16, - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "i" |) + |) |), - M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) + |) |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -767,43 +776,61 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := Constant.int 1 |) |), - M.get_subscript (| M.get_name (| globals, "x" |), Constant.int 0 |) + M.get_subscript (| + M.get_name (| globals, "x" |), + Constant.int 0 + |) |) ], make_dict [] |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 1; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |); - Constant.int 2 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 1; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ BinOp.add (| BinOp.mult (| Constant.int 16, - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "i" |) + |) |), - M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) + |) |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -850,40 +877,55 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := ], make_dict [] |) in - For make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ] in M.call (| - M.get_name (| globals, "enumerate" |), - make_list [ - M.get_name (| globals, "bytes_" |) - ], - make_dict [] - |) do - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.mult (| - M.get_name (| globals, "byte_index" |), - Constant.int 2 - |) |), - BinOp.r_shift (| - BinOp.bit_and (| - M.get_name (| globals, "byte" |), - Constant.int 240 - |), - Constant.int 4 - |) - |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "byte_index" |), - Constant.int 2 - |), - Constant.int 1 - |) |), - BinOp.bit_and (| - M.get_name (| globals, "byte" |), - Constant.int 15 - |) - |) in - EndFor. + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ], + M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "bytes_" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "nibble_list" |), + BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |) + |), + BinOp.r_shift (| + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 240 + |), + Constant.int 4 + |) + |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "nibble_list" |), + BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |), + Constant.int 1 + |) + |), + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 15 + |) + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Bytes" |), @@ -916,65 +958,69 @@ Definition _prepare_trie : Value.t -> Value.t -> M := Object with keys mapped to nibble-byte form. " in (* At stmt: unsupported node type: AnnAssign *) - For make_tuple [ M.get_name (| globals, "preimage" |); M.get_name (| globals, "value" |) ] in M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "items" |), - make_list [], - make_dict [] - |) do - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "value" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "preimage" |); M.get_name (| globals, "value" |) ], + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "items" |), + make_list [], + make_dict [] + |), ltac:(M.monadic ( - let _ := M.assert (| Compare.is_not (| + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in - let address := - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in - let encoded_value := - M.call (| - M.get_name (| globals, "encode_node" |), - make_list [ - M.get_name (| globals, "value" |); + let address := M.call (| - M.get_name (| globals, "get_storage_root" |), + M.get_name (| globals, "Address" |), make_list [ - M.get_name (| globals, "address" |) + M.get_name (| globals, "preimage" |) ], make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let encoded_value := - M.call (| - M.get_name (| globals, "encode_node" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - )) |) in - let _ := M.call (| + |) in + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |); + M.call (| + M.get_name (| globals, "get_storage_root" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_eq (| @@ -986,38 +1032,46 @@ Definition _prepare_trie : Value.t -> Value.t -> M := make_dict [] |) in (* At stmt: unsupported node type: AnnAssign *) - let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "trie" |), "secured" |), - (* then *) - ltac:(M.monadic ( - let key := - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "trie" |), "secured" |), + (* then *) + ltac:(M.monadic ( + let key := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let key := + M.get_name (| globals, "preimage" |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "mapped" |), + M.call (| + M.get_name (| globals, "bytes_to_nibble_list" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |) + |), + M.get_name (| globals, "encoded_value" |) + |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let key := - M.get_name (| globals, "preimage" |) in + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "mapped" |), M.call (| - M.get_name (| globals, "bytes_to_nibble_list" |), - make_list [ - M.get_name (| globals, "key" |) - ], - make_dict [] - |) |), - M.get_name (| globals, "encoded_value" |) - |) in - EndFor. + )) + |) in let _ := M.return_ (| M.get_name (| globals, "mapped" |) |) in @@ -1210,8 +1264,16 @@ Definition patricialize : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "LeafNode" |), make_list [ - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |); - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) + M.slice (| + M.get_name (| globals, "arbitrary_key" |), + M.get_name (| globals, "level" |), + Constant.None_, + Constant.None_ + |); + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "arbitrary_key" |) + |) ], make_dict [] |) in @@ -1224,7 +1286,12 @@ Definition patricialize : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in let substring := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "arbitrary_key" |), + M.get_name (| globals, "level" |), + Constant.None_, + Constant.None_ + |) in let prefix_length := M.call (| M.get_name (| globals, "len" |), @@ -1233,39 +1300,53 @@ Definition patricialize : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do - let prefix_length := - M.call (| - M.get_name (| globals, "min" |), - make_list [ - M.get_name (| globals, "prefix_length" |); + let _ := + M.for_ (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "obj" |), + ltac:(M.monadic ( + let prefix_length := M.call (| - M.get_name (| globals, "common_prefix_length" |), + M.get_name (| globals, "min" |), make_list [ - M.get_name (| globals, "substring" |); - M.get_subscript (| M.get_name (| globals, "key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) + M.get_name (| globals, "prefix_length" |); + M.call (| + M.get_name (| globals, "common_prefix_length" |), + make_list [ + M.get_name (| globals, "substring" |); + M.slice (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "level" |), + Constant.None_, + Constant.None_ + |) + ], + make_dict [] + |) ], make_dict [] - |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "prefix_length" |), - Constant.int 0 - |), - (* then *) - ltac:(M.monadic ( - let _ := M.break (| |) in + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "prefix_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := (* if *) M.if_then_else (| @@ -1276,10 +1357,15 @@ Definition patricialize : Value.t -> Value.t -> M := (* then *) ltac:(M.monadic ( let prefix := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), BinOp.add (| + M.slice (| + M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |), - M.get_name (| globals, "prefix_length" |) - |) |) |) in + BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |), + Constant.None_ + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ExtensionNode" |), @@ -1312,70 +1398,106 @@ Definition patricialize : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) - For M.get_name (| globals, "_" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 16 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "_" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 16 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "branches" |), "append" |), make_list [ {} ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let value := Constant.bytes "" in - For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "key" |) - ], - make_dict [] - |), - M.get_name (| globals, "level" |) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "obj" |), ltac:(M.monadic ( let _ := (* if *) M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); - make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] - ], - make_dict [] + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |), + M.get_name (| globals, "level" |) |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "AssertionError" |)) |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "key" |) + |); + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "AssertionError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "key" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| + M.get_subscript (| + M.get_name (| globals, "branches" |), + M.get_subscript (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "level" |) + |) + |), + M.get_name (| globals, "key" |) + |), + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "key" |) + |) + |) in M.pure Constant.None_ )) |) in - let value := - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.assign (| - M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) - |) in + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "BranchNode" |), diff --git a/CoqOfPython/ethereum/byzantium/utils/__init__.v b/CoqOfPython/ethereum/byzantium/utils/__init__.v index 1baedea..418c984 100644 --- a/CoqOfPython/ethereum/byzantium/utils/__init__.v +++ b/CoqOfPython/ethereum/byzantium/utils/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.byzantium.utils.__init__". Definition expr_1 : Value.t := Constant.str " diff --git a/CoqOfPython/ethereum/byzantium/utils/address.v b/CoqOfPython/ethereum/byzantium/utils/address.v index 22d928a..5b41324 100644 --- a/CoqOfPython/ethereum/byzantium/utils/address.v +++ b/CoqOfPython/ethereum/byzantium/utils/address.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.byzantium.utils.address". Definition expr_1 : Value.t := Constant.str " @@ -18,31 +18,23 @@ Address specific functions used in this byzantium version of specification. ". -Require typing. -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". +Axiom typing_imports : + AreImported globals "typing" [ "Union" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_left_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. -Require ethereum.byzantium.fork_types. -Axiom ethereum_byzantium_fork_types_Address : - IsGlobalAlias globals ethereum.byzantium.fork_types.globals "Address". +Axiom ethereum_byzantium_fork_types_imports : + AreImported globals "ethereum.byzantium.fork_types" [ "Address" ]. Definition to_address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -64,11 +56,16 @@ Definition to_address : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "Address" |), make_list [ - M.get_subscript (| M.call (| - M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), - make_list [], - make_dict [] - |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) + M.slice (| + M.call (| + M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), + UnOp.sub (| Constant.int 20 |), + Constant.None_, + Constant.None_ + |) ], make_dict [] |) @@ -112,7 +109,12 @@ Definition compute_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "computed_address" |), + UnOp.sub (| Constant.int 20 |), + Constant.None_, + Constant.None_ + |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/byzantium/utils/hexadecimal.v b/CoqOfPython/ethereum/byzantium/utils/hexadecimal.v index 6847186..23c4d87 100644 --- a/CoqOfPython/ethereum/byzantium/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/byzantium/utils/hexadecimal.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.byzantium.utils.hexadecimal". Definition expr_1 : Value.t := Constant.str " @@ -18,17 +18,11 @@ Hexadecimal utility functions used in this specification, specific to Byzantium types. ". -Require ethereum.utils.hexadecimal. -Axiom ethereum_utils_hexadecimal_remove_hex_prefix : - IsGlobalAlias globals ethereum.utils.hexadecimal.globals "remove_hex_prefix". - -Require ethereum.byzantium.fork_types. -Axiom ethereum_byzantium_fork_types_Address : - IsGlobalAlias globals ethereum.byzantium.fork_types.globals "Address". -Axiom ethereum_byzantium_fork_types_Bloom : - IsGlobalAlias globals ethereum.byzantium.fork_types.globals "Bloom". -Axiom ethereum_byzantium_fork_types_Root : - IsGlobalAlias globals ethereum.byzantium.fork_types.globals "Root". +Axiom ethereum_utils_hexadecimal_imports : + AreImported globals "ethereum.utils.hexadecimal" [ "remove_hex_prefix" ]. + +Axiom ethereum_byzantium_fork_types_imports : + AreImported globals "ethereum.byzantium.fork_types" [ "Address"; "Bloom"; "Root" ]. Definition hex_to_root : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/byzantium/utils/message.v b/CoqOfPython/ethereum/byzantium/utils/message.v index f23befa..4003c44 100644 --- a/CoqOfPython/ethereum/byzantium/utils/message.v +++ b/CoqOfPython/ethereum/byzantium/utils/message.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.byzantium.utils.message". Definition expr_1 : Value.t := Constant.str " @@ -18,39 +18,23 @@ Message specific functions used in this byzantium version of specification. ". -Require typing. -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". +Axiom typing_imports : + AreImported globals "typing" [ "Optional"; "Union" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint" ]. -Require ethereum.byzantium.fork_types. -Axiom ethereum_byzantium_fork_types_Address : - IsGlobalAlias globals ethereum.byzantium.fork_types.globals "Address". +Axiom ethereum_byzantium_fork_types_imports : + AreImported globals "ethereum.byzantium.fork_types" [ "Address" ]. -Require ethereum.byzantium.state. -Axiom ethereum_byzantium_state_get_account : - IsGlobalAlias globals ethereum.byzantium.state.globals "get_account". +Axiom ethereum_byzantium_state_imports : + AreImported globals "ethereum.byzantium.state" [ "get_account" ]. -Require ethereum.byzantium.vm.__init__. -Axiom ethereum_byzantium_vm___init___Environment : - IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Environment". -Axiom ethereum_byzantium_vm___init___Message : - IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Message". +Axiom ethereum_byzantium_vm_imports : + AreImported globals "ethereum.byzantium.vm" [ "Environment"; "Message" ]. -Require ethereum.byzantium.utils.address. -Axiom ethereum_byzantium_utils_address_compute_contract_address : - IsGlobalAlias globals ethereum.byzantium.utils.address.globals "compute_contract_address". +Axiom ethereum_byzantium_utils_address_imports : + AreImported globals "ethereum.byzantium.utils.address" [ "compute_contract_address" ]. Definition prepare_message : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -183,7 +167,7 @@ Definition prepare_message : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "Target must be address or empty bytes" diff --git a/CoqOfPython/ethereum/byzantium/vm/__init__.v b/CoqOfPython/ethereum/byzantium/vm/__init__.v index c26fa07..3e2b32d 100644 --- a/CoqOfPython/ethereum/byzantium/vm/__init__.v +++ b/CoqOfPython/ethereum/byzantium/vm/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.byzantium.vm.__init__". Definition expr_1 : Value.t := Constant.str " @@ -18,53 +18,29 @@ The abstract computer which runs the code stored in an `.fork_types.Account`. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". - -Require ethereum.byzantium.blocks. -Axiom ethereum_byzantium_blocks_Log : - IsGlobalAlias globals ethereum.byzantium.blocks.globals "Log". - -Require ethereum.byzantium.fork_types. -Axiom ethereum_byzantium_fork_types_Address : - IsGlobalAlias globals ethereum.byzantium.fork_types.globals "Address". - -Require ethereum.byzantium.state. -Axiom ethereum_byzantium_state_State : - IsGlobalAlias globals ethereum.byzantium.state.globals "State". -Axiom ethereum_byzantium_state_account_exists_and_is_empty : - IsGlobalAlias globals ethereum.byzantium.state.globals "account_exists_and_is_empty". - -Require ethereum.byzantium.vm.precompiled_contracts.__init__. -Axiom ethereum_byzantium_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : - IsGlobalAlias globals ethereum.byzantium.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple"; "Union" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. + +Axiom ethereum_byzantium_blocks_imports : + AreImported globals "ethereum.byzantium.blocks" [ "Log" ]. + +Axiom ethereum_byzantium_fork_types_imports : + AreImported globals "ethereum.byzantium.fork_types" [ "Address" ]. + +Axiom ethereum_byzantium_state_imports : + AreImported globals "ethereum.byzantium.state" [ "State"; "account_exists_and_is_empty" ]. + +Axiom ethereum_byzantium_vm_precompiled_contracts_imports : + AreImported globals "ethereum.byzantium.vm.precompiled_contracts" [ "RIPEMD160_ADDRESS" ]. Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] @@ -185,7 +161,7 @@ Definition incorporate_child_on_error : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "RIPEMD160_ADDRESS" |), M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) |), diff --git a/CoqOfPython/ethereum/byzantium/vm/exceptions.v b/CoqOfPython/ethereum/byzantium/vm/exceptions.v index 23d00db..079a2a6 100644 --- a/CoqOfPython/ethereum/byzantium/vm/exceptions.v +++ b/CoqOfPython/ethereum/byzantium/vm/exceptions.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.byzantium.vm.exceptions". Definition expr_1 : Value.t := Constant.str " @@ -17,9 +17,8 @@ Introduction Exceptions which cause the EVM to halt exceptionally. ". -Require ethereum.exceptions. -Axiom ethereum_exceptions_EthereumException : - IsGlobalAlias globals ethereum.exceptions.globals "EthereumException". +Axiom ethereum_exceptions_imports : + AreImported globals "ethereum.exceptions" [ "EthereumException" ]. Definition ExceptionalHalt : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/byzantium/vm/gas.v b/CoqOfPython/ethereum/byzantium/vm/gas.v index 90d9c68..ea3b305 100644 --- a/CoqOfPython/ethereum/byzantium/vm/gas.v +++ b/CoqOfPython/ethereum/byzantium/vm/gas.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.byzantium.vm.gas". Definition expr_1 : Value.t := Constant.str " @@ -17,39 +17,26 @@ Introduction EVM gas constants and calculators. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Tuple" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. -Require ethereum.trace. -Axiom ethereum_trace_GasAndRefund : - IsGlobalAlias globals ethereum.trace.globals "GasAndRefund". -Axiom ethereum_trace_evm_trace : - IsGlobalAlias globals ethereum.trace.globals "evm_trace". +Axiom ethereum_trace_imports : + AreImported globals "ethereum.trace" [ "GasAndRefund"; "evm_trace" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.byzantium.vm.__init__. -Axiom ethereum_byzantium_vm___init___Evm : - IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Evm". +Axiom ethereum_byzantium_vm_imports : + AreImported globals "ethereum.byzantium.vm" [ "Evm" ]. -Require ethereum.byzantium.vm.exceptions. -Axiom ethereum_byzantium_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.byzantium.vm.exceptions.globals "OutOfGasError". +Axiom ethereum_byzantium_vm_exceptions_imports : + AreImported globals "ethereum.byzantium.vm.exceptions" [ "OutOfGasError" ]. Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -508,7 +495,7 @@ Definition charge_gas : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -625,105 +612,114 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := ], make_dict [] |) in - For make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ] in M.get_name (| globals, "extensions" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "size" |), - Constant.int 0 - |), - (* then *) + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ], + M.get_name (| globals, "extensions" |), ltac:(M.monadic ( - let _ := M.continue (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let before_size := - M.call (| - M.get_name (| globals, "ceil32" |), - make_list [ - M.get_name (| globals, "current_size" |) - ], - make_dict [] - |) in - let after_size := - M.call (| - M.get_name (| globals, "ceil32" |), - make_list [ - BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "size" |), + Constant.int 0 |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.lt_e (| - M.get_name (| globals, "after_size" |), - M.get_name (| globals, "before_size" |) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.continue (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let size_to_extend := BinOp.add - BinOp.sub (| + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let before_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "current_size" |) + ], + make_dict [] + |) in + let after_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let size_to_extend := BinOp.add + BinOp.sub (| M.get_name (| globals, "after_size" |), M.get_name (| globals, "before_size" |) |) - BinOp.sub (| + BinOp.sub (| M.get_name (| globals, "after_size" |), M.get_name (| globals, "before_size" |) |) in - let already_paid := - M.call (| - M.get_name (| globals, "calculate_memory_gas_cost" |), - make_list [ - M.get_name (| globals, "before_size" |) - ], - make_dict [] - |) in - let total_cost := - M.call (| - M.get_name (| globals, "calculate_memory_gas_cost" |), - make_list [ - M.get_name (| globals, "after_size" |) - ], - make_dict [] - |) in - let to_be_paid := BinOp.add - BinOp.sub (| + let already_paid := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "before_size" |) + ], + make_dict [] + |) in + let total_cost := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "after_size" |) + ], + make_dict [] + |) in + let to_be_paid := BinOp.add + BinOp.sub (| M.get_name (| globals, "total_cost" |), M.get_name (| globals, "already_paid" |) |) - BinOp.sub (| + BinOp.sub (| M.get_name (| globals, "total_cost" |), M.get_name (| globals, "already_paid" |) |) in - let current_size := - M.get_name (| globals, "after_size" |) in - EndFor. + let current_size := + M.get_name (| globals, "after_size" |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ExtendMemory" |), diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/__init__.v b/CoqOfPython/ethereum/byzantium/vm/instructions/__init__.v index 248e357..c27504a 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/__init__.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.byzantium.vm.instructions.__init__". Definition expr_1 : Value.t := Constant.str " @@ -20,59 +20,44 @@ implementations. (* At top_level_stmt: unsupported node type: Import *) -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict" ]. -Require ethereum.byzantium.vm.instructions.__init__. -Axiom ethereum_byzantium_vm_instructions___init___arithmetic : - IsGlobalAlias globals ethereum.byzantium.vm.instructions.__init__.globals "arithmetic". +Axiom ethereum_byzantium_vm_instructions_imports : + AreImported globals "ethereum.byzantium.vm.instructions" [ "arithmetic" ]. -Require ethereum.byzantium.vm.instructions.__init__. -Axiom ethereum_byzantium_vm_instructions___init___bitwise : - IsGlobalAlias globals ethereum.byzantium.vm.instructions.__init__.globals "bitwise". +Axiom ethereum_byzantium_vm_instructions_imports : + AreImported globals "ethereum.byzantium.vm.instructions" [ "bitwise" ]. -Require ethereum.byzantium.vm.instructions.__init__. -Axiom ethereum_byzantium_vm_instructions___init___block : - IsGlobalAlias globals ethereum.byzantium.vm.instructions.__init__.globals "block". +Axiom ethereum_byzantium_vm_instructions_imports : + AreImported globals "ethereum.byzantium.vm.instructions" [ "block" ]. -Require ethereum.byzantium.vm.instructions.__init__. -Axiom ethereum_byzantium_vm_instructions___init___comparison : - IsGlobalAlias globals ethereum.byzantium.vm.instructions.__init__.globals "comparison". +Axiom ethereum_byzantium_vm_instructions_imports : + AreImported globals "ethereum.byzantium.vm.instructions" [ "comparison" ]. -Require ethereum.byzantium.vm.instructions.__init__. -Axiom ethereum_byzantium_vm_instructions___init___control_flow : - IsGlobalAlias globals ethereum.byzantium.vm.instructions.__init__.globals "control_flow". +Axiom ethereum_byzantium_vm_instructions_imports : + AreImported globals "ethereum.byzantium.vm.instructions" [ "control_flow" ]. -Require ethereum.byzantium.vm.instructions.__init__. -Axiom ethereum_byzantium_vm_instructions___init___environment : - IsGlobalAlias globals ethereum.byzantium.vm.instructions.__init__.globals "environment". +Axiom ethereum_byzantium_vm_instructions_imports : + AreImported globals "ethereum.byzantium.vm.instructions" [ "environment" ]. -Require ethereum.byzantium.vm.instructions.__init__. -Axiom ethereum_byzantium_vm_instructions___init___keccak : - IsGlobalAlias globals ethereum.byzantium.vm.instructions.__init__.globals "keccak". +Axiom ethereum_byzantium_vm_instructions_imports : + AreImported globals "ethereum.byzantium.vm.instructions" [ "keccak" ]. -Require ethereum.byzantium.vm.instructions.__init__. -Axiom ethereum_byzantium_vm_instructions___init___log : - IsGlobalAlias globals ethereum.byzantium.vm.instructions.__init__.globals "log". +Axiom ethereum_byzantium_vm_instructions_imports : + AreImported globals "ethereum.byzantium.vm.instructions" [ "log" ]. -Require ethereum.byzantium.vm.instructions.__init__. -Axiom ethereum_byzantium_vm_instructions___init___memory : - IsGlobalAlias globals ethereum.byzantium.vm.instructions.__init__.globals "memory". +Axiom ethereum_byzantium_vm_instructions_imports : + AreImported globals "ethereum.byzantium.vm.instructions" [ "memory" ]. -Require ethereum.byzantium.vm.instructions.__init__. -Axiom ethereum_byzantium_vm_instructions___init___stack : - IsGlobalAlias globals ethereum.byzantium.vm.instructions.__init__.globals "stack". +Axiom ethereum_byzantium_vm_instructions_imports : + AreImported globals "ethereum.byzantium.vm.instructions" [ "stack" ]. -Require ethereum.byzantium.vm.instructions.__init__. -Axiom ethereum_byzantium_vm_instructions___init___storage : - IsGlobalAlias globals ethereum.byzantium.vm.instructions.__init__.globals "storage". +Axiom ethereum_byzantium_vm_instructions_imports : + AreImported globals "ethereum.byzantium.vm.instructions" [ "storage" ]. -Require ethereum.byzantium.vm.instructions.__init__. -Axiom ethereum_byzantium_vm_instructions___init___system : - IsGlobalAlias globals ethereum.byzantium.vm.instructions.__init__.globals "system". +Axiom ethereum_byzantium_vm_instructions_imports : + AreImported globals "ethereum.byzantium.vm.instructions" [ "system" ]. Definition Ops : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/byzantium/vm/instructions/arithmetic.v index ae4fb95..c9d385d 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/arithmetic.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.byzantium.vm.instructions.arithmetic". Definition expr_1 : Value.t := Constant.str " @@ -17,43 +17,20 @@ Introduction Implementations of the EVM Arithmetic instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U255_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U255_CEIL_VALUE". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_U256_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U255_CEIL_VALUE"; "U256"; "U256_CEIL_VALUE"; "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_get_sign : - IsGlobalAlias globals ethereum.utils.numeric.globals "get_sign". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "get_sign" ]. -Require ethereum.byzantium.vm.__init__. -Axiom ethereum_byzantium_vm___init___Evm : - IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Evm". +Axiom ethereum_byzantium_vm_imports : + AreImported globals "ethereum.byzantium.vm" [ "Evm" ]. -Require ethereum.byzantium.vm.gas. -Axiom ethereum_byzantium_vm_gas_GAS_EXPONENTIATION : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_EXPONENTIATION". -Axiom ethereum_byzantium_vm_gas_GAS_EXPONENTIATION_PER_BYTE : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_EXPONENTIATION_PER_BYTE". -Axiom ethereum_byzantium_vm_gas_GAS_LOW : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_LOW". -Axiom ethereum_byzantium_vm_gas_GAS_MID : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_MID". -Axiom ethereum_byzantium_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_byzantium_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "charge_gas". +Axiom ethereum_byzantium_vm_gas_imports : + AreImported globals "ethereum.byzantium.vm.gas" [ "GAS_EXPONENTIATION"; "GAS_EXPONENTIATION_PER_BYTE"; "GAS_LOW"; "GAS_MID"; "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.byzantium.vm.stack. -Axiom ethereum_byzantium_vm_stack_pop : - IsGlobalAlias globals ethereum.byzantium.vm.stack.globals "pop". -Axiom ethereum_byzantium_vm_stack_push : - IsGlobalAlias globals ethereum.byzantium.vm.stack.globals "push". +Axiom ethereum_byzantium_vm_stack_imports : + AreImported globals "ethereum.byzantium.vm.stack" [ "pop"; "push" ]. Definition add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -1030,19 +1007,27 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let value_bytes := - M.get_subscript (| M.get_name (| globals, "value_bytes" |), M.slice (| BinOp.sub (| - Constant.int 31, - M.call (| - M.get_name (| globals, "int" |), - make_list [ - M.get_name (| globals, "byte_num" |) - ], - make_dict [] - |) - |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "value_bytes" |), + BinOp.sub (| + Constant.int 31, + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "byte_num" |) + ], + make_dict [] + |) + |), + Constant.None_, + Constant.None_ + |) in let sign_bit := BinOp.r_shift (| - M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), + M.get_subscript (| + M.get_name (| globals, "value_bytes" |), + Constant.int 0 + |), Constant.int 7 |) in let _ := diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/bitwise.v b/CoqOfPython/ethereum/byzantium/vm/instructions/bitwise.v index e7643c3..ddb2396 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/bitwise.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.byzantium.vm.instructions.bitwise". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementations of the EVM bitwise instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.byzantium.vm.__init__. -Axiom ethereum_byzantium_vm___init___Evm : - IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Evm". +Axiom ethereum_byzantium_vm_imports : + AreImported globals "ethereum.byzantium.vm" [ "Evm" ]. -Require ethereum.byzantium.vm.gas. -Axiom ethereum_byzantium_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_byzantium_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "charge_gas". +Axiom ethereum_byzantium_vm_gas_imports : + AreImported globals "ethereum.byzantium.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.byzantium.vm.stack. -Axiom ethereum_byzantium_vm_stack_pop : - IsGlobalAlias globals ethereum.byzantium.vm.stack.globals "pop". -Axiom ethereum_byzantium_vm_stack_push : - IsGlobalAlias globals ethereum.byzantium.vm.stack.globals "push". +Axiom ethereum_byzantium_vm_stack_imports : + AreImported globals "ethereum.byzantium.vm.stack" [ "pop"; "push" ]. Definition bitwise_and : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/block.v b/CoqOfPython/ethereum/byzantium/vm/instructions/block.v index d25412d..3d8f83c 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/block.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/block.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.byzantium.vm.instructions.block". Definition expr_1 : Value.t := Constant.str " @@ -17,27 +17,17 @@ Introduction Implementations of the EVM block instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.byzantium.vm.__init__. -Axiom ethereum_byzantium_vm___init___Evm : - IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Evm". +Axiom ethereum_byzantium_vm_imports : + AreImported globals "ethereum.byzantium.vm" [ "Evm" ]. -Require ethereum.byzantium.vm.gas. -Axiom ethereum_byzantium_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_BASE". -Axiom ethereum_byzantium_vm_gas_GAS_BLOCK_HASH : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_BLOCK_HASH". -Axiom ethereum_byzantium_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "charge_gas". +Axiom ethereum_byzantium_vm_gas_imports : + AreImported globals "ethereum.byzantium.vm.gas" [ "GAS_BASE"; "GAS_BLOCK_HASH"; "charge_gas" ]. -Require ethereum.byzantium.vm.stack. -Axiom ethereum_byzantium_vm_stack_pop : - IsGlobalAlias globals ethereum.byzantium.vm.stack.globals "pop". -Axiom ethereum_byzantium_vm_stack_push : - IsGlobalAlias globals ethereum.byzantium.vm.stack.globals "push". +Axiom ethereum_byzantium_vm_stack_imports : + AreImported globals "ethereum.byzantium.vm.stack" [ "pop"; "push" ]. Definition block_hash : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -94,10 +84,13 @@ Definition block_hash : Value.t -> Value.t -> M := (* else *) )), ltac:(M.monadic ( let hash := - M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), - M.get_name (| globals, "block_number" |) - |) |) |) in + M.get_subscript (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), + UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + M.get_name (| globals, "block_number" |) + |) |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/comparison.v b/CoqOfPython/ethereum/byzantium/vm/instructions/comparison.v index 1f88ba2..7a7923c 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/comparison.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.byzantium.vm.instructions.comparison". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementations of the EVM Comparison instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.byzantium.vm.__init__. -Axiom ethereum_byzantium_vm___init___Evm : - IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Evm". +Axiom ethereum_byzantium_vm_imports : + AreImported globals "ethereum.byzantium.vm" [ "Evm" ]. -Require ethereum.byzantium.vm.gas. -Axiom ethereum_byzantium_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_byzantium_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "charge_gas". +Axiom ethereum_byzantium_vm_gas_imports : + AreImported globals "ethereum.byzantium.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.byzantium.vm.stack. -Axiom ethereum_byzantium_vm_stack_pop : - IsGlobalAlias globals ethereum.byzantium.vm.stack.globals "pop". -Axiom ethereum_byzantium_vm_stack_push : - IsGlobalAlias globals ethereum.byzantium.vm.stack.globals "push". +Axiom ethereum_byzantium_vm_stack_imports : + AreImported globals "ethereum.byzantium.vm.stack" [ "pop"; "push" ]. Definition less_than : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/control_flow.v b/CoqOfPython/ethereum/byzantium/vm/instructions/control_flow.v index ced2b03..fc0b158 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/control_flow.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.byzantium.vm.instructions.control_flow". Definition expr_1 : Value.t := Constant.str " @@ -17,37 +17,20 @@ Introduction Implementations of the EVM control flow instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. -Require ethereum.byzantium.vm.gas. -Axiom ethereum_byzantium_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_BASE". -Axiom ethereum_byzantium_vm_gas_GAS_HIGH : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_HIGH". -Axiom ethereum_byzantium_vm_gas_GAS_JUMPDEST : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_JUMPDEST". -Axiom ethereum_byzantium_vm_gas_GAS_MID : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_MID". -Axiom ethereum_byzantium_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "charge_gas". +Axiom ethereum_byzantium_vm_gas_imports : + AreImported globals "ethereum.byzantium.vm.gas" [ "GAS_BASE"; "GAS_HIGH"; "GAS_JUMPDEST"; "GAS_MID"; "charge_gas" ]. -Require ethereum.byzantium.vm.__init__. -Axiom ethereum_byzantium_vm___init___Evm : - IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Evm". +Axiom ethereum_byzantium_vm_imports : + AreImported globals "ethereum.byzantium.vm" [ "Evm" ]. -Require ethereum.byzantium.vm.exceptions. -Axiom ethereum_byzantium_vm_exceptions_InvalidJumpDestError : - IsGlobalAlias globals ethereum.byzantium.vm.exceptions.globals "InvalidJumpDestError". +Axiom ethereum_byzantium_vm_exceptions_imports : + AreImported globals "ethereum.byzantium.vm.exceptions" [ "InvalidJumpDestError" ]. -Require ethereum.byzantium.vm.stack. -Axiom ethereum_byzantium_vm_stack_pop : - IsGlobalAlias globals ethereum.byzantium.vm.stack.globals "pop". -Axiom ethereum_byzantium_vm_stack_push : - IsGlobalAlias globals ethereum.byzantium.vm.stack.globals "push". +Axiom ethereum_byzantium_vm_stack_imports : + AreImported globals "ethereum.byzantium.vm.stack" [ "pop"; "push" ]. Definition stop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -117,7 +100,7 @@ Definition jump : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "InvalidJumpDestError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -205,7 +188,7 @@ Definition jumpi : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "InvalidJumpDestError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/environment.v b/CoqOfPython/ethereum/byzantium/vm/instructions/environment.v index 9b8a11f..5ed3fbd 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/environment.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.byzantium.vm.instructions.environment". Definition expr_1 : Value.t := Constant.str " @@ -17,65 +17,35 @@ Introduction Implementations of the EVM environment related instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.byzantium.state. -Axiom ethereum_byzantium_state_get_account : - IsGlobalAlias globals ethereum.byzantium.state.globals "get_account". +Axiom ethereum_byzantium_state_imports : + AreImported globals "ethereum.byzantium.state" [ "get_account" ]. -Require ethereum.byzantium.utils.address. -Axiom ethereum_byzantium_utils_address_to_address : - IsGlobalAlias globals ethereum.byzantium.utils.address.globals "to_address". +Axiom ethereum_byzantium_utils_address_imports : + AreImported globals "ethereum.byzantium.utils.address" [ "to_address" ]. -Require ethereum.byzantium.vm.memory. -Axiom ethereum_byzantium_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.byzantium.vm.memory.globals "buffer_read". -Axiom ethereum_byzantium_vm_memory_memory_write : - IsGlobalAlias globals ethereum.byzantium.vm.memory.globals "memory_write". +Axiom ethereum_byzantium_vm_memory_imports : + AreImported globals "ethereum.byzantium.vm.memory" [ "buffer_read"; "memory_write" ]. -Require ethereum.byzantium.vm.__init__. -Axiom ethereum_byzantium_vm___init___Evm : - IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Evm". +Axiom ethereum_byzantium_vm_imports : + AreImported globals "ethereum.byzantium.vm" [ "Evm" ]. -Require ethereum.byzantium.vm.exceptions. -Axiom ethereum_byzantium_vm_exceptions_OutOfBoundsRead : - IsGlobalAlias globals ethereum.byzantium.vm.exceptions.globals "OutOfBoundsRead". +Axiom ethereum_byzantium_vm_exceptions_imports : + AreImported globals "ethereum.byzantium.vm.exceptions" [ "OutOfBoundsRead" ]. -Require ethereum.byzantium.vm.gas. -Axiom ethereum_byzantium_vm_gas_GAS_BALANCE : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_BALANCE". -Axiom ethereum_byzantium_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_BASE". -Axiom ethereum_byzantium_vm_gas_GAS_COPY : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_COPY". -Axiom ethereum_byzantium_vm_gas_GAS_EXTERNAL : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_EXTERNAL". -Axiom ethereum_byzantium_vm_gas_GAS_RETURN_DATA_COPY : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_RETURN_DATA_COPY". -Axiom ethereum_byzantium_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_byzantium_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_byzantium_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "charge_gas". +Axiom ethereum_byzantium_vm_gas_imports : + AreImported globals "ethereum.byzantium.vm.gas" [ "GAS_BALANCE"; "GAS_BASE"; "GAS_COPY"; "GAS_EXTERNAL"; "GAS_RETURN_DATA_COPY"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. -Require ethereum.byzantium.vm.stack. -Axiom ethereum_byzantium_vm_stack_pop : - IsGlobalAlias globals ethereum.byzantium.vm.stack.globals "pop". -Axiom ethereum_byzantium_vm_stack_push : - IsGlobalAlias globals ethereum.byzantium.vm.stack.globals "push". +Axiom ethereum_byzantium_vm_stack_imports : + AreImported globals "ethereum.byzantium.vm.stack" [ "pop"; "push" ]. Definition address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -1122,10 +1092,15 @@ Definition returndatacopy : Value.t -> Value.t -> M := |) |) in let value := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.slice (| M.get_name (| globals, "return_data_start_position" |), BinOp.add (| + M.slice (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |), - M.get_name (| globals, "size" |) - |) |) |) in + BinOp.add (| + M.get_name (| globals, "return_data_start_position" |), + M.get_name (| globals, "size" |) + |), + Constant.None_ + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/keccak.v b/CoqOfPython/ethereum/byzantium/vm/instructions/keccak.v index a9e0538..f65f159 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/keccak.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.byzantium.vm.instructions.keccak". Definition expr_1 : Value.t := Constant.str " @@ -17,43 +17,26 @@ Introduction Implementations of the EVM keccak instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". - -Require ethereum.byzantium.vm.__init__. -Axiom ethereum_byzantium_vm___init___Evm : - IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Evm". - -Require ethereum.byzantium.vm.gas. -Axiom ethereum_byzantium_vm_gas_GAS_KECCAK256 : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_KECCAK256". -Axiom ethereum_byzantium_vm_gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_KECCAK256_WORD". -Axiom ethereum_byzantium_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_byzantium_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "charge_gas". - -Require ethereum.byzantium.vm.memory. -Axiom ethereum_byzantium_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.byzantium.vm.memory.globals "memory_read_bytes". - -Require ethereum.byzantium.vm.stack. -Axiom ethereum_byzantium_vm_stack_pop : - IsGlobalAlias globals ethereum.byzantium.vm.stack.globals "pop". -Axiom ethereum_byzantium_vm_stack_push : - IsGlobalAlias globals ethereum.byzantium.vm.stack.globals "push". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. + +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. + +Axiom ethereum_byzantium_vm_imports : + AreImported globals "ethereum.byzantium.vm" [ "Evm" ]. + +Axiom ethereum_byzantium_vm_gas_imports : + AreImported globals "ethereum.byzantium.vm.gas" [ "GAS_KECCAK256"; "GAS_KECCAK256_WORD"; "calculate_gas_extend_memory"; "charge_gas" ]. + +Axiom ethereum_byzantium_vm_memory_imports : + AreImported globals "ethereum.byzantium.vm.memory" [ "memory_read_bytes" ]. + +Axiom ethereum_byzantium_vm_stack_imports : + AreImported globals "ethereum.byzantium.vm.stack" [ "pop"; "push" ]. Definition keccak : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/log.v b/CoqOfPython/ethereum/byzantium/vm/instructions/log.v index 7783692..cf021db 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/log.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/log.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.byzantium.vm.instructions.log". Definition expr_1 : Value.t := Constant.str " @@ -17,49 +17,32 @@ Introduction Implementations of the EVM logging instructions. ". -Require functools. -Axiom functools_partial : - IsGlobalAlias globals functools.globals "partial". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.byzantium.blocks. -Axiom ethereum_byzantium_blocks_Log : - IsGlobalAlias globals ethereum.byzantium.blocks.globals "Log". - -Require ethereum.byzantium.vm.__init__. -Axiom ethereum_byzantium_vm___init___Evm : - IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Evm". - -Require ethereum.byzantium.vm.exceptions. -Axiom ethereum_byzantium_vm_exceptions_WriteInStaticContext : - IsGlobalAlias globals ethereum.byzantium.vm.exceptions.globals "WriteInStaticContext". - -Require ethereum.byzantium.vm.gas. -Axiom ethereum_byzantium_vm_gas_GAS_LOG : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_LOG". -Axiom ethereum_byzantium_vm_gas_GAS_LOG_DATA : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_LOG_DATA". -Axiom ethereum_byzantium_vm_gas_GAS_LOG_TOPIC : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_LOG_TOPIC". -Axiom ethereum_byzantium_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_byzantium_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "charge_gas". - -Require ethereum.byzantium.vm.memory. -Axiom ethereum_byzantium_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.byzantium.vm.memory.globals "memory_read_bytes". - -Require ethereum.byzantium.vm.stack. -Axiom ethereum_byzantium_vm_stack_pop : - IsGlobalAlias globals ethereum.byzantium.vm.stack.globals "pop". +Axiom functools_imports : + AreImported globals "functools" [ "partial" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_byzantium_blocks_imports : + AreImported globals "ethereum.byzantium.blocks" [ "Log" ]. + +Axiom ethereum_byzantium_vm_imports : + AreImported globals "ethereum.byzantium.vm" [ "Evm" ]. + +Axiom ethereum_byzantium_vm_exceptions_imports : + AreImported globals "ethereum.byzantium.vm.exceptions" [ "WriteInStaticContext" ]. + +Axiom ethereum_byzantium_vm_gas_imports : + AreImported globals "ethereum.byzantium.vm.gas" [ "GAS_LOG"; "GAS_LOG_DATA"; "GAS_LOG_TOPIC"; "calculate_gas_extend_memory"; "charge_gas" ]. + +Axiom ethereum_byzantium_vm_memory_imports : + AreImported globals "ethereum.byzantium.vm.memory" [ "memory_read_bytes" ]. + +Axiom ethereum_byzantium_vm_stack_imports : + AreImported globals "ethereum.byzantium.vm.stack" [ "pop" ]. Definition log_n : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -96,33 +79,42 @@ Definition log_n : Value.t -> Value.t -> M := |) in let topics := make_list [] in - For M.get_name (| globals, "_" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - M.get_name (| globals, "num_topics" |) - ], - make_dict [] - |) do - let topic := + let _ := + M.for_ (| + M.get_name (| globals, "_" |), M.call (| - M.get_field (| M.call (| - M.get_name (| globals, "pop" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] - |), "to_be_bytes32" |), - make_list [], - make_dict [] - |) in - let _ := M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "num_topics" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let topic := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| M.get_field (| M.get_name (| globals, "topics" |), "append" |), make_list [ M.get_name (| globals, "topic" |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let extend_memory := M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/memory.v b/CoqOfPython/ethereum/byzantium/vm/instructions/memory.v index f2f5a5d..fd6b222 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/memory.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.byzantium.vm.instructions.memory". Definition expr_1 : Value.t := Constant.str " @@ -17,37 +17,20 @@ Introduction Implementations of the EVM Memory instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes" ]. -Require ethereum.byzantium.vm.__init__. -Axiom ethereum_byzantium_vm___init___Evm : - IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Evm". +Axiom ethereum_byzantium_vm_imports : + AreImported globals "ethereum.byzantium.vm" [ "Evm" ]. -Require ethereum.byzantium.vm.gas. -Axiom ethereum_byzantium_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_BASE". -Axiom ethereum_byzantium_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_byzantium_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_byzantium_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "charge_gas". +Axiom ethereum_byzantium_vm_gas_imports : + AreImported globals "ethereum.byzantium.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. -Require ethereum.byzantium.vm.memory. -Axiom ethereum_byzantium_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.byzantium.vm.memory.globals "memory_read_bytes". -Axiom ethereum_byzantium_vm_memory_memory_write : - IsGlobalAlias globals ethereum.byzantium.vm.memory.globals "memory_write". +Axiom ethereum_byzantium_vm_memory_imports : + AreImported globals "ethereum.byzantium.vm.memory" [ "memory_read_bytes"; "memory_write" ]. -Require ethereum.byzantium.vm.stack. -Axiom ethereum_byzantium_vm_stack_pop : - IsGlobalAlias globals ethereum.byzantium.vm.stack.globals "pop". -Axiom ethereum_byzantium_vm_stack_push : - IsGlobalAlias globals ethereum.byzantium.vm.stack.globals "push". +Axiom ethereum_byzantium_vm_stack_imports : + AreImported globals "ethereum.byzantium.vm.stack" [ "pop"; "push" ]. Definition mstore : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/stack.v b/CoqOfPython/ethereum/byzantium/vm/instructions/stack.v index f9eec4b..446a88f 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/stack.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.byzantium.vm.instructions.stack". Definition expr_1 : Value.t := Constant.str " @@ -17,39 +17,26 @@ Introduction Implementations of the EVM stack related instructions. ". -Require functools. -Axiom functools_partial : - IsGlobalAlias globals functools.globals "partial". +Axiom functools_imports : + AreImported globals "functools" [ "partial" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.byzantium.vm.__init__. -Axiom ethereum_byzantium_vm___init___Evm : - IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Evm". -Axiom ethereum_byzantium_vm___init___stack : - IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "stack". +Axiom ethereum_byzantium_vm_imports : + AreImported globals "ethereum.byzantium.vm" [ "Evm"; "stack" ]. -Require ethereum.byzantium.vm.exceptions. -Axiom ethereum_byzantium_vm_exceptions_StackUnderflowError : - IsGlobalAlias globals ethereum.byzantium.vm.exceptions.globals "StackUnderflowError". +Axiom ethereum_byzantium_vm_exceptions_imports : + AreImported globals "ethereum.byzantium.vm.exceptions" [ "StackUnderflowError" ]. -Require ethereum.byzantium.vm.gas. -Axiom ethereum_byzantium_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_BASE". -Axiom ethereum_byzantium_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_byzantium_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "charge_gas". +Axiom ethereum_byzantium_vm_gas_imports : + AreImported globals "ethereum.byzantium.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.byzantium.vm.memory. -Axiom ethereum_byzantium_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.byzantium.vm.memory.globals "buffer_read". +Axiom ethereum_byzantium_vm_memory_imports : + AreImported globals "ethereum.byzantium.vm.memory" [ "buffer_read" ]. Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -203,19 +190,22 @@ Definition dup_n : Value.t -> Value.t -> M := make_dict [] |) in let data_to_duplicate := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] + BinOp.sub (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), + Constant.int 1 |), - Constant.int 1 - |), - M.get_name (| globals, "item_number" |) - |) |) in + M.get_name (| globals, "item_number" |) + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "stack" |), "push" |), make_list [ @@ -278,14 +268,26 @@ Definition swap_n : Value.t -> Value.t -> M := make_dict [] |) in let _ := M.assign (| - make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| - UnOp.sub (| Constant.int 1 |), - M.get_name (| globals, "item_number" |) - |) |) ], - make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| - UnOp.sub (| Constant.int 1 |), - M.get_name (| globals, "item_number" |) - |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |) ] + make_tuple [ M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + UnOp.sub (| Constant.int 1 |) + |); M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) + |) ], + make_tuple [ M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) + |); M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + UnOp.sub (| Constant.int 1 |) + |) ] |) in let _ := M.assign_op (| BinOp.add, diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/storage.v b/CoqOfPython/ethereum/byzantium/vm/instructions/storage.v index 9055a0d..559c559 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/storage.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.byzantium.vm.instructions.storage". Definition expr_1 : Value.t := Constant.str " @@ -17,41 +17,23 @@ Introduction Implementations of the EVM storage related instructions. ". -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.byzantium.state. -Axiom ethereum_byzantium_state_get_storage : - IsGlobalAlias globals ethereum.byzantium.state.globals "get_storage". -Axiom ethereum_byzantium_state_set_storage : - IsGlobalAlias globals ethereum.byzantium.state.globals "set_storage". - -Require ethereum.byzantium.vm.__init__. -Axiom ethereum_byzantium_vm___init___Evm : - IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Evm". - -Require ethereum.byzantium.vm.exceptions. -Axiom ethereum_byzantium_vm_exceptions_WriteInStaticContext : - IsGlobalAlias globals ethereum.byzantium.vm.exceptions.globals "WriteInStaticContext". - -Require ethereum.byzantium.vm.gas. -Axiom ethereum_byzantium_vm_gas_GAS_SLOAD : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_SLOAD". -Axiom ethereum_byzantium_vm_gas_GAS_STORAGE_CLEAR_REFUND : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_STORAGE_CLEAR_REFUND". -Axiom ethereum_byzantium_vm_gas_GAS_STORAGE_SET : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_STORAGE_SET". -Axiom ethereum_byzantium_vm_gas_GAS_STORAGE_UPDATE : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_STORAGE_UPDATE". -Axiom ethereum_byzantium_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "charge_gas". - -Require ethereum.byzantium.vm.stack. -Axiom ethereum_byzantium_vm_stack_pop : - IsGlobalAlias globals ethereum.byzantium.vm.stack.globals "pop". -Axiom ethereum_byzantium_vm_stack_push : - IsGlobalAlias globals ethereum.byzantium.vm.stack.globals "push". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_byzantium_state_imports : + AreImported globals "ethereum.byzantium.state" [ "get_storage"; "set_storage" ]. + +Axiom ethereum_byzantium_vm_imports : + AreImported globals "ethereum.byzantium.vm" [ "Evm" ]. + +Axiom ethereum_byzantium_vm_exceptions_imports : + AreImported globals "ethereum.byzantium.vm.exceptions" [ "WriteInStaticContext" ]. + +Axiom ethereum_byzantium_vm_gas_imports : + AreImported globals "ethereum.byzantium.vm.gas" [ "GAS_SLOAD"; "GAS_STORAGE_CLEAR_REFUND"; "GAS_STORAGE_SET"; "GAS_STORAGE_UPDATE"; "charge_gas" ]. + +Axiom ethereum_byzantium_vm_stack_imports : + AreImported globals "ethereum.byzantium.vm.stack" [ "pop"; "push" ]. Definition sload : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/system.v b/CoqOfPython/ethereum/byzantium/vm/instructions/system.v index e48ab33..470c813 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/system.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/system.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.byzantium.vm.instructions.system". Definition expr_1 : Value.t := Constant.str " @@ -17,95 +17,35 @@ Introduction Implementations of the EVM system related instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.byzantium.fork_types. -Axiom ethereum_byzantium_fork_types_Address : - IsGlobalAlias globals ethereum.byzantium.fork_types.globals "Address". +Axiom ethereum_byzantium_fork_types_imports : + AreImported globals "ethereum.byzantium.fork_types" [ "Address" ]. -Require ethereum.byzantium.state. -Axiom ethereum_byzantium_state_account_exists_and_is_empty : - IsGlobalAlias globals ethereum.byzantium.state.globals "account_exists_and_is_empty". -Axiom ethereum_byzantium_state_account_has_code_or_nonce : - IsGlobalAlias globals ethereum.byzantium.state.globals "account_has_code_or_nonce". -Axiom ethereum_byzantium_state_get_account : - IsGlobalAlias globals ethereum.byzantium.state.globals "get_account". -Axiom ethereum_byzantium_state_increment_nonce : - IsGlobalAlias globals ethereum.byzantium.state.globals "increment_nonce". -Axiom ethereum_byzantium_state_is_account_alive : - IsGlobalAlias globals ethereum.byzantium.state.globals "is_account_alive". -Axiom ethereum_byzantium_state_set_account_balance : - IsGlobalAlias globals ethereum.byzantium.state.globals "set_account_balance". +Axiom ethereum_byzantium_state_imports : + AreImported globals "ethereum.byzantium.state" [ "account_exists_and_is_empty"; "account_has_code_or_nonce"; "get_account"; "increment_nonce"; "is_account_alive"; "set_account_balance" ]. -Require ethereum.byzantium.utils.address. -Axiom ethereum_byzantium_utils_address_compute_contract_address : - IsGlobalAlias globals ethereum.byzantium.utils.address.globals "compute_contract_address". -Axiom ethereum_byzantium_utils_address_to_address : - IsGlobalAlias globals ethereum.byzantium.utils.address.globals "to_address". +Axiom ethereum_byzantium_utils_address_imports : + AreImported globals "ethereum.byzantium.utils.address" [ "compute_contract_address"; "to_address" ]. -Require ethereum.byzantium.vm.__init__. -Axiom ethereum_byzantium_vm___init___Evm : - IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Evm". -Axiom ethereum_byzantium_vm___init___Message : - IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Message". -Axiom ethereum_byzantium_vm___init___incorporate_child_on_error : - IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "incorporate_child_on_error". -Axiom ethereum_byzantium_vm___init___incorporate_child_on_success : - IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "incorporate_child_on_success". +Axiom ethereum_byzantium_vm_imports : + AreImported globals "ethereum.byzantium.vm" [ "Evm"; "Message"; "incorporate_child_on_error"; "incorporate_child_on_success" ]. -Require ethereum.byzantium.vm.exceptions. -Axiom ethereum_byzantium_vm_exceptions_Revert : - IsGlobalAlias globals ethereum.byzantium.vm.exceptions.globals "Revert". -Axiom ethereum_byzantium_vm_exceptions_WriteInStaticContext : - IsGlobalAlias globals ethereum.byzantium.vm.exceptions.globals "WriteInStaticContext". +Axiom ethereum_byzantium_vm_exceptions_imports : + AreImported globals "ethereum.byzantium.vm.exceptions" [ "Revert"; "WriteInStaticContext" ]. -Require ethereum.byzantium.vm.gas. -Axiom ethereum_byzantium_vm_gas_GAS_CALL : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_CALL". -Axiom ethereum_byzantium_vm_gas_GAS_CALL_VALUE : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_CALL_VALUE". -Axiom ethereum_byzantium_vm_gas_GAS_CREATE : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_CREATE". -Axiom ethereum_byzantium_vm_gas_GAS_NEW_ACCOUNT : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_NEW_ACCOUNT". -Axiom ethereum_byzantium_vm_gas_GAS_SELF_DESTRUCT : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_SELF_DESTRUCT". -Axiom ethereum_byzantium_vm_gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". -Axiom ethereum_byzantium_vm_gas_GAS_ZERO : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_ZERO". -Axiom ethereum_byzantium_vm_gas_REFUND_SELF_DESTRUCT : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "REFUND_SELF_DESTRUCT". -Axiom ethereum_byzantium_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_byzantium_vm_gas_calculate_message_call_gas : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "calculate_message_call_gas". -Axiom ethereum_byzantium_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "charge_gas". -Axiom ethereum_byzantium_vm_gas_max_message_call_gas : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "max_message_call_gas". +Axiom ethereum_byzantium_vm_gas_imports : + AreImported globals "ethereum.byzantium.vm.gas" [ "GAS_CALL"; "GAS_CALL_VALUE"; "GAS_CREATE"; "GAS_NEW_ACCOUNT"; "GAS_SELF_DESTRUCT"; "GAS_SELF_DESTRUCT_NEW_ACCOUNT"; "GAS_ZERO"; "REFUND_SELF_DESTRUCT"; "calculate_gas_extend_memory"; "calculate_message_call_gas"; "charge_gas"; "max_message_call_gas" ]. -Require ethereum.byzantium.vm.memory. -Axiom ethereum_byzantium_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.byzantium.vm.memory.globals "memory_read_bytes". -Axiom ethereum_byzantium_vm_memory_memory_write : - IsGlobalAlias globals ethereum.byzantium.vm.memory.globals "memory_write". +Axiom ethereum_byzantium_vm_memory_imports : + AreImported globals "ethereum.byzantium.vm.memory" [ "memory_read_bytes"; "memory_write" ]. -Require ethereum.byzantium.vm.stack. -Axiom ethereum_byzantium_vm_stack_pop : - IsGlobalAlias globals ethereum.byzantium.vm.stack.globals "pop". -Axiom ethereum_byzantium_vm_stack_push : - IsGlobalAlias globals ethereum.byzantium.vm.stack.globals "push". +Axiom ethereum_byzantium_vm_stack_imports : + AreImported globals "ethereum.byzantium.vm.stack" [ "pop"; "push" ]. Definition create : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -687,7 +627,12 @@ Definition generic_call : Value.t -> Value.t -> M := make_list [ M.get_field (| M.get_name (| globals, "evm" |), "memory" |); M.get_name (| globals, "memory_output_start_position" |); - M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), M.slice (| Constant.None_, M.get_name (| globals, "actual_output_size" |) |) |) + M.slice (| + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), + Constant.None_, + M.get_name (| globals, "actual_output_size" |), + Constant.None_ + |) ], make_dict [] |) in @@ -1265,20 +1210,28 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in let parent_evm := M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "parent_evm" |) in - While Compare.is_not (| - M.get_name (| globals, "parent_evm" |), - Constant.None_ - |) do - let _ := M.call (| + let _ := + M.while (| + Compare.is_not (| + M.get_name (| globals, "parent_evm" |), + Constant.None_ + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "refunded_accounts" |), "update" |), make_list [ M.get_field (| M.get_name (| globals, "parent_evm" |), "accounts_to_delete" |) ], make_dict [] |) in - let parent_evm := - M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in - EndWhile. + let parent_evm := + M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := (* if *) M.if_then_else (| @@ -1780,6 +1733,6 @@ Definition revert : Value.t -> Value.t -> M := make_dict [] |) |) in - let _ := M.raise (| Some(M.get_name (| globals, "Revert" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "Revert" |)) |) in let _ := M.pass (| |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/byzantium/vm/interpreter.v b/CoqOfPython/ethereum/byzantium/vm/interpreter.v index 0ee8639..e9ddd6b 100644 --- a/CoqOfPython/ethereum/byzantium/vm/interpreter.v +++ b/CoqOfPython/ethereum/byzantium/vm/interpreter.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.byzantium.vm.interpreter". Definition expr_1 : Value.t := Constant.str " @@ -17,123 +17,50 @@ Introduction A straightforward interpreter that executes EVM code. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_Iterable : - IsGlobalAlias globals typing.globals "Iterable". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.trace. -Axiom ethereum_trace_EvmStop : - IsGlobalAlias globals ethereum.trace.globals "EvmStop". -Axiom ethereum_trace_OpEnd : - IsGlobalAlias globals ethereum.trace.globals "OpEnd". -Axiom ethereum_trace_OpException : - IsGlobalAlias globals ethereum.trace.globals "OpException". -Axiom ethereum_trace_OpStart : - IsGlobalAlias globals ethereum.trace.globals "OpStart". -Axiom ethereum_trace_PrecompileEnd : - IsGlobalAlias globals ethereum.trace.globals "PrecompileEnd". -Axiom ethereum_trace_PrecompileStart : - IsGlobalAlias globals ethereum.trace.globals "PrecompileStart". -Axiom ethereum_trace_TransactionEnd : - IsGlobalAlias globals ethereum.trace.globals "TransactionEnd". -Axiom ethereum_trace_evm_trace : - IsGlobalAlias globals ethereum.trace.globals "evm_trace". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.byzantium.blocks. -Axiom ethereum_byzantium_blocks_Log : - IsGlobalAlias globals ethereum.byzantium.blocks.globals "Log". - -Require ethereum.byzantium.fork_types. -Axiom ethereum_byzantium_fork_types_Address : - IsGlobalAlias globals ethereum.byzantium.fork_types.globals "Address". - -Require ethereum.byzantium.state. -Axiom ethereum_byzantium_state_account_exists_and_is_empty : - IsGlobalAlias globals ethereum.byzantium.state.globals "account_exists_and_is_empty". -Axiom ethereum_byzantium_state_account_has_code_or_nonce : - IsGlobalAlias globals ethereum.byzantium.state.globals "account_has_code_or_nonce". -Axiom ethereum_byzantium_state_begin_transaction : - IsGlobalAlias globals ethereum.byzantium.state.globals "begin_transaction". -Axiom ethereum_byzantium_state_commit_transaction : - IsGlobalAlias globals ethereum.byzantium.state.globals "commit_transaction". -Axiom ethereum_byzantium_state_destroy_storage : - IsGlobalAlias globals ethereum.byzantium.state.globals "destroy_storage". -Axiom ethereum_byzantium_state_increment_nonce : - IsGlobalAlias globals ethereum.byzantium.state.globals "increment_nonce". -Axiom ethereum_byzantium_state_move_ether : - IsGlobalAlias globals ethereum.byzantium.state.globals "move_ether". -Axiom ethereum_byzantium_state_rollback_transaction : - IsGlobalAlias globals ethereum.byzantium.state.globals "rollback_transaction". -Axiom ethereum_byzantium_state_set_code : - IsGlobalAlias globals ethereum.byzantium.state.globals "set_code". -Axiom ethereum_byzantium_state_touch_account : - IsGlobalAlias globals ethereum.byzantium.state.globals "touch_account". - -Require ethereum.byzantium.vm.__init__. -Axiom ethereum_byzantium_vm___init___Message : - IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Message". - -Require ethereum.byzantium.vm.gas. -Axiom ethereum_byzantium_vm_gas_GAS_CODE_DEPOSIT : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_CODE_DEPOSIT". -Axiom ethereum_byzantium_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "charge_gas". - -Require ethereum.byzantium.vm.precompiled_contracts.mapping. -Axiom ethereum_byzantium_vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : - IsGlobalAlias globals ethereum.byzantium.vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". - -Require ethereum.byzantium.vm.__init__. -Axiom ethereum_byzantium_vm___init___Environment : - IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Environment". -Axiom ethereum_byzantium_vm___init___Evm : - IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Evm". - -Require ethereum.byzantium.vm.exceptions. -Axiom ethereum_byzantium_vm_exceptions_AddressCollision : - IsGlobalAlias globals ethereum.byzantium.vm.exceptions.globals "AddressCollision". -Axiom ethereum_byzantium_vm_exceptions_ExceptionalHalt : - IsGlobalAlias globals ethereum.byzantium.vm.exceptions.globals "ExceptionalHalt". -Axiom ethereum_byzantium_vm_exceptions_InvalidOpcode : - IsGlobalAlias globals ethereum.byzantium.vm.exceptions.globals "InvalidOpcode". -Axiom ethereum_byzantium_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.byzantium.vm.exceptions.globals "OutOfGasError". -Axiom ethereum_byzantium_vm_exceptions_Revert : - IsGlobalAlias globals ethereum.byzantium.vm.exceptions.globals "Revert". -Axiom ethereum_byzantium_vm_exceptions_StackDepthLimitError : - IsGlobalAlias globals ethereum.byzantium.vm.exceptions.globals "StackDepthLimitError". - -Require ethereum.byzantium.vm.instructions.__init__. -Axiom ethereum_byzantium_vm_instructions___init___Ops : - IsGlobalAlias globals ethereum.byzantium.vm.instructions.__init__.globals "Ops". -Axiom ethereum_byzantium_vm_instructions___init___op_implementation : - IsGlobalAlias globals ethereum.byzantium.vm.instructions.__init__.globals "op_implementation". - -Require ethereum.byzantium.vm.runtime. -Axiom ethereum_byzantium_vm_runtime_get_valid_jump_destinations : - IsGlobalAlias globals ethereum.byzantium.vm.runtime.globals "get_valid_jump_destinations". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Iterable"; "Optional"; "Set"; "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. + +Axiom ethereum_trace_imports : + AreImported globals "ethereum.trace" [ "EvmStop"; "OpEnd"; "OpException"; "OpStart"; "PrecompileEnd"; "PrecompileStart"; "TransactionEnd"; "evm_trace" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_byzantium_blocks_imports : + AreImported globals "ethereum.byzantium.blocks" [ "Log" ]. + +Axiom ethereum_byzantium_fork_types_imports : + AreImported globals "ethereum.byzantium.fork_types" [ "Address" ]. + +Axiom ethereum_byzantium_state_imports : + AreImported globals "ethereum.byzantium.state" [ "account_exists_and_is_empty"; "account_has_code_or_nonce"; "begin_transaction"; "commit_transaction"; "destroy_storage"; "increment_nonce"; "move_ether"; "rollback_transaction"; "set_code"; "touch_account" ]. + +Axiom ethereum_byzantium_vm_imports : + AreImported globals "ethereum.byzantium.vm" [ "Message" ]. + +Axiom ethereum_byzantium_vm_gas_imports : + AreImported globals "ethereum.byzantium.vm.gas" [ "GAS_CODE_DEPOSIT"; "charge_gas" ]. + +Axiom ethereum_byzantium_vm_precompiled_contracts_mapping_imports : + AreImported globals "ethereum.byzantium.vm.precompiled_contracts.mapping" [ "PRE_COMPILED_CONTRACTS" ]. + +Axiom ethereum_byzantium_vm_imports : + AreImported globals "ethereum.byzantium.vm" [ "Environment"; "Evm" ]. + +Axiom ethereum_byzantium_vm_exceptions_imports : + AreImported globals "ethereum.byzantium.vm.exceptions" [ "AddressCollision"; "ExceptionalHalt"; "InvalidOpcode"; "OutOfGasError"; "Revert"; "StackDepthLimitError" ]. + +Axiom ethereum_byzantium_vm_instructions_imports : + AreImported globals "ethereum.byzantium.vm.instructions" [ "Ops"; "op_implementation" ]. + +Axiom ethereum_byzantium_vm_runtime_imports : + AreImported globals "ethereum.byzantium.vm.runtime" [ "get_valid_jump_destinations" ]. Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -500,7 +427,7 @@ Definition process_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "StackDepthLimitError" |), make_list [ Constant.str "Stack depth limit reached" diff --git a/CoqOfPython/ethereum/byzantium/vm/memory.v b/CoqOfPython/ethereum/byzantium/vm/memory.v index 08d2290..18903ab 100644 --- a/CoqOfPython/ethereum/byzantium/vm/memory.v +++ b/CoqOfPython/ethereum/byzantium/vm/memory.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.byzantium.vm.memory". Definition expr_1 : Value.t := Constant.str " @@ -17,17 +17,11 @@ Introduction EVM memory operations. ". -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_right_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "right_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "right_pad_zero_bytes" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. Definition memory_write : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,22 +39,27 @@ Definition memory_write : Value.t -> Value.t -> M := Data to write to memory. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + M.slice (| + M.get_name (| globals, "memory" |), + M.get_name (| globals, "start_position" |), + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) - |) |) |), + Constant.None_ + |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_)). @@ -86,22 +85,27 @@ Definition memory_read_bytes : Value.t -> Value.t -> M := Data read from memory. " in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + M.slice (| + M.get_name (| globals, "memory" |), + M.get_name (| globals, "start_position" |), + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |) |) + Constant.None_ + |) |) in M.pure Constant.None_)). @@ -129,22 +133,27 @@ Definition buffer_read : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "right_pad_zero_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "buffer" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + M.slice (| + M.get_name (| globals, "buffer" |), + M.get_name (| globals, "start_position" |), + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |) |); + Constant.None_ + |); M.get_name (| globals, "size" |) ], make_dict [] diff --git a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/__init__.v index 070b8b2..dc8ad82 100644 --- a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/__init__.v +++ b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.byzantium.vm.precompiled_contracts.__init__". Definition expr_1 : Value.t := Constant.str " @@ -18,9 +18,8 @@ Addresses of precompiled contracts and mappings to their implementations. ". -Require ethereum.byzantium.utils.hexadecimal. -Axiom ethereum_byzantium_utils_hexadecimal_hex_to_address : - IsGlobalAlias globals ethereum.byzantium.utils.hexadecimal.globals "hex_to_address". +Axiom ethereum_byzantium_utils_hexadecimal_imports : + AreImported globals "ethereum.byzantium.utils.hexadecimal" [ "hex_to_address" ]. Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS"; Constant.str "MODEXP_ADDRESS"; Constant.str "ALT_BN128_ADD_ADDRESS"; Constant.str "ALT_BN128_MUL_ADDRESS"; Constant.str "ALT_BN128_PAIRING_CHECK_ADDRESS"; Constant.str "BLAKE2F_ADDRESS" ] diff --git a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/alt_bn128.v index c07bb35..c75c674 100644 --- a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/alt_bn128.v +++ b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/alt_bn128.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.byzantium.vm.precompiled_contracts.alt_bn128". Definition expr_1 : Value.t := Constant.str " @@ -17,49 +17,26 @@ Introduction Implementation of the ALT_BN128 precompiled contracts. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. -Require ethereum.crypto.alt_bn128. -Axiom ethereum_crypto_alt_bn128_ALT_BN128_CURVE_ORDER : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "ALT_BN128_CURVE_ORDER". -Axiom ethereum_crypto_alt_bn128_ALT_BN128_PRIME : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "ALT_BN128_PRIME". -Axiom ethereum_crypto_alt_bn128_BNF : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF". -Axiom ethereum_crypto_alt_bn128_BNF2 : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF2". -Axiom ethereum_crypto_alt_bn128_BNF12 : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF12". -Axiom ethereum_crypto_alt_bn128_BNP : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNP". -Axiom ethereum_crypto_alt_bn128_BNP2 : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNP2". -Axiom ethereum_crypto_alt_bn128_pairing : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "pairing". +Axiom ethereum_crypto_alt_bn128_imports : + AreImported globals "ethereum.crypto.alt_bn128" [ "ALT_BN128_CURVE_ORDER"; "ALT_BN128_PRIME"; "BNF"; "BNF2"; "BNF12"; "BNP"; "BNP2"; "pairing" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.byzantium.vm.__init__. -Axiom ethereum_byzantium_vm___init___Evm : - IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Evm". +Axiom ethereum_byzantium_vm_imports : + AreImported globals "ethereum.byzantium.vm" [ "Evm" ]. -Require ethereum.byzantium.vm.gas. -Axiom ethereum_byzantium_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "charge_gas". +Axiom ethereum_byzantium_vm_gas_imports : + AreImported globals "ethereum.byzantium.vm.gas" [ "charge_gas" ]. -Require ethereum.byzantium.vm.memory. -Axiom ethereum_byzantium_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.byzantium.vm.memory.globals "buffer_read". +Axiom ethereum_byzantium_vm_memory_imports : + AreImported globals "ethereum.byzantium.vm.memory" [ "buffer_read" ]. -Require ethereum.byzantium.vm.exceptions. -Axiom ethereum_byzantium_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.byzantium.vm.exceptions.globals "OutOfGasError". +Axiom ethereum_byzantium_vm_exceptions_imports : + AreImported globals "ethereum.byzantium.vm.exceptions" [ "OutOfGasError" ]. Definition alt_bn128_add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -208,23 +185,32 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ] do - let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| - M.get_name (| globals, "i" |), - M.get_name (| globals, "ALT_BN128_PRIME" |) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ], ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in (* At stmt: unsupported node type: Try *) let p := BinOp.add (| @@ -363,23 +349,32 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ] do - let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| - M.get_name (| globals, "i" |), - M.get_name (| globals, "ALT_BN128_PRIME" |) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ], ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in (* At stmt: unsupported node type: Try *) let p := M.call (| @@ -466,7 +461,7 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -480,76 +475,89 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - BinOp.floor_div (| + let _ := + M.for_ (| + M.get_name (| globals, "i" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "data" |) - ], - make_dict [] - |), - Constant.int 192 - |) - ], - make_dict [] - |) do - let values := - make_list [] in - For M.get_name (| globals, "j" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 6 - ], - make_dict [] - |) do - let value := + M.get_name (| globals, "range" |), + make_list [ + BinOp.floor_div (| M.call (| - M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + M.get_name (| globals, "len" |), make_list [ - M.get_subscript (| M.get_name (| globals, "data" |), M.slice (| BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "i" |), - Constant.int 192 - |), - BinOp.mult (| - Constant.int 32, - M.get_name (| globals, "j" |) - |) - |), BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "i" |), - Constant.int 192 - |), - BinOp.mult (| - Constant.int 32, - BinOp.add (| - M.get_name (| globals, "j" |), - Constant.int 1 - |) - |) - |) |) |) + M.get_name (| globals, "data" |) ], make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| - M.get_name (| globals, "value" |), - M.get_name (| globals, "ALT_BN128_PRIME" |) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let _ := M.call (| + |), + Constant.int 192 + |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let values := + make_list [] in + let _ := + M.for_ (| + M.get_name (| globals, "j" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 6 + ], + make_dict [] + |), + ltac:(M.monadic ( + let value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.slice (| + M.get_name (| globals, "data" |), + BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + M.get_name (| globals, "j" |) + |) + |), + BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "j" |), + Constant.int 1 + |) + |) + |), + Constant.None_ + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| M.get_field (| M.get_name (| globals, "values" |), "append" |), make_list [ M.call (| @@ -562,9 +570,14 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in (* At stmt: unsupported node type: Try *) - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.eq (| @@ -585,7 +598,7 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.eq (| @@ -606,49 +619,54 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| - M.get_name (| globals, "p" |), - M.call (| - M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) - |), + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "p" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "q" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |) + )) + |), + (* then *) ltac:(M.monadic ( - Compare.not_eq (| - M.get_name (| globals, "q" |), - M.call (| - M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) - |) - )) - |), - (* then *) - ltac:(M.monadic ( - let result := - BinOp.mult (| - M.get_name (| globals, "result" |), - M.call (| - M.get_name (| globals, "pairing" |), - make_list [ - M.get_name (| globals, "q" |); - M.get_name (| globals, "p" |) - ], - make_dict [] - |) - |) in + let result := + BinOp.mult (| + M.get_name (| globals, "result" |), + M.call (| + M.get_name (| globals, "pairing" |), + make_list [ + M.get_name (| globals, "q" |); + M.get_name (| globals, "p" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := (* if *) M.if_then_else (| diff --git a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/ecrecover.v index 347014f..e130dd9 100644 --- a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/ecrecover.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.byzantium.vm.precompiled_contracts.ecrecover". Definition expr_1 : Value.t := Constant.str " @@ -17,39 +17,26 @@ Introduction Implementation of the ECRECOVER precompiled contract. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.crypto.elliptic_curve. -Axiom ethereum_crypto_elliptic_curve_SECP256K1N : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". -Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". +Axiom ethereum_crypto_elliptic_curve_imports : + AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_left_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. -Require ethereum.byzantium.vm.__init__. -Axiom ethereum_byzantium_vm___init___Evm : - IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Evm". +Axiom ethereum_byzantium_vm_imports : + AreImported globals "ethereum.byzantium.vm" [ "Evm" ]. -Require ethereum.byzantium.vm.gas. -Axiom ethereum_byzantium_vm_gas_GAS_ECRECOVER : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_ECRECOVER". -Axiom ethereum_byzantium_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "charge_gas". +Axiom ethereum_byzantium_vm_gas_imports : + AreImported globals "ethereum.byzantium.vm.gas" [ "GAS_ECRECOVER"; "charge_gas" ]. -Require ethereum.byzantium.vm.memory. -Axiom ethereum_byzantium_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.byzantium.vm.memory.globals "buffer_read". +Axiom ethereum_byzantium_vm_memory_imports : + AreImported globals "ethereum.byzantium.vm.memory" [ "buffer_read" ]. Definition ecrecover : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -264,13 +251,18 @@ Definition ecrecover : Value.t -> Value.t -> M := )) |) in (* At stmt: unsupported node type: Try *) let address := - M.get_subscript (| M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "public_key" |) - ], - make_dict [] - |), M.slice (| Constant.int 12, Constant.int 32 |) |) in + M.slice (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), + Constant.int 12, + Constant.int 32, + Constant.None_ + |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/identity.v index 6601ede..6ee7dae 100644 --- a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/identity.v +++ b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/identity.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.byzantium.vm.precompiled_contracts.identity". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementation of the `IDENTITY` precompiled contract. ". -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.byzantium.vm.__init__. -Axiom ethereum_byzantium_vm___init___Evm : - IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Evm". +Axiom ethereum_byzantium_vm_imports : + AreImported globals "ethereum.byzantium.vm" [ "Evm" ]. -Require ethereum.byzantium.vm.gas. -Axiom ethereum_byzantium_vm_gas_GAS_IDENTITY : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_IDENTITY". -Axiom ethereum_byzantium_vm_gas_GAS_IDENTITY_WORD : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_IDENTITY_WORD". -Axiom ethereum_byzantium_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "charge_gas". +Axiom ethereum_byzantium_vm_gas_imports : + AreImported globals "ethereum.byzantium.vm.gas" [ "GAS_IDENTITY"; "GAS_IDENTITY_WORD"; "charge_gas" ]. Definition identity : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/mapping.v index 4f7ca92..d016ee6 100644 --- a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/mapping.v +++ b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/mapping.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.byzantium.vm.precompiled_contracts.mapping". Definition expr_1 : Value.t := Constant.str " @@ -17,60 +17,31 @@ Introduction Mapping of precompiled contracts their implementations. ". -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict" ]. -Require ethereum.byzantium.fork_types. -Axiom ethereum_byzantium_fork_types_Address : - IsGlobalAlias globals ethereum.byzantium.fork_types.globals "Address". +Axiom ethereum_byzantium_fork_types_imports : + AreImported globals "ethereum.byzantium.fork_types" [ "Address" ]. -Require ethereum.byzantium.vm.precompiled_contracts.__init__. -Axiom ethereum_byzantium_vm_precompiled_contracts___init___ALT_BN128_ADD_ADDRESS : - IsGlobalAlias globals ethereum.byzantium.vm.precompiled_contracts.__init__.globals "ALT_BN128_ADD_ADDRESS". -Axiom ethereum_byzantium_vm_precompiled_contracts___init___ALT_BN128_MUL_ADDRESS : - IsGlobalAlias globals ethereum.byzantium.vm.precompiled_contracts.__init__.globals "ALT_BN128_MUL_ADDRESS". -Axiom ethereum_byzantium_vm_precompiled_contracts___init___ALT_BN128_PAIRING_CHECK_ADDRESS : - IsGlobalAlias globals ethereum.byzantium.vm.precompiled_contracts.__init__.globals "ALT_BN128_PAIRING_CHECK_ADDRESS". -Axiom ethereum_byzantium_vm_precompiled_contracts___init___ECRECOVER_ADDRESS : - IsGlobalAlias globals ethereum.byzantium.vm.precompiled_contracts.__init__.globals "ECRECOVER_ADDRESS". -Axiom ethereum_byzantium_vm_precompiled_contracts___init___IDENTITY_ADDRESS : - IsGlobalAlias globals ethereum.byzantium.vm.precompiled_contracts.__init__.globals "IDENTITY_ADDRESS". -Axiom ethereum_byzantium_vm_precompiled_contracts___init___MODEXP_ADDRESS : - IsGlobalAlias globals ethereum.byzantium.vm.precompiled_contracts.__init__.globals "MODEXP_ADDRESS". -Axiom ethereum_byzantium_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : - IsGlobalAlias globals ethereum.byzantium.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". -Axiom ethereum_byzantium_vm_precompiled_contracts___init___SHA256_ADDRESS : - IsGlobalAlias globals ethereum.byzantium.vm.precompiled_contracts.__init__.globals "SHA256_ADDRESS". +Axiom ethereum_byzantium_vm_precompiled_contracts_imports : + AreImported globals "ethereum.byzantium.vm.precompiled_contracts" [ "ALT_BN128_ADD_ADDRESS"; "ALT_BN128_MUL_ADDRESS"; "ALT_BN128_PAIRING_CHECK_ADDRESS"; "ECRECOVER_ADDRESS"; "IDENTITY_ADDRESS"; "MODEXP_ADDRESS"; "RIPEMD160_ADDRESS"; "SHA256_ADDRESS" ]. -Require ethereum.byzantium.vm.precompiled_contracts.alt_bn128. -Axiom ethereum_byzantium_vm_precompiled_contracts_alt_bn128_alt_bn128_add : - IsGlobalAlias globals ethereum.byzantium.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_add". -Axiom ethereum_byzantium_vm_precompiled_contracts_alt_bn128_alt_bn128_mul : - IsGlobalAlias globals ethereum.byzantium.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_mul". -Axiom ethereum_byzantium_vm_precompiled_contracts_alt_bn128_alt_bn128_pairing_check : - IsGlobalAlias globals ethereum.byzantium.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_pairing_check". +Axiom ethereum_byzantium_vm_precompiled_contracts_alt_bn128_imports : + AreImported globals "ethereum.byzantium.vm.precompiled_contracts.alt_bn128" [ "alt_bn128_add"; "alt_bn128_mul"; "alt_bn128_pairing_check" ]. -Require ethereum.byzantium.vm.precompiled_contracts.ecrecover. -Axiom ethereum_byzantium_vm_precompiled_contracts_ecrecover_ecrecover : - IsGlobalAlias globals ethereum.byzantium.vm.precompiled_contracts.ecrecover.globals "ecrecover". +Axiom ethereum_byzantium_vm_precompiled_contracts_ecrecover_imports : + AreImported globals "ethereum.byzantium.vm.precompiled_contracts.ecrecover" [ "ecrecover" ]. -Require ethereum.byzantium.vm.precompiled_contracts.identity. -Axiom ethereum_byzantium_vm_precompiled_contracts_identity_identity : - IsGlobalAlias globals ethereum.byzantium.vm.precompiled_contracts.identity.globals "identity". +Axiom ethereum_byzantium_vm_precompiled_contracts_identity_imports : + AreImported globals "ethereum.byzantium.vm.precompiled_contracts.identity" [ "identity" ]. -Require ethereum.byzantium.vm.precompiled_contracts.modexp. -Axiom ethereum_byzantium_vm_precompiled_contracts_modexp_modexp : - IsGlobalAlias globals ethereum.byzantium.vm.precompiled_contracts.modexp.globals "modexp". +Axiom ethereum_byzantium_vm_precompiled_contracts_modexp_imports : + AreImported globals "ethereum.byzantium.vm.precompiled_contracts.modexp" [ "modexp" ]. -Require ethereum.byzantium.vm.precompiled_contracts.ripemd160. -Axiom ethereum_byzantium_vm_precompiled_contracts_ripemd160_ripemd160 : - IsGlobalAlias globals ethereum.byzantium.vm.precompiled_contracts.ripemd160.globals "ripemd160". +Axiom ethereum_byzantium_vm_precompiled_contracts_ripemd160_imports : + AreImported globals "ethereum.byzantium.vm.precompiled_contracts.ripemd160" [ "ripemd160" ]. -Require ethereum.byzantium.vm.precompiled_contracts.sha256. -Axiom ethereum_byzantium_vm_precompiled_contracts_sha256_sha256 : - IsGlobalAlias globals ethereum.byzantium.vm.precompiled_contracts.sha256.globals "sha256". +Axiom ethereum_byzantium_vm_precompiled_contracts_sha256_imports : + AreImported globals "ethereum.byzantium.vm.precompiled_contracts.sha256" [ "sha256" ]. (* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/modexp.v index b67c04e..7d7b8f9 100644 --- a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/modexp.v +++ b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/modexp.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.byzantium.vm.precompiled_contracts.modexp". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementation of the `MODEXP` precompiled contract. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. -Require ethereum.byzantium.vm.__init__. -Axiom ethereum_byzantium_vm___init___Evm : - IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Evm". +Axiom ethereum_byzantium_vm_imports : + AreImported globals "ethereum.byzantium.vm" [ "Evm" ]. -Require ethereum.byzantium.vm.gas. -Axiom ethereum_byzantium_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "charge_gas". +Axiom ethereum_byzantium_vm_gas_imports : + AreImported globals "ethereum.byzantium.vm.gas" [ "charge_gas" ]. -Require ethereum.byzantium.vm.memory. -Axiom ethereum_byzantium_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.byzantium.vm.memory.globals "buffer_read". +Axiom ethereum_byzantium_vm_memory_imports : + AreImported globals "ethereum.byzantium.vm.memory" [ "buffer_read" ]. Definition GQUADDIVISOR : Value.t := M.run ltac:(M.monadic ( M.call (| diff --git a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/ripemd160.v index ca3ec8b..f5f954e 100644 --- a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/ripemd160.v +++ b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/ripemd160.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.byzantium.vm.precompiled_contracts.ripemd160". Definition expr_1 : Value.t := Constant.str " @@ -19,29 +19,20 @@ Implementation of the `RIPEMD160` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_left_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.byzantium.vm.__init__. -Axiom ethereum_byzantium_vm___init___Evm : - IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Evm". +Axiom ethereum_byzantium_vm_imports : + AreImported globals "ethereum.byzantium.vm" [ "Evm" ]. -Require ethereum.byzantium.vm.gas. -Axiom ethereum_byzantium_vm_gas_GAS_RIPEMD160 : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_RIPEMD160". -Axiom ethereum_byzantium_vm_gas_GAS_RIPEMD160_WORD : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_RIPEMD160_WORD". -Axiom ethereum_byzantium_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "charge_gas". +Axiom ethereum_byzantium_vm_gas_imports : + AreImported globals "ethereum.byzantium.vm.gas" [ "GAS_RIPEMD160"; "GAS_RIPEMD160_WORD"; "charge_gas" ]. Definition ripemd160 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/sha256.v index ddcccf9..17ff45d 100644 --- a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/sha256.v +++ b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/sha256.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.byzantium.vm.precompiled_contracts.sha256". Definition expr_1 : Value.t := Constant.str " @@ -19,25 +19,17 @@ Implementation of the `SHA256` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.byzantium.vm.__init__. -Axiom ethereum_byzantium_vm___init___Evm : - IsGlobalAlias globals ethereum.byzantium.vm.__init__.globals "Evm". +Axiom ethereum_byzantium_vm_imports : + AreImported globals "ethereum.byzantium.vm" [ "Evm" ]. -Require ethereum.byzantium.vm.gas. -Axiom ethereum_byzantium_vm_gas_GAS_SHA256 : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_SHA256". -Axiom ethereum_byzantium_vm_gas_GAS_SHA256_WORD : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "GAS_SHA256_WORD". -Axiom ethereum_byzantium_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.byzantium.vm.gas.globals "charge_gas". +Axiom ethereum_byzantium_vm_gas_imports : + AreImported globals "ethereum.byzantium.vm.gas" [ "GAS_SHA256"; "GAS_SHA256_WORD"; "charge_gas" ]. Definition sha256 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/byzantium/vm/runtime.v b/CoqOfPython/ethereum/byzantium/vm/runtime.v index b3b5055..954535c 100644 --- a/CoqOfPython/ethereum/byzantium/vm/runtime.v +++ b/CoqOfPython/ethereum/byzantium/vm/runtime.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.byzantium.vm.runtime". Definition expr_1 : Value.t := Constant.str " @@ -17,17 +17,14 @@ Introduction Runtime related operations used while executing EVM code. ". -Require typing. -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". +Axiom typing_imports : + AreImported globals "typing" [ "Set" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.byzantium.vm.instructions.__init__. -Axiom ethereum_byzantium_vm_instructions___init___Ops : - IsGlobalAlias globals ethereum.byzantium.vm.instructions.__init__.globals "Ops". +Axiom ethereum_byzantium_vm_instructions_imports : + AreImported globals "ethereum.byzantium.vm.instructions" [ "Ops" ]. Definition get_valid_jump_destinations : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -67,75 +64,83 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := ], make_dict [] |) in - While Compare.lt (| - M.get_name (| globals, "pc" |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "code" |) - ], - make_dict [] - |) - |) do -(* At stmt: unsupported node type: Try *) - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "current_opcode" |), - M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) - |), - (* then *) + let _ := + M.while (| + Compare.lt (| + M.get_name (| globals, "pc" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) + |), ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), - make_list [ - M.get_name (| globals, "pc" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( +(* At stmt: unsupported node type: Try *) let _ := (* if *) M.if_then_else (| - BoolOp.and (| - Compare.lt_e (| - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |), - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |) - |), - ltac:(M.monadic ( - Compare.lt_e (| - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH32" |), "value" |) - |) - )) + Compare.eq (| + M.get_name (| globals, "current_opcode" |), + M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) |), (* then *) ltac:(M.monadic ( - let push_data_size := - BinOp.add (| - BinOp.sub (| - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) - |), - Constant.int 1 - |) in - let pc := BinOp.add - M.get_name (| globals, "push_data_size" |) - M.get_name (| globals, "push_data_size" |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), + make_list [ + M.get_name (| globals, "pc" |) + ], + make_dict [] + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.lt_e (| + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |), + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH32" |), "value" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let push_data_size := + BinOp.add (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) + |), + Constant.int 1 + |) in + let pc := BinOp.add + M.get_name (| globals, "push_data_size" |) + M.get_name (| globals, "push_data_size" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ )) |) in + let pc := BinOp.add + Constant.int 1 + Constant.int 1 in M.pure Constant.None_ - )) |) in - let pc := BinOp.add - Constant.int 1 - Constant.int 1 in - EndWhile. + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.get_name (| globals, "valid_jump_destinations" |) |) in diff --git a/CoqOfPython/ethereum/byzantium/vm/stack.v b/CoqOfPython/ethereum/byzantium/vm/stack.v index c6bc41e..203cac2 100644 --- a/CoqOfPython/ethereum/byzantium/vm/stack.v +++ b/CoqOfPython/ethereum/byzantium/vm/stack.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.byzantium.vm.stack". Definition expr_1 : Value.t := Constant.str " @@ -17,19 +17,14 @@ Introduction Implementation of the stack operators for the EVM. ". -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". +Axiom typing_imports : + AreImported globals "typing" [ "List" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.byzantium.vm.exceptions. -Axiom ethereum_byzantium_vm_exceptions_StackOverflowError : - IsGlobalAlias globals ethereum.byzantium.vm.exceptions.globals "StackOverflowError". -Axiom ethereum_byzantium_vm_exceptions_StackUnderflowError : - IsGlobalAlias globals ethereum.byzantium.vm.exceptions.globals "StackUnderflowError". +Axiom ethereum_byzantium_vm_exceptions_imports : + AreImported globals "ethereum.byzantium.vm.exceptions" [ "StackOverflowError"; "StackUnderflowError" ]. Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -63,7 +58,7 @@ Definition pop : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "StackUnderflowError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "StackUnderflowError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -108,7 +103,7 @@ Definition push : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "StackOverflowError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "StackOverflowError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/cancun/__init__.v b/CoqOfPython/ethereum/cancun/__init__.v index 17b03d0..5ddcc4d 100644 --- a/CoqOfPython/ethereum/cancun/__init__.v +++ b/CoqOfPython/ethereum/cancun/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.cancun.__init__". Definition expr_1 : Value.t := Constant.str " @@ -10,9 +10,8 @@ instruction, limits self-destruct to only work for contracts created in the same transaction, and adds an instruction to read the blob base fee. ". -Require ethereum.fork_criteria. -Axiom ethereum_fork_criteria_ByTimestamp : - IsGlobalAlias globals ethereum.fork_criteria.globals "ByTimestamp". +Axiom ethereum_fork_criteria_imports : + AreImported globals "ethereum.fork_criteria" [ "ByTimestamp" ]. Definition FORK_CRITERIA : Value.t := M.run ltac:(M.monadic ( M.call (| diff --git a/CoqOfPython/ethereum/cancun/blocks.v b/CoqOfPython/ethereum/cancun/blocks.v index d5c5e90..6e439c4 100644 --- a/CoqOfPython/ethereum/cancun/blocks.v +++ b/CoqOfPython/ethereum/cancun/blocks.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.cancun.blocks". Definition expr_1 : Value.t := Constant.str " @@ -14,47 +14,23 @@ history of all state transitions that have happened since the genesis of the chain. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". - -Require ethereum.base_types. -Axiom ethereum_base_types_U64 : - IsGlobalAlias globals ethereum.base_types.globals "U64". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes8 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes8". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". - -Require ethereum.cancun.fork_types. -Axiom ethereum_cancun_fork_types_Address : - IsGlobalAlias globals ethereum.cancun.fork_types.globals "Address". -Axiom ethereum_cancun_fork_types_Bloom : - IsGlobalAlias globals ethereum.cancun.fork_types.globals "Bloom". -Axiom ethereum_cancun_fork_types_Root : - IsGlobalAlias globals ethereum.cancun.fork_types.globals "Root". - -Require ethereum.cancun.transactions. -Axiom ethereum_cancun_transactions_LegacyTransaction : - IsGlobalAlias globals ethereum.cancun.transactions.globals "LegacyTransaction". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Tuple"; "Union" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U64"; "U256"; "Bytes"; "Bytes8"; "Bytes32"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. + +Axiom ethereum_cancun_fork_types_imports : + AreImported globals "ethereum.cancun.fork_types" [ "Address"; "Bloom"; "Root" ]. + +Axiom ethereum_cancun_transactions_imports : + AreImported globals "ethereum.cancun.transactions" [ "LegacyTransaction" ]. Definition Withdrawal : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/cancun/bloom.v b/CoqOfPython/ethereum/cancun/bloom.v index a9df591..9603ee6 100644 --- a/CoqOfPython/ethereum/cancun/bloom.v +++ b/CoqOfPython/ethereum/cancun/bloom.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.cancun.bloom". Definition expr_1 : Value.t := Constant.str " @@ -21,25 +21,20 @@ for efficient searching of logs by address and/or topic, by rapidly eliminating blocks and receipts from their search. ". -Require typing. -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_imports : + AreImported globals "typing" [ "Tuple" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. -Require ethereum.cancun.blocks. -Axiom ethereum_cancun_blocks_Log : - IsGlobalAlias globals ethereum.cancun.blocks.globals "Log". +Axiom ethereum_cancun_blocks_imports : + AreImported globals "ethereum.cancun.blocks" [ "Log" ]. -Require ethereum.cancun.fork_types. -Axiom ethereum_cancun_fork_types_Bloom : - IsGlobalAlias globals ethereum.cancun.fork_types.globals "Bloom". +Axiom ethereum_cancun_fork_types_imports : + AreImported globals "ethereum.cancun.fork_types" [ "Bloom" ]. Definition add_to_bloom : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -66,50 +61,70 @@ Definition add_to_bloom : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "idx" |) in make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ] do - let bit_to_set := - BinOp.bit_and (| - M.call (| - M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "hash" |), M.slice (| M.get_name (| globals, "idx" |), BinOp.add (| - M.get_name (| globals, "idx" |), - Constant.int 2 - |) |) |) - ], - make_dict [] - |), - Constant.int 2047 - |) in - let bit_index := - BinOp.sub (| - Constant.int 2047, - M.get_name (| globals, "bit_to_set" |) - |) in - let byte_index := - BinOp.floor_div (| - M.get_name (| globals, "bit_index" |), - Constant.int 8 - |) in - let bit_value := - BinOp.l_shift (| - Constant.int 1, - BinOp.sub (| - Constant.int 7, - BinOp.mod_ (| + let _ := + M.for_ (| + M.get_name (| globals, "idx" |), + make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ], + ltac:(M.monadic ( + let bit_to_set := + BinOp.bit_and (| + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.slice (| + M.get_name (| globals, "hash" |), + M.get_name (| globals, "idx" |), + BinOp.add (| + M.get_name (| globals, "idx" |), + Constant.int 2 + |), + Constant.None_ + |) + ], + make_dict [] + |), + Constant.int 2047 + |) in + let bit_index := + BinOp.sub (| + Constant.int 2047, + M.get_name (| globals, "bit_to_set" |) + |) in + let byte_index := + BinOp.floor_div (| M.get_name (| globals, "bit_index" |), Constant.int 8 + |) in + let bit_value := + BinOp.l_shift (| + Constant.int 1, + BinOp.sub (| + Constant.int 7, + BinOp.mod_ (| + M.get_name (| globals, "bit_index" |), + Constant.int 8 + |) + |) + |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "bloom" |), + M.get_name (| globals, "byte_index" |) + |), + BinOp.bit_or (| + M.get_subscript (| + M.get_name (| globals, "bloom" |), + M.get_name (| globals, "byte_index" |) + |), + M.get_name (| globals, "bit_value" |) |) - |) - |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), - BinOp.bit_or (| - M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), - M.get_name (| globals, "bit_value" |) - |) - |) in - EndFor. + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_)). Definition logs_bloom : Value.t -> Value.t -> M := @@ -132,8 +147,12 @@ Definition logs_bloom : Value.t -> Value.t -> M := the caller address and the log topics. " in (* At stmt: unsupported node type: AnnAssign *) - For M.get_name (| globals, "log" |) in M.get_name (| globals, "logs" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "log" |), + M.get_name (| globals, "logs" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "add_to_bloom" |), make_list [ M.get_name (| globals, "bloom" |); @@ -141,8 +160,12 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "topic" |) in M.get_field (| M.get_name (| globals, "log" |), "topics" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "topic" |), + M.get_field (| M.get_name (| globals, "log" |), "topics" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "add_to_bloom" |), make_list [ M.get_name (| globals, "bloom" |); @@ -150,8 +173,18 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Bloom" |), diff --git a/CoqOfPython/ethereum/cancun/fork.v b/CoqOfPython/ethereum/cancun/fork.v index 2dd9a95..918ac94 100644 --- a/CoqOfPython/ethereum/cancun/fork.v +++ b/CoqOfPython/ethereum/cancun/fork.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.cancun.fork". Definition expr_1 : Value.t := Constant.str " @@ -17,177 +17,68 @@ Introduction Entry point for the Ethereum specification. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". - -Require ethereum.base_types. -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". - -Require ethereum.crypto.elliptic_curve. -Axiom ethereum_crypto_elliptic_curve_SECP256K1N : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". -Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.exceptions. -Axiom ethereum_exceptions_InvalidBlock : - IsGlobalAlias globals ethereum.exceptions.globals "InvalidBlock". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U64 : - IsGlobalAlias globals ethereum.base_types.globals "U64". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.cancun.__init__. -Axiom ethereum_cancun___init___vm : - IsGlobalAlias globals ethereum.cancun.__init__.globals "vm". - -Require ethereum.cancun.blocks. -Axiom ethereum_cancun_blocks_Block : - IsGlobalAlias globals ethereum.cancun.blocks.globals "Block". -Axiom ethereum_cancun_blocks_Header : - IsGlobalAlias globals ethereum.cancun.blocks.globals "Header". -Axiom ethereum_cancun_blocks_Log : - IsGlobalAlias globals ethereum.cancun.blocks.globals "Log". -Axiom ethereum_cancun_blocks_Receipt : - IsGlobalAlias globals ethereum.cancun.blocks.globals "Receipt". -Axiom ethereum_cancun_blocks_Withdrawal : - IsGlobalAlias globals ethereum.cancun.blocks.globals "Withdrawal". - -Require ethereum.cancun.bloom. -Axiom ethereum_cancun_bloom_logs_bloom : - IsGlobalAlias globals ethereum.cancun.bloom.globals "logs_bloom". - -Require ethereum.cancun.fork_types. -Axiom ethereum_cancun_fork_types_Address : - IsGlobalAlias globals ethereum.cancun.fork_types.globals "Address". -Axiom ethereum_cancun_fork_types_Bloom : - IsGlobalAlias globals ethereum.cancun.fork_types.globals "Bloom". -Axiom ethereum_cancun_fork_types_Root : - IsGlobalAlias globals ethereum.cancun.fork_types.globals "Root". -Axiom ethereum_cancun_fork_types_VersionedHash : - IsGlobalAlias globals ethereum.cancun.fork_types.globals "VersionedHash". - -Require ethereum.cancun.state. -Axiom ethereum_cancun_state_State : - IsGlobalAlias globals ethereum.cancun.state.globals "State". -Axiom ethereum_cancun_state_TransientStorage : - IsGlobalAlias globals ethereum.cancun.state.globals "TransientStorage". -Axiom ethereum_cancun_state_account_exists_and_is_empty : - IsGlobalAlias globals ethereum.cancun.state.globals "account_exists_and_is_empty". -Axiom ethereum_cancun_state_destroy_account : - IsGlobalAlias globals ethereum.cancun.state.globals "destroy_account". -Axiom ethereum_cancun_state_destroy_touched_empty_accounts : - IsGlobalAlias globals ethereum.cancun.state.globals "destroy_touched_empty_accounts". -Axiom ethereum_cancun_state_get_account : - IsGlobalAlias globals ethereum.cancun.state.globals "get_account". -Axiom ethereum_cancun_state_increment_nonce : - IsGlobalAlias globals ethereum.cancun.state.globals "increment_nonce". -Axiom ethereum_cancun_state_process_withdrawal : - IsGlobalAlias globals ethereum.cancun.state.globals "process_withdrawal". -Axiom ethereum_cancun_state_set_account_balance : - IsGlobalAlias globals ethereum.cancun.state.globals "set_account_balance". -Axiom ethereum_cancun_state_state_root : - IsGlobalAlias globals ethereum.cancun.state.globals "state_root". - -Require ethereum.cancun.transactions. -Axiom ethereum_cancun_transactions_TX_ACCESS_LIST_ADDRESS_COST : - IsGlobalAlias globals ethereum.cancun.transactions.globals "TX_ACCESS_LIST_ADDRESS_COST". -Axiom ethereum_cancun_transactions_TX_ACCESS_LIST_STORAGE_KEY_COST : - IsGlobalAlias globals ethereum.cancun.transactions.globals "TX_ACCESS_LIST_STORAGE_KEY_COST". -Axiom ethereum_cancun_transactions_TX_BASE_COST : - IsGlobalAlias globals ethereum.cancun.transactions.globals "TX_BASE_COST". -Axiom ethereum_cancun_transactions_TX_CREATE_COST : - IsGlobalAlias globals ethereum.cancun.transactions.globals "TX_CREATE_COST". -Axiom ethereum_cancun_transactions_TX_DATA_COST_PER_NON_ZERO : - IsGlobalAlias globals ethereum.cancun.transactions.globals "TX_DATA_COST_PER_NON_ZERO". -Axiom ethereum_cancun_transactions_TX_DATA_COST_PER_ZERO : - IsGlobalAlias globals ethereum.cancun.transactions.globals "TX_DATA_COST_PER_ZERO". -Axiom ethereum_cancun_transactions_AccessListTransaction : - IsGlobalAlias globals ethereum.cancun.transactions.globals "AccessListTransaction". -Axiom ethereum_cancun_transactions_BlobTransaction : - IsGlobalAlias globals ethereum.cancun.transactions.globals "BlobTransaction". -Axiom ethereum_cancun_transactions_FeeMarketTransaction : - IsGlobalAlias globals ethereum.cancun.transactions.globals "FeeMarketTransaction". -Axiom ethereum_cancun_transactions_LegacyTransaction : - IsGlobalAlias globals ethereum.cancun.transactions.globals "LegacyTransaction". -Axiom ethereum_cancun_transactions_Transaction : - IsGlobalAlias globals ethereum.cancun.transactions.globals "Transaction". -Axiom ethereum_cancun_transactions_decode_transaction : - IsGlobalAlias globals ethereum.cancun.transactions.globals "decode_transaction". -Axiom ethereum_cancun_transactions_encode_transaction : - IsGlobalAlias globals ethereum.cancun.transactions.globals "encode_transaction". - -Require ethereum.cancun.trie. -Axiom ethereum_cancun_trie_Trie : - IsGlobalAlias globals ethereum.cancun.trie.globals "Trie". -Axiom ethereum_cancun_trie_root : - IsGlobalAlias globals ethereum.cancun.trie.globals "root". -Axiom ethereum_cancun_trie_trie_set : - IsGlobalAlias globals ethereum.cancun.trie.globals "trie_set". - -Require ethereum.cancun.utils.hexadecimal. -Axiom ethereum_cancun_utils_hexadecimal_hex_to_address : - IsGlobalAlias globals ethereum.cancun.utils.hexadecimal.globals "hex_to_address". - -Require ethereum.cancun.utils.message. -Axiom ethereum_cancun_utils_message_prepare_message : - IsGlobalAlias globals ethereum.cancun.utils.message.globals "prepare_message". - -Require ethereum.cancun.vm.__init__. -Axiom ethereum_cancun_vm___init___Message : - IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Message". - -Require ethereum.cancun.vm.gas. -Axiom ethereum_cancun_vm_gas_calculate_blob_gas_price : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "calculate_blob_gas_price". -Axiom ethereum_cancun_vm_gas_calculate_data_fee : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "calculate_data_fee". -Axiom ethereum_cancun_vm_gas_calculate_excess_blob_gas : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "calculate_excess_blob_gas". -Axiom ethereum_cancun_vm_gas_calculate_total_blob_gas : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "calculate_total_blob_gas". -Axiom ethereum_cancun_vm_gas_init_code_cost : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "init_code_cost". - -Require ethereum.cancun.vm.interpreter. -Axiom ethereum_cancun_vm_interpreter_MAX_CODE_SIZE : - IsGlobalAlias globals ethereum.cancun.vm.interpreter.globals "MAX_CODE_SIZE". -Axiom ethereum_cancun_vm_interpreter_process_message_call : - IsGlobalAlias globals ethereum.cancun.vm.interpreter.globals "process_message_call". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Optional"; "Tuple"; "Union" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Bytes0"; "Bytes32" ]. + +Axiom ethereum_crypto_elliptic_curve_imports : + AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. + +Axiom ethereum_exceptions_imports : + AreImported globals "ethereum.exceptions" [ "InvalidBlock" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U64"; "U256"; "Bytes"; "Uint" ]. + +Axiom ethereum_cancun_imports : + AreImported globals "ethereum.cancun" [ "vm" ]. + +Axiom ethereum_cancun_blocks_imports : + AreImported globals "ethereum.cancun.blocks" [ "Block"; "Header"; "Log"; "Receipt"; "Withdrawal" ]. + +Axiom ethereum_cancun_bloom_imports : + AreImported globals "ethereum.cancun.bloom" [ "logs_bloom" ]. + +Axiom ethereum_cancun_fork_types_imports : + AreImported globals "ethereum.cancun.fork_types" [ "Address"; "Bloom"; "Root"; "VersionedHash" ]. + +Axiom ethereum_cancun_state_imports : + AreImported globals "ethereum.cancun.state" [ "State"; "TransientStorage"; "account_exists_and_is_empty"; "destroy_account"; "destroy_touched_empty_accounts"; "get_account"; "increment_nonce"; "process_withdrawal"; "set_account_balance"; "state_root" ]. + +Axiom ethereum_cancun_transactions_imports : + AreImported globals "ethereum.cancun.transactions" [ "TX_ACCESS_LIST_ADDRESS_COST"; "TX_ACCESS_LIST_STORAGE_KEY_COST"; "TX_BASE_COST"; "TX_CREATE_COST"; "TX_DATA_COST_PER_NON_ZERO"; "TX_DATA_COST_PER_ZERO"; "AccessListTransaction"; "BlobTransaction"; "FeeMarketTransaction"; "LegacyTransaction"; "Transaction"; "decode_transaction"; "encode_transaction" ]. + +Axiom ethereum_cancun_trie_imports : + AreImported globals "ethereum.cancun.trie" [ "Trie"; "root"; "trie_set" ]. + +Axiom ethereum_cancun_utils_hexadecimal_imports : + AreImported globals "ethereum.cancun.utils.hexadecimal" [ "hex_to_address" ]. + +Axiom ethereum_cancun_utils_message_imports : + AreImported globals "ethereum.cancun.utils.message" [ "prepare_message" ]. + +Axiom ethereum_cancun_vm_imports : + AreImported globals "ethereum.cancun.vm" [ "Message" ]. + +Axiom ethereum_cancun_vm_gas_imports : + AreImported globals "ethereum.cancun.vm.gas" [ "calculate_blob_gas_price"; "calculate_data_fee"; "calculate_excess_blob_gas"; "calculate_total_blob_gas"; "init_code_cost" ]. + +Axiom ethereum_cancun_vm_interpreter_imports : + AreImported globals "ethereum.cancun.vm.interpreter" [ "MAX_CODE_SIZE"; "process_message_call" ]. Definition BASE_FEE_MAX_CHANGE_DENOMINATOR : Value.t := M.run ltac:(M.monadic ( Constant.int 8 @@ -318,7 +209,12 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := Hashes of the recent 256 blocks in order of increasing block number. " in let recent_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) in + M.slice (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| Constant.int 255 |), + Constant.None_, + Constant.None_ + |) in let _ := (* if *) M.if_then_else (| @@ -344,17 +240,26 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := )) |) in let recent_block_hashes := make_list [] in - For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_blocks" |) do - let prev_block_hash := - M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "block" |), + M.get_name (| globals, "recent_blocks" |), + ltac:(M.monadic ( + let prev_block_hash := + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in + let _ := M.call (| M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), make_list [ M.get_name (| globals, "prev_block_hash" |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let most_recent_block_hash := M.call (| M.get_name (| globals, "keccak256" |), @@ -362,7 +267,10 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), make_list [ - M.get_field (| M.get_subscript (| M.get_name (| globals, "recent_blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) + M.get_field (| M.get_subscript (| + M.get_name (| globals, "recent_blocks" |), + UnOp.sub (| Constant.int 1 |) + |), "header" |) ], make_dict [] |) @@ -406,7 +314,10 @@ Definition state_transition : Value.t -> Value.t -> M := Block to apply to `chain`. " in let parent_header := - M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) in + M.get_field (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| Constant.int 1 |) + |), "header" |) in let excess_blob_gas := M.call (| M.get_name (| globals, "calculate_excess_blob_gas" |), @@ -572,7 +483,12 @@ Definition state_transition : Value.t -> Value.t -> M := ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) + M.slice (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| Constant.int 255 |), + Constant.None_, + Constant.None_ + |) |) in M.pure Constant.None_ (* else *) @@ -926,7 +842,7 @@ Definition check_transaction : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidBlock" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "InvalidBlock" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -947,7 +863,7 @@ Definition check_transaction : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidBlock" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "InvalidBlock" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -985,7 +901,7 @@ Definition check_transaction : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidBlock" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "InvalidBlock" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1000,7 +916,7 @@ Definition check_transaction : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidBlock" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "InvalidBlock" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1046,7 +962,7 @@ Definition check_transaction : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidBlock" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "InvalidBlock" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1061,7 +977,7 @@ Definition check_transaction : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidBlock" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "InvalidBlock" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1101,7 +1017,7 @@ Definition check_transaction : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidBlock" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "InvalidBlock" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1142,7 +1058,7 @@ Definition check_transaction : Value.t -> Value.t -> M := |) |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidBlock" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "InvalidBlock" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1163,29 +1079,43 @@ Definition check_transaction : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidBlock" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "InvalidBlock" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - For M.get_name (| globals, "blob_versioned_hash" |) in M.get_field (| M.get_name (| globals, "tx" |), "blob_versioned_hashes" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.not_eq (| - M.get_subscript (| M.get_name (| globals, "blob_versioned_hash" |), M.slice (| Constant.int 0, Constant.int 1 |) |), - M.get_name (| globals, "VERSIONED_HASH_VERSION_KZG" |) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "blob_versioned_hash" |), + M.get_field (| M.get_name (| globals, "tx" |), "blob_versioned_hashes" |), ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidBlock" |)) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| + M.slice (| + M.get_name (| globals, "blob_versioned_hash" |), + Constant.int 0, + Constant.int 1, + Constant.None_ + |), + M.get_name (| globals, "VERSIONED_HASH_VERSION_KZG" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "InvalidBlock" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := (* if *) M.if_then_else (| @@ -1201,7 +1131,7 @@ Definition check_transaction : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidBlock" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "InvalidBlock" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1519,21 +1449,25 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - For make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "tx" |) ] in M.call (| - M.get_name (| globals, "enumerate" |), - make_list [ - M.call (| - M.get_name (| globals, "map" |), - make_list [ - M.get_name (| globals, "decode_transaction" |); - M.get_name (| globals, "transactions" |) - ], - make_dict [] - |) - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "tx" |) ], + M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.call (| + M.get_name (| globals, "map" |), + make_list [ + M.get_name (| globals, "decode_transaction" |); + M.get_name (| globals, "transactions" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ M.get_name (| globals, "transactions_trie" |); @@ -1560,56 +1494,56 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.assign (| - make_tuple [ M.get_name (| globals, "sender_address" |); M.get_name (| globals, "effective_gas_price" |); M.get_name (| globals, "blob_versioned_hashes" |) ], - M.call (| - M.get_name (| globals, "check_transaction" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "tx" |); - M.get_name (| globals, "gas_available" |); - M.get_name (| globals, "chain_id" |); - M.get_name (| globals, "base_fee_per_gas" |); - M.get_name (| globals, "excess_blob_gas" |) - ], - make_dict [] - |) - |) in - let env := - M.call (| - M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), - make_list [], - make_dict [] - |) in - let _ := M.assign (| - make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |); M.get_name (| globals, "error" |) ], - M.call (| - M.get_name (| globals, "process_transaction" |), - make_list [ - M.get_name (| globals, "env" |); - M.get_name (| globals, "tx" |) - ], - make_dict [] - |) - |) in - let gas_available := BinOp.sub - M.get_name (| globals, "gas_used" |) - M.get_name (| globals, "gas_used" |) in - let receipt := - M.call (| - M.get_name (| globals, "make_receipt" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "error" |); - BinOp.sub (| - M.get_name (| globals, "block_gas_limit" |), - M.get_name (| globals, "gas_available" |) - |); - M.get_name (| globals, "logs" |) - ], - make_dict [] - |) in - let _ := M.call (| + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "sender_address" |); M.get_name (| globals, "effective_gas_price" |); M.get_name (| globals, "blob_versioned_hashes" |) ], + M.call (| + M.get_name (| globals, "check_transaction" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "tx" |); + M.get_name (| globals, "gas_available" |); + M.get_name (| globals, "chain_id" |); + M.get_name (| globals, "base_fee_per_gas" |); + M.get_name (| globals, "excess_blob_gas" |) + ], + make_dict [] + |) + |) in + let env := + M.call (| + M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |); M.get_name (| globals, "error" |) ], + M.call (| + M.get_name (| globals, "process_transaction" |), + make_list [ + M.get_name (| globals, "env" |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) in + let gas_available := BinOp.sub + M.get_name (| globals, "gas_used" |) + M.get_name (| globals, "gas_used" |) in + let receipt := + M.call (| + M.get_name (| globals, "make_receipt" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "error" |); + BinOp.sub (| + M.get_name (| globals, "block_gas_limit" |), + M.get_name (| globals, "gas_available" |) + |); + M.get_name (| globals, "logs" |) + ], + make_dict [] + |) in + let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ M.get_name (| globals, "receipts_trie" |); @@ -1630,25 +1564,30 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_logs := BinOp.add - M.get_name (| globals, "logs" |) - M.get_name (| globals, "logs" |) in - let blob_gas_used := BinOp.add - M.call (| + let block_logs := BinOp.add + M.get_name (| globals, "logs" |) + M.get_name (| globals, "logs" |) in + let blob_gas_used := BinOp.add + M.call (| M.get_name (| globals, "calculate_total_blob_gas" |), make_list [ M.get_name (| globals, "tx" |) ], make_dict [] |) - M.call (| + M.call (| M.get_name (| globals, "calculate_total_blob_gas" |), make_list [ M.get_name (| globals, "tx" |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1673,14 +1612,18 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - For make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "wd" |) ] in M.call (| - M.get_name (| globals, "enumerate" |), - make_list [ - M.get_name (| globals, "withdrawals" |) - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "wd" |) ], + M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "withdrawals" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ M.get_name (| globals, "withdrawals_trie" |); @@ -1707,7 +1650,7 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "process_withdrawal" |), make_list [ M.get_name (| globals, "state" |); @@ -1715,20 +1658,20 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_field (| M.get_name (| globals, "wd" |), "address" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_field (| M.get_name (| globals, "wd" |), "address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "destroy_account" |), make_list [ M.get_name (| globals, "state" |); @@ -1736,12 +1679,17 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ApplyBodyOutput" |), @@ -1931,24 +1879,42 @@ Definition process_transaction : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - For make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "keys" |) ] in M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) do - let _ := M.call (| + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "keys" |) ], + M.get_field (| M.get_name (| globals, "tx" |), "access_list" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "preaccessed_addresses" |), "add" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] |) in - For M.get_name (| globals, "key" |) in M.get_name (| globals, "keys" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "keys" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "preaccessed_storage_keys" |), "add" |), make_list [ make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "key" |) ] ], make_dict [] |) in - EndFor. - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -2104,8 +2070,12 @@ Definition process_transaction : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "accounts_to_delete" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "output" |), "accounts_to_delete" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "destroy_account" |), make_list [ M.get_field (| M.get_name (| globals, "env" |), "state" |); @@ -2113,7 +2083,12 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.call (| M.get_name (| globals, "destroy_touched_empty_accounts" |), make_list [ @@ -2154,28 +2129,37 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := " in let data_cost := Constant.int 0 in - For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "byte" |), - Constant.int 0 - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "byte" |), + M.get_field (| M.get_name (| globals, "tx" |), "data" |), ltac:(M.monadic ( - let data_cost := BinOp.add - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "byte" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let data_cost := BinOp.add - M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := (* if *) M.if_then_else (| @@ -2242,12 +2226,16 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - For make_tuple [ M.get_name (| globals, "_address" |); M.get_name (| globals, "keys" |) ] in M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) do - let access_list_cost := BinOp.add - M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) - M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) in - let access_list_cost := BinOp.add - BinOp.mult (| + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "_address" |); M.get_name (| globals, "keys" |) ], + M.get_field (| M.get_name (| globals, "tx" |), "access_list" |), + ltac:(M.monadic ( + let access_list_cost := BinOp.add + M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) + M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) in + let access_list_cost := BinOp.add + BinOp.mult (| M.call (| M.get_name (| globals, "len" |), make_list [ @@ -2257,7 +2245,7 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) |) - BinOp.mult (| + BinOp.mult (| M.call (| M.get_name (| globals, "len" |), make_list [ @@ -2267,7 +2255,12 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -2591,13 +2584,18 @@ Definition recover_sender : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "Address" |), make_list [ - M.get_subscript (| M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "public_key" |) - ], - make_dict [] - |), M.slice (| Constant.int 12, Constant.int 32 |) |) + M.slice (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), + Constant.int 12, + Constant.int 32, + Constant.None_ + |) ], make_dict [] |) diff --git a/CoqOfPython/ethereum/cancun/fork_types.v b/CoqOfPython/ethereum/cancun/fork_types.v index 8fdada2..95f1234 100644 --- a/CoqOfPython/ethereum/cancun/fork_types.v +++ b/CoqOfPython/ethereum/cancun/fork_types.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.cancun.fork_types". Definition expr_1 : Value.t := Constant.str " @@ -17,33 +17,17 @@ Introduction Types re-used throughout the specification, which are specific to Ethereum. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes20 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes20". -Axiom ethereum_base_types_Bytes256 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes20"; "Bytes256"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) diff --git a/CoqOfPython/ethereum/cancun/state.v b/CoqOfPython/ethereum/cancun/state.v index 6dcccea..e98a472 100644 --- a/CoqOfPython/ethereum/cancun/state.v +++ b/CoqOfPython/ethereum/cancun/state.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.cancun.state". Definition expr_1 : Value.t := Constant.str " @@ -22,69 +22,26 @@ There is a distinction between an account that does not exist and `EMPTY_ACCOUNT`. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". -Axiom dataclasses_field : - IsGlobalAlias globals dataclasses.globals "field". - -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". -Axiom typing_Iterable : - IsGlobalAlias globals typing.globals "Iterable". -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_modify : - IsGlobalAlias globals ethereum.base_types.globals "modify". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.cancun.blocks. -Axiom ethereum_cancun_blocks_Withdrawal : - IsGlobalAlias globals ethereum.cancun.blocks.globals "Withdrawal". - -Require ethereum.cancun.fork_types. -Axiom ethereum_cancun_fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals ethereum.cancun.fork_types.globals "EMPTY_ACCOUNT". -Axiom ethereum_cancun_fork_types_Account : - IsGlobalAlias globals ethereum.cancun.fork_types.globals "Account". -Axiom ethereum_cancun_fork_types_Address : - IsGlobalAlias globals ethereum.cancun.fork_types.globals "Address". -Axiom ethereum_cancun_fork_types_Root : - IsGlobalAlias globals ethereum.cancun.fork_types.globals "Root". - -Require ethereum.cancun.trie. -Axiom ethereum_cancun_trie_EMPTY_TRIE_ROOT : - IsGlobalAlias globals ethereum.cancun.trie.globals "EMPTY_TRIE_ROOT". -Axiom ethereum_cancun_trie_Trie : - IsGlobalAlias globals ethereum.cancun.trie.globals "Trie". -Axiom ethereum_cancun_trie_copy_trie : - IsGlobalAlias globals ethereum.cancun.trie.globals "copy_trie". -Axiom ethereum_cancun_trie_root : - IsGlobalAlias globals ethereum.cancun.trie.globals "root". -Axiom ethereum_cancun_trie_trie_get : - IsGlobalAlias globals ethereum.cancun.trie.globals "trie_get". -Axiom ethereum_cancun_trie_trie_set : - IsGlobalAlias globals ethereum.cancun.trie.globals "trie_set". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass"; "field" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict"; "Iterable"; "List"; "Optional"; "Set"; "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "modify" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_cancun_blocks_imports : + AreImported globals "ethereum.cancun.blocks" [ "Withdrawal" ]. + +Axiom ethereum_cancun_fork_types_imports : + AreImported globals "ethereum.cancun.fork_types" [ "EMPTY_ACCOUNT"; "Account"; "Address"; "Root" ]. + +Axiom ethereum_cancun_trie_imports : + AreImported globals "ethereum.cancun.trie" [ "EMPTY_TRIE_ROOT"; "Trie"; "copy_trie"; "root"; "trie_get"; "trie_set" ]. Definition State : Value.t := builtins.make_klass @@ -415,13 +372,16 @@ Definition destroy_storage : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -584,7 +544,10 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), + M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |), M.get_name (| globals, "trie" |) |) in M.pure Constant.None_ @@ -610,7 +573,10 @@ Definition set_storage : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -640,7 +606,7 @@ Definition storage_root : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), @@ -650,7 +616,10 @@ Definition storage_root : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "root" |), make_list [ - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) + M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |) ], make_dict [] |) @@ -1200,7 +1169,7 @@ Definition get_storage_original : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "created_accounts" |) |), @@ -1222,7 +1191,10 @@ Definition get_storage_original : Value.t -> Value.t -> M := )) |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "_" |); M.get_name (| globals, "original_trie" |) ], - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), Constant.int 0 |) + M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), + Constant.int 0 + |) |) in let original_account_trie := M.call (| @@ -1389,7 +1361,10 @@ Definition set_transient_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "transient_storage" |), "_tries" |), M.get_name (| globals, "address" |) |), + M.get_subscript (| + M.get_field (| M.get_name (| globals, "transient_storage" |), "_tries" |), + M.get_name (| globals, "address" |) + |), M.get_name (| globals, "trie" |) |) in M.pure Constant.None_ @@ -1415,7 +1390,10 @@ Definition set_transient_storage : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "transient_storage" |), "_tries" |), M.get_name (| globals, "address" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "transient_storage" |), "_tries" |), + M.get_name (| globals, "address" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1435,21 +1413,25 @@ Definition destroy_touched_empty_accounts : Value.t -> Value.t -> M := touched_accounts: `Iterable[Address]` All the accounts that have been touched in the current transaction. " in - For M.get_name (| globals, "address" |) in M.get_name (| globals, "touched_accounts" |) do - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "address" |), + M.get_name (| globals, "touched_accounts" |), ltac:(M.monadic ( - let _ := M.call (| + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "destroy_account" |), make_list [ M.get_name (| globals, "state" |); @@ -1457,10 +1439,15 @@ Definition destroy_touched_empty_accounts : Value.t -> Value.t -> M := ], make_dict [] |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/transactions.v b/CoqOfPython/ethereum/cancun/transactions.v index e6fd77f..e564d06 100644 --- a/CoqOfPython/ethereum/cancun/transactions.v +++ b/CoqOfPython/ethereum/cancun/transactions.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.cancun.transactions". Definition expr_1 : Value.t := Constant.str " @@ -9,45 +9,23 @@ submitted to be executed. If Ethereum is viewed as a state machine, transactions are the events that move between states. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. -Require typing. -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". +Axiom typing_imports : + AreImported globals "typing" [ "Tuple"; "Union" ]. -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U64 : - IsGlobalAlias globals ethereum.base_types.globals "U64". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U64"; "U256"; "Bytes"; "Bytes0"; "Bytes32"; "Uint"; "slotted_freezable" ]. -Require ethereum.exceptions. -Axiom ethereum_exceptions_InvalidBlock : - IsGlobalAlias globals ethereum.exceptions.globals "InvalidBlock". +Axiom ethereum_exceptions_imports : + AreImported globals "ethereum.exceptions" [ "InvalidBlock" ]. -Require ethereum.cancun.fork_types. -Axiom ethereum_cancun_fork_types_Address : - IsGlobalAlias globals ethereum.cancun.fork_types.globals "Address". -Axiom ethereum_cancun_fork_types_VersionedHash : - IsGlobalAlias globals ethereum.cancun.fork_types.globals "VersionedHash". +Axiom ethereum_cancun_fork_types_imports : + AreImported globals "ethereum.cancun.fork_types" [ "Address"; "VersionedHash" ]. Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( Constant.int 21000 @@ -114,7 +92,10 @@ Definition BlobTransaction : Value.t := ]. Definition Transaction : Value.t := M.run ltac:(M.monadic ( - M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "AccessListTransaction" |); M.get_name (| globals, "FeeMarketTransaction" |); M.get_name (| globals, "BlobTransaction" |) ] |) + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "AccessListTransaction" |); M.get_name (| globals, "FeeMarketTransaction" |); M.get_name (| globals, "BlobTransaction" |) ] + |) )). Definition encode_transaction : Value.t -> Value.t -> M := @@ -226,7 +207,7 @@ Definition encode_transaction : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "Exception" |), make_list [ Constant.str "(* At expr: unsupported node type: JoinedStr *)" @@ -266,7 +247,10 @@ Definition decode_transaction : Value.t -> Value.t -> M := (* if *) M.if_then_else (| Compare.eq (| - M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), + M.get_subscript (| + M.get_name (| globals, "tx" |), + Constant.int 0 + |), Constant.int 1 |), (* then *) @@ -276,7 +260,12 @@ Definition decode_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), make_list [ M.get_name (| globals, "AccessListTransaction" |); - M.get_subscript (| M.get_name (| globals, "tx" |), M.slice (| Constant.int 1, Constant.None_ |) |) + M.slice (| + M.get_name (| globals, "tx" |), + Constant.int 1, + Constant.None_, + Constant.None_ + |) ], make_dict [] |) @@ -288,7 +277,10 @@ Definition decode_transaction : Value.t -> Value.t -> M := (* if *) M.if_then_else (| Compare.eq (| - M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), + M.get_subscript (| + M.get_name (| globals, "tx" |), + Constant.int 0 + |), Constant.int 2 |), (* then *) @@ -298,7 +290,12 @@ Definition decode_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), make_list [ M.get_name (| globals, "FeeMarketTransaction" |); - M.get_subscript (| M.get_name (| globals, "tx" |), M.slice (| Constant.int 1, Constant.None_ |) |) + M.slice (| + M.get_name (| globals, "tx" |), + Constant.int 1, + Constant.None_, + Constant.None_ + |) ], make_dict [] |) @@ -310,7 +307,10 @@ Definition decode_transaction : Value.t -> Value.t -> M := (* if *) M.if_then_else (| Compare.eq (| - M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), + M.get_subscript (| + M.get_name (| globals, "tx" |), + Constant.int 0 + |), Constant.int 3 |), (* then *) @@ -320,7 +320,12 @@ Definition decode_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), make_list [ M.get_name (| globals, "BlobTransaction" |); - M.get_subscript (| M.get_name (| globals, "tx" |), M.slice (| Constant.int 1, Constant.None_ |) |) + M.slice (| + M.get_name (| globals, "tx" |), + Constant.int 1, + Constant.None_, + Constant.None_ + |) ], make_dict [] |) @@ -328,7 +333,7 @@ Definition decode_transaction : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidBlock" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "InvalidBlock" |)) |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/cancun/trie.v b/CoqOfPython/ethereum/cancun/trie.v index 87ec388..d850a1f 100644 --- a/CoqOfPython/ethereum/cancun/trie.v +++ b/CoqOfPython/ethereum/cancun/trie.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.cancun.trie". Definition expr_1 : Value.t := Constant.str " @@ -20,85 +20,38 @@ The state trie is the structure responsible for storing (* At top_level_stmt: unsupported node type: Import *) -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". -Axiom dataclasses_field : - IsGlobalAlias globals dataclasses.globals "field". - -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". -Axiom typing_Generic : - IsGlobalAlias globals typing.globals "Generic". -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Mapping : - IsGlobalAlias globals typing.globals "Mapping". -Axiom typing_MutableMapping : - IsGlobalAlias globals typing.globals "MutableMapping". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Sequence : - IsGlobalAlias globals typing.globals "Sequence". -Axiom typing_TypeVar : - IsGlobalAlias globals typing.globals "TypeVar". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". -Axiom typing_cast : - IsGlobalAlias globals typing.globals "cast". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.shanghai.__init__. -Axiom ethereum_shanghai___init___trie : - IsGlobalAlias globals ethereum.shanghai.__init__.globals "trie". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.utils.hexadecimal. -Axiom ethereum_utils_hexadecimal_hex_to_bytes : - IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.cancun.blocks. -Axiom ethereum_cancun_blocks_Receipt : - IsGlobalAlias globals ethereum.cancun.blocks.globals "Receipt". -Axiom ethereum_cancun_blocks_Withdrawal : - IsGlobalAlias globals ethereum.cancun.blocks.globals "Withdrawal". - -Require ethereum.cancun.fork_types. -Axiom ethereum_cancun_fork_types_Account : - IsGlobalAlias globals ethereum.cancun.fork_types.globals "Account". -Axiom ethereum_cancun_fork_types_Address : - IsGlobalAlias globals ethereum.cancun.fork_types.globals "Address". -Axiom ethereum_cancun_fork_types_Root : - IsGlobalAlias globals ethereum.cancun.fork_types.globals "Root". -Axiom ethereum_cancun_fork_types_encode_account : - IsGlobalAlias globals ethereum.cancun.fork_types.globals "encode_account". - -Require ethereum.cancun.transactions. -Axiom ethereum_cancun_transactions_LegacyTransaction : - IsGlobalAlias globals ethereum.cancun.transactions.globals "LegacyTransaction". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass"; "field" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict"; "Generic"; "List"; "Mapping"; "MutableMapping"; "Optional"; "Sequence"; "TypeVar"; "Union"; "cast" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. + +Axiom ethereum_shanghai_imports : + AreImported globals "ethereum.shanghai" [ "trie" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_utils_hexadecimal_imports : + AreImported globals "ethereum.utils.hexadecimal" [ "hex_to_bytes" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_cancun_blocks_imports : + AreImported globals "ethereum.cancun.blocks" [ "Receipt"; "Withdrawal" ]. + +Axiom ethereum_cancun_fork_types_imports : + AreImported globals "ethereum.cancun.fork_types" [ "Account"; "Address"; "Root"; "encode_account" ]. + +Axiom ethereum_cancun_transactions_imports : + AreImported globals "ethereum.cancun.transactions" [ "LegacyTransaction" ]. Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -117,7 +70,10 @@ Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( )). Definition Node : Value.t := M.run ltac:(M.monadic ( - M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Bytes" |); M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |); M.get_name (| globals, "Withdrawal" |); Constant.None_ ] |) + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Bytes" |); M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |); M.get_name (| globals, "Withdrawal" |); Constant.None_ ] + |) )). Definition K : Value.t := M.run ltac:(M.monadic ( @@ -135,12 +91,36 @@ Definition V : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "TypeVar" |), make_list [ Constant.str "V"; - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Account" |) |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Bytes" |) |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Account" |) + |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Bytes" |) + |); M.get_name (| globals, "Bytes" |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Bytes" |) ] |) |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Bytes" |) ] |) |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Withdrawal" |); M.get_name (| globals, "Bytes" |) ] |) |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Bytes" |) ] + |) + |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Bytes" |) ] + |) + |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "Withdrawal" |); M.get_name (| globals, "Bytes" |) ] + |) + |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |) ], @@ -179,7 +159,10 @@ Definition BranchNode : Value.t := ]. Definition InternalNode : Value.t := M.run ltac:(M.monadic ( - M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LeafNode" |); M.get_name (| globals, "ExtensionNode" |); M.get_name (| globals, "BranchNode" |) ] |) + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "LeafNode" |); M.get_name (| globals, "ExtensionNode" |); M.get_name (| globals, "BranchNode" |) ] + |) )). Definition encode_internal_node : Value.t -> Value.t -> M := @@ -291,7 +274,7 @@ Definition encode_internal_node : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "(* At expr: unsupported node type: JoinedStr *)" @@ -531,13 +514,16 @@ Definition trie_set : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "key" |), M.get_field (| M.get_name (| globals, "trie" |), "_data" |) |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + M.get_name (| globals, "key" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -547,7 +533,10 @@ Definition trie_set : Value.t -> Value.t -> M := (* else *) )), ltac:(M.monadic ( let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), + M.get_subscript (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + M.get_name (| globals, "key" |) + |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_ @@ -592,51 +581,66 @@ Definition common_prefix_length : Value.t -> Value.t -> M := let _ := Constant.str " Find the longest common prefix of two sequences. " in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "a" |) - ], - make_dict [] - |) - ], - make_dict [] - |) do - let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| - M.get_name (| globals, "i" |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "b" |) - ], - make_dict [] - |) - |), - ltac:(M.monadic ( - Compare.not_eq (| - M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), - M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) - |) - )) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + ], + make_dict [] + |), ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "i" |) - |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_subscript (| + M.get_name (| globals, "a" |), + M.get_name (| globals, "i" |) + |), + M.get_subscript (| + M.get_name (| globals, "b" |), + M.get_name (| globals, "i" |) + |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "len" |), @@ -721,38 +725,53 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 0; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |); - Constant.int 2 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ BinOp.add (| BinOp.mult (| Constant.int 16, - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "i" |) + |) |), - M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) + |) |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -770,43 +789,61 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := Constant.int 1 |) |), - M.get_subscript (| M.get_name (| globals, "x" |), Constant.int 0 |) + M.get_subscript (| + M.get_name (| globals, "x" |), + Constant.int 0 + |) |) ], make_dict [] |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 1; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |); - Constant.int 2 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 1; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ BinOp.add (| BinOp.mult (| Constant.int 16, - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "i" |) + |) |), - M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) + |) |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -853,40 +890,55 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := ], make_dict [] |) in - For make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ] in M.call (| - M.get_name (| globals, "enumerate" |), - make_list [ - M.get_name (| globals, "bytes_" |) - ], - make_dict [] - |) do - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.mult (| - M.get_name (| globals, "byte_index" |), - Constant.int 2 - |) |), - BinOp.r_shift (| - BinOp.bit_and (| - M.get_name (| globals, "byte" |), - Constant.int 240 - |), - Constant.int 4 - |) - |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "byte_index" |), - Constant.int 2 - |), - Constant.int 1 - |) |), - BinOp.bit_and (| - M.get_name (| globals, "byte" |), - Constant.int 15 - |) - |) in - EndFor. + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ], + M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "bytes_" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "nibble_list" |), + BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |) + |), + BinOp.r_shift (| + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 240 + |), + Constant.int 4 + |) + |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "nibble_list" |), + BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |), + Constant.int 1 + |) + |), + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 15 + |) + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Bytes" |), @@ -919,65 +971,69 @@ Definition _prepare_trie : Value.t -> Value.t -> M := Object with keys mapped to nibble-byte form. " in (* At stmt: unsupported node type: AnnAssign *) - For make_tuple [ M.get_name (| globals, "preimage" |); M.get_name (| globals, "value" |) ] in M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "items" |), - make_list [], - make_dict [] - |) do - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "value" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "preimage" |); M.get_name (| globals, "value" |) ], + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "items" |), + make_list [], + make_dict [] + |), ltac:(M.monadic ( - let _ := M.assert (| Compare.is_not (| + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in - let address := - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in - let encoded_value := - M.call (| - M.get_name (| globals, "encode_node" |), - make_list [ - M.get_name (| globals, "value" |); + let address := M.call (| - M.get_name (| globals, "get_storage_root" |), + M.get_name (| globals, "Address" |), make_list [ - M.get_name (| globals, "address" |) + M.get_name (| globals, "preimage" |) ], make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let encoded_value := - M.call (| - M.get_name (| globals, "encode_node" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - )) |) in - let _ := M.call (| + |) in + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |); + M.call (| + M.get_name (| globals, "get_storage_root" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_eq (| @@ -989,38 +1045,46 @@ Definition _prepare_trie : Value.t -> Value.t -> M := make_dict [] |) in (* At stmt: unsupported node type: AnnAssign *) - let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "trie" |), "secured" |), - (* then *) - ltac:(M.monadic ( - let key := - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "trie" |), "secured" |), + (* then *) + ltac:(M.monadic ( + let key := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let key := + M.get_name (| globals, "preimage" |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "mapped" |), + M.call (| + M.get_name (| globals, "bytes_to_nibble_list" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |) + |), + M.get_name (| globals, "encoded_value" |) + |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let key := - M.get_name (| globals, "preimage" |) in + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "mapped" |), M.call (| - M.get_name (| globals, "bytes_to_nibble_list" |), - make_list [ - M.get_name (| globals, "key" |) - ], - make_dict [] - |) |), - M.get_name (| globals, "encoded_value" |) - |) in - EndFor. + )) + |) in let _ := M.return_ (| M.get_name (| globals, "mapped" |) |) in @@ -1213,8 +1277,16 @@ Definition patricialize : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "LeafNode" |), make_list [ - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |); - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) + M.slice (| + M.get_name (| globals, "arbitrary_key" |), + M.get_name (| globals, "level" |), + Constant.None_, + Constant.None_ + |); + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "arbitrary_key" |) + |) ], make_dict [] |) in @@ -1227,7 +1299,12 @@ Definition patricialize : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in let substring := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "arbitrary_key" |), + M.get_name (| globals, "level" |), + Constant.None_, + Constant.None_ + |) in let prefix_length := M.call (| M.get_name (| globals, "len" |), @@ -1236,39 +1313,53 @@ Definition patricialize : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do - let prefix_length := - M.call (| - M.get_name (| globals, "min" |), - make_list [ - M.get_name (| globals, "prefix_length" |); + let _ := + M.for_ (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "obj" |), + ltac:(M.monadic ( + let prefix_length := M.call (| - M.get_name (| globals, "common_prefix_length" |), + M.get_name (| globals, "min" |), make_list [ - M.get_name (| globals, "substring" |); - M.get_subscript (| M.get_name (| globals, "key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) + M.get_name (| globals, "prefix_length" |); + M.call (| + M.get_name (| globals, "common_prefix_length" |), + make_list [ + M.get_name (| globals, "substring" |); + M.slice (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "level" |), + Constant.None_, + Constant.None_ + |) + ], + make_dict [] + |) ], make_dict [] - |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "prefix_length" |), - Constant.int 0 - |), - (* then *) - ltac:(M.monadic ( - let _ := M.break (| |) in + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "prefix_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := (* if *) M.if_then_else (| @@ -1279,10 +1370,15 @@ Definition patricialize : Value.t -> Value.t -> M := (* then *) ltac:(M.monadic ( let prefix := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), BinOp.add (| + M.slice (| + M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |), - M.get_name (| globals, "prefix_length" |) - |) |) |) in + BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |), + Constant.None_ + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ExtensionNode" |), @@ -1315,70 +1411,106 @@ Definition patricialize : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) - For M.get_name (| globals, "_" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 16 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "_" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 16 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "branches" |), "append" |), make_list [ {} ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let value := Constant.bytes "" in - For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "key" |) - ], - make_dict [] - |), - M.get_name (| globals, "level" |) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "obj" |), ltac:(M.monadic ( let _ := (* if *) M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); - make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] - ], - make_dict [] + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |), + M.get_name (| globals, "level" |) |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "AssertionError" |)) |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "key" |) + |); + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "AssertionError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "key" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| + M.get_subscript (| + M.get_name (| globals, "branches" |), + M.get_subscript (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "level" |) + |) + |), + M.get_name (| globals, "key" |) + |), + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "key" |) + |) + |) in M.pure Constant.None_ )) |) in - let value := - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.assign (| - M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) - |) in + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "BranchNode" |), diff --git a/CoqOfPython/ethereum/cancun/utils/__init__.v b/CoqOfPython/ethereum/cancun/utils/__init__.v index 1baedea..3e26e47 100644 --- a/CoqOfPython/ethereum/cancun/utils/__init__.v +++ b/CoqOfPython/ethereum/cancun/utils/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.cancun.utils.__init__". Definition expr_1 : Value.t := Constant.str " diff --git a/CoqOfPython/ethereum/cancun/utils/address.v b/CoqOfPython/ethereum/cancun/utils/address.v index 9d642c7..cbc30b0 100644 --- a/CoqOfPython/ethereum/cancun/utils/address.v +++ b/CoqOfPython/ethereum/cancun/utils/address.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.cancun.utils.address". Definition expr_1 : Value.t := Constant.str " @@ -18,33 +18,23 @@ Address specific functions used in this cancun version of specification. ". -Require typing. -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". +Axiom typing_imports : + AreImported globals "typing" [ "Union" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes32"; "Uint" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_left_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. -Require ethereum.cancun.fork_types. -Axiom ethereum_cancun_fork_types_Address : - IsGlobalAlias globals ethereum.cancun.fork_types.globals "Address". +Axiom ethereum_cancun_fork_types_imports : + AreImported globals "ethereum.cancun.fork_types" [ "Address" ]. Definition to_address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -66,11 +56,16 @@ Definition to_address : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "Address" |), make_list [ - M.get_subscript (| M.call (| - M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), - make_list [], - make_dict [] - |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) + M.slice (| + M.call (| + M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), + UnOp.sub (| Constant.int 20 |), + Constant.None_, + Constant.None_ + |) ], make_dict [] |) @@ -114,7 +109,12 @@ Definition compute_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "computed_address" |), + UnOp.sub (| Constant.int 20 |), + Constant.None_, + Constant.None_ + |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -182,7 +182,12 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "computed_address" |), + UnOp.sub (| Constant.int 20 |), + Constant.None_, + Constant.None_ + |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/cancun/utils/hexadecimal.v b/CoqOfPython/ethereum/cancun/utils/hexadecimal.v index a10ce83..2739846 100644 --- a/CoqOfPython/ethereum/cancun/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/cancun/utils/hexadecimal.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.cancun.utils.hexadecimal". Definition expr_1 : Value.t := Constant.str " @@ -18,17 +18,11 @@ Hexadecimal utility functions used in this specification, specific to Cancun types. ". -Require ethereum.utils.hexadecimal. -Axiom ethereum_utils_hexadecimal_remove_hex_prefix : - IsGlobalAlias globals ethereum.utils.hexadecimal.globals "remove_hex_prefix". - -Require ethereum.cancun.fork_types. -Axiom ethereum_cancun_fork_types_Address : - IsGlobalAlias globals ethereum.cancun.fork_types.globals "Address". -Axiom ethereum_cancun_fork_types_Bloom : - IsGlobalAlias globals ethereum.cancun.fork_types.globals "Bloom". -Axiom ethereum_cancun_fork_types_Root : - IsGlobalAlias globals ethereum.cancun.fork_types.globals "Root". +Axiom ethereum_utils_hexadecimal_imports : + AreImported globals "ethereum.utils.hexadecimal" [ "remove_hex_prefix" ]. + +Axiom ethereum_cancun_fork_types_imports : + AreImported globals "ethereum.cancun.fork_types" [ "Address"; "Bloom"; "Root" ]. Definition hex_to_root : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/cancun/utils/message.v b/CoqOfPython/ethereum/cancun/utils/message.v index ce231f7..ec2cf45 100644 --- a/CoqOfPython/ethereum/cancun/utils/message.v +++ b/CoqOfPython/ethereum/cancun/utils/message.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.cancun.utils.message". Definition expr_1 : Value.t := Constant.str " @@ -18,49 +18,26 @@ Message specific functions used in this cancun version of specification. ". -Require typing. -Axiom typing_FrozenSet : - IsGlobalAlias globals typing.globals "FrozenSet". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". +Axiom typing_imports : + AreImported globals "typing" [ "FrozenSet"; "Optional"; "Tuple"; "Union" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Bytes32"; "Uint" ]. -Require ethereum.cancun.fork_types. -Axiom ethereum_cancun_fork_types_Address : - IsGlobalAlias globals ethereum.cancun.fork_types.globals "Address". +Axiom ethereum_cancun_fork_types_imports : + AreImported globals "ethereum.cancun.fork_types" [ "Address" ]. -Require ethereum.cancun.state. -Axiom ethereum_cancun_state_get_account : - IsGlobalAlias globals ethereum.cancun.state.globals "get_account". +Axiom ethereum_cancun_state_imports : + AreImported globals "ethereum.cancun.state" [ "get_account" ]. -Require ethereum.cancun.vm.__init__. -Axiom ethereum_cancun_vm___init___Environment : - IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Environment". -Axiom ethereum_cancun_vm___init___Message : - IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Message". +Axiom ethereum_cancun_vm_imports : + AreImported globals "ethereum.cancun.vm" [ "Environment"; "Message" ]. -Require ethereum.cancun.vm.precompiled_contracts.mapping. -Axiom ethereum_cancun_vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : - IsGlobalAlias globals ethereum.cancun.vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". +Axiom ethereum_cancun_vm_precompiled_contracts_mapping_imports : + AreImported globals "ethereum.cancun.vm.precompiled_contracts.mapping" [ "PRE_COMPILED_CONTRACTS" ]. -Require ethereum.cancun.utils.address. -Axiom ethereum_cancun_utils_address_compute_contract_address : - IsGlobalAlias globals ethereum.cancun.utils.address.globals "compute_contract_address". +Axiom ethereum_cancun_utils_address_imports : + AreImported globals "ethereum.cancun.utils.address" [ "compute_contract_address" ]. Definition prepare_message : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -198,7 +175,7 @@ Definition prepare_message : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "Target must be address or empty bytes" diff --git a/CoqOfPython/ethereum/cancun/vm/__init__.v b/CoqOfPython/ethereum/cancun/vm/__init__.v index a534ff3..a41db5c 100644 --- a/CoqOfPython/ethereum/cancun/vm/__init__.v +++ b/CoqOfPython/ethereum/cancun/vm/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.cancun.vm.__init__". Definition expr_1 : Value.t := Constant.str " @@ -18,61 +18,29 @@ The abstract computer which runs the code stored in an `.fork_types.Account`. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple"; "Union" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U64 : - IsGlobalAlias globals ethereum.base_types.globals "U64". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U64"; "U256"; "Bytes"; "Bytes0"; "Bytes32"; "Uint" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. -Require ethereum.cancun.blocks. -Axiom ethereum_cancun_blocks_Log : - IsGlobalAlias globals ethereum.cancun.blocks.globals "Log". +Axiom ethereum_cancun_blocks_imports : + AreImported globals "ethereum.cancun.blocks" [ "Log" ]. -Require ethereum.cancun.fork_types. -Axiom ethereum_cancun_fork_types_Address : - IsGlobalAlias globals ethereum.cancun.fork_types.globals "Address". -Axiom ethereum_cancun_fork_types_VersionedHash : - IsGlobalAlias globals ethereum.cancun.fork_types.globals "VersionedHash". +Axiom ethereum_cancun_fork_types_imports : + AreImported globals "ethereum.cancun.fork_types" [ "Address"; "VersionedHash" ]. -Require ethereum.cancun.state. -Axiom ethereum_cancun_state_State : - IsGlobalAlias globals ethereum.cancun.state.globals "State". -Axiom ethereum_cancun_state_TransientStorage : - IsGlobalAlias globals ethereum.cancun.state.globals "TransientStorage". -Axiom ethereum_cancun_state_account_exists_and_is_empty : - IsGlobalAlias globals ethereum.cancun.state.globals "account_exists_and_is_empty". +Axiom ethereum_cancun_state_imports : + AreImported globals "ethereum.cancun.state" [ "State"; "TransientStorage"; "account_exists_and_is_empty" ]. -Require ethereum.cancun.vm.precompiled_contracts.__init__. -Axiom ethereum_cancun_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : - IsGlobalAlias globals ethereum.cancun.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". +Axiom ethereum_cancun_vm_precompiled_contracts_imports : + AreImported globals "ethereum.cancun.vm.precompiled_contracts" [ "RIPEMD160_ADDRESS" ]. Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] @@ -207,7 +175,7 @@ Definition incorporate_child_on_error : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "RIPEMD160_ADDRESS" |), M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) |), diff --git a/CoqOfPython/ethereum/cancun/vm/exceptions.v b/CoqOfPython/ethereum/cancun/vm/exceptions.v index 722d4a8..cd1f083 100644 --- a/CoqOfPython/ethereum/cancun/vm/exceptions.v +++ b/CoqOfPython/ethereum/cancun/vm/exceptions.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.cancun.vm.exceptions". Definition expr_1 : Value.t := Constant.str " @@ -17,9 +17,8 @@ Introduction Exceptions which cause the EVM to halt exceptionally. ". -Require ethereum.exceptions. -Axiom ethereum_exceptions_EthereumException : - IsGlobalAlias globals ethereum.exceptions.globals "EthereumException". +Axiom ethereum_exceptions_imports : + AreImported globals "ethereum.exceptions" [ "EthereumException" ]. Definition ExceptionalHalt : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/cancun/vm/gas.v b/CoqOfPython/ethereum/cancun/vm/gas.v index ae28679..1cf1c94 100644 --- a/CoqOfPython/ethereum/cancun/vm/gas.v +++ b/CoqOfPython/ethereum/cancun/vm/gas.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.cancun.vm.gas". Definition expr_1 : Value.t := Constant.str " @@ -17,53 +17,32 @@ Introduction EVM gas constants and calculators. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_U64 : - IsGlobalAlias globals ethereum.base_types.globals "U64". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.trace. -Axiom ethereum_trace_GasAndRefund : - IsGlobalAlias globals ethereum.trace.globals "GasAndRefund". -Axiom ethereum_trace_evm_trace : - IsGlobalAlias globals ethereum.trace.globals "evm_trace". - -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". -Axiom ethereum_utils_numeric_taylor_exponential : - IsGlobalAlias globals ethereum.utils.numeric.globals "taylor_exponential". - -Require ethereum.cancun.blocks. -Axiom ethereum_cancun_blocks_Header : - IsGlobalAlias globals ethereum.cancun.blocks.globals "Header". - -Require ethereum.cancun.transactions. -Axiom ethereum_cancun_transactions_BlobTransaction : - IsGlobalAlias globals ethereum.cancun.transactions.globals "BlobTransaction". -Axiom ethereum_cancun_transactions_Transaction : - IsGlobalAlias globals ethereum.cancun.transactions.globals "Transaction". - -Require ethereum.cancun.vm.__init__. -Axiom ethereum_cancun_vm___init___Evm : - IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Evm". - -Require ethereum.cancun.vm.exceptions. -Axiom ethereum_cancun_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.cancun.vm.exceptions.globals "OutOfGasError". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U64"; "U256"; "Uint" ]. + +Axiom ethereum_trace_imports : + AreImported globals "ethereum.trace" [ "GasAndRefund"; "evm_trace" ]. + +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32"; "taylor_exponential" ]. + +Axiom ethereum_cancun_blocks_imports : + AreImported globals "ethereum.cancun.blocks" [ "Header" ]. + +Axiom ethereum_cancun_transactions_imports : + AreImported globals "ethereum.cancun.transactions" [ "BlobTransaction"; "Transaction" ]. + +Axiom ethereum_cancun_vm_imports : + AreImported globals "ethereum.cancun.vm" [ "Evm" ]. + +Axiom ethereum_cancun_vm_exceptions_imports : + AreImported globals "ethereum.cancun.vm.exceptions" [ "OutOfGasError" ]. Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -589,7 +568,7 @@ Definition charge_gas : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -706,105 +685,114 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := ], make_dict [] |) in - For make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ] in M.get_name (| globals, "extensions" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "size" |), - Constant.int 0 - |), - (* then *) + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ], + M.get_name (| globals, "extensions" |), ltac:(M.monadic ( - let _ := M.continue (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let before_size := - M.call (| - M.get_name (| globals, "ceil32" |), - make_list [ - M.get_name (| globals, "current_size" |) - ], - make_dict [] - |) in - let after_size := - M.call (| - M.get_name (| globals, "ceil32" |), - make_list [ - BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "size" |), + Constant.int 0 |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.lt_e (| - M.get_name (| globals, "after_size" |), - M.get_name (| globals, "before_size" |) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.continue (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let size_to_extend := BinOp.add - BinOp.sub (| + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let before_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "current_size" |) + ], + make_dict [] + |) in + let after_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let size_to_extend := BinOp.add + BinOp.sub (| M.get_name (| globals, "after_size" |), M.get_name (| globals, "before_size" |) |) - BinOp.sub (| + BinOp.sub (| M.get_name (| globals, "after_size" |), M.get_name (| globals, "before_size" |) |) in - let already_paid := - M.call (| - M.get_name (| globals, "calculate_memory_gas_cost" |), - make_list [ - M.get_name (| globals, "before_size" |) - ], - make_dict [] - |) in - let total_cost := - M.call (| - M.get_name (| globals, "calculate_memory_gas_cost" |), - make_list [ - M.get_name (| globals, "after_size" |) - ], - make_dict [] - |) in - let to_be_paid := BinOp.add - BinOp.sub (| + let already_paid := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "before_size" |) + ], + make_dict [] + |) in + let total_cost := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "after_size" |) + ], + make_dict [] + |) in + let to_be_paid := BinOp.add + BinOp.sub (| M.get_name (| globals, "total_cost" |), M.get_name (| globals, "already_paid" |) |) - BinOp.sub (| + BinOp.sub (| M.get_name (| globals, "total_cost" |), M.get_name (| globals, "already_paid" |) |) in - let current_size := - M.get_name (| globals, "after_size" |) in - EndFor. + let current_size := + M.get_name (| globals, "after_size" |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ExtendMemory" |), diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/__init__.v b/CoqOfPython/ethereum/cancun/vm/instructions/__init__.v index c88f1fb..770a543 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/__init__.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.cancun.vm.instructions.__init__". Definition expr_1 : Value.t := Constant.str " @@ -20,59 +20,44 @@ implementations. (* At top_level_stmt: unsupported node type: Import *) -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict" ]. -Require ethereum.cancun.vm.instructions.__init__. -Axiom ethereum_cancun_vm_instructions___init___arithmetic : - IsGlobalAlias globals ethereum.cancun.vm.instructions.__init__.globals "arithmetic". +Axiom ethereum_cancun_vm_instructions_imports : + AreImported globals "ethereum.cancun.vm.instructions" [ "arithmetic" ]. -Require ethereum.cancun.vm.instructions.__init__. -Axiom ethereum_cancun_vm_instructions___init___bitwise : - IsGlobalAlias globals ethereum.cancun.vm.instructions.__init__.globals "bitwise". +Axiom ethereum_cancun_vm_instructions_imports : + AreImported globals "ethereum.cancun.vm.instructions" [ "bitwise" ]. -Require ethereum.cancun.vm.instructions.__init__. -Axiom ethereum_cancun_vm_instructions___init___block : - IsGlobalAlias globals ethereum.cancun.vm.instructions.__init__.globals "block". +Axiom ethereum_cancun_vm_instructions_imports : + AreImported globals "ethereum.cancun.vm.instructions" [ "block" ]. -Require ethereum.cancun.vm.instructions.__init__. -Axiom ethereum_cancun_vm_instructions___init___comparison : - IsGlobalAlias globals ethereum.cancun.vm.instructions.__init__.globals "comparison". +Axiom ethereum_cancun_vm_instructions_imports : + AreImported globals "ethereum.cancun.vm.instructions" [ "comparison" ]. -Require ethereum.cancun.vm.instructions.__init__. -Axiom ethereum_cancun_vm_instructions___init___control_flow : - IsGlobalAlias globals ethereum.cancun.vm.instructions.__init__.globals "control_flow". +Axiom ethereum_cancun_vm_instructions_imports : + AreImported globals "ethereum.cancun.vm.instructions" [ "control_flow" ]. -Require ethereum.cancun.vm.instructions.__init__. -Axiom ethereum_cancun_vm_instructions___init___environment : - IsGlobalAlias globals ethereum.cancun.vm.instructions.__init__.globals "environment". +Axiom ethereum_cancun_vm_instructions_imports : + AreImported globals "ethereum.cancun.vm.instructions" [ "environment" ]. -Require ethereum.cancun.vm.instructions.__init__. -Axiom ethereum_cancun_vm_instructions___init___keccak : - IsGlobalAlias globals ethereum.cancun.vm.instructions.__init__.globals "keccak". +Axiom ethereum_cancun_vm_instructions_imports : + AreImported globals "ethereum.cancun.vm.instructions" [ "keccak" ]. -Require ethereum.cancun.vm.instructions.__init__. -Axiom ethereum_cancun_vm_instructions___init___log : - IsGlobalAlias globals ethereum.cancun.vm.instructions.__init__.globals "log". +Axiom ethereum_cancun_vm_instructions_imports : + AreImported globals "ethereum.cancun.vm.instructions" [ "log" ]. -Require ethereum.cancun.vm.instructions.__init__. -Axiom ethereum_cancun_vm_instructions___init___memory : - IsGlobalAlias globals ethereum.cancun.vm.instructions.__init__.globals "memory". +Axiom ethereum_cancun_vm_instructions_imports : + AreImported globals "ethereum.cancun.vm.instructions" [ "memory" ]. -Require ethereum.cancun.vm.instructions.__init__. -Axiom ethereum_cancun_vm_instructions___init___stack : - IsGlobalAlias globals ethereum.cancun.vm.instructions.__init__.globals "stack". +Axiom ethereum_cancun_vm_instructions_imports : + AreImported globals "ethereum.cancun.vm.instructions" [ "stack" ]. -Require ethereum.cancun.vm.instructions.__init__. -Axiom ethereum_cancun_vm_instructions___init___storage : - IsGlobalAlias globals ethereum.cancun.vm.instructions.__init__.globals "storage". +Axiom ethereum_cancun_vm_instructions_imports : + AreImported globals "ethereum.cancun.vm.instructions" [ "storage" ]. -Require ethereum.cancun.vm.instructions.__init__. -Axiom ethereum_cancun_vm_instructions___init___system : - IsGlobalAlias globals ethereum.cancun.vm.instructions.__init__.globals "system". +Axiom ethereum_cancun_vm_instructions_imports : + AreImported globals "ethereum.cancun.vm.instructions" [ "system" ]. Definition Ops : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/cancun/vm/instructions/arithmetic.v index 0b28cf8..5f279b7 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/arithmetic.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.cancun.vm.instructions.arithmetic". Definition expr_1 : Value.t := Constant.str " @@ -17,43 +17,20 @@ Introduction Implementations of the EVM Arithmetic instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U255_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U255_CEIL_VALUE". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_U256_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U255_CEIL_VALUE"; "U256"; "U256_CEIL_VALUE"; "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_get_sign : - IsGlobalAlias globals ethereum.utils.numeric.globals "get_sign". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "get_sign" ]. -Require ethereum.cancun.vm.__init__. -Axiom ethereum_cancun_vm___init___Evm : - IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Evm". +Axiom ethereum_cancun_vm_imports : + AreImported globals "ethereum.cancun.vm" [ "Evm" ]. -Require ethereum.cancun.vm.gas. -Axiom ethereum_cancun_vm_gas_GAS_EXPONENTIATION : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_EXPONENTIATION". -Axiom ethereum_cancun_vm_gas_GAS_EXPONENTIATION_PER_BYTE : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_EXPONENTIATION_PER_BYTE". -Axiom ethereum_cancun_vm_gas_GAS_LOW : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_LOW". -Axiom ethereum_cancun_vm_gas_GAS_MID : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_MID". -Axiom ethereum_cancun_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_cancun_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "charge_gas". +Axiom ethereum_cancun_vm_gas_imports : + AreImported globals "ethereum.cancun.vm.gas" [ "GAS_EXPONENTIATION"; "GAS_EXPONENTIATION_PER_BYTE"; "GAS_LOW"; "GAS_MID"; "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.cancun.vm.stack. -Axiom ethereum_cancun_vm_stack_pop : - IsGlobalAlias globals ethereum.cancun.vm.stack.globals "pop". -Axiom ethereum_cancun_vm_stack_push : - IsGlobalAlias globals ethereum.cancun.vm.stack.globals "push". +Axiom ethereum_cancun_vm_stack_imports : + AreImported globals "ethereum.cancun.vm.stack" [ "pop"; "push" ]. Definition add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -1030,19 +1007,27 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let value_bytes := - M.get_subscript (| M.get_name (| globals, "value_bytes" |), M.slice (| BinOp.sub (| - Constant.int 31, - M.call (| - M.get_name (| globals, "int" |), - make_list [ - M.get_name (| globals, "byte_num" |) - ], - make_dict [] - |) - |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "value_bytes" |), + BinOp.sub (| + Constant.int 31, + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "byte_num" |) + ], + make_dict [] + |) + |), + Constant.None_, + Constant.None_ + |) in let sign_bit := BinOp.r_shift (| - M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), + M.get_subscript (| + M.get_name (| globals, "value_bytes" |), + Constant.int 0 + |), Constant.int 7 |) in let _ := diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/bitwise.v b/CoqOfPython/ethereum/cancun/vm/instructions/bitwise.v index 09dde27..c4e95c5 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/bitwise.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.cancun.vm.instructions.bitwise". Definition expr_1 : Value.t := Constant.str " @@ -17,27 +17,17 @@ Introduction Implementations of the EVM bitwise instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_U256_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "U256_CEIL_VALUE" ]. -Require ethereum.cancun.vm.__init__. -Axiom ethereum_cancun_vm___init___Evm : - IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Evm". +Axiom ethereum_cancun_vm_imports : + AreImported globals "ethereum.cancun.vm" [ "Evm" ]. -Require ethereum.cancun.vm.gas. -Axiom ethereum_cancun_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_cancun_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "charge_gas". +Axiom ethereum_cancun_vm_gas_imports : + AreImported globals "ethereum.cancun.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.cancun.vm.stack. -Axiom ethereum_cancun_vm_stack_pop : - IsGlobalAlias globals ethereum.cancun.vm.stack.globals "pop". -Axiom ethereum_cancun_vm_stack_push : - IsGlobalAlias globals ethereum.cancun.vm.stack.globals "push". +Axiom ethereum_cancun_vm_stack_imports : + AreImported globals "ethereum.cancun.vm.stack" [ "pop"; "push" ]. Definition bitwise_and : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/block.v b/CoqOfPython/ethereum/cancun/vm/instructions/block.v index 9bd1ac0..86d212c 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/block.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/block.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.cancun.vm.instructions.block". Definition expr_1 : Value.t := Constant.str " @@ -17,27 +17,17 @@ Introduction Implementations of the EVM block instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.cancun.vm.__init__. -Axiom ethereum_cancun_vm___init___Evm : - IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Evm". +Axiom ethereum_cancun_vm_imports : + AreImported globals "ethereum.cancun.vm" [ "Evm" ]. -Require ethereum.cancun.vm.gas. -Axiom ethereum_cancun_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_BASE". -Axiom ethereum_cancun_vm_gas_GAS_BLOCK_HASH : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_BLOCK_HASH". -Axiom ethereum_cancun_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "charge_gas". +Axiom ethereum_cancun_vm_gas_imports : + AreImported globals "ethereum.cancun.vm.gas" [ "GAS_BASE"; "GAS_BLOCK_HASH"; "charge_gas" ]. -Require ethereum.cancun.vm.stack. -Axiom ethereum_cancun_vm_stack_pop : - IsGlobalAlias globals ethereum.cancun.vm.stack.globals "pop". -Axiom ethereum_cancun_vm_stack_push : - IsGlobalAlias globals ethereum.cancun.vm.stack.globals "push". +Axiom ethereum_cancun_vm_stack_imports : + AreImported globals "ethereum.cancun.vm.stack" [ "pop"; "push" ]. Definition block_hash : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -100,10 +90,13 @@ Definition block_hash : Value.t -> Value.t -> M := (* else *) )), ltac:(M.monadic ( let hash := - M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), - M.get_name (| globals, "block_number" |) - |) |) |) in + M.get_subscript (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), + UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + M.get_name (| globals, "block_number" |) + |) |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/comparison.v b/CoqOfPython/ethereum/cancun/vm/instructions/comparison.v index d3ba649..d1ca20b 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/comparison.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.cancun.vm.instructions.comparison". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementations of the EVM Comparison instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.cancun.vm.__init__. -Axiom ethereum_cancun_vm___init___Evm : - IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Evm". +Axiom ethereum_cancun_vm_imports : + AreImported globals "ethereum.cancun.vm" [ "Evm" ]. -Require ethereum.cancun.vm.gas. -Axiom ethereum_cancun_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_cancun_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "charge_gas". +Axiom ethereum_cancun_vm_gas_imports : + AreImported globals "ethereum.cancun.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.cancun.vm.stack. -Axiom ethereum_cancun_vm_stack_pop : - IsGlobalAlias globals ethereum.cancun.vm.stack.globals "pop". -Axiom ethereum_cancun_vm_stack_push : - IsGlobalAlias globals ethereum.cancun.vm.stack.globals "push". +Axiom ethereum_cancun_vm_stack_imports : + AreImported globals "ethereum.cancun.vm.stack" [ "pop"; "push" ]. Definition less_than : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/control_flow.v b/CoqOfPython/ethereum/cancun/vm/instructions/control_flow.v index b44fd44..159e932 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/control_flow.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.cancun.vm.instructions.control_flow". Definition expr_1 : Value.t := Constant.str " @@ -17,37 +17,20 @@ Introduction Implementations of the EVM control flow instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. -Require ethereum.cancun.vm.gas. -Axiom ethereum_cancun_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_BASE". -Axiom ethereum_cancun_vm_gas_GAS_HIGH : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_HIGH". -Axiom ethereum_cancun_vm_gas_GAS_JUMPDEST : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_JUMPDEST". -Axiom ethereum_cancun_vm_gas_GAS_MID : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_MID". -Axiom ethereum_cancun_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "charge_gas". +Axiom ethereum_cancun_vm_gas_imports : + AreImported globals "ethereum.cancun.vm.gas" [ "GAS_BASE"; "GAS_HIGH"; "GAS_JUMPDEST"; "GAS_MID"; "charge_gas" ]. -Require ethereum.cancun.vm.__init__. -Axiom ethereum_cancun_vm___init___Evm : - IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Evm". +Axiom ethereum_cancun_vm_imports : + AreImported globals "ethereum.cancun.vm" [ "Evm" ]. -Require ethereum.cancun.vm.exceptions. -Axiom ethereum_cancun_vm_exceptions_InvalidJumpDestError : - IsGlobalAlias globals ethereum.cancun.vm.exceptions.globals "InvalidJumpDestError". +Axiom ethereum_cancun_vm_exceptions_imports : + AreImported globals "ethereum.cancun.vm.exceptions" [ "InvalidJumpDestError" ]. -Require ethereum.cancun.vm.stack. -Axiom ethereum_cancun_vm_stack_pop : - IsGlobalAlias globals ethereum.cancun.vm.stack.globals "pop". -Axiom ethereum_cancun_vm_stack_push : - IsGlobalAlias globals ethereum.cancun.vm.stack.globals "push". +Axiom ethereum_cancun_vm_stack_imports : + AreImported globals "ethereum.cancun.vm.stack" [ "pop"; "push" ]. Definition stop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -117,7 +100,7 @@ Definition jump : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "InvalidJumpDestError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -205,7 +188,7 @@ Definition jumpi : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "InvalidJumpDestError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/environment.v b/CoqOfPython/ethereum/cancun/vm/instructions/environment.v index 1403c17..fa5e4eb 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/environment.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.cancun.vm.instructions.environment". Definition expr_1 : Value.t := Constant.str " @@ -17,81 +17,41 @@ Introduction Implementations of the EVM environment related instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". - -Require ethereum.cancun.fork_types. -Axiom ethereum_cancun_fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals ethereum.cancun.fork_types.globals "EMPTY_ACCOUNT". - -Require ethereum.cancun.state. -Axiom ethereum_cancun_state_get_account : - IsGlobalAlias globals ethereum.cancun.state.globals "get_account". - -Require ethereum.cancun.utils.address. -Axiom ethereum_cancun_utils_address_to_address : - IsGlobalAlias globals ethereum.cancun.utils.address.globals "to_address". - -Require ethereum.cancun.vm.memory. -Axiom ethereum_cancun_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.cancun.vm.memory.globals "buffer_read". -Axiom ethereum_cancun_vm_memory_memory_write : - IsGlobalAlias globals ethereum.cancun.vm.memory.globals "memory_write". - -Require ethereum.cancun.vm.__init__. -Axiom ethereum_cancun_vm___init___Evm : - IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Evm". - -Require ethereum.cancun.vm.exceptions. -Axiom ethereum_cancun_vm_exceptions_OutOfBoundsRead : - IsGlobalAlias globals ethereum.cancun.vm.exceptions.globals "OutOfBoundsRead". - -Require ethereum.cancun.vm.gas. -Axiom ethereum_cancun_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_BASE". -Axiom ethereum_cancun_vm_gas_GAS_BLOBHASH_OPCODE : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_BLOBHASH_OPCODE". -Axiom ethereum_cancun_vm_gas_GAS_COLD_ACCOUNT_ACCESS : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_COLD_ACCOUNT_ACCESS". -Axiom ethereum_cancun_vm_gas_GAS_COPY : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_COPY". -Axiom ethereum_cancun_vm_gas_GAS_FAST_STEP : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_FAST_STEP". -Axiom ethereum_cancun_vm_gas_GAS_RETURN_DATA_COPY : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_RETURN_DATA_COPY". -Axiom ethereum_cancun_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_cancun_vm_gas_GAS_WARM_ACCESS : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_WARM_ACCESS". -Axiom ethereum_cancun_vm_gas_calculate_blob_gas_price : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "calculate_blob_gas_price". -Axiom ethereum_cancun_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_cancun_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "charge_gas". - -Require ethereum.cancun.vm.stack. -Axiom ethereum_cancun_vm_stack_pop : - IsGlobalAlias globals ethereum.cancun.vm.stack.globals "pop". -Axiom ethereum_cancun_vm_stack_push : - IsGlobalAlias globals ethereum.cancun.vm.stack.globals "push". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes32"; "Uint" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. + +Axiom ethereum_cancun_fork_types_imports : + AreImported globals "ethereum.cancun.fork_types" [ "EMPTY_ACCOUNT" ]. + +Axiom ethereum_cancun_state_imports : + AreImported globals "ethereum.cancun.state" [ "get_account" ]. + +Axiom ethereum_cancun_utils_address_imports : + AreImported globals "ethereum.cancun.utils.address" [ "to_address" ]. + +Axiom ethereum_cancun_vm_memory_imports : + AreImported globals "ethereum.cancun.vm.memory" [ "buffer_read"; "memory_write" ]. + +Axiom ethereum_cancun_vm_imports : + AreImported globals "ethereum.cancun.vm" [ "Evm" ]. + +Axiom ethereum_cancun_vm_exceptions_imports : + AreImported globals "ethereum.cancun.vm.exceptions" [ "OutOfBoundsRead" ]. + +Axiom ethereum_cancun_vm_gas_imports : + AreImported globals "ethereum.cancun.vm.gas" [ "GAS_BASE"; "GAS_BLOBHASH_OPCODE"; "GAS_COLD_ACCOUNT_ACCESS"; "GAS_COPY"; "GAS_FAST_STEP"; "GAS_RETURN_DATA_COPY"; "GAS_VERY_LOW"; "GAS_WARM_ACCESS"; "calculate_blob_gas_price"; "calculate_gas_extend_memory"; "charge_gas" ]. + +Axiom ethereum_cancun_vm_stack_imports : + AreImported globals "ethereum.cancun.vm.stack" [ "pop"; "push" ]. Definition address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -164,7 +124,7 @@ Definition balance : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -816,7 +776,7 @@ Definition extcodesize : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -972,7 +932,7 @@ Definition extcodecopy : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -1231,10 +1191,15 @@ Definition returndatacopy : Value.t -> Value.t -> M := |) |) in let value := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.slice (| M.get_name (| globals, "return_data_start_position" |), BinOp.add (| + M.slice (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |), - M.get_name (| globals, "size" |) - |) |) |) in + BinOp.add (| + M.get_name (| globals, "return_data_start_position" |), + M.get_name (| globals, "size" |) + |), + Constant.None_ + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -1278,7 +1243,7 @@ Definition extcodehash : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -1503,7 +1468,10 @@ Definition blob_hash : Value.t -> Value.t -> M := (* then *) ltac:(M.monadic ( let blob_hash := - M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "blob_versioned_hashes" |), M.get_name (| globals, "index" |) |) in + M.get_subscript (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "blob_versioned_hashes" |), + M.get_name (| globals, "index" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/keccak.v b/CoqOfPython/ethereum/cancun/vm/instructions/keccak.v index 40fe147..3b8b029 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/keccak.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.cancun.vm.instructions.keccak". Definition expr_1 : Value.t := Constant.str " @@ -17,43 +17,26 @@ Introduction Implementations of the EVM keccak instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". - -Require ethereum.cancun.vm.__init__. -Axiom ethereum_cancun_vm___init___Evm : - IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Evm". - -Require ethereum.cancun.vm.gas. -Axiom ethereum_cancun_vm_gas_GAS_KECCAK256 : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_KECCAK256". -Axiom ethereum_cancun_vm_gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_KECCAK256_WORD". -Axiom ethereum_cancun_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_cancun_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "charge_gas". - -Require ethereum.cancun.vm.memory. -Axiom ethereum_cancun_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.cancun.vm.memory.globals "memory_read_bytes". - -Require ethereum.cancun.vm.stack. -Axiom ethereum_cancun_vm_stack_pop : - IsGlobalAlias globals ethereum.cancun.vm.stack.globals "pop". -Axiom ethereum_cancun_vm_stack_push : - IsGlobalAlias globals ethereum.cancun.vm.stack.globals "push". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. + +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. + +Axiom ethereum_cancun_vm_imports : + AreImported globals "ethereum.cancun.vm" [ "Evm" ]. + +Axiom ethereum_cancun_vm_gas_imports : + AreImported globals "ethereum.cancun.vm.gas" [ "GAS_KECCAK256"; "GAS_KECCAK256_WORD"; "calculate_gas_extend_memory"; "charge_gas" ]. + +Axiom ethereum_cancun_vm_memory_imports : + AreImported globals "ethereum.cancun.vm.memory" [ "memory_read_bytes" ]. + +Axiom ethereum_cancun_vm_stack_imports : + AreImported globals "ethereum.cancun.vm.stack" [ "pop"; "push" ]. Definition keccak : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/log.v b/CoqOfPython/ethereum/cancun/vm/instructions/log.v index d828499..49d60ea 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/log.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/log.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.cancun.vm.instructions.log". Definition expr_1 : Value.t := Constant.str " @@ -17,49 +17,32 @@ Introduction Implementations of the EVM logging instructions. ". -Require functools. -Axiom functools_partial : - IsGlobalAlias globals functools.globals "partial". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.cancun.blocks. -Axiom ethereum_cancun_blocks_Log : - IsGlobalAlias globals ethereum.cancun.blocks.globals "Log". - -Require ethereum.cancun.vm.__init__. -Axiom ethereum_cancun_vm___init___Evm : - IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Evm". - -Require ethereum.cancun.vm.exceptions. -Axiom ethereum_cancun_vm_exceptions_WriteInStaticContext : - IsGlobalAlias globals ethereum.cancun.vm.exceptions.globals "WriteInStaticContext". - -Require ethereum.cancun.vm.gas. -Axiom ethereum_cancun_vm_gas_GAS_LOG : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_LOG". -Axiom ethereum_cancun_vm_gas_GAS_LOG_DATA : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_LOG_DATA". -Axiom ethereum_cancun_vm_gas_GAS_LOG_TOPIC : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_LOG_TOPIC". -Axiom ethereum_cancun_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_cancun_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "charge_gas". - -Require ethereum.cancun.vm.memory. -Axiom ethereum_cancun_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.cancun.vm.memory.globals "memory_read_bytes". - -Require ethereum.cancun.vm.stack. -Axiom ethereum_cancun_vm_stack_pop : - IsGlobalAlias globals ethereum.cancun.vm.stack.globals "pop". +Axiom functools_imports : + AreImported globals "functools" [ "partial" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_cancun_blocks_imports : + AreImported globals "ethereum.cancun.blocks" [ "Log" ]. + +Axiom ethereum_cancun_vm_imports : + AreImported globals "ethereum.cancun.vm" [ "Evm" ]. + +Axiom ethereum_cancun_vm_exceptions_imports : + AreImported globals "ethereum.cancun.vm.exceptions" [ "WriteInStaticContext" ]. + +Axiom ethereum_cancun_vm_gas_imports : + AreImported globals "ethereum.cancun.vm.gas" [ "GAS_LOG"; "GAS_LOG_DATA"; "GAS_LOG_TOPIC"; "calculate_gas_extend_memory"; "charge_gas" ]. + +Axiom ethereum_cancun_vm_memory_imports : + AreImported globals "ethereum.cancun.vm.memory" [ "memory_read_bytes" ]. + +Axiom ethereum_cancun_vm_stack_imports : + AreImported globals "ethereum.cancun.vm.stack" [ "pop" ]. Definition log_n : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -96,33 +79,42 @@ Definition log_n : Value.t -> Value.t -> M := |) in let topics := make_list [] in - For M.get_name (| globals, "_" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - M.get_name (| globals, "num_topics" |) - ], - make_dict [] - |) do - let topic := + let _ := + M.for_ (| + M.get_name (| globals, "_" |), M.call (| - M.get_field (| M.call (| - M.get_name (| globals, "pop" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] - |), "to_be_bytes32" |), - make_list [], - make_dict [] - |) in - let _ := M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "num_topics" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let topic := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| M.get_field (| M.get_name (| globals, "topics" |), "append" |), make_list [ M.get_name (| globals, "topic" |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let extend_memory := M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/memory.v b/CoqOfPython/ethereum/cancun/vm/instructions/memory.v index d6b1b92..d64ad64 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/memory.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.cancun.vm.instructions.memory". Definition expr_1 : Value.t := Constant.str " @@ -17,45 +17,23 @@ Introduction Implementations of the EVM Memory instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.cancun.vm.__init__. -Axiom ethereum_cancun_vm___init___Evm : - IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Evm". +Axiom ethereum_cancun_vm_imports : + AreImported globals "ethereum.cancun.vm" [ "Evm" ]. -Require ethereum.cancun.vm.gas. -Axiom ethereum_cancun_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_BASE". -Axiom ethereum_cancun_vm_gas_GAS_COPY : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_COPY". -Axiom ethereum_cancun_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_cancun_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_cancun_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "charge_gas". +Axiom ethereum_cancun_vm_gas_imports : + AreImported globals "ethereum.cancun.vm.gas" [ "GAS_BASE"; "GAS_COPY"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. -Require ethereum.cancun.vm.memory. -Axiom ethereum_cancun_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.cancun.vm.memory.globals "memory_read_bytes". -Axiom ethereum_cancun_vm_memory_memory_write : - IsGlobalAlias globals ethereum.cancun.vm.memory.globals "memory_write". +Axiom ethereum_cancun_vm_memory_imports : + AreImported globals "ethereum.cancun.vm.memory" [ "memory_read_bytes"; "memory_write" ]. -Require ethereum.cancun.vm.stack. -Axiom ethereum_cancun_vm_stack_pop : - IsGlobalAlias globals ethereum.cancun.vm.stack.globals "pop". -Axiom ethereum_cancun_vm_stack_push : - IsGlobalAlias globals ethereum.cancun.vm.stack.globals "push". +Axiom ethereum_cancun_vm_stack_imports : + AreImported globals "ethereum.cancun.vm.stack" [ "pop"; "push" ]. Definition mstore : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/stack.v b/CoqOfPython/ethereum/cancun/vm/instructions/stack.v index a46eb79..7b65ede 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/stack.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.cancun.vm.instructions.stack". Definition expr_1 : Value.t := Constant.str " @@ -17,39 +17,26 @@ Introduction Implementations of the EVM stack related instructions. ". -Require functools. -Axiom functools_partial : - IsGlobalAlias globals functools.globals "partial". +Axiom functools_imports : + AreImported globals "functools" [ "partial" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.cancun.vm.__init__. -Axiom ethereum_cancun_vm___init___Evm : - IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Evm". -Axiom ethereum_cancun_vm___init___stack : - IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "stack". +Axiom ethereum_cancun_vm_imports : + AreImported globals "ethereum.cancun.vm" [ "Evm"; "stack" ]. -Require ethereum.cancun.vm.exceptions. -Axiom ethereum_cancun_vm_exceptions_StackUnderflowError : - IsGlobalAlias globals ethereum.cancun.vm.exceptions.globals "StackUnderflowError". +Axiom ethereum_cancun_vm_exceptions_imports : + AreImported globals "ethereum.cancun.vm.exceptions" [ "StackUnderflowError" ]. -Require ethereum.cancun.vm.gas. -Axiom ethereum_cancun_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_BASE". -Axiom ethereum_cancun_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_cancun_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "charge_gas". +Axiom ethereum_cancun_vm_gas_imports : + AreImported globals "ethereum.cancun.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.cancun.vm.memory. -Axiom ethereum_cancun_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.cancun.vm.memory.globals "buffer_read". +Axiom ethereum_cancun_vm_memory_imports : + AreImported globals "ethereum.cancun.vm.memory" [ "buffer_read" ]. Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -225,19 +212,22 @@ Definition dup_n : Value.t -> Value.t -> M := make_dict [] |) in let data_to_duplicate := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] + BinOp.sub (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), + Constant.int 1 |), - Constant.int 1 - |), - M.get_name (| globals, "item_number" |) - |) |) in + M.get_name (| globals, "item_number" |) + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "stack" |), "push" |), make_list [ @@ -300,14 +290,26 @@ Definition swap_n : Value.t -> Value.t -> M := make_dict [] |) in let _ := M.assign (| - make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| - UnOp.sub (| Constant.int 1 |), - M.get_name (| globals, "item_number" |) - |) |) ], - make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| - UnOp.sub (| Constant.int 1 |), - M.get_name (| globals, "item_number" |) - |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |) ] + make_tuple [ M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + UnOp.sub (| Constant.int 1 |) + |); M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) + |) ], + make_tuple [ M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) + |); M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + UnOp.sub (| Constant.int 1 |) + |) ] |) in let _ := M.assign_op (| BinOp.add, diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/storage.v b/CoqOfPython/ethereum/cancun/vm/instructions/storage.v index 83ebab0..d27683d 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/storage.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.cancun.vm.instructions.storage". Definition expr_1 : Value.t := Constant.str " @@ -17,57 +17,26 @@ Introduction Implementations of the EVM storage related instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.cancun.state. -Axiom ethereum_cancun_state_get_storage : - IsGlobalAlias globals ethereum.cancun.state.globals "get_storage". -Axiom ethereum_cancun_state_get_storage_original : - IsGlobalAlias globals ethereum.cancun.state.globals "get_storage_original". -Axiom ethereum_cancun_state_get_transient_storage : - IsGlobalAlias globals ethereum.cancun.state.globals "get_transient_storage". -Axiom ethereum_cancun_state_set_storage : - IsGlobalAlias globals ethereum.cancun.state.globals "set_storage". -Axiom ethereum_cancun_state_set_transient_storage : - IsGlobalAlias globals ethereum.cancun.state.globals "set_transient_storage". +Axiom ethereum_cancun_state_imports : + AreImported globals "ethereum.cancun.state" [ "get_storage"; "get_storage_original"; "get_transient_storage"; "set_storage"; "set_transient_storage" ]. -Require ethereum.cancun.vm.__init__. -Axiom ethereum_cancun_vm___init___Evm : - IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Evm". +Axiom ethereum_cancun_vm_imports : + AreImported globals "ethereum.cancun.vm" [ "Evm" ]. -Require ethereum.cancun.vm.exceptions. -Axiom ethereum_cancun_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.cancun.vm.exceptions.globals "OutOfGasError". -Axiom ethereum_cancun_vm_exceptions_WriteInStaticContext : - IsGlobalAlias globals ethereum.cancun.vm.exceptions.globals "WriteInStaticContext". +Axiom ethereum_cancun_vm_exceptions_imports : + AreImported globals "ethereum.cancun.vm.exceptions" [ "OutOfGasError"; "WriteInStaticContext" ]. -Require ethereum.cancun.vm.gas. -Axiom ethereum_cancun_vm_gas_GAS_CALL_STIPEND : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_CALL_STIPEND". -Axiom ethereum_cancun_vm_gas_GAS_COLD_SLOAD : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_COLD_SLOAD". -Axiom ethereum_cancun_vm_gas_GAS_STORAGE_CLEAR_REFUND : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_STORAGE_CLEAR_REFUND". -Axiom ethereum_cancun_vm_gas_GAS_STORAGE_SET : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_STORAGE_SET". -Axiom ethereum_cancun_vm_gas_GAS_STORAGE_UPDATE : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_STORAGE_UPDATE". -Axiom ethereum_cancun_vm_gas_GAS_WARM_ACCESS : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_WARM_ACCESS". -Axiom ethereum_cancun_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "charge_gas". +Axiom ethereum_cancun_vm_gas_imports : + AreImported globals "ethereum.cancun.vm.gas" [ "GAS_CALL_STIPEND"; "GAS_COLD_SLOAD"; "GAS_STORAGE_CLEAR_REFUND"; "GAS_STORAGE_SET"; "GAS_STORAGE_UPDATE"; "GAS_WARM_ACCESS"; "charge_gas" ]. -Require ethereum.cancun.vm.stack. -Axiom ethereum_cancun_vm_stack_pop : - IsGlobalAlias globals ethereum.cancun.vm.stack.globals "pop". -Axiom ethereum_cancun_vm_stack_push : - IsGlobalAlias globals ethereum.cancun.vm.stack.globals "push". +Axiom ethereum_cancun_vm_stack_imports : + AreImported globals "ethereum.cancun.vm.stack" [ "pop"; "push" ]. Definition sload : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -97,7 +66,7 @@ Definition sload : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) |), diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/system.v b/CoqOfPython/ethereum/cancun/vm/instructions/system.v index 936f03b..6383f61 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/system.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/system.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.cancun.vm.instructions.system". Definition expr_1 : Value.t := Constant.str " @@ -17,109 +17,38 @@ Introduction Implementations of the EVM system related instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.cancun.fork_types. -Axiom ethereum_cancun_fork_types_Address : - IsGlobalAlias globals ethereum.cancun.fork_types.globals "Address". +Axiom ethereum_cancun_fork_types_imports : + AreImported globals "ethereum.cancun.fork_types" [ "Address" ]. -Require ethereum.cancun.state. -Axiom ethereum_cancun_state_account_exists_and_is_empty : - IsGlobalAlias globals ethereum.cancun.state.globals "account_exists_and_is_empty". -Axiom ethereum_cancun_state_account_has_code_or_nonce : - IsGlobalAlias globals ethereum.cancun.state.globals "account_has_code_or_nonce". -Axiom ethereum_cancun_state_get_account : - IsGlobalAlias globals ethereum.cancun.state.globals "get_account". -Axiom ethereum_cancun_state_increment_nonce : - IsGlobalAlias globals ethereum.cancun.state.globals "increment_nonce". -Axiom ethereum_cancun_state_is_account_alive : - IsGlobalAlias globals ethereum.cancun.state.globals "is_account_alive". -Axiom ethereum_cancun_state_move_ether : - IsGlobalAlias globals ethereum.cancun.state.globals "move_ether". -Axiom ethereum_cancun_state_set_account_balance : - IsGlobalAlias globals ethereum.cancun.state.globals "set_account_balance". +Axiom ethereum_cancun_state_imports : + AreImported globals "ethereum.cancun.state" [ "account_exists_and_is_empty"; "account_has_code_or_nonce"; "get_account"; "increment_nonce"; "is_account_alive"; "move_ether"; "set_account_balance" ]. -Require ethereum.cancun.utils.address. -Axiom ethereum_cancun_utils_address_compute_contract_address : - IsGlobalAlias globals ethereum.cancun.utils.address.globals "compute_contract_address". -Axiom ethereum_cancun_utils_address_compute_create2_contract_address : - IsGlobalAlias globals ethereum.cancun.utils.address.globals "compute_create2_contract_address". -Axiom ethereum_cancun_utils_address_to_address : - IsGlobalAlias globals ethereum.cancun.utils.address.globals "to_address". +Axiom ethereum_cancun_utils_address_imports : + AreImported globals "ethereum.cancun.utils.address" [ "compute_contract_address"; "compute_create2_contract_address"; "to_address" ]. -Require ethereum.cancun.vm.__init__. -Axiom ethereum_cancun_vm___init___Evm : - IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Evm". -Axiom ethereum_cancun_vm___init___Message : - IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Message". -Axiom ethereum_cancun_vm___init___incorporate_child_on_error : - IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "incorporate_child_on_error". -Axiom ethereum_cancun_vm___init___incorporate_child_on_success : - IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "incorporate_child_on_success". +Axiom ethereum_cancun_vm_imports : + AreImported globals "ethereum.cancun.vm" [ "Evm"; "Message"; "incorporate_child_on_error"; "incorporate_child_on_success" ]. -Require ethereum.cancun.vm.exceptions. -Axiom ethereum_cancun_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.cancun.vm.exceptions.globals "OutOfGasError". -Axiom ethereum_cancun_vm_exceptions_Revert : - IsGlobalAlias globals ethereum.cancun.vm.exceptions.globals "Revert". -Axiom ethereum_cancun_vm_exceptions_WriteInStaticContext : - IsGlobalAlias globals ethereum.cancun.vm.exceptions.globals "WriteInStaticContext". +Axiom ethereum_cancun_vm_exceptions_imports : + AreImported globals "ethereum.cancun.vm.exceptions" [ "OutOfGasError"; "Revert"; "WriteInStaticContext" ]. -Require ethereum.cancun.vm.gas. -Axiom ethereum_cancun_vm_gas_GAS_CALL_VALUE : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_CALL_VALUE". -Axiom ethereum_cancun_vm_gas_GAS_COLD_ACCOUNT_ACCESS : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_COLD_ACCOUNT_ACCESS". -Axiom ethereum_cancun_vm_gas_GAS_CREATE : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_CREATE". -Axiom ethereum_cancun_vm_gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_KECCAK256_WORD". -Axiom ethereum_cancun_vm_gas_GAS_NEW_ACCOUNT : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_NEW_ACCOUNT". -Axiom ethereum_cancun_vm_gas_GAS_SELF_DESTRUCT : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_SELF_DESTRUCT". -Axiom ethereum_cancun_vm_gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". -Axiom ethereum_cancun_vm_gas_GAS_WARM_ACCESS : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_WARM_ACCESS". -Axiom ethereum_cancun_vm_gas_GAS_ZERO : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_ZERO". -Axiom ethereum_cancun_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_cancun_vm_gas_calculate_message_call_gas : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "calculate_message_call_gas". -Axiom ethereum_cancun_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "charge_gas". -Axiom ethereum_cancun_vm_gas_init_code_cost : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "init_code_cost". -Axiom ethereum_cancun_vm_gas_max_message_call_gas : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "max_message_call_gas". +Axiom ethereum_cancun_vm_gas_imports : + AreImported globals "ethereum.cancun.vm.gas" [ "GAS_CALL_VALUE"; "GAS_COLD_ACCOUNT_ACCESS"; "GAS_CREATE"; "GAS_KECCAK256_WORD"; "GAS_NEW_ACCOUNT"; "GAS_SELF_DESTRUCT"; "GAS_SELF_DESTRUCT_NEW_ACCOUNT"; "GAS_WARM_ACCESS"; "GAS_ZERO"; "calculate_gas_extend_memory"; "calculate_message_call_gas"; "charge_gas"; "init_code_cost"; "max_message_call_gas" ]. -Require ethereum.cancun.vm.memory. -Axiom ethereum_cancun_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.cancun.vm.memory.globals "memory_read_bytes". -Axiom ethereum_cancun_vm_memory_memory_write : - IsGlobalAlias globals ethereum.cancun.vm.memory.globals "memory_write". +Axiom ethereum_cancun_vm_memory_imports : + AreImported globals "ethereum.cancun.vm.memory" [ "memory_read_bytes"; "memory_write" ]. -Require ethereum.cancun.vm.stack. -Axiom ethereum_cancun_vm_stack_pop : - IsGlobalAlias globals ethereum.cancun.vm.stack.globals "pop". -Axiom ethereum_cancun_vm_stack_push : - IsGlobalAlias globals ethereum.cancun.vm.stack.globals "push". +Axiom ethereum_cancun_vm_stack_imports : + AreImported globals "ethereum.cancun.vm.stack" [ "pop"; "push" ]. Definition generic_create : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -928,7 +857,12 @@ Definition generic_call : Value.t -> Value.t -> M := make_list [ M.get_field (| M.get_name (| globals, "evm" |), "memory" |); M.get_name (| globals, "memory_output_start_position" |); - M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), M.slice (| Constant.None_, M.get_name (| globals, "actual_output_size" |) |) |) + M.slice (| + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), + Constant.None_, + M.get_name (| globals, "actual_output_size" |), + Constant.None_ + |) ], make_dict [] |) in @@ -1028,7 +962,7 @@ Definition call : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "to" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -1334,7 +1268,7 @@ Definition callcode : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "code_address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -1614,7 +1548,7 @@ Definition selfdestruct : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "originator" |), M.get_field (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "state" |), "created_accounts" |) |), @@ -1765,7 +1699,7 @@ Definition delegatecall : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "code_address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -1941,7 +1875,7 @@ Definition staticcall : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "to" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -2111,6 +2045,6 @@ Definition revert : Value.t -> Value.t -> M := make_dict [] |) |) in - let _ := M.raise (| Some(M.get_name (| globals, "Revert" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "Revert" |)) |) in let _ := M.pass (| |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/cancun/vm/interpreter.v b/CoqOfPython/ethereum/cancun/vm/interpreter.v index 8ed4da9..13b4d41 100644 --- a/CoqOfPython/ethereum/cancun/vm/interpreter.v +++ b/CoqOfPython/ethereum/cancun/vm/interpreter.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.cancun.vm.interpreter". Definition expr_1 : Value.t := Constant.str " @@ -17,129 +17,50 @@ Introduction A straightforward interpreter that executes EVM code. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_Iterable : - IsGlobalAlias globals typing.globals "Iterable". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.trace. -Axiom ethereum_trace_EvmStop : - IsGlobalAlias globals ethereum.trace.globals "EvmStop". -Axiom ethereum_trace_OpEnd : - IsGlobalAlias globals ethereum.trace.globals "OpEnd". -Axiom ethereum_trace_OpException : - IsGlobalAlias globals ethereum.trace.globals "OpException". -Axiom ethereum_trace_OpStart : - IsGlobalAlias globals ethereum.trace.globals "OpStart". -Axiom ethereum_trace_PrecompileEnd : - IsGlobalAlias globals ethereum.trace.globals "PrecompileEnd". -Axiom ethereum_trace_PrecompileStart : - IsGlobalAlias globals ethereum.trace.globals "PrecompileStart". -Axiom ethereum_trace_TransactionEnd : - IsGlobalAlias globals ethereum.trace.globals "TransactionEnd". -Axiom ethereum_trace_evm_trace : - IsGlobalAlias globals ethereum.trace.globals "evm_trace". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.cancun.blocks. -Axiom ethereum_cancun_blocks_Log : - IsGlobalAlias globals ethereum.cancun.blocks.globals "Log". - -Require ethereum.cancun.fork_types. -Axiom ethereum_cancun_fork_types_Address : - IsGlobalAlias globals ethereum.cancun.fork_types.globals "Address". - -Require ethereum.cancun.state. -Axiom ethereum_cancun_state_account_exists_and_is_empty : - IsGlobalAlias globals ethereum.cancun.state.globals "account_exists_and_is_empty". -Axiom ethereum_cancun_state_account_has_code_or_nonce : - IsGlobalAlias globals ethereum.cancun.state.globals "account_has_code_or_nonce". -Axiom ethereum_cancun_state_begin_transaction : - IsGlobalAlias globals ethereum.cancun.state.globals "begin_transaction". -Axiom ethereum_cancun_state_commit_transaction : - IsGlobalAlias globals ethereum.cancun.state.globals "commit_transaction". -Axiom ethereum_cancun_state_destroy_storage : - IsGlobalAlias globals ethereum.cancun.state.globals "destroy_storage". -Axiom ethereum_cancun_state_increment_nonce : - IsGlobalAlias globals ethereum.cancun.state.globals "increment_nonce". -Axiom ethereum_cancun_state_mark_account_created : - IsGlobalAlias globals ethereum.cancun.state.globals "mark_account_created". -Axiom ethereum_cancun_state_move_ether : - IsGlobalAlias globals ethereum.cancun.state.globals "move_ether". -Axiom ethereum_cancun_state_rollback_transaction : - IsGlobalAlias globals ethereum.cancun.state.globals "rollback_transaction". -Axiom ethereum_cancun_state_set_code : - IsGlobalAlias globals ethereum.cancun.state.globals "set_code". -Axiom ethereum_cancun_state_touch_account : - IsGlobalAlias globals ethereum.cancun.state.globals "touch_account". - -Require ethereum.cancun.vm.__init__. -Axiom ethereum_cancun_vm___init___Message : - IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Message". - -Require ethereum.cancun.vm.gas. -Axiom ethereum_cancun_vm_gas_GAS_CODE_DEPOSIT : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_CODE_DEPOSIT". -Axiom ethereum_cancun_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "charge_gas". - -Require ethereum.cancun.vm.precompiled_contracts.mapping. -Axiom ethereum_cancun_vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : - IsGlobalAlias globals ethereum.cancun.vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". - -Require ethereum.cancun.vm.__init__. -Axiom ethereum_cancun_vm___init___Environment : - IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Environment". -Axiom ethereum_cancun_vm___init___Evm : - IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Evm". - -Require ethereum.cancun.vm.exceptions. -Axiom ethereum_cancun_vm_exceptions_AddressCollision : - IsGlobalAlias globals ethereum.cancun.vm.exceptions.globals "AddressCollision". -Axiom ethereum_cancun_vm_exceptions_ExceptionalHalt : - IsGlobalAlias globals ethereum.cancun.vm.exceptions.globals "ExceptionalHalt". -Axiom ethereum_cancun_vm_exceptions_InvalidContractPrefix : - IsGlobalAlias globals ethereum.cancun.vm.exceptions.globals "InvalidContractPrefix". -Axiom ethereum_cancun_vm_exceptions_InvalidOpcode : - IsGlobalAlias globals ethereum.cancun.vm.exceptions.globals "InvalidOpcode". -Axiom ethereum_cancun_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.cancun.vm.exceptions.globals "OutOfGasError". -Axiom ethereum_cancun_vm_exceptions_Revert : - IsGlobalAlias globals ethereum.cancun.vm.exceptions.globals "Revert". -Axiom ethereum_cancun_vm_exceptions_StackDepthLimitError : - IsGlobalAlias globals ethereum.cancun.vm.exceptions.globals "StackDepthLimitError". - -Require ethereum.cancun.vm.instructions.__init__. -Axiom ethereum_cancun_vm_instructions___init___Ops : - IsGlobalAlias globals ethereum.cancun.vm.instructions.__init__.globals "Ops". -Axiom ethereum_cancun_vm_instructions___init___op_implementation : - IsGlobalAlias globals ethereum.cancun.vm.instructions.__init__.globals "op_implementation". - -Require ethereum.cancun.vm.runtime. -Axiom ethereum_cancun_vm_runtime_get_valid_jump_destinations : - IsGlobalAlias globals ethereum.cancun.vm.runtime.globals "get_valid_jump_destinations". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Iterable"; "Optional"; "Set"; "Tuple"; "Union" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. + +Axiom ethereum_trace_imports : + AreImported globals "ethereum.trace" [ "EvmStop"; "OpEnd"; "OpException"; "OpStart"; "PrecompileEnd"; "PrecompileStart"; "TransactionEnd"; "evm_trace" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_cancun_blocks_imports : + AreImported globals "ethereum.cancun.blocks" [ "Log" ]. + +Axiom ethereum_cancun_fork_types_imports : + AreImported globals "ethereum.cancun.fork_types" [ "Address" ]. + +Axiom ethereum_cancun_state_imports : + AreImported globals "ethereum.cancun.state" [ "account_exists_and_is_empty"; "account_has_code_or_nonce"; "begin_transaction"; "commit_transaction"; "destroy_storage"; "increment_nonce"; "mark_account_created"; "move_ether"; "rollback_transaction"; "set_code"; "touch_account" ]. + +Axiom ethereum_cancun_vm_imports : + AreImported globals "ethereum.cancun.vm" [ "Message" ]. + +Axiom ethereum_cancun_vm_gas_imports : + AreImported globals "ethereum.cancun.vm.gas" [ "GAS_CODE_DEPOSIT"; "charge_gas" ]. + +Axiom ethereum_cancun_vm_precompiled_contracts_mapping_imports : + AreImported globals "ethereum.cancun.vm.precompiled_contracts.mapping" [ "PRE_COMPILED_CONTRACTS" ]. + +Axiom ethereum_cancun_vm_imports : + AreImported globals "ethereum.cancun.vm" [ "Environment"; "Evm" ]. + +Axiom ethereum_cancun_vm_exceptions_imports : + AreImported globals "ethereum.cancun.vm.exceptions" [ "AddressCollision"; "ExceptionalHalt"; "InvalidContractPrefix"; "InvalidOpcode"; "OutOfGasError"; "Revert"; "StackDepthLimitError" ]. + +Axiom ethereum_cancun_vm_instructions_imports : + AreImported globals "ethereum.cancun.vm.instructions" [ "Ops"; "op_implementation" ]. + +Axiom ethereum_cancun_vm_runtime_imports : + AreImported globals "ethereum.cancun.vm.runtime" [ "get_valid_jump_destinations" ]. Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -522,7 +443,7 @@ Definition process_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "StackDepthLimitError" |), make_list [ Constant.str "Stack depth limit reached" diff --git a/CoqOfPython/ethereum/cancun/vm/memory.v b/CoqOfPython/ethereum/cancun/vm/memory.v index 08d2290..9b428c0 100644 --- a/CoqOfPython/ethereum/cancun/vm/memory.v +++ b/CoqOfPython/ethereum/cancun/vm/memory.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.cancun.vm.memory". Definition expr_1 : Value.t := Constant.str " @@ -17,17 +17,11 @@ Introduction EVM memory operations. ". -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_right_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "right_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "right_pad_zero_bytes" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. Definition memory_write : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,22 +39,27 @@ Definition memory_write : Value.t -> Value.t -> M := Data to write to memory. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + M.slice (| + M.get_name (| globals, "memory" |), + M.get_name (| globals, "start_position" |), + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) - |) |) |), + Constant.None_ + |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_)). @@ -86,22 +85,27 @@ Definition memory_read_bytes : Value.t -> Value.t -> M := Data read from memory. " in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + M.slice (| + M.get_name (| globals, "memory" |), + M.get_name (| globals, "start_position" |), + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |) |) + Constant.None_ + |) |) in M.pure Constant.None_)). @@ -129,22 +133,27 @@ Definition buffer_read : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "right_pad_zero_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "buffer" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + M.slice (| + M.get_name (| globals, "buffer" |), + M.get_name (| globals, "start_position" |), + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |) |); + Constant.None_ + |); M.get_name (| globals, "size" |) ], make_dict [] diff --git a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/__init__.v index 93f0111..b52e0bf 100644 --- a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/__init__.v +++ b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.cancun.vm.precompiled_contracts.__init__". Definition expr_1 : Value.t := Constant.str " @@ -18,9 +18,8 @@ Addresses of precompiled contracts and mappings to their implementations. ". -Require ethereum.cancun.utils.hexadecimal. -Axiom ethereum_cancun_utils_hexadecimal_hex_to_address : - IsGlobalAlias globals ethereum.cancun.utils.hexadecimal.globals "hex_to_address". +Axiom ethereum_cancun_utils_hexadecimal_imports : + AreImported globals "ethereum.cancun.utils.hexadecimal" [ "hex_to_address" ]. Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS"; Constant.str "MODEXP_ADDRESS"; Constant.str "ALT_BN128_ADD_ADDRESS"; Constant.str "ALT_BN128_MUL_ADDRESS"; Constant.str "ALT_BN128_PAIRING_CHECK_ADDRESS"; Constant.str "BLAKE2F_ADDRESS"; Constant.str "POINT_EVALUATION_ADDRESS" ] diff --git a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/alt_bn128.v index b461c47..206b422 100644 --- a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/alt_bn128.v +++ b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/alt_bn128.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.cancun.vm.precompiled_contracts.alt_bn128". Definition expr_1 : Value.t := Constant.str " @@ -17,49 +17,26 @@ Introduction Implementation of the ALT_BN128 precompiled contracts. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. -Require ethereum.crypto.alt_bn128. -Axiom ethereum_crypto_alt_bn128_ALT_BN128_CURVE_ORDER : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "ALT_BN128_CURVE_ORDER". -Axiom ethereum_crypto_alt_bn128_ALT_BN128_PRIME : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "ALT_BN128_PRIME". -Axiom ethereum_crypto_alt_bn128_BNF : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF". -Axiom ethereum_crypto_alt_bn128_BNF2 : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF2". -Axiom ethereum_crypto_alt_bn128_BNF12 : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF12". -Axiom ethereum_crypto_alt_bn128_BNP : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNP". -Axiom ethereum_crypto_alt_bn128_BNP2 : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNP2". -Axiom ethereum_crypto_alt_bn128_pairing : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "pairing". +Axiom ethereum_crypto_alt_bn128_imports : + AreImported globals "ethereum.crypto.alt_bn128" [ "ALT_BN128_CURVE_ORDER"; "ALT_BN128_PRIME"; "BNF"; "BNF2"; "BNF12"; "BNP"; "BNP2"; "pairing" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.cancun.vm.__init__. -Axiom ethereum_cancun_vm___init___Evm : - IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Evm". +Axiom ethereum_cancun_vm_imports : + AreImported globals "ethereum.cancun.vm" [ "Evm" ]. -Require ethereum.cancun.vm.gas. -Axiom ethereum_cancun_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "charge_gas". +Axiom ethereum_cancun_vm_gas_imports : + AreImported globals "ethereum.cancun.vm.gas" [ "charge_gas" ]. -Require ethereum.cancun.vm.memory. -Axiom ethereum_cancun_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.cancun.vm.memory.globals "buffer_read". +Axiom ethereum_cancun_vm_memory_imports : + AreImported globals "ethereum.cancun.vm.memory" [ "buffer_read" ]. -Require ethereum.cancun.vm.exceptions. -Axiom ethereum_cancun_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.cancun.vm.exceptions.globals "OutOfGasError". +Axiom ethereum_cancun_vm_exceptions_imports : + AreImported globals "ethereum.cancun.vm.exceptions" [ "OutOfGasError" ]. Definition alt_bn128_add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -208,23 +185,32 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ] do - let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| - M.get_name (| globals, "i" |), - M.get_name (| globals, "ALT_BN128_PRIME" |) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ], ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in (* At stmt: unsupported node type: Try *) let p := BinOp.add (| @@ -363,23 +349,32 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ] do - let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| - M.get_name (| globals, "i" |), - M.get_name (| globals, "ALT_BN128_PRIME" |) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ], ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in (* At stmt: unsupported node type: Try *) let p := M.call (| @@ -466,7 +461,7 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -480,76 +475,89 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - BinOp.floor_div (| + let _ := + M.for_ (| + M.get_name (| globals, "i" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "data" |) - ], - make_dict [] - |), - Constant.int 192 - |) - ], - make_dict [] - |) do - let values := - make_list [] in - For M.get_name (| globals, "j" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 6 - ], - make_dict [] - |) do - let value := + M.get_name (| globals, "range" |), + make_list [ + BinOp.floor_div (| M.call (| - M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + M.get_name (| globals, "len" |), make_list [ - M.get_subscript (| M.get_name (| globals, "data" |), M.slice (| BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "i" |), - Constant.int 192 - |), - BinOp.mult (| - Constant.int 32, - M.get_name (| globals, "j" |) - |) - |), BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "i" |), - Constant.int 192 - |), - BinOp.mult (| - Constant.int 32, - BinOp.add (| - M.get_name (| globals, "j" |), - Constant.int 1 - |) - |) - |) |) |) + M.get_name (| globals, "data" |) ], make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| - M.get_name (| globals, "value" |), - M.get_name (| globals, "ALT_BN128_PRIME" |) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let _ := M.call (| + |), + Constant.int 192 + |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let values := + make_list [] in + let _ := + M.for_ (| + M.get_name (| globals, "j" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 6 + ], + make_dict [] + |), + ltac:(M.monadic ( + let value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.slice (| + M.get_name (| globals, "data" |), + BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + M.get_name (| globals, "j" |) + |) + |), + BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "j" |), + Constant.int 1 + |) + |) + |), + Constant.None_ + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| M.get_field (| M.get_name (| globals, "values" |), "append" |), make_list [ M.call (| @@ -562,9 +570,14 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in (* At stmt: unsupported node type: Try *) - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.eq (| @@ -585,7 +598,7 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.eq (| @@ -606,49 +619,54 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| - M.get_name (| globals, "p" |), - M.call (| - M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) - |), + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "p" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "q" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |) + )) + |), + (* then *) ltac:(M.monadic ( - Compare.not_eq (| - M.get_name (| globals, "q" |), - M.call (| - M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) - |) - )) - |), - (* then *) - ltac:(M.monadic ( - let result := - BinOp.mult (| - M.get_name (| globals, "result" |), - M.call (| - M.get_name (| globals, "pairing" |), - make_list [ - M.get_name (| globals, "q" |); - M.get_name (| globals, "p" |) - ], - make_dict [] - |) - |) in + let result := + BinOp.mult (| + M.get_name (| globals, "result" |), + M.call (| + M.get_name (| globals, "pairing" |), + make_list [ + M.get_name (| globals, "q" |); + M.get_name (| globals, "p" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := (* if *) M.if_then_else (| diff --git a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/blake2f.v b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/blake2f.v index 2d21cae..5eb8fb4 100644 --- a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/blake2f.v +++ b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/blake2f.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.cancun.vm.precompiled_contracts.blake2f". Definition expr_1 : Value.t := Constant.str " @@ -17,27 +17,20 @@ Introduction Implementation of the `Blake2` precompiled contract. ". -Require ethereum.crypto.blake2. -Axiom ethereum_crypto_blake2_Blake2b : - IsGlobalAlias globals ethereum.crypto.blake2.globals "Blake2b". +Axiom ethereum_crypto_blake2_imports : + AreImported globals "ethereum.crypto.blake2" [ "Blake2b" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.cancun.vm.__init__. -Axiom ethereum_cancun_vm___init___Evm : - IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Evm". +Axiom ethereum_cancun_vm_imports : + AreImported globals "ethereum.cancun.vm" [ "Evm" ]. -Require ethereum.cancun.vm.gas. -Axiom ethereum_cancun_vm_gas_GAS_BLAKE2_PER_ROUND : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_BLAKE2_PER_ROUND". -Axiom ethereum_cancun_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "charge_gas". +Axiom ethereum_cancun_vm_gas_imports : + AreImported globals "ethereum.cancun.vm.gas" [ "GAS_BLAKE2_PER_ROUND"; "charge_gas" ]. -Require ethereum.cancun.vm.exceptions. -Axiom ethereum_cancun_vm_exceptions_InvalidParameter : - IsGlobalAlias globals ethereum.cancun.vm.exceptions.globals "InvalidParameter". +Axiom ethereum_cancun_vm_exceptions_imports : + AreImported globals "ethereum.cancun.vm.exceptions" [ "InvalidParameter" ]. Definition blake2f : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -99,7 +92,7 @@ Definition blake2f : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.in (| + Compare.in_ (| M.get_name (| globals, "f" |), make_list [ Constant.int 0; diff --git a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/ecrecover.v index 1fc12ba..9e2966e 100644 --- a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/ecrecover.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.cancun.vm.precompiled_contracts.ecrecover". Definition expr_1 : Value.t := Constant.str " @@ -17,39 +17,26 @@ Introduction Implementation of the ECRECOVER precompiled contract. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.crypto.elliptic_curve. -Axiom ethereum_crypto_elliptic_curve_SECP256K1N : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". -Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". +Axiom ethereum_crypto_elliptic_curve_imports : + AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_left_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. -Require ethereum.cancun.vm.__init__. -Axiom ethereum_cancun_vm___init___Evm : - IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Evm". +Axiom ethereum_cancun_vm_imports : + AreImported globals "ethereum.cancun.vm" [ "Evm" ]. -Require ethereum.cancun.vm.gas. -Axiom ethereum_cancun_vm_gas_GAS_ECRECOVER : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_ECRECOVER". -Axiom ethereum_cancun_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "charge_gas". +Axiom ethereum_cancun_vm_gas_imports : + AreImported globals "ethereum.cancun.vm.gas" [ "GAS_ECRECOVER"; "charge_gas" ]. -Require ethereum.cancun.vm.memory. -Axiom ethereum_cancun_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.cancun.vm.memory.globals "buffer_read". +Axiom ethereum_cancun_vm_memory_imports : + AreImported globals "ethereum.cancun.vm.memory" [ "buffer_read" ]. Definition ecrecover : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -264,13 +251,18 @@ Definition ecrecover : Value.t -> Value.t -> M := )) |) in (* At stmt: unsupported node type: Try *) let address := - M.get_subscript (| M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "public_key" |) - ], - make_dict [] - |), M.slice (| Constant.int 12, Constant.int 32 |) |) in + M.slice (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), + Constant.int 12, + Constant.int 32, + Constant.None_ + |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/identity.v index ce9b2e7..9b7df58 100644 --- a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/identity.v +++ b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/identity.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.cancun.vm.precompiled_contracts.identity". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementation of the `IDENTITY` precompiled contract. ". -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.cancun.vm.__init__. -Axiom ethereum_cancun_vm___init___Evm : - IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Evm". +Axiom ethereum_cancun_vm_imports : + AreImported globals "ethereum.cancun.vm" [ "Evm" ]. -Require ethereum.cancun.vm.gas. -Axiom ethereum_cancun_vm_gas_GAS_IDENTITY : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_IDENTITY". -Axiom ethereum_cancun_vm_gas_GAS_IDENTITY_WORD : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_IDENTITY_WORD". -Axiom ethereum_cancun_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "charge_gas". +Axiom ethereum_cancun_vm_gas_imports : + AreImported globals "ethereum.cancun.vm.gas" [ "GAS_IDENTITY"; "GAS_IDENTITY_WORD"; "charge_gas" ]. Definition identity : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/mapping.v index 52973e3..0bf721f 100644 --- a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/mapping.v +++ b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/mapping.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.cancun.vm.precompiled_contracts.mapping". Definition expr_1 : Value.t := Constant.str " @@ -17,72 +17,37 @@ Introduction Mapping of precompiled contracts their implementations. ". -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". - -Require ethereum.cancun.fork_types. -Axiom ethereum_cancun_fork_types_Address : - IsGlobalAlias globals ethereum.cancun.fork_types.globals "Address". - -Require ethereum.cancun.vm.precompiled_contracts.__init__. -Axiom ethereum_cancun_vm_precompiled_contracts___init___ALT_BN128_ADD_ADDRESS : - IsGlobalAlias globals ethereum.cancun.vm.precompiled_contracts.__init__.globals "ALT_BN128_ADD_ADDRESS". -Axiom ethereum_cancun_vm_precompiled_contracts___init___ALT_BN128_MUL_ADDRESS : - IsGlobalAlias globals ethereum.cancun.vm.precompiled_contracts.__init__.globals "ALT_BN128_MUL_ADDRESS". -Axiom ethereum_cancun_vm_precompiled_contracts___init___ALT_BN128_PAIRING_CHECK_ADDRESS : - IsGlobalAlias globals ethereum.cancun.vm.precompiled_contracts.__init__.globals "ALT_BN128_PAIRING_CHECK_ADDRESS". -Axiom ethereum_cancun_vm_precompiled_contracts___init___BLAKE2F_ADDRESS : - IsGlobalAlias globals ethereum.cancun.vm.precompiled_contracts.__init__.globals "BLAKE2F_ADDRESS". -Axiom ethereum_cancun_vm_precompiled_contracts___init___ECRECOVER_ADDRESS : - IsGlobalAlias globals ethereum.cancun.vm.precompiled_contracts.__init__.globals "ECRECOVER_ADDRESS". -Axiom ethereum_cancun_vm_precompiled_contracts___init___IDENTITY_ADDRESS : - IsGlobalAlias globals ethereum.cancun.vm.precompiled_contracts.__init__.globals "IDENTITY_ADDRESS". -Axiom ethereum_cancun_vm_precompiled_contracts___init___MODEXP_ADDRESS : - IsGlobalAlias globals ethereum.cancun.vm.precompiled_contracts.__init__.globals "MODEXP_ADDRESS". -Axiom ethereum_cancun_vm_precompiled_contracts___init___POINT_EVALUATION_ADDRESS : - IsGlobalAlias globals ethereum.cancun.vm.precompiled_contracts.__init__.globals "POINT_EVALUATION_ADDRESS". -Axiom ethereum_cancun_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : - IsGlobalAlias globals ethereum.cancun.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". -Axiom ethereum_cancun_vm_precompiled_contracts___init___SHA256_ADDRESS : - IsGlobalAlias globals ethereum.cancun.vm.precompiled_contracts.__init__.globals "SHA256_ADDRESS". - -Require ethereum.cancun.vm.precompiled_contracts.alt_bn128. -Axiom ethereum_cancun_vm_precompiled_contracts_alt_bn128_alt_bn128_add : - IsGlobalAlias globals ethereum.cancun.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_add". -Axiom ethereum_cancun_vm_precompiled_contracts_alt_bn128_alt_bn128_mul : - IsGlobalAlias globals ethereum.cancun.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_mul". -Axiom ethereum_cancun_vm_precompiled_contracts_alt_bn128_alt_bn128_pairing_check : - IsGlobalAlias globals ethereum.cancun.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_pairing_check". - -Require ethereum.cancun.vm.precompiled_contracts.blake2f. -Axiom ethereum_cancun_vm_precompiled_contracts_blake2f_blake2f : - IsGlobalAlias globals ethereum.cancun.vm.precompiled_contracts.blake2f.globals "blake2f". - -Require ethereum.cancun.vm.precompiled_contracts.ecrecover. -Axiom ethereum_cancun_vm_precompiled_contracts_ecrecover_ecrecover : - IsGlobalAlias globals ethereum.cancun.vm.precompiled_contracts.ecrecover.globals "ecrecover". - -Require ethereum.cancun.vm.precompiled_contracts.identity. -Axiom ethereum_cancun_vm_precompiled_contracts_identity_identity : - IsGlobalAlias globals ethereum.cancun.vm.precompiled_contracts.identity.globals "identity". - -Require ethereum.cancun.vm.precompiled_contracts.modexp. -Axiom ethereum_cancun_vm_precompiled_contracts_modexp_modexp : - IsGlobalAlias globals ethereum.cancun.vm.precompiled_contracts.modexp.globals "modexp". - -Require ethereum.cancun.vm.precompiled_contracts.point_evaluation. -Axiom ethereum_cancun_vm_precompiled_contracts_point_evaluation_point_evaluation : - IsGlobalAlias globals ethereum.cancun.vm.precompiled_contracts.point_evaluation.globals "point_evaluation". - -Require ethereum.cancun.vm.precompiled_contracts.ripemd160. -Axiom ethereum_cancun_vm_precompiled_contracts_ripemd160_ripemd160 : - IsGlobalAlias globals ethereum.cancun.vm.precompiled_contracts.ripemd160.globals "ripemd160". - -Require ethereum.cancun.vm.precompiled_contracts.sha256. -Axiom ethereum_cancun_vm_precompiled_contracts_sha256_sha256 : - IsGlobalAlias globals ethereum.cancun.vm.precompiled_contracts.sha256.globals "sha256". +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict" ]. + +Axiom ethereum_cancun_fork_types_imports : + AreImported globals "ethereum.cancun.fork_types" [ "Address" ]. + +Axiom ethereum_cancun_vm_precompiled_contracts_imports : + AreImported globals "ethereum.cancun.vm.precompiled_contracts" [ "ALT_BN128_ADD_ADDRESS"; "ALT_BN128_MUL_ADDRESS"; "ALT_BN128_PAIRING_CHECK_ADDRESS"; "BLAKE2F_ADDRESS"; "ECRECOVER_ADDRESS"; "IDENTITY_ADDRESS"; "MODEXP_ADDRESS"; "POINT_EVALUATION_ADDRESS"; "RIPEMD160_ADDRESS"; "SHA256_ADDRESS" ]. + +Axiom ethereum_cancun_vm_precompiled_contracts_alt_bn128_imports : + AreImported globals "ethereum.cancun.vm.precompiled_contracts.alt_bn128" [ "alt_bn128_add"; "alt_bn128_mul"; "alt_bn128_pairing_check" ]. + +Axiom ethereum_cancun_vm_precompiled_contracts_blake2f_imports : + AreImported globals "ethereum.cancun.vm.precompiled_contracts.blake2f" [ "blake2f" ]. + +Axiom ethereum_cancun_vm_precompiled_contracts_ecrecover_imports : + AreImported globals "ethereum.cancun.vm.precompiled_contracts.ecrecover" [ "ecrecover" ]. + +Axiom ethereum_cancun_vm_precompiled_contracts_identity_imports : + AreImported globals "ethereum.cancun.vm.precompiled_contracts.identity" [ "identity" ]. + +Axiom ethereum_cancun_vm_precompiled_contracts_modexp_imports : + AreImported globals "ethereum.cancun.vm.precompiled_contracts.modexp" [ "modexp" ]. + +Axiom ethereum_cancun_vm_precompiled_contracts_point_evaluation_imports : + AreImported globals "ethereum.cancun.vm.precompiled_contracts.point_evaluation" [ "point_evaluation" ]. + +Axiom ethereum_cancun_vm_precompiled_contracts_ripemd160_imports : + AreImported globals "ethereum.cancun.vm.precompiled_contracts.ripemd160" [ "ripemd160" ]. + +Axiom ethereum_cancun_vm_precompiled_contracts_sha256_imports : + AreImported globals "ethereum.cancun.vm.precompiled_contracts.sha256" [ "sha256" ]. (* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/modexp.v index b1c90a6..5480d95 100644 --- a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/modexp.v +++ b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/modexp.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.cancun.vm.precompiled_contracts.modexp". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementation of the `MODEXP` precompiled contract. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. -Require ethereum.cancun.vm.__init__. -Axiom ethereum_cancun_vm___init___Evm : - IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Evm". +Axiom ethereum_cancun_vm_imports : + AreImported globals "ethereum.cancun.vm" [ "Evm" ]. -Require ethereum.cancun.vm.gas. -Axiom ethereum_cancun_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "charge_gas". +Axiom ethereum_cancun_vm_gas_imports : + AreImported globals "ethereum.cancun.vm.gas" [ "charge_gas" ]. -Require ethereum.cancun.vm.memory. -Axiom ethereum_cancun_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.cancun.vm.memory.globals "buffer_read". +Axiom ethereum_cancun_vm_memory_imports : + AreImported globals "ethereum.cancun.vm.memory" [ "buffer_read" ]. Definition GQUADDIVISOR : Value.t := M.run ltac:(M.monadic ( Constant.int 3 diff --git a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/point_evaluation.v b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/point_evaluation.v index 50fe7bc..a243f3f 100644 --- a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/point_evaluation.v +++ b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/point_evaluation.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.cancun.vm.precompiled_contracts.point_evaluation". Definition expr_1 : Value.t := Constant.str " @@ -17,37 +17,23 @@ Introduction Implementation of the POINT EVALUATION precompiled contract. ". -Require eth2spec.deneb.mainnet. -Axiom eth2spec_deneb_mainnet_KZGCommitment : - IsGlobalAlias globals eth2spec.deneb.mainnet.globals "KZGCommitment". -Axiom eth2spec_deneb_mainnet_kzg_commitment_to_versioned_hash : - IsGlobalAlias globals eth2spec.deneb.mainnet.globals "kzg_commitment_to_versioned_hash". -Axiom eth2spec_deneb_mainnet_verify_kzg_proof : - IsGlobalAlias globals eth2spec.deneb.mainnet.globals "verify_kzg_proof". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.cancun.vm.__init__. -Axiom ethereum_cancun_vm___init___Evm : - IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Evm". - -Require ethereum.cancun.vm.exceptions. -Axiom ethereum_cancun_vm_exceptions_KZGProofError : - IsGlobalAlias globals ethereum.cancun.vm.exceptions.globals "KZGProofError". - -Require ethereum.cancun.vm.gas. -Axiom ethereum_cancun_vm_gas_GAS_POINT_EVALUATION : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_POINT_EVALUATION". -Axiom ethereum_cancun_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "charge_gas". +Axiom eth2spec_deneb_mainnet_imports : + AreImported globals "eth2spec.deneb.mainnet" [ "KZGCommitment"; "kzg_commitment_to_versioned_hash"; "verify_kzg_proof" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_cancun_vm_imports : + AreImported globals "ethereum.cancun.vm" [ "Evm" ]. + +Axiom ethereum_cancun_vm_exceptions_imports : + AreImported globals "ethereum.cancun.vm.exceptions" [ "KZGProofError" ]. + +Axiom ethereum_cancun_vm_gas_imports : + AreImported globals "ethereum.cancun.vm.gas" [ "GAS_POINT_EVALUATION"; "charge_gas" ]. Definition FIELD_ELEMENTS_PER_BLOB : Value.t := M.run ltac:(M.monadic ( Constant.int 4096 @@ -94,21 +80,46 @@ Definition point_evaluation : Value.t -> Value.t -> M := make_dict [] |) in let versioned_hash := - M.get_subscript (| M.get_name (| globals, "data" |), M.slice (| Constant.None_, Constant.int 32 |) |) in + M.slice (| + M.get_name (| globals, "data" |), + Constant.None_, + Constant.int 32, + Constant.None_ + |) in let z := - M.get_subscript (| M.get_name (| globals, "data" |), M.slice (| Constant.int 32, Constant.int 64 |) |) in + M.slice (| + M.get_name (| globals, "data" |), + Constant.int 32, + Constant.int 64, + Constant.None_ + |) in let y := - M.get_subscript (| M.get_name (| globals, "data" |), M.slice (| Constant.int 64, Constant.int 96 |) |) in + M.slice (| + M.get_name (| globals, "data" |), + Constant.int 64, + Constant.int 96, + Constant.None_ + |) in let commitment := M.call (| M.get_name (| globals, "KZGCommitment" |), make_list [ - M.get_subscript (| M.get_name (| globals, "data" |), M.slice (| Constant.int 96, Constant.int 144 |) |) + M.slice (| + M.get_name (| globals, "data" |), + Constant.int 96, + Constant.int 144, + Constant.None_ + |) ], make_dict [] |) in let proof := - M.get_subscript (| M.get_name (| globals, "data" |), M.slice (| Constant.int 144, Constant.int 192 |) |) in + M.slice (| + M.get_name (| globals, "data" |), + Constant.int 144, + Constant.int 192, + Constant.None_ + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ diff --git a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/ripemd160.v index 03543d2..ecb3e96 100644 --- a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/ripemd160.v +++ b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/ripemd160.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.cancun.vm.precompiled_contracts.ripemd160". Definition expr_1 : Value.t := Constant.str " @@ -19,29 +19,20 @@ Implementation of the `RIPEMD160` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_left_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.cancun.vm.__init__. -Axiom ethereum_cancun_vm___init___Evm : - IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Evm". +Axiom ethereum_cancun_vm_imports : + AreImported globals "ethereum.cancun.vm" [ "Evm" ]. -Require ethereum.cancun.vm.gas. -Axiom ethereum_cancun_vm_gas_GAS_RIPEMD160 : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_RIPEMD160". -Axiom ethereum_cancun_vm_gas_GAS_RIPEMD160_WORD : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_RIPEMD160_WORD". -Axiom ethereum_cancun_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "charge_gas". +Axiom ethereum_cancun_vm_gas_imports : + AreImported globals "ethereum.cancun.vm.gas" [ "GAS_RIPEMD160"; "GAS_RIPEMD160_WORD"; "charge_gas" ]. Definition ripemd160 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/sha256.v index c1dd853..14c6290 100644 --- a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/sha256.v +++ b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/sha256.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.cancun.vm.precompiled_contracts.sha256". Definition expr_1 : Value.t := Constant.str " @@ -19,25 +19,17 @@ Implementation of the `SHA256` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.cancun.vm.__init__. -Axiom ethereum_cancun_vm___init___Evm : - IsGlobalAlias globals ethereum.cancun.vm.__init__.globals "Evm". +Axiom ethereum_cancun_vm_imports : + AreImported globals "ethereum.cancun.vm" [ "Evm" ]. -Require ethereum.cancun.vm.gas. -Axiom ethereum_cancun_vm_gas_GAS_SHA256 : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_SHA256". -Axiom ethereum_cancun_vm_gas_GAS_SHA256_WORD : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "GAS_SHA256_WORD". -Axiom ethereum_cancun_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.cancun.vm.gas.globals "charge_gas". +Axiom ethereum_cancun_vm_gas_imports : + AreImported globals "ethereum.cancun.vm.gas" [ "GAS_SHA256"; "GAS_SHA256_WORD"; "charge_gas" ]. Definition sha256 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/cancun/vm/runtime.v b/CoqOfPython/ethereum/cancun/vm/runtime.v index 238d0df..6ec53e6 100644 --- a/CoqOfPython/ethereum/cancun/vm/runtime.v +++ b/CoqOfPython/ethereum/cancun/vm/runtime.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.cancun.vm.runtime". Definition expr_1 : Value.t := Constant.str " @@ -17,17 +17,14 @@ Introduction Runtime related operations used while executing EVM code. ". -Require typing. -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". +Axiom typing_imports : + AreImported globals "typing" [ "Set" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.cancun.vm.instructions.__init__. -Axiom ethereum_cancun_vm_instructions___init___Ops : - IsGlobalAlias globals ethereum.cancun.vm.instructions.__init__.globals "Ops". +Axiom ethereum_cancun_vm_instructions_imports : + AreImported globals "ethereum.cancun.vm.instructions" [ "Ops" ]. Definition get_valid_jump_destinations : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -67,75 +64,83 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := ], make_dict [] |) in - While Compare.lt (| - M.get_name (| globals, "pc" |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "code" |) - ], - make_dict [] - |) - |) do -(* At stmt: unsupported node type: Try *) - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "current_opcode" |), - M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) - |), - (* then *) + let _ := + M.while (| + Compare.lt (| + M.get_name (| globals, "pc" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) + |), ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), - make_list [ - M.get_name (| globals, "pc" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( +(* At stmt: unsupported node type: Try *) let _ := (* if *) M.if_then_else (| - BoolOp.and (| - Compare.lt_e (| - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |), - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |) - |), - ltac:(M.monadic ( - Compare.lt_e (| - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH32" |), "value" |) - |) - )) + Compare.eq (| + M.get_name (| globals, "current_opcode" |), + M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) |), (* then *) ltac:(M.monadic ( - let push_data_size := - BinOp.add (| - BinOp.sub (| - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) - |), - Constant.int 1 - |) in - let pc := BinOp.add - M.get_name (| globals, "push_data_size" |) - M.get_name (| globals, "push_data_size" |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), + make_list [ + M.get_name (| globals, "pc" |) + ], + make_dict [] + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.lt_e (| + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |), + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH32" |), "value" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let push_data_size := + BinOp.add (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) + |), + Constant.int 1 + |) in + let pc := BinOp.add + M.get_name (| globals, "push_data_size" |) + M.get_name (| globals, "push_data_size" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ )) |) in + let pc := BinOp.add + Constant.int 1 + Constant.int 1 in M.pure Constant.None_ - )) |) in - let pc := BinOp.add - Constant.int 1 - Constant.int 1 in - EndWhile. + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.get_name (| globals, "valid_jump_destinations" |) |) in diff --git a/CoqOfPython/ethereum/cancun/vm/stack.v b/CoqOfPython/ethereum/cancun/vm/stack.v index f6dfd56..7af5c14 100644 --- a/CoqOfPython/ethereum/cancun/vm/stack.v +++ b/CoqOfPython/ethereum/cancun/vm/stack.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.cancun.vm.stack". Definition expr_1 : Value.t := Constant.str " @@ -17,19 +17,14 @@ Introduction Implementation of the stack operators for the EVM. ". -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". +Axiom typing_imports : + AreImported globals "typing" [ "List" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.cancun.vm.exceptions. -Axiom ethereum_cancun_vm_exceptions_StackOverflowError : - IsGlobalAlias globals ethereum.cancun.vm.exceptions.globals "StackOverflowError". -Axiom ethereum_cancun_vm_exceptions_StackUnderflowError : - IsGlobalAlias globals ethereum.cancun.vm.exceptions.globals "StackUnderflowError". +Axiom ethereum_cancun_vm_exceptions_imports : + AreImported globals "ethereum.cancun.vm.exceptions" [ "StackOverflowError"; "StackUnderflowError" ]. Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -63,7 +58,7 @@ Definition pop : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "StackUnderflowError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "StackUnderflowError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -108,7 +103,7 @@ Definition push : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "StackOverflowError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "StackOverflowError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/constantinople/__init__.v b/CoqOfPython/ethereum/constantinople/__init__.v index 1ebc0ac..78ad716 100644 --- a/CoqOfPython/ethereum/constantinople/__init__.v +++ b/CoqOfPython/ethereum/constantinople/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.constantinople.__init__". Definition expr_1 : Value.t := Constant.str " @@ -9,9 +9,8 @@ and introduces new EVM instructions for logical shifts, counterfactual contract deployment, and computing bytecode hashes. ". -Require ethereum.fork_criteria. -Axiom ethereum_fork_criteria_ByBlockNumber : - IsGlobalAlias globals ethereum.fork_criteria.globals "ByBlockNumber". +Axiom ethereum_fork_criteria_imports : + AreImported globals "ethereum.fork_criteria" [ "ByBlockNumber" ]. Definition FORK_CRITERIA : Value.t := M.run ltac:(M.monadic ( M.call (| diff --git a/CoqOfPython/ethereum/constantinople/blocks.v b/CoqOfPython/ethereum/constantinople/blocks.v index ef524dc..3967b31 100644 --- a/CoqOfPython/ethereum/constantinople/blocks.v +++ b/CoqOfPython/ethereum/constantinople/blocks.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.constantinople.blocks". Definition expr_1 : Value.t := Constant.str " @@ -14,43 +14,23 @@ history of all state transitions that have happened since the genesis of the chain. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes8 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes8". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". - -Require ethereum.constantinople.fork_types. -Axiom ethereum_constantinople_fork_types_Address : - IsGlobalAlias globals ethereum.constantinople.fork_types.globals "Address". -Axiom ethereum_constantinople_fork_types_Bloom : - IsGlobalAlias globals ethereum.constantinople.fork_types.globals "Bloom". -Axiom ethereum_constantinople_fork_types_Root : - IsGlobalAlias globals ethereum.constantinople.fork_types.globals "Root". - -Require ethereum.constantinople.transactions. -Axiom ethereum_constantinople_transactions_Transaction : - IsGlobalAlias globals ethereum.constantinople.transactions.globals "Transaction". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes8"; "Bytes32"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. + +Axiom ethereum_constantinople_fork_types_imports : + AreImported globals "ethereum.constantinople.fork_types" [ "Address"; "Bloom"; "Root" ]. + +Axiom ethereum_constantinople_transactions_imports : + AreImported globals "ethereum.constantinople.transactions" [ "Transaction" ]. Definition Header : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/constantinople/bloom.v b/CoqOfPython/ethereum/constantinople/bloom.v index 90f926e..58de453 100644 --- a/CoqOfPython/ethereum/constantinople/bloom.v +++ b/CoqOfPython/ethereum/constantinople/bloom.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.constantinople.bloom". Definition expr_1 : Value.t := Constant.str " @@ -21,25 +21,20 @@ for efficient searching of logs by address and/or topic, by rapidly eliminating blocks and receipts from their search. ". -Require typing. -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_imports : + AreImported globals "typing" [ "Tuple" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. -Require ethereum.constantinople.blocks. -Axiom ethereum_constantinople_blocks_Log : - IsGlobalAlias globals ethereum.constantinople.blocks.globals "Log". +Axiom ethereum_constantinople_blocks_imports : + AreImported globals "ethereum.constantinople.blocks" [ "Log" ]. -Require ethereum.constantinople.fork_types. -Axiom ethereum_constantinople_fork_types_Bloom : - IsGlobalAlias globals ethereum.constantinople.fork_types.globals "Bloom". +Axiom ethereum_constantinople_fork_types_imports : + AreImported globals "ethereum.constantinople.fork_types" [ "Bloom" ]. Definition add_to_bloom : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -66,50 +61,70 @@ Definition add_to_bloom : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "idx" |) in make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ] do - let bit_to_set := - BinOp.bit_and (| - M.call (| - M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "hash" |), M.slice (| M.get_name (| globals, "idx" |), BinOp.add (| - M.get_name (| globals, "idx" |), - Constant.int 2 - |) |) |) - ], - make_dict [] - |), - Constant.int 2047 - |) in - let bit_index := - BinOp.sub (| - Constant.int 2047, - M.get_name (| globals, "bit_to_set" |) - |) in - let byte_index := - BinOp.floor_div (| - M.get_name (| globals, "bit_index" |), - Constant.int 8 - |) in - let bit_value := - BinOp.l_shift (| - Constant.int 1, - BinOp.sub (| - Constant.int 7, - BinOp.mod_ (| + let _ := + M.for_ (| + M.get_name (| globals, "idx" |), + make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ], + ltac:(M.monadic ( + let bit_to_set := + BinOp.bit_and (| + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.slice (| + M.get_name (| globals, "hash" |), + M.get_name (| globals, "idx" |), + BinOp.add (| + M.get_name (| globals, "idx" |), + Constant.int 2 + |), + Constant.None_ + |) + ], + make_dict [] + |), + Constant.int 2047 + |) in + let bit_index := + BinOp.sub (| + Constant.int 2047, + M.get_name (| globals, "bit_to_set" |) + |) in + let byte_index := + BinOp.floor_div (| M.get_name (| globals, "bit_index" |), Constant.int 8 + |) in + let bit_value := + BinOp.l_shift (| + Constant.int 1, + BinOp.sub (| + Constant.int 7, + BinOp.mod_ (| + M.get_name (| globals, "bit_index" |), + Constant.int 8 + |) + |) + |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "bloom" |), + M.get_name (| globals, "byte_index" |) + |), + BinOp.bit_or (| + M.get_subscript (| + M.get_name (| globals, "bloom" |), + M.get_name (| globals, "byte_index" |) + |), + M.get_name (| globals, "bit_value" |) |) - |) - |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), - BinOp.bit_or (| - M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), - M.get_name (| globals, "bit_value" |) - |) - |) in - EndFor. + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_)). Definition logs_bloom : Value.t -> Value.t -> M := @@ -132,8 +147,12 @@ Definition logs_bloom : Value.t -> Value.t -> M := the caller address and the log topics. " in (* At stmt: unsupported node type: AnnAssign *) - For M.get_name (| globals, "log" |) in M.get_name (| globals, "logs" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "log" |), + M.get_name (| globals, "logs" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "add_to_bloom" |), make_list [ M.get_name (| globals, "bloom" |); @@ -141,8 +160,12 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "topic" |) in M.get_field (| M.get_name (| globals, "log" |), "topics" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "topic" |), + M.get_field (| M.get_name (| globals, "log" |), "topics" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "add_to_bloom" |), make_list [ M.get_name (| globals, "bloom" |); @@ -150,8 +173,18 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Bloom" |), diff --git a/CoqOfPython/ethereum/constantinople/fork.v b/CoqOfPython/ethereum/constantinople/fork.v index 7105bb0..c879a88 100644 --- a/CoqOfPython/ethereum/constantinople/fork.v +++ b/CoqOfPython/ethereum/constantinople/fork.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.constantinople.fork". Definition expr_1 : Value.t := Constant.str " @@ -17,139 +17,62 @@ Introduction Entry point for the Ethereum specification. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". - -Require ethereum.crypto.elliptic_curve. -Axiom ethereum_crypto_elliptic_curve_SECP256K1N : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". -Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.ethash. -Axiom ethereum_ethash_dataset_size : - IsGlobalAlias globals ethereum.ethash.globals "dataset_size". -Axiom ethereum_ethash_generate_cache : - IsGlobalAlias globals ethereum.ethash.globals "generate_cache". -Axiom ethereum_ethash_hashimoto_light : - IsGlobalAlias globals ethereum.ethash.globals "hashimoto_light". - -Require ethereum.exceptions. -Axiom ethereum_exceptions_InvalidBlock : - IsGlobalAlias globals ethereum.exceptions.globals "InvalidBlock". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U64 : - IsGlobalAlias globals ethereum.base_types.globals "U64". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_U256_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.constantinople.__init__. -Axiom ethereum_constantinople___init___vm : - IsGlobalAlias globals ethereum.constantinople.__init__.globals "vm". - -Require ethereum.constantinople.blocks. -Axiom ethereum_constantinople_blocks_Block : - IsGlobalAlias globals ethereum.constantinople.blocks.globals "Block". -Axiom ethereum_constantinople_blocks_Header : - IsGlobalAlias globals ethereum.constantinople.blocks.globals "Header". -Axiom ethereum_constantinople_blocks_Log : - IsGlobalAlias globals ethereum.constantinople.blocks.globals "Log". -Axiom ethereum_constantinople_blocks_Receipt : - IsGlobalAlias globals ethereum.constantinople.blocks.globals "Receipt". - -Require ethereum.constantinople.bloom. -Axiom ethereum_constantinople_bloom_logs_bloom : - IsGlobalAlias globals ethereum.constantinople.bloom.globals "logs_bloom". - -Require ethereum.constantinople.fork_types. -Axiom ethereum_constantinople_fork_types_Address : - IsGlobalAlias globals ethereum.constantinople.fork_types.globals "Address". -Axiom ethereum_constantinople_fork_types_Bloom : - IsGlobalAlias globals ethereum.constantinople.fork_types.globals "Bloom". -Axiom ethereum_constantinople_fork_types_Root : - IsGlobalAlias globals ethereum.constantinople.fork_types.globals "Root". - -Require ethereum.constantinople.state. -Axiom ethereum_constantinople_state_State : - IsGlobalAlias globals ethereum.constantinople.state.globals "State". -Axiom ethereum_constantinople_state_account_exists_and_is_empty : - IsGlobalAlias globals ethereum.constantinople.state.globals "account_exists_and_is_empty". -Axiom ethereum_constantinople_state_create_ether : - IsGlobalAlias globals ethereum.constantinople.state.globals "create_ether". -Axiom ethereum_constantinople_state_destroy_account : - IsGlobalAlias globals ethereum.constantinople.state.globals "destroy_account". -Axiom ethereum_constantinople_state_get_account : - IsGlobalAlias globals ethereum.constantinople.state.globals "get_account". -Axiom ethereum_constantinople_state_increment_nonce : - IsGlobalAlias globals ethereum.constantinople.state.globals "increment_nonce". -Axiom ethereum_constantinople_state_set_account_balance : - IsGlobalAlias globals ethereum.constantinople.state.globals "set_account_balance". -Axiom ethereum_constantinople_state_state_root : - IsGlobalAlias globals ethereum.constantinople.state.globals "state_root". - -Require ethereum.constantinople.transactions. -Axiom ethereum_constantinople_transactions_TX_BASE_COST : - IsGlobalAlias globals ethereum.constantinople.transactions.globals "TX_BASE_COST". -Axiom ethereum_constantinople_transactions_TX_CREATE_COST : - IsGlobalAlias globals ethereum.constantinople.transactions.globals "TX_CREATE_COST". -Axiom ethereum_constantinople_transactions_TX_DATA_COST_PER_NON_ZERO : - IsGlobalAlias globals ethereum.constantinople.transactions.globals "TX_DATA_COST_PER_NON_ZERO". -Axiom ethereum_constantinople_transactions_TX_DATA_COST_PER_ZERO : - IsGlobalAlias globals ethereum.constantinople.transactions.globals "TX_DATA_COST_PER_ZERO". -Axiom ethereum_constantinople_transactions_Transaction : - IsGlobalAlias globals ethereum.constantinople.transactions.globals "Transaction". - -Require ethereum.constantinople.trie. -Axiom ethereum_constantinople_trie_Trie : - IsGlobalAlias globals ethereum.constantinople.trie.globals "Trie". -Axiom ethereum_constantinople_trie_root : - IsGlobalAlias globals ethereum.constantinople.trie.globals "root". -Axiom ethereum_constantinople_trie_trie_set : - IsGlobalAlias globals ethereum.constantinople.trie.globals "trie_set". - -Require ethereum.constantinople.utils.message. -Axiom ethereum_constantinople_utils_message_prepare_message : - IsGlobalAlias globals ethereum.constantinople.utils.message.globals "prepare_message". - -Require ethereum.constantinople.vm.interpreter. -Axiom ethereum_constantinople_vm_interpreter_process_message_call : - IsGlobalAlias globals ethereum.constantinople.vm.interpreter.globals "process_message_call". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Bytes0" ]. + +Axiom ethereum_crypto_elliptic_curve_imports : + AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. + +Axiom ethereum_ethash_imports : + AreImported globals "ethereum.ethash" [ "dataset_size"; "generate_cache"; "hashimoto_light" ]. + +Axiom ethereum_exceptions_imports : + AreImported globals "ethereum.exceptions" [ "InvalidBlock" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U64"; "U256"; "U256_CEIL_VALUE"; "Bytes"; "Uint" ]. + +Axiom ethereum_constantinople_imports : + AreImported globals "ethereum.constantinople" [ "vm" ]. + +Axiom ethereum_constantinople_blocks_imports : + AreImported globals "ethereum.constantinople.blocks" [ "Block"; "Header"; "Log"; "Receipt" ]. + +Axiom ethereum_constantinople_bloom_imports : + AreImported globals "ethereum.constantinople.bloom" [ "logs_bloom" ]. + +Axiom ethereum_constantinople_fork_types_imports : + AreImported globals "ethereum.constantinople.fork_types" [ "Address"; "Bloom"; "Root" ]. + +Axiom ethereum_constantinople_state_imports : + AreImported globals "ethereum.constantinople.state" [ "State"; "account_exists_and_is_empty"; "create_ether"; "destroy_account"; "get_account"; "increment_nonce"; "set_account_balance"; "state_root" ]. + +Axiom ethereum_constantinople_transactions_imports : + AreImported globals "ethereum.constantinople.transactions" [ "TX_BASE_COST"; "TX_CREATE_COST"; "TX_DATA_COST_PER_NON_ZERO"; "TX_DATA_COST_PER_ZERO"; "Transaction" ]. + +Axiom ethereum_constantinople_trie_imports : + AreImported globals "ethereum.constantinople.trie" [ "Trie"; "root"; "trie_set" ]. + +Axiom ethereum_constantinople_utils_message_imports : + AreImported globals "ethereum.constantinople.utils.message" [ "prepare_message" ]. + +Axiom ethereum_constantinople_vm_interpreter_imports : + AreImported globals "ethereum.constantinople.vm.interpreter" [ "process_message_call" ]. Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -268,7 +191,12 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := Hashes of the recent 256 blocks in order of increasing block number. " in let recent_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) in + M.slice (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| Constant.int 255 |), + Constant.None_, + Constant.None_ + |) in let _ := (* if *) M.if_then_else (| @@ -294,17 +222,26 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := )) |) in let recent_block_hashes := make_list [] in - For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_blocks" |) do - let prev_block_hash := - M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "block" |), + M.get_name (| globals, "recent_blocks" |), + ltac:(M.monadic ( + let prev_block_hash := + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in + let _ := M.call (| M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), make_list [ M.get_name (| globals, "prev_block_hash" |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let most_recent_block_hash := M.call (| M.get_name (| globals, "keccak256" |), @@ -312,7 +249,10 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), make_list [ - M.get_field (| M.get_subscript (| M.get_name (| globals, "recent_blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) + M.get_field (| M.get_subscript (| + M.get_name (| globals, "recent_blocks" |), + UnOp.sub (| Constant.int 1 |) + |), "header" |) ], make_dict [] |) @@ -356,7 +296,10 @@ Definition state_transition : Value.t -> Value.t -> M := Block to apply to `chain`. " in let parent_header := - M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) in + M.get_field (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| Constant.int 1 |) + |), "header" |) in let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ @@ -476,7 +419,12 @@ Definition state_transition : Value.t -> Value.t -> M := ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) + M.slice (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| Constant.int 255 |), + Constant.None_, + Constant.None_ + |) |) in M.pure Constant.None_ (* else *) @@ -903,14 +851,18 @@ Definition apply_body : Value.t -> Value.t -> M := (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) - For make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "tx" |) ] in M.call (| - M.get_name (| globals, "enumerate" |), - make_list [ - M.get_name (| globals, "transactions" |) - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "tx" |) ], + M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "transactions" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ M.get_name (| globals, "transactions_trie" |); @@ -931,51 +883,51 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_address := - M.call (| - M.get_name (| globals, "check_transaction" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "gas_available" |); - M.get_name (| globals, "chain_id" |) - ], - make_dict [] - |) in - let env := - M.call (| - M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), - make_list [], - make_dict [] - |) in - let _ := M.assign (| - make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |); M.get_name (| globals, "error" |) ], - M.call (| - M.get_name (| globals, "process_transaction" |), - make_list [ - M.get_name (| globals, "env" |); - M.get_name (| globals, "tx" |) - ], - make_dict [] - |) - |) in - let gas_available := BinOp.sub - M.get_name (| globals, "gas_used" |) - M.get_name (| globals, "gas_used" |) in - let receipt := - M.call (| - M.get_name (| globals, "make_receipt" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "error" |); - BinOp.sub (| - M.get_name (| globals, "block_gas_limit" |), - M.get_name (| globals, "gas_available" |) - |); - M.get_name (| globals, "logs" |) - ], - make_dict [] - |) in - let _ := M.call (| + let sender_address := + M.call (| + M.get_name (| globals, "check_transaction" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "gas_available" |); + M.get_name (| globals, "chain_id" |) + ], + make_dict [] + |) in + let env := + M.call (| + M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |); M.get_name (| globals, "error" |) ], + M.call (| + M.get_name (| globals, "process_transaction" |), + make_list [ + M.get_name (| globals, "env" |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) in + let gas_available := BinOp.sub + M.get_name (| globals, "gas_used" |) + M.get_name (| globals, "gas_used" |) in + let receipt := + M.call (| + M.get_name (| globals, "make_receipt" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "error" |); + BinOp.sub (| + M.get_name (| globals, "block_gas_limit" |), + M.get_name (| globals, "gas_available" |) + |); + M.get_name (| globals, "logs" |) + ], + make_dict [] + |) in + let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ M.get_name (| globals, "receipts_trie" |); @@ -996,10 +948,15 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_logs := BinOp.add - M.get_name (| globals, "logs" |) - M.get_name (| globals, "logs" |) in - EndFor. + let block_logs := BinOp.add + M.get_name (| globals, "logs" |) + M.get_name (| globals, "logs" |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.call (| M.get_name (| globals, "pay_rewards" |), make_list [ @@ -1128,8 +1085,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "ommer" |), + M.get_name (| globals, "ommers" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ BoolOp.and (| @@ -1148,15 +1109,18 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_parent_header := - M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), BinOp.sub (| - UnOp.sub (| BinOp.sub (| - M.get_field (| M.get_name (| globals, "block_header" |), "number" |), - M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) |), - Constant.int 1 - |) |), "header" |) in - let _ := M.call (| + let ommer_parent_header := + M.get_field (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + BinOp.sub (| + UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) |), + Constant.int 1 + |) + |), "header" |) in + let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ M.get_name (| globals, "ommer" |); @@ -1164,7 +1128,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1214,33 +1183,54 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let recent_canonical_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| BinOp.add (| - M.get_name (| globals, "MAX_OMMER_DEPTH" |), - Constant.int 1 - |) |), Constant.None_ |) |) in + M.slice (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| BinOp.add (| + M.get_name (| globals, "MAX_OMMER_DEPTH" |), + Constant.int 1 + |) |), + Constant.None_, + Constant.None_ + |) in let recent_canonical_block_hashes := Constant.str "(* At expr: unsupported node type: SetComp *)" in (* At stmt: unsupported node type: AnnAssign *) - For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_canonical_blocks" |) do - let recent_ommers_hashes := + let _ := + M.for_ (| + M.get_name (| globals, "block" |), + M.get_name (| globals, "recent_canonical_blocks" |), + ltac:(M.monadic ( + let recent_ommers_hashes := + M.call (| + M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), + make_list [ + Constant.str "(* At expr: unsupported node type: SetComp *)" + ], + make_dict [] + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "ommer_index" |); M.get_name (| globals, "ommer" |) ], M.call (| - M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), - make_list [ - Constant.str "(* At expr: unsupported node type: SetComp *)" - ], - make_dict [] - |) in - EndFor. - For make_tuple [ M.get_name (| globals, "ommer_index" |); M.get_name (| globals, "ommer" |) ] in M.call (| - M.get_name (| globals, "enumerate" |), - make_list [ - M.get_name (| globals, "ommers" |) - ], - make_dict [] - |) do - let ommer_hash := - M.get_subscript (| M.get_name (| globals, "ommers_hashes" |), M.get_name (| globals, "ommer_index" |) |) in - let _ := M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let ommer_hash := + M.get_subscript (| + M.get_name (| globals, "ommers_hashes" |), + M.get_name (| globals, "ommer_index" |) + |) in + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_eq (| @@ -1251,7 +1241,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_in (| @@ -1262,7 +1252,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_in (| @@ -1273,12 +1263,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_age := - BinOp.sub (| - M.get_field (| M.get_name (| globals, "block_header" |), "number" |), - M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) in - let _ := M.call (| + let ommer_age := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) in + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ BoolOp.and (| @@ -1297,10 +1287,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.in (| + Compare.in_ (| M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), M.get_name (| globals, "recent_canonical_block_hashes" |) |); @@ -1308,7 +1298,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_eq (| @@ -1319,7 +1309,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_)). Definition pay_rewards : Value.t -> Value.t -> M := @@ -1376,30 +1371,34 @@ Definition pay_rewards : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do - let ommer_age := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - BinOp.sub (| - M.get_name (| globals, "block_number" |), - M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) - ], - make_dict [] - |) in - let ommer_miner_reward := - BinOp.floor_div (| - BinOp.mult (| - BinOp.sub (| - Constant.int 8, - M.get_name (| globals, "ommer_age" |) - |), - M.get_name (| globals, "BLOCK_REWARD" |) - |), - Constant.int 8 - |) in - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "ommer" |), + M.get_name (| globals, "ommers" |), + ltac:(M.monadic ( + let ommer_age := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "block_number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) + ], + make_dict [] + |) in + let ommer_miner_reward := + BinOp.floor_div (| + BinOp.mult (| + BinOp.sub (| + Constant.int 8, + M.get_name (| globals, "ommer_age" |) + |), + M.get_name (| globals, "BLOCK_REWARD" |) + |), + Constant.int 8 + |) in + let _ := M.call (| M.get_name (| globals, "create_ether" |), make_list [ M.get_name (| globals, "state" |); @@ -1408,7 +1407,12 @@ Definition pay_rewards : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_)). Definition process_transaction : Value.t -> Value.t -> M := @@ -1688,8 +1692,12 @@ Definition process_transaction : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "accounts_to_delete" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "output" |), "accounts_to_delete" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "destroy_account" |), make_list [ M.get_field (| M.get_name (| globals, "env" |), "state" |); @@ -1697,22 +1705,31 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. - For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "touched_accounts" |) do - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), - (* then *) + M.pure Constant.None_ + )), ltac:(M.monadic ( - let _ := M.call (| + M.pure Constant.None_ + )) + |) in + let _ := + M.for_ (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "output" |), "touched_accounts" |), + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "destroy_account" |), make_list [ M.get_field (| M.get_name (| globals, "env" |), "state" |); @@ -1720,12 +1737,17 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := M.return_ (| make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |); M.get_field (| M.get_name (| globals, "output" |), "error" |) ] |) in @@ -1813,28 +1835,37 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := " in let data_cost := Constant.int 0 in - For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "byte" |), - Constant.int 0 - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "byte" |), + M.get_field (| M.get_name (| globals, "tx" |), "data" |), ltac:(M.monadic ( - let data_cost := BinOp.add - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "byte" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let data_cost := BinOp.add - M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := (* if *) M.if_then_else (| @@ -2049,13 +2080,18 @@ Definition recover_sender : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "Address" |), make_list [ - M.get_subscript (| M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "public_key" |) - ], - make_dict [] - |), M.slice (| Constant.int 12, Constant.int 32 |) |) + M.slice (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), + Constant.int 12, + Constant.int 32, + Constant.None_ + |) ], make_dict [] |) diff --git a/CoqOfPython/ethereum/constantinople/fork_types.v b/CoqOfPython/ethereum/constantinople/fork_types.v index cc8e4a1..e4d2540 100644 --- a/CoqOfPython/ethereum/constantinople/fork_types.v +++ b/CoqOfPython/ethereum/constantinople/fork_types.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.constantinople.fork_types". Definition expr_1 : Value.t := Constant.str " @@ -17,33 +17,17 @@ Introduction Types re-used throughout the specification, which are specific to Ethereum. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes20 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes20". -Axiom ethereum_base_types_Bytes256 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes20"; "Bytes256"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) diff --git a/CoqOfPython/ethereum/constantinople/state.v b/CoqOfPython/ethereum/constantinople/state.v index 0d54e5a..c81c754 100644 --- a/CoqOfPython/ethereum/constantinople/state.v +++ b/CoqOfPython/ethereum/constantinople/state.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.constantinople.state". Definition expr_1 : Value.t := Constant.str " @@ -22,61 +22,23 @@ There is a distinction between an account that does not exist and `EMPTY_ACCOUNT`. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". -Axiom dataclasses_field : - IsGlobalAlias globals dataclasses.globals "field". - -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_modify : - IsGlobalAlias globals ethereum.base_types.globals "modify". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.constantinople.fork_types. -Axiom ethereum_constantinople_fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals ethereum.constantinople.fork_types.globals "EMPTY_ACCOUNT". -Axiom ethereum_constantinople_fork_types_Account : - IsGlobalAlias globals ethereum.constantinople.fork_types.globals "Account". -Axiom ethereum_constantinople_fork_types_Address : - IsGlobalAlias globals ethereum.constantinople.fork_types.globals "Address". -Axiom ethereum_constantinople_fork_types_Root : - IsGlobalAlias globals ethereum.constantinople.fork_types.globals "Root". - -Require ethereum.constantinople.trie. -Axiom ethereum_constantinople_trie_EMPTY_TRIE_ROOT : - IsGlobalAlias globals ethereum.constantinople.trie.globals "EMPTY_TRIE_ROOT". -Axiom ethereum_constantinople_trie_Trie : - IsGlobalAlias globals ethereum.constantinople.trie.globals "Trie". -Axiom ethereum_constantinople_trie_copy_trie : - IsGlobalAlias globals ethereum.constantinople.trie.globals "copy_trie". -Axiom ethereum_constantinople_trie_root : - IsGlobalAlias globals ethereum.constantinople.trie.globals "root". -Axiom ethereum_constantinople_trie_trie_get : - IsGlobalAlias globals ethereum.constantinople.trie.globals "trie_get". -Axiom ethereum_constantinople_trie_trie_set : - IsGlobalAlias globals ethereum.constantinople.trie.globals "trie_set". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass"; "field" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict"; "List"; "Optional"; "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "modify" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_constantinople_fork_types_imports : + AreImported globals "ethereum.constantinople.fork_types" [ "EMPTY_ACCOUNT"; "Account"; "Address"; "Root" ]. + +Axiom ethereum_constantinople_trie_imports : + AreImported globals "ethereum.constantinople.trie" [ "EMPTY_TRIE_ROOT"; "Trie"; "copy_trie"; "root"; "trie_get"; "trie_set" ]. Definition State : Value.t := builtins.make_klass @@ -338,13 +300,16 @@ Definition destroy_storage : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -479,7 +444,10 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), + M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |), M.get_name (| globals, "trie" |) |) in M.pure Constant.None_ @@ -505,7 +473,10 @@ Definition set_storage : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -535,7 +506,7 @@ Definition storage_root : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), @@ -545,7 +516,10 @@ Definition storage_root : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "root" |), make_list [ - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) + M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |) ], make_dict [] |) diff --git a/CoqOfPython/ethereum/constantinople/transactions.v b/CoqOfPython/ethereum/constantinople/transactions.v index e051e60..8eedff8 100644 --- a/CoqOfPython/ethereum/constantinople/transactions.v +++ b/CoqOfPython/ethereum/constantinople/transactions.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.constantinople.transactions". Definition expr_1 : Value.t := Constant.str " @@ -9,29 +9,17 @@ submitted to be executed. If Ethereum is viewed as a state machine, transactions are the events that move between states. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.constantinople.fork_types. -Axiom ethereum_constantinople_fork_types_Address : - IsGlobalAlias globals ethereum.constantinople.fork_types.globals "Address". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Union" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_constantinople_fork_types_imports : + AreImported globals "ethereum.constantinople.fork_types" [ "Address" ]. Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( Constant.int 21000 diff --git a/CoqOfPython/ethereum/constantinople/trie.v b/CoqOfPython/ethereum/constantinople/trie.v index cfed49d..c242bbd 100644 --- a/CoqOfPython/ethereum/constantinople/trie.v +++ b/CoqOfPython/ethereum/constantinople/trie.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.constantinople.trie". Definition expr_1 : Value.t := Constant.str " @@ -20,83 +20,38 @@ The state trie is the structure responsible for storing (* At top_level_stmt: unsupported node type: Import *) -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". -Axiom dataclasses_field : - IsGlobalAlias globals dataclasses.globals "field". - -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". -Axiom typing_Generic : - IsGlobalAlias globals typing.globals "Generic". -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Mapping : - IsGlobalAlias globals typing.globals "Mapping". -Axiom typing_MutableMapping : - IsGlobalAlias globals typing.globals "MutableMapping". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Sequence : - IsGlobalAlias globals typing.globals "Sequence". -Axiom typing_TypeVar : - IsGlobalAlias globals typing.globals "TypeVar". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". -Axiom typing_cast : - IsGlobalAlias globals typing.globals "cast". - -Require ethereum.byzantium.__init__. -Axiom ethereum_byzantium___init___trie : - IsGlobalAlias globals ethereum.byzantium.__init__.globals "trie". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.utils.hexadecimal. -Axiom ethereum_utils_hexadecimal_hex_to_bytes : - IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.constantinople.blocks. -Axiom ethereum_constantinople_blocks_Receipt : - IsGlobalAlias globals ethereum.constantinople.blocks.globals "Receipt". - -Require ethereum.constantinople.fork_types. -Axiom ethereum_constantinople_fork_types_Account : - IsGlobalAlias globals ethereum.constantinople.fork_types.globals "Account". -Axiom ethereum_constantinople_fork_types_Address : - IsGlobalAlias globals ethereum.constantinople.fork_types.globals "Address". -Axiom ethereum_constantinople_fork_types_Root : - IsGlobalAlias globals ethereum.constantinople.fork_types.globals "Root". -Axiom ethereum_constantinople_fork_types_encode_account : - IsGlobalAlias globals ethereum.constantinople.fork_types.globals "encode_account". - -Require ethereum.constantinople.transactions. -Axiom ethereum_constantinople_transactions_Transaction : - IsGlobalAlias globals ethereum.constantinople.transactions.globals "Transaction". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass"; "field" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict"; "Generic"; "List"; "Mapping"; "MutableMapping"; "Optional"; "Sequence"; "TypeVar"; "Union"; "cast" ]. + +Axiom ethereum_byzantium_imports : + AreImported globals "ethereum.byzantium" [ "trie" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_utils_hexadecimal_imports : + AreImported globals "ethereum.utils.hexadecimal" [ "hex_to_bytes" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_constantinople_blocks_imports : + AreImported globals "ethereum.constantinople.blocks" [ "Receipt" ]. + +Axiom ethereum_constantinople_fork_types_imports : + AreImported globals "ethereum.constantinople.fork_types" [ "Account"; "Address"; "Root"; "encode_account" ]. + +Axiom ethereum_constantinople_transactions_imports : + AreImported globals "ethereum.constantinople.transactions" [ "Transaction" ]. Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -115,7 +70,10 @@ Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( )). Definition Node : Value.t := M.run ltac:(M.monadic ( - M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Bytes" |); M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |); Constant.None_ ] |) + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Bytes" |); M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |); Constant.None_ ] + |) )). Definition K : Value.t := M.run ltac:(M.monadic ( @@ -133,11 +91,23 @@ Definition V : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "TypeVar" |), make_list [ Constant.str "V"; - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Account" |) |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Bytes" |) |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Account" |) + |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Bytes" |) + |); M.get_name (| globals, "Bytes" |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Transaction" |) |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Receipt" |) |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Transaction" |) + |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Receipt" |) + |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |) ], @@ -176,7 +146,10 @@ Definition BranchNode : Value.t := ]. Definition InternalNode : Value.t := M.run ltac:(M.monadic ( - M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LeafNode" |); M.get_name (| globals, "ExtensionNode" |); M.get_name (| globals, "BranchNode" |) ] |) + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "LeafNode" |); M.get_name (| globals, "ExtensionNode" |); M.get_name (| globals, "BranchNode" |) ] + |) )). Definition encode_internal_node : Value.t -> Value.t -> M := @@ -288,7 +261,7 @@ Definition encode_internal_node : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "(* At expr: unsupported node type: JoinedStr *)" @@ -528,13 +501,16 @@ Definition trie_set : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "key" |), M.get_field (| M.get_name (| globals, "trie" |), "_data" |) |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + M.get_name (| globals, "key" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -544,7 +520,10 @@ Definition trie_set : Value.t -> Value.t -> M := (* else *) )), ltac:(M.monadic ( let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), + M.get_subscript (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + M.get_name (| globals, "key" |) + |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_ @@ -589,51 +568,66 @@ Definition common_prefix_length : Value.t -> Value.t -> M := let _ := Constant.str " Find the longest common prefix of two sequences. " in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "a" |) - ], - make_dict [] - |) - ], - make_dict [] - |) do - let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| - M.get_name (| globals, "i" |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "b" |) - ], - make_dict [] - |) - |), - ltac:(M.monadic ( - Compare.not_eq (| - M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), - M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) - |) - )) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + ], + make_dict [] + |), ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "i" |) - |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_subscript (| + M.get_name (| globals, "a" |), + M.get_name (| globals, "i" |) + |), + M.get_subscript (| + M.get_name (| globals, "b" |), + M.get_name (| globals, "i" |) + |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "len" |), @@ -718,38 +712,53 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 0; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |); - Constant.int 2 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ BinOp.add (| BinOp.mult (| Constant.int 16, - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "i" |) + |) |), - M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) + |) |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -767,43 +776,61 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := Constant.int 1 |) |), - M.get_subscript (| M.get_name (| globals, "x" |), Constant.int 0 |) + M.get_subscript (| + M.get_name (| globals, "x" |), + Constant.int 0 + |) |) ], make_dict [] |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 1; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |); - Constant.int 2 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 1; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ BinOp.add (| BinOp.mult (| Constant.int 16, - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "i" |) + |) |), - M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) + |) |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -850,40 +877,55 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := ], make_dict [] |) in - For make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ] in M.call (| - M.get_name (| globals, "enumerate" |), - make_list [ - M.get_name (| globals, "bytes_" |) - ], - make_dict [] - |) do - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.mult (| - M.get_name (| globals, "byte_index" |), - Constant.int 2 - |) |), - BinOp.r_shift (| - BinOp.bit_and (| - M.get_name (| globals, "byte" |), - Constant.int 240 - |), - Constant.int 4 - |) - |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "byte_index" |), - Constant.int 2 - |), - Constant.int 1 - |) |), - BinOp.bit_and (| - M.get_name (| globals, "byte" |), - Constant.int 15 - |) - |) in - EndFor. + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ], + M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "bytes_" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "nibble_list" |), + BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |) + |), + BinOp.r_shift (| + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 240 + |), + Constant.int 4 + |) + |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "nibble_list" |), + BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |), + Constant.int 1 + |) + |), + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 15 + |) + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Bytes" |), @@ -916,65 +958,69 @@ Definition _prepare_trie : Value.t -> Value.t -> M := Object with keys mapped to nibble-byte form. " in (* At stmt: unsupported node type: AnnAssign *) - For make_tuple [ M.get_name (| globals, "preimage" |); M.get_name (| globals, "value" |) ] in M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "items" |), - make_list [], - make_dict [] - |) do - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "value" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "preimage" |); M.get_name (| globals, "value" |) ], + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "items" |), + make_list [], + make_dict [] + |), ltac:(M.monadic ( - let _ := M.assert (| Compare.is_not (| + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in - let address := - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in - let encoded_value := - M.call (| - M.get_name (| globals, "encode_node" |), - make_list [ - M.get_name (| globals, "value" |); + let address := M.call (| - M.get_name (| globals, "get_storage_root" |), + M.get_name (| globals, "Address" |), make_list [ - M.get_name (| globals, "address" |) + M.get_name (| globals, "preimage" |) ], make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let encoded_value := - M.call (| - M.get_name (| globals, "encode_node" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - )) |) in - let _ := M.call (| + |) in + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |); + M.call (| + M.get_name (| globals, "get_storage_root" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_eq (| @@ -986,38 +1032,46 @@ Definition _prepare_trie : Value.t -> Value.t -> M := make_dict [] |) in (* At stmt: unsupported node type: AnnAssign *) - let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "trie" |), "secured" |), - (* then *) - ltac:(M.monadic ( - let key := - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "trie" |), "secured" |), + (* then *) + ltac:(M.monadic ( + let key := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let key := + M.get_name (| globals, "preimage" |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "mapped" |), + M.call (| + M.get_name (| globals, "bytes_to_nibble_list" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |) + |), + M.get_name (| globals, "encoded_value" |) + |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let key := - M.get_name (| globals, "preimage" |) in + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "mapped" |), M.call (| - M.get_name (| globals, "bytes_to_nibble_list" |), - make_list [ - M.get_name (| globals, "key" |) - ], - make_dict [] - |) |), - M.get_name (| globals, "encoded_value" |) - |) in - EndFor. + )) + |) in let _ := M.return_ (| M.get_name (| globals, "mapped" |) |) in @@ -1210,8 +1264,16 @@ Definition patricialize : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "LeafNode" |), make_list [ - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |); - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) + M.slice (| + M.get_name (| globals, "arbitrary_key" |), + M.get_name (| globals, "level" |), + Constant.None_, + Constant.None_ + |); + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "arbitrary_key" |) + |) ], make_dict [] |) in @@ -1224,7 +1286,12 @@ Definition patricialize : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in let substring := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "arbitrary_key" |), + M.get_name (| globals, "level" |), + Constant.None_, + Constant.None_ + |) in let prefix_length := M.call (| M.get_name (| globals, "len" |), @@ -1233,39 +1300,53 @@ Definition patricialize : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do - let prefix_length := - M.call (| - M.get_name (| globals, "min" |), - make_list [ - M.get_name (| globals, "prefix_length" |); + let _ := + M.for_ (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "obj" |), + ltac:(M.monadic ( + let prefix_length := M.call (| - M.get_name (| globals, "common_prefix_length" |), + M.get_name (| globals, "min" |), make_list [ - M.get_name (| globals, "substring" |); - M.get_subscript (| M.get_name (| globals, "key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) + M.get_name (| globals, "prefix_length" |); + M.call (| + M.get_name (| globals, "common_prefix_length" |), + make_list [ + M.get_name (| globals, "substring" |); + M.slice (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "level" |), + Constant.None_, + Constant.None_ + |) + ], + make_dict [] + |) ], make_dict [] - |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "prefix_length" |), - Constant.int 0 - |), - (* then *) - ltac:(M.monadic ( - let _ := M.break (| |) in + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "prefix_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := (* if *) M.if_then_else (| @@ -1276,10 +1357,15 @@ Definition patricialize : Value.t -> Value.t -> M := (* then *) ltac:(M.monadic ( let prefix := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), BinOp.add (| + M.slice (| + M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |), - M.get_name (| globals, "prefix_length" |) - |) |) |) in + BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |), + Constant.None_ + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ExtensionNode" |), @@ -1312,70 +1398,106 @@ Definition patricialize : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) - For M.get_name (| globals, "_" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 16 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "_" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 16 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "branches" |), "append" |), make_list [ {} ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let value := Constant.bytes "" in - For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "key" |) - ], - make_dict [] - |), - M.get_name (| globals, "level" |) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "obj" |), ltac:(M.monadic ( let _ := (* if *) M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); - make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] - ], - make_dict [] + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |), + M.get_name (| globals, "level" |) |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "AssertionError" |)) |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "key" |) + |); + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "AssertionError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "key" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| + M.get_subscript (| + M.get_name (| globals, "branches" |), + M.get_subscript (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "level" |) + |) + |), + M.get_name (| globals, "key" |) + |), + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "key" |) + |) + |) in M.pure Constant.None_ )) |) in - let value := - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.assign (| - M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) - |) in + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "BranchNode" |), diff --git a/CoqOfPython/ethereum/constantinople/utils/__init__.v b/CoqOfPython/ethereum/constantinople/utils/__init__.v index 1baedea..e5396b1 100644 --- a/CoqOfPython/ethereum/constantinople/utils/__init__.v +++ b/CoqOfPython/ethereum/constantinople/utils/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.constantinople.utils.__init__". Definition expr_1 : Value.t := Constant.str " diff --git a/CoqOfPython/ethereum/constantinople/utils/address.v b/CoqOfPython/ethereum/constantinople/utils/address.v index 8240fa7..a2749d9 100644 --- a/CoqOfPython/ethereum/constantinople/utils/address.v +++ b/CoqOfPython/ethereum/constantinople/utils/address.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.constantinople.utils.address". Definition expr_1 : Value.t := Constant.str " @@ -18,33 +18,23 @@ Address specific functions used in this constantinople version of specification. ". -Require typing. -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". +Axiom typing_imports : + AreImported globals "typing" [ "Union" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes32"; "Uint" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_left_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. -Require ethereum.constantinople.fork_types. -Axiom ethereum_constantinople_fork_types_Address : - IsGlobalAlias globals ethereum.constantinople.fork_types.globals "Address". +Axiom ethereum_constantinople_fork_types_imports : + AreImported globals "ethereum.constantinople.fork_types" [ "Address" ]. Definition to_address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -66,11 +56,16 @@ Definition to_address : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "Address" |), make_list [ - M.get_subscript (| M.call (| - M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), - make_list [], - make_dict [] - |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) + M.slice (| + M.call (| + M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), + UnOp.sub (| Constant.int 20 |), + Constant.None_, + Constant.None_ + |) ], make_dict [] |) @@ -114,7 +109,12 @@ Definition compute_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "computed_address" |), + UnOp.sub (| Constant.int 20 |), + Constant.None_, + Constant.None_ + |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -182,7 +182,12 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "computed_address" |), + UnOp.sub (| Constant.int 20 |), + Constant.None_, + Constant.None_ + |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/constantinople/utils/hexadecimal.v b/CoqOfPython/ethereum/constantinople/utils/hexadecimal.v index 550399b..e060a84 100644 --- a/CoqOfPython/ethereum/constantinople/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/constantinople/utils/hexadecimal.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.constantinople.utils.hexadecimal". Definition expr_1 : Value.t := Constant.str " @@ -18,17 +18,11 @@ Hexadecimal utility functions used in this specification, specific to Constantinople types. ". -Require ethereum.utils.hexadecimal. -Axiom ethereum_utils_hexadecimal_remove_hex_prefix : - IsGlobalAlias globals ethereum.utils.hexadecimal.globals "remove_hex_prefix". - -Require ethereum.constantinople.fork_types. -Axiom ethereum_constantinople_fork_types_Address : - IsGlobalAlias globals ethereum.constantinople.fork_types.globals "Address". -Axiom ethereum_constantinople_fork_types_Bloom : - IsGlobalAlias globals ethereum.constantinople.fork_types.globals "Bloom". -Axiom ethereum_constantinople_fork_types_Root : - IsGlobalAlias globals ethereum.constantinople.fork_types.globals "Root". +Axiom ethereum_utils_hexadecimal_imports : + AreImported globals "ethereum.utils.hexadecimal" [ "remove_hex_prefix" ]. + +Axiom ethereum_constantinople_fork_types_imports : + AreImported globals "ethereum.constantinople.fork_types" [ "Address"; "Bloom"; "Root" ]. Definition hex_to_root : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/constantinople/utils/message.v b/CoqOfPython/ethereum/constantinople/utils/message.v index d79ff6e..ce63cad 100644 --- a/CoqOfPython/ethereum/constantinople/utils/message.v +++ b/CoqOfPython/ethereum/constantinople/utils/message.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.constantinople.utils.message". Definition expr_1 : Value.t := Constant.str " @@ -18,39 +18,23 @@ Message specific functions used in this constantinople version of specification. ". -Require typing. -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". +Axiom typing_imports : + AreImported globals "typing" [ "Optional"; "Union" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint" ]. -Require ethereum.constantinople.fork_types. -Axiom ethereum_constantinople_fork_types_Address : - IsGlobalAlias globals ethereum.constantinople.fork_types.globals "Address". +Axiom ethereum_constantinople_fork_types_imports : + AreImported globals "ethereum.constantinople.fork_types" [ "Address" ]. -Require ethereum.constantinople.state. -Axiom ethereum_constantinople_state_get_account : - IsGlobalAlias globals ethereum.constantinople.state.globals "get_account". +Axiom ethereum_constantinople_state_imports : + AreImported globals "ethereum.constantinople.state" [ "get_account" ]. -Require ethereum.constantinople.vm.__init__. -Axiom ethereum_constantinople_vm___init___Environment : - IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Environment". -Axiom ethereum_constantinople_vm___init___Message : - IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Message". +Axiom ethereum_constantinople_vm_imports : + AreImported globals "ethereum.constantinople.vm" [ "Environment"; "Message" ]. -Require ethereum.constantinople.utils.address. -Axiom ethereum_constantinople_utils_address_compute_contract_address : - IsGlobalAlias globals ethereum.constantinople.utils.address.globals "compute_contract_address". +Axiom ethereum_constantinople_utils_address_imports : + AreImported globals "ethereum.constantinople.utils.address" [ "compute_contract_address" ]. Definition prepare_message : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -183,7 +167,7 @@ Definition prepare_message : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "Target must be address or empty bytes" diff --git a/CoqOfPython/ethereum/constantinople/vm/__init__.v b/CoqOfPython/ethereum/constantinople/vm/__init__.v index 08b3c32..159f09c 100644 --- a/CoqOfPython/ethereum/constantinople/vm/__init__.v +++ b/CoqOfPython/ethereum/constantinople/vm/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.constantinople.vm.__init__". Definition expr_1 : Value.t := Constant.str " @@ -18,53 +18,29 @@ The abstract computer which runs the code stored in an `.fork_types.Account`. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". - -Require ethereum.constantinople.blocks. -Axiom ethereum_constantinople_blocks_Log : - IsGlobalAlias globals ethereum.constantinople.blocks.globals "Log". - -Require ethereum.constantinople.fork_types. -Axiom ethereum_constantinople_fork_types_Address : - IsGlobalAlias globals ethereum.constantinople.fork_types.globals "Address". - -Require ethereum.constantinople.state. -Axiom ethereum_constantinople_state_State : - IsGlobalAlias globals ethereum.constantinople.state.globals "State". -Axiom ethereum_constantinople_state_account_exists_and_is_empty : - IsGlobalAlias globals ethereum.constantinople.state.globals "account_exists_and_is_empty". - -Require ethereum.constantinople.vm.precompiled_contracts.__init__. -Axiom ethereum_constantinople_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : - IsGlobalAlias globals ethereum.constantinople.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple"; "Union" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. + +Axiom ethereum_constantinople_blocks_imports : + AreImported globals "ethereum.constantinople.blocks" [ "Log" ]. + +Axiom ethereum_constantinople_fork_types_imports : + AreImported globals "ethereum.constantinople.fork_types" [ "Address" ]. + +Axiom ethereum_constantinople_state_imports : + AreImported globals "ethereum.constantinople.state" [ "State"; "account_exists_and_is_empty" ]. + +Axiom ethereum_constantinople_vm_precompiled_contracts_imports : + AreImported globals "ethereum.constantinople.vm.precompiled_contracts" [ "RIPEMD160_ADDRESS" ]. Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] @@ -185,7 +161,7 @@ Definition incorporate_child_on_error : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "RIPEMD160_ADDRESS" |), M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) |), diff --git a/CoqOfPython/ethereum/constantinople/vm/exceptions.v b/CoqOfPython/ethereum/constantinople/vm/exceptions.v index 23d00db..9a8dc42 100644 --- a/CoqOfPython/ethereum/constantinople/vm/exceptions.v +++ b/CoqOfPython/ethereum/constantinople/vm/exceptions.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.constantinople.vm.exceptions". Definition expr_1 : Value.t := Constant.str " @@ -17,9 +17,8 @@ Introduction Exceptions which cause the EVM to halt exceptionally. ". -Require ethereum.exceptions. -Axiom ethereum_exceptions_EthereumException : - IsGlobalAlias globals ethereum.exceptions.globals "EthereumException". +Axiom ethereum_exceptions_imports : + AreImported globals "ethereum.exceptions" [ "EthereumException" ]. Definition ExceptionalHalt : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/constantinople/vm/gas.v b/CoqOfPython/ethereum/constantinople/vm/gas.v index c7efec9..3ad8be6 100644 --- a/CoqOfPython/ethereum/constantinople/vm/gas.v +++ b/CoqOfPython/ethereum/constantinople/vm/gas.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.constantinople.vm.gas". Definition expr_1 : Value.t := Constant.str " @@ -17,39 +17,26 @@ Introduction EVM gas constants and calculators. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Tuple" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. -Require ethereum.trace. -Axiom ethereum_trace_GasAndRefund : - IsGlobalAlias globals ethereum.trace.globals "GasAndRefund". -Axiom ethereum_trace_evm_trace : - IsGlobalAlias globals ethereum.trace.globals "evm_trace". +Axiom ethereum_trace_imports : + AreImported globals "ethereum.trace" [ "GasAndRefund"; "evm_trace" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.constantinople.vm.__init__. -Axiom ethereum_constantinople_vm___init___Evm : - IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Evm". +Axiom ethereum_constantinople_vm_imports : + AreImported globals "ethereum.constantinople.vm" [ "Evm" ]. -Require ethereum.constantinople.vm.exceptions. -Axiom ethereum_constantinople_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.constantinople.vm.exceptions.globals "OutOfGasError". +Axiom ethereum_constantinople_vm_exceptions_imports : + AreImported globals "ethereum.constantinople.vm.exceptions" [ "OutOfGasError" ]. Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -518,7 +505,7 @@ Definition charge_gas : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -635,105 +622,114 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := ], make_dict [] |) in - For make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ] in M.get_name (| globals, "extensions" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "size" |), - Constant.int 0 - |), - (* then *) + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ], + M.get_name (| globals, "extensions" |), ltac:(M.monadic ( - let _ := M.continue (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let before_size := - M.call (| - M.get_name (| globals, "ceil32" |), - make_list [ - M.get_name (| globals, "current_size" |) - ], - make_dict [] - |) in - let after_size := - M.call (| - M.get_name (| globals, "ceil32" |), - make_list [ - BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "size" |), + Constant.int 0 |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.lt_e (| - M.get_name (| globals, "after_size" |), - M.get_name (| globals, "before_size" |) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.continue (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let size_to_extend := BinOp.add - BinOp.sub (| + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let before_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "current_size" |) + ], + make_dict [] + |) in + let after_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let size_to_extend := BinOp.add + BinOp.sub (| M.get_name (| globals, "after_size" |), M.get_name (| globals, "before_size" |) |) - BinOp.sub (| + BinOp.sub (| M.get_name (| globals, "after_size" |), M.get_name (| globals, "before_size" |) |) in - let already_paid := - M.call (| - M.get_name (| globals, "calculate_memory_gas_cost" |), - make_list [ - M.get_name (| globals, "before_size" |) - ], - make_dict [] - |) in - let total_cost := - M.call (| - M.get_name (| globals, "calculate_memory_gas_cost" |), - make_list [ - M.get_name (| globals, "after_size" |) - ], - make_dict [] - |) in - let to_be_paid := BinOp.add - BinOp.sub (| + let already_paid := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "before_size" |) + ], + make_dict [] + |) in + let total_cost := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "after_size" |) + ], + make_dict [] + |) in + let to_be_paid := BinOp.add + BinOp.sub (| M.get_name (| globals, "total_cost" |), M.get_name (| globals, "already_paid" |) |) - BinOp.sub (| + BinOp.sub (| M.get_name (| globals, "total_cost" |), M.get_name (| globals, "already_paid" |) |) in - let current_size := - M.get_name (| globals, "after_size" |) in - EndFor. + let current_size := + M.get_name (| globals, "after_size" |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ExtendMemory" |), diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/__init__.v b/CoqOfPython/ethereum/constantinople/vm/instructions/__init__.v index 2025bc9..ec360d8 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/__init__.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.constantinople.vm.instructions.__init__". Definition expr_1 : Value.t := Constant.str " @@ -20,59 +20,44 @@ implementations. (* At top_level_stmt: unsupported node type: Import *) -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict" ]. -Require ethereum.constantinople.vm.instructions.__init__. -Axiom ethereum_constantinople_vm_instructions___init___arithmetic : - IsGlobalAlias globals ethereum.constantinople.vm.instructions.__init__.globals "arithmetic". +Axiom ethereum_constantinople_vm_instructions_imports : + AreImported globals "ethereum.constantinople.vm.instructions" [ "arithmetic" ]. -Require ethereum.constantinople.vm.instructions.__init__. -Axiom ethereum_constantinople_vm_instructions___init___bitwise : - IsGlobalAlias globals ethereum.constantinople.vm.instructions.__init__.globals "bitwise". +Axiom ethereum_constantinople_vm_instructions_imports : + AreImported globals "ethereum.constantinople.vm.instructions" [ "bitwise" ]. -Require ethereum.constantinople.vm.instructions.__init__. -Axiom ethereum_constantinople_vm_instructions___init___block : - IsGlobalAlias globals ethereum.constantinople.vm.instructions.__init__.globals "block". +Axiom ethereum_constantinople_vm_instructions_imports : + AreImported globals "ethereum.constantinople.vm.instructions" [ "block" ]. -Require ethereum.constantinople.vm.instructions.__init__. -Axiom ethereum_constantinople_vm_instructions___init___comparison : - IsGlobalAlias globals ethereum.constantinople.vm.instructions.__init__.globals "comparison". +Axiom ethereum_constantinople_vm_instructions_imports : + AreImported globals "ethereum.constantinople.vm.instructions" [ "comparison" ]. -Require ethereum.constantinople.vm.instructions.__init__. -Axiom ethereum_constantinople_vm_instructions___init___control_flow : - IsGlobalAlias globals ethereum.constantinople.vm.instructions.__init__.globals "control_flow". +Axiom ethereum_constantinople_vm_instructions_imports : + AreImported globals "ethereum.constantinople.vm.instructions" [ "control_flow" ]. -Require ethereum.constantinople.vm.instructions.__init__. -Axiom ethereum_constantinople_vm_instructions___init___environment : - IsGlobalAlias globals ethereum.constantinople.vm.instructions.__init__.globals "environment". +Axiom ethereum_constantinople_vm_instructions_imports : + AreImported globals "ethereum.constantinople.vm.instructions" [ "environment" ]. -Require ethereum.constantinople.vm.instructions.__init__. -Axiom ethereum_constantinople_vm_instructions___init___keccak : - IsGlobalAlias globals ethereum.constantinople.vm.instructions.__init__.globals "keccak". +Axiom ethereum_constantinople_vm_instructions_imports : + AreImported globals "ethereum.constantinople.vm.instructions" [ "keccak" ]. -Require ethereum.constantinople.vm.instructions.__init__. -Axiom ethereum_constantinople_vm_instructions___init___log : - IsGlobalAlias globals ethereum.constantinople.vm.instructions.__init__.globals "log". +Axiom ethereum_constantinople_vm_instructions_imports : + AreImported globals "ethereum.constantinople.vm.instructions" [ "log" ]. -Require ethereum.constantinople.vm.instructions.__init__. -Axiom ethereum_constantinople_vm_instructions___init___memory : - IsGlobalAlias globals ethereum.constantinople.vm.instructions.__init__.globals "memory". +Axiom ethereum_constantinople_vm_instructions_imports : + AreImported globals "ethereum.constantinople.vm.instructions" [ "memory" ]. -Require ethereum.constantinople.vm.instructions.__init__. -Axiom ethereum_constantinople_vm_instructions___init___stack : - IsGlobalAlias globals ethereum.constantinople.vm.instructions.__init__.globals "stack". +Axiom ethereum_constantinople_vm_instructions_imports : + AreImported globals "ethereum.constantinople.vm.instructions" [ "stack" ]. -Require ethereum.constantinople.vm.instructions.__init__. -Axiom ethereum_constantinople_vm_instructions___init___storage : - IsGlobalAlias globals ethereum.constantinople.vm.instructions.__init__.globals "storage". +Axiom ethereum_constantinople_vm_instructions_imports : + AreImported globals "ethereum.constantinople.vm.instructions" [ "storage" ]. -Require ethereum.constantinople.vm.instructions.__init__. -Axiom ethereum_constantinople_vm_instructions___init___system : - IsGlobalAlias globals ethereum.constantinople.vm.instructions.__init__.globals "system". +Axiom ethereum_constantinople_vm_instructions_imports : + AreImported globals "ethereum.constantinople.vm.instructions" [ "system" ]. Definition Ops : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/constantinople/vm/instructions/arithmetic.v index 0ff304a..d8fc85c 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/arithmetic.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.constantinople.vm.instructions.arithmetic". Definition expr_1 : Value.t := Constant.str " @@ -17,43 +17,20 @@ Introduction Implementations of the EVM Arithmetic instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U255_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U255_CEIL_VALUE". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_U256_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U255_CEIL_VALUE"; "U256"; "U256_CEIL_VALUE"; "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_get_sign : - IsGlobalAlias globals ethereum.utils.numeric.globals "get_sign". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "get_sign" ]. -Require ethereum.constantinople.vm.__init__. -Axiom ethereum_constantinople_vm___init___Evm : - IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Evm". +Axiom ethereum_constantinople_vm_imports : + AreImported globals "ethereum.constantinople.vm" [ "Evm" ]. -Require ethereum.constantinople.vm.gas. -Axiom ethereum_constantinople_vm_gas_GAS_EXPONENTIATION : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_EXPONENTIATION". -Axiom ethereum_constantinople_vm_gas_GAS_EXPONENTIATION_PER_BYTE : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_EXPONENTIATION_PER_BYTE". -Axiom ethereum_constantinople_vm_gas_GAS_LOW : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_LOW". -Axiom ethereum_constantinople_vm_gas_GAS_MID : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_MID". -Axiom ethereum_constantinople_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_constantinople_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "charge_gas". +Axiom ethereum_constantinople_vm_gas_imports : + AreImported globals "ethereum.constantinople.vm.gas" [ "GAS_EXPONENTIATION"; "GAS_EXPONENTIATION_PER_BYTE"; "GAS_LOW"; "GAS_MID"; "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.constantinople.vm.stack. -Axiom ethereum_constantinople_vm_stack_pop : - IsGlobalAlias globals ethereum.constantinople.vm.stack.globals "pop". -Axiom ethereum_constantinople_vm_stack_push : - IsGlobalAlias globals ethereum.constantinople.vm.stack.globals "push". +Axiom ethereum_constantinople_vm_stack_imports : + AreImported globals "ethereum.constantinople.vm.stack" [ "pop"; "push" ]. Definition add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -1030,19 +1007,27 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let value_bytes := - M.get_subscript (| M.get_name (| globals, "value_bytes" |), M.slice (| BinOp.sub (| - Constant.int 31, - M.call (| - M.get_name (| globals, "int" |), - make_list [ - M.get_name (| globals, "byte_num" |) - ], - make_dict [] - |) - |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "value_bytes" |), + BinOp.sub (| + Constant.int 31, + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "byte_num" |) + ], + make_dict [] + |) + |), + Constant.None_, + Constant.None_ + |) in let sign_bit := BinOp.r_shift (| - M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), + M.get_subscript (| + M.get_name (| globals, "value_bytes" |), + Constant.int 0 + |), Constant.int 7 |) in let _ := diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/bitwise.v b/CoqOfPython/ethereum/constantinople/vm/instructions/bitwise.v index 46db25a..ea48581 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/bitwise.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.constantinople.vm.instructions.bitwise". Definition expr_1 : Value.t := Constant.str " @@ -17,27 +17,17 @@ Introduction Implementations of the EVM bitwise instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_U256_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "U256_CEIL_VALUE" ]. -Require ethereum.constantinople.vm.__init__. -Axiom ethereum_constantinople_vm___init___Evm : - IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Evm". +Axiom ethereum_constantinople_vm_imports : + AreImported globals "ethereum.constantinople.vm" [ "Evm" ]. -Require ethereum.constantinople.vm.gas. -Axiom ethereum_constantinople_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_constantinople_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "charge_gas". +Axiom ethereum_constantinople_vm_gas_imports : + AreImported globals "ethereum.constantinople.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.constantinople.vm.stack. -Axiom ethereum_constantinople_vm_stack_pop : - IsGlobalAlias globals ethereum.constantinople.vm.stack.globals "pop". -Axiom ethereum_constantinople_vm_stack_push : - IsGlobalAlias globals ethereum.constantinople.vm.stack.globals "push". +Axiom ethereum_constantinople_vm_stack_imports : + AreImported globals "ethereum.constantinople.vm.stack" [ "pop"; "push" ]. Definition bitwise_and : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/block.v b/CoqOfPython/ethereum/constantinople/vm/instructions/block.v index e83afd2..bfafb33 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/block.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/block.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.constantinople.vm.instructions.block". Definition expr_1 : Value.t := Constant.str " @@ -17,27 +17,17 @@ Introduction Implementations of the EVM block instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.constantinople.vm.__init__. -Axiom ethereum_constantinople_vm___init___Evm : - IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Evm". +Axiom ethereum_constantinople_vm_imports : + AreImported globals "ethereum.constantinople.vm" [ "Evm" ]. -Require ethereum.constantinople.vm.gas. -Axiom ethereum_constantinople_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_BASE". -Axiom ethereum_constantinople_vm_gas_GAS_BLOCK_HASH : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_BLOCK_HASH". -Axiom ethereum_constantinople_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "charge_gas". +Axiom ethereum_constantinople_vm_gas_imports : + AreImported globals "ethereum.constantinople.vm.gas" [ "GAS_BASE"; "GAS_BLOCK_HASH"; "charge_gas" ]. -Require ethereum.constantinople.vm.stack. -Axiom ethereum_constantinople_vm_stack_pop : - IsGlobalAlias globals ethereum.constantinople.vm.stack.globals "pop". -Axiom ethereum_constantinople_vm_stack_push : - IsGlobalAlias globals ethereum.constantinople.vm.stack.globals "push". +Axiom ethereum_constantinople_vm_stack_imports : + AreImported globals "ethereum.constantinople.vm.stack" [ "pop"; "push" ]. Definition block_hash : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -94,10 +84,13 @@ Definition block_hash : Value.t -> Value.t -> M := (* else *) )), ltac:(M.monadic ( let hash := - M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), - M.get_name (| globals, "block_number" |) - |) |) |) in + M.get_subscript (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), + UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + M.get_name (| globals, "block_number" |) + |) |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/comparison.v b/CoqOfPython/ethereum/constantinople/vm/instructions/comparison.v index ed8e781..e788189 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/comparison.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.constantinople.vm.instructions.comparison". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementations of the EVM Comparison instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.constantinople.vm.__init__. -Axiom ethereum_constantinople_vm___init___Evm : - IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Evm". +Axiom ethereum_constantinople_vm_imports : + AreImported globals "ethereum.constantinople.vm" [ "Evm" ]. -Require ethereum.constantinople.vm.gas. -Axiom ethereum_constantinople_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_constantinople_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "charge_gas". +Axiom ethereum_constantinople_vm_gas_imports : + AreImported globals "ethereum.constantinople.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.constantinople.vm.stack. -Axiom ethereum_constantinople_vm_stack_pop : - IsGlobalAlias globals ethereum.constantinople.vm.stack.globals "pop". -Axiom ethereum_constantinople_vm_stack_push : - IsGlobalAlias globals ethereum.constantinople.vm.stack.globals "push". +Axiom ethereum_constantinople_vm_stack_imports : + AreImported globals "ethereum.constantinople.vm.stack" [ "pop"; "push" ]. Definition less_than : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/control_flow.v b/CoqOfPython/ethereum/constantinople/vm/instructions/control_flow.v index cae7d6b..49a0558 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/control_flow.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.constantinople.vm.instructions.control_flow". Definition expr_1 : Value.t := Constant.str " @@ -17,37 +17,20 @@ Introduction Implementations of the EVM control flow instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. -Require ethereum.constantinople.vm.gas. -Axiom ethereum_constantinople_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_BASE". -Axiom ethereum_constantinople_vm_gas_GAS_HIGH : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_HIGH". -Axiom ethereum_constantinople_vm_gas_GAS_JUMPDEST : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_JUMPDEST". -Axiom ethereum_constantinople_vm_gas_GAS_MID : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_MID". -Axiom ethereum_constantinople_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "charge_gas". +Axiom ethereum_constantinople_vm_gas_imports : + AreImported globals "ethereum.constantinople.vm.gas" [ "GAS_BASE"; "GAS_HIGH"; "GAS_JUMPDEST"; "GAS_MID"; "charge_gas" ]. -Require ethereum.constantinople.vm.__init__. -Axiom ethereum_constantinople_vm___init___Evm : - IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Evm". +Axiom ethereum_constantinople_vm_imports : + AreImported globals "ethereum.constantinople.vm" [ "Evm" ]. -Require ethereum.constantinople.vm.exceptions. -Axiom ethereum_constantinople_vm_exceptions_InvalidJumpDestError : - IsGlobalAlias globals ethereum.constantinople.vm.exceptions.globals "InvalidJumpDestError". +Axiom ethereum_constantinople_vm_exceptions_imports : + AreImported globals "ethereum.constantinople.vm.exceptions" [ "InvalidJumpDestError" ]. -Require ethereum.constantinople.vm.stack. -Axiom ethereum_constantinople_vm_stack_pop : - IsGlobalAlias globals ethereum.constantinople.vm.stack.globals "pop". -Axiom ethereum_constantinople_vm_stack_push : - IsGlobalAlias globals ethereum.constantinople.vm.stack.globals "push". +Axiom ethereum_constantinople_vm_stack_imports : + AreImported globals "ethereum.constantinople.vm.stack" [ "pop"; "push" ]. Definition stop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -117,7 +100,7 @@ Definition jump : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "InvalidJumpDestError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -205,7 +188,7 @@ Definition jumpi : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "InvalidJumpDestError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/environment.v b/CoqOfPython/ethereum/constantinople/vm/instructions/environment.v index 4a58239..9c81aed 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/environment.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.constantinople.vm.instructions.environment". Definition expr_1 : Value.t := Constant.str " @@ -17,75 +17,41 @@ Introduction Implementations of the EVM environment related instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.constantinople.fork_types. -Axiom ethereum_constantinople_fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals ethereum.constantinople.fork_types.globals "EMPTY_ACCOUNT". +Axiom ethereum_constantinople_fork_types_imports : + AreImported globals "ethereum.constantinople.fork_types" [ "EMPTY_ACCOUNT" ]. -Require ethereum.constantinople.state. -Axiom ethereum_constantinople_state_get_account : - IsGlobalAlias globals ethereum.constantinople.state.globals "get_account". +Axiom ethereum_constantinople_state_imports : + AreImported globals "ethereum.constantinople.state" [ "get_account" ]. -Require ethereum.constantinople.utils.address. -Axiom ethereum_constantinople_utils_address_to_address : - IsGlobalAlias globals ethereum.constantinople.utils.address.globals "to_address". +Axiom ethereum_constantinople_utils_address_imports : + AreImported globals "ethereum.constantinople.utils.address" [ "to_address" ]. -Require ethereum.constantinople.vm.memory. -Axiom ethereum_constantinople_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.constantinople.vm.memory.globals "buffer_read". -Axiom ethereum_constantinople_vm_memory_memory_write : - IsGlobalAlias globals ethereum.constantinople.vm.memory.globals "memory_write". +Axiom ethereum_constantinople_vm_memory_imports : + AreImported globals "ethereum.constantinople.vm.memory" [ "buffer_read"; "memory_write" ]. -Require ethereum.constantinople.vm.__init__. -Axiom ethereum_constantinople_vm___init___Evm : - IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Evm". +Axiom ethereum_constantinople_vm_imports : + AreImported globals "ethereum.constantinople.vm" [ "Evm" ]. -Require ethereum.constantinople.vm.exceptions. -Axiom ethereum_constantinople_vm_exceptions_OutOfBoundsRead : - IsGlobalAlias globals ethereum.constantinople.vm.exceptions.globals "OutOfBoundsRead". +Axiom ethereum_constantinople_vm_exceptions_imports : + AreImported globals "ethereum.constantinople.vm.exceptions" [ "OutOfBoundsRead" ]. -Require ethereum.constantinople.vm.gas. -Axiom ethereum_constantinople_vm_gas_GAS_BALANCE : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_BALANCE". -Axiom ethereum_constantinople_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_BASE". -Axiom ethereum_constantinople_vm_gas_GAS_CODE_HASH : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_CODE_HASH". -Axiom ethereum_constantinople_vm_gas_GAS_COPY : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_COPY". -Axiom ethereum_constantinople_vm_gas_GAS_EXTERNAL : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_EXTERNAL". -Axiom ethereum_constantinople_vm_gas_GAS_RETURN_DATA_COPY : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_RETURN_DATA_COPY". -Axiom ethereum_constantinople_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_constantinople_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_constantinople_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "charge_gas". +Axiom ethereum_constantinople_vm_gas_imports : + AreImported globals "ethereum.constantinople.vm.gas" [ "GAS_BALANCE"; "GAS_BASE"; "GAS_CODE_HASH"; "GAS_COPY"; "GAS_EXTERNAL"; "GAS_RETURN_DATA_COPY"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. -Require ethereum.constantinople.vm.stack. -Axiom ethereum_constantinople_vm_stack_pop : - IsGlobalAlias globals ethereum.constantinople.vm.stack.globals "pop". -Axiom ethereum_constantinople_vm_stack_push : - IsGlobalAlias globals ethereum.constantinople.vm.stack.globals "push". +Axiom ethereum_constantinople_vm_stack_imports : + AreImported globals "ethereum.constantinople.vm.stack" [ "pop"; "push" ]. Definition address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -1132,10 +1098,15 @@ Definition returndatacopy : Value.t -> Value.t -> M := |) |) in let value := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.slice (| M.get_name (| globals, "return_data_start_position" |), BinOp.add (| + M.slice (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |), - M.get_name (| globals, "size" |) - |) |) |) in + BinOp.add (| + M.get_name (| globals, "return_data_start_position" |), + M.get_name (| globals, "size" |) + |), + Constant.None_ + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/keccak.v b/CoqOfPython/ethereum/constantinople/vm/instructions/keccak.v index 50fcd51..db3696a 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/keccak.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.constantinople.vm.instructions.keccak". Definition expr_1 : Value.t := Constant.str " @@ -17,43 +17,26 @@ Introduction Implementations of the EVM keccak instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". - -Require ethereum.constantinople.vm.__init__. -Axiom ethereum_constantinople_vm___init___Evm : - IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Evm". - -Require ethereum.constantinople.vm.gas. -Axiom ethereum_constantinople_vm_gas_GAS_KECCAK256 : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_KECCAK256". -Axiom ethereum_constantinople_vm_gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_KECCAK256_WORD". -Axiom ethereum_constantinople_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_constantinople_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "charge_gas". - -Require ethereum.constantinople.vm.memory. -Axiom ethereum_constantinople_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.constantinople.vm.memory.globals "memory_read_bytes". - -Require ethereum.constantinople.vm.stack. -Axiom ethereum_constantinople_vm_stack_pop : - IsGlobalAlias globals ethereum.constantinople.vm.stack.globals "pop". -Axiom ethereum_constantinople_vm_stack_push : - IsGlobalAlias globals ethereum.constantinople.vm.stack.globals "push". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. + +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. + +Axiom ethereum_constantinople_vm_imports : + AreImported globals "ethereum.constantinople.vm" [ "Evm" ]. + +Axiom ethereum_constantinople_vm_gas_imports : + AreImported globals "ethereum.constantinople.vm.gas" [ "GAS_KECCAK256"; "GAS_KECCAK256_WORD"; "calculate_gas_extend_memory"; "charge_gas" ]. + +Axiom ethereum_constantinople_vm_memory_imports : + AreImported globals "ethereum.constantinople.vm.memory" [ "memory_read_bytes" ]. + +Axiom ethereum_constantinople_vm_stack_imports : + AreImported globals "ethereum.constantinople.vm.stack" [ "pop"; "push" ]. Definition keccak : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/log.v b/CoqOfPython/ethereum/constantinople/vm/instructions/log.v index cc79a76..62c5f01 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/log.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/log.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.constantinople.vm.instructions.log". Definition expr_1 : Value.t := Constant.str " @@ -17,49 +17,32 @@ Introduction Implementations of the EVM logging instructions. ". -Require functools. -Axiom functools_partial : - IsGlobalAlias globals functools.globals "partial". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.constantinople.blocks. -Axiom ethereum_constantinople_blocks_Log : - IsGlobalAlias globals ethereum.constantinople.blocks.globals "Log". - -Require ethereum.constantinople.vm.__init__. -Axiom ethereum_constantinople_vm___init___Evm : - IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Evm". - -Require ethereum.constantinople.vm.exceptions. -Axiom ethereum_constantinople_vm_exceptions_WriteInStaticContext : - IsGlobalAlias globals ethereum.constantinople.vm.exceptions.globals "WriteInStaticContext". - -Require ethereum.constantinople.vm.gas. -Axiom ethereum_constantinople_vm_gas_GAS_LOG : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_LOG". -Axiom ethereum_constantinople_vm_gas_GAS_LOG_DATA : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_LOG_DATA". -Axiom ethereum_constantinople_vm_gas_GAS_LOG_TOPIC : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_LOG_TOPIC". -Axiom ethereum_constantinople_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_constantinople_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "charge_gas". - -Require ethereum.constantinople.vm.memory. -Axiom ethereum_constantinople_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.constantinople.vm.memory.globals "memory_read_bytes". - -Require ethereum.constantinople.vm.stack. -Axiom ethereum_constantinople_vm_stack_pop : - IsGlobalAlias globals ethereum.constantinople.vm.stack.globals "pop". +Axiom functools_imports : + AreImported globals "functools" [ "partial" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_constantinople_blocks_imports : + AreImported globals "ethereum.constantinople.blocks" [ "Log" ]. + +Axiom ethereum_constantinople_vm_imports : + AreImported globals "ethereum.constantinople.vm" [ "Evm" ]. + +Axiom ethereum_constantinople_vm_exceptions_imports : + AreImported globals "ethereum.constantinople.vm.exceptions" [ "WriteInStaticContext" ]. + +Axiom ethereum_constantinople_vm_gas_imports : + AreImported globals "ethereum.constantinople.vm.gas" [ "GAS_LOG"; "GAS_LOG_DATA"; "GAS_LOG_TOPIC"; "calculate_gas_extend_memory"; "charge_gas" ]. + +Axiom ethereum_constantinople_vm_memory_imports : + AreImported globals "ethereum.constantinople.vm.memory" [ "memory_read_bytes" ]. + +Axiom ethereum_constantinople_vm_stack_imports : + AreImported globals "ethereum.constantinople.vm.stack" [ "pop" ]. Definition log_n : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -96,33 +79,42 @@ Definition log_n : Value.t -> Value.t -> M := |) in let topics := make_list [] in - For M.get_name (| globals, "_" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - M.get_name (| globals, "num_topics" |) - ], - make_dict [] - |) do - let topic := + let _ := + M.for_ (| + M.get_name (| globals, "_" |), M.call (| - M.get_field (| M.call (| - M.get_name (| globals, "pop" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] - |), "to_be_bytes32" |), - make_list [], - make_dict [] - |) in - let _ := M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "num_topics" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let topic := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| M.get_field (| M.get_name (| globals, "topics" |), "append" |), make_list [ M.get_name (| globals, "topic" |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let extend_memory := M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/memory.v b/CoqOfPython/ethereum/constantinople/vm/instructions/memory.v index b27af6c..6465028 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/memory.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.constantinople.vm.instructions.memory". Definition expr_1 : Value.t := Constant.str " @@ -17,37 +17,20 @@ Introduction Implementations of the EVM Memory instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes" ]. -Require ethereum.constantinople.vm.__init__. -Axiom ethereum_constantinople_vm___init___Evm : - IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Evm". +Axiom ethereum_constantinople_vm_imports : + AreImported globals "ethereum.constantinople.vm" [ "Evm" ]. -Require ethereum.constantinople.vm.gas. -Axiom ethereum_constantinople_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_BASE". -Axiom ethereum_constantinople_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_constantinople_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_constantinople_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "charge_gas". +Axiom ethereum_constantinople_vm_gas_imports : + AreImported globals "ethereum.constantinople.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. -Require ethereum.constantinople.vm.memory. -Axiom ethereum_constantinople_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.constantinople.vm.memory.globals "memory_read_bytes". -Axiom ethereum_constantinople_vm_memory_memory_write : - IsGlobalAlias globals ethereum.constantinople.vm.memory.globals "memory_write". +Axiom ethereum_constantinople_vm_memory_imports : + AreImported globals "ethereum.constantinople.vm.memory" [ "memory_read_bytes"; "memory_write" ]. -Require ethereum.constantinople.vm.stack. -Axiom ethereum_constantinople_vm_stack_pop : - IsGlobalAlias globals ethereum.constantinople.vm.stack.globals "pop". -Axiom ethereum_constantinople_vm_stack_push : - IsGlobalAlias globals ethereum.constantinople.vm.stack.globals "push". +Axiom ethereum_constantinople_vm_stack_imports : + AreImported globals "ethereum.constantinople.vm.stack" [ "pop"; "push" ]. Definition mstore : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/stack.v b/CoqOfPython/ethereum/constantinople/vm/instructions/stack.v index 414f00c..3e6170d 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/stack.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.constantinople.vm.instructions.stack". Definition expr_1 : Value.t := Constant.str " @@ -17,39 +17,26 @@ Introduction Implementations of the EVM stack related instructions. ". -Require functools. -Axiom functools_partial : - IsGlobalAlias globals functools.globals "partial". +Axiom functools_imports : + AreImported globals "functools" [ "partial" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.constantinople.vm.__init__. -Axiom ethereum_constantinople_vm___init___Evm : - IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Evm". -Axiom ethereum_constantinople_vm___init___stack : - IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "stack". +Axiom ethereum_constantinople_vm_imports : + AreImported globals "ethereum.constantinople.vm" [ "Evm"; "stack" ]. -Require ethereum.constantinople.vm.exceptions. -Axiom ethereum_constantinople_vm_exceptions_StackUnderflowError : - IsGlobalAlias globals ethereum.constantinople.vm.exceptions.globals "StackUnderflowError". +Axiom ethereum_constantinople_vm_exceptions_imports : + AreImported globals "ethereum.constantinople.vm.exceptions" [ "StackUnderflowError" ]. -Require ethereum.constantinople.vm.gas. -Axiom ethereum_constantinople_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_BASE". -Axiom ethereum_constantinople_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_constantinople_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "charge_gas". +Axiom ethereum_constantinople_vm_gas_imports : + AreImported globals "ethereum.constantinople.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.constantinople.vm.memory. -Axiom ethereum_constantinople_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.constantinople.vm.memory.globals "buffer_read". +Axiom ethereum_constantinople_vm_memory_imports : + AreImported globals "ethereum.constantinople.vm.memory" [ "buffer_read" ]. Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -203,19 +190,22 @@ Definition dup_n : Value.t -> Value.t -> M := make_dict [] |) in let data_to_duplicate := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] + BinOp.sub (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), + Constant.int 1 |), - Constant.int 1 - |), - M.get_name (| globals, "item_number" |) - |) |) in + M.get_name (| globals, "item_number" |) + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "stack" |), "push" |), make_list [ @@ -278,14 +268,26 @@ Definition swap_n : Value.t -> Value.t -> M := make_dict [] |) in let _ := M.assign (| - make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| - UnOp.sub (| Constant.int 1 |), - M.get_name (| globals, "item_number" |) - |) |) ], - make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| - UnOp.sub (| Constant.int 1 |), - M.get_name (| globals, "item_number" |) - |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |) ] + make_tuple [ M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + UnOp.sub (| Constant.int 1 |) + |); M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) + |) ], + make_tuple [ M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) + |); M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + UnOp.sub (| Constant.int 1 |) + |) ] |) in let _ := M.assign_op (| BinOp.add, diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/storage.v b/CoqOfPython/ethereum/constantinople/vm/instructions/storage.v index 13af511..bbea490 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/storage.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.constantinople.vm.instructions.storage". Definition expr_1 : Value.t := Constant.str " @@ -17,41 +17,23 @@ Introduction Implementations of the EVM storage related instructions. ". -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.constantinople.state. -Axiom ethereum_constantinople_state_get_storage : - IsGlobalAlias globals ethereum.constantinople.state.globals "get_storage". -Axiom ethereum_constantinople_state_set_storage : - IsGlobalAlias globals ethereum.constantinople.state.globals "set_storage". - -Require ethereum.constantinople.vm.__init__. -Axiom ethereum_constantinople_vm___init___Evm : - IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Evm". - -Require ethereum.constantinople.vm.exceptions. -Axiom ethereum_constantinople_vm_exceptions_WriteInStaticContext : - IsGlobalAlias globals ethereum.constantinople.vm.exceptions.globals "WriteInStaticContext". - -Require ethereum.constantinople.vm.gas. -Axiom ethereum_constantinople_vm_gas_GAS_SLOAD : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_SLOAD". -Axiom ethereum_constantinople_vm_gas_GAS_STORAGE_CLEAR_REFUND : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_STORAGE_CLEAR_REFUND". -Axiom ethereum_constantinople_vm_gas_GAS_STORAGE_SET : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_STORAGE_SET". -Axiom ethereum_constantinople_vm_gas_GAS_STORAGE_UPDATE : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_STORAGE_UPDATE". -Axiom ethereum_constantinople_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "charge_gas". - -Require ethereum.constantinople.vm.stack. -Axiom ethereum_constantinople_vm_stack_pop : - IsGlobalAlias globals ethereum.constantinople.vm.stack.globals "pop". -Axiom ethereum_constantinople_vm_stack_push : - IsGlobalAlias globals ethereum.constantinople.vm.stack.globals "push". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_constantinople_state_imports : + AreImported globals "ethereum.constantinople.state" [ "get_storage"; "set_storage" ]. + +Axiom ethereum_constantinople_vm_imports : + AreImported globals "ethereum.constantinople.vm" [ "Evm" ]. + +Axiom ethereum_constantinople_vm_exceptions_imports : + AreImported globals "ethereum.constantinople.vm.exceptions" [ "WriteInStaticContext" ]. + +Axiom ethereum_constantinople_vm_gas_imports : + AreImported globals "ethereum.constantinople.vm.gas" [ "GAS_SLOAD"; "GAS_STORAGE_CLEAR_REFUND"; "GAS_STORAGE_SET"; "GAS_STORAGE_UPDATE"; "charge_gas" ]. + +Axiom ethereum_constantinople_vm_stack_imports : + AreImported globals "ethereum.constantinople.vm.stack" [ "pop"; "push" ]. Definition sload : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/system.v b/CoqOfPython/ethereum/constantinople/vm/instructions/system.v index caef466..08e6802 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/system.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/system.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.constantinople.vm.instructions.system". Definition expr_1 : Value.t := Constant.str " @@ -17,103 +17,38 @@ Introduction Implementations of the EVM system related instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.constantinople.fork_types. -Axiom ethereum_constantinople_fork_types_Address : - IsGlobalAlias globals ethereum.constantinople.fork_types.globals "Address". +Axiom ethereum_constantinople_fork_types_imports : + AreImported globals "ethereum.constantinople.fork_types" [ "Address" ]. -Require ethereum.constantinople.state. -Axiom ethereum_constantinople_state_account_exists_and_is_empty : - IsGlobalAlias globals ethereum.constantinople.state.globals "account_exists_and_is_empty". -Axiom ethereum_constantinople_state_account_has_code_or_nonce : - IsGlobalAlias globals ethereum.constantinople.state.globals "account_has_code_or_nonce". -Axiom ethereum_constantinople_state_get_account : - IsGlobalAlias globals ethereum.constantinople.state.globals "get_account". -Axiom ethereum_constantinople_state_increment_nonce : - IsGlobalAlias globals ethereum.constantinople.state.globals "increment_nonce". -Axiom ethereum_constantinople_state_is_account_alive : - IsGlobalAlias globals ethereum.constantinople.state.globals "is_account_alive". -Axiom ethereum_constantinople_state_set_account_balance : - IsGlobalAlias globals ethereum.constantinople.state.globals "set_account_balance". +Axiom ethereum_constantinople_state_imports : + AreImported globals "ethereum.constantinople.state" [ "account_exists_and_is_empty"; "account_has_code_or_nonce"; "get_account"; "increment_nonce"; "is_account_alive"; "set_account_balance" ]. -Require ethereum.constantinople.utils.address. -Axiom ethereum_constantinople_utils_address_compute_contract_address : - IsGlobalAlias globals ethereum.constantinople.utils.address.globals "compute_contract_address". -Axiom ethereum_constantinople_utils_address_compute_create2_contract_address : - IsGlobalAlias globals ethereum.constantinople.utils.address.globals "compute_create2_contract_address". -Axiom ethereum_constantinople_utils_address_to_address : - IsGlobalAlias globals ethereum.constantinople.utils.address.globals "to_address". +Axiom ethereum_constantinople_utils_address_imports : + AreImported globals "ethereum.constantinople.utils.address" [ "compute_contract_address"; "compute_create2_contract_address"; "to_address" ]. -Require ethereum.constantinople.vm.__init__. -Axiom ethereum_constantinople_vm___init___Evm : - IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Evm". -Axiom ethereum_constantinople_vm___init___Message : - IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Message". -Axiom ethereum_constantinople_vm___init___incorporate_child_on_error : - IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "incorporate_child_on_error". -Axiom ethereum_constantinople_vm___init___incorporate_child_on_success : - IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "incorporate_child_on_success". +Axiom ethereum_constantinople_vm_imports : + AreImported globals "ethereum.constantinople.vm" [ "Evm"; "Message"; "incorporate_child_on_error"; "incorporate_child_on_success" ]. -Require ethereum.constantinople.vm.exceptions. -Axiom ethereum_constantinople_vm_exceptions_Revert : - IsGlobalAlias globals ethereum.constantinople.vm.exceptions.globals "Revert". -Axiom ethereum_constantinople_vm_exceptions_WriteInStaticContext : - IsGlobalAlias globals ethereum.constantinople.vm.exceptions.globals "WriteInStaticContext". +Axiom ethereum_constantinople_vm_exceptions_imports : + AreImported globals "ethereum.constantinople.vm.exceptions" [ "Revert"; "WriteInStaticContext" ]. -Require ethereum.constantinople.vm.gas. -Axiom ethereum_constantinople_vm_gas_GAS_CALL : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_CALL". -Axiom ethereum_constantinople_vm_gas_GAS_CALL_VALUE : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_CALL_VALUE". -Axiom ethereum_constantinople_vm_gas_GAS_CREATE : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_CREATE". -Axiom ethereum_constantinople_vm_gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_KECCAK256_WORD". -Axiom ethereum_constantinople_vm_gas_GAS_NEW_ACCOUNT : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_NEW_ACCOUNT". -Axiom ethereum_constantinople_vm_gas_GAS_SELF_DESTRUCT : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_SELF_DESTRUCT". -Axiom ethereum_constantinople_vm_gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". -Axiom ethereum_constantinople_vm_gas_GAS_ZERO : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_ZERO". -Axiom ethereum_constantinople_vm_gas_REFUND_SELF_DESTRUCT : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "REFUND_SELF_DESTRUCT". -Axiom ethereum_constantinople_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_constantinople_vm_gas_calculate_message_call_gas : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "calculate_message_call_gas". -Axiom ethereum_constantinople_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "charge_gas". -Axiom ethereum_constantinople_vm_gas_max_message_call_gas : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "max_message_call_gas". +Axiom ethereum_constantinople_vm_gas_imports : + AreImported globals "ethereum.constantinople.vm.gas" [ "GAS_CALL"; "GAS_CALL_VALUE"; "GAS_CREATE"; "GAS_KECCAK256_WORD"; "GAS_NEW_ACCOUNT"; "GAS_SELF_DESTRUCT"; "GAS_SELF_DESTRUCT_NEW_ACCOUNT"; "GAS_ZERO"; "REFUND_SELF_DESTRUCT"; "calculate_gas_extend_memory"; "calculate_message_call_gas"; "charge_gas"; "max_message_call_gas" ]. -Require ethereum.constantinople.vm.memory. -Axiom ethereum_constantinople_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.constantinople.vm.memory.globals "memory_read_bytes". -Axiom ethereum_constantinople_vm_memory_memory_write : - IsGlobalAlias globals ethereum.constantinople.vm.memory.globals "memory_write". +Axiom ethereum_constantinople_vm_memory_imports : + AreImported globals "ethereum.constantinople.vm.memory" [ "memory_read_bytes"; "memory_write" ]. -Require ethereum.constantinople.vm.stack. -Axiom ethereum_constantinople_vm_stack_pop : - IsGlobalAlias globals ethereum.constantinople.vm.stack.globals "pop". -Axiom ethereum_constantinople_vm_stack_push : - IsGlobalAlias globals ethereum.constantinople.vm.stack.globals "push". +Axiom ethereum_constantinople_vm_stack_imports : + AreImported globals "ethereum.constantinople.vm.stack" [ "pop"; "push" ]. Definition generic_create : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -859,7 +794,12 @@ Definition generic_call : Value.t -> Value.t -> M := make_list [ M.get_field (| M.get_name (| globals, "evm" |), "memory" |); M.get_name (| globals, "memory_output_start_position" |); - M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), M.slice (| Constant.None_, M.get_name (| globals, "actual_output_size" |) |) |) + M.slice (| + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), + Constant.None_, + M.get_name (| globals, "actual_output_size" |), + Constant.None_ + |) ], make_dict [] |) in @@ -1437,20 +1377,28 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in let parent_evm := M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "parent_evm" |) in - While Compare.is_not (| - M.get_name (| globals, "parent_evm" |), - Constant.None_ - |) do - let _ := M.call (| + let _ := + M.while (| + Compare.is_not (| + M.get_name (| globals, "parent_evm" |), + Constant.None_ + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "refunded_accounts" |), "update" |), make_list [ M.get_field (| M.get_name (| globals, "parent_evm" |), "accounts_to_delete" |) ], make_dict [] |) in - let parent_evm := - M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in - EndWhile. + let parent_evm := + M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := (* if *) M.if_then_else (| @@ -1952,6 +1900,6 @@ Definition revert : Value.t -> Value.t -> M := make_dict [] |) |) in - let _ := M.raise (| Some(M.get_name (| globals, "Revert" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "Revert" |)) |) in let _ := M.pass (| |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/constantinople/vm/interpreter.v b/CoqOfPython/ethereum/constantinople/vm/interpreter.v index 5ca515a..b005455 100644 --- a/CoqOfPython/ethereum/constantinople/vm/interpreter.v +++ b/CoqOfPython/ethereum/constantinople/vm/interpreter.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.constantinople.vm.interpreter". Definition expr_1 : Value.t := Constant.str " @@ -17,123 +17,50 @@ Introduction A straightforward interpreter that executes EVM code. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_Iterable : - IsGlobalAlias globals typing.globals "Iterable". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.trace. -Axiom ethereum_trace_EvmStop : - IsGlobalAlias globals ethereum.trace.globals "EvmStop". -Axiom ethereum_trace_OpEnd : - IsGlobalAlias globals ethereum.trace.globals "OpEnd". -Axiom ethereum_trace_OpException : - IsGlobalAlias globals ethereum.trace.globals "OpException". -Axiom ethereum_trace_OpStart : - IsGlobalAlias globals ethereum.trace.globals "OpStart". -Axiom ethereum_trace_PrecompileEnd : - IsGlobalAlias globals ethereum.trace.globals "PrecompileEnd". -Axiom ethereum_trace_PrecompileStart : - IsGlobalAlias globals ethereum.trace.globals "PrecompileStart". -Axiom ethereum_trace_TransactionEnd : - IsGlobalAlias globals ethereum.trace.globals "TransactionEnd". -Axiom ethereum_trace_evm_trace : - IsGlobalAlias globals ethereum.trace.globals "evm_trace". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.constantinople.blocks. -Axiom ethereum_constantinople_blocks_Log : - IsGlobalAlias globals ethereum.constantinople.blocks.globals "Log". - -Require ethereum.constantinople.fork_types. -Axiom ethereum_constantinople_fork_types_Address : - IsGlobalAlias globals ethereum.constantinople.fork_types.globals "Address". - -Require ethereum.constantinople.state. -Axiom ethereum_constantinople_state_account_exists_and_is_empty : - IsGlobalAlias globals ethereum.constantinople.state.globals "account_exists_and_is_empty". -Axiom ethereum_constantinople_state_account_has_code_or_nonce : - IsGlobalAlias globals ethereum.constantinople.state.globals "account_has_code_or_nonce". -Axiom ethereum_constantinople_state_begin_transaction : - IsGlobalAlias globals ethereum.constantinople.state.globals "begin_transaction". -Axiom ethereum_constantinople_state_commit_transaction : - IsGlobalAlias globals ethereum.constantinople.state.globals "commit_transaction". -Axiom ethereum_constantinople_state_destroy_storage : - IsGlobalAlias globals ethereum.constantinople.state.globals "destroy_storage". -Axiom ethereum_constantinople_state_increment_nonce : - IsGlobalAlias globals ethereum.constantinople.state.globals "increment_nonce". -Axiom ethereum_constantinople_state_move_ether : - IsGlobalAlias globals ethereum.constantinople.state.globals "move_ether". -Axiom ethereum_constantinople_state_rollback_transaction : - IsGlobalAlias globals ethereum.constantinople.state.globals "rollback_transaction". -Axiom ethereum_constantinople_state_set_code : - IsGlobalAlias globals ethereum.constantinople.state.globals "set_code". -Axiom ethereum_constantinople_state_touch_account : - IsGlobalAlias globals ethereum.constantinople.state.globals "touch_account". - -Require ethereum.constantinople.vm.__init__. -Axiom ethereum_constantinople_vm___init___Message : - IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Message". - -Require ethereum.constantinople.vm.gas. -Axiom ethereum_constantinople_vm_gas_GAS_CODE_DEPOSIT : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_CODE_DEPOSIT". -Axiom ethereum_constantinople_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "charge_gas". - -Require ethereum.constantinople.vm.precompiled_contracts.mapping. -Axiom ethereum_constantinople_vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : - IsGlobalAlias globals ethereum.constantinople.vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". - -Require ethereum.constantinople.vm.__init__. -Axiom ethereum_constantinople_vm___init___Environment : - IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Environment". -Axiom ethereum_constantinople_vm___init___Evm : - IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Evm". - -Require ethereum.constantinople.vm.exceptions. -Axiom ethereum_constantinople_vm_exceptions_AddressCollision : - IsGlobalAlias globals ethereum.constantinople.vm.exceptions.globals "AddressCollision". -Axiom ethereum_constantinople_vm_exceptions_ExceptionalHalt : - IsGlobalAlias globals ethereum.constantinople.vm.exceptions.globals "ExceptionalHalt". -Axiom ethereum_constantinople_vm_exceptions_InvalidOpcode : - IsGlobalAlias globals ethereum.constantinople.vm.exceptions.globals "InvalidOpcode". -Axiom ethereum_constantinople_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.constantinople.vm.exceptions.globals "OutOfGasError". -Axiom ethereum_constantinople_vm_exceptions_Revert : - IsGlobalAlias globals ethereum.constantinople.vm.exceptions.globals "Revert". -Axiom ethereum_constantinople_vm_exceptions_StackDepthLimitError : - IsGlobalAlias globals ethereum.constantinople.vm.exceptions.globals "StackDepthLimitError". - -Require ethereum.constantinople.vm.instructions.__init__. -Axiom ethereum_constantinople_vm_instructions___init___Ops : - IsGlobalAlias globals ethereum.constantinople.vm.instructions.__init__.globals "Ops". -Axiom ethereum_constantinople_vm_instructions___init___op_implementation : - IsGlobalAlias globals ethereum.constantinople.vm.instructions.__init__.globals "op_implementation". - -Require ethereum.constantinople.vm.runtime. -Axiom ethereum_constantinople_vm_runtime_get_valid_jump_destinations : - IsGlobalAlias globals ethereum.constantinople.vm.runtime.globals "get_valid_jump_destinations". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Iterable"; "Optional"; "Set"; "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. + +Axiom ethereum_trace_imports : + AreImported globals "ethereum.trace" [ "EvmStop"; "OpEnd"; "OpException"; "OpStart"; "PrecompileEnd"; "PrecompileStart"; "TransactionEnd"; "evm_trace" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_constantinople_blocks_imports : + AreImported globals "ethereum.constantinople.blocks" [ "Log" ]. + +Axiom ethereum_constantinople_fork_types_imports : + AreImported globals "ethereum.constantinople.fork_types" [ "Address" ]. + +Axiom ethereum_constantinople_state_imports : + AreImported globals "ethereum.constantinople.state" [ "account_exists_and_is_empty"; "account_has_code_or_nonce"; "begin_transaction"; "commit_transaction"; "destroy_storage"; "increment_nonce"; "move_ether"; "rollback_transaction"; "set_code"; "touch_account" ]. + +Axiom ethereum_constantinople_vm_imports : + AreImported globals "ethereum.constantinople.vm" [ "Message" ]. + +Axiom ethereum_constantinople_vm_gas_imports : + AreImported globals "ethereum.constantinople.vm.gas" [ "GAS_CODE_DEPOSIT"; "charge_gas" ]. + +Axiom ethereum_constantinople_vm_precompiled_contracts_mapping_imports : + AreImported globals "ethereum.constantinople.vm.precompiled_contracts.mapping" [ "PRE_COMPILED_CONTRACTS" ]. + +Axiom ethereum_constantinople_vm_imports : + AreImported globals "ethereum.constantinople.vm" [ "Environment"; "Evm" ]. + +Axiom ethereum_constantinople_vm_exceptions_imports : + AreImported globals "ethereum.constantinople.vm.exceptions" [ "AddressCollision"; "ExceptionalHalt"; "InvalidOpcode"; "OutOfGasError"; "Revert"; "StackDepthLimitError" ]. + +Axiom ethereum_constantinople_vm_instructions_imports : + AreImported globals "ethereum.constantinople.vm.instructions" [ "Ops"; "op_implementation" ]. + +Axiom ethereum_constantinople_vm_runtime_imports : + AreImported globals "ethereum.constantinople.vm.runtime" [ "get_valid_jump_destinations" ]. Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -500,7 +427,7 @@ Definition process_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "StackDepthLimitError" |), make_list [ Constant.str "Stack depth limit reached" diff --git a/CoqOfPython/ethereum/constantinople/vm/memory.v b/CoqOfPython/ethereum/constantinople/vm/memory.v index 08d2290..d542adf 100644 --- a/CoqOfPython/ethereum/constantinople/vm/memory.v +++ b/CoqOfPython/ethereum/constantinople/vm/memory.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.constantinople.vm.memory". Definition expr_1 : Value.t := Constant.str " @@ -17,17 +17,11 @@ Introduction EVM memory operations. ". -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_right_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "right_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "right_pad_zero_bytes" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. Definition memory_write : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,22 +39,27 @@ Definition memory_write : Value.t -> Value.t -> M := Data to write to memory. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + M.slice (| + M.get_name (| globals, "memory" |), + M.get_name (| globals, "start_position" |), + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) - |) |) |), + Constant.None_ + |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_)). @@ -86,22 +85,27 @@ Definition memory_read_bytes : Value.t -> Value.t -> M := Data read from memory. " in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + M.slice (| + M.get_name (| globals, "memory" |), + M.get_name (| globals, "start_position" |), + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |) |) + Constant.None_ + |) |) in M.pure Constant.None_)). @@ -129,22 +133,27 @@ Definition buffer_read : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "right_pad_zero_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "buffer" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + M.slice (| + M.get_name (| globals, "buffer" |), + M.get_name (| globals, "start_position" |), + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |) |); + Constant.None_ + |); M.get_name (| globals, "size" |) ], make_dict [] diff --git a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/__init__.v index 3c7f471..48bc095 100644 --- a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/__init__.v +++ b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.constantinople.vm.precompiled_contracts.__init__". Definition expr_1 : Value.t := Constant.str " @@ -18,9 +18,8 @@ Addresses of precompiled contracts and mappings to their implementations. ". -Require ethereum.constantinople.utils.hexadecimal. -Axiom ethereum_constantinople_utils_hexadecimal_hex_to_address : - IsGlobalAlias globals ethereum.constantinople.utils.hexadecimal.globals "hex_to_address". +Axiom ethereum_constantinople_utils_hexadecimal_imports : + AreImported globals "ethereum.constantinople.utils.hexadecimal" [ "hex_to_address" ]. Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS"; Constant.str "MODEXP_ADDRESS"; Constant.str "ALT_BN128_ADD_ADDRESS"; Constant.str "ALT_BN128_MUL_ADDRESS"; Constant.str "ALT_BN128_PAIRING_CHECK_ADDRESS"; Constant.str "BLAKE2F_ADDRESS" ] diff --git a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/alt_bn128.v index f938fae..0f2bf06 100644 --- a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/alt_bn128.v +++ b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/alt_bn128.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.constantinople.vm.precompiled_contracts.alt_bn128". Definition expr_1 : Value.t := Constant.str " @@ -17,49 +17,26 @@ Introduction Implementation of the ALT_BN128 precompiled contracts. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. -Require ethereum.crypto.alt_bn128. -Axiom ethereum_crypto_alt_bn128_ALT_BN128_CURVE_ORDER : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "ALT_BN128_CURVE_ORDER". -Axiom ethereum_crypto_alt_bn128_ALT_BN128_PRIME : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "ALT_BN128_PRIME". -Axiom ethereum_crypto_alt_bn128_BNF : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF". -Axiom ethereum_crypto_alt_bn128_BNF2 : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF2". -Axiom ethereum_crypto_alt_bn128_BNF12 : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF12". -Axiom ethereum_crypto_alt_bn128_BNP : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNP". -Axiom ethereum_crypto_alt_bn128_BNP2 : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNP2". -Axiom ethereum_crypto_alt_bn128_pairing : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "pairing". +Axiom ethereum_crypto_alt_bn128_imports : + AreImported globals "ethereum.crypto.alt_bn128" [ "ALT_BN128_CURVE_ORDER"; "ALT_BN128_PRIME"; "BNF"; "BNF2"; "BNF12"; "BNP"; "BNP2"; "pairing" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.constantinople.vm.__init__. -Axiom ethereum_constantinople_vm___init___Evm : - IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Evm". +Axiom ethereum_constantinople_vm_imports : + AreImported globals "ethereum.constantinople.vm" [ "Evm" ]. -Require ethereum.constantinople.vm.gas. -Axiom ethereum_constantinople_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "charge_gas". +Axiom ethereum_constantinople_vm_gas_imports : + AreImported globals "ethereum.constantinople.vm.gas" [ "charge_gas" ]. -Require ethereum.constantinople.vm.memory. -Axiom ethereum_constantinople_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.constantinople.vm.memory.globals "buffer_read". +Axiom ethereum_constantinople_vm_memory_imports : + AreImported globals "ethereum.constantinople.vm.memory" [ "buffer_read" ]. -Require ethereum.constantinople.vm.exceptions. -Axiom ethereum_constantinople_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.constantinople.vm.exceptions.globals "OutOfGasError". +Axiom ethereum_constantinople_vm_exceptions_imports : + AreImported globals "ethereum.constantinople.vm.exceptions" [ "OutOfGasError" ]. Definition alt_bn128_add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -208,23 +185,32 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ] do - let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| - M.get_name (| globals, "i" |), - M.get_name (| globals, "ALT_BN128_PRIME" |) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ], ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in (* At stmt: unsupported node type: Try *) let p := BinOp.add (| @@ -363,23 +349,32 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ] do - let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| - M.get_name (| globals, "i" |), - M.get_name (| globals, "ALT_BN128_PRIME" |) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ], ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in (* At stmt: unsupported node type: Try *) let p := M.call (| @@ -466,7 +461,7 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -480,76 +475,89 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - BinOp.floor_div (| + let _ := + M.for_ (| + M.get_name (| globals, "i" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "data" |) - ], - make_dict [] - |), - Constant.int 192 - |) - ], - make_dict [] - |) do - let values := - make_list [] in - For M.get_name (| globals, "j" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 6 - ], - make_dict [] - |) do - let value := + M.get_name (| globals, "range" |), + make_list [ + BinOp.floor_div (| M.call (| - M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + M.get_name (| globals, "len" |), make_list [ - M.get_subscript (| M.get_name (| globals, "data" |), M.slice (| BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "i" |), - Constant.int 192 - |), - BinOp.mult (| - Constant.int 32, - M.get_name (| globals, "j" |) - |) - |), BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "i" |), - Constant.int 192 - |), - BinOp.mult (| - Constant.int 32, - BinOp.add (| - M.get_name (| globals, "j" |), - Constant.int 1 - |) - |) - |) |) |) + M.get_name (| globals, "data" |) ], make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| - M.get_name (| globals, "value" |), - M.get_name (| globals, "ALT_BN128_PRIME" |) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let _ := M.call (| + |), + Constant.int 192 + |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let values := + make_list [] in + let _ := + M.for_ (| + M.get_name (| globals, "j" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 6 + ], + make_dict [] + |), + ltac:(M.monadic ( + let value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.slice (| + M.get_name (| globals, "data" |), + BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + M.get_name (| globals, "j" |) + |) + |), + BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "j" |), + Constant.int 1 + |) + |) + |), + Constant.None_ + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| M.get_field (| M.get_name (| globals, "values" |), "append" |), make_list [ M.call (| @@ -562,9 +570,14 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in (* At stmt: unsupported node type: Try *) - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.eq (| @@ -585,7 +598,7 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.eq (| @@ -606,49 +619,54 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| - M.get_name (| globals, "p" |), - M.call (| - M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) - |), + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "p" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "q" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |) + )) + |), + (* then *) ltac:(M.monadic ( - Compare.not_eq (| - M.get_name (| globals, "q" |), - M.call (| - M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) - |) - )) - |), - (* then *) - ltac:(M.monadic ( - let result := - BinOp.mult (| - M.get_name (| globals, "result" |), - M.call (| - M.get_name (| globals, "pairing" |), - make_list [ - M.get_name (| globals, "q" |); - M.get_name (| globals, "p" |) - ], - make_dict [] - |) - |) in + let result := + BinOp.mult (| + M.get_name (| globals, "result" |), + M.call (| + M.get_name (| globals, "pairing" |), + make_list [ + M.get_name (| globals, "q" |); + M.get_name (| globals, "p" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := (* if *) M.if_then_else (| diff --git a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/ecrecover.v index 67d304b..71ad01d 100644 --- a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/ecrecover.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.constantinople.vm.precompiled_contracts.ecrecover". Definition expr_1 : Value.t := Constant.str " @@ -17,39 +17,26 @@ Introduction Implementation of the ECRECOVER precompiled contract. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.crypto.elliptic_curve. -Axiom ethereum_crypto_elliptic_curve_SECP256K1N : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". -Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". +Axiom ethereum_crypto_elliptic_curve_imports : + AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_left_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. -Require ethereum.constantinople.vm.__init__. -Axiom ethereum_constantinople_vm___init___Evm : - IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Evm". +Axiom ethereum_constantinople_vm_imports : + AreImported globals "ethereum.constantinople.vm" [ "Evm" ]. -Require ethereum.constantinople.vm.gas. -Axiom ethereum_constantinople_vm_gas_GAS_ECRECOVER : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_ECRECOVER". -Axiom ethereum_constantinople_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "charge_gas". +Axiom ethereum_constantinople_vm_gas_imports : + AreImported globals "ethereum.constantinople.vm.gas" [ "GAS_ECRECOVER"; "charge_gas" ]. -Require ethereum.constantinople.vm.memory. -Axiom ethereum_constantinople_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.constantinople.vm.memory.globals "buffer_read". +Axiom ethereum_constantinople_vm_memory_imports : + AreImported globals "ethereum.constantinople.vm.memory" [ "buffer_read" ]. Definition ecrecover : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -264,13 +251,18 @@ Definition ecrecover : Value.t -> Value.t -> M := )) |) in (* At stmt: unsupported node type: Try *) let address := - M.get_subscript (| M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "public_key" |) - ], - make_dict [] - |), M.slice (| Constant.int 12, Constant.int 32 |) |) in + M.slice (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), + Constant.int 12, + Constant.int 32, + Constant.None_ + |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/identity.v index 6a8eb62..ac6ab23 100644 --- a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/identity.v +++ b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/identity.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.constantinople.vm.precompiled_contracts.identity". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementation of the `IDENTITY` precompiled contract. ". -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.constantinople.vm.__init__. -Axiom ethereum_constantinople_vm___init___Evm : - IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Evm". +Axiom ethereum_constantinople_vm_imports : + AreImported globals "ethereum.constantinople.vm" [ "Evm" ]. -Require ethereum.constantinople.vm.gas. -Axiom ethereum_constantinople_vm_gas_GAS_IDENTITY : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_IDENTITY". -Axiom ethereum_constantinople_vm_gas_GAS_IDENTITY_WORD : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_IDENTITY_WORD". -Axiom ethereum_constantinople_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "charge_gas". +Axiom ethereum_constantinople_vm_gas_imports : + AreImported globals "ethereum.constantinople.vm.gas" [ "GAS_IDENTITY"; "GAS_IDENTITY_WORD"; "charge_gas" ]. Definition identity : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/mapping.v index f6570fb..5f9eca2 100644 --- a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/mapping.v +++ b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/mapping.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.constantinople.vm.precompiled_contracts.mapping". Definition expr_1 : Value.t := Constant.str " @@ -17,60 +17,31 @@ Introduction Mapping of precompiled contracts their implementations. ". -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict" ]. -Require ethereum.constantinople.fork_types. -Axiom ethereum_constantinople_fork_types_Address : - IsGlobalAlias globals ethereum.constantinople.fork_types.globals "Address". +Axiom ethereum_constantinople_fork_types_imports : + AreImported globals "ethereum.constantinople.fork_types" [ "Address" ]. -Require ethereum.constantinople.vm.precompiled_contracts.__init__. -Axiom ethereum_constantinople_vm_precompiled_contracts___init___ALT_BN128_ADD_ADDRESS : - IsGlobalAlias globals ethereum.constantinople.vm.precompiled_contracts.__init__.globals "ALT_BN128_ADD_ADDRESS". -Axiom ethereum_constantinople_vm_precompiled_contracts___init___ALT_BN128_MUL_ADDRESS : - IsGlobalAlias globals ethereum.constantinople.vm.precompiled_contracts.__init__.globals "ALT_BN128_MUL_ADDRESS". -Axiom ethereum_constantinople_vm_precompiled_contracts___init___ALT_BN128_PAIRING_CHECK_ADDRESS : - IsGlobalAlias globals ethereum.constantinople.vm.precompiled_contracts.__init__.globals "ALT_BN128_PAIRING_CHECK_ADDRESS". -Axiom ethereum_constantinople_vm_precompiled_contracts___init___ECRECOVER_ADDRESS : - IsGlobalAlias globals ethereum.constantinople.vm.precompiled_contracts.__init__.globals "ECRECOVER_ADDRESS". -Axiom ethereum_constantinople_vm_precompiled_contracts___init___IDENTITY_ADDRESS : - IsGlobalAlias globals ethereum.constantinople.vm.precompiled_contracts.__init__.globals "IDENTITY_ADDRESS". -Axiom ethereum_constantinople_vm_precompiled_contracts___init___MODEXP_ADDRESS : - IsGlobalAlias globals ethereum.constantinople.vm.precompiled_contracts.__init__.globals "MODEXP_ADDRESS". -Axiom ethereum_constantinople_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : - IsGlobalAlias globals ethereum.constantinople.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". -Axiom ethereum_constantinople_vm_precompiled_contracts___init___SHA256_ADDRESS : - IsGlobalAlias globals ethereum.constantinople.vm.precompiled_contracts.__init__.globals "SHA256_ADDRESS". +Axiom ethereum_constantinople_vm_precompiled_contracts_imports : + AreImported globals "ethereum.constantinople.vm.precompiled_contracts" [ "ALT_BN128_ADD_ADDRESS"; "ALT_BN128_MUL_ADDRESS"; "ALT_BN128_PAIRING_CHECK_ADDRESS"; "ECRECOVER_ADDRESS"; "IDENTITY_ADDRESS"; "MODEXP_ADDRESS"; "RIPEMD160_ADDRESS"; "SHA256_ADDRESS" ]. -Require ethereum.constantinople.vm.precompiled_contracts.alt_bn128. -Axiom ethereum_constantinople_vm_precompiled_contracts_alt_bn128_alt_bn128_add : - IsGlobalAlias globals ethereum.constantinople.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_add". -Axiom ethereum_constantinople_vm_precompiled_contracts_alt_bn128_alt_bn128_mul : - IsGlobalAlias globals ethereum.constantinople.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_mul". -Axiom ethereum_constantinople_vm_precompiled_contracts_alt_bn128_alt_bn128_pairing_check : - IsGlobalAlias globals ethereum.constantinople.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_pairing_check". +Axiom ethereum_constantinople_vm_precompiled_contracts_alt_bn128_imports : + AreImported globals "ethereum.constantinople.vm.precompiled_contracts.alt_bn128" [ "alt_bn128_add"; "alt_bn128_mul"; "alt_bn128_pairing_check" ]. -Require ethereum.constantinople.vm.precompiled_contracts.ecrecover. -Axiom ethereum_constantinople_vm_precompiled_contracts_ecrecover_ecrecover : - IsGlobalAlias globals ethereum.constantinople.vm.precompiled_contracts.ecrecover.globals "ecrecover". +Axiom ethereum_constantinople_vm_precompiled_contracts_ecrecover_imports : + AreImported globals "ethereum.constantinople.vm.precompiled_contracts.ecrecover" [ "ecrecover" ]. -Require ethereum.constantinople.vm.precompiled_contracts.identity. -Axiom ethereum_constantinople_vm_precompiled_contracts_identity_identity : - IsGlobalAlias globals ethereum.constantinople.vm.precompiled_contracts.identity.globals "identity". +Axiom ethereum_constantinople_vm_precompiled_contracts_identity_imports : + AreImported globals "ethereum.constantinople.vm.precompiled_contracts.identity" [ "identity" ]. -Require ethereum.constantinople.vm.precompiled_contracts.modexp. -Axiom ethereum_constantinople_vm_precompiled_contracts_modexp_modexp : - IsGlobalAlias globals ethereum.constantinople.vm.precompiled_contracts.modexp.globals "modexp". +Axiom ethereum_constantinople_vm_precompiled_contracts_modexp_imports : + AreImported globals "ethereum.constantinople.vm.precompiled_contracts.modexp" [ "modexp" ]. -Require ethereum.constantinople.vm.precompiled_contracts.ripemd160. -Axiom ethereum_constantinople_vm_precompiled_contracts_ripemd160_ripemd160 : - IsGlobalAlias globals ethereum.constantinople.vm.precompiled_contracts.ripemd160.globals "ripemd160". +Axiom ethereum_constantinople_vm_precompiled_contracts_ripemd160_imports : + AreImported globals "ethereum.constantinople.vm.precompiled_contracts.ripemd160" [ "ripemd160" ]. -Require ethereum.constantinople.vm.precompiled_contracts.sha256. -Axiom ethereum_constantinople_vm_precompiled_contracts_sha256_sha256 : - IsGlobalAlias globals ethereum.constantinople.vm.precompiled_contracts.sha256.globals "sha256". +Axiom ethereum_constantinople_vm_precompiled_contracts_sha256_imports : + AreImported globals "ethereum.constantinople.vm.precompiled_contracts.sha256" [ "sha256" ]. (* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/modexp.v index d688844..cea4cb3 100644 --- a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/modexp.v +++ b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/modexp.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.constantinople.vm.precompiled_contracts.modexp". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementation of the `MODEXP` precompiled contract. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. -Require ethereum.constantinople.vm.__init__. -Axiom ethereum_constantinople_vm___init___Evm : - IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Evm". +Axiom ethereum_constantinople_vm_imports : + AreImported globals "ethereum.constantinople.vm" [ "Evm" ]. -Require ethereum.constantinople.vm.gas. -Axiom ethereum_constantinople_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "charge_gas". +Axiom ethereum_constantinople_vm_gas_imports : + AreImported globals "ethereum.constantinople.vm.gas" [ "charge_gas" ]. -Require ethereum.constantinople.vm.memory. -Axiom ethereum_constantinople_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.constantinople.vm.memory.globals "buffer_read". +Axiom ethereum_constantinople_vm_memory_imports : + AreImported globals "ethereum.constantinople.vm.memory" [ "buffer_read" ]. Definition GQUADDIVISOR : Value.t := M.run ltac:(M.monadic ( M.call (| diff --git a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/ripemd160.v index df42cbf..73a1f72 100644 --- a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/ripemd160.v +++ b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/ripemd160.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.constantinople.vm.precompiled_contracts.ripemd160". Definition expr_1 : Value.t := Constant.str " @@ -19,29 +19,20 @@ Implementation of the `RIPEMD160` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_left_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.constantinople.vm.__init__. -Axiom ethereum_constantinople_vm___init___Evm : - IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Evm". +Axiom ethereum_constantinople_vm_imports : + AreImported globals "ethereum.constantinople.vm" [ "Evm" ]. -Require ethereum.constantinople.vm.gas. -Axiom ethereum_constantinople_vm_gas_GAS_RIPEMD160 : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_RIPEMD160". -Axiom ethereum_constantinople_vm_gas_GAS_RIPEMD160_WORD : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_RIPEMD160_WORD". -Axiom ethereum_constantinople_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "charge_gas". +Axiom ethereum_constantinople_vm_gas_imports : + AreImported globals "ethereum.constantinople.vm.gas" [ "GAS_RIPEMD160"; "GAS_RIPEMD160_WORD"; "charge_gas" ]. Definition ripemd160 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/sha256.v index e89bb4b..cda8916 100644 --- a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/sha256.v +++ b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/sha256.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.constantinople.vm.precompiled_contracts.sha256". Definition expr_1 : Value.t := Constant.str " @@ -19,25 +19,17 @@ Implementation of the `SHA256` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.constantinople.vm.__init__. -Axiom ethereum_constantinople_vm___init___Evm : - IsGlobalAlias globals ethereum.constantinople.vm.__init__.globals "Evm". +Axiom ethereum_constantinople_vm_imports : + AreImported globals "ethereum.constantinople.vm" [ "Evm" ]. -Require ethereum.constantinople.vm.gas. -Axiom ethereum_constantinople_vm_gas_GAS_SHA256 : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_SHA256". -Axiom ethereum_constantinople_vm_gas_GAS_SHA256_WORD : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "GAS_SHA256_WORD". -Axiom ethereum_constantinople_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.constantinople.vm.gas.globals "charge_gas". +Axiom ethereum_constantinople_vm_gas_imports : + AreImported globals "ethereum.constantinople.vm.gas" [ "GAS_SHA256"; "GAS_SHA256_WORD"; "charge_gas" ]. Definition sha256 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/constantinople/vm/runtime.v b/CoqOfPython/ethereum/constantinople/vm/runtime.v index 90b65f5..bf6ec2c 100644 --- a/CoqOfPython/ethereum/constantinople/vm/runtime.v +++ b/CoqOfPython/ethereum/constantinople/vm/runtime.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.constantinople.vm.runtime". Definition expr_1 : Value.t := Constant.str " @@ -17,17 +17,14 @@ Introduction Runtime related operations used while executing EVM code. ". -Require typing. -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". +Axiom typing_imports : + AreImported globals "typing" [ "Set" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.constantinople.vm.instructions.__init__. -Axiom ethereum_constantinople_vm_instructions___init___Ops : - IsGlobalAlias globals ethereum.constantinople.vm.instructions.__init__.globals "Ops". +Axiom ethereum_constantinople_vm_instructions_imports : + AreImported globals "ethereum.constantinople.vm.instructions" [ "Ops" ]. Definition get_valid_jump_destinations : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -67,75 +64,83 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := ], make_dict [] |) in - While Compare.lt (| - M.get_name (| globals, "pc" |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "code" |) - ], - make_dict [] - |) - |) do -(* At stmt: unsupported node type: Try *) - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "current_opcode" |), - M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) - |), - (* then *) + let _ := + M.while (| + Compare.lt (| + M.get_name (| globals, "pc" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) + |), ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), - make_list [ - M.get_name (| globals, "pc" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( +(* At stmt: unsupported node type: Try *) let _ := (* if *) M.if_then_else (| - BoolOp.and (| - Compare.lt_e (| - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |), - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |) - |), - ltac:(M.monadic ( - Compare.lt_e (| - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH32" |), "value" |) - |) - )) + Compare.eq (| + M.get_name (| globals, "current_opcode" |), + M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) |), (* then *) ltac:(M.monadic ( - let push_data_size := - BinOp.add (| - BinOp.sub (| - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) - |), - Constant.int 1 - |) in - let pc := BinOp.add - M.get_name (| globals, "push_data_size" |) - M.get_name (| globals, "push_data_size" |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), + make_list [ + M.get_name (| globals, "pc" |) + ], + make_dict [] + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.lt_e (| + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |), + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH32" |), "value" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let push_data_size := + BinOp.add (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) + |), + Constant.int 1 + |) in + let pc := BinOp.add + M.get_name (| globals, "push_data_size" |) + M.get_name (| globals, "push_data_size" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ )) |) in + let pc := BinOp.add + Constant.int 1 + Constant.int 1 in M.pure Constant.None_ - )) |) in - let pc := BinOp.add - Constant.int 1 - Constant.int 1 in - EndWhile. + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.get_name (| globals, "valid_jump_destinations" |) |) in diff --git a/CoqOfPython/ethereum/constantinople/vm/stack.v b/CoqOfPython/ethereum/constantinople/vm/stack.v index 04b1a75..6242369 100644 --- a/CoqOfPython/ethereum/constantinople/vm/stack.v +++ b/CoqOfPython/ethereum/constantinople/vm/stack.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.constantinople.vm.stack". Definition expr_1 : Value.t := Constant.str " @@ -17,19 +17,14 @@ Introduction Implementation of the stack operators for the EVM. ". -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". +Axiom typing_imports : + AreImported globals "typing" [ "List" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.constantinople.vm.exceptions. -Axiom ethereum_constantinople_vm_exceptions_StackOverflowError : - IsGlobalAlias globals ethereum.constantinople.vm.exceptions.globals "StackOverflowError". -Axiom ethereum_constantinople_vm_exceptions_StackUnderflowError : - IsGlobalAlias globals ethereum.constantinople.vm.exceptions.globals "StackUnderflowError". +Axiom ethereum_constantinople_vm_exceptions_imports : + AreImported globals "ethereum.constantinople.vm.exceptions" [ "StackOverflowError"; "StackUnderflowError" ]. Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -63,7 +58,7 @@ Definition pop : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "StackUnderflowError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "StackUnderflowError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -108,7 +103,7 @@ Definition push : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "StackOverflowError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "StackOverflowError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/crypto/__init__.v b/CoqOfPython/ethereum/crypto/__init__.v index 97b4e39..d20cfb4 100644 --- a/CoqOfPython/ethereum/crypto/__init__.v +++ b/CoqOfPython/ethereum/crypto/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.crypto.__init__". Definition expr_1 : Value.t := Constant.str " diff --git a/CoqOfPython/ethereum/crypto/alt_bn128.v b/CoqOfPython/ethereum/crypto/alt_bn128.v index f4ba848..ea237cf 100644 --- a/CoqOfPython/ethereum/crypto/alt_bn128.v +++ b/CoqOfPython/ethereum/crypto/alt_bn128.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.crypto.alt_bn128". Definition expr_1 : Value.t := Constant.str " @@ -8,11 +8,8 @@ The alt_bn128 curve ^^^^^^^^^^^^^^^^^^^ ". -Require ethereum.crypto.__init__. -Axiom ethereum_crypto___init___elliptic_curve : - IsGlobalAlias globals ethereum.crypto.__init__.globals "elliptic_curve". -Axiom ethereum_crypto___init___finite_field : - IsGlobalAlias globals ethereum.crypto.__init__.globals "finite_field". +Axiom ethereum_crypto_imports : + AreImported globals "ethereum.crypto" [ "elliptic_curve"; "finite_field" ]. Definition ALT_BN128_PRIME : Value.t := M.run ltac:(M.monadic ( Constant.int 21888242871839275222246405745257275088696311157297823662689037894645226208583 @@ -106,71 +103,124 @@ Definition BNF12 : Value.t := ], Constant.int 23 |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 12 - ], - make_dict [] - |) do - For M.get_name (| globals, "j" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 12 - ], - make_dict [] - |) do - let _ := M.assign_op (| - BinOp.add, - M.get_subscript (| M.get_name (| globals, "mul" |), BinOp.add (| - M.get_name (| globals, "i" |), - M.get_name (| globals, "j" |) - |) |), - BinOp.mult (| - M.get_subscript (| M.get_name (| globals, "self" |), M.get_name (| globals, "i" |) |), - M.get_subscript (| M.get_name (| globals, "right" |), M.get_name (| globals, "j" |) |) + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 12 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := + M.for_ (| + M.get_name (| globals, "j" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 12 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_subscript (| + M.get_name (| globals, "mul" |), + BinOp.add (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "j" |) + |) + |), + BinOp.mult (| + M.get_subscript (| + M.get_name (| globals, "self" |), + M.get_name (| globals, "i" |) + |), + M.get_subscript (| + M.get_name (| globals, "right" |), + M.get_name (| globals, "j" |) + |) |) - |) in - EndFor. - EndFor. - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 22; - Constant.int 11; - UnOp.sub (| Constant.int 1 |) - ], - make_dict [] - |) do - let _ := M.assign_op (| - BinOp.sub, - M.get_subscript (| M.get_name (| globals, "mul" |), BinOp.sub (| - M.get_name (| globals, "i" |), - Constant.int 6 - |) |), - BinOp.mult (| - M.get_subscript (| M.get_name (| globals, "mul" |), M.get_name (| globals, "i" |) |), + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 22; + Constant.int 11; + UnOp.sub (| Constant.int 1 |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.sub, + M.get_subscript (| + M.get_name (| globals, "mul" |), + BinOp.sub (| + M.get_name (| globals, "i" |), + Constant.int 6 + |) + |), + BinOp.mult (| + M.get_subscript (| + M.get_name (| globals, "mul" |), + M.get_name (| globals, "i" |) + |), UnOp.sub (| Constant.int 18 |) |) - |) in - let _ := M.assign_op (| - BinOp.sub, - M.get_subscript (| M.get_name (| globals, "mul" |), BinOp.sub (| - M.get_name (| globals, "i" |), - Constant.int 12 - |) |), - BinOp.mult (| - M.get_subscript (| M.get_name (| globals, "mul" |), M.get_name (| globals, "i" |) |), + |) in + let _ := M.assign_op (| + BinOp.sub, + M.get_subscript (| + M.get_name (| globals, "mul" |), + BinOp.sub (| + M.get_name (| globals, "i" |), + Constant.int 12 + |) + |), + BinOp.mult (| + M.get_subscript (| + M.get_name (| globals, "mul" |), + M.get_name (| globals, "i" |) + |), Constant.int 82 |) - |) in - EndFor. + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "BNF12" |), "__new__" |), make_list [ M.get_name (| globals, "BNF12" |); - M.get_subscript (| M.get_name (| globals, "mul" |), M.slice (| Constant.None_, Constant.int 12 |) |) + M.slice (| + M.get_name (| globals, "mul" |), + Constant.None_, + Constant.int 12, + Constant.None_ + |) ], make_dict [] |) @@ -215,7 +265,10 @@ Definition bnf2_to_bnf12 : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), make_list [ - M.get_subscript (| M.get_name (| globals, "x" |), Constant.int 0 |) + M.get_subscript (| + M.get_name (| globals, "x" |), + Constant.int 0 + |) ], make_dict [] |), @@ -223,7 +276,10 @@ Definition bnf2_to_bnf12 : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), make_list [ - M.get_subscript (| M.get_name (| globals, "x" |), Constant.int 1 |) + M.get_subscript (| + M.get_name (| globals, "x" |), + Constant.int 1 + |) ], make_dict [] |), @@ -496,76 +552,85 @@ Definition miller_loop : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - M.get_name (| globals, "ATE_PAIRING_COUNT_BITS" |); - UnOp.sub (| Constant.int 1 |); - UnOp.sub (| Constant.int 1 |) - ], - make_dict [] - |) do - let f := - BinOp.mult (| - BinOp.mult (| - M.get_name (| globals, "f" |), - M.get_name (| globals, "f" |) - |), - M.call (| - M.get_name (| globals, "linefunc" |), - make_list [ - M.get_name (| globals, "r" |); - M.get_name (| globals, "r" |); - M.get_name (| globals, "p" |) - ], - make_dict [] - |) - |) in - let r := + let _ := + M.for_ (| + M.get_name (| globals, "i" |), M.call (| - M.get_field (| M.get_name (| globals, "r" |), "double" |), - make_list [], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - BinOp.bit_and (| - BinOp.sub (| - M.get_name (| globals, "ATE_PAIRING_COUNT" |), - Constant.int 1 - |), - BinOp.pow (| - Constant.int 2, - M.get_name (| globals, "i" |) - |) - |), - (* then *) + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "ATE_PAIRING_COUNT_BITS" |); + UnOp.sub (| Constant.int 1 |); + UnOp.sub (| Constant.int 1 |) + ], + make_dict [] + |), ltac:(M.monadic ( let f := BinOp.mult (| - M.get_name (| globals, "f" |), + BinOp.mult (| + M.get_name (| globals, "f" |), + M.get_name (| globals, "f" |) + |), M.call (| M.get_name (| globals, "linefunc" |), make_list [ M.get_name (| globals, "r" |); - M.get_name (| globals, "q" |); + M.get_name (| globals, "r" |); M.get_name (| globals, "p" |) ], make_dict [] |) |) in let r := - BinOp.add (| - M.get_name (| globals, "r" |), - M.get_name (| globals, "q" |) + M.call (| + M.get_field (| M.get_name (| globals, "r" |), "double" |), + make_list [], + make_dict [] |) in + let _ := + (* if *) + M.if_then_else (| + BinOp.bit_and (| + BinOp.sub (| + M.get_name (| globals, "ATE_PAIRING_COUNT" |), + Constant.int 1 + |), + BinOp.pow (| + Constant.int 2, + M.get_name (| globals, "i" |) + |) + |), + (* then *) + ltac:(M.monadic ( + let f := + BinOp.mult (| + M.get_name (| globals, "f" |), + M.call (| + M.get_name (| globals, "linefunc" |), + make_list [ + M.get_name (| globals, "r" |); + M.get_name (| globals, "q" |); + M.get_name (| globals, "p" |) + ], + make_dict [] + |) + |) in + let r := + BinOp.add (| + M.get_name (| globals, "r" |), + M.get_name (| globals, "q" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := M.assert (| Compare.eq (| M.get_name (| globals, "r" |), M.call (| diff --git a/CoqOfPython/ethereum/crypto/blake2.v b/CoqOfPython/ethereum/crypto/blake2.v index f00276b..8087294 100644 --- a/CoqOfPython/ethereum/crypto/blake2.v +++ b/CoqOfPython/ethereum/crypto/blake2.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.crypto.blake2". Definition expr_1 : Value.t := Constant.str " @@ -10,19 +10,14 @@ The Blake2 Implementation (* At top_level_stmt: unsupported node type: Import *) -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Tuple" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. Definition spit_le_to_uint : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -41,38 +36,52 @@ Definition spit_le_to_uint : Value.t -> Value.t -> M := " in let words := make_list [] in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - M.get_name (| globals, "num_words" |) - ], - make_dict [] - |) do - let start_position := - BinOp.add (| - M.get_name (| globals, "start" |), - BinOp.mult (| - M.get_name (| globals, "i" |), - Constant.int 8 - |) - |) in - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "num_words" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let start_position := + BinOp.add (| + M.get_name (| globals, "start" |), + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 8 + |) + |) in + let _ := M.call (| M.get_field (| M.get_name (| globals, "words" |), "append" |), make_list [ M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_le_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "data" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| + M.slice (| + M.get_name (| globals, "data" |), M.get_name (| globals, "start_position" |), - Constant.int 8 - |) |) |) + BinOp.add (| + M.get_name (| globals, "start_position" |), + Constant.int 8 + |), + Constant.None_ + |) ], make_dict [] |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.get_name (| globals, "words" |) |) in @@ -102,7 +111,12 @@ Definition Blake2 : Value.t := M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "data" |), M.slice (| Constant.None_, Constant.int 4 |) |) + M.slice (| + M.get_name (| globals, "data" |), + Constant.None_, + Constant.int 4, + Constant.None_ + |) ], make_dict [] |) in @@ -142,7 +156,12 @@ Definition Blake2 : Value.t := M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "data" |), M.slice (| Constant.int 212, Constant.None_ |) |) + M.slice (| + M.get_name (| globals, "data" |), + Constant.int 212, + Constant.None_, + Constant.None_ + |) ], make_dict [] |) in @@ -169,12 +188,21 @@ Definition Blake2 : Value.t := The two input words for the mixing. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "a" |) |), + M.get_subscript (| + M.get_name (| globals, "v" |), + M.get_name (| globals, "a" |) + |), BinOp.mod_ (| BinOp.add (| BinOp.add (| - M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "a" |) |), - M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "b" |) |) + M.get_subscript (| + M.get_name (| globals, "v" |), + M.get_name (| globals, "a" |) + |), + M.get_subscript (| + M.get_name (| globals, "v" |), + M.get_name (| globals, "b" |) + |) |), M.get_name (| globals, "x" |) |), @@ -182,20 +210,35 @@ Definition Blake2 : Value.t := |) |) in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "d" |) |), + M.get_subscript (| + M.get_name (| globals, "v" |), + M.get_name (| globals, "d" |) + |), BinOp.bit_xor (| BinOp.r_shift (| BinOp.bit_xor (| - M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "d" |) |), - M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "a" |) |) + M.get_subscript (| + M.get_name (| globals, "v" |), + M.get_name (| globals, "d" |) + |), + M.get_subscript (| + M.get_name (| globals, "v" |), + M.get_name (| globals, "a" |) + |) |), M.get_field (| M.get_name (| globals, "self" |), "R1" |) |), BinOp.mod_ (| BinOp.l_shift (| BinOp.bit_xor (| - M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "d" |) |), - M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "a" |) |) + M.get_subscript (| + M.get_name (| globals, "v" |), + M.get_name (| globals, "d" |) + |), + M.get_subscript (| + M.get_name (| globals, "v" |), + M.get_name (| globals, "a" |) + |) |), M.get_field (| M.get_name (| globals, "self" |), "w_R1" |) |), @@ -204,30 +247,54 @@ Definition Blake2 : Value.t := |) |) in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "c" |) |), + M.get_subscript (| + M.get_name (| globals, "v" |), + M.get_name (| globals, "c" |) + |), BinOp.mod_ (| BinOp.add (| - M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "c" |) |), - M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "d" |) |) + M.get_subscript (| + M.get_name (| globals, "v" |), + M.get_name (| globals, "c" |) + |), + M.get_subscript (| + M.get_name (| globals, "v" |), + M.get_name (| globals, "d" |) + |) |), M.get_field (| M.get_name (| globals, "self" |), "max_word" |) |) |) in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "b" |) |), + M.get_subscript (| + M.get_name (| globals, "v" |), + M.get_name (| globals, "b" |) + |), BinOp.bit_xor (| BinOp.r_shift (| BinOp.bit_xor (| - M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "b" |) |), - M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "c" |) |) + M.get_subscript (| + M.get_name (| globals, "v" |), + M.get_name (| globals, "b" |) + |), + M.get_subscript (| + M.get_name (| globals, "v" |), + M.get_name (| globals, "c" |) + |) |), M.get_field (| M.get_name (| globals, "self" |), "R2" |) |), BinOp.mod_ (| BinOp.l_shift (| BinOp.bit_xor (| - M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "b" |) |), - M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "c" |) |) + M.get_subscript (| + M.get_name (| globals, "v" |), + M.get_name (| globals, "b" |) + |), + M.get_subscript (| + M.get_name (| globals, "v" |), + M.get_name (| globals, "c" |) + |) |), M.get_field (| M.get_name (| globals, "self" |), "w_R2" |) |), @@ -236,12 +303,21 @@ Definition Blake2 : Value.t := |) |) in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "a" |) |), + M.get_subscript (| + M.get_name (| globals, "v" |), + M.get_name (| globals, "a" |) + |), BinOp.mod_ (| BinOp.add (| BinOp.add (| - M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "a" |) |), - M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "b" |) |) + M.get_subscript (| + M.get_name (| globals, "v" |), + M.get_name (| globals, "a" |) + |), + M.get_subscript (| + M.get_name (| globals, "v" |), + M.get_name (| globals, "b" |) + |) |), M.get_name (| globals, "y" |) |), @@ -249,20 +325,35 @@ Definition Blake2 : Value.t := |) |) in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "d" |) |), + M.get_subscript (| + M.get_name (| globals, "v" |), + M.get_name (| globals, "d" |) + |), BinOp.bit_xor (| BinOp.r_shift (| BinOp.bit_xor (| - M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "d" |) |), - M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "a" |) |) + M.get_subscript (| + M.get_name (| globals, "v" |), + M.get_name (| globals, "d" |) + |), + M.get_subscript (| + M.get_name (| globals, "v" |), + M.get_name (| globals, "a" |) + |) |), M.get_field (| M.get_name (| globals, "self" |), "R3" |) |), BinOp.mod_ (| BinOp.l_shift (| BinOp.bit_xor (| - M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "d" |) |), - M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "a" |) |) + M.get_subscript (| + M.get_name (| globals, "v" |), + M.get_name (| globals, "d" |) + |), + M.get_subscript (| + M.get_name (| globals, "v" |), + M.get_name (| globals, "a" |) + |) |), M.get_field (| M.get_name (| globals, "self" |), "w_R3" |) |), @@ -271,30 +362,54 @@ Definition Blake2 : Value.t := |) |) in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "c" |) |), + M.get_subscript (| + M.get_name (| globals, "v" |), + M.get_name (| globals, "c" |) + |), BinOp.mod_ (| BinOp.add (| - M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "c" |) |), - M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "d" |) |) + M.get_subscript (| + M.get_name (| globals, "v" |), + M.get_name (| globals, "c" |) + |), + M.get_subscript (| + M.get_name (| globals, "v" |), + M.get_name (| globals, "d" |) + |) |), M.get_field (| M.get_name (| globals, "self" |), "max_word" |) |) |) in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "b" |) |), + M.get_subscript (| + M.get_name (| globals, "v" |), + M.get_name (| globals, "b" |) + |), BinOp.bit_xor (| BinOp.r_shift (| BinOp.bit_xor (| - M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "b" |) |), - M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "c" |) |) + M.get_subscript (| + M.get_name (| globals, "v" |), + M.get_name (| globals, "b" |) + |), + M.get_subscript (| + M.get_name (| globals, "v" |), + M.get_name (| globals, "c" |) + |) |), M.get_field (| M.get_name (| globals, "self" |), "R4" |) |), BinOp.mod_ (| BinOp.l_shift (| BinOp.bit_xor (| - M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "b" |) |), - M.get_subscript (| M.get_name (| globals, "v" |), M.get_name (| globals, "c" |) |) + M.get_subscript (| + M.get_name (| globals, "v" |), + M.get_name (| globals, "b" |) + |), + M.get_subscript (| + M.get_name (| globals, "v" |), + M.get_name (| globals, "c" |) + |) |), M.get_field (| M.get_name (| globals, "self" |), "w_R4" |) |), @@ -336,25 +451,47 @@ Definition Blake2 : Value.t := Constant.int 16 |) in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "v" |), M.slice (| Constant.int 0, Constant.int 8 |) |), + M.slice (| + M.get_name (| globals, "v" |), + Constant.int 0, + Constant.int 8, + Constant.None_ + |), M.get_name (| globals, "h" |) |) in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "v" |), M.slice (| Constant.int 8, Constant.int 15 |) |), + M.slice (| + M.get_name (| globals, "v" |), + Constant.int 8, + Constant.int 15, + Constant.None_ + |), M.get_field (| M.get_name (| globals, "self" |), "IV" |) |) in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "v" |), Constant.int 12 |), + M.get_subscript (| + M.get_name (| globals, "v" |), + Constant.int 12 + |), BinOp.bit_xor (| M.get_name (| globals, "t_0" |), - M.get_subscript (| M.get_field (| M.get_name (| globals, "self" |), "IV" |), Constant.int 4 |) + M.get_subscript (| + M.get_field (| M.get_name (| globals, "self" |), "IV" |), + Constant.int 4 + |) |) |) in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "v" |), Constant.int 13 |), + M.get_subscript (| + M.get_name (| globals, "v" |), + Constant.int 13 + |), BinOp.bit_xor (| M.get_name (| globals, "t_1" |), - M.get_subscript (| M.get_field (| M.get_name (| globals, "self" |), "IV" |), Constant.int 5 |) + M.get_subscript (| + M.get_field (| M.get_name (| globals, "self" |), "IV" |), + Constant.int 5 + |) |) |) in let _ := @@ -364,9 +501,15 @@ Definition Blake2 : Value.t := (* then *) ltac:(M.monadic ( let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "v" |), Constant.int 14 |), + M.get_subscript (| + M.get_name (| globals, "v" |), + Constant.int 14 + |), BinOp.bit_xor (| - M.get_subscript (| M.get_name (| globals, "v" |), Constant.int 14 |), + M.get_subscript (| + M.get_name (| globals, "v" |), + Constant.int 14 + |), M.get_field (| M.get_name (| globals, "self" |), "mask_bits" |) |) |) in @@ -375,131 +518,239 @@ Definition Blake2 : Value.t := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - For M.get_name (| globals, "r" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - M.get_name (| globals, "num_rounds" |) - ], - make_dict [] - |) do - let s := - M.get_subscript (| M.get_field (| M.get_name (| globals, "self" |), "sigma" |), BinOp.mod_ (| - M.get_name (| globals, "r" |), - M.get_field (| M.get_name (| globals, "self" |), "sigma_len" |) - |) |) in - let v := - M.call (| - M.get_field (| M.get_name (| globals, "self" |), "G" |), - make_list [ - M.get_name (| globals, "v" |); - Constant.int 0; - Constant.int 4; - Constant.int 8; - Constant.int 12; - M.get_subscript (| M.get_name (| globals, "m" |), M.get_subscript (| M.get_name (| globals, "s" |), Constant.int 0 |) |); - M.get_subscript (| M.get_name (| globals, "m" |), M.get_subscript (| M.get_name (| globals, "s" |), Constant.int 1 |) |) - ], - make_dict [] - |) in - let v := - M.call (| - M.get_field (| M.get_name (| globals, "self" |), "G" |), - make_list [ - M.get_name (| globals, "v" |); - Constant.int 1; - Constant.int 5; - Constant.int 9; - Constant.int 13; - M.get_subscript (| M.get_name (| globals, "m" |), M.get_subscript (| M.get_name (| globals, "s" |), Constant.int 2 |) |); - M.get_subscript (| M.get_name (| globals, "m" |), M.get_subscript (| M.get_name (| globals, "s" |), Constant.int 3 |) |) - ], - make_dict [] - |) in - let v := - M.call (| - M.get_field (| M.get_name (| globals, "self" |), "G" |), - make_list [ - M.get_name (| globals, "v" |); - Constant.int 2; - Constant.int 6; - Constant.int 10; - Constant.int 14; - M.get_subscript (| M.get_name (| globals, "m" |), M.get_subscript (| M.get_name (| globals, "s" |), Constant.int 4 |) |); - M.get_subscript (| M.get_name (| globals, "m" |), M.get_subscript (| M.get_name (| globals, "s" |), Constant.int 5 |) |) - ], - make_dict [] - |) in - let v := - M.call (| - M.get_field (| M.get_name (| globals, "self" |), "G" |), - make_list [ - M.get_name (| globals, "v" |); - Constant.int 3; - Constant.int 7; - Constant.int 11; - Constant.int 15; - M.get_subscript (| M.get_name (| globals, "m" |), M.get_subscript (| M.get_name (| globals, "s" |), Constant.int 6 |) |); - M.get_subscript (| M.get_name (| globals, "m" |), M.get_subscript (| M.get_name (| globals, "s" |), Constant.int 7 |) |) - ], - make_dict [] - |) in - let v := - M.call (| - M.get_field (| M.get_name (| globals, "self" |), "G" |), - make_list [ - M.get_name (| globals, "v" |); - Constant.int 0; - Constant.int 5; - Constant.int 10; - Constant.int 15; - M.get_subscript (| M.get_name (| globals, "m" |), M.get_subscript (| M.get_name (| globals, "s" |), Constant.int 8 |) |); - M.get_subscript (| M.get_name (| globals, "m" |), M.get_subscript (| M.get_name (| globals, "s" |), Constant.int 9 |) |) - ], - make_dict [] - |) in - let v := - M.call (| - M.get_field (| M.get_name (| globals, "self" |), "G" |), - make_list [ - M.get_name (| globals, "v" |); - Constant.int 1; - Constant.int 6; - Constant.int 11; - Constant.int 12; - M.get_subscript (| M.get_name (| globals, "m" |), M.get_subscript (| M.get_name (| globals, "s" |), Constant.int 10 |) |); - M.get_subscript (| M.get_name (| globals, "m" |), M.get_subscript (| M.get_name (| globals, "s" |), Constant.int 11 |) |) - ], - make_dict [] - |) in - let v := - M.call (| - M.get_field (| M.get_name (| globals, "self" |), "G" |), - make_list [ - M.get_name (| globals, "v" |); - Constant.int 2; - Constant.int 7; - Constant.int 8; - Constant.int 13; - M.get_subscript (| M.get_name (| globals, "m" |), M.get_subscript (| M.get_name (| globals, "s" |), Constant.int 12 |) |); - M.get_subscript (| M.get_name (| globals, "m" |), M.get_subscript (| M.get_name (| globals, "s" |), Constant.int 13 |) |) - ], - make_dict [] - |) in - let v := + let _ := + M.for_ (| + M.get_name (| globals, "r" |), M.call (| - M.get_field (| M.get_name (| globals, "self" |), "G" |), - make_list [ - M.get_name (| globals, "v" |); - Constant.int 3; - Constant.int 4; - Constant.int 9; - Constant.int 14; - M.get_subscript (| M.get_name (| globals, "m" |), M.get_subscript (| M.get_name (| globals, "s" |), Constant.int 14 |) |); - M.get_subscript (| M.get_name (| globals, "m" |), M.get_subscript (| M.get_name (| globals, "s" |), Constant.int 15 |) |) - ], - make_dict [] - |) in - EndFor. + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "num_rounds" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let s := + M.get_subscript (| + M.get_field (| M.get_name (| globals, "self" |), "sigma" |), + BinOp.mod_ (| + M.get_name (| globals, "r" |), + M.get_field (| M.get_name (| globals, "self" |), "sigma_len" |) + |) + |) in + let v := + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "G" |), + make_list [ + M.get_name (| globals, "v" |); + Constant.int 0; + Constant.int 4; + Constant.int 8; + Constant.int 12; + M.get_subscript (| + M.get_name (| globals, "m" |), + M.get_subscript (| + M.get_name (| globals, "s" |), + Constant.int 0 + |) + |); + M.get_subscript (| + M.get_name (| globals, "m" |), + M.get_subscript (| + M.get_name (| globals, "s" |), + Constant.int 1 + |) + |) + ], + make_dict [] + |) in + let v := + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "G" |), + make_list [ + M.get_name (| globals, "v" |); + Constant.int 1; + Constant.int 5; + Constant.int 9; + Constant.int 13; + M.get_subscript (| + M.get_name (| globals, "m" |), + M.get_subscript (| + M.get_name (| globals, "s" |), + Constant.int 2 + |) + |); + M.get_subscript (| + M.get_name (| globals, "m" |), + M.get_subscript (| + M.get_name (| globals, "s" |), + Constant.int 3 + |) + |) + ], + make_dict [] + |) in + let v := + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "G" |), + make_list [ + M.get_name (| globals, "v" |); + Constant.int 2; + Constant.int 6; + Constant.int 10; + Constant.int 14; + M.get_subscript (| + M.get_name (| globals, "m" |), + M.get_subscript (| + M.get_name (| globals, "s" |), + Constant.int 4 + |) + |); + M.get_subscript (| + M.get_name (| globals, "m" |), + M.get_subscript (| + M.get_name (| globals, "s" |), + Constant.int 5 + |) + |) + ], + make_dict [] + |) in + let v := + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "G" |), + make_list [ + M.get_name (| globals, "v" |); + Constant.int 3; + Constant.int 7; + Constant.int 11; + Constant.int 15; + M.get_subscript (| + M.get_name (| globals, "m" |), + M.get_subscript (| + M.get_name (| globals, "s" |), + Constant.int 6 + |) + |); + M.get_subscript (| + M.get_name (| globals, "m" |), + M.get_subscript (| + M.get_name (| globals, "s" |), + Constant.int 7 + |) + |) + ], + make_dict [] + |) in + let v := + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "G" |), + make_list [ + M.get_name (| globals, "v" |); + Constant.int 0; + Constant.int 5; + Constant.int 10; + Constant.int 15; + M.get_subscript (| + M.get_name (| globals, "m" |), + M.get_subscript (| + M.get_name (| globals, "s" |), + Constant.int 8 + |) + |); + M.get_subscript (| + M.get_name (| globals, "m" |), + M.get_subscript (| + M.get_name (| globals, "s" |), + Constant.int 9 + |) + |) + ], + make_dict [] + |) in + let v := + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "G" |), + make_list [ + M.get_name (| globals, "v" |); + Constant.int 1; + Constant.int 6; + Constant.int 11; + Constant.int 12; + M.get_subscript (| + M.get_name (| globals, "m" |), + M.get_subscript (| + M.get_name (| globals, "s" |), + Constant.int 10 + |) + |); + M.get_subscript (| + M.get_name (| globals, "m" |), + M.get_subscript (| + M.get_name (| globals, "s" |), + Constant.int 11 + |) + |) + ], + make_dict [] + |) in + let v := + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "G" |), + make_list [ + M.get_name (| globals, "v" |); + Constant.int 2; + Constant.int 7; + Constant.int 8; + Constant.int 13; + M.get_subscript (| + M.get_name (| globals, "m" |), + M.get_subscript (| + M.get_name (| globals, "s" |), + Constant.int 12 + |) + |); + M.get_subscript (| + M.get_name (| globals, "m" |), + M.get_subscript (| + M.get_name (| globals, "s" |), + Constant.int 13 + |) + |) + ], + make_dict [] + |) in + let v := + M.call (| + M.get_field (| M.get_name (| globals, "self" |), "G" |), + make_list [ + M.get_name (| globals, "v" |); + Constant.int 3; + Constant.int 4; + Constant.int 9; + Constant.int 14; + M.get_subscript (| + M.get_name (| globals, "m" |), + M.get_subscript (| + M.get_name (| globals, "s" |), + Constant.int 14 + |) + |); + M.get_subscript (| + M.get_name (| globals, "m" |), + M.get_subscript (| + M.get_name (| globals, "s" |), + Constant.int 15 + |) + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let result_message_words := Constant.str "(* At expr: unsupported node type: GeneratorExp *)" in let _ := M.return_ (| diff --git a/CoqOfPython/ethereum/crypto/elliptic_curve.v b/CoqOfPython/ethereum/crypto/elliptic_curve.v index b70039d..da924f9 100644 --- a/CoqOfPython/ethereum/crypto/elliptic_curve.v +++ b/CoqOfPython/ethereum/crypto/elliptic_curve.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.crypto.elliptic_curve". Definition expr_1 : Value.t := Constant.str " @@ -8,29 +8,19 @@ Elliptic Curves ^^^^^^^^^^^^^^^ ". -Require typing. -Axiom typing_Generic : - IsGlobalAlias globals typing.globals "Generic". -Axiom typing_Type_ : - IsGlobalAlias globals typing.globals "Type_". -Axiom typing_TypeVar : - IsGlobalAlias globals typing.globals "TypeVar". +Axiom typing_imports : + AreImported globals "typing" [ "Generic"; "Type"; "TypeVar" ]. (* At top_level_stmt: unsupported node type: Import *) -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes" ]. -Require ethereum.crypto.finite_field. -Axiom ethereum_crypto_finite_field_Field : - IsGlobalAlias globals ethereum.crypto.finite_field.globals "Field". +Axiom ethereum_crypto_finite_field_imports : + AreImported globals "ethereum.crypto.finite_field" [ "Field" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. Definition SECP256K1N : Value.t := M.run ltac:(M.monadic ( Constant.int 115792089237316195423570985008687907852837564279074904382605163141518161494337 @@ -104,33 +94,46 @@ Definition secp256k1_recover : Value.t -> Value.t -> M := make_dict [] |) in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "signature" |), M.slice (| BinOp.sub (| + M.slice (| + M.get_name (| globals, "signature" |), + BinOp.sub (| + Constant.int 32, + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "r_bytes" |) + ], + make_dict [] + |) + |), Constant.int 32, - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "r_bytes" |) - ], - make_dict [] - |) - |), Constant.int 32 |) |), + Constant.None_ + |), M.get_name (| globals, "r_bytes" |) |) in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "signature" |), M.slice (| BinOp.sub (| + M.slice (| + M.get_name (| globals, "signature" |), + BinOp.sub (| + Constant.int 64, + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "s_bytes" |) + ], + make_dict [] + |) + |), Constant.int 64, - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "s_bytes" |) - ], - make_dict [] - |) - |), Constant.int 64 |) |), + Constant.None_ + |), M.get_name (| globals, "s_bytes" |) |) in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "signature" |), Constant.int 64 |), + M.get_subscript (| + M.get_name (| globals, "signature" |), + Constant.int 64 + |), M.get_name (| globals, "v" |) |) in let public_key := @@ -149,11 +152,16 @@ Definition secp256k1_recover : Value.t -> Value.t -> M := make_dict [] |) in let public_key := - M.get_subscript (| M.call (| - M.get_field (| M.get_name (| globals, "public_key" |), "format" |), - make_list [], - make_dict [] - |), M.slice (| Constant.int 1, Constant.None_ |) |) in + M.slice (| + M.call (| + M.get_field (| M.get_name (| globals, "public_key" |), "format" |), + make_list [], + make_dict [] + |), + Constant.int 1, + Constant.None_, + Constant.None_ + |) in let _ := M.return_ (| M.get_name (| globals, "public_key" |) |) in @@ -289,7 +297,7 @@ Definition EllipticCurve : Value.t := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "ValueError" |), make_list [ Constant.str "Point not on curve" @@ -671,41 +679,49 @@ Definition EllipticCurve : Value.t := |) in let s := M.get_name (| globals, "self" |) in - While Compare.not_eq (| - M.get_name (| globals, "n" |), - Constant.int 0 - |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - BinOp.mod_ (| - M.get_name (| globals, "n" |), - Constant.int 2 - |), - Constant.int 1 - |), - (* then *) + let _ := + M.while (| + Compare.not_eq (| + M.get_name (| globals, "n" |), + Constant.int 0 + |), ltac:(M.monadic ( - let res := + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + BinOp.mod_ (| + M.get_name (| globals, "n" |), + Constant.int 2 + |), + Constant.int 1 + |), + (* then *) + ltac:(M.monadic ( + let res := + BinOp.add (| + M.get_name (| globals, "res" |), + M.get_name (| globals, "s" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let s := BinOp.add (| - M.get_name (| globals, "res" |), + M.get_name (| globals, "s" |), M.get_name (| globals, "s" |) |) in + let n := BinOp.floor_div + Constant.int 2 + Constant.int 2 in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - let s := - BinOp.add (| - M.get_name (| globals, "s" |), - M.get_name (| globals, "s" |) - |) in - let n := BinOp.floor_div - Constant.int 2 - Constant.int 2 in - EndWhile. + )) + |) in let _ := M.return_ (| M.get_name (| globals, "res" |) |) in diff --git a/CoqOfPython/ethereum/crypto/finite_field.v b/CoqOfPython/ethereum/crypto/finite_field.v index c6a59cd..71dd446 100644 --- a/CoqOfPython/ethereum/crypto/finite_field.v +++ b/CoqOfPython/ethereum/crypto/finite_field.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.crypto.finite_field". Definition expr_1 : Value.t := Constant.str " @@ -8,29 +8,14 @@ Finite Fields ^^^^^^^^^^^^^ ". -Require typing. -Axiom typing_Iterable : - IsGlobalAlias globals typing.globals "Iterable". -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Type_ : - IsGlobalAlias globals typing.globals "Type_". -Axiom typing_TypeVar : - IsGlobalAlias globals typing.globals "TypeVar". -Axiom typing_cast : - IsGlobalAlias globals typing.globals "cast". +Axiom typing_imports : + AreImported globals "typing" [ "Iterable"; "List"; "Tuple"; "Type"; "TypeVar"; "cast" ]. -Require typing_extensions. -Axiom typing_extensions_Protocol : - IsGlobalAlias globals typing_extensions.globals "Protocol". +Axiom typing_extensions_imports : + AreImported globals "typing_extensions" [ "Protocol" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Bytes"; "Bytes32" ]. Definition F : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -731,37 +716,44 @@ Definition GaloisField : Value.t := " in let coefficients := make_list [] in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "cls" |), "MODULUS" |) - ], - make_dict [] - |) - ], - make_dict [] - |) do - let x := - BinOp.mult (| - make_list [ - Constant.int 0 - ], - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "cls" |), "MODULUS" |) - ], - make_dict [] - |) - |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |), - Constant.int 1 - |) in - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "cls" |), "MODULUS" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let x := + BinOp.mult (| + make_list [ + Constant.int 0 + ], + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "cls" |), "MODULUS" |) + ], + make_dict [] + |) + |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "i" |) + |), + Constant.int 1 + |) in + let _ := M.call (| M.get_field (| M.get_name (| globals, "coefficients" |), "append" |), make_list [ BinOp.pow (| @@ -778,7 +770,12 @@ Definition GaloisField : Value.t := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "tuple" |), @@ -1031,81 +1028,135 @@ Definition GaloisField : Value.t := Constant.int 2 |) |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - M.get_name (| globals, "degree" |) - ], - make_dict [] - |) do - For M.get_name (| globals, "j" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - M.get_name (| globals, "degree" |) - ], - make_dict [] - |) do - let _ := M.assign_op (| - BinOp.add, - M.get_subscript (| M.get_name (| globals, "mul" |), BinOp.add (| - M.get_name (| globals, "i" |), - M.get_name (| globals, "j" |) - |) |), - BinOp.mult (| - M.get_subscript (| M.get_name (| globals, "self" |), M.get_name (| globals, "i" |) |), - M.get_subscript (| M.get_name (| globals, "right" |), M.get_name (| globals, "j" |) |) - |) - |) in - EndFor. - EndFor. - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - BinOp.sub (| - BinOp.mult (| - M.get_name (| globals, "degree" |), - Constant.int 2 - |), - Constant.int 1 - |); - BinOp.sub (| - M.get_name (| globals, "degree" |), - Constant.int 1 - |); - UnOp.sub (| Constant.int 1 |) - ], - make_dict [] - |) do - For M.get_name (| globals, "j" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - BinOp.sub (| - M.get_name (| globals, "i" |), + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ M.get_name (| globals, "degree" |) - |); + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := + M.for_ (| + M.get_name (| globals, "j" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "degree" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.add, + M.get_subscript (| + M.get_name (| globals, "mul" |), + BinOp.add (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "j" |) + |) + |), + BinOp.mult (| + M.get_subscript (| + M.get_name (| globals, "self" |), M.get_name (| globals, "i" |) - ], - make_dict [] - |) do - let _ := M.assign_op (| - BinOp.sub, - M.get_subscript (| M.get_name (| globals, "mul" |), M.get_name (| globals, "j" |) |), - BinOp.mod_ (| - BinOp.mult (| - M.get_subscript (| M.get_name (| globals, "mul" |), M.get_name (| globals, "i" |) |), - M.get_subscript (| M.get_name (| globals, "modulus" |), BinOp.sub (| - M.get_name (| globals, "degree" |), + |), + M.get_subscript (| + M.get_name (| globals, "right" |), + M.get_name (| globals, "j" |) + |) + |) + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + BinOp.sub (| + BinOp.mult (| + M.get_name (| globals, "degree" |), + Constant.int 2 + |), + Constant.int 1 + |); + BinOp.sub (| + M.get_name (| globals, "degree" |), + Constant.int 1 + |); + UnOp.sub (| Constant.int 1 |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := + M.for_ (| + M.get_name (| globals, "j" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ BinOp.sub (| M.get_name (| globals, "i" |), - M.get_name (| globals, "j" |) + M.get_name (| globals, "degree" |) + |); + M.get_name (| globals, "i" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.sub, + M.get_subscript (| + M.get_name (| globals, "mul" |), + M.get_name (| globals, "j" |) + |), + BinOp.mod_ (| + BinOp.mult (| + M.get_subscript (| + M.get_name (| globals, "mul" |), + M.get_name (| globals, "i" |) + |), + M.get_subscript (| + M.get_name (| globals, "modulus" |), + BinOp.sub (| + M.get_name (| globals, "degree" |), + BinOp.sub (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "j" |) + |) |) - |) |) + |) |), M.get_name (| globals, "prime" |) |) - |) in - EndFor. - EndFor. + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "self" |), "__new__" |), @@ -1117,7 +1168,12 @@ Definition GaloisField : Value.t := ], make_dict [] |); - M.get_subscript (| M.get_name (| globals, "mul" |), M.slice (| Constant.None_, M.get_name (| globals, "degree" |) |) |) + M.slice (| + M.get_name (| globals, "mul" |), + Constant.None_, + M.get_name (| globals, "degree" |), + Constant.None_ + |) ], make_dict [] |) @@ -1225,43 +1281,55 @@ Definition GaloisField : Value.t := let _ := Constant.str " This is a support function for `multiplicative_inverse()`. " in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - BinOp.sub (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "self" |), "MODULUS" |) - ], - make_dict [] - |), - Constant.int 1 - |); - UnOp.sub (| Constant.int 1 |); - UnOp.sub (| Constant.int 1 |) - ], - make_dict [] - |) do - let _ := - (* if *) - M.if_then_else (| - Compare.not_eq (| - M.get_subscript (| M.get_name (| globals, "self" |), M.get_name (| globals, "i" |) |), - Constant.int 0 - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + BinOp.sub (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "self" |), "MODULUS" |) + ], + make_dict [] + |), + Constant.int 1 + |); + UnOp.sub (| Constant.int 1 |); + UnOp.sub (| Constant.int 1 |) + ], + make_dict [] + |), ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "i" |) - |) in + let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| + M.get_subscript (| + M.get_name (| globals, "self" |), + M.get_name (| globals, "i" |) + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. - let _ := M.raise (| Some(M.call (| + )) + |) in + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "ValueError" |), make_list [ Constant.str "deg() does not support zero" @@ -1338,418 +1406,583 @@ Definition GaloisField : Value.t := M.call (| M.get_name (| globals, "pow" |), make_list [ - M.get_subscript (| M.get_name (| globals, "x2" |), M.get_name (| globals, "d2" |) |); + M.get_subscript (| + M.get_name (| globals, "x2" |), + M.get_name (| globals, "d2" |) + |); UnOp.sub (| Constant.int 1 |); M.get_name (| globals, "p" |) ], make_dict [] |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - M.get_name (| globals, "d2" |) - ], - make_dict [] - |) do - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "x1" |), BinOp.sub (| - BinOp.add (| - M.get_name (| globals, "i" |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x1" |) - ], - make_dict [] - |) - |), - M.get_name (| globals, "d2" |) - |) |), - BinOp.mod_ (| - BinOp.sub (| - M.get_subscript (| M.get_name (| globals, "x1" |), BinOp.sub (| - BinOp.add (| - M.get_name (| globals, "i" |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x1" |) - ], - make_dict [] + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "d2" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "x1" |), + BinOp.sub (| + BinOp.add (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x1" |) + ], + make_dict [] + |) + |), + M.get_name (| globals, "d2" |) + |) + |), + BinOp.mod_ (| + BinOp.sub (| + M.get_subscript (| + M.get_name (| globals, "x1" |), + BinOp.sub (| + BinOp.add (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x1" |) + ], + make_dict [] + |) + |), + M.get_name (| globals, "d2" |) + |) + |), + BinOp.mult (| + M.get_name (| globals, "q_0" |), + M.get_subscript (| + M.get_name (| globals, "x2" |), + M.get_name (| globals, "i" |) + |) |) |), - M.get_name (| globals, "d2" |) - |) |), - BinOp.mult (| - M.get_name (| globals, "q_0" |), - M.get_subscript (| M.get_name (| globals, "x2" |), M.get_name (| globals, "i" |) |) - |) - |), - M.get_name (| globals, "p" |) - |) - |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "f1" |), BinOp.sub (| - BinOp.add (| - M.get_name (| globals, "i" |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x1" |) - ], - make_dict [] + M.get_name (| globals, "p" |) |) - |), - M.get_name (| globals, "d2" |) - |) |), - BinOp.mod_ (| - BinOp.sub (| - M.get_subscript (| M.get_name (| globals, "f1" |), BinOp.sub (| - BinOp.add (| - M.get_name (| globals, "i" |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x1" |) - ], - make_dict [] + |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "f1" |), + BinOp.sub (| + BinOp.add (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x1" |) + ], + make_dict [] + |) + |), + M.get_name (| globals, "d2" |) + |) + |), + BinOp.mod_ (| + BinOp.sub (| + M.get_subscript (| + M.get_name (| globals, "f1" |), + BinOp.sub (| + BinOp.add (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x1" |) + ], + make_dict [] + |) + |), + M.get_name (| globals, "d2" |) + |) + |), + BinOp.mult (| + M.get_name (| globals, "q_0" |), + M.get_subscript (| + M.get_name (| globals, "f2" |), + M.get_name (| globals, "i" |) + |) |) |), - M.get_name (| globals, "d2" |) - |) |), - BinOp.mult (| - M.get_name (| globals, "q_0" |), - M.get_subscript (| M.get_name (| globals, "f2" |), M.get_name (| globals, "i" |) |) + M.get_name (| globals, "p" |) |) - |), - M.get_name (| globals, "p" |) - |) - |) in - EndFor. - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - BinOp.sub (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "self" |), "MODULUS" |) - ], - make_dict [] - |), - Constant.int 1 - |); - UnOp.sub (| Constant.int 1 |); - UnOp.sub (| Constant.int 1 |) - ], - make_dict [] - |) do - let _ := - (* if *) - M.if_then_else (| - Compare.not_eq (| - M.get_subscript (| M.get_name (| globals, "x1" |), M.get_name (| globals, "i" |) |), - Constant.int 0 - |), - (* then *) + |) in + M.pure Constant.None_ + )), ltac:(M.monadic ( - let d1 := - M.get_name (| globals, "i" |) in - let _ := M.break (| |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )) + |) in + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + BinOp.sub (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "self" |), "MODULUS" |) + ], + make_dict [] + |), + Constant.int 1 + |); + UnOp.sub (| Constant.int 1 |); + UnOp.sub (| Constant.int 1 |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.not_eq (| + M.get_subscript (| + M.get_name (| globals, "x1" |), + M.get_name (| globals, "i" |) + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let d1 := + M.get_name (| globals, "i" |) in + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - )) |) in - EndFor. - While Constant.bool true do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "d1" |), - Constant.int 0 - |), - (* then *) + )), ltac:(M.monadic ( - let ans := - M.get_name (| globals, "f1" |) in - let q := - M.call (| - M.get_name (| globals, "pow" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "x1" |), Constant.int 0 |); - UnOp.sub (| Constant.int 1 |); - M.get_field (| M.get_name (| globals, "self" |), "PRIME" |) - ], - make_dict [] - |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "ans" |) - ], - make_dict [] - |) - ], - make_dict [] - |) do - let _ := M.assign_op (| - BinOp.mult, - M.get_subscript (| M.get_name (| globals, "ans" |), M.get_name (| globals, "i" |) |), - M.get_name (| globals, "q" |) - |) in - EndFor. - let _ := M.break (| |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )) + |) in + let _ := + M.while (| + Constant.bool true, + ltac:(M.monadic ( let _ := (* if *) M.if_then_else (| Compare.eq (| - M.get_name (| globals, "d2" |), + M.get_name (| globals, "d1" |), Constant.int 0 |), (* then *) ltac:(M.monadic ( let ans := - M.get_name (| globals, "f2" |) in + M.get_name (| globals, "f1" |) in let q := M.call (| M.get_name (| globals, "pow" |), make_list [ - M.get_subscript (| M.get_name (| globals, "x2" |), Constant.int 0 |); + M.get_subscript (| + M.get_name (| globals, "x1" |), + Constant.int 0 + |); UnOp.sub (| Constant.int 1 |); M.get_field (| M.get_name (| globals, "self" |), "PRIME" |) ], make_dict [] |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "ans" |) - ], - make_dict [] - |) - ], - make_dict [] - |) do - let ans := BinOp.mult - M.get_name (| globals, "q" |) - M.get_name (| globals, "q" |) in - EndFor. - let _ := M.break (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - M.pure Constant.None_ - )) |) in - let _ := - (* if *) - M.if_then_else (| - Compare.lt (| - M.get_name (| globals, "d1" |), - M.get_name (| globals, "d2" |) - |), - (* then *) - ltac:(M.monadic ( - let q := - BinOp.mult (| - M.get_subscript (| M.get_name (| globals, "x2" |), M.get_name (| globals, "d2" |) |), - M.call (| - M.get_name (| globals, "pow" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "x1" |), M.get_name (| globals, "d1" |) |); - UnOp.sub (| Constant.int 1 |); - M.get_field (| M.get_name (| globals, "self" |), "PRIME" |) - ], - make_dict [] - |) - |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - BinOp.sub (| + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ M.call (| M.get_name (| globals, "len" |), make_list [ - M.get_field (| M.get_name (| globals, "self" |), "MODULUS" |) + M.get_name (| globals, "ans" |) ], make_dict [] - |), - BinOp.sub (| - M.get_name (| globals, "d2" |), - M.get_name (| globals, "d1" |) |) - |) - ], - make_dict [] - |) do - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "x2" |), BinOp.add (| - M.get_name (| globals, "i" |), - BinOp.sub (| - M.get_name (| globals, "d2" |), - M.get_name (| globals, "d1" |) - |) - |) |), - BinOp.mod_ (| - BinOp.sub (| - M.get_subscript (| M.get_name (| globals, "x2" |), BinOp.add (| - M.get_name (| globals, "i" |), - BinOp.sub (| - M.get_name (| globals, "d2" |), - M.get_name (| globals, "d1" |) - |) - |) |), - BinOp.mult (| - M.get_name (| globals, "q" |), - M.get_subscript (| M.get_name (| globals, "x1" |), M.get_name (| globals, "i" |) |) - |) - |), - M.get_name (| globals, "p" |) - |) - |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "f2" |), BinOp.add (| - M.get_name (| globals, "i" |), - BinOp.sub (| - M.get_name (| globals, "d2" |), - M.get_name (| globals, "d1" |) - |) - |) |), - BinOp.mod_ (| - BinOp.sub (| - M.get_subscript (| M.get_name (| globals, "f2" |), BinOp.add (| - M.get_name (| globals, "i" |), - BinOp.sub (| - M.get_name (| globals, "d2" |), - M.get_name (| globals, "d1" |) - |) - |) |), - BinOp.mult (| - M.get_name (| globals, "q" |), - M.get_subscript (| M.get_name (| globals, "f1" |), M.get_name (| globals, "i" |) |) - |) - |), - M.get_name (| globals, "p" |) - |) - |) in - EndFor. - While Compare.eq (| - M.get_subscript (| M.get_name (| globals, "x2" |), M.get_name (| globals, "d2" |) |), - Constant.int 0 - |) do - let d2 := BinOp.sub - Constant.int 1 - Constant.int 1 in - EndWhile. - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let q := - BinOp.mult (| - M.get_subscript (| M.get_name (| globals, "x1" |), M.get_name (| globals, "d1" |) |), - M.call (| - M.get_name (| globals, "pow" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "x2" |), M.get_name (| globals, "d2" |) |); - UnOp.sub (| Constant.int 1 |); - M.get_field (| M.get_name (| globals, "self" |), "PRIME" |) - ], - make_dict [] - |) - |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - BinOp.sub (| + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.assign_op (| + BinOp.mult, + M.get_subscript (| + M.get_name (| globals, "ans" |), + M.get_name (| globals, "i" |) + |), + M.get_name (| globals, "q" |) + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "d2" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let ans := + M.get_name (| globals, "f2" |) in + let q := + M.call (| + M.get_name (| globals, "pow" |), + make_list [ + M.get_subscript (| + M.get_name (| globals, "x2" |), + Constant.int 0 + |); + UnOp.sub (| Constant.int 1 |); + M.get_field (| M.get_name (| globals, "self" |), "PRIME" |) + ], + make_dict [] + |) in + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ M.call (| M.get_name (| globals, "len" |), make_list [ - M.get_field (| M.get_name (| globals, "self" |), "MODULUS" |) + M.get_name (| globals, "ans" |) ], make_dict [] - |), - BinOp.sub (| - M.get_name (| globals, "d1" |), - M.get_name (| globals, "d2" |) |) - |) - ], - make_dict [] - |) do - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "x1" |), BinOp.add (| - M.get_name (| globals, "i" |), - BinOp.sub (| - M.get_name (| globals, "d1" |), - M.get_name (| globals, "d2" |) - |) - |) |), - BinOp.mod_ (| - BinOp.sub (| - M.get_subscript (| M.get_name (| globals, "x1" |), BinOp.add (| - M.get_name (| globals, "i" |), - BinOp.sub (| - M.get_name (| globals, "d1" |), - M.get_name (| globals, "d2" |) - |) - |) |), - BinOp.mult (| - M.get_name (| globals, "q" |), - M.get_subscript (| M.get_name (| globals, "x2" |), M.get_name (| globals, "i" |) |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let ans := BinOp.mult + M.get_name (| globals, "q" |) + M.get_name (| globals, "q" |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + M.pure Constant.None_ + )) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt (| + M.get_name (| globals, "d1" |), + M.get_name (| globals, "d2" |) + |), + (* then *) + ltac:(M.monadic ( + let q := + BinOp.mult (| + M.get_subscript (| + M.get_name (| globals, "x2" |), + M.get_name (| globals, "d2" |) + |), + M.call (| + M.get_name (| globals, "pow" |), + make_list [ + M.get_subscript (| + M.get_name (| globals, "x1" |), + M.get_name (| globals, "d1" |) + |); + UnOp.sub (| Constant.int 1 |); + M.get_field (| M.get_name (| globals, "self" |), "PRIME" |) + ], + make_dict [] |) - |), - M.get_name (| globals, "p" |) - |) - |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "f1" |), BinOp.add (| - M.get_name (| globals, "i" |), - BinOp.sub (| - M.get_name (| globals, "d1" |), - M.get_name (| globals, "d2" |) - |) - |) |), - BinOp.mod_ (| - BinOp.sub (| - M.get_subscript (| M.get_name (| globals, "f1" |), BinOp.add (| - M.get_name (| globals, "i" |), - BinOp.sub (| - M.get_name (| globals, "d1" |), - M.get_name (| globals, "d2" |) - |) - |) |), - BinOp.mult (| - M.get_name (| globals, "q" |), - M.get_subscript (| M.get_name (| globals, "f2" |), M.get_name (| globals, "i" |) |) + |) in + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + BinOp.sub (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "self" |), "MODULUS" |) + ], + make_dict [] + |), + BinOp.sub (| + M.get_name (| globals, "d2" |), + M.get_name (| globals, "d1" |) + |) + |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "x2" |), + BinOp.add (| + M.get_name (| globals, "i" |), + BinOp.sub (| + M.get_name (| globals, "d2" |), + M.get_name (| globals, "d1" |) + |) + |) + |), + BinOp.mod_ (| + BinOp.sub (| + M.get_subscript (| + M.get_name (| globals, "x2" |), + BinOp.add (| + M.get_name (| globals, "i" |), + BinOp.sub (| + M.get_name (| globals, "d2" |), + M.get_name (| globals, "d1" |) + |) + |) + |), + BinOp.mult (| + M.get_name (| globals, "q" |), + M.get_subscript (| + M.get_name (| globals, "x1" |), + M.get_name (| globals, "i" |) + |) + |) + |), + M.get_name (| globals, "p" |) + |) + |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "f2" |), + BinOp.add (| + M.get_name (| globals, "i" |), + BinOp.sub (| + M.get_name (| globals, "d2" |), + M.get_name (| globals, "d1" |) + |) + |) + |), + BinOp.mod_ (| + BinOp.sub (| + M.get_subscript (| + M.get_name (| globals, "f2" |), + BinOp.add (| + M.get_name (| globals, "i" |), + BinOp.sub (| + M.get_name (| globals, "d2" |), + M.get_name (| globals, "d1" |) + |) + |) + |), + BinOp.mult (| + M.get_name (| globals, "q" |), + M.get_subscript (| + M.get_name (| globals, "f1" |), + M.get_name (| globals, "i" |) + |) + |) + |), + M.get_name (| globals, "p" |) + |) + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + let _ := + M.while (| + Compare.eq (| + M.get_subscript (| + M.get_name (| globals, "x2" |), + M.get_name (| globals, "d2" |) + |), + Constant.int 0 + |), + ltac:(M.monadic ( + let d2 := BinOp.sub + Constant.int 1 + Constant.int 1 in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let q := + BinOp.mult (| + M.get_subscript (| + M.get_name (| globals, "x1" |), + M.get_name (| globals, "d1" |) + |), + M.call (| + M.get_name (| globals, "pow" |), + make_list [ + M.get_subscript (| + M.get_name (| globals, "x2" |), + M.get_name (| globals, "d2" |) + |); + UnOp.sub (| Constant.int 1 |); + M.get_field (| M.get_name (| globals, "self" |), "PRIME" |) + ], + make_dict [] |) - |), - M.get_name (| globals, "p" |) - |) - |) in - EndFor. - While Compare.eq (| - M.get_subscript (| M.get_name (| globals, "x1" |), M.get_name (| globals, "d1" |) |), - Constant.int 0 - |) do - let d1 := BinOp.sub - Constant.int 1 - Constant.int 1 in - EndWhile. + |) in + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + BinOp.sub (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "self" |), "MODULUS" |) + ], + make_dict [] + |), + BinOp.sub (| + M.get_name (| globals, "d1" |), + M.get_name (| globals, "d2" |) + |) + |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "x1" |), + BinOp.add (| + M.get_name (| globals, "i" |), + BinOp.sub (| + M.get_name (| globals, "d1" |), + M.get_name (| globals, "d2" |) + |) + |) + |), + BinOp.mod_ (| + BinOp.sub (| + M.get_subscript (| + M.get_name (| globals, "x1" |), + BinOp.add (| + M.get_name (| globals, "i" |), + BinOp.sub (| + M.get_name (| globals, "d1" |), + M.get_name (| globals, "d2" |) + |) + |) + |), + BinOp.mult (| + M.get_name (| globals, "q" |), + M.get_subscript (| + M.get_name (| globals, "x2" |), + M.get_name (| globals, "i" |) + |) + |) + |), + M.get_name (| globals, "p" |) + |) + |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "f1" |), + BinOp.add (| + M.get_name (| globals, "i" |), + BinOp.sub (| + M.get_name (| globals, "d1" |), + M.get_name (| globals, "d2" |) + |) + |) + |), + BinOp.mod_ (| + BinOp.sub (| + M.get_subscript (| + M.get_name (| globals, "f1" |), + BinOp.add (| + M.get_name (| globals, "i" |), + BinOp.sub (| + M.get_name (| globals, "d1" |), + M.get_name (| globals, "d2" |) + |) + |) + |), + BinOp.mult (| + M.get_name (| globals, "q" |), + M.get_subscript (| + M.get_name (| globals, "f2" |), + M.get_name (| globals, "i" |) + |) + |) + |), + M.get_name (| globals, "p" |) + |) + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + let _ := + M.while (| + Compare.eq (| + M.get_subscript (| + M.get_name (| globals, "x1" |), + M.get_name (| globals, "d1" |) + |), + Constant.int 0 + |), + ltac:(M.monadic ( + let d1 := BinOp.sub + Constant.int 1 + Constant.int 1 in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - )) |) in - EndWhile. + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "self" |), "__new__" |), @@ -1832,37 +2065,45 @@ Definition GaloisField : Value.t := |) in let s := M.get_name (| globals, "self" |) in - While Compare.not_eq (| - M.get_name (| globals, "exponent" |), - Constant.int 0 - |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - BinOp.mod_ (| - M.get_name (| globals, "exponent" |), - Constant.int 2 - |), - Constant.int 1 - |), - (* then *) + let _ := + M.while (| + Compare.not_eq (| + M.get_name (| globals, "exponent" |), + Constant.int 0 + |), ltac:(M.monadic ( - let res := BinOp.mult + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + BinOp.mod_ (| + M.get_name (| globals, "exponent" |), + Constant.int 2 + |), + Constant.int 1 + |), + (* then *) + ltac:(M.monadic ( + let res := BinOp.mult + M.get_name (| globals, "s" |) + M.get_name (| globals, "s" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let s := BinOp.mult M.get_name (| globals, "s" |) M.get_name (| globals, "s" |) in + let exponent := BinOp.floor_div + Constant.int 2 + Constant.int 2 in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - let s := BinOp.mult - M.get_name (| globals, "s" |) - M.get_name (| globals, "s" |) in - let exponent := BinOp.floor_div - Constant.int 2 - Constant.int 2 in - EndWhile. + )) + |) in let _ := M.return_ (| M.get_name (| globals, "res" |) |) in @@ -1902,20 +2143,27 @@ Definition GaloisField : Value.t := make_dict [] |) in (* At stmt: unsupported node type: AnnAssign *) - For make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "a" |) ] in M.call (| - M.get_name (| globals, "enumerate" |), - make_list [ - M.get_name (| globals, "self" |) - ], - make_dict [] - |) do - let ans := BinOp.add + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "a" |) ], M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "self" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let ans := BinOp.add + M.call (| M.get_field (| M.call (| M.get_name (| globals, "cast" |), make_list [ M.get_name (| globals, "U" |); - M.get_subscript (| M.get_field (| M.get_name (| globals, "self" |), "FROBENIUS_COEFFICIENTS" |), M.get_name (| globals, "i" |) |) + M.get_subscript (| + M.get_field (| M.get_name (| globals, "self" |), "FROBENIUS_COEFFICIENTS" |), + M.get_name (| globals, "i" |) + |) ], make_dict [] |), "scalar_mul" |), @@ -1924,12 +2172,15 @@ Definition GaloisField : Value.t := ], make_dict [] |) - M.call (| + M.call (| M.get_field (| M.call (| M.get_name (| globals, "cast" |), make_list [ M.get_name (| globals, "U" |); - M.get_subscript (| M.get_field (| M.get_name (| globals, "self" |), "FROBENIUS_COEFFICIENTS" |), M.get_name (| globals, "i" |) |) + M.get_subscript (| + M.get_field (| M.get_name (| globals, "self" |), "FROBENIUS_COEFFICIENTS" |), + M.get_name (| globals, "i" |) + |) ], make_dict [] |), "scalar_mul" |), @@ -1938,7 +2189,12 @@ Definition GaloisField : Value.t := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.get_name (| globals, "ans" |) |) in diff --git a/CoqOfPython/ethereum/crypto/hash.v b/CoqOfPython/ethereum/crypto/hash.v index 58d2b5d..4fa9d00 100644 --- a/CoqOfPython/ethereum/crypto/hash.v +++ b/CoqOfPython/ethereum/crypto/hash.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.crypto.hash". Definition expr_1 : Value.t := Constant.str " @@ -17,17 +17,11 @@ Introduction Cryptographic hashing functions. ". -Require Crypto.Hash. -Axiom Crypto_Hash_keccak : - IsGlobalAlias globals Crypto.Hash.globals "keccak". +Axiom Crypto_Hash_imports : + AreImported globals "Crypto.Hash" [ "keccak" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Bytes64 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes64". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Bytes"; "Bytes32"; "Bytes64" ]. Definition Hash32 : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes32" |) diff --git a/CoqOfPython/ethereum/dao_fork/__init__.v b/CoqOfPython/ethereum/dao_fork/__init__.v index 99f8b78..3a5a97a 100644 --- a/CoqOfPython/ethereum/dao_fork/__init__.v +++ b/CoqOfPython/ethereum/dao_fork/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.dao_fork.__init__". Definition expr_1 : Value.t := Constant.str " @@ -9,9 +9,8 @@ Attack where a vulnerable contract was drained of its ether. This fork recovers the stolen funds into a new contract. ". -Require ethereum.fork_criteria. -Axiom ethereum_fork_criteria_ByBlockNumber : - IsGlobalAlias globals ethereum.fork_criteria.globals "ByBlockNumber". +Axiom ethereum_fork_criteria_imports : + AreImported globals "ethereum.fork_criteria" [ "ByBlockNumber" ]. Definition FORK_CRITERIA : Value.t := M.run ltac:(M.monadic ( M.call (| diff --git a/CoqOfPython/ethereum/dao_fork/blocks.v b/CoqOfPython/ethereum/dao_fork/blocks.v index b46e806..a7d4e0a 100644 --- a/CoqOfPython/ethereum/dao_fork/blocks.v +++ b/CoqOfPython/ethereum/dao_fork/blocks.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.dao_fork.blocks". Definition expr_1 : Value.t := Constant.str " @@ -14,43 +14,23 @@ history of all state transitions that have happened since the genesis of the chain. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes8 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes8". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". - -Require ethereum.dao_fork.fork_types. -Axiom ethereum_dao_fork_fork_types_Address : - IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "Address". -Axiom ethereum_dao_fork_fork_types_Bloom : - IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "Bloom". -Axiom ethereum_dao_fork_fork_types_Root : - IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "Root". - -Require ethereum.dao_fork.transactions. -Axiom ethereum_dao_fork_transactions_Transaction : - IsGlobalAlias globals ethereum.dao_fork.transactions.globals "Transaction". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes8"; "Bytes32"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. + +Axiom ethereum_dao_fork_fork_types_imports : + AreImported globals "ethereum.dao_fork.fork_types" [ "Address"; "Bloom"; "Root" ]. + +Axiom ethereum_dao_fork_transactions_imports : + AreImported globals "ethereum.dao_fork.transactions" [ "Transaction" ]. Definition Header : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/dao_fork/bloom.v b/CoqOfPython/ethereum/dao_fork/bloom.v index 536d4e0..e7f9fae 100644 --- a/CoqOfPython/ethereum/dao_fork/bloom.v +++ b/CoqOfPython/ethereum/dao_fork/bloom.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.dao_fork.bloom". Definition expr_1 : Value.t := Constant.str " @@ -21,25 +21,20 @@ for efficient searching of logs by address and/or topic, by rapidly eliminating blocks and receipts from their search. ". -Require typing. -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_imports : + AreImported globals "typing" [ "Tuple" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. -Require ethereum.dao_fork.blocks. -Axiom ethereum_dao_fork_blocks_Log : - IsGlobalAlias globals ethereum.dao_fork.blocks.globals "Log". +Axiom ethereum_dao_fork_blocks_imports : + AreImported globals "ethereum.dao_fork.blocks" [ "Log" ]. -Require ethereum.dao_fork.fork_types. -Axiom ethereum_dao_fork_fork_types_Bloom : - IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "Bloom". +Axiom ethereum_dao_fork_fork_types_imports : + AreImported globals "ethereum.dao_fork.fork_types" [ "Bloom" ]. Definition add_to_bloom : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -66,50 +61,70 @@ Definition add_to_bloom : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "idx" |) in make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ] do - let bit_to_set := - BinOp.bit_and (| - M.call (| - M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "hash" |), M.slice (| M.get_name (| globals, "idx" |), BinOp.add (| - M.get_name (| globals, "idx" |), - Constant.int 2 - |) |) |) - ], - make_dict [] - |), - Constant.int 2047 - |) in - let bit_index := - BinOp.sub (| - Constant.int 2047, - M.get_name (| globals, "bit_to_set" |) - |) in - let byte_index := - BinOp.floor_div (| - M.get_name (| globals, "bit_index" |), - Constant.int 8 - |) in - let bit_value := - BinOp.l_shift (| - Constant.int 1, - BinOp.sub (| - Constant.int 7, - BinOp.mod_ (| + let _ := + M.for_ (| + M.get_name (| globals, "idx" |), + make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ], + ltac:(M.monadic ( + let bit_to_set := + BinOp.bit_and (| + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.slice (| + M.get_name (| globals, "hash" |), + M.get_name (| globals, "idx" |), + BinOp.add (| + M.get_name (| globals, "idx" |), + Constant.int 2 + |), + Constant.None_ + |) + ], + make_dict [] + |), + Constant.int 2047 + |) in + let bit_index := + BinOp.sub (| + Constant.int 2047, + M.get_name (| globals, "bit_to_set" |) + |) in + let byte_index := + BinOp.floor_div (| M.get_name (| globals, "bit_index" |), Constant.int 8 + |) in + let bit_value := + BinOp.l_shift (| + Constant.int 1, + BinOp.sub (| + Constant.int 7, + BinOp.mod_ (| + M.get_name (| globals, "bit_index" |), + Constant.int 8 + |) + |) + |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "bloom" |), + M.get_name (| globals, "byte_index" |) + |), + BinOp.bit_or (| + M.get_subscript (| + M.get_name (| globals, "bloom" |), + M.get_name (| globals, "byte_index" |) + |), + M.get_name (| globals, "bit_value" |) |) - |) - |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), - BinOp.bit_or (| - M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), - M.get_name (| globals, "bit_value" |) - |) - |) in - EndFor. + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_)). Definition logs_bloom : Value.t -> Value.t -> M := @@ -132,8 +147,12 @@ Definition logs_bloom : Value.t -> Value.t -> M := the caller address and the log topics. " in (* At stmt: unsupported node type: AnnAssign *) - For M.get_name (| globals, "log" |) in M.get_name (| globals, "logs" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "log" |), + M.get_name (| globals, "logs" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "add_to_bloom" |), make_list [ M.get_name (| globals, "bloom" |); @@ -141,8 +160,12 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "topic" |) in M.get_field (| M.get_name (| globals, "log" |), "topics" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "topic" |), + M.get_field (| M.get_name (| globals, "log" |), "topics" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "add_to_bloom" |), make_list [ M.get_name (| globals, "bloom" |); @@ -150,8 +173,18 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Bloom" |), diff --git a/CoqOfPython/ethereum/dao_fork/dao.v b/CoqOfPython/ethereum/dao_fork/dao.v index 1b3d368..5664341 100644 --- a/CoqOfPython/ethereum/dao_fork/dao.v +++ b/CoqOfPython/ethereum/dao_fork/dao.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.dao_fork.dao". Definition expr_1 : Value.t := Constant.str " @@ -20,17 +20,11 @@ collection of accounts (The Dao and all its children) to a recovery contract. The recovery contract was previously created using normal contract deployment. ". -Require ethereum.dao_fork.state. -Axiom ethereum_dao_fork_state_State : - IsGlobalAlias globals ethereum.dao_fork.state.globals "State". -Axiom ethereum_dao_fork_state_get_account : - IsGlobalAlias globals ethereum.dao_fork.state.globals "get_account". -Axiom ethereum_dao_fork_state_move_ether : - IsGlobalAlias globals ethereum.dao_fork.state.globals "move_ether". +Axiom ethereum_dao_fork_state_imports : + AreImported globals "ethereum.dao_fork.state" [ "State"; "get_account"; "move_ether" ]. -Require ethereum.dao_fork.utils.hexadecimal. -Axiom ethereum_dao_fork_utils_hexadecimal_hex_to_address : - IsGlobalAlias globals ethereum.dao_fork.utils.hexadecimal.globals "hex_to_address". +Axiom ethereum_dao_fork_utils_hexadecimal_imports : + AreImported globals "ethereum.dao_fork.utils.hexadecimal" [ "hex_to_address" ]. Definition DAO_ACCOUNTS : Value.t := M.run ltac:(M.monadic ( Constant.str "(* At expr: unsupported node type: ListComp *)" @@ -57,17 +51,21 @@ Definition apply_dao : Value.t -> Value.t -> M := state : State before applying the DAO Fork. " in - For M.get_name (| globals, "address" |) in M.get_name (| globals, "DAO_ACCOUNTS" |) do - let balance := - M.get_field (| M.call (| - M.get_name (| globals, "get_account" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), "balance" |) in - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "address" |), + M.get_name (| globals, "DAO_ACCOUNTS" |), + ltac:(M.monadic ( + let balance := + M.get_field (| M.call (| + M.get_name (| globals, "get_account" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), "balance" |) in + let _ := M.call (| M.get_name (| globals, "move_ether" |), make_list [ M.get_name (| globals, "state" |); @@ -77,5 +75,10 @@ Definition apply_dao : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/dao_fork/fork.v b/CoqOfPython/ethereum/dao_fork/fork.v index bfac7ab..ef20c56 100644 --- a/CoqOfPython/ethereum/dao_fork/fork.v +++ b/CoqOfPython/ethereum/dao_fork/fork.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.dao_fork.fork". Definition expr_1 : Value.t := Constant.str " @@ -19,145 +19,65 @@ Introduction Entry point for the Ethereum specification. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". - -Require ethereum.crypto.elliptic_curve. -Axiom ethereum_crypto_elliptic_curve_SECP256K1N : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". -Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.ethash. -Axiom ethereum_ethash_dataset_size : - IsGlobalAlias globals ethereum.ethash.globals "dataset_size". -Axiom ethereum_ethash_generate_cache : - IsGlobalAlias globals ethereum.ethash.globals "generate_cache". -Axiom ethereum_ethash_hashimoto_light : - IsGlobalAlias globals ethereum.ethash.globals "hashimoto_light". - -Require ethereum.exceptions. -Axiom ethereum_exceptions_InvalidBlock : - IsGlobalAlias globals ethereum.exceptions.globals "InvalidBlock". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U64 : - IsGlobalAlias globals ethereum.base_types.globals "U64". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_U256_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.dao_fork.__init__. -Axiom ethereum_dao_fork___init___FORK_CRITERIA : - IsGlobalAlias globals ethereum.dao_fork.__init__.globals "FORK_CRITERIA". -Axiom ethereum_dao_fork___init___vm : - IsGlobalAlias globals ethereum.dao_fork.__init__.globals "vm". - -Require ethereum.dao_fork.blocks. -Axiom ethereum_dao_fork_blocks_Block : - IsGlobalAlias globals ethereum.dao_fork.blocks.globals "Block". -Axiom ethereum_dao_fork_blocks_Header : - IsGlobalAlias globals ethereum.dao_fork.blocks.globals "Header". -Axiom ethereum_dao_fork_blocks_Log : - IsGlobalAlias globals ethereum.dao_fork.blocks.globals "Log". -Axiom ethereum_dao_fork_blocks_Receipt : - IsGlobalAlias globals ethereum.dao_fork.blocks.globals "Receipt". - -Require ethereum.dao_fork.bloom. -Axiom ethereum_dao_fork_bloom_logs_bloom : - IsGlobalAlias globals ethereum.dao_fork.bloom.globals "logs_bloom". - -Require ethereum.dao_fork.dao. -Axiom ethereum_dao_fork_dao_apply_dao : - IsGlobalAlias globals ethereum.dao_fork.dao.globals "apply_dao". - -Require ethereum.dao_fork.fork_types. -Axiom ethereum_dao_fork_fork_types_Address : - IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "Address". -Axiom ethereum_dao_fork_fork_types_Bloom : - IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "Bloom". -Axiom ethereum_dao_fork_fork_types_Root : - IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "Root". - -Require ethereum.dao_fork.state. -Axiom ethereum_dao_fork_state_State : - IsGlobalAlias globals ethereum.dao_fork.state.globals "State". -Axiom ethereum_dao_fork_state_create_ether : - IsGlobalAlias globals ethereum.dao_fork.state.globals "create_ether". -Axiom ethereum_dao_fork_state_destroy_account : - IsGlobalAlias globals ethereum.dao_fork.state.globals "destroy_account". -Axiom ethereum_dao_fork_state_get_account : - IsGlobalAlias globals ethereum.dao_fork.state.globals "get_account". -Axiom ethereum_dao_fork_state_increment_nonce : - IsGlobalAlias globals ethereum.dao_fork.state.globals "increment_nonce". -Axiom ethereum_dao_fork_state_set_account_balance : - IsGlobalAlias globals ethereum.dao_fork.state.globals "set_account_balance". -Axiom ethereum_dao_fork_state_state_root : - IsGlobalAlias globals ethereum.dao_fork.state.globals "state_root". - -Require ethereum.dao_fork.transactions. -Axiom ethereum_dao_fork_transactions_TX_BASE_COST : - IsGlobalAlias globals ethereum.dao_fork.transactions.globals "TX_BASE_COST". -Axiom ethereum_dao_fork_transactions_TX_CREATE_COST : - IsGlobalAlias globals ethereum.dao_fork.transactions.globals "TX_CREATE_COST". -Axiom ethereum_dao_fork_transactions_TX_DATA_COST_PER_NON_ZERO : - IsGlobalAlias globals ethereum.dao_fork.transactions.globals "TX_DATA_COST_PER_NON_ZERO". -Axiom ethereum_dao_fork_transactions_TX_DATA_COST_PER_ZERO : - IsGlobalAlias globals ethereum.dao_fork.transactions.globals "TX_DATA_COST_PER_ZERO". -Axiom ethereum_dao_fork_transactions_Transaction : - IsGlobalAlias globals ethereum.dao_fork.transactions.globals "Transaction". - -Require ethereum.dao_fork.trie. -Axiom ethereum_dao_fork_trie_Trie : - IsGlobalAlias globals ethereum.dao_fork.trie.globals "Trie". -Axiom ethereum_dao_fork_trie_root : - IsGlobalAlias globals ethereum.dao_fork.trie.globals "root". -Axiom ethereum_dao_fork_trie_trie_set : - IsGlobalAlias globals ethereum.dao_fork.trie.globals "trie_set". - -Require ethereum.dao_fork.utils.message. -Axiom ethereum_dao_fork_utils_message_prepare_message : - IsGlobalAlias globals ethereum.dao_fork.utils.message.globals "prepare_message". - -Require ethereum.dao_fork.vm.interpreter. -Axiom ethereum_dao_fork_vm_interpreter_process_message_call : - IsGlobalAlias globals ethereum.dao_fork.vm.interpreter.globals "process_message_call". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Bytes0" ]. + +Axiom ethereum_crypto_elliptic_curve_imports : + AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. + +Axiom ethereum_ethash_imports : + AreImported globals "ethereum.ethash" [ "dataset_size"; "generate_cache"; "hashimoto_light" ]. + +Axiom ethereum_exceptions_imports : + AreImported globals "ethereum.exceptions" [ "InvalidBlock" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U64"; "U256"; "U256_CEIL_VALUE"; "Bytes"; "Bytes32"; "Uint" ]. + +Axiom ethereum_dao_fork_imports : + AreImported globals "ethereum.dao_fork" [ "FORK_CRITERIA"; "vm" ]. + +Axiom ethereum_dao_fork_blocks_imports : + AreImported globals "ethereum.dao_fork.blocks" [ "Block"; "Header"; "Log"; "Receipt" ]. + +Axiom ethereum_dao_fork_bloom_imports : + AreImported globals "ethereum.dao_fork.bloom" [ "logs_bloom" ]. + +Axiom ethereum_dao_fork_dao_imports : + AreImported globals "ethereum.dao_fork.dao" [ "apply_dao" ]. + +Axiom ethereum_dao_fork_fork_types_imports : + AreImported globals "ethereum.dao_fork.fork_types" [ "Address"; "Bloom"; "Root" ]. + +Axiom ethereum_dao_fork_state_imports : + AreImported globals "ethereum.dao_fork.state" [ "State"; "create_ether"; "destroy_account"; "get_account"; "increment_nonce"; "set_account_balance"; "state_root" ]. + +Axiom ethereum_dao_fork_transactions_imports : + AreImported globals "ethereum.dao_fork.transactions" [ "TX_BASE_COST"; "TX_CREATE_COST"; "TX_DATA_COST_PER_NON_ZERO"; "TX_DATA_COST_PER_ZERO"; "Transaction" ]. + +Axiom ethereum_dao_fork_trie_imports : + AreImported globals "ethereum.dao_fork.trie" [ "Trie"; "root"; "trie_set" ]. + +Axiom ethereum_dao_fork_utils_message_imports : + AreImported globals "ethereum.dao_fork.utils.message" [ "prepare_message" ]. + +Axiom ethereum_dao_fork_vm_interpreter_imports : + AreImported globals "ethereum.dao_fork.vm.interpreter" [ "process_message_call" ]. Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -270,7 +190,12 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := Hashes of the recent 256 blocks in order of increasing block number. " in let recent_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) in + M.slice (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| Constant.int 255 |), + Constant.None_, + Constant.None_ + |) in let _ := (* if *) M.if_then_else (| @@ -296,17 +221,26 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := )) |) in let recent_block_hashes := make_list [] in - For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_blocks" |) do - let prev_block_hash := - M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "block" |), + M.get_name (| globals, "recent_blocks" |), + ltac:(M.monadic ( + let prev_block_hash := + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in + let _ := M.call (| M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), make_list [ M.get_name (| globals, "prev_block_hash" |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let most_recent_block_hash := M.call (| M.get_name (| globals, "keccak256" |), @@ -314,7 +248,10 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), make_list [ - M.get_field (| M.get_subscript (| M.get_name (| globals, "recent_blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) + M.get_field (| M.get_subscript (| + M.get_name (| globals, "recent_blocks" |), + UnOp.sub (| Constant.int 1 |) + |), "header" |) ], make_dict [] |) @@ -358,7 +295,10 @@ Definition state_transition : Value.t -> Value.t -> M := Block to apply to `chain`. " in let parent_header := - M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) in + M.get_field (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| Constant.int 1 |) + |), "header" |) in let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ @@ -477,7 +417,12 @@ Definition state_transition : Value.t -> Value.t -> M := ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) + M.slice (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| Constant.int 255 |), + Constant.None_, + Constant.None_ + |) |) in M.pure Constant.None_ (* else *) @@ -929,14 +874,18 @@ Definition apply_body : Value.t -> Value.t -> M := (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) - For make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "tx" |) ] in M.call (| - M.get_name (| globals, "enumerate" |), - make_list [ - M.get_name (| globals, "transactions" |) - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "tx" |) ], + M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "transactions" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ M.get_name (| globals, "transactions_trie" |); @@ -957,56 +906,56 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_address := - M.call (| - M.get_name (| globals, "check_transaction" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "gas_available" |) - ], - make_dict [] - |) in - let env := - M.call (| - M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), - make_list [], - make_dict [] - |) in - let _ := M.assign (| - make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |) ], - M.call (| - M.get_name (| globals, "process_transaction" |), - make_list [ - M.get_name (| globals, "env" |); - M.get_name (| globals, "tx" |) - ], - make_dict [] - |) - |) in - let gas_available := BinOp.sub - M.get_name (| globals, "gas_used" |) - M.get_name (| globals, "gas_used" |) in - let receipt := - M.call (| - M.get_name (| globals, "make_receipt" |), - make_list [ - M.get_name (| globals, "tx" |); + let sender_address := M.call (| - M.get_name (| globals, "state_root" |), + M.get_name (| globals, "check_transaction" |), make_list [ - M.get_name (| globals, "state" |) + M.get_name (| globals, "tx" |); + M.get_name (| globals, "gas_available" |) ], make_dict [] - |); - BinOp.sub (| - M.get_name (| globals, "block_gas_limit" |), - M.get_name (| globals, "gas_available" |) - |); - M.get_name (| globals, "logs" |) - ], - make_dict [] - |) in - let _ := M.call (| + |) in + let env := + M.call (| + M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |) ], + M.call (| + M.get_name (| globals, "process_transaction" |), + make_list [ + M.get_name (| globals, "env" |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) in + let gas_available := BinOp.sub + M.get_name (| globals, "gas_used" |) + M.get_name (| globals, "gas_used" |) in + let receipt := + M.call (| + M.get_name (| globals, "make_receipt" |), + make_list [ + M.get_name (| globals, "tx" |); + M.call (| + M.get_name (| globals, "state_root" |), + make_list [ + M.get_name (| globals, "state" |) + ], + make_dict [] + |); + BinOp.sub (| + M.get_name (| globals, "block_gas_limit" |), + M.get_name (| globals, "gas_available" |) + |); + M.get_name (| globals, "logs" |) + ], + make_dict [] + |) in + let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ M.get_name (| globals, "receipts_trie" |); @@ -1027,10 +976,15 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_logs := BinOp.add - M.get_name (| globals, "logs" |) - M.get_name (| globals, "logs" |) in - EndFor. + let block_logs := BinOp.add + M.get_name (| globals, "logs" |) + M.get_name (| globals, "logs" |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.call (| M.get_name (| globals, "pay_rewards" |), make_list [ @@ -1159,8 +1113,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "ommer" |), + M.get_name (| globals, "ommers" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ BoolOp.and (| @@ -1179,15 +1137,18 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_parent_header := - M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), BinOp.sub (| - UnOp.sub (| BinOp.sub (| - M.get_field (| M.get_name (| globals, "block_header" |), "number" |), - M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) |), - Constant.int 1 - |) |), "header" |) in - let _ := M.call (| + let ommer_parent_header := + M.get_field (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + BinOp.sub (| + UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) |), + Constant.int 1 + |) + |), "header" |) in + let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ M.get_name (| globals, "ommer" |); @@ -1195,7 +1156,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1245,33 +1211,54 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let recent_canonical_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| BinOp.add (| - M.get_name (| globals, "MAX_OMMER_DEPTH" |), - Constant.int 1 - |) |), Constant.None_ |) |) in + M.slice (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| BinOp.add (| + M.get_name (| globals, "MAX_OMMER_DEPTH" |), + Constant.int 1 + |) |), + Constant.None_, + Constant.None_ + |) in let recent_canonical_block_hashes := Constant.str "(* At expr: unsupported node type: SetComp *)" in (* At stmt: unsupported node type: AnnAssign *) - For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_canonical_blocks" |) do - let recent_ommers_hashes := + let _ := + M.for_ (| + M.get_name (| globals, "block" |), + M.get_name (| globals, "recent_canonical_blocks" |), + ltac:(M.monadic ( + let recent_ommers_hashes := + M.call (| + M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), + make_list [ + Constant.str "(* At expr: unsupported node type: SetComp *)" + ], + make_dict [] + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "ommer_index" |); M.get_name (| globals, "ommer" |) ], M.call (| - M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), - make_list [ - Constant.str "(* At expr: unsupported node type: SetComp *)" - ], - make_dict [] - |) in - EndFor. - For make_tuple [ M.get_name (| globals, "ommer_index" |); M.get_name (| globals, "ommer" |) ] in M.call (| - M.get_name (| globals, "enumerate" |), - make_list [ - M.get_name (| globals, "ommers" |) - ], - make_dict [] - |) do - let ommer_hash := - M.get_subscript (| M.get_name (| globals, "ommers_hashes" |), M.get_name (| globals, "ommer_index" |) |) in - let _ := M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let ommer_hash := + M.get_subscript (| + M.get_name (| globals, "ommers_hashes" |), + M.get_name (| globals, "ommer_index" |) + |) in + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_eq (| @@ -1282,7 +1269,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_in (| @@ -1293,7 +1280,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_in (| @@ -1304,12 +1291,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_age := - BinOp.sub (| - M.get_field (| M.get_name (| globals, "block_header" |), "number" |), - M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) in - let _ := M.call (| + let ommer_age := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) in + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ BoolOp.and (| @@ -1328,10 +1315,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.in (| + Compare.in_ (| M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), M.get_name (| globals, "recent_canonical_block_hashes" |) |); @@ -1339,7 +1326,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_eq (| @@ -1350,7 +1337,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_)). Definition pay_rewards : Value.t -> Value.t -> M := @@ -1407,30 +1399,34 @@ Definition pay_rewards : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do - let ommer_age := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - BinOp.sub (| - M.get_name (| globals, "block_number" |), - M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) - ], - make_dict [] - |) in - let ommer_miner_reward := - BinOp.floor_div (| - BinOp.mult (| - BinOp.sub (| - Constant.int 8, - M.get_name (| globals, "ommer_age" |) - |), - M.get_name (| globals, "BLOCK_REWARD" |) - |), - Constant.int 8 - |) in - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "ommer" |), + M.get_name (| globals, "ommers" |), + ltac:(M.monadic ( + let ommer_age := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "block_number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) + ], + make_dict [] + |) in + let ommer_miner_reward := + BinOp.floor_div (| + BinOp.mult (| + BinOp.sub (| + Constant.int 8, + M.get_name (| globals, "ommer_age" |) + |), + M.get_name (| globals, "BLOCK_REWARD" |) + |), + Constant.int 8 + |) in + let _ := M.call (| M.get_name (| globals, "create_ether" |), make_list [ M.get_name (| globals, "state" |); @@ -1439,7 +1435,12 @@ Definition pay_rewards : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_)). Definition process_transaction : Value.t -> Value.t -> M := @@ -1679,8 +1680,12 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "accounts_to_delete" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "output" |), "accounts_to_delete" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "destroy_account" |), make_list [ M.get_field (| M.get_name (| globals, "env" |), "state" |); @@ -1688,7 +1693,12 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |) ] |) in @@ -1776,28 +1786,37 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := " in let data_cost := Constant.int 0 in - For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "byte" |), - Constant.int 0 - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "byte" |), + M.get_field (| M.get_name (| globals, "tx" |), "data" |), ltac:(M.monadic ( - let data_cost := BinOp.add - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "byte" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let data_cost := BinOp.add - M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := (* if *) M.if_then_else (| @@ -1949,13 +1968,18 @@ Definition recover_sender : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "Address" |), make_list [ - M.get_subscript (| M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "public_key" |) - ], - make_dict [] - |), M.slice (| Constant.int 12, Constant.int 32 |) |) + M.slice (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), + Constant.int 12, + Constant.int 32, + Constant.None_ + |) ], make_dict [] |) diff --git a/CoqOfPython/ethereum/dao_fork/fork_types.v b/CoqOfPython/ethereum/dao_fork/fork_types.v index cc8e4a1..644c8bd 100644 --- a/CoqOfPython/ethereum/dao_fork/fork_types.v +++ b/CoqOfPython/ethereum/dao_fork/fork_types.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.dao_fork.fork_types". Definition expr_1 : Value.t := Constant.str " @@ -17,33 +17,17 @@ Introduction Types re-used throughout the specification, which are specific to Ethereum. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes20 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes20". -Axiom ethereum_base_types_Bytes256 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes20"; "Bytes256"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) diff --git a/CoqOfPython/ethereum/dao_fork/state.v b/CoqOfPython/ethereum/dao_fork/state.v index efaf955..0da631e 100644 --- a/CoqOfPython/ethereum/dao_fork/state.v +++ b/CoqOfPython/ethereum/dao_fork/state.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.dao_fork.state". Definition expr_1 : Value.t := Constant.str " @@ -22,61 +22,23 @@ There is a distinction between an account that does not exist and `EMPTY_ACCOUNT`. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". -Axiom dataclasses_field : - IsGlobalAlias globals dataclasses.globals "field". - -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_modify : - IsGlobalAlias globals ethereum.base_types.globals "modify". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.dao_fork.fork_types. -Axiom ethereum_dao_fork_fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "EMPTY_ACCOUNT". -Axiom ethereum_dao_fork_fork_types_Account : - IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "Account". -Axiom ethereum_dao_fork_fork_types_Address : - IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "Address". -Axiom ethereum_dao_fork_fork_types_Root : - IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "Root". - -Require ethereum.dao_fork.trie. -Axiom ethereum_dao_fork_trie_EMPTY_TRIE_ROOT : - IsGlobalAlias globals ethereum.dao_fork.trie.globals "EMPTY_TRIE_ROOT". -Axiom ethereum_dao_fork_trie_Trie : - IsGlobalAlias globals ethereum.dao_fork.trie.globals "Trie". -Axiom ethereum_dao_fork_trie_copy_trie : - IsGlobalAlias globals ethereum.dao_fork.trie.globals "copy_trie". -Axiom ethereum_dao_fork_trie_root : - IsGlobalAlias globals ethereum.dao_fork.trie.globals "root". -Axiom ethereum_dao_fork_trie_trie_get : - IsGlobalAlias globals ethereum.dao_fork.trie.globals "trie_get". -Axiom ethereum_dao_fork_trie_trie_set : - IsGlobalAlias globals ethereum.dao_fork.trie.globals "trie_set". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass"; "field" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict"; "List"; "Optional"; "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "modify" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_dao_fork_fork_types_imports : + AreImported globals "ethereum.dao_fork.fork_types" [ "EMPTY_ACCOUNT"; "Account"; "Address"; "Root" ]. + +Axiom ethereum_dao_fork_trie_imports : + AreImported globals "ethereum.dao_fork.trie" [ "EMPTY_TRIE_ROOT"; "Trie"; "copy_trie"; "root"; "trie_get"; "trie_set" ]. Definition State : Value.t := builtins.make_klass @@ -338,13 +300,16 @@ Definition destroy_storage : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -479,7 +444,10 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), + M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |), M.get_name (| globals, "trie" |) |) in M.pure Constant.None_ @@ -505,7 +473,10 @@ Definition set_storage : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -535,7 +506,7 @@ Definition storage_root : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), @@ -545,7 +516,10 @@ Definition storage_root : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "root" |), make_list [ - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) + M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |) ], make_dict [] |) diff --git a/CoqOfPython/ethereum/dao_fork/transactions.v b/CoqOfPython/ethereum/dao_fork/transactions.v index 25df68a..3b7cac3 100644 --- a/CoqOfPython/ethereum/dao_fork/transactions.v +++ b/CoqOfPython/ethereum/dao_fork/transactions.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.dao_fork.transactions". Definition expr_1 : Value.t := Constant.str " @@ -9,29 +9,17 @@ submitted to be executed. If Ethereum is viewed as a state machine, transactions are the events that move between states. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.dao_fork.fork_types. -Axiom ethereum_dao_fork_fork_types_Address : - IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "Address". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Union" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_dao_fork_fork_types_imports : + AreImported globals "ethereum.dao_fork.fork_types" [ "Address" ]. Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( Constant.int 21000 diff --git a/CoqOfPython/ethereum/dao_fork/trie.v b/CoqOfPython/ethereum/dao_fork/trie.v index 0755f51..f009130 100644 --- a/CoqOfPython/ethereum/dao_fork/trie.v +++ b/CoqOfPython/ethereum/dao_fork/trie.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.dao_fork.trie". Definition expr_1 : Value.t := Constant.str " @@ -20,83 +20,38 @@ The state trie is the structure responsible for storing (* At top_level_stmt: unsupported node type: Import *) -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". -Axiom dataclasses_field : - IsGlobalAlias globals dataclasses.globals "field". - -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". -Axiom typing_Generic : - IsGlobalAlias globals typing.globals "Generic". -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Mapping : - IsGlobalAlias globals typing.globals "Mapping". -Axiom typing_MutableMapping : - IsGlobalAlias globals typing.globals "MutableMapping". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Sequence : - IsGlobalAlias globals typing.globals "Sequence". -Axiom typing_TypeVar : - IsGlobalAlias globals typing.globals "TypeVar". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". -Axiom typing_cast : - IsGlobalAlias globals typing.globals "cast". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.homestead.__init__. -Axiom ethereum_homestead___init___trie : - IsGlobalAlias globals ethereum.homestead.__init__.globals "trie". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.utils.hexadecimal. -Axiom ethereum_utils_hexadecimal_hex_to_bytes : - IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.dao_fork.blocks. -Axiom ethereum_dao_fork_blocks_Receipt : - IsGlobalAlias globals ethereum.dao_fork.blocks.globals "Receipt". - -Require ethereum.dao_fork.fork_types. -Axiom ethereum_dao_fork_fork_types_Account : - IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "Account". -Axiom ethereum_dao_fork_fork_types_Address : - IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "Address". -Axiom ethereum_dao_fork_fork_types_Root : - IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "Root". -Axiom ethereum_dao_fork_fork_types_encode_account : - IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "encode_account". - -Require ethereum.dao_fork.transactions. -Axiom ethereum_dao_fork_transactions_Transaction : - IsGlobalAlias globals ethereum.dao_fork.transactions.globals "Transaction". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass"; "field" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict"; "Generic"; "List"; "Mapping"; "MutableMapping"; "Optional"; "Sequence"; "TypeVar"; "Union"; "cast" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. + +Axiom ethereum_homestead_imports : + AreImported globals "ethereum.homestead" [ "trie" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_utils_hexadecimal_imports : + AreImported globals "ethereum.utils.hexadecimal" [ "hex_to_bytes" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_dao_fork_blocks_imports : + AreImported globals "ethereum.dao_fork.blocks" [ "Receipt" ]. + +Axiom ethereum_dao_fork_fork_types_imports : + AreImported globals "ethereum.dao_fork.fork_types" [ "Account"; "Address"; "Root"; "encode_account" ]. + +Axiom ethereum_dao_fork_transactions_imports : + AreImported globals "ethereum.dao_fork.transactions" [ "Transaction" ]. Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -115,7 +70,10 @@ Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( )). Definition Node : Value.t := M.run ltac:(M.monadic ( - M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Bytes" |); M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |); Constant.None_ ] |) + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Bytes" |); M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |); Constant.None_ ] + |) )). Definition K : Value.t := M.run ltac:(M.monadic ( @@ -133,11 +91,23 @@ Definition V : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "TypeVar" |), make_list [ Constant.str "V"; - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Account" |) |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Bytes" |) |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Account" |) + |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Bytes" |) + |); M.get_name (| globals, "Bytes" |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Transaction" |) |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Receipt" |) |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Transaction" |) + |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Receipt" |) + |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |) ], @@ -176,7 +146,10 @@ Definition BranchNode : Value.t := ]. Definition InternalNode : Value.t := M.run ltac:(M.monadic ( - M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LeafNode" |); M.get_name (| globals, "ExtensionNode" |); M.get_name (| globals, "BranchNode" |) ] |) + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "LeafNode" |); M.get_name (| globals, "ExtensionNode" |); M.get_name (| globals, "BranchNode" |) ] + |) )). Definition encode_internal_node : Value.t -> Value.t -> M := @@ -288,7 +261,7 @@ Definition encode_internal_node : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "(* At expr: unsupported node type: JoinedStr *)" @@ -528,13 +501,16 @@ Definition trie_set : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "key" |), M.get_field (| M.get_name (| globals, "trie" |), "_data" |) |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + M.get_name (| globals, "key" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -544,7 +520,10 @@ Definition trie_set : Value.t -> Value.t -> M := (* else *) )), ltac:(M.monadic ( let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), + M.get_subscript (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + M.get_name (| globals, "key" |) + |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_ @@ -589,51 +568,66 @@ Definition common_prefix_length : Value.t -> Value.t -> M := let _ := Constant.str " Find the longest common prefix of two sequences. " in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "a" |) - ], - make_dict [] - |) - ], - make_dict [] - |) do - let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| - M.get_name (| globals, "i" |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "b" |) - ], - make_dict [] - |) - |), - ltac:(M.monadic ( - Compare.not_eq (| - M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), - M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) - |) - )) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + ], + make_dict [] + |), ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "i" |) - |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_subscript (| + M.get_name (| globals, "a" |), + M.get_name (| globals, "i" |) + |), + M.get_subscript (| + M.get_name (| globals, "b" |), + M.get_name (| globals, "i" |) + |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "len" |), @@ -718,38 +712,53 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 0; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |); - Constant.int 2 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ BinOp.add (| BinOp.mult (| Constant.int 16, - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "i" |) + |) |), - M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) + |) |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -767,43 +776,61 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := Constant.int 1 |) |), - M.get_subscript (| M.get_name (| globals, "x" |), Constant.int 0 |) + M.get_subscript (| + M.get_name (| globals, "x" |), + Constant.int 0 + |) |) ], make_dict [] |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 1; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |); - Constant.int 2 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 1; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ BinOp.add (| BinOp.mult (| Constant.int 16, - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "i" |) + |) |), - M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) + |) |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -850,40 +877,55 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := ], make_dict [] |) in - For make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ] in M.call (| - M.get_name (| globals, "enumerate" |), - make_list [ - M.get_name (| globals, "bytes_" |) - ], - make_dict [] - |) do - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.mult (| - M.get_name (| globals, "byte_index" |), - Constant.int 2 - |) |), - BinOp.r_shift (| - BinOp.bit_and (| - M.get_name (| globals, "byte" |), - Constant.int 240 - |), - Constant.int 4 - |) - |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "byte_index" |), - Constant.int 2 - |), - Constant.int 1 - |) |), - BinOp.bit_and (| - M.get_name (| globals, "byte" |), - Constant.int 15 - |) - |) in - EndFor. + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ], + M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "bytes_" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "nibble_list" |), + BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |) + |), + BinOp.r_shift (| + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 240 + |), + Constant.int 4 + |) + |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "nibble_list" |), + BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |), + Constant.int 1 + |) + |), + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 15 + |) + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Bytes" |), @@ -916,65 +958,69 @@ Definition _prepare_trie : Value.t -> Value.t -> M := Object with keys mapped to nibble-byte form. " in (* At stmt: unsupported node type: AnnAssign *) - For make_tuple [ M.get_name (| globals, "preimage" |); M.get_name (| globals, "value" |) ] in M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "items" |), - make_list [], - make_dict [] - |) do - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "value" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "preimage" |); M.get_name (| globals, "value" |) ], + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "items" |), + make_list [], + make_dict [] + |), ltac:(M.monadic ( - let _ := M.assert (| Compare.is_not (| + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in - let address := - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in - let encoded_value := - M.call (| - M.get_name (| globals, "encode_node" |), - make_list [ - M.get_name (| globals, "value" |); + let address := M.call (| - M.get_name (| globals, "get_storage_root" |), + M.get_name (| globals, "Address" |), make_list [ - M.get_name (| globals, "address" |) + M.get_name (| globals, "preimage" |) ], make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let encoded_value := - M.call (| - M.get_name (| globals, "encode_node" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - )) |) in - let _ := M.call (| + |) in + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |); + M.call (| + M.get_name (| globals, "get_storage_root" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_eq (| @@ -986,38 +1032,46 @@ Definition _prepare_trie : Value.t -> Value.t -> M := make_dict [] |) in (* At stmt: unsupported node type: AnnAssign *) - let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "trie" |), "secured" |), - (* then *) - ltac:(M.monadic ( - let key := - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "trie" |), "secured" |), + (* then *) + ltac:(M.monadic ( + let key := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let key := + M.get_name (| globals, "preimage" |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "mapped" |), + M.call (| + M.get_name (| globals, "bytes_to_nibble_list" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |) + |), + M.get_name (| globals, "encoded_value" |) + |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let key := - M.get_name (| globals, "preimage" |) in + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "mapped" |), M.call (| - M.get_name (| globals, "bytes_to_nibble_list" |), - make_list [ - M.get_name (| globals, "key" |) - ], - make_dict [] - |) |), - M.get_name (| globals, "encoded_value" |) - |) in - EndFor. + )) + |) in let _ := M.return_ (| M.get_name (| globals, "mapped" |) |) in @@ -1210,8 +1264,16 @@ Definition patricialize : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "LeafNode" |), make_list [ - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |); - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) + M.slice (| + M.get_name (| globals, "arbitrary_key" |), + M.get_name (| globals, "level" |), + Constant.None_, + Constant.None_ + |); + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "arbitrary_key" |) + |) ], make_dict [] |) in @@ -1224,7 +1286,12 @@ Definition patricialize : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in let substring := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "arbitrary_key" |), + M.get_name (| globals, "level" |), + Constant.None_, + Constant.None_ + |) in let prefix_length := M.call (| M.get_name (| globals, "len" |), @@ -1233,39 +1300,53 @@ Definition patricialize : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do - let prefix_length := - M.call (| - M.get_name (| globals, "min" |), - make_list [ - M.get_name (| globals, "prefix_length" |); + let _ := + M.for_ (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "obj" |), + ltac:(M.monadic ( + let prefix_length := M.call (| - M.get_name (| globals, "common_prefix_length" |), + M.get_name (| globals, "min" |), make_list [ - M.get_name (| globals, "substring" |); - M.get_subscript (| M.get_name (| globals, "key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) + M.get_name (| globals, "prefix_length" |); + M.call (| + M.get_name (| globals, "common_prefix_length" |), + make_list [ + M.get_name (| globals, "substring" |); + M.slice (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "level" |), + Constant.None_, + Constant.None_ + |) + ], + make_dict [] + |) ], make_dict [] - |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "prefix_length" |), - Constant.int 0 - |), - (* then *) - ltac:(M.monadic ( - let _ := M.break (| |) in + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "prefix_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := (* if *) M.if_then_else (| @@ -1276,10 +1357,15 @@ Definition patricialize : Value.t -> Value.t -> M := (* then *) ltac:(M.monadic ( let prefix := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), BinOp.add (| + M.slice (| + M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |), - M.get_name (| globals, "prefix_length" |) - |) |) |) in + BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |), + Constant.None_ + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ExtensionNode" |), @@ -1312,70 +1398,106 @@ Definition patricialize : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) - For M.get_name (| globals, "_" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 16 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "_" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 16 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "branches" |), "append" |), make_list [ {} ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let value := Constant.bytes "" in - For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "key" |) - ], - make_dict [] - |), - M.get_name (| globals, "level" |) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "obj" |), ltac:(M.monadic ( let _ := (* if *) M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); - make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] - ], - make_dict [] + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |), + M.get_name (| globals, "level" |) |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "AssertionError" |)) |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "key" |) + |); + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "AssertionError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "key" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| + M.get_subscript (| + M.get_name (| globals, "branches" |), + M.get_subscript (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "level" |) + |) + |), + M.get_name (| globals, "key" |) + |), + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "key" |) + |) + |) in M.pure Constant.None_ )) |) in - let value := - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.assign (| - M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) - |) in + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "BranchNode" |), diff --git a/CoqOfPython/ethereum/dao_fork/utils/__init__.v b/CoqOfPython/ethereum/dao_fork/utils/__init__.v index 1baedea..dbf11fc 100644 --- a/CoqOfPython/ethereum/dao_fork/utils/__init__.v +++ b/CoqOfPython/ethereum/dao_fork/utils/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.dao_fork.utils.__init__". Definition expr_1 : Value.t := Constant.str " diff --git a/CoqOfPython/ethereum/dao_fork/utils/address.v b/CoqOfPython/ethereum/dao_fork/utils/address.v index 5cb49df..93430a5 100644 --- a/CoqOfPython/ethereum/dao_fork/utils/address.v +++ b/CoqOfPython/ethereum/dao_fork/utils/address.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.dao_fork.utils.address". Definition expr_1 : Value.t := Constant.str " @@ -17,31 +17,23 @@ Introduction Address specific functions used in this Dao Fork version of specification. ". -Require typing. -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". +Axiom typing_imports : + AreImported globals "typing" [ "Union" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_left_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. -Require ethereum.dao_fork.fork_types. -Axiom ethereum_dao_fork_fork_types_Address : - IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "Address". +Axiom ethereum_dao_fork_fork_types_imports : + AreImported globals "ethereum.dao_fork.fork_types" [ "Address" ]. Definition to_address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -63,11 +55,16 @@ Definition to_address : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "Address" |), make_list [ - M.get_subscript (| M.call (| - M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), - make_list [], - make_dict [] - |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) + M.slice (| + M.call (| + M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), + UnOp.sub (| Constant.int 20 |), + Constant.None_, + Constant.None_ + |) ], make_dict [] |) @@ -111,7 +108,12 @@ Definition compute_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "computed_address" |), + UnOp.sub (| Constant.int 20 |), + Constant.None_, + Constant.None_ + |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/dao_fork/utils/hexadecimal.v b/CoqOfPython/ethereum/dao_fork/utils/hexadecimal.v index df224a7..3e89490 100644 --- a/CoqOfPython/ethereum/dao_fork/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/dao_fork/utils/hexadecimal.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.dao_fork.utils.hexadecimal". Definition expr_1 : Value.t := Constant.str " @@ -18,17 +18,11 @@ Hexadecimal utility functions used in this specification, specific to Dao Fork types. ". -Require ethereum.utils.hexadecimal. -Axiom ethereum_utils_hexadecimal_remove_hex_prefix : - IsGlobalAlias globals ethereum.utils.hexadecimal.globals "remove_hex_prefix". - -Require ethereum.dao_fork.fork_types. -Axiom ethereum_dao_fork_fork_types_Address : - IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "Address". -Axiom ethereum_dao_fork_fork_types_Bloom : - IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "Bloom". -Axiom ethereum_dao_fork_fork_types_Root : - IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "Root". +Axiom ethereum_utils_hexadecimal_imports : + AreImported globals "ethereum.utils.hexadecimal" [ "remove_hex_prefix" ]. + +Axiom ethereum_dao_fork_fork_types_imports : + AreImported globals "ethereum.dao_fork.fork_types" [ "Address"; "Bloom"; "Root" ]. Definition hex_to_root : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/dao_fork/utils/message.v b/CoqOfPython/ethereum/dao_fork/utils/message.v index 759d611..0e2da42 100644 --- a/CoqOfPython/ethereum/dao_fork/utils/message.v +++ b/CoqOfPython/ethereum/dao_fork/utils/message.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.dao_fork.utils.message". Definition expr_1 : Value.t := Constant.str " @@ -17,39 +17,23 @@ Introduction Message specific functions used in this Dao Fork version of specification. ". -Require typing. -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". +Axiom typing_imports : + AreImported globals "typing" [ "Optional"; "Union" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint" ]. -Require ethereum.dao_fork.fork_types. -Axiom ethereum_dao_fork_fork_types_Address : - IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "Address". +Axiom ethereum_dao_fork_fork_types_imports : + AreImported globals "ethereum.dao_fork.fork_types" [ "Address" ]. -Require ethereum.dao_fork.state. -Axiom ethereum_dao_fork_state_get_account : - IsGlobalAlias globals ethereum.dao_fork.state.globals "get_account". +Axiom ethereum_dao_fork_state_imports : + AreImported globals "ethereum.dao_fork.state" [ "get_account" ]. -Require ethereum.dao_fork.vm.__init__. -Axiom ethereum_dao_fork_vm___init___Environment : - IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "Environment". -Axiom ethereum_dao_fork_vm___init___Message : - IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "Message". +Axiom ethereum_dao_fork_vm_imports : + AreImported globals "ethereum.dao_fork.vm" [ "Environment"; "Message" ]. -Require ethereum.dao_fork.utils.address. -Axiom ethereum_dao_fork_utils_address_compute_contract_address : - IsGlobalAlias globals ethereum.dao_fork.utils.address.globals "compute_contract_address". +Axiom ethereum_dao_fork_utils_address_imports : + AreImported globals "ethereum.dao_fork.utils.address" [ "compute_contract_address" ]. Definition prepare_message : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -179,7 +163,7 @@ Definition prepare_message : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "Target must be address or empty bytes" diff --git a/CoqOfPython/ethereum/dao_fork/vm/__init__.v b/CoqOfPython/ethereum/dao_fork/vm/__init__.v index 1b240a8..03365f0 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/__init__.v +++ b/CoqOfPython/ethereum/dao_fork/vm/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.dao_fork.vm.__init__". Definition expr_1 : Value.t := Constant.str " @@ -18,47 +18,26 @@ The abstract computer which runs the code stored in an `.fork_types.Account`. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". - -Require ethereum.dao_fork.blocks. -Axiom ethereum_dao_fork_blocks_Log : - IsGlobalAlias globals ethereum.dao_fork.blocks.globals "Log". - -Require ethereum.dao_fork.fork_types. -Axiom ethereum_dao_fork_fork_types_Address : - IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "Address". - -Require ethereum.dao_fork.state. -Axiom ethereum_dao_fork_state_State : - IsGlobalAlias globals ethereum.dao_fork.state.globals "State". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple"; "Union" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. + +Axiom ethereum_dao_fork_blocks_imports : + AreImported globals "ethereum.dao_fork.blocks" [ "Log" ]. + +Axiom ethereum_dao_fork_fork_types_imports : + AreImported globals "ethereum.dao_fork.fork_types" [ "Address" ]. + +Axiom ethereum_dao_fork_state_imports : + AreImported globals "ethereum.dao_fork.state" [ "State" ]. Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] diff --git a/CoqOfPython/ethereum/dao_fork/vm/exceptions.v b/CoqOfPython/ethereum/dao_fork/vm/exceptions.v index 45435b3..e9914f2 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/exceptions.v +++ b/CoqOfPython/ethereum/dao_fork/vm/exceptions.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.dao_fork.vm.exceptions". Definition expr_1 : Value.t := Constant.str " @@ -17,9 +17,8 @@ Introduction Exceptions which cause the EVM to halt exceptionally. ". -Require ethereum.exceptions. -Axiom ethereum_exceptions_EthereumException : - IsGlobalAlias globals ethereum.exceptions.globals "EthereumException". +Axiom ethereum_exceptions_imports : + AreImported globals "ethereum.exceptions" [ "EthereumException" ]. Definition ExceptionalHalt : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/dao_fork/vm/gas.v b/CoqOfPython/ethereum/dao_fork/vm/gas.v index 62ff7dc..e0761e3 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/gas.v +++ b/CoqOfPython/ethereum/dao_fork/vm/gas.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.dao_fork.vm.gas". Definition expr_1 : Value.t := Constant.str " @@ -17,49 +17,32 @@ Introduction EVM gas constants and calculators. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.trace. -Axiom ethereum_trace_GasAndRefund : - IsGlobalAlias globals ethereum.trace.globals "GasAndRefund". -Axiom ethereum_trace_evm_trace : - IsGlobalAlias globals ethereum.trace.globals "evm_trace". - -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". - -Require ethereum.dao_fork.fork_types. -Axiom ethereum_dao_fork_fork_types_Address : - IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "Address". - -Require ethereum.dao_fork.state. -Axiom ethereum_dao_fork_state_State : - IsGlobalAlias globals ethereum.dao_fork.state.globals "State". -Axiom ethereum_dao_fork_state_account_exists : - IsGlobalAlias globals ethereum.dao_fork.state.globals "account_exists". - -Require ethereum.dao_fork.vm.__init__. -Axiom ethereum_dao_fork_vm___init___Evm : - IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "Evm". - -Require ethereum.dao_fork.vm.exceptions. -Axiom ethereum_dao_fork_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.dao_fork.vm.exceptions.globals "OutOfGasError". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. + +Axiom ethereum_trace_imports : + AreImported globals "ethereum.trace" [ "GasAndRefund"; "evm_trace" ]. + +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. + +Axiom ethereum_dao_fork_fork_types_imports : + AreImported globals "ethereum.dao_fork.fork_types" [ "Address" ]. + +Axiom ethereum_dao_fork_state_imports : + AreImported globals "ethereum.dao_fork.state" [ "State"; "account_exists" ]. + +Axiom ethereum_dao_fork_vm_imports : + AreImported globals "ethereum.dao_fork.vm" [ "Evm" ]. + +Axiom ethereum_dao_fork_vm_exceptions_imports : + AreImported globals "ethereum.dao_fork.vm.exceptions" [ "OutOfGasError" ]. Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -488,7 +471,7 @@ Definition charge_gas : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -605,105 +588,114 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := ], make_dict [] |) in - For make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ] in M.get_name (| globals, "extensions" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "size" |), - Constant.int 0 - |), - (* then *) + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ], + M.get_name (| globals, "extensions" |), ltac:(M.monadic ( - let _ := M.continue (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let before_size := - M.call (| - M.get_name (| globals, "ceil32" |), - make_list [ - M.get_name (| globals, "current_size" |) - ], - make_dict [] - |) in - let after_size := - M.call (| - M.get_name (| globals, "ceil32" |), - make_list [ - BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "size" |), + Constant.int 0 |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.lt_e (| - M.get_name (| globals, "after_size" |), - M.get_name (| globals, "before_size" |) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.continue (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let size_to_extend := BinOp.add - BinOp.sub (| + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let before_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "current_size" |) + ], + make_dict [] + |) in + let after_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let size_to_extend := BinOp.add + BinOp.sub (| M.get_name (| globals, "after_size" |), M.get_name (| globals, "before_size" |) |) - BinOp.sub (| + BinOp.sub (| M.get_name (| globals, "after_size" |), M.get_name (| globals, "before_size" |) |) in - let already_paid := - M.call (| - M.get_name (| globals, "calculate_memory_gas_cost" |), - make_list [ - M.get_name (| globals, "before_size" |) - ], - make_dict [] - |) in - let total_cost := - M.call (| - M.get_name (| globals, "calculate_memory_gas_cost" |), - make_list [ - M.get_name (| globals, "after_size" |) - ], - make_dict [] - |) in - let to_be_paid := BinOp.add - BinOp.sub (| + let already_paid := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "before_size" |) + ], + make_dict [] + |) in + let total_cost := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "after_size" |) + ], + make_dict [] + |) in + let to_be_paid := BinOp.add + BinOp.sub (| M.get_name (| globals, "total_cost" |), M.get_name (| globals, "already_paid" |) |) - BinOp.sub (| + BinOp.sub (| M.get_name (| globals, "total_cost" |), M.get_name (| globals, "already_paid" |) |) in - let current_size := - M.get_name (| globals, "after_size" |) in - EndFor. + let current_size := + M.get_name (| globals, "after_size" |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ExtendMemory" |), diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/__init__.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/__init__.v index 08d558b..c96ddaa 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/__init__.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.dao_fork.vm.instructions.__init__". Definition expr_1 : Value.t := Constant.str " @@ -20,59 +20,44 @@ implementations. (* At top_level_stmt: unsupported node type: Import *) -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict" ]. -Require ethereum.dao_fork.vm.instructions.__init__. -Axiom ethereum_dao_fork_vm_instructions___init___arithmetic : - IsGlobalAlias globals ethereum.dao_fork.vm.instructions.__init__.globals "arithmetic". +Axiom ethereum_dao_fork_vm_instructions_imports : + AreImported globals "ethereum.dao_fork.vm.instructions" [ "arithmetic" ]. -Require ethereum.dao_fork.vm.instructions.__init__. -Axiom ethereum_dao_fork_vm_instructions___init___bitwise : - IsGlobalAlias globals ethereum.dao_fork.vm.instructions.__init__.globals "bitwise". +Axiom ethereum_dao_fork_vm_instructions_imports : + AreImported globals "ethereum.dao_fork.vm.instructions" [ "bitwise" ]. -Require ethereum.dao_fork.vm.instructions.__init__. -Axiom ethereum_dao_fork_vm_instructions___init___block : - IsGlobalAlias globals ethereum.dao_fork.vm.instructions.__init__.globals "block". +Axiom ethereum_dao_fork_vm_instructions_imports : + AreImported globals "ethereum.dao_fork.vm.instructions" [ "block" ]. -Require ethereum.dao_fork.vm.instructions.__init__. -Axiom ethereum_dao_fork_vm_instructions___init___comparison : - IsGlobalAlias globals ethereum.dao_fork.vm.instructions.__init__.globals "comparison". +Axiom ethereum_dao_fork_vm_instructions_imports : + AreImported globals "ethereum.dao_fork.vm.instructions" [ "comparison" ]. -Require ethereum.dao_fork.vm.instructions.__init__. -Axiom ethereum_dao_fork_vm_instructions___init___control_flow : - IsGlobalAlias globals ethereum.dao_fork.vm.instructions.__init__.globals "control_flow". +Axiom ethereum_dao_fork_vm_instructions_imports : + AreImported globals "ethereum.dao_fork.vm.instructions" [ "control_flow" ]. -Require ethereum.dao_fork.vm.instructions.__init__. -Axiom ethereum_dao_fork_vm_instructions___init___environment : - IsGlobalAlias globals ethereum.dao_fork.vm.instructions.__init__.globals "environment". +Axiom ethereum_dao_fork_vm_instructions_imports : + AreImported globals "ethereum.dao_fork.vm.instructions" [ "environment" ]. -Require ethereum.dao_fork.vm.instructions.__init__. -Axiom ethereum_dao_fork_vm_instructions___init___keccak : - IsGlobalAlias globals ethereum.dao_fork.vm.instructions.__init__.globals "keccak". +Axiom ethereum_dao_fork_vm_instructions_imports : + AreImported globals "ethereum.dao_fork.vm.instructions" [ "keccak" ]. -Require ethereum.dao_fork.vm.instructions.__init__. -Axiom ethereum_dao_fork_vm_instructions___init___log : - IsGlobalAlias globals ethereum.dao_fork.vm.instructions.__init__.globals "log". +Axiom ethereum_dao_fork_vm_instructions_imports : + AreImported globals "ethereum.dao_fork.vm.instructions" [ "log" ]. -Require ethereum.dao_fork.vm.instructions.__init__. -Axiom ethereum_dao_fork_vm_instructions___init___memory : - IsGlobalAlias globals ethereum.dao_fork.vm.instructions.__init__.globals "memory". +Axiom ethereum_dao_fork_vm_instructions_imports : + AreImported globals "ethereum.dao_fork.vm.instructions" [ "memory" ]. -Require ethereum.dao_fork.vm.instructions.__init__. -Axiom ethereum_dao_fork_vm_instructions___init___stack : - IsGlobalAlias globals ethereum.dao_fork.vm.instructions.__init__.globals "stack". +Axiom ethereum_dao_fork_vm_instructions_imports : + AreImported globals "ethereum.dao_fork.vm.instructions" [ "stack" ]. -Require ethereum.dao_fork.vm.instructions.__init__. -Axiom ethereum_dao_fork_vm_instructions___init___storage : - IsGlobalAlias globals ethereum.dao_fork.vm.instructions.__init__.globals "storage". +Axiom ethereum_dao_fork_vm_instructions_imports : + AreImported globals "ethereum.dao_fork.vm.instructions" [ "storage" ]. -Require ethereum.dao_fork.vm.instructions.__init__. -Axiom ethereum_dao_fork_vm_instructions___init___system : - IsGlobalAlias globals ethereum.dao_fork.vm.instructions.__init__.globals "system". +Axiom ethereum_dao_fork_vm_instructions_imports : + AreImported globals "ethereum.dao_fork.vm.instructions" [ "system" ]. Definition Ops : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/arithmetic.v index 2decdb1..53c6c89 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/arithmetic.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.dao_fork.vm.instructions.arithmetic". Definition expr_1 : Value.t := Constant.str " @@ -17,43 +17,20 @@ Introduction Implementations of the EVM Arithmetic instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U255_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U255_CEIL_VALUE". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_U256_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U255_CEIL_VALUE"; "U256"; "U256_CEIL_VALUE"; "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_get_sign : - IsGlobalAlias globals ethereum.utils.numeric.globals "get_sign". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "get_sign" ]. -Require ethereum.dao_fork.vm.__init__. -Axiom ethereum_dao_fork_vm___init___Evm : - IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "Evm". +Axiom ethereum_dao_fork_vm_imports : + AreImported globals "ethereum.dao_fork.vm" [ "Evm" ]. -Require ethereum.dao_fork.vm.gas. -Axiom ethereum_dao_fork_vm_gas_GAS_EXPONENTIATION : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_EXPONENTIATION". -Axiom ethereum_dao_fork_vm_gas_GAS_EXPONENTIATION_PER_BYTE : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_EXPONENTIATION_PER_BYTE". -Axiom ethereum_dao_fork_vm_gas_GAS_LOW : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_LOW". -Axiom ethereum_dao_fork_vm_gas_GAS_MID : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_MID". -Axiom ethereum_dao_fork_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_dao_fork_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "charge_gas". +Axiom ethereum_dao_fork_vm_gas_imports : + AreImported globals "ethereum.dao_fork.vm.gas" [ "GAS_EXPONENTIATION"; "GAS_EXPONENTIATION_PER_BYTE"; "GAS_LOW"; "GAS_MID"; "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.dao_fork.vm.stack. -Axiom ethereum_dao_fork_vm_stack_pop : - IsGlobalAlias globals ethereum.dao_fork.vm.stack.globals "pop". -Axiom ethereum_dao_fork_vm_stack_push : - IsGlobalAlias globals ethereum.dao_fork.vm.stack.globals "push". +Axiom ethereum_dao_fork_vm_stack_imports : + AreImported globals "ethereum.dao_fork.vm.stack" [ "pop"; "push" ]. Definition add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -1030,19 +1007,27 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let value_bytes := - M.get_subscript (| M.get_name (| globals, "value_bytes" |), M.slice (| BinOp.sub (| - Constant.int 31, - M.call (| - M.get_name (| globals, "int" |), - make_list [ - M.get_name (| globals, "byte_num" |) - ], - make_dict [] - |) - |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "value_bytes" |), + BinOp.sub (| + Constant.int 31, + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "byte_num" |) + ], + make_dict [] + |) + |), + Constant.None_, + Constant.None_ + |) in let sign_bit := BinOp.r_shift (| - M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), + M.get_subscript (| + M.get_name (| globals, "value_bytes" |), + Constant.int 0 + |), Constant.int 7 |) in let _ := diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/bitwise.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/bitwise.v index 1f50216..f552ec9 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/bitwise.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.dao_fork.vm.instructions.bitwise". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementations of the EVM bitwise instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.dao_fork.vm.__init__. -Axiom ethereum_dao_fork_vm___init___Evm : - IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "Evm". +Axiom ethereum_dao_fork_vm_imports : + AreImported globals "ethereum.dao_fork.vm" [ "Evm" ]. -Require ethereum.dao_fork.vm.gas. -Axiom ethereum_dao_fork_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_dao_fork_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "charge_gas". +Axiom ethereum_dao_fork_vm_gas_imports : + AreImported globals "ethereum.dao_fork.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.dao_fork.vm.stack. -Axiom ethereum_dao_fork_vm_stack_pop : - IsGlobalAlias globals ethereum.dao_fork.vm.stack.globals "pop". -Axiom ethereum_dao_fork_vm_stack_push : - IsGlobalAlias globals ethereum.dao_fork.vm.stack.globals "push". +Axiom ethereum_dao_fork_vm_stack_imports : + AreImported globals "ethereum.dao_fork.vm.stack" [ "pop"; "push" ]. Definition bitwise_and : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/block.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/block.v index 2a83909..02269c3 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/block.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/block.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.dao_fork.vm.instructions.block". Definition expr_1 : Value.t := Constant.str " @@ -17,27 +17,17 @@ Introduction Implementations of the EVM block instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.dao_fork.vm.__init__. -Axiom ethereum_dao_fork_vm___init___Evm : - IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "Evm". +Axiom ethereum_dao_fork_vm_imports : + AreImported globals "ethereum.dao_fork.vm" [ "Evm" ]. -Require ethereum.dao_fork.vm.gas. -Axiom ethereum_dao_fork_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_BASE". -Axiom ethereum_dao_fork_vm_gas_GAS_BLOCK_HASH : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_BLOCK_HASH". -Axiom ethereum_dao_fork_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "charge_gas". +Axiom ethereum_dao_fork_vm_gas_imports : + AreImported globals "ethereum.dao_fork.vm.gas" [ "GAS_BASE"; "GAS_BLOCK_HASH"; "charge_gas" ]. -Require ethereum.dao_fork.vm.stack. -Axiom ethereum_dao_fork_vm_stack_pop : - IsGlobalAlias globals ethereum.dao_fork.vm.stack.globals "pop". -Axiom ethereum_dao_fork_vm_stack_push : - IsGlobalAlias globals ethereum.dao_fork.vm.stack.globals "push". +Axiom ethereum_dao_fork_vm_stack_imports : + AreImported globals "ethereum.dao_fork.vm.stack" [ "pop"; "push" ]. Definition block_hash : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -94,10 +84,13 @@ Definition block_hash : Value.t -> Value.t -> M := (* else *) )), ltac:(M.monadic ( let hash := - M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), - M.get_name (| globals, "block_number" |) - |) |) |) in + M.get_subscript (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), + UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + M.get_name (| globals, "block_number" |) + |) |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/comparison.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/comparison.v index a81fe64..f55a03a 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/comparison.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.dao_fork.vm.instructions.comparison". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementations of the EVM Comparison instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.dao_fork.vm.__init__. -Axiom ethereum_dao_fork_vm___init___Evm : - IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "Evm". +Axiom ethereum_dao_fork_vm_imports : + AreImported globals "ethereum.dao_fork.vm" [ "Evm" ]. -Require ethereum.dao_fork.vm.gas. -Axiom ethereum_dao_fork_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_dao_fork_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "charge_gas". +Axiom ethereum_dao_fork_vm_gas_imports : + AreImported globals "ethereum.dao_fork.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.dao_fork.vm.stack. -Axiom ethereum_dao_fork_vm_stack_pop : - IsGlobalAlias globals ethereum.dao_fork.vm.stack.globals "pop". -Axiom ethereum_dao_fork_vm_stack_push : - IsGlobalAlias globals ethereum.dao_fork.vm.stack.globals "push". +Axiom ethereum_dao_fork_vm_stack_imports : + AreImported globals "ethereum.dao_fork.vm.stack" [ "pop"; "push" ]. Definition less_than : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/control_flow.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/control_flow.v index 598db3e..6abe333 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/control_flow.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.dao_fork.vm.instructions.control_flow". Definition expr_1 : Value.t := Constant.str " @@ -17,37 +17,20 @@ Introduction Implementations of the EVM control flow instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. -Require ethereum.dao_fork.vm.gas. -Axiom ethereum_dao_fork_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_BASE". -Axiom ethereum_dao_fork_vm_gas_GAS_HIGH : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_HIGH". -Axiom ethereum_dao_fork_vm_gas_GAS_JUMPDEST : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_JUMPDEST". -Axiom ethereum_dao_fork_vm_gas_GAS_MID : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_MID". -Axiom ethereum_dao_fork_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "charge_gas". +Axiom ethereum_dao_fork_vm_gas_imports : + AreImported globals "ethereum.dao_fork.vm.gas" [ "GAS_BASE"; "GAS_HIGH"; "GAS_JUMPDEST"; "GAS_MID"; "charge_gas" ]. -Require ethereum.dao_fork.vm.__init__. -Axiom ethereum_dao_fork_vm___init___Evm : - IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "Evm". +Axiom ethereum_dao_fork_vm_imports : + AreImported globals "ethereum.dao_fork.vm" [ "Evm" ]. -Require ethereum.dao_fork.vm.exceptions. -Axiom ethereum_dao_fork_vm_exceptions_InvalidJumpDestError : - IsGlobalAlias globals ethereum.dao_fork.vm.exceptions.globals "InvalidJumpDestError". +Axiom ethereum_dao_fork_vm_exceptions_imports : + AreImported globals "ethereum.dao_fork.vm.exceptions" [ "InvalidJumpDestError" ]. -Require ethereum.dao_fork.vm.stack. -Axiom ethereum_dao_fork_vm_stack_pop : - IsGlobalAlias globals ethereum.dao_fork.vm.stack.globals "pop". -Axiom ethereum_dao_fork_vm_stack_push : - IsGlobalAlias globals ethereum.dao_fork.vm.stack.globals "push". +Axiom ethereum_dao_fork_vm_stack_imports : + AreImported globals "ethereum.dao_fork.vm.stack" [ "pop"; "push" ]. Definition stop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -117,7 +100,7 @@ Definition jump : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "InvalidJumpDestError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -205,7 +188,7 @@ Definition jumpi : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "InvalidJumpDestError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/environment.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/environment.v index f6aad83..bb655b1 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/environment.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.dao_fork.vm.instructions.environment". Definition expr_1 : Value.t := Constant.str " @@ -17,55 +17,29 @@ Introduction Implementations of the EVM environment related instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". - -Require ethereum.dao_fork.state. -Axiom ethereum_dao_fork_state_get_account : - IsGlobalAlias globals ethereum.dao_fork.state.globals "get_account". - -Require ethereum.dao_fork.utils.address. -Axiom ethereum_dao_fork_utils_address_to_address : - IsGlobalAlias globals ethereum.dao_fork.utils.address.globals "to_address". - -Require ethereum.dao_fork.vm.memory. -Axiom ethereum_dao_fork_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.dao_fork.vm.memory.globals "buffer_read". -Axiom ethereum_dao_fork_vm_memory_memory_write : - IsGlobalAlias globals ethereum.dao_fork.vm.memory.globals "memory_write". - -Require ethereum.dao_fork.vm.__init__. -Axiom ethereum_dao_fork_vm___init___Evm : - IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "Evm". - -Require ethereum.dao_fork.vm.gas. -Axiom ethereum_dao_fork_vm_gas_GAS_BALANCE : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_BALANCE". -Axiom ethereum_dao_fork_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_BASE". -Axiom ethereum_dao_fork_vm_gas_GAS_COPY : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_COPY". -Axiom ethereum_dao_fork_vm_gas_GAS_EXTERNAL : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_EXTERNAL". -Axiom ethereum_dao_fork_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_dao_fork_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_dao_fork_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "charge_gas". - -Require ethereum.dao_fork.vm.stack. -Axiom ethereum_dao_fork_vm_stack_pop : - IsGlobalAlias globals ethereum.dao_fork.vm.stack.globals "pop". -Axiom ethereum_dao_fork_vm_stack_push : - IsGlobalAlias globals ethereum.dao_fork.vm.stack.globals "push". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. + +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. + +Axiom ethereum_dao_fork_state_imports : + AreImported globals "ethereum.dao_fork.state" [ "get_account" ]. + +Axiom ethereum_dao_fork_utils_address_imports : + AreImported globals "ethereum.dao_fork.utils.address" [ "to_address" ]. + +Axiom ethereum_dao_fork_vm_memory_imports : + AreImported globals "ethereum.dao_fork.vm.memory" [ "buffer_read"; "memory_write" ]. + +Axiom ethereum_dao_fork_vm_imports : + AreImported globals "ethereum.dao_fork.vm" [ "Evm" ]. + +Axiom ethereum_dao_fork_vm_gas_imports : + AreImported globals "ethereum.dao_fork.vm.gas" [ "GAS_BALANCE"; "GAS_BASE"; "GAS_COPY"; "GAS_EXTERNAL"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. + +Axiom ethereum_dao_fork_vm_stack_imports : + AreImported globals "ethereum.dao_fork.vm.stack" [ "pop"; "push" ]. Definition address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/keccak.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/keccak.v index 7653850..68788bd 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/keccak.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.dao_fork.vm.instructions.keccak". Definition expr_1 : Value.t := Constant.str " @@ -17,43 +17,26 @@ Introduction Implementations of the EVM keccak instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". - -Require ethereum.dao_fork.vm.__init__. -Axiom ethereum_dao_fork_vm___init___Evm : - IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "Evm". - -Require ethereum.dao_fork.vm.gas. -Axiom ethereum_dao_fork_vm_gas_GAS_KECCAK256 : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_KECCAK256". -Axiom ethereum_dao_fork_vm_gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_KECCAK256_WORD". -Axiom ethereum_dao_fork_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_dao_fork_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "charge_gas". - -Require ethereum.dao_fork.vm.memory. -Axiom ethereum_dao_fork_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.dao_fork.vm.memory.globals "memory_read_bytes". - -Require ethereum.dao_fork.vm.stack. -Axiom ethereum_dao_fork_vm_stack_pop : - IsGlobalAlias globals ethereum.dao_fork.vm.stack.globals "pop". -Axiom ethereum_dao_fork_vm_stack_push : - IsGlobalAlias globals ethereum.dao_fork.vm.stack.globals "push". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. + +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. + +Axiom ethereum_dao_fork_vm_imports : + AreImported globals "ethereum.dao_fork.vm" [ "Evm" ]. + +Axiom ethereum_dao_fork_vm_gas_imports : + AreImported globals "ethereum.dao_fork.vm.gas" [ "GAS_KECCAK256"; "GAS_KECCAK256_WORD"; "calculate_gas_extend_memory"; "charge_gas" ]. + +Axiom ethereum_dao_fork_vm_memory_imports : + AreImported globals "ethereum.dao_fork.vm.memory" [ "memory_read_bytes" ]. + +Axiom ethereum_dao_fork_vm_stack_imports : + AreImported globals "ethereum.dao_fork.vm.stack" [ "pop"; "push" ]. Definition keccak : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/log.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/log.v index a148c90..e1cf129 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/log.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/log.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.dao_fork.vm.instructions.log". Definition expr_1 : Value.t := Constant.str " @@ -17,41 +17,26 @@ Introduction Implementations of the EVM logging instructions. ". -Require functools. -Axiom functools_partial : - IsGlobalAlias globals functools.globals "partial". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". - -Require ethereum.dao_fork.blocks. -Axiom ethereum_dao_fork_blocks_Log : - IsGlobalAlias globals ethereum.dao_fork.blocks.globals "Log". - -Require ethereum.dao_fork.vm.__init__. -Axiom ethereum_dao_fork_vm___init___Evm : - IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "Evm". - -Require ethereum.dao_fork.vm.gas. -Axiom ethereum_dao_fork_vm_gas_GAS_LOG : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_LOG". -Axiom ethereum_dao_fork_vm_gas_GAS_LOG_DATA : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_LOG_DATA". -Axiom ethereum_dao_fork_vm_gas_GAS_LOG_TOPIC : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_LOG_TOPIC". -Axiom ethereum_dao_fork_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_dao_fork_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "charge_gas". - -Require ethereum.dao_fork.vm.memory. -Axiom ethereum_dao_fork_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.dao_fork.vm.memory.globals "memory_read_bytes". - -Require ethereum.dao_fork.vm.stack. -Axiom ethereum_dao_fork_vm_stack_pop : - IsGlobalAlias globals ethereum.dao_fork.vm.stack.globals "pop". +Axiom functools_imports : + AreImported globals "functools" [ "partial" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. + +Axiom ethereum_dao_fork_blocks_imports : + AreImported globals "ethereum.dao_fork.blocks" [ "Log" ]. + +Axiom ethereum_dao_fork_vm_imports : + AreImported globals "ethereum.dao_fork.vm" [ "Evm" ]. + +Axiom ethereum_dao_fork_vm_gas_imports : + AreImported globals "ethereum.dao_fork.vm.gas" [ "GAS_LOG"; "GAS_LOG_DATA"; "GAS_LOG_TOPIC"; "calculate_gas_extend_memory"; "charge_gas" ]. + +Axiom ethereum_dao_fork_vm_memory_imports : + AreImported globals "ethereum.dao_fork.vm.memory" [ "memory_read_bytes" ]. + +Axiom ethereum_dao_fork_vm_stack_imports : + AreImported globals "ethereum.dao_fork.vm.stack" [ "pop" ]. Definition log_n : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -88,33 +73,42 @@ Definition log_n : Value.t -> Value.t -> M := |) in let topics := make_list [] in - For M.get_name (| globals, "_" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - M.get_name (| globals, "num_topics" |) - ], - make_dict [] - |) do - let topic := + let _ := + M.for_ (| + M.get_name (| globals, "_" |), M.call (| - M.get_field (| M.call (| - M.get_name (| globals, "pop" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] - |), "to_be_bytes32" |), - make_list [], - make_dict [] - |) in - let _ := M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "num_topics" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let topic := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| M.get_field (| M.get_name (| globals, "topics" |), "append" |), make_list [ M.get_name (| globals, "topic" |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let extend_memory := M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/memory.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/memory.v index 0165398..9959d29 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/memory.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.dao_fork.vm.instructions.memory". Definition expr_1 : Value.t := Constant.str " @@ -17,37 +17,20 @@ Introduction Implementations of the EVM Memory instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes" ]. -Require ethereum.dao_fork.vm.__init__. -Axiom ethereum_dao_fork_vm___init___Evm : - IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "Evm". +Axiom ethereum_dao_fork_vm_imports : + AreImported globals "ethereum.dao_fork.vm" [ "Evm" ]. -Require ethereum.dao_fork.vm.gas. -Axiom ethereum_dao_fork_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_BASE". -Axiom ethereum_dao_fork_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_dao_fork_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_dao_fork_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "charge_gas". +Axiom ethereum_dao_fork_vm_gas_imports : + AreImported globals "ethereum.dao_fork.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. -Require ethereum.dao_fork.vm.memory. -Axiom ethereum_dao_fork_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.dao_fork.vm.memory.globals "memory_read_bytes". -Axiom ethereum_dao_fork_vm_memory_memory_write : - IsGlobalAlias globals ethereum.dao_fork.vm.memory.globals "memory_write". +Axiom ethereum_dao_fork_vm_memory_imports : + AreImported globals "ethereum.dao_fork.vm.memory" [ "memory_read_bytes"; "memory_write" ]. -Require ethereum.dao_fork.vm.stack. -Axiom ethereum_dao_fork_vm_stack_pop : - IsGlobalAlias globals ethereum.dao_fork.vm.stack.globals "pop". -Axiom ethereum_dao_fork_vm_stack_push : - IsGlobalAlias globals ethereum.dao_fork.vm.stack.globals "push". +Axiom ethereum_dao_fork_vm_stack_imports : + AreImported globals "ethereum.dao_fork.vm.stack" [ "pop"; "push" ]. Definition mstore : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/stack.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/stack.v index bfd40cc..e64ce43 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/stack.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.dao_fork.vm.instructions.stack". Definition expr_1 : Value.t := Constant.str " @@ -17,39 +17,26 @@ Introduction Implementations of the EVM stack related instructions. ". -Require functools. -Axiom functools_partial : - IsGlobalAlias globals functools.globals "partial". +Axiom functools_imports : + AreImported globals "functools" [ "partial" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.dao_fork.vm.__init__. -Axiom ethereum_dao_fork_vm___init___Evm : - IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "Evm". -Axiom ethereum_dao_fork_vm___init___stack : - IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "stack". +Axiom ethereum_dao_fork_vm_imports : + AreImported globals "ethereum.dao_fork.vm" [ "Evm"; "stack" ]. -Require ethereum.dao_fork.vm.exceptions. -Axiom ethereum_dao_fork_vm_exceptions_StackUnderflowError : - IsGlobalAlias globals ethereum.dao_fork.vm.exceptions.globals "StackUnderflowError". +Axiom ethereum_dao_fork_vm_exceptions_imports : + AreImported globals "ethereum.dao_fork.vm.exceptions" [ "StackUnderflowError" ]. -Require ethereum.dao_fork.vm.gas. -Axiom ethereum_dao_fork_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_BASE". -Axiom ethereum_dao_fork_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_dao_fork_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "charge_gas". +Axiom ethereum_dao_fork_vm_gas_imports : + AreImported globals "ethereum.dao_fork.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.dao_fork.vm.memory. -Axiom ethereum_dao_fork_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.dao_fork.vm.memory.globals "buffer_read". +Axiom ethereum_dao_fork_vm_memory_imports : + AreImported globals "ethereum.dao_fork.vm.memory" [ "buffer_read" ]. Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -203,19 +190,22 @@ Definition dup_n : Value.t -> Value.t -> M := make_dict [] |) in let data_to_duplicate := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] + BinOp.sub (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), + Constant.int 1 |), - Constant.int 1 - |), - M.get_name (| globals, "item_number" |) - |) |) in + M.get_name (| globals, "item_number" |) + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "stack" |), "push" |), make_list [ @@ -278,14 +268,26 @@ Definition swap_n : Value.t -> Value.t -> M := make_dict [] |) in let _ := M.assign (| - make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| - UnOp.sub (| Constant.int 1 |), - M.get_name (| globals, "item_number" |) - |) |) ], - make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| - UnOp.sub (| Constant.int 1 |), - M.get_name (| globals, "item_number" |) - |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |) ] + make_tuple [ M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + UnOp.sub (| Constant.int 1 |) + |); M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) + |) ], + make_tuple [ M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) + |); M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + UnOp.sub (| Constant.int 1 |) + |) ] |) in let _ := M.assign_op (| BinOp.add, diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/storage.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/storage.v index aca2f43..9cbe938 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/storage.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.dao_fork.vm.instructions.storage". Definition expr_1 : Value.t := Constant.str " @@ -17,33 +17,17 @@ Introduction Implementations of the EVM storage related instructions. ". -Require ethereum.dao_fork.state. -Axiom ethereum_dao_fork_state_get_storage : - IsGlobalAlias globals ethereum.dao_fork.state.globals "get_storage". -Axiom ethereum_dao_fork_state_set_storage : - IsGlobalAlias globals ethereum.dao_fork.state.globals "set_storage". +Axiom ethereum_dao_fork_state_imports : + AreImported globals "ethereum.dao_fork.state" [ "get_storage"; "set_storage" ]. -Require ethereum.dao_fork.vm.__init__. -Axiom ethereum_dao_fork_vm___init___Evm : - IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "Evm". +Axiom ethereum_dao_fork_vm_imports : + AreImported globals "ethereum.dao_fork.vm" [ "Evm" ]. -Require ethereum.dao_fork.vm.gas. -Axiom ethereum_dao_fork_vm_gas_GAS_SLOAD : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_SLOAD". -Axiom ethereum_dao_fork_vm_gas_GAS_STORAGE_CLEAR_REFUND : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_STORAGE_CLEAR_REFUND". -Axiom ethereum_dao_fork_vm_gas_GAS_STORAGE_SET : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_STORAGE_SET". -Axiom ethereum_dao_fork_vm_gas_GAS_STORAGE_UPDATE : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_STORAGE_UPDATE". -Axiom ethereum_dao_fork_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "charge_gas". +Axiom ethereum_dao_fork_vm_gas_imports : + AreImported globals "ethereum.dao_fork.vm.gas" [ "GAS_SLOAD"; "GAS_STORAGE_CLEAR_REFUND"; "GAS_STORAGE_SET"; "GAS_STORAGE_UPDATE"; "charge_gas" ]. -Require ethereum.dao_fork.vm.stack. -Axiom ethereum_dao_fork_vm_stack_pop : - IsGlobalAlias globals ethereum.dao_fork.vm.stack.globals "pop". -Axiom ethereum_dao_fork_vm_stack_push : - IsGlobalAlias globals ethereum.dao_fork.vm.stack.globals "push". +Axiom ethereum_dao_fork_vm_stack_imports : + AreImported globals "ethereum.dao_fork.vm.stack" [ "pop"; "push" ]. Definition sload : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/system.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/system.v index 45307ce..8541798 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/system.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/system.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.dao_fork.vm.instructions.system". Definition expr_1 : Value.t := Constant.str " @@ -17,71 +17,29 @@ Introduction Implementations of the EVM system related instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. -Require ethereum.dao_fork.fork_types. -Axiom ethereum_dao_fork_fork_types_Address : - IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "Address". +Axiom ethereum_dao_fork_fork_types_imports : + AreImported globals "ethereum.dao_fork.fork_types" [ "Address" ]. -Require ethereum.dao_fork.state. -Axiom ethereum_dao_fork_state_account_has_code_or_nonce : - IsGlobalAlias globals ethereum.dao_fork.state.globals "account_has_code_or_nonce". -Axiom ethereum_dao_fork_state_get_account : - IsGlobalAlias globals ethereum.dao_fork.state.globals "get_account". -Axiom ethereum_dao_fork_state_increment_nonce : - IsGlobalAlias globals ethereum.dao_fork.state.globals "increment_nonce". -Axiom ethereum_dao_fork_state_set_account_balance : - IsGlobalAlias globals ethereum.dao_fork.state.globals "set_account_balance". +Axiom ethereum_dao_fork_state_imports : + AreImported globals "ethereum.dao_fork.state" [ "account_has_code_or_nonce"; "get_account"; "increment_nonce"; "set_account_balance" ]. -Require ethereum.dao_fork.utils.address. -Axiom ethereum_dao_fork_utils_address_compute_contract_address : - IsGlobalAlias globals ethereum.dao_fork.utils.address.globals "compute_contract_address". -Axiom ethereum_dao_fork_utils_address_to_address : - IsGlobalAlias globals ethereum.dao_fork.utils.address.globals "to_address". +Axiom ethereum_dao_fork_utils_address_imports : + AreImported globals "ethereum.dao_fork.utils.address" [ "compute_contract_address"; "to_address" ]. -Require ethereum.dao_fork.vm.__init__. -Axiom ethereum_dao_fork_vm___init___Evm : - IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "Evm". -Axiom ethereum_dao_fork_vm___init___Message : - IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "Message". -Axiom ethereum_dao_fork_vm___init___incorporate_child_on_error : - IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "incorporate_child_on_error". -Axiom ethereum_dao_fork_vm___init___incorporate_child_on_success : - IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "incorporate_child_on_success". +Axiom ethereum_dao_fork_vm_imports : + AreImported globals "ethereum.dao_fork.vm" [ "Evm"; "Message"; "incorporate_child_on_error"; "incorporate_child_on_success" ]. -Require ethereum.dao_fork.vm.gas. -Axiom ethereum_dao_fork_vm_gas_GAS_CALL : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_CALL". -Axiom ethereum_dao_fork_vm_gas_GAS_CREATE : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_CREATE". -Axiom ethereum_dao_fork_vm_gas_GAS_ZERO : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_ZERO". -Axiom ethereum_dao_fork_vm_gas_REFUND_SELF_DESTRUCT : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "REFUND_SELF_DESTRUCT". -Axiom ethereum_dao_fork_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_dao_fork_vm_gas_calculate_message_call_gas : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "calculate_message_call_gas". -Axiom ethereum_dao_fork_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "charge_gas". +Axiom ethereum_dao_fork_vm_gas_imports : + AreImported globals "ethereum.dao_fork.vm.gas" [ "GAS_CALL"; "GAS_CREATE"; "GAS_ZERO"; "REFUND_SELF_DESTRUCT"; "calculate_gas_extend_memory"; "calculate_message_call_gas"; "charge_gas" ]. -Require ethereum.dao_fork.vm.memory. -Axiom ethereum_dao_fork_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.dao_fork.vm.memory.globals "memory_read_bytes". -Axiom ethereum_dao_fork_vm_memory_memory_write : - IsGlobalAlias globals ethereum.dao_fork.vm.memory.globals "memory_write". +Axiom ethereum_dao_fork_vm_memory_imports : + AreImported globals "ethereum.dao_fork.vm.memory" [ "memory_read_bytes"; "memory_write" ]. -Require ethereum.dao_fork.vm.stack. -Axiom ethereum_dao_fork_vm_stack_pop : - IsGlobalAlias globals ethereum.dao_fork.vm.stack.globals "pop". -Axiom ethereum_dao_fork_vm_stack_push : - IsGlobalAlias globals ethereum.dao_fork.vm.stack.globals "push". +Axiom ethereum_dao_fork_vm_stack_imports : + AreImported globals "ethereum.dao_fork.vm.stack" [ "pop"; "push" ]. Definition create : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -624,7 +582,12 @@ Definition generic_call : Value.t -> Value.t -> M := make_list [ M.get_field (| M.get_name (| globals, "evm" |), "memory" |); M.get_name (| globals, "memory_output_start_position" |); - M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), M.slice (| Constant.None_, M.get_name (| globals, "actual_output_size" |) |) |) + M.slice (| + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), + Constant.None_, + M.get_name (| globals, "actual_output_size" |), + Constant.None_ + |) ], make_dict [] |) in @@ -1039,20 +1002,28 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in let parent_evm := M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "parent_evm" |) in - While Compare.is_not (| - M.get_name (| globals, "parent_evm" |), - Constant.None_ - |) do - let _ := M.call (| + let _ := + M.while (| + Compare.is_not (| + M.get_name (| globals, "parent_evm" |), + Constant.None_ + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "refunded_accounts" |), "update" |), make_list [ M.get_field (| M.get_name (| globals, "parent_evm" |), "accounts_to_delete" |) ], make_dict [] |) in - let parent_evm := - M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in - EndWhile. + let parent_evm := + M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := (* if *) M.if_then_else (| diff --git a/CoqOfPython/ethereum/dao_fork/vm/interpreter.v b/CoqOfPython/ethereum/dao_fork/vm/interpreter.v index 7ed4c77..cbdc08b 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/interpreter.v +++ b/CoqOfPython/ethereum/dao_fork/vm/interpreter.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.dao_fork.vm.interpreter". Definition expr_1 : Value.t := Constant.str " @@ -17,109 +17,47 @@ Introduction A straightforward interpreter that executes EVM code. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.trace. -Axiom ethereum_trace_EvmStop : - IsGlobalAlias globals ethereum.trace.globals "EvmStop". -Axiom ethereum_trace_OpEnd : - IsGlobalAlias globals ethereum.trace.globals "OpEnd". -Axiom ethereum_trace_OpException : - IsGlobalAlias globals ethereum.trace.globals "OpException". -Axiom ethereum_trace_OpStart : - IsGlobalAlias globals ethereum.trace.globals "OpStart". -Axiom ethereum_trace_PrecompileEnd : - IsGlobalAlias globals ethereum.trace.globals "PrecompileEnd". -Axiom ethereum_trace_PrecompileStart : - IsGlobalAlias globals ethereum.trace.globals "PrecompileStart". -Axiom ethereum_trace_TransactionEnd : - IsGlobalAlias globals ethereum.trace.globals "TransactionEnd". -Axiom ethereum_trace_evm_trace : - IsGlobalAlias globals ethereum.trace.globals "evm_trace". - -Require ethereum.dao_fork.blocks. -Axiom ethereum_dao_fork_blocks_Log : - IsGlobalAlias globals ethereum.dao_fork.blocks.globals "Log". - -Require ethereum.dao_fork.fork_types. -Axiom ethereum_dao_fork_fork_types_Address : - IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "Address". - -Require ethereum.dao_fork.state. -Axiom ethereum_dao_fork_state_account_has_code_or_nonce : - IsGlobalAlias globals ethereum.dao_fork.state.globals "account_has_code_or_nonce". -Axiom ethereum_dao_fork_state_begin_transaction : - IsGlobalAlias globals ethereum.dao_fork.state.globals "begin_transaction". -Axiom ethereum_dao_fork_state_commit_transaction : - IsGlobalAlias globals ethereum.dao_fork.state.globals "commit_transaction". -Axiom ethereum_dao_fork_state_move_ether : - IsGlobalAlias globals ethereum.dao_fork.state.globals "move_ether". -Axiom ethereum_dao_fork_state_rollback_transaction : - IsGlobalAlias globals ethereum.dao_fork.state.globals "rollback_transaction". -Axiom ethereum_dao_fork_state_set_code : - IsGlobalAlias globals ethereum.dao_fork.state.globals "set_code". -Axiom ethereum_dao_fork_state_touch_account : - IsGlobalAlias globals ethereum.dao_fork.state.globals "touch_account". - -Require ethereum.dao_fork.vm.__init__. -Axiom ethereum_dao_fork_vm___init___Message : - IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "Message". - -Require ethereum.dao_fork.vm.gas. -Axiom ethereum_dao_fork_vm_gas_GAS_CODE_DEPOSIT : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_CODE_DEPOSIT". -Axiom ethereum_dao_fork_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "charge_gas". - -Require ethereum.dao_fork.vm.precompiled_contracts.mapping. -Axiom ethereum_dao_fork_vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : - IsGlobalAlias globals ethereum.dao_fork.vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". - -Require ethereum.dao_fork.vm.__init__. -Axiom ethereum_dao_fork_vm___init___Environment : - IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "Environment". -Axiom ethereum_dao_fork_vm___init___Evm : - IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "Evm". - -Require ethereum.dao_fork.vm.exceptions. -Axiom ethereum_dao_fork_vm_exceptions_AddressCollision : - IsGlobalAlias globals ethereum.dao_fork.vm.exceptions.globals "AddressCollision". -Axiom ethereum_dao_fork_vm_exceptions_ExceptionalHalt : - IsGlobalAlias globals ethereum.dao_fork.vm.exceptions.globals "ExceptionalHalt". -Axiom ethereum_dao_fork_vm_exceptions_InvalidOpcode : - IsGlobalAlias globals ethereum.dao_fork.vm.exceptions.globals "InvalidOpcode". -Axiom ethereum_dao_fork_vm_exceptions_StackDepthLimitError : - IsGlobalAlias globals ethereum.dao_fork.vm.exceptions.globals "StackDepthLimitError". - -Require ethereum.dao_fork.vm.instructions.__init__. -Axiom ethereum_dao_fork_vm_instructions___init___Ops : - IsGlobalAlias globals ethereum.dao_fork.vm.instructions.__init__.globals "Ops". -Axiom ethereum_dao_fork_vm_instructions___init___op_implementation : - IsGlobalAlias globals ethereum.dao_fork.vm.instructions.__init__.globals "op_implementation". - -Require ethereum.dao_fork.vm.runtime. -Axiom ethereum_dao_fork_vm_runtime_get_valid_jump_destinations : - IsGlobalAlias globals ethereum.dao_fork.vm.runtime.globals "get_valid_jump_destinations". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Optional"; "Set"; "Tuple"; "Union" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. + +Axiom ethereum_trace_imports : + AreImported globals "ethereum.trace" [ "EvmStop"; "OpEnd"; "OpException"; "OpStart"; "PrecompileEnd"; "PrecompileStart"; "TransactionEnd"; "evm_trace" ]. + +Axiom ethereum_dao_fork_blocks_imports : + AreImported globals "ethereum.dao_fork.blocks" [ "Log" ]. + +Axiom ethereum_dao_fork_fork_types_imports : + AreImported globals "ethereum.dao_fork.fork_types" [ "Address" ]. + +Axiom ethereum_dao_fork_state_imports : + AreImported globals "ethereum.dao_fork.state" [ "account_has_code_or_nonce"; "begin_transaction"; "commit_transaction"; "move_ether"; "rollback_transaction"; "set_code"; "touch_account" ]. + +Axiom ethereum_dao_fork_vm_imports : + AreImported globals "ethereum.dao_fork.vm" [ "Message" ]. + +Axiom ethereum_dao_fork_vm_gas_imports : + AreImported globals "ethereum.dao_fork.vm.gas" [ "GAS_CODE_DEPOSIT"; "charge_gas" ]. + +Axiom ethereum_dao_fork_vm_precompiled_contracts_mapping_imports : + AreImported globals "ethereum.dao_fork.vm.precompiled_contracts.mapping" [ "PRE_COMPILED_CONTRACTS" ]. + +Axiom ethereum_dao_fork_vm_imports : + AreImported globals "ethereum.dao_fork.vm" [ "Environment"; "Evm" ]. + +Axiom ethereum_dao_fork_vm_exceptions_imports : + AreImported globals "ethereum.dao_fork.vm.exceptions" [ "AddressCollision"; "ExceptionalHalt"; "InvalidOpcode"; "StackDepthLimitError" ]. + +Axiom ethereum_dao_fork_vm_instructions_imports : + AreImported globals "ethereum.dao_fork.vm.instructions" [ "Ops"; "op_implementation" ]. + +Axiom ethereum_dao_fork_vm_runtime_imports : + AreImported globals "ethereum.dao_fork.vm.runtime" [ "get_valid_jump_destinations" ]. Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -416,7 +354,7 @@ Definition process_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "StackDepthLimitError" |), make_list [ Constant.str "Stack depth limit reached" diff --git a/CoqOfPython/ethereum/dao_fork/vm/memory.v b/CoqOfPython/ethereum/dao_fork/vm/memory.v index 08d2290..2d024b9 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/memory.v +++ b/CoqOfPython/ethereum/dao_fork/vm/memory.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.dao_fork.vm.memory". Definition expr_1 : Value.t := Constant.str " @@ -17,17 +17,11 @@ Introduction EVM memory operations. ". -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_right_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "right_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "right_pad_zero_bytes" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. Definition memory_write : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,22 +39,27 @@ Definition memory_write : Value.t -> Value.t -> M := Data to write to memory. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + M.slice (| + M.get_name (| globals, "memory" |), + M.get_name (| globals, "start_position" |), + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) - |) |) |), + Constant.None_ + |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_)). @@ -86,22 +85,27 @@ Definition memory_read_bytes : Value.t -> Value.t -> M := Data read from memory. " in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + M.slice (| + M.get_name (| globals, "memory" |), + M.get_name (| globals, "start_position" |), + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |) |) + Constant.None_ + |) |) in M.pure Constant.None_)). @@ -129,22 +133,27 @@ Definition buffer_read : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "right_pad_zero_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "buffer" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + M.slice (| + M.get_name (| globals, "buffer" |), + M.get_name (| globals, "start_position" |), + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |) |); + Constant.None_ + |); M.get_name (| globals, "size" |) ], make_dict [] diff --git a/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/__init__.v index e4c6e92..e714303 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/__init__.v +++ b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.dao_fork.vm.precompiled_contracts.__init__". Definition expr_1 : Value.t := Constant.str " @@ -18,9 +18,8 @@ Addresses of precompiled contracts and mappings to their implementations. ". -Require ethereum.dao_fork.utils.hexadecimal. -Axiom ethereum_dao_fork_utils_hexadecimal_hex_to_address : - IsGlobalAlias globals ethereum.dao_fork.utils.hexadecimal.globals "hex_to_address". +Axiom ethereum_dao_fork_utils_hexadecimal_imports : + AreImported globals "ethereum.dao_fork.utils.hexadecimal" [ "hex_to_address" ]. Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS" ] diff --git a/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/ecrecover.v index c43db35..6067370 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/ecrecover.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.dao_fork.vm.precompiled_contracts.ecrecover". Definition expr_1 : Value.t := Constant.str " @@ -17,39 +17,26 @@ Introduction Implementation of the ECRECOVER precompiled contract. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.crypto.elliptic_curve. -Axiom ethereum_crypto_elliptic_curve_SECP256K1N : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". -Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". +Axiom ethereum_crypto_elliptic_curve_imports : + AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_left_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. -Require ethereum.dao_fork.vm.__init__. -Axiom ethereum_dao_fork_vm___init___Evm : - IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "Evm". +Axiom ethereum_dao_fork_vm_imports : + AreImported globals "ethereum.dao_fork.vm" [ "Evm" ]. -Require ethereum.dao_fork.vm.gas. -Axiom ethereum_dao_fork_vm_gas_GAS_ECRECOVER : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_ECRECOVER". -Axiom ethereum_dao_fork_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "charge_gas". +Axiom ethereum_dao_fork_vm_gas_imports : + AreImported globals "ethereum.dao_fork.vm.gas" [ "GAS_ECRECOVER"; "charge_gas" ]. -Require ethereum.dao_fork.vm.memory. -Axiom ethereum_dao_fork_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.dao_fork.vm.memory.globals "buffer_read". +Axiom ethereum_dao_fork_vm_memory_imports : + AreImported globals "ethereum.dao_fork.vm.memory" [ "buffer_read" ]. Definition ecrecover : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -264,13 +251,18 @@ Definition ecrecover : Value.t -> Value.t -> M := )) |) in (* At stmt: unsupported node type: Try *) let address := - M.get_subscript (| M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "public_key" |) - ], - make_dict [] - |), M.slice (| Constant.int 12, Constant.int 32 |) |) in + M.slice (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), + Constant.int 12, + Constant.int 32, + Constant.None_ + |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/identity.v index e935160..7bf6d15 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/identity.v +++ b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/identity.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.dao_fork.vm.precompiled_contracts.identity". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementation of the `IDENTITY` precompiled contract. ". -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.dao_fork.vm.__init__. -Axiom ethereum_dao_fork_vm___init___Evm : - IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "Evm". +Axiom ethereum_dao_fork_vm_imports : + AreImported globals "ethereum.dao_fork.vm" [ "Evm" ]. -Require ethereum.dao_fork.vm.gas. -Axiom ethereum_dao_fork_vm_gas_GAS_IDENTITY : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_IDENTITY". -Axiom ethereum_dao_fork_vm_gas_GAS_IDENTITY_WORD : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_IDENTITY_WORD". -Axiom ethereum_dao_fork_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "charge_gas". +Axiom ethereum_dao_fork_vm_gas_imports : + AreImported globals "ethereum.dao_fork.vm.gas" [ "GAS_IDENTITY"; "GAS_IDENTITY_WORD"; "charge_gas" ]. Definition identity : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/mapping.v index c487428..8de95c1 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/mapping.v +++ b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/mapping.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.dao_fork.vm.precompiled_contracts.mapping". Definition expr_1 : Value.t := Constant.str " @@ -17,40 +17,25 @@ Introduction Mapping of precompiled contracts their implementations. ". -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". - -Require ethereum.dao_fork.fork_types. -Axiom ethereum_dao_fork_fork_types_Address : - IsGlobalAlias globals ethereum.dao_fork.fork_types.globals "Address". - -Require ethereum.dao_fork.vm.precompiled_contracts.__init__. -Axiom ethereum_dao_fork_vm_precompiled_contracts___init___ECRECOVER_ADDRESS : - IsGlobalAlias globals ethereum.dao_fork.vm.precompiled_contracts.__init__.globals "ECRECOVER_ADDRESS". -Axiom ethereum_dao_fork_vm_precompiled_contracts___init___IDENTITY_ADDRESS : - IsGlobalAlias globals ethereum.dao_fork.vm.precompiled_contracts.__init__.globals "IDENTITY_ADDRESS". -Axiom ethereum_dao_fork_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : - IsGlobalAlias globals ethereum.dao_fork.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". -Axiom ethereum_dao_fork_vm_precompiled_contracts___init___SHA256_ADDRESS : - IsGlobalAlias globals ethereum.dao_fork.vm.precompiled_contracts.__init__.globals "SHA256_ADDRESS". - -Require ethereum.dao_fork.vm.precompiled_contracts.ecrecover. -Axiom ethereum_dao_fork_vm_precompiled_contracts_ecrecover_ecrecover : - IsGlobalAlias globals ethereum.dao_fork.vm.precompiled_contracts.ecrecover.globals "ecrecover". - -Require ethereum.dao_fork.vm.precompiled_contracts.identity. -Axiom ethereum_dao_fork_vm_precompiled_contracts_identity_identity : - IsGlobalAlias globals ethereum.dao_fork.vm.precompiled_contracts.identity.globals "identity". - -Require ethereum.dao_fork.vm.precompiled_contracts.ripemd160. -Axiom ethereum_dao_fork_vm_precompiled_contracts_ripemd160_ripemd160 : - IsGlobalAlias globals ethereum.dao_fork.vm.precompiled_contracts.ripemd160.globals "ripemd160". - -Require ethereum.dao_fork.vm.precompiled_contracts.sha256. -Axiom ethereum_dao_fork_vm_precompiled_contracts_sha256_sha256 : - IsGlobalAlias globals ethereum.dao_fork.vm.precompiled_contracts.sha256.globals "sha256". +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict" ]. + +Axiom ethereum_dao_fork_fork_types_imports : + AreImported globals "ethereum.dao_fork.fork_types" [ "Address" ]. + +Axiom ethereum_dao_fork_vm_precompiled_contracts_imports : + AreImported globals "ethereum.dao_fork.vm.precompiled_contracts" [ "ECRECOVER_ADDRESS"; "IDENTITY_ADDRESS"; "RIPEMD160_ADDRESS"; "SHA256_ADDRESS" ]. + +Axiom ethereum_dao_fork_vm_precompiled_contracts_ecrecover_imports : + AreImported globals "ethereum.dao_fork.vm.precompiled_contracts.ecrecover" [ "ecrecover" ]. + +Axiom ethereum_dao_fork_vm_precompiled_contracts_identity_imports : + AreImported globals "ethereum.dao_fork.vm.precompiled_contracts.identity" [ "identity" ]. + +Axiom ethereum_dao_fork_vm_precompiled_contracts_ripemd160_imports : + AreImported globals "ethereum.dao_fork.vm.precompiled_contracts.ripemd160" [ "ripemd160" ]. + +Axiom ethereum_dao_fork_vm_precompiled_contracts_sha256_imports : + AreImported globals "ethereum.dao_fork.vm.precompiled_contracts.sha256" [ "sha256" ]. (* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/ripemd160.v index ef25944..9a13512 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/ripemd160.v +++ b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/ripemd160.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.dao_fork.vm.precompiled_contracts.ripemd160". Definition expr_1 : Value.t := Constant.str " @@ -19,29 +19,20 @@ Implementation of the `RIPEMD160` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_left_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.dao_fork.vm.__init__. -Axiom ethereum_dao_fork_vm___init___Evm : - IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "Evm". +Axiom ethereum_dao_fork_vm_imports : + AreImported globals "ethereum.dao_fork.vm" [ "Evm" ]. -Require ethereum.dao_fork.vm.gas. -Axiom ethereum_dao_fork_vm_gas_GAS_RIPEMD160 : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_RIPEMD160". -Axiom ethereum_dao_fork_vm_gas_GAS_RIPEMD160_WORD : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_RIPEMD160_WORD". -Axiom ethereum_dao_fork_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "charge_gas". +Axiom ethereum_dao_fork_vm_gas_imports : + AreImported globals "ethereum.dao_fork.vm.gas" [ "GAS_RIPEMD160"; "GAS_RIPEMD160_WORD"; "charge_gas" ]. Definition ripemd160 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/sha256.v index 464c763..4d42913 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/sha256.v +++ b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/sha256.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.dao_fork.vm.precompiled_contracts.sha256". Definition expr_1 : Value.t := Constant.str " @@ -19,25 +19,17 @@ Implementation of the `SHA256` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.dao_fork.vm.__init__. -Axiom ethereum_dao_fork_vm___init___Evm : - IsGlobalAlias globals ethereum.dao_fork.vm.__init__.globals "Evm". +Axiom ethereum_dao_fork_vm_imports : + AreImported globals "ethereum.dao_fork.vm" [ "Evm" ]. -Require ethereum.dao_fork.vm.gas. -Axiom ethereum_dao_fork_vm_gas_GAS_SHA256 : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_SHA256". -Axiom ethereum_dao_fork_vm_gas_GAS_SHA256_WORD : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "GAS_SHA256_WORD". -Axiom ethereum_dao_fork_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.dao_fork.vm.gas.globals "charge_gas". +Axiom ethereum_dao_fork_vm_gas_imports : + AreImported globals "ethereum.dao_fork.vm.gas" [ "GAS_SHA256"; "GAS_SHA256_WORD"; "charge_gas" ]. Definition sha256 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/dao_fork/vm/runtime.v b/CoqOfPython/ethereum/dao_fork/vm/runtime.v index 4d10050..ac94d55 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/runtime.v +++ b/CoqOfPython/ethereum/dao_fork/vm/runtime.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.dao_fork.vm.runtime". Definition expr_1 : Value.t := Constant.str " @@ -17,17 +17,14 @@ Introduction Runtime related operations used while executing EVM code. ". -Require typing. -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". +Axiom typing_imports : + AreImported globals "typing" [ "Set" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.dao_fork.vm.instructions.__init__. -Axiom ethereum_dao_fork_vm_instructions___init___Ops : - IsGlobalAlias globals ethereum.dao_fork.vm.instructions.__init__.globals "Ops". +Axiom ethereum_dao_fork_vm_instructions_imports : + AreImported globals "ethereum.dao_fork.vm.instructions" [ "Ops" ]. Definition get_valid_jump_destinations : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -67,75 +64,83 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := ], make_dict [] |) in - While Compare.lt (| - M.get_name (| globals, "pc" |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "code" |) - ], - make_dict [] - |) - |) do -(* At stmt: unsupported node type: Try *) - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "current_opcode" |), - M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) - |), - (* then *) + let _ := + M.while (| + Compare.lt (| + M.get_name (| globals, "pc" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) + |), ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), - make_list [ - M.get_name (| globals, "pc" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( +(* At stmt: unsupported node type: Try *) let _ := (* if *) M.if_then_else (| - BoolOp.and (| - Compare.lt_e (| - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |), - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |) - |), - ltac:(M.monadic ( - Compare.lt_e (| - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH32" |), "value" |) - |) - )) + Compare.eq (| + M.get_name (| globals, "current_opcode" |), + M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) |), (* then *) ltac:(M.monadic ( - let push_data_size := - BinOp.add (| - BinOp.sub (| - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) - |), - Constant.int 1 - |) in - let pc := BinOp.add - M.get_name (| globals, "push_data_size" |) - M.get_name (| globals, "push_data_size" |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), + make_list [ + M.get_name (| globals, "pc" |) + ], + make_dict [] + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.lt_e (| + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |), + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH32" |), "value" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let push_data_size := + BinOp.add (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) + |), + Constant.int 1 + |) in + let pc := BinOp.add + M.get_name (| globals, "push_data_size" |) + M.get_name (| globals, "push_data_size" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ )) |) in + let pc := BinOp.add + Constant.int 1 + Constant.int 1 in M.pure Constant.None_ - )) |) in - let pc := BinOp.add - Constant.int 1 - Constant.int 1 in - EndWhile. + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.get_name (| globals, "valid_jump_destinations" |) |) in diff --git a/CoqOfPython/ethereum/dao_fork/vm/stack.v b/CoqOfPython/ethereum/dao_fork/vm/stack.v index ce376ae..aae386d 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/stack.v +++ b/CoqOfPython/ethereum/dao_fork/vm/stack.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.dao_fork.vm.stack". Definition expr_1 : Value.t := Constant.str " @@ -17,19 +17,14 @@ Introduction Implementation of the stack operators for the EVM. ". -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". +Axiom typing_imports : + AreImported globals "typing" [ "List" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.dao_fork.vm.exceptions. -Axiom ethereum_dao_fork_vm_exceptions_StackOverflowError : - IsGlobalAlias globals ethereum.dao_fork.vm.exceptions.globals "StackOverflowError". -Axiom ethereum_dao_fork_vm_exceptions_StackUnderflowError : - IsGlobalAlias globals ethereum.dao_fork.vm.exceptions.globals "StackUnderflowError". +Axiom ethereum_dao_fork_vm_exceptions_imports : + AreImported globals "ethereum.dao_fork.vm.exceptions" [ "StackOverflowError"; "StackUnderflowError" ]. Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -63,7 +58,7 @@ Definition pop : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "StackUnderflowError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "StackUnderflowError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -108,7 +103,7 @@ Definition push : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "StackOverflowError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "StackOverflowError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/ethash.v b/CoqOfPython/ethereum/ethash.v index 07fc2e3..a9e4a62 100644 --- a/CoqOfPython/ethereum/ethash.v +++ b/CoqOfPython/ethereum/ethash.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.ethash". Definition expr_1 : Value.t := Constant.str " @@ -13,6 +13,15 @@ header, while the set itself is changed every [`epoch`]. At a high level, the Ethash algorithm is as follows: +1. Create a **seed** value, generated with [`generate_seed`] and based on the + preceding block numbers. +1. From the seed, compute a pseudorandom **cache** with [`generate_cache`]. +1. From the cache, generate a **dataset** with [`generate_dataset`]. The + dataset grows over time based on [`DATASET_EPOCH_GROWTH_SIZE`]. +1. Miners hash slices of the dataset together, which is where the memory + hardness is introduced. Verification of the proof-of-work only requires the + cache to be able to recompute a much smaller subset of the full dataset. + [`DATASET_EPOCH_GROWTH_SIZE`]: ref:ethereum.ethash.DATASET_EPOCH_GROWTH_SIZE [`generate_dataset`]: ref:ethereum.ethash.generate_dataset [`generate_cache`]: ref:ethereum.ethash.generate_cache @@ -22,41 +31,17 @@ At a high level, the Ethash algorithm is as follows: [mem-hard]: https://en.wikipedia.org/wiki/Memory-hard_function ". -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". - -Require ethereum.base_types. -Axiom ethereum_base_types_U32 : - IsGlobalAlias globals ethereum.base_types.globals "U32". -Axiom ethereum_base_types_Bytes8 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes8". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_Hash64 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash64". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". -Axiom ethereum_crypto_hash_keccak512 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak512". - -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_is_prime : - IsGlobalAlias globals ethereum.utils.numeric.globals "is_prime". -Axiom ethereum_utils_numeric_le_bytes_to_uint32_sequence : - IsGlobalAlias globals ethereum.utils.numeric.globals "le_bytes_to_uint32_sequence". -Axiom ethereum_utils_numeric_le_uint32_sequence_to_bytes : - IsGlobalAlias globals ethereum.utils.numeric.globals "le_uint32_sequence_to_bytes". -Axiom ethereum_utils_numeric_le_uint32_sequence_to_uint : - IsGlobalAlias globals ethereum.utils.numeric.globals "le_uint32_sequence_to_uint". +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Tuple"; "Union" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U32"; "Bytes8"; "Uint" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "Hash64"; "keccak256"; "keccak512" ]. + +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "is_prime"; "le_bytes_to_uint32_sequence"; "le_uint32_sequence_to_bytes"; "le_uint32_sequence_to_uint" ]. Definition EPOCH_SIZE : Value.t := M.run ltac:(M.monadic ( Constant.int 30000 @@ -247,26 +232,34 @@ Definition cache_size : Value.t -> Value.t -> M := let size := BinOp.sub M.get_name (| globals, "HASH_BYTES" |) M.get_name (| globals, "HASH_BYTES" |) in - While UnOp.not (| M.call (| - M.get_name (| globals, "is_prime" |), - make_list [ - BinOp.floor_div (| - M.get_name (| globals, "size" |), - M.get_name (| globals, "HASH_BYTES" |) - |) - ], - make_dict [] - |) |) do - let size := BinOp.sub - BinOp.mult (| + let _ := + M.while (| + UnOp.not (| M.call (| + M.get_name (| globals, "is_prime" |), + make_list [ + BinOp.floor_div (| + M.get_name (| globals, "size" |), + M.get_name (| globals, "HASH_BYTES" |) + |) + ], + make_dict [] + |) |), + ltac:(M.monadic ( + let size := BinOp.sub + BinOp.mult (| Constant.int 2, M.get_name (| globals, "HASH_BYTES" |) |) - BinOp.mult (| + BinOp.mult (| Constant.int 2, M.get_name (| globals, "HASH_BYTES" |) |) in - EndWhile. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.get_name (| globals, "size" |) |) in @@ -311,26 +304,34 @@ Definition dataset_size : Value.t -> Value.t -> M := let size := BinOp.sub M.get_name (| globals, "MIX_BYTES" |) M.get_name (| globals, "MIX_BYTES" |) in - While UnOp.not (| M.call (| - M.get_name (| globals, "is_prime" |), - make_list [ - BinOp.floor_div (| - M.get_name (| globals, "size" |), - M.get_name (| globals, "MIX_BYTES" |) - |) - ], - make_dict [] - |) |) do - let size := BinOp.sub - BinOp.mult (| + let _ := + M.while (| + UnOp.not (| M.call (| + M.get_name (| globals, "is_prime" |), + make_list [ + BinOp.floor_div (| + M.get_name (| globals, "size" |), + M.get_name (| globals, "MIX_BYTES" |) + |) + ], + make_dict [] + |) |), + ltac:(M.monadic ( + let size := BinOp.sub + BinOp.mult (| Constant.int 2, M.get_name (| globals, "MIX_BYTES" |) |) - BinOp.mult (| + BinOp.mult (| Constant.int 2, M.get_name (| globals, "MIX_BYTES" |) |) in - EndWhile. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.get_name (| globals, "size" |) |) in @@ -358,22 +359,30 @@ Definition generate_seed : Value.t -> Value.t -> M := Constant.bytes "00", Constant.int 32 |) in - While Compare.not_eq (| - M.get_name (| globals, "epoch_number" |), - Constant.int 0 - |) do - let seed := - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "seed" |) - ], - make_dict [] - |) in - let epoch_number := BinOp.sub - Constant.int 1 - Constant.int 1 in - EndWhile. + let _ := + M.while (| + Compare.not_eq (| + M.get_name (| globals, "epoch_number" |), + Constant.int 0 + |), + ltac:(M.monadic ( + let seed := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "seed" |) + ], + make_dict [] + |) in + let epoch_number := BinOp.sub + Constant.int 1 + Constant.int 1 in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Hash32" |), @@ -431,95 +440,142 @@ Definition generate_cache : Value.t -> Value.t -> M := make_dict [] |) ] in - For M.get_name (| globals, "index" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 1; - M.get_name (| globals, "cache_size_words" |) - ], - make_dict [] - |) do - let cache_item := + let _ := + M.for_ (| + M.get_name (| globals, "index" |), M.call (| - M.get_name (| globals, "keccak512" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "cache" |), BinOp.sub (| - M.get_name (| globals, "index" |), - Constant.int 1 - |) |) - ], - make_dict [] - |) in - let _ := M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 1; + M.get_name (| globals, "cache_size_words" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let cache_item := + M.call (| + M.get_name (| globals, "keccak512" |), + make_list [ + M.get_subscript (| + M.get_name (| globals, "cache" |), + BinOp.sub (| + M.get_name (| globals, "index" |), + Constant.int 1 + |) + |) + ], + make_dict [] + |) in + let _ := M.call (| M.get_field (| M.get_name (| globals, "cache" |), "append" |), make_list [ M.get_name (| globals, "cache_item" |) ], make_dict [] |) in - EndFor. - For M.get_name (| globals, "_" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - M.get_name (| globals, "CACHE_ROUNDS" |) - ], - make_dict [] - |) do - For M.get_name (| globals, "index" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - M.get_name (| globals, "cache_size_words" |) - ], - make_dict [] - |) do - let first_cache_item := - M.get_subscript (| M.get_name (| globals, "cache" |), BinOp.mod_ (| - BinOp.add (| - BinOp.sub (| - M.get_name (| globals, "index" |), - Constant.int 1 - |), + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + let _ := + M.for_ (| + M.get_name (| globals, "_" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "CACHE_ROUNDS" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := + M.for_ (| + M.get_name (| globals, "index" |), M.call (| - M.get_name (| globals, "int" |), - make_list [ - M.get_name (| globals, "cache_size_words" |) - ], - make_dict [] - |) - |), - M.get_name (| globals, "cache_size_words" |) - |) |) in - let second_cache_item := - M.get_subscript (| M.get_name (| globals, "cache" |), BinOp.mod_ (| - M.call (| - M.get_field (| M.get_name (| globals, "U32" |), "from_le_bytes" |), - make_list [ - M.get_subscript (| M.get_subscript (| M.get_name (| globals, "cache" |), M.get_name (| globals, "index" |) |), M.slice (| Constant.int 0, Constant.int 4 |) |) - ], - make_dict [] - |), - M.get_name (| globals, "cache_size_words" |) - |) |) in - let result := - M.call (| - M.get_name (| globals, "bytes" |), - make_list [ - Constant.str "(* At expr: unsupported node type: ListComp *)" - ], - make_dict [] + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "cache_size_words" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let first_cache_item := + M.get_subscript (| + M.get_name (| globals, "cache" |), + BinOp.mod_ (| + BinOp.add (| + BinOp.sub (| + M.get_name (| globals, "index" |), + Constant.int 1 + |), + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "cache_size_words" |) + ], + make_dict [] + |) + |), + M.get_name (| globals, "cache_size_words" |) + |) + |) in + let second_cache_item := + M.get_subscript (| + M.get_name (| globals, "cache" |), + BinOp.mod_ (| + M.call (| + M.get_field (| M.get_name (| globals, "U32" |), "from_le_bytes" |), + make_list [ + M.slice (| + M.get_subscript (| + M.get_name (| globals, "cache" |), + M.get_name (| globals, "index" |) + |), + Constant.int 0, + Constant.int 4, + Constant.None_ + |) + ], + make_dict [] + |), + M.get_name (| globals, "cache_size_words" |) + |) + |) in + let result := + M.call (| + M.get_name (| globals, "bytes" |), + make_list [ + Constant.str "(* At expr: unsupported node type: ListComp *)" + ], + make_dict [] + |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "cache" |), + M.get_name (| globals, "index" |) + |), + M.call (| + M.get_name (| globals, "keccak512" |), + make_list [ + M.get_name (| globals, "result" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "cache" |), M.get_name (| globals, "index" |) |), - M.call (| - M.get_name (| globals, "keccak512" |), - make_list [ - M.get_name (| globals, "result" |) - ], - make_dict [] - |) - |) in - EndFor. - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "tuple" |), @@ -600,7 +656,7 @@ Definition fnv_hash : Value.t -> Value.t -> M := make_list [ Constant.str "(* At expr: unsupported node type: GeneratorExp *)" ], - make_dict [ ] + make_dict [] |) |) in M.pure Constant.None_)). @@ -629,16 +685,19 @@ Definition generate_dataset_item : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "le_uint32_sequence_to_uint" |), make_list [ - M.get_subscript (| M.get_name (| globals, "cache" |), BinOp.mod_ (| - M.get_name (| globals, "index" |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "cache" |) - ], - make_dict [] + M.get_subscript (| + M.get_name (| globals, "cache" |), + BinOp.mod_ (| + M.get_name (| globals, "index" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "cache" |) + ], + make_dict [] + |) |) - |) |) + |) ], make_dict [] |), @@ -658,47 +717,59 @@ Definition generate_dataset_item : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "j" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - M.get_name (| globals, "DATASET_PARENTS" |) - ], - make_dict [] - |) do -(* At stmt: unsupported node type: AnnAssign *) - let cache_index := - BinOp.mod_ (| - M.call (| - M.get_name (| globals, "fnv" |), - make_list [ - BinOp.bit_xor (| - M.get_name (| globals, "index" |), - M.get_name (| globals, "j" |) - |); - M.get_name (| globals, "mix_word" |) - ], - make_dict [] - |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "cache" |) - ], - make_dict [] - |) - |) in - let parent := - M.get_subscript (| M.get_name (| globals, "cache" |), M.get_name (| globals, "cache_index" |) |) in - let mix_integers := + let _ := + M.for_ (| + M.get_name (| globals, "j" |), M.call (| - M.get_name (| globals, "fnv_hash" |), - make_list [ - M.get_name (| globals, "mix_integers" |); - M.get_name (| globals, "parent" |) - ], - make_dict [] - |) in - EndFor. + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "DATASET_PARENTS" |) + ], + make_dict [] + |), + ltac:(M.monadic ( +(* At stmt: unsupported node type: AnnAssign *) + let cache_index := + BinOp.mod_ (| + M.call (| + M.get_name (| globals, "fnv" |), + make_list [ + BinOp.bit_xor (| + M.get_name (| globals, "index" |), + M.get_name (| globals, "j" |) + |); + M.get_name (| globals, "mix_word" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "cache" |) + ], + make_dict [] + |) + |) in + let parent := + M.get_subscript (| + M.get_name (| globals, "cache" |), + M.get_name (| globals, "cache_index" |) + |) in + let mix_integers := + M.call (| + M.get_name (| globals, "fnv_hash" |), + make_list [ + M.get_name (| globals, "mix_integers" |); + M.get_name (| globals, "parent" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let mix := M.call (| M.get_name (| globals, "Hash64" |), @@ -799,7 +870,12 @@ Definition hashimoto : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "U32" |), "from_le_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "seed_hash" |), M.slice (| Constant.None_, Constant.int 4 |) |) + M.slice (| + M.get_name (| globals, "seed_hash" |), + Constant.None_, + Constant.int 4, + Constant.None_ + |) ], make_dict [] |) in @@ -822,50 +898,61 @@ Definition hashimoto : Value.t -> Value.t -> M := M.get_name (| globals, "HASH_BYTES" |) |) |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - M.get_name (| globals, "HASHIMOTO_ACCESSES" |) - ], - make_dict [] - |) do + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "HASHIMOTO_ACCESSES" |) + ], + make_dict [] + |), + ltac:(M.monadic ( (* At stmt: unsupported node type: AnnAssign *) - let parent := - BinOp.mod_ (| - M.call (| - M.get_name (| globals, "fnv" |), - make_list [ - BinOp.bit_xor (| - M.get_name (| globals, "i" |), - M.get_name (| globals, "seed_head" |) - |); - M.get_subscript (| M.get_name (| globals, "mix" |), BinOp.mod_ (| - M.get_name (| globals, "i" |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "mix" |) - ], - make_dict [] - |) - |) |) - ], - make_dict [] - |), - M.get_name (| globals, "rows" |) - |) in - For M.get_name (| globals, "j" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - BinOp.floor_div (| - M.get_name (| globals, "MIX_BYTES" |), - M.get_name (| globals, "HASH_BYTES" |) - |) - ], - make_dict [] - |) do - let new_data := BinOp.add - M.call (| + let parent := + BinOp.mod_ (| + M.call (| + M.get_name (| globals, "fnv" |), + make_list [ + BinOp.bit_xor (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "seed_head" |) + |); + M.get_subscript (| + M.get_name (| globals, "mix" |), + BinOp.mod_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "mix" |) + ], + make_dict [] + |) + |) + |) + ], + make_dict [] + |), + M.get_name (| globals, "rows" |) + |) in + let _ := + M.for_ (| + M.get_name (| globals, "j" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + BinOp.floor_div (| + M.get_name (| globals, "MIX_BYTES" |), + M.get_name (| globals, "HASH_BYTES" |) + |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let new_data := BinOp.add + M.call (| M.get_name (| globals, "fetch_dataset_item" |), make_list [ BinOp.add (| @@ -884,7 +971,7 @@ Definition hashimoto : Value.t -> Value.t -> M := ], make_dict [] |) - M.call (| + M.call (| M.get_name (| globals, "fetch_dataset_item" |), make_list [ BinOp.add (| @@ -903,35 +990,49 @@ Definition hashimoto : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. - let mix := + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + let mix := + M.call (| + M.get_name (| globals, "fnv_hash" |), + make_list [ + M.get_name (| globals, "mix" |); + M.get_name (| globals, "new_data" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + let compressed_mix := + make_list [] in + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; M.call (| - M.get_name (| globals, "fnv_hash" |), + M.get_name (| globals, "len" |), make_list [ - M.get_name (| globals, "mix" |); - M.get_name (| globals, "new_data" |) + M.get_name (| globals, "mix" |) ], make_dict [] - |) in - EndFor. - let compressed_mix := - make_list [] in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 0; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "mix" |) - ], - make_dict [] - |); - Constant.int 4 - ], - make_dict [] - |) do - let _ := M.call (| + |); + Constant.int 4 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "compressed_mix" |), "append" |), make_list [ M.call (| @@ -943,32 +1044,49 @@ Definition hashimoto : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "fnv" |), make_list [ - M.get_subscript (| M.get_name (| globals, "mix" |), M.get_name (| globals, "i" |) |); - M.get_subscript (| M.get_name (| globals, "mix" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) + M.get_subscript (| + M.get_name (| globals, "mix" |), + M.get_name (| globals, "i" |) + |); + M.get_subscript (| + M.get_name (| globals, "mix" |), + BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) + |) ], make_dict [] |); - M.get_subscript (| M.get_name (| globals, "mix" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 2 - |) |) + M.get_subscript (| + M.get_name (| globals, "mix" |), + BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 2 + |) + |) ], make_dict [] |); - M.get_subscript (| M.get_name (| globals, "mix" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 3 - |) |) + M.get_subscript (| + M.get_name (| globals, "mix" |), + BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 3 + |) + |) ], make_dict [] |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let mix_digest := M.call (| M.get_name (| globals, "le_uint32_sequence_to_bytes" |), diff --git a/CoqOfPython/ethereum/exceptions.v b/CoqOfPython/ethereum/exceptions.v index ea05a9f..275bc32 100644 --- a/CoqOfPython/ethereum/exceptions.v +++ b/CoqOfPython/ethereum/exceptions.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.exceptions". Definition expr_1 : Value.t := Constant.str " diff --git a/CoqOfPython/ethereum/fork_criteria.v b/CoqOfPython/ethereum/fork_criteria.v index 819e702..c3040ca 100644 --- a/CoqOfPython/ethereum/fork_criteria.v +++ b/CoqOfPython/ethereum/fork_criteria.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.fork_criteria". Definition expr_1 : Value.t := Constant.str " @@ -19,17 +19,11 @@ Classes for specifying criteria for Mainnet forks. (* At top_level_stmt: unsupported node type: Import *) -Require abc. -Axiom abc_ABC : - IsGlobalAlias globals abc.globals "ABC". -Axiom abc_abstractmethod : - IsGlobalAlias globals abc.globals "abstractmethod". +Axiom abc_imports : + AreImported globals "abc" [ "ABC"; "abstractmethod" ]. -Require typing. -Axiom typing_Final : - IsGlobalAlias globals typing.globals "Final". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_imports : + AreImported globals "typing" [ "Final"; "Tuple" ]. Definition ForkCriteria : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/frontier/__init__.v b/CoqOfPython/ethereum/frontier/__init__.v index c80e652..ba6be25 100644 --- a/CoqOfPython/ethereum/frontier/__init__.v +++ b/CoqOfPython/ethereum/frontier/__init__.v @@ -1,15 +1,14 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.frontier.__init__". Definition expr_1 : Value.t := Constant.str " Frontier is the first production-ready iteration of the Ethereum protocol. ". -Require ethereum.fork_criteria. -Axiom ethereum_fork_criteria_ByBlockNumber : - IsGlobalAlias globals ethereum.fork_criteria.globals "ByBlockNumber". +Axiom ethereum_fork_criteria_imports : + AreImported globals "ethereum.fork_criteria" [ "ByBlockNumber" ]. Definition FORK_CRITERIA : Value.t := M.run ltac:(M.monadic ( M.call (| diff --git a/CoqOfPython/ethereum/frontier/blocks.v b/CoqOfPython/ethereum/frontier/blocks.v index 3ed662a..f3822d6 100644 --- a/CoqOfPython/ethereum/frontier/blocks.v +++ b/CoqOfPython/ethereum/frontier/blocks.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.frontier.blocks". Definition expr_1 : Value.t := Constant.str " @@ -14,43 +14,23 @@ history of all state transitions that have happened since the genesis of the chain. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes8 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes8". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". - -Require ethereum.frontier.fork_types. -Axiom ethereum_frontier_fork_types_Address : - IsGlobalAlias globals ethereum.frontier.fork_types.globals "Address". -Axiom ethereum_frontier_fork_types_Bloom : - IsGlobalAlias globals ethereum.frontier.fork_types.globals "Bloom". -Axiom ethereum_frontier_fork_types_Root : - IsGlobalAlias globals ethereum.frontier.fork_types.globals "Root". - -Require ethereum.frontier.transactions. -Axiom ethereum_frontier_transactions_Transaction : - IsGlobalAlias globals ethereum.frontier.transactions.globals "Transaction". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes8"; "Bytes32"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. + +Axiom ethereum_frontier_fork_types_imports : + AreImported globals "ethereum.frontier.fork_types" [ "Address"; "Bloom"; "Root" ]. + +Axiom ethereum_frontier_transactions_imports : + AreImported globals "ethereum.frontier.transactions" [ "Transaction" ]. Definition Header : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/frontier/bloom.v b/CoqOfPython/ethereum/frontier/bloom.v index cc6bb49..1bf769d 100644 --- a/CoqOfPython/ethereum/frontier/bloom.v +++ b/CoqOfPython/ethereum/frontier/bloom.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.frontier.bloom". Definition expr_1 : Value.t := Constant.str " @@ -21,25 +21,20 @@ for efficient searching of logs by address and/or topic, by rapidly eliminating blocks and receipts from their search. ". -Require typing. -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_imports : + AreImported globals "typing" [ "Tuple" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. -Require ethereum.frontier.blocks. -Axiom ethereum_frontier_blocks_Log : - IsGlobalAlias globals ethereum.frontier.blocks.globals "Log". +Axiom ethereum_frontier_blocks_imports : + AreImported globals "ethereum.frontier.blocks" [ "Log" ]. -Require ethereum.frontier.fork_types. -Axiom ethereum_frontier_fork_types_Bloom : - IsGlobalAlias globals ethereum.frontier.fork_types.globals "Bloom". +Axiom ethereum_frontier_fork_types_imports : + AreImported globals "ethereum.frontier.fork_types" [ "Bloom" ]. Definition add_to_bloom : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -66,50 +61,70 @@ Definition add_to_bloom : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "idx" |) in make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ] do - let bit_to_set := - BinOp.bit_and (| - M.call (| - M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "hash" |), M.slice (| M.get_name (| globals, "idx" |), BinOp.add (| - M.get_name (| globals, "idx" |), - Constant.int 2 - |) |) |) - ], - make_dict [] - |), - Constant.int 2047 - |) in - let bit_index := - BinOp.sub (| - Constant.int 2047, - M.get_name (| globals, "bit_to_set" |) - |) in - let byte_index := - BinOp.floor_div (| - M.get_name (| globals, "bit_index" |), - Constant.int 8 - |) in - let bit_value := - BinOp.l_shift (| - Constant.int 1, - BinOp.sub (| - Constant.int 7, - BinOp.mod_ (| + let _ := + M.for_ (| + M.get_name (| globals, "idx" |), + make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ], + ltac:(M.monadic ( + let bit_to_set := + BinOp.bit_and (| + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.slice (| + M.get_name (| globals, "hash" |), + M.get_name (| globals, "idx" |), + BinOp.add (| + M.get_name (| globals, "idx" |), + Constant.int 2 + |), + Constant.None_ + |) + ], + make_dict [] + |), + Constant.int 2047 + |) in + let bit_index := + BinOp.sub (| + Constant.int 2047, + M.get_name (| globals, "bit_to_set" |) + |) in + let byte_index := + BinOp.floor_div (| M.get_name (| globals, "bit_index" |), Constant.int 8 + |) in + let bit_value := + BinOp.l_shift (| + Constant.int 1, + BinOp.sub (| + Constant.int 7, + BinOp.mod_ (| + M.get_name (| globals, "bit_index" |), + Constant.int 8 + |) + |) + |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "bloom" |), + M.get_name (| globals, "byte_index" |) + |), + BinOp.bit_or (| + M.get_subscript (| + M.get_name (| globals, "bloom" |), + M.get_name (| globals, "byte_index" |) + |), + M.get_name (| globals, "bit_value" |) |) - |) - |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), - BinOp.bit_or (| - M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), - M.get_name (| globals, "bit_value" |) - |) - |) in - EndFor. + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_)). Definition logs_bloom : Value.t -> Value.t -> M := @@ -132,8 +147,12 @@ Definition logs_bloom : Value.t -> Value.t -> M := the caller address and the log topics. " in (* At stmt: unsupported node type: AnnAssign *) - For M.get_name (| globals, "log" |) in M.get_name (| globals, "logs" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "log" |), + M.get_name (| globals, "logs" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "add_to_bloom" |), make_list [ M.get_name (| globals, "bloom" |); @@ -141,8 +160,12 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "topic" |) in M.get_field (| M.get_name (| globals, "log" |), "topics" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "topic" |), + M.get_field (| M.get_name (| globals, "log" |), "topics" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "add_to_bloom" |), make_list [ M.get_name (| globals, "bloom" |); @@ -150,8 +173,18 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Bloom" |), diff --git a/CoqOfPython/ethereum/frontier/fork.v b/CoqOfPython/ethereum/frontier/fork.v index 732bbc8..031f860 100644 --- a/CoqOfPython/ethereum/frontier/fork.v +++ b/CoqOfPython/ethereum/frontier/fork.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.frontier.fork". Definition expr_1 : Value.t := Constant.str " @@ -17,133 +17,59 @@ Introduction Entry point for the Ethereum specification. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.crypto.elliptic_curve. -Axiom ethereum_crypto_elliptic_curve_SECP256K1N : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". -Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.ethash. -Axiom ethereum_ethash_dataset_size : - IsGlobalAlias globals ethereum.ethash.globals "dataset_size". -Axiom ethereum_ethash_generate_cache : - IsGlobalAlias globals ethereum.ethash.globals "generate_cache". -Axiom ethereum_ethash_hashimoto_light : - IsGlobalAlias globals ethereum.ethash.globals "hashimoto_light". - -Require ethereum.exceptions. -Axiom ethereum_exceptions_InvalidBlock : - IsGlobalAlias globals ethereum.exceptions.globals "InvalidBlock". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U64 : - IsGlobalAlias globals ethereum.base_types.globals "U64". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_U256_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.frontier.__init__. -Axiom ethereum_frontier___init___vm : - IsGlobalAlias globals ethereum.frontier.__init__.globals "vm". - -Require ethereum.frontier.blocks. -Axiom ethereum_frontier_blocks_Block : - IsGlobalAlias globals ethereum.frontier.blocks.globals "Block". -Axiom ethereum_frontier_blocks_Header : - IsGlobalAlias globals ethereum.frontier.blocks.globals "Header". -Axiom ethereum_frontier_blocks_Log : - IsGlobalAlias globals ethereum.frontier.blocks.globals "Log". -Axiom ethereum_frontier_blocks_Receipt : - IsGlobalAlias globals ethereum.frontier.blocks.globals "Receipt". - -Require ethereum.frontier.bloom. -Axiom ethereum_frontier_bloom_logs_bloom : - IsGlobalAlias globals ethereum.frontier.bloom.globals "logs_bloom". - -Require ethereum.frontier.fork_types. -Axiom ethereum_frontier_fork_types_Address : - IsGlobalAlias globals ethereum.frontier.fork_types.globals "Address". -Axiom ethereum_frontier_fork_types_Bloom : - IsGlobalAlias globals ethereum.frontier.fork_types.globals "Bloom". -Axiom ethereum_frontier_fork_types_Root : - IsGlobalAlias globals ethereum.frontier.fork_types.globals "Root". - -Require ethereum.frontier.state. -Axiom ethereum_frontier_state_State : - IsGlobalAlias globals ethereum.frontier.state.globals "State". -Axiom ethereum_frontier_state_create_ether : - IsGlobalAlias globals ethereum.frontier.state.globals "create_ether". -Axiom ethereum_frontier_state_destroy_account : - IsGlobalAlias globals ethereum.frontier.state.globals "destroy_account". -Axiom ethereum_frontier_state_get_account : - IsGlobalAlias globals ethereum.frontier.state.globals "get_account". -Axiom ethereum_frontier_state_increment_nonce : - IsGlobalAlias globals ethereum.frontier.state.globals "increment_nonce". -Axiom ethereum_frontier_state_set_account_balance : - IsGlobalAlias globals ethereum.frontier.state.globals "set_account_balance". -Axiom ethereum_frontier_state_state_root : - IsGlobalAlias globals ethereum.frontier.state.globals "state_root". - -Require ethereum.frontier.transactions. -Axiom ethereum_frontier_transactions_TX_BASE_COST : - IsGlobalAlias globals ethereum.frontier.transactions.globals "TX_BASE_COST". -Axiom ethereum_frontier_transactions_TX_DATA_COST_PER_NON_ZERO : - IsGlobalAlias globals ethereum.frontier.transactions.globals "TX_DATA_COST_PER_NON_ZERO". -Axiom ethereum_frontier_transactions_TX_DATA_COST_PER_ZERO : - IsGlobalAlias globals ethereum.frontier.transactions.globals "TX_DATA_COST_PER_ZERO". -Axiom ethereum_frontier_transactions_Transaction : - IsGlobalAlias globals ethereum.frontier.transactions.globals "Transaction". - -Require ethereum.frontier.trie. -Axiom ethereum_frontier_trie_Trie : - IsGlobalAlias globals ethereum.frontier.trie.globals "Trie". -Axiom ethereum_frontier_trie_root : - IsGlobalAlias globals ethereum.frontier.trie.globals "root". -Axiom ethereum_frontier_trie_trie_set : - IsGlobalAlias globals ethereum.frontier.trie.globals "trie_set". - -Require ethereum.frontier.utils.message. -Axiom ethereum_frontier_utils_message_prepare_message : - IsGlobalAlias globals ethereum.frontier.utils.message.globals "prepare_message". - -Require ethereum.frontier.vm.interpreter. -Axiom ethereum_frontier_vm_interpreter_process_message_call : - IsGlobalAlias globals ethereum.frontier.vm.interpreter.globals "process_message_call". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple" ]. + +Axiom ethereum_crypto_elliptic_curve_imports : + AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. + +Axiom ethereum_ethash_imports : + AreImported globals "ethereum.ethash" [ "dataset_size"; "generate_cache"; "hashimoto_light" ]. + +Axiom ethereum_exceptions_imports : + AreImported globals "ethereum.exceptions" [ "InvalidBlock" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U64"; "U256"; "U256_CEIL_VALUE"; "Bytes"; "Bytes32"; "Uint" ]. + +Axiom ethereum_frontier_imports : + AreImported globals "ethereum.frontier" [ "vm" ]. + +Axiom ethereum_frontier_blocks_imports : + AreImported globals "ethereum.frontier.blocks" [ "Block"; "Header"; "Log"; "Receipt" ]. + +Axiom ethereum_frontier_bloom_imports : + AreImported globals "ethereum.frontier.bloom" [ "logs_bloom" ]. + +Axiom ethereum_frontier_fork_types_imports : + AreImported globals "ethereum.frontier.fork_types" [ "Address"; "Bloom"; "Root" ]. + +Axiom ethereum_frontier_state_imports : + AreImported globals "ethereum.frontier.state" [ "State"; "create_ether"; "destroy_account"; "get_account"; "increment_nonce"; "set_account_balance"; "state_root" ]. + +Axiom ethereum_frontier_transactions_imports : + AreImported globals "ethereum.frontier.transactions" [ "TX_BASE_COST"; "TX_DATA_COST_PER_NON_ZERO"; "TX_DATA_COST_PER_ZERO"; "Transaction" ]. + +Axiom ethereum_frontier_trie_imports : + AreImported globals "ethereum.frontier.trie" [ "Trie"; "root"; "trie_set" ]. + +Axiom ethereum_frontier_utils_message_imports : + AreImported globals "ethereum.frontier.utils.message" [ "prepare_message" ]. + +Axiom ethereum_frontier_vm_interpreter_imports : + AreImported globals "ethereum.frontier.vm.interpreter" [ "process_message_call" ]. Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -242,7 +168,12 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := Hashes of the recent 256 blocks in order of increasing block number. " in let recent_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) in + M.slice (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| Constant.int 255 |), + Constant.None_, + Constant.None_ + |) in let _ := (* if *) M.if_then_else (| @@ -268,17 +199,26 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := )) |) in let recent_block_hashes := make_list [] in - For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_blocks" |) do - let prev_block_hash := - M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "block" |), + M.get_name (| globals, "recent_blocks" |), + ltac:(M.monadic ( + let prev_block_hash := + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in + let _ := M.call (| M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), make_list [ M.get_name (| globals, "prev_block_hash" |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let most_recent_block_hash := M.call (| M.get_name (| globals, "keccak256" |), @@ -286,7 +226,10 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), make_list [ - M.get_field (| M.get_subscript (| M.get_name (| globals, "recent_blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) + M.get_field (| M.get_subscript (| + M.get_name (| globals, "recent_blocks" |), + UnOp.sub (| Constant.int 1 |) + |), "header" |) ], make_dict [] |) @@ -330,7 +273,10 @@ Definition state_transition : Value.t -> Value.t -> M := Block to apply to `chain`. " in let parent_header := - M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) in + M.get_field (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| Constant.int 1 |) + |), "header" |) in let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ @@ -449,7 +395,12 @@ Definition state_transition : Value.t -> Value.t -> M := ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) + M.slice (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| Constant.int 255 |), + Constant.None_, + Constant.None_ + |) |) in M.pure Constant.None_ (* else *) @@ -865,14 +816,18 @@ Definition apply_body : Value.t -> Value.t -> M := (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) - For make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "tx" |) ] in M.call (| - M.get_name (| globals, "enumerate" |), - make_list [ - M.get_name (| globals, "transactions" |) - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "tx" |) ], + M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "transactions" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ M.get_name (| globals, "transactions_trie" |); @@ -893,56 +848,56 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_address := - M.call (| - M.get_name (| globals, "check_transaction" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "gas_available" |) - ], - make_dict [] - |) in - let env := - M.call (| - M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), - make_list [], - make_dict [] - |) in - let _ := M.assign (| - make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |) ], - M.call (| - M.get_name (| globals, "process_transaction" |), - make_list [ - M.get_name (| globals, "env" |); - M.get_name (| globals, "tx" |) - ], - make_dict [] - |) - |) in - let gas_available := BinOp.sub - M.get_name (| globals, "gas_used" |) - M.get_name (| globals, "gas_used" |) in - let receipt := - M.call (| - M.get_name (| globals, "make_receipt" |), - make_list [ - M.get_name (| globals, "tx" |); + let sender_address := M.call (| - M.get_name (| globals, "state_root" |), + M.get_name (| globals, "check_transaction" |), make_list [ - M.get_name (| globals, "state" |) + M.get_name (| globals, "tx" |); + M.get_name (| globals, "gas_available" |) ], make_dict [] - |); - BinOp.sub (| - M.get_name (| globals, "block_gas_limit" |), - M.get_name (| globals, "gas_available" |) - |); - M.get_name (| globals, "logs" |) - ], - make_dict [] - |) in - let _ := M.call (| + |) in + let env := + M.call (| + M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |) ], + M.call (| + M.get_name (| globals, "process_transaction" |), + make_list [ + M.get_name (| globals, "env" |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) in + let gas_available := BinOp.sub + M.get_name (| globals, "gas_used" |) + M.get_name (| globals, "gas_used" |) in + let receipt := + M.call (| + M.get_name (| globals, "make_receipt" |), + make_list [ + M.get_name (| globals, "tx" |); + M.call (| + M.get_name (| globals, "state_root" |), + make_list [ + M.get_name (| globals, "state" |) + ], + make_dict [] + |); + BinOp.sub (| + M.get_name (| globals, "block_gas_limit" |), + M.get_name (| globals, "gas_available" |) + |); + M.get_name (| globals, "logs" |) + ], + make_dict [] + |) in + let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ M.get_name (| globals, "receipts_trie" |); @@ -963,10 +918,15 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_logs := BinOp.add - M.get_name (| globals, "logs" |) - M.get_name (| globals, "logs" |) in - EndFor. + let block_logs := BinOp.add + M.get_name (| globals, "logs" |) + M.get_name (| globals, "logs" |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.call (| M.get_name (| globals, "pay_rewards" |), make_list [ @@ -1095,8 +1055,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "ommer" |), + M.get_name (| globals, "ommers" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ BoolOp.and (| @@ -1115,15 +1079,18 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_parent_header := - M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), BinOp.sub (| - UnOp.sub (| BinOp.sub (| - M.get_field (| M.get_name (| globals, "block_header" |), "number" |), - M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) |), - Constant.int 1 - |) |), "header" |) in - let _ := M.call (| + let ommer_parent_header := + M.get_field (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + BinOp.sub (| + UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) |), + Constant.int 1 + |) + |), "header" |) in + let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ M.get_name (| globals, "ommer" |); @@ -1131,7 +1098,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1181,33 +1153,54 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let recent_canonical_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| BinOp.add (| - M.get_name (| globals, "MAX_OMMER_DEPTH" |), - Constant.int 1 - |) |), Constant.None_ |) |) in + M.slice (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| BinOp.add (| + M.get_name (| globals, "MAX_OMMER_DEPTH" |), + Constant.int 1 + |) |), + Constant.None_, + Constant.None_ + |) in let recent_canonical_block_hashes := Constant.str "(* At expr: unsupported node type: SetComp *)" in (* At stmt: unsupported node type: AnnAssign *) - For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_canonical_blocks" |) do - let recent_ommers_hashes := + let _ := + M.for_ (| + M.get_name (| globals, "block" |), + M.get_name (| globals, "recent_canonical_blocks" |), + ltac:(M.monadic ( + let recent_ommers_hashes := + M.call (| + M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), + make_list [ + Constant.str "(* At expr: unsupported node type: SetComp *)" + ], + make_dict [] + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "ommer_index" |); M.get_name (| globals, "ommer" |) ], M.call (| - M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), - make_list [ - Constant.str "(* At expr: unsupported node type: SetComp *)" - ], - make_dict [] - |) in - EndFor. - For make_tuple [ M.get_name (| globals, "ommer_index" |); M.get_name (| globals, "ommer" |) ] in M.call (| - M.get_name (| globals, "enumerate" |), - make_list [ - M.get_name (| globals, "ommers" |) - ], - make_dict [] - |) do - let ommer_hash := - M.get_subscript (| M.get_name (| globals, "ommers_hashes" |), M.get_name (| globals, "ommer_index" |) |) in - let _ := M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let ommer_hash := + M.get_subscript (| + M.get_name (| globals, "ommers_hashes" |), + M.get_name (| globals, "ommer_index" |) + |) in + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_eq (| @@ -1218,7 +1211,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_in (| @@ -1229,7 +1222,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_in (| @@ -1240,12 +1233,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_age := - BinOp.sub (| - M.get_field (| M.get_name (| globals, "block_header" |), "number" |), - M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) in - let _ := M.call (| + let ommer_age := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) in + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ BoolOp.and (| @@ -1264,10 +1257,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.in (| + Compare.in_ (| M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), M.get_name (| globals, "recent_canonical_block_hashes" |) |); @@ -1275,7 +1268,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_eq (| @@ -1286,7 +1279,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_)). Definition pay_rewards : Value.t -> Value.t -> M := @@ -1343,30 +1341,34 @@ Definition pay_rewards : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do - let ommer_age := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - BinOp.sub (| - M.get_name (| globals, "block_number" |), - M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) - ], - make_dict [] - |) in - let ommer_miner_reward := - BinOp.floor_div (| - BinOp.mult (| - BinOp.sub (| - Constant.int 8, - M.get_name (| globals, "ommer_age" |) - |), - M.get_name (| globals, "BLOCK_REWARD" |) - |), - Constant.int 8 - |) in - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "ommer" |), + M.get_name (| globals, "ommers" |), + ltac:(M.monadic ( + let ommer_age := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "block_number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) + ], + make_dict [] + |) in + let ommer_miner_reward := + BinOp.floor_div (| + BinOp.mult (| + BinOp.sub (| + Constant.int 8, + M.get_name (| globals, "ommer_age" |) + |), + M.get_name (| globals, "BLOCK_REWARD" |) + |), + Constant.int 8 + |) in + let _ := M.call (| M.get_name (| globals, "create_ether" |), make_list [ M.get_name (| globals, "state" |); @@ -1375,7 +1377,12 @@ Definition pay_rewards : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_)). Definition process_transaction : Value.t -> Value.t -> M := @@ -1615,8 +1622,12 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "accounts_to_delete" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "output" |), "accounts_to_delete" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "destroy_account" |), make_list [ M.get_field (| M.get_name (| globals, "env" |), "state" |); @@ -1624,7 +1635,12 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |) ] |) in @@ -1712,28 +1728,37 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := " in let data_cost := Constant.int 0 in - For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "byte" |), - Constant.int 0 - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "byte" |), + M.get_field (| M.get_name (| globals, "tx" |), "data" |), ltac:(M.monadic ( - let data_cost := BinOp.add - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "byte" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let data_cost := BinOp.add - M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Uint" |), @@ -1855,13 +1880,18 @@ Definition recover_sender : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "Address" |), make_list [ - M.get_subscript (| M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "public_key" |) - ], - make_dict [] - |), M.slice (| Constant.int 12, Constant.int 32 |) |) + M.slice (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), + Constant.int 12, + Constant.int 32, + Constant.None_ + |) ], make_dict [] |) diff --git a/CoqOfPython/ethereum/frontier/fork_types.v b/CoqOfPython/ethereum/frontier/fork_types.v index cc8e4a1..46b00d0 100644 --- a/CoqOfPython/ethereum/frontier/fork_types.v +++ b/CoqOfPython/ethereum/frontier/fork_types.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.frontier.fork_types". Definition expr_1 : Value.t := Constant.str " @@ -17,33 +17,17 @@ Introduction Types re-used throughout the specification, which are specific to Ethereum. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes20 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes20". -Axiom ethereum_base_types_Bytes256 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes20"; "Bytes256"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) diff --git a/CoqOfPython/ethereum/frontier/state.v b/CoqOfPython/ethereum/frontier/state.v index e984742..69597ae 100644 --- a/CoqOfPython/ethereum/frontier/state.v +++ b/CoqOfPython/ethereum/frontier/state.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.frontier.state". Definition expr_1 : Value.t := Constant.str " @@ -22,61 +22,23 @@ There is a distinction between an account that does not exist and `EMPTY_ACCOUNT`. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". -Axiom dataclasses_field : - IsGlobalAlias globals dataclasses.globals "field". - -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_modify : - IsGlobalAlias globals ethereum.base_types.globals "modify". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.frontier.fork_types. -Axiom ethereum_frontier_fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals ethereum.frontier.fork_types.globals "EMPTY_ACCOUNT". -Axiom ethereum_frontier_fork_types_Account : - IsGlobalAlias globals ethereum.frontier.fork_types.globals "Account". -Axiom ethereum_frontier_fork_types_Address : - IsGlobalAlias globals ethereum.frontier.fork_types.globals "Address". -Axiom ethereum_frontier_fork_types_Root : - IsGlobalAlias globals ethereum.frontier.fork_types.globals "Root". - -Require ethereum.frontier.trie. -Axiom ethereum_frontier_trie_EMPTY_TRIE_ROOT : - IsGlobalAlias globals ethereum.frontier.trie.globals "EMPTY_TRIE_ROOT". -Axiom ethereum_frontier_trie_Trie : - IsGlobalAlias globals ethereum.frontier.trie.globals "Trie". -Axiom ethereum_frontier_trie_copy_trie : - IsGlobalAlias globals ethereum.frontier.trie.globals "copy_trie". -Axiom ethereum_frontier_trie_root : - IsGlobalAlias globals ethereum.frontier.trie.globals "root". -Axiom ethereum_frontier_trie_trie_get : - IsGlobalAlias globals ethereum.frontier.trie.globals "trie_get". -Axiom ethereum_frontier_trie_trie_set : - IsGlobalAlias globals ethereum.frontier.trie.globals "trie_set". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass"; "field" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict"; "List"; "Optional"; "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "modify" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_frontier_fork_types_imports : + AreImported globals "ethereum.frontier.fork_types" [ "EMPTY_ACCOUNT"; "Account"; "Address"; "Root" ]. + +Axiom ethereum_frontier_trie_imports : + AreImported globals "ethereum.frontier.trie" [ "EMPTY_TRIE_ROOT"; "Trie"; "copy_trie"; "root"; "trie_get"; "trie_set" ]. Definition State : Value.t := builtins.make_klass @@ -338,13 +300,16 @@ Definition destroy_storage : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -479,7 +444,10 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), + M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |), M.get_name (| globals, "trie" |) |) in M.pure Constant.None_ @@ -505,7 +473,10 @@ Definition set_storage : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -535,7 +506,7 @@ Definition storage_root : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), @@ -545,7 +516,10 @@ Definition storage_root : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "root" |), make_list [ - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) + M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |) ], make_dict [] |) diff --git a/CoqOfPython/ethereum/frontier/transactions.v b/CoqOfPython/ethereum/frontier/transactions.v index bbcdf4d..16a12e0 100644 --- a/CoqOfPython/ethereum/frontier/transactions.v +++ b/CoqOfPython/ethereum/frontier/transactions.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.frontier.transactions". Definition expr_1 : Value.t := Constant.str " @@ -9,29 +9,17 @@ submitted to be executed. If Ethereum is viewed as a state machine, transactions are the events that move between states. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.frontier.fork_types. -Axiom ethereum_frontier_fork_types_Address : - IsGlobalAlias globals ethereum.frontier.fork_types.globals "Address". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Union" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_frontier_fork_types_imports : + AreImported globals "ethereum.frontier.fork_types" [ "Address" ]. Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( Constant.int 21000 diff --git a/CoqOfPython/ethereum/frontier/trie.v b/CoqOfPython/ethereum/frontier/trie.v index 509578c..fad3922 100644 --- a/CoqOfPython/ethereum/frontier/trie.v +++ b/CoqOfPython/ethereum/frontier/trie.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.frontier.trie". Definition expr_1 : Value.t := Constant.str " @@ -20,79 +20,35 @@ The state trie is the structure responsible for storing (* At top_level_stmt: unsupported node type: Import *) -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". -Axiom dataclasses_field : - IsGlobalAlias globals dataclasses.globals "field". - -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". -Axiom typing_Generic : - IsGlobalAlias globals typing.globals "Generic". -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Mapping : - IsGlobalAlias globals typing.globals "Mapping". -Axiom typing_MutableMapping : - IsGlobalAlias globals typing.globals "MutableMapping". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Sequence : - IsGlobalAlias globals typing.globals "Sequence". -Axiom typing_TypeVar : - IsGlobalAlias globals typing.globals "TypeVar". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". -Axiom typing_cast : - IsGlobalAlias globals typing.globals "cast". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.utils.hexadecimal. -Axiom ethereum_utils_hexadecimal_hex_to_bytes : - IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.frontier.blocks. -Axiom ethereum_frontier_blocks_Receipt : - IsGlobalAlias globals ethereum.frontier.blocks.globals "Receipt". - -Require ethereum.frontier.fork_types. -Axiom ethereum_frontier_fork_types_Account : - IsGlobalAlias globals ethereum.frontier.fork_types.globals "Account". -Axiom ethereum_frontier_fork_types_Address : - IsGlobalAlias globals ethereum.frontier.fork_types.globals "Address". -Axiom ethereum_frontier_fork_types_Root : - IsGlobalAlias globals ethereum.frontier.fork_types.globals "Root". -Axiom ethereum_frontier_fork_types_encode_account : - IsGlobalAlias globals ethereum.frontier.fork_types.globals "encode_account". - -Require ethereum.frontier.transactions. -Axiom ethereum_frontier_transactions_Transaction : - IsGlobalAlias globals ethereum.frontier.transactions.globals "Transaction". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass"; "field" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict"; "Generic"; "List"; "Mapping"; "MutableMapping"; "Optional"; "Sequence"; "TypeVar"; "Union"; "cast" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_utils_hexadecimal_imports : + AreImported globals "ethereum.utils.hexadecimal" [ "hex_to_bytes" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_frontier_blocks_imports : + AreImported globals "ethereum.frontier.blocks" [ "Receipt" ]. + +Axiom ethereum_frontier_fork_types_imports : + AreImported globals "ethereum.frontier.fork_types" [ "Account"; "Address"; "Root"; "encode_account" ]. + +Axiom ethereum_frontier_transactions_imports : + AreImported globals "ethereum.frontier.transactions" [ "Transaction" ]. Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -111,7 +67,10 @@ Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( )). Definition Node : Value.t := M.run ltac:(M.monadic ( - M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Bytes" |); M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |); Constant.None_ ] |) + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Bytes" |); M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |); Constant.None_ ] + |) )). Definition K : Value.t := M.run ltac:(M.monadic ( @@ -129,11 +88,23 @@ Definition V : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "TypeVar" |), make_list [ Constant.str "V"; - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Account" |) |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Bytes" |) |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Account" |) + |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Bytes" |) + |); M.get_name (| globals, "Bytes" |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Transaction" |) |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Receipt" |) |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Transaction" |) + |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Receipt" |) + |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |) ], @@ -172,7 +143,10 @@ Definition BranchNode : Value.t := ]. Definition InternalNode : Value.t := M.run ltac:(M.monadic ( - M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LeafNode" |); M.get_name (| globals, "ExtensionNode" |); M.get_name (| globals, "BranchNode" |) ] |) + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "LeafNode" |); M.get_name (| globals, "ExtensionNode" |); M.get_name (| globals, "BranchNode" |) ] + |) )). Definition encode_internal_node : Value.t -> Value.t -> M := @@ -284,7 +258,7 @@ Definition encode_internal_node : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "(* At expr: unsupported node type: JoinedStr *)" @@ -430,7 +404,7 @@ Definition encode_node : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "(* At expr: unsupported node type: JoinedStr *)" @@ -521,13 +495,16 @@ Definition trie_set : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "key" |), M.get_field (| M.get_name (| globals, "trie" |), "_data" |) |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + M.get_name (| globals, "key" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -537,7 +514,10 @@ Definition trie_set : Value.t -> Value.t -> M := (* else *) )), ltac:(M.monadic ( let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), + M.get_subscript (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + M.get_name (| globals, "key" |) + |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_ @@ -582,51 +562,66 @@ Definition common_prefix_length : Value.t -> Value.t -> M := let _ := Constant.str " Find the longest common prefix of two sequences. " in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "a" |) - ], - make_dict [] - |) - ], - make_dict [] - |) do - let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| - M.get_name (| globals, "i" |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "b" |) - ], - make_dict [] - |) - |), - ltac:(M.monadic ( - Compare.not_eq (| - M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), - M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) - |) - )) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + ], + make_dict [] + |), ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "i" |) - |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_subscript (| + M.get_name (| globals, "a" |), + M.get_name (| globals, "i" |) + |), + M.get_subscript (| + M.get_name (| globals, "b" |), + M.get_name (| globals, "i" |) + |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "len" |), @@ -711,38 +706,53 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 0; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |); - Constant.int 2 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ BinOp.add (| BinOp.mult (| Constant.int 16, - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "i" |) + |) |), - M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) + |) |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -760,43 +770,61 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := Constant.int 1 |) |), - M.get_subscript (| M.get_name (| globals, "x" |), Constant.int 0 |) + M.get_subscript (| + M.get_name (| globals, "x" |), + Constant.int 0 + |) |) ], make_dict [] |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 1; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |); - Constant.int 2 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 1; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ BinOp.add (| BinOp.mult (| Constant.int 16, - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "i" |) + |) |), - M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) + |) |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -843,40 +871,55 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := ], make_dict [] |) in - For make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ] in M.call (| - M.get_name (| globals, "enumerate" |), - make_list [ - M.get_name (| globals, "bytes_" |) - ], - make_dict [] - |) do - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.mult (| - M.get_name (| globals, "byte_index" |), - Constant.int 2 - |) |), - BinOp.r_shift (| - BinOp.bit_and (| - M.get_name (| globals, "byte" |), - Constant.int 240 - |), - Constant.int 4 - |) - |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "byte_index" |), - Constant.int 2 - |), - Constant.int 1 - |) |), - BinOp.bit_and (| - M.get_name (| globals, "byte" |), - Constant.int 15 - |) - |) in - EndFor. + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ], + M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "bytes_" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "nibble_list" |), + BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |) + |), + BinOp.r_shift (| + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 240 + |), + Constant.int 4 + |) + |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "nibble_list" |), + BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |), + Constant.int 1 + |) + |), + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 15 + |) + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Bytes" |), @@ -909,65 +952,69 @@ Definition _prepare_trie : Value.t -> Value.t -> M := Object with keys mapped to nibble-byte form. " in (* At stmt: unsupported node type: AnnAssign *) - For make_tuple [ M.get_name (| globals, "preimage" |); M.get_name (| globals, "value" |) ] in M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "items" |), - make_list [], - make_dict [] - |) do - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "value" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "preimage" |); M.get_name (| globals, "value" |) ], + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "items" |), + make_list [], + make_dict [] + |), ltac:(M.monadic ( - let _ := M.assert (| Compare.is_not (| + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in - let address := - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in - let encoded_value := - M.call (| - M.get_name (| globals, "encode_node" |), - make_list [ - M.get_name (| globals, "value" |); + let address := M.call (| - M.get_name (| globals, "get_storage_root" |), + M.get_name (| globals, "Address" |), make_list [ - M.get_name (| globals, "address" |) + M.get_name (| globals, "preimage" |) ], make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let encoded_value := - M.call (| - M.get_name (| globals, "encode_node" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - )) |) in - let _ := M.call (| + |) in + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |); + M.call (| + M.get_name (| globals, "get_storage_root" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_eq (| @@ -979,38 +1026,46 @@ Definition _prepare_trie : Value.t -> Value.t -> M := make_dict [] |) in (* At stmt: unsupported node type: AnnAssign *) - let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "trie" |), "secured" |), - (* then *) - ltac:(M.monadic ( - let key := - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "trie" |), "secured" |), + (* then *) + ltac:(M.monadic ( + let key := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let key := + M.get_name (| globals, "preimage" |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "mapped" |), + M.call (| + M.get_name (| globals, "bytes_to_nibble_list" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |) + |), + M.get_name (| globals, "encoded_value" |) + |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let key := - M.get_name (| globals, "preimage" |) in + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "mapped" |), M.call (| - M.get_name (| globals, "bytes_to_nibble_list" |), - make_list [ - M.get_name (| globals, "key" |) - ], - make_dict [] - |) |), - M.get_name (| globals, "encoded_value" |) - |) in - EndFor. + )) + |) in let _ := M.return_ (| M.get_name (| globals, "mapped" |) |) in @@ -1203,8 +1258,16 @@ Definition patricialize : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "LeafNode" |), make_list [ - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |); - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) + M.slice (| + M.get_name (| globals, "arbitrary_key" |), + M.get_name (| globals, "level" |), + Constant.None_, + Constant.None_ + |); + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "arbitrary_key" |) + |) ], make_dict [] |) in @@ -1217,7 +1280,12 @@ Definition patricialize : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in let substring := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "arbitrary_key" |), + M.get_name (| globals, "level" |), + Constant.None_, + Constant.None_ + |) in let prefix_length := M.call (| M.get_name (| globals, "len" |), @@ -1226,39 +1294,53 @@ Definition patricialize : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do - let prefix_length := - M.call (| - M.get_name (| globals, "min" |), - make_list [ - M.get_name (| globals, "prefix_length" |); + let _ := + M.for_ (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "obj" |), + ltac:(M.monadic ( + let prefix_length := M.call (| - M.get_name (| globals, "common_prefix_length" |), + M.get_name (| globals, "min" |), make_list [ - M.get_name (| globals, "substring" |); - M.get_subscript (| M.get_name (| globals, "key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) + M.get_name (| globals, "prefix_length" |); + M.call (| + M.get_name (| globals, "common_prefix_length" |), + make_list [ + M.get_name (| globals, "substring" |); + M.slice (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "level" |), + Constant.None_, + Constant.None_ + |) + ], + make_dict [] + |) ], make_dict [] - |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "prefix_length" |), - Constant.int 0 - |), - (* then *) - ltac:(M.monadic ( - let _ := M.break (| |) in + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "prefix_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := (* if *) M.if_then_else (| @@ -1269,10 +1351,15 @@ Definition patricialize : Value.t -> Value.t -> M := (* then *) ltac:(M.monadic ( let prefix := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), BinOp.add (| + M.slice (| + M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |), - M.get_name (| globals, "prefix_length" |) - |) |) |) in + BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |), + Constant.None_ + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ExtensionNode" |), @@ -1305,70 +1392,106 @@ Definition patricialize : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) - For M.get_name (| globals, "_" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 16 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "_" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 16 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "branches" |), "append" |), make_list [ {} ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let value := Constant.bytes "" in - For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "key" |) - ], - make_dict [] - |), - M.get_name (| globals, "level" |) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "obj" |), ltac:(M.monadic ( let _ := (* if *) M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); - make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] - ], - make_dict [] + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |), + M.get_name (| globals, "level" |) |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "AssertionError" |)) |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "key" |) + |); + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "AssertionError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "key" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| + M.get_subscript (| + M.get_name (| globals, "branches" |), + M.get_subscript (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "level" |) + |) + |), + M.get_name (| globals, "key" |) + |), + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "key" |) + |) + |) in M.pure Constant.None_ )) |) in - let value := - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.assign (| - M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) - |) in + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "BranchNode" |), diff --git a/CoqOfPython/ethereum/frontier/utils/__init__.v b/CoqOfPython/ethereum/frontier/utils/__init__.v index 1baedea..0506f75 100644 --- a/CoqOfPython/ethereum/frontier/utils/__init__.v +++ b/CoqOfPython/ethereum/frontier/utils/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.frontier.utils.__init__". Definition expr_1 : Value.t := Constant.str " diff --git a/CoqOfPython/ethereum/frontier/utils/address.v b/CoqOfPython/ethereum/frontier/utils/address.v index 6d1f67a..fe329d1 100644 --- a/CoqOfPython/ethereum/frontier/utils/address.v +++ b/CoqOfPython/ethereum/frontier/utils/address.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.frontier.utils.address". Definition expr_1 : Value.t := Constant.str " @@ -17,31 +17,23 @@ Introduction Address specific functions used in this frontier version of specification. ". -Require typing. -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". +Axiom typing_imports : + AreImported globals "typing" [ "Union" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_left_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. -Require ethereum.frontier.fork_types. -Axiom ethereum_frontier_fork_types_Address : - IsGlobalAlias globals ethereum.frontier.fork_types.globals "Address". +Axiom ethereum_frontier_fork_types_imports : + AreImported globals "ethereum.frontier.fork_types" [ "Address" ]. Definition to_address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -63,11 +55,16 @@ Definition to_address : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "Address" |), make_list [ - M.get_subscript (| M.call (| - M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), - make_list [], - make_dict [] - |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) + M.slice (| + M.call (| + M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), + UnOp.sub (| Constant.int 20 |), + Constant.None_, + Constant.None_ + |) ], make_dict [] |) @@ -111,7 +108,12 @@ Definition compute_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "computed_address" |), + UnOp.sub (| Constant.int 20 |), + Constant.None_, + Constant.None_ + |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/frontier/utils/hexadecimal.v b/CoqOfPython/ethereum/frontier/utils/hexadecimal.v index c2f05ff..799670c 100644 --- a/CoqOfPython/ethereum/frontier/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/frontier/utils/hexadecimal.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.frontier.utils.hexadecimal". Definition expr_1 : Value.t := Constant.str " @@ -18,17 +18,11 @@ Hexadecimal utility functions used in this specification, specific to Frontier types. ". -Require ethereum.utils.hexadecimal. -Axiom ethereum_utils_hexadecimal_remove_hex_prefix : - IsGlobalAlias globals ethereum.utils.hexadecimal.globals "remove_hex_prefix". - -Require ethereum.frontier.fork_types. -Axiom ethereum_frontier_fork_types_Address : - IsGlobalAlias globals ethereum.frontier.fork_types.globals "Address". -Axiom ethereum_frontier_fork_types_Bloom : - IsGlobalAlias globals ethereum.frontier.fork_types.globals "Bloom". -Axiom ethereum_frontier_fork_types_Root : - IsGlobalAlias globals ethereum.frontier.fork_types.globals "Root". +Axiom ethereum_utils_hexadecimal_imports : + AreImported globals "ethereum.utils.hexadecimal" [ "remove_hex_prefix" ]. + +Axiom ethereum_frontier_fork_types_imports : + AreImported globals "ethereum.frontier.fork_types" [ "Address"; "Bloom"; "Root" ]. Definition hex_to_root : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/frontier/utils/message.v b/CoqOfPython/ethereum/frontier/utils/message.v index 86d0cf9..ca8fa8c 100644 --- a/CoqOfPython/ethereum/frontier/utils/message.v +++ b/CoqOfPython/ethereum/frontier/utils/message.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.frontier.utils.message". Definition expr_1 : Value.t := Constant.str " @@ -17,39 +17,23 @@ Introduction Message specific functions used in this frontier version of specification. ". -Require typing. -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". +Axiom typing_imports : + AreImported globals "typing" [ "Optional"; "Union" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint" ]. -Require ethereum.frontier.fork_types. -Axiom ethereum_frontier_fork_types_Address : - IsGlobalAlias globals ethereum.frontier.fork_types.globals "Address". +Axiom ethereum_frontier_fork_types_imports : + AreImported globals "ethereum.frontier.fork_types" [ "Address" ]. -Require ethereum.frontier.state. -Axiom ethereum_frontier_state_get_account : - IsGlobalAlias globals ethereum.frontier.state.globals "get_account". +Axiom ethereum_frontier_state_imports : + AreImported globals "ethereum.frontier.state" [ "get_account" ]. -Require ethereum.frontier.vm.__init__. -Axiom ethereum_frontier_vm___init___Environment : - IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "Environment". -Axiom ethereum_frontier_vm___init___Message : - IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "Message". +Axiom ethereum_frontier_vm_imports : + AreImported globals "ethereum.frontier.vm" [ "Environment"; "Message" ]. -Require ethereum.frontier.utils.address. -Axiom ethereum_frontier_utils_address_compute_contract_address : - IsGlobalAlias globals ethereum.frontier.utils.address.globals "compute_contract_address". +Axiom ethereum_frontier_utils_address_imports : + AreImported globals "ethereum.frontier.utils.address" [ "compute_contract_address" ]. Definition prepare_message : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -177,7 +161,7 @@ Definition prepare_message : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "Target must be address or empty bytes" diff --git a/CoqOfPython/ethereum/frontier/vm/__init__.v b/CoqOfPython/ethereum/frontier/vm/__init__.v index 1680b9c..85ab9d3 100644 --- a/CoqOfPython/ethereum/frontier/vm/__init__.v +++ b/CoqOfPython/ethereum/frontier/vm/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.frontier.vm.__init__". Definition expr_1 : Value.t := Constant.str " @@ -18,47 +18,26 @@ The abstract computer which runs the code stored in an `.fork_types.Account`. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". - -Require ethereum.frontier.blocks. -Axiom ethereum_frontier_blocks_Log : - IsGlobalAlias globals ethereum.frontier.blocks.globals "Log". - -Require ethereum.frontier.fork_types. -Axiom ethereum_frontier_fork_types_Address : - IsGlobalAlias globals ethereum.frontier.fork_types.globals "Address". - -Require ethereum.frontier.state. -Axiom ethereum_frontier_state_State : - IsGlobalAlias globals ethereum.frontier.state.globals "State". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple"; "Union" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. + +Axiom ethereum_frontier_blocks_imports : + AreImported globals "ethereum.frontier.blocks" [ "Log" ]. + +Axiom ethereum_frontier_fork_types_imports : + AreImported globals "ethereum.frontier.fork_types" [ "Address" ]. + +Axiom ethereum_frontier_state_imports : + AreImported globals "ethereum.frontier.state" [ "State" ]. Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] diff --git a/CoqOfPython/ethereum/frontier/vm/exceptions.v b/CoqOfPython/ethereum/frontier/vm/exceptions.v index 45435b3..7718d59 100644 --- a/CoqOfPython/ethereum/frontier/vm/exceptions.v +++ b/CoqOfPython/ethereum/frontier/vm/exceptions.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.frontier.vm.exceptions". Definition expr_1 : Value.t := Constant.str " @@ -17,9 +17,8 @@ Introduction Exceptions which cause the EVM to halt exceptionally. ". -Require ethereum.exceptions. -Axiom ethereum_exceptions_EthereumException : - IsGlobalAlias globals ethereum.exceptions.globals "EthereumException". +Axiom ethereum_exceptions_imports : + AreImported globals "ethereum.exceptions" [ "EthereumException" ]. Definition ExceptionalHalt : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/frontier/vm/gas.v b/CoqOfPython/ethereum/frontier/vm/gas.v index 63b538c..b13832d 100644 --- a/CoqOfPython/ethereum/frontier/vm/gas.v +++ b/CoqOfPython/ethereum/frontier/vm/gas.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.frontier.vm.gas". Definition expr_1 : Value.t := Constant.str " @@ -17,49 +17,32 @@ Introduction EVM gas constants and calculators. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.trace. -Axiom ethereum_trace_GasAndRefund : - IsGlobalAlias globals ethereum.trace.globals "GasAndRefund". -Axiom ethereum_trace_evm_trace : - IsGlobalAlias globals ethereum.trace.globals "evm_trace". - -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". - -Require ethereum.frontier.fork_types. -Axiom ethereum_frontier_fork_types_Address : - IsGlobalAlias globals ethereum.frontier.fork_types.globals "Address". - -Require ethereum.frontier.state. -Axiom ethereum_frontier_state_State : - IsGlobalAlias globals ethereum.frontier.state.globals "State". -Axiom ethereum_frontier_state_account_exists : - IsGlobalAlias globals ethereum.frontier.state.globals "account_exists". - -Require ethereum.frontier.vm.__init__. -Axiom ethereum_frontier_vm___init___Evm : - IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "Evm". - -Require ethereum.frontier.vm.exceptions. -Axiom ethereum_frontier_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.frontier.vm.exceptions.globals "OutOfGasError". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. + +Axiom ethereum_trace_imports : + AreImported globals "ethereum.trace" [ "GasAndRefund"; "evm_trace" ]. + +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. + +Axiom ethereum_frontier_fork_types_imports : + AreImported globals "ethereum.frontier.fork_types" [ "Address" ]. + +Axiom ethereum_frontier_state_imports : + AreImported globals "ethereum.frontier.state" [ "State"; "account_exists" ]. + +Axiom ethereum_frontier_vm_imports : + AreImported globals "ethereum.frontier.vm" [ "Evm" ]. + +Axiom ethereum_frontier_vm_exceptions_imports : + AreImported globals "ethereum.frontier.vm.exceptions" [ "OutOfGasError" ]. Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -488,7 +471,7 @@ Definition charge_gas : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -605,105 +588,114 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := ], make_dict [] |) in - For make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ] in M.get_name (| globals, "extensions" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "size" |), - Constant.int 0 - |), - (* then *) + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ], + M.get_name (| globals, "extensions" |), ltac:(M.monadic ( - let _ := M.continue (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let before_size := - M.call (| - M.get_name (| globals, "ceil32" |), - make_list [ - M.get_name (| globals, "current_size" |) - ], - make_dict [] - |) in - let after_size := - M.call (| - M.get_name (| globals, "ceil32" |), - make_list [ - BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "size" |), + Constant.int 0 |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.lt_e (| - M.get_name (| globals, "after_size" |), - M.get_name (| globals, "before_size" |) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.continue (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let size_to_extend := BinOp.add - BinOp.sub (| + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let before_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "current_size" |) + ], + make_dict [] + |) in + let after_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let size_to_extend := BinOp.add + BinOp.sub (| M.get_name (| globals, "after_size" |), M.get_name (| globals, "before_size" |) |) - BinOp.sub (| + BinOp.sub (| M.get_name (| globals, "after_size" |), M.get_name (| globals, "before_size" |) |) in - let already_paid := - M.call (| - M.get_name (| globals, "calculate_memory_gas_cost" |), - make_list [ - M.get_name (| globals, "before_size" |) - ], - make_dict [] - |) in - let total_cost := - M.call (| - M.get_name (| globals, "calculate_memory_gas_cost" |), - make_list [ - M.get_name (| globals, "after_size" |) - ], - make_dict [] - |) in - let to_be_paid := BinOp.add - BinOp.sub (| + let already_paid := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "before_size" |) + ], + make_dict [] + |) in + let total_cost := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "after_size" |) + ], + make_dict [] + |) in + let to_be_paid := BinOp.add + BinOp.sub (| M.get_name (| globals, "total_cost" |), M.get_name (| globals, "already_paid" |) |) - BinOp.sub (| + BinOp.sub (| M.get_name (| globals, "total_cost" |), M.get_name (| globals, "already_paid" |) |) in - let current_size := - M.get_name (| globals, "after_size" |) in - EndFor. + let current_size := + M.get_name (| globals, "after_size" |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ExtendMemory" |), diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/__init__.v b/CoqOfPython/ethereum/frontier/vm/instructions/__init__.v index 46647fa..990234a 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/__init__.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.frontier.vm.instructions.__init__". Definition expr_1 : Value.t := Constant.str " @@ -20,59 +20,44 @@ implementations. (* At top_level_stmt: unsupported node type: Import *) -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict" ]. -Require ethereum.frontier.vm.instructions.__init__. -Axiom ethereum_frontier_vm_instructions___init___arithmetic : - IsGlobalAlias globals ethereum.frontier.vm.instructions.__init__.globals "arithmetic". +Axiom ethereum_frontier_vm_instructions_imports : + AreImported globals "ethereum.frontier.vm.instructions" [ "arithmetic" ]. -Require ethereum.frontier.vm.instructions.__init__. -Axiom ethereum_frontier_vm_instructions___init___bitwise : - IsGlobalAlias globals ethereum.frontier.vm.instructions.__init__.globals "bitwise". +Axiom ethereum_frontier_vm_instructions_imports : + AreImported globals "ethereum.frontier.vm.instructions" [ "bitwise" ]. -Require ethereum.frontier.vm.instructions.__init__. -Axiom ethereum_frontier_vm_instructions___init___block : - IsGlobalAlias globals ethereum.frontier.vm.instructions.__init__.globals "block". +Axiom ethereum_frontier_vm_instructions_imports : + AreImported globals "ethereum.frontier.vm.instructions" [ "block" ]. -Require ethereum.frontier.vm.instructions.__init__. -Axiom ethereum_frontier_vm_instructions___init___comparison : - IsGlobalAlias globals ethereum.frontier.vm.instructions.__init__.globals "comparison". +Axiom ethereum_frontier_vm_instructions_imports : + AreImported globals "ethereum.frontier.vm.instructions" [ "comparison" ]. -Require ethereum.frontier.vm.instructions.__init__. -Axiom ethereum_frontier_vm_instructions___init___control_flow : - IsGlobalAlias globals ethereum.frontier.vm.instructions.__init__.globals "control_flow". +Axiom ethereum_frontier_vm_instructions_imports : + AreImported globals "ethereum.frontier.vm.instructions" [ "control_flow" ]. -Require ethereum.frontier.vm.instructions.__init__. -Axiom ethereum_frontier_vm_instructions___init___environment : - IsGlobalAlias globals ethereum.frontier.vm.instructions.__init__.globals "environment". +Axiom ethereum_frontier_vm_instructions_imports : + AreImported globals "ethereum.frontier.vm.instructions" [ "environment" ]. -Require ethereum.frontier.vm.instructions.__init__. -Axiom ethereum_frontier_vm_instructions___init___keccak : - IsGlobalAlias globals ethereum.frontier.vm.instructions.__init__.globals "keccak". +Axiom ethereum_frontier_vm_instructions_imports : + AreImported globals "ethereum.frontier.vm.instructions" [ "keccak" ]. -Require ethereum.frontier.vm.instructions.__init__. -Axiom ethereum_frontier_vm_instructions___init___log : - IsGlobalAlias globals ethereum.frontier.vm.instructions.__init__.globals "log". +Axiom ethereum_frontier_vm_instructions_imports : + AreImported globals "ethereum.frontier.vm.instructions" [ "log" ]. -Require ethereum.frontier.vm.instructions.__init__. -Axiom ethereum_frontier_vm_instructions___init___memory : - IsGlobalAlias globals ethereum.frontier.vm.instructions.__init__.globals "memory". +Axiom ethereum_frontier_vm_instructions_imports : + AreImported globals "ethereum.frontier.vm.instructions" [ "memory" ]. -Require ethereum.frontier.vm.instructions.__init__. -Axiom ethereum_frontier_vm_instructions___init___stack : - IsGlobalAlias globals ethereum.frontier.vm.instructions.__init__.globals "stack". +Axiom ethereum_frontier_vm_instructions_imports : + AreImported globals "ethereum.frontier.vm.instructions" [ "stack" ]. -Require ethereum.frontier.vm.instructions.__init__. -Axiom ethereum_frontier_vm_instructions___init___storage : - IsGlobalAlias globals ethereum.frontier.vm.instructions.__init__.globals "storage". +Axiom ethereum_frontier_vm_instructions_imports : + AreImported globals "ethereum.frontier.vm.instructions" [ "storage" ]. -Require ethereum.frontier.vm.instructions.__init__. -Axiom ethereum_frontier_vm_instructions___init___system : - IsGlobalAlias globals ethereum.frontier.vm.instructions.__init__.globals "system". +Axiom ethereum_frontier_vm_instructions_imports : + AreImported globals "ethereum.frontier.vm.instructions" [ "system" ]. Definition Ops : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/frontier/vm/instructions/arithmetic.v index ad992d8..119678d 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/arithmetic.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.frontier.vm.instructions.arithmetic". Definition expr_1 : Value.t := Constant.str " @@ -17,43 +17,20 @@ Introduction Implementations of the EVM Arithmetic instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U255_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U255_CEIL_VALUE". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_U256_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U255_CEIL_VALUE"; "U256"; "U256_CEIL_VALUE"; "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_get_sign : - IsGlobalAlias globals ethereum.utils.numeric.globals "get_sign". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "get_sign" ]. -Require ethereum.frontier.vm.__init__. -Axiom ethereum_frontier_vm___init___Evm : - IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "Evm". +Axiom ethereum_frontier_vm_imports : + AreImported globals "ethereum.frontier.vm" [ "Evm" ]. -Require ethereum.frontier.vm.gas. -Axiom ethereum_frontier_vm_gas_GAS_EXPONENTIATION : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_EXPONENTIATION". -Axiom ethereum_frontier_vm_gas_GAS_EXPONENTIATION_PER_BYTE : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_EXPONENTIATION_PER_BYTE". -Axiom ethereum_frontier_vm_gas_GAS_LOW : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_LOW". -Axiom ethereum_frontier_vm_gas_GAS_MID : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_MID". -Axiom ethereum_frontier_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_frontier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "charge_gas". +Axiom ethereum_frontier_vm_gas_imports : + AreImported globals "ethereum.frontier.vm.gas" [ "GAS_EXPONENTIATION"; "GAS_EXPONENTIATION_PER_BYTE"; "GAS_LOW"; "GAS_MID"; "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.frontier.vm.stack. -Axiom ethereum_frontier_vm_stack_pop : - IsGlobalAlias globals ethereum.frontier.vm.stack.globals "pop". -Axiom ethereum_frontier_vm_stack_push : - IsGlobalAlias globals ethereum.frontier.vm.stack.globals "push". +Axiom ethereum_frontier_vm_stack_imports : + AreImported globals "ethereum.frontier.vm.stack" [ "pop"; "push" ]. Definition add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -1030,19 +1007,27 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let value_bytes := - M.get_subscript (| M.get_name (| globals, "value_bytes" |), M.slice (| BinOp.sub (| - Constant.int 31, - M.call (| - M.get_name (| globals, "int" |), - make_list [ - M.get_name (| globals, "byte_num" |) - ], - make_dict [] - |) - |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "value_bytes" |), + BinOp.sub (| + Constant.int 31, + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "byte_num" |) + ], + make_dict [] + |) + |), + Constant.None_, + Constant.None_ + |) in let sign_bit := BinOp.r_shift (| - M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), + M.get_subscript (| + M.get_name (| globals, "value_bytes" |), + Constant.int 0 + |), Constant.int 7 |) in let _ := diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/bitwise.v b/CoqOfPython/ethereum/frontier/vm/instructions/bitwise.v index a640fd7..299e447 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/bitwise.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.frontier.vm.instructions.bitwise". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementations of the EVM bitwise instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.frontier.vm.__init__. -Axiom ethereum_frontier_vm___init___Evm : - IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "Evm". +Axiom ethereum_frontier_vm_imports : + AreImported globals "ethereum.frontier.vm" [ "Evm" ]. -Require ethereum.frontier.vm.gas. -Axiom ethereum_frontier_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_frontier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "charge_gas". +Axiom ethereum_frontier_vm_gas_imports : + AreImported globals "ethereum.frontier.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.frontier.vm.stack. -Axiom ethereum_frontier_vm_stack_pop : - IsGlobalAlias globals ethereum.frontier.vm.stack.globals "pop". -Axiom ethereum_frontier_vm_stack_push : - IsGlobalAlias globals ethereum.frontier.vm.stack.globals "push". +Axiom ethereum_frontier_vm_stack_imports : + AreImported globals "ethereum.frontier.vm.stack" [ "pop"; "push" ]. Definition bitwise_and : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/block.v b/CoqOfPython/ethereum/frontier/vm/instructions/block.v index 64df956..54166fb 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/block.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/block.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.frontier.vm.instructions.block". Definition expr_1 : Value.t := Constant.str " @@ -17,27 +17,17 @@ Introduction Implementations of the EVM block instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.frontier.vm.__init__. -Axiom ethereum_frontier_vm___init___Evm : - IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "Evm". +Axiom ethereum_frontier_vm_imports : + AreImported globals "ethereum.frontier.vm" [ "Evm" ]. -Require ethereum.frontier.vm.gas. -Axiom ethereum_frontier_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_BASE". -Axiom ethereum_frontier_vm_gas_GAS_BLOCK_HASH : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_BLOCK_HASH". -Axiom ethereum_frontier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "charge_gas". +Axiom ethereum_frontier_vm_gas_imports : + AreImported globals "ethereum.frontier.vm.gas" [ "GAS_BASE"; "GAS_BLOCK_HASH"; "charge_gas" ]. -Require ethereum.frontier.vm.stack. -Axiom ethereum_frontier_vm_stack_pop : - IsGlobalAlias globals ethereum.frontier.vm.stack.globals "pop". -Axiom ethereum_frontier_vm_stack_push : - IsGlobalAlias globals ethereum.frontier.vm.stack.globals "push". +Axiom ethereum_frontier_vm_stack_imports : + AreImported globals "ethereum.frontier.vm.stack" [ "pop"; "push" ]. Definition block_hash : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -94,10 +84,13 @@ Definition block_hash : Value.t -> Value.t -> M := (* else *) )), ltac:(M.monadic ( let hash := - M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), - M.get_name (| globals, "block_number" |) - |) |) |) in + M.get_subscript (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), + UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + M.get_name (| globals, "block_number" |) + |) |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/comparison.v b/CoqOfPython/ethereum/frontier/vm/instructions/comparison.v index f809174..132c084 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/comparison.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.frontier.vm.instructions.comparison". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementations of the EVM Comparison instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.frontier.vm.__init__. -Axiom ethereum_frontier_vm___init___Evm : - IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "Evm". +Axiom ethereum_frontier_vm_imports : + AreImported globals "ethereum.frontier.vm" [ "Evm" ]. -Require ethereum.frontier.vm.gas. -Axiom ethereum_frontier_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_frontier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "charge_gas". +Axiom ethereum_frontier_vm_gas_imports : + AreImported globals "ethereum.frontier.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.frontier.vm.stack. -Axiom ethereum_frontier_vm_stack_pop : - IsGlobalAlias globals ethereum.frontier.vm.stack.globals "pop". -Axiom ethereum_frontier_vm_stack_push : - IsGlobalAlias globals ethereum.frontier.vm.stack.globals "push". +Axiom ethereum_frontier_vm_stack_imports : + AreImported globals "ethereum.frontier.vm.stack" [ "pop"; "push" ]. Definition less_than : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/control_flow.v b/CoqOfPython/ethereum/frontier/vm/instructions/control_flow.v index bc51f99..6c9a489 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/control_flow.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.frontier.vm.instructions.control_flow". Definition expr_1 : Value.t := Constant.str " @@ -17,37 +17,20 @@ Introduction Implementations of the EVM control flow instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. -Require ethereum.frontier.vm.gas. -Axiom ethereum_frontier_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_BASE". -Axiom ethereum_frontier_vm_gas_GAS_HIGH : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_HIGH". -Axiom ethereum_frontier_vm_gas_GAS_JUMPDEST : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_JUMPDEST". -Axiom ethereum_frontier_vm_gas_GAS_MID : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_MID". -Axiom ethereum_frontier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "charge_gas". +Axiom ethereum_frontier_vm_gas_imports : + AreImported globals "ethereum.frontier.vm.gas" [ "GAS_BASE"; "GAS_HIGH"; "GAS_JUMPDEST"; "GAS_MID"; "charge_gas" ]. -Require ethereum.frontier.vm.__init__. -Axiom ethereum_frontier_vm___init___Evm : - IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "Evm". +Axiom ethereum_frontier_vm_imports : + AreImported globals "ethereum.frontier.vm" [ "Evm" ]. -Require ethereum.frontier.vm.exceptions. -Axiom ethereum_frontier_vm_exceptions_InvalidJumpDestError : - IsGlobalAlias globals ethereum.frontier.vm.exceptions.globals "InvalidJumpDestError". +Axiom ethereum_frontier_vm_exceptions_imports : + AreImported globals "ethereum.frontier.vm.exceptions" [ "InvalidJumpDestError" ]. -Require ethereum.frontier.vm.stack. -Axiom ethereum_frontier_vm_stack_pop : - IsGlobalAlias globals ethereum.frontier.vm.stack.globals "pop". -Axiom ethereum_frontier_vm_stack_push : - IsGlobalAlias globals ethereum.frontier.vm.stack.globals "push". +Axiom ethereum_frontier_vm_stack_imports : + AreImported globals "ethereum.frontier.vm.stack" [ "pop"; "push" ]. Definition stop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -117,7 +100,7 @@ Definition jump : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "InvalidJumpDestError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -205,7 +188,7 @@ Definition jumpi : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "InvalidJumpDestError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/environment.v b/CoqOfPython/ethereum/frontier/vm/instructions/environment.v index 02d92cd..502329a 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/environment.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.frontier.vm.instructions.environment". Definition expr_1 : Value.t := Constant.str " @@ -17,55 +17,29 @@ Introduction Implementations of the EVM environment related instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". - -Require ethereum.frontier.state. -Axiom ethereum_frontier_state_get_account : - IsGlobalAlias globals ethereum.frontier.state.globals "get_account". - -Require ethereum.frontier.utils.address. -Axiom ethereum_frontier_utils_address_to_address : - IsGlobalAlias globals ethereum.frontier.utils.address.globals "to_address". - -Require ethereum.frontier.vm.memory. -Axiom ethereum_frontier_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.frontier.vm.memory.globals "buffer_read". -Axiom ethereum_frontier_vm_memory_memory_write : - IsGlobalAlias globals ethereum.frontier.vm.memory.globals "memory_write". - -Require ethereum.frontier.vm.__init__. -Axiom ethereum_frontier_vm___init___Evm : - IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "Evm". - -Require ethereum.frontier.vm.gas. -Axiom ethereum_frontier_vm_gas_GAS_BALANCE : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_BALANCE". -Axiom ethereum_frontier_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_BASE". -Axiom ethereum_frontier_vm_gas_GAS_COPY : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_COPY". -Axiom ethereum_frontier_vm_gas_GAS_EXTERNAL : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_EXTERNAL". -Axiom ethereum_frontier_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_frontier_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_frontier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "charge_gas". - -Require ethereum.frontier.vm.stack. -Axiom ethereum_frontier_vm_stack_pop : - IsGlobalAlias globals ethereum.frontier.vm.stack.globals "pop". -Axiom ethereum_frontier_vm_stack_push : - IsGlobalAlias globals ethereum.frontier.vm.stack.globals "push". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. + +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. + +Axiom ethereum_frontier_state_imports : + AreImported globals "ethereum.frontier.state" [ "get_account" ]. + +Axiom ethereum_frontier_utils_address_imports : + AreImported globals "ethereum.frontier.utils.address" [ "to_address" ]. + +Axiom ethereum_frontier_vm_memory_imports : + AreImported globals "ethereum.frontier.vm.memory" [ "buffer_read"; "memory_write" ]. + +Axiom ethereum_frontier_vm_imports : + AreImported globals "ethereum.frontier.vm" [ "Evm" ]. + +Axiom ethereum_frontier_vm_gas_imports : + AreImported globals "ethereum.frontier.vm.gas" [ "GAS_BALANCE"; "GAS_BASE"; "GAS_COPY"; "GAS_EXTERNAL"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. + +Axiom ethereum_frontier_vm_stack_imports : + AreImported globals "ethereum.frontier.vm.stack" [ "pop"; "push" ]. Definition address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/keccak.v b/CoqOfPython/ethereum/frontier/vm/instructions/keccak.v index 9ed220d..1d8fbbc 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/keccak.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.frontier.vm.instructions.keccak". Definition expr_1 : Value.t := Constant.str " @@ -17,43 +17,26 @@ Introduction Implementations of the EVM keccak instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". - -Require ethereum.frontier.vm.__init__. -Axiom ethereum_frontier_vm___init___Evm : - IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "Evm". - -Require ethereum.frontier.vm.gas. -Axiom ethereum_frontier_vm_gas_GAS_KECCAK256 : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_KECCAK256". -Axiom ethereum_frontier_vm_gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_KECCAK256_WORD". -Axiom ethereum_frontier_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_frontier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "charge_gas". - -Require ethereum.frontier.vm.memory. -Axiom ethereum_frontier_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.frontier.vm.memory.globals "memory_read_bytes". - -Require ethereum.frontier.vm.stack. -Axiom ethereum_frontier_vm_stack_pop : - IsGlobalAlias globals ethereum.frontier.vm.stack.globals "pop". -Axiom ethereum_frontier_vm_stack_push : - IsGlobalAlias globals ethereum.frontier.vm.stack.globals "push". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. + +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. + +Axiom ethereum_frontier_vm_imports : + AreImported globals "ethereum.frontier.vm" [ "Evm" ]. + +Axiom ethereum_frontier_vm_gas_imports : + AreImported globals "ethereum.frontier.vm.gas" [ "GAS_KECCAK256"; "GAS_KECCAK256_WORD"; "calculate_gas_extend_memory"; "charge_gas" ]. + +Axiom ethereum_frontier_vm_memory_imports : + AreImported globals "ethereum.frontier.vm.memory" [ "memory_read_bytes" ]. + +Axiom ethereum_frontier_vm_stack_imports : + AreImported globals "ethereum.frontier.vm.stack" [ "pop"; "push" ]. Definition keccak : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/log.v b/CoqOfPython/ethereum/frontier/vm/instructions/log.v index 51783fc..4cf0761 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/log.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/log.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.frontier.vm.instructions.log". Definition expr_1 : Value.t := Constant.str " @@ -17,41 +17,26 @@ Introduction Implementations of the EVM logging instructions. ". -Require functools. -Axiom functools_partial : - IsGlobalAlias globals functools.globals "partial". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". - -Require ethereum.frontier.blocks. -Axiom ethereum_frontier_blocks_Log : - IsGlobalAlias globals ethereum.frontier.blocks.globals "Log". - -Require ethereum.frontier.vm.__init__. -Axiom ethereum_frontier_vm___init___Evm : - IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "Evm". - -Require ethereum.frontier.vm.gas. -Axiom ethereum_frontier_vm_gas_GAS_LOG : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_LOG". -Axiom ethereum_frontier_vm_gas_GAS_LOG_DATA : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_LOG_DATA". -Axiom ethereum_frontier_vm_gas_GAS_LOG_TOPIC : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_LOG_TOPIC". -Axiom ethereum_frontier_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_frontier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "charge_gas". - -Require ethereum.frontier.vm.memory. -Axiom ethereum_frontier_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.frontier.vm.memory.globals "memory_read_bytes". - -Require ethereum.frontier.vm.stack. -Axiom ethereum_frontier_vm_stack_pop : - IsGlobalAlias globals ethereum.frontier.vm.stack.globals "pop". +Axiom functools_imports : + AreImported globals "functools" [ "partial" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. + +Axiom ethereum_frontier_blocks_imports : + AreImported globals "ethereum.frontier.blocks" [ "Log" ]. + +Axiom ethereum_frontier_vm_imports : + AreImported globals "ethereum.frontier.vm" [ "Evm" ]. + +Axiom ethereum_frontier_vm_gas_imports : + AreImported globals "ethereum.frontier.vm.gas" [ "GAS_LOG"; "GAS_LOG_DATA"; "GAS_LOG_TOPIC"; "calculate_gas_extend_memory"; "charge_gas" ]. + +Axiom ethereum_frontier_vm_memory_imports : + AreImported globals "ethereum.frontier.vm.memory" [ "memory_read_bytes" ]. + +Axiom ethereum_frontier_vm_stack_imports : + AreImported globals "ethereum.frontier.vm.stack" [ "pop" ]. Definition log_n : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -88,33 +73,42 @@ Definition log_n : Value.t -> Value.t -> M := |) in let topics := make_list [] in - For M.get_name (| globals, "_" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - M.get_name (| globals, "num_topics" |) - ], - make_dict [] - |) do - let topic := + let _ := + M.for_ (| + M.get_name (| globals, "_" |), M.call (| - M.get_field (| M.call (| - M.get_name (| globals, "pop" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] - |), "to_be_bytes32" |), - make_list [], - make_dict [] - |) in - let _ := M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "num_topics" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let topic := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| M.get_field (| M.get_name (| globals, "topics" |), "append" |), make_list [ M.get_name (| globals, "topic" |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let extend_memory := M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/memory.v b/CoqOfPython/ethereum/frontier/vm/instructions/memory.v index 3cb3f30..2646957 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/memory.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.frontier.vm.instructions.memory". Definition expr_1 : Value.t := Constant.str " @@ -17,37 +17,20 @@ Introduction Implementations of the EVM Memory instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes" ]. -Require ethereum.frontier.vm.__init__. -Axiom ethereum_frontier_vm___init___Evm : - IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "Evm". +Axiom ethereum_frontier_vm_imports : + AreImported globals "ethereum.frontier.vm" [ "Evm" ]. -Require ethereum.frontier.vm.gas. -Axiom ethereum_frontier_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_BASE". -Axiom ethereum_frontier_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_frontier_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_frontier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "charge_gas". +Axiom ethereum_frontier_vm_gas_imports : + AreImported globals "ethereum.frontier.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. -Require ethereum.frontier.vm.memory. -Axiom ethereum_frontier_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.frontier.vm.memory.globals "memory_read_bytes". -Axiom ethereum_frontier_vm_memory_memory_write : - IsGlobalAlias globals ethereum.frontier.vm.memory.globals "memory_write". +Axiom ethereum_frontier_vm_memory_imports : + AreImported globals "ethereum.frontier.vm.memory" [ "memory_read_bytes"; "memory_write" ]. -Require ethereum.frontier.vm.stack. -Axiom ethereum_frontier_vm_stack_pop : - IsGlobalAlias globals ethereum.frontier.vm.stack.globals "pop". -Axiom ethereum_frontier_vm_stack_push : - IsGlobalAlias globals ethereum.frontier.vm.stack.globals "push". +Axiom ethereum_frontier_vm_stack_imports : + AreImported globals "ethereum.frontier.vm.stack" [ "pop"; "push" ]. Definition mstore : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/stack.v b/CoqOfPython/ethereum/frontier/vm/instructions/stack.v index 8fb1c4c..44c9eb7 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/stack.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.frontier.vm.instructions.stack". Definition expr_1 : Value.t := Constant.str " @@ -17,39 +17,26 @@ Introduction Implementations of the EVM stack related instructions. ". -Require functools. -Axiom functools_partial : - IsGlobalAlias globals functools.globals "partial". +Axiom functools_imports : + AreImported globals "functools" [ "partial" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.frontier.vm.__init__. -Axiom ethereum_frontier_vm___init___Evm : - IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "Evm". -Axiom ethereum_frontier_vm___init___stack : - IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "stack". +Axiom ethereum_frontier_vm_imports : + AreImported globals "ethereum.frontier.vm" [ "Evm"; "stack" ]. -Require ethereum.frontier.vm.exceptions. -Axiom ethereum_frontier_vm_exceptions_StackUnderflowError : - IsGlobalAlias globals ethereum.frontier.vm.exceptions.globals "StackUnderflowError". +Axiom ethereum_frontier_vm_exceptions_imports : + AreImported globals "ethereum.frontier.vm.exceptions" [ "StackUnderflowError" ]. -Require ethereum.frontier.vm.gas. -Axiom ethereum_frontier_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_BASE". -Axiom ethereum_frontier_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_frontier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "charge_gas". +Axiom ethereum_frontier_vm_gas_imports : + AreImported globals "ethereum.frontier.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.frontier.vm.memory. -Axiom ethereum_frontier_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.frontier.vm.memory.globals "buffer_read". +Axiom ethereum_frontier_vm_memory_imports : + AreImported globals "ethereum.frontier.vm.memory" [ "buffer_read" ]. Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -203,19 +190,22 @@ Definition dup_n : Value.t -> Value.t -> M := make_dict [] |) in let data_to_duplicate := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] + BinOp.sub (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), + Constant.int 1 |), - Constant.int 1 - |), - M.get_name (| globals, "item_number" |) - |) |) in + M.get_name (| globals, "item_number" |) + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "stack" |), "push" |), make_list [ @@ -278,14 +268,26 @@ Definition swap_n : Value.t -> Value.t -> M := make_dict [] |) in let _ := M.assign (| - make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| - UnOp.sub (| Constant.int 1 |), - M.get_name (| globals, "item_number" |) - |) |) ], - make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| - UnOp.sub (| Constant.int 1 |), - M.get_name (| globals, "item_number" |) - |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |) ] + make_tuple [ M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + UnOp.sub (| Constant.int 1 |) + |); M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) + |) ], + make_tuple [ M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) + |); M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + UnOp.sub (| Constant.int 1 |) + |) ] |) in let _ := M.assign_op (| BinOp.add, diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/storage.v b/CoqOfPython/ethereum/frontier/vm/instructions/storage.v index 6899add..bf59138 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/storage.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.frontier.vm.instructions.storage". Definition expr_1 : Value.t := Constant.str " @@ -17,33 +17,17 @@ Introduction Implementations of the EVM storage related instructions. ". -Require ethereum.frontier.state. -Axiom ethereum_frontier_state_get_storage : - IsGlobalAlias globals ethereum.frontier.state.globals "get_storage". -Axiom ethereum_frontier_state_set_storage : - IsGlobalAlias globals ethereum.frontier.state.globals "set_storage". +Axiom ethereum_frontier_state_imports : + AreImported globals "ethereum.frontier.state" [ "get_storage"; "set_storage" ]. -Require ethereum.frontier.vm.__init__. -Axiom ethereum_frontier_vm___init___Evm : - IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "Evm". +Axiom ethereum_frontier_vm_imports : + AreImported globals "ethereum.frontier.vm" [ "Evm" ]. -Require ethereum.frontier.vm.gas. -Axiom ethereum_frontier_vm_gas_GAS_SLOAD : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_SLOAD". -Axiom ethereum_frontier_vm_gas_GAS_STORAGE_CLEAR_REFUND : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_STORAGE_CLEAR_REFUND". -Axiom ethereum_frontier_vm_gas_GAS_STORAGE_SET : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_STORAGE_SET". -Axiom ethereum_frontier_vm_gas_GAS_STORAGE_UPDATE : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_STORAGE_UPDATE". -Axiom ethereum_frontier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "charge_gas". +Axiom ethereum_frontier_vm_gas_imports : + AreImported globals "ethereum.frontier.vm.gas" [ "GAS_SLOAD"; "GAS_STORAGE_CLEAR_REFUND"; "GAS_STORAGE_SET"; "GAS_STORAGE_UPDATE"; "charge_gas" ]. -Require ethereum.frontier.vm.stack. -Axiom ethereum_frontier_vm_stack_pop : - IsGlobalAlias globals ethereum.frontier.vm.stack.globals "pop". -Axiom ethereum_frontier_vm_stack_push : - IsGlobalAlias globals ethereum.frontier.vm.stack.globals "push". +Axiom ethereum_frontier_vm_stack_imports : + AreImported globals "ethereum.frontier.vm.stack" [ "pop"; "push" ]. Definition sload : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/system.v b/CoqOfPython/ethereum/frontier/vm/instructions/system.v index 4ef9cd6..c2e171c 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/system.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/system.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.frontier.vm.instructions.system". Definition expr_1 : Value.t := Constant.str " @@ -17,69 +17,29 @@ Introduction Implementations of the EVM system related instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. -Require ethereum.frontier.fork_types. -Axiom ethereum_frontier_fork_types_Address : - IsGlobalAlias globals ethereum.frontier.fork_types.globals "Address". +Axiom ethereum_frontier_fork_types_imports : + AreImported globals "ethereum.frontier.fork_types" [ "Address" ]. -Require ethereum.frontier.state. -Axiom ethereum_frontier_state_account_has_code_or_nonce : - IsGlobalAlias globals ethereum.frontier.state.globals "account_has_code_or_nonce". -Axiom ethereum_frontier_state_get_account : - IsGlobalAlias globals ethereum.frontier.state.globals "get_account". -Axiom ethereum_frontier_state_increment_nonce : - IsGlobalAlias globals ethereum.frontier.state.globals "increment_nonce". -Axiom ethereum_frontier_state_set_account_balance : - IsGlobalAlias globals ethereum.frontier.state.globals "set_account_balance". +Axiom ethereum_frontier_state_imports : + AreImported globals "ethereum.frontier.state" [ "account_has_code_or_nonce"; "get_account"; "increment_nonce"; "set_account_balance" ]. -Require ethereum.frontier.utils.address. -Axiom ethereum_frontier_utils_address_compute_contract_address : - IsGlobalAlias globals ethereum.frontier.utils.address.globals "compute_contract_address". -Axiom ethereum_frontier_utils_address_to_address : - IsGlobalAlias globals ethereum.frontier.utils.address.globals "to_address". +Axiom ethereum_frontier_utils_address_imports : + AreImported globals "ethereum.frontier.utils.address" [ "compute_contract_address"; "to_address" ]. -Require ethereum.frontier.vm.__init__. -Axiom ethereum_frontier_vm___init___Evm : - IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "Evm". -Axiom ethereum_frontier_vm___init___Message : - IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "Message". -Axiom ethereum_frontier_vm___init___incorporate_child_on_error : - IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "incorporate_child_on_error". -Axiom ethereum_frontier_vm___init___incorporate_child_on_success : - IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "incorporate_child_on_success". +Axiom ethereum_frontier_vm_imports : + AreImported globals "ethereum.frontier.vm" [ "Evm"; "Message"; "incorporate_child_on_error"; "incorporate_child_on_success" ]. -Require ethereum.frontier.vm.gas. -Axiom ethereum_frontier_vm_gas_GAS_CREATE : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_CREATE". -Axiom ethereum_frontier_vm_gas_GAS_ZERO : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_ZERO". -Axiom ethereum_frontier_vm_gas_REFUND_SELF_DESTRUCT : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "REFUND_SELF_DESTRUCT". -Axiom ethereum_frontier_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_frontier_vm_gas_calculate_message_call_gas : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "calculate_message_call_gas". -Axiom ethereum_frontier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "charge_gas". +Axiom ethereum_frontier_vm_gas_imports : + AreImported globals "ethereum.frontier.vm.gas" [ "GAS_CREATE"; "GAS_ZERO"; "REFUND_SELF_DESTRUCT"; "calculate_gas_extend_memory"; "calculate_message_call_gas"; "charge_gas" ]. -Require ethereum.frontier.vm.memory. -Axiom ethereum_frontier_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.frontier.vm.memory.globals "memory_read_bytes". -Axiom ethereum_frontier_vm_memory_memory_write : - IsGlobalAlias globals ethereum.frontier.vm.memory.globals "memory_write". +Axiom ethereum_frontier_vm_memory_imports : + AreImported globals "ethereum.frontier.vm.memory" [ "memory_read_bytes"; "memory_write" ]. -Require ethereum.frontier.vm.stack. -Axiom ethereum_frontier_vm_stack_pop : - IsGlobalAlias globals ethereum.frontier.vm.stack.globals "pop". -Axiom ethereum_frontier_vm_stack_push : - IsGlobalAlias globals ethereum.frontier.vm.stack.globals "push". +Axiom ethereum_frontier_vm_stack_imports : + AreImported globals "ethereum.frontier.vm.stack" [ "pop"; "push" ]. Definition create : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -622,7 +582,12 @@ Definition generic_call : Value.t -> Value.t -> M := make_list [ M.get_field (| M.get_name (| globals, "evm" |), "memory" |); M.get_name (| globals, "memory_output_start_position" |); - M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), M.slice (| Constant.None_, M.get_name (| globals, "actual_output_size" |) |) |) + M.slice (| + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), + Constant.None_, + M.get_name (| globals, "actual_output_size" |), + Constant.None_ + |) ], make_dict [] |) in @@ -1035,20 +1000,28 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in let parent_evm := M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "parent_evm" |) in - While Compare.is_not (| - M.get_name (| globals, "parent_evm" |), - Constant.None_ - |) do - let _ := M.call (| + let _ := + M.while (| + Compare.is_not (| + M.get_name (| globals, "parent_evm" |), + Constant.None_ + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "refunded_accounts" |), "update" |), make_list [ M.get_field (| M.get_name (| globals, "parent_evm" |), "accounts_to_delete" |) ], make_dict [] |) in - let parent_evm := - M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in - EndWhile. + let parent_evm := + M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := (* if *) M.if_then_else (| diff --git a/CoqOfPython/ethereum/frontier/vm/interpreter.v b/CoqOfPython/ethereum/frontier/vm/interpreter.v index 68fa407..5fb825a 100644 --- a/CoqOfPython/ethereum/frontier/vm/interpreter.v +++ b/CoqOfPython/ethereum/frontier/vm/interpreter.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.frontier.vm.interpreter". Definition expr_1 : Value.t := Constant.str " @@ -17,109 +17,47 @@ Introduction A straightforward interpreter that executes EVM code. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.trace. -Axiom ethereum_trace_EvmStop : - IsGlobalAlias globals ethereum.trace.globals "EvmStop". -Axiom ethereum_trace_OpEnd : - IsGlobalAlias globals ethereum.trace.globals "OpEnd". -Axiom ethereum_trace_OpException : - IsGlobalAlias globals ethereum.trace.globals "OpException". -Axiom ethereum_trace_OpStart : - IsGlobalAlias globals ethereum.trace.globals "OpStart". -Axiom ethereum_trace_PrecompileEnd : - IsGlobalAlias globals ethereum.trace.globals "PrecompileEnd". -Axiom ethereum_trace_PrecompileStart : - IsGlobalAlias globals ethereum.trace.globals "PrecompileStart". -Axiom ethereum_trace_TransactionEnd : - IsGlobalAlias globals ethereum.trace.globals "TransactionEnd". -Axiom ethereum_trace_evm_trace : - IsGlobalAlias globals ethereum.trace.globals "evm_trace". - -Require ethereum.frontier.blocks. -Axiom ethereum_frontier_blocks_Log : - IsGlobalAlias globals ethereum.frontier.blocks.globals "Log". - -Require ethereum.frontier.fork_types. -Axiom ethereum_frontier_fork_types_Address : - IsGlobalAlias globals ethereum.frontier.fork_types.globals "Address". - -Require ethereum.frontier.state. -Axiom ethereum_frontier_state_account_has_code_or_nonce : - IsGlobalAlias globals ethereum.frontier.state.globals "account_has_code_or_nonce". -Axiom ethereum_frontier_state_begin_transaction : - IsGlobalAlias globals ethereum.frontier.state.globals "begin_transaction". -Axiom ethereum_frontier_state_commit_transaction : - IsGlobalAlias globals ethereum.frontier.state.globals "commit_transaction". -Axiom ethereum_frontier_state_destroy_storage : - IsGlobalAlias globals ethereum.frontier.state.globals "destroy_storage". -Axiom ethereum_frontier_state_move_ether : - IsGlobalAlias globals ethereum.frontier.state.globals "move_ether". -Axiom ethereum_frontier_state_rollback_transaction : - IsGlobalAlias globals ethereum.frontier.state.globals "rollback_transaction". -Axiom ethereum_frontier_state_set_code : - IsGlobalAlias globals ethereum.frontier.state.globals "set_code". -Axiom ethereum_frontier_state_touch_account : - IsGlobalAlias globals ethereum.frontier.state.globals "touch_account". - -Require ethereum.frontier.vm.__init__. -Axiom ethereum_frontier_vm___init___Message : - IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "Message". - -Require ethereum.frontier.vm.gas. -Axiom ethereum_frontier_vm_gas_GAS_CODE_DEPOSIT : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_CODE_DEPOSIT". -Axiom ethereum_frontier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "charge_gas". - -Require ethereum.frontier.vm.precompiled_contracts.mapping. -Axiom ethereum_frontier_vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : - IsGlobalAlias globals ethereum.frontier.vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". - -Require ethereum.frontier.vm.__init__. -Axiom ethereum_frontier_vm___init___Environment : - IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "Environment". -Axiom ethereum_frontier_vm___init___Evm : - IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "Evm". - -Require ethereum.frontier.vm.exceptions. -Axiom ethereum_frontier_vm_exceptions_AddressCollision : - IsGlobalAlias globals ethereum.frontier.vm.exceptions.globals "AddressCollision". -Axiom ethereum_frontier_vm_exceptions_ExceptionalHalt : - IsGlobalAlias globals ethereum.frontier.vm.exceptions.globals "ExceptionalHalt". -Axiom ethereum_frontier_vm_exceptions_InvalidOpcode : - IsGlobalAlias globals ethereum.frontier.vm.exceptions.globals "InvalidOpcode". -Axiom ethereum_frontier_vm_exceptions_StackDepthLimitError : - IsGlobalAlias globals ethereum.frontier.vm.exceptions.globals "StackDepthLimitError". - -Require ethereum.frontier.vm.instructions.__init__. -Axiom ethereum_frontier_vm_instructions___init___Ops : - IsGlobalAlias globals ethereum.frontier.vm.instructions.__init__.globals "Ops". -Axiom ethereum_frontier_vm_instructions___init___op_implementation : - IsGlobalAlias globals ethereum.frontier.vm.instructions.__init__.globals "op_implementation". - -Require ethereum.frontier.vm.runtime. -Axiom ethereum_frontier_vm_runtime_get_valid_jump_destinations : - IsGlobalAlias globals ethereum.frontier.vm.runtime.globals "get_valid_jump_destinations". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Optional"; "Set"; "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. + +Axiom ethereum_trace_imports : + AreImported globals "ethereum.trace" [ "EvmStop"; "OpEnd"; "OpException"; "OpStart"; "PrecompileEnd"; "PrecompileStart"; "TransactionEnd"; "evm_trace" ]. + +Axiom ethereum_frontier_blocks_imports : + AreImported globals "ethereum.frontier.blocks" [ "Log" ]. + +Axiom ethereum_frontier_fork_types_imports : + AreImported globals "ethereum.frontier.fork_types" [ "Address" ]. + +Axiom ethereum_frontier_state_imports : + AreImported globals "ethereum.frontier.state" [ "account_has_code_or_nonce"; "begin_transaction"; "commit_transaction"; "destroy_storage"; "move_ether"; "rollback_transaction"; "set_code"; "touch_account" ]. + +Axiom ethereum_frontier_vm_imports : + AreImported globals "ethereum.frontier.vm" [ "Message" ]. + +Axiom ethereum_frontier_vm_gas_imports : + AreImported globals "ethereum.frontier.vm.gas" [ "GAS_CODE_DEPOSIT"; "charge_gas" ]. + +Axiom ethereum_frontier_vm_precompiled_contracts_mapping_imports : + AreImported globals "ethereum.frontier.vm.precompiled_contracts.mapping" [ "PRE_COMPILED_CONTRACTS" ]. + +Axiom ethereum_frontier_vm_imports : + AreImported globals "ethereum.frontier.vm" [ "Environment"; "Evm" ]. + +Axiom ethereum_frontier_vm_exceptions_imports : + AreImported globals "ethereum.frontier.vm.exceptions" [ "AddressCollision"; "ExceptionalHalt"; "InvalidOpcode"; "StackDepthLimitError" ]. + +Axiom ethereum_frontier_vm_instructions_imports : + AreImported globals "ethereum.frontier.vm.instructions" [ "Ops"; "op_implementation" ]. + +Axiom ethereum_frontier_vm_runtime_imports : + AreImported globals "ethereum.frontier.vm.runtime" [ "get_valid_jump_destinations" ]. Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -431,7 +369,7 @@ Definition process_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "StackDepthLimitError" |), make_list [ Constant.str "Stack depth limit reached" diff --git a/CoqOfPython/ethereum/frontier/vm/memory.v b/CoqOfPython/ethereum/frontier/vm/memory.v index 08d2290..280775b 100644 --- a/CoqOfPython/ethereum/frontier/vm/memory.v +++ b/CoqOfPython/ethereum/frontier/vm/memory.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.frontier.vm.memory". Definition expr_1 : Value.t := Constant.str " @@ -17,17 +17,11 @@ Introduction EVM memory operations. ". -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_right_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "right_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "right_pad_zero_bytes" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. Definition memory_write : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,22 +39,27 @@ Definition memory_write : Value.t -> Value.t -> M := Data to write to memory. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + M.slice (| + M.get_name (| globals, "memory" |), + M.get_name (| globals, "start_position" |), + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) - |) |) |), + Constant.None_ + |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_)). @@ -86,22 +85,27 @@ Definition memory_read_bytes : Value.t -> Value.t -> M := Data read from memory. " in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + M.slice (| + M.get_name (| globals, "memory" |), + M.get_name (| globals, "start_position" |), + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |) |) + Constant.None_ + |) |) in M.pure Constant.None_)). @@ -129,22 +133,27 @@ Definition buffer_read : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "right_pad_zero_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "buffer" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + M.slice (| + M.get_name (| globals, "buffer" |), + M.get_name (| globals, "start_position" |), + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |) |); + Constant.None_ + |); M.get_name (| globals, "size" |) ], make_dict [] diff --git a/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/__init__.v index b0d967f..ff4dfb5 100644 --- a/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/__init__.v +++ b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.frontier.vm.precompiled_contracts.__init__". Definition expr_1 : Value.t := Constant.str " @@ -18,9 +18,8 @@ Addresses of precompiled contracts and mappings to their implementations. ". -Require ethereum.frontier.utils.hexadecimal. -Axiom ethereum_frontier_utils_hexadecimal_hex_to_address : - IsGlobalAlias globals ethereum.frontier.utils.hexadecimal.globals "hex_to_address". +Axiom ethereum_frontier_utils_hexadecimal_imports : + AreImported globals "ethereum.frontier.utils.hexadecimal" [ "hex_to_address" ]. Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS" ] diff --git a/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/ecrecover.v index e54178a..a76cd62 100644 --- a/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/ecrecover.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.frontier.vm.precompiled_contracts.ecrecover". Definition expr_1 : Value.t := Constant.str " @@ -17,39 +17,26 @@ Introduction Implementation of the ECRECOVER precompiled contract. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.crypto.elliptic_curve. -Axiom ethereum_crypto_elliptic_curve_SECP256K1N : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". -Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". +Axiom ethereum_crypto_elliptic_curve_imports : + AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_left_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. -Require ethereum.frontier.vm.__init__. -Axiom ethereum_frontier_vm___init___Evm : - IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "Evm". +Axiom ethereum_frontier_vm_imports : + AreImported globals "ethereum.frontier.vm" [ "Evm" ]. -Require ethereum.frontier.vm.gas. -Axiom ethereum_frontier_vm_gas_GAS_ECRECOVER : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_ECRECOVER". -Axiom ethereum_frontier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "charge_gas". +Axiom ethereum_frontier_vm_gas_imports : + AreImported globals "ethereum.frontier.vm.gas" [ "GAS_ECRECOVER"; "charge_gas" ]. -Require ethereum.frontier.vm.memory. -Axiom ethereum_frontier_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.frontier.vm.memory.globals "buffer_read". +Axiom ethereum_frontier_vm_memory_imports : + AreImported globals "ethereum.frontier.vm.memory" [ "buffer_read" ]. Definition ecrecover : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -264,13 +251,18 @@ Definition ecrecover : Value.t -> Value.t -> M := )) |) in (* At stmt: unsupported node type: Try *) let address := - M.get_subscript (| M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "public_key" |) - ], - make_dict [] - |), M.slice (| Constant.int 12, Constant.int 32 |) |) in + M.slice (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), + Constant.int 12, + Constant.int 32, + Constant.None_ + |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/identity.v index 6e7b4d3..e03db13 100644 --- a/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/identity.v +++ b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/identity.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.frontier.vm.precompiled_contracts.identity". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementation of the `IDENTITY` precompiled contract. ". -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.frontier.vm.__init__. -Axiom ethereum_frontier_vm___init___Evm : - IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "Evm". +Axiom ethereum_frontier_vm_imports : + AreImported globals "ethereum.frontier.vm" [ "Evm" ]. -Require ethereum.frontier.vm.gas. -Axiom ethereum_frontier_vm_gas_GAS_IDENTITY : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_IDENTITY". -Axiom ethereum_frontier_vm_gas_GAS_IDENTITY_WORD : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_IDENTITY_WORD". -Axiom ethereum_frontier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "charge_gas". +Axiom ethereum_frontier_vm_gas_imports : + AreImported globals "ethereum.frontier.vm.gas" [ "GAS_IDENTITY"; "GAS_IDENTITY_WORD"; "charge_gas" ]. Definition identity : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/mapping.v index a482e4b..e1e4110 100644 --- a/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/mapping.v +++ b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/mapping.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.frontier.vm.precompiled_contracts.mapping". Definition expr_1 : Value.t := Constant.str " @@ -17,40 +17,25 @@ Introduction Mapping of precompiled contracts their implementations. ". -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". - -Require ethereum.frontier.fork_types. -Axiom ethereum_frontier_fork_types_Address : - IsGlobalAlias globals ethereum.frontier.fork_types.globals "Address". - -Require ethereum.frontier.vm.precompiled_contracts.__init__. -Axiom ethereum_frontier_vm_precompiled_contracts___init___ECRECOVER_ADDRESS : - IsGlobalAlias globals ethereum.frontier.vm.precompiled_contracts.__init__.globals "ECRECOVER_ADDRESS". -Axiom ethereum_frontier_vm_precompiled_contracts___init___IDENTITY_ADDRESS : - IsGlobalAlias globals ethereum.frontier.vm.precompiled_contracts.__init__.globals "IDENTITY_ADDRESS". -Axiom ethereum_frontier_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : - IsGlobalAlias globals ethereum.frontier.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". -Axiom ethereum_frontier_vm_precompiled_contracts___init___SHA256_ADDRESS : - IsGlobalAlias globals ethereum.frontier.vm.precompiled_contracts.__init__.globals "SHA256_ADDRESS". - -Require ethereum.frontier.vm.precompiled_contracts.ecrecover. -Axiom ethereum_frontier_vm_precompiled_contracts_ecrecover_ecrecover : - IsGlobalAlias globals ethereum.frontier.vm.precompiled_contracts.ecrecover.globals "ecrecover". - -Require ethereum.frontier.vm.precompiled_contracts.identity. -Axiom ethereum_frontier_vm_precompiled_contracts_identity_identity : - IsGlobalAlias globals ethereum.frontier.vm.precompiled_contracts.identity.globals "identity". - -Require ethereum.frontier.vm.precompiled_contracts.ripemd160. -Axiom ethereum_frontier_vm_precompiled_contracts_ripemd160_ripemd160 : - IsGlobalAlias globals ethereum.frontier.vm.precompiled_contracts.ripemd160.globals "ripemd160". - -Require ethereum.frontier.vm.precompiled_contracts.sha256. -Axiom ethereum_frontier_vm_precompiled_contracts_sha256_sha256 : - IsGlobalAlias globals ethereum.frontier.vm.precompiled_contracts.sha256.globals "sha256". +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict" ]. + +Axiom ethereum_frontier_fork_types_imports : + AreImported globals "ethereum.frontier.fork_types" [ "Address" ]. + +Axiom ethereum_frontier_vm_precompiled_contracts_imports : + AreImported globals "ethereum.frontier.vm.precompiled_contracts" [ "ECRECOVER_ADDRESS"; "IDENTITY_ADDRESS"; "RIPEMD160_ADDRESS"; "SHA256_ADDRESS" ]. + +Axiom ethereum_frontier_vm_precompiled_contracts_ecrecover_imports : + AreImported globals "ethereum.frontier.vm.precompiled_contracts.ecrecover" [ "ecrecover" ]. + +Axiom ethereum_frontier_vm_precompiled_contracts_identity_imports : + AreImported globals "ethereum.frontier.vm.precompiled_contracts.identity" [ "identity" ]. + +Axiom ethereum_frontier_vm_precompiled_contracts_ripemd160_imports : + AreImported globals "ethereum.frontier.vm.precompiled_contracts.ripemd160" [ "ripemd160" ]. + +Axiom ethereum_frontier_vm_precompiled_contracts_sha256_imports : + AreImported globals "ethereum.frontier.vm.precompiled_contracts.sha256" [ "sha256" ]. (* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/ripemd160.v index 2d0a6cc..a95ac84 100644 --- a/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/ripemd160.v +++ b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/ripemd160.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.frontier.vm.precompiled_contracts.ripemd160". Definition expr_1 : Value.t := Constant.str " @@ -19,29 +19,20 @@ Implementation of the `RIPEMD160` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_left_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.frontier.vm.__init__. -Axiom ethereum_frontier_vm___init___Evm : - IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "Evm". +Axiom ethereum_frontier_vm_imports : + AreImported globals "ethereum.frontier.vm" [ "Evm" ]. -Require ethereum.frontier.vm.gas. -Axiom ethereum_frontier_vm_gas_GAS_RIPEMD160 : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_RIPEMD160". -Axiom ethereum_frontier_vm_gas_GAS_RIPEMD160_WORD : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_RIPEMD160_WORD". -Axiom ethereum_frontier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "charge_gas". +Axiom ethereum_frontier_vm_gas_imports : + AreImported globals "ethereum.frontier.vm.gas" [ "GAS_RIPEMD160"; "GAS_RIPEMD160_WORD"; "charge_gas" ]. Definition ripemd160 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/sha256.v index ce63204..941dbb4 100644 --- a/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/sha256.v +++ b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/sha256.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.frontier.vm.precompiled_contracts.sha256". Definition expr_1 : Value.t := Constant.str " @@ -19,25 +19,17 @@ Implementation of the `SHA256` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.frontier.vm.__init__. -Axiom ethereum_frontier_vm___init___Evm : - IsGlobalAlias globals ethereum.frontier.vm.__init__.globals "Evm". +Axiom ethereum_frontier_vm_imports : + AreImported globals "ethereum.frontier.vm" [ "Evm" ]. -Require ethereum.frontier.vm.gas. -Axiom ethereum_frontier_vm_gas_GAS_SHA256 : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_SHA256". -Axiom ethereum_frontier_vm_gas_GAS_SHA256_WORD : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "GAS_SHA256_WORD". -Axiom ethereum_frontier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.frontier.vm.gas.globals "charge_gas". +Axiom ethereum_frontier_vm_gas_imports : + AreImported globals "ethereum.frontier.vm.gas" [ "GAS_SHA256"; "GAS_SHA256_WORD"; "charge_gas" ]. Definition sha256 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/frontier/vm/runtime.v b/CoqOfPython/ethereum/frontier/vm/runtime.v index 21656f1..6e7e96d 100644 --- a/CoqOfPython/ethereum/frontier/vm/runtime.v +++ b/CoqOfPython/ethereum/frontier/vm/runtime.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.frontier.vm.runtime". Definition expr_1 : Value.t := Constant.str " @@ -17,17 +17,14 @@ Introduction Runtime related operations used while executing EVM code. ". -Require typing. -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". +Axiom typing_imports : + AreImported globals "typing" [ "Set" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.frontier.vm.instructions.__init__. -Axiom ethereum_frontier_vm_instructions___init___Ops : - IsGlobalAlias globals ethereum.frontier.vm.instructions.__init__.globals "Ops". +Axiom ethereum_frontier_vm_instructions_imports : + AreImported globals "ethereum.frontier.vm.instructions" [ "Ops" ]. Definition get_valid_jump_destinations : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -67,75 +64,83 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := ], make_dict [] |) in - While Compare.lt (| - M.get_name (| globals, "pc" |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "code" |) - ], - make_dict [] - |) - |) do -(* At stmt: unsupported node type: Try *) - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "current_opcode" |), - M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) - |), - (* then *) + let _ := + M.while (| + Compare.lt (| + M.get_name (| globals, "pc" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) + |), ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), - make_list [ - M.get_name (| globals, "pc" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( +(* At stmt: unsupported node type: Try *) let _ := (* if *) M.if_then_else (| - BoolOp.and (| - Compare.lt_e (| - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |), - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |) - |), - ltac:(M.monadic ( - Compare.lt_e (| - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH32" |), "value" |) - |) - )) + Compare.eq (| + M.get_name (| globals, "current_opcode" |), + M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) |), (* then *) ltac:(M.monadic ( - let push_data_size := - BinOp.add (| - BinOp.sub (| - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) - |), - Constant.int 1 - |) in - let pc := BinOp.add - M.get_name (| globals, "push_data_size" |) - M.get_name (| globals, "push_data_size" |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), + make_list [ + M.get_name (| globals, "pc" |) + ], + make_dict [] + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.lt_e (| + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |), + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH32" |), "value" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let push_data_size := + BinOp.add (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) + |), + Constant.int 1 + |) in + let pc := BinOp.add + M.get_name (| globals, "push_data_size" |) + M.get_name (| globals, "push_data_size" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ )) |) in + let pc := BinOp.add + Constant.int 1 + Constant.int 1 in M.pure Constant.None_ - )) |) in - let pc := BinOp.add - Constant.int 1 - Constant.int 1 in - EndWhile. + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.get_name (| globals, "valid_jump_destinations" |) |) in diff --git a/CoqOfPython/ethereum/frontier/vm/stack.v b/CoqOfPython/ethereum/frontier/vm/stack.v index b7f149b..797e688 100644 --- a/CoqOfPython/ethereum/frontier/vm/stack.v +++ b/CoqOfPython/ethereum/frontier/vm/stack.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.frontier.vm.stack". Definition expr_1 : Value.t := Constant.str " @@ -17,19 +17,14 @@ Introduction Implementation of the stack operators for the EVM. ". -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". +Axiom typing_imports : + AreImported globals "typing" [ "List" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.frontier.vm.exceptions. -Axiom ethereum_frontier_vm_exceptions_StackOverflowError : - IsGlobalAlias globals ethereum.frontier.vm.exceptions.globals "StackOverflowError". -Axiom ethereum_frontier_vm_exceptions_StackUnderflowError : - IsGlobalAlias globals ethereum.frontier.vm.exceptions.globals "StackUnderflowError". +Axiom ethereum_frontier_vm_exceptions_imports : + AreImported globals "ethereum.frontier.vm.exceptions" [ "StackOverflowError"; "StackUnderflowError" ]. Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -63,7 +58,7 @@ Definition pop : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "StackUnderflowError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "StackUnderflowError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -108,7 +103,7 @@ Definition push : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "StackOverflowError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "StackOverflowError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/genesis.v b/CoqOfPython/ethereum/genesis.v index 41faa5c..9c3bac3 100644 --- a/CoqOfPython/ethereum/genesis.v +++ b/CoqOfPython/ethereum/genesis.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.genesis". Definition expr_1 : Value.t := Constant.str " @@ -22,49 +22,20 @@ different chains. (* At top_level_stmt: unsupported node type: Import *) -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. -Require typing. -Axiom typing_Any : - IsGlobalAlias globals typing.globals "Any". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". -Axiom typing_cast : - IsGlobalAlias globals typing.globals "cast". +Axiom typing_imports : + AreImported globals "typing" [ "Any"; "Dict"; "cast" ]. -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U64 : - IsGlobalAlias globals ethereum.base_types.globals "U64". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes8 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes8". -Axiom ethereum_base_types_Bytes20 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes20". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U64"; "U256"; "Bytes"; "Bytes8"; "Bytes20"; "Uint"; "slotted_freezable" ]. -Require ethereum.utils.hexadecimal. -Axiom ethereum_utils_hexadecimal_hex_to_bytes : - IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". -Axiom ethereum_utils_hexadecimal_hex_to_bytes8 : - IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes8". -Axiom ethereum_utils_hexadecimal_hex_to_bytes32 : - IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes32". -Axiom ethereum_utils_hexadecimal_hex_to_u256 : - IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_u256". -Axiom ethereum_utils_hexadecimal_hex_to_uint : - IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_uint". +Axiom ethereum_utils_hexadecimal_imports : + AreImported globals "ethereum.utils.hexadecimal" [ "hex_to_bytes"; "hex_to_bytes8"; "hex_to_bytes32"; "hex_to_u256"; "hex_to_uint" ]. Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) @@ -233,20 +204,24 @@ Definition add_genesis_block : Value.t -> Value.t -> M := genesis : The genesis configuration to use. " in - For make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "account" |) ] in M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "genesis" |), "initial_accounts" |), "items" |), - make_list [], - make_dict [] - |) do - let address := + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "account" |) ], M.call (| - M.get_field (| M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "utils" |), "hexadecimal" |), "hex_to_address" |), - make_list [ - M.get_name (| globals, "address" |) - ], - make_dict [] - |) in - let _ := M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "genesis" |), "initial_accounts" |), "items" |), + make_list [], + make_dict [] + |), + ltac:(M.monadic ( + let address := + M.call (| + M.get_field (| M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "utils" |), "hexadecimal" |), "hex_to_address" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) in + let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "state" |), "set_account" |), make_list [ M.get_field (| M.get_name (| globals, "chain" |), "state" |); @@ -308,19 +283,23 @@ Definition add_genesis_block : Value.t -> Value.t -> M := ], make_dict [] |) in - For make_tuple [ M.get_name (| globals, "key" |); M.get_name (| globals, "value" |) ] in M.call (| - M.get_field (| M.call (| - M.get_field (| M.get_name (| globals, "account" |), "get" |), - make_list [ - Constant.str "storage"; - {} - ], + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "key" |); M.get_name (| globals, "value" |) ], + M.call (| + M.get_field (| M.call (| + M.get_field (| M.get_name (| globals, "account" |), "get" |), + make_list [ + Constant.str "storage"; + {} + ], + make_dict [] + |), "items" |), + make_list [], make_dict [] - |), "items" |), - make_list [], - make_dict [] - |) do - let _ := M.call (| + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "state" |), "set_storage" |), make_list [ M.get_field (| M.get_name (| globals, "chain" |), "state" |); @@ -342,8 +321,18 @@ Definition add_genesis_block : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let fields := {Constant.str "parent_hash": M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "fork_types" |), "Hash32" |), @@ -437,7 +426,10 @@ Definition add_genesis_block : Value.t -> Value.t -> M := (* then *) ltac:(M.monadic ( let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "fields" |), Constant.str "mix_digest" |), + M.get_subscript (| + M.get_name (| globals, "fields" |), + Constant.str "mix_digest" + |), M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "fork_types" |), "Hash32" |), make_list [ @@ -453,7 +445,10 @@ Definition add_genesis_block : Value.t -> Value.t -> M := (* else *) )), ltac:(M.monadic ( let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "fields" |), Constant.str "prev_randao" |), + M.get_subscript (| + M.get_name (| globals, "fields" |), + Constant.str "prev_randao" + |), M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "fork_types" |), "Hash32" |), make_list [ @@ -481,7 +476,10 @@ Definition add_genesis_block : Value.t -> Value.t -> M := (* then *) ltac:(M.monadic ( let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "fields" |), Constant.str "base_fee_per_gas" |), + M.get_subscript (| + M.get_name (| globals, "fields" |), + Constant.str "base_fee_per_gas" + |), M.call (| M.get_name (| globals, "Uint" |), make_list [ diff --git a/CoqOfPython/ethereum/gray_glacier/__init__.v b/CoqOfPython/ethereum/gray_glacier/__init__.v index 2ed64ad..63786a4 100644 --- a/CoqOfPython/ethereum/gray_glacier/__init__.v +++ b/CoqOfPython/ethereum/gray_glacier/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.gray_glacier.__init__". Definition expr_1 : Value.t := Constant.str " @@ -8,9 +8,8 @@ The Gray Glacier fork delays the difficulty bomb. There are no other changes in this fork. ". -Require ethereum.fork_criteria. -Axiom ethereum_fork_criteria_ByBlockNumber : - IsGlobalAlias globals ethereum.fork_criteria.globals "ByBlockNumber". +Axiom ethereum_fork_criteria_imports : + AreImported globals "ethereum.fork_criteria" [ "ByBlockNumber" ]. Definition FORK_CRITERIA : Value.t := M.run ltac:(M.monadic ( M.call (| diff --git a/CoqOfPython/ethereum/gray_glacier/blocks.v b/CoqOfPython/ethereum/gray_glacier/blocks.v index 7656b6a..0845cef 100644 --- a/CoqOfPython/ethereum/gray_glacier/blocks.v +++ b/CoqOfPython/ethereum/gray_glacier/blocks.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.gray_glacier.blocks". Definition expr_1 : Value.t := Constant.str " @@ -14,45 +14,23 @@ history of all state transitions that have happened since the genesis of the chain. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes8 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes8". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". - -Require ethereum.gray_glacier.fork_types. -Axiom ethereum_gray_glacier_fork_types_Address : - IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "Address". -Axiom ethereum_gray_glacier_fork_types_Bloom : - IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "Bloom". -Axiom ethereum_gray_glacier_fork_types_Root : - IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "Root". - -Require ethereum.gray_glacier.transactions. -Axiom ethereum_gray_glacier_transactions_LegacyTransaction : - IsGlobalAlias globals ethereum.gray_glacier.transactions.globals "LegacyTransaction". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Tuple"; "Union" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes8"; "Bytes32"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. + +Axiom ethereum_gray_glacier_fork_types_imports : + AreImported globals "ethereum.gray_glacier.fork_types" [ "Address"; "Bloom"; "Root" ]. + +Axiom ethereum_gray_glacier_transactions_imports : + AreImported globals "ethereum.gray_glacier.transactions" [ "LegacyTransaction" ]. Definition Header : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/gray_glacier/bloom.v b/CoqOfPython/ethereum/gray_glacier/bloom.v index fb2d5b0..b87575c 100644 --- a/CoqOfPython/ethereum/gray_glacier/bloom.v +++ b/CoqOfPython/ethereum/gray_glacier/bloom.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.gray_glacier.bloom". Definition expr_1 : Value.t := Constant.str " @@ -21,25 +21,20 @@ for efficient searching of logs by address and/or topic, by rapidly eliminating blocks and receipts from their search. ". -Require typing. -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_imports : + AreImported globals "typing" [ "Tuple" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. -Require ethereum.gray_glacier.blocks. -Axiom ethereum_gray_glacier_blocks_Log : - IsGlobalAlias globals ethereum.gray_glacier.blocks.globals "Log". +Axiom ethereum_gray_glacier_blocks_imports : + AreImported globals "ethereum.gray_glacier.blocks" [ "Log" ]. -Require ethereum.gray_glacier.fork_types. -Axiom ethereum_gray_glacier_fork_types_Bloom : - IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "Bloom". +Axiom ethereum_gray_glacier_fork_types_imports : + AreImported globals "ethereum.gray_glacier.fork_types" [ "Bloom" ]. Definition add_to_bloom : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -66,50 +61,70 @@ Definition add_to_bloom : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "idx" |) in make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ] do - let bit_to_set := - BinOp.bit_and (| - M.call (| - M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "hash" |), M.slice (| M.get_name (| globals, "idx" |), BinOp.add (| - M.get_name (| globals, "idx" |), - Constant.int 2 - |) |) |) - ], - make_dict [] - |), - Constant.int 2047 - |) in - let bit_index := - BinOp.sub (| - Constant.int 2047, - M.get_name (| globals, "bit_to_set" |) - |) in - let byte_index := - BinOp.floor_div (| - M.get_name (| globals, "bit_index" |), - Constant.int 8 - |) in - let bit_value := - BinOp.l_shift (| - Constant.int 1, - BinOp.sub (| - Constant.int 7, - BinOp.mod_ (| + let _ := + M.for_ (| + M.get_name (| globals, "idx" |), + make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ], + ltac:(M.monadic ( + let bit_to_set := + BinOp.bit_and (| + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.slice (| + M.get_name (| globals, "hash" |), + M.get_name (| globals, "idx" |), + BinOp.add (| + M.get_name (| globals, "idx" |), + Constant.int 2 + |), + Constant.None_ + |) + ], + make_dict [] + |), + Constant.int 2047 + |) in + let bit_index := + BinOp.sub (| + Constant.int 2047, + M.get_name (| globals, "bit_to_set" |) + |) in + let byte_index := + BinOp.floor_div (| M.get_name (| globals, "bit_index" |), Constant.int 8 + |) in + let bit_value := + BinOp.l_shift (| + Constant.int 1, + BinOp.sub (| + Constant.int 7, + BinOp.mod_ (| + M.get_name (| globals, "bit_index" |), + Constant.int 8 + |) + |) + |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "bloom" |), + M.get_name (| globals, "byte_index" |) + |), + BinOp.bit_or (| + M.get_subscript (| + M.get_name (| globals, "bloom" |), + M.get_name (| globals, "byte_index" |) + |), + M.get_name (| globals, "bit_value" |) |) - |) - |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), - BinOp.bit_or (| - M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), - M.get_name (| globals, "bit_value" |) - |) - |) in - EndFor. + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_)). Definition logs_bloom : Value.t -> Value.t -> M := @@ -132,8 +147,12 @@ Definition logs_bloom : Value.t -> Value.t -> M := the caller address and the log topics. " in (* At stmt: unsupported node type: AnnAssign *) - For M.get_name (| globals, "log" |) in M.get_name (| globals, "logs" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "log" |), + M.get_name (| globals, "logs" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "add_to_bloom" |), make_list [ M.get_name (| globals, "bloom" |); @@ -141,8 +160,12 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "topic" |) in M.get_field (| M.get_name (| globals, "log" |), "topics" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "topic" |), + M.get_field (| M.get_name (| globals, "log" |), "topics" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "add_to_bloom" |), make_list [ M.get_name (| globals, "bloom" |); @@ -150,8 +173,18 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Bloom" |), diff --git a/CoqOfPython/ethereum/gray_glacier/fork.v b/CoqOfPython/ethereum/gray_glacier/fork.v index a0c2cc6..09ccc1f 100644 --- a/CoqOfPython/ethereum/gray_glacier/fork.v +++ b/CoqOfPython/ethereum/gray_glacier/fork.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.gray_glacier.fork". Definition expr_1 : Value.t := Constant.str " @@ -17,155 +17,62 @@ Introduction Entry point for the Ethereum specification. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". - -Require ethereum.base_types. -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". - -Require ethereum.crypto.elliptic_curve. -Axiom ethereum_crypto_elliptic_curve_SECP256K1N : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". -Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.ethash. -Axiom ethereum_ethash_dataset_size : - IsGlobalAlias globals ethereum.ethash.globals "dataset_size". -Axiom ethereum_ethash_generate_cache : - IsGlobalAlias globals ethereum.ethash.globals "generate_cache". -Axiom ethereum_ethash_hashimoto_light : - IsGlobalAlias globals ethereum.ethash.globals "hashimoto_light". - -Require ethereum.exceptions. -Axiom ethereum_exceptions_InvalidBlock : - IsGlobalAlias globals ethereum.exceptions.globals "InvalidBlock". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U64 : - IsGlobalAlias globals ethereum.base_types.globals "U64". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_U256_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.gray_glacier.__init__. -Axiom ethereum_gray_glacier___init___vm : - IsGlobalAlias globals ethereum.gray_glacier.__init__.globals "vm". - -Require ethereum.gray_glacier.blocks. -Axiom ethereum_gray_glacier_blocks_Block : - IsGlobalAlias globals ethereum.gray_glacier.blocks.globals "Block". -Axiom ethereum_gray_glacier_blocks_Header : - IsGlobalAlias globals ethereum.gray_glacier.blocks.globals "Header". -Axiom ethereum_gray_glacier_blocks_Log : - IsGlobalAlias globals ethereum.gray_glacier.blocks.globals "Log". -Axiom ethereum_gray_glacier_blocks_Receipt : - IsGlobalAlias globals ethereum.gray_glacier.blocks.globals "Receipt". - -Require ethereum.gray_glacier.bloom. -Axiom ethereum_gray_glacier_bloom_logs_bloom : - IsGlobalAlias globals ethereum.gray_glacier.bloom.globals "logs_bloom". - -Require ethereum.gray_glacier.fork_types. -Axiom ethereum_gray_glacier_fork_types_Address : - IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "Address". -Axiom ethereum_gray_glacier_fork_types_Bloom : - IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "Bloom". -Axiom ethereum_gray_glacier_fork_types_Root : - IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "Root". - -Require ethereum.gray_glacier.state. -Axiom ethereum_gray_glacier_state_State : - IsGlobalAlias globals ethereum.gray_glacier.state.globals "State". -Axiom ethereum_gray_glacier_state_account_exists_and_is_empty : - IsGlobalAlias globals ethereum.gray_glacier.state.globals "account_exists_and_is_empty". -Axiom ethereum_gray_glacier_state_create_ether : - IsGlobalAlias globals ethereum.gray_glacier.state.globals "create_ether". -Axiom ethereum_gray_glacier_state_destroy_account : - IsGlobalAlias globals ethereum.gray_glacier.state.globals "destroy_account". -Axiom ethereum_gray_glacier_state_get_account : - IsGlobalAlias globals ethereum.gray_glacier.state.globals "get_account". -Axiom ethereum_gray_glacier_state_increment_nonce : - IsGlobalAlias globals ethereum.gray_glacier.state.globals "increment_nonce". -Axiom ethereum_gray_glacier_state_set_account_balance : - IsGlobalAlias globals ethereum.gray_glacier.state.globals "set_account_balance". -Axiom ethereum_gray_glacier_state_state_root : - IsGlobalAlias globals ethereum.gray_glacier.state.globals "state_root". - -Require ethereum.gray_glacier.transactions. -Axiom ethereum_gray_glacier_transactions_TX_ACCESS_LIST_ADDRESS_COST : - IsGlobalAlias globals ethereum.gray_glacier.transactions.globals "TX_ACCESS_LIST_ADDRESS_COST". -Axiom ethereum_gray_glacier_transactions_TX_ACCESS_LIST_STORAGE_KEY_COST : - IsGlobalAlias globals ethereum.gray_glacier.transactions.globals "TX_ACCESS_LIST_STORAGE_KEY_COST". -Axiom ethereum_gray_glacier_transactions_TX_BASE_COST : - IsGlobalAlias globals ethereum.gray_glacier.transactions.globals "TX_BASE_COST". -Axiom ethereum_gray_glacier_transactions_TX_CREATE_COST : - IsGlobalAlias globals ethereum.gray_glacier.transactions.globals "TX_CREATE_COST". -Axiom ethereum_gray_glacier_transactions_TX_DATA_COST_PER_NON_ZERO : - IsGlobalAlias globals ethereum.gray_glacier.transactions.globals "TX_DATA_COST_PER_NON_ZERO". -Axiom ethereum_gray_glacier_transactions_TX_DATA_COST_PER_ZERO : - IsGlobalAlias globals ethereum.gray_glacier.transactions.globals "TX_DATA_COST_PER_ZERO". -Axiom ethereum_gray_glacier_transactions_AccessListTransaction : - IsGlobalAlias globals ethereum.gray_glacier.transactions.globals "AccessListTransaction". -Axiom ethereum_gray_glacier_transactions_FeeMarketTransaction : - IsGlobalAlias globals ethereum.gray_glacier.transactions.globals "FeeMarketTransaction". -Axiom ethereum_gray_glacier_transactions_LegacyTransaction : - IsGlobalAlias globals ethereum.gray_glacier.transactions.globals "LegacyTransaction". -Axiom ethereum_gray_glacier_transactions_Transaction : - IsGlobalAlias globals ethereum.gray_glacier.transactions.globals "Transaction". -Axiom ethereum_gray_glacier_transactions_decode_transaction : - IsGlobalAlias globals ethereum.gray_glacier.transactions.globals "decode_transaction". -Axiom ethereum_gray_glacier_transactions_encode_transaction : - IsGlobalAlias globals ethereum.gray_glacier.transactions.globals "encode_transaction". - -Require ethereum.gray_glacier.trie. -Axiom ethereum_gray_glacier_trie_Trie : - IsGlobalAlias globals ethereum.gray_glacier.trie.globals "Trie". -Axiom ethereum_gray_glacier_trie_root : - IsGlobalAlias globals ethereum.gray_glacier.trie.globals "root". -Axiom ethereum_gray_glacier_trie_trie_set : - IsGlobalAlias globals ethereum.gray_glacier.trie.globals "trie_set". - -Require ethereum.gray_glacier.utils.message. -Axiom ethereum_gray_glacier_utils_message_prepare_message : - IsGlobalAlias globals ethereum.gray_glacier.utils.message.globals "prepare_message". - -Require ethereum.gray_glacier.vm.interpreter. -Axiom ethereum_gray_glacier_vm_interpreter_process_message_call : - IsGlobalAlias globals ethereum.gray_glacier.vm.interpreter.globals "process_message_call". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple"; "Union" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Bytes0" ]. + +Axiom ethereum_crypto_elliptic_curve_imports : + AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. + +Axiom ethereum_ethash_imports : + AreImported globals "ethereum.ethash" [ "dataset_size"; "generate_cache"; "hashimoto_light" ]. + +Axiom ethereum_exceptions_imports : + AreImported globals "ethereum.exceptions" [ "InvalidBlock" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U64"; "U256"; "U256_CEIL_VALUE"; "Bytes"; "Uint" ]. + +Axiom ethereum_gray_glacier_imports : + AreImported globals "ethereum.gray_glacier" [ "vm" ]. + +Axiom ethereum_gray_glacier_blocks_imports : + AreImported globals "ethereum.gray_glacier.blocks" [ "Block"; "Header"; "Log"; "Receipt" ]. + +Axiom ethereum_gray_glacier_bloom_imports : + AreImported globals "ethereum.gray_glacier.bloom" [ "logs_bloom" ]. + +Axiom ethereum_gray_glacier_fork_types_imports : + AreImported globals "ethereum.gray_glacier.fork_types" [ "Address"; "Bloom"; "Root" ]. + +Axiom ethereum_gray_glacier_state_imports : + AreImported globals "ethereum.gray_glacier.state" [ "State"; "account_exists_and_is_empty"; "create_ether"; "destroy_account"; "get_account"; "increment_nonce"; "set_account_balance"; "state_root" ]. + +Axiom ethereum_gray_glacier_transactions_imports : + AreImported globals "ethereum.gray_glacier.transactions" [ "TX_ACCESS_LIST_ADDRESS_COST"; "TX_ACCESS_LIST_STORAGE_KEY_COST"; "TX_BASE_COST"; "TX_CREATE_COST"; "TX_DATA_COST_PER_NON_ZERO"; "TX_DATA_COST_PER_ZERO"; "AccessListTransaction"; "FeeMarketTransaction"; "LegacyTransaction"; "Transaction"; "decode_transaction"; "encode_transaction" ]. + +Axiom ethereum_gray_glacier_trie_imports : + AreImported globals "ethereum.gray_glacier.trie" [ "Trie"; "root"; "trie_set" ]. + +Axiom ethereum_gray_glacier_utils_message_imports : + AreImported globals "ethereum.gray_glacier.utils.message" [ "prepare_message" ]. + +Axiom ethereum_gray_glacier_vm_interpreter_imports : + AreImported globals "ethereum.gray_glacier.vm.interpreter" [ "process_message_call" ]. Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -292,7 +199,12 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := Hashes of the recent 256 blocks in order of increasing block number. " in let recent_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) in + M.slice (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| Constant.int 255 |), + Constant.None_, + Constant.None_ + |) in let _ := (* if *) M.if_then_else (| @@ -318,17 +230,26 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := )) |) in let recent_block_hashes := make_list [] in - For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_blocks" |) do - let prev_block_hash := - M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "block" |), + M.get_name (| globals, "recent_blocks" |), + ltac:(M.monadic ( + let prev_block_hash := + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in + let _ := M.call (| M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), make_list [ M.get_name (| globals, "prev_block_hash" |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let most_recent_block_hash := M.call (| M.get_name (| globals, "keccak256" |), @@ -336,7 +257,10 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), make_list [ - M.get_field (| M.get_subscript (| M.get_name (| globals, "recent_blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) + M.get_field (| M.get_subscript (| + M.get_name (| globals, "recent_blocks" |), + UnOp.sub (| Constant.int 1 |) + |), "header" |) ], make_dict [] |) @@ -380,7 +304,10 @@ Definition state_transition : Value.t -> Value.t -> M := Block to apply to `chain`. " in let parent_header := - M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) in + M.get_field (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| Constant.int 1 |) + |), "header" |) in let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ @@ -501,7 +428,12 @@ Definition state_transition : Value.t -> Value.t -> M := ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) + M.slice (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| Constant.int 255 |), + Constant.None_, + Constant.None_ + |) |) in M.pure Constant.None_ (* else *) @@ -1223,21 +1155,25 @@ Definition apply_body : Value.t -> Value.t -> M := (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) - For make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "tx" |) ] in M.call (| - M.get_name (| globals, "enumerate" |), - make_list [ - M.call (| - M.get_name (| globals, "map" |), - make_list [ - M.get_name (| globals, "decode_transaction" |); - M.get_name (| globals, "transactions" |) - ], - make_dict [] - |) - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "tx" |) ], + M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.call (| + M.get_name (| globals, "map" |), + make_list [ + M.get_name (| globals, "decode_transaction" |); + M.get_name (| globals, "transactions" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ M.get_name (| globals, "transactions_trie" |); @@ -1264,54 +1200,54 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.assign (| - make_tuple [ M.get_name (| globals, "sender_address" |); M.get_name (| globals, "effective_gas_price" |) ], - M.call (| - M.get_name (| globals, "check_transaction" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "base_fee_per_gas" |); - M.get_name (| globals, "gas_available" |); - M.get_name (| globals, "chain_id" |) - ], - make_dict [] - |) - |) in - let env := - M.call (| - M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), - make_list [], - make_dict [] - |) in - let _ := M.assign (| - make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |); M.get_name (| globals, "error" |) ], - M.call (| - M.get_name (| globals, "process_transaction" |), - make_list [ - M.get_name (| globals, "env" |); - M.get_name (| globals, "tx" |) - ], - make_dict [] - |) - |) in - let gas_available := BinOp.sub - M.get_name (| globals, "gas_used" |) - M.get_name (| globals, "gas_used" |) in - let receipt := - M.call (| - M.get_name (| globals, "make_receipt" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "error" |); - BinOp.sub (| - M.get_name (| globals, "block_gas_limit" |), - M.get_name (| globals, "gas_available" |) - |); - M.get_name (| globals, "logs" |) - ], - make_dict [] - |) in - let _ := M.call (| + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "sender_address" |); M.get_name (| globals, "effective_gas_price" |) ], + M.call (| + M.get_name (| globals, "check_transaction" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "base_fee_per_gas" |); + M.get_name (| globals, "gas_available" |); + M.get_name (| globals, "chain_id" |) + ], + make_dict [] + |) + |) in + let env := + M.call (| + M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |); M.get_name (| globals, "error" |) ], + M.call (| + M.get_name (| globals, "process_transaction" |), + make_list [ + M.get_name (| globals, "env" |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) in + let gas_available := BinOp.sub + M.get_name (| globals, "gas_used" |) + M.get_name (| globals, "gas_used" |) in + let receipt := + M.call (| + M.get_name (| globals, "make_receipt" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "error" |); + BinOp.sub (| + M.get_name (| globals, "block_gas_limit" |), + M.get_name (| globals, "gas_available" |) + |); + M.get_name (| globals, "logs" |) + ], + make_dict [] + |) in + let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ M.get_name (| globals, "receipts_trie" |); @@ -1332,10 +1268,15 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_logs := BinOp.add - M.get_name (| globals, "logs" |) - M.get_name (| globals, "logs" |) in - EndFor. + let block_logs := BinOp.add + M.get_name (| globals, "logs" |) + M.get_name (| globals, "logs" |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.call (| M.get_name (| globals, "pay_rewards" |), make_list [ @@ -1464,8 +1405,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "ommer" |), + M.get_name (| globals, "ommers" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ BoolOp.and (| @@ -1484,15 +1429,18 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_parent_header := - M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), BinOp.sub (| - UnOp.sub (| BinOp.sub (| - M.get_field (| M.get_name (| globals, "block_header" |), "number" |), - M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) |), - Constant.int 1 - |) |), "header" |) in - let _ := M.call (| + let ommer_parent_header := + M.get_field (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + BinOp.sub (| + UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) |), + Constant.int 1 + |) + |), "header" |) in + let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ M.get_name (| globals, "ommer" |); @@ -1500,7 +1448,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1550,33 +1503,54 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let recent_canonical_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| BinOp.add (| - M.get_name (| globals, "MAX_OMMER_DEPTH" |), - Constant.int 1 - |) |), Constant.None_ |) |) in + M.slice (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| BinOp.add (| + M.get_name (| globals, "MAX_OMMER_DEPTH" |), + Constant.int 1 + |) |), + Constant.None_, + Constant.None_ + |) in let recent_canonical_block_hashes := Constant.str "(* At expr: unsupported node type: SetComp *)" in (* At stmt: unsupported node type: AnnAssign *) - For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_canonical_blocks" |) do - let recent_ommers_hashes := + let _ := + M.for_ (| + M.get_name (| globals, "block" |), + M.get_name (| globals, "recent_canonical_blocks" |), + ltac:(M.monadic ( + let recent_ommers_hashes := + M.call (| + M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), + make_list [ + Constant.str "(* At expr: unsupported node type: SetComp *)" + ], + make_dict [] + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "ommer_index" |); M.get_name (| globals, "ommer" |) ], M.call (| - M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), - make_list [ - Constant.str "(* At expr: unsupported node type: SetComp *)" - ], - make_dict [] - |) in - EndFor. - For make_tuple [ M.get_name (| globals, "ommer_index" |); M.get_name (| globals, "ommer" |) ] in M.call (| - M.get_name (| globals, "enumerate" |), - make_list [ - M.get_name (| globals, "ommers" |) - ], - make_dict [] - |) do - let ommer_hash := - M.get_subscript (| M.get_name (| globals, "ommers_hashes" |), M.get_name (| globals, "ommer_index" |) |) in - let _ := M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let ommer_hash := + M.get_subscript (| + M.get_name (| globals, "ommers_hashes" |), + M.get_name (| globals, "ommer_index" |) + |) in + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_eq (| @@ -1587,7 +1561,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_in (| @@ -1598,7 +1572,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_in (| @@ -1609,12 +1583,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_age := - BinOp.sub (| - M.get_field (| M.get_name (| globals, "block_header" |), "number" |), - M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) in - let _ := M.call (| + let ommer_age := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) in + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ BoolOp.and (| @@ -1633,10 +1607,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.in (| + Compare.in_ (| M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), M.get_name (| globals, "recent_canonical_block_hashes" |) |); @@ -1644,7 +1618,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_eq (| @@ -1655,7 +1629,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_)). Definition pay_rewards : Value.t -> Value.t -> M := @@ -1712,30 +1691,34 @@ Definition pay_rewards : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do - let ommer_age := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - BinOp.sub (| - M.get_name (| globals, "block_number" |), - M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) - ], - make_dict [] - |) in - let ommer_miner_reward := - BinOp.floor_div (| - BinOp.mult (| - BinOp.sub (| - Constant.int 8, - M.get_name (| globals, "ommer_age" |) - |), - M.get_name (| globals, "BLOCK_REWARD" |) - |), - Constant.int 8 - |) in - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "ommer" |), + M.get_name (| globals, "ommers" |), + ltac:(M.monadic ( + let ommer_age := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "block_number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) + ], + make_dict [] + |) in + let ommer_miner_reward := + BinOp.floor_div (| + BinOp.mult (| + BinOp.sub (| + Constant.int 8, + M.get_name (| globals, "ommer_age" |) + |), + M.get_name (| globals, "BLOCK_REWARD" |) + |), + Constant.int 8 + |) in + let _ := M.call (| M.get_name (| globals, "create_ether" |), make_list [ M.get_name (| globals, "state" |); @@ -1744,7 +1727,12 @@ Definition pay_rewards : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_)). Definition process_transaction : Value.t -> Value.t -> M := @@ -1932,24 +1920,42 @@ Definition process_transaction : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - For make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "keys" |) ] in M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) do - let _ := M.call (| + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "keys" |) ], + M.get_field (| M.get_name (| globals, "tx" |), "access_list" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "preaccessed_addresses" |), "add" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] |) in - For M.get_name (| globals, "key" |) in M.get_name (| globals, "keys" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "keys" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "preaccessed_storage_keys" |), "add" |), make_list [ make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "key" |) ] ], make_dict [] |) in - EndFor. - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -2105,8 +2111,12 @@ Definition process_transaction : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "accounts_to_delete" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "output" |), "accounts_to_delete" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "destroy_account" |), make_list [ M.get_field (| M.get_name (| globals, "env" |), "state" |); @@ -2114,22 +2124,31 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. - For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "touched_accounts" |) do - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), - (* then *) + M.pure Constant.None_ + )), ltac:(M.monadic ( - let _ := M.call (| + M.pure Constant.None_ + )) + |) in + let _ := + M.for_ (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "output" |), "touched_accounts" |), + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "destroy_account" |), make_list [ M.get_field (| M.get_name (| globals, "env" |), "state" |); @@ -2137,12 +2156,17 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := M.return_ (| make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |); M.get_field (| M.get_name (| globals, "output" |), "error" |) ] |) in @@ -2230,28 +2254,37 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := " in let data_cost := Constant.int 0 in - For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "byte" |), - Constant.int 0 - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "byte" |), + M.get_field (| M.get_name (| globals, "tx" |), "data" |), ltac:(M.monadic ( - let data_cost := BinOp.add - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "byte" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let data_cost := BinOp.add - M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := (* if *) M.if_then_else (| @@ -2291,12 +2324,16 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - For make_tuple [ M.get_name (| globals, "_address" |); M.get_name (| globals, "keys" |) ] in M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) do - let access_list_cost := BinOp.add - M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) - M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) in - let access_list_cost := BinOp.add - BinOp.mult (| + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "_address" |); M.get_name (| globals, "keys" |) ], + M.get_field (| M.get_name (| globals, "tx" |), "access_list" |), + ltac:(M.monadic ( + let access_list_cost := BinOp.add + M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) + M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) in + let access_list_cost := BinOp.add + BinOp.mult (| M.call (| M.get_name (| globals, "len" |), make_list [ @@ -2306,7 +2343,7 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) |) - BinOp.mult (| + BinOp.mult (| M.call (| M.get_name (| globals, "len" |), make_list [ @@ -2316,7 +2353,12 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -2605,13 +2647,18 @@ Definition recover_sender : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "Address" |), make_list [ - M.get_subscript (| M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "public_key" |) - ], - make_dict [] - |), M.slice (| Constant.int 12, Constant.int 32 |) |) + M.slice (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), + Constant.int 12, + Constant.int 32, + Constant.None_ + |) ], make_dict [] |) diff --git a/CoqOfPython/ethereum/gray_glacier/fork_types.v b/CoqOfPython/ethereum/gray_glacier/fork_types.v index cc8e4a1..374e9c6 100644 --- a/CoqOfPython/ethereum/gray_glacier/fork_types.v +++ b/CoqOfPython/ethereum/gray_glacier/fork_types.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.gray_glacier.fork_types". Definition expr_1 : Value.t := Constant.str " @@ -17,33 +17,17 @@ Introduction Types re-used throughout the specification, which are specific to Ethereum. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes20 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes20". -Axiom ethereum_base_types_Bytes256 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes20"; "Bytes256"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) diff --git a/CoqOfPython/ethereum/gray_glacier/state.v b/CoqOfPython/ethereum/gray_glacier/state.v index 8dc2148..6e039ed 100644 --- a/CoqOfPython/ethereum/gray_glacier/state.v +++ b/CoqOfPython/ethereum/gray_glacier/state.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.gray_glacier.state". Definition expr_1 : Value.t := Constant.str " @@ -22,63 +22,23 @@ There is a distinction between an account that does not exist and `EMPTY_ACCOUNT`. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". -Axiom dataclasses_field : - IsGlobalAlias globals dataclasses.globals "field". - -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_modify : - IsGlobalAlias globals ethereum.base_types.globals "modify". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.gray_glacier.fork_types. -Axiom ethereum_gray_glacier_fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "EMPTY_ACCOUNT". -Axiom ethereum_gray_glacier_fork_types_Account : - IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "Account". -Axiom ethereum_gray_glacier_fork_types_Address : - IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "Address". -Axiom ethereum_gray_glacier_fork_types_Root : - IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "Root". - -Require ethereum.gray_glacier.trie. -Axiom ethereum_gray_glacier_trie_EMPTY_TRIE_ROOT : - IsGlobalAlias globals ethereum.gray_glacier.trie.globals "EMPTY_TRIE_ROOT". -Axiom ethereum_gray_glacier_trie_Trie : - IsGlobalAlias globals ethereum.gray_glacier.trie.globals "Trie". -Axiom ethereum_gray_glacier_trie_copy_trie : - IsGlobalAlias globals ethereum.gray_glacier.trie.globals "copy_trie". -Axiom ethereum_gray_glacier_trie_root : - IsGlobalAlias globals ethereum.gray_glacier.trie.globals "root". -Axiom ethereum_gray_glacier_trie_trie_get : - IsGlobalAlias globals ethereum.gray_glacier.trie.globals "trie_get". -Axiom ethereum_gray_glacier_trie_trie_set : - IsGlobalAlias globals ethereum.gray_glacier.trie.globals "trie_set". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass"; "field" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict"; "List"; "Optional"; "Set"; "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "modify" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_gray_glacier_fork_types_imports : + AreImported globals "ethereum.gray_glacier.fork_types" [ "EMPTY_ACCOUNT"; "Account"; "Address"; "Root" ]. + +Axiom ethereum_gray_glacier_trie_imports : + AreImported globals "ethereum.gray_glacier.trie" [ "EMPTY_TRIE_ROOT"; "Trie"; "copy_trie"; "root"; "trie_get"; "trie_set" ]. Definition State : Value.t := builtins.make_klass @@ -373,13 +333,16 @@ Definition destroy_storage : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -542,7 +505,10 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), + M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |), M.get_name (| globals, "trie" |) |) in M.pure Constant.None_ @@ -568,7 +534,10 @@ Definition set_storage : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -598,7 +567,7 @@ Definition storage_root : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), @@ -608,7 +577,10 @@ Definition storage_root : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "root" |), make_list [ - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) + M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |) ], make_dict [] |) @@ -1167,7 +1139,7 @@ Definition get_storage_original : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |) |), @@ -1189,7 +1161,10 @@ Definition get_storage_original : Value.t -> Value.t -> M := )) |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "_" |); M.get_name (| globals, "original_trie" |) ], - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), Constant.int 0 |) + M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), + Constant.int 0 + |) |) in let original_account_trie := M.call (| diff --git a/CoqOfPython/ethereum/gray_glacier/transactions.v b/CoqOfPython/ethereum/gray_glacier/transactions.v index 6057c15..da20fcd 100644 --- a/CoqOfPython/ethereum/gray_glacier/transactions.v +++ b/CoqOfPython/ethereum/gray_glacier/transactions.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.gray_glacier.transactions". Definition expr_1 : Value.t := Constant.str " @@ -9,43 +9,23 @@ submitted to be executed. If Ethereum is viewed as a state machine, transactions are the events that move between states. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. -Require typing. -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". +Axiom typing_imports : + AreImported globals "typing" [ "Tuple"; "Union" ]. -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U64 : - IsGlobalAlias globals ethereum.base_types.globals "U64". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U64"; "U256"; "Bytes"; "Bytes0"; "Bytes32"; "Uint"; "slotted_freezable" ]. -Require ethereum.exceptions. -Axiom ethereum_exceptions_InvalidBlock : - IsGlobalAlias globals ethereum.exceptions.globals "InvalidBlock". +Axiom ethereum_exceptions_imports : + AreImported globals "ethereum.exceptions" [ "InvalidBlock" ]. -Require ethereum.gray_glacier.fork_types. -Axiom ethereum_gray_glacier_fork_types_Address : - IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "Address". +Axiom ethereum_gray_glacier_fork_types_imports : + AreImported globals "ethereum.gray_glacier.fork_types" [ "Address" ]. Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( Constant.int 21000 @@ -102,7 +82,10 @@ Definition FeeMarketTransaction : Value.t := ]. Definition Transaction : Value.t := M.run ltac:(M.monadic ( - M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "AccessListTransaction" |); M.get_name (| globals, "FeeMarketTransaction" |) ] |) + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "AccessListTransaction" |); M.get_name (| globals, "FeeMarketTransaction" |) ] + |) )). Definition encode_transaction : Value.t -> Value.t -> M := @@ -186,7 +169,7 @@ Definition encode_transaction : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "Exception" |), make_list [ Constant.str "(* At expr: unsupported node type: JoinedStr *)" @@ -224,7 +207,10 @@ Definition decode_transaction : Value.t -> Value.t -> M := (* if *) M.if_then_else (| Compare.eq (| - M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), + M.get_subscript (| + M.get_name (| globals, "tx" |), + Constant.int 0 + |), Constant.int 1 |), (* then *) @@ -234,7 +220,12 @@ Definition decode_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), make_list [ M.get_name (| globals, "AccessListTransaction" |); - M.get_subscript (| M.get_name (| globals, "tx" |), M.slice (| Constant.int 1, Constant.None_ |) |) + M.slice (| + M.get_name (| globals, "tx" |), + Constant.int 1, + Constant.None_, + Constant.None_ + |) ], make_dict [] |) @@ -246,7 +237,10 @@ Definition decode_transaction : Value.t -> Value.t -> M := (* if *) M.if_then_else (| Compare.eq (| - M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), + M.get_subscript (| + M.get_name (| globals, "tx" |), + Constant.int 0 + |), Constant.int 2 |), (* then *) @@ -256,7 +250,12 @@ Definition decode_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), make_list [ M.get_name (| globals, "FeeMarketTransaction" |); - M.get_subscript (| M.get_name (| globals, "tx" |), M.slice (| Constant.int 1, Constant.None_ |) |) + M.slice (| + M.get_name (| globals, "tx" |), + Constant.int 1, + Constant.None_, + Constant.None_ + |) ], make_dict [] |) @@ -264,7 +263,7 @@ Definition decode_transaction : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidBlock" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "InvalidBlock" |)) |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/gray_glacier/trie.v b/CoqOfPython/ethereum/gray_glacier/trie.v index abd999e..50d2c44 100644 --- a/CoqOfPython/ethereum/gray_glacier/trie.v +++ b/CoqOfPython/ethereum/gray_glacier/trie.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.gray_glacier.trie". Definition expr_1 : Value.t := Constant.str " @@ -20,83 +20,38 @@ The state trie is the structure responsible for storing (* At top_level_stmt: unsupported node type: Import *) -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". -Axiom dataclasses_field : - IsGlobalAlias globals dataclasses.globals "field". - -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". -Axiom typing_Generic : - IsGlobalAlias globals typing.globals "Generic". -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Mapping : - IsGlobalAlias globals typing.globals "Mapping". -Axiom typing_MutableMapping : - IsGlobalAlias globals typing.globals "MutableMapping". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Sequence : - IsGlobalAlias globals typing.globals "Sequence". -Axiom typing_TypeVar : - IsGlobalAlias globals typing.globals "TypeVar". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". -Axiom typing_cast : - IsGlobalAlias globals typing.globals "cast". - -Require ethereum.arrow_glacier.__init__. -Axiom ethereum_arrow_glacier___init___trie : - IsGlobalAlias globals ethereum.arrow_glacier.__init__.globals "trie". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.utils.hexadecimal. -Axiom ethereum_utils_hexadecimal_hex_to_bytes : - IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.gray_glacier.blocks. -Axiom ethereum_gray_glacier_blocks_Receipt : - IsGlobalAlias globals ethereum.gray_glacier.blocks.globals "Receipt". - -Require ethereum.gray_glacier.fork_types. -Axiom ethereum_gray_glacier_fork_types_Account : - IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "Account". -Axiom ethereum_gray_glacier_fork_types_Address : - IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "Address". -Axiom ethereum_gray_glacier_fork_types_Root : - IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "Root". -Axiom ethereum_gray_glacier_fork_types_encode_account : - IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "encode_account". - -Require ethereum.gray_glacier.transactions. -Axiom ethereum_gray_glacier_transactions_LegacyTransaction : - IsGlobalAlias globals ethereum.gray_glacier.transactions.globals "LegacyTransaction". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass"; "field" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict"; "Generic"; "List"; "Mapping"; "MutableMapping"; "Optional"; "Sequence"; "TypeVar"; "Union"; "cast" ]. + +Axiom ethereum_arrow_glacier_imports : + AreImported globals "ethereum.arrow_glacier" [ "trie" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_utils_hexadecimal_imports : + AreImported globals "ethereum.utils.hexadecimal" [ "hex_to_bytes" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_gray_glacier_blocks_imports : + AreImported globals "ethereum.gray_glacier.blocks" [ "Receipt" ]. + +Axiom ethereum_gray_glacier_fork_types_imports : + AreImported globals "ethereum.gray_glacier.fork_types" [ "Account"; "Address"; "Root"; "encode_account" ]. + +Axiom ethereum_gray_glacier_transactions_imports : + AreImported globals "ethereum.gray_glacier.transactions" [ "LegacyTransaction" ]. Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -115,7 +70,10 @@ Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( )). Definition Node : Value.t := M.run ltac:(M.monadic ( - M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Bytes" |); M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |); Constant.None_ ] |) + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Bytes" |); M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |); Constant.None_ ] + |) )). Definition K : Value.t := M.run ltac:(M.monadic ( @@ -133,11 +91,29 @@ Definition V : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "TypeVar" |), make_list [ Constant.str "V"; - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Account" |) |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Bytes" |) |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Account" |) + |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Bytes" |) + |); M.get_name (| globals, "Bytes" |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Bytes" |) ] |) |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Bytes" |) ] |) |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Bytes" |) ] + |) + |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Bytes" |) ] + |) + |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |) ], @@ -176,7 +152,10 @@ Definition BranchNode : Value.t := ]. Definition InternalNode : Value.t := M.run ltac:(M.monadic ( - M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LeafNode" |); M.get_name (| globals, "ExtensionNode" |); M.get_name (| globals, "BranchNode" |) ] |) + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "LeafNode" |); M.get_name (| globals, "ExtensionNode" |); M.get_name (| globals, "BranchNode" |) ] + |) )). Definition encode_internal_node : Value.t -> Value.t -> M := @@ -288,7 +267,7 @@ Definition encode_internal_node : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "(* At expr: unsupported node type: JoinedStr *)" @@ -528,13 +507,16 @@ Definition trie_set : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "key" |), M.get_field (| M.get_name (| globals, "trie" |), "_data" |) |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + M.get_name (| globals, "key" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -544,7 +526,10 @@ Definition trie_set : Value.t -> Value.t -> M := (* else *) )), ltac:(M.monadic ( let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), + M.get_subscript (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + M.get_name (| globals, "key" |) + |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_ @@ -589,51 +574,66 @@ Definition common_prefix_length : Value.t -> Value.t -> M := let _ := Constant.str " Find the longest common prefix of two sequences. " in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "a" |) - ], - make_dict [] - |) - ], - make_dict [] - |) do - let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| - M.get_name (| globals, "i" |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "b" |) - ], - make_dict [] - |) - |), - ltac:(M.monadic ( - Compare.not_eq (| - M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), - M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) - |) - )) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + ], + make_dict [] + |), ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "i" |) - |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_subscript (| + M.get_name (| globals, "a" |), + M.get_name (| globals, "i" |) + |), + M.get_subscript (| + M.get_name (| globals, "b" |), + M.get_name (| globals, "i" |) + |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "len" |), @@ -718,38 +718,53 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 0; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |); - Constant.int 2 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ BinOp.add (| BinOp.mult (| Constant.int 16, - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "i" |) + |) |), - M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) + |) |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -767,43 +782,61 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := Constant.int 1 |) |), - M.get_subscript (| M.get_name (| globals, "x" |), Constant.int 0 |) + M.get_subscript (| + M.get_name (| globals, "x" |), + Constant.int 0 + |) |) ], make_dict [] |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 1; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |); - Constant.int 2 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 1; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ BinOp.add (| BinOp.mult (| Constant.int 16, - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "i" |) + |) |), - M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) + |) |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -850,40 +883,55 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := ], make_dict [] |) in - For make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ] in M.call (| - M.get_name (| globals, "enumerate" |), - make_list [ - M.get_name (| globals, "bytes_" |) - ], - make_dict [] - |) do - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.mult (| - M.get_name (| globals, "byte_index" |), - Constant.int 2 - |) |), - BinOp.r_shift (| - BinOp.bit_and (| - M.get_name (| globals, "byte" |), - Constant.int 240 - |), - Constant.int 4 - |) - |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "byte_index" |), - Constant.int 2 - |), - Constant.int 1 - |) |), - BinOp.bit_and (| - M.get_name (| globals, "byte" |), - Constant.int 15 - |) - |) in - EndFor. + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ], + M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "bytes_" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "nibble_list" |), + BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |) + |), + BinOp.r_shift (| + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 240 + |), + Constant.int 4 + |) + |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "nibble_list" |), + BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |), + Constant.int 1 + |) + |), + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 15 + |) + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Bytes" |), @@ -916,65 +964,69 @@ Definition _prepare_trie : Value.t -> Value.t -> M := Object with keys mapped to nibble-byte form. " in (* At stmt: unsupported node type: AnnAssign *) - For make_tuple [ M.get_name (| globals, "preimage" |); M.get_name (| globals, "value" |) ] in M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "items" |), - make_list [], - make_dict [] - |) do - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "value" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "preimage" |); M.get_name (| globals, "value" |) ], + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "items" |), + make_list [], + make_dict [] + |), ltac:(M.monadic ( - let _ := M.assert (| Compare.is_not (| + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in - let address := - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in - let encoded_value := - M.call (| - M.get_name (| globals, "encode_node" |), - make_list [ - M.get_name (| globals, "value" |); + let address := M.call (| - M.get_name (| globals, "get_storage_root" |), + M.get_name (| globals, "Address" |), make_list [ - M.get_name (| globals, "address" |) + M.get_name (| globals, "preimage" |) ], make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let encoded_value := - M.call (| - M.get_name (| globals, "encode_node" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - )) |) in - let _ := M.call (| + |) in + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |); + M.call (| + M.get_name (| globals, "get_storage_root" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_eq (| @@ -986,38 +1038,46 @@ Definition _prepare_trie : Value.t -> Value.t -> M := make_dict [] |) in (* At stmt: unsupported node type: AnnAssign *) - let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "trie" |), "secured" |), - (* then *) - ltac:(M.monadic ( - let key := - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "trie" |), "secured" |), + (* then *) + ltac:(M.monadic ( + let key := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let key := + M.get_name (| globals, "preimage" |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "mapped" |), + M.call (| + M.get_name (| globals, "bytes_to_nibble_list" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |) + |), + M.get_name (| globals, "encoded_value" |) + |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let key := - M.get_name (| globals, "preimage" |) in + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "mapped" |), M.call (| - M.get_name (| globals, "bytes_to_nibble_list" |), - make_list [ - M.get_name (| globals, "key" |) - ], - make_dict [] - |) |), - M.get_name (| globals, "encoded_value" |) - |) in - EndFor. + )) + |) in let _ := M.return_ (| M.get_name (| globals, "mapped" |) |) in @@ -1210,8 +1270,16 @@ Definition patricialize : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "LeafNode" |), make_list [ - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |); - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) + M.slice (| + M.get_name (| globals, "arbitrary_key" |), + M.get_name (| globals, "level" |), + Constant.None_, + Constant.None_ + |); + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "arbitrary_key" |) + |) ], make_dict [] |) in @@ -1224,7 +1292,12 @@ Definition patricialize : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in let substring := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "arbitrary_key" |), + M.get_name (| globals, "level" |), + Constant.None_, + Constant.None_ + |) in let prefix_length := M.call (| M.get_name (| globals, "len" |), @@ -1233,39 +1306,53 @@ Definition patricialize : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do - let prefix_length := - M.call (| - M.get_name (| globals, "min" |), - make_list [ - M.get_name (| globals, "prefix_length" |); + let _ := + M.for_ (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "obj" |), + ltac:(M.monadic ( + let prefix_length := M.call (| - M.get_name (| globals, "common_prefix_length" |), + M.get_name (| globals, "min" |), make_list [ - M.get_name (| globals, "substring" |); - M.get_subscript (| M.get_name (| globals, "key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) + M.get_name (| globals, "prefix_length" |); + M.call (| + M.get_name (| globals, "common_prefix_length" |), + make_list [ + M.get_name (| globals, "substring" |); + M.slice (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "level" |), + Constant.None_, + Constant.None_ + |) + ], + make_dict [] + |) ], make_dict [] - |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "prefix_length" |), - Constant.int 0 - |), - (* then *) - ltac:(M.monadic ( - let _ := M.break (| |) in + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "prefix_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := (* if *) M.if_then_else (| @@ -1276,10 +1363,15 @@ Definition patricialize : Value.t -> Value.t -> M := (* then *) ltac:(M.monadic ( let prefix := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), BinOp.add (| + M.slice (| + M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |), - M.get_name (| globals, "prefix_length" |) - |) |) |) in + BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |), + Constant.None_ + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ExtensionNode" |), @@ -1312,70 +1404,106 @@ Definition patricialize : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) - For M.get_name (| globals, "_" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 16 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "_" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 16 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "branches" |), "append" |), make_list [ {} ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let value := Constant.bytes "" in - For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "key" |) - ], - make_dict [] - |), - M.get_name (| globals, "level" |) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "obj" |), ltac:(M.monadic ( let _ := (* if *) M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); - make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] - ], - make_dict [] + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |), + M.get_name (| globals, "level" |) |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "AssertionError" |)) |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "key" |) + |); + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "AssertionError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "key" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| + M.get_subscript (| + M.get_name (| globals, "branches" |), + M.get_subscript (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "level" |) + |) + |), + M.get_name (| globals, "key" |) + |), + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "key" |) + |) + |) in M.pure Constant.None_ )) |) in - let value := - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.assign (| - M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) - |) in + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "BranchNode" |), diff --git a/CoqOfPython/ethereum/gray_glacier/utils/__init__.v b/CoqOfPython/ethereum/gray_glacier/utils/__init__.v index 1baedea..180ce26 100644 --- a/CoqOfPython/ethereum/gray_glacier/utils/__init__.v +++ b/CoqOfPython/ethereum/gray_glacier/utils/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.gray_glacier.utils.__init__". Definition expr_1 : Value.t := Constant.str " diff --git a/CoqOfPython/ethereum/gray_glacier/utils/address.v b/CoqOfPython/ethereum/gray_glacier/utils/address.v index c9d4f44..9313e03 100644 --- a/CoqOfPython/ethereum/gray_glacier/utils/address.v +++ b/CoqOfPython/ethereum/gray_glacier/utils/address.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.gray_glacier.utils.address". Definition expr_1 : Value.t := Constant.str " @@ -18,33 +18,23 @@ Address specific functions used in this gray_glacier version of specification. ". -Require typing. -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". +Axiom typing_imports : + AreImported globals "typing" [ "Union" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes32"; "Uint" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_left_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. -Require ethereum.gray_glacier.fork_types. -Axiom ethereum_gray_glacier_fork_types_Address : - IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "Address". +Axiom ethereum_gray_glacier_fork_types_imports : + AreImported globals "ethereum.gray_glacier.fork_types" [ "Address" ]. Definition to_address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -66,11 +56,16 @@ Definition to_address : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "Address" |), make_list [ - M.get_subscript (| M.call (| - M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), - make_list [], - make_dict [] - |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) + M.slice (| + M.call (| + M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), + UnOp.sub (| Constant.int 20 |), + Constant.None_, + Constant.None_ + |) ], make_dict [] |) @@ -114,7 +109,12 @@ Definition compute_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "computed_address" |), + UnOp.sub (| Constant.int 20 |), + Constant.None_, + Constant.None_ + |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -182,7 +182,12 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "computed_address" |), + UnOp.sub (| Constant.int 20 |), + Constant.None_, + Constant.None_ + |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/gray_glacier/utils/hexadecimal.v b/CoqOfPython/ethereum/gray_glacier/utils/hexadecimal.v index 09a3916..b51bb59 100644 --- a/CoqOfPython/ethereum/gray_glacier/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/gray_glacier/utils/hexadecimal.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.gray_glacier.utils.hexadecimal". Definition expr_1 : Value.t := Constant.str " @@ -18,17 +18,11 @@ Hexadecimal utility functions used in this specification, specific to Gray Glacier types. ". -Require ethereum.utils.hexadecimal. -Axiom ethereum_utils_hexadecimal_remove_hex_prefix : - IsGlobalAlias globals ethereum.utils.hexadecimal.globals "remove_hex_prefix". - -Require ethereum.gray_glacier.fork_types. -Axiom ethereum_gray_glacier_fork_types_Address : - IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "Address". -Axiom ethereum_gray_glacier_fork_types_Bloom : - IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "Bloom". -Axiom ethereum_gray_glacier_fork_types_Root : - IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "Root". +Axiom ethereum_utils_hexadecimal_imports : + AreImported globals "ethereum.utils.hexadecimal" [ "remove_hex_prefix" ]. + +Axiom ethereum_gray_glacier_fork_types_imports : + AreImported globals "ethereum.gray_glacier.fork_types" [ "Address"; "Bloom"; "Root" ]. Definition hex_to_root : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/gray_glacier/utils/message.v b/CoqOfPython/ethereum/gray_glacier/utils/message.v index 3775172..b44a695 100644 --- a/CoqOfPython/ethereum/gray_glacier/utils/message.v +++ b/CoqOfPython/ethereum/gray_glacier/utils/message.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.gray_glacier.utils.message". Definition expr_1 : Value.t := Constant.str " @@ -18,49 +18,26 @@ Message specific functions used in this gray_glacier version of specification. ". -Require typing. -Axiom typing_FrozenSet : - IsGlobalAlias globals typing.globals "FrozenSet". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". +Axiom typing_imports : + AreImported globals "typing" [ "FrozenSet"; "Optional"; "Tuple"; "Union" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Bytes32"; "Uint" ]. -Require ethereum.gray_glacier.fork_types. -Axiom ethereum_gray_glacier_fork_types_Address : - IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "Address". +Axiom ethereum_gray_glacier_fork_types_imports : + AreImported globals "ethereum.gray_glacier.fork_types" [ "Address" ]. -Require ethereum.gray_glacier.state. -Axiom ethereum_gray_glacier_state_get_account : - IsGlobalAlias globals ethereum.gray_glacier.state.globals "get_account". +Axiom ethereum_gray_glacier_state_imports : + AreImported globals "ethereum.gray_glacier.state" [ "get_account" ]. -Require ethereum.gray_glacier.vm.__init__. -Axiom ethereum_gray_glacier_vm___init___Environment : - IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Environment". -Axiom ethereum_gray_glacier_vm___init___Message : - IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Message". +Axiom ethereum_gray_glacier_vm_imports : + AreImported globals "ethereum.gray_glacier.vm" [ "Environment"; "Message" ]. -Require ethereum.gray_glacier.vm.precompiled_contracts.mapping. -Axiom ethereum_gray_glacier_vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : - IsGlobalAlias globals ethereum.gray_glacier.vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". +Axiom ethereum_gray_glacier_vm_precompiled_contracts_mapping_imports : + AreImported globals "ethereum.gray_glacier.vm.precompiled_contracts.mapping" [ "PRE_COMPILED_CONTRACTS" ]. -Require ethereum.gray_glacier.utils.address. -Axiom ethereum_gray_glacier_utils_address_compute_contract_address : - IsGlobalAlias globals ethereum.gray_glacier.utils.address.globals "compute_contract_address". +Axiom ethereum_gray_glacier_utils_address_imports : + AreImported globals "ethereum.gray_glacier.utils.address" [ "compute_contract_address" ]. Definition prepare_message : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -198,7 +175,7 @@ Definition prepare_message : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "Target must be address or empty bytes" diff --git a/CoqOfPython/ethereum/gray_glacier/vm/__init__.v b/CoqOfPython/ethereum/gray_glacier/vm/__init__.v index 2aa9a09..376d1ca 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/__init__.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.gray_glacier.vm.__init__". Definition expr_1 : Value.t := Constant.str " @@ -18,57 +18,29 @@ The abstract computer which runs the code stored in an `.fork_types.Account`. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple"; "Union" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U64 : - IsGlobalAlias globals ethereum.base_types.globals "U64". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U64"; "U256"; "Bytes"; "Bytes0"; "Bytes32"; "Uint" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. -Require ethereum.gray_glacier.blocks. -Axiom ethereum_gray_glacier_blocks_Log : - IsGlobalAlias globals ethereum.gray_glacier.blocks.globals "Log". +Axiom ethereum_gray_glacier_blocks_imports : + AreImported globals "ethereum.gray_glacier.blocks" [ "Log" ]. -Require ethereum.gray_glacier.fork_types. -Axiom ethereum_gray_glacier_fork_types_Address : - IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "Address". +Axiom ethereum_gray_glacier_fork_types_imports : + AreImported globals "ethereum.gray_glacier.fork_types" [ "Address" ]. -Require ethereum.gray_glacier.state. -Axiom ethereum_gray_glacier_state_State : - IsGlobalAlias globals ethereum.gray_glacier.state.globals "State". -Axiom ethereum_gray_glacier_state_account_exists_and_is_empty : - IsGlobalAlias globals ethereum.gray_glacier.state.globals "account_exists_and_is_empty". +Axiom ethereum_gray_glacier_state_imports : + AreImported globals "ethereum.gray_glacier.state" [ "State"; "account_exists_and_is_empty" ]. -Require ethereum.gray_glacier.vm.precompiled_contracts.__init__. -Axiom ethereum_gray_glacier_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : - IsGlobalAlias globals ethereum.gray_glacier.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". +Axiom ethereum_gray_glacier_vm_precompiled_contracts_imports : + AreImported globals "ethereum.gray_glacier.vm.precompiled_contracts" [ "RIPEMD160_ADDRESS" ]. Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] @@ -203,7 +175,7 @@ Definition incorporate_child_on_error : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "RIPEMD160_ADDRESS" |), M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) |), diff --git a/CoqOfPython/ethereum/gray_glacier/vm/exceptions.v b/CoqOfPython/ethereum/gray_glacier/vm/exceptions.v index 1f4363d..a429037 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/exceptions.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/exceptions.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.gray_glacier.vm.exceptions". Definition expr_1 : Value.t := Constant.str " @@ -17,9 +17,8 @@ Introduction Exceptions which cause the EVM to halt exceptionally. ". -Require ethereum.exceptions. -Axiom ethereum_exceptions_EthereumException : - IsGlobalAlias globals ethereum.exceptions.globals "EthereumException". +Axiom ethereum_exceptions_imports : + AreImported globals "ethereum.exceptions" [ "EthereumException" ]. Definition ExceptionalHalt : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/gray_glacier/vm/gas.v b/CoqOfPython/ethereum/gray_glacier/vm/gas.v index 640b543..3ae9328 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/gas.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/gas.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.gray_glacier.vm.gas". Definition expr_1 : Value.t := Constant.str " @@ -17,39 +17,26 @@ Introduction EVM gas constants and calculators. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Tuple" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. -Require ethereum.trace. -Axiom ethereum_trace_GasAndRefund : - IsGlobalAlias globals ethereum.trace.globals "GasAndRefund". -Axiom ethereum_trace_evm_trace : - IsGlobalAlias globals ethereum.trace.globals "evm_trace". +Axiom ethereum_trace_imports : + AreImported globals "ethereum.trace" [ "GasAndRefund"; "evm_trace" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.gray_glacier.vm.__init__. -Axiom ethereum_gray_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Evm". +Axiom ethereum_gray_glacier_vm_imports : + AreImported globals "ethereum.gray_glacier.vm" [ "Evm" ]. -Require ethereum.gray_glacier.vm.exceptions. -Axiom ethereum_gray_glacier_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.gray_glacier.vm.exceptions.globals "OutOfGasError". +Axiom ethereum_gray_glacier_vm_exceptions_imports : + AreImported globals "ethereum.gray_glacier.vm.exceptions" [ "OutOfGasError" ]. Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -508,7 +495,7 @@ Definition charge_gas : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -625,105 +612,114 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := ], make_dict [] |) in - For make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ] in M.get_name (| globals, "extensions" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "size" |), - Constant.int 0 - |), - (* then *) + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ], + M.get_name (| globals, "extensions" |), ltac:(M.monadic ( - let _ := M.continue (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let before_size := - M.call (| - M.get_name (| globals, "ceil32" |), - make_list [ - M.get_name (| globals, "current_size" |) - ], - make_dict [] - |) in - let after_size := - M.call (| - M.get_name (| globals, "ceil32" |), - make_list [ - BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "size" |), + Constant.int 0 |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.lt_e (| - M.get_name (| globals, "after_size" |), - M.get_name (| globals, "before_size" |) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.continue (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let size_to_extend := BinOp.add - BinOp.sub (| + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let before_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "current_size" |) + ], + make_dict [] + |) in + let after_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let size_to_extend := BinOp.add + BinOp.sub (| M.get_name (| globals, "after_size" |), M.get_name (| globals, "before_size" |) |) - BinOp.sub (| + BinOp.sub (| M.get_name (| globals, "after_size" |), M.get_name (| globals, "before_size" |) |) in - let already_paid := - M.call (| - M.get_name (| globals, "calculate_memory_gas_cost" |), - make_list [ - M.get_name (| globals, "before_size" |) - ], - make_dict [] - |) in - let total_cost := - M.call (| - M.get_name (| globals, "calculate_memory_gas_cost" |), - make_list [ - M.get_name (| globals, "after_size" |) - ], - make_dict [] - |) in - let to_be_paid := BinOp.add - BinOp.sub (| + let already_paid := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "before_size" |) + ], + make_dict [] + |) in + let total_cost := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "after_size" |) + ], + make_dict [] + |) in + let to_be_paid := BinOp.add + BinOp.sub (| M.get_name (| globals, "total_cost" |), M.get_name (| globals, "already_paid" |) |) - BinOp.sub (| + BinOp.sub (| M.get_name (| globals, "total_cost" |), M.get_name (| globals, "already_paid" |) |) in - let current_size := - M.get_name (| globals, "after_size" |) in - EndFor. + let current_size := + M.get_name (| globals, "after_size" |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ExtendMemory" |), diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/__init__.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/__init__.v index 27d60b9..f2a6201 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/__init__.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.gray_glacier.vm.instructions.__init__". Definition expr_1 : Value.t := Constant.str " @@ -20,59 +20,44 @@ implementations. (* At top_level_stmt: unsupported node type: Import *) -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict" ]. -Require ethereum.gray_glacier.vm.instructions.__init__. -Axiom ethereum_gray_glacier_vm_instructions___init___arithmetic : - IsGlobalAlias globals ethereum.gray_glacier.vm.instructions.__init__.globals "arithmetic". +Axiom ethereum_gray_glacier_vm_instructions_imports : + AreImported globals "ethereum.gray_glacier.vm.instructions" [ "arithmetic" ]. -Require ethereum.gray_glacier.vm.instructions.__init__. -Axiom ethereum_gray_glacier_vm_instructions___init___bitwise : - IsGlobalAlias globals ethereum.gray_glacier.vm.instructions.__init__.globals "bitwise". +Axiom ethereum_gray_glacier_vm_instructions_imports : + AreImported globals "ethereum.gray_glacier.vm.instructions" [ "bitwise" ]. -Require ethereum.gray_glacier.vm.instructions.__init__. -Axiom ethereum_gray_glacier_vm_instructions___init___block : - IsGlobalAlias globals ethereum.gray_glacier.vm.instructions.__init__.globals "block". +Axiom ethereum_gray_glacier_vm_instructions_imports : + AreImported globals "ethereum.gray_glacier.vm.instructions" [ "block" ]. -Require ethereum.gray_glacier.vm.instructions.__init__. -Axiom ethereum_gray_glacier_vm_instructions___init___comparison : - IsGlobalAlias globals ethereum.gray_glacier.vm.instructions.__init__.globals "comparison". +Axiom ethereum_gray_glacier_vm_instructions_imports : + AreImported globals "ethereum.gray_glacier.vm.instructions" [ "comparison" ]. -Require ethereum.gray_glacier.vm.instructions.__init__. -Axiom ethereum_gray_glacier_vm_instructions___init___control_flow : - IsGlobalAlias globals ethereum.gray_glacier.vm.instructions.__init__.globals "control_flow". +Axiom ethereum_gray_glacier_vm_instructions_imports : + AreImported globals "ethereum.gray_glacier.vm.instructions" [ "control_flow" ]. -Require ethereum.gray_glacier.vm.instructions.__init__. -Axiom ethereum_gray_glacier_vm_instructions___init___environment : - IsGlobalAlias globals ethereum.gray_glacier.vm.instructions.__init__.globals "environment". +Axiom ethereum_gray_glacier_vm_instructions_imports : + AreImported globals "ethereum.gray_glacier.vm.instructions" [ "environment" ]. -Require ethereum.gray_glacier.vm.instructions.__init__. -Axiom ethereum_gray_glacier_vm_instructions___init___keccak : - IsGlobalAlias globals ethereum.gray_glacier.vm.instructions.__init__.globals "keccak". +Axiom ethereum_gray_glacier_vm_instructions_imports : + AreImported globals "ethereum.gray_glacier.vm.instructions" [ "keccak" ]. -Require ethereum.gray_glacier.vm.instructions.__init__. -Axiom ethereum_gray_glacier_vm_instructions___init___log : - IsGlobalAlias globals ethereum.gray_glacier.vm.instructions.__init__.globals "log". +Axiom ethereum_gray_glacier_vm_instructions_imports : + AreImported globals "ethereum.gray_glacier.vm.instructions" [ "log" ]. -Require ethereum.gray_glacier.vm.instructions.__init__. -Axiom ethereum_gray_glacier_vm_instructions___init___memory : - IsGlobalAlias globals ethereum.gray_glacier.vm.instructions.__init__.globals "memory". +Axiom ethereum_gray_glacier_vm_instructions_imports : + AreImported globals "ethereum.gray_glacier.vm.instructions" [ "memory" ]. -Require ethereum.gray_glacier.vm.instructions.__init__. -Axiom ethereum_gray_glacier_vm_instructions___init___stack : - IsGlobalAlias globals ethereum.gray_glacier.vm.instructions.__init__.globals "stack". +Axiom ethereum_gray_glacier_vm_instructions_imports : + AreImported globals "ethereum.gray_glacier.vm.instructions" [ "stack" ]. -Require ethereum.gray_glacier.vm.instructions.__init__. -Axiom ethereum_gray_glacier_vm_instructions___init___storage : - IsGlobalAlias globals ethereum.gray_glacier.vm.instructions.__init__.globals "storage". +Axiom ethereum_gray_glacier_vm_instructions_imports : + AreImported globals "ethereum.gray_glacier.vm.instructions" [ "storage" ]. -Require ethereum.gray_glacier.vm.instructions.__init__. -Axiom ethereum_gray_glacier_vm_instructions___init___system : - IsGlobalAlias globals ethereum.gray_glacier.vm.instructions.__init__.globals "system". +Axiom ethereum_gray_glacier_vm_instructions_imports : + AreImported globals "ethereum.gray_glacier.vm.instructions" [ "system" ]. Definition Ops : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/arithmetic.v index 3a30545..a5388a5 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/arithmetic.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.gray_glacier.vm.instructions.arithmetic". Definition expr_1 : Value.t := Constant.str " @@ -17,43 +17,20 @@ Introduction Implementations of the EVM Arithmetic instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U255_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U255_CEIL_VALUE". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_U256_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U255_CEIL_VALUE"; "U256"; "U256_CEIL_VALUE"; "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_get_sign : - IsGlobalAlias globals ethereum.utils.numeric.globals "get_sign". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "get_sign" ]. -Require ethereum.gray_glacier.vm.__init__. -Axiom ethereum_gray_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Evm". +Axiom ethereum_gray_glacier_vm_imports : + AreImported globals "ethereum.gray_glacier.vm" [ "Evm" ]. -Require ethereum.gray_glacier.vm.gas. -Axiom ethereum_gray_glacier_vm_gas_GAS_EXPONENTIATION : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_EXPONENTIATION". -Axiom ethereum_gray_glacier_vm_gas_GAS_EXPONENTIATION_PER_BYTE : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_EXPONENTIATION_PER_BYTE". -Axiom ethereum_gray_glacier_vm_gas_GAS_LOW : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_LOW". -Axiom ethereum_gray_glacier_vm_gas_GAS_MID : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_MID". -Axiom ethereum_gray_glacier_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_gray_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "charge_gas". +Axiom ethereum_gray_glacier_vm_gas_imports : + AreImported globals "ethereum.gray_glacier.vm.gas" [ "GAS_EXPONENTIATION"; "GAS_EXPONENTIATION_PER_BYTE"; "GAS_LOW"; "GAS_MID"; "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.gray_glacier.vm.stack. -Axiom ethereum_gray_glacier_vm_stack_pop : - IsGlobalAlias globals ethereum.gray_glacier.vm.stack.globals "pop". -Axiom ethereum_gray_glacier_vm_stack_push : - IsGlobalAlias globals ethereum.gray_glacier.vm.stack.globals "push". +Axiom ethereum_gray_glacier_vm_stack_imports : + AreImported globals "ethereum.gray_glacier.vm.stack" [ "pop"; "push" ]. Definition add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -1030,19 +1007,27 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let value_bytes := - M.get_subscript (| M.get_name (| globals, "value_bytes" |), M.slice (| BinOp.sub (| - Constant.int 31, - M.call (| - M.get_name (| globals, "int" |), - make_list [ - M.get_name (| globals, "byte_num" |) - ], - make_dict [] - |) - |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "value_bytes" |), + BinOp.sub (| + Constant.int 31, + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "byte_num" |) + ], + make_dict [] + |) + |), + Constant.None_, + Constant.None_ + |) in let sign_bit := BinOp.r_shift (| - M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), + M.get_subscript (| + M.get_name (| globals, "value_bytes" |), + Constant.int 0 + |), Constant.int 7 |) in let _ := diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/bitwise.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/bitwise.v index 196ce46..ada0bff 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/bitwise.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.gray_glacier.vm.instructions.bitwise". Definition expr_1 : Value.t := Constant.str " @@ -17,27 +17,17 @@ Introduction Implementations of the EVM bitwise instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_U256_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "U256_CEIL_VALUE" ]. -Require ethereum.gray_glacier.vm.__init__. -Axiom ethereum_gray_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Evm". +Axiom ethereum_gray_glacier_vm_imports : + AreImported globals "ethereum.gray_glacier.vm" [ "Evm" ]. -Require ethereum.gray_glacier.vm.gas. -Axiom ethereum_gray_glacier_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_gray_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "charge_gas". +Axiom ethereum_gray_glacier_vm_gas_imports : + AreImported globals "ethereum.gray_glacier.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.gray_glacier.vm.stack. -Axiom ethereum_gray_glacier_vm_stack_pop : - IsGlobalAlias globals ethereum.gray_glacier.vm.stack.globals "pop". -Axiom ethereum_gray_glacier_vm_stack_push : - IsGlobalAlias globals ethereum.gray_glacier.vm.stack.globals "push". +Axiom ethereum_gray_glacier_vm_stack_imports : + AreImported globals "ethereum.gray_glacier.vm.stack" [ "pop"; "push" ]. Definition bitwise_and : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/block.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/block.v index ef75123..4f07399 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/block.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/block.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.gray_glacier.vm.instructions.block". Definition expr_1 : Value.t := Constant.str " @@ -17,27 +17,17 @@ Introduction Implementations of the EVM block instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.gray_glacier.vm.__init__. -Axiom ethereum_gray_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Evm". +Axiom ethereum_gray_glacier_vm_imports : + AreImported globals "ethereum.gray_glacier.vm" [ "Evm" ]. -Require ethereum.gray_glacier.vm.gas. -Axiom ethereum_gray_glacier_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_BASE". -Axiom ethereum_gray_glacier_vm_gas_GAS_BLOCK_HASH : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_BLOCK_HASH". -Axiom ethereum_gray_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "charge_gas". +Axiom ethereum_gray_glacier_vm_gas_imports : + AreImported globals "ethereum.gray_glacier.vm.gas" [ "GAS_BASE"; "GAS_BLOCK_HASH"; "charge_gas" ]. -Require ethereum.gray_glacier.vm.stack. -Axiom ethereum_gray_glacier_vm_stack_pop : - IsGlobalAlias globals ethereum.gray_glacier.vm.stack.globals "pop". -Axiom ethereum_gray_glacier_vm_stack_push : - IsGlobalAlias globals ethereum.gray_glacier.vm.stack.globals "push". +Axiom ethereum_gray_glacier_vm_stack_imports : + AreImported globals "ethereum.gray_glacier.vm.stack" [ "pop"; "push" ]. Definition block_hash : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -94,10 +84,13 @@ Definition block_hash : Value.t -> Value.t -> M := (* else *) )), ltac:(M.monadic ( let hash := - M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), - M.get_name (| globals, "block_number" |) - |) |) |) in + M.get_subscript (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), + UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + M.get_name (| globals, "block_number" |) + |) |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/comparison.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/comparison.v index cebb228..b32daf2 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/comparison.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.gray_glacier.vm.instructions.comparison". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementations of the EVM Comparison instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.gray_glacier.vm.__init__. -Axiom ethereum_gray_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Evm". +Axiom ethereum_gray_glacier_vm_imports : + AreImported globals "ethereum.gray_glacier.vm" [ "Evm" ]. -Require ethereum.gray_glacier.vm.gas. -Axiom ethereum_gray_glacier_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_gray_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "charge_gas". +Axiom ethereum_gray_glacier_vm_gas_imports : + AreImported globals "ethereum.gray_glacier.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.gray_glacier.vm.stack. -Axiom ethereum_gray_glacier_vm_stack_pop : - IsGlobalAlias globals ethereum.gray_glacier.vm.stack.globals "pop". -Axiom ethereum_gray_glacier_vm_stack_push : - IsGlobalAlias globals ethereum.gray_glacier.vm.stack.globals "push". +Axiom ethereum_gray_glacier_vm_stack_imports : + AreImported globals "ethereum.gray_glacier.vm.stack" [ "pop"; "push" ]. Definition less_than : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/control_flow.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/control_flow.v index 781ffd8..25a48b1 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/control_flow.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.gray_glacier.vm.instructions.control_flow". Definition expr_1 : Value.t := Constant.str " @@ -17,37 +17,20 @@ Introduction Implementations of the EVM control flow instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. -Require ethereum.gray_glacier.vm.gas. -Axiom ethereum_gray_glacier_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_BASE". -Axiom ethereum_gray_glacier_vm_gas_GAS_HIGH : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_HIGH". -Axiom ethereum_gray_glacier_vm_gas_GAS_JUMPDEST : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_JUMPDEST". -Axiom ethereum_gray_glacier_vm_gas_GAS_MID : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_MID". -Axiom ethereum_gray_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "charge_gas". +Axiom ethereum_gray_glacier_vm_gas_imports : + AreImported globals "ethereum.gray_glacier.vm.gas" [ "GAS_BASE"; "GAS_HIGH"; "GAS_JUMPDEST"; "GAS_MID"; "charge_gas" ]. -Require ethereum.gray_glacier.vm.__init__. -Axiom ethereum_gray_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Evm". +Axiom ethereum_gray_glacier_vm_imports : + AreImported globals "ethereum.gray_glacier.vm" [ "Evm" ]. -Require ethereum.gray_glacier.vm.exceptions. -Axiom ethereum_gray_glacier_vm_exceptions_InvalidJumpDestError : - IsGlobalAlias globals ethereum.gray_glacier.vm.exceptions.globals "InvalidJumpDestError". +Axiom ethereum_gray_glacier_vm_exceptions_imports : + AreImported globals "ethereum.gray_glacier.vm.exceptions" [ "InvalidJumpDestError" ]. -Require ethereum.gray_glacier.vm.stack. -Axiom ethereum_gray_glacier_vm_stack_pop : - IsGlobalAlias globals ethereum.gray_glacier.vm.stack.globals "pop". -Axiom ethereum_gray_glacier_vm_stack_push : - IsGlobalAlias globals ethereum.gray_glacier.vm.stack.globals "push". +Axiom ethereum_gray_glacier_vm_stack_imports : + AreImported globals "ethereum.gray_glacier.vm.stack" [ "pop"; "push" ]. Definition stop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -117,7 +100,7 @@ Definition jump : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "InvalidJumpDestError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -205,7 +188,7 @@ Definition jumpi : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "InvalidJumpDestError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/environment.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/environment.v index d4843ce..efeb715 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/environment.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.gray_glacier.vm.instructions.environment". Definition expr_1 : Value.t := Constant.str " @@ -17,75 +17,41 @@ Introduction Implementations of the EVM environment related instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". - -Require ethereum.gray_glacier.fork_types. -Axiom ethereum_gray_glacier_fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "EMPTY_ACCOUNT". - -Require ethereum.gray_glacier.state. -Axiom ethereum_gray_glacier_state_get_account : - IsGlobalAlias globals ethereum.gray_glacier.state.globals "get_account". - -Require ethereum.gray_glacier.utils.address. -Axiom ethereum_gray_glacier_utils_address_to_address : - IsGlobalAlias globals ethereum.gray_glacier.utils.address.globals "to_address". - -Require ethereum.gray_glacier.vm.memory. -Axiom ethereum_gray_glacier_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.gray_glacier.vm.memory.globals "buffer_read". -Axiom ethereum_gray_glacier_vm_memory_memory_write : - IsGlobalAlias globals ethereum.gray_glacier.vm.memory.globals "memory_write". - -Require ethereum.gray_glacier.vm.__init__. -Axiom ethereum_gray_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Evm". - -Require ethereum.gray_glacier.vm.exceptions. -Axiom ethereum_gray_glacier_vm_exceptions_OutOfBoundsRead : - IsGlobalAlias globals ethereum.gray_glacier.vm.exceptions.globals "OutOfBoundsRead". - -Require ethereum.gray_glacier.vm.gas. -Axiom ethereum_gray_glacier_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_BASE". -Axiom ethereum_gray_glacier_vm_gas_GAS_COLD_ACCOUNT_ACCESS : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_COLD_ACCOUNT_ACCESS". -Axiom ethereum_gray_glacier_vm_gas_GAS_COPY : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_COPY". -Axiom ethereum_gray_glacier_vm_gas_GAS_FAST_STEP : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_FAST_STEP". -Axiom ethereum_gray_glacier_vm_gas_GAS_RETURN_DATA_COPY : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_RETURN_DATA_COPY". -Axiom ethereum_gray_glacier_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_gray_glacier_vm_gas_GAS_WARM_ACCESS : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_WARM_ACCESS". -Axiom ethereum_gray_glacier_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_gray_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "charge_gas". - -Require ethereum.gray_glacier.vm.stack. -Axiom ethereum_gray_glacier_vm_stack_pop : - IsGlobalAlias globals ethereum.gray_glacier.vm.stack.globals "pop". -Axiom ethereum_gray_glacier_vm_stack_push : - IsGlobalAlias globals ethereum.gray_glacier.vm.stack.globals "push". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. + +Axiom ethereum_gray_glacier_fork_types_imports : + AreImported globals "ethereum.gray_glacier.fork_types" [ "EMPTY_ACCOUNT" ]. + +Axiom ethereum_gray_glacier_state_imports : + AreImported globals "ethereum.gray_glacier.state" [ "get_account" ]. + +Axiom ethereum_gray_glacier_utils_address_imports : + AreImported globals "ethereum.gray_glacier.utils.address" [ "to_address" ]. + +Axiom ethereum_gray_glacier_vm_memory_imports : + AreImported globals "ethereum.gray_glacier.vm.memory" [ "buffer_read"; "memory_write" ]. + +Axiom ethereum_gray_glacier_vm_imports : + AreImported globals "ethereum.gray_glacier.vm" [ "Evm" ]. + +Axiom ethereum_gray_glacier_vm_exceptions_imports : + AreImported globals "ethereum.gray_glacier.vm.exceptions" [ "OutOfBoundsRead" ]. + +Axiom ethereum_gray_glacier_vm_gas_imports : + AreImported globals "ethereum.gray_glacier.vm.gas" [ "GAS_BASE"; "GAS_COLD_ACCOUNT_ACCESS"; "GAS_COPY"; "GAS_FAST_STEP"; "GAS_RETURN_DATA_COPY"; "GAS_VERY_LOW"; "GAS_WARM_ACCESS"; "calculate_gas_extend_memory"; "charge_gas" ]. + +Axiom ethereum_gray_glacier_vm_stack_imports : + AreImported globals "ethereum.gray_glacier.vm.stack" [ "pop"; "push" ]. Definition address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -158,7 +124,7 @@ Definition balance : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -810,7 +776,7 @@ Definition extcodesize : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -966,7 +932,7 @@ Definition extcodecopy : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -1225,10 +1191,15 @@ Definition returndatacopy : Value.t -> Value.t -> M := |) |) in let value := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.slice (| M.get_name (| globals, "return_data_start_position" |), BinOp.add (| + M.slice (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |), - M.get_name (| globals, "size" |) - |) |) |) in + BinOp.add (| + M.get_name (| globals, "return_data_start_position" |), + M.get_name (| globals, "size" |) + |), + Constant.None_ + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -1272,7 +1243,7 @@ Definition extcodehash : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/keccak.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/keccak.v index dc92c68..f6861d6 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/keccak.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.gray_glacier.vm.instructions.keccak". Definition expr_1 : Value.t := Constant.str " @@ -17,43 +17,26 @@ Introduction Implementations of the EVM keccak instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". - -Require ethereum.gray_glacier.vm.__init__. -Axiom ethereum_gray_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Evm". - -Require ethereum.gray_glacier.vm.gas. -Axiom ethereum_gray_glacier_vm_gas_GAS_KECCAK256 : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_KECCAK256". -Axiom ethereum_gray_glacier_vm_gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_KECCAK256_WORD". -Axiom ethereum_gray_glacier_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_gray_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "charge_gas". - -Require ethereum.gray_glacier.vm.memory. -Axiom ethereum_gray_glacier_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.gray_glacier.vm.memory.globals "memory_read_bytes". - -Require ethereum.gray_glacier.vm.stack. -Axiom ethereum_gray_glacier_vm_stack_pop : - IsGlobalAlias globals ethereum.gray_glacier.vm.stack.globals "pop". -Axiom ethereum_gray_glacier_vm_stack_push : - IsGlobalAlias globals ethereum.gray_glacier.vm.stack.globals "push". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. + +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. + +Axiom ethereum_gray_glacier_vm_imports : + AreImported globals "ethereum.gray_glacier.vm" [ "Evm" ]. + +Axiom ethereum_gray_glacier_vm_gas_imports : + AreImported globals "ethereum.gray_glacier.vm.gas" [ "GAS_KECCAK256"; "GAS_KECCAK256_WORD"; "calculate_gas_extend_memory"; "charge_gas" ]. + +Axiom ethereum_gray_glacier_vm_memory_imports : + AreImported globals "ethereum.gray_glacier.vm.memory" [ "memory_read_bytes" ]. + +Axiom ethereum_gray_glacier_vm_stack_imports : + AreImported globals "ethereum.gray_glacier.vm.stack" [ "pop"; "push" ]. Definition keccak : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/log.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/log.v index d7f8075..b438023 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/log.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/log.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.gray_glacier.vm.instructions.log". Definition expr_1 : Value.t := Constant.str " @@ -17,49 +17,32 @@ Introduction Implementations of the EVM logging instructions. ". -Require functools. -Axiom functools_partial : - IsGlobalAlias globals functools.globals "partial". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.gray_glacier.blocks. -Axiom ethereum_gray_glacier_blocks_Log : - IsGlobalAlias globals ethereum.gray_glacier.blocks.globals "Log". - -Require ethereum.gray_glacier.vm.__init__. -Axiom ethereum_gray_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Evm". - -Require ethereum.gray_glacier.vm.exceptions. -Axiom ethereum_gray_glacier_vm_exceptions_WriteInStaticContext : - IsGlobalAlias globals ethereum.gray_glacier.vm.exceptions.globals "WriteInStaticContext". - -Require ethereum.gray_glacier.vm.gas. -Axiom ethereum_gray_glacier_vm_gas_GAS_LOG : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_LOG". -Axiom ethereum_gray_glacier_vm_gas_GAS_LOG_DATA : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_LOG_DATA". -Axiom ethereum_gray_glacier_vm_gas_GAS_LOG_TOPIC : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_LOG_TOPIC". -Axiom ethereum_gray_glacier_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_gray_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "charge_gas". - -Require ethereum.gray_glacier.vm.memory. -Axiom ethereum_gray_glacier_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.gray_glacier.vm.memory.globals "memory_read_bytes". - -Require ethereum.gray_glacier.vm.stack. -Axiom ethereum_gray_glacier_vm_stack_pop : - IsGlobalAlias globals ethereum.gray_glacier.vm.stack.globals "pop". +Axiom functools_imports : + AreImported globals "functools" [ "partial" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_gray_glacier_blocks_imports : + AreImported globals "ethereum.gray_glacier.blocks" [ "Log" ]. + +Axiom ethereum_gray_glacier_vm_imports : + AreImported globals "ethereum.gray_glacier.vm" [ "Evm" ]. + +Axiom ethereum_gray_glacier_vm_exceptions_imports : + AreImported globals "ethereum.gray_glacier.vm.exceptions" [ "WriteInStaticContext" ]. + +Axiom ethereum_gray_glacier_vm_gas_imports : + AreImported globals "ethereum.gray_glacier.vm.gas" [ "GAS_LOG"; "GAS_LOG_DATA"; "GAS_LOG_TOPIC"; "calculate_gas_extend_memory"; "charge_gas" ]. + +Axiom ethereum_gray_glacier_vm_memory_imports : + AreImported globals "ethereum.gray_glacier.vm.memory" [ "memory_read_bytes" ]. + +Axiom ethereum_gray_glacier_vm_stack_imports : + AreImported globals "ethereum.gray_glacier.vm.stack" [ "pop" ]. Definition log_n : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -96,33 +79,42 @@ Definition log_n : Value.t -> Value.t -> M := |) in let topics := make_list [] in - For M.get_name (| globals, "_" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - M.get_name (| globals, "num_topics" |) - ], - make_dict [] - |) do - let topic := + let _ := + M.for_ (| + M.get_name (| globals, "_" |), M.call (| - M.get_field (| M.call (| - M.get_name (| globals, "pop" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] - |), "to_be_bytes32" |), - make_list [], - make_dict [] - |) in - let _ := M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "num_topics" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let topic := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| M.get_field (| M.get_name (| globals, "topics" |), "append" |), make_list [ M.get_name (| globals, "topic" |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let extend_memory := M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/memory.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/memory.v index a2a84f5..a86572c 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/memory.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.gray_glacier.vm.instructions.memory". Definition expr_1 : Value.t := Constant.str " @@ -17,37 +17,20 @@ Introduction Implementations of the EVM Memory instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes" ]. -Require ethereum.gray_glacier.vm.__init__. -Axiom ethereum_gray_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Evm". +Axiom ethereum_gray_glacier_vm_imports : + AreImported globals "ethereum.gray_glacier.vm" [ "Evm" ]. -Require ethereum.gray_glacier.vm.gas. -Axiom ethereum_gray_glacier_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_BASE". -Axiom ethereum_gray_glacier_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_gray_glacier_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_gray_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "charge_gas". +Axiom ethereum_gray_glacier_vm_gas_imports : + AreImported globals "ethereum.gray_glacier.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. -Require ethereum.gray_glacier.vm.memory. -Axiom ethereum_gray_glacier_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.gray_glacier.vm.memory.globals "memory_read_bytes". -Axiom ethereum_gray_glacier_vm_memory_memory_write : - IsGlobalAlias globals ethereum.gray_glacier.vm.memory.globals "memory_write". +Axiom ethereum_gray_glacier_vm_memory_imports : + AreImported globals "ethereum.gray_glacier.vm.memory" [ "memory_read_bytes"; "memory_write" ]. -Require ethereum.gray_glacier.vm.stack. -Axiom ethereum_gray_glacier_vm_stack_pop : - IsGlobalAlias globals ethereum.gray_glacier.vm.stack.globals "pop". -Axiom ethereum_gray_glacier_vm_stack_push : - IsGlobalAlias globals ethereum.gray_glacier.vm.stack.globals "push". +Axiom ethereum_gray_glacier_vm_stack_imports : + AreImported globals "ethereum.gray_glacier.vm.stack" [ "pop"; "push" ]. Definition mstore : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/stack.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/stack.v index 4ff75c7..73ca8c9 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/stack.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.gray_glacier.vm.instructions.stack". Definition expr_1 : Value.t := Constant.str " @@ -17,39 +17,26 @@ Introduction Implementations of the EVM stack related instructions. ". -Require functools. -Axiom functools_partial : - IsGlobalAlias globals functools.globals "partial". +Axiom functools_imports : + AreImported globals "functools" [ "partial" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.gray_glacier.vm.__init__. -Axiom ethereum_gray_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Evm". -Axiom ethereum_gray_glacier_vm___init___stack : - IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "stack". +Axiom ethereum_gray_glacier_vm_imports : + AreImported globals "ethereum.gray_glacier.vm" [ "Evm"; "stack" ]. -Require ethereum.gray_glacier.vm.exceptions. -Axiom ethereum_gray_glacier_vm_exceptions_StackUnderflowError : - IsGlobalAlias globals ethereum.gray_glacier.vm.exceptions.globals "StackUnderflowError". +Axiom ethereum_gray_glacier_vm_exceptions_imports : + AreImported globals "ethereum.gray_glacier.vm.exceptions" [ "StackUnderflowError" ]. -Require ethereum.gray_glacier.vm.gas. -Axiom ethereum_gray_glacier_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_BASE". -Axiom ethereum_gray_glacier_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_gray_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "charge_gas". +Axiom ethereum_gray_glacier_vm_gas_imports : + AreImported globals "ethereum.gray_glacier.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.gray_glacier.vm.memory. -Axiom ethereum_gray_glacier_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.gray_glacier.vm.memory.globals "buffer_read". +Axiom ethereum_gray_glacier_vm_memory_imports : + AreImported globals "ethereum.gray_glacier.vm.memory" [ "buffer_read" ]. Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -203,19 +190,22 @@ Definition dup_n : Value.t -> Value.t -> M := make_dict [] |) in let data_to_duplicate := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] + BinOp.sub (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), + Constant.int 1 |), - Constant.int 1 - |), - M.get_name (| globals, "item_number" |) - |) |) in + M.get_name (| globals, "item_number" |) + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "stack" |), "push" |), make_list [ @@ -278,14 +268,26 @@ Definition swap_n : Value.t -> Value.t -> M := make_dict [] |) in let _ := M.assign (| - make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| - UnOp.sub (| Constant.int 1 |), - M.get_name (| globals, "item_number" |) - |) |) ], - make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| - UnOp.sub (| Constant.int 1 |), - M.get_name (| globals, "item_number" |) - |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |) ] + make_tuple [ M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + UnOp.sub (| Constant.int 1 |) + |); M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) + |) ], + make_tuple [ M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) + |); M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + UnOp.sub (| Constant.int 1 |) + |) ] |) in let _ := M.assign_op (| BinOp.add, diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/storage.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/storage.v index 846db44..7bb3cb1 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/storage.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.gray_glacier.vm.instructions.storage". Definition expr_1 : Value.t := Constant.str " @@ -17,53 +17,26 @@ Introduction Implementations of the EVM storage related instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.gray_glacier.state. -Axiom ethereum_gray_glacier_state_get_storage : - IsGlobalAlias globals ethereum.gray_glacier.state.globals "get_storage". -Axiom ethereum_gray_glacier_state_get_storage_original : - IsGlobalAlias globals ethereum.gray_glacier.state.globals "get_storage_original". -Axiom ethereum_gray_glacier_state_set_storage : - IsGlobalAlias globals ethereum.gray_glacier.state.globals "set_storage". +Axiom ethereum_gray_glacier_state_imports : + AreImported globals "ethereum.gray_glacier.state" [ "get_storage"; "get_storage_original"; "set_storage" ]. -Require ethereum.gray_glacier.vm.__init__. -Axiom ethereum_gray_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Evm". +Axiom ethereum_gray_glacier_vm_imports : + AreImported globals "ethereum.gray_glacier.vm" [ "Evm" ]. -Require ethereum.gray_glacier.vm.exceptions. -Axiom ethereum_gray_glacier_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.gray_glacier.vm.exceptions.globals "OutOfGasError". -Axiom ethereum_gray_glacier_vm_exceptions_WriteInStaticContext : - IsGlobalAlias globals ethereum.gray_glacier.vm.exceptions.globals "WriteInStaticContext". +Axiom ethereum_gray_glacier_vm_exceptions_imports : + AreImported globals "ethereum.gray_glacier.vm.exceptions" [ "OutOfGasError"; "WriteInStaticContext" ]. -Require ethereum.gray_glacier.vm.gas. -Axiom ethereum_gray_glacier_vm_gas_GAS_CALL_STIPEND : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_CALL_STIPEND". -Axiom ethereum_gray_glacier_vm_gas_GAS_COLD_SLOAD : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_COLD_SLOAD". -Axiom ethereum_gray_glacier_vm_gas_GAS_STORAGE_CLEAR_REFUND : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_STORAGE_CLEAR_REFUND". -Axiom ethereum_gray_glacier_vm_gas_GAS_STORAGE_SET : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_STORAGE_SET". -Axiom ethereum_gray_glacier_vm_gas_GAS_STORAGE_UPDATE : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_STORAGE_UPDATE". -Axiom ethereum_gray_glacier_vm_gas_GAS_WARM_ACCESS : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_WARM_ACCESS". -Axiom ethereum_gray_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "charge_gas". +Axiom ethereum_gray_glacier_vm_gas_imports : + AreImported globals "ethereum.gray_glacier.vm.gas" [ "GAS_CALL_STIPEND"; "GAS_COLD_SLOAD"; "GAS_STORAGE_CLEAR_REFUND"; "GAS_STORAGE_SET"; "GAS_STORAGE_UPDATE"; "GAS_WARM_ACCESS"; "charge_gas" ]. -Require ethereum.gray_glacier.vm.stack. -Axiom ethereum_gray_glacier_vm_stack_pop : - IsGlobalAlias globals ethereum.gray_glacier.vm.stack.globals "pop". -Axiom ethereum_gray_glacier_vm_stack_push : - IsGlobalAlias globals ethereum.gray_glacier.vm.stack.globals "push". +Axiom ethereum_gray_glacier_vm_stack_imports : + AreImported globals "ethereum.gray_glacier.vm.stack" [ "pop"; "push" ]. Definition sload : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -93,7 +66,7 @@ Definition sload : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) |), diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/system.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/system.v index 5df4fd8..c4320ce 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/system.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/system.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.gray_glacier.vm.instructions.system". Definition expr_1 : Value.t := Constant.str " @@ -17,103 +17,38 @@ Introduction Implementations of the EVM system related instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.gray_glacier.fork_types. -Axiom ethereum_gray_glacier_fork_types_Address : - IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "Address". +Axiom ethereum_gray_glacier_fork_types_imports : + AreImported globals "ethereum.gray_glacier.fork_types" [ "Address" ]. -Require ethereum.gray_glacier.state. -Axiom ethereum_gray_glacier_state_account_exists_and_is_empty : - IsGlobalAlias globals ethereum.gray_glacier.state.globals "account_exists_and_is_empty". -Axiom ethereum_gray_glacier_state_account_has_code_or_nonce : - IsGlobalAlias globals ethereum.gray_glacier.state.globals "account_has_code_or_nonce". -Axiom ethereum_gray_glacier_state_get_account : - IsGlobalAlias globals ethereum.gray_glacier.state.globals "get_account". -Axiom ethereum_gray_glacier_state_increment_nonce : - IsGlobalAlias globals ethereum.gray_glacier.state.globals "increment_nonce". -Axiom ethereum_gray_glacier_state_is_account_alive : - IsGlobalAlias globals ethereum.gray_glacier.state.globals "is_account_alive". -Axiom ethereum_gray_glacier_state_set_account_balance : - IsGlobalAlias globals ethereum.gray_glacier.state.globals "set_account_balance". +Axiom ethereum_gray_glacier_state_imports : + AreImported globals "ethereum.gray_glacier.state" [ "account_exists_and_is_empty"; "account_has_code_or_nonce"; "get_account"; "increment_nonce"; "is_account_alive"; "set_account_balance" ]. -Require ethereum.gray_glacier.utils.address. -Axiom ethereum_gray_glacier_utils_address_compute_contract_address : - IsGlobalAlias globals ethereum.gray_glacier.utils.address.globals "compute_contract_address". -Axiom ethereum_gray_glacier_utils_address_compute_create2_contract_address : - IsGlobalAlias globals ethereum.gray_glacier.utils.address.globals "compute_create2_contract_address". -Axiom ethereum_gray_glacier_utils_address_to_address : - IsGlobalAlias globals ethereum.gray_glacier.utils.address.globals "to_address". +Axiom ethereum_gray_glacier_utils_address_imports : + AreImported globals "ethereum.gray_glacier.utils.address" [ "compute_contract_address"; "compute_create2_contract_address"; "to_address" ]. -Require ethereum.gray_glacier.vm.__init__. -Axiom ethereum_gray_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Evm". -Axiom ethereum_gray_glacier_vm___init___Message : - IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Message". -Axiom ethereum_gray_glacier_vm___init___incorporate_child_on_error : - IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "incorporate_child_on_error". -Axiom ethereum_gray_glacier_vm___init___incorporate_child_on_success : - IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "incorporate_child_on_success". +Axiom ethereum_gray_glacier_vm_imports : + AreImported globals "ethereum.gray_glacier.vm" [ "Evm"; "Message"; "incorporate_child_on_error"; "incorporate_child_on_success" ]. -Require ethereum.gray_glacier.vm.exceptions. -Axiom ethereum_gray_glacier_vm_exceptions_Revert : - IsGlobalAlias globals ethereum.gray_glacier.vm.exceptions.globals "Revert". -Axiom ethereum_gray_glacier_vm_exceptions_WriteInStaticContext : - IsGlobalAlias globals ethereum.gray_glacier.vm.exceptions.globals "WriteInStaticContext". +Axiom ethereum_gray_glacier_vm_exceptions_imports : + AreImported globals "ethereum.gray_glacier.vm.exceptions" [ "Revert"; "WriteInStaticContext" ]. -Require ethereum.gray_glacier.vm.gas. -Axiom ethereum_gray_glacier_vm_gas_GAS_CALL_VALUE : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_CALL_VALUE". -Axiom ethereum_gray_glacier_vm_gas_GAS_COLD_ACCOUNT_ACCESS : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_COLD_ACCOUNT_ACCESS". -Axiom ethereum_gray_glacier_vm_gas_GAS_CREATE : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_CREATE". -Axiom ethereum_gray_glacier_vm_gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_KECCAK256_WORD". -Axiom ethereum_gray_glacier_vm_gas_GAS_NEW_ACCOUNT : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_NEW_ACCOUNT". -Axiom ethereum_gray_glacier_vm_gas_GAS_SELF_DESTRUCT : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_SELF_DESTRUCT". -Axiom ethereum_gray_glacier_vm_gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". -Axiom ethereum_gray_glacier_vm_gas_GAS_WARM_ACCESS : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_WARM_ACCESS". -Axiom ethereum_gray_glacier_vm_gas_GAS_ZERO : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_ZERO". -Axiom ethereum_gray_glacier_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_gray_glacier_vm_gas_calculate_message_call_gas : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "calculate_message_call_gas". -Axiom ethereum_gray_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "charge_gas". -Axiom ethereum_gray_glacier_vm_gas_max_message_call_gas : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "max_message_call_gas". +Axiom ethereum_gray_glacier_vm_gas_imports : + AreImported globals "ethereum.gray_glacier.vm.gas" [ "GAS_CALL_VALUE"; "GAS_COLD_ACCOUNT_ACCESS"; "GAS_CREATE"; "GAS_KECCAK256_WORD"; "GAS_NEW_ACCOUNT"; "GAS_SELF_DESTRUCT"; "GAS_SELF_DESTRUCT_NEW_ACCOUNT"; "GAS_WARM_ACCESS"; "GAS_ZERO"; "calculate_gas_extend_memory"; "calculate_message_call_gas"; "charge_gas"; "max_message_call_gas" ]. -Require ethereum.gray_glacier.vm.memory. -Axiom ethereum_gray_glacier_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.gray_glacier.vm.memory.globals "memory_read_bytes". -Axiom ethereum_gray_glacier_vm_memory_memory_write : - IsGlobalAlias globals ethereum.gray_glacier.vm.memory.globals "memory_write". +Axiom ethereum_gray_glacier_vm_memory_imports : + AreImported globals "ethereum.gray_glacier.vm.memory" [ "memory_read_bytes"; "memory_write" ]. -Require ethereum.gray_glacier.vm.stack. -Axiom ethereum_gray_glacier_vm_stack_pop : - IsGlobalAlias globals ethereum.gray_glacier.vm.stack.globals "pop". -Axiom ethereum_gray_glacier_vm_stack_push : - IsGlobalAlias globals ethereum.gray_glacier.vm.stack.globals "push". +Axiom ethereum_gray_glacier_vm_stack_imports : + AreImported globals "ethereum.gray_glacier.vm.stack" [ "pop"; "push" ]. Definition generic_create : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -866,7 +801,12 @@ Definition generic_call : Value.t -> Value.t -> M := make_list [ M.get_field (| M.get_name (| globals, "evm" |), "memory" |); M.get_name (| globals, "memory_output_start_position" |); - M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), M.slice (| Constant.None_, M.get_name (| globals, "actual_output_size" |) |) |) + M.slice (| + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), + Constant.None_, + M.get_name (| globals, "actual_output_size" |), + Constant.None_ + |) ], make_dict [] |) in @@ -966,7 +906,7 @@ Definition call : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "to" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -1272,7 +1212,7 @@ Definition callcode : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "code_address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -1700,7 +1640,7 @@ Definition delegatecall : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "code_address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -1876,7 +1816,7 @@ Definition staticcall : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "to" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -2046,6 +1986,6 @@ Definition revert : Value.t -> Value.t -> M := make_dict [] |) |) in - let _ := M.raise (| Some(M.get_name (| globals, "Revert" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "Revert" |)) |) in let _ := M.pass (| |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/gray_glacier/vm/interpreter.v b/CoqOfPython/ethereum/gray_glacier/vm/interpreter.v index fe17b9d..9d7e97e 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/interpreter.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/interpreter.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.gray_glacier.vm.interpreter". Definition expr_1 : Value.t := Constant.str " @@ -17,127 +17,50 @@ Introduction A straightforward interpreter that executes EVM code. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_Iterable : - IsGlobalAlias globals typing.globals "Iterable". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.trace. -Axiom ethereum_trace_EvmStop : - IsGlobalAlias globals ethereum.trace.globals "EvmStop". -Axiom ethereum_trace_OpEnd : - IsGlobalAlias globals ethereum.trace.globals "OpEnd". -Axiom ethereum_trace_OpException : - IsGlobalAlias globals ethereum.trace.globals "OpException". -Axiom ethereum_trace_OpStart : - IsGlobalAlias globals ethereum.trace.globals "OpStart". -Axiom ethereum_trace_PrecompileEnd : - IsGlobalAlias globals ethereum.trace.globals "PrecompileEnd". -Axiom ethereum_trace_PrecompileStart : - IsGlobalAlias globals ethereum.trace.globals "PrecompileStart". -Axiom ethereum_trace_TransactionEnd : - IsGlobalAlias globals ethereum.trace.globals "TransactionEnd". -Axiom ethereum_trace_evm_trace : - IsGlobalAlias globals ethereum.trace.globals "evm_trace". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.gray_glacier.blocks. -Axiom ethereum_gray_glacier_blocks_Log : - IsGlobalAlias globals ethereum.gray_glacier.blocks.globals "Log". - -Require ethereum.gray_glacier.fork_types. -Axiom ethereum_gray_glacier_fork_types_Address : - IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "Address". - -Require ethereum.gray_glacier.state. -Axiom ethereum_gray_glacier_state_account_exists_and_is_empty : - IsGlobalAlias globals ethereum.gray_glacier.state.globals "account_exists_and_is_empty". -Axiom ethereum_gray_glacier_state_account_has_code_or_nonce : - IsGlobalAlias globals ethereum.gray_glacier.state.globals "account_has_code_or_nonce". -Axiom ethereum_gray_glacier_state_begin_transaction : - IsGlobalAlias globals ethereum.gray_glacier.state.globals "begin_transaction". -Axiom ethereum_gray_glacier_state_commit_transaction : - IsGlobalAlias globals ethereum.gray_glacier.state.globals "commit_transaction". -Axiom ethereum_gray_glacier_state_destroy_storage : - IsGlobalAlias globals ethereum.gray_glacier.state.globals "destroy_storage". -Axiom ethereum_gray_glacier_state_increment_nonce : - IsGlobalAlias globals ethereum.gray_glacier.state.globals "increment_nonce". -Axiom ethereum_gray_glacier_state_mark_account_created : - IsGlobalAlias globals ethereum.gray_glacier.state.globals "mark_account_created". -Axiom ethereum_gray_glacier_state_move_ether : - IsGlobalAlias globals ethereum.gray_glacier.state.globals "move_ether". -Axiom ethereum_gray_glacier_state_rollback_transaction : - IsGlobalAlias globals ethereum.gray_glacier.state.globals "rollback_transaction". -Axiom ethereum_gray_glacier_state_set_code : - IsGlobalAlias globals ethereum.gray_glacier.state.globals "set_code". -Axiom ethereum_gray_glacier_state_touch_account : - IsGlobalAlias globals ethereum.gray_glacier.state.globals "touch_account". - -Require ethereum.gray_glacier.vm.__init__. -Axiom ethereum_gray_glacier_vm___init___Message : - IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Message". - -Require ethereum.gray_glacier.vm.gas. -Axiom ethereum_gray_glacier_vm_gas_GAS_CODE_DEPOSIT : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_CODE_DEPOSIT". -Axiom ethereum_gray_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "charge_gas". - -Require ethereum.gray_glacier.vm.precompiled_contracts.mapping. -Axiom ethereum_gray_glacier_vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : - IsGlobalAlias globals ethereum.gray_glacier.vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". - -Require ethereum.gray_glacier.vm.__init__. -Axiom ethereum_gray_glacier_vm___init___Environment : - IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Environment". -Axiom ethereum_gray_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Evm". - -Require ethereum.gray_glacier.vm.exceptions. -Axiom ethereum_gray_glacier_vm_exceptions_AddressCollision : - IsGlobalAlias globals ethereum.gray_glacier.vm.exceptions.globals "AddressCollision". -Axiom ethereum_gray_glacier_vm_exceptions_ExceptionalHalt : - IsGlobalAlias globals ethereum.gray_glacier.vm.exceptions.globals "ExceptionalHalt". -Axiom ethereum_gray_glacier_vm_exceptions_InvalidContractPrefix : - IsGlobalAlias globals ethereum.gray_glacier.vm.exceptions.globals "InvalidContractPrefix". -Axiom ethereum_gray_glacier_vm_exceptions_InvalidOpcode : - IsGlobalAlias globals ethereum.gray_glacier.vm.exceptions.globals "InvalidOpcode". -Axiom ethereum_gray_glacier_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.gray_glacier.vm.exceptions.globals "OutOfGasError". -Axiom ethereum_gray_glacier_vm_exceptions_Revert : - IsGlobalAlias globals ethereum.gray_glacier.vm.exceptions.globals "Revert". -Axiom ethereum_gray_glacier_vm_exceptions_StackDepthLimitError : - IsGlobalAlias globals ethereum.gray_glacier.vm.exceptions.globals "StackDepthLimitError". - -Require ethereum.gray_glacier.vm.instructions.__init__. -Axiom ethereum_gray_glacier_vm_instructions___init___Ops : - IsGlobalAlias globals ethereum.gray_glacier.vm.instructions.__init__.globals "Ops". -Axiom ethereum_gray_glacier_vm_instructions___init___op_implementation : - IsGlobalAlias globals ethereum.gray_glacier.vm.instructions.__init__.globals "op_implementation". - -Require ethereum.gray_glacier.vm.runtime. -Axiom ethereum_gray_glacier_vm_runtime_get_valid_jump_destinations : - IsGlobalAlias globals ethereum.gray_glacier.vm.runtime.globals "get_valid_jump_destinations". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Iterable"; "Optional"; "Set"; "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. + +Axiom ethereum_trace_imports : + AreImported globals "ethereum.trace" [ "EvmStop"; "OpEnd"; "OpException"; "OpStart"; "PrecompileEnd"; "PrecompileStart"; "TransactionEnd"; "evm_trace" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_gray_glacier_blocks_imports : + AreImported globals "ethereum.gray_glacier.blocks" [ "Log" ]. + +Axiom ethereum_gray_glacier_fork_types_imports : + AreImported globals "ethereum.gray_glacier.fork_types" [ "Address" ]. + +Axiom ethereum_gray_glacier_state_imports : + AreImported globals "ethereum.gray_glacier.state" [ "account_exists_and_is_empty"; "account_has_code_or_nonce"; "begin_transaction"; "commit_transaction"; "destroy_storage"; "increment_nonce"; "mark_account_created"; "move_ether"; "rollback_transaction"; "set_code"; "touch_account" ]. + +Axiom ethereum_gray_glacier_vm_imports : + AreImported globals "ethereum.gray_glacier.vm" [ "Message" ]. + +Axiom ethereum_gray_glacier_vm_gas_imports : + AreImported globals "ethereum.gray_glacier.vm.gas" [ "GAS_CODE_DEPOSIT"; "charge_gas" ]. + +Axiom ethereum_gray_glacier_vm_precompiled_contracts_mapping_imports : + AreImported globals "ethereum.gray_glacier.vm.precompiled_contracts.mapping" [ "PRE_COMPILED_CONTRACTS" ]. + +Axiom ethereum_gray_glacier_vm_imports : + AreImported globals "ethereum.gray_glacier.vm" [ "Environment"; "Evm" ]. + +Axiom ethereum_gray_glacier_vm_exceptions_imports : + AreImported globals "ethereum.gray_glacier.vm.exceptions" [ "AddressCollision"; "ExceptionalHalt"; "InvalidContractPrefix"; "InvalidOpcode"; "OutOfGasError"; "Revert"; "StackDepthLimitError" ]. + +Axiom ethereum_gray_glacier_vm_instructions_imports : + AreImported globals "ethereum.gray_glacier.vm.instructions" [ "Ops"; "op_implementation" ]. + +Axiom ethereum_gray_glacier_vm_runtime_imports : + AreImported globals "ethereum.gray_glacier.vm.runtime" [ "get_valid_jump_destinations" ]. Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -518,7 +441,7 @@ Definition process_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "StackDepthLimitError" |), make_list [ Constant.str "Stack depth limit reached" diff --git a/CoqOfPython/ethereum/gray_glacier/vm/memory.v b/CoqOfPython/ethereum/gray_glacier/vm/memory.v index 08d2290..3f05578 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/memory.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/memory.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.gray_glacier.vm.memory". Definition expr_1 : Value.t := Constant.str " @@ -17,17 +17,11 @@ Introduction EVM memory operations. ". -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_right_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "right_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "right_pad_zero_bytes" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. Definition memory_write : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,22 +39,27 @@ Definition memory_write : Value.t -> Value.t -> M := Data to write to memory. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + M.slice (| + M.get_name (| globals, "memory" |), + M.get_name (| globals, "start_position" |), + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) - |) |) |), + Constant.None_ + |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_)). @@ -86,22 +85,27 @@ Definition memory_read_bytes : Value.t -> Value.t -> M := Data read from memory. " in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + M.slice (| + M.get_name (| globals, "memory" |), + M.get_name (| globals, "start_position" |), + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |) |) + Constant.None_ + |) |) in M.pure Constant.None_)). @@ -129,22 +133,27 @@ Definition buffer_read : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "right_pad_zero_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "buffer" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + M.slice (| + M.get_name (| globals, "buffer" |), + M.get_name (| globals, "start_position" |), + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |) |); + Constant.None_ + |); M.get_name (| globals, "size" |) ], make_dict [] diff --git a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/__init__.v index 6658651..c0cc5cf 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/__init__.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.gray_glacier.vm.precompiled_contracts.__init__". Definition expr_1 : Value.t := Constant.str " @@ -18,9 +18,8 @@ Addresses of precompiled contracts and mappings to their implementations. ". -Require ethereum.gray_glacier.utils.hexadecimal. -Axiom ethereum_gray_glacier_utils_hexadecimal_hex_to_address : - IsGlobalAlias globals ethereum.gray_glacier.utils.hexadecimal.globals "hex_to_address". +Axiom ethereum_gray_glacier_utils_hexadecimal_imports : + AreImported globals "ethereum.gray_glacier.utils.hexadecimal" [ "hex_to_address" ]. Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS"; Constant.str "MODEXP_ADDRESS"; Constant.str "ALT_BN128_ADD_ADDRESS"; Constant.str "ALT_BN128_MUL_ADDRESS"; Constant.str "ALT_BN128_PAIRING_CHECK_ADDRESS"; Constant.str "BLAKE2F_ADDRESS" ] diff --git a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/alt_bn128.v index d7ca245..70533ad 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/alt_bn128.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/alt_bn128.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.gray_glacier.vm.precompiled_contracts.alt_bn128". Definition expr_1 : Value.t := Constant.str " @@ -17,49 +17,26 @@ Introduction Implementation of the ALT_BN128 precompiled contracts. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. -Require ethereum.crypto.alt_bn128. -Axiom ethereum_crypto_alt_bn128_ALT_BN128_CURVE_ORDER : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "ALT_BN128_CURVE_ORDER". -Axiom ethereum_crypto_alt_bn128_ALT_BN128_PRIME : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "ALT_BN128_PRIME". -Axiom ethereum_crypto_alt_bn128_BNF : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF". -Axiom ethereum_crypto_alt_bn128_BNF2 : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF2". -Axiom ethereum_crypto_alt_bn128_BNF12 : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF12". -Axiom ethereum_crypto_alt_bn128_BNP : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNP". -Axiom ethereum_crypto_alt_bn128_BNP2 : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNP2". -Axiom ethereum_crypto_alt_bn128_pairing : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "pairing". +Axiom ethereum_crypto_alt_bn128_imports : + AreImported globals "ethereum.crypto.alt_bn128" [ "ALT_BN128_CURVE_ORDER"; "ALT_BN128_PRIME"; "BNF"; "BNF2"; "BNF12"; "BNP"; "BNP2"; "pairing" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.gray_glacier.vm.__init__. -Axiom ethereum_gray_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Evm". +Axiom ethereum_gray_glacier_vm_imports : + AreImported globals "ethereum.gray_glacier.vm" [ "Evm" ]. -Require ethereum.gray_glacier.vm.gas. -Axiom ethereum_gray_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "charge_gas". +Axiom ethereum_gray_glacier_vm_gas_imports : + AreImported globals "ethereum.gray_glacier.vm.gas" [ "charge_gas" ]. -Require ethereum.gray_glacier.vm.memory. -Axiom ethereum_gray_glacier_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.gray_glacier.vm.memory.globals "buffer_read". +Axiom ethereum_gray_glacier_vm_memory_imports : + AreImported globals "ethereum.gray_glacier.vm.memory" [ "buffer_read" ]. -Require ethereum.gray_glacier.vm.exceptions. -Axiom ethereum_gray_glacier_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.gray_glacier.vm.exceptions.globals "OutOfGasError". +Axiom ethereum_gray_glacier_vm_exceptions_imports : + AreImported globals "ethereum.gray_glacier.vm.exceptions" [ "OutOfGasError" ]. Definition alt_bn128_add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -208,23 +185,32 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ] do - let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| - M.get_name (| globals, "i" |), - M.get_name (| globals, "ALT_BN128_PRIME" |) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ], ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in (* At stmt: unsupported node type: Try *) let p := BinOp.add (| @@ -363,23 +349,32 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ] do - let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| - M.get_name (| globals, "i" |), - M.get_name (| globals, "ALT_BN128_PRIME" |) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ], ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in (* At stmt: unsupported node type: Try *) let p := M.call (| @@ -466,7 +461,7 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -480,76 +475,89 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - BinOp.floor_div (| + let _ := + M.for_ (| + M.get_name (| globals, "i" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "data" |) - ], - make_dict [] - |), - Constant.int 192 - |) - ], - make_dict [] - |) do - let values := - make_list [] in - For M.get_name (| globals, "j" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 6 - ], - make_dict [] - |) do - let value := + M.get_name (| globals, "range" |), + make_list [ + BinOp.floor_div (| M.call (| - M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + M.get_name (| globals, "len" |), make_list [ - M.get_subscript (| M.get_name (| globals, "data" |), M.slice (| BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "i" |), - Constant.int 192 - |), - BinOp.mult (| - Constant.int 32, - M.get_name (| globals, "j" |) - |) - |), BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "i" |), - Constant.int 192 - |), - BinOp.mult (| - Constant.int 32, - BinOp.add (| - M.get_name (| globals, "j" |), - Constant.int 1 - |) - |) - |) |) |) + M.get_name (| globals, "data" |) ], make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| - M.get_name (| globals, "value" |), - M.get_name (| globals, "ALT_BN128_PRIME" |) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let _ := M.call (| + |), + Constant.int 192 + |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let values := + make_list [] in + let _ := + M.for_ (| + M.get_name (| globals, "j" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 6 + ], + make_dict [] + |), + ltac:(M.monadic ( + let value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.slice (| + M.get_name (| globals, "data" |), + BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + M.get_name (| globals, "j" |) + |) + |), + BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "j" |), + Constant.int 1 + |) + |) + |), + Constant.None_ + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| M.get_field (| M.get_name (| globals, "values" |), "append" |), make_list [ M.call (| @@ -562,9 +570,14 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in (* At stmt: unsupported node type: Try *) - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.eq (| @@ -585,7 +598,7 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.eq (| @@ -606,49 +619,54 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| - M.get_name (| globals, "p" |), - M.call (| - M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) - |), + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "p" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "q" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |) + )) + |), + (* then *) ltac:(M.monadic ( - Compare.not_eq (| - M.get_name (| globals, "q" |), - M.call (| - M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) - |) - )) - |), - (* then *) - ltac:(M.monadic ( - let result := - BinOp.mult (| - M.get_name (| globals, "result" |), - M.call (| - M.get_name (| globals, "pairing" |), - make_list [ - M.get_name (| globals, "q" |); - M.get_name (| globals, "p" |) - ], - make_dict [] - |) - |) in + let result := + BinOp.mult (| + M.get_name (| globals, "result" |), + M.call (| + M.get_name (| globals, "pairing" |), + make_list [ + M.get_name (| globals, "q" |); + M.get_name (| globals, "p" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := (* if *) M.if_then_else (| diff --git a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/blake2f.v b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/blake2f.v index 8bfd578..4f52681 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/blake2f.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/blake2f.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.gray_glacier.vm.precompiled_contracts.blake2f". Definition expr_1 : Value.t := Constant.str " @@ -17,27 +17,20 @@ Introduction Implementation of the `Blake2` precompiled contract. ". -Require ethereum.crypto.blake2. -Axiom ethereum_crypto_blake2_Blake2b : - IsGlobalAlias globals ethereum.crypto.blake2.globals "Blake2b". +Axiom ethereum_crypto_blake2_imports : + AreImported globals "ethereum.crypto.blake2" [ "Blake2b" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.gray_glacier.vm.__init__. -Axiom ethereum_gray_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Evm". +Axiom ethereum_gray_glacier_vm_imports : + AreImported globals "ethereum.gray_glacier.vm" [ "Evm" ]. -Require ethereum.gray_glacier.vm.gas. -Axiom ethereum_gray_glacier_vm_gas_GAS_BLAKE2_PER_ROUND : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_BLAKE2_PER_ROUND". -Axiom ethereum_gray_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "charge_gas". +Axiom ethereum_gray_glacier_vm_gas_imports : + AreImported globals "ethereum.gray_glacier.vm.gas" [ "GAS_BLAKE2_PER_ROUND"; "charge_gas" ]. -Require ethereum.gray_glacier.vm.exceptions. -Axiom ethereum_gray_glacier_vm_exceptions_InvalidParameter : - IsGlobalAlias globals ethereum.gray_glacier.vm.exceptions.globals "InvalidParameter". +Axiom ethereum_gray_glacier_vm_exceptions_imports : + AreImported globals "ethereum.gray_glacier.vm.exceptions" [ "InvalidParameter" ]. Definition blake2f : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -99,7 +92,7 @@ Definition blake2f : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.in (| + Compare.in_ (| M.get_name (| globals, "f" |), make_list [ Constant.int 0; diff --git a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/ecrecover.v index 0819bfd..9538a33 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/ecrecover.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.gray_glacier.vm.precompiled_contracts.ecrecover". Definition expr_1 : Value.t := Constant.str " @@ -17,39 +17,26 @@ Introduction Implementation of the ECRECOVER precompiled contract. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.crypto.elliptic_curve. -Axiom ethereum_crypto_elliptic_curve_SECP256K1N : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". -Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". +Axiom ethereum_crypto_elliptic_curve_imports : + AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_left_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. -Require ethereum.gray_glacier.vm.__init__. -Axiom ethereum_gray_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Evm". +Axiom ethereum_gray_glacier_vm_imports : + AreImported globals "ethereum.gray_glacier.vm" [ "Evm" ]. -Require ethereum.gray_glacier.vm.gas. -Axiom ethereum_gray_glacier_vm_gas_GAS_ECRECOVER : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_ECRECOVER". -Axiom ethereum_gray_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "charge_gas". +Axiom ethereum_gray_glacier_vm_gas_imports : + AreImported globals "ethereum.gray_glacier.vm.gas" [ "GAS_ECRECOVER"; "charge_gas" ]. -Require ethereum.gray_glacier.vm.memory. -Axiom ethereum_gray_glacier_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.gray_glacier.vm.memory.globals "buffer_read". +Axiom ethereum_gray_glacier_vm_memory_imports : + AreImported globals "ethereum.gray_glacier.vm.memory" [ "buffer_read" ]. Definition ecrecover : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -264,13 +251,18 @@ Definition ecrecover : Value.t -> Value.t -> M := )) |) in (* At stmt: unsupported node type: Try *) let address := - M.get_subscript (| M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "public_key" |) - ], - make_dict [] - |), M.slice (| Constant.int 12, Constant.int 32 |) |) in + M.slice (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), + Constant.int 12, + Constant.int 32, + Constant.None_ + |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/identity.v index 024d1db..8442cd7 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/identity.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/identity.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.gray_glacier.vm.precompiled_contracts.identity". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementation of the `IDENTITY` precompiled contract. ". -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.gray_glacier.vm.__init__. -Axiom ethereum_gray_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Evm". +Axiom ethereum_gray_glacier_vm_imports : + AreImported globals "ethereum.gray_glacier.vm" [ "Evm" ]. -Require ethereum.gray_glacier.vm.gas. -Axiom ethereum_gray_glacier_vm_gas_GAS_IDENTITY : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_IDENTITY". -Axiom ethereum_gray_glacier_vm_gas_GAS_IDENTITY_WORD : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_IDENTITY_WORD". -Axiom ethereum_gray_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "charge_gas". +Axiom ethereum_gray_glacier_vm_gas_imports : + AreImported globals "ethereum.gray_glacier.vm.gas" [ "GAS_IDENTITY"; "GAS_IDENTITY_WORD"; "charge_gas" ]. Definition identity : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/mapping.v index 1eade51..94e0d64 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/mapping.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/mapping.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.gray_glacier.vm.precompiled_contracts.mapping". Definition expr_1 : Value.t := Constant.str " @@ -17,66 +17,34 @@ Introduction Mapping of precompiled contracts their implementations. ". -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". - -Require ethereum.gray_glacier.fork_types. -Axiom ethereum_gray_glacier_fork_types_Address : - IsGlobalAlias globals ethereum.gray_glacier.fork_types.globals "Address". - -Require ethereum.gray_glacier.vm.precompiled_contracts.__init__. -Axiom ethereum_gray_glacier_vm_precompiled_contracts___init___ALT_BN128_ADD_ADDRESS : - IsGlobalAlias globals ethereum.gray_glacier.vm.precompiled_contracts.__init__.globals "ALT_BN128_ADD_ADDRESS". -Axiom ethereum_gray_glacier_vm_precompiled_contracts___init___ALT_BN128_MUL_ADDRESS : - IsGlobalAlias globals ethereum.gray_glacier.vm.precompiled_contracts.__init__.globals "ALT_BN128_MUL_ADDRESS". -Axiom ethereum_gray_glacier_vm_precompiled_contracts___init___ALT_BN128_PAIRING_CHECK_ADDRESS : - IsGlobalAlias globals ethereum.gray_glacier.vm.precompiled_contracts.__init__.globals "ALT_BN128_PAIRING_CHECK_ADDRESS". -Axiom ethereum_gray_glacier_vm_precompiled_contracts___init___BLAKE2F_ADDRESS : - IsGlobalAlias globals ethereum.gray_glacier.vm.precompiled_contracts.__init__.globals "BLAKE2F_ADDRESS". -Axiom ethereum_gray_glacier_vm_precompiled_contracts___init___ECRECOVER_ADDRESS : - IsGlobalAlias globals ethereum.gray_glacier.vm.precompiled_contracts.__init__.globals "ECRECOVER_ADDRESS". -Axiom ethereum_gray_glacier_vm_precompiled_contracts___init___IDENTITY_ADDRESS : - IsGlobalAlias globals ethereum.gray_glacier.vm.precompiled_contracts.__init__.globals "IDENTITY_ADDRESS". -Axiom ethereum_gray_glacier_vm_precompiled_contracts___init___MODEXP_ADDRESS : - IsGlobalAlias globals ethereum.gray_glacier.vm.precompiled_contracts.__init__.globals "MODEXP_ADDRESS". -Axiom ethereum_gray_glacier_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : - IsGlobalAlias globals ethereum.gray_glacier.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". -Axiom ethereum_gray_glacier_vm_precompiled_contracts___init___SHA256_ADDRESS : - IsGlobalAlias globals ethereum.gray_glacier.vm.precompiled_contracts.__init__.globals "SHA256_ADDRESS". - -Require ethereum.gray_glacier.vm.precompiled_contracts.alt_bn128. -Axiom ethereum_gray_glacier_vm_precompiled_contracts_alt_bn128_alt_bn128_add : - IsGlobalAlias globals ethereum.gray_glacier.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_add". -Axiom ethereum_gray_glacier_vm_precompiled_contracts_alt_bn128_alt_bn128_mul : - IsGlobalAlias globals ethereum.gray_glacier.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_mul". -Axiom ethereum_gray_glacier_vm_precompiled_contracts_alt_bn128_alt_bn128_pairing_check : - IsGlobalAlias globals ethereum.gray_glacier.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_pairing_check". - -Require ethereum.gray_glacier.vm.precompiled_contracts.blake2f. -Axiom ethereum_gray_glacier_vm_precompiled_contracts_blake2f_blake2f : - IsGlobalAlias globals ethereum.gray_glacier.vm.precompiled_contracts.blake2f.globals "blake2f". - -Require ethereum.gray_glacier.vm.precompiled_contracts.ecrecover. -Axiom ethereum_gray_glacier_vm_precompiled_contracts_ecrecover_ecrecover : - IsGlobalAlias globals ethereum.gray_glacier.vm.precompiled_contracts.ecrecover.globals "ecrecover". - -Require ethereum.gray_glacier.vm.precompiled_contracts.identity. -Axiom ethereum_gray_glacier_vm_precompiled_contracts_identity_identity : - IsGlobalAlias globals ethereum.gray_glacier.vm.precompiled_contracts.identity.globals "identity". - -Require ethereum.gray_glacier.vm.precompiled_contracts.modexp. -Axiom ethereum_gray_glacier_vm_precompiled_contracts_modexp_modexp : - IsGlobalAlias globals ethereum.gray_glacier.vm.precompiled_contracts.modexp.globals "modexp". - -Require ethereum.gray_glacier.vm.precompiled_contracts.ripemd160. -Axiom ethereum_gray_glacier_vm_precompiled_contracts_ripemd160_ripemd160 : - IsGlobalAlias globals ethereum.gray_glacier.vm.precompiled_contracts.ripemd160.globals "ripemd160". - -Require ethereum.gray_glacier.vm.precompiled_contracts.sha256. -Axiom ethereum_gray_glacier_vm_precompiled_contracts_sha256_sha256 : - IsGlobalAlias globals ethereum.gray_glacier.vm.precompiled_contracts.sha256.globals "sha256". +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict" ]. + +Axiom ethereum_gray_glacier_fork_types_imports : + AreImported globals "ethereum.gray_glacier.fork_types" [ "Address" ]. + +Axiom ethereum_gray_glacier_vm_precompiled_contracts_imports : + AreImported globals "ethereum.gray_glacier.vm.precompiled_contracts" [ "ALT_BN128_ADD_ADDRESS"; "ALT_BN128_MUL_ADDRESS"; "ALT_BN128_PAIRING_CHECK_ADDRESS"; "BLAKE2F_ADDRESS"; "ECRECOVER_ADDRESS"; "IDENTITY_ADDRESS"; "MODEXP_ADDRESS"; "RIPEMD160_ADDRESS"; "SHA256_ADDRESS" ]. + +Axiom ethereum_gray_glacier_vm_precompiled_contracts_alt_bn128_imports : + AreImported globals "ethereum.gray_glacier.vm.precompiled_contracts.alt_bn128" [ "alt_bn128_add"; "alt_bn128_mul"; "alt_bn128_pairing_check" ]. + +Axiom ethereum_gray_glacier_vm_precompiled_contracts_blake2f_imports : + AreImported globals "ethereum.gray_glacier.vm.precompiled_contracts.blake2f" [ "blake2f" ]. + +Axiom ethereum_gray_glacier_vm_precompiled_contracts_ecrecover_imports : + AreImported globals "ethereum.gray_glacier.vm.precompiled_contracts.ecrecover" [ "ecrecover" ]. + +Axiom ethereum_gray_glacier_vm_precompiled_contracts_identity_imports : + AreImported globals "ethereum.gray_glacier.vm.precompiled_contracts.identity" [ "identity" ]. + +Axiom ethereum_gray_glacier_vm_precompiled_contracts_modexp_imports : + AreImported globals "ethereum.gray_glacier.vm.precompiled_contracts.modexp" [ "modexp" ]. + +Axiom ethereum_gray_glacier_vm_precompiled_contracts_ripemd160_imports : + AreImported globals "ethereum.gray_glacier.vm.precompiled_contracts.ripemd160" [ "ripemd160" ]. + +Axiom ethereum_gray_glacier_vm_precompiled_contracts_sha256_imports : + AreImported globals "ethereum.gray_glacier.vm.precompiled_contracts.sha256" [ "sha256" ]. (* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/modexp.v index 40654e2..8c46415 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/modexp.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/modexp.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.gray_glacier.vm.precompiled_contracts.modexp". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementation of the `MODEXP` precompiled contract. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. -Require ethereum.gray_glacier.vm.__init__. -Axiom ethereum_gray_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Evm". +Axiom ethereum_gray_glacier_vm_imports : + AreImported globals "ethereum.gray_glacier.vm" [ "Evm" ]. -Require ethereum.gray_glacier.vm.gas. -Axiom ethereum_gray_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "charge_gas". +Axiom ethereum_gray_glacier_vm_gas_imports : + AreImported globals "ethereum.gray_glacier.vm.gas" [ "charge_gas" ]. -Require ethereum.gray_glacier.vm.memory. -Axiom ethereum_gray_glacier_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.gray_glacier.vm.memory.globals "buffer_read". +Axiom ethereum_gray_glacier_vm_memory_imports : + AreImported globals "ethereum.gray_glacier.vm.memory" [ "buffer_read" ]. Definition GQUADDIVISOR : Value.t := M.run ltac:(M.monadic ( Constant.int 3 diff --git a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/ripemd160.v index 88a93f9..5766b64 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/ripemd160.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/ripemd160.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.gray_glacier.vm.precompiled_contracts.ripemd160". Definition expr_1 : Value.t := Constant.str " @@ -19,29 +19,20 @@ Implementation of the `RIPEMD160` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_left_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.gray_glacier.vm.__init__. -Axiom ethereum_gray_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Evm". +Axiom ethereum_gray_glacier_vm_imports : + AreImported globals "ethereum.gray_glacier.vm" [ "Evm" ]. -Require ethereum.gray_glacier.vm.gas. -Axiom ethereum_gray_glacier_vm_gas_GAS_RIPEMD160 : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_RIPEMD160". -Axiom ethereum_gray_glacier_vm_gas_GAS_RIPEMD160_WORD : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_RIPEMD160_WORD". -Axiom ethereum_gray_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "charge_gas". +Axiom ethereum_gray_glacier_vm_gas_imports : + AreImported globals "ethereum.gray_glacier.vm.gas" [ "GAS_RIPEMD160"; "GAS_RIPEMD160_WORD"; "charge_gas" ]. Definition ripemd160 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/sha256.v index 4d0cb65..8a9ad1b 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/sha256.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/sha256.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.gray_glacier.vm.precompiled_contracts.sha256". Definition expr_1 : Value.t := Constant.str " @@ -19,25 +19,17 @@ Implementation of the `SHA256` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.gray_glacier.vm.__init__. -Axiom ethereum_gray_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.gray_glacier.vm.__init__.globals "Evm". +Axiom ethereum_gray_glacier_vm_imports : + AreImported globals "ethereum.gray_glacier.vm" [ "Evm" ]. -Require ethereum.gray_glacier.vm.gas. -Axiom ethereum_gray_glacier_vm_gas_GAS_SHA256 : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_SHA256". -Axiom ethereum_gray_glacier_vm_gas_GAS_SHA256_WORD : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "GAS_SHA256_WORD". -Axiom ethereum_gray_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.gray_glacier.vm.gas.globals "charge_gas". +Axiom ethereum_gray_glacier_vm_gas_imports : + AreImported globals "ethereum.gray_glacier.vm.gas" [ "GAS_SHA256"; "GAS_SHA256_WORD"; "charge_gas" ]. Definition sha256 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/gray_glacier/vm/runtime.v b/CoqOfPython/ethereum/gray_glacier/vm/runtime.v index 10332e5..6cb1c91 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/runtime.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/runtime.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.gray_glacier.vm.runtime". Definition expr_1 : Value.t := Constant.str " @@ -17,17 +17,14 @@ Introduction Runtime related operations used while executing EVM code. ". -Require typing. -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". +Axiom typing_imports : + AreImported globals "typing" [ "Set" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.gray_glacier.vm.instructions.__init__. -Axiom ethereum_gray_glacier_vm_instructions___init___Ops : - IsGlobalAlias globals ethereum.gray_glacier.vm.instructions.__init__.globals "Ops". +Axiom ethereum_gray_glacier_vm_instructions_imports : + AreImported globals "ethereum.gray_glacier.vm.instructions" [ "Ops" ]. Definition get_valid_jump_destinations : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -67,75 +64,83 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := ], make_dict [] |) in - While Compare.lt (| - M.get_name (| globals, "pc" |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "code" |) - ], - make_dict [] - |) - |) do -(* At stmt: unsupported node type: Try *) - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "current_opcode" |), - M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) - |), - (* then *) + let _ := + M.while (| + Compare.lt (| + M.get_name (| globals, "pc" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) + |), ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), - make_list [ - M.get_name (| globals, "pc" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( +(* At stmt: unsupported node type: Try *) let _ := (* if *) M.if_then_else (| - BoolOp.and (| - Compare.lt_e (| - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |), - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |) - |), - ltac:(M.monadic ( - Compare.lt_e (| - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH32" |), "value" |) - |) - )) + Compare.eq (| + M.get_name (| globals, "current_opcode" |), + M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) |), (* then *) ltac:(M.monadic ( - let push_data_size := - BinOp.add (| - BinOp.sub (| - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) - |), - Constant.int 1 - |) in - let pc := BinOp.add - M.get_name (| globals, "push_data_size" |) - M.get_name (| globals, "push_data_size" |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), + make_list [ + M.get_name (| globals, "pc" |) + ], + make_dict [] + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.lt_e (| + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |), + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH32" |), "value" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let push_data_size := + BinOp.add (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) + |), + Constant.int 1 + |) in + let pc := BinOp.add + M.get_name (| globals, "push_data_size" |) + M.get_name (| globals, "push_data_size" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ )) |) in + let pc := BinOp.add + Constant.int 1 + Constant.int 1 in M.pure Constant.None_ - )) |) in - let pc := BinOp.add - Constant.int 1 - Constant.int 1 in - EndWhile. + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.get_name (| globals, "valid_jump_destinations" |) |) in diff --git a/CoqOfPython/ethereum/gray_glacier/vm/stack.v b/CoqOfPython/ethereum/gray_glacier/vm/stack.v index 274024e..8f04eae 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/stack.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/stack.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.gray_glacier.vm.stack". Definition expr_1 : Value.t := Constant.str " @@ -17,19 +17,14 @@ Introduction Implementation of the stack operators for the EVM. ". -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". +Axiom typing_imports : + AreImported globals "typing" [ "List" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.gray_glacier.vm.exceptions. -Axiom ethereum_gray_glacier_vm_exceptions_StackOverflowError : - IsGlobalAlias globals ethereum.gray_glacier.vm.exceptions.globals "StackOverflowError". -Axiom ethereum_gray_glacier_vm_exceptions_StackUnderflowError : - IsGlobalAlias globals ethereum.gray_glacier.vm.exceptions.globals "StackUnderflowError". +Axiom ethereum_gray_glacier_vm_exceptions_imports : + AreImported globals "ethereum.gray_glacier.vm.exceptions" [ "StackOverflowError"; "StackUnderflowError" ]. Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -63,7 +58,7 @@ Definition pop : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "StackUnderflowError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "StackUnderflowError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -108,7 +103,7 @@ Definition push : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "StackOverflowError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "StackOverflowError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/homestead/__init__.v b/CoqOfPython/ethereum/homestead/__init__.v index b8c6ea5..cc7997c 100644 --- a/CoqOfPython/ethereum/homestead/__init__.v +++ b/CoqOfPython/ethereum/homestead/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.homestead.__init__". Definition expr_1 : Value.t := Constant.str " @@ -10,9 +10,8 @@ the behavior of contract creation with insufficient gas, delays the difficulty bomb, and adds an improved delegate call EVM instruction. ". -Require ethereum.fork_criteria. -Axiom ethereum_fork_criteria_ByBlockNumber : - IsGlobalAlias globals ethereum.fork_criteria.globals "ByBlockNumber". +Axiom ethereum_fork_criteria_imports : + AreImported globals "ethereum.fork_criteria" [ "ByBlockNumber" ]. Definition FORK_CRITERIA : Value.t := M.run ltac:(M.monadic ( M.call (| diff --git a/CoqOfPython/ethereum/homestead/blocks.v b/CoqOfPython/ethereum/homestead/blocks.v index f541174..a725a0e 100644 --- a/CoqOfPython/ethereum/homestead/blocks.v +++ b/CoqOfPython/ethereum/homestead/blocks.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.homestead.blocks". Definition expr_1 : Value.t := Constant.str " @@ -14,43 +14,23 @@ history of all state transitions that have happened since the genesis of the chain. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes8 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes8". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". - -Require ethereum.homestead.fork_types. -Axiom ethereum_homestead_fork_types_Address : - IsGlobalAlias globals ethereum.homestead.fork_types.globals "Address". -Axiom ethereum_homestead_fork_types_Bloom : - IsGlobalAlias globals ethereum.homestead.fork_types.globals "Bloom". -Axiom ethereum_homestead_fork_types_Root : - IsGlobalAlias globals ethereum.homestead.fork_types.globals "Root". - -Require ethereum.homestead.transactions. -Axiom ethereum_homestead_transactions_Transaction : - IsGlobalAlias globals ethereum.homestead.transactions.globals "Transaction". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes8"; "Bytes32"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. + +Axiom ethereum_homestead_fork_types_imports : + AreImported globals "ethereum.homestead.fork_types" [ "Address"; "Bloom"; "Root" ]. + +Axiom ethereum_homestead_transactions_imports : + AreImported globals "ethereum.homestead.transactions" [ "Transaction" ]. Definition Header : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/homestead/bloom.v b/CoqOfPython/ethereum/homestead/bloom.v index 638e95a..412a1c1 100644 --- a/CoqOfPython/ethereum/homestead/bloom.v +++ b/CoqOfPython/ethereum/homestead/bloom.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.homestead.bloom". Definition expr_1 : Value.t := Constant.str " @@ -21,25 +21,20 @@ for efficient searching of logs by address and/or topic, by rapidly eliminating blocks and receipts from their search. ". -Require typing. -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_imports : + AreImported globals "typing" [ "Tuple" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. -Require ethereum.homestead.blocks. -Axiom ethereum_homestead_blocks_Log : - IsGlobalAlias globals ethereum.homestead.blocks.globals "Log". +Axiom ethereum_homestead_blocks_imports : + AreImported globals "ethereum.homestead.blocks" [ "Log" ]. -Require ethereum.homestead.fork_types. -Axiom ethereum_homestead_fork_types_Bloom : - IsGlobalAlias globals ethereum.homestead.fork_types.globals "Bloom". +Axiom ethereum_homestead_fork_types_imports : + AreImported globals "ethereum.homestead.fork_types" [ "Bloom" ]. Definition add_to_bloom : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -66,50 +61,70 @@ Definition add_to_bloom : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "idx" |) in make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ] do - let bit_to_set := - BinOp.bit_and (| - M.call (| - M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "hash" |), M.slice (| M.get_name (| globals, "idx" |), BinOp.add (| - M.get_name (| globals, "idx" |), - Constant.int 2 - |) |) |) - ], - make_dict [] - |), - Constant.int 2047 - |) in - let bit_index := - BinOp.sub (| - Constant.int 2047, - M.get_name (| globals, "bit_to_set" |) - |) in - let byte_index := - BinOp.floor_div (| - M.get_name (| globals, "bit_index" |), - Constant.int 8 - |) in - let bit_value := - BinOp.l_shift (| - Constant.int 1, - BinOp.sub (| - Constant.int 7, - BinOp.mod_ (| + let _ := + M.for_ (| + M.get_name (| globals, "idx" |), + make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ], + ltac:(M.monadic ( + let bit_to_set := + BinOp.bit_and (| + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.slice (| + M.get_name (| globals, "hash" |), + M.get_name (| globals, "idx" |), + BinOp.add (| + M.get_name (| globals, "idx" |), + Constant.int 2 + |), + Constant.None_ + |) + ], + make_dict [] + |), + Constant.int 2047 + |) in + let bit_index := + BinOp.sub (| + Constant.int 2047, + M.get_name (| globals, "bit_to_set" |) + |) in + let byte_index := + BinOp.floor_div (| M.get_name (| globals, "bit_index" |), Constant.int 8 + |) in + let bit_value := + BinOp.l_shift (| + Constant.int 1, + BinOp.sub (| + Constant.int 7, + BinOp.mod_ (| + M.get_name (| globals, "bit_index" |), + Constant.int 8 + |) + |) + |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "bloom" |), + M.get_name (| globals, "byte_index" |) + |), + BinOp.bit_or (| + M.get_subscript (| + M.get_name (| globals, "bloom" |), + M.get_name (| globals, "byte_index" |) + |), + M.get_name (| globals, "bit_value" |) |) - |) - |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), - BinOp.bit_or (| - M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), - M.get_name (| globals, "bit_value" |) - |) - |) in - EndFor. + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_)). Definition logs_bloom : Value.t -> Value.t -> M := @@ -132,8 +147,12 @@ Definition logs_bloom : Value.t -> Value.t -> M := the caller address and the log topics. " in (* At stmt: unsupported node type: AnnAssign *) - For M.get_name (| globals, "log" |) in M.get_name (| globals, "logs" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "log" |), + M.get_name (| globals, "logs" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "add_to_bloom" |), make_list [ M.get_name (| globals, "bloom" |); @@ -141,8 +160,12 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "topic" |) in M.get_field (| M.get_name (| globals, "log" |), "topics" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "topic" |), + M.get_field (| M.get_name (| globals, "log" |), "topics" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "add_to_bloom" |), make_list [ M.get_name (| globals, "bloom" |); @@ -150,8 +173,18 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Bloom" |), diff --git a/CoqOfPython/ethereum/homestead/fork.v b/CoqOfPython/ethereum/homestead/fork.v index 80befd6..4c5e111 100644 --- a/CoqOfPython/ethereum/homestead/fork.v +++ b/CoqOfPython/ethereum/homestead/fork.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.homestead.fork". Definition expr_1 : Value.t := Constant.str " @@ -17,139 +17,62 @@ Introduction Entry point for the Ethereum specification. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". - -Require ethereum.crypto.elliptic_curve. -Axiom ethereum_crypto_elliptic_curve_SECP256K1N : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". -Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.ethash. -Axiom ethereum_ethash_dataset_size : - IsGlobalAlias globals ethereum.ethash.globals "dataset_size". -Axiom ethereum_ethash_generate_cache : - IsGlobalAlias globals ethereum.ethash.globals "generate_cache". -Axiom ethereum_ethash_hashimoto_light : - IsGlobalAlias globals ethereum.ethash.globals "hashimoto_light". - -Require ethereum.exceptions. -Axiom ethereum_exceptions_InvalidBlock : - IsGlobalAlias globals ethereum.exceptions.globals "InvalidBlock". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U64 : - IsGlobalAlias globals ethereum.base_types.globals "U64". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_U256_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.homestead.__init__. -Axiom ethereum_homestead___init___vm : - IsGlobalAlias globals ethereum.homestead.__init__.globals "vm". - -Require ethereum.homestead.blocks. -Axiom ethereum_homestead_blocks_Block : - IsGlobalAlias globals ethereum.homestead.blocks.globals "Block". -Axiom ethereum_homestead_blocks_Header : - IsGlobalAlias globals ethereum.homestead.blocks.globals "Header". -Axiom ethereum_homestead_blocks_Log : - IsGlobalAlias globals ethereum.homestead.blocks.globals "Log". -Axiom ethereum_homestead_blocks_Receipt : - IsGlobalAlias globals ethereum.homestead.blocks.globals "Receipt". - -Require ethereum.homestead.bloom. -Axiom ethereum_homestead_bloom_logs_bloom : - IsGlobalAlias globals ethereum.homestead.bloom.globals "logs_bloom". - -Require ethereum.homestead.fork_types. -Axiom ethereum_homestead_fork_types_Address : - IsGlobalAlias globals ethereum.homestead.fork_types.globals "Address". -Axiom ethereum_homestead_fork_types_Bloom : - IsGlobalAlias globals ethereum.homestead.fork_types.globals "Bloom". -Axiom ethereum_homestead_fork_types_Root : - IsGlobalAlias globals ethereum.homestead.fork_types.globals "Root". - -Require ethereum.homestead.state. -Axiom ethereum_homestead_state_State : - IsGlobalAlias globals ethereum.homestead.state.globals "State". -Axiom ethereum_homestead_state_create_ether : - IsGlobalAlias globals ethereum.homestead.state.globals "create_ether". -Axiom ethereum_homestead_state_destroy_account : - IsGlobalAlias globals ethereum.homestead.state.globals "destroy_account". -Axiom ethereum_homestead_state_get_account : - IsGlobalAlias globals ethereum.homestead.state.globals "get_account". -Axiom ethereum_homestead_state_increment_nonce : - IsGlobalAlias globals ethereum.homestead.state.globals "increment_nonce". -Axiom ethereum_homestead_state_set_account_balance : - IsGlobalAlias globals ethereum.homestead.state.globals "set_account_balance". -Axiom ethereum_homestead_state_state_root : - IsGlobalAlias globals ethereum.homestead.state.globals "state_root". - -Require ethereum.homestead.transactions. -Axiom ethereum_homestead_transactions_TX_BASE_COST : - IsGlobalAlias globals ethereum.homestead.transactions.globals "TX_BASE_COST". -Axiom ethereum_homestead_transactions_TX_CREATE_COST : - IsGlobalAlias globals ethereum.homestead.transactions.globals "TX_CREATE_COST". -Axiom ethereum_homestead_transactions_TX_DATA_COST_PER_NON_ZERO : - IsGlobalAlias globals ethereum.homestead.transactions.globals "TX_DATA_COST_PER_NON_ZERO". -Axiom ethereum_homestead_transactions_TX_DATA_COST_PER_ZERO : - IsGlobalAlias globals ethereum.homestead.transactions.globals "TX_DATA_COST_PER_ZERO". -Axiom ethereum_homestead_transactions_Transaction : - IsGlobalAlias globals ethereum.homestead.transactions.globals "Transaction". - -Require ethereum.homestead.trie. -Axiom ethereum_homestead_trie_Trie : - IsGlobalAlias globals ethereum.homestead.trie.globals "Trie". -Axiom ethereum_homestead_trie_root : - IsGlobalAlias globals ethereum.homestead.trie.globals "root". -Axiom ethereum_homestead_trie_trie_set : - IsGlobalAlias globals ethereum.homestead.trie.globals "trie_set". - -Require ethereum.homestead.utils.message. -Axiom ethereum_homestead_utils_message_prepare_message : - IsGlobalAlias globals ethereum.homestead.utils.message.globals "prepare_message". - -Require ethereum.homestead.vm.interpreter. -Axiom ethereum_homestead_vm_interpreter_process_message_call : - IsGlobalAlias globals ethereum.homestead.vm.interpreter.globals "process_message_call". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Bytes0" ]. + +Axiom ethereum_crypto_elliptic_curve_imports : + AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. + +Axiom ethereum_ethash_imports : + AreImported globals "ethereum.ethash" [ "dataset_size"; "generate_cache"; "hashimoto_light" ]. + +Axiom ethereum_exceptions_imports : + AreImported globals "ethereum.exceptions" [ "InvalidBlock" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U64"; "U256"; "U256_CEIL_VALUE"; "Bytes"; "Bytes32"; "Uint" ]. + +Axiom ethereum_homestead_imports : + AreImported globals "ethereum.homestead" [ "vm" ]. + +Axiom ethereum_homestead_blocks_imports : + AreImported globals "ethereum.homestead.blocks" [ "Block"; "Header"; "Log"; "Receipt" ]. + +Axiom ethereum_homestead_bloom_imports : + AreImported globals "ethereum.homestead.bloom" [ "logs_bloom" ]. + +Axiom ethereum_homestead_fork_types_imports : + AreImported globals "ethereum.homestead.fork_types" [ "Address"; "Bloom"; "Root" ]. + +Axiom ethereum_homestead_state_imports : + AreImported globals "ethereum.homestead.state" [ "State"; "create_ether"; "destroy_account"; "get_account"; "increment_nonce"; "set_account_balance"; "state_root" ]. + +Axiom ethereum_homestead_transactions_imports : + AreImported globals "ethereum.homestead.transactions" [ "TX_BASE_COST"; "TX_CREATE_COST"; "TX_DATA_COST_PER_NON_ZERO"; "TX_DATA_COST_PER_ZERO"; "Transaction" ]. + +Axiom ethereum_homestead_trie_imports : + AreImported globals "ethereum.homestead.trie" [ "Trie"; "root"; "trie_set" ]. + +Axiom ethereum_homestead_utils_message_imports : + AreImported globals "ethereum.homestead.utils.message" [ "prepare_message" ]. + +Axiom ethereum_homestead_vm_interpreter_imports : + AreImported globals "ethereum.homestead.vm.interpreter" [ "process_message_call" ]. Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -248,7 +171,12 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := Hashes of the recent 256 blocks in order of increasing block number. " in let recent_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) in + M.slice (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| Constant.int 255 |), + Constant.None_, + Constant.None_ + |) in let _ := (* if *) M.if_then_else (| @@ -274,17 +202,26 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := )) |) in let recent_block_hashes := make_list [] in - For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_blocks" |) do - let prev_block_hash := - M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "block" |), + M.get_name (| globals, "recent_blocks" |), + ltac:(M.monadic ( + let prev_block_hash := + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in + let _ := M.call (| M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), make_list [ M.get_name (| globals, "prev_block_hash" |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let most_recent_block_hash := M.call (| M.get_name (| globals, "keccak256" |), @@ -292,7 +229,10 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), make_list [ - M.get_field (| M.get_subscript (| M.get_name (| globals, "recent_blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) + M.get_field (| M.get_subscript (| + M.get_name (| globals, "recent_blocks" |), + UnOp.sub (| Constant.int 1 |) + |), "header" |) ], make_dict [] |) @@ -336,7 +276,10 @@ Definition state_transition : Value.t -> Value.t -> M := Block to apply to `chain`. " in let parent_header := - M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) in + M.get_field (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| Constant.int 1 |) + |), "header" |) in let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ @@ -455,7 +398,12 @@ Definition state_transition : Value.t -> Value.t -> M := ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) + M.slice (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| Constant.int 255 |), + Constant.None_, + Constant.None_ + |) |) in M.pure Constant.None_ (* else *) @@ -871,14 +819,18 @@ Definition apply_body : Value.t -> Value.t -> M := (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) - For make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "tx" |) ] in M.call (| - M.get_name (| globals, "enumerate" |), - make_list [ - M.get_name (| globals, "transactions" |) - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "tx" |) ], + M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "transactions" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ M.get_name (| globals, "transactions_trie" |); @@ -899,56 +851,56 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_address := - M.call (| - M.get_name (| globals, "check_transaction" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "gas_available" |) - ], - make_dict [] - |) in - let env := - M.call (| - M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), - make_list [], - make_dict [] - |) in - let _ := M.assign (| - make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |) ], - M.call (| - M.get_name (| globals, "process_transaction" |), - make_list [ - M.get_name (| globals, "env" |); - M.get_name (| globals, "tx" |) - ], - make_dict [] - |) - |) in - let gas_available := BinOp.sub - M.get_name (| globals, "gas_used" |) - M.get_name (| globals, "gas_used" |) in - let receipt := - M.call (| - M.get_name (| globals, "make_receipt" |), - make_list [ - M.get_name (| globals, "tx" |); + let sender_address := M.call (| - M.get_name (| globals, "state_root" |), + M.get_name (| globals, "check_transaction" |), make_list [ - M.get_name (| globals, "state" |) + M.get_name (| globals, "tx" |); + M.get_name (| globals, "gas_available" |) ], make_dict [] - |); - BinOp.sub (| - M.get_name (| globals, "block_gas_limit" |), - M.get_name (| globals, "gas_available" |) - |); - M.get_name (| globals, "logs" |) - ], - make_dict [] - |) in - let _ := M.call (| + |) in + let env := + M.call (| + M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |) ], + M.call (| + M.get_name (| globals, "process_transaction" |), + make_list [ + M.get_name (| globals, "env" |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) in + let gas_available := BinOp.sub + M.get_name (| globals, "gas_used" |) + M.get_name (| globals, "gas_used" |) in + let receipt := + M.call (| + M.get_name (| globals, "make_receipt" |), + make_list [ + M.get_name (| globals, "tx" |); + M.call (| + M.get_name (| globals, "state_root" |), + make_list [ + M.get_name (| globals, "state" |) + ], + make_dict [] + |); + BinOp.sub (| + M.get_name (| globals, "block_gas_limit" |), + M.get_name (| globals, "gas_available" |) + |); + M.get_name (| globals, "logs" |) + ], + make_dict [] + |) in + let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ M.get_name (| globals, "receipts_trie" |); @@ -969,10 +921,15 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_logs := BinOp.add - M.get_name (| globals, "logs" |) - M.get_name (| globals, "logs" |) in - EndFor. + let block_logs := BinOp.add + M.get_name (| globals, "logs" |) + M.get_name (| globals, "logs" |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.call (| M.get_name (| globals, "pay_rewards" |), make_list [ @@ -1101,8 +1058,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "ommer" |), + M.get_name (| globals, "ommers" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ BoolOp.and (| @@ -1121,15 +1082,18 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_parent_header := - M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), BinOp.sub (| - UnOp.sub (| BinOp.sub (| - M.get_field (| M.get_name (| globals, "block_header" |), "number" |), - M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) |), - Constant.int 1 - |) |), "header" |) in - let _ := M.call (| + let ommer_parent_header := + M.get_field (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + BinOp.sub (| + UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) |), + Constant.int 1 + |) + |), "header" |) in + let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ M.get_name (| globals, "ommer" |); @@ -1137,7 +1101,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1187,33 +1156,54 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let recent_canonical_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| BinOp.add (| - M.get_name (| globals, "MAX_OMMER_DEPTH" |), - Constant.int 1 - |) |), Constant.None_ |) |) in + M.slice (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| BinOp.add (| + M.get_name (| globals, "MAX_OMMER_DEPTH" |), + Constant.int 1 + |) |), + Constant.None_, + Constant.None_ + |) in let recent_canonical_block_hashes := Constant.str "(* At expr: unsupported node type: SetComp *)" in (* At stmt: unsupported node type: AnnAssign *) - For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_canonical_blocks" |) do - let recent_ommers_hashes := + let _ := + M.for_ (| + M.get_name (| globals, "block" |), + M.get_name (| globals, "recent_canonical_blocks" |), + ltac:(M.monadic ( + let recent_ommers_hashes := + M.call (| + M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), + make_list [ + Constant.str "(* At expr: unsupported node type: SetComp *)" + ], + make_dict [] + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "ommer_index" |); M.get_name (| globals, "ommer" |) ], M.call (| - M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), - make_list [ - Constant.str "(* At expr: unsupported node type: SetComp *)" - ], - make_dict [] - |) in - EndFor. - For make_tuple [ M.get_name (| globals, "ommer_index" |); M.get_name (| globals, "ommer" |) ] in M.call (| - M.get_name (| globals, "enumerate" |), - make_list [ - M.get_name (| globals, "ommers" |) - ], - make_dict [] - |) do - let ommer_hash := - M.get_subscript (| M.get_name (| globals, "ommers_hashes" |), M.get_name (| globals, "ommer_index" |) |) in - let _ := M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let ommer_hash := + M.get_subscript (| + M.get_name (| globals, "ommers_hashes" |), + M.get_name (| globals, "ommer_index" |) + |) in + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_eq (| @@ -1224,7 +1214,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_in (| @@ -1235,7 +1225,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_in (| @@ -1246,12 +1236,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_age := - BinOp.sub (| - M.get_field (| M.get_name (| globals, "block_header" |), "number" |), - M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) in - let _ := M.call (| + let ommer_age := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) in + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ BoolOp.and (| @@ -1270,10 +1260,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.in (| + Compare.in_ (| M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), M.get_name (| globals, "recent_canonical_block_hashes" |) |); @@ -1281,7 +1271,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_eq (| @@ -1292,7 +1282,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_)). Definition pay_rewards : Value.t -> Value.t -> M := @@ -1349,30 +1344,34 @@ Definition pay_rewards : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do - let ommer_age := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - BinOp.sub (| - M.get_name (| globals, "block_number" |), - M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) - ], - make_dict [] - |) in - let ommer_miner_reward := - BinOp.floor_div (| - BinOp.mult (| - BinOp.sub (| - Constant.int 8, - M.get_name (| globals, "ommer_age" |) - |), - M.get_name (| globals, "BLOCK_REWARD" |) - |), - Constant.int 8 - |) in - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "ommer" |), + M.get_name (| globals, "ommers" |), + ltac:(M.monadic ( + let ommer_age := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "block_number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) + ], + make_dict [] + |) in + let ommer_miner_reward := + BinOp.floor_div (| + BinOp.mult (| + BinOp.sub (| + Constant.int 8, + M.get_name (| globals, "ommer_age" |) + |), + M.get_name (| globals, "BLOCK_REWARD" |) + |), + Constant.int 8 + |) in + let _ := M.call (| M.get_name (| globals, "create_ether" |), make_list [ M.get_name (| globals, "state" |); @@ -1381,7 +1380,12 @@ Definition pay_rewards : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_)). Definition process_transaction : Value.t -> Value.t -> M := @@ -1621,8 +1625,12 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "accounts_to_delete" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "output" |), "accounts_to_delete" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "destroy_account" |), make_list [ M.get_field (| M.get_name (| globals, "env" |), "state" |); @@ -1630,7 +1638,12 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |) ] |) in @@ -1718,28 +1731,37 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := " in let data_cost := Constant.int 0 in - For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "byte" |), - Constant.int 0 - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "byte" |), + M.get_field (| M.get_name (| globals, "tx" |), "data" |), ltac:(M.monadic ( - let data_cost := BinOp.add - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "byte" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let data_cost := BinOp.add - M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := (* if *) M.if_then_else (| @@ -1891,13 +1913,18 @@ Definition recover_sender : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "Address" |), make_list [ - M.get_subscript (| M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "public_key" |) - ], - make_dict [] - |), M.slice (| Constant.int 12, Constant.int 32 |) |) + M.slice (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), + Constant.int 12, + Constant.int 32, + Constant.None_ + |) ], make_dict [] |) diff --git a/CoqOfPython/ethereum/homestead/fork_types.v b/CoqOfPython/ethereum/homestead/fork_types.v index cc8e4a1..90a973d 100644 --- a/CoqOfPython/ethereum/homestead/fork_types.v +++ b/CoqOfPython/ethereum/homestead/fork_types.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.homestead.fork_types". Definition expr_1 : Value.t := Constant.str " @@ -17,33 +17,17 @@ Introduction Types re-used throughout the specification, which are specific to Ethereum. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes20 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes20". -Axiom ethereum_base_types_Bytes256 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes20"; "Bytes256"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) diff --git a/CoqOfPython/ethereum/homestead/state.v b/CoqOfPython/ethereum/homestead/state.v index 576dfb0..6053a03 100644 --- a/CoqOfPython/ethereum/homestead/state.v +++ b/CoqOfPython/ethereum/homestead/state.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.homestead.state". Definition expr_1 : Value.t := Constant.str " @@ -22,61 +22,23 @@ There is a distinction between an account that does not exist and `EMPTY_ACCOUNT`. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". -Axiom dataclasses_field : - IsGlobalAlias globals dataclasses.globals "field". - -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_modify : - IsGlobalAlias globals ethereum.base_types.globals "modify". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.homestead.fork_types. -Axiom ethereum_homestead_fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals ethereum.homestead.fork_types.globals "EMPTY_ACCOUNT". -Axiom ethereum_homestead_fork_types_Account : - IsGlobalAlias globals ethereum.homestead.fork_types.globals "Account". -Axiom ethereum_homestead_fork_types_Address : - IsGlobalAlias globals ethereum.homestead.fork_types.globals "Address". -Axiom ethereum_homestead_fork_types_Root : - IsGlobalAlias globals ethereum.homestead.fork_types.globals "Root". - -Require ethereum.homestead.trie. -Axiom ethereum_homestead_trie_EMPTY_TRIE_ROOT : - IsGlobalAlias globals ethereum.homestead.trie.globals "EMPTY_TRIE_ROOT". -Axiom ethereum_homestead_trie_Trie : - IsGlobalAlias globals ethereum.homestead.trie.globals "Trie". -Axiom ethereum_homestead_trie_copy_trie : - IsGlobalAlias globals ethereum.homestead.trie.globals "copy_trie". -Axiom ethereum_homestead_trie_root : - IsGlobalAlias globals ethereum.homestead.trie.globals "root". -Axiom ethereum_homestead_trie_trie_get : - IsGlobalAlias globals ethereum.homestead.trie.globals "trie_get". -Axiom ethereum_homestead_trie_trie_set : - IsGlobalAlias globals ethereum.homestead.trie.globals "trie_set". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass"; "field" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict"; "List"; "Optional"; "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "modify" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_homestead_fork_types_imports : + AreImported globals "ethereum.homestead.fork_types" [ "EMPTY_ACCOUNT"; "Account"; "Address"; "Root" ]. + +Axiom ethereum_homestead_trie_imports : + AreImported globals "ethereum.homestead.trie" [ "EMPTY_TRIE_ROOT"; "Trie"; "copy_trie"; "root"; "trie_get"; "trie_set" ]. Definition State : Value.t := builtins.make_klass @@ -338,13 +300,16 @@ Definition destroy_storage : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -479,7 +444,10 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), + M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |), M.get_name (| globals, "trie" |) |) in M.pure Constant.None_ @@ -505,7 +473,10 @@ Definition set_storage : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -535,7 +506,7 @@ Definition storage_root : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), @@ -545,7 +516,10 @@ Definition storage_root : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "root" |), make_list [ - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) + M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |) ], make_dict [] |) diff --git a/CoqOfPython/ethereum/homestead/transactions.v b/CoqOfPython/ethereum/homestead/transactions.v index 3db6fc4..32c8227 100644 --- a/CoqOfPython/ethereum/homestead/transactions.v +++ b/CoqOfPython/ethereum/homestead/transactions.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.homestead.transactions". Definition expr_1 : Value.t := Constant.str " @@ -9,29 +9,17 @@ submitted to be executed. If Ethereum is viewed as a state machine, transactions are the events that move between states. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.homestead.fork_types. -Axiom ethereum_homestead_fork_types_Address : - IsGlobalAlias globals ethereum.homestead.fork_types.globals "Address". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Union" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_homestead_fork_types_imports : + AreImported globals "ethereum.homestead.fork_types" [ "Address" ]. Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( Constant.int 21000 diff --git a/CoqOfPython/ethereum/homestead/trie.v b/CoqOfPython/ethereum/homestead/trie.v index a1932cd..fad7c92 100644 --- a/CoqOfPython/ethereum/homestead/trie.v +++ b/CoqOfPython/ethereum/homestead/trie.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.homestead.trie". Definition expr_1 : Value.t := Constant.str " @@ -20,83 +20,38 @@ The state trie is the structure responsible for storing (* At top_level_stmt: unsupported node type: Import *) -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". -Axiom dataclasses_field : - IsGlobalAlias globals dataclasses.globals "field". - -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". -Axiom typing_Generic : - IsGlobalAlias globals typing.globals "Generic". -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Mapping : - IsGlobalAlias globals typing.globals "Mapping". -Axiom typing_MutableMapping : - IsGlobalAlias globals typing.globals "MutableMapping". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Sequence : - IsGlobalAlias globals typing.globals "Sequence". -Axiom typing_TypeVar : - IsGlobalAlias globals typing.globals "TypeVar". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". -Axiom typing_cast : - IsGlobalAlias globals typing.globals "cast". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.frontier.__init__. -Axiom ethereum_frontier___init___trie : - IsGlobalAlias globals ethereum.frontier.__init__.globals "trie". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.utils.hexadecimal. -Axiom ethereum_utils_hexadecimal_hex_to_bytes : - IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.homestead.blocks. -Axiom ethereum_homestead_blocks_Receipt : - IsGlobalAlias globals ethereum.homestead.blocks.globals "Receipt". - -Require ethereum.homestead.fork_types. -Axiom ethereum_homestead_fork_types_Account : - IsGlobalAlias globals ethereum.homestead.fork_types.globals "Account". -Axiom ethereum_homestead_fork_types_Address : - IsGlobalAlias globals ethereum.homestead.fork_types.globals "Address". -Axiom ethereum_homestead_fork_types_Root : - IsGlobalAlias globals ethereum.homestead.fork_types.globals "Root". -Axiom ethereum_homestead_fork_types_encode_account : - IsGlobalAlias globals ethereum.homestead.fork_types.globals "encode_account". - -Require ethereum.homestead.transactions. -Axiom ethereum_homestead_transactions_Transaction : - IsGlobalAlias globals ethereum.homestead.transactions.globals "Transaction". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass"; "field" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict"; "Generic"; "List"; "Mapping"; "MutableMapping"; "Optional"; "Sequence"; "TypeVar"; "Union"; "cast" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. + +Axiom ethereum_frontier_imports : + AreImported globals "ethereum.frontier" [ "trie" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_utils_hexadecimal_imports : + AreImported globals "ethereum.utils.hexadecimal" [ "hex_to_bytes" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_homestead_blocks_imports : + AreImported globals "ethereum.homestead.blocks" [ "Receipt" ]. + +Axiom ethereum_homestead_fork_types_imports : + AreImported globals "ethereum.homestead.fork_types" [ "Account"; "Address"; "Root"; "encode_account" ]. + +Axiom ethereum_homestead_transactions_imports : + AreImported globals "ethereum.homestead.transactions" [ "Transaction" ]. Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -115,7 +70,10 @@ Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( )). Definition Node : Value.t := M.run ltac:(M.monadic ( - M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Bytes" |); M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |); Constant.None_ ] |) + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Bytes" |); M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |); Constant.None_ ] + |) )). Definition K : Value.t := M.run ltac:(M.monadic ( @@ -133,11 +91,23 @@ Definition V : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "TypeVar" |), make_list [ Constant.str "V"; - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Account" |) |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Bytes" |) |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Account" |) + |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Bytes" |) + |); M.get_name (| globals, "Bytes" |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Transaction" |) |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Receipt" |) |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Transaction" |) + |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Receipt" |) + |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |) ], @@ -176,7 +146,10 @@ Definition BranchNode : Value.t := ]. Definition InternalNode : Value.t := M.run ltac:(M.monadic ( - M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LeafNode" |); M.get_name (| globals, "ExtensionNode" |); M.get_name (| globals, "BranchNode" |) ] |) + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "LeafNode" |); M.get_name (| globals, "ExtensionNode" |); M.get_name (| globals, "BranchNode" |) ] + |) )). Definition encode_internal_node : Value.t -> Value.t -> M := @@ -288,7 +261,7 @@ Definition encode_internal_node : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "(* At expr: unsupported node type: JoinedStr *)" @@ -528,13 +501,16 @@ Definition trie_set : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "key" |), M.get_field (| M.get_name (| globals, "trie" |), "_data" |) |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + M.get_name (| globals, "key" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -544,7 +520,10 @@ Definition trie_set : Value.t -> Value.t -> M := (* else *) )), ltac:(M.monadic ( let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), + M.get_subscript (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + M.get_name (| globals, "key" |) + |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_ @@ -589,51 +568,66 @@ Definition common_prefix_length : Value.t -> Value.t -> M := let _ := Constant.str " Find the longest common prefix of two sequences. " in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "a" |) - ], - make_dict [] - |) - ], - make_dict [] - |) do - let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| - M.get_name (| globals, "i" |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "b" |) - ], - make_dict [] - |) - |), - ltac:(M.monadic ( - Compare.not_eq (| - M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), - M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) - |) - )) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + ], + make_dict [] + |), ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "i" |) - |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_subscript (| + M.get_name (| globals, "a" |), + M.get_name (| globals, "i" |) + |), + M.get_subscript (| + M.get_name (| globals, "b" |), + M.get_name (| globals, "i" |) + |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "len" |), @@ -718,38 +712,53 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 0; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |); - Constant.int 2 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ BinOp.add (| BinOp.mult (| Constant.int 16, - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "i" |) + |) |), - M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) + |) |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -767,43 +776,61 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := Constant.int 1 |) |), - M.get_subscript (| M.get_name (| globals, "x" |), Constant.int 0 |) + M.get_subscript (| + M.get_name (| globals, "x" |), + Constant.int 0 + |) |) ], make_dict [] |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 1; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |); - Constant.int 2 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 1; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ BinOp.add (| BinOp.mult (| Constant.int 16, - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "i" |) + |) |), - M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) + |) |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -850,40 +877,55 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := ], make_dict [] |) in - For make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ] in M.call (| - M.get_name (| globals, "enumerate" |), - make_list [ - M.get_name (| globals, "bytes_" |) - ], - make_dict [] - |) do - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.mult (| - M.get_name (| globals, "byte_index" |), - Constant.int 2 - |) |), - BinOp.r_shift (| - BinOp.bit_and (| - M.get_name (| globals, "byte" |), - Constant.int 240 - |), - Constant.int 4 - |) - |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "byte_index" |), - Constant.int 2 - |), - Constant.int 1 - |) |), - BinOp.bit_and (| - M.get_name (| globals, "byte" |), - Constant.int 15 - |) - |) in - EndFor. + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ], + M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "bytes_" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "nibble_list" |), + BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |) + |), + BinOp.r_shift (| + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 240 + |), + Constant.int 4 + |) + |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "nibble_list" |), + BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |), + Constant.int 1 + |) + |), + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 15 + |) + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Bytes" |), @@ -916,65 +958,69 @@ Definition _prepare_trie : Value.t -> Value.t -> M := Object with keys mapped to nibble-byte form. " in (* At stmt: unsupported node type: AnnAssign *) - For make_tuple [ M.get_name (| globals, "preimage" |); M.get_name (| globals, "value" |) ] in M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "items" |), - make_list [], - make_dict [] - |) do - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "value" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "preimage" |); M.get_name (| globals, "value" |) ], + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "items" |), + make_list [], + make_dict [] + |), ltac:(M.monadic ( - let _ := M.assert (| Compare.is_not (| + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in - let address := - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in - let encoded_value := - M.call (| - M.get_name (| globals, "encode_node" |), - make_list [ - M.get_name (| globals, "value" |); + let address := M.call (| - M.get_name (| globals, "get_storage_root" |), + M.get_name (| globals, "Address" |), make_list [ - M.get_name (| globals, "address" |) + M.get_name (| globals, "preimage" |) ], make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let encoded_value := - M.call (| - M.get_name (| globals, "encode_node" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - )) |) in - let _ := M.call (| + |) in + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |); + M.call (| + M.get_name (| globals, "get_storage_root" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_eq (| @@ -986,38 +1032,46 @@ Definition _prepare_trie : Value.t -> Value.t -> M := make_dict [] |) in (* At stmt: unsupported node type: AnnAssign *) - let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "trie" |), "secured" |), - (* then *) - ltac:(M.monadic ( - let key := - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "trie" |), "secured" |), + (* then *) + ltac:(M.monadic ( + let key := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let key := + M.get_name (| globals, "preimage" |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "mapped" |), + M.call (| + M.get_name (| globals, "bytes_to_nibble_list" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |) + |), + M.get_name (| globals, "encoded_value" |) + |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let key := - M.get_name (| globals, "preimage" |) in + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "mapped" |), M.call (| - M.get_name (| globals, "bytes_to_nibble_list" |), - make_list [ - M.get_name (| globals, "key" |) - ], - make_dict [] - |) |), - M.get_name (| globals, "encoded_value" |) - |) in - EndFor. + )) + |) in let _ := M.return_ (| M.get_name (| globals, "mapped" |) |) in @@ -1210,8 +1264,16 @@ Definition patricialize : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "LeafNode" |), make_list [ - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |); - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) + M.slice (| + M.get_name (| globals, "arbitrary_key" |), + M.get_name (| globals, "level" |), + Constant.None_, + Constant.None_ + |); + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "arbitrary_key" |) + |) ], make_dict [] |) in @@ -1224,7 +1286,12 @@ Definition patricialize : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in let substring := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "arbitrary_key" |), + M.get_name (| globals, "level" |), + Constant.None_, + Constant.None_ + |) in let prefix_length := M.call (| M.get_name (| globals, "len" |), @@ -1233,39 +1300,53 @@ Definition patricialize : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do - let prefix_length := - M.call (| - M.get_name (| globals, "min" |), - make_list [ - M.get_name (| globals, "prefix_length" |); + let _ := + M.for_ (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "obj" |), + ltac:(M.monadic ( + let prefix_length := M.call (| - M.get_name (| globals, "common_prefix_length" |), + M.get_name (| globals, "min" |), make_list [ - M.get_name (| globals, "substring" |); - M.get_subscript (| M.get_name (| globals, "key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) + M.get_name (| globals, "prefix_length" |); + M.call (| + M.get_name (| globals, "common_prefix_length" |), + make_list [ + M.get_name (| globals, "substring" |); + M.slice (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "level" |), + Constant.None_, + Constant.None_ + |) + ], + make_dict [] + |) ], make_dict [] - |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "prefix_length" |), - Constant.int 0 - |), - (* then *) - ltac:(M.monadic ( - let _ := M.break (| |) in + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "prefix_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := (* if *) M.if_then_else (| @@ -1276,10 +1357,15 @@ Definition patricialize : Value.t -> Value.t -> M := (* then *) ltac:(M.monadic ( let prefix := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), BinOp.add (| + M.slice (| + M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |), - M.get_name (| globals, "prefix_length" |) - |) |) |) in + BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |), + Constant.None_ + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ExtensionNode" |), @@ -1312,70 +1398,106 @@ Definition patricialize : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) - For M.get_name (| globals, "_" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 16 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "_" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 16 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "branches" |), "append" |), make_list [ {} ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let value := Constant.bytes "" in - For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "key" |) - ], - make_dict [] - |), - M.get_name (| globals, "level" |) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "obj" |), ltac:(M.monadic ( let _ := (* if *) M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); - make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] - ], - make_dict [] + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |), + M.get_name (| globals, "level" |) |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "AssertionError" |)) |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "key" |) + |); + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "AssertionError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "key" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| + M.get_subscript (| + M.get_name (| globals, "branches" |), + M.get_subscript (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "level" |) + |) + |), + M.get_name (| globals, "key" |) + |), + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "key" |) + |) + |) in M.pure Constant.None_ )) |) in - let value := - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.assign (| - M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) - |) in + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "BranchNode" |), diff --git a/CoqOfPython/ethereum/homestead/utils/__init__.v b/CoqOfPython/ethereum/homestead/utils/__init__.v index 1baedea..c70cb4e 100644 --- a/CoqOfPython/ethereum/homestead/utils/__init__.v +++ b/CoqOfPython/ethereum/homestead/utils/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.homestead.utils.__init__". Definition expr_1 : Value.t := Constant.str " diff --git a/CoqOfPython/ethereum/homestead/utils/address.v b/CoqOfPython/ethereum/homestead/utils/address.v index 793d8bd..4105423 100644 --- a/CoqOfPython/ethereum/homestead/utils/address.v +++ b/CoqOfPython/ethereum/homestead/utils/address.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.homestead.utils.address". Definition expr_1 : Value.t := Constant.str " @@ -17,31 +17,23 @@ Introduction Address specific functions used in this homestead version of specification. ". -Require typing. -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". +Axiom typing_imports : + AreImported globals "typing" [ "Union" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_left_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. -Require ethereum.homestead.fork_types. -Axiom ethereum_homestead_fork_types_Address : - IsGlobalAlias globals ethereum.homestead.fork_types.globals "Address". +Axiom ethereum_homestead_fork_types_imports : + AreImported globals "ethereum.homestead.fork_types" [ "Address" ]. Definition to_address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -63,11 +55,16 @@ Definition to_address : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "Address" |), make_list [ - M.get_subscript (| M.call (| - M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), - make_list [], - make_dict [] - |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) + M.slice (| + M.call (| + M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), + UnOp.sub (| Constant.int 20 |), + Constant.None_, + Constant.None_ + |) ], make_dict [] |) @@ -111,7 +108,12 @@ Definition compute_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "computed_address" |), + UnOp.sub (| Constant.int 20 |), + Constant.None_, + Constant.None_ + |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/homestead/utils/hexadecimal.v b/CoqOfPython/ethereum/homestead/utils/hexadecimal.v index cb864a9..6c9c4df 100644 --- a/CoqOfPython/ethereum/homestead/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/homestead/utils/hexadecimal.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.homestead.utils.hexadecimal". Definition expr_1 : Value.t := Constant.str " @@ -18,17 +18,11 @@ Hexadecimal utility functions used in this specification, specific to Homestead types. ". -Require ethereum.utils.hexadecimal. -Axiom ethereum_utils_hexadecimal_remove_hex_prefix : - IsGlobalAlias globals ethereum.utils.hexadecimal.globals "remove_hex_prefix". - -Require ethereum.homestead.fork_types. -Axiom ethereum_homestead_fork_types_Address : - IsGlobalAlias globals ethereum.homestead.fork_types.globals "Address". -Axiom ethereum_homestead_fork_types_Bloom : - IsGlobalAlias globals ethereum.homestead.fork_types.globals "Bloom". -Axiom ethereum_homestead_fork_types_Root : - IsGlobalAlias globals ethereum.homestead.fork_types.globals "Root". +Axiom ethereum_utils_hexadecimal_imports : + AreImported globals "ethereum.utils.hexadecimal" [ "remove_hex_prefix" ]. + +Axiom ethereum_homestead_fork_types_imports : + AreImported globals "ethereum.homestead.fork_types" [ "Address"; "Bloom"; "Root" ]. Definition hex_to_root : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/homestead/utils/message.v b/CoqOfPython/ethereum/homestead/utils/message.v index e72658e..16ddc16 100644 --- a/CoqOfPython/ethereum/homestead/utils/message.v +++ b/CoqOfPython/ethereum/homestead/utils/message.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.homestead.utils.message". Definition expr_1 : Value.t := Constant.str " @@ -17,39 +17,23 @@ Introduction Message specific functions used in this homestead version of specification. ". -Require typing. -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". +Axiom typing_imports : + AreImported globals "typing" [ "Optional"; "Union" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint" ]. -Require ethereum.homestead.fork_types. -Axiom ethereum_homestead_fork_types_Address : - IsGlobalAlias globals ethereum.homestead.fork_types.globals "Address". +Axiom ethereum_homestead_fork_types_imports : + AreImported globals "ethereum.homestead.fork_types" [ "Address" ]. -Require ethereum.homestead.state. -Axiom ethereum_homestead_state_get_account : - IsGlobalAlias globals ethereum.homestead.state.globals "get_account". +Axiom ethereum_homestead_state_imports : + AreImported globals "ethereum.homestead.state" [ "get_account" ]. -Require ethereum.homestead.vm.__init__. -Axiom ethereum_homestead_vm___init___Environment : - IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "Environment". -Axiom ethereum_homestead_vm___init___Message : - IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "Message". +Axiom ethereum_homestead_vm_imports : + AreImported globals "ethereum.homestead.vm" [ "Environment"; "Message" ]. -Require ethereum.homestead.utils.address. -Axiom ethereum_homestead_utils_address_compute_contract_address : - IsGlobalAlias globals ethereum.homestead.utils.address.globals "compute_contract_address". +Axiom ethereum_homestead_utils_address_imports : + AreImported globals "ethereum.homestead.utils.address" [ "compute_contract_address" ]. Definition prepare_message : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -179,7 +163,7 @@ Definition prepare_message : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "Target must be address or empty bytes" diff --git a/CoqOfPython/ethereum/homestead/vm/__init__.v b/CoqOfPython/ethereum/homestead/vm/__init__.v index 11ebd54..6bc6543 100644 --- a/CoqOfPython/ethereum/homestead/vm/__init__.v +++ b/CoqOfPython/ethereum/homestead/vm/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.homestead.vm.__init__". Definition expr_1 : Value.t := Constant.str " @@ -18,47 +18,26 @@ The abstract computer which runs the code stored in an `.fork_types.Account`. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". - -Require ethereum.homestead.blocks. -Axiom ethereum_homestead_blocks_Log : - IsGlobalAlias globals ethereum.homestead.blocks.globals "Log". - -Require ethereum.homestead.fork_types. -Axiom ethereum_homestead_fork_types_Address : - IsGlobalAlias globals ethereum.homestead.fork_types.globals "Address". - -Require ethereum.homestead.state. -Axiom ethereum_homestead_state_State : - IsGlobalAlias globals ethereum.homestead.state.globals "State". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple"; "Union" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. + +Axiom ethereum_homestead_blocks_imports : + AreImported globals "ethereum.homestead.blocks" [ "Log" ]. + +Axiom ethereum_homestead_fork_types_imports : + AreImported globals "ethereum.homestead.fork_types" [ "Address" ]. + +Axiom ethereum_homestead_state_imports : + AreImported globals "ethereum.homestead.state" [ "State" ]. Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] diff --git a/CoqOfPython/ethereum/homestead/vm/exceptions.v b/CoqOfPython/ethereum/homestead/vm/exceptions.v index 45435b3..5676be5 100644 --- a/CoqOfPython/ethereum/homestead/vm/exceptions.v +++ b/CoqOfPython/ethereum/homestead/vm/exceptions.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.homestead.vm.exceptions". Definition expr_1 : Value.t := Constant.str " @@ -17,9 +17,8 @@ Introduction Exceptions which cause the EVM to halt exceptionally. ". -Require ethereum.exceptions. -Axiom ethereum_exceptions_EthereumException : - IsGlobalAlias globals ethereum.exceptions.globals "EthereumException". +Axiom ethereum_exceptions_imports : + AreImported globals "ethereum.exceptions" [ "EthereumException" ]. Definition ExceptionalHalt : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/homestead/vm/gas.v b/CoqOfPython/ethereum/homestead/vm/gas.v index 0403b1e..28b51e6 100644 --- a/CoqOfPython/ethereum/homestead/vm/gas.v +++ b/CoqOfPython/ethereum/homestead/vm/gas.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.homestead.vm.gas". Definition expr_1 : Value.t := Constant.str " @@ -17,49 +17,32 @@ Introduction EVM gas constants and calculators. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.trace. -Axiom ethereum_trace_GasAndRefund : - IsGlobalAlias globals ethereum.trace.globals "GasAndRefund". -Axiom ethereum_trace_evm_trace : - IsGlobalAlias globals ethereum.trace.globals "evm_trace". - -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". - -Require ethereum.homestead.fork_types. -Axiom ethereum_homestead_fork_types_Address : - IsGlobalAlias globals ethereum.homestead.fork_types.globals "Address". - -Require ethereum.homestead.state. -Axiom ethereum_homestead_state_State : - IsGlobalAlias globals ethereum.homestead.state.globals "State". -Axiom ethereum_homestead_state_account_exists : - IsGlobalAlias globals ethereum.homestead.state.globals "account_exists". - -Require ethereum.homestead.vm.__init__. -Axiom ethereum_homestead_vm___init___Evm : - IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "Evm". - -Require ethereum.homestead.vm.exceptions. -Axiom ethereum_homestead_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.homestead.vm.exceptions.globals "OutOfGasError". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. + +Axiom ethereum_trace_imports : + AreImported globals "ethereum.trace" [ "GasAndRefund"; "evm_trace" ]. + +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. + +Axiom ethereum_homestead_fork_types_imports : + AreImported globals "ethereum.homestead.fork_types" [ "Address" ]. + +Axiom ethereum_homestead_state_imports : + AreImported globals "ethereum.homestead.state" [ "State"; "account_exists" ]. + +Axiom ethereum_homestead_vm_imports : + AreImported globals "ethereum.homestead.vm" [ "Evm" ]. + +Axiom ethereum_homestead_vm_exceptions_imports : + AreImported globals "ethereum.homestead.vm.exceptions" [ "OutOfGasError" ]. Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -488,7 +471,7 @@ Definition charge_gas : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -605,105 +588,114 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := ], make_dict [] |) in - For make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ] in M.get_name (| globals, "extensions" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "size" |), - Constant.int 0 - |), - (* then *) + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ], + M.get_name (| globals, "extensions" |), ltac:(M.monadic ( - let _ := M.continue (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let before_size := - M.call (| - M.get_name (| globals, "ceil32" |), - make_list [ - M.get_name (| globals, "current_size" |) - ], - make_dict [] - |) in - let after_size := - M.call (| - M.get_name (| globals, "ceil32" |), - make_list [ - BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "size" |), + Constant.int 0 |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.lt_e (| - M.get_name (| globals, "after_size" |), - M.get_name (| globals, "before_size" |) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.continue (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let size_to_extend := BinOp.add - BinOp.sub (| + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let before_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "current_size" |) + ], + make_dict [] + |) in + let after_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let size_to_extend := BinOp.add + BinOp.sub (| M.get_name (| globals, "after_size" |), M.get_name (| globals, "before_size" |) |) - BinOp.sub (| + BinOp.sub (| M.get_name (| globals, "after_size" |), M.get_name (| globals, "before_size" |) |) in - let already_paid := - M.call (| - M.get_name (| globals, "calculate_memory_gas_cost" |), - make_list [ - M.get_name (| globals, "before_size" |) - ], - make_dict [] - |) in - let total_cost := - M.call (| - M.get_name (| globals, "calculate_memory_gas_cost" |), - make_list [ - M.get_name (| globals, "after_size" |) - ], - make_dict [] - |) in - let to_be_paid := BinOp.add - BinOp.sub (| + let already_paid := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "before_size" |) + ], + make_dict [] + |) in + let total_cost := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "after_size" |) + ], + make_dict [] + |) in + let to_be_paid := BinOp.add + BinOp.sub (| M.get_name (| globals, "total_cost" |), M.get_name (| globals, "already_paid" |) |) - BinOp.sub (| + BinOp.sub (| M.get_name (| globals, "total_cost" |), M.get_name (| globals, "already_paid" |) |) in - let current_size := - M.get_name (| globals, "after_size" |) in - EndFor. + let current_size := + M.get_name (| globals, "after_size" |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ExtendMemory" |), diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/__init__.v b/CoqOfPython/ethereum/homestead/vm/instructions/__init__.v index 4398890..b5be76b 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/__init__.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.homestead.vm.instructions.__init__". Definition expr_1 : Value.t := Constant.str " @@ -20,59 +20,44 @@ implementations. (* At top_level_stmt: unsupported node type: Import *) -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict" ]. -Require ethereum.homestead.vm.instructions.__init__. -Axiom ethereum_homestead_vm_instructions___init___arithmetic : - IsGlobalAlias globals ethereum.homestead.vm.instructions.__init__.globals "arithmetic". +Axiom ethereum_homestead_vm_instructions_imports : + AreImported globals "ethereum.homestead.vm.instructions" [ "arithmetic" ]. -Require ethereum.homestead.vm.instructions.__init__. -Axiom ethereum_homestead_vm_instructions___init___bitwise : - IsGlobalAlias globals ethereum.homestead.vm.instructions.__init__.globals "bitwise". +Axiom ethereum_homestead_vm_instructions_imports : + AreImported globals "ethereum.homestead.vm.instructions" [ "bitwise" ]. -Require ethereum.homestead.vm.instructions.__init__. -Axiom ethereum_homestead_vm_instructions___init___block : - IsGlobalAlias globals ethereum.homestead.vm.instructions.__init__.globals "block". +Axiom ethereum_homestead_vm_instructions_imports : + AreImported globals "ethereum.homestead.vm.instructions" [ "block" ]. -Require ethereum.homestead.vm.instructions.__init__. -Axiom ethereum_homestead_vm_instructions___init___comparison : - IsGlobalAlias globals ethereum.homestead.vm.instructions.__init__.globals "comparison". +Axiom ethereum_homestead_vm_instructions_imports : + AreImported globals "ethereum.homestead.vm.instructions" [ "comparison" ]. -Require ethereum.homestead.vm.instructions.__init__. -Axiom ethereum_homestead_vm_instructions___init___control_flow : - IsGlobalAlias globals ethereum.homestead.vm.instructions.__init__.globals "control_flow". +Axiom ethereum_homestead_vm_instructions_imports : + AreImported globals "ethereum.homestead.vm.instructions" [ "control_flow" ]. -Require ethereum.homestead.vm.instructions.__init__. -Axiom ethereum_homestead_vm_instructions___init___environment : - IsGlobalAlias globals ethereum.homestead.vm.instructions.__init__.globals "environment". +Axiom ethereum_homestead_vm_instructions_imports : + AreImported globals "ethereum.homestead.vm.instructions" [ "environment" ]. -Require ethereum.homestead.vm.instructions.__init__. -Axiom ethereum_homestead_vm_instructions___init___keccak : - IsGlobalAlias globals ethereum.homestead.vm.instructions.__init__.globals "keccak". +Axiom ethereum_homestead_vm_instructions_imports : + AreImported globals "ethereum.homestead.vm.instructions" [ "keccak" ]. -Require ethereum.homestead.vm.instructions.__init__. -Axiom ethereum_homestead_vm_instructions___init___log : - IsGlobalAlias globals ethereum.homestead.vm.instructions.__init__.globals "log". +Axiom ethereum_homestead_vm_instructions_imports : + AreImported globals "ethereum.homestead.vm.instructions" [ "log" ]. -Require ethereum.homestead.vm.instructions.__init__. -Axiom ethereum_homestead_vm_instructions___init___memory : - IsGlobalAlias globals ethereum.homestead.vm.instructions.__init__.globals "memory". +Axiom ethereum_homestead_vm_instructions_imports : + AreImported globals "ethereum.homestead.vm.instructions" [ "memory" ]. -Require ethereum.homestead.vm.instructions.__init__. -Axiom ethereum_homestead_vm_instructions___init___stack : - IsGlobalAlias globals ethereum.homestead.vm.instructions.__init__.globals "stack". +Axiom ethereum_homestead_vm_instructions_imports : + AreImported globals "ethereum.homestead.vm.instructions" [ "stack" ]. -Require ethereum.homestead.vm.instructions.__init__. -Axiom ethereum_homestead_vm_instructions___init___storage : - IsGlobalAlias globals ethereum.homestead.vm.instructions.__init__.globals "storage". +Axiom ethereum_homestead_vm_instructions_imports : + AreImported globals "ethereum.homestead.vm.instructions" [ "storage" ]. -Require ethereum.homestead.vm.instructions.__init__. -Axiom ethereum_homestead_vm_instructions___init___system : - IsGlobalAlias globals ethereum.homestead.vm.instructions.__init__.globals "system". +Axiom ethereum_homestead_vm_instructions_imports : + AreImported globals "ethereum.homestead.vm.instructions" [ "system" ]. Definition Ops : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/homestead/vm/instructions/arithmetic.v index f3ce972..6c67fc6 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/arithmetic.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.homestead.vm.instructions.arithmetic". Definition expr_1 : Value.t := Constant.str " @@ -17,43 +17,20 @@ Introduction Implementations of the EVM Arithmetic instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U255_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U255_CEIL_VALUE". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_U256_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U255_CEIL_VALUE"; "U256"; "U256_CEIL_VALUE"; "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_get_sign : - IsGlobalAlias globals ethereum.utils.numeric.globals "get_sign". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "get_sign" ]. -Require ethereum.homestead.vm.__init__. -Axiom ethereum_homestead_vm___init___Evm : - IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "Evm". +Axiom ethereum_homestead_vm_imports : + AreImported globals "ethereum.homestead.vm" [ "Evm" ]. -Require ethereum.homestead.vm.gas. -Axiom ethereum_homestead_vm_gas_GAS_EXPONENTIATION : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_EXPONENTIATION". -Axiom ethereum_homestead_vm_gas_GAS_EXPONENTIATION_PER_BYTE : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_EXPONENTIATION_PER_BYTE". -Axiom ethereum_homestead_vm_gas_GAS_LOW : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_LOW". -Axiom ethereum_homestead_vm_gas_GAS_MID : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_MID". -Axiom ethereum_homestead_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_homestead_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "charge_gas". +Axiom ethereum_homestead_vm_gas_imports : + AreImported globals "ethereum.homestead.vm.gas" [ "GAS_EXPONENTIATION"; "GAS_EXPONENTIATION_PER_BYTE"; "GAS_LOW"; "GAS_MID"; "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.homestead.vm.stack. -Axiom ethereum_homestead_vm_stack_pop : - IsGlobalAlias globals ethereum.homestead.vm.stack.globals "pop". -Axiom ethereum_homestead_vm_stack_push : - IsGlobalAlias globals ethereum.homestead.vm.stack.globals "push". +Axiom ethereum_homestead_vm_stack_imports : + AreImported globals "ethereum.homestead.vm.stack" [ "pop"; "push" ]. Definition add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -1030,19 +1007,27 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let value_bytes := - M.get_subscript (| M.get_name (| globals, "value_bytes" |), M.slice (| BinOp.sub (| - Constant.int 31, - M.call (| - M.get_name (| globals, "int" |), - make_list [ - M.get_name (| globals, "byte_num" |) - ], - make_dict [] - |) - |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "value_bytes" |), + BinOp.sub (| + Constant.int 31, + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "byte_num" |) + ], + make_dict [] + |) + |), + Constant.None_, + Constant.None_ + |) in let sign_bit := BinOp.r_shift (| - M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), + M.get_subscript (| + M.get_name (| globals, "value_bytes" |), + Constant.int 0 + |), Constant.int 7 |) in let _ := diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/bitwise.v b/CoqOfPython/ethereum/homestead/vm/instructions/bitwise.v index 623316d..a42f204 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/bitwise.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.homestead.vm.instructions.bitwise". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementations of the EVM bitwise instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.homestead.vm.__init__. -Axiom ethereum_homestead_vm___init___Evm : - IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "Evm". +Axiom ethereum_homestead_vm_imports : + AreImported globals "ethereum.homestead.vm" [ "Evm" ]. -Require ethereum.homestead.vm.gas. -Axiom ethereum_homestead_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_homestead_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "charge_gas". +Axiom ethereum_homestead_vm_gas_imports : + AreImported globals "ethereum.homestead.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.homestead.vm.stack. -Axiom ethereum_homestead_vm_stack_pop : - IsGlobalAlias globals ethereum.homestead.vm.stack.globals "pop". -Axiom ethereum_homestead_vm_stack_push : - IsGlobalAlias globals ethereum.homestead.vm.stack.globals "push". +Axiom ethereum_homestead_vm_stack_imports : + AreImported globals "ethereum.homestead.vm.stack" [ "pop"; "push" ]. Definition bitwise_and : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/block.v b/CoqOfPython/ethereum/homestead/vm/instructions/block.v index 0c0fa2b..adca5ee 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/block.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/block.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.homestead.vm.instructions.block". Definition expr_1 : Value.t := Constant.str " @@ -17,27 +17,17 @@ Introduction Implementations of the EVM block instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.homestead.vm.__init__. -Axiom ethereum_homestead_vm___init___Evm : - IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "Evm". +Axiom ethereum_homestead_vm_imports : + AreImported globals "ethereum.homestead.vm" [ "Evm" ]. -Require ethereum.homestead.vm.gas. -Axiom ethereum_homestead_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_BASE". -Axiom ethereum_homestead_vm_gas_GAS_BLOCK_HASH : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_BLOCK_HASH". -Axiom ethereum_homestead_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "charge_gas". +Axiom ethereum_homestead_vm_gas_imports : + AreImported globals "ethereum.homestead.vm.gas" [ "GAS_BASE"; "GAS_BLOCK_HASH"; "charge_gas" ]. -Require ethereum.homestead.vm.stack. -Axiom ethereum_homestead_vm_stack_pop : - IsGlobalAlias globals ethereum.homestead.vm.stack.globals "pop". -Axiom ethereum_homestead_vm_stack_push : - IsGlobalAlias globals ethereum.homestead.vm.stack.globals "push". +Axiom ethereum_homestead_vm_stack_imports : + AreImported globals "ethereum.homestead.vm.stack" [ "pop"; "push" ]. Definition block_hash : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -94,10 +84,13 @@ Definition block_hash : Value.t -> Value.t -> M := (* else *) )), ltac:(M.monadic ( let hash := - M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), - M.get_name (| globals, "block_number" |) - |) |) |) in + M.get_subscript (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), + UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + M.get_name (| globals, "block_number" |) + |) |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/comparison.v b/CoqOfPython/ethereum/homestead/vm/instructions/comparison.v index 55d09e3..6adc1a7 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/comparison.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.homestead.vm.instructions.comparison". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementations of the EVM Comparison instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.homestead.vm.__init__. -Axiom ethereum_homestead_vm___init___Evm : - IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "Evm". +Axiom ethereum_homestead_vm_imports : + AreImported globals "ethereum.homestead.vm" [ "Evm" ]. -Require ethereum.homestead.vm.gas. -Axiom ethereum_homestead_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_homestead_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "charge_gas". +Axiom ethereum_homestead_vm_gas_imports : + AreImported globals "ethereum.homestead.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.homestead.vm.stack. -Axiom ethereum_homestead_vm_stack_pop : - IsGlobalAlias globals ethereum.homestead.vm.stack.globals "pop". -Axiom ethereum_homestead_vm_stack_push : - IsGlobalAlias globals ethereum.homestead.vm.stack.globals "push". +Axiom ethereum_homestead_vm_stack_imports : + AreImported globals "ethereum.homestead.vm.stack" [ "pop"; "push" ]. Definition less_than : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/control_flow.v b/CoqOfPython/ethereum/homestead/vm/instructions/control_flow.v index 8be3532..a0cc7cb 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/control_flow.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.homestead.vm.instructions.control_flow". Definition expr_1 : Value.t := Constant.str " @@ -17,37 +17,20 @@ Introduction Implementations of the EVM control flow instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. -Require ethereum.homestead.vm.gas. -Axiom ethereum_homestead_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_BASE". -Axiom ethereum_homestead_vm_gas_GAS_HIGH : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_HIGH". -Axiom ethereum_homestead_vm_gas_GAS_JUMPDEST : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_JUMPDEST". -Axiom ethereum_homestead_vm_gas_GAS_MID : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_MID". -Axiom ethereum_homestead_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "charge_gas". +Axiom ethereum_homestead_vm_gas_imports : + AreImported globals "ethereum.homestead.vm.gas" [ "GAS_BASE"; "GAS_HIGH"; "GAS_JUMPDEST"; "GAS_MID"; "charge_gas" ]. -Require ethereum.homestead.vm.__init__. -Axiom ethereum_homestead_vm___init___Evm : - IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "Evm". +Axiom ethereum_homestead_vm_imports : + AreImported globals "ethereum.homestead.vm" [ "Evm" ]. -Require ethereum.homestead.vm.exceptions. -Axiom ethereum_homestead_vm_exceptions_InvalidJumpDestError : - IsGlobalAlias globals ethereum.homestead.vm.exceptions.globals "InvalidJumpDestError". +Axiom ethereum_homestead_vm_exceptions_imports : + AreImported globals "ethereum.homestead.vm.exceptions" [ "InvalidJumpDestError" ]. -Require ethereum.homestead.vm.stack. -Axiom ethereum_homestead_vm_stack_pop : - IsGlobalAlias globals ethereum.homestead.vm.stack.globals "pop". -Axiom ethereum_homestead_vm_stack_push : - IsGlobalAlias globals ethereum.homestead.vm.stack.globals "push". +Axiom ethereum_homestead_vm_stack_imports : + AreImported globals "ethereum.homestead.vm.stack" [ "pop"; "push" ]. Definition stop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -117,7 +100,7 @@ Definition jump : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "InvalidJumpDestError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -205,7 +188,7 @@ Definition jumpi : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "InvalidJumpDestError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/environment.v b/CoqOfPython/ethereum/homestead/vm/instructions/environment.v index dfa51f1..ecb0f65 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/environment.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.homestead.vm.instructions.environment". Definition expr_1 : Value.t := Constant.str " @@ -17,55 +17,29 @@ Introduction Implementations of the EVM environment related instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". - -Require ethereum.homestead.state. -Axiom ethereum_homestead_state_get_account : - IsGlobalAlias globals ethereum.homestead.state.globals "get_account". - -Require ethereum.homestead.utils.address. -Axiom ethereum_homestead_utils_address_to_address : - IsGlobalAlias globals ethereum.homestead.utils.address.globals "to_address". - -Require ethereum.homestead.vm.memory. -Axiom ethereum_homestead_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.homestead.vm.memory.globals "buffer_read". -Axiom ethereum_homestead_vm_memory_memory_write : - IsGlobalAlias globals ethereum.homestead.vm.memory.globals "memory_write". - -Require ethereum.homestead.vm.__init__. -Axiom ethereum_homestead_vm___init___Evm : - IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "Evm". - -Require ethereum.homestead.vm.gas. -Axiom ethereum_homestead_vm_gas_GAS_BALANCE : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_BALANCE". -Axiom ethereum_homestead_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_BASE". -Axiom ethereum_homestead_vm_gas_GAS_COPY : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_COPY". -Axiom ethereum_homestead_vm_gas_GAS_EXTERNAL : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_EXTERNAL". -Axiom ethereum_homestead_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_homestead_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_homestead_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "charge_gas". - -Require ethereum.homestead.vm.stack. -Axiom ethereum_homestead_vm_stack_pop : - IsGlobalAlias globals ethereum.homestead.vm.stack.globals "pop". -Axiom ethereum_homestead_vm_stack_push : - IsGlobalAlias globals ethereum.homestead.vm.stack.globals "push". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. + +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. + +Axiom ethereum_homestead_state_imports : + AreImported globals "ethereum.homestead.state" [ "get_account" ]. + +Axiom ethereum_homestead_utils_address_imports : + AreImported globals "ethereum.homestead.utils.address" [ "to_address" ]. + +Axiom ethereum_homestead_vm_memory_imports : + AreImported globals "ethereum.homestead.vm.memory" [ "buffer_read"; "memory_write" ]. + +Axiom ethereum_homestead_vm_imports : + AreImported globals "ethereum.homestead.vm" [ "Evm" ]. + +Axiom ethereum_homestead_vm_gas_imports : + AreImported globals "ethereum.homestead.vm.gas" [ "GAS_BALANCE"; "GAS_BASE"; "GAS_COPY"; "GAS_EXTERNAL"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. + +Axiom ethereum_homestead_vm_stack_imports : + AreImported globals "ethereum.homestead.vm.stack" [ "pop"; "push" ]. Definition address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/keccak.v b/CoqOfPython/ethereum/homestead/vm/instructions/keccak.v index 6a6a593..edb6298 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/keccak.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.homestead.vm.instructions.keccak". Definition expr_1 : Value.t := Constant.str " @@ -17,43 +17,26 @@ Introduction Implementations of the EVM keccak instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". - -Require ethereum.homestead.vm.__init__. -Axiom ethereum_homestead_vm___init___Evm : - IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "Evm". - -Require ethereum.homestead.vm.gas. -Axiom ethereum_homestead_vm_gas_GAS_KECCAK256 : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_KECCAK256". -Axiom ethereum_homestead_vm_gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_KECCAK256_WORD". -Axiom ethereum_homestead_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_homestead_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "charge_gas". - -Require ethereum.homestead.vm.memory. -Axiom ethereum_homestead_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.homestead.vm.memory.globals "memory_read_bytes". - -Require ethereum.homestead.vm.stack. -Axiom ethereum_homestead_vm_stack_pop : - IsGlobalAlias globals ethereum.homestead.vm.stack.globals "pop". -Axiom ethereum_homestead_vm_stack_push : - IsGlobalAlias globals ethereum.homestead.vm.stack.globals "push". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. + +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. + +Axiom ethereum_homestead_vm_imports : + AreImported globals "ethereum.homestead.vm" [ "Evm" ]. + +Axiom ethereum_homestead_vm_gas_imports : + AreImported globals "ethereum.homestead.vm.gas" [ "GAS_KECCAK256"; "GAS_KECCAK256_WORD"; "calculate_gas_extend_memory"; "charge_gas" ]. + +Axiom ethereum_homestead_vm_memory_imports : + AreImported globals "ethereum.homestead.vm.memory" [ "memory_read_bytes" ]. + +Axiom ethereum_homestead_vm_stack_imports : + AreImported globals "ethereum.homestead.vm.stack" [ "pop"; "push" ]. Definition keccak : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/log.v b/CoqOfPython/ethereum/homestead/vm/instructions/log.v index 1c37f23..72dbe65 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/log.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/log.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.homestead.vm.instructions.log". Definition expr_1 : Value.t := Constant.str " @@ -17,41 +17,26 @@ Introduction Implementations of the EVM logging instructions. ". -Require functools. -Axiom functools_partial : - IsGlobalAlias globals functools.globals "partial". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". - -Require ethereum.homestead.blocks. -Axiom ethereum_homestead_blocks_Log : - IsGlobalAlias globals ethereum.homestead.blocks.globals "Log". - -Require ethereum.homestead.vm.__init__. -Axiom ethereum_homestead_vm___init___Evm : - IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "Evm". - -Require ethereum.homestead.vm.gas. -Axiom ethereum_homestead_vm_gas_GAS_LOG : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_LOG". -Axiom ethereum_homestead_vm_gas_GAS_LOG_DATA : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_LOG_DATA". -Axiom ethereum_homestead_vm_gas_GAS_LOG_TOPIC : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_LOG_TOPIC". -Axiom ethereum_homestead_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_homestead_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "charge_gas". - -Require ethereum.homestead.vm.memory. -Axiom ethereum_homestead_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.homestead.vm.memory.globals "memory_read_bytes". - -Require ethereum.homestead.vm.stack. -Axiom ethereum_homestead_vm_stack_pop : - IsGlobalAlias globals ethereum.homestead.vm.stack.globals "pop". +Axiom functools_imports : + AreImported globals "functools" [ "partial" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. + +Axiom ethereum_homestead_blocks_imports : + AreImported globals "ethereum.homestead.blocks" [ "Log" ]. + +Axiom ethereum_homestead_vm_imports : + AreImported globals "ethereum.homestead.vm" [ "Evm" ]. + +Axiom ethereum_homestead_vm_gas_imports : + AreImported globals "ethereum.homestead.vm.gas" [ "GAS_LOG"; "GAS_LOG_DATA"; "GAS_LOG_TOPIC"; "calculate_gas_extend_memory"; "charge_gas" ]. + +Axiom ethereum_homestead_vm_memory_imports : + AreImported globals "ethereum.homestead.vm.memory" [ "memory_read_bytes" ]. + +Axiom ethereum_homestead_vm_stack_imports : + AreImported globals "ethereum.homestead.vm.stack" [ "pop" ]. Definition log_n : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -88,33 +73,42 @@ Definition log_n : Value.t -> Value.t -> M := |) in let topics := make_list [] in - For M.get_name (| globals, "_" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - M.get_name (| globals, "num_topics" |) - ], - make_dict [] - |) do - let topic := + let _ := + M.for_ (| + M.get_name (| globals, "_" |), M.call (| - M.get_field (| M.call (| - M.get_name (| globals, "pop" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] - |), "to_be_bytes32" |), - make_list [], - make_dict [] - |) in - let _ := M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "num_topics" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let topic := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| M.get_field (| M.get_name (| globals, "topics" |), "append" |), make_list [ M.get_name (| globals, "topic" |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let extend_memory := M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/memory.v b/CoqOfPython/ethereum/homestead/vm/instructions/memory.v index 3631aa5..e440cba 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/memory.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.homestead.vm.instructions.memory". Definition expr_1 : Value.t := Constant.str " @@ -17,37 +17,20 @@ Introduction Implementations of the EVM Memory instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes" ]. -Require ethereum.homestead.vm.__init__. -Axiom ethereum_homestead_vm___init___Evm : - IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "Evm". +Axiom ethereum_homestead_vm_imports : + AreImported globals "ethereum.homestead.vm" [ "Evm" ]. -Require ethereum.homestead.vm.gas. -Axiom ethereum_homestead_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_BASE". -Axiom ethereum_homestead_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_homestead_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_homestead_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "charge_gas". +Axiom ethereum_homestead_vm_gas_imports : + AreImported globals "ethereum.homestead.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. -Require ethereum.homestead.vm.memory. -Axiom ethereum_homestead_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.homestead.vm.memory.globals "memory_read_bytes". -Axiom ethereum_homestead_vm_memory_memory_write : - IsGlobalAlias globals ethereum.homestead.vm.memory.globals "memory_write". +Axiom ethereum_homestead_vm_memory_imports : + AreImported globals "ethereum.homestead.vm.memory" [ "memory_read_bytes"; "memory_write" ]. -Require ethereum.homestead.vm.stack. -Axiom ethereum_homestead_vm_stack_pop : - IsGlobalAlias globals ethereum.homestead.vm.stack.globals "pop". -Axiom ethereum_homestead_vm_stack_push : - IsGlobalAlias globals ethereum.homestead.vm.stack.globals "push". +Axiom ethereum_homestead_vm_stack_imports : + AreImported globals "ethereum.homestead.vm.stack" [ "pop"; "push" ]. Definition mstore : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/stack.v b/CoqOfPython/ethereum/homestead/vm/instructions/stack.v index 8498137..e1cc81e 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/stack.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.homestead.vm.instructions.stack". Definition expr_1 : Value.t := Constant.str " @@ -17,39 +17,26 @@ Introduction Implementations of the EVM stack related instructions. ". -Require functools. -Axiom functools_partial : - IsGlobalAlias globals functools.globals "partial". +Axiom functools_imports : + AreImported globals "functools" [ "partial" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.homestead.vm.__init__. -Axiom ethereum_homestead_vm___init___Evm : - IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "Evm". -Axiom ethereum_homestead_vm___init___stack : - IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "stack". +Axiom ethereum_homestead_vm_imports : + AreImported globals "ethereum.homestead.vm" [ "Evm"; "stack" ]. -Require ethereum.homestead.vm.exceptions. -Axiom ethereum_homestead_vm_exceptions_StackUnderflowError : - IsGlobalAlias globals ethereum.homestead.vm.exceptions.globals "StackUnderflowError". +Axiom ethereum_homestead_vm_exceptions_imports : + AreImported globals "ethereum.homestead.vm.exceptions" [ "StackUnderflowError" ]. -Require ethereum.homestead.vm.gas. -Axiom ethereum_homestead_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_BASE". -Axiom ethereum_homestead_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_homestead_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "charge_gas". +Axiom ethereum_homestead_vm_gas_imports : + AreImported globals "ethereum.homestead.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.homestead.vm.memory. -Axiom ethereum_homestead_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.homestead.vm.memory.globals "buffer_read". +Axiom ethereum_homestead_vm_memory_imports : + AreImported globals "ethereum.homestead.vm.memory" [ "buffer_read" ]. Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -203,19 +190,22 @@ Definition dup_n : Value.t -> Value.t -> M := make_dict [] |) in let data_to_duplicate := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] + BinOp.sub (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), + Constant.int 1 |), - Constant.int 1 - |), - M.get_name (| globals, "item_number" |) - |) |) in + M.get_name (| globals, "item_number" |) + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "stack" |), "push" |), make_list [ @@ -278,14 +268,26 @@ Definition swap_n : Value.t -> Value.t -> M := make_dict [] |) in let _ := M.assign (| - make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| - UnOp.sub (| Constant.int 1 |), - M.get_name (| globals, "item_number" |) - |) |) ], - make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| - UnOp.sub (| Constant.int 1 |), - M.get_name (| globals, "item_number" |) - |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |) ] + make_tuple [ M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + UnOp.sub (| Constant.int 1 |) + |); M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) + |) ], + make_tuple [ M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) + |); M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + UnOp.sub (| Constant.int 1 |) + |) ] |) in let _ := M.assign_op (| BinOp.add, diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/storage.v b/CoqOfPython/ethereum/homestead/vm/instructions/storage.v index 3b90027..bf4e8aa 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/storage.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.homestead.vm.instructions.storage". Definition expr_1 : Value.t := Constant.str " @@ -17,33 +17,17 @@ Introduction Implementations of the EVM storage related instructions. ". -Require ethereum.homestead.state. -Axiom ethereum_homestead_state_get_storage : - IsGlobalAlias globals ethereum.homestead.state.globals "get_storage". -Axiom ethereum_homestead_state_set_storage : - IsGlobalAlias globals ethereum.homestead.state.globals "set_storage". +Axiom ethereum_homestead_state_imports : + AreImported globals "ethereum.homestead.state" [ "get_storage"; "set_storage" ]. -Require ethereum.homestead.vm.__init__. -Axiom ethereum_homestead_vm___init___Evm : - IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "Evm". +Axiom ethereum_homestead_vm_imports : + AreImported globals "ethereum.homestead.vm" [ "Evm" ]. -Require ethereum.homestead.vm.gas. -Axiom ethereum_homestead_vm_gas_GAS_SLOAD : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_SLOAD". -Axiom ethereum_homestead_vm_gas_GAS_STORAGE_CLEAR_REFUND : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_STORAGE_CLEAR_REFUND". -Axiom ethereum_homestead_vm_gas_GAS_STORAGE_SET : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_STORAGE_SET". -Axiom ethereum_homestead_vm_gas_GAS_STORAGE_UPDATE : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_STORAGE_UPDATE". -Axiom ethereum_homestead_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "charge_gas". +Axiom ethereum_homestead_vm_gas_imports : + AreImported globals "ethereum.homestead.vm.gas" [ "GAS_SLOAD"; "GAS_STORAGE_CLEAR_REFUND"; "GAS_STORAGE_SET"; "GAS_STORAGE_UPDATE"; "charge_gas" ]. -Require ethereum.homestead.vm.stack. -Axiom ethereum_homestead_vm_stack_pop : - IsGlobalAlias globals ethereum.homestead.vm.stack.globals "pop". -Axiom ethereum_homestead_vm_stack_push : - IsGlobalAlias globals ethereum.homestead.vm.stack.globals "push". +Axiom ethereum_homestead_vm_stack_imports : + AreImported globals "ethereum.homestead.vm.stack" [ "pop"; "push" ]. Definition sload : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/system.v b/CoqOfPython/ethereum/homestead/vm/instructions/system.v index c2af944..f88541e 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/system.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/system.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.homestead.vm.instructions.system". Definition expr_1 : Value.t := Constant.str " @@ -17,71 +17,29 @@ Introduction Implementations of the EVM system related instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. -Require ethereum.homestead.fork_types. -Axiom ethereum_homestead_fork_types_Address : - IsGlobalAlias globals ethereum.homestead.fork_types.globals "Address". +Axiom ethereum_homestead_fork_types_imports : + AreImported globals "ethereum.homestead.fork_types" [ "Address" ]. -Require ethereum.homestead.state. -Axiom ethereum_homestead_state_account_has_code_or_nonce : - IsGlobalAlias globals ethereum.homestead.state.globals "account_has_code_or_nonce". -Axiom ethereum_homestead_state_get_account : - IsGlobalAlias globals ethereum.homestead.state.globals "get_account". -Axiom ethereum_homestead_state_increment_nonce : - IsGlobalAlias globals ethereum.homestead.state.globals "increment_nonce". -Axiom ethereum_homestead_state_set_account_balance : - IsGlobalAlias globals ethereum.homestead.state.globals "set_account_balance". +Axiom ethereum_homestead_state_imports : + AreImported globals "ethereum.homestead.state" [ "account_has_code_or_nonce"; "get_account"; "increment_nonce"; "set_account_balance" ]. -Require ethereum.homestead.utils.address. -Axiom ethereum_homestead_utils_address_compute_contract_address : - IsGlobalAlias globals ethereum.homestead.utils.address.globals "compute_contract_address". -Axiom ethereum_homestead_utils_address_to_address : - IsGlobalAlias globals ethereum.homestead.utils.address.globals "to_address". +Axiom ethereum_homestead_utils_address_imports : + AreImported globals "ethereum.homestead.utils.address" [ "compute_contract_address"; "to_address" ]. -Require ethereum.homestead.vm.__init__. -Axiom ethereum_homestead_vm___init___Evm : - IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "Evm". -Axiom ethereum_homestead_vm___init___Message : - IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "Message". -Axiom ethereum_homestead_vm___init___incorporate_child_on_error : - IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "incorporate_child_on_error". -Axiom ethereum_homestead_vm___init___incorporate_child_on_success : - IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "incorporate_child_on_success". +Axiom ethereum_homestead_vm_imports : + AreImported globals "ethereum.homestead.vm" [ "Evm"; "Message"; "incorporate_child_on_error"; "incorporate_child_on_success" ]. -Require ethereum.homestead.vm.gas. -Axiom ethereum_homestead_vm_gas_GAS_CALL : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_CALL". -Axiom ethereum_homestead_vm_gas_GAS_CREATE : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_CREATE". -Axiom ethereum_homestead_vm_gas_GAS_ZERO : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_ZERO". -Axiom ethereum_homestead_vm_gas_REFUND_SELF_DESTRUCT : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "REFUND_SELF_DESTRUCT". -Axiom ethereum_homestead_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_homestead_vm_gas_calculate_message_call_gas : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "calculate_message_call_gas". -Axiom ethereum_homestead_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "charge_gas". +Axiom ethereum_homestead_vm_gas_imports : + AreImported globals "ethereum.homestead.vm.gas" [ "GAS_CALL"; "GAS_CREATE"; "GAS_ZERO"; "REFUND_SELF_DESTRUCT"; "calculate_gas_extend_memory"; "calculate_message_call_gas"; "charge_gas" ]. -Require ethereum.homestead.vm.memory. -Axiom ethereum_homestead_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.homestead.vm.memory.globals "memory_read_bytes". -Axiom ethereum_homestead_vm_memory_memory_write : - IsGlobalAlias globals ethereum.homestead.vm.memory.globals "memory_write". +Axiom ethereum_homestead_vm_memory_imports : + AreImported globals "ethereum.homestead.vm.memory" [ "memory_read_bytes"; "memory_write" ]. -Require ethereum.homestead.vm.stack. -Axiom ethereum_homestead_vm_stack_pop : - IsGlobalAlias globals ethereum.homestead.vm.stack.globals "pop". -Axiom ethereum_homestead_vm_stack_push : - IsGlobalAlias globals ethereum.homestead.vm.stack.globals "push". +Axiom ethereum_homestead_vm_stack_imports : + AreImported globals "ethereum.homestead.vm.stack" [ "pop"; "push" ]. Definition create : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -624,7 +582,12 @@ Definition generic_call : Value.t -> Value.t -> M := make_list [ M.get_field (| M.get_name (| globals, "evm" |), "memory" |); M.get_name (| globals, "memory_output_start_position" |); - M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), M.slice (| Constant.None_, M.get_name (| globals, "actual_output_size" |) |) |) + M.slice (| + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), + Constant.None_, + M.get_name (| globals, "actual_output_size" |), + Constant.None_ + |) ], make_dict [] |) in @@ -1039,20 +1002,28 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in let parent_evm := M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "parent_evm" |) in - While Compare.is_not (| - M.get_name (| globals, "parent_evm" |), - Constant.None_ - |) do - let _ := M.call (| + let _ := + M.while (| + Compare.is_not (| + M.get_name (| globals, "parent_evm" |), + Constant.None_ + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "refunded_accounts" |), "update" |), make_list [ M.get_field (| M.get_name (| globals, "parent_evm" |), "accounts_to_delete" |) ], make_dict [] |) in - let parent_evm := - M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in - EndWhile. + let parent_evm := + M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := (* if *) M.if_then_else (| diff --git a/CoqOfPython/ethereum/homestead/vm/interpreter.v b/CoqOfPython/ethereum/homestead/vm/interpreter.v index 2f09635..f1c68be 100644 --- a/CoqOfPython/ethereum/homestead/vm/interpreter.v +++ b/CoqOfPython/ethereum/homestead/vm/interpreter.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.homestead.vm.interpreter". Definition expr_1 : Value.t := Constant.str " @@ -17,109 +17,47 @@ Introduction A straightforward interpreter that executes EVM code. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.trace. -Axiom ethereum_trace_EvmStop : - IsGlobalAlias globals ethereum.trace.globals "EvmStop". -Axiom ethereum_trace_OpEnd : - IsGlobalAlias globals ethereum.trace.globals "OpEnd". -Axiom ethereum_trace_OpException : - IsGlobalAlias globals ethereum.trace.globals "OpException". -Axiom ethereum_trace_OpStart : - IsGlobalAlias globals ethereum.trace.globals "OpStart". -Axiom ethereum_trace_PrecompileEnd : - IsGlobalAlias globals ethereum.trace.globals "PrecompileEnd". -Axiom ethereum_trace_PrecompileStart : - IsGlobalAlias globals ethereum.trace.globals "PrecompileStart". -Axiom ethereum_trace_TransactionEnd : - IsGlobalAlias globals ethereum.trace.globals "TransactionEnd". -Axiom ethereum_trace_evm_trace : - IsGlobalAlias globals ethereum.trace.globals "evm_trace". - -Require ethereum.homestead.blocks. -Axiom ethereum_homestead_blocks_Log : - IsGlobalAlias globals ethereum.homestead.blocks.globals "Log". - -Require ethereum.homestead.fork_types. -Axiom ethereum_homestead_fork_types_Address : - IsGlobalAlias globals ethereum.homestead.fork_types.globals "Address". - -Require ethereum.homestead.state. -Axiom ethereum_homestead_state_account_has_code_or_nonce : - IsGlobalAlias globals ethereum.homestead.state.globals "account_has_code_or_nonce". -Axiom ethereum_homestead_state_begin_transaction : - IsGlobalAlias globals ethereum.homestead.state.globals "begin_transaction". -Axiom ethereum_homestead_state_commit_transaction : - IsGlobalAlias globals ethereum.homestead.state.globals "commit_transaction". -Axiom ethereum_homestead_state_destroy_storage : - IsGlobalAlias globals ethereum.homestead.state.globals "destroy_storage". -Axiom ethereum_homestead_state_move_ether : - IsGlobalAlias globals ethereum.homestead.state.globals "move_ether". -Axiom ethereum_homestead_state_rollback_transaction : - IsGlobalAlias globals ethereum.homestead.state.globals "rollback_transaction". -Axiom ethereum_homestead_state_set_code : - IsGlobalAlias globals ethereum.homestead.state.globals "set_code". -Axiom ethereum_homestead_state_touch_account : - IsGlobalAlias globals ethereum.homestead.state.globals "touch_account". - -Require ethereum.homestead.vm.__init__. -Axiom ethereum_homestead_vm___init___Message : - IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "Message". - -Require ethereum.homestead.vm.gas. -Axiom ethereum_homestead_vm_gas_GAS_CODE_DEPOSIT : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_CODE_DEPOSIT". -Axiom ethereum_homestead_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "charge_gas". - -Require ethereum.homestead.vm.precompiled_contracts.mapping. -Axiom ethereum_homestead_vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : - IsGlobalAlias globals ethereum.homestead.vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". - -Require ethereum.homestead.vm.__init__. -Axiom ethereum_homestead_vm___init___Environment : - IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "Environment". -Axiom ethereum_homestead_vm___init___Evm : - IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "Evm". - -Require ethereum.homestead.vm.exceptions. -Axiom ethereum_homestead_vm_exceptions_AddressCollision : - IsGlobalAlias globals ethereum.homestead.vm.exceptions.globals "AddressCollision". -Axiom ethereum_homestead_vm_exceptions_ExceptionalHalt : - IsGlobalAlias globals ethereum.homestead.vm.exceptions.globals "ExceptionalHalt". -Axiom ethereum_homestead_vm_exceptions_InvalidOpcode : - IsGlobalAlias globals ethereum.homestead.vm.exceptions.globals "InvalidOpcode". -Axiom ethereum_homestead_vm_exceptions_StackDepthLimitError : - IsGlobalAlias globals ethereum.homestead.vm.exceptions.globals "StackDepthLimitError". - -Require ethereum.homestead.vm.instructions.__init__. -Axiom ethereum_homestead_vm_instructions___init___Ops : - IsGlobalAlias globals ethereum.homestead.vm.instructions.__init__.globals "Ops". -Axiom ethereum_homestead_vm_instructions___init___op_implementation : - IsGlobalAlias globals ethereum.homestead.vm.instructions.__init__.globals "op_implementation". - -Require ethereum.homestead.vm.runtime. -Axiom ethereum_homestead_vm_runtime_get_valid_jump_destinations : - IsGlobalAlias globals ethereum.homestead.vm.runtime.globals "get_valid_jump_destinations". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Optional"; "Set"; "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. + +Axiom ethereum_trace_imports : + AreImported globals "ethereum.trace" [ "EvmStop"; "OpEnd"; "OpException"; "OpStart"; "PrecompileEnd"; "PrecompileStart"; "TransactionEnd"; "evm_trace" ]. + +Axiom ethereum_homestead_blocks_imports : + AreImported globals "ethereum.homestead.blocks" [ "Log" ]. + +Axiom ethereum_homestead_fork_types_imports : + AreImported globals "ethereum.homestead.fork_types" [ "Address" ]. + +Axiom ethereum_homestead_state_imports : + AreImported globals "ethereum.homestead.state" [ "account_has_code_or_nonce"; "begin_transaction"; "commit_transaction"; "destroy_storage"; "move_ether"; "rollback_transaction"; "set_code"; "touch_account" ]. + +Axiom ethereum_homestead_vm_imports : + AreImported globals "ethereum.homestead.vm" [ "Message" ]. + +Axiom ethereum_homestead_vm_gas_imports : + AreImported globals "ethereum.homestead.vm.gas" [ "GAS_CODE_DEPOSIT"; "charge_gas" ]. + +Axiom ethereum_homestead_vm_precompiled_contracts_mapping_imports : + AreImported globals "ethereum.homestead.vm.precompiled_contracts.mapping" [ "PRE_COMPILED_CONTRACTS" ]. + +Axiom ethereum_homestead_vm_imports : + AreImported globals "ethereum.homestead.vm" [ "Environment"; "Evm" ]. + +Axiom ethereum_homestead_vm_exceptions_imports : + AreImported globals "ethereum.homestead.vm.exceptions" [ "AddressCollision"; "ExceptionalHalt"; "InvalidOpcode"; "StackDepthLimitError" ]. + +Axiom ethereum_homestead_vm_instructions_imports : + AreImported globals "ethereum.homestead.vm.instructions" [ "Ops"; "op_implementation" ]. + +Axiom ethereum_homestead_vm_runtime_imports : + AreImported globals "ethereum.homestead.vm.runtime" [ "get_valid_jump_destinations" ]. Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -424,7 +362,7 @@ Definition process_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "StackDepthLimitError" |), make_list [ Constant.str "Stack depth limit reached" diff --git a/CoqOfPython/ethereum/homestead/vm/memory.v b/CoqOfPython/ethereum/homestead/vm/memory.v index 08d2290..c36e579 100644 --- a/CoqOfPython/ethereum/homestead/vm/memory.v +++ b/CoqOfPython/ethereum/homestead/vm/memory.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.homestead.vm.memory". Definition expr_1 : Value.t := Constant.str " @@ -17,17 +17,11 @@ Introduction EVM memory operations. ". -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_right_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "right_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "right_pad_zero_bytes" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. Definition memory_write : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,22 +39,27 @@ Definition memory_write : Value.t -> Value.t -> M := Data to write to memory. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + M.slice (| + M.get_name (| globals, "memory" |), + M.get_name (| globals, "start_position" |), + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) - |) |) |), + Constant.None_ + |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_)). @@ -86,22 +85,27 @@ Definition memory_read_bytes : Value.t -> Value.t -> M := Data read from memory. " in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + M.slice (| + M.get_name (| globals, "memory" |), + M.get_name (| globals, "start_position" |), + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |) |) + Constant.None_ + |) |) in M.pure Constant.None_)). @@ -129,22 +133,27 @@ Definition buffer_read : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "right_pad_zero_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "buffer" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + M.slice (| + M.get_name (| globals, "buffer" |), + M.get_name (| globals, "start_position" |), + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |) |); + Constant.None_ + |); M.get_name (| globals, "size" |) ], make_dict [] diff --git a/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/__init__.v index 8a37e98..0649114 100644 --- a/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/__init__.v +++ b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.homestead.vm.precompiled_contracts.__init__". Definition expr_1 : Value.t := Constant.str " @@ -18,9 +18,8 @@ Addresses of precompiled contracts and mappings to their implementations. ". -Require ethereum.homestead.utils.hexadecimal. -Axiom ethereum_homestead_utils_hexadecimal_hex_to_address : - IsGlobalAlias globals ethereum.homestead.utils.hexadecimal.globals "hex_to_address". +Axiom ethereum_homestead_utils_hexadecimal_imports : + AreImported globals "ethereum.homestead.utils.hexadecimal" [ "hex_to_address" ]. Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS" ] diff --git a/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/ecrecover.v index d269a09..ef0e625 100644 --- a/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/ecrecover.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.homestead.vm.precompiled_contracts.ecrecover". Definition expr_1 : Value.t := Constant.str " @@ -17,39 +17,26 @@ Introduction Implementation of the ECRECOVER precompiled contract. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.crypto.elliptic_curve. -Axiom ethereum_crypto_elliptic_curve_SECP256K1N : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". -Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". +Axiom ethereum_crypto_elliptic_curve_imports : + AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_left_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. -Require ethereum.homestead.vm.__init__. -Axiom ethereum_homestead_vm___init___Evm : - IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "Evm". +Axiom ethereum_homestead_vm_imports : + AreImported globals "ethereum.homestead.vm" [ "Evm" ]. -Require ethereum.homestead.vm.gas. -Axiom ethereum_homestead_vm_gas_GAS_ECRECOVER : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_ECRECOVER". -Axiom ethereum_homestead_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "charge_gas". +Axiom ethereum_homestead_vm_gas_imports : + AreImported globals "ethereum.homestead.vm.gas" [ "GAS_ECRECOVER"; "charge_gas" ]. -Require ethereum.homestead.vm.memory. -Axiom ethereum_homestead_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.homestead.vm.memory.globals "buffer_read". +Axiom ethereum_homestead_vm_memory_imports : + AreImported globals "ethereum.homestead.vm.memory" [ "buffer_read" ]. Definition ecrecover : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -264,13 +251,18 @@ Definition ecrecover : Value.t -> Value.t -> M := )) |) in (* At stmt: unsupported node type: Try *) let address := - M.get_subscript (| M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "public_key" |) - ], - make_dict [] - |), M.slice (| Constant.int 12, Constant.int 32 |) |) in + M.slice (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), + Constant.int 12, + Constant.int 32, + Constant.None_ + |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/identity.v index 74c03df..b5a7610 100644 --- a/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/identity.v +++ b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/identity.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.homestead.vm.precompiled_contracts.identity". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementation of the `IDENTITY` precompiled contract. ". -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.homestead.vm.__init__. -Axiom ethereum_homestead_vm___init___Evm : - IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "Evm". +Axiom ethereum_homestead_vm_imports : + AreImported globals "ethereum.homestead.vm" [ "Evm" ]. -Require ethereum.homestead.vm.gas. -Axiom ethereum_homestead_vm_gas_GAS_IDENTITY : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_IDENTITY". -Axiom ethereum_homestead_vm_gas_GAS_IDENTITY_WORD : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_IDENTITY_WORD". -Axiom ethereum_homestead_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "charge_gas". +Axiom ethereum_homestead_vm_gas_imports : + AreImported globals "ethereum.homestead.vm.gas" [ "GAS_IDENTITY"; "GAS_IDENTITY_WORD"; "charge_gas" ]. Definition identity : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/mapping.v index f519b0e..e083ecf 100644 --- a/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/mapping.v +++ b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/mapping.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.homestead.vm.precompiled_contracts.mapping". Definition expr_1 : Value.t := Constant.str " @@ -17,40 +17,25 @@ Introduction Mapping of precompiled contracts their implementations. ". -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". - -Require ethereum.homestead.fork_types. -Axiom ethereum_homestead_fork_types_Address : - IsGlobalAlias globals ethereum.homestead.fork_types.globals "Address". - -Require ethereum.homestead.vm.precompiled_contracts.__init__. -Axiom ethereum_homestead_vm_precompiled_contracts___init___ECRECOVER_ADDRESS : - IsGlobalAlias globals ethereum.homestead.vm.precompiled_contracts.__init__.globals "ECRECOVER_ADDRESS". -Axiom ethereum_homestead_vm_precompiled_contracts___init___IDENTITY_ADDRESS : - IsGlobalAlias globals ethereum.homestead.vm.precompiled_contracts.__init__.globals "IDENTITY_ADDRESS". -Axiom ethereum_homestead_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : - IsGlobalAlias globals ethereum.homestead.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". -Axiom ethereum_homestead_vm_precompiled_contracts___init___SHA256_ADDRESS : - IsGlobalAlias globals ethereum.homestead.vm.precompiled_contracts.__init__.globals "SHA256_ADDRESS". - -Require ethereum.homestead.vm.precompiled_contracts.ecrecover. -Axiom ethereum_homestead_vm_precompiled_contracts_ecrecover_ecrecover : - IsGlobalAlias globals ethereum.homestead.vm.precompiled_contracts.ecrecover.globals "ecrecover". - -Require ethereum.homestead.vm.precompiled_contracts.identity. -Axiom ethereum_homestead_vm_precompiled_contracts_identity_identity : - IsGlobalAlias globals ethereum.homestead.vm.precompiled_contracts.identity.globals "identity". - -Require ethereum.homestead.vm.precompiled_contracts.ripemd160. -Axiom ethereum_homestead_vm_precompiled_contracts_ripemd160_ripemd160 : - IsGlobalAlias globals ethereum.homestead.vm.precompiled_contracts.ripemd160.globals "ripemd160". - -Require ethereum.homestead.vm.precompiled_contracts.sha256. -Axiom ethereum_homestead_vm_precompiled_contracts_sha256_sha256 : - IsGlobalAlias globals ethereum.homestead.vm.precompiled_contracts.sha256.globals "sha256". +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict" ]. + +Axiom ethereum_homestead_fork_types_imports : + AreImported globals "ethereum.homestead.fork_types" [ "Address" ]. + +Axiom ethereum_homestead_vm_precompiled_contracts_imports : + AreImported globals "ethereum.homestead.vm.precompiled_contracts" [ "ECRECOVER_ADDRESS"; "IDENTITY_ADDRESS"; "RIPEMD160_ADDRESS"; "SHA256_ADDRESS" ]. + +Axiom ethereum_homestead_vm_precompiled_contracts_ecrecover_imports : + AreImported globals "ethereum.homestead.vm.precompiled_contracts.ecrecover" [ "ecrecover" ]. + +Axiom ethereum_homestead_vm_precompiled_contracts_identity_imports : + AreImported globals "ethereum.homestead.vm.precompiled_contracts.identity" [ "identity" ]. + +Axiom ethereum_homestead_vm_precompiled_contracts_ripemd160_imports : + AreImported globals "ethereum.homestead.vm.precompiled_contracts.ripemd160" [ "ripemd160" ]. + +Axiom ethereum_homestead_vm_precompiled_contracts_sha256_imports : + AreImported globals "ethereum.homestead.vm.precompiled_contracts.sha256" [ "sha256" ]. (* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/ripemd160.v index 471df33..1ad1433 100644 --- a/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/ripemd160.v +++ b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/ripemd160.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.homestead.vm.precompiled_contracts.ripemd160". Definition expr_1 : Value.t := Constant.str " @@ -19,29 +19,20 @@ Implementation of the `RIPEMD160` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_left_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.homestead.vm.__init__. -Axiom ethereum_homestead_vm___init___Evm : - IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "Evm". +Axiom ethereum_homestead_vm_imports : + AreImported globals "ethereum.homestead.vm" [ "Evm" ]. -Require ethereum.homestead.vm.gas. -Axiom ethereum_homestead_vm_gas_GAS_RIPEMD160 : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_RIPEMD160". -Axiom ethereum_homestead_vm_gas_GAS_RIPEMD160_WORD : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_RIPEMD160_WORD". -Axiom ethereum_homestead_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "charge_gas". +Axiom ethereum_homestead_vm_gas_imports : + AreImported globals "ethereum.homestead.vm.gas" [ "GAS_RIPEMD160"; "GAS_RIPEMD160_WORD"; "charge_gas" ]. Definition ripemd160 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/sha256.v index af87e60..c6bc0bc 100644 --- a/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/sha256.v +++ b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/sha256.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.homestead.vm.precompiled_contracts.sha256". Definition expr_1 : Value.t := Constant.str " @@ -19,25 +19,17 @@ Implementation of the `SHA256` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.homestead.vm.__init__. -Axiom ethereum_homestead_vm___init___Evm : - IsGlobalAlias globals ethereum.homestead.vm.__init__.globals "Evm". +Axiom ethereum_homestead_vm_imports : + AreImported globals "ethereum.homestead.vm" [ "Evm" ]. -Require ethereum.homestead.vm.gas. -Axiom ethereum_homestead_vm_gas_GAS_SHA256 : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_SHA256". -Axiom ethereum_homestead_vm_gas_GAS_SHA256_WORD : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "GAS_SHA256_WORD". -Axiom ethereum_homestead_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.homestead.vm.gas.globals "charge_gas". +Axiom ethereum_homestead_vm_gas_imports : + AreImported globals "ethereum.homestead.vm.gas" [ "GAS_SHA256"; "GAS_SHA256_WORD"; "charge_gas" ]. Definition sha256 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/homestead/vm/runtime.v b/CoqOfPython/ethereum/homestead/vm/runtime.v index b4e2487..fe4477f 100644 --- a/CoqOfPython/ethereum/homestead/vm/runtime.v +++ b/CoqOfPython/ethereum/homestead/vm/runtime.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.homestead.vm.runtime". Definition expr_1 : Value.t := Constant.str " @@ -17,17 +17,14 @@ Introduction Runtime related operations used while executing EVM code. ". -Require typing. -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". +Axiom typing_imports : + AreImported globals "typing" [ "Set" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.homestead.vm.instructions.__init__. -Axiom ethereum_homestead_vm_instructions___init___Ops : - IsGlobalAlias globals ethereum.homestead.vm.instructions.__init__.globals "Ops". +Axiom ethereum_homestead_vm_instructions_imports : + AreImported globals "ethereum.homestead.vm.instructions" [ "Ops" ]. Definition get_valid_jump_destinations : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -67,75 +64,83 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := ], make_dict [] |) in - While Compare.lt (| - M.get_name (| globals, "pc" |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "code" |) - ], - make_dict [] - |) - |) do -(* At stmt: unsupported node type: Try *) - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "current_opcode" |), - M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) - |), - (* then *) + let _ := + M.while (| + Compare.lt (| + M.get_name (| globals, "pc" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) + |), ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), - make_list [ - M.get_name (| globals, "pc" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( +(* At stmt: unsupported node type: Try *) let _ := (* if *) M.if_then_else (| - BoolOp.and (| - Compare.lt_e (| - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |), - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |) - |), - ltac:(M.monadic ( - Compare.lt_e (| - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH32" |), "value" |) - |) - )) + Compare.eq (| + M.get_name (| globals, "current_opcode" |), + M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) |), (* then *) ltac:(M.monadic ( - let push_data_size := - BinOp.add (| - BinOp.sub (| - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) - |), - Constant.int 1 - |) in - let pc := BinOp.add - M.get_name (| globals, "push_data_size" |) - M.get_name (| globals, "push_data_size" |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), + make_list [ + M.get_name (| globals, "pc" |) + ], + make_dict [] + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.lt_e (| + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |), + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH32" |), "value" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let push_data_size := + BinOp.add (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) + |), + Constant.int 1 + |) in + let pc := BinOp.add + M.get_name (| globals, "push_data_size" |) + M.get_name (| globals, "push_data_size" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ )) |) in + let pc := BinOp.add + Constant.int 1 + Constant.int 1 in M.pure Constant.None_ - )) |) in - let pc := BinOp.add - Constant.int 1 - Constant.int 1 in - EndWhile. + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.get_name (| globals, "valid_jump_destinations" |) |) in diff --git a/CoqOfPython/ethereum/homestead/vm/stack.v b/CoqOfPython/ethereum/homestead/vm/stack.v index 6acecf3..caaa1d4 100644 --- a/CoqOfPython/ethereum/homestead/vm/stack.v +++ b/CoqOfPython/ethereum/homestead/vm/stack.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.homestead.vm.stack". Definition expr_1 : Value.t := Constant.str " @@ -17,19 +17,14 @@ Introduction Implementation of the stack operators for the EVM. ". -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". +Axiom typing_imports : + AreImported globals "typing" [ "List" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.homestead.vm.exceptions. -Axiom ethereum_homestead_vm_exceptions_StackOverflowError : - IsGlobalAlias globals ethereum.homestead.vm.exceptions.globals "StackOverflowError". -Axiom ethereum_homestead_vm_exceptions_StackUnderflowError : - IsGlobalAlias globals ethereum.homestead.vm.exceptions.globals "StackUnderflowError". +Axiom ethereum_homestead_vm_exceptions_imports : + AreImported globals "ethereum.homestead.vm.exceptions" [ "StackOverflowError"; "StackUnderflowError" ]. Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -63,7 +58,7 @@ Definition pop : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "StackUnderflowError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "StackUnderflowError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -108,7 +103,7 @@ Definition push : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "StackOverflowError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "StackOverflowError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/istanbul/__init__.v b/CoqOfPython/ethereum/istanbul/__init__.v index bea9b01..2a28913 100644 --- a/CoqOfPython/ethereum/istanbul/__init__.v +++ b/CoqOfPython/ethereum/istanbul/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.istanbul.__init__". Definition expr_1 : Value.t := Constant.str " @@ -9,9 +9,8 @@ adds a cryptographic primitive, and introduces an instruction to fetch the current chain identifier. ". -Require ethereum.fork_criteria. -Axiom ethereum_fork_criteria_ByBlockNumber : - IsGlobalAlias globals ethereum.fork_criteria.globals "ByBlockNumber". +Axiom ethereum_fork_criteria_imports : + AreImported globals "ethereum.fork_criteria" [ "ByBlockNumber" ]. Definition FORK_CRITERIA : Value.t := M.run ltac:(M.monadic ( M.call (| diff --git a/CoqOfPython/ethereum/istanbul/blocks.v b/CoqOfPython/ethereum/istanbul/blocks.v index 0375d8d..ea63e2d 100644 --- a/CoqOfPython/ethereum/istanbul/blocks.v +++ b/CoqOfPython/ethereum/istanbul/blocks.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.istanbul.blocks". Definition expr_1 : Value.t := Constant.str " @@ -14,43 +14,23 @@ history of all state transitions that have happened since the genesis of the chain. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes8 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes8". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". - -Require ethereum.istanbul.fork_types. -Axiom ethereum_istanbul_fork_types_Address : - IsGlobalAlias globals ethereum.istanbul.fork_types.globals "Address". -Axiom ethereum_istanbul_fork_types_Bloom : - IsGlobalAlias globals ethereum.istanbul.fork_types.globals "Bloom". -Axiom ethereum_istanbul_fork_types_Root : - IsGlobalAlias globals ethereum.istanbul.fork_types.globals "Root". - -Require ethereum.istanbul.transactions. -Axiom ethereum_istanbul_transactions_Transaction : - IsGlobalAlias globals ethereum.istanbul.transactions.globals "Transaction". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes8"; "Bytes32"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. + +Axiom ethereum_istanbul_fork_types_imports : + AreImported globals "ethereum.istanbul.fork_types" [ "Address"; "Bloom"; "Root" ]. + +Axiom ethereum_istanbul_transactions_imports : + AreImported globals "ethereum.istanbul.transactions" [ "Transaction" ]. Definition Header : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/istanbul/bloom.v b/CoqOfPython/ethereum/istanbul/bloom.v index e9ff47e..f2f7123 100644 --- a/CoqOfPython/ethereum/istanbul/bloom.v +++ b/CoqOfPython/ethereum/istanbul/bloom.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.istanbul.bloom". Definition expr_1 : Value.t := Constant.str " @@ -21,25 +21,20 @@ for efficient searching of logs by address and/or topic, by rapidly eliminating blocks and receipts from their search. ". -Require typing. -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_imports : + AreImported globals "typing" [ "Tuple" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. -Require ethereum.istanbul.blocks. -Axiom ethereum_istanbul_blocks_Log : - IsGlobalAlias globals ethereum.istanbul.blocks.globals "Log". +Axiom ethereum_istanbul_blocks_imports : + AreImported globals "ethereum.istanbul.blocks" [ "Log" ]. -Require ethereum.istanbul.fork_types. -Axiom ethereum_istanbul_fork_types_Bloom : - IsGlobalAlias globals ethereum.istanbul.fork_types.globals "Bloom". +Axiom ethereum_istanbul_fork_types_imports : + AreImported globals "ethereum.istanbul.fork_types" [ "Bloom" ]. Definition add_to_bloom : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -66,50 +61,70 @@ Definition add_to_bloom : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "idx" |) in make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ] do - let bit_to_set := - BinOp.bit_and (| - M.call (| - M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "hash" |), M.slice (| M.get_name (| globals, "idx" |), BinOp.add (| - M.get_name (| globals, "idx" |), - Constant.int 2 - |) |) |) - ], - make_dict [] - |), - Constant.int 2047 - |) in - let bit_index := - BinOp.sub (| - Constant.int 2047, - M.get_name (| globals, "bit_to_set" |) - |) in - let byte_index := - BinOp.floor_div (| - M.get_name (| globals, "bit_index" |), - Constant.int 8 - |) in - let bit_value := - BinOp.l_shift (| - Constant.int 1, - BinOp.sub (| - Constant.int 7, - BinOp.mod_ (| + let _ := + M.for_ (| + M.get_name (| globals, "idx" |), + make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ], + ltac:(M.monadic ( + let bit_to_set := + BinOp.bit_and (| + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.slice (| + M.get_name (| globals, "hash" |), + M.get_name (| globals, "idx" |), + BinOp.add (| + M.get_name (| globals, "idx" |), + Constant.int 2 + |), + Constant.None_ + |) + ], + make_dict [] + |), + Constant.int 2047 + |) in + let bit_index := + BinOp.sub (| + Constant.int 2047, + M.get_name (| globals, "bit_to_set" |) + |) in + let byte_index := + BinOp.floor_div (| M.get_name (| globals, "bit_index" |), Constant.int 8 + |) in + let bit_value := + BinOp.l_shift (| + Constant.int 1, + BinOp.sub (| + Constant.int 7, + BinOp.mod_ (| + M.get_name (| globals, "bit_index" |), + Constant.int 8 + |) + |) + |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "bloom" |), + M.get_name (| globals, "byte_index" |) + |), + BinOp.bit_or (| + M.get_subscript (| + M.get_name (| globals, "bloom" |), + M.get_name (| globals, "byte_index" |) + |), + M.get_name (| globals, "bit_value" |) |) - |) - |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), - BinOp.bit_or (| - M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), - M.get_name (| globals, "bit_value" |) - |) - |) in - EndFor. + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_)). Definition logs_bloom : Value.t -> Value.t -> M := @@ -132,8 +147,12 @@ Definition logs_bloom : Value.t -> Value.t -> M := the caller address and the log topics. " in (* At stmt: unsupported node type: AnnAssign *) - For M.get_name (| globals, "log" |) in M.get_name (| globals, "logs" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "log" |), + M.get_name (| globals, "logs" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "add_to_bloom" |), make_list [ M.get_name (| globals, "bloom" |); @@ -141,8 +160,12 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "topic" |) in M.get_field (| M.get_name (| globals, "log" |), "topics" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "topic" |), + M.get_field (| M.get_name (| globals, "log" |), "topics" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "add_to_bloom" |), make_list [ M.get_name (| globals, "bloom" |); @@ -150,8 +173,18 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Bloom" |), diff --git a/CoqOfPython/ethereum/istanbul/fork.v b/CoqOfPython/ethereum/istanbul/fork.v index 8c0dbe2..39cc961 100644 --- a/CoqOfPython/ethereum/istanbul/fork.v +++ b/CoqOfPython/ethereum/istanbul/fork.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.istanbul.fork". Definition expr_1 : Value.t := Constant.str " @@ -17,139 +17,62 @@ Introduction Entry point for the Ethereum specification. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". - -Require ethereum.crypto.elliptic_curve. -Axiom ethereum_crypto_elliptic_curve_SECP256K1N : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". -Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.ethash. -Axiom ethereum_ethash_dataset_size : - IsGlobalAlias globals ethereum.ethash.globals "dataset_size". -Axiom ethereum_ethash_generate_cache : - IsGlobalAlias globals ethereum.ethash.globals "generate_cache". -Axiom ethereum_ethash_hashimoto_light : - IsGlobalAlias globals ethereum.ethash.globals "hashimoto_light". - -Require ethereum.exceptions. -Axiom ethereum_exceptions_InvalidBlock : - IsGlobalAlias globals ethereum.exceptions.globals "InvalidBlock". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U64 : - IsGlobalAlias globals ethereum.base_types.globals "U64". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_U256_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.istanbul.__init__. -Axiom ethereum_istanbul___init___vm : - IsGlobalAlias globals ethereum.istanbul.__init__.globals "vm". - -Require ethereum.istanbul.blocks. -Axiom ethereum_istanbul_blocks_Block : - IsGlobalAlias globals ethereum.istanbul.blocks.globals "Block". -Axiom ethereum_istanbul_blocks_Header : - IsGlobalAlias globals ethereum.istanbul.blocks.globals "Header". -Axiom ethereum_istanbul_blocks_Log : - IsGlobalAlias globals ethereum.istanbul.blocks.globals "Log". -Axiom ethereum_istanbul_blocks_Receipt : - IsGlobalAlias globals ethereum.istanbul.blocks.globals "Receipt". - -Require ethereum.istanbul.bloom. -Axiom ethereum_istanbul_bloom_logs_bloom : - IsGlobalAlias globals ethereum.istanbul.bloom.globals "logs_bloom". - -Require ethereum.istanbul.fork_types. -Axiom ethereum_istanbul_fork_types_Address : - IsGlobalAlias globals ethereum.istanbul.fork_types.globals "Address". -Axiom ethereum_istanbul_fork_types_Bloom : - IsGlobalAlias globals ethereum.istanbul.fork_types.globals "Bloom". -Axiom ethereum_istanbul_fork_types_Root : - IsGlobalAlias globals ethereum.istanbul.fork_types.globals "Root". - -Require ethereum.istanbul.state. -Axiom ethereum_istanbul_state_State : - IsGlobalAlias globals ethereum.istanbul.state.globals "State". -Axiom ethereum_istanbul_state_account_exists_and_is_empty : - IsGlobalAlias globals ethereum.istanbul.state.globals "account_exists_and_is_empty". -Axiom ethereum_istanbul_state_create_ether : - IsGlobalAlias globals ethereum.istanbul.state.globals "create_ether". -Axiom ethereum_istanbul_state_destroy_account : - IsGlobalAlias globals ethereum.istanbul.state.globals "destroy_account". -Axiom ethereum_istanbul_state_get_account : - IsGlobalAlias globals ethereum.istanbul.state.globals "get_account". -Axiom ethereum_istanbul_state_increment_nonce : - IsGlobalAlias globals ethereum.istanbul.state.globals "increment_nonce". -Axiom ethereum_istanbul_state_set_account_balance : - IsGlobalAlias globals ethereum.istanbul.state.globals "set_account_balance". -Axiom ethereum_istanbul_state_state_root : - IsGlobalAlias globals ethereum.istanbul.state.globals "state_root". - -Require ethereum.istanbul.transactions. -Axiom ethereum_istanbul_transactions_TX_BASE_COST : - IsGlobalAlias globals ethereum.istanbul.transactions.globals "TX_BASE_COST". -Axiom ethereum_istanbul_transactions_TX_CREATE_COST : - IsGlobalAlias globals ethereum.istanbul.transactions.globals "TX_CREATE_COST". -Axiom ethereum_istanbul_transactions_TX_DATA_COST_PER_NON_ZERO : - IsGlobalAlias globals ethereum.istanbul.transactions.globals "TX_DATA_COST_PER_NON_ZERO". -Axiom ethereum_istanbul_transactions_TX_DATA_COST_PER_ZERO : - IsGlobalAlias globals ethereum.istanbul.transactions.globals "TX_DATA_COST_PER_ZERO". -Axiom ethereum_istanbul_transactions_Transaction : - IsGlobalAlias globals ethereum.istanbul.transactions.globals "Transaction". - -Require ethereum.istanbul.trie. -Axiom ethereum_istanbul_trie_Trie : - IsGlobalAlias globals ethereum.istanbul.trie.globals "Trie". -Axiom ethereum_istanbul_trie_root : - IsGlobalAlias globals ethereum.istanbul.trie.globals "root". -Axiom ethereum_istanbul_trie_trie_set : - IsGlobalAlias globals ethereum.istanbul.trie.globals "trie_set". - -Require ethereum.istanbul.utils.message. -Axiom ethereum_istanbul_utils_message_prepare_message : - IsGlobalAlias globals ethereum.istanbul.utils.message.globals "prepare_message". - -Require ethereum.istanbul.vm.interpreter. -Axiom ethereum_istanbul_vm_interpreter_process_message_call : - IsGlobalAlias globals ethereum.istanbul.vm.interpreter.globals "process_message_call". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Bytes0" ]. + +Axiom ethereum_crypto_elliptic_curve_imports : + AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. + +Axiom ethereum_ethash_imports : + AreImported globals "ethereum.ethash" [ "dataset_size"; "generate_cache"; "hashimoto_light" ]. + +Axiom ethereum_exceptions_imports : + AreImported globals "ethereum.exceptions" [ "InvalidBlock" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U64"; "U256"; "U256_CEIL_VALUE"; "Bytes"; "Uint" ]. + +Axiom ethereum_istanbul_imports : + AreImported globals "ethereum.istanbul" [ "vm" ]. + +Axiom ethereum_istanbul_blocks_imports : + AreImported globals "ethereum.istanbul.blocks" [ "Block"; "Header"; "Log"; "Receipt" ]. + +Axiom ethereum_istanbul_bloom_imports : + AreImported globals "ethereum.istanbul.bloom" [ "logs_bloom" ]. + +Axiom ethereum_istanbul_fork_types_imports : + AreImported globals "ethereum.istanbul.fork_types" [ "Address"; "Bloom"; "Root" ]. + +Axiom ethereum_istanbul_state_imports : + AreImported globals "ethereum.istanbul.state" [ "State"; "account_exists_and_is_empty"; "create_ether"; "destroy_account"; "get_account"; "increment_nonce"; "set_account_balance"; "state_root" ]. + +Axiom ethereum_istanbul_transactions_imports : + AreImported globals "ethereum.istanbul.transactions" [ "TX_BASE_COST"; "TX_CREATE_COST"; "TX_DATA_COST_PER_NON_ZERO"; "TX_DATA_COST_PER_ZERO"; "Transaction" ]. + +Axiom ethereum_istanbul_trie_imports : + AreImported globals "ethereum.istanbul.trie" [ "Trie"; "root"; "trie_set" ]. + +Axiom ethereum_istanbul_utils_message_imports : + AreImported globals "ethereum.istanbul.utils.message" [ "prepare_message" ]. + +Axiom ethereum_istanbul_vm_interpreter_imports : + AreImported globals "ethereum.istanbul.vm.interpreter" [ "process_message_call" ]. Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -268,7 +191,12 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := Hashes of the recent 256 blocks in order of increasing block number. " in let recent_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) in + M.slice (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| Constant.int 255 |), + Constant.None_, + Constant.None_ + |) in let _ := (* if *) M.if_then_else (| @@ -294,17 +222,26 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := )) |) in let recent_block_hashes := make_list [] in - For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_blocks" |) do - let prev_block_hash := - M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "block" |), + M.get_name (| globals, "recent_blocks" |), + ltac:(M.monadic ( + let prev_block_hash := + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in + let _ := M.call (| M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), make_list [ M.get_name (| globals, "prev_block_hash" |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let most_recent_block_hash := M.call (| M.get_name (| globals, "keccak256" |), @@ -312,7 +249,10 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), make_list [ - M.get_field (| M.get_subscript (| M.get_name (| globals, "recent_blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) + M.get_field (| M.get_subscript (| + M.get_name (| globals, "recent_blocks" |), + UnOp.sub (| Constant.int 1 |) + |), "header" |) ], make_dict [] |) @@ -356,7 +296,10 @@ Definition state_transition : Value.t -> Value.t -> M := Block to apply to `chain`. " in let parent_header := - M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) in + M.get_field (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| Constant.int 1 |) + |), "header" |) in let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ @@ -476,7 +419,12 @@ Definition state_transition : Value.t -> Value.t -> M := ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) + M.slice (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| Constant.int 255 |), + Constant.None_, + Constant.None_ + |) |) in M.pure Constant.None_ (* else *) @@ -903,14 +851,18 @@ Definition apply_body : Value.t -> Value.t -> M := (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) - For make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "tx" |) ] in M.call (| - M.get_name (| globals, "enumerate" |), - make_list [ - M.get_name (| globals, "transactions" |) - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "tx" |) ], + M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "transactions" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ M.get_name (| globals, "transactions_trie" |); @@ -931,51 +883,51 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_address := - M.call (| - M.get_name (| globals, "check_transaction" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "gas_available" |); - M.get_name (| globals, "chain_id" |) - ], - make_dict [] - |) in - let env := - M.call (| - M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), - make_list [], - make_dict [] - |) in - let _ := M.assign (| - make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |); M.get_name (| globals, "error" |) ], - M.call (| - M.get_name (| globals, "process_transaction" |), - make_list [ - M.get_name (| globals, "env" |); - M.get_name (| globals, "tx" |) - ], - make_dict [] - |) - |) in - let gas_available := BinOp.sub - M.get_name (| globals, "gas_used" |) - M.get_name (| globals, "gas_used" |) in - let receipt := - M.call (| - M.get_name (| globals, "make_receipt" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "error" |); - BinOp.sub (| - M.get_name (| globals, "block_gas_limit" |), - M.get_name (| globals, "gas_available" |) - |); - M.get_name (| globals, "logs" |) - ], - make_dict [] - |) in - let _ := M.call (| + let sender_address := + M.call (| + M.get_name (| globals, "check_transaction" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "gas_available" |); + M.get_name (| globals, "chain_id" |) + ], + make_dict [] + |) in + let env := + M.call (| + M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |); M.get_name (| globals, "error" |) ], + M.call (| + M.get_name (| globals, "process_transaction" |), + make_list [ + M.get_name (| globals, "env" |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) in + let gas_available := BinOp.sub + M.get_name (| globals, "gas_used" |) + M.get_name (| globals, "gas_used" |) in + let receipt := + M.call (| + M.get_name (| globals, "make_receipt" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "error" |); + BinOp.sub (| + M.get_name (| globals, "block_gas_limit" |), + M.get_name (| globals, "gas_available" |) + |); + M.get_name (| globals, "logs" |) + ], + make_dict [] + |) in + let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ M.get_name (| globals, "receipts_trie" |); @@ -996,10 +948,15 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_logs := BinOp.add - M.get_name (| globals, "logs" |) - M.get_name (| globals, "logs" |) in - EndFor. + let block_logs := BinOp.add + M.get_name (| globals, "logs" |) + M.get_name (| globals, "logs" |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.call (| M.get_name (| globals, "pay_rewards" |), make_list [ @@ -1128,8 +1085,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "ommer" |), + M.get_name (| globals, "ommers" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ BoolOp.and (| @@ -1148,15 +1109,18 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_parent_header := - M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), BinOp.sub (| - UnOp.sub (| BinOp.sub (| - M.get_field (| M.get_name (| globals, "block_header" |), "number" |), - M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) |), - Constant.int 1 - |) |), "header" |) in - let _ := M.call (| + let ommer_parent_header := + M.get_field (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + BinOp.sub (| + UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) |), + Constant.int 1 + |) + |), "header" |) in + let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ M.get_name (| globals, "ommer" |); @@ -1164,7 +1128,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1214,33 +1183,54 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let recent_canonical_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| BinOp.add (| - M.get_name (| globals, "MAX_OMMER_DEPTH" |), - Constant.int 1 - |) |), Constant.None_ |) |) in + M.slice (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| BinOp.add (| + M.get_name (| globals, "MAX_OMMER_DEPTH" |), + Constant.int 1 + |) |), + Constant.None_, + Constant.None_ + |) in let recent_canonical_block_hashes := Constant.str "(* At expr: unsupported node type: SetComp *)" in (* At stmt: unsupported node type: AnnAssign *) - For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_canonical_blocks" |) do - let recent_ommers_hashes := + let _ := + M.for_ (| + M.get_name (| globals, "block" |), + M.get_name (| globals, "recent_canonical_blocks" |), + ltac:(M.monadic ( + let recent_ommers_hashes := + M.call (| + M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), + make_list [ + Constant.str "(* At expr: unsupported node type: SetComp *)" + ], + make_dict [] + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "ommer_index" |); M.get_name (| globals, "ommer" |) ], M.call (| - M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), - make_list [ - Constant.str "(* At expr: unsupported node type: SetComp *)" - ], - make_dict [] - |) in - EndFor. - For make_tuple [ M.get_name (| globals, "ommer_index" |); M.get_name (| globals, "ommer" |) ] in M.call (| - M.get_name (| globals, "enumerate" |), - make_list [ - M.get_name (| globals, "ommers" |) - ], - make_dict [] - |) do - let ommer_hash := - M.get_subscript (| M.get_name (| globals, "ommers_hashes" |), M.get_name (| globals, "ommer_index" |) |) in - let _ := M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let ommer_hash := + M.get_subscript (| + M.get_name (| globals, "ommers_hashes" |), + M.get_name (| globals, "ommer_index" |) + |) in + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_eq (| @@ -1251,7 +1241,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_in (| @@ -1262,7 +1252,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_in (| @@ -1273,12 +1263,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_age := - BinOp.sub (| - M.get_field (| M.get_name (| globals, "block_header" |), "number" |), - M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) in - let _ := M.call (| + let ommer_age := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) in + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ BoolOp.and (| @@ -1297,10 +1287,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.in (| + Compare.in_ (| M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), M.get_name (| globals, "recent_canonical_block_hashes" |) |); @@ -1308,7 +1298,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_eq (| @@ -1319,7 +1309,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_)). Definition pay_rewards : Value.t -> Value.t -> M := @@ -1376,30 +1371,34 @@ Definition pay_rewards : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do - let ommer_age := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - BinOp.sub (| - M.get_name (| globals, "block_number" |), - M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) - ], - make_dict [] - |) in - let ommer_miner_reward := - BinOp.floor_div (| - BinOp.mult (| - BinOp.sub (| - Constant.int 8, - M.get_name (| globals, "ommer_age" |) - |), - M.get_name (| globals, "BLOCK_REWARD" |) - |), - Constant.int 8 - |) in - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "ommer" |), + M.get_name (| globals, "ommers" |), + ltac:(M.monadic ( + let ommer_age := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "block_number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) + ], + make_dict [] + |) in + let ommer_miner_reward := + BinOp.floor_div (| + BinOp.mult (| + BinOp.sub (| + Constant.int 8, + M.get_name (| globals, "ommer_age" |) + |), + M.get_name (| globals, "BLOCK_REWARD" |) + |), + Constant.int 8 + |) in + let _ := M.call (| M.get_name (| globals, "create_ether" |), make_list [ M.get_name (| globals, "state" |); @@ -1408,7 +1407,12 @@ Definition pay_rewards : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_)). Definition process_transaction : Value.t -> Value.t -> M := @@ -1688,8 +1692,12 @@ Definition process_transaction : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "accounts_to_delete" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "output" |), "accounts_to_delete" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "destroy_account" |), make_list [ M.get_field (| M.get_name (| globals, "env" |), "state" |); @@ -1697,22 +1705,31 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. - For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "touched_accounts" |) do - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), - (* then *) + M.pure Constant.None_ + )), ltac:(M.monadic ( - let _ := M.call (| + M.pure Constant.None_ + )) + |) in + let _ := + M.for_ (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "output" |), "touched_accounts" |), + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "destroy_account" |), make_list [ M.get_field (| M.get_name (| globals, "env" |), "state" |); @@ -1720,12 +1737,17 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := M.return_ (| make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |); M.get_field (| M.get_name (| globals, "output" |), "error" |) ] |) in @@ -1813,28 +1835,37 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := " in let data_cost := Constant.int 0 in - For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "byte" |), - Constant.int 0 - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "byte" |), + M.get_field (| M.get_name (| globals, "tx" |), "data" |), ltac:(M.monadic ( - let data_cost := BinOp.add - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "byte" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let data_cost := BinOp.add - M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := (* if *) M.if_then_else (| @@ -2049,13 +2080,18 @@ Definition recover_sender : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "Address" |), make_list [ - M.get_subscript (| M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "public_key" |) - ], - make_dict [] - |), M.slice (| Constant.int 12, Constant.int 32 |) |) + M.slice (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), + Constant.int 12, + Constant.int 32, + Constant.None_ + |) ], make_dict [] |) diff --git a/CoqOfPython/ethereum/istanbul/fork_types.v b/CoqOfPython/ethereum/istanbul/fork_types.v index cc8e4a1..e78c8f6 100644 --- a/CoqOfPython/ethereum/istanbul/fork_types.v +++ b/CoqOfPython/ethereum/istanbul/fork_types.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.istanbul.fork_types". Definition expr_1 : Value.t := Constant.str " @@ -17,33 +17,17 @@ Introduction Types re-used throughout the specification, which are specific to Ethereum. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes20 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes20". -Axiom ethereum_base_types_Bytes256 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes20"; "Bytes256"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) diff --git a/CoqOfPython/ethereum/istanbul/state.v b/CoqOfPython/ethereum/istanbul/state.v index a592b4e..928472f 100644 --- a/CoqOfPython/ethereum/istanbul/state.v +++ b/CoqOfPython/ethereum/istanbul/state.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.istanbul.state". Definition expr_1 : Value.t := Constant.str " @@ -22,63 +22,23 @@ There is a distinction between an account that does not exist and `EMPTY_ACCOUNT`. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". -Axiom dataclasses_field : - IsGlobalAlias globals dataclasses.globals "field". - -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_modify : - IsGlobalAlias globals ethereum.base_types.globals "modify". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.istanbul.fork_types. -Axiom ethereum_istanbul_fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals ethereum.istanbul.fork_types.globals "EMPTY_ACCOUNT". -Axiom ethereum_istanbul_fork_types_Account : - IsGlobalAlias globals ethereum.istanbul.fork_types.globals "Account". -Axiom ethereum_istanbul_fork_types_Address : - IsGlobalAlias globals ethereum.istanbul.fork_types.globals "Address". -Axiom ethereum_istanbul_fork_types_Root : - IsGlobalAlias globals ethereum.istanbul.fork_types.globals "Root". - -Require ethereum.istanbul.trie. -Axiom ethereum_istanbul_trie_EMPTY_TRIE_ROOT : - IsGlobalAlias globals ethereum.istanbul.trie.globals "EMPTY_TRIE_ROOT". -Axiom ethereum_istanbul_trie_Trie : - IsGlobalAlias globals ethereum.istanbul.trie.globals "Trie". -Axiom ethereum_istanbul_trie_copy_trie : - IsGlobalAlias globals ethereum.istanbul.trie.globals "copy_trie". -Axiom ethereum_istanbul_trie_root : - IsGlobalAlias globals ethereum.istanbul.trie.globals "root". -Axiom ethereum_istanbul_trie_trie_get : - IsGlobalAlias globals ethereum.istanbul.trie.globals "trie_get". -Axiom ethereum_istanbul_trie_trie_set : - IsGlobalAlias globals ethereum.istanbul.trie.globals "trie_set". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass"; "field" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict"; "List"; "Optional"; "Set"; "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "modify" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_istanbul_fork_types_imports : + AreImported globals "ethereum.istanbul.fork_types" [ "EMPTY_ACCOUNT"; "Account"; "Address"; "Root" ]. + +Axiom ethereum_istanbul_trie_imports : + AreImported globals "ethereum.istanbul.trie" [ "EMPTY_TRIE_ROOT"; "Trie"; "copy_trie"; "root"; "trie_get"; "trie_set" ]. Definition State : Value.t := builtins.make_klass @@ -373,13 +333,16 @@ Definition destroy_storage : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -542,7 +505,10 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), + M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |), M.get_name (| globals, "trie" |) |) in M.pure Constant.None_ @@ -568,7 +534,10 @@ Definition set_storage : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -598,7 +567,7 @@ Definition storage_root : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), @@ -608,7 +577,10 @@ Definition storage_root : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "root" |), make_list [ - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) + M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |) ], make_dict [] |) @@ -1167,7 +1139,7 @@ Definition get_storage_original : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |) |), @@ -1189,7 +1161,10 @@ Definition get_storage_original : Value.t -> Value.t -> M := )) |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "_" |); M.get_name (| globals, "original_trie" |) ], - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), Constant.int 0 |) + M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), + Constant.int 0 + |) |) in let original_account_trie := M.call (| diff --git a/CoqOfPython/ethereum/istanbul/transactions.v b/CoqOfPython/ethereum/istanbul/transactions.v index e6d51bd..0dbad42 100644 --- a/CoqOfPython/ethereum/istanbul/transactions.v +++ b/CoqOfPython/ethereum/istanbul/transactions.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.istanbul.transactions". Definition expr_1 : Value.t := Constant.str " @@ -9,29 +9,17 @@ submitted to be executed. If Ethereum is viewed as a state machine, transactions are the events that move between states. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.istanbul.fork_types. -Axiom ethereum_istanbul_fork_types_Address : - IsGlobalAlias globals ethereum.istanbul.fork_types.globals "Address". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Union" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_istanbul_fork_types_imports : + AreImported globals "ethereum.istanbul.fork_types" [ "Address" ]. Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( Constant.int 21000 diff --git a/CoqOfPython/ethereum/istanbul/trie.v b/CoqOfPython/ethereum/istanbul/trie.v index 83f3e40..579b49d 100644 --- a/CoqOfPython/ethereum/istanbul/trie.v +++ b/CoqOfPython/ethereum/istanbul/trie.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.istanbul.trie". Definition expr_1 : Value.t := Constant.str " @@ -20,83 +20,38 @@ The state trie is the structure responsible for storing (* At top_level_stmt: unsupported node type: Import *) -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". -Axiom dataclasses_field : - IsGlobalAlias globals dataclasses.globals "field". - -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". -Axiom typing_Generic : - IsGlobalAlias globals typing.globals "Generic". -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Mapping : - IsGlobalAlias globals typing.globals "Mapping". -Axiom typing_MutableMapping : - IsGlobalAlias globals typing.globals "MutableMapping". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Sequence : - IsGlobalAlias globals typing.globals "Sequence". -Axiom typing_TypeVar : - IsGlobalAlias globals typing.globals "TypeVar". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". -Axiom typing_cast : - IsGlobalAlias globals typing.globals "cast". - -Require ethereum.constantinople.__init__. -Axiom ethereum_constantinople___init___trie : - IsGlobalAlias globals ethereum.constantinople.__init__.globals "trie". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.utils.hexadecimal. -Axiom ethereum_utils_hexadecimal_hex_to_bytes : - IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.istanbul.blocks. -Axiom ethereum_istanbul_blocks_Receipt : - IsGlobalAlias globals ethereum.istanbul.blocks.globals "Receipt". - -Require ethereum.istanbul.fork_types. -Axiom ethereum_istanbul_fork_types_Account : - IsGlobalAlias globals ethereum.istanbul.fork_types.globals "Account". -Axiom ethereum_istanbul_fork_types_Address : - IsGlobalAlias globals ethereum.istanbul.fork_types.globals "Address". -Axiom ethereum_istanbul_fork_types_Root : - IsGlobalAlias globals ethereum.istanbul.fork_types.globals "Root". -Axiom ethereum_istanbul_fork_types_encode_account : - IsGlobalAlias globals ethereum.istanbul.fork_types.globals "encode_account". - -Require ethereum.istanbul.transactions. -Axiom ethereum_istanbul_transactions_Transaction : - IsGlobalAlias globals ethereum.istanbul.transactions.globals "Transaction". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass"; "field" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict"; "Generic"; "List"; "Mapping"; "MutableMapping"; "Optional"; "Sequence"; "TypeVar"; "Union"; "cast" ]. + +Axiom ethereum_constantinople_imports : + AreImported globals "ethereum.constantinople" [ "trie" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_utils_hexadecimal_imports : + AreImported globals "ethereum.utils.hexadecimal" [ "hex_to_bytes" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_istanbul_blocks_imports : + AreImported globals "ethereum.istanbul.blocks" [ "Receipt" ]. + +Axiom ethereum_istanbul_fork_types_imports : + AreImported globals "ethereum.istanbul.fork_types" [ "Account"; "Address"; "Root"; "encode_account" ]. + +Axiom ethereum_istanbul_transactions_imports : + AreImported globals "ethereum.istanbul.transactions" [ "Transaction" ]. Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -115,7 +70,10 @@ Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( )). Definition Node : Value.t := M.run ltac:(M.monadic ( - M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Bytes" |); M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |); Constant.None_ ] |) + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Bytes" |); M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |); Constant.None_ ] + |) )). Definition K : Value.t := M.run ltac:(M.monadic ( @@ -133,11 +91,23 @@ Definition V : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "TypeVar" |), make_list [ Constant.str "V"; - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Account" |) |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Bytes" |) |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Account" |) + |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Bytes" |) + |); M.get_name (| globals, "Bytes" |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Transaction" |) |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Receipt" |) |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Transaction" |) + |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Receipt" |) + |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |) ], @@ -176,7 +146,10 @@ Definition BranchNode : Value.t := ]. Definition InternalNode : Value.t := M.run ltac:(M.monadic ( - M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LeafNode" |); M.get_name (| globals, "ExtensionNode" |); M.get_name (| globals, "BranchNode" |) ] |) + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "LeafNode" |); M.get_name (| globals, "ExtensionNode" |); M.get_name (| globals, "BranchNode" |) ] + |) )). Definition encode_internal_node : Value.t -> Value.t -> M := @@ -288,7 +261,7 @@ Definition encode_internal_node : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "(* At expr: unsupported node type: JoinedStr *)" @@ -528,13 +501,16 @@ Definition trie_set : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "key" |), M.get_field (| M.get_name (| globals, "trie" |), "_data" |) |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + M.get_name (| globals, "key" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -544,7 +520,10 @@ Definition trie_set : Value.t -> Value.t -> M := (* else *) )), ltac:(M.monadic ( let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), + M.get_subscript (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + M.get_name (| globals, "key" |) + |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_ @@ -589,51 +568,66 @@ Definition common_prefix_length : Value.t -> Value.t -> M := let _ := Constant.str " Find the longest common prefix of two sequences. " in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "a" |) - ], - make_dict [] - |) - ], - make_dict [] - |) do - let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| - M.get_name (| globals, "i" |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "b" |) - ], - make_dict [] - |) - |), - ltac:(M.monadic ( - Compare.not_eq (| - M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), - M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) - |) - )) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + ], + make_dict [] + |), ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "i" |) - |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_subscript (| + M.get_name (| globals, "a" |), + M.get_name (| globals, "i" |) + |), + M.get_subscript (| + M.get_name (| globals, "b" |), + M.get_name (| globals, "i" |) + |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "len" |), @@ -718,38 +712,53 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 0; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |); - Constant.int 2 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ BinOp.add (| BinOp.mult (| Constant.int 16, - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "i" |) + |) |), - M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) + |) |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -767,43 +776,61 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := Constant.int 1 |) |), - M.get_subscript (| M.get_name (| globals, "x" |), Constant.int 0 |) + M.get_subscript (| + M.get_name (| globals, "x" |), + Constant.int 0 + |) |) ], make_dict [] |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 1; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |); - Constant.int 2 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 1; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ BinOp.add (| BinOp.mult (| Constant.int 16, - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "i" |) + |) |), - M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) + |) |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -850,40 +877,55 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := ], make_dict [] |) in - For make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ] in M.call (| - M.get_name (| globals, "enumerate" |), - make_list [ - M.get_name (| globals, "bytes_" |) - ], - make_dict [] - |) do - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.mult (| - M.get_name (| globals, "byte_index" |), - Constant.int 2 - |) |), - BinOp.r_shift (| - BinOp.bit_and (| - M.get_name (| globals, "byte" |), - Constant.int 240 - |), - Constant.int 4 - |) - |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "byte_index" |), - Constant.int 2 - |), - Constant.int 1 - |) |), - BinOp.bit_and (| - M.get_name (| globals, "byte" |), - Constant.int 15 - |) - |) in - EndFor. + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ], + M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "bytes_" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "nibble_list" |), + BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |) + |), + BinOp.r_shift (| + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 240 + |), + Constant.int 4 + |) + |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "nibble_list" |), + BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |), + Constant.int 1 + |) + |), + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 15 + |) + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Bytes" |), @@ -916,65 +958,69 @@ Definition _prepare_trie : Value.t -> Value.t -> M := Object with keys mapped to nibble-byte form. " in (* At stmt: unsupported node type: AnnAssign *) - For make_tuple [ M.get_name (| globals, "preimage" |); M.get_name (| globals, "value" |) ] in M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "items" |), - make_list [], - make_dict [] - |) do - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "value" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "preimage" |); M.get_name (| globals, "value" |) ], + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "items" |), + make_list [], + make_dict [] + |), ltac:(M.monadic ( - let _ := M.assert (| Compare.is_not (| + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in - let address := - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in - let encoded_value := - M.call (| - M.get_name (| globals, "encode_node" |), - make_list [ - M.get_name (| globals, "value" |); + let address := M.call (| - M.get_name (| globals, "get_storage_root" |), + M.get_name (| globals, "Address" |), make_list [ - M.get_name (| globals, "address" |) + M.get_name (| globals, "preimage" |) ], make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let encoded_value := - M.call (| - M.get_name (| globals, "encode_node" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - )) |) in - let _ := M.call (| + |) in + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |); + M.call (| + M.get_name (| globals, "get_storage_root" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_eq (| @@ -986,38 +1032,46 @@ Definition _prepare_trie : Value.t -> Value.t -> M := make_dict [] |) in (* At stmt: unsupported node type: AnnAssign *) - let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "trie" |), "secured" |), - (* then *) - ltac:(M.monadic ( - let key := - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "trie" |), "secured" |), + (* then *) + ltac:(M.monadic ( + let key := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let key := + M.get_name (| globals, "preimage" |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "mapped" |), + M.call (| + M.get_name (| globals, "bytes_to_nibble_list" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |) + |), + M.get_name (| globals, "encoded_value" |) + |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let key := - M.get_name (| globals, "preimage" |) in + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "mapped" |), M.call (| - M.get_name (| globals, "bytes_to_nibble_list" |), - make_list [ - M.get_name (| globals, "key" |) - ], - make_dict [] - |) |), - M.get_name (| globals, "encoded_value" |) - |) in - EndFor. + )) + |) in let _ := M.return_ (| M.get_name (| globals, "mapped" |) |) in @@ -1210,8 +1264,16 @@ Definition patricialize : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "LeafNode" |), make_list [ - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |); - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) + M.slice (| + M.get_name (| globals, "arbitrary_key" |), + M.get_name (| globals, "level" |), + Constant.None_, + Constant.None_ + |); + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "arbitrary_key" |) + |) ], make_dict [] |) in @@ -1224,7 +1286,12 @@ Definition patricialize : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in let substring := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "arbitrary_key" |), + M.get_name (| globals, "level" |), + Constant.None_, + Constant.None_ + |) in let prefix_length := M.call (| M.get_name (| globals, "len" |), @@ -1233,39 +1300,53 @@ Definition patricialize : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do - let prefix_length := - M.call (| - M.get_name (| globals, "min" |), - make_list [ - M.get_name (| globals, "prefix_length" |); + let _ := + M.for_ (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "obj" |), + ltac:(M.monadic ( + let prefix_length := M.call (| - M.get_name (| globals, "common_prefix_length" |), + M.get_name (| globals, "min" |), make_list [ - M.get_name (| globals, "substring" |); - M.get_subscript (| M.get_name (| globals, "key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) + M.get_name (| globals, "prefix_length" |); + M.call (| + M.get_name (| globals, "common_prefix_length" |), + make_list [ + M.get_name (| globals, "substring" |); + M.slice (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "level" |), + Constant.None_, + Constant.None_ + |) + ], + make_dict [] + |) ], make_dict [] - |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "prefix_length" |), - Constant.int 0 - |), - (* then *) - ltac:(M.monadic ( - let _ := M.break (| |) in + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "prefix_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := (* if *) M.if_then_else (| @@ -1276,10 +1357,15 @@ Definition patricialize : Value.t -> Value.t -> M := (* then *) ltac:(M.monadic ( let prefix := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), BinOp.add (| + M.slice (| + M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |), - M.get_name (| globals, "prefix_length" |) - |) |) |) in + BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |), + Constant.None_ + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ExtensionNode" |), @@ -1312,70 +1398,106 @@ Definition patricialize : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) - For M.get_name (| globals, "_" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 16 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "_" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 16 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "branches" |), "append" |), make_list [ {} ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let value := Constant.bytes "" in - For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "key" |) - ], - make_dict [] - |), - M.get_name (| globals, "level" |) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "obj" |), ltac:(M.monadic ( let _ := (* if *) M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); - make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] - ], - make_dict [] + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |), + M.get_name (| globals, "level" |) |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "AssertionError" |)) |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "key" |) + |); + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "AssertionError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "key" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| + M.get_subscript (| + M.get_name (| globals, "branches" |), + M.get_subscript (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "level" |) + |) + |), + M.get_name (| globals, "key" |) + |), + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "key" |) + |) + |) in M.pure Constant.None_ )) |) in - let value := - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.assign (| - M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) - |) in + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "BranchNode" |), diff --git a/CoqOfPython/ethereum/istanbul/utils/__init__.v b/CoqOfPython/ethereum/istanbul/utils/__init__.v index 1baedea..bcee1bf 100644 --- a/CoqOfPython/ethereum/istanbul/utils/__init__.v +++ b/CoqOfPython/ethereum/istanbul/utils/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.istanbul.utils.__init__". Definition expr_1 : Value.t := Constant.str " diff --git a/CoqOfPython/ethereum/istanbul/utils/address.v b/CoqOfPython/ethereum/istanbul/utils/address.v index 2de5bfb..cb5fb4d 100644 --- a/CoqOfPython/ethereum/istanbul/utils/address.v +++ b/CoqOfPython/ethereum/istanbul/utils/address.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.istanbul.utils.address". Definition expr_1 : Value.t := Constant.str " @@ -18,33 +18,23 @@ Address specific functions used in this istanbul version of specification. ". -Require typing. -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". +Axiom typing_imports : + AreImported globals "typing" [ "Union" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes32"; "Uint" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_left_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. -Require ethereum.istanbul.fork_types. -Axiom ethereum_istanbul_fork_types_Address : - IsGlobalAlias globals ethereum.istanbul.fork_types.globals "Address". +Axiom ethereum_istanbul_fork_types_imports : + AreImported globals "ethereum.istanbul.fork_types" [ "Address" ]. Definition to_address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -66,11 +56,16 @@ Definition to_address : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "Address" |), make_list [ - M.get_subscript (| M.call (| - M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), - make_list [], - make_dict [] - |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) + M.slice (| + M.call (| + M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), + UnOp.sub (| Constant.int 20 |), + Constant.None_, + Constant.None_ + |) ], make_dict [] |) @@ -114,7 +109,12 @@ Definition compute_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "computed_address" |), + UnOp.sub (| Constant.int 20 |), + Constant.None_, + Constant.None_ + |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -182,7 +182,12 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "computed_address" |), + UnOp.sub (| Constant.int 20 |), + Constant.None_, + Constant.None_ + |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/istanbul/utils/hexadecimal.v b/CoqOfPython/ethereum/istanbul/utils/hexadecimal.v index 7acfddf..d797c37 100644 --- a/CoqOfPython/ethereum/istanbul/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/istanbul/utils/hexadecimal.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.istanbul.utils.hexadecimal". Definition expr_1 : Value.t := Constant.str " @@ -18,17 +18,11 @@ Hexadecimal utility functions used in this specification, specific to Istanbul types. ". -Require ethereum.utils.hexadecimal. -Axiom ethereum_utils_hexadecimal_remove_hex_prefix : - IsGlobalAlias globals ethereum.utils.hexadecimal.globals "remove_hex_prefix". - -Require ethereum.istanbul.fork_types. -Axiom ethereum_istanbul_fork_types_Address : - IsGlobalAlias globals ethereum.istanbul.fork_types.globals "Address". -Axiom ethereum_istanbul_fork_types_Bloom : - IsGlobalAlias globals ethereum.istanbul.fork_types.globals "Bloom". -Axiom ethereum_istanbul_fork_types_Root : - IsGlobalAlias globals ethereum.istanbul.fork_types.globals "Root". +Axiom ethereum_utils_hexadecimal_imports : + AreImported globals "ethereum.utils.hexadecimal" [ "remove_hex_prefix" ]. + +Axiom ethereum_istanbul_fork_types_imports : + AreImported globals "ethereum.istanbul.fork_types" [ "Address"; "Bloom"; "Root" ]. Definition hex_to_root : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/istanbul/utils/message.v b/CoqOfPython/ethereum/istanbul/utils/message.v index da02502..88cd234 100644 --- a/CoqOfPython/ethereum/istanbul/utils/message.v +++ b/CoqOfPython/ethereum/istanbul/utils/message.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.istanbul.utils.message". Definition expr_1 : Value.t := Constant.str " @@ -18,39 +18,23 @@ Message specific functions used in this istanbul version of specification. ". -Require typing. -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". +Axiom typing_imports : + AreImported globals "typing" [ "Optional"; "Union" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint" ]. -Require ethereum.istanbul.fork_types. -Axiom ethereum_istanbul_fork_types_Address : - IsGlobalAlias globals ethereum.istanbul.fork_types.globals "Address". +Axiom ethereum_istanbul_fork_types_imports : + AreImported globals "ethereum.istanbul.fork_types" [ "Address" ]. -Require ethereum.istanbul.state. -Axiom ethereum_istanbul_state_get_account : - IsGlobalAlias globals ethereum.istanbul.state.globals "get_account". +Axiom ethereum_istanbul_state_imports : + AreImported globals "ethereum.istanbul.state" [ "get_account" ]. -Require ethereum.istanbul.vm.__init__. -Axiom ethereum_istanbul_vm___init___Environment : - IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Environment". -Axiom ethereum_istanbul_vm___init___Message : - IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Message". +Axiom ethereum_istanbul_vm_imports : + AreImported globals "ethereum.istanbul.vm" [ "Environment"; "Message" ]. -Require ethereum.istanbul.utils.address. -Axiom ethereum_istanbul_utils_address_compute_contract_address : - IsGlobalAlias globals ethereum.istanbul.utils.address.globals "compute_contract_address". +Axiom ethereum_istanbul_utils_address_imports : + AreImported globals "ethereum.istanbul.utils.address" [ "compute_contract_address" ]. Definition prepare_message : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -183,7 +167,7 @@ Definition prepare_message : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "Target must be address or empty bytes" diff --git a/CoqOfPython/ethereum/istanbul/vm/__init__.v b/CoqOfPython/ethereum/istanbul/vm/__init__.v index 0614167..365da0c 100644 --- a/CoqOfPython/ethereum/istanbul/vm/__init__.v +++ b/CoqOfPython/ethereum/istanbul/vm/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.istanbul.vm.__init__". Definition expr_1 : Value.t := Constant.str " @@ -18,55 +18,29 @@ The abstract computer which runs the code stored in an `.fork_types.Account`. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". - -Require ethereum.base_types. -Axiom ethereum_base_types_U64 : - IsGlobalAlias globals ethereum.base_types.globals "U64". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". - -Require ethereum.istanbul.blocks. -Axiom ethereum_istanbul_blocks_Log : - IsGlobalAlias globals ethereum.istanbul.blocks.globals "Log". - -Require ethereum.istanbul.fork_types. -Axiom ethereum_istanbul_fork_types_Address : - IsGlobalAlias globals ethereum.istanbul.fork_types.globals "Address". - -Require ethereum.istanbul.state. -Axiom ethereum_istanbul_state_State : - IsGlobalAlias globals ethereum.istanbul.state.globals "State". -Axiom ethereum_istanbul_state_account_exists_and_is_empty : - IsGlobalAlias globals ethereum.istanbul.state.globals "account_exists_and_is_empty". - -Require ethereum.istanbul.vm.precompiled_contracts.__init__. -Axiom ethereum_istanbul_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : - IsGlobalAlias globals ethereum.istanbul.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple"; "Union" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U64"; "U256"; "Bytes"; "Bytes0"; "Uint" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. + +Axiom ethereum_istanbul_blocks_imports : + AreImported globals "ethereum.istanbul.blocks" [ "Log" ]. + +Axiom ethereum_istanbul_fork_types_imports : + AreImported globals "ethereum.istanbul.fork_types" [ "Address" ]. + +Axiom ethereum_istanbul_state_imports : + AreImported globals "ethereum.istanbul.state" [ "State"; "account_exists_and_is_empty" ]. + +Axiom ethereum_istanbul_vm_precompiled_contracts_imports : + AreImported globals "ethereum.istanbul.vm.precompiled_contracts" [ "RIPEMD160_ADDRESS" ]. Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] @@ -187,7 +161,7 @@ Definition incorporate_child_on_error : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "RIPEMD160_ADDRESS" |), M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) |), diff --git a/CoqOfPython/ethereum/istanbul/vm/exceptions.v b/CoqOfPython/ethereum/istanbul/vm/exceptions.v index 8560cef..87a9d29 100644 --- a/CoqOfPython/ethereum/istanbul/vm/exceptions.v +++ b/CoqOfPython/ethereum/istanbul/vm/exceptions.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.istanbul.vm.exceptions". Definition expr_1 : Value.t := Constant.str " @@ -17,9 +17,8 @@ Introduction Exceptions which cause the EVM to halt exceptionally. ". -Require ethereum.exceptions. -Axiom ethereum_exceptions_EthereumException : - IsGlobalAlias globals ethereum.exceptions.globals "EthereumException". +Axiom ethereum_exceptions_imports : + AreImported globals "ethereum.exceptions" [ "EthereumException" ]. Definition ExceptionalHalt : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/istanbul/vm/gas.v b/CoqOfPython/ethereum/istanbul/vm/gas.v index 216b412..921b718 100644 --- a/CoqOfPython/ethereum/istanbul/vm/gas.v +++ b/CoqOfPython/ethereum/istanbul/vm/gas.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.istanbul.vm.gas". Definition expr_1 : Value.t := Constant.str " @@ -17,39 +17,26 @@ Introduction EVM gas constants and calculators. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Tuple" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. -Require ethereum.trace. -Axiom ethereum_trace_GasAndRefund : - IsGlobalAlias globals ethereum.trace.globals "GasAndRefund". -Axiom ethereum_trace_evm_trace : - IsGlobalAlias globals ethereum.trace.globals "evm_trace". +Axiom ethereum_trace_imports : + AreImported globals "ethereum.trace" [ "GasAndRefund"; "evm_trace" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.istanbul.vm.__init__. -Axiom ethereum_istanbul_vm___init___Evm : - IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Evm". +Axiom ethereum_istanbul_vm_imports : + AreImported globals "ethereum.istanbul.vm" [ "Evm" ]. -Require ethereum.istanbul.vm.exceptions. -Axiom ethereum_istanbul_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.istanbul.vm.exceptions.globals "OutOfGasError". +Axiom ethereum_istanbul_vm_exceptions_imports : + AreImported globals "ethereum.istanbul.vm.exceptions" [ "OutOfGasError" ]. Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -538,7 +525,7 @@ Definition charge_gas : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -655,105 +642,114 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := ], make_dict [] |) in - For make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ] in M.get_name (| globals, "extensions" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "size" |), - Constant.int 0 - |), - (* then *) + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ], + M.get_name (| globals, "extensions" |), ltac:(M.monadic ( - let _ := M.continue (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let before_size := - M.call (| - M.get_name (| globals, "ceil32" |), - make_list [ - M.get_name (| globals, "current_size" |) - ], - make_dict [] - |) in - let after_size := - M.call (| - M.get_name (| globals, "ceil32" |), - make_list [ - BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "size" |), + Constant.int 0 |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.lt_e (| - M.get_name (| globals, "after_size" |), - M.get_name (| globals, "before_size" |) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.continue (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let size_to_extend := BinOp.add - BinOp.sub (| + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let before_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "current_size" |) + ], + make_dict [] + |) in + let after_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let size_to_extend := BinOp.add + BinOp.sub (| M.get_name (| globals, "after_size" |), M.get_name (| globals, "before_size" |) |) - BinOp.sub (| + BinOp.sub (| M.get_name (| globals, "after_size" |), M.get_name (| globals, "before_size" |) |) in - let already_paid := - M.call (| - M.get_name (| globals, "calculate_memory_gas_cost" |), - make_list [ - M.get_name (| globals, "before_size" |) - ], - make_dict [] - |) in - let total_cost := - M.call (| - M.get_name (| globals, "calculate_memory_gas_cost" |), - make_list [ - M.get_name (| globals, "after_size" |) - ], - make_dict [] - |) in - let to_be_paid := BinOp.add - BinOp.sub (| + let already_paid := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "before_size" |) + ], + make_dict [] + |) in + let total_cost := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "after_size" |) + ], + make_dict [] + |) in + let to_be_paid := BinOp.add + BinOp.sub (| M.get_name (| globals, "total_cost" |), M.get_name (| globals, "already_paid" |) |) - BinOp.sub (| + BinOp.sub (| M.get_name (| globals, "total_cost" |), M.get_name (| globals, "already_paid" |) |) in - let current_size := - M.get_name (| globals, "after_size" |) in - EndFor. + let current_size := + M.get_name (| globals, "after_size" |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ExtendMemory" |), diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/__init__.v b/CoqOfPython/ethereum/istanbul/vm/instructions/__init__.v index 4aa92f7..60ca1c4 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/__init__.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.istanbul.vm.instructions.__init__". Definition expr_1 : Value.t := Constant.str " @@ -20,59 +20,44 @@ implementations. (* At top_level_stmt: unsupported node type: Import *) -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict" ]. -Require ethereum.istanbul.vm.instructions.__init__. -Axiom ethereum_istanbul_vm_instructions___init___arithmetic : - IsGlobalAlias globals ethereum.istanbul.vm.instructions.__init__.globals "arithmetic". +Axiom ethereum_istanbul_vm_instructions_imports : + AreImported globals "ethereum.istanbul.vm.instructions" [ "arithmetic" ]. -Require ethereum.istanbul.vm.instructions.__init__. -Axiom ethereum_istanbul_vm_instructions___init___bitwise : - IsGlobalAlias globals ethereum.istanbul.vm.instructions.__init__.globals "bitwise". +Axiom ethereum_istanbul_vm_instructions_imports : + AreImported globals "ethereum.istanbul.vm.instructions" [ "bitwise" ]. -Require ethereum.istanbul.vm.instructions.__init__. -Axiom ethereum_istanbul_vm_instructions___init___block : - IsGlobalAlias globals ethereum.istanbul.vm.instructions.__init__.globals "block". +Axiom ethereum_istanbul_vm_instructions_imports : + AreImported globals "ethereum.istanbul.vm.instructions" [ "block" ]. -Require ethereum.istanbul.vm.instructions.__init__. -Axiom ethereum_istanbul_vm_instructions___init___comparison : - IsGlobalAlias globals ethereum.istanbul.vm.instructions.__init__.globals "comparison". +Axiom ethereum_istanbul_vm_instructions_imports : + AreImported globals "ethereum.istanbul.vm.instructions" [ "comparison" ]. -Require ethereum.istanbul.vm.instructions.__init__. -Axiom ethereum_istanbul_vm_instructions___init___control_flow : - IsGlobalAlias globals ethereum.istanbul.vm.instructions.__init__.globals "control_flow". +Axiom ethereum_istanbul_vm_instructions_imports : + AreImported globals "ethereum.istanbul.vm.instructions" [ "control_flow" ]. -Require ethereum.istanbul.vm.instructions.__init__. -Axiom ethereum_istanbul_vm_instructions___init___environment : - IsGlobalAlias globals ethereum.istanbul.vm.instructions.__init__.globals "environment". +Axiom ethereum_istanbul_vm_instructions_imports : + AreImported globals "ethereum.istanbul.vm.instructions" [ "environment" ]. -Require ethereum.istanbul.vm.instructions.__init__. -Axiom ethereum_istanbul_vm_instructions___init___keccak : - IsGlobalAlias globals ethereum.istanbul.vm.instructions.__init__.globals "keccak". +Axiom ethereum_istanbul_vm_instructions_imports : + AreImported globals "ethereum.istanbul.vm.instructions" [ "keccak" ]. -Require ethereum.istanbul.vm.instructions.__init__. -Axiom ethereum_istanbul_vm_instructions___init___log : - IsGlobalAlias globals ethereum.istanbul.vm.instructions.__init__.globals "log". +Axiom ethereum_istanbul_vm_instructions_imports : + AreImported globals "ethereum.istanbul.vm.instructions" [ "log" ]. -Require ethereum.istanbul.vm.instructions.__init__. -Axiom ethereum_istanbul_vm_instructions___init___memory : - IsGlobalAlias globals ethereum.istanbul.vm.instructions.__init__.globals "memory". +Axiom ethereum_istanbul_vm_instructions_imports : + AreImported globals "ethereum.istanbul.vm.instructions" [ "memory" ]. -Require ethereum.istanbul.vm.instructions.__init__. -Axiom ethereum_istanbul_vm_instructions___init___stack : - IsGlobalAlias globals ethereum.istanbul.vm.instructions.__init__.globals "stack". +Axiom ethereum_istanbul_vm_instructions_imports : + AreImported globals "ethereum.istanbul.vm.instructions" [ "stack" ]. -Require ethereum.istanbul.vm.instructions.__init__. -Axiom ethereum_istanbul_vm_instructions___init___storage : - IsGlobalAlias globals ethereum.istanbul.vm.instructions.__init__.globals "storage". +Axiom ethereum_istanbul_vm_instructions_imports : + AreImported globals "ethereum.istanbul.vm.instructions" [ "storage" ]. -Require ethereum.istanbul.vm.instructions.__init__. -Axiom ethereum_istanbul_vm_instructions___init___system : - IsGlobalAlias globals ethereum.istanbul.vm.instructions.__init__.globals "system". +Axiom ethereum_istanbul_vm_instructions_imports : + AreImported globals "ethereum.istanbul.vm.instructions" [ "system" ]. Definition Ops : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/istanbul/vm/instructions/arithmetic.v index a7893ea..5ffc75b 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/arithmetic.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.istanbul.vm.instructions.arithmetic". Definition expr_1 : Value.t := Constant.str " @@ -17,43 +17,20 @@ Introduction Implementations of the EVM Arithmetic instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U255_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U255_CEIL_VALUE". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_U256_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U255_CEIL_VALUE"; "U256"; "U256_CEIL_VALUE"; "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_get_sign : - IsGlobalAlias globals ethereum.utils.numeric.globals "get_sign". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "get_sign" ]. -Require ethereum.istanbul.vm.__init__. -Axiom ethereum_istanbul_vm___init___Evm : - IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Evm". +Axiom ethereum_istanbul_vm_imports : + AreImported globals "ethereum.istanbul.vm" [ "Evm" ]. -Require ethereum.istanbul.vm.gas. -Axiom ethereum_istanbul_vm_gas_GAS_EXPONENTIATION : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_EXPONENTIATION". -Axiom ethereum_istanbul_vm_gas_GAS_EXPONENTIATION_PER_BYTE : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_EXPONENTIATION_PER_BYTE". -Axiom ethereum_istanbul_vm_gas_GAS_LOW : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_LOW". -Axiom ethereum_istanbul_vm_gas_GAS_MID : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_MID". -Axiom ethereum_istanbul_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_istanbul_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "charge_gas". +Axiom ethereum_istanbul_vm_gas_imports : + AreImported globals "ethereum.istanbul.vm.gas" [ "GAS_EXPONENTIATION"; "GAS_EXPONENTIATION_PER_BYTE"; "GAS_LOW"; "GAS_MID"; "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.istanbul.vm.stack. -Axiom ethereum_istanbul_vm_stack_pop : - IsGlobalAlias globals ethereum.istanbul.vm.stack.globals "pop". -Axiom ethereum_istanbul_vm_stack_push : - IsGlobalAlias globals ethereum.istanbul.vm.stack.globals "push". +Axiom ethereum_istanbul_vm_stack_imports : + AreImported globals "ethereum.istanbul.vm.stack" [ "pop"; "push" ]. Definition add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -1030,19 +1007,27 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let value_bytes := - M.get_subscript (| M.get_name (| globals, "value_bytes" |), M.slice (| BinOp.sub (| - Constant.int 31, - M.call (| - M.get_name (| globals, "int" |), - make_list [ - M.get_name (| globals, "byte_num" |) - ], - make_dict [] - |) - |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "value_bytes" |), + BinOp.sub (| + Constant.int 31, + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "byte_num" |) + ], + make_dict [] + |) + |), + Constant.None_, + Constant.None_ + |) in let sign_bit := BinOp.r_shift (| - M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), + M.get_subscript (| + M.get_name (| globals, "value_bytes" |), + Constant.int 0 + |), Constant.int 7 |) in let _ := diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/bitwise.v b/CoqOfPython/ethereum/istanbul/vm/instructions/bitwise.v index 4a55db3..f83e61e 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/bitwise.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.istanbul.vm.instructions.bitwise". Definition expr_1 : Value.t := Constant.str " @@ -17,27 +17,17 @@ Introduction Implementations of the EVM bitwise instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_U256_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "U256_CEIL_VALUE" ]. -Require ethereum.istanbul.vm.__init__. -Axiom ethereum_istanbul_vm___init___Evm : - IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Evm". +Axiom ethereum_istanbul_vm_imports : + AreImported globals "ethereum.istanbul.vm" [ "Evm" ]. -Require ethereum.istanbul.vm.gas. -Axiom ethereum_istanbul_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_istanbul_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "charge_gas". +Axiom ethereum_istanbul_vm_gas_imports : + AreImported globals "ethereum.istanbul.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.istanbul.vm.stack. -Axiom ethereum_istanbul_vm_stack_pop : - IsGlobalAlias globals ethereum.istanbul.vm.stack.globals "pop". -Axiom ethereum_istanbul_vm_stack_push : - IsGlobalAlias globals ethereum.istanbul.vm.stack.globals "push". +Axiom ethereum_istanbul_vm_stack_imports : + AreImported globals "ethereum.istanbul.vm.stack" [ "pop"; "push" ]. Definition bitwise_and : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/block.v b/CoqOfPython/ethereum/istanbul/vm/instructions/block.v index 8411c2b..1e79e21 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/block.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/block.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.istanbul.vm.instructions.block". Definition expr_1 : Value.t := Constant.str " @@ -17,27 +17,17 @@ Introduction Implementations of the EVM block instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.istanbul.vm.__init__. -Axiom ethereum_istanbul_vm___init___Evm : - IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Evm". +Axiom ethereum_istanbul_vm_imports : + AreImported globals "ethereum.istanbul.vm" [ "Evm" ]. -Require ethereum.istanbul.vm.gas. -Axiom ethereum_istanbul_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_BASE". -Axiom ethereum_istanbul_vm_gas_GAS_BLOCK_HASH : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_BLOCK_HASH". -Axiom ethereum_istanbul_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "charge_gas". +Axiom ethereum_istanbul_vm_gas_imports : + AreImported globals "ethereum.istanbul.vm.gas" [ "GAS_BASE"; "GAS_BLOCK_HASH"; "charge_gas" ]. -Require ethereum.istanbul.vm.stack. -Axiom ethereum_istanbul_vm_stack_pop : - IsGlobalAlias globals ethereum.istanbul.vm.stack.globals "pop". -Axiom ethereum_istanbul_vm_stack_push : - IsGlobalAlias globals ethereum.istanbul.vm.stack.globals "push". +Axiom ethereum_istanbul_vm_stack_imports : + AreImported globals "ethereum.istanbul.vm.stack" [ "pop"; "push" ]. Definition block_hash : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -94,10 +84,13 @@ Definition block_hash : Value.t -> Value.t -> M := (* else *) )), ltac:(M.monadic ( let hash := - M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), - M.get_name (| globals, "block_number" |) - |) |) |) in + M.get_subscript (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), + UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + M.get_name (| globals, "block_number" |) + |) |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/comparison.v b/CoqOfPython/ethereum/istanbul/vm/instructions/comparison.v index fcf5c15..2f35a57 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/comparison.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.istanbul.vm.instructions.comparison". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementations of the EVM Comparison instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.istanbul.vm.__init__. -Axiom ethereum_istanbul_vm___init___Evm : - IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Evm". +Axiom ethereum_istanbul_vm_imports : + AreImported globals "ethereum.istanbul.vm" [ "Evm" ]. -Require ethereum.istanbul.vm.gas. -Axiom ethereum_istanbul_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_istanbul_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "charge_gas". +Axiom ethereum_istanbul_vm_gas_imports : + AreImported globals "ethereum.istanbul.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.istanbul.vm.stack. -Axiom ethereum_istanbul_vm_stack_pop : - IsGlobalAlias globals ethereum.istanbul.vm.stack.globals "pop". -Axiom ethereum_istanbul_vm_stack_push : - IsGlobalAlias globals ethereum.istanbul.vm.stack.globals "push". +Axiom ethereum_istanbul_vm_stack_imports : + AreImported globals "ethereum.istanbul.vm.stack" [ "pop"; "push" ]. Definition less_than : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/control_flow.v b/CoqOfPython/ethereum/istanbul/vm/instructions/control_flow.v index 5b19ce0..b53d5d1 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/control_flow.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.istanbul.vm.instructions.control_flow". Definition expr_1 : Value.t := Constant.str " @@ -17,37 +17,20 @@ Introduction Implementations of the EVM control flow instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. -Require ethereum.istanbul.vm.gas. -Axiom ethereum_istanbul_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_BASE". -Axiom ethereum_istanbul_vm_gas_GAS_HIGH : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_HIGH". -Axiom ethereum_istanbul_vm_gas_GAS_JUMPDEST : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_JUMPDEST". -Axiom ethereum_istanbul_vm_gas_GAS_MID : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_MID". -Axiom ethereum_istanbul_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "charge_gas". +Axiom ethereum_istanbul_vm_gas_imports : + AreImported globals "ethereum.istanbul.vm.gas" [ "GAS_BASE"; "GAS_HIGH"; "GAS_JUMPDEST"; "GAS_MID"; "charge_gas" ]. -Require ethereum.istanbul.vm.__init__. -Axiom ethereum_istanbul_vm___init___Evm : - IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Evm". +Axiom ethereum_istanbul_vm_imports : + AreImported globals "ethereum.istanbul.vm" [ "Evm" ]. -Require ethereum.istanbul.vm.exceptions. -Axiom ethereum_istanbul_vm_exceptions_InvalidJumpDestError : - IsGlobalAlias globals ethereum.istanbul.vm.exceptions.globals "InvalidJumpDestError". +Axiom ethereum_istanbul_vm_exceptions_imports : + AreImported globals "ethereum.istanbul.vm.exceptions" [ "InvalidJumpDestError" ]. -Require ethereum.istanbul.vm.stack. -Axiom ethereum_istanbul_vm_stack_pop : - IsGlobalAlias globals ethereum.istanbul.vm.stack.globals "pop". -Axiom ethereum_istanbul_vm_stack_push : - IsGlobalAlias globals ethereum.istanbul.vm.stack.globals "push". +Axiom ethereum_istanbul_vm_stack_imports : + AreImported globals "ethereum.istanbul.vm.stack" [ "pop"; "push" ]. Definition stop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -117,7 +100,7 @@ Definition jump : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "InvalidJumpDestError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -205,7 +188,7 @@ Definition jumpi : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "InvalidJumpDestError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/environment.v b/CoqOfPython/ethereum/istanbul/vm/instructions/environment.v index 2ae1498..7311123 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/environment.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.istanbul.vm.instructions.environment". Definition expr_1 : Value.t := Constant.str " @@ -17,77 +17,41 @@ Introduction Implementations of the EVM environment related instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". - -Require ethereum.istanbul.fork_types. -Axiom ethereum_istanbul_fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals ethereum.istanbul.fork_types.globals "EMPTY_ACCOUNT". - -Require ethereum.istanbul.state. -Axiom ethereum_istanbul_state_get_account : - IsGlobalAlias globals ethereum.istanbul.state.globals "get_account". - -Require ethereum.istanbul.utils.address. -Axiom ethereum_istanbul_utils_address_to_address : - IsGlobalAlias globals ethereum.istanbul.utils.address.globals "to_address". - -Require ethereum.istanbul.vm.memory. -Axiom ethereum_istanbul_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.istanbul.vm.memory.globals "buffer_read". -Axiom ethereum_istanbul_vm_memory_memory_write : - IsGlobalAlias globals ethereum.istanbul.vm.memory.globals "memory_write". - -Require ethereum.istanbul.vm.__init__. -Axiom ethereum_istanbul_vm___init___Evm : - IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Evm". - -Require ethereum.istanbul.vm.exceptions. -Axiom ethereum_istanbul_vm_exceptions_OutOfBoundsRead : - IsGlobalAlias globals ethereum.istanbul.vm.exceptions.globals "OutOfBoundsRead". - -Require ethereum.istanbul.vm.gas. -Axiom ethereum_istanbul_vm_gas_GAS_BALANCE : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_BALANCE". -Axiom ethereum_istanbul_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_BASE". -Axiom ethereum_istanbul_vm_gas_GAS_CODE_HASH : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_CODE_HASH". -Axiom ethereum_istanbul_vm_gas_GAS_COPY : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_COPY". -Axiom ethereum_istanbul_vm_gas_GAS_EXTERNAL : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_EXTERNAL". -Axiom ethereum_istanbul_vm_gas_GAS_FAST_STEP : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_FAST_STEP". -Axiom ethereum_istanbul_vm_gas_GAS_RETURN_DATA_COPY : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_RETURN_DATA_COPY". -Axiom ethereum_istanbul_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_istanbul_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_istanbul_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "charge_gas". - -Require ethereum.istanbul.vm.stack. -Axiom ethereum_istanbul_vm_stack_pop : - IsGlobalAlias globals ethereum.istanbul.vm.stack.globals "pop". -Axiom ethereum_istanbul_vm_stack_push : - IsGlobalAlias globals ethereum.istanbul.vm.stack.globals "push". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. + +Axiom ethereum_istanbul_fork_types_imports : + AreImported globals "ethereum.istanbul.fork_types" [ "EMPTY_ACCOUNT" ]. + +Axiom ethereum_istanbul_state_imports : + AreImported globals "ethereum.istanbul.state" [ "get_account" ]. + +Axiom ethereum_istanbul_utils_address_imports : + AreImported globals "ethereum.istanbul.utils.address" [ "to_address" ]. + +Axiom ethereum_istanbul_vm_memory_imports : + AreImported globals "ethereum.istanbul.vm.memory" [ "buffer_read"; "memory_write" ]. + +Axiom ethereum_istanbul_vm_imports : + AreImported globals "ethereum.istanbul.vm" [ "Evm" ]. + +Axiom ethereum_istanbul_vm_exceptions_imports : + AreImported globals "ethereum.istanbul.vm.exceptions" [ "OutOfBoundsRead" ]. + +Axiom ethereum_istanbul_vm_gas_imports : + AreImported globals "ethereum.istanbul.vm.gas" [ "GAS_BALANCE"; "GAS_BASE"; "GAS_CODE_HASH"; "GAS_COPY"; "GAS_EXTERNAL"; "GAS_FAST_STEP"; "GAS_RETURN_DATA_COPY"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. + +Axiom ethereum_istanbul_vm_stack_imports : + AreImported globals "ethereum.istanbul.vm.stack" [ "pop"; "push" ]. Definition address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -1134,10 +1098,15 @@ Definition returndatacopy : Value.t -> Value.t -> M := |) |) in let value := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.slice (| M.get_name (| globals, "return_data_start_position" |), BinOp.add (| + M.slice (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |), - M.get_name (| globals, "size" |) - |) |) |) in + BinOp.add (| + M.get_name (| globals, "return_data_start_position" |), + M.get_name (| globals, "size" |) + |), + Constant.None_ + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/keccak.v b/CoqOfPython/ethereum/istanbul/vm/instructions/keccak.v index 4b2ee32..b21b84d 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/keccak.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.istanbul.vm.instructions.keccak". Definition expr_1 : Value.t := Constant.str " @@ -17,43 +17,26 @@ Introduction Implementations of the EVM keccak instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". - -Require ethereum.istanbul.vm.__init__. -Axiom ethereum_istanbul_vm___init___Evm : - IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Evm". - -Require ethereum.istanbul.vm.gas. -Axiom ethereum_istanbul_vm_gas_GAS_KECCAK256 : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_KECCAK256". -Axiom ethereum_istanbul_vm_gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_KECCAK256_WORD". -Axiom ethereum_istanbul_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_istanbul_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "charge_gas". - -Require ethereum.istanbul.vm.memory. -Axiom ethereum_istanbul_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.istanbul.vm.memory.globals "memory_read_bytes". - -Require ethereum.istanbul.vm.stack. -Axiom ethereum_istanbul_vm_stack_pop : - IsGlobalAlias globals ethereum.istanbul.vm.stack.globals "pop". -Axiom ethereum_istanbul_vm_stack_push : - IsGlobalAlias globals ethereum.istanbul.vm.stack.globals "push". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. + +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. + +Axiom ethereum_istanbul_vm_imports : + AreImported globals "ethereum.istanbul.vm" [ "Evm" ]. + +Axiom ethereum_istanbul_vm_gas_imports : + AreImported globals "ethereum.istanbul.vm.gas" [ "GAS_KECCAK256"; "GAS_KECCAK256_WORD"; "calculate_gas_extend_memory"; "charge_gas" ]. + +Axiom ethereum_istanbul_vm_memory_imports : + AreImported globals "ethereum.istanbul.vm.memory" [ "memory_read_bytes" ]. + +Axiom ethereum_istanbul_vm_stack_imports : + AreImported globals "ethereum.istanbul.vm.stack" [ "pop"; "push" ]. Definition keccak : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/log.v b/CoqOfPython/ethereum/istanbul/vm/instructions/log.v index 902c053..14591b8 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/log.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/log.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.istanbul.vm.instructions.log". Definition expr_1 : Value.t := Constant.str " @@ -17,49 +17,32 @@ Introduction Implementations of the EVM logging instructions. ". -Require functools. -Axiom functools_partial : - IsGlobalAlias globals functools.globals "partial". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.istanbul.blocks. -Axiom ethereum_istanbul_blocks_Log : - IsGlobalAlias globals ethereum.istanbul.blocks.globals "Log". - -Require ethereum.istanbul.vm.__init__. -Axiom ethereum_istanbul_vm___init___Evm : - IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Evm". - -Require ethereum.istanbul.vm.exceptions. -Axiom ethereum_istanbul_vm_exceptions_WriteInStaticContext : - IsGlobalAlias globals ethereum.istanbul.vm.exceptions.globals "WriteInStaticContext". - -Require ethereum.istanbul.vm.gas. -Axiom ethereum_istanbul_vm_gas_GAS_LOG : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_LOG". -Axiom ethereum_istanbul_vm_gas_GAS_LOG_DATA : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_LOG_DATA". -Axiom ethereum_istanbul_vm_gas_GAS_LOG_TOPIC : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_LOG_TOPIC". -Axiom ethereum_istanbul_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_istanbul_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "charge_gas". - -Require ethereum.istanbul.vm.memory. -Axiom ethereum_istanbul_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.istanbul.vm.memory.globals "memory_read_bytes". - -Require ethereum.istanbul.vm.stack. -Axiom ethereum_istanbul_vm_stack_pop : - IsGlobalAlias globals ethereum.istanbul.vm.stack.globals "pop". +Axiom functools_imports : + AreImported globals "functools" [ "partial" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_istanbul_blocks_imports : + AreImported globals "ethereum.istanbul.blocks" [ "Log" ]. + +Axiom ethereum_istanbul_vm_imports : + AreImported globals "ethereum.istanbul.vm" [ "Evm" ]. + +Axiom ethereum_istanbul_vm_exceptions_imports : + AreImported globals "ethereum.istanbul.vm.exceptions" [ "WriteInStaticContext" ]. + +Axiom ethereum_istanbul_vm_gas_imports : + AreImported globals "ethereum.istanbul.vm.gas" [ "GAS_LOG"; "GAS_LOG_DATA"; "GAS_LOG_TOPIC"; "calculate_gas_extend_memory"; "charge_gas" ]. + +Axiom ethereum_istanbul_vm_memory_imports : + AreImported globals "ethereum.istanbul.vm.memory" [ "memory_read_bytes" ]. + +Axiom ethereum_istanbul_vm_stack_imports : + AreImported globals "ethereum.istanbul.vm.stack" [ "pop" ]. Definition log_n : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -96,33 +79,42 @@ Definition log_n : Value.t -> Value.t -> M := |) in let topics := make_list [] in - For M.get_name (| globals, "_" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - M.get_name (| globals, "num_topics" |) - ], - make_dict [] - |) do - let topic := + let _ := + M.for_ (| + M.get_name (| globals, "_" |), M.call (| - M.get_field (| M.call (| - M.get_name (| globals, "pop" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] - |), "to_be_bytes32" |), - make_list [], - make_dict [] - |) in - let _ := M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "num_topics" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let topic := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| M.get_field (| M.get_name (| globals, "topics" |), "append" |), make_list [ M.get_name (| globals, "topic" |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let extend_memory := M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/memory.v b/CoqOfPython/ethereum/istanbul/vm/instructions/memory.v index dcb6ab0..e214883 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/memory.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.istanbul.vm.instructions.memory". Definition expr_1 : Value.t := Constant.str " @@ -17,37 +17,20 @@ Introduction Implementations of the EVM Memory instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes" ]. -Require ethereum.istanbul.vm.__init__. -Axiom ethereum_istanbul_vm___init___Evm : - IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Evm". +Axiom ethereum_istanbul_vm_imports : + AreImported globals "ethereum.istanbul.vm" [ "Evm" ]. -Require ethereum.istanbul.vm.gas. -Axiom ethereum_istanbul_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_BASE". -Axiom ethereum_istanbul_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_istanbul_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_istanbul_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "charge_gas". +Axiom ethereum_istanbul_vm_gas_imports : + AreImported globals "ethereum.istanbul.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. -Require ethereum.istanbul.vm.memory. -Axiom ethereum_istanbul_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.istanbul.vm.memory.globals "memory_read_bytes". -Axiom ethereum_istanbul_vm_memory_memory_write : - IsGlobalAlias globals ethereum.istanbul.vm.memory.globals "memory_write". +Axiom ethereum_istanbul_vm_memory_imports : + AreImported globals "ethereum.istanbul.vm.memory" [ "memory_read_bytes"; "memory_write" ]. -Require ethereum.istanbul.vm.stack. -Axiom ethereum_istanbul_vm_stack_pop : - IsGlobalAlias globals ethereum.istanbul.vm.stack.globals "pop". -Axiom ethereum_istanbul_vm_stack_push : - IsGlobalAlias globals ethereum.istanbul.vm.stack.globals "push". +Axiom ethereum_istanbul_vm_stack_imports : + AreImported globals "ethereum.istanbul.vm.stack" [ "pop"; "push" ]. Definition mstore : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/stack.v b/CoqOfPython/ethereum/istanbul/vm/instructions/stack.v index 14f5374..90b7219 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/stack.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.istanbul.vm.instructions.stack". Definition expr_1 : Value.t := Constant.str " @@ -17,39 +17,26 @@ Introduction Implementations of the EVM stack related instructions. ". -Require functools. -Axiom functools_partial : - IsGlobalAlias globals functools.globals "partial". +Axiom functools_imports : + AreImported globals "functools" [ "partial" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.istanbul.vm.__init__. -Axiom ethereum_istanbul_vm___init___Evm : - IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Evm". -Axiom ethereum_istanbul_vm___init___stack : - IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "stack". +Axiom ethereum_istanbul_vm_imports : + AreImported globals "ethereum.istanbul.vm" [ "Evm"; "stack" ]. -Require ethereum.istanbul.vm.exceptions. -Axiom ethereum_istanbul_vm_exceptions_StackUnderflowError : - IsGlobalAlias globals ethereum.istanbul.vm.exceptions.globals "StackUnderflowError". +Axiom ethereum_istanbul_vm_exceptions_imports : + AreImported globals "ethereum.istanbul.vm.exceptions" [ "StackUnderflowError" ]. -Require ethereum.istanbul.vm.gas. -Axiom ethereum_istanbul_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_BASE". -Axiom ethereum_istanbul_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_istanbul_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "charge_gas". +Axiom ethereum_istanbul_vm_gas_imports : + AreImported globals "ethereum.istanbul.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.istanbul.vm.memory. -Axiom ethereum_istanbul_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.istanbul.vm.memory.globals "buffer_read". +Axiom ethereum_istanbul_vm_memory_imports : + AreImported globals "ethereum.istanbul.vm.memory" [ "buffer_read" ]. Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -203,19 +190,22 @@ Definition dup_n : Value.t -> Value.t -> M := make_dict [] |) in let data_to_duplicate := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] + BinOp.sub (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), + Constant.int 1 |), - Constant.int 1 - |), - M.get_name (| globals, "item_number" |) - |) |) in + M.get_name (| globals, "item_number" |) + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "stack" |), "push" |), make_list [ @@ -278,14 +268,26 @@ Definition swap_n : Value.t -> Value.t -> M := make_dict [] |) in let _ := M.assign (| - make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| - UnOp.sub (| Constant.int 1 |), - M.get_name (| globals, "item_number" |) - |) |) ], - make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| - UnOp.sub (| Constant.int 1 |), - M.get_name (| globals, "item_number" |) - |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |) ] + make_tuple [ M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + UnOp.sub (| Constant.int 1 |) + |); M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) + |) ], + make_tuple [ M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) + |); M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + UnOp.sub (| Constant.int 1 |) + |) ] |) in let _ := M.assign_op (| BinOp.add, diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/storage.v b/CoqOfPython/ethereum/istanbul/vm/instructions/storage.v index a5cb2f2..11a5c83 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/storage.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.istanbul.vm.instructions.storage". Definition expr_1 : Value.t := Constant.str " @@ -17,47 +17,23 @@ Introduction Implementations of the EVM storage related instructions. ". -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.istanbul.state. -Axiom ethereum_istanbul_state_get_storage : - IsGlobalAlias globals ethereum.istanbul.state.globals "get_storage". -Axiom ethereum_istanbul_state_get_storage_original : - IsGlobalAlias globals ethereum.istanbul.state.globals "get_storage_original". -Axiom ethereum_istanbul_state_set_storage : - IsGlobalAlias globals ethereum.istanbul.state.globals "set_storage". +Axiom ethereum_istanbul_state_imports : + AreImported globals "ethereum.istanbul.state" [ "get_storage"; "get_storage_original"; "set_storage" ]. -Require ethereum.istanbul.vm.__init__. -Axiom ethereum_istanbul_vm___init___Evm : - IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Evm". +Axiom ethereum_istanbul_vm_imports : + AreImported globals "ethereum.istanbul.vm" [ "Evm" ]. -Require ethereum.istanbul.vm.exceptions. -Axiom ethereum_istanbul_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.istanbul.vm.exceptions.globals "OutOfGasError". -Axiom ethereum_istanbul_vm_exceptions_WriteInStaticContext : - IsGlobalAlias globals ethereum.istanbul.vm.exceptions.globals "WriteInStaticContext". +Axiom ethereum_istanbul_vm_exceptions_imports : + AreImported globals "ethereum.istanbul.vm.exceptions" [ "OutOfGasError"; "WriteInStaticContext" ]. -Require ethereum.istanbul.vm.gas. -Axiom ethereum_istanbul_vm_gas_GAS_CALL_STIPEND : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_CALL_STIPEND". -Axiom ethereum_istanbul_vm_gas_GAS_SLOAD : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_SLOAD". -Axiom ethereum_istanbul_vm_gas_GAS_STORAGE_CLEAR_REFUND : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_STORAGE_CLEAR_REFUND". -Axiom ethereum_istanbul_vm_gas_GAS_STORAGE_SET : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_STORAGE_SET". -Axiom ethereum_istanbul_vm_gas_GAS_STORAGE_UPDATE : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_STORAGE_UPDATE". -Axiom ethereum_istanbul_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "charge_gas". +Axiom ethereum_istanbul_vm_gas_imports : + AreImported globals "ethereum.istanbul.vm.gas" [ "GAS_CALL_STIPEND"; "GAS_SLOAD"; "GAS_STORAGE_CLEAR_REFUND"; "GAS_STORAGE_SET"; "GAS_STORAGE_UPDATE"; "charge_gas" ]. -Require ethereum.istanbul.vm.stack. -Axiom ethereum_istanbul_vm_stack_pop : - IsGlobalAlias globals ethereum.istanbul.vm.stack.globals "pop". -Axiom ethereum_istanbul_vm_stack_push : - IsGlobalAlias globals ethereum.istanbul.vm.stack.globals "push". +Axiom ethereum_istanbul_vm_stack_imports : + AreImported globals "ethereum.istanbul.vm.stack" [ "pop"; "push" ]. Definition sload : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/system.v b/CoqOfPython/ethereum/istanbul/vm/instructions/system.v index 7ef15d4..3e57a51 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/system.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/system.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.istanbul.vm.instructions.system". Definition expr_1 : Value.t := Constant.str " @@ -17,103 +17,38 @@ Introduction Implementations of the EVM system related instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.istanbul.fork_types. -Axiom ethereum_istanbul_fork_types_Address : - IsGlobalAlias globals ethereum.istanbul.fork_types.globals "Address". +Axiom ethereum_istanbul_fork_types_imports : + AreImported globals "ethereum.istanbul.fork_types" [ "Address" ]. -Require ethereum.istanbul.state. -Axiom ethereum_istanbul_state_account_exists_and_is_empty : - IsGlobalAlias globals ethereum.istanbul.state.globals "account_exists_and_is_empty". -Axiom ethereum_istanbul_state_account_has_code_or_nonce : - IsGlobalAlias globals ethereum.istanbul.state.globals "account_has_code_or_nonce". -Axiom ethereum_istanbul_state_get_account : - IsGlobalAlias globals ethereum.istanbul.state.globals "get_account". -Axiom ethereum_istanbul_state_increment_nonce : - IsGlobalAlias globals ethereum.istanbul.state.globals "increment_nonce". -Axiom ethereum_istanbul_state_is_account_alive : - IsGlobalAlias globals ethereum.istanbul.state.globals "is_account_alive". -Axiom ethereum_istanbul_state_set_account_balance : - IsGlobalAlias globals ethereum.istanbul.state.globals "set_account_balance". +Axiom ethereum_istanbul_state_imports : + AreImported globals "ethereum.istanbul.state" [ "account_exists_and_is_empty"; "account_has_code_or_nonce"; "get_account"; "increment_nonce"; "is_account_alive"; "set_account_balance" ]. -Require ethereum.istanbul.utils.address. -Axiom ethereum_istanbul_utils_address_compute_contract_address : - IsGlobalAlias globals ethereum.istanbul.utils.address.globals "compute_contract_address". -Axiom ethereum_istanbul_utils_address_compute_create2_contract_address : - IsGlobalAlias globals ethereum.istanbul.utils.address.globals "compute_create2_contract_address". -Axiom ethereum_istanbul_utils_address_to_address : - IsGlobalAlias globals ethereum.istanbul.utils.address.globals "to_address". +Axiom ethereum_istanbul_utils_address_imports : + AreImported globals "ethereum.istanbul.utils.address" [ "compute_contract_address"; "compute_create2_contract_address"; "to_address" ]. -Require ethereum.istanbul.vm.__init__. -Axiom ethereum_istanbul_vm___init___Evm : - IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Evm". -Axiom ethereum_istanbul_vm___init___Message : - IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Message". -Axiom ethereum_istanbul_vm___init___incorporate_child_on_error : - IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "incorporate_child_on_error". -Axiom ethereum_istanbul_vm___init___incorporate_child_on_success : - IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "incorporate_child_on_success". +Axiom ethereum_istanbul_vm_imports : + AreImported globals "ethereum.istanbul.vm" [ "Evm"; "Message"; "incorporate_child_on_error"; "incorporate_child_on_success" ]. -Require ethereum.istanbul.vm.exceptions. -Axiom ethereum_istanbul_vm_exceptions_Revert : - IsGlobalAlias globals ethereum.istanbul.vm.exceptions.globals "Revert". -Axiom ethereum_istanbul_vm_exceptions_WriteInStaticContext : - IsGlobalAlias globals ethereum.istanbul.vm.exceptions.globals "WriteInStaticContext". +Axiom ethereum_istanbul_vm_exceptions_imports : + AreImported globals "ethereum.istanbul.vm.exceptions" [ "Revert"; "WriteInStaticContext" ]. -Require ethereum.istanbul.vm.gas. -Axiom ethereum_istanbul_vm_gas_GAS_CALL : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_CALL". -Axiom ethereum_istanbul_vm_gas_GAS_CALL_VALUE : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_CALL_VALUE". -Axiom ethereum_istanbul_vm_gas_GAS_CREATE : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_CREATE". -Axiom ethereum_istanbul_vm_gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_KECCAK256_WORD". -Axiom ethereum_istanbul_vm_gas_GAS_NEW_ACCOUNT : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_NEW_ACCOUNT". -Axiom ethereum_istanbul_vm_gas_GAS_SELF_DESTRUCT : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_SELF_DESTRUCT". -Axiom ethereum_istanbul_vm_gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". -Axiom ethereum_istanbul_vm_gas_GAS_ZERO : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_ZERO". -Axiom ethereum_istanbul_vm_gas_REFUND_SELF_DESTRUCT : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "REFUND_SELF_DESTRUCT". -Axiom ethereum_istanbul_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_istanbul_vm_gas_calculate_message_call_gas : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "calculate_message_call_gas". -Axiom ethereum_istanbul_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "charge_gas". -Axiom ethereum_istanbul_vm_gas_max_message_call_gas : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "max_message_call_gas". +Axiom ethereum_istanbul_vm_gas_imports : + AreImported globals "ethereum.istanbul.vm.gas" [ "GAS_CALL"; "GAS_CALL_VALUE"; "GAS_CREATE"; "GAS_KECCAK256_WORD"; "GAS_NEW_ACCOUNT"; "GAS_SELF_DESTRUCT"; "GAS_SELF_DESTRUCT_NEW_ACCOUNT"; "GAS_ZERO"; "REFUND_SELF_DESTRUCT"; "calculate_gas_extend_memory"; "calculate_message_call_gas"; "charge_gas"; "max_message_call_gas" ]. -Require ethereum.istanbul.vm.memory. -Axiom ethereum_istanbul_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.istanbul.vm.memory.globals "memory_read_bytes". -Axiom ethereum_istanbul_vm_memory_memory_write : - IsGlobalAlias globals ethereum.istanbul.vm.memory.globals "memory_write". +Axiom ethereum_istanbul_vm_memory_imports : + AreImported globals "ethereum.istanbul.vm.memory" [ "memory_read_bytes"; "memory_write" ]. -Require ethereum.istanbul.vm.stack. -Axiom ethereum_istanbul_vm_stack_pop : - IsGlobalAlias globals ethereum.istanbul.vm.stack.globals "pop". -Axiom ethereum_istanbul_vm_stack_push : - IsGlobalAlias globals ethereum.istanbul.vm.stack.globals "push". +Axiom ethereum_istanbul_vm_stack_imports : + AreImported globals "ethereum.istanbul.vm.stack" [ "pop"; "push" ]. Definition generic_create : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -859,7 +794,12 @@ Definition generic_call : Value.t -> Value.t -> M := make_list [ M.get_field (| M.get_name (| globals, "evm" |), "memory" |); M.get_name (| globals, "memory_output_start_position" |); - M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), M.slice (| Constant.None_, M.get_name (| globals, "actual_output_size" |) |) |) + M.slice (| + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), + Constant.None_, + M.get_name (| globals, "actual_output_size" |), + Constant.None_ + |) ], make_dict [] |) in @@ -1437,20 +1377,28 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in let parent_evm := M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "parent_evm" |) in - While Compare.is_not (| - M.get_name (| globals, "parent_evm" |), - Constant.None_ - |) do - let _ := M.call (| + let _ := + M.while (| + Compare.is_not (| + M.get_name (| globals, "parent_evm" |), + Constant.None_ + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "refunded_accounts" |), "update" |), make_list [ M.get_field (| M.get_name (| globals, "parent_evm" |), "accounts_to_delete" |) ], make_dict [] |) in - let parent_evm := - M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in - EndWhile. + let parent_evm := + M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := (* if *) M.if_then_else (| @@ -1952,6 +1900,6 @@ Definition revert : Value.t -> Value.t -> M := make_dict [] |) |) in - let _ := M.raise (| Some(M.get_name (| globals, "Revert" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "Revert" |)) |) in let _ := M.pass (| |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/istanbul/vm/interpreter.v b/CoqOfPython/ethereum/istanbul/vm/interpreter.v index 145b4d1..993fb31 100644 --- a/CoqOfPython/ethereum/istanbul/vm/interpreter.v +++ b/CoqOfPython/ethereum/istanbul/vm/interpreter.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.istanbul.vm.interpreter". Definition expr_1 : Value.t := Constant.str " @@ -17,125 +17,50 @@ Introduction A straightforward interpreter that executes EVM code. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_Iterable : - IsGlobalAlias globals typing.globals "Iterable". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.trace. -Axiom ethereum_trace_EvmStop : - IsGlobalAlias globals ethereum.trace.globals "EvmStop". -Axiom ethereum_trace_OpEnd : - IsGlobalAlias globals ethereum.trace.globals "OpEnd". -Axiom ethereum_trace_OpException : - IsGlobalAlias globals ethereum.trace.globals "OpException". -Axiom ethereum_trace_OpStart : - IsGlobalAlias globals ethereum.trace.globals "OpStart". -Axiom ethereum_trace_PrecompileEnd : - IsGlobalAlias globals ethereum.trace.globals "PrecompileEnd". -Axiom ethereum_trace_PrecompileStart : - IsGlobalAlias globals ethereum.trace.globals "PrecompileStart". -Axiom ethereum_trace_TransactionEnd : - IsGlobalAlias globals ethereum.trace.globals "TransactionEnd". -Axiom ethereum_trace_evm_trace : - IsGlobalAlias globals ethereum.trace.globals "evm_trace". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.istanbul.blocks. -Axiom ethereum_istanbul_blocks_Log : - IsGlobalAlias globals ethereum.istanbul.blocks.globals "Log". - -Require ethereum.istanbul.fork_types. -Axiom ethereum_istanbul_fork_types_Address : - IsGlobalAlias globals ethereum.istanbul.fork_types.globals "Address". - -Require ethereum.istanbul.state. -Axiom ethereum_istanbul_state_account_exists_and_is_empty : - IsGlobalAlias globals ethereum.istanbul.state.globals "account_exists_and_is_empty". -Axiom ethereum_istanbul_state_account_has_code_or_nonce : - IsGlobalAlias globals ethereum.istanbul.state.globals "account_has_code_or_nonce". -Axiom ethereum_istanbul_state_begin_transaction : - IsGlobalAlias globals ethereum.istanbul.state.globals "begin_transaction". -Axiom ethereum_istanbul_state_commit_transaction : - IsGlobalAlias globals ethereum.istanbul.state.globals "commit_transaction". -Axiom ethereum_istanbul_state_destroy_storage : - IsGlobalAlias globals ethereum.istanbul.state.globals "destroy_storage". -Axiom ethereum_istanbul_state_increment_nonce : - IsGlobalAlias globals ethereum.istanbul.state.globals "increment_nonce". -Axiom ethereum_istanbul_state_mark_account_created : - IsGlobalAlias globals ethereum.istanbul.state.globals "mark_account_created". -Axiom ethereum_istanbul_state_move_ether : - IsGlobalAlias globals ethereum.istanbul.state.globals "move_ether". -Axiom ethereum_istanbul_state_rollback_transaction : - IsGlobalAlias globals ethereum.istanbul.state.globals "rollback_transaction". -Axiom ethereum_istanbul_state_set_code : - IsGlobalAlias globals ethereum.istanbul.state.globals "set_code". -Axiom ethereum_istanbul_state_touch_account : - IsGlobalAlias globals ethereum.istanbul.state.globals "touch_account". - -Require ethereum.istanbul.vm.__init__. -Axiom ethereum_istanbul_vm___init___Message : - IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Message". - -Require ethereum.istanbul.vm.gas. -Axiom ethereum_istanbul_vm_gas_GAS_CODE_DEPOSIT : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_CODE_DEPOSIT". -Axiom ethereum_istanbul_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "charge_gas". - -Require ethereum.istanbul.vm.precompiled_contracts.mapping. -Axiom ethereum_istanbul_vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : - IsGlobalAlias globals ethereum.istanbul.vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". - -Require ethereum.istanbul.vm.__init__. -Axiom ethereum_istanbul_vm___init___Environment : - IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Environment". -Axiom ethereum_istanbul_vm___init___Evm : - IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Evm". - -Require ethereum.istanbul.vm.exceptions. -Axiom ethereum_istanbul_vm_exceptions_AddressCollision : - IsGlobalAlias globals ethereum.istanbul.vm.exceptions.globals "AddressCollision". -Axiom ethereum_istanbul_vm_exceptions_ExceptionalHalt : - IsGlobalAlias globals ethereum.istanbul.vm.exceptions.globals "ExceptionalHalt". -Axiom ethereum_istanbul_vm_exceptions_InvalidOpcode : - IsGlobalAlias globals ethereum.istanbul.vm.exceptions.globals "InvalidOpcode". -Axiom ethereum_istanbul_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.istanbul.vm.exceptions.globals "OutOfGasError". -Axiom ethereum_istanbul_vm_exceptions_Revert : - IsGlobalAlias globals ethereum.istanbul.vm.exceptions.globals "Revert". -Axiom ethereum_istanbul_vm_exceptions_StackDepthLimitError : - IsGlobalAlias globals ethereum.istanbul.vm.exceptions.globals "StackDepthLimitError". - -Require ethereum.istanbul.vm.instructions.__init__. -Axiom ethereum_istanbul_vm_instructions___init___Ops : - IsGlobalAlias globals ethereum.istanbul.vm.instructions.__init__.globals "Ops". -Axiom ethereum_istanbul_vm_instructions___init___op_implementation : - IsGlobalAlias globals ethereum.istanbul.vm.instructions.__init__.globals "op_implementation". - -Require ethereum.istanbul.vm.runtime. -Axiom ethereum_istanbul_vm_runtime_get_valid_jump_destinations : - IsGlobalAlias globals ethereum.istanbul.vm.runtime.globals "get_valid_jump_destinations". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Iterable"; "Optional"; "Set"; "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. + +Axiom ethereum_trace_imports : + AreImported globals "ethereum.trace" [ "EvmStop"; "OpEnd"; "OpException"; "OpStart"; "PrecompileEnd"; "PrecompileStart"; "TransactionEnd"; "evm_trace" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_istanbul_blocks_imports : + AreImported globals "ethereum.istanbul.blocks" [ "Log" ]. + +Axiom ethereum_istanbul_fork_types_imports : + AreImported globals "ethereum.istanbul.fork_types" [ "Address" ]. + +Axiom ethereum_istanbul_state_imports : + AreImported globals "ethereum.istanbul.state" [ "account_exists_and_is_empty"; "account_has_code_or_nonce"; "begin_transaction"; "commit_transaction"; "destroy_storage"; "increment_nonce"; "mark_account_created"; "move_ether"; "rollback_transaction"; "set_code"; "touch_account" ]. + +Axiom ethereum_istanbul_vm_imports : + AreImported globals "ethereum.istanbul.vm" [ "Message" ]. + +Axiom ethereum_istanbul_vm_gas_imports : + AreImported globals "ethereum.istanbul.vm.gas" [ "GAS_CODE_DEPOSIT"; "charge_gas" ]. + +Axiom ethereum_istanbul_vm_precompiled_contracts_mapping_imports : + AreImported globals "ethereum.istanbul.vm.precompiled_contracts.mapping" [ "PRE_COMPILED_CONTRACTS" ]. + +Axiom ethereum_istanbul_vm_imports : + AreImported globals "ethereum.istanbul.vm" [ "Environment"; "Evm" ]. + +Axiom ethereum_istanbul_vm_exceptions_imports : + AreImported globals "ethereum.istanbul.vm.exceptions" [ "AddressCollision"; "ExceptionalHalt"; "InvalidOpcode"; "OutOfGasError"; "Revert"; "StackDepthLimitError" ]. + +Axiom ethereum_istanbul_vm_instructions_imports : + AreImported globals "ethereum.istanbul.vm.instructions" [ "Ops"; "op_implementation" ]. + +Axiom ethereum_istanbul_vm_runtime_imports : + AreImported globals "ethereum.istanbul.vm.runtime" [ "get_valid_jump_destinations" ]. Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -516,7 +441,7 @@ Definition process_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "StackDepthLimitError" |), make_list [ Constant.str "Stack depth limit reached" diff --git a/CoqOfPython/ethereum/istanbul/vm/memory.v b/CoqOfPython/ethereum/istanbul/vm/memory.v index 08d2290..7a5c377 100644 --- a/CoqOfPython/ethereum/istanbul/vm/memory.v +++ b/CoqOfPython/ethereum/istanbul/vm/memory.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.istanbul.vm.memory". Definition expr_1 : Value.t := Constant.str " @@ -17,17 +17,11 @@ Introduction EVM memory operations. ". -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_right_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "right_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "right_pad_zero_bytes" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. Definition memory_write : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,22 +39,27 @@ Definition memory_write : Value.t -> Value.t -> M := Data to write to memory. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + M.slice (| + M.get_name (| globals, "memory" |), + M.get_name (| globals, "start_position" |), + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) - |) |) |), + Constant.None_ + |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_)). @@ -86,22 +85,27 @@ Definition memory_read_bytes : Value.t -> Value.t -> M := Data read from memory. " in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + M.slice (| + M.get_name (| globals, "memory" |), + M.get_name (| globals, "start_position" |), + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |) |) + Constant.None_ + |) |) in M.pure Constant.None_)). @@ -129,22 +133,27 @@ Definition buffer_read : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "right_pad_zero_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "buffer" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + M.slice (| + M.get_name (| globals, "buffer" |), + M.get_name (| globals, "start_position" |), + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |) |); + Constant.None_ + |); M.get_name (| globals, "size" |) ], make_dict [] diff --git a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/__init__.v index 4ecabfb..0dced64 100644 --- a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/__init__.v +++ b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.istanbul.vm.precompiled_contracts.__init__". Definition expr_1 : Value.t := Constant.str " @@ -18,9 +18,8 @@ Addresses of precompiled contracts and mappings to their implementations. ". -Require ethereum.istanbul.utils.hexadecimal. -Axiom ethereum_istanbul_utils_hexadecimal_hex_to_address : - IsGlobalAlias globals ethereum.istanbul.utils.hexadecimal.globals "hex_to_address". +Axiom ethereum_istanbul_utils_hexadecimal_imports : + AreImported globals "ethereum.istanbul.utils.hexadecimal" [ "hex_to_address" ]. Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS"; Constant.str "MODEXP_ADDRESS"; Constant.str "ALT_BN128_ADD_ADDRESS"; Constant.str "ALT_BN128_MUL_ADDRESS"; Constant.str "ALT_BN128_PAIRING_CHECK_ADDRESS"; Constant.str "BLAKE2F_ADDRESS" ] diff --git a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/alt_bn128.v index 2ac2172..7cada44 100644 --- a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/alt_bn128.v +++ b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/alt_bn128.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.istanbul.vm.precompiled_contracts.alt_bn128". Definition expr_1 : Value.t := Constant.str " @@ -17,49 +17,26 @@ Introduction Implementation of the ALT_BN128 precompiled contracts. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. -Require ethereum.crypto.alt_bn128. -Axiom ethereum_crypto_alt_bn128_ALT_BN128_CURVE_ORDER : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "ALT_BN128_CURVE_ORDER". -Axiom ethereum_crypto_alt_bn128_ALT_BN128_PRIME : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "ALT_BN128_PRIME". -Axiom ethereum_crypto_alt_bn128_BNF : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF". -Axiom ethereum_crypto_alt_bn128_BNF2 : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF2". -Axiom ethereum_crypto_alt_bn128_BNF12 : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF12". -Axiom ethereum_crypto_alt_bn128_BNP : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNP". -Axiom ethereum_crypto_alt_bn128_BNP2 : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNP2". -Axiom ethereum_crypto_alt_bn128_pairing : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "pairing". +Axiom ethereum_crypto_alt_bn128_imports : + AreImported globals "ethereum.crypto.alt_bn128" [ "ALT_BN128_CURVE_ORDER"; "ALT_BN128_PRIME"; "BNF"; "BNF2"; "BNF12"; "BNP"; "BNP2"; "pairing" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.istanbul.vm.__init__. -Axiom ethereum_istanbul_vm___init___Evm : - IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Evm". +Axiom ethereum_istanbul_vm_imports : + AreImported globals "ethereum.istanbul.vm" [ "Evm" ]. -Require ethereum.istanbul.vm.gas. -Axiom ethereum_istanbul_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "charge_gas". +Axiom ethereum_istanbul_vm_gas_imports : + AreImported globals "ethereum.istanbul.vm.gas" [ "charge_gas" ]. -Require ethereum.istanbul.vm.memory. -Axiom ethereum_istanbul_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.istanbul.vm.memory.globals "buffer_read". +Axiom ethereum_istanbul_vm_memory_imports : + AreImported globals "ethereum.istanbul.vm.memory" [ "buffer_read" ]. -Require ethereum.istanbul.vm.exceptions. -Axiom ethereum_istanbul_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.istanbul.vm.exceptions.globals "OutOfGasError". +Axiom ethereum_istanbul_vm_exceptions_imports : + AreImported globals "ethereum.istanbul.vm.exceptions" [ "OutOfGasError" ]. Definition alt_bn128_add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -208,23 +185,32 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ] do - let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| - M.get_name (| globals, "i" |), - M.get_name (| globals, "ALT_BN128_PRIME" |) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ], ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in (* At stmt: unsupported node type: Try *) let p := BinOp.add (| @@ -363,23 +349,32 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ] do - let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| - M.get_name (| globals, "i" |), - M.get_name (| globals, "ALT_BN128_PRIME" |) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ], ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in (* At stmt: unsupported node type: Try *) let p := M.call (| @@ -466,7 +461,7 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -480,76 +475,89 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - BinOp.floor_div (| + let _ := + M.for_ (| + M.get_name (| globals, "i" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "data" |) - ], - make_dict [] - |), - Constant.int 192 - |) - ], - make_dict [] - |) do - let values := - make_list [] in - For M.get_name (| globals, "j" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 6 - ], - make_dict [] - |) do - let value := + M.get_name (| globals, "range" |), + make_list [ + BinOp.floor_div (| M.call (| - M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + M.get_name (| globals, "len" |), make_list [ - M.get_subscript (| M.get_name (| globals, "data" |), M.slice (| BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "i" |), - Constant.int 192 - |), - BinOp.mult (| - Constant.int 32, - M.get_name (| globals, "j" |) - |) - |), BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "i" |), - Constant.int 192 - |), - BinOp.mult (| - Constant.int 32, - BinOp.add (| - M.get_name (| globals, "j" |), - Constant.int 1 - |) - |) - |) |) |) + M.get_name (| globals, "data" |) ], make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| - M.get_name (| globals, "value" |), - M.get_name (| globals, "ALT_BN128_PRIME" |) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let _ := M.call (| + |), + Constant.int 192 + |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let values := + make_list [] in + let _ := + M.for_ (| + M.get_name (| globals, "j" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 6 + ], + make_dict [] + |), + ltac:(M.monadic ( + let value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.slice (| + M.get_name (| globals, "data" |), + BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + M.get_name (| globals, "j" |) + |) + |), + BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "j" |), + Constant.int 1 + |) + |) + |), + Constant.None_ + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| M.get_field (| M.get_name (| globals, "values" |), "append" |), make_list [ M.call (| @@ -562,9 +570,14 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in (* At stmt: unsupported node type: Try *) - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.eq (| @@ -585,7 +598,7 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.eq (| @@ -606,49 +619,54 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| - M.get_name (| globals, "p" |), - M.call (| - M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) - |), + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "p" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "q" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |) + )) + |), + (* then *) ltac:(M.monadic ( - Compare.not_eq (| - M.get_name (| globals, "q" |), - M.call (| - M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) - |) - )) - |), - (* then *) - ltac:(M.monadic ( - let result := - BinOp.mult (| - M.get_name (| globals, "result" |), - M.call (| - M.get_name (| globals, "pairing" |), - make_list [ - M.get_name (| globals, "q" |); - M.get_name (| globals, "p" |) - ], - make_dict [] - |) - |) in + let result := + BinOp.mult (| + M.get_name (| globals, "result" |), + M.call (| + M.get_name (| globals, "pairing" |), + make_list [ + M.get_name (| globals, "q" |); + M.get_name (| globals, "p" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := (* if *) M.if_then_else (| diff --git a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/blake2f.v b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/blake2f.v index a0c873b..6c768ea 100644 --- a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/blake2f.v +++ b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/blake2f.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.istanbul.vm.precompiled_contracts.blake2f". Definition expr_1 : Value.t := Constant.str " @@ -17,27 +17,20 @@ Introduction Implementation of the `Blake2` precompiled contract. ". -Require ethereum.crypto.blake2. -Axiom ethereum_crypto_blake2_Blake2b : - IsGlobalAlias globals ethereum.crypto.blake2.globals "Blake2b". +Axiom ethereum_crypto_blake2_imports : + AreImported globals "ethereum.crypto.blake2" [ "Blake2b" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.istanbul.vm.__init__. -Axiom ethereum_istanbul_vm___init___Evm : - IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Evm". +Axiom ethereum_istanbul_vm_imports : + AreImported globals "ethereum.istanbul.vm" [ "Evm" ]. -Require ethereum.istanbul.vm.gas. -Axiom ethereum_istanbul_vm_gas_GAS_BLAKE2_PER_ROUND : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_BLAKE2_PER_ROUND". -Axiom ethereum_istanbul_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "charge_gas". +Axiom ethereum_istanbul_vm_gas_imports : + AreImported globals "ethereum.istanbul.vm.gas" [ "GAS_BLAKE2_PER_ROUND"; "charge_gas" ]. -Require ethereum.istanbul.vm.exceptions. -Axiom ethereum_istanbul_vm_exceptions_InvalidParameter : - IsGlobalAlias globals ethereum.istanbul.vm.exceptions.globals "InvalidParameter". +Axiom ethereum_istanbul_vm_exceptions_imports : + AreImported globals "ethereum.istanbul.vm.exceptions" [ "InvalidParameter" ]. Definition blake2f : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -99,7 +92,7 @@ Definition blake2f : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.in (| + Compare.in_ (| M.get_name (| globals, "f" |), make_list [ Constant.int 0; diff --git a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/ecrecover.v index 25c8238..3b38ee1 100644 --- a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/ecrecover.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.istanbul.vm.precompiled_contracts.ecrecover". Definition expr_1 : Value.t := Constant.str " @@ -17,39 +17,26 @@ Introduction Implementation of the ECRECOVER precompiled contract. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.crypto.elliptic_curve. -Axiom ethereum_crypto_elliptic_curve_SECP256K1N : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". -Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". +Axiom ethereum_crypto_elliptic_curve_imports : + AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_left_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. -Require ethereum.istanbul.vm.__init__. -Axiom ethereum_istanbul_vm___init___Evm : - IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Evm". +Axiom ethereum_istanbul_vm_imports : + AreImported globals "ethereum.istanbul.vm" [ "Evm" ]. -Require ethereum.istanbul.vm.gas. -Axiom ethereum_istanbul_vm_gas_GAS_ECRECOVER : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_ECRECOVER". -Axiom ethereum_istanbul_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "charge_gas". +Axiom ethereum_istanbul_vm_gas_imports : + AreImported globals "ethereum.istanbul.vm.gas" [ "GAS_ECRECOVER"; "charge_gas" ]. -Require ethereum.istanbul.vm.memory. -Axiom ethereum_istanbul_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.istanbul.vm.memory.globals "buffer_read". +Axiom ethereum_istanbul_vm_memory_imports : + AreImported globals "ethereum.istanbul.vm.memory" [ "buffer_read" ]. Definition ecrecover : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -264,13 +251,18 @@ Definition ecrecover : Value.t -> Value.t -> M := )) |) in (* At stmt: unsupported node type: Try *) let address := - M.get_subscript (| M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "public_key" |) - ], - make_dict [] - |), M.slice (| Constant.int 12, Constant.int 32 |) |) in + M.slice (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), + Constant.int 12, + Constant.int 32, + Constant.None_ + |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/identity.v index 3e2007a..9250b3c 100644 --- a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/identity.v +++ b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/identity.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.istanbul.vm.precompiled_contracts.identity". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementation of the `IDENTITY` precompiled contract. ". -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.istanbul.vm.__init__. -Axiom ethereum_istanbul_vm___init___Evm : - IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Evm". +Axiom ethereum_istanbul_vm_imports : + AreImported globals "ethereum.istanbul.vm" [ "Evm" ]. -Require ethereum.istanbul.vm.gas. -Axiom ethereum_istanbul_vm_gas_GAS_IDENTITY : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_IDENTITY". -Axiom ethereum_istanbul_vm_gas_GAS_IDENTITY_WORD : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_IDENTITY_WORD". -Axiom ethereum_istanbul_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "charge_gas". +Axiom ethereum_istanbul_vm_gas_imports : + AreImported globals "ethereum.istanbul.vm.gas" [ "GAS_IDENTITY"; "GAS_IDENTITY_WORD"; "charge_gas" ]. Definition identity : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/mapping.v index 2dfb4a0..7aeb360 100644 --- a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/mapping.v +++ b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/mapping.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.istanbul.vm.precompiled_contracts.mapping". Definition expr_1 : Value.t := Constant.str " @@ -17,66 +17,34 @@ Introduction Mapping of precompiled contracts their implementations. ". -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". - -Require ethereum.istanbul.fork_types. -Axiom ethereum_istanbul_fork_types_Address : - IsGlobalAlias globals ethereum.istanbul.fork_types.globals "Address". - -Require ethereum.istanbul.vm.precompiled_contracts.__init__. -Axiom ethereum_istanbul_vm_precompiled_contracts___init___ALT_BN128_ADD_ADDRESS : - IsGlobalAlias globals ethereum.istanbul.vm.precompiled_contracts.__init__.globals "ALT_BN128_ADD_ADDRESS". -Axiom ethereum_istanbul_vm_precompiled_contracts___init___ALT_BN128_MUL_ADDRESS : - IsGlobalAlias globals ethereum.istanbul.vm.precompiled_contracts.__init__.globals "ALT_BN128_MUL_ADDRESS". -Axiom ethereum_istanbul_vm_precompiled_contracts___init___ALT_BN128_PAIRING_CHECK_ADDRESS : - IsGlobalAlias globals ethereum.istanbul.vm.precompiled_contracts.__init__.globals "ALT_BN128_PAIRING_CHECK_ADDRESS". -Axiom ethereum_istanbul_vm_precompiled_contracts___init___BLAKE2F_ADDRESS : - IsGlobalAlias globals ethereum.istanbul.vm.precompiled_contracts.__init__.globals "BLAKE2F_ADDRESS". -Axiom ethereum_istanbul_vm_precompiled_contracts___init___ECRECOVER_ADDRESS : - IsGlobalAlias globals ethereum.istanbul.vm.precompiled_contracts.__init__.globals "ECRECOVER_ADDRESS". -Axiom ethereum_istanbul_vm_precompiled_contracts___init___IDENTITY_ADDRESS : - IsGlobalAlias globals ethereum.istanbul.vm.precompiled_contracts.__init__.globals "IDENTITY_ADDRESS". -Axiom ethereum_istanbul_vm_precompiled_contracts___init___MODEXP_ADDRESS : - IsGlobalAlias globals ethereum.istanbul.vm.precompiled_contracts.__init__.globals "MODEXP_ADDRESS". -Axiom ethereum_istanbul_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : - IsGlobalAlias globals ethereum.istanbul.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". -Axiom ethereum_istanbul_vm_precompiled_contracts___init___SHA256_ADDRESS : - IsGlobalAlias globals ethereum.istanbul.vm.precompiled_contracts.__init__.globals "SHA256_ADDRESS". - -Require ethereum.istanbul.vm.precompiled_contracts.alt_bn128. -Axiom ethereum_istanbul_vm_precompiled_contracts_alt_bn128_alt_bn128_add : - IsGlobalAlias globals ethereum.istanbul.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_add". -Axiom ethereum_istanbul_vm_precompiled_contracts_alt_bn128_alt_bn128_mul : - IsGlobalAlias globals ethereum.istanbul.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_mul". -Axiom ethereum_istanbul_vm_precompiled_contracts_alt_bn128_alt_bn128_pairing_check : - IsGlobalAlias globals ethereum.istanbul.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_pairing_check". - -Require ethereum.istanbul.vm.precompiled_contracts.blake2f. -Axiom ethereum_istanbul_vm_precompiled_contracts_blake2f_blake2f : - IsGlobalAlias globals ethereum.istanbul.vm.precompiled_contracts.blake2f.globals "blake2f". - -Require ethereum.istanbul.vm.precompiled_contracts.ecrecover. -Axiom ethereum_istanbul_vm_precompiled_contracts_ecrecover_ecrecover : - IsGlobalAlias globals ethereum.istanbul.vm.precompiled_contracts.ecrecover.globals "ecrecover". - -Require ethereum.istanbul.vm.precompiled_contracts.identity. -Axiom ethereum_istanbul_vm_precompiled_contracts_identity_identity : - IsGlobalAlias globals ethereum.istanbul.vm.precompiled_contracts.identity.globals "identity". - -Require ethereum.istanbul.vm.precompiled_contracts.modexp. -Axiom ethereum_istanbul_vm_precompiled_contracts_modexp_modexp : - IsGlobalAlias globals ethereum.istanbul.vm.precompiled_contracts.modexp.globals "modexp". - -Require ethereum.istanbul.vm.precompiled_contracts.ripemd160. -Axiom ethereum_istanbul_vm_precompiled_contracts_ripemd160_ripemd160 : - IsGlobalAlias globals ethereum.istanbul.vm.precompiled_contracts.ripemd160.globals "ripemd160". - -Require ethereum.istanbul.vm.precompiled_contracts.sha256. -Axiom ethereum_istanbul_vm_precompiled_contracts_sha256_sha256 : - IsGlobalAlias globals ethereum.istanbul.vm.precompiled_contracts.sha256.globals "sha256". +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict" ]. + +Axiom ethereum_istanbul_fork_types_imports : + AreImported globals "ethereum.istanbul.fork_types" [ "Address" ]. + +Axiom ethereum_istanbul_vm_precompiled_contracts_imports : + AreImported globals "ethereum.istanbul.vm.precompiled_contracts" [ "ALT_BN128_ADD_ADDRESS"; "ALT_BN128_MUL_ADDRESS"; "ALT_BN128_PAIRING_CHECK_ADDRESS"; "BLAKE2F_ADDRESS"; "ECRECOVER_ADDRESS"; "IDENTITY_ADDRESS"; "MODEXP_ADDRESS"; "RIPEMD160_ADDRESS"; "SHA256_ADDRESS" ]. + +Axiom ethereum_istanbul_vm_precompiled_contracts_alt_bn128_imports : + AreImported globals "ethereum.istanbul.vm.precompiled_contracts.alt_bn128" [ "alt_bn128_add"; "alt_bn128_mul"; "alt_bn128_pairing_check" ]. + +Axiom ethereum_istanbul_vm_precompiled_contracts_blake2f_imports : + AreImported globals "ethereum.istanbul.vm.precompiled_contracts.blake2f" [ "blake2f" ]. + +Axiom ethereum_istanbul_vm_precompiled_contracts_ecrecover_imports : + AreImported globals "ethereum.istanbul.vm.precompiled_contracts.ecrecover" [ "ecrecover" ]. + +Axiom ethereum_istanbul_vm_precompiled_contracts_identity_imports : + AreImported globals "ethereum.istanbul.vm.precompiled_contracts.identity" [ "identity" ]. + +Axiom ethereum_istanbul_vm_precompiled_contracts_modexp_imports : + AreImported globals "ethereum.istanbul.vm.precompiled_contracts.modexp" [ "modexp" ]. + +Axiom ethereum_istanbul_vm_precompiled_contracts_ripemd160_imports : + AreImported globals "ethereum.istanbul.vm.precompiled_contracts.ripemd160" [ "ripemd160" ]. + +Axiom ethereum_istanbul_vm_precompiled_contracts_sha256_imports : + AreImported globals "ethereum.istanbul.vm.precompiled_contracts.sha256" [ "sha256" ]. (* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/modexp.v index 2eb27a5..d0bfc29 100644 --- a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/modexp.v +++ b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/modexp.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.istanbul.vm.precompiled_contracts.modexp". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementation of the `MODEXP` precompiled contract. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. -Require ethereum.istanbul.vm.__init__. -Axiom ethereum_istanbul_vm___init___Evm : - IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Evm". +Axiom ethereum_istanbul_vm_imports : + AreImported globals "ethereum.istanbul.vm" [ "Evm" ]. -Require ethereum.istanbul.vm.gas. -Axiom ethereum_istanbul_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "charge_gas". +Axiom ethereum_istanbul_vm_gas_imports : + AreImported globals "ethereum.istanbul.vm.gas" [ "charge_gas" ]. -Require ethereum.istanbul.vm.memory. -Axiom ethereum_istanbul_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.istanbul.vm.memory.globals "buffer_read". +Axiom ethereum_istanbul_vm_memory_imports : + AreImported globals "ethereum.istanbul.vm.memory" [ "buffer_read" ]. Definition GQUADDIVISOR : Value.t := M.run ltac:(M.monadic ( M.call (| diff --git a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/ripemd160.v index 7725002..0cc1522 100644 --- a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/ripemd160.v +++ b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/ripemd160.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.istanbul.vm.precompiled_contracts.ripemd160". Definition expr_1 : Value.t := Constant.str " @@ -19,29 +19,20 @@ Implementation of the `RIPEMD160` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_left_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.istanbul.vm.__init__. -Axiom ethereum_istanbul_vm___init___Evm : - IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Evm". +Axiom ethereum_istanbul_vm_imports : + AreImported globals "ethereum.istanbul.vm" [ "Evm" ]. -Require ethereum.istanbul.vm.gas. -Axiom ethereum_istanbul_vm_gas_GAS_RIPEMD160 : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_RIPEMD160". -Axiom ethereum_istanbul_vm_gas_GAS_RIPEMD160_WORD : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_RIPEMD160_WORD". -Axiom ethereum_istanbul_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "charge_gas". +Axiom ethereum_istanbul_vm_gas_imports : + AreImported globals "ethereum.istanbul.vm.gas" [ "GAS_RIPEMD160"; "GAS_RIPEMD160_WORD"; "charge_gas" ]. Definition ripemd160 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/sha256.v index 14ebf99..d5850ca 100644 --- a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/sha256.v +++ b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/sha256.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.istanbul.vm.precompiled_contracts.sha256". Definition expr_1 : Value.t := Constant.str " @@ -19,25 +19,17 @@ Implementation of the `SHA256` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.istanbul.vm.__init__. -Axiom ethereum_istanbul_vm___init___Evm : - IsGlobalAlias globals ethereum.istanbul.vm.__init__.globals "Evm". +Axiom ethereum_istanbul_vm_imports : + AreImported globals "ethereum.istanbul.vm" [ "Evm" ]. -Require ethereum.istanbul.vm.gas. -Axiom ethereum_istanbul_vm_gas_GAS_SHA256 : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_SHA256". -Axiom ethereum_istanbul_vm_gas_GAS_SHA256_WORD : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "GAS_SHA256_WORD". -Axiom ethereum_istanbul_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.istanbul.vm.gas.globals "charge_gas". +Axiom ethereum_istanbul_vm_gas_imports : + AreImported globals "ethereum.istanbul.vm.gas" [ "GAS_SHA256"; "GAS_SHA256_WORD"; "charge_gas" ]. Definition sha256 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/istanbul/vm/runtime.v b/CoqOfPython/ethereum/istanbul/vm/runtime.v index 77cb330..4f6271e 100644 --- a/CoqOfPython/ethereum/istanbul/vm/runtime.v +++ b/CoqOfPython/ethereum/istanbul/vm/runtime.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.istanbul.vm.runtime". Definition expr_1 : Value.t := Constant.str " @@ -17,17 +17,14 @@ Introduction Runtime related operations used while executing EVM code. ". -Require typing. -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". +Axiom typing_imports : + AreImported globals "typing" [ "Set" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.istanbul.vm.instructions.__init__. -Axiom ethereum_istanbul_vm_instructions___init___Ops : - IsGlobalAlias globals ethereum.istanbul.vm.instructions.__init__.globals "Ops". +Axiom ethereum_istanbul_vm_instructions_imports : + AreImported globals "ethereum.istanbul.vm.instructions" [ "Ops" ]. Definition get_valid_jump_destinations : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -67,75 +64,83 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := ], make_dict [] |) in - While Compare.lt (| - M.get_name (| globals, "pc" |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "code" |) - ], - make_dict [] - |) - |) do -(* At stmt: unsupported node type: Try *) - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "current_opcode" |), - M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) - |), - (* then *) + let _ := + M.while (| + Compare.lt (| + M.get_name (| globals, "pc" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) + |), ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), - make_list [ - M.get_name (| globals, "pc" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( +(* At stmt: unsupported node type: Try *) let _ := (* if *) M.if_then_else (| - BoolOp.and (| - Compare.lt_e (| - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |), - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |) - |), - ltac:(M.monadic ( - Compare.lt_e (| - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH32" |), "value" |) - |) - )) + Compare.eq (| + M.get_name (| globals, "current_opcode" |), + M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) |), (* then *) ltac:(M.monadic ( - let push_data_size := - BinOp.add (| - BinOp.sub (| - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) - |), - Constant.int 1 - |) in - let pc := BinOp.add - M.get_name (| globals, "push_data_size" |) - M.get_name (| globals, "push_data_size" |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), + make_list [ + M.get_name (| globals, "pc" |) + ], + make_dict [] + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.lt_e (| + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |), + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH32" |), "value" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let push_data_size := + BinOp.add (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) + |), + Constant.int 1 + |) in + let pc := BinOp.add + M.get_name (| globals, "push_data_size" |) + M.get_name (| globals, "push_data_size" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ )) |) in + let pc := BinOp.add + Constant.int 1 + Constant.int 1 in M.pure Constant.None_ - )) |) in - let pc := BinOp.add - Constant.int 1 - Constant.int 1 in - EndWhile. + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.get_name (| globals, "valid_jump_destinations" |) |) in diff --git a/CoqOfPython/ethereum/istanbul/vm/stack.v b/CoqOfPython/ethereum/istanbul/vm/stack.v index f9af452..abea471 100644 --- a/CoqOfPython/ethereum/istanbul/vm/stack.v +++ b/CoqOfPython/ethereum/istanbul/vm/stack.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.istanbul.vm.stack". Definition expr_1 : Value.t := Constant.str " @@ -17,19 +17,14 @@ Introduction Implementation of the stack operators for the EVM. ". -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". +Axiom typing_imports : + AreImported globals "typing" [ "List" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.istanbul.vm.exceptions. -Axiom ethereum_istanbul_vm_exceptions_StackOverflowError : - IsGlobalAlias globals ethereum.istanbul.vm.exceptions.globals "StackOverflowError". -Axiom ethereum_istanbul_vm_exceptions_StackUnderflowError : - IsGlobalAlias globals ethereum.istanbul.vm.exceptions.globals "StackUnderflowError". +Axiom ethereum_istanbul_vm_exceptions_imports : + AreImported globals "ethereum.istanbul.vm.exceptions" [ "StackOverflowError"; "StackUnderflowError" ]. Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -63,7 +58,7 @@ Definition pop : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "StackUnderflowError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "StackUnderflowError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -108,7 +103,7 @@ Definition push : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "StackOverflowError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "StackOverflowError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/london/__init__.v b/CoqOfPython/ethereum/london/__init__.v index f653d66..219f2eb 100644 --- a/CoqOfPython/ethereum/london/__init__.v +++ b/CoqOfPython/ethereum/london/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.london.__init__". Definition expr_1 : Value.t := Constant.str " @@ -8,9 +8,8 @@ The London fork overhauls the transaction fee market, changes gas refunds, reserves a contract prefix for future use, and delays the difficulty bomb. ". -Require ethereum.fork_criteria. -Axiom ethereum_fork_criteria_ByBlockNumber : - IsGlobalAlias globals ethereum.fork_criteria.globals "ByBlockNumber". +Axiom ethereum_fork_criteria_imports : + AreImported globals "ethereum.fork_criteria" [ "ByBlockNumber" ]. Definition FORK_CRITERIA : Value.t := M.run ltac:(M.monadic ( M.call (| diff --git a/CoqOfPython/ethereum/london/blocks.v b/CoqOfPython/ethereum/london/blocks.v index 1b30d27..50027c9 100644 --- a/CoqOfPython/ethereum/london/blocks.v +++ b/CoqOfPython/ethereum/london/blocks.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.london.blocks". Definition expr_1 : Value.t := Constant.str " @@ -14,45 +14,23 @@ history of all state transitions that have happened since the genesis of the chain. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes8 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes8". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". - -Require ethereum.london.fork_types. -Axiom ethereum_london_fork_types_Address : - IsGlobalAlias globals ethereum.london.fork_types.globals "Address". -Axiom ethereum_london_fork_types_Bloom : - IsGlobalAlias globals ethereum.london.fork_types.globals "Bloom". -Axiom ethereum_london_fork_types_Root : - IsGlobalAlias globals ethereum.london.fork_types.globals "Root". - -Require ethereum.london.transactions. -Axiom ethereum_london_transactions_LegacyTransaction : - IsGlobalAlias globals ethereum.london.transactions.globals "LegacyTransaction". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Tuple"; "Union" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes8"; "Bytes32"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. + +Axiom ethereum_london_fork_types_imports : + AreImported globals "ethereum.london.fork_types" [ "Address"; "Bloom"; "Root" ]. + +Axiom ethereum_london_transactions_imports : + AreImported globals "ethereum.london.transactions" [ "LegacyTransaction" ]. Definition Header : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/london/bloom.v b/CoqOfPython/ethereum/london/bloom.v index afe8e98..9a8f4fc 100644 --- a/CoqOfPython/ethereum/london/bloom.v +++ b/CoqOfPython/ethereum/london/bloom.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.london.bloom". Definition expr_1 : Value.t := Constant.str " @@ -21,25 +21,20 @@ for efficient searching of logs by address and/or topic, by rapidly eliminating blocks and receipts from their search. ". -Require typing. -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_imports : + AreImported globals "typing" [ "Tuple" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. -Require ethereum.london.blocks. -Axiom ethereum_london_blocks_Log : - IsGlobalAlias globals ethereum.london.blocks.globals "Log". +Axiom ethereum_london_blocks_imports : + AreImported globals "ethereum.london.blocks" [ "Log" ]. -Require ethereum.london.fork_types. -Axiom ethereum_london_fork_types_Bloom : - IsGlobalAlias globals ethereum.london.fork_types.globals "Bloom". +Axiom ethereum_london_fork_types_imports : + AreImported globals "ethereum.london.fork_types" [ "Bloom" ]. Definition add_to_bloom : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -66,50 +61,70 @@ Definition add_to_bloom : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "idx" |) in make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ] do - let bit_to_set := - BinOp.bit_and (| - M.call (| - M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "hash" |), M.slice (| M.get_name (| globals, "idx" |), BinOp.add (| - M.get_name (| globals, "idx" |), - Constant.int 2 - |) |) |) - ], - make_dict [] - |), - Constant.int 2047 - |) in - let bit_index := - BinOp.sub (| - Constant.int 2047, - M.get_name (| globals, "bit_to_set" |) - |) in - let byte_index := - BinOp.floor_div (| - M.get_name (| globals, "bit_index" |), - Constant.int 8 - |) in - let bit_value := - BinOp.l_shift (| - Constant.int 1, - BinOp.sub (| - Constant.int 7, - BinOp.mod_ (| + let _ := + M.for_ (| + M.get_name (| globals, "idx" |), + make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ], + ltac:(M.monadic ( + let bit_to_set := + BinOp.bit_and (| + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.slice (| + M.get_name (| globals, "hash" |), + M.get_name (| globals, "idx" |), + BinOp.add (| + M.get_name (| globals, "idx" |), + Constant.int 2 + |), + Constant.None_ + |) + ], + make_dict [] + |), + Constant.int 2047 + |) in + let bit_index := + BinOp.sub (| + Constant.int 2047, + M.get_name (| globals, "bit_to_set" |) + |) in + let byte_index := + BinOp.floor_div (| M.get_name (| globals, "bit_index" |), Constant.int 8 + |) in + let bit_value := + BinOp.l_shift (| + Constant.int 1, + BinOp.sub (| + Constant.int 7, + BinOp.mod_ (| + M.get_name (| globals, "bit_index" |), + Constant.int 8 + |) + |) + |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "bloom" |), + M.get_name (| globals, "byte_index" |) + |), + BinOp.bit_or (| + M.get_subscript (| + M.get_name (| globals, "bloom" |), + M.get_name (| globals, "byte_index" |) + |), + M.get_name (| globals, "bit_value" |) |) - |) - |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), - BinOp.bit_or (| - M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), - M.get_name (| globals, "bit_value" |) - |) - |) in - EndFor. + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_)). Definition logs_bloom : Value.t -> Value.t -> M := @@ -132,8 +147,12 @@ Definition logs_bloom : Value.t -> Value.t -> M := the caller address and the log topics. " in (* At stmt: unsupported node type: AnnAssign *) - For M.get_name (| globals, "log" |) in M.get_name (| globals, "logs" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "log" |), + M.get_name (| globals, "logs" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "add_to_bloom" |), make_list [ M.get_name (| globals, "bloom" |); @@ -141,8 +160,12 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "topic" |) in M.get_field (| M.get_name (| globals, "log" |), "topics" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "topic" |), + M.get_field (| M.get_name (| globals, "log" |), "topics" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "add_to_bloom" |), make_list [ M.get_name (| globals, "bloom" |); @@ -150,8 +173,18 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Bloom" |), diff --git a/CoqOfPython/ethereum/london/fork.v b/CoqOfPython/ethereum/london/fork.v index 5904b9f..aa592fc 100644 --- a/CoqOfPython/ethereum/london/fork.v +++ b/CoqOfPython/ethereum/london/fork.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.london.fork". Definition expr_1 : Value.t := Constant.str " @@ -17,157 +17,62 @@ Introduction Entry point for the Ethereum specification. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". - -Require ethereum.base_types. -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". - -Require ethereum.crypto.elliptic_curve. -Axiom ethereum_crypto_elliptic_curve_SECP256K1N : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". -Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.ethash. -Axiom ethereum_ethash_dataset_size : - IsGlobalAlias globals ethereum.ethash.globals "dataset_size". -Axiom ethereum_ethash_generate_cache : - IsGlobalAlias globals ethereum.ethash.globals "generate_cache". -Axiom ethereum_ethash_hashimoto_light : - IsGlobalAlias globals ethereum.ethash.globals "hashimoto_light". - -Require ethereum.exceptions. -Axiom ethereum_exceptions_InvalidBlock : - IsGlobalAlias globals ethereum.exceptions.globals "InvalidBlock". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U64 : - IsGlobalAlias globals ethereum.base_types.globals "U64". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_U256_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.london.__init__. -Axiom ethereum_london___init___FORK_CRITERIA : - IsGlobalAlias globals ethereum.london.__init__.globals "FORK_CRITERIA". -Axiom ethereum_london___init___vm : - IsGlobalAlias globals ethereum.london.__init__.globals "vm". - -Require ethereum.london.blocks. -Axiom ethereum_london_blocks_Block : - IsGlobalAlias globals ethereum.london.blocks.globals "Block". -Axiom ethereum_london_blocks_Header : - IsGlobalAlias globals ethereum.london.blocks.globals "Header". -Axiom ethereum_london_blocks_Log : - IsGlobalAlias globals ethereum.london.blocks.globals "Log". -Axiom ethereum_london_blocks_Receipt : - IsGlobalAlias globals ethereum.london.blocks.globals "Receipt". - -Require ethereum.london.bloom. -Axiom ethereum_london_bloom_logs_bloom : - IsGlobalAlias globals ethereum.london.bloom.globals "logs_bloom". - -Require ethereum.london.fork_types. -Axiom ethereum_london_fork_types_Address : - IsGlobalAlias globals ethereum.london.fork_types.globals "Address". -Axiom ethereum_london_fork_types_Bloom : - IsGlobalAlias globals ethereum.london.fork_types.globals "Bloom". -Axiom ethereum_london_fork_types_Root : - IsGlobalAlias globals ethereum.london.fork_types.globals "Root". - -Require ethereum.london.state. -Axiom ethereum_london_state_State : - IsGlobalAlias globals ethereum.london.state.globals "State". -Axiom ethereum_london_state_account_exists_and_is_empty : - IsGlobalAlias globals ethereum.london.state.globals "account_exists_and_is_empty". -Axiom ethereum_london_state_create_ether : - IsGlobalAlias globals ethereum.london.state.globals "create_ether". -Axiom ethereum_london_state_destroy_account : - IsGlobalAlias globals ethereum.london.state.globals "destroy_account". -Axiom ethereum_london_state_get_account : - IsGlobalAlias globals ethereum.london.state.globals "get_account". -Axiom ethereum_london_state_increment_nonce : - IsGlobalAlias globals ethereum.london.state.globals "increment_nonce". -Axiom ethereum_london_state_set_account_balance : - IsGlobalAlias globals ethereum.london.state.globals "set_account_balance". -Axiom ethereum_london_state_state_root : - IsGlobalAlias globals ethereum.london.state.globals "state_root". - -Require ethereum.london.transactions. -Axiom ethereum_london_transactions_TX_ACCESS_LIST_ADDRESS_COST : - IsGlobalAlias globals ethereum.london.transactions.globals "TX_ACCESS_LIST_ADDRESS_COST". -Axiom ethereum_london_transactions_TX_ACCESS_LIST_STORAGE_KEY_COST : - IsGlobalAlias globals ethereum.london.transactions.globals "TX_ACCESS_LIST_STORAGE_KEY_COST". -Axiom ethereum_london_transactions_TX_BASE_COST : - IsGlobalAlias globals ethereum.london.transactions.globals "TX_BASE_COST". -Axiom ethereum_london_transactions_TX_CREATE_COST : - IsGlobalAlias globals ethereum.london.transactions.globals "TX_CREATE_COST". -Axiom ethereum_london_transactions_TX_DATA_COST_PER_NON_ZERO : - IsGlobalAlias globals ethereum.london.transactions.globals "TX_DATA_COST_PER_NON_ZERO". -Axiom ethereum_london_transactions_TX_DATA_COST_PER_ZERO : - IsGlobalAlias globals ethereum.london.transactions.globals "TX_DATA_COST_PER_ZERO". -Axiom ethereum_london_transactions_AccessListTransaction : - IsGlobalAlias globals ethereum.london.transactions.globals "AccessListTransaction". -Axiom ethereum_london_transactions_FeeMarketTransaction : - IsGlobalAlias globals ethereum.london.transactions.globals "FeeMarketTransaction". -Axiom ethereum_london_transactions_LegacyTransaction : - IsGlobalAlias globals ethereum.london.transactions.globals "LegacyTransaction". -Axiom ethereum_london_transactions_Transaction : - IsGlobalAlias globals ethereum.london.transactions.globals "Transaction". -Axiom ethereum_london_transactions_decode_transaction : - IsGlobalAlias globals ethereum.london.transactions.globals "decode_transaction". -Axiom ethereum_london_transactions_encode_transaction : - IsGlobalAlias globals ethereum.london.transactions.globals "encode_transaction". - -Require ethereum.london.trie. -Axiom ethereum_london_trie_Trie : - IsGlobalAlias globals ethereum.london.trie.globals "Trie". -Axiom ethereum_london_trie_root : - IsGlobalAlias globals ethereum.london.trie.globals "root". -Axiom ethereum_london_trie_trie_set : - IsGlobalAlias globals ethereum.london.trie.globals "trie_set". - -Require ethereum.london.utils.message. -Axiom ethereum_london_utils_message_prepare_message : - IsGlobalAlias globals ethereum.london.utils.message.globals "prepare_message". - -Require ethereum.london.vm.interpreter. -Axiom ethereum_london_vm_interpreter_process_message_call : - IsGlobalAlias globals ethereum.london.vm.interpreter.globals "process_message_call". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple"; "Union" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Bytes0" ]. + +Axiom ethereum_crypto_elliptic_curve_imports : + AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. + +Axiom ethereum_ethash_imports : + AreImported globals "ethereum.ethash" [ "dataset_size"; "generate_cache"; "hashimoto_light" ]. + +Axiom ethereum_exceptions_imports : + AreImported globals "ethereum.exceptions" [ "InvalidBlock" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U64"; "U256"; "U256_CEIL_VALUE"; "Bytes"; "Uint" ]. + +Axiom ethereum_london_imports : + AreImported globals "ethereum.london" [ "FORK_CRITERIA"; "vm" ]. + +Axiom ethereum_london_blocks_imports : + AreImported globals "ethereum.london.blocks" [ "Block"; "Header"; "Log"; "Receipt" ]. + +Axiom ethereum_london_bloom_imports : + AreImported globals "ethereum.london.bloom" [ "logs_bloom" ]. + +Axiom ethereum_london_fork_types_imports : + AreImported globals "ethereum.london.fork_types" [ "Address"; "Bloom"; "Root" ]. + +Axiom ethereum_london_state_imports : + AreImported globals "ethereum.london.state" [ "State"; "account_exists_and_is_empty"; "create_ether"; "destroy_account"; "get_account"; "increment_nonce"; "set_account_balance"; "state_root" ]. + +Axiom ethereum_london_transactions_imports : + AreImported globals "ethereum.london.transactions" [ "TX_ACCESS_LIST_ADDRESS_COST"; "TX_ACCESS_LIST_STORAGE_KEY_COST"; "TX_BASE_COST"; "TX_CREATE_COST"; "TX_DATA_COST_PER_NON_ZERO"; "TX_DATA_COST_PER_ZERO"; "AccessListTransaction"; "FeeMarketTransaction"; "LegacyTransaction"; "Transaction"; "decode_transaction"; "encode_transaction" ]. + +Axiom ethereum_london_trie_imports : + AreImported globals "ethereum.london.trie" [ "Trie"; "root"; "trie_set" ]. + +Axiom ethereum_london_utils_message_imports : + AreImported globals "ethereum.london.utils.message" [ "prepare_message" ]. + +Axiom ethereum_london_vm_interpreter_imports : + AreImported globals "ethereum.london.vm.interpreter" [ "process_message_call" ]. Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -298,7 +203,12 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := Hashes of the recent 256 blocks in order of increasing block number. " in let recent_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) in + M.slice (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| Constant.int 255 |), + Constant.None_, + Constant.None_ + |) in let _ := (* if *) M.if_then_else (| @@ -324,17 +234,26 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := )) |) in let recent_block_hashes := make_list [] in - For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_blocks" |) do - let prev_block_hash := - M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "block" |), + M.get_name (| globals, "recent_blocks" |), + ltac:(M.monadic ( + let prev_block_hash := + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in + let _ := M.call (| M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), make_list [ M.get_name (| globals, "prev_block_hash" |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let most_recent_block_hash := M.call (| M.get_name (| globals, "keccak256" |), @@ -342,7 +261,10 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), make_list [ - M.get_field (| M.get_subscript (| M.get_name (| globals, "recent_blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) + M.get_field (| M.get_subscript (| + M.get_name (| globals, "recent_blocks" |), + UnOp.sub (| Constant.int 1 |) + |), "header" |) ], make_dict [] |) @@ -386,7 +308,10 @@ Definition state_transition : Value.t -> Value.t -> M := Block to apply to `chain`. " in let parent_header := - M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) in + M.get_field (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| Constant.int 1 |) + |), "header" |) in let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ @@ -507,7 +432,12 @@ Definition state_transition : Value.t -> Value.t -> M := ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) + M.slice (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| Constant.int 255 |), + Constant.None_, + Constant.None_ + |) |) in M.pure Constant.None_ (* else *) @@ -1257,21 +1187,25 @@ Definition apply_body : Value.t -> Value.t -> M := (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) - For make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "tx" |) ] in M.call (| - M.get_name (| globals, "enumerate" |), - make_list [ - M.call (| - M.get_name (| globals, "map" |), - make_list [ - M.get_name (| globals, "decode_transaction" |); - M.get_name (| globals, "transactions" |) - ], - make_dict [] - |) - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "tx" |) ], + M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.call (| + M.get_name (| globals, "map" |), + make_list [ + M.get_name (| globals, "decode_transaction" |); + M.get_name (| globals, "transactions" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ M.get_name (| globals, "transactions_trie" |); @@ -1298,54 +1232,54 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.assign (| - make_tuple [ M.get_name (| globals, "sender_address" |); M.get_name (| globals, "effective_gas_price" |) ], - M.call (| - M.get_name (| globals, "check_transaction" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "base_fee_per_gas" |); - M.get_name (| globals, "gas_available" |); - M.get_name (| globals, "chain_id" |) - ], - make_dict [] - |) - |) in - let env := - M.call (| - M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), - make_list [], - make_dict [] - |) in - let _ := M.assign (| - make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |); M.get_name (| globals, "error" |) ], - M.call (| - M.get_name (| globals, "process_transaction" |), - make_list [ - M.get_name (| globals, "env" |); - M.get_name (| globals, "tx" |) - ], - make_dict [] - |) - |) in - let gas_available := BinOp.sub - M.get_name (| globals, "gas_used" |) - M.get_name (| globals, "gas_used" |) in - let receipt := - M.call (| - M.get_name (| globals, "make_receipt" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "error" |); - BinOp.sub (| - M.get_name (| globals, "block_gas_limit" |), - M.get_name (| globals, "gas_available" |) - |); - M.get_name (| globals, "logs" |) - ], - make_dict [] - |) in - let _ := M.call (| + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "sender_address" |); M.get_name (| globals, "effective_gas_price" |) ], + M.call (| + M.get_name (| globals, "check_transaction" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "base_fee_per_gas" |); + M.get_name (| globals, "gas_available" |); + M.get_name (| globals, "chain_id" |) + ], + make_dict [] + |) + |) in + let env := + M.call (| + M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |); M.get_name (| globals, "error" |) ], + M.call (| + M.get_name (| globals, "process_transaction" |), + make_list [ + M.get_name (| globals, "env" |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) in + let gas_available := BinOp.sub + M.get_name (| globals, "gas_used" |) + M.get_name (| globals, "gas_used" |) in + let receipt := + M.call (| + M.get_name (| globals, "make_receipt" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "error" |); + BinOp.sub (| + M.get_name (| globals, "block_gas_limit" |), + M.get_name (| globals, "gas_available" |) + |); + M.get_name (| globals, "logs" |) + ], + make_dict [] + |) in + let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ M.get_name (| globals, "receipts_trie" |); @@ -1366,10 +1300,15 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_logs := BinOp.add - M.get_name (| globals, "logs" |) - M.get_name (| globals, "logs" |) in - EndFor. + let block_logs := BinOp.add + M.get_name (| globals, "logs" |) + M.get_name (| globals, "logs" |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.call (| M.get_name (| globals, "pay_rewards" |), make_list [ @@ -1498,8 +1437,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "ommer" |), + M.get_name (| globals, "ommers" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ BoolOp.and (| @@ -1518,15 +1461,18 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_parent_header := - M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), BinOp.sub (| - UnOp.sub (| BinOp.sub (| - M.get_field (| M.get_name (| globals, "block_header" |), "number" |), - M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) |), - Constant.int 1 - |) |), "header" |) in - let _ := M.call (| + let ommer_parent_header := + M.get_field (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + BinOp.sub (| + UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) |), + Constant.int 1 + |) + |), "header" |) in + let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ M.get_name (| globals, "ommer" |); @@ -1534,7 +1480,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1584,33 +1535,54 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let recent_canonical_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| BinOp.add (| - M.get_name (| globals, "MAX_OMMER_DEPTH" |), - Constant.int 1 - |) |), Constant.None_ |) |) in + M.slice (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| BinOp.add (| + M.get_name (| globals, "MAX_OMMER_DEPTH" |), + Constant.int 1 + |) |), + Constant.None_, + Constant.None_ + |) in let recent_canonical_block_hashes := Constant.str "(* At expr: unsupported node type: SetComp *)" in (* At stmt: unsupported node type: AnnAssign *) - For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_canonical_blocks" |) do - let recent_ommers_hashes := + let _ := + M.for_ (| + M.get_name (| globals, "block" |), + M.get_name (| globals, "recent_canonical_blocks" |), + ltac:(M.monadic ( + let recent_ommers_hashes := + M.call (| + M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), + make_list [ + Constant.str "(* At expr: unsupported node type: SetComp *)" + ], + make_dict [] + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "ommer_index" |); M.get_name (| globals, "ommer" |) ], M.call (| - M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), - make_list [ - Constant.str "(* At expr: unsupported node type: SetComp *)" - ], - make_dict [] - |) in - EndFor. - For make_tuple [ M.get_name (| globals, "ommer_index" |); M.get_name (| globals, "ommer" |) ] in M.call (| - M.get_name (| globals, "enumerate" |), - make_list [ - M.get_name (| globals, "ommers" |) - ], - make_dict [] - |) do - let ommer_hash := - M.get_subscript (| M.get_name (| globals, "ommers_hashes" |), M.get_name (| globals, "ommer_index" |) |) in - let _ := M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let ommer_hash := + M.get_subscript (| + M.get_name (| globals, "ommers_hashes" |), + M.get_name (| globals, "ommer_index" |) + |) in + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_eq (| @@ -1621,7 +1593,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_in (| @@ -1632,7 +1604,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_in (| @@ -1643,12 +1615,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_age := - BinOp.sub (| - M.get_field (| M.get_name (| globals, "block_header" |), "number" |), - M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) in - let _ := M.call (| + let ommer_age := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) in + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ BoolOp.and (| @@ -1667,10 +1639,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.in (| + Compare.in_ (| M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), M.get_name (| globals, "recent_canonical_block_hashes" |) |); @@ -1678,7 +1650,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_eq (| @@ -1689,7 +1661,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_)). Definition pay_rewards : Value.t -> Value.t -> M := @@ -1746,30 +1723,34 @@ Definition pay_rewards : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do - let ommer_age := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - BinOp.sub (| - M.get_name (| globals, "block_number" |), - M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) - ], - make_dict [] - |) in - let ommer_miner_reward := - BinOp.floor_div (| - BinOp.mult (| - BinOp.sub (| - Constant.int 8, - M.get_name (| globals, "ommer_age" |) - |), - M.get_name (| globals, "BLOCK_REWARD" |) - |), - Constant.int 8 - |) in - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "ommer" |), + M.get_name (| globals, "ommers" |), + ltac:(M.monadic ( + let ommer_age := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "block_number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) + ], + make_dict [] + |) in + let ommer_miner_reward := + BinOp.floor_div (| + BinOp.mult (| + BinOp.sub (| + Constant.int 8, + M.get_name (| globals, "ommer_age" |) + |), + M.get_name (| globals, "BLOCK_REWARD" |) + |), + Constant.int 8 + |) in + let _ := M.call (| M.get_name (| globals, "create_ether" |), make_list [ M.get_name (| globals, "state" |); @@ -1778,7 +1759,12 @@ Definition pay_rewards : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_)). Definition process_transaction : Value.t -> Value.t -> M := @@ -1966,24 +1952,42 @@ Definition process_transaction : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - For make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "keys" |) ] in M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) do - let _ := M.call (| + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "keys" |) ], + M.get_field (| M.get_name (| globals, "tx" |), "access_list" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "preaccessed_addresses" |), "add" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] |) in - For M.get_name (| globals, "key" |) in M.get_name (| globals, "keys" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "keys" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "preaccessed_storage_keys" |), "add" |), make_list [ make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "key" |) ] ], make_dict [] |) in - EndFor. - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -2139,8 +2143,12 @@ Definition process_transaction : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "accounts_to_delete" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "output" |), "accounts_to_delete" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "destroy_account" |), make_list [ M.get_field (| M.get_name (| globals, "env" |), "state" |); @@ -2148,22 +2156,31 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. - For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "touched_accounts" |) do - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), - (* then *) + M.pure Constant.None_ + )), ltac:(M.monadic ( - let _ := M.call (| + M.pure Constant.None_ + )) + |) in + let _ := + M.for_ (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "output" |), "touched_accounts" |), + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "destroy_account" |), make_list [ M.get_field (| M.get_name (| globals, "env" |), "state" |); @@ -2171,12 +2188,17 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := M.return_ (| make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |); M.get_field (| M.get_name (| globals, "output" |), "error" |) ] |) in @@ -2264,28 +2286,37 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := " in let data_cost := Constant.int 0 in - For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "byte" |), - Constant.int 0 - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "byte" |), + M.get_field (| M.get_name (| globals, "tx" |), "data" |), ltac:(M.monadic ( - let data_cost := BinOp.add - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "byte" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let data_cost := BinOp.add - M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := (* if *) M.if_then_else (| @@ -2325,12 +2356,16 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - For make_tuple [ M.get_name (| globals, "_address" |); M.get_name (| globals, "keys" |) ] in M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) do - let access_list_cost := BinOp.add - M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) - M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) in - let access_list_cost := BinOp.add - BinOp.mult (| + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "_address" |); M.get_name (| globals, "keys" |) ], + M.get_field (| M.get_name (| globals, "tx" |), "access_list" |), + ltac:(M.monadic ( + let access_list_cost := BinOp.add + M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) + M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) in + let access_list_cost := BinOp.add + BinOp.mult (| M.call (| M.get_name (| globals, "len" |), make_list [ @@ -2340,7 +2375,7 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) |) - BinOp.mult (| + BinOp.mult (| M.call (| M.get_name (| globals, "len" |), make_list [ @@ -2350,7 +2385,12 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -2639,13 +2679,18 @@ Definition recover_sender : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "Address" |), make_list [ - M.get_subscript (| M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "public_key" |) - ], - make_dict [] - |), M.slice (| Constant.int 12, Constant.int 32 |) |) + M.slice (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), + Constant.int 12, + Constant.int 32, + Constant.None_ + |) ], make_dict [] |) diff --git a/CoqOfPython/ethereum/london/fork_types.v b/CoqOfPython/ethereum/london/fork_types.v index cc8e4a1..d6c2db5 100644 --- a/CoqOfPython/ethereum/london/fork_types.v +++ b/CoqOfPython/ethereum/london/fork_types.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.london.fork_types". Definition expr_1 : Value.t := Constant.str " @@ -17,33 +17,17 @@ Introduction Types re-used throughout the specification, which are specific to Ethereum. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes20 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes20". -Axiom ethereum_base_types_Bytes256 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes20"; "Bytes256"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) diff --git a/CoqOfPython/ethereum/london/state.v b/CoqOfPython/ethereum/london/state.v index ce927a1..e32ff35 100644 --- a/CoqOfPython/ethereum/london/state.v +++ b/CoqOfPython/ethereum/london/state.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.london.state". Definition expr_1 : Value.t := Constant.str " @@ -22,63 +22,23 @@ There is a distinction between an account that does not exist and `EMPTY_ACCOUNT`. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". -Axiom dataclasses_field : - IsGlobalAlias globals dataclasses.globals "field". - -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_modify : - IsGlobalAlias globals ethereum.base_types.globals "modify". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.london.fork_types. -Axiom ethereum_london_fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals ethereum.london.fork_types.globals "EMPTY_ACCOUNT". -Axiom ethereum_london_fork_types_Account : - IsGlobalAlias globals ethereum.london.fork_types.globals "Account". -Axiom ethereum_london_fork_types_Address : - IsGlobalAlias globals ethereum.london.fork_types.globals "Address". -Axiom ethereum_london_fork_types_Root : - IsGlobalAlias globals ethereum.london.fork_types.globals "Root". - -Require ethereum.london.trie. -Axiom ethereum_london_trie_EMPTY_TRIE_ROOT : - IsGlobalAlias globals ethereum.london.trie.globals "EMPTY_TRIE_ROOT". -Axiom ethereum_london_trie_Trie : - IsGlobalAlias globals ethereum.london.trie.globals "Trie". -Axiom ethereum_london_trie_copy_trie : - IsGlobalAlias globals ethereum.london.trie.globals "copy_trie". -Axiom ethereum_london_trie_root : - IsGlobalAlias globals ethereum.london.trie.globals "root". -Axiom ethereum_london_trie_trie_get : - IsGlobalAlias globals ethereum.london.trie.globals "trie_get". -Axiom ethereum_london_trie_trie_set : - IsGlobalAlias globals ethereum.london.trie.globals "trie_set". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass"; "field" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict"; "List"; "Optional"; "Set"; "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "modify" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_london_fork_types_imports : + AreImported globals "ethereum.london.fork_types" [ "EMPTY_ACCOUNT"; "Account"; "Address"; "Root" ]. + +Axiom ethereum_london_trie_imports : + AreImported globals "ethereum.london.trie" [ "EMPTY_TRIE_ROOT"; "Trie"; "copy_trie"; "root"; "trie_get"; "trie_set" ]. Definition State : Value.t := builtins.make_klass @@ -373,13 +333,16 @@ Definition destroy_storage : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -542,7 +505,10 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), + M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |), M.get_name (| globals, "trie" |) |) in M.pure Constant.None_ @@ -568,7 +534,10 @@ Definition set_storage : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -598,7 +567,7 @@ Definition storage_root : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), @@ -608,7 +577,10 @@ Definition storage_root : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "root" |), make_list [ - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) + M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |) ], make_dict [] |) @@ -1167,7 +1139,7 @@ Definition get_storage_original : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |) |), @@ -1189,7 +1161,10 @@ Definition get_storage_original : Value.t -> Value.t -> M := )) |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "_" |); M.get_name (| globals, "original_trie" |) ], - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), Constant.int 0 |) + M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), + Constant.int 0 + |) |) in let original_account_trie := M.call (| diff --git a/CoqOfPython/ethereum/london/transactions.v b/CoqOfPython/ethereum/london/transactions.v index 1e68477..a1c9195 100644 --- a/CoqOfPython/ethereum/london/transactions.v +++ b/CoqOfPython/ethereum/london/transactions.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.london.transactions". Definition expr_1 : Value.t := Constant.str " @@ -9,43 +9,23 @@ submitted to be executed. If Ethereum is viewed as a state machine, transactions are the events that move between states. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. -Require typing. -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". +Axiom typing_imports : + AreImported globals "typing" [ "Tuple"; "Union" ]. -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U64 : - IsGlobalAlias globals ethereum.base_types.globals "U64". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U64"; "U256"; "Bytes"; "Bytes0"; "Bytes32"; "Uint"; "slotted_freezable" ]. -Require ethereum.exceptions. -Axiom ethereum_exceptions_InvalidBlock : - IsGlobalAlias globals ethereum.exceptions.globals "InvalidBlock". +Axiom ethereum_exceptions_imports : + AreImported globals "ethereum.exceptions" [ "InvalidBlock" ]. -Require ethereum.london.fork_types. -Axiom ethereum_london_fork_types_Address : - IsGlobalAlias globals ethereum.london.fork_types.globals "Address". +Axiom ethereum_london_fork_types_imports : + AreImported globals "ethereum.london.fork_types" [ "Address" ]. Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( Constant.int 21000 @@ -102,7 +82,10 @@ Definition FeeMarketTransaction : Value.t := ]. Definition Transaction : Value.t := M.run ltac:(M.monadic ( - M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "AccessListTransaction" |); M.get_name (| globals, "FeeMarketTransaction" |) ] |) + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "AccessListTransaction" |); M.get_name (| globals, "FeeMarketTransaction" |) ] + |) )). Definition encode_transaction : Value.t -> Value.t -> M := @@ -186,7 +169,7 @@ Definition encode_transaction : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "Exception" |), make_list [ Constant.str "(* At expr: unsupported node type: JoinedStr *)" @@ -224,7 +207,10 @@ Definition decode_transaction : Value.t -> Value.t -> M := (* if *) M.if_then_else (| Compare.eq (| - M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), + M.get_subscript (| + M.get_name (| globals, "tx" |), + Constant.int 0 + |), Constant.int 1 |), (* then *) @@ -234,7 +220,12 @@ Definition decode_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), make_list [ M.get_name (| globals, "AccessListTransaction" |); - M.get_subscript (| M.get_name (| globals, "tx" |), M.slice (| Constant.int 1, Constant.None_ |) |) + M.slice (| + M.get_name (| globals, "tx" |), + Constant.int 1, + Constant.None_, + Constant.None_ + |) ], make_dict [] |) @@ -246,7 +237,10 @@ Definition decode_transaction : Value.t -> Value.t -> M := (* if *) M.if_then_else (| Compare.eq (| - M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), + M.get_subscript (| + M.get_name (| globals, "tx" |), + Constant.int 0 + |), Constant.int 2 |), (* then *) @@ -256,7 +250,12 @@ Definition decode_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), make_list [ M.get_name (| globals, "FeeMarketTransaction" |); - M.get_subscript (| M.get_name (| globals, "tx" |), M.slice (| Constant.int 1, Constant.None_ |) |) + M.slice (| + M.get_name (| globals, "tx" |), + Constant.int 1, + Constant.None_, + Constant.None_ + |) ], make_dict [] |) @@ -264,7 +263,7 @@ Definition decode_transaction : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidBlock" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "InvalidBlock" |)) |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/london/trie.v b/CoqOfPython/ethereum/london/trie.v index 6bf9385..08540f1 100644 --- a/CoqOfPython/ethereum/london/trie.v +++ b/CoqOfPython/ethereum/london/trie.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.london.trie". Definition expr_1 : Value.t := Constant.str " @@ -20,83 +20,38 @@ The state trie is the structure responsible for storing (* At top_level_stmt: unsupported node type: Import *) -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". -Axiom dataclasses_field : - IsGlobalAlias globals dataclasses.globals "field". - -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". -Axiom typing_Generic : - IsGlobalAlias globals typing.globals "Generic". -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Mapping : - IsGlobalAlias globals typing.globals "Mapping". -Axiom typing_MutableMapping : - IsGlobalAlias globals typing.globals "MutableMapping". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Sequence : - IsGlobalAlias globals typing.globals "Sequence". -Axiom typing_TypeVar : - IsGlobalAlias globals typing.globals "TypeVar". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". -Axiom typing_cast : - IsGlobalAlias globals typing.globals "cast". - -Require ethereum.berlin.__init__. -Axiom ethereum_berlin___init___trie : - IsGlobalAlias globals ethereum.berlin.__init__.globals "trie". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.utils.hexadecimal. -Axiom ethereum_utils_hexadecimal_hex_to_bytes : - IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.london.blocks. -Axiom ethereum_london_blocks_Receipt : - IsGlobalAlias globals ethereum.london.blocks.globals "Receipt". - -Require ethereum.london.fork_types. -Axiom ethereum_london_fork_types_Account : - IsGlobalAlias globals ethereum.london.fork_types.globals "Account". -Axiom ethereum_london_fork_types_Address : - IsGlobalAlias globals ethereum.london.fork_types.globals "Address". -Axiom ethereum_london_fork_types_Root : - IsGlobalAlias globals ethereum.london.fork_types.globals "Root". -Axiom ethereum_london_fork_types_encode_account : - IsGlobalAlias globals ethereum.london.fork_types.globals "encode_account". - -Require ethereum.london.transactions. -Axiom ethereum_london_transactions_LegacyTransaction : - IsGlobalAlias globals ethereum.london.transactions.globals "LegacyTransaction". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass"; "field" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict"; "Generic"; "List"; "Mapping"; "MutableMapping"; "Optional"; "Sequence"; "TypeVar"; "Union"; "cast" ]. + +Axiom ethereum_berlin_imports : + AreImported globals "ethereum.berlin" [ "trie" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_utils_hexadecimal_imports : + AreImported globals "ethereum.utils.hexadecimal" [ "hex_to_bytes" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_london_blocks_imports : + AreImported globals "ethereum.london.blocks" [ "Receipt" ]. + +Axiom ethereum_london_fork_types_imports : + AreImported globals "ethereum.london.fork_types" [ "Account"; "Address"; "Root"; "encode_account" ]. + +Axiom ethereum_london_transactions_imports : + AreImported globals "ethereum.london.transactions" [ "LegacyTransaction" ]. Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -115,7 +70,10 @@ Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( )). Definition Node : Value.t := M.run ltac:(M.monadic ( - M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Bytes" |); M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |); Constant.None_ ] |) + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Bytes" |); M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |); Constant.None_ ] + |) )). Definition K : Value.t := M.run ltac:(M.monadic ( @@ -133,11 +91,29 @@ Definition V : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "TypeVar" |), make_list [ Constant.str "V"; - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Account" |) |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Bytes" |) |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Account" |) + |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Bytes" |) + |); M.get_name (| globals, "Bytes" |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Bytes" |) ] |) |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Bytes" |) ] |) |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Bytes" |) ] + |) + |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Bytes" |) ] + |) + |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |) ], @@ -176,7 +152,10 @@ Definition BranchNode : Value.t := ]. Definition InternalNode : Value.t := M.run ltac:(M.monadic ( - M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LeafNode" |); M.get_name (| globals, "ExtensionNode" |); M.get_name (| globals, "BranchNode" |) ] |) + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "LeafNode" |); M.get_name (| globals, "ExtensionNode" |); M.get_name (| globals, "BranchNode" |) ] + |) )). Definition encode_internal_node : Value.t -> Value.t -> M := @@ -288,7 +267,7 @@ Definition encode_internal_node : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "(* At expr: unsupported node type: JoinedStr *)" @@ -528,13 +507,16 @@ Definition trie_set : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "key" |), M.get_field (| M.get_name (| globals, "trie" |), "_data" |) |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + M.get_name (| globals, "key" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -544,7 +526,10 @@ Definition trie_set : Value.t -> Value.t -> M := (* else *) )), ltac:(M.monadic ( let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), + M.get_subscript (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + M.get_name (| globals, "key" |) + |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_ @@ -589,51 +574,66 @@ Definition common_prefix_length : Value.t -> Value.t -> M := let _ := Constant.str " Find the longest common prefix of two sequences. " in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "a" |) - ], - make_dict [] - |) - ], - make_dict [] - |) do - let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| - M.get_name (| globals, "i" |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "b" |) - ], - make_dict [] - |) - |), - ltac:(M.monadic ( - Compare.not_eq (| - M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), - M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) - |) - )) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + ], + make_dict [] + |), ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "i" |) - |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_subscript (| + M.get_name (| globals, "a" |), + M.get_name (| globals, "i" |) + |), + M.get_subscript (| + M.get_name (| globals, "b" |), + M.get_name (| globals, "i" |) + |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "len" |), @@ -718,38 +718,53 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 0; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |); - Constant.int 2 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ BinOp.add (| BinOp.mult (| Constant.int 16, - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "i" |) + |) |), - M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) + |) |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -767,43 +782,61 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := Constant.int 1 |) |), - M.get_subscript (| M.get_name (| globals, "x" |), Constant.int 0 |) + M.get_subscript (| + M.get_name (| globals, "x" |), + Constant.int 0 + |) |) ], make_dict [] |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 1; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |); - Constant.int 2 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 1; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ BinOp.add (| BinOp.mult (| Constant.int 16, - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "i" |) + |) |), - M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) + |) |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -850,40 +883,55 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := ], make_dict [] |) in - For make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ] in M.call (| - M.get_name (| globals, "enumerate" |), - make_list [ - M.get_name (| globals, "bytes_" |) - ], - make_dict [] - |) do - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.mult (| - M.get_name (| globals, "byte_index" |), - Constant.int 2 - |) |), - BinOp.r_shift (| - BinOp.bit_and (| - M.get_name (| globals, "byte" |), - Constant.int 240 - |), - Constant.int 4 - |) - |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "byte_index" |), - Constant.int 2 - |), - Constant.int 1 - |) |), - BinOp.bit_and (| - M.get_name (| globals, "byte" |), - Constant.int 15 - |) - |) in - EndFor. + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ], + M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "bytes_" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "nibble_list" |), + BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |) + |), + BinOp.r_shift (| + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 240 + |), + Constant.int 4 + |) + |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "nibble_list" |), + BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |), + Constant.int 1 + |) + |), + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 15 + |) + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Bytes" |), @@ -916,65 +964,69 @@ Definition _prepare_trie : Value.t -> Value.t -> M := Object with keys mapped to nibble-byte form. " in (* At stmt: unsupported node type: AnnAssign *) - For make_tuple [ M.get_name (| globals, "preimage" |); M.get_name (| globals, "value" |) ] in M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "items" |), - make_list [], - make_dict [] - |) do - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "value" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "preimage" |); M.get_name (| globals, "value" |) ], + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "items" |), + make_list [], + make_dict [] + |), ltac:(M.monadic ( - let _ := M.assert (| Compare.is_not (| + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in - let address := - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in - let encoded_value := - M.call (| - M.get_name (| globals, "encode_node" |), - make_list [ - M.get_name (| globals, "value" |); + let address := M.call (| - M.get_name (| globals, "get_storage_root" |), + M.get_name (| globals, "Address" |), make_list [ - M.get_name (| globals, "address" |) + M.get_name (| globals, "preimage" |) ], make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let encoded_value := - M.call (| - M.get_name (| globals, "encode_node" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - )) |) in - let _ := M.call (| + |) in + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |); + M.call (| + M.get_name (| globals, "get_storage_root" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_eq (| @@ -986,38 +1038,46 @@ Definition _prepare_trie : Value.t -> Value.t -> M := make_dict [] |) in (* At stmt: unsupported node type: AnnAssign *) - let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "trie" |), "secured" |), - (* then *) - ltac:(M.monadic ( - let key := - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "trie" |), "secured" |), + (* then *) + ltac:(M.monadic ( + let key := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let key := + M.get_name (| globals, "preimage" |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "mapped" |), + M.call (| + M.get_name (| globals, "bytes_to_nibble_list" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |) + |), + M.get_name (| globals, "encoded_value" |) + |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let key := - M.get_name (| globals, "preimage" |) in + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "mapped" |), M.call (| - M.get_name (| globals, "bytes_to_nibble_list" |), - make_list [ - M.get_name (| globals, "key" |) - ], - make_dict [] - |) |), - M.get_name (| globals, "encoded_value" |) - |) in - EndFor. + )) + |) in let _ := M.return_ (| M.get_name (| globals, "mapped" |) |) in @@ -1210,8 +1270,16 @@ Definition patricialize : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "LeafNode" |), make_list [ - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |); - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) + M.slice (| + M.get_name (| globals, "arbitrary_key" |), + M.get_name (| globals, "level" |), + Constant.None_, + Constant.None_ + |); + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "arbitrary_key" |) + |) ], make_dict [] |) in @@ -1224,7 +1292,12 @@ Definition patricialize : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in let substring := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "arbitrary_key" |), + M.get_name (| globals, "level" |), + Constant.None_, + Constant.None_ + |) in let prefix_length := M.call (| M.get_name (| globals, "len" |), @@ -1233,39 +1306,53 @@ Definition patricialize : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do - let prefix_length := - M.call (| - M.get_name (| globals, "min" |), - make_list [ - M.get_name (| globals, "prefix_length" |); + let _ := + M.for_ (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "obj" |), + ltac:(M.monadic ( + let prefix_length := M.call (| - M.get_name (| globals, "common_prefix_length" |), + M.get_name (| globals, "min" |), make_list [ - M.get_name (| globals, "substring" |); - M.get_subscript (| M.get_name (| globals, "key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) + M.get_name (| globals, "prefix_length" |); + M.call (| + M.get_name (| globals, "common_prefix_length" |), + make_list [ + M.get_name (| globals, "substring" |); + M.slice (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "level" |), + Constant.None_, + Constant.None_ + |) + ], + make_dict [] + |) ], make_dict [] - |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "prefix_length" |), - Constant.int 0 - |), - (* then *) - ltac:(M.monadic ( - let _ := M.break (| |) in + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "prefix_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := (* if *) M.if_then_else (| @@ -1276,10 +1363,15 @@ Definition patricialize : Value.t -> Value.t -> M := (* then *) ltac:(M.monadic ( let prefix := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), BinOp.add (| + M.slice (| + M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |), - M.get_name (| globals, "prefix_length" |) - |) |) |) in + BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |), + Constant.None_ + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ExtensionNode" |), @@ -1312,70 +1404,106 @@ Definition patricialize : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) - For M.get_name (| globals, "_" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 16 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "_" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 16 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "branches" |), "append" |), make_list [ {} ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let value := Constant.bytes "" in - For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "key" |) - ], - make_dict [] - |), - M.get_name (| globals, "level" |) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "obj" |), ltac:(M.monadic ( let _ := (* if *) M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); - make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] - ], - make_dict [] + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |), + M.get_name (| globals, "level" |) |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "AssertionError" |)) |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "key" |) + |); + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "AssertionError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "key" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| + M.get_subscript (| + M.get_name (| globals, "branches" |), + M.get_subscript (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "level" |) + |) + |), + M.get_name (| globals, "key" |) + |), + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "key" |) + |) + |) in M.pure Constant.None_ )) |) in - let value := - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.assign (| - M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) - |) in + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "BranchNode" |), diff --git a/CoqOfPython/ethereum/london/utils/__init__.v b/CoqOfPython/ethereum/london/utils/__init__.v index 1baedea..3cb26eb 100644 --- a/CoqOfPython/ethereum/london/utils/__init__.v +++ b/CoqOfPython/ethereum/london/utils/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.london.utils.__init__". Definition expr_1 : Value.t := Constant.str " diff --git a/CoqOfPython/ethereum/london/utils/address.v b/CoqOfPython/ethereum/london/utils/address.v index 4affa6d..7008573 100644 --- a/CoqOfPython/ethereum/london/utils/address.v +++ b/CoqOfPython/ethereum/london/utils/address.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.london.utils.address". Definition expr_1 : Value.t := Constant.str " @@ -18,33 +18,23 @@ Address specific functions used in this london version of specification. ". -Require typing. -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". +Axiom typing_imports : + AreImported globals "typing" [ "Union" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes32"; "Uint" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_left_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. -Require ethereum.london.fork_types. -Axiom ethereum_london_fork_types_Address : - IsGlobalAlias globals ethereum.london.fork_types.globals "Address". +Axiom ethereum_london_fork_types_imports : + AreImported globals "ethereum.london.fork_types" [ "Address" ]. Definition to_address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -66,11 +56,16 @@ Definition to_address : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "Address" |), make_list [ - M.get_subscript (| M.call (| - M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), - make_list [], - make_dict [] - |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) + M.slice (| + M.call (| + M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), + UnOp.sub (| Constant.int 20 |), + Constant.None_, + Constant.None_ + |) ], make_dict [] |) @@ -114,7 +109,12 @@ Definition compute_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "computed_address" |), + UnOp.sub (| Constant.int 20 |), + Constant.None_, + Constant.None_ + |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -182,7 +182,12 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "computed_address" |), + UnOp.sub (| Constant.int 20 |), + Constant.None_, + Constant.None_ + |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/london/utils/hexadecimal.v b/CoqOfPython/ethereum/london/utils/hexadecimal.v index 0798912..bf7ef1e 100644 --- a/CoqOfPython/ethereum/london/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/london/utils/hexadecimal.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.london.utils.hexadecimal". Definition expr_1 : Value.t := Constant.str " @@ -18,17 +18,11 @@ Hexadecimal utility functions used in this specification, specific to London types. ". -Require ethereum.utils.hexadecimal. -Axiom ethereum_utils_hexadecimal_remove_hex_prefix : - IsGlobalAlias globals ethereum.utils.hexadecimal.globals "remove_hex_prefix". - -Require ethereum.london.fork_types. -Axiom ethereum_london_fork_types_Address : - IsGlobalAlias globals ethereum.london.fork_types.globals "Address". -Axiom ethereum_london_fork_types_Bloom : - IsGlobalAlias globals ethereum.london.fork_types.globals "Bloom". -Axiom ethereum_london_fork_types_Root : - IsGlobalAlias globals ethereum.london.fork_types.globals "Root". +Axiom ethereum_utils_hexadecimal_imports : + AreImported globals "ethereum.utils.hexadecimal" [ "remove_hex_prefix" ]. + +Axiom ethereum_london_fork_types_imports : + AreImported globals "ethereum.london.fork_types" [ "Address"; "Bloom"; "Root" ]. Definition hex_to_root : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/london/utils/message.v b/CoqOfPython/ethereum/london/utils/message.v index 0570427..ce358ab 100644 --- a/CoqOfPython/ethereum/london/utils/message.v +++ b/CoqOfPython/ethereum/london/utils/message.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.london.utils.message". Definition expr_1 : Value.t := Constant.str " @@ -18,49 +18,26 @@ Message specific functions used in this london version of specification. ". -Require typing. -Axiom typing_FrozenSet : - IsGlobalAlias globals typing.globals "FrozenSet". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". +Axiom typing_imports : + AreImported globals "typing" [ "FrozenSet"; "Optional"; "Tuple"; "Union" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Bytes32"; "Uint" ]. -Require ethereum.london.fork_types. -Axiom ethereum_london_fork_types_Address : - IsGlobalAlias globals ethereum.london.fork_types.globals "Address". +Axiom ethereum_london_fork_types_imports : + AreImported globals "ethereum.london.fork_types" [ "Address" ]. -Require ethereum.london.state. -Axiom ethereum_london_state_get_account : - IsGlobalAlias globals ethereum.london.state.globals "get_account". +Axiom ethereum_london_state_imports : + AreImported globals "ethereum.london.state" [ "get_account" ]. -Require ethereum.london.vm.__init__. -Axiom ethereum_london_vm___init___Environment : - IsGlobalAlias globals ethereum.london.vm.__init__.globals "Environment". -Axiom ethereum_london_vm___init___Message : - IsGlobalAlias globals ethereum.london.vm.__init__.globals "Message". +Axiom ethereum_london_vm_imports : + AreImported globals "ethereum.london.vm" [ "Environment"; "Message" ]. -Require ethereum.london.vm.precompiled_contracts.mapping. -Axiom ethereum_london_vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : - IsGlobalAlias globals ethereum.london.vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". +Axiom ethereum_london_vm_precompiled_contracts_mapping_imports : + AreImported globals "ethereum.london.vm.precompiled_contracts.mapping" [ "PRE_COMPILED_CONTRACTS" ]. -Require ethereum.london.utils.address. -Axiom ethereum_london_utils_address_compute_contract_address : - IsGlobalAlias globals ethereum.london.utils.address.globals "compute_contract_address". +Axiom ethereum_london_utils_address_imports : + AreImported globals "ethereum.london.utils.address" [ "compute_contract_address" ]. Definition prepare_message : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -198,7 +175,7 @@ Definition prepare_message : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "Target must be address or empty bytes" diff --git a/CoqOfPython/ethereum/london/vm/__init__.v b/CoqOfPython/ethereum/london/vm/__init__.v index 57f8791..908c463 100644 --- a/CoqOfPython/ethereum/london/vm/__init__.v +++ b/CoqOfPython/ethereum/london/vm/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.london.vm.__init__". Definition expr_1 : Value.t := Constant.str " @@ -18,57 +18,29 @@ The abstract computer which runs the code stored in an `.fork_types.Account`. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple"; "Union" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U64 : - IsGlobalAlias globals ethereum.base_types.globals "U64". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U64"; "U256"; "Bytes"; "Bytes0"; "Bytes32"; "Uint" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. -Require ethereum.london.blocks. -Axiom ethereum_london_blocks_Log : - IsGlobalAlias globals ethereum.london.blocks.globals "Log". +Axiom ethereum_london_blocks_imports : + AreImported globals "ethereum.london.blocks" [ "Log" ]. -Require ethereum.london.fork_types. -Axiom ethereum_london_fork_types_Address : - IsGlobalAlias globals ethereum.london.fork_types.globals "Address". +Axiom ethereum_london_fork_types_imports : + AreImported globals "ethereum.london.fork_types" [ "Address" ]. -Require ethereum.london.state. -Axiom ethereum_london_state_State : - IsGlobalAlias globals ethereum.london.state.globals "State". -Axiom ethereum_london_state_account_exists_and_is_empty : - IsGlobalAlias globals ethereum.london.state.globals "account_exists_and_is_empty". +Axiom ethereum_london_state_imports : + AreImported globals "ethereum.london.state" [ "State"; "account_exists_and_is_empty" ]. -Require ethereum.london.vm.precompiled_contracts.__init__. -Axiom ethereum_london_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : - IsGlobalAlias globals ethereum.london.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". +Axiom ethereum_london_vm_precompiled_contracts_imports : + AreImported globals "ethereum.london.vm.precompiled_contracts" [ "RIPEMD160_ADDRESS" ]. Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] @@ -203,7 +175,7 @@ Definition incorporate_child_on_error : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "RIPEMD160_ADDRESS" |), M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) |), diff --git a/CoqOfPython/ethereum/london/vm/exceptions.v b/CoqOfPython/ethereum/london/vm/exceptions.v index 1f4363d..93e464a 100644 --- a/CoqOfPython/ethereum/london/vm/exceptions.v +++ b/CoqOfPython/ethereum/london/vm/exceptions.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.london.vm.exceptions". Definition expr_1 : Value.t := Constant.str " @@ -17,9 +17,8 @@ Introduction Exceptions which cause the EVM to halt exceptionally. ". -Require ethereum.exceptions. -Axiom ethereum_exceptions_EthereumException : - IsGlobalAlias globals ethereum.exceptions.globals "EthereumException". +Axiom ethereum_exceptions_imports : + AreImported globals "ethereum.exceptions" [ "EthereumException" ]. Definition ExceptionalHalt : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/london/vm/gas.v b/CoqOfPython/ethereum/london/vm/gas.v index da5f5b4..bc67712 100644 --- a/CoqOfPython/ethereum/london/vm/gas.v +++ b/CoqOfPython/ethereum/london/vm/gas.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.london.vm.gas". Definition expr_1 : Value.t := Constant.str " @@ -17,39 +17,26 @@ Introduction EVM gas constants and calculators. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Tuple" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. -Require ethereum.trace. -Axiom ethereum_trace_GasAndRefund : - IsGlobalAlias globals ethereum.trace.globals "GasAndRefund". -Axiom ethereum_trace_evm_trace : - IsGlobalAlias globals ethereum.trace.globals "evm_trace". +Axiom ethereum_trace_imports : + AreImported globals "ethereum.trace" [ "GasAndRefund"; "evm_trace" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.london.vm.__init__. -Axiom ethereum_london_vm___init___Evm : - IsGlobalAlias globals ethereum.london.vm.__init__.globals "Evm". +Axiom ethereum_london_vm_imports : + AreImported globals "ethereum.london.vm" [ "Evm" ]. -Require ethereum.london.vm.exceptions. -Axiom ethereum_london_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.london.vm.exceptions.globals "OutOfGasError". +Axiom ethereum_london_vm_exceptions_imports : + AreImported globals "ethereum.london.vm.exceptions" [ "OutOfGasError" ]. Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -508,7 +495,7 @@ Definition charge_gas : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -625,105 +612,114 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := ], make_dict [] |) in - For make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ] in M.get_name (| globals, "extensions" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "size" |), - Constant.int 0 - |), - (* then *) + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ], + M.get_name (| globals, "extensions" |), ltac:(M.monadic ( - let _ := M.continue (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let before_size := - M.call (| - M.get_name (| globals, "ceil32" |), - make_list [ - M.get_name (| globals, "current_size" |) - ], - make_dict [] - |) in - let after_size := - M.call (| - M.get_name (| globals, "ceil32" |), - make_list [ - BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "size" |), + Constant.int 0 |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.lt_e (| - M.get_name (| globals, "after_size" |), - M.get_name (| globals, "before_size" |) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.continue (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let size_to_extend := BinOp.add - BinOp.sub (| + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let before_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "current_size" |) + ], + make_dict [] + |) in + let after_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let size_to_extend := BinOp.add + BinOp.sub (| M.get_name (| globals, "after_size" |), M.get_name (| globals, "before_size" |) |) - BinOp.sub (| + BinOp.sub (| M.get_name (| globals, "after_size" |), M.get_name (| globals, "before_size" |) |) in - let already_paid := - M.call (| - M.get_name (| globals, "calculate_memory_gas_cost" |), - make_list [ - M.get_name (| globals, "before_size" |) - ], - make_dict [] - |) in - let total_cost := - M.call (| - M.get_name (| globals, "calculate_memory_gas_cost" |), - make_list [ - M.get_name (| globals, "after_size" |) - ], - make_dict [] - |) in - let to_be_paid := BinOp.add - BinOp.sub (| + let already_paid := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "before_size" |) + ], + make_dict [] + |) in + let total_cost := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "after_size" |) + ], + make_dict [] + |) in + let to_be_paid := BinOp.add + BinOp.sub (| M.get_name (| globals, "total_cost" |), M.get_name (| globals, "already_paid" |) |) - BinOp.sub (| + BinOp.sub (| M.get_name (| globals, "total_cost" |), M.get_name (| globals, "already_paid" |) |) in - let current_size := - M.get_name (| globals, "after_size" |) in - EndFor. + let current_size := + M.get_name (| globals, "after_size" |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ExtendMemory" |), diff --git a/CoqOfPython/ethereum/london/vm/instructions/__init__.v b/CoqOfPython/ethereum/london/vm/instructions/__init__.v index a7f4e82..bf96acb 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/__init__.v +++ b/CoqOfPython/ethereum/london/vm/instructions/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.london.vm.instructions.__init__". Definition expr_1 : Value.t := Constant.str " @@ -20,59 +20,44 @@ implementations. (* At top_level_stmt: unsupported node type: Import *) -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict" ]. -Require ethereum.london.vm.instructions.__init__. -Axiom ethereum_london_vm_instructions___init___arithmetic : - IsGlobalAlias globals ethereum.london.vm.instructions.__init__.globals "arithmetic". +Axiom ethereum_london_vm_instructions_imports : + AreImported globals "ethereum.london.vm.instructions" [ "arithmetic" ]. -Require ethereum.london.vm.instructions.__init__. -Axiom ethereum_london_vm_instructions___init___bitwise : - IsGlobalAlias globals ethereum.london.vm.instructions.__init__.globals "bitwise". +Axiom ethereum_london_vm_instructions_imports : + AreImported globals "ethereum.london.vm.instructions" [ "bitwise" ]. -Require ethereum.london.vm.instructions.__init__. -Axiom ethereum_london_vm_instructions___init___block : - IsGlobalAlias globals ethereum.london.vm.instructions.__init__.globals "block". +Axiom ethereum_london_vm_instructions_imports : + AreImported globals "ethereum.london.vm.instructions" [ "block" ]. -Require ethereum.london.vm.instructions.__init__. -Axiom ethereum_london_vm_instructions___init___comparison : - IsGlobalAlias globals ethereum.london.vm.instructions.__init__.globals "comparison". +Axiom ethereum_london_vm_instructions_imports : + AreImported globals "ethereum.london.vm.instructions" [ "comparison" ]. -Require ethereum.london.vm.instructions.__init__. -Axiom ethereum_london_vm_instructions___init___control_flow : - IsGlobalAlias globals ethereum.london.vm.instructions.__init__.globals "control_flow". +Axiom ethereum_london_vm_instructions_imports : + AreImported globals "ethereum.london.vm.instructions" [ "control_flow" ]. -Require ethereum.london.vm.instructions.__init__. -Axiom ethereum_london_vm_instructions___init___environment : - IsGlobalAlias globals ethereum.london.vm.instructions.__init__.globals "environment". +Axiom ethereum_london_vm_instructions_imports : + AreImported globals "ethereum.london.vm.instructions" [ "environment" ]. -Require ethereum.london.vm.instructions.__init__. -Axiom ethereum_london_vm_instructions___init___keccak : - IsGlobalAlias globals ethereum.london.vm.instructions.__init__.globals "keccak". +Axiom ethereum_london_vm_instructions_imports : + AreImported globals "ethereum.london.vm.instructions" [ "keccak" ]. -Require ethereum.london.vm.instructions.__init__. -Axiom ethereum_london_vm_instructions___init___log : - IsGlobalAlias globals ethereum.london.vm.instructions.__init__.globals "log". +Axiom ethereum_london_vm_instructions_imports : + AreImported globals "ethereum.london.vm.instructions" [ "log" ]. -Require ethereum.london.vm.instructions.__init__. -Axiom ethereum_london_vm_instructions___init___memory : - IsGlobalAlias globals ethereum.london.vm.instructions.__init__.globals "memory". +Axiom ethereum_london_vm_instructions_imports : + AreImported globals "ethereum.london.vm.instructions" [ "memory" ]. -Require ethereum.london.vm.instructions.__init__. -Axiom ethereum_london_vm_instructions___init___stack : - IsGlobalAlias globals ethereum.london.vm.instructions.__init__.globals "stack". +Axiom ethereum_london_vm_instructions_imports : + AreImported globals "ethereum.london.vm.instructions" [ "stack" ]. -Require ethereum.london.vm.instructions.__init__. -Axiom ethereum_london_vm_instructions___init___storage : - IsGlobalAlias globals ethereum.london.vm.instructions.__init__.globals "storage". +Axiom ethereum_london_vm_instructions_imports : + AreImported globals "ethereum.london.vm.instructions" [ "storage" ]. -Require ethereum.london.vm.instructions.__init__. -Axiom ethereum_london_vm_instructions___init___system : - IsGlobalAlias globals ethereum.london.vm.instructions.__init__.globals "system". +Axiom ethereum_london_vm_instructions_imports : + AreImported globals "ethereum.london.vm.instructions" [ "system" ]. Definition Ops : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/london/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/london/vm/instructions/arithmetic.v index 73a3005..c37cf66 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/london/vm/instructions/arithmetic.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.london.vm.instructions.arithmetic". Definition expr_1 : Value.t := Constant.str " @@ -17,43 +17,20 @@ Introduction Implementations of the EVM Arithmetic instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U255_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U255_CEIL_VALUE". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_U256_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U255_CEIL_VALUE"; "U256"; "U256_CEIL_VALUE"; "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_get_sign : - IsGlobalAlias globals ethereum.utils.numeric.globals "get_sign". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "get_sign" ]. -Require ethereum.london.vm.__init__. -Axiom ethereum_london_vm___init___Evm : - IsGlobalAlias globals ethereum.london.vm.__init__.globals "Evm". +Axiom ethereum_london_vm_imports : + AreImported globals "ethereum.london.vm" [ "Evm" ]. -Require ethereum.london.vm.gas. -Axiom ethereum_london_vm_gas_GAS_EXPONENTIATION : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_EXPONENTIATION". -Axiom ethereum_london_vm_gas_GAS_EXPONENTIATION_PER_BYTE : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_EXPONENTIATION_PER_BYTE". -Axiom ethereum_london_vm_gas_GAS_LOW : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_LOW". -Axiom ethereum_london_vm_gas_GAS_MID : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_MID". -Axiom ethereum_london_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_london_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.london.vm.gas.globals "charge_gas". +Axiom ethereum_london_vm_gas_imports : + AreImported globals "ethereum.london.vm.gas" [ "GAS_EXPONENTIATION"; "GAS_EXPONENTIATION_PER_BYTE"; "GAS_LOW"; "GAS_MID"; "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.london.vm.stack. -Axiom ethereum_london_vm_stack_pop : - IsGlobalAlias globals ethereum.london.vm.stack.globals "pop". -Axiom ethereum_london_vm_stack_push : - IsGlobalAlias globals ethereum.london.vm.stack.globals "push". +Axiom ethereum_london_vm_stack_imports : + AreImported globals "ethereum.london.vm.stack" [ "pop"; "push" ]. Definition add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -1030,19 +1007,27 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let value_bytes := - M.get_subscript (| M.get_name (| globals, "value_bytes" |), M.slice (| BinOp.sub (| - Constant.int 31, - M.call (| - M.get_name (| globals, "int" |), - make_list [ - M.get_name (| globals, "byte_num" |) - ], - make_dict [] - |) - |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "value_bytes" |), + BinOp.sub (| + Constant.int 31, + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "byte_num" |) + ], + make_dict [] + |) + |), + Constant.None_, + Constant.None_ + |) in let sign_bit := BinOp.r_shift (| - M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), + M.get_subscript (| + M.get_name (| globals, "value_bytes" |), + Constant.int 0 + |), Constant.int 7 |) in let _ := diff --git a/CoqOfPython/ethereum/london/vm/instructions/bitwise.v b/CoqOfPython/ethereum/london/vm/instructions/bitwise.v index 867a104..5568bf4 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/london/vm/instructions/bitwise.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.london.vm.instructions.bitwise". Definition expr_1 : Value.t := Constant.str " @@ -17,27 +17,17 @@ Introduction Implementations of the EVM bitwise instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_U256_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "U256_CEIL_VALUE" ]. -Require ethereum.london.vm.__init__. -Axiom ethereum_london_vm___init___Evm : - IsGlobalAlias globals ethereum.london.vm.__init__.globals "Evm". +Axiom ethereum_london_vm_imports : + AreImported globals "ethereum.london.vm" [ "Evm" ]. -Require ethereum.london.vm.gas. -Axiom ethereum_london_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_london_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.london.vm.gas.globals "charge_gas". +Axiom ethereum_london_vm_gas_imports : + AreImported globals "ethereum.london.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.london.vm.stack. -Axiom ethereum_london_vm_stack_pop : - IsGlobalAlias globals ethereum.london.vm.stack.globals "pop". -Axiom ethereum_london_vm_stack_push : - IsGlobalAlias globals ethereum.london.vm.stack.globals "push". +Axiom ethereum_london_vm_stack_imports : + AreImported globals "ethereum.london.vm.stack" [ "pop"; "push" ]. Definition bitwise_and : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/london/vm/instructions/block.v b/CoqOfPython/ethereum/london/vm/instructions/block.v index b3ed746..2fdf889 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/block.v +++ b/CoqOfPython/ethereum/london/vm/instructions/block.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.london.vm.instructions.block". Definition expr_1 : Value.t := Constant.str " @@ -17,27 +17,17 @@ Introduction Implementations of the EVM block instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.london.vm.__init__. -Axiom ethereum_london_vm___init___Evm : - IsGlobalAlias globals ethereum.london.vm.__init__.globals "Evm". +Axiom ethereum_london_vm_imports : + AreImported globals "ethereum.london.vm" [ "Evm" ]. -Require ethereum.london.vm.gas. -Axiom ethereum_london_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_BASE". -Axiom ethereum_london_vm_gas_GAS_BLOCK_HASH : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_BLOCK_HASH". -Axiom ethereum_london_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.london.vm.gas.globals "charge_gas". +Axiom ethereum_london_vm_gas_imports : + AreImported globals "ethereum.london.vm.gas" [ "GAS_BASE"; "GAS_BLOCK_HASH"; "charge_gas" ]. -Require ethereum.london.vm.stack. -Axiom ethereum_london_vm_stack_pop : - IsGlobalAlias globals ethereum.london.vm.stack.globals "pop". -Axiom ethereum_london_vm_stack_push : - IsGlobalAlias globals ethereum.london.vm.stack.globals "push". +Axiom ethereum_london_vm_stack_imports : + AreImported globals "ethereum.london.vm.stack" [ "pop"; "push" ]. Definition block_hash : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -94,10 +84,13 @@ Definition block_hash : Value.t -> Value.t -> M := (* else *) )), ltac:(M.monadic ( let hash := - M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), - M.get_name (| globals, "block_number" |) - |) |) |) in + M.get_subscript (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), + UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + M.get_name (| globals, "block_number" |) + |) |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/london/vm/instructions/comparison.v b/CoqOfPython/ethereum/london/vm/instructions/comparison.v index 5eb7b4e..bc6ca77 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/london/vm/instructions/comparison.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.london.vm.instructions.comparison". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementations of the EVM Comparison instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.london.vm.__init__. -Axiom ethereum_london_vm___init___Evm : - IsGlobalAlias globals ethereum.london.vm.__init__.globals "Evm". +Axiom ethereum_london_vm_imports : + AreImported globals "ethereum.london.vm" [ "Evm" ]. -Require ethereum.london.vm.gas. -Axiom ethereum_london_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_london_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.london.vm.gas.globals "charge_gas". +Axiom ethereum_london_vm_gas_imports : + AreImported globals "ethereum.london.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.london.vm.stack. -Axiom ethereum_london_vm_stack_pop : - IsGlobalAlias globals ethereum.london.vm.stack.globals "pop". -Axiom ethereum_london_vm_stack_push : - IsGlobalAlias globals ethereum.london.vm.stack.globals "push". +Axiom ethereum_london_vm_stack_imports : + AreImported globals "ethereum.london.vm.stack" [ "pop"; "push" ]. Definition less_than : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/london/vm/instructions/control_flow.v b/CoqOfPython/ethereum/london/vm/instructions/control_flow.v index 5996ffc..25913ee 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/london/vm/instructions/control_flow.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.london.vm.instructions.control_flow". Definition expr_1 : Value.t := Constant.str " @@ -17,37 +17,20 @@ Introduction Implementations of the EVM control flow instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. -Require ethereum.london.vm.gas. -Axiom ethereum_london_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_BASE". -Axiom ethereum_london_vm_gas_GAS_HIGH : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_HIGH". -Axiom ethereum_london_vm_gas_GAS_JUMPDEST : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_JUMPDEST". -Axiom ethereum_london_vm_gas_GAS_MID : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_MID". -Axiom ethereum_london_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.london.vm.gas.globals "charge_gas". +Axiom ethereum_london_vm_gas_imports : + AreImported globals "ethereum.london.vm.gas" [ "GAS_BASE"; "GAS_HIGH"; "GAS_JUMPDEST"; "GAS_MID"; "charge_gas" ]. -Require ethereum.london.vm.__init__. -Axiom ethereum_london_vm___init___Evm : - IsGlobalAlias globals ethereum.london.vm.__init__.globals "Evm". +Axiom ethereum_london_vm_imports : + AreImported globals "ethereum.london.vm" [ "Evm" ]. -Require ethereum.london.vm.exceptions. -Axiom ethereum_london_vm_exceptions_InvalidJumpDestError : - IsGlobalAlias globals ethereum.london.vm.exceptions.globals "InvalidJumpDestError". +Axiom ethereum_london_vm_exceptions_imports : + AreImported globals "ethereum.london.vm.exceptions" [ "InvalidJumpDestError" ]. -Require ethereum.london.vm.stack. -Axiom ethereum_london_vm_stack_pop : - IsGlobalAlias globals ethereum.london.vm.stack.globals "pop". -Axiom ethereum_london_vm_stack_push : - IsGlobalAlias globals ethereum.london.vm.stack.globals "push". +Axiom ethereum_london_vm_stack_imports : + AreImported globals "ethereum.london.vm.stack" [ "pop"; "push" ]. Definition stop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -117,7 +100,7 @@ Definition jump : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "InvalidJumpDestError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -205,7 +188,7 @@ Definition jumpi : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "InvalidJumpDestError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/london/vm/instructions/environment.v b/CoqOfPython/ethereum/london/vm/instructions/environment.v index d570179..fe79dbd 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/london/vm/instructions/environment.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.london.vm.instructions.environment". Definition expr_1 : Value.t := Constant.str " @@ -17,75 +17,41 @@ Introduction Implementations of the EVM environment related instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". - -Require ethereum.london.fork_types. -Axiom ethereum_london_fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals ethereum.london.fork_types.globals "EMPTY_ACCOUNT". - -Require ethereum.london.state. -Axiom ethereum_london_state_get_account : - IsGlobalAlias globals ethereum.london.state.globals "get_account". - -Require ethereum.london.utils.address. -Axiom ethereum_london_utils_address_to_address : - IsGlobalAlias globals ethereum.london.utils.address.globals "to_address". - -Require ethereum.london.vm.memory. -Axiom ethereum_london_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.london.vm.memory.globals "buffer_read". -Axiom ethereum_london_vm_memory_memory_write : - IsGlobalAlias globals ethereum.london.vm.memory.globals "memory_write". - -Require ethereum.london.vm.__init__. -Axiom ethereum_london_vm___init___Evm : - IsGlobalAlias globals ethereum.london.vm.__init__.globals "Evm". - -Require ethereum.london.vm.exceptions. -Axiom ethereum_london_vm_exceptions_OutOfBoundsRead : - IsGlobalAlias globals ethereum.london.vm.exceptions.globals "OutOfBoundsRead". - -Require ethereum.london.vm.gas. -Axiom ethereum_london_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_BASE". -Axiom ethereum_london_vm_gas_GAS_COLD_ACCOUNT_ACCESS : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_COLD_ACCOUNT_ACCESS". -Axiom ethereum_london_vm_gas_GAS_COPY : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_COPY". -Axiom ethereum_london_vm_gas_GAS_FAST_STEP : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_FAST_STEP". -Axiom ethereum_london_vm_gas_GAS_RETURN_DATA_COPY : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_RETURN_DATA_COPY". -Axiom ethereum_london_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_london_vm_gas_GAS_WARM_ACCESS : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_WARM_ACCESS". -Axiom ethereum_london_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.london.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_london_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.london.vm.gas.globals "charge_gas". - -Require ethereum.london.vm.stack. -Axiom ethereum_london_vm_stack_pop : - IsGlobalAlias globals ethereum.london.vm.stack.globals "pop". -Axiom ethereum_london_vm_stack_push : - IsGlobalAlias globals ethereum.london.vm.stack.globals "push". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. + +Axiom ethereum_london_fork_types_imports : + AreImported globals "ethereum.london.fork_types" [ "EMPTY_ACCOUNT" ]. + +Axiom ethereum_london_state_imports : + AreImported globals "ethereum.london.state" [ "get_account" ]. + +Axiom ethereum_london_utils_address_imports : + AreImported globals "ethereum.london.utils.address" [ "to_address" ]. + +Axiom ethereum_london_vm_memory_imports : + AreImported globals "ethereum.london.vm.memory" [ "buffer_read"; "memory_write" ]. + +Axiom ethereum_london_vm_imports : + AreImported globals "ethereum.london.vm" [ "Evm" ]. + +Axiom ethereum_london_vm_exceptions_imports : + AreImported globals "ethereum.london.vm.exceptions" [ "OutOfBoundsRead" ]. + +Axiom ethereum_london_vm_gas_imports : + AreImported globals "ethereum.london.vm.gas" [ "GAS_BASE"; "GAS_COLD_ACCOUNT_ACCESS"; "GAS_COPY"; "GAS_FAST_STEP"; "GAS_RETURN_DATA_COPY"; "GAS_VERY_LOW"; "GAS_WARM_ACCESS"; "calculate_gas_extend_memory"; "charge_gas" ]. + +Axiom ethereum_london_vm_stack_imports : + AreImported globals "ethereum.london.vm.stack" [ "pop"; "push" ]. Definition address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -158,7 +124,7 @@ Definition balance : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -810,7 +776,7 @@ Definition extcodesize : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -966,7 +932,7 @@ Definition extcodecopy : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -1225,10 +1191,15 @@ Definition returndatacopy : Value.t -> Value.t -> M := |) |) in let value := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.slice (| M.get_name (| globals, "return_data_start_position" |), BinOp.add (| + M.slice (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |), - M.get_name (| globals, "size" |) - |) |) |) in + BinOp.add (| + M.get_name (| globals, "return_data_start_position" |), + M.get_name (| globals, "size" |) + |), + Constant.None_ + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -1272,7 +1243,7 @@ Definition extcodehash : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), diff --git a/CoqOfPython/ethereum/london/vm/instructions/keccak.v b/CoqOfPython/ethereum/london/vm/instructions/keccak.v index 7fd6db8..bfd364b 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/london/vm/instructions/keccak.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.london.vm.instructions.keccak". Definition expr_1 : Value.t := Constant.str " @@ -17,43 +17,26 @@ Introduction Implementations of the EVM keccak instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". - -Require ethereum.london.vm.__init__. -Axiom ethereum_london_vm___init___Evm : - IsGlobalAlias globals ethereum.london.vm.__init__.globals "Evm". - -Require ethereum.london.vm.gas. -Axiom ethereum_london_vm_gas_GAS_KECCAK256 : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_KECCAK256". -Axiom ethereum_london_vm_gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_KECCAK256_WORD". -Axiom ethereum_london_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.london.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_london_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.london.vm.gas.globals "charge_gas". - -Require ethereum.london.vm.memory. -Axiom ethereum_london_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.london.vm.memory.globals "memory_read_bytes". - -Require ethereum.london.vm.stack. -Axiom ethereum_london_vm_stack_pop : - IsGlobalAlias globals ethereum.london.vm.stack.globals "pop". -Axiom ethereum_london_vm_stack_push : - IsGlobalAlias globals ethereum.london.vm.stack.globals "push". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. + +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. + +Axiom ethereum_london_vm_imports : + AreImported globals "ethereum.london.vm" [ "Evm" ]. + +Axiom ethereum_london_vm_gas_imports : + AreImported globals "ethereum.london.vm.gas" [ "GAS_KECCAK256"; "GAS_KECCAK256_WORD"; "calculate_gas_extend_memory"; "charge_gas" ]. + +Axiom ethereum_london_vm_memory_imports : + AreImported globals "ethereum.london.vm.memory" [ "memory_read_bytes" ]. + +Axiom ethereum_london_vm_stack_imports : + AreImported globals "ethereum.london.vm.stack" [ "pop"; "push" ]. Definition keccak : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/london/vm/instructions/log.v b/CoqOfPython/ethereum/london/vm/instructions/log.v index 70e1f3d..ce64677 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/log.v +++ b/CoqOfPython/ethereum/london/vm/instructions/log.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.london.vm.instructions.log". Definition expr_1 : Value.t := Constant.str " @@ -17,49 +17,32 @@ Introduction Implementations of the EVM logging instructions. ". -Require functools. -Axiom functools_partial : - IsGlobalAlias globals functools.globals "partial". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.london.blocks. -Axiom ethereum_london_blocks_Log : - IsGlobalAlias globals ethereum.london.blocks.globals "Log". - -Require ethereum.london.vm.__init__. -Axiom ethereum_london_vm___init___Evm : - IsGlobalAlias globals ethereum.london.vm.__init__.globals "Evm". - -Require ethereum.london.vm.exceptions. -Axiom ethereum_london_vm_exceptions_WriteInStaticContext : - IsGlobalAlias globals ethereum.london.vm.exceptions.globals "WriteInStaticContext". - -Require ethereum.london.vm.gas. -Axiom ethereum_london_vm_gas_GAS_LOG : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_LOG". -Axiom ethereum_london_vm_gas_GAS_LOG_DATA : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_LOG_DATA". -Axiom ethereum_london_vm_gas_GAS_LOG_TOPIC : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_LOG_TOPIC". -Axiom ethereum_london_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.london.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_london_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.london.vm.gas.globals "charge_gas". - -Require ethereum.london.vm.memory. -Axiom ethereum_london_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.london.vm.memory.globals "memory_read_bytes". - -Require ethereum.london.vm.stack. -Axiom ethereum_london_vm_stack_pop : - IsGlobalAlias globals ethereum.london.vm.stack.globals "pop". +Axiom functools_imports : + AreImported globals "functools" [ "partial" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_london_blocks_imports : + AreImported globals "ethereum.london.blocks" [ "Log" ]. + +Axiom ethereum_london_vm_imports : + AreImported globals "ethereum.london.vm" [ "Evm" ]. + +Axiom ethereum_london_vm_exceptions_imports : + AreImported globals "ethereum.london.vm.exceptions" [ "WriteInStaticContext" ]. + +Axiom ethereum_london_vm_gas_imports : + AreImported globals "ethereum.london.vm.gas" [ "GAS_LOG"; "GAS_LOG_DATA"; "GAS_LOG_TOPIC"; "calculate_gas_extend_memory"; "charge_gas" ]. + +Axiom ethereum_london_vm_memory_imports : + AreImported globals "ethereum.london.vm.memory" [ "memory_read_bytes" ]. + +Axiom ethereum_london_vm_stack_imports : + AreImported globals "ethereum.london.vm.stack" [ "pop" ]. Definition log_n : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -96,33 +79,42 @@ Definition log_n : Value.t -> Value.t -> M := |) in let topics := make_list [] in - For M.get_name (| globals, "_" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - M.get_name (| globals, "num_topics" |) - ], - make_dict [] - |) do - let topic := + let _ := + M.for_ (| + M.get_name (| globals, "_" |), M.call (| - M.get_field (| M.call (| - M.get_name (| globals, "pop" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] - |), "to_be_bytes32" |), - make_list [], - make_dict [] - |) in - let _ := M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "num_topics" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let topic := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| M.get_field (| M.get_name (| globals, "topics" |), "append" |), make_list [ M.get_name (| globals, "topic" |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let extend_memory := M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), diff --git a/CoqOfPython/ethereum/london/vm/instructions/memory.v b/CoqOfPython/ethereum/london/vm/instructions/memory.v index e508c08..1dd7862 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/london/vm/instructions/memory.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.london.vm.instructions.memory". Definition expr_1 : Value.t := Constant.str " @@ -17,37 +17,20 @@ Introduction Implementations of the EVM Memory instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes" ]. -Require ethereum.london.vm.__init__. -Axiom ethereum_london_vm___init___Evm : - IsGlobalAlias globals ethereum.london.vm.__init__.globals "Evm". +Axiom ethereum_london_vm_imports : + AreImported globals "ethereum.london.vm" [ "Evm" ]. -Require ethereum.london.vm.gas. -Axiom ethereum_london_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_BASE". -Axiom ethereum_london_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_london_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.london.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_london_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.london.vm.gas.globals "charge_gas". +Axiom ethereum_london_vm_gas_imports : + AreImported globals "ethereum.london.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. -Require ethereum.london.vm.memory. -Axiom ethereum_london_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.london.vm.memory.globals "memory_read_bytes". -Axiom ethereum_london_vm_memory_memory_write : - IsGlobalAlias globals ethereum.london.vm.memory.globals "memory_write". +Axiom ethereum_london_vm_memory_imports : + AreImported globals "ethereum.london.vm.memory" [ "memory_read_bytes"; "memory_write" ]. -Require ethereum.london.vm.stack. -Axiom ethereum_london_vm_stack_pop : - IsGlobalAlias globals ethereum.london.vm.stack.globals "pop". -Axiom ethereum_london_vm_stack_push : - IsGlobalAlias globals ethereum.london.vm.stack.globals "push". +Axiom ethereum_london_vm_stack_imports : + AreImported globals "ethereum.london.vm.stack" [ "pop"; "push" ]. Definition mstore : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/london/vm/instructions/stack.v b/CoqOfPython/ethereum/london/vm/instructions/stack.v index ac9633a..42b7bec 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/london/vm/instructions/stack.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.london.vm.instructions.stack". Definition expr_1 : Value.t := Constant.str " @@ -17,39 +17,26 @@ Introduction Implementations of the EVM stack related instructions. ". -Require functools. -Axiom functools_partial : - IsGlobalAlias globals functools.globals "partial". +Axiom functools_imports : + AreImported globals "functools" [ "partial" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.london.vm.__init__. -Axiom ethereum_london_vm___init___Evm : - IsGlobalAlias globals ethereum.london.vm.__init__.globals "Evm". -Axiom ethereum_london_vm___init___stack : - IsGlobalAlias globals ethereum.london.vm.__init__.globals "stack". +Axiom ethereum_london_vm_imports : + AreImported globals "ethereum.london.vm" [ "Evm"; "stack" ]. -Require ethereum.london.vm.exceptions. -Axiom ethereum_london_vm_exceptions_StackUnderflowError : - IsGlobalAlias globals ethereum.london.vm.exceptions.globals "StackUnderflowError". +Axiom ethereum_london_vm_exceptions_imports : + AreImported globals "ethereum.london.vm.exceptions" [ "StackUnderflowError" ]. -Require ethereum.london.vm.gas. -Axiom ethereum_london_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_BASE". -Axiom ethereum_london_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_london_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.london.vm.gas.globals "charge_gas". +Axiom ethereum_london_vm_gas_imports : + AreImported globals "ethereum.london.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.london.vm.memory. -Axiom ethereum_london_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.london.vm.memory.globals "buffer_read". +Axiom ethereum_london_vm_memory_imports : + AreImported globals "ethereum.london.vm.memory" [ "buffer_read" ]. Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -203,19 +190,22 @@ Definition dup_n : Value.t -> Value.t -> M := make_dict [] |) in let data_to_duplicate := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] + BinOp.sub (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), + Constant.int 1 |), - Constant.int 1 - |), - M.get_name (| globals, "item_number" |) - |) |) in + M.get_name (| globals, "item_number" |) + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "stack" |), "push" |), make_list [ @@ -278,14 +268,26 @@ Definition swap_n : Value.t -> Value.t -> M := make_dict [] |) in let _ := M.assign (| - make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| - UnOp.sub (| Constant.int 1 |), - M.get_name (| globals, "item_number" |) - |) |) ], - make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| - UnOp.sub (| Constant.int 1 |), - M.get_name (| globals, "item_number" |) - |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |) ] + make_tuple [ M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + UnOp.sub (| Constant.int 1 |) + |); M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) + |) ], + make_tuple [ M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) + |); M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + UnOp.sub (| Constant.int 1 |) + |) ] |) in let _ := M.assign_op (| BinOp.add, diff --git a/CoqOfPython/ethereum/london/vm/instructions/storage.v b/CoqOfPython/ethereum/london/vm/instructions/storage.v index 8cfa118..2ca159e 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/london/vm/instructions/storage.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.london.vm.instructions.storage". Definition expr_1 : Value.t := Constant.str " @@ -17,53 +17,26 @@ Introduction Implementations of the EVM storage related instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.london.state. -Axiom ethereum_london_state_get_storage : - IsGlobalAlias globals ethereum.london.state.globals "get_storage". -Axiom ethereum_london_state_get_storage_original : - IsGlobalAlias globals ethereum.london.state.globals "get_storage_original". -Axiom ethereum_london_state_set_storage : - IsGlobalAlias globals ethereum.london.state.globals "set_storage". +Axiom ethereum_london_state_imports : + AreImported globals "ethereum.london.state" [ "get_storage"; "get_storage_original"; "set_storage" ]. -Require ethereum.london.vm.__init__. -Axiom ethereum_london_vm___init___Evm : - IsGlobalAlias globals ethereum.london.vm.__init__.globals "Evm". +Axiom ethereum_london_vm_imports : + AreImported globals "ethereum.london.vm" [ "Evm" ]. -Require ethereum.london.vm.exceptions. -Axiom ethereum_london_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.london.vm.exceptions.globals "OutOfGasError". -Axiom ethereum_london_vm_exceptions_WriteInStaticContext : - IsGlobalAlias globals ethereum.london.vm.exceptions.globals "WriteInStaticContext". +Axiom ethereum_london_vm_exceptions_imports : + AreImported globals "ethereum.london.vm.exceptions" [ "OutOfGasError"; "WriteInStaticContext" ]. -Require ethereum.london.vm.gas. -Axiom ethereum_london_vm_gas_GAS_CALL_STIPEND : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_CALL_STIPEND". -Axiom ethereum_london_vm_gas_GAS_COLD_SLOAD : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_COLD_SLOAD". -Axiom ethereum_london_vm_gas_GAS_STORAGE_CLEAR_REFUND : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_STORAGE_CLEAR_REFUND". -Axiom ethereum_london_vm_gas_GAS_STORAGE_SET : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_STORAGE_SET". -Axiom ethereum_london_vm_gas_GAS_STORAGE_UPDATE : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_STORAGE_UPDATE". -Axiom ethereum_london_vm_gas_GAS_WARM_ACCESS : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_WARM_ACCESS". -Axiom ethereum_london_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.london.vm.gas.globals "charge_gas". +Axiom ethereum_london_vm_gas_imports : + AreImported globals "ethereum.london.vm.gas" [ "GAS_CALL_STIPEND"; "GAS_COLD_SLOAD"; "GAS_STORAGE_CLEAR_REFUND"; "GAS_STORAGE_SET"; "GAS_STORAGE_UPDATE"; "GAS_WARM_ACCESS"; "charge_gas" ]. -Require ethereum.london.vm.stack. -Axiom ethereum_london_vm_stack_pop : - IsGlobalAlias globals ethereum.london.vm.stack.globals "pop". -Axiom ethereum_london_vm_stack_push : - IsGlobalAlias globals ethereum.london.vm.stack.globals "push". +Axiom ethereum_london_vm_stack_imports : + AreImported globals "ethereum.london.vm.stack" [ "pop"; "push" ]. Definition sload : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -93,7 +66,7 @@ Definition sload : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) |), diff --git a/CoqOfPython/ethereum/london/vm/instructions/system.v b/CoqOfPython/ethereum/london/vm/instructions/system.v index 41bdf93..6d68d15 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/system.v +++ b/CoqOfPython/ethereum/london/vm/instructions/system.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.london.vm.instructions.system". Definition expr_1 : Value.t := Constant.str " @@ -17,103 +17,38 @@ Introduction Implementations of the EVM system related instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.london.fork_types. -Axiom ethereum_london_fork_types_Address : - IsGlobalAlias globals ethereum.london.fork_types.globals "Address". +Axiom ethereum_london_fork_types_imports : + AreImported globals "ethereum.london.fork_types" [ "Address" ]. -Require ethereum.london.state. -Axiom ethereum_london_state_account_exists_and_is_empty : - IsGlobalAlias globals ethereum.london.state.globals "account_exists_and_is_empty". -Axiom ethereum_london_state_account_has_code_or_nonce : - IsGlobalAlias globals ethereum.london.state.globals "account_has_code_or_nonce". -Axiom ethereum_london_state_get_account : - IsGlobalAlias globals ethereum.london.state.globals "get_account". -Axiom ethereum_london_state_increment_nonce : - IsGlobalAlias globals ethereum.london.state.globals "increment_nonce". -Axiom ethereum_london_state_is_account_alive : - IsGlobalAlias globals ethereum.london.state.globals "is_account_alive". -Axiom ethereum_london_state_set_account_balance : - IsGlobalAlias globals ethereum.london.state.globals "set_account_balance". +Axiom ethereum_london_state_imports : + AreImported globals "ethereum.london.state" [ "account_exists_and_is_empty"; "account_has_code_or_nonce"; "get_account"; "increment_nonce"; "is_account_alive"; "set_account_balance" ]. -Require ethereum.london.utils.address. -Axiom ethereum_london_utils_address_compute_contract_address : - IsGlobalAlias globals ethereum.london.utils.address.globals "compute_contract_address". -Axiom ethereum_london_utils_address_compute_create2_contract_address : - IsGlobalAlias globals ethereum.london.utils.address.globals "compute_create2_contract_address". -Axiom ethereum_london_utils_address_to_address : - IsGlobalAlias globals ethereum.london.utils.address.globals "to_address". +Axiom ethereum_london_utils_address_imports : + AreImported globals "ethereum.london.utils.address" [ "compute_contract_address"; "compute_create2_contract_address"; "to_address" ]. -Require ethereum.london.vm.__init__. -Axiom ethereum_london_vm___init___Evm : - IsGlobalAlias globals ethereum.london.vm.__init__.globals "Evm". -Axiom ethereum_london_vm___init___Message : - IsGlobalAlias globals ethereum.london.vm.__init__.globals "Message". -Axiom ethereum_london_vm___init___incorporate_child_on_error : - IsGlobalAlias globals ethereum.london.vm.__init__.globals "incorporate_child_on_error". -Axiom ethereum_london_vm___init___incorporate_child_on_success : - IsGlobalAlias globals ethereum.london.vm.__init__.globals "incorporate_child_on_success". +Axiom ethereum_london_vm_imports : + AreImported globals "ethereum.london.vm" [ "Evm"; "Message"; "incorporate_child_on_error"; "incorporate_child_on_success" ]. -Require ethereum.london.vm.exceptions. -Axiom ethereum_london_vm_exceptions_Revert : - IsGlobalAlias globals ethereum.london.vm.exceptions.globals "Revert". -Axiom ethereum_london_vm_exceptions_WriteInStaticContext : - IsGlobalAlias globals ethereum.london.vm.exceptions.globals "WriteInStaticContext". +Axiom ethereum_london_vm_exceptions_imports : + AreImported globals "ethereum.london.vm.exceptions" [ "Revert"; "WriteInStaticContext" ]. -Require ethereum.london.vm.gas. -Axiom ethereum_london_vm_gas_GAS_CALL_VALUE : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_CALL_VALUE". -Axiom ethereum_london_vm_gas_GAS_COLD_ACCOUNT_ACCESS : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_COLD_ACCOUNT_ACCESS". -Axiom ethereum_london_vm_gas_GAS_CREATE : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_CREATE". -Axiom ethereum_london_vm_gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_KECCAK256_WORD". -Axiom ethereum_london_vm_gas_GAS_NEW_ACCOUNT : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_NEW_ACCOUNT". -Axiom ethereum_london_vm_gas_GAS_SELF_DESTRUCT : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_SELF_DESTRUCT". -Axiom ethereum_london_vm_gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". -Axiom ethereum_london_vm_gas_GAS_WARM_ACCESS : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_WARM_ACCESS". -Axiom ethereum_london_vm_gas_GAS_ZERO : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_ZERO". -Axiom ethereum_london_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.london.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_london_vm_gas_calculate_message_call_gas : - IsGlobalAlias globals ethereum.london.vm.gas.globals "calculate_message_call_gas". -Axiom ethereum_london_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.london.vm.gas.globals "charge_gas". -Axiom ethereum_london_vm_gas_max_message_call_gas : - IsGlobalAlias globals ethereum.london.vm.gas.globals "max_message_call_gas". +Axiom ethereum_london_vm_gas_imports : + AreImported globals "ethereum.london.vm.gas" [ "GAS_CALL_VALUE"; "GAS_COLD_ACCOUNT_ACCESS"; "GAS_CREATE"; "GAS_KECCAK256_WORD"; "GAS_NEW_ACCOUNT"; "GAS_SELF_DESTRUCT"; "GAS_SELF_DESTRUCT_NEW_ACCOUNT"; "GAS_WARM_ACCESS"; "GAS_ZERO"; "calculate_gas_extend_memory"; "calculate_message_call_gas"; "charge_gas"; "max_message_call_gas" ]. -Require ethereum.london.vm.memory. -Axiom ethereum_london_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.london.vm.memory.globals "memory_read_bytes". -Axiom ethereum_london_vm_memory_memory_write : - IsGlobalAlias globals ethereum.london.vm.memory.globals "memory_write". +Axiom ethereum_london_vm_memory_imports : + AreImported globals "ethereum.london.vm.memory" [ "memory_read_bytes"; "memory_write" ]. -Require ethereum.london.vm.stack. -Axiom ethereum_london_vm_stack_pop : - IsGlobalAlias globals ethereum.london.vm.stack.globals "pop". -Axiom ethereum_london_vm_stack_push : - IsGlobalAlias globals ethereum.london.vm.stack.globals "push". +Axiom ethereum_london_vm_stack_imports : + AreImported globals "ethereum.london.vm.stack" [ "pop"; "push" ]. Definition generic_create : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -866,7 +801,12 @@ Definition generic_call : Value.t -> Value.t -> M := make_list [ M.get_field (| M.get_name (| globals, "evm" |), "memory" |); M.get_name (| globals, "memory_output_start_position" |); - M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), M.slice (| Constant.None_, M.get_name (| globals, "actual_output_size" |) |) |) + M.slice (| + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), + Constant.None_, + M.get_name (| globals, "actual_output_size" |), + Constant.None_ + |) ], make_dict [] |) in @@ -966,7 +906,7 @@ Definition call : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "to" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -1272,7 +1212,7 @@ Definition callcode : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "code_address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -1700,7 +1640,7 @@ Definition delegatecall : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "code_address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -1876,7 +1816,7 @@ Definition staticcall : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "to" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -2046,6 +1986,6 @@ Definition revert : Value.t -> Value.t -> M := make_dict [] |) |) in - let _ := M.raise (| Some(M.get_name (| globals, "Revert" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "Revert" |)) |) in let _ := M.pass (| |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/london/vm/interpreter.v b/CoqOfPython/ethereum/london/vm/interpreter.v index 085e5dd..0fa190a 100644 --- a/CoqOfPython/ethereum/london/vm/interpreter.v +++ b/CoqOfPython/ethereum/london/vm/interpreter.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.london.vm.interpreter". Definition expr_1 : Value.t := Constant.str " @@ -17,127 +17,50 @@ Introduction A straightforward interpreter that executes EVM code. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_Iterable : - IsGlobalAlias globals typing.globals "Iterable". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.trace. -Axiom ethereum_trace_EvmStop : - IsGlobalAlias globals ethereum.trace.globals "EvmStop". -Axiom ethereum_trace_OpEnd : - IsGlobalAlias globals ethereum.trace.globals "OpEnd". -Axiom ethereum_trace_OpException : - IsGlobalAlias globals ethereum.trace.globals "OpException". -Axiom ethereum_trace_OpStart : - IsGlobalAlias globals ethereum.trace.globals "OpStart". -Axiom ethereum_trace_PrecompileEnd : - IsGlobalAlias globals ethereum.trace.globals "PrecompileEnd". -Axiom ethereum_trace_PrecompileStart : - IsGlobalAlias globals ethereum.trace.globals "PrecompileStart". -Axiom ethereum_trace_TransactionEnd : - IsGlobalAlias globals ethereum.trace.globals "TransactionEnd". -Axiom ethereum_trace_evm_trace : - IsGlobalAlias globals ethereum.trace.globals "evm_trace". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.london.blocks. -Axiom ethereum_london_blocks_Log : - IsGlobalAlias globals ethereum.london.blocks.globals "Log". - -Require ethereum.london.fork_types. -Axiom ethereum_london_fork_types_Address : - IsGlobalAlias globals ethereum.london.fork_types.globals "Address". - -Require ethereum.london.state. -Axiom ethereum_london_state_account_exists_and_is_empty : - IsGlobalAlias globals ethereum.london.state.globals "account_exists_and_is_empty". -Axiom ethereum_london_state_account_has_code_or_nonce : - IsGlobalAlias globals ethereum.london.state.globals "account_has_code_or_nonce". -Axiom ethereum_london_state_begin_transaction : - IsGlobalAlias globals ethereum.london.state.globals "begin_transaction". -Axiom ethereum_london_state_commit_transaction : - IsGlobalAlias globals ethereum.london.state.globals "commit_transaction". -Axiom ethereum_london_state_destroy_storage : - IsGlobalAlias globals ethereum.london.state.globals "destroy_storage". -Axiom ethereum_london_state_increment_nonce : - IsGlobalAlias globals ethereum.london.state.globals "increment_nonce". -Axiom ethereum_london_state_mark_account_created : - IsGlobalAlias globals ethereum.london.state.globals "mark_account_created". -Axiom ethereum_london_state_move_ether : - IsGlobalAlias globals ethereum.london.state.globals "move_ether". -Axiom ethereum_london_state_rollback_transaction : - IsGlobalAlias globals ethereum.london.state.globals "rollback_transaction". -Axiom ethereum_london_state_set_code : - IsGlobalAlias globals ethereum.london.state.globals "set_code". -Axiom ethereum_london_state_touch_account : - IsGlobalAlias globals ethereum.london.state.globals "touch_account". - -Require ethereum.london.vm.__init__. -Axiom ethereum_london_vm___init___Message : - IsGlobalAlias globals ethereum.london.vm.__init__.globals "Message". - -Require ethereum.london.vm.gas. -Axiom ethereum_london_vm_gas_GAS_CODE_DEPOSIT : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_CODE_DEPOSIT". -Axiom ethereum_london_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.london.vm.gas.globals "charge_gas". - -Require ethereum.london.vm.precompiled_contracts.mapping. -Axiom ethereum_london_vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : - IsGlobalAlias globals ethereum.london.vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". - -Require ethereum.london.vm.__init__. -Axiom ethereum_london_vm___init___Environment : - IsGlobalAlias globals ethereum.london.vm.__init__.globals "Environment". -Axiom ethereum_london_vm___init___Evm : - IsGlobalAlias globals ethereum.london.vm.__init__.globals "Evm". - -Require ethereum.london.vm.exceptions. -Axiom ethereum_london_vm_exceptions_AddressCollision : - IsGlobalAlias globals ethereum.london.vm.exceptions.globals "AddressCollision". -Axiom ethereum_london_vm_exceptions_ExceptionalHalt : - IsGlobalAlias globals ethereum.london.vm.exceptions.globals "ExceptionalHalt". -Axiom ethereum_london_vm_exceptions_InvalidContractPrefix : - IsGlobalAlias globals ethereum.london.vm.exceptions.globals "InvalidContractPrefix". -Axiom ethereum_london_vm_exceptions_InvalidOpcode : - IsGlobalAlias globals ethereum.london.vm.exceptions.globals "InvalidOpcode". -Axiom ethereum_london_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.london.vm.exceptions.globals "OutOfGasError". -Axiom ethereum_london_vm_exceptions_Revert : - IsGlobalAlias globals ethereum.london.vm.exceptions.globals "Revert". -Axiom ethereum_london_vm_exceptions_StackDepthLimitError : - IsGlobalAlias globals ethereum.london.vm.exceptions.globals "StackDepthLimitError". - -Require ethereum.london.vm.instructions.__init__. -Axiom ethereum_london_vm_instructions___init___Ops : - IsGlobalAlias globals ethereum.london.vm.instructions.__init__.globals "Ops". -Axiom ethereum_london_vm_instructions___init___op_implementation : - IsGlobalAlias globals ethereum.london.vm.instructions.__init__.globals "op_implementation". - -Require ethereum.london.vm.runtime. -Axiom ethereum_london_vm_runtime_get_valid_jump_destinations : - IsGlobalAlias globals ethereum.london.vm.runtime.globals "get_valid_jump_destinations". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Iterable"; "Optional"; "Set"; "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. + +Axiom ethereum_trace_imports : + AreImported globals "ethereum.trace" [ "EvmStop"; "OpEnd"; "OpException"; "OpStart"; "PrecompileEnd"; "PrecompileStart"; "TransactionEnd"; "evm_trace" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_london_blocks_imports : + AreImported globals "ethereum.london.blocks" [ "Log" ]. + +Axiom ethereum_london_fork_types_imports : + AreImported globals "ethereum.london.fork_types" [ "Address" ]. + +Axiom ethereum_london_state_imports : + AreImported globals "ethereum.london.state" [ "account_exists_and_is_empty"; "account_has_code_or_nonce"; "begin_transaction"; "commit_transaction"; "destroy_storage"; "increment_nonce"; "mark_account_created"; "move_ether"; "rollback_transaction"; "set_code"; "touch_account" ]. + +Axiom ethereum_london_vm_imports : + AreImported globals "ethereum.london.vm" [ "Message" ]. + +Axiom ethereum_london_vm_gas_imports : + AreImported globals "ethereum.london.vm.gas" [ "GAS_CODE_DEPOSIT"; "charge_gas" ]. + +Axiom ethereum_london_vm_precompiled_contracts_mapping_imports : + AreImported globals "ethereum.london.vm.precompiled_contracts.mapping" [ "PRE_COMPILED_CONTRACTS" ]. + +Axiom ethereum_london_vm_imports : + AreImported globals "ethereum.london.vm" [ "Environment"; "Evm" ]. + +Axiom ethereum_london_vm_exceptions_imports : + AreImported globals "ethereum.london.vm.exceptions" [ "AddressCollision"; "ExceptionalHalt"; "InvalidContractPrefix"; "InvalidOpcode"; "OutOfGasError"; "Revert"; "StackDepthLimitError" ]. + +Axiom ethereum_london_vm_instructions_imports : + AreImported globals "ethereum.london.vm.instructions" [ "Ops"; "op_implementation" ]. + +Axiom ethereum_london_vm_runtime_imports : + AreImported globals "ethereum.london.vm.runtime" [ "get_valid_jump_destinations" ]. Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -518,7 +441,7 @@ Definition process_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "StackDepthLimitError" |), make_list [ Constant.str "Stack depth limit reached" diff --git a/CoqOfPython/ethereum/london/vm/memory.v b/CoqOfPython/ethereum/london/vm/memory.v index 08d2290..197e545 100644 --- a/CoqOfPython/ethereum/london/vm/memory.v +++ b/CoqOfPython/ethereum/london/vm/memory.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.london.vm.memory". Definition expr_1 : Value.t := Constant.str " @@ -17,17 +17,11 @@ Introduction EVM memory operations. ". -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_right_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "right_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "right_pad_zero_bytes" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. Definition memory_write : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,22 +39,27 @@ Definition memory_write : Value.t -> Value.t -> M := Data to write to memory. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + M.slice (| + M.get_name (| globals, "memory" |), + M.get_name (| globals, "start_position" |), + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) - |) |) |), + Constant.None_ + |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_)). @@ -86,22 +85,27 @@ Definition memory_read_bytes : Value.t -> Value.t -> M := Data read from memory. " in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + M.slice (| + M.get_name (| globals, "memory" |), + M.get_name (| globals, "start_position" |), + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |) |) + Constant.None_ + |) |) in M.pure Constant.None_)). @@ -129,22 +133,27 @@ Definition buffer_read : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "right_pad_zero_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "buffer" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + M.slice (| + M.get_name (| globals, "buffer" |), + M.get_name (| globals, "start_position" |), + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |) |); + Constant.None_ + |); M.get_name (| globals, "size" |) ], make_dict [] diff --git a/CoqOfPython/ethereum/london/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/london/vm/precompiled_contracts/__init__.v index 37fddad..b034b9c 100644 --- a/CoqOfPython/ethereum/london/vm/precompiled_contracts/__init__.v +++ b/CoqOfPython/ethereum/london/vm/precompiled_contracts/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.london.vm.precompiled_contracts.__init__". Definition expr_1 : Value.t := Constant.str " @@ -18,9 +18,8 @@ Addresses of precompiled contracts and mappings to their implementations. ". -Require ethereum.london.utils.hexadecimal. -Axiom ethereum_london_utils_hexadecimal_hex_to_address : - IsGlobalAlias globals ethereum.london.utils.hexadecimal.globals "hex_to_address". +Axiom ethereum_london_utils_hexadecimal_imports : + AreImported globals "ethereum.london.utils.hexadecimal" [ "hex_to_address" ]. Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS"; Constant.str "MODEXP_ADDRESS"; Constant.str "ALT_BN128_ADD_ADDRESS"; Constant.str "ALT_BN128_MUL_ADDRESS"; Constant.str "ALT_BN128_PAIRING_CHECK_ADDRESS"; Constant.str "BLAKE2F_ADDRESS" ] diff --git a/CoqOfPython/ethereum/london/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/london/vm/precompiled_contracts/alt_bn128.v index 43f2cec..37bf4a5 100644 --- a/CoqOfPython/ethereum/london/vm/precompiled_contracts/alt_bn128.v +++ b/CoqOfPython/ethereum/london/vm/precompiled_contracts/alt_bn128.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.london.vm.precompiled_contracts.alt_bn128". Definition expr_1 : Value.t := Constant.str " @@ -17,49 +17,26 @@ Introduction Implementation of the ALT_BN128 precompiled contracts. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. -Require ethereum.crypto.alt_bn128. -Axiom ethereum_crypto_alt_bn128_ALT_BN128_CURVE_ORDER : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "ALT_BN128_CURVE_ORDER". -Axiom ethereum_crypto_alt_bn128_ALT_BN128_PRIME : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "ALT_BN128_PRIME". -Axiom ethereum_crypto_alt_bn128_BNF : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF". -Axiom ethereum_crypto_alt_bn128_BNF2 : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF2". -Axiom ethereum_crypto_alt_bn128_BNF12 : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF12". -Axiom ethereum_crypto_alt_bn128_BNP : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNP". -Axiom ethereum_crypto_alt_bn128_BNP2 : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNP2". -Axiom ethereum_crypto_alt_bn128_pairing : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "pairing". +Axiom ethereum_crypto_alt_bn128_imports : + AreImported globals "ethereum.crypto.alt_bn128" [ "ALT_BN128_CURVE_ORDER"; "ALT_BN128_PRIME"; "BNF"; "BNF2"; "BNF12"; "BNP"; "BNP2"; "pairing" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.london.vm.__init__. -Axiom ethereum_london_vm___init___Evm : - IsGlobalAlias globals ethereum.london.vm.__init__.globals "Evm". +Axiom ethereum_london_vm_imports : + AreImported globals "ethereum.london.vm" [ "Evm" ]. -Require ethereum.london.vm.gas. -Axiom ethereum_london_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.london.vm.gas.globals "charge_gas". +Axiom ethereum_london_vm_gas_imports : + AreImported globals "ethereum.london.vm.gas" [ "charge_gas" ]. -Require ethereum.london.vm.memory. -Axiom ethereum_london_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.london.vm.memory.globals "buffer_read". +Axiom ethereum_london_vm_memory_imports : + AreImported globals "ethereum.london.vm.memory" [ "buffer_read" ]. -Require ethereum.london.vm.exceptions. -Axiom ethereum_london_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.london.vm.exceptions.globals "OutOfGasError". +Axiom ethereum_london_vm_exceptions_imports : + AreImported globals "ethereum.london.vm.exceptions" [ "OutOfGasError" ]. Definition alt_bn128_add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -208,23 +185,32 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ] do - let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| - M.get_name (| globals, "i" |), - M.get_name (| globals, "ALT_BN128_PRIME" |) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ], ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in (* At stmt: unsupported node type: Try *) let p := BinOp.add (| @@ -363,23 +349,32 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ] do - let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| - M.get_name (| globals, "i" |), - M.get_name (| globals, "ALT_BN128_PRIME" |) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ], ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in (* At stmt: unsupported node type: Try *) let p := M.call (| @@ -466,7 +461,7 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -480,76 +475,89 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - BinOp.floor_div (| + let _ := + M.for_ (| + M.get_name (| globals, "i" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "data" |) - ], - make_dict [] - |), - Constant.int 192 - |) - ], - make_dict [] - |) do - let values := - make_list [] in - For M.get_name (| globals, "j" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 6 - ], - make_dict [] - |) do - let value := + M.get_name (| globals, "range" |), + make_list [ + BinOp.floor_div (| M.call (| - M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + M.get_name (| globals, "len" |), make_list [ - M.get_subscript (| M.get_name (| globals, "data" |), M.slice (| BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "i" |), - Constant.int 192 - |), - BinOp.mult (| - Constant.int 32, - M.get_name (| globals, "j" |) - |) - |), BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "i" |), - Constant.int 192 - |), - BinOp.mult (| - Constant.int 32, - BinOp.add (| - M.get_name (| globals, "j" |), - Constant.int 1 - |) - |) - |) |) |) + M.get_name (| globals, "data" |) ], make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| - M.get_name (| globals, "value" |), - M.get_name (| globals, "ALT_BN128_PRIME" |) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let _ := M.call (| + |), + Constant.int 192 + |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let values := + make_list [] in + let _ := + M.for_ (| + M.get_name (| globals, "j" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 6 + ], + make_dict [] + |), + ltac:(M.monadic ( + let value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.slice (| + M.get_name (| globals, "data" |), + BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + M.get_name (| globals, "j" |) + |) + |), + BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "j" |), + Constant.int 1 + |) + |) + |), + Constant.None_ + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| M.get_field (| M.get_name (| globals, "values" |), "append" |), make_list [ M.call (| @@ -562,9 +570,14 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in (* At stmt: unsupported node type: Try *) - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.eq (| @@ -585,7 +598,7 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.eq (| @@ -606,49 +619,54 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| - M.get_name (| globals, "p" |), - M.call (| - M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) - |), + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "p" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "q" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |) + )) + |), + (* then *) ltac:(M.monadic ( - Compare.not_eq (| - M.get_name (| globals, "q" |), - M.call (| - M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) - |) - )) - |), - (* then *) - ltac:(M.monadic ( - let result := - BinOp.mult (| - M.get_name (| globals, "result" |), - M.call (| - M.get_name (| globals, "pairing" |), - make_list [ - M.get_name (| globals, "q" |); - M.get_name (| globals, "p" |) - ], - make_dict [] - |) - |) in + let result := + BinOp.mult (| + M.get_name (| globals, "result" |), + M.call (| + M.get_name (| globals, "pairing" |), + make_list [ + M.get_name (| globals, "q" |); + M.get_name (| globals, "p" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := (* if *) M.if_then_else (| diff --git a/CoqOfPython/ethereum/london/vm/precompiled_contracts/blake2f.v b/CoqOfPython/ethereum/london/vm/precompiled_contracts/blake2f.v index 7a133d3..9673476 100644 --- a/CoqOfPython/ethereum/london/vm/precompiled_contracts/blake2f.v +++ b/CoqOfPython/ethereum/london/vm/precompiled_contracts/blake2f.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.london.vm.precompiled_contracts.blake2f". Definition expr_1 : Value.t := Constant.str " @@ -17,27 +17,20 @@ Introduction Implementation of the `Blake2` precompiled contract. ". -Require ethereum.crypto.blake2. -Axiom ethereum_crypto_blake2_Blake2b : - IsGlobalAlias globals ethereum.crypto.blake2.globals "Blake2b". +Axiom ethereum_crypto_blake2_imports : + AreImported globals "ethereum.crypto.blake2" [ "Blake2b" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.london.vm.__init__. -Axiom ethereum_london_vm___init___Evm : - IsGlobalAlias globals ethereum.london.vm.__init__.globals "Evm". +Axiom ethereum_london_vm_imports : + AreImported globals "ethereum.london.vm" [ "Evm" ]. -Require ethereum.london.vm.gas. -Axiom ethereum_london_vm_gas_GAS_BLAKE2_PER_ROUND : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_BLAKE2_PER_ROUND". -Axiom ethereum_london_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.london.vm.gas.globals "charge_gas". +Axiom ethereum_london_vm_gas_imports : + AreImported globals "ethereum.london.vm.gas" [ "GAS_BLAKE2_PER_ROUND"; "charge_gas" ]. -Require ethereum.london.vm.exceptions. -Axiom ethereum_london_vm_exceptions_InvalidParameter : - IsGlobalAlias globals ethereum.london.vm.exceptions.globals "InvalidParameter". +Axiom ethereum_london_vm_exceptions_imports : + AreImported globals "ethereum.london.vm.exceptions" [ "InvalidParameter" ]. Definition blake2f : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -99,7 +92,7 @@ Definition blake2f : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.in (| + Compare.in_ (| M.get_name (| globals, "f" |), make_list [ Constant.int 0; diff --git a/CoqOfPython/ethereum/london/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/london/vm/precompiled_contracts/ecrecover.v index e9ca1bc..3b1bf86 100644 --- a/CoqOfPython/ethereum/london/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/london/vm/precompiled_contracts/ecrecover.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.london.vm.precompiled_contracts.ecrecover". Definition expr_1 : Value.t := Constant.str " @@ -17,39 +17,26 @@ Introduction Implementation of the ECRECOVER precompiled contract. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.crypto.elliptic_curve. -Axiom ethereum_crypto_elliptic_curve_SECP256K1N : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". -Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". +Axiom ethereum_crypto_elliptic_curve_imports : + AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_left_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. -Require ethereum.london.vm.__init__. -Axiom ethereum_london_vm___init___Evm : - IsGlobalAlias globals ethereum.london.vm.__init__.globals "Evm". +Axiom ethereum_london_vm_imports : + AreImported globals "ethereum.london.vm" [ "Evm" ]. -Require ethereum.london.vm.gas. -Axiom ethereum_london_vm_gas_GAS_ECRECOVER : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_ECRECOVER". -Axiom ethereum_london_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.london.vm.gas.globals "charge_gas". +Axiom ethereum_london_vm_gas_imports : + AreImported globals "ethereum.london.vm.gas" [ "GAS_ECRECOVER"; "charge_gas" ]. -Require ethereum.london.vm.memory. -Axiom ethereum_london_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.london.vm.memory.globals "buffer_read". +Axiom ethereum_london_vm_memory_imports : + AreImported globals "ethereum.london.vm.memory" [ "buffer_read" ]. Definition ecrecover : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -264,13 +251,18 @@ Definition ecrecover : Value.t -> Value.t -> M := )) |) in (* At stmt: unsupported node type: Try *) let address := - M.get_subscript (| M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "public_key" |) - ], - make_dict [] - |), M.slice (| Constant.int 12, Constant.int 32 |) |) in + M.slice (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), + Constant.int 12, + Constant.int 32, + Constant.None_ + |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/london/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/london/vm/precompiled_contracts/identity.v index 31f2698..df82aa3 100644 --- a/CoqOfPython/ethereum/london/vm/precompiled_contracts/identity.v +++ b/CoqOfPython/ethereum/london/vm/precompiled_contracts/identity.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.london.vm.precompiled_contracts.identity". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementation of the `IDENTITY` precompiled contract. ". -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.london.vm.__init__. -Axiom ethereum_london_vm___init___Evm : - IsGlobalAlias globals ethereum.london.vm.__init__.globals "Evm". +Axiom ethereum_london_vm_imports : + AreImported globals "ethereum.london.vm" [ "Evm" ]. -Require ethereum.london.vm.gas. -Axiom ethereum_london_vm_gas_GAS_IDENTITY : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_IDENTITY". -Axiom ethereum_london_vm_gas_GAS_IDENTITY_WORD : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_IDENTITY_WORD". -Axiom ethereum_london_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.london.vm.gas.globals "charge_gas". +Axiom ethereum_london_vm_gas_imports : + AreImported globals "ethereum.london.vm.gas" [ "GAS_IDENTITY"; "GAS_IDENTITY_WORD"; "charge_gas" ]. Definition identity : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/london/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/london/vm/precompiled_contracts/mapping.v index 47a552e..83041fa 100644 --- a/CoqOfPython/ethereum/london/vm/precompiled_contracts/mapping.v +++ b/CoqOfPython/ethereum/london/vm/precompiled_contracts/mapping.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.london.vm.precompiled_contracts.mapping". Definition expr_1 : Value.t := Constant.str " @@ -17,66 +17,34 @@ Introduction Mapping of precompiled contracts their implementations. ". -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". - -Require ethereum.london.fork_types. -Axiom ethereum_london_fork_types_Address : - IsGlobalAlias globals ethereum.london.fork_types.globals "Address". - -Require ethereum.london.vm.precompiled_contracts.__init__. -Axiom ethereum_london_vm_precompiled_contracts___init___ALT_BN128_ADD_ADDRESS : - IsGlobalAlias globals ethereum.london.vm.precompiled_contracts.__init__.globals "ALT_BN128_ADD_ADDRESS". -Axiom ethereum_london_vm_precompiled_contracts___init___ALT_BN128_MUL_ADDRESS : - IsGlobalAlias globals ethereum.london.vm.precompiled_contracts.__init__.globals "ALT_BN128_MUL_ADDRESS". -Axiom ethereum_london_vm_precompiled_contracts___init___ALT_BN128_PAIRING_CHECK_ADDRESS : - IsGlobalAlias globals ethereum.london.vm.precompiled_contracts.__init__.globals "ALT_BN128_PAIRING_CHECK_ADDRESS". -Axiom ethereum_london_vm_precompiled_contracts___init___BLAKE2F_ADDRESS : - IsGlobalAlias globals ethereum.london.vm.precompiled_contracts.__init__.globals "BLAKE2F_ADDRESS". -Axiom ethereum_london_vm_precompiled_contracts___init___ECRECOVER_ADDRESS : - IsGlobalAlias globals ethereum.london.vm.precompiled_contracts.__init__.globals "ECRECOVER_ADDRESS". -Axiom ethereum_london_vm_precompiled_contracts___init___IDENTITY_ADDRESS : - IsGlobalAlias globals ethereum.london.vm.precompiled_contracts.__init__.globals "IDENTITY_ADDRESS". -Axiom ethereum_london_vm_precompiled_contracts___init___MODEXP_ADDRESS : - IsGlobalAlias globals ethereum.london.vm.precompiled_contracts.__init__.globals "MODEXP_ADDRESS". -Axiom ethereum_london_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : - IsGlobalAlias globals ethereum.london.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". -Axiom ethereum_london_vm_precompiled_contracts___init___SHA256_ADDRESS : - IsGlobalAlias globals ethereum.london.vm.precompiled_contracts.__init__.globals "SHA256_ADDRESS". - -Require ethereum.london.vm.precompiled_contracts.alt_bn128. -Axiom ethereum_london_vm_precompiled_contracts_alt_bn128_alt_bn128_add : - IsGlobalAlias globals ethereum.london.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_add". -Axiom ethereum_london_vm_precompiled_contracts_alt_bn128_alt_bn128_mul : - IsGlobalAlias globals ethereum.london.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_mul". -Axiom ethereum_london_vm_precompiled_contracts_alt_bn128_alt_bn128_pairing_check : - IsGlobalAlias globals ethereum.london.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_pairing_check". - -Require ethereum.london.vm.precompiled_contracts.blake2f. -Axiom ethereum_london_vm_precompiled_contracts_blake2f_blake2f : - IsGlobalAlias globals ethereum.london.vm.precompiled_contracts.blake2f.globals "blake2f". - -Require ethereum.london.vm.precompiled_contracts.ecrecover. -Axiom ethereum_london_vm_precompiled_contracts_ecrecover_ecrecover : - IsGlobalAlias globals ethereum.london.vm.precompiled_contracts.ecrecover.globals "ecrecover". - -Require ethereum.london.vm.precompiled_contracts.identity. -Axiom ethereum_london_vm_precompiled_contracts_identity_identity : - IsGlobalAlias globals ethereum.london.vm.precompiled_contracts.identity.globals "identity". - -Require ethereum.london.vm.precompiled_contracts.modexp. -Axiom ethereum_london_vm_precompiled_contracts_modexp_modexp : - IsGlobalAlias globals ethereum.london.vm.precompiled_contracts.modexp.globals "modexp". - -Require ethereum.london.vm.precompiled_contracts.ripemd160. -Axiom ethereum_london_vm_precompiled_contracts_ripemd160_ripemd160 : - IsGlobalAlias globals ethereum.london.vm.precompiled_contracts.ripemd160.globals "ripemd160". - -Require ethereum.london.vm.precompiled_contracts.sha256. -Axiom ethereum_london_vm_precompiled_contracts_sha256_sha256 : - IsGlobalAlias globals ethereum.london.vm.precompiled_contracts.sha256.globals "sha256". +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict" ]. + +Axiom ethereum_london_fork_types_imports : + AreImported globals "ethereum.london.fork_types" [ "Address" ]. + +Axiom ethereum_london_vm_precompiled_contracts_imports : + AreImported globals "ethereum.london.vm.precompiled_contracts" [ "ALT_BN128_ADD_ADDRESS"; "ALT_BN128_MUL_ADDRESS"; "ALT_BN128_PAIRING_CHECK_ADDRESS"; "BLAKE2F_ADDRESS"; "ECRECOVER_ADDRESS"; "IDENTITY_ADDRESS"; "MODEXP_ADDRESS"; "RIPEMD160_ADDRESS"; "SHA256_ADDRESS" ]. + +Axiom ethereum_london_vm_precompiled_contracts_alt_bn128_imports : + AreImported globals "ethereum.london.vm.precompiled_contracts.alt_bn128" [ "alt_bn128_add"; "alt_bn128_mul"; "alt_bn128_pairing_check" ]. + +Axiom ethereum_london_vm_precompiled_contracts_blake2f_imports : + AreImported globals "ethereum.london.vm.precompiled_contracts.blake2f" [ "blake2f" ]. + +Axiom ethereum_london_vm_precompiled_contracts_ecrecover_imports : + AreImported globals "ethereum.london.vm.precompiled_contracts.ecrecover" [ "ecrecover" ]. + +Axiom ethereum_london_vm_precompiled_contracts_identity_imports : + AreImported globals "ethereum.london.vm.precompiled_contracts.identity" [ "identity" ]. + +Axiom ethereum_london_vm_precompiled_contracts_modexp_imports : + AreImported globals "ethereum.london.vm.precompiled_contracts.modexp" [ "modexp" ]. + +Axiom ethereum_london_vm_precompiled_contracts_ripemd160_imports : + AreImported globals "ethereum.london.vm.precompiled_contracts.ripemd160" [ "ripemd160" ]. + +Axiom ethereum_london_vm_precompiled_contracts_sha256_imports : + AreImported globals "ethereum.london.vm.precompiled_contracts.sha256" [ "sha256" ]. (* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/london/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/london/vm/precompiled_contracts/modexp.v index 87dc90c..609b589 100644 --- a/CoqOfPython/ethereum/london/vm/precompiled_contracts/modexp.v +++ b/CoqOfPython/ethereum/london/vm/precompiled_contracts/modexp.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.london.vm.precompiled_contracts.modexp". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementation of the `MODEXP` precompiled contract. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. -Require ethereum.london.vm.__init__. -Axiom ethereum_london_vm___init___Evm : - IsGlobalAlias globals ethereum.london.vm.__init__.globals "Evm". +Axiom ethereum_london_vm_imports : + AreImported globals "ethereum.london.vm" [ "Evm" ]. -Require ethereum.london.vm.gas. -Axiom ethereum_london_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.london.vm.gas.globals "charge_gas". +Axiom ethereum_london_vm_gas_imports : + AreImported globals "ethereum.london.vm.gas" [ "charge_gas" ]. -Require ethereum.london.vm.memory. -Axiom ethereum_london_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.london.vm.memory.globals "buffer_read". +Axiom ethereum_london_vm_memory_imports : + AreImported globals "ethereum.london.vm.memory" [ "buffer_read" ]. Definition GQUADDIVISOR : Value.t := M.run ltac:(M.monadic ( Constant.int 3 diff --git a/CoqOfPython/ethereum/london/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/london/vm/precompiled_contracts/ripemd160.v index 48bc733..2cb0913 100644 --- a/CoqOfPython/ethereum/london/vm/precompiled_contracts/ripemd160.v +++ b/CoqOfPython/ethereum/london/vm/precompiled_contracts/ripemd160.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.london.vm.precompiled_contracts.ripemd160". Definition expr_1 : Value.t := Constant.str " @@ -19,29 +19,20 @@ Implementation of the `RIPEMD160` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_left_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.london.vm.__init__. -Axiom ethereum_london_vm___init___Evm : - IsGlobalAlias globals ethereum.london.vm.__init__.globals "Evm". +Axiom ethereum_london_vm_imports : + AreImported globals "ethereum.london.vm" [ "Evm" ]. -Require ethereum.london.vm.gas. -Axiom ethereum_london_vm_gas_GAS_RIPEMD160 : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_RIPEMD160". -Axiom ethereum_london_vm_gas_GAS_RIPEMD160_WORD : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_RIPEMD160_WORD". -Axiom ethereum_london_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.london.vm.gas.globals "charge_gas". +Axiom ethereum_london_vm_gas_imports : + AreImported globals "ethereum.london.vm.gas" [ "GAS_RIPEMD160"; "GAS_RIPEMD160_WORD"; "charge_gas" ]. Definition ripemd160 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/london/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/london/vm/precompiled_contracts/sha256.v index f345af0..6a7d01d 100644 --- a/CoqOfPython/ethereum/london/vm/precompiled_contracts/sha256.v +++ b/CoqOfPython/ethereum/london/vm/precompiled_contracts/sha256.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.london.vm.precompiled_contracts.sha256". Definition expr_1 : Value.t := Constant.str " @@ -19,25 +19,17 @@ Implementation of the `SHA256` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.london.vm.__init__. -Axiom ethereum_london_vm___init___Evm : - IsGlobalAlias globals ethereum.london.vm.__init__.globals "Evm". +Axiom ethereum_london_vm_imports : + AreImported globals "ethereum.london.vm" [ "Evm" ]. -Require ethereum.london.vm.gas. -Axiom ethereum_london_vm_gas_GAS_SHA256 : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_SHA256". -Axiom ethereum_london_vm_gas_GAS_SHA256_WORD : - IsGlobalAlias globals ethereum.london.vm.gas.globals "GAS_SHA256_WORD". -Axiom ethereum_london_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.london.vm.gas.globals "charge_gas". +Axiom ethereum_london_vm_gas_imports : + AreImported globals "ethereum.london.vm.gas" [ "GAS_SHA256"; "GAS_SHA256_WORD"; "charge_gas" ]. Definition sha256 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/london/vm/runtime.v b/CoqOfPython/ethereum/london/vm/runtime.v index 8cbf8ad..5900241 100644 --- a/CoqOfPython/ethereum/london/vm/runtime.v +++ b/CoqOfPython/ethereum/london/vm/runtime.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.london.vm.runtime". Definition expr_1 : Value.t := Constant.str " @@ -17,17 +17,14 @@ Introduction Runtime related operations used while executing EVM code. ". -Require typing. -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". +Axiom typing_imports : + AreImported globals "typing" [ "Set" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.london.vm.instructions.__init__. -Axiom ethereum_london_vm_instructions___init___Ops : - IsGlobalAlias globals ethereum.london.vm.instructions.__init__.globals "Ops". +Axiom ethereum_london_vm_instructions_imports : + AreImported globals "ethereum.london.vm.instructions" [ "Ops" ]. Definition get_valid_jump_destinations : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -67,75 +64,83 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := ], make_dict [] |) in - While Compare.lt (| - M.get_name (| globals, "pc" |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "code" |) - ], - make_dict [] - |) - |) do -(* At stmt: unsupported node type: Try *) - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "current_opcode" |), - M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) - |), - (* then *) + let _ := + M.while (| + Compare.lt (| + M.get_name (| globals, "pc" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) + |), ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), - make_list [ - M.get_name (| globals, "pc" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( +(* At stmt: unsupported node type: Try *) let _ := (* if *) M.if_then_else (| - BoolOp.and (| - Compare.lt_e (| - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |), - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |) - |), - ltac:(M.monadic ( - Compare.lt_e (| - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH32" |), "value" |) - |) - )) + Compare.eq (| + M.get_name (| globals, "current_opcode" |), + M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) |), (* then *) ltac:(M.monadic ( - let push_data_size := - BinOp.add (| - BinOp.sub (| - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) - |), - Constant.int 1 - |) in - let pc := BinOp.add - M.get_name (| globals, "push_data_size" |) - M.get_name (| globals, "push_data_size" |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), + make_list [ + M.get_name (| globals, "pc" |) + ], + make_dict [] + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.lt_e (| + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |), + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH32" |), "value" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let push_data_size := + BinOp.add (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) + |), + Constant.int 1 + |) in + let pc := BinOp.add + M.get_name (| globals, "push_data_size" |) + M.get_name (| globals, "push_data_size" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ )) |) in + let pc := BinOp.add + Constant.int 1 + Constant.int 1 in M.pure Constant.None_ - )) |) in - let pc := BinOp.add - Constant.int 1 - Constant.int 1 in - EndWhile. + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.get_name (| globals, "valid_jump_destinations" |) |) in diff --git a/CoqOfPython/ethereum/london/vm/stack.v b/CoqOfPython/ethereum/london/vm/stack.v index 6460116..b72a931 100644 --- a/CoqOfPython/ethereum/london/vm/stack.v +++ b/CoqOfPython/ethereum/london/vm/stack.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.london.vm.stack". Definition expr_1 : Value.t := Constant.str " @@ -17,19 +17,14 @@ Introduction Implementation of the stack operators for the EVM. ". -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". +Axiom typing_imports : + AreImported globals "typing" [ "List" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.london.vm.exceptions. -Axiom ethereum_london_vm_exceptions_StackOverflowError : - IsGlobalAlias globals ethereum.london.vm.exceptions.globals "StackOverflowError". -Axiom ethereum_london_vm_exceptions_StackUnderflowError : - IsGlobalAlias globals ethereum.london.vm.exceptions.globals "StackUnderflowError". +Axiom ethereum_london_vm_exceptions_imports : + AreImported globals "ethereum.london.vm.exceptions" [ "StackOverflowError"; "StackUnderflowError" ]. Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -63,7 +58,7 @@ Definition pop : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "StackUnderflowError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "StackUnderflowError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -108,7 +103,7 @@ Definition push : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "StackOverflowError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "StackOverflowError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/muir_glacier/__init__.v b/CoqOfPython/ethereum/muir_glacier/__init__.v index 35111c4..199ea08 100644 --- a/CoqOfPython/ethereum/muir_glacier/__init__.v +++ b/CoqOfPython/ethereum/muir_glacier/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.muir_glacier.__init__". Definition expr_1 : Value.t := Constant.str " @@ -8,9 +8,8 @@ The Muir Glacier fork delays the difficulty bomb. There are no other changes in this fork. ". -Require ethereum.fork_criteria. -Axiom ethereum_fork_criteria_ByBlockNumber : - IsGlobalAlias globals ethereum.fork_criteria.globals "ByBlockNumber". +Axiom ethereum_fork_criteria_imports : + AreImported globals "ethereum.fork_criteria" [ "ByBlockNumber" ]. Definition FORK_CRITERIA : Value.t := M.run ltac:(M.monadic ( M.call (| diff --git a/CoqOfPython/ethereum/muir_glacier/blocks.v b/CoqOfPython/ethereum/muir_glacier/blocks.v index 40922ea..2d9367b 100644 --- a/CoqOfPython/ethereum/muir_glacier/blocks.v +++ b/CoqOfPython/ethereum/muir_glacier/blocks.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.muir_glacier.blocks". Definition expr_1 : Value.t := Constant.str " @@ -14,43 +14,23 @@ history of all state transitions that have happened since the genesis of the chain. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes8 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes8". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". - -Require ethereum.muir_glacier.fork_types. -Axiom ethereum_muir_glacier_fork_types_Address : - IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "Address". -Axiom ethereum_muir_glacier_fork_types_Bloom : - IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "Bloom". -Axiom ethereum_muir_glacier_fork_types_Root : - IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "Root". - -Require ethereum.muir_glacier.transactions. -Axiom ethereum_muir_glacier_transactions_Transaction : - IsGlobalAlias globals ethereum.muir_glacier.transactions.globals "Transaction". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes8"; "Bytes32"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. + +Axiom ethereum_muir_glacier_fork_types_imports : + AreImported globals "ethereum.muir_glacier.fork_types" [ "Address"; "Bloom"; "Root" ]. + +Axiom ethereum_muir_glacier_transactions_imports : + AreImported globals "ethereum.muir_glacier.transactions" [ "Transaction" ]. Definition Header : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/muir_glacier/bloom.v b/CoqOfPython/ethereum/muir_glacier/bloom.v index 4332553..a821322 100644 --- a/CoqOfPython/ethereum/muir_glacier/bloom.v +++ b/CoqOfPython/ethereum/muir_glacier/bloom.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.muir_glacier.bloom". Definition expr_1 : Value.t := Constant.str " @@ -21,25 +21,20 @@ for efficient searching of logs by address and/or topic, by rapidly eliminating blocks and receipts from their search. ". -Require typing. -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_imports : + AreImported globals "typing" [ "Tuple" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. -Require ethereum.muir_glacier.blocks. -Axiom ethereum_muir_glacier_blocks_Log : - IsGlobalAlias globals ethereum.muir_glacier.blocks.globals "Log". +Axiom ethereum_muir_glacier_blocks_imports : + AreImported globals "ethereum.muir_glacier.blocks" [ "Log" ]. -Require ethereum.muir_glacier.fork_types. -Axiom ethereum_muir_glacier_fork_types_Bloom : - IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "Bloom". +Axiom ethereum_muir_glacier_fork_types_imports : + AreImported globals "ethereum.muir_glacier.fork_types" [ "Bloom" ]. Definition add_to_bloom : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -66,50 +61,70 @@ Definition add_to_bloom : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "idx" |) in make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ] do - let bit_to_set := - BinOp.bit_and (| - M.call (| - M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "hash" |), M.slice (| M.get_name (| globals, "idx" |), BinOp.add (| - M.get_name (| globals, "idx" |), - Constant.int 2 - |) |) |) - ], - make_dict [] - |), - Constant.int 2047 - |) in - let bit_index := - BinOp.sub (| - Constant.int 2047, - M.get_name (| globals, "bit_to_set" |) - |) in - let byte_index := - BinOp.floor_div (| - M.get_name (| globals, "bit_index" |), - Constant.int 8 - |) in - let bit_value := - BinOp.l_shift (| - Constant.int 1, - BinOp.sub (| - Constant.int 7, - BinOp.mod_ (| + let _ := + M.for_ (| + M.get_name (| globals, "idx" |), + make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ], + ltac:(M.monadic ( + let bit_to_set := + BinOp.bit_and (| + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.slice (| + M.get_name (| globals, "hash" |), + M.get_name (| globals, "idx" |), + BinOp.add (| + M.get_name (| globals, "idx" |), + Constant.int 2 + |), + Constant.None_ + |) + ], + make_dict [] + |), + Constant.int 2047 + |) in + let bit_index := + BinOp.sub (| + Constant.int 2047, + M.get_name (| globals, "bit_to_set" |) + |) in + let byte_index := + BinOp.floor_div (| M.get_name (| globals, "bit_index" |), Constant.int 8 + |) in + let bit_value := + BinOp.l_shift (| + Constant.int 1, + BinOp.sub (| + Constant.int 7, + BinOp.mod_ (| + M.get_name (| globals, "bit_index" |), + Constant.int 8 + |) + |) + |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "bloom" |), + M.get_name (| globals, "byte_index" |) + |), + BinOp.bit_or (| + M.get_subscript (| + M.get_name (| globals, "bloom" |), + M.get_name (| globals, "byte_index" |) + |), + M.get_name (| globals, "bit_value" |) |) - |) - |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), - BinOp.bit_or (| - M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), - M.get_name (| globals, "bit_value" |) - |) - |) in - EndFor. + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_)). Definition logs_bloom : Value.t -> Value.t -> M := @@ -132,8 +147,12 @@ Definition logs_bloom : Value.t -> Value.t -> M := the caller address and the log topics. " in (* At stmt: unsupported node type: AnnAssign *) - For M.get_name (| globals, "log" |) in M.get_name (| globals, "logs" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "log" |), + M.get_name (| globals, "logs" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "add_to_bloom" |), make_list [ M.get_name (| globals, "bloom" |); @@ -141,8 +160,12 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "topic" |) in M.get_field (| M.get_name (| globals, "log" |), "topics" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "topic" |), + M.get_field (| M.get_name (| globals, "log" |), "topics" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "add_to_bloom" |), make_list [ M.get_name (| globals, "bloom" |); @@ -150,8 +173,18 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Bloom" |), diff --git a/CoqOfPython/ethereum/muir_glacier/fork.v b/CoqOfPython/ethereum/muir_glacier/fork.v index d4c2985..c7af4a6 100644 --- a/CoqOfPython/ethereum/muir_glacier/fork.v +++ b/CoqOfPython/ethereum/muir_glacier/fork.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.muir_glacier.fork". Definition expr_1 : Value.t := Constant.str " @@ -17,139 +17,62 @@ Introduction Entry point for the Ethereum specification. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". - -Require ethereum.crypto.elliptic_curve. -Axiom ethereum_crypto_elliptic_curve_SECP256K1N : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". -Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.ethash. -Axiom ethereum_ethash_dataset_size : - IsGlobalAlias globals ethereum.ethash.globals "dataset_size". -Axiom ethereum_ethash_generate_cache : - IsGlobalAlias globals ethereum.ethash.globals "generate_cache". -Axiom ethereum_ethash_hashimoto_light : - IsGlobalAlias globals ethereum.ethash.globals "hashimoto_light". - -Require ethereum.exceptions. -Axiom ethereum_exceptions_InvalidBlock : - IsGlobalAlias globals ethereum.exceptions.globals "InvalidBlock". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U64 : - IsGlobalAlias globals ethereum.base_types.globals "U64". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_U256_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.muir_glacier.__init__. -Axiom ethereum_muir_glacier___init___vm : - IsGlobalAlias globals ethereum.muir_glacier.__init__.globals "vm". - -Require ethereum.muir_glacier.blocks. -Axiom ethereum_muir_glacier_blocks_Block : - IsGlobalAlias globals ethereum.muir_glacier.blocks.globals "Block". -Axiom ethereum_muir_glacier_blocks_Header : - IsGlobalAlias globals ethereum.muir_glacier.blocks.globals "Header". -Axiom ethereum_muir_glacier_blocks_Log : - IsGlobalAlias globals ethereum.muir_glacier.blocks.globals "Log". -Axiom ethereum_muir_glacier_blocks_Receipt : - IsGlobalAlias globals ethereum.muir_glacier.blocks.globals "Receipt". - -Require ethereum.muir_glacier.bloom. -Axiom ethereum_muir_glacier_bloom_logs_bloom : - IsGlobalAlias globals ethereum.muir_glacier.bloom.globals "logs_bloom". - -Require ethereum.muir_glacier.fork_types. -Axiom ethereum_muir_glacier_fork_types_Address : - IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "Address". -Axiom ethereum_muir_glacier_fork_types_Bloom : - IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "Bloom". -Axiom ethereum_muir_glacier_fork_types_Root : - IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "Root". - -Require ethereum.muir_glacier.state. -Axiom ethereum_muir_glacier_state_State : - IsGlobalAlias globals ethereum.muir_glacier.state.globals "State". -Axiom ethereum_muir_glacier_state_account_exists_and_is_empty : - IsGlobalAlias globals ethereum.muir_glacier.state.globals "account_exists_and_is_empty". -Axiom ethereum_muir_glacier_state_create_ether : - IsGlobalAlias globals ethereum.muir_glacier.state.globals "create_ether". -Axiom ethereum_muir_glacier_state_destroy_account : - IsGlobalAlias globals ethereum.muir_glacier.state.globals "destroy_account". -Axiom ethereum_muir_glacier_state_get_account : - IsGlobalAlias globals ethereum.muir_glacier.state.globals "get_account". -Axiom ethereum_muir_glacier_state_increment_nonce : - IsGlobalAlias globals ethereum.muir_glacier.state.globals "increment_nonce". -Axiom ethereum_muir_glacier_state_set_account_balance : - IsGlobalAlias globals ethereum.muir_glacier.state.globals "set_account_balance". -Axiom ethereum_muir_glacier_state_state_root : - IsGlobalAlias globals ethereum.muir_glacier.state.globals "state_root". - -Require ethereum.muir_glacier.transactions. -Axiom ethereum_muir_glacier_transactions_TX_BASE_COST : - IsGlobalAlias globals ethereum.muir_glacier.transactions.globals "TX_BASE_COST". -Axiom ethereum_muir_glacier_transactions_TX_CREATE_COST : - IsGlobalAlias globals ethereum.muir_glacier.transactions.globals "TX_CREATE_COST". -Axiom ethereum_muir_glacier_transactions_TX_DATA_COST_PER_NON_ZERO : - IsGlobalAlias globals ethereum.muir_glacier.transactions.globals "TX_DATA_COST_PER_NON_ZERO". -Axiom ethereum_muir_glacier_transactions_TX_DATA_COST_PER_ZERO : - IsGlobalAlias globals ethereum.muir_glacier.transactions.globals "TX_DATA_COST_PER_ZERO". -Axiom ethereum_muir_glacier_transactions_Transaction : - IsGlobalAlias globals ethereum.muir_glacier.transactions.globals "Transaction". - -Require ethereum.muir_glacier.trie. -Axiom ethereum_muir_glacier_trie_Trie : - IsGlobalAlias globals ethereum.muir_glacier.trie.globals "Trie". -Axiom ethereum_muir_glacier_trie_root : - IsGlobalAlias globals ethereum.muir_glacier.trie.globals "root". -Axiom ethereum_muir_glacier_trie_trie_set : - IsGlobalAlias globals ethereum.muir_glacier.trie.globals "trie_set". - -Require ethereum.muir_glacier.utils.message. -Axiom ethereum_muir_glacier_utils_message_prepare_message : - IsGlobalAlias globals ethereum.muir_glacier.utils.message.globals "prepare_message". - -Require ethereum.muir_glacier.vm.interpreter. -Axiom ethereum_muir_glacier_vm_interpreter_process_message_call : - IsGlobalAlias globals ethereum.muir_glacier.vm.interpreter.globals "process_message_call". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Bytes0" ]. + +Axiom ethereum_crypto_elliptic_curve_imports : + AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. + +Axiom ethereum_ethash_imports : + AreImported globals "ethereum.ethash" [ "dataset_size"; "generate_cache"; "hashimoto_light" ]. + +Axiom ethereum_exceptions_imports : + AreImported globals "ethereum.exceptions" [ "InvalidBlock" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U64"; "U256"; "U256_CEIL_VALUE"; "Bytes"; "Uint" ]. + +Axiom ethereum_muir_glacier_imports : + AreImported globals "ethereum.muir_glacier" [ "vm" ]. + +Axiom ethereum_muir_glacier_blocks_imports : + AreImported globals "ethereum.muir_glacier.blocks" [ "Block"; "Header"; "Log"; "Receipt" ]. + +Axiom ethereum_muir_glacier_bloom_imports : + AreImported globals "ethereum.muir_glacier.bloom" [ "logs_bloom" ]. + +Axiom ethereum_muir_glacier_fork_types_imports : + AreImported globals "ethereum.muir_glacier.fork_types" [ "Address"; "Bloom"; "Root" ]. + +Axiom ethereum_muir_glacier_state_imports : + AreImported globals "ethereum.muir_glacier.state" [ "State"; "account_exists_and_is_empty"; "create_ether"; "destroy_account"; "get_account"; "increment_nonce"; "set_account_balance"; "state_root" ]. + +Axiom ethereum_muir_glacier_transactions_imports : + AreImported globals "ethereum.muir_glacier.transactions" [ "TX_BASE_COST"; "TX_CREATE_COST"; "TX_DATA_COST_PER_NON_ZERO"; "TX_DATA_COST_PER_ZERO"; "Transaction" ]. + +Axiom ethereum_muir_glacier_trie_imports : + AreImported globals "ethereum.muir_glacier.trie" [ "Trie"; "root"; "trie_set" ]. + +Axiom ethereum_muir_glacier_utils_message_imports : + AreImported globals "ethereum.muir_glacier.utils.message" [ "prepare_message" ]. + +Axiom ethereum_muir_glacier_vm_interpreter_imports : + AreImported globals "ethereum.muir_glacier.vm.interpreter" [ "process_message_call" ]. Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -268,7 +191,12 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := Hashes of the recent 256 blocks in order of increasing block number. " in let recent_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) in + M.slice (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| Constant.int 255 |), + Constant.None_, + Constant.None_ + |) in let _ := (* if *) M.if_then_else (| @@ -294,17 +222,26 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := )) |) in let recent_block_hashes := make_list [] in - For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_blocks" |) do - let prev_block_hash := - M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "block" |), + M.get_name (| globals, "recent_blocks" |), + ltac:(M.monadic ( + let prev_block_hash := + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in + let _ := M.call (| M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), make_list [ M.get_name (| globals, "prev_block_hash" |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let most_recent_block_hash := M.call (| M.get_name (| globals, "keccak256" |), @@ -312,7 +249,10 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), make_list [ - M.get_field (| M.get_subscript (| M.get_name (| globals, "recent_blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) + M.get_field (| M.get_subscript (| + M.get_name (| globals, "recent_blocks" |), + UnOp.sub (| Constant.int 1 |) + |), "header" |) ], make_dict [] |) @@ -356,7 +296,10 @@ Definition state_transition : Value.t -> Value.t -> M := Block to apply to `chain`. " in let parent_header := - M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) in + M.get_field (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| Constant.int 1 |) + |), "header" |) in let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ @@ -476,7 +419,12 @@ Definition state_transition : Value.t -> Value.t -> M := ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) + M.slice (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| Constant.int 255 |), + Constant.None_, + Constant.None_ + |) |) in M.pure Constant.None_ (* else *) @@ -903,14 +851,18 @@ Definition apply_body : Value.t -> Value.t -> M := (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) - For make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "tx" |) ] in M.call (| - M.get_name (| globals, "enumerate" |), - make_list [ - M.get_name (| globals, "transactions" |) - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "tx" |) ], + M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "transactions" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ M.get_name (| globals, "transactions_trie" |); @@ -931,51 +883,51 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_address := - M.call (| - M.get_name (| globals, "check_transaction" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "gas_available" |); - M.get_name (| globals, "chain_id" |) - ], - make_dict [] - |) in - let env := - M.call (| - M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), - make_list [], - make_dict [] - |) in - let _ := M.assign (| - make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |); M.get_name (| globals, "error" |) ], - M.call (| - M.get_name (| globals, "process_transaction" |), - make_list [ - M.get_name (| globals, "env" |); - M.get_name (| globals, "tx" |) - ], - make_dict [] - |) - |) in - let gas_available := BinOp.sub - M.get_name (| globals, "gas_used" |) - M.get_name (| globals, "gas_used" |) in - let receipt := - M.call (| - M.get_name (| globals, "make_receipt" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "error" |); - BinOp.sub (| - M.get_name (| globals, "block_gas_limit" |), - M.get_name (| globals, "gas_available" |) - |); - M.get_name (| globals, "logs" |) - ], - make_dict [] - |) in - let _ := M.call (| + let sender_address := + M.call (| + M.get_name (| globals, "check_transaction" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "gas_available" |); + M.get_name (| globals, "chain_id" |) + ], + make_dict [] + |) in + let env := + M.call (| + M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |); M.get_name (| globals, "error" |) ], + M.call (| + M.get_name (| globals, "process_transaction" |), + make_list [ + M.get_name (| globals, "env" |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) in + let gas_available := BinOp.sub + M.get_name (| globals, "gas_used" |) + M.get_name (| globals, "gas_used" |) in + let receipt := + M.call (| + M.get_name (| globals, "make_receipt" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "error" |); + BinOp.sub (| + M.get_name (| globals, "block_gas_limit" |), + M.get_name (| globals, "gas_available" |) + |); + M.get_name (| globals, "logs" |) + ], + make_dict [] + |) in + let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ M.get_name (| globals, "receipts_trie" |); @@ -996,10 +948,15 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_logs := BinOp.add - M.get_name (| globals, "logs" |) - M.get_name (| globals, "logs" |) in - EndFor. + let block_logs := BinOp.add + M.get_name (| globals, "logs" |) + M.get_name (| globals, "logs" |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.call (| M.get_name (| globals, "pay_rewards" |), make_list [ @@ -1128,8 +1085,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "ommer" |), + M.get_name (| globals, "ommers" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ BoolOp.and (| @@ -1148,15 +1109,18 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_parent_header := - M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), BinOp.sub (| - UnOp.sub (| BinOp.sub (| - M.get_field (| M.get_name (| globals, "block_header" |), "number" |), - M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) |), - Constant.int 1 - |) |), "header" |) in - let _ := M.call (| + let ommer_parent_header := + M.get_field (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + BinOp.sub (| + UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) |), + Constant.int 1 + |) + |), "header" |) in + let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ M.get_name (| globals, "ommer" |); @@ -1164,7 +1128,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1214,33 +1183,54 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let recent_canonical_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| BinOp.add (| - M.get_name (| globals, "MAX_OMMER_DEPTH" |), - Constant.int 1 - |) |), Constant.None_ |) |) in + M.slice (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| BinOp.add (| + M.get_name (| globals, "MAX_OMMER_DEPTH" |), + Constant.int 1 + |) |), + Constant.None_, + Constant.None_ + |) in let recent_canonical_block_hashes := Constant.str "(* At expr: unsupported node type: SetComp *)" in (* At stmt: unsupported node type: AnnAssign *) - For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_canonical_blocks" |) do - let recent_ommers_hashes := + let _ := + M.for_ (| + M.get_name (| globals, "block" |), + M.get_name (| globals, "recent_canonical_blocks" |), + ltac:(M.monadic ( + let recent_ommers_hashes := + M.call (| + M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), + make_list [ + Constant.str "(* At expr: unsupported node type: SetComp *)" + ], + make_dict [] + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "ommer_index" |); M.get_name (| globals, "ommer" |) ], M.call (| - M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), - make_list [ - Constant.str "(* At expr: unsupported node type: SetComp *)" - ], - make_dict [] - |) in - EndFor. - For make_tuple [ M.get_name (| globals, "ommer_index" |); M.get_name (| globals, "ommer" |) ] in M.call (| - M.get_name (| globals, "enumerate" |), - make_list [ - M.get_name (| globals, "ommers" |) - ], - make_dict [] - |) do - let ommer_hash := - M.get_subscript (| M.get_name (| globals, "ommers_hashes" |), M.get_name (| globals, "ommer_index" |) |) in - let _ := M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let ommer_hash := + M.get_subscript (| + M.get_name (| globals, "ommers_hashes" |), + M.get_name (| globals, "ommer_index" |) + |) in + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_eq (| @@ -1251,7 +1241,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_in (| @@ -1262,7 +1252,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_in (| @@ -1273,12 +1263,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_age := - BinOp.sub (| - M.get_field (| M.get_name (| globals, "block_header" |), "number" |), - M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) in - let _ := M.call (| + let ommer_age := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) in + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ BoolOp.and (| @@ -1297,10 +1287,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.in (| + Compare.in_ (| M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), M.get_name (| globals, "recent_canonical_block_hashes" |) |); @@ -1308,7 +1298,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_eq (| @@ -1319,7 +1309,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_)). Definition pay_rewards : Value.t -> Value.t -> M := @@ -1376,30 +1371,34 @@ Definition pay_rewards : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do - let ommer_age := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - BinOp.sub (| - M.get_name (| globals, "block_number" |), - M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) - ], - make_dict [] - |) in - let ommer_miner_reward := - BinOp.floor_div (| - BinOp.mult (| - BinOp.sub (| - Constant.int 8, - M.get_name (| globals, "ommer_age" |) - |), - M.get_name (| globals, "BLOCK_REWARD" |) - |), - Constant.int 8 - |) in - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "ommer" |), + M.get_name (| globals, "ommers" |), + ltac:(M.monadic ( + let ommer_age := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "block_number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) + ], + make_dict [] + |) in + let ommer_miner_reward := + BinOp.floor_div (| + BinOp.mult (| + BinOp.sub (| + Constant.int 8, + M.get_name (| globals, "ommer_age" |) + |), + M.get_name (| globals, "BLOCK_REWARD" |) + |), + Constant.int 8 + |) in + let _ := M.call (| M.get_name (| globals, "create_ether" |), make_list [ M.get_name (| globals, "state" |); @@ -1408,7 +1407,12 @@ Definition pay_rewards : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_)). Definition process_transaction : Value.t -> Value.t -> M := @@ -1688,8 +1692,12 @@ Definition process_transaction : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "accounts_to_delete" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "output" |), "accounts_to_delete" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "destroy_account" |), make_list [ M.get_field (| M.get_name (| globals, "env" |), "state" |); @@ -1697,22 +1705,31 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. - For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "touched_accounts" |) do - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), - (* then *) + M.pure Constant.None_ + )), ltac:(M.monadic ( - let _ := M.call (| + M.pure Constant.None_ + )) + |) in + let _ := + M.for_ (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "output" |), "touched_accounts" |), + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "destroy_account" |), make_list [ M.get_field (| M.get_name (| globals, "env" |), "state" |); @@ -1720,12 +1737,17 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := M.return_ (| make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |); M.get_field (| M.get_name (| globals, "output" |), "error" |) ] |) in @@ -1813,28 +1835,37 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := " in let data_cost := Constant.int 0 in - For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "byte" |), - Constant.int 0 - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "byte" |), + M.get_field (| M.get_name (| globals, "tx" |), "data" |), ltac:(M.monadic ( - let data_cost := BinOp.add - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "byte" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let data_cost := BinOp.add - M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := (* if *) M.if_then_else (| @@ -2049,13 +2080,18 @@ Definition recover_sender : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "Address" |), make_list [ - M.get_subscript (| M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "public_key" |) - ], - make_dict [] - |), M.slice (| Constant.int 12, Constant.int 32 |) |) + M.slice (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), + Constant.int 12, + Constant.int 32, + Constant.None_ + |) ], make_dict [] |) diff --git a/CoqOfPython/ethereum/muir_glacier/fork_types.v b/CoqOfPython/ethereum/muir_glacier/fork_types.v index cc8e4a1..775b1dd 100644 --- a/CoqOfPython/ethereum/muir_glacier/fork_types.v +++ b/CoqOfPython/ethereum/muir_glacier/fork_types.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.muir_glacier.fork_types". Definition expr_1 : Value.t := Constant.str " @@ -17,33 +17,17 @@ Introduction Types re-used throughout the specification, which are specific to Ethereum. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes20 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes20". -Axiom ethereum_base_types_Bytes256 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes20"; "Bytes256"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) diff --git a/CoqOfPython/ethereum/muir_glacier/state.v b/CoqOfPython/ethereum/muir_glacier/state.v index d83d177..d7321e4 100644 --- a/CoqOfPython/ethereum/muir_glacier/state.v +++ b/CoqOfPython/ethereum/muir_glacier/state.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.muir_glacier.state". Definition expr_1 : Value.t := Constant.str " @@ -22,63 +22,23 @@ There is a distinction between an account that does not exist and `EMPTY_ACCOUNT`. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". -Axiom dataclasses_field : - IsGlobalAlias globals dataclasses.globals "field". - -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_modify : - IsGlobalAlias globals ethereum.base_types.globals "modify". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.muir_glacier.fork_types. -Axiom ethereum_muir_glacier_fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "EMPTY_ACCOUNT". -Axiom ethereum_muir_glacier_fork_types_Account : - IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "Account". -Axiom ethereum_muir_glacier_fork_types_Address : - IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "Address". -Axiom ethereum_muir_glacier_fork_types_Root : - IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "Root". - -Require ethereum.muir_glacier.trie. -Axiom ethereum_muir_glacier_trie_EMPTY_TRIE_ROOT : - IsGlobalAlias globals ethereum.muir_glacier.trie.globals "EMPTY_TRIE_ROOT". -Axiom ethereum_muir_glacier_trie_Trie : - IsGlobalAlias globals ethereum.muir_glacier.trie.globals "Trie". -Axiom ethereum_muir_glacier_trie_copy_trie : - IsGlobalAlias globals ethereum.muir_glacier.trie.globals "copy_trie". -Axiom ethereum_muir_glacier_trie_root : - IsGlobalAlias globals ethereum.muir_glacier.trie.globals "root". -Axiom ethereum_muir_glacier_trie_trie_get : - IsGlobalAlias globals ethereum.muir_glacier.trie.globals "trie_get". -Axiom ethereum_muir_glacier_trie_trie_set : - IsGlobalAlias globals ethereum.muir_glacier.trie.globals "trie_set". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass"; "field" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict"; "List"; "Optional"; "Set"; "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "modify" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_muir_glacier_fork_types_imports : + AreImported globals "ethereum.muir_glacier.fork_types" [ "EMPTY_ACCOUNT"; "Account"; "Address"; "Root" ]. + +Axiom ethereum_muir_glacier_trie_imports : + AreImported globals "ethereum.muir_glacier.trie" [ "EMPTY_TRIE_ROOT"; "Trie"; "copy_trie"; "root"; "trie_get"; "trie_set" ]. Definition State : Value.t := builtins.make_klass @@ -373,13 +333,16 @@ Definition destroy_storage : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -542,7 +505,10 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), + M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |), M.get_name (| globals, "trie" |) |) in M.pure Constant.None_ @@ -568,7 +534,10 @@ Definition set_storage : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -598,7 +567,7 @@ Definition storage_root : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), @@ -608,7 +577,10 @@ Definition storage_root : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "root" |), make_list [ - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) + M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |) ], make_dict [] |) @@ -1167,7 +1139,7 @@ Definition get_storage_original : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |) |), @@ -1189,7 +1161,10 @@ Definition get_storage_original : Value.t -> Value.t -> M := )) |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "_" |); M.get_name (| globals, "original_trie" |) ], - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), Constant.int 0 |) + M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), + Constant.int 0 + |) |) in let original_account_trie := M.call (| diff --git a/CoqOfPython/ethereum/muir_glacier/transactions.v b/CoqOfPython/ethereum/muir_glacier/transactions.v index 26455ec..0db6afa 100644 --- a/CoqOfPython/ethereum/muir_glacier/transactions.v +++ b/CoqOfPython/ethereum/muir_glacier/transactions.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.muir_glacier.transactions". Definition expr_1 : Value.t := Constant.str " @@ -9,29 +9,17 @@ submitted to be executed. If Ethereum is viewed as a state machine, transactions are the events that move between states. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.muir_glacier.fork_types. -Axiom ethereum_muir_glacier_fork_types_Address : - IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "Address". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Union" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_muir_glacier_fork_types_imports : + AreImported globals "ethereum.muir_glacier.fork_types" [ "Address" ]. Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( Constant.int 21000 diff --git a/CoqOfPython/ethereum/muir_glacier/trie.v b/CoqOfPython/ethereum/muir_glacier/trie.v index a29e0e3..b8c79e6 100644 --- a/CoqOfPython/ethereum/muir_glacier/trie.v +++ b/CoqOfPython/ethereum/muir_glacier/trie.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.muir_glacier.trie". Definition expr_1 : Value.t := Constant.str " @@ -20,83 +20,38 @@ The state trie is the structure responsible for storing (* At top_level_stmt: unsupported node type: Import *) -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". -Axiom dataclasses_field : - IsGlobalAlias globals dataclasses.globals "field". - -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". -Axiom typing_Generic : - IsGlobalAlias globals typing.globals "Generic". -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Mapping : - IsGlobalAlias globals typing.globals "Mapping". -Axiom typing_MutableMapping : - IsGlobalAlias globals typing.globals "MutableMapping". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Sequence : - IsGlobalAlias globals typing.globals "Sequence". -Axiom typing_TypeVar : - IsGlobalAlias globals typing.globals "TypeVar". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". -Axiom typing_cast : - IsGlobalAlias globals typing.globals "cast". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.istanbul.__init__. -Axiom ethereum_istanbul___init___trie : - IsGlobalAlias globals ethereum.istanbul.__init__.globals "trie". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.utils.hexadecimal. -Axiom ethereum_utils_hexadecimal_hex_to_bytes : - IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.muir_glacier.blocks. -Axiom ethereum_muir_glacier_blocks_Receipt : - IsGlobalAlias globals ethereum.muir_glacier.blocks.globals "Receipt". - -Require ethereum.muir_glacier.fork_types. -Axiom ethereum_muir_glacier_fork_types_Account : - IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "Account". -Axiom ethereum_muir_glacier_fork_types_Address : - IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "Address". -Axiom ethereum_muir_glacier_fork_types_Root : - IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "Root". -Axiom ethereum_muir_glacier_fork_types_encode_account : - IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "encode_account". - -Require ethereum.muir_glacier.transactions. -Axiom ethereum_muir_glacier_transactions_Transaction : - IsGlobalAlias globals ethereum.muir_glacier.transactions.globals "Transaction". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass"; "field" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict"; "Generic"; "List"; "Mapping"; "MutableMapping"; "Optional"; "Sequence"; "TypeVar"; "Union"; "cast" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. + +Axiom ethereum_istanbul_imports : + AreImported globals "ethereum.istanbul" [ "trie" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_utils_hexadecimal_imports : + AreImported globals "ethereum.utils.hexadecimal" [ "hex_to_bytes" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_muir_glacier_blocks_imports : + AreImported globals "ethereum.muir_glacier.blocks" [ "Receipt" ]. + +Axiom ethereum_muir_glacier_fork_types_imports : + AreImported globals "ethereum.muir_glacier.fork_types" [ "Account"; "Address"; "Root"; "encode_account" ]. + +Axiom ethereum_muir_glacier_transactions_imports : + AreImported globals "ethereum.muir_glacier.transactions" [ "Transaction" ]. Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -115,7 +70,10 @@ Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( )). Definition Node : Value.t := M.run ltac:(M.monadic ( - M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Bytes" |); M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |); Constant.None_ ] |) + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Bytes" |); M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |); Constant.None_ ] + |) )). Definition K : Value.t := M.run ltac:(M.monadic ( @@ -133,11 +91,23 @@ Definition V : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "TypeVar" |), make_list [ Constant.str "V"; - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Account" |) |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Bytes" |) |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Account" |) + |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Bytes" |) + |); M.get_name (| globals, "Bytes" |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Transaction" |) |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Receipt" |) |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Transaction" |) + |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Receipt" |) + |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |) ], @@ -176,7 +146,10 @@ Definition BranchNode : Value.t := ]. Definition InternalNode : Value.t := M.run ltac:(M.monadic ( - M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LeafNode" |); M.get_name (| globals, "ExtensionNode" |); M.get_name (| globals, "BranchNode" |) ] |) + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "LeafNode" |); M.get_name (| globals, "ExtensionNode" |); M.get_name (| globals, "BranchNode" |) ] + |) )). Definition encode_internal_node : Value.t -> Value.t -> M := @@ -288,7 +261,7 @@ Definition encode_internal_node : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "(* At expr: unsupported node type: JoinedStr *)" @@ -528,13 +501,16 @@ Definition trie_set : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "key" |), M.get_field (| M.get_name (| globals, "trie" |), "_data" |) |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + M.get_name (| globals, "key" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -544,7 +520,10 @@ Definition trie_set : Value.t -> Value.t -> M := (* else *) )), ltac:(M.monadic ( let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), + M.get_subscript (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + M.get_name (| globals, "key" |) + |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_ @@ -589,51 +568,66 @@ Definition common_prefix_length : Value.t -> Value.t -> M := let _ := Constant.str " Find the longest common prefix of two sequences. " in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "a" |) - ], - make_dict [] - |) - ], - make_dict [] - |) do - let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| - M.get_name (| globals, "i" |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "b" |) - ], - make_dict [] - |) - |), - ltac:(M.monadic ( - Compare.not_eq (| - M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), - M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) - |) - )) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + ], + make_dict [] + |), ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "i" |) - |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_subscript (| + M.get_name (| globals, "a" |), + M.get_name (| globals, "i" |) + |), + M.get_subscript (| + M.get_name (| globals, "b" |), + M.get_name (| globals, "i" |) + |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "len" |), @@ -718,38 +712,53 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 0; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |); - Constant.int 2 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ BinOp.add (| BinOp.mult (| Constant.int 16, - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "i" |) + |) |), - M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) + |) |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -767,43 +776,61 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := Constant.int 1 |) |), - M.get_subscript (| M.get_name (| globals, "x" |), Constant.int 0 |) + M.get_subscript (| + M.get_name (| globals, "x" |), + Constant.int 0 + |) |) ], make_dict [] |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 1; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |); - Constant.int 2 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 1; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ BinOp.add (| BinOp.mult (| Constant.int 16, - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "i" |) + |) |), - M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) + |) |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -850,40 +877,55 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := ], make_dict [] |) in - For make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ] in M.call (| - M.get_name (| globals, "enumerate" |), - make_list [ - M.get_name (| globals, "bytes_" |) - ], - make_dict [] - |) do - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.mult (| - M.get_name (| globals, "byte_index" |), - Constant.int 2 - |) |), - BinOp.r_shift (| - BinOp.bit_and (| - M.get_name (| globals, "byte" |), - Constant.int 240 - |), - Constant.int 4 - |) - |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "byte_index" |), - Constant.int 2 - |), - Constant.int 1 - |) |), - BinOp.bit_and (| - M.get_name (| globals, "byte" |), - Constant.int 15 - |) - |) in - EndFor. + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ], + M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "bytes_" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "nibble_list" |), + BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |) + |), + BinOp.r_shift (| + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 240 + |), + Constant.int 4 + |) + |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "nibble_list" |), + BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |), + Constant.int 1 + |) + |), + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 15 + |) + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Bytes" |), @@ -916,65 +958,69 @@ Definition _prepare_trie : Value.t -> Value.t -> M := Object with keys mapped to nibble-byte form. " in (* At stmt: unsupported node type: AnnAssign *) - For make_tuple [ M.get_name (| globals, "preimage" |); M.get_name (| globals, "value" |) ] in M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "items" |), - make_list [], - make_dict [] - |) do - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "value" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "preimage" |); M.get_name (| globals, "value" |) ], + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "items" |), + make_list [], + make_dict [] + |), ltac:(M.monadic ( - let _ := M.assert (| Compare.is_not (| + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in - let address := - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in - let encoded_value := - M.call (| - M.get_name (| globals, "encode_node" |), - make_list [ - M.get_name (| globals, "value" |); + let address := M.call (| - M.get_name (| globals, "get_storage_root" |), + M.get_name (| globals, "Address" |), make_list [ - M.get_name (| globals, "address" |) + M.get_name (| globals, "preimage" |) ], make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let encoded_value := - M.call (| - M.get_name (| globals, "encode_node" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - )) |) in - let _ := M.call (| + |) in + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |); + M.call (| + M.get_name (| globals, "get_storage_root" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_eq (| @@ -986,38 +1032,46 @@ Definition _prepare_trie : Value.t -> Value.t -> M := make_dict [] |) in (* At stmt: unsupported node type: AnnAssign *) - let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "trie" |), "secured" |), - (* then *) - ltac:(M.monadic ( - let key := - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "trie" |), "secured" |), + (* then *) + ltac:(M.monadic ( + let key := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let key := + M.get_name (| globals, "preimage" |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "mapped" |), + M.call (| + M.get_name (| globals, "bytes_to_nibble_list" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |) + |), + M.get_name (| globals, "encoded_value" |) + |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let key := - M.get_name (| globals, "preimage" |) in + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "mapped" |), M.call (| - M.get_name (| globals, "bytes_to_nibble_list" |), - make_list [ - M.get_name (| globals, "key" |) - ], - make_dict [] - |) |), - M.get_name (| globals, "encoded_value" |) - |) in - EndFor. + )) + |) in let _ := M.return_ (| M.get_name (| globals, "mapped" |) |) in @@ -1210,8 +1264,16 @@ Definition patricialize : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "LeafNode" |), make_list [ - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |); - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) + M.slice (| + M.get_name (| globals, "arbitrary_key" |), + M.get_name (| globals, "level" |), + Constant.None_, + Constant.None_ + |); + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "arbitrary_key" |) + |) ], make_dict [] |) in @@ -1224,7 +1286,12 @@ Definition patricialize : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in let substring := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "arbitrary_key" |), + M.get_name (| globals, "level" |), + Constant.None_, + Constant.None_ + |) in let prefix_length := M.call (| M.get_name (| globals, "len" |), @@ -1233,39 +1300,53 @@ Definition patricialize : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do - let prefix_length := - M.call (| - M.get_name (| globals, "min" |), - make_list [ - M.get_name (| globals, "prefix_length" |); + let _ := + M.for_ (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "obj" |), + ltac:(M.monadic ( + let prefix_length := M.call (| - M.get_name (| globals, "common_prefix_length" |), + M.get_name (| globals, "min" |), make_list [ - M.get_name (| globals, "substring" |); - M.get_subscript (| M.get_name (| globals, "key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) + M.get_name (| globals, "prefix_length" |); + M.call (| + M.get_name (| globals, "common_prefix_length" |), + make_list [ + M.get_name (| globals, "substring" |); + M.slice (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "level" |), + Constant.None_, + Constant.None_ + |) + ], + make_dict [] + |) ], make_dict [] - |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "prefix_length" |), - Constant.int 0 - |), - (* then *) - ltac:(M.monadic ( - let _ := M.break (| |) in + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "prefix_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := (* if *) M.if_then_else (| @@ -1276,10 +1357,15 @@ Definition patricialize : Value.t -> Value.t -> M := (* then *) ltac:(M.monadic ( let prefix := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), BinOp.add (| + M.slice (| + M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |), - M.get_name (| globals, "prefix_length" |) - |) |) |) in + BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |), + Constant.None_ + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ExtensionNode" |), @@ -1312,70 +1398,106 @@ Definition patricialize : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) - For M.get_name (| globals, "_" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 16 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "_" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 16 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "branches" |), "append" |), make_list [ {} ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let value := Constant.bytes "" in - For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "key" |) - ], - make_dict [] - |), - M.get_name (| globals, "level" |) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "obj" |), ltac:(M.monadic ( let _ := (* if *) M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); - make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] - ], - make_dict [] + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |), + M.get_name (| globals, "level" |) |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "AssertionError" |)) |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "key" |) + |); + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "AssertionError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "key" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| + M.get_subscript (| + M.get_name (| globals, "branches" |), + M.get_subscript (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "level" |) + |) + |), + M.get_name (| globals, "key" |) + |), + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "key" |) + |) + |) in M.pure Constant.None_ )) |) in - let value := - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.assign (| - M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) - |) in + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "BranchNode" |), diff --git a/CoqOfPython/ethereum/muir_glacier/utils/__init__.v b/CoqOfPython/ethereum/muir_glacier/utils/__init__.v index 1baedea..d8eb235 100644 --- a/CoqOfPython/ethereum/muir_glacier/utils/__init__.v +++ b/CoqOfPython/ethereum/muir_glacier/utils/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.muir_glacier.utils.__init__". Definition expr_1 : Value.t := Constant.str " diff --git a/CoqOfPython/ethereum/muir_glacier/utils/address.v b/CoqOfPython/ethereum/muir_glacier/utils/address.v index 5e9649a..d56d7fd 100644 --- a/CoqOfPython/ethereum/muir_glacier/utils/address.v +++ b/CoqOfPython/ethereum/muir_glacier/utils/address.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.muir_glacier.utils.address". Definition expr_1 : Value.t := Constant.str " @@ -18,33 +18,23 @@ Address specific functions used in this muir_glacier version of specification. ". -Require typing. -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". +Axiom typing_imports : + AreImported globals "typing" [ "Union" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes32"; "Uint" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_left_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. -Require ethereum.muir_glacier.fork_types. -Axiom ethereum_muir_glacier_fork_types_Address : - IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "Address". +Axiom ethereum_muir_glacier_fork_types_imports : + AreImported globals "ethereum.muir_glacier.fork_types" [ "Address" ]. Definition to_address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -66,11 +56,16 @@ Definition to_address : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "Address" |), make_list [ - M.get_subscript (| M.call (| - M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), - make_list [], - make_dict [] - |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) + M.slice (| + M.call (| + M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), + UnOp.sub (| Constant.int 20 |), + Constant.None_, + Constant.None_ + |) ], make_dict [] |) @@ -114,7 +109,12 @@ Definition compute_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "computed_address" |), + UnOp.sub (| Constant.int 20 |), + Constant.None_, + Constant.None_ + |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -182,7 +182,12 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "computed_address" |), + UnOp.sub (| Constant.int 20 |), + Constant.None_, + Constant.None_ + |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/muir_glacier/utils/hexadecimal.v b/CoqOfPython/ethereum/muir_glacier/utils/hexadecimal.v index 267f06f..b4ee57d 100644 --- a/CoqOfPython/ethereum/muir_glacier/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/muir_glacier/utils/hexadecimal.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.muir_glacier.utils.hexadecimal". Definition expr_1 : Value.t := Constant.str " @@ -18,17 +18,11 @@ Hexadecimal utility functions used in this specification, specific to Muir Glacier types. ". -Require ethereum.utils.hexadecimal. -Axiom ethereum_utils_hexadecimal_remove_hex_prefix : - IsGlobalAlias globals ethereum.utils.hexadecimal.globals "remove_hex_prefix". - -Require ethereum.muir_glacier.fork_types. -Axiom ethereum_muir_glacier_fork_types_Address : - IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "Address". -Axiom ethereum_muir_glacier_fork_types_Bloom : - IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "Bloom". -Axiom ethereum_muir_glacier_fork_types_Root : - IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "Root". +Axiom ethereum_utils_hexadecimal_imports : + AreImported globals "ethereum.utils.hexadecimal" [ "remove_hex_prefix" ]. + +Axiom ethereum_muir_glacier_fork_types_imports : + AreImported globals "ethereum.muir_glacier.fork_types" [ "Address"; "Bloom"; "Root" ]. Definition hex_to_root : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/muir_glacier/utils/message.v b/CoqOfPython/ethereum/muir_glacier/utils/message.v index 47321ef..dede9cd 100644 --- a/CoqOfPython/ethereum/muir_glacier/utils/message.v +++ b/CoqOfPython/ethereum/muir_glacier/utils/message.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.muir_glacier.utils.message". Definition expr_1 : Value.t := Constant.str " @@ -18,39 +18,23 @@ Message specific functions used in this muir_glacier version of specification. ". -Require typing. -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". +Axiom typing_imports : + AreImported globals "typing" [ "Optional"; "Union" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint" ]. -Require ethereum.muir_glacier.fork_types. -Axiom ethereum_muir_glacier_fork_types_Address : - IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "Address". +Axiom ethereum_muir_glacier_fork_types_imports : + AreImported globals "ethereum.muir_glacier.fork_types" [ "Address" ]. -Require ethereum.muir_glacier.state. -Axiom ethereum_muir_glacier_state_get_account : - IsGlobalAlias globals ethereum.muir_glacier.state.globals "get_account". +Axiom ethereum_muir_glacier_state_imports : + AreImported globals "ethereum.muir_glacier.state" [ "get_account" ]. -Require ethereum.muir_glacier.vm.__init__. -Axiom ethereum_muir_glacier_vm___init___Environment : - IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Environment". -Axiom ethereum_muir_glacier_vm___init___Message : - IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Message". +Axiom ethereum_muir_glacier_vm_imports : + AreImported globals "ethereum.muir_glacier.vm" [ "Environment"; "Message" ]. -Require ethereum.muir_glacier.utils.address. -Axiom ethereum_muir_glacier_utils_address_compute_contract_address : - IsGlobalAlias globals ethereum.muir_glacier.utils.address.globals "compute_contract_address". +Axiom ethereum_muir_glacier_utils_address_imports : + AreImported globals "ethereum.muir_glacier.utils.address" [ "compute_contract_address" ]. Definition prepare_message : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -183,7 +167,7 @@ Definition prepare_message : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "Target must be address or empty bytes" diff --git a/CoqOfPython/ethereum/muir_glacier/vm/__init__.v b/CoqOfPython/ethereum/muir_glacier/vm/__init__.v index 48b9cbd..ebce706 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/__init__.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.muir_glacier.vm.__init__". Definition expr_1 : Value.t := Constant.str " @@ -18,55 +18,29 @@ The abstract computer which runs the code stored in an `.fork_types.Account`. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". - -Require ethereum.base_types. -Axiom ethereum_base_types_U64 : - IsGlobalAlias globals ethereum.base_types.globals "U64". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". - -Require ethereum.muir_glacier.blocks. -Axiom ethereum_muir_glacier_blocks_Log : - IsGlobalAlias globals ethereum.muir_glacier.blocks.globals "Log". - -Require ethereum.muir_glacier.fork_types. -Axiom ethereum_muir_glacier_fork_types_Address : - IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "Address". - -Require ethereum.muir_glacier.state. -Axiom ethereum_muir_glacier_state_State : - IsGlobalAlias globals ethereum.muir_glacier.state.globals "State". -Axiom ethereum_muir_glacier_state_account_exists_and_is_empty : - IsGlobalAlias globals ethereum.muir_glacier.state.globals "account_exists_and_is_empty". - -Require ethereum.muir_glacier.vm.precompiled_contracts.__init__. -Axiom ethereum_muir_glacier_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : - IsGlobalAlias globals ethereum.muir_glacier.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple"; "Union" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U64"; "U256"; "Bytes"; "Bytes0"; "Uint" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. + +Axiom ethereum_muir_glacier_blocks_imports : + AreImported globals "ethereum.muir_glacier.blocks" [ "Log" ]. + +Axiom ethereum_muir_glacier_fork_types_imports : + AreImported globals "ethereum.muir_glacier.fork_types" [ "Address" ]. + +Axiom ethereum_muir_glacier_state_imports : + AreImported globals "ethereum.muir_glacier.state" [ "State"; "account_exists_and_is_empty" ]. + +Axiom ethereum_muir_glacier_vm_precompiled_contracts_imports : + AreImported globals "ethereum.muir_glacier.vm.precompiled_contracts" [ "RIPEMD160_ADDRESS" ]. Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] @@ -187,7 +161,7 @@ Definition incorporate_child_on_error : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "RIPEMD160_ADDRESS" |), M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) |), diff --git a/CoqOfPython/ethereum/muir_glacier/vm/exceptions.v b/CoqOfPython/ethereum/muir_glacier/vm/exceptions.v index 8560cef..cff930b 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/exceptions.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/exceptions.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.muir_glacier.vm.exceptions". Definition expr_1 : Value.t := Constant.str " @@ -17,9 +17,8 @@ Introduction Exceptions which cause the EVM to halt exceptionally. ". -Require ethereum.exceptions. -Axiom ethereum_exceptions_EthereumException : - IsGlobalAlias globals ethereum.exceptions.globals "EthereumException". +Axiom ethereum_exceptions_imports : + AreImported globals "ethereum.exceptions" [ "EthereumException" ]. Definition ExceptionalHalt : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/muir_glacier/vm/gas.v b/CoqOfPython/ethereum/muir_glacier/vm/gas.v index 3c89b66..3597875 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/gas.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/gas.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.muir_glacier.vm.gas". Definition expr_1 : Value.t := Constant.str " @@ -17,39 +17,26 @@ Introduction EVM gas constants and calculators. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Tuple" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. -Require ethereum.trace. -Axiom ethereum_trace_GasAndRefund : - IsGlobalAlias globals ethereum.trace.globals "GasAndRefund". -Axiom ethereum_trace_evm_trace : - IsGlobalAlias globals ethereum.trace.globals "evm_trace". +Axiom ethereum_trace_imports : + AreImported globals "ethereum.trace" [ "GasAndRefund"; "evm_trace" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.muir_glacier.vm.__init__. -Axiom ethereum_muir_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Evm". +Axiom ethereum_muir_glacier_vm_imports : + AreImported globals "ethereum.muir_glacier.vm" [ "Evm" ]. -Require ethereum.muir_glacier.vm.exceptions. -Axiom ethereum_muir_glacier_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.muir_glacier.vm.exceptions.globals "OutOfGasError". +Axiom ethereum_muir_glacier_vm_exceptions_imports : + AreImported globals "ethereum.muir_glacier.vm.exceptions" [ "OutOfGasError" ]. Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -538,7 +525,7 @@ Definition charge_gas : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -655,105 +642,114 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := ], make_dict [] |) in - For make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ] in M.get_name (| globals, "extensions" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "size" |), - Constant.int 0 - |), - (* then *) + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ], + M.get_name (| globals, "extensions" |), ltac:(M.monadic ( - let _ := M.continue (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let before_size := - M.call (| - M.get_name (| globals, "ceil32" |), - make_list [ - M.get_name (| globals, "current_size" |) - ], - make_dict [] - |) in - let after_size := - M.call (| - M.get_name (| globals, "ceil32" |), - make_list [ - BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "size" |), + Constant.int 0 |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.lt_e (| - M.get_name (| globals, "after_size" |), - M.get_name (| globals, "before_size" |) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.continue (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let size_to_extend := BinOp.add - BinOp.sub (| + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let before_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "current_size" |) + ], + make_dict [] + |) in + let after_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let size_to_extend := BinOp.add + BinOp.sub (| M.get_name (| globals, "after_size" |), M.get_name (| globals, "before_size" |) |) - BinOp.sub (| + BinOp.sub (| M.get_name (| globals, "after_size" |), M.get_name (| globals, "before_size" |) |) in - let already_paid := - M.call (| - M.get_name (| globals, "calculate_memory_gas_cost" |), - make_list [ - M.get_name (| globals, "before_size" |) - ], - make_dict [] - |) in - let total_cost := - M.call (| - M.get_name (| globals, "calculate_memory_gas_cost" |), - make_list [ - M.get_name (| globals, "after_size" |) - ], - make_dict [] - |) in - let to_be_paid := BinOp.add - BinOp.sub (| + let already_paid := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "before_size" |) + ], + make_dict [] + |) in + let total_cost := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "after_size" |) + ], + make_dict [] + |) in + let to_be_paid := BinOp.add + BinOp.sub (| M.get_name (| globals, "total_cost" |), M.get_name (| globals, "already_paid" |) |) - BinOp.sub (| + BinOp.sub (| M.get_name (| globals, "total_cost" |), M.get_name (| globals, "already_paid" |) |) in - let current_size := - M.get_name (| globals, "after_size" |) in - EndFor. + let current_size := + M.get_name (| globals, "after_size" |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ExtendMemory" |), diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/__init__.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/__init__.v index a916d0e..e9a8f65 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/__init__.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.muir_glacier.vm.instructions.__init__". Definition expr_1 : Value.t := Constant.str " @@ -20,59 +20,44 @@ implementations. (* At top_level_stmt: unsupported node type: Import *) -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict" ]. -Require ethereum.muir_glacier.vm.instructions.__init__. -Axiom ethereum_muir_glacier_vm_instructions___init___arithmetic : - IsGlobalAlias globals ethereum.muir_glacier.vm.instructions.__init__.globals "arithmetic". +Axiom ethereum_muir_glacier_vm_instructions_imports : + AreImported globals "ethereum.muir_glacier.vm.instructions" [ "arithmetic" ]. -Require ethereum.muir_glacier.vm.instructions.__init__. -Axiom ethereum_muir_glacier_vm_instructions___init___bitwise : - IsGlobalAlias globals ethereum.muir_glacier.vm.instructions.__init__.globals "bitwise". +Axiom ethereum_muir_glacier_vm_instructions_imports : + AreImported globals "ethereum.muir_glacier.vm.instructions" [ "bitwise" ]. -Require ethereum.muir_glacier.vm.instructions.__init__. -Axiom ethereum_muir_glacier_vm_instructions___init___block : - IsGlobalAlias globals ethereum.muir_glacier.vm.instructions.__init__.globals "block". +Axiom ethereum_muir_glacier_vm_instructions_imports : + AreImported globals "ethereum.muir_glacier.vm.instructions" [ "block" ]. -Require ethereum.muir_glacier.vm.instructions.__init__. -Axiom ethereum_muir_glacier_vm_instructions___init___comparison : - IsGlobalAlias globals ethereum.muir_glacier.vm.instructions.__init__.globals "comparison". +Axiom ethereum_muir_glacier_vm_instructions_imports : + AreImported globals "ethereum.muir_glacier.vm.instructions" [ "comparison" ]. -Require ethereum.muir_glacier.vm.instructions.__init__. -Axiom ethereum_muir_glacier_vm_instructions___init___control_flow : - IsGlobalAlias globals ethereum.muir_glacier.vm.instructions.__init__.globals "control_flow". +Axiom ethereum_muir_glacier_vm_instructions_imports : + AreImported globals "ethereum.muir_glacier.vm.instructions" [ "control_flow" ]. -Require ethereum.muir_glacier.vm.instructions.__init__. -Axiom ethereum_muir_glacier_vm_instructions___init___environment : - IsGlobalAlias globals ethereum.muir_glacier.vm.instructions.__init__.globals "environment". +Axiom ethereum_muir_glacier_vm_instructions_imports : + AreImported globals "ethereum.muir_glacier.vm.instructions" [ "environment" ]. -Require ethereum.muir_glacier.vm.instructions.__init__. -Axiom ethereum_muir_glacier_vm_instructions___init___keccak : - IsGlobalAlias globals ethereum.muir_glacier.vm.instructions.__init__.globals "keccak". +Axiom ethereum_muir_glacier_vm_instructions_imports : + AreImported globals "ethereum.muir_glacier.vm.instructions" [ "keccak" ]. -Require ethereum.muir_glacier.vm.instructions.__init__. -Axiom ethereum_muir_glacier_vm_instructions___init___log : - IsGlobalAlias globals ethereum.muir_glacier.vm.instructions.__init__.globals "log". +Axiom ethereum_muir_glacier_vm_instructions_imports : + AreImported globals "ethereum.muir_glacier.vm.instructions" [ "log" ]. -Require ethereum.muir_glacier.vm.instructions.__init__. -Axiom ethereum_muir_glacier_vm_instructions___init___memory : - IsGlobalAlias globals ethereum.muir_glacier.vm.instructions.__init__.globals "memory". +Axiom ethereum_muir_glacier_vm_instructions_imports : + AreImported globals "ethereum.muir_glacier.vm.instructions" [ "memory" ]. -Require ethereum.muir_glacier.vm.instructions.__init__. -Axiom ethereum_muir_glacier_vm_instructions___init___stack : - IsGlobalAlias globals ethereum.muir_glacier.vm.instructions.__init__.globals "stack". +Axiom ethereum_muir_glacier_vm_instructions_imports : + AreImported globals "ethereum.muir_glacier.vm.instructions" [ "stack" ]. -Require ethereum.muir_glacier.vm.instructions.__init__. -Axiom ethereum_muir_glacier_vm_instructions___init___storage : - IsGlobalAlias globals ethereum.muir_glacier.vm.instructions.__init__.globals "storage". +Axiom ethereum_muir_glacier_vm_instructions_imports : + AreImported globals "ethereum.muir_glacier.vm.instructions" [ "storage" ]. -Require ethereum.muir_glacier.vm.instructions.__init__. -Axiom ethereum_muir_glacier_vm_instructions___init___system : - IsGlobalAlias globals ethereum.muir_glacier.vm.instructions.__init__.globals "system". +Axiom ethereum_muir_glacier_vm_instructions_imports : + AreImported globals "ethereum.muir_glacier.vm.instructions" [ "system" ]. Definition Ops : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/arithmetic.v index 704eed9..d28e88d 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/arithmetic.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.muir_glacier.vm.instructions.arithmetic". Definition expr_1 : Value.t := Constant.str " @@ -17,43 +17,20 @@ Introduction Implementations of the EVM Arithmetic instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U255_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U255_CEIL_VALUE". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_U256_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U255_CEIL_VALUE"; "U256"; "U256_CEIL_VALUE"; "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_get_sign : - IsGlobalAlias globals ethereum.utils.numeric.globals "get_sign". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "get_sign" ]. -Require ethereum.muir_glacier.vm.__init__. -Axiom ethereum_muir_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Evm". +Axiom ethereum_muir_glacier_vm_imports : + AreImported globals "ethereum.muir_glacier.vm" [ "Evm" ]. -Require ethereum.muir_glacier.vm.gas. -Axiom ethereum_muir_glacier_vm_gas_GAS_EXPONENTIATION : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_EXPONENTIATION". -Axiom ethereum_muir_glacier_vm_gas_GAS_EXPONENTIATION_PER_BYTE : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_EXPONENTIATION_PER_BYTE". -Axiom ethereum_muir_glacier_vm_gas_GAS_LOW : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_LOW". -Axiom ethereum_muir_glacier_vm_gas_GAS_MID : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_MID". -Axiom ethereum_muir_glacier_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_muir_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "charge_gas". +Axiom ethereum_muir_glacier_vm_gas_imports : + AreImported globals "ethereum.muir_glacier.vm.gas" [ "GAS_EXPONENTIATION"; "GAS_EXPONENTIATION_PER_BYTE"; "GAS_LOW"; "GAS_MID"; "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.muir_glacier.vm.stack. -Axiom ethereum_muir_glacier_vm_stack_pop : - IsGlobalAlias globals ethereum.muir_glacier.vm.stack.globals "pop". -Axiom ethereum_muir_glacier_vm_stack_push : - IsGlobalAlias globals ethereum.muir_glacier.vm.stack.globals "push". +Axiom ethereum_muir_glacier_vm_stack_imports : + AreImported globals "ethereum.muir_glacier.vm.stack" [ "pop"; "push" ]. Definition add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -1030,19 +1007,27 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let value_bytes := - M.get_subscript (| M.get_name (| globals, "value_bytes" |), M.slice (| BinOp.sub (| - Constant.int 31, - M.call (| - M.get_name (| globals, "int" |), - make_list [ - M.get_name (| globals, "byte_num" |) - ], - make_dict [] - |) - |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "value_bytes" |), + BinOp.sub (| + Constant.int 31, + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "byte_num" |) + ], + make_dict [] + |) + |), + Constant.None_, + Constant.None_ + |) in let sign_bit := BinOp.r_shift (| - M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), + M.get_subscript (| + M.get_name (| globals, "value_bytes" |), + Constant.int 0 + |), Constant.int 7 |) in let _ := diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/bitwise.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/bitwise.v index a13ee9e..a68dc9b 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/bitwise.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.muir_glacier.vm.instructions.bitwise". Definition expr_1 : Value.t := Constant.str " @@ -17,27 +17,17 @@ Introduction Implementations of the EVM bitwise instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_U256_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "U256_CEIL_VALUE" ]. -Require ethereum.muir_glacier.vm.__init__. -Axiom ethereum_muir_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Evm". +Axiom ethereum_muir_glacier_vm_imports : + AreImported globals "ethereum.muir_glacier.vm" [ "Evm" ]. -Require ethereum.muir_glacier.vm.gas. -Axiom ethereum_muir_glacier_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_muir_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "charge_gas". +Axiom ethereum_muir_glacier_vm_gas_imports : + AreImported globals "ethereum.muir_glacier.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.muir_glacier.vm.stack. -Axiom ethereum_muir_glacier_vm_stack_pop : - IsGlobalAlias globals ethereum.muir_glacier.vm.stack.globals "pop". -Axiom ethereum_muir_glacier_vm_stack_push : - IsGlobalAlias globals ethereum.muir_glacier.vm.stack.globals "push". +Axiom ethereum_muir_glacier_vm_stack_imports : + AreImported globals "ethereum.muir_glacier.vm.stack" [ "pop"; "push" ]. Definition bitwise_and : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/block.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/block.v index 378f5fb..404f2ac 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/block.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/block.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.muir_glacier.vm.instructions.block". Definition expr_1 : Value.t := Constant.str " @@ -17,27 +17,17 @@ Introduction Implementations of the EVM block instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.muir_glacier.vm.__init__. -Axiom ethereum_muir_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Evm". +Axiom ethereum_muir_glacier_vm_imports : + AreImported globals "ethereum.muir_glacier.vm" [ "Evm" ]. -Require ethereum.muir_glacier.vm.gas. -Axiom ethereum_muir_glacier_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_BASE". -Axiom ethereum_muir_glacier_vm_gas_GAS_BLOCK_HASH : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_BLOCK_HASH". -Axiom ethereum_muir_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "charge_gas". +Axiom ethereum_muir_glacier_vm_gas_imports : + AreImported globals "ethereum.muir_glacier.vm.gas" [ "GAS_BASE"; "GAS_BLOCK_HASH"; "charge_gas" ]. -Require ethereum.muir_glacier.vm.stack. -Axiom ethereum_muir_glacier_vm_stack_pop : - IsGlobalAlias globals ethereum.muir_glacier.vm.stack.globals "pop". -Axiom ethereum_muir_glacier_vm_stack_push : - IsGlobalAlias globals ethereum.muir_glacier.vm.stack.globals "push". +Axiom ethereum_muir_glacier_vm_stack_imports : + AreImported globals "ethereum.muir_glacier.vm.stack" [ "pop"; "push" ]. Definition block_hash : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -94,10 +84,13 @@ Definition block_hash : Value.t -> Value.t -> M := (* else *) )), ltac:(M.monadic ( let hash := - M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), - M.get_name (| globals, "block_number" |) - |) |) |) in + M.get_subscript (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), + UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + M.get_name (| globals, "block_number" |) + |) |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/comparison.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/comparison.v index 07e7c06..881d3fd 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/comparison.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.muir_glacier.vm.instructions.comparison". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementations of the EVM Comparison instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.muir_glacier.vm.__init__. -Axiom ethereum_muir_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Evm". +Axiom ethereum_muir_glacier_vm_imports : + AreImported globals "ethereum.muir_glacier.vm" [ "Evm" ]. -Require ethereum.muir_glacier.vm.gas. -Axiom ethereum_muir_glacier_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_muir_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "charge_gas". +Axiom ethereum_muir_glacier_vm_gas_imports : + AreImported globals "ethereum.muir_glacier.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.muir_glacier.vm.stack. -Axiom ethereum_muir_glacier_vm_stack_pop : - IsGlobalAlias globals ethereum.muir_glacier.vm.stack.globals "pop". -Axiom ethereum_muir_glacier_vm_stack_push : - IsGlobalAlias globals ethereum.muir_glacier.vm.stack.globals "push". +Axiom ethereum_muir_glacier_vm_stack_imports : + AreImported globals "ethereum.muir_glacier.vm.stack" [ "pop"; "push" ]. Definition less_than : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/control_flow.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/control_flow.v index 09e43fc..486d6cd 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/control_flow.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.muir_glacier.vm.instructions.control_flow". Definition expr_1 : Value.t := Constant.str " @@ -17,37 +17,20 @@ Introduction Implementations of the EVM control flow instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. -Require ethereum.muir_glacier.vm.gas. -Axiom ethereum_muir_glacier_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_BASE". -Axiom ethereum_muir_glacier_vm_gas_GAS_HIGH : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_HIGH". -Axiom ethereum_muir_glacier_vm_gas_GAS_JUMPDEST : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_JUMPDEST". -Axiom ethereum_muir_glacier_vm_gas_GAS_MID : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_MID". -Axiom ethereum_muir_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "charge_gas". +Axiom ethereum_muir_glacier_vm_gas_imports : + AreImported globals "ethereum.muir_glacier.vm.gas" [ "GAS_BASE"; "GAS_HIGH"; "GAS_JUMPDEST"; "GAS_MID"; "charge_gas" ]. -Require ethereum.muir_glacier.vm.__init__. -Axiom ethereum_muir_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Evm". +Axiom ethereum_muir_glacier_vm_imports : + AreImported globals "ethereum.muir_glacier.vm" [ "Evm" ]. -Require ethereum.muir_glacier.vm.exceptions. -Axiom ethereum_muir_glacier_vm_exceptions_InvalidJumpDestError : - IsGlobalAlias globals ethereum.muir_glacier.vm.exceptions.globals "InvalidJumpDestError". +Axiom ethereum_muir_glacier_vm_exceptions_imports : + AreImported globals "ethereum.muir_glacier.vm.exceptions" [ "InvalidJumpDestError" ]. -Require ethereum.muir_glacier.vm.stack. -Axiom ethereum_muir_glacier_vm_stack_pop : - IsGlobalAlias globals ethereum.muir_glacier.vm.stack.globals "pop". -Axiom ethereum_muir_glacier_vm_stack_push : - IsGlobalAlias globals ethereum.muir_glacier.vm.stack.globals "push". +Axiom ethereum_muir_glacier_vm_stack_imports : + AreImported globals "ethereum.muir_glacier.vm.stack" [ "pop"; "push" ]. Definition stop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -117,7 +100,7 @@ Definition jump : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "InvalidJumpDestError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -205,7 +188,7 @@ Definition jumpi : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "InvalidJumpDestError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/environment.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/environment.v index b766ae2..77a757c 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/environment.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.muir_glacier.vm.instructions.environment". Definition expr_1 : Value.t := Constant.str " @@ -17,77 +17,41 @@ Introduction Implementations of the EVM environment related instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". - -Require ethereum.muir_glacier.fork_types. -Axiom ethereum_muir_glacier_fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "EMPTY_ACCOUNT". - -Require ethereum.muir_glacier.state. -Axiom ethereum_muir_glacier_state_get_account : - IsGlobalAlias globals ethereum.muir_glacier.state.globals "get_account". - -Require ethereum.muir_glacier.utils.address. -Axiom ethereum_muir_glacier_utils_address_to_address : - IsGlobalAlias globals ethereum.muir_glacier.utils.address.globals "to_address". - -Require ethereum.muir_glacier.vm.memory. -Axiom ethereum_muir_glacier_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.muir_glacier.vm.memory.globals "buffer_read". -Axiom ethereum_muir_glacier_vm_memory_memory_write : - IsGlobalAlias globals ethereum.muir_glacier.vm.memory.globals "memory_write". - -Require ethereum.muir_glacier.vm.__init__. -Axiom ethereum_muir_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Evm". - -Require ethereum.muir_glacier.vm.exceptions. -Axiom ethereum_muir_glacier_vm_exceptions_OutOfBoundsRead : - IsGlobalAlias globals ethereum.muir_glacier.vm.exceptions.globals "OutOfBoundsRead". - -Require ethereum.muir_glacier.vm.gas. -Axiom ethereum_muir_glacier_vm_gas_GAS_BALANCE : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_BALANCE". -Axiom ethereum_muir_glacier_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_BASE". -Axiom ethereum_muir_glacier_vm_gas_GAS_CODE_HASH : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_CODE_HASH". -Axiom ethereum_muir_glacier_vm_gas_GAS_COPY : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_COPY". -Axiom ethereum_muir_glacier_vm_gas_GAS_EXTERNAL : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_EXTERNAL". -Axiom ethereum_muir_glacier_vm_gas_GAS_FAST_STEP : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_FAST_STEP". -Axiom ethereum_muir_glacier_vm_gas_GAS_RETURN_DATA_COPY : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_RETURN_DATA_COPY". -Axiom ethereum_muir_glacier_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_muir_glacier_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_muir_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "charge_gas". - -Require ethereum.muir_glacier.vm.stack. -Axiom ethereum_muir_glacier_vm_stack_pop : - IsGlobalAlias globals ethereum.muir_glacier.vm.stack.globals "pop". -Axiom ethereum_muir_glacier_vm_stack_push : - IsGlobalAlias globals ethereum.muir_glacier.vm.stack.globals "push". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. + +Axiom ethereum_muir_glacier_fork_types_imports : + AreImported globals "ethereum.muir_glacier.fork_types" [ "EMPTY_ACCOUNT" ]. + +Axiom ethereum_muir_glacier_state_imports : + AreImported globals "ethereum.muir_glacier.state" [ "get_account" ]. + +Axiom ethereum_muir_glacier_utils_address_imports : + AreImported globals "ethereum.muir_glacier.utils.address" [ "to_address" ]. + +Axiom ethereum_muir_glacier_vm_memory_imports : + AreImported globals "ethereum.muir_glacier.vm.memory" [ "buffer_read"; "memory_write" ]. + +Axiom ethereum_muir_glacier_vm_imports : + AreImported globals "ethereum.muir_glacier.vm" [ "Evm" ]. + +Axiom ethereum_muir_glacier_vm_exceptions_imports : + AreImported globals "ethereum.muir_glacier.vm.exceptions" [ "OutOfBoundsRead" ]. + +Axiom ethereum_muir_glacier_vm_gas_imports : + AreImported globals "ethereum.muir_glacier.vm.gas" [ "GAS_BALANCE"; "GAS_BASE"; "GAS_CODE_HASH"; "GAS_COPY"; "GAS_EXTERNAL"; "GAS_FAST_STEP"; "GAS_RETURN_DATA_COPY"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. + +Axiom ethereum_muir_glacier_vm_stack_imports : + AreImported globals "ethereum.muir_glacier.vm.stack" [ "pop"; "push" ]. Definition address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -1134,10 +1098,15 @@ Definition returndatacopy : Value.t -> Value.t -> M := |) |) in let value := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.slice (| M.get_name (| globals, "return_data_start_position" |), BinOp.add (| + M.slice (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |), - M.get_name (| globals, "size" |) - |) |) |) in + BinOp.add (| + M.get_name (| globals, "return_data_start_position" |), + M.get_name (| globals, "size" |) + |), + Constant.None_ + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/keccak.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/keccak.v index 22153d9..788dc38 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/keccak.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.muir_glacier.vm.instructions.keccak". Definition expr_1 : Value.t := Constant.str " @@ -17,43 +17,26 @@ Introduction Implementations of the EVM keccak instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". - -Require ethereum.muir_glacier.vm.__init__. -Axiom ethereum_muir_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Evm". - -Require ethereum.muir_glacier.vm.gas. -Axiom ethereum_muir_glacier_vm_gas_GAS_KECCAK256 : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_KECCAK256". -Axiom ethereum_muir_glacier_vm_gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_KECCAK256_WORD". -Axiom ethereum_muir_glacier_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_muir_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "charge_gas". - -Require ethereum.muir_glacier.vm.memory. -Axiom ethereum_muir_glacier_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.muir_glacier.vm.memory.globals "memory_read_bytes". - -Require ethereum.muir_glacier.vm.stack. -Axiom ethereum_muir_glacier_vm_stack_pop : - IsGlobalAlias globals ethereum.muir_glacier.vm.stack.globals "pop". -Axiom ethereum_muir_glacier_vm_stack_push : - IsGlobalAlias globals ethereum.muir_glacier.vm.stack.globals "push". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. + +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. + +Axiom ethereum_muir_glacier_vm_imports : + AreImported globals "ethereum.muir_glacier.vm" [ "Evm" ]. + +Axiom ethereum_muir_glacier_vm_gas_imports : + AreImported globals "ethereum.muir_glacier.vm.gas" [ "GAS_KECCAK256"; "GAS_KECCAK256_WORD"; "calculate_gas_extend_memory"; "charge_gas" ]. + +Axiom ethereum_muir_glacier_vm_memory_imports : + AreImported globals "ethereum.muir_glacier.vm.memory" [ "memory_read_bytes" ]. + +Axiom ethereum_muir_glacier_vm_stack_imports : + AreImported globals "ethereum.muir_glacier.vm.stack" [ "pop"; "push" ]. Definition keccak : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/log.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/log.v index 592dfcf..e21e74a 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/log.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/log.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.muir_glacier.vm.instructions.log". Definition expr_1 : Value.t := Constant.str " @@ -17,49 +17,32 @@ Introduction Implementations of the EVM logging instructions. ". -Require functools. -Axiom functools_partial : - IsGlobalAlias globals functools.globals "partial". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.muir_glacier.blocks. -Axiom ethereum_muir_glacier_blocks_Log : - IsGlobalAlias globals ethereum.muir_glacier.blocks.globals "Log". - -Require ethereum.muir_glacier.vm.__init__. -Axiom ethereum_muir_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Evm". - -Require ethereum.muir_glacier.vm.exceptions. -Axiom ethereum_muir_glacier_vm_exceptions_WriteInStaticContext : - IsGlobalAlias globals ethereum.muir_glacier.vm.exceptions.globals "WriteInStaticContext". - -Require ethereum.muir_glacier.vm.gas. -Axiom ethereum_muir_glacier_vm_gas_GAS_LOG : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_LOG". -Axiom ethereum_muir_glacier_vm_gas_GAS_LOG_DATA : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_LOG_DATA". -Axiom ethereum_muir_glacier_vm_gas_GAS_LOG_TOPIC : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_LOG_TOPIC". -Axiom ethereum_muir_glacier_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_muir_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "charge_gas". - -Require ethereum.muir_glacier.vm.memory. -Axiom ethereum_muir_glacier_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.muir_glacier.vm.memory.globals "memory_read_bytes". - -Require ethereum.muir_glacier.vm.stack. -Axiom ethereum_muir_glacier_vm_stack_pop : - IsGlobalAlias globals ethereum.muir_glacier.vm.stack.globals "pop". +Axiom functools_imports : + AreImported globals "functools" [ "partial" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_muir_glacier_blocks_imports : + AreImported globals "ethereum.muir_glacier.blocks" [ "Log" ]. + +Axiom ethereum_muir_glacier_vm_imports : + AreImported globals "ethereum.muir_glacier.vm" [ "Evm" ]. + +Axiom ethereum_muir_glacier_vm_exceptions_imports : + AreImported globals "ethereum.muir_glacier.vm.exceptions" [ "WriteInStaticContext" ]. + +Axiom ethereum_muir_glacier_vm_gas_imports : + AreImported globals "ethereum.muir_glacier.vm.gas" [ "GAS_LOG"; "GAS_LOG_DATA"; "GAS_LOG_TOPIC"; "calculate_gas_extend_memory"; "charge_gas" ]. + +Axiom ethereum_muir_glacier_vm_memory_imports : + AreImported globals "ethereum.muir_glacier.vm.memory" [ "memory_read_bytes" ]. + +Axiom ethereum_muir_glacier_vm_stack_imports : + AreImported globals "ethereum.muir_glacier.vm.stack" [ "pop" ]. Definition log_n : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -96,33 +79,42 @@ Definition log_n : Value.t -> Value.t -> M := |) in let topics := make_list [] in - For M.get_name (| globals, "_" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - M.get_name (| globals, "num_topics" |) - ], - make_dict [] - |) do - let topic := + let _ := + M.for_ (| + M.get_name (| globals, "_" |), M.call (| - M.get_field (| M.call (| - M.get_name (| globals, "pop" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] - |), "to_be_bytes32" |), - make_list [], - make_dict [] - |) in - let _ := M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "num_topics" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let topic := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| M.get_field (| M.get_name (| globals, "topics" |), "append" |), make_list [ M.get_name (| globals, "topic" |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let extend_memory := M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/memory.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/memory.v index 93d2906..2413644 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/memory.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.muir_glacier.vm.instructions.memory". Definition expr_1 : Value.t := Constant.str " @@ -17,37 +17,20 @@ Introduction Implementations of the EVM Memory instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes" ]. -Require ethereum.muir_glacier.vm.__init__. -Axiom ethereum_muir_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Evm". +Axiom ethereum_muir_glacier_vm_imports : + AreImported globals "ethereum.muir_glacier.vm" [ "Evm" ]. -Require ethereum.muir_glacier.vm.gas. -Axiom ethereum_muir_glacier_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_BASE". -Axiom ethereum_muir_glacier_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_muir_glacier_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_muir_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "charge_gas". +Axiom ethereum_muir_glacier_vm_gas_imports : + AreImported globals "ethereum.muir_glacier.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. -Require ethereum.muir_glacier.vm.memory. -Axiom ethereum_muir_glacier_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.muir_glacier.vm.memory.globals "memory_read_bytes". -Axiom ethereum_muir_glacier_vm_memory_memory_write : - IsGlobalAlias globals ethereum.muir_glacier.vm.memory.globals "memory_write". +Axiom ethereum_muir_glacier_vm_memory_imports : + AreImported globals "ethereum.muir_glacier.vm.memory" [ "memory_read_bytes"; "memory_write" ]. -Require ethereum.muir_glacier.vm.stack. -Axiom ethereum_muir_glacier_vm_stack_pop : - IsGlobalAlias globals ethereum.muir_glacier.vm.stack.globals "pop". -Axiom ethereum_muir_glacier_vm_stack_push : - IsGlobalAlias globals ethereum.muir_glacier.vm.stack.globals "push". +Axiom ethereum_muir_glacier_vm_stack_imports : + AreImported globals "ethereum.muir_glacier.vm.stack" [ "pop"; "push" ]. Definition mstore : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/stack.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/stack.v index 8103c7f..84aa293 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/stack.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.muir_glacier.vm.instructions.stack". Definition expr_1 : Value.t := Constant.str " @@ -17,39 +17,26 @@ Introduction Implementations of the EVM stack related instructions. ". -Require functools. -Axiom functools_partial : - IsGlobalAlias globals functools.globals "partial". +Axiom functools_imports : + AreImported globals "functools" [ "partial" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.muir_glacier.vm.__init__. -Axiom ethereum_muir_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Evm". -Axiom ethereum_muir_glacier_vm___init___stack : - IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "stack". +Axiom ethereum_muir_glacier_vm_imports : + AreImported globals "ethereum.muir_glacier.vm" [ "Evm"; "stack" ]. -Require ethereum.muir_glacier.vm.exceptions. -Axiom ethereum_muir_glacier_vm_exceptions_StackUnderflowError : - IsGlobalAlias globals ethereum.muir_glacier.vm.exceptions.globals "StackUnderflowError". +Axiom ethereum_muir_glacier_vm_exceptions_imports : + AreImported globals "ethereum.muir_glacier.vm.exceptions" [ "StackUnderflowError" ]. -Require ethereum.muir_glacier.vm.gas. -Axiom ethereum_muir_glacier_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_BASE". -Axiom ethereum_muir_glacier_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_muir_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "charge_gas". +Axiom ethereum_muir_glacier_vm_gas_imports : + AreImported globals "ethereum.muir_glacier.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.muir_glacier.vm.memory. -Axiom ethereum_muir_glacier_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.muir_glacier.vm.memory.globals "buffer_read". +Axiom ethereum_muir_glacier_vm_memory_imports : + AreImported globals "ethereum.muir_glacier.vm.memory" [ "buffer_read" ]. Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -203,19 +190,22 @@ Definition dup_n : Value.t -> Value.t -> M := make_dict [] |) in let data_to_duplicate := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] + BinOp.sub (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), + Constant.int 1 |), - Constant.int 1 - |), - M.get_name (| globals, "item_number" |) - |) |) in + M.get_name (| globals, "item_number" |) + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "stack" |), "push" |), make_list [ @@ -278,14 +268,26 @@ Definition swap_n : Value.t -> Value.t -> M := make_dict [] |) in let _ := M.assign (| - make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| - UnOp.sub (| Constant.int 1 |), - M.get_name (| globals, "item_number" |) - |) |) ], - make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| - UnOp.sub (| Constant.int 1 |), - M.get_name (| globals, "item_number" |) - |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |) ] + make_tuple [ M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + UnOp.sub (| Constant.int 1 |) + |); M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) + |) ], + make_tuple [ M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) + |); M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + UnOp.sub (| Constant.int 1 |) + |) ] |) in let _ := M.assign_op (| BinOp.add, diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/storage.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/storage.v index 5169683..884a80d 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/storage.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.muir_glacier.vm.instructions.storage". Definition expr_1 : Value.t := Constant.str " @@ -17,47 +17,23 @@ Introduction Implementations of the EVM storage related instructions. ". -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.muir_glacier.state. -Axiom ethereum_muir_glacier_state_get_storage : - IsGlobalAlias globals ethereum.muir_glacier.state.globals "get_storage". -Axiom ethereum_muir_glacier_state_get_storage_original : - IsGlobalAlias globals ethereum.muir_glacier.state.globals "get_storage_original". -Axiom ethereum_muir_glacier_state_set_storage : - IsGlobalAlias globals ethereum.muir_glacier.state.globals "set_storage". +Axiom ethereum_muir_glacier_state_imports : + AreImported globals "ethereum.muir_glacier.state" [ "get_storage"; "get_storage_original"; "set_storage" ]. -Require ethereum.muir_glacier.vm.__init__. -Axiom ethereum_muir_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Evm". +Axiom ethereum_muir_glacier_vm_imports : + AreImported globals "ethereum.muir_glacier.vm" [ "Evm" ]. -Require ethereum.muir_glacier.vm.exceptions. -Axiom ethereum_muir_glacier_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.muir_glacier.vm.exceptions.globals "OutOfGasError". -Axiom ethereum_muir_glacier_vm_exceptions_WriteInStaticContext : - IsGlobalAlias globals ethereum.muir_glacier.vm.exceptions.globals "WriteInStaticContext". +Axiom ethereum_muir_glacier_vm_exceptions_imports : + AreImported globals "ethereum.muir_glacier.vm.exceptions" [ "OutOfGasError"; "WriteInStaticContext" ]. -Require ethereum.muir_glacier.vm.gas. -Axiom ethereum_muir_glacier_vm_gas_GAS_CALL_STIPEND : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_CALL_STIPEND". -Axiom ethereum_muir_glacier_vm_gas_GAS_SLOAD : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_SLOAD". -Axiom ethereum_muir_glacier_vm_gas_GAS_STORAGE_CLEAR_REFUND : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_STORAGE_CLEAR_REFUND". -Axiom ethereum_muir_glacier_vm_gas_GAS_STORAGE_SET : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_STORAGE_SET". -Axiom ethereum_muir_glacier_vm_gas_GAS_STORAGE_UPDATE : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_STORAGE_UPDATE". -Axiom ethereum_muir_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "charge_gas". +Axiom ethereum_muir_glacier_vm_gas_imports : + AreImported globals "ethereum.muir_glacier.vm.gas" [ "GAS_CALL_STIPEND"; "GAS_SLOAD"; "GAS_STORAGE_CLEAR_REFUND"; "GAS_STORAGE_SET"; "GAS_STORAGE_UPDATE"; "charge_gas" ]. -Require ethereum.muir_glacier.vm.stack. -Axiom ethereum_muir_glacier_vm_stack_pop : - IsGlobalAlias globals ethereum.muir_glacier.vm.stack.globals "pop". -Axiom ethereum_muir_glacier_vm_stack_push : - IsGlobalAlias globals ethereum.muir_glacier.vm.stack.globals "push". +Axiom ethereum_muir_glacier_vm_stack_imports : + AreImported globals "ethereum.muir_glacier.vm.stack" [ "pop"; "push" ]. Definition sload : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/system.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/system.v index 1697cea..86d3a13 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/system.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/system.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.muir_glacier.vm.instructions.system". Definition expr_1 : Value.t := Constant.str " @@ -17,103 +17,38 @@ Introduction Implementations of the EVM system related instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.muir_glacier.fork_types. -Axiom ethereum_muir_glacier_fork_types_Address : - IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "Address". +Axiom ethereum_muir_glacier_fork_types_imports : + AreImported globals "ethereum.muir_glacier.fork_types" [ "Address" ]. -Require ethereum.muir_glacier.state. -Axiom ethereum_muir_glacier_state_account_exists_and_is_empty : - IsGlobalAlias globals ethereum.muir_glacier.state.globals "account_exists_and_is_empty". -Axiom ethereum_muir_glacier_state_account_has_code_or_nonce : - IsGlobalAlias globals ethereum.muir_glacier.state.globals "account_has_code_or_nonce". -Axiom ethereum_muir_glacier_state_get_account : - IsGlobalAlias globals ethereum.muir_glacier.state.globals "get_account". -Axiom ethereum_muir_glacier_state_increment_nonce : - IsGlobalAlias globals ethereum.muir_glacier.state.globals "increment_nonce". -Axiom ethereum_muir_glacier_state_is_account_alive : - IsGlobalAlias globals ethereum.muir_glacier.state.globals "is_account_alive". -Axiom ethereum_muir_glacier_state_set_account_balance : - IsGlobalAlias globals ethereum.muir_glacier.state.globals "set_account_balance". +Axiom ethereum_muir_glacier_state_imports : + AreImported globals "ethereum.muir_glacier.state" [ "account_exists_and_is_empty"; "account_has_code_or_nonce"; "get_account"; "increment_nonce"; "is_account_alive"; "set_account_balance" ]. -Require ethereum.muir_glacier.utils.address. -Axiom ethereum_muir_glacier_utils_address_compute_contract_address : - IsGlobalAlias globals ethereum.muir_glacier.utils.address.globals "compute_contract_address". -Axiom ethereum_muir_glacier_utils_address_compute_create2_contract_address : - IsGlobalAlias globals ethereum.muir_glacier.utils.address.globals "compute_create2_contract_address". -Axiom ethereum_muir_glacier_utils_address_to_address : - IsGlobalAlias globals ethereum.muir_glacier.utils.address.globals "to_address". +Axiom ethereum_muir_glacier_utils_address_imports : + AreImported globals "ethereum.muir_glacier.utils.address" [ "compute_contract_address"; "compute_create2_contract_address"; "to_address" ]. -Require ethereum.muir_glacier.vm.__init__. -Axiom ethereum_muir_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Evm". -Axiom ethereum_muir_glacier_vm___init___Message : - IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Message". -Axiom ethereum_muir_glacier_vm___init___incorporate_child_on_error : - IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "incorporate_child_on_error". -Axiom ethereum_muir_glacier_vm___init___incorporate_child_on_success : - IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "incorporate_child_on_success". +Axiom ethereum_muir_glacier_vm_imports : + AreImported globals "ethereum.muir_glacier.vm" [ "Evm"; "Message"; "incorporate_child_on_error"; "incorporate_child_on_success" ]. -Require ethereum.muir_glacier.vm.exceptions. -Axiom ethereum_muir_glacier_vm_exceptions_Revert : - IsGlobalAlias globals ethereum.muir_glacier.vm.exceptions.globals "Revert". -Axiom ethereum_muir_glacier_vm_exceptions_WriteInStaticContext : - IsGlobalAlias globals ethereum.muir_glacier.vm.exceptions.globals "WriteInStaticContext". +Axiom ethereum_muir_glacier_vm_exceptions_imports : + AreImported globals "ethereum.muir_glacier.vm.exceptions" [ "Revert"; "WriteInStaticContext" ]. -Require ethereum.muir_glacier.vm.gas. -Axiom ethereum_muir_glacier_vm_gas_GAS_CALL : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_CALL". -Axiom ethereum_muir_glacier_vm_gas_GAS_CALL_VALUE : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_CALL_VALUE". -Axiom ethereum_muir_glacier_vm_gas_GAS_CREATE : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_CREATE". -Axiom ethereum_muir_glacier_vm_gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_KECCAK256_WORD". -Axiom ethereum_muir_glacier_vm_gas_GAS_NEW_ACCOUNT : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_NEW_ACCOUNT". -Axiom ethereum_muir_glacier_vm_gas_GAS_SELF_DESTRUCT : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_SELF_DESTRUCT". -Axiom ethereum_muir_glacier_vm_gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". -Axiom ethereum_muir_glacier_vm_gas_GAS_ZERO : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_ZERO". -Axiom ethereum_muir_glacier_vm_gas_REFUND_SELF_DESTRUCT : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "REFUND_SELF_DESTRUCT". -Axiom ethereum_muir_glacier_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_muir_glacier_vm_gas_calculate_message_call_gas : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "calculate_message_call_gas". -Axiom ethereum_muir_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "charge_gas". -Axiom ethereum_muir_glacier_vm_gas_max_message_call_gas : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "max_message_call_gas". +Axiom ethereum_muir_glacier_vm_gas_imports : + AreImported globals "ethereum.muir_glacier.vm.gas" [ "GAS_CALL"; "GAS_CALL_VALUE"; "GAS_CREATE"; "GAS_KECCAK256_WORD"; "GAS_NEW_ACCOUNT"; "GAS_SELF_DESTRUCT"; "GAS_SELF_DESTRUCT_NEW_ACCOUNT"; "GAS_ZERO"; "REFUND_SELF_DESTRUCT"; "calculate_gas_extend_memory"; "calculate_message_call_gas"; "charge_gas"; "max_message_call_gas" ]. -Require ethereum.muir_glacier.vm.memory. -Axiom ethereum_muir_glacier_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.muir_glacier.vm.memory.globals "memory_read_bytes". -Axiom ethereum_muir_glacier_vm_memory_memory_write : - IsGlobalAlias globals ethereum.muir_glacier.vm.memory.globals "memory_write". +Axiom ethereum_muir_glacier_vm_memory_imports : + AreImported globals "ethereum.muir_glacier.vm.memory" [ "memory_read_bytes"; "memory_write" ]. -Require ethereum.muir_glacier.vm.stack. -Axiom ethereum_muir_glacier_vm_stack_pop : - IsGlobalAlias globals ethereum.muir_glacier.vm.stack.globals "pop". -Axiom ethereum_muir_glacier_vm_stack_push : - IsGlobalAlias globals ethereum.muir_glacier.vm.stack.globals "push". +Axiom ethereum_muir_glacier_vm_stack_imports : + AreImported globals "ethereum.muir_glacier.vm.stack" [ "pop"; "push" ]. Definition generic_create : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -859,7 +794,12 @@ Definition generic_call : Value.t -> Value.t -> M := make_list [ M.get_field (| M.get_name (| globals, "evm" |), "memory" |); M.get_name (| globals, "memory_output_start_position" |); - M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), M.slice (| Constant.None_, M.get_name (| globals, "actual_output_size" |) |) |) + M.slice (| + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), + Constant.None_, + M.get_name (| globals, "actual_output_size" |), + Constant.None_ + |) ], make_dict [] |) in @@ -1437,20 +1377,28 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in let parent_evm := M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "parent_evm" |) in - While Compare.is_not (| - M.get_name (| globals, "parent_evm" |), - Constant.None_ - |) do - let _ := M.call (| + let _ := + M.while (| + Compare.is_not (| + M.get_name (| globals, "parent_evm" |), + Constant.None_ + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "refunded_accounts" |), "update" |), make_list [ M.get_field (| M.get_name (| globals, "parent_evm" |), "accounts_to_delete" |) ], make_dict [] |) in - let parent_evm := - M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in - EndWhile. + let parent_evm := + M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := (* if *) M.if_then_else (| @@ -1952,6 +1900,6 @@ Definition revert : Value.t -> Value.t -> M := make_dict [] |) |) in - let _ := M.raise (| Some(M.get_name (| globals, "Revert" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "Revert" |)) |) in let _ := M.pass (| |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/muir_glacier/vm/interpreter.v b/CoqOfPython/ethereum/muir_glacier/vm/interpreter.v index ec729e3..01f6a58 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/interpreter.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/interpreter.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.muir_glacier.vm.interpreter". Definition expr_1 : Value.t := Constant.str " @@ -17,125 +17,50 @@ Introduction A straightforward interpreter that executes EVM code. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_Iterable : - IsGlobalAlias globals typing.globals "Iterable". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.trace. -Axiom ethereum_trace_EvmStop : - IsGlobalAlias globals ethereum.trace.globals "EvmStop". -Axiom ethereum_trace_OpEnd : - IsGlobalAlias globals ethereum.trace.globals "OpEnd". -Axiom ethereum_trace_OpException : - IsGlobalAlias globals ethereum.trace.globals "OpException". -Axiom ethereum_trace_OpStart : - IsGlobalAlias globals ethereum.trace.globals "OpStart". -Axiom ethereum_trace_PrecompileEnd : - IsGlobalAlias globals ethereum.trace.globals "PrecompileEnd". -Axiom ethereum_trace_PrecompileStart : - IsGlobalAlias globals ethereum.trace.globals "PrecompileStart". -Axiom ethereum_trace_TransactionEnd : - IsGlobalAlias globals ethereum.trace.globals "TransactionEnd". -Axiom ethereum_trace_evm_trace : - IsGlobalAlias globals ethereum.trace.globals "evm_trace". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.muir_glacier.blocks. -Axiom ethereum_muir_glacier_blocks_Log : - IsGlobalAlias globals ethereum.muir_glacier.blocks.globals "Log". - -Require ethereum.muir_glacier.fork_types. -Axiom ethereum_muir_glacier_fork_types_Address : - IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "Address". - -Require ethereum.muir_glacier.state. -Axiom ethereum_muir_glacier_state_account_exists_and_is_empty : - IsGlobalAlias globals ethereum.muir_glacier.state.globals "account_exists_and_is_empty". -Axiom ethereum_muir_glacier_state_account_has_code_or_nonce : - IsGlobalAlias globals ethereum.muir_glacier.state.globals "account_has_code_or_nonce". -Axiom ethereum_muir_glacier_state_begin_transaction : - IsGlobalAlias globals ethereum.muir_glacier.state.globals "begin_transaction". -Axiom ethereum_muir_glacier_state_commit_transaction : - IsGlobalAlias globals ethereum.muir_glacier.state.globals "commit_transaction". -Axiom ethereum_muir_glacier_state_destroy_storage : - IsGlobalAlias globals ethereum.muir_glacier.state.globals "destroy_storage". -Axiom ethereum_muir_glacier_state_increment_nonce : - IsGlobalAlias globals ethereum.muir_glacier.state.globals "increment_nonce". -Axiom ethereum_muir_glacier_state_mark_account_created : - IsGlobalAlias globals ethereum.muir_glacier.state.globals "mark_account_created". -Axiom ethereum_muir_glacier_state_move_ether : - IsGlobalAlias globals ethereum.muir_glacier.state.globals "move_ether". -Axiom ethereum_muir_glacier_state_rollback_transaction : - IsGlobalAlias globals ethereum.muir_glacier.state.globals "rollback_transaction". -Axiom ethereum_muir_glacier_state_set_code : - IsGlobalAlias globals ethereum.muir_glacier.state.globals "set_code". -Axiom ethereum_muir_glacier_state_touch_account : - IsGlobalAlias globals ethereum.muir_glacier.state.globals "touch_account". - -Require ethereum.muir_glacier.vm.__init__. -Axiom ethereum_muir_glacier_vm___init___Message : - IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Message". - -Require ethereum.muir_glacier.vm.gas. -Axiom ethereum_muir_glacier_vm_gas_GAS_CODE_DEPOSIT : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_CODE_DEPOSIT". -Axiom ethereum_muir_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "charge_gas". - -Require ethereum.muir_glacier.vm.precompiled_contracts.mapping. -Axiom ethereum_muir_glacier_vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : - IsGlobalAlias globals ethereum.muir_glacier.vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". - -Require ethereum.muir_glacier.vm.__init__. -Axiom ethereum_muir_glacier_vm___init___Environment : - IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Environment". -Axiom ethereum_muir_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Evm". - -Require ethereum.muir_glacier.vm.exceptions. -Axiom ethereum_muir_glacier_vm_exceptions_AddressCollision : - IsGlobalAlias globals ethereum.muir_glacier.vm.exceptions.globals "AddressCollision". -Axiom ethereum_muir_glacier_vm_exceptions_ExceptionalHalt : - IsGlobalAlias globals ethereum.muir_glacier.vm.exceptions.globals "ExceptionalHalt". -Axiom ethereum_muir_glacier_vm_exceptions_InvalidOpcode : - IsGlobalAlias globals ethereum.muir_glacier.vm.exceptions.globals "InvalidOpcode". -Axiom ethereum_muir_glacier_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.muir_glacier.vm.exceptions.globals "OutOfGasError". -Axiom ethereum_muir_glacier_vm_exceptions_Revert : - IsGlobalAlias globals ethereum.muir_glacier.vm.exceptions.globals "Revert". -Axiom ethereum_muir_glacier_vm_exceptions_StackDepthLimitError : - IsGlobalAlias globals ethereum.muir_glacier.vm.exceptions.globals "StackDepthLimitError". - -Require ethereum.muir_glacier.vm.instructions.__init__. -Axiom ethereum_muir_glacier_vm_instructions___init___Ops : - IsGlobalAlias globals ethereum.muir_glacier.vm.instructions.__init__.globals "Ops". -Axiom ethereum_muir_glacier_vm_instructions___init___op_implementation : - IsGlobalAlias globals ethereum.muir_glacier.vm.instructions.__init__.globals "op_implementation". - -Require ethereum.muir_glacier.vm.runtime. -Axiom ethereum_muir_glacier_vm_runtime_get_valid_jump_destinations : - IsGlobalAlias globals ethereum.muir_glacier.vm.runtime.globals "get_valid_jump_destinations". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Iterable"; "Optional"; "Set"; "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. + +Axiom ethereum_trace_imports : + AreImported globals "ethereum.trace" [ "EvmStop"; "OpEnd"; "OpException"; "OpStart"; "PrecompileEnd"; "PrecompileStart"; "TransactionEnd"; "evm_trace" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_muir_glacier_blocks_imports : + AreImported globals "ethereum.muir_glacier.blocks" [ "Log" ]. + +Axiom ethereum_muir_glacier_fork_types_imports : + AreImported globals "ethereum.muir_glacier.fork_types" [ "Address" ]. + +Axiom ethereum_muir_glacier_state_imports : + AreImported globals "ethereum.muir_glacier.state" [ "account_exists_and_is_empty"; "account_has_code_or_nonce"; "begin_transaction"; "commit_transaction"; "destroy_storage"; "increment_nonce"; "mark_account_created"; "move_ether"; "rollback_transaction"; "set_code"; "touch_account" ]. + +Axiom ethereum_muir_glacier_vm_imports : + AreImported globals "ethereum.muir_glacier.vm" [ "Message" ]. + +Axiom ethereum_muir_glacier_vm_gas_imports : + AreImported globals "ethereum.muir_glacier.vm.gas" [ "GAS_CODE_DEPOSIT"; "charge_gas" ]. + +Axiom ethereum_muir_glacier_vm_precompiled_contracts_mapping_imports : + AreImported globals "ethereum.muir_glacier.vm.precompiled_contracts.mapping" [ "PRE_COMPILED_CONTRACTS" ]. + +Axiom ethereum_muir_glacier_vm_imports : + AreImported globals "ethereum.muir_glacier.vm" [ "Environment"; "Evm" ]. + +Axiom ethereum_muir_glacier_vm_exceptions_imports : + AreImported globals "ethereum.muir_glacier.vm.exceptions" [ "AddressCollision"; "ExceptionalHalt"; "InvalidOpcode"; "OutOfGasError"; "Revert"; "StackDepthLimitError" ]. + +Axiom ethereum_muir_glacier_vm_instructions_imports : + AreImported globals "ethereum.muir_glacier.vm.instructions" [ "Ops"; "op_implementation" ]. + +Axiom ethereum_muir_glacier_vm_runtime_imports : + AreImported globals "ethereum.muir_glacier.vm.runtime" [ "get_valid_jump_destinations" ]. Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -516,7 +441,7 @@ Definition process_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "StackDepthLimitError" |), make_list [ Constant.str "Stack depth limit reached" diff --git a/CoqOfPython/ethereum/muir_glacier/vm/memory.v b/CoqOfPython/ethereum/muir_glacier/vm/memory.v index 08d2290..ebeaeaf 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/memory.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/memory.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.muir_glacier.vm.memory". Definition expr_1 : Value.t := Constant.str " @@ -17,17 +17,11 @@ Introduction EVM memory operations. ". -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_right_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "right_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "right_pad_zero_bytes" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. Definition memory_write : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,22 +39,27 @@ Definition memory_write : Value.t -> Value.t -> M := Data to write to memory. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + M.slice (| + M.get_name (| globals, "memory" |), + M.get_name (| globals, "start_position" |), + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) - |) |) |), + Constant.None_ + |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_)). @@ -86,22 +85,27 @@ Definition memory_read_bytes : Value.t -> Value.t -> M := Data read from memory. " in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + M.slice (| + M.get_name (| globals, "memory" |), + M.get_name (| globals, "start_position" |), + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |) |) + Constant.None_ + |) |) in M.pure Constant.None_)). @@ -129,22 +133,27 @@ Definition buffer_read : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "right_pad_zero_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "buffer" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + M.slice (| + M.get_name (| globals, "buffer" |), + M.get_name (| globals, "start_position" |), + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |) |); + Constant.None_ + |); M.get_name (| globals, "size" |) ], make_dict [] diff --git a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/__init__.v index afe08fc..4c9fbd4 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/__init__.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.muir_glacier.vm.precompiled_contracts.__init__". Definition expr_1 : Value.t := Constant.str " @@ -18,9 +18,8 @@ Addresses of precompiled contracts and mappings to their implementations. ". -Require ethereum.muir_glacier.utils.hexadecimal. -Axiom ethereum_muir_glacier_utils_hexadecimal_hex_to_address : - IsGlobalAlias globals ethereum.muir_glacier.utils.hexadecimal.globals "hex_to_address". +Axiom ethereum_muir_glacier_utils_hexadecimal_imports : + AreImported globals "ethereum.muir_glacier.utils.hexadecimal" [ "hex_to_address" ]. Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS"; Constant.str "MODEXP_ADDRESS"; Constant.str "ALT_BN128_ADD_ADDRESS"; Constant.str "ALT_BN128_MUL_ADDRESS"; Constant.str "ALT_BN128_PAIRING_CHECK_ADDRESS"; Constant.str "BLAKE2F_ADDRESS" ] diff --git a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/alt_bn128.v index 5eb4a47..56b7599 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/alt_bn128.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/alt_bn128.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.muir_glacier.vm.precompiled_contracts.alt_bn128". Definition expr_1 : Value.t := Constant.str " @@ -17,49 +17,26 @@ Introduction Implementation of the ALT_BN128 precompiled contracts. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. -Require ethereum.crypto.alt_bn128. -Axiom ethereum_crypto_alt_bn128_ALT_BN128_CURVE_ORDER : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "ALT_BN128_CURVE_ORDER". -Axiom ethereum_crypto_alt_bn128_ALT_BN128_PRIME : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "ALT_BN128_PRIME". -Axiom ethereum_crypto_alt_bn128_BNF : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF". -Axiom ethereum_crypto_alt_bn128_BNF2 : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF2". -Axiom ethereum_crypto_alt_bn128_BNF12 : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF12". -Axiom ethereum_crypto_alt_bn128_BNP : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNP". -Axiom ethereum_crypto_alt_bn128_BNP2 : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNP2". -Axiom ethereum_crypto_alt_bn128_pairing : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "pairing". +Axiom ethereum_crypto_alt_bn128_imports : + AreImported globals "ethereum.crypto.alt_bn128" [ "ALT_BN128_CURVE_ORDER"; "ALT_BN128_PRIME"; "BNF"; "BNF2"; "BNF12"; "BNP"; "BNP2"; "pairing" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.muir_glacier.vm.__init__. -Axiom ethereum_muir_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Evm". +Axiom ethereum_muir_glacier_vm_imports : + AreImported globals "ethereum.muir_glacier.vm" [ "Evm" ]. -Require ethereum.muir_glacier.vm.gas. -Axiom ethereum_muir_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "charge_gas". +Axiom ethereum_muir_glacier_vm_gas_imports : + AreImported globals "ethereum.muir_glacier.vm.gas" [ "charge_gas" ]. -Require ethereum.muir_glacier.vm.memory. -Axiom ethereum_muir_glacier_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.muir_glacier.vm.memory.globals "buffer_read". +Axiom ethereum_muir_glacier_vm_memory_imports : + AreImported globals "ethereum.muir_glacier.vm.memory" [ "buffer_read" ]. -Require ethereum.muir_glacier.vm.exceptions. -Axiom ethereum_muir_glacier_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.muir_glacier.vm.exceptions.globals "OutOfGasError". +Axiom ethereum_muir_glacier_vm_exceptions_imports : + AreImported globals "ethereum.muir_glacier.vm.exceptions" [ "OutOfGasError" ]. Definition alt_bn128_add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -208,23 +185,32 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ] do - let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| - M.get_name (| globals, "i" |), - M.get_name (| globals, "ALT_BN128_PRIME" |) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ], ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in (* At stmt: unsupported node type: Try *) let p := BinOp.add (| @@ -363,23 +349,32 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ] do - let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| - M.get_name (| globals, "i" |), - M.get_name (| globals, "ALT_BN128_PRIME" |) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ], ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in (* At stmt: unsupported node type: Try *) let p := M.call (| @@ -466,7 +461,7 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -480,76 +475,89 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - BinOp.floor_div (| + let _ := + M.for_ (| + M.get_name (| globals, "i" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "data" |) - ], - make_dict [] - |), - Constant.int 192 - |) - ], - make_dict [] - |) do - let values := - make_list [] in - For M.get_name (| globals, "j" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 6 - ], - make_dict [] - |) do - let value := + M.get_name (| globals, "range" |), + make_list [ + BinOp.floor_div (| M.call (| - M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + M.get_name (| globals, "len" |), make_list [ - M.get_subscript (| M.get_name (| globals, "data" |), M.slice (| BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "i" |), - Constant.int 192 - |), - BinOp.mult (| - Constant.int 32, - M.get_name (| globals, "j" |) - |) - |), BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "i" |), - Constant.int 192 - |), - BinOp.mult (| - Constant.int 32, - BinOp.add (| - M.get_name (| globals, "j" |), - Constant.int 1 - |) - |) - |) |) |) + M.get_name (| globals, "data" |) ], make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| - M.get_name (| globals, "value" |), - M.get_name (| globals, "ALT_BN128_PRIME" |) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let _ := M.call (| + |), + Constant.int 192 + |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let values := + make_list [] in + let _ := + M.for_ (| + M.get_name (| globals, "j" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 6 + ], + make_dict [] + |), + ltac:(M.monadic ( + let value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.slice (| + M.get_name (| globals, "data" |), + BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + M.get_name (| globals, "j" |) + |) + |), + BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "j" |), + Constant.int 1 + |) + |) + |), + Constant.None_ + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| M.get_field (| M.get_name (| globals, "values" |), "append" |), make_list [ M.call (| @@ -562,9 +570,14 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in (* At stmt: unsupported node type: Try *) - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.eq (| @@ -585,7 +598,7 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.eq (| @@ -606,49 +619,54 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| - M.get_name (| globals, "p" |), - M.call (| - M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) - |), + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "p" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "q" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |) + )) + |), + (* then *) ltac:(M.monadic ( - Compare.not_eq (| - M.get_name (| globals, "q" |), - M.call (| - M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) - |) - )) - |), - (* then *) - ltac:(M.monadic ( - let result := - BinOp.mult (| - M.get_name (| globals, "result" |), - M.call (| - M.get_name (| globals, "pairing" |), - make_list [ - M.get_name (| globals, "q" |); - M.get_name (| globals, "p" |) - ], - make_dict [] - |) - |) in + let result := + BinOp.mult (| + M.get_name (| globals, "result" |), + M.call (| + M.get_name (| globals, "pairing" |), + make_list [ + M.get_name (| globals, "q" |); + M.get_name (| globals, "p" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := (* if *) M.if_then_else (| diff --git a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/blake2f.v b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/blake2f.v index 05a1fea..506c825 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/blake2f.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/blake2f.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.muir_glacier.vm.precompiled_contracts.blake2f". Definition expr_1 : Value.t := Constant.str " @@ -17,27 +17,20 @@ Introduction Implementation of the `Blake2` precompiled contract. ". -Require ethereum.crypto.blake2. -Axiom ethereum_crypto_blake2_Blake2b : - IsGlobalAlias globals ethereum.crypto.blake2.globals "Blake2b". +Axiom ethereum_crypto_blake2_imports : + AreImported globals "ethereum.crypto.blake2" [ "Blake2b" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.muir_glacier.vm.__init__. -Axiom ethereum_muir_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Evm". +Axiom ethereum_muir_glacier_vm_imports : + AreImported globals "ethereum.muir_glacier.vm" [ "Evm" ]. -Require ethereum.muir_glacier.vm.gas. -Axiom ethereum_muir_glacier_vm_gas_GAS_BLAKE2_PER_ROUND : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_BLAKE2_PER_ROUND". -Axiom ethereum_muir_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "charge_gas". +Axiom ethereum_muir_glacier_vm_gas_imports : + AreImported globals "ethereum.muir_glacier.vm.gas" [ "GAS_BLAKE2_PER_ROUND"; "charge_gas" ]. -Require ethereum.muir_glacier.vm.exceptions. -Axiom ethereum_muir_glacier_vm_exceptions_InvalidParameter : - IsGlobalAlias globals ethereum.muir_glacier.vm.exceptions.globals "InvalidParameter". +Axiom ethereum_muir_glacier_vm_exceptions_imports : + AreImported globals "ethereum.muir_glacier.vm.exceptions" [ "InvalidParameter" ]. Definition blake2f : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -99,7 +92,7 @@ Definition blake2f : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.in (| + Compare.in_ (| M.get_name (| globals, "f" |), make_list [ Constant.int 0; diff --git a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/ecrecover.v index d2dc0ee..1adae4d 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/ecrecover.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.muir_glacier.vm.precompiled_contracts.ecrecover". Definition expr_1 : Value.t := Constant.str " @@ -17,39 +17,26 @@ Introduction Implementation of the ECRECOVER precompiled contract. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.crypto.elliptic_curve. -Axiom ethereum_crypto_elliptic_curve_SECP256K1N : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". -Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". +Axiom ethereum_crypto_elliptic_curve_imports : + AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_left_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. -Require ethereum.muir_glacier.vm.__init__. -Axiom ethereum_muir_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Evm". +Axiom ethereum_muir_glacier_vm_imports : + AreImported globals "ethereum.muir_glacier.vm" [ "Evm" ]. -Require ethereum.muir_glacier.vm.gas. -Axiom ethereum_muir_glacier_vm_gas_GAS_ECRECOVER : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_ECRECOVER". -Axiom ethereum_muir_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "charge_gas". +Axiom ethereum_muir_glacier_vm_gas_imports : + AreImported globals "ethereum.muir_glacier.vm.gas" [ "GAS_ECRECOVER"; "charge_gas" ]. -Require ethereum.muir_glacier.vm.memory. -Axiom ethereum_muir_glacier_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.muir_glacier.vm.memory.globals "buffer_read". +Axiom ethereum_muir_glacier_vm_memory_imports : + AreImported globals "ethereum.muir_glacier.vm.memory" [ "buffer_read" ]. Definition ecrecover : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -264,13 +251,18 @@ Definition ecrecover : Value.t -> Value.t -> M := )) |) in (* At stmt: unsupported node type: Try *) let address := - M.get_subscript (| M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "public_key" |) - ], - make_dict [] - |), M.slice (| Constant.int 12, Constant.int 32 |) |) in + M.slice (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), + Constant.int 12, + Constant.int 32, + Constant.None_ + |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/identity.v index 6963212..e6ee61a 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/identity.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/identity.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.muir_glacier.vm.precompiled_contracts.identity". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementation of the `IDENTITY` precompiled contract. ". -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.muir_glacier.vm.__init__. -Axiom ethereum_muir_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Evm". +Axiom ethereum_muir_glacier_vm_imports : + AreImported globals "ethereum.muir_glacier.vm" [ "Evm" ]. -Require ethereum.muir_glacier.vm.gas. -Axiom ethereum_muir_glacier_vm_gas_GAS_IDENTITY : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_IDENTITY". -Axiom ethereum_muir_glacier_vm_gas_GAS_IDENTITY_WORD : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_IDENTITY_WORD". -Axiom ethereum_muir_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "charge_gas". +Axiom ethereum_muir_glacier_vm_gas_imports : + AreImported globals "ethereum.muir_glacier.vm.gas" [ "GAS_IDENTITY"; "GAS_IDENTITY_WORD"; "charge_gas" ]. Definition identity : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/mapping.v index ba41ecf..ffd941a 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/mapping.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/mapping.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.muir_glacier.vm.precompiled_contracts.mapping". Definition expr_1 : Value.t := Constant.str " @@ -17,66 +17,34 @@ Introduction Mapping of precompiled contracts their implementations. ". -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". - -Require ethereum.muir_glacier.fork_types. -Axiom ethereum_muir_glacier_fork_types_Address : - IsGlobalAlias globals ethereum.muir_glacier.fork_types.globals "Address". - -Require ethereum.muir_glacier.vm.precompiled_contracts.__init__. -Axiom ethereum_muir_glacier_vm_precompiled_contracts___init___ALT_BN128_ADD_ADDRESS : - IsGlobalAlias globals ethereum.muir_glacier.vm.precompiled_contracts.__init__.globals "ALT_BN128_ADD_ADDRESS". -Axiom ethereum_muir_glacier_vm_precompiled_contracts___init___ALT_BN128_MUL_ADDRESS : - IsGlobalAlias globals ethereum.muir_glacier.vm.precompiled_contracts.__init__.globals "ALT_BN128_MUL_ADDRESS". -Axiom ethereum_muir_glacier_vm_precompiled_contracts___init___ALT_BN128_PAIRING_CHECK_ADDRESS : - IsGlobalAlias globals ethereum.muir_glacier.vm.precompiled_contracts.__init__.globals "ALT_BN128_PAIRING_CHECK_ADDRESS". -Axiom ethereum_muir_glacier_vm_precompiled_contracts___init___BLAKE2F_ADDRESS : - IsGlobalAlias globals ethereum.muir_glacier.vm.precompiled_contracts.__init__.globals "BLAKE2F_ADDRESS". -Axiom ethereum_muir_glacier_vm_precompiled_contracts___init___ECRECOVER_ADDRESS : - IsGlobalAlias globals ethereum.muir_glacier.vm.precompiled_contracts.__init__.globals "ECRECOVER_ADDRESS". -Axiom ethereum_muir_glacier_vm_precompiled_contracts___init___IDENTITY_ADDRESS : - IsGlobalAlias globals ethereum.muir_glacier.vm.precompiled_contracts.__init__.globals "IDENTITY_ADDRESS". -Axiom ethereum_muir_glacier_vm_precompiled_contracts___init___MODEXP_ADDRESS : - IsGlobalAlias globals ethereum.muir_glacier.vm.precompiled_contracts.__init__.globals "MODEXP_ADDRESS". -Axiom ethereum_muir_glacier_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : - IsGlobalAlias globals ethereum.muir_glacier.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". -Axiom ethereum_muir_glacier_vm_precompiled_contracts___init___SHA256_ADDRESS : - IsGlobalAlias globals ethereum.muir_glacier.vm.precompiled_contracts.__init__.globals "SHA256_ADDRESS". - -Require ethereum.muir_glacier.vm.precompiled_contracts.alt_bn128. -Axiom ethereum_muir_glacier_vm_precompiled_contracts_alt_bn128_alt_bn128_add : - IsGlobalAlias globals ethereum.muir_glacier.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_add". -Axiom ethereum_muir_glacier_vm_precompiled_contracts_alt_bn128_alt_bn128_mul : - IsGlobalAlias globals ethereum.muir_glacier.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_mul". -Axiom ethereum_muir_glacier_vm_precompiled_contracts_alt_bn128_alt_bn128_pairing_check : - IsGlobalAlias globals ethereum.muir_glacier.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_pairing_check". - -Require ethereum.muir_glacier.vm.precompiled_contracts.blake2f. -Axiom ethereum_muir_glacier_vm_precompiled_contracts_blake2f_blake2f : - IsGlobalAlias globals ethereum.muir_glacier.vm.precompiled_contracts.blake2f.globals "blake2f". - -Require ethereum.muir_glacier.vm.precompiled_contracts.ecrecover. -Axiom ethereum_muir_glacier_vm_precompiled_contracts_ecrecover_ecrecover : - IsGlobalAlias globals ethereum.muir_glacier.vm.precompiled_contracts.ecrecover.globals "ecrecover". - -Require ethereum.muir_glacier.vm.precompiled_contracts.identity. -Axiom ethereum_muir_glacier_vm_precompiled_contracts_identity_identity : - IsGlobalAlias globals ethereum.muir_glacier.vm.precompiled_contracts.identity.globals "identity". - -Require ethereum.muir_glacier.vm.precompiled_contracts.modexp. -Axiom ethereum_muir_glacier_vm_precompiled_contracts_modexp_modexp : - IsGlobalAlias globals ethereum.muir_glacier.vm.precompiled_contracts.modexp.globals "modexp". - -Require ethereum.muir_glacier.vm.precompiled_contracts.ripemd160. -Axiom ethereum_muir_glacier_vm_precompiled_contracts_ripemd160_ripemd160 : - IsGlobalAlias globals ethereum.muir_glacier.vm.precompiled_contracts.ripemd160.globals "ripemd160". - -Require ethereum.muir_glacier.vm.precompiled_contracts.sha256. -Axiom ethereum_muir_glacier_vm_precompiled_contracts_sha256_sha256 : - IsGlobalAlias globals ethereum.muir_glacier.vm.precompiled_contracts.sha256.globals "sha256". +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict" ]. + +Axiom ethereum_muir_glacier_fork_types_imports : + AreImported globals "ethereum.muir_glacier.fork_types" [ "Address" ]. + +Axiom ethereum_muir_glacier_vm_precompiled_contracts_imports : + AreImported globals "ethereum.muir_glacier.vm.precompiled_contracts" [ "ALT_BN128_ADD_ADDRESS"; "ALT_BN128_MUL_ADDRESS"; "ALT_BN128_PAIRING_CHECK_ADDRESS"; "BLAKE2F_ADDRESS"; "ECRECOVER_ADDRESS"; "IDENTITY_ADDRESS"; "MODEXP_ADDRESS"; "RIPEMD160_ADDRESS"; "SHA256_ADDRESS" ]. + +Axiom ethereum_muir_glacier_vm_precompiled_contracts_alt_bn128_imports : + AreImported globals "ethereum.muir_glacier.vm.precompiled_contracts.alt_bn128" [ "alt_bn128_add"; "alt_bn128_mul"; "alt_bn128_pairing_check" ]. + +Axiom ethereum_muir_glacier_vm_precompiled_contracts_blake2f_imports : + AreImported globals "ethereum.muir_glacier.vm.precompiled_contracts.blake2f" [ "blake2f" ]. + +Axiom ethereum_muir_glacier_vm_precompiled_contracts_ecrecover_imports : + AreImported globals "ethereum.muir_glacier.vm.precompiled_contracts.ecrecover" [ "ecrecover" ]. + +Axiom ethereum_muir_glacier_vm_precompiled_contracts_identity_imports : + AreImported globals "ethereum.muir_glacier.vm.precompiled_contracts.identity" [ "identity" ]. + +Axiom ethereum_muir_glacier_vm_precompiled_contracts_modexp_imports : + AreImported globals "ethereum.muir_glacier.vm.precompiled_contracts.modexp" [ "modexp" ]. + +Axiom ethereum_muir_glacier_vm_precompiled_contracts_ripemd160_imports : + AreImported globals "ethereum.muir_glacier.vm.precompiled_contracts.ripemd160" [ "ripemd160" ]. + +Axiom ethereum_muir_glacier_vm_precompiled_contracts_sha256_imports : + AreImported globals "ethereum.muir_glacier.vm.precompiled_contracts.sha256" [ "sha256" ]. (* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/modexp.v index 70c6865..7e5d8f5 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/modexp.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/modexp.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.muir_glacier.vm.precompiled_contracts.modexp". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementation of the `MODEXP` precompiled contract. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. -Require ethereum.muir_glacier.vm.__init__. -Axiom ethereum_muir_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Evm". +Axiom ethereum_muir_glacier_vm_imports : + AreImported globals "ethereum.muir_glacier.vm" [ "Evm" ]. -Require ethereum.muir_glacier.vm.gas. -Axiom ethereum_muir_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "charge_gas". +Axiom ethereum_muir_glacier_vm_gas_imports : + AreImported globals "ethereum.muir_glacier.vm.gas" [ "charge_gas" ]. -Require ethereum.muir_glacier.vm.memory. -Axiom ethereum_muir_glacier_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.muir_glacier.vm.memory.globals "buffer_read". +Axiom ethereum_muir_glacier_vm_memory_imports : + AreImported globals "ethereum.muir_glacier.vm.memory" [ "buffer_read" ]. Definition GQUADDIVISOR : Value.t := M.run ltac:(M.monadic ( M.call (| diff --git a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/ripemd160.v index 8a809b6..29b3b14 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/ripemd160.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/ripemd160.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.muir_glacier.vm.precompiled_contracts.ripemd160". Definition expr_1 : Value.t := Constant.str " @@ -19,29 +19,20 @@ Implementation of the `RIPEMD160` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_left_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.muir_glacier.vm.__init__. -Axiom ethereum_muir_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Evm". +Axiom ethereum_muir_glacier_vm_imports : + AreImported globals "ethereum.muir_glacier.vm" [ "Evm" ]. -Require ethereum.muir_glacier.vm.gas. -Axiom ethereum_muir_glacier_vm_gas_GAS_RIPEMD160 : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_RIPEMD160". -Axiom ethereum_muir_glacier_vm_gas_GAS_RIPEMD160_WORD : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_RIPEMD160_WORD". -Axiom ethereum_muir_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "charge_gas". +Axiom ethereum_muir_glacier_vm_gas_imports : + AreImported globals "ethereum.muir_glacier.vm.gas" [ "GAS_RIPEMD160"; "GAS_RIPEMD160_WORD"; "charge_gas" ]. Definition ripemd160 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/sha256.v index 80a1266..0639c19 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/sha256.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/sha256.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.muir_glacier.vm.precompiled_contracts.sha256". Definition expr_1 : Value.t := Constant.str " @@ -19,25 +19,17 @@ Implementation of the `SHA256` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.muir_glacier.vm.__init__. -Axiom ethereum_muir_glacier_vm___init___Evm : - IsGlobalAlias globals ethereum.muir_glacier.vm.__init__.globals "Evm". +Axiom ethereum_muir_glacier_vm_imports : + AreImported globals "ethereum.muir_glacier.vm" [ "Evm" ]. -Require ethereum.muir_glacier.vm.gas. -Axiom ethereum_muir_glacier_vm_gas_GAS_SHA256 : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_SHA256". -Axiom ethereum_muir_glacier_vm_gas_GAS_SHA256_WORD : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "GAS_SHA256_WORD". -Axiom ethereum_muir_glacier_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.muir_glacier.vm.gas.globals "charge_gas". +Axiom ethereum_muir_glacier_vm_gas_imports : + AreImported globals "ethereum.muir_glacier.vm.gas" [ "GAS_SHA256"; "GAS_SHA256_WORD"; "charge_gas" ]. Definition sha256 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/muir_glacier/vm/runtime.v b/CoqOfPython/ethereum/muir_glacier/vm/runtime.v index 092b217..d9903d3 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/runtime.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/runtime.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.muir_glacier.vm.runtime". Definition expr_1 : Value.t := Constant.str " @@ -17,17 +17,14 @@ Introduction Runtime related operations used while executing EVM code. ". -Require typing. -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". +Axiom typing_imports : + AreImported globals "typing" [ "Set" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.muir_glacier.vm.instructions.__init__. -Axiom ethereum_muir_glacier_vm_instructions___init___Ops : - IsGlobalAlias globals ethereum.muir_glacier.vm.instructions.__init__.globals "Ops". +Axiom ethereum_muir_glacier_vm_instructions_imports : + AreImported globals "ethereum.muir_glacier.vm.instructions" [ "Ops" ]. Definition get_valid_jump_destinations : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -67,75 +64,83 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := ], make_dict [] |) in - While Compare.lt (| - M.get_name (| globals, "pc" |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "code" |) - ], - make_dict [] - |) - |) do -(* At stmt: unsupported node type: Try *) - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "current_opcode" |), - M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) - |), - (* then *) + let _ := + M.while (| + Compare.lt (| + M.get_name (| globals, "pc" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) + |), ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), - make_list [ - M.get_name (| globals, "pc" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( +(* At stmt: unsupported node type: Try *) let _ := (* if *) M.if_then_else (| - BoolOp.and (| - Compare.lt_e (| - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |), - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |) - |), - ltac:(M.monadic ( - Compare.lt_e (| - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH32" |), "value" |) - |) - )) + Compare.eq (| + M.get_name (| globals, "current_opcode" |), + M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) |), (* then *) ltac:(M.monadic ( - let push_data_size := - BinOp.add (| - BinOp.sub (| - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) - |), - Constant.int 1 - |) in - let pc := BinOp.add - M.get_name (| globals, "push_data_size" |) - M.get_name (| globals, "push_data_size" |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), + make_list [ + M.get_name (| globals, "pc" |) + ], + make_dict [] + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.lt_e (| + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |), + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH32" |), "value" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let push_data_size := + BinOp.add (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) + |), + Constant.int 1 + |) in + let pc := BinOp.add + M.get_name (| globals, "push_data_size" |) + M.get_name (| globals, "push_data_size" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ )) |) in + let pc := BinOp.add + Constant.int 1 + Constant.int 1 in M.pure Constant.None_ - )) |) in - let pc := BinOp.add - Constant.int 1 - Constant.int 1 in - EndWhile. + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.get_name (| globals, "valid_jump_destinations" |) |) in diff --git a/CoqOfPython/ethereum/muir_glacier/vm/stack.v b/CoqOfPython/ethereum/muir_glacier/vm/stack.v index 7130027..f39ae16 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/stack.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/stack.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.muir_glacier.vm.stack". Definition expr_1 : Value.t := Constant.str " @@ -17,19 +17,14 @@ Introduction Implementation of the stack operators for the EVM. ". -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". +Axiom typing_imports : + AreImported globals "typing" [ "List" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.muir_glacier.vm.exceptions. -Axiom ethereum_muir_glacier_vm_exceptions_StackOverflowError : - IsGlobalAlias globals ethereum.muir_glacier.vm.exceptions.globals "StackOverflowError". -Axiom ethereum_muir_glacier_vm_exceptions_StackUnderflowError : - IsGlobalAlias globals ethereum.muir_glacier.vm.exceptions.globals "StackUnderflowError". +Axiom ethereum_muir_glacier_vm_exceptions_imports : + AreImported globals "ethereum.muir_glacier.vm.exceptions" [ "StackOverflowError"; "StackUnderflowError" ]. Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -63,7 +58,7 @@ Definition pop : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "StackUnderflowError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "StackUnderflowError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -108,7 +103,7 @@ Definition push : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "StackOverflowError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "StackOverflowError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/paris/__init__.v b/CoqOfPython/ethereum/paris/__init__.v index 27930db..8931eb8 100644 --- a/CoqOfPython/ethereum/paris/__init__.v +++ b/CoqOfPython/ethereum/paris/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.paris.__init__". Definition expr_1 : Value.t := Constant.str " @@ -12,9 +12,8 @@ marks the integration of the [consensus layer] with the execution layer [consensus layer]: https://github.com/ethereum/consensus-specs ". -Require ethereum.fork_criteria. -Axiom ethereum_fork_criteria_ByBlockNumber : - IsGlobalAlias globals ethereum.fork_criteria.globals "ByBlockNumber". +Axiom ethereum_fork_criteria_imports : + AreImported globals "ethereum.fork_criteria" [ "ByBlockNumber" ]. Definition FORK_CRITERIA : Value.t := M.run ltac:(M.monadic ( M.call (| diff --git a/CoqOfPython/ethereum/paris/blocks.v b/CoqOfPython/ethereum/paris/blocks.v index 667f555..7fcc061 100644 --- a/CoqOfPython/ethereum/paris/blocks.v +++ b/CoqOfPython/ethereum/paris/blocks.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.paris.blocks". Definition expr_1 : Value.t := Constant.str " @@ -14,45 +14,23 @@ history of all state transitions that have happened since the genesis of the chain. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes8 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes8". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". - -Require ethereum.paris.fork_types. -Axiom ethereum_paris_fork_types_Address : - IsGlobalAlias globals ethereum.paris.fork_types.globals "Address". -Axiom ethereum_paris_fork_types_Bloom : - IsGlobalAlias globals ethereum.paris.fork_types.globals "Bloom". -Axiom ethereum_paris_fork_types_Root : - IsGlobalAlias globals ethereum.paris.fork_types.globals "Root". - -Require ethereum.paris.transactions. -Axiom ethereum_paris_transactions_LegacyTransaction : - IsGlobalAlias globals ethereum.paris.transactions.globals "LegacyTransaction". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Tuple"; "Union" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes8"; "Bytes32"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. + +Axiom ethereum_paris_fork_types_imports : + AreImported globals "ethereum.paris.fork_types" [ "Address"; "Bloom"; "Root" ]. + +Axiom ethereum_paris_transactions_imports : + AreImported globals "ethereum.paris.transactions" [ "LegacyTransaction" ]. Definition Header : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/paris/bloom.v b/CoqOfPython/ethereum/paris/bloom.v index 91a6d9d..71adf2c 100644 --- a/CoqOfPython/ethereum/paris/bloom.v +++ b/CoqOfPython/ethereum/paris/bloom.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.paris.bloom". Definition expr_1 : Value.t := Constant.str " @@ -21,25 +21,20 @@ for efficient searching of logs by address and/or topic, by rapidly eliminating blocks and receipts from their search. ". -Require typing. -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_imports : + AreImported globals "typing" [ "Tuple" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. -Require ethereum.paris.blocks. -Axiom ethereum_paris_blocks_Log : - IsGlobalAlias globals ethereum.paris.blocks.globals "Log". +Axiom ethereum_paris_blocks_imports : + AreImported globals "ethereum.paris.blocks" [ "Log" ]. -Require ethereum.paris.fork_types. -Axiom ethereum_paris_fork_types_Bloom : - IsGlobalAlias globals ethereum.paris.fork_types.globals "Bloom". +Axiom ethereum_paris_fork_types_imports : + AreImported globals "ethereum.paris.fork_types" [ "Bloom" ]. Definition add_to_bloom : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -66,50 +61,70 @@ Definition add_to_bloom : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "idx" |) in make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ] do - let bit_to_set := - BinOp.bit_and (| - M.call (| - M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "hash" |), M.slice (| M.get_name (| globals, "idx" |), BinOp.add (| - M.get_name (| globals, "idx" |), - Constant.int 2 - |) |) |) - ], - make_dict [] - |), - Constant.int 2047 - |) in - let bit_index := - BinOp.sub (| - Constant.int 2047, - M.get_name (| globals, "bit_to_set" |) - |) in - let byte_index := - BinOp.floor_div (| - M.get_name (| globals, "bit_index" |), - Constant.int 8 - |) in - let bit_value := - BinOp.l_shift (| - Constant.int 1, - BinOp.sub (| - Constant.int 7, - BinOp.mod_ (| + let _ := + M.for_ (| + M.get_name (| globals, "idx" |), + make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ], + ltac:(M.monadic ( + let bit_to_set := + BinOp.bit_and (| + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.slice (| + M.get_name (| globals, "hash" |), + M.get_name (| globals, "idx" |), + BinOp.add (| + M.get_name (| globals, "idx" |), + Constant.int 2 + |), + Constant.None_ + |) + ], + make_dict [] + |), + Constant.int 2047 + |) in + let bit_index := + BinOp.sub (| + Constant.int 2047, + M.get_name (| globals, "bit_to_set" |) + |) in + let byte_index := + BinOp.floor_div (| M.get_name (| globals, "bit_index" |), Constant.int 8 + |) in + let bit_value := + BinOp.l_shift (| + Constant.int 1, + BinOp.sub (| + Constant.int 7, + BinOp.mod_ (| + M.get_name (| globals, "bit_index" |), + Constant.int 8 + |) + |) + |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "bloom" |), + M.get_name (| globals, "byte_index" |) + |), + BinOp.bit_or (| + M.get_subscript (| + M.get_name (| globals, "bloom" |), + M.get_name (| globals, "byte_index" |) + |), + M.get_name (| globals, "bit_value" |) |) - |) - |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), - BinOp.bit_or (| - M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), - M.get_name (| globals, "bit_value" |) - |) - |) in - EndFor. + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_)). Definition logs_bloom : Value.t -> Value.t -> M := @@ -132,8 +147,12 @@ Definition logs_bloom : Value.t -> Value.t -> M := the caller address and the log topics. " in (* At stmt: unsupported node type: AnnAssign *) - For M.get_name (| globals, "log" |) in M.get_name (| globals, "logs" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "log" |), + M.get_name (| globals, "logs" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "add_to_bloom" |), make_list [ M.get_name (| globals, "bloom" |); @@ -141,8 +160,12 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "topic" |) in M.get_field (| M.get_name (| globals, "log" |), "topics" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "topic" |), + M.get_field (| M.get_name (| globals, "log" |), "topics" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "add_to_bloom" |), make_list [ M.get_name (| globals, "bloom" |); @@ -150,8 +173,18 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Bloom" |), diff --git a/CoqOfPython/ethereum/paris/fork.v b/CoqOfPython/ethereum/paris/fork.v index 0dd3260..9051393 100644 --- a/CoqOfPython/ethereum/paris/fork.v +++ b/CoqOfPython/ethereum/paris/fork.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.paris.fork". Definition expr_1 : Value.t := Constant.str " @@ -17,143 +17,59 @@ Introduction Entry point for the Ethereum specification. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". - -Require ethereum.base_types. -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". - -Require ethereum.crypto.elliptic_curve. -Axiom ethereum_crypto_elliptic_curve_SECP256K1N : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". -Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.exceptions. -Axiom ethereum_exceptions_InvalidBlock : - IsGlobalAlias globals ethereum.exceptions.globals "InvalidBlock". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U64 : - IsGlobalAlias globals ethereum.base_types.globals "U64". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.paris.__init__. -Axiom ethereum_paris___init___vm : - IsGlobalAlias globals ethereum.paris.__init__.globals "vm". - -Require ethereum.paris.blocks. -Axiom ethereum_paris_blocks_Block : - IsGlobalAlias globals ethereum.paris.blocks.globals "Block". -Axiom ethereum_paris_blocks_Header : - IsGlobalAlias globals ethereum.paris.blocks.globals "Header". -Axiom ethereum_paris_blocks_Log : - IsGlobalAlias globals ethereum.paris.blocks.globals "Log". -Axiom ethereum_paris_blocks_Receipt : - IsGlobalAlias globals ethereum.paris.blocks.globals "Receipt". - -Require ethereum.paris.bloom. -Axiom ethereum_paris_bloom_logs_bloom : - IsGlobalAlias globals ethereum.paris.bloom.globals "logs_bloom". - -Require ethereum.paris.fork_types. -Axiom ethereum_paris_fork_types_Address : - IsGlobalAlias globals ethereum.paris.fork_types.globals "Address". -Axiom ethereum_paris_fork_types_Bloom : - IsGlobalAlias globals ethereum.paris.fork_types.globals "Bloom". -Axiom ethereum_paris_fork_types_Root : - IsGlobalAlias globals ethereum.paris.fork_types.globals "Root". - -Require ethereum.paris.state. -Axiom ethereum_paris_state_State : - IsGlobalAlias globals ethereum.paris.state.globals "State". -Axiom ethereum_paris_state_account_exists_and_is_empty : - IsGlobalAlias globals ethereum.paris.state.globals "account_exists_and_is_empty". -Axiom ethereum_paris_state_destroy_account : - IsGlobalAlias globals ethereum.paris.state.globals "destroy_account". -Axiom ethereum_paris_state_get_account : - IsGlobalAlias globals ethereum.paris.state.globals "get_account". -Axiom ethereum_paris_state_increment_nonce : - IsGlobalAlias globals ethereum.paris.state.globals "increment_nonce". -Axiom ethereum_paris_state_set_account_balance : - IsGlobalAlias globals ethereum.paris.state.globals "set_account_balance". -Axiom ethereum_paris_state_state_root : - IsGlobalAlias globals ethereum.paris.state.globals "state_root". - -Require ethereum.paris.transactions. -Axiom ethereum_paris_transactions_TX_ACCESS_LIST_ADDRESS_COST : - IsGlobalAlias globals ethereum.paris.transactions.globals "TX_ACCESS_LIST_ADDRESS_COST". -Axiom ethereum_paris_transactions_TX_ACCESS_LIST_STORAGE_KEY_COST : - IsGlobalAlias globals ethereum.paris.transactions.globals "TX_ACCESS_LIST_STORAGE_KEY_COST". -Axiom ethereum_paris_transactions_TX_BASE_COST : - IsGlobalAlias globals ethereum.paris.transactions.globals "TX_BASE_COST". -Axiom ethereum_paris_transactions_TX_CREATE_COST : - IsGlobalAlias globals ethereum.paris.transactions.globals "TX_CREATE_COST". -Axiom ethereum_paris_transactions_TX_DATA_COST_PER_NON_ZERO : - IsGlobalAlias globals ethereum.paris.transactions.globals "TX_DATA_COST_PER_NON_ZERO". -Axiom ethereum_paris_transactions_TX_DATA_COST_PER_ZERO : - IsGlobalAlias globals ethereum.paris.transactions.globals "TX_DATA_COST_PER_ZERO". -Axiom ethereum_paris_transactions_AccessListTransaction : - IsGlobalAlias globals ethereum.paris.transactions.globals "AccessListTransaction". -Axiom ethereum_paris_transactions_FeeMarketTransaction : - IsGlobalAlias globals ethereum.paris.transactions.globals "FeeMarketTransaction". -Axiom ethereum_paris_transactions_LegacyTransaction : - IsGlobalAlias globals ethereum.paris.transactions.globals "LegacyTransaction". -Axiom ethereum_paris_transactions_Transaction : - IsGlobalAlias globals ethereum.paris.transactions.globals "Transaction". -Axiom ethereum_paris_transactions_decode_transaction : - IsGlobalAlias globals ethereum.paris.transactions.globals "decode_transaction". -Axiom ethereum_paris_transactions_encode_transaction : - IsGlobalAlias globals ethereum.paris.transactions.globals "encode_transaction". - -Require ethereum.paris.trie. -Axiom ethereum_paris_trie_Trie : - IsGlobalAlias globals ethereum.paris.trie.globals "Trie". -Axiom ethereum_paris_trie_root : - IsGlobalAlias globals ethereum.paris.trie.globals "root". -Axiom ethereum_paris_trie_trie_set : - IsGlobalAlias globals ethereum.paris.trie.globals "trie_set". - -Require ethereum.paris.utils.message. -Axiom ethereum_paris_utils_message_prepare_message : - IsGlobalAlias globals ethereum.paris.utils.message.globals "prepare_message". - -Require ethereum.paris.vm.interpreter. -Axiom ethereum_paris_vm_interpreter_process_message_call : - IsGlobalAlias globals ethereum.paris.vm.interpreter.globals "process_message_call". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Optional"; "Tuple"; "Union" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Bytes0"; "Bytes32" ]. + +Axiom ethereum_crypto_elliptic_curve_imports : + AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. + +Axiom ethereum_exceptions_imports : + AreImported globals "ethereum.exceptions" [ "InvalidBlock" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U64"; "U256"; "Bytes"; "Uint" ]. + +Axiom ethereum_paris_imports : + AreImported globals "ethereum.paris" [ "vm" ]. + +Axiom ethereum_paris_blocks_imports : + AreImported globals "ethereum.paris.blocks" [ "Block"; "Header"; "Log"; "Receipt" ]. + +Axiom ethereum_paris_bloom_imports : + AreImported globals "ethereum.paris.bloom" [ "logs_bloom" ]. + +Axiom ethereum_paris_fork_types_imports : + AreImported globals "ethereum.paris.fork_types" [ "Address"; "Bloom"; "Root" ]. + +Axiom ethereum_paris_state_imports : + AreImported globals "ethereum.paris.state" [ "State"; "account_exists_and_is_empty"; "destroy_account"; "get_account"; "increment_nonce"; "set_account_balance"; "state_root" ]. + +Axiom ethereum_paris_transactions_imports : + AreImported globals "ethereum.paris.transactions" [ "TX_ACCESS_LIST_ADDRESS_COST"; "TX_ACCESS_LIST_STORAGE_KEY_COST"; "TX_BASE_COST"; "TX_CREATE_COST"; "TX_DATA_COST_PER_NON_ZERO"; "TX_DATA_COST_PER_ZERO"; "AccessListTransaction"; "FeeMarketTransaction"; "LegacyTransaction"; "Transaction"; "decode_transaction"; "encode_transaction" ]. + +Axiom ethereum_paris_trie_imports : + AreImported globals "ethereum.paris.trie" [ "Trie"; "root"; "trie_set" ]. + +Axiom ethereum_paris_utils_message_imports : + AreImported globals "ethereum.paris.utils.message" [ "prepare_message" ]. + +Axiom ethereum_paris_vm_interpreter_imports : + AreImported globals "ethereum.paris.vm.interpreter" [ "process_message_call" ]. Definition BASE_FEE_MAX_CHANGE_DENOMINATOR : Value.t := M.run ltac:(M.monadic ( Constant.int 8 @@ -246,7 +162,12 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := Hashes of the recent 256 blocks in order of increasing block number. " in let recent_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) in + M.slice (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| Constant.int 255 |), + Constant.None_, + Constant.None_ + |) in let _ := (* if *) M.if_then_else (| @@ -272,17 +193,26 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := )) |) in let recent_block_hashes := make_list [] in - For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_blocks" |) do - let prev_block_hash := - M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "block" |), + M.get_name (| globals, "recent_blocks" |), + ltac:(M.monadic ( + let prev_block_hash := + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in + let _ := M.call (| M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), make_list [ M.get_name (| globals, "prev_block_hash" |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let most_recent_block_hash := M.call (| M.get_name (| globals, "keccak256" |), @@ -290,7 +220,10 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), make_list [ - M.get_field (| M.get_subscript (| M.get_name (| globals, "recent_blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) + M.get_field (| M.get_subscript (| + M.get_name (| globals, "recent_blocks" |), + UnOp.sub (| Constant.int 1 |) + |), "header" |) ], make_dict [] |) @@ -334,7 +267,10 @@ Definition state_transition : Value.t -> Value.t -> M := Block to apply to `chain`. " in let parent_header := - M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) in + M.get_field (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| Constant.int 1 |) + |), "header" |) in let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ @@ -456,7 +392,12 @@ Definition state_transition : Value.t -> Value.t -> M := ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) + M.slice (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| Constant.int 255 |), + Constant.None_, + Constant.None_ + |) |) in M.pure Constant.None_ (* else *) @@ -1038,21 +979,25 @@ Definition apply_body : Value.t -> Value.t -> M := (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) - For make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "tx" |) ] in M.call (| - M.get_name (| globals, "enumerate" |), - make_list [ - M.call (| - M.get_name (| globals, "map" |), - make_list [ - M.get_name (| globals, "decode_transaction" |); - M.get_name (| globals, "transactions" |) - ], - make_dict [] - |) - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "tx" |) ], + M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.call (| + M.get_name (| globals, "map" |), + make_list [ + M.get_name (| globals, "decode_transaction" |); + M.get_name (| globals, "transactions" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ M.get_name (| globals, "transactions_trie" |); @@ -1079,54 +1024,54 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.assign (| - make_tuple [ M.get_name (| globals, "sender_address" |); M.get_name (| globals, "effective_gas_price" |) ], - M.call (| - M.get_name (| globals, "check_transaction" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "base_fee_per_gas" |); - M.get_name (| globals, "gas_available" |); - M.get_name (| globals, "chain_id" |) - ], - make_dict [] - |) - |) in - let env := - M.call (| - M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), - make_list [], - make_dict [] - |) in - let _ := M.assign (| - make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |); M.get_name (| globals, "error" |) ], - M.call (| - M.get_name (| globals, "process_transaction" |), - make_list [ - M.get_name (| globals, "env" |); - M.get_name (| globals, "tx" |) - ], - make_dict [] - |) - |) in - let gas_available := BinOp.sub - M.get_name (| globals, "gas_used" |) - M.get_name (| globals, "gas_used" |) in - let receipt := - M.call (| - M.get_name (| globals, "make_receipt" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "error" |); - BinOp.sub (| - M.get_name (| globals, "block_gas_limit" |), - M.get_name (| globals, "gas_available" |) - |); - M.get_name (| globals, "logs" |) - ], - make_dict [] - |) in - let _ := M.call (| + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "sender_address" |); M.get_name (| globals, "effective_gas_price" |) ], + M.call (| + M.get_name (| globals, "check_transaction" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "base_fee_per_gas" |); + M.get_name (| globals, "gas_available" |); + M.get_name (| globals, "chain_id" |) + ], + make_dict [] + |) + |) in + let env := + M.call (| + M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |); M.get_name (| globals, "error" |) ], + M.call (| + M.get_name (| globals, "process_transaction" |), + make_list [ + M.get_name (| globals, "env" |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) in + let gas_available := BinOp.sub + M.get_name (| globals, "gas_used" |) + M.get_name (| globals, "gas_used" |) in + let receipt := + M.call (| + M.get_name (| globals, "make_receipt" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "error" |); + BinOp.sub (| + M.get_name (| globals, "block_gas_limit" |), + M.get_name (| globals, "gas_available" |) + |); + M.get_name (| globals, "logs" |) + ], + make_dict [] + |) in + let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ M.get_name (| globals, "receipts_trie" |); @@ -1147,10 +1092,15 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_logs := BinOp.add - M.get_name (| globals, "logs" |) - M.get_name (| globals, "logs" |) in - EndFor. + let block_logs := BinOp.add + M.get_name (| globals, "logs" |) + M.get_name (| globals, "logs" |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let block_gas_used := BinOp.sub (| M.get_name (| globals, "block_gas_limit" |), @@ -1382,24 +1332,42 @@ Definition process_transaction : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - For make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "keys" |) ] in M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) do - let _ := M.call (| + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "keys" |) ], + M.get_field (| M.get_name (| globals, "tx" |), "access_list" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "preaccessed_addresses" |), "add" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] |) in - For M.get_name (| globals, "key" |) in M.get_name (| globals, "keys" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "keys" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "preaccessed_storage_keys" |), "add" |), make_list [ make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "key" |) ] ], make_dict [] |) in - EndFor. - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1555,8 +1523,12 @@ Definition process_transaction : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "accounts_to_delete" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "output" |), "accounts_to_delete" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "destroy_account" |), make_list [ M.get_field (| M.get_name (| globals, "env" |), "state" |); @@ -1564,22 +1536,31 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. - For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "touched_accounts" |) do - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), - (* then *) + M.pure Constant.None_ + )), ltac:(M.monadic ( - let _ := M.call (| + M.pure Constant.None_ + )) + |) in + let _ := + M.for_ (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "output" |), "touched_accounts" |), + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "destroy_account" |), make_list [ M.get_field (| M.get_name (| globals, "env" |), "state" |); @@ -1587,12 +1568,17 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := M.return_ (| make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |); M.get_field (| M.get_name (| globals, "output" |), "error" |) ] |) in @@ -1680,28 +1666,37 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := " in let data_cost := Constant.int 0 in - For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "byte" |), - Constant.int 0 - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "byte" |), + M.get_field (| M.get_name (| globals, "tx" |), "data" |), ltac:(M.monadic ( - let data_cost := BinOp.add - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "byte" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let data_cost := BinOp.add - M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := (* if *) M.if_then_else (| @@ -1741,12 +1736,16 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - For make_tuple [ M.get_name (| globals, "_address" |); M.get_name (| globals, "keys" |) ] in M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) do - let access_list_cost := BinOp.add - M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) - M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) in - let access_list_cost := BinOp.add - BinOp.mult (| + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "_address" |); M.get_name (| globals, "keys" |) ], + M.get_field (| M.get_name (| globals, "tx" |), "access_list" |), + ltac:(M.monadic ( + let access_list_cost := BinOp.add + M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) + M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) in + let access_list_cost := BinOp.add + BinOp.mult (| M.call (| M.get_name (| globals, "len" |), make_list [ @@ -1756,7 +1755,7 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) |) - BinOp.mult (| + BinOp.mult (| M.call (| M.get_name (| globals, "len" |), make_list [ @@ -1766,7 +1765,12 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -2055,13 +2059,18 @@ Definition recover_sender : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "Address" |), make_list [ - M.get_subscript (| M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "public_key" |) - ], - make_dict [] - |), M.slice (| Constant.int 12, Constant.int 32 |) |) + M.slice (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), + Constant.int 12, + Constant.int 32, + Constant.None_ + |) ], make_dict [] |) diff --git a/CoqOfPython/ethereum/paris/fork_types.v b/CoqOfPython/ethereum/paris/fork_types.v index cc8e4a1..9570ed3 100644 --- a/CoqOfPython/ethereum/paris/fork_types.v +++ b/CoqOfPython/ethereum/paris/fork_types.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.paris.fork_types". Definition expr_1 : Value.t := Constant.str " @@ -17,33 +17,17 @@ Introduction Types re-used throughout the specification, which are specific to Ethereum. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes20 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes20". -Axiom ethereum_base_types_Bytes256 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes20"; "Bytes256"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) diff --git a/CoqOfPython/ethereum/paris/state.v b/CoqOfPython/ethereum/paris/state.v index e044783..9599f90 100644 --- a/CoqOfPython/ethereum/paris/state.v +++ b/CoqOfPython/ethereum/paris/state.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.paris.state". Definition expr_1 : Value.t := Constant.str " @@ -22,63 +22,23 @@ There is a distinction between an account that does not exist and `EMPTY_ACCOUNT`. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". -Axiom dataclasses_field : - IsGlobalAlias globals dataclasses.globals "field". - -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_modify : - IsGlobalAlias globals ethereum.base_types.globals "modify". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.paris.fork_types. -Axiom ethereum_paris_fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals ethereum.paris.fork_types.globals "EMPTY_ACCOUNT". -Axiom ethereum_paris_fork_types_Account : - IsGlobalAlias globals ethereum.paris.fork_types.globals "Account". -Axiom ethereum_paris_fork_types_Address : - IsGlobalAlias globals ethereum.paris.fork_types.globals "Address". -Axiom ethereum_paris_fork_types_Root : - IsGlobalAlias globals ethereum.paris.fork_types.globals "Root". - -Require ethereum.paris.trie. -Axiom ethereum_paris_trie_EMPTY_TRIE_ROOT : - IsGlobalAlias globals ethereum.paris.trie.globals "EMPTY_TRIE_ROOT". -Axiom ethereum_paris_trie_Trie : - IsGlobalAlias globals ethereum.paris.trie.globals "Trie". -Axiom ethereum_paris_trie_copy_trie : - IsGlobalAlias globals ethereum.paris.trie.globals "copy_trie". -Axiom ethereum_paris_trie_root : - IsGlobalAlias globals ethereum.paris.trie.globals "root". -Axiom ethereum_paris_trie_trie_get : - IsGlobalAlias globals ethereum.paris.trie.globals "trie_get". -Axiom ethereum_paris_trie_trie_set : - IsGlobalAlias globals ethereum.paris.trie.globals "trie_set". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass"; "field" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict"; "List"; "Optional"; "Set"; "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "modify" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_paris_fork_types_imports : + AreImported globals "ethereum.paris.fork_types" [ "EMPTY_ACCOUNT"; "Account"; "Address"; "Root" ]. + +Axiom ethereum_paris_trie_imports : + AreImported globals "ethereum.paris.trie" [ "EMPTY_TRIE_ROOT"; "Trie"; "copy_trie"; "root"; "trie_get"; "trie_set" ]. Definition State : Value.t := builtins.make_klass @@ -373,13 +333,16 @@ Definition destroy_storage : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -542,7 +505,10 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), + M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |), M.get_name (| globals, "trie" |) |) in M.pure Constant.None_ @@ -568,7 +534,10 @@ Definition set_storage : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -598,7 +567,7 @@ Definition storage_root : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), @@ -608,7 +577,10 @@ Definition storage_root : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "root" |), make_list [ - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) + M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |) ], make_dict [] |) @@ -1140,7 +1112,7 @@ Definition get_storage_original : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |) |), @@ -1162,7 +1134,10 @@ Definition get_storage_original : Value.t -> Value.t -> M := )) |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "_" |); M.get_name (| globals, "original_trie" |) ], - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), Constant.int 0 |) + M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), + Constant.int 0 + |) |) in let original_account_trie := M.call (| diff --git a/CoqOfPython/ethereum/paris/transactions.v b/CoqOfPython/ethereum/paris/transactions.v index d16cff9..55db9ea 100644 --- a/CoqOfPython/ethereum/paris/transactions.v +++ b/CoqOfPython/ethereum/paris/transactions.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.paris.transactions". Definition expr_1 : Value.t := Constant.str " @@ -9,43 +9,23 @@ submitted to be executed. If Ethereum is viewed as a state machine, transactions are the events that move between states. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. -Require typing. -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". +Axiom typing_imports : + AreImported globals "typing" [ "Tuple"; "Union" ]. -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U64 : - IsGlobalAlias globals ethereum.base_types.globals "U64". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U64"; "U256"; "Bytes"; "Bytes0"; "Bytes32"; "Uint"; "slotted_freezable" ]. -Require ethereum.exceptions. -Axiom ethereum_exceptions_InvalidBlock : - IsGlobalAlias globals ethereum.exceptions.globals "InvalidBlock". +Axiom ethereum_exceptions_imports : + AreImported globals "ethereum.exceptions" [ "InvalidBlock" ]. -Require ethereum.paris.fork_types. -Axiom ethereum_paris_fork_types_Address : - IsGlobalAlias globals ethereum.paris.fork_types.globals "Address". +Axiom ethereum_paris_fork_types_imports : + AreImported globals "ethereum.paris.fork_types" [ "Address" ]. Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( Constant.int 21000 @@ -102,7 +82,10 @@ Definition FeeMarketTransaction : Value.t := ]. Definition Transaction : Value.t := M.run ltac:(M.monadic ( - M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "AccessListTransaction" |); M.get_name (| globals, "FeeMarketTransaction" |) ] |) + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "AccessListTransaction" |); M.get_name (| globals, "FeeMarketTransaction" |) ] + |) )). Definition encode_transaction : Value.t -> Value.t -> M := @@ -186,7 +169,7 @@ Definition encode_transaction : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "Exception" |), make_list [ Constant.str "(* At expr: unsupported node type: JoinedStr *)" @@ -224,7 +207,10 @@ Definition decode_transaction : Value.t -> Value.t -> M := (* if *) M.if_then_else (| Compare.eq (| - M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), + M.get_subscript (| + M.get_name (| globals, "tx" |), + Constant.int 0 + |), Constant.int 1 |), (* then *) @@ -234,7 +220,12 @@ Definition decode_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), make_list [ M.get_name (| globals, "AccessListTransaction" |); - M.get_subscript (| M.get_name (| globals, "tx" |), M.slice (| Constant.int 1, Constant.None_ |) |) + M.slice (| + M.get_name (| globals, "tx" |), + Constant.int 1, + Constant.None_, + Constant.None_ + |) ], make_dict [] |) @@ -246,7 +237,10 @@ Definition decode_transaction : Value.t -> Value.t -> M := (* if *) M.if_then_else (| Compare.eq (| - M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), + M.get_subscript (| + M.get_name (| globals, "tx" |), + Constant.int 0 + |), Constant.int 2 |), (* then *) @@ -256,7 +250,12 @@ Definition decode_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), make_list [ M.get_name (| globals, "FeeMarketTransaction" |); - M.get_subscript (| M.get_name (| globals, "tx" |), M.slice (| Constant.int 1, Constant.None_ |) |) + M.slice (| + M.get_name (| globals, "tx" |), + Constant.int 1, + Constant.None_, + Constant.None_ + |) ], make_dict [] |) @@ -264,7 +263,7 @@ Definition decode_transaction : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidBlock" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "InvalidBlock" |)) |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/paris/trie.v b/CoqOfPython/ethereum/paris/trie.v index 41d8641..4325e35 100644 --- a/CoqOfPython/ethereum/paris/trie.v +++ b/CoqOfPython/ethereum/paris/trie.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.paris.trie". Definition expr_1 : Value.t := Constant.str " @@ -20,83 +20,38 @@ The state trie is the structure responsible for storing (* At top_level_stmt: unsupported node type: Import *) -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". -Axiom dataclasses_field : - IsGlobalAlias globals dataclasses.globals "field". - -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". -Axiom typing_Generic : - IsGlobalAlias globals typing.globals "Generic". -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Mapping : - IsGlobalAlias globals typing.globals "Mapping". -Axiom typing_MutableMapping : - IsGlobalAlias globals typing.globals "MutableMapping". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Sequence : - IsGlobalAlias globals typing.globals "Sequence". -Axiom typing_TypeVar : - IsGlobalAlias globals typing.globals "TypeVar". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". -Axiom typing_cast : - IsGlobalAlias globals typing.globals "cast". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.gray_glacier.__init__. -Axiom ethereum_gray_glacier___init___trie : - IsGlobalAlias globals ethereum.gray_glacier.__init__.globals "trie". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.utils.hexadecimal. -Axiom ethereum_utils_hexadecimal_hex_to_bytes : - IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.paris.blocks. -Axiom ethereum_paris_blocks_Receipt : - IsGlobalAlias globals ethereum.paris.blocks.globals "Receipt". - -Require ethereum.paris.fork_types. -Axiom ethereum_paris_fork_types_Account : - IsGlobalAlias globals ethereum.paris.fork_types.globals "Account". -Axiom ethereum_paris_fork_types_Address : - IsGlobalAlias globals ethereum.paris.fork_types.globals "Address". -Axiom ethereum_paris_fork_types_Root : - IsGlobalAlias globals ethereum.paris.fork_types.globals "Root". -Axiom ethereum_paris_fork_types_encode_account : - IsGlobalAlias globals ethereum.paris.fork_types.globals "encode_account". - -Require ethereum.paris.transactions. -Axiom ethereum_paris_transactions_LegacyTransaction : - IsGlobalAlias globals ethereum.paris.transactions.globals "LegacyTransaction". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass"; "field" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict"; "Generic"; "List"; "Mapping"; "MutableMapping"; "Optional"; "Sequence"; "TypeVar"; "Union"; "cast" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. + +Axiom ethereum_gray_glacier_imports : + AreImported globals "ethereum.gray_glacier" [ "trie" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_utils_hexadecimal_imports : + AreImported globals "ethereum.utils.hexadecimal" [ "hex_to_bytes" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_paris_blocks_imports : + AreImported globals "ethereum.paris.blocks" [ "Receipt" ]. + +Axiom ethereum_paris_fork_types_imports : + AreImported globals "ethereum.paris.fork_types" [ "Account"; "Address"; "Root"; "encode_account" ]. + +Axiom ethereum_paris_transactions_imports : + AreImported globals "ethereum.paris.transactions" [ "LegacyTransaction" ]. Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -115,7 +70,10 @@ Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( )). Definition Node : Value.t := M.run ltac:(M.monadic ( - M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Bytes" |); M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |); Constant.None_ ] |) + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Bytes" |); M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |); Constant.None_ ] + |) )). Definition K : Value.t := M.run ltac:(M.monadic ( @@ -133,11 +91,29 @@ Definition V : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "TypeVar" |), make_list [ Constant.str "V"; - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Account" |) |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Bytes" |) |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Account" |) + |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Bytes" |) + |); M.get_name (| globals, "Bytes" |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Bytes" |) ] |) |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Bytes" |) ] |) |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Bytes" |) ] + |) + |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Bytes" |) ] + |) + |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |) ], @@ -176,7 +152,10 @@ Definition BranchNode : Value.t := ]. Definition InternalNode : Value.t := M.run ltac:(M.monadic ( - M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LeafNode" |); M.get_name (| globals, "ExtensionNode" |); M.get_name (| globals, "BranchNode" |) ] |) + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "LeafNode" |); M.get_name (| globals, "ExtensionNode" |); M.get_name (| globals, "BranchNode" |) ] + |) )). Definition encode_internal_node : Value.t -> Value.t -> M := @@ -288,7 +267,7 @@ Definition encode_internal_node : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "(* At expr: unsupported node type: JoinedStr *)" @@ -528,13 +507,16 @@ Definition trie_set : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "key" |), M.get_field (| M.get_name (| globals, "trie" |), "_data" |) |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + M.get_name (| globals, "key" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -544,7 +526,10 @@ Definition trie_set : Value.t -> Value.t -> M := (* else *) )), ltac:(M.monadic ( let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), + M.get_subscript (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + M.get_name (| globals, "key" |) + |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_ @@ -589,51 +574,66 @@ Definition common_prefix_length : Value.t -> Value.t -> M := let _ := Constant.str " Find the longest common prefix of two sequences. " in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "a" |) - ], - make_dict [] - |) - ], - make_dict [] - |) do - let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| - M.get_name (| globals, "i" |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "b" |) - ], - make_dict [] - |) - |), - ltac:(M.monadic ( - Compare.not_eq (| - M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), - M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) - |) - )) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + ], + make_dict [] + |), ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "i" |) - |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_subscript (| + M.get_name (| globals, "a" |), + M.get_name (| globals, "i" |) + |), + M.get_subscript (| + M.get_name (| globals, "b" |), + M.get_name (| globals, "i" |) + |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "len" |), @@ -718,38 +718,53 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 0; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |); - Constant.int 2 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ BinOp.add (| BinOp.mult (| Constant.int 16, - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "i" |) + |) |), - M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) + |) |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -767,43 +782,61 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := Constant.int 1 |) |), - M.get_subscript (| M.get_name (| globals, "x" |), Constant.int 0 |) + M.get_subscript (| + M.get_name (| globals, "x" |), + Constant.int 0 + |) |) ], make_dict [] |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 1; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |); - Constant.int 2 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 1; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ BinOp.add (| BinOp.mult (| Constant.int 16, - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "i" |) + |) |), - M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) + |) |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -850,40 +883,55 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := ], make_dict [] |) in - For make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ] in M.call (| - M.get_name (| globals, "enumerate" |), - make_list [ - M.get_name (| globals, "bytes_" |) - ], - make_dict [] - |) do - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.mult (| - M.get_name (| globals, "byte_index" |), - Constant.int 2 - |) |), - BinOp.r_shift (| - BinOp.bit_and (| - M.get_name (| globals, "byte" |), - Constant.int 240 - |), - Constant.int 4 - |) - |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "byte_index" |), - Constant.int 2 - |), - Constant.int 1 - |) |), - BinOp.bit_and (| - M.get_name (| globals, "byte" |), - Constant.int 15 - |) - |) in - EndFor. + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ], + M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "bytes_" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "nibble_list" |), + BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |) + |), + BinOp.r_shift (| + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 240 + |), + Constant.int 4 + |) + |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "nibble_list" |), + BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |), + Constant.int 1 + |) + |), + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 15 + |) + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Bytes" |), @@ -916,65 +964,69 @@ Definition _prepare_trie : Value.t -> Value.t -> M := Object with keys mapped to nibble-byte form. " in (* At stmt: unsupported node type: AnnAssign *) - For make_tuple [ M.get_name (| globals, "preimage" |); M.get_name (| globals, "value" |) ] in M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "items" |), - make_list [], - make_dict [] - |) do - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "value" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "preimage" |); M.get_name (| globals, "value" |) ], + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "items" |), + make_list [], + make_dict [] + |), ltac:(M.monadic ( - let _ := M.assert (| Compare.is_not (| + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in - let address := - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in - let encoded_value := - M.call (| - M.get_name (| globals, "encode_node" |), - make_list [ - M.get_name (| globals, "value" |); + let address := M.call (| - M.get_name (| globals, "get_storage_root" |), + M.get_name (| globals, "Address" |), make_list [ - M.get_name (| globals, "address" |) + M.get_name (| globals, "preimage" |) ], make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let encoded_value := - M.call (| - M.get_name (| globals, "encode_node" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - )) |) in - let _ := M.call (| + |) in + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |); + M.call (| + M.get_name (| globals, "get_storage_root" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_eq (| @@ -986,38 +1038,46 @@ Definition _prepare_trie : Value.t -> Value.t -> M := make_dict [] |) in (* At stmt: unsupported node type: AnnAssign *) - let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "trie" |), "secured" |), - (* then *) - ltac:(M.monadic ( - let key := - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "trie" |), "secured" |), + (* then *) + ltac:(M.monadic ( + let key := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let key := + M.get_name (| globals, "preimage" |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "mapped" |), + M.call (| + M.get_name (| globals, "bytes_to_nibble_list" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |) + |), + M.get_name (| globals, "encoded_value" |) + |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let key := - M.get_name (| globals, "preimage" |) in + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "mapped" |), M.call (| - M.get_name (| globals, "bytes_to_nibble_list" |), - make_list [ - M.get_name (| globals, "key" |) - ], - make_dict [] - |) |), - M.get_name (| globals, "encoded_value" |) - |) in - EndFor. + )) + |) in let _ := M.return_ (| M.get_name (| globals, "mapped" |) |) in @@ -1210,8 +1270,16 @@ Definition patricialize : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "LeafNode" |), make_list [ - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |); - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) + M.slice (| + M.get_name (| globals, "arbitrary_key" |), + M.get_name (| globals, "level" |), + Constant.None_, + Constant.None_ + |); + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "arbitrary_key" |) + |) ], make_dict [] |) in @@ -1224,7 +1292,12 @@ Definition patricialize : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in let substring := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "arbitrary_key" |), + M.get_name (| globals, "level" |), + Constant.None_, + Constant.None_ + |) in let prefix_length := M.call (| M.get_name (| globals, "len" |), @@ -1233,39 +1306,53 @@ Definition patricialize : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do - let prefix_length := - M.call (| - M.get_name (| globals, "min" |), - make_list [ - M.get_name (| globals, "prefix_length" |); + let _ := + M.for_ (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "obj" |), + ltac:(M.monadic ( + let prefix_length := M.call (| - M.get_name (| globals, "common_prefix_length" |), + M.get_name (| globals, "min" |), make_list [ - M.get_name (| globals, "substring" |); - M.get_subscript (| M.get_name (| globals, "key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) + M.get_name (| globals, "prefix_length" |); + M.call (| + M.get_name (| globals, "common_prefix_length" |), + make_list [ + M.get_name (| globals, "substring" |); + M.slice (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "level" |), + Constant.None_, + Constant.None_ + |) + ], + make_dict [] + |) ], make_dict [] - |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "prefix_length" |), - Constant.int 0 - |), - (* then *) - ltac:(M.monadic ( - let _ := M.break (| |) in + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "prefix_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := (* if *) M.if_then_else (| @@ -1276,10 +1363,15 @@ Definition patricialize : Value.t -> Value.t -> M := (* then *) ltac:(M.monadic ( let prefix := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), BinOp.add (| + M.slice (| + M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |), - M.get_name (| globals, "prefix_length" |) - |) |) |) in + BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |), + Constant.None_ + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ExtensionNode" |), @@ -1312,70 +1404,106 @@ Definition patricialize : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) - For M.get_name (| globals, "_" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 16 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "_" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 16 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "branches" |), "append" |), make_list [ {} ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let value := Constant.bytes "" in - For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "key" |) - ], - make_dict [] - |), - M.get_name (| globals, "level" |) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "obj" |), ltac:(M.monadic ( let _ := (* if *) M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); - make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] - ], - make_dict [] + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |), + M.get_name (| globals, "level" |) |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "AssertionError" |)) |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "key" |) + |); + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "AssertionError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "key" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| + M.get_subscript (| + M.get_name (| globals, "branches" |), + M.get_subscript (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "level" |) + |) + |), + M.get_name (| globals, "key" |) + |), + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "key" |) + |) + |) in M.pure Constant.None_ )) |) in - let value := - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.assign (| - M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) - |) in + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "BranchNode" |), diff --git a/CoqOfPython/ethereum/paris/utils/__init__.v b/CoqOfPython/ethereum/paris/utils/__init__.v index 1baedea..afb5c35 100644 --- a/CoqOfPython/ethereum/paris/utils/__init__.v +++ b/CoqOfPython/ethereum/paris/utils/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.paris.utils.__init__". Definition expr_1 : Value.t := Constant.str " diff --git a/CoqOfPython/ethereum/paris/utils/address.v b/CoqOfPython/ethereum/paris/utils/address.v index c6ea8ef..ad264a6 100644 --- a/CoqOfPython/ethereum/paris/utils/address.v +++ b/CoqOfPython/ethereum/paris/utils/address.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.paris.utils.address". Definition expr_1 : Value.t := Constant.str " @@ -18,33 +18,23 @@ Address specific functions used in this paris version of specification. ". -Require typing. -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". +Axiom typing_imports : + AreImported globals "typing" [ "Union" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes32"; "Uint" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_left_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. -Require ethereum.paris.fork_types. -Axiom ethereum_paris_fork_types_Address : - IsGlobalAlias globals ethereum.paris.fork_types.globals "Address". +Axiom ethereum_paris_fork_types_imports : + AreImported globals "ethereum.paris.fork_types" [ "Address" ]. Definition to_address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -66,11 +56,16 @@ Definition to_address : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "Address" |), make_list [ - M.get_subscript (| M.call (| - M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), - make_list [], - make_dict [] - |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) + M.slice (| + M.call (| + M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), + UnOp.sub (| Constant.int 20 |), + Constant.None_, + Constant.None_ + |) ], make_dict [] |) @@ -114,7 +109,12 @@ Definition compute_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "computed_address" |), + UnOp.sub (| Constant.int 20 |), + Constant.None_, + Constant.None_ + |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -182,7 +182,12 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "computed_address" |), + UnOp.sub (| Constant.int 20 |), + Constant.None_, + Constant.None_ + |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/paris/utils/hexadecimal.v b/CoqOfPython/ethereum/paris/utils/hexadecimal.v index 45cda10..af069d3 100644 --- a/CoqOfPython/ethereum/paris/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/paris/utils/hexadecimal.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.paris.utils.hexadecimal". Definition expr_1 : Value.t := Constant.str " @@ -18,17 +18,11 @@ Hexadecimal utility functions used in this specification, specific to Paris types. ". -Require ethereum.utils.hexadecimal. -Axiom ethereum_utils_hexadecimal_remove_hex_prefix : - IsGlobalAlias globals ethereum.utils.hexadecimal.globals "remove_hex_prefix". - -Require ethereum.paris.fork_types. -Axiom ethereum_paris_fork_types_Address : - IsGlobalAlias globals ethereum.paris.fork_types.globals "Address". -Axiom ethereum_paris_fork_types_Bloom : - IsGlobalAlias globals ethereum.paris.fork_types.globals "Bloom". -Axiom ethereum_paris_fork_types_Root : - IsGlobalAlias globals ethereum.paris.fork_types.globals "Root". +Axiom ethereum_utils_hexadecimal_imports : + AreImported globals "ethereum.utils.hexadecimal" [ "remove_hex_prefix" ]. + +Axiom ethereum_paris_fork_types_imports : + AreImported globals "ethereum.paris.fork_types" [ "Address"; "Bloom"; "Root" ]. Definition hex_to_root : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/paris/utils/message.v b/CoqOfPython/ethereum/paris/utils/message.v index 80999f8..752cf70 100644 --- a/CoqOfPython/ethereum/paris/utils/message.v +++ b/CoqOfPython/ethereum/paris/utils/message.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.paris.utils.message". Definition expr_1 : Value.t := Constant.str " @@ -18,49 +18,26 @@ Message specific functions used in this paris version of specification. ". -Require typing. -Axiom typing_FrozenSet : - IsGlobalAlias globals typing.globals "FrozenSet". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". +Axiom typing_imports : + AreImported globals "typing" [ "FrozenSet"; "Optional"; "Tuple"; "Union" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Bytes32"; "Uint" ]. -Require ethereum.paris.fork_types. -Axiom ethereum_paris_fork_types_Address : - IsGlobalAlias globals ethereum.paris.fork_types.globals "Address". +Axiom ethereum_paris_fork_types_imports : + AreImported globals "ethereum.paris.fork_types" [ "Address" ]. -Require ethereum.paris.state. -Axiom ethereum_paris_state_get_account : - IsGlobalAlias globals ethereum.paris.state.globals "get_account". +Axiom ethereum_paris_state_imports : + AreImported globals "ethereum.paris.state" [ "get_account" ]. -Require ethereum.paris.vm.__init__. -Axiom ethereum_paris_vm___init___Environment : - IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Environment". -Axiom ethereum_paris_vm___init___Message : - IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Message". +Axiom ethereum_paris_vm_imports : + AreImported globals "ethereum.paris.vm" [ "Environment"; "Message" ]. -Require ethereum.paris.vm.precompiled_contracts.mapping. -Axiom ethereum_paris_vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : - IsGlobalAlias globals ethereum.paris.vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". +Axiom ethereum_paris_vm_precompiled_contracts_mapping_imports : + AreImported globals "ethereum.paris.vm.precompiled_contracts.mapping" [ "PRE_COMPILED_CONTRACTS" ]. -Require ethereum.paris.utils.address. -Axiom ethereum_paris_utils_address_compute_contract_address : - IsGlobalAlias globals ethereum.paris.utils.address.globals "compute_contract_address". +Axiom ethereum_paris_utils_address_imports : + AreImported globals "ethereum.paris.utils.address" [ "compute_contract_address" ]. Definition prepare_message : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -198,7 +175,7 @@ Definition prepare_message : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "Target must be address or empty bytes" diff --git a/CoqOfPython/ethereum/paris/vm/__init__.v b/CoqOfPython/ethereum/paris/vm/__init__.v index f46ba2a..dcfac8a 100644 --- a/CoqOfPython/ethereum/paris/vm/__init__.v +++ b/CoqOfPython/ethereum/paris/vm/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.paris.vm.__init__". Definition expr_1 : Value.t := Constant.str " @@ -18,57 +18,29 @@ The abstract computer which runs the code stored in an `.fork_types.Account`. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple"; "Union" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U64 : - IsGlobalAlias globals ethereum.base_types.globals "U64". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U64"; "U256"; "Bytes"; "Bytes0"; "Bytes32"; "Uint" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. -Require ethereum.paris.blocks. -Axiom ethereum_paris_blocks_Log : - IsGlobalAlias globals ethereum.paris.blocks.globals "Log". +Axiom ethereum_paris_blocks_imports : + AreImported globals "ethereum.paris.blocks" [ "Log" ]. -Require ethereum.paris.fork_types. -Axiom ethereum_paris_fork_types_Address : - IsGlobalAlias globals ethereum.paris.fork_types.globals "Address". +Axiom ethereum_paris_fork_types_imports : + AreImported globals "ethereum.paris.fork_types" [ "Address" ]. -Require ethereum.paris.state. -Axiom ethereum_paris_state_State : - IsGlobalAlias globals ethereum.paris.state.globals "State". -Axiom ethereum_paris_state_account_exists_and_is_empty : - IsGlobalAlias globals ethereum.paris.state.globals "account_exists_and_is_empty". +Axiom ethereum_paris_state_imports : + AreImported globals "ethereum.paris.state" [ "State"; "account_exists_and_is_empty" ]. -Require ethereum.paris.vm.precompiled_contracts.__init__. -Axiom ethereum_paris_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : - IsGlobalAlias globals ethereum.paris.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". +Axiom ethereum_paris_vm_precompiled_contracts_imports : + AreImported globals "ethereum.paris.vm.precompiled_contracts" [ "RIPEMD160_ADDRESS" ]. Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] @@ -203,7 +175,7 @@ Definition incorporate_child_on_error : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "RIPEMD160_ADDRESS" |), M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) |), diff --git a/CoqOfPython/ethereum/paris/vm/exceptions.v b/CoqOfPython/ethereum/paris/vm/exceptions.v index 1f4363d..4df4ea7 100644 --- a/CoqOfPython/ethereum/paris/vm/exceptions.v +++ b/CoqOfPython/ethereum/paris/vm/exceptions.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.paris.vm.exceptions". Definition expr_1 : Value.t := Constant.str " @@ -17,9 +17,8 @@ Introduction Exceptions which cause the EVM to halt exceptionally. ". -Require ethereum.exceptions. -Axiom ethereum_exceptions_EthereumException : - IsGlobalAlias globals ethereum.exceptions.globals "EthereumException". +Axiom ethereum_exceptions_imports : + AreImported globals "ethereum.exceptions" [ "EthereumException" ]. Definition ExceptionalHalt : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/paris/vm/gas.v b/CoqOfPython/ethereum/paris/vm/gas.v index e20e15c..a170113 100644 --- a/CoqOfPython/ethereum/paris/vm/gas.v +++ b/CoqOfPython/ethereum/paris/vm/gas.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.paris.vm.gas". Definition expr_1 : Value.t := Constant.str " @@ -17,39 +17,26 @@ Introduction EVM gas constants and calculators. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Tuple" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. -Require ethereum.trace. -Axiom ethereum_trace_GasAndRefund : - IsGlobalAlias globals ethereum.trace.globals "GasAndRefund". -Axiom ethereum_trace_evm_trace : - IsGlobalAlias globals ethereum.trace.globals "evm_trace". +Axiom ethereum_trace_imports : + AreImported globals "ethereum.trace" [ "GasAndRefund"; "evm_trace" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.paris.vm.__init__. -Axiom ethereum_paris_vm___init___Evm : - IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Evm". +Axiom ethereum_paris_vm_imports : + AreImported globals "ethereum.paris.vm" [ "Evm" ]. -Require ethereum.paris.vm.exceptions. -Axiom ethereum_paris_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.paris.vm.exceptions.globals "OutOfGasError". +Axiom ethereum_paris_vm_exceptions_imports : + AreImported globals "ethereum.paris.vm.exceptions" [ "OutOfGasError" ]. Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -508,7 +495,7 @@ Definition charge_gas : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -625,105 +612,114 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := ], make_dict [] |) in - For make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ] in M.get_name (| globals, "extensions" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "size" |), - Constant.int 0 - |), - (* then *) + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ], + M.get_name (| globals, "extensions" |), ltac:(M.monadic ( - let _ := M.continue (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let before_size := - M.call (| - M.get_name (| globals, "ceil32" |), - make_list [ - M.get_name (| globals, "current_size" |) - ], - make_dict [] - |) in - let after_size := - M.call (| - M.get_name (| globals, "ceil32" |), - make_list [ - BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "size" |), + Constant.int 0 |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.lt_e (| - M.get_name (| globals, "after_size" |), - M.get_name (| globals, "before_size" |) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.continue (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let size_to_extend := BinOp.add - BinOp.sub (| + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let before_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "current_size" |) + ], + make_dict [] + |) in + let after_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let size_to_extend := BinOp.add + BinOp.sub (| M.get_name (| globals, "after_size" |), M.get_name (| globals, "before_size" |) |) - BinOp.sub (| + BinOp.sub (| M.get_name (| globals, "after_size" |), M.get_name (| globals, "before_size" |) |) in - let already_paid := - M.call (| - M.get_name (| globals, "calculate_memory_gas_cost" |), - make_list [ - M.get_name (| globals, "before_size" |) - ], - make_dict [] - |) in - let total_cost := - M.call (| - M.get_name (| globals, "calculate_memory_gas_cost" |), - make_list [ - M.get_name (| globals, "after_size" |) - ], - make_dict [] - |) in - let to_be_paid := BinOp.add - BinOp.sub (| + let already_paid := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "before_size" |) + ], + make_dict [] + |) in + let total_cost := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "after_size" |) + ], + make_dict [] + |) in + let to_be_paid := BinOp.add + BinOp.sub (| M.get_name (| globals, "total_cost" |), M.get_name (| globals, "already_paid" |) |) - BinOp.sub (| + BinOp.sub (| M.get_name (| globals, "total_cost" |), M.get_name (| globals, "already_paid" |) |) in - let current_size := - M.get_name (| globals, "after_size" |) in - EndFor. + let current_size := + M.get_name (| globals, "after_size" |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ExtendMemory" |), diff --git a/CoqOfPython/ethereum/paris/vm/instructions/__init__.v b/CoqOfPython/ethereum/paris/vm/instructions/__init__.v index 7cd4d8a..1dcc787 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/__init__.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.paris.vm.instructions.__init__". Definition expr_1 : Value.t := Constant.str " @@ -20,59 +20,44 @@ implementations. (* At top_level_stmt: unsupported node type: Import *) -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict" ]. -Require ethereum.paris.vm.instructions.__init__. -Axiom ethereum_paris_vm_instructions___init___arithmetic : - IsGlobalAlias globals ethereum.paris.vm.instructions.__init__.globals "arithmetic". +Axiom ethereum_paris_vm_instructions_imports : + AreImported globals "ethereum.paris.vm.instructions" [ "arithmetic" ]. -Require ethereum.paris.vm.instructions.__init__. -Axiom ethereum_paris_vm_instructions___init___bitwise : - IsGlobalAlias globals ethereum.paris.vm.instructions.__init__.globals "bitwise". +Axiom ethereum_paris_vm_instructions_imports : + AreImported globals "ethereum.paris.vm.instructions" [ "bitwise" ]. -Require ethereum.paris.vm.instructions.__init__. -Axiom ethereum_paris_vm_instructions___init___block : - IsGlobalAlias globals ethereum.paris.vm.instructions.__init__.globals "block". +Axiom ethereum_paris_vm_instructions_imports : + AreImported globals "ethereum.paris.vm.instructions" [ "block" ]. -Require ethereum.paris.vm.instructions.__init__. -Axiom ethereum_paris_vm_instructions___init___comparison : - IsGlobalAlias globals ethereum.paris.vm.instructions.__init__.globals "comparison". +Axiom ethereum_paris_vm_instructions_imports : + AreImported globals "ethereum.paris.vm.instructions" [ "comparison" ]. -Require ethereum.paris.vm.instructions.__init__. -Axiom ethereum_paris_vm_instructions___init___control_flow : - IsGlobalAlias globals ethereum.paris.vm.instructions.__init__.globals "control_flow". +Axiom ethereum_paris_vm_instructions_imports : + AreImported globals "ethereum.paris.vm.instructions" [ "control_flow" ]. -Require ethereum.paris.vm.instructions.__init__. -Axiom ethereum_paris_vm_instructions___init___environment : - IsGlobalAlias globals ethereum.paris.vm.instructions.__init__.globals "environment". +Axiom ethereum_paris_vm_instructions_imports : + AreImported globals "ethereum.paris.vm.instructions" [ "environment" ]. -Require ethereum.paris.vm.instructions.__init__. -Axiom ethereum_paris_vm_instructions___init___keccak : - IsGlobalAlias globals ethereum.paris.vm.instructions.__init__.globals "keccak". +Axiom ethereum_paris_vm_instructions_imports : + AreImported globals "ethereum.paris.vm.instructions" [ "keccak" ]. -Require ethereum.paris.vm.instructions.__init__. -Axiom ethereum_paris_vm_instructions___init___log : - IsGlobalAlias globals ethereum.paris.vm.instructions.__init__.globals "log". +Axiom ethereum_paris_vm_instructions_imports : + AreImported globals "ethereum.paris.vm.instructions" [ "log" ]. -Require ethereum.paris.vm.instructions.__init__. -Axiom ethereum_paris_vm_instructions___init___memory : - IsGlobalAlias globals ethereum.paris.vm.instructions.__init__.globals "memory". +Axiom ethereum_paris_vm_instructions_imports : + AreImported globals "ethereum.paris.vm.instructions" [ "memory" ]. -Require ethereum.paris.vm.instructions.__init__. -Axiom ethereum_paris_vm_instructions___init___stack : - IsGlobalAlias globals ethereum.paris.vm.instructions.__init__.globals "stack". +Axiom ethereum_paris_vm_instructions_imports : + AreImported globals "ethereum.paris.vm.instructions" [ "stack" ]. -Require ethereum.paris.vm.instructions.__init__. -Axiom ethereum_paris_vm_instructions___init___storage : - IsGlobalAlias globals ethereum.paris.vm.instructions.__init__.globals "storage". +Axiom ethereum_paris_vm_instructions_imports : + AreImported globals "ethereum.paris.vm.instructions" [ "storage" ]. -Require ethereum.paris.vm.instructions.__init__. -Axiom ethereum_paris_vm_instructions___init___system : - IsGlobalAlias globals ethereum.paris.vm.instructions.__init__.globals "system". +Axiom ethereum_paris_vm_instructions_imports : + AreImported globals "ethereum.paris.vm.instructions" [ "system" ]. Definition Ops : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/paris/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/paris/vm/instructions/arithmetic.v index aa1d6e0..8708af7 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/arithmetic.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.paris.vm.instructions.arithmetic". Definition expr_1 : Value.t := Constant.str " @@ -17,43 +17,20 @@ Introduction Implementations of the EVM Arithmetic instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U255_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U255_CEIL_VALUE". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_U256_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U255_CEIL_VALUE"; "U256"; "U256_CEIL_VALUE"; "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_get_sign : - IsGlobalAlias globals ethereum.utils.numeric.globals "get_sign". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "get_sign" ]. -Require ethereum.paris.vm.__init__. -Axiom ethereum_paris_vm___init___Evm : - IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Evm". +Axiom ethereum_paris_vm_imports : + AreImported globals "ethereum.paris.vm" [ "Evm" ]. -Require ethereum.paris.vm.gas. -Axiom ethereum_paris_vm_gas_GAS_EXPONENTIATION : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_EXPONENTIATION". -Axiom ethereum_paris_vm_gas_GAS_EXPONENTIATION_PER_BYTE : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_EXPONENTIATION_PER_BYTE". -Axiom ethereum_paris_vm_gas_GAS_LOW : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_LOW". -Axiom ethereum_paris_vm_gas_GAS_MID : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_MID". -Axiom ethereum_paris_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_paris_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "charge_gas". +Axiom ethereum_paris_vm_gas_imports : + AreImported globals "ethereum.paris.vm.gas" [ "GAS_EXPONENTIATION"; "GAS_EXPONENTIATION_PER_BYTE"; "GAS_LOW"; "GAS_MID"; "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.paris.vm.stack. -Axiom ethereum_paris_vm_stack_pop : - IsGlobalAlias globals ethereum.paris.vm.stack.globals "pop". -Axiom ethereum_paris_vm_stack_push : - IsGlobalAlias globals ethereum.paris.vm.stack.globals "push". +Axiom ethereum_paris_vm_stack_imports : + AreImported globals "ethereum.paris.vm.stack" [ "pop"; "push" ]. Definition add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -1030,19 +1007,27 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let value_bytes := - M.get_subscript (| M.get_name (| globals, "value_bytes" |), M.slice (| BinOp.sub (| - Constant.int 31, - M.call (| - M.get_name (| globals, "int" |), - make_list [ - M.get_name (| globals, "byte_num" |) - ], - make_dict [] - |) - |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "value_bytes" |), + BinOp.sub (| + Constant.int 31, + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "byte_num" |) + ], + make_dict [] + |) + |), + Constant.None_, + Constant.None_ + |) in let sign_bit := BinOp.r_shift (| - M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), + M.get_subscript (| + M.get_name (| globals, "value_bytes" |), + Constant.int 0 + |), Constant.int 7 |) in let _ := diff --git a/CoqOfPython/ethereum/paris/vm/instructions/bitwise.v b/CoqOfPython/ethereum/paris/vm/instructions/bitwise.v index 0527ef4..aed53c1 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/bitwise.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.paris.vm.instructions.bitwise". Definition expr_1 : Value.t := Constant.str " @@ -17,27 +17,17 @@ Introduction Implementations of the EVM bitwise instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_U256_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "U256_CEIL_VALUE" ]. -Require ethereum.paris.vm.__init__. -Axiom ethereum_paris_vm___init___Evm : - IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Evm". +Axiom ethereum_paris_vm_imports : + AreImported globals "ethereum.paris.vm" [ "Evm" ]. -Require ethereum.paris.vm.gas. -Axiom ethereum_paris_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_paris_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "charge_gas". +Axiom ethereum_paris_vm_gas_imports : + AreImported globals "ethereum.paris.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.paris.vm.stack. -Axiom ethereum_paris_vm_stack_pop : - IsGlobalAlias globals ethereum.paris.vm.stack.globals "pop". -Axiom ethereum_paris_vm_stack_push : - IsGlobalAlias globals ethereum.paris.vm.stack.globals "push". +Axiom ethereum_paris_vm_stack_imports : + AreImported globals "ethereum.paris.vm.stack" [ "pop"; "push" ]. Definition bitwise_and : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/paris/vm/instructions/block.v b/CoqOfPython/ethereum/paris/vm/instructions/block.v index b3c359e..05a2cd3 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/block.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/block.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.paris.vm.instructions.block". Definition expr_1 : Value.t := Constant.str " @@ -17,27 +17,17 @@ Introduction Implementations of the EVM block instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.paris.vm.__init__. -Axiom ethereum_paris_vm___init___Evm : - IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Evm". +Axiom ethereum_paris_vm_imports : + AreImported globals "ethereum.paris.vm" [ "Evm" ]. -Require ethereum.paris.vm.gas. -Axiom ethereum_paris_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_BASE". -Axiom ethereum_paris_vm_gas_GAS_BLOCK_HASH : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_BLOCK_HASH". -Axiom ethereum_paris_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "charge_gas". +Axiom ethereum_paris_vm_gas_imports : + AreImported globals "ethereum.paris.vm.gas" [ "GAS_BASE"; "GAS_BLOCK_HASH"; "charge_gas" ]. -Require ethereum.paris.vm.stack. -Axiom ethereum_paris_vm_stack_pop : - IsGlobalAlias globals ethereum.paris.vm.stack.globals "pop". -Axiom ethereum_paris_vm_stack_push : - IsGlobalAlias globals ethereum.paris.vm.stack.globals "push". +Axiom ethereum_paris_vm_stack_imports : + AreImported globals "ethereum.paris.vm.stack" [ "pop"; "push" ]. Definition block_hash : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -100,10 +90,13 @@ Definition block_hash : Value.t -> Value.t -> M := (* else *) )), ltac:(M.monadic ( let hash := - M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), - M.get_name (| globals, "block_number" |) - |) |) |) in + M.get_subscript (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), + UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + M.get_name (| globals, "block_number" |) + |) |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/paris/vm/instructions/comparison.v b/CoqOfPython/ethereum/paris/vm/instructions/comparison.v index 6c08576..b80d897 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/comparison.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.paris.vm.instructions.comparison". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementations of the EVM Comparison instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.paris.vm.__init__. -Axiom ethereum_paris_vm___init___Evm : - IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Evm". +Axiom ethereum_paris_vm_imports : + AreImported globals "ethereum.paris.vm" [ "Evm" ]. -Require ethereum.paris.vm.gas. -Axiom ethereum_paris_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_paris_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "charge_gas". +Axiom ethereum_paris_vm_gas_imports : + AreImported globals "ethereum.paris.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.paris.vm.stack. -Axiom ethereum_paris_vm_stack_pop : - IsGlobalAlias globals ethereum.paris.vm.stack.globals "pop". -Axiom ethereum_paris_vm_stack_push : - IsGlobalAlias globals ethereum.paris.vm.stack.globals "push". +Axiom ethereum_paris_vm_stack_imports : + AreImported globals "ethereum.paris.vm.stack" [ "pop"; "push" ]. Definition less_than : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/paris/vm/instructions/control_flow.v b/CoqOfPython/ethereum/paris/vm/instructions/control_flow.v index 44bff2b..fa26588 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/control_flow.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.paris.vm.instructions.control_flow". Definition expr_1 : Value.t := Constant.str " @@ -17,37 +17,20 @@ Introduction Implementations of the EVM control flow instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. -Require ethereum.paris.vm.gas. -Axiom ethereum_paris_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_BASE". -Axiom ethereum_paris_vm_gas_GAS_HIGH : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_HIGH". -Axiom ethereum_paris_vm_gas_GAS_JUMPDEST : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_JUMPDEST". -Axiom ethereum_paris_vm_gas_GAS_MID : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_MID". -Axiom ethereum_paris_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "charge_gas". +Axiom ethereum_paris_vm_gas_imports : + AreImported globals "ethereum.paris.vm.gas" [ "GAS_BASE"; "GAS_HIGH"; "GAS_JUMPDEST"; "GAS_MID"; "charge_gas" ]. -Require ethereum.paris.vm.__init__. -Axiom ethereum_paris_vm___init___Evm : - IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Evm". +Axiom ethereum_paris_vm_imports : + AreImported globals "ethereum.paris.vm" [ "Evm" ]. -Require ethereum.paris.vm.exceptions. -Axiom ethereum_paris_vm_exceptions_InvalidJumpDestError : - IsGlobalAlias globals ethereum.paris.vm.exceptions.globals "InvalidJumpDestError". +Axiom ethereum_paris_vm_exceptions_imports : + AreImported globals "ethereum.paris.vm.exceptions" [ "InvalidJumpDestError" ]. -Require ethereum.paris.vm.stack. -Axiom ethereum_paris_vm_stack_pop : - IsGlobalAlias globals ethereum.paris.vm.stack.globals "pop". -Axiom ethereum_paris_vm_stack_push : - IsGlobalAlias globals ethereum.paris.vm.stack.globals "push". +Axiom ethereum_paris_vm_stack_imports : + AreImported globals "ethereum.paris.vm.stack" [ "pop"; "push" ]. Definition stop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -117,7 +100,7 @@ Definition jump : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "InvalidJumpDestError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -205,7 +188,7 @@ Definition jumpi : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "InvalidJumpDestError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/paris/vm/instructions/environment.v b/CoqOfPython/ethereum/paris/vm/instructions/environment.v index 94f1204..5b2a06c 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/environment.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.paris.vm.instructions.environment". Definition expr_1 : Value.t := Constant.str " @@ -17,75 +17,41 @@ Introduction Implementations of the EVM environment related instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". - -Require ethereum.paris.fork_types. -Axiom ethereum_paris_fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals ethereum.paris.fork_types.globals "EMPTY_ACCOUNT". - -Require ethereum.paris.state. -Axiom ethereum_paris_state_get_account : - IsGlobalAlias globals ethereum.paris.state.globals "get_account". - -Require ethereum.paris.utils.address. -Axiom ethereum_paris_utils_address_to_address : - IsGlobalAlias globals ethereum.paris.utils.address.globals "to_address". - -Require ethereum.paris.vm.memory. -Axiom ethereum_paris_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.paris.vm.memory.globals "buffer_read". -Axiom ethereum_paris_vm_memory_memory_write : - IsGlobalAlias globals ethereum.paris.vm.memory.globals "memory_write". - -Require ethereum.paris.vm.__init__. -Axiom ethereum_paris_vm___init___Evm : - IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Evm". - -Require ethereum.paris.vm.exceptions. -Axiom ethereum_paris_vm_exceptions_OutOfBoundsRead : - IsGlobalAlias globals ethereum.paris.vm.exceptions.globals "OutOfBoundsRead". - -Require ethereum.paris.vm.gas. -Axiom ethereum_paris_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_BASE". -Axiom ethereum_paris_vm_gas_GAS_COLD_ACCOUNT_ACCESS : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_COLD_ACCOUNT_ACCESS". -Axiom ethereum_paris_vm_gas_GAS_COPY : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_COPY". -Axiom ethereum_paris_vm_gas_GAS_FAST_STEP : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_FAST_STEP". -Axiom ethereum_paris_vm_gas_GAS_RETURN_DATA_COPY : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_RETURN_DATA_COPY". -Axiom ethereum_paris_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_paris_vm_gas_GAS_WARM_ACCESS : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_WARM_ACCESS". -Axiom ethereum_paris_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_paris_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "charge_gas". - -Require ethereum.paris.vm.stack. -Axiom ethereum_paris_vm_stack_pop : - IsGlobalAlias globals ethereum.paris.vm.stack.globals "pop". -Axiom ethereum_paris_vm_stack_push : - IsGlobalAlias globals ethereum.paris.vm.stack.globals "push". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. + +Axiom ethereum_paris_fork_types_imports : + AreImported globals "ethereum.paris.fork_types" [ "EMPTY_ACCOUNT" ]. + +Axiom ethereum_paris_state_imports : + AreImported globals "ethereum.paris.state" [ "get_account" ]. + +Axiom ethereum_paris_utils_address_imports : + AreImported globals "ethereum.paris.utils.address" [ "to_address" ]. + +Axiom ethereum_paris_vm_memory_imports : + AreImported globals "ethereum.paris.vm.memory" [ "buffer_read"; "memory_write" ]. + +Axiom ethereum_paris_vm_imports : + AreImported globals "ethereum.paris.vm" [ "Evm" ]. + +Axiom ethereum_paris_vm_exceptions_imports : + AreImported globals "ethereum.paris.vm.exceptions" [ "OutOfBoundsRead" ]. + +Axiom ethereum_paris_vm_gas_imports : + AreImported globals "ethereum.paris.vm.gas" [ "GAS_BASE"; "GAS_COLD_ACCOUNT_ACCESS"; "GAS_COPY"; "GAS_FAST_STEP"; "GAS_RETURN_DATA_COPY"; "GAS_VERY_LOW"; "GAS_WARM_ACCESS"; "calculate_gas_extend_memory"; "charge_gas" ]. + +Axiom ethereum_paris_vm_stack_imports : + AreImported globals "ethereum.paris.vm.stack" [ "pop"; "push" ]. Definition address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -158,7 +124,7 @@ Definition balance : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -810,7 +776,7 @@ Definition extcodesize : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -966,7 +932,7 @@ Definition extcodecopy : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -1225,10 +1191,15 @@ Definition returndatacopy : Value.t -> Value.t -> M := |) |) in let value := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.slice (| M.get_name (| globals, "return_data_start_position" |), BinOp.add (| + M.slice (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |), - M.get_name (| globals, "size" |) - |) |) |) in + BinOp.add (| + M.get_name (| globals, "return_data_start_position" |), + M.get_name (| globals, "size" |) + |), + Constant.None_ + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -1272,7 +1243,7 @@ Definition extcodehash : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), diff --git a/CoqOfPython/ethereum/paris/vm/instructions/keccak.v b/CoqOfPython/ethereum/paris/vm/instructions/keccak.v index 635fe27..12f0bec 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/keccak.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.paris.vm.instructions.keccak". Definition expr_1 : Value.t := Constant.str " @@ -17,43 +17,26 @@ Introduction Implementations of the EVM keccak instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". - -Require ethereum.paris.vm.__init__. -Axiom ethereum_paris_vm___init___Evm : - IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Evm". - -Require ethereum.paris.vm.gas. -Axiom ethereum_paris_vm_gas_GAS_KECCAK256 : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_KECCAK256". -Axiom ethereum_paris_vm_gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_KECCAK256_WORD". -Axiom ethereum_paris_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_paris_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "charge_gas". - -Require ethereum.paris.vm.memory. -Axiom ethereum_paris_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.paris.vm.memory.globals "memory_read_bytes". - -Require ethereum.paris.vm.stack. -Axiom ethereum_paris_vm_stack_pop : - IsGlobalAlias globals ethereum.paris.vm.stack.globals "pop". -Axiom ethereum_paris_vm_stack_push : - IsGlobalAlias globals ethereum.paris.vm.stack.globals "push". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. + +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. + +Axiom ethereum_paris_vm_imports : + AreImported globals "ethereum.paris.vm" [ "Evm" ]. + +Axiom ethereum_paris_vm_gas_imports : + AreImported globals "ethereum.paris.vm.gas" [ "GAS_KECCAK256"; "GAS_KECCAK256_WORD"; "calculate_gas_extend_memory"; "charge_gas" ]. + +Axiom ethereum_paris_vm_memory_imports : + AreImported globals "ethereum.paris.vm.memory" [ "memory_read_bytes" ]. + +Axiom ethereum_paris_vm_stack_imports : + AreImported globals "ethereum.paris.vm.stack" [ "pop"; "push" ]. Definition keccak : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/paris/vm/instructions/log.v b/CoqOfPython/ethereum/paris/vm/instructions/log.v index df4a2fe..3c8093d 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/log.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/log.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.paris.vm.instructions.log". Definition expr_1 : Value.t := Constant.str " @@ -17,49 +17,32 @@ Introduction Implementations of the EVM logging instructions. ". -Require functools. -Axiom functools_partial : - IsGlobalAlias globals functools.globals "partial". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.paris.blocks. -Axiom ethereum_paris_blocks_Log : - IsGlobalAlias globals ethereum.paris.blocks.globals "Log". - -Require ethereum.paris.vm.__init__. -Axiom ethereum_paris_vm___init___Evm : - IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Evm". - -Require ethereum.paris.vm.exceptions. -Axiom ethereum_paris_vm_exceptions_WriteInStaticContext : - IsGlobalAlias globals ethereum.paris.vm.exceptions.globals "WriteInStaticContext". - -Require ethereum.paris.vm.gas. -Axiom ethereum_paris_vm_gas_GAS_LOG : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_LOG". -Axiom ethereum_paris_vm_gas_GAS_LOG_DATA : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_LOG_DATA". -Axiom ethereum_paris_vm_gas_GAS_LOG_TOPIC : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_LOG_TOPIC". -Axiom ethereum_paris_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_paris_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "charge_gas". - -Require ethereum.paris.vm.memory. -Axiom ethereum_paris_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.paris.vm.memory.globals "memory_read_bytes". - -Require ethereum.paris.vm.stack. -Axiom ethereum_paris_vm_stack_pop : - IsGlobalAlias globals ethereum.paris.vm.stack.globals "pop". +Axiom functools_imports : + AreImported globals "functools" [ "partial" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_paris_blocks_imports : + AreImported globals "ethereum.paris.blocks" [ "Log" ]. + +Axiom ethereum_paris_vm_imports : + AreImported globals "ethereum.paris.vm" [ "Evm" ]. + +Axiom ethereum_paris_vm_exceptions_imports : + AreImported globals "ethereum.paris.vm.exceptions" [ "WriteInStaticContext" ]. + +Axiom ethereum_paris_vm_gas_imports : + AreImported globals "ethereum.paris.vm.gas" [ "GAS_LOG"; "GAS_LOG_DATA"; "GAS_LOG_TOPIC"; "calculate_gas_extend_memory"; "charge_gas" ]. + +Axiom ethereum_paris_vm_memory_imports : + AreImported globals "ethereum.paris.vm.memory" [ "memory_read_bytes" ]. + +Axiom ethereum_paris_vm_stack_imports : + AreImported globals "ethereum.paris.vm.stack" [ "pop" ]. Definition log_n : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -96,33 +79,42 @@ Definition log_n : Value.t -> Value.t -> M := |) in let topics := make_list [] in - For M.get_name (| globals, "_" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - M.get_name (| globals, "num_topics" |) - ], - make_dict [] - |) do - let topic := + let _ := + M.for_ (| + M.get_name (| globals, "_" |), M.call (| - M.get_field (| M.call (| - M.get_name (| globals, "pop" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] - |), "to_be_bytes32" |), - make_list [], - make_dict [] - |) in - let _ := M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "num_topics" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let topic := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| M.get_field (| M.get_name (| globals, "topics" |), "append" |), make_list [ M.get_name (| globals, "topic" |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let extend_memory := M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), diff --git a/CoqOfPython/ethereum/paris/vm/instructions/memory.v b/CoqOfPython/ethereum/paris/vm/instructions/memory.v index 119554e..4c214b5 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/memory.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.paris.vm.instructions.memory". Definition expr_1 : Value.t := Constant.str " @@ -17,37 +17,20 @@ Introduction Implementations of the EVM Memory instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes" ]. -Require ethereum.paris.vm.__init__. -Axiom ethereum_paris_vm___init___Evm : - IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Evm". +Axiom ethereum_paris_vm_imports : + AreImported globals "ethereum.paris.vm" [ "Evm" ]. -Require ethereum.paris.vm.gas. -Axiom ethereum_paris_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_BASE". -Axiom ethereum_paris_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_paris_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_paris_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "charge_gas". +Axiom ethereum_paris_vm_gas_imports : + AreImported globals "ethereum.paris.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. -Require ethereum.paris.vm.memory. -Axiom ethereum_paris_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.paris.vm.memory.globals "memory_read_bytes". -Axiom ethereum_paris_vm_memory_memory_write : - IsGlobalAlias globals ethereum.paris.vm.memory.globals "memory_write". +Axiom ethereum_paris_vm_memory_imports : + AreImported globals "ethereum.paris.vm.memory" [ "memory_read_bytes"; "memory_write" ]. -Require ethereum.paris.vm.stack. -Axiom ethereum_paris_vm_stack_pop : - IsGlobalAlias globals ethereum.paris.vm.stack.globals "pop". -Axiom ethereum_paris_vm_stack_push : - IsGlobalAlias globals ethereum.paris.vm.stack.globals "push". +Axiom ethereum_paris_vm_stack_imports : + AreImported globals "ethereum.paris.vm.stack" [ "pop"; "push" ]. Definition mstore : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/paris/vm/instructions/stack.v b/CoqOfPython/ethereum/paris/vm/instructions/stack.v index e7dd5b9..1a7d994 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/stack.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.paris.vm.instructions.stack". Definition expr_1 : Value.t := Constant.str " @@ -17,39 +17,26 @@ Introduction Implementations of the EVM stack related instructions. ". -Require functools. -Axiom functools_partial : - IsGlobalAlias globals functools.globals "partial". +Axiom functools_imports : + AreImported globals "functools" [ "partial" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.paris.vm.__init__. -Axiom ethereum_paris_vm___init___Evm : - IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Evm". -Axiom ethereum_paris_vm___init___stack : - IsGlobalAlias globals ethereum.paris.vm.__init__.globals "stack". +Axiom ethereum_paris_vm_imports : + AreImported globals "ethereum.paris.vm" [ "Evm"; "stack" ]. -Require ethereum.paris.vm.exceptions. -Axiom ethereum_paris_vm_exceptions_StackUnderflowError : - IsGlobalAlias globals ethereum.paris.vm.exceptions.globals "StackUnderflowError". +Axiom ethereum_paris_vm_exceptions_imports : + AreImported globals "ethereum.paris.vm.exceptions" [ "StackUnderflowError" ]. -Require ethereum.paris.vm.gas. -Axiom ethereum_paris_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_BASE". -Axiom ethereum_paris_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_paris_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "charge_gas". +Axiom ethereum_paris_vm_gas_imports : + AreImported globals "ethereum.paris.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.paris.vm.memory. -Axiom ethereum_paris_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.paris.vm.memory.globals "buffer_read". +Axiom ethereum_paris_vm_memory_imports : + AreImported globals "ethereum.paris.vm.memory" [ "buffer_read" ]. Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -203,19 +190,22 @@ Definition dup_n : Value.t -> Value.t -> M := make_dict [] |) in let data_to_duplicate := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] + BinOp.sub (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), + Constant.int 1 |), - Constant.int 1 - |), - M.get_name (| globals, "item_number" |) - |) |) in + M.get_name (| globals, "item_number" |) + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "stack" |), "push" |), make_list [ @@ -278,14 +268,26 @@ Definition swap_n : Value.t -> Value.t -> M := make_dict [] |) in let _ := M.assign (| - make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| - UnOp.sub (| Constant.int 1 |), - M.get_name (| globals, "item_number" |) - |) |) ], - make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| - UnOp.sub (| Constant.int 1 |), - M.get_name (| globals, "item_number" |) - |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |) ] + make_tuple [ M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + UnOp.sub (| Constant.int 1 |) + |); M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) + |) ], + make_tuple [ M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) + |); M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + UnOp.sub (| Constant.int 1 |) + |) ] |) in let _ := M.assign_op (| BinOp.add, diff --git a/CoqOfPython/ethereum/paris/vm/instructions/storage.v b/CoqOfPython/ethereum/paris/vm/instructions/storage.v index 945f785..236ef48 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/storage.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.paris.vm.instructions.storage". Definition expr_1 : Value.t := Constant.str " @@ -17,53 +17,26 @@ Introduction Implementations of the EVM storage related instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.paris.state. -Axiom ethereum_paris_state_get_storage : - IsGlobalAlias globals ethereum.paris.state.globals "get_storage". -Axiom ethereum_paris_state_get_storage_original : - IsGlobalAlias globals ethereum.paris.state.globals "get_storage_original". -Axiom ethereum_paris_state_set_storage : - IsGlobalAlias globals ethereum.paris.state.globals "set_storage". +Axiom ethereum_paris_state_imports : + AreImported globals "ethereum.paris.state" [ "get_storage"; "get_storage_original"; "set_storage" ]. -Require ethereum.paris.vm.__init__. -Axiom ethereum_paris_vm___init___Evm : - IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Evm". +Axiom ethereum_paris_vm_imports : + AreImported globals "ethereum.paris.vm" [ "Evm" ]. -Require ethereum.paris.vm.exceptions. -Axiom ethereum_paris_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.paris.vm.exceptions.globals "OutOfGasError". -Axiom ethereum_paris_vm_exceptions_WriteInStaticContext : - IsGlobalAlias globals ethereum.paris.vm.exceptions.globals "WriteInStaticContext". +Axiom ethereum_paris_vm_exceptions_imports : + AreImported globals "ethereum.paris.vm.exceptions" [ "OutOfGasError"; "WriteInStaticContext" ]. -Require ethereum.paris.vm.gas. -Axiom ethereum_paris_vm_gas_GAS_CALL_STIPEND : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_CALL_STIPEND". -Axiom ethereum_paris_vm_gas_GAS_COLD_SLOAD : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_COLD_SLOAD". -Axiom ethereum_paris_vm_gas_GAS_STORAGE_CLEAR_REFUND : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_STORAGE_CLEAR_REFUND". -Axiom ethereum_paris_vm_gas_GAS_STORAGE_SET : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_STORAGE_SET". -Axiom ethereum_paris_vm_gas_GAS_STORAGE_UPDATE : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_STORAGE_UPDATE". -Axiom ethereum_paris_vm_gas_GAS_WARM_ACCESS : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_WARM_ACCESS". -Axiom ethereum_paris_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "charge_gas". +Axiom ethereum_paris_vm_gas_imports : + AreImported globals "ethereum.paris.vm.gas" [ "GAS_CALL_STIPEND"; "GAS_COLD_SLOAD"; "GAS_STORAGE_CLEAR_REFUND"; "GAS_STORAGE_SET"; "GAS_STORAGE_UPDATE"; "GAS_WARM_ACCESS"; "charge_gas" ]. -Require ethereum.paris.vm.stack. -Axiom ethereum_paris_vm_stack_pop : - IsGlobalAlias globals ethereum.paris.vm.stack.globals "pop". -Axiom ethereum_paris_vm_stack_push : - IsGlobalAlias globals ethereum.paris.vm.stack.globals "push". +Axiom ethereum_paris_vm_stack_imports : + AreImported globals "ethereum.paris.vm.stack" [ "pop"; "push" ]. Definition sload : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -93,7 +66,7 @@ Definition sload : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) |), diff --git a/CoqOfPython/ethereum/paris/vm/instructions/system.v b/CoqOfPython/ethereum/paris/vm/instructions/system.v index 2c3b610..303ebfa 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/system.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/system.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.paris.vm.instructions.system". Definition expr_1 : Value.t := Constant.str " @@ -17,103 +17,38 @@ Introduction Implementations of the EVM system related instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.paris.fork_types. -Axiom ethereum_paris_fork_types_Address : - IsGlobalAlias globals ethereum.paris.fork_types.globals "Address". +Axiom ethereum_paris_fork_types_imports : + AreImported globals "ethereum.paris.fork_types" [ "Address" ]. -Require ethereum.paris.state. -Axiom ethereum_paris_state_account_exists_and_is_empty : - IsGlobalAlias globals ethereum.paris.state.globals "account_exists_and_is_empty". -Axiom ethereum_paris_state_account_has_code_or_nonce : - IsGlobalAlias globals ethereum.paris.state.globals "account_has_code_or_nonce". -Axiom ethereum_paris_state_get_account : - IsGlobalAlias globals ethereum.paris.state.globals "get_account". -Axiom ethereum_paris_state_increment_nonce : - IsGlobalAlias globals ethereum.paris.state.globals "increment_nonce". -Axiom ethereum_paris_state_is_account_alive : - IsGlobalAlias globals ethereum.paris.state.globals "is_account_alive". -Axiom ethereum_paris_state_set_account_balance : - IsGlobalAlias globals ethereum.paris.state.globals "set_account_balance". +Axiom ethereum_paris_state_imports : + AreImported globals "ethereum.paris.state" [ "account_exists_and_is_empty"; "account_has_code_or_nonce"; "get_account"; "increment_nonce"; "is_account_alive"; "set_account_balance" ]. -Require ethereum.paris.utils.address. -Axiom ethereum_paris_utils_address_compute_contract_address : - IsGlobalAlias globals ethereum.paris.utils.address.globals "compute_contract_address". -Axiom ethereum_paris_utils_address_compute_create2_contract_address : - IsGlobalAlias globals ethereum.paris.utils.address.globals "compute_create2_contract_address". -Axiom ethereum_paris_utils_address_to_address : - IsGlobalAlias globals ethereum.paris.utils.address.globals "to_address". +Axiom ethereum_paris_utils_address_imports : + AreImported globals "ethereum.paris.utils.address" [ "compute_contract_address"; "compute_create2_contract_address"; "to_address" ]. -Require ethereum.paris.vm.__init__. -Axiom ethereum_paris_vm___init___Evm : - IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Evm". -Axiom ethereum_paris_vm___init___Message : - IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Message". -Axiom ethereum_paris_vm___init___incorporate_child_on_error : - IsGlobalAlias globals ethereum.paris.vm.__init__.globals "incorporate_child_on_error". -Axiom ethereum_paris_vm___init___incorporate_child_on_success : - IsGlobalAlias globals ethereum.paris.vm.__init__.globals "incorporate_child_on_success". +Axiom ethereum_paris_vm_imports : + AreImported globals "ethereum.paris.vm" [ "Evm"; "Message"; "incorporate_child_on_error"; "incorporate_child_on_success" ]. -Require ethereum.paris.vm.exceptions. -Axiom ethereum_paris_vm_exceptions_Revert : - IsGlobalAlias globals ethereum.paris.vm.exceptions.globals "Revert". -Axiom ethereum_paris_vm_exceptions_WriteInStaticContext : - IsGlobalAlias globals ethereum.paris.vm.exceptions.globals "WriteInStaticContext". +Axiom ethereum_paris_vm_exceptions_imports : + AreImported globals "ethereum.paris.vm.exceptions" [ "Revert"; "WriteInStaticContext" ]. -Require ethereum.paris.vm.gas. -Axiom ethereum_paris_vm_gas_GAS_CALL_VALUE : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_CALL_VALUE". -Axiom ethereum_paris_vm_gas_GAS_COLD_ACCOUNT_ACCESS : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_COLD_ACCOUNT_ACCESS". -Axiom ethereum_paris_vm_gas_GAS_CREATE : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_CREATE". -Axiom ethereum_paris_vm_gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_KECCAK256_WORD". -Axiom ethereum_paris_vm_gas_GAS_NEW_ACCOUNT : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_NEW_ACCOUNT". -Axiom ethereum_paris_vm_gas_GAS_SELF_DESTRUCT : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_SELF_DESTRUCT". -Axiom ethereum_paris_vm_gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". -Axiom ethereum_paris_vm_gas_GAS_WARM_ACCESS : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_WARM_ACCESS". -Axiom ethereum_paris_vm_gas_GAS_ZERO : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_ZERO". -Axiom ethereum_paris_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_paris_vm_gas_calculate_message_call_gas : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "calculate_message_call_gas". -Axiom ethereum_paris_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "charge_gas". -Axiom ethereum_paris_vm_gas_max_message_call_gas : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "max_message_call_gas". +Axiom ethereum_paris_vm_gas_imports : + AreImported globals "ethereum.paris.vm.gas" [ "GAS_CALL_VALUE"; "GAS_COLD_ACCOUNT_ACCESS"; "GAS_CREATE"; "GAS_KECCAK256_WORD"; "GAS_NEW_ACCOUNT"; "GAS_SELF_DESTRUCT"; "GAS_SELF_DESTRUCT_NEW_ACCOUNT"; "GAS_WARM_ACCESS"; "GAS_ZERO"; "calculate_gas_extend_memory"; "calculate_message_call_gas"; "charge_gas"; "max_message_call_gas" ]. -Require ethereum.paris.vm.memory. -Axiom ethereum_paris_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.paris.vm.memory.globals "memory_read_bytes". -Axiom ethereum_paris_vm_memory_memory_write : - IsGlobalAlias globals ethereum.paris.vm.memory.globals "memory_write". +Axiom ethereum_paris_vm_memory_imports : + AreImported globals "ethereum.paris.vm.memory" [ "memory_read_bytes"; "memory_write" ]. -Require ethereum.paris.vm.stack. -Axiom ethereum_paris_vm_stack_pop : - IsGlobalAlias globals ethereum.paris.vm.stack.globals "pop". -Axiom ethereum_paris_vm_stack_push : - IsGlobalAlias globals ethereum.paris.vm.stack.globals "push". +Axiom ethereum_paris_vm_stack_imports : + AreImported globals "ethereum.paris.vm.stack" [ "pop"; "push" ]. Definition generic_create : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -866,7 +801,12 @@ Definition generic_call : Value.t -> Value.t -> M := make_list [ M.get_field (| M.get_name (| globals, "evm" |), "memory" |); M.get_name (| globals, "memory_output_start_position" |); - M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), M.slice (| Constant.None_, M.get_name (| globals, "actual_output_size" |) |) |) + M.slice (| + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), + Constant.None_, + M.get_name (| globals, "actual_output_size" |), + Constant.None_ + |) ], make_dict [] |) in @@ -966,7 +906,7 @@ Definition call : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "to" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -1272,7 +1212,7 @@ Definition callcode : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "code_address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -1700,7 +1640,7 @@ Definition delegatecall : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "code_address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -1876,7 +1816,7 @@ Definition staticcall : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "to" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -2046,6 +1986,6 @@ Definition revert : Value.t -> Value.t -> M := make_dict [] |) |) in - let _ := M.raise (| Some(M.get_name (| globals, "Revert" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "Revert" |)) |) in let _ := M.pass (| |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/paris/vm/interpreter.v b/CoqOfPython/ethereum/paris/vm/interpreter.v index 0c037cb..f9d52c1 100644 --- a/CoqOfPython/ethereum/paris/vm/interpreter.v +++ b/CoqOfPython/ethereum/paris/vm/interpreter.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.paris.vm.interpreter". Definition expr_1 : Value.t := Constant.str " @@ -17,129 +17,50 @@ Introduction A straightforward interpreter that executes EVM code. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_Iterable : - IsGlobalAlias globals typing.globals "Iterable". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.trace. -Axiom ethereum_trace_EvmStop : - IsGlobalAlias globals ethereum.trace.globals "EvmStop". -Axiom ethereum_trace_OpEnd : - IsGlobalAlias globals ethereum.trace.globals "OpEnd". -Axiom ethereum_trace_OpException : - IsGlobalAlias globals ethereum.trace.globals "OpException". -Axiom ethereum_trace_OpStart : - IsGlobalAlias globals ethereum.trace.globals "OpStart". -Axiom ethereum_trace_PrecompileEnd : - IsGlobalAlias globals ethereum.trace.globals "PrecompileEnd". -Axiom ethereum_trace_PrecompileStart : - IsGlobalAlias globals ethereum.trace.globals "PrecompileStart". -Axiom ethereum_trace_TransactionEnd : - IsGlobalAlias globals ethereum.trace.globals "TransactionEnd". -Axiom ethereum_trace_evm_trace : - IsGlobalAlias globals ethereum.trace.globals "evm_trace". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.paris.blocks. -Axiom ethereum_paris_blocks_Log : - IsGlobalAlias globals ethereum.paris.blocks.globals "Log". - -Require ethereum.paris.fork_types. -Axiom ethereum_paris_fork_types_Address : - IsGlobalAlias globals ethereum.paris.fork_types.globals "Address". - -Require ethereum.paris.state. -Axiom ethereum_paris_state_account_exists_and_is_empty : - IsGlobalAlias globals ethereum.paris.state.globals "account_exists_and_is_empty". -Axiom ethereum_paris_state_account_has_code_or_nonce : - IsGlobalAlias globals ethereum.paris.state.globals "account_has_code_or_nonce". -Axiom ethereum_paris_state_begin_transaction : - IsGlobalAlias globals ethereum.paris.state.globals "begin_transaction". -Axiom ethereum_paris_state_commit_transaction : - IsGlobalAlias globals ethereum.paris.state.globals "commit_transaction". -Axiom ethereum_paris_state_destroy_storage : - IsGlobalAlias globals ethereum.paris.state.globals "destroy_storage". -Axiom ethereum_paris_state_increment_nonce : - IsGlobalAlias globals ethereum.paris.state.globals "increment_nonce". -Axiom ethereum_paris_state_mark_account_created : - IsGlobalAlias globals ethereum.paris.state.globals "mark_account_created". -Axiom ethereum_paris_state_move_ether : - IsGlobalAlias globals ethereum.paris.state.globals "move_ether". -Axiom ethereum_paris_state_rollback_transaction : - IsGlobalAlias globals ethereum.paris.state.globals "rollback_transaction". -Axiom ethereum_paris_state_set_code : - IsGlobalAlias globals ethereum.paris.state.globals "set_code". -Axiom ethereum_paris_state_touch_account : - IsGlobalAlias globals ethereum.paris.state.globals "touch_account". - -Require ethereum.paris.vm.__init__. -Axiom ethereum_paris_vm___init___Message : - IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Message". - -Require ethereum.paris.vm.gas. -Axiom ethereum_paris_vm_gas_GAS_CODE_DEPOSIT : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_CODE_DEPOSIT". -Axiom ethereum_paris_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "charge_gas". - -Require ethereum.paris.vm.precompiled_contracts.mapping. -Axiom ethereum_paris_vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : - IsGlobalAlias globals ethereum.paris.vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". - -Require ethereum.paris.vm.__init__. -Axiom ethereum_paris_vm___init___Environment : - IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Environment". -Axiom ethereum_paris_vm___init___Evm : - IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Evm". - -Require ethereum.paris.vm.exceptions. -Axiom ethereum_paris_vm_exceptions_AddressCollision : - IsGlobalAlias globals ethereum.paris.vm.exceptions.globals "AddressCollision". -Axiom ethereum_paris_vm_exceptions_ExceptionalHalt : - IsGlobalAlias globals ethereum.paris.vm.exceptions.globals "ExceptionalHalt". -Axiom ethereum_paris_vm_exceptions_InvalidContractPrefix : - IsGlobalAlias globals ethereum.paris.vm.exceptions.globals "InvalidContractPrefix". -Axiom ethereum_paris_vm_exceptions_InvalidOpcode : - IsGlobalAlias globals ethereum.paris.vm.exceptions.globals "InvalidOpcode". -Axiom ethereum_paris_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.paris.vm.exceptions.globals "OutOfGasError". -Axiom ethereum_paris_vm_exceptions_Revert : - IsGlobalAlias globals ethereum.paris.vm.exceptions.globals "Revert". -Axiom ethereum_paris_vm_exceptions_StackDepthLimitError : - IsGlobalAlias globals ethereum.paris.vm.exceptions.globals "StackDepthLimitError". - -Require ethereum.paris.vm.instructions.__init__. -Axiom ethereum_paris_vm_instructions___init___Ops : - IsGlobalAlias globals ethereum.paris.vm.instructions.__init__.globals "Ops". -Axiom ethereum_paris_vm_instructions___init___op_implementation : - IsGlobalAlias globals ethereum.paris.vm.instructions.__init__.globals "op_implementation". - -Require ethereum.paris.vm.runtime. -Axiom ethereum_paris_vm_runtime_get_valid_jump_destinations : - IsGlobalAlias globals ethereum.paris.vm.runtime.globals "get_valid_jump_destinations". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Iterable"; "Optional"; "Set"; "Tuple"; "Union" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. + +Axiom ethereum_trace_imports : + AreImported globals "ethereum.trace" [ "EvmStop"; "OpEnd"; "OpException"; "OpStart"; "PrecompileEnd"; "PrecompileStart"; "TransactionEnd"; "evm_trace" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_paris_blocks_imports : + AreImported globals "ethereum.paris.blocks" [ "Log" ]. + +Axiom ethereum_paris_fork_types_imports : + AreImported globals "ethereum.paris.fork_types" [ "Address" ]. + +Axiom ethereum_paris_state_imports : + AreImported globals "ethereum.paris.state" [ "account_exists_and_is_empty"; "account_has_code_or_nonce"; "begin_transaction"; "commit_transaction"; "destroy_storage"; "increment_nonce"; "mark_account_created"; "move_ether"; "rollback_transaction"; "set_code"; "touch_account" ]. + +Axiom ethereum_paris_vm_imports : + AreImported globals "ethereum.paris.vm" [ "Message" ]. + +Axiom ethereum_paris_vm_gas_imports : + AreImported globals "ethereum.paris.vm.gas" [ "GAS_CODE_DEPOSIT"; "charge_gas" ]. + +Axiom ethereum_paris_vm_precompiled_contracts_mapping_imports : + AreImported globals "ethereum.paris.vm.precompiled_contracts.mapping" [ "PRE_COMPILED_CONTRACTS" ]. + +Axiom ethereum_paris_vm_imports : + AreImported globals "ethereum.paris.vm" [ "Environment"; "Evm" ]. + +Axiom ethereum_paris_vm_exceptions_imports : + AreImported globals "ethereum.paris.vm.exceptions" [ "AddressCollision"; "ExceptionalHalt"; "InvalidContractPrefix"; "InvalidOpcode"; "OutOfGasError"; "Revert"; "StackDepthLimitError" ]. + +Axiom ethereum_paris_vm_instructions_imports : + AreImported globals "ethereum.paris.vm.instructions" [ "Ops"; "op_implementation" ]. + +Axiom ethereum_paris_vm_runtime_imports : + AreImported globals "ethereum.paris.vm.runtime" [ "get_valid_jump_destinations" ]. Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -520,7 +441,7 @@ Definition process_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "StackDepthLimitError" |), make_list [ Constant.str "Stack depth limit reached" diff --git a/CoqOfPython/ethereum/paris/vm/memory.v b/CoqOfPython/ethereum/paris/vm/memory.v index 08d2290..72ec45f 100644 --- a/CoqOfPython/ethereum/paris/vm/memory.v +++ b/CoqOfPython/ethereum/paris/vm/memory.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.paris.vm.memory". Definition expr_1 : Value.t := Constant.str " @@ -17,17 +17,11 @@ Introduction EVM memory operations. ". -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_right_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "right_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "right_pad_zero_bytes" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. Definition memory_write : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,22 +39,27 @@ Definition memory_write : Value.t -> Value.t -> M := Data to write to memory. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + M.slice (| + M.get_name (| globals, "memory" |), + M.get_name (| globals, "start_position" |), + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) - |) |) |), + Constant.None_ + |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_)). @@ -86,22 +85,27 @@ Definition memory_read_bytes : Value.t -> Value.t -> M := Data read from memory. " in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + M.slice (| + M.get_name (| globals, "memory" |), + M.get_name (| globals, "start_position" |), + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |) |) + Constant.None_ + |) |) in M.pure Constant.None_)). @@ -129,22 +133,27 @@ Definition buffer_read : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "right_pad_zero_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "buffer" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + M.slice (| + M.get_name (| globals, "buffer" |), + M.get_name (| globals, "start_position" |), + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |) |); + Constant.None_ + |); M.get_name (| globals, "size" |) ], make_dict [] diff --git a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/__init__.v index d1d68ef..a7d0bd0 100644 --- a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/__init__.v +++ b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.paris.vm.precompiled_contracts.__init__". Definition expr_1 : Value.t := Constant.str " @@ -18,9 +18,8 @@ Addresses of precompiled contracts and mappings to their implementations. ". -Require ethereum.paris.utils.hexadecimal. -Axiom ethereum_paris_utils_hexadecimal_hex_to_address : - IsGlobalAlias globals ethereum.paris.utils.hexadecimal.globals "hex_to_address". +Axiom ethereum_paris_utils_hexadecimal_imports : + AreImported globals "ethereum.paris.utils.hexadecimal" [ "hex_to_address" ]. Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS"; Constant.str "MODEXP_ADDRESS"; Constant.str "ALT_BN128_ADD_ADDRESS"; Constant.str "ALT_BN128_MUL_ADDRESS"; Constant.str "ALT_BN128_PAIRING_CHECK_ADDRESS"; Constant.str "BLAKE2F_ADDRESS" ] diff --git a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/alt_bn128.v index 996ca5a..8c25271 100644 --- a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/alt_bn128.v +++ b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/alt_bn128.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.paris.vm.precompiled_contracts.alt_bn128". Definition expr_1 : Value.t := Constant.str " @@ -17,49 +17,26 @@ Introduction Implementation of the ALT_BN128 precompiled contracts. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. -Require ethereum.crypto.alt_bn128. -Axiom ethereum_crypto_alt_bn128_ALT_BN128_CURVE_ORDER : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "ALT_BN128_CURVE_ORDER". -Axiom ethereum_crypto_alt_bn128_ALT_BN128_PRIME : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "ALT_BN128_PRIME". -Axiom ethereum_crypto_alt_bn128_BNF : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF". -Axiom ethereum_crypto_alt_bn128_BNF2 : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF2". -Axiom ethereum_crypto_alt_bn128_BNF12 : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF12". -Axiom ethereum_crypto_alt_bn128_BNP : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNP". -Axiom ethereum_crypto_alt_bn128_BNP2 : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNP2". -Axiom ethereum_crypto_alt_bn128_pairing : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "pairing". +Axiom ethereum_crypto_alt_bn128_imports : + AreImported globals "ethereum.crypto.alt_bn128" [ "ALT_BN128_CURVE_ORDER"; "ALT_BN128_PRIME"; "BNF"; "BNF2"; "BNF12"; "BNP"; "BNP2"; "pairing" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.paris.vm.__init__. -Axiom ethereum_paris_vm___init___Evm : - IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Evm". +Axiom ethereum_paris_vm_imports : + AreImported globals "ethereum.paris.vm" [ "Evm" ]. -Require ethereum.paris.vm.gas. -Axiom ethereum_paris_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "charge_gas". +Axiom ethereum_paris_vm_gas_imports : + AreImported globals "ethereum.paris.vm.gas" [ "charge_gas" ]. -Require ethereum.paris.vm.memory. -Axiom ethereum_paris_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.paris.vm.memory.globals "buffer_read". +Axiom ethereum_paris_vm_memory_imports : + AreImported globals "ethereum.paris.vm.memory" [ "buffer_read" ]. -Require ethereum.paris.vm.exceptions. -Axiom ethereum_paris_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.paris.vm.exceptions.globals "OutOfGasError". +Axiom ethereum_paris_vm_exceptions_imports : + AreImported globals "ethereum.paris.vm.exceptions" [ "OutOfGasError" ]. Definition alt_bn128_add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -208,23 +185,32 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ] do - let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| - M.get_name (| globals, "i" |), - M.get_name (| globals, "ALT_BN128_PRIME" |) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ], ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in (* At stmt: unsupported node type: Try *) let p := BinOp.add (| @@ -363,23 +349,32 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ] do - let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| - M.get_name (| globals, "i" |), - M.get_name (| globals, "ALT_BN128_PRIME" |) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ], ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in (* At stmt: unsupported node type: Try *) let p := M.call (| @@ -466,7 +461,7 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -480,76 +475,89 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - BinOp.floor_div (| + let _ := + M.for_ (| + M.get_name (| globals, "i" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "data" |) - ], - make_dict [] - |), - Constant.int 192 - |) - ], - make_dict [] - |) do - let values := - make_list [] in - For M.get_name (| globals, "j" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 6 - ], - make_dict [] - |) do - let value := + M.get_name (| globals, "range" |), + make_list [ + BinOp.floor_div (| M.call (| - M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + M.get_name (| globals, "len" |), make_list [ - M.get_subscript (| M.get_name (| globals, "data" |), M.slice (| BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "i" |), - Constant.int 192 - |), - BinOp.mult (| - Constant.int 32, - M.get_name (| globals, "j" |) - |) - |), BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "i" |), - Constant.int 192 - |), - BinOp.mult (| - Constant.int 32, - BinOp.add (| - M.get_name (| globals, "j" |), - Constant.int 1 - |) - |) - |) |) |) + M.get_name (| globals, "data" |) ], make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| - M.get_name (| globals, "value" |), - M.get_name (| globals, "ALT_BN128_PRIME" |) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let _ := M.call (| + |), + Constant.int 192 + |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let values := + make_list [] in + let _ := + M.for_ (| + M.get_name (| globals, "j" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 6 + ], + make_dict [] + |), + ltac:(M.monadic ( + let value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.slice (| + M.get_name (| globals, "data" |), + BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + M.get_name (| globals, "j" |) + |) + |), + BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "j" |), + Constant.int 1 + |) + |) + |), + Constant.None_ + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| M.get_field (| M.get_name (| globals, "values" |), "append" |), make_list [ M.call (| @@ -562,9 +570,14 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in (* At stmt: unsupported node type: Try *) - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.eq (| @@ -585,7 +598,7 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.eq (| @@ -606,49 +619,54 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| - M.get_name (| globals, "p" |), - M.call (| - M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) - |), + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "p" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "q" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |) + )) + |), + (* then *) ltac:(M.monadic ( - Compare.not_eq (| - M.get_name (| globals, "q" |), - M.call (| - M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) - |) - )) - |), - (* then *) - ltac:(M.monadic ( - let result := - BinOp.mult (| - M.get_name (| globals, "result" |), - M.call (| - M.get_name (| globals, "pairing" |), - make_list [ - M.get_name (| globals, "q" |); - M.get_name (| globals, "p" |) - ], - make_dict [] - |) - |) in + let result := + BinOp.mult (| + M.get_name (| globals, "result" |), + M.call (| + M.get_name (| globals, "pairing" |), + make_list [ + M.get_name (| globals, "q" |); + M.get_name (| globals, "p" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := (* if *) M.if_then_else (| diff --git a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/blake2f.v b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/blake2f.v index 3a5e5fd..77a5a42 100644 --- a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/blake2f.v +++ b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/blake2f.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.paris.vm.precompiled_contracts.blake2f". Definition expr_1 : Value.t := Constant.str " @@ -17,27 +17,20 @@ Introduction Implementation of the `Blake2` precompiled contract. ". -Require ethereum.crypto.blake2. -Axiom ethereum_crypto_blake2_Blake2b : - IsGlobalAlias globals ethereum.crypto.blake2.globals "Blake2b". +Axiom ethereum_crypto_blake2_imports : + AreImported globals "ethereum.crypto.blake2" [ "Blake2b" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.paris.vm.__init__. -Axiom ethereum_paris_vm___init___Evm : - IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Evm". +Axiom ethereum_paris_vm_imports : + AreImported globals "ethereum.paris.vm" [ "Evm" ]. -Require ethereum.paris.vm.gas. -Axiom ethereum_paris_vm_gas_GAS_BLAKE2_PER_ROUND : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_BLAKE2_PER_ROUND". -Axiom ethereum_paris_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "charge_gas". +Axiom ethereum_paris_vm_gas_imports : + AreImported globals "ethereum.paris.vm.gas" [ "GAS_BLAKE2_PER_ROUND"; "charge_gas" ]. -Require ethereum.paris.vm.exceptions. -Axiom ethereum_paris_vm_exceptions_InvalidParameter : - IsGlobalAlias globals ethereum.paris.vm.exceptions.globals "InvalidParameter". +Axiom ethereum_paris_vm_exceptions_imports : + AreImported globals "ethereum.paris.vm.exceptions" [ "InvalidParameter" ]. Definition blake2f : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -99,7 +92,7 @@ Definition blake2f : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.in (| + Compare.in_ (| M.get_name (| globals, "f" |), make_list [ Constant.int 0; diff --git a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/ecrecover.v index 7ac3491..c1ca85f 100644 --- a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/ecrecover.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.paris.vm.precompiled_contracts.ecrecover". Definition expr_1 : Value.t := Constant.str " @@ -17,39 +17,26 @@ Introduction Implementation of the ECRECOVER precompiled contract. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.crypto.elliptic_curve. -Axiom ethereum_crypto_elliptic_curve_SECP256K1N : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". -Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". +Axiom ethereum_crypto_elliptic_curve_imports : + AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_left_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. -Require ethereum.paris.vm.__init__. -Axiom ethereum_paris_vm___init___Evm : - IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Evm". +Axiom ethereum_paris_vm_imports : + AreImported globals "ethereum.paris.vm" [ "Evm" ]. -Require ethereum.paris.vm.gas. -Axiom ethereum_paris_vm_gas_GAS_ECRECOVER : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_ECRECOVER". -Axiom ethereum_paris_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "charge_gas". +Axiom ethereum_paris_vm_gas_imports : + AreImported globals "ethereum.paris.vm.gas" [ "GAS_ECRECOVER"; "charge_gas" ]. -Require ethereum.paris.vm.memory. -Axiom ethereum_paris_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.paris.vm.memory.globals "buffer_read". +Axiom ethereum_paris_vm_memory_imports : + AreImported globals "ethereum.paris.vm.memory" [ "buffer_read" ]. Definition ecrecover : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -264,13 +251,18 @@ Definition ecrecover : Value.t -> Value.t -> M := )) |) in (* At stmt: unsupported node type: Try *) let address := - M.get_subscript (| M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "public_key" |) - ], - make_dict [] - |), M.slice (| Constant.int 12, Constant.int 32 |) |) in + M.slice (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), + Constant.int 12, + Constant.int 32, + Constant.None_ + |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/identity.v index 5bd5e8c..1ccc7ab 100644 --- a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/identity.v +++ b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/identity.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.paris.vm.precompiled_contracts.identity". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementation of the `IDENTITY` precompiled contract. ". -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.paris.vm.__init__. -Axiom ethereum_paris_vm___init___Evm : - IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Evm". +Axiom ethereum_paris_vm_imports : + AreImported globals "ethereum.paris.vm" [ "Evm" ]. -Require ethereum.paris.vm.gas. -Axiom ethereum_paris_vm_gas_GAS_IDENTITY : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_IDENTITY". -Axiom ethereum_paris_vm_gas_GAS_IDENTITY_WORD : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_IDENTITY_WORD". -Axiom ethereum_paris_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "charge_gas". +Axiom ethereum_paris_vm_gas_imports : + AreImported globals "ethereum.paris.vm.gas" [ "GAS_IDENTITY"; "GAS_IDENTITY_WORD"; "charge_gas" ]. Definition identity : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/mapping.v index 428d10c..45e83d9 100644 --- a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/mapping.v +++ b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/mapping.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.paris.vm.precompiled_contracts.mapping". Definition expr_1 : Value.t := Constant.str " @@ -17,66 +17,34 @@ Introduction Mapping of precompiled contracts their implementations. ". -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". - -Require ethereum.paris.fork_types. -Axiom ethereum_paris_fork_types_Address : - IsGlobalAlias globals ethereum.paris.fork_types.globals "Address". - -Require ethereum.paris.vm.precompiled_contracts.__init__. -Axiom ethereum_paris_vm_precompiled_contracts___init___ALT_BN128_ADD_ADDRESS : - IsGlobalAlias globals ethereum.paris.vm.precompiled_contracts.__init__.globals "ALT_BN128_ADD_ADDRESS". -Axiom ethereum_paris_vm_precompiled_contracts___init___ALT_BN128_MUL_ADDRESS : - IsGlobalAlias globals ethereum.paris.vm.precompiled_contracts.__init__.globals "ALT_BN128_MUL_ADDRESS". -Axiom ethereum_paris_vm_precompiled_contracts___init___ALT_BN128_PAIRING_CHECK_ADDRESS : - IsGlobalAlias globals ethereum.paris.vm.precompiled_contracts.__init__.globals "ALT_BN128_PAIRING_CHECK_ADDRESS". -Axiom ethereum_paris_vm_precompiled_contracts___init___BLAKE2F_ADDRESS : - IsGlobalAlias globals ethereum.paris.vm.precompiled_contracts.__init__.globals "BLAKE2F_ADDRESS". -Axiom ethereum_paris_vm_precompiled_contracts___init___ECRECOVER_ADDRESS : - IsGlobalAlias globals ethereum.paris.vm.precompiled_contracts.__init__.globals "ECRECOVER_ADDRESS". -Axiom ethereum_paris_vm_precompiled_contracts___init___IDENTITY_ADDRESS : - IsGlobalAlias globals ethereum.paris.vm.precompiled_contracts.__init__.globals "IDENTITY_ADDRESS". -Axiom ethereum_paris_vm_precompiled_contracts___init___MODEXP_ADDRESS : - IsGlobalAlias globals ethereum.paris.vm.precompiled_contracts.__init__.globals "MODEXP_ADDRESS". -Axiom ethereum_paris_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : - IsGlobalAlias globals ethereum.paris.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". -Axiom ethereum_paris_vm_precompiled_contracts___init___SHA256_ADDRESS : - IsGlobalAlias globals ethereum.paris.vm.precompiled_contracts.__init__.globals "SHA256_ADDRESS". - -Require ethereum.paris.vm.precompiled_contracts.alt_bn128. -Axiom ethereum_paris_vm_precompiled_contracts_alt_bn128_alt_bn128_add : - IsGlobalAlias globals ethereum.paris.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_add". -Axiom ethereum_paris_vm_precompiled_contracts_alt_bn128_alt_bn128_mul : - IsGlobalAlias globals ethereum.paris.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_mul". -Axiom ethereum_paris_vm_precompiled_contracts_alt_bn128_alt_bn128_pairing_check : - IsGlobalAlias globals ethereum.paris.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_pairing_check". - -Require ethereum.paris.vm.precompiled_contracts.blake2f. -Axiom ethereum_paris_vm_precompiled_contracts_blake2f_blake2f : - IsGlobalAlias globals ethereum.paris.vm.precompiled_contracts.blake2f.globals "blake2f". - -Require ethereum.paris.vm.precompiled_contracts.ecrecover. -Axiom ethereum_paris_vm_precompiled_contracts_ecrecover_ecrecover : - IsGlobalAlias globals ethereum.paris.vm.precompiled_contracts.ecrecover.globals "ecrecover". - -Require ethereum.paris.vm.precompiled_contracts.identity. -Axiom ethereum_paris_vm_precompiled_contracts_identity_identity : - IsGlobalAlias globals ethereum.paris.vm.precompiled_contracts.identity.globals "identity". - -Require ethereum.paris.vm.precompiled_contracts.modexp. -Axiom ethereum_paris_vm_precompiled_contracts_modexp_modexp : - IsGlobalAlias globals ethereum.paris.vm.precompiled_contracts.modexp.globals "modexp". - -Require ethereum.paris.vm.precompiled_contracts.ripemd160. -Axiom ethereum_paris_vm_precompiled_contracts_ripemd160_ripemd160 : - IsGlobalAlias globals ethereum.paris.vm.precompiled_contracts.ripemd160.globals "ripemd160". - -Require ethereum.paris.vm.precompiled_contracts.sha256. -Axiom ethereum_paris_vm_precompiled_contracts_sha256_sha256 : - IsGlobalAlias globals ethereum.paris.vm.precompiled_contracts.sha256.globals "sha256". +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict" ]. + +Axiom ethereum_paris_fork_types_imports : + AreImported globals "ethereum.paris.fork_types" [ "Address" ]. + +Axiom ethereum_paris_vm_precompiled_contracts_imports : + AreImported globals "ethereum.paris.vm.precompiled_contracts" [ "ALT_BN128_ADD_ADDRESS"; "ALT_BN128_MUL_ADDRESS"; "ALT_BN128_PAIRING_CHECK_ADDRESS"; "BLAKE2F_ADDRESS"; "ECRECOVER_ADDRESS"; "IDENTITY_ADDRESS"; "MODEXP_ADDRESS"; "RIPEMD160_ADDRESS"; "SHA256_ADDRESS" ]. + +Axiom ethereum_paris_vm_precompiled_contracts_alt_bn128_imports : + AreImported globals "ethereum.paris.vm.precompiled_contracts.alt_bn128" [ "alt_bn128_add"; "alt_bn128_mul"; "alt_bn128_pairing_check" ]. + +Axiom ethereum_paris_vm_precompiled_contracts_blake2f_imports : + AreImported globals "ethereum.paris.vm.precompiled_contracts.blake2f" [ "blake2f" ]. + +Axiom ethereum_paris_vm_precompiled_contracts_ecrecover_imports : + AreImported globals "ethereum.paris.vm.precompiled_contracts.ecrecover" [ "ecrecover" ]. + +Axiom ethereum_paris_vm_precompiled_contracts_identity_imports : + AreImported globals "ethereum.paris.vm.precompiled_contracts.identity" [ "identity" ]. + +Axiom ethereum_paris_vm_precompiled_contracts_modexp_imports : + AreImported globals "ethereum.paris.vm.precompiled_contracts.modexp" [ "modexp" ]. + +Axiom ethereum_paris_vm_precompiled_contracts_ripemd160_imports : + AreImported globals "ethereum.paris.vm.precompiled_contracts.ripemd160" [ "ripemd160" ]. + +Axiom ethereum_paris_vm_precompiled_contracts_sha256_imports : + AreImported globals "ethereum.paris.vm.precompiled_contracts.sha256" [ "sha256" ]. (* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/modexp.v index 5056a4d..b21b98a 100644 --- a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/modexp.v +++ b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/modexp.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.paris.vm.precompiled_contracts.modexp". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementation of the `MODEXP` precompiled contract. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. -Require ethereum.paris.vm.__init__. -Axiom ethereum_paris_vm___init___Evm : - IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Evm". +Axiom ethereum_paris_vm_imports : + AreImported globals "ethereum.paris.vm" [ "Evm" ]. -Require ethereum.paris.vm.gas. -Axiom ethereum_paris_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "charge_gas". +Axiom ethereum_paris_vm_gas_imports : + AreImported globals "ethereum.paris.vm.gas" [ "charge_gas" ]. -Require ethereum.paris.vm.memory. -Axiom ethereum_paris_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.paris.vm.memory.globals "buffer_read". +Axiom ethereum_paris_vm_memory_imports : + AreImported globals "ethereum.paris.vm.memory" [ "buffer_read" ]. Definition GQUADDIVISOR : Value.t := M.run ltac:(M.monadic ( Constant.int 3 diff --git a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/ripemd160.v index 93fdcfc..8dc4508 100644 --- a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/ripemd160.v +++ b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/ripemd160.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.paris.vm.precompiled_contracts.ripemd160". Definition expr_1 : Value.t := Constant.str " @@ -19,29 +19,20 @@ Implementation of the `RIPEMD160` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_left_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.paris.vm.__init__. -Axiom ethereum_paris_vm___init___Evm : - IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Evm". +Axiom ethereum_paris_vm_imports : + AreImported globals "ethereum.paris.vm" [ "Evm" ]. -Require ethereum.paris.vm.gas. -Axiom ethereum_paris_vm_gas_GAS_RIPEMD160 : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_RIPEMD160". -Axiom ethereum_paris_vm_gas_GAS_RIPEMD160_WORD : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_RIPEMD160_WORD". -Axiom ethereum_paris_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "charge_gas". +Axiom ethereum_paris_vm_gas_imports : + AreImported globals "ethereum.paris.vm.gas" [ "GAS_RIPEMD160"; "GAS_RIPEMD160_WORD"; "charge_gas" ]. Definition ripemd160 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/sha256.v index f6e9c6c..97f82e5 100644 --- a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/sha256.v +++ b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/sha256.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.paris.vm.precompiled_contracts.sha256". Definition expr_1 : Value.t := Constant.str " @@ -19,25 +19,17 @@ Implementation of the `SHA256` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.paris.vm.__init__. -Axiom ethereum_paris_vm___init___Evm : - IsGlobalAlias globals ethereum.paris.vm.__init__.globals "Evm". +Axiom ethereum_paris_vm_imports : + AreImported globals "ethereum.paris.vm" [ "Evm" ]. -Require ethereum.paris.vm.gas. -Axiom ethereum_paris_vm_gas_GAS_SHA256 : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_SHA256". -Axiom ethereum_paris_vm_gas_GAS_SHA256_WORD : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "GAS_SHA256_WORD". -Axiom ethereum_paris_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.paris.vm.gas.globals "charge_gas". +Axiom ethereum_paris_vm_gas_imports : + AreImported globals "ethereum.paris.vm.gas" [ "GAS_SHA256"; "GAS_SHA256_WORD"; "charge_gas" ]. Definition sha256 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/paris/vm/runtime.v b/CoqOfPython/ethereum/paris/vm/runtime.v index ee592a8..4c01cde 100644 --- a/CoqOfPython/ethereum/paris/vm/runtime.v +++ b/CoqOfPython/ethereum/paris/vm/runtime.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.paris.vm.runtime". Definition expr_1 : Value.t := Constant.str " @@ -17,17 +17,14 @@ Introduction Runtime related operations used while executing EVM code. ". -Require typing. -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". +Axiom typing_imports : + AreImported globals "typing" [ "Set" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.paris.vm.instructions.__init__. -Axiom ethereum_paris_vm_instructions___init___Ops : - IsGlobalAlias globals ethereum.paris.vm.instructions.__init__.globals "Ops". +Axiom ethereum_paris_vm_instructions_imports : + AreImported globals "ethereum.paris.vm.instructions" [ "Ops" ]. Definition get_valid_jump_destinations : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -67,75 +64,83 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := ], make_dict [] |) in - While Compare.lt (| - M.get_name (| globals, "pc" |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "code" |) - ], - make_dict [] - |) - |) do -(* At stmt: unsupported node type: Try *) - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "current_opcode" |), - M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) - |), - (* then *) + let _ := + M.while (| + Compare.lt (| + M.get_name (| globals, "pc" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) + |), ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), - make_list [ - M.get_name (| globals, "pc" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( +(* At stmt: unsupported node type: Try *) let _ := (* if *) M.if_then_else (| - BoolOp.and (| - Compare.lt_e (| - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |), - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |) - |), - ltac:(M.monadic ( - Compare.lt_e (| - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH32" |), "value" |) - |) - )) + Compare.eq (| + M.get_name (| globals, "current_opcode" |), + M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) |), (* then *) ltac:(M.monadic ( - let push_data_size := - BinOp.add (| - BinOp.sub (| - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) - |), - Constant.int 1 - |) in - let pc := BinOp.add - M.get_name (| globals, "push_data_size" |) - M.get_name (| globals, "push_data_size" |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), + make_list [ + M.get_name (| globals, "pc" |) + ], + make_dict [] + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.lt_e (| + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |), + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH32" |), "value" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let push_data_size := + BinOp.add (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) + |), + Constant.int 1 + |) in + let pc := BinOp.add + M.get_name (| globals, "push_data_size" |) + M.get_name (| globals, "push_data_size" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ )) |) in + let pc := BinOp.add + Constant.int 1 + Constant.int 1 in M.pure Constant.None_ - )) |) in - let pc := BinOp.add - Constant.int 1 - Constant.int 1 in - EndWhile. + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.get_name (| globals, "valid_jump_destinations" |) |) in diff --git a/CoqOfPython/ethereum/paris/vm/stack.v b/CoqOfPython/ethereum/paris/vm/stack.v index cc70502..d52ab7d 100644 --- a/CoqOfPython/ethereum/paris/vm/stack.v +++ b/CoqOfPython/ethereum/paris/vm/stack.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.paris.vm.stack". Definition expr_1 : Value.t := Constant.str " @@ -17,19 +17,14 @@ Introduction Implementation of the stack operators for the EVM. ". -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". +Axiom typing_imports : + AreImported globals "typing" [ "List" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.paris.vm.exceptions. -Axiom ethereum_paris_vm_exceptions_StackOverflowError : - IsGlobalAlias globals ethereum.paris.vm.exceptions.globals "StackOverflowError". -Axiom ethereum_paris_vm_exceptions_StackUnderflowError : - IsGlobalAlias globals ethereum.paris.vm.exceptions.globals "StackUnderflowError". +Axiom ethereum_paris_vm_exceptions_imports : + AreImported globals "ethereum.paris.vm.exceptions" [ "StackOverflowError"; "StackUnderflowError" ]. Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -63,7 +58,7 @@ Definition pop : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "StackUnderflowError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "StackUnderflowError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -108,7 +103,7 @@ Definition push : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "StackOverflowError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "StackOverflowError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/rlp.v b/CoqOfPython/ethereum/rlp.v index 65abb6f..a99ae1d 100644 --- a/CoqOfPython/ethereum/rlp.v +++ b/CoqOfPython/ethereum/rlp.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.rlp". Definition expr_1 : Value.t := Constant.str " @@ -19,61 +19,23 @@ Introduction Defines the serialization and deserialization format used throughout Ethereum. ". -Require dataclasses. -Axiom dataclasses_astuple : - IsGlobalAlias globals dataclasses.globals "astuple". -Axiom dataclasses_fields : - IsGlobalAlias globals dataclasses.globals "fields". -Axiom dataclasses_is_dataclass : - IsGlobalAlias globals dataclasses.globals "is_dataclass". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "astuple"; "fields"; "is_dataclass" ]. -Require typing. -Axiom typing_Any : - IsGlobalAlias globals typing.globals "Any". -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Sequence : - IsGlobalAlias globals typing.globals "Sequence". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Type_ : - IsGlobalAlias globals typing.globals "Type_". -Axiom typing_TypeVar : - IsGlobalAlias globals typing.globals "TypeVar". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". -Axiom typing_cast : - IsGlobalAlias globals typing.globals "cast". +Axiom typing_imports : + AreImported globals "typing" [ "Any"; "List"; "Sequence"; "Tuple"; "Type"; "TypeVar"; "Union"; "cast" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. -Require ethereum.exceptions. -Axiom ethereum_exceptions_RLPDecodingError : - IsGlobalAlias globals ethereum.exceptions.globals "RLPDecodingError". -Axiom ethereum_exceptions_RLPEncodingError : - IsGlobalAlias globals ethereum.exceptions.globals "RLPEncodingError". +Axiom ethereum_exceptions_imports : + AreImported globals "ethereum.exceptions" [ "RLPDecodingError"; "RLPEncodingError" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Bytes20 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes20". -Axiom ethereum_base_types_FixedBytes : - IsGlobalAlias globals ethereum.base_types.globals "FixedBytes". -Axiom ethereum_base_types_FixedUint : - IsGlobalAlias globals ethereum.base_types.globals "FixedUint". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Bytes"; "Bytes0"; "Bytes20"; "FixedBytes"; "FixedUint"; "Uint" ]. Definition RLP : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Any" |) @@ -279,7 +241,7 @@ Definition encode : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "RLPEncodingError" |), make_list [ M.call (| @@ -352,7 +314,10 @@ Definition encode_bytes : Value.t -> Value.t -> M := |), ltac:(M.monadic ( Compare.lt (| - M.get_subscript (| M.get_name (| globals, "raw_bytes" |), Constant.int 0 |), + M.get_subscript (| + M.get_name (| globals, "raw_bytes" |), + Constant.int 0 + |), Constant.int 128 |) )) @@ -608,7 +573,10 @@ Definition decode : Value.t -> Value.t -> M := (* if *) M.if_then_else (| Compare.lt_e (| - M.get_subscript (| M.get_name (| globals, "encoded_data" |), Constant.int 0 |), + M.get_subscript (| + M.get_name (| globals, "encoded_data" |), + Constant.int 0 + |), Constant.int 191 |), (* then *) @@ -716,7 +684,10 @@ Definition _decode_to : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "type" |), make_list [ - M.get_subscript (| M.get_name (| globals, "Tuple" |), make_tuple [ M.get_name (| globals, "Uint" |); (* At constant: unsupported node type: Constant *) ] |) + M.get_subscript (| + M.get_name (| globals, "Tuple" |), + make_tuple [ M.get_name (| globals, "Uint" |); (* At constant: unsupported node type: Constant *) ] + |) ], make_dict [] |) @@ -751,21 +722,31 @@ Definition _decode_to : Value.t -> Value.t -> M := (* if *) M.if_then_else (| Compare.eq (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "cls" |), "__args__" |), Constant.int 1 |), + M.get_subscript (| + M.get_field (| M.get_name (| globals, "cls" |), "__args__" |), + Constant.int 1 + |), (* At constant: unsupported node type: Constant *) |), (* then *) ltac:(M.monadic ( let args := make_list [] in - For M.get_name (| globals, "raw_item" |) in M.get_name (| globals, "raw_rlp" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "raw_item" |), + M.get_name (| globals, "raw_rlp" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "args" |), "append" |), make_list [ M.call (| M.get_name (| globals, "_decode_to" |), make_list [ - M.get_subscript (| M.get_field (| M.get_name (| globals, "cls" |), "__args__" |), Constant.int 0 |); + M.get_subscript (| + M.get_field (| M.get_name (| globals, "cls" |), "__args__" |), + Constant.int 0 + |); M.get_name (| globals, "raw_item" |) ], make_dict [] @@ -773,7 +754,12 @@ Definition _decode_to : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "tuple" |), @@ -811,15 +797,19 @@ Definition _decode_to : Value.t -> Value.t -> M := ], make_dict [] |) in - For make_tuple [ M.get_name (| globals, "t" |); M.get_name (| globals, "raw_item" |) ] in M.call (| - M.get_name (| globals, "zip" |), - make_list [ - M.get_field (| M.get_name (| globals, "cls" |), "__args__" |); - M.get_name (| globals, "raw_rlp" |) - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "t" |); M.get_name (| globals, "raw_item" |) ], + M.call (| + M.get_name (| globals, "zip" |), + make_list [ + M.get_field (| M.get_name (| globals, "cls" |), "__args__" |); + M.get_name (| globals, "raw_rlp" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "args" |), "append" |), make_list [ M.call (| @@ -833,7 +823,12 @@ Definition _decode_to : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "tuple" |), @@ -853,7 +848,10 @@ Definition _decode_to : Value.t -> Value.t -> M := M.if_then_else (| Compare.eq (| M.get_name (| globals, "cls" |), - M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Bytes0" |); M.get_name (| globals, "Bytes20" |) ] |) + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "Bytes0" |); M.get_name (| globals, "Bytes20" |) ] + |) |), (* then *) ltac:(M.monadic ( @@ -924,7 +922,7 @@ Definition _decode_to : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "RLPDecodingError" |), make_list [ M.call (| @@ -961,7 +959,10 @@ Definition _decode_to : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "type" |), make_list [ - M.get_subscript (| M.get_name (| globals, "List" |), M.get_name (| globals, "Bytes" |) |) + M.get_subscript (| + M.get_name (| globals, "List" |), + M.get_name (| globals, "Bytes" |) + |) ], make_dict [] |) @@ -994,14 +995,21 @@ Definition _decode_to : Value.t -> Value.t -> M := |) in let items := make_list [] in - For M.get_name (| globals, "raw_item" |) in M.get_name (| globals, "raw_rlp" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "raw_item" |), + M.get_name (| globals, "raw_rlp" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "items" |), "append" |), make_list [ M.call (| M.get_name (| globals, "_decode_to" |), make_list [ - M.get_subscript (| M.get_field (| M.get_name (| globals, "cls" |), "__args__" |), Constant.int 0 |); + M.get_subscript (| + M.get_field (| M.get_name (| globals, "cls" |), "__args__" |), + Constant.int 0 + |); M.get_name (| globals, "raw_item" |) ], make_dict [] @@ -1009,7 +1017,12 @@ Definition _decode_to : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.get_name (| globals, "items" |) |) in @@ -1027,7 +1040,13 @@ Definition _decode_to : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "type" |), make_list [ - M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Bytes" |); M.get_subscript (| M.get_name (| globals, "List" |), M.get_name (| globals, "Bytes" |) |) ] |) + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "Bytes" |); M.get_subscript (| + M.get_name (| globals, "List" |), + M.get_name (| globals, "Bytes" |) + |) ] + |) ], make_dict [] |) @@ -1066,7 +1085,7 @@ Definition _decode_to : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "RLPDecodingError" |), make_list [ M.call (| @@ -1107,7 +1126,10 @@ Definition _decode_to : Value.t -> Value.t -> M := (* if *) M.if_then_else (| Compare.eq (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "cls" |), "__args__" |), Constant.int 0 |), + M.get_subscript (| + M.get_field (| M.get_name (| globals, "cls" |), "__args__" |), + Constant.int 0 + |), M.get_name (| globals, "Bytes" |) |), (* then *) @@ -1116,7 +1138,10 @@ Definition _decode_to : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "_decode_to" |), make_list [ - M.get_subscript (| M.get_field (| M.get_name (| globals, "cls" |), "__args__" |), Constant.int 1 |); + M.get_subscript (| + M.get_field (| M.get_name (| globals, "cls" |), "__args__" |), + Constant.int 1 + |); M.get_name (| globals, "raw_rlp" |) ], make_dict [] @@ -1129,7 +1154,10 @@ Definition _decode_to : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "_decode_to" |), make_list [ - M.get_subscript (| M.get_field (| M.get_name (| globals, "cls" |), "__args__" |), Constant.int 0 |); + M.get_subscript (| + M.get_field (| M.get_name (| globals, "cls" |), "__args__" |), + Constant.int 0 + |); M.get_name (| globals, "raw_rlp" |) ], make_dict [] @@ -1197,7 +1225,7 @@ Definition _decode_to : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "TypeError" |), make_list [ M.call (| @@ -1407,21 +1435,25 @@ Definition _decode_to : Value.t -> Value.t -> M := ], make_dict [] |) in - For make_tuple [ M.get_name (| globals, "field" |); M.get_name (| globals, "rlp_item" |) ] in M.call (| - M.get_name (| globals, "zip" |), - make_list [ - M.call (| - M.get_name (| globals, "fields" |), - make_list [ - M.get_name (| globals, "cls" |) - ], - make_dict [] - |); - M.get_name (| globals, "raw_rlp" |) - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "field" |); M.get_name (| globals, "rlp_item" |) ], + M.call (| + M.get_name (| globals, "zip" |), + make_list [ + M.call (| + M.get_name (| globals, "fields" |), + make_list [ + M.get_name (| globals, "cls" |) + ], + make_dict [] + |); + M.get_name (| globals, "raw_rlp" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "args" |), "append" |), make_list [ M.call (| @@ -1435,7 +1467,12 @@ Definition _decode_to : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "cast" |), @@ -1453,7 +1490,7 @@ Definition _decode_to : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "RLPDecodingError" |), make_list [ M.call (| @@ -1519,7 +1556,10 @@ Definition decode_to_bytes : Value.t -> Value.t -> M := |), ltac:(M.monadic ( Compare.lt (| - M.get_subscript (| M.get_name (| globals, "encoded_bytes" |), Constant.int 0 |), + M.get_subscript (| + M.get_name (| globals, "encoded_bytes" |), + Constant.int 0 + |), Constant.int 128 |) )) @@ -1536,14 +1576,20 @@ Definition decode_to_bytes : Value.t -> Value.t -> M := (* if *) M.if_then_else (| Compare.lt_e (| - M.get_subscript (| M.get_name (| globals, "encoded_bytes" |), Constant.int 0 |), + M.get_subscript (| + M.get_name (| globals, "encoded_bytes" |), + Constant.int 0 + |), Constant.int 183 |), (* then *) ltac:(M.monadic ( let len_raw_data := BinOp.sub (| - M.get_subscript (| M.get_name (| globals, "encoded_bytes" |), Constant.int 0 |), + M.get_subscript (| + M.get_name (| globals, "encoded_bytes" |), + Constant.int 0 + |), Constant.int 128 |) in let _ := M.call (| @@ -1564,10 +1610,15 @@ Definition decode_to_bytes : Value.t -> Value.t -> M := make_dict [] |) in let raw_data := - M.get_subscript (| M.get_name (| globals, "encoded_bytes" |), M.slice (| Constant.int 1, BinOp.add (| + M.slice (| + M.get_name (| globals, "encoded_bytes" |), Constant.int 1, - M.get_name (| globals, "len_raw_data" |) - |) |) |) in + BinOp.add (| + Constant.int 1, + M.get_name (| globals, "len_raw_data" |) + |), + Constant.None_ + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1578,7 +1629,10 @@ Definition decode_to_bytes : Value.t -> Value.t -> M := |), ltac:(M.monadic ( Compare.lt (| - M.get_subscript (| M.get_name (| globals, "raw_data" |), Constant.int 0 |), + M.get_subscript (| + M.get_name (| globals, "raw_data" |), + Constant.int 0 + |), Constant.int 128 |) )) @@ -1597,7 +1651,10 @@ Definition decode_to_bytes : Value.t -> Value.t -> M := BinOp.sub (| BinOp.add (| Constant.int 1, - M.get_subscript (| M.get_name (| globals, "encoded_bytes" |), Constant.int 0 |) + M.get_subscript (| + M.get_name (| globals, "encoded_bytes" |), + Constant.int 0 + |) |), Constant.int 183 |) in @@ -1625,7 +1682,10 @@ Definition decode_to_bytes : Value.t -> Value.t -> M := M.get_name (| globals, "ensure" |), make_list [ Compare.not_eq (| - M.get_subscript (| M.get_name (| globals, "encoded_bytes" |), Constant.int 1 |), + M.get_subscript (| + M.get_name (| globals, "encoded_bytes" |), + Constant.int 1 + |), Constant.int 0 |); M.get_name (| globals, "RLPDecodingError" |) @@ -1636,7 +1696,12 @@ Definition decode_to_bytes : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "encoded_bytes" |), M.slice (| Constant.int 1, M.get_name (| globals, "decoded_data_start_idx" |) |) |) + M.slice (| + M.get_name (| globals, "encoded_bytes" |), + Constant.int 1, + M.get_name (| globals, "decoded_data_start_idx" |), + Constant.None_ + |) ], make_dict [] |) in @@ -1677,7 +1742,12 @@ Definition decode_to_bytes : Value.t -> Value.t -> M := make_dict [] |) in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "encoded_bytes" |), M.slice (| M.get_name (| globals, "decoded_data_start_idx" |), M.get_name (| globals, "decoded_data_end_idx" |) |) |) + M.slice (| + M.get_name (| globals, "encoded_bytes" |), + M.get_name (| globals, "decoded_data_start_idx" |), + M.get_name (| globals, "decoded_data_end_idx" |), + Constant.None_ + |) |) in M.pure Constant.None_ )) |) in @@ -1706,14 +1776,20 @@ Definition decode_to_sequence : Value.t -> Value.t -> M := (* if *) M.if_then_else (| Compare.lt_e (| - M.get_subscript (| M.get_name (| globals, "encoded_sequence" |), Constant.int 0 |), + M.get_subscript (| + M.get_name (| globals, "encoded_sequence" |), + Constant.int 0 + |), Constant.int 247 |), (* then *) ltac:(M.monadic ( let len_joined_encodings := BinOp.sub (| - M.get_subscript (| M.get_name (| globals, "encoded_sequence" |), Constant.int 0 |), + M.get_subscript (| + M.get_name (| globals, "encoded_sequence" |), + Constant.int 0 + |), Constant.int 192 |) in let _ := M.call (| @@ -1734,10 +1810,15 @@ Definition decode_to_sequence : Value.t -> Value.t -> M := make_dict [] |) in let joined_encodings := - M.get_subscript (| M.get_name (| globals, "encoded_sequence" |), M.slice (| Constant.int 1, BinOp.add (| + M.slice (| + M.get_name (| globals, "encoded_sequence" |), Constant.int 1, - M.get_name (| globals, "len_joined_encodings" |) - |) |) |) in + BinOp.add (| + Constant.int 1, + M.get_name (| globals, "len_joined_encodings" |) + |), + Constant.None_ + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1745,7 +1826,10 @@ Definition decode_to_sequence : Value.t -> Value.t -> M := BinOp.sub (| BinOp.add (| Constant.int 1, - M.get_subscript (| M.get_name (| globals, "encoded_sequence" |), Constant.int 0 |) + M.get_subscript (| + M.get_name (| globals, "encoded_sequence" |), + Constant.int 0 + |) |), Constant.int 247 |) in @@ -1773,7 +1857,10 @@ Definition decode_to_sequence : Value.t -> Value.t -> M := M.get_name (| globals, "ensure" |), make_list [ Compare.not_eq (| - M.get_subscript (| M.get_name (| globals, "encoded_sequence" |), Constant.int 1 |), + M.get_subscript (| + M.get_name (| globals, "encoded_sequence" |), + Constant.int 1 + |), Constant.int 0 |); M.get_name (| globals, "RLPDecodingError" |) @@ -1784,7 +1871,12 @@ Definition decode_to_sequence : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "encoded_sequence" |), M.slice (| Constant.int 1, M.get_name (| globals, "joined_encodings_start_idx" |) |) |) + M.slice (| + M.get_name (| globals, "encoded_sequence" |), + Constant.int 1, + M.get_name (| globals, "joined_encodings_start_idx" |), + Constant.None_ + |) ], make_dict [] |) in @@ -1825,7 +1917,12 @@ Definition decode_to_sequence : Value.t -> Value.t -> M := make_dict [] |) in let joined_encodings := - M.get_subscript (| M.get_name (| globals, "encoded_sequence" |), M.slice (| M.get_name (| globals, "joined_encodings_start_idx" |), M.get_name (| globals, "joined_encodings_end_idx" |) |) |) in + M.slice (| + M.get_name (| globals, "encoded_sequence" |), + M.get_name (| globals, "joined_encodings_start_idx" |), + M.get_name (| globals, "joined_encodings_end_idx" |), + Constant.None_ + |) in M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1860,25 +1957,33 @@ Definition decode_joined_encodings : Value.t -> Value.t -> M := make_list [] in let item_start_idx := Constant.int 0 in - While Compare.lt (| - M.get_name (| globals, "item_start_idx" |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "joined_encodings" |) - ], - make_dict [] - |) - |) do - let encoded_item_length := - M.call (| - M.get_name (| globals, "decode_item_length" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "joined_encodings" |), M.slice (| M.get_name (| globals, "item_start_idx" |), Constant.None_ |) |) - ], - make_dict [] - |) in - let _ := M.call (| + let _ := + M.while (| + Compare.lt (| + M.get_name (| globals, "item_start_idx" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "joined_encodings" |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + let encoded_item_length := + M.call (| + M.get_name (| globals, "decode_item_length" |), + make_list [ + M.slice (| + M.get_name (| globals, "joined_encodings" |), + M.get_name (| globals, "item_start_idx" |), + Constant.None_, + Constant.None_ + |) + ], + make_dict [] + |) in + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.lt (| @@ -1901,12 +2006,17 @@ Definition decode_joined_encodings : Value.t -> Value.t -> M := ], make_dict [] |) in - let encoded_item := - M.get_subscript (| M.get_name (| globals, "joined_encodings" |), M.slice (| M.get_name (| globals, "item_start_idx" |), BinOp.add (| - M.get_name (| globals, "item_start_idx" |), - M.get_name (| globals, "encoded_item_length" |) - |) |) |) in - let _ := M.call (| + let encoded_item := + M.slice (| + M.get_name (| globals, "joined_encodings" |), + M.get_name (| globals, "item_start_idx" |), + BinOp.add (| + M.get_name (| globals, "item_start_idx" |), + M.get_name (| globals, "encoded_item_length" |) + |), + Constant.None_ + |) in + let _ := M.call (| M.get_field (| M.get_name (| globals, "decoded_sequence" |), "append" |), make_list [ M.call (| @@ -1919,10 +2029,15 @@ Definition decode_joined_encodings : Value.t -> Value.t -> M := ], make_dict [] |) in - let item_start_idx := BinOp.add - M.get_name (| globals, "encoded_item_length" |) - M.get_name (| globals, "encoded_item_length" |) in - EndWhile. + let item_start_idx := BinOp.add + M.get_name (| globals, "encoded_item_length" |) + M.get_name (| globals, "encoded_item_length" |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.get_name (| globals, "decoded_sequence" |) |) in @@ -1971,7 +2086,10 @@ Definition decode_item_length : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "Uint" |), make_list [ - M.get_subscript (| M.get_name (| globals, "encoded_data" |), Constant.int 0 |) + M.get_subscript (| + M.get_name (| globals, "encoded_data" |), + Constant.int 0 + |) ], make_dict [] |) in @@ -2052,7 +2170,10 @@ Definition decode_item_length : Value.t -> Value.t -> M := M.get_name (| globals, "ensure" |), make_list [ Compare.not_eq (| - M.get_subscript (| M.get_name (| globals, "encoded_data" |), Constant.int 1 |), + M.get_subscript (| + M.get_name (| globals, "encoded_data" |), + Constant.int 1 + |), Constant.int 0 |); M.get_name (| globals, "RLPDecodingError" |) @@ -2063,10 +2184,15 @@ Definition decode_item_length : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "encoded_data" |), M.slice (| Constant.int 1, BinOp.add (| + M.slice (| + M.get_name (| globals, "encoded_data" |), Constant.int 1, - M.get_name (| globals, "length_length" |) - |) |) |) + BinOp.add (| + Constant.int 1, + M.get_name (| globals, "length_length" |) + |), + Constant.None_ + |) ], make_dict [] |) in @@ -2125,7 +2251,10 @@ Definition decode_item_length : Value.t -> Value.t -> M := M.get_name (| globals, "ensure" |), make_list [ Compare.not_eq (| - M.get_subscript (| M.get_name (| globals, "encoded_data" |), Constant.int 1 |), + M.get_subscript (| + M.get_name (| globals, "encoded_data" |), + Constant.int 1 + |), Constant.int 0 |); M.get_name (| globals, "RLPDecodingError" |) @@ -2136,10 +2265,15 @@ Definition decode_item_length : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "encoded_data" |), M.slice (| Constant.int 1, BinOp.add (| + M.slice (| + M.get_name (| globals, "encoded_data" |), Constant.int 1, - M.get_name (| globals, "length_length" |) - |) |) |) + BinOp.add (| + Constant.int 1, + M.get_name (| globals, "length_length" |) + |), + Constant.None_ + |) ], make_dict [] |) in diff --git a/CoqOfPython/ethereum/shanghai/__init__.v b/CoqOfPython/ethereum/shanghai/__init__.v index 1e974d9..c966ed2 100644 --- a/CoqOfPython/ethereum/shanghai/__init__.v +++ b/CoqOfPython/ethereum/shanghai/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.shanghai.__init__". Definition expr_1 : Value.t := Constant.str " @@ -9,9 +9,8 @@ push-zero EVM instruction, limits the maximum size of initialization bytecode, and deprecates the self-destruct EVM instruction. ". -Require ethereum.fork_criteria. -Axiom ethereum_fork_criteria_ByTimestamp : - IsGlobalAlias globals ethereum.fork_criteria.globals "ByTimestamp". +Axiom ethereum_fork_criteria_imports : + AreImported globals "ethereum.fork_criteria" [ "ByTimestamp" ]. Definition FORK_CRITERIA : Value.t := M.run ltac:(M.monadic ( M.call (| diff --git a/CoqOfPython/ethereum/shanghai/blocks.v b/CoqOfPython/ethereum/shanghai/blocks.v index 74717c4..5d51a1c 100644 --- a/CoqOfPython/ethereum/shanghai/blocks.v +++ b/CoqOfPython/ethereum/shanghai/blocks.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.shanghai.blocks". Definition expr_1 : Value.t := Constant.str " @@ -14,47 +14,23 @@ history of all state transitions that have happened since the genesis of the chain. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". - -Require ethereum.base_types. -Axiom ethereum_base_types_U64 : - IsGlobalAlias globals ethereum.base_types.globals "U64". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes8 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes8". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". - -Require ethereum.shanghai.fork_types. -Axiom ethereum_shanghai_fork_types_Address : - IsGlobalAlias globals ethereum.shanghai.fork_types.globals "Address". -Axiom ethereum_shanghai_fork_types_Bloom : - IsGlobalAlias globals ethereum.shanghai.fork_types.globals "Bloom". -Axiom ethereum_shanghai_fork_types_Root : - IsGlobalAlias globals ethereum.shanghai.fork_types.globals "Root". - -Require ethereum.shanghai.transactions. -Axiom ethereum_shanghai_transactions_LegacyTransaction : - IsGlobalAlias globals ethereum.shanghai.transactions.globals "LegacyTransaction". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Tuple"; "Union" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U64"; "U256"; "Bytes"; "Bytes8"; "Bytes32"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. + +Axiom ethereum_shanghai_fork_types_imports : + AreImported globals "ethereum.shanghai.fork_types" [ "Address"; "Bloom"; "Root" ]. + +Axiom ethereum_shanghai_transactions_imports : + AreImported globals "ethereum.shanghai.transactions" [ "LegacyTransaction" ]. Definition Withdrawal : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/shanghai/bloom.v b/CoqOfPython/ethereum/shanghai/bloom.v index 32d85e3..7395a1d 100644 --- a/CoqOfPython/ethereum/shanghai/bloom.v +++ b/CoqOfPython/ethereum/shanghai/bloom.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.shanghai.bloom". Definition expr_1 : Value.t := Constant.str " @@ -21,25 +21,20 @@ for efficient searching of logs by address and/or topic, by rapidly eliminating blocks and receipts from their search. ". -Require typing. -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_imports : + AreImported globals "typing" [ "Tuple" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. -Require ethereum.shanghai.blocks. -Axiom ethereum_shanghai_blocks_Log : - IsGlobalAlias globals ethereum.shanghai.blocks.globals "Log". +Axiom ethereum_shanghai_blocks_imports : + AreImported globals "ethereum.shanghai.blocks" [ "Log" ]. -Require ethereum.shanghai.fork_types. -Axiom ethereum_shanghai_fork_types_Bloom : - IsGlobalAlias globals ethereum.shanghai.fork_types.globals "Bloom". +Axiom ethereum_shanghai_fork_types_imports : + AreImported globals "ethereum.shanghai.fork_types" [ "Bloom" ]. Definition add_to_bloom : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -66,50 +61,70 @@ Definition add_to_bloom : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "idx" |) in make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ] do - let bit_to_set := - BinOp.bit_and (| - M.call (| - M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "hash" |), M.slice (| M.get_name (| globals, "idx" |), BinOp.add (| - M.get_name (| globals, "idx" |), - Constant.int 2 - |) |) |) - ], - make_dict [] - |), - Constant.int 2047 - |) in - let bit_index := - BinOp.sub (| - Constant.int 2047, - M.get_name (| globals, "bit_to_set" |) - |) in - let byte_index := - BinOp.floor_div (| - M.get_name (| globals, "bit_index" |), - Constant.int 8 - |) in - let bit_value := - BinOp.l_shift (| - Constant.int 1, - BinOp.sub (| - Constant.int 7, - BinOp.mod_ (| + let _ := + M.for_ (| + M.get_name (| globals, "idx" |), + make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ], + ltac:(M.monadic ( + let bit_to_set := + BinOp.bit_and (| + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.slice (| + M.get_name (| globals, "hash" |), + M.get_name (| globals, "idx" |), + BinOp.add (| + M.get_name (| globals, "idx" |), + Constant.int 2 + |), + Constant.None_ + |) + ], + make_dict [] + |), + Constant.int 2047 + |) in + let bit_index := + BinOp.sub (| + Constant.int 2047, + M.get_name (| globals, "bit_to_set" |) + |) in + let byte_index := + BinOp.floor_div (| M.get_name (| globals, "bit_index" |), Constant.int 8 + |) in + let bit_value := + BinOp.l_shift (| + Constant.int 1, + BinOp.sub (| + Constant.int 7, + BinOp.mod_ (| + M.get_name (| globals, "bit_index" |), + Constant.int 8 + |) + |) + |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "bloom" |), + M.get_name (| globals, "byte_index" |) + |), + BinOp.bit_or (| + M.get_subscript (| + M.get_name (| globals, "bloom" |), + M.get_name (| globals, "byte_index" |) + |), + M.get_name (| globals, "bit_value" |) |) - |) - |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), - BinOp.bit_or (| - M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), - M.get_name (| globals, "bit_value" |) - |) - |) in - EndFor. + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_)). Definition logs_bloom : Value.t -> Value.t -> M := @@ -132,8 +147,12 @@ Definition logs_bloom : Value.t -> Value.t -> M := the caller address and the log topics. " in (* At stmt: unsupported node type: AnnAssign *) - For M.get_name (| globals, "log" |) in M.get_name (| globals, "logs" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "log" |), + M.get_name (| globals, "logs" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "add_to_bloom" |), make_list [ M.get_name (| globals, "bloom" |); @@ -141,8 +160,12 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "topic" |) in M.get_field (| M.get_name (| globals, "log" |), "topics" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "topic" |), + M.get_field (| M.get_name (| globals, "log" |), "topics" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "add_to_bloom" |), make_list [ M.get_name (| globals, "bloom" |); @@ -150,8 +173,18 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Bloom" |), diff --git a/CoqOfPython/ethereum/shanghai/fork.v b/CoqOfPython/ethereum/shanghai/fork.v index 35598b8..2e2552a 100644 --- a/CoqOfPython/ethereum/shanghai/fork.v +++ b/CoqOfPython/ethereum/shanghai/fork.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.shanghai.fork". Definition expr_1 : Value.t := Constant.str " @@ -17,153 +17,62 @@ Introduction Entry point for the Ethereum specification. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". - -Require ethereum.base_types. -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". - -Require ethereum.crypto.elliptic_curve. -Axiom ethereum_crypto_elliptic_curve_SECP256K1N : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". -Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.exceptions. -Axiom ethereum_exceptions_InvalidBlock : - IsGlobalAlias globals ethereum.exceptions.globals "InvalidBlock". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U64 : - IsGlobalAlias globals ethereum.base_types.globals "U64". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.shanghai.__init__. -Axiom ethereum_shanghai___init___vm : - IsGlobalAlias globals ethereum.shanghai.__init__.globals "vm". - -Require ethereum.shanghai.blocks. -Axiom ethereum_shanghai_blocks_Block : - IsGlobalAlias globals ethereum.shanghai.blocks.globals "Block". -Axiom ethereum_shanghai_blocks_Header : - IsGlobalAlias globals ethereum.shanghai.blocks.globals "Header". -Axiom ethereum_shanghai_blocks_Log : - IsGlobalAlias globals ethereum.shanghai.blocks.globals "Log". -Axiom ethereum_shanghai_blocks_Receipt : - IsGlobalAlias globals ethereum.shanghai.blocks.globals "Receipt". -Axiom ethereum_shanghai_blocks_Withdrawal : - IsGlobalAlias globals ethereum.shanghai.blocks.globals "Withdrawal". - -Require ethereum.shanghai.bloom. -Axiom ethereum_shanghai_bloom_logs_bloom : - IsGlobalAlias globals ethereum.shanghai.bloom.globals "logs_bloom". - -Require ethereum.shanghai.fork_types. -Axiom ethereum_shanghai_fork_types_Address : - IsGlobalAlias globals ethereum.shanghai.fork_types.globals "Address". -Axiom ethereum_shanghai_fork_types_Bloom : - IsGlobalAlias globals ethereum.shanghai.fork_types.globals "Bloom". -Axiom ethereum_shanghai_fork_types_Root : - IsGlobalAlias globals ethereum.shanghai.fork_types.globals "Root". - -Require ethereum.shanghai.state. -Axiom ethereum_shanghai_state_State : - IsGlobalAlias globals ethereum.shanghai.state.globals "State". -Axiom ethereum_shanghai_state_account_exists_and_is_empty : - IsGlobalAlias globals ethereum.shanghai.state.globals "account_exists_and_is_empty". -Axiom ethereum_shanghai_state_destroy_account : - IsGlobalAlias globals ethereum.shanghai.state.globals "destroy_account". -Axiom ethereum_shanghai_state_get_account : - IsGlobalAlias globals ethereum.shanghai.state.globals "get_account". -Axiom ethereum_shanghai_state_increment_nonce : - IsGlobalAlias globals ethereum.shanghai.state.globals "increment_nonce". -Axiom ethereum_shanghai_state_process_withdrawal : - IsGlobalAlias globals ethereum.shanghai.state.globals "process_withdrawal". -Axiom ethereum_shanghai_state_set_account_balance : - IsGlobalAlias globals ethereum.shanghai.state.globals "set_account_balance". -Axiom ethereum_shanghai_state_state_root : - IsGlobalAlias globals ethereum.shanghai.state.globals "state_root". - -Require ethereum.shanghai.transactions. -Axiom ethereum_shanghai_transactions_TX_ACCESS_LIST_ADDRESS_COST : - IsGlobalAlias globals ethereum.shanghai.transactions.globals "TX_ACCESS_LIST_ADDRESS_COST". -Axiom ethereum_shanghai_transactions_TX_ACCESS_LIST_STORAGE_KEY_COST : - IsGlobalAlias globals ethereum.shanghai.transactions.globals "TX_ACCESS_LIST_STORAGE_KEY_COST". -Axiom ethereum_shanghai_transactions_TX_BASE_COST : - IsGlobalAlias globals ethereum.shanghai.transactions.globals "TX_BASE_COST". -Axiom ethereum_shanghai_transactions_TX_CREATE_COST : - IsGlobalAlias globals ethereum.shanghai.transactions.globals "TX_CREATE_COST". -Axiom ethereum_shanghai_transactions_TX_DATA_COST_PER_NON_ZERO : - IsGlobalAlias globals ethereum.shanghai.transactions.globals "TX_DATA_COST_PER_NON_ZERO". -Axiom ethereum_shanghai_transactions_TX_DATA_COST_PER_ZERO : - IsGlobalAlias globals ethereum.shanghai.transactions.globals "TX_DATA_COST_PER_ZERO". -Axiom ethereum_shanghai_transactions_AccessListTransaction : - IsGlobalAlias globals ethereum.shanghai.transactions.globals "AccessListTransaction". -Axiom ethereum_shanghai_transactions_FeeMarketTransaction : - IsGlobalAlias globals ethereum.shanghai.transactions.globals "FeeMarketTransaction". -Axiom ethereum_shanghai_transactions_LegacyTransaction : - IsGlobalAlias globals ethereum.shanghai.transactions.globals "LegacyTransaction". -Axiom ethereum_shanghai_transactions_Transaction : - IsGlobalAlias globals ethereum.shanghai.transactions.globals "Transaction". -Axiom ethereum_shanghai_transactions_decode_transaction : - IsGlobalAlias globals ethereum.shanghai.transactions.globals "decode_transaction". -Axiom ethereum_shanghai_transactions_encode_transaction : - IsGlobalAlias globals ethereum.shanghai.transactions.globals "encode_transaction". - -Require ethereum.shanghai.trie. -Axiom ethereum_shanghai_trie_Trie : - IsGlobalAlias globals ethereum.shanghai.trie.globals "Trie". -Axiom ethereum_shanghai_trie_root : - IsGlobalAlias globals ethereum.shanghai.trie.globals "root". -Axiom ethereum_shanghai_trie_trie_set : - IsGlobalAlias globals ethereum.shanghai.trie.globals "trie_set". - -Require ethereum.shanghai.utils.message. -Axiom ethereum_shanghai_utils_message_prepare_message : - IsGlobalAlias globals ethereum.shanghai.utils.message.globals "prepare_message". - -Require ethereum.shanghai.vm.gas. -Axiom ethereum_shanghai_vm_gas_init_code_cost : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "init_code_cost". - -Require ethereum.shanghai.vm.interpreter. -Axiom ethereum_shanghai_vm_interpreter_MAX_CODE_SIZE : - IsGlobalAlias globals ethereum.shanghai.vm.interpreter.globals "MAX_CODE_SIZE". -Axiom ethereum_shanghai_vm_interpreter_process_message_call : - IsGlobalAlias globals ethereum.shanghai.vm.interpreter.globals "process_message_call". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Optional"; "Tuple"; "Union" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Bytes0"; "Bytes32" ]. + +Axiom ethereum_crypto_elliptic_curve_imports : + AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. + +Axiom ethereum_exceptions_imports : + AreImported globals "ethereum.exceptions" [ "InvalidBlock" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U64"; "U256"; "Bytes"; "Uint" ]. + +Axiom ethereum_shanghai_imports : + AreImported globals "ethereum.shanghai" [ "vm" ]. + +Axiom ethereum_shanghai_blocks_imports : + AreImported globals "ethereum.shanghai.blocks" [ "Block"; "Header"; "Log"; "Receipt"; "Withdrawal" ]. + +Axiom ethereum_shanghai_bloom_imports : + AreImported globals "ethereum.shanghai.bloom" [ "logs_bloom" ]. + +Axiom ethereum_shanghai_fork_types_imports : + AreImported globals "ethereum.shanghai.fork_types" [ "Address"; "Bloom"; "Root" ]. + +Axiom ethereum_shanghai_state_imports : + AreImported globals "ethereum.shanghai.state" [ "State"; "account_exists_and_is_empty"; "destroy_account"; "get_account"; "increment_nonce"; "process_withdrawal"; "set_account_balance"; "state_root" ]. + +Axiom ethereum_shanghai_transactions_imports : + AreImported globals "ethereum.shanghai.transactions" [ "TX_ACCESS_LIST_ADDRESS_COST"; "TX_ACCESS_LIST_STORAGE_KEY_COST"; "TX_BASE_COST"; "TX_CREATE_COST"; "TX_DATA_COST_PER_NON_ZERO"; "TX_DATA_COST_PER_ZERO"; "AccessListTransaction"; "FeeMarketTransaction"; "LegacyTransaction"; "Transaction"; "decode_transaction"; "encode_transaction" ]. + +Axiom ethereum_shanghai_trie_imports : + AreImported globals "ethereum.shanghai.trie" [ "Trie"; "root"; "trie_set" ]. + +Axiom ethereum_shanghai_utils_message_imports : + AreImported globals "ethereum.shanghai.utils.message" [ "prepare_message" ]. + +Axiom ethereum_shanghai_vm_gas_imports : + AreImported globals "ethereum.shanghai.vm.gas" [ "init_code_cost" ]. + +Axiom ethereum_shanghai_vm_interpreter_imports : + AreImported globals "ethereum.shanghai.vm.interpreter" [ "MAX_CODE_SIZE"; "process_message_call" ]. Definition BASE_FEE_MAX_CHANGE_DENOMINATOR : Value.t := M.run ltac:(M.monadic ( Constant.int 8 @@ -256,7 +165,12 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := Hashes of the recent 256 blocks in order of increasing block number. " in let recent_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) in + M.slice (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| Constant.int 255 |), + Constant.None_, + Constant.None_ + |) in let _ := (* if *) M.if_then_else (| @@ -282,17 +196,26 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := )) |) in let recent_block_hashes := make_list [] in - For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_blocks" |) do - let prev_block_hash := - M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "block" |), + M.get_name (| globals, "recent_blocks" |), + ltac:(M.monadic ( + let prev_block_hash := + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in + let _ := M.call (| M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), make_list [ M.get_name (| globals, "prev_block_hash" |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let most_recent_block_hash := M.call (| M.get_name (| globals, "keccak256" |), @@ -300,7 +223,10 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), make_list [ - M.get_field (| M.get_subscript (| M.get_name (| globals, "recent_blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) + M.get_field (| M.get_subscript (| + M.get_name (| globals, "recent_blocks" |), + UnOp.sub (| Constant.int 1 |) + |), "header" |) ], make_dict [] |) @@ -344,7 +270,10 @@ Definition state_transition : Value.t -> Value.t -> M := Block to apply to `chain`. " in let parent_header := - M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) in + M.get_field (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| Constant.int 1 |) + |), "header" |) in let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ @@ -478,7 +407,12 @@ Definition state_transition : Value.t -> Value.t -> M := ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) + M.slice (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| Constant.int 255 |), + Constant.None_, + Constant.None_ + |) |) in M.pure Constant.None_ (* else *) @@ -1063,21 +997,25 @@ Definition apply_body : Value.t -> Value.t -> M := (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) - For make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "tx" |) ] in M.call (| - M.get_name (| globals, "enumerate" |), - make_list [ - M.call (| - M.get_name (| globals, "map" |), - make_list [ - M.get_name (| globals, "decode_transaction" |); - M.get_name (| globals, "transactions" |) - ], - make_dict [] - |) - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "tx" |) ], + M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.call (| + M.get_name (| globals, "map" |), + make_list [ + M.get_name (| globals, "decode_transaction" |); + M.get_name (| globals, "transactions" |) + ], + make_dict [] + |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ M.get_name (| globals, "transactions_trie" |); @@ -1104,54 +1042,54 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.assign (| - make_tuple [ M.get_name (| globals, "sender_address" |); M.get_name (| globals, "effective_gas_price" |) ], - M.call (| - M.get_name (| globals, "check_transaction" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "base_fee_per_gas" |); - M.get_name (| globals, "gas_available" |); - M.get_name (| globals, "chain_id" |) - ], - make_dict [] - |) - |) in - let env := - M.call (| - M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), - make_list [], - make_dict [] - |) in - let _ := M.assign (| - make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |); M.get_name (| globals, "error" |) ], - M.call (| - M.get_name (| globals, "process_transaction" |), - make_list [ - M.get_name (| globals, "env" |); - M.get_name (| globals, "tx" |) - ], - make_dict [] - |) - |) in - let gas_available := BinOp.sub - M.get_name (| globals, "gas_used" |) - M.get_name (| globals, "gas_used" |) in - let receipt := - M.call (| - M.get_name (| globals, "make_receipt" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "error" |); - BinOp.sub (| - M.get_name (| globals, "block_gas_limit" |), - M.get_name (| globals, "gas_available" |) - |); - M.get_name (| globals, "logs" |) - ], - make_dict [] - |) in - let _ := M.call (| + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "sender_address" |); M.get_name (| globals, "effective_gas_price" |) ], + M.call (| + M.get_name (| globals, "check_transaction" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "base_fee_per_gas" |); + M.get_name (| globals, "gas_available" |); + M.get_name (| globals, "chain_id" |) + ], + make_dict [] + |) + |) in + let env := + M.call (| + M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |); M.get_name (| globals, "error" |) ], + M.call (| + M.get_name (| globals, "process_transaction" |), + make_list [ + M.get_name (| globals, "env" |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) in + let gas_available := BinOp.sub + M.get_name (| globals, "gas_used" |) + M.get_name (| globals, "gas_used" |) in + let receipt := + M.call (| + M.get_name (| globals, "make_receipt" |), + make_list [ + M.get_name (| globals, "tx" |); + M.get_name (| globals, "error" |); + BinOp.sub (| + M.get_name (| globals, "block_gas_limit" |), + M.get_name (| globals, "gas_available" |) + |); + M.get_name (| globals, "logs" |) + ], + make_dict [] + |) in + let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ M.get_name (| globals, "receipts_trie" |); @@ -1172,10 +1110,15 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_logs := BinOp.add - M.get_name (| globals, "logs" |) - M.get_name (| globals, "logs" |) in - EndFor. + let block_logs := BinOp.add + M.get_name (| globals, "logs" |) + M.get_name (| globals, "logs" |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let block_gas_used := BinOp.sub (| M.get_name (| globals, "block_gas_limit" |), @@ -1189,14 +1132,18 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - For make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "wd" |) ] in M.call (| - M.get_name (| globals, "enumerate" |), - make_list [ - M.get_name (| globals, "withdrawals" |) - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "wd" |) ], + M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "withdrawals" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ M.get_name (| globals, "withdrawals_trie" |); @@ -1223,7 +1170,7 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "process_withdrawal" |), make_list [ M.get_name (| globals, "state" |); @@ -1231,20 +1178,20 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_name (| globals, "state" |); - M.get_field (| M.get_name (| globals, "wd" |), "address" |) - ], - make_dict [] - |), - (* then *) - ltac:(M.monadic ( - let _ := M.call (| + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_name (| globals, "state" |); + M.get_field (| M.get_name (| globals, "wd" |), "address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "destroy_account" |), make_list [ M.get_name (| globals, "state" |); @@ -1252,12 +1199,17 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ApplyBodyOutput" |), @@ -1490,24 +1442,42 @@ Definition process_transaction : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - For make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "keys" |) ] in M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) do - let _ := M.call (| + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "keys" |) ], + M.get_field (| M.get_name (| globals, "tx" |), "access_list" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "preaccessed_addresses" |), "add" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] |) in - For M.get_name (| globals, "key" |) in M.get_name (| globals, "keys" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "keys" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "preaccessed_storage_keys" |), "add" |), make_list [ make_tuple [ M.get_name (| globals, "address" |); M.get_name (| globals, "key" |) ] ], make_dict [] |) in - EndFor. - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1663,8 +1633,12 @@ Definition process_transaction : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "accounts_to_delete" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "output" |), "accounts_to_delete" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "destroy_account" |), make_list [ M.get_field (| M.get_name (| globals, "env" |), "state" |); @@ -1672,22 +1646,31 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. - For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "touched_accounts" |) do - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), - (* then *) + M.pure Constant.None_ + )), ltac:(M.monadic ( - let _ := M.call (| + M.pure Constant.None_ + )) + |) in + let _ := + M.for_ (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "output" |), "touched_accounts" |), + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "destroy_account" |), make_list [ M.get_field (| M.get_name (| globals, "env" |), "state" |); @@ -1695,12 +1678,17 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := M.return_ (| make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |); M.get_field (| M.get_name (| globals, "output" |), "error" |) ] |) in @@ -1851,28 +1839,37 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := " in let data_cost := Constant.int 0 in - For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "byte" |), - Constant.int 0 - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "byte" |), + M.get_field (| M.get_name (| globals, "tx" |), "data" |), ltac:(M.monadic ( - let data_cost := BinOp.add - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "byte" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let data_cost := BinOp.add - M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := (* if *) M.if_then_else (| @@ -1939,12 +1936,16 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - For make_tuple [ M.get_name (| globals, "_address" |); M.get_name (| globals, "keys" |) ] in M.get_field (| M.get_name (| globals, "tx" |), "access_list" |) do - let access_list_cost := BinOp.add - M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) - M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) in - let access_list_cost := BinOp.add - BinOp.mult (| + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "_address" |); M.get_name (| globals, "keys" |) ], + M.get_field (| M.get_name (| globals, "tx" |), "access_list" |), + ltac:(M.monadic ( + let access_list_cost := BinOp.add + M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) + M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) in + let access_list_cost := BinOp.add + BinOp.mult (| M.call (| M.get_name (| globals, "len" |), make_list [ @@ -1954,7 +1955,7 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) |) - BinOp.mult (| + BinOp.mult (| M.call (| M.get_name (| globals, "len" |), make_list [ @@ -1964,7 +1965,12 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -2253,13 +2259,18 @@ Definition recover_sender : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "Address" |), make_list [ - M.get_subscript (| M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "public_key" |) - ], - make_dict [] - |), M.slice (| Constant.int 12, Constant.int 32 |) |) + M.slice (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), + Constant.int 12, + Constant.int 32, + Constant.None_ + |) ], make_dict [] |) diff --git a/CoqOfPython/ethereum/shanghai/fork_types.v b/CoqOfPython/ethereum/shanghai/fork_types.v index cc8e4a1..0f4ef00 100644 --- a/CoqOfPython/ethereum/shanghai/fork_types.v +++ b/CoqOfPython/ethereum/shanghai/fork_types.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.shanghai.fork_types". Definition expr_1 : Value.t := Constant.str " @@ -17,33 +17,17 @@ Introduction Types re-used throughout the specification, which are specific to Ethereum. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes20 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes20". -Axiom ethereum_base_types_Bytes256 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes20"; "Bytes256"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) diff --git a/CoqOfPython/ethereum/shanghai/state.v b/CoqOfPython/ethereum/shanghai/state.v index 2feb225..8434eb0 100644 --- a/CoqOfPython/ethereum/shanghai/state.v +++ b/CoqOfPython/ethereum/shanghai/state.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.shanghai.state". Definition expr_1 : Value.t := Constant.str " @@ -22,67 +22,26 @@ There is a distinction between an account that does not exist and `EMPTY_ACCOUNT`. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". -Axiom dataclasses_field : - IsGlobalAlias globals dataclasses.globals "field". - -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_modify : - IsGlobalAlias globals ethereum.base_types.globals "modify". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.shanghai.blocks. -Axiom ethereum_shanghai_blocks_Withdrawal : - IsGlobalAlias globals ethereum.shanghai.blocks.globals "Withdrawal". - -Require ethereum.shanghai.fork_types. -Axiom ethereum_shanghai_fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals ethereum.shanghai.fork_types.globals "EMPTY_ACCOUNT". -Axiom ethereum_shanghai_fork_types_Account : - IsGlobalAlias globals ethereum.shanghai.fork_types.globals "Account". -Axiom ethereum_shanghai_fork_types_Address : - IsGlobalAlias globals ethereum.shanghai.fork_types.globals "Address". -Axiom ethereum_shanghai_fork_types_Root : - IsGlobalAlias globals ethereum.shanghai.fork_types.globals "Root". - -Require ethereum.shanghai.trie. -Axiom ethereum_shanghai_trie_EMPTY_TRIE_ROOT : - IsGlobalAlias globals ethereum.shanghai.trie.globals "EMPTY_TRIE_ROOT". -Axiom ethereum_shanghai_trie_Trie : - IsGlobalAlias globals ethereum.shanghai.trie.globals "Trie". -Axiom ethereum_shanghai_trie_copy_trie : - IsGlobalAlias globals ethereum.shanghai.trie.globals "copy_trie". -Axiom ethereum_shanghai_trie_root : - IsGlobalAlias globals ethereum.shanghai.trie.globals "root". -Axiom ethereum_shanghai_trie_trie_get : - IsGlobalAlias globals ethereum.shanghai.trie.globals "trie_get". -Axiom ethereum_shanghai_trie_trie_set : - IsGlobalAlias globals ethereum.shanghai.trie.globals "trie_set". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass"; "field" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict"; "List"; "Optional"; "Set"; "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "modify" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_shanghai_blocks_imports : + AreImported globals "ethereum.shanghai.blocks" [ "Withdrawal" ]. + +Axiom ethereum_shanghai_fork_types_imports : + AreImported globals "ethereum.shanghai.fork_types" [ "EMPTY_ACCOUNT"; "Account"; "Address"; "Root" ]. + +Axiom ethereum_shanghai_trie_imports : + AreImported globals "ethereum.shanghai.trie" [ "EMPTY_TRIE_ROOT"; "Trie"; "copy_trie"; "root"; "trie_get"; "trie_set" ]. Definition State : Value.t := builtins.make_klass @@ -377,13 +336,16 @@ Definition destroy_storage : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -546,7 +508,10 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), + M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |), M.get_name (| globals, "trie" |) |) in M.pure Constant.None_ @@ -572,7 +537,10 @@ Definition set_storage : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -602,7 +570,7 @@ Definition storage_root : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), @@ -612,7 +580,10 @@ Definition storage_root : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "root" |), make_list [ - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) + M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |) ], make_dict [] |) @@ -1162,7 +1133,7 @@ Definition get_storage_original : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_created_accounts" |) |), @@ -1184,7 +1155,10 @@ Definition get_storage_original : Value.t -> Value.t -> M := )) |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "_" |); M.get_name (| globals, "original_trie" |) ], - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), Constant.int 0 |) + M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_snapshots" |), + Constant.int 0 + |) |) in let original_account_trie := M.call (| diff --git a/CoqOfPython/ethereum/shanghai/transactions.v b/CoqOfPython/ethereum/shanghai/transactions.v index 5dda66e..6e939bf 100644 --- a/CoqOfPython/ethereum/shanghai/transactions.v +++ b/CoqOfPython/ethereum/shanghai/transactions.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.shanghai.transactions". Definition expr_1 : Value.t := Constant.str " @@ -9,43 +9,23 @@ submitted to be executed. If Ethereum is viewed as a state machine, transactions are the events that move between states. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. -Require typing. -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". +Axiom typing_imports : + AreImported globals "typing" [ "Tuple"; "Union" ]. -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U64 : - IsGlobalAlias globals ethereum.base_types.globals "U64". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U64"; "U256"; "Bytes"; "Bytes0"; "Bytes32"; "Uint"; "slotted_freezable" ]. -Require ethereum.exceptions. -Axiom ethereum_exceptions_InvalidBlock : - IsGlobalAlias globals ethereum.exceptions.globals "InvalidBlock". +Axiom ethereum_exceptions_imports : + AreImported globals "ethereum.exceptions" [ "InvalidBlock" ]. -Require ethereum.shanghai.fork_types. -Axiom ethereum_shanghai_fork_types_Address : - IsGlobalAlias globals ethereum.shanghai.fork_types.globals "Address". +Axiom ethereum_shanghai_fork_types_imports : + AreImported globals "ethereum.shanghai.fork_types" [ "Address" ]. Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( Constant.int 21000 @@ -102,7 +82,10 @@ Definition FeeMarketTransaction : Value.t := ]. Definition Transaction : Value.t := M.run ltac:(M.monadic ( - M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "AccessListTransaction" |); M.get_name (| globals, "FeeMarketTransaction" |) ] |) + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "AccessListTransaction" |); M.get_name (| globals, "FeeMarketTransaction" |) ] + |) )). Definition encode_transaction : Value.t -> Value.t -> M := @@ -186,7 +169,7 @@ Definition encode_transaction : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "Exception" |), make_list [ Constant.str "(* At expr: unsupported node type: JoinedStr *)" @@ -224,7 +207,10 @@ Definition decode_transaction : Value.t -> Value.t -> M := (* if *) M.if_then_else (| Compare.eq (| - M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), + M.get_subscript (| + M.get_name (| globals, "tx" |), + Constant.int 0 + |), Constant.int 1 |), (* then *) @@ -234,7 +220,12 @@ Definition decode_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), make_list [ M.get_name (| globals, "AccessListTransaction" |); - M.get_subscript (| M.get_name (| globals, "tx" |), M.slice (| Constant.int 1, Constant.None_ |) |) + M.slice (| + M.get_name (| globals, "tx" |), + Constant.int 1, + Constant.None_, + Constant.None_ + |) ], make_dict [] |) @@ -246,7 +237,10 @@ Definition decode_transaction : Value.t -> Value.t -> M := (* if *) M.if_then_else (| Compare.eq (| - M.get_subscript (| M.get_name (| globals, "tx" |), Constant.int 0 |), + M.get_subscript (| + M.get_name (| globals, "tx" |), + Constant.int 0 + |), Constant.int 2 |), (* then *) @@ -256,7 +250,12 @@ Definition decode_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "rlp" |), "decode_to" |), make_list [ M.get_name (| globals, "FeeMarketTransaction" |); - M.get_subscript (| M.get_name (| globals, "tx" |), M.slice (| Constant.int 1, Constant.None_ |) |) + M.slice (| + M.get_name (| globals, "tx" |), + Constant.int 1, + Constant.None_, + Constant.None_ + |) ], make_dict [] |) @@ -264,7 +263,7 @@ Definition decode_transaction : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidBlock" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "InvalidBlock" |)) |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/shanghai/trie.v b/CoqOfPython/ethereum/shanghai/trie.v index 506e584..2983dcf 100644 --- a/CoqOfPython/ethereum/shanghai/trie.v +++ b/CoqOfPython/ethereum/shanghai/trie.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.shanghai.trie". Definition expr_1 : Value.t := Constant.str " @@ -20,85 +20,38 @@ The state trie is the structure responsible for storing (* At top_level_stmt: unsupported node type: Import *) -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". -Axiom dataclasses_field : - IsGlobalAlias globals dataclasses.globals "field". - -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". -Axiom typing_Generic : - IsGlobalAlias globals typing.globals "Generic". -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Mapping : - IsGlobalAlias globals typing.globals "Mapping". -Axiom typing_MutableMapping : - IsGlobalAlias globals typing.globals "MutableMapping". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Sequence : - IsGlobalAlias globals typing.globals "Sequence". -Axiom typing_TypeVar : - IsGlobalAlias globals typing.globals "TypeVar". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". -Axiom typing_cast : - IsGlobalAlias globals typing.globals "cast". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.paris.__init__. -Axiom ethereum_paris___init___trie : - IsGlobalAlias globals ethereum.paris.__init__.globals "trie". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.utils.hexadecimal. -Axiom ethereum_utils_hexadecimal_hex_to_bytes : - IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.shanghai.blocks. -Axiom ethereum_shanghai_blocks_Receipt : - IsGlobalAlias globals ethereum.shanghai.blocks.globals "Receipt". -Axiom ethereum_shanghai_blocks_Withdrawal : - IsGlobalAlias globals ethereum.shanghai.blocks.globals "Withdrawal". - -Require ethereum.shanghai.fork_types. -Axiom ethereum_shanghai_fork_types_Account : - IsGlobalAlias globals ethereum.shanghai.fork_types.globals "Account". -Axiom ethereum_shanghai_fork_types_Address : - IsGlobalAlias globals ethereum.shanghai.fork_types.globals "Address". -Axiom ethereum_shanghai_fork_types_Root : - IsGlobalAlias globals ethereum.shanghai.fork_types.globals "Root". -Axiom ethereum_shanghai_fork_types_encode_account : - IsGlobalAlias globals ethereum.shanghai.fork_types.globals "encode_account". - -Require ethereum.shanghai.transactions. -Axiom ethereum_shanghai_transactions_LegacyTransaction : - IsGlobalAlias globals ethereum.shanghai.transactions.globals "LegacyTransaction". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass"; "field" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict"; "Generic"; "List"; "Mapping"; "MutableMapping"; "Optional"; "Sequence"; "TypeVar"; "Union"; "cast" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. + +Axiom ethereum_paris_imports : + AreImported globals "ethereum.paris" [ "trie" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_utils_hexadecimal_imports : + AreImported globals "ethereum.utils.hexadecimal" [ "hex_to_bytes" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_shanghai_blocks_imports : + AreImported globals "ethereum.shanghai.blocks" [ "Receipt"; "Withdrawal" ]. + +Axiom ethereum_shanghai_fork_types_imports : + AreImported globals "ethereum.shanghai.fork_types" [ "Account"; "Address"; "Root"; "encode_account" ]. + +Axiom ethereum_shanghai_transactions_imports : + AreImported globals "ethereum.shanghai.transactions" [ "LegacyTransaction" ]. Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -117,7 +70,10 @@ Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( )). Definition Node : Value.t := M.run ltac:(M.monadic ( - M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Bytes" |); M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |); M.get_name (| globals, "Withdrawal" |); Constant.None_ ] |) + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Bytes" |); M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |); M.get_name (| globals, "Withdrawal" |); Constant.None_ ] + |) )). Definition K : Value.t := M.run ltac:(M.monadic ( @@ -135,12 +91,36 @@ Definition V : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "TypeVar" |), make_list [ Constant.str "V"; - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Account" |) |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Bytes" |) |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Account" |) + |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Bytes" |) + |); M.get_name (| globals, "Bytes" |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Bytes" |) ] |) |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Bytes" |) ] |) |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Withdrawal" |); M.get_name (| globals, "Bytes" |) ] |) |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "LegacyTransaction" |); M.get_name (| globals, "Bytes" |) ] + |) + |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Bytes" |) ] + |) + |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "Withdrawal" |); M.get_name (| globals, "Bytes" |) ] + |) + |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |) ], @@ -179,7 +159,10 @@ Definition BranchNode : Value.t := ]. Definition InternalNode : Value.t := M.run ltac:(M.monadic ( - M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LeafNode" |); M.get_name (| globals, "ExtensionNode" |); M.get_name (| globals, "BranchNode" |) ] |) + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "LeafNode" |); M.get_name (| globals, "ExtensionNode" |); M.get_name (| globals, "BranchNode" |) ] + |) )). Definition encode_internal_node : Value.t -> Value.t -> M := @@ -291,7 +274,7 @@ Definition encode_internal_node : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "(* At expr: unsupported node type: JoinedStr *)" @@ -531,13 +514,16 @@ Definition trie_set : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "key" |), M.get_field (| M.get_name (| globals, "trie" |), "_data" |) |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + M.get_name (| globals, "key" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -547,7 +533,10 @@ Definition trie_set : Value.t -> Value.t -> M := (* else *) )), ltac:(M.monadic ( let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), + M.get_subscript (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + M.get_name (| globals, "key" |) + |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_ @@ -592,51 +581,66 @@ Definition common_prefix_length : Value.t -> Value.t -> M := let _ := Constant.str " Find the longest common prefix of two sequences. " in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "a" |) - ], - make_dict [] - |) - ], - make_dict [] - |) do - let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| - M.get_name (| globals, "i" |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "b" |) - ], - make_dict [] - |) - |), - ltac:(M.monadic ( - Compare.not_eq (| - M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), - M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) - |) - )) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + ], + make_dict [] + |), ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "i" |) - |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_subscript (| + M.get_name (| globals, "a" |), + M.get_name (| globals, "i" |) + |), + M.get_subscript (| + M.get_name (| globals, "b" |), + M.get_name (| globals, "i" |) + |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "len" |), @@ -721,38 +725,53 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 0; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |); - Constant.int 2 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ BinOp.add (| BinOp.mult (| Constant.int 16, - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "i" |) + |) |), - M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) + |) |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -770,43 +789,61 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := Constant.int 1 |) |), - M.get_subscript (| M.get_name (| globals, "x" |), Constant.int 0 |) + M.get_subscript (| + M.get_name (| globals, "x" |), + Constant.int 0 + |) |) ], make_dict [] |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 1; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |); - Constant.int 2 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 1; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ BinOp.add (| BinOp.mult (| Constant.int 16, - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "i" |) + |) |), - M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) + |) |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -853,40 +890,55 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := ], make_dict [] |) in - For make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ] in M.call (| - M.get_name (| globals, "enumerate" |), - make_list [ - M.get_name (| globals, "bytes_" |) - ], - make_dict [] - |) do - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.mult (| - M.get_name (| globals, "byte_index" |), - Constant.int 2 - |) |), - BinOp.r_shift (| - BinOp.bit_and (| - M.get_name (| globals, "byte" |), - Constant.int 240 - |), - Constant.int 4 - |) - |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "byte_index" |), - Constant.int 2 - |), - Constant.int 1 - |) |), - BinOp.bit_and (| - M.get_name (| globals, "byte" |), - Constant.int 15 - |) - |) in - EndFor. + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ], + M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "bytes_" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "nibble_list" |), + BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |) + |), + BinOp.r_shift (| + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 240 + |), + Constant.int 4 + |) + |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "nibble_list" |), + BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |), + Constant.int 1 + |) + |), + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 15 + |) + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Bytes" |), @@ -919,65 +971,69 @@ Definition _prepare_trie : Value.t -> Value.t -> M := Object with keys mapped to nibble-byte form. " in (* At stmt: unsupported node type: AnnAssign *) - For make_tuple [ M.get_name (| globals, "preimage" |); M.get_name (| globals, "value" |) ] in M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "items" |), - make_list [], - make_dict [] - |) do - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "value" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "preimage" |); M.get_name (| globals, "value" |) ], + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "items" |), + make_list [], + make_dict [] + |), ltac:(M.monadic ( - let _ := M.assert (| Compare.is_not (| + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in - let address := - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in - let encoded_value := - M.call (| - M.get_name (| globals, "encode_node" |), - make_list [ - M.get_name (| globals, "value" |); + let address := M.call (| - M.get_name (| globals, "get_storage_root" |), + M.get_name (| globals, "Address" |), make_list [ - M.get_name (| globals, "address" |) + M.get_name (| globals, "preimage" |) ], make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let encoded_value := - M.call (| - M.get_name (| globals, "encode_node" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - )) |) in - let _ := M.call (| + |) in + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |); + M.call (| + M.get_name (| globals, "get_storage_root" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_eq (| @@ -989,38 +1045,46 @@ Definition _prepare_trie : Value.t -> Value.t -> M := make_dict [] |) in (* At stmt: unsupported node type: AnnAssign *) - let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "trie" |), "secured" |), - (* then *) - ltac:(M.monadic ( - let key := - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "trie" |), "secured" |), + (* then *) + ltac:(M.monadic ( + let key := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let key := + M.get_name (| globals, "preimage" |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "mapped" |), + M.call (| + M.get_name (| globals, "bytes_to_nibble_list" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |) + |), + M.get_name (| globals, "encoded_value" |) + |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let key := - M.get_name (| globals, "preimage" |) in + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "mapped" |), M.call (| - M.get_name (| globals, "bytes_to_nibble_list" |), - make_list [ - M.get_name (| globals, "key" |) - ], - make_dict [] - |) |), - M.get_name (| globals, "encoded_value" |) - |) in - EndFor. + )) + |) in let _ := M.return_ (| M.get_name (| globals, "mapped" |) |) in @@ -1213,8 +1277,16 @@ Definition patricialize : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "LeafNode" |), make_list [ - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |); - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) + M.slice (| + M.get_name (| globals, "arbitrary_key" |), + M.get_name (| globals, "level" |), + Constant.None_, + Constant.None_ + |); + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "arbitrary_key" |) + |) ], make_dict [] |) in @@ -1227,7 +1299,12 @@ Definition patricialize : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in let substring := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "arbitrary_key" |), + M.get_name (| globals, "level" |), + Constant.None_, + Constant.None_ + |) in let prefix_length := M.call (| M.get_name (| globals, "len" |), @@ -1236,39 +1313,53 @@ Definition patricialize : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do - let prefix_length := - M.call (| - M.get_name (| globals, "min" |), - make_list [ - M.get_name (| globals, "prefix_length" |); + let _ := + M.for_ (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "obj" |), + ltac:(M.monadic ( + let prefix_length := M.call (| - M.get_name (| globals, "common_prefix_length" |), + M.get_name (| globals, "min" |), make_list [ - M.get_name (| globals, "substring" |); - M.get_subscript (| M.get_name (| globals, "key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) + M.get_name (| globals, "prefix_length" |); + M.call (| + M.get_name (| globals, "common_prefix_length" |), + make_list [ + M.get_name (| globals, "substring" |); + M.slice (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "level" |), + Constant.None_, + Constant.None_ + |) + ], + make_dict [] + |) ], make_dict [] - |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "prefix_length" |), - Constant.int 0 - |), - (* then *) - ltac:(M.monadic ( - let _ := M.break (| |) in + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "prefix_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := (* if *) M.if_then_else (| @@ -1279,10 +1370,15 @@ Definition patricialize : Value.t -> Value.t -> M := (* then *) ltac:(M.monadic ( let prefix := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), BinOp.add (| + M.slice (| + M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |), - M.get_name (| globals, "prefix_length" |) - |) |) |) in + BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |), + Constant.None_ + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ExtensionNode" |), @@ -1315,70 +1411,106 @@ Definition patricialize : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) - For M.get_name (| globals, "_" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 16 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "_" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 16 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "branches" |), "append" |), make_list [ {} ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let value := Constant.bytes "" in - For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "key" |) - ], - make_dict [] - |), - M.get_name (| globals, "level" |) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "obj" |), ltac:(M.monadic ( let _ := (* if *) M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); - make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] - ], - make_dict [] + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |), + M.get_name (| globals, "level" |) |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "AssertionError" |)) |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "key" |) + |); + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "AssertionError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "key" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| + M.get_subscript (| + M.get_name (| globals, "branches" |), + M.get_subscript (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "level" |) + |) + |), + M.get_name (| globals, "key" |) + |), + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "key" |) + |) + |) in M.pure Constant.None_ )) |) in - let value := - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.assign (| - M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) - |) in + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "BranchNode" |), diff --git a/CoqOfPython/ethereum/shanghai/utils/__init__.v b/CoqOfPython/ethereum/shanghai/utils/__init__.v index 1baedea..5a9b965 100644 --- a/CoqOfPython/ethereum/shanghai/utils/__init__.v +++ b/CoqOfPython/ethereum/shanghai/utils/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.shanghai.utils.__init__". Definition expr_1 : Value.t := Constant.str " diff --git a/CoqOfPython/ethereum/shanghai/utils/address.v b/CoqOfPython/ethereum/shanghai/utils/address.v index 460b28c..f2d8436 100644 --- a/CoqOfPython/ethereum/shanghai/utils/address.v +++ b/CoqOfPython/ethereum/shanghai/utils/address.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.shanghai.utils.address". Definition expr_1 : Value.t := Constant.str " @@ -18,33 +18,23 @@ Address specific functions used in this shanghai version of specification. ". -Require typing. -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". +Axiom typing_imports : + AreImported globals "typing" [ "Union" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes32"; "Uint" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_left_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. -Require ethereum.shanghai.fork_types. -Axiom ethereum_shanghai_fork_types_Address : - IsGlobalAlias globals ethereum.shanghai.fork_types.globals "Address". +Axiom ethereum_shanghai_fork_types_imports : + AreImported globals "ethereum.shanghai.fork_types" [ "Address" ]. Definition to_address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -66,11 +56,16 @@ Definition to_address : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "Address" |), make_list [ - M.get_subscript (| M.call (| - M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), - make_list [], - make_dict [] - |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) + M.slice (| + M.call (| + M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), + UnOp.sub (| Constant.int 20 |), + Constant.None_, + Constant.None_ + |) ], make_dict [] |) @@ -114,7 +109,12 @@ Definition compute_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "computed_address" |), + UnOp.sub (| Constant.int 20 |), + Constant.None_, + Constant.None_ + |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), @@ -182,7 +182,12 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "computed_address" |), + UnOp.sub (| Constant.int 20 |), + Constant.None_, + Constant.None_ + |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/shanghai/utils/hexadecimal.v b/CoqOfPython/ethereum/shanghai/utils/hexadecimal.v index 10b0f37..e7da0f7 100644 --- a/CoqOfPython/ethereum/shanghai/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/shanghai/utils/hexadecimal.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.shanghai.utils.hexadecimal". Definition expr_1 : Value.t := Constant.str " @@ -18,17 +18,11 @@ Hexadecimal utility functions used in this specification, specific to Shanghai types. ". -Require ethereum.utils.hexadecimal. -Axiom ethereum_utils_hexadecimal_remove_hex_prefix : - IsGlobalAlias globals ethereum.utils.hexadecimal.globals "remove_hex_prefix". - -Require ethereum.shanghai.fork_types. -Axiom ethereum_shanghai_fork_types_Address : - IsGlobalAlias globals ethereum.shanghai.fork_types.globals "Address". -Axiom ethereum_shanghai_fork_types_Bloom : - IsGlobalAlias globals ethereum.shanghai.fork_types.globals "Bloom". -Axiom ethereum_shanghai_fork_types_Root : - IsGlobalAlias globals ethereum.shanghai.fork_types.globals "Root". +Axiom ethereum_utils_hexadecimal_imports : + AreImported globals "ethereum.utils.hexadecimal" [ "remove_hex_prefix" ]. + +Axiom ethereum_shanghai_fork_types_imports : + AreImported globals "ethereum.shanghai.fork_types" [ "Address"; "Bloom"; "Root" ]. Definition hex_to_root : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/shanghai/utils/message.v b/CoqOfPython/ethereum/shanghai/utils/message.v index a473e7e..706cf76 100644 --- a/CoqOfPython/ethereum/shanghai/utils/message.v +++ b/CoqOfPython/ethereum/shanghai/utils/message.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.shanghai.utils.message". Definition expr_1 : Value.t := Constant.str " @@ -18,49 +18,26 @@ Message specific functions used in this shanghai version of specification. ". -Require typing. -Axiom typing_FrozenSet : - IsGlobalAlias globals typing.globals "FrozenSet". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". +Axiom typing_imports : + AreImported globals "typing" [ "FrozenSet"; "Optional"; "Tuple"; "Union" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Bytes32"; "Uint" ]. -Require ethereum.shanghai.fork_types. -Axiom ethereum_shanghai_fork_types_Address : - IsGlobalAlias globals ethereum.shanghai.fork_types.globals "Address". +Axiom ethereum_shanghai_fork_types_imports : + AreImported globals "ethereum.shanghai.fork_types" [ "Address" ]. -Require ethereum.shanghai.state. -Axiom ethereum_shanghai_state_get_account : - IsGlobalAlias globals ethereum.shanghai.state.globals "get_account". +Axiom ethereum_shanghai_state_imports : + AreImported globals "ethereum.shanghai.state" [ "get_account" ]. -Require ethereum.shanghai.vm.__init__. -Axiom ethereum_shanghai_vm___init___Environment : - IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Environment". -Axiom ethereum_shanghai_vm___init___Message : - IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Message". +Axiom ethereum_shanghai_vm_imports : + AreImported globals "ethereum.shanghai.vm" [ "Environment"; "Message" ]. -Require ethereum.shanghai.vm.precompiled_contracts.mapping. -Axiom ethereum_shanghai_vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : - IsGlobalAlias globals ethereum.shanghai.vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". +Axiom ethereum_shanghai_vm_precompiled_contracts_mapping_imports : + AreImported globals "ethereum.shanghai.vm.precompiled_contracts.mapping" [ "PRE_COMPILED_CONTRACTS" ]. -Require ethereum.shanghai.utils.address. -Axiom ethereum_shanghai_utils_address_compute_contract_address : - IsGlobalAlias globals ethereum.shanghai.utils.address.globals "compute_contract_address". +Axiom ethereum_shanghai_utils_address_imports : + AreImported globals "ethereum.shanghai.utils.address" [ "compute_contract_address" ]. Definition prepare_message : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -198,7 +175,7 @@ Definition prepare_message : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "Target must be address or empty bytes" diff --git a/CoqOfPython/ethereum/shanghai/vm/__init__.v b/CoqOfPython/ethereum/shanghai/vm/__init__.v index 95d7c55..a40457f 100644 --- a/CoqOfPython/ethereum/shanghai/vm/__init__.v +++ b/CoqOfPython/ethereum/shanghai/vm/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.shanghai.vm.__init__". Definition expr_1 : Value.t := Constant.str " @@ -18,57 +18,29 @@ The abstract computer which runs the code stored in an `.fork_types.Account`. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple"; "Union" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U64 : - IsGlobalAlias globals ethereum.base_types.globals "U64". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U64"; "U256"; "Bytes"; "Bytes0"; "Bytes32"; "Uint" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. -Require ethereum.shanghai.blocks. -Axiom ethereum_shanghai_blocks_Log : - IsGlobalAlias globals ethereum.shanghai.blocks.globals "Log". +Axiom ethereum_shanghai_blocks_imports : + AreImported globals "ethereum.shanghai.blocks" [ "Log" ]. -Require ethereum.shanghai.fork_types. -Axiom ethereum_shanghai_fork_types_Address : - IsGlobalAlias globals ethereum.shanghai.fork_types.globals "Address". +Axiom ethereum_shanghai_fork_types_imports : + AreImported globals "ethereum.shanghai.fork_types" [ "Address" ]. -Require ethereum.shanghai.state. -Axiom ethereum_shanghai_state_State : - IsGlobalAlias globals ethereum.shanghai.state.globals "State". -Axiom ethereum_shanghai_state_account_exists_and_is_empty : - IsGlobalAlias globals ethereum.shanghai.state.globals "account_exists_and_is_empty". +Axiom ethereum_shanghai_state_imports : + AreImported globals "ethereum.shanghai.state" [ "State"; "account_exists_and_is_empty" ]. -Require ethereum.shanghai.vm.precompiled_contracts.__init__. -Axiom ethereum_shanghai_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : - IsGlobalAlias globals ethereum.shanghai.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". +Axiom ethereum_shanghai_vm_precompiled_contracts_imports : + AreImported globals "ethereum.shanghai.vm.precompiled_contracts" [ "RIPEMD160_ADDRESS" ]. Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] @@ -203,7 +175,7 @@ Definition incorporate_child_on_error : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "RIPEMD160_ADDRESS" |), M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) |), diff --git a/CoqOfPython/ethereum/shanghai/vm/exceptions.v b/CoqOfPython/ethereum/shanghai/vm/exceptions.v index 1f4363d..fc20be3 100644 --- a/CoqOfPython/ethereum/shanghai/vm/exceptions.v +++ b/CoqOfPython/ethereum/shanghai/vm/exceptions.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.shanghai.vm.exceptions". Definition expr_1 : Value.t := Constant.str " @@ -17,9 +17,8 @@ Introduction Exceptions which cause the EVM to halt exceptionally. ". -Require ethereum.exceptions. -Axiom ethereum_exceptions_EthereumException : - IsGlobalAlias globals ethereum.exceptions.globals "EthereumException". +Axiom ethereum_exceptions_imports : + AreImported globals "ethereum.exceptions" [ "EthereumException" ]. Definition ExceptionalHalt : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/shanghai/vm/gas.v b/CoqOfPython/ethereum/shanghai/vm/gas.v index f066a72..92abbef 100644 --- a/CoqOfPython/ethereum/shanghai/vm/gas.v +++ b/CoqOfPython/ethereum/shanghai/vm/gas.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.shanghai.vm.gas". Definition expr_1 : Value.t := Constant.str " @@ -17,39 +17,26 @@ Introduction EVM gas constants and calculators. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Tuple" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. -Require ethereum.trace. -Axiom ethereum_trace_GasAndRefund : - IsGlobalAlias globals ethereum.trace.globals "GasAndRefund". -Axiom ethereum_trace_evm_trace : - IsGlobalAlias globals ethereum.trace.globals "evm_trace". +Axiom ethereum_trace_imports : + AreImported globals "ethereum.trace" [ "GasAndRefund"; "evm_trace" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.shanghai.vm.__init__. -Axiom ethereum_shanghai_vm___init___Evm : - IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Evm". +Axiom ethereum_shanghai_vm_imports : + AreImported globals "ethereum.shanghai.vm" [ "Evm" ]. -Require ethereum.shanghai.vm.exceptions. -Axiom ethereum_shanghai_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.shanghai.vm.exceptions.globals "OutOfGasError". +Axiom ethereum_shanghai_vm_exceptions_imports : + AreImported globals "ethereum.shanghai.vm.exceptions" [ "OutOfGasError" ]. Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -512,7 +499,7 @@ Definition charge_gas : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -629,105 +616,114 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := ], make_dict [] |) in - For make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ] in M.get_name (| globals, "extensions" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "size" |), - Constant.int 0 - |), - (* then *) + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ], + M.get_name (| globals, "extensions" |), ltac:(M.monadic ( - let _ := M.continue (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let before_size := - M.call (| - M.get_name (| globals, "ceil32" |), - make_list [ - M.get_name (| globals, "current_size" |) - ], - make_dict [] - |) in - let after_size := - M.call (| - M.get_name (| globals, "ceil32" |), - make_list [ - BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "size" |), + Constant.int 0 |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.lt_e (| - M.get_name (| globals, "after_size" |), - M.get_name (| globals, "before_size" |) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.continue (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let size_to_extend := BinOp.add - BinOp.sub (| + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let before_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "current_size" |) + ], + make_dict [] + |) in + let after_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let size_to_extend := BinOp.add + BinOp.sub (| M.get_name (| globals, "after_size" |), M.get_name (| globals, "before_size" |) |) - BinOp.sub (| + BinOp.sub (| M.get_name (| globals, "after_size" |), M.get_name (| globals, "before_size" |) |) in - let already_paid := - M.call (| - M.get_name (| globals, "calculate_memory_gas_cost" |), - make_list [ - M.get_name (| globals, "before_size" |) - ], - make_dict [] - |) in - let total_cost := - M.call (| - M.get_name (| globals, "calculate_memory_gas_cost" |), - make_list [ - M.get_name (| globals, "after_size" |) - ], - make_dict [] - |) in - let to_be_paid := BinOp.add - BinOp.sub (| + let already_paid := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "before_size" |) + ], + make_dict [] + |) in + let total_cost := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "after_size" |) + ], + make_dict [] + |) in + let to_be_paid := BinOp.add + BinOp.sub (| M.get_name (| globals, "total_cost" |), M.get_name (| globals, "already_paid" |) |) - BinOp.sub (| + BinOp.sub (| M.get_name (| globals, "total_cost" |), M.get_name (| globals, "already_paid" |) |) in - let current_size := - M.get_name (| globals, "after_size" |) in - EndFor. + let current_size := + M.get_name (| globals, "after_size" |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ExtendMemory" |), diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/__init__.v b/CoqOfPython/ethereum/shanghai/vm/instructions/__init__.v index cd917fc..4281cd7 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/__init__.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.shanghai.vm.instructions.__init__". Definition expr_1 : Value.t := Constant.str " @@ -20,59 +20,44 @@ implementations. (* At top_level_stmt: unsupported node type: Import *) -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict" ]. -Require ethereum.shanghai.vm.instructions.__init__. -Axiom ethereum_shanghai_vm_instructions___init___arithmetic : - IsGlobalAlias globals ethereum.shanghai.vm.instructions.__init__.globals "arithmetic". +Axiom ethereum_shanghai_vm_instructions_imports : + AreImported globals "ethereum.shanghai.vm.instructions" [ "arithmetic" ]. -Require ethereum.shanghai.vm.instructions.__init__. -Axiom ethereum_shanghai_vm_instructions___init___bitwise : - IsGlobalAlias globals ethereum.shanghai.vm.instructions.__init__.globals "bitwise". +Axiom ethereum_shanghai_vm_instructions_imports : + AreImported globals "ethereum.shanghai.vm.instructions" [ "bitwise" ]. -Require ethereum.shanghai.vm.instructions.__init__. -Axiom ethereum_shanghai_vm_instructions___init___block : - IsGlobalAlias globals ethereum.shanghai.vm.instructions.__init__.globals "block". +Axiom ethereum_shanghai_vm_instructions_imports : + AreImported globals "ethereum.shanghai.vm.instructions" [ "block" ]. -Require ethereum.shanghai.vm.instructions.__init__. -Axiom ethereum_shanghai_vm_instructions___init___comparison : - IsGlobalAlias globals ethereum.shanghai.vm.instructions.__init__.globals "comparison". +Axiom ethereum_shanghai_vm_instructions_imports : + AreImported globals "ethereum.shanghai.vm.instructions" [ "comparison" ]. -Require ethereum.shanghai.vm.instructions.__init__. -Axiom ethereum_shanghai_vm_instructions___init___control_flow : - IsGlobalAlias globals ethereum.shanghai.vm.instructions.__init__.globals "control_flow". +Axiom ethereum_shanghai_vm_instructions_imports : + AreImported globals "ethereum.shanghai.vm.instructions" [ "control_flow" ]. -Require ethereum.shanghai.vm.instructions.__init__. -Axiom ethereum_shanghai_vm_instructions___init___environment : - IsGlobalAlias globals ethereum.shanghai.vm.instructions.__init__.globals "environment". +Axiom ethereum_shanghai_vm_instructions_imports : + AreImported globals "ethereum.shanghai.vm.instructions" [ "environment" ]. -Require ethereum.shanghai.vm.instructions.__init__. -Axiom ethereum_shanghai_vm_instructions___init___keccak : - IsGlobalAlias globals ethereum.shanghai.vm.instructions.__init__.globals "keccak". +Axiom ethereum_shanghai_vm_instructions_imports : + AreImported globals "ethereum.shanghai.vm.instructions" [ "keccak" ]. -Require ethereum.shanghai.vm.instructions.__init__. -Axiom ethereum_shanghai_vm_instructions___init___log : - IsGlobalAlias globals ethereum.shanghai.vm.instructions.__init__.globals "log". +Axiom ethereum_shanghai_vm_instructions_imports : + AreImported globals "ethereum.shanghai.vm.instructions" [ "log" ]. -Require ethereum.shanghai.vm.instructions.__init__. -Axiom ethereum_shanghai_vm_instructions___init___memory : - IsGlobalAlias globals ethereum.shanghai.vm.instructions.__init__.globals "memory". +Axiom ethereum_shanghai_vm_instructions_imports : + AreImported globals "ethereum.shanghai.vm.instructions" [ "memory" ]. -Require ethereum.shanghai.vm.instructions.__init__. -Axiom ethereum_shanghai_vm_instructions___init___stack : - IsGlobalAlias globals ethereum.shanghai.vm.instructions.__init__.globals "stack". +Axiom ethereum_shanghai_vm_instructions_imports : + AreImported globals "ethereum.shanghai.vm.instructions" [ "stack" ]. -Require ethereum.shanghai.vm.instructions.__init__. -Axiom ethereum_shanghai_vm_instructions___init___storage : - IsGlobalAlias globals ethereum.shanghai.vm.instructions.__init__.globals "storage". +Axiom ethereum_shanghai_vm_instructions_imports : + AreImported globals "ethereum.shanghai.vm.instructions" [ "storage" ]. -Require ethereum.shanghai.vm.instructions.__init__. -Axiom ethereum_shanghai_vm_instructions___init___system : - IsGlobalAlias globals ethereum.shanghai.vm.instructions.__init__.globals "system". +Axiom ethereum_shanghai_vm_instructions_imports : + AreImported globals "ethereum.shanghai.vm.instructions" [ "system" ]. Definition Ops : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/shanghai/vm/instructions/arithmetic.v index e63147d..d155846 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/arithmetic.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.shanghai.vm.instructions.arithmetic". Definition expr_1 : Value.t := Constant.str " @@ -17,43 +17,20 @@ Introduction Implementations of the EVM Arithmetic instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U255_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U255_CEIL_VALUE". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_U256_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U255_CEIL_VALUE"; "U256"; "U256_CEIL_VALUE"; "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_get_sign : - IsGlobalAlias globals ethereum.utils.numeric.globals "get_sign". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "get_sign" ]. -Require ethereum.shanghai.vm.__init__. -Axiom ethereum_shanghai_vm___init___Evm : - IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Evm". +Axiom ethereum_shanghai_vm_imports : + AreImported globals "ethereum.shanghai.vm" [ "Evm" ]. -Require ethereum.shanghai.vm.gas. -Axiom ethereum_shanghai_vm_gas_GAS_EXPONENTIATION : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_EXPONENTIATION". -Axiom ethereum_shanghai_vm_gas_GAS_EXPONENTIATION_PER_BYTE : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_EXPONENTIATION_PER_BYTE". -Axiom ethereum_shanghai_vm_gas_GAS_LOW : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_LOW". -Axiom ethereum_shanghai_vm_gas_GAS_MID : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_MID". -Axiom ethereum_shanghai_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_shanghai_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "charge_gas". +Axiom ethereum_shanghai_vm_gas_imports : + AreImported globals "ethereum.shanghai.vm.gas" [ "GAS_EXPONENTIATION"; "GAS_EXPONENTIATION_PER_BYTE"; "GAS_LOW"; "GAS_MID"; "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.shanghai.vm.stack. -Axiom ethereum_shanghai_vm_stack_pop : - IsGlobalAlias globals ethereum.shanghai.vm.stack.globals "pop". -Axiom ethereum_shanghai_vm_stack_push : - IsGlobalAlias globals ethereum.shanghai.vm.stack.globals "push". +Axiom ethereum_shanghai_vm_stack_imports : + AreImported globals "ethereum.shanghai.vm.stack" [ "pop"; "push" ]. Definition add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -1030,19 +1007,27 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let value_bytes := - M.get_subscript (| M.get_name (| globals, "value_bytes" |), M.slice (| BinOp.sub (| - Constant.int 31, - M.call (| - M.get_name (| globals, "int" |), - make_list [ - M.get_name (| globals, "byte_num" |) - ], - make_dict [] - |) - |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "value_bytes" |), + BinOp.sub (| + Constant.int 31, + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "byte_num" |) + ], + make_dict [] + |) + |), + Constant.None_, + Constant.None_ + |) in let sign_bit := BinOp.r_shift (| - M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), + M.get_subscript (| + M.get_name (| globals, "value_bytes" |), + Constant.int 0 + |), Constant.int 7 |) in let _ := diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/bitwise.v b/CoqOfPython/ethereum/shanghai/vm/instructions/bitwise.v index 614db14..ac97518 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/bitwise.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.shanghai.vm.instructions.bitwise". Definition expr_1 : Value.t := Constant.str " @@ -17,27 +17,17 @@ Introduction Implementations of the EVM bitwise instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_U256_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "U256_CEIL_VALUE" ]. -Require ethereum.shanghai.vm.__init__. -Axiom ethereum_shanghai_vm___init___Evm : - IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Evm". +Axiom ethereum_shanghai_vm_imports : + AreImported globals "ethereum.shanghai.vm" [ "Evm" ]. -Require ethereum.shanghai.vm.gas. -Axiom ethereum_shanghai_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_shanghai_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "charge_gas". +Axiom ethereum_shanghai_vm_gas_imports : + AreImported globals "ethereum.shanghai.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.shanghai.vm.stack. -Axiom ethereum_shanghai_vm_stack_pop : - IsGlobalAlias globals ethereum.shanghai.vm.stack.globals "pop". -Axiom ethereum_shanghai_vm_stack_push : - IsGlobalAlias globals ethereum.shanghai.vm.stack.globals "push". +Axiom ethereum_shanghai_vm_stack_imports : + AreImported globals "ethereum.shanghai.vm.stack" [ "pop"; "push" ]. Definition bitwise_and : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/block.v b/CoqOfPython/ethereum/shanghai/vm/instructions/block.v index 92c2662..60c3592 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/block.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/block.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.shanghai.vm.instructions.block". Definition expr_1 : Value.t := Constant.str " @@ -17,27 +17,17 @@ Introduction Implementations of the EVM block instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.shanghai.vm.__init__. -Axiom ethereum_shanghai_vm___init___Evm : - IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Evm". +Axiom ethereum_shanghai_vm_imports : + AreImported globals "ethereum.shanghai.vm" [ "Evm" ]. -Require ethereum.shanghai.vm.gas. -Axiom ethereum_shanghai_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_BASE". -Axiom ethereum_shanghai_vm_gas_GAS_BLOCK_HASH : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_BLOCK_HASH". -Axiom ethereum_shanghai_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "charge_gas". +Axiom ethereum_shanghai_vm_gas_imports : + AreImported globals "ethereum.shanghai.vm.gas" [ "GAS_BASE"; "GAS_BLOCK_HASH"; "charge_gas" ]. -Require ethereum.shanghai.vm.stack. -Axiom ethereum_shanghai_vm_stack_pop : - IsGlobalAlias globals ethereum.shanghai.vm.stack.globals "pop". -Axiom ethereum_shanghai_vm_stack_push : - IsGlobalAlias globals ethereum.shanghai.vm.stack.globals "push". +Axiom ethereum_shanghai_vm_stack_imports : + AreImported globals "ethereum.shanghai.vm.stack" [ "pop"; "push" ]. Definition block_hash : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -100,10 +90,13 @@ Definition block_hash : Value.t -> Value.t -> M := (* else *) )), ltac:(M.monadic ( let hash := - M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), - M.get_name (| globals, "block_number" |) - |) |) |) in + M.get_subscript (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), + UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + M.get_name (| globals, "block_number" |) + |) |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/comparison.v b/CoqOfPython/ethereum/shanghai/vm/instructions/comparison.v index 40c05f4..6ae5902 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/comparison.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.shanghai.vm.instructions.comparison". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementations of the EVM Comparison instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.shanghai.vm.__init__. -Axiom ethereum_shanghai_vm___init___Evm : - IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Evm". +Axiom ethereum_shanghai_vm_imports : + AreImported globals "ethereum.shanghai.vm" [ "Evm" ]. -Require ethereum.shanghai.vm.gas. -Axiom ethereum_shanghai_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_shanghai_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "charge_gas". +Axiom ethereum_shanghai_vm_gas_imports : + AreImported globals "ethereum.shanghai.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.shanghai.vm.stack. -Axiom ethereum_shanghai_vm_stack_pop : - IsGlobalAlias globals ethereum.shanghai.vm.stack.globals "pop". -Axiom ethereum_shanghai_vm_stack_push : - IsGlobalAlias globals ethereum.shanghai.vm.stack.globals "push". +Axiom ethereum_shanghai_vm_stack_imports : + AreImported globals "ethereum.shanghai.vm.stack" [ "pop"; "push" ]. Definition less_than : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/control_flow.v b/CoqOfPython/ethereum/shanghai/vm/instructions/control_flow.v index 360ca46..c1d696d 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/control_flow.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.shanghai.vm.instructions.control_flow". Definition expr_1 : Value.t := Constant.str " @@ -17,37 +17,20 @@ Introduction Implementations of the EVM control flow instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. -Require ethereum.shanghai.vm.gas. -Axiom ethereum_shanghai_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_BASE". -Axiom ethereum_shanghai_vm_gas_GAS_HIGH : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_HIGH". -Axiom ethereum_shanghai_vm_gas_GAS_JUMPDEST : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_JUMPDEST". -Axiom ethereum_shanghai_vm_gas_GAS_MID : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_MID". -Axiom ethereum_shanghai_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "charge_gas". +Axiom ethereum_shanghai_vm_gas_imports : + AreImported globals "ethereum.shanghai.vm.gas" [ "GAS_BASE"; "GAS_HIGH"; "GAS_JUMPDEST"; "GAS_MID"; "charge_gas" ]. -Require ethereum.shanghai.vm.__init__. -Axiom ethereum_shanghai_vm___init___Evm : - IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Evm". +Axiom ethereum_shanghai_vm_imports : + AreImported globals "ethereum.shanghai.vm" [ "Evm" ]. -Require ethereum.shanghai.vm.exceptions. -Axiom ethereum_shanghai_vm_exceptions_InvalidJumpDestError : - IsGlobalAlias globals ethereum.shanghai.vm.exceptions.globals "InvalidJumpDestError". +Axiom ethereum_shanghai_vm_exceptions_imports : + AreImported globals "ethereum.shanghai.vm.exceptions" [ "InvalidJumpDestError" ]. -Require ethereum.shanghai.vm.stack. -Axiom ethereum_shanghai_vm_stack_pop : - IsGlobalAlias globals ethereum.shanghai.vm.stack.globals "pop". -Axiom ethereum_shanghai_vm_stack_push : - IsGlobalAlias globals ethereum.shanghai.vm.stack.globals "push". +Axiom ethereum_shanghai_vm_stack_imports : + AreImported globals "ethereum.shanghai.vm.stack" [ "pop"; "push" ]. Definition stop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -117,7 +100,7 @@ Definition jump : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "InvalidJumpDestError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -205,7 +188,7 @@ Definition jumpi : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "InvalidJumpDestError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/environment.v b/CoqOfPython/ethereum/shanghai/vm/instructions/environment.v index 488eeda..e529efa 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/environment.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.shanghai.vm.instructions.environment". Definition expr_1 : Value.t := Constant.str " @@ -17,75 +17,41 @@ Introduction Implementations of the EVM environment related instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". - -Require ethereum.shanghai.fork_types. -Axiom ethereum_shanghai_fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals ethereum.shanghai.fork_types.globals "EMPTY_ACCOUNT". - -Require ethereum.shanghai.state. -Axiom ethereum_shanghai_state_get_account : - IsGlobalAlias globals ethereum.shanghai.state.globals "get_account". - -Require ethereum.shanghai.utils.address. -Axiom ethereum_shanghai_utils_address_to_address : - IsGlobalAlias globals ethereum.shanghai.utils.address.globals "to_address". - -Require ethereum.shanghai.vm.memory. -Axiom ethereum_shanghai_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.shanghai.vm.memory.globals "buffer_read". -Axiom ethereum_shanghai_vm_memory_memory_write : - IsGlobalAlias globals ethereum.shanghai.vm.memory.globals "memory_write". - -Require ethereum.shanghai.vm.__init__. -Axiom ethereum_shanghai_vm___init___Evm : - IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Evm". - -Require ethereum.shanghai.vm.exceptions. -Axiom ethereum_shanghai_vm_exceptions_OutOfBoundsRead : - IsGlobalAlias globals ethereum.shanghai.vm.exceptions.globals "OutOfBoundsRead". - -Require ethereum.shanghai.vm.gas. -Axiom ethereum_shanghai_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_BASE". -Axiom ethereum_shanghai_vm_gas_GAS_COLD_ACCOUNT_ACCESS : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_COLD_ACCOUNT_ACCESS". -Axiom ethereum_shanghai_vm_gas_GAS_COPY : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_COPY". -Axiom ethereum_shanghai_vm_gas_GAS_FAST_STEP : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_FAST_STEP". -Axiom ethereum_shanghai_vm_gas_GAS_RETURN_DATA_COPY : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_RETURN_DATA_COPY". -Axiom ethereum_shanghai_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_shanghai_vm_gas_GAS_WARM_ACCESS : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_WARM_ACCESS". -Axiom ethereum_shanghai_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_shanghai_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "charge_gas". - -Require ethereum.shanghai.vm.stack. -Axiom ethereum_shanghai_vm_stack_pop : - IsGlobalAlias globals ethereum.shanghai.vm.stack.globals "pop". -Axiom ethereum_shanghai_vm_stack_push : - IsGlobalAlias globals ethereum.shanghai.vm.stack.globals "push". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. + +Axiom ethereum_shanghai_fork_types_imports : + AreImported globals "ethereum.shanghai.fork_types" [ "EMPTY_ACCOUNT" ]. + +Axiom ethereum_shanghai_state_imports : + AreImported globals "ethereum.shanghai.state" [ "get_account" ]. + +Axiom ethereum_shanghai_utils_address_imports : + AreImported globals "ethereum.shanghai.utils.address" [ "to_address" ]. + +Axiom ethereum_shanghai_vm_memory_imports : + AreImported globals "ethereum.shanghai.vm.memory" [ "buffer_read"; "memory_write" ]. + +Axiom ethereum_shanghai_vm_imports : + AreImported globals "ethereum.shanghai.vm" [ "Evm" ]. + +Axiom ethereum_shanghai_vm_exceptions_imports : + AreImported globals "ethereum.shanghai.vm.exceptions" [ "OutOfBoundsRead" ]. + +Axiom ethereum_shanghai_vm_gas_imports : + AreImported globals "ethereum.shanghai.vm.gas" [ "GAS_BASE"; "GAS_COLD_ACCOUNT_ACCESS"; "GAS_COPY"; "GAS_FAST_STEP"; "GAS_RETURN_DATA_COPY"; "GAS_VERY_LOW"; "GAS_WARM_ACCESS"; "calculate_gas_extend_memory"; "charge_gas" ]. + +Axiom ethereum_shanghai_vm_stack_imports : + AreImported globals "ethereum.shanghai.vm.stack" [ "pop"; "push" ]. Definition address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -158,7 +124,7 @@ Definition balance : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -810,7 +776,7 @@ Definition extcodesize : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -966,7 +932,7 @@ Definition extcodecopy : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -1225,10 +1191,15 @@ Definition returndatacopy : Value.t -> Value.t -> M := |) |) in let value := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.slice (| M.get_name (| globals, "return_data_start_position" |), BinOp.add (| + M.slice (| + M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |), - M.get_name (| globals, "size" |) - |) |) |) in + BinOp.add (| + M.get_name (| globals, "return_data_start_position" |), + M.get_name (| globals, "size" |) + |), + Constant.None_ + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -1272,7 +1243,7 @@ Definition extcodehash : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/keccak.v b/CoqOfPython/ethereum/shanghai/vm/instructions/keccak.v index 5c8d48d..ec50b85 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/keccak.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.shanghai.vm.instructions.keccak". Definition expr_1 : Value.t := Constant.str " @@ -17,43 +17,26 @@ Introduction Implementations of the EVM keccak instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". - -Require ethereum.shanghai.vm.__init__. -Axiom ethereum_shanghai_vm___init___Evm : - IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Evm". - -Require ethereum.shanghai.vm.gas. -Axiom ethereum_shanghai_vm_gas_GAS_KECCAK256 : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_KECCAK256". -Axiom ethereum_shanghai_vm_gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_KECCAK256_WORD". -Axiom ethereum_shanghai_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_shanghai_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "charge_gas". - -Require ethereum.shanghai.vm.memory. -Axiom ethereum_shanghai_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.shanghai.vm.memory.globals "memory_read_bytes". - -Require ethereum.shanghai.vm.stack. -Axiom ethereum_shanghai_vm_stack_pop : - IsGlobalAlias globals ethereum.shanghai.vm.stack.globals "pop". -Axiom ethereum_shanghai_vm_stack_push : - IsGlobalAlias globals ethereum.shanghai.vm.stack.globals "push". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. + +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. + +Axiom ethereum_shanghai_vm_imports : + AreImported globals "ethereum.shanghai.vm" [ "Evm" ]. + +Axiom ethereum_shanghai_vm_gas_imports : + AreImported globals "ethereum.shanghai.vm.gas" [ "GAS_KECCAK256"; "GAS_KECCAK256_WORD"; "calculate_gas_extend_memory"; "charge_gas" ]. + +Axiom ethereum_shanghai_vm_memory_imports : + AreImported globals "ethereum.shanghai.vm.memory" [ "memory_read_bytes" ]. + +Axiom ethereum_shanghai_vm_stack_imports : + AreImported globals "ethereum.shanghai.vm.stack" [ "pop"; "push" ]. Definition keccak : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/log.v b/CoqOfPython/ethereum/shanghai/vm/instructions/log.v index 06c53da..6759b95 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/log.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/log.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.shanghai.vm.instructions.log". Definition expr_1 : Value.t := Constant.str " @@ -17,49 +17,32 @@ Introduction Implementations of the EVM logging instructions. ". -Require functools. -Axiom functools_partial : - IsGlobalAlias globals functools.globals "partial". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.shanghai.blocks. -Axiom ethereum_shanghai_blocks_Log : - IsGlobalAlias globals ethereum.shanghai.blocks.globals "Log". - -Require ethereum.shanghai.vm.__init__. -Axiom ethereum_shanghai_vm___init___Evm : - IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Evm". - -Require ethereum.shanghai.vm.exceptions. -Axiom ethereum_shanghai_vm_exceptions_WriteInStaticContext : - IsGlobalAlias globals ethereum.shanghai.vm.exceptions.globals "WriteInStaticContext". - -Require ethereum.shanghai.vm.gas. -Axiom ethereum_shanghai_vm_gas_GAS_LOG : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_LOG". -Axiom ethereum_shanghai_vm_gas_GAS_LOG_DATA : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_LOG_DATA". -Axiom ethereum_shanghai_vm_gas_GAS_LOG_TOPIC : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_LOG_TOPIC". -Axiom ethereum_shanghai_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_shanghai_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "charge_gas". - -Require ethereum.shanghai.vm.memory. -Axiom ethereum_shanghai_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.shanghai.vm.memory.globals "memory_read_bytes". - -Require ethereum.shanghai.vm.stack. -Axiom ethereum_shanghai_vm_stack_pop : - IsGlobalAlias globals ethereum.shanghai.vm.stack.globals "pop". +Axiom functools_imports : + AreImported globals "functools" [ "partial" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_shanghai_blocks_imports : + AreImported globals "ethereum.shanghai.blocks" [ "Log" ]. + +Axiom ethereum_shanghai_vm_imports : + AreImported globals "ethereum.shanghai.vm" [ "Evm" ]. + +Axiom ethereum_shanghai_vm_exceptions_imports : + AreImported globals "ethereum.shanghai.vm.exceptions" [ "WriteInStaticContext" ]. + +Axiom ethereum_shanghai_vm_gas_imports : + AreImported globals "ethereum.shanghai.vm.gas" [ "GAS_LOG"; "GAS_LOG_DATA"; "GAS_LOG_TOPIC"; "calculate_gas_extend_memory"; "charge_gas" ]. + +Axiom ethereum_shanghai_vm_memory_imports : + AreImported globals "ethereum.shanghai.vm.memory" [ "memory_read_bytes" ]. + +Axiom ethereum_shanghai_vm_stack_imports : + AreImported globals "ethereum.shanghai.vm.stack" [ "pop" ]. Definition log_n : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -96,33 +79,42 @@ Definition log_n : Value.t -> Value.t -> M := |) in let topics := make_list [] in - For M.get_name (| globals, "_" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - M.get_name (| globals, "num_topics" |) - ], - make_dict [] - |) do - let topic := + let _ := + M.for_ (| + M.get_name (| globals, "_" |), M.call (| - M.get_field (| M.call (| - M.get_name (| globals, "pop" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] - |), "to_be_bytes32" |), - make_list [], - make_dict [] - |) in - let _ := M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "num_topics" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let topic := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| M.get_field (| M.get_name (| globals, "topics" |), "append" |), make_list [ M.get_name (| globals, "topic" |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let extend_memory := M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/memory.v b/CoqOfPython/ethereum/shanghai/vm/instructions/memory.v index d516fdf..1293676 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/memory.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.shanghai.vm.instructions.memory". Definition expr_1 : Value.t := Constant.str " @@ -17,37 +17,20 @@ Introduction Implementations of the EVM Memory instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes" ]. -Require ethereum.shanghai.vm.__init__. -Axiom ethereum_shanghai_vm___init___Evm : - IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Evm". +Axiom ethereum_shanghai_vm_imports : + AreImported globals "ethereum.shanghai.vm" [ "Evm" ]. -Require ethereum.shanghai.vm.gas. -Axiom ethereum_shanghai_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_BASE". -Axiom ethereum_shanghai_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_shanghai_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_shanghai_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "charge_gas". +Axiom ethereum_shanghai_vm_gas_imports : + AreImported globals "ethereum.shanghai.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. -Require ethereum.shanghai.vm.memory. -Axiom ethereum_shanghai_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.shanghai.vm.memory.globals "memory_read_bytes". -Axiom ethereum_shanghai_vm_memory_memory_write : - IsGlobalAlias globals ethereum.shanghai.vm.memory.globals "memory_write". +Axiom ethereum_shanghai_vm_memory_imports : + AreImported globals "ethereum.shanghai.vm.memory" [ "memory_read_bytes"; "memory_write" ]. -Require ethereum.shanghai.vm.stack. -Axiom ethereum_shanghai_vm_stack_pop : - IsGlobalAlias globals ethereum.shanghai.vm.stack.globals "pop". -Axiom ethereum_shanghai_vm_stack_push : - IsGlobalAlias globals ethereum.shanghai.vm.stack.globals "push". +Axiom ethereum_shanghai_vm_stack_imports : + AreImported globals "ethereum.shanghai.vm.stack" [ "pop"; "push" ]. Definition mstore : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/stack.v b/CoqOfPython/ethereum/shanghai/vm/instructions/stack.v index 3b72bc8..522ea88 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/stack.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.shanghai.vm.instructions.stack". Definition expr_1 : Value.t := Constant.str " @@ -17,39 +17,26 @@ Introduction Implementations of the EVM stack related instructions. ". -Require functools. -Axiom functools_partial : - IsGlobalAlias globals functools.globals "partial". +Axiom functools_imports : + AreImported globals "functools" [ "partial" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.shanghai.vm.__init__. -Axiom ethereum_shanghai_vm___init___Evm : - IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Evm". -Axiom ethereum_shanghai_vm___init___stack : - IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "stack". +Axiom ethereum_shanghai_vm_imports : + AreImported globals "ethereum.shanghai.vm" [ "Evm"; "stack" ]. -Require ethereum.shanghai.vm.exceptions. -Axiom ethereum_shanghai_vm_exceptions_StackUnderflowError : - IsGlobalAlias globals ethereum.shanghai.vm.exceptions.globals "StackUnderflowError". +Axiom ethereum_shanghai_vm_exceptions_imports : + AreImported globals "ethereum.shanghai.vm.exceptions" [ "StackUnderflowError" ]. -Require ethereum.shanghai.vm.gas. -Axiom ethereum_shanghai_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_BASE". -Axiom ethereum_shanghai_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_shanghai_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "charge_gas". +Axiom ethereum_shanghai_vm_gas_imports : + AreImported globals "ethereum.shanghai.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.shanghai.vm.memory. -Axiom ethereum_shanghai_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.shanghai.vm.memory.globals "buffer_read". +Axiom ethereum_shanghai_vm_memory_imports : + AreImported globals "ethereum.shanghai.vm.memory" [ "buffer_read" ]. Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -225,19 +212,22 @@ Definition dup_n : Value.t -> Value.t -> M := make_dict [] |) in let data_to_duplicate := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] + BinOp.sub (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), + Constant.int 1 |), - Constant.int 1 - |), - M.get_name (| globals, "item_number" |) - |) |) in + M.get_name (| globals, "item_number" |) + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "stack" |), "push" |), make_list [ @@ -300,14 +290,26 @@ Definition swap_n : Value.t -> Value.t -> M := make_dict [] |) in let _ := M.assign (| - make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| - UnOp.sub (| Constant.int 1 |), - M.get_name (| globals, "item_number" |) - |) |) ], - make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| - UnOp.sub (| Constant.int 1 |), - M.get_name (| globals, "item_number" |) - |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |) ] + make_tuple [ M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + UnOp.sub (| Constant.int 1 |) + |); M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) + |) ], + make_tuple [ M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) + |); M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + UnOp.sub (| Constant.int 1 |) + |) ] |) in let _ := M.assign_op (| BinOp.add, diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/storage.v b/CoqOfPython/ethereum/shanghai/vm/instructions/storage.v index 3ed65d5..d5bd6f6 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/storage.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.shanghai.vm.instructions.storage". Definition expr_1 : Value.t := Constant.str " @@ -17,53 +17,26 @@ Introduction Implementations of the EVM storage related instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.shanghai.state. -Axiom ethereum_shanghai_state_get_storage : - IsGlobalAlias globals ethereum.shanghai.state.globals "get_storage". -Axiom ethereum_shanghai_state_get_storage_original : - IsGlobalAlias globals ethereum.shanghai.state.globals "get_storage_original". -Axiom ethereum_shanghai_state_set_storage : - IsGlobalAlias globals ethereum.shanghai.state.globals "set_storage". +Axiom ethereum_shanghai_state_imports : + AreImported globals "ethereum.shanghai.state" [ "get_storage"; "get_storage_original"; "set_storage" ]. -Require ethereum.shanghai.vm.__init__. -Axiom ethereum_shanghai_vm___init___Evm : - IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Evm". +Axiom ethereum_shanghai_vm_imports : + AreImported globals "ethereum.shanghai.vm" [ "Evm" ]. -Require ethereum.shanghai.vm.exceptions. -Axiom ethereum_shanghai_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.shanghai.vm.exceptions.globals "OutOfGasError". -Axiom ethereum_shanghai_vm_exceptions_WriteInStaticContext : - IsGlobalAlias globals ethereum.shanghai.vm.exceptions.globals "WriteInStaticContext". +Axiom ethereum_shanghai_vm_exceptions_imports : + AreImported globals "ethereum.shanghai.vm.exceptions" [ "OutOfGasError"; "WriteInStaticContext" ]. -Require ethereum.shanghai.vm.gas. -Axiom ethereum_shanghai_vm_gas_GAS_CALL_STIPEND : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_CALL_STIPEND". -Axiom ethereum_shanghai_vm_gas_GAS_COLD_SLOAD : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_COLD_SLOAD". -Axiom ethereum_shanghai_vm_gas_GAS_STORAGE_CLEAR_REFUND : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_STORAGE_CLEAR_REFUND". -Axiom ethereum_shanghai_vm_gas_GAS_STORAGE_SET : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_STORAGE_SET". -Axiom ethereum_shanghai_vm_gas_GAS_STORAGE_UPDATE : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_STORAGE_UPDATE". -Axiom ethereum_shanghai_vm_gas_GAS_WARM_ACCESS : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_WARM_ACCESS". -Axiom ethereum_shanghai_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "charge_gas". +Axiom ethereum_shanghai_vm_gas_imports : + AreImported globals "ethereum.shanghai.vm.gas" [ "GAS_CALL_STIPEND"; "GAS_COLD_SLOAD"; "GAS_STORAGE_CLEAR_REFUND"; "GAS_STORAGE_SET"; "GAS_STORAGE_UPDATE"; "GAS_WARM_ACCESS"; "charge_gas" ]. -Require ethereum.shanghai.vm.stack. -Axiom ethereum_shanghai_vm_stack_pop : - IsGlobalAlias globals ethereum.shanghai.vm.stack.globals "pop". -Axiom ethereum_shanghai_vm_stack_push : - IsGlobalAlias globals ethereum.shanghai.vm.stack.globals "push". +Axiom ethereum_shanghai_vm_stack_imports : + AreImported globals "ethereum.shanghai.vm.stack" [ "pop"; "push" ]. Definition sload : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -93,7 +66,7 @@ Definition sload : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| make_tuple [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |); M.get_name (| globals, "key" |) ], M.get_field (| M.get_name (| globals, "evm" |), "accessed_storage_keys" |) |), diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/system.v b/CoqOfPython/ethereum/shanghai/vm/instructions/system.v index e38459d..034932a 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/system.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/system.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.shanghai.vm.instructions.system". Definition expr_1 : Value.t := Constant.str " @@ -17,107 +17,38 @@ Introduction Implementations of the EVM system related instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.shanghai.fork_types. -Axiom ethereum_shanghai_fork_types_Address : - IsGlobalAlias globals ethereum.shanghai.fork_types.globals "Address". +Axiom ethereum_shanghai_fork_types_imports : + AreImported globals "ethereum.shanghai.fork_types" [ "Address" ]. -Require ethereum.shanghai.state. -Axiom ethereum_shanghai_state_account_exists_and_is_empty : - IsGlobalAlias globals ethereum.shanghai.state.globals "account_exists_and_is_empty". -Axiom ethereum_shanghai_state_account_has_code_or_nonce : - IsGlobalAlias globals ethereum.shanghai.state.globals "account_has_code_or_nonce". -Axiom ethereum_shanghai_state_get_account : - IsGlobalAlias globals ethereum.shanghai.state.globals "get_account". -Axiom ethereum_shanghai_state_increment_nonce : - IsGlobalAlias globals ethereum.shanghai.state.globals "increment_nonce". -Axiom ethereum_shanghai_state_is_account_alive : - IsGlobalAlias globals ethereum.shanghai.state.globals "is_account_alive". -Axiom ethereum_shanghai_state_set_account_balance : - IsGlobalAlias globals ethereum.shanghai.state.globals "set_account_balance". +Axiom ethereum_shanghai_state_imports : + AreImported globals "ethereum.shanghai.state" [ "account_exists_and_is_empty"; "account_has_code_or_nonce"; "get_account"; "increment_nonce"; "is_account_alive"; "set_account_balance" ]. -Require ethereum.shanghai.utils.address. -Axiom ethereum_shanghai_utils_address_compute_contract_address : - IsGlobalAlias globals ethereum.shanghai.utils.address.globals "compute_contract_address". -Axiom ethereum_shanghai_utils_address_compute_create2_contract_address : - IsGlobalAlias globals ethereum.shanghai.utils.address.globals "compute_create2_contract_address". -Axiom ethereum_shanghai_utils_address_to_address : - IsGlobalAlias globals ethereum.shanghai.utils.address.globals "to_address". +Axiom ethereum_shanghai_utils_address_imports : + AreImported globals "ethereum.shanghai.utils.address" [ "compute_contract_address"; "compute_create2_contract_address"; "to_address" ]. -Require ethereum.shanghai.vm.__init__. -Axiom ethereum_shanghai_vm___init___Evm : - IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Evm". -Axiom ethereum_shanghai_vm___init___Message : - IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Message". -Axiom ethereum_shanghai_vm___init___incorporate_child_on_error : - IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "incorporate_child_on_error". -Axiom ethereum_shanghai_vm___init___incorporate_child_on_success : - IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "incorporate_child_on_success". +Axiom ethereum_shanghai_vm_imports : + AreImported globals "ethereum.shanghai.vm" [ "Evm"; "Message"; "incorporate_child_on_error"; "incorporate_child_on_success" ]. -Require ethereum.shanghai.vm.exceptions. -Axiom ethereum_shanghai_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.shanghai.vm.exceptions.globals "OutOfGasError". -Axiom ethereum_shanghai_vm_exceptions_Revert : - IsGlobalAlias globals ethereum.shanghai.vm.exceptions.globals "Revert". -Axiom ethereum_shanghai_vm_exceptions_WriteInStaticContext : - IsGlobalAlias globals ethereum.shanghai.vm.exceptions.globals "WriteInStaticContext". +Axiom ethereum_shanghai_vm_exceptions_imports : + AreImported globals "ethereum.shanghai.vm.exceptions" [ "OutOfGasError"; "Revert"; "WriteInStaticContext" ]. -Require ethereum.shanghai.vm.gas. -Axiom ethereum_shanghai_vm_gas_GAS_CALL_VALUE : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_CALL_VALUE". -Axiom ethereum_shanghai_vm_gas_GAS_COLD_ACCOUNT_ACCESS : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_COLD_ACCOUNT_ACCESS". -Axiom ethereum_shanghai_vm_gas_GAS_CREATE : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_CREATE". -Axiom ethereum_shanghai_vm_gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_KECCAK256_WORD". -Axiom ethereum_shanghai_vm_gas_GAS_NEW_ACCOUNT : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_NEW_ACCOUNT". -Axiom ethereum_shanghai_vm_gas_GAS_SELF_DESTRUCT : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_SELF_DESTRUCT". -Axiom ethereum_shanghai_vm_gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". -Axiom ethereum_shanghai_vm_gas_GAS_WARM_ACCESS : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_WARM_ACCESS". -Axiom ethereum_shanghai_vm_gas_GAS_ZERO : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_ZERO". -Axiom ethereum_shanghai_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_shanghai_vm_gas_calculate_message_call_gas : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "calculate_message_call_gas". -Axiom ethereum_shanghai_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "charge_gas". -Axiom ethereum_shanghai_vm_gas_init_code_cost : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "init_code_cost". -Axiom ethereum_shanghai_vm_gas_max_message_call_gas : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "max_message_call_gas". +Axiom ethereum_shanghai_vm_gas_imports : + AreImported globals "ethereum.shanghai.vm.gas" [ "GAS_CALL_VALUE"; "GAS_COLD_ACCOUNT_ACCESS"; "GAS_CREATE"; "GAS_KECCAK256_WORD"; "GAS_NEW_ACCOUNT"; "GAS_SELF_DESTRUCT"; "GAS_SELF_DESTRUCT_NEW_ACCOUNT"; "GAS_WARM_ACCESS"; "GAS_ZERO"; "calculate_gas_extend_memory"; "calculate_message_call_gas"; "charge_gas"; "init_code_cost"; "max_message_call_gas" ]. -Require ethereum.shanghai.vm.memory. -Axiom ethereum_shanghai_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.shanghai.vm.memory.globals "memory_read_bytes". -Axiom ethereum_shanghai_vm_memory_memory_write : - IsGlobalAlias globals ethereum.shanghai.vm.memory.globals "memory_write". +Axiom ethereum_shanghai_vm_memory_imports : + AreImported globals "ethereum.shanghai.vm.memory" [ "memory_read_bytes"; "memory_write" ]. -Require ethereum.shanghai.vm.stack. -Axiom ethereum_shanghai_vm_stack_pop : - IsGlobalAlias globals ethereum.shanghai.vm.stack.globals "pop". -Axiom ethereum_shanghai_vm_stack_push : - IsGlobalAlias globals ethereum.shanghai.vm.stack.globals "push". +Axiom ethereum_shanghai_vm_stack_imports : + AreImported globals "ethereum.shanghai.vm.stack" [ "pop"; "push" ]. Definition generic_create : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -926,7 +857,12 @@ Definition generic_call : Value.t -> Value.t -> M := make_list [ M.get_field (| M.get_name (| globals, "evm" |), "memory" |); M.get_name (| globals, "memory_output_start_position" |); - M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), M.slice (| Constant.None_, M.get_name (| globals, "actual_output_size" |) |) |) + M.slice (| + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), + Constant.None_, + M.get_name (| globals, "actual_output_size" |), + Constant.None_ + |) ], make_dict [] |) in @@ -1026,7 +962,7 @@ Definition call : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "to" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -1332,7 +1268,7 @@ Definition callcode : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "code_address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -1760,7 +1696,7 @@ Definition delegatecall : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "code_address" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -1936,7 +1872,7 @@ Definition staticcall : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "to" |), M.get_field (| M.get_name (| globals, "evm" |), "accessed_addresses" |) |), @@ -2106,6 +2042,6 @@ Definition revert : Value.t -> Value.t -> M := make_dict [] |) |) in - let _ := M.raise (| Some(M.get_name (| globals, "Revert" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "Revert" |)) |) in let _ := M.pass (| |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/shanghai/vm/interpreter.v b/CoqOfPython/ethereum/shanghai/vm/interpreter.v index a5b78df..5d5bb22 100644 --- a/CoqOfPython/ethereum/shanghai/vm/interpreter.v +++ b/CoqOfPython/ethereum/shanghai/vm/interpreter.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.shanghai.vm.interpreter". Definition expr_1 : Value.t := Constant.str " @@ -17,129 +17,50 @@ Introduction A straightforward interpreter that executes EVM code. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_Iterable : - IsGlobalAlias globals typing.globals "Iterable". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.trace. -Axiom ethereum_trace_EvmStop : - IsGlobalAlias globals ethereum.trace.globals "EvmStop". -Axiom ethereum_trace_OpEnd : - IsGlobalAlias globals ethereum.trace.globals "OpEnd". -Axiom ethereum_trace_OpException : - IsGlobalAlias globals ethereum.trace.globals "OpException". -Axiom ethereum_trace_OpStart : - IsGlobalAlias globals ethereum.trace.globals "OpStart". -Axiom ethereum_trace_PrecompileEnd : - IsGlobalAlias globals ethereum.trace.globals "PrecompileEnd". -Axiom ethereum_trace_PrecompileStart : - IsGlobalAlias globals ethereum.trace.globals "PrecompileStart". -Axiom ethereum_trace_TransactionEnd : - IsGlobalAlias globals ethereum.trace.globals "TransactionEnd". -Axiom ethereum_trace_evm_trace : - IsGlobalAlias globals ethereum.trace.globals "evm_trace". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.shanghai.blocks. -Axiom ethereum_shanghai_blocks_Log : - IsGlobalAlias globals ethereum.shanghai.blocks.globals "Log". - -Require ethereum.shanghai.fork_types. -Axiom ethereum_shanghai_fork_types_Address : - IsGlobalAlias globals ethereum.shanghai.fork_types.globals "Address". - -Require ethereum.shanghai.state. -Axiom ethereum_shanghai_state_account_exists_and_is_empty : - IsGlobalAlias globals ethereum.shanghai.state.globals "account_exists_and_is_empty". -Axiom ethereum_shanghai_state_account_has_code_or_nonce : - IsGlobalAlias globals ethereum.shanghai.state.globals "account_has_code_or_nonce". -Axiom ethereum_shanghai_state_begin_transaction : - IsGlobalAlias globals ethereum.shanghai.state.globals "begin_transaction". -Axiom ethereum_shanghai_state_commit_transaction : - IsGlobalAlias globals ethereum.shanghai.state.globals "commit_transaction". -Axiom ethereum_shanghai_state_destroy_storage : - IsGlobalAlias globals ethereum.shanghai.state.globals "destroy_storage". -Axiom ethereum_shanghai_state_increment_nonce : - IsGlobalAlias globals ethereum.shanghai.state.globals "increment_nonce". -Axiom ethereum_shanghai_state_mark_account_created : - IsGlobalAlias globals ethereum.shanghai.state.globals "mark_account_created". -Axiom ethereum_shanghai_state_move_ether : - IsGlobalAlias globals ethereum.shanghai.state.globals "move_ether". -Axiom ethereum_shanghai_state_rollback_transaction : - IsGlobalAlias globals ethereum.shanghai.state.globals "rollback_transaction". -Axiom ethereum_shanghai_state_set_code : - IsGlobalAlias globals ethereum.shanghai.state.globals "set_code". -Axiom ethereum_shanghai_state_touch_account : - IsGlobalAlias globals ethereum.shanghai.state.globals "touch_account". - -Require ethereum.shanghai.vm.__init__. -Axiom ethereum_shanghai_vm___init___Message : - IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Message". - -Require ethereum.shanghai.vm.gas. -Axiom ethereum_shanghai_vm_gas_GAS_CODE_DEPOSIT : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_CODE_DEPOSIT". -Axiom ethereum_shanghai_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "charge_gas". - -Require ethereum.shanghai.vm.precompiled_contracts.mapping. -Axiom ethereum_shanghai_vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : - IsGlobalAlias globals ethereum.shanghai.vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". - -Require ethereum.shanghai.vm.__init__. -Axiom ethereum_shanghai_vm___init___Environment : - IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Environment". -Axiom ethereum_shanghai_vm___init___Evm : - IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Evm". - -Require ethereum.shanghai.vm.exceptions. -Axiom ethereum_shanghai_vm_exceptions_AddressCollision : - IsGlobalAlias globals ethereum.shanghai.vm.exceptions.globals "AddressCollision". -Axiom ethereum_shanghai_vm_exceptions_ExceptionalHalt : - IsGlobalAlias globals ethereum.shanghai.vm.exceptions.globals "ExceptionalHalt". -Axiom ethereum_shanghai_vm_exceptions_InvalidContractPrefix : - IsGlobalAlias globals ethereum.shanghai.vm.exceptions.globals "InvalidContractPrefix". -Axiom ethereum_shanghai_vm_exceptions_InvalidOpcode : - IsGlobalAlias globals ethereum.shanghai.vm.exceptions.globals "InvalidOpcode". -Axiom ethereum_shanghai_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.shanghai.vm.exceptions.globals "OutOfGasError". -Axiom ethereum_shanghai_vm_exceptions_Revert : - IsGlobalAlias globals ethereum.shanghai.vm.exceptions.globals "Revert". -Axiom ethereum_shanghai_vm_exceptions_StackDepthLimitError : - IsGlobalAlias globals ethereum.shanghai.vm.exceptions.globals "StackDepthLimitError". - -Require ethereum.shanghai.vm.instructions.__init__. -Axiom ethereum_shanghai_vm_instructions___init___Ops : - IsGlobalAlias globals ethereum.shanghai.vm.instructions.__init__.globals "Ops". -Axiom ethereum_shanghai_vm_instructions___init___op_implementation : - IsGlobalAlias globals ethereum.shanghai.vm.instructions.__init__.globals "op_implementation". - -Require ethereum.shanghai.vm.runtime. -Axiom ethereum_shanghai_vm_runtime_get_valid_jump_destinations : - IsGlobalAlias globals ethereum.shanghai.vm.runtime.globals "get_valid_jump_destinations". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Iterable"; "Optional"; "Set"; "Tuple"; "Union" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. + +Axiom ethereum_trace_imports : + AreImported globals "ethereum.trace" [ "EvmStop"; "OpEnd"; "OpException"; "OpStart"; "PrecompileEnd"; "PrecompileStart"; "TransactionEnd"; "evm_trace" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_shanghai_blocks_imports : + AreImported globals "ethereum.shanghai.blocks" [ "Log" ]. + +Axiom ethereum_shanghai_fork_types_imports : + AreImported globals "ethereum.shanghai.fork_types" [ "Address" ]. + +Axiom ethereum_shanghai_state_imports : + AreImported globals "ethereum.shanghai.state" [ "account_exists_and_is_empty"; "account_has_code_or_nonce"; "begin_transaction"; "commit_transaction"; "destroy_storage"; "increment_nonce"; "mark_account_created"; "move_ether"; "rollback_transaction"; "set_code"; "touch_account" ]. + +Axiom ethereum_shanghai_vm_imports : + AreImported globals "ethereum.shanghai.vm" [ "Message" ]. + +Axiom ethereum_shanghai_vm_gas_imports : + AreImported globals "ethereum.shanghai.vm.gas" [ "GAS_CODE_DEPOSIT"; "charge_gas" ]. + +Axiom ethereum_shanghai_vm_precompiled_contracts_mapping_imports : + AreImported globals "ethereum.shanghai.vm.precompiled_contracts.mapping" [ "PRE_COMPILED_CONTRACTS" ]. + +Axiom ethereum_shanghai_vm_imports : + AreImported globals "ethereum.shanghai.vm" [ "Environment"; "Evm" ]. + +Axiom ethereum_shanghai_vm_exceptions_imports : + AreImported globals "ethereum.shanghai.vm.exceptions" [ "AddressCollision"; "ExceptionalHalt"; "InvalidContractPrefix"; "InvalidOpcode"; "OutOfGasError"; "Revert"; "StackDepthLimitError" ]. + +Axiom ethereum_shanghai_vm_instructions_imports : + AreImported globals "ethereum.shanghai.vm.instructions" [ "Ops"; "op_implementation" ]. + +Axiom ethereum_shanghai_vm_runtime_imports : + AreImported globals "ethereum.shanghai.vm.runtime" [ "get_valid_jump_destinations" ]. Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -520,7 +441,7 @@ Definition process_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "StackDepthLimitError" |), make_list [ Constant.str "Stack depth limit reached" diff --git a/CoqOfPython/ethereum/shanghai/vm/memory.v b/CoqOfPython/ethereum/shanghai/vm/memory.v index 08d2290..e5006c5 100644 --- a/CoqOfPython/ethereum/shanghai/vm/memory.v +++ b/CoqOfPython/ethereum/shanghai/vm/memory.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.shanghai.vm.memory". Definition expr_1 : Value.t := Constant.str " @@ -17,17 +17,11 @@ Introduction EVM memory operations. ". -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_right_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "right_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "right_pad_zero_bytes" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. Definition memory_write : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,22 +39,27 @@ Definition memory_write : Value.t -> Value.t -> M := Data to write to memory. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + M.slice (| + M.get_name (| globals, "memory" |), + M.get_name (| globals, "start_position" |), + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) - |) |) |), + Constant.None_ + |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_)). @@ -86,22 +85,27 @@ Definition memory_read_bytes : Value.t -> Value.t -> M := Data read from memory. " in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + M.slice (| + M.get_name (| globals, "memory" |), + M.get_name (| globals, "start_position" |), + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |) |) + Constant.None_ + |) |) in M.pure Constant.None_)). @@ -129,22 +133,27 @@ Definition buffer_read : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "right_pad_zero_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "buffer" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + M.slice (| + M.get_name (| globals, "buffer" |), + M.get_name (| globals, "start_position" |), + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |) |); + Constant.None_ + |); M.get_name (| globals, "size" |) ], make_dict [] diff --git a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/__init__.v index 4ef50e8..c3a26d6 100644 --- a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/__init__.v +++ b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.shanghai.vm.precompiled_contracts.__init__". Definition expr_1 : Value.t := Constant.str " @@ -18,9 +18,8 @@ Addresses of precompiled contracts and mappings to their implementations. ". -Require ethereum.shanghai.utils.hexadecimal. -Axiom ethereum_shanghai_utils_hexadecimal_hex_to_address : - IsGlobalAlias globals ethereum.shanghai.utils.hexadecimal.globals "hex_to_address". +Axiom ethereum_shanghai_utils_hexadecimal_imports : + AreImported globals "ethereum.shanghai.utils.hexadecimal" [ "hex_to_address" ]. Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS"; Constant.str "MODEXP_ADDRESS"; Constant.str "ALT_BN128_ADD_ADDRESS"; Constant.str "ALT_BN128_MUL_ADDRESS"; Constant.str "ALT_BN128_PAIRING_CHECK_ADDRESS"; Constant.str "BLAKE2F_ADDRESS" ] diff --git a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/alt_bn128.v index 53543aa..598f17f 100644 --- a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/alt_bn128.v +++ b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/alt_bn128.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.shanghai.vm.precompiled_contracts.alt_bn128". Definition expr_1 : Value.t := Constant.str " @@ -17,49 +17,26 @@ Introduction Implementation of the ALT_BN128 precompiled contracts. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. -Require ethereum.crypto.alt_bn128. -Axiom ethereum_crypto_alt_bn128_ALT_BN128_CURVE_ORDER : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "ALT_BN128_CURVE_ORDER". -Axiom ethereum_crypto_alt_bn128_ALT_BN128_PRIME : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "ALT_BN128_PRIME". -Axiom ethereum_crypto_alt_bn128_BNF : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF". -Axiom ethereum_crypto_alt_bn128_BNF2 : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF2". -Axiom ethereum_crypto_alt_bn128_BNF12 : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNF12". -Axiom ethereum_crypto_alt_bn128_BNP : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNP". -Axiom ethereum_crypto_alt_bn128_BNP2 : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "BNP2". -Axiom ethereum_crypto_alt_bn128_pairing : - IsGlobalAlias globals ethereum.crypto.alt_bn128.globals "pairing". +Axiom ethereum_crypto_alt_bn128_imports : + AreImported globals "ethereum.crypto.alt_bn128" [ "ALT_BN128_CURVE_ORDER"; "ALT_BN128_PRIME"; "BNF"; "BNF2"; "BNF12"; "BNP"; "BNP2"; "pairing" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.shanghai.vm.__init__. -Axiom ethereum_shanghai_vm___init___Evm : - IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Evm". +Axiom ethereum_shanghai_vm_imports : + AreImported globals "ethereum.shanghai.vm" [ "Evm" ]. -Require ethereum.shanghai.vm.gas. -Axiom ethereum_shanghai_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "charge_gas". +Axiom ethereum_shanghai_vm_gas_imports : + AreImported globals "ethereum.shanghai.vm.gas" [ "charge_gas" ]. -Require ethereum.shanghai.vm.memory. -Axiom ethereum_shanghai_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.shanghai.vm.memory.globals "buffer_read". +Axiom ethereum_shanghai_vm_memory_imports : + AreImported globals "ethereum.shanghai.vm.memory" [ "buffer_read" ]. -Require ethereum.shanghai.vm.exceptions. -Axiom ethereum_shanghai_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.shanghai.vm.exceptions.globals "OutOfGasError". +Axiom ethereum_shanghai_vm_exceptions_imports : + AreImported globals "ethereum.shanghai.vm.exceptions" [ "OutOfGasError" ]. Definition alt_bn128_add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -208,23 +185,32 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ] do - let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| - M.get_name (| globals, "i" |), - M.get_name (| globals, "ALT_BN128_PRIME" |) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |); M.get_name (| globals, "x1_value" |); M.get_name (| globals, "y1_value" |) ], ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in (* At stmt: unsupported node type: Try *) let p := BinOp.add (| @@ -363,23 +349,32 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ] do - let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| - M.get_name (| globals, "i" |), - M.get_name (| globals, "ALT_BN128_PRIME" |) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + make_tuple [ M.get_name (| globals, "x0_value" |); M.get_name (| globals, "y0_value" |) ], ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in (* At stmt: unsupported node type: Try *) let p := M.call (| @@ -466,7 +461,7 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -480,76 +475,89 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - BinOp.floor_div (| + let _ := + M.for_ (| + M.get_name (| globals, "i" |), M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "data" |) - ], - make_dict [] - |), - Constant.int 192 - |) - ], - make_dict [] - |) do - let values := - make_list [] in - For M.get_name (| globals, "j" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 6 - ], - make_dict [] - |) do - let value := + M.get_name (| globals, "range" |), + make_list [ + BinOp.floor_div (| M.call (| - M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + M.get_name (| globals, "len" |), make_list [ - M.get_subscript (| M.get_name (| globals, "data" |), M.slice (| BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "i" |), - Constant.int 192 - |), - BinOp.mult (| - Constant.int 32, - M.get_name (| globals, "j" |) - |) - |), BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "i" |), - Constant.int 192 - |), - BinOp.mult (| - Constant.int 32, - BinOp.add (| - M.get_name (| globals, "j" |), - Constant.int 1 - |) - |) - |) |) |) + M.get_name (| globals, "data" |) ], make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.gt_e (| - M.get_name (| globals, "value" |), - M.get_name (| globals, "ALT_BN128_PRIME" |) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let _ := M.call (| + |), + Constant.int 192 + |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let values := + make_list [] in + let _ := + M.for_ (| + M.get_name (| globals, "j" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 6 + ], + make_dict [] + |), + ltac:(M.monadic ( + let value := + M.call (| + M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), + make_list [ + M.slice (| + M.get_name (| globals, "data" |), + BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + M.get_name (| globals, "j" |) + |) + |), + BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "i" |), + Constant.int 192 + |), + BinOp.mult (| + Constant.int 32, + BinOp.add (| + M.get_name (| globals, "j" |), + Constant.int 1 + |) + |) + |), + Constant.None_ + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.gt_e (| + M.get_name (| globals, "value" |), + M.get_name (| globals, "ALT_BN128_PRIME" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let _ := M.call (| M.get_field (| M.get_name (| globals, "values" |), "append" |), make_list [ M.call (| @@ -562,9 +570,14 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in (* At stmt: unsupported node type: Try *) - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.eq (| @@ -585,7 +598,7 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.eq (| @@ -606,49 +619,54 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := - (* if *) - M.if_then_else (| - BoolOp.and (| - Compare.not_eq (| - M.get_name (| globals, "p" |), - M.call (| - M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) - |), + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.not_eq (| + M.get_name (| globals, "p" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_name (| globals, "q" |), + M.call (| + M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), + make_list [], + make_dict [] + |) + |) + )) + |), + (* then *) ltac:(M.monadic ( - Compare.not_eq (| - M.get_name (| globals, "q" |), - M.call (| - M.get_field (| M.get_name (| globals, "BNP2" |), "point_at_infinity" |), - make_list [], - make_dict [] - |) - |) - )) - |), - (* then *) - ltac:(M.monadic ( - let result := - BinOp.mult (| - M.get_name (| globals, "result" |), - M.call (| - M.get_name (| globals, "pairing" |), - make_list [ - M.get_name (| globals, "q" |); - M.get_name (| globals, "p" |) - ], - make_dict [] - |) - |) in + let result := + BinOp.mult (| + M.get_name (| globals, "result" |), + M.call (| + M.get_name (| globals, "pairing" |), + make_list [ + M.get_name (| globals, "q" |); + M.get_name (| globals, "p" |) + ], + make_dict [] + |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := (* if *) M.if_then_else (| diff --git a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/blake2f.v b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/blake2f.v index f9d1f0b..142ed4a 100644 --- a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/blake2f.v +++ b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/blake2f.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.shanghai.vm.precompiled_contracts.blake2f". Definition expr_1 : Value.t := Constant.str " @@ -17,27 +17,20 @@ Introduction Implementation of the `Blake2` precompiled contract. ". -Require ethereum.crypto.blake2. -Axiom ethereum_crypto_blake2_Blake2b : - IsGlobalAlias globals ethereum.crypto.blake2.globals "Blake2b". +Axiom ethereum_crypto_blake2_imports : + AreImported globals "ethereum.crypto.blake2" [ "Blake2b" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.shanghai.vm.__init__. -Axiom ethereum_shanghai_vm___init___Evm : - IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Evm". +Axiom ethereum_shanghai_vm_imports : + AreImported globals "ethereum.shanghai.vm" [ "Evm" ]. -Require ethereum.shanghai.vm.gas. -Axiom ethereum_shanghai_vm_gas_GAS_BLAKE2_PER_ROUND : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_BLAKE2_PER_ROUND". -Axiom ethereum_shanghai_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "charge_gas". +Axiom ethereum_shanghai_vm_gas_imports : + AreImported globals "ethereum.shanghai.vm.gas" [ "GAS_BLAKE2_PER_ROUND"; "charge_gas" ]. -Require ethereum.shanghai.vm.exceptions. -Axiom ethereum_shanghai_vm_exceptions_InvalidParameter : - IsGlobalAlias globals ethereum.shanghai.vm.exceptions.globals "InvalidParameter". +Axiom ethereum_shanghai_vm_exceptions_imports : + AreImported globals "ethereum.shanghai.vm.exceptions" [ "InvalidParameter" ]. Definition blake2f : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -99,7 +92,7 @@ Definition blake2f : Value.t -> Value.t -> M := let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.in (| + Compare.in_ (| M.get_name (| globals, "f" |), make_list [ Constant.int 0; diff --git a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/ecrecover.v index 42d4132..08460e2 100644 --- a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/ecrecover.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.shanghai.vm.precompiled_contracts.ecrecover". Definition expr_1 : Value.t := Constant.str " @@ -17,39 +17,26 @@ Introduction Implementation of the ECRECOVER precompiled contract. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.crypto.elliptic_curve. -Axiom ethereum_crypto_elliptic_curve_SECP256K1N : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". -Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". +Axiom ethereum_crypto_elliptic_curve_imports : + AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_left_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. -Require ethereum.shanghai.vm.__init__. -Axiom ethereum_shanghai_vm___init___Evm : - IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Evm". +Axiom ethereum_shanghai_vm_imports : + AreImported globals "ethereum.shanghai.vm" [ "Evm" ]. -Require ethereum.shanghai.vm.gas. -Axiom ethereum_shanghai_vm_gas_GAS_ECRECOVER : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_ECRECOVER". -Axiom ethereum_shanghai_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "charge_gas". +Axiom ethereum_shanghai_vm_gas_imports : + AreImported globals "ethereum.shanghai.vm.gas" [ "GAS_ECRECOVER"; "charge_gas" ]. -Require ethereum.shanghai.vm.memory. -Axiom ethereum_shanghai_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.shanghai.vm.memory.globals "buffer_read". +Axiom ethereum_shanghai_vm_memory_imports : + AreImported globals "ethereum.shanghai.vm.memory" [ "buffer_read" ]. Definition ecrecover : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -264,13 +251,18 @@ Definition ecrecover : Value.t -> Value.t -> M := )) |) in (* At stmt: unsupported node type: Try *) let address := - M.get_subscript (| M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "public_key" |) - ], - make_dict [] - |), M.slice (| Constant.int 12, Constant.int 32 |) |) in + M.slice (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), + Constant.int 12, + Constant.int 32, + Constant.None_ + |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/identity.v index 67d5eb2..d912b9e 100644 --- a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/identity.v +++ b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/identity.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.shanghai.vm.precompiled_contracts.identity". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementation of the `IDENTITY` precompiled contract. ". -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.shanghai.vm.__init__. -Axiom ethereum_shanghai_vm___init___Evm : - IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Evm". +Axiom ethereum_shanghai_vm_imports : + AreImported globals "ethereum.shanghai.vm" [ "Evm" ]. -Require ethereum.shanghai.vm.gas. -Axiom ethereum_shanghai_vm_gas_GAS_IDENTITY : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_IDENTITY". -Axiom ethereum_shanghai_vm_gas_GAS_IDENTITY_WORD : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_IDENTITY_WORD". -Axiom ethereum_shanghai_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "charge_gas". +Axiom ethereum_shanghai_vm_gas_imports : + AreImported globals "ethereum.shanghai.vm.gas" [ "GAS_IDENTITY"; "GAS_IDENTITY_WORD"; "charge_gas" ]. Definition identity : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/mapping.v index 535a24a..d240a83 100644 --- a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/mapping.v +++ b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/mapping.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.shanghai.vm.precompiled_contracts.mapping". Definition expr_1 : Value.t := Constant.str " @@ -17,66 +17,34 @@ Introduction Mapping of precompiled contracts their implementations. ". -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". - -Require ethereum.shanghai.fork_types. -Axiom ethereum_shanghai_fork_types_Address : - IsGlobalAlias globals ethereum.shanghai.fork_types.globals "Address". - -Require ethereum.shanghai.vm.precompiled_contracts.__init__. -Axiom ethereum_shanghai_vm_precompiled_contracts___init___ALT_BN128_ADD_ADDRESS : - IsGlobalAlias globals ethereum.shanghai.vm.precompiled_contracts.__init__.globals "ALT_BN128_ADD_ADDRESS". -Axiom ethereum_shanghai_vm_precompiled_contracts___init___ALT_BN128_MUL_ADDRESS : - IsGlobalAlias globals ethereum.shanghai.vm.precompiled_contracts.__init__.globals "ALT_BN128_MUL_ADDRESS". -Axiom ethereum_shanghai_vm_precompiled_contracts___init___ALT_BN128_PAIRING_CHECK_ADDRESS : - IsGlobalAlias globals ethereum.shanghai.vm.precompiled_contracts.__init__.globals "ALT_BN128_PAIRING_CHECK_ADDRESS". -Axiom ethereum_shanghai_vm_precompiled_contracts___init___BLAKE2F_ADDRESS : - IsGlobalAlias globals ethereum.shanghai.vm.precompiled_contracts.__init__.globals "BLAKE2F_ADDRESS". -Axiom ethereum_shanghai_vm_precompiled_contracts___init___ECRECOVER_ADDRESS : - IsGlobalAlias globals ethereum.shanghai.vm.precompiled_contracts.__init__.globals "ECRECOVER_ADDRESS". -Axiom ethereum_shanghai_vm_precompiled_contracts___init___IDENTITY_ADDRESS : - IsGlobalAlias globals ethereum.shanghai.vm.precompiled_contracts.__init__.globals "IDENTITY_ADDRESS". -Axiom ethereum_shanghai_vm_precompiled_contracts___init___MODEXP_ADDRESS : - IsGlobalAlias globals ethereum.shanghai.vm.precompiled_contracts.__init__.globals "MODEXP_ADDRESS". -Axiom ethereum_shanghai_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : - IsGlobalAlias globals ethereum.shanghai.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". -Axiom ethereum_shanghai_vm_precompiled_contracts___init___SHA256_ADDRESS : - IsGlobalAlias globals ethereum.shanghai.vm.precompiled_contracts.__init__.globals "SHA256_ADDRESS". - -Require ethereum.shanghai.vm.precompiled_contracts.alt_bn128. -Axiom ethereum_shanghai_vm_precompiled_contracts_alt_bn128_alt_bn128_add : - IsGlobalAlias globals ethereum.shanghai.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_add". -Axiom ethereum_shanghai_vm_precompiled_contracts_alt_bn128_alt_bn128_mul : - IsGlobalAlias globals ethereum.shanghai.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_mul". -Axiom ethereum_shanghai_vm_precompiled_contracts_alt_bn128_alt_bn128_pairing_check : - IsGlobalAlias globals ethereum.shanghai.vm.precompiled_contracts.alt_bn128.globals "alt_bn128_pairing_check". - -Require ethereum.shanghai.vm.precompiled_contracts.blake2f. -Axiom ethereum_shanghai_vm_precompiled_contracts_blake2f_blake2f : - IsGlobalAlias globals ethereum.shanghai.vm.precompiled_contracts.blake2f.globals "blake2f". - -Require ethereum.shanghai.vm.precompiled_contracts.ecrecover. -Axiom ethereum_shanghai_vm_precompiled_contracts_ecrecover_ecrecover : - IsGlobalAlias globals ethereum.shanghai.vm.precompiled_contracts.ecrecover.globals "ecrecover". - -Require ethereum.shanghai.vm.precompiled_contracts.identity. -Axiom ethereum_shanghai_vm_precompiled_contracts_identity_identity : - IsGlobalAlias globals ethereum.shanghai.vm.precompiled_contracts.identity.globals "identity". - -Require ethereum.shanghai.vm.precompiled_contracts.modexp. -Axiom ethereum_shanghai_vm_precompiled_contracts_modexp_modexp : - IsGlobalAlias globals ethereum.shanghai.vm.precompiled_contracts.modexp.globals "modexp". - -Require ethereum.shanghai.vm.precompiled_contracts.ripemd160. -Axiom ethereum_shanghai_vm_precompiled_contracts_ripemd160_ripemd160 : - IsGlobalAlias globals ethereum.shanghai.vm.precompiled_contracts.ripemd160.globals "ripemd160". - -Require ethereum.shanghai.vm.precompiled_contracts.sha256. -Axiom ethereum_shanghai_vm_precompiled_contracts_sha256_sha256 : - IsGlobalAlias globals ethereum.shanghai.vm.precompiled_contracts.sha256.globals "sha256". +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict" ]. + +Axiom ethereum_shanghai_fork_types_imports : + AreImported globals "ethereum.shanghai.fork_types" [ "Address" ]. + +Axiom ethereum_shanghai_vm_precompiled_contracts_imports : + AreImported globals "ethereum.shanghai.vm.precompiled_contracts" [ "ALT_BN128_ADD_ADDRESS"; "ALT_BN128_MUL_ADDRESS"; "ALT_BN128_PAIRING_CHECK_ADDRESS"; "BLAKE2F_ADDRESS"; "ECRECOVER_ADDRESS"; "IDENTITY_ADDRESS"; "MODEXP_ADDRESS"; "RIPEMD160_ADDRESS"; "SHA256_ADDRESS" ]. + +Axiom ethereum_shanghai_vm_precompiled_contracts_alt_bn128_imports : + AreImported globals "ethereum.shanghai.vm.precompiled_contracts.alt_bn128" [ "alt_bn128_add"; "alt_bn128_mul"; "alt_bn128_pairing_check" ]. + +Axiom ethereum_shanghai_vm_precompiled_contracts_blake2f_imports : + AreImported globals "ethereum.shanghai.vm.precompiled_contracts.blake2f" [ "blake2f" ]. + +Axiom ethereum_shanghai_vm_precompiled_contracts_ecrecover_imports : + AreImported globals "ethereum.shanghai.vm.precompiled_contracts.ecrecover" [ "ecrecover" ]. + +Axiom ethereum_shanghai_vm_precompiled_contracts_identity_imports : + AreImported globals "ethereum.shanghai.vm.precompiled_contracts.identity" [ "identity" ]. + +Axiom ethereum_shanghai_vm_precompiled_contracts_modexp_imports : + AreImported globals "ethereum.shanghai.vm.precompiled_contracts.modexp" [ "modexp" ]. + +Axiom ethereum_shanghai_vm_precompiled_contracts_ripemd160_imports : + AreImported globals "ethereum.shanghai.vm.precompiled_contracts.ripemd160" [ "ripemd160" ]. + +Axiom ethereum_shanghai_vm_precompiled_contracts_sha256_imports : + AreImported globals "ethereum.shanghai.vm.precompiled_contracts.sha256" [ "sha256" ]. (* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/modexp.v index 48cbbe9..ce3a676 100644 --- a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/modexp.v +++ b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/modexp.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.shanghai.vm.precompiled_contracts.modexp". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementation of the `MODEXP` precompiled contract. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. -Require ethereum.shanghai.vm.__init__. -Axiom ethereum_shanghai_vm___init___Evm : - IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Evm". +Axiom ethereum_shanghai_vm_imports : + AreImported globals "ethereum.shanghai.vm" [ "Evm" ]. -Require ethereum.shanghai.vm.gas. -Axiom ethereum_shanghai_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "charge_gas". +Axiom ethereum_shanghai_vm_gas_imports : + AreImported globals "ethereum.shanghai.vm.gas" [ "charge_gas" ]. -Require ethereum.shanghai.vm.memory. -Axiom ethereum_shanghai_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.shanghai.vm.memory.globals "buffer_read". +Axiom ethereum_shanghai_vm_memory_imports : + AreImported globals "ethereum.shanghai.vm.memory" [ "buffer_read" ]. Definition GQUADDIVISOR : Value.t := M.run ltac:(M.monadic ( Constant.int 3 diff --git a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/ripemd160.v index 49c91d6..81d2ec2 100644 --- a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/ripemd160.v +++ b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/ripemd160.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.shanghai.vm.precompiled_contracts.ripemd160". Definition expr_1 : Value.t := Constant.str " @@ -19,29 +19,20 @@ Implementation of the `RIPEMD160` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_left_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.shanghai.vm.__init__. -Axiom ethereum_shanghai_vm___init___Evm : - IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Evm". +Axiom ethereum_shanghai_vm_imports : + AreImported globals "ethereum.shanghai.vm" [ "Evm" ]. -Require ethereum.shanghai.vm.gas. -Axiom ethereum_shanghai_vm_gas_GAS_RIPEMD160 : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_RIPEMD160". -Axiom ethereum_shanghai_vm_gas_GAS_RIPEMD160_WORD : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_RIPEMD160_WORD". -Axiom ethereum_shanghai_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "charge_gas". +Axiom ethereum_shanghai_vm_gas_imports : + AreImported globals "ethereum.shanghai.vm.gas" [ "GAS_RIPEMD160"; "GAS_RIPEMD160_WORD"; "charge_gas" ]. Definition ripemd160 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/sha256.v index 80beec5..1562fc4 100644 --- a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/sha256.v +++ b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/sha256.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.shanghai.vm.precompiled_contracts.sha256". Definition expr_1 : Value.t := Constant.str " @@ -19,25 +19,17 @@ Implementation of the `SHA256` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.shanghai.vm.__init__. -Axiom ethereum_shanghai_vm___init___Evm : - IsGlobalAlias globals ethereum.shanghai.vm.__init__.globals "Evm". +Axiom ethereum_shanghai_vm_imports : + AreImported globals "ethereum.shanghai.vm" [ "Evm" ]. -Require ethereum.shanghai.vm.gas. -Axiom ethereum_shanghai_vm_gas_GAS_SHA256 : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_SHA256". -Axiom ethereum_shanghai_vm_gas_GAS_SHA256_WORD : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "GAS_SHA256_WORD". -Axiom ethereum_shanghai_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.shanghai.vm.gas.globals "charge_gas". +Axiom ethereum_shanghai_vm_gas_imports : + AreImported globals "ethereum.shanghai.vm.gas" [ "GAS_SHA256"; "GAS_SHA256_WORD"; "charge_gas" ]. Definition sha256 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/shanghai/vm/runtime.v b/CoqOfPython/ethereum/shanghai/vm/runtime.v index 0b06bfb..93e75b8 100644 --- a/CoqOfPython/ethereum/shanghai/vm/runtime.v +++ b/CoqOfPython/ethereum/shanghai/vm/runtime.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.shanghai.vm.runtime". Definition expr_1 : Value.t := Constant.str " @@ -17,17 +17,14 @@ Introduction Runtime related operations used while executing EVM code. ". -Require typing. -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". +Axiom typing_imports : + AreImported globals "typing" [ "Set" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.shanghai.vm.instructions.__init__. -Axiom ethereum_shanghai_vm_instructions___init___Ops : - IsGlobalAlias globals ethereum.shanghai.vm.instructions.__init__.globals "Ops". +Axiom ethereum_shanghai_vm_instructions_imports : + AreImported globals "ethereum.shanghai.vm.instructions" [ "Ops" ]. Definition get_valid_jump_destinations : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -67,75 +64,83 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := ], make_dict [] |) in - While Compare.lt (| - M.get_name (| globals, "pc" |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "code" |) - ], - make_dict [] - |) - |) do -(* At stmt: unsupported node type: Try *) - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "current_opcode" |), - M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) - |), - (* then *) + let _ := + M.while (| + Compare.lt (| + M.get_name (| globals, "pc" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) + |), ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), - make_list [ - M.get_name (| globals, "pc" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( +(* At stmt: unsupported node type: Try *) let _ := (* if *) M.if_then_else (| - BoolOp.and (| - Compare.lt_e (| - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |), - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |) - |), - ltac:(M.monadic ( - Compare.lt_e (| - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH32" |), "value" |) - |) - )) + Compare.eq (| + M.get_name (| globals, "current_opcode" |), + M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) |), (* then *) ltac:(M.monadic ( - let push_data_size := - BinOp.add (| - BinOp.sub (| - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) - |), - Constant.int 1 - |) in - let pc := BinOp.add - M.get_name (| globals, "push_data_size" |) - M.get_name (| globals, "push_data_size" |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), + make_list [ + M.get_name (| globals, "pc" |) + ], + make_dict [] + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.lt_e (| + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |), + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH32" |), "value" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let push_data_size := + BinOp.add (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) + |), + Constant.int 1 + |) in + let pc := BinOp.add + M.get_name (| globals, "push_data_size" |) + M.get_name (| globals, "push_data_size" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ )) |) in + let pc := BinOp.add + Constant.int 1 + Constant.int 1 in M.pure Constant.None_ - )) |) in - let pc := BinOp.add - Constant.int 1 - Constant.int 1 in - EndWhile. + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.get_name (| globals, "valid_jump_destinations" |) |) in diff --git a/CoqOfPython/ethereum/shanghai/vm/stack.v b/CoqOfPython/ethereum/shanghai/vm/stack.v index aa9f4c0..4ff4d79 100644 --- a/CoqOfPython/ethereum/shanghai/vm/stack.v +++ b/CoqOfPython/ethereum/shanghai/vm/stack.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.shanghai.vm.stack". Definition expr_1 : Value.t := Constant.str " @@ -17,19 +17,14 @@ Introduction Implementation of the stack operators for the EVM. ". -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". +Axiom typing_imports : + AreImported globals "typing" [ "List" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.shanghai.vm.exceptions. -Axiom ethereum_shanghai_vm_exceptions_StackOverflowError : - IsGlobalAlias globals ethereum.shanghai.vm.exceptions.globals "StackOverflowError". -Axiom ethereum_shanghai_vm_exceptions_StackUnderflowError : - IsGlobalAlias globals ethereum.shanghai.vm.exceptions.globals "StackUnderflowError". +Axiom ethereum_shanghai_vm_exceptions_imports : + AreImported globals "ethereum.shanghai.vm.exceptions" [ "StackOverflowError"; "StackUnderflowError" ]. Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -63,7 +58,7 @@ Definition pop : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "StackUnderflowError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "StackUnderflowError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -108,7 +103,7 @@ Definition push : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "StackOverflowError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "StackOverflowError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/spurious_dragon/__init__.v b/CoqOfPython/ethereum/spurious_dragon/__init__.v index 56d74fe..46bdc54 100644 --- a/CoqOfPython/ethereum/spurious_dragon/__init__.v +++ b/CoqOfPython/ethereum/spurious_dragon/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.spurious_dragon.__init__". Definition expr_1 : Value.t := Constant.str " @@ -11,9 +11,8 @@ chains, limits the maximum size of contract code, and enables the removal of empty accounts. ". -Require ethereum.fork_criteria. -Axiom ethereum_fork_criteria_ByBlockNumber : - IsGlobalAlias globals ethereum.fork_criteria.globals "ByBlockNumber". +Axiom ethereum_fork_criteria_imports : + AreImported globals "ethereum.fork_criteria" [ "ByBlockNumber" ]. Definition FORK_CRITERIA : Value.t := M.run ltac:(M.monadic ( M.call (| diff --git a/CoqOfPython/ethereum/spurious_dragon/blocks.v b/CoqOfPython/ethereum/spurious_dragon/blocks.v index f0b2003..fe188c1 100644 --- a/CoqOfPython/ethereum/spurious_dragon/blocks.v +++ b/CoqOfPython/ethereum/spurious_dragon/blocks.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.spurious_dragon.blocks". Definition expr_1 : Value.t := Constant.str " @@ -14,43 +14,23 @@ history of all state transitions that have happened since the genesis of the chain. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes8 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes8". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". - -Require ethereum.spurious_dragon.fork_types. -Axiom ethereum_spurious_dragon_fork_types_Address : - IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "Address". -Axiom ethereum_spurious_dragon_fork_types_Bloom : - IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "Bloom". -Axiom ethereum_spurious_dragon_fork_types_Root : - IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "Root". - -Require ethereum.spurious_dragon.transactions. -Axiom ethereum_spurious_dragon_transactions_Transaction : - IsGlobalAlias globals ethereum.spurious_dragon.transactions.globals "Transaction". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes8"; "Bytes32"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. + +Axiom ethereum_spurious_dragon_fork_types_imports : + AreImported globals "ethereum.spurious_dragon.fork_types" [ "Address"; "Bloom"; "Root" ]. + +Axiom ethereum_spurious_dragon_transactions_imports : + AreImported globals "ethereum.spurious_dragon.transactions" [ "Transaction" ]. Definition Header : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/spurious_dragon/bloom.v b/CoqOfPython/ethereum/spurious_dragon/bloom.v index ba1a08f..6a34d82 100644 --- a/CoqOfPython/ethereum/spurious_dragon/bloom.v +++ b/CoqOfPython/ethereum/spurious_dragon/bloom.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.spurious_dragon.bloom". Definition expr_1 : Value.t := Constant.str " @@ -21,25 +21,20 @@ for efficient searching of logs by address and/or topic, by rapidly eliminating blocks and receipts from their search. ". -Require typing. -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_imports : + AreImported globals "typing" [ "Tuple" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. -Require ethereum.spurious_dragon.blocks. -Axiom ethereum_spurious_dragon_blocks_Log : - IsGlobalAlias globals ethereum.spurious_dragon.blocks.globals "Log". +Axiom ethereum_spurious_dragon_blocks_imports : + AreImported globals "ethereum.spurious_dragon.blocks" [ "Log" ]. -Require ethereum.spurious_dragon.fork_types. -Axiom ethereum_spurious_dragon_fork_types_Bloom : - IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "Bloom". +Axiom ethereum_spurious_dragon_fork_types_imports : + AreImported globals "ethereum.spurious_dragon.fork_types" [ "Bloom" ]. Definition add_to_bloom : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -66,50 +61,70 @@ Definition add_to_bloom : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "idx" |) in make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ] do - let bit_to_set := - BinOp.bit_and (| - M.call (| - M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "hash" |), M.slice (| M.get_name (| globals, "idx" |), BinOp.add (| - M.get_name (| globals, "idx" |), - Constant.int 2 - |) |) |) - ], - make_dict [] - |), - Constant.int 2047 - |) in - let bit_index := - BinOp.sub (| - Constant.int 2047, - M.get_name (| globals, "bit_to_set" |) - |) in - let byte_index := - BinOp.floor_div (| - M.get_name (| globals, "bit_index" |), - Constant.int 8 - |) in - let bit_value := - BinOp.l_shift (| - Constant.int 1, - BinOp.sub (| - Constant.int 7, - BinOp.mod_ (| + let _ := + M.for_ (| + M.get_name (| globals, "idx" |), + make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ], + ltac:(M.monadic ( + let bit_to_set := + BinOp.bit_and (| + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.slice (| + M.get_name (| globals, "hash" |), + M.get_name (| globals, "idx" |), + BinOp.add (| + M.get_name (| globals, "idx" |), + Constant.int 2 + |), + Constant.None_ + |) + ], + make_dict [] + |), + Constant.int 2047 + |) in + let bit_index := + BinOp.sub (| + Constant.int 2047, + M.get_name (| globals, "bit_to_set" |) + |) in + let byte_index := + BinOp.floor_div (| M.get_name (| globals, "bit_index" |), Constant.int 8 + |) in + let bit_value := + BinOp.l_shift (| + Constant.int 1, + BinOp.sub (| + Constant.int 7, + BinOp.mod_ (| + M.get_name (| globals, "bit_index" |), + Constant.int 8 + |) + |) + |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "bloom" |), + M.get_name (| globals, "byte_index" |) + |), + BinOp.bit_or (| + M.get_subscript (| + M.get_name (| globals, "bloom" |), + M.get_name (| globals, "byte_index" |) + |), + M.get_name (| globals, "bit_value" |) |) - |) - |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), - BinOp.bit_or (| - M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), - M.get_name (| globals, "bit_value" |) - |) - |) in - EndFor. + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_)). Definition logs_bloom : Value.t -> Value.t -> M := @@ -132,8 +147,12 @@ Definition logs_bloom : Value.t -> Value.t -> M := the caller address and the log topics. " in (* At stmt: unsupported node type: AnnAssign *) - For M.get_name (| globals, "log" |) in M.get_name (| globals, "logs" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "log" |), + M.get_name (| globals, "logs" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "add_to_bloom" |), make_list [ M.get_name (| globals, "bloom" |); @@ -141,8 +160,12 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "topic" |) in M.get_field (| M.get_name (| globals, "log" |), "topics" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "topic" |), + M.get_field (| M.get_name (| globals, "log" |), "topics" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "add_to_bloom" |), make_list [ M.get_name (| globals, "bloom" |); @@ -150,8 +173,18 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Bloom" |), diff --git a/CoqOfPython/ethereum/spurious_dragon/fork.v b/CoqOfPython/ethereum/spurious_dragon/fork.v index be54a14..19a0751 100644 --- a/CoqOfPython/ethereum/spurious_dragon/fork.v +++ b/CoqOfPython/ethereum/spurious_dragon/fork.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.spurious_dragon.fork". Definition expr_1 : Value.t := Constant.str " @@ -17,141 +17,62 @@ Introduction Entry point for the Ethereum specification. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". - -Require ethereum.crypto.elliptic_curve. -Axiom ethereum_crypto_elliptic_curve_SECP256K1N : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". -Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.ethash. -Axiom ethereum_ethash_dataset_size : - IsGlobalAlias globals ethereum.ethash.globals "dataset_size". -Axiom ethereum_ethash_generate_cache : - IsGlobalAlias globals ethereum.ethash.globals "generate_cache". -Axiom ethereum_ethash_hashimoto_light : - IsGlobalAlias globals ethereum.ethash.globals "hashimoto_light". - -Require ethereum.exceptions. -Axiom ethereum_exceptions_InvalidBlock : - IsGlobalAlias globals ethereum.exceptions.globals "InvalidBlock". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U64 : - IsGlobalAlias globals ethereum.base_types.globals "U64". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_U256_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.spurious_dragon.__init__. -Axiom ethereum_spurious_dragon___init___vm : - IsGlobalAlias globals ethereum.spurious_dragon.__init__.globals "vm". - -Require ethereum.spurious_dragon.blocks. -Axiom ethereum_spurious_dragon_blocks_Block : - IsGlobalAlias globals ethereum.spurious_dragon.blocks.globals "Block". -Axiom ethereum_spurious_dragon_blocks_Header : - IsGlobalAlias globals ethereum.spurious_dragon.blocks.globals "Header". -Axiom ethereum_spurious_dragon_blocks_Log : - IsGlobalAlias globals ethereum.spurious_dragon.blocks.globals "Log". -Axiom ethereum_spurious_dragon_blocks_Receipt : - IsGlobalAlias globals ethereum.spurious_dragon.blocks.globals "Receipt". - -Require ethereum.spurious_dragon.bloom. -Axiom ethereum_spurious_dragon_bloom_logs_bloom : - IsGlobalAlias globals ethereum.spurious_dragon.bloom.globals "logs_bloom". - -Require ethereum.spurious_dragon.fork_types. -Axiom ethereum_spurious_dragon_fork_types_Address : - IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "Address". -Axiom ethereum_spurious_dragon_fork_types_Bloom : - IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "Bloom". -Axiom ethereum_spurious_dragon_fork_types_Root : - IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "Root". - -Require ethereum.spurious_dragon.state. -Axiom ethereum_spurious_dragon_state_State : - IsGlobalAlias globals ethereum.spurious_dragon.state.globals "State". -Axiom ethereum_spurious_dragon_state_account_exists_and_is_empty : - IsGlobalAlias globals ethereum.spurious_dragon.state.globals "account_exists_and_is_empty". -Axiom ethereum_spurious_dragon_state_create_ether : - IsGlobalAlias globals ethereum.spurious_dragon.state.globals "create_ether". -Axiom ethereum_spurious_dragon_state_destroy_account : - IsGlobalAlias globals ethereum.spurious_dragon.state.globals "destroy_account". -Axiom ethereum_spurious_dragon_state_get_account : - IsGlobalAlias globals ethereum.spurious_dragon.state.globals "get_account". -Axiom ethereum_spurious_dragon_state_increment_nonce : - IsGlobalAlias globals ethereum.spurious_dragon.state.globals "increment_nonce". -Axiom ethereum_spurious_dragon_state_set_account_balance : - IsGlobalAlias globals ethereum.spurious_dragon.state.globals "set_account_balance". -Axiom ethereum_spurious_dragon_state_state_root : - IsGlobalAlias globals ethereum.spurious_dragon.state.globals "state_root". - -Require ethereum.spurious_dragon.transactions. -Axiom ethereum_spurious_dragon_transactions_TX_BASE_COST : - IsGlobalAlias globals ethereum.spurious_dragon.transactions.globals "TX_BASE_COST". -Axiom ethereum_spurious_dragon_transactions_TX_CREATE_COST : - IsGlobalAlias globals ethereum.spurious_dragon.transactions.globals "TX_CREATE_COST". -Axiom ethereum_spurious_dragon_transactions_TX_DATA_COST_PER_NON_ZERO : - IsGlobalAlias globals ethereum.spurious_dragon.transactions.globals "TX_DATA_COST_PER_NON_ZERO". -Axiom ethereum_spurious_dragon_transactions_TX_DATA_COST_PER_ZERO : - IsGlobalAlias globals ethereum.spurious_dragon.transactions.globals "TX_DATA_COST_PER_ZERO". -Axiom ethereum_spurious_dragon_transactions_Transaction : - IsGlobalAlias globals ethereum.spurious_dragon.transactions.globals "Transaction". - -Require ethereum.spurious_dragon.trie. -Axiom ethereum_spurious_dragon_trie_Trie : - IsGlobalAlias globals ethereum.spurious_dragon.trie.globals "Trie". -Axiom ethereum_spurious_dragon_trie_root : - IsGlobalAlias globals ethereum.spurious_dragon.trie.globals "root". -Axiom ethereum_spurious_dragon_trie_trie_set : - IsGlobalAlias globals ethereum.spurious_dragon.trie.globals "trie_set". - -Require ethereum.spurious_dragon.utils.message. -Axiom ethereum_spurious_dragon_utils_message_prepare_message : - IsGlobalAlias globals ethereum.spurious_dragon.utils.message.globals "prepare_message". - -Require ethereum.spurious_dragon.vm.interpreter. -Axiom ethereum_spurious_dragon_vm_interpreter_process_message_call : - IsGlobalAlias globals ethereum.spurious_dragon.vm.interpreter.globals "process_message_call". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Bytes0" ]. + +Axiom ethereum_crypto_elliptic_curve_imports : + AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. + +Axiom ethereum_ethash_imports : + AreImported globals "ethereum.ethash" [ "dataset_size"; "generate_cache"; "hashimoto_light" ]. + +Axiom ethereum_exceptions_imports : + AreImported globals "ethereum.exceptions" [ "InvalidBlock" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U64"; "U256"; "U256_CEIL_VALUE"; "Bytes"; "Bytes32"; "Uint" ]. + +Axiom ethereum_spurious_dragon_imports : + AreImported globals "ethereum.spurious_dragon" [ "vm" ]. + +Axiom ethereum_spurious_dragon_blocks_imports : + AreImported globals "ethereum.spurious_dragon.blocks" [ "Block"; "Header"; "Log"; "Receipt" ]. + +Axiom ethereum_spurious_dragon_bloom_imports : + AreImported globals "ethereum.spurious_dragon.bloom" [ "logs_bloom" ]. + +Axiom ethereum_spurious_dragon_fork_types_imports : + AreImported globals "ethereum.spurious_dragon.fork_types" [ "Address"; "Bloom"; "Root" ]. + +Axiom ethereum_spurious_dragon_state_imports : + AreImported globals "ethereum.spurious_dragon.state" [ "State"; "account_exists_and_is_empty"; "create_ether"; "destroy_account"; "get_account"; "increment_nonce"; "set_account_balance"; "state_root" ]. + +Axiom ethereum_spurious_dragon_transactions_imports : + AreImported globals "ethereum.spurious_dragon.transactions" [ "TX_BASE_COST"; "TX_CREATE_COST"; "TX_DATA_COST_PER_NON_ZERO"; "TX_DATA_COST_PER_ZERO"; "Transaction" ]. + +Axiom ethereum_spurious_dragon_trie_imports : + AreImported globals "ethereum.spurious_dragon.trie" [ "Trie"; "root"; "trie_set" ]. + +Axiom ethereum_spurious_dragon_utils_message_imports : + AreImported globals "ethereum.spurious_dragon.utils.message" [ "prepare_message" ]. + +Axiom ethereum_spurious_dragon_vm_interpreter_imports : + AreImported globals "ethereum.spurious_dragon.vm.interpreter" [ "process_message_call" ]. Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -250,7 +171,12 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := Hashes of the recent 256 blocks in order of increasing block number. " in let recent_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) in + M.slice (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| Constant.int 255 |), + Constant.None_, + Constant.None_ + |) in let _ := (* if *) M.if_then_else (| @@ -276,17 +202,26 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := )) |) in let recent_block_hashes := make_list [] in - For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_blocks" |) do - let prev_block_hash := - M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "block" |), + M.get_name (| globals, "recent_blocks" |), + ltac:(M.monadic ( + let prev_block_hash := + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in + let _ := M.call (| M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), make_list [ M.get_name (| globals, "prev_block_hash" |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let most_recent_block_hash := M.call (| M.get_name (| globals, "keccak256" |), @@ -294,7 +229,10 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), make_list [ - M.get_field (| M.get_subscript (| M.get_name (| globals, "recent_blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) + M.get_field (| M.get_subscript (| + M.get_name (| globals, "recent_blocks" |), + UnOp.sub (| Constant.int 1 |) + |), "header" |) ], make_dict [] |) @@ -338,7 +276,10 @@ Definition state_transition : Value.t -> Value.t -> M := Block to apply to `chain`. " in let parent_header := - M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) in + M.get_field (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| Constant.int 1 |) + |), "header" |) in let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ @@ -458,7 +399,12 @@ Definition state_transition : Value.t -> Value.t -> M := ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) + M.slice (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| Constant.int 255 |), + Constant.None_, + Constant.None_ + |) |) in M.pure Constant.None_ (* else *) @@ -879,14 +825,18 @@ Definition apply_body : Value.t -> Value.t -> M := (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) - For make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "tx" |) ] in M.call (| - M.get_name (| globals, "enumerate" |), - make_list [ - M.get_name (| globals, "transactions" |) - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "tx" |) ], + M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "transactions" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ M.get_name (| globals, "transactions_trie" |); @@ -907,57 +857,57 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_address := - M.call (| - M.get_name (| globals, "check_transaction" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "gas_available" |); - M.get_name (| globals, "chain_id" |) - ], - make_dict [] - |) in - let env := - M.call (| - M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), - make_list [], - make_dict [] - |) in - let _ := M.assign (| - make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |) ], - M.call (| - M.get_name (| globals, "process_transaction" |), - make_list [ - M.get_name (| globals, "env" |); - M.get_name (| globals, "tx" |) - ], - make_dict [] - |) - |) in - let gas_available := BinOp.sub - M.get_name (| globals, "gas_used" |) - M.get_name (| globals, "gas_used" |) in - let receipt := - M.call (| - M.get_name (| globals, "make_receipt" |), - make_list [ - M.get_name (| globals, "tx" |); + let sender_address := M.call (| - M.get_name (| globals, "state_root" |), + M.get_name (| globals, "check_transaction" |), make_list [ - M.get_name (| globals, "state" |) + M.get_name (| globals, "tx" |); + M.get_name (| globals, "gas_available" |); + M.get_name (| globals, "chain_id" |) ], make_dict [] - |); - BinOp.sub (| - M.get_name (| globals, "block_gas_limit" |), - M.get_name (| globals, "gas_available" |) - |); - M.get_name (| globals, "logs" |) - ], - make_dict [] - |) in - let _ := M.call (| + |) in + let env := + M.call (| + M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |) ], + M.call (| + M.get_name (| globals, "process_transaction" |), + make_list [ + M.get_name (| globals, "env" |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) in + let gas_available := BinOp.sub + M.get_name (| globals, "gas_used" |) + M.get_name (| globals, "gas_used" |) in + let receipt := + M.call (| + M.get_name (| globals, "make_receipt" |), + make_list [ + M.get_name (| globals, "tx" |); + M.call (| + M.get_name (| globals, "state_root" |), + make_list [ + M.get_name (| globals, "state" |) + ], + make_dict [] + |); + BinOp.sub (| + M.get_name (| globals, "block_gas_limit" |), + M.get_name (| globals, "gas_available" |) + |); + M.get_name (| globals, "logs" |) + ], + make_dict [] + |) in + let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ M.get_name (| globals, "receipts_trie" |); @@ -978,10 +928,15 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_logs := BinOp.add - M.get_name (| globals, "logs" |) - M.get_name (| globals, "logs" |) in - EndFor. + let block_logs := BinOp.add + M.get_name (| globals, "logs" |) + M.get_name (| globals, "logs" |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.call (| M.get_name (| globals, "pay_rewards" |), make_list [ @@ -1110,8 +1065,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "ommer" |), + M.get_name (| globals, "ommers" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ BoolOp.and (| @@ -1130,15 +1089,18 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_parent_header := - M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), BinOp.sub (| - UnOp.sub (| BinOp.sub (| - M.get_field (| M.get_name (| globals, "block_header" |), "number" |), - M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) |), - Constant.int 1 - |) |), "header" |) in - let _ := M.call (| + let ommer_parent_header := + M.get_field (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + BinOp.sub (| + UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) |), + Constant.int 1 + |) + |), "header" |) in + let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ M.get_name (| globals, "ommer" |); @@ -1146,7 +1108,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1196,33 +1163,54 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let recent_canonical_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| BinOp.add (| - M.get_name (| globals, "MAX_OMMER_DEPTH" |), - Constant.int 1 - |) |), Constant.None_ |) |) in + M.slice (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| BinOp.add (| + M.get_name (| globals, "MAX_OMMER_DEPTH" |), + Constant.int 1 + |) |), + Constant.None_, + Constant.None_ + |) in let recent_canonical_block_hashes := Constant.str "(* At expr: unsupported node type: SetComp *)" in (* At stmt: unsupported node type: AnnAssign *) - For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_canonical_blocks" |) do - let recent_ommers_hashes := + let _ := + M.for_ (| + M.get_name (| globals, "block" |), + M.get_name (| globals, "recent_canonical_blocks" |), + ltac:(M.monadic ( + let recent_ommers_hashes := + M.call (| + M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), + make_list [ + Constant.str "(* At expr: unsupported node type: SetComp *)" + ], + make_dict [] + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "ommer_index" |); M.get_name (| globals, "ommer" |) ], M.call (| - M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), - make_list [ - Constant.str "(* At expr: unsupported node type: SetComp *)" - ], - make_dict [] - |) in - EndFor. - For make_tuple [ M.get_name (| globals, "ommer_index" |); M.get_name (| globals, "ommer" |) ] in M.call (| - M.get_name (| globals, "enumerate" |), - make_list [ - M.get_name (| globals, "ommers" |) - ], - make_dict [] - |) do - let ommer_hash := - M.get_subscript (| M.get_name (| globals, "ommers_hashes" |), M.get_name (| globals, "ommer_index" |) |) in - let _ := M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let ommer_hash := + M.get_subscript (| + M.get_name (| globals, "ommers_hashes" |), + M.get_name (| globals, "ommer_index" |) + |) in + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_eq (| @@ -1233,7 +1221,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_in (| @@ -1244,7 +1232,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_in (| @@ -1255,12 +1243,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_age := - BinOp.sub (| - M.get_field (| M.get_name (| globals, "block_header" |), "number" |), - M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) in - let _ := M.call (| + let ommer_age := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) in + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ BoolOp.and (| @@ -1279,10 +1267,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.in (| + Compare.in_ (| M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), M.get_name (| globals, "recent_canonical_block_hashes" |) |); @@ -1290,7 +1278,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_eq (| @@ -1301,7 +1289,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_)). Definition pay_rewards : Value.t -> Value.t -> M := @@ -1358,30 +1351,34 @@ Definition pay_rewards : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do - let ommer_age := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - BinOp.sub (| - M.get_name (| globals, "block_number" |), - M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) - ], - make_dict [] - |) in - let ommer_miner_reward := - BinOp.floor_div (| - BinOp.mult (| - BinOp.sub (| - Constant.int 8, - M.get_name (| globals, "ommer_age" |) - |), - M.get_name (| globals, "BLOCK_REWARD" |) - |), - Constant.int 8 - |) in - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "ommer" |), + M.get_name (| globals, "ommers" |), + ltac:(M.monadic ( + let ommer_age := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "block_number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) + ], + make_dict [] + |) in + let ommer_miner_reward := + BinOp.floor_div (| + BinOp.mult (| + BinOp.sub (| + Constant.int 8, + M.get_name (| globals, "ommer_age" |) + |), + M.get_name (| globals, "BLOCK_REWARD" |) + |), + Constant.int 8 + |) in + let _ := M.call (| M.get_name (| globals, "create_ether" |), make_list [ M.get_name (| globals, "state" |); @@ -1390,7 +1387,12 @@ Definition pay_rewards : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_)). Definition process_transaction : Value.t -> Value.t -> M := @@ -1670,8 +1672,12 @@ Definition process_transaction : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "accounts_to_delete" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "output" |), "accounts_to_delete" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "destroy_account" |), make_list [ M.get_field (| M.get_name (| globals, "env" |), "state" |); @@ -1679,22 +1685,31 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. - For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "touched_accounts" |) do - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "account_exists_and_is_empty" |), - make_list [ - M.get_field (| M.get_name (| globals, "env" |), "state" |); - M.get_name (| globals, "address" |) - ], - make_dict [] - |), - (* then *) + M.pure Constant.None_ + )), ltac:(M.monadic ( - let _ := M.call (| + M.pure Constant.None_ + )) + |) in + let _ := + M.for_ (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "output" |), "touched_accounts" |), + ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "account_exists_and_is_empty" |), + make_list [ + M.get_field (| M.get_name (| globals, "env" |), "state" |); + M.get_name (| globals, "address" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "destroy_account" |), make_list [ M.get_field (| M.get_name (| globals, "env" |), "state" |); @@ -1702,12 +1717,17 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := M.return_ (| make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |) ] |) in @@ -1795,28 +1815,37 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := " in let data_cost := Constant.int 0 in - For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "byte" |), - Constant.int 0 - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "byte" |), + M.get_field (| M.get_name (| globals, "tx" |), "data" |), ltac:(M.monadic ( - let data_cost := BinOp.add - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "byte" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let data_cost := BinOp.add - M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := (* if *) M.if_then_else (| @@ -2031,13 +2060,18 @@ Definition recover_sender : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "Address" |), make_list [ - M.get_subscript (| M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "public_key" |) - ], - make_dict [] - |), M.slice (| Constant.int 12, Constant.int 32 |) |) + M.slice (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), + Constant.int 12, + Constant.int 32, + Constant.None_ + |) ], make_dict [] |) diff --git a/CoqOfPython/ethereum/spurious_dragon/fork_types.v b/CoqOfPython/ethereum/spurious_dragon/fork_types.v index cc8e4a1..2016387 100644 --- a/CoqOfPython/ethereum/spurious_dragon/fork_types.v +++ b/CoqOfPython/ethereum/spurious_dragon/fork_types.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.spurious_dragon.fork_types". Definition expr_1 : Value.t := Constant.str " @@ -17,33 +17,17 @@ Introduction Types re-used throughout the specification, which are specific to Ethereum. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes20 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes20". -Axiom ethereum_base_types_Bytes256 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes20"; "Bytes256"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) diff --git a/CoqOfPython/ethereum/spurious_dragon/state.v b/CoqOfPython/ethereum/spurious_dragon/state.v index 3a25070..088ce84 100644 --- a/CoqOfPython/ethereum/spurious_dragon/state.v +++ b/CoqOfPython/ethereum/spurious_dragon/state.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.spurious_dragon.state". Definition expr_1 : Value.t := Constant.str " @@ -22,61 +22,23 @@ There is a distinction between an account that does not exist and `EMPTY_ACCOUNT`. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". -Axiom dataclasses_field : - IsGlobalAlias globals dataclasses.globals "field". - -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_modify : - IsGlobalAlias globals ethereum.base_types.globals "modify". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.spurious_dragon.fork_types. -Axiom ethereum_spurious_dragon_fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "EMPTY_ACCOUNT". -Axiom ethereum_spurious_dragon_fork_types_Account : - IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "Account". -Axiom ethereum_spurious_dragon_fork_types_Address : - IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "Address". -Axiom ethereum_spurious_dragon_fork_types_Root : - IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "Root". - -Require ethereum.spurious_dragon.trie. -Axiom ethereum_spurious_dragon_trie_EMPTY_TRIE_ROOT : - IsGlobalAlias globals ethereum.spurious_dragon.trie.globals "EMPTY_TRIE_ROOT". -Axiom ethereum_spurious_dragon_trie_Trie : - IsGlobalAlias globals ethereum.spurious_dragon.trie.globals "Trie". -Axiom ethereum_spurious_dragon_trie_copy_trie : - IsGlobalAlias globals ethereum.spurious_dragon.trie.globals "copy_trie". -Axiom ethereum_spurious_dragon_trie_root : - IsGlobalAlias globals ethereum.spurious_dragon.trie.globals "root". -Axiom ethereum_spurious_dragon_trie_trie_get : - IsGlobalAlias globals ethereum.spurious_dragon.trie.globals "trie_get". -Axiom ethereum_spurious_dragon_trie_trie_set : - IsGlobalAlias globals ethereum.spurious_dragon.trie.globals "trie_set". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass"; "field" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict"; "List"; "Optional"; "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "modify" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_spurious_dragon_fork_types_imports : + AreImported globals "ethereum.spurious_dragon.fork_types" [ "EMPTY_ACCOUNT"; "Account"; "Address"; "Root" ]. + +Axiom ethereum_spurious_dragon_trie_imports : + AreImported globals "ethereum.spurious_dragon.trie" [ "EMPTY_TRIE_ROOT"; "Trie"; "copy_trie"; "root"; "trie_get"; "trie_set" ]. Definition State : Value.t := builtins.make_klass @@ -338,13 +300,16 @@ Definition destroy_storage : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -479,7 +444,10 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), + M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |), M.get_name (| globals, "trie" |) |) in M.pure Constant.None_ @@ -505,7 +473,10 @@ Definition set_storage : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -535,7 +506,7 @@ Definition storage_root : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), @@ -545,7 +516,10 @@ Definition storage_root : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "root" |), make_list [ - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) + M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |) ], make_dict [] |) diff --git a/CoqOfPython/ethereum/spurious_dragon/transactions.v b/CoqOfPython/ethereum/spurious_dragon/transactions.v index f6ba300..e1289b5 100644 --- a/CoqOfPython/ethereum/spurious_dragon/transactions.v +++ b/CoqOfPython/ethereum/spurious_dragon/transactions.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.spurious_dragon.transactions". Definition expr_1 : Value.t := Constant.str " @@ -9,29 +9,17 @@ submitted to be executed. If Ethereum is viewed as a state machine, transactions are the events that move between states. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.spurious_dragon.fork_types. -Axiom ethereum_spurious_dragon_fork_types_Address : - IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "Address". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Union" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_spurious_dragon_fork_types_imports : + AreImported globals "ethereum.spurious_dragon.fork_types" [ "Address" ]. Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( Constant.int 21000 diff --git a/CoqOfPython/ethereum/spurious_dragon/trie.v b/CoqOfPython/ethereum/spurious_dragon/trie.v index 1e2dee1..dae0e12 100644 --- a/CoqOfPython/ethereum/spurious_dragon/trie.v +++ b/CoqOfPython/ethereum/spurious_dragon/trie.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.spurious_dragon.trie". Definition expr_1 : Value.t := Constant.str " @@ -20,83 +20,38 @@ The state trie is the structure responsible for storing (* At top_level_stmt: unsupported node type: Import *) -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". -Axiom dataclasses_field : - IsGlobalAlias globals dataclasses.globals "field". - -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". -Axiom typing_Generic : - IsGlobalAlias globals typing.globals "Generic". -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Mapping : - IsGlobalAlias globals typing.globals "Mapping". -Axiom typing_MutableMapping : - IsGlobalAlias globals typing.globals "MutableMapping". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Sequence : - IsGlobalAlias globals typing.globals "Sequence". -Axiom typing_TypeVar : - IsGlobalAlias globals typing.globals "TypeVar". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". -Axiom typing_cast : - IsGlobalAlias globals typing.globals "cast". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.tangerine_whistle.__init__. -Axiom ethereum_tangerine_whistle___init___trie : - IsGlobalAlias globals ethereum.tangerine_whistle.__init__.globals "trie". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.utils.hexadecimal. -Axiom ethereum_utils_hexadecimal_hex_to_bytes : - IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.spurious_dragon.blocks. -Axiom ethereum_spurious_dragon_blocks_Receipt : - IsGlobalAlias globals ethereum.spurious_dragon.blocks.globals "Receipt". - -Require ethereum.spurious_dragon.fork_types. -Axiom ethereum_spurious_dragon_fork_types_Account : - IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "Account". -Axiom ethereum_spurious_dragon_fork_types_Address : - IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "Address". -Axiom ethereum_spurious_dragon_fork_types_Root : - IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "Root". -Axiom ethereum_spurious_dragon_fork_types_encode_account : - IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "encode_account". - -Require ethereum.spurious_dragon.transactions. -Axiom ethereum_spurious_dragon_transactions_Transaction : - IsGlobalAlias globals ethereum.spurious_dragon.transactions.globals "Transaction". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass"; "field" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict"; "Generic"; "List"; "Mapping"; "MutableMapping"; "Optional"; "Sequence"; "TypeVar"; "Union"; "cast" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. + +Axiom ethereum_tangerine_whistle_imports : + AreImported globals "ethereum.tangerine_whistle" [ "trie" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_utils_hexadecimal_imports : + AreImported globals "ethereum.utils.hexadecimal" [ "hex_to_bytes" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_spurious_dragon_blocks_imports : + AreImported globals "ethereum.spurious_dragon.blocks" [ "Receipt" ]. + +Axiom ethereum_spurious_dragon_fork_types_imports : + AreImported globals "ethereum.spurious_dragon.fork_types" [ "Account"; "Address"; "Root"; "encode_account" ]. + +Axiom ethereum_spurious_dragon_transactions_imports : + AreImported globals "ethereum.spurious_dragon.transactions" [ "Transaction" ]. Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -115,7 +70,10 @@ Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( )). Definition Node : Value.t := M.run ltac:(M.monadic ( - M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Bytes" |); M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |); Constant.None_ ] |) + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Bytes" |); M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |); Constant.None_ ] + |) )). Definition K : Value.t := M.run ltac:(M.monadic ( @@ -133,11 +91,23 @@ Definition V : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "TypeVar" |), make_list [ Constant.str "V"; - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Account" |) |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Bytes" |) |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Account" |) + |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Bytes" |) + |); M.get_name (| globals, "Bytes" |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Transaction" |) |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Receipt" |) |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Transaction" |) + |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Receipt" |) + |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |) ], @@ -176,7 +146,10 @@ Definition BranchNode : Value.t := ]. Definition InternalNode : Value.t := M.run ltac:(M.monadic ( - M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LeafNode" |); M.get_name (| globals, "ExtensionNode" |); M.get_name (| globals, "BranchNode" |) ] |) + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "LeafNode" |); M.get_name (| globals, "ExtensionNode" |); M.get_name (| globals, "BranchNode" |) ] + |) )). Definition encode_internal_node : Value.t -> Value.t -> M := @@ -288,7 +261,7 @@ Definition encode_internal_node : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "(* At expr: unsupported node type: JoinedStr *)" @@ -528,13 +501,16 @@ Definition trie_set : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "key" |), M.get_field (| M.get_name (| globals, "trie" |), "_data" |) |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + M.get_name (| globals, "key" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -544,7 +520,10 @@ Definition trie_set : Value.t -> Value.t -> M := (* else *) )), ltac:(M.monadic ( let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), + M.get_subscript (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + M.get_name (| globals, "key" |) + |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_ @@ -589,51 +568,66 @@ Definition common_prefix_length : Value.t -> Value.t -> M := let _ := Constant.str " Find the longest common prefix of two sequences. " in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "a" |) - ], - make_dict [] - |) - ], - make_dict [] - |) do - let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| - M.get_name (| globals, "i" |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "b" |) - ], - make_dict [] - |) - |), - ltac:(M.monadic ( - Compare.not_eq (| - M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), - M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) - |) - )) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + ], + make_dict [] + |), ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "i" |) - |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_subscript (| + M.get_name (| globals, "a" |), + M.get_name (| globals, "i" |) + |), + M.get_subscript (| + M.get_name (| globals, "b" |), + M.get_name (| globals, "i" |) + |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "len" |), @@ -718,38 +712,53 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 0; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |); - Constant.int 2 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ BinOp.add (| BinOp.mult (| Constant.int 16, - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "i" |) + |) |), - M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) + |) |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -767,43 +776,61 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := Constant.int 1 |) |), - M.get_subscript (| M.get_name (| globals, "x" |), Constant.int 0 |) + M.get_subscript (| + M.get_name (| globals, "x" |), + Constant.int 0 + |) |) ], make_dict [] |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 1; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |); - Constant.int 2 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 1; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ BinOp.add (| BinOp.mult (| Constant.int 16, - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "i" |) + |) |), - M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) + |) |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -850,40 +877,55 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := ], make_dict [] |) in - For make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ] in M.call (| - M.get_name (| globals, "enumerate" |), - make_list [ - M.get_name (| globals, "bytes_" |) - ], - make_dict [] - |) do - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.mult (| - M.get_name (| globals, "byte_index" |), - Constant.int 2 - |) |), - BinOp.r_shift (| - BinOp.bit_and (| - M.get_name (| globals, "byte" |), - Constant.int 240 - |), - Constant.int 4 - |) - |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "byte_index" |), - Constant.int 2 - |), - Constant.int 1 - |) |), - BinOp.bit_and (| - M.get_name (| globals, "byte" |), - Constant.int 15 - |) - |) in - EndFor. + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ], + M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "bytes_" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "nibble_list" |), + BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |) + |), + BinOp.r_shift (| + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 240 + |), + Constant.int 4 + |) + |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "nibble_list" |), + BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |), + Constant.int 1 + |) + |), + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 15 + |) + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Bytes" |), @@ -916,65 +958,69 @@ Definition _prepare_trie : Value.t -> Value.t -> M := Object with keys mapped to nibble-byte form. " in (* At stmt: unsupported node type: AnnAssign *) - For make_tuple [ M.get_name (| globals, "preimage" |); M.get_name (| globals, "value" |) ] in M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "items" |), - make_list [], - make_dict [] - |) do - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "value" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "preimage" |); M.get_name (| globals, "value" |) ], + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "items" |), + make_list [], + make_dict [] + |), ltac:(M.monadic ( - let _ := M.assert (| Compare.is_not (| + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in - let address := - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in - let encoded_value := - M.call (| - M.get_name (| globals, "encode_node" |), - make_list [ - M.get_name (| globals, "value" |); + let address := M.call (| - M.get_name (| globals, "get_storage_root" |), + M.get_name (| globals, "Address" |), make_list [ - M.get_name (| globals, "address" |) + M.get_name (| globals, "preimage" |) ], make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let encoded_value := - M.call (| - M.get_name (| globals, "encode_node" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - )) |) in - let _ := M.call (| + |) in + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |); + M.call (| + M.get_name (| globals, "get_storage_root" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_eq (| @@ -986,38 +1032,46 @@ Definition _prepare_trie : Value.t -> Value.t -> M := make_dict [] |) in (* At stmt: unsupported node type: AnnAssign *) - let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "trie" |), "secured" |), - (* then *) - ltac:(M.monadic ( - let key := - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "trie" |), "secured" |), + (* then *) + ltac:(M.monadic ( + let key := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let key := + M.get_name (| globals, "preimage" |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "mapped" |), + M.call (| + M.get_name (| globals, "bytes_to_nibble_list" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |) + |), + M.get_name (| globals, "encoded_value" |) + |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let key := - M.get_name (| globals, "preimage" |) in + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "mapped" |), M.call (| - M.get_name (| globals, "bytes_to_nibble_list" |), - make_list [ - M.get_name (| globals, "key" |) - ], - make_dict [] - |) |), - M.get_name (| globals, "encoded_value" |) - |) in - EndFor. + )) + |) in let _ := M.return_ (| M.get_name (| globals, "mapped" |) |) in @@ -1210,8 +1264,16 @@ Definition patricialize : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "LeafNode" |), make_list [ - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |); - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) + M.slice (| + M.get_name (| globals, "arbitrary_key" |), + M.get_name (| globals, "level" |), + Constant.None_, + Constant.None_ + |); + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "arbitrary_key" |) + |) ], make_dict [] |) in @@ -1224,7 +1286,12 @@ Definition patricialize : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in let substring := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "arbitrary_key" |), + M.get_name (| globals, "level" |), + Constant.None_, + Constant.None_ + |) in let prefix_length := M.call (| M.get_name (| globals, "len" |), @@ -1233,39 +1300,53 @@ Definition patricialize : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do - let prefix_length := - M.call (| - M.get_name (| globals, "min" |), - make_list [ - M.get_name (| globals, "prefix_length" |); + let _ := + M.for_ (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "obj" |), + ltac:(M.monadic ( + let prefix_length := M.call (| - M.get_name (| globals, "common_prefix_length" |), + M.get_name (| globals, "min" |), make_list [ - M.get_name (| globals, "substring" |); - M.get_subscript (| M.get_name (| globals, "key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) + M.get_name (| globals, "prefix_length" |); + M.call (| + M.get_name (| globals, "common_prefix_length" |), + make_list [ + M.get_name (| globals, "substring" |); + M.slice (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "level" |), + Constant.None_, + Constant.None_ + |) + ], + make_dict [] + |) ], make_dict [] - |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "prefix_length" |), - Constant.int 0 - |), - (* then *) - ltac:(M.monadic ( - let _ := M.break (| |) in + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "prefix_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := (* if *) M.if_then_else (| @@ -1276,10 +1357,15 @@ Definition patricialize : Value.t -> Value.t -> M := (* then *) ltac:(M.monadic ( let prefix := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), BinOp.add (| + M.slice (| + M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |), - M.get_name (| globals, "prefix_length" |) - |) |) |) in + BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |), + Constant.None_ + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ExtensionNode" |), @@ -1312,70 +1398,106 @@ Definition patricialize : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) - For M.get_name (| globals, "_" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 16 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "_" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 16 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "branches" |), "append" |), make_list [ {} ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let value := Constant.bytes "" in - For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "key" |) - ], - make_dict [] - |), - M.get_name (| globals, "level" |) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "obj" |), ltac:(M.monadic ( let _ := (* if *) M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); - make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] - ], - make_dict [] + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |), + M.get_name (| globals, "level" |) |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "AssertionError" |)) |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "key" |) + |); + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "AssertionError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "key" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| + M.get_subscript (| + M.get_name (| globals, "branches" |), + M.get_subscript (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "level" |) + |) + |), + M.get_name (| globals, "key" |) + |), + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "key" |) + |) + |) in M.pure Constant.None_ )) |) in - let value := - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.assign (| - M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) - |) in + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "BranchNode" |), diff --git a/CoqOfPython/ethereum/spurious_dragon/utils/__init__.v b/CoqOfPython/ethereum/spurious_dragon/utils/__init__.v index 1baedea..05c126f 100644 --- a/CoqOfPython/ethereum/spurious_dragon/utils/__init__.v +++ b/CoqOfPython/ethereum/spurious_dragon/utils/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.spurious_dragon.utils.__init__". Definition expr_1 : Value.t := Constant.str " diff --git a/CoqOfPython/ethereum/spurious_dragon/utils/address.v b/CoqOfPython/ethereum/spurious_dragon/utils/address.v index 33ae415..0281007 100644 --- a/CoqOfPython/ethereum/spurious_dragon/utils/address.v +++ b/CoqOfPython/ethereum/spurious_dragon/utils/address.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.spurious_dragon.utils.address". Definition expr_1 : Value.t := Constant.str " @@ -18,31 +18,23 @@ Address specific functions used in this spurious dragon version of specification. ". -Require typing. -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". +Axiom typing_imports : + AreImported globals "typing" [ "Union" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_left_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. -Require ethereum.spurious_dragon.fork_types. -Axiom ethereum_spurious_dragon_fork_types_Address : - IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "Address". +Axiom ethereum_spurious_dragon_fork_types_imports : + AreImported globals "ethereum.spurious_dragon.fork_types" [ "Address" ]. Definition to_address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -64,11 +56,16 @@ Definition to_address : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "Address" |), make_list [ - M.get_subscript (| M.call (| - M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), - make_list [], - make_dict [] - |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) + M.slice (| + M.call (| + M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), + UnOp.sub (| Constant.int 20 |), + Constant.None_, + Constant.None_ + |) ], make_dict [] |) @@ -112,7 +109,12 @@ Definition compute_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "computed_address" |), + UnOp.sub (| Constant.int 20 |), + Constant.None_, + Constant.None_ + |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/spurious_dragon/utils/hexadecimal.v b/CoqOfPython/ethereum/spurious_dragon/utils/hexadecimal.v index f1b941c..0cd23a2 100644 --- a/CoqOfPython/ethereum/spurious_dragon/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/spurious_dragon/utils/hexadecimal.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.spurious_dragon.utils.hexadecimal". Definition expr_1 : Value.t := Constant.str " @@ -18,17 +18,11 @@ Hexadecimal utility functions used in this specification, specific to Spurious Dragon types. ". -Require ethereum.utils.hexadecimal. -Axiom ethereum_utils_hexadecimal_remove_hex_prefix : - IsGlobalAlias globals ethereum.utils.hexadecimal.globals "remove_hex_prefix". - -Require ethereum.spurious_dragon.fork_types. -Axiom ethereum_spurious_dragon_fork_types_Address : - IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "Address". -Axiom ethereum_spurious_dragon_fork_types_Bloom : - IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "Bloom". -Axiom ethereum_spurious_dragon_fork_types_Root : - IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "Root". +Axiom ethereum_utils_hexadecimal_imports : + AreImported globals "ethereum.utils.hexadecimal" [ "remove_hex_prefix" ]. + +Axiom ethereum_spurious_dragon_fork_types_imports : + AreImported globals "ethereum.spurious_dragon.fork_types" [ "Address"; "Bloom"; "Root" ]. Definition hex_to_root : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/spurious_dragon/utils/message.v b/CoqOfPython/ethereum/spurious_dragon/utils/message.v index 2cab620..a3cd59e 100644 --- a/CoqOfPython/ethereum/spurious_dragon/utils/message.v +++ b/CoqOfPython/ethereum/spurious_dragon/utils/message.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.spurious_dragon.utils.message". Definition expr_1 : Value.t := Constant.str " @@ -18,39 +18,23 @@ Message specific functions used in this spurious dragon version of specification. ". -Require typing. -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". +Axiom typing_imports : + AreImported globals "typing" [ "Optional"; "Union" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint" ]. -Require ethereum.spurious_dragon.fork_types. -Axiom ethereum_spurious_dragon_fork_types_Address : - IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "Address". +Axiom ethereum_spurious_dragon_fork_types_imports : + AreImported globals "ethereum.spurious_dragon.fork_types" [ "Address" ]. -Require ethereum.spurious_dragon.state. -Axiom ethereum_spurious_dragon_state_get_account : - IsGlobalAlias globals ethereum.spurious_dragon.state.globals "get_account". +Axiom ethereum_spurious_dragon_state_imports : + AreImported globals "ethereum.spurious_dragon.state" [ "get_account" ]. -Require ethereum.spurious_dragon.vm.__init__. -Axiom ethereum_spurious_dragon_vm___init___Environment : - IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "Environment". -Axiom ethereum_spurious_dragon_vm___init___Message : - IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "Message". +Axiom ethereum_spurious_dragon_vm_imports : + AreImported globals "ethereum.spurious_dragon.vm" [ "Environment"; "Message" ]. -Require ethereum.spurious_dragon.utils.address. -Axiom ethereum_spurious_dragon_utils_address_compute_contract_address : - IsGlobalAlias globals ethereum.spurious_dragon.utils.address.globals "compute_contract_address". +Axiom ethereum_spurious_dragon_utils_address_imports : + AreImported globals "ethereum.spurious_dragon.utils.address" [ "compute_contract_address" ]. Definition prepare_message : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -180,7 +164,7 @@ Definition prepare_message : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "Target must be address or empty bytes" diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/__init__.v b/CoqOfPython/ethereum/spurious_dragon/vm/__init__.v index d66c0b1..cff1138 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/__init__.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.spurious_dragon.vm.__init__". Definition expr_1 : Value.t := Constant.str " @@ -18,53 +18,29 @@ The abstract computer which runs the code stored in an `.fork_types.Account`. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". - -Require ethereum.spurious_dragon.blocks. -Axiom ethereum_spurious_dragon_blocks_Log : - IsGlobalAlias globals ethereum.spurious_dragon.blocks.globals "Log". - -Require ethereum.spurious_dragon.fork_types. -Axiom ethereum_spurious_dragon_fork_types_Address : - IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "Address". - -Require ethereum.spurious_dragon.state. -Axiom ethereum_spurious_dragon_state_State : - IsGlobalAlias globals ethereum.spurious_dragon.state.globals "State". -Axiom ethereum_spurious_dragon_state_account_exists_and_is_empty : - IsGlobalAlias globals ethereum.spurious_dragon.state.globals "account_exists_and_is_empty". - -Require ethereum.spurious_dragon.vm.precompiled_contracts.__init__. -Axiom ethereum_spurious_dragon_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : - IsGlobalAlias globals ethereum.spurious_dragon.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple"; "Union" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. + +Axiom ethereum_spurious_dragon_blocks_imports : + AreImported globals "ethereum.spurious_dragon.blocks" [ "Log" ]. + +Axiom ethereum_spurious_dragon_fork_types_imports : + AreImported globals "ethereum.spurious_dragon.fork_types" [ "Address" ]. + +Axiom ethereum_spurious_dragon_state_imports : + AreImported globals "ethereum.spurious_dragon.state" [ "State"; "account_exists_and_is_empty" ]. + +Axiom ethereum_spurious_dragon_vm_precompiled_contracts_imports : + AreImported globals "ethereum.spurious_dragon.vm.precompiled_contracts" [ "RIPEMD160_ADDRESS" ]. Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] @@ -185,7 +161,7 @@ Definition incorporate_child_on_error : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "RIPEMD160_ADDRESS" |), M.get_field (| M.get_name (| globals, "child_evm" |), "touched_accounts" |) |), diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/exceptions.v b/CoqOfPython/ethereum/spurious_dragon/vm/exceptions.v index 45435b3..aa6a22c 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/exceptions.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/exceptions.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.spurious_dragon.vm.exceptions". Definition expr_1 : Value.t := Constant.str " @@ -17,9 +17,8 @@ Introduction Exceptions which cause the EVM to halt exceptionally. ". -Require ethereum.exceptions. -Axiom ethereum_exceptions_EthereumException : - IsGlobalAlias globals ethereum.exceptions.globals "EthereumException". +Axiom ethereum_exceptions_imports : + AreImported globals "ethereum.exceptions" [ "EthereumException" ]. Definition ExceptionalHalt : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/gas.v b/CoqOfPython/ethereum/spurious_dragon/vm/gas.v index 6923f48..7a7bcbe 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/gas.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/gas.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.spurious_dragon.vm.gas". Definition expr_1 : Value.t := Constant.str " @@ -17,39 +17,26 @@ Introduction EVM gas constants and calculators. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Tuple" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. -Require ethereum.trace. -Axiom ethereum_trace_GasAndRefund : - IsGlobalAlias globals ethereum.trace.globals "GasAndRefund". -Axiom ethereum_trace_evm_trace : - IsGlobalAlias globals ethereum.trace.globals "evm_trace". +Axiom ethereum_trace_imports : + AreImported globals "ethereum.trace" [ "GasAndRefund"; "evm_trace" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.spurious_dragon.vm.__init__. -Axiom ethereum_spurious_dragon_vm___init___Evm : - IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "Evm". +Axiom ethereum_spurious_dragon_vm_imports : + AreImported globals "ethereum.spurious_dragon.vm" [ "Evm" ]. -Require ethereum.spurious_dragon.vm.exceptions. -Axiom ethereum_spurious_dragon_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.spurious_dragon.vm.exceptions.globals "OutOfGasError". +Axiom ethereum_spurious_dragon_vm_exceptions_imports : + AreImported globals "ethereum.spurious_dragon.vm.exceptions" [ "OutOfGasError" ]. Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -498,7 +485,7 @@ Definition charge_gas : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -615,105 +602,114 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := ], make_dict [] |) in - For make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ] in M.get_name (| globals, "extensions" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "size" |), - Constant.int 0 - |), - (* then *) + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ], + M.get_name (| globals, "extensions" |), ltac:(M.monadic ( - let _ := M.continue (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let before_size := - M.call (| - M.get_name (| globals, "ceil32" |), - make_list [ - M.get_name (| globals, "current_size" |) - ], - make_dict [] - |) in - let after_size := - M.call (| - M.get_name (| globals, "ceil32" |), - make_list [ - BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "size" |), + Constant.int 0 |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.lt_e (| - M.get_name (| globals, "after_size" |), - M.get_name (| globals, "before_size" |) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.continue (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let size_to_extend := BinOp.add - BinOp.sub (| + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let before_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "current_size" |) + ], + make_dict [] + |) in + let after_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let size_to_extend := BinOp.add + BinOp.sub (| M.get_name (| globals, "after_size" |), M.get_name (| globals, "before_size" |) |) - BinOp.sub (| + BinOp.sub (| M.get_name (| globals, "after_size" |), M.get_name (| globals, "before_size" |) |) in - let already_paid := - M.call (| - M.get_name (| globals, "calculate_memory_gas_cost" |), - make_list [ - M.get_name (| globals, "before_size" |) - ], - make_dict [] - |) in - let total_cost := - M.call (| - M.get_name (| globals, "calculate_memory_gas_cost" |), - make_list [ - M.get_name (| globals, "after_size" |) - ], - make_dict [] - |) in - let to_be_paid := BinOp.add - BinOp.sub (| + let already_paid := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "before_size" |) + ], + make_dict [] + |) in + let total_cost := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "after_size" |) + ], + make_dict [] + |) in + let to_be_paid := BinOp.add + BinOp.sub (| M.get_name (| globals, "total_cost" |), M.get_name (| globals, "already_paid" |) |) - BinOp.sub (| + BinOp.sub (| M.get_name (| globals, "total_cost" |), M.get_name (| globals, "already_paid" |) |) in - let current_size := - M.get_name (| globals, "after_size" |) in - EndFor. + let current_size := + M.get_name (| globals, "after_size" |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ExtendMemory" |), diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/__init__.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/__init__.v index 60f3b2f..2c3e746 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/__init__.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.spurious_dragon.vm.instructions.__init__". Definition expr_1 : Value.t := Constant.str " @@ -20,59 +20,44 @@ implementations. (* At top_level_stmt: unsupported node type: Import *) -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict" ]. -Require ethereum.spurious_dragon.vm.instructions.__init__. -Axiom ethereum_spurious_dragon_vm_instructions___init___arithmetic : - IsGlobalAlias globals ethereum.spurious_dragon.vm.instructions.__init__.globals "arithmetic". +Axiom ethereum_spurious_dragon_vm_instructions_imports : + AreImported globals "ethereum.spurious_dragon.vm.instructions" [ "arithmetic" ]. -Require ethereum.spurious_dragon.vm.instructions.__init__. -Axiom ethereum_spurious_dragon_vm_instructions___init___bitwise : - IsGlobalAlias globals ethereum.spurious_dragon.vm.instructions.__init__.globals "bitwise". +Axiom ethereum_spurious_dragon_vm_instructions_imports : + AreImported globals "ethereum.spurious_dragon.vm.instructions" [ "bitwise" ]. -Require ethereum.spurious_dragon.vm.instructions.__init__. -Axiom ethereum_spurious_dragon_vm_instructions___init___block : - IsGlobalAlias globals ethereum.spurious_dragon.vm.instructions.__init__.globals "block". +Axiom ethereum_spurious_dragon_vm_instructions_imports : + AreImported globals "ethereum.spurious_dragon.vm.instructions" [ "block" ]. -Require ethereum.spurious_dragon.vm.instructions.__init__. -Axiom ethereum_spurious_dragon_vm_instructions___init___comparison : - IsGlobalAlias globals ethereum.spurious_dragon.vm.instructions.__init__.globals "comparison". +Axiom ethereum_spurious_dragon_vm_instructions_imports : + AreImported globals "ethereum.spurious_dragon.vm.instructions" [ "comparison" ]. -Require ethereum.spurious_dragon.vm.instructions.__init__. -Axiom ethereum_spurious_dragon_vm_instructions___init___control_flow : - IsGlobalAlias globals ethereum.spurious_dragon.vm.instructions.__init__.globals "control_flow". +Axiom ethereum_spurious_dragon_vm_instructions_imports : + AreImported globals "ethereum.spurious_dragon.vm.instructions" [ "control_flow" ]. -Require ethereum.spurious_dragon.vm.instructions.__init__. -Axiom ethereum_spurious_dragon_vm_instructions___init___environment : - IsGlobalAlias globals ethereum.spurious_dragon.vm.instructions.__init__.globals "environment". +Axiom ethereum_spurious_dragon_vm_instructions_imports : + AreImported globals "ethereum.spurious_dragon.vm.instructions" [ "environment" ]. -Require ethereum.spurious_dragon.vm.instructions.__init__. -Axiom ethereum_spurious_dragon_vm_instructions___init___keccak : - IsGlobalAlias globals ethereum.spurious_dragon.vm.instructions.__init__.globals "keccak". +Axiom ethereum_spurious_dragon_vm_instructions_imports : + AreImported globals "ethereum.spurious_dragon.vm.instructions" [ "keccak" ]. -Require ethereum.spurious_dragon.vm.instructions.__init__. -Axiom ethereum_spurious_dragon_vm_instructions___init___log : - IsGlobalAlias globals ethereum.spurious_dragon.vm.instructions.__init__.globals "log". +Axiom ethereum_spurious_dragon_vm_instructions_imports : + AreImported globals "ethereum.spurious_dragon.vm.instructions" [ "log" ]. -Require ethereum.spurious_dragon.vm.instructions.__init__. -Axiom ethereum_spurious_dragon_vm_instructions___init___memory : - IsGlobalAlias globals ethereum.spurious_dragon.vm.instructions.__init__.globals "memory". +Axiom ethereum_spurious_dragon_vm_instructions_imports : + AreImported globals "ethereum.spurious_dragon.vm.instructions" [ "memory" ]. -Require ethereum.spurious_dragon.vm.instructions.__init__. -Axiom ethereum_spurious_dragon_vm_instructions___init___stack : - IsGlobalAlias globals ethereum.spurious_dragon.vm.instructions.__init__.globals "stack". +Axiom ethereum_spurious_dragon_vm_instructions_imports : + AreImported globals "ethereum.spurious_dragon.vm.instructions" [ "stack" ]. -Require ethereum.spurious_dragon.vm.instructions.__init__. -Axiom ethereum_spurious_dragon_vm_instructions___init___storage : - IsGlobalAlias globals ethereum.spurious_dragon.vm.instructions.__init__.globals "storage". +Axiom ethereum_spurious_dragon_vm_instructions_imports : + AreImported globals "ethereum.spurious_dragon.vm.instructions" [ "storage" ]. -Require ethereum.spurious_dragon.vm.instructions.__init__. -Axiom ethereum_spurious_dragon_vm_instructions___init___system : - IsGlobalAlias globals ethereum.spurious_dragon.vm.instructions.__init__.globals "system". +Axiom ethereum_spurious_dragon_vm_instructions_imports : + AreImported globals "ethereum.spurious_dragon.vm.instructions" [ "system" ]. Definition Ops : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/arithmetic.v index 80f960f..f0df563 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/arithmetic.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.spurious_dragon.vm.instructions.arithmetic". Definition expr_1 : Value.t := Constant.str " @@ -17,43 +17,20 @@ Introduction Implementations of the EVM Arithmetic instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U255_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U255_CEIL_VALUE". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_U256_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U255_CEIL_VALUE"; "U256"; "U256_CEIL_VALUE"; "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_get_sign : - IsGlobalAlias globals ethereum.utils.numeric.globals "get_sign". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "get_sign" ]. -Require ethereum.spurious_dragon.vm.__init__. -Axiom ethereum_spurious_dragon_vm___init___Evm : - IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "Evm". +Axiom ethereum_spurious_dragon_vm_imports : + AreImported globals "ethereum.spurious_dragon.vm" [ "Evm" ]. -Require ethereum.spurious_dragon.vm.gas. -Axiom ethereum_spurious_dragon_vm_gas_GAS_EXPONENTIATION : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_EXPONENTIATION". -Axiom ethereum_spurious_dragon_vm_gas_GAS_EXPONENTIATION_PER_BYTE : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_EXPONENTIATION_PER_BYTE". -Axiom ethereum_spurious_dragon_vm_gas_GAS_LOW : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_LOW". -Axiom ethereum_spurious_dragon_vm_gas_GAS_MID : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_MID". -Axiom ethereum_spurious_dragon_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_spurious_dragon_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "charge_gas". +Axiom ethereum_spurious_dragon_vm_gas_imports : + AreImported globals "ethereum.spurious_dragon.vm.gas" [ "GAS_EXPONENTIATION"; "GAS_EXPONENTIATION_PER_BYTE"; "GAS_LOW"; "GAS_MID"; "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.spurious_dragon.vm.stack. -Axiom ethereum_spurious_dragon_vm_stack_pop : - IsGlobalAlias globals ethereum.spurious_dragon.vm.stack.globals "pop". -Axiom ethereum_spurious_dragon_vm_stack_push : - IsGlobalAlias globals ethereum.spurious_dragon.vm.stack.globals "push". +Axiom ethereum_spurious_dragon_vm_stack_imports : + AreImported globals "ethereum.spurious_dragon.vm.stack" [ "pop"; "push" ]. Definition add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -1030,19 +1007,27 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let value_bytes := - M.get_subscript (| M.get_name (| globals, "value_bytes" |), M.slice (| BinOp.sub (| - Constant.int 31, - M.call (| - M.get_name (| globals, "int" |), - make_list [ - M.get_name (| globals, "byte_num" |) - ], - make_dict [] - |) - |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "value_bytes" |), + BinOp.sub (| + Constant.int 31, + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "byte_num" |) + ], + make_dict [] + |) + |), + Constant.None_, + Constant.None_ + |) in let sign_bit := BinOp.r_shift (| - M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), + M.get_subscript (| + M.get_name (| globals, "value_bytes" |), + Constant.int 0 + |), Constant.int 7 |) in let _ := diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/bitwise.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/bitwise.v index cc2404d..f364066 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/bitwise.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.spurious_dragon.vm.instructions.bitwise". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementations of the EVM bitwise instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.spurious_dragon.vm.__init__. -Axiom ethereum_spurious_dragon_vm___init___Evm : - IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "Evm". +Axiom ethereum_spurious_dragon_vm_imports : + AreImported globals "ethereum.spurious_dragon.vm" [ "Evm" ]. -Require ethereum.spurious_dragon.vm.gas. -Axiom ethereum_spurious_dragon_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_spurious_dragon_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "charge_gas". +Axiom ethereum_spurious_dragon_vm_gas_imports : + AreImported globals "ethereum.spurious_dragon.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.spurious_dragon.vm.stack. -Axiom ethereum_spurious_dragon_vm_stack_pop : - IsGlobalAlias globals ethereum.spurious_dragon.vm.stack.globals "pop". -Axiom ethereum_spurious_dragon_vm_stack_push : - IsGlobalAlias globals ethereum.spurious_dragon.vm.stack.globals "push". +Axiom ethereum_spurious_dragon_vm_stack_imports : + AreImported globals "ethereum.spurious_dragon.vm.stack" [ "pop"; "push" ]. Definition bitwise_and : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/block.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/block.v index 6a7737d..db5c548 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/block.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/block.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.spurious_dragon.vm.instructions.block". Definition expr_1 : Value.t := Constant.str " @@ -17,27 +17,17 @@ Introduction Implementations of the EVM block instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.spurious_dragon.vm.__init__. -Axiom ethereum_spurious_dragon_vm___init___Evm : - IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "Evm". +Axiom ethereum_spurious_dragon_vm_imports : + AreImported globals "ethereum.spurious_dragon.vm" [ "Evm" ]. -Require ethereum.spurious_dragon.vm.gas. -Axiom ethereum_spurious_dragon_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_BASE". -Axiom ethereum_spurious_dragon_vm_gas_GAS_BLOCK_HASH : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_BLOCK_HASH". -Axiom ethereum_spurious_dragon_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "charge_gas". +Axiom ethereum_spurious_dragon_vm_gas_imports : + AreImported globals "ethereum.spurious_dragon.vm.gas" [ "GAS_BASE"; "GAS_BLOCK_HASH"; "charge_gas" ]. -Require ethereum.spurious_dragon.vm.stack. -Axiom ethereum_spurious_dragon_vm_stack_pop : - IsGlobalAlias globals ethereum.spurious_dragon.vm.stack.globals "pop". -Axiom ethereum_spurious_dragon_vm_stack_push : - IsGlobalAlias globals ethereum.spurious_dragon.vm.stack.globals "push". +Axiom ethereum_spurious_dragon_vm_stack_imports : + AreImported globals "ethereum.spurious_dragon.vm.stack" [ "pop"; "push" ]. Definition block_hash : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -94,10 +84,13 @@ Definition block_hash : Value.t -> Value.t -> M := (* else *) )), ltac:(M.monadic ( let hash := - M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), - M.get_name (| globals, "block_number" |) - |) |) |) in + M.get_subscript (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), + UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + M.get_name (| globals, "block_number" |) + |) |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/comparison.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/comparison.v index 2c803bf..3e22c3e 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/comparison.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.spurious_dragon.vm.instructions.comparison". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementations of the EVM Comparison instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.spurious_dragon.vm.__init__. -Axiom ethereum_spurious_dragon_vm___init___Evm : - IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "Evm". +Axiom ethereum_spurious_dragon_vm_imports : + AreImported globals "ethereum.spurious_dragon.vm" [ "Evm" ]. -Require ethereum.spurious_dragon.vm.gas. -Axiom ethereum_spurious_dragon_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_spurious_dragon_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "charge_gas". +Axiom ethereum_spurious_dragon_vm_gas_imports : + AreImported globals "ethereum.spurious_dragon.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.spurious_dragon.vm.stack. -Axiom ethereum_spurious_dragon_vm_stack_pop : - IsGlobalAlias globals ethereum.spurious_dragon.vm.stack.globals "pop". -Axiom ethereum_spurious_dragon_vm_stack_push : - IsGlobalAlias globals ethereum.spurious_dragon.vm.stack.globals "push". +Axiom ethereum_spurious_dragon_vm_stack_imports : + AreImported globals "ethereum.spurious_dragon.vm.stack" [ "pop"; "push" ]. Definition less_than : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/control_flow.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/control_flow.v index bfc9c53..4d7ebd5 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/control_flow.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.spurious_dragon.vm.instructions.control_flow". Definition expr_1 : Value.t := Constant.str " @@ -17,37 +17,20 @@ Introduction Implementations of the EVM control flow instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. -Require ethereum.spurious_dragon.vm.gas. -Axiom ethereum_spurious_dragon_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_BASE". -Axiom ethereum_spurious_dragon_vm_gas_GAS_HIGH : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_HIGH". -Axiom ethereum_spurious_dragon_vm_gas_GAS_JUMPDEST : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_JUMPDEST". -Axiom ethereum_spurious_dragon_vm_gas_GAS_MID : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_MID". -Axiom ethereum_spurious_dragon_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "charge_gas". +Axiom ethereum_spurious_dragon_vm_gas_imports : + AreImported globals "ethereum.spurious_dragon.vm.gas" [ "GAS_BASE"; "GAS_HIGH"; "GAS_JUMPDEST"; "GAS_MID"; "charge_gas" ]. -Require ethereum.spurious_dragon.vm.__init__. -Axiom ethereum_spurious_dragon_vm___init___Evm : - IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "Evm". +Axiom ethereum_spurious_dragon_vm_imports : + AreImported globals "ethereum.spurious_dragon.vm" [ "Evm" ]. -Require ethereum.spurious_dragon.vm.exceptions. -Axiom ethereum_spurious_dragon_vm_exceptions_InvalidJumpDestError : - IsGlobalAlias globals ethereum.spurious_dragon.vm.exceptions.globals "InvalidJumpDestError". +Axiom ethereum_spurious_dragon_vm_exceptions_imports : + AreImported globals "ethereum.spurious_dragon.vm.exceptions" [ "InvalidJumpDestError" ]. -Require ethereum.spurious_dragon.vm.stack. -Axiom ethereum_spurious_dragon_vm_stack_pop : - IsGlobalAlias globals ethereum.spurious_dragon.vm.stack.globals "pop". -Axiom ethereum_spurious_dragon_vm_stack_push : - IsGlobalAlias globals ethereum.spurious_dragon.vm.stack.globals "push". +Axiom ethereum_spurious_dragon_vm_stack_imports : + AreImported globals "ethereum.spurious_dragon.vm.stack" [ "pop"; "push" ]. Definition stop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -117,7 +100,7 @@ Definition jump : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "InvalidJumpDestError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -205,7 +188,7 @@ Definition jumpi : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "InvalidJumpDestError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/environment.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/environment.v index fbfdca2..01557ae 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/environment.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.spurious_dragon.vm.instructions.environment". Definition expr_1 : Value.t := Constant.str " @@ -17,55 +17,29 @@ Introduction Implementations of the EVM environment related instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". - -Require ethereum.spurious_dragon.state. -Axiom ethereum_spurious_dragon_state_get_account : - IsGlobalAlias globals ethereum.spurious_dragon.state.globals "get_account". - -Require ethereum.spurious_dragon.utils.address. -Axiom ethereum_spurious_dragon_utils_address_to_address : - IsGlobalAlias globals ethereum.spurious_dragon.utils.address.globals "to_address". - -Require ethereum.spurious_dragon.vm.memory. -Axiom ethereum_spurious_dragon_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.spurious_dragon.vm.memory.globals "buffer_read". -Axiom ethereum_spurious_dragon_vm_memory_memory_write : - IsGlobalAlias globals ethereum.spurious_dragon.vm.memory.globals "memory_write". - -Require ethereum.spurious_dragon.vm.__init__. -Axiom ethereum_spurious_dragon_vm___init___Evm : - IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "Evm". - -Require ethereum.spurious_dragon.vm.gas. -Axiom ethereum_spurious_dragon_vm_gas_GAS_BALANCE : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_BALANCE". -Axiom ethereum_spurious_dragon_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_BASE". -Axiom ethereum_spurious_dragon_vm_gas_GAS_COPY : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_COPY". -Axiom ethereum_spurious_dragon_vm_gas_GAS_EXTERNAL : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_EXTERNAL". -Axiom ethereum_spurious_dragon_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_spurious_dragon_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_spurious_dragon_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "charge_gas". - -Require ethereum.spurious_dragon.vm.stack. -Axiom ethereum_spurious_dragon_vm_stack_pop : - IsGlobalAlias globals ethereum.spurious_dragon.vm.stack.globals "pop". -Axiom ethereum_spurious_dragon_vm_stack_push : - IsGlobalAlias globals ethereum.spurious_dragon.vm.stack.globals "push". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. + +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. + +Axiom ethereum_spurious_dragon_state_imports : + AreImported globals "ethereum.spurious_dragon.state" [ "get_account" ]. + +Axiom ethereum_spurious_dragon_utils_address_imports : + AreImported globals "ethereum.spurious_dragon.utils.address" [ "to_address" ]. + +Axiom ethereum_spurious_dragon_vm_memory_imports : + AreImported globals "ethereum.spurious_dragon.vm.memory" [ "buffer_read"; "memory_write" ]. + +Axiom ethereum_spurious_dragon_vm_imports : + AreImported globals "ethereum.spurious_dragon.vm" [ "Evm" ]. + +Axiom ethereum_spurious_dragon_vm_gas_imports : + AreImported globals "ethereum.spurious_dragon.vm.gas" [ "GAS_BALANCE"; "GAS_BASE"; "GAS_COPY"; "GAS_EXTERNAL"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. + +Axiom ethereum_spurious_dragon_vm_stack_imports : + AreImported globals "ethereum.spurious_dragon.vm.stack" [ "pop"; "push" ]. Definition address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/keccak.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/keccak.v index 723443a..41dbfda 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/keccak.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.spurious_dragon.vm.instructions.keccak". Definition expr_1 : Value.t := Constant.str " @@ -17,43 +17,26 @@ Introduction Implementations of the EVM keccak instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". - -Require ethereum.spurious_dragon.vm.__init__. -Axiom ethereum_spurious_dragon_vm___init___Evm : - IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "Evm". - -Require ethereum.spurious_dragon.vm.gas. -Axiom ethereum_spurious_dragon_vm_gas_GAS_KECCAK256 : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_KECCAK256". -Axiom ethereum_spurious_dragon_vm_gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_KECCAK256_WORD". -Axiom ethereum_spurious_dragon_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_spurious_dragon_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "charge_gas". - -Require ethereum.spurious_dragon.vm.memory. -Axiom ethereum_spurious_dragon_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.spurious_dragon.vm.memory.globals "memory_read_bytes". - -Require ethereum.spurious_dragon.vm.stack. -Axiom ethereum_spurious_dragon_vm_stack_pop : - IsGlobalAlias globals ethereum.spurious_dragon.vm.stack.globals "pop". -Axiom ethereum_spurious_dragon_vm_stack_push : - IsGlobalAlias globals ethereum.spurious_dragon.vm.stack.globals "push". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. + +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. + +Axiom ethereum_spurious_dragon_vm_imports : + AreImported globals "ethereum.spurious_dragon.vm" [ "Evm" ]. + +Axiom ethereum_spurious_dragon_vm_gas_imports : + AreImported globals "ethereum.spurious_dragon.vm.gas" [ "GAS_KECCAK256"; "GAS_KECCAK256_WORD"; "calculate_gas_extend_memory"; "charge_gas" ]. + +Axiom ethereum_spurious_dragon_vm_memory_imports : + AreImported globals "ethereum.spurious_dragon.vm.memory" [ "memory_read_bytes" ]. + +Axiom ethereum_spurious_dragon_vm_stack_imports : + AreImported globals "ethereum.spurious_dragon.vm.stack" [ "pop"; "push" ]. Definition keccak : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/log.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/log.v index 463486d..8aa3ef5 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/log.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/log.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.spurious_dragon.vm.instructions.log". Definition expr_1 : Value.t := Constant.str " @@ -17,41 +17,26 @@ Introduction Implementations of the EVM logging instructions. ". -Require functools. -Axiom functools_partial : - IsGlobalAlias globals functools.globals "partial". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". - -Require ethereum.spurious_dragon.blocks. -Axiom ethereum_spurious_dragon_blocks_Log : - IsGlobalAlias globals ethereum.spurious_dragon.blocks.globals "Log". - -Require ethereum.spurious_dragon.vm.__init__. -Axiom ethereum_spurious_dragon_vm___init___Evm : - IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "Evm". - -Require ethereum.spurious_dragon.vm.gas. -Axiom ethereum_spurious_dragon_vm_gas_GAS_LOG : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_LOG". -Axiom ethereum_spurious_dragon_vm_gas_GAS_LOG_DATA : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_LOG_DATA". -Axiom ethereum_spurious_dragon_vm_gas_GAS_LOG_TOPIC : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_LOG_TOPIC". -Axiom ethereum_spurious_dragon_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_spurious_dragon_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "charge_gas". - -Require ethereum.spurious_dragon.vm.memory. -Axiom ethereum_spurious_dragon_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.spurious_dragon.vm.memory.globals "memory_read_bytes". - -Require ethereum.spurious_dragon.vm.stack. -Axiom ethereum_spurious_dragon_vm_stack_pop : - IsGlobalAlias globals ethereum.spurious_dragon.vm.stack.globals "pop". +Axiom functools_imports : + AreImported globals "functools" [ "partial" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. + +Axiom ethereum_spurious_dragon_blocks_imports : + AreImported globals "ethereum.spurious_dragon.blocks" [ "Log" ]. + +Axiom ethereum_spurious_dragon_vm_imports : + AreImported globals "ethereum.spurious_dragon.vm" [ "Evm" ]. + +Axiom ethereum_spurious_dragon_vm_gas_imports : + AreImported globals "ethereum.spurious_dragon.vm.gas" [ "GAS_LOG"; "GAS_LOG_DATA"; "GAS_LOG_TOPIC"; "calculate_gas_extend_memory"; "charge_gas" ]. + +Axiom ethereum_spurious_dragon_vm_memory_imports : + AreImported globals "ethereum.spurious_dragon.vm.memory" [ "memory_read_bytes" ]. + +Axiom ethereum_spurious_dragon_vm_stack_imports : + AreImported globals "ethereum.spurious_dragon.vm.stack" [ "pop" ]. Definition log_n : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -88,33 +73,42 @@ Definition log_n : Value.t -> Value.t -> M := |) in let topics := make_list [] in - For M.get_name (| globals, "_" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - M.get_name (| globals, "num_topics" |) - ], - make_dict [] - |) do - let topic := + let _ := + M.for_ (| + M.get_name (| globals, "_" |), M.call (| - M.get_field (| M.call (| - M.get_name (| globals, "pop" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] - |), "to_be_bytes32" |), - make_list [], - make_dict [] - |) in - let _ := M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "num_topics" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let topic := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| M.get_field (| M.get_name (| globals, "topics" |), "append" |), make_list [ M.get_name (| globals, "topic" |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let extend_memory := M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/memory.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/memory.v index 408e328..b6ed42f 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/memory.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.spurious_dragon.vm.instructions.memory". Definition expr_1 : Value.t := Constant.str " @@ -17,37 +17,20 @@ Introduction Implementations of the EVM Memory instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes" ]. -Require ethereum.spurious_dragon.vm.__init__. -Axiom ethereum_spurious_dragon_vm___init___Evm : - IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "Evm". +Axiom ethereum_spurious_dragon_vm_imports : + AreImported globals "ethereum.spurious_dragon.vm" [ "Evm" ]. -Require ethereum.spurious_dragon.vm.gas. -Axiom ethereum_spurious_dragon_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_BASE". -Axiom ethereum_spurious_dragon_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_spurious_dragon_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_spurious_dragon_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "charge_gas". +Axiom ethereum_spurious_dragon_vm_gas_imports : + AreImported globals "ethereum.spurious_dragon.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. -Require ethereum.spurious_dragon.vm.memory. -Axiom ethereum_spurious_dragon_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.spurious_dragon.vm.memory.globals "memory_read_bytes". -Axiom ethereum_spurious_dragon_vm_memory_memory_write : - IsGlobalAlias globals ethereum.spurious_dragon.vm.memory.globals "memory_write". +Axiom ethereum_spurious_dragon_vm_memory_imports : + AreImported globals "ethereum.spurious_dragon.vm.memory" [ "memory_read_bytes"; "memory_write" ]. -Require ethereum.spurious_dragon.vm.stack. -Axiom ethereum_spurious_dragon_vm_stack_pop : - IsGlobalAlias globals ethereum.spurious_dragon.vm.stack.globals "pop". -Axiom ethereum_spurious_dragon_vm_stack_push : - IsGlobalAlias globals ethereum.spurious_dragon.vm.stack.globals "push". +Axiom ethereum_spurious_dragon_vm_stack_imports : + AreImported globals "ethereum.spurious_dragon.vm.stack" [ "pop"; "push" ]. Definition mstore : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/stack.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/stack.v index bd63cf7..04f9a66 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/stack.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.spurious_dragon.vm.instructions.stack". Definition expr_1 : Value.t := Constant.str " @@ -17,39 +17,26 @@ Introduction Implementations of the EVM stack related instructions. ". -Require functools. -Axiom functools_partial : - IsGlobalAlias globals functools.globals "partial". +Axiom functools_imports : + AreImported globals "functools" [ "partial" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.spurious_dragon.vm.__init__. -Axiom ethereum_spurious_dragon_vm___init___Evm : - IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "Evm". -Axiom ethereum_spurious_dragon_vm___init___stack : - IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "stack". +Axiom ethereum_spurious_dragon_vm_imports : + AreImported globals "ethereum.spurious_dragon.vm" [ "Evm"; "stack" ]. -Require ethereum.spurious_dragon.vm.exceptions. -Axiom ethereum_spurious_dragon_vm_exceptions_StackUnderflowError : - IsGlobalAlias globals ethereum.spurious_dragon.vm.exceptions.globals "StackUnderflowError". +Axiom ethereum_spurious_dragon_vm_exceptions_imports : + AreImported globals "ethereum.spurious_dragon.vm.exceptions" [ "StackUnderflowError" ]. -Require ethereum.spurious_dragon.vm.gas. -Axiom ethereum_spurious_dragon_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_BASE". -Axiom ethereum_spurious_dragon_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_spurious_dragon_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "charge_gas". +Axiom ethereum_spurious_dragon_vm_gas_imports : + AreImported globals "ethereum.spurious_dragon.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.spurious_dragon.vm.memory. -Axiom ethereum_spurious_dragon_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.spurious_dragon.vm.memory.globals "buffer_read". +Axiom ethereum_spurious_dragon_vm_memory_imports : + AreImported globals "ethereum.spurious_dragon.vm.memory" [ "buffer_read" ]. Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -203,19 +190,22 @@ Definition dup_n : Value.t -> Value.t -> M := make_dict [] |) in let data_to_duplicate := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] + BinOp.sub (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), + Constant.int 1 |), - Constant.int 1 - |), - M.get_name (| globals, "item_number" |) - |) |) in + M.get_name (| globals, "item_number" |) + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "stack" |), "push" |), make_list [ @@ -278,14 +268,26 @@ Definition swap_n : Value.t -> Value.t -> M := make_dict [] |) in let _ := M.assign (| - make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| - UnOp.sub (| Constant.int 1 |), - M.get_name (| globals, "item_number" |) - |) |) ], - make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| - UnOp.sub (| Constant.int 1 |), - M.get_name (| globals, "item_number" |) - |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |) ] + make_tuple [ M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + UnOp.sub (| Constant.int 1 |) + |); M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) + |) ], + make_tuple [ M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) + |); M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + UnOp.sub (| Constant.int 1 |) + |) ] |) in let _ := M.assign_op (| BinOp.add, diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/storage.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/storage.v index df5345c..0d72826 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/storage.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.spurious_dragon.vm.instructions.storage". Definition expr_1 : Value.t := Constant.str " @@ -17,33 +17,17 @@ Introduction Implementations of the EVM storage related instructions. ". -Require ethereum.spurious_dragon.state. -Axiom ethereum_spurious_dragon_state_get_storage : - IsGlobalAlias globals ethereum.spurious_dragon.state.globals "get_storage". -Axiom ethereum_spurious_dragon_state_set_storage : - IsGlobalAlias globals ethereum.spurious_dragon.state.globals "set_storage". +Axiom ethereum_spurious_dragon_state_imports : + AreImported globals "ethereum.spurious_dragon.state" [ "get_storage"; "set_storage" ]. -Require ethereum.spurious_dragon.vm.__init__. -Axiom ethereum_spurious_dragon_vm___init___Evm : - IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "Evm". +Axiom ethereum_spurious_dragon_vm_imports : + AreImported globals "ethereum.spurious_dragon.vm" [ "Evm" ]. -Require ethereum.spurious_dragon.vm.gas. -Axiom ethereum_spurious_dragon_vm_gas_GAS_SLOAD : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_SLOAD". -Axiom ethereum_spurious_dragon_vm_gas_GAS_STORAGE_CLEAR_REFUND : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_STORAGE_CLEAR_REFUND". -Axiom ethereum_spurious_dragon_vm_gas_GAS_STORAGE_SET : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_STORAGE_SET". -Axiom ethereum_spurious_dragon_vm_gas_GAS_STORAGE_UPDATE : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_STORAGE_UPDATE". -Axiom ethereum_spurious_dragon_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "charge_gas". +Axiom ethereum_spurious_dragon_vm_gas_imports : + AreImported globals "ethereum.spurious_dragon.vm.gas" [ "GAS_SLOAD"; "GAS_STORAGE_CLEAR_REFUND"; "GAS_STORAGE_SET"; "GAS_STORAGE_UPDATE"; "charge_gas" ]. -Require ethereum.spurious_dragon.vm.stack. -Axiom ethereum_spurious_dragon_vm_stack_pop : - IsGlobalAlias globals ethereum.spurious_dragon.vm.stack.globals "pop". -Axiom ethereum_spurious_dragon_vm_stack_push : - IsGlobalAlias globals ethereum.spurious_dragon.vm.stack.globals "push". +Axiom ethereum_spurious_dragon_vm_stack_imports : + AreImported globals "ethereum.spurious_dragon.vm.stack" [ "pop"; "push" ]. Definition sload : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/system.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/system.v index a1b98c5..4a8dd1f 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/system.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/system.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.spurious_dragon.vm.instructions.system". Definition expr_1 : Value.t := Constant.str " @@ -17,85 +17,29 @@ Introduction Implementations of the EVM system related instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. -Require ethereum.spurious_dragon.fork_types. -Axiom ethereum_spurious_dragon_fork_types_Address : - IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "Address". +Axiom ethereum_spurious_dragon_fork_types_imports : + AreImported globals "ethereum.spurious_dragon.fork_types" [ "Address" ]. -Require ethereum.spurious_dragon.state. -Axiom ethereum_spurious_dragon_state_account_exists_and_is_empty : - IsGlobalAlias globals ethereum.spurious_dragon.state.globals "account_exists_and_is_empty". -Axiom ethereum_spurious_dragon_state_account_has_code_or_nonce : - IsGlobalAlias globals ethereum.spurious_dragon.state.globals "account_has_code_or_nonce". -Axiom ethereum_spurious_dragon_state_get_account : - IsGlobalAlias globals ethereum.spurious_dragon.state.globals "get_account". -Axiom ethereum_spurious_dragon_state_increment_nonce : - IsGlobalAlias globals ethereum.spurious_dragon.state.globals "increment_nonce". -Axiom ethereum_spurious_dragon_state_is_account_alive : - IsGlobalAlias globals ethereum.spurious_dragon.state.globals "is_account_alive". -Axiom ethereum_spurious_dragon_state_set_account_balance : - IsGlobalAlias globals ethereum.spurious_dragon.state.globals "set_account_balance". +Axiom ethereum_spurious_dragon_state_imports : + AreImported globals "ethereum.spurious_dragon.state" [ "account_exists_and_is_empty"; "account_has_code_or_nonce"; "get_account"; "increment_nonce"; "is_account_alive"; "set_account_balance" ]. -Require ethereum.spurious_dragon.utils.address. -Axiom ethereum_spurious_dragon_utils_address_compute_contract_address : - IsGlobalAlias globals ethereum.spurious_dragon.utils.address.globals "compute_contract_address". -Axiom ethereum_spurious_dragon_utils_address_to_address : - IsGlobalAlias globals ethereum.spurious_dragon.utils.address.globals "to_address". +Axiom ethereum_spurious_dragon_utils_address_imports : + AreImported globals "ethereum.spurious_dragon.utils.address" [ "compute_contract_address"; "to_address" ]. -Require ethereum.spurious_dragon.vm.__init__. -Axiom ethereum_spurious_dragon_vm___init___Evm : - IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "Evm". -Axiom ethereum_spurious_dragon_vm___init___Message : - IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "Message". -Axiom ethereum_spurious_dragon_vm___init___incorporate_child_on_error : - IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "incorporate_child_on_error". -Axiom ethereum_spurious_dragon_vm___init___incorporate_child_on_success : - IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "incorporate_child_on_success". +Axiom ethereum_spurious_dragon_vm_imports : + AreImported globals "ethereum.spurious_dragon.vm" [ "Evm"; "Message"; "incorporate_child_on_error"; "incorporate_child_on_success" ]. -Require ethereum.spurious_dragon.vm.gas. -Axiom ethereum_spurious_dragon_vm_gas_GAS_CALL : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_CALL". -Axiom ethereum_spurious_dragon_vm_gas_GAS_CALL_VALUE : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_CALL_VALUE". -Axiom ethereum_spurious_dragon_vm_gas_GAS_CREATE : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_CREATE". -Axiom ethereum_spurious_dragon_vm_gas_GAS_NEW_ACCOUNT : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_NEW_ACCOUNT". -Axiom ethereum_spurious_dragon_vm_gas_GAS_SELF_DESTRUCT : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_SELF_DESTRUCT". -Axiom ethereum_spurious_dragon_vm_gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". -Axiom ethereum_spurious_dragon_vm_gas_GAS_ZERO : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_ZERO". -Axiom ethereum_spurious_dragon_vm_gas_REFUND_SELF_DESTRUCT : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "REFUND_SELF_DESTRUCT". -Axiom ethereum_spurious_dragon_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_spurious_dragon_vm_gas_calculate_message_call_gas : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "calculate_message_call_gas". -Axiom ethereum_spurious_dragon_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "charge_gas". -Axiom ethereum_spurious_dragon_vm_gas_max_message_call_gas : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "max_message_call_gas". +Axiom ethereum_spurious_dragon_vm_gas_imports : + AreImported globals "ethereum.spurious_dragon.vm.gas" [ "GAS_CALL"; "GAS_CALL_VALUE"; "GAS_CREATE"; "GAS_NEW_ACCOUNT"; "GAS_SELF_DESTRUCT"; "GAS_SELF_DESTRUCT_NEW_ACCOUNT"; "GAS_ZERO"; "REFUND_SELF_DESTRUCT"; "calculate_gas_extend_memory"; "calculate_message_call_gas"; "charge_gas"; "max_message_call_gas" ]. -Require ethereum.spurious_dragon.vm.memory. -Axiom ethereum_spurious_dragon_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.spurious_dragon.vm.memory.globals "memory_read_bytes". -Axiom ethereum_spurious_dragon_vm_memory_memory_write : - IsGlobalAlias globals ethereum.spurious_dragon.vm.memory.globals "memory_write". +Axiom ethereum_spurious_dragon_vm_memory_imports : + AreImported globals "ethereum.spurious_dragon.vm.memory" [ "memory_read_bytes"; "memory_write" ]. -Require ethereum.spurious_dragon.vm.stack. -Axiom ethereum_spurious_dragon_vm_stack_pop : - IsGlobalAlias globals ethereum.spurious_dragon.vm.stack.globals "pop". -Axiom ethereum_spurious_dragon_vm_stack_push : - IsGlobalAlias globals ethereum.spurious_dragon.vm.stack.globals "push". +Axiom ethereum_spurious_dragon_vm_stack_imports : + AreImported globals "ethereum.spurious_dragon.vm.stack" [ "pop"; "push" ]. Definition create : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -645,7 +589,12 @@ Definition generic_call : Value.t -> Value.t -> M := make_list [ M.get_field (| M.get_name (| globals, "evm" |), "memory" |); M.get_name (| globals, "memory_output_start_position" |); - M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), M.slice (| Constant.None_, M.get_name (| globals, "actual_output_size" |) |) |) + M.slice (| + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), + Constant.None_, + M.get_name (| globals, "actual_output_size" |), + Constant.None_ + |) ], make_dict [] |) in @@ -1191,20 +1140,28 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in let parent_evm := M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "parent_evm" |) in - While Compare.is_not (| - M.get_name (| globals, "parent_evm" |), - Constant.None_ - |) do - let _ := M.call (| + let _ := + M.while (| + Compare.is_not (| + M.get_name (| globals, "parent_evm" |), + Constant.None_ + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "refunded_accounts" |), "update" |), make_list [ M.get_field (| M.get_name (| globals, "parent_evm" |), "accounts_to_delete" |) ], make_dict [] |) in - let parent_evm := - M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in - EndWhile. + let parent_evm := + M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := (* if *) M.if_then_else (| diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/interpreter.v b/CoqOfPython/ethereum/spurious_dragon/vm/interpreter.v index 78aae7a..8e8287b 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/interpreter.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/interpreter.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.spurious_dragon.vm.interpreter". Definition expr_1 : Value.t := Constant.str " @@ -17,121 +17,50 @@ Introduction A straightforward interpreter that executes EVM code. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_Iterable : - IsGlobalAlias globals typing.globals "Iterable". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.trace. -Axiom ethereum_trace_EvmStop : - IsGlobalAlias globals ethereum.trace.globals "EvmStop". -Axiom ethereum_trace_OpEnd : - IsGlobalAlias globals ethereum.trace.globals "OpEnd". -Axiom ethereum_trace_OpException : - IsGlobalAlias globals ethereum.trace.globals "OpException". -Axiom ethereum_trace_OpStart : - IsGlobalAlias globals ethereum.trace.globals "OpStart". -Axiom ethereum_trace_PrecompileEnd : - IsGlobalAlias globals ethereum.trace.globals "PrecompileEnd". -Axiom ethereum_trace_PrecompileStart : - IsGlobalAlias globals ethereum.trace.globals "PrecompileStart". -Axiom ethereum_trace_TransactionEnd : - IsGlobalAlias globals ethereum.trace.globals "TransactionEnd". -Axiom ethereum_trace_evm_trace : - IsGlobalAlias globals ethereum.trace.globals "evm_trace". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.spurious_dragon.blocks. -Axiom ethereum_spurious_dragon_blocks_Log : - IsGlobalAlias globals ethereum.spurious_dragon.blocks.globals "Log". - -Require ethereum.spurious_dragon.fork_types. -Axiom ethereum_spurious_dragon_fork_types_Address : - IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "Address". - -Require ethereum.spurious_dragon.state. -Axiom ethereum_spurious_dragon_state_account_exists_and_is_empty : - IsGlobalAlias globals ethereum.spurious_dragon.state.globals "account_exists_and_is_empty". -Axiom ethereum_spurious_dragon_state_account_has_code_or_nonce : - IsGlobalAlias globals ethereum.spurious_dragon.state.globals "account_has_code_or_nonce". -Axiom ethereum_spurious_dragon_state_begin_transaction : - IsGlobalAlias globals ethereum.spurious_dragon.state.globals "begin_transaction". -Axiom ethereum_spurious_dragon_state_commit_transaction : - IsGlobalAlias globals ethereum.spurious_dragon.state.globals "commit_transaction". -Axiom ethereum_spurious_dragon_state_destroy_storage : - IsGlobalAlias globals ethereum.spurious_dragon.state.globals "destroy_storage". -Axiom ethereum_spurious_dragon_state_increment_nonce : - IsGlobalAlias globals ethereum.spurious_dragon.state.globals "increment_nonce". -Axiom ethereum_spurious_dragon_state_move_ether : - IsGlobalAlias globals ethereum.spurious_dragon.state.globals "move_ether". -Axiom ethereum_spurious_dragon_state_rollback_transaction : - IsGlobalAlias globals ethereum.spurious_dragon.state.globals "rollback_transaction". -Axiom ethereum_spurious_dragon_state_set_code : - IsGlobalAlias globals ethereum.spurious_dragon.state.globals "set_code". -Axiom ethereum_spurious_dragon_state_touch_account : - IsGlobalAlias globals ethereum.spurious_dragon.state.globals "touch_account". - -Require ethereum.spurious_dragon.vm.__init__. -Axiom ethereum_spurious_dragon_vm___init___Message : - IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "Message". - -Require ethereum.spurious_dragon.vm.gas. -Axiom ethereum_spurious_dragon_vm_gas_GAS_CODE_DEPOSIT : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_CODE_DEPOSIT". -Axiom ethereum_spurious_dragon_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "charge_gas". - -Require ethereum.spurious_dragon.vm.precompiled_contracts.mapping. -Axiom ethereum_spurious_dragon_vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : - IsGlobalAlias globals ethereum.spurious_dragon.vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". - -Require ethereum.spurious_dragon.vm.__init__. -Axiom ethereum_spurious_dragon_vm___init___Environment : - IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "Environment". -Axiom ethereum_spurious_dragon_vm___init___Evm : - IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "Evm". - -Require ethereum.spurious_dragon.vm.exceptions. -Axiom ethereum_spurious_dragon_vm_exceptions_AddressCollision : - IsGlobalAlias globals ethereum.spurious_dragon.vm.exceptions.globals "AddressCollision". -Axiom ethereum_spurious_dragon_vm_exceptions_ExceptionalHalt : - IsGlobalAlias globals ethereum.spurious_dragon.vm.exceptions.globals "ExceptionalHalt". -Axiom ethereum_spurious_dragon_vm_exceptions_InvalidOpcode : - IsGlobalAlias globals ethereum.spurious_dragon.vm.exceptions.globals "InvalidOpcode". -Axiom ethereum_spurious_dragon_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.spurious_dragon.vm.exceptions.globals "OutOfGasError". -Axiom ethereum_spurious_dragon_vm_exceptions_StackDepthLimitError : - IsGlobalAlias globals ethereum.spurious_dragon.vm.exceptions.globals "StackDepthLimitError". - -Require ethereum.spurious_dragon.vm.instructions.__init__. -Axiom ethereum_spurious_dragon_vm_instructions___init___Ops : - IsGlobalAlias globals ethereum.spurious_dragon.vm.instructions.__init__.globals "Ops". -Axiom ethereum_spurious_dragon_vm_instructions___init___op_implementation : - IsGlobalAlias globals ethereum.spurious_dragon.vm.instructions.__init__.globals "op_implementation". - -Require ethereum.spurious_dragon.vm.runtime. -Axiom ethereum_spurious_dragon_vm_runtime_get_valid_jump_destinations : - IsGlobalAlias globals ethereum.spurious_dragon.vm.runtime.globals "get_valid_jump_destinations". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Iterable"; "Optional"; "Set"; "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. + +Axiom ethereum_trace_imports : + AreImported globals "ethereum.trace" [ "EvmStop"; "OpEnd"; "OpException"; "OpStart"; "PrecompileEnd"; "PrecompileStart"; "TransactionEnd"; "evm_trace" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_spurious_dragon_blocks_imports : + AreImported globals "ethereum.spurious_dragon.blocks" [ "Log" ]. + +Axiom ethereum_spurious_dragon_fork_types_imports : + AreImported globals "ethereum.spurious_dragon.fork_types" [ "Address" ]. + +Axiom ethereum_spurious_dragon_state_imports : + AreImported globals "ethereum.spurious_dragon.state" [ "account_exists_and_is_empty"; "account_has_code_or_nonce"; "begin_transaction"; "commit_transaction"; "destroy_storage"; "increment_nonce"; "move_ether"; "rollback_transaction"; "set_code"; "touch_account" ]. + +Axiom ethereum_spurious_dragon_vm_imports : + AreImported globals "ethereum.spurious_dragon.vm" [ "Message" ]. + +Axiom ethereum_spurious_dragon_vm_gas_imports : + AreImported globals "ethereum.spurious_dragon.vm.gas" [ "GAS_CODE_DEPOSIT"; "charge_gas" ]. + +Axiom ethereum_spurious_dragon_vm_precompiled_contracts_mapping_imports : + AreImported globals "ethereum.spurious_dragon.vm.precompiled_contracts.mapping" [ "PRE_COMPILED_CONTRACTS" ]. + +Axiom ethereum_spurious_dragon_vm_imports : + AreImported globals "ethereum.spurious_dragon.vm" [ "Environment"; "Evm" ]. + +Axiom ethereum_spurious_dragon_vm_exceptions_imports : + AreImported globals "ethereum.spurious_dragon.vm.exceptions" [ "AddressCollision"; "ExceptionalHalt"; "InvalidOpcode"; "OutOfGasError"; "StackDepthLimitError" ]. + +Axiom ethereum_spurious_dragon_vm_instructions_imports : + AreImported globals "ethereum.spurious_dragon.vm.instructions" [ "Ops"; "op_implementation" ]. + +Axiom ethereum_spurious_dragon_vm_runtime_imports : + AreImported globals "ethereum.spurious_dragon.vm.runtime" [ "get_valid_jump_destinations" ]. Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -498,7 +427,7 @@ Definition process_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "StackDepthLimitError" |), make_list [ Constant.str "Stack depth limit reached" diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/memory.v b/CoqOfPython/ethereum/spurious_dragon/vm/memory.v index 08d2290..d6d4144 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/memory.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/memory.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.spurious_dragon.vm.memory". Definition expr_1 : Value.t := Constant.str " @@ -17,17 +17,11 @@ Introduction EVM memory operations. ". -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_right_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "right_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "right_pad_zero_bytes" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. Definition memory_write : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,22 +39,27 @@ Definition memory_write : Value.t -> Value.t -> M := Data to write to memory. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + M.slice (| + M.get_name (| globals, "memory" |), + M.get_name (| globals, "start_position" |), + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) - |) |) |), + Constant.None_ + |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_)). @@ -86,22 +85,27 @@ Definition memory_read_bytes : Value.t -> Value.t -> M := Data read from memory. " in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + M.slice (| + M.get_name (| globals, "memory" |), + M.get_name (| globals, "start_position" |), + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |) |) + Constant.None_ + |) |) in M.pure Constant.None_)). @@ -129,22 +133,27 @@ Definition buffer_read : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "right_pad_zero_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "buffer" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + M.slice (| + M.get_name (| globals, "buffer" |), + M.get_name (| globals, "start_position" |), + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |) |); + Constant.None_ + |); M.get_name (| globals, "size" |) ], make_dict [] diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/__init__.v index 8d64b76..4f4bcd1 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/__init__.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.spurious_dragon.vm.precompiled_contracts.__init__". Definition expr_1 : Value.t := Constant.str " @@ -18,9 +18,8 @@ Addresses of precompiled contracts and mappings to their implementations. ". -Require ethereum.spurious_dragon.utils.hexadecimal. -Axiom ethereum_spurious_dragon_utils_hexadecimal_hex_to_address : - IsGlobalAlias globals ethereum.spurious_dragon.utils.hexadecimal.globals "hex_to_address". +Axiom ethereum_spurious_dragon_utils_hexadecimal_imports : + AreImported globals "ethereum.spurious_dragon.utils.hexadecimal" [ "hex_to_address" ]. Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS" ] diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/ecrecover.v index c304229..f527432 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/ecrecover.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.spurious_dragon.vm.precompiled_contracts.ecrecover". Definition expr_1 : Value.t := Constant.str " @@ -17,39 +17,26 @@ Introduction Implementation of the ECRECOVER precompiled contract. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.crypto.elliptic_curve. -Axiom ethereum_crypto_elliptic_curve_SECP256K1N : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". -Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". +Axiom ethereum_crypto_elliptic_curve_imports : + AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_left_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. -Require ethereum.spurious_dragon.vm.__init__. -Axiom ethereum_spurious_dragon_vm___init___Evm : - IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "Evm". +Axiom ethereum_spurious_dragon_vm_imports : + AreImported globals "ethereum.spurious_dragon.vm" [ "Evm" ]. -Require ethereum.spurious_dragon.vm.gas. -Axiom ethereum_spurious_dragon_vm_gas_GAS_ECRECOVER : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_ECRECOVER". -Axiom ethereum_spurious_dragon_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "charge_gas". +Axiom ethereum_spurious_dragon_vm_gas_imports : + AreImported globals "ethereum.spurious_dragon.vm.gas" [ "GAS_ECRECOVER"; "charge_gas" ]. -Require ethereum.spurious_dragon.vm.memory. -Axiom ethereum_spurious_dragon_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.spurious_dragon.vm.memory.globals "buffer_read". +Axiom ethereum_spurious_dragon_vm_memory_imports : + AreImported globals "ethereum.spurious_dragon.vm.memory" [ "buffer_read" ]. Definition ecrecover : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -264,13 +251,18 @@ Definition ecrecover : Value.t -> Value.t -> M := )) |) in (* At stmt: unsupported node type: Try *) let address := - M.get_subscript (| M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "public_key" |) - ], - make_dict [] - |), M.slice (| Constant.int 12, Constant.int 32 |) |) in + M.slice (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), + Constant.int 12, + Constant.int 32, + Constant.None_ + |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/identity.v index a3cf5a9..a727fec 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/identity.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/identity.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.spurious_dragon.vm.precompiled_contracts.identity". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementation of the `IDENTITY` precompiled contract. ". -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.spurious_dragon.vm.__init__. -Axiom ethereum_spurious_dragon_vm___init___Evm : - IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "Evm". +Axiom ethereum_spurious_dragon_vm_imports : + AreImported globals "ethereum.spurious_dragon.vm" [ "Evm" ]. -Require ethereum.spurious_dragon.vm.gas. -Axiom ethereum_spurious_dragon_vm_gas_GAS_IDENTITY : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_IDENTITY". -Axiom ethereum_spurious_dragon_vm_gas_GAS_IDENTITY_WORD : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_IDENTITY_WORD". -Axiom ethereum_spurious_dragon_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "charge_gas". +Axiom ethereum_spurious_dragon_vm_gas_imports : + AreImported globals "ethereum.spurious_dragon.vm.gas" [ "GAS_IDENTITY"; "GAS_IDENTITY_WORD"; "charge_gas" ]. Definition identity : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/mapping.v index b0e598a..5c95c6e 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/mapping.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/mapping.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.spurious_dragon.vm.precompiled_contracts.mapping". Definition expr_1 : Value.t := Constant.str " @@ -17,40 +17,25 @@ Introduction Mapping of precompiled contracts their implementations. ". -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". - -Require ethereum.spurious_dragon.fork_types. -Axiom ethereum_spurious_dragon_fork_types_Address : - IsGlobalAlias globals ethereum.spurious_dragon.fork_types.globals "Address". - -Require ethereum.spurious_dragon.vm.precompiled_contracts.__init__. -Axiom ethereum_spurious_dragon_vm_precompiled_contracts___init___ECRECOVER_ADDRESS : - IsGlobalAlias globals ethereum.spurious_dragon.vm.precompiled_contracts.__init__.globals "ECRECOVER_ADDRESS". -Axiom ethereum_spurious_dragon_vm_precompiled_contracts___init___IDENTITY_ADDRESS : - IsGlobalAlias globals ethereum.spurious_dragon.vm.precompiled_contracts.__init__.globals "IDENTITY_ADDRESS". -Axiom ethereum_spurious_dragon_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : - IsGlobalAlias globals ethereum.spurious_dragon.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". -Axiom ethereum_spurious_dragon_vm_precompiled_contracts___init___SHA256_ADDRESS : - IsGlobalAlias globals ethereum.spurious_dragon.vm.precompiled_contracts.__init__.globals "SHA256_ADDRESS". - -Require ethereum.spurious_dragon.vm.precompiled_contracts.ecrecover. -Axiom ethereum_spurious_dragon_vm_precompiled_contracts_ecrecover_ecrecover : - IsGlobalAlias globals ethereum.spurious_dragon.vm.precompiled_contracts.ecrecover.globals "ecrecover". - -Require ethereum.spurious_dragon.vm.precompiled_contracts.identity. -Axiom ethereum_spurious_dragon_vm_precompiled_contracts_identity_identity : - IsGlobalAlias globals ethereum.spurious_dragon.vm.precompiled_contracts.identity.globals "identity". - -Require ethereum.spurious_dragon.vm.precompiled_contracts.ripemd160. -Axiom ethereum_spurious_dragon_vm_precompiled_contracts_ripemd160_ripemd160 : - IsGlobalAlias globals ethereum.spurious_dragon.vm.precompiled_contracts.ripemd160.globals "ripemd160". - -Require ethereum.spurious_dragon.vm.precompiled_contracts.sha256. -Axiom ethereum_spurious_dragon_vm_precompiled_contracts_sha256_sha256 : - IsGlobalAlias globals ethereum.spurious_dragon.vm.precompiled_contracts.sha256.globals "sha256". +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict" ]. + +Axiom ethereum_spurious_dragon_fork_types_imports : + AreImported globals "ethereum.spurious_dragon.fork_types" [ "Address" ]. + +Axiom ethereum_spurious_dragon_vm_precompiled_contracts_imports : + AreImported globals "ethereum.spurious_dragon.vm.precompiled_contracts" [ "ECRECOVER_ADDRESS"; "IDENTITY_ADDRESS"; "RIPEMD160_ADDRESS"; "SHA256_ADDRESS" ]. + +Axiom ethereum_spurious_dragon_vm_precompiled_contracts_ecrecover_imports : + AreImported globals "ethereum.spurious_dragon.vm.precompiled_contracts.ecrecover" [ "ecrecover" ]. + +Axiom ethereum_spurious_dragon_vm_precompiled_contracts_identity_imports : + AreImported globals "ethereum.spurious_dragon.vm.precompiled_contracts.identity" [ "identity" ]. + +Axiom ethereum_spurious_dragon_vm_precompiled_contracts_ripemd160_imports : + AreImported globals "ethereum.spurious_dragon.vm.precompiled_contracts.ripemd160" [ "ripemd160" ]. + +Axiom ethereum_spurious_dragon_vm_precompiled_contracts_sha256_imports : + AreImported globals "ethereum.spurious_dragon.vm.precompiled_contracts.sha256" [ "sha256" ]. (* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/ripemd160.v index a6246db..4a39a9c 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/ripemd160.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/ripemd160.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.spurious_dragon.vm.precompiled_contracts.ripemd160". Definition expr_1 : Value.t := Constant.str " @@ -19,29 +19,20 @@ Implementation of the `RIPEMD160` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_left_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.spurious_dragon.vm.__init__. -Axiom ethereum_spurious_dragon_vm___init___Evm : - IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "Evm". +Axiom ethereum_spurious_dragon_vm_imports : + AreImported globals "ethereum.spurious_dragon.vm" [ "Evm" ]. -Require ethereum.spurious_dragon.vm.gas. -Axiom ethereum_spurious_dragon_vm_gas_GAS_RIPEMD160 : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_RIPEMD160". -Axiom ethereum_spurious_dragon_vm_gas_GAS_RIPEMD160_WORD : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_RIPEMD160_WORD". -Axiom ethereum_spurious_dragon_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "charge_gas". +Axiom ethereum_spurious_dragon_vm_gas_imports : + AreImported globals "ethereum.spurious_dragon.vm.gas" [ "GAS_RIPEMD160"; "GAS_RIPEMD160_WORD"; "charge_gas" ]. Definition ripemd160 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/sha256.v index fd8aa4b..d82133c 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/sha256.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/sha256.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.spurious_dragon.vm.precompiled_contracts.sha256". Definition expr_1 : Value.t := Constant.str " @@ -19,25 +19,17 @@ Implementation of the `SHA256` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.spurious_dragon.vm.__init__. -Axiom ethereum_spurious_dragon_vm___init___Evm : - IsGlobalAlias globals ethereum.spurious_dragon.vm.__init__.globals "Evm". +Axiom ethereum_spurious_dragon_vm_imports : + AreImported globals "ethereum.spurious_dragon.vm" [ "Evm" ]. -Require ethereum.spurious_dragon.vm.gas. -Axiom ethereum_spurious_dragon_vm_gas_GAS_SHA256 : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_SHA256". -Axiom ethereum_spurious_dragon_vm_gas_GAS_SHA256_WORD : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "GAS_SHA256_WORD". -Axiom ethereum_spurious_dragon_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.spurious_dragon.vm.gas.globals "charge_gas". +Axiom ethereum_spurious_dragon_vm_gas_imports : + AreImported globals "ethereum.spurious_dragon.vm.gas" [ "GAS_SHA256"; "GAS_SHA256_WORD"; "charge_gas" ]. Definition sha256 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/runtime.v b/CoqOfPython/ethereum/spurious_dragon/vm/runtime.v index 70b1b41..1ee9b82 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/runtime.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/runtime.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.spurious_dragon.vm.runtime". Definition expr_1 : Value.t := Constant.str " @@ -17,17 +17,14 @@ Introduction Runtime related operations used while executing EVM code. ". -Require typing. -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". +Axiom typing_imports : + AreImported globals "typing" [ "Set" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.spurious_dragon.vm.instructions.__init__. -Axiom ethereum_spurious_dragon_vm_instructions___init___Ops : - IsGlobalAlias globals ethereum.spurious_dragon.vm.instructions.__init__.globals "Ops". +Axiom ethereum_spurious_dragon_vm_instructions_imports : + AreImported globals "ethereum.spurious_dragon.vm.instructions" [ "Ops" ]. Definition get_valid_jump_destinations : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -67,75 +64,83 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := ], make_dict [] |) in - While Compare.lt (| - M.get_name (| globals, "pc" |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "code" |) - ], - make_dict [] - |) - |) do -(* At stmt: unsupported node type: Try *) - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "current_opcode" |), - M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) - |), - (* then *) + let _ := + M.while (| + Compare.lt (| + M.get_name (| globals, "pc" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) + |), ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), - make_list [ - M.get_name (| globals, "pc" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( +(* At stmt: unsupported node type: Try *) let _ := (* if *) M.if_then_else (| - BoolOp.and (| - Compare.lt_e (| - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |), - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |) - |), - ltac:(M.monadic ( - Compare.lt_e (| - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH32" |), "value" |) - |) - )) + Compare.eq (| + M.get_name (| globals, "current_opcode" |), + M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) |), (* then *) ltac:(M.monadic ( - let push_data_size := - BinOp.add (| - BinOp.sub (| - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) - |), - Constant.int 1 - |) in - let pc := BinOp.add - M.get_name (| globals, "push_data_size" |) - M.get_name (| globals, "push_data_size" |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), + make_list [ + M.get_name (| globals, "pc" |) + ], + make_dict [] + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.lt_e (| + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |), + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH32" |), "value" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let push_data_size := + BinOp.add (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) + |), + Constant.int 1 + |) in + let pc := BinOp.add + M.get_name (| globals, "push_data_size" |) + M.get_name (| globals, "push_data_size" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ )) |) in + let pc := BinOp.add + Constant.int 1 + Constant.int 1 in M.pure Constant.None_ - )) |) in - let pc := BinOp.add - Constant.int 1 - Constant.int 1 in - EndWhile. + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.get_name (| globals, "valid_jump_destinations" |) |) in diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/stack.v b/CoqOfPython/ethereum/spurious_dragon/vm/stack.v index 1c3b5a2..5cf5f43 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/stack.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/stack.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.spurious_dragon.vm.stack". Definition expr_1 : Value.t := Constant.str " @@ -17,19 +17,14 @@ Introduction Implementation of the stack operators for the EVM. ". -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". +Axiom typing_imports : + AreImported globals "typing" [ "List" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.spurious_dragon.vm.exceptions. -Axiom ethereum_spurious_dragon_vm_exceptions_StackOverflowError : - IsGlobalAlias globals ethereum.spurious_dragon.vm.exceptions.globals "StackOverflowError". -Axiom ethereum_spurious_dragon_vm_exceptions_StackUnderflowError : - IsGlobalAlias globals ethereum.spurious_dragon.vm.exceptions.globals "StackUnderflowError". +Axiom ethereum_spurious_dragon_vm_exceptions_imports : + AreImported globals "ethereum.spurious_dragon.vm.exceptions" [ "StackOverflowError"; "StackUnderflowError" ]. Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -63,7 +58,7 @@ Definition pop : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "StackUnderflowError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "StackUnderflowError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -108,7 +103,7 @@ Definition push : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "StackOverflowError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "StackOverflowError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/tangerine_whistle/__init__.v b/CoqOfPython/ethereum/tangerine_whistle/__init__.v index 25e2813..aa34c97 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/__init__.v +++ b/CoqOfPython/ethereum/tangerine_whistle/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.tangerine_whistle.__init__". Definition expr_1 : Value.t := Constant.str " @@ -10,9 +10,8 @@ EVM instructions, and reduces the state size by removing a number of empty accounts. ". -Require ethereum.fork_criteria. -Axiom ethereum_fork_criteria_ByBlockNumber : - IsGlobalAlias globals ethereum.fork_criteria.globals "ByBlockNumber". +Axiom ethereum_fork_criteria_imports : + AreImported globals "ethereum.fork_criteria" [ "ByBlockNumber" ]. Definition FORK_CRITERIA : Value.t := M.run ltac:(M.monadic ( M.call (| diff --git a/CoqOfPython/ethereum/tangerine_whistle/blocks.v b/CoqOfPython/ethereum/tangerine_whistle/blocks.v index 57ca486..c21d5ca 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/blocks.v +++ b/CoqOfPython/ethereum/tangerine_whistle/blocks.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.tangerine_whistle.blocks". Definition expr_1 : Value.t := Constant.str " @@ -14,43 +14,23 @@ history of all state transitions that have happened since the genesis of the chain. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes8 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes8". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". - -Require ethereum.tangerine_whistle.fork_types. -Axiom ethereum_tangerine_whistle_fork_types_Address : - IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "Address". -Axiom ethereum_tangerine_whistle_fork_types_Bloom : - IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "Bloom". -Axiom ethereum_tangerine_whistle_fork_types_Root : - IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "Root". - -Require ethereum.tangerine_whistle.transactions. -Axiom ethereum_tangerine_whistle_transactions_Transaction : - IsGlobalAlias globals ethereum.tangerine_whistle.transactions.globals "Transaction". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes8"; "Bytes32"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. + +Axiom ethereum_tangerine_whistle_fork_types_imports : + AreImported globals "ethereum.tangerine_whistle.fork_types" [ "Address"; "Bloom"; "Root" ]. + +Axiom ethereum_tangerine_whistle_transactions_imports : + AreImported globals "ethereum.tangerine_whistle.transactions" [ "Transaction" ]. Definition Header : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/tangerine_whistle/bloom.v b/CoqOfPython/ethereum/tangerine_whistle/bloom.v index 4c9e15e..1451af7 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/bloom.v +++ b/CoqOfPython/ethereum/tangerine_whistle/bloom.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.tangerine_whistle.bloom". Definition expr_1 : Value.t := Constant.str " @@ -21,25 +21,20 @@ for efficient searching of logs by address and/or topic, by rapidly eliminating blocks and receipts from their search. ". -Require typing. -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_imports : + AreImported globals "typing" [ "Tuple" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. -Require ethereum.tangerine_whistle.blocks. -Axiom ethereum_tangerine_whistle_blocks_Log : - IsGlobalAlias globals ethereum.tangerine_whistle.blocks.globals "Log". +Axiom ethereum_tangerine_whistle_blocks_imports : + AreImported globals "ethereum.tangerine_whistle.blocks" [ "Log" ]. -Require ethereum.tangerine_whistle.fork_types. -Axiom ethereum_tangerine_whistle_fork_types_Bloom : - IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "Bloom". +Axiom ethereum_tangerine_whistle_fork_types_imports : + AreImported globals "ethereum.tangerine_whistle.fork_types" [ "Bloom" ]. Definition add_to_bloom : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -66,50 +61,70 @@ Definition add_to_bloom : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "idx" |) in make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ] do - let bit_to_set := - BinOp.bit_and (| - M.call (| - M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "hash" |), M.slice (| M.get_name (| globals, "idx" |), BinOp.add (| - M.get_name (| globals, "idx" |), - Constant.int 2 - |) |) |) - ], - make_dict [] - |), - Constant.int 2047 - |) in - let bit_index := - BinOp.sub (| - Constant.int 2047, - M.get_name (| globals, "bit_to_set" |) - |) in - let byte_index := - BinOp.floor_div (| - M.get_name (| globals, "bit_index" |), - Constant.int 8 - |) in - let bit_value := - BinOp.l_shift (| - Constant.int 1, - BinOp.sub (| - Constant.int 7, - BinOp.mod_ (| + let _ := + M.for_ (| + M.get_name (| globals, "idx" |), + make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ], + ltac:(M.monadic ( + let bit_to_set := + BinOp.bit_and (| + M.call (| + M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), + make_list [ + M.slice (| + M.get_name (| globals, "hash" |), + M.get_name (| globals, "idx" |), + BinOp.add (| + M.get_name (| globals, "idx" |), + Constant.int 2 + |), + Constant.None_ + |) + ], + make_dict [] + |), + Constant.int 2047 + |) in + let bit_index := + BinOp.sub (| + Constant.int 2047, + M.get_name (| globals, "bit_to_set" |) + |) in + let byte_index := + BinOp.floor_div (| M.get_name (| globals, "bit_index" |), Constant.int 8 + |) in + let bit_value := + BinOp.l_shift (| + Constant.int 1, + BinOp.sub (| + Constant.int 7, + BinOp.mod_ (| + M.get_name (| globals, "bit_index" |), + Constant.int 8 + |) + |) + |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "bloom" |), + M.get_name (| globals, "byte_index" |) + |), + BinOp.bit_or (| + M.get_subscript (| + M.get_name (| globals, "bloom" |), + M.get_name (| globals, "byte_index" |) + |), + M.get_name (| globals, "bit_value" |) |) - |) - |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), - BinOp.bit_or (| - M.get_subscript (| M.get_name (| globals, "bloom" |), M.get_name (| globals, "byte_index" |) |), - M.get_name (| globals, "bit_value" |) - |) - |) in - EndFor. + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_)). Definition logs_bloom : Value.t -> Value.t -> M := @@ -132,8 +147,12 @@ Definition logs_bloom : Value.t -> Value.t -> M := the caller address and the log topics. " in (* At stmt: unsupported node type: AnnAssign *) - For M.get_name (| globals, "log" |) in M.get_name (| globals, "logs" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "log" |), + M.get_name (| globals, "logs" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "add_to_bloom" |), make_list [ M.get_name (| globals, "bloom" |); @@ -141,8 +160,12 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "topic" |) in M.get_field (| M.get_name (| globals, "log" |), "topics" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "topic" |), + M.get_field (| M.get_name (| globals, "log" |), "topics" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "add_to_bloom" |), make_list [ M.get_name (| globals, "bloom" |); @@ -150,8 +173,18 @@ Definition logs_bloom : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Bloom" |), diff --git a/CoqOfPython/ethereum/tangerine_whistle/fork.v b/CoqOfPython/ethereum/tangerine_whistle/fork.v index c59f022..b7f1c88 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/fork.v +++ b/CoqOfPython/ethereum/tangerine_whistle/fork.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.tangerine_whistle.fork". Definition expr_1 : Value.t := Constant.str " @@ -17,139 +17,62 @@ Introduction Entry point for the Ethereum specification. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". - -Require ethereum.crypto.elliptic_curve. -Axiom ethereum_crypto_elliptic_curve_SECP256K1N : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". -Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.ethash. -Axiom ethereum_ethash_dataset_size : - IsGlobalAlias globals ethereum.ethash.globals "dataset_size". -Axiom ethereum_ethash_generate_cache : - IsGlobalAlias globals ethereum.ethash.globals "generate_cache". -Axiom ethereum_ethash_hashimoto_light : - IsGlobalAlias globals ethereum.ethash.globals "hashimoto_light". - -Require ethereum.exceptions. -Axiom ethereum_exceptions_InvalidBlock : - IsGlobalAlias globals ethereum.exceptions.globals "InvalidBlock". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U64 : - IsGlobalAlias globals ethereum.base_types.globals "U64". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_U256_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.tangerine_whistle.__init__. -Axiom ethereum_tangerine_whistle___init___vm : - IsGlobalAlias globals ethereum.tangerine_whistle.__init__.globals "vm". - -Require ethereum.tangerine_whistle.blocks. -Axiom ethereum_tangerine_whistle_blocks_Block : - IsGlobalAlias globals ethereum.tangerine_whistle.blocks.globals "Block". -Axiom ethereum_tangerine_whistle_blocks_Header : - IsGlobalAlias globals ethereum.tangerine_whistle.blocks.globals "Header". -Axiom ethereum_tangerine_whistle_blocks_Log : - IsGlobalAlias globals ethereum.tangerine_whistle.blocks.globals "Log". -Axiom ethereum_tangerine_whistle_blocks_Receipt : - IsGlobalAlias globals ethereum.tangerine_whistle.blocks.globals "Receipt". - -Require ethereum.tangerine_whistle.bloom. -Axiom ethereum_tangerine_whistle_bloom_logs_bloom : - IsGlobalAlias globals ethereum.tangerine_whistle.bloom.globals "logs_bloom". - -Require ethereum.tangerine_whistle.fork_types. -Axiom ethereum_tangerine_whistle_fork_types_Address : - IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "Address". -Axiom ethereum_tangerine_whistle_fork_types_Bloom : - IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "Bloom". -Axiom ethereum_tangerine_whistle_fork_types_Root : - IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "Root". - -Require ethereum.tangerine_whistle.state. -Axiom ethereum_tangerine_whistle_state_State : - IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "State". -Axiom ethereum_tangerine_whistle_state_create_ether : - IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "create_ether". -Axiom ethereum_tangerine_whistle_state_destroy_account : - IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "destroy_account". -Axiom ethereum_tangerine_whistle_state_get_account : - IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "get_account". -Axiom ethereum_tangerine_whistle_state_increment_nonce : - IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "increment_nonce". -Axiom ethereum_tangerine_whistle_state_set_account_balance : - IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "set_account_balance". -Axiom ethereum_tangerine_whistle_state_state_root : - IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "state_root". - -Require ethereum.tangerine_whistle.transactions. -Axiom ethereum_tangerine_whistle_transactions_TX_BASE_COST : - IsGlobalAlias globals ethereum.tangerine_whistle.transactions.globals "TX_BASE_COST". -Axiom ethereum_tangerine_whistle_transactions_TX_CREATE_COST : - IsGlobalAlias globals ethereum.tangerine_whistle.transactions.globals "TX_CREATE_COST". -Axiom ethereum_tangerine_whistle_transactions_TX_DATA_COST_PER_NON_ZERO : - IsGlobalAlias globals ethereum.tangerine_whistle.transactions.globals "TX_DATA_COST_PER_NON_ZERO". -Axiom ethereum_tangerine_whistle_transactions_TX_DATA_COST_PER_ZERO : - IsGlobalAlias globals ethereum.tangerine_whistle.transactions.globals "TX_DATA_COST_PER_ZERO". -Axiom ethereum_tangerine_whistle_transactions_Transaction : - IsGlobalAlias globals ethereum.tangerine_whistle.transactions.globals "Transaction". - -Require ethereum.tangerine_whistle.trie. -Axiom ethereum_tangerine_whistle_trie_Trie : - IsGlobalAlias globals ethereum.tangerine_whistle.trie.globals "Trie". -Axiom ethereum_tangerine_whistle_trie_root : - IsGlobalAlias globals ethereum.tangerine_whistle.trie.globals "root". -Axiom ethereum_tangerine_whistle_trie_trie_set : - IsGlobalAlias globals ethereum.tangerine_whistle.trie.globals "trie_set". - -Require ethereum.tangerine_whistle.utils.message. -Axiom ethereum_tangerine_whistle_utils_message_prepare_message : - IsGlobalAlias globals ethereum.tangerine_whistle.utils.message.globals "prepare_message". - -Require ethereum.tangerine_whistle.vm.interpreter. -Axiom ethereum_tangerine_whistle_vm_interpreter_process_message_call : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.interpreter.globals "process_message_call". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Bytes0" ]. + +Axiom ethereum_crypto_elliptic_curve_imports : + AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. + +Axiom ethereum_ethash_imports : + AreImported globals "ethereum.ethash" [ "dataset_size"; "generate_cache"; "hashimoto_light" ]. + +Axiom ethereum_exceptions_imports : + AreImported globals "ethereum.exceptions" [ "InvalidBlock" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U64"; "U256"; "U256_CEIL_VALUE"; "Bytes"; "Bytes32"; "Uint" ]. + +Axiom ethereum_tangerine_whistle_imports : + AreImported globals "ethereum.tangerine_whistle" [ "vm" ]. + +Axiom ethereum_tangerine_whistle_blocks_imports : + AreImported globals "ethereum.tangerine_whistle.blocks" [ "Block"; "Header"; "Log"; "Receipt" ]. + +Axiom ethereum_tangerine_whistle_bloom_imports : + AreImported globals "ethereum.tangerine_whistle.bloom" [ "logs_bloom" ]. + +Axiom ethereum_tangerine_whistle_fork_types_imports : + AreImported globals "ethereum.tangerine_whistle.fork_types" [ "Address"; "Bloom"; "Root" ]. + +Axiom ethereum_tangerine_whistle_state_imports : + AreImported globals "ethereum.tangerine_whistle.state" [ "State"; "create_ether"; "destroy_account"; "get_account"; "increment_nonce"; "set_account_balance"; "state_root" ]. + +Axiom ethereum_tangerine_whistle_transactions_imports : + AreImported globals "ethereum.tangerine_whistle.transactions" [ "TX_BASE_COST"; "TX_CREATE_COST"; "TX_DATA_COST_PER_NON_ZERO"; "TX_DATA_COST_PER_ZERO"; "Transaction" ]. + +Axiom ethereum_tangerine_whistle_trie_imports : + AreImported globals "ethereum.tangerine_whistle.trie" [ "Trie"; "root"; "trie_set" ]. + +Axiom ethereum_tangerine_whistle_utils_message_imports : + AreImported globals "ethereum.tangerine_whistle.utils.message" [ "prepare_message" ]. + +Axiom ethereum_tangerine_whistle_vm_interpreter_imports : + AreImported globals "ethereum.tangerine_whistle.vm.interpreter" [ "process_message_call" ]. Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -248,7 +171,12 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := Hashes of the recent 256 blocks in order of increasing block number. " in let recent_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) in + M.slice (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| Constant.int 255 |), + Constant.None_, + Constant.None_ + |) in let _ := (* if *) M.if_then_else (| @@ -274,17 +202,26 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := )) |) in let recent_block_hashes := make_list [] in - For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_blocks" |) do - let prev_block_hash := - M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "block" |), + M.get_name (| globals, "recent_blocks" |), + ltac:(M.monadic ( + let prev_block_hash := + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in + let _ := M.call (| M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), make_list [ M.get_name (| globals, "prev_block_hash" |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let most_recent_block_hash := M.call (| M.get_name (| globals, "keccak256" |), @@ -292,7 +229,10 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), make_list [ - M.get_field (| M.get_subscript (| M.get_name (| globals, "recent_blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) + M.get_field (| M.get_subscript (| + M.get_name (| globals, "recent_blocks" |), + UnOp.sub (| Constant.int 1 |) + |), "header" |) ], make_dict [] |) @@ -336,7 +276,10 @@ Definition state_transition : Value.t -> Value.t -> M := Block to apply to `chain`. " in let parent_header := - M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 1 |) |), "header" |) in + M.get_field (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| Constant.int 1 |) + |), "header" |) in let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ @@ -455,7 +398,12 @@ Definition state_transition : Value.t -> Value.t -> M := ltac:(M.monadic ( let _ := M.assign (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| Constant.int 255 |), Constant.None_ |) |) + M.slice (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| Constant.int 255 |), + Constant.None_, + Constant.None_ + |) |) in M.pure Constant.None_ (* else *) @@ -871,14 +819,18 @@ Definition apply_body : Value.t -> Value.t -> M := (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) - For make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "tx" |) ] in M.call (| - M.get_name (| globals, "enumerate" |), - make_list [ - M.get_name (| globals, "transactions" |) - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "tx" |) ], + M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "transactions" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ M.get_name (| globals, "transactions_trie" |); @@ -899,56 +851,56 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_address := - M.call (| - M.get_name (| globals, "check_transaction" |), - make_list [ - M.get_name (| globals, "tx" |); - M.get_name (| globals, "gas_available" |) - ], - make_dict [] - |) in - let env := - M.call (| - M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), - make_list [], - make_dict [] - |) in - let _ := M.assign (| - make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |) ], - M.call (| - M.get_name (| globals, "process_transaction" |), - make_list [ - M.get_name (| globals, "env" |); - M.get_name (| globals, "tx" |) - ], - make_dict [] - |) - |) in - let gas_available := BinOp.sub - M.get_name (| globals, "gas_used" |) - M.get_name (| globals, "gas_used" |) in - let receipt := - M.call (| - M.get_name (| globals, "make_receipt" |), - make_list [ - M.get_name (| globals, "tx" |); + let sender_address := M.call (| - M.get_name (| globals, "state_root" |), + M.get_name (| globals, "check_transaction" |), make_list [ - M.get_name (| globals, "state" |) + M.get_name (| globals, "tx" |); + M.get_name (| globals, "gas_available" |) ], make_dict [] - |); - BinOp.sub (| - M.get_name (| globals, "block_gas_limit" |), - M.get_name (| globals, "gas_available" |) - |); - M.get_name (| globals, "logs" |) - ], - make_dict [] - |) in - let _ := M.call (| + |) in + let env := + M.call (| + M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), + make_list [], + make_dict [] + |) in + let _ := M.assign (| + make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |) ], + M.call (| + M.get_name (| globals, "process_transaction" |), + make_list [ + M.get_name (| globals, "env" |); + M.get_name (| globals, "tx" |) + ], + make_dict [] + |) + |) in + let gas_available := BinOp.sub + M.get_name (| globals, "gas_used" |) + M.get_name (| globals, "gas_used" |) in + let receipt := + M.call (| + M.get_name (| globals, "make_receipt" |), + make_list [ + M.get_name (| globals, "tx" |); + M.call (| + M.get_name (| globals, "state_root" |), + make_list [ + M.get_name (| globals, "state" |) + ], + make_dict [] + |); + BinOp.sub (| + M.get_name (| globals, "block_gas_limit" |), + M.get_name (| globals, "gas_available" |) + |); + M.get_name (| globals, "logs" |) + ], + make_dict [] + |) in + let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ M.get_name (| globals, "receipts_trie" |); @@ -969,10 +921,15 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_logs := BinOp.add - M.get_name (| globals, "logs" |) - M.get_name (| globals, "logs" |) in - EndFor. + let block_logs := BinOp.add + M.get_name (| globals, "logs" |) + M.get_name (| globals, "logs" |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.call (| M.get_name (| globals, "pay_rewards" |), make_list [ @@ -1101,8 +1058,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "ommer" |), + M.get_name (| globals, "ommers" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ BoolOp.and (| @@ -1121,15 +1082,18 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_parent_header := - M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), BinOp.sub (| - UnOp.sub (| BinOp.sub (| - M.get_field (| M.get_name (| globals, "block_header" |), "number" |), - M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) |), - Constant.int 1 - |) |), "header" |) in - let _ := M.call (| + let ommer_parent_header := + M.get_field (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + BinOp.sub (| + UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) |), + Constant.int 1 + |) + |), "header" |) in + let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ M.get_name (| globals, "ommer" |); @@ -1137,7 +1101,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1187,33 +1156,54 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |) in let recent_canonical_blocks := - M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), M.slice (| UnOp.sub (| BinOp.add (| - M.get_name (| globals, "MAX_OMMER_DEPTH" |), - Constant.int 1 - |) |), Constant.None_ |) |) in + M.slice (| + M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), + UnOp.sub (| BinOp.add (| + M.get_name (| globals, "MAX_OMMER_DEPTH" |), + Constant.int 1 + |) |), + Constant.None_, + Constant.None_ + |) in let recent_canonical_block_hashes := Constant.str "(* At expr: unsupported node type: SetComp *)" in (* At stmt: unsupported node type: AnnAssign *) - For M.get_name (| globals, "block" |) in M.get_name (| globals, "recent_canonical_blocks" |) do - let recent_ommers_hashes := + let _ := + M.for_ (| + M.get_name (| globals, "block" |), + M.get_name (| globals, "recent_canonical_blocks" |), + ltac:(M.monadic ( + let recent_ommers_hashes := + M.call (| + M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), + make_list [ + Constant.str "(* At expr: unsupported node type: SetComp *)" + ], + make_dict [] + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "ommer_index" |); M.get_name (| globals, "ommer" |) ], M.call (| - M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), - make_list [ - Constant.str "(* At expr: unsupported node type: SetComp *)" - ], - make_dict [] - |) in - EndFor. - For make_tuple [ M.get_name (| globals, "ommer_index" |); M.get_name (| globals, "ommer" |) ] in M.call (| - M.get_name (| globals, "enumerate" |), - make_list [ - M.get_name (| globals, "ommers" |) - ], - make_dict [] - |) do - let ommer_hash := - M.get_subscript (| M.get_name (| globals, "ommers_hashes" |), M.get_name (| globals, "ommer_index" |) |) in - let _ := M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "ommers" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let ommer_hash := + M.get_subscript (| + M.get_name (| globals, "ommers_hashes" |), + M.get_name (| globals, "ommer_index" |) + |) in + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_eq (| @@ -1224,7 +1214,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_in (| @@ -1235,7 +1225,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_in (| @@ -1246,12 +1236,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_age := - BinOp.sub (| - M.get_field (| M.get_name (| globals, "block_header" |), "number" |), - M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) in - let _ := M.call (| + let ommer_age := + BinOp.sub (| + M.get_field (| M.get_name (| globals, "block_header" |), "number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) in + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ BoolOp.and (| @@ -1270,10 +1260,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ - Compare.in (| + Compare.in_ (| M.get_field (| M.get_name (| globals, "ommer" |), "parent_hash" |), M.get_name (| globals, "recent_canonical_block_hashes" |) |); @@ -1281,7 +1271,7 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let _ := M.call (| + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_eq (| @@ -1292,7 +1282,12 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_)). Definition pay_rewards : Value.t -> Value.t -> M := @@ -1349,30 +1344,34 @@ Definition pay_rewards : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "ommer" |) in M.get_name (| globals, "ommers" |) do - let ommer_age := - M.call (| - M.get_name (| globals, "U256" |), - make_list [ - BinOp.sub (| - M.get_name (| globals, "block_number" |), - M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) - ], - make_dict [] - |) in - let ommer_miner_reward := - BinOp.floor_div (| - BinOp.mult (| - BinOp.sub (| - Constant.int 8, - M.get_name (| globals, "ommer_age" |) - |), - M.get_name (| globals, "BLOCK_REWARD" |) - |), - Constant.int 8 - |) in - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "ommer" |), + M.get_name (| globals, "ommers" |), + ltac:(M.monadic ( + let ommer_age := + M.call (| + M.get_name (| globals, "U256" |), + make_list [ + BinOp.sub (| + M.get_name (| globals, "block_number" |), + M.get_field (| M.get_name (| globals, "ommer" |), "number" |) + |) + ], + make_dict [] + |) in + let ommer_miner_reward := + BinOp.floor_div (| + BinOp.mult (| + BinOp.sub (| + Constant.int 8, + M.get_name (| globals, "ommer_age" |) + |), + M.get_name (| globals, "BLOCK_REWARD" |) + |), + Constant.int 8 + |) in + let _ := M.call (| M.get_name (| globals, "create_ether" |), make_list [ M.get_name (| globals, "state" |); @@ -1381,7 +1380,12 @@ Definition pay_rewards : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_)). Definition process_transaction : Value.t -> Value.t -> M := @@ -1621,8 +1625,12 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "address" |) in M.get_field (| M.get_name (| globals, "output" |), "accounts_to_delete" |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "address" |), + M.get_field (| M.get_name (| globals, "output" |), "accounts_to_delete" |), + ltac:(M.monadic ( + let _ := M.call (| M.get_name (| globals, "destroy_account" |), make_list [ M.get_field (| M.get_name (| globals, "env" |), "state" |); @@ -1630,7 +1638,12 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| make_tuple [ M.get_name (| globals, "total_gas_used" |); M.get_field (| M.get_name (| globals, "output" |), "logs" |) ] |) in @@ -1718,28 +1731,37 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := " in let data_cost := Constant.int 0 in - For M.get_name (| globals, "byte" |) in M.get_field (| M.get_name (| globals, "tx" |), "data" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "byte" |), - Constant.int 0 - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "byte" |), + M.get_field (| M.get_name (| globals, "tx" |), "data" |), ltac:(M.monadic ( - let data_cost := BinOp.add - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "byte" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let data_cost := BinOp.add + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) + M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let data_cost := BinOp.add - M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := (* if *) M.if_then_else (| @@ -1891,13 +1913,18 @@ Definition recover_sender : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "Address" |), make_list [ - M.get_subscript (| M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "public_key" |) - ], - make_dict [] - |), M.slice (| Constant.int 12, Constant.int 32 |) |) + M.slice (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), + Constant.int 12, + Constant.int 32, + Constant.None_ + |) ], make_dict [] |) diff --git a/CoqOfPython/ethereum/tangerine_whistle/fork_types.v b/CoqOfPython/ethereum/tangerine_whistle/fork_types.v index cc8e4a1..58d7a57 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/fork_types.v +++ b/CoqOfPython/ethereum/tangerine_whistle/fork_types.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.tangerine_whistle.fork_types". Definition expr_1 : Value.t := Constant.str " @@ -17,33 +17,17 @@ Introduction Types re-used throughout the specification, which are specific to Ethereum. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes20 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes20". -Axiom ethereum_base_types_Bytes256 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes20"; "Bytes256"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) diff --git a/CoqOfPython/ethereum/tangerine_whistle/state.v b/CoqOfPython/ethereum/tangerine_whistle/state.v index 3b6122d..26851e6 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/state.v +++ b/CoqOfPython/ethereum/tangerine_whistle/state.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.tangerine_whistle.state". Definition expr_1 : Value.t := Constant.str " @@ -22,61 +22,23 @@ There is a distinction between an account that does not exist and `EMPTY_ACCOUNT`. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". -Axiom dataclasses_field : - IsGlobalAlias globals dataclasses.globals "field". - -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_modify : - IsGlobalAlias globals ethereum.base_types.globals "modify". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.tangerine_whistle.fork_types. -Axiom ethereum_tangerine_whistle_fork_types_EMPTY_ACCOUNT : - IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "EMPTY_ACCOUNT". -Axiom ethereum_tangerine_whistle_fork_types_Account : - IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "Account". -Axiom ethereum_tangerine_whistle_fork_types_Address : - IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "Address". -Axiom ethereum_tangerine_whistle_fork_types_Root : - IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "Root". - -Require ethereum.tangerine_whistle.trie. -Axiom ethereum_tangerine_whistle_trie_EMPTY_TRIE_ROOT : - IsGlobalAlias globals ethereum.tangerine_whistle.trie.globals "EMPTY_TRIE_ROOT". -Axiom ethereum_tangerine_whistle_trie_Trie : - IsGlobalAlias globals ethereum.tangerine_whistle.trie.globals "Trie". -Axiom ethereum_tangerine_whistle_trie_copy_trie : - IsGlobalAlias globals ethereum.tangerine_whistle.trie.globals "copy_trie". -Axiom ethereum_tangerine_whistle_trie_root : - IsGlobalAlias globals ethereum.tangerine_whistle.trie.globals "root". -Axiom ethereum_tangerine_whistle_trie_trie_get : - IsGlobalAlias globals ethereum.tangerine_whistle.trie.globals "trie_get". -Axiom ethereum_tangerine_whistle_trie_trie_set : - IsGlobalAlias globals ethereum.tangerine_whistle.trie.globals "trie_set". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass"; "field" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict"; "List"; "Optional"; "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "modify" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_tangerine_whistle_fork_types_imports : + AreImported globals "ethereum.tangerine_whistle.fork_types" [ "EMPTY_ACCOUNT"; "Account"; "Address"; "Root" ]. + +Axiom ethereum_tangerine_whistle_trie_imports : + AreImported globals "ethereum.tangerine_whistle.trie" [ "EMPTY_TRIE_ROOT"; "Trie"; "copy_trie"; "root"; "trie_get"; "trie_set" ]. Definition State : Value.t := builtins.make_klass @@ -338,13 +300,16 @@ Definition destroy_storage : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -479,7 +444,10 @@ Definition set_storage : Value.t -> Value.t -> M := make_dict [] |) in let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |), + M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |), M.get_name (| globals, "trie" |) |) in M.pure Constant.None_ @@ -505,7 +473,10 @@ Definition set_storage : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -535,7 +506,7 @@ Definition storage_root : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "address" |), M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |) |), @@ -545,7 +516,10 @@ Definition storage_root : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "root" |), make_list [ - M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), M.get_name (| globals, "address" |) |) + M.get_subscript (| + M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), + M.get_name (| globals, "address" |) + |) ], make_dict [] |) diff --git a/CoqOfPython/ethereum/tangerine_whistle/transactions.v b/CoqOfPython/ethereum/tangerine_whistle/transactions.v index 4d58502..29fdcd2 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/transactions.v +++ b/CoqOfPython/ethereum/tangerine_whistle/transactions.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.tangerine_whistle.transactions". Definition expr_1 : Value.t := Constant.str " @@ -9,29 +9,17 @@ submitted to be executed. If Ethereum is viewed as a state machine, transactions are the events that move between states. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.tangerine_whistle.fork_types. -Axiom ethereum_tangerine_whistle_fork_types_Address : - IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "Address". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Union" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_tangerine_whistle_fork_types_imports : + AreImported globals "ethereum.tangerine_whistle.fork_types" [ "Address" ]. Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( Constant.int 21000 diff --git a/CoqOfPython/ethereum/tangerine_whistle/trie.v b/CoqOfPython/ethereum/tangerine_whistle/trie.v index 77642c6..02f7b48 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/trie.v +++ b/CoqOfPython/ethereum/tangerine_whistle/trie.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.tangerine_whistle.trie". Definition expr_1 : Value.t := Constant.str " @@ -20,83 +20,38 @@ The state trie is the structure responsible for storing (* At top_level_stmt: unsupported node type: Import *) -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". -Axiom dataclasses_field : - IsGlobalAlias globals dataclasses.globals "field". - -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". -Axiom typing_Generic : - IsGlobalAlias globals typing.globals "Generic". -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Mapping : - IsGlobalAlias globals typing.globals "Mapping". -Axiom typing_MutableMapping : - IsGlobalAlias globals typing.globals "MutableMapping". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Sequence : - IsGlobalAlias globals typing.globals "Sequence". -Axiom typing_TypeVar : - IsGlobalAlias globals typing.globals "TypeVar". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". -Axiom typing_cast : - IsGlobalAlias globals typing.globals "cast". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.dao_fork.__init__. -Axiom ethereum_dao_fork___init___trie : - IsGlobalAlias globals ethereum.dao_fork.__init__.globals "trie". - -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". - -Require ethereum.utils.hexadecimal. -Axiom ethereum_utils_hexadecimal_hex_to_bytes : - IsGlobalAlias globals ethereum.utils.hexadecimal.globals "hex_to_bytes". - -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". -Axiom ethereum_base_types_slotted_freezable : - IsGlobalAlias globals ethereum.base_types.globals "slotted_freezable". - -Require ethereum.tangerine_whistle.blocks. -Axiom ethereum_tangerine_whistle_blocks_Receipt : - IsGlobalAlias globals ethereum.tangerine_whistle.blocks.globals "Receipt". - -Require ethereum.tangerine_whistle.fork_types. -Axiom ethereum_tangerine_whistle_fork_types_Account : - IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "Account". -Axiom ethereum_tangerine_whistle_fork_types_Address : - IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "Address". -Axiom ethereum_tangerine_whistle_fork_types_Root : - IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "Root". -Axiom ethereum_tangerine_whistle_fork_types_encode_account : - IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "encode_account". - -Require ethereum.tangerine_whistle.transactions. -Axiom ethereum_tangerine_whistle_transactions_Transaction : - IsGlobalAlias globals ethereum.tangerine_whistle.transactions.globals "Transaction". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass"; "field" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict"; "Generic"; "List"; "Mapping"; "MutableMapping"; "Optional"; "Sequence"; "TypeVar"; "Union"; "cast" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. + +Axiom ethereum_dao_fork_imports : + AreImported globals "ethereum.dao_fork" [ "trie" ]. + +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. + +Axiom ethereum_utils_hexadecimal_imports : + AreImported globals "ethereum.utils.hexadecimal" [ "hex_to_bytes" ]. + +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "slotted_freezable" ]. + +Axiom ethereum_tangerine_whistle_blocks_imports : + AreImported globals "ethereum.tangerine_whistle.blocks" [ "Receipt" ]. + +Axiom ethereum_tangerine_whistle_fork_types_imports : + AreImported globals "ethereum.tangerine_whistle.fork_types" [ "Account"; "Address"; "Root"; "encode_account" ]. + +Axiom ethereum_tangerine_whistle_transactions_imports : + AreImported globals "ethereum.tangerine_whistle.transactions" [ "Transaction" ]. Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -115,7 +70,10 @@ Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( )). Definition Node : Value.t := M.run ltac:(M.monadic ( - M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Bytes" |); M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |); Constant.None_ ] |) + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Bytes" |); M.get_name (| globals, "Transaction" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |); Constant.None_ ] + |) )). Definition K : Value.t := M.run ltac:(M.monadic ( @@ -133,11 +91,23 @@ Definition V : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "TypeVar" |), make_list [ Constant.str "V"; - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Account" |) |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Bytes" |) |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Account" |) + |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Bytes" |) + |); M.get_name (| globals, "Bytes" |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Transaction" |) |); - M.get_subscript (| M.get_name (| globals, "Optional" |), M.get_name (| globals, "Receipt" |) |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Transaction" |) + |); + M.get_subscript (| + M.get_name (| globals, "Optional" |), + M.get_name (| globals, "Receipt" |) + |); M.get_name (| globals, "Uint" |); M.get_name (| globals, "U256" |) ], @@ -176,7 +146,10 @@ Definition BranchNode : Value.t := ]. Definition InternalNode : Value.t := M.run ltac:(M.monadic ( - M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "LeafNode" |); M.get_name (| globals, "ExtensionNode" |); M.get_name (| globals, "BranchNode" |) ] |) + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "LeafNode" |); M.get_name (| globals, "ExtensionNode" |); M.get_name (| globals, "BranchNode" |) ] + |) )). Definition encode_internal_node : Value.t -> Value.t -> M := @@ -288,7 +261,7 @@ Definition encode_internal_node : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "(* At expr: unsupported node type: JoinedStr *)" @@ -528,13 +501,16 @@ Definition trie_set : Value.t -> Value.t -> M := let _ := (* if *) M.if_then_else (| - Compare.in (| + Compare.in_ (| M.get_name (| globals, "key" |), M.get_field (| M.get_name (| globals, "trie" |), "_data" |) |), (* then *) ltac:(M.monadic ( - let _ := M.delete (| M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |) |) in + let _ := M.delete (| M.get_subscript (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + M.get_name (| globals, "key" |) + |) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -544,7 +520,10 @@ Definition trie_set : Value.t -> Value.t -> M := (* else *) )), ltac:(M.monadic ( let _ := M.assign (| - M.get_subscript (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), M.get_name (| globals, "key" |) |), + M.get_subscript (| + M.get_field (| M.get_name (| globals, "trie" |), "_data" |), + M.get_name (| globals, "key" |) + |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_ @@ -589,51 +568,66 @@ Definition common_prefix_length : Value.t -> Value.t -> M := let _ := Constant.str " Find the longest common prefix of two sequences. " in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "a" |) - ], - make_dict [] - |) - ], - make_dict [] - |) do - let _ := - (* if *) - M.if_then_else (| - BoolOp.or (| - Compare.gt_e (| - M.get_name (| globals, "i" |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "b" |) - ], - make_dict [] - |) - |), - ltac:(M.monadic ( - Compare.not_eq (| - M.get_subscript (| M.get_name (| globals, "a" |), M.get_name (| globals, "i" |) |), - M.get_subscript (| M.get_name (| globals, "b" |), M.get_name (| globals, "i" |) |) - |) - )) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "a" |) + ], + make_dict [] + |) + ], + make_dict [] + |), ltac:(M.monadic ( - let _ := M.return_ (| - M.get_name (| globals, "i" |) - |) in + let _ := + (* if *) + M.if_then_else (| + BoolOp.or (| + Compare.gt_e (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "b" |) + ], + make_dict [] + |) + |), + ltac:(M.monadic ( + Compare.not_eq (| + M.get_subscript (| + M.get_name (| globals, "a" |), + M.get_name (| globals, "i" |) + |), + M.get_subscript (| + M.get_name (| globals, "b" |), + M.get_name (| globals, "i" |) + |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + M.get_name (| globals, "i" |) + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "len" |), @@ -718,38 +712,53 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 0; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |); - Constant.int 2 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ BinOp.add (| BinOp.mult (| Constant.int 16, - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "i" |) + |) |), - M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) + |) |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -767,43 +776,61 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := Constant.int 1 |) |), - M.get_subscript (| M.get_name (| globals, "x" |), Constant.int 0 |) + M.get_subscript (| + M.get_name (| globals, "x" |), + Constant.int 0 + |) |) ], make_dict [] |) in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 1; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "x" |) - ], - make_dict [] - |); - Constant.int 2 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 1; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "x" |) + ], + make_dict [] + |); + Constant.int 2 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "compact" |), "append" |), make_list [ BinOp.add (| BinOp.mult (| Constant.int 16, - M.get_subscript (| M.get_name (| globals, "x" |), M.get_name (| globals, "i" |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + M.get_name (| globals, "i" |) + |) |), - M.get_subscript (| M.get_name (| globals, "x" |), BinOp.add (| - M.get_name (| globals, "i" |), - Constant.int 1 - |) |) + M.get_subscript (| + M.get_name (| globals, "x" |), + BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 1 + |) + |) |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -850,40 +877,55 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := ], make_dict [] |) in - For make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ] in M.call (| - M.get_name (| globals, "enumerate" |), - make_list [ - M.get_name (| globals, "bytes_" |) - ], - make_dict [] - |) do - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.mult (| - M.get_name (| globals, "byte_index" |), - Constant.int 2 - |) |), - BinOp.r_shift (| - BinOp.bit_and (| - M.get_name (| globals, "byte" |), - Constant.int 240 - |), - Constant.int 4 - |) - |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "nibble_list" |), BinOp.add (| - BinOp.mult (| - M.get_name (| globals, "byte_index" |), - Constant.int 2 - |), - Constant.int 1 - |) |), - BinOp.bit_and (| - M.get_name (| globals, "byte" |), - Constant.int 15 - |) - |) in - EndFor. + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ], + M.call (| + M.get_name (| globals, "enumerate" |), + make_list [ + M.get_name (| globals, "bytes_" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "nibble_list" |), + BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |) + |), + BinOp.r_shift (| + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 240 + |), + Constant.int 4 + |) + |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "nibble_list" |), + BinOp.add (| + BinOp.mult (| + M.get_name (| globals, "byte_index" |), + Constant.int 2 + |), + Constant.int 1 + |) + |), + BinOp.bit_and (| + M.get_name (| globals, "byte" |), + Constant.int 15 + |) + |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Bytes" |), @@ -916,65 +958,69 @@ Definition _prepare_trie : Value.t -> Value.t -> M := Object with keys mapped to nibble-byte form. " in (* At stmt: unsupported node type: AnnAssign *) - For make_tuple [ M.get_name (| globals, "preimage" |); M.get_name (| globals, "value" |) ] in M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "items" |), - make_list [], - make_dict [] - |) do - let _ := - (* if *) - M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_name (| globals, "value" |); - M.get_name (| globals, "Account" |) - ], - make_dict [] - |), - (* then *) + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "preimage" |); M.get_name (| globals, "value" |) ], + M.call (| + M.get_field (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), "items" |), + make_list [], + make_dict [] + |), ltac:(M.monadic ( - let _ := M.assert (| Compare.is_not (| + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_name (| globals, "value" |); + M.get_name (| globals, "Account" |) + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.assert (| Compare.is_not (| M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in - let address := - M.call (| - M.get_name (| globals, "Address" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in - let encoded_value := - M.call (| - M.get_name (| globals, "encode_node" |), - make_list [ - M.get_name (| globals, "value" |); + let address := M.call (| - M.get_name (| globals, "get_storage_root" |), + M.get_name (| globals, "Address" |), make_list [ - M.get_name (| globals, "address" |) + M.get_name (| globals, "preimage" |) ], make_dict [] - |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let encoded_value := - M.call (| - M.get_name (| globals, "encode_node" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - )) |) in - let _ := M.call (| + |) in + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |); + M.call (| + M.get_name (| globals, "get_storage_root" |), + make_list [ + M.get_name (| globals, "address" |) + ], + make_dict [] + |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let encoded_value := + M.call (| + M.get_name (| globals, "encode_node" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + )) |) in + let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ Compare.not_eq (| @@ -986,38 +1032,46 @@ Definition _prepare_trie : Value.t -> Value.t -> M := make_dict [] |) in (* At stmt: unsupported node type: AnnAssign *) - let _ := - (* if *) - M.if_then_else (| - M.get_field (| M.get_name (| globals, "trie" |), "secured" |), - (* then *) - ltac:(M.monadic ( - let key := - M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "preimage" |) - ], - make_dict [] - |) in + let _ := + (* if *) + M.if_then_else (| + M.get_field (| M.get_name (| globals, "trie" |), "secured" |), + (* then *) + ltac:(M.monadic ( + let key := + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "preimage" |) + ], + make_dict [] + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + let key := + M.get_name (| globals, "preimage" |) in + M.pure Constant.None_ + )) |) in + let _ := M.assign (| + M.get_subscript (| + M.get_name (| globals, "mapped" |), + M.call (| + M.get_name (| globals, "bytes_to_nibble_list" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |) + |), + M.get_name (| globals, "encoded_value" |) + |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let key := - M.get_name (| globals, "preimage" |) in + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "mapped" |), M.call (| - M.get_name (| globals, "bytes_to_nibble_list" |), - make_list [ - M.get_name (| globals, "key" |) - ], - make_dict [] - |) |), - M.get_name (| globals, "encoded_value" |) - |) in - EndFor. + )) + |) in let _ := M.return_ (| M.get_name (| globals, "mapped" |) |) in @@ -1210,8 +1264,16 @@ Definition patricialize : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "LeafNode" |), make_list [ - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |); - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "arbitrary_key" |) |) + M.slice (| + M.get_name (| globals, "arbitrary_key" |), + M.get_name (| globals, "level" |), + Constant.None_, + Constant.None_ + |); + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "arbitrary_key" |) + |) ], make_dict [] |) in @@ -1224,7 +1286,12 @@ Definition patricialize : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in let substring := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "arbitrary_key" |), + M.get_name (| globals, "level" |), + Constant.None_, + Constant.None_ + |) in let prefix_length := M.call (| M.get_name (| globals, "len" |), @@ -1233,39 +1300,53 @@ Definition patricialize : Value.t -> Value.t -> M := ], make_dict [] |) in - For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do - let prefix_length := - M.call (| - M.get_name (| globals, "min" |), - make_list [ - M.get_name (| globals, "prefix_length" |); + let _ := + M.for_ (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "obj" |), + ltac:(M.monadic ( + let prefix_length := M.call (| - M.get_name (| globals, "common_prefix_length" |), + M.get_name (| globals, "min" |), make_list [ - M.get_name (| globals, "substring" |); - M.get_subscript (| M.get_name (| globals, "key" |), M.slice (| M.get_name (| globals, "level" |), Constant.None_ |) |) + M.get_name (| globals, "prefix_length" |); + M.call (| + M.get_name (| globals, "common_prefix_length" |), + make_list [ + M.get_name (| globals, "substring" |); + M.slice (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "level" |), + Constant.None_, + Constant.None_ + |) + ], + make_dict [] + |) ], make_dict [] - |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "prefix_length" |), - Constant.int 0 - |), - (* then *) - ltac:(M.monadic ( - let _ := M.break (| |) in + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "prefix_length" |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.break (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := (* if *) M.if_then_else (| @@ -1276,10 +1357,15 @@ Definition patricialize : Value.t -> Value.t -> M := (* then *) ltac:(M.monadic ( let prefix := - M.get_subscript (| M.get_name (| globals, "arbitrary_key" |), M.slice (| M.get_name (| globals, "level" |), BinOp.add (| + M.slice (| + M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |), - M.get_name (| globals, "prefix_length" |) - |) |) |) in + BinOp.add (| + M.get_name (| globals, "level" |), + M.get_name (| globals, "prefix_length" |) + |), + Constant.None_ + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ExtensionNode" |), @@ -1312,70 +1398,106 @@ Definition patricialize : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: AnnAssign *) - For M.get_name (| globals, "_" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 16 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "_" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 16 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "branches" |), "append" |), make_list [ {} ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let value := Constant.bytes "" in - For M.get_name (| globals, "key" |) in M.get_name (| globals, "obj" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "key" |) - ], - make_dict [] - |), - M.get_name (| globals, "level" |) - |), - (* then *) + let _ := + M.for_ (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "obj" |), ltac:(M.monadic ( let _ := (* if *) M.if_then_else (| - M.call (| - M.get_name (| globals, "isinstance" |), - make_list [ - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |); - make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] - ], - make_dict [] + Compare.eq (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "key" |) + ], + make_dict [] + |), + M.get_name (| globals, "level" |) |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "AssertionError" |)) |) in + let _ := + (* if *) + M.if_then_else (| + M.call (| + M.get_name (| globals, "isinstance" |), + make_list [ + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "key" |) + |); + make_tuple [ M.get_name (| globals, "Account" |); M.get_name (| globals, "Receipt" |); M.get_name (| globals, "Uint" |) ] + ], + make_dict [] + |), + (* then *) + ltac:(M.monadic ( + let _ := M.raise (| Some (M.get_name (| globals, "AssertionError" |)) |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let value := + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "key" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( + let _ := M.assign (| + M.get_subscript (| + M.get_subscript (| + M.get_name (| globals, "branches" |), + M.get_subscript (| + M.get_name (| globals, "key" |), + M.get_name (| globals, "level" |) + |) + |), + M.get_name (| globals, "key" |) + |), + M.get_subscript (| + M.get_name (| globals, "obj" |), + M.get_name (| globals, "key" |) + |) + |) in M.pure Constant.None_ )) |) in - let value := - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - let _ := M.assign (| - M.get_subscript (| M.get_subscript (| M.get_name (| globals, "branches" |), M.get_subscript (| M.get_name (| globals, "key" |), M.get_name (| globals, "level" |) |) |), M.get_name (| globals, "key" |) |), - M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) |) - |) in + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "BranchNode" |), diff --git a/CoqOfPython/ethereum/tangerine_whistle/utils/__init__.v b/CoqOfPython/ethereum/tangerine_whistle/utils/__init__.v index 1baedea..c4428f6 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/utils/__init__.v +++ b/CoqOfPython/ethereum/tangerine_whistle/utils/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.tangerine_whistle.utils.__init__". Definition expr_1 : Value.t := Constant.str " diff --git a/CoqOfPython/ethereum/tangerine_whistle/utils/address.v b/CoqOfPython/ethereum/tangerine_whistle/utils/address.v index bed9575..3acee7a 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/utils/address.v +++ b/CoqOfPython/ethereum/tangerine_whistle/utils/address.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.tangerine_whistle.utils.address". Definition expr_1 : Value.t := Constant.str " @@ -18,31 +18,23 @@ Address specific functions used in this tangerine whistle version of specification. ". -Require typing. -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". +Axiom typing_imports : + AreImported globals "typing" [ "Union" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_left_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. -Require ethereum.__init__. -Axiom ethereum___init___rlp : - IsGlobalAlias globals ethereum.__init__.globals "rlp". +Axiom ethereum_imports : + AreImported globals "ethereum" [ "rlp" ]. -Require ethereum.tangerine_whistle.fork_types. -Axiom ethereum_tangerine_whistle_fork_types_Address : - IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "Address". +Axiom ethereum_tangerine_whistle_fork_types_imports : + AreImported globals "ethereum.tangerine_whistle.fork_types" [ "Address" ]. Definition to_address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -64,11 +56,16 @@ Definition to_address : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "Address" |), make_list [ - M.get_subscript (| M.call (| - M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), - make_list [], - make_dict [] - |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) + M.slice (| + M.call (| + M.get_field (| M.get_name (| globals, "data" |), "to_be_bytes32" |), + make_list [], + make_dict [] + |), + UnOp.sub (| Constant.int 20 |), + Constant.None_, + Constant.None_ + |) ], make_dict [] |) @@ -112,7 +109,12 @@ Definition compute_contract_address : Value.t -> Value.t -> M := make_dict [] |) in let canonical_address := - M.get_subscript (| M.get_name (| globals, "computed_address" |), M.slice (| UnOp.sub (| Constant.int 20 |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "computed_address" |), + UnOp.sub (| Constant.int 20 |), + Constant.None_, + Constant.None_ + |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/tangerine_whistle/utils/hexadecimal.v b/CoqOfPython/ethereum/tangerine_whistle/utils/hexadecimal.v index 7c15918..3ba1301 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/tangerine_whistle/utils/hexadecimal.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.tangerine_whistle.utils.hexadecimal". Definition expr_1 : Value.t := Constant.str " @@ -18,17 +18,11 @@ Hexadecimal utility functions used in this specification, specific to Tangerine Whistle types. ". -Require ethereum.utils.hexadecimal. -Axiom ethereum_utils_hexadecimal_remove_hex_prefix : - IsGlobalAlias globals ethereum.utils.hexadecimal.globals "remove_hex_prefix". - -Require ethereum.tangerine_whistle.fork_types. -Axiom ethereum_tangerine_whistle_fork_types_Address : - IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "Address". -Axiom ethereum_tangerine_whistle_fork_types_Bloom : - IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "Bloom". -Axiom ethereum_tangerine_whistle_fork_types_Root : - IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "Root". +Axiom ethereum_utils_hexadecimal_imports : + AreImported globals "ethereum.utils.hexadecimal" [ "remove_hex_prefix" ]. + +Axiom ethereum_tangerine_whistle_fork_types_imports : + AreImported globals "ethereum.tangerine_whistle.fork_types" [ "Address"; "Bloom"; "Root" ]. Definition hex_to_root : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/tangerine_whistle/utils/message.v b/CoqOfPython/ethereum/tangerine_whistle/utils/message.v index 0cf6875..d1c4cdc 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/utils/message.v +++ b/CoqOfPython/ethereum/tangerine_whistle/utils/message.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.tangerine_whistle.utils.message". Definition expr_1 : Value.t := Constant.str " @@ -18,39 +18,23 @@ Message specific functions used in this tangerine whistle version of specification. ". -Require typing. -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". +Axiom typing_imports : + AreImported globals "typing" [ "Optional"; "Union" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint" ]. -Require ethereum.tangerine_whistle.fork_types. -Axiom ethereum_tangerine_whistle_fork_types_Address : - IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "Address". +Axiom ethereum_tangerine_whistle_fork_types_imports : + AreImported globals "ethereum.tangerine_whistle.fork_types" [ "Address" ]. -Require ethereum.tangerine_whistle.state. -Axiom ethereum_tangerine_whistle_state_get_account : - IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "get_account". +Axiom ethereum_tangerine_whistle_state_imports : + AreImported globals "ethereum.tangerine_whistle.state" [ "get_account" ]. -Require ethereum.tangerine_whistle.vm.__init__. -Axiom ethereum_tangerine_whistle_vm___init___Environment : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "Environment". -Axiom ethereum_tangerine_whistle_vm___init___Message : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "Message". +Axiom ethereum_tangerine_whistle_vm_imports : + AreImported globals "ethereum.tangerine_whistle.vm" [ "Environment"; "Message" ]. -Require ethereum.tangerine_whistle.utils.address. -Axiom ethereum_tangerine_whistle_utils_address_compute_contract_address : - IsGlobalAlias globals ethereum.tangerine_whistle.utils.address.globals "compute_contract_address". +Axiom ethereum_tangerine_whistle_utils_address_imports : + AreImported globals "ethereum.tangerine_whistle.utils.address" [ "compute_contract_address" ]. Definition prepare_message : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -180,7 +164,7 @@ Definition prepare_message : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "AssertionError" |), make_list [ Constant.str "Target must be address or empty bytes" diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/__init__.v b/CoqOfPython/ethereum/tangerine_whistle/vm/__init__.v index 3d7480a..f840ed3 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/__init__.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.tangerine_whistle.vm.__init__". Definition expr_1 : Value.t := Constant.str " @@ -18,47 +18,26 @@ The abstract computer which runs the code stored in an `.fork_types.Account`. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". - -Require ethereum.tangerine_whistle.blocks. -Axiom ethereum_tangerine_whistle_blocks_Log : - IsGlobalAlias globals ethereum.tangerine_whistle.blocks.globals "Log". - -Require ethereum.tangerine_whistle.fork_types. -Axiom ethereum_tangerine_whistle_fork_types_Address : - IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "Address". - -Require ethereum.tangerine_whistle.state. -Axiom ethereum_tangerine_whistle_state_State : - IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "State". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple"; "Union" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. + +Axiom ethereum_tangerine_whistle_blocks_imports : + AreImported globals "ethereum.tangerine_whistle.blocks" [ "Log" ]. + +Axiom ethereum_tangerine_whistle_fork_types_imports : + AreImported globals "ethereum.tangerine_whistle.fork_types" [ "Address" ]. + +Axiom ethereum_tangerine_whistle_state_imports : + AreImported globals "ethereum.tangerine_whistle.state" [ "State" ]. Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/exceptions.v b/CoqOfPython/ethereum/tangerine_whistle/vm/exceptions.v index 45435b3..3a03a51 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/exceptions.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/exceptions.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.tangerine_whistle.vm.exceptions". Definition expr_1 : Value.t := Constant.str " @@ -17,9 +17,8 @@ Introduction Exceptions which cause the EVM to halt exceptionally. ". -Require ethereum.exceptions. -Axiom ethereum_exceptions_EthereumException : - IsGlobalAlias globals ethereum.exceptions.globals "EthereumException". +Axiom ethereum_exceptions_imports : + AreImported globals "ethereum.exceptions" [ "EthereumException" ]. Definition ExceptionalHalt : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/gas.v b/CoqOfPython/ethereum/tangerine_whistle/vm/gas.v index 9009607..31134c8 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/gas.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/gas.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.tangerine_whistle.vm.gas". Definition expr_1 : Value.t := Constant.str " @@ -17,39 +17,26 @@ Introduction EVM gas constants and calculators. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_imports : + AreImported globals "typing" [ "List"; "Tuple" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. -Require ethereum.trace. -Axiom ethereum_trace_GasAndRefund : - IsGlobalAlias globals ethereum.trace.globals "GasAndRefund". -Axiom ethereum_trace_evm_trace : - IsGlobalAlias globals ethereum.trace.globals "evm_trace". +Axiom ethereum_trace_imports : + AreImported globals "ethereum.trace" [ "GasAndRefund"; "evm_trace" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.tangerine_whistle.vm.__init__. -Axiom ethereum_tangerine_whistle_vm___init___Evm : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "Evm". +Axiom ethereum_tangerine_whistle_vm_imports : + AreImported globals "ethereum.tangerine_whistle.vm" [ "Evm" ]. -Require ethereum.tangerine_whistle.vm.exceptions. -Axiom ethereum_tangerine_whistle_vm_exceptions_OutOfGasError : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.exceptions.globals "OutOfGasError". +Axiom ethereum_tangerine_whistle_vm_exceptions_imports : + AreImported globals "ethereum.tangerine_whistle.vm.exceptions" [ "OutOfGasError" ]. Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -498,7 +485,7 @@ Definition charge_gas : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "OutOfGasError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "OutOfGasError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -615,105 +602,114 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := ], make_dict [] |) in - For make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ] in M.get_name (| globals, "extensions" |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "size" |), - Constant.int 0 - |), - (* then *) + let _ := + M.for_ (| + make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ], + M.get_name (| globals, "extensions" |), ltac:(M.monadic ( - let _ := M.continue (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let before_size := - M.call (| - M.get_name (| globals, "ceil32" |), - make_list [ - M.get_name (| globals, "current_size" |) - ], - make_dict [] - |) in - let after_size := - M.call (| - M.get_name (| globals, "ceil32" |), - make_list [ - BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + M.get_name (| globals, "size" |), + Constant.int 0 |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) - ], - make_dict [] - |) in - let _ := - (* if *) - M.if_then_else (| - Compare.lt_e (| - M.get_name (| globals, "after_size" |), - M.get_name (| globals, "before_size" |) - |), - (* then *) - ltac:(M.monadic ( - let _ := M.continue (| |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( - M.pure Constant.None_ - )) |) in - let size_to_extend := BinOp.add - BinOp.sub (| + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let before_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + M.get_name (| globals, "current_size" |) + ], + make_dict [] + |) in + let after_size := + M.call (| + M.get_name (| globals, "ceil32" |), + make_list [ + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) + |) + ], + make_dict [] + |) in + let _ := + (* if *) + M.if_then_else (| + Compare.lt_e (| + M.get_name (| globals, "after_size" |), + M.get_name (| globals, "before_size" |) + |), + (* then *) + ltac:(M.monadic ( + let _ := M.continue (| |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in + let size_to_extend := BinOp.add + BinOp.sub (| M.get_name (| globals, "after_size" |), M.get_name (| globals, "before_size" |) |) - BinOp.sub (| + BinOp.sub (| M.get_name (| globals, "after_size" |), M.get_name (| globals, "before_size" |) |) in - let already_paid := - M.call (| - M.get_name (| globals, "calculate_memory_gas_cost" |), - make_list [ - M.get_name (| globals, "before_size" |) - ], - make_dict [] - |) in - let total_cost := - M.call (| - M.get_name (| globals, "calculate_memory_gas_cost" |), - make_list [ - M.get_name (| globals, "after_size" |) - ], - make_dict [] - |) in - let to_be_paid := BinOp.add - BinOp.sub (| + let already_paid := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "before_size" |) + ], + make_dict [] + |) in + let total_cost := + M.call (| + M.get_name (| globals, "calculate_memory_gas_cost" |), + make_list [ + M.get_name (| globals, "after_size" |) + ], + make_dict [] + |) in + let to_be_paid := BinOp.add + BinOp.sub (| M.get_name (| globals, "total_cost" |), M.get_name (| globals, "already_paid" |) |) - BinOp.sub (| + BinOp.sub (| M.get_name (| globals, "total_cost" |), M.get_name (| globals, "already_paid" |) |) in - let current_size := - M.get_name (| globals, "after_size" |) in - EndFor. + let current_size := + M.get_name (| globals, "after_size" |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ExtendMemory" |), diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/__init__.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/__init__.v index 2df87cd..cb5f046 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/__init__.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.tangerine_whistle.vm.instructions.__init__". Definition expr_1 : Value.t := Constant.str " @@ -20,59 +20,44 @@ implementations. (* At top_level_stmt: unsupported node type: Import *) -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict" ]. -Require ethereum.tangerine_whistle.vm.instructions.__init__. -Axiom ethereum_tangerine_whistle_vm_instructions___init___arithmetic : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.instructions.__init__.globals "arithmetic". +Axiom ethereum_tangerine_whistle_vm_instructions_imports : + AreImported globals "ethereum.tangerine_whistle.vm.instructions" [ "arithmetic" ]. -Require ethereum.tangerine_whistle.vm.instructions.__init__. -Axiom ethereum_tangerine_whistle_vm_instructions___init___bitwise : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.instructions.__init__.globals "bitwise". +Axiom ethereum_tangerine_whistle_vm_instructions_imports : + AreImported globals "ethereum.tangerine_whistle.vm.instructions" [ "bitwise" ]. -Require ethereum.tangerine_whistle.vm.instructions.__init__. -Axiom ethereum_tangerine_whistle_vm_instructions___init___block : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.instructions.__init__.globals "block". +Axiom ethereum_tangerine_whistle_vm_instructions_imports : + AreImported globals "ethereum.tangerine_whistle.vm.instructions" [ "block" ]. -Require ethereum.tangerine_whistle.vm.instructions.__init__. -Axiom ethereum_tangerine_whistle_vm_instructions___init___comparison : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.instructions.__init__.globals "comparison". +Axiom ethereum_tangerine_whistle_vm_instructions_imports : + AreImported globals "ethereum.tangerine_whistle.vm.instructions" [ "comparison" ]. -Require ethereum.tangerine_whistle.vm.instructions.__init__. -Axiom ethereum_tangerine_whistle_vm_instructions___init___control_flow : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.instructions.__init__.globals "control_flow". +Axiom ethereum_tangerine_whistle_vm_instructions_imports : + AreImported globals "ethereum.tangerine_whistle.vm.instructions" [ "control_flow" ]. -Require ethereum.tangerine_whistle.vm.instructions.__init__. -Axiom ethereum_tangerine_whistle_vm_instructions___init___environment : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.instructions.__init__.globals "environment". +Axiom ethereum_tangerine_whistle_vm_instructions_imports : + AreImported globals "ethereum.tangerine_whistle.vm.instructions" [ "environment" ]. -Require ethereum.tangerine_whistle.vm.instructions.__init__. -Axiom ethereum_tangerine_whistle_vm_instructions___init___keccak : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.instructions.__init__.globals "keccak". +Axiom ethereum_tangerine_whistle_vm_instructions_imports : + AreImported globals "ethereum.tangerine_whistle.vm.instructions" [ "keccak" ]. -Require ethereum.tangerine_whistle.vm.instructions.__init__. -Axiom ethereum_tangerine_whistle_vm_instructions___init___log : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.instructions.__init__.globals "log". +Axiom ethereum_tangerine_whistle_vm_instructions_imports : + AreImported globals "ethereum.tangerine_whistle.vm.instructions" [ "log" ]. -Require ethereum.tangerine_whistle.vm.instructions.__init__. -Axiom ethereum_tangerine_whistle_vm_instructions___init___memory : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.instructions.__init__.globals "memory". +Axiom ethereum_tangerine_whistle_vm_instructions_imports : + AreImported globals "ethereum.tangerine_whistle.vm.instructions" [ "memory" ]. -Require ethereum.tangerine_whistle.vm.instructions.__init__. -Axiom ethereum_tangerine_whistle_vm_instructions___init___stack : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.instructions.__init__.globals "stack". +Axiom ethereum_tangerine_whistle_vm_instructions_imports : + AreImported globals "ethereum.tangerine_whistle.vm.instructions" [ "stack" ]. -Require ethereum.tangerine_whistle.vm.instructions.__init__. -Axiom ethereum_tangerine_whistle_vm_instructions___init___storage : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.instructions.__init__.globals "storage". +Axiom ethereum_tangerine_whistle_vm_instructions_imports : + AreImported globals "ethereum.tangerine_whistle.vm.instructions" [ "storage" ]. -Require ethereum.tangerine_whistle.vm.instructions.__init__. -Axiom ethereum_tangerine_whistle_vm_instructions___init___system : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.instructions.__init__.globals "system". +Axiom ethereum_tangerine_whistle_vm_instructions_imports : + AreImported globals "ethereum.tangerine_whistle.vm.instructions" [ "system" ]. Definition Ops : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/arithmetic.v index 5b28b51..b72a216 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/arithmetic.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.tangerine_whistle.vm.instructions.arithmetic". Definition expr_1 : Value.t := Constant.str " @@ -17,43 +17,20 @@ Introduction Implementations of the EVM Arithmetic instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U255_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U255_CEIL_VALUE". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_U256_CEIL_VALUE : - IsGlobalAlias globals ethereum.base_types.globals "U256_CEIL_VALUE". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U255_CEIL_VALUE"; "U256"; "U256_CEIL_VALUE"; "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_get_sign : - IsGlobalAlias globals ethereum.utils.numeric.globals "get_sign". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "get_sign" ]. -Require ethereum.tangerine_whistle.vm.__init__. -Axiom ethereum_tangerine_whistle_vm___init___Evm : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "Evm". +Axiom ethereum_tangerine_whistle_vm_imports : + AreImported globals "ethereum.tangerine_whistle.vm" [ "Evm" ]. -Require ethereum.tangerine_whistle.vm.gas. -Axiom ethereum_tangerine_whistle_vm_gas_GAS_EXPONENTIATION : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_EXPONENTIATION". -Axiom ethereum_tangerine_whistle_vm_gas_GAS_EXPONENTIATION_PER_BYTE : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_EXPONENTIATION_PER_BYTE". -Axiom ethereum_tangerine_whistle_vm_gas_GAS_LOW : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_LOW". -Axiom ethereum_tangerine_whistle_vm_gas_GAS_MID : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_MID". -Axiom ethereum_tangerine_whistle_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_tangerine_whistle_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "charge_gas". +Axiom ethereum_tangerine_whistle_vm_gas_imports : + AreImported globals "ethereum.tangerine_whistle.vm.gas" [ "GAS_EXPONENTIATION"; "GAS_EXPONENTIATION_PER_BYTE"; "GAS_LOW"; "GAS_MID"; "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.tangerine_whistle.vm.stack. -Axiom ethereum_tangerine_whistle_vm_stack_pop : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.stack.globals "pop". -Axiom ethereum_tangerine_whistle_vm_stack_push : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.stack.globals "push". +Axiom ethereum_tangerine_whistle_vm_stack_imports : + AreImported globals "ethereum.tangerine_whistle.vm.stack" [ "pop"; "push" ]. Definition add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -1030,19 +1007,27 @@ Definition signextend : Value.t -> Value.t -> M := make_dict [] |) in let value_bytes := - M.get_subscript (| M.get_name (| globals, "value_bytes" |), M.slice (| BinOp.sub (| - Constant.int 31, - M.call (| - M.get_name (| globals, "int" |), - make_list [ - M.get_name (| globals, "byte_num" |) - ], - make_dict [] - |) - |), Constant.None_ |) |) in + M.slice (| + M.get_name (| globals, "value_bytes" |), + BinOp.sub (| + Constant.int 31, + M.call (| + M.get_name (| globals, "int" |), + make_list [ + M.get_name (| globals, "byte_num" |) + ], + make_dict [] + |) + |), + Constant.None_, + Constant.None_ + |) in let sign_bit := BinOp.r_shift (| - M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), + M.get_subscript (| + M.get_name (| globals, "value_bytes" |), + Constant.int 0 + |), Constant.int 7 |) in let _ := diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/bitwise.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/bitwise.v index 179a578..476749d 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/bitwise.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.tangerine_whistle.vm.instructions.bitwise". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementations of the EVM bitwise instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.tangerine_whistle.vm.__init__. -Axiom ethereum_tangerine_whistle_vm___init___Evm : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "Evm". +Axiom ethereum_tangerine_whistle_vm_imports : + AreImported globals "ethereum.tangerine_whistle.vm" [ "Evm" ]. -Require ethereum.tangerine_whistle.vm.gas. -Axiom ethereum_tangerine_whistle_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_tangerine_whistle_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "charge_gas". +Axiom ethereum_tangerine_whistle_vm_gas_imports : + AreImported globals "ethereum.tangerine_whistle.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.tangerine_whistle.vm.stack. -Axiom ethereum_tangerine_whistle_vm_stack_pop : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.stack.globals "pop". -Axiom ethereum_tangerine_whistle_vm_stack_push : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.stack.globals "push". +Axiom ethereum_tangerine_whistle_vm_stack_imports : + AreImported globals "ethereum.tangerine_whistle.vm.stack" [ "pop"; "push" ]. Definition bitwise_and : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/block.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/block.v index c3f2b4d..976f1f2 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/block.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/block.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.tangerine_whistle.vm.instructions.block". Definition expr_1 : Value.t := Constant.str " @@ -17,27 +17,17 @@ Introduction Implementations of the EVM block instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.tangerine_whistle.vm.__init__. -Axiom ethereum_tangerine_whistle_vm___init___Evm : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "Evm". +Axiom ethereum_tangerine_whistle_vm_imports : + AreImported globals "ethereum.tangerine_whistle.vm" [ "Evm" ]. -Require ethereum.tangerine_whistle.vm.gas. -Axiom ethereum_tangerine_whistle_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_BASE". -Axiom ethereum_tangerine_whistle_vm_gas_GAS_BLOCK_HASH : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_BLOCK_HASH". -Axiom ethereum_tangerine_whistle_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "charge_gas". +Axiom ethereum_tangerine_whistle_vm_gas_imports : + AreImported globals "ethereum.tangerine_whistle.vm.gas" [ "GAS_BASE"; "GAS_BLOCK_HASH"; "charge_gas" ]. -Require ethereum.tangerine_whistle.vm.stack. -Axiom ethereum_tangerine_whistle_vm_stack_pop : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.stack.globals "pop". -Axiom ethereum_tangerine_whistle_vm_stack_push : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.stack.globals "push". +Axiom ethereum_tangerine_whistle_vm_stack_imports : + AreImported globals "ethereum.tangerine_whistle.vm.stack" [ "pop"; "push" ]. Definition block_hash : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -94,10 +84,13 @@ Definition block_hash : Value.t -> Value.t -> M := (* else *) )), ltac:(M.monadic ( let hash := - M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), - M.get_name (| globals, "block_number" |) - |) |) |) in + M.get_subscript (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), + UnOp.sub (| BinOp.sub (| + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), + M.get_name (| globals, "block_number" |) + |) |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/comparison.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/comparison.v index e99a53f..014d467 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/comparison.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.tangerine_whistle.vm.instructions.comparison". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementations of the EVM Comparison instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.tangerine_whistle.vm.__init__. -Axiom ethereum_tangerine_whistle_vm___init___Evm : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "Evm". +Axiom ethereum_tangerine_whistle_vm_imports : + AreImported globals "ethereum.tangerine_whistle.vm" [ "Evm" ]. -Require ethereum.tangerine_whistle.vm.gas. -Axiom ethereum_tangerine_whistle_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_tangerine_whistle_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "charge_gas". +Axiom ethereum_tangerine_whistle_vm_gas_imports : + AreImported globals "ethereum.tangerine_whistle.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.tangerine_whistle.vm.stack. -Axiom ethereum_tangerine_whistle_vm_stack_pop : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.stack.globals "pop". -Axiom ethereum_tangerine_whistle_vm_stack_push : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.stack.globals "push". +Axiom ethereum_tangerine_whistle_vm_stack_imports : + AreImported globals "ethereum.tangerine_whistle.vm.stack" [ "pop"; "push" ]. Definition less_than : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/control_flow.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/control_flow.v index 5aa8895..c615c86 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/control_flow.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.tangerine_whistle.vm.instructions.control_flow". Definition expr_1 : Value.t := Constant.str " @@ -17,37 +17,20 @@ Introduction Implementations of the EVM control flow instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. -Require ethereum.tangerine_whistle.vm.gas. -Axiom ethereum_tangerine_whistle_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_BASE". -Axiom ethereum_tangerine_whistle_vm_gas_GAS_HIGH : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_HIGH". -Axiom ethereum_tangerine_whistle_vm_gas_GAS_JUMPDEST : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_JUMPDEST". -Axiom ethereum_tangerine_whistle_vm_gas_GAS_MID : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_MID". -Axiom ethereum_tangerine_whistle_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "charge_gas". +Axiom ethereum_tangerine_whistle_vm_gas_imports : + AreImported globals "ethereum.tangerine_whistle.vm.gas" [ "GAS_BASE"; "GAS_HIGH"; "GAS_JUMPDEST"; "GAS_MID"; "charge_gas" ]. -Require ethereum.tangerine_whistle.vm.__init__. -Axiom ethereum_tangerine_whistle_vm___init___Evm : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "Evm". +Axiom ethereum_tangerine_whistle_vm_imports : + AreImported globals "ethereum.tangerine_whistle.vm" [ "Evm" ]. -Require ethereum.tangerine_whistle.vm.exceptions. -Axiom ethereum_tangerine_whistle_vm_exceptions_InvalidJumpDestError : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.exceptions.globals "InvalidJumpDestError". +Axiom ethereum_tangerine_whistle_vm_exceptions_imports : + AreImported globals "ethereum.tangerine_whistle.vm.exceptions" [ "InvalidJumpDestError" ]. -Require ethereum.tangerine_whistle.vm.stack. -Axiom ethereum_tangerine_whistle_vm_stack_pop : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.stack.globals "pop". -Axiom ethereum_tangerine_whistle_vm_stack_push : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.stack.globals "push". +Axiom ethereum_tangerine_whistle_vm_stack_imports : + AreImported globals "ethereum.tangerine_whistle.vm.stack" [ "pop"; "push" ]. Definition stop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -117,7 +100,7 @@ Definition jump : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "InvalidJumpDestError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -205,7 +188,7 @@ Definition jumpi : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "InvalidJumpDestError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "InvalidJumpDestError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/environment.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/environment.v index ec9d582..68c919a 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/environment.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.tangerine_whistle.vm.instructions.environment". Definition expr_1 : Value.t := Constant.str " @@ -17,55 +17,29 @@ Introduction Implementations of the EVM environment related instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". - -Require ethereum.tangerine_whistle.state. -Axiom ethereum_tangerine_whistle_state_get_account : - IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "get_account". - -Require ethereum.tangerine_whistle.utils.address. -Axiom ethereum_tangerine_whistle_utils_address_to_address : - IsGlobalAlias globals ethereum.tangerine_whistle.utils.address.globals "to_address". - -Require ethereum.tangerine_whistle.vm.memory. -Axiom ethereum_tangerine_whistle_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.memory.globals "buffer_read". -Axiom ethereum_tangerine_whistle_vm_memory_memory_write : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.memory.globals "memory_write". - -Require ethereum.tangerine_whistle.vm.__init__. -Axiom ethereum_tangerine_whistle_vm___init___Evm : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "Evm". - -Require ethereum.tangerine_whistle.vm.gas. -Axiom ethereum_tangerine_whistle_vm_gas_GAS_BALANCE : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_BALANCE". -Axiom ethereum_tangerine_whistle_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_BASE". -Axiom ethereum_tangerine_whistle_vm_gas_GAS_COPY : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_COPY". -Axiom ethereum_tangerine_whistle_vm_gas_GAS_EXTERNAL : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_EXTERNAL". -Axiom ethereum_tangerine_whistle_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_tangerine_whistle_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_tangerine_whistle_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "charge_gas". - -Require ethereum.tangerine_whistle.vm.stack. -Axiom ethereum_tangerine_whistle_vm_stack_pop : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.stack.globals "pop". -Axiom ethereum_tangerine_whistle_vm_stack_push : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.stack.globals "push". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. + +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. + +Axiom ethereum_tangerine_whistle_state_imports : + AreImported globals "ethereum.tangerine_whistle.state" [ "get_account" ]. + +Axiom ethereum_tangerine_whistle_utils_address_imports : + AreImported globals "ethereum.tangerine_whistle.utils.address" [ "to_address" ]. + +Axiom ethereum_tangerine_whistle_vm_memory_imports : + AreImported globals "ethereum.tangerine_whistle.vm.memory" [ "buffer_read"; "memory_write" ]. + +Axiom ethereum_tangerine_whistle_vm_imports : + AreImported globals "ethereum.tangerine_whistle.vm" [ "Evm" ]. + +Axiom ethereum_tangerine_whistle_vm_gas_imports : + AreImported globals "ethereum.tangerine_whistle.vm.gas" [ "GAS_BALANCE"; "GAS_BASE"; "GAS_COPY"; "GAS_EXTERNAL"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. + +Axiom ethereum_tangerine_whistle_vm_stack_imports : + AreImported globals "ethereum.tangerine_whistle.vm.stack" [ "pop"; "push" ]. Definition address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/keccak.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/keccak.v index 6ca60b6..0559a39 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/keccak.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.tangerine_whistle.vm.instructions.keccak". Definition expr_1 : Value.t := Constant.str " @@ -17,43 +17,26 @@ Introduction Implementations of the EVM keccak instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". - -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". - -Require ethereum.tangerine_whistle.vm.__init__. -Axiom ethereum_tangerine_whistle_vm___init___Evm : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "Evm". - -Require ethereum.tangerine_whistle.vm.gas. -Axiom ethereum_tangerine_whistle_vm_gas_GAS_KECCAK256 : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_KECCAK256". -Axiom ethereum_tangerine_whistle_vm_gas_GAS_KECCAK256_WORD : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_KECCAK256_WORD". -Axiom ethereum_tangerine_whistle_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_tangerine_whistle_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "charge_gas". - -Require ethereum.tangerine_whistle.vm.memory. -Axiom ethereum_tangerine_whistle_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.memory.globals "memory_read_bytes". - -Require ethereum.tangerine_whistle.vm.stack. -Axiom ethereum_tangerine_whistle_vm_stack_pop : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.stack.globals "pop". -Axiom ethereum_tangerine_whistle_vm_stack_push : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.stack.globals "push". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. + +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. + +Axiom ethereum_tangerine_whistle_vm_imports : + AreImported globals "ethereum.tangerine_whistle.vm" [ "Evm" ]. + +Axiom ethereum_tangerine_whistle_vm_gas_imports : + AreImported globals "ethereum.tangerine_whistle.vm.gas" [ "GAS_KECCAK256"; "GAS_KECCAK256_WORD"; "calculate_gas_extend_memory"; "charge_gas" ]. + +Axiom ethereum_tangerine_whistle_vm_memory_imports : + AreImported globals "ethereum.tangerine_whistle.vm.memory" [ "memory_read_bytes" ]. + +Axiom ethereum_tangerine_whistle_vm_stack_imports : + AreImported globals "ethereum.tangerine_whistle.vm.stack" [ "pop"; "push" ]. Definition keccak : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/log.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/log.v index cd9aa02..d705a66 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/log.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/log.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.tangerine_whistle.vm.instructions.log". Definition expr_1 : Value.t := Constant.str " @@ -17,41 +17,26 @@ Introduction Implementations of the EVM logging instructions. ". -Require functools. -Axiom functools_partial : - IsGlobalAlias globals functools.globals "partial". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". - -Require ethereum.tangerine_whistle.blocks. -Axiom ethereum_tangerine_whistle_blocks_Log : - IsGlobalAlias globals ethereum.tangerine_whistle.blocks.globals "Log". - -Require ethereum.tangerine_whistle.vm.__init__. -Axiom ethereum_tangerine_whistle_vm___init___Evm : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "Evm". - -Require ethereum.tangerine_whistle.vm.gas. -Axiom ethereum_tangerine_whistle_vm_gas_GAS_LOG : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_LOG". -Axiom ethereum_tangerine_whistle_vm_gas_GAS_LOG_DATA : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_LOG_DATA". -Axiom ethereum_tangerine_whistle_vm_gas_GAS_LOG_TOPIC : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_LOG_TOPIC". -Axiom ethereum_tangerine_whistle_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_tangerine_whistle_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "charge_gas". - -Require ethereum.tangerine_whistle.vm.memory. -Axiom ethereum_tangerine_whistle_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.memory.globals "memory_read_bytes". - -Require ethereum.tangerine_whistle.vm.stack. -Axiom ethereum_tangerine_whistle_vm_stack_pop : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.stack.globals "pop". +Axiom functools_imports : + AreImported globals "functools" [ "partial" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. + +Axiom ethereum_tangerine_whistle_blocks_imports : + AreImported globals "ethereum.tangerine_whistle.blocks" [ "Log" ]. + +Axiom ethereum_tangerine_whistle_vm_imports : + AreImported globals "ethereum.tangerine_whistle.vm" [ "Evm" ]. + +Axiom ethereum_tangerine_whistle_vm_gas_imports : + AreImported globals "ethereum.tangerine_whistle.vm.gas" [ "GAS_LOG"; "GAS_LOG_DATA"; "GAS_LOG_TOPIC"; "calculate_gas_extend_memory"; "charge_gas" ]. + +Axiom ethereum_tangerine_whistle_vm_memory_imports : + AreImported globals "ethereum.tangerine_whistle.vm.memory" [ "memory_read_bytes" ]. + +Axiom ethereum_tangerine_whistle_vm_stack_imports : + AreImported globals "ethereum.tangerine_whistle.vm.stack" [ "pop" ]. Definition log_n : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -88,33 +73,42 @@ Definition log_n : Value.t -> Value.t -> M := |) in let topics := make_list [] in - For M.get_name (| globals, "_" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - M.get_name (| globals, "num_topics" |) - ], - make_dict [] - |) do - let topic := + let _ := + M.for_ (| + M.get_name (| globals, "_" |), M.call (| - M.get_field (| M.call (| - M.get_name (| globals, "pop" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] - |), "to_be_bytes32" |), - make_list [], - make_dict [] - |) in - let _ := M.call (| + M.get_name (| globals, "range" |), + make_list [ + M.get_name (| globals, "num_topics" |) + ], + make_dict [] + |), + ltac:(M.monadic ( + let topic := + M.call (| + M.get_field (| M.call (| + M.get_name (| globals, "pop" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), "to_be_bytes32" |), + make_list [], + make_dict [] + |) in + let _ := M.call (| M.get_field (| M.get_name (| globals, "topics" |), "append" |), make_list [ M.get_name (| globals, "topic" |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let extend_memory := M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/memory.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/memory.v index 13a2715..6b34ce0 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/memory.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.tangerine_whistle.vm.instructions.memory". Definition expr_1 : Value.t := Constant.str " @@ -17,37 +17,20 @@ Introduction Implementations of the EVM Memory instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes" ]. -Require ethereum.tangerine_whistle.vm.__init__. -Axiom ethereum_tangerine_whistle_vm___init___Evm : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "Evm". +Axiom ethereum_tangerine_whistle_vm_imports : + AreImported globals "ethereum.tangerine_whistle.vm" [ "Evm" ]. -Require ethereum.tangerine_whistle.vm.gas. -Axiom ethereum_tangerine_whistle_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_BASE". -Axiom ethereum_tangerine_whistle_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_tangerine_whistle_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_tangerine_whistle_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "charge_gas". +Axiom ethereum_tangerine_whistle_vm_gas_imports : + AreImported globals "ethereum.tangerine_whistle.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. -Require ethereum.tangerine_whistle.vm.memory. -Axiom ethereum_tangerine_whistle_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.memory.globals "memory_read_bytes". -Axiom ethereum_tangerine_whistle_vm_memory_memory_write : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.memory.globals "memory_write". +Axiom ethereum_tangerine_whistle_vm_memory_imports : + AreImported globals "ethereum.tangerine_whistle.vm.memory" [ "memory_read_bytes"; "memory_write" ]. -Require ethereum.tangerine_whistle.vm.stack. -Axiom ethereum_tangerine_whistle_vm_stack_pop : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.stack.globals "pop". -Axiom ethereum_tangerine_whistle_vm_stack_push : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.stack.globals "push". +Axiom ethereum_tangerine_whistle_vm_stack_imports : + AreImported globals "ethereum.tangerine_whistle.vm.stack" [ "pop"; "push" ]. Definition mstore : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/stack.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/stack.v index 1e06082..4ddab44 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/stack.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.tangerine_whistle.vm.instructions.stack". Definition expr_1 : Value.t := Constant.str " @@ -17,39 +17,26 @@ Introduction Implementations of the EVM stack related instructions. ". -Require functools. -Axiom functools_partial : - IsGlobalAlias globals functools.globals "partial". +Axiom functools_imports : + AreImported globals "functools" [ "partial" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.utils.ensure. -Axiom ethereum_utils_ensure_ensure : - IsGlobalAlias globals ethereum.utils.ensure.globals "ensure". +Axiom ethereum_utils_ensure_imports : + AreImported globals "ethereum.utils.ensure" [ "ensure" ]. -Require ethereum.tangerine_whistle.vm.__init__. -Axiom ethereum_tangerine_whistle_vm___init___Evm : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "Evm". -Axiom ethereum_tangerine_whistle_vm___init___stack : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "stack". +Axiom ethereum_tangerine_whistle_vm_imports : + AreImported globals "ethereum.tangerine_whistle.vm" [ "Evm"; "stack" ]. -Require ethereum.tangerine_whistle.vm.exceptions. -Axiom ethereum_tangerine_whistle_vm_exceptions_StackUnderflowError : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.exceptions.globals "StackUnderflowError". +Axiom ethereum_tangerine_whistle_vm_exceptions_imports : + AreImported globals "ethereum.tangerine_whistle.vm.exceptions" [ "StackUnderflowError" ]. -Require ethereum.tangerine_whistle.vm.gas. -Axiom ethereum_tangerine_whistle_vm_gas_GAS_BASE : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_BASE". -Axiom ethereum_tangerine_whistle_vm_gas_GAS_VERY_LOW : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_VERY_LOW". -Axiom ethereum_tangerine_whistle_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "charge_gas". +Axiom ethereum_tangerine_whistle_vm_gas_imports : + AreImported globals "ethereum.tangerine_whistle.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "charge_gas" ]. -Require ethereum.tangerine_whistle.vm.memory. -Axiom ethereum_tangerine_whistle_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.memory.globals "buffer_read". +Axiom ethereum_tangerine_whistle_vm_memory_imports : + AreImported globals "ethereum.tangerine_whistle.vm.memory" [ "buffer_read" ]. Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -203,19 +190,22 @@ Definition dup_n : Value.t -> Value.t -> M := make_dict [] |) in let data_to_duplicate := - M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| + M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_field (| M.get_name (| globals, "evm" |), "stack" |) - ], - make_dict [] + BinOp.sub (| + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_field (| M.get_name (| globals, "evm" |), "stack" |) + ], + make_dict [] + |), + Constant.int 1 |), - Constant.int 1 - |), - M.get_name (| globals, "item_number" |) - |) |) in + M.get_name (| globals, "item_number" |) + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "stack" |), "push" |), make_list [ @@ -278,14 +268,26 @@ Definition swap_n : Value.t -> Value.t -> M := make_dict [] |) in let _ := M.assign (| - make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| - UnOp.sub (| Constant.int 1 |), - M.get_name (| globals, "item_number" |) - |) |) ], - make_tuple [ M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| - UnOp.sub (| Constant.int 1 |), - M.get_name (| globals, "item_number" |) - |) |); M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), UnOp.sub (| Constant.int 1 |) |) ] + make_tuple [ M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + UnOp.sub (| Constant.int 1 |) + |); M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) + |) ], + make_tuple [ M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + BinOp.sub (| + UnOp.sub (| Constant.int 1 |), + M.get_name (| globals, "item_number" |) + |) + |); M.get_subscript (| + M.get_field (| M.get_name (| globals, "evm" |), "stack" |), + UnOp.sub (| Constant.int 1 |) + |) ] |) in let _ := M.assign_op (| BinOp.add, diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/storage.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/storage.v index e0288ec..a02fde8 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/storage.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.tangerine_whistle.vm.instructions.storage". Definition expr_1 : Value.t := Constant.str " @@ -17,33 +17,17 @@ Introduction Implementations of the EVM storage related instructions. ". -Require ethereum.tangerine_whistle.state. -Axiom ethereum_tangerine_whistle_state_get_storage : - IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "get_storage". -Axiom ethereum_tangerine_whistle_state_set_storage : - IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "set_storage". +Axiom ethereum_tangerine_whistle_state_imports : + AreImported globals "ethereum.tangerine_whistle.state" [ "get_storage"; "set_storage" ]. -Require ethereum.tangerine_whistle.vm.__init__. -Axiom ethereum_tangerine_whistle_vm___init___Evm : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "Evm". +Axiom ethereum_tangerine_whistle_vm_imports : + AreImported globals "ethereum.tangerine_whistle.vm" [ "Evm" ]. -Require ethereum.tangerine_whistle.vm.gas. -Axiom ethereum_tangerine_whistle_vm_gas_GAS_SLOAD : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_SLOAD". -Axiom ethereum_tangerine_whistle_vm_gas_GAS_STORAGE_CLEAR_REFUND : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_STORAGE_CLEAR_REFUND". -Axiom ethereum_tangerine_whistle_vm_gas_GAS_STORAGE_SET : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_STORAGE_SET". -Axiom ethereum_tangerine_whistle_vm_gas_GAS_STORAGE_UPDATE : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_STORAGE_UPDATE". -Axiom ethereum_tangerine_whistle_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "charge_gas". +Axiom ethereum_tangerine_whistle_vm_gas_imports : + AreImported globals "ethereum.tangerine_whistle.vm.gas" [ "GAS_SLOAD"; "GAS_STORAGE_CLEAR_REFUND"; "GAS_STORAGE_SET"; "GAS_STORAGE_UPDATE"; "charge_gas" ]. -Require ethereum.tangerine_whistle.vm.stack. -Axiom ethereum_tangerine_whistle_vm_stack_pop : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.stack.globals "pop". -Axiom ethereum_tangerine_whistle_vm_stack_push : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.stack.globals "push". +Axiom ethereum_tangerine_whistle_vm_stack_imports : + AreImported globals "ethereum.tangerine_whistle.vm.stack" [ "pop"; "push" ]. Definition sload : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/system.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/system.v index 5ecb81f..c782996 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/system.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/system.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.tangerine_whistle.vm.instructions.system". Definition expr_1 : Value.t := Constant.str " @@ -17,83 +17,29 @@ Introduction Implementations of the EVM system related instructions. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. -Require ethereum.tangerine_whistle.fork_types. -Axiom ethereum_tangerine_whistle_fork_types_Address : - IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "Address". +Axiom ethereum_tangerine_whistle_fork_types_imports : + AreImported globals "ethereum.tangerine_whistle.fork_types" [ "Address" ]. -Require ethereum.tangerine_whistle.state. -Axiom ethereum_tangerine_whistle_state_account_exists : - IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "account_exists". -Axiom ethereum_tangerine_whistle_state_account_has_code_or_nonce : - IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "account_has_code_or_nonce". -Axiom ethereum_tangerine_whistle_state_get_account : - IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "get_account". -Axiom ethereum_tangerine_whistle_state_increment_nonce : - IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "increment_nonce". -Axiom ethereum_tangerine_whistle_state_set_account_balance : - IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "set_account_balance". +Axiom ethereum_tangerine_whistle_state_imports : + AreImported globals "ethereum.tangerine_whistle.state" [ "account_exists"; "account_has_code_or_nonce"; "get_account"; "increment_nonce"; "set_account_balance" ]. -Require ethereum.tangerine_whistle.utils.address. -Axiom ethereum_tangerine_whistle_utils_address_compute_contract_address : - IsGlobalAlias globals ethereum.tangerine_whistle.utils.address.globals "compute_contract_address". -Axiom ethereum_tangerine_whistle_utils_address_to_address : - IsGlobalAlias globals ethereum.tangerine_whistle.utils.address.globals "to_address". +Axiom ethereum_tangerine_whistle_utils_address_imports : + AreImported globals "ethereum.tangerine_whistle.utils.address" [ "compute_contract_address"; "to_address" ]. -Require ethereum.tangerine_whistle.vm.__init__. -Axiom ethereum_tangerine_whistle_vm___init___Evm : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "Evm". -Axiom ethereum_tangerine_whistle_vm___init___Message : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "Message". -Axiom ethereum_tangerine_whistle_vm___init___incorporate_child_on_error : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "incorporate_child_on_error". -Axiom ethereum_tangerine_whistle_vm___init___incorporate_child_on_success : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "incorporate_child_on_success". +Axiom ethereum_tangerine_whistle_vm_imports : + AreImported globals "ethereum.tangerine_whistle.vm" [ "Evm"; "Message"; "incorporate_child_on_error"; "incorporate_child_on_success" ]. -Require ethereum.tangerine_whistle.vm.gas. -Axiom ethereum_tangerine_whistle_vm_gas_GAS_CALL : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_CALL". -Axiom ethereum_tangerine_whistle_vm_gas_GAS_CALL_VALUE : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_CALL_VALUE". -Axiom ethereum_tangerine_whistle_vm_gas_GAS_CREATE : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_CREATE". -Axiom ethereum_tangerine_whistle_vm_gas_GAS_NEW_ACCOUNT : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_NEW_ACCOUNT". -Axiom ethereum_tangerine_whistle_vm_gas_GAS_SELF_DESTRUCT : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_SELF_DESTRUCT". -Axiom ethereum_tangerine_whistle_vm_gas_GAS_SELF_DESTRUCT_NEW_ACCOUNT : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_SELF_DESTRUCT_NEW_ACCOUNT". -Axiom ethereum_tangerine_whistle_vm_gas_GAS_ZERO : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_ZERO". -Axiom ethereum_tangerine_whistle_vm_gas_REFUND_SELF_DESTRUCT : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "REFUND_SELF_DESTRUCT". -Axiom ethereum_tangerine_whistle_vm_gas_calculate_gas_extend_memory : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "calculate_gas_extend_memory". -Axiom ethereum_tangerine_whistle_vm_gas_calculate_message_call_gas : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "calculate_message_call_gas". -Axiom ethereum_tangerine_whistle_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "charge_gas". -Axiom ethereum_tangerine_whistle_vm_gas_max_message_call_gas : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "max_message_call_gas". +Axiom ethereum_tangerine_whistle_vm_gas_imports : + AreImported globals "ethereum.tangerine_whistle.vm.gas" [ "GAS_CALL"; "GAS_CALL_VALUE"; "GAS_CREATE"; "GAS_NEW_ACCOUNT"; "GAS_SELF_DESTRUCT"; "GAS_SELF_DESTRUCT_NEW_ACCOUNT"; "GAS_ZERO"; "REFUND_SELF_DESTRUCT"; "calculate_gas_extend_memory"; "calculate_message_call_gas"; "charge_gas"; "max_message_call_gas" ]. -Require ethereum.tangerine_whistle.vm.memory. -Axiom ethereum_tangerine_whistle_vm_memory_memory_read_bytes : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.memory.globals "memory_read_bytes". -Axiom ethereum_tangerine_whistle_vm_memory_memory_write : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.memory.globals "memory_write". +Axiom ethereum_tangerine_whistle_vm_memory_imports : + AreImported globals "ethereum.tangerine_whistle.vm.memory" [ "memory_read_bytes"; "memory_write" ]. -Require ethereum.tangerine_whistle.vm.stack. -Axiom ethereum_tangerine_whistle_vm_stack_pop : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.stack.globals "pop". -Axiom ethereum_tangerine_whistle_vm_stack_push : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.stack.globals "push". +Axiom ethereum_tangerine_whistle_vm_stack_imports : + AreImported globals "ethereum.tangerine_whistle.vm.stack" [ "pop"; "push" ]. Definition create : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -643,7 +589,12 @@ Definition generic_call : Value.t -> Value.t -> M := make_list [ M.get_field (| M.get_name (| globals, "evm" |), "memory" |); M.get_name (| globals, "memory_output_start_position" |); - M.get_subscript (| M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), M.slice (| Constant.None_, M.get_name (| globals, "actual_output_size" |) |) |) + M.slice (| + M.get_field (| M.get_name (| globals, "child_evm" |), "output" |), + Constant.None_, + M.get_name (| globals, "actual_output_size" |), + Constant.None_ + |) ], make_dict [] |) in @@ -1168,20 +1119,28 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in let parent_evm := M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "parent_evm" |) in - While Compare.is_not (| - M.get_name (| globals, "parent_evm" |), - Constant.None_ - |) do - let _ := M.call (| + let _ := + M.while (| + Compare.is_not (| + M.get_name (| globals, "parent_evm" |), + Constant.None_ + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "refunded_accounts" |), "update" |), make_list [ M.get_field (| M.get_name (| globals, "parent_evm" |), "accounts_to_delete" |) ], make_dict [] |) in - let parent_evm := - M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in - EndWhile. + let parent_evm := + M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := (* if *) M.if_then_else (| diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/interpreter.v b/CoqOfPython/ethereum/tangerine_whistle/vm/interpreter.v index 6c9b819..3214ea1 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/interpreter.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/interpreter.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.tangerine_whistle.vm.interpreter". Definition expr_1 : Value.t := Constant.str " @@ -17,109 +17,47 @@ Introduction A straightforward interpreter that executes EVM code. ". -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". - -Require typing. -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". - -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes0 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes0". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.trace. -Axiom ethereum_trace_EvmStop : - IsGlobalAlias globals ethereum.trace.globals "EvmStop". -Axiom ethereum_trace_OpEnd : - IsGlobalAlias globals ethereum.trace.globals "OpEnd". -Axiom ethereum_trace_OpException : - IsGlobalAlias globals ethereum.trace.globals "OpException". -Axiom ethereum_trace_OpStart : - IsGlobalAlias globals ethereum.trace.globals "OpStart". -Axiom ethereum_trace_PrecompileEnd : - IsGlobalAlias globals ethereum.trace.globals "PrecompileEnd". -Axiom ethereum_trace_PrecompileStart : - IsGlobalAlias globals ethereum.trace.globals "PrecompileStart". -Axiom ethereum_trace_TransactionEnd : - IsGlobalAlias globals ethereum.trace.globals "TransactionEnd". -Axiom ethereum_trace_evm_trace : - IsGlobalAlias globals ethereum.trace.globals "evm_trace". - -Require ethereum.tangerine_whistle.blocks. -Axiom ethereum_tangerine_whistle_blocks_Log : - IsGlobalAlias globals ethereum.tangerine_whistle.blocks.globals "Log". - -Require ethereum.tangerine_whistle.fork_types. -Axiom ethereum_tangerine_whistle_fork_types_Address : - IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "Address". - -Require ethereum.tangerine_whistle.state. -Axiom ethereum_tangerine_whistle_state_account_has_code_or_nonce : - IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "account_has_code_or_nonce". -Axiom ethereum_tangerine_whistle_state_begin_transaction : - IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "begin_transaction". -Axiom ethereum_tangerine_whistle_state_commit_transaction : - IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "commit_transaction". -Axiom ethereum_tangerine_whistle_state_destroy_storage : - IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "destroy_storage". -Axiom ethereum_tangerine_whistle_state_move_ether : - IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "move_ether". -Axiom ethereum_tangerine_whistle_state_rollback_transaction : - IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "rollback_transaction". -Axiom ethereum_tangerine_whistle_state_set_code : - IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "set_code". -Axiom ethereum_tangerine_whistle_state_touch_account : - IsGlobalAlias globals ethereum.tangerine_whistle.state.globals "touch_account". - -Require ethereum.tangerine_whistle.vm.__init__. -Axiom ethereum_tangerine_whistle_vm___init___Message : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "Message". - -Require ethereum.tangerine_whistle.vm.gas. -Axiom ethereum_tangerine_whistle_vm_gas_GAS_CODE_DEPOSIT : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_CODE_DEPOSIT". -Axiom ethereum_tangerine_whistle_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "charge_gas". - -Require ethereum.tangerine_whistle.vm.precompiled_contracts.mapping. -Axiom ethereum_tangerine_whistle_vm_precompiled_contracts_mapping_PRE_COMPILED_CONTRACTS : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.precompiled_contracts.mapping.globals "PRE_COMPILED_CONTRACTS". - -Require ethereum.tangerine_whistle.vm.__init__. -Axiom ethereum_tangerine_whistle_vm___init___Environment : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "Environment". -Axiom ethereum_tangerine_whistle_vm___init___Evm : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "Evm". - -Require ethereum.tangerine_whistle.vm.exceptions. -Axiom ethereum_tangerine_whistle_vm_exceptions_AddressCollision : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.exceptions.globals "AddressCollision". -Axiom ethereum_tangerine_whistle_vm_exceptions_ExceptionalHalt : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.exceptions.globals "ExceptionalHalt". -Axiom ethereum_tangerine_whistle_vm_exceptions_InvalidOpcode : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.exceptions.globals "InvalidOpcode". -Axiom ethereum_tangerine_whistle_vm_exceptions_StackDepthLimitError : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.exceptions.globals "StackDepthLimitError". - -Require ethereum.tangerine_whistle.vm.instructions.__init__. -Axiom ethereum_tangerine_whistle_vm_instructions___init___Ops : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.instructions.__init__.globals "Ops". -Axiom ethereum_tangerine_whistle_vm_instructions___init___op_implementation : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.instructions.__init__.globals "op_implementation". - -Require ethereum.tangerine_whistle.vm.runtime. -Axiom ethereum_tangerine_whistle_vm_runtime_get_valid_jump_destinations : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.runtime.globals "get_valid_jump_destinations". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. + +Axiom typing_imports : + AreImported globals "typing" [ "Optional"; "Set"; "Tuple" ]. + +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. + +Axiom ethereum_trace_imports : + AreImported globals "ethereum.trace" [ "EvmStop"; "OpEnd"; "OpException"; "OpStart"; "PrecompileEnd"; "PrecompileStart"; "TransactionEnd"; "evm_trace" ]. + +Axiom ethereum_tangerine_whistle_blocks_imports : + AreImported globals "ethereum.tangerine_whistle.blocks" [ "Log" ]. + +Axiom ethereum_tangerine_whistle_fork_types_imports : + AreImported globals "ethereum.tangerine_whistle.fork_types" [ "Address" ]. + +Axiom ethereum_tangerine_whistle_state_imports : + AreImported globals "ethereum.tangerine_whistle.state" [ "account_has_code_or_nonce"; "begin_transaction"; "commit_transaction"; "destroy_storage"; "move_ether"; "rollback_transaction"; "set_code"; "touch_account" ]. + +Axiom ethereum_tangerine_whistle_vm_imports : + AreImported globals "ethereum.tangerine_whistle.vm" [ "Message" ]. + +Axiom ethereum_tangerine_whistle_vm_gas_imports : + AreImported globals "ethereum.tangerine_whistle.vm.gas" [ "GAS_CODE_DEPOSIT"; "charge_gas" ]. + +Axiom ethereum_tangerine_whistle_vm_precompiled_contracts_mapping_imports : + AreImported globals "ethereum.tangerine_whistle.vm.precompiled_contracts.mapping" [ "PRE_COMPILED_CONTRACTS" ]. + +Axiom ethereum_tangerine_whistle_vm_imports : + AreImported globals "ethereum.tangerine_whistle.vm" [ "Environment"; "Evm" ]. + +Axiom ethereum_tangerine_whistle_vm_exceptions_imports : + AreImported globals "ethereum.tangerine_whistle.vm.exceptions" [ "AddressCollision"; "ExceptionalHalt"; "InvalidOpcode"; "StackDepthLimitError" ]. + +Axiom ethereum_tangerine_whistle_vm_instructions_imports : + AreImported globals "ethereum.tangerine_whistle.vm.instructions" [ "Ops"; "op_implementation" ]. + +Axiom ethereum_tangerine_whistle_vm_runtime_imports : + AreImported globals "ethereum.tangerine_whistle.vm.runtime" [ "get_valid_jump_destinations" ]. Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -424,7 +362,7 @@ Definition process_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.call (| + let _ := M.raise (| Some (M.call (| M.get_name (| globals, "StackDepthLimitError" |), make_list [ Constant.str "Stack depth limit reached" diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/memory.v b/CoqOfPython/ethereum/tangerine_whistle/vm/memory.v index 08d2290..1bc0926 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/memory.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/memory.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.tangerine_whistle.vm.memory". Definition expr_1 : Value.t := Constant.str " @@ -17,17 +17,11 @@ Introduction EVM memory operations. ". -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_right_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "right_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "right_pad_zero_bytes" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. Definition memory_write : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,22 +39,27 @@ Definition memory_write : Value.t -> Value.t -> M := Data to write to memory. " in let _ := M.assign (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + M.slice (| + M.get_name (| globals, "memory" |), + M.get_name (| globals, "start_position" |), + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "value" |) + ], + make_dict [] + |) |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "value" |) - ], - make_dict [] - |) - |) |) |), + Constant.None_ + |), M.get_name (| globals, "value" |) |) in M.pure Constant.None_)). @@ -86,22 +85,27 @@ Definition memory_read_bytes : Value.t -> Value.t -> M := Data read from memory. " in let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "memory" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + M.slice (| + M.get_name (| globals, "memory" |), + M.get_name (| globals, "start_position" |), + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |) |) + Constant.None_ + |) |) in M.pure Constant.None_)). @@ -129,22 +133,27 @@ Definition buffer_read : Value.t -> Value.t -> M := M.call (| M.get_name (| globals, "right_pad_zero_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "buffer" |), M.slice (| M.get_name (| globals, "start_position" |), BinOp.add (| - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "start_position" |) - ], - make_dict [] + M.slice (| + M.get_name (| globals, "buffer" |), + M.get_name (| globals, "start_position" |), + BinOp.add (| + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "start_position" |) + ], + make_dict [] + |), + M.call (| + M.get_name (| globals, "Uint" |), + make_list [ + M.get_name (| globals, "size" |) + ], + make_dict [] + |) |), - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "size" |) - ], - make_dict [] - |) - |) |) |); + Constant.None_ + |); M.get_name (| globals, "size" |) ], make_dict [] diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/__init__.v index 4e1e63a..533c3c9 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/__init__.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.tangerine_whistle.vm.precompiled_contracts.__init__". Definition expr_1 : Value.t := Constant.str " @@ -18,9 +18,8 @@ Addresses of precompiled contracts and mappings to their implementations. ". -Require ethereum.tangerine_whistle.utils.hexadecimal. -Axiom ethereum_tangerine_whistle_utils_hexadecimal_hex_to_address : - IsGlobalAlias globals ethereum.tangerine_whistle.utils.hexadecimal.globals "hex_to_address". +Axiom ethereum_tangerine_whistle_utils_hexadecimal_imports : + AreImported globals "ethereum.tangerine_whistle.utils.hexadecimal" [ "hex_to_address" ]. Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS" ] diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/ecrecover.v index 63cef4d..8d8ddd1 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/ecrecover.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.tangerine_whistle.vm.precompiled_contracts.ecrecover". Definition expr_1 : Value.t := Constant.str " @@ -17,39 +17,26 @@ Introduction Implementation of the ECRECOVER precompiled contract. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.crypto.elliptic_curve. -Axiom ethereum_crypto_elliptic_curve_SECP256K1N : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "SECP256K1N". -Axiom ethereum_crypto_elliptic_curve_secp256k1_recover : - IsGlobalAlias globals ethereum.crypto.elliptic_curve.globals "secp256k1_recover". +Axiom ethereum_crypto_elliptic_curve_imports : + AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". -Axiom ethereum_crypto_hash_keccak256 : - IsGlobalAlias globals ethereum.crypto.hash.globals "keccak256". +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_left_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. -Require ethereum.tangerine_whistle.vm.__init__. -Axiom ethereum_tangerine_whistle_vm___init___Evm : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "Evm". +Axiom ethereum_tangerine_whistle_vm_imports : + AreImported globals "ethereum.tangerine_whistle.vm" [ "Evm" ]. -Require ethereum.tangerine_whistle.vm.gas. -Axiom ethereum_tangerine_whistle_vm_gas_GAS_ECRECOVER : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_ECRECOVER". -Axiom ethereum_tangerine_whistle_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "charge_gas". +Axiom ethereum_tangerine_whistle_vm_gas_imports : + AreImported globals "ethereum.tangerine_whistle.vm.gas" [ "GAS_ECRECOVER"; "charge_gas" ]. -Require ethereum.tangerine_whistle.vm.memory. -Axiom ethereum_tangerine_whistle_vm_memory_buffer_read : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.memory.globals "buffer_read". +Axiom ethereum_tangerine_whistle_vm_memory_imports : + AreImported globals "ethereum.tangerine_whistle.vm.memory" [ "buffer_read" ]. Definition ecrecover : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -264,13 +251,18 @@ Definition ecrecover : Value.t -> Value.t -> M := )) |) in (* At stmt: unsupported node type: Try *) let address := - M.get_subscript (| M.call (| - M.get_name (| globals, "keccak256" |), - make_list [ - M.get_name (| globals, "public_key" |) - ], - make_dict [] - |), M.slice (| Constant.int 12, Constant.int 32 |) |) in + M.slice (| + M.call (| + M.get_name (| globals, "keccak256" |), + make_list [ + M.get_name (| globals, "public_key" |) + ], + make_dict [] + |), + Constant.int 12, + Constant.int 32, + Constant.None_ + |) in let padded_address := M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/identity.v index 68036e2..655cd9a 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/identity.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/identity.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.tangerine_whistle.vm.precompiled_contracts.identity". Definition expr_1 : Value.t := Constant.str " @@ -17,25 +17,17 @@ Introduction Implementation of the `IDENTITY` precompiled contract. ". -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.tangerine_whistle.vm.__init__. -Axiom ethereum_tangerine_whistle_vm___init___Evm : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "Evm". +Axiom ethereum_tangerine_whistle_vm_imports : + AreImported globals "ethereum.tangerine_whistle.vm" [ "Evm" ]. -Require ethereum.tangerine_whistle.vm.gas. -Axiom ethereum_tangerine_whistle_vm_gas_GAS_IDENTITY : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_IDENTITY". -Axiom ethereum_tangerine_whistle_vm_gas_GAS_IDENTITY_WORD : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_IDENTITY_WORD". -Axiom ethereum_tangerine_whistle_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "charge_gas". +Axiom ethereum_tangerine_whistle_vm_gas_imports : + AreImported globals "ethereum.tangerine_whistle.vm.gas" [ "GAS_IDENTITY"; "GAS_IDENTITY_WORD"; "charge_gas" ]. Definition identity : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/mapping.v index 5f05c47..e678e41 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/mapping.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/mapping.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.tangerine_whistle.vm.precompiled_contracts.mapping". Definition expr_1 : Value.t := Constant.str " @@ -17,40 +17,25 @@ Introduction Mapping of precompiled contracts their implementations. ". -Require typing. -Axiom typing_Callable : - IsGlobalAlias globals typing.globals "Callable". -Axiom typing_Dict : - IsGlobalAlias globals typing.globals "Dict". - -Require ethereum.tangerine_whistle.fork_types. -Axiom ethereum_tangerine_whistle_fork_types_Address : - IsGlobalAlias globals ethereum.tangerine_whistle.fork_types.globals "Address". - -Require ethereum.tangerine_whistle.vm.precompiled_contracts.__init__. -Axiom ethereum_tangerine_whistle_vm_precompiled_contracts___init___ECRECOVER_ADDRESS : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.precompiled_contracts.__init__.globals "ECRECOVER_ADDRESS". -Axiom ethereum_tangerine_whistle_vm_precompiled_contracts___init___IDENTITY_ADDRESS : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.precompiled_contracts.__init__.globals "IDENTITY_ADDRESS". -Axiom ethereum_tangerine_whistle_vm_precompiled_contracts___init___RIPEMD160_ADDRESS : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.precompiled_contracts.__init__.globals "RIPEMD160_ADDRESS". -Axiom ethereum_tangerine_whistle_vm_precompiled_contracts___init___SHA256_ADDRESS : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.precompiled_contracts.__init__.globals "SHA256_ADDRESS". - -Require ethereum.tangerine_whistle.vm.precompiled_contracts.ecrecover. -Axiom ethereum_tangerine_whistle_vm_precompiled_contracts_ecrecover_ecrecover : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.precompiled_contracts.ecrecover.globals "ecrecover". - -Require ethereum.tangerine_whistle.vm.precompiled_contracts.identity. -Axiom ethereum_tangerine_whistle_vm_precompiled_contracts_identity_identity : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.precompiled_contracts.identity.globals "identity". - -Require ethereum.tangerine_whistle.vm.precompiled_contracts.ripemd160. -Axiom ethereum_tangerine_whistle_vm_precompiled_contracts_ripemd160_ripemd160 : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.precompiled_contracts.ripemd160.globals "ripemd160". - -Require ethereum.tangerine_whistle.vm.precompiled_contracts.sha256. -Axiom ethereum_tangerine_whistle_vm_precompiled_contracts_sha256_sha256 : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.precompiled_contracts.sha256.globals "sha256". +Axiom typing_imports : + AreImported globals "typing" [ "Callable"; "Dict" ]. + +Axiom ethereum_tangerine_whistle_fork_types_imports : + AreImported globals "ethereum.tangerine_whistle.fork_types" [ "Address" ]. + +Axiom ethereum_tangerine_whistle_vm_precompiled_contracts_imports : + AreImported globals "ethereum.tangerine_whistle.vm.precompiled_contracts" [ "ECRECOVER_ADDRESS"; "IDENTITY_ADDRESS"; "RIPEMD160_ADDRESS"; "SHA256_ADDRESS" ]. + +Axiom ethereum_tangerine_whistle_vm_precompiled_contracts_ecrecover_imports : + AreImported globals "ethereum.tangerine_whistle.vm.precompiled_contracts.ecrecover" [ "ecrecover" ]. + +Axiom ethereum_tangerine_whistle_vm_precompiled_contracts_identity_imports : + AreImported globals "ethereum.tangerine_whistle.vm.precompiled_contracts.identity" [ "identity" ]. + +Axiom ethereum_tangerine_whistle_vm_precompiled_contracts_ripemd160_imports : + AreImported globals "ethereum.tangerine_whistle.vm.precompiled_contracts.ripemd160" [ "ripemd160" ]. + +Axiom ethereum_tangerine_whistle_vm_precompiled_contracts_sha256_imports : + AreImported globals "ethereum.tangerine_whistle.vm.precompiled_contracts.sha256" [ "sha256" ]. (* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/ripemd160.v index c2f4b20..145db2b 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/ripemd160.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/ripemd160.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.tangerine_whistle.vm.precompiled_contracts.ripemd160". Definition expr_1 : Value.t := Constant.str " @@ -19,29 +19,20 @@ Implementation of the `RIPEMD160` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.byte. -Axiom ethereum_utils_byte_left_pad_zero_bytes : - IsGlobalAlias globals ethereum.utils.byte.globals "left_pad_zero_bytes". +Axiom ethereum_utils_byte_imports : + AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.tangerine_whistle.vm.__init__. -Axiom ethereum_tangerine_whistle_vm___init___Evm : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "Evm". +Axiom ethereum_tangerine_whistle_vm_imports : + AreImported globals "ethereum.tangerine_whistle.vm" [ "Evm" ]. -Require ethereum.tangerine_whistle.vm.gas. -Axiom ethereum_tangerine_whistle_vm_gas_GAS_RIPEMD160 : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_RIPEMD160". -Axiom ethereum_tangerine_whistle_vm_gas_GAS_RIPEMD160_WORD : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_RIPEMD160_WORD". -Axiom ethereum_tangerine_whistle_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "charge_gas". +Axiom ethereum_tangerine_whistle_vm_gas_imports : + AreImported globals "ethereum.tangerine_whistle.vm.gas" [ "GAS_RIPEMD160"; "GAS_RIPEMD160_WORD"; "charge_gas" ]. Definition ripemd160 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/sha256.v index c2ff5d8..9d5702e 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/sha256.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/sha256.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.tangerine_whistle.vm.precompiled_contracts.sha256". Definition expr_1 : Value.t := Constant.str " @@ -19,25 +19,17 @@ Implementation of the `SHA256` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.utils.numeric. -Axiom ethereum_utils_numeric_ceil32 : - IsGlobalAlias globals ethereum.utils.numeric.globals "ceil32". +Axiom ethereum_utils_numeric_imports : + AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. -Require ethereum.tangerine_whistle.vm.__init__. -Axiom ethereum_tangerine_whistle_vm___init___Evm : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.__init__.globals "Evm". +Axiom ethereum_tangerine_whistle_vm_imports : + AreImported globals "ethereum.tangerine_whistle.vm" [ "Evm" ]. -Require ethereum.tangerine_whistle.vm.gas. -Axiom ethereum_tangerine_whistle_vm_gas_GAS_SHA256 : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_SHA256". -Axiom ethereum_tangerine_whistle_vm_gas_GAS_SHA256_WORD : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "GAS_SHA256_WORD". -Axiom ethereum_tangerine_whistle_vm_gas_charge_gas : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.gas.globals "charge_gas". +Axiom ethereum_tangerine_whistle_vm_gas_imports : + AreImported globals "ethereum.tangerine_whistle.vm.gas" [ "GAS_SHA256"; "GAS_SHA256_WORD"; "charge_gas" ]. Definition sha256 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/runtime.v b/CoqOfPython/ethereum/tangerine_whistle/vm/runtime.v index 7ff8cc5..dc740b0 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/runtime.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/runtime.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.tangerine_whistle.vm.runtime". Definition expr_1 : Value.t := Constant.str " @@ -17,17 +17,14 @@ Introduction Runtime related operations used while executing EVM code. ". -Require typing. -Axiom typing_Set_ : - IsGlobalAlias globals typing.globals "Set_". +Axiom typing_imports : + AreImported globals "typing" [ "Set" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Uint" ]. -Require ethereum.tangerine_whistle.vm.instructions.__init__. -Axiom ethereum_tangerine_whistle_vm_instructions___init___Ops : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.instructions.__init__.globals "Ops". +Axiom ethereum_tangerine_whistle_vm_instructions_imports : + AreImported globals "ethereum.tangerine_whistle.vm.instructions" [ "Ops" ]. Definition get_valid_jump_destinations : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -67,75 +64,83 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := ], make_dict [] |) in - While Compare.lt (| - M.get_name (| globals, "pc" |), - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "code" |) - ], - make_dict [] - |) - |) do -(* At stmt: unsupported node type: Try *) - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - M.get_name (| globals, "current_opcode" |), - M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) - |), - (* then *) + let _ := + M.while (| + Compare.lt (| + M.get_name (| globals, "pc" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "code" |) + ], + make_dict [] + |) + |), ltac:(M.monadic ( - let _ := M.call (| - M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), - make_list [ - M.get_name (| globals, "pc" |) - ], - make_dict [] - |) in - M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( +(* At stmt: unsupported node type: Try *) let _ := (* if *) M.if_then_else (| - BoolOp.and (| - Compare.lt_e (| - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |), - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |) - |), - ltac:(M.monadic ( - Compare.lt_e (| - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH32" |), "value" |) - |) - )) + Compare.eq (| + M.get_name (| globals, "current_opcode" |), + M.get_field (| M.get_name (| globals, "Ops" |), "JUMPDEST" |) |), (* then *) ltac:(M.monadic ( - let push_data_size := - BinOp.add (| - BinOp.sub (| - M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), - M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) - |), - Constant.int 1 - |) in - let pc := BinOp.add - M.get_name (| globals, "push_data_size" |) - M.get_name (| globals, "push_data_size" |) in + let _ := M.call (| + M.get_field (| M.get_name (| globals, "valid_jump_destinations" |), "add" |), + make_list [ + M.get_name (| globals, "pc" |) + ], + make_dict [] + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( + let _ := + (* if *) + M.if_then_else (| + BoolOp.and (| + Compare.lt_e (| + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |), + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |) + |), + ltac:(M.monadic ( + Compare.lt_e (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH32" |), "value" |) + |) + )) + |), + (* then *) + ltac:(M.monadic ( + let push_data_size := + BinOp.add (| + BinOp.sub (| + M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), + M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) + |), + Constant.int 1 + |) in + let pc := BinOp.add + M.get_name (| globals, "push_data_size" |) + M.get_name (| globals, "push_data_size" |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ )) |) in + let pc := BinOp.add + Constant.int 1 + Constant.int 1 in M.pure Constant.None_ - )) |) in - let pc := BinOp.add - Constant.int 1 - Constant.int 1 in - EndWhile. + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.get_name (| globals, "valid_jump_destinations" |) |) in diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/stack.v b/CoqOfPython/ethereum/tangerine_whistle/vm/stack.v index 8123c16..b163880 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/stack.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/stack.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.tangerine_whistle.vm.stack". Definition expr_1 : Value.t := Constant.str " @@ -17,19 +17,14 @@ Introduction Implementation of the stack operators for the EVM. ". -Require typing. -Axiom typing_List : - IsGlobalAlias globals typing.globals "List". +Axiom typing_imports : + AreImported globals "typing" [ "List" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256" ]. -Require ethereum.tangerine_whistle.vm.exceptions. -Axiom ethereum_tangerine_whistle_vm_exceptions_StackOverflowError : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.exceptions.globals "StackOverflowError". -Axiom ethereum_tangerine_whistle_vm_exceptions_StackUnderflowError : - IsGlobalAlias globals ethereum.tangerine_whistle.vm.exceptions.globals "StackUnderflowError". +Axiom ethereum_tangerine_whistle_vm_exceptions_imports : + AreImported globals "ethereum.tangerine_whistle.vm.exceptions" [ "StackOverflowError"; "StackUnderflowError" ]. Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -63,7 +58,7 @@ Definition pop : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "StackUnderflowError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "StackUnderflowError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -108,7 +103,7 @@ Definition push : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let _ := M.raise (| Some(M.get_name (| globals, "StackOverflowError" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "StackOverflowError" |)) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/trace.v b/CoqOfPython/ethereum/trace.v index be717d7..a0176e9 100644 --- a/CoqOfPython/ethereum/trace.v +++ b/CoqOfPython/ethereum/trace.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.trace". Definition expr_1 : Value.t := Constant.str " @@ -21,15 +21,11 @@ Defines the functions required for creating evm traces during execution. (* At top_level_stmt: unsupported node type: Import *) -Require dataclasses. -Axiom dataclasses_dataclass : - IsGlobalAlias globals dataclasses.globals "dataclass". +Axiom dataclasses_imports : + AreImported globals "dataclasses" [ "dataclass" ]. -Require typing. -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". +Axiom typing_imports : + AreImported globals "typing" [ "Optional"; "Union" ]. Definition TransactionStart : Value.t := builtins.make_klass @@ -122,7 +118,10 @@ Definition GasAndRefund : Value.t := ]. Definition TraceEvent : Value.t := M.run ltac:(M.monadic ( - M.get_subscript (| M.get_name (| globals, "Union" |), make_tuple [ M.get_name (| globals, "TransactionStart" |); M.get_name (| globals, "TransactionEnd" |); M.get_name (| globals, "PrecompileStart" |); M.get_name (| globals, "PrecompileEnd" |); M.get_name (| globals, "OpStart" |); M.get_name (| globals, "OpEnd" |); M.get_name (| globals, "OpException" |); M.get_name (| globals, "EvmStop" |); M.get_name (| globals, "GasAndRefund" |) ] |) + M.get_subscript (| + M.get_name (| globals, "Union" |), + make_tuple [ M.get_name (| globals, "TransactionStart" |); M.get_name (| globals, "TransactionEnd" |); M.get_name (| globals, "PrecompileStart" |); M.get_name (| globals, "PrecompileEnd" |); M.get_name (| globals, "OpStart" |); M.get_name (| globals, "OpEnd" |); M.get_name (| globals, "OpException" |); M.get_name (| globals, "EvmStop" |); M.get_name (| globals, "GasAndRefund" |) ] + |) )). Definition evm_trace : Value.t -> Value.t -> M := diff --git a/CoqOfPython/ethereum/utils/__init__.v b/CoqOfPython/ethereum/utils/__init__.v index 9fe6ec9..aa7d70b 100644 --- a/CoqOfPython/ethereum/utils/__init__.v +++ b/CoqOfPython/ethereum/utils/__init__.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.utils.__init__". Definition expr_1 : Value.t := Constant.str " diff --git a/CoqOfPython/ethereum/utils/byte.v b/CoqOfPython/ethereum/utils/byte.v index 50eac5b..0d41aa0 100644 --- a/CoqOfPython/ethereum/utils/byte.v +++ b/CoqOfPython/ethereum/utils/byte.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.utils.byte". Definition expr_1 : Value.t := Constant.str " @@ -17,9 +17,8 @@ Introduction Byte specific utility functions used in this specification. ". -Require ethereum.base_types. -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "Bytes" ]. Definition left_pad_zero_bytes : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/utils/ensure.v b/CoqOfPython/ethereum/utils/ensure.v index 58534bc..8955c24 100644 --- a/CoqOfPython/ethereum/utils/ensure.v +++ b/CoqOfPython/ethereum/utils/ensure.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.utils.ensure". Definition expr_1 : Value.t := Constant.str " @@ -17,11 +17,8 @@ Introduction Functions that simplify checking assertions and raising exceptions. ". -Require typing. -Axiom typing_Type_ : - IsGlobalAlias globals typing.globals "Type_". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". +Axiom typing_imports : + AreImported globals "typing" [ "Type"; "Union" ]. Definition ensure : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -53,5 +50,5 @@ Definition ensure : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let _ := M.raise (| Some(M.get_name (| globals, "exception" |)) |) in + let _ := M.raise (| Some (M.get_name (| globals, "exception" |)) |) in M.pure Constant.None_)). diff --git a/CoqOfPython/ethereum/utils/hexadecimal.v b/CoqOfPython/ethereum/utils/hexadecimal.v index 18fc6f1..a63732a 100644 --- a/CoqOfPython/ethereum/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/utils/hexadecimal.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.utils.hexadecimal". Definition expr_1 : Value.t := Constant.str " @@ -17,27 +17,11 @@ Introduction Hexadecimal strings specific utility functions used in this specification. ". -Require ethereum.base_types. -Axiom ethereum_base_types_U64 : - IsGlobalAlias globals ethereum.base_types.globals "U64". -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Bytes : - IsGlobalAlias globals ethereum.base_types.globals "Bytes". -Axiom ethereum_base_types_Bytes8 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes8". -Axiom ethereum_base_types_Bytes20 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes20". -Axiom ethereum_base_types_Bytes32 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes32". -Axiom ethereum_base_types_Bytes256 : - IsGlobalAlias globals ethereum.base_types.globals "Bytes256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". - -Require ethereum.crypto.hash. -Axiom ethereum_crypto_hash_Hash32 : - IsGlobalAlias globals ethereum.crypto.hash.globals "Hash32". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U64"; "U256"; "Bytes"; "Bytes8"; "Bytes20"; "Bytes32"; "Bytes256"; "Uint" ]. + +Axiom ethereum_crypto_hash_imports : + AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. Definition has_hex_prefix : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -96,13 +80,18 @@ Definition remove_hex_prefix : Value.t -> Value.t -> M := (* then *) ltac:(M.monadic ( let _ := M.return_ (| - M.get_subscript (| M.get_name (| globals, "hex_string" |), M.slice (| M.call (| - M.get_name (| globals, "len" |), - make_list [ - Constant.str "0x" - ], - make_dict [] - |), Constant.None_ |) |) + M.slice (| + M.get_name (| globals, "hex_string" |), + M.call (| + M.get_name (| globals, "len" |), + make_list [ + Constant.str "0x" + ], + make_dict [] + |), + Constant.None_, + Constant.None_ + |) |) in M.pure Constant.None_ (* else *) diff --git a/CoqOfPython/ethereum/utils/numeric.v b/CoqOfPython/ethereum/utils/numeric.v index b31bf33..c1c111b 100644 --- a/CoqOfPython/ethereum/utils/numeric.v +++ b/CoqOfPython/ethereum/utils/numeric.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.utils.numeric". Definition expr_1 : Value.t := Constant.str " @@ -17,17 +17,11 @@ Introduction Numeric operations specific utility functions used in this specification. ". -Require typing. -Axiom typing_Sequence : - IsGlobalAlias globals typing.globals "Sequence". -Axiom typing_Tuple : - IsGlobalAlias globals typing.globals "Tuple". +Axiom typing_imports : + AreImported globals "typing" [ "Sequence"; "Tuple" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U32 : - IsGlobalAlias globals ethereum.base_types.globals "U32". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U32"; "Uint" ]. Definition get_sign : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -183,47 +177,56 @@ Definition is_prime : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - For M.get_name (| globals, "x" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 2; - BinOp.add (| + let _ := + M.for_ (| + M.get_name (| globals, "x" |), M.call (| - M.get_name (| globals, "int" |), - make_list [ - BinOp.pow (| - M.get_name (| globals, "number" |), - Value.Float 0.5 - |) - ], - make_dict [] - |), - Constant.int 1 - |) - ], - make_dict [] - |) do - let _ := - (* if *) - M.if_then_else (| - Compare.eq (| - BinOp.mod_ (| - M.get_name (| globals, "number" |), - M.get_name (| globals, "x" |) - |), - Constant.int 0 + M.get_name (| globals, "range" |), + make_list [ + Constant.int 2; + BinOp.add (| + M.call (| + M.get_name (| globals, "int" |), + make_list [ + BinOp.pow (| + M.get_name (| globals, "number" |), + Value.Float 0.5 + |) + ], + make_dict [] |), - (* then *) + Constant.int 1 + |) + ], + make_dict [] + |), ltac:(M.monadic ( - let _ := M.return_ (| - Constant.bool false - |) in + let _ := + (* if *) + M.if_then_else (| + Compare.eq (| + BinOp.mod_ (| + M.get_name (| globals, "number" |), + M.get_name (| globals, "x" |) + |), + Constant.int 0 + |), + (* then *) + ltac:(M.monadic ( + let _ := M.return_ (| + Constant.bool false + |) in + M.pure Constant.None_ + (* else *) + )), ltac:(M.monadic ( + M.pure Constant.None_ + )) |) in M.pure Constant.None_ - (* else *) - )), ltac:(M.monadic ( + )), + ltac:(M.monadic ( M.pure Constant.None_ - )) |) in - EndFor. + )) + |) in let _ := M.return_ (| Constant.bool true |) in @@ -251,38 +254,52 @@ Definition le_bytes_to_uint32_sequence : Value.t -> Value.t -> M := " in let sequence := make_list [] in - For M.get_name (| globals, "i" |) in M.call (| - M.get_name (| globals, "range" |), - make_list [ - Constant.int 0; - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "data" |) - ], - make_dict [] - |); - Constant.int 4 - ], - make_dict [] - |) do - let _ := M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "i" |), + M.call (| + M.get_name (| globals, "range" |), + make_list [ + Constant.int 0; + M.call (| + M.get_name (| globals, "len" |), + make_list [ + M.get_name (| globals, "data" |) + ], + make_dict [] + |); + Constant.int 4 + ], + make_dict [] + |), + ltac:(M.monadic ( + let _ := M.call (| M.get_field (| M.get_name (| globals, "sequence" |), "append" |), make_list [ M.call (| M.get_field (| M.get_name (| globals, "U32" |), "from_le_bytes" |), make_list [ - M.get_subscript (| M.get_name (| globals, "data" |), M.slice (| M.get_name (| globals, "i" |), BinOp.add (| + M.slice (| + M.get_name (| globals, "data" |), M.get_name (| globals, "i" |), - Constant.int 4 - |) |) |) + BinOp.add (| + M.get_name (| globals, "i" |), + Constant.int 4 + |), + Constant.None_ + |) ], make_dict [] |) ], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "tuple" |), @@ -323,19 +340,28 @@ Definition le_uint32_sequence_to_bytes : Value.t -> Value.t -> M := " in let result_bytes := Constant.bytes "" in - For M.get_name (| globals, "item" |) in M.get_name (| globals, "sequence" |) do - let result_bytes := BinOp.add - M.call (| + let _ := + M.for_ (| + M.get_name (| globals, "item" |), + M.get_name (| globals, "sequence" |), + ltac:(M.monadic ( + let result_bytes := BinOp.add + M.call (| M.get_field (| M.get_name (| globals, "item" |), "to_le_bytes4" |), make_list [], make_dict [] |) - M.call (| + M.call (| M.get_field (| M.get_name (| globals, "item" |), "to_le_bytes4" |), make_list [], make_dict [] |) in - EndFor. + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| M.get_name (| globals, "result_bytes" |) |) in @@ -410,28 +436,36 @@ Definition taylor_exponential : Value.t -> Value.t -> M := M.get_name (| globals, "factor" |), M.get_name (| globals, "denominator" |) |) in - While Compare.gt (| - M.get_name (| globals, "numerator_accumulated" |), - Constant.int 0 - |) do - let output := BinOp.add - M.get_name (| globals, "numerator_accumulated" |) - M.get_name (| globals, "numerator_accumulated" |) in - let numerator_accumulated := - BinOp.floor_div (| - BinOp.mult (| - M.get_name (| globals, "numerator_accumulated" |), - M.get_name (| globals, "numerator" |) - |), - BinOp.mult (| - M.get_name (| globals, "denominator" |), - M.get_name (| globals, "i" |) - |) - |) in - let i := BinOp.add - Constant.int 1 - Constant.int 1 in - EndWhile. + let _ := + M.while (| + Compare.gt (| + M.get_name (| globals, "numerator_accumulated" |), + Constant.int 0 + |), + ltac:(M.monadic ( + let output := BinOp.add + M.get_name (| globals, "numerator_accumulated" |) + M.get_name (| globals, "numerator_accumulated" |) in + let numerator_accumulated := + BinOp.floor_div (| + BinOp.mult (| + M.get_name (| globals, "numerator_accumulated" |), + M.get_name (| globals, "numerator" |) + |), + BinOp.mult (| + M.get_name (| globals, "denominator" |), + M.get_name (| globals, "i" |) + |) + |) in + let i := BinOp.add + Constant.int 1 + Constant.int 1 in + M.pure Constant.None_ + )), + ltac:(M.monadic ( + M.pure Constant.None_ + )) + |) in let _ := M.return_ (| BinOp.floor_div (| M.get_name (| globals, "output" |), diff --git a/CoqOfPython/ethereum/utils/safe_arithmetic.v b/CoqOfPython/ethereum/utils/safe_arithmetic.v index f9d67fc..be5bf78 100644 --- a/CoqOfPython/ethereum/utils/safe_arithmetic.v +++ b/CoqOfPython/ethereum/utils/safe_arithmetic.v @@ -1,6 +1,6 @@ Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "ethereum.utils.safe_arithmetic". Definition expr_1 : Value.t := Constant.str " @@ -17,19 +17,11 @@ Introduction Safe arithmetic utility functions for U256 integer type. ". -Require typing. -Axiom typing_Optional : - IsGlobalAlias globals typing.globals "Optional". -Axiom typing_Type_ : - IsGlobalAlias globals typing.globals "Type_". -Axiom typing_Union : - IsGlobalAlias globals typing.globals "Union". +Axiom typing_imports : + AreImported globals "typing" [ "Optional"; "Type"; "Union" ]. -Require ethereum.base_types. -Axiom ethereum_base_types_U256 : - IsGlobalAlias globals ethereum.base_types.globals "U256". -Axiom ethereum_base_types_Uint : - IsGlobalAlias globals ethereum.base_types.globals "Uint". +Axiom ethereum_base_types_imports : + AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. Definition u256_safe_add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -91,6 +83,9 @@ Definition u256_safe_multiply : Value.t -> Value.t -> M := else `exception_type` is raised. " in let result := - M.get_subscript (| M.get_name (| globals, "numbers" |), Constant.int 0 |) in + M.get_subscript (| + M.get_name (| globals, "numbers" |), + Constant.int 0 + |) in (* At stmt: unsupported node type: Try *) M.pure Constant.None_)). diff --git a/main.py b/main.py index d4db1da..2b532fc 100644 --- a/main.py +++ b/main.py @@ -80,36 +80,21 @@ def generate_mod(node: ast.mod): return generate_error("mod", node) -def get_require_path_from_path(path: str) -> str: - # Check if it is a folder - if os.path.isdir(path): - require_path = path + "/__init__" - else: - require_path = path - - return require_path.replace("/", ".") - - -def get_require_path(node: ast.ImportFrom) -> str: +def get_globals_of_import(node: ast.ImportFrom) -> str: module = node.module.replace(".", "/") if node.module is not None else "" - # If this is an external package - if node.level == 0 and module.split("/")[0] != "ethereum": - return module.replace("/", ".") - - # Otherwise we map the module to an actual file system path - # Absolute path + # If this is an absolute import if node.level == 0: - return get_require_path_from_path(module) + return module.replace("/", ".") - # Relative path + # If this is a relative path actual_path = input_file_name for _ in range(node.level): actual_path = os.path.dirname(actual_path) if module != "": actual_path += "/" + module - return get_require_path_from_path(actual_path) + return actual_path.replace("/", ".") def generate_top_level_stmt(node: ast.stmt): @@ -186,17 +171,13 @@ def generate_top_level_stmt(node: ast.stmt): elif isinstance(node, ast.Import): return generate_error("top_level_stmt", node) elif isinstance(node, ast.ImportFrom): - module = get_require_path(node) + module = get_globals_of_import(node) snake_module = module.replace(".", "_") - return f"Require {module}.\n" + \ - "\n".join( - f"Axiom {snake_module}_{generate_name(alias.name)} :\n" + - generate_indent(1) + - f"IsGlobalAlias globals {module}.globals " + - f"\"{generate_name(alias.name)}\"." - for alias in node.names - ) + return f"Axiom {snake_module}_imports :\n" + \ + generate_indent(1) + \ + f"AreImported globals \"{module}\" [ " + \ + "; ".join(f"\"{alias.name}\"" for alias in node.names) + " ]." elif isinstance(node, ast.Global): return generate_error("top_level_stmt", node) elif isinstance(node, ast.Nonlocal): @@ -305,16 +286,30 @@ def generate_stmt(indent, node: ast.stmt): elif isinstance(node, ast.AnnAssign): return generate_error("stmt", node) elif isinstance(node, ast.For): - return generate_indent(indent) + "For " + generate_expr(1, False, node.target) + " in " + \ - generate_expr(1, False, node.iter) + " do\n" + \ - "\n".join(generate_stmt(indent + 1, stmt) for stmt in node.body) + "\n" + \ - generate_indent(indent) + "EndFor." + return generate_indent(indent) + "let _ :=\n" + \ + generate_indent(indent + 1) + "M.for_ (|\n" + \ + generate_indent(indent + 2) + generate_expr(2, False, node.target) + ",\n" + \ + generate_indent(indent + 2) + generate_expr(2, False, node.iter) + ",\n" + \ + generate_indent(indent + 2) + "ltac:(M.monadic (\n" + \ + generate_stmts(indent + 3, node.body) + "\n" + \ + generate_indent(indent + 2) + ")),\n" + \ + generate_indent(indent + 2) + "ltac:(M.monadic (\n" + \ + generate_stmts(indent + 3, node.orelse) + "\n" + \ + generate_indent(indent + 2) + "))\n" + \ + generate_indent(indent) + "|) in" elif isinstance(node, ast.AsyncFor): return generate_error("stmt", node) elif isinstance(node, ast.While): - return generate_indent(indent) + "While " + generate_expr(1, False, node.test) + " do\n" + \ - "\n".join(generate_stmt(indent + 1, stmt) for stmt in node.body) + "\n" + \ - generate_indent(indent) + "EndWhile." + return generate_indent(indent) + "let _ :=\n" + \ + generate_indent(indent + 1) + "M.while (|\n" + \ + generate_indent(indent + 2) + generate_expr(2, False, node.test) + ",\n" + \ + generate_indent(indent + 2) + "ltac:(M.monadic (\n" + \ + generate_stmts(indent + 3, node.body) + "\n" + \ + generate_indent(indent + 2) + ")),\n" + \ + generate_indent(indent + 2) + "ltac:(M.monadic (\n" + \ + generate_stmts(indent + 3, node.orelse) + "\n" + \ + generate_indent(indent + 2) + "))\n" + \ + generate_indent(indent) + "|) in" elif isinstance(node, ast.If): return generate_indent(indent) + "let _ :=\n" + \ generate_if_then_else(indent + 1, node.test, node.body, node.orelse) + \ @@ -327,7 +322,7 @@ def generate_stmt(indent, node: ast.stmt): return generate_error("stmt", node) elif isinstance(node, ast.Raise): return generate_indent(indent) + "let _ := M.raise (| " + \ - ("Some(" + generate_expr(indent, False, node.exc) + ")" + ("Some (" + generate_expr(indent, False, node.exc) + ")" if node.exc is not None else "None") + \ " |) in" @@ -570,9 +565,37 @@ def generate_expr(indent, is_with_paren, node: ast.expr): f"M.get_field (| {generate_expr(indent, False, node.value)}, \"{node.attr}\" |)" ) elif isinstance(node, ast.Subscript): + slice = node.slice + + if isinstance(slice, ast.Slice): + return paren( + is_with_paren, + "M.slice (|\n" + + generate_indent(indent + 1) + + generate_expr(indent + 1, False, node.value) + ",\n" + + generate_indent(indent + 1) + + (generate_expr(indent + 1, False, slice.lower) + if slice.lower is not None + else "Constant.None_") + ",\n" + + generate_indent(indent + 1) + + (generate_expr(indent + 1, False, slice.upper) + if slice.upper is not None + else "Constant.None_") + ",\n" + + generate_indent(indent + 1) + + (generate_expr(indent + 1, False, slice.step) + if slice.step is not None + else "Constant.None_") + "\n" + + generate_indent(indent) + "|)" + ) + return paren( is_with_paren, - f"M.get_subscript (| {generate_expr(indent, False, node.value)}, {generate_expr(indent, False, node.slice)} |)" + "M.get_subscript (|\n" + + generate_indent(indent + 1) + + generate_expr(indent + 1, False, node.value) + ",\n" + + generate_indent(indent + 1) + + generate_expr(indent + 1, False, slice) + "\n" + + generate_indent(indent) + "|)" ) elif isinstance(node, ast.Starred): # We should handle this kind of expression as part of the enclosing expression @@ -592,6 +615,8 @@ def generate_expr(indent, is_with_paren, node: ast.expr): " ]" ) elif isinstance(node, ast.Slice): + # This case is supposed to only appear as part of a Subscript node, so we + # do not handle it here. return paren( is_with_paren, "M.slice (| " + @@ -679,7 +704,7 @@ def generate_cmpop(node): elif isinstance(node, ast.IsNot): return "Compare.is_not" elif isinstance(node, ast.In): - return "Compare.in" + return "Compare.in_" elif isinstance(node, ast.NotIn): return "Compare.not_in" else: @@ -697,10 +722,12 @@ def generate_arg(node): file_content = open(input_file_name).read() parsed_tree = ast.parse(file_content) +globals = input_file_name.replace("/", ".").replace(".py", "") + # Generate Coq code from the AST coq_code = f"""Require Import CoqOfPython.CoqOfPython. -Inductive globals : Set :=. +Definition globals : string := "{globals}". {generate_mod(parsed_tree)} """ @@ -710,7 +737,11 @@ def generate_arg(node): if not os.path.exists(output_directory): os.makedirs(output_directory) -# Output the generated Coq code +# Output the generated Coq code only if the content changed +if os.path.exists(output_file_name): + with open(output_file_name, "r") as output_file: + if output_file.read() == coq_code: + sys.exit(0) with open(output_file_name, "w") as output_file: output_file.write(coq_code) From de3102f7ae520779ac959ea388eb545331194b63 Mon Sep 17 00:00:00 2001 From: Guillaume Claret Date: Fri, 10 May 2024 22:01:01 +0200 Subject: [PATCH 5/6] Type-check all the generated files --- CoqOfPython/CoqOfPython.v | 16 +- CoqOfPython/ethereum/arrow_glacier/__init__.v | 4 +- CoqOfPython/ethereum/arrow_glacier/blocks.v | 50 +- CoqOfPython/ethereum/arrow_glacier/bloom.v | 50 +- CoqOfPython/ethereum/arrow_glacier/fork.v | 708 +++++++++++------ .../ethereum/arrow_glacier/fork_types.v | 34 +- CoqOfPython/ethereum/arrow_glacier/state.v | 148 ++-- .../ethereum/arrow_glacier/transactions.v | 38 +- CoqOfPython/ethereum/arrow_glacier/trie.v | 234 ++++-- .../ethereum/arrow_glacier/utils/address.v | 70 +- .../arrow_glacier/utils/hexadecimal.v | 14 +- .../ethereum/arrow_glacier/utils/message.v | 92 ++- .../ethereum/arrow_glacier/vm/__init__.v | 52 +- .../ethereum/arrow_glacier/vm/exceptions.v | 4 +- CoqOfPython/ethereum/arrow_glacier/vm/gas.v | 136 ++-- .../arrow_glacier/vm/instructions/__init__.v | 54 +- .../vm/instructions/arithmetic.v | 346 ++++++--- .../arrow_glacier/vm/instructions/bitwise.v | 184 +++-- .../arrow_glacier/vm/instructions/block.v | 40 +- .../vm/instructions/comparison.v | 122 ++- .../vm/instructions/control_flow.v | 62 +- .../vm/instructions/environment.v | 338 ++++++--- .../arrow_glacier/vm/instructions/keccak.v | 80 +- .../arrow_glacier/vm/instructions/log.v | 80 +- .../arrow_glacier/vm/instructions/memory.v | 92 ++- .../arrow_glacier/vm/instructions/stack.v | 46 +- .../arrow_glacier/vm/instructions/storage.v | 117 ++- .../arrow_glacier/vm/instructions/system.v | 608 ++++++++++----- .../ethereum/arrow_glacier/vm/interpreter.v | 258 +++++-- .../ethereum/arrow_glacier/vm/memory.v | 12 +- .../vm/precompiled_contracts/__init__.v | 4 +- .../vm/precompiled_contracts/alt_bn128.v | 176 +++-- .../vm/precompiled_contracts/blake2f.v | 34 +- .../vm/precompiled_contracts/ecrecover.v | 82 +- .../vm/precompiled_contracts/identity.v | 32 +- .../vm/precompiled_contracts/mapping.v | 80 +- .../vm/precompiled_contracts/modexp.v | 164 ++-- .../vm/precompiled_contracts/ripemd160.v | 48 +- .../vm/precompiled_contracts/sha256.v | 32 +- .../ethereum/arrow_glacier/vm/runtime.v | 42 +- CoqOfPython/ethereum/arrow_glacier/vm/stack.v | 14 +- CoqOfPython/ethereum/base_types.v | 157 ++-- CoqOfPython/ethereum/berlin/__init__.v | 4 +- CoqOfPython/ethereum/berlin/blocks.v | 50 +- CoqOfPython/ethereum/berlin/bloom.v | 50 +- CoqOfPython/ethereum/berlin/fork.v | 592 ++++++++++----- CoqOfPython/ethereum/berlin/fork_types.v | 34 +- CoqOfPython/ethereum/berlin/state.v | 148 ++-- CoqOfPython/ethereum/berlin/transactions.v | 54 +- CoqOfPython/ethereum/berlin/trie.v | 234 ++++-- CoqOfPython/ethereum/berlin/utils/address.v | 70 +- .../ethereum/berlin/utils/hexadecimal.v | 14 +- CoqOfPython/ethereum/berlin/utils/message.v | 92 ++- CoqOfPython/ethereum/berlin/vm/__init__.v | 52 +- CoqOfPython/ethereum/berlin/vm/exceptions.v | 4 +- CoqOfPython/ethereum/berlin/vm/gas.v | 136 ++-- .../berlin/vm/instructions/__init__.v | 54 +- .../berlin/vm/instructions/arithmetic.v | 346 ++++++--- .../ethereum/berlin/vm/instructions/bitwise.v | 184 +++-- .../ethereum/berlin/vm/instructions/block.v | 40 +- .../berlin/vm/instructions/comparison.v | 122 ++- .../berlin/vm/instructions/control_flow.v | 62 +- .../berlin/vm/instructions/environment.v | 338 ++++++--- .../ethereum/berlin/vm/instructions/keccak.v | 80 +- .../ethereum/berlin/vm/instructions/log.v | 80 +- .../ethereum/berlin/vm/instructions/memory.v | 92 ++- .../ethereum/berlin/vm/instructions/stack.v | 46 +- .../ethereum/berlin/vm/instructions/storage.v | 117 ++- .../ethereum/berlin/vm/instructions/system.v | 628 ++++++++++----- CoqOfPython/ethereum/berlin/vm/interpreter.v | 256 +++++-- CoqOfPython/ethereum/berlin/vm/memory.v | 12 +- .../vm/precompiled_contracts/__init__.v | 4 +- .../vm/precompiled_contracts/alt_bn128.v | 176 +++-- .../berlin/vm/precompiled_contracts/blake2f.v | 34 +- .../vm/precompiled_contracts/ecrecover.v | 82 +- .../vm/precompiled_contracts/identity.v | 32 +- .../berlin/vm/precompiled_contracts/mapping.v | 80 +- .../berlin/vm/precompiled_contracts/modexp.v | 164 ++-- .../vm/precompiled_contracts/ripemd160.v | 48 +- .../berlin/vm/precompiled_contracts/sha256.v | 32 +- CoqOfPython/ethereum/berlin/vm/runtime.v | 42 +- CoqOfPython/ethereum/berlin/vm/stack.v | 14 +- CoqOfPython/ethereum/byzantium/__init__.v | 4 +- CoqOfPython/ethereum/byzantium/blocks.v | 48 +- CoqOfPython/ethereum/byzantium/bloom.v | 50 +- CoqOfPython/ethereum/byzantium/fork.v | 527 ++++++++----- CoqOfPython/ethereum/byzantium/fork_types.v | 34 +- CoqOfPython/ethereum/byzantium/state.v | 128 +++- CoqOfPython/ethereum/byzantium/transactions.v | 30 +- CoqOfPython/ethereum/byzantium/trie.v | 234 ++++-- .../ethereum/byzantium/utils/address.v | 44 +- .../ethereum/byzantium/utils/hexadecimal.v | 14 +- .../ethereum/byzantium/utils/message.v | 76 +- CoqOfPython/ethereum/byzantium/vm/__init__.v | 62 +- .../ethereum/byzantium/vm/exceptions.v | 4 +- CoqOfPython/ethereum/byzantium/vm/gas.v | 136 ++-- .../byzantium/vm/instructions/__init__.v | 54 +- .../byzantium/vm/instructions/arithmetic.v | 346 ++++++--- .../byzantium/vm/instructions/bitwise.v | 104 ++- .../byzantium/vm/instructions/block.v | 40 +- .../byzantium/vm/instructions/comparison.v | 122 ++- .../byzantium/vm/instructions/control_flow.v | 62 +- .../byzantium/vm/instructions/environment.v | 276 ++++--- .../byzantium/vm/instructions/keccak.v | 80 +- .../ethereum/byzantium/vm/instructions/log.v | 80 +- .../byzantium/vm/instructions/memory.v | 92 ++- .../byzantium/vm/instructions/stack.v | 46 +- .../byzantium/vm/instructions/storage.v | 88 ++- .../byzantium/vm/instructions/system.v | 522 +++++++++---- .../ethereum/byzantium/vm/interpreter.v | 254 +++++-- CoqOfPython/ethereum/byzantium/vm/memory.v | 12 +- .../vm/precompiled_contracts/__init__.v | 4 +- .../vm/precompiled_contracts/alt_bn128.v | 176 +++-- .../vm/precompiled_contracts/ecrecover.v | 82 +- .../vm/precompiled_contracts/identity.v | 32 +- .../vm/precompiled_contracts/mapping.v | 56 +- .../vm/precompiled_contracts/modexp.v | 92 ++- .../vm/precompiled_contracts/ripemd160.v | 48 +- .../vm/precompiled_contracts/sha256.v | 32 +- CoqOfPython/ethereum/byzantium/vm/runtime.v | 42 +- CoqOfPython/ethereum/byzantium/vm/stack.v | 14 +- CoqOfPython/ethereum/cancun/__init__.v | 4 +- CoqOfPython/ethereum/cancun/blocks.v | 52 +- CoqOfPython/ethereum/cancun/bloom.v | 50 +- CoqOfPython/ethereum/cancun/fork.v | 710 +++++++++++------ CoqOfPython/ethereum/cancun/fork_types.v | 34 +- CoqOfPython/ethereum/cancun/state.v | 182 +++-- CoqOfPython/ethereum/cancun/transactions.v | 40 +- CoqOfPython/ethereum/cancun/trie.v | 236 ++++-- CoqOfPython/ethereum/cancun/utils/address.v | 70 +- .../ethereum/cancun/utils/hexadecimal.v | 14 +- CoqOfPython/ethereum/cancun/utils/message.v | 92 ++- CoqOfPython/ethereum/cancun/vm/__init__.v | 56 +- CoqOfPython/ethereum/cancun/vm/exceptions.v | 4 +- CoqOfPython/ethereum/cancun/vm/gas.v | 156 ++-- .../cancun/vm/instructions/__init__.v | 54 +- .../cancun/vm/instructions/arithmetic.v | 346 ++++++--- .../ethereum/cancun/vm/instructions/bitwise.v | 184 +++-- .../ethereum/cancun/vm/instructions/block.v | 40 +- .../cancun/vm/instructions/comparison.v | 122 ++- .../cancun/vm/instructions/control_flow.v | 62 +- .../cancun/vm/instructions/environment.v | 368 ++++++--- .../ethereum/cancun/vm/instructions/keccak.v | 80 +- .../ethereum/cancun/vm/instructions/log.v | 80 +- .../ethereum/cancun/vm/instructions/memory.v | 142 ++-- .../ethereum/cancun/vm/instructions/stack.v | 46 +- .../ethereum/cancun/vm/instructions/storage.v | 145 ++-- .../ethereum/cancun/vm/instructions/system.v | 620 ++++++++++----- CoqOfPython/ethereum/cancun/vm/interpreter.v | 260 +++++-- CoqOfPython/ethereum/cancun/vm/memory.v | 12 +- .../vm/precompiled_contracts/__init__.v | 4 +- .../vm/precompiled_contracts/alt_bn128.v | 176 +++-- .../cancun/vm/precompiled_contracts/blake2f.v | 34 +- .../vm/precompiled_contracts/ecrecover.v | 82 +- .../vm/precompiled_contracts/identity.v | 32 +- .../cancun/vm/precompiled_contracts/mapping.v | 88 ++- .../cancun/vm/precompiled_contracts/modexp.v | 164 ++-- .../precompiled_contracts/point_evaluation.v | 68 +- .../vm/precompiled_contracts/ripemd160.v | 48 +- .../cancun/vm/precompiled_contracts/sha256.v | 32 +- CoqOfPython/ethereum/cancun/vm/runtime.v | 42 +- CoqOfPython/ethereum/cancun/vm/stack.v | 14 +- .../ethereum/constantinople/__init__.v | 4 +- CoqOfPython/ethereum/constantinople/blocks.v | 48 +- CoqOfPython/ethereum/constantinople/bloom.v | 50 +- CoqOfPython/ethereum/constantinople/fork.v | 527 ++++++++----- .../ethereum/constantinople/fork_types.v | 34 +- CoqOfPython/ethereum/constantinople/state.v | 128 +++- .../ethereum/constantinople/transactions.v | 30 +- CoqOfPython/ethereum/constantinople/trie.v | 234 ++++-- .../ethereum/constantinople/utils/address.v | 70 +- .../constantinople/utils/hexadecimal.v | 14 +- .../ethereum/constantinople/utils/message.v | 76 +- .../ethereum/constantinople/vm/__init__.v | 62 +- .../ethereum/constantinople/vm/exceptions.v | 4 +- CoqOfPython/ethereum/constantinople/vm/gas.v | 136 ++-- .../constantinople/vm/instructions/__init__.v | 54 +- .../vm/instructions/arithmetic.v | 346 ++++++--- .../constantinople/vm/instructions/bitwise.v | 184 +++-- .../constantinople/vm/instructions/block.v | 40 +- .../vm/instructions/comparison.v | 122 ++- .../vm/instructions/control_flow.v | 62 +- .../vm/instructions/environment.v | 310 +++++--- .../constantinople/vm/instructions/keccak.v | 80 +- .../constantinople/vm/instructions/log.v | 80 +- .../constantinople/vm/instructions/memory.v | 92 ++- .../constantinople/vm/instructions/stack.v | 46 +- .../constantinople/vm/instructions/storage.v | 88 ++- .../constantinople/vm/instructions/system.v | 572 +++++++++----- .../ethereum/constantinople/vm/interpreter.v | 254 +++++-- .../ethereum/constantinople/vm/memory.v | 12 +- .../vm/precompiled_contracts/__init__.v | 4 +- .../vm/precompiled_contracts/alt_bn128.v | 176 +++-- .../vm/precompiled_contracts/ecrecover.v | 82 +- .../vm/precompiled_contracts/identity.v | 32 +- .../vm/precompiled_contracts/mapping.v | 56 +- .../vm/precompiled_contracts/modexp.v | 92 ++- .../vm/precompiled_contracts/ripemd160.v | 48 +- .../vm/precompiled_contracts/sha256.v | 32 +- .../ethereum/constantinople/vm/runtime.v | 42 +- .../ethereum/constantinople/vm/stack.v | 14 +- CoqOfPython/ethereum/crypto/alt_bn128.v | 90 ++- CoqOfPython/ethereum/crypto/blake2.v | 116 ++- CoqOfPython/ethereum/crypto/elliptic_curve.v | 130 ++-- CoqOfPython/ethereum/crypto/finite_field.v | 242 +++--- CoqOfPython/ethereum/crypto/hash.v | 24 +- CoqOfPython/ethereum/dao_fork/__init__.v | 4 +- CoqOfPython/ethereum/dao_fork/blocks.v | 48 +- CoqOfPython/ethereum/dao_fork/bloom.v | 50 +- CoqOfPython/ethereum/dao_fork/dao.v | 18 +- CoqOfPython/ethereum/dao_fork/fork.v | 523 ++++++++----- CoqOfPython/ethereum/dao_fork/fork_types.v | 34 +- CoqOfPython/ethereum/dao_fork/state.v | 110 ++- CoqOfPython/ethereum/dao_fork/transactions.v | 30 +- CoqOfPython/ethereum/dao_fork/trie.v | 234 ++++-- CoqOfPython/ethereum/dao_fork/utils/address.v | 44 +- .../ethereum/dao_fork/utils/hexadecimal.v | 14 +- CoqOfPython/ethereum/dao_fork/utils/message.v | 76 +- CoqOfPython/ethereum/dao_fork/vm/__init__.v | 54 +- CoqOfPython/ethereum/dao_fork/vm/exceptions.v | 4 +- CoqOfPython/ethereum/dao_fork/vm/gas.v | 158 ++-- .../dao_fork/vm/instructions/__init__.v | 54 +- .../dao_fork/vm/instructions/arithmetic.v | 346 ++++++--- .../dao_fork/vm/instructions/bitwise.v | 104 ++- .../ethereum/dao_fork/vm/instructions/block.v | 40 +- .../dao_fork/vm/instructions/comparison.v | 122 ++- .../dao_fork/vm/instructions/control_flow.v | 62 +- .../dao_fork/vm/instructions/environment.v | 238 ++++-- .../dao_fork/vm/instructions/keccak.v | 80 +- .../ethereum/dao_fork/vm/instructions/log.v | 72 +- .../dao_fork/vm/instructions/memory.v | 92 ++- .../ethereum/dao_fork/vm/instructions/stack.v | 46 +- .../dao_fork/vm/instructions/storage.v | 70 +- .../dao_fork/vm/instructions/system.v | 396 +++++++--- .../ethereum/dao_fork/vm/interpreter.v | 226 ++++-- CoqOfPython/ethereum/dao_fork/vm/memory.v | 12 +- .../vm/precompiled_contracts/__init__.v | 4 +- .../vm/precompiled_contracts/ecrecover.v | 82 +- .../vm/precompiled_contracts/identity.v | 32 +- .../vm/precompiled_contracts/mapping.v | 48 +- .../vm/precompiled_contracts/ripemd160.v | 48 +- .../vm/precompiled_contracts/sha256.v | 32 +- CoqOfPython/ethereum/dao_fork/vm/runtime.v | 42 +- CoqOfPython/ethereum/dao_fork/vm/stack.v | 14 +- CoqOfPython/ethereum/ethash.v | 284 ++++--- CoqOfPython/ethereum/fork_criteria.v | 12 +- CoqOfPython/ethereum/frontier/__init__.v | 4 +- CoqOfPython/ethereum/frontier/blocks.v | 48 +- CoqOfPython/ethereum/frontier/bloom.v | 50 +- CoqOfPython/ethereum/frontier/fork.v | 501 ++++++++---- CoqOfPython/ethereum/frontier/fork_types.v | 34 +- CoqOfPython/ethereum/frontier/state.v | 110 ++- CoqOfPython/ethereum/frontier/transactions.v | 30 +- CoqOfPython/ethereum/frontier/trie.v | 228 ++++-- CoqOfPython/ethereum/frontier/utils/address.v | 44 +- .../ethereum/frontier/utils/hexadecimal.v | 14 +- CoqOfPython/ethereum/frontier/utils/message.v | 76 +- CoqOfPython/ethereum/frontier/vm/__init__.v | 54 +- CoqOfPython/ethereum/frontier/vm/exceptions.v | 4 +- CoqOfPython/ethereum/frontier/vm/gas.v | 158 ++-- .../frontier/vm/instructions/__init__.v | 54 +- .../frontier/vm/instructions/arithmetic.v | 346 ++++++--- .../frontier/vm/instructions/bitwise.v | 104 ++- .../ethereum/frontier/vm/instructions/block.v | 40 +- .../frontier/vm/instructions/comparison.v | 122 ++- .../frontier/vm/instructions/control_flow.v | 62 +- .../frontier/vm/instructions/environment.v | 238 ++++-- .../frontier/vm/instructions/keccak.v | 80 +- .../ethereum/frontier/vm/instructions/log.v | 72 +- .../frontier/vm/instructions/memory.v | 92 ++- .../ethereum/frontier/vm/instructions/stack.v | 46 +- .../frontier/vm/instructions/storage.v | 70 +- .../frontier/vm/instructions/system.v | 352 ++++++--- .../ethereum/frontier/vm/interpreter.v | 226 ++++-- CoqOfPython/ethereum/frontier/vm/memory.v | 12 +- .../vm/precompiled_contracts/__init__.v | 4 +- .../vm/precompiled_contracts/ecrecover.v | 82 +- .../vm/precompiled_contracts/identity.v | 32 +- .../vm/precompiled_contracts/mapping.v | 48 +- .../vm/precompiled_contracts/ripemd160.v | 48 +- .../vm/precompiled_contracts/sha256.v | 32 +- CoqOfPython/ethereum/frontier/vm/runtime.v | 42 +- CoqOfPython/ethereum/frontier/vm/stack.v | 14 +- CoqOfPython/ethereum/genesis.v | 165 ++-- CoqOfPython/ethereum/gray_glacier/__init__.v | 4 +- CoqOfPython/ethereum/gray_glacier/blocks.v | 50 +- CoqOfPython/ethereum/gray_glacier/bloom.v | 50 +- CoqOfPython/ethereum/gray_glacier/fork.v | 708 +++++++++++------ .../ethereum/gray_glacier/fork_types.v | 34 +- CoqOfPython/ethereum/gray_glacier/state.v | 148 ++-- .../ethereum/gray_glacier/transactions.v | 38 +- CoqOfPython/ethereum/gray_glacier/trie.v | 234 ++++-- .../ethereum/gray_glacier/utils/address.v | 70 +- .../ethereum/gray_glacier/utils/hexadecimal.v | 14 +- .../ethereum/gray_glacier/utils/message.v | 92 ++- .../ethereum/gray_glacier/vm/__init__.v | 52 +- .../ethereum/gray_glacier/vm/exceptions.v | 4 +- CoqOfPython/ethereum/gray_glacier/vm/gas.v | 136 ++-- .../gray_glacier/vm/instructions/__init__.v | 54 +- .../gray_glacier/vm/instructions/arithmetic.v | 346 ++++++--- .../gray_glacier/vm/instructions/bitwise.v | 184 +++-- .../gray_glacier/vm/instructions/block.v | 40 +- .../gray_glacier/vm/instructions/comparison.v | 122 ++- .../vm/instructions/control_flow.v | 62 +- .../vm/instructions/environment.v | 338 ++++++--- .../gray_glacier/vm/instructions/keccak.v | 80 +- .../gray_glacier/vm/instructions/log.v | 80 +- .../gray_glacier/vm/instructions/memory.v | 92 ++- .../gray_glacier/vm/instructions/stack.v | 46 +- .../gray_glacier/vm/instructions/storage.v | 117 ++- .../gray_glacier/vm/instructions/system.v | 608 ++++++++++----- .../ethereum/gray_glacier/vm/interpreter.v | 258 +++++-- CoqOfPython/ethereum/gray_glacier/vm/memory.v | 12 +- .../vm/precompiled_contracts/__init__.v | 4 +- .../vm/precompiled_contracts/alt_bn128.v | 176 +++-- .../vm/precompiled_contracts/blake2f.v | 34 +- .../vm/precompiled_contracts/ecrecover.v | 82 +- .../vm/precompiled_contracts/identity.v | 32 +- .../vm/precompiled_contracts/mapping.v | 80 +- .../vm/precompiled_contracts/modexp.v | 164 ++-- .../vm/precompiled_contracts/ripemd160.v | 48 +- .../vm/precompiled_contracts/sha256.v | 32 +- .../ethereum/gray_glacier/vm/runtime.v | 42 +- CoqOfPython/ethereum/gray_glacier/vm/stack.v | 14 +- CoqOfPython/ethereum/homestead/__init__.v | 4 +- CoqOfPython/ethereum/homestead/blocks.v | 48 +- CoqOfPython/ethereum/homestead/bloom.v | 50 +- CoqOfPython/ethereum/homestead/fork.v | 515 ++++++++----- CoqOfPython/ethereum/homestead/fork_types.v | 34 +- CoqOfPython/ethereum/homestead/state.v | 110 ++- CoqOfPython/ethereum/homestead/transactions.v | 30 +- CoqOfPython/ethereum/homestead/trie.v | 234 ++++-- .../ethereum/homestead/utils/address.v | 44 +- .../ethereum/homestead/utils/hexadecimal.v | 14 +- .../ethereum/homestead/utils/message.v | 76 +- CoqOfPython/ethereum/homestead/vm/__init__.v | 54 +- .../ethereum/homestead/vm/exceptions.v | 4 +- CoqOfPython/ethereum/homestead/vm/gas.v | 158 ++-- .../homestead/vm/instructions/__init__.v | 54 +- .../homestead/vm/instructions/arithmetic.v | 346 ++++++--- .../homestead/vm/instructions/bitwise.v | 104 ++- .../homestead/vm/instructions/block.v | 40 +- .../homestead/vm/instructions/comparison.v | 122 ++- .../homestead/vm/instructions/control_flow.v | 62 +- .../homestead/vm/instructions/environment.v | 238 ++++-- .../homestead/vm/instructions/keccak.v | 80 +- .../ethereum/homestead/vm/instructions/log.v | 72 +- .../homestead/vm/instructions/memory.v | 92 ++- .../homestead/vm/instructions/stack.v | 46 +- .../homestead/vm/instructions/storage.v | 70 +- .../homestead/vm/instructions/system.v | 396 +++++++--- .../ethereum/homestead/vm/interpreter.v | 226 ++++-- CoqOfPython/ethereum/homestead/vm/memory.v | 12 +- .../vm/precompiled_contracts/__init__.v | 4 +- .../vm/precompiled_contracts/ecrecover.v | 82 +- .../vm/precompiled_contracts/identity.v | 32 +- .../vm/precompiled_contracts/mapping.v | 48 +- .../vm/precompiled_contracts/ripemd160.v | 48 +- .../vm/precompiled_contracts/sha256.v | 32 +- CoqOfPython/ethereum/homestead/vm/runtime.v | 42 +- CoqOfPython/ethereum/homestead/vm/stack.v | 14 +- CoqOfPython/ethereum/istanbul/__init__.v | 4 +- CoqOfPython/ethereum/istanbul/blocks.v | 48 +- CoqOfPython/ethereum/istanbul/bloom.v | 50 +- CoqOfPython/ethereum/istanbul/fork.v | 527 ++++++++----- CoqOfPython/ethereum/istanbul/fork_types.v | 34 +- CoqOfPython/ethereum/istanbul/state.v | 148 ++-- CoqOfPython/ethereum/istanbul/transactions.v | 30 +- CoqOfPython/ethereum/istanbul/trie.v | 234 ++++-- CoqOfPython/ethereum/istanbul/utils/address.v | 70 +- .../ethereum/istanbul/utils/hexadecimal.v | 14 +- CoqOfPython/ethereum/istanbul/utils/message.v | 76 +- CoqOfPython/ethereum/istanbul/vm/__init__.v | 64 +- CoqOfPython/ethereum/istanbul/vm/exceptions.v | 4 +- CoqOfPython/ethereum/istanbul/vm/gas.v | 136 ++-- .../istanbul/vm/instructions/__init__.v | 54 +- .../istanbul/vm/instructions/arithmetic.v | 346 ++++++--- .../istanbul/vm/instructions/bitwise.v | 184 +++-- .../ethereum/istanbul/vm/instructions/block.v | 40 +- .../istanbul/vm/instructions/comparison.v | 122 ++- .../istanbul/vm/instructions/control_flow.v | 62 +- .../istanbul/vm/instructions/environment.v | 340 ++++++--- .../istanbul/vm/instructions/keccak.v | 80 +- .../ethereum/istanbul/vm/instructions/log.v | 80 +- .../istanbul/vm/instructions/memory.v | 92 ++- .../ethereum/istanbul/vm/instructions/stack.v | 46 +- .../istanbul/vm/instructions/storage.v | 96 ++- .../istanbul/vm/instructions/system.v | 572 +++++++++----- .../ethereum/istanbul/vm/interpreter.v | 256 +++++-- CoqOfPython/ethereum/istanbul/vm/memory.v | 12 +- .../vm/precompiled_contracts/__init__.v | 4 +- .../vm/precompiled_contracts/alt_bn128.v | 176 +++-- .../vm/precompiled_contracts/blake2f.v | 34 +- .../vm/precompiled_contracts/ecrecover.v | 82 +- .../vm/precompiled_contracts/identity.v | 32 +- .../vm/precompiled_contracts/mapping.v | 80 +- .../vm/precompiled_contracts/modexp.v | 92 ++- .../vm/precompiled_contracts/ripemd160.v | 48 +- .../vm/precompiled_contracts/sha256.v | 32 +- CoqOfPython/ethereum/istanbul/vm/runtime.v | 42 +- CoqOfPython/ethereum/istanbul/vm/stack.v | 14 +- CoqOfPython/ethereum/london/__init__.v | 4 +- CoqOfPython/ethereum/london/blocks.v | 50 +- CoqOfPython/ethereum/london/bloom.v | 50 +- CoqOfPython/ethereum/london/fork.v | 716 ++++++++++++------ CoqOfPython/ethereum/london/fork_types.v | 34 +- CoqOfPython/ethereum/london/state.v | 148 ++-- CoqOfPython/ethereum/london/transactions.v | 38 +- CoqOfPython/ethereum/london/trie.v | 234 ++++-- CoqOfPython/ethereum/london/utils/address.v | 70 +- .../ethereum/london/utils/hexadecimal.v | 14 +- CoqOfPython/ethereum/london/utils/message.v | 92 ++- CoqOfPython/ethereum/london/vm/__init__.v | 52 +- CoqOfPython/ethereum/london/vm/exceptions.v | 4 +- CoqOfPython/ethereum/london/vm/gas.v | 136 ++-- .../london/vm/instructions/__init__.v | 54 +- .../london/vm/instructions/arithmetic.v | 346 ++++++--- .../ethereum/london/vm/instructions/bitwise.v | 184 +++-- .../ethereum/london/vm/instructions/block.v | 40 +- .../london/vm/instructions/comparison.v | 122 ++- .../london/vm/instructions/control_flow.v | 62 +- .../london/vm/instructions/environment.v | 338 ++++++--- .../ethereum/london/vm/instructions/keccak.v | 80 +- .../ethereum/london/vm/instructions/log.v | 80 +- .../ethereum/london/vm/instructions/memory.v | 92 ++- .../ethereum/london/vm/instructions/stack.v | 46 +- .../ethereum/london/vm/instructions/storage.v | 117 ++- .../ethereum/london/vm/instructions/system.v | 608 ++++++++++----- CoqOfPython/ethereum/london/vm/interpreter.v | 258 +++++-- CoqOfPython/ethereum/london/vm/memory.v | 12 +- .../vm/precompiled_contracts/__init__.v | 4 +- .../vm/precompiled_contracts/alt_bn128.v | 176 +++-- .../london/vm/precompiled_contracts/blake2f.v | 34 +- .../vm/precompiled_contracts/ecrecover.v | 82 +- .../vm/precompiled_contracts/identity.v | 32 +- .../london/vm/precompiled_contracts/mapping.v | 80 +- .../london/vm/precompiled_contracts/modexp.v | 164 ++-- .../vm/precompiled_contracts/ripemd160.v | 48 +- .../london/vm/precompiled_contracts/sha256.v | 32 +- CoqOfPython/ethereum/london/vm/runtime.v | 42 +- CoqOfPython/ethereum/london/vm/stack.v | 14 +- CoqOfPython/ethereum/muir_glacier/__init__.v | 4 +- CoqOfPython/ethereum/muir_glacier/blocks.v | 48 +- CoqOfPython/ethereum/muir_glacier/bloom.v | 50 +- CoqOfPython/ethereum/muir_glacier/fork.v | 527 ++++++++----- .../ethereum/muir_glacier/fork_types.v | 34 +- CoqOfPython/ethereum/muir_glacier/state.v | 148 ++-- .../ethereum/muir_glacier/transactions.v | 30 +- CoqOfPython/ethereum/muir_glacier/trie.v | 234 ++++-- .../ethereum/muir_glacier/utils/address.v | 70 +- .../ethereum/muir_glacier/utils/hexadecimal.v | 14 +- .../ethereum/muir_glacier/utils/message.v | 76 +- .../ethereum/muir_glacier/vm/__init__.v | 64 +- .../ethereum/muir_glacier/vm/exceptions.v | 4 +- CoqOfPython/ethereum/muir_glacier/vm/gas.v | 136 ++-- .../muir_glacier/vm/instructions/__init__.v | 54 +- .../muir_glacier/vm/instructions/arithmetic.v | 346 ++++++--- .../muir_glacier/vm/instructions/bitwise.v | 184 +++-- .../muir_glacier/vm/instructions/block.v | 40 +- .../muir_glacier/vm/instructions/comparison.v | 122 ++- .../vm/instructions/control_flow.v | 62 +- .../vm/instructions/environment.v | 340 ++++++--- .../muir_glacier/vm/instructions/keccak.v | 80 +- .../muir_glacier/vm/instructions/log.v | 80 +- .../muir_glacier/vm/instructions/memory.v | 92 ++- .../muir_glacier/vm/instructions/stack.v | 46 +- .../muir_glacier/vm/instructions/storage.v | 96 ++- .../muir_glacier/vm/instructions/system.v | 572 +++++++++----- .../ethereum/muir_glacier/vm/interpreter.v | 256 +++++-- CoqOfPython/ethereum/muir_glacier/vm/memory.v | 12 +- .../vm/precompiled_contracts/__init__.v | 4 +- .../vm/precompiled_contracts/alt_bn128.v | 176 +++-- .../vm/precompiled_contracts/blake2f.v | 34 +- .../vm/precompiled_contracts/ecrecover.v | 82 +- .../vm/precompiled_contracts/identity.v | 32 +- .../vm/precompiled_contracts/mapping.v | 80 +- .../vm/precompiled_contracts/modexp.v | 92 ++- .../vm/precompiled_contracts/ripemd160.v | 48 +- .../vm/precompiled_contracts/sha256.v | 32 +- .../ethereum/muir_glacier/vm/runtime.v | 42 +- CoqOfPython/ethereum/muir_glacier/vm/stack.v | 14 +- CoqOfPython/ethereum/paris/__init__.v | 6 +- CoqOfPython/ethereum/paris/blocks.v | 50 +- CoqOfPython/ethereum/paris/bloom.v | 50 +- CoqOfPython/ethereum/paris/fork.v | 571 +++++++++----- CoqOfPython/ethereum/paris/fork_types.v | 34 +- CoqOfPython/ethereum/paris/state.v | 148 ++-- CoqOfPython/ethereum/paris/transactions.v | 38 +- CoqOfPython/ethereum/paris/trie.v | 234 ++++-- CoqOfPython/ethereum/paris/utils/address.v | 70 +- .../ethereum/paris/utils/hexadecimal.v | 14 +- CoqOfPython/ethereum/paris/utils/message.v | 92 ++- CoqOfPython/ethereum/paris/vm/__init__.v | 52 +- CoqOfPython/ethereum/paris/vm/exceptions.v | 4 +- CoqOfPython/ethereum/paris/vm/gas.v | 136 ++-- .../ethereum/paris/vm/instructions/__init__.v | 54 +- .../paris/vm/instructions/arithmetic.v | 346 ++++++--- .../ethereum/paris/vm/instructions/bitwise.v | 184 +++-- .../ethereum/paris/vm/instructions/block.v | 40 +- .../paris/vm/instructions/comparison.v | 122 ++- .../paris/vm/instructions/control_flow.v | 62 +- .../paris/vm/instructions/environment.v | 338 ++++++--- .../ethereum/paris/vm/instructions/keccak.v | 80 +- .../ethereum/paris/vm/instructions/log.v | 80 +- .../ethereum/paris/vm/instructions/memory.v | 92 ++- .../ethereum/paris/vm/instructions/stack.v | 46 +- .../ethereum/paris/vm/instructions/storage.v | 117 ++- .../ethereum/paris/vm/instructions/system.v | 608 ++++++++++----- CoqOfPython/ethereum/paris/vm/interpreter.v | 260 +++++-- CoqOfPython/ethereum/paris/vm/memory.v | 12 +- .../paris/vm/precompiled_contracts/__init__.v | 4 +- .../vm/precompiled_contracts/alt_bn128.v | 176 +++-- .../paris/vm/precompiled_contracts/blake2f.v | 34 +- .../vm/precompiled_contracts/ecrecover.v | 82 +- .../paris/vm/precompiled_contracts/identity.v | 32 +- .../paris/vm/precompiled_contracts/mapping.v | 80 +- .../paris/vm/precompiled_contracts/modexp.v | 164 ++-- .../vm/precompiled_contracts/ripemd160.v | 48 +- .../paris/vm/precompiled_contracts/sha256.v | 32 +- CoqOfPython/ethereum/paris/vm/runtime.v | 42 +- CoqOfPython/ethereum/paris/vm/stack.v | 14 +- CoqOfPython/ethereum/rlp.v | 264 +++++-- CoqOfPython/ethereum/shanghai/__init__.v | 4 +- CoqOfPython/ethereum/shanghai/blocks.v | 52 +- CoqOfPython/ethereum/shanghai/bloom.v | 50 +- CoqOfPython/ethereum/shanghai/fork.v | 583 +++++++++----- CoqOfPython/ethereum/shanghai/fork_types.v | 34 +- CoqOfPython/ethereum/shanghai/state.v | 154 ++-- CoqOfPython/ethereum/shanghai/transactions.v | 38 +- CoqOfPython/ethereum/shanghai/trie.v | 236 ++++-- CoqOfPython/ethereum/shanghai/utils/address.v | 70 +- .../ethereum/shanghai/utils/hexadecimal.v | 14 +- CoqOfPython/ethereum/shanghai/utils/message.v | 92 ++- CoqOfPython/ethereum/shanghai/vm/__init__.v | 52 +- CoqOfPython/ethereum/shanghai/vm/exceptions.v | 4 +- CoqOfPython/ethereum/shanghai/vm/gas.v | 136 ++-- .../shanghai/vm/instructions/__init__.v | 54 +- .../shanghai/vm/instructions/arithmetic.v | 346 ++++++--- .../shanghai/vm/instructions/bitwise.v | 184 +++-- .../ethereum/shanghai/vm/instructions/block.v | 40 +- .../shanghai/vm/instructions/comparison.v | 122 ++- .../shanghai/vm/instructions/control_flow.v | 62 +- .../shanghai/vm/instructions/environment.v | 338 ++++++--- .../shanghai/vm/instructions/keccak.v | 80 +- .../ethereum/shanghai/vm/instructions/log.v | 80 +- .../shanghai/vm/instructions/memory.v | 92 ++- .../ethereum/shanghai/vm/instructions/stack.v | 46 +- .../shanghai/vm/instructions/storage.v | 117 ++- .../shanghai/vm/instructions/system.v | 624 ++++++++++----- .../ethereum/shanghai/vm/interpreter.v | 260 +++++-- CoqOfPython/ethereum/shanghai/vm/memory.v | 12 +- .../vm/precompiled_contracts/__init__.v | 4 +- .../vm/precompiled_contracts/alt_bn128.v | 176 +++-- .../vm/precompiled_contracts/blake2f.v | 34 +- .../vm/precompiled_contracts/ecrecover.v | 82 +- .../vm/precompiled_contracts/identity.v | 32 +- .../vm/precompiled_contracts/mapping.v | 80 +- .../vm/precompiled_contracts/modexp.v | 164 ++-- .../vm/precompiled_contracts/ripemd160.v | 48 +- .../vm/precompiled_contracts/sha256.v | 32 +- CoqOfPython/ethereum/shanghai/vm/runtime.v | 42 +- CoqOfPython/ethereum/shanghai/vm/stack.v | 14 +- .../ethereum/spurious_dragon/__init__.v | 4 +- CoqOfPython/ethereum/spurious_dragon/blocks.v | 48 +- CoqOfPython/ethereum/spurious_dragon/bloom.v | 50 +- CoqOfPython/ethereum/spurious_dragon/fork.v | 523 ++++++++----- .../ethereum/spurious_dragon/fork_types.v | 34 +- CoqOfPython/ethereum/spurious_dragon/state.v | 128 +++- .../ethereum/spurious_dragon/transactions.v | 30 +- CoqOfPython/ethereum/spurious_dragon/trie.v | 234 ++++-- .../ethereum/spurious_dragon/utils/address.v | 44 +- .../spurious_dragon/utils/hexadecimal.v | 14 +- .../ethereum/spurious_dragon/utils/message.v | 76 +- .../ethereum/spurious_dragon/vm/__init__.v | 62 +- .../ethereum/spurious_dragon/vm/exceptions.v | 4 +- CoqOfPython/ethereum/spurious_dragon/vm/gas.v | 136 ++-- .../vm/instructions/__init__.v | 54 +- .../vm/instructions/arithmetic.v | 346 ++++++--- .../spurious_dragon/vm/instructions/bitwise.v | 104 ++- .../spurious_dragon/vm/instructions/block.v | 40 +- .../vm/instructions/comparison.v | 122 ++- .../vm/instructions/control_flow.v | 62 +- .../vm/instructions/environment.v | 238 ++++-- .../spurious_dragon/vm/instructions/keccak.v | 80 +- .../spurious_dragon/vm/instructions/log.v | 72 +- .../spurious_dragon/vm/instructions/memory.v | 92 ++- .../spurious_dragon/vm/instructions/stack.v | 46 +- .../spurious_dragon/vm/instructions/storage.v | 70 +- .../spurious_dragon/vm/instructions/system.v | 440 +++++++---- .../ethereum/spurious_dragon/vm/interpreter.v | 252 ++++-- .../ethereum/spurious_dragon/vm/memory.v | 12 +- .../vm/precompiled_contracts/__init__.v | 4 +- .../vm/precompiled_contracts/ecrecover.v | 82 +- .../vm/precompiled_contracts/identity.v | 32 +- .../vm/precompiled_contracts/mapping.v | 48 +- .../vm/precompiled_contracts/ripemd160.v | 48 +- .../vm/precompiled_contracts/sha256.v | 32 +- .../ethereum/spurious_dragon/vm/runtime.v | 42 +- .../ethereum/spurious_dragon/vm/stack.v | 14 +- .../ethereum/tangerine_whistle/__init__.v | 4 +- .../ethereum/tangerine_whistle/blocks.v | 48 +- .../ethereum/tangerine_whistle/bloom.v | 50 +- CoqOfPython/ethereum/tangerine_whistle/fork.v | 515 ++++++++----- .../ethereum/tangerine_whistle/fork_types.v | 34 +- .../ethereum/tangerine_whistle/state.v | 110 ++- .../ethereum/tangerine_whistle/transactions.v | 30 +- CoqOfPython/ethereum/tangerine_whistle/trie.v | 234 ++++-- .../tangerine_whistle/utils/address.v | 44 +- .../tangerine_whistle/utils/hexadecimal.v | 14 +- .../tangerine_whistle/utils/message.v | 76 +- .../ethereum/tangerine_whistle/vm/__init__.v | 54 +- .../tangerine_whistle/vm/exceptions.v | 4 +- .../ethereum/tangerine_whistle/vm/gas.v | 136 ++-- .../vm/instructions/__init__.v | 54 +- .../vm/instructions/arithmetic.v | 346 ++++++--- .../vm/instructions/bitwise.v | 104 ++- .../tangerine_whistle/vm/instructions/block.v | 40 +- .../vm/instructions/comparison.v | 122 ++- .../vm/instructions/control_flow.v | 62 +- .../vm/instructions/environment.v | 238 ++++-- .../vm/instructions/keccak.v | 80 +- .../tangerine_whistle/vm/instructions/log.v | 72 +- .../vm/instructions/memory.v | 92 ++- .../tangerine_whistle/vm/instructions/stack.v | 46 +- .../vm/instructions/storage.v | 70 +- .../vm/instructions/system.v | 444 +++++++---- .../tangerine_whistle/vm/interpreter.v | 226 ++++-- .../ethereum/tangerine_whistle/vm/memory.v | 12 +- .../vm/precompiled_contracts/__init__.v | 4 +- .../vm/precompiled_contracts/ecrecover.v | 82 +- .../vm/precompiled_contracts/identity.v | 32 +- .../vm/precompiled_contracts/mapping.v | 48 +- .../vm/precompiled_contracts/ripemd160.v | 48 +- .../vm/precompiled_contracts/sha256.v | 32 +- .../ethereum/tangerine_whistle/vm/runtime.v | 42 +- .../ethereum/tangerine_whistle/vm/stack.v | 14 +- CoqOfPython/ethereum/trace.v | 10 +- CoqOfPython/ethereum/utils/byte.v | 4 +- CoqOfPython/ethereum/utils/ensure.v | 6 +- CoqOfPython/ethereum/utils/hexadecimal.v | 24 +- CoqOfPython/ethereum/utils/numeric.v | 90 ++- CoqOfPython/ethereum/utils/safe_arithmetic.v | 20 +- main.py | 49 +- 643 files changed, 46624 insertions(+), 24159 deletions(-) diff --git a/CoqOfPython/CoqOfPython.v b/CoqOfPython/CoqOfPython.v index 58cd3e7..b6128c3 100644 --- a/CoqOfPython/CoqOfPython.v +++ b/CoqOfPython/CoqOfPython.v @@ -20,8 +20,10 @@ Module Data. internally to represent integers, closures, ... that can be made accessible in a special field of objects. *) Inductive t (Value : Set) : Set := + | Ellipsis | Bool (b : bool) | Integer (z : Z) + | Float (f : string) | String (s : string) | Tuple (items : list Value) (** Lists and tuples are very similar. The distinction between the two is conventional. We use @@ -34,8 +36,10 @@ Module Data. (bases : list (string * string)) (class_methods : list (string * (Value -> Value -> M))) (methods : list (string * (Value -> Value -> M))). + Arguments Ellipsis {_}. Arguments Bool {_}. Arguments Integer {_}. + Arguments Float {_}. Arguments String {_}. Arguments Tuple {_}. Arguments List {_}. @@ -78,7 +82,7 @@ Parameter M : Set. Parameter IsInGlobals : string -> Value.t -> string -> Prop. -Parameter AreImported : string -> string -> list string -> Prop. +Parameter IsImported : string -> string -> string -> Prop. Module M. Parameter pure : Value.t -> M. @@ -100,8 +104,12 @@ Module M. Parameter assign : Value.t -> Value.t -> M. + Parameter assign_local : string -> Value.t -> M. + Parameter assign_op : (Value.t -> Value.t -> M) -> Value.t -> Value.t -> M. + Parameter assign_op_local : (Value.t -> Value.t -> M) -> string -> Value.t -> M. + Parameter delete : Value.t -> M. Parameter return_ : Value.t -> M. @@ -282,12 +290,18 @@ Module Constant. Object.fields := []; |}). + Definition ellipsis : Value.t := + Value.Make builtins.globals "ellipsis" (Pointer.Imm (Object.wrapper Data.Ellipsis)). + Definition bool (b : bool) : Value.t := Value.Make builtins.globals "bool" (Pointer.Imm (Object.wrapper (Data.Bool b))). Definition int (z : Z) : Value.t := Value.Make builtins.globals "int" (Pointer.Imm (Object.wrapper (Data.Integer z))). + Definition float (f : string) : Value.t := + Value.Make builtins.globals "float" (Pointer.Imm (Object.wrapper (Data.Float f))). + Definition str (s : string) : Value.t := Value.Make builtins.globals "str" (Pointer.Imm (Object.wrapper (Data.String s))). diff --git a/CoqOfPython/ethereum/arrow_glacier/__init__.v b/CoqOfPython/ethereum/arrow_glacier/__init__.v index daac7b6..6adb453 100644 --- a/CoqOfPython/ethereum/arrow_glacier/__init__.v +++ b/CoqOfPython/ethereum/arrow_glacier/__init__.v @@ -8,8 +8,8 @@ The Arrow Glacier fork delays the difficulty bomb. There are no other changes in this fork. ". -Axiom ethereum_fork_criteria_imports : - AreImported globals "ethereum.fork_criteria" [ "ByBlockNumber" ]. +Axiom ethereum_fork_criteria_imports_ByBlockNumber : + IsImported globals "ethereum.fork_criteria" "ByBlockNumber". Definition FORK_CRITERIA : Value.t := M.run ltac:(M.monadic ( M.call (| diff --git a/CoqOfPython/ethereum/arrow_glacier/blocks.v b/CoqOfPython/ethereum/arrow_glacier/blocks.v index 353d9e0..09a6083 100644 --- a/CoqOfPython/ethereum/arrow_glacier/blocks.v +++ b/CoqOfPython/ethereum/arrow_glacier/blocks.v @@ -14,23 +14,39 @@ history of all state transitions that have happened since the genesis of the chain. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Tuple"; "Union" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes8"; "Bytes32"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. - -Axiom ethereum_arrow_glacier_fork_types_imports : - AreImported globals "ethereum.arrow_glacier.fork_types" [ "Address"; "Bloom"; "Root" ]. - -Axiom ethereum_arrow_glacier_transactions_imports : - AreImported globals "ethereum.arrow_glacier.transactions" [ "LegacyTransaction" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes8 : + IsImported globals "ethereum.base_types" "Bytes8". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". + +Axiom ethereum_arrow_glacier_fork_types_imports_Address : + IsImported globals "ethereum.arrow_glacier.fork_types" "Address". +Axiom ethereum_arrow_glacier_fork_types_imports_Bloom : + IsImported globals "ethereum.arrow_glacier.fork_types" "Bloom". +Axiom ethereum_arrow_glacier_fork_types_imports_Root : + IsImported globals "ethereum.arrow_glacier.fork_types" "Root". + +Axiom ethereum_arrow_glacier_transactions_imports_LegacyTransaction : + IsImported globals "ethereum.arrow_glacier.transactions" "LegacyTransaction". Definition Header : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/arrow_glacier/bloom.v b/CoqOfPython/ethereum/arrow_glacier/bloom.v index 0b959bb..9f27d32 100644 --- a/CoqOfPython/ethereum/arrow_glacier/bloom.v +++ b/CoqOfPython/ethereum/arrow_glacier/bloom.v @@ -21,20 +21,20 @@ for efficient searching of logs by address and/or topic, by rapidly eliminating blocks and receipts from their search. ". -Axiom typing_imports : - AreImported globals "typing" [ "Tuple" ]. +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_arrow_glacier_blocks_imports : - AreImported globals "ethereum.arrow_glacier.blocks" [ "Log" ]. +Axiom ethereum_arrow_glacier_blocks_imports_Log : + IsImported globals "ethereum.arrow_glacier.blocks" "Log". -Axiom ethereum_arrow_glacier_fork_types_imports : - AreImported globals "ethereum.arrow_glacier.fork_types" [ "Bloom" ]. +Axiom ethereum_arrow_glacier_fork_types_imports_Bloom : + IsImported globals "ethereum.arrow_glacier.fork_types" "Bloom". Definition add_to_bloom : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -53,20 +53,23 @@ Definition add_to_bloom : Value.t -> Value.t -> M := bloom_entry : An entry which is to be added to bloom filter. " in - let hash := + let _ := M.assign_local (| + "hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "bloom_entry" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "idx" |), make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ], ltac:(M.monadic ( - let bit_to_set := + let _ := M.assign_local (| + "bit_to_set" , BinOp.bit_and (| M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), @@ -84,18 +87,24 @@ Definition add_to_bloom : Value.t -> Value.t -> M := make_dict [] |), Constant.int 2047 - |) in - let bit_index := + |) + |) in + let _ := M.assign_local (| + "bit_index" , BinOp.sub (| Constant.int 2047, M.get_name (| globals, "bit_to_set" |) - |) in - let byte_index := + |) + |) in + let _ := M.assign_local (| + "byte_index" , BinOp.floor_div (| M.get_name (| globals, "bit_index" |), Constant.int 8 - |) in - let bit_value := + |) + |) in + let _ := M.assign_local (| + "bit_value" , BinOp.l_shift (| Constant.int 1, BinOp.sub (| @@ -105,7 +114,8 @@ Definition add_to_bloom : Value.t -> Value.t -> M := Constant.int 8 |) |) - |) in + |) + |) in let _ := M.assign (| M.get_subscript (| M.get_name (| globals, "bloom" |), diff --git a/CoqOfPython/ethereum/arrow_glacier/fork.v b/CoqOfPython/ethereum/arrow_glacier/fork.v index 225bbee..00cdb50 100644 --- a/CoqOfPython/ethereum/arrow_glacier/fork.v +++ b/CoqOfPython/ethereum/arrow_glacier/fork.v @@ -17,62 +17,136 @@ Introduction Entry point for the Ethereum specification. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple"; "Union" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Bytes0" ]. - -Axiom ethereum_crypto_elliptic_curve_imports : - AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. - -Axiom ethereum_ethash_imports : - AreImported globals "ethereum.ethash" [ "dataset_size"; "generate_cache"; "hashimoto_light" ]. - -Axiom ethereum_exceptions_imports : - AreImported globals "ethereum.exceptions" [ "InvalidBlock" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U64"; "U256"; "U256_CEIL_VALUE"; "Bytes"; "Uint" ]. - -Axiom ethereum_arrow_glacier_imports : - AreImported globals "ethereum.arrow_glacier" [ "vm" ]. - -Axiom ethereum_arrow_glacier_blocks_imports : - AreImported globals "ethereum.arrow_glacier.blocks" [ "Block"; "Header"; "Log"; "Receipt" ]. - -Axiom ethereum_arrow_glacier_bloom_imports : - AreImported globals "ethereum.arrow_glacier.bloom" [ "logs_bloom" ]. - -Axiom ethereum_arrow_glacier_fork_types_imports : - AreImported globals "ethereum.arrow_glacier.fork_types" [ "Address"; "Bloom"; "Root" ]. - -Axiom ethereum_arrow_glacier_state_imports : - AreImported globals "ethereum.arrow_glacier.state" [ "State"; "account_exists_and_is_empty"; "create_ether"; "destroy_account"; "get_account"; "increment_nonce"; "set_account_balance"; "state_root" ]. - -Axiom ethereum_arrow_glacier_transactions_imports : - AreImported globals "ethereum.arrow_glacier.transactions" [ "TX_ACCESS_LIST_ADDRESS_COST"; "TX_ACCESS_LIST_STORAGE_KEY_COST"; "TX_BASE_COST"; "TX_CREATE_COST"; "TX_DATA_COST_PER_NON_ZERO"; "TX_DATA_COST_PER_ZERO"; "AccessListTransaction"; "FeeMarketTransaction"; "LegacyTransaction"; "Transaction"; "decode_transaction"; "encode_transaction" ]. - -Axiom ethereum_arrow_glacier_trie_imports : - AreImported globals "ethereum.arrow_glacier.trie" [ "Trie"; "root"; "trie_set" ]. - -Axiom ethereum_arrow_glacier_utils_message_imports : - AreImported globals "ethereum.arrow_glacier.utils.message" [ "prepare_message" ]. - -Axiom ethereum_arrow_glacier_vm_interpreter_imports : - AreImported globals "ethereum.arrow_glacier.vm.interpreter" [ "process_message_call" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". + +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". + +Axiom ethereum_crypto_elliptic_curve_imports_SECP256K1N : + IsImported globals "ethereum.crypto.elliptic_curve" "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_imports_secp256k1_recover : + IsImported globals "ethereum.crypto.elliptic_curve" "secp256k1_recover". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". + +Axiom ethereum_ethash_imports_dataset_size : + IsImported globals "ethereum.ethash" "dataset_size". +Axiom ethereum_ethash_imports_generate_cache : + IsImported globals "ethereum.ethash" "generate_cache". +Axiom ethereum_ethash_imports_hashimoto_light : + IsImported globals "ethereum.ethash" "hashimoto_light". + +Axiom ethereum_exceptions_imports_InvalidBlock : + IsImported globals "ethereum.exceptions" "InvalidBlock". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U64 : + IsImported globals "ethereum.base_types" "U64". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_U256_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U256_CEIL_VALUE". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_arrow_glacier_imports_vm : + IsImported globals "ethereum.arrow_glacier" "vm". + +Axiom ethereum_arrow_glacier_blocks_imports_Block : + IsImported globals "ethereum.arrow_glacier.blocks" "Block". +Axiom ethereum_arrow_glacier_blocks_imports_Header : + IsImported globals "ethereum.arrow_glacier.blocks" "Header". +Axiom ethereum_arrow_glacier_blocks_imports_Log : + IsImported globals "ethereum.arrow_glacier.blocks" "Log". +Axiom ethereum_arrow_glacier_blocks_imports_Receipt : + IsImported globals "ethereum.arrow_glacier.blocks" "Receipt". + +Axiom ethereum_arrow_glacier_bloom_imports_logs_bloom : + IsImported globals "ethereum.arrow_glacier.bloom" "logs_bloom". + +Axiom ethereum_arrow_glacier_fork_types_imports_Address : + IsImported globals "ethereum.arrow_glacier.fork_types" "Address". +Axiom ethereum_arrow_glacier_fork_types_imports_Bloom : + IsImported globals "ethereum.arrow_glacier.fork_types" "Bloom". +Axiom ethereum_arrow_glacier_fork_types_imports_Root : + IsImported globals "ethereum.arrow_glacier.fork_types" "Root". + +Axiom ethereum_arrow_glacier_state_imports_State : + IsImported globals "ethereum.arrow_glacier.state" "State". +Axiom ethereum_arrow_glacier_state_imports_account_exists_and_is_empty : + IsImported globals "ethereum.arrow_glacier.state" "account_exists_and_is_empty". +Axiom ethereum_arrow_glacier_state_imports_create_ether : + IsImported globals "ethereum.arrow_glacier.state" "create_ether". +Axiom ethereum_arrow_glacier_state_imports_destroy_account : + IsImported globals "ethereum.arrow_glacier.state" "destroy_account". +Axiom ethereum_arrow_glacier_state_imports_get_account : + IsImported globals "ethereum.arrow_glacier.state" "get_account". +Axiom ethereum_arrow_glacier_state_imports_increment_nonce : + IsImported globals "ethereum.arrow_glacier.state" "increment_nonce". +Axiom ethereum_arrow_glacier_state_imports_set_account_balance : + IsImported globals "ethereum.arrow_glacier.state" "set_account_balance". +Axiom ethereum_arrow_glacier_state_imports_state_root : + IsImported globals "ethereum.arrow_glacier.state" "state_root". + +Axiom ethereum_arrow_glacier_transactions_imports_TX_ACCESS_LIST_ADDRESS_COST : + IsImported globals "ethereum.arrow_glacier.transactions" "TX_ACCESS_LIST_ADDRESS_COST". +Axiom ethereum_arrow_glacier_transactions_imports_TX_ACCESS_LIST_STORAGE_KEY_COST : + IsImported globals "ethereum.arrow_glacier.transactions" "TX_ACCESS_LIST_STORAGE_KEY_COST". +Axiom ethereum_arrow_glacier_transactions_imports_TX_BASE_COST : + IsImported globals "ethereum.arrow_glacier.transactions" "TX_BASE_COST". +Axiom ethereum_arrow_glacier_transactions_imports_TX_CREATE_COST : + IsImported globals "ethereum.arrow_glacier.transactions" "TX_CREATE_COST". +Axiom ethereum_arrow_glacier_transactions_imports_TX_DATA_COST_PER_NON_ZERO : + IsImported globals "ethereum.arrow_glacier.transactions" "TX_DATA_COST_PER_NON_ZERO". +Axiom ethereum_arrow_glacier_transactions_imports_TX_DATA_COST_PER_ZERO : + IsImported globals "ethereum.arrow_glacier.transactions" "TX_DATA_COST_PER_ZERO". +Axiom ethereum_arrow_glacier_transactions_imports_AccessListTransaction : + IsImported globals "ethereum.arrow_glacier.transactions" "AccessListTransaction". +Axiom ethereum_arrow_glacier_transactions_imports_FeeMarketTransaction : + IsImported globals "ethereum.arrow_glacier.transactions" "FeeMarketTransaction". +Axiom ethereum_arrow_glacier_transactions_imports_LegacyTransaction : + IsImported globals "ethereum.arrow_glacier.transactions" "LegacyTransaction". +Axiom ethereum_arrow_glacier_transactions_imports_Transaction : + IsImported globals "ethereum.arrow_glacier.transactions" "Transaction". +Axiom ethereum_arrow_glacier_transactions_imports_decode_transaction : + IsImported globals "ethereum.arrow_glacier.transactions" "decode_transaction". +Axiom ethereum_arrow_glacier_transactions_imports_encode_transaction : + IsImported globals "ethereum.arrow_glacier.transactions" "encode_transaction". + +Axiom ethereum_arrow_glacier_trie_imports_Trie : + IsImported globals "ethereum.arrow_glacier.trie" "Trie". +Axiom ethereum_arrow_glacier_trie_imports_root : + IsImported globals "ethereum.arrow_glacier.trie" "root". +Axiom ethereum_arrow_glacier_trie_imports_trie_set : + IsImported globals "ethereum.arrow_glacier.trie" "trie_set". + +Axiom ethereum_arrow_glacier_utils_message_imports_prepare_message : + IsImported globals "ethereum.arrow_glacier.utils.message" "prepare_message". + +Axiom ethereum_arrow_glacier_vm_interpreter_imports_process_message_call : + IsImported globals "ethereum.arrow_glacier.vm.interpreter" "process_message_call". Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -198,13 +272,15 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := recent_block_hashes : `List[Hash32]` Hashes of the recent 256 blocks in order of increasing block number. " in - let recent_blocks := + let _ := M.assign_local (| + "recent_blocks" , M.slice (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |), Constant.None_, Constant.None_ - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -228,15 +304,19 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let recent_block_hashes := - make_list [] in + let _ := M.assign_local (| + "recent_block_hashes" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "block" |), M.get_name (| globals, "recent_blocks" |), ltac:(M.monadic ( - let prev_block_hash := - M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in + let _ := M.assign_local (| + "prev_block_hash" , + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), make_list [ @@ -250,7 +330,8 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let most_recent_block_hash := + let _ := M.assign_local (| + "most_recent_block_hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -266,7 +347,8 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), make_list [ @@ -303,11 +385,13 @@ Definition state_transition : Value.t -> Value.t -> M := block : Block to apply to `chain`. " in - let parent_header := + let _ := M.assign_local (| + "parent_header" , M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 1 |) - |), "header" |) in + |), "header" |) + |) in let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ @@ -325,7 +409,8 @@ Definition state_transition : Value.t -> Value.t -> M := ], make_dict [] |) in - let apply_body_output := + let _ := M.assign_local (| + "apply_body_output" , M.call (| M.get_name (| globals, "apply_body" |), make_list [ @@ -348,7 +433,8 @@ Definition state_transition : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "chain" |), "chain_id" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -464,11 +550,13 @@ Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := base_fee_per_gas : `Uint` Base fee per gas for the block. " in - let parent_gas_target := + let _ := M.assign_local (| + "parent_gas_target" , BinOp.floor_div (| M.get_name (| globals, "parent_gas_limit" |), M.get_name (| globals, "ELASTICITY_MULTIPLIER" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -493,8 +581,10 @@ Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let expected_base_fee_per_gas := - M.get_name (| globals, "parent_base_fee_per_gas" |) in + let _ := M.assign_local (| + "expected_base_fee_per_gas" , + M.get_name (| globals, "parent_base_fee_per_gas" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -507,22 +597,29 @@ Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let gas_used_delta := + let _ := M.assign_local (| + "gas_used_delta" , BinOp.sub (| M.get_name (| globals, "parent_gas_used" |), M.get_name (| globals, "parent_gas_target" |) - |) in - let parent_fee_gas_delta := + |) + |) in + let _ := M.assign_local (| + "parent_fee_gas_delta" , BinOp.mult (| M.get_name (| globals, "parent_base_fee_per_gas" |), M.get_name (| globals, "gas_used_delta" |) - |) in - let target_fee_gas_delta := + |) + |) in + let _ := M.assign_local (| + "target_fee_gas_delta" , BinOp.floor_div (| M.get_name (| globals, "parent_fee_gas_delta" |), M.get_name (| globals, "parent_gas_target" |) - |) in - let base_fee_per_gas_delta := + |) + |) in + let _ := M.assign_local (| + "base_fee_per_gas_delta" , M.call (| M.get_name (| globals, "max" |), make_list [ @@ -533,40 +630,53 @@ Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := Constant.int 1 ], make_dict [] - |) in - let expected_base_fee_per_gas := + |) + |) in + let _ := M.assign_local (| + "expected_base_fee_per_gas" , BinOp.add (| M.get_name (| globals, "parent_base_fee_per_gas" |), M.get_name (| globals, "base_fee_per_gas_delta" |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let gas_used_delta := + let _ := M.assign_local (| + "gas_used_delta" , BinOp.sub (| M.get_name (| globals, "parent_gas_target" |), M.get_name (| globals, "parent_gas_used" |) - |) in - let parent_fee_gas_delta := + |) + |) in + let _ := M.assign_local (| + "parent_fee_gas_delta" , BinOp.mult (| M.get_name (| globals, "parent_base_fee_per_gas" |), M.get_name (| globals, "gas_used_delta" |) - |) in - let target_fee_gas_delta := + |) + |) in + let _ := M.assign_local (| + "target_fee_gas_delta" , BinOp.floor_div (| M.get_name (| globals, "parent_fee_gas_delta" |), M.get_name (| globals, "parent_gas_target" |) - |) in - let base_fee_per_gas_delta := + |) + |) in + let _ := M.assign_local (| + "base_fee_per_gas_delta" , BinOp.floor_div (| M.get_name (| globals, "target_fee_gas_delta" |), M.get_name (| globals, "BASE_FEE_MAX_CHANGE_DENOMINATOR" |) - |) in - let expected_base_fee_per_gas := + |) + |) in + let _ := M.assign_local (| + "expected_base_fee_per_gas" , BinOp.sub (| M.get_name (| globals, "parent_base_fee_per_gas" |), M.get_name (| globals, "base_fee_per_gas_delta" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -613,7 +723,8 @@ Definition validate_header : Value.t -> Value.t -> M := ], make_dict [] |) in - let expected_base_fee_per_gas := + let _ := M.assign_local (| + "expected_base_fee_per_gas" , M.call (| M.get_name (| globals, "calculate_base_fee_per_gas" |), make_list [ @@ -623,7 +734,8 @@ Definition validate_header : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "parent_header" |), "base_fee_per_gas" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -635,11 +747,13 @@ Definition validate_header : Value.t -> Value.t -> M := ], make_dict [] |) in - let parent_has_ommers := + let _ := M.assign_local (| + "parent_has_ommers" , Compare.not_eq (| M.get_field (| M.get_name (| globals, "parent_header" |), "ommers_hash" |), M.get_name (| globals, "EMPTY_OMMER_HASH" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -682,7 +796,8 @@ Definition validate_header : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_difficulty := + let _ := M.assign_local (| + "block_difficulty" , M.call (| M.get_name (| globals, "calculate_block_difficulty" |), make_list [ @@ -693,7 +808,8 @@ Definition validate_header : Value.t -> Value.t -> M := M.get_name (| globals, "parent_has_ommers" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -705,7 +821,8 @@ Definition validate_header : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_parent_hash := + let _ := M.assign_local (| + "block_parent_hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -718,7 +835,8 @@ Definition validate_header : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -764,7 +882,8 @@ Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := hash : `Hash32` The PoW valid rlp hash of the passed in header. " in - let header_data_without_pow_artefacts := + let _ := M.assign_local (| + "header_data_without_pow_artefacts" , make_list [ M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |); M.get_field (| M.get_name (| globals, "header" |), "ommers_hash" |); @@ -780,7 +899,8 @@ Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "header" |), "timestamp" |); M.get_field (| M.get_name (| globals, "header" |), "extra_data" |); M.get_field (| M.get_name (| globals, "header" |), "base_fee_per_gas" |) - ] in + ] + |) in let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), @@ -809,22 +929,26 @@ Definition validate_proof_of_work : Value.t -> Value.t -> M := header : Header of interest. " in - let header_hash := + let _ := M.assign_local (| + "header_hash" , M.call (| M.get_name (| globals, "generate_header_hash_for_pow" |), make_list [ M.get_name (| globals, "header" |) ], make_dict [] - |) in - let cache := + |) + |) in + let _ := M.assign_local (| + "cache" , M.call (| M.get_name (| globals, "generate_cache" |), make_list [ M.get_field (| M.get_name (| globals, "header" |), "number" |) ], make_dict [] - |) in + |) + |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "mix_digest" |); M.get_name (| globals, "result" |) ], M.call (| @@ -917,7 +1041,8 @@ Definition check_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_address := + let _ := M.assign_local (| + "sender_address" , M.call (| M.get_name (| globals, "recover_sender" |), make_list [ @@ -925,7 +1050,8 @@ Definition check_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "tx" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -961,7 +1087,8 @@ Definition check_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let priority_fee_per_gas := + let _ := M.assign_local (| + "priority_fee_per_gas" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -972,12 +1099,15 @@ Definition check_transaction : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let effective_gas_price := + |) + |) in + let _ := M.assign_local (| + "effective_gas_price" , BinOp.add (| M.get_name (| globals, "priority_fee_per_gas" |), M.get_name (| globals, "base_fee_per_gas" |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -992,8 +1122,10 @@ Definition check_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let effective_gas_price := - M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) in + let _ := M.assign_local (| + "effective_gas_price" , + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) + |) in M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1024,12 +1156,14 @@ Definition make_receipt : Value.t -> Value.t -> M := receipt : The receipt for the transaction. " in - let receipt := + let _ := M.assign_local (| + "receipt" , M.call (| M.get_name (| globals, "Receipt" |), make_list [], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1150,8 +1284,10 @@ Definition apply_body : Value.t -> Value.t -> M := apply_body_output : `ApplyBodyOutput` Output of applying the block body to the state. " in - let gas_available := - M.get_name (| globals, "block_gas_limit" |) in + let _ := M.assign_local (| + "gas_available" , + M.get_name (| globals, "block_gas_limit" |) + |) in (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) @@ -1213,12 +1349,14 @@ Definition apply_body : Value.t -> Value.t -> M := make_dict [] |) |) in - let env := + let _ := M.assign_local (| + "env" , M.call (| M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |); M.get_name (| globals, "error" |) ], M.call (| @@ -1230,10 +1368,13 @@ Definition apply_body : Value.t -> Value.t -> M := make_dict [] |) |) in - let gas_available := BinOp.sub + let _ := M.assign_op_local (| + BinOp.sub, + "gas_available", M.get_name (| globals, "gas_used" |) - M.get_name (| globals, "gas_used" |) in - let receipt := + |) in + let _ := M.assign_local (| + "receipt" , M.call (| M.get_name (| globals, "make_receipt" |), make_list [ @@ -1246,7 +1387,8 @@ Definition apply_body : Value.t -> Value.t -> M := M.get_name (| globals, "logs" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ @@ -1268,9 +1410,11 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_logs := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "block_logs", M.get_name (| globals, "logs" |) - M.get_name (| globals, "logs" |) in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -1287,19 +1431,23 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_gas_used := + let _ := M.assign_local (| + "block_gas_used" , BinOp.sub (| M.get_name (| globals, "block_gas_limit" |), M.get_name (| globals, "gas_available" |) - |) in - let block_logs_bloom := + |) + |) in + let _ := M.assign_local (| + "block_logs_bloom" , M.call (| M.get_name (| globals, "logs_bloom" |), make_list [ M.get_name (| globals, "block_logs" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ApplyBodyOutput" |), @@ -1357,14 +1505,16 @@ Definition validate_ommers : Value.t -> Value.t -> M := chain : History and current state. " in - let block_hash := + let _ := M.assign_local (| + "block_hash" , M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), make_list [ M.get_name (| globals, "block_header" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1429,7 +1579,8 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_parent_header := + let _ := M.assign_local (| + "ommer_parent_header" , M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), BinOp.sub (| @@ -1439,7 +1590,8 @@ Definition validate_ommers : Value.t -> Value.t -> M := |) |), Constant.int 1 |) - |), "header" |) in + |), "header" |) + |) in let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ @@ -1471,8 +1623,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommers_hashes := - Constant.str "(* At expr: unsupported node type: ListComp *)" in + let _ := M.assign_local (| + "ommers_hashes" , + Constant.str "(* At expr: unsupported node type: ListComp *)" + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1502,7 +1656,8 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let recent_canonical_blocks := + let _ := M.assign_local (| + "recent_canonical_blocks" , M.slice (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| BinOp.add (| @@ -1511,23 +1666,28 @@ Definition validate_ommers : Value.t -> Value.t -> M := |) |), Constant.None_, Constant.None_ - |) in - let recent_canonical_block_hashes := - Constant.str "(* At expr: unsupported node type: SetComp *)" in + |) + |) in + let _ := M.assign_local (| + "recent_canonical_block_hashes" , + Constant.str "(* At expr: unsupported node type: SetComp *)" + |) in (* At stmt: unsupported node type: AnnAssign *) let _ := M.for_ (| M.get_name (| globals, "block" |), M.get_name (| globals, "recent_canonical_blocks" |), ltac:(M.monadic ( - let recent_ommers_hashes := + let _ := M.assign_local (| + "recent_ommers_hashes" , M.call (| M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), make_list [ Constant.str "(* At expr: unsupported node type: SetComp *)" ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -1545,11 +1705,13 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let ommer_hash := + let _ := M.assign_local (| + "ommer_hash" , M.get_subscript (| M.get_name (| globals, "ommers_hashes" |), M.get_name (| globals, "ommer_index" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1583,11 +1745,13 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_age := + let _ := M.assign_local (| + "ommer_age" , BinOp.sub (| M.get_field (| M.get_name (| globals, "block_header" |), "number" |), M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1665,7 +1829,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := ommers : List of ommers mentioned in the current block. " in - let miner_reward := + let _ := M.assign_local (| + "miner_reward" , BinOp.add (| M.get_name (| globals, "BLOCK_REWARD" |), BinOp.mult (| @@ -1681,7 +1846,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := Constant.int 32 |) |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "create_ether" |), make_list [ @@ -1696,7 +1862,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := M.get_name (| globals, "ommer" |), M.get_name (| globals, "ommers" |), ltac:(M.monadic ( - let ommer_age := + let _ := M.assign_local (| + "ommer_age" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -1706,8 +1873,10 @@ Definition pay_rewards : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let ommer_miner_reward := + |) + |) in + let _ := M.assign_local (| + "ommer_miner_reward" , BinOp.floor_div (| BinOp.mult (| BinOp.sub (| @@ -1717,7 +1886,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := M.get_name (| globals, "BLOCK_REWARD" |) |), Constant.int 8 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "create_ether" |), make_list [ @@ -1778,9 +1948,12 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender := - M.get_field (| M.get_name (| globals, "env" |), "origin" |) in - let sender_account := + let _ := M.assign_local (| + "sender" , + M.get_field (| M.get_name (| globals, "env" |), "origin" |) + |) in + let _ := M.assign_local (| + "sender_account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1788,7 +1961,8 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "sender" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1802,19 +1976,23 @@ Definition process_transaction : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let max_gas_fee := + let _ := M.assign_local (| + "max_gas_fee" , BinOp.mult (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let max_gas_fee := + let _ := M.assign_local (| + "max_gas_fee" , BinOp.mult (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -1857,12 +2035,15 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let effective_gas_fee := + let _ := M.assign_local (| + "effective_gas_fee" , BinOp.mult (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_field (| M.get_name (| globals, "env" |), "gas_price" |) - |) in - let gas := + |) + |) in + let _ := M.assign_local (| + "gas" , BinOp.sub (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.call (| @@ -1872,7 +2053,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "increment_nonce" |), make_list [ @@ -1881,11 +2063,13 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_balance_after_gas_fee := + let _ := M.assign_local (| + "sender_balance_after_gas_fee" , BinOp.sub (| M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), M.get_name (| globals, "effective_gas_fee" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -1895,18 +2079,22 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let preaccessed_addresses := + let _ := M.assign_local (| + "preaccessed_addresses" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let preaccessed_storage_keys := + |) + |) in + let _ := M.assign_local (| + "preaccessed_storage_keys" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1961,7 +2149,8 @@ Definition process_transaction : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let message := + let _ := M.assign_local (| + "message" , M.call (| M.get_name (| globals, "prepare_message" |), make_list [ @@ -1973,8 +2162,10 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in - let output := + |) + |) in + let _ := M.assign_local (| + "output" , M.call (| M.get_name (| globals, "process_message_call" |), make_list [ @@ -1982,13 +2173,17 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in - let gas_used := + |) + |) in + let _ := M.assign_local (| + "gas_used" , BinOp.sub (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_field (| M.get_name (| globals, "output" |), "gas_left" |) - |) in - let gas_refund := + |) + |) in + let _ := M.assign_local (| + "gas_refund" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -1999,21 +2194,27 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "output" |), "refund_counter" |) ], make_dict [] - |) in - let gas_refund_amount := + |) + |) in + let _ := M.assign_local (| + "gas_refund_amount" , BinOp.mult (| BinOp.add (| M.get_field (| M.get_name (| globals, "output" |), "gas_left" |), M.get_name (| globals, "gas_refund" |) |), M.get_field (| M.get_name (| globals, "env" |), "gas_price" |) - |) in - let priority_fee_per_gas := + |) + |) in + let _ := M.assign_local (| + "priority_fee_per_gas" , BinOp.sub (| M.get_field (| M.get_name (| globals, "env" |), "gas_price" |), M.get_field (| M.get_name (| globals, "env" |), "base_fee_per_gas" |) - |) in - let transaction_fee := + |) + |) in + let _ := M.assign_local (| + "transaction_fee" , BinOp.mult (| BinOp.sub (| BinOp.sub (| @@ -2023,13 +2224,17 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "gas_refund" |) |), M.get_name (| globals, "priority_fee_per_gas" |) - |) in - let total_gas_used := + |) + |) in + let _ := M.assign_local (| + "total_gas_used" , BinOp.sub (| M.get_name (| globals, "gas_used" |), M.get_name (| globals, "gas_refund" |) - |) in - let sender_balance_after_refund := + |) + |) in + let _ := M.assign_local (| + "sender_balance_after_refund" , BinOp.add (| M.get_field (| M.call (| M.get_name (| globals, "get_account" |), @@ -2040,7 +2245,8 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |), "balance" |), M.get_name (| globals, "gas_refund_amount" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -2050,7 +2256,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let coinbase_balance_after_mining_fee := + let _ := M.assign_local (| + "coinbase_balance_after_mining_fee" , BinOp.add (| M.get_field (| M.call (| M.get_name (| globals, "get_account" |), @@ -2061,7 +2268,8 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |), "balance" |), M.get_name (| globals, "transaction_fee" |) - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -2252,8 +2460,10 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := verified : `ethereum.base_types.Uint` The intrinsic cost of the transaction. " in - let data_cost := - Constant.int 0 in + let _ := M.assign_local (| + "data_cost" , + Constant.int 0 + |) in let _ := M.for_ (| M.get_name (| globals, "byte" |), @@ -2268,15 +2478,19 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let data_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "data_cost", M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let data_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "data_cost", M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -2300,17 +2514,23 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let create_cost := - M.get_name (| globals, "TX_CREATE_COST" |) in + let _ := M.assign_local (| + "create_cost" , + M.get_name (| globals, "TX_CREATE_COST" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let create_cost := - Constant.int 0 in + let _ := M.assign_local (| + "create_cost" , + Constant.int 0 + |) in M.pure Constant.None_ )) |) in - let access_list_cost := - Constant.int 0 in + let _ := M.assign_local (| + "access_list_cost" , + Constant.int 0 + |) in let _ := (* if *) M.if_then_else (| @@ -2329,10 +2549,14 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := make_tuple [ M.get_name (| globals, "_address" |); M.get_name (| globals, "keys" |) ], M.get_field (| M.get_name (| globals, "tx" |), "access_list" |), ltac:(M.monadic ( - let access_list_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "access_list_cost", M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) - M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) in - let access_list_cost := BinOp.add + |) in + let _ := M.assign_op_local (| + BinOp.add, + "access_list_cost", BinOp.mult (| M.call (| M.get_name (| globals, "len" |), @@ -2343,16 +2567,7 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) |) - BinOp.mult (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "keys" |) - ], - make_dict [] - |), - M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) - |) in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -2466,8 +2681,10 @@ Definition recover_sender : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let v := - M.get_field (| M.get_name (| globals, "tx" |), "v" |) in + let _ := M.assign_local (| + "v" , + M.get_field (| M.get_name (| globals, "tx" |), "v" |) + |) in let _ := (* if *) M.if_then_else (| @@ -2485,7 +2702,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let public_key := + let _ := M.assign_local (| + "public_key" , M.call (| M.get_name (| globals, "secp256k1_recover" |), make_list [ @@ -2504,7 +2722,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -2539,7 +2758,8 @@ Definition recover_sender : Value.t -> Value.t -> M := ], make_dict [] |) in - let public_key := + let _ := M.assign_local (| + "public_key" , M.call (| M.get_name (| globals, "secp256k1_recover" |), make_list [ @@ -2565,7 +2785,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -2584,7 +2805,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let public_key := + let _ := M.assign_local (| + "public_key" , M.call (| M.get_name (| globals, "secp256k1_recover" |), make_list [ @@ -2600,7 +2822,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -2617,7 +2840,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let public_key := + let _ := M.assign_local (| + "public_key" , M.call (| M.get_name (| globals, "secp256k1_recover" |), make_list [ @@ -2633,7 +2857,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -2898,11 +3123,13 @@ Definition check_gas_limit : Value.t -> Value.t -> M := check : `bool` True if gas limit constraints are satisfied, False otherwise. " in - let max_adjustment_delta := + let _ := M.assign_local (| + "max_adjustment_delta" , BinOp.floor_div (| M.get_name (| globals, "parent_gas_limit" |), M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -3006,7 +3233,8 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := difficulty : `ethereum.base_types.Uint` Computed difficulty for a block. " in - let offset := + let _ := M.assign_local (| + "offset" , BinOp.mult (| BinOp.floor_div (| M.call (| @@ -3050,8 +3278,10 @@ Constant.int 1 ], make_dict [] |) - |) in - let difficulty := + |) + |) in + let _ := M.assign_local (| + "difficulty" , BinOp.add (| M.call (| M.get_name (| globals, "int" |), @@ -3061,8 +3291,10 @@ Constant.int 1 make_dict [] |), M.get_name (| globals, "offset" |) - |) in - let num_bomb_periods := + |) + |) in + let _ := M.assign_local (| + "num_bomb_periods" , BinOp.sub (| BinOp.floor_div (| BinOp.sub (| @@ -3078,7 +3310,8 @@ Constant.int 1 Constant.int 100000 |), Constant.int 2 - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -3088,15 +3321,14 @@ Constant.int 1 |), (* then *) ltac:(M.monadic ( - let difficulty := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "difficulty", BinOp.pow (| Constant.int 2, M.get_name (| globals, "num_bomb_periods" |) |) - BinOp.pow (| - Constant.int 2, - M.get_name (| globals, "num_bomb_periods" |) - |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/arrow_glacier/fork_types.v b/CoqOfPython/ethereum/arrow_glacier/fork_types.v index d08565d..e46e8cb 100644 --- a/CoqOfPython/ethereum/arrow_glacier/fork_types.v +++ b/CoqOfPython/ethereum/arrow_glacier/fork_types.v @@ -17,17 +17,29 @@ Introduction Types re-used throughout the specification, which are specific to Ethereum. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes20"; "Bytes256"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes20 : + IsImported globals "ethereum.base_types" "Bytes20". +Axiom ethereum_base_types_imports_Bytes256 : + IsImported globals "ethereum.base_types" "Bytes256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) diff --git a/CoqOfPython/ethereum/arrow_glacier/state.v b/CoqOfPython/ethereum/arrow_glacier/state.v index 18088d3..455bfaa 100644 --- a/CoqOfPython/ethereum/arrow_glacier/state.v +++ b/CoqOfPython/ethereum/arrow_glacier/state.v @@ -22,23 +22,57 @@ There is a distinction between an account that does not exist and `EMPTY_ACCOUNT`. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass"; "field" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict"; "List"; "Optional"; "Set"; "Tuple" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "modify" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_arrow_glacier_fork_types_imports : - AreImported globals "ethereum.arrow_glacier.fork_types" [ "EMPTY_ACCOUNT"; "Account"; "Address"; "Root" ]. - -Axiom ethereum_arrow_glacier_trie_imports : - AreImported globals "ethereum.arrow_glacier.trie" [ "EMPTY_TRIE_ROOT"; "Trie"; "copy_trie"; "root"; "trie_get"; "trie_set" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". +Axiom dataclasses_imports_field : + IsImported globals "dataclasses" "field". + +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_modify : + IsImported globals "ethereum.base_types" "modify". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_arrow_glacier_fork_types_imports_EMPTY_ACCOUNT : + IsImported globals "ethereum.arrow_glacier.fork_types" "EMPTY_ACCOUNT". +Axiom ethereum_arrow_glacier_fork_types_imports_Account : + IsImported globals "ethereum.arrow_glacier.fork_types" "Account". +Axiom ethereum_arrow_glacier_fork_types_imports_Address : + IsImported globals "ethereum.arrow_glacier.fork_types" "Address". +Axiom ethereum_arrow_glacier_fork_types_imports_Root : + IsImported globals "ethereum.arrow_glacier.fork_types" "Root". + +Axiom ethereum_arrow_glacier_trie_imports_EMPTY_TRIE_ROOT : + IsImported globals "ethereum.arrow_glacier.trie" "EMPTY_TRIE_ROOT". +Axiom ethereum_arrow_glacier_trie_imports_Trie : + IsImported globals "ethereum.arrow_glacier.trie" "Trie". +Axiom ethereum_arrow_glacier_trie_imports_copy_trie : + IsImported globals "ethereum.arrow_glacier.trie" "copy_trie". +Axiom ethereum_arrow_glacier_trie_imports_root : + IsImported globals "ethereum.arrow_glacier.trie" "root". +Axiom ethereum_arrow_glacier_trie_imports_trie_get : + IsImported globals "ethereum.arrow_glacier.trie" "trie_get". +Axiom ethereum_arrow_glacier_trie_imports_trie_set : + IsImported globals "ethereum.arrow_glacier.trie" "trie_set". Definition State : Value.t := builtins.make_klass @@ -186,7 +220,8 @@ Definition get_account : Value.t -> Value.t -> M := account : `Account` Account at address. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account_optional" |), make_list [ @@ -194,7 +229,8 @@ Definition get_account : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -240,7 +276,8 @@ Definition get_account_optional : Value.t -> Value.t -> M := account : `Account` Account at address. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "trie_get" |), make_list [ @@ -248,7 +285,8 @@ Definition get_account_optional : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "account" |) |) in @@ -399,14 +437,16 @@ Definition get_storage : Value.t -> Value.t -> M := value : `U256` Value at the key. " in - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -430,7 +470,8 @@ Definition get_storage : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "trie_get" |), make_list [ @@ -438,7 +479,8 @@ Definition get_storage : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -481,14 +523,16 @@ Definition set_storage : Value.t -> Value.t -> M := |), Constant.None_ |) |) in - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -498,12 +542,14 @@ Definition set_storage : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_name (| globals, "Trie" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), @@ -530,7 +576,7 @@ Definition set_storage : Value.t -> Value.t -> M := M.if_then_else (| Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), - {} + Constant.str "(* At expr: unsupported node type: Dict *)" |), (* then *) ltac:(M.monadic ( @@ -676,7 +722,8 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := True if if an account has non zero nonce or non empty code, False otherwise. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -684,7 +731,8 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| BoolOp.or (| Compare.not_eq (| @@ -726,7 +774,8 @@ Definition is_account_empty : Value.t -> Value.t -> M := True if if an account has zero nonce, empty code and zero balance, False otherwise. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -734,7 +783,8 @@ Definition is_account_empty : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| BoolOp.and (| Compare.eq (| @@ -785,7 +835,8 @@ Definition account_exists_and_is_empty : Value.t -> Value.t -> M := True if an account exists and has zero nonce, empty code and zero balance, False otherwise. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account_optional" |), make_list [ @@ -793,7 +844,8 @@ Definition account_exists_and_is_empty : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| BoolOp.and (| Compare.is_not (| @@ -850,7 +902,8 @@ Definition is_account_alive : Value.t -> Value.t -> M := is_alive : `bool` True if the account is alive. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account_optional" |), make_list [ @@ -858,7 +911,8 @@ Definition is_account_alive : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1166,14 +1220,16 @@ Definition get_storage_original : Value.t -> Value.t -> M := Constant.int 0 |) |) in - let original_account_trie := + let _ := M.assign_local (| + "original_account_trie" , M.call (| M.get_field (| M.get_name (| globals, "original_trie" |), "get" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1183,18 +1239,21 @@ Definition get_storage_original : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let original_value := + let _ := M.assign_local (| + "original_value" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let original_value := + let _ := M.assign_local (| + "original_value" , M.call (| M.get_name (| globals, "trie_get" |), make_list [ @@ -1202,7 +1261,8 @@ Definition get_storage_original : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.assert (| M.call (| diff --git a/CoqOfPython/ethereum/arrow_glacier/transactions.v b/CoqOfPython/ethereum/arrow_glacier/transactions.v index 770e331..67ba8e4 100644 --- a/CoqOfPython/ethereum/arrow_glacier/transactions.v +++ b/CoqOfPython/ethereum/arrow_glacier/transactions.v @@ -9,23 +9,37 @@ submitted to be executed. If Ethereum is viewed as a state machine, transactions are the events that move between states. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". -Axiom typing_imports : - AreImported globals "typing" [ "Tuple"; "Union" ]. +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U64"; "U256"; "Bytes"; "Bytes0"; "Bytes32"; "Uint"; "slotted_freezable" ]. +Axiom ethereum_base_types_imports_U64 : + IsImported globals "ethereum.base_types" "U64". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". -Axiom ethereum_exceptions_imports : - AreImported globals "ethereum.exceptions" [ "InvalidBlock" ]. +Axiom ethereum_exceptions_imports_InvalidBlock : + IsImported globals "ethereum.exceptions" "InvalidBlock". -Axiom ethereum_arrow_glacier_fork_types_imports : - AreImported globals "ethereum.arrow_glacier.fork_types" [ "Address" ]. +Axiom ethereum_arrow_glacier_fork_types_imports_Address : + IsImported globals "ethereum.arrow_glacier.fork_types" "Address". Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( Constant.int 21000 diff --git a/CoqOfPython/ethereum/arrow_glacier/trie.v b/CoqOfPython/ethereum/arrow_glacier/trie.v index 022a627..0941ddc 100644 --- a/CoqOfPython/ethereum/arrow_glacier/trie.v +++ b/CoqOfPython/ethereum/arrow_glacier/trie.v @@ -20,38 +20,72 @@ The state trie is the structure responsible for storing (* At top_level_stmt: unsupported node type: Import *) -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass"; "field" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict"; "Generic"; "List"; "Mapping"; "MutableMapping"; "Optional"; "Sequence"; "TypeVar"; "Union"; "cast" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. - -Axiom ethereum_london_imports : - AreImported globals "ethereum.london" [ "trie" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_utils_hexadecimal_imports : - AreImported globals "ethereum.utils.hexadecimal" [ "hex_to_bytes" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_arrow_glacier_blocks_imports : - AreImported globals "ethereum.arrow_glacier.blocks" [ "Receipt" ]. - -Axiom ethereum_arrow_glacier_fork_types_imports : - AreImported globals "ethereum.arrow_glacier.fork_types" [ "Account"; "Address"; "Root"; "encode_account" ]. - -Axiom ethereum_arrow_glacier_transactions_imports : - AreImported globals "ethereum.arrow_glacier.transactions" [ "LegacyTransaction" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". +Axiom dataclasses_imports_field : + IsImported globals "dataclasses" "field". + +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". +Axiom typing_imports_Generic : + IsImported globals "typing" "Generic". +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Mapping : + IsImported globals "typing" "Mapping". +Axiom typing_imports_MutableMapping : + IsImported globals "typing" "MutableMapping". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Sequence : + IsImported globals "typing" "Sequence". +Axiom typing_imports_TypeVar : + IsImported globals "typing" "TypeVar". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". +Axiom typing_imports_cast : + IsImported globals "typing" "cast". + +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". + +Axiom ethereum_london_imports_trie : + IsImported globals "ethereum.london" "trie". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_utils_hexadecimal_imports_hex_to_bytes : + IsImported globals "ethereum.utils.hexadecimal" "hex_to_bytes". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_arrow_glacier_blocks_imports_Receipt : + IsImported globals "ethereum.arrow_glacier.blocks" "Receipt". + +Axiom ethereum_arrow_glacier_fork_types_imports_Account : + IsImported globals "ethereum.arrow_glacier.fork_types" "Account". +Axiom ethereum_arrow_glacier_fork_types_imports_Address : + IsImported globals "ethereum.arrow_glacier.fork_types" "Address". +Axiom ethereum_arrow_glacier_fork_types_imports_Root : + IsImported globals "ethereum.arrow_glacier.fork_types" "Root". +Axiom ethereum_arrow_glacier_fork_types_imports_encode_account : + IsImported globals "ethereum.arrow_glacier.fork_types" "encode_account". + +Axiom ethereum_arrow_glacier_transactions_imports_LegacyTransaction : + IsImported globals "ethereum.arrow_glacier.transactions" "LegacyTransaction". Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -167,7 +201,7 @@ Definition encode_internal_node : Value.t -> Value.t -> M := when serialized. This function also accepts `None`, representing the absence of a node, - which is encoded to `b""""""`. + which is encoded to `b""""`. Parameters ---------- @@ -189,8 +223,10 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := - Constant.bytes "" in + let _ := M.assign_local (| + "unencoded" , + Constant.bytes "" + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -207,7 +243,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := + let _ := M.assign_local (| + "unencoded" , make_tuple [ M.call (| M.get_name (| globals, "nibble_list_to_compact" |), make_list [ @@ -215,7 +252,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := Constant.bool true ], make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in + |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -232,7 +270,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := + let _ := M.assign_local (| + "unencoded" , make_tuple [ M.call (| M.get_name (| globals, "nibble_list_to_compact" |), make_list [ @@ -240,7 +279,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := Constant.bool false ], make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in + |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -257,13 +297,15 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := + let _ := M.assign_local (| + "unencoded" , BinOp.add (| M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), make_list [ M.get_field (| M.get_name (| globals, "node" |), "value" |) ] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -282,14 +324,16 @@ Definition encode_internal_node : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - let encoded := + let _ := M.assign_local (| + "encoded" , M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), make_list [ M.get_name (| globals, "unencoded" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -681,12 +725,14 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := compressed : `bytearray` Compact byte array. " in - let compact := + let _ := M.assign_local (| + "compact" , M.call (| M.get_name (| globals, "bytearray" |), make_list [], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -866,7 +912,8 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := nibble_list : `Bytes` The `Bytes` in nibble-list format. " in - let nibble_list := + let _ := M.assign_local (| + "nibble_list" , M.call (| M.get_name (| globals, "bytearray" |), make_list [ @@ -882,7 +929,8 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ], @@ -990,15 +1038,18 @@ Definition _prepare_trie : Value.t -> Value.t -> M := M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "Address" |), make_list [ M.get_name (| globals, "preimage" |) ], make_dict [] - |) in - let encoded_value := + |) + |) in + let _ := M.assign_local (| + "encoded_value" , M.call (| M.get_name (| globals, "encode_node" |), make_list [ @@ -1012,18 +1063,21 @@ Definition _prepare_trie : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let encoded_value := + let _ := M.assign_local (| + "encoded_value" , M.call (| M.get_name (| globals, "encode_node" |), make_list [ M.get_name (| globals, "value" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -1044,19 +1098,23 @@ Definition _prepare_trie : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "trie" |), "secured" |), (* then *) ltac:(M.monadic ( - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "preimage" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let key := - M.get_name (| globals, "preimage" |) in + let _ := M.assign_local (| + "key" , + M.get_name (| globals, "preimage" |) + |) in M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -1103,7 +1161,8 @@ Definition root : Value.t -> Value.t -> M := root : `.fork_types.Root` MPT root of the underlying key-value pairs. " in - let obj := + let _ := M.assign_local (| + "obj" , M.call (| M.get_name (| globals, "_prepare_trie" |), make_list [ @@ -1111,8 +1170,10 @@ Definition root : Value.t -> Value.t -> M := M.get_name (| globals, "get_storage_root" |) ], make_dict [] - |) in - let root_node := + |) + |) in + let _ := M.assign_local (| + "root_node" , M.call (| M.get_name (| globals, "encode_internal_node" |), make_list [ @@ -1132,7 +1193,8 @@ Definition root : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1237,7 +1299,8 @@ Definition patricialize : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let arbitrary_key := + let _ := M.assign_local (| + "arbitrary_key" , M.call (| M.get_name (| globals, "next" |), make_list [ @@ -1250,7 +1313,8 @@ Definition patricialize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1266,7 +1330,8 @@ Definition patricialize : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let leaf := + let _ := M.assign_local (| + "leaf" , M.call (| M.get_name (| globals, "LeafNode" |), make_list [ @@ -1282,7 +1347,8 @@ Definition patricialize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "leaf" |) |) in @@ -1291,27 +1357,32 @@ Definition patricialize : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let substring := + let _ := M.assign_local (| + "substring" , M.slice (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |), Constant.None_, Constant.None_ - |) in - let prefix_length := + |) + |) in + let _ := M.assign_local (| + "prefix_length" , M.call (| M.get_name (| globals, "len" |), make_list [ M.get_name (| globals, "substring" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "key" |), M.get_name (| globals, "obj" |), ltac:(M.monadic ( - let prefix_length := + let _ := M.assign_local (| + "prefix_length" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -1331,7 +1402,8 @@ Definition patricialize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1362,7 +1434,8 @@ Definition patricialize : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let prefix := + let _ := M.assign_local (| + "prefix" , M.slice (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |), @@ -1371,7 +1444,8 @@ Definition patricialize : Value.t -> Value.t -> M := M.get_name (| globals, "prefix_length" |) |), Constant.None_ - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ExtensionNode" |), @@ -1418,7 +1492,7 @@ Definition patricialize : Value.t -> Value.t -> M := let _ := M.call (| M.get_field (| M.get_name (| globals, "branches" |), "append" |), make_list [ - {} + Constant.str "(* At expr: unsupported node type: Dict *)" ], make_dict [] |) in @@ -1428,8 +1502,10 @@ Definition patricialize : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let value := - Constant.bytes "" in + let _ := M.assign_local (| + "value" , + Constant.bytes "" + |) in let _ := M.for_ (| M.get_name (| globals, "key" |), @@ -1472,11 +1548,13 @@ Definition patricialize : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let value := + let _ := M.assign_local (| + "value" , M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/arrow_glacier/utils/address.v b/CoqOfPython/ethereum/arrow_glacier/utils/address.v index 8f6b436..34dfc3f 100644 --- a/CoqOfPython/ethereum/arrow_glacier/utils/address.v +++ b/CoqOfPython/ethereum/arrow_glacier/utils/address.v @@ -18,23 +18,27 @@ Address specific functions used in this arrow_glacier version of specification. ". -Axiom typing_imports : - AreImported globals "typing" [ "Union" ]. +Axiom typing_imports_Union : + IsImported globals "typing" "Union". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes32"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_left_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "left_pad_zero_bytes". -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". -Axiom ethereum_arrow_glacier_fork_types_imports : - AreImported globals "ethereum.arrow_glacier.fork_types" [ "Address" ]. +Axiom ethereum_arrow_glacier_fork_types_imports_Address : + IsImported globals "ethereum.arrow_glacier.fork_types" "Address". Definition to_address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -91,7 +95,8 @@ Definition compute_contract_address : Value.t -> Value.t -> M := address: `Address` The computed address of the new account. " in - let computed_address := + let _ := M.assign_local (| + "computed_address" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -107,15 +112,19 @@ Definition compute_contract_address : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let canonical_address := + |) + |) in + let _ := M.assign_local (| + "canonical_address" , M.slice (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |), Constant.None_, Constant.None_ - |) in - let padded_address := + |) + |) in + let _ := M.assign_local (| + "padded_address" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -123,7 +132,8 @@ Definition compute_contract_address : Value.t -> Value.t -> M := Constant.int 20 ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Address" |), @@ -156,7 +166,8 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := address: `ethereum.arrow_glacier.fork_types.Address` The computed address of the new account. " in - let preimage := + let _ := M.assign_local (| + "preimage" , BinOp.add (| BinOp.add (| BinOp.add (| @@ -172,23 +183,29 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in - let computed_address := + |) + |) in + let _ := M.assign_local (| + "computed_address" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "preimage" |) ], make_dict [] - |) in - let canonical_address := + |) + |) in + let _ := M.assign_local (| + "canonical_address" , M.slice (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |), Constant.None_, Constant.None_ - |) in - let padded_address := + |) + |) in + let _ := M.assign_local (| + "padded_address" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -196,7 +213,8 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := Constant.int 20 ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Address" |), diff --git a/CoqOfPython/ethereum/arrow_glacier/utils/hexadecimal.v b/CoqOfPython/ethereum/arrow_glacier/utils/hexadecimal.v index d87dde9..7d39659 100644 --- a/CoqOfPython/ethereum/arrow_glacier/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/arrow_glacier/utils/hexadecimal.v @@ -18,11 +18,15 @@ Hexadecimal utility functions used in this specification, specific to Arrow Glacier types. ". -Axiom ethereum_utils_hexadecimal_imports : - AreImported globals "ethereum.utils.hexadecimal" [ "remove_hex_prefix" ]. - -Axiom ethereum_arrow_glacier_fork_types_imports : - AreImported globals "ethereum.arrow_glacier.fork_types" [ "Address"; "Bloom"; "Root" ]. +Axiom ethereum_utils_hexadecimal_imports_remove_hex_prefix : + IsImported globals "ethereum.utils.hexadecimal" "remove_hex_prefix". + +Axiom ethereum_arrow_glacier_fork_types_imports_Address : + IsImported globals "ethereum.arrow_glacier.fork_types" "Address". +Axiom ethereum_arrow_glacier_fork_types_imports_Bloom : + IsImported globals "ethereum.arrow_glacier.fork_types" "Bloom". +Axiom ethereum_arrow_glacier_fork_types_imports_Root : + IsImported globals "ethereum.arrow_glacier.fork_types" "Root". Definition hex_to_root : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/arrow_glacier/utils/message.v b/CoqOfPython/ethereum/arrow_glacier/utils/message.v index 2b5423f..c8a6555 100644 --- a/CoqOfPython/ethereum/arrow_glacier/utils/message.v +++ b/CoqOfPython/ethereum/arrow_glacier/utils/message.v @@ -18,26 +18,42 @@ Message specific functions used in this arrow_glacier version of specification. ". -Axiom typing_imports : - AreImported globals "typing" [ "FrozenSet"; "Optional"; "Tuple"; "Union" ]. +Axiom typing_imports_FrozenSet : + IsImported globals "typing" "FrozenSet". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Bytes32"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_arrow_glacier_fork_types_imports : - AreImported globals "ethereum.arrow_glacier.fork_types" [ "Address" ]. +Axiom ethereum_arrow_glacier_fork_types_imports_Address : + IsImported globals "ethereum.arrow_glacier.fork_types" "Address". -Axiom ethereum_arrow_glacier_state_imports : - AreImported globals "ethereum.arrow_glacier.state" [ "get_account" ]. +Axiom ethereum_arrow_glacier_state_imports_get_account : + IsImported globals "ethereum.arrow_glacier.state" "get_account". -Axiom ethereum_arrow_glacier_vm_imports : - AreImported globals "ethereum.arrow_glacier.vm" [ "Environment"; "Message" ]. +Axiom ethereum_arrow_glacier_vm_imports_Environment : + IsImported globals "ethereum.arrow_glacier.vm" "Environment". +Axiom ethereum_arrow_glacier_vm_imports_Message : + IsImported globals "ethereum.arrow_glacier.vm" "Message". -Axiom ethereum_arrow_glacier_vm_precompiled_contracts_mapping_imports : - AreImported globals "ethereum.arrow_glacier.vm.precompiled_contracts.mapping" [ "PRE_COMPILED_CONTRACTS" ]. +Axiom ethereum_arrow_glacier_vm_precompiled_contracts_mapping_imports_PRE_COMPILED_CONTRACTS : + IsImported globals "ethereum.arrow_glacier.vm.precompiled_contracts.mapping" "PRE_COMPILED_CONTRACTS". -Axiom ethereum_arrow_glacier_utils_address_imports : - AreImported globals "ethereum.arrow_glacier.utils.address" [ "compute_contract_address" ]. +Axiom ethereum_arrow_glacier_utils_address_imports_compute_contract_address : + IsImported globals "ethereum.arrow_glacier.utils.address" "compute_contract_address". Definition prepare_message : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -92,7 +108,8 @@ Definition prepare_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let current_target := + let _ := M.assign_local (| + "current_target" , M.call (| M.get_name (| globals, "compute_contract_address" |), make_list [ @@ -116,17 +133,22 @@ Definition prepare_message : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let msg_data := + |) + |) in + let _ := M.assign_local (| + "msg_data" , M.call (| M.get_name (| globals, "Bytes" |), make_list [ Constant.bytes "" ], make_dict [] - |) in - let code := - M.get_name (| globals, "data" |) in + |) + |) in + let _ := M.assign_local (| + "code" , + M.get_name (| globals, "data" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -143,11 +165,16 @@ Definition prepare_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let current_target := - M.get_name (| globals, "target" |) in - let msg_data := - M.get_name (| globals, "data" |) in - let code := + let _ := M.assign_local (| + "current_target" , + M.get_name (| globals, "target" |) + |) in + let _ := M.assign_local (| + "msg_data" , + M.get_name (| globals, "data" |) + |) in + let _ := M.assign_local (| + "code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -155,7 +182,8 @@ Definition prepare_message : Value.t -> Value.t -> M := M.get_name (| globals, "target" |) ], make_dict [] - |), "code" |) in + |), "code" |) + |) in let _ := (* if *) M.if_then_else (| @@ -165,8 +193,10 @@ Definition prepare_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let code_address := - M.get_name (| globals, "target" |) in + let _ := M.assign_local (| + "code_address" , + M.get_name (| globals, "target" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -186,12 +216,14 @@ Definition prepare_message : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - let accessed_addresses := + let _ := M.assign_local (| + "accessed_addresses" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "accessed_addresses" |), "add" |), make_list [ diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/__init__.v b/CoqOfPython/ethereum/arrow_glacier/vm/__init__.v index c0cf9bf..19418af 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/__init__.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/__init__.v @@ -18,29 +18,49 @@ The abstract computer which runs the code stored in an `.fork_types.Account`. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple"; "Union" ]. +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U64"; "U256"; "Bytes"; "Bytes0"; "Bytes32"; "Uint" ]. +Axiom ethereum_base_types_imports_U64 : + IsImported globals "ethereum.base_types" "U64". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". -Axiom ethereum_arrow_glacier_blocks_imports : - AreImported globals "ethereum.arrow_glacier.blocks" [ "Log" ]. +Axiom ethereum_arrow_glacier_blocks_imports_Log : + IsImported globals "ethereum.arrow_glacier.blocks" "Log". -Axiom ethereum_arrow_glacier_fork_types_imports : - AreImported globals "ethereum.arrow_glacier.fork_types" [ "Address" ]. +Axiom ethereum_arrow_glacier_fork_types_imports_Address : + IsImported globals "ethereum.arrow_glacier.fork_types" "Address". -Axiom ethereum_arrow_glacier_state_imports : - AreImported globals "ethereum.arrow_glacier.state" [ "State"; "account_exists_and_is_empty" ]. +Axiom ethereum_arrow_glacier_state_imports_State : + IsImported globals "ethereum.arrow_glacier.state" "State". +Axiom ethereum_arrow_glacier_state_imports_account_exists_and_is_empty : + IsImported globals "ethereum.arrow_glacier.state" "account_exists_and_is_empty". -Axiom ethereum_arrow_glacier_vm_precompiled_contracts_imports : - AreImported globals "ethereum.arrow_glacier.vm.precompiled_contracts" [ "RIPEMD160_ADDRESS" ]. +Axiom ethereum_arrow_glacier_vm_precompiled_contracts_imports_RIPEMD160_ADDRESS : + IsImported globals "ethereum.arrow_glacier.vm.precompiled_contracts" "RIPEMD160_ADDRESS". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/exceptions.v b/CoqOfPython/ethereum/arrow_glacier/vm/exceptions.v index 4f9d6c0..c699641 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/exceptions.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/exceptions.v @@ -17,8 +17,8 @@ Introduction Exceptions which cause the EVM to halt exceptionally. ". -Axiom ethereum_exceptions_imports : - AreImported globals "ethereum.exceptions" [ "EthereumException" ]. +Axiom ethereum_exceptions_imports_EthereumException : + IsImported globals "ethereum.exceptions" "EthereumException". Definition ExceptionalHalt : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/gas.v b/CoqOfPython/ethereum/arrow_glacier/vm/gas.v index 2dbc7ef..ca2cac0 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/gas.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/gas.v @@ -17,26 +17,32 @@ Introduction EVM gas constants and calculators. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Tuple" ]. +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_trace_imports : - AreImported globals "ethereum.trace" [ "GasAndRefund"; "evm_trace" ]. +Axiom ethereum_trace_imports_GasAndRefund : + IsImported globals "ethereum.trace" "GasAndRefund". +Axiom ethereum_trace_imports_evm_trace : + IsImported globals "ethereum.trace" "evm_trace". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_arrow_glacier_vm_imports : - AreImported globals "ethereum.arrow_glacier.vm" [ "Evm" ]. +Axiom ethereum_arrow_glacier_vm_imports_Evm : + IsImported globals "ethereum.arrow_glacier.vm" "Evm". -Axiom ethereum_arrow_glacier_vm_exceptions_imports : - AreImported globals "ethereum.arrow_glacier.vm.exceptions" [ "OutOfGasError" ]. +Axiom ethereum_arrow_glacier_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.arrow_glacier.vm.exceptions" "OutOfGasError". Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -532,7 +538,8 @@ Definition calculate_memory_gas_cost : Value.t -> Value.t -> M := total_gas_cost : `ethereum.base_types.Uint` The gas cost for storing data in memory. " in - let size_in_words := + let _ := M.assign_local (| + "size_in_words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -542,25 +549,32 @@ Definition calculate_memory_gas_cost : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let linear_cost := + |) + |) in + let _ := M.assign_local (| + "linear_cost" , BinOp.mult (| M.get_name (| globals, "size_in_words" |), M.get_name (| globals, "GAS_MEMORY" |) - |) in - let quadratic_cost := + |) + |) in + let _ := M.assign_local (| + "quadratic_cost" , BinOp.floor_div (| BinOp.pow (| M.get_name (| globals, "size_in_words" |), Constant.int 2 |), Constant.int 512 - |) in - let total_gas_cost := + |) + |) in + let _ := M.assign_local (| + "total_gas_cost" , BinOp.add (| M.get_name (| globals, "linear_cost" |), M.get_name (| globals, "quadratic_cost" |) - |) in + |) + |) in (* At stmt: unsupported node type: Try *) M.pure Constant.None_)). @@ -582,23 +596,28 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := ------- extend_memory: `ExtendMemory` " in - let size_to_extend := + let _ := M.assign_local (| + "size_to_extend" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in - let to_be_paid := + |) + |) in + let _ := M.assign_local (| + "to_be_paid" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in - let current_size := + |) + |) in + let _ := M.assign_local (| + "current_size" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -611,7 +630,8 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ], @@ -632,15 +652,18 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let before_size := + let _ := M.assign_local (| + "before_size" , M.call (| M.get_name (| globals, "ceil32" |), make_list [ M.get_name (| globals, "current_size" |) ], make_dict [] - |) in - let after_size := + |) + |) in + let _ := M.assign_local (| + "after_size" , M.call (| M.get_name (| globals, "ceil32" |), make_list [ @@ -662,7 +685,8 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -678,42 +702,46 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let size_to_extend := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "size_to_extend", BinOp.sub (| M.get_name (| globals, "after_size" |), M.get_name (| globals, "before_size" |) |) - BinOp.sub (| - M.get_name (| globals, "after_size" |), - M.get_name (| globals, "before_size" |) - |) in - let already_paid := + |) in + let _ := M.assign_local (| + "already_paid" , M.call (| M.get_name (| globals, "calculate_memory_gas_cost" |), make_list [ M.get_name (| globals, "before_size" |) ], make_dict [] - |) in - let total_cost := + |) + |) in + let _ := M.assign_local (| + "total_cost" , M.call (| M.get_name (| globals, "calculate_memory_gas_cost" |), make_list [ M.get_name (| globals, "after_size" |) ], make_dict [] - |) in - let to_be_paid := BinOp.add + |) + |) in + let _ := M.assign_op_local (| + BinOp.add, + "to_be_paid", BinOp.sub (| M.get_name (| globals, "total_cost" |), M.get_name (| globals, "already_paid" |) |) - BinOp.sub (| - M.get_name (| globals, "total_cost" |), - M.get_name (| globals, "already_paid" |) - |) in - let current_size := - M.get_name (| globals, "after_size" |) in + |) in + let _ := M.assign_local (| + "current_size" , + M.get_name (| globals, "after_size" |) + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -760,7 +788,8 @@ Definition calculate_message_call_gas : Value.t -> Value.t -> M := ------- message_call_gas: `MessageCallGas` " in - let call_stipend := + let _ := M.assign_local (| + "call_stipend" , (* if *) M.if_then_else (| Compare.eq (| @@ -779,7 +808,8 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "call_stipend" |) - )) |) in + )) |) + |) in let _ := (* if *) M.if_then_else (| @@ -813,7 +843,8 @@ M.get_name (| globals, "call_stipend" |) )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -833,7 +864,8 @@ M.get_name (| globals, "call_stipend" |) |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "MessageCallGas" |), diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/__init__.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/__init__.v index 40358e1..2163ec5 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/__init__.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/__init__.v @@ -20,44 +20,46 @@ implementations. (* At top_level_stmt: unsupported node type: Import *) -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict" ]. +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". -Axiom ethereum_arrow_glacier_vm_instructions_imports : - AreImported globals "ethereum.arrow_glacier.vm.instructions" [ "arithmetic" ]. +Axiom ethereum_arrow_glacier_vm_instructions_imports_arithmetic : + IsImported globals "ethereum.arrow_glacier.vm.instructions" "arithmetic". -Axiom ethereum_arrow_glacier_vm_instructions_imports : - AreImported globals "ethereum.arrow_glacier.vm.instructions" [ "bitwise" ]. +Axiom ethereum_arrow_glacier_vm_instructions_imports_bitwise : + IsImported globals "ethereum.arrow_glacier.vm.instructions" "bitwise". -Axiom ethereum_arrow_glacier_vm_instructions_imports : - AreImported globals "ethereum.arrow_glacier.vm.instructions" [ "block" ]. +Axiom ethereum_arrow_glacier_vm_instructions_imports_block : + IsImported globals "ethereum.arrow_glacier.vm.instructions" "block". -Axiom ethereum_arrow_glacier_vm_instructions_imports : - AreImported globals "ethereum.arrow_glacier.vm.instructions" [ "comparison" ]. +Axiom ethereum_arrow_glacier_vm_instructions_imports_comparison : + IsImported globals "ethereum.arrow_glacier.vm.instructions" "comparison". -Axiom ethereum_arrow_glacier_vm_instructions_imports : - AreImported globals "ethereum.arrow_glacier.vm.instructions" [ "control_flow" ]. +Axiom ethereum_arrow_glacier_vm_instructions_imports_control_flow : + IsImported globals "ethereum.arrow_glacier.vm.instructions" "control_flow". -Axiom ethereum_arrow_glacier_vm_instructions_imports : - AreImported globals "ethereum.arrow_glacier.vm.instructions" [ "environment" ]. +Axiom ethereum_arrow_glacier_vm_instructions_imports_environment : + IsImported globals "ethereum.arrow_glacier.vm.instructions" "environment". -Axiom ethereum_arrow_glacier_vm_instructions_imports : - AreImported globals "ethereum.arrow_glacier.vm.instructions" [ "keccak" ]. +Axiom ethereum_arrow_glacier_vm_instructions_imports_keccak : + IsImported globals "ethereum.arrow_glacier.vm.instructions" "keccak". -Axiom ethereum_arrow_glacier_vm_instructions_imports : - AreImported globals "ethereum.arrow_glacier.vm.instructions" [ "log" ]. +Axiom ethereum_arrow_glacier_vm_instructions_imports_log : + IsImported globals "ethereum.arrow_glacier.vm.instructions" "log". -Axiom ethereum_arrow_glacier_vm_instructions_imports : - AreImported globals "ethereum.arrow_glacier.vm.instructions" [ "memory" ]. +Axiom ethereum_arrow_glacier_vm_instructions_imports_memory : + IsImported globals "ethereum.arrow_glacier.vm.instructions" "memory". -Axiom ethereum_arrow_glacier_vm_instructions_imports : - AreImported globals "ethereum.arrow_glacier.vm.instructions" [ "stack" ]. +Axiom ethereum_arrow_glacier_vm_instructions_imports_stack : + IsImported globals "ethereum.arrow_glacier.vm.instructions" "stack". -Axiom ethereum_arrow_glacier_vm_instructions_imports : - AreImported globals "ethereum.arrow_glacier.vm.instructions" [ "storage" ]. +Axiom ethereum_arrow_glacier_vm_instructions_imports_storage : + IsImported globals "ethereum.arrow_glacier.vm.instructions" "storage". -Axiom ethereum_arrow_glacier_vm_instructions_imports : - AreImported globals "ethereum.arrow_glacier.vm.instructions" [ "system" ]. +Axiom ethereum_arrow_glacier_vm_instructions_imports_system : + IsImported globals "ethereum.arrow_glacier.vm.instructions" "system". Definition Ops : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/arithmetic.v index 6a7fa74..9c026ce 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/arithmetic.v @@ -17,20 +17,38 @@ Introduction Implementations of the EVM Arithmetic instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U255_CEIL_VALUE"; "U256"; "U256_CEIL_VALUE"; "Uint" ]. +Axiom ethereum_base_types_imports_U255_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U255_CEIL_VALUE". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_U256_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U256_CEIL_VALUE". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "get_sign" ]. +Axiom ethereum_utils_numeric_imports_get_sign : + IsImported globals "ethereum.utils.numeric" "get_sign". -Axiom ethereum_arrow_glacier_vm_imports : - AreImported globals "ethereum.arrow_glacier.vm" [ "Evm" ]. +Axiom ethereum_arrow_glacier_vm_imports_Evm : + IsImported globals "ethereum.arrow_glacier.vm" "Evm". -Axiom ethereum_arrow_glacier_vm_gas_imports : - AreImported globals "ethereum.arrow_glacier.vm.gas" [ "GAS_EXPONENTIATION"; "GAS_EXPONENTIATION_PER_BYTE"; "GAS_LOW"; "GAS_MID"; "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_EXPONENTIATION : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_EXPONENTIATION". +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_EXPONENTIATION_PER_BYTE : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_EXPONENTIATION_PER_BYTE". +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_LOW : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_LOW". +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_MID : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_MID". +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_arrow_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.arrow_glacier.vm.gas" "charge_gas". -Axiom ethereum_arrow_glacier_vm_stack_imports : - AreImported globals "ethereum.arrow_glacier.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_arrow_glacier_vm_stack_imports_pop : + IsImported globals "ethereum.arrow_glacier.vm.stack" "pop". +Axiom ethereum_arrow_glacier_vm_stack_imports_push : + IsImported globals "ethereum.arrow_glacier.vm.stack" "push". Definition add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,22 +63,26 @@ Definition add : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -69,14 +91,16 @@ Definition add : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "x" |), "wrapping_add" |), make_list [ M.get_name (| globals, "y" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -105,22 +129,26 @@ Definition sub : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -129,14 +157,16 @@ Definition sub : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "x" |), "wrapping_sub" |), make_list [ M.get_name (| globals, "y" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -165,22 +195,26 @@ Definition mul : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -189,14 +223,16 @@ Definition mul : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "x" |), "wrapping_mul" |), make_list [ M.get_name (| globals, "y" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -225,22 +261,26 @@ Definition div : Value.t -> Value.t -> M := The current EVM frame. " in - let dividend := + let _ := M.assign_local (| + "dividend" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let divisor := + |) + |) in + let _ := M.assign_local (| + "divisor" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -258,22 +298,26 @@ Definition div : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let quotient := + let _ := M.assign_local (| + "quotient" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let quotient := + let _ := M.assign_local (| + "quotient" , BinOp.floor_div (| M.get_name (| globals, "dividend" |), M.get_name (| globals, "divisor" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -304,7 +348,8 @@ Definition sdiv : Value.t -> Value.t -> M := The current EVM frame. " in - let dividend := + let _ := M.assign_local (| + "dividend" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -315,8 +360,10 @@ Definition sdiv : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let divisor := + |) + |) in + let _ := M.assign_local (| + "divisor" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -327,7 +374,8 @@ Definition sdiv : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -345,8 +393,10 @@ Definition sdiv : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let quotient := - Constant.int 0 in + let _ := M.assign_local (| + "quotient" , + Constant.int 0 + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -367,12 +417,15 @@ Definition sdiv : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let quotient := - UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in + let _ := M.assign_local (| + "quotient" , + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let sign := + let _ := M.assign_local (| + "sign" , M.call (| M.get_name (| globals, "get_sign" |), make_list [ @@ -382,8 +435,10 @@ Definition sdiv : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let quotient := + |) + |) in + let _ := M.assign_local (| + "quotient" , BinOp.mult (| M.get_name (| globals, "sign" |), BinOp.floor_div (| @@ -402,7 +457,8 @@ Definition sdiv : Value.t -> Value.t -> M := make_dict [] |) |) - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -428,7 +484,7 @@ Definition sdiv : Value.t -> Value.t -> M := |) in M.pure Constant.None_)). -Definition mod : Value.t -> Value.t -> M := +Definition mod_ : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in let _ := Constant.str " @@ -441,22 +497,26 @@ Definition mod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -474,22 +534,26 @@ Definition mod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let remainder := + let _ := M.assign_local (| + "remainder" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let remainder := + let _ := M.assign_local (| + "remainder" , BinOp.mod_ (| M.get_name (| globals, "x" |), M.get_name (| globals, "y" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -520,7 +584,8 @@ Definition smod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -531,8 +596,10 @@ Definition smod : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -543,7 +610,8 @@ Definition smod : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -561,12 +629,15 @@ Definition smod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let remainder := - Constant.int 0 in + let _ := M.assign_local (| + "remainder" , + Constant.int 0 + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let remainder := + let _ := M.assign_local (| + "remainder" , BinOp.mult (| M.call (| M.get_name (| globals, "get_sign" |), @@ -591,7 +662,8 @@ Definition smod : Value.t -> Value.t -> M := make_dict [] |) |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -628,7 +700,8 @@ Definition addmod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -641,8 +714,10 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -655,8 +730,10 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let z := + |) + |) in + let _ := M.assign_local (| + "z" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -669,7 +746,8 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -687,18 +765,21 @@ Definition addmod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -711,7 +792,8 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -742,7 +824,8 @@ Definition mulmod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -755,8 +838,10 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -769,8 +854,10 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let z := + |) + |) in + let _ := M.assign_local (| + "z" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -783,7 +870,8 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -801,18 +889,21 @@ Definition mulmod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -825,7 +916,8 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -856,7 +948,8 @@ Definition exp : Value.t -> Value.t -> M := The current EVM frame. " in - let base := + let _ := M.assign_local (| + "base" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -869,8 +962,10 @@ Definition exp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exponent := + |) + |) in + let _ := M.assign_local (| + "exponent" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -883,21 +978,26 @@ Definition exp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exponent_bits := + |) + |) in + let _ := M.assign_local (| + "exponent_bits" , M.call (| M.get_field (| M.get_name (| globals, "exponent" |), "bit_length" |), make_list [], make_dict [] - |) in - let exponent_bytes := + |) + |) in + let _ := M.assign_local (| + "exponent_bytes" , BinOp.floor_div (| BinOp.add (| M.get_name (| globals, "exponent_bits" |), Constant.int 7 |), Constant.int 8 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -912,7 +1012,8 @@ Definition exp : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -927,7 +1028,8 @@ Definition exp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -956,22 +1058,26 @@ Definition signextend : Value.t -> Value.t -> M := The current EVM frame. " in - let byte_num := + let _ := M.assign_local (| + "byte_num" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -989,12 +1095,15 @@ Definition signextend : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := - M.get_name (| globals, "value" |) in + let _ := M.assign_local (| + "result" , + M.get_name (| globals, "value" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let value_bytes := + let _ := M.assign_local (| + "value_bytes" , M.call (| M.get_name (| globals, "bytes" |), make_list [ @@ -1005,8 +1114,10 @@ Definition signextend : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let value_bytes := + |) + |) in + let _ := M.assign_local (| + "value_bytes" , M.slice (| M.get_name (| globals, "value_bytes" |), BinOp.sub (| @@ -1021,15 +1132,18 @@ Definition signextend : Value.t -> Value.t -> M := |), Constant.None_, Constant.None_ - |) in - let sign_bit := + |) + |) in + let _ := M.assign_local (| + "sign_bit" , BinOp.r_shift (| M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), Constant.int 7 - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1039,26 +1153,31 @@ Definition signextend : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "value_bytes" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let num_bytes_prepend := + let _ := M.assign_local (| + "num_bytes_prepend" , BinOp.sub (| Constant.int 32, BinOp.add (| M.get_name (| globals, "byte_num" |), Constant.int 1 |) - |) in - let result := + |) + |) in + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -1079,7 +1198,8 @@ Definition signextend : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/bitwise.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/bitwise.v index 74b4347..db4eddd 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/bitwise.v @@ -17,17 +17,23 @@ Introduction Implementations of the EVM bitwise instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "U256_CEIL_VALUE" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_U256_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U256_CEIL_VALUE". -Axiom ethereum_arrow_glacier_vm_imports : - AreImported globals "ethereum.arrow_glacier.vm" [ "Evm" ]. +Axiom ethereum_arrow_glacier_vm_imports_Evm : + IsImported globals "ethereum.arrow_glacier.vm" "Evm". -Axiom ethereum_arrow_glacier_vm_gas_imports : - AreImported globals "ethereum.arrow_glacier.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_arrow_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.arrow_glacier.vm.gas" "charge_gas". -Axiom ethereum_arrow_glacier_vm_stack_imports : - AreImported globals "ethereum.arrow_glacier.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_arrow_glacier_vm_stack_imports_pop : + IsImported globals "ethereum.arrow_glacier.vm.stack" "pop". +Axiom ethereum_arrow_glacier_vm_stack_imports_push : + IsImported globals "ethereum.arrow_glacier.vm.stack" "push". Definition bitwise_and : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,22 +48,26 @@ Definition bitwise_and : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -97,22 +107,26 @@ Definition bitwise_or : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -152,22 +166,26 @@ Definition bitwise_xor : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -207,14 +225,16 @@ Definition bitwise_not : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -252,22 +272,26 @@ Definition get_byte : Value.t -> Value.t -> M := The current EVM frame. " in - let byte_index := + let _ := M.assign_local (| + "byte_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let word := + |) + |) in + let _ := M.assign_local (| + "word" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -285,43 +309,53 @@ Definition get_byte : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let extra_bytes_to_right := + let _ := M.assign_local (| + "extra_bytes_to_right" , BinOp.sub (| Constant.int 31, M.get_name (| globals, "byte_index" |) - |) in - let word := + |) + |) in + let _ := M.assign_local (| + "word" , BinOp.r_shift (| M.get_name (| globals, "word" |), BinOp.mult (| M.get_name (| globals, "extra_bytes_to_right" |), Constant.int 8 |) - |) in - let word := + |) + |) in + let _ := M.assign_local (| + "word" , BinOp.bit_and (| M.get_name (| globals, "word" |), Constant.int 255 - |) in - let result := + |) + |) in + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ M.get_name (| globals, "word" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -350,22 +384,26 @@ Definition bitwise_shl : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let shift := + let _ := M.assign_local (| + "shift" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -383,7 +421,8 @@ Definition bitwise_shl : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -396,18 +435,21 @@ Definition bitwise_shl : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -436,22 +478,26 @@ Definition bitwise_shr : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let shift := + let _ := M.assign_local (| + "shift" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -469,22 +515,26 @@ Definition bitwise_shr : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , BinOp.r_shift (| M.get_name (| globals, "value" |), M.get_name (| globals, "shift" |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -513,15 +563,18 @@ Definition bitwise_sar : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let shift := + let _ := M.assign_local (| + "shift" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let signed_value := + |) + |) in + let _ := M.assign_local (| + "signed_value" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -532,7 +585,8 @@ Definition bitwise_sar : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -550,7 +604,8 @@ Definition bitwise_sar : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), make_list [ @@ -560,7 +615,8 @@ Definition bitwise_sar : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -573,19 +629,23 @@ Definition bitwise_sar : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := - M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) in + let _ := M.assign_local (| + "result" , + M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/block.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/block.v index f8e1a78..b5df822 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/block.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/block.v @@ -17,17 +17,23 @@ Introduction Implementations of the EVM block instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_arrow_glacier_vm_imports : - AreImported globals "ethereum.arrow_glacier.vm" [ "Evm" ]. +Axiom ethereum_arrow_glacier_vm_imports_Evm : + IsImported globals "ethereum.arrow_glacier.vm" "Evm". -Axiom ethereum_arrow_glacier_vm_gas_imports : - AreImported globals "ethereum.arrow_glacier.vm.gas" [ "GAS_BASE"; "GAS_BLOCK_HASH"; "charge_gas" ]. +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_BASE". +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_BLOCK_HASH : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_BLOCK_HASH". +Axiom ethereum_arrow_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.arrow_glacier.vm.gas" "charge_gas". -Axiom ethereum_arrow_glacier_vm_stack_imports : - AreImported globals "ethereum.arrow_glacier.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_arrow_glacier_vm_stack_imports_pop : + IsImported globals "ethereum.arrow_glacier.vm.stack" "pop". +Axiom ethereum_arrow_glacier_vm_stack_imports_push : + IsImported globals "ethereum.arrow_glacier.vm.stack" "push". Definition block_hash : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,14 +48,16 @@ Definition block_hash : Value.t -> Value.t -> M := The current EVM frame. " in - let block_number := + let _ := M.assign_local (| + "block_number" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -78,19 +86,23 @@ Definition block_hash : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let hash := - Constant.bytes "00" in + let _ := M.assign_local (| + "hash" , + Constant.bytes "00" + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let hash := + let _ := M.assign_local (| + "hash" , M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), M.get_name (| globals, "block_number" |) |) |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/comparison.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/comparison.v index 889bbc1..a48a324 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/comparison.v @@ -17,17 +17,21 @@ Introduction Implementations of the EVM Comparison instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_arrow_glacier_vm_imports : - AreImported globals "ethereum.arrow_glacier.vm" [ "Evm" ]. +Axiom ethereum_arrow_glacier_vm_imports_Evm : + IsImported globals "ethereum.arrow_glacier.vm" "Evm". -Axiom ethereum_arrow_glacier_vm_gas_imports : - AreImported globals "ethereum.arrow_glacier.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_arrow_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.arrow_glacier.vm.gas" "charge_gas". -Axiom ethereum_arrow_glacier_vm_stack_imports : - AreImported globals "ethereum.arrow_glacier.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_arrow_glacier_vm_stack_imports_pop : + IsImported globals "ethereum.arrow_glacier.vm.stack" "pop". +Axiom ethereum_arrow_glacier_vm_stack_imports_push : + IsImported globals "ethereum.arrow_glacier.vm.stack" "push". Definition less_than : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,22 +46,26 @@ Definition less_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -66,7 +74,8 @@ Definition less_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -76,7 +85,8 @@ Definition less_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -104,7 +114,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -115,8 +126,10 @@ Definition signed_less_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -127,7 +140,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -136,7 +150,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -146,7 +161,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -175,22 +191,26 @@ Definition greater_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -199,7 +219,8 @@ Definition greater_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -209,7 +230,8 @@ Definition greater_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -237,7 +259,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -248,8 +271,10 @@ Definition signed_greater_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -260,7 +285,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -269,7 +295,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -279,7 +306,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -308,22 +336,26 @@ Definition equal : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -332,7 +364,8 @@ Definition equal : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -342,7 +375,8 @@ Definition equal : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -371,14 +405,16 @@ Definition is_zero : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -387,7 +423,8 @@ Definition is_zero : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -397,7 +434,8 @@ Definition is_zero : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/control_flow.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/control_flow.v index 836b022..ab3b78d 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/control_flow.v @@ -17,20 +17,32 @@ Introduction Implementations of the EVM control flow instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_arrow_glacier_vm_gas_imports : - AreImported globals "ethereum.arrow_glacier.vm.gas" [ "GAS_BASE"; "GAS_HIGH"; "GAS_JUMPDEST"; "GAS_MID"; "charge_gas" ]. +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_BASE". +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_HIGH : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_HIGH". +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_JUMPDEST : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_JUMPDEST". +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_MID : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_MID". +Axiom ethereum_arrow_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.arrow_glacier.vm.gas" "charge_gas". -Axiom ethereum_arrow_glacier_vm_imports : - AreImported globals "ethereum.arrow_glacier.vm" [ "Evm" ]. +Axiom ethereum_arrow_glacier_vm_imports_Evm : + IsImported globals "ethereum.arrow_glacier.vm" "Evm". -Axiom ethereum_arrow_glacier_vm_exceptions_imports : - AreImported globals "ethereum.arrow_glacier.vm.exceptions" [ "InvalidJumpDestError" ]. +Axiom ethereum_arrow_glacier_vm_exceptions_imports_InvalidJumpDestError : + IsImported globals "ethereum.arrow_glacier.vm.exceptions" "InvalidJumpDestError". -Axiom ethereum_arrow_glacier_vm_stack_imports : - AreImported globals "ethereum.arrow_glacier.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_arrow_glacier_vm_stack_imports_pop : + IsImported globals "ethereum.arrow_glacier.vm.stack" "pop". +Axiom ethereum_arrow_glacier_vm_stack_imports_push : + IsImported globals "ethereum.arrow_glacier.vm.stack" "push". Definition stop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -69,7 +81,8 @@ Definition jump : Value.t -> Value.t -> M := The current EVM frame. " in - let jump_dest := + let _ := M.assign_local (| + "jump_dest" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -82,7 +95,8 @@ Definition jump : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -132,7 +146,8 @@ Definition jumpi : Value.t -> Value.t -> M := The current EVM frame. " in - let jump_dest := + let _ := M.assign_local (| + "jump_dest" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -145,15 +160,18 @@ Definition jumpi : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let conditional_value := + |) + |) in + let _ := M.assign_local (| + "conditional_value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -171,11 +189,13 @@ Definition jumpi : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let destination := + let _ := M.assign_local (| + "destination" , BinOp.add (| M.get_field (| M.get_name (| globals, "evm" |), "pc" |), Constant.int 1 - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -192,8 +212,10 @@ Definition jumpi : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let destination := - M.get_name (| globals, "jump_dest" |) in + let _ := M.assign_local (| + "destination" , + M.get_name (| globals, "jump_dest" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/environment.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/environment.v index a537125..182c5e4 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/environment.v @@ -17,41 +17,63 @@ Introduction Implementations of the EVM environment related instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. - -Axiom ethereum_arrow_glacier_fork_types_imports : - AreImported globals "ethereum.arrow_glacier.fork_types" [ "EMPTY_ACCOUNT" ]. - -Axiom ethereum_arrow_glacier_state_imports : - AreImported globals "ethereum.arrow_glacier.state" [ "get_account" ]. - -Axiom ethereum_arrow_glacier_utils_address_imports : - AreImported globals "ethereum.arrow_glacier.utils.address" [ "to_address" ]. - -Axiom ethereum_arrow_glacier_vm_memory_imports : - AreImported globals "ethereum.arrow_glacier.vm.memory" [ "buffer_read"; "memory_write" ]. - -Axiom ethereum_arrow_glacier_vm_imports : - AreImported globals "ethereum.arrow_glacier.vm" [ "Evm" ]. - -Axiom ethereum_arrow_glacier_vm_exceptions_imports : - AreImported globals "ethereum.arrow_glacier.vm.exceptions" [ "OutOfBoundsRead" ]. - -Axiom ethereum_arrow_glacier_vm_gas_imports : - AreImported globals "ethereum.arrow_glacier.vm.gas" [ "GAS_BASE"; "GAS_COLD_ACCOUNT_ACCESS"; "GAS_COPY"; "GAS_FAST_STEP"; "GAS_RETURN_DATA_COPY"; "GAS_VERY_LOW"; "GAS_WARM_ACCESS"; "calculate_gas_extend_memory"; "charge_gas" ]. - -Axiom ethereum_arrow_glacier_vm_stack_imports : - AreImported globals "ethereum.arrow_glacier.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". + +Axiom ethereum_arrow_glacier_fork_types_imports_EMPTY_ACCOUNT : + IsImported globals "ethereum.arrow_glacier.fork_types" "EMPTY_ACCOUNT". + +Axiom ethereum_arrow_glacier_state_imports_get_account : + IsImported globals "ethereum.arrow_glacier.state" "get_account". + +Axiom ethereum_arrow_glacier_utils_address_imports_to_address : + IsImported globals "ethereum.arrow_glacier.utils.address" "to_address". + +Axiom ethereum_arrow_glacier_vm_memory_imports_buffer_read : + IsImported globals "ethereum.arrow_glacier.vm.memory" "buffer_read". +Axiom ethereum_arrow_glacier_vm_memory_imports_memory_write : + IsImported globals "ethereum.arrow_glacier.vm.memory" "memory_write". + +Axiom ethereum_arrow_glacier_vm_imports_Evm : + IsImported globals "ethereum.arrow_glacier.vm" "Evm". + +Axiom ethereum_arrow_glacier_vm_exceptions_imports_OutOfBoundsRead : + IsImported globals "ethereum.arrow_glacier.vm.exceptions" "OutOfBoundsRead". + +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_BASE". +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_COLD_ACCOUNT_ACCESS : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_COLD_ACCOUNT_ACCESS". +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_COPY : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_COPY". +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_FAST_STEP : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_FAST_STEP". +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_RETURN_DATA_COPY : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_RETURN_DATA_COPY". +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_WARM_ACCESS : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_WARM_ACCESS". +Axiom ethereum_arrow_glacier_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.arrow_glacier.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_arrow_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.arrow_glacier.vm.gas" "charge_gas". + +Axiom ethereum_arrow_glacier_vm_stack_imports_pop : + IsImported globals "ethereum.arrow_glacier.vm.stack" "pop". +Axiom ethereum_arrow_glacier_vm_stack_imports_push : + IsImported globals "ethereum.arrow_glacier.vm.stack" "push". Definition address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -107,7 +129,8 @@ Definition balance : Value.t -> Value.t -> M := The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -120,7 +143,8 @@ Definition balance : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -158,7 +182,8 @@ Definition balance : Value.t -> Value.t -> M := |) in M.pure Constant.None_ )) |) in - let balance := + let _ := M.assign_local (| + "balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -166,7 +191,8 @@ Definition balance : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -316,14 +342,16 @@ Definition calldataload : Value.t -> Value.t -> M := The current EVM frame. " in - let start_index := + let _ := M.assign_local (| + "start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -332,7 +360,8 @@ Definition calldataload : Value.t -> Value.t -> M := ], make_dict [] |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -347,7 +376,8 @@ Definition calldataload : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -432,31 +462,38 @@ Definition calldatacopy : Value.t -> Value.t -> M := The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let data_start_index := + |) + |) in + let _ := M.assign_local (| + "data_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -472,13 +509,17 @@ Definition calldatacopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -488,7 +529,8 @@ Definition calldatacopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -511,7 +553,8 @@ Definition calldatacopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -520,7 +563,8 @@ Definition calldatacopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -600,31 +644,38 @@ Definition codecopy : Value.t -> Value.t -> M := The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let code_start_index := + |) + |) in + let _ := M.assign_local (| + "code_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -640,13 +691,17 @@ Definition codecopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -656,7 +711,8 @@ Definition codecopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -679,7 +735,8 @@ Definition codecopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -688,7 +745,8 @@ Definition codecopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -759,7 +817,8 @@ Definition extcodesize : Value.t -> Value.t -> M := The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -772,7 +831,8 @@ Definition extcodesize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -810,7 +870,8 @@ Definition extcodesize : Value.t -> Value.t -> M := |) in M.pure Constant.None_ )) |) in - let codesize := + let _ := M.assign_local (| + "codesize" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -830,7 +891,8 @@ Definition extcodesize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -858,7 +920,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -871,32 +934,40 @@ Definition extcodecopy : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let memory_start_index := + |) + |) in + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let code_start_index := + |) + |) in + let _ := M.assign_local (| + "code_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -912,13 +983,17 @@ Definition extcodecopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -928,7 +1003,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -986,7 +1062,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let code := + let _ := M.assign_local (| + "code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -994,8 +1071,10 @@ Definition extcodecopy : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |), "code" |) in - let value := + |), "code" |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -1004,7 +1083,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -1079,31 +1159,38 @@ Definition returndatacopy : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let return_data_start_position := + |) + |) in + let _ := M.assign_local (| + "return_data_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -1119,13 +1206,17 @@ Definition returndatacopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_RETURN_DATA_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1135,7 +1226,8 @@ Definition returndatacopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1190,7 +1282,8 @@ Definition returndatacopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.slice (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |), @@ -1199,7 +1292,8 @@ Definition returndatacopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) |), Constant.None_ - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -1226,7 +1320,8 @@ Definition extcodehash : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1239,7 +1334,8 @@ Definition extcodehash : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1277,7 +1373,8 @@ Definition extcodehash : Value.t -> Value.t -> M := |) in M.pure Constant.None_ )) |) in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1285,7 +1382,8 @@ Definition extcodehash : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1295,18 +1393,21 @@ Definition extcodehash : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let codehash := + let _ := M.assign_local (| + "codehash" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let codehash := + let _ := M.assign_local (| + "codehash" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -1319,7 +1420,8 @@ Definition extcodehash : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -1358,7 +1460,8 @@ Definition self_balance : Value.t -> Value.t -> M := ], make_dict [] |) in - let balance := + let _ := M.assign_local (| + "balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1366,7 +1469,8 @@ Definition self_balance : Value.t -> Value.t -> M := M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/keccak.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/keccak.v index fbda431..eea02f8 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/keccak.v @@ -17,26 +17,36 @@ Introduction Implementations of the EVM keccak instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_arrow_glacier_vm_imports : - AreImported globals "ethereum.arrow_glacier.vm" [ "Evm" ]. +Axiom ethereum_arrow_glacier_vm_imports_Evm : + IsImported globals "ethereum.arrow_glacier.vm" "Evm". -Axiom ethereum_arrow_glacier_vm_gas_imports : - AreImported globals "ethereum.arrow_glacier.vm.gas" [ "GAS_KECCAK256"; "GAS_KECCAK256_WORD"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_KECCAK256 : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_KECCAK256". +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_KECCAK256_WORD : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_KECCAK256_WORD". +Axiom ethereum_arrow_glacier_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.arrow_glacier.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_arrow_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.arrow_glacier.vm.gas" "charge_gas". -Axiom ethereum_arrow_glacier_vm_memory_imports : - AreImported globals "ethereum.arrow_glacier.vm.memory" [ "memory_read_bytes" ]. +Axiom ethereum_arrow_glacier_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.arrow_glacier.vm.memory" "memory_read_bytes". -Axiom ethereum_arrow_glacier_vm_stack_imports : - AreImported globals "ethereum.arrow_glacier.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_arrow_glacier_vm_stack_imports_pop : + IsImported globals "ethereum.arrow_glacier.vm.stack" "pop". +Axiom ethereum_arrow_glacier_vm_stack_imports_push : + IsImported globals "ethereum.arrow_glacier.vm.stack" "push". Definition keccak : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -53,23 +63,28 @@ Definition keccak : Value.t -> Value.t -> M := The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -85,13 +100,17 @@ Definition keccak : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let word_gas_cost := + |) + |) in + let _ := M.assign_local (| + "word_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_KECCAK256_WORD" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -101,7 +120,8 @@ Definition keccak : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -124,7 +144,8 @@ Definition keccak : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let data := + let _ := M.assign_local (| + "data" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -133,15 +154,18 @@ Definition keccak : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in - let hash := + |) + |) in + let _ := M.assign_local (| + "hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "data" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/log.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/log.v index d687001..77cb339 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/log.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/log.v @@ -17,32 +17,40 @@ Introduction Implementations of the EVM logging instructions. ". -Axiom functools_imports : - AreImported globals "functools" [ "partial" ]. +Axiom functools_imports_partial : + IsImported globals "functools" "partial". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_arrow_glacier_blocks_imports : - AreImported globals "ethereum.arrow_glacier.blocks" [ "Log" ]. +Axiom ethereum_arrow_glacier_blocks_imports_Log : + IsImported globals "ethereum.arrow_glacier.blocks" "Log". -Axiom ethereum_arrow_glacier_vm_imports : - AreImported globals "ethereum.arrow_glacier.vm" [ "Evm" ]. +Axiom ethereum_arrow_glacier_vm_imports_Evm : + IsImported globals "ethereum.arrow_glacier.vm" "Evm". -Axiom ethereum_arrow_glacier_vm_exceptions_imports : - AreImported globals "ethereum.arrow_glacier.vm.exceptions" [ "WriteInStaticContext" ]. +Axiom ethereum_arrow_glacier_vm_exceptions_imports_WriteInStaticContext : + IsImported globals "ethereum.arrow_glacier.vm.exceptions" "WriteInStaticContext". -Axiom ethereum_arrow_glacier_vm_gas_imports : - AreImported globals "ethereum.arrow_glacier.vm.gas" [ "GAS_LOG"; "GAS_LOG_DATA"; "GAS_LOG_TOPIC"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_LOG : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_LOG". +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_LOG_DATA : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_LOG_DATA". +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_LOG_TOPIC : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_LOG_TOPIC". +Axiom ethereum_arrow_glacier_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.arrow_glacier.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_arrow_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.arrow_glacier.vm.gas" "charge_gas". -Axiom ethereum_arrow_glacier_vm_memory_imports : - AreImported globals "ethereum.arrow_glacier.vm.memory" [ "memory_read_bytes" ]. +Axiom ethereum_arrow_glacier_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.arrow_glacier.vm.memory" "memory_read_bytes". -Axiom ethereum_arrow_glacier_vm_stack_imports : - AreImported globals "ethereum.arrow_glacier.vm.stack" [ "pop" ]. +Axiom ethereum_arrow_glacier_vm_stack_imports_pop : + IsImported globals "ethereum.arrow_glacier.vm.stack" "pop". Definition log_n : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -61,24 +69,30 @@ Definition log_n : Value.t -> Value.t -> M := The number of topics to be included in the log entry. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let topics := - make_list [] in + |) + |) in + let _ := M.assign_local (| + "topics" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "_" |), @@ -90,7 +104,8 @@ Definition log_n : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let topic := + let _ := M.assign_local (| + "topic" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -101,7 +116,8 @@ Definition log_n : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "topics" |), "append" |), make_list [ @@ -115,7 +131,8 @@ Definition log_n : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let extend_memory := + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -125,7 +142,8 @@ Definition log_n : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -165,12 +183,14 @@ Definition log_n : Value.t -> Value.t -> M := ], make_dict [] |) in - let log_entry := + let _ := M.assign_local (| + "log_entry" , M.call (| M.get_name (| globals, "Log" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "logs" |), BinOp.add (| diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/memory.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/memory.v index 05d47e6..4fdbe0d 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/memory.v @@ -17,20 +17,32 @@ Introduction Implementations of the EVM Memory instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". -Axiom ethereum_arrow_glacier_vm_imports : - AreImported globals "ethereum.arrow_glacier.vm" [ "Evm" ]. +Axiom ethereum_arrow_glacier_vm_imports_Evm : + IsImported globals "ethereum.arrow_glacier.vm" "Evm". -Axiom ethereum_arrow_glacier_vm_gas_imports : - AreImported globals "ethereum.arrow_glacier.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_BASE". +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_arrow_glacier_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.arrow_glacier.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_arrow_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.arrow_glacier.vm.gas" "charge_gas". -Axiom ethereum_arrow_glacier_vm_memory_imports : - AreImported globals "ethereum.arrow_glacier.vm.memory" [ "memory_read_bytes"; "memory_write" ]. +Axiom ethereum_arrow_glacier_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.arrow_glacier.vm.memory" "memory_read_bytes". +Axiom ethereum_arrow_glacier_vm_memory_imports_memory_write : + IsImported globals "ethereum.arrow_glacier.vm.memory" "memory_write". -Axiom ethereum_arrow_glacier_vm_stack_imports : - AreImported globals "ethereum.arrow_glacier.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_arrow_glacier_vm_stack_imports_pop : + IsImported globals "ethereum.arrow_glacier.vm.stack" "pop". +Axiom ethereum_arrow_glacier_vm_stack_imports_push : + IsImported globals "ethereum.arrow_glacier.vm.stack" "push". Definition mstore : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -46,15 +58,18 @@ Definition mstore : Value.t -> Value.t -> M := The current EVM frame. " in - let start_position := + let _ := M.assign_local (| + "start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -65,8 +80,10 @@ Definition mstore : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -88,7 +105,8 @@ Definition mstore : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -138,23 +156,28 @@ Definition mstore8 : Value.t -> Value.t -> M := The current EVM frame. " in - let start_position := + let _ := M.assign_local (| + "start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -170,7 +193,8 @@ Definition mstore8 : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -190,7 +214,8 @@ Definition mstore8 : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let normalized_bytes_value := + let _ := M.assign_local (| + "normalized_bytes_value" , M.call (| M.get_name (| globals, "Bytes" |), make_list [ @@ -202,7 +227,8 @@ Definition mstore8 : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -231,15 +257,18 @@ Definition mload : Value.t -> Value.t -> M := The current EVM frame. " in - let start_position := + let _ := M.assign_local (| + "start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -255,7 +284,8 @@ Definition mload : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -275,7 +305,8 @@ Definition mload : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -296,7 +327,8 @@ Definition mload : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/stack.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/stack.v index 3115267..ba06637 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/stack.v @@ -17,26 +17,32 @@ Introduction Implementations of the EVM stack related instructions. ". -Axiom functools_imports : - AreImported globals "functools" [ "partial" ]. +Axiom functools_imports_partial : + IsImported globals "functools" "partial". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_arrow_glacier_vm_imports : - AreImported globals "ethereum.arrow_glacier.vm" [ "Evm"; "stack" ]. +Axiom ethereum_arrow_glacier_vm_imports_Evm : + IsImported globals "ethereum.arrow_glacier.vm" "Evm". +Axiom ethereum_arrow_glacier_vm_imports_stack : + IsImported globals "ethereum.arrow_glacier.vm" "stack". -Axiom ethereum_arrow_glacier_vm_exceptions_imports : - AreImported globals "ethereum.arrow_glacier.vm.exceptions" [ "StackUnderflowError" ]. +Axiom ethereum_arrow_glacier_vm_exceptions_imports_StackUnderflowError : + IsImported globals "ethereum.arrow_glacier.vm.exceptions" "StackUnderflowError". -Axiom ethereum_arrow_glacier_vm_gas_imports : - AreImported globals "ethereum.arrow_glacier.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_BASE". +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_arrow_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.arrow_glacier.vm.gas" "charge_gas". -Axiom ethereum_arrow_glacier_vm_memory_imports : - AreImported globals "ethereum.arrow_glacier.vm.memory" [ "buffer_read" ]. +Axiom ethereum_arrow_glacier_vm_memory_imports_buffer_read : + IsImported globals "ethereum.arrow_glacier.vm.memory" "buffer_read". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -98,7 +104,8 @@ Definition push_n : Value.t -> Value.t -> M := ], make_dict [] |) in - let data_to_push := + let _ := M.assign_local (| + "data_to_push" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -128,7 +135,8 @@ Definition push_n : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "stack" |), "push" |), make_list [ @@ -189,7 +197,8 @@ Definition dup_n : Value.t -> Value.t -> M := ], make_dict [] |) in - let data_to_duplicate := + let _ := M.assign_local (| + "data_to_duplicate" , M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| @@ -205,7 +214,8 @@ Definition dup_n : Value.t -> Value.t -> M := |), M.get_name (| globals, "item_number" |) |) - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "stack" |), "push" |), make_list [ diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/storage.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/storage.v index a8e32f7..b104e43 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/storage.v @@ -17,26 +17,46 @@ Introduction Implementations of the EVM storage related instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_arrow_glacier_state_imports : - AreImported globals "ethereum.arrow_glacier.state" [ "get_storage"; "get_storage_original"; "set_storage" ]. +Axiom ethereum_arrow_glacier_state_imports_get_storage : + IsImported globals "ethereum.arrow_glacier.state" "get_storage". +Axiom ethereum_arrow_glacier_state_imports_get_storage_original : + IsImported globals "ethereum.arrow_glacier.state" "get_storage_original". +Axiom ethereum_arrow_glacier_state_imports_set_storage : + IsImported globals "ethereum.arrow_glacier.state" "set_storage". -Axiom ethereum_arrow_glacier_vm_imports : - AreImported globals "ethereum.arrow_glacier.vm" [ "Evm" ]. +Axiom ethereum_arrow_glacier_vm_imports_Evm : + IsImported globals "ethereum.arrow_glacier.vm" "Evm". -Axiom ethereum_arrow_glacier_vm_exceptions_imports : - AreImported globals "ethereum.arrow_glacier.vm.exceptions" [ "OutOfGasError"; "WriteInStaticContext" ]. +Axiom ethereum_arrow_glacier_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.arrow_glacier.vm.exceptions" "OutOfGasError". +Axiom ethereum_arrow_glacier_vm_exceptions_imports_WriteInStaticContext : + IsImported globals "ethereum.arrow_glacier.vm.exceptions" "WriteInStaticContext". -Axiom ethereum_arrow_glacier_vm_gas_imports : - AreImported globals "ethereum.arrow_glacier.vm.gas" [ "GAS_CALL_STIPEND"; "GAS_COLD_SLOAD"; "GAS_STORAGE_CLEAR_REFUND"; "GAS_STORAGE_SET"; "GAS_STORAGE_UPDATE"; "GAS_WARM_ACCESS"; "charge_gas" ]. +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_CALL_STIPEND : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_CALL_STIPEND". +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_COLD_SLOAD : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_COLD_SLOAD". +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_STORAGE_CLEAR_REFUND : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_STORAGE_CLEAR_REFUND". +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_STORAGE_SET : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_STORAGE_SET". +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_STORAGE_UPDATE : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_STORAGE_UPDATE". +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_WARM_ACCESS : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_WARM_ACCESS". +Axiom ethereum_arrow_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.arrow_glacier.vm.gas" "charge_gas". -Axiom ethereum_arrow_glacier_vm_stack_imports : - AreImported globals "ethereum.arrow_glacier.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_arrow_glacier_vm_stack_imports_pop : + IsImported globals "ethereum.arrow_glacier.vm.stack" "pop". +Axiom ethereum_arrow_glacier_vm_stack_imports_push : + IsImported globals "ethereum.arrow_glacier.vm.stack" "push". Definition sload : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -51,7 +71,8 @@ Definition sload : Value.t -> Value.t -> M := The current EVM frame. " in - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -62,7 +83,8 @@ Definition sload : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -100,7 +122,8 @@ Definition sload : Value.t -> Value.t -> M := |) in M.pure Constant.None_ )) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "get_storage" |), make_list [ @@ -109,7 +132,8 @@ Definition sload : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -137,7 +161,8 @@ Definition sstore : Value.t -> Value.t -> M := The current EVM frame. " in - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -148,15 +173,18 @@ Definition sstore : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in - let new_value := + |) + |) in + let _ := M.assign_local (| + "new_value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -168,7 +196,8 @@ Definition sstore : Value.t -> Value.t -> M := ], make_dict [] |) in - let original_value := + let _ := M.assign_local (| + "original_value" , M.call (| M.get_name (| globals, "get_storage_original" |), make_list [ @@ -177,8 +206,10 @@ Definition sstore : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in - let current_value := + |) + |) in + let _ := M.assign_local (| + "current_value" , M.call (| M.get_name (| globals, "get_storage" |), make_list [ @@ -187,15 +218,18 @@ Definition sstore : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in - let gas_cost := + |) + |) in + let _ := M.assign_local (| + "gas_cost" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -212,9 +246,11 @@ Definition sstore : Value.t -> Value.t -> M := ], make_dict [] |) in - let gas_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "gas_cost", M.get_name (| globals, "GAS_COLD_SLOAD" |) - M.get_name (| globals, "GAS_COLD_SLOAD" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -246,29 +282,32 @@ Definition sstore : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let gas_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "gas_cost", M.get_name (| globals, "GAS_STORAGE_SET" |) - M.get_name (| globals, "GAS_STORAGE_SET" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let gas_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "gas_cost", BinOp.sub (| M.get_name (| globals, "GAS_STORAGE_UPDATE" |), M.get_name (| globals, "GAS_COLD_SLOAD" |) |) - BinOp.sub (| - M.get_name (| globals, "GAS_STORAGE_UPDATE" |), - M.get_name (| globals, "GAS_COLD_SLOAD" |) - |) in + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let gas_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "gas_cost", M.get_name (| globals, "GAS_WARM_ACCESS" |) - M.get_name (| globals, "GAS_WARM_ACCESS" |) in + |) in M.pure Constant.None_ )) |) in let _ := diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/system.v b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/system.v index a4cc36e..315f8d0 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/instructions/system.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/instructions/system.v @@ -17,38 +17,92 @@ Introduction Implementations of the EVM system related instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_arrow_glacier_fork_types_imports : - AreImported globals "ethereum.arrow_glacier.fork_types" [ "Address" ]. +Axiom ethereum_arrow_glacier_fork_types_imports_Address : + IsImported globals "ethereum.arrow_glacier.fork_types" "Address". -Axiom ethereum_arrow_glacier_state_imports : - AreImported globals "ethereum.arrow_glacier.state" [ "account_exists_and_is_empty"; "account_has_code_or_nonce"; "get_account"; "increment_nonce"; "is_account_alive"; "set_account_balance" ]. +Axiom ethereum_arrow_glacier_state_imports_account_exists_and_is_empty : + IsImported globals "ethereum.arrow_glacier.state" "account_exists_and_is_empty". +Axiom ethereum_arrow_glacier_state_imports_account_has_code_or_nonce : + IsImported globals "ethereum.arrow_glacier.state" "account_has_code_or_nonce". +Axiom ethereum_arrow_glacier_state_imports_get_account : + IsImported globals "ethereum.arrow_glacier.state" "get_account". +Axiom ethereum_arrow_glacier_state_imports_increment_nonce : + IsImported globals "ethereum.arrow_glacier.state" "increment_nonce". +Axiom ethereum_arrow_glacier_state_imports_is_account_alive : + IsImported globals "ethereum.arrow_glacier.state" "is_account_alive". +Axiom ethereum_arrow_glacier_state_imports_set_account_balance : + IsImported globals "ethereum.arrow_glacier.state" "set_account_balance". -Axiom ethereum_arrow_glacier_utils_address_imports : - AreImported globals "ethereum.arrow_glacier.utils.address" [ "compute_contract_address"; "compute_create2_contract_address"; "to_address" ]. +Axiom ethereum_arrow_glacier_utils_address_imports_compute_contract_address : + IsImported globals "ethereum.arrow_glacier.utils.address" "compute_contract_address". +Axiom ethereum_arrow_glacier_utils_address_imports_compute_create2_contract_address : + IsImported globals "ethereum.arrow_glacier.utils.address" "compute_create2_contract_address". +Axiom ethereum_arrow_glacier_utils_address_imports_to_address : + IsImported globals "ethereum.arrow_glacier.utils.address" "to_address". -Axiom ethereum_arrow_glacier_vm_imports : - AreImported globals "ethereum.arrow_glacier.vm" [ "Evm"; "Message"; "incorporate_child_on_error"; "incorporate_child_on_success" ]. +Axiom ethereum_arrow_glacier_vm_imports_Evm : + IsImported globals "ethereum.arrow_glacier.vm" "Evm". +Axiom ethereum_arrow_glacier_vm_imports_Message : + IsImported globals "ethereum.arrow_glacier.vm" "Message". +Axiom ethereum_arrow_glacier_vm_imports_incorporate_child_on_error : + IsImported globals "ethereum.arrow_glacier.vm" "incorporate_child_on_error". +Axiom ethereum_arrow_glacier_vm_imports_incorporate_child_on_success : + IsImported globals "ethereum.arrow_glacier.vm" "incorporate_child_on_success". -Axiom ethereum_arrow_glacier_vm_exceptions_imports : - AreImported globals "ethereum.arrow_glacier.vm.exceptions" [ "Revert"; "WriteInStaticContext" ]. +Axiom ethereum_arrow_glacier_vm_exceptions_imports_Revert : + IsImported globals "ethereum.arrow_glacier.vm.exceptions" "Revert". +Axiom ethereum_arrow_glacier_vm_exceptions_imports_WriteInStaticContext : + IsImported globals "ethereum.arrow_glacier.vm.exceptions" "WriteInStaticContext". -Axiom ethereum_arrow_glacier_vm_gas_imports : - AreImported globals "ethereum.arrow_glacier.vm.gas" [ "GAS_CALL_VALUE"; "GAS_COLD_ACCOUNT_ACCESS"; "GAS_CREATE"; "GAS_KECCAK256_WORD"; "GAS_NEW_ACCOUNT"; "GAS_SELF_DESTRUCT"; "GAS_SELF_DESTRUCT_NEW_ACCOUNT"; "GAS_WARM_ACCESS"; "GAS_ZERO"; "calculate_gas_extend_memory"; "calculate_message_call_gas"; "charge_gas"; "max_message_call_gas" ]. +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_CALL_VALUE : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_CALL_VALUE". +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_COLD_ACCOUNT_ACCESS : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_COLD_ACCOUNT_ACCESS". +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_CREATE : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_CREATE". +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_KECCAK256_WORD : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_KECCAK256_WORD". +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_NEW_ACCOUNT : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_NEW_ACCOUNT". +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_SELF_DESTRUCT : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_SELF_DESTRUCT". +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_SELF_DESTRUCT_NEW_ACCOUNT : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_SELF_DESTRUCT_NEW_ACCOUNT". +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_WARM_ACCESS : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_WARM_ACCESS". +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_ZERO : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_ZERO". +Axiom ethereum_arrow_glacier_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.arrow_glacier.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_arrow_glacier_vm_gas_imports_calculate_message_call_gas : + IsImported globals "ethereum.arrow_glacier.vm.gas" "calculate_message_call_gas". +Axiom ethereum_arrow_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.arrow_glacier.vm.gas" "charge_gas". +Axiom ethereum_arrow_glacier_vm_gas_imports_max_message_call_gas : + IsImported globals "ethereum.arrow_glacier.vm.gas" "max_message_call_gas". -Axiom ethereum_arrow_glacier_vm_memory_imports : - AreImported globals "ethereum.arrow_glacier.vm.memory" [ "memory_read_bytes"; "memory_write" ]. +Axiom ethereum_arrow_glacier_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.arrow_glacier.vm.memory" "memory_read_bytes". +Axiom ethereum_arrow_glacier_vm_memory_imports_memory_write : + IsImported globals "ethereum.arrow_glacier.vm.memory" "memory_write". -Axiom ethereum_arrow_glacier_vm_stack_imports : - AreImported globals "ethereum.arrow_glacier.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_arrow_glacier_vm_stack_imports_pop : + IsImported globals "ethereum.arrow_glacier.vm.stack" "pop". +Axiom ethereum_arrow_glacier_vm_stack_imports_push : + IsImported globals "ethereum.arrow_glacier.vm.stack" "push". Definition generic_create : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -64,7 +118,8 @@ Definition generic_create : Value.t -> Value.t -> M := ], make_dict [] |) in - let create_message_gas := + let _ := M.assign_local (| + "create_message_gas" , M.call (| M.get_name (| globals, "max_message_call_gas" |), make_list [ @@ -77,7 +132,8 @@ Definition generic_create : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.assign_op (| BinOp.sub, M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), @@ -95,9 +151,12 @@ Definition generic_create : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), Constant.bytes "" |) in - let sender_address := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in - let sender := + let _ := M.assign_local (| + "sender_address" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + |) in + let _ := M.assign_local (| + "sender" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -105,7 +164,8 @@ Definition generic_create : Value.t -> Value.t -> M := M.get_name (| globals, "sender_address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -216,7 +276,8 @@ Definition generic_create : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let call_data := + let _ := M.assign_local (| + "call_data" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -225,7 +286,8 @@ Definition generic_create : Value.t -> Value.t -> M := M.get_name (| globals, "memory_size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "increment_nonce" |), make_list [ @@ -234,13 +296,16 @@ Definition generic_create : Value.t -> Value.t -> M := ], make_dict [] |) in - let child_message := + let _ := M.assign_local (| + "child_message" , M.call (| M.get_name (| globals, "Message" |), make_list [], make_dict [] - |) in - let child_evm := + |) + |) in + let _ := M.assign_local (| + "child_evm" , M.call (| M.get_name (| globals, "process_create_message" |), make_list [ @@ -248,7 +313,8 @@ Definition generic_create : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -325,31 +391,38 @@ Definition create : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let endowment := + let _ := M.assign_local (| + "endowment" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_size := + |) + |) in + let _ := M.assign_local (| + "memory_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -359,7 +432,8 @@ Definition create : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -379,7 +453,8 @@ Definition create : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let contract_address := + let _ := M.assign_local (| + "contract_address" , M.call (| M.get_name (| globals, "compute_contract_address" |), make_list [ @@ -394,7 +469,8 @@ Definition create : Value.t -> Value.t -> M := |), "nonce" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "generic_create" |), make_list [ @@ -427,31 +503,38 @@ Definition create2 : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let endowment := + let _ := M.assign_local (| + "endowment" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_size := + |) + |) in + let _ := M.assign_local (| + "memory_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let salt := + |) + |) in + let _ := M.assign_local (| + "salt" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -462,8 +545,10 @@ Definition create2 : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -473,8 +558,10 @@ Definition create2 : Value.t -> Value.t -> M := ] ], make_dict [] - |) in - let call_data_words := + |) + |) in + let _ := M.assign_local (| + "call_data_words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -490,7 +577,8 @@ Definition create2 : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -516,7 +604,8 @@ Definition create2 : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let contract_address := + let _ := M.assign_local (| + "contract_address" , M.call (| M.get_name (| globals, "compute_create2_contract_address" |), make_list [ @@ -533,7 +622,8 @@ Definition create2 : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "generic_create" |), make_list [ @@ -563,23 +653,28 @@ Definition return_ : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let memory_start_position := + let _ := M.assign_local (| + "memory_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_size := + |) + |) in + let _ := M.assign_local (| + "memory_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -589,7 +684,8 @@ Definition return_ : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -678,7 +774,8 @@ Definition generic_call : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let call_data := + let _ := M.assign_local (| + "call_data" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -687,8 +784,10 @@ Definition generic_call : Value.t -> Value.t -> M := M.get_name (| globals, "memory_input_size" |) ], make_dict [] - |) in - let code := + |) + |) in + let _ := M.assign_local (| + "code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -696,14 +795,18 @@ Definition generic_call : Value.t -> Value.t -> M := M.get_name (| globals, "code_address" |) ], make_dict [] - |), "code" |) in - let child_message := + |), "code" |) + |) in + let _ := M.assign_local (| + "child_message" , M.call (| M.get_name (| globals, "Message" |), make_list [], make_dict [] - |) in - let child_evm := + |) + |) in + let _ := M.assign_local (| + "child_evm" , M.call (| M.get_name (| globals, "process_message" |), make_list [ @@ -711,7 +814,8 @@ Definition generic_call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -775,7 +879,8 @@ Definition generic_call : Value.t -> Value.t -> M := |) in M.pure Constant.None_ )) |) in - let actual_output_size := + let _ := M.assign_local (| + "actual_output_size" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -795,7 +900,8 @@ Definition generic_call : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -823,7 +929,8 @@ Definition call : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -836,8 +943,10 @@ Definition call : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let to := + |) + |) in + let _ := M.assign_local (| + "to" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -850,48 +959,60 @@ Definition call : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -902,7 +1023,8 @@ Definition call : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -912,8 +1034,10 @@ Definition call : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let access_gas_cost := - M.get_name (| globals, "GAS_WARM_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -924,11 +1048,14 @@ Definition call : Value.t -> Value.t -> M := ], make_dict [] |) in - let access_gas_cost := - M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + |) in M.pure Constant.None_ )) |) in - let create_gas_cost := + let _ := M.assign_local (| + "create_gas_cost" , (* if *) M.if_then_else (| BoolOp.or (| @@ -959,8 +1086,10 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "GAS_NEW_ACCOUNT" |) - )) |) in - let transfer_gas_cost := + )) |) + |) in + let _ := M.assign_local (| + "transfer_gas_cost" , (* if *) M.if_then_else (| Compare.eq (| @@ -979,8 +1108,10 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "GAS_CALL_VALUE" |) - )) |) in - let message_call_gas := + )) |) + |) in + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -1003,7 +1134,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1045,7 +1177,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let sender_balance := + let _ := M.assign_local (| + "sender_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1053,7 +1186,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := (* if *) M.if_then_else (| @@ -1127,7 +1261,8 @@ Definition callcode : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -1140,8 +1275,10 @@ Definition callcode : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let code_address := + |) + |) in + let _ := M.assign_local (| + "code_address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1154,50 +1291,64 @@ Definition callcode : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let to := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "to" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1208,7 +1359,8 @@ Definition callcode : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1218,8 +1370,10 @@ Definition callcode : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let access_gas_cost := - M.get_name (| globals, "GAS_WARM_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1230,11 +1384,14 @@ Definition callcode : Value.t -> Value.t -> M := ], make_dict [] |) in - let access_gas_cost := - M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + |) in M.pure Constant.None_ )) |) in - let transfer_gas_cost := + let _ := M.assign_local (| + "transfer_gas_cost" , (* if *) M.if_then_else (| Compare.eq (| @@ -1253,8 +1410,10 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "GAS_CALL_VALUE" |) - )) |) in - let message_call_gas := + )) |) + |) in + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -1274,7 +1433,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1294,7 +1454,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let sender_balance := + let _ := M.assign_local (| + "sender_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1302,7 +1463,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := (* if *) M.if_then_else (| @@ -1376,7 +1538,8 @@ Definition selfdestruct : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let beneficiary := + let _ := M.assign_local (| + "beneficiary" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1389,9 +1552,12 @@ Definition selfdestruct : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let gas_cost := - M.get_name (| globals, "GAS_SELF_DESTRUCT" |) in + |) + |) in + let _ := M.assign_local (| + "gas_cost" , + M.get_name (| globals, "GAS_SELF_DESTRUCT" |) + |) in let _ := (* if *) M.if_then_else (| @@ -1408,9 +1574,11 @@ Definition selfdestruct : Value.t -> Value.t -> M := ], make_dict [] |) in - let gas_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "gas_cost", M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) - M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1444,9 +1612,11 @@ Definition selfdestruct : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let gas_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "gas_cost", M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) - M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1468,9 +1638,12 @@ Definition selfdestruct : Value.t -> Value.t -> M := ], make_dict [] |) in - let originator := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in - let beneficiary_balance := + let _ := M.assign_local (| + "originator" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + |) in + let _ := M.assign_local (| + "beneficiary_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1478,8 +1651,10 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_name (| globals, "beneficiary" |) ], make_dict [] - |), "balance" |) in - let originator_balance := + |), "balance" |) + |) in + let _ := M.assign_local (| + "originator_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1487,7 +1662,8 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_name (| globals, "originator" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -1565,7 +1741,8 @@ Definition delegatecall : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -1578,8 +1755,10 @@ Definition delegatecall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let code_address := + |) + |) in + let _ := M.assign_local (| + "code_address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1592,40 +1771,50 @@ Definition delegatecall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1636,7 +1825,8 @@ Definition delegatecall : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1646,8 +1836,10 @@ Definition delegatecall : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let access_gas_cost := - M.get_name (| globals, "GAS_WARM_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1658,11 +1850,14 @@ Definition delegatecall : Value.t -> Value.t -> M := ], make_dict [] |) in - let access_gas_cost := - M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + |) in M.pure Constant.None_ )) |) in - let message_call_gas := + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -1685,7 +1880,8 @@ Definition delegatecall : Value.t -> Value.t -> M := M.get_name (| globals, "access_gas_cost" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1741,7 +1937,8 @@ Definition staticcall : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -1754,8 +1951,10 @@ Definition staticcall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let to := + |) + |) in + let _ := M.assign_local (| + "to" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1768,40 +1967,50 @@ Definition staticcall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1812,7 +2021,8 @@ Definition staticcall : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1822,8 +2032,10 @@ Definition staticcall : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let access_gas_cost := - M.get_name (| globals, "GAS_WARM_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1834,11 +2046,14 @@ Definition staticcall : Value.t -> Value.t -> M := ], make_dict [] |) in - let access_gas_cost := - M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + |) in M.pure Constant.None_ )) |) in - let message_call_gas := + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -1861,7 +2076,8 @@ Definition staticcall : Value.t -> Value.t -> M := M.get_name (| globals, "access_gas_cost" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1923,23 +2139,28 @@ Definition revert : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1949,7 +2170,8 @@ Definition revert : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1966,7 +2188,8 @@ Definition revert : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let output := + let _ := M.assign_local (| + "output" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -1975,7 +2198,8 @@ Definition revert : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/interpreter.v b/CoqOfPython/ethereum/arrow_glacier/vm/interpreter.v index 5b61da7..7958dd7 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/interpreter.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/interpreter.v @@ -17,50 +17,112 @@ Introduction A straightforward interpreter that executes EVM code. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Iterable"; "Optional"; "Set"; "Tuple" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. - -Axiom ethereum_trace_imports : - AreImported globals "ethereum.trace" [ "EvmStop"; "OpEnd"; "OpException"; "OpStart"; "PrecompileEnd"; "PrecompileStart"; "TransactionEnd"; "evm_trace" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_arrow_glacier_blocks_imports : - AreImported globals "ethereum.arrow_glacier.blocks" [ "Log" ]. - -Axiom ethereum_arrow_glacier_fork_types_imports : - AreImported globals "ethereum.arrow_glacier.fork_types" [ "Address" ]. - -Axiom ethereum_arrow_glacier_state_imports : - AreImported globals "ethereum.arrow_glacier.state" [ "account_exists_and_is_empty"; "account_has_code_or_nonce"; "begin_transaction"; "commit_transaction"; "destroy_storage"; "increment_nonce"; "mark_account_created"; "move_ether"; "rollback_transaction"; "set_code"; "touch_account" ]. - -Axiom ethereum_arrow_glacier_vm_imports : - AreImported globals "ethereum.arrow_glacier.vm" [ "Message" ]. - -Axiom ethereum_arrow_glacier_vm_gas_imports : - AreImported globals "ethereum.arrow_glacier.vm.gas" [ "GAS_CODE_DEPOSIT"; "charge_gas" ]. - -Axiom ethereum_arrow_glacier_vm_precompiled_contracts_mapping_imports : - AreImported globals "ethereum.arrow_glacier.vm.precompiled_contracts.mapping" [ "PRE_COMPILED_CONTRACTS" ]. - -Axiom ethereum_arrow_glacier_vm_imports : - AreImported globals "ethereum.arrow_glacier.vm" [ "Environment"; "Evm" ]. - -Axiom ethereum_arrow_glacier_vm_exceptions_imports : - AreImported globals "ethereum.arrow_glacier.vm.exceptions" [ "AddressCollision"; "ExceptionalHalt"; "InvalidContractPrefix"; "InvalidOpcode"; "OutOfGasError"; "Revert"; "StackDepthLimitError" ]. - -Axiom ethereum_arrow_glacier_vm_instructions_imports : - AreImported globals "ethereum.arrow_glacier.vm.instructions" [ "Ops"; "op_implementation" ]. - -Axiom ethereum_arrow_glacier_vm_runtime_imports : - AreImported globals "ethereum.arrow_glacier.vm.runtime" [ "get_valid_jump_destinations" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_Iterable : + IsImported globals "typing" "Iterable". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_trace_imports_EvmStop : + IsImported globals "ethereum.trace" "EvmStop". +Axiom ethereum_trace_imports_OpEnd : + IsImported globals "ethereum.trace" "OpEnd". +Axiom ethereum_trace_imports_OpException : + IsImported globals "ethereum.trace" "OpException". +Axiom ethereum_trace_imports_OpStart : + IsImported globals "ethereum.trace" "OpStart". +Axiom ethereum_trace_imports_PrecompileEnd : + IsImported globals "ethereum.trace" "PrecompileEnd". +Axiom ethereum_trace_imports_PrecompileStart : + IsImported globals "ethereum.trace" "PrecompileStart". +Axiom ethereum_trace_imports_TransactionEnd : + IsImported globals "ethereum.trace" "TransactionEnd". +Axiom ethereum_trace_imports_evm_trace : + IsImported globals "ethereum.trace" "evm_trace". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_arrow_glacier_blocks_imports_Log : + IsImported globals "ethereum.arrow_glacier.blocks" "Log". + +Axiom ethereum_arrow_glacier_fork_types_imports_Address : + IsImported globals "ethereum.arrow_glacier.fork_types" "Address". + +Axiom ethereum_arrow_glacier_state_imports_account_exists_and_is_empty : + IsImported globals "ethereum.arrow_glacier.state" "account_exists_and_is_empty". +Axiom ethereum_arrow_glacier_state_imports_account_has_code_or_nonce : + IsImported globals "ethereum.arrow_glacier.state" "account_has_code_or_nonce". +Axiom ethereum_arrow_glacier_state_imports_begin_transaction : + IsImported globals "ethereum.arrow_glacier.state" "begin_transaction". +Axiom ethereum_arrow_glacier_state_imports_commit_transaction : + IsImported globals "ethereum.arrow_glacier.state" "commit_transaction". +Axiom ethereum_arrow_glacier_state_imports_destroy_storage : + IsImported globals "ethereum.arrow_glacier.state" "destroy_storage". +Axiom ethereum_arrow_glacier_state_imports_increment_nonce : + IsImported globals "ethereum.arrow_glacier.state" "increment_nonce". +Axiom ethereum_arrow_glacier_state_imports_mark_account_created : + IsImported globals "ethereum.arrow_glacier.state" "mark_account_created". +Axiom ethereum_arrow_glacier_state_imports_move_ether : + IsImported globals "ethereum.arrow_glacier.state" "move_ether". +Axiom ethereum_arrow_glacier_state_imports_rollback_transaction : + IsImported globals "ethereum.arrow_glacier.state" "rollback_transaction". +Axiom ethereum_arrow_glacier_state_imports_set_code : + IsImported globals "ethereum.arrow_glacier.state" "set_code". +Axiom ethereum_arrow_glacier_state_imports_touch_account : + IsImported globals "ethereum.arrow_glacier.state" "touch_account". + +Axiom ethereum_arrow_glacier_vm_imports_Message : + IsImported globals "ethereum.arrow_glacier.vm" "Message". + +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_CODE_DEPOSIT : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_CODE_DEPOSIT". +Axiom ethereum_arrow_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.arrow_glacier.vm.gas" "charge_gas". + +Axiom ethereum_arrow_glacier_vm_precompiled_contracts_mapping_imports_PRE_COMPILED_CONTRACTS : + IsImported globals "ethereum.arrow_glacier.vm.precompiled_contracts.mapping" "PRE_COMPILED_CONTRACTS". + +Axiom ethereum_arrow_glacier_vm_imports_Environment : + IsImported globals "ethereum.arrow_glacier.vm" "Environment". +Axiom ethereum_arrow_glacier_vm_imports_Evm : + IsImported globals "ethereum.arrow_glacier.vm" "Evm". + +Axiom ethereum_arrow_glacier_vm_exceptions_imports_AddressCollision : + IsImported globals "ethereum.arrow_glacier.vm.exceptions" "AddressCollision". +Axiom ethereum_arrow_glacier_vm_exceptions_imports_ExceptionalHalt : + IsImported globals "ethereum.arrow_glacier.vm.exceptions" "ExceptionalHalt". +Axiom ethereum_arrow_glacier_vm_exceptions_imports_InvalidContractPrefix : + IsImported globals "ethereum.arrow_glacier.vm.exceptions" "InvalidContractPrefix". +Axiom ethereum_arrow_glacier_vm_exceptions_imports_InvalidOpcode : + IsImported globals "ethereum.arrow_glacier.vm.exceptions" "InvalidOpcode". +Axiom ethereum_arrow_glacier_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.arrow_glacier.vm.exceptions" "OutOfGasError". +Axiom ethereum_arrow_glacier_vm_exceptions_imports_Revert : + IsImported globals "ethereum.arrow_glacier.vm.exceptions" "Revert". +Axiom ethereum_arrow_glacier_vm_exceptions_imports_StackDepthLimitError : + IsImported globals "ethereum.arrow_glacier.vm.exceptions" "StackDepthLimitError". + +Axiom ethereum_arrow_glacier_vm_instructions_imports_Ops : + IsImported globals "ethereum.arrow_glacier.vm.instructions" "Ops". +Axiom ethereum_arrow_glacier_vm_instructions_imports_op_implementation : + IsImported globals "ethereum.arrow_glacier.vm.instructions" "op_implementation". + +Axiom ethereum_arrow_glacier_vm_runtime_imports_get_valid_jump_destinations : + IsImported globals "ethereum.arrow_glacier.vm.runtime" "get_valid_jump_destinations". Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -121,7 +183,8 @@ Definition process_message_call : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let is_collision := + let _ := M.assign_local (| + "is_collision" , M.call (| M.get_name (| globals, "account_has_code_or_nonce" |), make_list [ @@ -129,7 +192,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "message" |), "current_target" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -181,7 +245,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "process_create_message" |), make_list [ @@ -189,13 +254,15 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "process_message" |), make_list [ @@ -203,7 +270,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -250,46 +318,61 @@ Definition process_message_call : Value.t -> Value.t -> M := (* then *) ltac:(M.monadic ( (* At stmt: unsupported node type: AnnAssign *) - let accounts_to_delete := + let _ := M.assign_local (| + "accounts_to_delete" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let touched_accounts := + |) + |) in + let _ := M.assign_local (| + "touched_accounts" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let refund_counter := + |) + |) in + let _ := M.assign_local (| + "refund_counter" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let logs := - M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in - let accounts_to_delete := - M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in - let touched_accounts := - M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |) in - let refund_counter := + let _ := M.assign_local (| + "logs" , + M.get_field (| M.get_name (| globals, "evm" |), "logs" |) + |) in + let _ := M.assign_local (| + "accounts_to_delete" , + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) + |) in + let _ := M.assign_local (| + "touched_accounts" , + M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |) + |) in + let _ := M.assign_local (| + "refund_counter" , M.call (| M.get_name (| globals, "U256" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in - let tx_end := + let _ := M.assign_local (| + "tx_end" , M.call (| M.get_name (| globals, "TransactionEnd" |), make_list [ @@ -301,7 +384,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "error" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "evm_trace" |), make_list [ @@ -368,7 +452,8 @@ Definition process_create_message : Value.t -> Value.t -> M := ], make_dict [] |) in - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "process_message" |), make_list [ @@ -376,16 +461,20 @@ Definition process_create_message : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), (* then *) ltac:(M.monadic ( - let contract_code := - M.get_field (| M.get_name (| globals, "evm" |), "output" |) in - let contract_code_gas := + let _ := M.assign_local (| + "contract_code" , + M.get_field (| M.get_name (| globals, "evm" |), "output" |) + |) in + let _ := M.assign_local (| + "contract_code_gas" , BinOp.mult (| M.call (| M.get_name (| globals, "len" |), @@ -395,7 +484,8 @@ Definition process_create_message : Value.t -> Value.t -> M := make_dict [] |), M.get_name (| globals, "GAS_CODE_DEPOSIT" |) - |) in + |) + |) in (* At stmt: unsupported node type: Try *) M.pure Constant.None_ (* else *) @@ -497,7 +587,8 @@ Definition process_message : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "execute_code" |), make_list [ @@ -505,7 +596,8 @@ Definition process_message : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -554,22 +646,28 @@ Definition execute_code : Value.t -> Value.t -> M := evm: `ethereum.vm.EVM` Items containing execution specific objects " in - let code := - M.get_field (| M.get_name (| globals, "message" |), "code" |) in - let valid_jump_destinations := + let _ := M.assign_local (| + "code" , + M.get_field (| M.get_name (| globals, "message" |), "code" |) + |) in + let _ := M.assign_local (| + "valid_jump_destinations" , M.call (| M.get_name (| globals, "get_valid_jump_destinations" |), make_list [ M.get_name (| globals, "code" |) ], make_dict [] - |) in - let evm := + |) + |) in + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "Evm" |), make_list [], make_dict [] - |) in + |) + |) in (* At stmt: unsupported node type: Try *) let _ := M.return_ (| M.get_name (| globals, "evm" |) diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/memory.v b/CoqOfPython/ethereum/arrow_glacier/vm/memory.v index acbe8bd..207f7fb 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/memory.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/memory.v @@ -17,11 +17,15 @@ Introduction EVM memory operations. ". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "right_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_right_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "right_pad_zero_bytes". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". Definition memory_write : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/__init__.v index 5d06ae3..2d091ab 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/__init__.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/__init__.v @@ -18,8 +18,8 @@ Addresses of precompiled contracts and mappings to their implementations. ". -Axiom ethereum_arrow_glacier_utils_hexadecimal_imports : - AreImported globals "ethereum.arrow_glacier.utils.hexadecimal" [ "hex_to_address" ]. +Axiom ethereum_arrow_glacier_utils_hexadecimal_imports_hex_to_address : + IsImported globals "ethereum.arrow_glacier.utils.hexadecimal" "hex_to_address". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS"; Constant.str "MODEXP_ADDRESS"; Constant.str "ALT_BN128_ADD_ADDRESS"; Constant.str "ALT_BN128_MUL_ADDRESS"; Constant.str "ALT_BN128_PAIRING_CHECK_ADDRESS"; Constant.str "BLAKE2F_ADDRESS" ] diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/alt_bn128.v index 3b43930..4649b5a 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/alt_bn128.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/alt_bn128.v @@ -17,26 +17,42 @@ Introduction Implementation of the ALT_BN128 precompiled contracts. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_alt_bn128_imports : - AreImported globals "ethereum.crypto.alt_bn128" [ "ALT_BN128_CURVE_ORDER"; "ALT_BN128_PRIME"; "BNF"; "BNF2"; "BNF12"; "BNP"; "BNP2"; "pairing" ]. +Axiom ethereum_crypto_alt_bn128_imports_ALT_BN128_CURVE_ORDER : + IsImported globals "ethereum.crypto.alt_bn128" "ALT_BN128_CURVE_ORDER". +Axiom ethereum_crypto_alt_bn128_imports_ALT_BN128_PRIME : + IsImported globals "ethereum.crypto.alt_bn128" "ALT_BN128_PRIME". +Axiom ethereum_crypto_alt_bn128_imports_BNF : + IsImported globals "ethereum.crypto.alt_bn128" "BNF". +Axiom ethereum_crypto_alt_bn128_imports_BNF2 : + IsImported globals "ethereum.crypto.alt_bn128" "BNF2". +Axiom ethereum_crypto_alt_bn128_imports_BNF12 : + IsImported globals "ethereum.crypto.alt_bn128" "BNF12". +Axiom ethereum_crypto_alt_bn128_imports_BNP : + IsImported globals "ethereum.crypto.alt_bn128" "BNP". +Axiom ethereum_crypto_alt_bn128_imports_BNP2 : + IsImported globals "ethereum.crypto.alt_bn128" "BNP2". +Axiom ethereum_crypto_alt_bn128_imports_pairing : + IsImported globals "ethereum.crypto.alt_bn128" "pairing". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_arrow_glacier_vm_imports : - AreImported globals "ethereum.arrow_glacier.vm" [ "Evm" ]. +Axiom ethereum_arrow_glacier_vm_imports_Evm : + IsImported globals "ethereum.arrow_glacier.vm" "Evm". -Axiom ethereum_arrow_glacier_vm_gas_imports : - AreImported globals "ethereum.arrow_glacier.vm.gas" [ "charge_gas" ]. +Axiom ethereum_arrow_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.arrow_glacier.vm.gas" "charge_gas". -Axiom ethereum_arrow_glacier_vm_memory_imports : - AreImported globals "ethereum.arrow_glacier.vm.memory" [ "buffer_read" ]. +Axiom ethereum_arrow_glacier_vm_memory_imports_buffer_read : + IsImported globals "ethereum.arrow_glacier.vm.memory" "buffer_read". -Axiom ethereum_arrow_glacier_vm_exceptions_imports : - AreImported globals "ethereum.arrow_glacier.vm.exceptions" [ "OutOfGasError" ]. +Axiom ethereum_arrow_glacier_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.arrow_glacier.vm.exceptions" "OutOfGasError". Definition alt_bn128_add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -49,8 +65,10 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -65,7 +83,8 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := ], make_dict [] |) in - let x0_bytes := + let _ := M.assign_local (| + "x0_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -86,16 +105,20 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let x0_value := + |) + |) in + let _ := M.assign_local (| + "x0_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "x0_bytes" |) ], make_dict [] - |) in - let y0_bytes := + |) + |) in + let _ := M.assign_local (| + "y0_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -116,16 +139,20 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y0_value := + |) + |) in + let _ := M.assign_local (| + "y0_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "y0_bytes" |) ], make_dict [] - |) in - let x1_bytes := + |) + |) in + let _ := M.assign_local (| + "x1_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -146,16 +173,20 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let x1_value := + |) + |) in + let _ := M.assign_local (| + "x1_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "x1_bytes" |) ], make_dict [] - |) in - let y1_bytes := + |) + |) in + let _ := M.assign_local (| + "y1_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -176,15 +207,18 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y1_value := + |) + |) in + let _ := M.assign_local (| + "y1_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "y1_bytes" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "i" |), @@ -212,11 +246,13 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := )) |) in (* At stmt: unsupported node type: Try *) - let p := + let _ := M.assign_local (| + "p" , BinOp.add (| M.get_name (| globals, "p0" |), M.get_name (| globals, "p1" |) - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), BinOp.add (| @@ -245,8 +281,10 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -261,7 +299,8 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := ], make_dict [] |) in - let x0_bytes := + let _ := M.assign_local (| + "x0_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -282,16 +321,20 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let x0_value := + |) + |) in + let _ := M.assign_local (| + "x0_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "x0_bytes" |) ], make_dict [] - |) in - let y0_bytes := + |) + |) in + let _ := M.assign_local (| + "y0_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -312,16 +355,20 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y0_value := + |) + |) in + let _ := M.assign_local (| + "y0_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "y0_bytes" |) ], make_dict [] - |) in - let n := + |) + |) in + let _ := M.assign_local (| + "n" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -348,7 +395,8 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "i" |), @@ -376,14 +424,16 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := )) |) in (* At stmt: unsupported node type: Try *) - let p := + let _ := M.assign_local (| + "p" , M.call (| M.get_field (| M.get_name (| globals, "p0" |), "mul_by" |), make_list [ M.get_name (| globals, "n" |) ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), BinOp.add (| @@ -412,8 +462,10 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -467,14 +519,16 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), make_list [ Constant.int 1 ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "i" |), @@ -495,8 +549,10 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let values := - make_list [] in + let _ := M.assign_local (| + "values" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "j" |), @@ -508,7 +564,8 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -541,7 +598,8 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -644,7 +702,8 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , BinOp.mult (| M.get_name (| globals, "result" |), M.call (| @@ -655,7 +714,8 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/blake2f.v b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/blake2f.v index bf62e5e..0cad2c6 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/blake2f.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/blake2f.v @@ -17,20 +17,22 @@ Introduction Implementation of the `Blake2` precompiled contract. ". -Axiom ethereum_crypto_blake2_imports : - AreImported globals "ethereum.crypto.blake2" [ "Blake2b" ]. +Axiom ethereum_crypto_blake2_imports_Blake2b : + IsImported globals "ethereum.crypto.blake2" "Blake2b". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_arrow_glacier_vm_imports : - AreImported globals "ethereum.arrow_glacier.vm" [ "Evm" ]. +Axiom ethereum_arrow_glacier_vm_imports_Evm : + IsImported globals "ethereum.arrow_glacier.vm" "Evm". -Axiom ethereum_arrow_glacier_vm_gas_imports : - AreImported globals "ethereum.arrow_glacier.vm.gas" [ "GAS_BLAKE2_PER_ROUND"; "charge_gas" ]. +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_BLAKE2_PER_ROUND : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_BLAKE2_PER_ROUND". +Axiom ethereum_arrow_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.arrow_glacier.vm.gas" "charge_gas". -Axiom ethereum_arrow_glacier_vm_exceptions_imports : - AreImported globals "ethereum.arrow_glacier.vm.exceptions" [ "InvalidParameter" ]. +Axiom ethereum_arrow_glacier_vm_exceptions_imports_InvalidParameter : + IsImported globals "ethereum.arrow_glacier.vm.exceptions" "InvalidParameter". Definition blake2f : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -43,8 +45,10 @@ Definition blake2f : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -62,12 +66,14 @@ Definition blake2f : Value.t -> Value.t -> M := ], make_dict [] |) in - let blake2b := + let _ := M.assign_local (| + "blake2b" , M.call (| M.get_name (| globals, "Blake2b" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "rounds" |); M.get_name (| globals, "h" |); M.get_name (| globals, "m" |); M.get_name (| globals, "t_0" |); M.get_name (| globals, "t_1" |); M.get_name (| globals, "f" |) ], M.call (| diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/ecrecover.v index 5b0a066..aaa3942 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/ecrecover.v @@ -17,26 +17,32 @@ Introduction Implementation of the ECRECOVER precompiled contract. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_crypto_elliptic_curve_imports : - AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. +Axiom ethereum_crypto_elliptic_curve_imports_SECP256K1N : + IsImported globals "ethereum.crypto.elliptic_curve" "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_imports_secp256k1_recover : + IsImported globals "ethereum.crypto.elliptic_curve" "secp256k1_recover". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_left_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "left_pad_zero_bytes". -Axiom ethereum_arrow_glacier_vm_imports : - AreImported globals "ethereum.arrow_glacier.vm" [ "Evm" ]. +Axiom ethereum_arrow_glacier_vm_imports_Evm : + IsImported globals "ethereum.arrow_glacier.vm" "Evm". -Axiom ethereum_arrow_glacier_vm_gas_imports : - AreImported globals "ethereum.arrow_glacier.vm.gas" [ "GAS_ECRECOVER"; "charge_gas" ]. +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_ECRECOVER : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_ECRECOVER". +Axiom ethereum_arrow_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.arrow_glacier.vm.gas" "charge_gas". -Axiom ethereum_arrow_glacier_vm_memory_imports : - AreImported globals "ethereum.arrow_glacier.vm.memory" [ "buffer_read" ]. +Axiom ethereum_arrow_glacier_vm_memory_imports_buffer_read : + IsImported globals "ethereum.arrow_glacier.vm.memory" "buffer_read". Definition ecrecover : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -50,8 +56,10 @@ Definition ecrecover : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -60,7 +68,8 @@ Definition ecrecover : Value.t -> Value.t -> M := ], make_dict [] |) in - let message_hash_bytes := + let _ := M.assign_local (| + "message_hash_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -81,16 +90,20 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let message_hash := + |) + |) in + let _ := M.assign_local (| + "message_hash" , M.call (| M.get_name (| globals, "Hash32" |), make_list [ M.get_name (| globals, "message_hash_bytes" |) ], make_dict [] - |) in - let v := + |) + |) in + let _ := M.assign_local (| + "v" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -117,8 +130,10 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let r := + |) + |) in + let _ := M.assign_local (| + "r" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -145,8 +160,10 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let s := + |) + |) in + let _ := M.assign_local (| + "s" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -173,7 +190,8 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -250,7 +268,8 @@ Definition ecrecover : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: Try *) - let address := + let _ := M.assign_local (| + "address" , M.slice (| M.call (| M.get_name (| globals, "keccak256" |), @@ -262,8 +281,10 @@ Definition ecrecover : Value.t -> Value.t -> M := Constant.int 12, Constant.int 32, Constant.None_ - |) in - let padded_address := + |) + |) in + let _ := M.assign_local (| + "padded_address" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -271,7 +292,8 @@ Definition ecrecover : Value.t -> Value.t -> M := Constant.int 32 ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.get_name (| globals, "padded_address" |) diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/identity.v index 9032a82..7443148 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/identity.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/identity.v @@ -17,17 +17,21 @@ Introduction Implementation of the `IDENTITY` precompiled contract. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_arrow_glacier_vm_imports : - AreImported globals "ethereum.arrow_glacier.vm" [ "Evm" ]. +Axiom ethereum_arrow_glacier_vm_imports_Evm : + IsImported globals "ethereum.arrow_glacier.vm" "Evm". -Axiom ethereum_arrow_glacier_vm_gas_imports : - AreImported globals "ethereum.arrow_glacier.vm.gas" [ "GAS_IDENTITY"; "GAS_IDENTITY_WORD"; "charge_gas" ]. +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_IDENTITY : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_IDENTITY". +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_IDENTITY_WORD : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_IDENTITY_WORD". +Axiom ethereum_arrow_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.arrow_glacier.vm.gas" "charge_gas". Definition identity : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -40,9 +44,12 @@ Definition identity : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let word_count := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "word_count" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -64,7 +71,8 @@ Definition identity : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/mapping.v index b43b508..d47d1fc 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/mapping.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/mapping.v @@ -17,34 +17,56 @@ Introduction Mapping of precompiled contracts their implementations. ". -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict" ]. - -Axiom ethereum_arrow_glacier_fork_types_imports : - AreImported globals "ethereum.arrow_glacier.fork_types" [ "Address" ]. - -Axiom ethereum_arrow_glacier_vm_precompiled_contracts_imports : - AreImported globals "ethereum.arrow_glacier.vm.precompiled_contracts" [ "ALT_BN128_ADD_ADDRESS"; "ALT_BN128_MUL_ADDRESS"; "ALT_BN128_PAIRING_CHECK_ADDRESS"; "BLAKE2F_ADDRESS"; "ECRECOVER_ADDRESS"; "IDENTITY_ADDRESS"; "MODEXP_ADDRESS"; "RIPEMD160_ADDRESS"; "SHA256_ADDRESS" ]. - -Axiom ethereum_arrow_glacier_vm_precompiled_contracts_alt_bn128_imports : - AreImported globals "ethereum.arrow_glacier.vm.precompiled_contracts.alt_bn128" [ "alt_bn128_add"; "alt_bn128_mul"; "alt_bn128_pairing_check" ]. - -Axiom ethereum_arrow_glacier_vm_precompiled_contracts_blake2f_imports : - AreImported globals "ethereum.arrow_glacier.vm.precompiled_contracts.blake2f" [ "blake2f" ]. - -Axiom ethereum_arrow_glacier_vm_precompiled_contracts_ecrecover_imports : - AreImported globals "ethereum.arrow_glacier.vm.precompiled_contracts.ecrecover" [ "ecrecover" ]. - -Axiom ethereum_arrow_glacier_vm_precompiled_contracts_identity_imports : - AreImported globals "ethereum.arrow_glacier.vm.precompiled_contracts.identity" [ "identity" ]. - -Axiom ethereum_arrow_glacier_vm_precompiled_contracts_modexp_imports : - AreImported globals "ethereum.arrow_glacier.vm.precompiled_contracts.modexp" [ "modexp" ]. - -Axiom ethereum_arrow_glacier_vm_precompiled_contracts_ripemd160_imports : - AreImported globals "ethereum.arrow_glacier.vm.precompiled_contracts.ripemd160" [ "ripemd160" ]. - -Axiom ethereum_arrow_glacier_vm_precompiled_contracts_sha256_imports : - AreImported globals "ethereum.arrow_glacier.vm.precompiled_contracts.sha256" [ "sha256" ]. +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". + +Axiom ethereum_arrow_glacier_fork_types_imports_Address : + IsImported globals "ethereum.arrow_glacier.fork_types" "Address". + +Axiom ethereum_arrow_glacier_vm_precompiled_contracts_imports_ALT_BN128_ADD_ADDRESS : + IsImported globals "ethereum.arrow_glacier.vm.precompiled_contracts" "ALT_BN128_ADD_ADDRESS". +Axiom ethereum_arrow_glacier_vm_precompiled_contracts_imports_ALT_BN128_MUL_ADDRESS : + IsImported globals "ethereum.arrow_glacier.vm.precompiled_contracts" "ALT_BN128_MUL_ADDRESS". +Axiom ethereum_arrow_glacier_vm_precompiled_contracts_imports_ALT_BN128_PAIRING_CHECK_ADDRESS : + IsImported globals "ethereum.arrow_glacier.vm.precompiled_contracts" "ALT_BN128_PAIRING_CHECK_ADDRESS". +Axiom ethereum_arrow_glacier_vm_precompiled_contracts_imports_BLAKE2F_ADDRESS : + IsImported globals "ethereum.arrow_glacier.vm.precompiled_contracts" "BLAKE2F_ADDRESS". +Axiom ethereum_arrow_glacier_vm_precompiled_contracts_imports_ECRECOVER_ADDRESS : + IsImported globals "ethereum.arrow_glacier.vm.precompiled_contracts" "ECRECOVER_ADDRESS". +Axiom ethereum_arrow_glacier_vm_precompiled_contracts_imports_IDENTITY_ADDRESS : + IsImported globals "ethereum.arrow_glacier.vm.precompiled_contracts" "IDENTITY_ADDRESS". +Axiom ethereum_arrow_glacier_vm_precompiled_contracts_imports_MODEXP_ADDRESS : + IsImported globals "ethereum.arrow_glacier.vm.precompiled_contracts" "MODEXP_ADDRESS". +Axiom ethereum_arrow_glacier_vm_precompiled_contracts_imports_RIPEMD160_ADDRESS : + IsImported globals "ethereum.arrow_glacier.vm.precompiled_contracts" "RIPEMD160_ADDRESS". +Axiom ethereum_arrow_glacier_vm_precompiled_contracts_imports_SHA256_ADDRESS : + IsImported globals "ethereum.arrow_glacier.vm.precompiled_contracts" "SHA256_ADDRESS". + +Axiom ethereum_arrow_glacier_vm_precompiled_contracts_alt_bn128_imports_alt_bn128_add : + IsImported globals "ethereum.arrow_glacier.vm.precompiled_contracts.alt_bn128" "alt_bn128_add". +Axiom ethereum_arrow_glacier_vm_precompiled_contracts_alt_bn128_imports_alt_bn128_mul : + IsImported globals "ethereum.arrow_glacier.vm.precompiled_contracts.alt_bn128" "alt_bn128_mul". +Axiom ethereum_arrow_glacier_vm_precompiled_contracts_alt_bn128_imports_alt_bn128_pairing_check : + IsImported globals "ethereum.arrow_glacier.vm.precompiled_contracts.alt_bn128" "alt_bn128_pairing_check". + +Axiom ethereum_arrow_glacier_vm_precompiled_contracts_blake2f_imports_blake2f : + IsImported globals "ethereum.arrow_glacier.vm.precompiled_contracts.blake2f" "blake2f". + +Axiom ethereum_arrow_glacier_vm_precompiled_contracts_ecrecover_imports_ecrecover : + IsImported globals "ethereum.arrow_glacier.vm.precompiled_contracts.ecrecover" "ecrecover". + +Axiom ethereum_arrow_glacier_vm_precompiled_contracts_identity_imports_identity : + IsImported globals "ethereum.arrow_glacier.vm.precompiled_contracts.identity" "identity". + +Axiom ethereum_arrow_glacier_vm_precompiled_contracts_modexp_imports_modexp : + IsImported globals "ethereum.arrow_glacier.vm.precompiled_contracts.modexp" "modexp". + +Axiom ethereum_arrow_glacier_vm_precompiled_contracts_ripemd160_imports_ripemd160 : + IsImported globals "ethereum.arrow_glacier.vm.precompiled_contracts.ripemd160" "ripemd160". + +Axiom ethereum_arrow_glacier_vm_precompiled_contracts_sha256_imports_sha256 : + IsImported globals "ethereum.arrow_glacier.vm.precompiled_contracts.sha256" "sha256". (* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/modexp.v index 7471ac7..df32505 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/modexp.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/modexp.v @@ -17,17 +17,21 @@ Introduction Implementation of the `MODEXP` precompiled contract. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_arrow_glacier_vm_imports : - AreImported globals "ethereum.arrow_glacier.vm" [ "Evm" ]. +Axiom ethereum_arrow_glacier_vm_imports_Evm : + IsImported globals "ethereum.arrow_glacier.vm" "Evm". -Axiom ethereum_arrow_glacier_vm_gas_imports : - AreImported globals "ethereum.arrow_glacier.vm.gas" [ "charge_gas" ]. +Axiom ethereum_arrow_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.arrow_glacier.vm.gas" "charge_gas". -Axiom ethereum_arrow_glacier_vm_memory_imports : - AreImported globals "ethereum.arrow_glacier.vm.memory" [ "buffer_read" ]. +Axiom ethereum_arrow_glacier_vm_memory_imports_buffer_read : + IsImported globals "ethereum.arrow_glacier.vm.memory" "buffer_read". Definition GQUADDIVISOR : Value.t := M.run ltac:(M.monadic ( Constant.int 3 @@ -40,9 +44,12 @@ Definition modexp : Value.t -> Value.t -> M := Calculates `(base**exp) % modulus` for arbitrary sized `base`, `exp` and. `modulus`. The return value is the same length as the modulus. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let base_length := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "base_length" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -69,8 +76,10 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exp_length := + |) + |) in + let _ := M.assign_local (| + "exp_length" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -97,8 +106,10 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let modulus_length := + |) + |) in + let _ := M.assign_local (| + "modulus_length" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -125,8 +136,10 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exp_start := + |) + |) in + let _ := M.assign_local (| + "exp_start" , BinOp.add (| M.call (| M.get_name (| globals, "U256" |), @@ -136,8 +149,10 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |), M.get_name (| globals, "base_length" |) - |) in - let exp_head := + |) + |) in + let _ := M.assign_local (| + "exp_head" , M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ @@ -165,7 +180,8 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -216,7 +232,8 @@ Definition modexp : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let base := + let _ := M.assign_local (| + "base" , M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ @@ -237,8 +254,10 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exp := + |) + |) in + let _ := M.assign_local (| + "exp" , M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ @@ -253,13 +272,17 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let modulus_start := + |) + |) in + let _ := M.assign_local (| + "modulus_start" , BinOp.add (| M.get_name (| globals, "exp_start" |), M.get_name (| globals, "exp_length" |) - |) in - let modulus := + |) + |) in + let _ := M.assign_local (| + "modulus" , M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ @@ -274,7 +297,8 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -350,7 +374,8 @@ Definition complexity : Value.t -> Value.t -> M := complexity : `Uint` Complexity of performing the operation. " in - let max_length := + let _ := M.assign_local (| + "max_length" , M.call (| M.get_name (| globals, "max" |), make_list [ @@ -370,15 +395,18 @@ Definition complexity : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| BinOp.add (| M.get_name (| globals, "max_length" |), Constant.int 7 |), Constant.int 8 - |) in + |) + |) in let _ := M.return_ (| BinOp.pow (| M.get_name (| globals, "words" |), @@ -427,14 +455,16 @@ Definition iterations : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let count := + let _ := M.assign_local (| + "count" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -447,7 +477,8 @@ Definition iterations : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let bit_length := + let _ := M.assign_local (| + "bit_length" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -458,7 +489,8 @@ Definition iterations : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -468,20 +500,25 @@ Definition iterations : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let bit_length := BinOp.sub + let _ := M.assign_op_local (| + BinOp.sub, + "bit_length", Constant.int 1 - Constant.int 1 in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let count := - M.get_name (| globals, "bit_length" |) in + let _ := M.assign_local (| + "count" , + M.get_name (| globals, "bit_length" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let length_part := + let _ := M.assign_local (| + "length_part" , BinOp.mult (| Constant.int 8, BinOp.sub (| @@ -494,8 +531,10 @@ Definition iterations : Value.t -> Value.t -> M := |), Constant.int 32 |) - |) in - let bits_part := + |) + |) in + let _ := M.assign_local (| + "bits_part" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -506,7 +545,8 @@ Definition iterations : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -516,19 +556,23 @@ Definition iterations : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let bits_part := BinOp.sub + let _ := M.assign_op_local (| + BinOp.sub, + "bits_part", Constant.int 1 - Constant.int 1 in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let count := + let _ := M.assign_local (| + "count" , BinOp.add (| M.get_name (| globals, "length_part" |), M.get_name (| globals, "bits_part" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -579,7 +623,8 @@ Definition gas_cost : Value.t -> Value.t -> M := gas_cost : `Uint` Gas required for performing the operation. " in - let multiplication_complexity := + let _ := M.assign_local (| + "multiplication_complexity" , M.call (| M.get_name (| globals, "complexity" |), make_list [ @@ -587,8 +632,10 @@ Definition gas_cost : Value.t -> Value.t -> M := M.get_name (| globals, "modulus_length" |) ], make_dict [] - |) in - let iteration_count := + |) + |) in + let _ := M.assign_local (| + "iteration_count" , M.call (| M.get_name (| globals, "iterations" |), make_list [ @@ -596,15 +643,20 @@ Definition gas_cost : Value.t -> Value.t -> M := M.get_name (| globals, "exponent_head" |) ], make_dict [] - |) in - let cost := + |) + |) in + let _ := M.assign_local (| + "cost" , BinOp.mult (| M.get_name (| globals, "multiplication_complexity" |), M.get_name (| globals, "iteration_count" |) - |) in - let cost := BinOp.floor_div + |) + |) in + let _ := M.assign_op_local (| + BinOp.floor_div, + "cost", M.get_name (| globals, "GQUADDIVISOR" |) - M.get_name (| globals, "GQUADDIVISOR" |) in + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "max" |), diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/ripemd160.v index 57fafeb..cc2bc0a 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/ripemd160.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/ripemd160.v @@ -19,20 +19,24 @@ Implementation of the `RIPEMD160` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_left_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "left_pad_zero_bytes". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_arrow_glacier_vm_imports : - AreImported globals "ethereum.arrow_glacier.vm" [ "Evm" ]. +Axiom ethereum_arrow_glacier_vm_imports_Evm : + IsImported globals "ethereum.arrow_glacier.vm" "Evm". -Axiom ethereum_arrow_glacier_vm_gas_imports : - AreImported globals "ethereum.arrow_glacier.vm.gas" [ "GAS_RIPEMD160"; "GAS_RIPEMD160_WORD"; "charge_gas" ]. +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_RIPEMD160 : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_RIPEMD160". +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_RIPEMD160_WORD : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_RIPEMD160_WORD". +Axiom ethereum_arrow_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.arrow_glacier.vm.gas" "charge_gas". Definition ripemd160 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,9 +49,12 @@ Definition ripemd160 : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let word_count := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "word_count" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -69,7 +76,8 @@ Definition ripemd160 : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -84,7 +92,8 @@ Definition ripemd160 : Value.t -> Value.t -> M := ], make_dict [] |) in - let hash_bytes := + let _ := M.assign_local (| + "hash_bytes" , M.call (| M.get_field (| M.call (| M.get_field (| M.get_name (| globals, "hashlib" |), "new" |), @@ -96,8 +105,10 @@ Definition ripemd160 : Value.t -> Value.t -> M := |), "digest" |), make_list [], make_dict [] - |) in - let padded_hash := + |) + |) in + let _ := M.assign_local (| + "padded_hash" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -105,7 +116,8 @@ Definition ripemd160 : Value.t -> Value.t -> M := Constant.int 32 ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.get_name (| globals, "padded_hash" |) diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/sha256.v index 97d3445..ce66ace 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/sha256.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/precompiled_contracts/sha256.v @@ -19,17 +19,21 @@ Implementation of the `SHA256` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_arrow_glacier_vm_imports : - AreImported globals "ethereum.arrow_glacier.vm" [ "Evm" ]. +Axiom ethereum_arrow_glacier_vm_imports_Evm : + IsImported globals "ethereum.arrow_glacier.vm" "Evm". -Axiom ethereum_arrow_glacier_vm_gas_imports : - AreImported globals "ethereum.arrow_glacier.vm.gas" [ "GAS_SHA256"; "GAS_SHA256_WORD"; "charge_gas" ]. +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_SHA256 : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_SHA256". +Axiom ethereum_arrow_glacier_vm_gas_imports_GAS_SHA256_WORD : + IsImported globals "ethereum.arrow_glacier.vm.gas" "GAS_SHA256_WORD". +Axiom ethereum_arrow_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.arrow_glacier.vm.gas" "charge_gas". Definition sha256 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,9 +46,12 @@ Definition sha256 : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let word_count := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "word_count" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -66,7 +73,8 @@ Definition sha256 : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/runtime.v b/CoqOfPython/ethereum/arrow_glacier/vm/runtime.v index f45a90f..4e59678 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/runtime.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/runtime.v @@ -17,14 +17,14 @@ Introduction Runtime related operations used while executing EVM code. ". -Axiom typing_imports : - AreImported globals "typing" [ "Set" ]. +Axiom typing_imports_Set : + IsImported globals "typing" "Set". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_arrow_glacier_vm_instructions_imports : - AreImported globals "ethereum.arrow_glacier.vm.instructions" [ "Ops" ]. +Axiom ethereum_arrow_glacier_vm_instructions_imports_Ops : + IsImported globals "ethereum.arrow_glacier.vm.instructions" "Ops". Definition get_valid_jump_destinations : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -50,20 +50,24 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := valid_jump_destinations: `Set[Uint]` The set of valid jump destinations in the code. " in - let valid_jump_destinations := + let _ := M.assign_local (| + "valid_jump_destinations" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let pc := + |) + |) in + let _ := M.assign_local (| + "pc" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in let _ := M.while (| Compare.lt (| @@ -114,17 +118,21 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let push_data_size := + let _ := M.assign_local (| + "push_data_size" , BinOp.add (| BinOp.sub (| M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) |), Constant.int 1 - |) in - let pc := BinOp.add + |) + |) in + let _ := M.assign_op_local (| + BinOp.add, + "pc", M.get_name (| globals, "push_data_size" |) - M.get_name (| globals, "push_data_size" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -132,9 +140,11 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - let pc := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "pc", Constant.int 1 - Constant.int 1 in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/arrow_glacier/vm/stack.v b/CoqOfPython/ethereum/arrow_glacier/vm/stack.v index e0be079..9258f93 100644 --- a/CoqOfPython/ethereum/arrow_glacier/vm/stack.v +++ b/CoqOfPython/ethereum/arrow_glacier/vm/stack.v @@ -17,14 +17,16 @@ Introduction Implementation of the stack operators for the EVM. ". -Axiom typing_imports : - AreImported globals "typing" [ "List" ]. +Axiom typing_imports_List : + IsImported globals "typing" "List". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_arrow_glacier_vm_exceptions_imports : - AreImported globals "ethereum.arrow_glacier.vm.exceptions" [ "StackOverflowError"; "StackUnderflowError" ]. +Axiom ethereum_arrow_glacier_vm_exceptions_imports_StackOverflowError : + IsImported globals "ethereum.arrow_glacier.vm.exceptions" "StackOverflowError". +Axiom ethereum_arrow_glacier_vm_exceptions_imports_StackUnderflowError : + IsImported globals "ethereum.arrow_glacier.vm.exceptions" "StackUnderflowError". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/base_types.v b/CoqOfPython/ethereum/base_types.v index 970976c..4229846 100644 --- a/CoqOfPython/ethereum/base_types.v +++ b/CoqOfPython/ethereum/base_types.v @@ -24,11 +24,29 @@ sequences containing an exact number of bytes. [`Bytes64`]: ref:ethereum.base_types.Bytes64 ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "is_dataclass"; "replace" ]. +Axiom dataclasses_imports_is_dataclass : + IsImported globals "dataclasses" "is_dataclass". +Axiom dataclasses_imports_replace : + IsImported globals "dataclasses" "replace". -Axiom typing_imports : - AreImported globals "typing" [ "Any"; "Callable"; "ClassVar"; "Optional"; "Protocol"; "Tuple"; "Type"; "TypeVar"; "runtime_checkable" ]. +Axiom typing_imports_Any : + IsImported globals "typing" "Any". +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_ClassVar : + IsImported globals "typing" "ClassVar". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Protocol : + IsImported globals "typing" "Protocol". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Type : + IsImported globals "typing" "Type". +Axiom typing_imports_TypeVar : + IsImported globals "typing" "TypeVar". +Axiom typing_imports_runtime_checkable : + IsImported globals "typing" "runtime_checkable". Definition SlottedFreezable : Value.t := builtins.make_klass @@ -846,7 +864,8 @@ Definition Uint : Value.t := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "int" |), "__divmod__" |), make_list [ @@ -854,7 +873,8 @@ Definition Uint : Value.t := M.get_name (| globals, "right" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| make_tuple [ M.call (| M.get_field (| M.get_name (| globals, "int" |), "__new__" |), @@ -924,7 +944,8 @@ Definition Uint : Value.t := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "int" |), "__rdivmod__" |), make_list [ @@ -932,7 +953,8 @@ Definition Uint : Value.t := M.get_name (| globals, "left" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| make_tuple [ M.call (| M.get_field (| M.get_name (| globals, "int" |), "__new__" |), @@ -1385,20 +1407,24 @@ Definition Uint : Value.t := Converts this arbitrarily sized unsigned integer into its big endian representation, without padding. " in - let bit_length := + let _ := M.assign_local (| + "bit_length" , M.call (| M.get_field (| M.get_name (| globals, "self" |), "bit_length" |), make_list [], make_dict [] - |) in - let byte_length := + |) + |) in + let _ := M.assign_local (| + "byte_length" , BinOp.floor_div (| BinOp.add (| M.get_name (| globals, "bit_length" |), Constant.int 7 |), Constant.int 8 - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "self" |), "to_bytes" |), @@ -1428,20 +1454,24 @@ Definition Uint : Value.t := |), (* then *) ltac:(M.monadic ( - let bit_length := + let _ := M.assign_local (| + "bit_length" , M.call (| M.get_field (| M.get_name (| globals, "self" |), "bit_length" |), make_list [], make_dict [] - |) in - let number_bytes := + |) + |) in + let _ := M.assign_local (| + "number_bytes" , BinOp.floor_div (| BinOp.add (| M.get_name (| globals, "bit_length" |), Constant.int 7 |), Constant.int 8 - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1574,7 +1604,8 @@ Definition FixedUint : Value.t := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "int" |), "__add__" |), make_list [ @@ -1582,7 +1613,8 @@ Definition FixedUint : Value.t := M.get_name (| globals, "right" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -2001,7 +2033,8 @@ Definition FixedUint : Value.t := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "int" |), "__mul__" |), make_list [ @@ -2009,7 +2042,8 @@ Definition FixedUint : Value.t := M.get_name (| globals, "right" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -2528,7 +2562,8 @@ Definition FixedUint : Value.t := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "super" |), @@ -2542,7 +2577,8 @@ Definition FixedUint : Value.t := M.get_name (| globals, "right" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| make_tuple [ M.call (| M.get_field (| M.get_name (| globals, "int" |), "__new__" |), @@ -2620,7 +2656,8 @@ Definition FixedUint : Value.t := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "super" |), @@ -2634,7 +2671,8 @@ Definition FixedUint : Value.t := M.get_name (| globals, "left" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| make_tuple [ M.call (| M.get_field (| M.get_name (| globals, "int" |), "__new__" |), @@ -2747,7 +2785,8 @@ Definition FixedUint : Value.t := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "int" |), "__pow__" |), make_list [ @@ -2756,7 +2795,8 @@ Definition FixedUint : Value.t := M.get_name (| globals, "modulo" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -3478,20 +3518,24 @@ Definition FixedUint : Value.t := Converts this unsigned integer into its big endian representation, omitting leading zero bytes. " in - let bit_length := + let _ := M.assign_local (| + "bit_length" , M.call (| M.get_field (| M.get_name (| globals, "self" |), "bit_length" |), make_list [], make_dict [] - |) in - let byte_length := + |) + |) in + let _ := M.assign_local (| + "byte_length" , BinOp.floor_div (| BinOp.add (| M.get_name (| globals, "bit_length" |), Constant.int 7 |), Constant.int 8 - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "self" |), "to_bytes" |), @@ -3777,20 +3821,24 @@ Definition U32 : Value.t := Converts this fixed sized unsigned integer into its little endian representation, in the fewest bytes possible. " in - let bit_length := + let _ := M.assign_local (| + "bit_length" , M.call (| M.get_field (| M.get_name (| globals, "self" |), "bit_length" |), make_list [], make_dict [] - |) in - let byte_length := + |) + |) in + let _ := M.assign_local (| + "byte_length" , BinOp.floor_div (| BinOp.add (| M.get_name (| globals, "bit_length" |), Constant.int 7 |), Constant.int 8 - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "self" |), "to_bytes" |), @@ -3949,20 +3997,24 @@ Definition U64 : Value.t := Converts this fixed sized unsigned integer into its little endian representation, in the fewest bytes possible. " in - let bit_length := + let _ := M.assign_local (| + "bit_length" , M.call (| M.get_field (| M.get_name (| globals, "self" |), "bit_length" |), make_list [], make_dict [] - |) in - let byte_length := + |) + |) in + let _ := M.assign_local (| + "byte_length" , BinOp.floor_div (| BinOp.add (| M.get_name (| globals, "bit_length" |), Constant.int 7 |), Constant.int 8 - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "self" |), "to_bytes" |), @@ -4003,22 +4055,8 @@ Definition FixedBytes : Value.t := let _ := Constant.str " Create a new instance, ensuring the result has the correct length. " in - let x := - make_list_concat (| [ - make_list [ - Constant.int 1; - Constant.int 2 - ]; - make_list [ - Constant.str "x"; - Constant.str "y"; - Constant.str "z" - ]; - make_list [ - Constant.int 3 - ] - ] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "super" |), @@ -4035,7 +4073,8 @@ Definition FixedBytes : Value.t := M.get_name (| globals, "args" |) ] |), make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -4154,7 +4193,7 @@ Definition Bytes : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "bytes" |) )). -Definition expr_926 : Value.t := +Definition expr_925 : Value.t := Constant.str " Sequence of bytes (octets) of arbitrary length. ". @@ -4339,14 +4378,16 @@ Definition modify : Value.t -> Value.t -> M := ], make_dict [] |) |) in - let new_obj := + let _ := M.assign_local (| + "new_obj" , M.call (| M.get_name (| globals, "replace" |), make_list [ M.get_name (| globals, "obj" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "f" |), make_list [ diff --git a/CoqOfPython/ethereum/berlin/__init__.v b/CoqOfPython/ethereum/berlin/__init__.v index efe0a00..9616412 100644 --- a/CoqOfPython/ethereum/berlin/__init__.v +++ b/CoqOfPython/ethereum/berlin/__init__.v @@ -9,8 +9,8 @@ state access EVM instructions, introduces typed transaction envelopes along with the first new transaction type—optional access lists. ". -Axiom ethereum_fork_criteria_imports : - AreImported globals "ethereum.fork_criteria" [ "ByBlockNumber" ]. +Axiom ethereum_fork_criteria_imports_ByBlockNumber : + IsImported globals "ethereum.fork_criteria" "ByBlockNumber". Definition FORK_CRITERIA : Value.t := M.run ltac:(M.monadic ( M.call (| diff --git a/CoqOfPython/ethereum/berlin/blocks.v b/CoqOfPython/ethereum/berlin/blocks.v index daec5a3..8ab9689 100644 --- a/CoqOfPython/ethereum/berlin/blocks.v +++ b/CoqOfPython/ethereum/berlin/blocks.v @@ -14,23 +14,39 @@ history of all state transitions that have happened since the genesis of the chain. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Tuple"; "Union" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes8"; "Bytes32"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. - -Axiom ethereum_berlin_fork_types_imports : - AreImported globals "ethereum.berlin.fork_types" [ "Address"; "Bloom"; "Root" ]. - -Axiom ethereum_berlin_transactions_imports : - AreImported globals "ethereum.berlin.transactions" [ "LegacyTransaction" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes8 : + IsImported globals "ethereum.base_types" "Bytes8". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". + +Axiom ethereum_berlin_fork_types_imports_Address : + IsImported globals "ethereum.berlin.fork_types" "Address". +Axiom ethereum_berlin_fork_types_imports_Bloom : + IsImported globals "ethereum.berlin.fork_types" "Bloom". +Axiom ethereum_berlin_fork_types_imports_Root : + IsImported globals "ethereum.berlin.fork_types" "Root". + +Axiom ethereum_berlin_transactions_imports_LegacyTransaction : + IsImported globals "ethereum.berlin.transactions" "LegacyTransaction". Definition Header : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/berlin/bloom.v b/CoqOfPython/ethereum/berlin/bloom.v index 8356dcc..a94f117 100644 --- a/CoqOfPython/ethereum/berlin/bloom.v +++ b/CoqOfPython/ethereum/berlin/bloom.v @@ -21,20 +21,20 @@ for efficient searching of logs by address and/or topic, by rapidly eliminating blocks and receipts from their search. ". -Axiom typing_imports : - AreImported globals "typing" [ "Tuple" ]. +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_berlin_blocks_imports : - AreImported globals "ethereum.berlin.blocks" [ "Log" ]. +Axiom ethereum_berlin_blocks_imports_Log : + IsImported globals "ethereum.berlin.blocks" "Log". -Axiom ethereum_berlin_fork_types_imports : - AreImported globals "ethereum.berlin.fork_types" [ "Bloom" ]. +Axiom ethereum_berlin_fork_types_imports_Bloom : + IsImported globals "ethereum.berlin.fork_types" "Bloom". Definition add_to_bloom : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -53,20 +53,23 @@ Definition add_to_bloom : Value.t -> Value.t -> M := bloom_entry : An entry which is to be added to bloom filter. " in - let hash := + let _ := M.assign_local (| + "hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "bloom_entry" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "idx" |), make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ], ltac:(M.monadic ( - let bit_to_set := + let _ := M.assign_local (| + "bit_to_set" , BinOp.bit_and (| M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), @@ -84,18 +87,24 @@ Definition add_to_bloom : Value.t -> Value.t -> M := make_dict [] |), Constant.int 2047 - |) in - let bit_index := + |) + |) in + let _ := M.assign_local (| + "bit_index" , BinOp.sub (| Constant.int 2047, M.get_name (| globals, "bit_to_set" |) - |) in - let byte_index := + |) + |) in + let _ := M.assign_local (| + "byte_index" , BinOp.floor_div (| M.get_name (| globals, "bit_index" |), Constant.int 8 - |) in - let bit_value := + |) + |) in + let _ := M.assign_local (| + "bit_value" , BinOp.l_shift (| Constant.int 1, BinOp.sub (| @@ -105,7 +114,8 @@ Definition add_to_bloom : Value.t -> Value.t -> M := Constant.int 8 |) |) - |) in + |) + |) in let _ := M.assign (| M.get_subscript (| M.get_name (| globals, "bloom" |), diff --git a/CoqOfPython/ethereum/berlin/fork.v b/CoqOfPython/ethereum/berlin/fork.v index d79219b..3a85cfb 100644 --- a/CoqOfPython/ethereum/berlin/fork.v +++ b/CoqOfPython/ethereum/berlin/fork.v @@ -17,62 +17,134 @@ Introduction Entry point for the Ethereum specification. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple"; "Union" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Bytes0" ]. - -Axiom ethereum_crypto_elliptic_curve_imports : - AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. - -Axiom ethereum_ethash_imports : - AreImported globals "ethereum.ethash" [ "dataset_size"; "generate_cache"; "hashimoto_light" ]. - -Axiom ethereum_exceptions_imports : - AreImported globals "ethereum.exceptions" [ "InvalidBlock" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U64"; "U256"; "U256_CEIL_VALUE"; "Bytes"; "Uint" ]. - -Axiom ethereum_berlin_imports : - AreImported globals "ethereum.berlin" [ "vm" ]. - -Axiom ethereum_berlin_blocks_imports : - AreImported globals "ethereum.berlin.blocks" [ "Block"; "Header"; "Log"; "Receipt" ]. - -Axiom ethereum_berlin_bloom_imports : - AreImported globals "ethereum.berlin.bloom" [ "logs_bloom" ]. - -Axiom ethereum_berlin_fork_types_imports : - AreImported globals "ethereum.berlin.fork_types" [ "Address"; "Bloom"; "Root" ]. - -Axiom ethereum_berlin_state_imports : - AreImported globals "ethereum.berlin.state" [ "State"; "account_exists_and_is_empty"; "create_ether"; "destroy_account"; "get_account"; "increment_nonce"; "set_account_balance"; "state_root" ]. - -Axiom ethereum_berlin_transactions_imports : - AreImported globals "ethereum.berlin.transactions" [ "TX_ACCESS_LIST_ADDRESS_COST"; "TX_ACCESS_LIST_STORAGE_KEY_COST"; "TX_BASE_COST"; "TX_CREATE_COST"; "TX_DATA_COST_PER_NON_ZERO"; "TX_DATA_COST_PER_ZERO"; "AccessListTransaction"; "LegacyTransaction"; "Transaction"; "decode_transaction"; "encode_transaction" ]. - -Axiom ethereum_berlin_trie_imports : - AreImported globals "ethereum.berlin.trie" [ "Trie"; "root"; "trie_set" ]. - -Axiom ethereum_berlin_utils_message_imports : - AreImported globals "ethereum.berlin.utils.message" [ "prepare_message" ]. - -Axiom ethereum_berlin_vm_interpreter_imports : - AreImported globals "ethereum.berlin.vm.interpreter" [ "process_message_call" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". + +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". + +Axiom ethereum_crypto_elliptic_curve_imports_SECP256K1N : + IsImported globals "ethereum.crypto.elliptic_curve" "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_imports_secp256k1_recover : + IsImported globals "ethereum.crypto.elliptic_curve" "secp256k1_recover". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". + +Axiom ethereum_ethash_imports_dataset_size : + IsImported globals "ethereum.ethash" "dataset_size". +Axiom ethereum_ethash_imports_generate_cache : + IsImported globals "ethereum.ethash" "generate_cache". +Axiom ethereum_ethash_imports_hashimoto_light : + IsImported globals "ethereum.ethash" "hashimoto_light". + +Axiom ethereum_exceptions_imports_InvalidBlock : + IsImported globals "ethereum.exceptions" "InvalidBlock". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U64 : + IsImported globals "ethereum.base_types" "U64". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_U256_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U256_CEIL_VALUE". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_berlin_imports_vm : + IsImported globals "ethereum.berlin" "vm". + +Axiom ethereum_berlin_blocks_imports_Block : + IsImported globals "ethereum.berlin.blocks" "Block". +Axiom ethereum_berlin_blocks_imports_Header : + IsImported globals "ethereum.berlin.blocks" "Header". +Axiom ethereum_berlin_blocks_imports_Log : + IsImported globals "ethereum.berlin.blocks" "Log". +Axiom ethereum_berlin_blocks_imports_Receipt : + IsImported globals "ethereum.berlin.blocks" "Receipt". + +Axiom ethereum_berlin_bloom_imports_logs_bloom : + IsImported globals "ethereum.berlin.bloom" "logs_bloom". + +Axiom ethereum_berlin_fork_types_imports_Address : + IsImported globals "ethereum.berlin.fork_types" "Address". +Axiom ethereum_berlin_fork_types_imports_Bloom : + IsImported globals "ethereum.berlin.fork_types" "Bloom". +Axiom ethereum_berlin_fork_types_imports_Root : + IsImported globals "ethereum.berlin.fork_types" "Root". + +Axiom ethereum_berlin_state_imports_State : + IsImported globals "ethereum.berlin.state" "State". +Axiom ethereum_berlin_state_imports_account_exists_and_is_empty : + IsImported globals "ethereum.berlin.state" "account_exists_and_is_empty". +Axiom ethereum_berlin_state_imports_create_ether : + IsImported globals "ethereum.berlin.state" "create_ether". +Axiom ethereum_berlin_state_imports_destroy_account : + IsImported globals "ethereum.berlin.state" "destroy_account". +Axiom ethereum_berlin_state_imports_get_account : + IsImported globals "ethereum.berlin.state" "get_account". +Axiom ethereum_berlin_state_imports_increment_nonce : + IsImported globals "ethereum.berlin.state" "increment_nonce". +Axiom ethereum_berlin_state_imports_set_account_balance : + IsImported globals "ethereum.berlin.state" "set_account_balance". +Axiom ethereum_berlin_state_imports_state_root : + IsImported globals "ethereum.berlin.state" "state_root". + +Axiom ethereum_berlin_transactions_imports_TX_ACCESS_LIST_ADDRESS_COST : + IsImported globals "ethereum.berlin.transactions" "TX_ACCESS_LIST_ADDRESS_COST". +Axiom ethereum_berlin_transactions_imports_TX_ACCESS_LIST_STORAGE_KEY_COST : + IsImported globals "ethereum.berlin.transactions" "TX_ACCESS_LIST_STORAGE_KEY_COST". +Axiom ethereum_berlin_transactions_imports_TX_BASE_COST : + IsImported globals "ethereum.berlin.transactions" "TX_BASE_COST". +Axiom ethereum_berlin_transactions_imports_TX_CREATE_COST : + IsImported globals "ethereum.berlin.transactions" "TX_CREATE_COST". +Axiom ethereum_berlin_transactions_imports_TX_DATA_COST_PER_NON_ZERO : + IsImported globals "ethereum.berlin.transactions" "TX_DATA_COST_PER_NON_ZERO". +Axiom ethereum_berlin_transactions_imports_TX_DATA_COST_PER_ZERO : + IsImported globals "ethereum.berlin.transactions" "TX_DATA_COST_PER_ZERO". +Axiom ethereum_berlin_transactions_imports_AccessListTransaction : + IsImported globals "ethereum.berlin.transactions" "AccessListTransaction". +Axiom ethereum_berlin_transactions_imports_LegacyTransaction : + IsImported globals "ethereum.berlin.transactions" "LegacyTransaction". +Axiom ethereum_berlin_transactions_imports_Transaction : + IsImported globals "ethereum.berlin.transactions" "Transaction". +Axiom ethereum_berlin_transactions_imports_decode_transaction : + IsImported globals "ethereum.berlin.transactions" "decode_transaction". +Axiom ethereum_berlin_transactions_imports_encode_transaction : + IsImported globals "ethereum.berlin.transactions" "encode_transaction". + +Axiom ethereum_berlin_trie_imports_Trie : + IsImported globals "ethereum.berlin.trie" "Trie". +Axiom ethereum_berlin_trie_imports_root : + IsImported globals "ethereum.berlin.trie" "root". +Axiom ethereum_berlin_trie_imports_trie_set : + IsImported globals "ethereum.berlin.trie" "trie_set". + +Axiom ethereum_berlin_utils_message_imports_prepare_message : + IsImported globals "ethereum.berlin.utils.message" "prepare_message". + +Axiom ethereum_berlin_vm_interpreter_imports_process_message_call : + IsImported globals "ethereum.berlin.vm.interpreter" "process_message_call". Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -190,13 +262,15 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := recent_block_hashes : `List[Hash32]` Hashes of the recent 256 blocks in order of increasing block number. " in - let recent_blocks := + let _ := M.assign_local (| + "recent_blocks" , M.slice (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |), Constant.None_, Constant.None_ - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -220,15 +294,19 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let recent_block_hashes := - make_list [] in + let _ := M.assign_local (| + "recent_block_hashes" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "block" |), M.get_name (| globals, "recent_blocks" |), ltac:(M.monadic ( - let prev_block_hash := - M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in + let _ := M.assign_local (| + "prev_block_hash" , + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), make_list [ @@ -242,7 +320,8 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let most_recent_block_hash := + let _ := M.assign_local (| + "most_recent_block_hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -258,7 +337,8 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), make_list [ @@ -295,11 +375,13 @@ Definition state_transition : Value.t -> Value.t -> M := block : Block to apply to `chain`. " in - let parent_header := + let _ := M.assign_local (| + "parent_header" , M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 1 |) - |), "header" |) in + |), "header" |) + |) in let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ @@ -317,7 +399,8 @@ Definition state_transition : Value.t -> Value.t -> M := ], make_dict [] |) in - let apply_body_output := + let _ := M.assign_local (| + "apply_body_output" , M.call (| M.get_name (| globals, "apply_body" |), make_list [ @@ -339,7 +422,8 @@ Definition state_transition : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "chain" |), "chain_id" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -453,11 +537,13 @@ Definition validate_header : Value.t -> Value.t -> M := parent_header : Parent Header of the header to check for correctness " in - let parent_has_ommers := + let _ := M.assign_local (| + "parent_has_ommers" , Compare.not_eq (| M.get_field (| M.get_name (| globals, "parent_header" |), "ommers_hash" |), M.get_name (| globals, "EMPTY_OMMER_HASH" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -515,7 +601,8 @@ Definition validate_header : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_difficulty := + let _ := M.assign_local (| + "block_difficulty" , M.call (| M.get_name (| globals, "calculate_block_difficulty" |), make_list [ @@ -526,7 +613,8 @@ Definition validate_header : Value.t -> Value.t -> M := M.get_name (| globals, "parent_has_ommers" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -538,7 +626,8 @@ Definition validate_header : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_parent_hash := + let _ := M.assign_local (| + "block_parent_hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -551,7 +640,8 @@ Definition validate_header : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -597,7 +687,8 @@ Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := hash : `Hash32` The PoW valid rlp hash of the passed in header. " in - let header_data_without_pow_artefacts := + let _ := M.assign_local (| + "header_data_without_pow_artefacts" , make_list [ M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |); M.get_field (| M.get_name (| globals, "header" |), "ommers_hash" |); @@ -612,7 +703,8 @@ Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "header" |), "gas_used" |); M.get_field (| M.get_name (| globals, "header" |), "timestamp" |); M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) - ] in + ] + |) in let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), @@ -641,22 +733,26 @@ Definition validate_proof_of_work : Value.t -> Value.t -> M := header : Header of interest. " in - let header_hash := + let _ := M.assign_local (| + "header_hash" , M.call (| M.get_name (| globals, "generate_header_hash_for_pow" |), make_list [ M.get_name (| globals, "header" |) ], make_dict [] - |) in - let cache := + |) + |) in + let _ := M.assign_local (| + "cache" , M.call (| M.get_name (| globals, "generate_cache" |), make_list [ M.get_field (| M.get_name (| globals, "header" |), "number" |) ], make_dict [] - |) in + |) + |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "mix_digest" |); M.get_name (| globals, "result" |) ], M.call (| @@ -745,7 +841,8 @@ Definition check_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_address := + let _ := M.assign_local (| + "sender_address" , M.call (| M.get_name (| globals, "recover_sender" |), make_list [ @@ -753,7 +850,8 @@ Definition check_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "tx" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "sender_address" |) |) in @@ -782,12 +880,14 @@ Definition make_receipt : Value.t -> Value.t -> M := receipt : The receipt for the transaction. " in - let receipt := + let _ := M.assign_local (| + "receipt" , M.call (| M.get_name (| globals, "Receipt" |), make_list [], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -876,8 +976,10 @@ Definition apply_body : Value.t -> Value.t -> M := apply_body_output : `ApplyBodyOutput` Output of applying the block body to the state. " in - let gas_available := - M.get_name (| globals, "block_gas_limit" |) in + let _ := M.assign_local (| + "gas_available" , + M.get_name (| globals, "block_gas_limit" |) + |) in (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) @@ -926,7 +1028,8 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_address := + let _ := M.assign_local (| + "sender_address" , M.call (| M.get_name (| globals, "check_transaction" |), make_list [ @@ -935,13 +1038,16 @@ Definition apply_body : Value.t -> Value.t -> M := M.get_name (| globals, "chain_id" |) ], make_dict [] - |) in - let env := + |) + |) in + let _ := M.assign_local (| + "env" , M.call (| M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |); M.get_name (| globals, "error" |) ], M.call (| @@ -953,10 +1059,13 @@ Definition apply_body : Value.t -> Value.t -> M := make_dict [] |) |) in - let gas_available := BinOp.sub + let _ := M.assign_op_local (| + BinOp.sub, + "gas_available", M.get_name (| globals, "gas_used" |) - M.get_name (| globals, "gas_used" |) in - let receipt := + |) in + let _ := M.assign_local (| + "receipt" , M.call (| M.get_name (| globals, "make_receipt" |), make_list [ @@ -969,7 +1078,8 @@ Definition apply_body : Value.t -> Value.t -> M := M.get_name (| globals, "logs" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ @@ -991,9 +1101,11 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_logs := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "block_logs", M.get_name (| globals, "logs" |) - M.get_name (| globals, "logs" |) in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -1010,19 +1122,23 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_gas_used := + let _ := M.assign_local (| + "block_gas_used" , BinOp.sub (| M.get_name (| globals, "block_gas_limit" |), M.get_name (| globals, "gas_available" |) - |) in - let block_logs_bloom := + |) + |) in + let _ := M.assign_local (| + "block_logs_bloom" , M.call (| M.get_name (| globals, "logs_bloom" |), make_list [ M.get_name (| globals, "block_logs" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ApplyBodyOutput" |), @@ -1080,14 +1196,16 @@ Definition validate_ommers : Value.t -> Value.t -> M := chain : History and current state. " in - let block_hash := + let _ := M.assign_local (| + "block_hash" , M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), make_list [ M.get_name (| globals, "block_header" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1152,7 +1270,8 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_parent_header := + let _ := M.assign_local (| + "ommer_parent_header" , M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), BinOp.sub (| @@ -1162,7 +1281,8 @@ Definition validate_ommers : Value.t -> Value.t -> M := |) |), Constant.int 1 |) - |), "header" |) in + |), "header" |) + |) in let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ @@ -1194,8 +1314,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommers_hashes := - Constant.str "(* At expr: unsupported node type: ListComp *)" in + let _ := M.assign_local (| + "ommers_hashes" , + Constant.str "(* At expr: unsupported node type: ListComp *)" + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1225,7 +1347,8 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let recent_canonical_blocks := + let _ := M.assign_local (| + "recent_canonical_blocks" , M.slice (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| BinOp.add (| @@ -1234,23 +1357,28 @@ Definition validate_ommers : Value.t -> Value.t -> M := |) |), Constant.None_, Constant.None_ - |) in - let recent_canonical_block_hashes := - Constant.str "(* At expr: unsupported node type: SetComp *)" in + |) + |) in + let _ := M.assign_local (| + "recent_canonical_block_hashes" , + Constant.str "(* At expr: unsupported node type: SetComp *)" + |) in (* At stmt: unsupported node type: AnnAssign *) let _ := M.for_ (| M.get_name (| globals, "block" |), M.get_name (| globals, "recent_canonical_blocks" |), ltac:(M.monadic ( - let recent_ommers_hashes := + let _ := M.assign_local (| + "recent_ommers_hashes" , M.call (| M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), make_list [ Constant.str "(* At expr: unsupported node type: SetComp *)" ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -1268,11 +1396,13 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let ommer_hash := + let _ := M.assign_local (| + "ommer_hash" , M.get_subscript (| M.get_name (| globals, "ommers_hashes" |), M.get_name (| globals, "ommer_index" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1306,11 +1436,13 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_age := + let _ := M.assign_local (| + "ommer_age" , BinOp.sub (| M.get_field (| M.get_name (| globals, "block_header" |), "number" |), M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1388,7 +1520,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := ommers : List of ommers mentioned in the current block. " in - let miner_reward := + let _ := M.assign_local (| + "miner_reward" , BinOp.add (| M.get_name (| globals, "BLOCK_REWARD" |), BinOp.mult (| @@ -1404,7 +1537,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := Constant.int 32 |) |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "create_ether" |), make_list [ @@ -1419,7 +1553,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := M.get_name (| globals, "ommer" |), M.get_name (| globals, "ommers" |), ltac:(M.monadic ( - let ommer_age := + let _ := M.assign_local (| + "ommer_age" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -1429,8 +1564,10 @@ Definition pay_rewards : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let ommer_miner_reward := + |) + |) in + let _ := M.assign_local (| + "ommer_miner_reward" , BinOp.floor_div (| BinOp.mult (| BinOp.sub (| @@ -1440,7 +1577,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := M.get_name (| globals, "BLOCK_REWARD" |) |), Constant.int 8 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "create_ether" |), make_list [ @@ -1501,9 +1639,12 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender := - M.get_field (| M.get_name (| globals, "env" |), "origin" |) in - let sender_account := + let _ := M.assign_local (| + "sender" , + M.get_field (| M.get_name (| globals, "env" |), "origin" |) + |) in + let _ := M.assign_local (| + "sender_account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1511,12 +1652,15 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "sender" |) ], make_dict [] - |) in - let gas_fee := + |) + |) in + let _ := M.assign_local (| + "gas_fee" , BinOp.mult (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1557,7 +1701,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let gas := + let _ := M.assign_local (| + "gas" , BinOp.sub (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.call (| @@ -1567,7 +1712,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "increment_nonce" |), make_list [ @@ -1576,11 +1722,13 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_balance_after_gas_fee := + let _ := M.assign_local (| + "sender_balance_after_gas_fee" , BinOp.sub (| M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), M.get_name (| globals, "gas_fee" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -1590,18 +1738,22 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let preaccessed_addresses := + let _ := M.assign_local (| + "preaccessed_addresses" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let preaccessed_storage_keys := + |) + |) in + let _ := M.assign_local (| + "preaccessed_storage_keys" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1656,7 +1808,8 @@ Definition process_transaction : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let message := + let _ := M.assign_local (| + "message" , M.call (| M.get_name (| globals, "prepare_message" |), make_list [ @@ -1668,8 +1821,10 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in - let output := + |) + |) in + let _ := M.assign_local (| + "output" , M.call (| M.get_name (| globals, "process_message_call" |), make_list [ @@ -1677,13 +1832,17 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in - let gas_used := + |) + |) in + let _ := M.assign_local (| + "gas_used" , BinOp.sub (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_field (| M.get_name (| globals, "output" |), "gas_left" |) - |) in - let gas_refund := + |) + |) in + let _ := M.assign_local (| + "gas_refund" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -1694,16 +1853,20 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "output" |), "refund_counter" |) ], make_dict [] - |) in - let gas_refund_amount := + |) + |) in + let _ := M.assign_local (| + "gas_refund_amount" , BinOp.mult (| BinOp.add (| M.get_field (| M.get_name (| globals, "output" |), "gas_left" |), M.get_name (| globals, "gas_refund" |) |), M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) - |) in - let transaction_fee := + |) + |) in + let _ := M.assign_local (| + "transaction_fee" , BinOp.mult (| BinOp.sub (| BinOp.sub (| @@ -1713,13 +1876,17 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "gas_refund" |) |), M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) - |) in - let total_gas_used := + |) + |) in + let _ := M.assign_local (| + "total_gas_used" , BinOp.sub (| M.get_name (| globals, "gas_used" |), M.get_name (| globals, "gas_refund" |) - |) in - let sender_balance_after_refund := + |) + |) in + let _ := M.assign_local (| + "sender_balance_after_refund" , BinOp.add (| M.get_field (| M.call (| M.get_name (| globals, "get_account" |), @@ -1730,7 +1897,8 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |), "balance" |), M.get_name (| globals, "gas_refund_amount" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -1740,7 +1908,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let coinbase_balance_after_mining_fee := + let _ := M.assign_local (| + "coinbase_balance_after_mining_fee" , BinOp.add (| M.get_field (| M.call (| M.get_name (| globals, "get_account" |), @@ -1751,7 +1920,8 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |), "balance" |), M.get_name (| globals, "transaction_fee" |) - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1942,8 +2112,10 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := verified : `ethereum.base_types.Uint` The intrinsic cost of the transaction. " in - let data_cost := - Constant.int 0 in + let _ := M.assign_local (| + "data_cost" , + Constant.int 0 + |) in let _ := M.for_ (| M.get_name (| globals, "byte" |), @@ -1958,15 +2130,19 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let data_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "data_cost", M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let data_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "data_cost", M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -1990,17 +2166,23 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let create_cost := - M.get_name (| globals, "TX_CREATE_COST" |) in + let _ := M.assign_local (| + "create_cost" , + M.get_name (| globals, "TX_CREATE_COST" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let create_cost := - Constant.int 0 in + let _ := M.assign_local (| + "create_cost" , + Constant.int 0 + |) in M.pure Constant.None_ )) |) in - let access_list_cost := - Constant.int 0 in + let _ := M.assign_local (| + "access_list_cost" , + Constant.int 0 + |) in let _ := (* if *) M.if_then_else (| @@ -2019,10 +2201,14 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := make_tuple [ M.get_name (| globals, "_address" |); M.get_name (| globals, "keys" |) ], M.get_field (| M.get_name (| globals, "tx" |), "access_list" |), ltac:(M.monadic ( - let access_list_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "access_list_cost", M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) - M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) in - let access_list_cost := BinOp.add + |) in + let _ := M.assign_op_local (| + BinOp.add, + "access_list_cost", BinOp.mult (| M.call (| M.get_name (| globals, "len" |), @@ -2033,16 +2219,7 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) |) - BinOp.mult (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "keys" |) - ], - make_dict [] - |), - M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) - |) in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -2156,8 +2333,10 @@ Definition recover_sender : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let v := - M.get_field (| M.get_name (| globals, "tx" |), "v" |) in + let _ := M.assign_local (| + "v" , + M.get_field (| M.get_name (| globals, "tx" |), "v" |) + |) in let _ := (* if *) M.if_then_else (| @@ -2175,7 +2354,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let public_key := + let _ := M.assign_local (| + "public_key" , M.call (| M.get_name (| globals, "secp256k1_recover" |), make_list [ @@ -2194,7 +2374,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -2229,7 +2410,8 @@ Definition recover_sender : Value.t -> Value.t -> M := ], make_dict [] |) in - let public_key := + let _ := M.assign_local (| + "public_key" , M.call (| M.get_name (| globals, "secp256k1_recover" |), make_list [ @@ -2255,7 +2437,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -2274,7 +2457,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let public_key := + let _ := M.assign_local (| + "public_key" , M.call (| M.get_name (| globals, "secp256k1_recover" |), make_list [ @@ -2290,7 +2474,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -2517,11 +2702,13 @@ Definition check_gas_limit : Value.t -> Value.t -> M := check : `bool` True if gas limit constraints are satisfied, False otherwise. " in - let max_adjustment_delta := + let _ := M.assign_local (| + "max_adjustment_delta" , BinOp.floor_div (| M.get_name (| globals, "parent_gas_limit" |), M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -2625,7 +2812,8 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := difficulty : `ethereum.base_types.Uint` Computed difficulty for a block. " in - let offset := + let _ := M.assign_local (| + "offset" , BinOp.mult (| BinOp.floor_div (| M.call (| @@ -2669,8 +2857,10 @@ Constant.int 1 ], make_dict [] |) - |) in - let difficulty := + |) + |) in + let _ := M.assign_local (| + "difficulty" , BinOp.add (| M.call (| M.get_name (| globals, "int" |), @@ -2680,8 +2870,10 @@ Constant.int 1 make_dict [] |), M.get_name (| globals, "offset" |) - |) in - let num_bomb_periods := + |) + |) in + let _ := M.assign_local (| + "num_bomb_periods" , BinOp.sub (| BinOp.floor_div (| BinOp.sub (| @@ -2697,7 +2889,8 @@ Constant.int 1 Constant.int 100000 |), Constant.int 2 - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -2707,15 +2900,14 @@ Constant.int 1 |), (* then *) ltac:(M.monadic ( - let difficulty := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "difficulty", BinOp.pow (| Constant.int 2, M.get_name (| globals, "num_bomb_periods" |) |) - BinOp.pow (| - Constant.int 2, - M.get_name (| globals, "num_bomb_periods" |) - |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/berlin/fork_types.v b/CoqOfPython/ethereum/berlin/fork_types.v index d7e9e4d..3502e2f 100644 --- a/CoqOfPython/ethereum/berlin/fork_types.v +++ b/CoqOfPython/ethereum/berlin/fork_types.v @@ -17,17 +17,29 @@ Introduction Types re-used throughout the specification, which are specific to Ethereum. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes20"; "Bytes256"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes20 : + IsImported globals "ethereum.base_types" "Bytes20". +Axiom ethereum_base_types_imports_Bytes256 : + IsImported globals "ethereum.base_types" "Bytes256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) diff --git a/CoqOfPython/ethereum/berlin/state.v b/CoqOfPython/ethereum/berlin/state.v index ce7be41..58d88b0 100644 --- a/CoqOfPython/ethereum/berlin/state.v +++ b/CoqOfPython/ethereum/berlin/state.v @@ -22,23 +22,57 @@ There is a distinction between an account that does not exist and `EMPTY_ACCOUNT`. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass"; "field" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict"; "List"; "Optional"; "Set"; "Tuple" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "modify" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_berlin_fork_types_imports : - AreImported globals "ethereum.berlin.fork_types" [ "EMPTY_ACCOUNT"; "Account"; "Address"; "Root" ]. - -Axiom ethereum_berlin_trie_imports : - AreImported globals "ethereum.berlin.trie" [ "EMPTY_TRIE_ROOT"; "Trie"; "copy_trie"; "root"; "trie_get"; "trie_set" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". +Axiom dataclasses_imports_field : + IsImported globals "dataclasses" "field". + +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_modify : + IsImported globals "ethereum.base_types" "modify". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_berlin_fork_types_imports_EMPTY_ACCOUNT : + IsImported globals "ethereum.berlin.fork_types" "EMPTY_ACCOUNT". +Axiom ethereum_berlin_fork_types_imports_Account : + IsImported globals "ethereum.berlin.fork_types" "Account". +Axiom ethereum_berlin_fork_types_imports_Address : + IsImported globals "ethereum.berlin.fork_types" "Address". +Axiom ethereum_berlin_fork_types_imports_Root : + IsImported globals "ethereum.berlin.fork_types" "Root". + +Axiom ethereum_berlin_trie_imports_EMPTY_TRIE_ROOT : + IsImported globals "ethereum.berlin.trie" "EMPTY_TRIE_ROOT". +Axiom ethereum_berlin_trie_imports_Trie : + IsImported globals "ethereum.berlin.trie" "Trie". +Axiom ethereum_berlin_trie_imports_copy_trie : + IsImported globals "ethereum.berlin.trie" "copy_trie". +Axiom ethereum_berlin_trie_imports_root : + IsImported globals "ethereum.berlin.trie" "root". +Axiom ethereum_berlin_trie_imports_trie_get : + IsImported globals "ethereum.berlin.trie" "trie_get". +Axiom ethereum_berlin_trie_imports_trie_set : + IsImported globals "ethereum.berlin.trie" "trie_set". Definition State : Value.t := builtins.make_klass @@ -186,7 +220,8 @@ Definition get_account : Value.t -> Value.t -> M := account : `Account` Account at address. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account_optional" |), make_list [ @@ -194,7 +229,8 @@ Definition get_account : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -240,7 +276,8 @@ Definition get_account_optional : Value.t -> Value.t -> M := account : `Account` Account at address. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "trie_get" |), make_list [ @@ -248,7 +285,8 @@ Definition get_account_optional : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "account" |) |) in @@ -399,14 +437,16 @@ Definition get_storage : Value.t -> Value.t -> M := value : `U256` Value at the key. " in - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -430,7 +470,8 @@ Definition get_storage : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "trie_get" |), make_list [ @@ -438,7 +479,8 @@ Definition get_storage : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -481,14 +523,16 @@ Definition set_storage : Value.t -> Value.t -> M := |), Constant.None_ |) |) in - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -498,12 +542,14 @@ Definition set_storage : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_name (| globals, "Trie" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), @@ -530,7 +576,7 @@ Definition set_storage : Value.t -> Value.t -> M := M.if_then_else (| Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), - {} + Constant.str "(* At expr: unsupported node type: Dict *)" |), (* then *) ltac:(M.monadic ( @@ -676,7 +722,8 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := True if if an account has non zero nonce or non empty code, False otherwise. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -684,7 +731,8 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| BoolOp.or (| Compare.not_eq (| @@ -726,7 +774,8 @@ Definition is_account_empty : Value.t -> Value.t -> M := True if if an account has zero nonce, empty code and zero balance, False otherwise. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -734,7 +783,8 @@ Definition is_account_empty : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| BoolOp.and (| Compare.eq (| @@ -785,7 +835,8 @@ Definition account_exists_and_is_empty : Value.t -> Value.t -> M := True if an account exists and has zero nonce, empty code and zero balance, False otherwise. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account_optional" |), make_list [ @@ -793,7 +844,8 @@ Definition account_exists_and_is_empty : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| BoolOp.and (| Compare.is_not (| @@ -850,7 +902,8 @@ Definition is_account_alive : Value.t -> Value.t -> M := is_alive : `bool` True if the account is alive. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account_optional" |), make_list [ @@ -858,7 +911,8 @@ Definition is_account_alive : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1166,14 +1220,16 @@ Definition get_storage_original : Value.t -> Value.t -> M := Constant.int 0 |) |) in - let original_account_trie := + let _ := M.assign_local (| + "original_account_trie" , M.call (| M.get_field (| M.get_name (| globals, "original_trie" |), "get" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1183,18 +1239,21 @@ Definition get_storage_original : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let original_value := + let _ := M.assign_local (| + "original_value" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let original_value := + let _ := M.assign_local (| + "original_value" , M.call (| M.get_name (| globals, "trie_get" |), make_list [ @@ -1202,7 +1261,8 @@ Definition get_storage_original : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.assert (| M.call (| diff --git a/CoqOfPython/ethereum/berlin/transactions.v b/CoqOfPython/ethereum/berlin/transactions.v index 3671146..bafffab 100644 --- a/CoqOfPython/ethereum/berlin/transactions.v +++ b/CoqOfPython/ethereum/berlin/transactions.v @@ -9,26 +9,40 @@ submitted to be executed. If Ethereum is viewed as a state machine, transactions are the events that move between states. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Tuple"; "Union" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U64"; "U256"; "Bytes"; "Bytes0"; "Bytes32"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_exceptions_imports : - AreImported globals "ethereum.exceptions" [ "InvalidBlock" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_berlin_fork_types_imports : - AreImported globals "ethereum.berlin.fork_types" [ "Address" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U64 : + IsImported globals "ethereum.base_types" "U64". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_exceptions_imports_InvalidBlock : + IsImported globals "ethereum.exceptions" "InvalidBlock". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_berlin_fork_types_imports_Address : + IsImported globals "ethereum.berlin.fork_types" "Address". Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( Constant.int 21000 diff --git a/CoqOfPython/ethereum/berlin/trie.v b/CoqOfPython/ethereum/berlin/trie.v index 55618f0..9dbed51 100644 --- a/CoqOfPython/ethereum/berlin/trie.v +++ b/CoqOfPython/ethereum/berlin/trie.v @@ -20,38 +20,72 @@ The state trie is the structure responsible for storing (* At top_level_stmt: unsupported node type: Import *) -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass"; "field" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict"; "Generic"; "List"; "Mapping"; "MutableMapping"; "Optional"; "Sequence"; "TypeVar"; "Union"; "cast" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. - -Axiom ethereum_muir_glacier_imports : - AreImported globals "ethereum.muir_glacier" [ "trie" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_utils_hexadecimal_imports : - AreImported globals "ethereum.utils.hexadecimal" [ "hex_to_bytes" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_berlin_blocks_imports : - AreImported globals "ethereum.berlin.blocks" [ "Receipt" ]. - -Axiom ethereum_berlin_fork_types_imports : - AreImported globals "ethereum.berlin.fork_types" [ "Account"; "Address"; "Root"; "encode_account" ]. - -Axiom ethereum_berlin_transactions_imports : - AreImported globals "ethereum.berlin.transactions" [ "LegacyTransaction" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". +Axiom dataclasses_imports_field : + IsImported globals "dataclasses" "field". + +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". +Axiom typing_imports_Generic : + IsImported globals "typing" "Generic". +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Mapping : + IsImported globals "typing" "Mapping". +Axiom typing_imports_MutableMapping : + IsImported globals "typing" "MutableMapping". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Sequence : + IsImported globals "typing" "Sequence". +Axiom typing_imports_TypeVar : + IsImported globals "typing" "TypeVar". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". +Axiom typing_imports_cast : + IsImported globals "typing" "cast". + +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". + +Axiom ethereum_muir_glacier_imports_trie : + IsImported globals "ethereum.muir_glacier" "trie". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_utils_hexadecimal_imports_hex_to_bytes : + IsImported globals "ethereum.utils.hexadecimal" "hex_to_bytes". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_berlin_blocks_imports_Receipt : + IsImported globals "ethereum.berlin.blocks" "Receipt". + +Axiom ethereum_berlin_fork_types_imports_Account : + IsImported globals "ethereum.berlin.fork_types" "Account". +Axiom ethereum_berlin_fork_types_imports_Address : + IsImported globals "ethereum.berlin.fork_types" "Address". +Axiom ethereum_berlin_fork_types_imports_Root : + IsImported globals "ethereum.berlin.fork_types" "Root". +Axiom ethereum_berlin_fork_types_imports_encode_account : + IsImported globals "ethereum.berlin.fork_types" "encode_account". + +Axiom ethereum_berlin_transactions_imports_LegacyTransaction : + IsImported globals "ethereum.berlin.transactions" "LegacyTransaction". Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -167,7 +201,7 @@ Definition encode_internal_node : Value.t -> Value.t -> M := when serialized. This function also accepts `None`, representing the absence of a node, - which is encoded to `b""""""`. + which is encoded to `b""""`. Parameters ---------- @@ -189,8 +223,10 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := - Constant.bytes "" in + let _ := M.assign_local (| + "unencoded" , + Constant.bytes "" + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -207,7 +243,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := + let _ := M.assign_local (| + "unencoded" , make_tuple [ M.call (| M.get_name (| globals, "nibble_list_to_compact" |), make_list [ @@ -215,7 +252,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := Constant.bool true ], make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in + |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -232,7 +270,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := + let _ := M.assign_local (| + "unencoded" , make_tuple [ M.call (| M.get_name (| globals, "nibble_list_to_compact" |), make_list [ @@ -240,7 +279,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := Constant.bool false ], make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in + |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -257,13 +297,15 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := + let _ := M.assign_local (| + "unencoded" , BinOp.add (| M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), make_list [ M.get_field (| M.get_name (| globals, "node" |), "value" |) ] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -282,14 +324,16 @@ Definition encode_internal_node : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - let encoded := + let _ := M.assign_local (| + "encoded" , M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), make_list [ M.get_name (| globals, "unencoded" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -681,12 +725,14 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := compressed : `bytearray` Compact byte array. " in - let compact := + let _ := M.assign_local (| + "compact" , M.call (| M.get_name (| globals, "bytearray" |), make_list [], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -866,7 +912,8 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := nibble_list : `Bytes` The `Bytes` in nibble-list format. " in - let nibble_list := + let _ := M.assign_local (| + "nibble_list" , M.call (| M.get_name (| globals, "bytearray" |), make_list [ @@ -882,7 +929,8 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ], @@ -990,15 +1038,18 @@ Definition _prepare_trie : Value.t -> Value.t -> M := M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "Address" |), make_list [ M.get_name (| globals, "preimage" |) ], make_dict [] - |) in - let encoded_value := + |) + |) in + let _ := M.assign_local (| + "encoded_value" , M.call (| M.get_name (| globals, "encode_node" |), make_list [ @@ -1012,18 +1063,21 @@ Definition _prepare_trie : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let encoded_value := + let _ := M.assign_local (| + "encoded_value" , M.call (| M.get_name (| globals, "encode_node" |), make_list [ M.get_name (| globals, "value" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -1044,19 +1098,23 @@ Definition _prepare_trie : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "trie" |), "secured" |), (* then *) ltac:(M.monadic ( - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "preimage" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let key := - M.get_name (| globals, "preimage" |) in + let _ := M.assign_local (| + "key" , + M.get_name (| globals, "preimage" |) + |) in M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -1103,7 +1161,8 @@ Definition root : Value.t -> Value.t -> M := root : `eth1spec.fork_types.Root` MPT root of the underlying key-value pairs. " in - let obj := + let _ := M.assign_local (| + "obj" , M.call (| M.get_name (| globals, "_prepare_trie" |), make_list [ @@ -1111,8 +1170,10 @@ Definition root : Value.t -> Value.t -> M := M.get_name (| globals, "get_storage_root" |) ], make_dict [] - |) in - let root_node := + |) + |) in + let _ := M.assign_local (| + "root_node" , M.call (| M.get_name (| globals, "encode_internal_node" |), make_list [ @@ -1132,7 +1193,8 @@ Definition root : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1237,7 +1299,8 @@ Definition patricialize : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let arbitrary_key := + let _ := M.assign_local (| + "arbitrary_key" , M.call (| M.get_name (| globals, "next" |), make_list [ @@ -1250,7 +1313,8 @@ Definition patricialize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1266,7 +1330,8 @@ Definition patricialize : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let leaf := + let _ := M.assign_local (| + "leaf" , M.call (| M.get_name (| globals, "LeafNode" |), make_list [ @@ -1282,7 +1347,8 @@ Definition patricialize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "leaf" |) |) in @@ -1291,27 +1357,32 @@ Definition patricialize : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let substring := + let _ := M.assign_local (| + "substring" , M.slice (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |), Constant.None_, Constant.None_ - |) in - let prefix_length := + |) + |) in + let _ := M.assign_local (| + "prefix_length" , M.call (| M.get_name (| globals, "len" |), make_list [ M.get_name (| globals, "substring" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "key" |), M.get_name (| globals, "obj" |), ltac:(M.monadic ( - let prefix_length := + let _ := M.assign_local (| + "prefix_length" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -1331,7 +1402,8 @@ Definition patricialize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1362,7 +1434,8 @@ Definition patricialize : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let prefix := + let _ := M.assign_local (| + "prefix" , M.slice (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |), @@ -1371,7 +1444,8 @@ Definition patricialize : Value.t -> Value.t -> M := M.get_name (| globals, "prefix_length" |) |), Constant.None_ - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ExtensionNode" |), @@ -1418,7 +1492,7 @@ Definition patricialize : Value.t -> Value.t -> M := let _ := M.call (| M.get_field (| M.get_name (| globals, "branches" |), "append" |), make_list [ - {} + Constant.str "(* At expr: unsupported node type: Dict *)" ], make_dict [] |) in @@ -1428,8 +1502,10 @@ Definition patricialize : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let value := - Constant.bytes "" in + let _ := M.assign_local (| + "value" , + Constant.bytes "" + |) in let _ := M.for_ (| M.get_name (| globals, "key" |), @@ -1472,11 +1548,13 @@ Definition patricialize : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let value := + let _ := M.assign_local (| + "value" , M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/berlin/utils/address.v b/CoqOfPython/ethereum/berlin/utils/address.v index d42cde7..dd8319d 100644 --- a/CoqOfPython/ethereum/berlin/utils/address.v +++ b/CoqOfPython/ethereum/berlin/utils/address.v @@ -18,23 +18,27 @@ Address specific functions used in this berlin version of specification. ". -Axiom typing_imports : - AreImported globals "typing" [ "Union" ]. +Axiom typing_imports_Union : + IsImported globals "typing" "Union". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes32"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_left_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "left_pad_zero_bytes". -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". -Axiom ethereum_berlin_fork_types_imports : - AreImported globals "ethereum.berlin.fork_types" [ "Address" ]. +Axiom ethereum_berlin_fork_types_imports_Address : + IsImported globals "ethereum.berlin.fork_types" "Address". Definition to_address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -91,7 +95,8 @@ Definition compute_contract_address : Value.t -> Value.t -> M := address: `Address` The computed address of the new account. " in - let computed_address := + let _ := M.assign_local (| + "computed_address" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -107,15 +112,19 @@ Definition compute_contract_address : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let canonical_address := + |) + |) in + let _ := M.assign_local (| + "canonical_address" , M.slice (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |), Constant.None_, Constant.None_ - |) in - let padded_address := + |) + |) in + let _ := M.assign_local (| + "padded_address" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -123,7 +132,8 @@ Definition compute_contract_address : Value.t -> Value.t -> M := Constant.int 20 ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Address" |), @@ -156,7 +166,8 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := address: `ethereum.berlin.fork_types.Address` The computed address of the new account. " in - let preimage := + let _ := M.assign_local (| + "preimage" , BinOp.add (| BinOp.add (| BinOp.add (| @@ -172,23 +183,29 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in - let computed_address := + |) + |) in + let _ := M.assign_local (| + "computed_address" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "preimage" |) ], make_dict [] - |) in - let canonical_address := + |) + |) in + let _ := M.assign_local (| + "canonical_address" , M.slice (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |), Constant.None_, Constant.None_ - |) in - let padded_address := + |) + |) in + let _ := M.assign_local (| + "padded_address" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -196,7 +213,8 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := Constant.int 20 ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Address" |), diff --git a/CoqOfPython/ethereum/berlin/utils/hexadecimal.v b/CoqOfPython/ethereum/berlin/utils/hexadecimal.v index b713703..4b247b7 100644 --- a/CoqOfPython/ethereum/berlin/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/berlin/utils/hexadecimal.v @@ -18,11 +18,15 @@ Hexadecimal utility functions used in this specification, specific to Berlin types. ". -Axiom ethereum_utils_hexadecimal_imports : - AreImported globals "ethereum.utils.hexadecimal" [ "remove_hex_prefix" ]. - -Axiom ethereum_berlin_fork_types_imports : - AreImported globals "ethereum.berlin.fork_types" [ "Address"; "Bloom"; "Root" ]. +Axiom ethereum_utils_hexadecimal_imports_remove_hex_prefix : + IsImported globals "ethereum.utils.hexadecimal" "remove_hex_prefix". + +Axiom ethereum_berlin_fork_types_imports_Address : + IsImported globals "ethereum.berlin.fork_types" "Address". +Axiom ethereum_berlin_fork_types_imports_Bloom : + IsImported globals "ethereum.berlin.fork_types" "Bloom". +Axiom ethereum_berlin_fork_types_imports_Root : + IsImported globals "ethereum.berlin.fork_types" "Root". Definition hex_to_root : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/berlin/utils/message.v b/CoqOfPython/ethereum/berlin/utils/message.v index 44ab863..6ce9be0 100644 --- a/CoqOfPython/ethereum/berlin/utils/message.v +++ b/CoqOfPython/ethereum/berlin/utils/message.v @@ -18,26 +18,42 @@ Message specific functions used in this berlin version of specification. ". -Axiom typing_imports : - AreImported globals "typing" [ "FrozenSet"; "Optional"; "Tuple"; "Union" ]. +Axiom typing_imports_FrozenSet : + IsImported globals "typing" "FrozenSet". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Bytes32"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_berlin_fork_types_imports : - AreImported globals "ethereum.berlin.fork_types" [ "Address" ]. +Axiom ethereum_berlin_fork_types_imports_Address : + IsImported globals "ethereum.berlin.fork_types" "Address". -Axiom ethereum_berlin_state_imports : - AreImported globals "ethereum.berlin.state" [ "get_account" ]. +Axiom ethereum_berlin_state_imports_get_account : + IsImported globals "ethereum.berlin.state" "get_account". -Axiom ethereum_berlin_vm_imports : - AreImported globals "ethereum.berlin.vm" [ "Environment"; "Message" ]. +Axiom ethereum_berlin_vm_imports_Environment : + IsImported globals "ethereum.berlin.vm" "Environment". +Axiom ethereum_berlin_vm_imports_Message : + IsImported globals "ethereum.berlin.vm" "Message". -Axiom ethereum_berlin_vm_precompiled_contracts_mapping_imports : - AreImported globals "ethereum.berlin.vm.precompiled_contracts.mapping" [ "PRE_COMPILED_CONTRACTS" ]. +Axiom ethereum_berlin_vm_precompiled_contracts_mapping_imports_PRE_COMPILED_CONTRACTS : + IsImported globals "ethereum.berlin.vm.precompiled_contracts.mapping" "PRE_COMPILED_CONTRACTS". -Axiom ethereum_berlin_utils_address_imports : - AreImported globals "ethereum.berlin.utils.address" [ "compute_contract_address" ]. +Axiom ethereum_berlin_utils_address_imports_compute_contract_address : + IsImported globals "ethereum.berlin.utils.address" "compute_contract_address". Definition prepare_message : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -92,7 +108,8 @@ Definition prepare_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let current_target := + let _ := M.assign_local (| + "current_target" , M.call (| M.get_name (| globals, "compute_contract_address" |), make_list [ @@ -116,17 +133,22 @@ Definition prepare_message : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let msg_data := + |) + |) in + let _ := M.assign_local (| + "msg_data" , M.call (| M.get_name (| globals, "Bytes" |), make_list [ Constant.bytes "" ], make_dict [] - |) in - let code := - M.get_name (| globals, "data" |) in + |) + |) in + let _ := M.assign_local (| + "code" , + M.get_name (| globals, "data" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -143,11 +165,16 @@ Definition prepare_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let current_target := - M.get_name (| globals, "target" |) in - let msg_data := - M.get_name (| globals, "data" |) in - let code := + let _ := M.assign_local (| + "current_target" , + M.get_name (| globals, "target" |) + |) in + let _ := M.assign_local (| + "msg_data" , + M.get_name (| globals, "data" |) + |) in + let _ := M.assign_local (| + "code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -155,7 +182,8 @@ Definition prepare_message : Value.t -> Value.t -> M := M.get_name (| globals, "target" |) ], make_dict [] - |), "code" |) in + |), "code" |) + |) in let _ := (* if *) M.if_then_else (| @@ -165,8 +193,10 @@ Definition prepare_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let code_address := - M.get_name (| globals, "target" |) in + let _ := M.assign_local (| + "code_address" , + M.get_name (| globals, "target" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -186,12 +216,14 @@ Definition prepare_message : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - let accessed_addresses := + let _ := M.assign_local (| + "accessed_addresses" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "accessed_addresses" |), "add" |), make_list [ diff --git a/CoqOfPython/ethereum/berlin/vm/__init__.v b/CoqOfPython/ethereum/berlin/vm/__init__.v index a846849..fcd61d5 100644 --- a/CoqOfPython/ethereum/berlin/vm/__init__.v +++ b/CoqOfPython/ethereum/berlin/vm/__init__.v @@ -18,29 +18,49 @@ The abstract computer which runs the code stored in an `.fork_types.Account`. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple"; "Union" ]. +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U64"; "U256"; "Bytes"; "Bytes0"; "Bytes32"; "Uint" ]. +Axiom ethereum_base_types_imports_U64 : + IsImported globals "ethereum.base_types" "U64". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". -Axiom ethereum_berlin_blocks_imports : - AreImported globals "ethereum.berlin.blocks" [ "Log" ]. +Axiom ethereum_berlin_blocks_imports_Log : + IsImported globals "ethereum.berlin.blocks" "Log". -Axiom ethereum_berlin_fork_types_imports : - AreImported globals "ethereum.berlin.fork_types" [ "Address" ]. +Axiom ethereum_berlin_fork_types_imports_Address : + IsImported globals "ethereum.berlin.fork_types" "Address". -Axiom ethereum_berlin_state_imports : - AreImported globals "ethereum.berlin.state" [ "State"; "account_exists_and_is_empty" ]. +Axiom ethereum_berlin_state_imports_State : + IsImported globals "ethereum.berlin.state" "State". +Axiom ethereum_berlin_state_imports_account_exists_and_is_empty : + IsImported globals "ethereum.berlin.state" "account_exists_and_is_empty". -Axiom ethereum_berlin_vm_precompiled_contracts_imports : - AreImported globals "ethereum.berlin.vm.precompiled_contracts" [ "RIPEMD160_ADDRESS" ]. +Axiom ethereum_berlin_vm_precompiled_contracts_imports_RIPEMD160_ADDRESS : + IsImported globals "ethereum.berlin.vm.precompiled_contracts" "RIPEMD160_ADDRESS". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] diff --git a/CoqOfPython/ethereum/berlin/vm/exceptions.v b/CoqOfPython/ethereum/berlin/vm/exceptions.v index 63d8cdd..20acb2f 100644 --- a/CoqOfPython/ethereum/berlin/vm/exceptions.v +++ b/CoqOfPython/ethereum/berlin/vm/exceptions.v @@ -17,8 +17,8 @@ Introduction Exceptions which cause the EVM to halt exceptionally. ". -Axiom ethereum_exceptions_imports : - AreImported globals "ethereum.exceptions" [ "EthereumException" ]. +Axiom ethereum_exceptions_imports_EthereumException : + IsImported globals "ethereum.exceptions" "EthereumException". Definition ExceptionalHalt : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/berlin/vm/gas.v b/CoqOfPython/ethereum/berlin/vm/gas.v index bbc5275..febe9f3 100644 --- a/CoqOfPython/ethereum/berlin/vm/gas.v +++ b/CoqOfPython/ethereum/berlin/vm/gas.v @@ -17,26 +17,32 @@ Introduction EVM gas constants and calculators. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Tuple" ]. +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_trace_imports : - AreImported globals "ethereum.trace" [ "GasAndRefund"; "evm_trace" ]. +Axiom ethereum_trace_imports_GasAndRefund : + IsImported globals "ethereum.trace" "GasAndRefund". +Axiom ethereum_trace_imports_evm_trace : + IsImported globals "ethereum.trace" "evm_trace". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_berlin_vm_imports : - AreImported globals "ethereum.berlin.vm" [ "Evm" ]. +Axiom ethereum_berlin_vm_imports_Evm : + IsImported globals "ethereum.berlin.vm" "Evm". -Axiom ethereum_berlin_vm_exceptions_imports : - AreImported globals "ethereum.berlin.vm.exceptions" [ "OutOfGasError" ]. +Axiom ethereum_berlin_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.berlin.vm.exceptions" "OutOfGasError". Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -542,7 +548,8 @@ Definition calculate_memory_gas_cost : Value.t -> Value.t -> M := total_gas_cost : `ethereum.base_types.Uint` The gas cost for storing data in memory. " in - let size_in_words := + let _ := M.assign_local (| + "size_in_words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -552,25 +559,32 @@ Definition calculate_memory_gas_cost : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let linear_cost := + |) + |) in + let _ := M.assign_local (| + "linear_cost" , BinOp.mult (| M.get_name (| globals, "size_in_words" |), M.get_name (| globals, "GAS_MEMORY" |) - |) in - let quadratic_cost := + |) + |) in + let _ := M.assign_local (| + "quadratic_cost" , BinOp.floor_div (| BinOp.pow (| M.get_name (| globals, "size_in_words" |), Constant.int 2 |), Constant.int 512 - |) in - let total_gas_cost := + |) + |) in + let _ := M.assign_local (| + "total_gas_cost" , BinOp.add (| M.get_name (| globals, "linear_cost" |), M.get_name (| globals, "quadratic_cost" |) - |) in + |) + |) in (* At stmt: unsupported node type: Try *) M.pure Constant.None_)). @@ -592,23 +606,28 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := ------- extend_memory: `ExtendMemory` " in - let size_to_extend := + let _ := M.assign_local (| + "size_to_extend" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in - let to_be_paid := + |) + |) in + let _ := M.assign_local (| + "to_be_paid" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in - let current_size := + |) + |) in + let _ := M.assign_local (| + "current_size" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -621,7 +640,8 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ], @@ -642,15 +662,18 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let before_size := + let _ := M.assign_local (| + "before_size" , M.call (| M.get_name (| globals, "ceil32" |), make_list [ M.get_name (| globals, "current_size" |) ], make_dict [] - |) in - let after_size := + |) + |) in + let _ := M.assign_local (| + "after_size" , M.call (| M.get_name (| globals, "ceil32" |), make_list [ @@ -672,7 +695,8 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -688,42 +712,46 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let size_to_extend := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "size_to_extend", BinOp.sub (| M.get_name (| globals, "after_size" |), M.get_name (| globals, "before_size" |) |) - BinOp.sub (| - M.get_name (| globals, "after_size" |), - M.get_name (| globals, "before_size" |) - |) in - let already_paid := + |) in + let _ := M.assign_local (| + "already_paid" , M.call (| M.get_name (| globals, "calculate_memory_gas_cost" |), make_list [ M.get_name (| globals, "before_size" |) ], make_dict [] - |) in - let total_cost := + |) + |) in + let _ := M.assign_local (| + "total_cost" , M.call (| M.get_name (| globals, "calculate_memory_gas_cost" |), make_list [ M.get_name (| globals, "after_size" |) ], make_dict [] - |) in - let to_be_paid := BinOp.add + |) + |) in + let _ := M.assign_op_local (| + BinOp.add, + "to_be_paid", BinOp.sub (| M.get_name (| globals, "total_cost" |), M.get_name (| globals, "already_paid" |) |) - BinOp.sub (| - M.get_name (| globals, "total_cost" |), - M.get_name (| globals, "already_paid" |) - |) in - let current_size := - M.get_name (| globals, "after_size" |) in + |) in + let _ := M.assign_local (| + "current_size" , + M.get_name (| globals, "after_size" |) + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -770,7 +798,8 @@ Definition calculate_message_call_gas : Value.t -> Value.t -> M := ------- message_call_gas: `MessageCallGas` " in - let call_stipend := + let _ := M.assign_local (| + "call_stipend" , (* if *) M.if_then_else (| Compare.eq (| @@ -789,7 +818,8 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "call_stipend" |) - )) |) in + )) |) + |) in let _ := (* if *) M.if_then_else (| @@ -823,7 +853,8 @@ M.get_name (| globals, "call_stipend" |) )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -843,7 +874,8 @@ M.get_name (| globals, "call_stipend" |) |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "MessageCallGas" |), diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/__init__.v b/CoqOfPython/ethereum/berlin/vm/instructions/__init__.v index c077623..0eae3b0 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/__init__.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/__init__.v @@ -20,44 +20,46 @@ implementations. (* At top_level_stmt: unsupported node type: Import *) -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict" ]. +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". -Axiom ethereum_berlin_vm_instructions_imports : - AreImported globals "ethereum.berlin.vm.instructions" [ "arithmetic" ]. +Axiom ethereum_berlin_vm_instructions_imports_arithmetic : + IsImported globals "ethereum.berlin.vm.instructions" "arithmetic". -Axiom ethereum_berlin_vm_instructions_imports : - AreImported globals "ethereum.berlin.vm.instructions" [ "bitwise" ]. +Axiom ethereum_berlin_vm_instructions_imports_bitwise : + IsImported globals "ethereum.berlin.vm.instructions" "bitwise". -Axiom ethereum_berlin_vm_instructions_imports : - AreImported globals "ethereum.berlin.vm.instructions" [ "block" ]. +Axiom ethereum_berlin_vm_instructions_imports_block : + IsImported globals "ethereum.berlin.vm.instructions" "block". -Axiom ethereum_berlin_vm_instructions_imports : - AreImported globals "ethereum.berlin.vm.instructions" [ "comparison" ]. +Axiom ethereum_berlin_vm_instructions_imports_comparison : + IsImported globals "ethereum.berlin.vm.instructions" "comparison". -Axiom ethereum_berlin_vm_instructions_imports : - AreImported globals "ethereum.berlin.vm.instructions" [ "control_flow" ]. +Axiom ethereum_berlin_vm_instructions_imports_control_flow : + IsImported globals "ethereum.berlin.vm.instructions" "control_flow". -Axiom ethereum_berlin_vm_instructions_imports : - AreImported globals "ethereum.berlin.vm.instructions" [ "environment" ]. +Axiom ethereum_berlin_vm_instructions_imports_environment : + IsImported globals "ethereum.berlin.vm.instructions" "environment". -Axiom ethereum_berlin_vm_instructions_imports : - AreImported globals "ethereum.berlin.vm.instructions" [ "keccak" ]. +Axiom ethereum_berlin_vm_instructions_imports_keccak : + IsImported globals "ethereum.berlin.vm.instructions" "keccak". -Axiom ethereum_berlin_vm_instructions_imports : - AreImported globals "ethereum.berlin.vm.instructions" [ "log" ]. +Axiom ethereum_berlin_vm_instructions_imports_log : + IsImported globals "ethereum.berlin.vm.instructions" "log". -Axiom ethereum_berlin_vm_instructions_imports : - AreImported globals "ethereum.berlin.vm.instructions" [ "memory" ]. +Axiom ethereum_berlin_vm_instructions_imports_memory : + IsImported globals "ethereum.berlin.vm.instructions" "memory". -Axiom ethereum_berlin_vm_instructions_imports : - AreImported globals "ethereum.berlin.vm.instructions" [ "stack" ]. +Axiom ethereum_berlin_vm_instructions_imports_stack : + IsImported globals "ethereum.berlin.vm.instructions" "stack". -Axiom ethereum_berlin_vm_instructions_imports : - AreImported globals "ethereum.berlin.vm.instructions" [ "storage" ]. +Axiom ethereum_berlin_vm_instructions_imports_storage : + IsImported globals "ethereum.berlin.vm.instructions" "storage". -Axiom ethereum_berlin_vm_instructions_imports : - AreImported globals "ethereum.berlin.vm.instructions" [ "system" ]. +Axiom ethereum_berlin_vm_instructions_imports_system : + IsImported globals "ethereum.berlin.vm.instructions" "system". Definition Ops : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/berlin/vm/instructions/arithmetic.v index 25123e3..ea8f027 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/arithmetic.v @@ -17,20 +17,38 @@ Introduction Implementations of the EVM Arithmetic instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U255_CEIL_VALUE"; "U256"; "U256_CEIL_VALUE"; "Uint" ]. +Axiom ethereum_base_types_imports_U255_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U255_CEIL_VALUE". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_U256_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U256_CEIL_VALUE". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "get_sign" ]. +Axiom ethereum_utils_numeric_imports_get_sign : + IsImported globals "ethereum.utils.numeric" "get_sign". -Axiom ethereum_berlin_vm_imports : - AreImported globals "ethereum.berlin.vm" [ "Evm" ]. +Axiom ethereum_berlin_vm_imports_Evm : + IsImported globals "ethereum.berlin.vm" "Evm". -Axiom ethereum_berlin_vm_gas_imports : - AreImported globals "ethereum.berlin.vm.gas" [ "GAS_EXPONENTIATION"; "GAS_EXPONENTIATION_PER_BYTE"; "GAS_LOW"; "GAS_MID"; "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_berlin_vm_gas_imports_GAS_EXPONENTIATION : + IsImported globals "ethereum.berlin.vm.gas" "GAS_EXPONENTIATION". +Axiom ethereum_berlin_vm_gas_imports_GAS_EXPONENTIATION_PER_BYTE : + IsImported globals "ethereum.berlin.vm.gas" "GAS_EXPONENTIATION_PER_BYTE". +Axiom ethereum_berlin_vm_gas_imports_GAS_LOW : + IsImported globals "ethereum.berlin.vm.gas" "GAS_LOW". +Axiom ethereum_berlin_vm_gas_imports_GAS_MID : + IsImported globals "ethereum.berlin.vm.gas" "GAS_MID". +Axiom ethereum_berlin_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.berlin.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_berlin_vm_gas_imports_charge_gas : + IsImported globals "ethereum.berlin.vm.gas" "charge_gas". -Axiom ethereum_berlin_vm_stack_imports : - AreImported globals "ethereum.berlin.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_berlin_vm_stack_imports_pop : + IsImported globals "ethereum.berlin.vm.stack" "pop". +Axiom ethereum_berlin_vm_stack_imports_push : + IsImported globals "ethereum.berlin.vm.stack" "push". Definition add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,22 +63,26 @@ Definition add : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -69,14 +91,16 @@ Definition add : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "x" |), "wrapping_add" |), make_list [ M.get_name (| globals, "y" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -105,22 +129,26 @@ Definition sub : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -129,14 +157,16 @@ Definition sub : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "x" |), "wrapping_sub" |), make_list [ M.get_name (| globals, "y" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -165,22 +195,26 @@ Definition mul : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -189,14 +223,16 @@ Definition mul : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "x" |), "wrapping_mul" |), make_list [ M.get_name (| globals, "y" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -225,22 +261,26 @@ Definition div : Value.t -> Value.t -> M := The current EVM frame. " in - let dividend := + let _ := M.assign_local (| + "dividend" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let divisor := + |) + |) in + let _ := M.assign_local (| + "divisor" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -258,22 +298,26 @@ Definition div : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let quotient := + let _ := M.assign_local (| + "quotient" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let quotient := + let _ := M.assign_local (| + "quotient" , BinOp.floor_div (| M.get_name (| globals, "dividend" |), M.get_name (| globals, "divisor" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -304,7 +348,8 @@ Definition sdiv : Value.t -> Value.t -> M := The current EVM frame. " in - let dividend := + let _ := M.assign_local (| + "dividend" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -315,8 +360,10 @@ Definition sdiv : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let divisor := + |) + |) in + let _ := M.assign_local (| + "divisor" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -327,7 +374,8 @@ Definition sdiv : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -345,8 +393,10 @@ Definition sdiv : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let quotient := - Constant.int 0 in + let _ := M.assign_local (| + "quotient" , + Constant.int 0 + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -367,12 +417,15 @@ Definition sdiv : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let quotient := - UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in + let _ := M.assign_local (| + "quotient" , + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let sign := + let _ := M.assign_local (| + "sign" , M.call (| M.get_name (| globals, "get_sign" |), make_list [ @@ -382,8 +435,10 @@ Definition sdiv : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let quotient := + |) + |) in + let _ := M.assign_local (| + "quotient" , BinOp.mult (| M.get_name (| globals, "sign" |), BinOp.floor_div (| @@ -402,7 +457,8 @@ Definition sdiv : Value.t -> Value.t -> M := make_dict [] |) |) - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -428,7 +484,7 @@ Definition sdiv : Value.t -> Value.t -> M := |) in M.pure Constant.None_)). -Definition mod : Value.t -> Value.t -> M := +Definition mod_ : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in let _ := Constant.str " @@ -441,22 +497,26 @@ Definition mod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -474,22 +534,26 @@ Definition mod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let remainder := + let _ := M.assign_local (| + "remainder" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let remainder := + let _ := M.assign_local (| + "remainder" , BinOp.mod_ (| M.get_name (| globals, "x" |), M.get_name (| globals, "y" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -520,7 +584,8 @@ Definition smod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -531,8 +596,10 @@ Definition smod : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -543,7 +610,8 @@ Definition smod : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -561,12 +629,15 @@ Definition smod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let remainder := - Constant.int 0 in + let _ := M.assign_local (| + "remainder" , + Constant.int 0 + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let remainder := + let _ := M.assign_local (| + "remainder" , BinOp.mult (| M.call (| M.get_name (| globals, "get_sign" |), @@ -591,7 +662,8 @@ Definition smod : Value.t -> Value.t -> M := make_dict [] |) |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -628,7 +700,8 @@ Definition addmod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -641,8 +714,10 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -655,8 +730,10 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let z := + |) + |) in + let _ := M.assign_local (| + "z" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -669,7 +746,8 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -687,18 +765,21 @@ Definition addmod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -711,7 +792,8 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -742,7 +824,8 @@ Definition mulmod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -755,8 +838,10 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -769,8 +854,10 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let z := + |) + |) in + let _ := M.assign_local (| + "z" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -783,7 +870,8 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -801,18 +889,21 @@ Definition mulmod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -825,7 +916,8 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -856,7 +948,8 @@ Definition exp : Value.t -> Value.t -> M := The current EVM frame. " in - let base := + let _ := M.assign_local (| + "base" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -869,8 +962,10 @@ Definition exp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exponent := + |) + |) in + let _ := M.assign_local (| + "exponent" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -883,21 +978,26 @@ Definition exp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exponent_bits := + |) + |) in + let _ := M.assign_local (| + "exponent_bits" , M.call (| M.get_field (| M.get_name (| globals, "exponent" |), "bit_length" |), make_list [], make_dict [] - |) in - let exponent_bytes := + |) + |) in + let _ := M.assign_local (| + "exponent_bytes" , BinOp.floor_div (| BinOp.add (| M.get_name (| globals, "exponent_bits" |), Constant.int 7 |), Constant.int 8 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -912,7 +1012,8 @@ Definition exp : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -927,7 +1028,8 @@ Definition exp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -956,22 +1058,26 @@ Definition signextend : Value.t -> Value.t -> M := The current EVM frame. " in - let byte_num := + let _ := M.assign_local (| + "byte_num" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -989,12 +1095,15 @@ Definition signextend : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := - M.get_name (| globals, "value" |) in + let _ := M.assign_local (| + "result" , + M.get_name (| globals, "value" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let value_bytes := + let _ := M.assign_local (| + "value_bytes" , M.call (| M.get_name (| globals, "bytes" |), make_list [ @@ -1005,8 +1114,10 @@ Definition signextend : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let value_bytes := + |) + |) in + let _ := M.assign_local (| + "value_bytes" , M.slice (| M.get_name (| globals, "value_bytes" |), BinOp.sub (| @@ -1021,15 +1132,18 @@ Definition signextend : Value.t -> Value.t -> M := |), Constant.None_, Constant.None_ - |) in - let sign_bit := + |) + |) in + let _ := M.assign_local (| + "sign_bit" , BinOp.r_shift (| M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), Constant.int 7 - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1039,26 +1153,31 @@ Definition signextend : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "value_bytes" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let num_bytes_prepend := + let _ := M.assign_local (| + "num_bytes_prepend" , BinOp.sub (| Constant.int 32, BinOp.add (| M.get_name (| globals, "byte_num" |), Constant.int 1 |) - |) in - let result := + |) + |) in + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -1079,7 +1198,8 @@ Definition signextend : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/bitwise.v b/CoqOfPython/ethereum/berlin/vm/instructions/bitwise.v index 01a7c3e..f18e7c2 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/bitwise.v @@ -17,17 +17,23 @@ Introduction Implementations of the EVM bitwise instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "U256_CEIL_VALUE" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_U256_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U256_CEIL_VALUE". -Axiom ethereum_berlin_vm_imports : - AreImported globals "ethereum.berlin.vm" [ "Evm" ]. +Axiom ethereum_berlin_vm_imports_Evm : + IsImported globals "ethereum.berlin.vm" "Evm". -Axiom ethereum_berlin_vm_gas_imports : - AreImported globals "ethereum.berlin.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_berlin_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.berlin.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_berlin_vm_gas_imports_charge_gas : + IsImported globals "ethereum.berlin.vm.gas" "charge_gas". -Axiom ethereum_berlin_vm_stack_imports : - AreImported globals "ethereum.berlin.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_berlin_vm_stack_imports_pop : + IsImported globals "ethereum.berlin.vm.stack" "pop". +Axiom ethereum_berlin_vm_stack_imports_push : + IsImported globals "ethereum.berlin.vm.stack" "push". Definition bitwise_and : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,22 +48,26 @@ Definition bitwise_and : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -97,22 +107,26 @@ Definition bitwise_or : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -152,22 +166,26 @@ Definition bitwise_xor : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -207,14 +225,16 @@ Definition bitwise_not : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -252,22 +272,26 @@ Definition get_byte : Value.t -> Value.t -> M := The current EVM frame. " in - let byte_index := + let _ := M.assign_local (| + "byte_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let word := + |) + |) in + let _ := M.assign_local (| + "word" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -285,43 +309,53 @@ Definition get_byte : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let extra_bytes_to_right := + let _ := M.assign_local (| + "extra_bytes_to_right" , BinOp.sub (| Constant.int 31, M.get_name (| globals, "byte_index" |) - |) in - let word := + |) + |) in + let _ := M.assign_local (| + "word" , BinOp.r_shift (| M.get_name (| globals, "word" |), BinOp.mult (| M.get_name (| globals, "extra_bytes_to_right" |), Constant.int 8 |) - |) in - let word := + |) + |) in + let _ := M.assign_local (| + "word" , BinOp.bit_and (| M.get_name (| globals, "word" |), Constant.int 255 - |) in - let result := + |) + |) in + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ M.get_name (| globals, "word" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -350,22 +384,26 @@ Definition bitwise_shl : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let shift := + let _ := M.assign_local (| + "shift" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -383,7 +421,8 @@ Definition bitwise_shl : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -396,18 +435,21 @@ Definition bitwise_shl : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -436,22 +478,26 @@ Definition bitwise_shr : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let shift := + let _ := M.assign_local (| + "shift" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -469,22 +515,26 @@ Definition bitwise_shr : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , BinOp.r_shift (| M.get_name (| globals, "value" |), M.get_name (| globals, "shift" |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -513,15 +563,18 @@ Definition bitwise_sar : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let shift := + let _ := M.assign_local (| + "shift" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let signed_value := + |) + |) in + let _ := M.assign_local (| + "signed_value" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -532,7 +585,8 @@ Definition bitwise_sar : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -550,7 +604,8 @@ Definition bitwise_sar : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), make_list [ @@ -560,7 +615,8 @@ Definition bitwise_sar : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -573,19 +629,23 @@ Definition bitwise_sar : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := - M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) in + let _ := M.assign_local (| + "result" , + M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/block.v b/CoqOfPython/ethereum/berlin/vm/instructions/block.v index f835701..055cd5d 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/block.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/block.v @@ -17,17 +17,23 @@ Introduction Implementations of the EVM block instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_berlin_vm_imports : - AreImported globals "ethereum.berlin.vm" [ "Evm" ]. +Axiom ethereum_berlin_vm_imports_Evm : + IsImported globals "ethereum.berlin.vm" "Evm". -Axiom ethereum_berlin_vm_gas_imports : - AreImported globals "ethereum.berlin.vm.gas" [ "GAS_BASE"; "GAS_BLOCK_HASH"; "charge_gas" ]. +Axiom ethereum_berlin_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.berlin.vm.gas" "GAS_BASE". +Axiom ethereum_berlin_vm_gas_imports_GAS_BLOCK_HASH : + IsImported globals "ethereum.berlin.vm.gas" "GAS_BLOCK_HASH". +Axiom ethereum_berlin_vm_gas_imports_charge_gas : + IsImported globals "ethereum.berlin.vm.gas" "charge_gas". -Axiom ethereum_berlin_vm_stack_imports : - AreImported globals "ethereum.berlin.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_berlin_vm_stack_imports_pop : + IsImported globals "ethereum.berlin.vm.stack" "pop". +Axiom ethereum_berlin_vm_stack_imports_push : + IsImported globals "ethereum.berlin.vm.stack" "push". Definition block_hash : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,14 +48,16 @@ Definition block_hash : Value.t -> Value.t -> M := The current EVM frame. " in - let block_number := + let _ := M.assign_local (| + "block_number" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -78,19 +86,23 @@ Definition block_hash : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let hash := - Constant.bytes "00" in + let _ := M.assign_local (| + "hash" , + Constant.bytes "00" + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let hash := + let _ := M.assign_local (| + "hash" , M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), M.get_name (| globals, "block_number" |) |) |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/comparison.v b/CoqOfPython/ethereum/berlin/vm/instructions/comparison.v index bc46aed..6815b65 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/comparison.v @@ -17,17 +17,21 @@ Introduction Implementations of the EVM Comparison instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_berlin_vm_imports : - AreImported globals "ethereum.berlin.vm" [ "Evm" ]. +Axiom ethereum_berlin_vm_imports_Evm : + IsImported globals "ethereum.berlin.vm" "Evm". -Axiom ethereum_berlin_vm_gas_imports : - AreImported globals "ethereum.berlin.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_berlin_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.berlin.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_berlin_vm_gas_imports_charge_gas : + IsImported globals "ethereum.berlin.vm.gas" "charge_gas". -Axiom ethereum_berlin_vm_stack_imports : - AreImported globals "ethereum.berlin.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_berlin_vm_stack_imports_pop : + IsImported globals "ethereum.berlin.vm.stack" "pop". +Axiom ethereum_berlin_vm_stack_imports_push : + IsImported globals "ethereum.berlin.vm.stack" "push". Definition less_than : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,22 +46,26 @@ Definition less_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -66,7 +74,8 @@ Definition less_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -76,7 +85,8 @@ Definition less_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -104,7 +114,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -115,8 +126,10 @@ Definition signed_less_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -127,7 +140,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -136,7 +150,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -146,7 +161,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -175,22 +191,26 @@ Definition greater_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -199,7 +219,8 @@ Definition greater_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -209,7 +230,8 @@ Definition greater_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -237,7 +259,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -248,8 +271,10 @@ Definition signed_greater_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -260,7 +285,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -269,7 +295,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -279,7 +306,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -308,22 +336,26 @@ Definition equal : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -332,7 +364,8 @@ Definition equal : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -342,7 +375,8 @@ Definition equal : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -371,14 +405,16 @@ Definition is_zero : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -387,7 +423,8 @@ Definition is_zero : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -397,7 +434,8 @@ Definition is_zero : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/control_flow.v b/CoqOfPython/ethereum/berlin/vm/instructions/control_flow.v index 3829375..d084bbb 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/control_flow.v @@ -17,20 +17,32 @@ Introduction Implementations of the EVM control flow instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_berlin_vm_gas_imports : - AreImported globals "ethereum.berlin.vm.gas" [ "GAS_BASE"; "GAS_HIGH"; "GAS_JUMPDEST"; "GAS_MID"; "charge_gas" ]. +Axiom ethereum_berlin_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.berlin.vm.gas" "GAS_BASE". +Axiom ethereum_berlin_vm_gas_imports_GAS_HIGH : + IsImported globals "ethereum.berlin.vm.gas" "GAS_HIGH". +Axiom ethereum_berlin_vm_gas_imports_GAS_JUMPDEST : + IsImported globals "ethereum.berlin.vm.gas" "GAS_JUMPDEST". +Axiom ethereum_berlin_vm_gas_imports_GAS_MID : + IsImported globals "ethereum.berlin.vm.gas" "GAS_MID". +Axiom ethereum_berlin_vm_gas_imports_charge_gas : + IsImported globals "ethereum.berlin.vm.gas" "charge_gas". -Axiom ethereum_berlin_vm_imports : - AreImported globals "ethereum.berlin.vm" [ "Evm" ]. +Axiom ethereum_berlin_vm_imports_Evm : + IsImported globals "ethereum.berlin.vm" "Evm". -Axiom ethereum_berlin_vm_exceptions_imports : - AreImported globals "ethereum.berlin.vm.exceptions" [ "InvalidJumpDestError" ]. +Axiom ethereum_berlin_vm_exceptions_imports_InvalidJumpDestError : + IsImported globals "ethereum.berlin.vm.exceptions" "InvalidJumpDestError". -Axiom ethereum_berlin_vm_stack_imports : - AreImported globals "ethereum.berlin.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_berlin_vm_stack_imports_pop : + IsImported globals "ethereum.berlin.vm.stack" "pop". +Axiom ethereum_berlin_vm_stack_imports_push : + IsImported globals "ethereum.berlin.vm.stack" "push". Definition stop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -69,7 +81,8 @@ Definition jump : Value.t -> Value.t -> M := The current EVM frame. " in - let jump_dest := + let _ := M.assign_local (| + "jump_dest" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -82,7 +95,8 @@ Definition jump : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -132,7 +146,8 @@ Definition jumpi : Value.t -> Value.t -> M := The current EVM frame. " in - let jump_dest := + let _ := M.assign_local (| + "jump_dest" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -145,15 +160,18 @@ Definition jumpi : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let conditional_value := + |) + |) in + let _ := M.assign_local (| + "conditional_value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -171,11 +189,13 @@ Definition jumpi : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let destination := + let _ := M.assign_local (| + "destination" , BinOp.add (| M.get_field (| M.get_name (| globals, "evm" |), "pc" |), Constant.int 1 - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -192,8 +212,10 @@ Definition jumpi : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let destination := - M.get_name (| globals, "jump_dest" |) in + let _ := M.assign_local (| + "destination" , + M.get_name (| globals, "jump_dest" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/environment.v b/CoqOfPython/ethereum/berlin/vm/instructions/environment.v index 428b5dc..973b275 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/environment.v @@ -17,41 +17,63 @@ Introduction Implementations of the EVM environment related instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. - -Axiom ethereum_berlin_fork_types_imports : - AreImported globals "ethereum.berlin.fork_types" [ "EMPTY_ACCOUNT" ]. - -Axiom ethereum_berlin_state_imports : - AreImported globals "ethereum.berlin.state" [ "get_account" ]. - -Axiom ethereum_berlin_utils_address_imports : - AreImported globals "ethereum.berlin.utils.address" [ "to_address" ]. - -Axiom ethereum_berlin_vm_memory_imports : - AreImported globals "ethereum.berlin.vm.memory" [ "buffer_read"; "memory_write" ]. - -Axiom ethereum_berlin_vm_imports : - AreImported globals "ethereum.berlin.vm" [ "Evm" ]. - -Axiom ethereum_berlin_vm_exceptions_imports : - AreImported globals "ethereum.berlin.vm.exceptions" [ "OutOfBoundsRead" ]. - -Axiom ethereum_berlin_vm_gas_imports : - AreImported globals "ethereum.berlin.vm.gas" [ "GAS_BASE"; "GAS_COLD_ACCOUNT_ACCESS"; "GAS_COPY"; "GAS_FAST_STEP"; "GAS_RETURN_DATA_COPY"; "GAS_VERY_LOW"; "GAS_WARM_ACCESS"; "calculate_gas_extend_memory"; "charge_gas" ]. - -Axiom ethereum_berlin_vm_stack_imports : - AreImported globals "ethereum.berlin.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". + +Axiom ethereum_berlin_fork_types_imports_EMPTY_ACCOUNT : + IsImported globals "ethereum.berlin.fork_types" "EMPTY_ACCOUNT". + +Axiom ethereum_berlin_state_imports_get_account : + IsImported globals "ethereum.berlin.state" "get_account". + +Axiom ethereum_berlin_utils_address_imports_to_address : + IsImported globals "ethereum.berlin.utils.address" "to_address". + +Axiom ethereum_berlin_vm_memory_imports_buffer_read : + IsImported globals "ethereum.berlin.vm.memory" "buffer_read". +Axiom ethereum_berlin_vm_memory_imports_memory_write : + IsImported globals "ethereum.berlin.vm.memory" "memory_write". + +Axiom ethereum_berlin_vm_imports_Evm : + IsImported globals "ethereum.berlin.vm" "Evm". + +Axiom ethereum_berlin_vm_exceptions_imports_OutOfBoundsRead : + IsImported globals "ethereum.berlin.vm.exceptions" "OutOfBoundsRead". + +Axiom ethereum_berlin_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.berlin.vm.gas" "GAS_BASE". +Axiom ethereum_berlin_vm_gas_imports_GAS_COLD_ACCOUNT_ACCESS : + IsImported globals "ethereum.berlin.vm.gas" "GAS_COLD_ACCOUNT_ACCESS". +Axiom ethereum_berlin_vm_gas_imports_GAS_COPY : + IsImported globals "ethereum.berlin.vm.gas" "GAS_COPY". +Axiom ethereum_berlin_vm_gas_imports_GAS_FAST_STEP : + IsImported globals "ethereum.berlin.vm.gas" "GAS_FAST_STEP". +Axiom ethereum_berlin_vm_gas_imports_GAS_RETURN_DATA_COPY : + IsImported globals "ethereum.berlin.vm.gas" "GAS_RETURN_DATA_COPY". +Axiom ethereum_berlin_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.berlin.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_berlin_vm_gas_imports_GAS_WARM_ACCESS : + IsImported globals "ethereum.berlin.vm.gas" "GAS_WARM_ACCESS". +Axiom ethereum_berlin_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.berlin.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_berlin_vm_gas_imports_charge_gas : + IsImported globals "ethereum.berlin.vm.gas" "charge_gas". + +Axiom ethereum_berlin_vm_stack_imports_pop : + IsImported globals "ethereum.berlin.vm.stack" "pop". +Axiom ethereum_berlin_vm_stack_imports_push : + IsImported globals "ethereum.berlin.vm.stack" "push". Definition address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -107,7 +129,8 @@ Definition balance : Value.t -> Value.t -> M := The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -120,7 +143,8 @@ Definition balance : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -158,7 +182,8 @@ Definition balance : Value.t -> Value.t -> M := |) in M.pure Constant.None_ )) |) in - let balance := + let _ := M.assign_local (| + "balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -166,7 +191,8 @@ Definition balance : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -316,14 +342,16 @@ Definition calldataload : Value.t -> Value.t -> M := The current EVM frame. " in - let start_index := + let _ := M.assign_local (| + "start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -332,7 +360,8 @@ Definition calldataload : Value.t -> Value.t -> M := ], make_dict [] |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -347,7 +376,8 @@ Definition calldataload : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -432,31 +462,38 @@ Definition calldatacopy : Value.t -> Value.t -> M := The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let data_start_index := + |) + |) in + let _ := M.assign_local (| + "data_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -472,13 +509,17 @@ Definition calldatacopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -488,7 +529,8 @@ Definition calldatacopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -511,7 +553,8 @@ Definition calldatacopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -520,7 +563,8 @@ Definition calldatacopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -600,31 +644,38 @@ Definition codecopy : Value.t -> Value.t -> M := The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let code_start_index := + |) + |) in + let _ := M.assign_local (| + "code_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -640,13 +691,17 @@ Definition codecopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -656,7 +711,8 @@ Definition codecopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -679,7 +735,8 @@ Definition codecopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -688,7 +745,8 @@ Definition codecopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -759,7 +817,8 @@ Definition extcodesize : Value.t -> Value.t -> M := The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -772,7 +831,8 @@ Definition extcodesize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -810,7 +870,8 @@ Definition extcodesize : Value.t -> Value.t -> M := |) in M.pure Constant.None_ )) |) in - let codesize := + let _ := M.assign_local (| + "codesize" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -830,7 +891,8 @@ Definition extcodesize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -858,7 +920,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -871,32 +934,40 @@ Definition extcodecopy : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let memory_start_index := + |) + |) in + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let code_start_index := + |) + |) in + let _ := M.assign_local (| + "code_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -912,13 +983,17 @@ Definition extcodecopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -928,7 +1003,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -986,7 +1062,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let code := + let _ := M.assign_local (| + "code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -994,8 +1071,10 @@ Definition extcodecopy : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |), "code" |) in - let value := + |), "code" |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -1004,7 +1083,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -1079,31 +1159,38 @@ Definition returndatacopy : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let return_data_start_position := + |) + |) in + let _ := M.assign_local (| + "return_data_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -1119,13 +1206,17 @@ Definition returndatacopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_RETURN_DATA_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1135,7 +1226,8 @@ Definition returndatacopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1190,7 +1282,8 @@ Definition returndatacopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.slice (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |), @@ -1199,7 +1292,8 @@ Definition returndatacopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) |), Constant.None_ - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -1226,7 +1320,8 @@ Definition extcodehash : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1239,7 +1334,8 @@ Definition extcodehash : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1277,7 +1373,8 @@ Definition extcodehash : Value.t -> Value.t -> M := |) in M.pure Constant.None_ )) |) in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1285,7 +1382,8 @@ Definition extcodehash : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1295,18 +1393,21 @@ Definition extcodehash : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let codehash := + let _ := M.assign_local (| + "codehash" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let codehash := + let _ := M.assign_local (| + "codehash" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -1319,7 +1420,8 @@ Definition extcodehash : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -1358,7 +1460,8 @@ Definition self_balance : Value.t -> Value.t -> M := ], make_dict [] |) in - let balance := + let _ := M.assign_local (| + "balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1366,7 +1469,8 @@ Definition self_balance : Value.t -> Value.t -> M := M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/keccak.v b/CoqOfPython/ethereum/berlin/vm/instructions/keccak.v index 6ff1f5f..3adfdb0 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/keccak.v @@ -17,26 +17,36 @@ Introduction Implementations of the EVM keccak instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_berlin_vm_imports : - AreImported globals "ethereum.berlin.vm" [ "Evm" ]. +Axiom ethereum_berlin_vm_imports_Evm : + IsImported globals "ethereum.berlin.vm" "Evm". -Axiom ethereum_berlin_vm_gas_imports : - AreImported globals "ethereum.berlin.vm.gas" [ "GAS_KECCAK256"; "GAS_KECCAK256_WORD"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_berlin_vm_gas_imports_GAS_KECCAK256 : + IsImported globals "ethereum.berlin.vm.gas" "GAS_KECCAK256". +Axiom ethereum_berlin_vm_gas_imports_GAS_KECCAK256_WORD : + IsImported globals "ethereum.berlin.vm.gas" "GAS_KECCAK256_WORD". +Axiom ethereum_berlin_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.berlin.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_berlin_vm_gas_imports_charge_gas : + IsImported globals "ethereum.berlin.vm.gas" "charge_gas". -Axiom ethereum_berlin_vm_memory_imports : - AreImported globals "ethereum.berlin.vm.memory" [ "memory_read_bytes" ]. +Axiom ethereum_berlin_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.berlin.vm.memory" "memory_read_bytes". -Axiom ethereum_berlin_vm_stack_imports : - AreImported globals "ethereum.berlin.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_berlin_vm_stack_imports_pop : + IsImported globals "ethereum.berlin.vm.stack" "pop". +Axiom ethereum_berlin_vm_stack_imports_push : + IsImported globals "ethereum.berlin.vm.stack" "push". Definition keccak : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -53,23 +63,28 @@ Definition keccak : Value.t -> Value.t -> M := The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -85,13 +100,17 @@ Definition keccak : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let word_gas_cost := + |) + |) in + let _ := M.assign_local (| + "word_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_KECCAK256_WORD" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -101,7 +120,8 @@ Definition keccak : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -124,7 +144,8 @@ Definition keccak : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let data := + let _ := M.assign_local (| + "data" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -133,15 +154,18 @@ Definition keccak : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in - let hash := + |) + |) in + let _ := M.assign_local (| + "hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "data" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/log.v b/CoqOfPython/ethereum/berlin/vm/instructions/log.v index c97a508..3add2f4 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/log.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/log.v @@ -17,32 +17,40 @@ Introduction Implementations of the EVM logging instructions. ". -Axiom functools_imports : - AreImported globals "functools" [ "partial" ]. +Axiom functools_imports_partial : + IsImported globals "functools" "partial". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_berlin_blocks_imports : - AreImported globals "ethereum.berlin.blocks" [ "Log" ]. +Axiom ethereum_berlin_blocks_imports_Log : + IsImported globals "ethereum.berlin.blocks" "Log". -Axiom ethereum_berlin_vm_imports : - AreImported globals "ethereum.berlin.vm" [ "Evm" ]. +Axiom ethereum_berlin_vm_imports_Evm : + IsImported globals "ethereum.berlin.vm" "Evm". -Axiom ethereum_berlin_vm_exceptions_imports : - AreImported globals "ethereum.berlin.vm.exceptions" [ "WriteInStaticContext" ]. +Axiom ethereum_berlin_vm_exceptions_imports_WriteInStaticContext : + IsImported globals "ethereum.berlin.vm.exceptions" "WriteInStaticContext". -Axiom ethereum_berlin_vm_gas_imports : - AreImported globals "ethereum.berlin.vm.gas" [ "GAS_LOG"; "GAS_LOG_DATA"; "GAS_LOG_TOPIC"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_berlin_vm_gas_imports_GAS_LOG : + IsImported globals "ethereum.berlin.vm.gas" "GAS_LOG". +Axiom ethereum_berlin_vm_gas_imports_GAS_LOG_DATA : + IsImported globals "ethereum.berlin.vm.gas" "GAS_LOG_DATA". +Axiom ethereum_berlin_vm_gas_imports_GAS_LOG_TOPIC : + IsImported globals "ethereum.berlin.vm.gas" "GAS_LOG_TOPIC". +Axiom ethereum_berlin_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.berlin.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_berlin_vm_gas_imports_charge_gas : + IsImported globals "ethereum.berlin.vm.gas" "charge_gas". -Axiom ethereum_berlin_vm_memory_imports : - AreImported globals "ethereum.berlin.vm.memory" [ "memory_read_bytes" ]. +Axiom ethereum_berlin_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.berlin.vm.memory" "memory_read_bytes". -Axiom ethereum_berlin_vm_stack_imports : - AreImported globals "ethereum.berlin.vm.stack" [ "pop" ]. +Axiom ethereum_berlin_vm_stack_imports_pop : + IsImported globals "ethereum.berlin.vm.stack" "pop". Definition log_n : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -61,24 +69,30 @@ Definition log_n : Value.t -> Value.t -> M := The number of topics to be included in the log entry. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let topics := - make_list [] in + |) + |) in + let _ := M.assign_local (| + "topics" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "_" |), @@ -90,7 +104,8 @@ Definition log_n : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let topic := + let _ := M.assign_local (| + "topic" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -101,7 +116,8 @@ Definition log_n : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "topics" |), "append" |), make_list [ @@ -115,7 +131,8 @@ Definition log_n : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let extend_memory := + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -125,7 +142,8 @@ Definition log_n : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -165,12 +183,14 @@ Definition log_n : Value.t -> Value.t -> M := ], make_dict [] |) in - let log_entry := + let _ := M.assign_local (| + "log_entry" , M.call (| M.get_name (| globals, "Log" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "logs" |), BinOp.add (| diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/memory.v b/CoqOfPython/ethereum/berlin/vm/instructions/memory.v index 349ccdb..c93d543 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/memory.v @@ -17,20 +17,32 @@ Introduction Implementations of the EVM Memory instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". -Axiom ethereum_berlin_vm_imports : - AreImported globals "ethereum.berlin.vm" [ "Evm" ]. +Axiom ethereum_berlin_vm_imports_Evm : + IsImported globals "ethereum.berlin.vm" "Evm". -Axiom ethereum_berlin_vm_gas_imports : - AreImported globals "ethereum.berlin.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_berlin_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.berlin.vm.gas" "GAS_BASE". +Axiom ethereum_berlin_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.berlin.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_berlin_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.berlin.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_berlin_vm_gas_imports_charge_gas : + IsImported globals "ethereum.berlin.vm.gas" "charge_gas". -Axiom ethereum_berlin_vm_memory_imports : - AreImported globals "ethereum.berlin.vm.memory" [ "memory_read_bytes"; "memory_write" ]. +Axiom ethereum_berlin_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.berlin.vm.memory" "memory_read_bytes". +Axiom ethereum_berlin_vm_memory_imports_memory_write : + IsImported globals "ethereum.berlin.vm.memory" "memory_write". -Axiom ethereum_berlin_vm_stack_imports : - AreImported globals "ethereum.berlin.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_berlin_vm_stack_imports_pop : + IsImported globals "ethereum.berlin.vm.stack" "pop". +Axiom ethereum_berlin_vm_stack_imports_push : + IsImported globals "ethereum.berlin.vm.stack" "push". Definition mstore : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -46,15 +58,18 @@ Definition mstore : Value.t -> Value.t -> M := The current EVM frame. " in - let start_position := + let _ := M.assign_local (| + "start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -65,8 +80,10 @@ Definition mstore : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -88,7 +105,8 @@ Definition mstore : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -138,23 +156,28 @@ Definition mstore8 : Value.t -> Value.t -> M := The current EVM frame. " in - let start_position := + let _ := M.assign_local (| + "start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -170,7 +193,8 @@ Definition mstore8 : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -190,7 +214,8 @@ Definition mstore8 : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let normalized_bytes_value := + let _ := M.assign_local (| + "normalized_bytes_value" , M.call (| M.get_name (| globals, "Bytes" |), make_list [ @@ -202,7 +227,8 @@ Definition mstore8 : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -231,15 +257,18 @@ Definition mload : Value.t -> Value.t -> M := The current EVM frame. " in - let start_position := + let _ := M.assign_local (| + "start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -255,7 +284,8 @@ Definition mload : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -275,7 +305,8 @@ Definition mload : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -296,7 +327,8 @@ Definition mload : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/stack.v b/CoqOfPython/ethereum/berlin/vm/instructions/stack.v index a570734..77860ad 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/stack.v @@ -17,26 +17,32 @@ Introduction Implementations of the EVM stack related instructions. ". -Axiom functools_imports : - AreImported globals "functools" [ "partial" ]. +Axiom functools_imports_partial : + IsImported globals "functools" "partial". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_berlin_vm_imports : - AreImported globals "ethereum.berlin.vm" [ "Evm"; "stack" ]. +Axiom ethereum_berlin_vm_imports_Evm : + IsImported globals "ethereum.berlin.vm" "Evm". +Axiom ethereum_berlin_vm_imports_stack : + IsImported globals "ethereum.berlin.vm" "stack". -Axiom ethereum_berlin_vm_exceptions_imports : - AreImported globals "ethereum.berlin.vm.exceptions" [ "StackUnderflowError" ]. +Axiom ethereum_berlin_vm_exceptions_imports_StackUnderflowError : + IsImported globals "ethereum.berlin.vm.exceptions" "StackUnderflowError". -Axiom ethereum_berlin_vm_gas_imports : - AreImported globals "ethereum.berlin.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_berlin_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.berlin.vm.gas" "GAS_BASE". +Axiom ethereum_berlin_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.berlin.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_berlin_vm_gas_imports_charge_gas : + IsImported globals "ethereum.berlin.vm.gas" "charge_gas". -Axiom ethereum_berlin_vm_memory_imports : - AreImported globals "ethereum.berlin.vm.memory" [ "buffer_read" ]. +Axiom ethereum_berlin_vm_memory_imports_buffer_read : + IsImported globals "ethereum.berlin.vm.memory" "buffer_read". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -98,7 +104,8 @@ Definition push_n : Value.t -> Value.t -> M := ], make_dict [] |) in - let data_to_push := + let _ := M.assign_local (| + "data_to_push" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -128,7 +135,8 @@ Definition push_n : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "stack" |), "push" |), make_list [ @@ -189,7 +197,8 @@ Definition dup_n : Value.t -> Value.t -> M := ], make_dict [] |) in - let data_to_duplicate := + let _ := M.assign_local (| + "data_to_duplicate" , M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| @@ -205,7 +214,8 @@ Definition dup_n : Value.t -> Value.t -> M := |), M.get_name (| globals, "item_number" |) |) - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "stack" |), "push" |), make_list [ diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/storage.v b/CoqOfPython/ethereum/berlin/vm/instructions/storage.v index 0670357..8bf28fd 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/storage.v @@ -17,26 +17,46 @@ Introduction Implementations of the EVM storage related instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_berlin_state_imports : - AreImported globals "ethereum.berlin.state" [ "get_storage"; "get_storage_original"; "set_storage" ]. +Axiom ethereum_berlin_state_imports_get_storage : + IsImported globals "ethereum.berlin.state" "get_storage". +Axiom ethereum_berlin_state_imports_get_storage_original : + IsImported globals "ethereum.berlin.state" "get_storage_original". +Axiom ethereum_berlin_state_imports_set_storage : + IsImported globals "ethereum.berlin.state" "set_storage". -Axiom ethereum_berlin_vm_imports : - AreImported globals "ethereum.berlin.vm" [ "Evm" ]. +Axiom ethereum_berlin_vm_imports_Evm : + IsImported globals "ethereum.berlin.vm" "Evm". -Axiom ethereum_berlin_vm_exceptions_imports : - AreImported globals "ethereum.berlin.vm.exceptions" [ "OutOfGasError"; "WriteInStaticContext" ]. +Axiom ethereum_berlin_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.berlin.vm.exceptions" "OutOfGasError". +Axiom ethereum_berlin_vm_exceptions_imports_WriteInStaticContext : + IsImported globals "ethereum.berlin.vm.exceptions" "WriteInStaticContext". -Axiom ethereum_berlin_vm_gas_imports : - AreImported globals "ethereum.berlin.vm.gas" [ "GAS_CALL_STIPEND"; "GAS_COLD_SLOAD"; "GAS_STORAGE_CLEAR_REFUND"; "GAS_STORAGE_SET"; "GAS_STORAGE_UPDATE"; "GAS_WARM_ACCESS"; "charge_gas" ]. +Axiom ethereum_berlin_vm_gas_imports_GAS_CALL_STIPEND : + IsImported globals "ethereum.berlin.vm.gas" "GAS_CALL_STIPEND". +Axiom ethereum_berlin_vm_gas_imports_GAS_COLD_SLOAD : + IsImported globals "ethereum.berlin.vm.gas" "GAS_COLD_SLOAD". +Axiom ethereum_berlin_vm_gas_imports_GAS_STORAGE_CLEAR_REFUND : + IsImported globals "ethereum.berlin.vm.gas" "GAS_STORAGE_CLEAR_REFUND". +Axiom ethereum_berlin_vm_gas_imports_GAS_STORAGE_SET : + IsImported globals "ethereum.berlin.vm.gas" "GAS_STORAGE_SET". +Axiom ethereum_berlin_vm_gas_imports_GAS_STORAGE_UPDATE : + IsImported globals "ethereum.berlin.vm.gas" "GAS_STORAGE_UPDATE". +Axiom ethereum_berlin_vm_gas_imports_GAS_WARM_ACCESS : + IsImported globals "ethereum.berlin.vm.gas" "GAS_WARM_ACCESS". +Axiom ethereum_berlin_vm_gas_imports_charge_gas : + IsImported globals "ethereum.berlin.vm.gas" "charge_gas". -Axiom ethereum_berlin_vm_stack_imports : - AreImported globals "ethereum.berlin.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_berlin_vm_stack_imports_pop : + IsImported globals "ethereum.berlin.vm.stack" "pop". +Axiom ethereum_berlin_vm_stack_imports_push : + IsImported globals "ethereum.berlin.vm.stack" "push". Definition sload : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -51,7 +71,8 @@ Definition sload : Value.t -> Value.t -> M := The current EVM frame. " in - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -62,7 +83,8 @@ Definition sload : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -100,7 +122,8 @@ Definition sload : Value.t -> Value.t -> M := |) in M.pure Constant.None_ )) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "get_storage" |), make_list [ @@ -109,7 +132,8 @@ Definition sload : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -137,7 +161,8 @@ Definition sstore : Value.t -> Value.t -> M := The current EVM frame. " in - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -148,15 +173,18 @@ Definition sstore : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in - let new_value := + |) + |) in + let _ := M.assign_local (| + "new_value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -168,7 +196,8 @@ Definition sstore : Value.t -> Value.t -> M := ], make_dict [] |) in - let original_value := + let _ := M.assign_local (| + "original_value" , M.call (| M.get_name (| globals, "get_storage_original" |), make_list [ @@ -177,8 +206,10 @@ Definition sstore : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in - let current_value := + |) + |) in + let _ := M.assign_local (| + "current_value" , M.call (| M.get_name (| globals, "get_storage" |), make_list [ @@ -187,15 +218,18 @@ Definition sstore : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in - let gas_cost := + |) + |) in + let _ := M.assign_local (| + "gas_cost" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -212,9 +246,11 @@ Definition sstore : Value.t -> Value.t -> M := ], make_dict [] |) in - let gas_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "gas_cost", M.get_name (| globals, "GAS_COLD_SLOAD" |) - M.get_name (| globals, "GAS_COLD_SLOAD" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -246,29 +282,32 @@ Definition sstore : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let gas_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "gas_cost", M.get_name (| globals, "GAS_STORAGE_SET" |) - M.get_name (| globals, "GAS_STORAGE_SET" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let gas_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "gas_cost", BinOp.sub (| M.get_name (| globals, "GAS_STORAGE_UPDATE" |), M.get_name (| globals, "GAS_COLD_SLOAD" |) |) - BinOp.sub (| - M.get_name (| globals, "GAS_STORAGE_UPDATE" |), - M.get_name (| globals, "GAS_COLD_SLOAD" |) - |) in + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let gas_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "gas_cost", M.get_name (| globals, "GAS_WARM_ACCESS" |) - M.get_name (| globals, "GAS_WARM_ACCESS" |) in + |) in M.pure Constant.None_ )) |) in let _ := diff --git a/CoqOfPython/ethereum/berlin/vm/instructions/system.v b/CoqOfPython/ethereum/berlin/vm/instructions/system.v index c6d9c82..313e0af 100644 --- a/CoqOfPython/ethereum/berlin/vm/instructions/system.v +++ b/CoqOfPython/ethereum/berlin/vm/instructions/system.v @@ -17,38 +17,94 @@ Introduction Implementations of the EVM system related instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_berlin_fork_types_imports : - AreImported globals "ethereum.berlin.fork_types" [ "Address" ]. +Axiom ethereum_berlin_fork_types_imports_Address : + IsImported globals "ethereum.berlin.fork_types" "Address". -Axiom ethereum_berlin_state_imports : - AreImported globals "ethereum.berlin.state" [ "account_exists_and_is_empty"; "account_has_code_or_nonce"; "get_account"; "increment_nonce"; "is_account_alive"; "set_account_balance" ]. +Axiom ethereum_berlin_state_imports_account_exists_and_is_empty : + IsImported globals "ethereum.berlin.state" "account_exists_and_is_empty". +Axiom ethereum_berlin_state_imports_account_has_code_or_nonce : + IsImported globals "ethereum.berlin.state" "account_has_code_or_nonce". +Axiom ethereum_berlin_state_imports_get_account : + IsImported globals "ethereum.berlin.state" "get_account". +Axiom ethereum_berlin_state_imports_increment_nonce : + IsImported globals "ethereum.berlin.state" "increment_nonce". +Axiom ethereum_berlin_state_imports_is_account_alive : + IsImported globals "ethereum.berlin.state" "is_account_alive". +Axiom ethereum_berlin_state_imports_set_account_balance : + IsImported globals "ethereum.berlin.state" "set_account_balance". -Axiom ethereum_berlin_utils_address_imports : - AreImported globals "ethereum.berlin.utils.address" [ "compute_contract_address"; "compute_create2_contract_address"; "to_address" ]. +Axiom ethereum_berlin_utils_address_imports_compute_contract_address : + IsImported globals "ethereum.berlin.utils.address" "compute_contract_address". +Axiom ethereum_berlin_utils_address_imports_compute_create2_contract_address : + IsImported globals "ethereum.berlin.utils.address" "compute_create2_contract_address". +Axiom ethereum_berlin_utils_address_imports_to_address : + IsImported globals "ethereum.berlin.utils.address" "to_address". -Axiom ethereum_berlin_vm_imports : - AreImported globals "ethereum.berlin.vm" [ "Evm"; "Message"; "incorporate_child_on_error"; "incorporate_child_on_success" ]. +Axiom ethereum_berlin_vm_imports_Evm : + IsImported globals "ethereum.berlin.vm" "Evm". +Axiom ethereum_berlin_vm_imports_Message : + IsImported globals "ethereum.berlin.vm" "Message". +Axiom ethereum_berlin_vm_imports_incorporate_child_on_error : + IsImported globals "ethereum.berlin.vm" "incorporate_child_on_error". +Axiom ethereum_berlin_vm_imports_incorporate_child_on_success : + IsImported globals "ethereum.berlin.vm" "incorporate_child_on_success". -Axiom ethereum_berlin_vm_exceptions_imports : - AreImported globals "ethereum.berlin.vm.exceptions" [ "Revert"; "WriteInStaticContext" ]. +Axiom ethereum_berlin_vm_exceptions_imports_Revert : + IsImported globals "ethereum.berlin.vm.exceptions" "Revert". +Axiom ethereum_berlin_vm_exceptions_imports_WriteInStaticContext : + IsImported globals "ethereum.berlin.vm.exceptions" "WriteInStaticContext". -Axiom ethereum_berlin_vm_gas_imports : - AreImported globals "ethereum.berlin.vm.gas" [ "GAS_CALL_VALUE"; "GAS_COLD_ACCOUNT_ACCESS"; "GAS_CREATE"; "GAS_KECCAK256_WORD"; "GAS_NEW_ACCOUNT"; "GAS_SELF_DESTRUCT"; "GAS_SELF_DESTRUCT_NEW_ACCOUNT"; "GAS_WARM_ACCESS"; "GAS_ZERO"; "REFUND_SELF_DESTRUCT"; "calculate_gas_extend_memory"; "calculate_message_call_gas"; "charge_gas"; "max_message_call_gas" ]. +Axiom ethereum_berlin_vm_gas_imports_GAS_CALL_VALUE : + IsImported globals "ethereum.berlin.vm.gas" "GAS_CALL_VALUE". +Axiom ethereum_berlin_vm_gas_imports_GAS_COLD_ACCOUNT_ACCESS : + IsImported globals "ethereum.berlin.vm.gas" "GAS_COLD_ACCOUNT_ACCESS". +Axiom ethereum_berlin_vm_gas_imports_GAS_CREATE : + IsImported globals "ethereum.berlin.vm.gas" "GAS_CREATE". +Axiom ethereum_berlin_vm_gas_imports_GAS_KECCAK256_WORD : + IsImported globals "ethereum.berlin.vm.gas" "GAS_KECCAK256_WORD". +Axiom ethereum_berlin_vm_gas_imports_GAS_NEW_ACCOUNT : + IsImported globals "ethereum.berlin.vm.gas" "GAS_NEW_ACCOUNT". +Axiom ethereum_berlin_vm_gas_imports_GAS_SELF_DESTRUCT : + IsImported globals "ethereum.berlin.vm.gas" "GAS_SELF_DESTRUCT". +Axiom ethereum_berlin_vm_gas_imports_GAS_SELF_DESTRUCT_NEW_ACCOUNT : + IsImported globals "ethereum.berlin.vm.gas" "GAS_SELF_DESTRUCT_NEW_ACCOUNT". +Axiom ethereum_berlin_vm_gas_imports_GAS_WARM_ACCESS : + IsImported globals "ethereum.berlin.vm.gas" "GAS_WARM_ACCESS". +Axiom ethereum_berlin_vm_gas_imports_GAS_ZERO : + IsImported globals "ethereum.berlin.vm.gas" "GAS_ZERO". +Axiom ethereum_berlin_vm_gas_imports_REFUND_SELF_DESTRUCT : + IsImported globals "ethereum.berlin.vm.gas" "REFUND_SELF_DESTRUCT". +Axiom ethereum_berlin_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.berlin.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_berlin_vm_gas_imports_calculate_message_call_gas : + IsImported globals "ethereum.berlin.vm.gas" "calculate_message_call_gas". +Axiom ethereum_berlin_vm_gas_imports_charge_gas : + IsImported globals "ethereum.berlin.vm.gas" "charge_gas". +Axiom ethereum_berlin_vm_gas_imports_max_message_call_gas : + IsImported globals "ethereum.berlin.vm.gas" "max_message_call_gas". -Axiom ethereum_berlin_vm_memory_imports : - AreImported globals "ethereum.berlin.vm.memory" [ "memory_read_bytes"; "memory_write" ]. +Axiom ethereum_berlin_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.berlin.vm.memory" "memory_read_bytes". +Axiom ethereum_berlin_vm_memory_imports_memory_write : + IsImported globals "ethereum.berlin.vm.memory" "memory_write". -Axiom ethereum_berlin_vm_stack_imports : - AreImported globals "ethereum.berlin.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_berlin_vm_stack_imports_pop : + IsImported globals "ethereum.berlin.vm.stack" "pop". +Axiom ethereum_berlin_vm_stack_imports_push : + IsImported globals "ethereum.berlin.vm.stack" "push". Definition generic_create : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -64,7 +120,8 @@ Definition generic_create : Value.t -> Value.t -> M := ], make_dict [] |) in - let create_message_gas := + let _ := M.assign_local (| + "create_message_gas" , M.call (| M.get_name (| globals, "max_message_call_gas" |), make_list [ @@ -77,7 +134,8 @@ Definition generic_create : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.assign_op (| BinOp.sub, M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), @@ -95,9 +153,12 @@ Definition generic_create : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), Constant.bytes "" |) in - let sender_address := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in - let sender := + let _ := M.assign_local (| + "sender_address" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + |) in + let _ := M.assign_local (| + "sender" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -105,7 +166,8 @@ Definition generic_create : Value.t -> Value.t -> M := M.get_name (| globals, "sender_address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -216,7 +278,8 @@ Definition generic_create : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let call_data := + let _ := M.assign_local (| + "call_data" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -225,7 +288,8 @@ Definition generic_create : Value.t -> Value.t -> M := M.get_name (| globals, "memory_size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "increment_nonce" |), make_list [ @@ -234,13 +298,16 @@ Definition generic_create : Value.t -> Value.t -> M := ], make_dict [] |) in - let child_message := + let _ := M.assign_local (| + "child_message" , M.call (| M.get_name (| globals, "Message" |), make_list [], make_dict [] - |) in - let child_evm := + |) + |) in + let _ := M.assign_local (| + "child_evm" , M.call (| M.get_name (| globals, "process_create_message" |), make_list [ @@ -248,7 +315,8 @@ Definition generic_create : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -325,31 +393,38 @@ Definition create : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let endowment := + let _ := M.assign_local (| + "endowment" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_size := + |) + |) in + let _ := M.assign_local (| + "memory_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -359,7 +434,8 @@ Definition create : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -379,7 +455,8 @@ Definition create : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let contract_address := + let _ := M.assign_local (| + "contract_address" , M.call (| M.get_name (| globals, "compute_contract_address" |), make_list [ @@ -394,7 +471,8 @@ Definition create : Value.t -> Value.t -> M := |), "nonce" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "generic_create" |), make_list [ @@ -427,31 +505,38 @@ Definition create2 : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let endowment := + let _ := M.assign_local (| + "endowment" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_size := + |) + |) in + let _ := M.assign_local (| + "memory_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let salt := + |) + |) in + let _ := M.assign_local (| + "salt" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -462,8 +547,10 @@ Definition create2 : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -473,8 +560,10 @@ Definition create2 : Value.t -> Value.t -> M := ] ], make_dict [] - |) in - let call_data_words := + |) + |) in + let _ := M.assign_local (| + "call_data_words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -490,7 +579,8 @@ Definition create2 : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -516,7 +606,8 @@ Definition create2 : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let contract_address := + let _ := M.assign_local (| + "contract_address" , M.call (| M.get_name (| globals, "compute_create2_contract_address" |), make_list [ @@ -533,7 +624,8 @@ Definition create2 : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "generic_create" |), make_list [ @@ -563,23 +655,28 @@ Definition return_ : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let memory_start_position := + let _ := M.assign_local (| + "memory_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_size := + |) + |) in + let _ := M.assign_local (| + "memory_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -589,7 +686,8 @@ Definition return_ : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -678,7 +776,8 @@ Definition generic_call : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let call_data := + let _ := M.assign_local (| + "call_data" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -687,8 +786,10 @@ Definition generic_call : Value.t -> Value.t -> M := M.get_name (| globals, "memory_input_size" |) ], make_dict [] - |) in - let code := + |) + |) in + let _ := M.assign_local (| + "code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -696,14 +797,18 @@ Definition generic_call : Value.t -> Value.t -> M := M.get_name (| globals, "code_address" |) ], make_dict [] - |), "code" |) in - let child_message := + |), "code" |) + |) in + let _ := M.assign_local (| + "child_message" , M.call (| M.get_name (| globals, "Message" |), make_list [], make_dict [] - |) in - let child_evm := + |) + |) in + let _ := M.assign_local (| + "child_evm" , M.call (| M.get_name (| globals, "process_message" |), make_list [ @@ -711,7 +816,8 @@ Definition generic_call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -775,7 +881,8 @@ Definition generic_call : Value.t -> Value.t -> M := |) in M.pure Constant.None_ )) |) in - let actual_output_size := + let _ := M.assign_local (| + "actual_output_size" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -795,7 +902,8 @@ Definition generic_call : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -823,7 +931,8 @@ Definition call : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -836,8 +945,10 @@ Definition call : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let to := + |) + |) in + let _ := M.assign_local (| + "to" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -850,48 +961,60 @@ Definition call : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -902,7 +1025,8 @@ Definition call : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -912,8 +1036,10 @@ Definition call : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let access_gas_cost := - M.get_name (| globals, "GAS_WARM_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -924,11 +1050,14 @@ Definition call : Value.t -> Value.t -> M := ], make_dict [] |) in - let access_gas_cost := - M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + |) in M.pure Constant.None_ )) |) in - let create_gas_cost := + let _ := M.assign_local (| + "create_gas_cost" , (* if *) M.if_then_else (| BoolOp.or (| @@ -959,8 +1088,10 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "GAS_NEW_ACCOUNT" |) - )) |) in - let transfer_gas_cost := + )) |) + |) in + let _ := M.assign_local (| + "transfer_gas_cost" , (* if *) M.if_then_else (| Compare.eq (| @@ -979,8 +1110,10 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "GAS_CALL_VALUE" |) - )) |) in - let message_call_gas := + )) |) + |) in + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -1003,7 +1136,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1045,7 +1179,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let sender_balance := + let _ := M.assign_local (| + "sender_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1053,7 +1188,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := (* if *) M.if_then_else (| @@ -1127,7 +1263,8 @@ Definition callcode : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -1140,8 +1277,10 @@ Definition callcode : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let code_address := + |) + |) in + let _ := M.assign_local (| + "code_address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1154,50 +1293,64 @@ Definition callcode : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let to := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "to" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1208,7 +1361,8 @@ Definition callcode : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1218,8 +1372,10 @@ Definition callcode : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let access_gas_cost := - M.get_name (| globals, "GAS_WARM_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1230,11 +1386,14 @@ Definition callcode : Value.t -> Value.t -> M := ], make_dict [] |) in - let access_gas_cost := - M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + |) in M.pure Constant.None_ )) |) in - let transfer_gas_cost := + let _ := M.assign_local (| + "transfer_gas_cost" , (* if *) M.if_then_else (| Compare.eq (| @@ -1253,8 +1412,10 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "GAS_CALL_VALUE" |) - )) |) in - let message_call_gas := + )) |) + |) in + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -1274,7 +1435,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1294,7 +1456,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let sender_balance := + let _ := M.assign_local (| + "sender_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1302,7 +1465,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := (* if *) M.if_then_else (| @@ -1376,7 +1540,8 @@ Definition selfdestruct : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let beneficiary := + let _ := M.assign_local (| + "beneficiary" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1389,9 +1554,12 @@ Definition selfdestruct : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let gas_cost := - M.get_name (| globals, "GAS_SELF_DESTRUCT" |) in + |) + |) in + let _ := M.assign_local (| + "gas_cost" , + M.get_name (| globals, "GAS_SELF_DESTRUCT" |) + |) in let _ := (* if *) M.if_then_else (| @@ -1408,9 +1576,11 @@ Definition selfdestruct : Value.t -> Value.t -> M := ], make_dict [] |) in - let gas_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "gas_cost", M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) - M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1444,20 +1614,28 @@ Definition selfdestruct : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let gas_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "gas_cost", M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) - M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let originator := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in - let refunded_accounts := - M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in - let parent_evm := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "parent_evm" |) in + let _ := M.assign_local (| + "originator" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + |) in + let _ := M.assign_local (| + "refunded_accounts" , + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) + |) in + let _ := M.assign_local (| + "parent_evm" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "parent_evm" |) + |) in let _ := M.while (| Compare.is_not (| @@ -1472,8 +1650,10 @@ Definition selfdestruct : Value.t -> Value.t -> M := ], make_dict [] |) in - let parent_evm := - M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in + let _ := M.assign_local (| + "parent_evm" , + M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -1515,7 +1695,8 @@ Definition selfdestruct : Value.t -> Value.t -> M := ], make_dict [] |) in - let beneficiary_balance := + let _ := M.assign_local (| + "beneficiary_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1523,8 +1704,10 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_name (| globals, "beneficiary" |) ], make_dict [] - |), "balance" |) in - let originator_balance := + |), "balance" |) + |) in + let _ := M.assign_local (| + "originator_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1532,7 +1715,8 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_name (| globals, "originator" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -1610,7 +1794,8 @@ Definition delegatecall : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -1623,8 +1808,10 @@ Definition delegatecall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let code_address := + |) + |) in + let _ := M.assign_local (| + "code_address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1637,40 +1824,50 @@ Definition delegatecall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1681,7 +1878,8 @@ Definition delegatecall : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1691,8 +1889,10 @@ Definition delegatecall : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let access_gas_cost := - M.get_name (| globals, "GAS_WARM_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1703,11 +1903,14 @@ Definition delegatecall : Value.t -> Value.t -> M := ], make_dict [] |) in - let access_gas_cost := - M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + |) in M.pure Constant.None_ )) |) in - let message_call_gas := + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -1730,7 +1933,8 @@ Definition delegatecall : Value.t -> Value.t -> M := M.get_name (| globals, "access_gas_cost" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1786,7 +1990,8 @@ Definition staticcall : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -1799,8 +2004,10 @@ Definition staticcall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let to := + |) + |) in + let _ := M.assign_local (| + "to" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1813,40 +2020,50 @@ Definition staticcall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1857,7 +2074,8 @@ Definition staticcall : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1867,8 +2085,10 @@ Definition staticcall : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let access_gas_cost := - M.get_name (| globals, "GAS_WARM_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1879,11 +2099,14 @@ Definition staticcall : Value.t -> Value.t -> M := ], make_dict [] |) in - let access_gas_cost := - M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + |) in M.pure Constant.None_ )) |) in - let message_call_gas := + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -1906,7 +2129,8 @@ Definition staticcall : Value.t -> Value.t -> M := M.get_name (| globals, "access_gas_cost" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1968,23 +2192,28 @@ Definition revert : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1994,7 +2223,8 @@ Definition revert : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -2011,7 +2241,8 @@ Definition revert : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let output := + let _ := M.assign_local (| + "output" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -2020,7 +2251,8 @@ Definition revert : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| diff --git a/CoqOfPython/ethereum/berlin/vm/interpreter.v b/CoqOfPython/ethereum/berlin/vm/interpreter.v index 4100220..c0c52ad 100644 --- a/CoqOfPython/ethereum/berlin/vm/interpreter.v +++ b/CoqOfPython/ethereum/berlin/vm/interpreter.v @@ -17,50 +17,110 @@ Introduction A straightforward interpreter that executes EVM code. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Iterable"; "Optional"; "Set"; "Tuple" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. - -Axiom ethereum_trace_imports : - AreImported globals "ethereum.trace" [ "EvmStop"; "OpEnd"; "OpException"; "OpStart"; "PrecompileEnd"; "PrecompileStart"; "TransactionEnd"; "evm_trace" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_berlin_blocks_imports : - AreImported globals "ethereum.berlin.blocks" [ "Log" ]. - -Axiom ethereum_berlin_fork_types_imports : - AreImported globals "ethereum.berlin.fork_types" [ "Address" ]. - -Axiom ethereum_berlin_state_imports : - AreImported globals "ethereum.berlin.state" [ "account_exists_and_is_empty"; "account_has_code_or_nonce"; "begin_transaction"; "commit_transaction"; "destroy_storage"; "increment_nonce"; "mark_account_created"; "move_ether"; "rollback_transaction"; "set_code"; "touch_account" ]. - -Axiom ethereum_berlin_vm_imports : - AreImported globals "ethereum.berlin.vm" [ "Message" ]. - -Axiom ethereum_berlin_vm_gas_imports : - AreImported globals "ethereum.berlin.vm.gas" [ "GAS_CODE_DEPOSIT"; "charge_gas" ]. - -Axiom ethereum_berlin_vm_precompiled_contracts_mapping_imports : - AreImported globals "ethereum.berlin.vm.precompiled_contracts.mapping" [ "PRE_COMPILED_CONTRACTS" ]. - -Axiom ethereum_berlin_vm_imports : - AreImported globals "ethereum.berlin.vm" [ "Environment"; "Evm" ]. - -Axiom ethereum_berlin_vm_exceptions_imports : - AreImported globals "ethereum.berlin.vm.exceptions" [ "AddressCollision"; "ExceptionalHalt"; "InvalidOpcode"; "OutOfGasError"; "Revert"; "StackDepthLimitError" ]. - -Axiom ethereum_berlin_vm_instructions_imports : - AreImported globals "ethereum.berlin.vm.instructions" [ "Ops"; "op_implementation" ]. - -Axiom ethereum_berlin_vm_runtime_imports : - AreImported globals "ethereum.berlin.vm.runtime" [ "get_valid_jump_destinations" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_Iterable : + IsImported globals "typing" "Iterable". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_trace_imports_EvmStop : + IsImported globals "ethereum.trace" "EvmStop". +Axiom ethereum_trace_imports_OpEnd : + IsImported globals "ethereum.trace" "OpEnd". +Axiom ethereum_trace_imports_OpException : + IsImported globals "ethereum.trace" "OpException". +Axiom ethereum_trace_imports_OpStart : + IsImported globals "ethereum.trace" "OpStart". +Axiom ethereum_trace_imports_PrecompileEnd : + IsImported globals "ethereum.trace" "PrecompileEnd". +Axiom ethereum_trace_imports_PrecompileStart : + IsImported globals "ethereum.trace" "PrecompileStart". +Axiom ethereum_trace_imports_TransactionEnd : + IsImported globals "ethereum.trace" "TransactionEnd". +Axiom ethereum_trace_imports_evm_trace : + IsImported globals "ethereum.trace" "evm_trace". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_berlin_blocks_imports_Log : + IsImported globals "ethereum.berlin.blocks" "Log". + +Axiom ethereum_berlin_fork_types_imports_Address : + IsImported globals "ethereum.berlin.fork_types" "Address". + +Axiom ethereum_berlin_state_imports_account_exists_and_is_empty : + IsImported globals "ethereum.berlin.state" "account_exists_and_is_empty". +Axiom ethereum_berlin_state_imports_account_has_code_or_nonce : + IsImported globals "ethereum.berlin.state" "account_has_code_or_nonce". +Axiom ethereum_berlin_state_imports_begin_transaction : + IsImported globals "ethereum.berlin.state" "begin_transaction". +Axiom ethereum_berlin_state_imports_commit_transaction : + IsImported globals "ethereum.berlin.state" "commit_transaction". +Axiom ethereum_berlin_state_imports_destroy_storage : + IsImported globals "ethereum.berlin.state" "destroy_storage". +Axiom ethereum_berlin_state_imports_increment_nonce : + IsImported globals "ethereum.berlin.state" "increment_nonce". +Axiom ethereum_berlin_state_imports_mark_account_created : + IsImported globals "ethereum.berlin.state" "mark_account_created". +Axiom ethereum_berlin_state_imports_move_ether : + IsImported globals "ethereum.berlin.state" "move_ether". +Axiom ethereum_berlin_state_imports_rollback_transaction : + IsImported globals "ethereum.berlin.state" "rollback_transaction". +Axiom ethereum_berlin_state_imports_set_code : + IsImported globals "ethereum.berlin.state" "set_code". +Axiom ethereum_berlin_state_imports_touch_account : + IsImported globals "ethereum.berlin.state" "touch_account". + +Axiom ethereum_berlin_vm_imports_Message : + IsImported globals "ethereum.berlin.vm" "Message". + +Axiom ethereum_berlin_vm_gas_imports_GAS_CODE_DEPOSIT : + IsImported globals "ethereum.berlin.vm.gas" "GAS_CODE_DEPOSIT". +Axiom ethereum_berlin_vm_gas_imports_charge_gas : + IsImported globals "ethereum.berlin.vm.gas" "charge_gas". + +Axiom ethereum_berlin_vm_precompiled_contracts_mapping_imports_PRE_COMPILED_CONTRACTS : + IsImported globals "ethereum.berlin.vm.precompiled_contracts.mapping" "PRE_COMPILED_CONTRACTS". + +Axiom ethereum_berlin_vm_imports_Environment : + IsImported globals "ethereum.berlin.vm" "Environment". +Axiom ethereum_berlin_vm_imports_Evm : + IsImported globals "ethereum.berlin.vm" "Evm". + +Axiom ethereum_berlin_vm_exceptions_imports_AddressCollision : + IsImported globals "ethereum.berlin.vm.exceptions" "AddressCollision". +Axiom ethereum_berlin_vm_exceptions_imports_ExceptionalHalt : + IsImported globals "ethereum.berlin.vm.exceptions" "ExceptionalHalt". +Axiom ethereum_berlin_vm_exceptions_imports_InvalidOpcode : + IsImported globals "ethereum.berlin.vm.exceptions" "InvalidOpcode". +Axiom ethereum_berlin_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.berlin.vm.exceptions" "OutOfGasError". +Axiom ethereum_berlin_vm_exceptions_imports_Revert : + IsImported globals "ethereum.berlin.vm.exceptions" "Revert". +Axiom ethereum_berlin_vm_exceptions_imports_StackDepthLimitError : + IsImported globals "ethereum.berlin.vm.exceptions" "StackDepthLimitError". + +Axiom ethereum_berlin_vm_instructions_imports_Ops : + IsImported globals "ethereum.berlin.vm.instructions" "Ops". +Axiom ethereum_berlin_vm_instructions_imports_op_implementation : + IsImported globals "ethereum.berlin.vm.instructions" "op_implementation". + +Axiom ethereum_berlin_vm_runtime_imports_get_valid_jump_destinations : + IsImported globals "ethereum.berlin.vm.runtime" "get_valid_jump_destinations". Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -121,7 +181,8 @@ Definition process_message_call : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let is_collision := + let _ := M.assign_local (| + "is_collision" , M.call (| M.get_name (| globals, "account_has_code_or_nonce" |), make_list [ @@ -129,7 +190,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "message" |), "current_target" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -181,7 +243,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "process_create_message" |), make_list [ @@ -189,13 +252,15 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "process_message" |), make_list [ @@ -203,7 +268,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -250,46 +316,61 @@ Definition process_message_call : Value.t -> Value.t -> M := (* then *) ltac:(M.monadic ( (* At stmt: unsupported node type: AnnAssign *) - let accounts_to_delete := + let _ := M.assign_local (| + "accounts_to_delete" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let touched_accounts := + |) + |) in + let _ := M.assign_local (| + "touched_accounts" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let refund_counter := + |) + |) in + let _ := M.assign_local (| + "refund_counter" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let logs := - M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in - let accounts_to_delete := - M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in - let touched_accounts := - M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |) in - let refund_counter := + let _ := M.assign_local (| + "logs" , + M.get_field (| M.get_name (| globals, "evm" |), "logs" |) + |) in + let _ := M.assign_local (| + "accounts_to_delete" , + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) + |) in + let _ := M.assign_local (| + "touched_accounts" , + M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |) + |) in + let _ := M.assign_local (| + "refund_counter" , M.call (| M.get_name (| globals, "U256" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in - let tx_end := + let _ := M.assign_local (| + "tx_end" , M.call (| M.get_name (| globals, "TransactionEnd" |), make_list [ @@ -301,7 +382,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "error" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "evm_trace" |), make_list [ @@ -368,7 +450,8 @@ Definition process_create_message : Value.t -> Value.t -> M := ], make_dict [] |) in - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "process_message" |), make_list [ @@ -376,16 +459,20 @@ Definition process_create_message : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), (* then *) ltac:(M.monadic ( - let contract_code := - M.get_field (| M.get_name (| globals, "evm" |), "output" |) in - let contract_code_gas := + let _ := M.assign_local (| + "contract_code" , + M.get_field (| M.get_name (| globals, "evm" |), "output" |) + |) in + let _ := M.assign_local (| + "contract_code_gas" , BinOp.mult (| M.call (| M.get_name (| globals, "len" |), @@ -395,7 +482,8 @@ Definition process_create_message : Value.t -> Value.t -> M := make_dict [] |), M.get_name (| globals, "GAS_CODE_DEPOSIT" |) - |) in + |) + |) in (* At stmt: unsupported node type: Try *) M.pure Constant.None_ (* else *) @@ -497,7 +585,8 @@ Definition process_message : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "execute_code" |), make_list [ @@ -505,7 +594,8 @@ Definition process_message : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -554,22 +644,28 @@ Definition execute_code : Value.t -> Value.t -> M := evm: `ethereum.vm.EVM` Items containing execution specific objects " in - let code := - M.get_field (| M.get_name (| globals, "message" |), "code" |) in - let valid_jump_destinations := + let _ := M.assign_local (| + "code" , + M.get_field (| M.get_name (| globals, "message" |), "code" |) + |) in + let _ := M.assign_local (| + "valid_jump_destinations" , M.call (| M.get_name (| globals, "get_valid_jump_destinations" |), make_list [ M.get_name (| globals, "code" |) ], make_dict [] - |) in - let evm := + |) + |) in + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "Evm" |), make_list [], make_dict [] - |) in + |) + |) in (* At stmt: unsupported node type: Try *) let _ := M.return_ (| M.get_name (| globals, "evm" |) diff --git a/CoqOfPython/ethereum/berlin/vm/memory.v b/CoqOfPython/ethereum/berlin/vm/memory.v index b747f84..62e26d1 100644 --- a/CoqOfPython/ethereum/berlin/vm/memory.v +++ b/CoqOfPython/ethereum/berlin/vm/memory.v @@ -17,11 +17,15 @@ Introduction EVM memory operations. ". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "right_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_right_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "right_pad_zero_bytes". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". Definition memory_write : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/__init__.v index 3bd7f40..311a52a 100644 --- a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/__init__.v +++ b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/__init__.v @@ -18,8 +18,8 @@ Addresses of precompiled contracts and mappings to their implementations. ". -Axiom ethereum_berlin_utils_hexadecimal_imports : - AreImported globals "ethereum.berlin.utils.hexadecimal" [ "hex_to_address" ]. +Axiom ethereum_berlin_utils_hexadecimal_imports_hex_to_address : + IsImported globals "ethereum.berlin.utils.hexadecimal" "hex_to_address". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS"; Constant.str "MODEXP_ADDRESS"; Constant.str "ALT_BN128_ADD_ADDRESS"; Constant.str "ALT_BN128_MUL_ADDRESS"; Constant.str "ALT_BN128_PAIRING_CHECK_ADDRESS"; Constant.str "BLAKE2F_ADDRESS" ] diff --git a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/alt_bn128.v index 9bd81c6..8bfbd17 100644 --- a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/alt_bn128.v +++ b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/alt_bn128.v @@ -17,26 +17,42 @@ Introduction Implementation of the ALT_BN128 precompiled contracts. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_alt_bn128_imports : - AreImported globals "ethereum.crypto.alt_bn128" [ "ALT_BN128_CURVE_ORDER"; "ALT_BN128_PRIME"; "BNF"; "BNF2"; "BNF12"; "BNP"; "BNP2"; "pairing" ]. +Axiom ethereum_crypto_alt_bn128_imports_ALT_BN128_CURVE_ORDER : + IsImported globals "ethereum.crypto.alt_bn128" "ALT_BN128_CURVE_ORDER". +Axiom ethereum_crypto_alt_bn128_imports_ALT_BN128_PRIME : + IsImported globals "ethereum.crypto.alt_bn128" "ALT_BN128_PRIME". +Axiom ethereum_crypto_alt_bn128_imports_BNF : + IsImported globals "ethereum.crypto.alt_bn128" "BNF". +Axiom ethereum_crypto_alt_bn128_imports_BNF2 : + IsImported globals "ethereum.crypto.alt_bn128" "BNF2". +Axiom ethereum_crypto_alt_bn128_imports_BNF12 : + IsImported globals "ethereum.crypto.alt_bn128" "BNF12". +Axiom ethereum_crypto_alt_bn128_imports_BNP : + IsImported globals "ethereum.crypto.alt_bn128" "BNP". +Axiom ethereum_crypto_alt_bn128_imports_BNP2 : + IsImported globals "ethereum.crypto.alt_bn128" "BNP2". +Axiom ethereum_crypto_alt_bn128_imports_pairing : + IsImported globals "ethereum.crypto.alt_bn128" "pairing". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_berlin_vm_imports : - AreImported globals "ethereum.berlin.vm" [ "Evm" ]. +Axiom ethereum_berlin_vm_imports_Evm : + IsImported globals "ethereum.berlin.vm" "Evm". -Axiom ethereum_berlin_vm_gas_imports : - AreImported globals "ethereum.berlin.vm.gas" [ "charge_gas" ]. +Axiom ethereum_berlin_vm_gas_imports_charge_gas : + IsImported globals "ethereum.berlin.vm.gas" "charge_gas". -Axiom ethereum_berlin_vm_memory_imports : - AreImported globals "ethereum.berlin.vm.memory" [ "buffer_read" ]. +Axiom ethereum_berlin_vm_memory_imports_buffer_read : + IsImported globals "ethereum.berlin.vm.memory" "buffer_read". -Axiom ethereum_berlin_vm_exceptions_imports : - AreImported globals "ethereum.berlin.vm.exceptions" [ "OutOfGasError" ]. +Axiom ethereum_berlin_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.berlin.vm.exceptions" "OutOfGasError". Definition alt_bn128_add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -49,8 +65,10 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -65,7 +83,8 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := ], make_dict [] |) in - let x0_bytes := + let _ := M.assign_local (| + "x0_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -86,16 +105,20 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let x0_value := + |) + |) in + let _ := M.assign_local (| + "x0_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "x0_bytes" |) ], make_dict [] - |) in - let y0_bytes := + |) + |) in + let _ := M.assign_local (| + "y0_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -116,16 +139,20 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y0_value := + |) + |) in + let _ := M.assign_local (| + "y0_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "y0_bytes" |) ], make_dict [] - |) in - let x1_bytes := + |) + |) in + let _ := M.assign_local (| + "x1_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -146,16 +173,20 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let x1_value := + |) + |) in + let _ := M.assign_local (| + "x1_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "x1_bytes" |) ], make_dict [] - |) in - let y1_bytes := + |) + |) in + let _ := M.assign_local (| + "y1_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -176,15 +207,18 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y1_value := + |) + |) in + let _ := M.assign_local (| + "y1_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "y1_bytes" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "i" |), @@ -212,11 +246,13 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := )) |) in (* At stmt: unsupported node type: Try *) - let p := + let _ := M.assign_local (| + "p" , BinOp.add (| M.get_name (| globals, "p0" |), M.get_name (| globals, "p1" |) - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), BinOp.add (| @@ -245,8 +281,10 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -261,7 +299,8 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := ], make_dict [] |) in - let x0_bytes := + let _ := M.assign_local (| + "x0_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -282,16 +321,20 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let x0_value := + |) + |) in + let _ := M.assign_local (| + "x0_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "x0_bytes" |) ], make_dict [] - |) in - let y0_bytes := + |) + |) in + let _ := M.assign_local (| + "y0_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -312,16 +355,20 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y0_value := + |) + |) in + let _ := M.assign_local (| + "y0_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "y0_bytes" |) ], make_dict [] - |) in - let n := + |) + |) in + let _ := M.assign_local (| + "n" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -348,7 +395,8 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "i" |), @@ -376,14 +424,16 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := )) |) in (* At stmt: unsupported node type: Try *) - let p := + let _ := M.assign_local (| + "p" , M.call (| M.get_field (| M.get_name (| globals, "p0" |), "mul_by" |), make_list [ M.get_name (| globals, "n" |) ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), BinOp.add (| @@ -412,8 +462,10 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -467,14 +519,16 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), make_list [ Constant.int 1 ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "i" |), @@ -495,8 +549,10 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let values := - make_list [] in + let _ := M.assign_local (| + "values" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "j" |), @@ -508,7 +564,8 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -541,7 +598,8 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -644,7 +702,8 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , BinOp.mult (| M.get_name (| globals, "result" |), M.call (| @@ -655,7 +714,8 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/blake2f.v b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/blake2f.v index 163d93c..5afc3b4 100644 --- a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/blake2f.v +++ b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/blake2f.v @@ -17,20 +17,22 @@ Introduction Implementation of the `Blake2` precompiled contract. ". -Axiom ethereum_crypto_blake2_imports : - AreImported globals "ethereum.crypto.blake2" [ "Blake2b" ]. +Axiom ethereum_crypto_blake2_imports_Blake2b : + IsImported globals "ethereum.crypto.blake2" "Blake2b". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_berlin_vm_imports : - AreImported globals "ethereum.berlin.vm" [ "Evm" ]. +Axiom ethereum_berlin_vm_imports_Evm : + IsImported globals "ethereum.berlin.vm" "Evm". -Axiom ethereum_berlin_vm_gas_imports : - AreImported globals "ethereum.berlin.vm.gas" [ "GAS_BLAKE2_PER_ROUND"; "charge_gas" ]. +Axiom ethereum_berlin_vm_gas_imports_GAS_BLAKE2_PER_ROUND : + IsImported globals "ethereum.berlin.vm.gas" "GAS_BLAKE2_PER_ROUND". +Axiom ethereum_berlin_vm_gas_imports_charge_gas : + IsImported globals "ethereum.berlin.vm.gas" "charge_gas". -Axiom ethereum_berlin_vm_exceptions_imports : - AreImported globals "ethereum.berlin.vm.exceptions" [ "InvalidParameter" ]. +Axiom ethereum_berlin_vm_exceptions_imports_InvalidParameter : + IsImported globals "ethereum.berlin.vm.exceptions" "InvalidParameter". Definition blake2f : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -43,8 +45,10 @@ Definition blake2f : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -62,12 +66,14 @@ Definition blake2f : Value.t -> Value.t -> M := ], make_dict [] |) in - let blake2b := + let _ := M.assign_local (| + "blake2b" , M.call (| M.get_name (| globals, "Blake2b" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "rounds" |); M.get_name (| globals, "h" |); M.get_name (| globals, "m" |); M.get_name (| globals, "t_0" |); M.get_name (| globals, "t_1" |); M.get_name (| globals, "f" |) ], M.call (| diff --git a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/ecrecover.v index 1fe04ba..9c5863b 100644 --- a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/ecrecover.v @@ -17,26 +17,32 @@ Introduction Implementation of the ECRECOVER precompiled contract. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_crypto_elliptic_curve_imports : - AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. +Axiom ethereum_crypto_elliptic_curve_imports_SECP256K1N : + IsImported globals "ethereum.crypto.elliptic_curve" "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_imports_secp256k1_recover : + IsImported globals "ethereum.crypto.elliptic_curve" "secp256k1_recover". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_left_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "left_pad_zero_bytes". -Axiom ethereum_berlin_vm_imports : - AreImported globals "ethereum.berlin.vm" [ "Evm" ]. +Axiom ethereum_berlin_vm_imports_Evm : + IsImported globals "ethereum.berlin.vm" "Evm". -Axiom ethereum_berlin_vm_gas_imports : - AreImported globals "ethereum.berlin.vm.gas" [ "GAS_ECRECOVER"; "charge_gas" ]. +Axiom ethereum_berlin_vm_gas_imports_GAS_ECRECOVER : + IsImported globals "ethereum.berlin.vm.gas" "GAS_ECRECOVER". +Axiom ethereum_berlin_vm_gas_imports_charge_gas : + IsImported globals "ethereum.berlin.vm.gas" "charge_gas". -Axiom ethereum_berlin_vm_memory_imports : - AreImported globals "ethereum.berlin.vm.memory" [ "buffer_read" ]. +Axiom ethereum_berlin_vm_memory_imports_buffer_read : + IsImported globals "ethereum.berlin.vm.memory" "buffer_read". Definition ecrecover : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -50,8 +56,10 @@ Definition ecrecover : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -60,7 +68,8 @@ Definition ecrecover : Value.t -> Value.t -> M := ], make_dict [] |) in - let message_hash_bytes := + let _ := M.assign_local (| + "message_hash_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -81,16 +90,20 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let message_hash := + |) + |) in + let _ := M.assign_local (| + "message_hash" , M.call (| M.get_name (| globals, "Hash32" |), make_list [ M.get_name (| globals, "message_hash_bytes" |) ], make_dict [] - |) in - let v := + |) + |) in + let _ := M.assign_local (| + "v" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -117,8 +130,10 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let r := + |) + |) in + let _ := M.assign_local (| + "r" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -145,8 +160,10 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let s := + |) + |) in + let _ := M.assign_local (| + "s" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -173,7 +190,8 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -250,7 +268,8 @@ Definition ecrecover : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: Try *) - let address := + let _ := M.assign_local (| + "address" , M.slice (| M.call (| M.get_name (| globals, "keccak256" |), @@ -262,8 +281,10 @@ Definition ecrecover : Value.t -> Value.t -> M := Constant.int 12, Constant.int 32, Constant.None_ - |) in - let padded_address := + |) + |) in + let _ := M.assign_local (| + "padded_address" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -271,7 +292,8 @@ Definition ecrecover : Value.t -> Value.t -> M := Constant.int 32 ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.get_name (| globals, "padded_address" |) diff --git a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/identity.v index 71f6812..3663ec2 100644 --- a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/identity.v +++ b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/identity.v @@ -17,17 +17,21 @@ Introduction Implementation of the `IDENTITY` precompiled contract. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_berlin_vm_imports : - AreImported globals "ethereum.berlin.vm" [ "Evm" ]. +Axiom ethereum_berlin_vm_imports_Evm : + IsImported globals "ethereum.berlin.vm" "Evm". -Axiom ethereum_berlin_vm_gas_imports : - AreImported globals "ethereum.berlin.vm.gas" [ "GAS_IDENTITY"; "GAS_IDENTITY_WORD"; "charge_gas" ]. +Axiom ethereum_berlin_vm_gas_imports_GAS_IDENTITY : + IsImported globals "ethereum.berlin.vm.gas" "GAS_IDENTITY". +Axiom ethereum_berlin_vm_gas_imports_GAS_IDENTITY_WORD : + IsImported globals "ethereum.berlin.vm.gas" "GAS_IDENTITY_WORD". +Axiom ethereum_berlin_vm_gas_imports_charge_gas : + IsImported globals "ethereum.berlin.vm.gas" "charge_gas". Definition identity : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -40,9 +44,12 @@ Definition identity : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let word_count := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "word_count" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -64,7 +71,8 @@ Definition identity : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ diff --git a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/mapping.v index b95e81e..14f0d14 100644 --- a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/mapping.v +++ b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/mapping.v @@ -17,34 +17,56 @@ Introduction Mapping of precompiled contracts their implementations. ". -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict" ]. - -Axiom ethereum_berlin_fork_types_imports : - AreImported globals "ethereum.berlin.fork_types" [ "Address" ]. - -Axiom ethereum_berlin_vm_precompiled_contracts_imports : - AreImported globals "ethereum.berlin.vm.precompiled_contracts" [ "ALT_BN128_ADD_ADDRESS"; "ALT_BN128_MUL_ADDRESS"; "ALT_BN128_PAIRING_CHECK_ADDRESS"; "BLAKE2F_ADDRESS"; "ECRECOVER_ADDRESS"; "IDENTITY_ADDRESS"; "MODEXP_ADDRESS"; "RIPEMD160_ADDRESS"; "SHA256_ADDRESS" ]. - -Axiom ethereum_berlin_vm_precompiled_contracts_alt_bn128_imports : - AreImported globals "ethereum.berlin.vm.precompiled_contracts.alt_bn128" [ "alt_bn128_add"; "alt_bn128_mul"; "alt_bn128_pairing_check" ]. - -Axiom ethereum_berlin_vm_precompiled_contracts_blake2f_imports : - AreImported globals "ethereum.berlin.vm.precompiled_contracts.blake2f" [ "blake2f" ]. - -Axiom ethereum_berlin_vm_precompiled_contracts_ecrecover_imports : - AreImported globals "ethereum.berlin.vm.precompiled_contracts.ecrecover" [ "ecrecover" ]. - -Axiom ethereum_berlin_vm_precompiled_contracts_identity_imports : - AreImported globals "ethereum.berlin.vm.precompiled_contracts.identity" [ "identity" ]. - -Axiom ethereum_berlin_vm_precompiled_contracts_modexp_imports : - AreImported globals "ethereum.berlin.vm.precompiled_contracts.modexp" [ "modexp" ]. - -Axiom ethereum_berlin_vm_precompiled_contracts_ripemd160_imports : - AreImported globals "ethereum.berlin.vm.precompiled_contracts.ripemd160" [ "ripemd160" ]. - -Axiom ethereum_berlin_vm_precompiled_contracts_sha256_imports : - AreImported globals "ethereum.berlin.vm.precompiled_contracts.sha256" [ "sha256" ]. +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". + +Axiom ethereum_berlin_fork_types_imports_Address : + IsImported globals "ethereum.berlin.fork_types" "Address". + +Axiom ethereum_berlin_vm_precompiled_contracts_imports_ALT_BN128_ADD_ADDRESS : + IsImported globals "ethereum.berlin.vm.precompiled_contracts" "ALT_BN128_ADD_ADDRESS". +Axiom ethereum_berlin_vm_precompiled_contracts_imports_ALT_BN128_MUL_ADDRESS : + IsImported globals "ethereum.berlin.vm.precompiled_contracts" "ALT_BN128_MUL_ADDRESS". +Axiom ethereum_berlin_vm_precompiled_contracts_imports_ALT_BN128_PAIRING_CHECK_ADDRESS : + IsImported globals "ethereum.berlin.vm.precompiled_contracts" "ALT_BN128_PAIRING_CHECK_ADDRESS". +Axiom ethereum_berlin_vm_precompiled_contracts_imports_BLAKE2F_ADDRESS : + IsImported globals "ethereum.berlin.vm.precompiled_contracts" "BLAKE2F_ADDRESS". +Axiom ethereum_berlin_vm_precompiled_contracts_imports_ECRECOVER_ADDRESS : + IsImported globals "ethereum.berlin.vm.precompiled_contracts" "ECRECOVER_ADDRESS". +Axiom ethereum_berlin_vm_precompiled_contracts_imports_IDENTITY_ADDRESS : + IsImported globals "ethereum.berlin.vm.precompiled_contracts" "IDENTITY_ADDRESS". +Axiom ethereum_berlin_vm_precompiled_contracts_imports_MODEXP_ADDRESS : + IsImported globals "ethereum.berlin.vm.precompiled_contracts" "MODEXP_ADDRESS". +Axiom ethereum_berlin_vm_precompiled_contracts_imports_RIPEMD160_ADDRESS : + IsImported globals "ethereum.berlin.vm.precompiled_contracts" "RIPEMD160_ADDRESS". +Axiom ethereum_berlin_vm_precompiled_contracts_imports_SHA256_ADDRESS : + IsImported globals "ethereum.berlin.vm.precompiled_contracts" "SHA256_ADDRESS". + +Axiom ethereum_berlin_vm_precompiled_contracts_alt_bn128_imports_alt_bn128_add : + IsImported globals "ethereum.berlin.vm.precompiled_contracts.alt_bn128" "alt_bn128_add". +Axiom ethereum_berlin_vm_precompiled_contracts_alt_bn128_imports_alt_bn128_mul : + IsImported globals "ethereum.berlin.vm.precompiled_contracts.alt_bn128" "alt_bn128_mul". +Axiom ethereum_berlin_vm_precompiled_contracts_alt_bn128_imports_alt_bn128_pairing_check : + IsImported globals "ethereum.berlin.vm.precompiled_contracts.alt_bn128" "alt_bn128_pairing_check". + +Axiom ethereum_berlin_vm_precompiled_contracts_blake2f_imports_blake2f : + IsImported globals "ethereum.berlin.vm.precompiled_contracts.blake2f" "blake2f". + +Axiom ethereum_berlin_vm_precompiled_contracts_ecrecover_imports_ecrecover : + IsImported globals "ethereum.berlin.vm.precompiled_contracts.ecrecover" "ecrecover". + +Axiom ethereum_berlin_vm_precompiled_contracts_identity_imports_identity : + IsImported globals "ethereum.berlin.vm.precompiled_contracts.identity" "identity". + +Axiom ethereum_berlin_vm_precompiled_contracts_modexp_imports_modexp : + IsImported globals "ethereum.berlin.vm.precompiled_contracts.modexp" "modexp". + +Axiom ethereum_berlin_vm_precompiled_contracts_ripemd160_imports_ripemd160 : + IsImported globals "ethereum.berlin.vm.precompiled_contracts.ripemd160" "ripemd160". + +Axiom ethereum_berlin_vm_precompiled_contracts_sha256_imports_sha256 : + IsImported globals "ethereum.berlin.vm.precompiled_contracts.sha256" "sha256". (* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/modexp.v index 70acad8..aa24c23 100644 --- a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/modexp.v +++ b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/modexp.v @@ -17,17 +17,21 @@ Introduction Implementation of the `MODEXP` precompiled contract. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_berlin_vm_imports : - AreImported globals "ethereum.berlin.vm" [ "Evm" ]. +Axiom ethereum_berlin_vm_imports_Evm : + IsImported globals "ethereum.berlin.vm" "Evm". -Axiom ethereum_berlin_vm_gas_imports : - AreImported globals "ethereum.berlin.vm.gas" [ "charge_gas" ]. +Axiom ethereum_berlin_vm_gas_imports_charge_gas : + IsImported globals "ethereum.berlin.vm.gas" "charge_gas". -Axiom ethereum_berlin_vm_memory_imports : - AreImported globals "ethereum.berlin.vm.memory" [ "buffer_read" ]. +Axiom ethereum_berlin_vm_memory_imports_buffer_read : + IsImported globals "ethereum.berlin.vm.memory" "buffer_read". Definition GQUADDIVISOR : Value.t := M.run ltac:(M.monadic ( Constant.int 3 @@ -40,9 +44,12 @@ Definition modexp : Value.t -> Value.t -> M := Calculates `(base**exp) % modulus` for arbitrary sized `base`, `exp` and. `modulus`. The return value is the same length as the modulus. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let base_length := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "base_length" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -69,8 +76,10 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exp_length := + |) + |) in + let _ := M.assign_local (| + "exp_length" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -97,8 +106,10 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let modulus_length := + |) + |) in + let _ := M.assign_local (| + "modulus_length" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -125,8 +136,10 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exp_start := + |) + |) in + let _ := M.assign_local (| + "exp_start" , BinOp.add (| M.call (| M.get_name (| globals, "U256" |), @@ -136,8 +149,10 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |), M.get_name (| globals, "base_length" |) - |) in - let exp_head := + |) + |) in + let _ := M.assign_local (| + "exp_head" , M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ @@ -165,7 +180,8 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -216,7 +232,8 @@ Definition modexp : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let base := + let _ := M.assign_local (| + "base" , M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ @@ -237,8 +254,10 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exp := + |) + |) in + let _ := M.assign_local (| + "exp" , M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ @@ -253,13 +272,17 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let modulus_start := + |) + |) in + let _ := M.assign_local (| + "modulus_start" , BinOp.add (| M.get_name (| globals, "exp_start" |), M.get_name (| globals, "exp_length" |) - |) in - let modulus := + |) + |) in + let _ := M.assign_local (| + "modulus" , M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ @@ -274,7 +297,8 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -350,7 +374,8 @@ Definition complexity : Value.t -> Value.t -> M := complexity : `Uint` Complexity of performing the operation. " in - let max_length := + let _ := M.assign_local (| + "max_length" , M.call (| M.get_name (| globals, "max" |), make_list [ @@ -370,15 +395,18 @@ Definition complexity : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| BinOp.add (| M.get_name (| globals, "max_length" |), Constant.int 7 |), Constant.int 8 - |) in + |) + |) in let _ := M.return_ (| BinOp.pow (| M.get_name (| globals, "words" |), @@ -427,14 +455,16 @@ Definition iterations : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let count := + let _ := M.assign_local (| + "count" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -447,7 +477,8 @@ Definition iterations : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let bit_length := + let _ := M.assign_local (| + "bit_length" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -458,7 +489,8 @@ Definition iterations : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -468,20 +500,25 @@ Definition iterations : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let bit_length := BinOp.sub + let _ := M.assign_op_local (| + BinOp.sub, + "bit_length", Constant.int 1 - Constant.int 1 in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let count := - M.get_name (| globals, "bit_length" |) in + let _ := M.assign_local (| + "count" , + M.get_name (| globals, "bit_length" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let length_part := + let _ := M.assign_local (| + "length_part" , BinOp.mult (| Constant.int 8, BinOp.sub (| @@ -494,8 +531,10 @@ Definition iterations : Value.t -> Value.t -> M := |), Constant.int 32 |) - |) in - let bits_part := + |) + |) in + let _ := M.assign_local (| + "bits_part" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -506,7 +545,8 @@ Definition iterations : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -516,19 +556,23 @@ Definition iterations : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let bits_part := BinOp.sub + let _ := M.assign_op_local (| + BinOp.sub, + "bits_part", Constant.int 1 - Constant.int 1 in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let count := + let _ := M.assign_local (| + "count" , BinOp.add (| M.get_name (| globals, "length_part" |), M.get_name (| globals, "bits_part" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -579,7 +623,8 @@ Definition gas_cost : Value.t -> Value.t -> M := gas_cost : `Uint` Gas required for performing the operation. " in - let multiplication_complexity := + let _ := M.assign_local (| + "multiplication_complexity" , M.call (| M.get_name (| globals, "complexity" |), make_list [ @@ -587,8 +632,10 @@ Definition gas_cost : Value.t -> Value.t -> M := M.get_name (| globals, "modulus_length" |) ], make_dict [] - |) in - let iteration_count := + |) + |) in + let _ := M.assign_local (| + "iteration_count" , M.call (| M.get_name (| globals, "iterations" |), make_list [ @@ -596,15 +643,20 @@ Definition gas_cost : Value.t -> Value.t -> M := M.get_name (| globals, "exponent_head" |) ], make_dict [] - |) in - let cost := + |) + |) in + let _ := M.assign_local (| + "cost" , BinOp.mult (| M.get_name (| globals, "multiplication_complexity" |), M.get_name (| globals, "iteration_count" |) - |) in - let cost := BinOp.floor_div + |) + |) in + let _ := M.assign_op_local (| + BinOp.floor_div, + "cost", M.get_name (| globals, "GQUADDIVISOR" |) - M.get_name (| globals, "GQUADDIVISOR" |) in + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "max" |), diff --git a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/ripemd160.v index 279665c..a699925 100644 --- a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/ripemd160.v +++ b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/ripemd160.v @@ -19,20 +19,24 @@ Implementation of the `RIPEMD160` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_left_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "left_pad_zero_bytes". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_berlin_vm_imports : - AreImported globals "ethereum.berlin.vm" [ "Evm" ]. +Axiom ethereum_berlin_vm_imports_Evm : + IsImported globals "ethereum.berlin.vm" "Evm". -Axiom ethereum_berlin_vm_gas_imports : - AreImported globals "ethereum.berlin.vm.gas" [ "GAS_RIPEMD160"; "GAS_RIPEMD160_WORD"; "charge_gas" ]. +Axiom ethereum_berlin_vm_gas_imports_GAS_RIPEMD160 : + IsImported globals "ethereum.berlin.vm.gas" "GAS_RIPEMD160". +Axiom ethereum_berlin_vm_gas_imports_GAS_RIPEMD160_WORD : + IsImported globals "ethereum.berlin.vm.gas" "GAS_RIPEMD160_WORD". +Axiom ethereum_berlin_vm_gas_imports_charge_gas : + IsImported globals "ethereum.berlin.vm.gas" "charge_gas". Definition ripemd160 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,9 +49,12 @@ Definition ripemd160 : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let word_count := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "word_count" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -69,7 +76,8 @@ Definition ripemd160 : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -84,7 +92,8 @@ Definition ripemd160 : Value.t -> Value.t -> M := ], make_dict [] |) in - let hash_bytes := + let _ := M.assign_local (| + "hash_bytes" , M.call (| M.get_field (| M.call (| M.get_field (| M.get_name (| globals, "hashlib" |), "new" |), @@ -96,8 +105,10 @@ Definition ripemd160 : Value.t -> Value.t -> M := |), "digest" |), make_list [], make_dict [] - |) in - let padded_hash := + |) + |) in + let _ := M.assign_local (| + "padded_hash" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -105,7 +116,8 @@ Definition ripemd160 : Value.t -> Value.t -> M := Constant.int 32 ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.get_name (| globals, "padded_hash" |) diff --git a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/sha256.v index 6d0aeb8..b3c060c 100644 --- a/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/sha256.v +++ b/CoqOfPython/ethereum/berlin/vm/precompiled_contracts/sha256.v @@ -19,17 +19,21 @@ Implementation of the `SHA256` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_berlin_vm_imports : - AreImported globals "ethereum.berlin.vm" [ "Evm" ]. +Axiom ethereum_berlin_vm_imports_Evm : + IsImported globals "ethereum.berlin.vm" "Evm". -Axiom ethereum_berlin_vm_gas_imports : - AreImported globals "ethereum.berlin.vm.gas" [ "GAS_SHA256"; "GAS_SHA256_WORD"; "charge_gas" ]. +Axiom ethereum_berlin_vm_gas_imports_GAS_SHA256 : + IsImported globals "ethereum.berlin.vm.gas" "GAS_SHA256". +Axiom ethereum_berlin_vm_gas_imports_GAS_SHA256_WORD : + IsImported globals "ethereum.berlin.vm.gas" "GAS_SHA256_WORD". +Axiom ethereum_berlin_vm_gas_imports_charge_gas : + IsImported globals "ethereum.berlin.vm.gas" "charge_gas". Definition sha256 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,9 +46,12 @@ Definition sha256 : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let word_count := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "word_count" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -66,7 +73,8 @@ Definition sha256 : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ diff --git a/CoqOfPython/ethereum/berlin/vm/runtime.v b/CoqOfPython/ethereum/berlin/vm/runtime.v index 3594c2e..03bc450 100644 --- a/CoqOfPython/ethereum/berlin/vm/runtime.v +++ b/CoqOfPython/ethereum/berlin/vm/runtime.v @@ -17,14 +17,14 @@ Introduction Runtime related operations used while executing EVM code. ". -Axiom typing_imports : - AreImported globals "typing" [ "Set" ]. +Axiom typing_imports_Set : + IsImported globals "typing" "Set". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_berlin_vm_instructions_imports : - AreImported globals "ethereum.berlin.vm.instructions" [ "Ops" ]. +Axiom ethereum_berlin_vm_instructions_imports_Ops : + IsImported globals "ethereum.berlin.vm.instructions" "Ops". Definition get_valid_jump_destinations : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -50,20 +50,24 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := valid_jump_destinations: `Set[Uint]` The set of valid jump destinations in the code. " in - let valid_jump_destinations := + let _ := M.assign_local (| + "valid_jump_destinations" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let pc := + |) + |) in + let _ := M.assign_local (| + "pc" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in let _ := M.while (| Compare.lt (| @@ -114,17 +118,21 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let push_data_size := + let _ := M.assign_local (| + "push_data_size" , BinOp.add (| BinOp.sub (| M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) |), Constant.int 1 - |) in - let pc := BinOp.add + |) + |) in + let _ := M.assign_op_local (| + BinOp.add, + "pc", M.get_name (| globals, "push_data_size" |) - M.get_name (| globals, "push_data_size" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -132,9 +140,11 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - let pc := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "pc", Constant.int 1 - Constant.int 1 in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/berlin/vm/stack.v b/CoqOfPython/ethereum/berlin/vm/stack.v index 7371cbc..812da9c 100644 --- a/CoqOfPython/ethereum/berlin/vm/stack.v +++ b/CoqOfPython/ethereum/berlin/vm/stack.v @@ -17,14 +17,16 @@ Introduction Implementation of the stack operators for the EVM. ". -Axiom typing_imports : - AreImported globals "typing" [ "List" ]. +Axiom typing_imports_List : + IsImported globals "typing" "List". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_berlin_vm_exceptions_imports : - AreImported globals "ethereum.berlin.vm.exceptions" [ "StackOverflowError"; "StackUnderflowError" ]. +Axiom ethereum_berlin_vm_exceptions_imports_StackOverflowError : + IsImported globals "ethereum.berlin.vm.exceptions" "StackOverflowError". +Axiom ethereum_berlin_vm_exceptions_imports_StackUnderflowError : + IsImported globals "ethereum.berlin.vm.exceptions" "StackUnderflowError". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/byzantium/__init__.v b/CoqOfPython/ethereum/byzantium/__init__.v index f918721..2dfebd4 100644 --- a/CoqOfPython/ethereum/byzantium/__init__.v +++ b/CoqOfPython/ethereum/byzantium/__init__.v @@ -9,8 +9,8 @@ lets contracts make non-state-changing calls to other contracts, and adds cryptographic primitives for layer 2 scaling. ". -Axiom ethereum_fork_criteria_imports : - AreImported globals "ethereum.fork_criteria" [ "ByBlockNumber" ]. +Axiom ethereum_fork_criteria_imports_ByBlockNumber : + IsImported globals "ethereum.fork_criteria" "ByBlockNumber". Definition FORK_CRITERIA : Value.t := M.run ltac:(M.monadic ( M.call (| diff --git a/CoqOfPython/ethereum/byzantium/blocks.v b/CoqOfPython/ethereum/byzantium/blocks.v index a4c1ca1..93405c6 100644 --- a/CoqOfPython/ethereum/byzantium/blocks.v +++ b/CoqOfPython/ethereum/byzantium/blocks.v @@ -14,23 +14,37 @@ history of all state transitions that have happened since the genesis of the chain. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Tuple" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes8"; "Bytes32"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. - -Axiom ethereum_byzantium_fork_types_imports : - AreImported globals "ethereum.byzantium.fork_types" [ "Address"; "Bloom"; "Root" ]. - -Axiom ethereum_byzantium_transactions_imports : - AreImported globals "ethereum.byzantium.transactions" [ "Transaction" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes8 : + IsImported globals "ethereum.base_types" "Bytes8". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". + +Axiom ethereum_byzantium_fork_types_imports_Address : + IsImported globals "ethereum.byzantium.fork_types" "Address". +Axiom ethereum_byzantium_fork_types_imports_Bloom : + IsImported globals "ethereum.byzantium.fork_types" "Bloom". +Axiom ethereum_byzantium_fork_types_imports_Root : + IsImported globals "ethereum.byzantium.fork_types" "Root". + +Axiom ethereum_byzantium_transactions_imports_Transaction : + IsImported globals "ethereum.byzantium.transactions" "Transaction". Definition Header : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/byzantium/bloom.v b/CoqOfPython/ethereum/byzantium/bloom.v index a89f7bc..4b8bc45 100644 --- a/CoqOfPython/ethereum/byzantium/bloom.v +++ b/CoqOfPython/ethereum/byzantium/bloom.v @@ -21,20 +21,20 @@ for efficient searching of logs by address and/or topic, by rapidly eliminating blocks and receipts from their search. ". -Axiom typing_imports : - AreImported globals "typing" [ "Tuple" ]. +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_byzantium_blocks_imports : - AreImported globals "ethereum.byzantium.blocks" [ "Log" ]. +Axiom ethereum_byzantium_blocks_imports_Log : + IsImported globals "ethereum.byzantium.blocks" "Log". -Axiom ethereum_byzantium_fork_types_imports : - AreImported globals "ethereum.byzantium.fork_types" [ "Bloom" ]. +Axiom ethereum_byzantium_fork_types_imports_Bloom : + IsImported globals "ethereum.byzantium.fork_types" "Bloom". Definition add_to_bloom : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -53,20 +53,23 @@ Definition add_to_bloom : Value.t -> Value.t -> M := bloom_entry : An entry which is to be added to bloom filter. " in - let hash := + let _ := M.assign_local (| + "hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "bloom_entry" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "idx" |), make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ], ltac:(M.monadic ( - let bit_to_set := + let _ := M.assign_local (| + "bit_to_set" , BinOp.bit_and (| M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), @@ -84,18 +87,24 @@ Definition add_to_bloom : Value.t -> Value.t -> M := make_dict [] |), Constant.int 2047 - |) in - let bit_index := + |) + |) in + let _ := M.assign_local (| + "bit_index" , BinOp.sub (| Constant.int 2047, M.get_name (| globals, "bit_to_set" |) - |) in - let byte_index := + |) + |) in + let _ := M.assign_local (| + "byte_index" , BinOp.floor_div (| M.get_name (| globals, "bit_index" |), Constant.int 8 - |) in - let bit_value := + |) + |) in + let _ := M.assign_local (| + "bit_value" , BinOp.l_shift (| Constant.int 1, BinOp.sub (| @@ -105,7 +114,8 @@ Definition add_to_bloom : Value.t -> Value.t -> M := Constant.int 8 |) |) - |) in + |) + |) in let _ := M.assign (| M.get_subscript (| M.get_name (| globals, "bloom" |), diff --git a/CoqOfPython/ethereum/byzantium/fork.v b/CoqOfPython/ethereum/byzantium/fork.v index ed39b3d..87d1e53 100644 --- a/CoqOfPython/ethereum/byzantium/fork.v +++ b/CoqOfPython/ethereum/byzantium/fork.v @@ -17,62 +17,120 @@ Introduction Entry point for the Ethereum specification. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Bytes0" ]. - -Axiom ethereum_crypto_elliptic_curve_imports : - AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. - -Axiom ethereum_ethash_imports : - AreImported globals "ethereum.ethash" [ "dataset_size"; "generate_cache"; "hashimoto_light" ]. - -Axiom ethereum_exceptions_imports : - AreImported globals "ethereum.exceptions" [ "InvalidBlock" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U64"; "U256"; "U256_CEIL_VALUE"; "Bytes"; "Uint" ]. - -Axiom ethereum_byzantium_imports : - AreImported globals "ethereum.byzantium" [ "vm" ]. - -Axiom ethereum_byzantium_blocks_imports : - AreImported globals "ethereum.byzantium.blocks" [ "Block"; "Header"; "Log"; "Receipt" ]. - -Axiom ethereum_byzantium_bloom_imports : - AreImported globals "ethereum.byzantium.bloom" [ "logs_bloom" ]. - -Axiom ethereum_byzantium_fork_types_imports : - AreImported globals "ethereum.byzantium.fork_types" [ "Address"; "Bloom"; "Root" ]. - -Axiom ethereum_byzantium_state_imports : - AreImported globals "ethereum.byzantium.state" [ "State"; "account_exists_and_is_empty"; "create_ether"; "destroy_account"; "get_account"; "increment_nonce"; "set_account_balance"; "state_root" ]. - -Axiom ethereum_byzantium_transactions_imports : - AreImported globals "ethereum.byzantium.transactions" [ "TX_BASE_COST"; "TX_CREATE_COST"; "TX_DATA_COST_PER_NON_ZERO"; "TX_DATA_COST_PER_ZERO"; "Transaction" ]. - -Axiom ethereum_byzantium_trie_imports : - AreImported globals "ethereum.byzantium.trie" [ "Trie"; "root"; "trie_set" ]. - -Axiom ethereum_byzantium_utils_message_imports : - AreImported globals "ethereum.byzantium.utils.message" [ "prepare_message" ]. - -Axiom ethereum_byzantium_vm_interpreter_imports : - AreImported globals "ethereum.byzantium.vm.interpreter" [ "process_message_call" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". + +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". + +Axiom ethereum_crypto_elliptic_curve_imports_SECP256K1N : + IsImported globals "ethereum.crypto.elliptic_curve" "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_imports_secp256k1_recover : + IsImported globals "ethereum.crypto.elliptic_curve" "secp256k1_recover". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". + +Axiom ethereum_ethash_imports_dataset_size : + IsImported globals "ethereum.ethash" "dataset_size". +Axiom ethereum_ethash_imports_generate_cache : + IsImported globals "ethereum.ethash" "generate_cache". +Axiom ethereum_ethash_imports_hashimoto_light : + IsImported globals "ethereum.ethash" "hashimoto_light". + +Axiom ethereum_exceptions_imports_InvalidBlock : + IsImported globals "ethereum.exceptions" "InvalidBlock". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U64 : + IsImported globals "ethereum.base_types" "U64". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_U256_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U256_CEIL_VALUE". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_byzantium_imports_vm : + IsImported globals "ethereum.byzantium" "vm". + +Axiom ethereum_byzantium_blocks_imports_Block : + IsImported globals "ethereum.byzantium.blocks" "Block". +Axiom ethereum_byzantium_blocks_imports_Header : + IsImported globals "ethereum.byzantium.blocks" "Header". +Axiom ethereum_byzantium_blocks_imports_Log : + IsImported globals "ethereum.byzantium.blocks" "Log". +Axiom ethereum_byzantium_blocks_imports_Receipt : + IsImported globals "ethereum.byzantium.blocks" "Receipt". + +Axiom ethereum_byzantium_bloom_imports_logs_bloom : + IsImported globals "ethereum.byzantium.bloom" "logs_bloom". + +Axiom ethereum_byzantium_fork_types_imports_Address : + IsImported globals "ethereum.byzantium.fork_types" "Address". +Axiom ethereum_byzantium_fork_types_imports_Bloom : + IsImported globals "ethereum.byzantium.fork_types" "Bloom". +Axiom ethereum_byzantium_fork_types_imports_Root : + IsImported globals "ethereum.byzantium.fork_types" "Root". + +Axiom ethereum_byzantium_state_imports_State : + IsImported globals "ethereum.byzantium.state" "State". +Axiom ethereum_byzantium_state_imports_account_exists_and_is_empty : + IsImported globals "ethereum.byzantium.state" "account_exists_and_is_empty". +Axiom ethereum_byzantium_state_imports_create_ether : + IsImported globals "ethereum.byzantium.state" "create_ether". +Axiom ethereum_byzantium_state_imports_destroy_account : + IsImported globals "ethereum.byzantium.state" "destroy_account". +Axiom ethereum_byzantium_state_imports_get_account : + IsImported globals "ethereum.byzantium.state" "get_account". +Axiom ethereum_byzantium_state_imports_increment_nonce : + IsImported globals "ethereum.byzantium.state" "increment_nonce". +Axiom ethereum_byzantium_state_imports_set_account_balance : + IsImported globals "ethereum.byzantium.state" "set_account_balance". +Axiom ethereum_byzantium_state_imports_state_root : + IsImported globals "ethereum.byzantium.state" "state_root". + +Axiom ethereum_byzantium_transactions_imports_TX_BASE_COST : + IsImported globals "ethereum.byzantium.transactions" "TX_BASE_COST". +Axiom ethereum_byzantium_transactions_imports_TX_CREATE_COST : + IsImported globals "ethereum.byzantium.transactions" "TX_CREATE_COST". +Axiom ethereum_byzantium_transactions_imports_TX_DATA_COST_PER_NON_ZERO : + IsImported globals "ethereum.byzantium.transactions" "TX_DATA_COST_PER_NON_ZERO". +Axiom ethereum_byzantium_transactions_imports_TX_DATA_COST_PER_ZERO : + IsImported globals "ethereum.byzantium.transactions" "TX_DATA_COST_PER_ZERO". +Axiom ethereum_byzantium_transactions_imports_Transaction : + IsImported globals "ethereum.byzantium.transactions" "Transaction". + +Axiom ethereum_byzantium_trie_imports_Trie : + IsImported globals "ethereum.byzantium.trie" "Trie". +Axiom ethereum_byzantium_trie_imports_root : + IsImported globals "ethereum.byzantium.trie" "root". +Axiom ethereum_byzantium_trie_imports_trie_set : + IsImported globals "ethereum.byzantium.trie" "trie_set". + +Axiom ethereum_byzantium_utils_message_imports_prepare_message : + IsImported globals "ethereum.byzantium.utils.message" "prepare_message". + +Axiom ethereum_byzantium_vm_interpreter_imports_process_message_call : + IsImported globals "ethereum.byzantium.vm.interpreter" "process_message_call". Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -190,13 +248,15 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := recent_block_hashes : `List[Hash32]` Hashes of the recent 256 blocks in order of increasing block number. " in - let recent_blocks := + let _ := M.assign_local (| + "recent_blocks" , M.slice (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |), Constant.None_, Constant.None_ - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -220,15 +280,19 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let recent_block_hashes := - make_list [] in + let _ := M.assign_local (| + "recent_block_hashes" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "block" |), M.get_name (| globals, "recent_blocks" |), ltac:(M.monadic ( - let prev_block_hash := - M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in + let _ := M.assign_local (| + "prev_block_hash" , + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), make_list [ @@ -242,7 +306,8 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let most_recent_block_hash := + let _ := M.assign_local (| + "most_recent_block_hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -258,7 +323,8 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), make_list [ @@ -295,11 +361,13 @@ Definition state_transition : Value.t -> Value.t -> M := block : Block to apply to `chain`. " in - let parent_header := + let _ := M.assign_local (| + "parent_header" , M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 1 |) - |), "header" |) in + |), "header" |) + |) in let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ @@ -317,7 +385,8 @@ Definition state_transition : Value.t -> Value.t -> M := ], make_dict [] |) in - let apply_body_output := + let _ := M.assign_local (| + "apply_body_output" , M.call (| M.get_name (| globals, "apply_body" |), make_list [ @@ -339,7 +408,8 @@ Definition state_transition : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "chain" |), "chain_id" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -453,11 +523,13 @@ Definition validate_header : Value.t -> Value.t -> M := parent_header : Parent Header of the header to check for correctness " in - let parent_has_ommers := + let _ := M.assign_local (| + "parent_has_ommers" , Compare.not_eq (| M.get_field (| M.get_name (| globals, "parent_header" |), "ommers_hash" |), M.get_name (| globals, "EMPTY_OMMER_HASH" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -515,7 +587,8 @@ Definition validate_header : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_difficulty := + let _ := M.assign_local (| + "block_difficulty" , M.call (| M.get_name (| globals, "calculate_block_difficulty" |), make_list [ @@ -526,7 +599,8 @@ Definition validate_header : Value.t -> Value.t -> M := M.get_name (| globals, "parent_has_ommers" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -538,7 +612,8 @@ Definition validate_header : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_parent_hash := + let _ := M.assign_local (| + "block_parent_hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -551,7 +626,8 @@ Definition validate_header : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -597,7 +673,8 @@ Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := hash : `Hash32` The PoW valid rlp hash of the passed in header. " in - let header_data_without_pow_artefacts := + let _ := M.assign_local (| + "header_data_without_pow_artefacts" , make_list [ M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |); M.get_field (| M.get_name (| globals, "header" |), "ommers_hash" |); @@ -612,7 +689,8 @@ Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "header" |), "gas_used" |); M.get_field (| M.get_name (| globals, "header" |), "timestamp" |); M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) - ] in + ] + |) in let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), @@ -641,22 +719,26 @@ Definition validate_proof_of_work : Value.t -> Value.t -> M := header : Header of interest. " in - let header_hash := + let _ := M.assign_local (| + "header_hash" , M.call (| M.get_name (| globals, "generate_header_hash_for_pow" |), make_list [ M.get_name (| globals, "header" |) ], make_dict [] - |) in - let cache := + |) + |) in + let _ := M.assign_local (| + "cache" , M.call (| M.get_name (| globals, "generate_cache" |), make_list [ M.get_field (| M.get_name (| globals, "header" |), "number" |) ], make_dict [] - |) in + |) + |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "mix_digest" |); M.get_name (| globals, "result" |) ], M.call (| @@ -745,7 +827,8 @@ Definition check_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_address := + let _ := M.assign_local (| + "sender_address" , M.call (| M.get_name (| globals, "recover_sender" |), make_list [ @@ -753,7 +836,8 @@ Definition check_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "tx" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "sender_address" |) |) in @@ -782,12 +866,14 @@ Definition make_receipt : Value.t -> Value.t -> M := receipt : The receipt for the transaction. " in - let receipt := + let _ := M.assign_local (| + "receipt" , M.call (| M.get_name (| globals, "Receipt" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "receipt" |) |) in @@ -846,8 +932,10 @@ Definition apply_body : Value.t -> Value.t -> M := apply_body_output : `ApplyBodyOutput` Output of applying the block body to the state. " in - let gas_available := - M.get_name (| globals, "block_gas_limit" |) in + let _ := M.assign_local (| + "gas_available" , + M.get_name (| globals, "block_gas_limit" |) + |) in (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) @@ -883,7 +971,8 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_address := + let _ := M.assign_local (| + "sender_address" , M.call (| M.get_name (| globals, "check_transaction" |), make_list [ @@ -892,13 +981,16 @@ Definition apply_body : Value.t -> Value.t -> M := M.get_name (| globals, "chain_id" |) ], make_dict [] - |) in - let env := + |) + |) in + let _ := M.assign_local (| + "env" , M.call (| M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |); M.get_name (| globals, "error" |) ], M.call (| @@ -910,10 +1002,13 @@ Definition apply_body : Value.t -> Value.t -> M := make_dict [] |) |) in - let gas_available := BinOp.sub + let _ := M.assign_op_local (| + BinOp.sub, + "gas_available", M.get_name (| globals, "gas_used" |) - M.get_name (| globals, "gas_used" |) in - let receipt := + |) in + let _ := M.assign_local (| + "receipt" , M.call (| M.get_name (| globals, "make_receipt" |), make_list [ @@ -926,7 +1021,8 @@ Definition apply_body : Value.t -> Value.t -> M := M.get_name (| globals, "logs" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ @@ -948,9 +1044,11 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_logs := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "block_logs", M.get_name (| globals, "logs" |) - M.get_name (| globals, "logs" |) in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -967,19 +1065,23 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_gas_used := + let _ := M.assign_local (| + "block_gas_used" , BinOp.sub (| M.get_name (| globals, "block_gas_limit" |), M.get_name (| globals, "gas_available" |) - |) in - let block_logs_bloom := + |) + |) in + let _ := M.assign_local (| + "block_logs_bloom" , M.call (| M.get_name (| globals, "logs_bloom" |), make_list [ M.get_name (| globals, "block_logs" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ApplyBodyOutput" |), @@ -1037,14 +1139,16 @@ Definition validate_ommers : Value.t -> Value.t -> M := chain : History and current state. " in - let block_hash := + let _ := M.assign_local (| + "block_hash" , M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), make_list [ M.get_name (| globals, "block_header" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1109,7 +1213,8 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_parent_header := + let _ := M.assign_local (| + "ommer_parent_header" , M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), BinOp.sub (| @@ -1119,7 +1224,8 @@ Definition validate_ommers : Value.t -> Value.t -> M := |) |), Constant.int 1 |) - |), "header" |) in + |), "header" |) + |) in let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ @@ -1151,8 +1257,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommers_hashes := - Constant.str "(* At expr: unsupported node type: ListComp *)" in + let _ := M.assign_local (| + "ommers_hashes" , + Constant.str "(* At expr: unsupported node type: ListComp *)" + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1182,7 +1290,8 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let recent_canonical_blocks := + let _ := M.assign_local (| + "recent_canonical_blocks" , M.slice (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| BinOp.add (| @@ -1191,23 +1300,28 @@ Definition validate_ommers : Value.t -> Value.t -> M := |) |), Constant.None_, Constant.None_ - |) in - let recent_canonical_block_hashes := - Constant.str "(* At expr: unsupported node type: SetComp *)" in + |) + |) in + let _ := M.assign_local (| + "recent_canonical_block_hashes" , + Constant.str "(* At expr: unsupported node type: SetComp *)" + |) in (* At stmt: unsupported node type: AnnAssign *) let _ := M.for_ (| M.get_name (| globals, "block" |), M.get_name (| globals, "recent_canonical_blocks" |), ltac:(M.monadic ( - let recent_ommers_hashes := + let _ := M.assign_local (| + "recent_ommers_hashes" , M.call (| M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), make_list [ Constant.str "(* At expr: unsupported node type: SetComp *)" ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -1225,11 +1339,13 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let ommer_hash := + let _ := M.assign_local (| + "ommer_hash" , M.get_subscript (| M.get_name (| globals, "ommers_hashes" |), M.get_name (| globals, "ommer_index" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1263,11 +1379,13 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_age := + let _ := M.assign_local (| + "ommer_age" , BinOp.sub (| M.get_field (| M.get_name (| globals, "block_header" |), "number" |), M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1345,7 +1463,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := ommers : List of ommers mentioned in the current block. " in - let miner_reward := + let _ := M.assign_local (| + "miner_reward" , BinOp.add (| M.get_name (| globals, "BLOCK_REWARD" |), BinOp.mult (| @@ -1361,7 +1480,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := Constant.int 32 |) |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "create_ether" |), make_list [ @@ -1376,7 +1496,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := M.get_name (| globals, "ommer" |), M.get_name (| globals, "ommers" |), ltac:(M.monadic ( - let ommer_age := + let _ := M.assign_local (| + "ommer_age" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -1386,8 +1507,10 @@ Definition pay_rewards : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let ommer_miner_reward := + |) + |) in + let _ := M.assign_local (| + "ommer_miner_reward" , BinOp.floor_div (| BinOp.mult (| BinOp.sub (| @@ -1397,7 +1520,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := M.get_name (| globals, "BLOCK_REWARD" |) |), Constant.int 8 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "create_ether" |), make_list [ @@ -1458,9 +1582,12 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender := - M.get_field (| M.get_name (| globals, "env" |), "origin" |) in - let sender_account := + let _ := M.assign_local (| + "sender" , + M.get_field (| M.get_name (| globals, "env" |), "origin" |) + |) in + let _ := M.assign_local (| + "sender_account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1468,12 +1595,15 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "sender" |) ], make_dict [] - |) in - let gas_fee := + |) + |) in + let _ := M.assign_local (| + "gas_fee" , BinOp.mult (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1514,7 +1644,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let gas := + let _ := M.assign_local (| + "gas" , BinOp.sub (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.call (| @@ -1524,7 +1655,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "increment_nonce" |), make_list [ @@ -1533,11 +1665,13 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_balance_after_gas_fee := + let _ := M.assign_local (| + "sender_balance_after_gas_fee" , BinOp.sub (| M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), M.get_name (| globals, "gas_fee" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -1547,7 +1681,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let message := + let _ := M.assign_local (| + "message" , M.call (| M.get_name (| globals, "prepare_message" |), make_list [ @@ -1559,8 +1694,10 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in - let output := + |) + |) in + let _ := M.assign_local (| + "output" , M.call (| M.get_name (| globals, "process_message_call" |), make_list [ @@ -1568,13 +1705,17 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in - let gas_used := + |) + |) in + let _ := M.assign_local (| + "gas_used" , BinOp.sub (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_field (| M.get_name (| globals, "output" |), "gas_left" |) - |) in - let gas_refund := + |) + |) in + let _ := M.assign_local (| + "gas_refund" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -1585,16 +1726,20 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "output" |), "refund_counter" |) ], make_dict [] - |) in - let gas_refund_amount := + |) + |) in + let _ := M.assign_local (| + "gas_refund_amount" , BinOp.mult (| BinOp.add (| M.get_field (| M.get_name (| globals, "output" |), "gas_left" |), M.get_name (| globals, "gas_refund" |) |), M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) - |) in - let transaction_fee := + |) + |) in + let _ := M.assign_local (| + "transaction_fee" , BinOp.mult (| BinOp.sub (| BinOp.sub (| @@ -1604,13 +1749,17 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "gas_refund" |) |), M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) - |) in - let total_gas_used := + |) + |) in + let _ := M.assign_local (| + "total_gas_used" , BinOp.sub (| M.get_name (| globals, "gas_used" |), M.get_name (| globals, "gas_refund" |) - |) in - let sender_balance_after_refund := + |) + |) in + let _ := M.assign_local (| + "sender_balance_after_refund" , BinOp.add (| M.get_field (| M.call (| M.get_name (| globals, "get_account" |), @@ -1621,7 +1770,8 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |), "balance" |), M.get_name (| globals, "gas_refund_amount" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -1631,7 +1781,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let coinbase_balance_after_mining_fee := + let _ := M.assign_local (| + "coinbase_balance_after_mining_fee" , BinOp.add (| M.get_field (| M.call (| M.get_name (| globals, "get_account" |), @@ -1642,7 +1793,8 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |), "balance" |), M.get_name (| globals, "transaction_fee" |) - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1833,8 +1985,10 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := verified : `ethereum.base_types.Uint` The intrinsic cost of the transaction. " in - let data_cost := - Constant.int 0 in + let _ := M.assign_local (| + "data_cost" , + Constant.int 0 + |) in let _ := M.for_ (| M.get_name (| globals, "byte" |), @@ -1849,15 +2003,19 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let data_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "data_cost", M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let data_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "data_cost", M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -1881,13 +2039,17 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let create_cost := - M.get_name (| globals, "TX_CREATE_COST" |) in + let _ := M.assign_local (| + "create_cost" , + M.get_name (| globals, "TX_CREATE_COST" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let create_cost := - Constant.int 0 in + let _ := M.assign_local (| + "create_cost" , + Constant.int 0 + |) in M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1993,7 +2155,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let public_key := + let _ := M.assign_local (| + "public_key" , M.call (| M.get_name (| globals, "secp256k1_recover" |), make_list [ @@ -2012,7 +2175,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -2047,7 +2211,8 @@ Definition recover_sender : Value.t -> Value.t -> M := ], make_dict [] |) in - let public_key := + let _ := M.assign_local (| + "public_key" , M.call (| M.get_name (| globals, "secp256k1_recover" |), make_list [ @@ -2073,7 +2238,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -2259,11 +2425,13 @@ Definition check_gas_limit : Value.t -> Value.t -> M := check : `bool` True if gas limit constraints are satisfied, False otherwise. " in - let max_adjustment_delta := + let _ := M.assign_local (| + "max_adjustment_delta" , BinOp.floor_div (| M.get_name (| globals, "parent_gas_limit" |), M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -2367,7 +2535,8 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := difficulty : `ethereum.base_types.Uint` Computed difficulty for a block. " in - let offset := + let _ := M.assign_local (| + "offset" , BinOp.mult (| BinOp.floor_div (| M.call (| @@ -2411,8 +2580,10 @@ Constant.int 1 ], make_dict [] |) - |) in - let difficulty := + |) + |) in + let _ := M.assign_local (| + "difficulty" , BinOp.add (| M.call (| M.get_name (| globals, "int" |), @@ -2422,8 +2593,10 @@ Constant.int 1 make_dict [] |), M.get_name (| globals, "offset" |) - |) in - let num_bomb_periods := + |) + |) in + let _ := M.assign_local (| + "num_bomb_periods" , BinOp.sub (| BinOp.floor_div (| BinOp.sub (| @@ -2439,7 +2612,8 @@ Constant.int 1 Constant.int 100000 |), Constant.int 2 - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -2449,15 +2623,14 @@ Constant.int 1 |), (* then *) ltac:(M.monadic ( - let difficulty := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "difficulty", BinOp.pow (| Constant.int 2, M.get_name (| globals, "num_bomb_periods" |) |) - BinOp.pow (| - Constant.int 2, - M.get_name (| globals, "num_bomb_periods" |) - |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/byzantium/fork_types.v b/CoqOfPython/ethereum/byzantium/fork_types.v index 40d441b..b564ee7 100644 --- a/CoqOfPython/ethereum/byzantium/fork_types.v +++ b/CoqOfPython/ethereum/byzantium/fork_types.v @@ -17,17 +17,29 @@ Introduction Types re-used throughout the specification, which are specific to Ethereum. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes20"; "Bytes256"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes20 : + IsImported globals "ethereum.base_types" "Bytes20". +Axiom ethereum_base_types_imports_Bytes256 : + IsImported globals "ethereum.base_types" "Bytes256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) diff --git a/CoqOfPython/ethereum/byzantium/state.v b/CoqOfPython/ethereum/byzantium/state.v index 038c479..525fbd8 100644 --- a/CoqOfPython/ethereum/byzantium/state.v +++ b/CoqOfPython/ethereum/byzantium/state.v @@ -22,23 +22,55 @@ There is a distinction between an account that does not exist and `EMPTY_ACCOUNT`. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass"; "field" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict"; "List"; "Optional"; "Tuple" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "modify" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_byzantium_fork_types_imports : - AreImported globals "ethereum.byzantium.fork_types" [ "EMPTY_ACCOUNT"; "Account"; "Address"; "Root" ]. - -Axiom ethereum_byzantium_trie_imports : - AreImported globals "ethereum.byzantium.trie" [ "EMPTY_TRIE_ROOT"; "Trie"; "copy_trie"; "root"; "trie_get"; "trie_set" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". +Axiom dataclasses_imports_field : + IsImported globals "dataclasses" "field". + +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_modify : + IsImported globals "ethereum.base_types" "modify". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_byzantium_fork_types_imports_EMPTY_ACCOUNT : + IsImported globals "ethereum.byzantium.fork_types" "EMPTY_ACCOUNT". +Axiom ethereum_byzantium_fork_types_imports_Account : + IsImported globals "ethereum.byzantium.fork_types" "Account". +Axiom ethereum_byzantium_fork_types_imports_Address : + IsImported globals "ethereum.byzantium.fork_types" "Address". +Axiom ethereum_byzantium_fork_types_imports_Root : + IsImported globals "ethereum.byzantium.fork_types" "Root". + +Axiom ethereum_byzantium_trie_imports_EMPTY_TRIE_ROOT : + IsImported globals "ethereum.byzantium.trie" "EMPTY_TRIE_ROOT". +Axiom ethereum_byzantium_trie_imports_Trie : + IsImported globals "ethereum.byzantium.trie" "Trie". +Axiom ethereum_byzantium_trie_imports_copy_trie : + IsImported globals "ethereum.byzantium.trie" "copy_trie". +Axiom ethereum_byzantium_trie_imports_root : + IsImported globals "ethereum.byzantium.trie" "root". +Axiom ethereum_byzantium_trie_imports_trie_get : + IsImported globals "ethereum.byzantium.trie" "trie_get". +Axiom ethereum_byzantium_trie_imports_trie_set : + IsImported globals "ethereum.byzantium.trie" "trie_set". Definition State : Value.t := builtins.make_klass @@ -153,7 +185,8 @@ Definition get_account : Value.t -> Value.t -> M := account : `Account` Account at address. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account_optional" |), make_list [ @@ -161,7 +194,8 @@ Definition get_account : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -207,7 +241,8 @@ Definition get_account_optional : Value.t -> Value.t -> M := account : `Account` Account at address. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "trie_get" |), make_list [ @@ -215,7 +250,8 @@ Definition get_account_optional : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "account" |) |) in @@ -338,14 +374,16 @@ Definition get_storage : Value.t -> Value.t -> M := value : `U256` Value at the key. " in - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -369,7 +407,8 @@ Definition get_storage : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "trie_get" |), make_list [ @@ -377,7 +416,8 @@ Definition get_storage : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -420,14 +460,16 @@ Definition set_storage : Value.t -> Value.t -> M := |), Constant.None_ |) |) in - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -437,12 +479,14 @@ Definition set_storage : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_name (| globals, "Trie" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), @@ -469,7 +513,7 @@ Definition set_storage : Value.t -> Value.t -> M := M.if_then_else (| Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), - {} + Constant.str "(* At expr: unsupported node type: Dict *)" |), (* then *) ltac:(M.monadic ( @@ -615,7 +659,8 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := True if if an account has non zero nonce or non empty code, False otherwise. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -623,7 +668,8 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| BoolOp.or (| Compare.not_eq (| @@ -665,7 +711,8 @@ Definition is_account_empty : Value.t -> Value.t -> M := True if if an account has zero nonce, empty code and zero balance, False otherwise. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -673,7 +720,8 @@ Definition is_account_empty : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| BoolOp.and (| Compare.eq (| @@ -724,7 +772,8 @@ Definition account_exists_and_is_empty : Value.t -> Value.t -> M := True if an account exists and has zero nonce, empty code and zero balance, False otherwise. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account_optional" |), make_list [ @@ -732,7 +781,8 @@ Definition account_exists_and_is_empty : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| BoolOp.and (| Compare.is_not (| @@ -789,7 +839,8 @@ Definition is_account_alive : Value.t -> Value.t -> M := is_alive : `bool` True if the account is alive. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account_optional" |), make_list [ @@ -797,7 +848,8 @@ Definition is_account_alive : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| diff --git a/CoqOfPython/ethereum/byzantium/transactions.v b/CoqOfPython/ethereum/byzantium/transactions.v index a47dce9..d474dfc 100644 --- a/CoqOfPython/ethereum/byzantium/transactions.v +++ b/CoqOfPython/ethereum/byzantium/transactions.v @@ -9,17 +9,25 @@ submitted to be executed. If Ethereum is viewed as a state machine, transactions are the events that move between states. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Union" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_byzantium_fork_types_imports : - AreImported globals "ethereum.byzantium.fork_types" [ "Address" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_Union : + IsImported globals "typing" "Union". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_byzantium_fork_types_imports_Address : + IsImported globals "ethereum.byzantium.fork_types" "Address". Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( Constant.int 21000 diff --git a/CoqOfPython/ethereum/byzantium/trie.v b/CoqOfPython/ethereum/byzantium/trie.v index 93b8822..4999d6e 100644 --- a/CoqOfPython/ethereum/byzantium/trie.v +++ b/CoqOfPython/ethereum/byzantium/trie.v @@ -20,38 +20,72 @@ The state trie is the structure responsible for storing (* At top_level_stmt: unsupported node type: Import *) -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass"; "field" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict"; "Generic"; "List"; "Mapping"; "MutableMapping"; "Optional"; "Sequence"; "TypeVar"; "Union"; "cast" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. - -Axiom ethereum_spurious_dragon_imports : - AreImported globals "ethereum.spurious_dragon" [ "trie" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_utils_hexadecimal_imports : - AreImported globals "ethereum.utils.hexadecimal" [ "hex_to_bytes" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_byzantium_blocks_imports : - AreImported globals "ethereum.byzantium.blocks" [ "Receipt" ]. - -Axiom ethereum_byzantium_fork_types_imports : - AreImported globals "ethereum.byzantium.fork_types" [ "Account"; "Address"; "Root"; "encode_account" ]. - -Axiom ethereum_byzantium_transactions_imports : - AreImported globals "ethereum.byzantium.transactions" [ "Transaction" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". +Axiom dataclasses_imports_field : + IsImported globals "dataclasses" "field". + +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". +Axiom typing_imports_Generic : + IsImported globals "typing" "Generic". +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Mapping : + IsImported globals "typing" "Mapping". +Axiom typing_imports_MutableMapping : + IsImported globals "typing" "MutableMapping". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Sequence : + IsImported globals "typing" "Sequence". +Axiom typing_imports_TypeVar : + IsImported globals "typing" "TypeVar". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". +Axiom typing_imports_cast : + IsImported globals "typing" "cast". + +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". + +Axiom ethereum_spurious_dragon_imports_trie : + IsImported globals "ethereum.spurious_dragon" "trie". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_utils_hexadecimal_imports_hex_to_bytes : + IsImported globals "ethereum.utils.hexadecimal" "hex_to_bytes". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_byzantium_blocks_imports_Receipt : + IsImported globals "ethereum.byzantium.blocks" "Receipt". + +Axiom ethereum_byzantium_fork_types_imports_Account : + IsImported globals "ethereum.byzantium.fork_types" "Account". +Axiom ethereum_byzantium_fork_types_imports_Address : + IsImported globals "ethereum.byzantium.fork_types" "Address". +Axiom ethereum_byzantium_fork_types_imports_Root : + IsImported globals "ethereum.byzantium.fork_types" "Root". +Axiom ethereum_byzantium_fork_types_imports_encode_account : + IsImported globals "ethereum.byzantium.fork_types" "encode_account". + +Axiom ethereum_byzantium_transactions_imports_Transaction : + IsImported globals "ethereum.byzantium.transactions" "Transaction". Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -161,7 +195,7 @@ Definition encode_internal_node : Value.t -> Value.t -> M := when serialized. This function also accepts `None`, representing the absence of a node, - which is encoded to `b""""""`. + which is encoded to `b""""`. Parameters ---------- @@ -183,8 +217,10 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := - Constant.bytes "" in + let _ := M.assign_local (| + "unencoded" , + Constant.bytes "" + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -201,7 +237,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := + let _ := M.assign_local (| + "unencoded" , make_tuple [ M.call (| M.get_name (| globals, "nibble_list_to_compact" |), make_list [ @@ -209,7 +246,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := Constant.bool true ], make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in + |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -226,7 +264,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := + let _ := M.assign_local (| + "unencoded" , make_tuple [ M.call (| M.get_name (| globals, "nibble_list_to_compact" |), make_list [ @@ -234,7 +273,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := Constant.bool false ], make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in + |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -251,13 +291,15 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := + let _ := M.assign_local (| + "unencoded" , BinOp.add (| M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), make_list [ M.get_field (| M.get_name (| globals, "node" |), "value" |) ] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -276,14 +318,16 @@ Definition encode_internal_node : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - let encoded := + let _ := M.assign_local (| + "encoded" , M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), make_list [ M.get_name (| globals, "unencoded" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -675,12 +719,14 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := compressed : `bytearray` Compact byte array. " in - let compact := + let _ := M.assign_local (| + "compact" , M.call (| M.get_name (| globals, "bytearray" |), make_list [], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -860,7 +906,8 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := nibble_list : `Bytes` The `Bytes` in nibble-list format. " in - let nibble_list := + let _ := M.assign_local (| + "nibble_list" , M.call (| M.get_name (| globals, "bytearray" |), make_list [ @@ -876,7 +923,8 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ], @@ -984,15 +1032,18 @@ Definition _prepare_trie : Value.t -> Value.t -> M := M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "Address" |), make_list [ M.get_name (| globals, "preimage" |) ], make_dict [] - |) in - let encoded_value := + |) + |) in + let _ := M.assign_local (| + "encoded_value" , M.call (| M.get_name (| globals, "encode_node" |), make_list [ @@ -1006,18 +1057,21 @@ Definition _prepare_trie : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let encoded_value := + let _ := M.assign_local (| + "encoded_value" , M.call (| M.get_name (| globals, "encode_node" |), make_list [ M.get_name (| globals, "value" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -1038,19 +1092,23 @@ Definition _prepare_trie : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "trie" |), "secured" |), (* then *) ltac:(M.monadic ( - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "preimage" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let key := - M.get_name (| globals, "preimage" |) in + let _ := M.assign_local (| + "key" , + M.get_name (| globals, "preimage" |) + |) in M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -1097,7 +1155,8 @@ Definition root : Value.t -> Value.t -> M := root : `.fork_types.Root` MPT root of the underlying key-value pairs. " in - let obj := + let _ := M.assign_local (| + "obj" , M.call (| M.get_name (| globals, "_prepare_trie" |), make_list [ @@ -1105,8 +1164,10 @@ Definition root : Value.t -> Value.t -> M := M.get_name (| globals, "get_storage_root" |) ], make_dict [] - |) in - let root_node := + |) + |) in + let _ := M.assign_local (| + "root_node" , M.call (| M.get_name (| globals, "encode_internal_node" |), make_list [ @@ -1126,7 +1187,8 @@ Definition root : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1231,7 +1293,8 @@ Definition patricialize : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let arbitrary_key := + let _ := M.assign_local (| + "arbitrary_key" , M.call (| M.get_name (| globals, "next" |), make_list [ @@ -1244,7 +1307,8 @@ Definition patricialize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1260,7 +1324,8 @@ Definition patricialize : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let leaf := + let _ := M.assign_local (| + "leaf" , M.call (| M.get_name (| globals, "LeafNode" |), make_list [ @@ -1276,7 +1341,8 @@ Definition patricialize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "leaf" |) |) in @@ -1285,27 +1351,32 @@ Definition patricialize : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let substring := + let _ := M.assign_local (| + "substring" , M.slice (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |), Constant.None_, Constant.None_ - |) in - let prefix_length := + |) + |) in + let _ := M.assign_local (| + "prefix_length" , M.call (| M.get_name (| globals, "len" |), make_list [ M.get_name (| globals, "substring" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "key" |), M.get_name (| globals, "obj" |), ltac:(M.monadic ( - let prefix_length := + let _ := M.assign_local (| + "prefix_length" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -1325,7 +1396,8 @@ Definition patricialize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1356,7 +1428,8 @@ Definition patricialize : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let prefix := + let _ := M.assign_local (| + "prefix" , M.slice (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |), @@ -1365,7 +1438,8 @@ Definition patricialize : Value.t -> Value.t -> M := M.get_name (| globals, "prefix_length" |) |), Constant.None_ - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ExtensionNode" |), @@ -1412,7 +1486,7 @@ Definition patricialize : Value.t -> Value.t -> M := let _ := M.call (| M.get_field (| M.get_name (| globals, "branches" |), "append" |), make_list [ - {} + Constant.str "(* At expr: unsupported node type: Dict *)" ], make_dict [] |) in @@ -1422,8 +1496,10 @@ Definition patricialize : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let value := - Constant.bytes "" in + let _ := M.assign_local (| + "value" , + Constant.bytes "" + |) in let _ := M.for_ (| M.get_name (| globals, "key" |), @@ -1466,11 +1542,13 @@ Definition patricialize : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let value := + let _ := M.assign_local (| + "value" , M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/byzantium/utils/address.v b/CoqOfPython/ethereum/byzantium/utils/address.v index 5b41324..f8a4ecd 100644 --- a/CoqOfPython/ethereum/byzantium/utils/address.v +++ b/CoqOfPython/ethereum/byzantium/utils/address.v @@ -18,23 +18,25 @@ Address specific functions used in this byzantium version of specification. ". -Axiom typing_imports : - AreImported globals "typing" [ "Union" ]. +Axiom typing_imports_Union : + IsImported globals "typing" "Union". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_left_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "left_pad_zero_bytes". -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". -Axiom ethereum_byzantium_fork_types_imports : - AreImported globals "ethereum.byzantium.fork_types" [ "Address" ]. +Axiom ethereum_byzantium_fork_types_imports_Address : + IsImported globals "ethereum.byzantium.fork_types" "Address". Definition to_address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -91,7 +93,8 @@ Definition compute_contract_address : Value.t -> Value.t -> M := address: `ethereum.byzantium.fork_types.Address` The computed address of the new account. " in - let computed_address := + let _ := M.assign_local (| + "computed_address" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -107,15 +110,19 @@ Definition compute_contract_address : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let canonical_address := + |) + |) in + let _ := M.assign_local (| + "canonical_address" , M.slice (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |), Constant.None_, Constant.None_ - |) in - let padded_address := + |) + |) in + let _ := M.assign_local (| + "padded_address" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -123,7 +130,8 @@ Definition compute_contract_address : Value.t -> Value.t -> M := Constant.int 20 ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Address" |), diff --git a/CoqOfPython/ethereum/byzantium/utils/hexadecimal.v b/CoqOfPython/ethereum/byzantium/utils/hexadecimal.v index 23c4d87..5540c16 100644 --- a/CoqOfPython/ethereum/byzantium/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/byzantium/utils/hexadecimal.v @@ -18,11 +18,15 @@ Hexadecimal utility functions used in this specification, specific to Byzantium types. ". -Axiom ethereum_utils_hexadecimal_imports : - AreImported globals "ethereum.utils.hexadecimal" [ "remove_hex_prefix" ]. - -Axiom ethereum_byzantium_fork_types_imports : - AreImported globals "ethereum.byzantium.fork_types" [ "Address"; "Bloom"; "Root" ]. +Axiom ethereum_utils_hexadecimal_imports_remove_hex_prefix : + IsImported globals "ethereum.utils.hexadecimal" "remove_hex_prefix". + +Axiom ethereum_byzantium_fork_types_imports_Address : + IsImported globals "ethereum.byzantium.fork_types" "Address". +Axiom ethereum_byzantium_fork_types_imports_Bloom : + IsImported globals "ethereum.byzantium.fork_types" "Bloom". +Axiom ethereum_byzantium_fork_types_imports_Root : + IsImported globals "ethereum.byzantium.fork_types" "Root". Definition hex_to_root : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/byzantium/utils/message.v b/CoqOfPython/ethereum/byzantium/utils/message.v index 4003c44..c60fbeb 100644 --- a/CoqOfPython/ethereum/byzantium/utils/message.v +++ b/CoqOfPython/ethereum/byzantium/utils/message.v @@ -18,23 +18,33 @@ Message specific functions used in this byzantium version of specification. ". -Axiom typing_imports : - AreImported globals "typing" [ "Optional"; "Union" ]. +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_byzantium_fork_types_imports : - AreImported globals "ethereum.byzantium.fork_types" [ "Address" ]. +Axiom ethereum_byzantium_fork_types_imports_Address : + IsImported globals "ethereum.byzantium.fork_types" "Address". -Axiom ethereum_byzantium_state_imports : - AreImported globals "ethereum.byzantium.state" [ "get_account" ]. +Axiom ethereum_byzantium_state_imports_get_account : + IsImported globals "ethereum.byzantium.state" "get_account". -Axiom ethereum_byzantium_vm_imports : - AreImported globals "ethereum.byzantium.vm" [ "Environment"; "Message" ]. +Axiom ethereum_byzantium_vm_imports_Environment : + IsImported globals "ethereum.byzantium.vm" "Environment". +Axiom ethereum_byzantium_vm_imports_Message : + IsImported globals "ethereum.byzantium.vm" "Message". -Axiom ethereum_byzantium_utils_address_imports : - AreImported globals "ethereum.byzantium.utils.address" [ "compute_contract_address" ]. +Axiom ethereum_byzantium_utils_address_imports_compute_contract_address : + IsImported globals "ethereum.byzantium.utils.address" "compute_contract_address". Definition prepare_message : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -84,7 +94,8 @@ Definition prepare_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let current_target := + let _ := M.assign_local (| + "current_target" , M.call (| M.get_name (| globals, "compute_contract_address" |), make_list [ @@ -108,17 +119,22 @@ Definition prepare_message : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let msg_data := + |) + |) in + let _ := M.assign_local (| + "msg_data" , M.call (| M.get_name (| globals, "Bytes" |), make_list [ Constant.bytes "" ], make_dict [] - |) in - let code := - M.get_name (| globals, "data" |) in + |) + |) in + let _ := M.assign_local (| + "code" , + M.get_name (| globals, "data" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -135,11 +151,16 @@ Definition prepare_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let current_target := - M.get_name (| globals, "target" |) in - let msg_data := - M.get_name (| globals, "data" |) in - let code := + let _ := M.assign_local (| + "current_target" , + M.get_name (| globals, "target" |) + |) in + let _ := M.assign_local (| + "msg_data" , + M.get_name (| globals, "data" |) + |) in + let _ := M.assign_local (| + "code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -147,7 +168,8 @@ Definition prepare_message : Value.t -> Value.t -> M := M.get_name (| globals, "target" |) ], make_dict [] - |), "code" |) in + |), "code" |) + |) in let _ := (* if *) M.if_then_else (| @@ -157,8 +179,10 @@ Definition prepare_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let code_address := - M.get_name (| globals, "target" |) in + let _ := M.assign_local (| + "code_address" , + M.get_name (| globals, "target" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/byzantium/vm/__init__.v b/CoqOfPython/ethereum/byzantium/vm/__init__.v index 3e2b32d..b02d05c 100644 --- a/CoqOfPython/ethereum/byzantium/vm/__init__.v +++ b/CoqOfPython/ethereum/byzantium/vm/__init__.v @@ -18,29 +18,45 @@ The abstract computer which runs the code stored in an `.fork_types.Account`. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple"; "Union" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. - -Axiom ethereum_byzantium_blocks_imports : - AreImported globals "ethereum.byzantium.blocks" [ "Log" ]. - -Axiom ethereum_byzantium_fork_types_imports : - AreImported globals "ethereum.byzantium.fork_types" [ "Address" ]. - -Axiom ethereum_byzantium_state_imports : - AreImported globals "ethereum.byzantium.state" [ "State"; "account_exists_and_is_empty" ]. - -Axiom ethereum_byzantium_vm_precompiled_contracts_imports : - AreImported globals "ethereum.byzantium.vm.precompiled_contracts" [ "RIPEMD160_ADDRESS" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". + +Axiom ethereum_byzantium_blocks_imports_Log : + IsImported globals "ethereum.byzantium.blocks" "Log". + +Axiom ethereum_byzantium_fork_types_imports_Address : + IsImported globals "ethereum.byzantium.fork_types" "Address". + +Axiom ethereum_byzantium_state_imports_State : + IsImported globals "ethereum.byzantium.state" "State". +Axiom ethereum_byzantium_state_imports_account_exists_and_is_empty : + IsImported globals "ethereum.byzantium.state" "account_exists_and_is_empty". + +Axiom ethereum_byzantium_vm_precompiled_contracts_imports_RIPEMD160_ADDRESS : + IsImported globals "ethereum.byzantium.vm.precompiled_contracts" "RIPEMD160_ADDRESS". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] diff --git a/CoqOfPython/ethereum/byzantium/vm/exceptions.v b/CoqOfPython/ethereum/byzantium/vm/exceptions.v index 079a2a6..7375e6c 100644 --- a/CoqOfPython/ethereum/byzantium/vm/exceptions.v +++ b/CoqOfPython/ethereum/byzantium/vm/exceptions.v @@ -17,8 +17,8 @@ Introduction Exceptions which cause the EVM to halt exceptionally. ". -Axiom ethereum_exceptions_imports : - AreImported globals "ethereum.exceptions" [ "EthereumException" ]. +Axiom ethereum_exceptions_imports_EthereumException : + IsImported globals "ethereum.exceptions" "EthereumException". Definition ExceptionalHalt : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/byzantium/vm/gas.v b/CoqOfPython/ethereum/byzantium/vm/gas.v index ea3b305..bd2fb66 100644 --- a/CoqOfPython/ethereum/byzantium/vm/gas.v +++ b/CoqOfPython/ethereum/byzantium/vm/gas.v @@ -17,26 +17,32 @@ Introduction EVM gas constants and calculators. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Tuple" ]. +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_trace_imports : - AreImported globals "ethereum.trace" [ "GasAndRefund"; "evm_trace" ]. +Axiom ethereum_trace_imports_GasAndRefund : + IsImported globals "ethereum.trace" "GasAndRefund". +Axiom ethereum_trace_imports_evm_trace : + IsImported globals "ethereum.trace" "evm_trace". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_byzantium_vm_imports : - AreImported globals "ethereum.byzantium.vm" [ "Evm" ]. +Axiom ethereum_byzantium_vm_imports_Evm : + IsImported globals "ethereum.byzantium.vm" "Evm". -Axiom ethereum_byzantium_vm_exceptions_imports : - AreImported globals "ethereum.byzantium.vm.exceptions" [ "OutOfGasError" ]. +Axiom ethereum_byzantium_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.byzantium.vm.exceptions" "OutOfGasError". Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -532,7 +538,8 @@ Definition calculate_memory_gas_cost : Value.t -> Value.t -> M := total_gas_cost : `ethereum.base_types.Uint` The gas cost for storing data in memory. " in - let size_in_words := + let _ := M.assign_local (| + "size_in_words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -542,25 +549,32 @@ Definition calculate_memory_gas_cost : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let linear_cost := + |) + |) in + let _ := M.assign_local (| + "linear_cost" , BinOp.mult (| M.get_name (| globals, "size_in_words" |), M.get_name (| globals, "GAS_MEMORY" |) - |) in - let quadratic_cost := + |) + |) in + let _ := M.assign_local (| + "quadratic_cost" , BinOp.floor_div (| BinOp.pow (| M.get_name (| globals, "size_in_words" |), Constant.int 2 |), Constant.int 512 - |) in - let total_gas_cost := + |) + |) in + let _ := M.assign_local (| + "total_gas_cost" , BinOp.add (| M.get_name (| globals, "linear_cost" |), M.get_name (| globals, "quadratic_cost" |) - |) in + |) + |) in (* At stmt: unsupported node type: Try *) M.pure Constant.None_)). @@ -582,23 +596,28 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := ------- extend_memory: `ExtendMemory` " in - let size_to_extend := + let _ := M.assign_local (| + "size_to_extend" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in - let to_be_paid := + |) + |) in + let _ := M.assign_local (| + "to_be_paid" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in - let current_size := + |) + |) in + let _ := M.assign_local (| + "current_size" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -611,7 +630,8 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ], @@ -632,15 +652,18 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let before_size := + let _ := M.assign_local (| + "before_size" , M.call (| M.get_name (| globals, "ceil32" |), make_list [ M.get_name (| globals, "current_size" |) ], make_dict [] - |) in - let after_size := + |) + |) in + let _ := M.assign_local (| + "after_size" , M.call (| M.get_name (| globals, "ceil32" |), make_list [ @@ -662,7 +685,8 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -678,42 +702,46 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let size_to_extend := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "size_to_extend", BinOp.sub (| M.get_name (| globals, "after_size" |), M.get_name (| globals, "before_size" |) |) - BinOp.sub (| - M.get_name (| globals, "after_size" |), - M.get_name (| globals, "before_size" |) - |) in - let already_paid := + |) in + let _ := M.assign_local (| + "already_paid" , M.call (| M.get_name (| globals, "calculate_memory_gas_cost" |), make_list [ M.get_name (| globals, "before_size" |) ], make_dict [] - |) in - let total_cost := + |) + |) in + let _ := M.assign_local (| + "total_cost" , M.call (| M.get_name (| globals, "calculate_memory_gas_cost" |), make_list [ M.get_name (| globals, "after_size" |) ], make_dict [] - |) in - let to_be_paid := BinOp.add + |) + |) in + let _ := M.assign_op_local (| + BinOp.add, + "to_be_paid", BinOp.sub (| M.get_name (| globals, "total_cost" |), M.get_name (| globals, "already_paid" |) |) - BinOp.sub (| - M.get_name (| globals, "total_cost" |), - M.get_name (| globals, "already_paid" |) - |) in - let current_size := - M.get_name (| globals, "after_size" |) in + |) in + let _ := M.assign_local (| + "current_size" , + M.get_name (| globals, "after_size" |) + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -760,7 +788,8 @@ Definition calculate_message_call_gas : Value.t -> Value.t -> M := ------- message_call_gas: `MessageCallGas` " in - let call_stipend := + let _ := M.assign_local (| + "call_stipend" , (* if *) M.if_then_else (| Compare.eq (| @@ -779,7 +808,8 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "call_stipend" |) - )) |) in + )) |) + |) in let _ := (* if *) M.if_then_else (| @@ -813,7 +843,8 @@ M.get_name (| globals, "call_stipend" |) )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -833,7 +864,8 @@ M.get_name (| globals, "call_stipend" |) |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "MessageCallGas" |), diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/__init__.v b/CoqOfPython/ethereum/byzantium/vm/instructions/__init__.v index c27504a..f76e351 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/__init__.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/__init__.v @@ -20,44 +20,46 @@ implementations. (* At top_level_stmt: unsupported node type: Import *) -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict" ]. +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". -Axiom ethereum_byzantium_vm_instructions_imports : - AreImported globals "ethereum.byzantium.vm.instructions" [ "arithmetic" ]. +Axiom ethereum_byzantium_vm_instructions_imports_arithmetic : + IsImported globals "ethereum.byzantium.vm.instructions" "arithmetic". -Axiom ethereum_byzantium_vm_instructions_imports : - AreImported globals "ethereum.byzantium.vm.instructions" [ "bitwise" ]. +Axiom ethereum_byzantium_vm_instructions_imports_bitwise : + IsImported globals "ethereum.byzantium.vm.instructions" "bitwise". -Axiom ethereum_byzantium_vm_instructions_imports : - AreImported globals "ethereum.byzantium.vm.instructions" [ "block" ]. +Axiom ethereum_byzantium_vm_instructions_imports_block : + IsImported globals "ethereum.byzantium.vm.instructions" "block". -Axiom ethereum_byzantium_vm_instructions_imports : - AreImported globals "ethereum.byzantium.vm.instructions" [ "comparison" ]. +Axiom ethereum_byzantium_vm_instructions_imports_comparison : + IsImported globals "ethereum.byzantium.vm.instructions" "comparison". -Axiom ethereum_byzantium_vm_instructions_imports : - AreImported globals "ethereum.byzantium.vm.instructions" [ "control_flow" ]. +Axiom ethereum_byzantium_vm_instructions_imports_control_flow : + IsImported globals "ethereum.byzantium.vm.instructions" "control_flow". -Axiom ethereum_byzantium_vm_instructions_imports : - AreImported globals "ethereum.byzantium.vm.instructions" [ "environment" ]. +Axiom ethereum_byzantium_vm_instructions_imports_environment : + IsImported globals "ethereum.byzantium.vm.instructions" "environment". -Axiom ethereum_byzantium_vm_instructions_imports : - AreImported globals "ethereum.byzantium.vm.instructions" [ "keccak" ]. +Axiom ethereum_byzantium_vm_instructions_imports_keccak : + IsImported globals "ethereum.byzantium.vm.instructions" "keccak". -Axiom ethereum_byzantium_vm_instructions_imports : - AreImported globals "ethereum.byzantium.vm.instructions" [ "log" ]. +Axiom ethereum_byzantium_vm_instructions_imports_log : + IsImported globals "ethereum.byzantium.vm.instructions" "log". -Axiom ethereum_byzantium_vm_instructions_imports : - AreImported globals "ethereum.byzantium.vm.instructions" [ "memory" ]. +Axiom ethereum_byzantium_vm_instructions_imports_memory : + IsImported globals "ethereum.byzantium.vm.instructions" "memory". -Axiom ethereum_byzantium_vm_instructions_imports : - AreImported globals "ethereum.byzantium.vm.instructions" [ "stack" ]. +Axiom ethereum_byzantium_vm_instructions_imports_stack : + IsImported globals "ethereum.byzantium.vm.instructions" "stack". -Axiom ethereum_byzantium_vm_instructions_imports : - AreImported globals "ethereum.byzantium.vm.instructions" [ "storage" ]. +Axiom ethereum_byzantium_vm_instructions_imports_storage : + IsImported globals "ethereum.byzantium.vm.instructions" "storage". -Axiom ethereum_byzantium_vm_instructions_imports : - AreImported globals "ethereum.byzantium.vm.instructions" [ "system" ]. +Axiom ethereum_byzantium_vm_instructions_imports_system : + IsImported globals "ethereum.byzantium.vm.instructions" "system". Definition Ops : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/byzantium/vm/instructions/arithmetic.v index c9d385d..554d565 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/arithmetic.v @@ -17,20 +17,38 @@ Introduction Implementations of the EVM Arithmetic instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U255_CEIL_VALUE"; "U256"; "U256_CEIL_VALUE"; "Uint" ]. +Axiom ethereum_base_types_imports_U255_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U255_CEIL_VALUE". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_U256_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U256_CEIL_VALUE". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "get_sign" ]. +Axiom ethereum_utils_numeric_imports_get_sign : + IsImported globals "ethereum.utils.numeric" "get_sign". -Axiom ethereum_byzantium_vm_imports : - AreImported globals "ethereum.byzantium.vm" [ "Evm" ]. +Axiom ethereum_byzantium_vm_imports_Evm : + IsImported globals "ethereum.byzantium.vm" "Evm". -Axiom ethereum_byzantium_vm_gas_imports : - AreImported globals "ethereum.byzantium.vm.gas" [ "GAS_EXPONENTIATION"; "GAS_EXPONENTIATION_PER_BYTE"; "GAS_LOW"; "GAS_MID"; "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_byzantium_vm_gas_imports_GAS_EXPONENTIATION : + IsImported globals "ethereum.byzantium.vm.gas" "GAS_EXPONENTIATION". +Axiom ethereum_byzantium_vm_gas_imports_GAS_EXPONENTIATION_PER_BYTE : + IsImported globals "ethereum.byzantium.vm.gas" "GAS_EXPONENTIATION_PER_BYTE". +Axiom ethereum_byzantium_vm_gas_imports_GAS_LOW : + IsImported globals "ethereum.byzantium.vm.gas" "GAS_LOW". +Axiom ethereum_byzantium_vm_gas_imports_GAS_MID : + IsImported globals "ethereum.byzantium.vm.gas" "GAS_MID". +Axiom ethereum_byzantium_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.byzantium.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_byzantium_vm_gas_imports_charge_gas : + IsImported globals "ethereum.byzantium.vm.gas" "charge_gas". -Axiom ethereum_byzantium_vm_stack_imports : - AreImported globals "ethereum.byzantium.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_byzantium_vm_stack_imports_pop : + IsImported globals "ethereum.byzantium.vm.stack" "pop". +Axiom ethereum_byzantium_vm_stack_imports_push : + IsImported globals "ethereum.byzantium.vm.stack" "push". Definition add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,22 +63,26 @@ Definition add : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -69,14 +91,16 @@ Definition add : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "x" |), "wrapping_add" |), make_list [ M.get_name (| globals, "y" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -105,22 +129,26 @@ Definition sub : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -129,14 +157,16 @@ Definition sub : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "x" |), "wrapping_sub" |), make_list [ M.get_name (| globals, "y" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -165,22 +195,26 @@ Definition mul : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -189,14 +223,16 @@ Definition mul : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "x" |), "wrapping_mul" |), make_list [ M.get_name (| globals, "y" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -225,22 +261,26 @@ Definition div : Value.t -> Value.t -> M := The current EVM frame. " in - let dividend := + let _ := M.assign_local (| + "dividend" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let divisor := + |) + |) in + let _ := M.assign_local (| + "divisor" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -258,22 +298,26 @@ Definition div : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let quotient := + let _ := M.assign_local (| + "quotient" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let quotient := + let _ := M.assign_local (| + "quotient" , BinOp.floor_div (| M.get_name (| globals, "dividend" |), M.get_name (| globals, "divisor" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -304,7 +348,8 @@ Definition sdiv : Value.t -> Value.t -> M := The current EVM frame. " in - let dividend := + let _ := M.assign_local (| + "dividend" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -315,8 +360,10 @@ Definition sdiv : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let divisor := + |) + |) in + let _ := M.assign_local (| + "divisor" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -327,7 +374,8 @@ Definition sdiv : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -345,8 +393,10 @@ Definition sdiv : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let quotient := - Constant.int 0 in + let _ := M.assign_local (| + "quotient" , + Constant.int 0 + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -367,12 +417,15 @@ Definition sdiv : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let quotient := - UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in + let _ := M.assign_local (| + "quotient" , + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let sign := + let _ := M.assign_local (| + "sign" , M.call (| M.get_name (| globals, "get_sign" |), make_list [ @@ -382,8 +435,10 @@ Definition sdiv : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let quotient := + |) + |) in + let _ := M.assign_local (| + "quotient" , BinOp.mult (| M.get_name (| globals, "sign" |), BinOp.floor_div (| @@ -402,7 +457,8 @@ Definition sdiv : Value.t -> Value.t -> M := make_dict [] |) |) - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -428,7 +484,7 @@ Definition sdiv : Value.t -> Value.t -> M := |) in M.pure Constant.None_)). -Definition mod : Value.t -> Value.t -> M := +Definition mod_ : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in let _ := Constant.str " @@ -441,22 +497,26 @@ Definition mod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -474,22 +534,26 @@ Definition mod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let remainder := + let _ := M.assign_local (| + "remainder" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let remainder := + let _ := M.assign_local (| + "remainder" , BinOp.mod_ (| M.get_name (| globals, "x" |), M.get_name (| globals, "y" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -520,7 +584,8 @@ Definition smod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -531,8 +596,10 @@ Definition smod : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -543,7 +610,8 @@ Definition smod : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -561,12 +629,15 @@ Definition smod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let remainder := - Constant.int 0 in + let _ := M.assign_local (| + "remainder" , + Constant.int 0 + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let remainder := + let _ := M.assign_local (| + "remainder" , BinOp.mult (| M.call (| M.get_name (| globals, "get_sign" |), @@ -591,7 +662,8 @@ Definition smod : Value.t -> Value.t -> M := make_dict [] |) |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -628,7 +700,8 @@ Definition addmod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -641,8 +714,10 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -655,8 +730,10 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let z := + |) + |) in + let _ := M.assign_local (| + "z" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -669,7 +746,8 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -687,18 +765,21 @@ Definition addmod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -711,7 +792,8 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -742,7 +824,8 @@ Definition mulmod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -755,8 +838,10 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -769,8 +854,10 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let z := + |) + |) in + let _ := M.assign_local (| + "z" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -783,7 +870,8 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -801,18 +889,21 @@ Definition mulmod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -825,7 +916,8 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -856,7 +948,8 @@ Definition exp : Value.t -> Value.t -> M := The current EVM frame. " in - let base := + let _ := M.assign_local (| + "base" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -869,8 +962,10 @@ Definition exp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exponent := + |) + |) in + let _ := M.assign_local (| + "exponent" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -883,21 +978,26 @@ Definition exp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exponent_bits := + |) + |) in + let _ := M.assign_local (| + "exponent_bits" , M.call (| M.get_field (| M.get_name (| globals, "exponent" |), "bit_length" |), make_list [], make_dict [] - |) in - let exponent_bytes := + |) + |) in + let _ := M.assign_local (| + "exponent_bytes" , BinOp.floor_div (| BinOp.add (| M.get_name (| globals, "exponent_bits" |), Constant.int 7 |), Constant.int 8 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -912,7 +1012,8 @@ Definition exp : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -927,7 +1028,8 @@ Definition exp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -956,22 +1058,26 @@ Definition signextend : Value.t -> Value.t -> M := The current EVM frame. " in - let byte_num := + let _ := M.assign_local (| + "byte_num" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -989,12 +1095,15 @@ Definition signextend : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := - M.get_name (| globals, "value" |) in + let _ := M.assign_local (| + "result" , + M.get_name (| globals, "value" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let value_bytes := + let _ := M.assign_local (| + "value_bytes" , M.call (| M.get_name (| globals, "bytes" |), make_list [ @@ -1005,8 +1114,10 @@ Definition signextend : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let value_bytes := + |) + |) in + let _ := M.assign_local (| + "value_bytes" , M.slice (| M.get_name (| globals, "value_bytes" |), BinOp.sub (| @@ -1021,15 +1132,18 @@ Definition signextend : Value.t -> Value.t -> M := |), Constant.None_, Constant.None_ - |) in - let sign_bit := + |) + |) in + let _ := M.assign_local (| + "sign_bit" , BinOp.r_shift (| M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), Constant.int 7 - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1039,26 +1153,31 @@ Definition signextend : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "value_bytes" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let num_bytes_prepend := + let _ := M.assign_local (| + "num_bytes_prepend" , BinOp.sub (| Constant.int 32, BinOp.add (| M.get_name (| globals, "byte_num" |), Constant.int 1 |) - |) in - let result := + |) + |) in + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -1079,7 +1198,8 @@ Definition signextend : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/bitwise.v b/CoqOfPython/ethereum/byzantium/vm/instructions/bitwise.v index ddb2396..78deb13 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/bitwise.v @@ -17,17 +17,21 @@ Introduction Implementations of the EVM bitwise instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_byzantium_vm_imports : - AreImported globals "ethereum.byzantium.vm" [ "Evm" ]. +Axiom ethereum_byzantium_vm_imports_Evm : + IsImported globals "ethereum.byzantium.vm" "Evm". -Axiom ethereum_byzantium_vm_gas_imports : - AreImported globals "ethereum.byzantium.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_byzantium_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.byzantium.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_byzantium_vm_gas_imports_charge_gas : + IsImported globals "ethereum.byzantium.vm.gas" "charge_gas". -Axiom ethereum_byzantium_vm_stack_imports : - AreImported globals "ethereum.byzantium.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_byzantium_vm_stack_imports_pop : + IsImported globals "ethereum.byzantium.vm.stack" "pop". +Axiom ethereum_byzantium_vm_stack_imports_push : + IsImported globals "ethereum.byzantium.vm.stack" "push". Definition bitwise_and : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,22 +46,26 @@ Definition bitwise_and : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -97,22 +105,26 @@ Definition bitwise_or : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -152,22 +164,26 @@ Definition bitwise_xor : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -207,14 +223,16 @@ Definition bitwise_not : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -252,22 +270,26 @@ Definition get_byte : Value.t -> Value.t -> M := The current EVM frame. " in - let byte_index := + let _ := M.assign_local (| + "byte_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let word := + |) + |) in + let _ := M.assign_local (| + "word" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -285,43 +307,53 @@ Definition get_byte : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let extra_bytes_to_right := + let _ := M.assign_local (| + "extra_bytes_to_right" , BinOp.sub (| Constant.int 31, M.get_name (| globals, "byte_index" |) - |) in - let word := + |) + |) in + let _ := M.assign_local (| + "word" , BinOp.r_shift (| M.get_name (| globals, "word" |), BinOp.mult (| M.get_name (| globals, "extra_bytes_to_right" |), Constant.int 8 |) - |) in - let word := + |) + |) in + let _ := M.assign_local (| + "word" , BinOp.bit_and (| M.get_name (| globals, "word" |), Constant.int 255 - |) in - let result := + |) + |) in + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ M.get_name (| globals, "word" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/block.v b/CoqOfPython/ethereum/byzantium/vm/instructions/block.v index 3d8f83c..deb5d8d 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/block.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/block.v @@ -17,17 +17,23 @@ Introduction Implementations of the EVM block instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_byzantium_vm_imports : - AreImported globals "ethereum.byzantium.vm" [ "Evm" ]. +Axiom ethereum_byzantium_vm_imports_Evm : + IsImported globals "ethereum.byzantium.vm" "Evm". -Axiom ethereum_byzantium_vm_gas_imports : - AreImported globals "ethereum.byzantium.vm.gas" [ "GAS_BASE"; "GAS_BLOCK_HASH"; "charge_gas" ]. +Axiom ethereum_byzantium_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.byzantium.vm.gas" "GAS_BASE". +Axiom ethereum_byzantium_vm_gas_imports_GAS_BLOCK_HASH : + IsImported globals "ethereum.byzantium.vm.gas" "GAS_BLOCK_HASH". +Axiom ethereum_byzantium_vm_gas_imports_charge_gas : + IsImported globals "ethereum.byzantium.vm.gas" "charge_gas". -Axiom ethereum_byzantium_vm_stack_imports : - AreImported globals "ethereum.byzantium.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_byzantium_vm_stack_imports_pop : + IsImported globals "ethereum.byzantium.vm.stack" "pop". +Axiom ethereum_byzantium_vm_stack_imports_push : + IsImported globals "ethereum.byzantium.vm.stack" "push". Definition block_hash : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,14 +48,16 @@ Definition block_hash : Value.t -> Value.t -> M := The current EVM frame. " in - let block_number := + let _ := M.assign_local (| + "block_number" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -78,19 +86,23 @@ Definition block_hash : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let hash := - Constant.bytes "00" in + let _ := M.assign_local (| + "hash" , + Constant.bytes "00" + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let hash := + let _ := M.assign_local (| + "hash" , M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), M.get_name (| globals, "block_number" |) |) |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/comparison.v b/CoqOfPython/ethereum/byzantium/vm/instructions/comparison.v index 7a7923c..b282bad 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/comparison.v @@ -17,17 +17,21 @@ Introduction Implementations of the EVM Comparison instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_byzantium_vm_imports : - AreImported globals "ethereum.byzantium.vm" [ "Evm" ]. +Axiom ethereum_byzantium_vm_imports_Evm : + IsImported globals "ethereum.byzantium.vm" "Evm". -Axiom ethereum_byzantium_vm_gas_imports : - AreImported globals "ethereum.byzantium.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_byzantium_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.byzantium.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_byzantium_vm_gas_imports_charge_gas : + IsImported globals "ethereum.byzantium.vm.gas" "charge_gas". -Axiom ethereum_byzantium_vm_stack_imports : - AreImported globals "ethereum.byzantium.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_byzantium_vm_stack_imports_pop : + IsImported globals "ethereum.byzantium.vm.stack" "pop". +Axiom ethereum_byzantium_vm_stack_imports_push : + IsImported globals "ethereum.byzantium.vm.stack" "push". Definition less_than : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,22 +46,26 @@ Definition less_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -66,7 +74,8 @@ Definition less_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -76,7 +85,8 @@ Definition less_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -104,7 +114,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -115,8 +126,10 @@ Definition signed_less_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -127,7 +140,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -136,7 +150,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -146,7 +161,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -175,22 +191,26 @@ Definition greater_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -199,7 +219,8 @@ Definition greater_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -209,7 +230,8 @@ Definition greater_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -237,7 +259,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -248,8 +271,10 @@ Definition signed_greater_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -260,7 +285,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -269,7 +295,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -279,7 +306,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -308,22 +336,26 @@ Definition equal : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -332,7 +364,8 @@ Definition equal : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -342,7 +375,8 @@ Definition equal : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -371,14 +405,16 @@ Definition is_zero : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -387,7 +423,8 @@ Definition is_zero : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -397,7 +434,8 @@ Definition is_zero : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/control_flow.v b/CoqOfPython/ethereum/byzantium/vm/instructions/control_flow.v index fc0b158..01a71f7 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/control_flow.v @@ -17,20 +17,32 @@ Introduction Implementations of the EVM control flow instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_byzantium_vm_gas_imports : - AreImported globals "ethereum.byzantium.vm.gas" [ "GAS_BASE"; "GAS_HIGH"; "GAS_JUMPDEST"; "GAS_MID"; "charge_gas" ]. +Axiom ethereum_byzantium_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.byzantium.vm.gas" "GAS_BASE". +Axiom ethereum_byzantium_vm_gas_imports_GAS_HIGH : + IsImported globals "ethereum.byzantium.vm.gas" "GAS_HIGH". +Axiom ethereum_byzantium_vm_gas_imports_GAS_JUMPDEST : + IsImported globals "ethereum.byzantium.vm.gas" "GAS_JUMPDEST". +Axiom ethereum_byzantium_vm_gas_imports_GAS_MID : + IsImported globals "ethereum.byzantium.vm.gas" "GAS_MID". +Axiom ethereum_byzantium_vm_gas_imports_charge_gas : + IsImported globals "ethereum.byzantium.vm.gas" "charge_gas". -Axiom ethereum_byzantium_vm_imports : - AreImported globals "ethereum.byzantium.vm" [ "Evm" ]. +Axiom ethereum_byzantium_vm_imports_Evm : + IsImported globals "ethereum.byzantium.vm" "Evm". -Axiom ethereum_byzantium_vm_exceptions_imports : - AreImported globals "ethereum.byzantium.vm.exceptions" [ "InvalidJumpDestError" ]. +Axiom ethereum_byzantium_vm_exceptions_imports_InvalidJumpDestError : + IsImported globals "ethereum.byzantium.vm.exceptions" "InvalidJumpDestError". -Axiom ethereum_byzantium_vm_stack_imports : - AreImported globals "ethereum.byzantium.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_byzantium_vm_stack_imports_pop : + IsImported globals "ethereum.byzantium.vm.stack" "pop". +Axiom ethereum_byzantium_vm_stack_imports_push : + IsImported globals "ethereum.byzantium.vm.stack" "push". Definition stop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -69,7 +81,8 @@ Definition jump : Value.t -> Value.t -> M := The current EVM frame. " in - let jump_dest := + let _ := M.assign_local (| + "jump_dest" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -82,7 +95,8 @@ Definition jump : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -132,7 +146,8 @@ Definition jumpi : Value.t -> Value.t -> M := The current EVM frame. " in - let jump_dest := + let _ := M.assign_local (| + "jump_dest" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -145,15 +160,18 @@ Definition jumpi : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let conditional_value := + |) + |) in + let _ := M.assign_local (| + "conditional_value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -171,11 +189,13 @@ Definition jumpi : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let destination := + let _ := M.assign_local (| + "destination" , BinOp.add (| M.get_field (| M.get_name (| globals, "evm" |), "pc" |), Constant.int 1 - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -192,8 +212,10 @@ Definition jumpi : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let destination := - M.get_name (| globals, "jump_dest" |) in + let _ := M.assign_local (| + "destination" , + M.get_name (| globals, "jump_dest" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/environment.v b/CoqOfPython/ethereum/byzantium/vm/instructions/environment.v index 5ed3fbd..150687d 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/environment.v @@ -17,35 +17,55 @@ Introduction Implementations of the EVM environment related instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_byzantium_state_imports : - AreImported globals "ethereum.byzantium.state" [ "get_account" ]. +Axiom ethereum_byzantium_state_imports_get_account : + IsImported globals "ethereum.byzantium.state" "get_account". -Axiom ethereum_byzantium_utils_address_imports : - AreImported globals "ethereum.byzantium.utils.address" [ "to_address" ]. +Axiom ethereum_byzantium_utils_address_imports_to_address : + IsImported globals "ethereum.byzantium.utils.address" "to_address". -Axiom ethereum_byzantium_vm_memory_imports : - AreImported globals "ethereum.byzantium.vm.memory" [ "buffer_read"; "memory_write" ]. +Axiom ethereum_byzantium_vm_memory_imports_buffer_read : + IsImported globals "ethereum.byzantium.vm.memory" "buffer_read". +Axiom ethereum_byzantium_vm_memory_imports_memory_write : + IsImported globals "ethereum.byzantium.vm.memory" "memory_write". -Axiom ethereum_byzantium_vm_imports : - AreImported globals "ethereum.byzantium.vm" [ "Evm" ]. +Axiom ethereum_byzantium_vm_imports_Evm : + IsImported globals "ethereum.byzantium.vm" "Evm". -Axiom ethereum_byzantium_vm_exceptions_imports : - AreImported globals "ethereum.byzantium.vm.exceptions" [ "OutOfBoundsRead" ]. +Axiom ethereum_byzantium_vm_exceptions_imports_OutOfBoundsRead : + IsImported globals "ethereum.byzantium.vm.exceptions" "OutOfBoundsRead". -Axiom ethereum_byzantium_vm_gas_imports : - AreImported globals "ethereum.byzantium.vm.gas" [ "GAS_BALANCE"; "GAS_BASE"; "GAS_COPY"; "GAS_EXTERNAL"; "GAS_RETURN_DATA_COPY"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_byzantium_vm_gas_imports_GAS_BALANCE : + IsImported globals "ethereum.byzantium.vm.gas" "GAS_BALANCE". +Axiom ethereum_byzantium_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.byzantium.vm.gas" "GAS_BASE". +Axiom ethereum_byzantium_vm_gas_imports_GAS_COPY : + IsImported globals "ethereum.byzantium.vm.gas" "GAS_COPY". +Axiom ethereum_byzantium_vm_gas_imports_GAS_EXTERNAL : + IsImported globals "ethereum.byzantium.vm.gas" "GAS_EXTERNAL". +Axiom ethereum_byzantium_vm_gas_imports_GAS_RETURN_DATA_COPY : + IsImported globals "ethereum.byzantium.vm.gas" "GAS_RETURN_DATA_COPY". +Axiom ethereum_byzantium_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.byzantium.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_byzantium_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.byzantium.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_byzantium_vm_gas_imports_charge_gas : + IsImported globals "ethereum.byzantium.vm.gas" "charge_gas". -Axiom ethereum_byzantium_vm_stack_imports : - AreImported globals "ethereum.byzantium.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_byzantium_vm_stack_imports_pop : + IsImported globals "ethereum.byzantium.vm.stack" "pop". +Axiom ethereum_byzantium_vm_stack_imports_push : + IsImported globals "ethereum.byzantium.vm.stack" "push". Definition address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -101,7 +121,8 @@ Definition balance : Value.t -> Value.t -> M := The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -114,7 +135,8 @@ Definition balance : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -123,7 +145,8 @@ Definition balance : Value.t -> Value.t -> M := ], make_dict [] |) in - let balance := + let _ := M.assign_local (| + "balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -131,7 +154,8 @@ Definition balance : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -281,14 +305,16 @@ Definition calldataload : Value.t -> Value.t -> M := The current EVM frame. " in - let start_index := + let _ := M.assign_local (| + "start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -297,7 +323,8 @@ Definition calldataload : Value.t -> Value.t -> M := ], make_dict [] |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -312,7 +339,8 @@ Definition calldataload : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -397,31 +425,38 @@ Definition calldatacopy : Value.t -> Value.t -> M := The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let data_start_index := + |) + |) in + let _ := M.assign_local (| + "data_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -437,13 +472,17 @@ Definition calldatacopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -453,7 +492,8 @@ Definition calldatacopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -476,7 +516,8 @@ Definition calldatacopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -485,7 +526,8 @@ Definition calldatacopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -565,31 +607,38 @@ Definition codecopy : Value.t -> Value.t -> M := The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let code_start_index := + |) + |) in + let _ := M.assign_local (| + "code_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -605,13 +654,17 @@ Definition codecopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -621,7 +674,8 @@ Definition codecopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -644,7 +698,8 @@ Definition codecopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -653,7 +708,8 @@ Definition codecopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -724,7 +780,8 @@ Definition extcodesize : Value.t -> Value.t -> M := The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -737,7 +794,8 @@ Definition extcodesize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -746,7 +804,8 @@ Definition extcodesize : Value.t -> Value.t -> M := ], make_dict [] |) in - let codesize := + let _ := M.assign_local (| + "codesize" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -766,7 +825,8 @@ Definition extcodesize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -794,7 +854,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -807,32 +868,40 @@ Definition extcodecopy : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let memory_start_index := + |) + |) in + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let code_start_index := + |) + |) in + let _ := M.assign_local (| + "code_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -848,13 +917,17 @@ Definition extcodecopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -864,7 +937,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -887,7 +961,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let code := + let _ := M.assign_local (| + "code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -895,8 +970,10 @@ Definition extcodecopy : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |), "code" |) in - let value := + |), "code" |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -905,7 +982,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -980,31 +1058,38 @@ Definition returndatacopy : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let return_data_start_position := + |) + |) in + let _ := M.assign_local (| + "return_data_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -1020,13 +1105,17 @@ Definition returndatacopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_RETURN_DATA_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1036,7 +1125,8 @@ Definition returndatacopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1091,7 +1181,8 @@ Definition returndatacopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.slice (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |), @@ -1100,7 +1191,8 @@ Definition returndatacopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) |), Constant.None_ - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/keccak.v b/CoqOfPython/ethereum/byzantium/vm/instructions/keccak.v index f65f159..c54b6cc 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/keccak.v @@ -17,26 +17,36 @@ Introduction Implementations of the EVM keccak instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_byzantium_vm_imports : - AreImported globals "ethereum.byzantium.vm" [ "Evm" ]. +Axiom ethereum_byzantium_vm_imports_Evm : + IsImported globals "ethereum.byzantium.vm" "Evm". -Axiom ethereum_byzantium_vm_gas_imports : - AreImported globals "ethereum.byzantium.vm.gas" [ "GAS_KECCAK256"; "GAS_KECCAK256_WORD"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_byzantium_vm_gas_imports_GAS_KECCAK256 : + IsImported globals "ethereum.byzantium.vm.gas" "GAS_KECCAK256". +Axiom ethereum_byzantium_vm_gas_imports_GAS_KECCAK256_WORD : + IsImported globals "ethereum.byzantium.vm.gas" "GAS_KECCAK256_WORD". +Axiom ethereum_byzantium_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.byzantium.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_byzantium_vm_gas_imports_charge_gas : + IsImported globals "ethereum.byzantium.vm.gas" "charge_gas". -Axiom ethereum_byzantium_vm_memory_imports : - AreImported globals "ethereum.byzantium.vm.memory" [ "memory_read_bytes" ]. +Axiom ethereum_byzantium_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.byzantium.vm.memory" "memory_read_bytes". -Axiom ethereum_byzantium_vm_stack_imports : - AreImported globals "ethereum.byzantium.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_byzantium_vm_stack_imports_pop : + IsImported globals "ethereum.byzantium.vm.stack" "pop". +Axiom ethereum_byzantium_vm_stack_imports_push : + IsImported globals "ethereum.byzantium.vm.stack" "push". Definition keccak : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -53,23 +63,28 @@ Definition keccak : Value.t -> Value.t -> M := The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -85,13 +100,17 @@ Definition keccak : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let word_gas_cost := + |) + |) in + let _ := M.assign_local (| + "word_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_KECCAK256_WORD" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -101,7 +120,8 @@ Definition keccak : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -124,7 +144,8 @@ Definition keccak : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let data := + let _ := M.assign_local (| + "data" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -133,15 +154,18 @@ Definition keccak : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in - let hash := + |) + |) in + let _ := M.assign_local (| + "hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "data" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/log.v b/CoqOfPython/ethereum/byzantium/vm/instructions/log.v index cf021db..4f0424b 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/log.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/log.v @@ -17,32 +17,40 @@ Introduction Implementations of the EVM logging instructions. ". -Axiom functools_imports : - AreImported globals "functools" [ "partial" ]. +Axiom functools_imports_partial : + IsImported globals "functools" "partial". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_byzantium_blocks_imports : - AreImported globals "ethereum.byzantium.blocks" [ "Log" ]. +Axiom ethereum_byzantium_blocks_imports_Log : + IsImported globals "ethereum.byzantium.blocks" "Log". -Axiom ethereum_byzantium_vm_imports : - AreImported globals "ethereum.byzantium.vm" [ "Evm" ]. +Axiom ethereum_byzantium_vm_imports_Evm : + IsImported globals "ethereum.byzantium.vm" "Evm". -Axiom ethereum_byzantium_vm_exceptions_imports : - AreImported globals "ethereum.byzantium.vm.exceptions" [ "WriteInStaticContext" ]. +Axiom ethereum_byzantium_vm_exceptions_imports_WriteInStaticContext : + IsImported globals "ethereum.byzantium.vm.exceptions" "WriteInStaticContext". -Axiom ethereum_byzantium_vm_gas_imports : - AreImported globals "ethereum.byzantium.vm.gas" [ "GAS_LOG"; "GAS_LOG_DATA"; "GAS_LOG_TOPIC"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_byzantium_vm_gas_imports_GAS_LOG : + IsImported globals "ethereum.byzantium.vm.gas" "GAS_LOG". +Axiom ethereum_byzantium_vm_gas_imports_GAS_LOG_DATA : + IsImported globals "ethereum.byzantium.vm.gas" "GAS_LOG_DATA". +Axiom ethereum_byzantium_vm_gas_imports_GAS_LOG_TOPIC : + IsImported globals "ethereum.byzantium.vm.gas" "GAS_LOG_TOPIC". +Axiom ethereum_byzantium_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.byzantium.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_byzantium_vm_gas_imports_charge_gas : + IsImported globals "ethereum.byzantium.vm.gas" "charge_gas". -Axiom ethereum_byzantium_vm_memory_imports : - AreImported globals "ethereum.byzantium.vm.memory" [ "memory_read_bytes" ]. +Axiom ethereum_byzantium_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.byzantium.vm.memory" "memory_read_bytes". -Axiom ethereum_byzantium_vm_stack_imports : - AreImported globals "ethereum.byzantium.vm.stack" [ "pop" ]. +Axiom ethereum_byzantium_vm_stack_imports_pop : + IsImported globals "ethereum.byzantium.vm.stack" "pop". Definition log_n : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -61,24 +69,30 @@ Definition log_n : Value.t -> Value.t -> M := The number of topics to be included in the log entry. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let topics := - make_list [] in + |) + |) in + let _ := M.assign_local (| + "topics" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "_" |), @@ -90,7 +104,8 @@ Definition log_n : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let topic := + let _ := M.assign_local (| + "topic" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -101,7 +116,8 @@ Definition log_n : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "topics" |), "append" |), make_list [ @@ -115,7 +131,8 @@ Definition log_n : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let extend_memory := + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -125,7 +142,8 @@ Definition log_n : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -165,12 +183,14 @@ Definition log_n : Value.t -> Value.t -> M := ], make_dict [] |) in - let log_entry := + let _ := M.assign_local (| + "log_entry" , M.call (| M.get_name (| globals, "Log" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "logs" |), BinOp.add (| diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/memory.v b/CoqOfPython/ethereum/byzantium/vm/instructions/memory.v index fd6b222..ff2aeb3 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/memory.v @@ -17,20 +17,32 @@ Introduction Implementations of the EVM Memory instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". -Axiom ethereum_byzantium_vm_imports : - AreImported globals "ethereum.byzantium.vm" [ "Evm" ]. +Axiom ethereum_byzantium_vm_imports_Evm : + IsImported globals "ethereum.byzantium.vm" "Evm". -Axiom ethereum_byzantium_vm_gas_imports : - AreImported globals "ethereum.byzantium.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_byzantium_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.byzantium.vm.gas" "GAS_BASE". +Axiom ethereum_byzantium_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.byzantium.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_byzantium_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.byzantium.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_byzantium_vm_gas_imports_charge_gas : + IsImported globals "ethereum.byzantium.vm.gas" "charge_gas". -Axiom ethereum_byzantium_vm_memory_imports : - AreImported globals "ethereum.byzantium.vm.memory" [ "memory_read_bytes"; "memory_write" ]. +Axiom ethereum_byzantium_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.byzantium.vm.memory" "memory_read_bytes". +Axiom ethereum_byzantium_vm_memory_imports_memory_write : + IsImported globals "ethereum.byzantium.vm.memory" "memory_write". -Axiom ethereum_byzantium_vm_stack_imports : - AreImported globals "ethereum.byzantium.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_byzantium_vm_stack_imports_pop : + IsImported globals "ethereum.byzantium.vm.stack" "pop". +Axiom ethereum_byzantium_vm_stack_imports_push : + IsImported globals "ethereum.byzantium.vm.stack" "push". Definition mstore : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -46,15 +58,18 @@ Definition mstore : Value.t -> Value.t -> M := The current EVM frame. " in - let start_position := + let _ := M.assign_local (| + "start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -65,8 +80,10 @@ Definition mstore : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -88,7 +105,8 @@ Definition mstore : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -138,23 +156,28 @@ Definition mstore8 : Value.t -> Value.t -> M := The current EVM frame. " in - let start_position := + let _ := M.assign_local (| + "start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -170,7 +193,8 @@ Definition mstore8 : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -190,7 +214,8 @@ Definition mstore8 : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let normalized_bytes_value := + let _ := M.assign_local (| + "normalized_bytes_value" , M.call (| M.get_name (| globals, "Bytes" |), make_list [ @@ -202,7 +227,8 @@ Definition mstore8 : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -231,15 +257,18 @@ Definition mload : Value.t -> Value.t -> M := The current EVM frame. " in - let start_position := + let _ := M.assign_local (| + "start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -255,7 +284,8 @@ Definition mload : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -275,7 +305,8 @@ Definition mload : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -296,7 +327,8 @@ Definition mload : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/stack.v b/CoqOfPython/ethereum/byzantium/vm/instructions/stack.v index 446a88f..2b2ad26 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/stack.v @@ -17,26 +17,32 @@ Introduction Implementations of the EVM stack related instructions. ". -Axiom functools_imports : - AreImported globals "functools" [ "partial" ]. +Axiom functools_imports_partial : + IsImported globals "functools" "partial". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_byzantium_vm_imports : - AreImported globals "ethereum.byzantium.vm" [ "Evm"; "stack" ]. +Axiom ethereum_byzantium_vm_imports_Evm : + IsImported globals "ethereum.byzantium.vm" "Evm". +Axiom ethereum_byzantium_vm_imports_stack : + IsImported globals "ethereum.byzantium.vm" "stack". -Axiom ethereum_byzantium_vm_exceptions_imports : - AreImported globals "ethereum.byzantium.vm.exceptions" [ "StackUnderflowError" ]. +Axiom ethereum_byzantium_vm_exceptions_imports_StackUnderflowError : + IsImported globals "ethereum.byzantium.vm.exceptions" "StackUnderflowError". -Axiom ethereum_byzantium_vm_gas_imports : - AreImported globals "ethereum.byzantium.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_byzantium_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.byzantium.vm.gas" "GAS_BASE". +Axiom ethereum_byzantium_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.byzantium.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_byzantium_vm_gas_imports_charge_gas : + IsImported globals "ethereum.byzantium.vm.gas" "charge_gas". -Axiom ethereum_byzantium_vm_memory_imports : - AreImported globals "ethereum.byzantium.vm.memory" [ "buffer_read" ]. +Axiom ethereum_byzantium_vm_memory_imports_buffer_read : + IsImported globals "ethereum.byzantium.vm.memory" "buffer_read". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -98,7 +104,8 @@ Definition push_n : Value.t -> Value.t -> M := ], make_dict [] |) in - let data_to_push := + let _ := M.assign_local (| + "data_to_push" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -128,7 +135,8 @@ Definition push_n : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "stack" |), "push" |), make_list [ @@ -189,7 +197,8 @@ Definition dup_n : Value.t -> Value.t -> M := ], make_dict [] |) in - let data_to_duplicate := + let _ := M.assign_local (| + "data_to_duplicate" , M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| @@ -205,7 +214,8 @@ Definition dup_n : Value.t -> Value.t -> M := |), M.get_name (| globals, "item_number" |) |) - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "stack" |), "push" |), make_list [ diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/storage.v b/CoqOfPython/ethereum/byzantium/vm/instructions/storage.v index 559c559..64a99f4 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/storage.v @@ -17,23 +17,35 @@ Introduction Implementations of the EVM storage related instructions. ". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_byzantium_state_imports : - AreImported globals "ethereum.byzantium.state" [ "get_storage"; "set_storage" ]. - -Axiom ethereum_byzantium_vm_imports : - AreImported globals "ethereum.byzantium.vm" [ "Evm" ]. - -Axiom ethereum_byzantium_vm_exceptions_imports : - AreImported globals "ethereum.byzantium.vm.exceptions" [ "WriteInStaticContext" ]. - -Axiom ethereum_byzantium_vm_gas_imports : - AreImported globals "ethereum.byzantium.vm.gas" [ "GAS_SLOAD"; "GAS_STORAGE_CLEAR_REFUND"; "GAS_STORAGE_SET"; "GAS_STORAGE_UPDATE"; "charge_gas" ]. - -Axiom ethereum_byzantium_vm_stack_imports : - AreImported globals "ethereum.byzantium.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_byzantium_state_imports_get_storage : + IsImported globals "ethereum.byzantium.state" "get_storage". +Axiom ethereum_byzantium_state_imports_set_storage : + IsImported globals "ethereum.byzantium.state" "set_storage". + +Axiom ethereum_byzantium_vm_imports_Evm : + IsImported globals "ethereum.byzantium.vm" "Evm". + +Axiom ethereum_byzantium_vm_exceptions_imports_WriteInStaticContext : + IsImported globals "ethereum.byzantium.vm.exceptions" "WriteInStaticContext". + +Axiom ethereum_byzantium_vm_gas_imports_GAS_SLOAD : + IsImported globals "ethereum.byzantium.vm.gas" "GAS_SLOAD". +Axiom ethereum_byzantium_vm_gas_imports_GAS_STORAGE_CLEAR_REFUND : + IsImported globals "ethereum.byzantium.vm.gas" "GAS_STORAGE_CLEAR_REFUND". +Axiom ethereum_byzantium_vm_gas_imports_GAS_STORAGE_SET : + IsImported globals "ethereum.byzantium.vm.gas" "GAS_STORAGE_SET". +Axiom ethereum_byzantium_vm_gas_imports_GAS_STORAGE_UPDATE : + IsImported globals "ethereum.byzantium.vm.gas" "GAS_STORAGE_UPDATE". +Axiom ethereum_byzantium_vm_gas_imports_charge_gas : + IsImported globals "ethereum.byzantium.vm.gas" "charge_gas". + +Axiom ethereum_byzantium_vm_stack_imports_pop : + IsImported globals "ethereum.byzantium.vm.stack" "pop". +Axiom ethereum_byzantium_vm_stack_imports_push : + IsImported globals "ethereum.byzantium.vm.stack" "push". Definition sload : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -48,7 +60,8 @@ Definition sload : Value.t -> Value.t -> M := The current EVM frame. " in - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -59,7 +72,8 @@ Definition sload : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -68,7 +82,8 @@ Definition sload : Value.t -> Value.t -> M := ], make_dict [] |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "get_storage" |), make_list [ @@ -77,7 +92,8 @@ Definition sload : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -105,7 +121,8 @@ Definition sstore : Value.t -> Value.t -> M := The current EVM frame. " in - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -116,16 +133,20 @@ Definition sstore : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in - let new_value := + |) + |) in + let _ := M.assign_local (| + "new_value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let current_value := + |) + |) in + let _ := M.assign_local (| + "current_value" , M.call (| M.get_name (| globals, "get_storage" |), make_list [ @@ -134,7 +155,8 @@ Definition sstore : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -152,13 +174,17 @@ Definition sstore : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let gas_cost := - M.get_name (| globals, "GAS_STORAGE_SET" |) in + let _ := M.assign_local (| + "gas_cost" , + M.get_name (| globals, "GAS_STORAGE_SET" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let gas_cost := - M.get_name (| globals, "GAS_STORAGE_UPDATE" |) in + let _ := M.assign_local (| + "gas_cost" , + M.get_name (| globals, "GAS_STORAGE_UPDATE" |) + |) in M.pure Constant.None_ )) |) in let _ := diff --git a/CoqOfPython/ethereum/byzantium/vm/instructions/system.v b/CoqOfPython/ethereum/byzantium/vm/instructions/system.v index 470c813..e75fc6e 100644 --- a/CoqOfPython/ethereum/byzantium/vm/instructions/system.v +++ b/CoqOfPython/ethereum/byzantium/vm/instructions/system.v @@ -17,35 +17,85 @@ Introduction Implementations of the EVM system related instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_byzantium_fork_types_imports : - AreImported globals "ethereum.byzantium.fork_types" [ "Address" ]. +Axiom ethereum_byzantium_fork_types_imports_Address : + IsImported globals "ethereum.byzantium.fork_types" "Address". -Axiom ethereum_byzantium_state_imports : - AreImported globals "ethereum.byzantium.state" [ "account_exists_and_is_empty"; "account_has_code_or_nonce"; "get_account"; "increment_nonce"; "is_account_alive"; "set_account_balance" ]. +Axiom ethereum_byzantium_state_imports_account_exists_and_is_empty : + IsImported globals "ethereum.byzantium.state" "account_exists_and_is_empty". +Axiom ethereum_byzantium_state_imports_account_has_code_or_nonce : + IsImported globals "ethereum.byzantium.state" "account_has_code_or_nonce". +Axiom ethereum_byzantium_state_imports_get_account : + IsImported globals "ethereum.byzantium.state" "get_account". +Axiom ethereum_byzantium_state_imports_increment_nonce : + IsImported globals "ethereum.byzantium.state" "increment_nonce". +Axiom ethereum_byzantium_state_imports_is_account_alive : + IsImported globals "ethereum.byzantium.state" "is_account_alive". +Axiom ethereum_byzantium_state_imports_set_account_balance : + IsImported globals "ethereum.byzantium.state" "set_account_balance". -Axiom ethereum_byzantium_utils_address_imports : - AreImported globals "ethereum.byzantium.utils.address" [ "compute_contract_address"; "to_address" ]. +Axiom ethereum_byzantium_utils_address_imports_compute_contract_address : + IsImported globals "ethereum.byzantium.utils.address" "compute_contract_address". +Axiom ethereum_byzantium_utils_address_imports_to_address : + IsImported globals "ethereum.byzantium.utils.address" "to_address". -Axiom ethereum_byzantium_vm_imports : - AreImported globals "ethereum.byzantium.vm" [ "Evm"; "Message"; "incorporate_child_on_error"; "incorporate_child_on_success" ]. +Axiom ethereum_byzantium_vm_imports_Evm : + IsImported globals "ethereum.byzantium.vm" "Evm". +Axiom ethereum_byzantium_vm_imports_Message : + IsImported globals "ethereum.byzantium.vm" "Message". +Axiom ethereum_byzantium_vm_imports_incorporate_child_on_error : + IsImported globals "ethereum.byzantium.vm" "incorporate_child_on_error". +Axiom ethereum_byzantium_vm_imports_incorporate_child_on_success : + IsImported globals "ethereum.byzantium.vm" "incorporate_child_on_success". -Axiom ethereum_byzantium_vm_exceptions_imports : - AreImported globals "ethereum.byzantium.vm.exceptions" [ "Revert"; "WriteInStaticContext" ]. +Axiom ethereum_byzantium_vm_exceptions_imports_Revert : + IsImported globals "ethereum.byzantium.vm.exceptions" "Revert". +Axiom ethereum_byzantium_vm_exceptions_imports_WriteInStaticContext : + IsImported globals "ethereum.byzantium.vm.exceptions" "WriteInStaticContext". -Axiom ethereum_byzantium_vm_gas_imports : - AreImported globals "ethereum.byzantium.vm.gas" [ "GAS_CALL"; "GAS_CALL_VALUE"; "GAS_CREATE"; "GAS_NEW_ACCOUNT"; "GAS_SELF_DESTRUCT"; "GAS_SELF_DESTRUCT_NEW_ACCOUNT"; "GAS_ZERO"; "REFUND_SELF_DESTRUCT"; "calculate_gas_extend_memory"; "calculate_message_call_gas"; "charge_gas"; "max_message_call_gas" ]. +Axiom ethereum_byzantium_vm_gas_imports_GAS_CALL : + IsImported globals "ethereum.byzantium.vm.gas" "GAS_CALL". +Axiom ethereum_byzantium_vm_gas_imports_GAS_CALL_VALUE : + IsImported globals "ethereum.byzantium.vm.gas" "GAS_CALL_VALUE". +Axiom ethereum_byzantium_vm_gas_imports_GAS_CREATE : + IsImported globals "ethereum.byzantium.vm.gas" "GAS_CREATE". +Axiom ethereum_byzantium_vm_gas_imports_GAS_NEW_ACCOUNT : + IsImported globals "ethereum.byzantium.vm.gas" "GAS_NEW_ACCOUNT". +Axiom ethereum_byzantium_vm_gas_imports_GAS_SELF_DESTRUCT : + IsImported globals "ethereum.byzantium.vm.gas" "GAS_SELF_DESTRUCT". +Axiom ethereum_byzantium_vm_gas_imports_GAS_SELF_DESTRUCT_NEW_ACCOUNT : + IsImported globals "ethereum.byzantium.vm.gas" "GAS_SELF_DESTRUCT_NEW_ACCOUNT". +Axiom ethereum_byzantium_vm_gas_imports_GAS_ZERO : + IsImported globals "ethereum.byzantium.vm.gas" "GAS_ZERO". +Axiom ethereum_byzantium_vm_gas_imports_REFUND_SELF_DESTRUCT : + IsImported globals "ethereum.byzantium.vm.gas" "REFUND_SELF_DESTRUCT". +Axiom ethereum_byzantium_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.byzantium.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_byzantium_vm_gas_imports_calculate_message_call_gas : + IsImported globals "ethereum.byzantium.vm.gas" "calculate_message_call_gas". +Axiom ethereum_byzantium_vm_gas_imports_charge_gas : + IsImported globals "ethereum.byzantium.vm.gas" "charge_gas". +Axiom ethereum_byzantium_vm_gas_imports_max_message_call_gas : + IsImported globals "ethereum.byzantium.vm.gas" "max_message_call_gas". -Axiom ethereum_byzantium_vm_memory_imports : - AreImported globals "ethereum.byzantium.vm.memory" [ "memory_read_bytes"; "memory_write" ]. +Axiom ethereum_byzantium_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.byzantium.vm.memory" "memory_read_bytes". +Axiom ethereum_byzantium_vm_memory_imports_memory_write : + IsImported globals "ethereum.byzantium.vm.memory" "memory_write". -Axiom ethereum_byzantium_vm_stack_imports : - AreImported globals "ethereum.byzantium.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_byzantium_vm_stack_imports_pop : + IsImported globals "ethereum.byzantium.vm.stack" "pop". +Axiom ethereum_byzantium_vm_stack_imports_push : + IsImported globals "ethereum.byzantium.vm.stack" "push". Definition create : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -59,31 +109,38 @@ Definition create : Value.t -> Value.t -> M := The current EVM frame. " in (* At stmt: unsupported node type: ImportFrom *) - let endowment := + let _ := M.assign_local (| + "endowment" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_size := + |) + |) in + let _ := M.assign_local (| + "memory_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -93,7 +150,8 @@ Definition create : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -105,7 +163,8 @@ Definition create : Value.t -> Value.t -> M := ], make_dict [] |) in - let create_message_gas := + let _ := M.assign_local (| + "create_message_gas" , M.call (| M.get_name (| globals, "max_message_call_gas" |), make_list [ @@ -118,7 +177,8 @@ Definition create : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.assign_op (| BinOp.sub, M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), @@ -144,9 +204,12 @@ Definition create : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), Constant.bytes "" |) in - let sender_address := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in - let sender := + let _ := M.assign_local (| + "sender_address" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + |) in + let _ := M.assign_local (| + "sender" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -154,8 +217,10 @@ Definition create : Value.t -> Value.t -> M := M.get_name (| globals, "sender_address" |) ], make_dict [] - |) in - let contract_address := + |) + |) in + let _ := M.assign_local (| + "contract_address" , M.call (| M.get_name (| globals, "compute_contract_address" |), make_list [ @@ -170,7 +235,8 @@ Definition create : Value.t -> Value.t -> M := |), "nonce" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -271,7 +337,8 @@ Definition create : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let call_data := + let _ := M.assign_local (| + "call_data" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -280,7 +347,8 @@ Definition create : Value.t -> Value.t -> M := M.get_name (| globals, "memory_size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "increment_nonce" |), make_list [ @@ -289,13 +357,16 @@ Definition create : Value.t -> Value.t -> M := ], make_dict [] |) in - let child_message := + let _ := M.assign_local (| + "child_message" , M.call (| M.get_name (| globals, "Message" |), make_list [], make_dict [] - |) in - let child_evm := + |) + |) in + let _ := M.assign_local (| + "child_evm" , M.call (| M.get_name (| globals, "process_create_message" |), make_list [ @@ -303,7 +374,8 @@ Definition create : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -389,23 +461,28 @@ Definition return_ : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let memory_start_position := + let _ := M.assign_local (| + "memory_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_size := + |) + |) in + let _ := M.assign_local (| + "memory_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -415,7 +492,8 @@ Definition return_ : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -504,7 +582,8 @@ Definition generic_call : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let call_data := + let _ := M.assign_local (| + "call_data" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -513,8 +592,10 @@ Definition generic_call : Value.t -> Value.t -> M := M.get_name (| globals, "memory_input_size" |) ], make_dict [] - |) in - let code := + |) + |) in + let _ := M.assign_local (| + "code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -522,14 +603,18 @@ Definition generic_call : Value.t -> Value.t -> M := M.get_name (| globals, "code_address" |) ], make_dict [] - |), "code" |) in - let child_message := + |), "code" |) + |) in + let _ := M.assign_local (| + "child_message" , M.call (| M.get_name (| globals, "Message" |), make_list [], make_dict [] - |) in - let child_evm := + |) + |) in + let _ := M.assign_local (| + "child_evm" , M.call (| M.get_name (| globals, "process_message" |), make_list [ @@ -537,7 +622,8 @@ Definition generic_call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -601,7 +687,8 @@ Definition generic_call : Value.t -> Value.t -> M := |) in M.pure Constant.None_ )) |) in - let actual_output_size := + let _ := M.assign_local (| + "actual_output_size" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -621,7 +708,8 @@ Definition generic_call : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -649,7 +737,8 @@ Definition call : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -662,8 +751,10 @@ Definition call : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let to := + |) + |) in + let _ := M.assign_local (| + "to" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -676,48 +767,60 @@ Definition call : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -728,8 +831,10 @@ Definition call : Value.t -> Value.t -> M := ] ], make_dict [] - |) in - let create_gas_cost := + |) + |) in + let _ := M.assign_local (| + "create_gas_cost" , (* if *) M.if_then_else (| BoolOp.or (| @@ -760,8 +865,10 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "GAS_NEW_ACCOUNT" |) - )) |) in - let transfer_gas_cost := + )) |) + |) in + let _ := M.assign_local (| + "transfer_gas_cost" , (* if *) M.if_then_else (| Compare.eq (| @@ -780,8 +887,10 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "GAS_CALL_VALUE" |) - )) |) in - let message_call_gas := + )) |) + |) in + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -804,7 +913,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -846,7 +956,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let sender_balance := + let _ := M.assign_local (| + "sender_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -854,7 +965,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := (* if *) M.if_then_else (| @@ -928,7 +1040,8 @@ Definition callcode : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -941,8 +1054,10 @@ Definition callcode : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let code_address := + |) + |) in + let _ := M.assign_local (| + "code_address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -955,50 +1070,64 @@ Definition callcode : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let to := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "to" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1009,8 +1138,10 @@ Definition callcode : Value.t -> Value.t -> M := ] ], make_dict [] - |) in - let transfer_gas_cost := + |) + |) in + let _ := M.assign_local (| + "transfer_gas_cost" , (* if *) M.if_then_else (| Compare.eq (| @@ -1029,8 +1160,10 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "GAS_CALL_VALUE" |) - )) |) in - let message_call_gas := + )) |) + |) in + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -1050,7 +1183,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1070,7 +1204,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let sender_balance := + let _ := M.assign_local (| + "sender_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1078,7 +1213,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := (* if *) M.if_then_else (| @@ -1152,7 +1288,8 @@ Definition selfdestruct : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let beneficiary := + let _ := M.assign_local (| + "beneficiary" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1165,9 +1302,12 @@ Definition selfdestruct : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let gas_cost := - M.get_name (| globals, "GAS_SELF_DESTRUCT" |) in + |) + |) in + let _ := M.assign_local (| + "gas_cost" , + M.get_name (| globals, "GAS_SELF_DESTRUCT" |) + |) in let _ := (* if *) M.if_then_else (| @@ -1196,20 +1336,28 @@ Definition selfdestruct : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let gas_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "gas_cost", M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) - M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let originator := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in - let refunded_accounts := - M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in - let parent_evm := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "parent_evm" |) in + let _ := M.assign_local (| + "originator" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + |) in + let _ := M.assign_local (| + "refunded_accounts" , + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) + |) in + let _ := M.assign_local (| + "parent_evm" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "parent_evm" |) + |) in let _ := M.while (| Compare.is_not (| @@ -1224,8 +1372,10 @@ Definition selfdestruct : Value.t -> Value.t -> M := ], make_dict [] |) in - let parent_evm := - M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in + let _ := M.assign_local (| + "parent_evm" , + M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -1267,7 +1417,8 @@ Definition selfdestruct : Value.t -> Value.t -> M := ], make_dict [] |) in - let beneficiary_balance := + let _ := M.assign_local (| + "beneficiary_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1275,8 +1426,10 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_name (| globals, "beneficiary" |) ], make_dict [] - |), "balance" |) in - let originator_balance := + |), "balance" |) + |) in + let _ := M.assign_local (| + "originator_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1284,7 +1437,8 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_name (| globals, "originator" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -1362,7 +1516,8 @@ Definition delegatecall : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -1375,8 +1530,10 @@ Definition delegatecall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let code_address := + |) + |) in + let _ := M.assign_local (| + "code_address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1389,40 +1546,50 @@ Definition delegatecall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1433,8 +1600,10 @@ Definition delegatecall : Value.t -> Value.t -> M := ] ], make_dict [] - |) in - let message_call_gas := + |) + |) in + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -1457,7 +1626,8 @@ Definition delegatecall : Value.t -> Value.t -> M := M.get_name (| globals, "GAS_CALL" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1513,7 +1683,8 @@ Definition staticcall : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -1526,8 +1697,10 @@ Definition staticcall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let to := + |) + |) in + let _ := M.assign_local (| + "to" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1540,40 +1713,50 @@ Definition staticcall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1584,8 +1767,10 @@ Definition staticcall : Value.t -> Value.t -> M := ] ], make_dict [] - |) in - let message_call_gas := + |) + |) in + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -1608,7 +1793,8 @@ Definition staticcall : Value.t -> Value.t -> M := M.get_name (| globals, "GAS_CALL" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1670,23 +1856,28 @@ Definition revert : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1696,7 +1887,8 @@ Definition revert : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1713,7 +1905,8 @@ Definition revert : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let output := + let _ := M.assign_local (| + "output" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -1722,7 +1915,8 @@ Definition revert : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| diff --git a/CoqOfPython/ethereum/byzantium/vm/interpreter.v b/CoqOfPython/ethereum/byzantium/vm/interpreter.v index e9ddd6b..53559db 100644 --- a/CoqOfPython/ethereum/byzantium/vm/interpreter.v +++ b/CoqOfPython/ethereum/byzantium/vm/interpreter.v @@ -17,50 +17,108 @@ Introduction A straightforward interpreter that executes EVM code. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Iterable"; "Optional"; "Set"; "Tuple" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. - -Axiom ethereum_trace_imports : - AreImported globals "ethereum.trace" [ "EvmStop"; "OpEnd"; "OpException"; "OpStart"; "PrecompileEnd"; "PrecompileStart"; "TransactionEnd"; "evm_trace" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_byzantium_blocks_imports : - AreImported globals "ethereum.byzantium.blocks" [ "Log" ]. - -Axiom ethereum_byzantium_fork_types_imports : - AreImported globals "ethereum.byzantium.fork_types" [ "Address" ]. - -Axiom ethereum_byzantium_state_imports : - AreImported globals "ethereum.byzantium.state" [ "account_exists_and_is_empty"; "account_has_code_or_nonce"; "begin_transaction"; "commit_transaction"; "destroy_storage"; "increment_nonce"; "move_ether"; "rollback_transaction"; "set_code"; "touch_account" ]. - -Axiom ethereum_byzantium_vm_imports : - AreImported globals "ethereum.byzantium.vm" [ "Message" ]. - -Axiom ethereum_byzantium_vm_gas_imports : - AreImported globals "ethereum.byzantium.vm.gas" [ "GAS_CODE_DEPOSIT"; "charge_gas" ]. - -Axiom ethereum_byzantium_vm_precompiled_contracts_mapping_imports : - AreImported globals "ethereum.byzantium.vm.precompiled_contracts.mapping" [ "PRE_COMPILED_CONTRACTS" ]. - -Axiom ethereum_byzantium_vm_imports : - AreImported globals "ethereum.byzantium.vm" [ "Environment"; "Evm" ]. - -Axiom ethereum_byzantium_vm_exceptions_imports : - AreImported globals "ethereum.byzantium.vm.exceptions" [ "AddressCollision"; "ExceptionalHalt"; "InvalidOpcode"; "OutOfGasError"; "Revert"; "StackDepthLimitError" ]. - -Axiom ethereum_byzantium_vm_instructions_imports : - AreImported globals "ethereum.byzantium.vm.instructions" [ "Ops"; "op_implementation" ]. - -Axiom ethereum_byzantium_vm_runtime_imports : - AreImported globals "ethereum.byzantium.vm.runtime" [ "get_valid_jump_destinations" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_Iterable : + IsImported globals "typing" "Iterable". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_trace_imports_EvmStop : + IsImported globals "ethereum.trace" "EvmStop". +Axiom ethereum_trace_imports_OpEnd : + IsImported globals "ethereum.trace" "OpEnd". +Axiom ethereum_trace_imports_OpException : + IsImported globals "ethereum.trace" "OpException". +Axiom ethereum_trace_imports_OpStart : + IsImported globals "ethereum.trace" "OpStart". +Axiom ethereum_trace_imports_PrecompileEnd : + IsImported globals "ethereum.trace" "PrecompileEnd". +Axiom ethereum_trace_imports_PrecompileStart : + IsImported globals "ethereum.trace" "PrecompileStart". +Axiom ethereum_trace_imports_TransactionEnd : + IsImported globals "ethereum.trace" "TransactionEnd". +Axiom ethereum_trace_imports_evm_trace : + IsImported globals "ethereum.trace" "evm_trace". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_byzantium_blocks_imports_Log : + IsImported globals "ethereum.byzantium.blocks" "Log". + +Axiom ethereum_byzantium_fork_types_imports_Address : + IsImported globals "ethereum.byzantium.fork_types" "Address". + +Axiom ethereum_byzantium_state_imports_account_exists_and_is_empty : + IsImported globals "ethereum.byzantium.state" "account_exists_and_is_empty". +Axiom ethereum_byzantium_state_imports_account_has_code_or_nonce : + IsImported globals "ethereum.byzantium.state" "account_has_code_or_nonce". +Axiom ethereum_byzantium_state_imports_begin_transaction : + IsImported globals "ethereum.byzantium.state" "begin_transaction". +Axiom ethereum_byzantium_state_imports_commit_transaction : + IsImported globals "ethereum.byzantium.state" "commit_transaction". +Axiom ethereum_byzantium_state_imports_destroy_storage : + IsImported globals "ethereum.byzantium.state" "destroy_storage". +Axiom ethereum_byzantium_state_imports_increment_nonce : + IsImported globals "ethereum.byzantium.state" "increment_nonce". +Axiom ethereum_byzantium_state_imports_move_ether : + IsImported globals "ethereum.byzantium.state" "move_ether". +Axiom ethereum_byzantium_state_imports_rollback_transaction : + IsImported globals "ethereum.byzantium.state" "rollback_transaction". +Axiom ethereum_byzantium_state_imports_set_code : + IsImported globals "ethereum.byzantium.state" "set_code". +Axiom ethereum_byzantium_state_imports_touch_account : + IsImported globals "ethereum.byzantium.state" "touch_account". + +Axiom ethereum_byzantium_vm_imports_Message : + IsImported globals "ethereum.byzantium.vm" "Message". + +Axiom ethereum_byzantium_vm_gas_imports_GAS_CODE_DEPOSIT : + IsImported globals "ethereum.byzantium.vm.gas" "GAS_CODE_DEPOSIT". +Axiom ethereum_byzantium_vm_gas_imports_charge_gas : + IsImported globals "ethereum.byzantium.vm.gas" "charge_gas". + +Axiom ethereum_byzantium_vm_precompiled_contracts_mapping_imports_PRE_COMPILED_CONTRACTS : + IsImported globals "ethereum.byzantium.vm.precompiled_contracts.mapping" "PRE_COMPILED_CONTRACTS". + +Axiom ethereum_byzantium_vm_imports_Environment : + IsImported globals "ethereum.byzantium.vm" "Environment". +Axiom ethereum_byzantium_vm_imports_Evm : + IsImported globals "ethereum.byzantium.vm" "Evm". + +Axiom ethereum_byzantium_vm_exceptions_imports_AddressCollision : + IsImported globals "ethereum.byzantium.vm.exceptions" "AddressCollision". +Axiom ethereum_byzantium_vm_exceptions_imports_ExceptionalHalt : + IsImported globals "ethereum.byzantium.vm.exceptions" "ExceptionalHalt". +Axiom ethereum_byzantium_vm_exceptions_imports_InvalidOpcode : + IsImported globals "ethereum.byzantium.vm.exceptions" "InvalidOpcode". +Axiom ethereum_byzantium_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.byzantium.vm.exceptions" "OutOfGasError". +Axiom ethereum_byzantium_vm_exceptions_imports_Revert : + IsImported globals "ethereum.byzantium.vm.exceptions" "Revert". +Axiom ethereum_byzantium_vm_exceptions_imports_StackDepthLimitError : + IsImported globals "ethereum.byzantium.vm.exceptions" "StackDepthLimitError". + +Axiom ethereum_byzantium_vm_instructions_imports_Ops : + IsImported globals "ethereum.byzantium.vm.instructions" "Ops". +Axiom ethereum_byzantium_vm_instructions_imports_op_implementation : + IsImported globals "ethereum.byzantium.vm.instructions" "op_implementation". + +Axiom ethereum_byzantium_vm_runtime_imports_get_valid_jump_destinations : + IsImported globals "ethereum.byzantium.vm.runtime" "get_valid_jump_destinations". Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -121,7 +179,8 @@ Definition process_message_call : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let is_collision := + let _ := M.assign_local (| + "is_collision" , M.call (| M.get_name (| globals, "account_has_code_or_nonce" |), make_list [ @@ -129,7 +188,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "message" |), "current_target" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -181,7 +241,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "process_create_message" |), make_list [ @@ -189,13 +250,15 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "process_message" |), make_list [ @@ -203,7 +266,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -250,40 +314,55 @@ Definition process_message_call : Value.t -> Value.t -> M := (* then *) ltac:(M.monadic ( (* At stmt: unsupported node type: AnnAssign *) - let accounts_to_delete := + let _ := M.assign_local (| + "accounts_to_delete" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let touched_accounts := + |) + |) in + let _ := M.assign_local (| + "touched_accounts" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let refund_counter := + |) + |) in + let _ := M.assign_local (| + "refund_counter" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let logs := - M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in - let accounts_to_delete := - M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in - let touched_accounts := - M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |) in - let refund_counter := - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |) in + let _ := M.assign_local (| + "logs" , + M.get_field (| M.get_name (| globals, "evm" |), "logs" |) + |) in + let _ := M.assign_local (| + "accounts_to_delete" , + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) + |) in + let _ := M.assign_local (| + "touched_accounts" , + M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |) + |) in + let _ := M.assign_local (| + "refund_counter" , + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |) + |) in M.pure Constant.None_ )) |) in - let tx_end := + let _ := M.assign_local (| + "tx_end" , M.call (| M.get_name (| globals, "TransactionEnd" |), make_list [ @@ -295,7 +374,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "error" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "evm_trace" |), make_list [ @@ -354,7 +434,8 @@ Definition process_create_message : Value.t -> Value.t -> M := ], make_dict [] |) in - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "process_message" |), make_list [ @@ -362,16 +443,20 @@ Definition process_create_message : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), (* then *) ltac:(M.monadic ( - let contract_code := - M.get_field (| M.get_name (| globals, "evm" |), "output" |) in - let contract_code_gas := + let _ := M.assign_local (| + "contract_code" , + M.get_field (| M.get_name (| globals, "evm" |), "output" |) + |) in + let _ := M.assign_local (| + "contract_code_gas" , BinOp.mult (| M.call (| M.get_name (| globals, "len" |), @@ -381,7 +466,8 @@ Definition process_create_message : Value.t -> Value.t -> M := make_dict [] |), M.get_name (| globals, "GAS_CODE_DEPOSIT" |) - |) in + |) + |) in (* At stmt: unsupported node type: Try *) M.pure Constant.None_ (* else *) @@ -483,7 +569,8 @@ Definition process_message : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "execute_code" |), make_list [ @@ -491,7 +578,8 @@ Definition process_message : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -540,22 +628,28 @@ Definition execute_code : Value.t -> Value.t -> M := evm: `ethereum.vm.EVM` Items containing execution specific objects " in - let code := - M.get_field (| M.get_name (| globals, "message" |), "code" |) in - let valid_jump_destinations := + let _ := M.assign_local (| + "code" , + M.get_field (| M.get_name (| globals, "message" |), "code" |) + |) in + let _ := M.assign_local (| + "valid_jump_destinations" , M.call (| M.get_name (| globals, "get_valid_jump_destinations" |), make_list [ M.get_name (| globals, "code" |) ], make_dict [] - |) in - let evm := + |) + |) in + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "Evm" |), make_list [], make_dict [] - |) in + |) + |) in (* At stmt: unsupported node type: Try *) let _ := M.return_ (| M.get_name (| globals, "evm" |) diff --git a/CoqOfPython/ethereum/byzantium/vm/memory.v b/CoqOfPython/ethereum/byzantium/vm/memory.v index 18903ab..148e6c5 100644 --- a/CoqOfPython/ethereum/byzantium/vm/memory.v +++ b/CoqOfPython/ethereum/byzantium/vm/memory.v @@ -17,11 +17,15 @@ Introduction EVM memory operations. ". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "right_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_right_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "right_pad_zero_bytes". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". Definition memory_write : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/__init__.v index dc8ad82..d82e958 100644 --- a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/__init__.v +++ b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/__init__.v @@ -18,8 +18,8 @@ Addresses of precompiled contracts and mappings to their implementations. ". -Axiom ethereum_byzantium_utils_hexadecimal_imports : - AreImported globals "ethereum.byzantium.utils.hexadecimal" [ "hex_to_address" ]. +Axiom ethereum_byzantium_utils_hexadecimal_imports_hex_to_address : + IsImported globals "ethereum.byzantium.utils.hexadecimal" "hex_to_address". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS"; Constant.str "MODEXP_ADDRESS"; Constant.str "ALT_BN128_ADD_ADDRESS"; Constant.str "ALT_BN128_MUL_ADDRESS"; Constant.str "ALT_BN128_PAIRING_CHECK_ADDRESS"; Constant.str "BLAKE2F_ADDRESS" ] diff --git a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/alt_bn128.v index c75c674..01b9f2c 100644 --- a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/alt_bn128.v +++ b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/alt_bn128.v @@ -17,26 +17,42 @@ Introduction Implementation of the ALT_BN128 precompiled contracts. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_alt_bn128_imports : - AreImported globals "ethereum.crypto.alt_bn128" [ "ALT_BN128_CURVE_ORDER"; "ALT_BN128_PRIME"; "BNF"; "BNF2"; "BNF12"; "BNP"; "BNP2"; "pairing" ]. +Axiom ethereum_crypto_alt_bn128_imports_ALT_BN128_CURVE_ORDER : + IsImported globals "ethereum.crypto.alt_bn128" "ALT_BN128_CURVE_ORDER". +Axiom ethereum_crypto_alt_bn128_imports_ALT_BN128_PRIME : + IsImported globals "ethereum.crypto.alt_bn128" "ALT_BN128_PRIME". +Axiom ethereum_crypto_alt_bn128_imports_BNF : + IsImported globals "ethereum.crypto.alt_bn128" "BNF". +Axiom ethereum_crypto_alt_bn128_imports_BNF2 : + IsImported globals "ethereum.crypto.alt_bn128" "BNF2". +Axiom ethereum_crypto_alt_bn128_imports_BNF12 : + IsImported globals "ethereum.crypto.alt_bn128" "BNF12". +Axiom ethereum_crypto_alt_bn128_imports_BNP : + IsImported globals "ethereum.crypto.alt_bn128" "BNP". +Axiom ethereum_crypto_alt_bn128_imports_BNP2 : + IsImported globals "ethereum.crypto.alt_bn128" "BNP2". +Axiom ethereum_crypto_alt_bn128_imports_pairing : + IsImported globals "ethereum.crypto.alt_bn128" "pairing". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_byzantium_vm_imports : - AreImported globals "ethereum.byzantium.vm" [ "Evm" ]. +Axiom ethereum_byzantium_vm_imports_Evm : + IsImported globals "ethereum.byzantium.vm" "Evm". -Axiom ethereum_byzantium_vm_gas_imports : - AreImported globals "ethereum.byzantium.vm.gas" [ "charge_gas" ]. +Axiom ethereum_byzantium_vm_gas_imports_charge_gas : + IsImported globals "ethereum.byzantium.vm.gas" "charge_gas". -Axiom ethereum_byzantium_vm_memory_imports : - AreImported globals "ethereum.byzantium.vm.memory" [ "buffer_read" ]. +Axiom ethereum_byzantium_vm_memory_imports_buffer_read : + IsImported globals "ethereum.byzantium.vm.memory" "buffer_read". -Axiom ethereum_byzantium_vm_exceptions_imports : - AreImported globals "ethereum.byzantium.vm.exceptions" [ "OutOfGasError" ]. +Axiom ethereum_byzantium_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.byzantium.vm.exceptions" "OutOfGasError". Definition alt_bn128_add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -49,8 +65,10 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -65,7 +83,8 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := ], make_dict [] |) in - let x0_bytes := + let _ := M.assign_local (| + "x0_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -86,16 +105,20 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let x0_value := + |) + |) in + let _ := M.assign_local (| + "x0_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "x0_bytes" |) ], make_dict [] - |) in - let y0_bytes := + |) + |) in + let _ := M.assign_local (| + "y0_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -116,16 +139,20 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y0_value := + |) + |) in + let _ := M.assign_local (| + "y0_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "y0_bytes" |) ], make_dict [] - |) in - let x1_bytes := + |) + |) in + let _ := M.assign_local (| + "x1_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -146,16 +173,20 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let x1_value := + |) + |) in + let _ := M.assign_local (| + "x1_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "x1_bytes" |) ], make_dict [] - |) in - let y1_bytes := + |) + |) in + let _ := M.assign_local (| + "y1_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -176,15 +207,18 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y1_value := + |) + |) in + let _ := M.assign_local (| + "y1_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "y1_bytes" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "i" |), @@ -212,11 +246,13 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := )) |) in (* At stmt: unsupported node type: Try *) - let p := + let _ := M.assign_local (| + "p" , BinOp.add (| M.get_name (| globals, "p0" |), M.get_name (| globals, "p1" |) - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), BinOp.add (| @@ -245,8 +281,10 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -261,7 +299,8 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := ], make_dict [] |) in - let x0_bytes := + let _ := M.assign_local (| + "x0_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -282,16 +321,20 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let x0_value := + |) + |) in + let _ := M.assign_local (| + "x0_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "x0_bytes" |) ], make_dict [] - |) in - let y0_bytes := + |) + |) in + let _ := M.assign_local (| + "y0_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -312,16 +355,20 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y0_value := + |) + |) in + let _ := M.assign_local (| + "y0_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "y0_bytes" |) ], make_dict [] - |) in - let n := + |) + |) in + let _ := M.assign_local (| + "n" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -348,7 +395,8 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "i" |), @@ -376,14 +424,16 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := )) |) in (* At stmt: unsupported node type: Try *) - let p := + let _ := M.assign_local (| + "p" , M.call (| M.get_field (| M.get_name (| globals, "p0" |), "mul_by" |), make_list [ M.get_name (| globals, "n" |) ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), BinOp.add (| @@ -412,8 +462,10 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -467,14 +519,16 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), make_list [ Constant.int 1 ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "i" |), @@ -495,8 +549,10 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let values := - make_list [] in + let _ := M.assign_local (| + "values" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "j" |), @@ -508,7 +564,8 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -541,7 +598,8 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -644,7 +702,8 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , BinOp.mult (| M.get_name (| globals, "result" |), M.call (| @@ -655,7 +714,8 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/ecrecover.v index e130dd9..6daeeb3 100644 --- a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/ecrecover.v @@ -17,26 +17,32 @@ Introduction Implementation of the ECRECOVER precompiled contract. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_crypto_elliptic_curve_imports : - AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. +Axiom ethereum_crypto_elliptic_curve_imports_SECP256K1N : + IsImported globals "ethereum.crypto.elliptic_curve" "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_imports_secp256k1_recover : + IsImported globals "ethereum.crypto.elliptic_curve" "secp256k1_recover". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_left_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "left_pad_zero_bytes". -Axiom ethereum_byzantium_vm_imports : - AreImported globals "ethereum.byzantium.vm" [ "Evm" ]. +Axiom ethereum_byzantium_vm_imports_Evm : + IsImported globals "ethereum.byzantium.vm" "Evm". -Axiom ethereum_byzantium_vm_gas_imports : - AreImported globals "ethereum.byzantium.vm.gas" [ "GAS_ECRECOVER"; "charge_gas" ]. +Axiom ethereum_byzantium_vm_gas_imports_GAS_ECRECOVER : + IsImported globals "ethereum.byzantium.vm.gas" "GAS_ECRECOVER". +Axiom ethereum_byzantium_vm_gas_imports_charge_gas : + IsImported globals "ethereum.byzantium.vm.gas" "charge_gas". -Axiom ethereum_byzantium_vm_memory_imports : - AreImported globals "ethereum.byzantium.vm.memory" [ "buffer_read" ]. +Axiom ethereum_byzantium_vm_memory_imports_buffer_read : + IsImported globals "ethereum.byzantium.vm.memory" "buffer_read". Definition ecrecover : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -50,8 +56,10 @@ Definition ecrecover : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -60,7 +68,8 @@ Definition ecrecover : Value.t -> Value.t -> M := ], make_dict [] |) in - let message_hash_bytes := + let _ := M.assign_local (| + "message_hash_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -81,16 +90,20 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let message_hash := + |) + |) in + let _ := M.assign_local (| + "message_hash" , M.call (| M.get_name (| globals, "Hash32" |), make_list [ M.get_name (| globals, "message_hash_bytes" |) ], make_dict [] - |) in - let v := + |) + |) in + let _ := M.assign_local (| + "v" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -117,8 +130,10 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let r := + |) + |) in + let _ := M.assign_local (| + "r" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -145,8 +160,10 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let s := + |) + |) in + let _ := M.assign_local (| + "s" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -173,7 +190,8 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -250,7 +268,8 @@ Definition ecrecover : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: Try *) - let address := + let _ := M.assign_local (| + "address" , M.slice (| M.call (| M.get_name (| globals, "keccak256" |), @@ -262,8 +281,10 @@ Definition ecrecover : Value.t -> Value.t -> M := Constant.int 12, Constant.int 32, Constant.None_ - |) in - let padded_address := + |) + |) in + let _ := M.assign_local (| + "padded_address" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -271,7 +292,8 @@ Definition ecrecover : Value.t -> Value.t -> M := Constant.int 32 ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.get_name (| globals, "padded_address" |) diff --git a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/identity.v index 6ee7dae..7f914dd 100644 --- a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/identity.v +++ b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/identity.v @@ -17,17 +17,21 @@ Introduction Implementation of the `IDENTITY` precompiled contract. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_byzantium_vm_imports : - AreImported globals "ethereum.byzantium.vm" [ "Evm" ]. +Axiom ethereum_byzantium_vm_imports_Evm : + IsImported globals "ethereum.byzantium.vm" "Evm". -Axiom ethereum_byzantium_vm_gas_imports : - AreImported globals "ethereum.byzantium.vm.gas" [ "GAS_IDENTITY"; "GAS_IDENTITY_WORD"; "charge_gas" ]. +Axiom ethereum_byzantium_vm_gas_imports_GAS_IDENTITY : + IsImported globals "ethereum.byzantium.vm.gas" "GAS_IDENTITY". +Axiom ethereum_byzantium_vm_gas_imports_GAS_IDENTITY_WORD : + IsImported globals "ethereum.byzantium.vm.gas" "GAS_IDENTITY_WORD". +Axiom ethereum_byzantium_vm_gas_imports_charge_gas : + IsImported globals "ethereum.byzantium.vm.gas" "charge_gas". Definition identity : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -40,9 +44,12 @@ Definition identity : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let word_count := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "word_count" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -64,7 +71,8 @@ Definition identity : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ diff --git a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/mapping.v index d016ee6..7088817 100644 --- a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/mapping.v +++ b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/mapping.v @@ -17,31 +17,51 @@ Introduction Mapping of precompiled contracts their implementations. ". -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict" ]. +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". -Axiom ethereum_byzantium_fork_types_imports : - AreImported globals "ethereum.byzantium.fork_types" [ "Address" ]. +Axiom ethereum_byzantium_fork_types_imports_Address : + IsImported globals "ethereum.byzantium.fork_types" "Address". -Axiom ethereum_byzantium_vm_precompiled_contracts_imports : - AreImported globals "ethereum.byzantium.vm.precompiled_contracts" [ "ALT_BN128_ADD_ADDRESS"; "ALT_BN128_MUL_ADDRESS"; "ALT_BN128_PAIRING_CHECK_ADDRESS"; "ECRECOVER_ADDRESS"; "IDENTITY_ADDRESS"; "MODEXP_ADDRESS"; "RIPEMD160_ADDRESS"; "SHA256_ADDRESS" ]. +Axiom ethereum_byzantium_vm_precompiled_contracts_imports_ALT_BN128_ADD_ADDRESS : + IsImported globals "ethereum.byzantium.vm.precompiled_contracts" "ALT_BN128_ADD_ADDRESS". +Axiom ethereum_byzantium_vm_precompiled_contracts_imports_ALT_BN128_MUL_ADDRESS : + IsImported globals "ethereum.byzantium.vm.precompiled_contracts" "ALT_BN128_MUL_ADDRESS". +Axiom ethereum_byzantium_vm_precompiled_contracts_imports_ALT_BN128_PAIRING_CHECK_ADDRESS : + IsImported globals "ethereum.byzantium.vm.precompiled_contracts" "ALT_BN128_PAIRING_CHECK_ADDRESS". +Axiom ethereum_byzantium_vm_precompiled_contracts_imports_ECRECOVER_ADDRESS : + IsImported globals "ethereum.byzantium.vm.precompiled_contracts" "ECRECOVER_ADDRESS". +Axiom ethereum_byzantium_vm_precompiled_contracts_imports_IDENTITY_ADDRESS : + IsImported globals "ethereum.byzantium.vm.precompiled_contracts" "IDENTITY_ADDRESS". +Axiom ethereum_byzantium_vm_precompiled_contracts_imports_MODEXP_ADDRESS : + IsImported globals "ethereum.byzantium.vm.precompiled_contracts" "MODEXP_ADDRESS". +Axiom ethereum_byzantium_vm_precompiled_contracts_imports_RIPEMD160_ADDRESS : + IsImported globals "ethereum.byzantium.vm.precompiled_contracts" "RIPEMD160_ADDRESS". +Axiom ethereum_byzantium_vm_precompiled_contracts_imports_SHA256_ADDRESS : + IsImported globals "ethereum.byzantium.vm.precompiled_contracts" "SHA256_ADDRESS". -Axiom ethereum_byzantium_vm_precompiled_contracts_alt_bn128_imports : - AreImported globals "ethereum.byzantium.vm.precompiled_contracts.alt_bn128" [ "alt_bn128_add"; "alt_bn128_mul"; "alt_bn128_pairing_check" ]. +Axiom ethereum_byzantium_vm_precompiled_contracts_alt_bn128_imports_alt_bn128_add : + IsImported globals "ethereum.byzantium.vm.precompiled_contracts.alt_bn128" "alt_bn128_add". +Axiom ethereum_byzantium_vm_precompiled_contracts_alt_bn128_imports_alt_bn128_mul : + IsImported globals "ethereum.byzantium.vm.precompiled_contracts.alt_bn128" "alt_bn128_mul". +Axiom ethereum_byzantium_vm_precompiled_contracts_alt_bn128_imports_alt_bn128_pairing_check : + IsImported globals "ethereum.byzantium.vm.precompiled_contracts.alt_bn128" "alt_bn128_pairing_check". -Axiom ethereum_byzantium_vm_precompiled_contracts_ecrecover_imports : - AreImported globals "ethereum.byzantium.vm.precompiled_contracts.ecrecover" [ "ecrecover" ]. +Axiom ethereum_byzantium_vm_precompiled_contracts_ecrecover_imports_ecrecover : + IsImported globals "ethereum.byzantium.vm.precompiled_contracts.ecrecover" "ecrecover". -Axiom ethereum_byzantium_vm_precompiled_contracts_identity_imports : - AreImported globals "ethereum.byzantium.vm.precompiled_contracts.identity" [ "identity" ]. +Axiom ethereum_byzantium_vm_precompiled_contracts_identity_imports_identity : + IsImported globals "ethereum.byzantium.vm.precompiled_contracts.identity" "identity". -Axiom ethereum_byzantium_vm_precompiled_contracts_modexp_imports : - AreImported globals "ethereum.byzantium.vm.precompiled_contracts.modexp" [ "modexp" ]. +Axiom ethereum_byzantium_vm_precompiled_contracts_modexp_imports_modexp : + IsImported globals "ethereum.byzantium.vm.precompiled_contracts.modexp" "modexp". -Axiom ethereum_byzantium_vm_precompiled_contracts_ripemd160_imports : - AreImported globals "ethereum.byzantium.vm.precompiled_contracts.ripemd160" [ "ripemd160" ]. +Axiom ethereum_byzantium_vm_precompiled_contracts_ripemd160_imports_ripemd160 : + IsImported globals "ethereum.byzantium.vm.precompiled_contracts.ripemd160" "ripemd160". -Axiom ethereum_byzantium_vm_precompiled_contracts_sha256_imports : - AreImported globals "ethereum.byzantium.vm.precompiled_contracts.sha256" [ "sha256" ]. +Axiom ethereum_byzantium_vm_precompiled_contracts_sha256_imports_sha256 : + IsImported globals "ethereum.byzantium.vm.precompiled_contracts.sha256" "sha256". (* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/modexp.v index 7d7b8f9..d8d7f8d 100644 --- a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/modexp.v +++ b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/modexp.v @@ -17,17 +17,21 @@ Introduction Implementation of the `MODEXP` precompiled contract. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_byzantium_vm_imports : - AreImported globals "ethereum.byzantium.vm" [ "Evm" ]. +Axiom ethereum_byzantium_vm_imports_Evm : + IsImported globals "ethereum.byzantium.vm" "Evm". -Axiom ethereum_byzantium_vm_gas_imports : - AreImported globals "ethereum.byzantium.vm.gas" [ "charge_gas" ]. +Axiom ethereum_byzantium_vm_gas_imports_charge_gas : + IsImported globals "ethereum.byzantium.vm.gas" "charge_gas". -Axiom ethereum_byzantium_vm_memory_imports : - AreImported globals "ethereum.byzantium.vm.memory" [ "buffer_read" ]. +Axiom ethereum_byzantium_vm_memory_imports_buffer_read : + IsImported globals "ethereum.byzantium.vm.memory" "buffer_read". Definition GQUADDIVISOR : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -46,9 +50,12 @@ Definition modexp : Value.t -> Value.t -> M := Calculates `(base**exp) % modulus` for arbitrary sized `base`, `exp` and. `modulus`. The return value is the same length as the modulus. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let base_length := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "base_length" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -75,8 +82,10 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exp_length := + |) + |) in + let _ := M.assign_local (| + "exp_length" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -103,8 +112,10 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let modulus_length := + |) + |) in + let _ := M.assign_local (| + "modulus_length" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -131,8 +142,10 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exp_start := + |) + |) in + let _ := M.assign_local (| + "exp_start" , BinOp.add (| M.call (| M.get_name (| globals, "U256" |), @@ -142,8 +155,10 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |), M.get_name (| globals, "base_length" |) - |) in - let exp_head := + |) + |) in + let _ := M.assign_local (| + "exp_head" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -171,7 +186,8 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -181,7 +197,8 @@ Definition modexp : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let adjusted_exp_length := + let _ := M.assign_local (| + "adjusted_exp_length" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -202,11 +219,13 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let adjusted_exp_length := + let _ := M.assign_local (| + "adjusted_exp_length" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -242,7 +261,8 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -324,7 +344,8 @@ Definition modexp : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let base := + let _ := M.assign_local (| + "base" , M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ @@ -345,8 +366,10 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exp := + |) + |) in + let _ := M.assign_local (| + "exp" , M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ @@ -361,13 +384,17 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let modulus_start := + |) + |) in + let _ := M.assign_local (| + "modulus_start" , BinOp.add (| M.get_name (| globals, "exp_start" |), M.get_name (| globals, "exp_length" |) - |) in - let modulus := + |) + |) in + let _ := M.assign_local (| + "modulus" , M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ @@ -382,7 +409,8 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| diff --git a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/ripemd160.v index f5f954e..dcf5699 100644 --- a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/ripemd160.v +++ b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/ripemd160.v @@ -19,20 +19,24 @@ Implementation of the `RIPEMD160` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_left_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "left_pad_zero_bytes". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_byzantium_vm_imports : - AreImported globals "ethereum.byzantium.vm" [ "Evm" ]. +Axiom ethereum_byzantium_vm_imports_Evm : + IsImported globals "ethereum.byzantium.vm" "Evm". -Axiom ethereum_byzantium_vm_gas_imports : - AreImported globals "ethereum.byzantium.vm.gas" [ "GAS_RIPEMD160"; "GAS_RIPEMD160_WORD"; "charge_gas" ]. +Axiom ethereum_byzantium_vm_gas_imports_GAS_RIPEMD160 : + IsImported globals "ethereum.byzantium.vm.gas" "GAS_RIPEMD160". +Axiom ethereum_byzantium_vm_gas_imports_GAS_RIPEMD160_WORD : + IsImported globals "ethereum.byzantium.vm.gas" "GAS_RIPEMD160_WORD". +Axiom ethereum_byzantium_vm_gas_imports_charge_gas : + IsImported globals "ethereum.byzantium.vm.gas" "charge_gas". Definition ripemd160 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,9 +49,12 @@ Definition ripemd160 : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let word_count := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "word_count" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -69,7 +76,8 @@ Definition ripemd160 : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -84,7 +92,8 @@ Definition ripemd160 : Value.t -> Value.t -> M := ], make_dict [] |) in - let hash_bytes := + let _ := M.assign_local (| + "hash_bytes" , M.call (| M.get_field (| M.call (| M.get_field (| M.get_name (| globals, "hashlib" |), "new" |), @@ -96,8 +105,10 @@ Definition ripemd160 : Value.t -> Value.t -> M := |), "digest" |), make_list [], make_dict [] - |) in - let padded_hash := + |) + |) in + let _ := M.assign_local (| + "padded_hash" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -105,7 +116,8 @@ Definition ripemd160 : Value.t -> Value.t -> M := Constant.int 32 ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.get_name (| globals, "padded_hash" |) diff --git a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/sha256.v index 17ff45d..3059153 100644 --- a/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/sha256.v +++ b/CoqOfPython/ethereum/byzantium/vm/precompiled_contracts/sha256.v @@ -19,17 +19,21 @@ Implementation of the `SHA256` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_byzantium_vm_imports : - AreImported globals "ethereum.byzantium.vm" [ "Evm" ]. +Axiom ethereum_byzantium_vm_imports_Evm : + IsImported globals "ethereum.byzantium.vm" "Evm". -Axiom ethereum_byzantium_vm_gas_imports : - AreImported globals "ethereum.byzantium.vm.gas" [ "GAS_SHA256"; "GAS_SHA256_WORD"; "charge_gas" ]. +Axiom ethereum_byzantium_vm_gas_imports_GAS_SHA256 : + IsImported globals "ethereum.byzantium.vm.gas" "GAS_SHA256". +Axiom ethereum_byzantium_vm_gas_imports_GAS_SHA256_WORD : + IsImported globals "ethereum.byzantium.vm.gas" "GAS_SHA256_WORD". +Axiom ethereum_byzantium_vm_gas_imports_charge_gas : + IsImported globals "ethereum.byzantium.vm.gas" "charge_gas". Definition sha256 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,9 +46,12 @@ Definition sha256 : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let word_count := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "word_count" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -66,7 +73,8 @@ Definition sha256 : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ diff --git a/CoqOfPython/ethereum/byzantium/vm/runtime.v b/CoqOfPython/ethereum/byzantium/vm/runtime.v index 954535c..0417135 100644 --- a/CoqOfPython/ethereum/byzantium/vm/runtime.v +++ b/CoqOfPython/ethereum/byzantium/vm/runtime.v @@ -17,14 +17,14 @@ Introduction Runtime related operations used while executing EVM code. ". -Axiom typing_imports : - AreImported globals "typing" [ "Set" ]. +Axiom typing_imports_Set : + IsImported globals "typing" "Set". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_byzantium_vm_instructions_imports : - AreImported globals "ethereum.byzantium.vm.instructions" [ "Ops" ]. +Axiom ethereum_byzantium_vm_instructions_imports_Ops : + IsImported globals "ethereum.byzantium.vm.instructions" "Ops". Definition get_valid_jump_destinations : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -50,20 +50,24 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := valid_jump_destinations: `Set[Uint]` The set of valid jump destinations in the code. " in - let valid_jump_destinations := + let _ := M.assign_local (| + "valid_jump_destinations" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let pc := + |) + |) in + let _ := M.assign_local (| + "pc" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in let _ := M.while (| Compare.lt (| @@ -114,17 +118,21 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let push_data_size := + let _ := M.assign_local (| + "push_data_size" , BinOp.add (| BinOp.sub (| M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) |), Constant.int 1 - |) in - let pc := BinOp.add + |) + |) in + let _ := M.assign_op_local (| + BinOp.add, + "pc", M.get_name (| globals, "push_data_size" |) - M.get_name (| globals, "push_data_size" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -132,9 +140,11 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - let pc := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "pc", Constant.int 1 - Constant.int 1 in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/byzantium/vm/stack.v b/CoqOfPython/ethereum/byzantium/vm/stack.v index 203cac2..e9c738b 100644 --- a/CoqOfPython/ethereum/byzantium/vm/stack.v +++ b/CoqOfPython/ethereum/byzantium/vm/stack.v @@ -17,14 +17,16 @@ Introduction Implementation of the stack operators for the EVM. ". -Axiom typing_imports : - AreImported globals "typing" [ "List" ]. +Axiom typing_imports_List : + IsImported globals "typing" "List". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_byzantium_vm_exceptions_imports : - AreImported globals "ethereum.byzantium.vm.exceptions" [ "StackOverflowError"; "StackUnderflowError" ]. +Axiom ethereum_byzantium_vm_exceptions_imports_StackOverflowError : + IsImported globals "ethereum.byzantium.vm.exceptions" "StackOverflowError". +Axiom ethereum_byzantium_vm_exceptions_imports_StackUnderflowError : + IsImported globals "ethereum.byzantium.vm.exceptions" "StackUnderflowError". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/cancun/__init__.v b/CoqOfPython/ethereum/cancun/__init__.v index 5ddcc4d..2ad1a6a 100644 --- a/CoqOfPython/ethereum/cancun/__init__.v +++ b/CoqOfPython/ethereum/cancun/__init__.v @@ -10,8 +10,8 @@ instruction, limits self-destruct to only work for contracts created in the same transaction, and adds an instruction to read the blob base fee. ". -Axiom ethereum_fork_criteria_imports : - AreImported globals "ethereum.fork_criteria" [ "ByTimestamp" ]. +Axiom ethereum_fork_criteria_imports_ByTimestamp : + IsImported globals "ethereum.fork_criteria" "ByTimestamp". Definition FORK_CRITERIA : Value.t := M.run ltac:(M.monadic ( M.call (| diff --git a/CoqOfPython/ethereum/cancun/blocks.v b/CoqOfPython/ethereum/cancun/blocks.v index 6e439c4..540810b 100644 --- a/CoqOfPython/ethereum/cancun/blocks.v +++ b/CoqOfPython/ethereum/cancun/blocks.v @@ -14,23 +14,41 @@ history of all state transitions that have happened since the genesis of the chain. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Tuple"; "Union" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U64"; "U256"; "Bytes"; "Bytes8"; "Bytes32"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. - -Axiom ethereum_cancun_fork_types_imports : - AreImported globals "ethereum.cancun.fork_types" [ "Address"; "Bloom"; "Root" ]. - -Axiom ethereum_cancun_transactions_imports : - AreImported globals "ethereum.cancun.transactions" [ "LegacyTransaction" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". + +Axiom ethereum_base_types_imports_U64 : + IsImported globals "ethereum.base_types" "U64". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes8 : + IsImported globals "ethereum.base_types" "Bytes8". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". + +Axiom ethereum_cancun_fork_types_imports_Address : + IsImported globals "ethereum.cancun.fork_types" "Address". +Axiom ethereum_cancun_fork_types_imports_Bloom : + IsImported globals "ethereum.cancun.fork_types" "Bloom". +Axiom ethereum_cancun_fork_types_imports_Root : + IsImported globals "ethereum.cancun.fork_types" "Root". + +Axiom ethereum_cancun_transactions_imports_LegacyTransaction : + IsImported globals "ethereum.cancun.transactions" "LegacyTransaction". Definition Withdrawal : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/cancun/bloom.v b/CoqOfPython/ethereum/cancun/bloom.v index 9603ee6..8795d1e 100644 --- a/CoqOfPython/ethereum/cancun/bloom.v +++ b/CoqOfPython/ethereum/cancun/bloom.v @@ -21,20 +21,20 @@ for efficient searching of logs by address and/or topic, by rapidly eliminating blocks and receipts from their search. ". -Axiom typing_imports : - AreImported globals "typing" [ "Tuple" ]. +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_cancun_blocks_imports : - AreImported globals "ethereum.cancun.blocks" [ "Log" ]. +Axiom ethereum_cancun_blocks_imports_Log : + IsImported globals "ethereum.cancun.blocks" "Log". -Axiom ethereum_cancun_fork_types_imports : - AreImported globals "ethereum.cancun.fork_types" [ "Bloom" ]. +Axiom ethereum_cancun_fork_types_imports_Bloom : + IsImported globals "ethereum.cancun.fork_types" "Bloom". Definition add_to_bloom : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -53,20 +53,23 @@ Definition add_to_bloom : Value.t -> Value.t -> M := bloom_entry : An entry which is to be added to bloom filter. " in - let hash := + let _ := M.assign_local (| + "hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "bloom_entry" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "idx" |), make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ], ltac:(M.monadic ( - let bit_to_set := + let _ := M.assign_local (| + "bit_to_set" , BinOp.bit_and (| M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), @@ -84,18 +87,24 @@ Definition add_to_bloom : Value.t -> Value.t -> M := make_dict [] |), Constant.int 2047 - |) in - let bit_index := + |) + |) in + let _ := M.assign_local (| + "bit_index" , BinOp.sub (| Constant.int 2047, M.get_name (| globals, "bit_to_set" |) - |) in - let byte_index := + |) + |) in + let _ := M.assign_local (| + "byte_index" , BinOp.floor_div (| M.get_name (| globals, "bit_index" |), Constant.int 8 - |) in - let bit_value := + |) + |) in + let _ := M.assign_local (| + "bit_value" , BinOp.l_shift (| Constant.int 1, BinOp.sub (| @@ -105,7 +114,8 @@ Definition add_to_bloom : Value.t -> Value.t -> M := Constant.int 8 |) |) - |) in + |) + |) in let _ := M.assign (| M.get_subscript (| M.get_name (| globals, "bloom" |), diff --git a/CoqOfPython/ethereum/cancun/fork.v b/CoqOfPython/ethereum/cancun/fork.v index 918ac94..678991e 100644 --- a/CoqOfPython/ethereum/cancun/fork.v +++ b/CoqOfPython/ethereum/cancun/fork.v @@ -17,68 +17,156 @@ Introduction Entry point for the Ethereum specification. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Optional"; "Tuple"; "Union" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Bytes0"; "Bytes32" ]. - -Axiom ethereum_crypto_elliptic_curve_imports : - AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. - -Axiom ethereum_exceptions_imports : - AreImported globals "ethereum.exceptions" [ "InvalidBlock" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U64"; "U256"; "Bytes"; "Uint" ]. - -Axiom ethereum_cancun_imports : - AreImported globals "ethereum.cancun" [ "vm" ]. - -Axiom ethereum_cancun_blocks_imports : - AreImported globals "ethereum.cancun.blocks" [ "Block"; "Header"; "Log"; "Receipt"; "Withdrawal" ]. - -Axiom ethereum_cancun_bloom_imports : - AreImported globals "ethereum.cancun.bloom" [ "logs_bloom" ]. - -Axiom ethereum_cancun_fork_types_imports : - AreImported globals "ethereum.cancun.fork_types" [ "Address"; "Bloom"; "Root"; "VersionedHash" ]. - -Axiom ethereum_cancun_state_imports : - AreImported globals "ethereum.cancun.state" [ "State"; "TransientStorage"; "account_exists_and_is_empty"; "destroy_account"; "destroy_touched_empty_accounts"; "get_account"; "increment_nonce"; "process_withdrawal"; "set_account_balance"; "state_root" ]. - -Axiom ethereum_cancun_transactions_imports : - AreImported globals "ethereum.cancun.transactions" [ "TX_ACCESS_LIST_ADDRESS_COST"; "TX_ACCESS_LIST_STORAGE_KEY_COST"; "TX_BASE_COST"; "TX_CREATE_COST"; "TX_DATA_COST_PER_NON_ZERO"; "TX_DATA_COST_PER_ZERO"; "AccessListTransaction"; "BlobTransaction"; "FeeMarketTransaction"; "LegacyTransaction"; "Transaction"; "decode_transaction"; "encode_transaction" ]. - -Axiom ethereum_cancun_trie_imports : - AreImported globals "ethereum.cancun.trie" [ "Trie"; "root"; "trie_set" ]. - -Axiom ethereum_cancun_utils_hexadecimal_imports : - AreImported globals "ethereum.cancun.utils.hexadecimal" [ "hex_to_address" ]. - -Axiom ethereum_cancun_utils_message_imports : - AreImported globals "ethereum.cancun.utils.message" [ "prepare_message" ]. - -Axiom ethereum_cancun_vm_imports : - AreImported globals "ethereum.cancun.vm" [ "Message" ]. - -Axiom ethereum_cancun_vm_gas_imports : - AreImported globals "ethereum.cancun.vm.gas" [ "calculate_blob_gas_price"; "calculate_data_fee"; "calculate_excess_blob_gas"; "calculate_total_blob_gas"; "init_code_cost" ]. - -Axiom ethereum_cancun_vm_interpreter_imports : - AreImported globals "ethereum.cancun.vm.interpreter" [ "MAX_CODE_SIZE"; "process_message_call" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". + +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". + +Axiom ethereum_crypto_elliptic_curve_imports_SECP256K1N : + IsImported globals "ethereum.crypto.elliptic_curve" "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_imports_secp256k1_recover : + IsImported globals "ethereum.crypto.elliptic_curve" "secp256k1_recover". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". + +Axiom ethereum_exceptions_imports_InvalidBlock : + IsImported globals "ethereum.exceptions" "InvalidBlock". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U64 : + IsImported globals "ethereum.base_types" "U64". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_cancun_imports_vm : + IsImported globals "ethereum.cancun" "vm". + +Axiom ethereum_cancun_blocks_imports_Block : + IsImported globals "ethereum.cancun.blocks" "Block". +Axiom ethereum_cancun_blocks_imports_Header : + IsImported globals "ethereum.cancun.blocks" "Header". +Axiom ethereum_cancun_blocks_imports_Log : + IsImported globals "ethereum.cancun.blocks" "Log". +Axiom ethereum_cancun_blocks_imports_Receipt : + IsImported globals "ethereum.cancun.blocks" "Receipt". +Axiom ethereum_cancun_blocks_imports_Withdrawal : + IsImported globals "ethereum.cancun.blocks" "Withdrawal". + +Axiom ethereum_cancun_bloom_imports_logs_bloom : + IsImported globals "ethereum.cancun.bloom" "logs_bloom". + +Axiom ethereum_cancun_fork_types_imports_Address : + IsImported globals "ethereum.cancun.fork_types" "Address". +Axiom ethereum_cancun_fork_types_imports_Bloom : + IsImported globals "ethereum.cancun.fork_types" "Bloom". +Axiom ethereum_cancun_fork_types_imports_Root : + IsImported globals "ethereum.cancun.fork_types" "Root". +Axiom ethereum_cancun_fork_types_imports_VersionedHash : + IsImported globals "ethereum.cancun.fork_types" "VersionedHash". + +Axiom ethereum_cancun_state_imports_State : + IsImported globals "ethereum.cancun.state" "State". +Axiom ethereum_cancun_state_imports_TransientStorage : + IsImported globals "ethereum.cancun.state" "TransientStorage". +Axiom ethereum_cancun_state_imports_account_exists_and_is_empty : + IsImported globals "ethereum.cancun.state" "account_exists_and_is_empty". +Axiom ethereum_cancun_state_imports_destroy_account : + IsImported globals "ethereum.cancun.state" "destroy_account". +Axiom ethereum_cancun_state_imports_destroy_touched_empty_accounts : + IsImported globals "ethereum.cancun.state" "destroy_touched_empty_accounts". +Axiom ethereum_cancun_state_imports_get_account : + IsImported globals "ethereum.cancun.state" "get_account". +Axiom ethereum_cancun_state_imports_increment_nonce : + IsImported globals "ethereum.cancun.state" "increment_nonce". +Axiom ethereum_cancun_state_imports_process_withdrawal : + IsImported globals "ethereum.cancun.state" "process_withdrawal". +Axiom ethereum_cancun_state_imports_set_account_balance : + IsImported globals "ethereum.cancun.state" "set_account_balance". +Axiom ethereum_cancun_state_imports_state_root : + IsImported globals "ethereum.cancun.state" "state_root". + +Axiom ethereum_cancun_transactions_imports_TX_ACCESS_LIST_ADDRESS_COST : + IsImported globals "ethereum.cancun.transactions" "TX_ACCESS_LIST_ADDRESS_COST". +Axiom ethereum_cancun_transactions_imports_TX_ACCESS_LIST_STORAGE_KEY_COST : + IsImported globals "ethereum.cancun.transactions" "TX_ACCESS_LIST_STORAGE_KEY_COST". +Axiom ethereum_cancun_transactions_imports_TX_BASE_COST : + IsImported globals "ethereum.cancun.transactions" "TX_BASE_COST". +Axiom ethereum_cancun_transactions_imports_TX_CREATE_COST : + IsImported globals "ethereum.cancun.transactions" "TX_CREATE_COST". +Axiom ethereum_cancun_transactions_imports_TX_DATA_COST_PER_NON_ZERO : + IsImported globals "ethereum.cancun.transactions" "TX_DATA_COST_PER_NON_ZERO". +Axiom ethereum_cancun_transactions_imports_TX_DATA_COST_PER_ZERO : + IsImported globals "ethereum.cancun.transactions" "TX_DATA_COST_PER_ZERO". +Axiom ethereum_cancun_transactions_imports_AccessListTransaction : + IsImported globals "ethereum.cancun.transactions" "AccessListTransaction". +Axiom ethereum_cancun_transactions_imports_BlobTransaction : + IsImported globals "ethereum.cancun.transactions" "BlobTransaction". +Axiom ethereum_cancun_transactions_imports_FeeMarketTransaction : + IsImported globals "ethereum.cancun.transactions" "FeeMarketTransaction". +Axiom ethereum_cancun_transactions_imports_LegacyTransaction : + IsImported globals "ethereum.cancun.transactions" "LegacyTransaction". +Axiom ethereum_cancun_transactions_imports_Transaction : + IsImported globals "ethereum.cancun.transactions" "Transaction". +Axiom ethereum_cancun_transactions_imports_decode_transaction : + IsImported globals "ethereum.cancun.transactions" "decode_transaction". +Axiom ethereum_cancun_transactions_imports_encode_transaction : + IsImported globals "ethereum.cancun.transactions" "encode_transaction". + +Axiom ethereum_cancun_trie_imports_Trie : + IsImported globals "ethereum.cancun.trie" "Trie". +Axiom ethereum_cancun_trie_imports_root : + IsImported globals "ethereum.cancun.trie" "root". +Axiom ethereum_cancun_trie_imports_trie_set : + IsImported globals "ethereum.cancun.trie" "trie_set". + +Axiom ethereum_cancun_utils_hexadecimal_imports_hex_to_address : + IsImported globals "ethereum.cancun.utils.hexadecimal" "hex_to_address". + +Axiom ethereum_cancun_utils_message_imports_prepare_message : + IsImported globals "ethereum.cancun.utils.message" "prepare_message". + +Axiom ethereum_cancun_vm_imports_Message : + IsImported globals "ethereum.cancun.vm" "Message". + +Axiom ethereum_cancun_vm_gas_imports_calculate_blob_gas_price : + IsImported globals "ethereum.cancun.vm.gas" "calculate_blob_gas_price". +Axiom ethereum_cancun_vm_gas_imports_calculate_data_fee : + IsImported globals "ethereum.cancun.vm.gas" "calculate_data_fee". +Axiom ethereum_cancun_vm_gas_imports_calculate_excess_blob_gas : + IsImported globals "ethereum.cancun.vm.gas" "calculate_excess_blob_gas". +Axiom ethereum_cancun_vm_gas_imports_calculate_total_blob_gas : + IsImported globals "ethereum.cancun.vm.gas" "calculate_total_blob_gas". +Axiom ethereum_cancun_vm_gas_imports_init_code_cost : + IsImported globals "ethereum.cancun.vm.gas" "init_code_cost". + +Axiom ethereum_cancun_vm_interpreter_imports_MAX_CODE_SIZE : + IsImported globals "ethereum.cancun.vm.interpreter" "MAX_CODE_SIZE". +Axiom ethereum_cancun_vm_interpreter_imports_process_message_call : + IsImported globals "ethereum.cancun.vm.interpreter" "process_message_call". Definition BASE_FEE_MAX_CHANGE_DENOMINATOR : Value.t := M.run ltac:(M.monadic ( Constant.int 8 @@ -208,13 +296,15 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := recent_block_hashes : `List[Hash32]` Hashes of the recent 256 blocks in order of increasing block number. " in - let recent_blocks := + let _ := M.assign_local (| + "recent_blocks" , M.slice (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |), Constant.None_, Constant.None_ - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -238,15 +328,19 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let recent_block_hashes := - make_list [] in + let _ := M.assign_local (| + "recent_block_hashes" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "block" |), M.get_name (| globals, "recent_blocks" |), ltac:(M.monadic ( - let prev_block_hash := - M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in + let _ := M.assign_local (| + "prev_block_hash" , + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), make_list [ @@ -260,7 +354,8 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let most_recent_block_hash := + let _ := M.assign_local (| + "most_recent_block_hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -276,7 +371,8 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), make_list [ @@ -313,19 +409,23 @@ Definition state_transition : Value.t -> Value.t -> M := block : Block to apply to `chain`. " in - let parent_header := + let _ := M.assign_local (| + "parent_header" , M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 1 |) - |), "header" |) in - let excess_blob_gas := + |), "header" |) + |) in + let _ := M.assign_local (| + "excess_blob_gas" , M.call (| M.get_name (| globals, "calculate_excess_blob_gas" |), make_list [ M.get_name (| globals, "parent_header" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -356,7 +456,8 @@ Definition state_transition : Value.t -> Value.t -> M := ], make_dict [] |) in - let apply_body_output := + let _ := M.assign_local (| + "apply_body_output" , M.call (| M.get_name (| globals, "apply_body" |), make_list [ @@ -381,7 +482,8 @@ Definition state_transition : Value.t -> Value.t -> M := M.get_name (| globals, "excess_blob_gas" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -519,11 +621,13 @@ Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := base_fee_per_gas : `Uint` Base fee per gas for the block. " in - let parent_gas_target := + let _ := M.assign_local (| + "parent_gas_target" , BinOp.floor_div (| M.get_name (| globals, "parent_gas_limit" |), M.get_name (| globals, "ELASTICITY_MULTIPLIER" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -548,8 +652,10 @@ Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let expected_base_fee_per_gas := - M.get_name (| globals, "parent_base_fee_per_gas" |) in + let _ := M.assign_local (| + "expected_base_fee_per_gas" , + M.get_name (| globals, "parent_base_fee_per_gas" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -562,22 +668,29 @@ Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let gas_used_delta := + let _ := M.assign_local (| + "gas_used_delta" , BinOp.sub (| M.get_name (| globals, "parent_gas_used" |), M.get_name (| globals, "parent_gas_target" |) - |) in - let parent_fee_gas_delta := + |) + |) in + let _ := M.assign_local (| + "parent_fee_gas_delta" , BinOp.mult (| M.get_name (| globals, "parent_base_fee_per_gas" |), M.get_name (| globals, "gas_used_delta" |) - |) in - let target_fee_gas_delta := + |) + |) in + let _ := M.assign_local (| + "target_fee_gas_delta" , BinOp.floor_div (| M.get_name (| globals, "parent_fee_gas_delta" |), M.get_name (| globals, "parent_gas_target" |) - |) in - let base_fee_per_gas_delta := + |) + |) in + let _ := M.assign_local (| + "base_fee_per_gas_delta" , M.call (| M.get_name (| globals, "max" |), make_list [ @@ -588,40 +701,53 @@ Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := Constant.int 1 ], make_dict [] - |) in - let expected_base_fee_per_gas := + |) + |) in + let _ := M.assign_local (| + "expected_base_fee_per_gas" , BinOp.add (| M.get_name (| globals, "parent_base_fee_per_gas" |), M.get_name (| globals, "base_fee_per_gas_delta" |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let gas_used_delta := + let _ := M.assign_local (| + "gas_used_delta" , BinOp.sub (| M.get_name (| globals, "parent_gas_target" |), M.get_name (| globals, "parent_gas_used" |) - |) in - let parent_fee_gas_delta := + |) + |) in + let _ := M.assign_local (| + "parent_fee_gas_delta" , BinOp.mult (| M.get_name (| globals, "parent_base_fee_per_gas" |), M.get_name (| globals, "gas_used_delta" |) - |) in - let target_fee_gas_delta := + |) + |) in + let _ := M.assign_local (| + "target_fee_gas_delta" , BinOp.floor_div (| M.get_name (| globals, "parent_fee_gas_delta" |), M.get_name (| globals, "parent_gas_target" |) - |) in - let base_fee_per_gas_delta := + |) + |) in + let _ := M.assign_local (| + "base_fee_per_gas_delta" , BinOp.floor_div (| M.get_name (| globals, "target_fee_gas_delta" |), M.get_name (| globals, "BASE_FEE_MAX_CHANGE_DENOMINATOR" |) - |) in - let expected_base_fee_per_gas := + |) + |) in + let _ := M.assign_local (| + "expected_base_fee_per_gas" , BinOp.sub (| M.get_name (| globals, "parent_base_fee_per_gas" |), M.get_name (| globals, "base_fee_per_gas_delta" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -668,7 +794,8 @@ Definition validate_header : Value.t -> Value.t -> M := ], make_dict [] |) in - let expected_base_fee_per_gas := + let _ := M.assign_local (| + "expected_base_fee_per_gas" , M.call (| M.get_name (| globals, "calculate_base_fee_per_gas" |), make_list [ @@ -678,7 +805,8 @@ Definition validate_header : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "parent_header" |), "base_fee_per_gas" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -765,7 +893,8 @@ Definition validate_header : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_parent_hash := + let _ := M.assign_local (| + "block_parent_hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -778,7 +907,8 @@ Definition validate_header : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -922,7 +1052,8 @@ Definition check_transaction : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let sender := + let _ := M.assign_local (| + "sender" , M.call (| M.get_name (| globals, "recover_sender" |), make_list [ @@ -930,8 +1061,10 @@ Definition check_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "tx" |) ], make_dict [] - |) in - let sender_account := + |) + |) in + let _ := M.assign_local (| + "sender_account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -939,7 +1072,8 @@ Definition check_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "sender" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -983,7 +1117,8 @@ Definition check_transaction : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let priority_fee_per_gas := + let _ := M.assign_local (| + "priority_fee_per_gas" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -994,17 +1129,22 @@ Definition check_transaction : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let effective_gas_price := + |) + |) in + let _ := M.assign_local (| + "effective_gas_price" , BinOp.add (| M.get_name (| globals, "priority_fee_per_gas" |), M.get_name (| globals, "base_fee_per_gas" |) - |) in - let max_gas_fee := + |) + |) in + let _ := M.assign_local (| + "max_gas_fee" , BinOp.mult (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1023,13 +1163,17 @@ Definition check_transaction : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let effective_gas_price := - M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) in - let max_gas_fee := + let _ := M.assign_local (| + "effective_gas_price" , + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) + |) in + let _ := M.assign_local (| + "max_gas_fee" , BinOp.mult (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := @@ -1137,7 +1281,9 @@ Definition check_transaction : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let max_gas_fee := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "max_gas_fee", BinOp.mult (| M.call (| M.get_name (| globals, "calculate_total_blob_gas" |), @@ -1148,23 +1294,18 @@ Definition check_transaction : Value.t -> Value.t -> M := |), M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_blob_gas" |) |) - BinOp.mult (| - M.call (| - M.get_name (| globals, "calculate_total_blob_gas" |), - make_list [ - M.get_name (| globals, "tx" |) - ], - make_dict [] - |), - M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_blob_gas" |) - |) in - let blob_versioned_hashes := - M.get_field (| M.get_name (| globals, "tx" |), "blob_versioned_hashes" |) in + |) in + let _ := M.assign_local (| + "blob_versioned_hashes" , + M.get_field (| M.get_name (| globals, "tx" |), "blob_versioned_hashes" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let blob_versioned_hashes := - make_tuple [ ] in + let _ := M.assign_local (| + "blob_versioned_hashes" , + make_tuple [ ] + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -1235,12 +1376,14 @@ Definition make_receipt : Value.t -> Value.t -> M := receipt : The receipt for the transaction. " in - let receipt := + let _ := M.assign_local (| + "receipt" , M.call (| M.get_name (| globals, "Receipt" |), make_list [], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1397,21 +1540,26 @@ Definition apply_body : Value.t -> Value.t -> M := apply_body_output : `ApplyBodyOutput` Output of applying the block body to the state. " in - let blob_gas_used := + let _ := M.assign_local (| + "blob_gas_used" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in - let gas_available := - M.get_name (| globals, "block_gas_limit" |) in + |) + |) in + let _ := M.assign_local (| + "gas_available" , + M.get_name (| globals, "block_gas_limit" |) + |) in (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) - let beacon_block_roots_contract_code := + let _ := M.assign_local (| + "beacon_block_roots_contract_code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1419,20 +1567,26 @@ Definition apply_body : Value.t -> Value.t -> M := M.get_name (| globals, "BEACON_ROOTS_ADDRESS" |) ], make_dict [] - |), "code" |) in - let system_tx_message := + |), "code" |) + |) in + let _ := M.assign_local (| + "system_tx_message" , M.call (| M.get_name (| globals, "Message" |), make_list [], make_dict [] - |) in - let system_tx_env := + |) + |) in + let _ := M.assign_local (| + "system_tx_env" , M.call (| M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), make_list [], make_dict [] - |) in - let system_tx_output := + |) + |) in + let _ := M.assign_local (| + "system_tx_output" , M.call (| M.get_name (| globals, "process_message_call" |), make_list [ @@ -1440,7 +1594,8 @@ Definition apply_body : Value.t -> Value.t -> M := M.get_name (| globals, "system_tx_env" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "destroy_touched_empty_accounts" |), make_list [ @@ -1509,12 +1664,14 @@ Definition apply_body : Value.t -> Value.t -> M := make_dict [] |) |) in - let env := + let _ := M.assign_local (| + "env" , M.call (| M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |); M.get_name (| globals, "error" |) ], M.call (| @@ -1526,10 +1683,13 @@ Definition apply_body : Value.t -> Value.t -> M := make_dict [] |) |) in - let gas_available := BinOp.sub + let _ := M.assign_op_local (| + BinOp.sub, + "gas_available", M.get_name (| globals, "gas_used" |) - M.get_name (| globals, "gas_used" |) in - let receipt := + |) in + let _ := M.assign_local (| + "receipt" , M.call (| M.get_name (| globals, "make_receipt" |), make_list [ @@ -1542,7 +1702,8 @@ Definition apply_body : Value.t -> Value.t -> M := M.get_name (| globals, "logs" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ @@ -1564,10 +1725,14 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_logs := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "block_logs", M.get_name (| globals, "logs" |) - M.get_name (| globals, "logs" |) in - let blob_gas_used := BinOp.add + |) in + let _ := M.assign_op_local (| + BinOp.add, + "blob_gas_used", M.call (| M.get_name (| globals, "calculate_total_blob_gas" |), make_list [ @@ -1575,13 +1740,7 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) - M.call (| - M.get_name (| globals, "calculate_total_blob_gas" |), - make_list [ - M.get_name (| globals, "tx" |) - ], - make_dict [] - |) in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -1599,19 +1758,23 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_gas_used := + let _ := M.assign_local (| + "block_gas_used" , BinOp.sub (| M.get_name (| globals, "block_gas_limit" |), M.get_name (| globals, "gas_available" |) - |) in - let block_logs_bloom := + |) + |) in + let _ := M.assign_local (| + "block_logs_bloom" , M.call (| M.get_name (| globals, "logs_bloom" |), make_list [ M.get_name (| globals, "block_logs" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "wd" |) ], @@ -1760,9 +1923,12 @@ Definition process_transaction : Value.t -> Value.t -> M := logs : `Tuple[ethereum.blocks.Log, ...]` Logs generated during execution. " in - let sender := - M.get_field (| M.get_name (| globals, "env" |), "origin" |) in - let sender_account := + let _ := M.assign_local (| + "sender" , + M.get_field (| M.get_name (| globals, "env" |), "origin" |) + |) in + let _ := M.assign_local (| + "sender_account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1770,7 +1936,8 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "sender" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1784,7 +1951,8 @@ Definition process_transaction : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let blob_gas_fee := + let _ := M.assign_local (| + "blob_gas_fee" , M.call (| M.get_name (| globals, "calculate_data_fee" |), make_list [ @@ -1792,26 +1960,32 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "tx" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let blob_gas_fee := + let _ := M.assign_local (| + "blob_gas_fee" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in - let effective_gas_fee := + let _ := M.assign_local (| + "effective_gas_fee" , BinOp.mult (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_field (| M.get_name (| globals, "env" |), "gas_price" |) - |) in - let gas := + |) + |) in + let _ := M.assign_local (| + "gas" , BinOp.sub (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.call (| @@ -1821,7 +1995,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "increment_nonce" |), make_list [ @@ -1830,14 +2005,16 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_balance_after_gas_fee := + let _ := M.assign_local (| + "sender_balance_after_gas_fee" , BinOp.sub (| BinOp.sub (| M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), M.get_name (| globals, "effective_gas_fee" |) |), M.get_name (| globals, "blob_gas_fee" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -1847,18 +2024,22 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let preaccessed_addresses := + let _ := M.assign_local (| + "preaccessed_addresses" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let preaccessed_storage_keys := + |) + |) in + let _ := M.assign_local (| + "preaccessed_storage_keys" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "preaccessed_addresses" |), "add" |), make_list [ @@ -1920,7 +2101,8 @@ Definition process_transaction : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let message := + let _ := M.assign_local (| + "message" , M.call (| M.get_name (| globals, "prepare_message" |), make_list [ @@ -1932,8 +2114,10 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in - let output := + |) + |) in + let _ := M.assign_local (| + "output" , M.call (| M.get_name (| globals, "process_message_call" |), make_list [ @@ -1941,13 +2125,17 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in - let gas_used := + |) + |) in + let _ := M.assign_local (| + "gas_used" , BinOp.sub (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_field (| M.get_name (| globals, "output" |), "gas_left" |) - |) in - let gas_refund := + |) + |) in + let _ := M.assign_local (| + "gas_refund" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -1958,21 +2146,27 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "output" |), "refund_counter" |) ], make_dict [] - |) in - let gas_refund_amount := + |) + |) in + let _ := M.assign_local (| + "gas_refund_amount" , BinOp.mult (| BinOp.add (| M.get_field (| M.get_name (| globals, "output" |), "gas_left" |), M.get_name (| globals, "gas_refund" |) |), M.get_field (| M.get_name (| globals, "env" |), "gas_price" |) - |) in - let priority_fee_per_gas := + |) + |) in + let _ := M.assign_local (| + "priority_fee_per_gas" , BinOp.sub (| M.get_field (| M.get_name (| globals, "env" |), "gas_price" |), M.get_field (| M.get_name (| globals, "env" |), "base_fee_per_gas" |) - |) in - let transaction_fee := + |) + |) in + let _ := M.assign_local (| + "transaction_fee" , BinOp.mult (| BinOp.sub (| BinOp.sub (| @@ -1982,13 +2176,17 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "gas_refund" |) |), M.get_name (| globals, "priority_fee_per_gas" |) - |) in - let total_gas_used := + |) + |) in + let _ := M.assign_local (| + "total_gas_used" , BinOp.sub (| M.get_name (| globals, "gas_used" |), M.get_name (| globals, "gas_refund" |) - |) in - let sender_balance_after_refund := + |) + |) in + let _ := M.assign_local (| + "sender_balance_after_refund" , BinOp.add (| M.get_field (| M.call (| M.get_name (| globals, "get_account" |), @@ -1999,7 +2197,8 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |), "balance" |), M.get_name (| globals, "gas_refund_amount" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -2009,7 +2208,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let coinbase_balance_after_mining_fee := + let _ := M.assign_local (| + "coinbase_balance_after_mining_fee" , BinOp.add (| M.get_field (| M.call (| M.get_name (| globals, "get_account" |), @@ -2020,7 +2220,8 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |), "balance" |), M.get_name (| globals, "transaction_fee" |) - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -2127,8 +2328,10 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := verified : `ethereum.base_types.Uint` The intrinsic cost of the transaction. " in - let data_cost := - Constant.int 0 in + let _ := M.assign_local (| + "data_cost" , + Constant.int 0 + |) in let _ := M.for_ (| M.get_name (| globals, "byte" |), @@ -2143,15 +2346,19 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let data_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "data_cost", M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let data_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "data_cost", M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -2175,7 +2382,8 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let create_cost := + let _ := M.assign_local (| + "create_cost" , BinOp.add (| M.get_name (| globals, "TX_CREATE_COST" |), M.call (| @@ -2203,16 +2411,21 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := ], make_dict [] |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let create_cost := - Constant.int 0 in + let _ := M.assign_local (| + "create_cost" , + Constant.int 0 + |) in M.pure Constant.None_ )) |) in - let access_list_cost := - Constant.int 0 in + let _ := M.assign_local (| + "access_list_cost" , + Constant.int 0 + |) in let _ := (* if *) M.if_then_else (| @@ -2231,10 +2444,14 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := make_tuple [ M.get_name (| globals, "_address" |); M.get_name (| globals, "keys" |) ], M.get_field (| M.get_name (| globals, "tx" |), "access_list" |), ltac:(M.monadic ( - let access_list_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "access_list_cost", M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) - M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) in - let access_list_cost := BinOp.add + |) in + let _ := M.assign_op_local (| + BinOp.add, + "access_list_cost", BinOp.mult (| M.call (| M.get_name (| globals, "len" |), @@ -2245,16 +2462,7 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) |) - BinOp.mult (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "keys" |) - ], - make_dict [] - |), - M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) - |) in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -2368,8 +2576,10 @@ Definition recover_sender : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let v := - M.get_field (| M.get_name (| globals, "tx" |), "v" |) in + let _ := M.assign_local (| + "v" , + M.get_field (| M.get_name (| globals, "tx" |), "v" |) + |) in let _ := (* if *) M.if_then_else (| @@ -2387,7 +2597,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let public_key := + let _ := M.assign_local (| + "public_key" , M.call (| M.get_name (| globals, "secp256k1_recover" |), make_list [ @@ -2406,7 +2617,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -2441,7 +2653,8 @@ Definition recover_sender : Value.t -> Value.t -> M := ], make_dict [] |) in - let public_key := + let _ := M.assign_local (| + "public_key" , M.call (| M.get_name (| globals, "secp256k1_recover" |), make_list [ @@ -2467,7 +2680,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -2486,7 +2700,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let public_key := + let _ := M.assign_local (| + "public_key" , M.call (| M.get_name (| globals, "secp256k1_recover" |), make_list [ @@ -2502,7 +2717,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -2519,7 +2735,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let public_key := + let _ := M.assign_local (| + "public_key" , M.call (| M.get_name (| globals, "secp256k1_recover" |), make_list [ @@ -2535,7 +2752,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -2552,7 +2770,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let public_key := + let _ := M.assign_local (| + "public_key" , M.call (| M.get_name (| globals, "secp256k1_recover" |), make_list [ @@ -2568,7 +2787,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -2871,11 +3091,13 @@ Definition check_gas_limit : Value.t -> Value.t -> M := check : `bool` True if gas limit constraints are satisfied, False otherwise. " in - let max_adjustment_delta := + let _ := M.assign_local (| + "max_adjustment_delta" , BinOp.floor_div (| M.get_name (| globals, "parent_gas_limit" |), M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) - |) in + |) + |) in let _ := (* if *) M.if_then_else (| diff --git a/CoqOfPython/ethereum/cancun/fork_types.v b/CoqOfPython/ethereum/cancun/fork_types.v index 95f1234..dd0de4b 100644 --- a/CoqOfPython/ethereum/cancun/fork_types.v +++ b/CoqOfPython/ethereum/cancun/fork_types.v @@ -17,17 +17,29 @@ Introduction Types re-used throughout the specification, which are specific to Ethereum. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes20"; "Bytes256"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes20 : + IsImported globals "ethereum.base_types" "Bytes20". +Axiom ethereum_base_types_imports_Bytes256 : + IsImported globals "ethereum.base_types" "Bytes256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) diff --git a/CoqOfPython/ethereum/cancun/state.v b/CoqOfPython/ethereum/cancun/state.v index e98a472..897c75a 100644 --- a/CoqOfPython/ethereum/cancun/state.v +++ b/CoqOfPython/ethereum/cancun/state.v @@ -22,26 +22,62 @@ There is a distinction between an account that does not exist and `EMPTY_ACCOUNT`. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass"; "field" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict"; "Iterable"; "List"; "Optional"; "Set"; "Tuple" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "modify" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_cancun_blocks_imports : - AreImported globals "ethereum.cancun.blocks" [ "Withdrawal" ]. - -Axiom ethereum_cancun_fork_types_imports : - AreImported globals "ethereum.cancun.fork_types" [ "EMPTY_ACCOUNT"; "Account"; "Address"; "Root" ]. - -Axiom ethereum_cancun_trie_imports : - AreImported globals "ethereum.cancun.trie" [ "EMPTY_TRIE_ROOT"; "Trie"; "copy_trie"; "root"; "trie_get"; "trie_set" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". +Axiom dataclasses_imports_field : + IsImported globals "dataclasses" "field". + +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". +Axiom typing_imports_Iterable : + IsImported globals "typing" "Iterable". +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_modify : + IsImported globals "ethereum.base_types" "modify". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_cancun_blocks_imports_Withdrawal : + IsImported globals "ethereum.cancun.blocks" "Withdrawal". + +Axiom ethereum_cancun_fork_types_imports_EMPTY_ACCOUNT : + IsImported globals "ethereum.cancun.fork_types" "EMPTY_ACCOUNT". +Axiom ethereum_cancun_fork_types_imports_Account : + IsImported globals "ethereum.cancun.fork_types" "Account". +Axiom ethereum_cancun_fork_types_imports_Address : + IsImported globals "ethereum.cancun.fork_types" "Address". +Axiom ethereum_cancun_fork_types_imports_Root : + IsImported globals "ethereum.cancun.fork_types" "Root". + +Axiom ethereum_cancun_trie_imports_EMPTY_TRIE_ROOT : + IsImported globals "ethereum.cancun.trie" "EMPTY_TRIE_ROOT". +Axiom ethereum_cancun_trie_imports_Trie : + IsImported globals "ethereum.cancun.trie" "Trie". +Axiom ethereum_cancun_trie_imports_copy_trie : + IsImported globals "ethereum.cancun.trie" "copy_trie". +Axiom ethereum_cancun_trie_imports_root : + IsImported globals "ethereum.cancun.trie" "root". +Axiom ethereum_cancun_trie_imports_trie_get : + IsImported globals "ethereum.cancun.trie" "trie_get". +Axiom ethereum_cancun_trie_imports_trie_set : + IsImported globals "ethereum.cancun.trie" "trie_set". Definition State : Value.t := builtins.make_klass @@ -225,7 +261,8 @@ Definition get_account : Value.t -> Value.t -> M := account : `Account` Account at address. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account_optional" |), make_list [ @@ -233,7 +270,8 @@ Definition get_account : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -279,7 +317,8 @@ Definition get_account_optional : Value.t -> Value.t -> M := account : `Account` Account at address. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "trie_get" |), make_list [ @@ -287,7 +326,8 @@ Definition get_account_optional : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "account" |) |) in @@ -438,14 +478,16 @@ Definition get_storage : Value.t -> Value.t -> M := value : `U256` Value at the key. " in - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -469,7 +511,8 @@ Definition get_storage : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "trie_get" |), make_list [ @@ -477,7 +520,8 @@ Definition get_storage : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -520,14 +564,16 @@ Definition set_storage : Value.t -> Value.t -> M := |), Constant.None_ |) |) in - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -537,12 +583,14 @@ Definition set_storage : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_name (| globals, "Trie" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), @@ -569,7 +617,7 @@ Definition set_storage : Value.t -> Value.t -> M := M.if_then_else (| Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), - {} + Constant.str "(* At expr: unsupported node type: Dict *)" |), (* then *) ltac:(M.monadic ( @@ -715,7 +763,8 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := True if if an account has non zero nonce or non empty code, False otherwise. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -723,7 +772,8 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| BoolOp.or (| Compare.not_eq (| @@ -765,7 +815,8 @@ Definition is_account_empty : Value.t -> Value.t -> M := True if if an account has zero nonce, empty code and zero balance, False otherwise. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -773,7 +824,8 @@ Definition is_account_empty : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| BoolOp.and (| Compare.eq (| @@ -824,7 +876,8 @@ Definition account_exists_and_is_empty : Value.t -> Value.t -> M := True if an account exists and has zero nonce, empty code and zero balance, False otherwise. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account_optional" |), make_list [ @@ -832,7 +885,8 @@ Definition account_exists_and_is_empty : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| BoolOp.and (| Compare.is_not (| @@ -889,7 +943,8 @@ Definition is_account_alive : Value.t -> Value.t -> M := is_alive : `bool` True if the account is alive. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account_optional" |), make_list [ @@ -897,7 +952,8 @@ Definition is_account_alive : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1196,14 +1252,16 @@ Definition get_storage_original : Value.t -> Value.t -> M := Constant.int 0 |) |) in - let original_account_trie := + let _ := M.assign_local (| + "original_account_trie" , M.call (| M.get_field (| M.get_name (| globals, "original_trie" |), "get" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1213,18 +1271,21 @@ Definition get_storage_original : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let original_value := + let _ := M.assign_local (| + "original_value" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let original_value := + let _ := M.assign_local (| + "original_value" , M.call (| M.get_name (| globals, "trie_get" |), make_list [ @@ -1232,7 +1293,8 @@ Definition get_storage_original : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.assert (| M.call (| @@ -1267,14 +1329,16 @@ Definition get_transient_storage : Value.t -> Value.t -> M := value : `U256` Value at the key. " in - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "transient_storage" |), "_tries" |), "get" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1298,7 +1362,8 @@ Definition get_transient_storage : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "trie_get" |), make_list [ @@ -1306,7 +1371,8 @@ Definition get_transient_storage : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -1337,14 +1403,16 @@ Definition set_transient_storage : Value.t -> Value.t -> M := value : `U256` Value to set at the key. " in - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "transient_storage" |), "_tries" |), "get" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1354,12 +1422,14 @@ Definition set_transient_storage : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_name (| globals, "Trie" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "transient_storage" |), "_tries" |), @@ -1386,7 +1456,7 @@ Definition set_transient_storage : Value.t -> Value.t -> M := M.if_then_else (| Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), - {} + Constant.str "(* At expr: unsupported node type: Dict *)" |), (* then *) ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/cancun/transactions.v b/CoqOfPython/ethereum/cancun/transactions.v index e564d06..e5e186a 100644 --- a/CoqOfPython/ethereum/cancun/transactions.v +++ b/CoqOfPython/ethereum/cancun/transactions.v @@ -9,23 +9,39 @@ submitted to be executed. If Ethereum is viewed as a state machine, transactions are the events that move between states. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". -Axiom typing_imports : - AreImported globals "typing" [ "Tuple"; "Union" ]. +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U64"; "U256"; "Bytes"; "Bytes0"; "Bytes32"; "Uint"; "slotted_freezable" ]. +Axiom ethereum_base_types_imports_U64 : + IsImported globals "ethereum.base_types" "U64". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". -Axiom ethereum_exceptions_imports : - AreImported globals "ethereum.exceptions" [ "InvalidBlock" ]. +Axiom ethereum_exceptions_imports_InvalidBlock : + IsImported globals "ethereum.exceptions" "InvalidBlock". -Axiom ethereum_cancun_fork_types_imports : - AreImported globals "ethereum.cancun.fork_types" [ "Address"; "VersionedHash" ]. +Axiom ethereum_cancun_fork_types_imports_Address : + IsImported globals "ethereum.cancun.fork_types" "Address". +Axiom ethereum_cancun_fork_types_imports_VersionedHash : + IsImported globals "ethereum.cancun.fork_types" "VersionedHash". Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( Constant.int 21000 diff --git a/CoqOfPython/ethereum/cancun/trie.v b/CoqOfPython/ethereum/cancun/trie.v index d850a1f..ef7de86 100644 --- a/CoqOfPython/ethereum/cancun/trie.v +++ b/CoqOfPython/ethereum/cancun/trie.v @@ -20,38 +20,74 @@ The state trie is the structure responsible for storing (* At top_level_stmt: unsupported node type: Import *) -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass"; "field" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict"; "Generic"; "List"; "Mapping"; "MutableMapping"; "Optional"; "Sequence"; "TypeVar"; "Union"; "cast" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. - -Axiom ethereum_shanghai_imports : - AreImported globals "ethereum.shanghai" [ "trie" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_utils_hexadecimal_imports : - AreImported globals "ethereum.utils.hexadecimal" [ "hex_to_bytes" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_cancun_blocks_imports : - AreImported globals "ethereum.cancun.blocks" [ "Receipt"; "Withdrawal" ]. - -Axiom ethereum_cancun_fork_types_imports : - AreImported globals "ethereum.cancun.fork_types" [ "Account"; "Address"; "Root"; "encode_account" ]. - -Axiom ethereum_cancun_transactions_imports : - AreImported globals "ethereum.cancun.transactions" [ "LegacyTransaction" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". +Axiom dataclasses_imports_field : + IsImported globals "dataclasses" "field". + +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". +Axiom typing_imports_Generic : + IsImported globals "typing" "Generic". +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Mapping : + IsImported globals "typing" "Mapping". +Axiom typing_imports_MutableMapping : + IsImported globals "typing" "MutableMapping". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Sequence : + IsImported globals "typing" "Sequence". +Axiom typing_imports_TypeVar : + IsImported globals "typing" "TypeVar". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". +Axiom typing_imports_cast : + IsImported globals "typing" "cast". + +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". + +Axiom ethereum_shanghai_imports_trie : + IsImported globals "ethereum.shanghai" "trie". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_utils_hexadecimal_imports_hex_to_bytes : + IsImported globals "ethereum.utils.hexadecimal" "hex_to_bytes". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_cancun_blocks_imports_Receipt : + IsImported globals "ethereum.cancun.blocks" "Receipt". +Axiom ethereum_cancun_blocks_imports_Withdrawal : + IsImported globals "ethereum.cancun.blocks" "Withdrawal". + +Axiom ethereum_cancun_fork_types_imports_Account : + IsImported globals "ethereum.cancun.fork_types" "Account". +Axiom ethereum_cancun_fork_types_imports_Address : + IsImported globals "ethereum.cancun.fork_types" "Address". +Axiom ethereum_cancun_fork_types_imports_Root : + IsImported globals "ethereum.cancun.fork_types" "Root". +Axiom ethereum_cancun_fork_types_imports_encode_account : + IsImported globals "ethereum.cancun.fork_types" "encode_account". + +Axiom ethereum_cancun_transactions_imports_LegacyTransaction : + IsImported globals "ethereum.cancun.transactions" "LegacyTransaction". Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -174,7 +210,7 @@ Definition encode_internal_node : Value.t -> Value.t -> M := when serialized. This function also accepts `None`, representing the absence of a node, - which is encoded to `b""""""`. + which is encoded to `b""""`. Parameters ---------- @@ -196,8 +232,10 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := - Constant.bytes "" in + let _ := M.assign_local (| + "unencoded" , + Constant.bytes "" + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -214,7 +252,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := + let _ := M.assign_local (| + "unencoded" , make_tuple [ M.call (| M.get_name (| globals, "nibble_list_to_compact" |), make_list [ @@ -222,7 +261,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := Constant.bool true ], make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in + |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -239,7 +279,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := + let _ := M.assign_local (| + "unencoded" , make_tuple [ M.call (| M.get_name (| globals, "nibble_list_to_compact" |), make_list [ @@ -247,7 +288,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := Constant.bool false ], make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in + |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -264,13 +306,15 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := + let _ := M.assign_local (| + "unencoded" , BinOp.add (| M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), make_list [ M.get_field (| M.get_name (| globals, "node" |), "value" |) ] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -289,14 +333,16 @@ Definition encode_internal_node : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - let encoded := + let _ := M.assign_local (| + "encoded" , M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), make_list [ M.get_name (| globals, "unencoded" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -688,12 +734,14 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := compressed : `bytearray` Compact byte array. " in - let compact := + let _ := M.assign_local (| + "compact" , M.call (| M.get_name (| globals, "bytearray" |), make_list [], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -873,7 +921,8 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := nibble_list : `Bytes` The `Bytes` in nibble-list format. " in - let nibble_list := + let _ := M.assign_local (| + "nibble_list" , M.call (| M.get_name (| globals, "bytearray" |), make_list [ @@ -889,7 +938,8 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ], @@ -997,15 +1047,18 @@ Definition _prepare_trie : Value.t -> Value.t -> M := M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "Address" |), make_list [ M.get_name (| globals, "preimage" |) ], make_dict [] - |) in - let encoded_value := + |) + |) in + let _ := M.assign_local (| + "encoded_value" , M.call (| M.get_name (| globals, "encode_node" |), make_list [ @@ -1019,18 +1072,21 @@ Definition _prepare_trie : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let encoded_value := + let _ := M.assign_local (| + "encoded_value" , M.call (| M.get_name (| globals, "encode_node" |), make_list [ M.get_name (| globals, "value" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -1051,19 +1107,23 @@ Definition _prepare_trie : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "trie" |), "secured" |), (* then *) ltac:(M.monadic ( - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "preimage" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let key := - M.get_name (| globals, "preimage" |) in + let _ := M.assign_local (| + "key" , + M.get_name (| globals, "preimage" |) + |) in M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -1110,7 +1170,8 @@ Definition root : Value.t -> Value.t -> M := root : `.fork_types.Root` MPT root of the underlying key-value pairs. " in - let obj := + let _ := M.assign_local (| + "obj" , M.call (| M.get_name (| globals, "_prepare_trie" |), make_list [ @@ -1118,8 +1179,10 @@ Definition root : Value.t -> Value.t -> M := M.get_name (| globals, "get_storage_root" |) ], make_dict [] - |) in - let root_node := + |) + |) in + let _ := M.assign_local (| + "root_node" , M.call (| M.get_name (| globals, "encode_internal_node" |), make_list [ @@ -1139,7 +1202,8 @@ Definition root : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1244,7 +1308,8 @@ Definition patricialize : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let arbitrary_key := + let _ := M.assign_local (| + "arbitrary_key" , M.call (| M.get_name (| globals, "next" |), make_list [ @@ -1257,7 +1322,8 @@ Definition patricialize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1273,7 +1339,8 @@ Definition patricialize : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let leaf := + let _ := M.assign_local (| + "leaf" , M.call (| M.get_name (| globals, "LeafNode" |), make_list [ @@ -1289,7 +1356,8 @@ Definition patricialize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "leaf" |) |) in @@ -1298,27 +1366,32 @@ Definition patricialize : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let substring := + let _ := M.assign_local (| + "substring" , M.slice (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |), Constant.None_, Constant.None_ - |) in - let prefix_length := + |) + |) in + let _ := M.assign_local (| + "prefix_length" , M.call (| M.get_name (| globals, "len" |), make_list [ M.get_name (| globals, "substring" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "key" |), M.get_name (| globals, "obj" |), ltac:(M.monadic ( - let prefix_length := + let _ := M.assign_local (| + "prefix_length" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -1338,7 +1411,8 @@ Definition patricialize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1369,7 +1443,8 @@ Definition patricialize : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let prefix := + let _ := M.assign_local (| + "prefix" , M.slice (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |), @@ -1378,7 +1453,8 @@ Definition patricialize : Value.t -> Value.t -> M := M.get_name (| globals, "prefix_length" |) |), Constant.None_ - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ExtensionNode" |), @@ -1425,7 +1501,7 @@ Definition patricialize : Value.t -> Value.t -> M := let _ := M.call (| M.get_field (| M.get_name (| globals, "branches" |), "append" |), make_list [ - {} + Constant.str "(* At expr: unsupported node type: Dict *)" ], make_dict [] |) in @@ -1435,8 +1511,10 @@ Definition patricialize : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let value := - Constant.bytes "" in + let _ := M.assign_local (| + "value" , + Constant.bytes "" + |) in let _ := M.for_ (| M.get_name (| globals, "key" |), @@ -1479,11 +1557,13 @@ Definition patricialize : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let value := + let _ := M.assign_local (| + "value" , M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/cancun/utils/address.v b/CoqOfPython/ethereum/cancun/utils/address.v index cbc30b0..c9e2edc 100644 --- a/CoqOfPython/ethereum/cancun/utils/address.v +++ b/CoqOfPython/ethereum/cancun/utils/address.v @@ -18,23 +18,27 @@ Address specific functions used in this cancun version of specification. ". -Axiom typing_imports : - AreImported globals "typing" [ "Union" ]. +Axiom typing_imports_Union : + IsImported globals "typing" "Union". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes32"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_left_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "left_pad_zero_bytes". -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". -Axiom ethereum_cancun_fork_types_imports : - AreImported globals "ethereum.cancun.fork_types" [ "Address" ]. +Axiom ethereum_cancun_fork_types_imports_Address : + IsImported globals "ethereum.cancun.fork_types" "Address". Definition to_address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -91,7 +95,8 @@ Definition compute_contract_address : Value.t -> Value.t -> M := address: `Address` The computed address of the new account. " in - let computed_address := + let _ := M.assign_local (| + "computed_address" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -107,15 +112,19 @@ Definition compute_contract_address : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let canonical_address := + |) + |) in + let _ := M.assign_local (| + "canonical_address" , M.slice (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |), Constant.None_, Constant.None_ - |) in - let padded_address := + |) + |) in + let _ := M.assign_local (| + "padded_address" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -123,7 +132,8 @@ Definition compute_contract_address : Value.t -> Value.t -> M := Constant.int 20 ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Address" |), @@ -156,7 +166,8 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := address: `ethereum.cancun.fork_types.Address` The computed address of the new account. " in - let preimage := + let _ := M.assign_local (| + "preimage" , BinOp.add (| BinOp.add (| BinOp.add (| @@ -172,23 +183,29 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in - let computed_address := + |) + |) in + let _ := M.assign_local (| + "computed_address" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "preimage" |) ], make_dict [] - |) in - let canonical_address := + |) + |) in + let _ := M.assign_local (| + "canonical_address" , M.slice (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |), Constant.None_, Constant.None_ - |) in - let padded_address := + |) + |) in + let _ := M.assign_local (| + "padded_address" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -196,7 +213,8 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := Constant.int 20 ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Address" |), diff --git a/CoqOfPython/ethereum/cancun/utils/hexadecimal.v b/CoqOfPython/ethereum/cancun/utils/hexadecimal.v index 2739846..8834108 100644 --- a/CoqOfPython/ethereum/cancun/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/cancun/utils/hexadecimal.v @@ -18,11 +18,15 @@ Hexadecimal utility functions used in this specification, specific to Cancun types. ". -Axiom ethereum_utils_hexadecimal_imports : - AreImported globals "ethereum.utils.hexadecimal" [ "remove_hex_prefix" ]. - -Axiom ethereum_cancun_fork_types_imports : - AreImported globals "ethereum.cancun.fork_types" [ "Address"; "Bloom"; "Root" ]. +Axiom ethereum_utils_hexadecimal_imports_remove_hex_prefix : + IsImported globals "ethereum.utils.hexadecimal" "remove_hex_prefix". + +Axiom ethereum_cancun_fork_types_imports_Address : + IsImported globals "ethereum.cancun.fork_types" "Address". +Axiom ethereum_cancun_fork_types_imports_Bloom : + IsImported globals "ethereum.cancun.fork_types" "Bloom". +Axiom ethereum_cancun_fork_types_imports_Root : + IsImported globals "ethereum.cancun.fork_types" "Root". Definition hex_to_root : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/cancun/utils/message.v b/CoqOfPython/ethereum/cancun/utils/message.v index ec2cf45..e62d563 100644 --- a/CoqOfPython/ethereum/cancun/utils/message.v +++ b/CoqOfPython/ethereum/cancun/utils/message.v @@ -18,26 +18,42 @@ Message specific functions used in this cancun version of specification. ". -Axiom typing_imports : - AreImported globals "typing" [ "FrozenSet"; "Optional"; "Tuple"; "Union" ]. +Axiom typing_imports_FrozenSet : + IsImported globals "typing" "FrozenSet". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Bytes32"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_cancun_fork_types_imports : - AreImported globals "ethereum.cancun.fork_types" [ "Address" ]. +Axiom ethereum_cancun_fork_types_imports_Address : + IsImported globals "ethereum.cancun.fork_types" "Address". -Axiom ethereum_cancun_state_imports : - AreImported globals "ethereum.cancun.state" [ "get_account" ]. +Axiom ethereum_cancun_state_imports_get_account : + IsImported globals "ethereum.cancun.state" "get_account". -Axiom ethereum_cancun_vm_imports : - AreImported globals "ethereum.cancun.vm" [ "Environment"; "Message" ]. +Axiom ethereum_cancun_vm_imports_Environment : + IsImported globals "ethereum.cancun.vm" "Environment". +Axiom ethereum_cancun_vm_imports_Message : + IsImported globals "ethereum.cancun.vm" "Message". -Axiom ethereum_cancun_vm_precompiled_contracts_mapping_imports : - AreImported globals "ethereum.cancun.vm.precompiled_contracts.mapping" [ "PRE_COMPILED_CONTRACTS" ]. +Axiom ethereum_cancun_vm_precompiled_contracts_mapping_imports_PRE_COMPILED_CONTRACTS : + IsImported globals "ethereum.cancun.vm.precompiled_contracts.mapping" "PRE_COMPILED_CONTRACTS". -Axiom ethereum_cancun_utils_address_imports : - AreImported globals "ethereum.cancun.utils.address" [ "compute_contract_address" ]. +Axiom ethereum_cancun_utils_address_imports_compute_contract_address : + IsImported globals "ethereum.cancun.utils.address" "compute_contract_address". Definition prepare_message : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -92,7 +108,8 @@ Definition prepare_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let current_target := + let _ := M.assign_local (| + "current_target" , M.call (| M.get_name (| globals, "compute_contract_address" |), make_list [ @@ -116,17 +133,22 @@ Definition prepare_message : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let msg_data := + |) + |) in + let _ := M.assign_local (| + "msg_data" , M.call (| M.get_name (| globals, "Bytes" |), make_list [ Constant.bytes "" ], make_dict [] - |) in - let code := - M.get_name (| globals, "data" |) in + |) + |) in + let _ := M.assign_local (| + "code" , + M.get_name (| globals, "data" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -143,11 +165,16 @@ Definition prepare_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let current_target := - M.get_name (| globals, "target" |) in - let msg_data := - M.get_name (| globals, "data" |) in - let code := + let _ := M.assign_local (| + "current_target" , + M.get_name (| globals, "target" |) + |) in + let _ := M.assign_local (| + "msg_data" , + M.get_name (| globals, "data" |) + |) in + let _ := M.assign_local (| + "code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -155,7 +182,8 @@ Definition prepare_message : Value.t -> Value.t -> M := M.get_name (| globals, "target" |) ], make_dict [] - |), "code" |) in + |), "code" |) + |) in let _ := (* if *) M.if_then_else (| @@ -165,8 +193,10 @@ Definition prepare_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let code_address := - M.get_name (| globals, "target" |) in + let _ := M.assign_local (| + "code_address" , + M.get_name (| globals, "target" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -186,12 +216,14 @@ Definition prepare_message : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - let accessed_addresses := + let _ := M.assign_local (| + "accessed_addresses" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "accessed_addresses" |), "add" |), make_list [ diff --git a/CoqOfPython/ethereum/cancun/vm/__init__.v b/CoqOfPython/ethereum/cancun/vm/__init__.v index a41db5c..5efb61d 100644 --- a/CoqOfPython/ethereum/cancun/vm/__init__.v +++ b/CoqOfPython/ethereum/cancun/vm/__init__.v @@ -18,29 +18,53 @@ The abstract computer which runs the code stored in an `.fork_types.Account`. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple"; "Union" ]. +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U64"; "U256"; "Bytes"; "Bytes0"; "Bytes32"; "Uint" ]. +Axiom ethereum_base_types_imports_U64 : + IsImported globals "ethereum.base_types" "U64". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". -Axiom ethereum_cancun_blocks_imports : - AreImported globals "ethereum.cancun.blocks" [ "Log" ]. +Axiom ethereum_cancun_blocks_imports_Log : + IsImported globals "ethereum.cancun.blocks" "Log". -Axiom ethereum_cancun_fork_types_imports : - AreImported globals "ethereum.cancun.fork_types" [ "Address"; "VersionedHash" ]. +Axiom ethereum_cancun_fork_types_imports_Address : + IsImported globals "ethereum.cancun.fork_types" "Address". +Axiom ethereum_cancun_fork_types_imports_VersionedHash : + IsImported globals "ethereum.cancun.fork_types" "VersionedHash". -Axiom ethereum_cancun_state_imports : - AreImported globals "ethereum.cancun.state" [ "State"; "TransientStorage"; "account_exists_and_is_empty" ]. +Axiom ethereum_cancun_state_imports_State : + IsImported globals "ethereum.cancun.state" "State". +Axiom ethereum_cancun_state_imports_TransientStorage : + IsImported globals "ethereum.cancun.state" "TransientStorage". +Axiom ethereum_cancun_state_imports_account_exists_and_is_empty : + IsImported globals "ethereum.cancun.state" "account_exists_and_is_empty". -Axiom ethereum_cancun_vm_precompiled_contracts_imports : - AreImported globals "ethereum.cancun.vm.precompiled_contracts" [ "RIPEMD160_ADDRESS" ]. +Axiom ethereum_cancun_vm_precompiled_contracts_imports_RIPEMD160_ADDRESS : + IsImported globals "ethereum.cancun.vm.precompiled_contracts" "RIPEMD160_ADDRESS". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] diff --git a/CoqOfPython/ethereum/cancun/vm/exceptions.v b/CoqOfPython/ethereum/cancun/vm/exceptions.v index cd1f083..42aba40 100644 --- a/CoqOfPython/ethereum/cancun/vm/exceptions.v +++ b/CoqOfPython/ethereum/cancun/vm/exceptions.v @@ -17,8 +17,8 @@ Introduction Exceptions which cause the EVM to halt exceptionally. ". -Axiom ethereum_exceptions_imports : - AreImported globals "ethereum.exceptions" [ "EthereumException" ]. +Axiom ethereum_exceptions_imports_EthereumException : + IsImported globals "ethereum.exceptions" "EthereumException". Definition ExceptionalHalt : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/cancun/vm/gas.v b/CoqOfPython/ethereum/cancun/vm/gas.v index 1cf1c94..8e04e69 100644 --- a/CoqOfPython/ethereum/cancun/vm/gas.v +++ b/CoqOfPython/ethereum/cancun/vm/gas.v @@ -17,32 +17,44 @@ Introduction EVM gas constants and calculators. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Tuple" ]. +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U64"; "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U64 : + IsImported globals "ethereum.base_types" "U64". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_trace_imports : - AreImported globals "ethereum.trace" [ "GasAndRefund"; "evm_trace" ]. +Axiom ethereum_trace_imports_GasAndRefund : + IsImported globals "ethereum.trace" "GasAndRefund". +Axiom ethereum_trace_imports_evm_trace : + IsImported globals "ethereum.trace" "evm_trace". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32"; "taylor_exponential" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". +Axiom ethereum_utils_numeric_imports_taylor_exponential : + IsImported globals "ethereum.utils.numeric" "taylor_exponential". -Axiom ethereum_cancun_blocks_imports : - AreImported globals "ethereum.cancun.blocks" [ "Header" ]. +Axiom ethereum_cancun_blocks_imports_Header : + IsImported globals "ethereum.cancun.blocks" "Header". -Axiom ethereum_cancun_transactions_imports : - AreImported globals "ethereum.cancun.transactions" [ "BlobTransaction"; "Transaction" ]. +Axiom ethereum_cancun_transactions_imports_BlobTransaction : + IsImported globals "ethereum.cancun.transactions" "BlobTransaction". +Axiom ethereum_cancun_transactions_imports_Transaction : + IsImported globals "ethereum.cancun.transactions" "Transaction". -Axiom ethereum_cancun_vm_imports : - AreImported globals "ethereum.cancun.vm" [ "Evm" ]. +Axiom ethereum_cancun_vm_imports_Evm : + IsImported globals "ethereum.cancun.vm" "Evm". -Axiom ethereum_cancun_vm_exceptions_imports : - AreImported globals "ethereum.cancun.vm.exceptions" [ "OutOfGasError" ]. +Axiom ethereum_cancun_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.cancun.vm.exceptions" "OutOfGasError". Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -605,7 +617,8 @@ Definition calculate_memory_gas_cost : Value.t -> Value.t -> M := total_gas_cost : `ethereum.base_types.Uint` The gas cost for storing data in memory. " in - let size_in_words := + let _ := M.assign_local (| + "size_in_words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -615,25 +628,32 @@ Definition calculate_memory_gas_cost : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let linear_cost := + |) + |) in + let _ := M.assign_local (| + "linear_cost" , BinOp.mult (| M.get_name (| globals, "size_in_words" |), M.get_name (| globals, "GAS_MEMORY" |) - |) in - let quadratic_cost := + |) + |) in + let _ := M.assign_local (| + "quadratic_cost" , BinOp.floor_div (| BinOp.pow (| M.get_name (| globals, "size_in_words" |), Constant.int 2 |), Constant.int 512 - |) in - let total_gas_cost := + |) + |) in + let _ := M.assign_local (| + "total_gas_cost" , BinOp.add (| M.get_name (| globals, "linear_cost" |), M.get_name (| globals, "quadratic_cost" |) - |) in + |) + |) in (* At stmt: unsupported node type: Try *) M.pure Constant.None_)). @@ -655,23 +675,28 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := ------- extend_memory: `ExtendMemory` " in - let size_to_extend := + let _ := M.assign_local (| + "size_to_extend" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in - let to_be_paid := + |) + |) in + let _ := M.assign_local (| + "to_be_paid" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in - let current_size := + |) + |) in + let _ := M.assign_local (| + "current_size" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -684,7 +709,8 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ], @@ -705,15 +731,18 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let before_size := + let _ := M.assign_local (| + "before_size" , M.call (| M.get_name (| globals, "ceil32" |), make_list [ M.get_name (| globals, "current_size" |) ], make_dict [] - |) in - let after_size := + |) + |) in + let _ := M.assign_local (| + "after_size" , M.call (| M.get_name (| globals, "ceil32" |), make_list [ @@ -735,7 +764,8 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -751,42 +781,46 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let size_to_extend := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "size_to_extend", BinOp.sub (| M.get_name (| globals, "after_size" |), M.get_name (| globals, "before_size" |) |) - BinOp.sub (| - M.get_name (| globals, "after_size" |), - M.get_name (| globals, "before_size" |) - |) in - let already_paid := + |) in + let _ := M.assign_local (| + "already_paid" , M.call (| M.get_name (| globals, "calculate_memory_gas_cost" |), make_list [ M.get_name (| globals, "before_size" |) ], make_dict [] - |) in - let total_cost := + |) + |) in + let _ := M.assign_local (| + "total_cost" , M.call (| M.get_name (| globals, "calculate_memory_gas_cost" |), make_list [ M.get_name (| globals, "after_size" |) ], make_dict [] - |) in - let to_be_paid := BinOp.add + |) + |) in + let _ := M.assign_op_local (| + BinOp.add, + "to_be_paid", BinOp.sub (| M.get_name (| globals, "total_cost" |), M.get_name (| globals, "already_paid" |) |) - BinOp.sub (| - M.get_name (| globals, "total_cost" |), - M.get_name (| globals, "already_paid" |) - |) in - let current_size := - M.get_name (| globals, "after_size" |) in + |) in + let _ := M.assign_local (| + "current_size" , + M.get_name (| globals, "after_size" |) + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -833,7 +867,8 @@ Definition calculate_message_call_gas : Value.t -> Value.t -> M := ------- message_call_gas: `MessageCallGas` " in - let call_stipend := + let _ := M.assign_local (| + "call_stipend" , (* if *) M.if_then_else (| Compare.eq (| @@ -852,7 +887,8 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "call_stipend" |) - )) |) in + )) |) + |) in let _ := (* if *) M.if_then_else (| @@ -886,7 +922,8 @@ M.get_name (| globals, "call_stipend" |) )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -906,7 +943,8 @@ M.get_name (| globals, "call_stipend" |) |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "MessageCallGas" |), @@ -1004,11 +1042,13 @@ Definition calculate_excess_blob_gas : Value.t -> Value.t -> M := excess_blob_gas: `ethereum.base_types.U64` The excess blob gas for the current block. " in - let parent_blob_gas := + let _ := M.assign_local (| + "parent_blob_gas" , BinOp.add (| M.get_field (| M.get_name (| globals, "parent_header" |), "excess_blob_gas" |), M.get_field (| M.get_name (| globals, "parent_header" |), "blob_gas_used" |) - |) in + |) + |) in let _ := (* if *) M.if_then_else (| diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/__init__.v b/CoqOfPython/ethereum/cancun/vm/instructions/__init__.v index 770a543..0523587 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/__init__.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/__init__.v @@ -20,44 +20,46 @@ implementations. (* At top_level_stmt: unsupported node type: Import *) -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict" ]. +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". -Axiom ethereum_cancun_vm_instructions_imports : - AreImported globals "ethereum.cancun.vm.instructions" [ "arithmetic" ]. +Axiom ethereum_cancun_vm_instructions_imports_arithmetic : + IsImported globals "ethereum.cancun.vm.instructions" "arithmetic". -Axiom ethereum_cancun_vm_instructions_imports : - AreImported globals "ethereum.cancun.vm.instructions" [ "bitwise" ]. +Axiom ethereum_cancun_vm_instructions_imports_bitwise : + IsImported globals "ethereum.cancun.vm.instructions" "bitwise". -Axiom ethereum_cancun_vm_instructions_imports : - AreImported globals "ethereum.cancun.vm.instructions" [ "block" ]. +Axiom ethereum_cancun_vm_instructions_imports_block : + IsImported globals "ethereum.cancun.vm.instructions" "block". -Axiom ethereum_cancun_vm_instructions_imports : - AreImported globals "ethereum.cancun.vm.instructions" [ "comparison" ]. +Axiom ethereum_cancun_vm_instructions_imports_comparison : + IsImported globals "ethereum.cancun.vm.instructions" "comparison". -Axiom ethereum_cancun_vm_instructions_imports : - AreImported globals "ethereum.cancun.vm.instructions" [ "control_flow" ]. +Axiom ethereum_cancun_vm_instructions_imports_control_flow : + IsImported globals "ethereum.cancun.vm.instructions" "control_flow". -Axiom ethereum_cancun_vm_instructions_imports : - AreImported globals "ethereum.cancun.vm.instructions" [ "environment" ]. +Axiom ethereum_cancun_vm_instructions_imports_environment : + IsImported globals "ethereum.cancun.vm.instructions" "environment". -Axiom ethereum_cancun_vm_instructions_imports : - AreImported globals "ethereum.cancun.vm.instructions" [ "keccak" ]. +Axiom ethereum_cancun_vm_instructions_imports_keccak : + IsImported globals "ethereum.cancun.vm.instructions" "keccak". -Axiom ethereum_cancun_vm_instructions_imports : - AreImported globals "ethereum.cancun.vm.instructions" [ "log" ]. +Axiom ethereum_cancun_vm_instructions_imports_log : + IsImported globals "ethereum.cancun.vm.instructions" "log". -Axiom ethereum_cancun_vm_instructions_imports : - AreImported globals "ethereum.cancun.vm.instructions" [ "memory" ]. +Axiom ethereum_cancun_vm_instructions_imports_memory : + IsImported globals "ethereum.cancun.vm.instructions" "memory". -Axiom ethereum_cancun_vm_instructions_imports : - AreImported globals "ethereum.cancun.vm.instructions" [ "stack" ]. +Axiom ethereum_cancun_vm_instructions_imports_stack : + IsImported globals "ethereum.cancun.vm.instructions" "stack". -Axiom ethereum_cancun_vm_instructions_imports : - AreImported globals "ethereum.cancun.vm.instructions" [ "storage" ]. +Axiom ethereum_cancun_vm_instructions_imports_storage : + IsImported globals "ethereum.cancun.vm.instructions" "storage". -Axiom ethereum_cancun_vm_instructions_imports : - AreImported globals "ethereum.cancun.vm.instructions" [ "system" ]. +Axiom ethereum_cancun_vm_instructions_imports_system : + IsImported globals "ethereum.cancun.vm.instructions" "system". Definition Ops : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/cancun/vm/instructions/arithmetic.v index 5f279b7..dc9d022 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/arithmetic.v @@ -17,20 +17,38 @@ Introduction Implementations of the EVM Arithmetic instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U255_CEIL_VALUE"; "U256"; "U256_CEIL_VALUE"; "Uint" ]. +Axiom ethereum_base_types_imports_U255_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U255_CEIL_VALUE". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_U256_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U256_CEIL_VALUE". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "get_sign" ]. +Axiom ethereum_utils_numeric_imports_get_sign : + IsImported globals "ethereum.utils.numeric" "get_sign". -Axiom ethereum_cancun_vm_imports : - AreImported globals "ethereum.cancun.vm" [ "Evm" ]. +Axiom ethereum_cancun_vm_imports_Evm : + IsImported globals "ethereum.cancun.vm" "Evm". -Axiom ethereum_cancun_vm_gas_imports : - AreImported globals "ethereum.cancun.vm.gas" [ "GAS_EXPONENTIATION"; "GAS_EXPONENTIATION_PER_BYTE"; "GAS_LOW"; "GAS_MID"; "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_cancun_vm_gas_imports_GAS_EXPONENTIATION : + IsImported globals "ethereum.cancun.vm.gas" "GAS_EXPONENTIATION". +Axiom ethereum_cancun_vm_gas_imports_GAS_EXPONENTIATION_PER_BYTE : + IsImported globals "ethereum.cancun.vm.gas" "GAS_EXPONENTIATION_PER_BYTE". +Axiom ethereum_cancun_vm_gas_imports_GAS_LOW : + IsImported globals "ethereum.cancun.vm.gas" "GAS_LOW". +Axiom ethereum_cancun_vm_gas_imports_GAS_MID : + IsImported globals "ethereum.cancun.vm.gas" "GAS_MID". +Axiom ethereum_cancun_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.cancun.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_cancun_vm_gas_imports_charge_gas : + IsImported globals "ethereum.cancun.vm.gas" "charge_gas". -Axiom ethereum_cancun_vm_stack_imports : - AreImported globals "ethereum.cancun.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_cancun_vm_stack_imports_pop : + IsImported globals "ethereum.cancun.vm.stack" "pop". +Axiom ethereum_cancun_vm_stack_imports_push : + IsImported globals "ethereum.cancun.vm.stack" "push". Definition add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,22 +63,26 @@ Definition add : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -69,14 +91,16 @@ Definition add : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "x" |), "wrapping_add" |), make_list [ M.get_name (| globals, "y" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -105,22 +129,26 @@ Definition sub : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -129,14 +157,16 @@ Definition sub : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "x" |), "wrapping_sub" |), make_list [ M.get_name (| globals, "y" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -165,22 +195,26 @@ Definition mul : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -189,14 +223,16 @@ Definition mul : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "x" |), "wrapping_mul" |), make_list [ M.get_name (| globals, "y" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -225,22 +261,26 @@ Definition div : Value.t -> Value.t -> M := The current EVM frame. " in - let dividend := + let _ := M.assign_local (| + "dividend" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let divisor := + |) + |) in + let _ := M.assign_local (| + "divisor" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -258,22 +298,26 @@ Definition div : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let quotient := + let _ := M.assign_local (| + "quotient" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let quotient := + let _ := M.assign_local (| + "quotient" , BinOp.floor_div (| M.get_name (| globals, "dividend" |), M.get_name (| globals, "divisor" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -304,7 +348,8 @@ Definition sdiv : Value.t -> Value.t -> M := The current EVM frame. " in - let dividend := + let _ := M.assign_local (| + "dividend" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -315,8 +360,10 @@ Definition sdiv : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let divisor := + |) + |) in + let _ := M.assign_local (| + "divisor" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -327,7 +374,8 @@ Definition sdiv : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -345,8 +393,10 @@ Definition sdiv : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let quotient := - Constant.int 0 in + let _ := M.assign_local (| + "quotient" , + Constant.int 0 + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -367,12 +417,15 @@ Definition sdiv : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let quotient := - UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in + let _ := M.assign_local (| + "quotient" , + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let sign := + let _ := M.assign_local (| + "sign" , M.call (| M.get_name (| globals, "get_sign" |), make_list [ @@ -382,8 +435,10 @@ Definition sdiv : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let quotient := + |) + |) in + let _ := M.assign_local (| + "quotient" , BinOp.mult (| M.get_name (| globals, "sign" |), BinOp.floor_div (| @@ -402,7 +457,8 @@ Definition sdiv : Value.t -> Value.t -> M := make_dict [] |) |) - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -428,7 +484,7 @@ Definition sdiv : Value.t -> Value.t -> M := |) in M.pure Constant.None_)). -Definition mod : Value.t -> Value.t -> M := +Definition mod_ : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in let _ := Constant.str " @@ -441,22 +497,26 @@ Definition mod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -474,22 +534,26 @@ Definition mod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let remainder := + let _ := M.assign_local (| + "remainder" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let remainder := + let _ := M.assign_local (| + "remainder" , BinOp.mod_ (| M.get_name (| globals, "x" |), M.get_name (| globals, "y" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -520,7 +584,8 @@ Definition smod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -531,8 +596,10 @@ Definition smod : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -543,7 +610,8 @@ Definition smod : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -561,12 +629,15 @@ Definition smod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let remainder := - Constant.int 0 in + let _ := M.assign_local (| + "remainder" , + Constant.int 0 + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let remainder := + let _ := M.assign_local (| + "remainder" , BinOp.mult (| M.call (| M.get_name (| globals, "get_sign" |), @@ -591,7 +662,8 @@ Definition smod : Value.t -> Value.t -> M := make_dict [] |) |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -628,7 +700,8 @@ Definition addmod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -641,8 +714,10 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -655,8 +730,10 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let z := + |) + |) in + let _ := M.assign_local (| + "z" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -669,7 +746,8 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -687,18 +765,21 @@ Definition addmod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -711,7 +792,8 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -742,7 +824,8 @@ Definition mulmod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -755,8 +838,10 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -769,8 +854,10 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let z := + |) + |) in + let _ := M.assign_local (| + "z" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -783,7 +870,8 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -801,18 +889,21 @@ Definition mulmod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -825,7 +916,8 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -856,7 +948,8 @@ Definition exp : Value.t -> Value.t -> M := The current EVM frame. " in - let base := + let _ := M.assign_local (| + "base" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -869,8 +962,10 @@ Definition exp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exponent := + |) + |) in + let _ := M.assign_local (| + "exponent" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -883,21 +978,26 @@ Definition exp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exponent_bits := + |) + |) in + let _ := M.assign_local (| + "exponent_bits" , M.call (| M.get_field (| M.get_name (| globals, "exponent" |), "bit_length" |), make_list [], make_dict [] - |) in - let exponent_bytes := + |) + |) in + let _ := M.assign_local (| + "exponent_bytes" , BinOp.floor_div (| BinOp.add (| M.get_name (| globals, "exponent_bits" |), Constant.int 7 |), Constant.int 8 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -912,7 +1012,8 @@ Definition exp : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -927,7 +1028,8 @@ Definition exp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -956,22 +1058,26 @@ Definition signextend : Value.t -> Value.t -> M := The current EVM frame. " in - let byte_num := + let _ := M.assign_local (| + "byte_num" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -989,12 +1095,15 @@ Definition signextend : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := - M.get_name (| globals, "value" |) in + let _ := M.assign_local (| + "result" , + M.get_name (| globals, "value" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let value_bytes := + let _ := M.assign_local (| + "value_bytes" , M.call (| M.get_name (| globals, "bytes" |), make_list [ @@ -1005,8 +1114,10 @@ Definition signextend : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let value_bytes := + |) + |) in + let _ := M.assign_local (| + "value_bytes" , M.slice (| M.get_name (| globals, "value_bytes" |), BinOp.sub (| @@ -1021,15 +1132,18 @@ Definition signextend : Value.t -> Value.t -> M := |), Constant.None_, Constant.None_ - |) in - let sign_bit := + |) + |) in + let _ := M.assign_local (| + "sign_bit" , BinOp.r_shift (| M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), Constant.int 7 - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1039,26 +1153,31 @@ Definition signextend : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "value_bytes" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let num_bytes_prepend := + let _ := M.assign_local (| + "num_bytes_prepend" , BinOp.sub (| Constant.int 32, BinOp.add (| M.get_name (| globals, "byte_num" |), Constant.int 1 |) - |) in - let result := + |) + |) in + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -1079,7 +1198,8 @@ Definition signextend : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/bitwise.v b/CoqOfPython/ethereum/cancun/vm/instructions/bitwise.v index c4e95c5..3a02f86 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/bitwise.v @@ -17,17 +17,23 @@ Introduction Implementations of the EVM bitwise instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "U256_CEIL_VALUE" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_U256_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U256_CEIL_VALUE". -Axiom ethereum_cancun_vm_imports : - AreImported globals "ethereum.cancun.vm" [ "Evm" ]. +Axiom ethereum_cancun_vm_imports_Evm : + IsImported globals "ethereum.cancun.vm" "Evm". -Axiom ethereum_cancun_vm_gas_imports : - AreImported globals "ethereum.cancun.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_cancun_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.cancun.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_cancun_vm_gas_imports_charge_gas : + IsImported globals "ethereum.cancun.vm.gas" "charge_gas". -Axiom ethereum_cancun_vm_stack_imports : - AreImported globals "ethereum.cancun.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_cancun_vm_stack_imports_pop : + IsImported globals "ethereum.cancun.vm.stack" "pop". +Axiom ethereum_cancun_vm_stack_imports_push : + IsImported globals "ethereum.cancun.vm.stack" "push". Definition bitwise_and : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,22 +48,26 @@ Definition bitwise_and : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -97,22 +107,26 @@ Definition bitwise_or : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -152,22 +166,26 @@ Definition bitwise_xor : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -207,14 +225,16 @@ Definition bitwise_not : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -252,22 +272,26 @@ Definition get_byte : Value.t -> Value.t -> M := The current EVM frame. " in - let byte_index := + let _ := M.assign_local (| + "byte_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let word := + |) + |) in + let _ := M.assign_local (| + "word" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -285,43 +309,53 @@ Definition get_byte : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let extra_bytes_to_right := + let _ := M.assign_local (| + "extra_bytes_to_right" , BinOp.sub (| Constant.int 31, M.get_name (| globals, "byte_index" |) - |) in - let word := + |) + |) in + let _ := M.assign_local (| + "word" , BinOp.r_shift (| M.get_name (| globals, "word" |), BinOp.mult (| M.get_name (| globals, "extra_bytes_to_right" |), Constant.int 8 |) - |) in - let word := + |) + |) in + let _ := M.assign_local (| + "word" , BinOp.bit_and (| M.get_name (| globals, "word" |), Constant.int 255 - |) in - let result := + |) + |) in + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ M.get_name (| globals, "word" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -350,22 +384,26 @@ Definition bitwise_shl : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let shift := + let _ := M.assign_local (| + "shift" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -383,7 +421,8 @@ Definition bitwise_shl : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -396,18 +435,21 @@ Definition bitwise_shl : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -436,22 +478,26 @@ Definition bitwise_shr : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let shift := + let _ := M.assign_local (| + "shift" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -469,22 +515,26 @@ Definition bitwise_shr : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , BinOp.r_shift (| M.get_name (| globals, "value" |), M.get_name (| globals, "shift" |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -513,15 +563,18 @@ Definition bitwise_sar : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let shift := + let _ := M.assign_local (| + "shift" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let signed_value := + |) + |) in + let _ := M.assign_local (| + "signed_value" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -532,7 +585,8 @@ Definition bitwise_sar : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -550,7 +604,8 @@ Definition bitwise_sar : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), make_list [ @@ -560,7 +615,8 @@ Definition bitwise_sar : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -573,19 +629,23 @@ Definition bitwise_sar : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := - M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) in + let _ := M.assign_local (| + "result" , + M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/block.v b/CoqOfPython/ethereum/cancun/vm/instructions/block.v index 86d212c..f0c6cb2 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/block.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/block.v @@ -17,17 +17,23 @@ Introduction Implementations of the EVM block instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_cancun_vm_imports : - AreImported globals "ethereum.cancun.vm" [ "Evm" ]. +Axiom ethereum_cancun_vm_imports_Evm : + IsImported globals "ethereum.cancun.vm" "Evm". -Axiom ethereum_cancun_vm_gas_imports : - AreImported globals "ethereum.cancun.vm.gas" [ "GAS_BASE"; "GAS_BLOCK_HASH"; "charge_gas" ]. +Axiom ethereum_cancun_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.cancun.vm.gas" "GAS_BASE". +Axiom ethereum_cancun_vm_gas_imports_GAS_BLOCK_HASH : + IsImported globals "ethereum.cancun.vm.gas" "GAS_BLOCK_HASH". +Axiom ethereum_cancun_vm_gas_imports_charge_gas : + IsImported globals "ethereum.cancun.vm.gas" "charge_gas". -Axiom ethereum_cancun_vm_stack_imports : - AreImported globals "ethereum.cancun.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_cancun_vm_stack_imports_pop : + IsImported globals "ethereum.cancun.vm.stack" "pop". +Axiom ethereum_cancun_vm_stack_imports_push : + IsImported globals "ethereum.cancun.vm.stack" "push". Definition block_hash : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -48,14 +54,16 @@ Definition block_hash : Value.t -> Value.t -> M := :py:class:`~ethereum.cancun.vm.exceptions.OutOfGasError` If `evm.gas_left` is less than `20`. " in - let block_number := + let _ := M.assign_local (| + "block_number" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -84,19 +92,23 @@ Definition block_hash : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let hash := - Constant.bytes "00" in + let _ := M.assign_local (| + "hash" , + Constant.bytes "00" + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let hash := + let _ := M.assign_local (| + "hash" , M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), M.get_name (| globals, "block_number" |) |) |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/comparison.v b/CoqOfPython/ethereum/cancun/vm/instructions/comparison.v index d1ca20b..a80ba14 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/comparison.v @@ -17,17 +17,21 @@ Introduction Implementations of the EVM Comparison instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_cancun_vm_imports : - AreImported globals "ethereum.cancun.vm" [ "Evm" ]. +Axiom ethereum_cancun_vm_imports_Evm : + IsImported globals "ethereum.cancun.vm" "Evm". -Axiom ethereum_cancun_vm_gas_imports : - AreImported globals "ethereum.cancun.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_cancun_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.cancun.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_cancun_vm_gas_imports_charge_gas : + IsImported globals "ethereum.cancun.vm.gas" "charge_gas". -Axiom ethereum_cancun_vm_stack_imports : - AreImported globals "ethereum.cancun.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_cancun_vm_stack_imports_pop : + IsImported globals "ethereum.cancun.vm.stack" "pop". +Axiom ethereum_cancun_vm_stack_imports_push : + IsImported globals "ethereum.cancun.vm.stack" "push". Definition less_than : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,22 +46,26 @@ Definition less_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -66,7 +74,8 @@ Definition less_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -76,7 +85,8 @@ Definition less_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -104,7 +114,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -115,8 +126,10 @@ Definition signed_less_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -127,7 +140,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -136,7 +150,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -146,7 +161,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -175,22 +191,26 @@ Definition greater_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -199,7 +219,8 @@ Definition greater_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -209,7 +230,8 @@ Definition greater_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -237,7 +259,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -248,8 +271,10 @@ Definition signed_greater_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -260,7 +285,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -269,7 +295,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -279,7 +306,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -308,22 +336,26 @@ Definition equal : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -332,7 +364,8 @@ Definition equal : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -342,7 +375,8 @@ Definition equal : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -371,14 +405,16 @@ Definition is_zero : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -387,7 +423,8 @@ Definition is_zero : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -397,7 +434,8 @@ Definition is_zero : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/control_flow.v b/CoqOfPython/ethereum/cancun/vm/instructions/control_flow.v index 159e932..ac1ba96 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/control_flow.v @@ -17,20 +17,32 @@ Introduction Implementations of the EVM control flow instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_cancun_vm_gas_imports : - AreImported globals "ethereum.cancun.vm.gas" [ "GAS_BASE"; "GAS_HIGH"; "GAS_JUMPDEST"; "GAS_MID"; "charge_gas" ]. +Axiom ethereum_cancun_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.cancun.vm.gas" "GAS_BASE". +Axiom ethereum_cancun_vm_gas_imports_GAS_HIGH : + IsImported globals "ethereum.cancun.vm.gas" "GAS_HIGH". +Axiom ethereum_cancun_vm_gas_imports_GAS_JUMPDEST : + IsImported globals "ethereum.cancun.vm.gas" "GAS_JUMPDEST". +Axiom ethereum_cancun_vm_gas_imports_GAS_MID : + IsImported globals "ethereum.cancun.vm.gas" "GAS_MID". +Axiom ethereum_cancun_vm_gas_imports_charge_gas : + IsImported globals "ethereum.cancun.vm.gas" "charge_gas". -Axiom ethereum_cancun_vm_imports : - AreImported globals "ethereum.cancun.vm" [ "Evm" ]. +Axiom ethereum_cancun_vm_imports_Evm : + IsImported globals "ethereum.cancun.vm" "Evm". -Axiom ethereum_cancun_vm_exceptions_imports : - AreImported globals "ethereum.cancun.vm.exceptions" [ "InvalidJumpDestError" ]. +Axiom ethereum_cancun_vm_exceptions_imports_InvalidJumpDestError : + IsImported globals "ethereum.cancun.vm.exceptions" "InvalidJumpDestError". -Axiom ethereum_cancun_vm_stack_imports : - AreImported globals "ethereum.cancun.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_cancun_vm_stack_imports_pop : + IsImported globals "ethereum.cancun.vm.stack" "pop". +Axiom ethereum_cancun_vm_stack_imports_push : + IsImported globals "ethereum.cancun.vm.stack" "push". Definition stop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -69,7 +81,8 @@ Definition jump : Value.t -> Value.t -> M := The current EVM frame. " in - let jump_dest := + let _ := M.assign_local (| + "jump_dest" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -82,7 +95,8 @@ Definition jump : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -132,7 +146,8 @@ Definition jumpi : Value.t -> Value.t -> M := The current EVM frame. " in - let jump_dest := + let _ := M.assign_local (| + "jump_dest" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -145,15 +160,18 @@ Definition jumpi : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let conditional_value := + |) + |) in + let _ := M.assign_local (| + "conditional_value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -171,11 +189,13 @@ Definition jumpi : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let destination := + let _ := M.assign_local (| + "destination" , BinOp.add (| M.get_field (| M.get_name (| globals, "evm" |), "pc" |), Constant.int 1 - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -192,8 +212,10 @@ Definition jumpi : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let destination := - M.get_name (| globals, "jump_dest" |) in + let _ := M.assign_local (| + "destination" , + M.get_name (| globals, "jump_dest" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/environment.v b/CoqOfPython/ethereum/cancun/vm/instructions/environment.v index fa5e4eb..ab22c8e 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/environment.v @@ -17,41 +17,69 @@ Introduction Implementations of the EVM environment related instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes32"; "Uint" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. - -Axiom ethereum_cancun_fork_types_imports : - AreImported globals "ethereum.cancun.fork_types" [ "EMPTY_ACCOUNT" ]. - -Axiom ethereum_cancun_state_imports : - AreImported globals "ethereum.cancun.state" [ "get_account" ]. - -Axiom ethereum_cancun_utils_address_imports : - AreImported globals "ethereum.cancun.utils.address" [ "to_address" ]. - -Axiom ethereum_cancun_vm_memory_imports : - AreImported globals "ethereum.cancun.vm.memory" [ "buffer_read"; "memory_write" ]. - -Axiom ethereum_cancun_vm_imports : - AreImported globals "ethereum.cancun.vm" [ "Evm" ]. - -Axiom ethereum_cancun_vm_exceptions_imports : - AreImported globals "ethereum.cancun.vm.exceptions" [ "OutOfBoundsRead" ]. - -Axiom ethereum_cancun_vm_gas_imports : - AreImported globals "ethereum.cancun.vm.gas" [ "GAS_BASE"; "GAS_BLOBHASH_OPCODE"; "GAS_COLD_ACCOUNT_ACCESS"; "GAS_COPY"; "GAS_FAST_STEP"; "GAS_RETURN_DATA_COPY"; "GAS_VERY_LOW"; "GAS_WARM_ACCESS"; "calculate_blob_gas_price"; "calculate_gas_extend_memory"; "charge_gas" ]. - -Axiom ethereum_cancun_vm_stack_imports : - AreImported globals "ethereum.cancun.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". + +Axiom ethereum_cancun_fork_types_imports_EMPTY_ACCOUNT : + IsImported globals "ethereum.cancun.fork_types" "EMPTY_ACCOUNT". + +Axiom ethereum_cancun_state_imports_get_account : + IsImported globals "ethereum.cancun.state" "get_account". + +Axiom ethereum_cancun_utils_address_imports_to_address : + IsImported globals "ethereum.cancun.utils.address" "to_address". + +Axiom ethereum_cancun_vm_memory_imports_buffer_read : + IsImported globals "ethereum.cancun.vm.memory" "buffer_read". +Axiom ethereum_cancun_vm_memory_imports_memory_write : + IsImported globals "ethereum.cancun.vm.memory" "memory_write". + +Axiom ethereum_cancun_vm_imports_Evm : + IsImported globals "ethereum.cancun.vm" "Evm". + +Axiom ethereum_cancun_vm_exceptions_imports_OutOfBoundsRead : + IsImported globals "ethereum.cancun.vm.exceptions" "OutOfBoundsRead". + +Axiom ethereum_cancun_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.cancun.vm.gas" "GAS_BASE". +Axiom ethereum_cancun_vm_gas_imports_GAS_BLOBHASH_OPCODE : + IsImported globals "ethereum.cancun.vm.gas" "GAS_BLOBHASH_OPCODE". +Axiom ethereum_cancun_vm_gas_imports_GAS_COLD_ACCOUNT_ACCESS : + IsImported globals "ethereum.cancun.vm.gas" "GAS_COLD_ACCOUNT_ACCESS". +Axiom ethereum_cancun_vm_gas_imports_GAS_COPY : + IsImported globals "ethereum.cancun.vm.gas" "GAS_COPY". +Axiom ethereum_cancun_vm_gas_imports_GAS_FAST_STEP : + IsImported globals "ethereum.cancun.vm.gas" "GAS_FAST_STEP". +Axiom ethereum_cancun_vm_gas_imports_GAS_RETURN_DATA_COPY : + IsImported globals "ethereum.cancun.vm.gas" "GAS_RETURN_DATA_COPY". +Axiom ethereum_cancun_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.cancun.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_cancun_vm_gas_imports_GAS_WARM_ACCESS : + IsImported globals "ethereum.cancun.vm.gas" "GAS_WARM_ACCESS". +Axiom ethereum_cancun_vm_gas_imports_calculate_blob_gas_price : + IsImported globals "ethereum.cancun.vm.gas" "calculate_blob_gas_price". +Axiom ethereum_cancun_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.cancun.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_cancun_vm_gas_imports_charge_gas : + IsImported globals "ethereum.cancun.vm.gas" "charge_gas". + +Axiom ethereum_cancun_vm_stack_imports_pop : + IsImported globals "ethereum.cancun.vm.stack" "pop". +Axiom ethereum_cancun_vm_stack_imports_push : + IsImported globals "ethereum.cancun.vm.stack" "push". Definition address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -107,7 +135,8 @@ Definition balance : Value.t -> Value.t -> M := The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -120,7 +149,8 @@ Definition balance : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -158,7 +188,8 @@ Definition balance : Value.t -> Value.t -> M := |) in M.pure Constant.None_ )) |) in - let balance := + let _ := M.assign_local (| + "balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -166,7 +197,8 @@ Definition balance : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -316,14 +348,16 @@ Definition calldataload : Value.t -> Value.t -> M := The current EVM frame. " in - let start_index := + let _ := M.assign_local (| + "start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -332,7 +366,8 @@ Definition calldataload : Value.t -> Value.t -> M := ], make_dict [] |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -347,7 +382,8 @@ Definition calldataload : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -432,31 +468,38 @@ Definition calldatacopy : Value.t -> Value.t -> M := The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let data_start_index := + |) + |) in + let _ := M.assign_local (| + "data_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -472,13 +515,17 @@ Definition calldatacopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -488,7 +535,8 @@ Definition calldatacopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -511,7 +559,8 @@ Definition calldatacopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -520,7 +569,8 @@ Definition calldatacopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -600,31 +650,38 @@ Definition codecopy : Value.t -> Value.t -> M := The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let code_start_index := + |) + |) in + let _ := M.assign_local (| + "code_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -640,13 +697,17 @@ Definition codecopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -656,7 +717,8 @@ Definition codecopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -679,7 +741,8 @@ Definition codecopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -688,7 +751,8 @@ Definition codecopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -759,7 +823,8 @@ Definition extcodesize : Value.t -> Value.t -> M := The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -772,7 +837,8 @@ Definition extcodesize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -810,7 +876,8 @@ Definition extcodesize : Value.t -> Value.t -> M := |) in M.pure Constant.None_ )) |) in - let codesize := + let _ := M.assign_local (| + "codesize" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -830,7 +897,8 @@ Definition extcodesize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -858,7 +926,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -871,32 +940,40 @@ Definition extcodecopy : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let memory_start_index := + |) + |) in + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let code_start_index := + |) + |) in + let _ := M.assign_local (| + "code_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -912,13 +989,17 @@ Definition extcodecopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -928,7 +1009,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -986,7 +1068,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let code := + let _ := M.assign_local (| + "code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -994,8 +1077,10 @@ Definition extcodecopy : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |), "code" |) in - let value := + |), "code" |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -1004,7 +1089,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -1079,31 +1165,38 @@ Definition returndatacopy : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let return_data_start_position := + |) + |) in + let _ := M.assign_local (| + "return_data_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -1119,13 +1212,17 @@ Definition returndatacopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_RETURN_DATA_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1135,7 +1232,8 @@ Definition returndatacopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1190,7 +1288,8 @@ Definition returndatacopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.slice (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |), @@ -1199,7 +1298,8 @@ Definition returndatacopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) |), Constant.None_ - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -1226,7 +1326,8 @@ Definition extcodehash : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1239,7 +1340,8 @@ Definition extcodehash : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1277,7 +1379,8 @@ Definition extcodehash : Value.t -> Value.t -> M := |) in M.pure Constant.None_ )) |) in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1285,7 +1388,8 @@ Definition extcodehash : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1295,18 +1399,21 @@ Definition extcodehash : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let codehash := + let _ := M.assign_local (| + "codehash" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let codehash := + let _ := M.assign_local (| + "codehash" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -1319,7 +1426,8 @@ Definition extcodehash : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -1358,7 +1466,8 @@ Definition self_balance : Value.t -> Value.t -> M := ], make_dict [] |) in - let balance := + let _ := M.assign_local (| + "balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1366,7 +1475,8 @@ Definition self_balance : Value.t -> Value.t -> M := M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -1436,14 +1546,16 @@ Definition blob_hash : Value.t -> Value.t -> M := The current EVM frame. " in - let index := + let _ := M.assign_local (| + "index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1467,15 +1579,18 @@ Definition blob_hash : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let blob_hash := + let _ := M.assign_local (| + "blob_hash" , M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "blob_versioned_hashes" |), M.get_name (| globals, "index" |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let blob_hash := + let _ := M.assign_local (| + "blob_hash" , M.call (| M.get_name (| globals, "Bytes32" |), make_list [ @@ -1485,7 +1600,8 @@ Definition blob_hash : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -1530,14 +1646,16 @@ Definition blob_base_fee : Value.t -> Value.t -> M := ], make_dict [] |) in - let blob_base_fee := + let _ := M.assign_local (| + "blob_base_fee" , M.call (| M.get_name (| globals, "calculate_blob_gas_price" |), make_list [ M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "excess_blob_gas" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/keccak.v b/CoqOfPython/ethereum/cancun/vm/instructions/keccak.v index 3b8b029..03a31d2 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/keccak.v @@ -17,26 +17,36 @@ Introduction Implementations of the EVM keccak instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_cancun_vm_imports : - AreImported globals "ethereum.cancun.vm" [ "Evm" ]. +Axiom ethereum_cancun_vm_imports_Evm : + IsImported globals "ethereum.cancun.vm" "Evm". -Axiom ethereum_cancun_vm_gas_imports : - AreImported globals "ethereum.cancun.vm.gas" [ "GAS_KECCAK256"; "GAS_KECCAK256_WORD"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_cancun_vm_gas_imports_GAS_KECCAK256 : + IsImported globals "ethereum.cancun.vm.gas" "GAS_KECCAK256". +Axiom ethereum_cancun_vm_gas_imports_GAS_KECCAK256_WORD : + IsImported globals "ethereum.cancun.vm.gas" "GAS_KECCAK256_WORD". +Axiom ethereum_cancun_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.cancun.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_cancun_vm_gas_imports_charge_gas : + IsImported globals "ethereum.cancun.vm.gas" "charge_gas". -Axiom ethereum_cancun_vm_memory_imports : - AreImported globals "ethereum.cancun.vm.memory" [ "memory_read_bytes" ]. +Axiom ethereum_cancun_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.cancun.vm.memory" "memory_read_bytes". -Axiom ethereum_cancun_vm_stack_imports : - AreImported globals "ethereum.cancun.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_cancun_vm_stack_imports_pop : + IsImported globals "ethereum.cancun.vm.stack" "pop". +Axiom ethereum_cancun_vm_stack_imports_push : + IsImported globals "ethereum.cancun.vm.stack" "push". Definition keccak : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -53,23 +63,28 @@ Definition keccak : Value.t -> Value.t -> M := The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -85,13 +100,17 @@ Definition keccak : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let word_gas_cost := + |) + |) in + let _ := M.assign_local (| + "word_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_KECCAK256_WORD" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -101,7 +120,8 @@ Definition keccak : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -124,7 +144,8 @@ Definition keccak : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let data := + let _ := M.assign_local (| + "data" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -133,15 +154,18 @@ Definition keccak : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in - let hash := + |) + |) in + let _ := M.assign_local (| + "hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "data" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/log.v b/CoqOfPython/ethereum/cancun/vm/instructions/log.v index 49d60ea..cfc4c02 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/log.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/log.v @@ -17,32 +17,40 @@ Introduction Implementations of the EVM logging instructions. ". -Axiom functools_imports : - AreImported globals "functools" [ "partial" ]. +Axiom functools_imports_partial : + IsImported globals "functools" "partial". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_cancun_blocks_imports : - AreImported globals "ethereum.cancun.blocks" [ "Log" ]. +Axiom ethereum_cancun_blocks_imports_Log : + IsImported globals "ethereum.cancun.blocks" "Log". -Axiom ethereum_cancun_vm_imports : - AreImported globals "ethereum.cancun.vm" [ "Evm" ]. +Axiom ethereum_cancun_vm_imports_Evm : + IsImported globals "ethereum.cancun.vm" "Evm". -Axiom ethereum_cancun_vm_exceptions_imports : - AreImported globals "ethereum.cancun.vm.exceptions" [ "WriteInStaticContext" ]. +Axiom ethereum_cancun_vm_exceptions_imports_WriteInStaticContext : + IsImported globals "ethereum.cancun.vm.exceptions" "WriteInStaticContext". -Axiom ethereum_cancun_vm_gas_imports : - AreImported globals "ethereum.cancun.vm.gas" [ "GAS_LOG"; "GAS_LOG_DATA"; "GAS_LOG_TOPIC"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_cancun_vm_gas_imports_GAS_LOG : + IsImported globals "ethereum.cancun.vm.gas" "GAS_LOG". +Axiom ethereum_cancun_vm_gas_imports_GAS_LOG_DATA : + IsImported globals "ethereum.cancun.vm.gas" "GAS_LOG_DATA". +Axiom ethereum_cancun_vm_gas_imports_GAS_LOG_TOPIC : + IsImported globals "ethereum.cancun.vm.gas" "GAS_LOG_TOPIC". +Axiom ethereum_cancun_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.cancun.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_cancun_vm_gas_imports_charge_gas : + IsImported globals "ethereum.cancun.vm.gas" "charge_gas". -Axiom ethereum_cancun_vm_memory_imports : - AreImported globals "ethereum.cancun.vm.memory" [ "memory_read_bytes" ]. +Axiom ethereum_cancun_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.cancun.vm.memory" "memory_read_bytes". -Axiom ethereum_cancun_vm_stack_imports : - AreImported globals "ethereum.cancun.vm.stack" [ "pop" ]. +Axiom ethereum_cancun_vm_stack_imports_pop : + IsImported globals "ethereum.cancun.vm.stack" "pop". Definition log_n : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -61,24 +69,30 @@ Definition log_n : Value.t -> Value.t -> M := The number of topics to be included in the log entry. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let topics := - make_list [] in + |) + |) in + let _ := M.assign_local (| + "topics" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "_" |), @@ -90,7 +104,8 @@ Definition log_n : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let topic := + let _ := M.assign_local (| + "topic" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -101,7 +116,8 @@ Definition log_n : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "topics" |), "append" |), make_list [ @@ -115,7 +131,8 @@ Definition log_n : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let extend_memory := + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -125,7 +142,8 @@ Definition log_n : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -165,12 +183,14 @@ Definition log_n : Value.t -> Value.t -> M := ], make_dict [] |) in - let log_entry := + let _ := M.assign_local (| + "log_entry" , M.call (| M.get_name (| globals, "Log" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "logs" |), BinOp.add (| diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/memory.v b/CoqOfPython/ethereum/cancun/vm/instructions/memory.v index d64ad64..acd8e09 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/memory.v @@ -17,23 +17,39 @@ Introduction Implementations of the EVM Memory instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_cancun_vm_imports : - AreImported globals "ethereum.cancun.vm" [ "Evm" ]. +Axiom ethereum_cancun_vm_imports_Evm : + IsImported globals "ethereum.cancun.vm" "Evm". -Axiom ethereum_cancun_vm_gas_imports : - AreImported globals "ethereum.cancun.vm.gas" [ "GAS_BASE"; "GAS_COPY"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_cancun_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.cancun.vm.gas" "GAS_BASE". +Axiom ethereum_cancun_vm_gas_imports_GAS_COPY : + IsImported globals "ethereum.cancun.vm.gas" "GAS_COPY". +Axiom ethereum_cancun_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.cancun.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_cancun_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.cancun.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_cancun_vm_gas_imports_charge_gas : + IsImported globals "ethereum.cancun.vm.gas" "charge_gas". -Axiom ethereum_cancun_vm_memory_imports : - AreImported globals "ethereum.cancun.vm.memory" [ "memory_read_bytes"; "memory_write" ]. +Axiom ethereum_cancun_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.cancun.vm.memory" "memory_read_bytes". +Axiom ethereum_cancun_vm_memory_imports_memory_write : + IsImported globals "ethereum.cancun.vm.memory" "memory_write". -Axiom ethereum_cancun_vm_stack_imports : - AreImported globals "ethereum.cancun.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_cancun_vm_stack_imports_pop : + IsImported globals "ethereum.cancun.vm.stack" "pop". +Axiom ethereum_cancun_vm_stack_imports_push : + IsImported globals "ethereum.cancun.vm.stack" "push". Definition mstore : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -49,15 +65,18 @@ Definition mstore : Value.t -> Value.t -> M := The current EVM frame. " in - let start_position := + let _ := M.assign_local (| + "start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -68,8 +87,10 @@ Definition mstore : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -91,7 +112,8 @@ Definition mstore : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -141,23 +163,28 @@ Definition mstore8 : Value.t -> Value.t -> M := The current EVM frame. " in - let start_position := + let _ := M.assign_local (| + "start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -173,7 +200,8 @@ Definition mstore8 : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -193,7 +221,8 @@ Definition mstore8 : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let normalized_bytes_value := + let _ := M.assign_local (| + "normalized_bytes_value" , M.call (| M.get_name (| globals, "Bytes" |), make_list [ @@ -205,7 +234,8 @@ Definition mstore8 : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -234,15 +264,18 @@ Definition mload : Value.t -> Value.t -> M := The current EVM frame. " in - let start_position := + let _ := M.assign_local (| + "start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -258,7 +291,8 @@ Definition mload : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -278,7 +312,8 @@ Definition mload : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -299,7 +334,8 @@ Definition mload : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -375,31 +411,38 @@ Definition mcopy : Value.t -> Value.t -> M := The current EVM frame. " in - let destination := + let _ := M.assign_local (| + "destination" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let source := + |) + |) in + let _ := M.assign_local (| + "source" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let length := + |) + |) in + let _ := M.assign_local (| + "length" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -415,13 +458,17 @@ Definition mcopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -432,7 +479,8 @@ Definition mcopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -455,7 +503,8 @@ Definition mcopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -464,7 +513,8 @@ Definition mcopy : Value.t -> Value.t -> M := M.get_name (| globals, "length" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/stack.v b/CoqOfPython/ethereum/cancun/vm/instructions/stack.v index 7b65ede..aec7b04 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/stack.v @@ -17,26 +17,32 @@ Introduction Implementations of the EVM stack related instructions. ". -Axiom functools_imports : - AreImported globals "functools" [ "partial" ]. +Axiom functools_imports_partial : + IsImported globals "functools" "partial". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_cancun_vm_imports : - AreImported globals "ethereum.cancun.vm" [ "Evm"; "stack" ]. +Axiom ethereum_cancun_vm_imports_Evm : + IsImported globals "ethereum.cancun.vm" "Evm". +Axiom ethereum_cancun_vm_imports_stack : + IsImported globals "ethereum.cancun.vm" "stack". -Axiom ethereum_cancun_vm_exceptions_imports : - AreImported globals "ethereum.cancun.vm.exceptions" [ "StackUnderflowError" ]. +Axiom ethereum_cancun_vm_exceptions_imports_StackUnderflowError : + IsImported globals "ethereum.cancun.vm.exceptions" "StackUnderflowError". -Axiom ethereum_cancun_vm_gas_imports : - AreImported globals "ethereum.cancun.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_cancun_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.cancun.vm.gas" "GAS_BASE". +Axiom ethereum_cancun_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.cancun.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_cancun_vm_gas_imports_charge_gas : + IsImported globals "ethereum.cancun.vm.gas" "charge_gas". -Axiom ethereum_cancun_vm_memory_imports : - AreImported globals "ethereum.cancun.vm.memory" [ "buffer_read" ]. +Axiom ethereum_cancun_vm_memory_imports_buffer_read : + IsImported globals "ethereum.cancun.vm.memory" "buffer_read". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -120,7 +126,8 @@ Definition push_n : Value.t -> Value.t -> M := |) in M.pure Constant.None_ )) |) in - let data_to_push := + let _ := M.assign_local (| + "data_to_push" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -150,7 +157,8 @@ Definition push_n : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "stack" |), "push" |), make_list [ @@ -211,7 +219,8 @@ Definition dup_n : Value.t -> Value.t -> M := ], make_dict [] |) in - let data_to_duplicate := + let _ := M.assign_local (| + "data_to_duplicate" , M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| @@ -227,7 +236,8 @@ Definition dup_n : Value.t -> Value.t -> M := |), M.get_name (| globals, "item_number" |) |) - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "stack" |), "push" |), make_list [ diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/storage.v b/CoqOfPython/ethereum/cancun/vm/instructions/storage.v index d27683d..04025e4 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/storage.v @@ -17,26 +17,50 @@ Introduction Implementations of the EVM storage related instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_cancun_state_imports : - AreImported globals "ethereum.cancun.state" [ "get_storage"; "get_storage_original"; "get_transient_storage"; "set_storage"; "set_transient_storage" ]. +Axiom ethereum_cancun_state_imports_get_storage : + IsImported globals "ethereum.cancun.state" "get_storage". +Axiom ethereum_cancun_state_imports_get_storage_original : + IsImported globals "ethereum.cancun.state" "get_storage_original". +Axiom ethereum_cancun_state_imports_get_transient_storage : + IsImported globals "ethereum.cancun.state" "get_transient_storage". +Axiom ethereum_cancun_state_imports_set_storage : + IsImported globals "ethereum.cancun.state" "set_storage". +Axiom ethereum_cancun_state_imports_set_transient_storage : + IsImported globals "ethereum.cancun.state" "set_transient_storage". -Axiom ethereum_cancun_vm_imports : - AreImported globals "ethereum.cancun.vm" [ "Evm" ]. +Axiom ethereum_cancun_vm_imports_Evm : + IsImported globals "ethereum.cancun.vm" "Evm". -Axiom ethereum_cancun_vm_exceptions_imports : - AreImported globals "ethereum.cancun.vm.exceptions" [ "OutOfGasError"; "WriteInStaticContext" ]. +Axiom ethereum_cancun_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.cancun.vm.exceptions" "OutOfGasError". +Axiom ethereum_cancun_vm_exceptions_imports_WriteInStaticContext : + IsImported globals "ethereum.cancun.vm.exceptions" "WriteInStaticContext". -Axiom ethereum_cancun_vm_gas_imports : - AreImported globals "ethereum.cancun.vm.gas" [ "GAS_CALL_STIPEND"; "GAS_COLD_SLOAD"; "GAS_STORAGE_CLEAR_REFUND"; "GAS_STORAGE_SET"; "GAS_STORAGE_UPDATE"; "GAS_WARM_ACCESS"; "charge_gas" ]. +Axiom ethereum_cancun_vm_gas_imports_GAS_CALL_STIPEND : + IsImported globals "ethereum.cancun.vm.gas" "GAS_CALL_STIPEND". +Axiom ethereum_cancun_vm_gas_imports_GAS_COLD_SLOAD : + IsImported globals "ethereum.cancun.vm.gas" "GAS_COLD_SLOAD". +Axiom ethereum_cancun_vm_gas_imports_GAS_STORAGE_CLEAR_REFUND : + IsImported globals "ethereum.cancun.vm.gas" "GAS_STORAGE_CLEAR_REFUND". +Axiom ethereum_cancun_vm_gas_imports_GAS_STORAGE_SET : + IsImported globals "ethereum.cancun.vm.gas" "GAS_STORAGE_SET". +Axiom ethereum_cancun_vm_gas_imports_GAS_STORAGE_UPDATE : + IsImported globals "ethereum.cancun.vm.gas" "GAS_STORAGE_UPDATE". +Axiom ethereum_cancun_vm_gas_imports_GAS_WARM_ACCESS : + IsImported globals "ethereum.cancun.vm.gas" "GAS_WARM_ACCESS". +Axiom ethereum_cancun_vm_gas_imports_charge_gas : + IsImported globals "ethereum.cancun.vm.gas" "charge_gas". -Axiom ethereum_cancun_vm_stack_imports : - AreImported globals "ethereum.cancun.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_cancun_vm_stack_imports_pop : + IsImported globals "ethereum.cancun.vm.stack" "pop". +Axiom ethereum_cancun_vm_stack_imports_push : + IsImported globals "ethereum.cancun.vm.stack" "push". Definition sload : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -51,7 +75,8 @@ Definition sload : Value.t -> Value.t -> M := The current EVM frame. " in - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -62,7 +87,8 @@ Definition sload : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -100,7 +126,8 @@ Definition sload : Value.t -> Value.t -> M := |) in M.pure Constant.None_ )) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "get_storage" |), make_list [ @@ -109,7 +136,8 @@ Definition sload : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -137,7 +165,8 @@ Definition sstore : Value.t -> Value.t -> M := The current EVM frame. " in - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -148,15 +177,18 @@ Definition sstore : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in - let new_value := + |) + |) in + let _ := M.assign_local (| + "new_value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -168,7 +200,8 @@ Definition sstore : Value.t -> Value.t -> M := ], make_dict [] |) in - let original_value := + let _ := M.assign_local (| + "original_value" , M.call (| M.get_name (| globals, "get_storage_original" |), make_list [ @@ -177,8 +210,10 @@ Definition sstore : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in - let current_value := + |) + |) in + let _ := M.assign_local (| + "current_value" , M.call (| M.get_name (| globals, "get_storage" |), make_list [ @@ -187,15 +222,18 @@ Definition sstore : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in - let gas_cost := + |) + |) in + let _ := M.assign_local (| + "gas_cost" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -212,9 +250,11 @@ Definition sstore : Value.t -> Value.t -> M := ], make_dict [] |) in - let gas_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "gas_cost", M.get_name (| globals, "GAS_COLD_SLOAD" |) - M.get_name (| globals, "GAS_COLD_SLOAD" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -246,29 +286,32 @@ Definition sstore : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let gas_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "gas_cost", M.get_name (| globals, "GAS_STORAGE_SET" |) - M.get_name (| globals, "GAS_STORAGE_SET" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let gas_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "gas_cost", BinOp.sub (| M.get_name (| globals, "GAS_STORAGE_UPDATE" |), M.get_name (| globals, "GAS_COLD_SLOAD" |) |) - BinOp.sub (| - M.get_name (| globals, "GAS_STORAGE_UPDATE" |), - M.get_name (| globals, "GAS_COLD_SLOAD" |) - |) in + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let gas_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "gas_cost", M.get_name (| globals, "GAS_WARM_ACCESS" |) - M.get_name (| globals, "GAS_WARM_ACCESS" |) in + |) in M.pure Constant.None_ )) |) in let _ := @@ -462,7 +505,8 @@ Definition tload : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -473,7 +517,8 @@ Definition tload : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -482,7 +527,8 @@ Definition tload : Value.t -> Value.t -> M := ], make_dict [] |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "get_transient_storage" |), make_list [ @@ -491,7 +537,8 @@ Definition tload : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -517,7 +564,8 @@ Definition tstore : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -528,15 +576,18 @@ Definition tstore : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in - let new_value := + |) + |) in + let _ := M.assign_local (| + "new_value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ diff --git a/CoqOfPython/ethereum/cancun/vm/instructions/system.v b/CoqOfPython/ethereum/cancun/vm/instructions/system.v index 6383f61..07121d5 100644 --- a/CoqOfPython/ethereum/cancun/vm/instructions/system.v +++ b/CoqOfPython/ethereum/cancun/vm/instructions/system.v @@ -17,38 +17,98 @@ Introduction Implementations of the EVM system related instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_cancun_fork_types_imports : - AreImported globals "ethereum.cancun.fork_types" [ "Address" ]. +Axiom ethereum_cancun_fork_types_imports_Address : + IsImported globals "ethereum.cancun.fork_types" "Address". -Axiom ethereum_cancun_state_imports : - AreImported globals "ethereum.cancun.state" [ "account_exists_and_is_empty"; "account_has_code_or_nonce"; "get_account"; "increment_nonce"; "is_account_alive"; "move_ether"; "set_account_balance" ]. +Axiom ethereum_cancun_state_imports_account_exists_and_is_empty : + IsImported globals "ethereum.cancun.state" "account_exists_and_is_empty". +Axiom ethereum_cancun_state_imports_account_has_code_or_nonce : + IsImported globals "ethereum.cancun.state" "account_has_code_or_nonce". +Axiom ethereum_cancun_state_imports_get_account : + IsImported globals "ethereum.cancun.state" "get_account". +Axiom ethereum_cancun_state_imports_increment_nonce : + IsImported globals "ethereum.cancun.state" "increment_nonce". +Axiom ethereum_cancun_state_imports_is_account_alive : + IsImported globals "ethereum.cancun.state" "is_account_alive". +Axiom ethereum_cancun_state_imports_move_ether : + IsImported globals "ethereum.cancun.state" "move_ether". +Axiom ethereum_cancun_state_imports_set_account_balance : + IsImported globals "ethereum.cancun.state" "set_account_balance". -Axiom ethereum_cancun_utils_address_imports : - AreImported globals "ethereum.cancun.utils.address" [ "compute_contract_address"; "compute_create2_contract_address"; "to_address" ]. +Axiom ethereum_cancun_utils_address_imports_compute_contract_address : + IsImported globals "ethereum.cancun.utils.address" "compute_contract_address". +Axiom ethereum_cancun_utils_address_imports_compute_create2_contract_address : + IsImported globals "ethereum.cancun.utils.address" "compute_create2_contract_address". +Axiom ethereum_cancun_utils_address_imports_to_address : + IsImported globals "ethereum.cancun.utils.address" "to_address". -Axiom ethereum_cancun_vm_imports : - AreImported globals "ethereum.cancun.vm" [ "Evm"; "Message"; "incorporate_child_on_error"; "incorporate_child_on_success" ]. +Axiom ethereum_cancun_vm_imports_Evm : + IsImported globals "ethereum.cancun.vm" "Evm". +Axiom ethereum_cancun_vm_imports_Message : + IsImported globals "ethereum.cancun.vm" "Message". +Axiom ethereum_cancun_vm_imports_incorporate_child_on_error : + IsImported globals "ethereum.cancun.vm" "incorporate_child_on_error". +Axiom ethereum_cancun_vm_imports_incorporate_child_on_success : + IsImported globals "ethereum.cancun.vm" "incorporate_child_on_success". -Axiom ethereum_cancun_vm_exceptions_imports : - AreImported globals "ethereum.cancun.vm.exceptions" [ "OutOfGasError"; "Revert"; "WriteInStaticContext" ]. +Axiom ethereum_cancun_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.cancun.vm.exceptions" "OutOfGasError". +Axiom ethereum_cancun_vm_exceptions_imports_Revert : + IsImported globals "ethereum.cancun.vm.exceptions" "Revert". +Axiom ethereum_cancun_vm_exceptions_imports_WriteInStaticContext : + IsImported globals "ethereum.cancun.vm.exceptions" "WriteInStaticContext". -Axiom ethereum_cancun_vm_gas_imports : - AreImported globals "ethereum.cancun.vm.gas" [ "GAS_CALL_VALUE"; "GAS_COLD_ACCOUNT_ACCESS"; "GAS_CREATE"; "GAS_KECCAK256_WORD"; "GAS_NEW_ACCOUNT"; "GAS_SELF_DESTRUCT"; "GAS_SELF_DESTRUCT_NEW_ACCOUNT"; "GAS_WARM_ACCESS"; "GAS_ZERO"; "calculate_gas_extend_memory"; "calculate_message_call_gas"; "charge_gas"; "init_code_cost"; "max_message_call_gas" ]. +Axiom ethereum_cancun_vm_gas_imports_GAS_CALL_VALUE : + IsImported globals "ethereum.cancun.vm.gas" "GAS_CALL_VALUE". +Axiom ethereum_cancun_vm_gas_imports_GAS_COLD_ACCOUNT_ACCESS : + IsImported globals "ethereum.cancun.vm.gas" "GAS_COLD_ACCOUNT_ACCESS". +Axiom ethereum_cancun_vm_gas_imports_GAS_CREATE : + IsImported globals "ethereum.cancun.vm.gas" "GAS_CREATE". +Axiom ethereum_cancun_vm_gas_imports_GAS_KECCAK256_WORD : + IsImported globals "ethereum.cancun.vm.gas" "GAS_KECCAK256_WORD". +Axiom ethereum_cancun_vm_gas_imports_GAS_NEW_ACCOUNT : + IsImported globals "ethereum.cancun.vm.gas" "GAS_NEW_ACCOUNT". +Axiom ethereum_cancun_vm_gas_imports_GAS_SELF_DESTRUCT : + IsImported globals "ethereum.cancun.vm.gas" "GAS_SELF_DESTRUCT". +Axiom ethereum_cancun_vm_gas_imports_GAS_SELF_DESTRUCT_NEW_ACCOUNT : + IsImported globals "ethereum.cancun.vm.gas" "GAS_SELF_DESTRUCT_NEW_ACCOUNT". +Axiom ethereum_cancun_vm_gas_imports_GAS_WARM_ACCESS : + IsImported globals "ethereum.cancun.vm.gas" "GAS_WARM_ACCESS". +Axiom ethereum_cancun_vm_gas_imports_GAS_ZERO : + IsImported globals "ethereum.cancun.vm.gas" "GAS_ZERO". +Axiom ethereum_cancun_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.cancun.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_cancun_vm_gas_imports_calculate_message_call_gas : + IsImported globals "ethereum.cancun.vm.gas" "calculate_message_call_gas". +Axiom ethereum_cancun_vm_gas_imports_charge_gas : + IsImported globals "ethereum.cancun.vm.gas" "charge_gas". +Axiom ethereum_cancun_vm_gas_imports_init_code_cost : + IsImported globals "ethereum.cancun.vm.gas" "init_code_cost". +Axiom ethereum_cancun_vm_gas_imports_max_message_call_gas : + IsImported globals "ethereum.cancun.vm.gas" "max_message_call_gas". -Axiom ethereum_cancun_vm_memory_imports : - AreImported globals "ethereum.cancun.vm.memory" [ "memory_read_bytes"; "memory_write" ]. +Axiom ethereum_cancun_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.cancun.vm.memory" "memory_read_bytes". +Axiom ethereum_cancun_vm_memory_imports_memory_write : + IsImported globals "ethereum.cancun.vm.memory" "memory_write". -Axiom ethereum_cancun_vm_stack_imports : - AreImported globals "ethereum.cancun.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_cancun_vm_stack_imports_pop : + IsImported globals "ethereum.cancun.vm.stack" "pop". +Axiom ethereum_cancun_vm_stack_imports_push : + IsImported globals "ethereum.cancun.vm.stack" "push". Definition generic_create : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -57,7 +117,8 @@ Definition generic_create : Value.t -> Value.t -> M := Core logic used by the `CREATE*` family of opcodes. " in (* At stmt: unsupported node type: ImportFrom *) - let call_data := + let _ := M.assign_local (| + "call_data" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -66,7 +127,8 @@ Definition generic_create : Value.t -> Value.t -> M := M.get_name (| globals, "memory_size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -94,7 +156,8 @@ Definition generic_create : Value.t -> Value.t -> M := ], make_dict [] |) in - let create_message_gas := + let _ := M.assign_local (| + "create_message_gas" , M.call (| M.get_name (| globals, "max_message_call_gas" |), make_list [ @@ -107,7 +170,8 @@ Definition generic_create : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.assign_op (| BinOp.sub, M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), @@ -125,9 +189,12 @@ Definition generic_create : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), Constant.bytes "" |) in - let sender_address := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in - let sender := + let _ := M.assign_local (| + "sender_address" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + |) in + let _ := M.assign_local (| + "sender" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -135,7 +202,8 @@ Definition generic_create : Value.t -> Value.t -> M := M.get_name (| globals, "sender_address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -254,13 +322,16 @@ Definition generic_create : Value.t -> Value.t -> M := ], make_dict [] |) in - let child_message := + let _ := M.assign_local (| + "child_message" , M.call (| M.get_name (| globals, "Message" |), make_list [], make_dict [] - |) in - let child_evm := + |) + |) in + let _ := M.assign_local (| + "child_evm" , M.call (| M.get_name (| globals, "process_create_message" |), make_list [ @@ -268,7 +339,8 @@ Definition generic_create : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -345,31 +417,38 @@ Definition create : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let endowment := + let _ := M.assign_local (| + "endowment" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_size := + |) + |) in + let _ := M.assign_local (| + "memory_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -379,8 +458,10 @@ Definition create : Value.t -> Value.t -> M := ] ], make_dict [] - |) in - let init_code_gas := + |) + |) in + let _ := M.assign_local (| + "init_code_gas" , M.call (| M.get_name (| globals, "init_code_cost" |), make_list [ @@ -393,7 +474,8 @@ Definition create : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -416,7 +498,8 @@ Definition create : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let contract_address := + let _ := M.assign_local (| + "contract_address" , M.call (| M.get_name (| globals, "compute_contract_address" |), make_list [ @@ -431,7 +514,8 @@ Definition create : Value.t -> Value.t -> M := |), "nonce" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "generic_create" |), make_list [ @@ -465,31 +549,38 @@ Definition create2 : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let endowment := + let _ := M.assign_local (| + "endowment" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_size := + |) + |) in + let _ := M.assign_local (| + "memory_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let salt := + |) + |) in + let _ := M.assign_local (| + "salt" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -500,8 +591,10 @@ Definition create2 : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -511,8 +604,10 @@ Definition create2 : Value.t -> Value.t -> M := ] ], make_dict [] - |) in - let call_data_words := + |) + |) in + let _ := M.assign_local (| + "call_data_words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -528,8 +623,10 @@ Definition create2 : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let init_code_gas := + |) + |) in + let _ := M.assign_local (| + "init_code_gas" , M.call (| M.get_name (| globals, "init_code_cost" |), make_list [ @@ -542,7 +639,8 @@ Definition create2 : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -571,7 +669,8 @@ Definition create2 : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let contract_address := + let _ := M.assign_local (| + "contract_address" , M.call (| M.get_name (| globals, "compute_create2_contract_address" |), make_list [ @@ -588,7 +687,8 @@ Definition create2 : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "generic_create" |), make_list [ @@ -619,23 +719,28 @@ Definition return_ : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let memory_start_position := + let _ := M.assign_local (| + "memory_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_size := + |) + |) in + let _ := M.assign_local (| + "memory_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -645,7 +750,8 @@ Definition return_ : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -734,7 +840,8 @@ Definition generic_call : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let call_data := + let _ := M.assign_local (| + "call_data" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -743,8 +850,10 @@ Definition generic_call : Value.t -> Value.t -> M := M.get_name (| globals, "memory_input_size" |) ], make_dict [] - |) in - let code := + |) + |) in + let _ := M.assign_local (| + "code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -752,14 +861,18 @@ Definition generic_call : Value.t -> Value.t -> M := M.get_name (| globals, "code_address" |) ], make_dict [] - |), "code" |) in - let child_message := + |), "code" |) + |) in + let _ := M.assign_local (| + "child_message" , M.call (| M.get_name (| globals, "Message" |), make_list [], make_dict [] - |) in - let child_evm := + |) + |) in + let _ := M.assign_local (| + "child_evm" , M.call (| M.get_name (| globals, "process_message" |), make_list [ @@ -767,7 +880,8 @@ Definition generic_call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -831,7 +945,8 @@ Definition generic_call : Value.t -> Value.t -> M := |) in M.pure Constant.None_ )) |) in - let actual_output_size := + let _ := M.assign_local (| + "actual_output_size" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -851,7 +966,8 @@ Definition generic_call : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -879,7 +995,8 @@ Definition call : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -892,8 +1009,10 @@ Definition call : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let to := + |) + |) in + let _ := M.assign_local (| + "to" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -906,48 +1025,60 @@ Definition call : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -958,7 +1089,8 @@ Definition call : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -968,8 +1100,10 @@ Definition call : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let access_gas_cost := - M.get_name (| globals, "GAS_WARM_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -980,11 +1114,14 @@ Definition call : Value.t -> Value.t -> M := ], make_dict [] |) in - let access_gas_cost := - M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + |) in M.pure Constant.None_ )) |) in - let create_gas_cost := + let _ := M.assign_local (| + "create_gas_cost" , (* if *) M.if_then_else (| BoolOp.or (| @@ -1015,8 +1152,10 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "GAS_NEW_ACCOUNT" |) - )) |) in - let transfer_gas_cost := + )) |) + |) in + let _ := M.assign_local (| + "transfer_gas_cost" , (* if *) M.if_then_else (| Compare.eq (| @@ -1035,8 +1174,10 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "GAS_CALL_VALUE" |) - )) |) in - let message_call_gas := + )) |) + |) in + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -1059,7 +1200,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1101,7 +1243,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let sender_balance := + let _ := M.assign_local (| + "sender_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1109,7 +1252,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := (* if *) M.if_then_else (| @@ -1183,7 +1327,8 @@ Definition callcode : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -1196,8 +1341,10 @@ Definition callcode : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let code_address := + |) + |) in + let _ := M.assign_local (| + "code_address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1210,50 +1357,64 @@ Definition callcode : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let to := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "to" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1264,7 +1425,8 @@ Definition callcode : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1274,8 +1436,10 @@ Definition callcode : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let access_gas_cost := - M.get_name (| globals, "GAS_WARM_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1286,11 +1450,14 @@ Definition callcode : Value.t -> Value.t -> M := ], make_dict [] |) in - let access_gas_cost := - M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + |) in M.pure Constant.None_ )) |) in - let transfer_gas_cost := + let _ := M.assign_local (| + "transfer_gas_cost" , (* if *) M.if_then_else (| Compare.eq (| @@ -1309,8 +1476,10 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "GAS_CALL_VALUE" |) - )) |) in - let message_call_gas := + )) |) + |) in + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -1330,7 +1499,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1350,7 +1520,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let sender_balance := + let _ := M.assign_local (| + "sender_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1358,7 +1529,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := (* if *) M.if_then_else (| @@ -1432,7 +1604,8 @@ Definition selfdestruct : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let beneficiary := + let _ := M.assign_local (| + "beneficiary" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1445,9 +1618,12 @@ Definition selfdestruct : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let gas_cost := - M.get_name (| globals, "GAS_SELF_DESTRUCT" |) in + |) + |) in + let _ := M.assign_local (| + "gas_cost" , + M.get_name (| globals, "GAS_SELF_DESTRUCT" |) + |) in let _ := (* if *) M.if_then_else (| @@ -1464,9 +1640,11 @@ Definition selfdestruct : Value.t -> Value.t -> M := ], make_dict [] |) in - let gas_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "gas_cost", M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) - M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1500,9 +1678,11 @@ Definition selfdestruct : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let gas_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "gas_cost", M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) - M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1524,9 +1704,12 @@ Definition selfdestruct : Value.t -> Value.t -> M := ], make_dict [] |) in - let originator := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in - let originator_balance := + let _ := M.assign_local (| + "originator" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + |) in + let _ := M.assign_local (| + "originator_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1534,7 +1717,8 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_name (| globals, "originator" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := M.call (| M.get_name (| globals, "move_ether" |), make_list [ @@ -1624,7 +1808,8 @@ Definition delegatecall : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -1637,8 +1822,10 @@ Definition delegatecall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let code_address := + |) + |) in + let _ := M.assign_local (| + "code_address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1651,40 +1838,50 @@ Definition delegatecall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1695,7 +1892,8 @@ Definition delegatecall : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1705,8 +1903,10 @@ Definition delegatecall : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let access_gas_cost := - M.get_name (| globals, "GAS_WARM_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1717,11 +1917,14 @@ Definition delegatecall : Value.t -> Value.t -> M := ], make_dict [] |) in - let access_gas_cost := - M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + |) in M.pure Constant.None_ )) |) in - let message_call_gas := + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -1744,7 +1947,8 @@ Definition delegatecall : Value.t -> Value.t -> M := M.get_name (| globals, "access_gas_cost" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1800,7 +2004,8 @@ Definition staticcall : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -1813,8 +2018,10 @@ Definition staticcall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let to := + |) + |) in + let _ := M.assign_local (| + "to" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1827,40 +2034,50 @@ Definition staticcall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1871,7 +2088,8 @@ Definition staticcall : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1881,8 +2099,10 @@ Definition staticcall : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let access_gas_cost := - M.get_name (| globals, "GAS_WARM_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1893,11 +2113,14 @@ Definition staticcall : Value.t -> Value.t -> M := ], make_dict [] |) in - let access_gas_cost := - M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + |) in M.pure Constant.None_ )) |) in - let message_call_gas := + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -1920,7 +2143,8 @@ Definition staticcall : Value.t -> Value.t -> M := M.get_name (| globals, "access_gas_cost" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1982,23 +2206,28 @@ Definition revert : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -2008,7 +2237,8 @@ Definition revert : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -2025,7 +2255,8 @@ Definition revert : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let output := + let _ := M.assign_local (| + "output" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -2034,7 +2265,8 @@ Definition revert : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| diff --git a/CoqOfPython/ethereum/cancun/vm/interpreter.v b/CoqOfPython/ethereum/cancun/vm/interpreter.v index 13b4d41..c3551ef 100644 --- a/CoqOfPython/ethereum/cancun/vm/interpreter.v +++ b/CoqOfPython/ethereum/cancun/vm/interpreter.v @@ -17,50 +17,114 @@ Introduction A straightforward interpreter that executes EVM code. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Iterable"; "Optional"; "Set"; "Tuple"; "Union" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. - -Axiom ethereum_trace_imports : - AreImported globals "ethereum.trace" [ "EvmStop"; "OpEnd"; "OpException"; "OpStart"; "PrecompileEnd"; "PrecompileStart"; "TransactionEnd"; "evm_trace" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_cancun_blocks_imports : - AreImported globals "ethereum.cancun.blocks" [ "Log" ]. - -Axiom ethereum_cancun_fork_types_imports : - AreImported globals "ethereum.cancun.fork_types" [ "Address" ]. - -Axiom ethereum_cancun_state_imports : - AreImported globals "ethereum.cancun.state" [ "account_exists_and_is_empty"; "account_has_code_or_nonce"; "begin_transaction"; "commit_transaction"; "destroy_storage"; "increment_nonce"; "mark_account_created"; "move_ether"; "rollback_transaction"; "set_code"; "touch_account" ]. - -Axiom ethereum_cancun_vm_imports : - AreImported globals "ethereum.cancun.vm" [ "Message" ]. - -Axiom ethereum_cancun_vm_gas_imports : - AreImported globals "ethereum.cancun.vm.gas" [ "GAS_CODE_DEPOSIT"; "charge_gas" ]. - -Axiom ethereum_cancun_vm_precompiled_contracts_mapping_imports : - AreImported globals "ethereum.cancun.vm.precompiled_contracts.mapping" [ "PRE_COMPILED_CONTRACTS" ]. - -Axiom ethereum_cancun_vm_imports : - AreImported globals "ethereum.cancun.vm" [ "Environment"; "Evm" ]. - -Axiom ethereum_cancun_vm_exceptions_imports : - AreImported globals "ethereum.cancun.vm.exceptions" [ "AddressCollision"; "ExceptionalHalt"; "InvalidContractPrefix"; "InvalidOpcode"; "OutOfGasError"; "Revert"; "StackDepthLimitError" ]. - -Axiom ethereum_cancun_vm_instructions_imports : - AreImported globals "ethereum.cancun.vm.instructions" [ "Ops"; "op_implementation" ]. - -Axiom ethereum_cancun_vm_runtime_imports : - AreImported globals "ethereum.cancun.vm.runtime" [ "get_valid_jump_destinations" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_Iterable : + IsImported globals "typing" "Iterable". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_trace_imports_EvmStop : + IsImported globals "ethereum.trace" "EvmStop". +Axiom ethereum_trace_imports_OpEnd : + IsImported globals "ethereum.trace" "OpEnd". +Axiom ethereum_trace_imports_OpException : + IsImported globals "ethereum.trace" "OpException". +Axiom ethereum_trace_imports_OpStart : + IsImported globals "ethereum.trace" "OpStart". +Axiom ethereum_trace_imports_PrecompileEnd : + IsImported globals "ethereum.trace" "PrecompileEnd". +Axiom ethereum_trace_imports_PrecompileStart : + IsImported globals "ethereum.trace" "PrecompileStart". +Axiom ethereum_trace_imports_TransactionEnd : + IsImported globals "ethereum.trace" "TransactionEnd". +Axiom ethereum_trace_imports_evm_trace : + IsImported globals "ethereum.trace" "evm_trace". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_cancun_blocks_imports_Log : + IsImported globals "ethereum.cancun.blocks" "Log". + +Axiom ethereum_cancun_fork_types_imports_Address : + IsImported globals "ethereum.cancun.fork_types" "Address". + +Axiom ethereum_cancun_state_imports_account_exists_and_is_empty : + IsImported globals "ethereum.cancun.state" "account_exists_and_is_empty". +Axiom ethereum_cancun_state_imports_account_has_code_or_nonce : + IsImported globals "ethereum.cancun.state" "account_has_code_or_nonce". +Axiom ethereum_cancun_state_imports_begin_transaction : + IsImported globals "ethereum.cancun.state" "begin_transaction". +Axiom ethereum_cancun_state_imports_commit_transaction : + IsImported globals "ethereum.cancun.state" "commit_transaction". +Axiom ethereum_cancun_state_imports_destroy_storage : + IsImported globals "ethereum.cancun.state" "destroy_storage". +Axiom ethereum_cancun_state_imports_increment_nonce : + IsImported globals "ethereum.cancun.state" "increment_nonce". +Axiom ethereum_cancun_state_imports_mark_account_created : + IsImported globals "ethereum.cancun.state" "mark_account_created". +Axiom ethereum_cancun_state_imports_move_ether : + IsImported globals "ethereum.cancun.state" "move_ether". +Axiom ethereum_cancun_state_imports_rollback_transaction : + IsImported globals "ethereum.cancun.state" "rollback_transaction". +Axiom ethereum_cancun_state_imports_set_code : + IsImported globals "ethereum.cancun.state" "set_code". +Axiom ethereum_cancun_state_imports_touch_account : + IsImported globals "ethereum.cancun.state" "touch_account". + +Axiom ethereum_cancun_vm_imports_Message : + IsImported globals "ethereum.cancun.vm" "Message". + +Axiom ethereum_cancun_vm_gas_imports_GAS_CODE_DEPOSIT : + IsImported globals "ethereum.cancun.vm.gas" "GAS_CODE_DEPOSIT". +Axiom ethereum_cancun_vm_gas_imports_charge_gas : + IsImported globals "ethereum.cancun.vm.gas" "charge_gas". + +Axiom ethereum_cancun_vm_precompiled_contracts_mapping_imports_PRE_COMPILED_CONTRACTS : + IsImported globals "ethereum.cancun.vm.precompiled_contracts.mapping" "PRE_COMPILED_CONTRACTS". + +Axiom ethereum_cancun_vm_imports_Environment : + IsImported globals "ethereum.cancun.vm" "Environment". +Axiom ethereum_cancun_vm_imports_Evm : + IsImported globals "ethereum.cancun.vm" "Evm". + +Axiom ethereum_cancun_vm_exceptions_imports_AddressCollision : + IsImported globals "ethereum.cancun.vm.exceptions" "AddressCollision". +Axiom ethereum_cancun_vm_exceptions_imports_ExceptionalHalt : + IsImported globals "ethereum.cancun.vm.exceptions" "ExceptionalHalt". +Axiom ethereum_cancun_vm_exceptions_imports_InvalidContractPrefix : + IsImported globals "ethereum.cancun.vm.exceptions" "InvalidContractPrefix". +Axiom ethereum_cancun_vm_exceptions_imports_InvalidOpcode : + IsImported globals "ethereum.cancun.vm.exceptions" "InvalidOpcode". +Axiom ethereum_cancun_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.cancun.vm.exceptions" "OutOfGasError". +Axiom ethereum_cancun_vm_exceptions_imports_Revert : + IsImported globals "ethereum.cancun.vm.exceptions" "Revert". +Axiom ethereum_cancun_vm_exceptions_imports_StackDepthLimitError : + IsImported globals "ethereum.cancun.vm.exceptions" "StackDepthLimitError". + +Axiom ethereum_cancun_vm_instructions_imports_Ops : + IsImported globals "ethereum.cancun.vm.instructions" "Ops". +Axiom ethereum_cancun_vm_instructions_imports_op_implementation : + IsImported globals "ethereum.cancun.vm.instructions" "op_implementation". + +Axiom ethereum_cancun_vm_runtime_imports_get_valid_jump_destinations : + IsImported globals "ethereum.cancun.vm.runtime" "get_valid_jump_destinations". Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -121,7 +185,8 @@ Definition process_message_call : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let is_collision := + let _ := M.assign_local (| + "is_collision" , M.call (| M.get_name (| globals, "account_has_code_or_nonce" |), make_list [ @@ -129,7 +194,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "message" |), "current_target" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -181,7 +247,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "process_create_message" |), make_list [ @@ -189,13 +256,15 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "process_message" |), make_list [ @@ -203,7 +272,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -250,46 +320,61 @@ Definition process_message_call : Value.t -> Value.t -> M := (* then *) ltac:(M.monadic ( (* At stmt: unsupported node type: AnnAssign *) - let accounts_to_delete := + let _ := M.assign_local (| + "accounts_to_delete" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let touched_accounts := + |) + |) in + let _ := M.assign_local (| + "touched_accounts" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let refund_counter := + |) + |) in + let _ := M.assign_local (| + "refund_counter" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let logs := - M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in - let accounts_to_delete := - M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in - let touched_accounts := - M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |) in - let refund_counter := + let _ := M.assign_local (| + "logs" , + M.get_field (| M.get_name (| globals, "evm" |), "logs" |) + |) in + let _ := M.assign_local (| + "accounts_to_delete" , + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) + |) in + let _ := M.assign_local (| + "touched_accounts" , + M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |) + |) in + let _ := M.assign_local (| + "refund_counter" , M.call (| M.get_name (| globals, "U256" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in - let tx_end := + let _ := M.assign_local (| + "tx_end" , M.call (| M.get_name (| globals, "TransactionEnd" |), make_list [ @@ -301,7 +386,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "error" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "evm_trace" |), make_list [ @@ -369,7 +455,8 @@ Definition process_create_message : Value.t -> Value.t -> M := ], make_dict [] |) in - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "process_message" |), make_list [ @@ -377,16 +464,20 @@ Definition process_create_message : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), (* then *) ltac:(M.monadic ( - let contract_code := - M.get_field (| M.get_name (| globals, "evm" |), "output" |) in - let contract_code_gas := + let _ := M.assign_local (| + "contract_code" , + M.get_field (| M.get_name (| globals, "evm" |), "output" |) + |) in + let _ := M.assign_local (| + "contract_code_gas" , BinOp.mult (| M.call (| M.get_name (| globals, "len" |), @@ -396,7 +487,8 @@ Definition process_create_message : Value.t -> Value.t -> M := make_dict [] |), M.get_name (| globals, "GAS_CODE_DEPOSIT" |) - |) in + |) + |) in (* At stmt: unsupported node type: Try *) M.pure Constant.None_ (* else *) @@ -500,7 +592,8 @@ Definition process_message : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "execute_code" |), make_list [ @@ -508,7 +601,8 @@ Definition process_message : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -559,22 +653,28 @@ Definition execute_code : Value.t -> Value.t -> M := evm: `ethereum.vm.EVM` Items containing execution specific objects " in - let code := - M.get_field (| M.get_name (| globals, "message" |), "code" |) in - let valid_jump_destinations := + let _ := M.assign_local (| + "code" , + M.get_field (| M.get_name (| globals, "message" |), "code" |) + |) in + let _ := M.assign_local (| + "valid_jump_destinations" , M.call (| M.get_name (| globals, "get_valid_jump_destinations" |), make_list [ M.get_name (| globals, "code" |) ], make_dict [] - |) in - let evm := + |) + |) in + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "Evm" |), make_list [], make_dict [] - |) in + |) + |) in (* At stmt: unsupported node type: Try *) let _ := M.return_ (| M.get_name (| globals, "evm" |) diff --git a/CoqOfPython/ethereum/cancun/vm/memory.v b/CoqOfPython/ethereum/cancun/vm/memory.v index 9b428c0..71fb1d2 100644 --- a/CoqOfPython/ethereum/cancun/vm/memory.v +++ b/CoqOfPython/ethereum/cancun/vm/memory.v @@ -17,11 +17,15 @@ Introduction EVM memory operations. ". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "right_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_right_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "right_pad_zero_bytes". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". Definition memory_write : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/__init__.v index b52e0bf..dbf6f8a 100644 --- a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/__init__.v +++ b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/__init__.v @@ -18,8 +18,8 @@ Addresses of precompiled contracts and mappings to their implementations. ". -Axiom ethereum_cancun_utils_hexadecimal_imports : - AreImported globals "ethereum.cancun.utils.hexadecimal" [ "hex_to_address" ]. +Axiom ethereum_cancun_utils_hexadecimal_imports_hex_to_address : + IsImported globals "ethereum.cancun.utils.hexadecimal" "hex_to_address". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS"; Constant.str "MODEXP_ADDRESS"; Constant.str "ALT_BN128_ADD_ADDRESS"; Constant.str "ALT_BN128_MUL_ADDRESS"; Constant.str "ALT_BN128_PAIRING_CHECK_ADDRESS"; Constant.str "BLAKE2F_ADDRESS"; Constant.str "POINT_EVALUATION_ADDRESS" ] diff --git a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/alt_bn128.v index 206b422..ec05c60 100644 --- a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/alt_bn128.v +++ b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/alt_bn128.v @@ -17,26 +17,42 @@ Introduction Implementation of the ALT_BN128 precompiled contracts. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_alt_bn128_imports : - AreImported globals "ethereum.crypto.alt_bn128" [ "ALT_BN128_CURVE_ORDER"; "ALT_BN128_PRIME"; "BNF"; "BNF2"; "BNF12"; "BNP"; "BNP2"; "pairing" ]. +Axiom ethereum_crypto_alt_bn128_imports_ALT_BN128_CURVE_ORDER : + IsImported globals "ethereum.crypto.alt_bn128" "ALT_BN128_CURVE_ORDER". +Axiom ethereum_crypto_alt_bn128_imports_ALT_BN128_PRIME : + IsImported globals "ethereum.crypto.alt_bn128" "ALT_BN128_PRIME". +Axiom ethereum_crypto_alt_bn128_imports_BNF : + IsImported globals "ethereum.crypto.alt_bn128" "BNF". +Axiom ethereum_crypto_alt_bn128_imports_BNF2 : + IsImported globals "ethereum.crypto.alt_bn128" "BNF2". +Axiom ethereum_crypto_alt_bn128_imports_BNF12 : + IsImported globals "ethereum.crypto.alt_bn128" "BNF12". +Axiom ethereum_crypto_alt_bn128_imports_BNP : + IsImported globals "ethereum.crypto.alt_bn128" "BNP". +Axiom ethereum_crypto_alt_bn128_imports_BNP2 : + IsImported globals "ethereum.crypto.alt_bn128" "BNP2". +Axiom ethereum_crypto_alt_bn128_imports_pairing : + IsImported globals "ethereum.crypto.alt_bn128" "pairing". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_cancun_vm_imports : - AreImported globals "ethereum.cancun.vm" [ "Evm" ]. +Axiom ethereum_cancun_vm_imports_Evm : + IsImported globals "ethereum.cancun.vm" "Evm". -Axiom ethereum_cancun_vm_gas_imports : - AreImported globals "ethereum.cancun.vm.gas" [ "charge_gas" ]. +Axiom ethereum_cancun_vm_gas_imports_charge_gas : + IsImported globals "ethereum.cancun.vm.gas" "charge_gas". -Axiom ethereum_cancun_vm_memory_imports : - AreImported globals "ethereum.cancun.vm.memory" [ "buffer_read" ]. +Axiom ethereum_cancun_vm_memory_imports_buffer_read : + IsImported globals "ethereum.cancun.vm.memory" "buffer_read". -Axiom ethereum_cancun_vm_exceptions_imports : - AreImported globals "ethereum.cancun.vm.exceptions" [ "OutOfGasError" ]. +Axiom ethereum_cancun_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.cancun.vm.exceptions" "OutOfGasError". Definition alt_bn128_add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -49,8 +65,10 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -65,7 +83,8 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := ], make_dict [] |) in - let x0_bytes := + let _ := M.assign_local (| + "x0_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -86,16 +105,20 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let x0_value := + |) + |) in + let _ := M.assign_local (| + "x0_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "x0_bytes" |) ], make_dict [] - |) in - let y0_bytes := + |) + |) in + let _ := M.assign_local (| + "y0_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -116,16 +139,20 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y0_value := + |) + |) in + let _ := M.assign_local (| + "y0_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "y0_bytes" |) ], make_dict [] - |) in - let x1_bytes := + |) + |) in + let _ := M.assign_local (| + "x1_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -146,16 +173,20 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let x1_value := + |) + |) in + let _ := M.assign_local (| + "x1_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "x1_bytes" |) ], make_dict [] - |) in - let y1_bytes := + |) + |) in + let _ := M.assign_local (| + "y1_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -176,15 +207,18 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y1_value := + |) + |) in + let _ := M.assign_local (| + "y1_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "y1_bytes" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "i" |), @@ -212,11 +246,13 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := )) |) in (* At stmt: unsupported node type: Try *) - let p := + let _ := M.assign_local (| + "p" , BinOp.add (| M.get_name (| globals, "p0" |), M.get_name (| globals, "p1" |) - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), BinOp.add (| @@ -245,8 +281,10 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -261,7 +299,8 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := ], make_dict [] |) in - let x0_bytes := + let _ := M.assign_local (| + "x0_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -282,16 +321,20 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let x0_value := + |) + |) in + let _ := M.assign_local (| + "x0_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "x0_bytes" |) ], make_dict [] - |) in - let y0_bytes := + |) + |) in + let _ := M.assign_local (| + "y0_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -312,16 +355,20 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y0_value := + |) + |) in + let _ := M.assign_local (| + "y0_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "y0_bytes" |) ], make_dict [] - |) in - let n := + |) + |) in + let _ := M.assign_local (| + "n" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -348,7 +395,8 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "i" |), @@ -376,14 +424,16 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := )) |) in (* At stmt: unsupported node type: Try *) - let p := + let _ := M.assign_local (| + "p" , M.call (| M.get_field (| M.get_name (| globals, "p0" |), "mul_by" |), make_list [ M.get_name (| globals, "n" |) ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), BinOp.add (| @@ -412,8 +462,10 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -467,14 +519,16 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), make_list [ Constant.int 1 ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "i" |), @@ -495,8 +549,10 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let values := - make_list [] in + let _ := M.assign_local (| + "values" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "j" |), @@ -508,7 +564,8 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -541,7 +598,8 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -644,7 +702,8 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , BinOp.mult (| M.get_name (| globals, "result" |), M.call (| @@ -655,7 +714,8 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/blake2f.v b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/blake2f.v index 5eb8fb4..9f5c33f 100644 --- a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/blake2f.v +++ b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/blake2f.v @@ -17,20 +17,22 @@ Introduction Implementation of the `Blake2` precompiled contract. ". -Axiom ethereum_crypto_blake2_imports : - AreImported globals "ethereum.crypto.blake2" [ "Blake2b" ]. +Axiom ethereum_crypto_blake2_imports_Blake2b : + IsImported globals "ethereum.crypto.blake2" "Blake2b". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_cancun_vm_imports : - AreImported globals "ethereum.cancun.vm" [ "Evm" ]. +Axiom ethereum_cancun_vm_imports_Evm : + IsImported globals "ethereum.cancun.vm" "Evm". -Axiom ethereum_cancun_vm_gas_imports : - AreImported globals "ethereum.cancun.vm.gas" [ "GAS_BLAKE2_PER_ROUND"; "charge_gas" ]. +Axiom ethereum_cancun_vm_gas_imports_GAS_BLAKE2_PER_ROUND : + IsImported globals "ethereum.cancun.vm.gas" "GAS_BLAKE2_PER_ROUND". +Axiom ethereum_cancun_vm_gas_imports_charge_gas : + IsImported globals "ethereum.cancun.vm.gas" "charge_gas". -Axiom ethereum_cancun_vm_exceptions_imports : - AreImported globals "ethereum.cancun.vm.exceptions" [ "InvalidParameter" ]. +Axiom ethereum_cancun_vm_exceptions_imports_InvalidParameter : + IsImported globals "ethereum.cancun.vm.exceptions" "InvalidParameter". Definition blake2f : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -43,8 +45,10 @@ Definition blake2f : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -62,12 +66,14 @@ Definition blake2f : Value.t -> Value.t -> M := ], make_dict [] |) in - let blake2b := + let _ := M.assign_local (| + "blake2b" , M.call (| M.get_name (| globals, "Blake2b" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "rounds" |); M.get_name (| globals, "h" |); M.get_name (| globals, "m" |); M.get_name (| globals, "t_0" |); M.get_name (| globals, "t_1" |); M.get_name (| globals, "f" |) ], M.call (| diff --git a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/ecrecover.v index 9e2966e..e169b9c 100644 --- a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/ecrecover.v @@ -17,26 +17,32 @@ Introduction Implementation of the ECRECOVER precompiled contract. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_crypto_elliptic_curve_imports : - AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. +Axiom ethereum_crypto_elliptic_curve_imports_SECP256K1N : + IsImported globals "ethereum.crypto.elliptic_curve" "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_imports_secp256k1_recover : + IsImported globals "ethereum.crypto.elliptic_curve" "secp256k1_recover". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_left_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "left_pad_zero_bytes". -Axiom ethereum_cancun_vm_imports : - AreImported globals "ethereum.cancun.vm" [ "Evm" ]. +Axiom ethereum_cancun_vm_imports_Evm : + IsImported globals "ethereum.cancun.vm" "Evm". -Axiom ethereum_cancun_vm_gas_imports : - AreImported globals "ethereum.cancun.vm.gas" [ "GAS_ECRECOVER"; "charge_gas" ]. +Axiom ethereum_cancun_vm_gas_imports_GAS_ECRECOVER : + IsImported globals "ethereum.cancun.vm.gas" "GAS_ECRECOVER". +Axiom ethereum_cancun_vm_gas_imports_charge_gas : + IsImported globals "ethereum.cancun.vm.gas" "charge_gas". -Axiom ethereum_cancun_vm_memory_imports : - AreImported globals "ethereum.cancun.vm.memory" [ "buffer_read" ]. +Axiom ethereum_cancun_vm_memory_imports_buffer_read : + IsImported globals "ethereum.cancun.vm.memory" "buffer_read". Definition ecrecover : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -50,8 +56,10 @@ Definition ecrecover : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -60,7 +68,8 @@ Definition ecrecover : Value.t -> Value.t -> M := ], make_dict [] |) in - let message_hash_bytes := + let _ := M.assign_local (| + "message_hash_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -81,16 +90,20 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let message_hash := + |) + |) in + let _ := M.assign_local (| + "message_hash" , M.call (| M.get_name (| globals, "Hash32" |), make_list [ M.get_name (| globals, "message_hash_bytes" |) ], make_dict [] - |) in - let v := + |) + |) in + let _ := M.assign_local (| + "v" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -117,8 +130,10 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let r := + |) + |) in + let _ := M.assign_local (| + "r" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -145,8 +160,10 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let s := + |) + |) in + let _ := M.assign_local (| + "s" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -173,7 +190,8 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -250,7 +268,8 @@ Definition ecrecover : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: Try *) - let address := + let _ := M.assign_local (| + "address" , M.slice (| M.call (| M.get_name (| globals, "keccak256" |), @@ -262,8 +281,10 @@ Definition ecrecover : Value.t -> Value.t -> M := Constant.int 12, Constant.int 32, Constant.None_ - |) in - let padded_address := + |) + |) in + let _ := M.assign_local (| + "padded_address" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -271,7 +292,8 @@ Definition ecrecover : Value.t -> Value.t -> M := Constant.int 32 ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.get_name (| globals, "padded_address" |) diff --git a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/identity.v index 9b7df58..bedd17c 100644 --- a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/identity.v +++ b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/identity.v @@ -17,17 +17,21 @@ Introduction Implementation of the `IDENTITY` precompiled contract. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_cancun_vm_imports : - AreImported globals "ethereum.cancun.vm" [ "Evm" ]. +Axiom ethereum_cancun_vm_imports_Evm : + IsImported globals "ethereum.cancun.vm" "Evm". -Axiom ethereum_cancun_vm_gas_imports : - AreImported globals "ethereum.cancun.vm.gas" [ "GAS_IDENTITY"; "GAS_IDENTITY_WORD"; "charge_gas" ]. +Axiom ethereum_cancun_vm_gas_imports_GAS_IDENTITY : + IsImported globals "ethereum.cancun.vm.gas" "GAS_IDENTITY". +Axiom ethereum_cancun_vm_gas_imports_GAS_IDENTITY_WORD : + IsImported globals "ethereum.cancun.vm.gas" "GAS_IDENTITY_WORD". +Axiom ethereum_cancun_vm_gas_imports_charge_gas : + IsImported globals "ethereum.cancun.vm.gas" "charge_gas". Definition identity : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -40,9 +44,12 @@ Definition identity : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let word_count := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "word_count" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -64,7 +71,8 @@ Definition identity : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ diff --git a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/mapping.v index 0bf721f..e780b97 100644 --- a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/mapping.v +++ b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/mapping.v @@ -17,37 +17,61 @@ Introduction Mapping of precompiled contracts their implementations. ". -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict" ]. - -Axiom ethereum_cancun_fork_types_imports : - AreImported globals "ethereum.cancun.fork_types" [ "Address" ]. - -Axiom ethereum_cancun_vm_precompiled_contracts_imports : - AreImported globals "ethereum.cancun.vm.precompiled_contracts" [ "ALT_BN128_ADD_ADDRESS"; "ALT_BN128_MUL_ADDRESS"; "ALT_BN128_PAIRING_CHECK_ADDRESS"; "BLAKE2F_ADDRESS"; "ECRECOVER_ADDRESS"; "IDENTITY_ADDRESS"; "MODEXP_ADDRESS"; "POINT_EVALUATION_ADDRESS"; "RIPEMD160_ADDRESS"; "SHA256_ADDRESS" ]. - -Axiom ethereum_cancun_vm_precompiled_contracts_alt_bn128_imports : - AreImported globals "ethereum.cancun.vm.precompiled_contracts.alt_bn128" [ "alt_bn128_add"; "alt_bn128_mul"; "alt_bn128_pairing_check" ]. - -Axiom ethereum_cancun_vm_precompiled_contracts_blake2f_imports : - AreImported globals "ethereum.cancun.vm.precompiled_contracts.blake2f" [ "blake2f" ]. - -Axiom ethereum_cancun_vm_precompiled_contracts_ecrecover_imports : - AreImported globals "ethereum.cancun.vm.precompiled_contracts.ecrecover" [ "ecrecover" ]. - -Axiom ethereum_cancun_vm_precompiled_contracts_identity_imports : - AreImported globals "ethereum.cancun.vm.precompiled_contracts.identity" [ "identity" ]. - -Axiom ethereum_cancun_vm_precompiled_contracts_modexp_imports : - AreImported globals "ethereum.cancun.vm.precompiled_contracts.modexp" [ "modexp" ]. - -Axiom ethereum_cancun_vm_precompiled_contracts_point_evaluation_imports : - AreImported globals "ethereum.cancun.vm.precompiled_contracts.point_evaluation" [ "point_evaluation" ]. - -Axiom ethereum_cancun_vm_precompiled_contracts_ripemd160_imports : - AreImported globals "ethereum.cancun.vm.precompiled_contracts.ripemd160" [ "ripemd160" ]. - -Axiom ethereum_cancun_vm_precompiled_contracts_sha256_imports : - AreImported globals "ethereum.cancun.vm.precompiled_contracts.sha256" [ "sha256" ]. +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". + +Axiom ethereum_cancun_fork_types_imports_Address : + IsImported globals "ethereum.cancun.fork_types" "Address". + +Axiom ethereum_cancun_vm_precompiled_contracts_imports_ALT_BN128_ADD_ADDRESS : + IsImported globals "ethereum.cancun.vm.precompiled_contracts" "ALT_BN128_ADD_ADDRESS". +Axiom ethereum_cancun_vm_precompiled_contracts_imports_ALT_BN128_MUL_ADDRESS : + IsImported globals "ethereum.cancun.vm.precompiled_contracts" "ALT_BN128_MUL_ADDRESS". +Axiom ethereum_cancun_vm_precompiled_contracts_imports_ALT_BN128_PAIRING_CHECK_ADDRESS : + IsImported globals "ethereum.cancun.vm.precompiled_contracts" "ALT_BN128_PAIRING_CHECK_ADDRESS". +Axiom ethereum_cancun_vm_precompiled_contracts_imports_BLAKE2F_ADDRESS : + IsImported globals "ethereum.cancun.vm.precompiled_contracts" "BLAKE2F_ADDRESS". +Axiom ethereum_cancun_vm_precompiled_contracts_imports_ECRECOVER_ADDRESS : + IsImported globals "ethereum.cancun.vm.precompiled_contracts" "ECRECOVER_ADDRESS". +Axiom ethereum_cancun_vm_precompiled_contracts_imports_IDENTITY_ADDRESS : + IsImported globals "ethereum.cancun.vm.precompiled_contracts" "IDENTITY_ADDRESS". +Axiom ethereum_cancun_vm_precompiled_contracts_imports_MODEXP_ADDRESS : + IsImported globals "ethereum.cancun.vm.precompiled_contracts" "MODEXP_ADDRESS". +Axiom ethereum_cancun_vm_precompiled_contracts_imports_POINT_EVALUATION_ADDRESS : + IsImported globals "ethereum.cancun.vm.precompiled_contracts" "POINT_EVALUATION_ADDRESS". +Axiom ethereum_cancun_vm_precompiled_contracts_imports_RIPEMD160_ADDRESS : + IsImported globals "ethereum.cancun.vm.precompiled_contracts" "RIPEMD160_ADDRESS". +Axiom ethereum_cancun_vm_precompiled_contracts_imports_SHA256_ADDRESS : + IsImported globals "ethereum.cancun.vm.precompiled_contracts" "SHA256_ADDRESS". + +Axiom ethereum_cancun_vm_precompiled_contracts_alt_bn128_imports_alt_bn128_add : + IsImported globals "ethereum.cancun.vm.precompiled_contracts.alt_bn128" "alt_bn128_add". +Axiom ethereum_cancun_vm_precompiled_contracts_alt_bn128_imports_alt_bn128_mul : + IsImported globals "ethereum.cancun.vm.precompiled_contracts.alt_bn128" "alt_bn128_mul". +Axiom ethereum_cancun_vm_precompiled_contracts_alt_bn128_imports_alt_bn128_pairing_check : + IsImported globals "ethereum.cancun.vm.precompiled_contracts.alt_bn128" "alt_bn128_pairing_check". + +Axiom ethereum_cancun_vm_precompiled_contracts_blake2f_imports_blake2f : + IsImported globals "ethereum.cancun.vm.precompiled_contracts.blake2f" "blake2f". + +Axiom ethereum_cancun_vm_precompiled_contracts_ecrecover_imports_ecrecover : + IsImported globals "ethereum.cancun.vm.precompiled_contracts.ecrecover" "ecrecover". + +Axiom ethereum_cancun_vm_precompiled_contracts_identity_imports_identity : + IsImported globals "ethereum.cancun.vm.precompiled_contracts.identity" "identity". + +Axiom ethereum_cancun_vm_precompiled_contracts_modexp_imports_modexp : + IsImported globals "ethereum.cancun.vm.precompiled_contracts.modexp" "modexp". + +Axiom ethereum_cancun_vm_precompiled_contracts_point_evaluation_imports_point_evaluation : + IsImported globals "ethereum.cancun.vm.precompiled_contracts.point_evaluation" "point_evaluation". + +Axiom ethereum_cancun_vm_precompiled_contracts_ripemd160_imports_ripemd160 : + IsImported globals "ethereum.cancun.vm.precompiled_contracts.ripemd160" "ripemd160". + +Axiom ethereum_cancun_vm_precompiled_contracts_sha256_imports_sha256 : + IsImported globals "ethereum.cancun.vm.precompiled_contracts.sha256" "sha256". (* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/modexp.v index 5480d95..ec4e35a 100644 --- a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/modexp.v +++ b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/modexp.v @@ -17,17 +17,21 @@ Introduction Implementation of the `MODEXP` precompiled contract. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_cancun_vm_imports : - AreImported globals "ethereum.cancun.vm" [ "Evm" ]. +Axiom ethereum_cancun_vm_imports_Evm : + IsImported globals "ethereum.cancun.vm" "Evm". -Axiom ethereum_cancun_vm_gas_imports : - AreImported globals "ethereum.cancun.vm.gas" [ "charge_gas" ]. +Axiom ethereum_cancun_vm_gas_imports_charge_gas : + IsImported globals "ethereum.cancun.vm.gas" "charge_gas". -Axiom ethereum_cancun_vm_memory_imports : - AreImported globals "ethereum.cancun.vm.memory" [ "buffer_read" ]. +Axiom ethereum_cancun_vm_memory_imports_buffer_read : + IsImported globals "ethereum.cancun.vm.memory" "buffer_read". Definition GQUADDIVISOR : Value.t := M.run ltac:(M.monadic ( Constant.int 3 @@ -40,9 +44,12 @@ Definition modexp : Value.t -> Value.t -> M := Calculates `(base**exp) % modulus` for arbitrary sized `base`, `exp` and. `modulus`. The return value is the same length as the modulus. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let base_length := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "base_length" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -69,8 +76,10 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exp_length := + |) + |) in + let _ := M.assign_local (| + "exp_length" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -97,8 +106,10 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let modulus_length := + |) + |) in + let _ := M.assign_local (| + "modulus_length" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -125,8 +136,10 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exp_start := + |) + |) in + let _ := M.assign_local (| + "exp_start" , BinOp.add (| M.call (| M.get_name (| globals, "U256" |), @@ -136,8 +149,10 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |), M.get_name (| globals, "base_length" |) - |) in - let exp_head := + |) + |) in + let _ := M.assign_local (| + "exp_head" , M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ @@ -165,7 +180,8 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -216,7 +232,8 @@ Definition modexp : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let base := + let _ := M.assign_local (| + "base" , M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ @@ -237,8 +254,10 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exp := + |) + |) in + let _ := M.assign_local (| + "exp" , M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ @@ -253,13 +272,17 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let modulus_start := + |) + |) in + let _ := M.assign_local (| + "modulus_start" , BinOp.add (| M.get_name (| globals, "exp_start" |), M.get_name (| globals, "exp_length" |) - |) in - let modulus := + |) + |) in + let _ := M.assign_local (| + "modulus" , M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ @@ -274,7 +297,8 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -350,7 +374,8 @@ Definition complexity : Value.t -> Value.t -> M := complexity : `Uint` Complexity of performing the operation. " in - let max_length := + let _ := M.assign_local (| + "max_length" , M.call (| M.get_name (| globals, "max" |), make_list [ @@ -370,15 +395,18 @@ Definition complexity : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| BinOp.add (| M.get_name (| globals, "max_length" |), Constant.int 7 |), Constant.int 8 - |) in + |) + |) in let _ := M.return_ (| BinOp.pow (| M.get_name (| globals, "words" |), @@ -427,14 +455,16 @@ Definition iterations : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let count := + let _ := M.assign_local (| + "count" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -447,7 +477,8 @@ Definition iterations : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let bit_length := + let _ := M.assign_local (| + "bit_length" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -458,7 +489,8 @@ Definition iterations : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -468,20 +500,25 @@ Definition iterations : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let bit_length := BinOp.sub + let _ := M.assign_op_local (| + BinOp.sub, + "bit_length", Constant.int 1 - Constant.int 1 in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let count := - M.get_name (| globals, "bit_length" |) in + let _ := M.assign_local (| + "count" , + M.get_name (| globals, "bit_length" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let length_part := + let _ := M.assign_local (| + "length_part" , BinOp.mult (| Constant.int 8, BinOp.sub (| @@ -494,8 +531,10 @@ Definition iterations : Value.t -> Value.t -> M := |), Constant.int 32 |) - |) in - let bits_part := + |) + |) in + let _ := M.assign_local (| + "bits_part" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -506,7 +545,8 @@ Definition iterations : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -516,19 +556,23 @@ Definition iterations : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let bits_part := BinOp.sub + let _ := M.assign_op_local (| + BinOp.sub, + "bits_part", Constant.int 1 - Constant.int 1 in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let count := + let _ := M.assign_local (| + "count" , BinOp.add (| M.get_name (| globals, "length_part" |), M.get_name (| globals, "bits_part" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -579,7 +623,8 @@ Definition gas_cost : Value.t -> Value.t -> M := gas_cost : `Uint` Gas required for performing the operation. " in - let multiplication_complexity := + let _ := M.assign_local (| + "multiplication_complexity" , M.call (| M.get_name (| globals, "complexity" |), make_list [ @@ -587,8 +632,10 @@ Definition gas_cost : Value.t -> Value.t -> M := M.get_name (| globals, "modulus_length" |) ], make_dict [] - |) in - let iteration_count := + |) + |) in + let _ := M.assign_local (| + "iteration_count" , M.call (| M.get_name (| globals, "iterations" |), make_list [ @@ -596,15 +643,20 @@ Definition gas_cost : Value.t -> Value.t -> M := M.get_name (| globals, "exponent_head" |) ], make_dict [] - |) in - let cost := + |) + |) in + let _ := M.assign_local (| + "cost" , BinOp.mult (| M.get_name (| globals, "multiplication_complexity" |), M.get_name (| globals, "iteration_count" |) - |) in - let cost := BinOp.floor_div + |) + |) in + let _ := M.assign_op_local (| + BinOp.floor_div, + "cost", M.get_name (| globals, "GQUADDIVISOR" |) - M.get_name (| globals, "GQUADDIVISOR" |) in + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "max" |), diff --git a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/point_evaluation.v b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/point_evaluation.v index a243f3f..4b6a5a2 100644 --- a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/point_evaluation.v +++ b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/point_evaluation.v @@ -17,23 +17,31 @@ Introduction Implementation of the POINT EVALUATION precompiled contract. ". -Axiom eth2spec_deneb_mainnet_imports : - AreImported globals "eth2spec.deneb.mainnet" [ "KZGCommitment"; "kzg_commitment_to_versioned_hash"; "verify_kzg_proof" ]. +Axiom eth2spec_deneb_mainnet_imports_KZGCommitment : + IsImported globals "eth2spec.deneb.mainnet" "KZGCommitment". +Axiom eth2spec_deneb_mainnet_imports_kzg_commitment_to_versioned_hash : + IsImported globals "eth2spec.deneb.mainnet" "kzg_commitment_to_versioned_hash". +Axiom eth2spec_deneb_mainnet_imports_verify_kzg_proof : + IsImported globals "eth2spec.deneb.mainnet" "verify_kzg_proof". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_cancun_vm_imports : - AreImported globals "ethereum.cancun.vm" [ "Evm" ]. +Axiom ethereum_cancun_vm_imports_Evm : + IsImported globals "ethereum.cancun.vm" "Evm". -Axiom ethereum_cancun_vm_exceptions_imports : - AreImported globals "ethereum.cancun.vm.exceptions" [ "KZGProofError" ]. +Axiom ethereum_cancun_vm_exceptions_imports_KZGProofError : + IsImported globals "ethereum.cancun.vm.exceptions" "KZGProofError". -Axiom ethereum_cancun_vm_gas_imports : - AreImported globals "ethereum.cancun.vm.gas" [ "GAS_POINT_EVALUATION"; "charge_gas" ]. +Axiom ethereum_cancun_vm_gas_imports_GAS_POINT_EVALUATION : + IsImported globals "ethereum.cancun.vm.gas" "GAS_POINT_EVALUATION". +Axiom ethereum_cancun_vm_gas_imports_charge_gas : + IsImported globals "ethereum.cancun.vm.gas" "charge_gas". Definition FIELD_ELEMENTS_PER_BLOB : Value.t := M.run ltac:(M.monadic ( Constant.int 4096 @@ -60,8 +68,10 @@ Definition point_evaluation : Value.t -> Value.t -> M := The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -79,28 +89,35 @@ Definition point_evaluation : Value.t -> Value.t -> M := ], make_dict [] |) in - let versioned_hash := + let _ := M.assign_local (| + "versioned_hash" , M.slice (| M.get_name (| globals, "data" |), Constant.None_, Constant.int 32, Constant.None_ - |) in - let z := + |) + |) in + let _ := M.assign_local (| + "z" , M.slice (| M.get_name (| globals, "data" |), Constant.int 32, Constant.int 64, Constant.None_ - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.slice (| M.get_name (| globals, "data" |), Constant.int 64, Constant.int 96, Constant.None_ - |) in - let commitment := + |) + |) in + let _ := M.assign_local (| + "commitment" , M.call (| M.get_name (| globals, "KZGCommitment" |), make_list [ @@ -112,14 +129,17 @@ Definition point_evaluation : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let proof := + |) + |) in + let _ := M.assign_local (| + "proof" , M.slice (| M.get_name (| globals, "data" |), Constant.int 144, Constant.int 192, Constant.None_ - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ diff --git a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/ripemd160.v index ecb3e96..18c8614 100644 --- a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/ripemd160.v +++ b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/ripemd160.v @@ -19,20 +19,24 @@ Implementation of the `RIPEMD160` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_left_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "left_pad_zero_bytes". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_cancun_vm_imports : - AreImported globals "ethereum.cancun.vm" [ "Evm" ]. +Axiom ethereum_cancun_vm_imports_Evm : + IsImported globals "ethereum.cancun.vm" "Evm". -Axiom ethereum_cancun_vm_gas_imports : - AreImported globals "ethereum.cancun.vm.gas" [ "GAS_RIPEMD160"; "GAS_RIPEMD160_WORD"; "charge_gas" ]. +Axiom ethereum_cancun_vm_gas_imports_GAS_RIPEMD160 : + IsImported globals "ethereum.cancun.vm.gas" "GAS_RIPEMD160". +Axiom ethereum_cancun_vm_gas_imports_GAS_RIPEMD160_WORD : + IsImported globals "ethereum.cancun.vm.gas" "GAS_RIPEMD160_WORD". +Axiom ethereum_cancun_vm_gas_imports_charge_gas : + IsImported globals "ethereum.cancun.vm.gas" "charge_gas". Definition ripemd160 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,9 +49,12 @@ Definition ripemd160 : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let word_count := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "word_count" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -69,7 +76,8 @@ Definition ripemd160 : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -84,7 +92,8 @@ Definition ripemd160 : Value.t -> Value.t -> M := ], make_dict [] |) in - let hash_bytes := + let _ := M.assign_local (| + "hash_bytes" , M.call (| M.get_field (| M.call (| M.get_field (| M.get_name (| globals, "hashlib" |), "new" |), @@ -96,8 +105,10 @@ Definition ripemd160 : Value.t -> Value.t -> M := |), "digest" |), make_list [], make_dict [] - |) in - let padded_hash := + |) + |) in + let _ := M.assign_local (| + "padded_hash" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -105,7 +116,8 @@ Definition ripemd160 : Value.t -> Value.t -> M := Constant.int 32 ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.get_name (| globals, "padded_hash" |) diff --git a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/sha256.v index 14c6290..fe7ed42 100644 --- a/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/sha256.v +++ b/CoqOfPython/ethereum/cancun/vm/precompiled_contracts/sha256.v @@ -19,17 +19,21 @@ Implementation of the `SHA256` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_cancun_vm_imports : - AreImported globals "ethereum.cancun.vm" [ "Evm" ]. +Axiom ethereum_cancun_vm_imports_Evm : + IsImported globals "ethereum.cancun.vm" "Evm". -Axiom ethereum_cancun_vm_gas_imports : - AreImported globals "ethereum.cancun.vm.gas" [ "GAS_SHA256"; "GAS_SHA256_WORD"; "charge_gas" ]. +Axiom ethereum_cancun_vm_gas_imports_GAS_SHA256 : + IsImported globals "ethereum.cancun.vm.gas" "GAS_SHA256". +Axiom ethereum_cancun_vm_gas_imports_GAS_SHA256_WORD : + IsImported globals "ethereum.cancun.vm.gas" "GAS_SHA256_WORD". +Axiom ethereum_cancun_vm_gas_imports_charge_gas : + IsImported globals "ethereum.cancun.vm.gas" "charge_gas". Definition sha256 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,9 +46,12 @@ Definition sha256 : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let word_count := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "word_count" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -66,7 +73,8 @@ Definition sha256 : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ diff --git a/CoqOfPython/ethereum/cancun/vm/runtime.v b/CoqOfPython/ethereum/cancun/vm/runtime.v index 6ec53e6..5c08753 100644 --- a/CoqOfPython/ethereum/cancun/vm/runtime.v +++ b/CoqOfPython/ethereum/cancun/vm/runtime.v @@ -17,14 +17,14 @@ Introduction Runtime related operations used while executing EVM code. ". -Axiom typing_imports : - AreImported globals "typing" [ "Set" ]. +Axiom typing_imports_Set : + IsImported globals "typing" "Set". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_cancun_vm_instructions_imports : - AreImported globals "ethereum.cancun.vm.instructions" [ "Ops" ]. +Axiom ethereum_cancun_vm_instructions_imports_Ops : + IsImported globals "ethereum.cancun.vm.instructions" "Ops". Definition get_valid_jump_destinations : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -50,20 +50,24 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := valid_jump_destinations: `Set[Uint]` The set of valid jump destinations in the code. " in - let valid_jump_destinations := + let _ := M.assign_local (| + "valid_jump_destinations" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let pc := + |) + |) in + let _ := M.assign_local (| + "pc" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in let _ := M.while (| Compare.lt (| @@ -114,17 +118,21 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let push_data_size := + let _ := M.assign_local (| + "push_data_size" , BinOp.add (| BinOp.sub (| M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) |), Constant.int 1 - |) in - let pc := BinOp.add + |) + |) in + let _ := M.assign_op_local (| + BinOp.add, + "pc", M.get_name (| globals, "push_data_size" |) - M.get_name (| globals, "push_data_size" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -132,9 +140,11 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - let pc := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "pc", Constant.int 1 - Constant.int 1 in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/cancun/vm/stack.v b/CoqOfPython/ethereum/cancun/vm/stack.v index 7af5c14..8c8a63b 100644 --- a/CoqOfPython/ethereum/cancun/vm/stack.v +++ b/CoqOfPython/ethereum/cancun/vm/stack.v @@ -17,14 +17,16 @@ Introduction Implementation of the stack operators for the EVM. ". -Axiom typing_imports : - AreImported globals "typing" [ "List" ]. +Axiom typing_imports_List : + IsImported globals "typing" "List". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_cancun_vm_exceptions_imports : - AreImported globals "ethereum.cancun.vm.exceptions" [ "StackOverflowError"; "StackUnderflowError" ]. +Axiom ethereum_cancun_vm_exceptions_imports_StackOverflowError : + IsImported globals "ethereum.cancun.vm.exceptions" "StackOverflowError". +Axiom ethereum_cancun_vm_exceptions_imports_StackUnderflowError : + IsImported globals "ethereum.cancun.vm.exceptions" "StackUnderflowError". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/constantinople/__init__.v b/CoqOfPython/ethereum/constantinople/__init__.v index 78ad716..4727e2a 100644 --- a/CoqOfPython/ethereum/constantinople/__init__.v +++ b/CoqOfPython/ethereum/constantinople/__init__.v @@ -9,8 +9,8 @@ and introduces new EVM instructions for logical shifts, counterfactual contract deployment, and computing bytecode hashes. ". -Axiom ethereum_fork_criteria_imports : - AreImported globals "ethereum.fork_criteria" [ "ByBlockNumber" ]. +Axiom ethereum_fork_criteria_imports_ByBlockNumber : + IsImported globals "ethereum.fork_criteria" "ByBlockNumber". Definition FORK_CRITERIA : Value.t := M.run ltac:(M.monadic ( M.call (| diff --git a/CoqOfPython/ethereum/constantinople/blocks.v b/CoqOfPython/ethereum/constantinople/blocks.v index 3967b31..e6c6eb3 100644 --- a/CoqOfPython/ethereum/constantinople/blocks.v +++ b/CoqOfPython/ethereum/constantinople/blocks.v @@ -14,23 +14,37 @@ history of all state transitions that have happened since the genesis of the chain. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Tuple" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes8"; "Bytes32"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. - -Axiom ethereum_constantinople_fork_types_imports : - AreImported globals "ethereum.constantinople.fork_types" [ "Address"; "Bloom"; "Root" ]. - -Axiom ethereum_constantinople_transactions_imports : - AreImported globals "ethereum.constantinople.transactions" [ "Transaction" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes8 : + IsImported globals "ethereum.base_types" "Bytes8". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". + +Axiom ethereum_constantinople_fork_types_imports_Address : + IsImported globals "ethereum.constantinople.fork_types" "Address". +Axiom ethereum_constantinople_fork_types_imports_Bloom : + IsImported globals "ethereum.constantinople.fork_types" "Bloom". +Axiom ethereum_constantinople_fork_types_imports_Root : + IsImported globals "ethereum.constantinople.fork_types" "Root". + +Axiom ethereum_constantinople_transactions_imports_Transaction : + IsImported globals "ethereum.constantinople.transactions" "Transaction". Definition Header : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/constantinople/bloom.v b/CoqOfPython/ethereum/constantinople/bloom.v index 58de453..a432ffc 100644 --- a/CoqOfPython/ethereum/constantinople/bloom.v +++ b/CoqOfPython/ethereum/constantinople/bloom.v @@ -21,20 +21,20 @@ for efficient searching of logs by address and/or topic, by rapidly eliminating blocks and receipts from their search. ". -Axiom typing_imports : - AreImported globals "typing" [ "Tuple" ]. +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_constantinople_blocks_imports : - AreImported globals "ethereum.constantinople.blocks" [ "Log" ]. +Axiom ethereum_constantinople_blocks_imports_Log : + IsImported globals "ethereum.constantinople.blocks" "Log". -Axiom ethereum_constantinople_fork_types_imports : - AreImported globals "ethereum.constantinople.fork_types" [ "Bloom" ]. +Axiom ethereum_constantinople_fork_types_imports_Bloom : + IsImported globals "ethereum.constantinople.fork_types" "Bloom". Definition add_to_bloom : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -53,20 +53,23 @@ Definition add_to_bloom : Value.t -> Value.t -> M := bloom_entry : An entry which is to be added to bloom filter. " in - let hash := + let _ := M.assign_local (| + "hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "bloom_entry" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "idx" |), make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ], ltac:(M.monadic ( - let bit_to_set := + let _ := M.assign_local (| + "bit_to_set" , BinOp.bit_and (| M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), @@ -84,18 +87,24 @@ Definition add_to_bloom : Value.t -> Value.t -> M := make_dict [] |), Constant.int 2047 - |) in - let bit_index := + |) + |) in + let _ := M.assign_local (| + "bit_index" , BinOp.sub (| Constant.int 2047, M.get_name (| globals, "bit_to_set" |) - |) in - let byte_index := + |) + |) in + let _ := M.assign_local (| + "byte_index" , BinOp.floor_div (| M.get_name (| globals, "bit_index" |), Constant.int 8 - |) in - let bit_value := + |) + |) in + let _ := M.assign_local (| + "bit_value" , BinOp.l_shift (| Constant.int 1, BinOp.sub (| @@ -105,7 +114,8 @@ Definition add_to_bloom : Value.t -> Value.t -> M := Constant.int 8 |) |) - |) in + |) + |) in let _ := M.assign (| M.get_subscript (| M.get_name (| globals, "bloom" |), diff --git a/CoqOfPython/ethereum/constantinople/fork.v b/CoqOfPython/ethereum/constantinople/fork.v index c879a88..06668fb 100644 --- a/CoqOfPython/ethereum/constantinople/fork.v +++ b/CoqOfPython/ethereum/constantinople/fork.v @@ -17,62 +17,120 @@ Introduction Entry point for the Ethereum specification. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Bytes0" ]. - -Axiom ethereum_crypto_elliptic_curve_imports : - AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. - -Axiom ethereum_ethash_imports : - AreImported globals "ethereum.ethash" [ "dataset_size"; "generate_cache"; "hashimoto_light" ]. - -Axiom ethereum_exceptions_imports : - AreImported globals "ethereum.exceptions" [ "InvalidBlock" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U64"; "U256"; "U256_CEIL_VALUE"; "Bytes"; "Uint" ]. - -Axiom ethereum_constantinople_imports : - AreImported globals "ethereum.constantinople" [ "vm" ]. - -Axiom ethereum_constantinople_blocks_imports : - AreImported globals "ethereum.constantinople.blocks" [ "Block"; "Header"; "Log"; "Receipt" ]. - -Axiom ethereum_constantinople_bloom_imports : - AreImported globals "ethereum.constantinople.bloom" [ "logs_bloom" ]. - -Axiom ethereum_constantinople_fork_types_imports : - AreImported globals "ethereum.constantinople.fork_types" [ "Address"; "Bloom"; "Root" ]. - -Axiom ethereum_constantinople_state_imports : - AreImported globals "ethereum.constantinople.state" [ "State"; "account_exists_and_is_empty"; "create_ether"; "destroy_account"; "get_account"; "increment_nonce"; "set_account_balance"; "state_root" ]. - -Axiom ethereum_constantinople_transactions_imports : - AreImported globals "ethereum.constantinople.transactions" [ "TX_BASE_COST"; "TX_CREATE_COST"; "TX_DATA_COST_PER_NON_ZERO"; "TX_DATA_COST_PER_ZERO"; "Transaction" ]. - -Axiom ethereum_constantinople_trie_imports : - AreImported globals "ethereum.constantinople.trie" [ "Trie"; "root"; "trie_set" ]. - -Axiom ethereum_constantinople_utils_message_imports : - AreImported globals "ethereum.constantinople.utils.message" [ "prepare_message" ]. - -Axiom ethereum_constantinople_vm_interpreter_imports : - AreImported globals "ethereum.constantinople.vm.interpreter" [ "process_message_call" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". + +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". + +Axiom ethereum_crypto_elliptic_curve_imports_SECP256K1N : + IsImported globals "ethereum.crypto.elliptic_curve" "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_imports_secp256k1_recover : + IsImported globals "ethereum.crypto.elliptic_curve" "secp256k1_recover". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". + +Axiom ethereum_ethash_imports_dataset_size : + IsImported globals "ethereum.ethash" "dataset_size". +Axiom ethereum_ethash_imports_generate_cache : + IsImported globals "ethereum.ethash" "generate_cache". +Axiom ethereum_ethash_imports_hashimoto_light : + IsImported globals "ethereum.ethash" "hashimoto_light". + +Axiom ethereum_exceptions_imports_InvalidBlock : + IsImported globals "ethereum.exceptions" "InvalidBlock". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U64 : + IsImported globals "ethereum.base_types" "U64". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_U256_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U256_CEIL_VALUE". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_constantinople_imports_vm : + IsImported globals "ethereum.constantinople" "vm". + +Axiom ethereum_constantinople_blocks_imports_Block : + IsImported globals "ethereum.constantinople.blocks" "Block". +Axiom ethereum_constantinople_blocks_imports_Header : + IsImported globals "ethereum.constantinople.blocks" "Header". +Axiom ethereum_constantinople_blocks_imports_Log : + IsImported globals "ethereum.constantinople.blocks" "Log". +Axiom ethereum_constantinople_blocks_imports_Receipt : + IsImported globals "ethereum.constantinople.blocks" "Receipt". + +Axiom ethereum_constantinople_bloom_imports_logs_bloom : + IsImported globals "ethereum.constantinople.bloom" "logs_bloom". + +Axiom ethereum_constantinople_fork_types_imports_Address : + IsImported globals "ethereum.constantinople.fork_types" "Address". +Axiom ethereum_constantinople_fork_types_imports_Bloom : + IsImported globals "ethereum.constantinople.fork_types" "Bloom". +Axiom ethereum_constantinople_fork_types_imports_Root : + IsImported globals "ethereum.constantinople.fork_types" "Root". + +Axiom ethereum_constantinople_state_imports_State : + IsImported globals "ethereum.constantinople.state" "State". +Axiom ethereum_constantinople_state_imports_account_exists_and_is_empty : + IsImported globals "ethereum.constantinople.state" "account_exists_and_is_empty". +Axiom ethereum_constantinople_state_imports_create_ether : + IsImported globals "ethereum.constantinople.state" "create_ether". +Axiom ethereum_constantinople_state_imports_destroy_account : + IsImported globals "ethereum.constantinople.state" "destroy_account". +Axiom ethereum_constantinople_state_imports_get_account : + IsImported globals "ethereum.constantinople.state" "get_account". +Axiom ethereum_constantinople_state_imports_increment_nonce : + IsImported globals "ethereum.constantinople.state" "increment_nonce". +Axiom ethereum_constantinople_state_imports_set_account_balance : + IsImported globals "ethereum.constantinople.state" "set_account_balance". +Axiom ethereum_constantinople_state_imports_state_root : + IsImported globals "ethereum.constantinople.state" "state_root". + +Axiom ethereum_constantinople_transactions_imports_TX_BASE_COST : + IsImported globals "ethereum.constantinople.transactions" "TX_BASE_COST". +Axiom ethereum_constantinople_transactions_imports_TX_CREATE_COST : + IsImported globals "ethereum.constantinople.transactions" "TX_CREATE_COST". +Axiom ethereum_constantinople_transactions_imports_TX_DATA_COST_PER_NON_ZERO : + IsImported globals "ethereum.constantinople.transactions" "TX_DATA_COST_PER_NON_ZERO". +Axiom ethereum_constantinople_transactions_imports_TX_DATA_COST_PER_ZERO : + IsImported globals "ethereum.constantinople.transactions" "TX_DATA_COST_PER_ZERO". +Axiom ethereum_constantinople_transactions_imports_Transaction : + IsImported globals "ethereum.constantinople.transactions" "Transaction". + +Axiom ethereum_constantinople_trie_imports_Trie : + IsImported globals "ethereum.constantinople.trie" "Trie". +Axiom ethereum_constantinople_trie_imports_root : + IsImported globals "ethereum.constantinople.trie" "root". +Axiom ethereum_constantinople_trie_imports_trie_set : + IsImported globals "ethereum.constantinople.trie" "trie_set". + +Axiom ethereum_constantinople_utils_message_imports_prepare_message : + IsImported globals "ethereum.constantinople.utils.message" "prepare_message". + +Axiom ethereum_constantinople_vm_interpreter_imports_process_message_call : + IsImported globals "ethereum.constantinople.vm.interpreter" "process_message_call". Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -190,13 +248,15 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := recent_block_hashes : `List[Hash32]` Hashes of the recent 256 blocks in order of increasing block number. " in - let recent_blocks := + let _ := M.assign_local (| + "recent_blocks" , M.slice (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |), Constant.None_, Constant.None_ - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -220,15 +280,19 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let recent_block_hashes := - make_list [] in + let _ := M.assign_local (| + "recent_block_hashes" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "block" |), M.get_name (| globals, "recent_blocks" |), ltac:(M.monadic ( - let prev_block_hash := - M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in + let _ := M.assign_local (| + "prev_block_hash" , + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), make_list [ @@ -242,7 +306,8 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let most_recent_block_hash := + let _ := M.assign_local (| + "most_recent_block_hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -258,7 +323,8 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), make_list [ @@ -295,11 +361,13 @@ Definition state_transition : Value.t -> Value.t -> M := block : Block to apply to `chain`. " in - let parent_header := + let _ := M.assign_local (| + "parent_header" , M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 1 |) - |), "header" |) in + |), "header" |) + |) in let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ @@ -317,7 +385,8 @@ Definition state_transition : Value.t -> Value.t -> M := ], make_dict [] |) in - let apply_body_output := + let _ := M.assign_local (| + "apply_body_output" , M.call (| M.get_name (| globals, "apply_body" |), make_list [ @@ -339,7 +408,8 @@ Definition state_transition : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "chain" |), "chain_id" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -453,11 +523,13 @@ Definition validate_header : Value.t -> Value.t -> M := parent_header : Parent Header of the header to check for correctness " in - let parent_has_ommers := + let _ := M.assign_local (| + "parent_has_ommers" , Compare.not_eq (| M.get_field (| M.get_name (| globals, "parent_header" |), "ommers_hash" |), M.get_name (| globals, "EMPTY_OMMER_HASH" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -515,7 +587,8 @@ Definition validate_header : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_difficulty := + let _ := M.assign_local (| + "block_difficulty" , M.call (| M.get_name (| globals, "calculate_block_difficulty" |), make_list [ @@ -526,7 +599,8 @@ Definition validate_header : Value.t -> Value.t -> M := M.get_name (| globals, "parent_has_ommers" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -538,7 +612,8 @@ Definition validate_header : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_parent_hash := + let _ := M.assign_local (| + "block_parent_hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -551,7 +626,8 @@ Definition validate_header : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -597,7 +673,8 @@ Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := hash : `Hash32` The PoW valid rlp hash of the passed in header. " in - let header_data_without_pow_artefacts := + let _ := M.assign_local (| + "header_data_without_pow_artefacts" , make_list [ M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |); M.get_field (| M.get_name (| globals, "header" |), "ommers_hash" |); @@ -612,7 +689,8 @@ Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "header" |), "gas_used" |); M.get_field (| M.get_name (| globals, "header" |), "timestamp" |); M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) - ] in + ] + |) in let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), @@ -641,22 +719,26 @@ Definition validate_proof_of_work : Value.t -> Value.t -> M := header : Header of interest. " in - let header_hash := + let _ := M.assign_local (| + "header_hash" , M.call (| M.get_name (| globals, "generate_header_hash_for_pow" |), make_list [ M.get_name (| globals, "header" |) ], make_dict [] - |) in - let cache := + |) + |) in + let _ := M.assign_local (| + "cache" , M.call (| M.get_name (| globals, "generate_cache" |), make_list [ M.get_field (| M.get_name (| globals, "header" |), "number" |) ], make_dict [] - |) in + |) + |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "mix_digest" |); M.get_name (| globals, "result" |) ], M.call (| @@ -745,7 +827,8 @@ Definition check_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_address := + let _ := M.assign_local (| + "sender_address" , M.call (| M.get_name (| globals, "recover_sender" |), make_list [ @@ -753,7 +836,8 @@ Definition check_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "tx" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "sender_address" |) |) in @@ -782,12 +866,14 @@ Definition make_receipt : Value.t -> Value.t -> M := receipt : The receipt for the transaction. " in - let receipt := + let _ := M.assign_local (| + "receipt" , M.call (| M.get_name (| globals, "Receipt" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "receipt" |) |) in @@ -846,8 +932,10 @@ Definition apply_body : Value.t -> Value.t -> M := apply_body_output : `ApplyBodyOutput` Output of applying the block body to the state. " in - let gas_available := - M.get_name (| globals, "block_gas_limit" |) in + let _ := M.assign_local (| + "gas_available" , + M.get_name (| globals, "block_gas_limit" |) + |) in (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) @@ -883,7 +971,8 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_address := + let _ := M.assign_local (| + "sender_address" , M.call (| M.get_name (| globals, "check_transaction" |), make_list [ @@ -892,13 +981,16 @@ Definition apply_body : Value.t -> Value.t -> M := M.get_name (| globals, "chain_id" |) ], make_dict [] - |) in - let env := + |) + |) in + let _ := M.assign_local (| + "env" , M.call (| M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |); M.get_name (| globals, "error" |) ], M.call (| @@ -910,10 +1002,13 @@ Definition apply_body : Value.t -> Value.t -> M := make_dict [] |) |) in - let gas_available := BinOp.sub + let _ := M.assign_op_local (| + BinOp.sub, + "gas_available", M.get_name (| globals, "gas_used" |) - M.get_name (| globals, "gas_used" |) in - let receipt := + |) in + let _ := M.assign_local (| + "receipt" , M.call (| M.get_name (| globals, "make_receipt" |), make_list [ @@ -926,7 +1021,8 @@ Definition apply_body : Value.t -> Value.t -> M := M.get_name (| globals, "logs" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ @@ -948,9 +1044,11 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_logs := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "block_logs", M.get_name (| globals, "logs" |) - M.get_name (| globals, "logs" |) in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -967,19 +1065,23 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_gas_used := + let _ := M.assign_local (| + "block_gas_used" , BinOp.sub (| M.get_name (| globals, "block_gas_limit" |), M.get_name (| globals, "gas_available" |) - |) in - let block_logs_bloom := + |) + |) in + let _ := M.assign_local (| + "block_logs_bloom" , M.call (| M.get_name (| globals, "logs_bloom" |), make_list [ M.get_name (| globals, "block_logs" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ApplyBodyOutput" |), @@ -1037,14 +1139,16 @@ Definition validate_ommers : Value.t -> Value.t -> M := chain : History and current state. " in - let block_hash := + let _ := M.assign_local (| + "block_hash" , M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), make_list [ M.get_name (| globals, "block_header" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1109,7 +1213,8 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_parent_header := + let _ := M.assign_local (| + "ommer_parent_header" , M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), BinOp.sub (| @@ -1119,7 +1224,8 @@ Definition validate_ommers : Value.t -> Value.t -> M := |) |), Constant.int 1 |) - |), "header" |) in + |), "header" |) + |) in let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ @@ -1151,8 +1257,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommers_hashes := - Constant.str "(* At expr: unsupported node type: ListComp *)" in + let _ := M.assign_local (| + "ommers_hashes" , + Constant.str "(* At expr: unsupported node type: ListComp *)" + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1182,7 +1290,8 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let recent_canonical_blocks := + let _ := M.assign_local (| + "recent_canonical_blocks" , M.slice (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| BinOp.add (| @@ -1191,23 +1300,28 @@ Definition validate_ommers : Value.t -> Value.t -> M := |) |), Constant.None_, Constant.None_ - |) in - let recent_canonical_block_hashes := - Constant.str "(* At expr: unsupported node type: SetComp *)" in + |) + |) in + let _ := M.assign_local (| + "recent_canonical_block_hashes" , + Constant.str "(* At expr: unsupported node type: SetComp *)" + |) in (* At stmt: unsupported node type: AnnAssign *) let _ := M.for_ (| M.get_name (| globals, "block" |), M.get_name (| globals, "recent_canonical_blocks" |), ltac:(M.monadic ( - let recent_ommers_hashes := + let _ := M.assign_local (| + "recent_ommers_hashes" , M.call (| M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), make_list [ Constant.str "(* At expr: unsupported node type: SetComp *)" ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -1225,11 +1339,13 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let ommer_hash := + let _ := M.assign_local (| + "ommer_hash" , M.get_subscript (| M.get_name (| globals, "ommers_hashes" |), M.get_name (| globals, "ommer_index" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1263,11 +1379,13 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_age := + let _ := M.assign_local (| + "ommer_age" , BinOp.sub (| M.get_field (| M.get_name (| globals, "block_header" |), "number" |), M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1345,7 +1463,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := ommers : List of ommers mentioned in the current block. " in - let miner_reward := + let _ := M.assign_local (| + "miner_reward" , BinOp.add (| M.get_name (| globals, "BLOCK_REWARD" |), BinOp.mult (| @@ -1361,7 +1480,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := Constant.int 32 |) |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "create_ether" |), make_list [ @@ -1376,7 +1496,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := M.get_name (| globals, "ommer" |), M.get_name (| globals, "ommers" |), ltac:(M.monadic ( - let ommer_age := + let _ := M.assign_local (| + "ommer_age" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -1386,8 +1507,10 @@ Definition pay_rewards : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let ommer_miner_reward := + |) + |) in + let _ := M.assign_local (| + "ommer_miner_reward" , BinOp.floor_div (| BinOp.mult (| BinOp.sub (| @@ -1397,7 +1520,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := M.get_name (| globals, "BLOCK_REWARD" |) |), Constant.int 8 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "create_ether" |), make_list [ @@ -1458,9 +1582,12 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender := - M.get_field (| M.get_name (| globals, "env" |), "origin" |) in - let sender_account := + let _ := M.assign_local (| + "sender" , + M.get_field (| M.get_name (| globals, "env" |), "origin" |) + |) in + let _ := M.assign_local (| + "sender_account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1468,12 +1595,15 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "sender" |) ], make_dict [] - |) in - let gas_fee := + |) + |) in + let _ := M.assign_local (| + "gas_fee" , BinOp.mult (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1514,7 +1644,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let gas := + let _ := M.assign_local (| + "gas" , BinOp.sub (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.call (| @@ -1524,7 +1655,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "increment_nonce" |), make_list [ @@ -1533,11 +1665,13 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_balance_after_gas_fee := + let _ := M.assign_local (| + "sender_balance_after_gas_fee" , BinOp.sub (| M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), M.get_name (| globals, "gas_fee" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -1547,7 +1681,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let message := + let _ := M.assign_local (| + "message" , M.call (| M.get_name (| globals, "prepare_message" |), make_list [ @@ -1559,8 +1694,10 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in - let output := + |) + |) in + let _ := M.assign_local (| + "output" , M.call (| M.get_name (| globals, "process_message_call" |), make_list [ @@ -1568,13 +1705,17 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in - let gas_used := + |) + |) in + let _ := M.assign_local (| + "gas_used" , BinOp.sub (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_field (| M.get_name (| globals, "output" |), "gas_left" |) - |) in - let gas_refund := + |) + |) in + let _ := M.assign_local (| + "gas_refund" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -1585,16 +1726,20 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "output" |), "refund_counter" |) ], make_dict [] - |) in - let gas_refund_amount := + |) + |) in + let _ := M.assign_local (| + "gas_refund_amount" , BinOp.mult (| BinOp.add (| M.get_field (| M.get_name (| globals, "output" |), "gas_left" |), M.get_name (| globals, "gas_refund" |) |), M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) - |) in - let transaction_fee := + |) + |) in + let _ := M.assign_local (| + "transaction_fee" , BinOp.mult (| BinOp.sub (| BinOp.sub (| @@ -1604,13 +1749,17 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "gas_refund" |) |), M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) - |) in - let total_gas_used := + |) + |) in + let _ := M.assign_local (| + "total_gas_used" , BinOp.sub (| M.get_name (| globals, "gas_used" |), M.get_name (| globals, "gas_refund" |) - |) in - let sender_balance_after_refund := + |) + |) in + let _ := M.assign_local (| + "sender_balance_after_refund" , BinOp.add (| M.get_field (| M.call (| M.get_name (| globals, "get_account" |), @@ -1621,7 +1770,8 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |), "balance" |), M.get_name (| globals, "gas_refund_amount" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -1631,7 +1781,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let coinbase_balance_after_mining_fee := + let _ := M.assign_local (| + "coinbase_balance_after_mining_fee" , BinOp.add (| M.get_field (| M.call (| M.get_name (| globals, "get_account" |), @@ -1642,7 +1793,8 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |), "balance" |), M.get_name (| globals, "transaction_fee" |) - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1833,8 +1985,10 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := verified : `ethereum.base_types.Uint` The intrinsic cost of the transaction. " in - let data_cost := - Constant.int 0 in + let _ := M.assign_local (| + "data_cost" , + Constant.int 0 + |) in let _ := M.for_ (| M.get_name (| globals, "byte" |), @@ -1849,15 +2003,19 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let data_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "data_cost", M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let data_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "data_cost", M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -1881,13 +2039,17 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let create_cost := - M.get_name (| globals, "TX_CREATE_COST" |) in + let _ := M.assign_local (| + "create_cost" , + M.get_name (| globals, "TX_CREATE_COST" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let create_cost := - Constant.int 0 in + let _ := M.assign_local (| + "create_cost" , + Constant.int 0 + |) in M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1993,7 +2155,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let public_key := + let _ := M.assign_local (| + "public_key" , M.call (| M.get_name (| globals, "secp256k1_recover" |), make_list [ @@ -2012,7 +2175,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -2047,7 +2211,8 @@ Definition recover_sender : Value.t -> Value.t -> M := ], make_dict [] |) in - let public_key := + let _ := M.assign_local (| + "public_key" , M.call (| M.get_name (| globals, "secp256k1_recover" |), make_list [ @@ -2073,7 +2238,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -2259,11 +2425,13 @@ Definition check_gas_limit : Value.t -> Value.t -> M := check : `bool` True if gas limit constraints are satisfied, False otherwise. " in - let max_adjustment_delta := + let _ := M.assign_local (| + "max_adjustment_delta" , BinOp.floor_div (| M.get_name (| globals, "parent_gas_limit" |), M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -2367,7 +2535,8 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := difficulty : `ethereum.base_types.Uint` Computed difficulty for a block. " in - let offset := + let _ := M.assign_local (| + "offset" , BinOp.mult (| BinOp.floor_div (| M.call (| @@ -2411,8 +2580,10 @@ Constant.int 1 ], make_dict [] |) - |) in - let difficulty := + |) + |) in + let _ := M.assign_local (| + "difficulty" , BinOp.add (| M.call (| M.get_name (| globals, "int" |), @@ -2422,8 +2593,10 @@ Constant.int 1 make_dict [] |), M.get_name (| globals, "offset" |) - |) in - let num_bomb_periods := + |) + |) in + let _ := M.assign_local (| + "num_bomb_periods" , BinOp.sub (| BinOp.floor_div (| BinOp.sub (| @@ -2439,7 +2612,8 @@ Constant.int 1 Constant.int 100000 |), Constant.int 2 - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -2449,15 +2623,14 @@ Constant.int 1 |), (* then *) ltac:(M.monadic ( - let difficulty := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "difficulty", BinOp.pow (| Constant.int 2, M.get_name (| globals, "num_bomb_periods" |) |) - BinOp.pow (| - Constant.int 2, - M.get_name (| globals, "num_bomb_periods" |) - |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/constantinople/fork_types.v b/CoqOfPython/ethereum/constantinople/fork_types.v index e4d2540..351e1ef 100644 --- a/CoqOfPython/ethereum/constantinople/fork_types.v +++ b/CoqOfPython/ethereum/constantinople/fork_types.v @@ -17,17 +17,29 @@ Introduction Types re-used throughout the specification, which are specific to Ethereum. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes20"; "Bytes256"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes20 : + IsImported globals "ethereum.base_types" "Bytes20". +Axiom ethereum_base_types_imports_Bytes256 : + IsImported globals "ethereum.base_types" "Bytes256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) diff --git a/CoqOfPython/ethereum/constantinople/state.v b/CoqOfPython/ethereum/constantinople/state.v index c81c754..15a1a6d 100644 --- a/CoqOfPython/ethereum/constantinople/state.v +++ b/CoqOfPython/ethereum/constantinople/state.v @@ -22,23 +22,55 @@ There is a distinction between an account that does not exist and `EMPTY_ACCOUNT`. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass"; "field" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict"; "List"; "Optional"; "Tuple" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "modify" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_constantinople_fork_types_imports : - AreImported globals "ethereum.constantinople.fork_types" [ "EMPTY_ACCOUNT"; "Account"; "Address"; "Root" ]. - -Axiom ethereum_constantinople_trie_imports : - AreImported globals "ethereum.constantinople.trie" [ "EMPTY_TRIE_ROOT"; "Trie"; "copy_trie"; "root"; "trie_get"; "trie_set" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". +Axiom dataclasses_imports_field : + IsImported globals "dataclasses" "field". + +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_modify : + IsImported globals "ethereum.base_types" "modify". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_constantinople_fork_types_imports_EMPTY_ACCOUNT : + IsImported globals "ethereum.constantinople.fork_types" "EMPTY_ACCOUNT". +Axiom ethereum_constantinople_fork_types_imports_Account : + IsImported globals "ethereum.constantinople.fork_types" "Account". +Axiom ethereum_constantinople_fork_types_imports_Address : + IsImported globals "ethereum.constantinople.fork_types" "Address". +Axiom ethereum_constantinople_fork_types_imports_Root : + IsImported globals "ethereum.constantinople.fork_types" "Root". + +Axiom ethereum_constantinople_trie_imports_EMPTY_TRIE_ROOT : + IsImported globals "ethereum.constantinople.trie" "EMPTY_TRIE_ROOT". +Axiom ethereum_constantinople_trie_imports_Trie : + IsImported globals "ethereum.constantinople.trie" "Trie". +Axiom ethereum_constantinople_trie_imports_copy_trie : + IsImported globals "ethereum.constantinople.trie" "copy_trie". +Axiom ethereum_constantinople_trie_imports_root : + IsImported globals "ethereum.constantinople.trie" "root". +Axiom ethereum_constantinople_trie_imports_trie_get : + IsImported globals "ethereum.constantinople.trie" "trie_get". +Axiom ethereum_constantinople_trie_imports_trie_set : + IsImported globals "ethereum.constantinople.trie" "trie_set". Definition State : Value.t := builtins.make_klass @@ -153,7 +185,8 @@ Definition get_account : Value.t -> Value.t -> M := account : `Account` Account at address. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account_optional" |), make_list [ @@ -161,7 +194,8 @@ Definition get_account : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -207,7 +241,8 @@ Definition get_account_optional : Value.t -> Value.t -> M := account : `Account` Account at address. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "trie_get" |), make_list [ @@ -215,7 +250,8 @@ Definition get_account_optional : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "account" |) |) in @@ -338,14 +374,16 @@ Definition get_storage : Value.t -> Value.t -> M := value : `U256` Value at the key. " in - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -369,7 +407,8 @@ Definition get_storage : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "trie_get" |), make_list [ @@ -377,7 +416,8 @@ Definition get_storage : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -420,14 +460,16 @@ Definition set_storage : Value.t -> Value.t -> M := |), Constant.None_ |) |) in - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -437,12 +479,14 @@ Definition set_storage : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_name (| globals, "Trie" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), @@ -469,7 +513,7 @@ Definition set_storage : Value.t -> Value.t -> M := M.if_then_else (| Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), - {} + Constant.str "(* At expr: unsupported node type: Dict *)" |), (* then *) ltac:(M.monadic ( @@ -615,7 +659,8 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := True if if an account has non zero nonce or non empty code, False otherwise. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -623,7 +668,8 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| BoolOp.or (| Compare.not_eq (| @@ -665,7 +711,8 @@ Definition is_account_empty : Value.t -> Value.t -> M := True if if an account has zero nonce, empty code and zero balance, False otherwise. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -673,7 +720,8 @@ Definition is_account_empty : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| BoolOp.and (| Compare.eq (| @@ -724,7 +772,8 @@ Definition account_exists_and_is_empty : Value.t -> Value.t -> M := True if an account exists and has zero nonce, empty code and zero balance, False otherwise. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account_optional" |), make_list [ @@ -732,7 +781,8 @@ Definition account_exists_and_is_empty : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| BoolOp.and (| Compare.is_not (| @@ -789,7 +839,8 @@ Definition is_account_alive : Value.t -> Value.t -> M := is_alive : `bool` True if the account is alive. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account_optional" |), make_list [ @@ -797,7 +848,8 @@ Definition is_account_alive : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| diff --git a/CoqOfPython/ethereum/constantinople/transactions.v b/CoqOfPython/ethereum/constantinople/transactions.v index 8eedff8..e2158f5 100644 --- a/CoqOfPython/ethereum/constantinople/transactions.v +++ b/CoqOfPython/ethereum/constantinople/transactions.v @@ -9,17 +9,25 @@ submitted to be executed. If Ethereum is viewed as a state machine, transactions are the events that move between states. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Union" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_constantinople_fork_types_imports : - AreImported globals "ethereum.constantinople.fork_types" [ "Address" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_Union : + IsImported globals "typing" "Union". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_constantinople_fork_types_imports_Address : + IsImported globals "ethereum.constantinople.fork_types" "Address". Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( Constant.int 21000 diff --git a/CoqOfPython/ethereum/constantinople/trie.v b/CoqOfPython/ethereum/constantinople/trie.v index c242bbd..18f9155 100644 --- a/CoqOfPython/ethereum/constantinople/trie.v +++ b/CoqOfPython/ethereum/constantinople/trie.v @@ -20,38 +20,72 @@ The state trie is the structure responsible for storing (* At top_level_stmt: unsupported node type: Import *) -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass"; "field" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict"; "Generic"; "List"; "Mapping"; "MutableMapping"; "Optional"; "Sequence"; "TypeVar"; "Union"; "cast" ]. - -Axiom ethereum_byzantium_imports : - AreImported globals "ethereum.byzantium" [ "trie" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_utils_hexadecimal_imports : - AreImported globals "ethereum.utils.hexadecimal" [ "hex_to_bytes" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_constantinople_blocks_imports : - AreImported globals "ethereum.constantinople.blocks" [ "Receipt" ]. - -Axiom ethereum_constantinople_fork_types_imports : - AreImported globals "ethereum.constantinople.fork_types" [ "Account"; "Address"; "Root"; "encode_account" ]. - -Axiom ethereum_constantinople_transactions_imports : - AreImported globals "ethereum.constantinople.transactions" [ "Transaction" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". +Axiom dataclasses_imports_field : + IsImported globals "dataclasses" "field". + +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". +Axiom typing_imports_Generic : + IsImported globals "typing" "Generic". +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Mapping : + IsImported globals "typing" "Mapping". +Axiom typing_imports_MutableMapping : + IsImported globals "typing" "MutableMapping". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Sequence : + IsImported globals "typing" "Sequence". +Axiom typing_imports_TypeVar : + IsImported globals "typing" "TypeVar". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". +Axiom typing_imports_cast : + IsImported globals "typing" "cast". + +Axiom ethereum_byzantium_imports_trie : + IsImported globals "ethereum.byzantium" "trie". + +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_utils_hexadecimal_imports_hex_to_bytes : + IsImported globals "ethereum.utils.hexadecimal" "hex_to_bytes". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_constantinople_blocks_imports_Receipt : + IsImported globals "ethereum.constantinople.blocks" "Receipt". + +Axiom ethereum_constantinople_fork_types_imports_Account : + IsImported globals "ethereum.constantinople.fork_types" "Account". +Axiom ethereum_constantinople_fork_types_imports_Address : + IsImported globals "ethereum.constantinople.fork_types" "Address". +Axiom ethereum_constantinople_fork_types_imports_Root : + IsImported globals "ethereum.constantinople.fork_types" "Root". +Axiom ethereum_constantinople_fork_types_imports_encode_account : + IsImported globals "ethereum.constantinople.fork_types" "encode_account". + +Axiom ethereum_constantinople_transactions_imports_Transaction : + IsImported globals "ethereum.constantinople.transactions" "Transaction". Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -161,7 +195,7 @@ Definition encode_internal_node : Value.t -> Value.t -> M := when serialized. This function also accepts `None`, representing the absence of a node, - which is encoded to `b""""""`. + which is encoded to `b""""`. Parameters ---------- @@ -183,8 +217,10 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := - Constant.bytes "" in + let _ := M.assign_local (| + "unencoded" , + Constant.bytes "" + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -201,7 +237,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := + let _ := M.assign_local (| + "unencoded" , make_tuple [ M.call (| M.get_name (| globals, "nibble_list_to_compact" |), make_list [ @@ -209,7 +246,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := Constant.bool true ], make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in + |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -226,7 +264,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := + let _ := M.assign_local (| + "unencoded" , make_tuple [ M.call (| M.get_name (| globals, "nibble_list_to_compact" |), make_list [ @@ -234,7 +273,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := Constant.bool false ], make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in + |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -251,13 +291,15 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := + let _ := M.assign_local (| + "unencoded" , BinOp.add (| M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), make_list [ M.get_field (| M.get_name (| globals, "node" |), "value" |) ] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -276,14 +318,16 @@ Definition encode_internal_node : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - let encoded := + let _ := M.assign_local (| + "encoded" , M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), make_list [ M.get_name (| globals, "unencoded" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -675,12 +719,14 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := compressed : `bytearray` Compact byte array. " in - let compact := + let _ := M.assign_local (| + "compact" , M.call (| M.get_name (| globals, "bytearray" |), make_list [], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -860,7 +906,8 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := nibble_list : `Bytes` The `Bytes` in nibble-list format. " in - let nibble_list := + let _ := M.assign_local (| + "nibble_list" , M.call (| M.get_name (| globals, "bytearray" |), make_list [ @@ -876,7 +923,8 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ], @@ -984,15 +1032,18 @@ Definition _prepare_trie : Value.t -> Value.t -> M := M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "Address" |), make_list [ M.get_name (| globals, "preimage" |) ], make_dict [] - |) in - let encoded_value := + |) + |) in + let _ := M.assign_local (| + "encoded_value" , M.call (| M.get_name (| globals, "encode_node" |), make_list [ @@ -1006,18 +1057,21 @@ Definition _prepare_trie : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let encoded_value := + let _ := M.assign_local (| + "encoded_value" , M.call (| M.get_name (| globals, "encode_node" |), make_list [ M.get_name (| globals, "value" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -1038,19 +1092,23 @@ Definition _prepare_trie : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "trie" |), "secured" |), (* then *) ltac:(M.monadic ( - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "preimage" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let key := - M.get_name (| globals, "preimage" |) in + let _ := M.assign_local (| + "key" , + M.get_name (| globals, "preimage" |) + |) in M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -1097,7 +1155,8 @@ Definition root : Value.t -> Value.t -> M := root : `.fork_types.Root` MPT root of the underlying key-value pairs. " in - let obj := + let _ := M.assign_local (| + "obj" , M.call (| M.get_name (| globals, "_prepare_trie" |), make_list [ @@ -1105,8 +1164,10 @@ Definition root : Value.t -> Value.t -> M := M.get_name (| globals, "get_storage_root" |) ], make_dict [] - |) in - let root_node := + |) + |) in + let _ := M.assign_local (| + "root_node" , M.call (| M.get_name (| globals, "encode_internal_node" |), make_list [ @@ -1126,7 +1187,8 @@ Definition root : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1231,7 +1293,8 @@ Definition patricialize : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let arbitrary_key := + let _ := M.assign_local (| + "arbitrary_key" , M.call (| M.get_name (| globals, "next" |), make_list [ @@ -1244,7 +1307,8 @@ Definition patricialize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1260,7 +1324,8 @@ Definition patricialize : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let leaf := + let _ := M.assign_local (| + "leaf" , M.call (| M.get_name (| globals, "LeafNode" |), make_list [ @@ -1276,7 +1341,8 @@ Definition patricialize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "leaf" |) |) in @@ -1285,27 +1351,32 @@ Definition patricialize : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let substring := + let _ := M.assign_local (| + "substring" , M.slice (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |), Constant.None_, Constant.None_ - |) in - let prefix_length := + |) + |) in + let _ := M.assign_local (| + "prefix_length" , M.call (| M.get_name (| globals, "len" |), make_list [ M.get_name (| globals, "substring" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "key" |), M.get_name (| globals, "obj" |), ltac:(M.monadic ( - let prefix_length := + let _ := M.assign_local (| + "prefix_length" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -1325,7 +1396,8 @@ Definition patricialize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1356,7 +1428,8 @@ Definition patricialize : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let prefix := + let _ := M.assign_local (| + "prefix" , M.slice (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |), @@ -1365,7 +1438,8 @@ Definition patricialize : Value.t -> Value.t -> M := M.get_name (| globals, "prefix_length" |) |), Constant.None_ - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ExtensionNode" |), @@ -1412,7 +1486,7 @@ Definition patricialize : Value.t -> Value.t -> M := let _ := M.call (| M.get_field (| M.get_name (| globals, "branches" |), "append" |), make_list [ - {} + Constant.str "(* At expr: unsupported node type: Dict *)" ], make_dict [] |) in @@ -1422,8 +1496,10 @@ Definition patricialize : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let value := - Constant.bytes "" in + let _ := M.assign_local (| + "value" , + Constant.bytes "" + |) in let _ := M.for_ (| M.get_name (| globals, "key" |), @@ -1466,11 +1542,13 @@ Definition patricialize : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let value := + let _ := M.assign_local (| + "value" , M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/constantinople/utils/address.v b/CoqOfPython/ethereum/constantinople/utils/address.v index a2749d9..a23e9b8 100644 --- a/CoqOfPython/ethereum/constantinople/utils/address.v +++ b/CoqOfPython/ethereum/constantinople/utils/address.v @@ -18,23 +18,27 @@ Address specific functions used in this constantinople version of specification. ". -Axiom typing_imports : - AreImported globals "typing" [ "Union" ]. +Axiom typing_imports_Union : + IsImported globals "typing" "Union". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes32"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_left_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "left_pad_zero_bytes". -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". -Axiom ethereum_constantinople_fork_types_imports : - AreImported globals "ethereum.constantinople.fork_types" [ "Address" ]. +Axiom ethereum_constantinople_fork_types_imports_Address : + IsImported globals "ethereum.constantinople.fork_types" "Address". Definition to_address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -91,7 +95,8 @@ Definition compute_contract_address : Value.t -> Value.t -> M := address: `Address` The computed address of the new account. " in - let computed_address := + let _ := M.assign_local (| + "computed_address" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -107,15 +112,19 @@ Definition compute_contract_address : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let canonical_address := + |) + |) in + let _ := M.assign_local (| + "canonical_address" , M.slice (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |), Constant.None_, Constant.None_ - |) in - let padded_address := + |) + |) in + let _ := M.assign_local (| + "padded_address" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -123,7 +132,8 @@ Definition compute_contract_address : Value.t -> Value.t -> M := Constant.int 20 ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Address" |), @@ -156,7 +166,8 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := address: `ethereum.constantinople.fork_types.Address` The computed address of the new account. " in - let preimage := + let _ := M.assign_local (| + "preimage" , BinOp.add (| BinOp.add (| BinOp.add (| @@ -172,23 +183,29 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in - let computed_address := + |) + |) in + let _ := M.assign_local (| + "computed_address" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "preimage" |) ], make_dict [] - |) in - let canonical_address := + |) + |) in + let _ := M.assign_local (| + "canonical_address" , M.slice (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |), Constant.None_, Constant.None_ - |) in - let padded_address := + |) + |) in + let _ := M.assign_local (| + "padded_address" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -196,7 +213,8 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := Constant.int 20 ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Address" |), diff --git a/CoqOfPython/ethereum/constantinople/utils/hexadecimal.v b/CoqOfPython/ethereum/constantinople/utils/hexadecimal.v index e060a84..6eae082 100644 --- a/CoqOfPython/ethereum/constantinople/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/constantinople/utils/hexadecimal.v @@ -18,11 +18,15 @@ Hexadecimal utility functions used in this specification, specific to Constantinople types. ". -Axiom ethereum_utils_hexadecimal_imports : - AreImported globals "ethereum.utils.hexadecimal" [ "remove_hex_prefix" ]. - -Axiom ethereum_constantinople_fork_types_imports : - AreImported globals "ethereum.constantinople.fork_types" [ "Address"; "Bloom"; "Root" ]. +Axiom ethereum_utils_hexadecimal_imports_remove_hex_prefix : + IsImported globals "ethereum.utils.hexadecimal" "remove_hex_prefix". + +Axiom ethereum_constantinople_fork_types_imports_Address : + IsImported globals "ethereum.constantinople.fork_types" "Address". +Axiom ethereum_constantinople_fork_types_imports_Bloom : + IsImported globals "ethereum.constantinople.fork_types" "Bloom". +Axiom ethereum_constantinople_fork_types_imports_Root : + IsImported globals "ethereum.constantinople.fork_types" "Root". Definition hex_to_root : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/constantinople/utils/message.v b/CoqOfPython/ethereum/constantinople/utils/message.v index ce63cad..202ca4d 100644 --- a/CoqOfPython/ethereum/constantinople/utils/message.v +++ b/CoqOfPython/ethereum/constantinople/utils/message.v @@ -18,23 +18,33 @@ Message specific functions used in this constantinople version of specification. ". -Axiom typing_imports : - AreImported globals "typing" [ "Optional"; "Union" ]. +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_constantinople_fork_types_imports : - AreImported globals "ethereum.constantinople.fork_types" [ "Address" ]. +Axiom ethereum_constantinople_fork_types_imports_Address : + IsImported globals "ethereum.constantinople.fork_types" "Address". -Axiom ethereum_constantinople_state_imports : - AreImported globals "ethereum.constantinople.state" [ "get_account" ]. +Axiom ethereum_constantinople_state_imports_get_account : + IsImported globals "ethereum.constantinople.state" "get_account". -Axiom ethereum_constantinople_vm_imports : - AreImported globals "ethereum.constantinople.vm" [ "Environment"; "Message" ]. +Axiom ethereum_constantinople_vm_imports_Environment : + IsImported globals "ethereum.constantinople.vm" "Environment". +Axiom ethereum_constantinople_vm_imports_Message : + IsImported globals "ethereum.constantinople.vm" "Message". -Axiom ethereum_constantinople_utils_address_imports : - AreImported globals "ethereum.constantinople.utils.address" [ "compute_contract_address" ]. +Axiom ethereum_constantinople_utils_address_imports_compute_contract_address : + IsImported globals "ethereum.constantinople.utils.address" "compute_contract_address". Definition prepare_message : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -84,7 +94,8 @@ Definition prepare_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let current_target := + let _ := M.assign_local (| + "current_target" , M.call (| M.get_name (| globals, "compute_contract_address" |), make_list [ @@ -108,17 +119,22 @@ Definition prepare_message : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let msg_data := + |) + |) in + let _ := M.assign_local (| + "msg_data" , M.call (| M.get_name (| globals, "Bytes" |), make_list [ Constant.bytes "" ], make_dict [] - |) in - let code := - M.get_name (| globals, "data" |) in + |) + |) in + let _ := M.assign_local (| + "code" , + M.get_name (| globals, "data" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -135,11 +151,16 @@ Definition prepare_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let current_target := - M.get_name (| globals, "target" |) in - let msg_data := - M.get_name (| globals, "data" |) in - let code := + let _ := M.assign_local (| + "current_target" , + M.get_name (| globals, "target" |) + |) in + let _ := M.assign_local (| + "msg_data" , + M.get_name (| globals, "data" |) + |) in + let _ := M.assign_local (| + "code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -147,7 +168,8 @@ Definition prepare_message : Value.t -> Value.t -> M := M.get_name (| globals, "target" |) ], make_dict [] - |), "code" |) in + |), "code" |) + |) in let _ := (* if *) M.if_then_else (| @@ -157,8 +179,10 @@ Definition prepare_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let code_address := - M.get_name (| globals, "target" |) in + let _ := M.assign_local (| + "code_address" , + M.get_name (| globals, "target" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/constantinople/vm/__init__.v b/CoqOfPython/ethereum/constantinople/vm/__init__.v index 159f09c..73a0539 100644 --- a/CoqOfPython/ethereum/constantinople/vm/__init__.v +++ b/CoqOfPython/ethereum/constantinople/vm/__init__.v @@ -18,29 +18,45 @@ The abstract computer which runs the code stored in an `.fork_types.Account`. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple"; "Union" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. - -Axiom ethereum_constantinople_blocks_imports : - AreImported globals "ethereum.constantinople.blocks" [ "Log" ]. - -Axiom ethereum_constantinople_fork_types_imports : - AreImported globals "ethereum.constantinople.fork_types" [ "Address" ]. - -Axiom ethereum_constantinople_state_imports : - AreImported globals "ethereum.constantinople.state" [ "State"; "account_exists_and_is_empty" ]. - -Axiom ethereum_constantinople_vm_precompiled_contracts_imports : - AreImported globals "ethereum.constantinople.vm.precompiled_contracts" [ "RIPEMD160_ADDRESS" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". + +Axiom ethereum_constantinople_blocks_imports_Log : + IsImported globals "ethereum.constantinople.blocks" "Log". + +Axiom ethereum_constantinople_fork_types_imports_Address : + IsImported globals "ethereum.constantinople.fork_types" "Address". + +Axiom ethereum_constantinople_state_imports_State : + IsImported globals "ethereum.constantinople.state" "State". +Axiom ethereum_constantinople_state_imports_account_exists_and_is_empty : + IsImported globals "ethereum.constantinople.state" "account_exists_and_is_empty". + +Axiom ethereum_constantinople_vm_precompiled_contracts_imports_RIPEMD160_ADDRESS : + IsImported globals "ethereum.constantinople.vm.precompiled_contracts" "RIPEMD160_ADDRESS". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] diff --git a/CoqOfPython/ethereum/constantinople/vm/exceptions.v b/CoqOfPython/ethereum/constantinople/vm/exceptions.v index 9a8dc42..6a2283c 100644 --- a/CoqOfPython/ethereum/constantinople/vm/exceptions.v +++ b/CoqOfPython/ethereum/constantinople/vm/exceptions.v @@ -17,8 +17,8 @@ Introduction Exceptions which cause the EVM to halt exceptionally. ". -Axiom ethereum_exceptions_imports : - AreImported globals "ethereum.exceptions" [ "EthereumException" ]. +Axiom ethereum_exceptions_imports_EthereumException : + IsImported globals "ethereum.exceptions" "EthereumException". Definition ExceptionalHalt : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/constantinople/vm/gas.v b/CoqOfPython/ethereum/constantinople/vm/gas.v index 3ad8be6..7a776c8 100644 --- a/CoqOfPython/ethereum/constantinople/vm/gas.v +++ b/CoqOfPython/ethereum/constantinople/vm/gas.v @@ -17,26 +17,32 @@ Introduction EVM gas constants and calculators. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Tuple" ]. +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_trace_imports : - AreImported globals "ethereum.trace" [ "GasAndRefund"; "evm_trace" ]. +Axiom ethereum_trace_imports_GasAndRefund : + IsImported globals "ethereum.trace" "GasAndRefund". +Axiom ethereum_trace_imports_evm_trace : + IsImported globals "ethereum.trace" "evm_trace". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_constantinople_vm_imports : - AreImported globals "ethereum.constantinople.vm" [ "Evm" ]. +Axiom ethereum_constantinople_vm_imports_Evm : + IsImported globals "ethereum.constantinople.vm" "Evm". -Axiom ethereum_constantinople_vm_exceptions_imports : - AreImported globals "ethereum.constantinople.vm.exceptions" [ "OutOfGasError" ]. +Axiom ethereum_constantinople_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.constantinople.vm.exceptions" "OutOfGasError". Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -542,7 +548,8 @@ Definition calculate_memory_gas_cost : Value.t -> Value.t -> M := total_gas_cost : `ethereum.base_types.Uint` The gas cost for storing data in memory. " in - let size_in_words := + let _ := M.assign_local (| + "size_in_words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -552,25 +559,32 @@ Definition calculate_memory_gas_cost : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let linear_cost := + |) + |) in + let _ := M.assign_local (| + "linear_cost" , BinOp.mult (| M.get_name (| globals, "size_in_words" |), M.get_name (| globals, "GAS_MEMORY" |) - |) in - let quadratic_cost := + |) + |) in + let _ := M.assign_local (| + "quadratic_cost" , BinOp.floor_div (| BinOp.pow (| M.get_name (| globals, "size_in_words" |), Constant.int 2 |), Constant.int 512 - |) in - let total_gas_cost := + |) + |) in + let _ := M.assign_local (| + "total_gas_cost" , BinOp.add (| M.get_name (| globals, "linear_cost" |), M.get_name (| globals, "quadratic_cost" |) - |) in + |) + |) in (* At stmt: unsupported node type: Try *) M.pure Constant.None_)). @@ -592,23 +606,28 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := ------- extend_memory: `ExtendMemory` " in - let size_to_extend := + let _ := M.assign_local (| + "size_to_extend" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in - let to_be_paid := + |) + |) in + let _ := M.assign_local (| + "to_be_paid" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in - let current_size := + |) + |) in + let _ := M.assign_local (| + "current_size" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -621,7 +640,8 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ], @@ -642,15 +662,18 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let before_size := + let _ := M.assign_local (| + "before_size" , M.call (| M.get_name (| globals, "ceil32" |), make_list [ M.get_name (| globals, "current_size" |) ], make_dict [] - |) in - let after_size := + |) + |) in + let _ := M.assign_local (| + "after_size" , M.call (| M.get_name (| globals, "ceil32" |), make_list [ @@ -672,7 +695,8 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -688,42 +712,46 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let size_to_extend := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "size_to_extend", BinOp.sub (| M.get_name (| globals, "after_size" |), M.get_name (| globals, "before_size" |) |) - BinOp.sub (| - M.get_name (| globals, "after_size" |), - M.get_name (| globals, "before_size" |) - |) in - let already_paid := + |) in + let _ := M.assign_local (| + "already_paid" , M.call (| M.get_name (| globals, "calculate_memory_gas_cost" |), make_list [ M.get_name (| globals, "before_size" |) ], make_dict [] - |) in - let total_cost := + |) + |) in + let _ := M.assign_local (| + "total_cost" , M.call (| M.get_name (| globals, "calculate_memory_gas_cost" |), make_list [ M.get_name (| globals, "after_size" |) ], make_dict [] - |) in - let to_be_paid := BinOp.add + |) + |) in + let _ := M.assign_op_local (| + BinOp.add, + "to_be_paid", BinOp.sub (| M.get_name (| globals, "total_cost" |), M.get_name (| globals, "already_paid" |) |) - BinOp.sub (| - M.get_name (| globals, "total_cost" |), - M.get_name (| globals, "already_paid" |) - |) in - let current_size := - M.get_name (| globals, "after_size" |) in + |) in + let _ := M.assign_local (| + "current_size" , + M.get_name (| globals, "after_size" |) + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -770,7 +798,8 @@ Definition calculate_message_call_gas : Value.t -> Value.t -> M := ------- message_call_gas: `MessageCallGas` " in - let call_stipend := + let _ := M.assign_local (| + "call_stipend" , (* if *) M.if_then_else (| Compare.eq (| @@ -789,7 +818,8 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "call_stipend" |) - )) |) in + )) |) + |) in let _ := (* if *) M.if_then_else (| @@ -823,7 +853,8 @@ M.get_name (| globals, "call_stipend" |) )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -843,7 +874,8 @@ M.get_name (| globals, "call_stipend" |) |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "MessageCallGas" |), diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/__init__.v b/CoqOfPython/ethereum/constantinople/vm/instructions/__init__.v index ec360d8..b8c6731 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/__init__.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/__init__.v @@ -20,44 +20,46 @@ implementations. (* At top_level_stmt: unsupported node type: Import *) -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict" ]. +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". -Axiom ethereum_constantinople_vm_instructions_imports : - AreImported globals "ethereum.constantinople.vm.instructions" [ "arithmetic" ]. +Axiom ethereum_constantinople_vm_instructions_imports_arithmetic : + IsImported globals "ethereum.constantinople.vm.instructions" "arithmetic". -Axiom ethereum_constantinople_vm_instructions_imports : - AreImported globals "ethereum.constantinople.vm.instructions" [ "bitwise" ]. +Axiom ethereum_constantinople_vm_instructions_imports_bitwise : + IsImported globals "ethereum.constantinople.vm.instructions" "bitwise". -Axiom ethereum_constantinople_vm_instructions_imports : - AreImported globals "ethereum.constantinople.vm.instructions" [ "block" ]. +Axiom ethereum_constantinople_vm_instructions_imports_block : + IsImported globals "ethereum.constantinople.vm.instructions" "block". -Axiom ethereum_constantinople_vm_instructions_imports : - AreImported globals "ethereum.constantinople.vm.instructions" [ "comparison" ]. +Axiom ethereum_constantinople_vm_instructions_imports_comparison : + IsImported globals "ethereum.constantinople.vm.instructions" "comparison". -Axiom ethereum_constantinople_vm_instructions_imports : - AreImported globals "ethereum.constantinople.vm.instructions" [ "control_flow" ]. +Axiom ethereum_constantinople_vm_instructions_imports_control_flow : + IsImported globals "ethereum.constantinople.vm.instructions" "control_flow". -Axiom ethereum_constantinople_vm_instructions_imports : - AreImported globals "ethereum.constantinople.vm.instructions" [ "environment" ]. +Axiom ethereum_constantinople_vm_instructions_imports_environment : + IsImported globals "ethereum.constantinople.vm.instructions" "environment". -Axiom ethereum_constantinople_vm_instructions_imports : - AreImported globals "ethereum.constantinople.vm.instructions" [ "keccak" ]. +Axiom ethereum_constantinople_vm_instructions_imports_keccak : + IsImported globals "ethereum.constantinople.vm.instructions" "keccak". -Axiom ethereum_constantinople_vm_instructions_imports : - AreImported globals "ethereum.constantinople.vm.instructions" [ "log" ]. +Axiom ethereum_constantinople_vm_instructions_imports_log : + IsImported globals "ethereum.constantinople.vm.instructions" "log". -Axiom ethereum_constantinople_vm_instructions_imports : - AreImported globals "ethereum.constantinople.vm.instructions" [ "memory" ]. +Axiom ethereum_constantinople_vm_instructions_imports_memory : + IsImported globals "ethereum.constantinople.vm.instructions" "memory". -Axiom ethereum_constantinople_vm_instructions_imports : - AreImported globals "ethereum.constantinople.vm.instructions" [ "stack" ]. +Axiom ethereum_constantinople_vm_instructions_imports_stack : + IsImported globals "ethereum.constantinople.vm.instructions" "stack". -Axiom ethereum_constantinople_vm_instructions_imports : - AreImported globals "ethereum.constantinople.vm.instructions" [ "storage" ]. +Axiom ethereum_constantinople_vm_instructions_imports_storage : + IsImported globals "ethereum.constantinople.vm.instructions" "storage". -Axiom ethereum_constantinople_vm_instructions_imports : - AreImported globals "ethereum.constantinople.vm.instructions" [ "system" ]. +Axiom ethereum_constantinople_vm_instructions_imports_system : + IsImported globals "ethereum.constantinople.vm.instructions" "system". Definition Ops : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/constantinople/vm/instructions/arithmetic.v index d8fc85c..3e3a445 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/arithmetic.v @@ -17,20 +17,38 @@ Introduction Implementations of the EVM Arithmetic instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U255_CEIL_VALUE"; "U256"; "U256_CEIL_VALUE"; "Uint" ]. +Axiom ethereum_base_types_imports_U255_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U255_CEIL_VALUE". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_U256_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U256_CEIL_VALUE". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "get_sign" ]. +Axiom ethereum_utils_numeric_imports_get_sign : + IsImported globals "ethereum.utils.numeric" "get_sign". -Axiom ethereum_constantinople_vm_imports : - AreImported globals "ethereum.constantinople.vm" [ "Evm" ]. +Axiom ethereum_constantinople_vm_imports_Evm : + IsImported globals "ethereum.constantinople.vm" "Evm". -Axiom ethereum_constantinople_vm_gas_imports : - AreImported globals "ethereum.constantinople.vm.gas" [ "GAS_EXPONENTIATION"; "GAS_EXPONENTIATION_PER_BYTE"; "GAS_LOW"; "GAS_MID"; "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_constantinople_vm_gas_imports_GAS_EXPONENTIATION : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_EXPONENTIATION". +Axiom ethereum_constantinople_vm_gas_imports_GAS_EXPONENTIATION_PER_BYTE : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_EXPONENTIATION_PER_BYTE". +Axiom ethereum_constantinople_vm_gas_imports_GAS_LOW : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_LOW". +Axiom ethereum_constantinople_vm_gas_imports_GAS_MID : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_MID". +Axiom ethereum_constantinople_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_constantinople_vm_gas_imports_charge_gas : + IsImported globals "ethereum.constantinople.vm.gas" "charge_gas". -Axiom ethereum_constantinople_vm_stack_imports : - AreImported globals "ethereum.constantinople.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_constantinople_vm_stack_imports_pop : + IsImported globals "ethereum.constantinople.vm.stack" "pop". +Axiom ethereum_constantinople_vm_stack_imports_push : + IsImported globals "ethereum.constantinople.vm.stack" "push". Definition add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,22 +63,26 @@ Definition add : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -69,14 +91,16 @@ Definition add : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "x" |), "wrapping_add" |), make_list [ M.get_name (| globals, "y" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -105,22 +129,26 @@ Definition sub : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -129,14 +157,16 @@ Definition sub : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "x" |), "wrapping_sub" |), make_list [ M.get_name (| globals, "y" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -165,22 +195,26 @@ Definition mul : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -189,14 +223,16 @@ Definition mul : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "x" |), "wrapping_mul" |), make_list [ M.get_name (| globals, "y" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -225,22 +261,26 @@ Definition div : Value.t -> Value.t -> M := The current EVM frame. " in - let dividend := + let _ := M.assign_local (| + "dividend" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let divisor := + |) + |) in + let _ := M.assign_local (| + "divisor" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -258,22 +298,26 @@ Definition div : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let quotient := + let _ := M.assign_local (| + "quotient" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let quotient := + let _ := M.assign_local (| + "quotient" , BinOp.floor_div (| M.get_name (| globals, "dividend" |), M.get_name (| globals, "divisor" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -304,7 +348,8 @@ Definition sdiv : Value.t -> Value.t -> M := The current EVM frame. " in - let dividend := + let _ := M.assign_local (| + "dividend" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -315,8 +360,10 @@ Definition sdiv : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let divisor := + |) + |) in + let _ := M.assign_local (| + "divisor" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -327,7 +374,8 @@ Definition sdiv : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -345,8 +393,10 @@ Definition sdiv : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let quotient := - Constant.int 0 in + let _ := M.assign_local (| + "quotient" , + Constant.int 0 + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -367,12 +417,15 @@ Definition sdiv : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let quotient := - UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in + let _ := M.assign_local (| + "quotient" , + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let sign := + let _ := M.assign_local (| + "sign" , M.call (| M.get_name (| globals, "get_sign" |), make_list [ @@ -382,8 +435,10 @@ Definition sdiv : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let quotient := + |) + |) in + let _ := M.assign_local (| + "quotient" , BinOp.mult (| M.get_name (| globals, "sign" |), BinOp.floor_div (| @@ -402,7 +457,8 @@ Definition sdiv : Value.t -> Value.t -> M := make_dict [] |) |) - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -428,7 +484,7 @@ Definition sdiv : Value.t -> Value.t -> M := |) in M.pure Constant.None_)). -Definition mod : Value.t -> Value.t -> M := +Definition mod_ : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in let _ := Constant.str " @@ -441,22 +497,26 @@ Definition mod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -474,22 +534,26 @@ Definition mod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let remainder := + let _ := M.assign_local (| + "remainder" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let remainder := + let _ := M.assign_local (| + "remainder" , BinOp.mod_ (| M.get_name (| globals, "x" |), M.get_name (| globals, "y" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -520,7 +584,8 @@ Definition smod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -531,8 +596,10 @@ Definition smod : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -543,7 +610,8 @@ Definition smod : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -561,12 +629,15 @@ Definition smod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let remainder := - Constant.int 0 in + let _ := M.assign_local (| + "remainder" , + Constant.int 0 + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let remainder := + let _ := M.assign_local (| + "remainder" , BinOp.mult (| M.call (| M.get_name (| globals, "get_sign" |), @@ -591,7 +662,8 @@ Definition smod : Value.t -> Value.t -> M := make_dict [] |) |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -628,7 +700,8 @@ Definition addmod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -641,8 +714,10 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -655,8 +730,10 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let z := + |) + |) in + let _ := M.assign_local (| + "z" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -669,7 +746,8 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -687,18 +765,21 @@ Definition addmod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -711,7 +792,8 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -742,7 +824,8 @@ Definition mulmod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -755,8 +838,10 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -769,8 +854,10 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let z := + |) + |) in + let _ := M.assign_local (| + "z" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -783,7 +870,8 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -801,18 +889,21 @@ Definition mulmod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -825,7 +916,8 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -856,7 +948,8 @@ Definition exp : Value.t -> Value.t -> M := The current EVM frame. " in - let base := + let _ := M.assign_local (| + "base" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -869,8 +962,10 @@ Definition exp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exponent := + |) + |) in + let _ := M.assign_local (| + "exponent" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -883,21 +978,26 @@ Definition exp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exponent_bits := + |) + |) in + let _ := M.assign_local (| + "exponent_bits" , M.call (| M.get_field (| M.get_name (| globals, "exponent" |), "bit_length" |), make_list [], make_dict [] - |) in - let exponent_bytes := + |) + |) in + let _ := M.assign_local (| + "exponent_bytes" , BinOp.floor_div (| BinOp.add (| M.get_name (| globals, "exponent_bits" |), Constant.int 7 |), Constant.int 8 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -912,7 +1012,8 @@ Definition exp : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -927,7 +1028,8 @@ Definition exp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -956,22 +1058,26 @@ Definition signextend : Value.t -> Value.t -> M := The current EVM frame. " in - let byte_num := + let _ := M.assign_local (| + "byte_num" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -989,12 +1095,15 @@ Definition signextend : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := - M.get_name (| globals, "value" |) in + let _ := M.assign_local (| + "result" , + M.get_name (| globals, "value" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let value_bytes := + let _ := M.assign_local (| + "value_bytes" , M.call (| M.get_name (| globals, "bytes" |), make_list [ @@ -1005,8 +1114,10 @@ Definition signextend : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let value_bytes := + |) + |) in + let _ := M.assign_local (| + "value_bytes" , M.slice (| M.get_name (| globals, "value_bytes" |), BinOp.sub (| @@ -1021,15 +1132,18 @@ Definition signextend : Value.t -> Value.t -> M := |), Constant.None_, Constant.None_ - |) in - let sign_bit := + |) + |) in + let _ := M.assign_local (| + "sign_bit" , BinOp.r_shift (| M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), Constant.int 7 - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1039,26 +1153,31 @@ Definition signextend : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "value_bytes" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let num_bytes_prepend := + let _ := M.assign_local (| + "num_bytes_prepend" , BinOp.sub (| Constant.int 32, BinOp.add (| M.get_name (| globals, "byte_num" |), Constant.int 1 |) - |) in - let result := + |) + |) in + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -1079,7 +1198,8 @@ Definition signextend : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/bitwise.v b/CoqOfPython/ethereum/constantinople/vm/instructions/bitwise.v index ea48581..76a9113 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/bitwise.v @@ -17,17 +17,23 @@ Introduction Implementations of the EVM bitwise instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "U256_CEIL_VALUE" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_U256_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U256_CEIL_VALUE". -Axiom ethereum_constantinople_vm_imports : - AreImported globals "ethereum.constantinople.vm" [ "Evm" ]. +Axiom ethereum_constantinople_vm_imports_Evm : + IsImported globals "ethereum.constantinople.vm" "Evm". -Axiom ethereum_constantinople_vm_gas_imports : - AreImported globals "ethereum.constantinople.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_constantinople_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_constantinople_vm_gas_imports_charge_gas : + IsImported globals "ethereum.constantinople.vm.gas" "charge_gas". -Axiom ethereum_constantinople_vm_stack_imports : - AreImported globals "ethereum.constantinople.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_constantinople_vm_stack_imports_pop : + IsImported globals "ethereum.constantinople.vm.stack" "pop". +Axiom ethereum_constantinople_vm_stack_imports_push : + IsImported globals "ethereum.constantinople.vm.stack" "push". Definition bitwise_and : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,22 +48,26 @@ Definition bitwise_and : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -97,22 +107,26 @@ Definition bitwise_or : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -152,22 +166,26 @@ Definition bitwise_xor : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -207,14 +225,16 @@ Definition bitwise_not : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -252,22 +272,26 @@ Definition get_byte : Value.t -> Value.t -> M := The current EVM frame. " in - let byte_index := + let _ := M.assign_local (| + "byte_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let word := + |) + |) in + let _ := M.assign_local (| + "word" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -285,43 +309,53 @@ Definition get_byte : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let extra_bytes_to_right := + let _ := M.assign_local (| + "extra_bytes_to_right" , BinOp.sub (| Constant.int 31, M.get_name (| globals, "byte_index" |) - |) in - let word := + |) + |) in + let _ := M.assign_local (| + "word" , BinOp.r_shift (| M.get_name (| globals, "word" |), BinOp.mult (| M.get_name (| globals, "extra_bytes_to_right" |), Constant.int 8 |) - |) in - let word := + |) + |) in + let _ := M.assign_local (| + "word" , BinOp.bit_and (| M.get_name (| globals, "word" |), Constant.int 255 - |) in - let result := + |) + |) in + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ M.get_name (| globals, "word" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -350,22 +384,26 @@ Definition bitwise_shl : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let shift := + let _ := M.assign_local (| + "shift" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -383,7 +421,8 @@ Definition bitwise_shl : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -396,18 +435,21 @@ Definition bitwise_shl : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -436,22 +478,26 @@ Definition bitwise_shr : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let shift := + let _ := M.assign_local (| + "shift" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -469,22 +515,26 @@ Definition bitwise_shr : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , BinOp.r_shift (| M.get_name (| globals, "value" |), M.get_name (| globals, "shift" |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -513,15 +563,18 @@ Definition bitwise_sar : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let shift := + let _ := M.assign_local (| + "shift" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let signed_value := + |) + |) in + let _ := M.assign_local (| + "signed_value" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -532,7 +585,8 @@ Definition bitwise_sar : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -550,7 +604,8 @@ Definition bitwise_sar : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), make_list [ @@ -560,7 +615,8 @@ Definition bitwise_sar : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -573,19 +629,23 @@ Definition bitwise_sar : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := - M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) in + let _ := M.assign_local (| + "result" , + M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/block.v b/CoqOfPython/ethereum/constantinople/vm/instructions/block.v index bfafb33..5481330 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/block.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/block.v @@ -17,17 +17,23 @@ Introduction Implementations of the EVM block instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_constantinople_vm_imports : - AreImported globals "ethereum.constantinople.vm" [ "Evm" ]. +Axiom ethereum_constantinople_vm_imports_Evm : + IsImported globals "ethereum.constantinople.vm" "Evm". -Axiom ethereum_constantinople_vm_gas_imports : - AreImported globals "ethereum.constantinople.vm.gas" [ "GAS_BASE"; "GAS_BLOCK_HASH"; "charge_gas" ]. +Axiom ethereum_constantinople_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_BASE". +Axiom ethereum_constantinople_vm_gas_imports_GAS_BLOCK_HASH : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_BLOCK_HASH". +Axiom ethereum_constantinople_vm_gas_imports_charge_gas : + IsImported globals "ethereum.constantinople.vm.gas" "charge_gas". -Axiom ethereum_constantinople_vm_stack_imports : - AreImported globals "ethereum.constantinople.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_constantinople_vm_stack_imports_pop : + IsImported globals "ethereum.constantinople.vm.stack" "pop". +Axiom ethereum_constantinople_vm_stack_imports_push : + IsImported globals "ethereum.constantinople.vm.stack" "push". Definition block_hash : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,14 +48,16 @@ Definition block_hash : Value.t -> Value.t -> M := The current EVM frame. " in - let block_number := + let _ := M.assign_local (| + "block_number" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -78,19 +86,23 @@ Definition block_hash : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let hash := - Constant.bytes "00" in + let _ := M.assign_local (| + "hash" , + Constant.bytes "00" + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let hash := + let _ := M.assign_local (| + "hash" , M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), M.get_name (| globals, "block_number" |) |) |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/comparison.v b/CoqOfPython/ethereum/constantinople/vm/instructions/comparison.v index e788189..50cbb7f 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/comparison.v @@ -17,17 +17,21 @@ Introduction Implementations of the EVM Comparison instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_constantinople_vm_imports : - AreImported globals "ethereum.constantinople.vm" [ "Evm" ]. +Axiom ethereum_constantinople_vm_imports_Evm : + IsImported globals "ethereum.constantinople.vm" "Evm". -Axiom ethereum_constantinople_vm_gas_imports : - AreImported globals "ethereum.constantinople.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_constantinople_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_constantinople_vm_gas_imports_charge_gas : + IsImported globals "ethereum.constantinople.vm.gas" "charge_gas". -Axiom ethereum_constantinople_vm_stack_imports : - AreImported globals "ethereum.constantinople.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_constantinople_vm_stack_imports_pop : + IsImported globals "ethereum.constantinople.vm.stack" "pop". +Axiom ethereum_constantinople_vm_stack_imports_push : + IsImported globals "ethereum.constantinople.vm.stack" "push". Definition less_than : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,22 +46,26 @@ Definition less_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -66,7 +74,8 @@ Definition less_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -76,7 +85,8 @@ Definition less_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -104,7 +114,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -115,8 +126,10 @@ Definition signed_less_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -127,7 +140,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -136,7 +150,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -146,7 +161,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -175,22 +191,26 @@ Definition greater_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -199,7 +219,8 @@ Definition greater_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -209,7 +230,8 @@ Definition greater_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -237,7 +259,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -248,8 +271,10 @@ Definition signed_greater_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -260,7 +285,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -269,7 +295,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -279,7 +306,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -308,22 +336,26 @@ Definition equal : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -332,7 +364,8 @@ Definition equal : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -342,7 +375,8 @@ Definition equal : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -371,14 +405,16 @@ Definition is_zero : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -387,7 +423,8 @@ Definition is_zero : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -397,7 +434,8 @@ Definition is_zero : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/control_flow.v b/CoqOfPython/ethereum/constantinople/vm/instructions/control_flow.v index 49a0558..4b37436 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/control_flow.v @@ -17,20 +17,32 @@ Introduction Implementations of the EVM control flow instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_constantinople_vm_gas_imports : - AreImported globals "ethereum.constantinople.vm.gas" [ "GAS_BASE"; "GAS_HIGH"; "GAS_JUMPDEST"; "GAS_MID"; "charge_gas" ]. +Axiom ethereum_constantinople_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_BASE". +Axiom ethereum_constantinople_vm_gas_imports_GAS_HIGH : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_HIGH". +Axiom ethereum_constantinople_vm_gas_imports_GAS_JUMPDEST : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_JUMPDEST". +Axiom ethereum_constantinople_vm_gas_imports_GAS_MID : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_MID". +Axiom ethereum_constantinople_vm_gas_imports_charge_gas : + IsImported globals "ethereum.constantinople.vm.gas" "charge_gas". -Axiom ethereum_constantinople_vm_imports : - AreImported globals "ethereum.constantinople.vm" [ "Evm" ]. +Axiom ethereum_constantinople_vm_imports_Evm : + IsImported globals "ethereum.constantinople.vm" "Evm". -Axiom ethereum_constantinople_vm_exceptions_imports : - AreImported globals "ethereum.constantinople.vm.exceptions" [ "InvalidJumpDestError" ]. +Axiom ethereum_constantinople_vm_exceptions_imports_InvalidJumpDestError : + IsImported globals "ethereum.constantinople.vm.exceptions" "InvalidJumpDestError". -Axiom ethereum_constantinople_vm_stack_imports : - AreImported globals "ethereum.constantinople.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_constantinople_vm_stack_imports_pop : + IsImported globals "ethereum.constantinople.vm.stack" "pop". +Axiom ethereum_constantinople_vm_stack_imports_push : + IsImported globals "ethereum.constantinople.vm.stack" "push". Definition stop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -69,7 +81,8 @@ Definition jump : Value.t -> Value.t -> M := The current EVM frame. " in - let jump_dest := + let _ := M.assign_local (| + "jump_dest" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -82,7 +95,8 @@ Definition jump : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -132,7 +146,8 @@ Definition jumpi : Value.t -> Value.t -> M := The current EVM frame. " in - let jump_dest := + let _ := M.assign_local (| + "jump_dest" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -145,15 +160,18 @@ Definition jumpi : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let conditional_value := + |) + |) in + let _ := M.assign_local (| + "conditional_value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -171,11 +189,13 @@ Definition jumpi : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let destination := + let _ := M.assign_local (| + "destination" , BinOp.add (| M.get_field (| M.get_name (| globals, "evm" |), "pc" |), Constant.int 1 - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -192,8 +212,10 @@ Definition jumpi : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let destination := - M.get_name (| globals, "jump_dest" |) in + let _ := M.assign_local (| + "destination" , + M.get_name (| globals, "jump_dest" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/environment.v b/CoqOfPython/ethereum/constantinople/vm/instructions/environment.v index 9c81aed..e6edba3 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/environment.v @@ -17,41 +17,63 @@ Introduction Implementations of the EVM environment related instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_constantinople_fork_types_imports : - AreImported globals "ethereum.constantinople.fork_types" [ "EMPTY_ACCOUNT" ]. +Axiom ethereum_constantinople_fork_types_imports_EMPTY_ACCOUNT : + IsImported globals "ethereum.constantinople.fork_types" "EMPTY_ACCOUNT". -Axiom ethereum_constantinople_state_imports : - AreImported globals "ethereum.constantinople.state" [ "get_account" ]. +Axiom ethereum_constantinople_state_imports_get_account : + IsImported globals "ethereum.constantinople.state" "get_account". -Axiom ethereum_constantinople_utils_address_imports : - AreImported globals "ethereum.constantinople.utils.address" [ "to_address" ]. +Axiom ethereum_constantinople_utils_address_imports_to_address : + IsImported globals "ethereum.constantinople.utils.address" "to_address". -Axiom ethereum_constantinople_vm_memory_imports : - AreImported globals "ethereum.constantinople.vm.memory" [ "buffer_read"; "memory_write" ]. +Axiom ethereum_constantinople_vm_memory_imports_buffer_read : + IsImported globals "ethereum.constantinople.vm.memory" "buffer_read". +Axiom ethereum_constantinople_vm_memory_imports_memory_write : + IsImported globals "ethereum.constantinople.vm.memory" "memory_write". -Axiom ethereum_constantinople_vm_imports : - AreImported globals "ethereum.constantinople.vm" [ "Evm" ]. +Axiom ethereum_constantinople_vm_imports_Evm : + IsImported globals "ethereum.constantinople.vm" "Evm". -Axiom ethereum_constantinople_vm_exceptions_imports : - AreImported globals "ethereum.constantinople.vm.exceptions" [ "OutOfBoundsRead" ]. +Axiom ethereum_constantinople_vm_exceptions_imports_OutOfBoundsRead : + IsImported globals "ethereum.constantinople.vm.exceptions" "OutOfBoundsRead". -Axiom ethereum_constantinople_vm_gas_imports : - AreImported globals "ethereum.constantinople.vm.gas" [ "GAS_BALANCE"; "GAS_BASE"; "GAS_CODE_HASH"; "GAS_COPY"; "GAS_EXTERNAL"; "GAS_RETURN_DATA_COPY"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_constantinople_vm_gas_imports_GAS_BALANCE : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_BALANCE". +Axiom ethereum_constantinople_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_BASE". +Axiom ethereum_constantinople_vm_gas_imports_GAS_CODE_HASH : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_CODE_HASH". +Axiom ethereum_constantinople_vm_gas_imports_GAS_COPY : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_COPY". +Axiom ethereum_constantinople_vm_gas_imports_GAS_EXTERNAL : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_EXTERNAL". +Axiom ethereum_constantinople_vm_gas_imports_GAS_RETURN_DATA_COPY : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_RETURN_DATA_COPY". +Axiom ethereum_constantinople_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_constantinople_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.constantinople.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_constantinople_vm_gas_imports_charge_gas : + IsImported globals "ethereum.constantinople.vm.gas" "charge_gas". -Axiom ethereum_constantinople_vm_stack_imports : - AreImported globals "ethereum.constantinople.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_constantinople_vm_stack_imports_pop : + IsImported globals "ethereum.constantinople.vm.stack" "pop". +Axiom ethereum_constantinople_vm_stack_imports_push : + IsImported globals "ethereum.constantinople.vm.stack" "push". Definition address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -107,7 +129,8 @@ Definition balance : Value.t -> Value.t -> M := The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -120,7 +143,8 @@ Definition balance : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -129,7 +153,8 @@ Definition balance : Value.t -> Value.t -> M := ], make_dict [] |) in - let balance := + let _ := M.assign_local (| + "balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -137,7 +162,8 @@ Definition balance : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -287,14 +313,16 @@ Definition calldataload : Value.t -> Value.t -> M := The current EVM frame. " in - let start_index := + let _ := M.assign_local (| + "start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -303,7 +331,8 @@ Definition calldataload : Value.t -> Value.t -> M := ], make_dict [] |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -318,7 +347,8 @@ Definition calldataload : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -403,31 +433,38 @@ Definition calldatacopy : Value.t -> Value.t -> M := The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let data_start_index := + |) + |) in + let _ := M.assign_local (| + "data_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -443,13 +480,17 @@ Definition calldatacopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -459,7 +500,8 @@ Definition calldatacopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -482,7 +524,8 @@ Definition calldatacopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -491,7 +534,8 @@ Definition calldatacopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -571,31 +615,38 @@ Definition codecopy : Value.t -> Value.t -> M := The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let code_start_index := + |) + |) in + let _ := M.assign_local (| + "code_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -611,13 +662,17 @@ Definition codecopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -627,7 +682,8 @@ Definition codecopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -650,7 +706,8 @@ Definition codecopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -659,7 +716,8 @@ Definition codecopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -730,7 +788,8 @@ Definition extcodesize : Value.t -> Value.t -> M := The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -743,7 +802,8 @@ Definition extcodesize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -752,7 +812,8 @@ Definition extcodesize : Value.t -> Value.t -> M := ], make_dict [] |) in - let codesize := + let _ := M.assign_local (| + "codesize" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -772,7 +833,8 @@ Definition extcodesize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -800,7 +862,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -813,32 +876,40 @@ Definition extcodecopy : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let memory_start_index := + |) + |) in + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let code_start_index := + |) + |) in + let _ := M.assign_local (| + "code_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -854,13 +925,17 @@ Definition extcodecopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -870,7 +945,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -893,7 +969,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let code := + let _ := M.assign_local (| + "code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -901,8 +978,10 @@ Definition extcodecopy : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |), "code" |) in - let value := + |), "code" |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -911,7 +990,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -986,31 +1066,38 @@ Definition returndatacopy : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let return_data_start_position := + |) + |) in + let _ := M.assign_local (| + "return_data_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -1026,13 +1113,17 @@ Definition returndatacopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_RETURN_DATA_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1042,7 +1133,8 @@ Definition returndatacopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1097,7 +1189,8 @@ Definition returndatacopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.slice (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |), @@ -1106,7 +1199,8 @@ Definition returndatacopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) |), Constant.None_ - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -1133,7 +1227,8 @@ Definition extcodehash : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1146,7 +1241,8 @@ Definition extcodehash : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1155,7 +1251,8 @@ Definition extcodehash : Value.t -> Value.t -> M := ], make_dict [] |) in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1163,7 +1260,8 @@ Definition extcodehash : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1173,18 +1271,21 @@ Definition extcodehash : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let codehash := + let _ := M.assign_local (| + "codehash" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let codehash := + let _ := M.assign_local (| + "codehash" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -1197,7 +1298,8 @@ Definition extcodehash : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/keccak.v b/CoqOfPython/ethereum/constantinople/vm/instructions/keccak.v index db3696a..8e00e8f 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/keccak.v @@ -17,26 +17,36 @@ Introduction Implementations of the EVM keccak instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_constantinople_vm_imports : - AreImported globals "ethereum.constantinople.vm" [ "Evm" ]. +Axiom ethereum_constantinople_vm_imports_Evm : + IsImported globals "ethereum.constantinople.vm" "Evm". -Axiom ethereum_constantinople_vm_gas_imports : - AreImported globals "ethereum.constantinople.vm.gas" [ "GAS_KECCAK256"; "GAS_KECCAK256_WORD"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_constantinople_vm_gas_imports_GAS_KECCAK256 : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_KECCAK256". +Axiom ethereum_constantinople_vm_gas_imports_GAS_KECCAK256_WORD : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_KECCAK256_WORD". +Axiom ethereum_constantinople_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.constantinople.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_constantinople_vm_gas_imports_charge_gas : + IsImported globals "ethereum.constantinople.vm.gas" "charge_gas". -Axiom ethereum_constantinople_vm_memory_imports : - AreImported globals "ethereum.constantinople.vm.memory" [ "memory_read_bytes" ]. +Axiom ethereum_constantinople_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.constantinople.vm.memory" "memory_read_bytes". -Axiom ethereum_constantinople_vm_stack_imports : - AreImported globals "ethereum.constantinople.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_constantinople_vm_stack_imports_pop : + IsImported globals "ethereum.constantinople.vm.stack" "pop". +Axiom ethereum_constantinople_vm_stack_imports_push : + IsImported globals "ethereum.constantinople.vm.stack" "push". Definition keccak : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -53,23 +63,28 @@ Definition keccak : Value.t -> Value.t -> M := The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -85,13 +100,17 @@ Definition keccak : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let word_gas_cost := + |) + |) in + let _ := M.assign_local (| + "word_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_KECCAK256_WORD" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -101,7 +120,8 @@ Definition keccak : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -124,7 +144,8 @@ Definition keccak : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let data := + let _ := M.assign_local (| + "data" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -133,15 +154,18 @@ Definition keccak : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in - let hash := + |) + |) in + let _ := M.assign_local (| + "hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "data" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/log.v b/CoqOfPython/ethereum/constantinople/vm/instructions/log.v index 62c5f01..51269e5 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/log.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/log.v @@ -17,32 +17,40 @@ Introduction Implementations of the EVM logging instructions. ". -Axiom functools_imports : - AreImported globals "functools" [ "partial" ]. +Axiom functools_imports_partial : + IsImported globals "functools" "partial". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_constantinople_blocks_imports : - AreImported globals "ethereum.constantinople.blocks" [ "Log" ]. +Axiom ethereum_constantinople_blocks_imports_Log : + IsImported globals "ethereum.constantinople.blocks" "Log". -Axiom ethereum_constantinople_vm_imports : - AreImported globals "ethereum.constantinople.vm" [ "Evm" ]. +Axiom ethereum_constantinople_vm_imports_Evm : + IsImported globals "ethereum.constantinople.vm" "Evm". -Axiom ethereum_constantinople_vm_exceptions_imports : - AreImported globals "ethereum.constantinople.vm.exceptions" [ "WriteInStaticContext" ]. +Axiom ethereum_constantinople_vm_exceptions_imports_WriteInStaticContext : + IsImported globals "ethereum.constantinople.vm.exceptions" "WriteInStaticContext". -Axiom ethereum_constantinople_vm_gas_imports : - AreImported globals "ethereum.constantinople.vm.gas" [ "GAS_LOG"; "GAS_LOG_DATA"; "GAS_LOG_TOPIC"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_constantinople_vm_gas_imports_GAS_LOG : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_LOG". +Axiom ethereum_constantinople_vm_gas_imports_GAS_LOG_DATA : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_LOG_DATA". +Axiom ethereum_constantinople_vm_gas_imports_GAS_LOG_TOPIC : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_LOG_TOPIC". +Axiom ethereum_constantinople_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.constantinople.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_constantinople_vm_gas_imports_charge_gas : + IsImported globals "ethereum.constantinople.vm.gas" "charge_gas". -Axiom ethereum_constantinople_vm_memory_imports : - AreImported globals "ethereum.constantinople.vm.memory" [ "memory_read_bytes" ]. +Axiom ethereum_constantinople_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.constantinople.vm.memory" "memory_read_bytes". -Axiom ethereum_constantinople_vm_stack_imports : - AreImported globals "ethereum.constantinople.vm.stack" [ "pop" ]. +Axiom ethereum_constantinople_vm_stack_imports_pop : + IsImported globals "ethereum.constantinople.vm.stack" "pop". Definition log_n : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -61,24 +69,30 @@ Definition log_n : Value.t -> Value.t -> M := The number of topics to be included in the log entry. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let topics := - make_list [] in + |) + |) in + let _ := M.assign_local (| + "topics" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "_" |), @@ -90,7 +104,8 @@ Definition log_n : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let topic := + let _ := M.assign_local (| + "topic" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -101,7 +116,8 @@ Definition log_n : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "topics" |), "append" |), make_list [ @@ -115,7 +131,8 @@ Definition log_n : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let extend_memory := + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -125,7 +142,8 @@ Definition log_n : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -165,12 +183,14 @@ Definition log_n : Value.t -> Value.t -> M := ], make_dict [] |) in - let log_entry := + let _ := M.assign_local (| + "log_entry" , M.call (| M.get_name (| globals, "Log" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "logs" |), BinOp.add (| diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/memory.v b/CoqOfPython/ethereum/constantinople/vm/instructions/memory.v index 6465028..9b9ada6 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/memory.v @@ -17,20 +17,32 @@ Introduction Implementations of the EVM Memory instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". -Axiom ethereum_constantinople_vm_imports : - AreImported globals "ethereum.constantinople.vm" [ "Evm" ]. +Axiom ethereum_constantinople_vm_imports_Evm : + IsImported globals "ethereum.constantinople.vm" "Evm". -Axiom ethereum_constantinople_vm_gas_imports : - AreImported globals "ethereum.constantinople.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_constantinople_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_BASE". +Axiom ethereum_constantinople_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_constantinople_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.constantinople.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_constantinople_vm_gas_imports_charge_gas : + IsImported globals "ethereum.constantinople.vm.gas" "charge_gas". -Axiom ethereum_constantinople_vm_memory_imports : - AreImported globals "ethereum.constantinople.vm.memory" [ "memory_read_bytes"; "memory_write" ]. +Axiom ethereum_constantinople_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.constantinople.vm.memory" "memory_read_bytes". +Axiom ethereum_constantinople_vm_memory_imports_memory_write : + IsImported globals "ethereum.constantinople.vm.memory" "memory_write". -Axiom ethereum_constantinople_vm_stack_imports : - AreImported globals "ethereum.constantinople.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_constantinople_vm_stack_imports_pop : + IsImported globals "ethereum.constantinople.vm.stack" "pop". +Axiom ethereum_constantinople_vm_stack_imports_push : + IsImported globals "ethereum.constantinople.vm.stack" "push". Definition mstore : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -46,15 +58,18 @@ Definition mstore : Value.t -> Value.t -> M := The current EVM frame. " in - let start_position := + let _ := M.assign_local (| + "start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -65,8 +80,10 @@ Definition mstore : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -88,7 +105,8 @@ Definition mstore : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -138,23 +156,28 @@ Definition mstore8 : Value.t -> Value.t -> M := The current EVM frame. " in - let start_position := + let _ := M.assign_local (| + "start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -170,7 +193,8 @@ Definition mstore8 : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -190,7 +214,8 @@ Definition mstore8 : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let normalized_bytes_value := + let _ := M.assign_local (| + "normalized_bytes_value" , M.call (| M.get_name (| globals, "Bytes" |), make_list [ @@ -202,7 +227,8 @@ Definition mstore8 : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -231,15 +257,18 @@ Definition mload : Value.t -> Value.t -> M := The current EVM frame. " in - let start_position := + let _ := M.assign_local (| + "start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -255,7 +284,8 @@ Definition mload : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -275,7 +305,8 @@ Definition mload : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -296,7 +327,8 @@ Definition mload : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/stack.v b/CoqOfPython/ethereum/constantinople/vm/instructions/stack.v index 3e6170d..a87c0aa 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/stack.v @@ -17,26 +17,32 @@ Introduction Implementations of the EVM stack related instructions. ". -Axiom functools_imports : - AreImported globals "functools" [ "partial" ]. +Axiom functools_imports_partial : + IsImported globals "functools" "partial". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_constantinople_vm_imports : - AreImported globals "ethereum.constantinople.vm" [ "Evm"; "stack" ]. +Axiom ethereum_constantinople_vm_imports_Evm : + IsImported globals "ethereum.constantinople.vm" "Evm". +Axiom ethereum_constantinople_vm_imports_stack : + IsImported globals "ethereum.constantinople.vm" "stack". -Axiom ethereum_constantinople_vm_exceptions_imports : - AreImported globals "ethereum.constantinople.vm.exceptions" [ "StackUnderflowError" ]. +Axiom ethereum_constantinople_vm_exceptions_imports_StackUnderflowError : + IsImported globals "ethereum.constantinople.vm.exceptions" "StackUnderflowError". -Axiom ethereum_constantinople_vm_gas_imports : - AreImported globals "ethereum.constantinople.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_constantinople_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_BASE". +Axiom ethereum_constantinople_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_constantinople_vm_gas_imports_charge_gas : + IsImported globals "ethereum.constantinople.vm.gas" "charge_gas". -Axiom ethereum_constantinople_vm_memory_imports : - AreImported globals "ethereum.constantinople.vm.memory" [ "buffer_read" ]. +Axiom ethereum_constantinople_vm_memory_imports_buffer_read : + IsImported globals "ethereum.constantinople.vm.memory" "buffer_read". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -98,7 +104,8 @@ Definition push_n : Value.t -> Value.t -> M := ], make_dict [] |) in - let data_to_push := + let _ := M.assign_local (| + "data_to_push" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -128,7 +135,8 @@ Definition push_n : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "stack" |), "push" |), make_list [ @@ -189,7 +197,8 @@ Definition dup_n : Value.t -> Value.t -> M := ], make_dict [] |) in - let data_to_duplicate := + let _ := M.assign_local (| + "data_to_duplicate" , M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| @@ -205,7 +214,8 @@ Definition dup_n : Value.t -> Value.t -> M := |), M.get_name (| globals, "item_number" |) |) - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "stack" |), "push" |), make_list [ diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/storage.v b/CoqOfPython/ethereum/constantinople/vm/instructions/storage.v index bbea490..95bb7fb 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/storage.v @@ -17,23 +17,35 @@ Introduction Implementations of the EVM storage related instructions. ". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_constantinople_state_imports : - AreImported globals "ethereum.constantinople.state" [ "get_storage"; "set_storage" ]. - -Axiom ethereum_constantinople_vm_imports : - AreImported globals "ethereum.constantinople.vm" [ "Evm" ]. - -Axiom ethereum_constantinople_vm_exceptions_imports : - AreImported globals "ethereum.constantinople.vm.exceptions" [ "WriteInStaticContext" ]. - -Axiom ethereum_constantinople_vm_gas_imports : - AreImported globals "ethereum.constantinople.vm.gas" [ "GAS_SLOAD"; "GAS_STORAGE_CLEAR_REFUND"; "GAS_STORAGE_SET"; "GAS_STORAGE_UPDATE"; "charge_gas" ]. - -Axiom ethereum_constantinople_vm_stack_imports : - AreImported globals "ethereum.constantinople.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_constantinople_state_imports_get_storage : + IsImported globals "ethereum.constantinople.state" "get_storage". +Axiom ethereum_constantinople_state_imports_set_storage : + IsImported globals "ethereum.constantinople.state" "set_storage". + +Axiom ethereum_constantinople_vm_imports_Evm : + IsImported globals "ethereum.constantinople.vm" "Evm". + +Axiom ethereum_constantinople_vm_exceptions_imports_WriteInStaticContext : + IsImported globals "ethereum.constantinople.vm.exceptions" "WriteInStaticContext". + +Axiom ethereum_constantinople_vm_gas_imports_GAS_SLOAD : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_SLOAD". +Axiom ethereum_constantinople_vm_gas_imports_GAS_STORAGE_CLEAR_REFUND : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_STORAGE_CLEAR_REFUND". +Axiom ethereum_constantinople_vm_gas_imports_GAS_STORAGE_SET : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_STORAGE_SET". +Axiom ethereum_constantinople_vm_gas_imports_GAS_STORAGE_UPDATE : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_STORAGE_UPDATE". +Axiom ethereum_constantinople_vm_gas_imports_charge_gas : + IsImported globals "ethereum.constantinople.vm.gas" "charge_gas". + +Axiom ethereum_constantinople_vm_stack_imports_pop : + IsImported globals "ethereum.constantinople.vm.stack" "pop". +Axiom ethereum_constantinople_vm_stack_imports_push : + IsImported globals "ethereum.constantinople.vm.stack" "push". Definition sload : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -48,7 +60,8 @@ Definition sload : Value.t -> Value.t -> M := The current EVM frame. " in - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -59,7 +72,8 @@ Definition sload : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -68,7 +82,8 @@ Definition sload : Value.t -> Value.t -> M := ], make_dict [] |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "get_storage" |), make_list [ @@ -77,7 +92,8 @@ Definition sload : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -105,7 +121,8 @@ Definition sstore : Value.t -> Value.t -> M := The current EVM frame. " in - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -116,16 +133,20 @@ Definition sstore : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in - let new_value := + |) + |) in + let _ := M.assign_local (| + "new_value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let current_value := + |) + |) in + let _ := M.assign_local (| + "current_value" , M.call (| M.get_name (| globals, "get_storage" |), make_list [ @@ -134,7 +155,8 @@ Definition sstore : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -152,13 +174,17 @@ Definition sstore : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let gas_cost := - M.get_name (| globals, "GAS_STORAGE_SET" |) in + let _ := M.assign_local (| + "gas_cost" , + M.get_name (| globals, "GAS_STORAGE_SET" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let gas_cost := - M.get_name (| globals, "GAS_STORAGE_UPDATE" |) in + let _ := M.assign_local (| + "gas_cost" , + M.get_name (| globals, "GAS_STORAGE_UPDATE" |) + |) in M.pure Constant.None_ )) |) in let _ := diff --git a/CoqOfPython/ethereum/constantinople/vm/instructions/system.v b/CoqOfPython/ethereum/constantinople/vm/instructions/system.v index 08e6802..d27c09f 100644 --- a/CoqOfPython/ethereum/constantinople/vm/instructions/system.v +++ b/CoqOfPython/ethereum/constantinople/vm/instructions/system.v @@ -17,38 +17,92 @@ Introduction Implementations of the EVM system related instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_constantinople_fork_types_imports : - AreImported globals "ethereum.constantinople.fork_types" [ "Address" ]. +Axiom ethereum_constantinople_fork_types_imports_Address : + IsImported globals "ethereum.constantinople.fork_types" "Address". -Axiom ethereum_constantinople_state_imports : - AreImported globals "ethereum.constantinople.state" [ "account_exists_and_is_empty"; "account_has_code_or_nonce"; "get_account"; "increment_nonce"; "is_account_alive"; "set_account_balance" ]. +Axiom ethereum_constantinople_state_imports_account_exists_and_is_empty : + IsImported globals "ethereum.constantinople.state" "account_exists_and_is_empty". +Axiom ethereum_constantinople_state_imports_account_has_code_or_nonce : + IsImported globals "ethereum.constantinople.state" "account_has_code_or_nonce". +Axiom ethereum_constantinople_state_imports_get_account : + IsImported globals "ethereum.constantinople.state" "get_account". +Axiom ethereum_constantinople_state_imports_increment_nonce : + IsImported globals "ethereum.constantinople.state" "increment_nonce". +Axiom ethereum_constantinople_state_imports_is_account_alive : + IsImported globals "ethereum.constantinople.state" "is_account_alive". +Axiom ethereum_constantinople_state_imports_set_account_balance : + IsImported globals "ethereum.constantinople.state" "set_account_balance". -Axiom ethereum_constantinople_utils_address_imports : - AreImported globals "ethereum.constantinople.utils.address" [ "compute_contract_address"; "compute_create2_contract_address"; "to_address" ]. +Axiom ethereum_constantinople_utils_address_imports_compute_contract_address : + IsImported globals "ethereum.constantinople.utils.address" "compute_contract_address". +Axiom ethereum_constantinople_utils_address_imports_compute_create2_contract_address : + IsImported globals "ethereum.constantinople.utils.address" "compute_create2_contract_address". +Axiom ethereum_constantinople_utils_address_imports_to_address : + IsImported globals "ethereum.constantinople.utils.address" "to_address". -Axiom ethereum_constantinople_vm_imports : - AreImported globals "ethereum.constantinople.vm" [ "Evm"; "Message"; "incorporate_child_on_error"; "incorporate_child_on_success" ]. +Axiom ethereum_constantinople_vm_imports_Evm : + IsImported globals "ethereum.constantinople.vm" "Evm". +Axiom ethereum_constantinople_vm_imports_Message : + IsImported globals "ethereum.constantinople.vm" "Message". +Axiom ethereum_constantinople_vm_imports_incorporate_child_on_error : + IsImported globals "ethereum.constantinople.vm" "incorporate_child_on_error". +Axiom ethereum_constantinople_vm_imports_incorporate_child_on_success : + IsImported globals "ethereum.constantinople.vm" "incorporate_child_on_success". -Axiom ethereum_constantinople_vm_exceptions_imports : - AreImported globals "ethereum.constantinople.vm.exceptions" [ "Revert"; "WriteInStaticContext" ]. +Axiom ethereum_constantinople_vm_exceptions_imports_Revert : + IsImported globals "ethereum.constantinople.vm.exceptions" "Revert". +Axiom ethereum_constantinople_vm_exceptions_imports_WriteInStaticContext : + IsImported globals "ethereum.constantinople.vm.exceptions" "WriteInStaticContext". -Axiom ethereum_constantinople_vm_gas_imports : - AreImported globals "ethereum.constantinople.vm.gas" [ "GAS_CALL"; "GAS_CALL_VALUE"; "GAS_CREATE"; "GAS_KECCAK256_WORD"; "GAS_NEW_ACCOUNT"; "GAS_SELF_DESTRUCT"; "GAS_SELF_DESTRUCT_NEW_ACCOUNT"; "GAS_ZERO"; "REFUND_SELF_DESTRUCT"; "calculate_gas_extend_memory"; "calculate_message_call_gas"; "charge_gas"; "max_message_call_gas" ]. +Axiom ethereum_constantinople_vm_gas_imports_GAS_CALL : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_CALL". +Axiom ethereum_constantinople_vm_gas_imports_GAS_CALL_VALUE : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_CALL_VALUE". +Axiom ethereum_constantinople_vm_gas_imports_GAS_CREATE : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_CREATE". +Axiom ethereum_constantinople_vm_gas_imports_GAS_KECCAK256_WORD : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_KECCAK256_WORD". +Axiom ethereum_constantinople_vm_gas_imports_GAS_NEW_ACCOUNT : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_NEW_ACCOUNT". +Axiom ethereum_constantinople_vm_gas_imports_GAS_SELF_DESTRUCT : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_SELF_DESTRUCT". +Axiom ethereum_constantinople_vm_gas_imports_GAS_SELF_DESTRUCT_NEW_ACCOUNT : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_SELF_DESTRUCT_NEW_ACCOUNT". +Axiom ethereum_constantinople_vm_gas_imports_GAS_ZERO : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_ZERO". +Axiom ethereum_constantinople_vm_gas_imports_REFUND_SELF_DESTRUCT : + IsImported globals "ethereum.constantinople.vm.gas" "REFUND_SELF_DESTRUCT". +Axiom ethereum_constantinople_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.constantinople.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_constantinople_vm_gas_imports_calculate_message_call_gas : + IsImported globals "ethereum.constantinople.vm.gas" "calculate_message_call_gas". +Axiom ethereum_constantinople_vm_gas_imports_charge_gas : + IsImported globals "ethereum.constantinople.vm.gas" "charge_gas". +Axiom ethereum_constantinople_vm_gas_imports_max_message_call_gas : + IsImported globals "ethereum.constantinople.vm.gas" "max_message_call_gas". -Axiom ethereum_constantinople_vm_memory_imports : - AreImported globals "ethereum.constantinople.vm.memory" [ "memory_read_bytes"; "memory_write" ]. +Axiom ethereum_constantinople_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.constantinople.vm.memory" "memory_read_bytes". +Axiom ethereum_constantinople_vm_memory_imports_memory_write : + IsImported globals "ethereum.constantinople.vm.memory" "memory_write". -Axiom ethereum_constantinople_vm_stack_imports : - AreImported globals "ethereum.constantinople.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_constantinople_vm_stack_imports_pop : + IsImported globals "ethereum.constantinople.vm.stack" "pop". +Axiom ethereum_constantinople_vm_stack_imports_push : + IsImported globals "ethereum.constantinople.vm.stack" "push". Definition generic_create : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -57,7 +111,8 @@ Definition generic_create : Value.t -> Value.t -> M := Core logic used by the `CREATE*` family of opcodes. " in (* At stmt: unsupported node type: ImportFrom *) - let create_message_gas := + let _ := M.assign_local (| + "create_message_gas" , M.call (| M.get_name (| globals, "max_message_call_gas" |), make_list [ @@ -70,7 +125,8 @@ Definition generic_create : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.assign_op (| BinOp.sub, M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), @@ -88,9 +144,12 @@ Definition generic_create : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), Constant.bytes "" |) in - let sender_address := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in - let sender := + let _ := M.assign_local (| + "sender_address" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + |) in + let _ := M.assign_local (| + "sender" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -98,7 +157,8 @@ Definition generic_create : Value.t -> Value.t -> M := M.get_name (| globals, "sender_address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -209,7 +269,8 @@ Definition generic_create : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let call_data := + let _ := M.assign_local (| + "call_data" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -218,7 +279,8 @@ Definition generic_create : Value.t -> Value.t -> M := M.get_name (| globals, "memory_size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "increment_nonce" |), make_list [ @@ -227,13 +289,16 @@ Definition generic_create : Value.t -> Value.t -> M := ], make_dict [] |) in - let child_message := + let _ := M.assign_local (| + "child_message" , M.call (| M.get_name (| globals, "Message" |), make_list [], make_dict [] - |) in - let child_evm := + |) + |) in + let _ := M.assign_local (| + "child_evm" , M.call (| M.get_name (| globals, "process_create_message" |), make_list [ @@ -241,7 +306,8 @@ Definition generic_create : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -318,31 +384,38 @@ Definition create : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let endowment := + let _ := M.assign_local (| + "endowment" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_size := + |) + |) in + let _ := M.assign_local (| + "memory_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -352,7 +425,8 @@ Definition create : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -372,7 +446,8 @@ Definition create : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let contract_address := + let _ := M.assign_local (| + "contract_address" , M.call (| M.get_name (| globals, "compute_contract_address" |), make_list [ @@ -387,7 +462,8 @@ Definition create : Value.t -> Value.t -> M := |), "nonce" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "generic_create" |), make_list [ @@ -420,31 +496,38 @@ Definition create2 : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let endowment := + let _ := M.assign_local (| + "endowment" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_size := + |) + |) in + let _ := M.assign_local (| + "memory_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let salt := + |) + |) in + let _ := M.assign_local (| + "salt" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -455,8 +538,10 @@ Definition create2 : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -466,8 +551,10 @@ Definition create2 : Value.t -> Value.t -> M := ] ], make_dict [] - |) in - let call_data_words := + |) + |) in + let _ := M.assign_local (| + "call_data_words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -483,7 +570,8 @@ Definition create2 : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -509,7 +597,8 @@ Definition create2 : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let contract_address := + let _ := M.assign_local (| + "contract_address" , M.call (| M.get_name (| globals, "compute_create2_contract_address" |), make_list [ @@ -526,7 +615,8 @@ Definition create2 : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "generic_create" |), make_list [ @@ -556,23 +646,28 @@ Definition return_ : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let memory_start_position := + let _ := M.assign_local (| + "memory_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_size := + |) + |) in + let _ := M.assign_local (| + "memory_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -582,7 +677,8 @@ Definition return_ : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -671,7 +767,8 @@ Definition generic_call : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let call_data := + let _ := M.assign_local (| + "call_data" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -680,8 +777,10 @@ Definition generic_call : Value.t -> Value.t -> M := M.get_name (| globals, "memory_input_size" |) ], make_dict [] - |) in - let code := + |) + |) in + let _ := M.assign_local (| + "code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -689,14 +788,18 @@ Definition generic_call : Value.t -> Value.t -> M := M.get_name (| globals, "code_address" |) ], make_dict [] - |), "code" |) in - let child_message := + |), "code" |) + |) in + let _ := M.assign_local (| + "child_message" , M.call (| M.get_name (| globals, "Message" |), make_list [], make_dict [] - |) in - let child_evm := + |) + |) in + let _ := M.assign_local (| + "child_evm" , M.call (| M.get_name (| globals, "process_message" |), make_list [ @@ -704,7 +807,8 @@ Definition generic_call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -768,7 +872,8 @@ Definition generic_call : Value.t -> Value.t -> M := |) in M.pure Constant.None_ )) |) in - let actual_output_size := + let _ := M.assign_local (| + "actual_output_size" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -788,7 +893,8 @@ Definition generic_call : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -816,7 +922,8 @@ Definition call : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -829,8 +936,10 @@ Definition call : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let to := + |) + |) in + let _ := M.assign_local (| + "to" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -843,48 +952,60 @@ Definition call : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -895,8 +1016,10 @@ Definition call : Value.t -> Value.t -> M := ] ], make_dict [] - |) in - let create_gas_cost := + |) + |) in + let _ := M.assign_local (| + "create_gas_cost" , (* if *) M.if_then_else (| BoolOp.or (| @@ -927,8 +1050,10 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "GAS_NEW_ACCOUNT" |) - )) |) in - let transfer_gas_cost := + )) |) + |) in + let _ := M.assign_local (| + "transfer_gas_cost" , (* if *) M.if_then_else (| Compare.eq (| @@ -947,8 +1072,10 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "GAS_CALL_VALUE" |) - )) |) in - let message_call_gas := + )) |) + |) in + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -971,7 +1098,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1013,7 +1141,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let sender_balance := + let _ := M.assign_local (| + "sender_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1021,7 +1150,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := (* if *) M.if_then_else (| @@ -1095,7 +1225,8 @@ Definition callcode : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -1108,8 +1239,10 @@ Definition callcode : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let code_address := + |) + |) in + let _ := M.assign_local (| + "code_address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1122,50 +1255,64 @@ Definition callcode : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let to := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "to" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1176,8 +1323,10 @@ Definition callcode : Value.t -> Value.t -> M := ] ], make_dict [] - |) in - let transfer_gas_cost := + |) + |) in + let _ := M.assign_local (| + "transfer_gas_cost" , (* if *) M.if_then_else (| Compare.eq (| @@ -1196,8 +1345,10 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "GAS_CALL_VALUE" |) - )) |) in - let message_call_gas := + )) |) + |) in + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -1217,7 +1368,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1237,7 +1389,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let sender_balance := + let _ := M.assign_local (| + "sender_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1245,7 +1398,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := (* if *) M.if_then_else (| @@ -1319,7 +1473,8 @@ Definition selfdestruct : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let beneficiary := + let _ := M.assign_local (| + "beneficiary" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1332,9 +1487,12 @@ Definition selfdestruct : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let gas_cost := - M.get_name (| globals, "GAS_SELF_DESTRUCT" |) in + |) + |) in + let _ := M.assign_local (| + "gas_cost" , + M.get_name (| globals, "GAS_SELF_DESTRUCT" |) + |) in let _ := (* if *) M.if_then_else (| @@ -1363,20 +1521,28 @@ Definition selfdestruct : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let gas_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "gas_cost", M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) - M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let originator := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in - let refunded_accounts := - M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in - let parent_evm := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "parent_evm" |) in + let _ := M.assign_local (| + "originator" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + |) in + let _ := M.assign_local (| + "refunded_accounts" , + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) + |) in + let _ := M.assign_local (| + "parent_evm" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "parent_evm" |) + |) in let _ := M.while (| Compare.is_not (| @@ -1391,8 +1557,10 @@ Definition selfdestruct : Value.t -> Value.t -> M := ], make_dict [] |) in - let parent_evm := - M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in + let _ := M.assign_local (| + "parent_evm" , + M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -1434,7 +1602,8 @@ Definition selfdestruct : Value.t -> Value.t -> M := ], make_dict [] |) in - let beneficiary_balance := + let _ := M.assign_local (| + "beneficiary_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1442,8 +1611,10 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_name (| globals, "beneficiary" |) ], make_dict [] - |), "balance" |) in - let originator_balance := + |), "balance" |) + |) in + let _ := M.assign_local (| + "originator_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1451,7 +1622,8 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_name (| globals, "originator" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -1529,7 +1701,8 @@ Definition delegatecall : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -1542,8 +1715,10 @@ Definition delegatecall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let code_address := + |) + |) in + let _ := M.assign_local (| + "code_address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1556,40 +1731,50 @@ Definition delegatecall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1600,8 +1785,10 @@ Definition delegatecall : Value.t -> Value.t -> M := ] ], make_dict [] - |) in - let message_call_gas := + |) + |) in + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -1624,7 +1811,8 @@ Definition delegatecall : Value.t -> Value.t -> M := M.get_name (| globals, "GAS_CALL" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1680,7 +1868,8 @@ Definition staticcall : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -1693,8 +1882,10 @@ Definition staticcall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let to := + |) + |) in + let _ := M.assign_local (| + "to" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1707,40 +1898,50 @@ Definition staticcall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1751,8 +1952,10 @@ Definition staticcall : Value.t -> Value.t -> M := ] ], make_dict [] - |) in - let message_call_gas := + |) + |) in + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -1775,7 +1978,8 @@ Definition staticcall : Value.t -> Value.t -> M := M.get_name (| globals, "GAS_CALL" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1837,23 +2041,28 @@ Definition revert : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1863,7 +2072,8 @@ Definition revert : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1880,7 +2090,8 @@ Definition revert : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let output := + let _ := M.assign_local (| + "output" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -1889,7 +2100,8 @@ Definition revert : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| diff --git a/CoqOfPython/ethereum/constantinople/vm/interpreter.v b/CoqOfPython/ethereum/constantinople/vm/interpreter.v index b005455..b589da7 100644 --- a/CoqOfPython/ethereum/constantinople/vm/interpreter.v +++ b/CoqOfPython/ethereum/constantinople/vm/interpreter.v @@ -17,50 +17,108 @@ Introduction A straightforward interpreter that executes EVM code. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Iterable"; "Optional"; "Set"; "Tuple" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. - -Axiom ethereum_trace_imports : - AreImported globals "ethereum.trace" [ "EvmStop"; "OpEnd"; "OpException"; "OpStart"; "PrecompileEnd"; "PrecompileStart"; "TransactionEnd"; "evm_trace" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_constantinople_blocks_imports : - AreImported globals "ethereum.constantinople.blocks" [ "Log" ]. - -Axiom ethereum_constantinople_fork_types_imports : - AreImported globals "ethereum.constantinople.fork_types" [ "Address" ]. - -Axiom ethereum_constantinople_state_imports : - AreImported globals "ethereum.constantinople.state" [ "account_exists_and_is_empty"; "account_has_code_or_nonce"; "begin_transaction"; "commit_transaction"; "destroy_storage"; "increment_nonce"; "move_ether"; "rollback_transaction"; "set_code"; "touch_account" ]. - -Axiom ethereum_constantinople_vm_imports : - AreImported globals "ethereum.constantinople.vm" [ "Message" ]. - -Axiom ethereum_constantinople_vm_gas_imports : - AreImported globals "ethereum.constantinople.vm.gas" [ "GAS_CODE_DEPOSIT"; "charge_gas" ]. - -Axiom ethereum_constantinople_vm_precompiled_contracts_mapping_imports : - AreImported globals "ethereum.constantinople.vm.precompiled_contracts.mapping" [ "PRE_COMPILED_CONTRACTS" ]. - -Axiom ethereum_constantinople_vm_imports : - AreImported globals "ethereum.constantinople.vm" [ "Environment"; "Evm" ]. - -Axiom ethereum_constantinople_vm_exceptions_imports : - AreImported globals "ethereum.constantinople.vm.exceptions" [ "AddressCollision"; "ExceptionalHalt"; "InvalidOpcode"; "OutOfGasError"; "Revert"; "StackDepthLimitError" ]. - -Axiom ethereum_constantinople_vm_instructions_imports : - AreImported globals "ethereum.constantinople.vm.instructions" [ "Ops"; "op_implementation" ]. - -Axiom ethereum_constantinople_vm_runtime_imports : - AreImported globals "ethereum.constantinople.vm.runtime" [ "get_valid_jump_destinations" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_Iterable : + IsImported globals "typing" "Iterable". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_trace_imports_EvmStop : + IsImported globals "ethereum.trace" "EvmStop". +Axiom ethereum_trace_imports_OpEnd : + IsImported globals "ethereum.trace" "OpEnd". +Axiom ethereum_trace_imports_OpException : + IsImported globals "ethereum.trace" "OpException". +Axiom ethereum_trace_imports_OpStart : + IsImported globals "ethereum.trace" "OpStart". +Axiom ethereum_trace_imports_PrecompileEnd : + IsImported globals "ethereum.trace" "PrecompileEnd". +Axiom ethereum_trace_imports_PrecompileStart : + IsImported globals "ethereum.trace" "PrecompileStart". +Axiom ethereum_trace_imports_TransactionEnd : + IsImported globals "ethereum.trace" "TransactionEnd". +Axiom ethereum_trace_imports_evm_trace : + IsImported globals "ethereum.trace" "evm_trace". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_constantinople_blocks_imports_Log : + IsImported globals "ethereum.constantinople.blocks" "Log". + +Axiom ethereum_constantinople_fork_types_imports_Address : + IsImported globals "ethereum.constantinople.fork_types" "Address". + +Axiom ethereum_constantinople_state_imports_account_exists_and_is_empty : + IsImported globals "ethereum.constantinople.state" "account_exists_and_is_empty". +Axiom ethereum_constantinople_state_imports_account_has_code_or_nonce : + IsImported globals "ethereum.constantinople.state" "account_has_code_or_nonce". +Axiom ethereum_constantinople_state_imports_begin_transaction : + IsImported globals "ethereum.constantinople.state" "begin_transaction". +Axiom ethereum_constantinople_state_imports_commit_transaction : + IsImported globals "ethereum.constantinople.state" "commit_transaction". +Axiom ethereum_constantinople_state_imports_destroy_storage : + IsImported globals "ethereum.constantinople.state" "destroy_storage". +Axiom ethereum_constantinople_state_imports_increment_nonce : + IsImported globals "ethereum.constantinople.state" "increment_nonce". +Axiom ethereum_constantinople_state_imports_move_ether : + IsImported globals "ethereum.constantinople.state" "move_ether". +Axiom ethereum_constantinople_state_imports_rollback_transaction : + IsImported globals "ethereum.constantinople.state" "rollback_transaction". +Axiom ethereum_constantinople_state_imports_set_code : + IsImported globals "ethereum.constantinople.state" "set_code". +Axiom ethereum_constantinople_state_imports_touch_account : + IsImported globals "ethereum.constantinople.state" "touch_account". + +Axiom ethereum_constantinople_vm_imports_Message : + IsImported globals "ethereum.constantinople.vm" "Message". + +Axiom ethereum_constantinople_vm_gas_imports_GAS_CODE_DEPOSIT : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_CODE_DEPOSIT". +Axiom ethereum_constantinople_vm_gas_imports_charge_gas : + IsImported globals "ethereum.constantinople.vm.gas" "charge_gas". + +Axiom ethereum_constantinople_vm_precompiled_contracts_mapping_imports_PRE_COMPILED_CONTRACTS : + IsImported globals "ethereum.constantinople.vm.precompiled_contracts.mapping" "PRE_COMPILED_CONTRACTS". + +Axiom ethereum_constantinople_vm_imports_Environment : + IsImported globals "ethereum.constantinople.vm" "Environment". +Axiom ethereum_constantinople_vm_imports_Evm : + IsImported globals "ethereum.constantinople.vm" "Evm". + +Axiom ethereum_constantinople_vm_exceptions_imports_AddressCollision : + IsImported globals "ethereum.constantinople.vm.exceptions" "AddressCollision". +Axiom ethereum_constantinople_vm_exceptions_imports_ExceptionalHalt : + IsImported globals "ethereum.constantinople.vm.exceptions" "ExceptionalHalt". +Axiom ethereum_constantinople_vm_exceptions_imports_InvalidOpcode : + IsImported globals "ethereum.constantinople.vm.exceptions" "InvalidOpcode". +Axiom ethereum_constantinople_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.constantinople.vm.exceptions" "OutOfGasError". +Axiom ethereum_constantinople_vm_exceptions_imports_Revert : + IsImported globals "ethereum.constantinople.vm.exceptions" "Revert". +Axiom ethereum_constantinople_vm_exceptions_imports_StackDepthLimitError : + IsImported globals "ethereum.constantinople.vm.exceptions" "StackDepthLimitError". + +Axiom ethereum_constantinople_vm_instructions_imports_Ops : + IsImported globals "ethereum.constantinople.vm.instructions" "Ops". +Axiom ethereum_constantinople_vm_instructions_imports_op_implementation : + IsImported globals "ethereum.constantinople.vm.instructions" "op_implementation". + +Axiom ethereum_constantinople_vm_runtime_imports_get_valid_jump_destinations : + IsImported globals "ethereum.constantinople.vm.runtime" "get_valid_jump_destinations". Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -121,7 +179,8 @@ Definition process_message_call : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let is_collision := + let _ := M.assign_local (| + "is_collision" , M.call (| M.get_name (| globals, "account_has_code_or_nonce" |), make_list [ @@ -129,7 +188,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "message" |), "current_target" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -181,7 +241,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "process_create_message" |), make_list [ @@ -189,13 +250,15 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "process_message" |), make_list [ @@ -203,7 +266,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -250,40 +314,55 @@ Definition process_message_call : Value.t -> Value.t -> M := (* then *) ltac:(M.monadic ( (* At stmt: unsupported node type: AnnAssign *) - let accounts_to_delete := + let _ := M.assign_local (| + "accounts_to_delete" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let touched_accounts := + |) + |) in + let _ := M.assign_local (| + "touched_accounts" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let refund_counter := + |) + |) in + let _ := M.assign_local (| + "refund_counter" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let logs := - M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in - let accounts_to_delete := - M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in - let touched_accounts := - M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |) in - let refund_counter := - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |) in + let _ := M.assign_local (| + "logs" , + M.get_field (| M.get_name (| globals, "evm" |), "logs" |) + |) in + let _ := M.assign_local (| + "accounts_to_delete" , + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) + |) in + let _ := M.assign_local (| + "touched_accounts" , + M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |) + |) in + let _ := M.assign_local (| + "refund_counter" , + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |) + |) in M.pure Constant.None_ )) |) in - let tx_end := + let _ := M.assign_local (| + "tx_end" , M.call (| M.get_name (| globals, "TransactionEnd" |), make_list [ @@ -295,7 +374,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "error" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "evm_trace" |), make_list [ @@ -354,7 +434,8 @@ Definition process_create_message : Value.t -> Value.t -> M := ], make_dict [] |) in - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "process_message" |), make_list [ @@ -362,16 +443,20 @@ Definition process_create_message : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), (* then *) ltac:(M.monadic ( - let contract_code := - M.get_field (| M.get_name (| globals, "evm" |), "output" |) in - let contract_code_gas := + let _ := M.assign_local (| + "contract_code" , + M.get_field (| M.get_name (| globals, "evm" |), "output" |) + |) in + let _ := M.assign_local (| + "contract_code_gas" , BinOp.mult (| M.call (| M.get_name (| globals, "len" |), @@ -381,7 +466,8 @@ Definition process_create_message : Value.t -> Value.t -> M := make_dict [] |), M.get_name (| globals, "GAS_CODE_DEPOSIT" |) - |) in + |) + |) in (* At stmt: unsupported node type: Try *) M.pure Constant.None_ (* else *) @@ -483,7 +569,8 @@ Definition process_message : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "execute_code" |), make_list [ @@ -491,7 +578,8 @@ Definition process_message : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -540,22 +628,28 @@ Definition execute_code : Value.t -> Value.t -> M := evm: `ethereum.vm.EVM` Items containing execution specific objects " in - let code := - M.get_field (| M.get_name (| globals, "message" |), "code" |) in - let valid_jump_destinations := + let _ := M.assign_local (| + "code" , + M.get_field (| M.get_name (| globals, "message" |), "code" |) + |) in + let _ := M.assign_local (| + "valid_jump_destinations" , M.call (| M.get_name (| globals, "get_valid_jump_destinations" |), make_list [ M.get_name (| globals, "code" |) ], make_dict [] - |) in - let evm := + |) + |) in + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "Evm" |), make_list [], make_dict [] - |) in + |) + |) in (* At stmt: unsupported node type: Try *) let _ := M.return_ (| M.get_name (| globals, "evm" |) diff --git a/CoqOfPython/ethereum/constantinople/vm/memory.v b/CoqOfPython/ethereum/constantinople/vm/memory.v index d542adf..f8c1898 100644 --- a/CoqOfPython/ethereum/constantinople/vm/memory.v +++ b/CoqOfPython/ethereum/constantinople/vm/memory.v @@ -17,11 +17,15 @@ Introduction EVM memory operations. ". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "right_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_right_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "right_pad_zero_bytes". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". Definition memory_write : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/__init__.v index 48bc095..028d559 100644 --- a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/__init__.v +++ b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/__init__.v @@ -18,8 +18,8 @@ Addresses of precompiled contracts and mappings to their implementations. ". -Axiom ethereum_constantinople_utils_hexadecimal_imports : - AreImported globals "ethereum.constantinople.utils.hexadecimal" [ "hex_to_address" ]. +Axiom ethereum_constantinople_utils_hexadecimal_imports_hex_to_address : + IsImported globals "ethereum.constantinople.utils.hexadecimal" "hex_to_address". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS"; Constant.str "MODEXP_ADDRESS"; Constant.str "ALT_BN128_ADD_ADDRESS"; Constant.str "ALT_BN128_MUL_ADDRESS"; Constant.str "ALT_BN128_PAIRING_CHECK_ADDRESS"; Constant.str "BLAKE2F_ADDRESS" ] diff --git a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/alt_bn128.v index 0f2bf06..35d5ffd 100644 --- a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/alt_bn128.v +++ b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/alt_bn128.v @@ -17,26 +17,42 @@ Introduction Implementation of the ALT_BN128 precompiled contracts. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_alt_bn128_imports : - AreImported globals "ethereum.crypto.alt_bn128" [ "ALT_BN128_CURVE_ORDER"; "ALT_BN128_PRIME"; "BNF"; "BNF2"; "BNF12"; "BNP"; "BNP2"; "pairing" ]. +Axiom ethereum_crypto_alt_bn128_imports_ALT_BN128_CURVE_ORDER : + IsImported globals "ethereum.crypto.alt_bn128" "ALT_BN128_CURVE_ORDER". +Axiom ethereum_crypto_alt_bn128_imports_ALT_BN128_PRIME : + IsImported globals "ethereum.crypto.alt_bn128" "ALT_BN128_PRIME". +Axiom ethereum_crypto_alt_bn128_imports_BNF : + IsImported globals "ethereum.crypto.alt_bn128" "BNF". +Axiom ethereum_crypto_alt_bn128_imports_BNF2 : + IsImported globals "ethereum.crypto.alt_bn128" "BNF2". +Axiom ethereum_crypto_alt_bn128_imports_BNF12 : + IsImported globals "ethereum.crypto.alt_bn128" "BNF12". +Axiom ethereum_crypto_alt_bn128_imports_BNP : + IsImported globals "ethereum.crypto.alt_bn128" "BNP". +Axiom ethereum_crypto_alt_bn128_imports_BNP2 : + IsImported globals "ethereum.crypto.alt_bn128" "BNP2". +Axiom ethereum_crypto_alt_bn128_imports_pairing : + IsImported globals "ethereum.crypto.alt_bn128" "pairing". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_constantinople_vm_imports : - AreImported globals "ethereum.constantinople.vm" [ "Evm" ]. +Axiom ethereum_constantinople_vm_imports_Evm : + IsImported globals "ethereum.constantinople.vm" "Evm". -Axiom ethereum_constantinople_vm_gas_imports : - AreImported globals "ethereum.constantinople.vm.gas" [ "charge_gas" ]. +Axiom ethereum_constantinople_vm_gas_imports_charge_gas : + IsImported globals "ethereum.constantinople.vm.gas" "charge_gas". -Axiom ethereum_constantinople_vm_memory_imports : - AreImported globals "ethereum.constantinople.vm.memory" [ "buffer_read" ]. +Axiom ethereum_constantinople_vm_memory_imports_buffer_read : + IsImported globals "ethereum.constantinople.vm.memory" "buffer_read". -Axiom ethereum_constantinople_vm_exceptions_imports : - AreImported globals "ethereum.constantinople.vm.exceptions" [ "OutOfGasError" ]. +Axiom ethereum_constantinople_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.constantinople.vm.exceptions" "OutOfGasError". Definition alt_bn128_add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -49,8 +65,10 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -65,7 +83,8 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := ], make_dict [] |) in - let x0_bytes := + let _ := M.assign_local (| + "x0_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -86,16 +105,20 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let x0_value := + |) + |) in + let _ := M.assign_local (| + "x0_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "x0_bytes" |) ], make_dict [] - |) in - let y0_bytes := + |) + |) in + let _ := M.assign_local (| + "y0_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -116,16 +139,20 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y0_value := + |) + |) in + let _ := M.assign_local (| + "y0_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "y0_bytes" |) ], make_dict [] - |) in - let x1_bytes := + |) + |) in + let _ := M.assign_local (| + "x1_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -146,16 +173,20 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let x1_value := + |) + |) in + let _ := M.assign_local (| + "x1_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "x1_bytes" |) ], make_dict [] - |) in - let y1_bytes := + |) + |) in + let _ := M.assign_local (| + "y1_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -176,15 +207,18 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y1_value := + |) + |) in + let _ := M.assign_local (| + "y1_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "y1_bytes" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "i" |), @@ -212,11 +246,13 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := )) |) in (* At stmt: unsupported node type: Try *) - let p := + let _ := M.assign_local (| + "p" , BinOp.add (| M.get_name (| globals, "p0" |), M.get_name (| globals, "p1" |) - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), BinOp.add (| @@ -245,8 +281,10 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -261,7 +299,8 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := ], make_dict [] |) in - let x0_bytes := + let _ := M.assign_local (| + "x0_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -282,16 +321,20 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let x0_value := + |) + |) in + let _ := M.assign_local (| + "x0_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "x0_bytes" |) ], make_dict [] - |) in - let y0_bytes := + |) + |) in + let _ := M.assign_local (| + "y0_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -312,16 +355,20 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y0_value := + |) + |) in + let _ := M.assign_local (| + "y0_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "y0_bytes" |) ], make_dict [] - |) in - let n := + |) + |) in + let _ := M.assign_local (| + "n" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -348,7 +395,8 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "i" |), @@ -376,14 +424,16 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := )) |) in (* At stmt: unsupported node type: Try *) - let p := + let _ := M.assign_local (| + "p" , M.call (| M.get_field (| M.get_name (| globals, "p0" |), "mul_by" |), make_list [ M.get_name (| globals, "n" |) ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), BinOp.add (| @@ -412,8 +462,10 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -467,14 +519,16 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), make_list [ Constant.int 1 ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "i" |), @@ -495,8 +549,10 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let values := - make_list [] in + let _ := M.assign_local (| + "values" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "j" |), @@ -508,7 +564,8 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -541,7 +598,8 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -644,7 +702,8 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , BinOp.mult (| M.get_name (| globals, "result" |), M.call (| @@ -655,7 +714,8 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/ecrecover.v index 71ad01d..3738033 100644 --- a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/ecrecover.v @@ -17,26 +17,32 @@ Introduction Implementation of the ECRECOVER precompiled contract. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_crypto_elliptic_curve_imports : - AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. +Axiom ethereum_crypto_elliptic_curve_imports_SECP256K1N : + IsImported globals "ethereum.crypto.elliptic_curve" "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_imports_secp256k1_recover : + IsImported globals "ethereum.crypto.elliptic_curve" "secp256k1_recover". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_left_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "left_pad_zero_bytes". -Axiom ethereum_constantinople_vm_imports : - AreImported globals "ethereum.constantinople.vm" [ "Evm" ]. +Axiom ethereum_constantinople_vm_imports_Evm : + IsImported globals "ethereum.constantinople.vm" "Evm". -Axiom ethereum_constantinople_vm_gas_imports : - AreImported globals "ethereum.constantinople.vm.gas" [ "GAS_ECRECOVER"; "charge_gas" ]. +Axiom ethereum_constantinople_vm_gas_imports_GAS_ECRECOVER : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_ECRECOVER". +Axiom ethereum_constantinople_vm_gas_imports_charge_gas : + IsImported globals "ethereum.constantinople.vm.gas" "charge_gas". -Axiom ethereum_constantinople_vm_memory_imports : - AreImported globals "ethereum.constantinople.vm.memory" [ "buffer_read" ]. +Axiom ethereum_constantinople_vm_memory_imports_buffer_read : + IsImported globals "ethereum.constantinople.vm.memory" "buffer_read". Definition ecrecover : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -50,8 +56,10 @@ Definition ecrecover : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -60,7 +68,8 @@ Definition ecrecover : Value.t -> Value.t -> M := ], make_dict [] |) in - let message_hash_bytes := + let _ := M.assign_local (| + "message_hash_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -81,16 +90,20 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let message_hash := + |) + |) in + let _ := M.assign_local (| + "message_hash" , M.call (| M.get_name (| globals, "Hash32" |), make_list [ M.get_name (| globals, "message_hash_bytes" |) ], make_dict [] - |) in - let v := + |) + |) in + let _ := M.assign_local (| + "v" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -117,8 +130,10 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let r := + |) + |) in + let _ := M.assign_local (| + "r" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -145,8 +160,10 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let s := + |) + |) in + let _ := M.assign_local (| + "s" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -173,7 +190,8 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -250,7 +268,8 @@ Definition ecrecover : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: Try *) - let address := + let _ := M.assign_local (| + "address" , M.slice (| M.call (| M.get_name (| globals, "keccak256" |), @@ -262,8 +281,10 @@ Definition ecrecover : Value.t -> Value.t -> M := Constant.int 12, Constant.int 32, Constant.None_ - |) in - let padded_address := + |) + |) in + let _ := M.assign_local (| + "padded_address" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -271,7 +292,8 @@ Definition ecrecover : Value.t -> Value.t -> M := Constant.int 32 ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.get_name (| globals, "padded_address" |) diff --git a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/identity.v index ac6ab23..f7e428a 100644 --- a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/identity.v +++ b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/identity.v @@ -17,17 +17,21 @@ Introduction Implementation of the `IDENTITY` precompiled contract. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_constantinople_vm_imports : - AreImported globals "ethereum.constantinople.vm" [ "Evm" ]. +Axiom ethereum_constantinople_vm_imports_Evm : + IsImported globals "ethereum.constantinople.vm" "Evm". -Axiom ethereum_constantinople_vm_gas_imports : - AreImported globals "ethereum.constantinople.vm.gas" [ "GAS_IDENTITY"; "GAS_IDENTITY_WORD"; "charge_gas" ]. +Axiom ethereum_constantinople_vm_gas_imports_GAS_IDENTITY : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_IDENTITY". +Axiom ethereum_constantinople_vm_gas_imports_GAS_IDENTITY_WORD : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_IDENTITY_WORD". +Axiom ethereum_constantinople_vm_gas_imports_charge_gas : + IsImported globals "ethereum.constantinople.vm.gas" "charge_gas". Definition identity : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -40,9 +44,12 @@ Definition identity : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let word_count := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "word_count" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -64,7 +71,8 @@ Definition identity : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ diff --git a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/mapping.v index 5f9eca2..90f0895 100644 --- a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/mapping.v +++ b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/mapping.v @@ -17,31 +17,51 @@ Introduction Mapping of precompiled contracts their implementations. ". -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict" ]. +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". -Axiom ethereum_constantinople_fork_types_imports : - AreImported globals "ethereum.constantinople.fork_types" [ "Address" ]. +Axiom ethereum_constantinople_fork_types_imports_Address : + IsImported globals "ethereum.constantinople.fork_types" "Address". -Axiom ethereum_constantinople_vm_precompiled_contracts_imports : - AreImported globals "ethereum.constantinople.vm.precompiled_contracts" [ "ALT_BN128_ADD_ADDRESS"; "ALT_BN128_MUL_ADDRESS"; "ALT_BN128_PAIRING_CHECK_ADDRESS"; "ECRECOVER_ADDRESS"; "IDENTITY_ADDRESS"; "MODEXP_ADDRESS"; "RIPEMD160_ADDRESS"; "SHA256_ADDRESS" ]. +Axiom ethereum_constantinople_vm_precompiled_contracts_imports_ALT_BN128_ADD_ADDRESS : + IsImported globals "ethereum.constantinople.vm.precompiled_contracts" "ALT_BN128_ADD_ADDRESS". +Axiom ethereum_constantinople_vm_precompiled_contracts_imports_ALT_BN128_MUL_ADDRESS : + IsImported globals "ethereum.constantinople.vm.precompiled_contracts" "ALT_BN128_MUL_ADDRESS". +Axiom ethereum_constantinople_vm_precompiled_contracts_imports_ALT_BN128_PAIRING_CHECK_ADDRESS : + IsImported globals "ethereum.constantinople.vm.precompiled_contracts" "ALT_BN128_PAIRING_CHECK_ADDRESS". +Axiom ethereum_constantinople_vm_precompiled_contracts_imports_ECRECOVER_ADDRESS : + IsImported globals "ethereum.constantinople.vm.precompiled_contracts" "ECRECOVER_ADDRESS". +Axiom ethereum_constantinople_vm_precompiled_contracts_imports_IDENTITY_ADDRESS : + IsImported globals "ethereum.constantinople.vm.precompiled_contracts" "IDENTITY_ADDRESS". +Axiom ethereum_constantinople_vm_precompiled_contracts_imports_MODEXP_ADDRESS : + IsImported globals "ethereum.constantinople.vm.precompiled_contracts" "MODEXP_ADDRESS". +Axiom ethereum_constantinople_vm_precompiled_contracts_imports_RIPEMD160_ADDRESS : + IsImported globals "ethereum.constantinople.vm.precompiled_contracts" "RIPEMD160_ADDRESS". +Axiom ethereum_constantinople_vm_precompiled_contracts_imports_SHA256_ADDRESS : + IsImported globals "ethereum.constantinople.vm.precompiled_contracts" "SHA256_ADDRESS". -Axiom ethereum_constantinople_vm_precompiled_contracts_alt_bn128_imports : - AreImported globals "ethereum.constantinople.vm.precompiled_contracts.alt_bn128" [ "alt_bn128_add"; "alt_bn128_mul"; "alt_bn128_pairing_check" ]. +Axiom ethereum_constantinople_vm_precompiled_contracts_alt_bn128_imports_alt_bn128_add : + IsImported globals "ethereum.constantinople.vm.precompiled_contracts.alt_bn128" "alt_bn128_add". +Axiom ethereum_constantinople_vm_precompiled_contracts_alt_bn128_imports_alt_bn128_mul : + IsImported globals "ethereum.constantinople.vm.precompiled_contracts.alt_bn128" "alt_bn128_mul". +Axiom ethereum_constantinople_vm_precompiled_contracts_alt_bn128_imports_alt_bn128_pairing_check : + IsImported globals "ethereum.constantinople.vm.precompiled_contracts.alt_bn128" "alt_bn128_pairing_check". -Axiom ethereum_constantinople_vm_precompiled_contracts_ecrecover_imports : - AreImported globals "ethereum.constantinople.vm.precompiled_contracts.ecrecover" [ "ecrecover" ]. +Axiom ethereum_constantinople_vm_precompiled_contracts_ecrecover_imports_ecrecover : + IsImported globals "ethereum.constantinople.vm.precompiled_contracts.ecrecover" "ecrecover". -Axiom ethereum_constantinople_vm_precompiled_contracts_identity_imports : - AreImported globals "ethereum.constantinople.vm.precompiled_contracts.identity" [ "identity" ]. +Axiom ethereum_constantinople_vm_precompiled_contracts_identity_imports_identity : + IsImported globals "ethereum.constantinople.vm.precompiled_contracts.identity" "identity". -Axiom ethereum_constantinople_vm_precompiled_contracts_modexp_imports : - AreImported globals "ethereum.constantinople.vm.precompiled_contracts.modexp" [ "modexp" ]. +Axiom ethereum_constantinople_vm_precompiled_contracts_modexp_imports_modexp : + IsImported globals "ethereum.constantinople.vm.precompiled_contracts.modexp" "modexp". -Axiom ethereum_constantinople_vm_precompiled_contracts_ripemd160_imports : - AreImported globals "ethereum.constantinople.vm.precompiled_contracts.ripemd160" [ "ripemd160" ]. +Axiom ethereum_constantinople_vm_precompiled_contracts_ripemd160_imports_ripemd160 : + IsImported globals "ethereum.constantinople.vm.precompiled_contracts.ripemd160" "ripemd160". -Axiom ethereum_constantinople_vm_precompiled_contracts_sha256_imports : - AreImported globals "ethereum.constantinople.vm.precompiled_contracts.sha256" [ "sha256" ]. +Axiom ethereum_constantinople_vm_precompiled_contracts_sha256_imports_sha256 : + IsImported globals "ethereum.constantinople.vm.precompiled_contracts.sha256" "sha256". (* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/modexp.v index cea4cb3..8bbf71b 100644 --- a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/modexp.v +++ b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/modexp.v @@ -17,17 +17,21 @@ Introduction Implementation of the `MODEXP` precompiled contract. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_constantinople_vm_imports : - AreImported globals "ethereum.constantinople.vm" [ "Evm" ]. +Axiom ethereum_constantinople_vm_imports_Evm : + IsImported globals "ethereum.constantinople.vm" "Evm". -Axiom ethereum_constantinople_vm_gas_imports : - AreImported globals "ethereum.constantinople.vm.gas" [ "charge_gas" ]. +Axiom ethereum_constantinople_vm_gas_imports_charge_gas : + IsImported globals "ethereum.constantinople.vm.gas" "charge_gas". -Axiom ethereum_constantinople_vm_memory_imports : - AreImported globals "ethereum.constantinople.vm.memory" [ "buffer_read" ]. +Axiom ethereum_constantinople_vm_memory_imports_buffer_read : + IsImported globals "ethereum.constantinople.vm.memory" "buffer_read". Definition GQUADDIVISOR : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -46,9 +50,12 @@ Definition modexp : Value.t -> Value.t -> M := Calculates `(base**exp) % modulus` for arbitrary sized `base`, `exp` and. `modulus`. The return value is the same length as the modulus. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let base_length := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "base_length" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -75,8 +82,10 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exp_length := + |) + |) in + let _ := M.assign_local (| + "exp_length" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -103,8 +112,10 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let modulus_length := + |) + |) in + let _ := M.assign_local (| + "modulus_length" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -131,8 +142,10 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exp_start := + |) + |) in + let _ := M.assign_local (| + "exp_start" , BinOp.add (| M.call (| M.get_name (| globals, "U256" |), @@ -142,8 +155,10 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |), M.get_name (| globals, "base_length" |) - |) in - let exp_head := + |) + |) in + let _ := M.assign_local (| + "exp_head" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -171,7 +186,8 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -181,7 +197,8 @@ Definition modexp : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let adjusted_exp_length := + let _ := M.assign_local (| + "adjusted_exp_length" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -202,11 +219,13 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let adjusted_exp_length := + let _ := M.assign_local (| + "adjusted_exp_length" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -242,7 +261,8 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -324,7 +344,8 @@ Definition modexp : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let base := + let _ := M.assign_local (| + "base" , M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ @@ -345,8 +366,10 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exp := + |) + |) in + let _ := M.assign_local (| + "exp" , M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ @@ -361,13 +384,17 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let modulus_start := + |) + |) in + let _ := M.assign_local (| + "modulus_start" , BinOp.add (| M.get_name (| globals, "exp_start" |), M.get_name (| globals, "exp_length" |) - |) in - let modulus := + |) + |) in + let _ := M.assign_local (| + "modulus" , M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ @@ -382,7 +409,8 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| diff --git a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/ripemd160.v index 73a1f72..9077c68 100644 --- a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/ripemd160.v +++ b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/ripemd160.v @@ -19,20 +19,24 @@ Implementation of the `RIPEMD160` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_left_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "left_pad_zero_bytes". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_constantinople_vm_imports : - AreImported globals "ethereum.constantinople.vm" [ "Evm" ]. +Axiom ethereum_constantinople_vm_imports_Evm : + IsImported globals "ethereum.constantinople.vm" "Evm". -Axiom ethereum_constantinople_vm_gas_imports : - AreImported globals "ethereum.constantinople.vm.gas" [ "GAS_RIPEMD160"; "GAS_RIPEMD160_WORD"; "charge_gas" ]. +Axiom ethereum_constantinople_vm_gas_imports_GAS_RIPEMD160 : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_RIPEMD160". +Axiom ethereum_constantinople_vm_gas_imports_GAS_RIPEMD160_WORD : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_RIPEMD160_WORD". +Axiom ethereum_constantinople_vm_gas_imports_charge_gas : + IsImported globals "ethereum.constantinople.vm.gas" "charge_gas". Definition ripemd160 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,9 +49,12 @@ Definition ripemd160 : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let word_count := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "word_count" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -69,7 +76,8 @@ Definition ripemd160 : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -84,7 +92,8 @@ Definition ripemd160 : Value.t -> Value.t -> M := ], make_dict [] |) in - let hash_bytes := + let _ := M.assign_local (| + "hash_bytes" , M.call (| M.get_field (| M.call (| M.get_field (| M.get_name (| globals, "hashlib" |), "new" |), @@ -96,8 +105,10 @@ Definition ripemd160 : Value.t -> Value.t -> M := |), "digest" |), make_list [], make_dict [] - |) in - let padded_hash := + |) + |) in + let _ := M.assign_local (| + "padded_hash" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -105,7 +116,8 @@ Definition ripemd160 : Value.t -> Value.t -> M := Constant.int 32 ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.get_name (| globals, "padded_hash" |) diff --git a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/sha256.v index cda8916..5e11ce8 100644 --- a/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/sha256.v +++ b/CoqOfPython/ethereum/constantinople/vm/precompiled_contracts/sha256.v @@ -19,17 +19,21 @@ Implementation of the `SHA256` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_constantinople_vm_imports : - AreImported globals "ethereum.constantinople.vm" [ "Evm" ]. +Axiom ethereum_constantinople_vm_imports_Evm : + IsImported globals "ethereum.constantinople.vm" "Evm". -Axiom ethereum_constantinople_vm_gas_imports : - AreImported globals "ethereum.constantinople.vm.gas" [ "GAS_SHA256"; "GAS_SHA256_WORD"; "charge_gas" ]. +Axiom ethereum_constantinople_vm_gas_imports_GAS_SHA256 : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_SHA256". +Axiom ethereum_constantinople_vm_gas_imports_GAS_SHA256_WORD : + IsImported globals "ethereum.constantinople.vm.gas" "GAS_SHA256_WORD". +Axiom ethereum_constantinople_vm_gas_imports_charge_gas : + IsImported globals "ethereum.constantinople.vm.gas" "charge_gas". Definition sha256 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,9 +46,12 @@ Definition sha256 : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let word_count := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "word_count" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -66,7 +73,8 @@ Definition sha256 : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ diff --git a/CoqOfPython/ethereum/constantinople/vm/runtime.v b/CoqOfPython/ethereum/constantinople/vm/runtime.v index bf6ec2c..f830abe 100644 --- a/CoqOfPython/ethereum/constantinople/vm/runtime.v +++ b/CoqOfPython/ethereum/constantinople/vm/runtime.v @@ -17,14 +17,14 @@ Introduction Runtime related operations used while executing EVM code. ". -Axiom typing_imports : - AreImported globals "typing" [ "Set" ]. +Axiom typing_imports_Set : + IsImported globals "typing" "Set". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_constantinople_vm_instructions_imports : - AreImported globals "ethereum.constantinople.vm.instructions" [ "Ops" ]. +Axiom ethereum_constantinople_vm_instructions_imports_Ops : + IsImported globals "ethereum.constantinople.vm.instructions" "Ops". Definition get_valid_jump_destinations : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -50,20 +50,24 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := valid_jump_destinations: `Set[Uint]` The set of valid jump destinations in the code. " in - let valid_jump_destinations := + let _ := M.assign_local (| + "valid_jump_destinations" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let pc := + |) + |) in + let _ := M.assign_local (| + "pc" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in let _ := M.while (| Compare.lt (| @@ -114,17 +118,21 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let push_data_size := + let _ := M.assign_local (| + "push_data_size" , BinOp.add (| BinOp.sub (| M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) |), Constant.int 1 - |) in - let pc := BinOp.add + |) + |) in + let _ := M.assign_op_local (| + BinOp.add, + "pc", M.get_name (| globals, "push_data_size" |) - M.get_name (| globals, "push_data_size" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -132,9 +140,11 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - let pc := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "pc", Constant.int 1 - Constant.int 1 in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/constantinople/vm/stack.v b/CoqOfPython/ethereum/constantinople/vm/stack.v index 6242369..afbe789 100644 --- a/CoqOfPython/ethereum/constantinople/vm/stack.v +++ b/CoqOfPython/ethereum/constantinople/vm/stack.v @@ -17,14 +17,16 @@ Introduction Implementation of the stack operators for the EVM. ". -Axiom typing_imports : - AreImported globals "typing" [ "List" ]. +Axiom typing_imports_List : + IsImported globals "typing" "List". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_constantinople_vm_exceptions_imports : - AreImported globals "ethereum.constantinople.vm.exceptions" [ "StackOverflowError"; "StackUnderflowError" ]. +Axiom ethereum_constantinople_vm_exceptions_imports_StackOverflowError : + IsImported globals "ethereum.constantinople.vm.exceptions" "StackOverflowError". +Axiom ethereum_constantinople_vm_exceptions_imports_StackUnderflowError : + IsImported globals "ethereum.constantinople.vm.exceptions" "StackUnderflowError". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/crypto/alt_bn128.v b/CoqOfPython/ethereum/crypto/alt_bn128.v index ea237cf..bc2b4ac 100644 --- a/CoqOfPython/ethereum/crypto/alt_bn128.v +++ b/CoqOfPython/ethereum/crypto/alt_bn128.v @@ -8,8 +8,10 @@ The alt_bn128 curve ^^^^^^^^^^^^^^^^^^^ ". -Axiom ethereum_crypto_imports : - AreImported globals "ethereum.crypto" [ "elliptic_curve"; "finite_field" ]. +Axiom ethereum_crypto_imports_elliptic_curve : + IsImported globals "ethereum.crypto" "elliptic_curve". +Axiom ethereum_crypto_imports_finite_field : + IsImported globals "ethereum.crypto" "finite_field". Definition ALT_BN128_PRIME : Value.t := M.run ltac:(M.monadic ( Constant.int 21888242871839275222246405745257275088696311157297823662689037894645226208583 @@ -96,13 +98,15 @@ Definition BNF12 : Value.t := let _ := Constant.str " Multiplication special cased for BNF12. " in - let mul := + let _ := M.assign_local (| + "mul" , BinOp.mult (| make_list [ Constant.int 0 ], Constant.int 23 - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "i" |), @@ -403,7 +407,8 @@ Definition linefunc : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let lam := + let _ := M.assign_local (| + "lam" , BinOp.div (| BinOp.sub (| M.get_field (| M.get_name (| globals, "p2" |), "y" |), @@ -413,7 +418,8 @@ Definition linefunc : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "p2" |), "x" |), M.get_field (| M.get_name (| globals, "p1" |), "x" |) |) - |) in + |) + |) in let _ := M.return_ (| BinOp.sub (| BinOp.mult (| @@ -441,7 +447,8 @@ Definition linefunc : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let lam := + let _ := M.assign_local (| + "lam" , BinOp.div (| BinOp.mult (| M.call (| @@ -466,7 +473,8 @@ Definition linefunc : Value.t -> Value.t -> M := |), M.get_field (| M.get_name (| globals, "p1" |), "y" |) |) - |) in + |) + |) in let _ := M.return_ (| BinOp.sub (| BinOp.mult (| @@ -542,16 +550,20 @@ Definition miller_loop : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let r := - M.get_name (| globals, "q" |) in - let f := + let _ := M.assign_local (| + "r" , + M.get_name (| globals, "q" |) + |) in + let _ := M.assign_local (| + "f" , M.call (| M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), make_list [ Constant.int 1 ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "i" |), @@ -565,7 +577,8 @@ Definition miller_loop : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let f := + let _ := M.assign_local (| + "f" , BinOp.mult (| BinOp.mult (| M.get_name (| globals, "f" |), @@ -580,13 +593,16 @@ Definition miller_loop : Value.t -> Value.t -> M := ], make_dict [] |) - |) in - let r := + |) + |) in + let _ := M.assign_local (| + "r" , M.call (| M.get_field (| M.get_name (| globals, "r" |), "double" |), make_list [], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -602,7 +618,8 @@ Definition miller_loop : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let f := + let _ := M.assign_local (| + "f" , BinOp.mult (| M.get_name (| globals, "f" |), M.call (| @@ -614,12 +631,15 @@ Definition miller_loop : Value.t -> Value.t -> M := ], make_dict [] |) - |) in - let r := + |) + |) in + let _ := M.assign_local (| + "r" , BinOp.add (| M.get_name (| globals, "r" |), M.get_name (| globals, "q" |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -644,7 +664,8 @@ Definition miller_loop : Value.t -> Value.t -> M := make_dict [] |) |) |) in - let q1 := + let _ := M.assign_local (| + "q1" , M.call (| M.get_name (| globals, "BNP12" |), make_list [ @@ -660,8 +681,10 @@ Definition miller_loop : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let nq2 := + |) + |) in + let _ := M.assign_local (| + "nq2" , M.call (| M.get_name (| globals, "BNP12" |), make_list [ @@ -677,8 +700,10 @@ Definition miller_loop : Value.t -> Value.t -> M := |) |) ], make_dict [] - |) in - let f := + |) + |) in + let _ := M.assign_local (| + "f" , BinOp.mult (| M.get_name (| globals, "f" |), M.call (| @@ -690,13 +715,17 @@ Definition miller_loop : Value.t -> Value.t -> M := ], make_dict [] |) - |) in - let r := + |) + |) in + let _ := M.assign_local (| + "r" , BinOp.add (| M.get_name (| globals, "r" |), M.get_name (| globals, "q1" |) - |) in - let f := + |) + |) in + let _ := M.assign_local (| + "f" , BinOp.mult (| M.get_name (| globals, "f" |), M.call (| @@ -708,7 +737,8 @@ Definition miller_loop : Value.t -> Value.t -> M := ], make_dict [] |) - |) in + |) + |) in let _ := M.return_ (| BinOp.pow (| M.get_name (| globals, "f" |), diff --git a/CoqOfPython/ethereum/crypto/blake2.v b/CoqOfPython/ethereum/crypto/blake2.v index 8087294..6cd27f7 100644 --- a/CoqOfPython/ethereum/crypto/blake2.v +++ b/CoqOfPython/ethereum/crypto/blake2.v @@ -10,14 +10,16 @@ The Blake2 Implementation (* At top_level_stmt: unsupported node type: Import *) -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Tuple" ]. +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". Definition spit_le_to_uint : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -34,8 +36,10 @@ Definition spit_le_to_uint : Value.t -> Value.t -> M := num_words: The number of words to be extracted " in - let words := - make_list [] in + let _ := M.assign_local (| + "words" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "i" |), @@ -47,14 +51,16 @@ Definition spit_le_to_uint : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let start_position := + let _ := M.assign_local (| + "start_position" , BinOp.add (| M.get_name (| globals, "start" |), BinOp.mult (| M.get_name (| globals, "i" |), Constant.int 8 |) - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "words" |), "append" |), make_list [ @@ -107,7 +113,8 @@ Definition Blake2 : Value.t := data : The bytes data that has been passed in the message. " in - let rounds := + let _ := M.assign_local (| + "rounds" , M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ @@ -119,8 +126,10 @@ Definition Blake2 : Value.t := |) ], make_dict [] - |) in - let h := + |) + |) in + let _ := M.assign_local (| + "h" , M.call (| M.get_name (| globals, "spit_le_to_uint" |), make_list [ @@ -129,8 +138,10 @@ Definition Blake2 : Value.t := Constant.int 8 ], make_dict [] - |) in - let m := + |) + |) in + let _ := M.assign_local (| + "m" , M.call (| M.get_name (| globals, "spit_le_to_uint" |), make_list [ @@ -139,7 +150,8 @@ Definition Blake2 : Value.t := Constant.int 16 ], make_dict [] - |) in + |) + |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "t_0" |); M.get_name (| globals, "t_1" |) ], M.call (| @@ -152,7 +164,8 @@ Definition Blake2 : Value.t := make_dict [] |) |) in - let f := + let _ := M.assign_local (| + "f" , M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ @@ -164,7 +177,8 @@ Definition Blake2 : Value.t := |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| make_tuple [ M.get_name (| globals, "rounds" |); M.get_name (| globals, "h" |); M.get_name (| globals, "m" |); M.get_name (| globals, "t_0" |); M.get_name (| globals, "t_1" |); M.get_name (| globals, "f" |) ] |) in @@ -443,13 +457,15 @@ Definition Blake2 : Value.t := f: The final block indicator flag. An 8-bit word " in - let v := + let _ := M.assign_local (| + "v" , BinOp.mult (| make_list [ Constant.int 0 ], Constant.int 16 - |) in + |) + |) in let _ := M.assign (| M.slice (| M.get_name (| globals, "v" |), @@ -529,15 +545,18 @@ Definition Blake2 : Value.t := make_dict [] |), ltac:(M.monadic ( - let s := + let _ := M.assign_local (| + "s" , M.get_subscript (| M.get_field (| M.get_name (| globals, "self" |), "sigma" |), BinOp.mod_ (| M.get_name (| globals, "r" |), M.get_field (| M.get_name (| globals, "self" |), "sigma_len" |) |) - |) in - let v := + |) + |) in + let _ := M.assign_local (| + "v" , M.call (| M.get_field (| M.get_name (| globals, "self" |), "G" |), make_list [ @@ -562,8 +581,10 @@ Definition Blake2 : Value.t := |) ], make_dict [] - |) in - let v := + |) + |) in + let _ := M.assign_local (| + "v" , M.call (| M.get_field (| M.get_name (| globals, "self" |), "G" |), make_list [ @@ -588,8 +609,10 @@ Definition Blake2 : Value.t := |) ], make_dict [] - |) in - let v := + |) + |) in + let _ := M.assign_local (| + "v" , M.call (| M.get_field (| M.get_name (| globals, "self" |), "G" |), make_list [ @@ -614,8 +637,10 @@ Definition Blake2 : Value.t := |) ], make_dict [] - |) in - let v := + |) + |) in + let _ := M.assign_local (| + "v" , M.call (| M.get_field (| M.get_name (| globals, "self" |), "G" |), make_list [ @@ -640,8 +665,10 @@ Definition Blake2 : Value.t := |) ], make_dict [] - |) in - let v := + |) + |) in + let _ := M.assign_local (| + "v" , M.call (| M.get_field (| M.get_name (| globals, "self" |), "G" |), make_list [ @@ -666,8 +693,10 @@ Definition Blake2 : Value.t := |) ], make_dict [] - |) in - let v := + |) + |) in + let _ := M.assign_local (| + "v" , M.call (| M.get_field (| M.get_name (| globals, "self" |), "G" |), make_list [ @@ -692,8 +721,10 @@ Definition Blake2 : Value.t := |) ], make_dict [] - |) in - let v := + |) + |) in + let _ := M.assign_local (| + "v" , M.call (| M.get_field (| M.get_name (| globals, "self" |), "G" |), make_list [ @@ -718,8 +749,10 @@ Definition Blake2 : Value.t := |) ], make_dict [] - |) in - let v := + |) + |) in + let _ := M.assign_local (| + "v" , M.call (| M.get_field (| M.get_name (| globals, "self" |), "G" |), make_list [ @@ -744,15 +777,18 @@ Definition Blake2 : Value.t := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let result_message_words := - Constant.str "(* At expr: unsupported node type: GeneratorExp *)" in + let _ := M.assign_local (| + "result_message_words" , + Constant.str "(* At expr: unsupported node type: GeneratorExp *)" + |) in let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "struct" |), "pack" |), diff --git a/CoqOfPython/ethereum/crypto/elliptic_curve.v b/CoqOfPython/ethereum/crypto/elliptic_curve.v index da924f9..3b7436b 100644 --- a/CoqOfPython/ethereum/crypto/elliptic_curve.v +++ b/CoqOfPython/ethereum/crypto/elliptic_curve.v @@ -8,19 +8,25 @@ Elliptic Curves ^^^^^^^^^^^^^^^ ". -Axiom typing_imports : - AreImported globals "typing" [ "Generic"; "Type"; "TypeVar" ]. +Axiom typing_imports_Generic : + IsImported globals "typing" "Generic". +Axiom typing_imports_Type : + IsImported globals "typing" "Type". +Axiom typing_imports_TypeVar : + IsImported globals "typing" "TypeVar". (* At top_level_stmt: unsupported node type: Import *) -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". -Axiom ethereum_crypto_finite_field_imports : - AreImported globals "ethereum.crypto.finite_field" [ "Field" ]. +Axiom ethereum_crypto_finite_field_imports_Field : + IsImported globals "ethereum.crypto.finite_field" "Field". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". Definition SECP256K1N : Value.t := M.run ltac:(M.monadic ( Constant.int 115792089237316195423570985008687907852837564279074904382605163141518161494337 @@ -68,19 +74,24 @@ Definition secp256k1_recover : Value.t -> Value.t -> M := public_key : `ethereum.base_types.Bytes` Recovered public key. " in - let r_bytes := + let _ := M.assign_local (| + "r_bytes" , M.call (| M.get_field (| M.get_name (| globals, "r" |), "to_be_bytes32" |), make_list [], make_dict [] - |) in - let s_bytes := + |) + |) in + let _ := M.assign_local (| + "s_bytes" , M.call (| M.get_field (| M.get_name (| globals, "s" |), "to_be_bytes32" |), make_list [], make_dict [] - |) in - let signature := + |) + |) in + let _ := M.assign_local (| + "signature" , M.call (| M.get_name (| globals, "bytearray" |), make_list [ @@ -92,7 +103,8 @@ Definition secp256k1_recover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.slice (| M.get_name (| globals, "signature" |), @@ -136,7 +148,8 @@ Definition secp256k1_recover : Value.t -> Value.t -> M := |), M.get_name (| globals, "v" |) |) in - let public_key := + let _ := M.assign_local (| + "public_key" , M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "coincurve" |), "PublicKey" |), "from_signature_and_message" |), make_list [ @@ -150,8 +163,10 @@ Definition secp256k1_recover : Value.t -> Value.t -> M := M.get_name (| globals, "msg_hash" |) ], make_dict [] - |) in - let public_key := + |) + |) in + let _ := M.assign_local (| + "public_key" , M.slice (| M.call (| M.get_field (| M.get_name (| globals, "public_key" |), "format" |), @@ -161,7 +176,8 @@ Definition secp256k1_recover : Value.t -> Value.t -> M := Constant.int 1, Constant.None_, Constant.None_ - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "public_key" |) |) in @@ -213,14 +229,16 @@ Definition EllipticCurve : Value.t := Make new point on the curve. The point is not checked to see if it is on the curve. " in - let res := + let _ := M.assign_local (| + "res" , M.call (| M.get_field (| M.get_name (| globals, "object" |), "__new__" |), make_list [ M.get_name (| globals, "cls" |) ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "res" |), "x" |), M.get_name (| globals, "x" |) @@ -415,7 +433,8 @@ Definition EllipticCurve : Value.t := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let lam := + let _ := M.assign_local (| + "lam" , BinOp.div (| BinOp.add (| BinOp.mult (| @@ -443,8 +462,10 @@ Definition EllipticCurve : Value.t := |), M.get_name (| globals, "y" |) |) - |) in - let new_x := + |) + |) in + let _ := M.assign_local (| + "new_x" , BinOp.sub (| BinOp.sub (| BinOp.pow (| @@ -454,8 +475,10 @@ Definition EllipticCurve : Value.t := M.get_name (| globals, "x" |) |), M.get_name (| globals, "x" |) - |) in - let new_y := + |) + |) in + let _ := M.assign_local (| + "new_y" , BinOp.sub (| BinOp.mult (| M.get_name (| globals, "lam" |), @@ -465,7 +488,8 @@ Definition EllipticCurve : Value.t := |) |), M.get_name (| globals, "y" |) - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "self" |), "__new__" |), @@ -492,12 +516,14 @@ Definition EllipticCurve : Value.t := let _ := Constant.str " Add two points together. " in - let ZERO := + let _ := M.assign_local (| + "ZERO" , M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "self" |), "FIELD" |), "zero" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "self_x" |); M.get_name (| globals, "self_y" |); M.get_name (| globals, "other_x" |); M.get_name (| globals, "other_y" |) ], make_tuple [ M.get_field (| M.get_name (| globals, "self" |), "x" |); M.get_field (| M.get_name (| globals, "self" |), "y" |); M.get_field (| M.get_name (| globals, "other" |), "x" |); M.get_field (| M.get_name (| globals, "other" |), "y" |) ] @@ -594,7 +620,8 @@ Definition EllipticCurve : Value.t := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let lam := + let _ := M.assign_local (| + "lam" , BinOp.div (| BinOp.sub (| M.get_name (| globals, "other_y" |), @@ -604,8 +631,10 @@ Definition EllipticCurve : Value.t := M.get_name (| globals, "other_x" |), M.get_name (| globals, "self_x" |) |) - |) in - let x := + |) + |) in + let _ := M.assign_local (| + "x" , BinOp.sub (| BinOp.sub (| BinOp.pow (| @@ -615,8 +644,10 @@ Definition EllipticCurve : Value.t := M.get_name (| globals, "self_x" |) |), M.get_name (| globals, "other_x" |) - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , BinOp.sub (| BinOp.mult (| M.get_name (| globals, "lam" |), @@ -626,7 +657,8 @@ Definition EllipticCurve : Value.t := |) |), M.get_name (| globals, "self_y" |) - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "self" |), "__new__" |), @@ -653,7 +685,8 @@ Definition EllipticCurve : Value.t := let _ := Constant.str " Multiply `self` by `n` using the double and add algorithm. " in - let res := + let _ := M.assign_local (| + "res" , M.call (| M.get_field (| M.get_name (| globals, "self" |), "__new__" |), make_list [ @@ -676,9 +709,12 @@ Definition EllipticCurve : Value.t := |) ], make_dict [] - |) in - let s := - M.get_name (| globals, "self" |) in + |) + |) in + let _ := M.assign_local (| + "s" , + M.get_name (| globals, "self" |) + |) in let _ := M.while (| Compare.not_eq (| @@ -698,24 +734,30 @@ Definition EllipticCurve : Value.t := |), (* then *) ltac:(M.monadic ( - let res := + let _ := M.assign_local (| + "res" , BinOp.add (| M.get_name (| globals, "res" |), M.get_name (| globals, "s" |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let s := + let _ := M.assign_local (| + "s" , BinOp.add (| M.get_name (| globals, "s" |), M.get_name (| globals, "s" |) - |) in - let n := BinOp.floor_div + |) + |) in + let _ := M.assign_op_local (| + BinOp.floor_div, + "n", Constant.int 2 - Constant.int 2 in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/crypto/finite_field.v b/CoqOfPython/ethereum/crypto/finite_field.v index 71dd446..fa90840 100644 --- a/CoqOfPython/ethereum/crypto/finite_field.v +++ b/CoqOfPython/ethereum/crypto/finite_field.v @@ -8,14 +8,26 @@ Finite Fields ^^^^^^^^^^^^^ ". -Axiom typing_imports : - AreImported globals "typing" [ "Iterable"; "List"; "Tuple"; "Type"; "TypeVar"; "cast" ]. +Axiom typing_imports_Iterable : + IsImported globals "typing" "Iterable". +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Type : + IsImported globals "typing" "Type". +Axiom typing_imports_TypeVar : + IsImported globals "typing" "TypeVar". +Axiom typing_imports_cast : + IsImported globals "typing" "cast". -Axiom typing_extensions_imports : - AreImported globals "typing_extensions" [ "Protocol" ]. +Axiom typing_extensions_imports_Protocol : + IsImported globals "typing_extensions" "Protocol". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Bytes"; "Bytes32" ]. +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". Definition F : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -35,14 +47,14 @@ Definition Field : Value.t := "zero", fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "cls" ] |) in - let _ := (* At constant: unsupported node type: Constant *) in + let _ := Constant.ellipsis in M.pure Constant.None_)) ); ( "from_int", fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "cls"; "n" ] |) in - let _ := (* At constant: unsupported node type: Constant *) in + let _ := Constant.ellipsis in M.pure Constant.None_)) ) ] @@ -51,84 +63,84 @@ Definition Field : Value.t := "__radd__", fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "left" ] |) in - let _ := (* At constant: unsupported node type: Constant *) in + let _ := Constant.ellipsis in M.pure Constant.None_)) ); ( "__add__", fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in - let _ := (* At constant: unsupported node type: Constant *) in + let _ := Constant.ellipsis in M.pure Constant.None_)) ); ( "__iadd__", fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in - let _ := (* At constant: unsupported node type: Constant *) in + let _ := Constant.ellipsis in M.pure Constant.None_)) ); ( "__sub__", fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in - let _ := (* At constant: unsupported node type: Constant *) in + let _ := Constant.ellipsis in M.pure Constant.None_)) ); ( "__rsub__", fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "left" ] |) in - let _ := (* At constant: unsupported node type: Constant *) in + let _ := Constant.ellipsis in M.pure Constant.None_)) ); ( "__mul__", fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in - let _ := (* At constant: unsupported node type: Constant *) in + let _ := Constant.ellipsis in M.pure Constant.None_)) ); ( "__rmul__", fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "left" ] |) in - let _ := (* At constant: unsupported node type: Constant *) in + let _ := Constant.ellipsis in M.pure Constant.None_)) ); ( "__imul__", fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in - let _ := (* At constant: unsupported node type: Constant *) in + let _ := Constant.ellipsis in M.pure Constant.None_)) ); ( "__pow__", fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "exponent" ] |) in - let _ := (* At constant: unsupported node type: Constant *) in + let _ := Constant.ellipsis in M.pure Constant.None_)) ); ( "__ipow__", fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in - let _ := (* At constant: unsupported node type: Constant *) in + let _ := Constant.ellipsis in M.pure Constant.None_)) ); ( "__neg__", fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self" ] |) in - let _ := (* At constant: unsupported node type: Constant *) in + let _ := Constant.ellipsis in M.pure Constant.None_)) ); ( "__truediv__", fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in - let _ := (* At constant: unsupported node type: Constant *) in + let _ := Constant.ellipsis in M.pure Constant.None_)) ) ]. @@ -714,8 +726,10 @@ Definition GaloisField : Value.t := let _ := Constant.str " Calculate the coefficients needed by `frobenius()`. " in - let coefficients := - make_list [] in + let _ := M.assign_local (| + "coefficients" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "i" |), @@ -733,7 +747,8 @@ Definition GaloisField : Value.t := make_dict [] |), ltac:(M.monadic ( - let x := + let _ := M.assign_local (| + "x" , BinOp.mult (| make_list [ Constant.int 0 @@ -745,7 +760,8 @@ Definition GaloisField : Value.t := ], make_dict [] |) - |) in + |) + |) in let _ := M.assign (| M.get_subscript (| M.get_name (| globals, "x" |), @@ -793,7 +809,8 @@ Definition GaloisField : Value.t := "__new__", fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "cls"; "iterable" ] |) in - let self := + let _ := M.assign_local (| + "self" , M.call (| M.get_field (| M.get_name (| globals, "tuple" |), "__new__" |), make_list [ @@ -801,7 +818,8 @@ Definition GaloisField : Value.t := Constant.str "(* At expr: unsupported node type: GeneratorExp *)" ], make_dict [] - |) in + |) + |) in let _ := M.assert (| Compare.eq (| M.call (| M.get_name (| globals, "len" |), @@ -1006,19 +1024,26 @@ Definition GaloisField : Value.t := "__mul__", fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "right" ] |) in - let modulus := - M.get_field (| M.get_name (| globals, "self" |), "MODULUS" |) in - let degree := + let _ := M.assign_local (| + "modulus" , + M.get_field (| M.get_name (| globals, "self" |), "MODULUS" |) + |) in + let _ := M.assign_local (| + "degree" , M.call (| M.get_name (| globals, "len" |), make_list [ M.get_name (| globals, "modulus" |) ], make_dict [] - |) in - let prime := - M.get_field (| M.get_name (| globals, "self" |), "PRIME" |) in - let mul := + |) + |) in + let _ := M.assign_local (| + "prime" , + M.get_field (| M.get_name (| globals, "self" |), "PRIME" |) + |) in + let _ := M.assign_local (| + "mul" , BinOp.mult (| make_list [ Constant.int 0 @@ -1027,7 +1052,8 @@ Definition GaloisField : Value.t := M.get_name (| globals, "degree" |), Constant.int 2 |) - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "i" |), @@ -1346,8 +1372,10 @@ Definition GaloisField : Value.t := Calculate the multiplicative inverse. Uses the Euclidean algorithm. " in (* At stmt: unsupported node type: AnnAssign *) - let p := - M.get_field (| M.get_name (| globals, "self" |), "PRIME" |) in + let _ := M.assign_local (| + "p" , + M.get_field (| M.get_name (| globals, "self" |), "PRIME" |) + |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "x1" |); M.get_name (| globals, "f1" |) ], make_tuple [ M.call (| @@ -1402,7 +1430,8 @@ Definition GaloisField : Value.t := make_dict [] |) ] |) in - let q_0 := + let _ := M.assign_local (| + "q_0" , M.call (| M.get_name (| globals, "pow" |), make_list [ @@ -1414,7 +1443,8 @@ Definition GaloisField : Value.t := M.get_name (| globals, "p" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "i" |), @@ -1558,8 +1588,10 @@ Definition GaloisField : Value.t := |), (* then *) ltac:(M.monadic ( - let d1 := - M.get_name (| globals, "i" |) in + let _ := M.assign_local (| + "d1" , + M.get_name (| globals, "i" |) + |) in let _ := M.break (| |) in M.pure Constant.None_ (* else *) @@ -1585,9 +1617,12 @@ Definition GaloisField : Value.t := |), (* then *) ltac:(M.monadic ( - let ans := - M.get_name (| globals, "f1" |) in - let q := + let _ := M.assign_local (| + "ans" , + M.get_name (| globals, "f1" |) + |) in + let _ := M.assign_local (| + "q" , M.call (| M.get_name (| globals, "pow" |), make_list [ @@ -1599,7 +1634,8 @@ Definition GaloisField : Value.t := M.get_field (| M.get_name (| globals, "self" |), "PRIME" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "i" |), @@ -1644,9 +1680,12 @@ Definition GaloisField : Value.t := |), (* then *) ltac:(M.monadic ( - let ans := - M.get_name (| globals, "f2" |) in - let q := + let _ := M.assign_local (| + "ans" , + M.get_name (| globals, "f2" |) + |) in + let _ := M.assign_local (| + "q" , M.call (| M.get_name (| globals, "pow" |), make_list [ @@ -1658,7 +1697,8 @@ Definition GaloisField : Value.t := M.get_field (| M.get_name (| globals, "self" |), "PRIME" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "i" |), @@ -1676,9 +1716,11 @@ Definition GaloisField : Value.t := make_dict [] |), ltac:(M.monadic ( - let ans := BinOp.mult + let _ := M.assign_op_local (| + BinOp.mult, + "ans", M.get_name (| globals, "q" |) - M.get_name (| globals, "q" |) in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -1702,7 +1744,8 @@ Definition GaloisField : Value.t := |), (* then *) ltac:(M.monadic ( - let q := + let _ := M.assign_local (| + "q" , BinOp.mult (| M.get_subscript (| M.get_name (| globals, "x2" |), @@ -1720,7 +1763,8 @@ Definition GaloisField : Value.t := ], make_dict [] |) - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "i" |), @@ -1828,9 +1872,11 @@ Definition GaloisField : Value.t := Constant.int 0 |), ltac:(M.monadic ( - let d2 := BinOp.sub + let _ := M.assign_op_local (| + BinOp.sub, + "d2", Constant.int 1 - Constant.int 1 in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -1840,7 +1886,8 @@ Definition GaloisField : Value.t := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let q := + let _ := M.assign_local (| + "q" , BinOp.mult (| M.get_subscript (| M.get_name (| globals, "x1" |), @@ -1858,7 +1905,8 @@ Definition GaloisField : Value.t := ], make_dict [] |) - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "i" |), @@ -1966,9 +2014,11 @@ Definition GaloisField : Value.t := Constant.int 0 |), ltac:(M.monadic ( - let d1 := BinOp.sub + let _ := M.assign_op_local (| + BinOp.sub, + "d1", Constant.int 1 - Constant.int 1 in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -2005,14 +2055,16 @@ Definition GaloisField : Value.t := "__pow__", fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "self"; "exponent" ] |) in - let degree := + let _ := M.assign_local (| + "degree" , M.call (| M.get_name (| globals, "len" |), make_list [ M.get_field (| M.get_name (| globals, "self" |), "MODULUS" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -2022,20 +2074,25 @@ Definition GaloisField : Value.t := |), (* then *) ltac:(M.monadic ( - let self := + let _ := M.assign_local (| + "self" , M.call (| M.get_field (| M.get_name (| globals, "self" |), "multiplicative_inverse" |), make_list [], make_dict [] - |) in - let exponent := - UnOp.sub (| M.get_name (| globals, "exponent" |) |) in + |) + |) in + let _ := M.assign_local (| + "exponent" , + UnOp.sub (| M.get_name (| globals, "exponent" |) |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let res := + let _ := M.assign_local (| + "res" , M.call (| M.get_field (| M.get_name (| globals, "self" |), "__new__" |), make_list [ @@ -2062,9 +2119,12 @@ Definition GaloisField : Value.t := |) ], make_dict [] - |) in - let s := - M.get_name (| globals, "self" |) in + |) + |) in + let _ := M.assign_local (| + "s" , + M.get_name (| globals, "self" |) + |) in let _ := M.while (| Compare.not_eq (| @@ -2084,20 +2144,26 @@ Definition GaloisField : Value.t := |), (* then *) ltac:(M.monadic ( - let res := BinOp.mult + let _ := M.assign_op_local (| + BinOp.mult, + "res", M.get_name (| globals, "s" |) - M.get_name (| globals, "s" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let s := BinOp.mult + let _ := M.assign_op_local (| + BinOp.mult, + "s", M.get_name (| globals, "s" |) - M.get_name (| globals, "s" |) in - let exponent := BinOp.floor_div + |) in + let _ := M.assign_op_local (| + BinOp.floor_div, + "exponent", Constant.int 2 - Constant.int 2 in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -2134,14 +2200,16 @@ Definition GaloisField : Value.t := particular it is extremely cheap to compute compared to other exponentiations. " in - let ans := + let _ := M.assign_local (| + "ans" , M.call (| M.get_field (| M.get_name (| globals, "self" |), "from_int" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in (* At stmt: unsupported node type: AnnAssign *) let _ := M.for_ (| @@ -2154,7 +2222,9 @@ Definition GaloisField : Value.t := make_dict [] |), ltac:(M.monadic ( - let ans := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "ans", M.call (| M.get_field (| M.call (| M.get_name (| globals, "cast" |), @@ -2172,23 +2242,7 @@ Definition GaloisField : Value.t := ], make_dict [] |) - M.call (| - M.get_field (| M.call (| - M.get_name (| globals, "cast" |), - make_list [ - M.get_name (| globals, "U" |); - M.get_subscript (| - M.get_field (| M.get_name (| globals, "self" |), "FROBENIUS_COEFFICIENTS" |), - M.get_name (| globals, "i" |) - |) - ], - make_dict [] - |), "scalar_mul" |), - make_list [ - M.get_name (| globals, "a" |) - ], - make_dict [] - |) in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/crypto/hash.v b/CoqOfPython/ethereum/crypto/hash.v index 4fa9d00..ffb11bc 100644 --- a/CoqOfPython/ethereum/crypto/hash.v +++ b/CoqOfPython/ethereum/crypto/hash.v @@ -17,11 +17,15 @@ Introduction Cryptographic hashing functions. ". -Axiom Crypto_Hash_imports : - AreImported globals "Crypto.Hash" [ "keccak" ]. +Axiom Crypto_Hash_imports_keccak : + IsImported globals "Crypto.Hash" "keccak". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Bytes"; "Bytes32"; "Bytes64" ]. +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Bytes64 : + IsImported globals "ethereum.base_types" "Bytes64". Definition Hash32 : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes32" |) @@ -47,12 +51,14 @@ Definition keccak256 : Value.t -> Value.t -> M := hash : `ethereum.base_types.Hash32` Output of the hash function. " in - let k := + let _ := M.assign_local (| + "k" , M.call (| M.get_field (| M.get_name (| globals, "keccak" |), "new" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Hash32" |), @@ -90,12 +96,14 @@ Definition keccak512 : Value.t -> Value.t -> M := hash : `ethereum.base_types.Hash32` Output of the hash function. " in - let k := + let _ := M.assign_local (| + "k" , M.call (| M.get_field (| M.get_name (| globals, "keccak" |), "new" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Hash64" |), diff --git a/CoqOfPython/ethereum/dao_fork/__init__.v b/CoqOfPython/ethereum/dao_fork/__init__.v index 3a5a97a..12b0f7a 100644 --- a/CoqOfPython/ethereum/dao_fork/__init__.v +++ b/CoqOfPython/ethereum/dao_fork/__init__.v @@ -9,8 +9,8 @@ Attack where a vulnerable contract was drained of its ether. This fork recovers the stolen funds into a new contract. ". -Axiom ethereum_fork_criteria_imports : - AreImported globals "ethereum.fork_criteria" [ "ByBlockNumber" ]. +Axiom ethereum_fork_criteria_imports_ByBlockNumber : + IsImported globals "ethereum.fork_criteria" "ByBlockNumber". Definition FORK_CRITERIA : Value.t := M.run ltac:(M.monadic ( M.call (| diff --git a/CoqOfPython/ethereum/dao_fork/blocks.v b/CoqOfPython/ethereum/dao_fork/blocks.v index a7d4e0a..0707efe 100644 --- a/CoqOfPython/ethereum/dao_fork/blocks.v +++ b/CoqOfPython/ethereum/dao_fork/blocks.v @@ -14,23 +14,37 @@ history of all state transitions that have happened since the genesis of the chain. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Tuple" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes8"; "Bytes32"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. - -Axiom ethereum_dao_fork_fork_types_imports : - AreImported globals "ethereum.dao_fork.fork_types" [ "Address"; "Bloom"; "Root" ]. - -Axiom ethereum_dao_fork_transactions_imports : - AreImported globals "ethereum.dao_fork.transactions" [ "Transaction" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes8 : + IsImported globals "ethereum.base_types" "Bytes8". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". + +Axiom ethereum_dao_fork_fork_types_imports_Address : + IsImported globals "ethereum.dao_fork.fork_types" "Address". +Axiom ethereum_dao_fork_fork_types_imports_Bloom : + IsImported globals "ethereum.dao_fork.fork_types" "Bloom". +Axiom ethereum_dao_fork_fork_types_imports_Root : + IsImported globals "ethereum.dao_fork.fork_types" "Root". + +Axiom ethereum_dao_fork_transactions_imports_Transaction : + IsImported globals "ethereum.dao_fork.transactions" "Transaction". Definition Header : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/dao_fork/bloom.v b/CoqOfPython/ethereum/dao_fork/bloom.v index e7f9fae..4b83130 100644 --- a/CoqOfPython/ethereum/dao_fork/bloom.v +++ b/CoqOfPython/ethereum/dao_fork/bloom.v @@ -21,20 +21,20 @@ for efficient searching of logs by address and/or topic, by rapidly eliminating blocks and receipts from their search. ". -Axiom typing_imports : - AreImported globals "typing" [ "Tuple" ]. +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_dao_fork_blocks_imports : - AreImported globals "ethereum.dao_fork.blocks" [ "Log" ]. +Axiom ethereum_dao_fork_blocks_imports_Log : + IsImported globals "ethereum.dao_fork.blocks" "Log". -Axiom ethereum_dao_fork_fork_types_imports : - AreImported globals "ethereum.dao_fork.fork_types" [ "Bloom" ]. +Axiom ethereum_dao_fork_fork_types_imports_Bloom : + IsImported globals "ethereum.dao_fork.fork_types" "Bloom". Definition add_to_bloom : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -53,20 +53,23 @@ Definition add_to_bloom : Value.t -> Value.t -> M := bloom_entry : An entry which is to be added to bloom filter. " in - let hash := + let _ := M.assign_local (| + "hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "bloom_entry" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "idx" |), make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ], ltac:(M.monadic ( - let bit_to_set := + let _ := M.assign_local (| + "bit_to_set" , BinOp.bit_and (| M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), @@ -84,18 +87,24 @@ Definition add_to_bloom : Value.t -> Value.t -> M := make_dict [] |), Constant.int 2047 - |) in - let bit_index := + |) + |) in + let _ := M.assign_local (| + "bit_index" , BinOp.sub (| Constant.int 2047, M.get_name (| globals, "bit_to_set" |) - |) in - let byte_index := + |) + |) in + let _ := M.assign_local (| + "byte_index" , BinOp.floor_div (| M.get_name (| globals, "bit_index" |), Constant.int 8 - |) in - let bit_value := + |) + |) in + let _ := M.assign_local (| + "bit_value" , BinOp.l_shift (| Constant.int 1, BinOp.sub (| @@ -105,7 +114,8 @@ Definition add_to_bloom : Value.t -> Value.t -> M := Constant.int 8 |) |) - |) in + |) + |) in let _ := M.assign (| M.get_subscript (| M.get_name (| globals, "bloom" |), diff --git a/CoqOfPython/ethereum/dao_fork/dao.v b/CoqOfPython/ethereum/dao_fork/dao.v index 5664341..160f310 100644 --- a/CoqOfPython/ethereum/dao_fork/dao.v +++ b/CoqOfPython/ethereum/dao_fork/dao.v @@ -20,11 +20,15 @@ collection of accounts (The Dao and all its children) to a recovery contract. The recovery contract was previously created using normal contract deployment. ". -Axiom ethereum_dao_fork_state_imports : - AreImported globals "ethereum.dao_fork.state" [ "State"; "get_account"; "move_ether" ]. +Axiom ethereum_dao_fork_state_imports_State : + IsImported globals "ethereum.dao_fork.state" "State". +Axiom ethereum_dao_fork_state_imports_get_account : + IsImported globals "ethereum.dao_fork.state" "get_account". +Axiom ethereum_dao_fork_state_imports_move_ether : + IsImported globals "ethereum.dao_fork.state" "move_ether". -Axiom ethereum_dao_fork_utils_hexadecimal_imports : - AreImported globals "ethereum.dao_fork.utils.hexadecimal" [ "hex_to_address" ]. +Axiom ethereum_dao_fork_utils_hexadecimal_imports_hex_to_address : + IsImported globals "ethereum.dao_fork.utils.hexadecimal" "hex_to_address". Definition DAO_ACCOUNTS : Value.t := M.run ltac:(M.monadic ( Constant.str "(* At expr: unsupported node type: ListComp *)" @@ -56,7 +60,8 @@ Definition apply_dao : Value.t -> Value.t -> M := M.get_name (| globals, "address" |), M.get_name (| globals, "DAO_ACCOUNTS" |), ltac:(M.monadic ( - let balance := + let _ := M.assign_local (| + "balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -64,7 +69,8 @@ Definition apply_dao : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := M.call (| M.get_name (| globals, "move_ether" |), make_list [ diff --git a/CoqOfPython/ethereum/dao_fork/fork.v b/CoqOfPython/ethereum/dao_fork/fork.v index ef20c56..cd0c092 100644 --- a/CoqOfPython/ethereum/dao_fork/fork.v +++ b/CoqOfPython/ethereum/dao_fork/fork.v @@ -19,65 +19,125 @@ Introduction Entry point for the Ethereum specification. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Bytes0" ]. - -Axiom ethereum_crypto_elliptic_curve_imports : - AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. - -Axiom ethereum_ethash_imports : - AreImported globals "ethereum.ethash" [ "dataset_size"; "generate_cache"; "hashimoto_light" ]. - -Axiom ethereum_exceptions_imports : - AreImported globals "ethereum.exceptions" [ "InvalidBlock" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U64"; "U256"; "U256_CEIL_VALUE"; "Bytes"; "Bytes32"; "Uint" ]. - -Axiom ethereum_dao_fork_imports : - AreImported globals "ethereum.dao_fork" [ "FORK_CRITERIA"; "vm" ]. - -Axiom ethereum_dao_fork_blocks_imports : - AreImported globals "ethereum.dao_fork.blocks" [ "Block"; "Header"; "Log"; "Receipt" ]. - -Axiom ethereum_dao_fork_bloom_imports : - AreImported globals "ethereum.dao_fork.bloom" [ "logs_bloom" ]. - -Axiom ethereum_dao_fork_dao_imports : - AreImported globals "ethereum.dao_fork.dao" [ "apply_dao" ]. - -Axiom ethereum_dao_fork_fork_types_imports : - AreImported globals "ethereum.dao_fork.fork_types" [ "Address"; "Bloom"; "Root" ]. - -Axiom ethereum_dao_fork_state_imports : - AreImported globals "ethereum.dao_fork.state" [ "State"; "create_ether"; "destroy_account"; "get_account"; "increment_nonce"; "set_account_balance"; "state_root" ]. - -Axiom ethereum_dao_fork_transactions_imports : - AreImported globals "ethereum.dao_fork.transactions" [ "TX_BASE_COST"; "TX_CREATE_COST"; "TX_DATA_COST_PER_NON_ZERO"; "TX_DATA_COST_PER_ZERO"; "Transaction" ]. - -Axiom ethereum_dao_fork_trie_imports : - AreImported globals "ethereum.dao_fork.trie" [ "Trie"; "root"; "trie_set" ]. - -Axiom ethereum_dao_fork_utils_message_imports : - AreImported globals "ethereum.dao_fork.utils.message" [ "prepare_message" ]. - -Axiom ethereum_dao_fork_vm_interpreter_imports : - AreImported globals "ethereum.dao_fork.vm.interpreter" [ "process_message_call" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". + +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". + +Axiom ethereum_crypto_elliptic_curve_imports_SECP256K1N : + IsImported globals "ethereum.crypto.elliptic_curve" "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_imports_secp256k1_recover : + IsImported globals "ethereum.crypto.elliptic_curve" "secp256k1_recover". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". + +Axiom ethereum_ethash_imports_dataset_size : + IsImported globals "ethereum.ethash" "dataset_size". +Axiom ethereum_ethash_imports_generate_cache : + IsImported globals "ethereum.ethash" "generate_cache". +Axiom ethereum_ethash_imports_hashimoto_light : + IsImported globals "ethereum.ethash" "hashimoto_light". + +Axiom ethereum_exceptions_imports_InvalidBlock : + IsImported globals "ethereum.exceptions" "InvalidBlock". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U64 : + IsImported globals "ethereum.base_types" "U64". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_U256_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U256_CEIL_VALUE". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_dao_fork_imports_FORK_CRITERIA : + IsImported globals "ethereum.dao_fork" "FORK_CRITERIA". +Axiom ethereum_dao_fork_imports_vm : + IsImported globals "ethereum.dao_fork" "vm". + +Axiom ethereum_dao_fork_blocks_imports_Block : + IsImported globals "ethereum.dao_fork.blocks" "Block". +Axiom ethereum_dao_fork_blocks_imports_Header : + IsImported globals "ethereum.dao_fork.blocks" "Header". +Axiom ethereum_dao_fork_blocks_imports_Log : + IsImported globals "ethereum.dao_fork.blocks" "Log". +Axiom ethereum_dao_fork_blocks_imports_Receipt : + IsImported globals "ethereum.dao_fork.blocks" "Receipt". + +Axiom ethereum_dao_fork_bloom_imports_logs_bloom : + IsImported globals "ethereum.dao_fork.bloom" "logs_bloom". + +Axiom ethereum_dao_fork_dao_imports_apply_dao : + IsImported globals "ethereum.dao_fork.dao" "apply_dao". + +Axiom ethereum_dao_fork_fork_types_imports_Address : + IsImported globals "ethereum.dao_fork.fork_types" "Address". +Axiom ethereum_dao_fork_fork_types_imports_Bloom : + IsImported globals "ethereum.dao_fork.fork_types" "Bloom". +Axiom ethereum_dao_fork_fork_types_imports_Root : + IsImported globals "ethereum.dao_fork.fork_types" "Root". + +Axiom ethereum_dao_fork_state_imports_State : + IsImported globals "ethereum.dao_fork.state" "State". +Axiom ethereum_dao_fork_state_imports_create_ether : + IsImported globals "ethereum.dao_fork.state" "create_ether". +Axiom ethereum_dao_fork_state_imports_destroy_account : + IsImported globals "ethereum.dao_fork.state" "destroy_account". +Axiom ethereum_dao_fork_state_imports_get_account : + IsImported globals "ethereum.dao_fork.state" "get_account". +Axiom ethereum_dao_fork_state_imports_increment_nonce : + IsImported globals "ethereum.dao_fork.state" "increment_nonce". +Axiom ethereum_dao_fork_state_imports_set_account_balance : + IsImported globals "ethereum.dao_fork.state" "set_account_balance". +Axiom ethereum_dao_fork_state_imports_state_root : + IsImported globals "ethereum.dao_fork.state" "state_root". + +Axiom ethereum_dao_fork_transactions_imports_TX_BASE_COST : + IsImported globals "ethereum.dao_fork.transactions" "TX_BASE_COST". +Axiom ethereum_dao_fork_transactions_imports_TX_CREATE_COST : + IsImported globals "ethereum.dao_fork.transactions" "TX_CREATE_COST". +Axiom ethereum_dao_fork_transactions_imports_TX_DATA_COST_PER_NON_ZERO : + IsImported globals "ethereum.dao_fork.transactions" "TX_DATA_COST_PER_NON_ZERO". +Axiom ethereum_dao_fork_transactions_imports_TX_DATA_COST_PER_ZERO : + IsImported globals "ethereum.dao_fork.transactions" "TX_DATA_COST_PER_ZERO". +Axiom ethereum_dao_fork_transactions_imports_Transaction : + IsImported globals "ethereum.dao_fork.transactions" "Transaction". + +Axiom ethereum_dao_fork_trie_imports_Trie : + IsImported globals "ethereum.dao_fork.trie" "Trie". +Axiom ethereum_dao_fork_trie_imports_root : + IsImported globals "ethereum.dao_fork.trie" "root". +Axiom ethereum_dao_fork_trie_imports_trie_set : + IsImported globals "ethereum.dao_fork.trie" "trie_set". + +Axiom ethereum_dao_fork_utils_message_imports_prepare_message : + IsImported globals "ethereum.dao_fork.utils.message" "prepare_message". + +Axiom ethereum_dao_fork_vm_interpreter_imports_process_message_call : + IsImported globals "ethereum.dao_fork.vm.interpreter" "process_message_call". Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -189,13 +249,15 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := recent_block_hashes : `List[Hash32]` Hashes of the recent 256 blocks in order of increasing block number. " in - let recent_blocks := + let _ := M.assign_local (| + "recent_blocks" , M.slice (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |), Constant.None_, Constant.None_ - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -219,15 +281,19 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let recent_block_hashes := - make_list [] in + let _ := M.assign_local (| + "recent_block_hashes" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "block" |), M.get_name (| globals, "recent_blocks" |), ltac:(M.monadic ( - let prev_block_hash := - M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in + let _ := M.assign_local (| + "prev_block_hash" , + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), make_list [ @@ -241,7 +307,8 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let most_recent_block_hash := + let _ := M.assign_local (| + "most_recent_block_hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -257,7 +324,8 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), make_list [ @@ -294,11 +362,13 @@ Definition state_transition : Value.t -> Value.t -> M := block : Block to apply to `chain`. " in - let parent_header := + let _ := M.assign_local (| + "parent_header" , M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 1 |) - |), "header" |) in + |), "header" |) + |) in let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ @@ -316,7 +386,8 @@ Definition state_transition : Value.t -> Value.t -> M := ], make_dict [] |) in - let apply_body_output := + let _ := M.assign_local (| + "apply_body_output" , M.call (| M.get_name (| globals, "apply_body" |), make_list [ @@ -337,7 +408,8 @@ Definition state_transition : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "block" |), "ommers" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -508,7 +580,8 @@ Definition validate_header : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_difficulty := + let _ := M.assign_local (| + "block_difficulty" , M.call (| M.get_name (| globals, "calculate_block_difficulty" |), make_list [ @@ -518,7 +591,8 @@ Definition validate_header : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "parent_header" |), "difficulty" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -530,7 +604,8 @@ Definition validate_header : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_parent_hash := + let _ := M.assign_local (| + "block_parent_hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -543,7 +618,8 @@ Definition validate_header : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -625,7 +701,8 @@ Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := hash : `Hash32` The PoW valid rlp hash of the passed in header. " in - let header_data_without_pow_artefacts := + let _ := M.assign_local (| + "header_data_without_pow_artefacts" , make_list [ M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |); M.get_field (| M.get_name (| globals, "header" |), "ommers_hash" |); @@ -640,7 +717,8 @@ Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "header" |), "gas_used" |); M.get_field (| M.get_name (| globals, "header" |), "timestamp" |); M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) - ] in + ] + |) in let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), @@ -669,22 +747,26 @@ Definition validate_proof_of_work : Value.t -> Value.t -> M := header : Header of interest. " in - let header_hash := + let _ := M.assign_local (| + "header_hash" , M.call (| M.get_name (| globals, "generate_header_hash_for_pow" |), make_list [ M.get_name (| globals, "header" |) ], make_dict [] - |) in - let cache := + |) + |) in + let _ := M.assign_local (| + "cache" , M.call (| M.get_name (| globals, "generate_cache" |), make_list [ M.get_field (| M.get_name (| globals, "header" |), "number" |) ], make_dict [] - |) in + |) + |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "mix_digest" |); M.get_name (| globals, "result" |) ], M.call (| @@ -771,14 +853,16 @@ Definition check_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_address := + let _ := M.assign_local (| + "sender_address" , M.call (| M.get_name (| globals, "recover_sender" |), make_list [ M.get_name (| globals, "tx" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "sender_address" |) |) in @@ -807,12 +891,14 @@ Definition make_receipt : Value.t -> Value.t -> M := receipt : The receipt for the transaction. " in - let receipt := + let _ := M.assign_local (| + "receipt" , M.call (| M.get_name (| globals, "Receipt" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "receipt" |) |) in @@ -869,8 +955,10 @@ Definition apply_body : Value.t -> Value.t -> M := apply_body_output : `ApplyBodyOutput` Output of applying the block body to the state. " in - let gas_available := - M.get_name (| globals, "block_gas_limit" |) in + let _ := M.assign_local (| + "gas_available" , + M.get_name (| globals, "block_gas_limit" |) + |) in (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) @@ -906,7 +994,8 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_address := + let _ := M.assign_local (| + "sender_address" , M.call (| M.get_name (| globals, "check_transaction" |), make_list [ @@ -914,13 +1003,16 @@ Definition apply_body : Value.t -> Value.t -> M := M.get_name (| globals, "gas_available" |) ], make_dict [] - |) in - let env := + |) + |) in + let _ := M.assign_local (| + "env" , M.call (| M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |) ], M.call (| @@ -932,10 +1024,13 @@ Definition apply_body : Value.t -> Value.t -> M := make_dict [] |) |) in - let gas_available := BinOp.sub + let _ := M.assign_op_local (| + BinOp.sub, + "gas_available", M.get_name (| globals, "gas_used" |) - M.get_name (| globals, "gas_used" |) in - let receipt := + |) in + let _ := M.assign_local (| + "receipt" , M.call (| M.get_name (| globals, "make_receipt" |), make_list [ @@ -954,7 +1049,8 @@ Definition apply_body : Value.t -> Value.t -> M := M.get_name (| globals, "logs" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ @@ -976,9 +1072,11 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_logs := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "block_logs", M.get_name (| globals, "logs" |) - M.get_name (| globals, "logs" |) in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -995,19 +1093,23 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_gas_used := + let _ := M.assign_local (| + "block_gas_used" , BinOp.sub (| M.get_name (| globals, "block_gas_limit" |), M.get_name (| globals, "gas_available" |) - |) in - let block_logs_bloom := + |) + |) in + let _ := M.assign_local (| + "block_logs_bloom" , M.call (| M.get_name (| globals, "logs_bloom" |), make_list [ M.get_name (| globals, "block_logs" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ApplyBodyOutput" |), @@ -1065,14 +1167,16 @@ Definition validate_ommers : Value.t -> Value.t -> M := chain : History and current state. " in - let block_hash := + let _ := M.assign_local (| + "block_hash" , M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), make_list [ M.get_name (| globals, "block_header" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1137,7 +1241,8 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_parent_header := + let _ := M.assign_local (| + "ommer_parent_header" , M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), BinOp.sub (| @@ -1147,7 +1252,8 @@ Definition validate_ommers : Value.t -> Value.t -> M := |) |), Constant.int 1 |) - |), "header" |) in + |), "header" |) + |) in let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ @@ -1179,8 +1285,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommers_hashes := - Constant.str "(* At expr: unsupported node type: ListComp *)" in + let _ := M.assign_local (| + "ommers_hashes" , + Constant.str "(* At expr: unsupported node type: ListComp *)" + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1210,7 +1318,8 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let recent_canonical_blocks := + let _ := M.assign_local (| + "recent_canonical_blocks" , M.slice (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| BinOp.add (| @@ -1219,23 +1328,28 @@ Definition validate_ommers : Value.t -> Value.t -> M := |) |), Constant.None_, Constant.None_ - |) in - let recent_canonical_block_hashes := - Constant.str "(* At expr: unsupported node type: SetComp *)" in + |) + |) in + let _ := M.assign_local (| + "recent_canonical_block_hashes" , + Constant.str "(* At expr: unsupported node type: SetComp *)" + |) in (* At stmt: unsupported node type: AnnAssign *) let _ := M.for_ (| M.get_name (| globals, "block" |), M.get_name (| globals, "recent_canonical_blocks" |), ltac:(M.monadic ( - let recent_ommers_hashes := + let _ := M.assign_local (| + "recent_ommers_hashes" , M.call (| M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), make_list [ Constant.str "(* At expr: unsupported node type: SetComp *)" ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -1253,11 +1367,13 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let ommer_hash := + let _ := M.assign_local (| + "ommer_hash" , M.get_subscript (| M.get_name (| globals, "ommers_hashes" |), M.get_name (| globals, "ommer_index" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1291,11 +1407,13 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_age := + let _ := M.assign_local (| + "ommer_age" , BinOp.sub (| M.get_field (| M.get_name (| globals, "block_header" |), "number" |), M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1373,7 +1491,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := ommers : List of ommers mentioned in the current block. " in - let miner_reward := + let _ := M.assign_local (| + "miner_reward" , BinOp.add (| M.get_name (| globals, "BLOCK_REWARD" |), BinOp.mult (| @@ -1389,7 +1508,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := Constant.int 32 |) |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "create_ether" |), make_list [ @@ -1404,7 +1524,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := M.get_name (| globals, "ommer" |), M.get_name (| globals, "ommers" |), ltac:(M.monadic ( - let ommer_age := + let _ := M.assign_local (| + "ommer_age" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -1414,8 +1535,10 @@ Definition pay_rewards : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let ommer_miner_reward := + |) + |) in + let _ := M.assign_local (| + "ommer_miner_reward" , BinOp.floor_div (| BinOp.mult (| BinOp.sub (| @@ -1425,7 +1548,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := M.get_name (| globals, "BLOCK_REWARD" |) |), Constant.int 8 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "create_ether" |), make_list [ @@ -1486,9 +1610,12 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender := - M.get_field (| M.get_name (| globals, "env" |), "origin" |) in - let sender_account := + let _ := M.assign_local (| + "sender" , + M.get_field (| M.get_name (| globals, "env" |), "origin" |) + |) in + let _ := M.assign_local (| + "sender_account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1496,12 +1623,15 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "sender" |) ], make_dict [] - |) in - let gas_fee := + |) + |) in + let _ := M.assign_local (| + "gas_fee" , BinOp.mult (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1542,7 +1672,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let gas := + let _ := M.assign_local (| + "gas" , BinOp.sub (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.call (| @@ -1552,7 +1683,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "increment_nonce" |), make_list [ @@ -1561,11 +1693,13 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_balance_after_gas_fee := + let _ := M.assign_local (| + "sender_balance_after_gas_fee" , BinOp.sub (| M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), M.get_name (| globals, "gas_fee" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -1575,7 +1709,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let message := + let _ := M.assign_local (| + "message" , M.call (| M.get_name (| globals, "prepare_message" |), make_list [ @@ -1587,8 +1722,10 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in - let output := + |) + |) in + let _ := M.assign_local (| + "output" , M.call (| M.get_name (| globals, "process_message_call" |), make_list [ @@ -1596,13 +1733,17 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in - let gas_used := + |) + |) in + let _ := M.assign_local (| + "gas_used" , BinOp.sub (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_field (| M.get_name (| globals, "output" |), "gas_left" |) - |) in - let gas_refund := + |) + |) in + let _ := M.assign_local (| + "gas_refund" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -1613,16 +1754,20 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "output" |), "refund_counter" |) ], make_dict [] - |) in - let gas_refund_amount := + |) + |) in + let _ := M.assign_local (| + "gas_refund_amount" , BinOp.mult (| BinOp.add (| M.get_field (| M.get_name (| globals, "output" |), "gas_left" |), M.get_name (| globals, "gas_refund" |) |), M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) - |) in - let transaction_fee := + |) + |) in + let _ := M.assign_local (| + "transaction_fee" , BinOp.mult (| BinOp.sub (| BinOp.sub (| @@ -1632,13 +1777,17 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "gas_refund" |) |), M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) - |) in - let total_gas_used := + |) + |) in + let _ := M.assign_local (| + "total_gas_used" , BinOp.sub (| M.get_name (| globals, "gas_used" |), M.get_name (| globals, "gas_refund" |) - |) in - let sender_balance_after_refund := + |) + |) in + let _ := M.assign_local (| + "sender_balance_after_refund" , BinOp.add (| M.get_field (| M.call (| M.get_name (| globals, "get_account" |), @@ -1649,7 +1798,8 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |), "balance" |), M.get_name (| globals, "gas_refund_amount" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -1659,7 +1809,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let coinbase_balance_after_mining_fee := + let _ := M.assign_local (| + "coinbase_balance_after_mining_fee" , BinOp.add (| M.get_field (| M.call (| M.get_name (| globals, "get_account" |), @@ -1670,7 +1821,8 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |), "balance" |), M.get_name (| globals, "transaction_fee" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -1784,8 +1936,10 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := verified : `ethereum.base_types.Uint` The intrinsic cost of the transaction. " in - let data_cost := - Constant.int 0 in + let _ := M.assign_local (| + "data_cost" , + Constant.int 0 + |) in let _ := M.for_ (| M.get_name (| globals, "byte" |), @@ -1800,15 +1954,19 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let data_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "data_cost", M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let data_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "data_cost", M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -1832,13 +1990,17 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let create_cost := - M.get_name (| globals, "TX_CREATE_COST" |) in + let _ := M.assign_local (| + "create_cost" , + M.get_name (| globals, "TX_CREATE_COST" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let create_cost := - Constant.int 0 in + let _ := M.assign_local (| + "create_cost" , + Constant.int 0 + |) in M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1944,7 +2106,8 @@ Definition recover_sender : Value.t -> Value.t -> M := ], make_dict [] |) in - let public_key := + let _ := M.assign_local (| + "public_key" , M.call (| M.get_name (| globals, "secp256k1_recover" |), make_list [ @@ -1963,7 +2126,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Address" |), @@ -2104,11 +2268,13 @@ Definition check_gas_limit : Value.t -> Value.t -> M := check : `bool` True if gas limit constraints are satisfied, False otherwise. " in - let max_adjustment_delta := + let _ := M.assign_local (| + "max_adjustment_delta" , BinOp.floor_div (| M.get_name (| globals, "parent_gas_limit" |), M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -2210,7 +2376,8 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := difficulty : `ethereum.base_types.Uint` Computed difficulty for a block. " in - let offset := + let _ := M.assign_local (| + "offset" , BinOp.mult (| BinOp.floor_div (| M.call (| @@ -2245,8 +2412,10 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := ], make_dict [] |) - |) in - let difficulty := + |) + |) in + let _ := M.assign_local (| + "difficulty" , BinOp.add (| M.call (| M.get_name (| globals, "int" |), @@ -2256,8 +2425,10 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := make_dict [] |), M.get_name (| globals, "offset" |) - |) in - let num_bomb_periods := + |) + |) in + let _ := M.assign_local (| + "num_bomb_periods" , BinOp.sub (| BinOp.floor_div (| M.call (| @@ -2270,7 +2441,8 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := Constant.int 100000 |), Constant.int 2 - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -2280,15 +2452,14 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let difficulty := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "difficulty", BinOp.pow (| Constant.int 2, M.get_name (| globals, "num_bomb_periods" |) |) - BinOp.pow (| - Constant.int 2, - M.get_name (| globals, "num_bomb_periods" |) - |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/dao_fork/fork_types.v b/CoqOfPython/ethereum/dao_fork/fork_types.v index 644c8bd..7d58b79 100644 --- a/CoqOfPython/ethereum/dao_fork/fork_types.v +++ b/CoqOfPython/ethereum/dao_fork/fork_types.v @@ -17,17 +17,29 @@ Introduction Types re-used throughout the specification, which are specific to Ethereum. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes20"; "Bytes256"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes20 : + IsImported globals "ethereum.base_types" "Bytes20". +Axiom ethereum_base_types_imports_Bytes256 : + IsImported globals "ethereum.base_types" "Bytes256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) diff --git a/CoqOfPython/ethereum/dao_fork/state.v b/CoqOfPython/ethereum/dao_fork/state.v index 0da631e..c526dbf 100644 --- a/CoqOfPython/ethereum/dao_fork/state.v +++ b/CoqOfPython/ethereum/dao_fork/state.v @@ -22,23 +22,55 @@ There is a distinction between an account that does not exist and `EMPTY_ACCOUNT`. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass"; "field" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict"; "List"; "Optional"; "Tuple" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "modify" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_dao_fork_fork_types_imports : - AreImported globals "ethereum.dao_fork.fork_types" [ "EMPTY_ACCOUNT"; "Account"; "Address"; "Root" ]. - -Axiom ethereum_dao_fork_trie_imports : - AreImported globals "ethereum.dao_fork.trie" [ "EMPTY_TRIE_ROOT"; "Trie"; "copy_trie"; "root"; "trie_get"; "trie_set" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". +Axiom dataclasses_imports_field : + IsImported globals "dataclasses" "field". + +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_modify : + IsImported globals "ethereum.base_types" "modify". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_dao_fork_fork_types_imports_EMPTY_ACCOUNT : + IsImported globals "ethereum.dao_fork.fork_types" "EMPTY_ACCOUNT". +Axiom ethereum_dao_fork_fork_types_imports_Account : + IsImported globals "ethereum.dao_fork.fork_types" "Account". +Axiom ethereum_dao_fork_fork_types_imports_Address : + IsImported globals "ethereum.dao_fork.fork_types" "Address". +Axiom ethereum_dao_fork_fork_types_imports_Root : + IsImported globals "ethereum.dao_fork.fork_types" "Root". + +Axiom ethereum_dao_fork_trie_imports_EMPTY_TRIE_ROOT : + IsImported globals "ethereum.dao_fork.trie" "EMPTY_TRIE_ROOT". +Axiom ethereum_dao_fork_trie_imports_Trie : + IsImported globals "ethereum.dao_fork.trie" "Trie". +Axiom ethereum_dao_fork_trie_imports_copy_trie : + IsImported globals "ethereum.dao_fork.trie" "copy_trie". +Axiom ethereum_dao_fork_trie_imports_root : + IsImported globals "ethereum.dao_fork.trie" "root". +Axiom ethereum_dao_fork_trie_imports_trie_get : + IsImported globals "ethereum.dao_fork.trie" "trie_get". +Axiom ethereum_dao_fork_trie_imports_trie_set : + IsImported globals "ethereum.dao_fork.trie" "trie_set". Definition State : Value.t := builtins.make_klass @@ -153,7 +185,8 @@ Definition get_account : Value.t -> Value.t -> M := account : `Account` Account at address. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account_optional" |), make_list [ @@ -161,7 +194,8 @@ Definition get_account : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -207,7 +241,8 @@ Definition get_account_optional : Value.t -> Value.t -> M := account : `Account` Account at address. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "trie_get" |), make_list [ @@ -215,7 +250,8 @@ Definition get_account_optional : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "account" |) |) in @@ -338,14 +374,16 @@ Definition get_storage : Value.t -> Value.t -> M := value : `U256` Value at the key. " in - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -369,7 +407,8 @@ Definition get_storage : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "trie_get" |), make_list [ @@ -377,7 +416,8 @@ Definition get_storage : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -420,14 +460,16 @@ Definition set_storage : Value.t -> Value.t -> M := |), Constant.None_ |) |) in - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -437,12 +479,14 @@ Definition set_storage : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_name (| globals, "Trie" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), @@ -469,7 +513,7 @@ Definition set_storage : Value.t -> Value.t -> M := M.if_then_else (| Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), - {} + Constant.str "(* At expr: unsupported node type: Dict *)" |), (* then *) ltac:(M.monadic ( @@ -615,7 +659,8 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := True if if an account has non zero nonce or non empty code, False otherwise. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -623,7 +668,8 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| BoolOp.or (| Compare.not_eq (| diff --git a/CoqOfPython/ethereum/dao_fork/transactions.v b/CoqOfPython/ethereum/dao_fork/transactions.v index 3b7cac3..c515aad 100644 --- a/CoqOfPython/ethereum/dao_fork/transactions.v +++ b/CoqOfPython/ethereum/dao_fork/transactions.v @@ -9,17 +9,25 @@ submitted to be executed. If Ethereum is viewed as a state machine, transactions are the events that move between states. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Union" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_dao_fork_fork_types_imports : - AreImported globals "ethereum.dao_fork.fork_types" [ "Address" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_Union : + IsImported globals "typing" "Union". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_dao_fork_fork_types_imports_Address : + IsImported globals "ethereum.dao_fork.fork_types" "Address". Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( Constant.int 21000 diff --git a/CoqOfPython/ethereum/dao_fork/trie.v b/CoqOfPython/ethereum/dao_fork/trie.v index f009130..77ab51e 100644 --- a/CoqOfPython/ethereum/dao_fork/trie.v +++ b/CoqOfPython/ethereum/dao_fork/trie.v @@ -20,38 +20,72 @@ The state trie is the structure responsible for storing (* At top_level_stmt: unsupported node type: Import *) -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass"; "field" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict"; "Generic"; "List"; "Mapping"; "MutableMapping"; "Optional"; "Sequence"; "TypeVar"; "Union"; "cast" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. - -Axiom ethereum_homestead_imports : - AreImported globals "ethereum.homestead" [ "trie" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_utils_hexadecimal_imports : - AreImported globals "ethereum.utils.hexadecimal" [ "hex_to_bytes" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_dao_fork_blocks_imports : - AreImported globals "ethereum.dao_fork.blocks" [ "Receipt" ]. - -Axiom ethereum_dao_fork_fork_types_imports : - AreImported globals "ethereum.dao_fork.fork_types" [ "Account"; "Address"; "Root"; "encode_account" ]. - -Axiom ethereum_dao_fork_transactions_imports : - AreImported globals "ethereum.dao_fork.transactions" [ "Transaction" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". +Axiom dataclasses_imports_field : + IsImported globals "dataclasses" "field". + +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". +Axiom typing_imports_Generic : + IsImported globals "typing" "Generic". +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Mapping : + IsImported globals "typing" "Mapping". +Axiom typing_imports_MutableMapping : + IsImported globals "typing" "MutableMapping". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Sequence : + IsImported globals "typing" "Sequence". +Axiom typing_imports_TypeVar : + IsImported globals "typing" "TypeVar". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". +Axiom typing_imports_cast : + IsImported globals "typing" "cast". + +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". + +Axiom ethereum_homestead_imports_trie : + IsImported globals "ethereum.homestead" "trie". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_utils_hexadecimal_imports_hex_to_bytes : + IsImported globals "ethereum.utils.hexadecimal" "hex_to_bytes". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_dao_fork_blocks_imports_Receipt : + IsImported globals "ethereum.dao_fork.blocks" "Receipt". + +Axiom ethereum_dao_fork_fork_types_imports_Account : + IsImported globals "ethereum.dao_fork.fork_types" "Account". +Axiom ethereum_dao_fork_fork_types_imports_Address : + IsImported globals "ethereum.dao_fork.fork_types" "Address". +Axiom ethereum_dao_fork_fork_types_imports_Root : + IsImported globals "ethereum.dao_fork.fork_types" "Root". +Axiom ethereum_dao_fork_fork_types_imports_encode_account : + IsImported globals "ethereum.dao_fork.fork_types" "encode_account". + +Axiom ethereum_dao_fork_transactions_imports_Transaction : + IsImported globals "ethereum.dao_fork.transactions" "Transaction". Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -161,7 +195,7 @@ Definition encode_internal_node : Value.t -> Value.t -> M := when serialized. This function also accepts `None`, representing the absence of a node, - which is encoded to `b""""""`. + which is encoded to `b""""`. Parameters ---------- @@ -183,8 +217,10 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := - Constant.bytes "" in + let _ := M.assign_local (| + "unencoded" , + Constant.bytes "" + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -201,7 +237,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := + let _ := M.assign_local (| + "unencoded" , make_tuple [ M.call (| M.get_name (| globals, "nibble_list_to_compact" |), make_list [ @@ -209,7 +246,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := Constant.bool true ], make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in + |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -226,7 +264,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := + let _ := M.assign_local (| + "unencoded" , make_tuple [ M.call (| M.get_name (| globals, "nibble_list_to_compact" |), make_list [ @@ -234,7 +273,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := Constant.bool false ], make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in + |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -251,13 +291,15 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := + let _ := M.assign_local (| + "unencoded" , BinOp.add (| M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), make_list [ M.get_field (| M.get_name (| globals, "node" |), "value" |) ] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -276,14 +318,16 @@ Definition encode_internal_node : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - let encoded := + let _ := M.assign_local (| + "encoded" , M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), make_list [ M.get_name (| globals, "unencoded" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -675,12 +719,14 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := compressed : `bytearray` Compact byte array. " in - let compact := + let _ := M.assign_local (| + "compact" , M.call (| M.get_name (| globals, "bytearray" |), make_list [], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -860,7 +906,8 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := nibble_list : `Bytes` The `Bytes` in nibble-list format. " in - let nibble_list := + let _ := M.assign_local (| + "nibble_list" , M.call (| M.get_name (| globals, "bytearray" |), make_list [ @@ -876,7 +923,8 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ], @@ -984,15 +1032,18 @@ Definition _prepare_trie : Value.t -> Value.t -> M := M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "Address" |), make_list [ M.get_name (| globals, "preimage" |) ], make_dict [] - |) in - let encoded_value := + |) + |) in + let _ := M.assign_local (| + "encoded_value" , M.call (| M.get_name (| globals, "encode_node" |), make_list [ @@ -1006,18 +1057,21 @@ Definition _prepare_trie : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let encoded_value := + let _ := M.assign_local (| + "encoded_value" , M.call (| M.get_name (| globals, "encode_node" |), make_list [ M.get_name (| globals, "value" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -1038,19 +1092,23 @@ Definition _prepare_trie : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "trie" |), "secured" |), (* then *) ltac:(M.monadic ( - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "preimage" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let key := - M.get_name (| globals, "preimage" |) in + let _ := M.assign_local (| + "key" , + M.get_name (| globals, "preimage" |) + |) in M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -1097,7 +1155,8 @@ Definition root : Value.t -> Value.t -> M := root : `.fork_types.Root` MPT root of the underlying key-value pairs. " in - let obj := + let _ := M.assign_local (| + "obj" , M.call (| M.get_name (| globals, "_prepare_trie" |), make_list [ @@ -1105,8 +1164,10 @@ Definition root : Value.t -> Value.t -> M := M.get_name (| globals, "get_storage_root" |) ], make_dict [] - |) in - let root_node := + |) + |) in + let _ := M.assign_local (| + "root_node" , M.call (| M.get_name (| globals, "encode_internal_node" |), make_list [ @@ -1126,7 +1187,8 @@ Definition root : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1231,7 +1293,8 @@ Definition patricialize : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let arbitrary_key := + let _ := M.assign_local (| + "arbitrary_key" , M.call (| M.get_name (| globals, "next" |), make_list [ @@ -1244,7 +1307,8 @@ Definition patricialize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1260,7 +1324,8 @@ Definition patricialize : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let leaf := + let _ := M.assign_local (| + "leaf" , M.call (| M.get_name (| globals, "LeafNode" |), make_list [ @@ -1276,7 +1341,8 @@ Definition patricialize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "leaf" |) |) in @@ -1285,27 +1351,32 @@ Definition patricialize : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let substring := + let _ := M.assign_local (| + "substring" , M.slice (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |), Constant.None_, Constant.None_ - |) in - let prefix_length := + |) + |) in + let _ := M.assign_local (| + "prefix_length" , M.call (| M.get_name (| globals, "len" |), make_list [ M.get_name (| globals, "substring" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "key" |), M.get_name (| globals, "obj" |), ltac:(M.monadic ( - let prefix_length := + let _ := M.assign_local (| + "prefix_length" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -1325,7 +1396,8 @@ Definition patricialize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1356,7 +1428,8 @@ Definition patricialize : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let prefix := + let _ := M.assign_local (| + "prefix" , M.slice (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |), @@ -1365,7 +1438,8 @@ Definition patricialize : Value.t -> Value.t -> M := M.get_name (| globals, "prefix_length" |) |), Constant.None_ - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ExtensionNode" |), @@ -1412,7 +1486,7 @@ Definition patricialize : Value.t -> Value.t -> M := let _ := M.call (| M.get_field (| M.get_name (| globals, "branches" |), "append" |), make_list [ - {} + Constant.str "(* At expr: unsupported node type: Dict *)" ], make_dict [] |) in @@ -1422,8 +1496,10 @@ Definition patricialize : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let value := - Constant.bytes "" in + let _ := M.assign_local (| + "value" , + Constant.bytes "" + |) in let _ := M.for_ (| M.get_name (| globals, "key" |), @@ -1466,11 +1542,13 @@ Definition patricialize : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let value := + let _ := M.assign_local (| + "value" , M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/dao_fork/utils/address.v b/CoqOfPython/ethereum/dao_fork/utils/address.v index 93430a5..43700aa 100644 --- a/CoqOfPython/ethereum/dao_fork/utils/address.v +++ b/CoqOfPython/ethereum/dao_fork/utils/address.v @@ -17,23 +17,25 @@ Introduction Address specific functions used in this Dao Fork version of specification. ". -Axiom typing_imports : - AreImported globals "typing" [ "Union" ]. +Axiom typing_imports_Union : + IsImported globals "typing" "Union". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_left_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "left_pad_zero_bytes". -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". -Axiom ethereum_dao_fork_fork_types_imports : - AreImported globals "ethereum.dao_fork.fork_types" [ "Address" ]. +Axiom ethereum_dao_fork_fork_types_imports_Address : + IsImported globals "ethereum.dao_fork.fork_types" "Address". Definition to_address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -90,7 +92,8 @@ Definition compute_contract_address : Value.t -> Value.t -> M := address: `ethereum.dao_fork.fork_types.Address` The computed address of the new account. " in - let computed_address := + let _ := M.assign_local (| + "computed_address" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -106,15 +109,19 @@ Definition compute_contract_address : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let canonical_address := + |) + |) in + let _ := M.assign_local (| + "canonical_address" , M.slice (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |), Constant.None_, Constant.None_ - |) in - let padded_address := + |) + |) in + let _ := M.assign_local (| + "padded_address" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -122,7 +129,8 @@ Definition compute_contract_address : Value.t -> Value.t -> M := Constant.int 20 ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Address" |), diff --git a/CoqOfPython/ethereum/dao_fork/utils/hexadecimal.v b/CoqOfPython/ethereum/dao_fork/utils/hexadecimal.v index 3e89490..3f19f3d 100644 --- a/CoqOfPython/ethereum/dao_fork/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/dao_fork/utils/hexadecimal.v @@ -18,11 +18,15 @@ Hexadecimal utility functions used in this specification, specific to Dao Fork types. ". -Axiom ethereum_utils_hexadecimal_imports : - AreImported globals "ethereum.utils.hexadecimal" [ "remove_hex_prefix" ]. - -Axiom ethereum_dao_fork_fork_types_imports : - AreImported globals "ethereum.dao_fork.fork_types" [ "Address"; "Bloom"; "Root" ]. +Axiom ethereum_utils_hexadecimal_imports_remove_hex_prefix : + IsImported globals "ethereum.utils.hexadecimal" "remove_hex_prefix". + +Axiom ethereum_dao_fork_fork_types_imports_Address : + IsImported globals "ethereum.dao_fork.fork_types" "Address". +Axiom ethereum_dao_fork_fork_types_imports_Bloom : + IsImported globals "ethereum.dao_fork.fork_types" "Bloom". +Axiom ethereum_dao_fork_fork_types_imports_Root : + IsImported globals "ethereum.dao_fork.fork_types" "Root". Definition hex_to_root : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/dao_fork/utils/message.v b/CoqOfPython/ethereum/dao_fork/utils/message.v index 0e2da42..9520a0a 100644 --- a/CoqOfPython/ethereum/dao_fork/utils/message.v +++ b/CoqOfPython/ethereum/dao_fork/utils/message.v @@ -17,23 +17,33 @@ Introduction Message specific functions used in this Dao Fork version of specification. ". -Axiom typing_imports : - AreImported globals "typing" [ "Optional"; "Union" ]. +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_dao_fork_fork_types_imports : - AreImported globals "ethereum.dao_fork.fork_types" [ "Address" ]. +Axiom ethereum_dao_fork_fork_types_imports_Address : + IsImported globals "ethereum.dao_fork.fork_types" "Address". -Axiom ethereum_dao_fork_state_imports : - AreImported globals "ethereum.dao_fork.state" [ "get_account" ]. +Axiom ethereum_dao_fork_state_imports_get_account : + IsImported globals "ethereum.dao_fork.state" "get_account". -Axiom ethereum_dao_fork_vm_imports : - AreImported globals "ethereum.dao_fork.vm" [ "Environment"; "Message" ]. +Axiom ethereum_dao_fork_vm_imports_Environment : + IsImported globals "ethereum.dao_fork.vm" "Environment". +Axiom ethereum_dao_fork_vm_imports_Message : + IsImported globals "ethereum.dao_fork.vm" "Message". -Axiom ethereum_dao_fork_utils_address_imports : - AreImported globals "ethereum.dao_fork.utils.address" [ "compute_contract_address" ]. +Axiom ethereum_dao_fork_utils_address_imports_compute_contract_address : + IsImported globals "ethereum.dao_fork.utils.address" "compute_contract_address". Definition prepare_message : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -80,7 +90,8 @@ Definition prepare_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let current_target := + let _ := M.assign_local (| + "current_target" , M.call (| M.get_name (| globals, "compute_contract_address" |), make_list [ @@ -104,17 +115,22 @@ Definition prepare_message : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let msg_data := + |) + |) in + let _ := M.assign_local (| + "msg_data" , M.call (| M.get_name (| globals, "Bytes" |), make_list [ Constant.bytes "" ], make_dict [] - |) in - let code := - M.get_name (| globals, "data" |) in + |) + |) in + let _ := M.assign_local (| + "code" , + M.get_name (| globals, "data" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -131,11 +147,16 @@ Definition prepare_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let current_target := - M.get_name (| globals, "target" |) in - let msg_data := - M.get_name (| globals, "data" |) in - let code := + let _ := M.assign_local (| + "current_target" , + M.get_name (| globals, "target" |) + |) in + let _ := M.assign_local (| + "msg_data" , + M.get_name (| globals, "data" |) + |) in + let _ := M.assign_local (| + "code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -143,7 +164,8 @@ Definition prepare_message : Value.t -> Value.t -> M := M.get_name (| globals, "target" |) ], make_dict [] - |), "code" |) in + |), "code" |) + |) in let _ := (* if *) M.if_then_else (| @@ -153,8 +175,10 @@ Definition prepare_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let code_address := - M.get_name (| globals, "target" |) in + let _ := M.assign_local (| + "code_address" , + M.get_name (| globals, "target" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/dao_fork/vm/__init__.v b/CoqOfPython/ethereum/dao_fork/vm/__init__.v index 03365f0..7a3276a 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/__init__.v +++ b/CoqOfPython/ethereum/dao_fork/vm/__init__.v @@ -18,26 +18,40 @@ The abstract computer which runs the code stored in an `.fork_types.Account`. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple"; "Union" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. - -Axiom ethereum_dao_fork_blocks_imports : - AreImported globals "ethereum.dao_fork.blocks" [ "Log" ]. - -Axiom ethereum_dao_fork_fork_types_imports : - AreImported globals "ethereum.dao_fork.fork_types" [ "Address" ]. - -Axiom ethereum_dao_fork_state_imports : - AreImported globals "ethereum.dao_fork.state" [ "State" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". + +Axiom ethereum_dao_fork_blocks_imports_Log : + IsImported globals "ethereum.dao_fork.blocks" "Log". + +Axiom ethereum_dao_fork_fork_types_imports_Address : + IsImported globals "ethereum.dao_fork.fork_types" "Address". + +Axiom ethereum_dao_fork_state_imports_State : + IsImported globals "ethereum.dao_fork.state" "State". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] diff --git a/CoqOfPython/ethereum/dao_fork/vm/exceptions.v b/CoqOfPython/ethereum/dao_fork/vm/exceptions.v index e9914f2..193cc22 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/exceptions.v +++ b/CoqOfPython/ethereum/dao_fork/vm/exceptions.v @@ -17,8 +17,8 @@ Introduction Exceptions which cause the EVM to halt exceptionally. ". -Axiom ethereum_exceptions_imports : - AreImported globals "ethereum.exceptions" [ "EthereumException" ]. +Axiom ethereum_exceptions_imports_EthereumException : + IsImported globals "ethereum.exceptions" "EthereumException". Definition ExceptionalHalt : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/dao_fork/vm/gas.v b/CoqOfPython/ethereum/dao_fork/vm/gas.v index e0761e3..7739073 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/gas.v +++ b/CoqOfPython/ethereum/dao_fork/vm/gas.v @@ -17,32 +17,40 @@ Introduction EVM gas constants and calculators. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Tuple" ]. +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_trace_imports : - AreImported globals "ethereum.trace" [ "GasAndRefund"; "evm_trace" ]. +Axiom ethereum_trace_imports_GasAndRefund : + IsImported globals "ethereum.trace" "GasAndRefund". +Axiom ethereum_trace_imports_evm_trace : + IsImported globals "ethereum.trace" "evm_trace". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_dao_fork_fork_types_imports : - AreImported globals "ethereum.dao_fork.fork_types" [ "Address" ]. +Axiom ethereum_dao_fork_fork_types_imports_Address : + IsImported globals "ethereum.dao_fork.fork_types" "Address". -Axiom ethereum_dao_fork_state_imports : - AreImported globals "ethereum.dao_fork.state" [ "State"; "account_exists" ]. +Axiom ethereum_dao_fork_state_imports_State : + IsImported globals "ethereum.dao_fork.state" "State". +Axiom ethereum_dao_fork_state_imports_account_exists : + IsImported globals "ethereum.dao_fork.state" "account_exists". -Axiom ethereum_dao_fork_vm_imports : - AreImported globals "ethereum.dao_fork.vm" [ "Evm" ]. +Axiom ethereum_dao_fork_vm_imports_Evm : + IsImported globals "ethereum.dao_fork.vm" "Evm". -Axiom ethereum_dao_fork_vm_exceptions_imports : - AreImported globals "ethereum.dao_fork.vm.exceptions" [ "OutOfGasError" ]. +Axiom ethereum_dao_fork_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.dao_fork.vm.exceptions" "OutOfGasError". Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -508,7 +516,8 @@ Definition calculate_memory_gas_cost : Value.t -> Value.t -> M := total_gas_cost : `ethereum.base_types.Uint` The gas cost for storing data in memory. " in - let size_in_words := + let _ := M.assign_local (| + "size_in_words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -518,25 +527,32 @@ Definition calculate_memory_gas_cost : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let linear_cost := + |) + |) in + let _ := M.assign_local (| + "linear_cost" , BinOp.mult (| M.get_name (| globals, "size_in_words" |), M.get_name (| globals, "GAS_MEMORY" |) - |) in - let quadratic_cost := + |) + |) in + let _ := M.assign_local (| + "quadratic_cost" , BinOp.floor_div (| BinOp.pow (| M.get_name (| globals, "size_in_words" |), Constant.int 2 |), Constant.int 512 - |) in - let total_gas_cost := + |) + |) in + let _ := M.assign_local (| + "total_gas_cost" , BinOp.add (| M.get_name (| globals, "linear_cost" |), M.get_name (| globals, "quadratic_cost" |) - |) in + |) + |) in (* At stmt: unsupported node type: Try *) M.pure Constant.None_)). @@ -558,23 +574,28 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := ------- extend_memory: `ExtendMemory` " in - let size_to_extend := + let _ := M.assign_local (| + "size_to_extend" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in - let to_be_paid := + |) + |) in + let _ := M.assign_local (| + "to_be_paid" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in - let current_size := + |) + |) in + let _ := M.assign_local (| + "current_size" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -587,7 +608,8 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ], @@ -608,15 +630,18 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let before_size := + let _ := M.assign_local (| + "before_size" , M.call (| M.get_name (| globals, "ceil32" |), make_list [ M.get_name (| globals, "current_size" |) ], make_dict [] - |) in - let after_size := + |) + |) in + let _ := M.assign_local (| + "after_size" , M.call (| M.get_name (| globals, "ceil32" |), make_list [ @@ -638,7 +663,8 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -654,42 +680,46 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let size_to_extend := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "size_to_extend", BinOp.sub (| M.get_name (| globals, "after_size" |), M.get_name (| globals, "before_size" |) |) - BinOp.sub (| - M.get_name (| globals, "after_size" |), - M.get_name (| globals, "before_size" |) - |) in - let already_paid := + |) in + let _ := M.assign_local (| + "already_paid" , M.call (| M.get_name (| globals, "calculate_memory_gas_cost" |), make_list [ M.get_name (| globals, "before_size" |) ], make_dict [] - |) in - let total_cost := + |) + |) in + let _ := M.assign_local (| + "total_cost" , M.call (| M.get_name (| globals, "calculate_memory_gas_cost" |), make_list [ M.get_name (| globals, "after_size" |) ], make_dict [] - |) in - let to_be_paid := BinOp.add + |) + |) in + let _ := M.assign_op_local (| + BinOp.add, + "to_be_paid", BinOp.sub (| M.get_name (| globals, "total_cost" |), M.get_name (| globals, "already_paid" |) |) - BinOp.sub (| - M.get_name (| globals, "total_cost" |), - M.get_name (| globals, "already_paid" |) - |) in - let current_size := - M.get_name (| globals, "after_size" |) in + |) in + let _ := M.assign_local (| + "current_size" , + M.get_name (| globals, "after_size" |) + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -729,7 +759,8 @@ Definition calculate_message_call_gas : Value.t -> Value.t -> M := ------- message_call_gas: `MessageCallGas` " in - let create_gas_cost := + let _ := M.assign_local (| + "create_gas_cost" , (* if *) M.if_then_else (| M.call (| @@ -752,8 +783,10 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "GAS_NEW_ACCOUNT" |) - )) |) in - let transfer_gas_cost := + )) |) + |) in + let _ := M.assign_local (| + "transfer_gas_cost" , (* if *) M.if_then_else (| Compare.eq (| @@ -772,8 +805,10 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "GAS_CALL_VALUE" |) - )) |) in - let cost := + )) |) + |) in + let _ := M.assign_local (| + "cost" , BinOp.add (| BinOp.add (| BinOp.add (| @@ -783,8 +818,10 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_name (| globals, "create_gas_cost" |) |), M.get_name (| globals, "transfer_gas_cost" |) - |) in - let stipend := + |) + |) in + let _ := M.assign_local (| + "stipend" , (* if *) M.if_then_else (| Compare.eq (| @@ -800,7 +837,8 @@ BinOp.add (| M.get_name (| globals, "GAS_CALL_STIPEND" |), M.get_name (| globals, "gas" |) |) - )) |) in + )) |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "MessageCallGas" |), diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/__init__.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/__init__.v index c96ddaa..ca3f554 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/__init__.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/__init__.v @@ -20,44 +20,46 @@ implementations. (* At top_level_stmt: unsupported node type: Import *) -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict" ]. +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". -Axiom ethereum_dao_fork_vm_instructions_imports : - AreImported globals "ethereum.dao_fork.vm.instructions" [ "arithmetic" ]. +Axiom ethereum_dao_fork_vm_instructions_imports_arithmetic : + IsImported globals "ethereum.dao_fork.vm.instructions" "arithmetic". -Axiom ethereum_dao_fork_vm_instructions_imports : - AreImported globals "ethereum.dao_fork.vm.instructions" [ "bitwise" ]. +Axiom ethereum_dao_fork_vm_instructions_imports_bitwise : + IsImported globals "ethereum.dao_fork.vm.instructions" "bitwise". -Axiom ethereum_dao_fork_vm_instructions_imports : - AreImported globals "ethereum.dao_fork.vm.instructions" [ "block" ]. +Axiom ethereum_dao_fork_vm_instructions_imports_block : + IsImported globals "ethereum.dao_fork.vm.instructions" "block". -Axiom ethereum_dao_fork_vm_instructions_imports : - AreImported globals "ethereum.dao_fork.vm.instructions" [ "comparison" ]. +Axiom ethereum_dao_fork_vm_instructions_imports_comparison : + IsImported globals "ethereum.dao_fork.vm.instructions" "comparison". -Axiom ethereum_dao_fork_vm_instructions_imports : - AreImported globals "ethereum.dao_fork.vm.instructions" [ "control_flow" ]. +Axiom ethereum_dao_fork_vm_instructions_imports_control_flow : + IsImported globals "ethereum.dao_fork.vm.instructions" "control_flow". -Axiom ethereum_dao_fork_vm_instructions_imports : - AreImported globals "ethereum.dao_fork.vm.instructions" [ "environment" ]. +Axiom ethereum_dao_fork_vm_instructions_imports_environment : + IsImported globals "ethereum.dao_fork.vm.instructions" "environment". -Axiom ethereum_dao_fork_vm_instructions_imports : - AreImported globals "ethereum.dao_fork.vm.instructions" [ "keccak" ]. +Axiom ethereum_dao_fork_vm_instructions_imports_keccak : + IsImported globals "ethereum.dao_fork.vm.instructions" "keccak". -Axiom ethereum_dao_fork_vm_instructions_imports : - AreImported globals "ethereum.dao_fork.vm.instructions" [ "log" ]. +Axiom ethereum_dao_fork_vm_instructions_imports_log : + IsImported globals "ethereum.dao_fork.vm.instructions" "log". -Axiom ethereum_dao_fork_vm_instructions_imports : - AreImported globals "ethereum.dao_fork.vm.instructions" [ "memory" ]. +Axiom ethereum_dao_fork_vm_instructions_imports_memory : + IsImported globals "ethereum.dao_fork.vm.instructions" "memory". -Axiom ethereum_dao_fork_vm_instructions_imports : - AreImported globals "ethereum.dao_fork.vm.instructions" [ "stack" ]. +Axiom ethereum_dao_fork_vm_instructions_imports_stack : + IsImported globals "ethereum.dao_fork.vm.instructions" "stack". -Axiom ethereum_dao_fork_vm_instructions_imports : - AreImported globals "ethereum.dao_fork.vm.instructions" [ "storage" ]. +Axiom ethereum_dao_fork_vm_instructions_imports_storage : + IsImported globals "ethereum.dao_fork.vm.instructions" "storage". -Axiom ethereum_dao_fork_vm_instructions_imports : - AreImported globals "ethereum.dao_fork.vm.instructions" [ "system" ]. +Axiom ethereum_dao_fork_vm_instructions_imports_system : + IsImported globals "ethereum.dao_fork.vm.instructions" "system". Definition Ops : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/arithmetic.v index 53c6c89..c64126f 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/arithmetic.v @@ -17,20 +17,38 @@ Introduction Implementations of the EVM Arithmetic instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U255_CEIL_VALUE"; "U256"; "U256_CEIL_VALUE"; "Uint" ]. +Axiom ethereum_base_types_imports_U255_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U255_CEIL_VALUE". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_U256_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U256_CEIL_VALUE". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "get_sign" ]. +Axiom ethereum_utils_numeric_imports_get_sign : + IsImported globals "ethereum.utils.numeric" "get_sign". -Axiom ethereum_dao_fork_vm_imports : - AreImported globals "ethereum.dao_fork.vm" [ "Evm" ]. +Axiom ethereum_dao_fork_vm_imports_Evm : + IsImported globals "ethereum.dao_fork.vm" "Evm". -Axiom ethereum_dao_fork_vm_gas_imports : - AreImported globals "ethereum.dao_fork.vm.gas" [ "GAS_EXPONENTIATION"; "GAS_EXPONENTIATION_PER_BYTE"; "GAS_LOW"; "GAS_MID"; "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_dao_fork_vm_gas_imports_GAS_EXPONENTIATION : + IsImported globals "ethereum.dao_fork.vm.gas" "GAS_EXPONENTIATION". +Axiom ethereum_dao_fork_vm_gas_imports_GAS_EXPONENTIATION_PER_BYTE : + IsImported globals "ethereum.dao_fork.vm.gas" "GAS_EXPONENTIATION_PER_BYTE". +Axiom ethereum_dao_fork_vm_gas_imports_GAS_LOW : + IsImported globals "ethereum.dao_fork.vm.gas" "GAS_LOW". +Axiom ethereum_dao_fork_vm_gas_imports_GAS_MID : + IsImported globals "ethereum.dao_fork.vm.gas" "GAS_MID". +Axiom ethereum_dao_fork_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.dao_fork.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_dao_fork_vm_gas_imports_charge_gas : + IsImported globals "ethereum.dao_fork.vm.gas" "charge_gas". -Axiom ethereum_dao_fork_vm_stack_imports : - AreImported globals "ethereum.dao_fork.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_dao_fork_vm_stack_imports_pop : + IsImported globals "ethereum.dao_fork.vm.stack" "pop". +Axiom ethereum_dao_fork_vm_stack_imports_push : + IsImported globals "ethereum.dao_fork.vm.stack" "push". Definition add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,22 +63,26 @@ Definition add : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -69,14 +91,16 @@ Definition add : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "x" |), "wrapping_add" |), make_list [ M.get_name (| globals, "y" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -105,22 +129,26 @@ Definition sub : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -129,14 +157,16 @@ Definition sub : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "x" |), "wrapping_sub" |), make_list [ M.get_name (| globals, "y" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -165,22 +195,26 @@ Definition mul : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -189,14 +223,16 @@ Definition mul : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "x" |), "wrapping_mul" |), make_list [ M.get_name (| globals, "y" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -225,22 +261,26 @@ Definition div : Value.t -> Value.t -> M := The current EVM frame. " in - let dividend := + let _ := M.assign_local (| + "dividend" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let divisor := + |) + |) in + let _ := M.assign_local (| + "divisor" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -258,22 +298,26 @@ Definition div : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let quotient := + let _ := M.assign_local (| + "quotient" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let quotient := + let _ := M.assign_local (| + "quotient" , BinOp.floor_div (| M.get_name (| globals, "dividend" |), M.get_name (| globals, "divisor" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -304,7 +348,8 @@ Definition sdiv : Value.t -> Value.t -> M := The current EVM frame. " in - let dividend := + let _ := M.assign_local (| + "dividend" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -315,8 +360,10 @@ Definition sdiv : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let divisor := + |) + |) in + let _ := M.assign_local (| + "divisor" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -327,7 +374,8 @@ Definition sdiv : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -345,8 +393,10 @@ Definition sdiv : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let quotient := - Constant.int 0 in + let _ := M.assign_local (| + "quotient" , + Constant.int 0 + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -367,12 +417,15 @@ Definition sdiv : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let quotient := - UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in + let _ := M.assign_local (| + "quotient" , + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let sign := + let _ := M.assign_local (| + "sign" , M.call (| M.get_name (| globals, "get_sign" |), make_list [ @@ -382,8 +435,10 @@ Definition sdiv : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let quotient := + |) + |) in + let _ := M.assign_local (| + "quotient" , BinOp.mult (| M.get_name (| globals, "sign" |), BinOp.floor_div (| @@ -402,7 +457,8 @@ Definition sdiv : Value.t -> Value.t -> M := make_dict [] |) |) - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -428,7 +484,7 @@ Definition sdiv : Value.t -> Value.t -> M := |) in M.pure Constant.None_)). -Definition mod : Value.t -> Value.t -> M := +Definition mod_ : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in let _ := Constant.str " @@ -441,22 +497,26 @@ Definition mod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -474,22 +534,26 @@ Definition mod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let remainder := + let _ := M.assign_local (| + "remainder" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let remainder := + let _ := M.assign_local (| + "remainder" , BinOp.mod_ (| M.get_name (| globals, "x" |), M.get_name (| globals, "y" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -520,7 +584,8 @@ Definition smod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -531,8 +596,10 @@ Definition smod : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -543,7 +610,8 @@ Definition smod : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -561,12 +629,15 @@ Definition smod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let remainder := - Constant.int 0 in + let _ := M.assign_local (| + "remainder" , + Constant.int 0 + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let remainder := + let _ := M.assign_local (| + "remainder" , BinOp.mult (| M.call (| M.get_name (| globals, "get_sign" |), @@ -591,7 +662,8 @@ Definition smod : Value.t -> Value.t -> M := make_dict [] |) |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -628,7 +700,8 @@ Definition addmod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -641,8 +714,10 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -655,8 +730,10 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let z := + |) + |) in + let _ := M.assign_local (| + "z" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -669,7 +746,8 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -687,18 +765,21 @@ Definition addmod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -711,7 +792,8 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -742,7 +824,8 @@ Definition mulmod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -755,8 +838,10 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -769,8 +854,10 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let z := + |) + |) in + let _ := M.assign_local (| + "z" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -783,7 +870,8 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -801,18 +889,21 @@ Definition mulmod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -825,7 +916,8 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -856,7 +948,8 @@ Definition exp : Value.t -> Value.t -> M := The current EVM frame. " in - let base := + let _ := M.assign_local (| + "base" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -869,8 +962,10 @@ Definition exp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exponent := + |) + |) in + let _ := M.assign_local (| + "exponent" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -883,21 +978,26 @@ Definition exp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exponent_bits := + |) + |) in + let _ := M.assign_local (| + "exponent_bits" , M.call (| M.get_field (| M.get_name (| globals, "exponent" |), "bit_length" |), make_list [], make_dict [] - |) in - let exponent_bytes := + |) + |) in + let _ := M.assign_local (| + "exponent_bytes" , BinOp.floor_div (| BinOp.add (| M.get_name (| globals, "exponent_bits" |), Constant.int 7 |), Constant.int 8 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -912,7 +1012,8 @@ Definition exp : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -927,7 +1028,8 @@ Definition exp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -956,22 +1058,26 @@ Definition signextend : Value.t -> Value.t -> M := The current EVM frame. " in - let byte_num := + let _ := M.assign_local (| + "byte_num" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -989,12 +1095,15 @@ Definition signextend : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := - M.get_name (| globals, "value" |) in + let _ := M.assign_local (| + "result" , + M.get_name (| globals, "value" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let value_bytes := + let _ := M.assign_local (| + "value_bytes" , M.call (| M.get_name (| globals, "bytes" |), make_list [ @@ -1005,8 +1114,10 @@ Definition signextend : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let value_bytes := + |) + |) in + let _ := M.assign_local (| + "value_bytes" , M.slice (| M.get_name (| globals, "value_bytes" |), BinOp.sub (| @@ -1021,15 +1132,18 @@ Definition signextend : Value.t -> Value.t -> M := |), Constant.None_, Constant.None_ - |) in - let sign_bit := + |) + |) in + let _ := M.assign_local (| + "sign_bit" , BinOp.r_shift (| M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), Constant.int 7 - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1039,26 +1153,31 @@ Definition signextend : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "value_bytes" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let num_bytes_prepend := + let _ := M.assign_local (| + "num_bytes_prepend" , BinOp.sub (| Constant.int 32, BinOp.add (| M.get_name (| globals, "byte_num" |), Constant.int 1 |) - |) in - let result := + |) + |) in + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -1079,7 +1198,8 @@ Definition signextend : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/bitwise.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/bitwise.v index f552ec9..fccfa0d 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/bitwise.v @@ -17,17 +17,21 @@ Introduction Implementations of the EVM bitwise instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_dao_fork_vm_imports : - AreImported globals "ethereum.dao_fork.vm" [ "Evm" ]. +Axiom ethereum_dao_fork_vm_imports_Evm : + IsImported globals "ethereum.dao_fork.vm" "Evm". -Axiom ethereum_dao_fork_vm_gas_imports : - AreImported globals "ethereum.dao_fork.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_dao_fork_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.dao_fork.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_dao_fork_vm_gas_imports_charge_gas : + IsImported globals "ethereum.dao_fork.vm.gas" "charge_gas". -Axiom ethereum_dao_fork_vm_stack_imports : - AreImported globals "ethereum.dao_fork.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_dao_fork_vm_stack_imports_pop : + IsImported globals "ethereum.dao_fork.vm.stack" "pop". +Axiom ethereum_dao_fork_vm_stack_imports_push : + IsImported globals "ethereum.dao_fork.vm.stack" "push". Definition bitwise_and : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,22 +46,26 @@ Definition bitwise_and : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -97,22 +105,26 @@ Definition bitwise_or : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -152,22 +164,26 @@ Definition bitwise_xor : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -207,14 +223,16 @@ Definition bitwise_not : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -252,22 +270,26 @@ Definition get_byte : Value.t -> Value.t -> M := The current EVM frame. " in - let byte_index := + let _ := M.assign_local (| + "byte_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let word := + |) + |) in + let _ := M.assign_local (| + "word" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -285,43 +307,53 @@ Definition get_byte : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let extra_bytes_to_right := + let _ := M.assign_local (| + "extra_bytes_to_right" , BinOp.sub (| Constant.int 31, M.get_name (| globals, "byte_index" |) - |) in - let word := + |) + |) in + let _ := M.assign_local (| + "word" , BinOp.r_shift (| M.get_name (| globals, "word" |), BinOp.mult (| M.get_name (| globals, "extra_bytes_to_right" |), Constant.int 8 |) - |) in - let word := + |) + |) in + let _ := M.assign_local (| + "word" , BinOp.bit_and (| M.get_name (| globals, "word" |), Constant.int 255 - |) in - let result := + |) + |) in + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ M.get_name (| globals, "word" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/block.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/block.v index 02269c3..5a65267 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/block.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/block.v @@ -17,17 +17,23 @@ Introduction Implementations of the EVM block instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_dao_fork_vm_imports : - AreImported globals "ethereum.dao_fork.vm" [ "Evm" ]. +Axiom ethereum_dao_fork_vm_imports_Evm : + IsImported globals "ethereum.dao_fork.vm" "Evm". -Axiom ethereum_dao_fork_vm_gas_imports : - AreImported globals "ethereum.dao_fork.vm.gas" [ "GAS_BASE"; "GAS_BLOCK_HASH"; "charge_gas" ]. +Axiom ethereum_dao_fork_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.dao_fork.vm.gas" "GAS_BASE". +Axiom ethereum_dao_fork_vm_gas_imports_GAS_BLOCK_HASH : + IsImported globals "ethereum.dao_fork.vm.gas" "GAS_BLOCK_HASH". +Axiom ethereum_dao_fork_vm_gas_imports_charge_gas : + IsImported globals "ethereum.dao_fork.vm.gas" "charge_gas". -Axiom ethereum_dao_fork_vm_stack_imports : - AreImported globals "ethereum.dao_fork.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_dao_fork_vm_stack_imports_pop : + IsImported globals "ethereum.dao_fork.vm.stack" "pop". +Axiom ethereum_dao_fork_vm_stack_imports_push : + IsImported globals "ethereum.dao_fork.vm.stack" "push". Definition block_hash : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,14 +48,16 @@ Definition block_hash : Value.t -> Value.t -> M := The current EVM frame. " in - let block_number := + let _ := M.assign_local (| + "block_number" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -78,19 +86,23 @@ Definition block_hash : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let hash := - Constant.bytes "00" in + let _ := M.assign_local (| + "hash" , + Constant.bytes "00" + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let hash := + let _ := M.assign_local (| + "hash" , M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), M.get_name (| globals, "block_number" |) |) |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/comparison.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/comparison.v index f55a03a..48940ed 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/comparison.v @@ -17,17 +17,21 @@ Introduction Implementations of the EVM Comparison instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_dao_fork_vm_imports : - AreImported globals "ethereum.dao_fork.vm" [ "Evm" ]. +Axiom ethereum_dao_fork_vm_imports_Evm : + IsImported globals "ethereum.dao_fork.vm" "Evm". -Axiom ethereum_dao_fork_vm_gas_imports : - AreImported globals "ethereum.dao_fork.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_dao_fork_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.dao_fork.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_dao_fork_vm_gas_imports_charge_gas : + IsImported globals "ethereum.dao_fork.vm.gas" "charge_gas". -Axiom ethereum_dao_fork_vm_stack_imports : - AreImported globals "ethereum.dao_fork.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_dao_fork_vm_stack_imports_pop : + IsImported globals "ethereum.dao_fork.vm.stack" "pop". +Axiom ethereum_dao_fork_vm_stack_imports_push : + IsImported globals "ethereum.dao_fork.vm.stack" "push". Definition less_than : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,22 +46,26 @@ Definition less_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -66,7 +74,8 @@ Definition less_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -76,7 +85,8 @@ Definition less_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -104,7 +114,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -115,8 +126,10 @@ Definition signed_less_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -127,7 +140,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -136,7 +150,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -146,7 +161,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -175,22 +191,26 @@ Definition greater_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -199,7 +219,8 @@ Definition greater_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -209,7 +230,8 @@ Definition greater_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -237,7 +259,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -248,8 +271,10 @@ Definition signed_greater_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -260,7 +285,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -269,7 +295,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -279,7 +306,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -308,22 +336,26 @@ Definition equal : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -332,7 +364,8 @@ Definition equal : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -342,7 +375,8 @@ Definition equal : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -371,14 +405,16 @@ Definition is_zero : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -387,7 +423,8 @@ Definition is_zero : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -397,7 +434,8 @@ Definition is_zero : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/control_flow.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/control_flow.v index 6abe333..2242d7f 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/control_flow.v @@ -17,20 +17,32 @@ Introduction Implementations of the EVM control flow instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_dao_fork_vm_gas_imports : - AreImported globals "ethereum.dao_fork.vm.gas" [ "GAS_BASE"; "GAS_HIGH"; "GAS_JUMPDEST"; "GAS_MID"; "charge_gas" ]. +Axiom ethereum_dao_fork_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.dao_fork.vm.gas" "GAS_BASE". +Axiom ethereum_dao_fork_vm_gas_imports_GAS_HIGH : + IsImported globals "ethereum.dao_fork.vm.gas" "GAS_HIGH". +Axiom ethereum_dao_fork_vm_gas_imports_GAS_JUMPDEST : + IsImported globals "ethereum.dao_fork.vm.gas" "GAS_JUMPDEST". +Axiom ethereum_dao_fork_vm_gas_imports_GAS_MID : + IsImported globals "ethereum.dao_fork.vm.gas" "GAS_MID". +Axiom ethereum_dao_fork_vm_gas_imports_charge_gas : + IsImported globals "ethereum.dao_fork.vm.gas" "charge_gas". -Axiom ethereum_dao_fork_vm_imports : - AreImported globals "ethereum.dao_fork.vm" [ "Evm" ]. +Axiom ethereum_dao_fork_vm_imports_Evm : + IsImported globals "ethereum.dao_fork.vm" "Evm". -Axiom ethereum_dao_fork_vm_exceptions_imports : - AreImported globals "ethereum.dao_fork.vm.exceptions" [ "InvalidJumpDestError" ]. +Axiom ethereum_dao_fork_vm_exceptions_imports_InvalidJumpDestError : + IsImported globals "ethereum.dao_fork.vm.exceptions" "InvalidJumpDestError". -Axiom ethereum_dao_fork_vm_stack_imports : - AreImported globals "ethereum.dao_fork.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_dao_fork_vm_stack_imports_pop : + IsImported globals "ethereum.dao_fork.vm.stack" "pop". +Axiom ethereum_dao_fork_vm_stack_imports_push : + IsImported globals "ethereum.dao_fork.vm.stack" "push". Definition stop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -69,7 +81,8 @@ Definition jump : Value.t -> Value.t -> M := The current EVM frame. " in - let jump_dest := + let _ := M.assign_local (| + "jump_dest" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -82,7 +95,8 @@ Definition jump : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -132,7 +146,8 @@ Definition jumpi : Value.t -> Value.t -> M := The current EVM frame. " in - let jump_dest := + let _ := M.assign_local (| + "jump_dest" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -145,15 +160,18 @@ Definition jumpi : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let conditional_value := + |) + |) in + let _ := M.assign_local (| + "conditional_value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -171,11 +189,13 @@ Definition jumpi : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let destination := + let _ := M.assign_local (| + "destination" , BinOp.add (| M.get_field (| M.get_name (| globals, "evm" |), "pc" |), Constant.int 1 - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -192,8 +212,10 @@ Definition jumpi : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let destination := - M.get_name (| globals, "jump_dest" |) in + let _ := M.assign_local (| + "destination" , + M.get_name (| globals, "jump_dest" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/environment.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/environment.v index bb655b1..42b1678 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/environment.v @@ -17,29 +17,47 @@ Introduction Implementations of the EVM environment related instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. - -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. - -Axiom ethereum_dao_fork_state_imports : - AreImported globals "ethereum.dao_fork.state" [ "get_account" ]. - -Axiom ethereum_dao_fork_utils_address_imports : - AreImported globals "ethereum.dao_fork.utils.address" [ "to_address" ]. - -Axiom ethereum_dao_fork_vm_memory_imports : - AreImported globals "ethereum.dao_fork.vm.memory" [ "buffer_read"; "memory_write" ]. - -Axiom ethereum_dao_fork_vm_imports : - AreImported globals "ethereum.dao_fork.vm" [ "Evm" ]. - -Axiom ethereum_dao_fork_vm_gas_imports : - AreImported globals "ethereum.dao_fork.vm.gas" [ "GAS_BALANCE"; "GAS_BASE"; "GAS_COPY"; "GAS_EXTERNAL"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. - -Axiom ethereum_dao_fork_vm_stack_imports : - AreImported globals "ethereum.dao_fork.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". + +Axiom ethereum_dao_fork_state_imports_get_account : + IsImported globals "ethereum.dao_fork.state" "get_account". + +Axiom ethereum_dao_fork_utils_address_imports_to_address : + IsImported globals "ethereum.dao_fork.utils.address" "to_address". + +Axiom ethereum_dao_fork_vm_memory_imports_buffer_read : + IsImported globals "ethereum.dao_fork.vm.memory" "buffer_read". +Axiom ethereum_dao_fork_vm_memory_imports_memory_write : + IsImported globals "ethereum.dao_fork.vm.memory" "memory_write". + +Axiom ethereum_dao_fork_vm_imports_Evm : + IsImported globals "ethereum.dao_fork.vm" "Evm". + +Axiom ethereum_dao_fork_vm_gas_imports_GAS_BALANCE : + IsImported globals "ethereum.dao_fork.vm.gas" "GAS_BALANCE". +Axiom ethereum_dao_fork_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.dao_fork.vm.gas" "GAS_BASE". +Axiom ethereum_dao_fork_vm_gas_imports_GAS_COPY : + IsImported globals "ethereum.dao_fork.vm.gas" "GAS_COPY". +Axiom ethereum_dao_fork_vm_gas_imports_GAS_EXTERNAL : + IsImported globals "ethereum.dao_fork.vm.gas" "GAS_EXTERNAL". +Axiom ethereum_dao_fork_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.dao_fork.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_dao_fork_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.dao_fork.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_dao_fork_vm_gas_imports_charge_gas : + IsImported globals "ethereum.dao_fork.vm.gas" "charge_gas". + +Axiom ethereum_dao_fork_vm_stack_imports_pop : + IsImported globals "ethereum.dao_fork.vm.stack" "pop". +Axiom ethereum_dao_fork_vm_stack_imports_push : + IsImported globals "ethereum.dao_fork.vm.stack" "push". Definition address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -95,7 +113,8 @@ Definition balance : Value.t -> Value.t -> M := The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -108,7 +127,8 @@ Definition balance : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -117,7 +137,8 @@ Definition balance : Value.t -> Value.t -> M := ], make_dict [] |) in - let balance := + let _ := M.assign_local (| + "balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -125,7 +146,8 @@ Definition balance : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -275,14 +297,16 @@ Definition calldataload : Value.t -> Value.t -> M := The current EVM frame. " in - let start_index := + let _ := M.assign_local (| + "start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -291,7 +315,8 @@ Definition calldataload : Value.t -> Value.t -> M := ], make_dict [] |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -306,7 +331,8 @@ Definition calldataload : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -391,31 +417,38 @@ Definition calldatacopy : Value.t -> Value.t -> M := The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let data_start_index := + |) + |) in + let _ := M.assign_local (| + "data_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -431,13 +464,17 @@ Definition calldatacopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -447,7 +484,8 @@ Definition calldatacopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -470,7 +508,8 @@ Definition calldatacopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -479,7 +518,8 @@ Definition calldatacopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -559,31 +599,38 @@ Definition codecopy : Value.t -> Value.t -> M := The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let code_start_index := + |) + |) in + let _ := M.assign_local (| + "code_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -599,13 +646,17 @@ Definition codecopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -615,7 +666,8 @@ Definition codecopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -638,7 +690,8 @@ Definition codecopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -647,7 +700,8 @@ Definition codecopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -718,7 +772,8 @@ Definition extcodesize : Value.t -> Value.t -> M := The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -731,7 +786,8 @@ Definition extcodesize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -740,7 +796,8 @@ Definition extcodesize : Value.t -> Value.t -> M := ], make_dict [] |) in - let codesize := + let _ := M.assign_local (| + "codesize" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -760,7 +817,8 @@ Definition extcodesize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -788,7 +846,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -801,32 +860,40 @@ Definition extcodecopy : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let memory_start_index := + |) + |) in + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let code_start_index := + |) + |) in + let _ := M.assign_local (| + "code_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -842,13 +909,17 @@ Definition extcodecopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -858,7 +929,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -881,7 +953,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let code := + let _ := M.assign_local (| + "code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -889,8 +962,10 @@ Definition extcodecopy : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |), "code" |) in - let value := + |), "code" |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -899,7 +974,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/keccak.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/keccak.v index 68788bd..3205868 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/keccak.v @@ -17,26 +17,36 @@ Introduction Implementations of the EVM keccak instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_dao_fork_vm_imports : - AreImported globals "ethereum.dao_fork.vm" [ "Evm" ]. +Axiom ethereum_dao_fork_vm_imports_Evm : + IsImported globals "ethereum.dao_fork.vm" "Evm". -Axiom ethereum_dao_fork_vm_gas_imports : - AreImported globals "ethereum.dao_fork.vm.gas" [ "GAS_KECCAK256"; "GAS_KECCAK256_WORD"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_dao_fork_vm_gas_imports_GAS_KECCAK256 : + IsImported globals "ethereum.dao_fork.vm.gas" "GAS_KECCAK256". +Axiom ethereum_dao_fork_vm_gas_imports_GAS_KECCAK256_WORD : + IsImported globals "ethereum.dao_fork.vm.gas" "GAS_KECCAK256_WORD". +Axiom ethereum_dao_fork_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.dao_fork.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_dao_fork_vm_gas_imports_charge_gas : + IsImported globals "ethereum.dao_fork.vm.gas" "charge_gas". -Axiom ethereum_dao_fork_vm_memory_imports : - AreImported globals "ethereum.dao_fork.vm.memory" [ "memory_read_bytes" ]. +Axiom ethereum_dao_fork_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.dao_fork.vm.memory" "memory_read_bytes". -Axiom ethereum_dao_fork_vm_stack_imports : - AreImported globals "ethereum.dao_fork.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_dao_fork_vm_stack_imports_pop : + IsImported globals "ethereum.dao_fork.vm.stack" "pop". +Axiom ethereum_dao_fork_vm_stack_imports_push : + IsImported globals "ethereum.dao_fork.vm.stack" "push". Definition keccak : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -53,23 +63,28 @@ Definition keccak : Value.t -> Value.t -> M := The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -85,13 +100,17 @@ Definition keccak : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let word_gas_cost := + |) + |) in + let _ := M.assign_local (| + "word_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_KECCAK256_WORD" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -101,7 +120,8 @@ Definition keccak : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -124,7 +144,8 @@ Definition keccak : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let data := + let _ := M.assign_local (| + "data" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -133,15 +154,18 @@ Definition keccak : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in - let hash := + |) + |) in + let _ := M.assign_local (| + "hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "data" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/log.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/log.v index e1cf129..47d5c73 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/log.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/log.v @@ -17,26 +17,34 @@ Introduction Implementations of the EVM logging instructions. ". -Axiom functools_imports : - AreImported globals "functools" [ "partial" ]. +Axiom functools_imports_partial : + IsImported globals "functools" "partial". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_dao_fork_blocks_imports : - AreImported globals "ethereum.dao_fork.blocks" [ "Log" ]. +Axiom ethereum_dao_fork_blocks_imports_Log : + IsImported globals "ethereum.dao_fork.blocks" "Log". -Axiom ethereum_dao_fork_vm_imports : - AreImported globals "ethereum.dao_fork.vm" [ "Evm" ]. +Axiom ethereum_dao_fork_vm_imports_Evm : + IsImported globals "ethereum.dao_fork.vm" "Evm". -Axiom ethereum_dao_fork_vm_gas_imports : - AreImported globals "ethereum.dao_fork.vm.gas" [ "GAS_LOG"; "GAS_LOG_DATA"; "GAS_LOG_TOPIC"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_dao_fork_vm_gas_imports_GAS_LOG : + IsImported globals "ethereum.dao_fork.vm.gas" "GAS_LOG". +Axiom ethereum_dao_fork_vm_gas_imports_GAS_LOG_DATA : + IsImported globals "ethereum.dao_fork.vm.gas" "GAS_LOG_DATA". +Axiom ethereum_dao_fork_vm_gas_imports_GAS_LOG_TOPIC : + IsImported globals "ethereum.dao_fork.vm.gas" "GAS_LOG_TOPIC". +Axiom ethereum_dao_fork_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.dao_fork.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_dao_fork_vm_gas_imports_charge_gas : + IsImported globals "ethereum.dao_fork.vm.gas" "charge_gas". -Axiom ethereum_dao_fork_vm_memory_imports : - AreImported globals "ethereum.dao_fork.vm.memory" [ "memory_read_bytes" ]. +Axiom ethereum_dao_fork_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.dao_fork.vm.memory" "memory_read_bytes". -Axiom ethereum_dao_fork_vm_stack_imports : - AreImported globals "ethereum.dao_fork.vm.stack" [ "pop" ]. +Axiom ethereum_dao_fork_vm_stack_imports_pop : + IsImported globals "ethereum.dao_fork.vm.stack" "pop". Definition log_n : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -55,24 +63,30 @@ Definition log_n : Value.t -> Value.t -> M := The number of topics to be included in the log entry. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let topics := - make_list [] in + |) + |) in + let _ := M.assign_local (| + "topics" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "_" |), @@ -84,7 +98,8 @@ Definition log_n : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let topic := + let _ := M.assign_local (| + "topic" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -95,7 +110,8 @@ Definition log_n : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "topics" |), "append" |), make_list [ @@ -109,7 +125,8 @@ Definition log_n : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let extend_memory := + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -119,7 +136,8 @@ Definition log_n : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -151,12 +169,14 @@ Definition log_n : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let log_entry := + let _ := M.assign_local (| + "log_entry" , M.call (| M.get_name (| globals, "Log" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "logs" |), BinOp.add (| diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/memory.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/memory.v index 9959d29..45dbf56 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/memory.v @@ -17,20 +17,32 @@ Introduction Implementations of the EVM Memory instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". -Axiom ethereum_dao_fork_vm_imports : - AreImported globals "ethereum.dao_fork.vm" [ "Evm" ]. +Axiom ethereum_dao_fork_vm_imports_Evm : + IsImported globals "ethereum.dao_fork.vm" "Evm". -Axiom ethereum_dao_fork_vm_gas_imports : - AreImported globals "ethereum.dao_fork.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_dao_fork_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.dao_fork.vm.gas" "GAS_BASE". +Axiom ethereum_dao_fork_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.dao_fork.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_dao_fork_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.dao_fork.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_dao_fork_vm_gas_imports_charge_gas : + IsImported globals "ethereum.dao_fork.vm.gas" "charge_gas". -Axiom ethereum_dao_fork_vm_memory_imports : - AreImported globals "ethereum.dao_fork.vm.memory" [ "memory_read_bytes"; "memory_write" ]. +Axiom ethereum_dao_fork_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.dao_fork.vm.memory" "memory_read_bytes". +Axiom ethereum_dao_fork_vm_memory_imports_memory_write : + IsImported globals "ethereum.dao_fork.vm.memory" "memory_write". -Axiom ethereum_dao_fork_vm_stack_imports : - AreImported globals "ethereum.dao_fork.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_dao_fork_vm_stack_imports_pop : + IsImported globals "ethereum.dao_fork.vm.stack" "pop". +Axiom ethereum_dao_fork_vm_stack_imports_push : + IsImported globals "ethereum.dao_fork.vm.stack" "push". Definition mstore : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -46,15 +58,18 @@ Definition mstore : Value.t -> Value.t -> M := The current EVM frame. " in - let start_position := + let _ := M.assign_local (| + "start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -65,8 +80,10 @@ Definition mstore : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -88,7 +105,8 @@ Definition mstore : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -138,23 +156,28 @@ Definition mstore8 : Value.t -> Value.t -> M := The current EVM frame. " in - let start_position := + let _ := M.assign_local (| + "start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -170,7 +193,8 @@ Definition mstore8 : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -190,7 +214,8 @@ Definition mstore8 : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let normalized_bytes_value := + let _ := M.assign_local (| + "normalized_bytes_value" , M.call (| M.get_name (| globals, "Bytes" |), make_list [ @@ -202,7 +227,8 @@ Definition mstore8 : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -231,15 +257,18 @@ Definition mload : Value.t -> Value.t -> M := The current EVM frame. " in - let start_position := + let _ := M.assign_local (| + "start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -255,7 +284,8 @@ Definition mload : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -275,7 +305,8 @@ Definition mload : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -296,7 +327,8 @@ Definition mload : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/stack.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/stack.v index e64ce43..2ee7ab3 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/stack.v @@ -17,26 +17,32 @@ Introduction Implementations of the EVM stack related instructions. ". -Axiom functools_imports : - AreImported globals "functools" [ "partial" ]. +Axiom functools_imports_partial : + IsImported globals "functools" "partial". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_dao_fork_vm_imports : - AreImported globals "ethereum.dao_fork.vm" [ "Evm"; "stack" ]. +Axiom ethereum_dao_fork_vm_imports_Evm : + IsImported globals "ethereum.dao_fork.vm" "Evm". +Axiom ethereum_dao_fork_vm_imports_stack : + IsImported globals "ethereum.dao_fork.vm" "stack". -Axiom ethereum_dao_fork_vm_exceptions_imports : - AreImported globals "ethereum.dao_fork.vm.exceptions" [ "StackUnderflowError" ]. +Axiom ethereum_dao_fork_vm_exceptions_imports_StackUnderflowError : + IsImported globals "ethereum.dao_fork.vm.exceptions" "StackUnderflowError". -Axiom ethereum_dao_fork_vm_gas_imports : - AreImported globals "ethereum.dao_fork.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_dao_fork_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.dao_fork.vm.gas" "GAS_BASE". +Axiom ethereum_dao_fork_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.dao_fork.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_dao_fork_vm_gas_imports_charge_gas : + IsImported globals "ethereum.dao_fork.vm.gas" "charge_gas". -Axiom ethereum_dao_fork_vm_memory_imports : - AreImported globals "ethereum.dao_fork.vm.memory" [ "buffer_read" ]. +Axiom ethereum_dao_fork_vm_memory_imports_buffer_read : + IsImported globals "ethereum.dao_fork.vm.memory" "buffer_read". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -98,7 +104,8 @@ Definition push_n : Value.t -> Value.t -> M := ], make_dict [] |) in - let data_to_push := + let _ := M.assign_local (| + "data_to_push" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -128,7 +135,8 @@ Definition push_n : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "stack" |), "push" |), make_list [ @@ -189,7 +197,8 @@ Definition dup_n : Value.t -> Value.t -> M := ], make_dict [] |) in - let data_to_duplicate := + let _ := M.assign_local (| + "data_to_duplicate" , M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| @@ -205,7 +214,8 @@ Definition dup_n : Value.t -> Value.t -> M := |), M.get_name (| globals, "item_number" |) |) - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "stack" |), "push" |), make_list [ diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/storage.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/storage.v index 9cbe938..de11f5d 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/storage.v @@ -17,17 +17,29 @@ Introduction Implementations of the EVM storage related instructions. ". -Axiom ethereum_dao_fork_state_imports : - AreImported globals "ethereum.dao_fork.state" [ "get_storage"; "set_storage" ]. +Axiom ethereum_dao_fork_state_imports_get_storage : + IsImported globals "ethereum.dao_fork.state" "get_storage". +Axiom ethereum_dao_fork_state_imports_set_storage : + IsImported globals "ethereum.dao_fork.state" "set_storage". -Axiom ethereum_dao_fork_vm_imports : - AreImported globals "ethereum.dao_fork.vm" [ "Evm" ]. +Axiom ethereum_dao_fork_vm_imports_Evm : + IsImported globals "ethereum.dao_fork.vm" "Evm". -Axiom ethereum_dao_fork_vm_gas_imports : - AreImported globals "ethereum.dao_fork.vm.gas" [ "GAS_SLOAD"; "GAS_STORAGE_CLEAR_REFUND"; "GAS_STORAGE_SET"; "GAS_STORAGE_UPDATE"; "charge_gas" ]. +Axiom ethereum_dao_fork_vm_gas_imports_GAS_SLOAD : + IsImported globals "ethereum.dao_fork.vm.gas" "GAS_SLOAD". +Axiom ethereum_dao_fork_vm_gas_imports_GAS_STORAGE_CLEAR_REFUND : + IsImported globals "ethereum.dao_fork.vm.gas" "GAS_STORAGE_CLEAR_REFUND". +Axiom ethereum_dao_fork_vm_gas_imports_GAS_STORAGE_SET : + IsImported globals "ethereum.dao_fork.vm.gas" "GAS_STORAGE_SET". +Axiom ethereum_dao_fork_vm_gas_imports_GAS_STORAGE_UPDATE : + IsImported globals "ethereum.dao_fork.vm.gas" "GAS_STORAGE_UPDATE". +Axiom ethereum_dao_fork_vm_gas_imports_charge_gas : + IsImported globals "ethereum.dao_fork.vm.gas" "charge_gas". -Axiom ethereum_dao_fork_vm_stack_imports : - AreImported globals "ethereum.dao_fork.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_dao_fork_vm_stack_imports_pop : + IsImported globals "ethereum.dao_fork.vm.stack" "pop". +Axiom ethereum_dao_fork_vm_stack_imports_push : + IsImported globals "ethereum.dao_fork.vm.stack" "push". Definition sload : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,7 +54,8 @@ Definition sload : Value.t -> Value.t -> M := The current EVM frame. " in - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -53,7 +66,8 @@ Definition sload : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -62,7 +76,8 @@ Definition sload : Value.t -> Value.t -> M := ], make_dict [] |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "get_storage" |), make_list [ @@ -71,7 +86,8 @@ Definition sload : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -99,7 +115,8 @@ Definition sstore : Value.t -> Value.t -> M := The current EVM frame. " in - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -110,16 +127,20 @@ Definition sstore : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in - let new_value := + |) + |) in + let _ := M.assign_local (| + "new_value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let current_value := + |) + |) in + let _ := M.assign_local (| + "current_value" , M.call (| M.get_name (| globals, "get_storage" |), make_list [ @@ -128,7 +149,8 @@ Definition sstore : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -146,13 +168,17 @@ Definition sstore : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let gas_cost := - M.get_name (| globals, "GAS_STORAGE_SET" |) in + let _ := M.assign_local (| + "gas_cost" , + M.get_name (| globals, "GAS_STORAGE_SET" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let gas_cost := - M.get_name (| globals, "GAS_STORAGE_UPDATE" |) in + let _ := M.assign_local (| + "gas_cost" , + M.get_name (| globals, "GAS_STORAGE_UPDATE" |) + |) in M.pure Constant.None_ )) |) in let _ := diff --git a/CoqOfPython/ethereum/dao_fork/vm/instructions/system.v b/CoqOfPython/ethereum/dao_fork/vm/instructions/system.v index 8541798..47ad133 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/instructions/system.v +++ b/CoqOfPython/ethereum/dao_fork/vm/instructions/system.v @@ -17,29 +17,63 @@ Introduction Implementations of the EVM system related instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_dao_fork_fork_types_imports : - AreImported globals "ethereum.dao_fork.fork_types" [ "Address" ]. +Axiom ethereum_dao_fork_fork_types_imports_Address : + IsImported globals "ethereum.dao_fork.fork_types" "Address". -Axiom ethereum_dao_fork_state_imports : - AreImported globals "ethereum.dao_fork.state" [ "account_has_code_or_nonce"; "get_account"; "increment_nonce"; "set_account_balance" ]. +Axiom ethereum_dao_fork_state_imports_account_has_code_or_nonce : + IsImported globals "ethereum.dao_fork.state" "account_has_code_or_nonce". +Axiom ethereum_dao_fork_state_imports_get_account : + IsImported globals "ethereum.dao_fork.state" "get_account". +Axiom ethereum_dao_fork_state_imports_increment_nonce : + IsImported globals "ethereum.dao_fork.state" "increment_nonce". +Axiom ethereum_dao_fork_state_imports_set_account_balance : + IsImported globals "ethereum.dao_fork.state" "set_account_balance". -Axiom ethereum_dao_fork_utils_address_imports : - AreImported globals "ethereum.dao_fork.utils.address" [ "compute_contract_address"; "to_address" ]. +Axiom ethereum_dao_fork_utils_address_imports_compute_contract_address : + IsImported globals "ethereum.dao_fork.utils.address" "compute_contract_address". +Axiom ethereum_dao_fork_utils_address_imports_to_address : + IsImported globals "ethereum.dao_fork.utils.address" "to_address". -Axiom ethereum_dao_fork_vm_imports : - AreImported globals "ethereum.dao_fork.vm" [ "Evm"; "Message"; "incorporate_child_on_error"; "incorporate_child_on_success" ]. +Axiom ethereum_dao_fork_vm_imports_Evm : + IsImported globals "ethereum.dao_fork.vm" "Evm". +Axiom ethereum_dao_fork_vm_imports_Message : + IsImported globals "ethereum.dao_fork.vm" "Message". +Axiom ethereum_dao_fork_vm_imports_incorporate_child_on_error : + IsImported globals "ethereum.dao_fork.vm" "incorporate_child_on_error". +Axiom ethereum_dao_fork_vm_imports_incorporate_child_on_success : + IsImported globals "ethereum.dao_fork.vm" "incorporate_child_on_success". -Axiom ethereum_dao_fork_vm_gas_imports : - AreImported globals "ethereum.dao_fork.vm.gas" [ "GAS_CALL"; "GAS_CREATE"; "GAS_ZERO"; "REFUND_SELF_DESTRUCT"; "calculate_gas_extend_memory"; "calculate_message_call_gas"; "charge_gas" ]. +Axiom ethereum_dao_fork_vm_gas_imports_GAS_CALL : + IsImported globals "ethereum.dao_fork.vm.gas" "GAS_CALL". +Axiom ethereum_dao_fork_vm_gas_imports_GAS_CREATE : + IsImported globals "ethereum.dao_fork.vm.gas" "GAS_CREATE". +Axiom ethereum_dao_fork_vm_gas_imports_GAS_ZERO : + IsImported globals "ethereum.dao_fork.vm.gas" "GAS_ZERO". +Axiom ethereum_dao_fork_vm_gas_imports_REFUND_SELF_DESTRUCT : + IsImported globals "ethereum.dao_fork.vm.gas" "REFUND_SELF_DESTRUCT". +Axiom ethereum_dao_fork_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.dao_fork.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_dao_fork_vm_gas_imports_calculate_message_call_gas : + IsImported globals "ethereum.dao_fork.vm.gas" "calculate_message_call_gas". +Axiom ethereum_dao_fork_vm_gas_imports_charge_gas : + IsImported globals "ethereum.dao_fork.vm.gas" "charge_gas". -Axiom ethereum_dao_fork_vm_memory_imports : - AreImported globals "ethereum.dao_fork.vm.memory" [ "memory_read_bytes"; "memory_write" ]. +Axiom ethereum_dao_fork_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.dao_fork.vm.memory" "memory_read_bytes". +Axiom ethereum_dao_fork_vm_memory_imports_memory_write : + IsImported globals "ethereum.dao_fork.vm.memory" "memory_write". -Axiom ethereum_dao_fork_vm_stack_imports : - AreImported globals "ethereum.dao_fork.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_dao_fork_vm_stack_imports_pop : + IsImported globals "ethereum.dao_fork.vm.stack" "pop". +Axiom ethereum_dao_fork_vm_stack_imports_push : + IsImported globals "ethereum.dao_fork.vm.stack" "push". Definition create : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -53,31 +87,38 @@ Definition create : Value.t -> Value.t -> M := The current EVM frame. " in (* At stmt: unsupported node type: ImportFrom *) - let endowment := + let _ := M.assign_local (| + "endowment" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_size := + |) + |) in + let _ := M.assign_local (| + "memory_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -87,7 +128,8 @@ Definition create : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -99,8 +141,10 @@ Definition create : Value.t -> Value.t -> M := ], make_dict [] |) in - let create_message_gas := - M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) in + let _ := M.assign_local (| + "create_message_gas" , + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), M.call (| @@ -119,9 +163,12 @@ Definition create : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let sender_address := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in - let sender := + let _ := M.assign_local (| + "sender_address" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + |) in + let _ := M.assign_local (| + "sender" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -129,8 +176,10 @@ Definition create : Value.t -> Value.t -> M := M.get_name (| globals, "sender_address" |) ], make_dict [] - |) in - let contract_address := + |) + |) in + let _ := M.assign_local (| + "contract_address" , M.call (| M.get_name (| globals, "compute_contract_address" |), make_list [ @@ -145,7 +194,8 @@ Definition create : Value.t -> Value.t -> M := |), "nonce" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -246,7 +296,8 @@ Definition create : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let call_data := + let _ := M.assign_local (| + "call_data" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -255,7 +306,8 @@ Definition create : Value.t -> Value.t -> M := M.get_name (| globals, "memory_size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "increment_nonce" |), make_list [ @@ -264,13 +316,16 @@ Definition create : Value.t -> Value.t -> M := ], make_dict [] |) in - let child_message := + let _ := M.assign_local (| + "child_message" , M.call (| M.get_name (| globals, "Message" |), make_list [], make_dict [] - |) in - let child_evm := + |) + |) in + let _ := M.assign_local (| + "child_evm" , M.call (| M.get_name (| globals, "process_create_message" |), make_list [ @@ -278,7 +333,8 @@ Definition create : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -356,23 +412,28 @@ Definition return_ : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let memory_start_position := + let _ := M.assign_local (| + "memory_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_size := + |) + |) in + let _ := M.assign_local (| + "memory_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -382,7 +443,8 @@ Definition return_ : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -467,7 +529,8 @@ Definition generic_call : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let call_data := + let _ := M.assign_local (| + "call_data" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -476,8 +539,10 @@ Definition generic_call : Value.t -> Value.t -> M := M.get_name (| globals, "memory_input_size" |) ], make_dict [] - |) in - let code := + |) + |) in + let _ := M.assign_local (| + "code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -485,14 +550,18 @@ Definition generic_call : Value.t -> Value.t -> M := M.get_name (| globals, "code_address" |) ], make_dict [] - |), "code" |) in - let child_message := + |), "code" |) + |) in + let _ := M.assign_local (| + "child_message" , M.call (| M.get_name (| globals, "Message" |), make_list [], make_dict [] - |) in - let child_evm := + |) + |) in + let _ := M.assign_local (| + "child_evm" , M.call (| M.get_name (| globals, "process_message" |), make_list [ @@ -500,7 +569,8 @@ Definition generic_call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -556,7 +626,8 @@ Definition generic_call : Value.t -> Value.t -> M := |) in M.pure Constant.None_ )) |) in - let actual_output_size := + let _ := M.assign_local (| + "actual_output_size" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -576,7 +647,8 @@ Definition generic_call : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -604,7 +676,8 @@ Definition call : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -617,8 +690,10 @@ Definition call : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let to := + |) + |) in + let _ := M.assign_local (| + "to" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -631,48 +706,60 @@ Definition call : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -683,8 +770,10 @@ Definition call : Value.t -> Value.t -> M := ] ], make_dict [] - |) in - let message_call_gas := + |) + |) in + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -694,7 +783,8 @@ Definition call : Value.t -> Value.t -> M := M.get_name (| globals, "value" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -714,7 +804,8 @@ Definition call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let sender_balance := + let _ := M.assign_local (| + "sender_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -722,7 +813,8 @@ Definition call : Value.t -> Value.t -> M := M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := (* if *) M.if_then_else (| @@ -791,7 +883,8 @@ Definition callcode : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -804,8 +897,10 @@ Definition callcode : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let code_address := + |) + |) in + let _ := M.assign_local (| + "code_address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -818,50 +913,64 @@ Definition callcode : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let to := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "to" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -872,8 +981,10 @@ Definition callcode : Value.t -> Value.t -> M := ] ], make_dict [] - |) in - let message_call_gas := + |) + |) in + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -883,7 +994,8 @@ Definition callcode : Value.t -> Value.t -> M := M.get_name (| globals, "value" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -903,7 +1015,8 @@ Definition callcode : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let sender_balance := + let _ := M.assign_local (| + "sender_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -911,7 +1024,8 @@ Definition callcode : Value.t -> Value.t -> M := M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := (* if *) M.if_then_else (| @@ -980,7 +1094,8 @@ Definition selfdestruct : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let beneficiary := + let _ := M.assign_local (| + "beneficiary" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -993,15 +1108,24 @@ Definition selfdestruct : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let gas_cost := - M.get_name (| globals, "GAS_ZERO" |) in - let originator := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in - let refunded_accounts := - M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in - let parent_evm := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "parent_evm" |) in + |) + |) in + let _ := M.assign_local (| + "gas_cost" , + M.get_name (| globals, "GAS_ZERO" |) + |) in + let _ := M.assign_local (| + "originator" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + |) in + let _ := M.assign_local (| + "refunded_accounts" , + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) + |) in + let _ := M.assign_local (| + "parent_evm" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "parent_evm" |) + |) in let _ := M.while (| Compare.is_not (| @@ -1016,8 +1140,10 @@ Definition selfdestruct : Value.t -> Value.t -> M := ], make_dict [] |) in - let parent_evm := - M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in + let _ := M.assign_local (| + "parent_evm" , + M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -1051,7 +1177,8 @@ Definition selfdestruct : Value.t -> Value.t -> M := ], make_dict [] |) in - let beneficiary_balance := + let _ := M.assign_local (| + "beneficiary_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1059,8 +1186,10 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_name (| globals, "beneficiary" |) ], make_dict [] - |), "balance" |) in - let originator_balance := + |), "balance" |) + |) in + let _ := M.assign_local (| + "originator_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1068,7 +1197,8 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_name (| globals, "originator" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -1121,7 +1251,8 @@ Definition delegatecall : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -1134,8 +1265,10 @@ Definition delegatecall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let code_address := + |) + |) in + let _ := M.assign_local (| + "code_address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1148,40 +1281,50 @@ Definition delegatecall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1192,7 +1335,8 @@ Definition delegatecall : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ diff --git a/CoqOfPython/ethereum/dao_fork/vm/interpreter.v b/CoqOfPython/ethereum/dao_fork/vm/interpreter.v index cbdc08b..1a01d75 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/interpreter.v +++ b/CoqOfPython/ethereum/dao_fork/vm/interpreter.v @@ -17,47 +17,95 @@ Introduction A straightforward interpreter that executes EVM code. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Optional"; "Set"; "Tuple"; "Union" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. - -Axiom ethereum_trace_imports : - AreImported globals "ethereum.trace" [ "EvmStop"; "OpEnd"; "OpException"; "OpStart"; "PrecompileEnd"; "PrecompileStart"; "TransactionEnd"; "evm_trace" ]. - -Axiom ethereum_dao_fork_blocks_imports : - AreImported globals "ethereum.dao_fork.blocks" [ "Log" ]. - -Axiom ethereum_dao_fork_fork_types_imports : - AreImported globals "ethereum.dao_fork.fork_types" [ "Address" ]. - -Axiom ethereum_dao_fork_state_imports : - AreImported globals "ethereum.dao_fork.state" [ "account_has_code_or_nonce"; "begin_transaction"; "commit_transaction"; "move_ether"; "rollback_transaction"; "set_code"; "touch_account" ]. - -Axiom ethereum_dao_fork_vm_imports : - AreImported globals "ethereum.dao_fork.vm" [ "Message" ]. - -Axiom ethereum_dao_fork_vm_gas_imports : - AreImported globals "ethereum.dao_fork.vm.gas" [ "GAS_CODE_DEPOSIT"; "charge_gas" ]. - -Axiom ethereum_dao_fork_vm_precompiled_contracts_mapping_imports : - AreImported globals "ethereum.dao_fork.vm.precompiled_contracts.mapping" [ "PRE_COMPILED_CONTRACTS" ]. - -Axiom ethereum_dao_fork_vm_imports : - AreImported globals "ethereum.dao_fork.vm" [ "Environment"; "Evm" ]. - -Axiom ethereum_dao_fork_vm_exceptions_imports : - AreImported globals "ethereum.dao_fork.vm.exceptions" [ "AddressCollision"; "ExceptionalHalt"; "InvalidOpcode"; "StackDepthLimitError" ]. - -Axiom ethereum_dao_fork_vm_instructions_imports : - AreImported globals "ethereum.dao_fork.vm.instructions" [ "Ops"; "op_implementation" ]. - -Axiom ethereum_dao_fork_vm_runtime_imports : - AreImported globals "ethereum.dao_fork.vm.runtime" [ "get_valid_jump_destinations" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_trace_imports_EvmStop : + IsImported globals "ethereum.trace" "EvmStop". +Axiom ethereum_trace_imports_OpEnd : + IsImported globals "ethereum.trace" "OpEnd". +Axiom ethereum_trace_imports_OpException : + IsImported globals "ethereum.trace" "OpException". +Axiom ethereum_trace_imports_OpStart : + IsImported globals "ethereum.trace" "OpStart". +Axiom ethereum_trace_imports_PrecompileEnd : + IsImported globals "ethereum.trace" "PrecompileEnd". +Axiom ethereum_trace_imports_PrecompileStart : + IsImported globals "ethereum.trace" "PrecompileStart". +Axiom ethereum_trace_imports_TransactionEnd : + IsImported globals "ethereum.trace" "TransactionEnd". +Axiom ethereum_trace_imports_evm_trace : + IsImported globals "ethereum.trace" "evm_trace". + +Axiom ethereum_dao_fork_blocks_imports_Log : + IsImported globals "ethereum.dao_fork.blocks" "Log". + +Axiom ethereum_dao_fork_fork_types_imports_Address : + IsImported globals "ethereum.dao_fork.fork_types" "Address". + +Axiom ethereum_dao_fork_state_imports_account_has_code_or_nonce : + IsImported globals "ethereum.dao_fork.state" "account_has_code_or_nonce". +Axiom ethereum_dao_fork_state_imports_begin_transaction : + IsImported globals "ethereum.dao_fork.state" "begin_transaction". +Axiom ethereum_dao_fork_state_imports_commit_transaction : + IsImported globals "ethereum.dao_fork.state" "commit_transaction". +Axiom ethereum_dao_fork_state_imports_move_ether : + IsImported globals "ethereum.dao_fork.state" "move_ether". +Axiom ethereum_dao_fork_state_imports_rollback_transaction : + IsImported globals "ethereum.dao_fork.state" "rollback_transaction". +Axiom ethereum_dao_fork_state_imports_set_code : + IsImported globals "ethereum.dao_fork.state" "set_code". +Axiom ethereum_dao_fork_state_imports_touch_account : + IsImported globals "ethereum.dao_fork.state" "touch_account". + +Axiom ethereum_dao_fork_vm_imports_Message : + IsImported globals "ethereum.dao_fork.vm" "Message". + +Axiom ethereum_dao_fork_vm_gas_imports_GAS_CODE_DEPOSIT : + IsImported globals "ethereum.dao_fork.vm.gas" "GAS_CODE_DEPOSIT". +Axiom ethereum_dao_fork_vm_gas_imports_charge_gas : + IsImported globals "ethereum.dao_fork.vm.gas" "charge_gas". + +Axiom ethereum_dao_fork_vm_precompiled_contracts_mapping_imports_PRE_COMPILED_CONTRACTS : + IsImported globals "ethereum.dao_fork.vm.precompiled_contracts.mapping" "PRE_COMPILED_CONTRACTS". + +Axiom ethereum_dao_fork_vm_imports_Environment : + IsImported globals "ethereum.dao_fork.vm" "Environment". +Axiom ethereum_dao_fork_vm_imports_Evm : + IsImported globals "ethereum.dao_fork.vm" "Evm". + +Axiom ethereum_dao_fork_vm_exceptions_imports_AddressCollision : + IsImported globals "ethereum.dao_fork.vm.exceptions" "AddressCollision". +Axiom ethereum_dao_fork_vm_exceptions_imports_ExceptionalHalt : + IsImported globals "ethereum.dao_fork.vm.exceptions" "ExceptionalHalt". +Axiom ethereum_dao_fork_vm_exceptions_imports_InvalidOpcode : + IsImported globals "ethereum.dao_fork.vm.exceptions" "InvalidOpcode". +Axiom ethereum_dao_fork_vm_exceptions_imports_StackDepthLimitError : + IsImported globals "ethereum.dao_fork.vm.exceptions" "StackDepthLimitError". + +Axiom ethereum_dao_fork_vm_instructions_imports_Ops : + IsImported globals "ethereum.dao_fork.vm.instructions" "Ops". +Axiom ethereum_dao_fork_vm_instructions_imports_op_implementation : + IsImported globals "ethereum.dao_fork.vm.instructions" "op_implementation". + +Axiom ethereum_dao_fork_vm_runtime_imports_get_valid_jump_destinations : + IsImported globals "ethereum.dao_fork.vm.runtime" "get_valid_jump_destinations". Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -114,7 +162,8 @@ Definition process_message_call : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let is_collision := + let _ := M.assign_local (| + "is_collision" , M.call (| M.get_name (| globals, "account_has_code_or_nonce" |), make_list [ @@ -122,7 +171,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "message" |), "current_target" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -169,7 +219,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "process_create_message" |), make_list [ @@ -177,13 +228,15 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "process_message" |), make_list [ @@ -191,7 +244,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := @@ -201,32 +255,43 @@ Definition process_message_call : Value.t -> Value.t -> M := (* then *) ltac:(M.monadic ( (* At stmt: unsupported node type: AnnAssign *) - let accounts_to_delete := + let _ := M.assign_local (| + "accounts_to_delete" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let refund_counter := + |) + |) in + let _ := M.assign_local (| + "refund_counter" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let logs := - M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in - let accounts_to_delete := - M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in - let refund_counter := - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |) in + let _ := M.assign_local (| + "logs" , + M.get_field (| M.get_name (| globals, "evm" |), "logs" |) + |) in + let _ := M.assign_local (| + "accounts_to_delete" , + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) + |) in + let _ := M.assign_local (| + "refund_counter" , + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |) + |) in M.pure Constant.None_ )) |) in - let tx_end := + let _ := M.assign_local (| + "tx_end" , M.call (| M.get_name (| globals, "TransactionEnd" |), make_list [ @@ -238,7 +303,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "error" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "evm_trace" |), make_list [ @@ -281,7 +347,8 @@ Definition process_create_message : Value.t -> Value.t -> M := ], make_dict [] |) in - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "process_message" |), make_list [ @@ -289,16 +356,20 @@ Definition process_create_message : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), (* then *) ltac:(M.monadic ( - let contract_code := - M.get_field (| M.get_name (| globals, "evm" |), "output" |) in - let contract_code_gas := + let _ := M.assign_local (| + "contract_code" , + M.get_field (| M.get_name (| globals, "evm" |), "output" |) + |) in + let _ := M.assign_local (| + "contract_code_gas" , BinOp.mult (| M.call (| M.get_name (| globals, "len" |), @@ -308,7 +379,8 @@ Definition process_create_message : Value.t -> Value.t -> M := make_dict [] |), M.get_name (| globals, "GAS_CODE_DEPOSIT" |) - |) in + |) + |) in (* At stmt: unsupported node type: Try *) M.pure Constant.None_ (* else *) @@ -410,7 +482,8 @@ Definition process_message : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "execute_code" |), make_list [ @@ -418,7 +491,8 @@ Definition process_message : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -467,22 +541,28 @@ Definition execute_code : Value.t -> Value.t -> M := evm: `ethereum.vm.EVM` Items containing execution specific objects " in - let code := - M.get_field (| M.get_name (| globals, "message" |), "code" |) in - let valid_jump_destinations := + let _ := M.assign_local (| + "code" , + M.get_field (| M.get_name (| globals, "message" |), "code" |) + |) in + let _ := M.assign_local (| + "valid_jump_destinations" , M.call (| M.get_name (| globals, "get_valid_jump_destinations" |), make_list [ M.get_name (| globals, "code" |) ], make_dict [] - |) in - let evm := + |) + |) in + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "Evm" |), make_list [], make_dict [] - |) in + |) + |) in (* At stmt: unsupported node type: Try *) let _ := M.return_ (| M.get_name (| globals, "evm" |) diff --git a/CoqOfPython/ethereum/dao_fork/vm/memory.v b/CoqOfPython/ethereum/dao_fork/vm/memory.v index 2d024b9..d512649 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/memory.v +++ b/CoqOfPython/ethereum/dao_fork/vm/memory.v @@ -17,11 +17,15 @@ Introduction EVM memory operations. ". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "right_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_right_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "right_pad_zero_bytes". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". Definition memory_write : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/__init__.v index e714303..a28f1e8 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/__init__.v +++ b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/__init__.v @@ -18,8 +18,8 @@ Addresses of precompiled contracts and mappings to their implementations. ". -Axiom ethereum_dao_fork_utils_hexadecimal_imports : - AreImported globals "ethereum.dao_fork.utils.hexadecimal" [ "hex_to_address" ]. +Axiom ethereum_dao_fork_utils_hexadecimal_imports_hex_to_address : + IsImported globals "ethereum.dao_fork.utils.hexadecimal" "hex_to_address". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS" ] diff --git a/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/ecrecover.v index 6067370..0c4b624 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/ecrecover.v @@ -17,26 +17,32 @@ Introduction Implementation of the ECRECOVER precompiled contract. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_crypto_elliptic_curve_imports : - AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. +Axiom ethereum_crypto_elliptic_curve_imports_SECP256K1N : + IsImported globals "ethereum.crypto.elliptic_curve" "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_imports_secp256k1_recover : + IsImported globals "ethereum.crypto.elliptic_curve" "secp256k1_recover". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_left_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "left_pad_zero_bytes". -Axiom ethereum_dao_fork_vm_imports : - AreImported globals "ethereum.dao_fork.vm" [ "Evm" ]. +Axiom ethereum_dao_fork_vm_imports_Evm : + IsImported globals "ethereum.dao_fork.vm" "Evm". -Axiom ethereum_dao_fork_vm_gas_imports : - AreImported globals "ethereum.dao_fork.vm.gas" [ "GAS_ECRECOVER"; "charge_gas" ]. +Axiom ethereum_dao_fork_vm_gas_imports_GAS_ECRECOVER : + IsImported globals "ethereum.dao_fork.vm.gas" "GAS_ECRECOVER". +Axiom ethereum_dao_fork_vm_gas_imports_charge_gas : + IsImported globals "ethereum.dao_fork.vm.gas" "charge_gas". -Axiom ethereum_dao_fork_vm_memory_imports : - AreImported globals "ethereum.dao_fork.vm.memory" [ "buffer_read" ]. +Axiom ethereum_dao_fork_vm_memory_imports_buffer_read : + IsImported globals "ethereum.dao_fork.vm.memory" "buffer_read". Definition ecrecover : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -50,8 +56,10 @@ Definition ecrecover : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -60,7 +68,8 @@ Definition ecrecover : Value.t -> Value.t -> M := ], make_dict [] |) in - let message_hash_bytes := + let _ := M.assign_local (| + "message_hash_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -81,16 +90,20 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let message_hash := + |) + |) in + let _ := M.assign_local (| + "message_hash" , M.call (| M.get_name (| globals, "Hash32" |), make_list [ M.get_name (| globals, "message_hash_bytes" |) ], make_dict [] - |) in - let v := + |) + |) in + let _ := M.assign_local (| + "v" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -117,8 +130,10 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let r := + |) + |) in + let _ := M.assign_local (| + "r" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -145,8 +160,10 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let s := + |) + |) in + let _ := M.assign_local (| + "s" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -173,7 +190,8 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -250,7 +268,8 @@ Definition ecrecover : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: Try *) - let address := + let _ := M.assign_local (| + "address" , M.slice (| M.call (| M.get_name (| globals, "keccak256" |), @@ -262,8 +281,10 @@ Definition ecrecover : Value.t -> Value.t -> M := Constant.int 12, Constant.int 32, Constant.None_ - |) in - let padded_address := + |) + |) in + let _ := M.assign_local (| + "padded_address" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -271,7 +292,8 @@ Definition ecrecover : Value.t -> Value.t -> M := Constant.int 32 ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.get_name (| globals, "padded_address" |) diff --git a/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/identity.v index 7bf6d15..4b71893 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/identity.v +++ b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/identity.v @@ -17,17 +17,21 @@ Introduction Implementation of the `IDENTITY` precompiled contract. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_dao_fork_vm_imports : - AreImported globals "ethereum.dao_fork.vm" [ "Evm" ]. +Axiom ethereum_dao_fork_vm_imports_Evm : + IsImported globals "ethereum.dao_fork.vm" "Evm". -Axiom ethereum_dao_fork_vm_gas_imports : - AreImported globals "ethereum.dao_fork.vm.gas" [ "GAS_IDENTITY"; "GAS_IDENTITY_WORD"; "charge_gas" ]. +Axiom ethereum_dao_fork_vm_gas_imports_GAS_IDENTITY : + IsImported globals "ethereum.dao_fork.vm.gas" "GAS_IDENTITY". +Axiom ethereum_dao_fork_vm_gas_imports_GAS_IDENTITY_WORD : + IsImported globals "ethereum.dao_fork.vm.gas" "GAS_IDENTITY_WORD". +Axiom ethereum_dao_fork_vm_gas_imports_charge_gas : + IsImported globals "ethereum.dao_fork.vm.gas" "charge_gas". Definition identity : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -40,9 +44,12 @@ Definition identity : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let word_count := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "word_count" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -64,7 +71,8 @@ Definition identity : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ diff --git a/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/mapping.v index 8de95c1..b94fbd8 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/mapping.v +++ b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/mapping.v @@ -17,25 +17,33 @@ Introduction Mapping of precompiled contracts their implementations. ". -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict" ]. - -Axiom ethereum_dao_fork_fork_types_imports : - AreImported globals "ethereum.dao_fork.fork_types" [ "Address" ]. - -Axiom ethereum_dao_fork_vm_precompiled_contracts_imports : - AreImported globals "ethereum.dao_fork.vm.precompiled_contracts" [ "ECRECOVER_ADDRESS"; "IDENTITY_ADDRESS"; "RIPEMD160_ADDRESS"; "SHA256_ADDRESS" ]. - -Axiom ethereum_dao_fork_vm_precompiled_contracts_ecrecover_imports : - AreImported globals "ethereum.dao_fork.vm.precompiled_contracts.ecrecover" [ "ecrecover" ]. - -Axiom ethereum_dao_fork_vm_precompiled_contracts_identity_imports : - AreImported globals "ethereum.dao_fork.vm.precompiled_contracts.identity" [ "identity" ]. - -Axiom ethereum_dao_fork_vm_precompiled_contracts_ripemd160_imports : - AreImported globals "ethereum.dao_fork.vm.precompiled_contracts.ripemd160" [ "ripemd160" ]. - -Axiom ethereum_dao_fork_vm_precompiled_contracts_sha256_imports : - AreImported globals "ethereum.dao_fork.vm.precompiled_contracts.sha256" [ "sha256" ]. +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". + +Axiom ethereum_dao_fork_fork_types_imports_Address : + IsImported globals "ethereum.dao_fork.fork_types" "Address". + +Axiom ethereum_dao_fork_vm_precompiled_contracts_imports_ECRECOVER_ADDRESS : + IsImported globals "ethereum.dao_fork.vm.precompiled_contracts" "ECRECOVER_ADDRESS". +Axiom ethereum_dao_fork_vm_precompiled_contracts_imports_IDENTITY_ADDRESS : + IsImported globals "ethereum.dao_fork.vm.precompiled_contracts" "IDENTITY_ADDRESS". +Axiom ethereum_dao_fork_vm_precompiled_contracts_imports_RIPEMD160_ADDRESS : + IsImported globals "ethereum.dao_fork.vm.precompiled_contracts" "RIPEMD160_ADDRESS". +Axiom ethereum_dao_fork_vm_precompiled_contracts_imports_SHA256_ADDRESS : + IsImported globals "ethereum.dao_fork.vm.precompiled_contracts" "SHA256_ADDRESS". + +Axiom ethereum_dao_fork_vm_precompiled_contracts_ecrecover_imports_ecrecover : + IsImported globals "ethereum.dao_fork.vm.precompiled_contracts.ecrecover" "ecrecover". + +Axiom ethereum_dao_fork_vm_precompiled_contracts_identity_imports_identity : + IsImported globals "ethereum.dao_fork.vm.precompiled_contracts.identity" "identity". + +Axiom ethereum_dao_fork_vm_precompiled_contracts_ripemd160_imports_ripemd160 : + IsImported globals "ethereum.dao_fork.vm.precompiled_contracts.ripemd160" "ripemd160". + +Axiom ethereum_dao_fork_vm_precompiled_contracts_sha256_imports_sha256 : + IsImported globals "ethereum.dao_fork.vm.precompiled_contracts.sha256" "sha256". (* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/ripemd160.v index 9a13512..39c8265 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/ripemd160.v +++ b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/ripemd160.v @@ -19,20 +19,24 @@ Implementation of the `RIPEMD160` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_left_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "left_pad_zero_bytes". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_dao_fork_vm_imports : - AreImported globals "ethereum.dao_fork.vm" [ "Evm" ]. +Axiom ethereum_dao_fork_vm_imports_Evm : + IsImported globals "ethereum.dao_fork.vm" "Evm". -Axiom ethereum_dao_fork_vm_gas_imports : - AreImported globals "ethereum.dao_fork.vm.gas" [ "GAS_RIPEMD160"; "GAS_RIPEMD160_WORD"; "charge_gas" ]. +Axiom ethereum_dao_fork_vm_gas_imports_GAS_RIPEMD160 : + IsImported globals "ethereum.dao_fork.vm.gas" "GAS_RIPEMD160". +Axiom ethereum_dao_fork_vm_gas_imports_GAS_RIPEMD160_WORD : + IsImported globals "ethereum.dao_fork.vm.gas" "GAS_RIPEMD160_WORD". +Axiom ethereum_dao_fork_vm_gas_imports_charge_gas : + IsImported globals "ethereum.dao_fork.vm.gas" "charge_gas". Definition ripemd160 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,9 +49,12 @@ Definition ripemd160 : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let word_count := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "word_count" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -69,7 +76,8 @@ Definition ripemd160 : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -84,7 +92,8 @@ Definition ripemd160 : Value.t -> Value.t -> M := ], make_dict [] |) in - let hash_bytes := + let _ := M.assign_local (| + "hash_bytes" , M.call (| M.get_field (| M.call (| M.get_field (| M.get_name (| globals, "hashlib" |), "new" |), @@ -96,8 +105,10 @@ Definition ripemd160 : Value.t -> Value.t -> M := |), "digest" |), make_list [], make_dict [] - |) in - let padded_hash := + |) + |) in + let _ := M.assign_local (| + "padded_hash" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -105,7 +116,8 @@ Definition ripemd160 : Value.t -> Value.t -> M := Constant.int 32 ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.get_name (| globals, "padded_hash" |) diff --git a/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/sha256.v index 4d42913..69f489f 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/sha256.v +++ b/CoqOfPython/ethereum/dao_fork/vm/precompiled_contracts/sha256.v @@ -19,17 +19,21 @@ Implementation of the `SHA256` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_dao_fork_vm_imports : - AreImported globals "ethereum.dao_fork.vm" [ "Evm" ]. +Axiom ethereum_dao_fork_vm_imports_Evm : + IsImported globals "ethereum.dao_fork.vm" "Evm". -Axiom ethereum_dao_fork_vm_gas_imports : - AreImported globals "ethereum.dao_fork.vm.gas" [ "GAS_SHA256"; "GAS_SHA256_WORD"; "charge_gas" ]. +Axiom ethereum_dao_fork_vm_gas_imports_GAS_SHA256 : + IsImported globals "ethereum.dao_fork.vm.gas" "GAS_SHA256". +Axiom ethereum_dao_fork_vm_gas_imports_GAS_SHA256_WORD : + IsImported globals "ethereum.dao_fork.vm.gas" "GAS_SHA256_WORD". +Axiom ethereum_dao_fork_vm_gas_imports_charge_gas : + IsImported globals "ethereum.dao_fork.vm.gas" "charge_gas". Definition sha256 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,9 +46,12 @@ Definition sha256 : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let word_count := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "word_count" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -66,7 +73,8 @@ Definition sha256 : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ diff --git a/CoqOfPython/ethereum/dao_fork/vm/runtime.v b/CoqOfPython/ethereum/dao_fork/vm/runtime.v index ac94d55..9c619f3 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/runtime.v +++ b/CoqOfPython/ethereum/dao_fork/vm/runtime.v @@ -17,14 +17,14 @@ Introduction Runtime related operations used while executing EVM code. ". -Axiom typing_imports : - AreImported globals "typing" [ "Set" ]. +Axiom typing_imports_Set : + IsImported globals "typing" "Set". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_dao_fork_vm_instructions_imports : - AreImported globals "ethereum.dao_fork.vm.instructions" [ "Ops" ]. +Axiom ethereum_dao_fork_vm_instructions_imports_Ops : + IsImported globals "ethereum.dao_fork.vm.instructions" "Ops". Definition get_valid_jump_destinations : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -50,20 +50,24 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := valid_jump_destinations: `Set[Uint]` The set of valid jump destinations in the code. " in - let valid_jump_destinations := + let _ := M.assign_local (| + "valid_jump_destinations" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let pc := + |) + |) in + let _ := M.assign_local (| + "pc" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in let _ := M.while (| Compare.lt (| @@ -114,17 +118,21 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let push_data_size := + let _ := M.assign_local (| + "push_data_size" , BinOp.add (| BinOp.sub (| M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) |), Constant.int 1 - |) in - let pc := BinOp.add + |) + |) in + let _ := M.assign_op_local (| + BinOp.add, + "pc", M.get_name (| globals, "push_data_size" |) - M.get_name (| globals, "push_data_size" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -132,9 +140,11 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - let pc := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "pc", Constant.int 1 - Constant.int 1 in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/dao_fork/vm/stack.v b/CoqOfPython/ethereum/dao_fork/vm/stack.v index aae386d..b8cc90b 100644 --- a/CoqOfPython/ethereum/dao_fork/vm/stack.v +++ b/CoqOfPython/ethereum/dao_fork/vm/stack.v @@ -17,14 +17,16 @@ Introduction Implementation of the stack operators for the EVM. ". -Axiom typing_imports : - AreImported globals "typing" [ "List" ]. +Axiom typing_imports_List : + IsImported globals "typing" "List". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_dao_fork_vm_exceptions_imports : - AreImported globals "ethereum.dao_fork.vm.exceptions" [ "StackOverflowError"; "StackUnderflowError" ]. +Axiom ethereum_dao_fork_vm_exceptions_imports_StackOverflowError : + IsImported globals "ethereum.dao_fork.vm.exceptions" "StackOverflowError". +Axiom ethereum_dao_fork_vm_exceptions_imports_StackUnderflowError : + IsImported globals "ethereum.dao_fork.vm.exceptions" "StackUnderflowError". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/ethash.v b/CoqOfPython/ethereum/ethash.v index a9e4a62..59371c7 100644 --- a/CoqOfPython/ethereum/ethash.v +++ b/CoqOfPython/ethereum/ethash.v @@ -31,17 +31,37 @@ At a high level, the Ethash algorithm is as follows: [mem-hard]: https://en.wikipedia.org/wiki/Memory-hard_function ". -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Tuple"; "Union" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U32"; "Bytes8"; "Uint" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "Hash64"; "keccak256"; "keccak512" ]. - -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "is_prime"; "le_bytes_to_uint32_sequence"; "le_uint32_sequence_to_bytes"; "le_uint32_sequence_to_uint" ]. +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". + +Axiom ethereum_base_types_imports_U32 : + IsImported globals "ethereum.base_types" "U32". +Axiom ethereum_base_types_imports_Bytes8 : + IsImported globals "ethereum.base_types" "Bytes8". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_Hash64 : + IsImported globals "ethereum.crypto.hash" "Hash64". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". +Axiom ethereum_crypto_hash_imports_keccak512 : + IsImported globals "ethereum.crypto.hash" "keccak512". + +Axiom ethereum_utils_numeric_imports_is_prime : + IsImported globals "ethereum.utils.numeric" "is_prime". +Axiom ethereum_utils_numeric_imports_le_bytes_to_uint32_sequence : + IsImported globals "ethereum.utils.numeric" "le_bytes_to_uint32_sequence". +Axiom ethereum_utils_numeric_imports_le_uint32_sequence_to_bytes : + IsImported globals "ethereum.utils.numeric" "le_uint32_sequence_to_bytes". +Axiom ethereum_utils_numeric_imports_le_uint32_sequence_to_uint : + IsImported globals "ethereum.utils.numeric" "le_uint32_sequence_to_uint". Definition EPOCH_SIZE : Value.t := M.run ltac:(M.monadic ( Constant.int 30000 @@ -50,7 +70,7 @@ Definition EPOCH_SIZE : Value.t := M.run ltac:(M.monadic ( Definition expr_41 : Value.t := Constant.str " Number of blocks before a dataset needs to be regenerated (known as an -"""epoch""".) See [`epoch`]. +""epoch"".) See [`epoch`]. [`epoch`]: ref:ethereum.ethash.epoch ". @@ -215,7 +235,8 @@ Definition cache_size : Value.t -> Value.t -> M := [`CACHE_EPOCH_GROWTH_SIZE`]: ref:ethereum.ethash.CACHE_EPOCH_GROWTH_SIZE [`generate_cache`]: ref:ethereum.ethash.generate_cache " in - let size := + let _ := M.assign_local (| + "size" , BinOp.add (| M.get_name (| globals, "INITIAL_CACHE_SIZE" |), BinOp.mult (| @@ -228,10 +249,13 @@ Definition cache_size : Value.t -> Value.t -> M := make_dict [] |) |) - |) in - let size := BinOp.sub + |) + |) in + let _ := M.assign_op_local (| + BinOp.sub, + "size", M.get_name (| globals, "HASH_BYTES" |) - M.get_name (| globals, "HASH_BYTES" |) in + |) in let _ := M.while (| UnOp.not (| M.call (| @@ -245,15 +269,14 @@ Definition cache_size : Value.t -> Value.t -> M := make_dict [] |) |), ltac:(M.monadic ( - let size := BinOp.sub + let _ := M.assign_op_local (| + BinOp.sub, + "size", BinOp.mult (| Constant.int 2, M.get_name (| globals, "HASH_BYTES" |) |) - BinOp.mult (| - Constant.int 2, - M.get_name (| globals, "HASH_BYTES" |) - |) in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -287,7 +310,8 @@ Definition dataset_size : Value.t -> Value.t -> M := [`generate_dataset`]: ref:ethereum.ethash.generate_dataset [`generate_dataset_item`]: ref:ethereum.ethash.generate_dataset_item " in - let size := + let _ := M.assign_local (| + "size" , BinOp.add (| M.get_name (| globals, "INITIAL_DATASET_SIZE" |), BinOp.mult (| @@ -300,10 +324,13 @@ Definition dataset_size : Value.t -> Value.t -> M := make_dict [] |) |) - |) in - let size := BinOp.sub + |) + |) in + let _ := M.assign_op_local (| + BinOp.sub, + "size", M.get_name (| globals, "MIX_BYTES" |) - M.get_name (| globals, "MIX_BYTES" |) in + |) in let _ := M.while (| UnOp.not (| M.call (| @@ -317,15 +344,14 @@ Definition dataset_size : Value.t -> Value.t -> M := make_dict [] |) |), ltac:(M.monadic ( - let size := BinOp.sub + let _ := M.assign_op_local (| + BinOp.sub, + "size", BinOp.mult (| Constant.int 2, M.get_name (| globals, "MIX_BYTES" |) |) - BinOp.mult (| - Constant.int 2, - M.get_name (| globals, "MIX_BYTES" |) - |) in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -346,19 +372,23 @@ Definition generate_seed : Value.t -> Value.t -> M := [`generate_cache`]: ref:ethereum.ethash.generate_cache " in - let epoch_number := + let _ := M.assign_local (| + "epoch_number" , M.call (| M.get_name (| globals, "epoch" |), make_list [ M.get_name (| globals, "block_number" |) ], make_dict [] - |) in - let seed := + |) + |) in + let _ := M.assign_local (| + "seed" , BinOp.mult (| Constant.bytes "00", Constant.int 32 - |) in + |) + |) in let _ := M.while (| Compare.not_eq (| @@ -366,17 +396,21 @@ Definition generate_seed : Value.t -> Value.t -> M := Constant.int 0 |), ltac:(M.monadic ( - let seed := + let _ := M.assign_local (| + "seed" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "seed" |) ], make_dict [] - |) in - let epoch_number := BinOp.sub + |) + |) in + let _ := M.assign_op_local (| + BinOp.sub, + "epoch_number", Constant.int 1 - Constant.int 1 in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -409,28 +443,35 @@ Definition generate_cache : Value.t -> Value.t -> M := [`generate_dataset`]: ref:ethereum.ethash.generate_dataset [RandMemoHash]: http://www.hashcash.org/papers/memohash.pdf " in - let seed := + let _ := M.assign_local (| + "seed" , M.call (| M.get_name (| globals, "generate_seed" |), make_list [ M.get_name (| globals, "block_number" |) ], make_dict [] - |) in - let cache_size_bytes := + |) + |) in + let _ := M.assign_local (| + "cache_size_bytes" , M.call (| M.get_name (| globals, "cache_size" |), make_list [ M.get_name (| globals, "block_number" |) ], make_dict [] - |) in - let cache_size_words := + |) + |) in + let _ := M.assign_local (| + "cache_size_words" , BinOp.floor_div (| M.get_name (| globals, "cache_size_bytes" |), M.get_name (| globals, "HASH_BYTES" |) - |) in - let cache := + |) + |) in + let _ := M.assign_local (| + "cache" , make_list [ M.call (| M.get_name (| globals, "keccak512" |), @@ -439,7 +480,8 @@ Definition generate_cache : Value.t -> Value.t -> M := ], make_dict [] |) - ] in + ] + |) in let _ := M.for_ (| M.get_name (| globals, "index" |), @@ -452,7 +494,8 @@ Definition generate_cache : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let cache_item := + let _ := M.assign_local (| + "cache_item" , M.call (| M.get_name (| globals, "keccak512" |), make_list [ @@ -465,7 +508,8 @@ Definition generate_cache : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "cache" |), "append" |), make_list [ @@ -501,7 +545,8 @@ Definition generate_cache : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let first_cache_item := + let _ := M.assign_local (| + "first_cache_item" , M.get_subscript (| M.get_name (| globals, "cache" |), BinOp.mod_ (| @@ -520,8 +565,10 @@ Definition generate_cache : Value.t -> Value.t -> M := |), M.get_name (| globals, "cache_size_words" |) |) - |) in - let second_cache_item := + |) + |) in + let _ := M.assign_local (| + "second_cache_item" , M.get_subscript (| M.get_name (| globals, "cache" |), BinOp.mod_ (| @@ -542,15 +589,18 @@ Definition generate_cache : Value.t -> Value.t -> M := |), M.get_name (| globals, "cache_size_words" |) |) - |) in - let result := + |) + |) in + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "bytes" |), make_list [ Constant.str "(* At expr: unsupported node type: ListComp *)" ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_subscript (| M.get_name (| globals, "cache" |), @@ -605,7 +655,8 @@ Definition fnv : Value.t -> Value.t -> M := [FNV]: https://w.wiki/XKZ [FNV-1]: http://www.isthe.com/chongo/tech/comp/fnv/#FNV-1 " in - let result := + let _ := M.assign_local (| + "result" , BinOp.bit_and (| BinOp.bit_xor (| BinOp.mult (| @@ -627,7 +678,8 @@ Definition fnv : Value.t -> Value.t -> M := |) |), M.get_field (| M.get_name (| globals, "U32" |), "MAX_VALUE" |) - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "U32" |), @@ -676,7 +728,8 @@ Definition generate_dataset_item : Value.t -> Value.t -> M := [`generate_dataset`]: ref:ethereum.ethash.generate_dataset [`generate_cache`]: ref:ethereum.ethash.generate_cache " in - let mix := + let _ := M.assign_local (| + "mix" , M.call (| M.get_name (| globals, "keccak512" |), make_list [ @@ -708,15 +761,18 @@ Definition generate_dataset_item : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let mix_integers := + |) + |) in + let _ := M.assign_local (| + "mix_integers" , M.call (| M.get_name (| globals, "le_bytes_to_uint32_sequence" |), make_list [ M.get_name (| globals, "mix" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "j" |), @@ -729,7 +785,8 @@ Definition generate_dataset_item : Value.t -> Value.t -> M := |), ltac:(M.monadic ( (* At stmt: unsupported node type: AnnAssign *) - let cache_index := + let _ := M.assign_local (| + "cache_index" , BinOp.mod_ (| M.call (| M.get_name (| globals, "fnv" |), @@ -749,13 +806,17 @@ Definition generate_dataset_item : Value.t -> Value.t -> M := ], make_dict [] |) - |) in - let parent := + |) + |) in + let _ := M.assign_local (| + "parent" , M.get_subscript (| M.get_name (| globals, "cache" |), M.get_name (| globals, "cache_index" |) - |) in - let mix_integers := + |) + |) in + let _ := M.assign_local (| + "mix_integers" , M.call (| M.get_name (| globals, "fnv_hash" |), make_list [ @@ -763,14 +824,16 @@ Definition generate_dataset_item : Value.t -> Value.t -> M := M.get_name (| globals, "parent" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let mix := + let _ := M.assign_local (| + "mix" , M.call (| M.get_name (| globals, "Hash64" |), make_list [ @@ -783,7 +846,8 @@ Definition generate_dataset_item : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "keccak512" |), @@ -841,7 +905,8 @@ Definition hashimoto : Value.t -> Value.t -> M := [RLP hash]: ref:ethereum.rlp.rlp_hash [`dataset_size`]: ref:ethereum.ethash.dataset_size " in - let nonce_le := + let _ := M.assign_local (| + "nonce_le" , M.call (| M.get_name (| globals, "bytes" |), make_list [ @@ -854,8 +919,10 @@ Definition hashimoto : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let seed_hash := + |) + |) in + let _ := M.assign_local (| + "seed_hash" , M.call (| M.get_name (| globals, "keccak512" |), make_list [ @@ -865,8 +932,10 @@ Definition hashimoto : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let seed_head := + |) + |) in + let _ := M.assign_local (| + "seed_head" , M.call (| M.get_field (| M.get_name (| globals, "U32" |), "from_le_bytes" |), make_list [ @@ -878,13 +947,17 @@ Definition hashimoto : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let rows := + |) + |) in + let _ := M.assign_local (| + "rows" , BinOp.floor_div (| M.get_name (| globals, "dataset_size" |), Constant.int 128 - |) in - let mix := + |) + |) in + let _ := M.assign_local (| + "mix" , BinOp.mult (| M.call (| M.get_name (| globals, "le_bytes_to_uint32_sequence" |), @@ -897,7 +970,8 @@ Definition hashimoto : Value.t -> Value.t -> M := M.get_name (| globals, "MIX_BYTES" |), M.get_name (| globals, "HASH_BYTES" |) |) - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "i" |), @@ -910,7 +984,8 @@ Definition hashimoto : Value.t -> Value.t -> M := |), ltac:(M.monadic ( (* At stmt: unsupported node type: AnnAssign *) - let parent := + let _ := M.assign_local (| + "parent" , BinOp.mod_ (| M.call (| M.get_name (| globals, "fnv" |), @@ -936,7 +1011,8 @@ Definition hashimoto : Value.t -> Value.t -> M := make_dict [] |), M.get_name (| globals, "rows" |) - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "j" |), @@ -951,7 +1027,9 @@ Definition hashimoto : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let new_data := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "new_data", M.call (| M.get_name (| globals, "fetch_dataset_item" |), make_list [ @@ -971,32 +1049,15 @@ Definition hashimoto : Value.t -> Value.t -> M := ], make_dict [] |) - M.call (| - M.get_name (| globals, "fetch_dataset_item" |), - make_list [ - BinOp.add (| - BinOp.mult (| - Constant.int 2, - M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - M.get_name (| globals, "parent" |) - ], - make_dict [] - |) - |), - M.get_name (| globals, "j" |) - |) - ], - make_dict [] - |) in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let mix := + let _ := M.assign_local (| + "mix" , M.call (| M.get_name (| globals, "fnv_hash" |), make_list [ @@ -1004,15 +1065,18 @@ Definition hashimoto : Value.t -> Value.t -> M := M.get_name (| globals, "new_data" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let compressed_mix := - make_list [] in + let _ := M.assign_local (| + "compressed_mix" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "i" |), @@ -1087,15 +1151,18 @@ Definition hashimoto : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let mix_digest := + let _ := M.assign_local (| + "mix_digest" , M.call (| M.get_name (| globals, "le_uint32_sequence_to_bytes" |), make_list [ M.get_name (| globals, "compressed_mix" |) ], make_dict [] - |) in - let result := + |) + |) in + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -1105,7 +1172,8 @@ Definition hashimoto : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| make_tuple [ M.get_name (| globals, "mix_digest" |); M.get_name (| globals, "result" |) ] |) in diff --git a/CoqOfPython/ethereum/fork_criteria.v b/CoqOfPython/ethereum/fork_criteria.v index c3040ca..b4e814f 100644 --- a/CoqOfPython/ethereum/fork_criteria.v +++ b/CoqOfPython/ethereum/fork_criteria.v @@ -19,11 +19,15 @@ Classes for specifying criteria for Mainnet forks. (* At top_level_stmt: unsupported node type: Import *) -Axiom abc_imports : - AreImported globals "abc" [ "ABC"; "abstractmethod" ]. +Axiom abc_imports_ABC : + IsImported globals "abc" "ABC". +Axiom abc_imports_abstractmethod : + IsImported globals "abc" "abstractmethod". -Axiom typing_imports : - AreImported globals "typing" [ "Final"; "Tuple" ]. +Axiom typing_imports_Final : + IsImported globals "typing" "Final". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". Definition ForkCriteria : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/frontier/__init__.v b/CoqOfPython/ethereum/frontier/__init__.v index ba6be25..e30d7e8 100644 --- a/CoqOfPython/ethereum/frontier/__init__.v +++ b/CoqOfPython/ethereum/frontier/__init__.v @@ -7,8 +7,8 @@ Definition expr_1 : Value.t := Frontier is the first production-ready iteration of the Ethereum protocol. ". -Axiom ethereum_fork_criteria_imports : - AreImported globals "ethereum.fork_criteria" [ "ByBlockNumber" ]. +Axiom ethereum_fork_criteria_imports_ByBlockNumber : + IsImported globals "ethereum.fork_criteria" "ByBlockNumber". Definition FORK_CRITERIA : Value.t := M.run ltac:(M.monadic ( M.call (| diff --git a/CoqOfPython/ethereum/frontier/blocks.v b/CoqOfPython/ethereum/frontier/blocks.v index f3822d6..69e273c 100644 --- a/CoqOfPython/ethereum/frontier/blocks.v +++ b/CoqOfPython/ethereum/frontier/blocks.v @@ -14,23 +14,37 @@ history of all state transitions that have happened since the genesis of the chain. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Tuple" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes8"; "Bytes32"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. - -Axiom ethereum_frontier_fork_types_imports : - AreImported globals "ethereum.frontier.fork_types" [ "Address"; "Bloom"; "Root" ]. - -Axiom ethereum_frontier_transactions_imports : - AreImported globals "ethereum.frontier.transactions" [ "Transaction" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes8 : + IsImported globals "ethereum.base_types" "Bytes8". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". + +Axiom ethereum_frontier_fork_types_imports_Address : + IsImported globals "ethereum.frontier.fork_types" "Address". +Axiom ethereum_frontier_fork_types_imports_Bloom : + IsImported globals "ethereum.frontier.fork_types" "Bloom". +Axiom ethereum_frontier_fork_types_imports_Root : + IsImported globals "ethereum.frontier.fork_types" "Root". + +Axiom ethereum_frontier_transactions_imports_Transaction : + IsImported globals "ethereum.frontier.transactions" "Transaction". Definition Header : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/frontier/bloom.v b/CoqOfPython/ethereum/frontier/bloom.v index 1bf769d..c2d4fc3 100644 --- a/CoqOfPython/ethereum/frontier/bloom.v +++ b/CoqOfPython/ethereum/frontier/bloom.v @@ -21,20 +21,20 @@ for efficient searching of logs by address and/or topic, by rapidly eliminating blocks and receipts from their search. ". -Axiom typing_imports : - AreImported globals "typing" [ "Tuple" ]. +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_frontier_blocks_imports : - AreImported globals "ethereum.frontier.blocks" [ "Log" ]. +Axiom ethereum_frontier_blocks_imports_Log : + IsImported globals "ethereum.frontier.blocks" "Log". -Axiom ethereum_frontier_fork_types_imports : - AreImported globals "ethereum.frontier.fork_types" [ "Bloom" ]. +Axiom ethereum_frontier_fork_types_imports_Bloom : + IsImported globals "ethereum.frontier.fork_types" "Bloom". Definition add_to_bloom : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -53,20 +53,23 @@ Definition add_to_bloom : Value.t -> Value.t -> M := bloom_entry : An entry which is to be added to bloom filter. " in - let hash := + let _ := M.assign_local (| + "hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "bloom_entry" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "idx" |), make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ], ltac:(M.monadic ( - let bit_to_set := + let _ := M.assign_local (| + "bit_to_set" , BinOp.bit_and (| M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), @@ -84,18 +87,24 @@ Definition add_to_bloom : Value.t -> Value.t -> M := make_dict [] |), Constant.int 2047 - |) in - let bit_index := + |) + |) in + let _ := M.assign_local (| + "bit_index" , BinOp.sub (| Constant.int 2047, M.get_name (| globals, "bit_to_set" |) - |) in - let byte_index := + |) + |) in + let _ := M.assign_local (| + "byte_index" , BinOp.floor_div (| M.get_name (| globals, "bit_index" |), Constant.int 8 - |) in - let bit_value := + |) + |) in + let _ := M.assign_local (| + "bit_value" , BinOp.l_shift (| Constant.int 1, BinOp.sub (| @@ -105,7 +114,8 @@ Definition add_to_bloom : Value.t -> Value.t -> M := Constant.int 8 |) |) - |) in + |) + |) in let _ := M.assign (| M.get_subscript (| M.get_name (| globals, "bloom" |), diff --git a/CoqOfPython/ethereum/frontier/fork.v b/CoqOfPython/ethereum/frontier/fork.v index 031f860..ca8bfdb 100644 --- a/CoqOfPython/ethereum/frontier/fork.v +++ b/CoqOfPython/ethereum/frontier/fork.v @@ -17,59 +17,115 @@ Introduction Entry point for the Ethereum specification. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple" ]. - -Axiom ethereum_crypto_elliptic_curve_imports : - AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. - -Axiom ethereum_ethash_imports : - AreImported globals "ethereum.ethash" [ "dataset_size"; "generate_cache"; "hashimoto_light" ]. - -Axiom ethereum_exceptions_imports : - AreImported globals "ethereum.exceptions" [ "InvalidBlock" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U64"; "U256"; "U256_CEIL_VALUE"; "Bytes"; "Bytes32"; "Uint" ]. - -Axiom ethereum_frontier_imports : - AreImported globals "ethereum.frontier" [ "vm" ]. - -Axiom ethereum_frontier_blocks_imports : - AreImported globals "ethereum.frontier.blocks" [ "Block"; "Header"; "Log"; "Receipt" ]. - -Axiom ethereum_frontier_bloom_imports : - AreImported globals "ethereum.frontier.bloom" [ "logs_bloom" ]. - -Axiom ethereum_frontier_fork_types_imports : - AreImported globals "ethereum.frontier.fork_types" [ "Address"; "Bloom"; "Root" ]. - -Axiom ethereum_frontier_state_imports : - AreImported globals "ethereum.frontier.state" [ "State"; "create_ether"; "destroy_account"; "get_account"; "increment_nonce"; "set_account_balance"; "state_root" ]. - -Axiom ethereum_frontier_transactions_imports : - AreImported globals "ethereum.frontier.transactions" [ "TX_BASE_COST"; "TX_DATA_COST_PER_NON_ZERO"; "TX_DATA_COST_PER_ZERO"; "Transaction" ]. - -Axiom ethereum_frontier_trie_imports : - AreImported globals "ethereum.frontier.trie" [ "Trie"; "root"; "trie_set" ]. - -Axiom ethereum_frontier_utils_message_imports : - AreImported globals "ethereum.frontier.utils.message" [ "prepare_message" ]. - -Axiom ethereum_frontier_vm_interpreter_imports : - AreImported globals "ethereum.frontier.vm.interpreter" [ "process_message_call" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". + +Axiom ethereum_crypto_elliptic_curve_imports_SECP256K1N : + IsImported globals "ethereum.crypto.elliptic_curve" "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_imports_secp256k1_recover : + IsImported globals "ethereum.crypto.elliptic_curve" "secp256k1_recover". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". + +Axiom ethereum_ethash_imports_dataset_size : + IsImported globals "ethereum.ethash" "dataset_size". +Axiom ethereum_ethash_imports_generate_cache : + IsImported globals "ethereum.ethash" "generate_cache". +Axiom ethereum_ethash_imports_hashimoto_light : + IsImported globals "ethereum.ethash" "hashimoto_light". + +Axiom ethereum_exceptions_imports_InvalidBlock : + IsImported globals "ethereum.exceptions" "InvalidBlock". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U64 : + IsImported globals "ethereum.base_types" "U64". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_U256_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U256_CEIL_VALUE". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_frontier_imports_vm : + IsImported globals "ethereum.frontier" "vm". + +Axiom ethereum_frontier_blocks_imports_Block : + IsImported globals "ethereum.frontier.blocks" "Block". +Axiom ethereum_frontier_blocks_imports_Header : + IsImported globals "ethereum.frontier.blocks" "Header". +Axiom ethereum_frontier_blocks_imports_Log : + IsImported globals "ethereum.frontier.blocks" "Log". +Axiom ethereum_frontier_blocks_imports_Receipt : + IsImported globals "ethereum.frontier.blocks" "Receipt". + +Axiom ethereum_frontier_bloom_imports_logs_bloom : + IsImported globals "ethereum.frontier.bloom" "logs_bloom". + +Axiom ethereum_frontier_fork_types_imports_Address : + IsImported globals "ethereum.frontier.fork_types" "Address". +Axiom ethereum_frontier_fork_types_imports_Bloom : + IsImported globals "ethereum.frontier.fork_types" "Bloom". +Axiom ethereum_frontier_fork_types_imports_Root : + IsImported globals "ethereum.frontier.fork_types" "Root". + +Axiom ethereum_frontier_state_imports_State : + IsImported globals "ethereum.frontier.state" "State". +Axiom ethereum_frontier_state_imports_create_ether : + IsImported globals "ethereum.frontier.state" "create_ether". +Axiom ethereum_frontier_state_imports_destroy_account : + IsImported globals "ethereum.frontier.state" "destroy_account". +Axiom ethereum_frontier_state_imports_get_account : + IsImported globals "ethereum.frontier.state" "get_account". +Axiom ethereum_frontier_state_imports_increment_nonce : + IsImported globals "ethereum.frontier.state" "increment_nonce". +Axiom ethereum_frontier_state_imports_set_account_balance : + IsImported globals "ethereum.frontier.state" "set_account_balance". +Axiom ethereum_frontier_state_imports_state_root : + IsImported globals "ethereum.frontier.state" "state_root". + +Axiom ethereum_frontier_transactions_imports_TX_BASE_COST : + IsImported globals "ethereum.frontier.transactions" "TX_BASE_COST". +Axiom ethereum_frontier_transactions_imports_TX_DATA_COST_PER_NON_ZERO : + IsImported globals "ethereum.frontier.transactions" "TX_DATA_COST_PER_NON_ZERO". +Axiom ethereum_frontier_transactions_imports_TX_DATA_COST_PER_ZERO : + IsImported globals "ethereum.frontier.transactions" "TX_DATA_COST_PER_ZERO". +Axiom ethereum_frontier_transactions_imports_Transaction : + IsImported globals "ethereum.frontier.transactions" "Transaction". + +Axiom ethereum_frontier_trie_imports_Trie : + IsImported globals "ethereum.frontier.trie" "Trie". +Axiom ethereum_frontier_trie_imports_root : + IsImported globals "ethereum.frontier.trie" "root". +Axiom ethereum_frontier_trie_imports_trie_set : + IsImported globals "ethereum.frontier.trie" "trie_set". + +Axiom ethereum_frontier_utils_message_imports_prepare_message : + IsImported globals "ethereum.frontier.utils.message" "prepare_message". + +Axiom ethereum_frontier_vm_interpreter_imports_process_message_call : + IsImported globals "ethereum.frontier.vm.interpreter" "process_message_call". Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -167,13 +223,15 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := recent_block_hashes : `List[Hash32]` Hashes of the recent 256 blocks in order of increasing block number. " in - let recent_blocks := + let _ := M.assign_local (| + "recent_blocks" , M.slice (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |), Constant.None_, Constant.None_ - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -197,15 +255,19 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let recent_block_hashes := - make_list [] in + let _ := M.assign_local (| + "recent_block_hashes" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "block" |), M.get_name (| globals, "recent_blocks" |), ltac:(M.monadic ( - let prev_block_hash := - M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in + let _ := M.assign_local (| + "prev_block_hash" , + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), make_list [ @@ -219,7 +281,8 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let most_recent_block_hash := + let _ := M.assign_local (| + "most_recent_block_hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -235,7 +298,8 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), make_list [ @@ -272,11 +336,13 @@ Definition state_transition : Value.t -> Value.t -> M := block : Block to apply to `chain`. " in - let parent_header := + let _ := M.assign_local (| + "parent_header" , M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 1 |) - |), "header" |) in + |), "header" |) + |) in let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ @@ -294,7 +360,8 @@ Definition state_transition : Value.t -> Value.t -> M := ], make_dict [] |) in - let apply_body_output := + let _ := M.assign_local (| + "apply_body_output" , M.call (| M.get_name (| globals, "apply_body" |), make_list [ @@ -315,7 +382,8 @@ Definition state_transition : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "block" |), "ommers" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -486,7 +554,8 @@ Definition validate_header : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_difficulty := + let _ := M.assign_local (| + "block_difficulty" , M.call (| M.get_name (| globals, "calculate_block_difficulty" |), make_list [ @@ -496,7 +565,8 @@ Definition validate_header : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "parent_header" |), "difficulty" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -508,7 +578,8 @@ Definition validate_header : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_parent_hash := + let _ := M.assign_local (| + "block_parent_hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -521,7 +592,8 @@ Definition validate_header : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -567,7 +639,8 @@ Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := hash : `Hash32` The PoW valid rlp hash of the passed in header. " in - let header_data_without_pow_artefacts := + let _ := M.assign_local (| + "header_data_without_pow_artefacts" , make_list [ M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |); M.get_field (| M.get_name (| globals, "header" |), "ommers_hash" |); @@ -582,7 +655,8 @@ Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "header" |), "gas_used" |); M.get_field (| M.get_name (| globals, "header" |), "timestamp" |); M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) - ] in + ] + |) in let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), @@ -611,22 +685,26 @@ Definition validate_proof_of_work : Value.t -> Value.t -> M := header : Header of interest. " in - let header_hash := + let _ := M.assign_local (| + "header_hash" , M.call (| M.get_name (| globals, "generate_header_hash_for_pow" |), make_list [ M.get_name (| globals, "header" |) ], make_dict [] - |) in - let cache := + |) + |) in + let _ := M.assign_local (| + "cache" , M.call (| M.get_name (| globals, "generate_cache" |), make_list [ M.get_field (| M.get_name (| globals, "header" |), "number" |) ], make_dict [] - |) in + |) + |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "mix_digest" |); M.get_name (| globals, "result" |) ], M.call (| @@ -713,14 +791,16 @@ Definition check_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_address := + let _ := M.assign_local (| + "sender_address" , M.call (| M.get_name (| globals, "recover_sender" |), make_list [ M.get_name (| globals, "tx" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "sender_address" |) |) in @@ -749,12 +829,14 @@ Definition make_receipt : Value.t -> Value.t -> M := receipt : The receipt for the transaction. " in - let receipt := + let _ := M.assign_local (| + "receipt" , M.call (| M.get_name (| globals, "Receipt" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "receipt" |) |) in @@ -811,8 +893,10 @@ Definition apply_body : Value.t -> Value.t -> M := apply_body_output : `ApplyBodyOutput` Output of applying the block body to the state. " in - let gas_available := - M.get_name (| globals, "block_gas_limit" |) in + let _ := M.assign_local (| + "gas_available" , + M.get_name (| globals, "block_gas_limit" |) + |) in (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) @@ -848,7 +932,8 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_address := + let _ := M.assign_local (| + "sender_address" , M.call (| M.get_name (| globals, "check_transaction" |), make_list [ @@ -856,13 +941,16 @@ Definition apply_body : Value.t -> Value.t -> M := M.get_name (| globals, "gas_available" |) ], make_dict [] - |) in - let env := + |) + |) in + let _ := M.assign_local (| + "env" , M.call (| M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |) ], M.call (| @@ -874,10 +962,13 @@ Definition apply_body : Value.t -> Value.t -> M := make_dict [] |) |) in - let gas_available := BinOp.sub + let _ := M.assign_op_local (| + BinOp.sub, + "gas_available", M.get_name (| globals, "gas_used" |) - M.get_name (| globals, "gas_used" |) in - let receipt := + |) in + let _ := M.assign_local (| + "receipt" , M.call (| M.get_name (| globals, "make_receipt" |), make_list [ @@ -896,7 +987,8 @@ Definition apply_body : Value.t -> Value.t -> M := M.get_name (| globals, "logs" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ @@ -918,9 +1010,11 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_logs := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "block_logs", M.get_name (| globals, "logs" |) - M.get_name (| globals, "logs" |) in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -937,19 +1031,23 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_gas_used := + let _ := M.assign_local (| + "block_gas_used" , BinOp.sub (| M.get_name (| globals, "block_gas_limit" |), M.get_name (| globals, "gas_available" |) - |) in - let block_logs_bloom := + |) + |) in + let _ := M.assign_local (| + "block_logs_bloom" , M.call (| M.get_name (| globals, "logs_bloom" |), make_list [ M.get_name (| globals, "block_logs" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ApplyBodyOutput" |), @@ -1007,14 +1105,16 @@ Definition validate_ommers : Value.t -> Value.t -> M := chain : History and current state. " in - let block_hash := + let _ := M.assign_local (| + "block_hash" , M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), make_list [ M.get_name (| globals, "block_header" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1079,7 +1179,8 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_parent_header := + let _ := M.assign_local (| + "ommer_parent_header" , M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), BinOp.sub (| @@ -1089,7 +1190,8 @@ Definition validate_ommers : Value.t -> Value.t -> M := |) |), Constant.int 1 |) - |), "header" |) in + |), "header" |) + |) in let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ @@ -1121,8 +1223,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommers_hashes := - Constant.str "(* At expr: unsupported node type: ListComp *)" in + let _ := M.assign_local (| + "ommers_hashes" , + Constant.str "(* At expr: unsupported node type: ListComp *)" + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1152,7 +1256,8 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let recent_canonical_blocks := + let _ := M.assign_local (| + "recent_canonical_blocks" , M.slice (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| BinOp.add (| @@ -1161,23 +1266,28 @@ Definition validate_ommers : Value.t -> Value.t -> M := |) |), Constant.None_, Constant.None_ - |) in - let recent_canonical_block_hashes := - Constant.str "(* At expr: unsupported node type: SetComp *)" in + |) + |) in + let _ := M.assign_local (| + "recent_canonical_block_hashes" , + Constant.str "(* At expr: unsupported node type: SetComp *)" + |) in (* At stmt: unsupported node type: AnnAssign *) let _ := M.for_ (| M.get_name (| globals, "block" |), M.get_name (| globals, "recent_canonical_blocks" |), ltac:(M.monadic ( - let recent_ommers_hashes := + let _ := M.assign_local (| + "recent_ommers_hashes" , M.call (| M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), make_list [ Constant.str "(* At expr: unsupported node type: SetComp *)" ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -1195,11 +1305,13 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let ommer_hash := + let _ := M.assign_local (| + "ommer_hash" , M.get_subscript (| M.get_name (| globals, "ommers_hashes" |), M.get_name (| globals, "ommer_index" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1233,11 +1345,13 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_age := + let _ := M.assign_local (| + "ommer_age" , BinOp.sub (| M.get_field (| M.get_name (| globals, "block_header" |), "number" |), M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1315,7 +1429,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := ommers : List of ommers mentioned in the current block. " in - let miner_reward := + let _ := M.assign_local (| + "miner_reward" , BinOp.add (| M.get_name (| globals, "BLOCK_REWARD" |), BinOp.mult (| @@ -1331,7 +1446,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := Constant.int 32 |) |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "create_ether" |), make_list [ @@ -1346,7 +1462,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := M.get_name (| globals, "ommer" |), M.get_name (| globals, "ommers" |), ltac:(M.monadic ( - let ommer_age := + let _ := M.assign_local (| + "ommer_age" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -1356,8 +1473,10 @@ Definition pay_rewards : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let ommer_miner_reward := + |) + |) in + let _ := M.assign_local (| + "ommer_miner_reward" , BinOp.floor_div (| BinOp.mult (| BinOp.sub (| @@ -1367,7 +1486,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := M.get_name (| globals, "BLOCK_REWARD" |) |), Constant.int 8 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "create_ether" |), make_list [ @@ -1428,9 +1548,12 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender := - M.get_field (| M.get_name (| globals, "env" |), "origin" |) in - let sender_account := + let _ := M.assign_local (| + "sender" , + M.get_field (| M.get_name (| globals, "env" |), "origin" |) + |) in + let _ := M.assign_local (| + "sender_account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1438,12 +1561,15 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "sender" |) ], make_dict [] - |) in - let gas_fee := + |) + |) in + let _ := M.assign_local (| + "gas_fee" , BinOp.mult (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1484,7 +1610,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let gas := + let _ := M.assign_local (| + "gas" , BinOp.sub (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.call (| @@ -1494,7 +1621,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "increment_nonce" |), make_list [ @@ -1503,11 +1631,13 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_balance_after_gas_fee := + let _ := M.assign_local (| + "sender_balance_after_gas_fee" , BinOp.sub (| M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), M.get_name (| globals, "gas_fee" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -1517,7 +1647,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let message := + let _ := M.assign_local (| + "message" , M.call (| M.get_name (| globals, "prepare_message" |), make_list [ @@ -1529,8 +1660,10 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in - let output := + |) + |) in + let _ := M.assign_local (| + "output" , M.call (| M.get_name (| globals, "process_message_call" |), make_list [ @@ -1538,13 +1671,17 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in - let gas_used := + |) + |) in + let _ := M.assign_local (| + "gas_used" , BinOp.sub (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_field (| M.get_name (| globals, "output" |), "gas_left" |) - |) in - let gas_refund := + |) + |) in + let _ := M.assign_local (| + "gas_refund" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -1555,16 +1692,20 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "output" |), "refund_counter" |) ], make_dict [] - |) in - let gas_refund_amount := + |) + |) in + let _ := M.assign_local (| + "gas_refund_amount" , BinOp.mult (| BinOp.add (| M.get_field (| M.get_name (| globals, "output" |), "gas_left" |), M.get_name (| globals, "gas_refund" |) |), M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) - |) in - let transaction_fee := + |) + |) in + let _ := M.assign_local (| + "transaction_fee" , BinOp.mult (| BinOp.sub (| BinOp.sub (| @@ -1574,13 +1715,17 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "gas_refund" |) |), M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) - |) in - let total_gas_used := + |) + |) in + let _ := M.assign_local (| + "total_gas_used" , BinOp.sub (| M.get_name (| globals, "gas_used" |), M.get_name (| globals, "gas_refund" |) - |) in - let sender_balance_after_refund := + |) + |) in + let _ := M.assign_local (| + "sender_balance_after_refund" , BinOp.add (| M.get_field (| M.call (| M.get_name (| globals, "get_account" |), @@ -1591,7 +1736,8 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |), "balance" |), M.get_name (| globals, "gas_refund_amount" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -1601,7 +1747,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let coinbase_balance_after_mining_fee := + let _ := M.assign_local (| + "coinbase_balance_after_mining_fee" , BinOp.add (| M.get_field (| M.call (| M.get_name (| globals, "get_account" |), @@ -1612,7 +1759,8 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |), "balance" |), M.get_name (| globals, "transaction_fee" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -1726,8 +1874,10 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := verified : `ethereum.base_types.Uint` The intrinsic cost of the transaction. " in - let data_cost := - Constant.int 0 in + let _ := M.assign_local (| + "data_cost" , + Constant.int 0 + |) in let _ := M.for_ (| M.get_name (| globals, "byte" |), @@ -1742,15 +1892,19 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let data_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "data_cost", M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let data_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "data_cost", M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -1856,7 +2010,8 @@ Definition recover_sender : Value.t -> Value.t -> M := ], make_dict [] |) in - let public_key := + let _ := M.assign_local (| + "public_key" , M.call (| M.get_name (| globals, "secp256k1_recover" |), make_list [ @@ -1875,7 +2030,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Address" |), @@ -2016,11 +2172,13 @@ Definition check_gas_limit : Value.t -> Value.t -> M := check : `bool` True if gas limit constraints are satisfied, False otherwise. " in - let max_adjustment_delta := + let _ := M.assign_local (| + "max_adjustment_delta" , BinOp.floor_div (| M.get_name (| globals, "parent_gas_limit" |), M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -2115,7 +2273,8 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := difficulty : `ethereum.base_types.Uint` Computed difficulty for a block. " in - let max_adjustment_delta := + let _ := M.assign_local (| + "max_adjustment_delta" , BinOp.floor_div (| M.get_name (| globals, "parent_difficulty" |), M.call (| @@ -2125,7 +2284,8 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := ], make_dict [] |) - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -2138,22 +2298,27 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let difficulty := + let _ := M.assign_local (| + "difficulty" , BinOp.add (| M.get_name (| globals, "parent_difficulty" |), M.get_name (| globals, "max_adjustment_delta" |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let difficulty := + let _ := M.assign_local (| + "difficulty" , BinOp.sub (| M.get_name (| globals, "parent_difficulty" |), M.get_name (| globals, "max_adjustment_delta" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in - let num_bomb_periods := + let _ := M.assign_local (| + "num_bomb_periods" , BinOp.sub (| BinOp.floor_div (| M.call (| @@ -2166,7 +2331,8 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := Constant.int 100000 |), Constant.int 2 - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -2176,15 +2342,14 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let difficulty := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "difficulty", BinOp.pow (| Constant.int 2, M.get_name (| globals, "num_bomb_periods" |) |) - BinOp.pow (| - Constant.int 2, - M.get_name (| globals, "num_bomb_periods" |) - |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/frontier/fork_types.v b/CoqOfPython/ethereum/frontier/fork_types.v index 46b00d0..1b8eb64 100644 --- a/CoqOfPython/ethereum/frontier/fork_types.v +++ b/CoqOfPython/ethereum/frontier/fork_types.v @@ -17,17 +17,29 @@ Introduction Types re-used throughout the specification, which are specific to Ethereum. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes20"; "Bytes256"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes20 : + IsImported globals "ethereum.base_types" "Bytes20". +Axiom ethereum_base_types_imports_Bytes256 : + IsImported globals "ethereum.base_types" "Bytes256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) diff --git a/CoqOfPython/ethereum/frontier/state.v b/CoqOfPython/ethereum/frontier/state.v index 69597ae..4e111a2 100644 --- a/CoqOfPython/ethereum/frontier/state.v +++ b/CoqOfPython/ethereum/frontier/state.v @@ -22,23 +22,55 @@ There is a distinction between an account that does not exist and `EMPTY_ACCOUNT`. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass"; "field" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict"; "List"; "Optional"; "Tuple" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "modify" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_frontier_fork_types_imports : - AreImported globals "ethereum.frontier.fork_types" [ "EMPTY_ACCOUNT"; "Account"; "Address"; "Root" ]. - -Axiom ethereum_frontier_trie_imports : - AreImported globals "ethereum.frontier.trie" [ "EMPTY_TRIE_ROOT"; "Trie"; "copy_trie"; "root"; "trie_get"; "trie_set" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". +Axiom dataclasses_imports_field : + IsImported globals "dataclasses" "field". + +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_modify : + IsImported globals "ethereum.base_types" "modify". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_frontier_fork_types_imports_EMPTY_ACCOUNT : + IsImported globals "ethereum.frontier.fork_types" "EMPTY_ACCOUNT". +Axiom ethereum_frontier_fork_types_imports_Account : + IsImported globals "ethereum.frontier.fork_types" "Account". +Axiom ethereum_frontier_fork_types_imports_Address : + IsImported globals "ethereum.frontier.fork_types" "Address". +Axiom ethereum_frontier_fork_types_imports_Root : + IsImported globals "ethereum.frontier.fork_types" "Root". + +Axiom ethereum_frontier_trie_imports_EMPTY_TRIE_ROOT : + IsImported globals "ethereum.frontier.trie" "EMPTY_TRIE_ROOT". +Axiom ethereum_frontier_trie_imports_Trie : + IsImported globals "ethereum.frontier.trie" "Trie". +Axiom ethereum_frontier_trie_imports_copy_trie : + IsImported globals "ethereum.frontier.trie" "copy_trie". +Axiom ethereum_frontier_trie_imports_root : + IsImported globals "ethereum.frontier.trie" "root". +Axiom ethereum_frontier_trie_imports_trie_get : + IsImported globals "ethereum.frontier.trie" "trie_get". +Axiom ethereum_frontier_trie_imports_trie_set : + IsImported globals "ethereum.frontier.trie" "trie_set". Definition State : Value.t := builtins.make_klass @@ -153,7 +185,8 @@ Definition get_account : Value.t -> Value.t -> M := account : `Account` Account at address. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account_optional" |), make_list [ @@ -161,7 +194,8 @@ Definition get_account : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -207,7 +241,8 @@ Definition get_account_optional : Value.t -> Value.t -> M := account : `Account` Account at address. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "trie_get" |), make_list [ @@ -215,7 +250,8 @@ Definition get_account_optional : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "account" |) |) in @@ -338,14 +374,16 @@ Definition get_storage : Value.t -> Value.t -> M := value : `U256` Value at the key. " in - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -369,7 +407,8 @@ Definition get_storage : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "trie_get" |), make_list [ @@ -377,7 +416,8 @@ Definition get_storage : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -420,14 +460,16 @@ Definition set_storage : Value.t -> Value.t -> M := |), Constant.None_ |) |) in - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -437,12 +479,14 @@ Definition set_storage : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_name (| globals, "Trie" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), @@ -469,7 +513,7 @@ Definition set_storage : Value.t -> Value.t -> M := M.if_then_else (| Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), - {} + Constant.str "(* At expr: unsupported node type: Dict *)" |), (* then *) ltac:(M.monadic ( @@ -615,7 +659,8 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := True if if an account has non zero nonce or non empty code, False otherwise. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -623,7 +668,8 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| BoolOp.or (| Compare.not_eq (| diff --git a/CoqOfPython/ethereum/frontier/transactions.v b/CoqOfPython/ethereum/frontier/transactions.v index 16a12e0..1c30efa 100644 --- a/CoqOfPython/ethereum/frontier/transactions.v +++ b/CoqOfPython/ethereum/frontier/transactions.v @@ -9,17 +9,25 @@ submitted to be executed. If Ethereum is viewed as a state machine, transactions are the events that move between states. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Union" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_frontier_fork_types_imports : - AreImported globals "ethereum.frontier.fork_types" [ "Address" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_Union : + IsImported globals "typing" "Union". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_frontier_fork_types_imports_Address : + IsImported globals "ethereum.frontier.fork_types" "Address". Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( Constant.int 21000 diff --git a/CoqOfPython/ethereum/frontier/trie.v b/CoqOfPython/ethereum/frontier/trie.v index fad3922..f92e8c5 100644 --- a/CoqOfPython/ethereum/frontier/trie.v +++ b/CoqOfPython/ethereum/frontier/trie.v @@ -20,35 +20,69 @@ The state trie is the structure responsible for storing (* At top_level_stmt: unsupported node type: Import *) -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass"; "field" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict"; "Generic"; "List"; "Mapping"; "MutableMapping"; "Optional"; "Sequence"; "TypeVar"; "Union"; "cast" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_utils_hexadecimal_imports : - AreImported globals "ethereum.utils.hexadecimal" [ "hex_to_bytes" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_frontier_blocks_imports : - AreImported globals "ethereum.frontier.blocks" [ "Receipt" ]. - -Axiom ethereum_frontier_fork_types_imports : - AreImported globals "ethereum.frontier.fork_types" [ "Account"; "Address"; "Root"; "encode_account" ]. - -Axiom ethereum_frontier_transactions_imports : - AreImported globals "ethereum.frontier.transactions" [ "Transaction" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". +Axiom dataclasses_imports_field : + IsImported globals "dataclasses" "field". + +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". +Axiom typing_imports_Generic : + IsImported globals "typing" "Generic". +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Mapping : + IsImported globals "typing" "Mapping". +Axiom typing_imports_MutableMapping : + IsImported globals "typing" "MutableMapping". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Sequence : + IsImported globals "typing" "Sequence". +Axiom typing_imports_TypeVar : + IsImported globals "typing" "TypeVar". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". +Axiom typing_imports_cast : + IsImported globals "typing" "cast". + +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_utils_hexadecimal_imports_hex_to_bytes : + IsImported globals "ethereum.utils.hexadecimal" "hex_to_bytes". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_frontier_blocks_imports_Receipt : + IsImported globals "ethereum.frontier.blocks" "Receipt". + +Axiom ethereum_frontier_fork_types_imports_Account : + IsImported globals "ethereum.frontier.fork_types" "Account". +Axiom ethereum_frontier_fork_types_imports_Address : + IsImported globals "ethereum.frontier.fork_types" "Address". +Axiom ethereum_frontier_fork_types_imports_Root : + IsImported globals "ethereum.frontier.fork_types" "Root". +Axiom ethereum_frontier_fork_types_imports_encode_account : + IsImported globals "ethereum.frontier.fork_types" "encode_account". + +Axiom ethereum_frontier_transactions_imports_Transaction : + IsImported globals "ethereum.frontier.transactions" "Transaction". Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -158,7 +192,7 @@ Definition encode_internal_node : Value.t -> Value.t -> M := when serialized. This function also accepts `None`, representing the absence of a node, - which is encoded to `b""""""`. + which is encoded to `b""""`. Parameters ---------- @@ -180,8 +214,10 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := - Constant.bytes "" in + let _ := M.assign_local (| + "unencoded" , + Constant.bytes "" + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -198,7 +234,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := + let _ := M.assign_local (| + "unencoded" , make_tuple [ M.call (| M.get_name (| globals, "nibble_list_to_compact" |), make_list [ @@ -206,7 +243,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := Constant.bool true ], make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in + |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -223,7 +261,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := + let _ := M.assign_local (| + "unencoded" , make_tuple [ M.call (| M.get_name (| globals, "nibble_list_to_compact" |), make_list [ @@ -231,7 +270,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := Constant.bool false ], make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in + |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -248,13 +288,15 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := + let _ := M.assign_local (| + "unencoded" , BinOp.add (| M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), make_list [ M.get_field (| M.get_name (| globals, "node" |), "value" |) ] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -273,14 +315,16 @@ Definition encode_internal_node : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - let encoded := + let _ := M.assign_local (| + "encoded" , M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), make_list [ M.get_name (| globals, "unencoded" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -669,12 +713,14 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := compressed : `bytearray` Compact byte array. " in - let compact := + let _ := M.assign_local (| + "compact" , M.call (| M.get_name (| globals, "bytearray" |), make_list [], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -854,7 +900,8 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := nibble_list : `Bytes` The `Bytes` in nibble-list format. " in - let nibble_list := + let _ := M.assign_local (| + "nibble_list" , M.call (| M.get_name (| globals, "bytearray" |), make_list [ @@ -870,7 +917,8 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ], @@ -978,15 +1026,18 @@ Definition _prepare_trie : Value.t -> Value.t -> M := M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "Address" |), make_list [ M.get_name (| globals, "preimage" |) ], make_dict [] - |) in - let encoded_value := + |) + |) in + let _ := M.assign_local (| + "encoded_value" , M.call (| M.get_name (| globals, "encode_node" |), make_list [ @@ -1000,18 +1051,21 @@ Definition _prepare_trie : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let encoded_value := + let _ := M.assign_local (| + "encoded_value" , M.call (| M.get_name (| globals, "encode_node" |), make_list [ M.get_name (| globals, "value" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -1032,19 +1086,23 @@ Definition _prepare_trie : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "trie" |), "secured" |), (* then *) ltac:(M.monadic ( - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "preimage" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let key := - M.get_name (| globals, "preimage" |) in + let _ := M.assign_local (| + "key" , + M.get_name (| globals, "preimage" |) + |) in M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -1091,7 +1149,8 @@ Definition root : Value.t -> Value.t -> M := root : `.fork_types.Root` MPT root of the underlying key-value pairs. " in - let obj := + let _ := M.assign_local (| + "obj" , M.call (| M.get_name (| globals, "_prepare_trie" |), make_list [ @@ -1099,8 +1158,10 @@ Definition root : Value.t -> Value.t -> M := M.get_name (| globals, "get_storage_root" |) ], make_dict [] - |) in - let root_node := + |) + |) in + let _ := M.assign_local (| + "root_node" , M.call (| M.get_name (| globals, "encode_internal_node" |), make_list [ @@ -1120,7 +1181,8 @@ Definition root : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1225,7 +1287,8 @@ Definition patricialize : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let arbitrary_key := + let _ := M.assign_local (| + "arbitrary_key" , M.call (| M.get_name (| globals, "next" |), make_list [ @@ -1238,7 +1301,8 @@ Definition patricialize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1254,7 +1318,8 @@ Definition patricialize : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let leaf := + let _ := M.assign_local (| + "leaf" , M.call (| M.get_name (| globals, "LeafNode" |), make_list [ @@ -1270,7 +1335,8 @@ Definition patricialize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "leaf" |) |) in @@ -1279,27 +1345,32 @@ Definition patricialize : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let substring := + let _ := M.assign_local (| + "substring" , M.slice (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |), Constant.None_, Constant.None_ - |) in - let prefix_length := + |) + |) in + let _ := M.assign_local (| + "prefix_length" , M.call (| M.get_name (| globals, "len" |), make_list [ M.get_name (| globals, "substring" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "key" |), M.get_name (| globals, "obj" |), ltac:(M.monadic ( - let prefix_length := + let _ := M.assign_local (| + "prefix_length" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -1319,7 +1390,8 @@ Definition patricialize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1350,7 +1422,8 @@ Definition patricialize : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let prefix := + let _ := M.assign_local (| + "prefix" , M.slice (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |), @@ -1359,7 +1432,8 @@ Definition patricialize : Value.t -> Value.t -> M := M.get_name (| globals, "prefix_length" |) |), Constant.None_ - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ExtensionNode" |), @@ -1406,7 +1480,7 @@ Definition patricialize : Value.t -> Value.t -> M := let _ := M.call (| M.get_field (| M.get_name (| globals, "branches" |), "append" |), make_list [ - {} + Constant.str "(* At expr: unsupported node type: Dict *)" ], make_dict [] |) in @@ -1416,8 +1490,10 @@ Definition patricialize : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let value := - Constant.bytes "" in + let _ := M.assign_local (| + "value" , + Constant.bytes "" + |) in let _ := M.for_ (| M.get_name (| globals, "key" |), @@ -1460,11 +1536,13 @@ Definition patricialize : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let value := + let _ := M.assign_local (| + "value" , M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/frontier/utils/address.v b/CoqOfPython/ethereum/frontier/utils/address.v index fe329d1..2fdbc8d 100644 --- a/CoqOfPython/ethereum/frontier/utils/address.v +++ b/CoqOfPython/ethereum/frontier/utils/address.v @@ -17,23 +17,25 @@ Introduction Address specific functions used in this frontier version of specification. ". -Axiom typing_imports : - AreImported globals "typing" [ "Union" ]. +Axiom typing_imports_Union : + IsImported globals "typing" "Union". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_left_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "left_pad_zero_bytes". -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". -Axiom ethereum_frontier_fork_types_imports : - AreImported globals "ethereum.frontier.fork_types" [ "Address" ]. +Axiom ethereum_frontier_fork_types_imports_Address : + IsImported globals "ethereum.frontier.fork_types" "Address". Definition to_address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -90,7 +92,8 @@ Definition compute_contract_address : Value.t -> Value.t -> M := address: `ethereum.frontier.fork_types.Address` The computed address of the new account. " in - let computed_address := + let _ := M.assign_local (| + "computed_address" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -106,15 +109,19 @@ Definition compute_contract_address : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let canonical_address := + |) + |) in + let _ := M.assign_local (| + "canonical_address" , M.slice (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |), Constant.None_, Constant.None_ - |) in - let padded_address := + |) + |) in + let _ := M.assign_local (| + "padded_address" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -122,7 +129,8 @@ Definition compute_contract_address : Value.t -> Value.t -> M := Constant.int 20 ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Address" |), diff --git a/CoqOfPython/ethereum/frontier/utils/hexadecimal.v b/CoqOfPython/ethereum/frontier/utils/hexadecimal.v index 799670c..865d427 100644 --- a/CoqOfPython/ethereum/frontier/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/frontier/utils/hexadecimal.v @@ -18,11 +18,15 @@ Hexadecimal utility functions used in this specification, specific to Frontier types. ". -Axiom ethereum_utils_hexadecimal_imports : - AreImported globals "ethereum.utils.hexadecimal" [ "remove_hex_prefix" ]. - -Axiom ethereum_frontier_fork_types_imports : - AreImported globals "ethereum.frontier.fork_types" [ "Address"; "Bloom"; "Root" ]. +Axiom ethereum_utils_hexadecimal_imports_remove_hex_prefix : + IsImported globals "ethereum.utils.hexadecimal" "remove_hex_prefix". + +Axiom ethereum_frontier_fork_types_imports_Address : + IsImported globals "ethereum.frontier.fork_types" "Address". +Axiom ethereum_frontier_fork_types_imports_Bloom : + IsImported globals "ethereum.frontier.fork_types" "Bloom". +Axiom ethereum_frontier_fork_types_imports_Root : + IsImported globals "ethereum.frontier.fork_types" "Root". Definition hex_to_root : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/frontier/utils/message.v b/CoqOfPython/ethereum/frontier/utils/message.v index ca8fa8c..6d47416 100644 --- a/CoqOfPython/ethereum/frontier/utils/message.v +++ b/CoqOfPython/ethereum/frontier/utils/message.v @@ -17,23 +17,33 @@ Introduction Message specific functions used in this frontier version of specification. ". -Axiom typing_imports : - AreImported globals "typing" [ "Optional"; "Union" ]. +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_frontier_fork_types_imports : - AreImported globals "ethereum.frontier.fork_types" [ "Address" ]. +Axiom ethereum_frontier_fork_types_imports_Address : + IsImported globals "ethereum.frontier.fork_types" "Address". -Axiom ethereum_frontier_state_imports : - AreImported globals "ethereum.frontier.state" [ "get_account" ]. +Axiom ethereum_frontier_state_imports_get_account : + IsImported globals "ethereum.frontier.state" "get_account". -Axiom ethereum_frontier_vm_imports : - AreImported globals "ethereum.frontier.vm" [ "Environment"; "Message" ]. +Axiom ethereum_frontier_vm_imports_Environment : + IsImported globals "ethereum.frontier.vm" "Environment". +Axiom ethereum_frontier_vm_imports_Message : + IsImported globals "ethereum.frontier.vm" "Message". -Axiom ethereum_frontier_utils_address_imports : - AreImported globals "ethereum.frontier.utils.address" [ "compute_contract_address" ]. +Axiom ethereum_frontier_utils_address_imports_compute_contract_address : + IsImported globals "ethereum.frontier.utils.address" "compute_contract_address". Definition prepare_message : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -78,7 +88,8 @@ Definition prepare_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let current_target := + let _ := M.assign_local (| + "current_target" , M.call (| M.get_name (| globals, "compute_contract_address" |), make_list [ @@ -102,17 +113,22 @@ Definition prepare_message : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let msg_data := + |) + |) in + let _ := M.assign_local (| + "msg_data" , M.call (| M.get_name (| globals, "Bytes" |), make_list [ Constant.bytes "" ], make_dict [] - |) in - let code := - M.get_name (| globals, "data" |) in + |) + |) in + let _ := M.assign_local (| + "code" , + M.get_name (| globals, "data" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -129,11 +145,16 @@ Definition prepare_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let current_target := - M.get_name (| globals, "target" |) in - let msg_data := - M.get_name (| globals, "data" |) in - let code := + let _ := M.assign_local (| + "current_target" , + M.get_name (| globals, "target" |) + |) in + let _ := M.assign_local (| + "msg_data" , + M.get_name (| globals, "data" |) + |) in + let _ := M.assign_local (| + "code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -141,7 +162,8 @@ Definition prepare_message : Value.t -> Value.t -> M := M.get_name (| globals, "target" |) ], make_dict [] - |), "code" |) in + |), "code" |) + |) in let _ := (* if *) M.if_then_else (| @@ -151,8 +173,10 @@ Definition prepare_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let code_address := - M.get_name (| globals, "target" |) in + let _ := M.assign_local (| + "code_address" , + M.get_name (| globals, "target" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/frontier/vm/__init__.v b/CoqOfPython/ethereum/frontier/vm/__init__.v index 85ab9d3..2c943a9 100644 --- a/CoqOfPython/ethereum/frontier/vm/__init__.v +++ b/CoqOfPython/ethereum/frontier/vm/__init__.v @@ -18,26 +18,40 @@ The abstract computer which runs the code stored in an `.fork_types.Account`. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple"; "Union" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. - -Axiom ethereum_frontier_blocks_imports : - AreImported globals "ethereum.frontier.blocks" [ "Log" ]. - -Axiom ethereum_frontier_fork_types_imports : - AreImported globals "ethereum.frontier.fork_types" [ "Address" ]. - -Axiom ethereum_frontier_state_imports : - AreImported globals "ethereum.frontier.state" [ "State" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". + +Axiom ethereum_frontier_blocks_imports_Log : + IsImported globals "ethereum.frontier.blocks" "Log". + +Axiom ethereum_frontier_fork_types_imports_Address : + IsImported globals "ethereum.frontier.fork_types" "Address". + +Axiom ethereum_frontier_state_imports_State : + IsImported globals "ethereum.frontier.state" "State". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] diff --git a/CoqOfPython/ethereum/frontier/vm/exceptions.v b/CoqOfPython/ethereum/frontier/vm/exceptions.v index 7718d59..f744f16 100644 --- a/CoqOfPython/ethereum/frontier/vm/exceptions.v +++ b/CoqOfPython/ethereum/frontier/vm/exceptions.v @@ -17,8 +17,8 @@ Introduction Exceptions which cause the EVM to halt exceptionally. ". -Axiom ethereum_exceptions_imports : - AreImported globals "ethereum.exceptions" [ "EthereumException" ]. +Axiom ethereum_exceptions_imports_EthereumException : + IsImported globals "ethereum.exceptions" "EthereumException". Definition ExceptionalHalt : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/frontier/vm/gas.v b/CoqOfPython/ethereum/frontier/vm/gas.v index b13832d..5e3fe66 100644 --- a/CoqOfPython/ethereum/frontier/vm/gas.v +++ b/CoqOfPython/ethereum/frontier/vm/gas.v @@ -17,32 +17,40 @@ Introduction EVM gas constants and calculators. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Tuple" ]. +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_trace_imports : - AreImported globals "ethereum.trace" [ "GasAndRefund"; "evm_trace" ]. +Axiom ethereum_trace_imports_GasAndRefund : + IsImported globals "ethereum.trace" "GasAndRefund". +Axiom ethereum_trace_imports_evm_trace : + IsImported globals "ethereum.trace" "evm_trace". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_frontier_fork_types_imports : - AreImported globals "ethereum.frontier.fork_types" [ "Address" ]. +Axiom ethereum_frontier_fork_types_imports_Address : + IsImported globals "ethereum.frontier.fork_types" "Address". -Axiom ethereum_frontier_state_imports : - AreImported globals "ethereum.frontier.state" [ "State"; "account_exists" ]. +Axiom ethereum_frontier_state_imports_State : + IsImported globals "ethereum.frontier.state" "State". +Axiom ethereum_frontier_state_imports_account_exists : + IsImported globals "ethereum.frontier.state" "account_exists". -Axiom ethereum_frontier_vm_imports : - AreImported globals "ethereum.frontier.vm" [ "Evm" ]. +Axiom ethereum_frontier_vm_imports_Evm : + IsImported globals "ethereum.frontier.vm" "Evm". -Axiom ethereum_frontier_vm_exceptions_imports : - AreImported globals "ethereum.frontier.vm.exceptions" [ "OutOfGasError" ]. +Axiom ethereum_frontier_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.frontier.vm.exceptions" "OutOfGasError". Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -508,7 +516,8 @@ Definition calculate_memory_gas_cost : Value.t -> Value.t -> M := total_gas_cost : `ethereum.base_types.Uint` The gas cost for storing data in memory. " in - let size_in_words := + let _ := M.assign_local (| + "size_in_words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -518,25 +527,32 @@ Definition calculate_memory_gas_cost : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let linear_cost := + |) + |) in + let _ := M.assign_local (| + "linear_cost" , BinOp.mult (| M.get_name (| globals, "size_in_words" |), M.get_name (| globals, "GAS_MEMORY" |) - |) in - let quadratic_cost := + |) + |) in + let _ := M.assign_local (| + "quadratic_cost" , BinOp.floor_div (| BinOp.pow (| M.get_name (| globals, "size_in_words" |), Constant.int 2 |), Constant.int 512 - |) in - let total_gas_cost := + |) + |) in + let _ := M.assign_local (| + "total_gas_cost" , BinOp.add (| M.get_name (| globals, "linear_cost" |), M.get_name (| globals, "quadratic_cost" |) - |) in + |) + |) in (* At stmt: unsupported node type: Try *) M.pure Constant.None_)). @@ -558,23 +574,28 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := ------- extend_memory: `ExtendMemory` " in - let size_to_extend := + let _ := M.assign_local (| + "size_to_extend" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in - let to_be_paid := + |) + |) in + let _ := M.assign_local (| + "to_be_paid" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in - let current_size := + |) + |) in + let _ := M.assign_local (| + "current_size" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -587,7 +608,8 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ], @@ -608,15 +630,18 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let before_size := + let _ := M.assign_local (| + "before_size" , M.call (| M.get_name (| globals, "ceil32" |), make_list [ M.get_name (| globals, "current_size" |) ], make_dict [] - |) in - let after_size := + |) + |) in + let _ := M.assign_local (| + "after_size" , M.call (| M.get_name (| globals, "ceil32" |), make_list [ @@ -638,7 +663,8 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -654,42 +680,46 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let size_to_extend := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "size_to_extend", BinOp.sub (| M.get_name (| globals, "after_size" |), M.get_name (| globals, "before_size" |) |) - BinOp.sub (| - M.get_name (| globals, "after_size" |), - M.get_name (| globals, "before_size" |) - |) in - let already_paid := + |) in + let _ := M.assign_local (| + "already_paid" , M.call (| M.get_name (| globals, "calculate_memory_gas_cost" |), make_list [ M.get_name (| globals, "before_size" |) ], make_dict [] - |) in - let total_cost := + |) + |) in + let _ := M.assign_local (| + "total_cost" , M.call (| M.get_name (| globals, "calculate_memory_gas_cost" |), make_list [ M.get_name (| globals, "after_size" |) ], make_dict [] - |) in - let to_be_paid := BinOp.add + |) + |) in + let _ := M.assign_op_local (| + BinOp.add, + "to_be_paid", BinOp.sub (| M.get_name (| globals, "total_cost" |), M.get_name (| globals, "already_paid" |) |) - BinOp.sub (| - M.get_name (| globals, "total_cost" |), - M.get_name (| globals, "already_paid" |) - |) in - let current_size := - M.get_name (| globals, "after_size" |) in + |) in + let _ := M.assign_local (| + "current_size" , + M.get_name (| globals, "after_size" |) + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -729,7 +759,8 @@ Definition calculate_message_call_gas : Value.t -> Value.t -> M := ------- message_call_gas: `MessageCallGas` " in - let create_gas_cost := + let _ := M.assign_local (| + "create_gas_cost" , (* if *) M.if_then_else (| M.call (| @@ -752,8 +783,10 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "GAS_NEW_ACCOUNT" |) - )) |) in - let transfer_gas_cost := + )) |) + |) in + let _ := M.assign_local (| + "transfer_gas_cost" , (* if *) M.if_then_else (| Compare.eq (| @@ -772,8 +805,10 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "GAS_CALL_VALUE" |) - )) |) in - let cost := + )) |) + |) in + let _ := M.assign_local (| + "cost" , BinOp.add (| BinOp.add (| BinOp.add (| @@ -783,8 +818,10 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_name (| globals, "create_gas_cost" |) |), M.get_name (| globals, "transfer_gas_cost" |) - |) in - let stipend := + |) + |) in + let _ := M.assign_local (| + "stipend" , (* if *) M.if_then_else (| Compare.eq (| @@ -800,7 +837,8 @@ BinOp.add (| M.get_name (| globals, "GAS_CALL_STIPEND" |), M.get_name (| globals, "gas" |) |) - )) |) in + )) |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "MessageCallGas" |), diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/__init__.v b/CoqOfPython/ethereum/frontier/vm/instructions/__init__.v index 990234a..b95c8d5 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/__init__.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/__init__.v @@ -20,44 +20,46 @@ implementations. (* At top_level_stmt: unsupported node type: Import *) -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict" ]. +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". -Axiom ethereum_frontier_vm_instructions_imports : - AreImported globals "ethereum.frontier.vm.instructions" [ "arithmetic" ]. +Axiom ethereum_frontier_vm_instructions_imports_arithmetic : + IsImported globals "ethereum.frontier.vm.instructions" "arithmetic". -Axiom ethereum_frontier_vm_instructions_imports : - AreImported globals "ethereum.frontier.vm.instructions" [ "bitwise" ]. +Axiom ethereum_frontier_vm_instructions_imports_bitwise : + IsImported globals "ethereum.frontier.vm.instructions" "bitwise". -Axiom ethereum_frontier_vm_instructions_imports : - AreImported globals "ethereum.frontier.vm.instructions" [ "block" ]. +Axiom ethereum_frontier_vm_instructions_imports_block : + IsImported globals "ethereum.frontier.vm.instructions" "block". -Axiom ethereum_frontier_vm_instructions_imports : - AreImported globals "ethereum.frontier.vm.instructions" [ "comparison" ]. +Axiom ethereum_frontier_vm_instructions_imports_comparison : + IsImported globals "ethereum.frontier.vm.instructions" "comparison". -Axiom ethereum_frontier_vm_instructions_imports : - AreImported globals "ethereum.frontier.vm.instructions" [ "control_flow" ]. +Axiom ethereum_frontier_vm_instructions_imports_control_flow : + IsImported globals "ethereum.frontier.vm.instructions" "control_flow". -Axiom ethereum_frontier_vm_instructions_imports : - AreImported globals "ethereum.frontier.vm.instructions" [ "environment" ]. +Axiom ethereum_frontier_vm_instructions_imports_environment : + IsImported globals "ethereum.frontier.vm.instructions" "environment". -Axiom ethereum_frontier_vm_instructions_imports : - AreImported globals "ethereum.frontier.vm.instructions" [ "keccak" ]. +Axiom ethereum_frontier_vm_instructions_imports_keccak : + IsImported globals "ethereum.frontier.vm.instructions" "keccak". -Axiom ethereum_frontier_vm_instructions_imports : - AreImported globals "ethereum.frontier.vm.instructions" [ "log" ]. +Axiom ethereum_frontier_vm_instructions_imports_log : + IsImported globals "ethereum.frontier.vm.instructions" "log". -Axiom ethereum_frontier_vm_instructions_imports : - AreImported globals "ethereum.frontier.vm.instructions" [ "memory" ]. +Axiom ethereum_frontier_vm_instructions_imports_memory : + IsImported globals "ethereum.frontier.vm.instructions" "memory". -Axiom ethereum_frontier_vm_instructions_imports : - AreImported globals "ethereum.frontier.vm.instructions" [ "stack" ]. +Axiom ethereum_frontier_vm_instructions_imports_stack : + IsImported globals "ethereum.frontier.vm.instructions" "stack". -Axiom ethereum_frontier_vm_instructions_imports : - AreImported globals "ethereum.frontier.vm.instructions" [ "storage" ]. +Axiom ethereum_frontier_vm_instructions_imports_storage : + IsImported globals "ethereum.frontier.vm.instructions" "storage". -Axiom ethereum_frontier_vm_instructions_imports : - AreImported globals "ethereum.frontier.vm.instructions" [ "system" ]. +Axiom ethereum_frontier_vm_instructions_imports_system : + IsImported globals "ethereum.frontier.vm.instructions" "system". Definition Ops : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/frontier/vm/instructions/arithmetic.v index 119678d..542e2ad 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/arithmetic.v @@ -17,20 +17,38 @@ Introduction Implementations of the EVM Arithmetic instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U255_CEIL_VALUE"; "U256"; "U256_CEIL_VALUE"; "Uint" ]. +Axiom ethereum_base_types_imports_U255_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U255_CEIL_VALUE". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_U256_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U256_CEIL_VALUE". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "get_sign" ]. +Axiom ethereum_utils_numeric_imports_get_sign : + IsImported globals "ethereum.utils.numeric" "get_sign". -Axiom ethereum_frontier_vm_imports : - AreImported globals "ethereum.frontier.vm" [ "Evm" ]. +Axiom ethereum_frontier_vm_imports_Evm : + IsImported globals "ethereum.frontier.vm" "Evm". -Axiom ethereum_frontier_vm_gas_imports : - AreImported globals "ethereum.frontier.vm.gas" [ "GAS_EXPONENTIATION"; "GAS_EXPONENTIATION_PER_BYTE"; "GAS_LOW"; "GAS_MID"; "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_frontier_vm_gas_imports_GAS_EXPONENTIATION : + IsImported globals "ethereum.frontier.vm.gas" "GAS_EXPONENTIATION". +Axiom ethereum_frontier_vm_gas_imports_GAS_EXPONENTIATION_PER_BYTE : + IsImported globals "ethereum.frontier.vm.gas" "GAS_EXPONENTIATION_PER_BYTE". +Axiom ethereum_frontier_vm_gas_imports_GAS_LOW : + IsImported globals "ethereum.frontier.vm.gas" "GAS_LOW". +Axiom ethereum_frontier_vm_gas_imports_GAS_MID : + IsImported globals "ethereum.frontier.vm.gas" "GAS_MID". +Axiom ethereum_frontier_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.frontier.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_frontier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.frontier.vm.gas" "charge_gas". -Axiom ethereum_frontier_vm_stack_imports : - AreImported globals "ethereum.frontier.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_frontier_vm_stack_imports_pop : + IsImported globals "ethereum.frontier.vm.stack" "pop". +Axiom ethereum_frontier_vm_stack_imports_push : + IsImported globals "ethereum.frontier.vm.stack" "push". Definition add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,22 +63,26 @@ Definition add : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -69,14 +91,16 @@ Definition add : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "x" |), "wrapping_add" |), make_list [ M.get_name (| globals, "y" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -105,22 +129,26 @@ Definition sub : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -129,14 +157,16 @@ Definition sub : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "x" |), "wrapping_sub" |), make_list [ M.get_name (| globals, "y" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -165,22 +195,26 @@ Definition mul : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -189,14 +223,16 @@ Definition mul : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "x" |), "wrapping_mul" |), make_list [ M.get_name (| globals, "y" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -225,22 +261,26 @@ Definition div : Value.t -> Value.t -> M := The current EVM frame. " in - let dividend := + let _ := M.assign_local (| + "dividend" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let divisor := + |) + |) in + let _ := M.assign_local (| + "divisor" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -258,22 +298,26 @@ Definition div : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let quotient := + let _ := M.assign_local (| + "quotient" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let quotient := + let _ := M.assign_local (| + "quotient" , BinOp.floor_div (| M.get_name (| globals, "dividend" |), M.get_name (| globals, "divisor" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -304,7 +348,8 @@ Definition sdiv : Value.t -> Value.t -> M := The current EVM frame. " in - let dividend := + let _ := M.assign_local (| + "dividend" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -315,8 +360,10 @@ Definition sdiv : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let divisor := + |) + |) in + let _ := M.assign_local (| + "divisor" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -327,7 +374,8 @@ Definition sdiv : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -345,8 +393,10 @@ Definition sdiv : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let quotient := - Constant.int 0 in + let _ := M.assign_local (| + "quotient" , + Constant.int 0 + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -367,12 +417,15 @@ Definition sdiv : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let quotient := - UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in + let _ := M.assign_local (| + "quotient" , + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let sign := + let _ := M.assign_local (| + "sign" , M.call (| M.get_name (| globals, "get_sign" |), make_list [ @@ -382,8 +435,10 @@ Definition sdiv : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let quotient := + |) + |) in + let _ := M.assign_local (| + "quotient" , BinOp.mult (| M.get_name (| globals, "sign" |), BinOp.floor_div (| @@ -402,7 +457,8 @@ Definition sdiv : Value.t -> Value.t -> M := make_dict [] |) |) - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -428,7 +484,7 @@ Definition sdiv : Value.t -> Value.t -> M := |) in M.pure Constant.None_)). -Definition mod : Value.t -> Value.t -> M := +Definition mod_ : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in let _ := Constant.str " @@ -441,22 +497,26 @@ Definition mod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -474,22 +534,26 @@ Definition mod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let remainder := + let _ := M.assign_local (| + "remainder" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let remainder := + let _ := M.assign_local (| + "remainder" , BinOp.mod_ (| M.get_name (| globals, "x" |), M.get_name (| globals, "y" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -520,7 +584,8 @@ Definition smod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -531,8 +596,10 @@ Definition smod : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -543,7 +610,8 @@ Definition smod : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -561,12 +629,15 @@ Definition smod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let remainder := - Constant.int 0 in + let _ := M.assign_local (| + "remainder" , + Constant.int 0 + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let remainder := + let _ := M.assign_local (| + "remainder" , BinOp.mult (| M.call (| M.get_name (| globals, "get_sign" |), @@ -591,7 +662,8 @@ Definition smod : Value.t -> Value.t -> M := make_dict [] |) |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -628,7 +700,8 @@ Definition addmod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -641,8 +714,10 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -655,8 +730,10 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let z := + |) + |) in + let _ := M.assign_local (| + "z" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -669,7 +746,8 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -687,18 +765,21 @@ Definition addmod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -711,7 +792,8 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -742,7 +824,8 @@ Definition mulmod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -755,8 +838,10 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -769,8 +854,10 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let z := + |) + |) in + let _ := M.assign_local (| + "z" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -783,7 +870,8 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -801,18 +889,21 @@ Definition mulmod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -825,7 +916,8 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -856,7 +948,8 @@ Definition exp : Value.t -> Value.t -> M := The current EVM frame. " in - let base := + let _ := M.assign_local (| + "base" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -869,8 +962,10 @@ Definition exp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exponent := + |) + |) in + let _ := M.assign_local (| + "exponent" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -883,21 +978,26 @@ Definition exp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exponent_bits := + |) + |) in + let _ := M.assign_local (| + "exponent_bits" , M.call (| M.get_field (| M.get_name (| globals, "exponent" |), "bit_length" |), make_list [], make_dict [] - |) in - let exponent_bytes := + |) + |) in + let _ := M.assign_local (| + "exponent_bytes" , BinOp.floor_div (| BinOp.add (| M.get_name (| globals, "exponent_bits" |), Constant.int 7 |), Constant.int 8 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -912,7 +1012,8 @@ Definition exp : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -927,7 +1028,8 @@ Definition exp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -956,22 +1058,26 @@ Definition signextend : Value.t -> Value.t -> M := The current EVM frame. " in - let byte_num := + let _ := M.assign_local (| + "byte_num" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -989,12 +1095,15 @@ Definition signextend : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := - M.get_name (| globals, "value" |) in + let _ := M.assign_local (| + "result" , + M.get_name (| globals, "value" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let value_bytes := + let _ := M.assign_local (| + "value_bytes" , M.call (| M.get_name (| globals, "bytes" |), make_list [ @@ -1005,8 +1114,10 @@ Definition signextend : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let value_bytes := + |) + |) in + let _ := M.assign_local (| + "value_bytes" , M.slice (| M.get_name (| globals, "value_bytes" |), BinOp.sub (| @@ -1021,15 +1132,18 @@ Definition signextend : Value.t -> Value.t -> M := |), Constant.None_, Constant.None_ - |) in - let sign_bit := + |) + |) in + let _ := M.assign_local (| + "sign_bit" , BinOp.r_shift (| M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), Constant.int 7 - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1039,26 +1153,31 @@ Definition signextend : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "value_bytes" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let num_bytes_prepend := + let _ := M.assign_local (| + "num_bytes_prepend" , BinOp.sub (| Constant.int 32, BinOp.add (| M.get_name (| globals, "byte_num" |), Constant.int 1 |) - |) in - let result := + |) + |) in + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -1079,7 +1198,8 @@ Definition signextend : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/bitwise.v b/CoqOfPython/ethereum/frontier/vm/instructions/bitwise.v index 299e447..f568271 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/bitwise.v @@ -17,17 +17,21 @@ Introduction Implementations of the EVM bitwise instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_frontier_vm_imports : - AreImported globals "ethereum.frontier.vm" [ "Evm" ]. +Axiom ethereum_frontier_vm_imports_Evm : + IsImported globals "ethereum.frontier.vm" "Evm". -Axiom ethereum_frontier_vm_gas_imports : - AreImported globals "ethereum.frontier.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_frontier_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.frontier.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_frontier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.frontier.vm.gas" "charge_gas". -Axiom ethereum_frontier_vm_stack_imports : - AreImported globals "ethereum.frontier.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_frontier_vm_stack_imports_pop : + IsImported globals "ethereum.frontier.vm.stack" "pop". +Axiom ethereum_frontier_vm_stack_imports_push : + IsImported globals "ethereum.frontier.vm.stack" "push". Definition bitwise_and : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,22 +46,26 @@ Definition bitwise_and : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -97,22 +105,26 @@ Definition bitwise_or : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -152,22 +164,26 @@ Definition bitwise_xor : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -207,14 +223,16 @@ Definition bitwise_not : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -252,22 +270,26 @@ Definition get_byte : Value.t -> Value.t -> M := The current EVM frame. " in - let byte_index := + let _ := M.assign_local (| + "byte_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let word := + |) + |) in + let _ := M.assign_local (| + "word" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -285,43 +307,53 @@ Definition get_byte : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let extra_bytes_to_right := + let _ := M.assign_local (| + "extra_bytes_to_right" , BinOp.sub (| Constant.int 31, M.get_name (| globals, "byte_index" |) - |) in - let word := + |) + |) in + let _ := M.assign_local (| + "word" , BinOp.r_shift (| M.get_name (| globals, "word" |), BinOp.mult (| M.get_name (| globals, "extra_bytes_to_right" |), Constant.int 8 |) - |) in - let word := + |) + |) in + let _ := M.assign_local (| + "word" , BinOp.bit_and (| M.get_name (| globals, "word" |), Constant.int 255 - |) in - let result := + |) + |) in + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ M.get_name (| globals, "word" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/block.v b/CoqOfPython/ethereum/frontier/vm/instructions/block.v index 54166fb..cbcd26a 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/block.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/block.v @@ -17,17 +17,23 @@ Introduction Implementations of the EVM block instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_frontier_vm_imports : - AreImported globals "ethereum.frontier.vm" [ "Evm" ]. +Axiom ethereum_frontier_vm_imports_Evm : + IsImported globals "ethereum.frontier.vm" "Evm". -Axiom ethereum_frontier_vm_gas_imports : - AreImported globals "ethereum.frontier.vm.gas" [ "GAS_BASE"; "GAS_BLOCK_HASH"; "charge_gas" ]. +Axiom ethereum_frontier_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.frontier.vm.gas" "GAS_BASE". +Axiom ethereum_frontier_vm_gas_imports_GAS_BLOCK_HASH : + IsImported globals "ethereum.frontier.vm.gas" "GAS_BLOCK_HASH". +Axiom ethereum_frontier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.frontier.vm.gas" "charge_gas". -Axiom ethereum_frontier_vm_stack_imports : - AreImported globals "ethereum.frontier.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_frontier_vm_stack_imports_pop : + IsImported globals "ethereum.frontier.vm.stack" "pop". +Axiom ethereum_frontier_vm_stack_imports_push : + IsImported globals "ethereum.frontier.vm.stack" "push". Definition block_hash : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,14 +48,16 @@ Definition block_hash : Value.t -> Value.t -> M := The current EVM frame. " in - let block_number := + let _ := M.assign_local (| + "block_number" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -78,19 +86,23 @@ Definition block_hash : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let hash := - Constant.bytes "00" in + let _ := M.assign_local (| + "hash" , + Constant.bytes "00" + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let hash := + let _ := M.assign_local (| + "hash" , M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), M.get_name (| globals, "block_number" |) |) |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/comparison.v b/CoqOfPython/ethereum/frontier/vm/instructions/comparison.v index 132c084..8c59240 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/comparison.v @@ -17,17 +17,21 @@ Introduction Implementations of the EVM Comparison instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_frontier_vm_imports : - AreImported globals "ethereum.frontier.vm" [ "Evm" ]. +Axiom ethereum_frontier_vm_imports_Evm : + IsImported globals "ethereum.frontier.vm" "Evm". -Axiom ethereum_frontier_vm_gas_imports : - AreImported globals "ethereum.frontier.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_frontier_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.frontier.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_frontier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.frontier.vm.gas" "charge_gas". -Axiom ethereum_frontier_vm_stack_imports : - AreImported globals "ethereum.frontier.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_frontier_vm_stack_imports_pop : + IsImported globals "ethereum.frontier.vm.stack" "pop". +Axiom ethereum_frontier_vm_stack_imports_push : + IsImported globals "ethereum.frontier.vm.stack" "push". Definition less_than : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,22 +46,26 @@ Definition less_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -66,7 +74,8 @@ Definition less_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -76,7 +85,8 @@ Definition less_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -104,7 +114,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -115,8 +126,10 @@ Definition signed_less_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -127,7 +140,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -136,7 +150,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -146,7 +161,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -175,22 +191,26 @@ Definition greater_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -199,7 +219,8 @@ Definition greater_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -209,7 +230,8 @@ Definition greater_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -237,7 +259,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -248,8 +271,10 @@ Definition signed_greater_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -260,7 +285,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -269,7 +295,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -279,7 +306,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -308,22 +336,26 @@ Definition equal : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -332,7 +364,8 @@ Definition equal : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -342,7 +375,8 @@ Definition equal : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -371,14 +405,16 @@ Definition is_zero : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -387,7 +423,8 @@ Definition is_zero : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -397,7 +434,8 @@ Definition is_zero : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/control_flow.v b/CoqOfPython/ethereum/frontier/vm/instructions/control_flow.v index 6c9a489..ce039f3 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/control_flow.v @@ -17,20 +17,32 @@ Introduction Implementations of the EVM control flow instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_frontier_vm_gas_imports : - AreImported globals "ethereum.frontier.vm.gas" [ "GAS_BASE"; "GAS_HIGH"; "GAS_JUMPDEST"; "GAS_MID"; "charge_gas" ]. +Axiom ethereum_frontier_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.frontier.vm.gas" "GAS_BASE". +Axiom ethereum_frontier_vm_gas_imports_GAS_HIGH : + IsImported globals "ethereum.frontier.vm.gas" "GAS_HIGH". +Axiom ethereum_frontier_vm_gas_imports_GAS_JUMPDEST : + IsImported globals "ethereum.frontier.vm.gas" "GAS_JUMPDEST". +Axiom ethereum_frontier_vm_gas_imports_GAS_MID : + IsImported globals "ethereum.frontier.vm.gas" "GAS_MID". +Axiom ethereum_frontier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.frontier.vm.gas" "charge_gas". -Axiom ethereum_frontier_vm_imports : - AreImported globals "ethereum.frontier.vm" [ "Evm" ]. +Axiom ethereum_frontier_vm_imports_Evm : + IsImported globals "ethereum.frontier.vm" "Evm". -Axiom ethereum_frontier_vm_exceptions_imports : - AreImported globals "ethereum.frontier.vm.exceptions" [ "InvalidJumpDestError" ]. +Axiom ethereum_frontier_vm_exceptions_imports_InvalidJumpDestError : + IsImported globals "ethereum.frontier.vm.exceptions" "InvalidJumpDestError". -Axiom ethereum_frontier_vm_stack_imports : - AreImported globals "ethereum.frontier.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_frontier_vm_stack_imports_pop : + IsImported globals "ethereum.frontier.vm.stack" "pop". +Axiom ethereum_frontier_vm_stack_imports_push : + IsImported globals "ethereum.frontier.vm.stack" "push". Definition stop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -69,7 +81,8 @@ Definition jump : Value.t -> Value.t -> M := The current EVM frame. " in - let jump_dest := + let _ := M.assign_local (| + "jump_dest" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -82,7 +95,8 @@ Definition jump : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -132,7 +146,8 @@ Definition jumpi : Value.t -> Value.t -> M := The current EVM frame. " in - let jump_dest := + let _ := M.assign_local (| + "jump_dest" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -145,15 +160,18 @@ Definition jumpi : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let conditional_value := + |) + |) in + let _ := M.assign_local (| + "conditional_value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -171,11 +189,13 @@ Definition jumpi : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let destination := + let _ := M.assign_local (| + "destination" , BinOp.add (| M.get_field (| M.get_name (| globals, "evm" |), "pc" |), Constant.int 1 - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -192,8 +212,10 @@ Definition jumpi : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let destination := - M.get_name (| globals, "jump_dest" |) in + let _ := M.assign_local (| + "destination" , + M.get_name (| globals, "jump_dest" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/environment.v b/CoqOfPython/ethereum/frontier/vm/instructions/environment.v index 502329a..2ed9e35 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/environment.v @@ -17,29 +17,47 @@ Introduction Implementations of the EVM environment related instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. - -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. - -Axiom ethereum_frontier_state_imports : - AreImported globals "ethereum.frontier.state" [ "get_account" ]. - -Axiom ethereum_frontier_utils_address_imports : - AreImported globals "ethereum.frontier.utils.address" [ "to_address" ]. - -Axiom ethereum_frontier_vm_memory_imports : - AreImported globals "ethereum.frontier.vm.memory" [ "buffer_read"; "memory_write" ]. - -Axiom ethereum_frontier_vm_imports : - AreImported globals "ethereum.frontier.vm" [ "Evm" ]. - -Axiom ethereum_frontier_vm_gas_imports : - AreImported globals "ethereum.frontier.vm.gas" [ "GAS_BALANCE"; "GAS_BASE"; "GAS_COPY"; "GAS_EXTERNAL"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. - -Axiom ethereum_frontier_vm_stack_imports : - AreImported globals "ethereum.frontier.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". + +Axiom ethereum_frontier_state_imports_get_account : + IsImported globals "ethereum.frontier.state" "get_account". + +Axiom ethereum_frontier_utils_address_imports_to_address : + IsImported globals "ethereum.frontier.utils.address" "to_address". + +Axiom ethereum_frontier_vm_memory_imports_buffer_read : + IsImported globals "ethereum.frontier.vm.memory" "buffer_read". +Axiom ethereum_frontier_vm_memory_imports_memory_write : + IsImported globals "ethereum.frontier.vm.memory" "memory_write". + +Axiom ethereum_frontier_vm_imports_Evm : + IsImported globals "ethereum.frontier.vm" "Evm". + +Axiom ethereum_frontier_vm_gas_imports_GAS_BALANCE : + IsImported globals "ethereum.frontier.vm.gas" "GAS_BALANCE". +Axiom ethereum_frontier_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.frontier.vm.gas" "GAS_BASE". +Axiom ethereum_frontier_vm_gas_imports_GAS_COPY : + IsImported globals "ethereum.frontier.vm.gas" "GAS_COPY". +Axiom ethereum_frontier_vm_gas_imports_GAS_EXTERNAL : + IsImported globals "ethereum.frontier.vm.gas" "GAS_EXTERNAL". +Axiom ethereum_frontier_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.frontier.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_frontier_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.frontier.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_frontier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.frontier.vm.gas" "charge_gas". + +Axiom ethereum_frontier_vm_stack_imports_pop : + IsImported globals "ethereum.frontier.vm.stack" "pop". +Axiom ethereum_frontier_vm_stack_imports_push : + IsImported globals "ethereum.frontier.vm.stack" "push". Definition address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -95,7 +113,8 @@ Definition balance : Value.t -> Value.t -> M := The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -108,7 +127,8 @@ Definition balance : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -117,7 +137,8 @@ Definition balance : Value.t -> Value.t -> M := ], make_dict [] |) in - let balance := + let _ := M.assign_local (| + "balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -125,7 +146,8 @@ Definition balance : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -275,14 +297,16 @@ Definition calldataload : Value.t -> Value.t -> M := The current EVM frame. " in - let start_index := + let _ := M.assign_local (| + "start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -291,7 +315,8 @@ Definition calldataload : Value.t -> Value.t -> M := ], make_dict [] |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -306,7 +331,8 @@ Definition calldataload : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -391,31 +417,38 @@ Definition calldatacopy : Value.t -> Value.t -> M := The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let data_start_index := + |) + |) in + let _ := M.assign_local (| + "data_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -431,13 +464,17 @@ Definition calldatacopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -447,7 +484,8 @@ Definition calldatacopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -470,7 +508,8 @@ Definition calldatacopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -479,7 +518,8 @@ Definition calldatacopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -559,31 +599,38 @@ Definition codecopy : Value.t -> Value.t -> M := The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let code_start_index := + |) + |) in + let _ := M.assign_local (| + "code_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -599,13 +646,17 @@ Definition codecopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -615,7 +666,8 @@ Definition codecopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -638,7 +690,8 @@ Definition codecopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -647,7 +700,8 @@ Definition codecopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -718,7 +772,8 @@ Definition extcodesize : Value.t -> Value.t -> M := The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -731,7 +786,8 @@ Definition extcodesize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -740,7 +796,8 @@ Definition extcodesize : Value.t -> Value.t -> M := ], make_dict [] |) in - let codesize := + let _ := M.assign_local (| + "codesize" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -760,7 +817,8 @@ Definition extcodesize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -788,7 +846,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -801,32 +860,40 @@ Definition extcodecopy : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let memory_start_index := + |) + |) in + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let code_start_index := + |) + |) in + let _ := M.assign_local (| + "code_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -842,13 +909,17 @@ Definition extcodecopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -858,7 +929,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -881,7 +953,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let code := + let _ := M.assign_local (| + "code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -889,8 +962,10 @@ Definition extcodecopy : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |), "code" |) in - let value := + |), "code" |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -899,7 +974,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/keccak.v b/CoqOfPython/ethereum/frontier/vm/instructions/keccak.v index 1d8fbbc..393213b 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/keccak.v @@ -17,26 +17,36 @@ Introduction Implementations of the EVM keccak instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_frontier_vm_imports : - AreImported globals "ethereum.frontier.vm" [ "Evm" ]. +Axiom ethereum_frontier_vm_imports_Evm : + IsImported globals "ethereum.frontier.vm" "Evm". -Axiom ethereum_frontier_vm_gas_imports : - AreImported globals "ethereum.frontier.vm.gas" [ "GAS_KECCAK256"; "GAS_KECCAK256_WORD"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_frontier_vm_gas_imports_GAS_KECCAK256 : + IsImported globals "ethereum.frontier.vm.gas" "GAS_KECCAK256". +Axiom ethereum_frontier_vm_gas_imports_GAS_KECCAK256_WORD : + IsImported globals "ethereum.frontier.vm.gas" "GAS_KECCAK256_WORD". +Axiom ethereum_frontier_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.frontier.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_frontier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.frontier.vm.gas" "charge_gas". -Axiom ethereum_frontier_vm_memory_imports : - AreImported globals "ethereum.frontier.vm.memory" [ "memory_read_bytes" ]. +Axiom ethereum_frontier_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.frontier.vm.memory" "memory_read_bytes". -Axiom ethereum_frontier_vm_stack_imports : - AreImported globals "ethereum.frontier.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_frontier_vm_stack_imports_pop : + IsImported globals "ethereum.frontier.vm.stack" "pop". +Axiom ethereum_frontier_vm_stack_imports_push : + IsImported globals "ethereum.frontier.vm.stack" "push". Definition keccak : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -53,23 +63,28 @@ Definition keccak : Value.t -> Value.t -> M := The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -85,13 +100,17 @@ Definition keccak : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let word_gas_cost := + |) + |) in + let _ := M.assign_local (| + "word_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_KECCAK256_WORD" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -101,7 +120,8 @@ Definition keccak : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -124,7 +144,8 @@ Definition keccak : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let data := + let _ := M.assign_local (| + "data" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -133,15 +154,18 @@ Definition keccak : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in - let hash := + |) + |) in + let _ := M.assign_local (| + "hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "data" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/log.v b/CoqOfPython/ethereum/frontier/vm/instructions/log.v index 4cf0761..f675d8d 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/log.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/log.v @@ -17,26 +17,34 @@ Introduction Implementations of the EVM logging instructions. ". -Axiom functools_imports : - AreImported globals "functools" [ "partial" ]. +Axiom functools_imports_partial : + IsImported globals "functools" "partial". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_frontier_blocks_imports : - AreImported globals "ethereum.frontier.blocks" [ "Log" ]. +Axiom ethereum_frontier_blocks_imports_Log : + IsImported globals "ethereum.frontier.blocks" "Log". -Axiom ethereum_frontier_vm_imports : - AreImported globals "ethereum.frontier.vm" [ "Evm" ]. +Axiom ethereum_frontier_vm_imports_Evm : + IsImported globals "ethereum.frontier.vm" "Evm". -Axiom ethereum_frontier_vm_gas_imports : - AreImported globals "ethereum.frontier.vm.gas" [ "GAS_LOG"; "GAS_LOG_DATA"; "GAS_LOG_TOPIC"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_frontier_vm_gas_imports_GAS_LOG : + IsImported globals "ethereum.frontier.vm.gas" "GAS_LOG". +Axiom ethereum_frontier_vm_gas_imports_GAS_LOG_DATA : + IsImported globals "ethereum.frontier.vm.gas" "GAS_LOG_DATA". +Axiom ethereum_frontier_vm_gas_imports_GAS_LOG_TOPIC : + IsImported globals "ethereum.frontier.vm.gas" "GAS_LOG_TOPIC". +Axiom ethereum_frontier_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.frontier.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_frontier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.frontier.vm.gas" "charge_gas". -Axiom ethereum_frontier_vm_memory_imports : - AreImported globals "ethereum.frontier.vm.memory" [ "memory_read_bytes" ]. +Axiom ethereum_frontier_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.frontier.vm.memory" "memory_read_bytes". -Axiom ethereum_frontier_vm_stack_imports : - AreImported globals "ethereum.frontier.vm.stack" [ "pop" ]. +Axiom ethereum_frontier_vm_stack_imports_pop : + IsImported globals "ethereum.frontier.vm.stack" "pop". Definition log_n : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -55,24 +63,30 @@ Definition log_n : Value.t -> Value.t -> M := The number of topics to be included in the log entry. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let topics := - make_list [] in + |) + |) in + let _ := M.assign_local (| + "topics" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "_" |), @@ -84,7 +98,8 @@ Definition log_n : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let topic := + let _ := M.assign_local (| + "topic" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -95,7 +110,8 @@ Definition log_n : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "topics" |), "append" |), make_list [ @@ -109,7 +125,8 @@ Definition log_n : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let extend_memory := + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -119,7 +136,8 @@ Definition log_n : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -151,12 +169,14 @@ Definition log_n : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let log_entry := + let _ := M.assign_local (| + "log_entry" , M.call (| M.get_name (| globals, "Log" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "logs" |), BinOp.add (| diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/memory.v b/CoqOfPython/ethereum/frontier/vm/instructions/memory.v index 2646957..56c03a2 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/memory.v @@ -17,20 +17,32 @@ Introduction Implementations of the EVM Memory instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". -Axiom ethereum_frontier_vm_imports : - AreImported globals "ethereum.frontier.vm" [ "Evm" ]. +Axiom ethereum_frontier_vm_imports_Evm : + IsImported globals "ethereum.frontier.vm" "Evm". -Axiom ethereum_frontier_vm_gas_imports : - AreImported globals "ethereum.frontier.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_frontier_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.frontier.vm.gas" "GAS_BASE". +Axiom ethereum_frontier_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.frontier.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_frontier_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.frontier.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_frontier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.frontier.vm.gas" "charge_gas". -Axiom ethereum_frontier_vm_memory_imports : - AreImported globals "ethereum.frontier.vm.memory" [ "memory_read_bytes"; "memory_write" ]. +Axiom ethereum_frontier_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.frontier.vm.memory" "memory_read_bytes". +Axiom ethereum_frontier_vm_memory_imports_memory_write : + IsImported globals "ethereum.frontier.vm.memory" "memory_write". -Axiom ethereum_frontier_vm_stack_imports : - AreImported globals "ethereum.frontier.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_frontier_vm_stack_imports_pop : + IsImported globals "ethereum.frontier.vm.stack" "pop". +Axiom ethereum_frontier_vm_stack_imports_push : + IsImported globals "ethereum.frontier.vm.stack" "push". Definition mstore : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -46,15 +58,18 @@ Definition mstore : Value.t -> Value.t -> M := The current EVM frame. " in - let start_position := + let _ := M.assign_local (| + "start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -65,8 +80,10 @@ Definition mstore : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -88,7 +105,8 @@ Definition mstore : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -138,23 +156,28 @@ Definition mstore8 : Value.t -> Value.t -> M := The current EVM frame. " in - let start_position := + let _ := M.assign_local (| + "start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -170,7 +193,8 @@ Definition mstore8 : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -190,7 +214,8 @@ Definition mstore8 : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let normalized_bytes_value := + let _ := M.assign_local (| + "normalized_bytes_value" , M.call (| M.get_name (| globals, "Bytes" |), make_list [ @@ -202,7 +227,8 @@ Definition mstore8 : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -231,15 +257,18 @@ Definition mload : Value.t -> Value.t -> M := The current EVM frame. " in - let start_position := + let _ := M.assign_local (| + "start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -255,7 +284,8 @@ Definition mload : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -275,7 +305,8 @@ Definition mload : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -296,7 +327,8 @@ Definition mload : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/stack.v b/CoqOfPython/ethereum/frontier/vm/instructions/stack.v index 44c9eb7..18ec37d 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/stack.v @@ -17,26 +17,32 @@ Introduction Implementations of the EVM stack related instructions. ". -Axiom functools_imports : - AreImported globals "functools" [ "partial" ]. +Axiom functools_imports_partial : + IsImported globals "functools" "partial". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_frontier_vm_imports : - AreImported globals "ethereum.frontier.vm" [ "Evm"; "stack" ]. +Axiom ethereum_frontier_vm_imports_Evm : + IsImported globals "ethereum.frontier.vm" "Evm". +Axiom ethereum_frontier_vm_imports_stack : + IsImported globals "ethereum.frontier.vm" "stack". -Axiom ethereum_frontier_vm_exceptions_imports : - AreImported globals "ethereum.frontier.vm.exceptions" [ "StackUnderflowError" ]. +Axiom ethereum_frontier_vm_exceptions_imports_StackUnderflowError : + IsImported globals "ethereum.frontier.vm.exceptions" "StackUnderflowError". -Axiom ethereum_frontier_vm_gas_imports : - AreImported globals "ethereum.frontier.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_frontier_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.frontier.vm.gas" "GAS_BASE". +Axiom ethereum_frontier_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.frontier.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_frontier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.frontier.vm.gas" "charge_gas". -Axiom ethereum_frontier_vm_memory_imports : - AreImported globals "ethereum.frontier.vm.memory" [ "buffer_read" ]. +Axiom ethereum_frontier_vm_memory_imports_buffer_read : + IsImported globals "ethereum.frontier.vm.memory" "buffer_read". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -98,7 +104,8 @@ Definition push_n : Value.t -> Value.t -> M := ], make_dict [] |) in - let data_to_push := + let _ := M.assign_local (| + "data_to_push" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -128,7 +135,8 @@ Definition push_n : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "stack" |), "push" |), make_list [ @@ -189,7 +197,8 @@ Definition dup_n : Value.t -> Value.t -> M := ], make_dict [] |) in - let data_to_duplicate := + let _ := M.assign_local (| + "data_to_duplicate" , M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| @@ -205,7 +214,8 @@ Definition dup_n : Value.t -> Value.t -> M := |), M.get_name (| globals, "item_number" |) |) - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "stack" |), "push" |), make_list [ diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/storage.v b/CoqOfPython/ethereum/frontier/vm/instructions/storage.v index bf59138..754b34a 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/storage.v @@ -17,17 +17,29 @@ Introduction Implementations of the EVM storage related instructions. ". -Axiom ethereum_frontier_state_imports : - AreImported globals "ethereum.frontier.state" [ "get_storage"; "set_storage" ]. +Axiom ethereum_frontier_state_imports_get_storage : + IsImported globals "ethereum.frontier.state" "get_storage". +Axiom ethereum_frontier_state_imports_set_storage : + IsImported globals "ethereum.frontier.state" "set_storage". -Axiom ethereum_frontier_vm_imports : - AreImported globals "ethereum.frontier.vm" [ "Evm" ]. +Axiom ethereum_frontier_vm_imports_Evm : + IsImported globals "ethereum.frontier.vm" "Evm". -Axiom ethereum_frontier_vm_gas_imports : - AreImported globals "ethereum.frontier.vm.gas" [ "GAS_SLOAD"; "GAS_STORAGE_CLEAR_REFUND"; "GAS_STORAGE_SET"; "GAS_STORAGE_UPDATE"; "charge_gas" ]. +Axiom ethereum_frontier_vm_gas_imports_GAS_SLOAD : + IsImported globals "ethereum.frontier.vm.gas" "GAS_SLOAD". +Axiom ethereum_frontier_vm_gas_imports_GAS_STORAGE_CLEAR_REFUND : + IsImported globals "ethereum.frontier.vm.gas" "GAS_STORAGE_CLEAR_REFUND". +Axiom ethereum_frontier_vm_gas_imports_GAS_STORAGE_SET : + IsImported globals "ethereum.frontier.vm.gas" "GAS_STORAGE_SET". +Axiom ethereum_frontier_vm_gas_imports_GAS_STORAGE_UPDATE : + IsImported globals "ethereum.frontier.vm.gas" "GAS_STORAGE_UPDATE". +Axiom ethereum_frontier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.frontier.vm.gas" "charge_gas". -Axiom ethereum_frontier_vm_stack_imports : - AreImported globals "ethereum.frontier.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_frontier_vm_stack_imports_pop : + IsImported globals "ethereum.frontier.vm.stack" "pop". +Axiom ethereum_frontier_vm_stack_imports_push : + IsImported globals "ethereum.frontier.vm.stack" "push". Definition sload : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,7 +54,8 @@ Definition sload : Value.t -> Value.t -> M := The current EVM frame. " in - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -53,7 +66,8 @@ Definition sload : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -62,7 +76,8 @@ Definition sload : Value.t -> Value.t -> M := ], make_dict [] |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "get_storage" |), make_list [ @@ -71,7 +86,8 @@ Definition sload : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -99,7 +115,8 @@ Definition sstore : Value.t -> Value.t -> M := The current EVM frame. " in - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -110,16 +127,20 @@ Definition sstore : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in - let new_value := + |) + |) in + let _ := M.assign_local (| + "new_value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let current_value := + |) + |) in + let _ := M.assign_local (| + "current_value" , M.call (| M.get_name (| globals, "get_storage" |), make_list [ @@ -128,7 +149,8 @@ Definition sstore : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -146,13 +168,17 @@ Definition sstore : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let gas_cost := - M.get_name (| globals, "GAS_STORAGE_SET" |) in + let _ := M.assign_local (| + "gas_cost" , + M.get_name (| globals, "GAS_STORAGE_SET" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let gas_cost := - M.get_name (| globals, "GAS_STORAGE_UPDATE" |) in + let _ := M.assign_local (| + "gas_cost" , + M.get_name (| globals, "GAS_STORAGE_UPDATE" |) + |) in M.pure Constant.None_ )) |) in let _ := diff --git a/CoqOfPython/ethereum/frontier/vm/instructions/system.v b/CoqOfPython/ethereum/frontier/vm/instructions/system.v index c2e171c..35a1fee 100644 --- a/CoqOfPython/ethereum/frontier/vm/instructions/system.v +++ b/CoqOfPython/ethereum/frontier/vm/instructions/system.v @@ -17,29 +17,61 @@ Introduction Implementations of the EVM system related instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_frontier_fork_types_imports : - AreImported globals "ethereum.frontier.fork_types" [ "Address" ]. +Axiom ethereum_frontier_fork_types_imports_Address : + IsImported globals "ethereum.frontier.fork_types" "Address". -Axiom ethereum_frontier_state_imports : - AreImported globals "ethereum.frontier.state" [ "account_has_code_or_nonce"; "get_account"; "increment_nonce"; "set_account_balance" ]. +Axiom ethereum_frontier_state_imports_account_has_code_or_nonce : + IsImported globals "ethereum.frontier.state" "account_has_code_or_nonce". +Axiom ethereum_frontier_state_imports_get_account : + IsImported globals "ethereum.frontier.state" "get_account". +Axiom ethereum_frontier_state_imports_increment_nonce : + IsImported globals "ethereum.frontier.state" "increment_nonce". +Axiom ethereum_frontier_state_imports_set_account_balance : + IsImported globals "ethereum.frontier.state" "set_account_balance". -Axiom ethereum_frontier_utils_address_imports : - AreImported globals "ethereum.frontier.utils.address" [ "compute_contract_address"; "to_address" ]. +Axiom ethereum_frontier_utils_address_imports_compute_contract_address : + IsImported globals "ethereum.frontier.utils.address" "compute_contract_address". +Axiom ethereum_frontier_utils_address_imports_to_address : + IsImported globals "ethereum.frontier.utils.address" "to_address". -Axiom ethereum_frontier_vm_imports : - AreImported globals "ethereum.frontier.vm" [ "Evm"; "Message"; "incorporate_child_on_error"; "incorporate_child_on_success" ]. +Axiom ethereum_frontier_vm_imports_Evm : + IsImported globals "ethereum.frontier.vm" "Evm". +Axiom ethereum_frontier_vm_imports_Message : + IsImported globals "ethereum.frontier.vm" "Message". +Axiom ethereum_frontier_vm_imports_incorporate_child_on_error : + IsImported globals "ethereum.frontier.vm" "incorporate_child_on_error". +Axiom ethereum_frontier_vm_imports_incorporate_child_on_success : + IsImported globals "ethereum.frontier.vm" "incorporate_child_on_success". -Axiom ethereum_frontier_vm_gas_imports : - AreImported globals "ethereum.frontier.vm.gas" [ "GAS_CREATE"; "GAS_ZERO"; "REFUND_SELF_DESTRUCT"; "calculate_gas_extend_memory"; "calculate_message_call_gas"; "charge_gas" ]. +Axiom ethereum_frontier_vm_gas_imports_GAS_CREATE : + IsImported globals "ethereum.frontier.vm.gas" "GAS_CREATE". +Axiom ethereum_frontier_vm_gas_imports_GAS_ZERO : + IsImported globals "ethereum.frontier.vm.gas" "GAS_ZERO". +Axiom ethereum_frontier_vm_gas_imports_REFUND_SELF_DESTRUCT : + IsImported globals "ethereum.frontier.vm.gas" "REFUND_SELF_DESTRUCT". +Axiom ethereum_frontier_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.frontier.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_frontier_vm_gas_imports_calculate_message_call_gas : + IsImported globals "ethereum.frontier.vm.gas" "calculate_message_call_gas". +Axiom ethereum_frontier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.frontier.vm.gas" "charge_gas". -Axiom ethereum_frontier_vm_memory_imports : - AreImported globals "ethereum.frontier.vm.memory" [ "memory_read_bytes"; "memory_write" ]. +Axiom ethereum_frontier_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.frontier.vm.memory" "memory_read_bytes". +Axiom ethereum_frontier_vm_memory_imports_memory_write : + IsImported globals "ethereum.frontier.vm.memory" "memory_write". -Axiom ethereum_frontier_vm_stack_imports : - AreImported globals "ethereum.frontier.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_frontier_vm_stack_imports_pop : + IsImported globals "ethereum.frontier.vm.stack" "pop". +Axiom ethereum_frontier_vm_stack_imports_push : + IsImported globals "ethereum.frontier.vm.stack" "push". Definition create : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -53,31 +85,38 @@ Definition create : Value.t -> Value.t -> M := The current EVM frame. " in (* At stmt: unsupported node type: ImportFrom *) - let endowment := + let _ := M.assign_local (| + "endowment" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_size := + |) + |) in + let _ := M.assign_local (| + "memory_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -87,7 +126,8 @@ Definition create : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -99,8 +139,10 @@ Definition create : Value.t -> Value.t -> M := ], make_dict [] |) in - let create_message_gas := - M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) in + let _ := M.assign_local (| + "create_message_gas" , + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), M.call (| @@ -119,9 +161,12 @@ Definition create : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let sender_address := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in - let sender := + let _ := M.assign_local (| + "sender_address" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + |) in + let _ := M.assign_local (| + "sender" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -129,8 +174,10 @@ Definition create : Value.t -> Value.t -> M := M.get_name (| globals, "sender_address" |) ], make_dict [] - |) in - let contract_address := + |) + |) in + let _ := M.assign_local (| + "contract_address" , M.call (| M.get_name (| globals, "compute_contract_address" |), make_list [ @@ -145,7 +192,8 @@ Definition create : Value.t -> Value.t -> M := |), "nonce" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -246,7 +294,8 @@ Definition create : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let call_data := + let _ := M.assign_local (| + "call_data" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -255,7 +304,8 @@ Definition create : Value.t -> Value.t -> M := M.get_name (| globals, "memory_size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "increment_nonce" |), make_list [ @@ -264,13 +314,16 @@ Definition create : Value.t -> Value.t -> M := ], make_dict [] |) in - let child_message := + let _ := M.assign_local (| + "child_message" , M.call (| M.get_name (| globals, "Message" |), make_list [], make_dict [] - |) in - let child_evm := + |) + |) in + let _ := M.assign_local (| + "child_evm" , M.call (| M.get_name (| globals, "process_create_message" |), make_list [ @@ -278,7 +331,8 @@ Definition create : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -356,23 +410,28 @@ Definition return_ : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let memory_start_position := + let _ := M.assign_local (| + "memory_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_size := + |) + |) in + let _ := M.assign_local (| + "memory_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -382,7 +441,8 @@ Definition return_ : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -467,7 +527,8 @@ Definition generic_call : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let call_data := + let _ := M.assign_local (| + "call_data" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -476,8 +537,10 @@ Definition generic_call : Value.t -> Value.t -> M := M.get_name (| globals, "memory_input_size" |) ], make_dict [] - |) in - let code := + |) + |) in + let _ := M.assign_local (| + "code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -485,14 +548,18 @@ Definition generic_call : Value.t -> Value.t -> M := M.get_name (| globals, "code_address" |) ], make_dict [] - |), "code" |) in - let child_message := + |), "code" |) + |) in + let _ := M.assign_local (| + "child_message" , M.call (| M.get_name (| globals, "Message" |), make_list [], make_dict [] - |) in - let child_evm := + |) + |) in + let _ := M.assign_local (| + "child_evm" , M.call (| M.get_name (| globals, "process_message" |), make_list [ @@ -500,7 +567,8 @@ Definition generic_call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -556,7 +624,8 @@ Definition generic_call : Value.t -> Value.t -> M := |) in M.pure Constant.None_ )) |) in - let actual_output_size := + let _ := M.assign_local (| + "actual_output_size" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -576,7 +645,8 @@ Definition generic_call : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -604,7 +674,8 @@ Definition call : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -617,8 +688,10 @@ Definition call : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let to := + |) + |) in + let _ := M.assign_local (| + "to" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -631,48 +704,60 @@ Definition call : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -683,8 +768,10 @@ Definition call : Value.t -> Value.t -> M := ] ], make_dict [] - |) in - let message_call_gas := + |) + |) in + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -694,7 +781,8 @@ Definition call : Value.t -> Value.t -> M := M.get_name (| globals, "value" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -714,7 +802,8 @@ Definition call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let sender_balance := + let _ := M.assign_local (| + "sender_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -722,7 +811,8 @@ Definition call : Value.t -> Value.t -> M := M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := (* if *) M.if_then_else (| @@ -790,7 +880,8 @@ Definition callcode : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -803,8 +894,10 @@ Definition callcode : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let code_address := + |) + |) in + let _ := M.assign_local (| + "code_address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -817,50 +910,64 @@ Definition callcode : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let to := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "to" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -871,8 +978,10 @@ Definition callcode : Value.t -> Value.t -> M := ] ], make_dict [] - |) in - let message_call_gas := + |) + |) in + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -882,7 +991,8 @@ Definition callcode : Value.t -> Value.t -> M := M.get_name (| globals, "value" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -902,7 +1012,8 @@ Definition callcode : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let sender_balance := + let _ := M.assign_local (| + "sender_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -910,7 +1021,8 @@ Definition callcode : Value.t -> Value.t -> M := M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := (* if *) M.if_then_else (| @@ -978,7 +1090,8 @@ Definition selfdestruct : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let beneficiary := + let _ := M.assign_local (| + "beneficiary" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -991,15 +1104,24 @@ Definition selfdestruct : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let gas_cost := - M.get_name (| globals, "GAS_ZERO" |) in - let originator := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in - let refunded_accounts := - M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in - let parent_evm := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "parent_evm" |) in + |) + |) in + let _ := M.assign_local (| + "gas_cost" , + M.get_name (| globals, "GAS_ZERO" |) + |) in + let _ := M.assign_local (| + "originator" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + |) in + let _ := M.assign_local (| + "refunded_accounts" , + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) + |) in + let _ := M.assign_local (| + "parent_evm" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "parent_evm" |) + |) in let _ := M.while (| Compare.is_not (| @@ -1014,8 +1136,10 @@ Definition selfdestruct : Value.t -> Value.t -> M := ], make_dict [] |) in - let parent_evm := - M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in + let _ := M.assign_local (| + "parent_evm" , + M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -1049,7 +1173,8 @@ Definition selfdestruct : Value.t -> Value.t -> M := ], make_dict [] |) in - let beneficiary_balance := + let _ := M.assign_local (| + "beneficiary_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1057,8 +1182,10 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_name (| globals, "beneficiary" |) ], make_dict [] - |), "balance" |) in - let originator_balance := + |), "balance" |) + |) in + let _ := M.assign_local (| + "originator_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1066,7 +1193,8 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_name (| globals, "originator" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ diff --git a/CoqOfPython/ethereum/frontier/vm/interpreter.v b/CoqOfPython/ethereum/frontier/vm/interpreter.v index 5fb825a..e1d892f 100644 --- a/CoqOfPython/ethereum/frontier/vm/interpreter.v +++ b/CoqOfPython/ethereum/frontier/vm/interpreter.v @@ -17,47 +17,95 @@ Introduction A straightforward interpreter that executes EVM code. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Optional"; "Set"; "Tuple" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. - -Axiom ethereum_trace_imports : - AreImported globals "ethereum.trace" [ "EvmStop"; "OpEnd"; "OpException"; "OpStart"; "PrecompileEnd"; "PrecompileStart"; "TransactionEnd"; "evm_trace" ]. - -Axiom ethereum_frontier_blocks_imports : - AreImported globals "ethereum.frontier.blocks" [ "Log" ]. - -Axiom ethereum_frontier_fork_types_imports : - AreImported globals "ethereum.frontier.fork_types" [ "Address" ]. - -Axiom ethereum_frontier_state_imports : - AreImported globals "ethereum.frontier.state" [ "account_has_code_or_nonce"; "begin_transaction"; "commit_transaction"; "destroy_storage"; "move_ether"; "rollback_transaction"; "set_code"; "touch_account" ]. - -Axiom ethereum_frontier_vm_imports : - AreImported globals "ethereum.frontier.vm" [ "Message" ]. - -Axiom ethereum_frontier_vm_gas_imports : - AreImported globals "ethereum.frontier.vm.gas" [ "GAS_CODE_DEPOSIT"; "charge_gas" ]. - -Axiom ethereum_frontier_vm_precompiled_contracts_mapping_imports : - AreImported globals "ethereum.frontier.vm.precompiled_contracts.mapping" [ "PRE_COMPILED_CONTRACTS" ]. - -Axiom ethereum_frontier_vm_imports : - AreImported globals "ethereum.frontier.vm" [ "Environment"; "Evm" ]. - -Axiom ethereum_frontier_vm_exceptions_imports : - AreImported globals "ethereum.frontier.vm.exceptions" [ "AddressCollision"; "ExceptionalHalt"; "InvalidOpcode"; "StackDepthLimitError" ]. - -Axiom ethereum_frontier_vm_instructions_imports : - AreImported globals "ethereum.frontier.vm.instructions" [ "Ops"; "op_implementation" ]. - -Axiom ethereum_frontier_vm_runtime_imports : - AreImported globals "ethereum.frontier.vm.runtime" [ "get_valid_jump_destinations" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_trace_imports_EvmStop : + IsImported globals "ethereum.trace" "EvmStop". +Axiom ethereum_trace_imports_OpEnd : + IsImported globals "ethereum.trace" "OpEnd". +Axiom ethereum_trace_imports_OpException : + IsImported globals "ethereum.trace" "OpException". +Axiom ethereum_trace_imports_OpStart : + IsImported globals "ethereum.trace" "OpStart". +Axiom ethereum_trace_imports_PrecompileEnd : + IsImported globals "ethereum.trace" "PrecompileEnd". +Axiom ethereum_trace_imports_PrecompileStart : + IsImported globals "ethereum.trace" "PrecompileStart". +Axiom ethereum_trace_imports_TransactionEnd : + IsImported globals "ethereum.trace" "TransactionEnd". +Axiom ethereum_trace_imports_evm_trace : + IsImported globals "ethereum.trace" "evm_trace". + +Axiom ethereum_frontier_blocks_imports_Log : + IsImported globals "ethereum.frontier.blocks" "Log". + +Axiom ethereum_frontier_fork_types_imports_Address : + IsImported globals "ethereum.frontier.fork_types" "Address". + +Axiom ethereum_frontier_state_imports_account_has_code_or_nonce : + IsImported globals "ethereum.frontier.state" "account_has_code_or_nonce". +Axiom ethereum_frontier_state_imports_begin_transaction : + IsImported globals "ethereum.frontier.state" "begin_transaction". +Axiom ethereum_frontier_state_imports_commit_transaction : + IsImported globals "ethereum.frontier.state" "commit_transaction". +Axiom ethereum_frontier_state_imports_destroy_storage : + IsImported globals "ethereum.frontier.state" "destroy_storage". +Axiom ethereum_frontier_state_imports_move_ether : + IsImported globals "ethereum.frontier.state" "move_ether". +Axiom ethereum_frontier_state_imports_rollback_transaction : + IsImported globals "ethereum.frontier.state" "rollback_transaction". +Axiom ethereum_frontier_state_imports_set_code : + IsImported globals "ethereum.frontier.state" "set_code". +Axiom ethereum_frontier_state_imports_touch_account : + IsImported globals "ethereum.frontier.state" "touch_account". + +Axiom ethereum_frontier_vm_imports_Message : + IsImported globals "ethereum.frontier.vm" "Message". + +Axiom ethereum_frontier_vm_gas_imports_GAS_CODE_DEPOSIT : + IsImported globals "ethereum.frontier.vm.gas" "GAS_CODE_DEPOSIT". +Axiom ethereum_frontier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.frontier.vm.gas" "charge_gas". + +Axiom ethereum_frontier_vm_precompiled_contracts_mapping_imports_PRE_COMPILED_CONTRACTS : + IsImported globals "ethereum.frontier.vm.precompiled_contracts.mapping" "PRE_COMPILED_CONTRACTS". + +Axiom ethereum_frontier_vm_imports_Environment : + IsImported globals "ethereum.frontier.vm" "Environment". +Axiom ethereum_frontier_vm_imports_Evm : + IsImported globals "ethereum.frontier.vm" "Evm". + +Axiom ethereum_frontier_vm_exceptions_imports_AddressCollision : + IsImported globals "ethereum.frontier.vm.exceptions" "AddressCollision". +Axiom ethereum_frontier_vm_exceptions_imports_ExceptionalHalt : + IsImported globals "ethereum.frontier.vm.exceptions" "ExceptionalHalt". +Axiom ethereum_frontier_vm_exceptions_imports_InvalidOpcode : + IsImported globals "ethereum.frontier.vm.exceptions" "InvalidOpcode". +Axiom ethereum_frontier_vm_exceptions_imports_StackDepthLimitError : + IsImported globals "ethereum.frontier.vm.exceptions" "StackDepthLimitError". + +Axiom ethereum_frontier_vm_instructions_imports_Ops : + IsImported globals "ethereum.frontier.vm.instructions" "Ops". +Axiom ethereum_frontier_vm_instructions_imports_op_implementation : + IsImported globals "ethereum.frontier.vm.instructions" "op_implementation". + +Axiom ethereum_frontier_vm_runtime_imports_get_valid_jump_destinations : + IsImported globals "ethereum.frontier.vm.runtime" "get_valid_jump_destinations". Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -114,7 +162,8 @@ Definition process_message_call : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let is_collision := + let _ := M.assign_local (| + "is_collision" , M.call (| M.get_name (| globals, "account_has_code_or_nonce" |), make_list [ @@ -122,7 +171,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "message" |), "current_target" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -169,7 +219,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "process_create_message" |), make_list [ @@ -177,13 +228,15 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "process_message" |), make_list [ @@ -191,7 +244,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := @@ -201,32 +255,43 @@ Definition process_message_call : Value.t -> Value.t -> M := (* then *) ltac:(M.monadic ( (* At stmt: unsupported node type: AnnAssign *) - let accounts_to_delete := + let _ := M.assign_local (| + "accounts_to_delete" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let refund_counter := + |) + |) in + let _ := M.assign_local (| + "refund_counter" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let logs := - M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in - let accounts_to_delete := - M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in - let refund_counter := - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |) in + let _ := M.assign_local (| + "logs" , + M.get_field (| M.get_name (| globals, "evm" |), "logs" |) + |) in + let _ := M.assign_local (| + "accounts_to_delete" , + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) + |) in + let _ := M.assign_local (| + "refund_counter" , + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |) + |) in M.pure Constant.None_ )) |) in - let tx_end := + let _ := M.assign_local (| + "tx_end" , M.call (| M.get_name (| globals, "TransactionEnd" |), make_list [ @@ -238,7 +303,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "error" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "evm_trace" |), make_list [ @@ -289,7 +355,8 @@ Definition process_create_message : Value.t -> Value.t -> M := ], make_dict [] |) in - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "process_message" |), make_list [ @@ -297,16 +364,20 @@ Definition process_create_message : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), (* then *) ltac:(M.monadic ( - let contract_code := - M.get_field (| M.get_name (| globals, "evm" |), "output" |) in - let contract_code_gas := + let _ := M.assign_local (| + "contract_code" , + M.get_field (| M.get_name (| globals, "evm" |), "output" |) + |) in + let _ := M.assign_local (| + "contract_code_gas" , BinOp.mult (| M.call (| M.get_name (| globals, "len" |), @@ -316,7 +387,8 @@ Definition process_create_message : Value.t -> Value.t -> M := make_dict [] |), M.get_name (| globals, "GAS_CODE_DEPOSIT" |) - |) in + |) + |) in (* At stmt: unsupported node type: Try *) let _ := M.call (| M.get_name (| globals, "commit_transaction" |), @@ -420,7 +492,8 @@ Definition process_message : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "execute_code" |), make_list [ @@ -428,7 +501,8 @@ Definition process_message : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -477,22 +551,28 @@ Definition execute_code : Value.t -> Value.t -> M := evm: `ethereum.vm.EVM` Items containing execution specific objects " in - let code := - M.get_field (| M.get_name (| globals, "message" |), "code" |) in - let valid_jump_destinations := + let _ := M.assign_local (| + "code" , + M.get_field (| M.get_name (| globals, "message" |), "code" |) + |) in + let _ := M.assign_local (| + "valid_jump_destinations" , M.call (| M.get_name (| globals, "get_valid_jump_destinations" |), make_list [ M.get_name (| globals, "code" |) ], make_dict [] - |) in - let evm := + |) + |) in + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "Evm" |), make_list [], make_dict [] - |) in + |) + |) in (* At stmt: unsupported node type: Try *) let _ := M.return_ (| M.get_name (| globals, "evm" |) diff --git a/CoqOfPython/ethereum/frontier/vm/memory.v b/CoqOfPython/ethereum/frontier/vm/memory.v index 280775b..be21aab 100644 --- a/CoqOfPython/ethereum/frontier/vm/memory.v +++ b/CoqOfPython/ethereum/frontier/vm/memory.v @@ -17,11 +17,15 @@ Introduction EVM memory operations. ". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "right_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_right_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "right_pad_zero_bytes". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". Definition memory_write : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/__init__.v index ff4dfb5..34b3b7b 100644 --- a/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/__init__.v +++ b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/__init__.v @@ -18,8 +18,8 @@ Addresses of precompiled contracts and mappings to their implementations. ". -Axiom ethereum_frontier_utils_hexadecimal_imports : - AreImported globals "ethereum.frontier.utils.hexadecimal" [ "hex_to_address" ]. +Axiom ethereum_frontier_utils_hexadecimal_imports_hex_to_address : + IsImported globals "ethereum.frontier.utils.hexadecimal" "hex_to_address". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS" ] diff --git a/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/ecrecover.v index a76cd62..6f8de26 100644 --- a/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/ecrecover.v @@ -17,26 +17,32 @@ Introduction Implementation of the ECRECOVER precompiled contract. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_crypto_elliptic_curve_imports : - AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. +Axiom ethereum_crypto_elliptic_curve_imports_SECP256K1N : + IsImported globals "ethereum.crypto.elliptic_curve" "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_imports_secp256k1_recover : + IsImported globals "ethereum.crypto.elliptic_curve" "secp256k1_recover". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_left_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "left_pad_zero_bytes". -Axiom ethereum_frontier_vm_imports : - AreImported globals "ethereum.frontier.vm" [ "Evm" ]. +Axiom ethereum_frontier_vm_imports_Evm : + IsImported globals "ethereum.frontier.vm" "Evm". -Axiom ethereum_frontier_vm_gas_imports : - AreImported globals "ethereum.frontier.vm.gas" [ "GAS_ECRECOVER"; "charge_gas" ]. +Axiom ethereum_frontier_vm_gas_imports_GAS_ECRECOVER : + IsImported globals "ethereum.frontier.vm.gas" "GAS_ECRECOVER". +Axiom ethereum_frontier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.frontier.vm.gas" "charge_gas". -Axiom ethereum_frontier_vm_memory_imports : - AreImported globals "ethereum.frontier.vm.memory" [ "buffer_read" ]. +Axiom ethereum_frontier_vm_memory_imports_buffer_read : + IsImported globals "ethereum.frontier.vm.memory" "buffer_read". Definition ecrecover : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -50,8 +56,10 @@ Definition ecrecover : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -60,7 +68,8 @@ Definition ecrecover : Value.t -> Value.t -> M := ], make_dict [] |) in - let message_hash_bytes := + let _ := M.assign_local (| + "message_hash_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -81,16 +90,20 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let message_hash := + |) + |) in + let _ := M.assign_local (| + "message_hash" , M.call (| M.get_name (| globals, "Hash32" |), make_list [ M.get_name (| globals, "message_hash_bytes" |) ], make_dict [] - |) in - let v := + |) + |) in + let _ := M.assign_local (| + "v" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -117,8 +130,10 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let r := + |) + |) in + let _ := M.assign_local (| + "r" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -145,8 +160,10 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let s := + |) + |) in + let _ := M.assign_local (| + "s" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -173,7 +190,8 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -250,7 +268,8 @@ Definition ecrecover : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: Try *) - let address := + let _ := M.assign_local (| + "address" , M.slice (| M.call (| M.get_name (| globals, "keccak256" |), @@ -262,8 +281,10 @@ Definition ecrecover : Value.t -> Value.t -> M := Constant.int 12, Constant.int 32, Constant.None_ - |) in - let padded_address := + |) + |) in + let _ := M.assign_local (| + "padded_address" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -271,7 +292,8 @@ Definition ecrecover : Value.t -> Value.t -> M := Constant.int 32 ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.get_name (| globals, "padded_address" |) diff --git a/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/identity.v index e03db13..ff7bb79 100644 --- a/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/identity.v +++ b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/identity.v @@ -17,17 +17,21 @@ Introduction Implementation of the `IDENTITY` precompiled contract. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_frontier_vm_imports : - AreImported globals "ethereum.frontier.vm" [ "Evm" ]. +Axiom ethereum_frontier_vm_imports_Evm : + IsImported globals "ethereum.frontier.vm" "Evm". -Axiom ethereum_frontier_vm_gas_imports : - AreImported globals "ethereum.frontier.vm.gas" [ "GAS_IDENTITY"; "GAS_IDENTITY_WORD"; "charge_gas" ]. +Axiom ethereum_frontier_vm_gas_imports_GAS_IDENTITY : + IsImported globals "ethereum.frontier.vm.gas" "GAS_IDENTITY". +Axiom ethereum_frontier_vm_gas_imports_GAS_IDENTITY_WORD : + IsImported globals "ethereum.frontier.vm.gas" "GAS_IDENTITY_WORD". +Axiom ethereum_frontier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.frontier.vm.gas" "charge_gas". Definition identity : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -40,9 +44,12 @@ Definition identity : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let word_count := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "word_count" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -64,7 +71,8 @@ Definition identity : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ diff --git a/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/mapping.v index e1e4110..f2f606e 100644 --- a/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/mapping.v +++ b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/mapping.v @@ -17,25 +17,33 @@ Introduction Mapping of precompiled contracts their implementations. ". -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict" ]. - -Axiom ethereum_frontier_fork_types_imports : - AreImported globals "ethereum.frontier.fork_types" [ "Address" ]. - -Axiom ethereum_frontier_vm_precompiled_contracts_imports : - AreImported globals "ethereum.frontier.vm.precompiled_contracts" [ "ECRECOVER_ADDRESS"; "IDENTITY_ADDRESS"; "RIPEMD160_ADDRESS"; "SHA256_ADDRESS" ]. - -Axiom ethereum_frontier_vm_precompiled_contracts_ecrecover_imports : - AreImported globals "ethereum.frontier.vm.precompiled_contracts.ecrecover" [ "ecrecover" ]. - -Axiom ethereum_frontier_vm_precompiled_contracts_identity_imports : - AreImported globals "ethereum.frontier.vm.precompiled_contracts.identity" [ "identity" ]. - -Axiom ethereum_frontier_vm_precompiled_contracts_ripemd160_imports : - AreImported globals "ethereum.frontier.vm.precompiled_contracts.ripemd160" [ "ripemd160" ]. - -Axiom ethereum_frontier_vm_precompiled_contracts_sha256_imports : - AreImported globals "ethereum.frontier.vm.precompiled_contracts.sha256" [ "sha256" ]. +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". + +Axiom ethereum_frontier_fork_types_imports_Address : + IsImported globals "ethereum.frontier.fork_types" "Address". + +Axiom ethereum_frontier_vm_precompiled_contracts_imports_ECRECOVER_ADDRESS : + IsImported globals "ethereum.frontier.vm.precompiled_contracts" "ECRECOVER_ADDRESS". +Axiom ethereum_frontier_vm_precompiled_contracts_imports_IDENTITY_ADDRESS : + IsImported globals "ethereum.frontier.vm.precompiled_contracts" "IDENTITY_ADDRESS". +Axiom ethereum_frontier_vm_precompiled_contracts_imports_RIPEMD160_ADDRESS : + IsImported globals "ethereum.frontier.vm.precompiled_contracts" "RIPEMD160_ADDRESS". +Axiom ethereum_frontier_vm_precompiled_contracts_imports_SHA256_ADDRESS : + IsImported globals "ethereum.frontier.vm.precompiled_contracts" "SHA256_ADDRESS". + +Axiom ethereum_frontier_vm_precompiled_contracts_ecrecover_imports_ecrecover : + IsImported globals "ethereum.frontier.vm.precompiled_contracts.ecrecover" "ecrecover". + +Axiom ethereum_frontier_vm_precompiled_contracts_identity_imports_identity : + IsImported globals "ethereum.frontier.vm.precompiled_contracts.identity" "identity". + +Axiom ethereum_frontier_vm_precompiled_contracts_ripemd160_imports_ripemd160 : + IsImported globals "ethereum.frontier.vm.precompiled_contracts.ripemd160" "ripemd160". + +Axiom ethereum_frontier_vm_precompiled_contracts_sha256_imports_sha256 : + IsImported globals "ethereum.frontier.vm.precompiled_contracts.sha256" "sha256". (* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/ripemd160.v index a95ac84..3f3bbd6 100644 --- a/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/ripemd160.v +++ b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/ripemd160.v @@ -19,20 +19,24 @@ Implementation of the `RIPEMD160` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_left_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "left_pad_zero_bytes". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_frontier_vm_imports : - AreImported globals "ethereum.frontier.vm" [ "Evm" ]. +Axiom ethereum_frontier_vm_imports_Evm : + IsImported globals "ethereum.frontier.vm" "Evm". -Axiom ethereum_frontier_vm_gas_imports : - AreImported globals "ethereum.frontier.vm.gas" [ "GAS_RIPEMD160"; "GAS_RIPEMD160_WORD"; "charge_gas" ]. +Axiom ethereum_frontier_vm_gas_imports_GAS_RIPEMD160 : + IsImported globals "ethereum.frontier.vm.gas" "GAS_RIPEMD160". +Axiom ethereum_frontier_vm_gas_imports_GAS_RIPEMD160_WORD : + IsImported globals "ethereum.frontier.vm.gas" "GAS_RIPEMD160_WORD". +Axiom ethereum_frontier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.frontier.vm.gas" "charge_gas". Definition ripemd160 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,9 +49,12 @@ Definition ripemd160 : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let word_count := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "word_count" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -69,7 +76,8 @@ Definition ripemd160 : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -84,7 +92,8 @@ Definition ripemd160 : Value.t -> Value.t -> M := ], make_dict [] |) in - let hash_bytes := + let _ := M.assign_local (| + "hash_bytes" , M.call (| M.get_field (| M.call (| M.get_field (| M.get_name (| globals, "hashlib" |), "new" |), @@ -96,8 +105,10 @@ Definition ripemd160 : Value.t -> Value.t -> M := |), "digest" |), make_list [], make_dict [] - |) in - let padded_hash := + |) + |) in + let _ := M.assign_local (| + "padded_hash" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -105,7 +116,8 @@ Definition ripemd160 : Value.t -> Value.t -> M := Constant.int 32 ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.get_name (| globals, "padded_hash" |) diff --git a/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/sha256.v index 941dbb4..e72a688 100644 --- a/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/sha256.v +++ b/CoqOfPython/ethereum/frontier/vm/precompiled_contracts/sha256.v @@ -19,17 +19,21 @@ Implementation of the `SHA256` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_frontier_vm_imports : - AreImported globals "ethereum.frontier.vm" [ "Evm" ]. +Axiom ethereum_frontier_vm_imports_Evm : + IsImported globals "ethereum.frontier.vm" "Evm". -Axiom ethereum_frontier_vm_gas_imports : - AreImported globals "ethereum.frontier.vm.gas" [ "GAS_SHA256"; "GAS_SHA256_WORD"; "charge_gas" ]. +Axiom ethereum_frontier_vm_gas_imports_GAS_SHA256 : + IsImported globals "ethereum.frontier.vm.gas" "GAS_SHA256". +Axiom ethereum_frontier_vm_gas_imports_GAS_SHA256_WORD : + IsImported globals "ethereum.frontier.vm.gas" "GAS_SHA256_WORD". +Axiom ethereum_frontier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.frontier.vm.gas" "charge_gas". Definition sha256 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,9 +46,12 @@ Definition sha256 : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let word_count := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "word_count" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -66,7 +73,8 @@ Definition sha256 : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ diff --git a/CoqOfPython/ethereum/frontier/vm/runtime.v b/CoqOfPython/ethereum/frontier/vm/runtime.v index 6e7e96d..316e3e2 100644 --- a/CoqOfPython/ethereum/frontier/vm/runtime.v +++ b/CoqOfPython/ethereum/frontier/vm/runtime.v @@ -17,14 +17,14 @@ Introduction Runtime related operations used while executing EVM code. ". -Axiom typing_imports : - AreImported globals "typing" [ "Set" ]. +Axiom typing_imports_Set : + IsImported globals "typing" "Set". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_frontier_vm_instructions_imports : - AreImported globals "ethereum.frontier.vm.instructions" [ "Ops" ]. +Axiom ethereum_frontier_vm_instructions_imports_Ops : + IsImported globals "ethereum.frontier.vm.instructions" "Ops". Definition get_valid_jump_destinations : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -50,20 +50,24 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := valid_jump_destinations: `Set[Uint]` The set of valid jump destinations in the code. " in - let valid_jump_destinations := + let _ := M.assign_local (| + "valid_jump_destinations" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let pc := + |) + |) in + let _ := M.assign_local (| + "pc" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in let _ := M.while (| Compare.lt (| @@ -114,17 +118,21 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let push_data_size := + let _ := M.assign_local (| + "push_data_size" , BinOp.add (| BinOp.sub (| M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) |), Constant.int 1 - |) in - let pc := BinOp.add + |) + |) in + let _ := M.assign_op_local (| + BinOp.add, + "pc", M.get_name (| globals, "push_data_size" |) - M.get_name (| globals, "push_data_size" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -132,9 +140,11 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - let pc := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "pc", Constant.int 1 - Constant.int 1 in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/frontier/vm/stack.v b/CoqOfPython/ethereum/frontier/vm/stack.v index 797e688..875e1e7 100644 --- a/CoqOfPython/ethereum/frontier/vm/stack.v +++ b/CoqOfPython/ethereum/frontier/vm/stack.v @@ -17,14 +17,16 @@ Introduction Implementation of the stack operators for the EVM. ". -Axiom typing_imports : - AreImported globals "typing" [ "List" ]. +Axiom typing_imports_List : + IsImported globals "typing" "List". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_frontier_vm_exceptions_imports : - AreImported globals "ethereum.frontier.vm.exceptions" [ "StackOverflowError"; "StackUnderflowError" ]. +Axiom ethereum_frontier_vm_exceptions_imports_StackOverflowError : + IsImported globals "ethereum.frontier.vm.exceptions" "StackOverflowError". +Axiom ethereum_frontier_vm_exceptions_imports_StackUnderflowError : + IsImported globals "ethereum.frontier.vm.exceptions" "StackUnderflowError". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/genesis.v b/CoqOfPython/ethereum/genesis.v index 9c3bac3..cd70564 100644 --- a/CoqOfPython/ethereum/genesis.v +++ b/CoqOfPython/ethereum/genesis.v @@ -22,20 +22,44 @@ different chains. (* At top_level_stmt: unsupported node type: Import *) -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". -Axiom typing_imports : - AreImported globals "typing" [ "Any"; "Dict"; "cast" ]. +Axiom typing_imports_Any : + IsImported globals "typing" "Any". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". +Axiom typing_imports_cast : + IsImported globals "typing" "cast". -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U64"; "U256"; "Bytes"; "Bytes8"; "Bytes20"; "Uint"; "slotted_freezable" ]. +Axiom ethereum_base_types_imports_U64 : + IsImported globals "ethereum.base_types" "U64". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes8 : + IsImported globals "ethereum.base_types" "Bytes8". +Axiom ethereum_base_types_imports_Bytes20 : + IsImported globals "ethereum.base_types" "Bytes20". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". -Axiom ethereum_utils_hexadecimal_imports : - AreImported globals "ethereum.utils.hexadecimal" [ "hex_to_bytes"; "hex_to_bytes8"; "hex_to_bytes32"; "hex_to_u256"; "hex_to_uint" ]. +Axiom ethereum_utils_hexadecimal_imports_hex_to_bytes : + IsImported globals "ethereum.utils.hexadecimal" "hex_to_bytes". +Axiom ethereum_utils_hexadecimal_imports_hex_to_bytes8 : + IsImported globals "ethereum.utils.hexadecimal" "hex_to_bytes8". +Axiom ethereum_utils_hexadecimal_imports_hex_to_bytes32 : + IsImported globals "ethereum.utils.hexadecimal" "hex_to_bytes32". +Axiom ethereum_utils_hexadecimal_imports_hex_to_u256 : + IsImported globals "ethereum.utils.hexadecimal" "hex_to_u256". +Axiom ethereum_utils_hexadecimal_imports_hex_to_uint : + IsImported globals "ethereum.utils.hexadecimal" "hex_to_uint". Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) @@ -70,7 +94,8 @@ Definition get_genesis_configuration : Value.t -> Value.t -> M := configuration : `GenesisConfiguration` The genesis configuration obtained from the json genesis file. " in - let genesis_str_data := + let _ := M.assign_local (| + "genesis_str_data" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "cast" |), @@ -89,15 +114,18 @@ Definition get_genesis_configuration : Value.t -> Value.t -> M := |), "decode" |), make_list [], make_dict [] - |) in - let genesis_data := + |) + |) in + let _ := M.assign_local (| + "genesis_data" , M.call (| M.get_field (| M.get_name (| globals, "json" |), "loads" |), make_list [ M.get_name (| globals, "genesis_str_data" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "GenesisConfiguration" |), @@ -181,12 +209,12 @@ Definition add_genesis_block : Value.t -> Value.t -> M := low gas limit made sending transactions impossible in the early stages of Frontier. - The `nonce` field is `0x42` referencing Douglas Adams' """HitchHiker's Guide - to the Galaxy""". + The `nonce` field is `0x42` referencing Douglas Adams' ""HitchHiker's Guide + to the Galaxy"". The `extra_data` field contains the hash of block `1028201` on the pre-launch Olympus testnet. The creation of block `1028201` on Olympus - marked the """starting gun""" for Ethereum block creation. Including its hash + marked the ""starting gun"" for Ethereum block creation. Including its hash in the genesis block ensured a fair launch of the Ethereum mining process. The remaining fields are set to appropriate default values. @@ -213,14 +241,16 @@ Definition add_genesis_block : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_field (| M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "utils" |), "hexadecimal" |), "hex_to_address" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "state" |), "set_account" |), make_list [ @@ -291,7 +321,7 @@ Definition add_genesis_block : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "account" |), "get" |), make_list [ Constant.str "storage"; - {} + Constant.str "(* At expr: unsupported node type: Dict *)" ], make_dict [] |), "items" |), @@ -333,85 +363,10 @@ Definition add_genesis_block : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let fields := - {Constant.str "parent_hash": M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "fork_types" |), "Hash32" |), - make_list [ - BinOp.mult (| - Constant.bytes "00", - Constant.int 32 - |) - ], - make_dict [] - |), Constant.str "ommers_hash": M.call (| - M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), - make_list [ - make_tuple [ ] - ], - make_dict [] - |), Constant.str "coinbase": M.call (| - M.get_name (| globals, "Address" |), - make_list [ - BinOp.mult (| - Constant.bytes "00", - Constant.int 20 - |) - ], - make_dict [] - |), Constant.str "state_root": M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "state" |), "state_root" |), - make_list [ - M.get_field (| M.get_name (| globals, "chain" |), "state" |) - ], - make_dict [] - |), Constant.str "transactions_root": M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "trie" |), "root" |), - make_list [ - M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "trie" |), "Trie" |), - make_list [ - Constant.bool false; - Constant.None_ - ], - make_dict [] - |) - ], - make_dict [] - |), Constant.str "receipt_root": M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "trie" |), "root" |), - make_list [ - M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "trie" |), "Trie" |), - make_list [ - Constant.bool false; - Constant.None_ - ], - make_dict [] - |) - ], - make_dict [] - |), Constant.str "bloom": M.call (| - M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "fork_types" |), "Bloom" |), - make_list [ - BinOp.mult (| - Constant.bytes "00", - Constant.int 256 - |) - ], - make_dict [] - |), Constant.str "difficulty": M.get_field (| M.get_name (| globals, "genesis" |), "difficulty" |), Constant.str "number": M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |), Constant.str "gas_limit": M.get_field (| M.get_name (| globals, "genesis" |), "gas_limit" |), Constant.str "gas_used": M.call (| - M.get_name (| globals, "Uint" |), - make_list [ - Constant.int 0 - ], - make_dict [] - |), Constant.str "timestamp": M.get_field (| M.get_name (| globals, "genesis" |), "timestamp" |), Constant.str "extra_data": M.get_field (| M.get_name (| globals, "genesis" |), "extra_data" |), Constant.str "nonce": M.get_field (| M.get_name (| globals, "genesis" |), "nonce" |)} in + let _ := M.assign_local (| + "fields" , + Constant.str "(* At expr: unsupported node type: Dict *)" + |) in let _ := (* if *) M.if_then_else (| @@ -496,18 +451,22 @@ Definition add_genesis_block : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let genesis_header := + let _ := M.assign_local (| + "genesis_header" , M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "blocks" |), "Header" |), make_list [], make_dict [] - |) in - let genesis_block := + |) + |) in + let _ := M.assign_local (| + "genesis_block" , M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "hardfork" |), "blocks" |), "Block" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), "append" |), make_list [ diff --git a/CoqOfPython/ethereum/gray_glacier/__init__.v b/CoqOfPython/ethereum/gray_glacier/__init__.v index 63786a4..214f63d 100644 --- a/CoqOfPython/ethereum/gray_glacier/__init__.v +++ b/CoqOfPython/ethereum/gray_glacier/__init__.v @@ -8,8 +8,8 @@ The Gray Glacier fork delays the difficulty bomb. There are no other changes in this fork. ". -Axiom ethereum_fork_criteria_imports : - AreImported globals "ethereum.fork_criteria" [ "ByBlockNumber" ]. +Axiom ethereum_fork_criteria_imports_ByBlockNumber : + IsImported globals "ethereum.fork_criteria" "ByBlockNumber". Definition FORK_CRITERIA : Value.t := M.run ltac:(M.monadic ( M.call (| diff --git a/CoqOfPython/ethereum/gray_glacier/blocks.v b/CoqOfPython/ethereum/gray_glacier/blocks.v index 0845cef..04f7678 100644 --- a/CoqOfPython/ethereum/gray_glacier/blocks.v +++ b/CoqOfPython/ethereum/gray_glacier/blocks.v @@ -14,23 +14,39 @@ history of all state transitions that have happened since the genesis of the chain. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Tuple"; "Union" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes8"; "Bytes32"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. - -Axiom ethereum_gray_glacier_fork_types_imports : - AreImported globals "ethereum.gray_glacier.fork_types" [ "Address"; "Bloom"; "Root" ]. - -Axiom ethereum_gray_glacier_transactions_imports : - AreImported globals "ethereum.gray_glacier.transactions" [ "LegacyTransaction" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes8 : + IsImported globals "ethereum.base_types" "Bytes8". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". + +Axiom ethereum_gray_glacier_fork_types_imports_Address : + IsImported globals "ethereum.gray_glacier.fork_types" "Address". +Axiom ethereum_gray_glacier_fork_types_imports_Bloom : + IsImported globals "ethereum.gray_glacier.fork_types" "Bloom". +Axiom ethereum_gray_glacier_fork_types_imports_Root : + IsImported globals "ethereum.gray_glacier.fork_types" "Root". + +Axiom ethereum_gray_glacier_transactions_imports_LegacyTransaction : + IsImported globals "ethereum.gray_glacier.transactions" "LegacyTransaction". Definition Header : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/gray_glacier/bloom.v b/CoqOfPython/ethereum/gray_glacier/bloom.v index b87575c..d2b450d 100644 --- a/CoqOfPython/ethereum/gray_glacier/bloom.v +++ b/CoqOfPython/ethereum/gray_glacier/bloom.v @@ -21,20 +21,20 @@ for efficient searching of logs by address and/or topic, by rapidly eliminating blocks and receipts from their search. ". -Axiom typing_imports : - AreImported globals "typing" [ "Tuple" ]. +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_gray_glacier_blocks_imports : - AreImported globals "ethereum.gray_glacier.blocks" [ "Log" ]. +Axiom ethereum_gray_glacier_blocks_imports_Log : + IsImported globals "ethereum.gray_glacier.blocks" "Log". -Axiom ethereum_gray_glacier_fork_types_imports : - AreImported globals "ethereum.gray_glacier.fork_types" [ "Bloom" ]. +Axiom ethereum_gray_glacier_fork_types_imports_Bloom : + IsImported globals "ethereum.gray_glacier.fork_types" "Bloom". Definition add_to_bloom : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -53,20 +53,23 @@ Definition add_to_bloom : Value.t -> Value.t -> M := bloom_entry : An entry which is to be added to bloom filter. " in - let hash := + let _ := M.assign_local (| + "hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "bloom_entry" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "idx" |), make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ], ltac:(M.monadic ( - let bit_to_set := + let _ := M.assign_local (| + "bit_to_set" , BinOp.bit_and (| M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), @@ -84,18 +87,24 @@ Definition add_to_bloom : Value.t -> Value.t -> M := make_dict [] |), Constant.int 2047 - |) in - let bit_index := + |) + |) in + let _ := M.assign_local (| + "bit_index" , BinOp.sub (| Constant.int 2047, M.get_name (| globals, "bit_to_set" |) - |) in - let byte_index := + |) + |) in + let _ := M.assign_local (| + "byte_index" , BinOp.floor_div (| M.get_name (| globals, "bit_index" |), Constant.int 8 - |) in - let bit_value := + |) + |) in + let _ := M.assign_local (| + "bit_value" , BinOp.l_shift (| Constant.int 1, BinOp.sub (| @@ -105,7 +114,8 @@ Definition add_to_bloom : Value.t -> Value.t -> M := Constant.int 8 |) |) - |) in + |) + |) in let _ := M.assign (| M.get_subscript (| M.get_name (| globals, "bloom" |), diff --git a/CoqOfPython/ethereum/gray_glacier/fork.v b/CoqOfPython/ethereum/gray_glacier/fork.v index 09ccc1f..0bd20df 100644 --- a/CoqOfPython/ethereum/gray_glacier/fork.v +++ b/CoqOfPython/ethereum/gray_glacier/fork.v @@ -17,62 +17,136 @@ Introduction Entry point for the Ethereum specification. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple"; "Union" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Bytes0" ]. - -Axiom ethereum_crypto_elliptic_curve_imports : - AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. - -Axiom ethereum_ethash_imports : - AreImported globals "ethereum.ethash" [ "dataset_size"; "generate_cache"; "hashimoto_light" ]. - -Axiom ethereum_exceptions_imports : - AreImported globals "ethereum.exceptions" [ "InvalidBlock" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U64"; "U256"; "U256_CEIL_VALUE"; "Bytes"; "Uint" ]. - -Axiom ethereum_gray_glacier_imports : - AreImported globals "ethereum.gray_glacier" [ "vm" ]. - -Axiom ethereum_gray_glacier_blocks_imports : - AreImported globals "ethereum.gray_glacier.blocks" [ "Block"; "Header"; "Log"; "Receipt" ]. - -Axiom ethereum_gray_glacier_bloom_imports : - AreImported globals "ethereum.gray_glacier.bloom" [ "logs_bloom" ]. - -Axiom ethereum_gray_glacier_fork_types_imports : - AreImported globals "ethereum.gray_glacier.fork_types" [ "Address"; "Bloom"; "Root" ]. - -Axiom ethereum_gray_glacier_state_imports : - AreImported globals "ethereum.gray_glacier.state" [ "State"; "account_exists_and_is_empty"; "create_ether"; "destroy_account"; "get_account"; "increment_nonce"; "set_account_balance"; "state_root" ]. - -Axiom ethereum_gray_glacier_transactions_imports : - AreImported globals "ethereum.gray_glacier.transactions" [ "TX_ACCESS_LIST_ADDRESS_COST"; "TX_ACCESS_LIST_STORAGE_KEY_COST"; "TX_BASE_COST"; "TX_CREATE_COST"; "TX_DATA_COST_PER_NON_ZERO"; "TX_DATA_COST_PER_ZERO"; "AccessListTransaction"; "FeeMarketTransaction"; "LegacyTransaction"; "Transaction"; "decode_transaction"; "encode_transaction" ]. - -Axiom ethereum_gray_glacier_trie_imports : - AreImported globals "ethereum.gray_glacier.trie" [ "Trie"; "root"; "trie_set" ]. - -Axiom ethereum_gray_glacier_utils_message_imports : - AreImported globals "ethereum.gray_glacier.utils.message" [ "prepare_message" ]. - -Axiom ethereum_gray_glacier_vm_interpreter_imports : - AreImported globals "ethereum.gray_glacier.vm.interpreter" [ "process_message_call" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". + +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". + +Axiom ethereum_crypto_elliptic_curve_imports_SECP256K1N : + IsImported globals "ethereum.crypto.elliptic_curve" "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_imports_secp256k1_recover : + IsImported globals "ethereum.crypto.elliptic_curve" "secp256k1_recover". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". + +Axiom ethereum_ethash_imports_dataset_size : + IsImported globals "ethereum.ethash" "dataset_size". +Axiom ethereum_ethash_imports_generate_cache : + IsImported globals "ethereum.ethash" "generate_cache". +Axiom ethereum_ethash_imports_hashimoto_light : + IsImported globals "ethereum.ethash" "hashimoto_light". + +Axiom ethereum_exceptions_imports_InvalidBlock : + IsImported globals "ethereum.exceptions" "InvalidBlock". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U64 : + IsImported globals "ethereum.base_types" "U64". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_U256_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U256_CEIL_VALUE". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_gray_glacier_imports_vm : + IsImported globals "ethereum.gray_glacier" "vm". + +Axiom ethereum_gray_glacier_blocks_imports_Block : + IsImported globals "ethereum.gray_glacier.blocks" "Block". +Axiom ethereum_gray_glacier_blocks_imports_Header : + IsImported globals "ethereum.gray_glacier.blocks" "Header". +Axiom ethereum_gray_glacier_blocks_imports_Log : + IsImported globals "ethereum.gray_glacier.blocks" "Log". +Axiom ethereum_gray_glacier_blocks_imports_Receipt : + IsImported globals "ethereum.gray_glacier.blocks" "Receipt". + +Axiom ethereum_gray_glacier_bloom_imports_logs_bloom : + IsImported globals "ethereum.gray_glacier.bloom" "logs_bloom". + +Axiom ethereum_gray_glacier_fork_types_imports_Address : + IsImported globals "ethereum.gray_glacier.fork_types" "Address". +Axiom ethereum_gray_glacier_fork_types_imports_Bloom : + IsImported globals "ethereum.gray_glacier.fork_types" "Bloom". +Axiom ethereum_gray_glacier_fork_types_imports_Root : + IsImported globals "ethereum.gray_glacier.fork_types" "Root". + +Axiom ethereum_gray_glacier_state_imports_State : + IsImported globals "ethereum.gray_glacier.state" "State". +Axiom ethereum_gray_glacier_state_imports_account_exists_and_is_empty : + IsImported globals "ethereum.gray_glacier.state" "account_exists_and_is_empty". +Axiom ethereum_gray_glacier_state_imports_create_ether : + IsImported globals "ethereum.gray_glacier.state" "create_ether". +Axiom ethereum_gray_glacier_state_imports_destroy_account : + IsImported globals "ethereum.gray_glacier.state" "destroy_account". +Axiom ethereum_gray_glacier_state_imports_get_account : + IsImported globals "ethereum.gray_glacier.state" "get_account". +Axiom ethereum_gray_glacier_state_imports_increment_nonce : + IsImported globals "ethereum.gray_glacier.state" "increment_nonce". +Axiom ethereum_gray_glacier_state_imports_set_account_balance : + IsImported globals "ethereum.gray_glacier.state" "set_account_balance". +Axiom ethereum_gray_glacier_state_imports_state_root : + IsImported globals "ethereum.gray_glacier.state" "state_root". + +Axiom ethereum_gray_glacier_transactions_imports_TX_ACCESS_LIST_ADDRESS_COST : + IsImported globals "ethereum.gray_glacier.transactions" "TX_ACCESS_LIST_ADDRESS_COST". +Axiom ethereum_gray_glacier_transactions_imports_TX_ACCESS_LIST_STORAGE_KEY_COST : + IsImported globals "ethereum.gray_glacier.transactions" "TX_ACCESS_LIST_STORAGE_KEY_COST". +Axiom ethereum_gray_glacier_transactions_imports_TX_BASE_COST : + IsImported globals "ethereum.gray_glacier.transactions" "TX_BASE_COST". +Axiom ethereum_gray_glacier_transactions_imports_TX_CREATE_COST : + IsImported globals "ethereum.gray_glacier.transactions" "TX_CREATE_COST". +Axiom ethereum_gray_glacier_transactions_imports_TX_DATA_COST_PER_NON_ZERO : + IsImported globals "ethereum.gray_glacier.transactions" "TX_DATA_COST_PER_NON_ZERO". +Axiom ethereum_gray_glacier_transactions_imports_TX_DATA_COST_PER_ZERO : + IsImported globals "ethereum.gray_glacier.transactions" "TX_DATA_COST_PER_ZERO". +Axiom ethereum_gray_glacier_transactions_imports_AccessListTransaction : + IsImported globals "ethereum.gray_glacier.transactions" "AccessListTransaction". +Axiom ethereum_gray_glacier_transactions_imports_FeeMarketTransaction : + IsImported globals "ethereum.gray_glacier.transactions" "FeeMarketTransaction". +Axiom ethereum_gray_glacier_transactions_imports_LegacyTransaction : + IsImported globals "ethereum.gray_glacier.transactions" "LegacyTransaction". +Axiom ethereum_gray_glacier_transactions_imports_Transaction : + IsImported globals "ethereum.gray_glacier.transactions" "Transaction". +Axiom ethereum_gray_glacier_transactions_imports_decode_transaction : + IsImported globals "ethereum.gray_glacier.transactions" "decode_transaction". +Axiom ethereum_gray_glacier_transactions_imports_encode_transaction : + IsImported globals "ethereum.gray_glacier.transactions" "encode_transaction". + +Axiom ethereum_gray_glacier_trie_imports_Trie : + IsImported globals "ethereum.gray_glacier.trie" "Trie". +Axiom ethereum_gray_glacier_trie_imports_root : + IsImported globals "ethereum.gray_glacier.trie" "root". +Axiom ethereum_gray_glacier_trie_imports_trie_set : + IsImported globals "ethereum.gray_glacier.trie" "trie_set". + +Axiom ethereum_gray_glacier_utils_message_imports_prepare_message : + IsImported globals "ethereum.gray_glacier.utils.message" "prepare_message". + +Axiom ethereum_gray_glacier_vm_interpreter_imports_process_message_call : + IsImported globals "ethereum.gray_glacier.vm.interpreter" "process_message_call". Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -198,13 +272,15 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := recent_block_hashes : `List[Hash32]` Hashes of the recent 256 blocks in order of increasing block number. " in - let recent_blocks := + let _ := M.assign_local (| + "recent_blocks" , M.slice (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |), Constant.None_, Constant.None_ - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -228,15 +304,19 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let recent_block_hashes := - make_list [] in + let _ := M.assign_local (| + "recent_block_hashes" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "block" |), M.get_name (| globals, "recent_blocks" |), ltac:(M.monadic ( - let prev_block_hash := - M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in + let _ := M.assign_local (| + "prev_block_hash" , + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), make_list [ @@ -250,7 +330,8 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let most_recent_block_hash := + let _ := M.assign_local (| + "most_recent_block_hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -266,7 +347,8 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), make_list [ @@ -303,11 +385,13 @@ Definition state_transition : Value.t -> Value.t -> M := block : Block to apply to `chain`. " in - let parent_header := + let _ := M.assign_local (| + "parent_header" , M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 1 |) - |), "header" |) in + |), "header" |) + |) in let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ @@ -325,7 +409,8 @@ Definition state_transition : Value.t -> Value.t -> M := ], make_dict [] |) in - let apply_body_output := + let _ := M.assign_local (| + "apply_body_output" , M.call (| M.get_name (| globals, "apply_body" |), make_list [ @@ -348,7 +433,8 @@ Definition state_transition : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "chain" |), "chain_id" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -464,11 +550,13 @@ Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := base_fee_per_gas : `Uint` Base fee per gas for the block. " in - let parent_gas_target := + let _ := M.assign_local (| + "parent_gas_target" , BinOp.floor_div (| M.get_name (| globals, "parent_gas_limit" |), M.get_name (| globals, "ELASTICITY_MULTIPLIER" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -493,8 +581,10 @@ Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let expected_base_fee_per_gas := - M.get_name (| globals, "parent_base_fee_per_gas" |) in + let _ := M.assign_local (| + "expected_base_fee_per_gas" , + M.get_name (| globals, "parent_base_fee_per_gas" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -507,22 +597,29 @@ Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let gas_used_delta := + let _ := M.assign_local (| + "gas_used_delta" , BinOp.sub (| M.get_name (| globals, "parent_gas_used" |), M.get_name (| globals, "parent_gas_target" |) - |) in - let parent_fee_gas_delta := + |) + |) in + let _ := M.assign_local (| + "parent_fee_gas_delta" , BinOp.mult (| M.get_name (| globals, "parent_base_fee_per_gas" |), M.get_name (| globals, "gas_used_delta" |) - |) in - let target_fee_gas_delta := + |) + |) in + let _ := M.assign_local (| + "target_fee_gas_delta" , BinOp.floor_div (| M.get_name (| globals, "parent_fee_gas_delta" |), M.get_name (| globals, "parent_gas_target" |) - |) in - let base_fee_per_gas_delta := + |) + |) in + let _ := M.assign_local (| + "base_fee_per_gas_delta" , M.call (| M.get_name (| globals, "max" |), make_list [ @@ -533,40 +630,53 @@ Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := Constant.int 1 ], make_dict [] - |) in - let expected_base_fee_per_gas := + |) + |) in + let _ := M.assign_local (| + "expected_base_fee_per_gas" , BinOp.add (| M.get_name (| globals, "parent_base_fee_per_gas" |), M.get_name (| globals, "base_fee_per_gas_delta" |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let gas_used_delta := + let _ := M.assign_local (| + "gas_used_delta" , BinOp.sub (| M.get_name (| globals, "parent_gas_target" |), M.get_name (| globals, "parent_gas_used" |) - |) in - let parent_fee_gas_delta := + |) + |) in + let _ := M.assign_local (| + "parent_fee_gas_delta" , BinOp.mult (| M.get_name (| globals, "parent_base_fee_per_gas" |), M.get_name (| globals, "gas_used_delta" |) - |) in - let target_fee_gas_delta := + |) + |) in + let _ := M.assign_local (| + "target_fee_gas_delta" , BinOp.floor_div (| M.get_name (| globals, "parent_fee_gas_delta" |), M.get_name (| globals, "parent_gas_target" |) - |) in - let base_fee_per_gas_delta := + |) + |) in + let _ := M.assign_local (| + "base_fee_per_gas_delta" , BinOp.floor_div (| M.get_name (| globals, "target_fee_gas_delta" |), M.get_name (| globals, "BASE_FEE_MAX_CHANGE_DENOMINATOR" |) - |) in - let expected_base_fee_per_gas := + |) + |) in + let _ := M.assign_local (| + "expected_base_fee_per_gas" , BinOp.sub (| M.get_name (| globals, "parent_base_fee_per_gas" |), M.get_name (| globals, "base_fee_per_gas_delta" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -613,7 +723,8 @@ Definition validate_header : Value.t -> Value.t -> M := ], make_dict [] |) in - let expected_base_fee_per_gas := + let _ := M.assign_local (| + "expected_base_fee_per_gas" , M.call (| M.get_name (| globals, "calculate_base_fee_per_gas" |), make_list [ @@ -623,7 +734,8 @@ Definition validate_header : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "parent_header" |), "base_fee_per_gas" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -635,11 +747,13 @@ Definition validate_header : Value.t -> Value.t -> M := ], make_dict [] |) in - let parent_has_ommers := + let _ := M.assign_local (| + "parent_has_ommers" , Compare.not_eq (| M.get_field (| M.get_name (| globals, "parent_header" |), "ommers_hash" |), M.get_name (| globals, "EMPTY_OMMER_HASH" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -682,7 +796,8 @@ Definition validate_header : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_difficulty := + let _ := M.assign_local (| + "block_difficulty" , M.call (| M.get_name (| globals, "calculate_block_difficulty" |), make_list [ @@ -693,7 +808,8 @@ Definition validate_header : Value.t -> Value.t -> M := M.get_name (| globals, "parent_has_ommers" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -705,7 +821,8 @@ Definition validate_header : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_parent_hash := + let _ := M.assign_local (| + "block_parent_hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -718,7 +835,8 @@ Definition validate_header : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -764,7 +882,8 @@ Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := hash : `Hash32` The PoW valid rlp hash of the passed in header. " in - let header_data_without_pow_artefacts := + let _ := M.assign_local (| + "header_data_without_pow_artefacts" , make_list [ M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |); M.get_field (| M.get_name (| globals, "header" |), "ommers_hash" |); @@ -780,7 +899,8 @@ Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "header" |), "timestamp" |); M.get_field (| M.get_name (| globals, "header" |), "extra_data" |); M.get_field (| M.get_name (| globals, "header" |), "base_fee_per_gas" |) - ] in + ] + |) in let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), @@ -809,22 +929,26 @@ Definition validate_proof_of_work : Value.t -> Value.t -> M := header : Header of interest. " in - let header_hash := + let _ := M.assign_local (| + "header_hash" , M.call (| M.get_name (| globals, "generate_header_hash_for_pow" |), make_list [ M.get_name (| globals, "header" |) ], make_dict [] - |) in - let cache := + |) + |) in + let _ := M.assign_local (| + "cache" , M.call (| M.get_name (| globals, "generate_cache" |), make_list [ M.get_field (| M.get_name (| globals, "header" |), "number" |) ], make_dict [] - |) in + |) + |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "mix_digest" |); M.get_name (| globals, "result" |) ], M.call (| @@ -917,7 +1041,8 @@ Definition check_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_address := + let _ := M.assign_local (| + "sender_address" , M.call (| M.get_name (| globals, "recover_sender" |), make_list [ @@ -925,7 +1050,8 @@ Definition check_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "tx" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -961,7 +1087,8 @@ Definition check_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let priority_fee_per_gas := + let _ := M.assign_local (| + "priority_fee_per_gas" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -972,12 +1099,15 @@ Definition check_transaction : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let effective_gas_price := + |) + |) in + let _ := M.assign_local (| + "effective_gas_price" , BinOp.add (| M.get_name (| globals, "priority_fee_per_gas" |), M.get_name (| globals, "base_fee_per_gas" |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -992,8 +1122,10 @@ Definition check_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let effective_gas_price := - M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) in + let _ := M.assign_local (| + "effective_gas_price" , + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) + |) in M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1024,12 +1156,14 @@ Definition make_receipt : Value.t -> Value.t -> M := receipt : The receipt for the transaction. " in - let receipt := + let _ := M.assign_local (| + "receipt" , M.call (| M.get_name (| globals, "Receipt" |), make_list [], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1150,8 +1284,10 @@ Definition apply_body : Value.t -> Value.t -> M := apply_body_output : `ApplyBodyOutput` Output of applying the block body to the state. " in - let gas_available := - M.get_name (| globals, "block_gas_limit" |) in + let _ := M.assign_local (| + "gas_available" , + M.get_name (| globals, "block_gas_limit" |) + |) in (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) @@ -1213,12 +1349,14 @@ Definition apply_body : Value.t -> Value.t -> M := make_dict [] |) |) in - let env := + let _ := M.assign_local (| + "env" , M.call (| M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |); M.get_name (| globals, "error" |) ], M.call (| @@ -1230,10 +1368,13 @@ Definition apply_body : Value.t -> Value.t -> M := make_dict [] |) |) in - let gas_available := BinOp.sub + let _ := M.assign_op_local (| + BinOp.sub, + "gas_available", M.get_name (| globals, "gas_used" |) - M.get_name (| globals, "gas_used" |) in - let receipt := + |) in + let _ := M.assign_local (| + "receipt" , M.call (| M.get_name (| globals, "make_receipt" |), make_list [ @@ -1246,7 +1387,8 @@ Definition apply_body : Value.t -> Value.t -> M := M.get_name (| globals, "logs" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ @@ -1268,9 +1410,11 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_logs := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "block_logs", M.get_name (| globals, "logs" |) - M.get_name (| globals, "logs" |) in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -1287,19 +1431,23 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_gas_used := + let _ := M.assign_local (| + "block_gas_used" , BinOp.sub (| M.get_name (| globals, "block_gas_limit" |), M.get_name (| globals, "gas_available" |) - |) in - let block_logs_bloom := + |) + |) in + let _ := M.assign_local (| + "block_logs_bloom" , M.call (| M.get_name (| globals, "logs_bloom" |), make_list [ M.get_name (| globals, "block_logs" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ApplyBodyOutput" |), @@ -1357,14 +1505,16 @@ Definition validate_ommers : Value.t -> Value.t -> M := chain : History and current state. " in - let block_hash := + let _ := M.assign_local (| + "block_hash" , M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), make_list [ M.get_name (| globals, "block_header" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1429,7 +1579,8 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_parent_header := + let _ := M.assign_local (| + "ommer_parent_header" , M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), BinOp.sub (| @@ -1439,7 +1590,8 @@ Definition validate_ommers : Value.t -> Value.t -> M := |) |), Constant.int 1 |) - |), "header" |) in + |), "header" |) + |) in let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ @@ -1471,8 +1623,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommers_hashes := - Constant.str "(* At expr: unsupported node type: ListComp *)" in + let _ := M.assign_local (| + "ommers_hashes" , + Constant.str "(* At expr: unsupported node type: ListComp *)" + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1502,7 +1656,8 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let recent_canonical_blocks := + let _ := M.assign_local (| + "recent_canonical_blocks" , M.slice (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| BinOp.add (| @@ -1511,23 +1666,28 @@ Definition validate_ommers : Value.t -> Value.t -> M := |) |), Constant.None_, Constant.None_ - |) in - let recent_canonical_block_hashes := - Constant.str "(* At expr: unsupported node type: SetComp *)" in + |) + |) in + let _ := M.assign_local (| + "recent_canonical_block_hashes" , + Constant.str "(* At expr: unsupported node type: SetComp *)" + |) in (* At stmt: unsupported node type: AnnAssign *) let _ := M.for_ (| M.get_name (| globals, "block" |), M.get_name (| globals, "recent_canonical_blocks" |), ltac:(M.monadic ( - let recent_ommers_hashes := + let _ := M.assign_local (| + "recent_ommers_hashes" , M.call (| M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), make_list [ Constant.str "(* At expr: unsupported node type: SetComp *)" ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -1545,11 +1705,13 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let ommer_hash := + let _ := M.assign_local (| + "ommer_hash" , M.get_subscript (| M.get_name (| globals, "ommers_hashes" |), M.get_name (| globals, "ommer_index" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1583,11 +1745,13 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_age := + let _ := M.assign_local (| + "ommer_age" , BinOp.sub (| M.get_field (| M.get_name (| globals, "block_header" |), "number" |), M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1665,7 +1829,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := ommers : List of ommers mentioned in the current block. " in - let miner_reward := + let _ := M.assign_local (| + "miner_reward" , BinOp.add (| M.get_name (| globals, "BLOCK_REWARD" |), BinOp.mult (| @@ -1681,7 +1846,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := Constant.int 32 |) |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "create_ether" |), make_list [ @@ -1696,7 +1862,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := M.get_name (| globals, "ommer" |), M.get_name (| globals, "ommers" |), ltac:(M.monadic ( - let ommer_age := + let _ := M.assign_local (| + "ommer_age" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -1706,8 +1873,10 @@ Definition pay_rewards : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let ommer_miner_reward := + |) + |) in + let _ := M.assign_local (| + "ommer_miner_reward" , BinOp.floor_div (| BinOp.mult (| BinOp.sub (| @@ -1717,7 +1886,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := M.get_name (| globals, "BLOCK_REWARD" |) |), Constant.int 8 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "create_ether" |), make_list [ @@ -1778,9 +1948,12 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender := - M.get_field (| M.get_name (| globals, "env" |), "origin" |) in - let sender_account := + let _ := M.assign_local (| + "sender" , + M.get_field (| M.get_name (| globals, "env" |), "origin" |) + |) in + let _ := M.assign_local (| + "sender_account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1788,7 +1961,8 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "sender" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1802,19 +1976,23 @@ Definition process_transaction : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let max_gas_fee := + let _ := M.assign_local (| + "max_gas_fee" , BinOp.mult (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let max_gas_fee := + let _ := M.assign_local (| + "max_gas_fee" , BinOp.mult (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -1857,12 +2035,15 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let effective_gas_fee := + let _ := M.assign_local (| + "effective_gas_fee" , BinOp.mult (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_field (| M.get_name (| globals, "env" |), "gas_price" |) - |) in - let gas := + |) + |) in + let _ := M.assign_local (| + "gas" , BinOp.sub (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.call (| @@ -1872,7 +2053,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "increment_nonce" |), make_list [ @@ -1881,11 +2063,13 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_balance_after_gas_fee := + let _ := M.assign_local (| + "sender_balance_after_gas_fee" , BinOp.sub (| M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), M.get_name (| globals, "effective_gas_fee" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -1895,18 +2079,22 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let preaccessed_addresses := + let _ := M.assign_local (| + "preaccessed_addresses" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let preaccessed_storage_keys := + |) + |) in + let _ := M.assign_local (| + "preaccessed_storage_keys" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1961,7 +2149,8 @@ Definition process_transaction : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let message := + let _ := M.assign_local (| + "message" , M.call (| M.get_name (| globals, "prepare_message" |), make_list [ @@ -1973,8 +2162,10 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in - let output := + |) + |) in + let _ := M.assign_local (| + "output" , M.call (| M.get_name (| globals, "process_message_call" |), make_list [ @@ -1982,13 +2173,17 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in - let gas_used := + |) + |) in + let _ := M.assign_local (| + "gas_used" , BinOp.sub (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_field (| M.get_name (| globals, "output" |), "gas_left" |) - |) in - let gas_refund := + |) + |) in + let _ := M.assign_local (| + "gas_refund" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -1999,21 +2194,27 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "output" |), "refund_counter" |) ], make_dict [] - |) in - let gas_refund_amount := + |) + |) in + let _ := M.assign_local (| + "gas_refund_amount" , BinOp.mult (| BinOp.add (| M.get_field (| M.get_name (| globals, "output" |), "gas_left" |), M.get_name (| globals, "gas_refund" |) |), M.get_field (| M.get_name (| globals, "env" |), "gas_price" |) - |) in - let priority_fee_per_gas := + |) + |) in + let _ := M.assign_local (| + "priority_fee_per_gas" , BinOp.sub (| M.get_field (| M.get_name (| globals, "env" |), "gas_price" |), M.get_field (| M.get_name (| globals, "env" |), "base_fee_per_gas" |) - |) in - let transaction_fee := + |) + |) in + let _ := M.assign_local (| + "transaction_fee" , BinOp.mult (| BinOp.sub (| BinOp.sub (| @@ -2023,13 +2224,17 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "gas_refund" |) |), M.get_name (| globals, "priority_fee_per_gas" |) - |) in - let total_gas_used := + |) + |) in + let _ := M.assign_local (| + "total_gas_used" , BinOp.sub (| M.get_name (| globals, "gas_used" |), M.get_name (| globals, "gas_refund" |) - |) in - let sender_balance_after_refund := + |) + |) in + let _ := M.assign_local (| + "sender_balance_after_refund" , BinOp.add (| M.get_field (| M.call (| M.get_name (| globals, "get_account" |), @@ -2040,7 +2245,8 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |), "balance" |), M.get_name (| globals, "gas_refund_amount" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -2050,7 +2256,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let coinbase_balance_after_mining_fee := + let _ := M.assign_local (| + "coinbase_balance_after_mining_fee" , BinOp.add (| M.get_field (| M.call (| M.get_name (| globals, "get_account" |), @@ -2061,7 +2268,8 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |), "balance" |), M.get_name (| globals, "transaction_fee" |) - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -2252,8 +2460,10 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := verified : `ethereum.base_types.Uint` The intrinsic cost of the transaction. " in - let data_cost := - Constant.int 0 in + let _ := M.assign_local (| + "data_cost" , + Constant.int 0 + |) in let _ := M.for_ (| M.get_name (| globals, "byte" |), @@ -2268,15 +2478,19 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let data_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "data_cost", M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let data_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "data_cost", M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -2300,17 +2514,23 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let create_cost := - M.get_name (| globals, "TX_CREATE_COST" |) in + let _ := M.assign_local (| + "create_cost" , + M.get_name (| globals, "TX_CREATE_COST" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let create_cost := - Constant.int 0 in + let _ := M.assign_local (| + "create_cost" , + Constant.int 0 + |) in M.pure Constant.None_ )) |) in - let access_list_cost := - Constant.int 0 in + let _ := M.assign_local (| + "access_list_cost" , + Constant.int 0 + |) in let _ := (* if *) M.if_then_else (| @@ -2329,10 +2549,14 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := make_tuple [ M.get_name (| globals, "_address" |); M.get_name (| globals, "keys" |) ], M.get_field (| M.get_name (| globals, "tx" |), "access_list" |), ltac:(M.monadic ( - let access_list_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "access_list_cost", M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) - M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) in - let access_list_cost := BinOp.add + |) in + let _ := M.assign_op_local (| + BinOp.add, + "access_list_cost", BinOp.mult (| M.call (| M.get_name (| globals, "len" |), @@ -2343,16 +2567,7 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) |) - BinOp.mult (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "keys" |) - ], - make_dict [] - |), - M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) - |) in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -2466,8 +2681,10 @@ Definition recover_sender : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let v := - M.get_field (| M.get_name (| globals, "tx" |), "v" |) in + let _ := M.assign_local (| + "v" , + M.get_field (| M.get_name (| globals, "tx" |), "v" |) + |) in let _ := (* if *) M.if_then_else (| @@ -2485,7 +2702,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let public_key := + let _ := M.assign_local (| + "public_key" , M.call (| M.get_name (| globals, "secp256k1_recover" |), make_list [ @@ -2504,7 +2722,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -2539,7 +2758,8 @@ Definition recover_sender : Value.t -> Value.t -> M := ], make_dict [] |) in - let public_key := + let _ := M.assign_local (| + "public_key" , M.call (| M.get_name (| globals, "secp256k1_recover" |), make_list [ @@ -2565,7 +2785,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -2584,7 +2805,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let public_key := + let _ := M.assign_local (| + "public_key" , M.call (| M.get_name (| globals, "secp256k1_recover" |), make_list [ @@ -2600,7 +2822,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -2617,7 +2840,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let public_key := + let _ := M.assign_local (| + "public_key" , M.call (| M.get_name (| globals, "secp256k1_recover" |), make_list [ @@ -2633,7 +2857,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -2898,11 +3123,13 @@ Definition check_gas_limit : Value.t -> Value.t -> M := check : `bool` True if gas limit constraints are satisfied, False otherwise. " in - let max_adjustment_delta := + let _ := M.assign_local (| + "max_adjustment_delta" , BinOp.floor_div (| M.get_name (| globals, "parent_gas_limit" |), M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -3006,7 +3233,8 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := difficulty : `ethereum.base_types.Uint` Computed difficulty for a block. " in - let offset := + let _ := M.assign_local (| + "offset" , BinOp.mult (| BinOp.floor_div (| M.call (| @@ -3050,8 +3278,10 @@ Constant.int 1 ], make_dict [] |) - |) in - let difficulty := + |) + |) in + let _ := M.assign_local (| + "difficulty" , BinOp.add (| M.call (| M.get_name (| globals, "int" |), @@ -3061,8 +3291,10 @@ Constant.int 1 make_dict [] |), M.get_name (| globals, "offset" |) - |) in - let num_bomb_periods := + |) + |) in + let _ := M.assign_local (| + "num_bomb_periods" , BinOp.sub (| BinOp.floor_div (| BinOp.sub (| @@ -3078,7 +3310,8 @@ Constant.int 1 Constant.int 100000 |), Constant.int 2 - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -3088,15 +3321,14 @@ Constant.int 1 |), (* then *) ltac:(M.monadic ( - let difficulty := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "difficulty", BinOp.pow (| Constant.int 2, M.get_name (| globals, "num_bomb_periods" |) |) - BinOp.pow (| - Constant.int 2, - M.get_name (| globals, "num_bomb_periods" |) - |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/gray_glacier/fork_types.v b/CoqOfPython/ethereum/gray_glacier/fork_types.v index 374e9c6..b0a58e8 100644 --- a/CoqOfPython/ethereum/gray_glacier/fork_types.v +++ b/CoqOfPython/ethereum/gray_glacier/fork_types.v @@ -17,17 +17,29 @@ Introduction Types re-used throughout the specification, which are specific to Ethereum. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes20"; "Bytes256"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes20 : + IsImported globals "ethereum.base_types" "Bytes20". +Axiom ethereum_base_types_imports_Bytes256 : + IsImported globals "ethereum.base_types" "Bytes256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) diff --git a/CoqOfPython/ethereum/gray_glacier/state.v b/CoqOfPython/ethereum/gray_glacier/state.v index 6e039ed..8cde655 100644 --- a/CoqOfPython/ethereum/gray_glacier/state.v +++ b/CoqOfPython/ethereum/gray_glacier/state.v @@ -22,23 +22,57 @@ There is a distinction between an account that does not exist and `EMPTY_ACCOUNT`. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass"; "field" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict"; "List"; "Optional"; "Set"; "Tuple" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "modify" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_gray_glacier_fork_types_imports : - AreImported globals "ethereum.gray_glacier.fork_types" [ "EMPTY_ACCOUNT"; "Account"; "Address"; "Root" ]. - -Axiom ethereum_gray_glacier_trie_imports : - AreImported globals "ethereum.gray_glacier.trie" [ "EMPTY_TRIE_ROOT"; "Trie"; "copy_trie"; "root"; "trie_get"; "trie_set" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". +Axiom dataclasses_imports_field : + IsImported globals "dataclasses" "field". + +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_modify : + IsImported globals "ethereum.base_types" "modify". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_gray_glacier_fork_types_imports_EMPTY_ACCOUNT : + IsImported globals "ethereum.gray_glacier.fork_types" "EMPTY_ACCOUNT". +Axiom ethereum_gray_glacier_fork_types_imports_Account : + IsImported globals "ethereum.gray_glacier.fork_types" "Account". +Axiom ethereum_gray_glacier_fork_types_imports_Address : + IsImported globals "ethereum.gray_glacier.fork_types" "Address". +Axiom ethereum_gray_glacier_fork_types_imports_Root : + IsImported globals "ethereum.gray_glacier.fork_types" "Root". + +Axiom ethereum_gray_glacier_trie_imports_EMPTY_TRIE_ROOT : + IsImported globals "ethereum.gray_glacier.trie" "EMPTY_TRIE_ROOT". +Axiom ethereum_gray_glacier_trie_imports_Trie : + IsImported globals "ethereum.gray_glacier.trie" "Trie". +Axiom ethereum_gray_glacier_trie_imports_copy_trie : + IsImported globals "ethereum.gray_glacier.trie" "copy_trie". +Axiom ethereum_gray_glacier_trie_imports_root : + IsImported globals "ethereum.gray_glacier.trie" "root". +Axiom ethereum_gray_glacier_trie_imports_trie_get : + IsImported globals "ethereum.gray_glacier.trie" "trie_get". +Axiom ethereum_gray_glacier_trie_imports_trie_set : + IsImported globals "ethereum.gray_glacier.trie" "trie_set". Definition State : Value.t := builtins.make_klass @@ -186,7 +220,8 @@ Definition get_account : Value.t -> Value.t -> M := account : `Account` Account at address. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account_optional" |), make_list [ @@ -194,7 +229,8 @@ Definition get_account : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -240,7 +276,8 @@ Definition get_account_optional : Value.t -> Value.t -> M := account : `Account` Account at address. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "trie_get" |), make_list [ @@ -248,7 +285,8 @@ Definition get_account_optional : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "account" |) |) in @@ -399,14 +437,16 @@ Definition get_storage : Value.t -> Value.t -> M := value : `U256` Value at the key. " in - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -430,7 +470,8 @@ Definition get_storage : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "trie_get" |), make_list [ @@ -438,7 +479,8 @@ Definition get_storage : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -481,14 +523,16 @@ Definition set_storage : Value.t -> Value.t -> M := |), Constant.None_ |) |) in - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -498,12 +542,14 @@ Definition set_storage : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_name (| globals, "Trie" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), @@ -530,7 +576,7 @@ Definition set_storage : Value.t -> Value.t -> M := M.if_then_else (| Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), - {} + Constant.str "(* At expr: unsupported node type: Dict *)" |), (* then *) ltac:(M.monadic ( @@ -676,7 +722,8 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := True if if an account has non zero nonce or non empty code, False otherwise. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -684,7 +731,8 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| BoolOp.or (| Compare.not_eq (| @@ -726,7 +774,8 @@ Definition is_account_empty : Value.t -> Value.t -> M := True if if an account has zero nonce, empty code and zero balance, False otherwise. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -734,7 +783,8 @@ Definition is_account_empty : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| BoolOp.and (| Compare.eq (| @@ -785,7 +835,8 @@ Definition account_exists_and_is_empty : Value.t -> Value.t -> M := True if an account exists and has zero nonce, empty code and zero balance, False otherwise. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account_optional" |), make_list [ @@ -793,7 +844,8 @@ Definition account_exists_and_is_empty : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| BoolOp.and (| Compare.is_not (| @@ -850,7 +902,8 @@ Definition is_account_alive : Value.t -> Value.t -> M := is_alive : `bool` True if the account is alive. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account_optional" |), make_list [ @@ -858,7 +911,8 @@ Definition is_account_alive : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1166,14 +1220,16 @@ Definition get_storage_original : Value.t -> Value.t -> M := Constant.int 0 |) |) in - let original_account_trie := + let _ := M.assign_local (| + "original_account_trie" , M.call (| M.get_field (| M.get_name (| globals, "original_trie" |), "get" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1183,18 +1239,21 @@ Definition get_storage_original : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let original_value := + let _ := M.assign_local (| + "original_value" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let original_value := + let _ := M.assign_local (| + "original_value" , M.call (| M.get_name (| globals, "trie_get" |), make_list [ @@ -1202,7 +1261,8 @@ Definition get_storage_original : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.assert (| M.call (| diff --git a/CoqOfPython/ethereum/gray_glacier/transactions.v b/CoqOfPython/ethereum/gray_glacier/transactions.v index da20fcd..3fb1a1b 100644 --- a/CoqOfPython/ethereum/gray_glacier/transactions.v +++ b/CoqOfPython/ethereum/gray_glacier/transactions.v @@ -9,23 +9,37 @@ submitted to be executed. If Ethereum is viewed as a state machine, transactions are the events that move between states. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". -Axiom typing_imports : - AreImported globals "typing" [ "Tuple"; "Union" ]. +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U64"; "U256"; "Bytes"; "Bytes0"; "Bytes32"; "Uint"; "slotted_freezable" ]. +Axiom ethereum_base_types_imports_U64 : + IsImported globals "ethereum.base_types" "U64". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". -Axiom ethereum_exceptions_imports : - AreImported globals "ethereum.exceptions" [ "InvalidBlock" ]. +Axiom ethereum_exceptions_imports_InvalidBlock : + IsImported globals "ethereum.exceptions" "InvalidBlock". -Axiom ethereum_gray_glacier_fork_types_imports : - AreImported globals "ethereum.gray_glacier.fork_types" [ "Address" ]. +Axiom ethereum_gray_glacier_fork_types_imports_Address : + IsImported globals "ethereum.gray_glacier.fork_types" "Address". Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( Constant.int 21000 diff --git a/CoqOfPython/ethereum/gray_glacier/trie.v b/CoqOfPython/ethereum/gray_glacier/trie.v index 50d2c44..8b795d8 100644 --- a/CoqOfPython/ethereum/gray_glacier/trie.v +++ b/CoqOfPython/ethereum/gray_glacier/trie.v @@ -20,38 +20,72 @@ The state trie is the structure responsible for storing (* At top_level_stmt: unsupported node type: Import *) -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass"; "field" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict"; "Generic"; "List"; "Mapping"; "MutableMapping"; "Optional"; "Sequence"; "TypeVar"; "Union"; "cast" ]. - -Axiom ethereum_arrow_glacier_imports : - AreImported globals "ethereum.arrow_glacier" [ "trie" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_utils_hexadecimal_imports : - AreImported globals "ethereum.utils.hexadecimal" [ "hex_to_bytes" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_gray_glacier_blocks_imports : - AreImported globals "ethereum.gray_glacier.blocks" [ "Receipt" ]. - -Axiom ethereum_gray_glacier_fork_types_imports : - AreImported globals "ethereum.gray_glacier.fork_types" [ "Account"; "Address"; "Root"; "encode_account" ]. - -Axiom ethereum_gray_glacier_transactions_imports : - AreImported globals "ethereum.gray_glacier.transactions" [ "LegacyTransaction" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". +Axiom dataclasses_imports_field : + IsImported globals "dataclasses" "field". + +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". +Axiom typing_imports_Generic : + IsImported globals "typing" "Generic". +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Mapping : + IsImported globals "typing" "Mapping". +Axiom typing_imports_MutableMapping : + IsImported globals "typing" "MutableMapping". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Sequence : + IsImported globals "typing" "Sequence". +Axiom typing_imports_TypeVar : + IsImported globals "typing" "TypeVar". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". +Axiom typing_imports_cast : + IsImported globals "typing" "cast". + +Axiom ethereum_arrow_glacier_imports_trie : + IsImported globals "ethereum.arrow_glacier" "trie". + +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_utils_hexadecimal_imports_hex_to_bytes : + IsImported globals "ethereum.utils.hexadecimal" "hex_to_bytes". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_gray_glacier_blocks_imports_Receipt : + IsImported globals "ethereum.gray_glacier.blocks" "Receipt". + +Axiom ethereum_gray_glacier_fork_types_imports_Account : + IsImported globals "ethereum.gray_glacier.fork_types" "Account". +Axiom ethereum_gray_glacier_fork_types_imports_Address : + IsImported globals "ethereum.gray_glacier.fork_types" "Address". +Axiom ethereum_gray_glacier_fork_types_imports_Root : + IsImported globals "ethereum.gray_glacier.fork_types" "Root". +Axiom ethereum_gray_glacier_fork_types_imports_encode_account : + IsImported globals "ethereum.gray_glacier.fork_types" "encode_account". + +Axiom ethereum_gray_glacier_transactions_imports_LegacyTransaction : + IsImported globals "ethereum.gray_glacier.transactions" "LegacyTransaction". Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -167,7 +201,7 @@ Definition encode_internal_node : Value.t -> Value.t -> M := when serialized. This function also accepts `None`, representing the absence of a node, - which is encoded to `b""""""`. + which is encoded to `b""""`. Parameters ---------- @@ -189,8 +223,10 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := - Constant.bytes "" in + let _ := M.assign_local (| + "unencoded" , + Constant.bytes "" + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -207,7 +243,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := + let _ := M.assign_local (| + "unencoded" , make_tuple [ M.call (| M.get_name (| globals, "nibble_list_to_compact" |), make_list [ @@ -215,7 +252,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := Constant.bool true ], make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in + |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -232,7 +270,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := + let _ := M.assign_local (| + "unencoded" , make_tuple [ M.call (| M.get_name (| globals, "nibble_list_to_compact" |), make_list [ @@ -240,7 +279,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := Constant.bool false ], make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in + |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -257,13 +297,15 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := + let _ := M.assign_local (| + "unencoded" , BinOp.add (| M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), make_list [ M.get_field (| M.get_name (| globals, "node" |), "value" |) ] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -282,14 +324,16 @@ Definition encode_internal_node : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - let encoded := + let _ := M.assign_local (| + "encoded" , M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), make_list [ M.get_name (| globals, "unencoded" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -681,12 +725,14 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := compressed : `bytearray` Compact byte array. " in - let compact := + let _ := M.assign_local (| + "compact" , M.call (| M.get_name (| globals, "bytearray" |), make_list [], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -866,7 +912,8 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := nibble_list : `Bytes` The `Bytes` in nibble-list format. " in - let nibble_list := + let _ := M.assign_local (| + "nibble_list" , M.call (| M.get_name (| globals, "bytearray" |), make_list [ @@ -882,7 +929,8 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ], @@ -990,15 +1038,18 @@ Definition _prepare_trie : Value.t -> Value.t -> M := M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "Address" |), make_list [ M.get_name (| globals, "preimage" |) ], make_dict [] - |) in - let encoded_value := + |) + |) in + let _ := M.assign_local (| + "encoded_value" , M.call (| M.get_name (| globals, "encode_node" |), make_list [ @@ -1012,18 +1063,21 @@ Definition _prepare_trie : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let encoded_value := + let _ := M.assign_local (| + "encoded_value" , M.call (| M.get_name (| globals, "encode_node" |), make_list [ M.get_name (| globals, "value" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -1044,19 +1098,23 @@ Definition _prepare_trie : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "trie" |), "secured" |), (* then *) ltac:(M.monadic ( - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "preimage" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let key := - M.get_name (| globals, "preimage" |) in + let _ := M.assign_local (| + "key" , + M.get_name (| globals, "preimage" |) + |) in M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -1103,7 +1161,8 @@ Definition root : Value.t -> Value.t -> M := root : `.fork_types.Root` MPT root of the underlying key-value pairs. " in - let obj := + let _ := M.assign_local (| + "obj" , M.call (| M.get_name (| globals, "_prepare_trie" |), make_list [ @@ -1111,8 +1170,10 @@ Definition root : Value.t -> Value.t -> M := M.get_name (| globals, "get_storage_root" |) ], make_dict [] - |) in - let root_node := + |) + |) in + let _ := M.assign_local (| + "root_node" , M.call (| M.get_name (| globals, "encode_internal_node" |), make_list [ @@ -1132,7 +1193,8 @@ Definition root : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1237,7 +1299,8 @@ Definition patricialize : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let arbitrary_key := + let _ := M.assign_local (| + "arbitrary_key" , M.call (| M.get_name (| globals, "next" |), make_list [ @@ -1250,7 +1313,8 @@ Definition patricialize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1266,7 +1330,8 @@ Definition patricialize : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let leaf := + let _ := M.assign_local (| + "leaf" , M.call (| M.get_name (| globals, "LeafNode" |), make_list [ @@ -1282,7 +1347,8 @@ Definition patricialize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "leaf" |) |) in @@ -1291,27 +1357,32 @@ Definition patricialize : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let substring := + let _ := M.assign_local (| + "substring" , M.slice (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |), Constant.None_, Constant.None_ - |) in - let prefix_length := + |) + |) in + let _ := M.assign_local (| + "prefix_length" , M.call (| M.get_name (| globals, "len" |), make_list [ M.get_name (| globals, "substring" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "key" |), M.get_name (| globals, "obj" |), ltac:(M.monadic ( - let prefix_length := + let _ := M.assign_local (| + "prefix_length" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -1331,7 +1402,8 @@ Definition patricialize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1362,7 +1434,8 @@ Definition patricialize : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let prefix := + let _ := M.assign_local (| + "prefix" , M.slice (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |), @@ -1371,7 +1444,8 @@ Definition patricialize : Value.t -> Value.t -> M := M.get_name (| globals, "prefix_length" |) |), Constant.None_ - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ExtensionNode" |), @@ -1418,7 +1492,7 @@ Definition patricialize : Value.t -> Value.t -> M := let _ := M.call (| M.get_field (| M.get_name (| globals, "branches" |), "append" |), make_list [ - {} + Constant.str "(* At expr: unsupported node type: Dict *)" ], make_dict [] |) in @@ -1428,8 +1502,10 @@ Definition patricialize : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let value := - Constant.bytes "" in + let _ := M.assign_local (| + "value" , + Constant.bytes "" + |) in let _ := M.for_ (| M.get_name (| globals, "key" |), @@ -1472,11 +1548,13 @@ Definition patricialize : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let value := + let _ := M.assign_local (| + "value" , M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/gray_glacier/utils/address.v b/CoqOfPython/ethereum/gray_glacier/utils/address.v index 9313e03..a7dbc7d 100644 --- a/CoqOfPython/ethereum/gray_glacier/utils/address.v +++ b/CoqOfPython/ethereum/gray_glacier/utils/address.v @@ -18,23 +18,27 @@ Address specific functions used in this gray_glacier version of specification. ". -Axiom typing_imports : - AreImported globals "typing" [ "Union" ]. +Axiom typing_imports_Union : + IsImported globals "typing" "Union". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes32"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_left_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "left_pad_zero_bytes". -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". -Axiom ethereum_gray_glacier_fork_types_imports : - AreImported globals "ethereum.gray_glacier.fork_types" [ "Address" ]. +Axiom ethereum_gray_glacier_fork_types_imports_Address : + IsImported globals "ethereum.gray_glacier.fork_types" "Address". Definition to_address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -91,7 +95,8 @@ Definition compute_contract_address : Value.t -> Value.t -> M := address: `Address` The computed address of the new account. " in - let computed_address := + let _ := M.assign_local (| + "computed_address" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -107,15 +112,19 @@ Definition compute_contract_address : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let canonical_address := + |) + |) in + let _ := M.assign_local (| + "canonical_address" , M.slice (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |), Constant.None_, Constant.None_ - |) in - let padded_address := + |) + |) in + let _ := M.assign_local (| + "padded_address" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -123,7 +132,8 @@ Definition compute_contract_address : Value.t -> Value.t -> M := Constant.int 20 ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Address" |), @@ -156,7 +166,8 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := address: `ethereum.gray_glacier.fork_types.Address` The computed address of the new account. " in - let preimage := + let _ := M.assign_local (| + "preimage" , BinOp.add (| BinOp.add (| BinOp.add (| @@ -172,23 +183,29 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in - let computed_address := + |) + |) in + let _ := M.assign_local (| + "computed_address" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "preimage" |) ], make_dict [] - |) in - let canonical_address := + |) + |) in + let _ := M.assign_local (| + "canonical_address" , M.slice (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |), Constant.None_, Constant.None_ - |) in - let padded_address := + |) + |) in + let _ := M.assign_local (| + "padded_address" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -196,7 +213,8 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := Constant.int 20 ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Address" |), diff --git a/CoqOfPython/ethereum/gray_glacier/utils/hexadecimal.v b/CoqOfPython/ethereum/gray_glacier/utils/hexadecimal.v index b51bb59..3ad2857 100644 --- a/CoqOfPython/ethereum/gray_glacier/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/gray_glacier/utils/hexadecimal.v @@ -18,11 +18,15 @@ Hexadecimal utility functions used in this specification, specific to Gray Glacier types. ". -Axiom ethereum_utils_hexadecimal_imports : - AreImported globals "ethereum.utils.hexadecimal" [ "remove_hex_prefix" ]. - -Axiom ethereum_gray_glacier_fork_types_imports : - AreImported globals "ethereum.gray_glacier.fork_types" [ "Address"; "Bloom"; "Root" ]. +Axiom ethereum_utils_hexadecimal_imports_remove_hex_prefix : + IsImported globals "ethereum.utils.hexadecimal" "remove_hex_prefix". + +Axiom ethereum_gray_glacier_fork_types_imports_Address : + IsImported globals "ethereum.gray_glacier.fork_types" "Address". +Axiom ethereum_gray_glacier_fork_types_imports_Bloom : + IsImported globals "ethereum.gray_glacier.fork_types" "Bloom". +Axiom ethereum_gray_glacier_fork_types_imports_Root : + IsImported globals "ethereum.gray_glacier.fork_types" "Root". Definition hex_to_root : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/gray_glacier/utils/message.v b/CoqOfPython/ethereum/gray_glacier/utils/message.v index b44a695..c2728e8 100644 --- a/CoqOfPython/ethereum/gray_glacier/utils/message.v +++ b/CoqOfPython/ethereum/gray_glacier/utils/message.v @@ -18,26 +18,42 @@ Message specific functions used in this gray_glacier version of specification. ". -Axiom typing_imports : - AreImported globals "typing" [ "FrozenSet"; "Optional"; "Tuple"; "Union" ]. +Axiom typing_imports_FrozenSet : + IsImported globals "typing" "FrozenSet". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Bytes32"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_gray_glacier_fork_types_imports : - AreImported globals "ethereum.gray_glacier.fork_types" [ "Address" ]. +Axiom ethereum_gray_glacier_fork_types_imports_Address : + IsImported globals "ethereum.gray_glacier.fork_types" "Address". -Axiom ethereum_gray_glacier_state_imports : - AreImported globals "ethereum.gray_glacier.state" [ "get_account" ]. +Axiom ethereum_gray_glacier_state_imports_get_account : + IsImported globals "ethereum.gray_glacier.state" "get_account". -Axiom ethereum_gray_glacier_vm_imports : - AreImported globals "ethereum.gray_glacier.vm" [ "Environment"; "Message" ]. +Axiom ethereum_gray_glacier_vm_imports_Environment : + IsImported globals "ethereum.gray_glacier.vm" "Environment". +Axiom ethereum_gray_glacier_vm_imports_Message : + IsImported globals "ethereum.gray_glacier.vm" "Message". -Axiom ethereum_gray_glacier_vm_precompiled_contracts_mapping_imports : - AreImported globals "ethereum.gray_glacier.vm.precompiled_contracts.mapping" [ "PRE_COMPILED_CONTRACTS" ]. +Axiom ethereum_gray_glacier_vm_precompiled_contracts_mapping_imports_PRE_COMPILED_CONTRACTS : + IsImported globals "ethereum.gray_glacier.vm.precompiled_contracts.mapping" "PRE_COMPILED_CONTRACTS". -Axiom ethereum_gray_glacier_utils_address_imports : - AreImported globals "ethereum.gray_glacier.utils.address" [ "compute_contract_address" ]. +Axiom ethereum_gray_glacier_utils_address_imports_compute_contract_address : + IsImported globals "ethereum.gray_glacier.utils.address" "compute_contract_address". Definition prepare_message : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -92,7 +108,8 @@ Definition prepare_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let current_target := + let _ := M.assign_local (| + "current_target" , M.call (| M.get_name (| globals, "compute_contract_address" |), make_list [ @@ -116,17 +133,22 @@ Definition prepare_message : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let msg_data := + |) + |) in + let _ := M.assign_local (| + "msg_data" , M.call (| M.get_name (| globals, "Bytes" |), make_list [ Constant.bytes "" ], make_dict [] - |) in - let code := - M.get_name (| globals, "data" |) in + |) + |) in + let _ := M.assign_local (| + "code" , + M.get_name (| globals, "data" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -143,11 +165,16 @@ Definition prepare_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let current_target := - M.get_name (| globals, "target" |) in - let msg_data := - M.get_name (| globals, "data" |) in - let code := + let _ := M.assign_local (| + "current_target" , + M.get_name (| globals, "target" |) + |) in + let _ := M.assign_local (| + "msg_data" , + M.get_name (| globals, "data" |) + |) in + let _ := M.assign_local (| + "code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -155,7 +182,8 @@ Definition prepare_message : Value.t -> Value.t -> M := M.get_name (| globals, "target" |) ], make_dict [] - |), "code" |) in + |), "code" |) + |) in let _ := (* if *) M.if_then_else (| @@ -165,8 +193,10 @@ Definition prepare_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let code_address := - M.get_name (| globals, "target" |) in + let _ := M.assign_local (| + "code_address" , + M.get_name (| globals, "target" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -186,12 +216,14 @@ Definition prepare_message : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - let accessed_addresses := + let _ := M.assign_local (| + "accessed_addresses" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "accessed_addresses" |), "add" |), make_list [ diff --git a/CoqOfPython/ethereum/gray_glacier/vm/__init__.v b/CoqOfPython/ethereum/gray_glacier/vm/__init__.v index 376d1ca..085ff3e 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/__init__.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/__init__.v @@ -18,29 +18,49 @@ The abstract computer which runs the code stored in an `.fork_types.Account`. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple"; "Union" ]. +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U64"; "U256"; "Bytes"; "Bytes0"; "Bytes32"; "Uint" ]. +Axiom ethereum_base_types_imports_U64 : + IsImported globals "ethereum.base_types" "U64". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". -Axiom ethereum_gray_glacier_blocks_imports : - AreImported globals "ethereum.gray_glacier.blocks" [ "Log" ]. +Axiom ethereum_gray_glacier_blocks_imports_Log : + IsImported globals "ethereum.gray_glacier.blocks" "Log". -Axiom ethereum_gray_glacier_fork_types_imports : - AreImported globals "ethereum.gray_glacier.fork_types" [ "Address" ]. +Axiom ethereum_gray_glacier_fork_types_imports_Address : + IsImported globals "ethereum.gray_glacier.fork_types" "Address". -Axiom ethereum_gray_glacier_state_imports : - AreImported globals "ethereum.gray_glacier.state" [ "State"; "account_exists_and_is_empty" ]. +Axiom ethereum_gray_glacier_state_imports_State : + IsImported globals "ethereum.gray_glacier.state" "State". +Axiom ethereum_gray_glacier_state_imports_account_exists_and_is_empty : + IsImported globals "ethereum.gray_glacier.state" "account_exists_and_is_empty". -Axiom ethereum_gray_glacier_vm_precompiled_contracts_imports : - AreImported globals "ethereum.gray_glacier.vm.precompiled_contracts" [ "RIPEMD160_ADDRESS" ]. +Axiom ethereum_gray_glacier_vm_precompiled_contracts_imports_RIPEMD160_ADDRESS : + IsImported globals "ethereum.gray_glacier.vm.precompiled_contracts" "RIPEMD160_ADDRESS". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] diff --git a/CoqOfPython/ethereum/gray_glacier/vm/exceptions.v b/CoqOfPython/ethereum/gray_glacier/vm/exceptions.v index a429037..3eab002 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/exceptions.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/exceptions.v @@ -17,8 +17,8 @@ Introduction Exceptions which cause the EVM to halt exceptionally. ". -Axiom ethereum_exceptions_imports : - AreImported globals "ethereum.exceptions" [ "EthereumException" ]. +Axiom ethereum_exceptions_imports_EthereumException : + IsImported globals "ethereum.exceptions" "EthereumException". Definition ExceptionalHalt : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/gray_glacier/vm/gas.v b/CoqOfPython/ethereum/gray_glacier/vm/gas.v index 3ae9328..a6dcb12 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/gas.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/gas.v @@ -17,26 +17,32 @@ Introduction EVM gas constants and calculators. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Tuple" ]. +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_trace_imports : - AreImported globals "ethereum.trace" [ "GasAndRefund"; "evm_trace" ]. +Axiom ethereum_trace_imports_GasAndRefund : + IsImported globals "ethereum.trace" "GasAndRefund". +Axiom ethereum_trace_imports_evm_trace : + IsImported globals "ethereum.trace" "evm_trace". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_gray_glacier_vm_imports : - AreImported globals "ethereum.gray_glacier.vm" [ "Evm" ]. +Axiom ethereum_gray_glacier_vm_imports_Evm : + IsImported globals "ethereum.gray_glacier.vm" "Evm". -Axiom ethereum_gray_glacier_vm_exceptions_imports : - AreImported globals "ethereum.gray_glacier.vm.exceptions" [ "OutOfGasError" ]. +Axiom ethereum_gray_glacier_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.gray_glacier.vm.exceptions" "OutOfGasError". Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -532,7 +538,8 @@ Definition calculate_memory_gas_cost : Value.t -> Value.t -> M := total_gas_cost : `ethereum.base_types.Uint` The gas cost for storing data in memory. " in - let size_in_words := + let _ := M.assign_local (| + "size_in_words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -542,25 +549,32 @@ Definition calculate_memory_gas_cost : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let linear_cost := + |) + |) in + let _ := M.assign_local (| + "linear_cost" , BinOp.mult (| M.get_name (| globals, "size_in_words" |), M.get_name (| globals, "GAS_MEMORY" |) - |) in - let quadratic_cost := + |) + |) in + let _ := M.assign_local (| + "quadratic_cost" , BinOp.floor_div (| BinOp.pow (| M.get_name (| globals, "size_in_words" |), Constant.int 2 |), Constant.int 512 - |) in - let total_gas_cost := + |) + |) in + let _ := M.assign_local (| + "total_gas_cost" , BinOp.add (| M.get_name (| globals, "linear_cost" |), M.get_name (| globals, "quadratic_cost" |) - |) in + |) + |) in (* At stmt: unsupported node type: Try *) M.pure Constant.None_)). @@ -582,23 +596,28 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := ------- extend_memory: `ExtendMemory` " in - let size_to_extend := + let _ := M.assign_local (| + "size_to_extend" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in - let to_be_paid := + |) + |) in + let _ := M.assign_local (| + "to_be_paid" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in - let current_size := + |) + |) in + let _ := M.assign_local (| + "current_size" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -611,7 +630,8 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ], @@ -632,15 +652,18 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let before_size := + let _ := M.assign_local (| + "before_size" , M.call (| M.get_name (| globals, "ceil32" |), make_list [ M.get_name (| globals, "current_size" |) ], make_dict [] - |) in - let after_size := + |) + |) in + let _ := M.assign_local (| + "after_size" , M.call (| M.get_name (| globals, "ceil32" |), make_list [ @@ -662,7 +685,8 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -678,42 +702,46 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let size_to_extend := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "size_to_extend", BinOp.sub (| M.get_name (| globals, "after_size" |), M.get_name (| globals, "before_size" |) |) - BinOp.sub (| - M.get_name (| globals, "after_size" |), - M.get_name (| globals, "before_size" |) - |) in - let already_paid := + |) in + let _ := M.assign_local (| + "already_paid" , M.call (| M.get_name (| globals, "calculate_memory_gas_cost" |), make_list [ M.get_name (| globals, "before_size" |) ], make_dict [] - |) in - let total_cost := + |) + |) in + let _ := M.assign_local (| + "total_cost" , M.call (| M.get_name (| globals, "calculate_memory_gas_cost" |), make_list [ M.get_name (| globals, "after_size" |) ], make_dict [] - |) in - let to_be_paid := BinOp.add + |) + |) in + let _ := M.assign_op_local (| + BinOp.add, + "to_be_paid", BinOp.sub (| M.get_name (| globals, "total_cost" |), M.get_name (| globals, "already_paid" |) |) - BinOp.sub (| - M.get_name (| globals, "total_cost" |), - M.get_name (| globals, "already_paid" |) - |) in - let current_size := - M.get_name (| globals, "after_size" |) in + |) in + let _ := M.assign_local (| + "current_size" , + M.get_name (| globals, "after_size" |) + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -760,7 +788,8 @@ Definition calculate_message_call_gas : Value.t -> Value.t -> M := ------- message_call_gas: `MessageCallGas` " in - let call_stipend := + let _ := M.assign_local (| + "call_stipend" , (* if *) M.if_then_else (| Compare.eq (| @@ -779,7 +808,8 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "call_stipend" |) - )) |) in + )) |) + |) in let _ := (* if *) M.if_then_else (| @@ -813,7 +843,8 @@ M.get_name (| globals, "call_stipend" |) )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -833,7 +864,8 @@ M.get_name (| globals, "call_stipend" |) |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "MessageCallGas" |), diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/__init__.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/__init__.v index f2a6201..a505398 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/__init__.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/__init__.v @@ -20,44 +20,46 @@ implementations. (* At top_level_stmt: unsupported node type: Import *) -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict" ]. +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". -Axiom ethereum_gray_glacier_vm_instructions_imports : - AreImported globals "ethereum.gray_glacier.vm.instructions" [ "arithmetic" ]. +Axiom ethereum_gray_glacier_vm_instructions_imports_arithmetic : + IsImported globals "ethereum.gray_glacier.vm.instructions" "arithmetic". -Axiom ethereum_gray_glacier_vm_instructions_imports : - AreImported globals "ethereum.gray_glacier.vm.instructions" [ "bitwise" ]. +Axiom ethereum_gray_glacier_vm_instructions_imports_bitwise : + IsImported globals "ethereum.gray_glacier.vm.instructions" "bitwise". -Axiom ethereum_gray_glacier_vm_instructions_imports : - AreImported globals "ethereum.gray_glacier.vm.instructions" [ "block" ]. +Axiom ethereum_gray_glacier_vm_instructions_imports_block : + IsImported globals "ethereum.gray_glacier.vm.instructions" "block". -Axiom ethereum_gray_glacier_vm_instructions_imports : - AreImported globals "ethereum.gray_glacier.vm.instructions" [ "comparison" ]. +Axiom ethereum_gray_glacier_vm_instructions_imports_comparison : + IsImported globals "ethereum.gray_glacier.vm.instructions" "comparison". -Axiom ethereum_gray_glacier_vm_instructions_imports : - AreImported globals "ethereum.gray_glacier.vm.instructions" [ "control_flow" ]. +Axiom ethereum_gray_glacier_vm_instructions_imports_control_flow : + IsImported globals "ethereum.gray_glacier.vm.instructions" "control_flow". -Axiom ethereum_gray_glacier_vm_instructions_imports : - AreImported globals "ethereum.gray_glacier.vm.instructions" [ "environment" ]. +Axiom ethereum_gray_glacier_vm_instructions_imports_environment : + IsImported globals "ethereum.gray_glacier.vm.instructions" "environment". -Axiom ethereum_gray_glacier_vm_instructions_imports : - AreImported globals "ethereum.gray_glacier.vm.instructions" [ "keccak" ]. +Axiom ethereum_gray_glacier_vm_instructions_imports_keccak : + IsImported globals "ethereum.gray_glacier.vm.instructions" "keccak". -Axiom ethereum_gray_glacier_vm_instructions_imports : - AreImported globals "ethereum.gray_glacier.vm.instructions" [ "log" ]. +Axiom ethereum_gray_glacier_vm_instructions_imports_log : + IsImported globals "ethereum.gray_glacier.vm.instructions" "log". -Axiom ethereum_gray_glacier_vm_instructions_imports : - AreImported globals "ethereum.gray_glacier.vm.instructions" [ "memory" ]. +Axiom ethereum_gray_glacier_vm_instructions_imports_memory : + IsImported globals "ethereum.gray_glacier.vm.instructions" "memory". -Axiom ethereum_gray_glacier_vm_instructions_imports : - AreImported globals "ethereum.gray_glacier.vm.instructions" [ "stack" ]. +Axiom ethereum_gray_glacier_vm_instructions_imports_stack : + IsImported globals "ethereum.gray_glacier.vm.instructions" "stack". -Axiom ethereum_gray_glacier_vm_instructions_imports : - AreImported globals "ethereum.gray_glacier.vm.instructions" [ "storage" ]. +Axiom ethereum_gray_glacier_vm_instructions_imports_storage : + IsImported globals "ethereum.gray_glacier.vm.instructions" "storage". -Axiom ethereum_gray_glacier_vm_instructions_imports : - AreImported globals "ethereum.gray_glacier.vm.instructions" [ "system" ]. +Axiom ethereum_gray_glacier_vm_instructions_imports_system : + IsImported globals "ethereum.gray_glacier.vm.instructions" "system". Definition Ops : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/arithmetic.v index a5388a5..d4d5eed 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/arithmetic.v @@ -17,20 +17,38 @@ Introduction Implementations of the EVM Arithmetic instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U255_CEIL_VALUE"; "U256"; "U256_CEIL_VALUE"; "Uint" ]. +Axiom ethereum_base_types_imports_U255_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U255_CEIL_VALUE". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_U256_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U256_CEIL_VALUE". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "get_sign" ]. +Axiom ethereum_utils_numeric_imports_get_sign : + IsImported globals "ethereum.utils.numeric" "get_sign". -Axiom ethereum_gray_glacier_vm_imports : - AreImported globals "ethereum.gray_glacier.vm" [ "Evm" ]. +Axiom ethereum_gray_glacier_vm_imports_Evm : + IsImported globals "ethereum.gray_glacier.vm" "Evm". -Axiom ethereum_gray_glacier_vm_gas_imports : - AreImported globals "ethereum.gray_glacier.vm.gas" [ "GAS_EXPONENTIATION"; "GAS_EXPONENTIATION_PER_BYTE"; "GAS_LOW"; "GAS_MID"; "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_EXPONENTIATION : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_EXPONENTIATION". +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_EXPONENTIATION_PER_BYTE : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_EXPONENTIATION_PER_BYTE". +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_LOW : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_LOW". +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_MID : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_MID". +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_gray_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.gray_glacier.vm.gas" "charge_gas". -Axiom ethereum_gray_glacier_vm_stack_imports : - AreImported globals "ethereum.gray_glacier.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_gray_glacier_vm_stack_imports_pop : + IsImported globals "ethereum.gray_glacier.vm.stack" "pop". +Axiom ethereum_gray_glacier_vm_stack_imports_push : + IsImported globals "ethereum.gray_glacier.vm.stack" "push". Definition add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,22 +63,26 @@ Definition add : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -69,14 +91,16 @@ Definition add : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "x" |), "wrapping_add" |), make_list [ M.get_name (| globals, "y" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -105,22 +129,26 @@ Definition sub : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -129,14 +157,16 @@ Definition sub : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "x" |), "wrapping_sub" |), make_list [ M.get_name (| globals, "y" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -165,22 +195,26 @@ Definition mul : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -189,14 +223,16 @@ Definition mul : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "x" |), "wrapping_mul" |), make_list [ M.get_name (| globals, "y" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -225,22 +261,26 @@ Definition div : Value.t -> Value.t -> M := The current EVM frame. " in - let dividend := + let _ := M.assign_local (| + "dividend" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let divisor := + |) + |) in + let _ := M.assign_local (| + "divisor" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -258,22 +298,26 @@ Definition div : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let quotient := + let _ := M.assign_local (| + "quotient" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let quotient := + let _ := M.assign_local (| + "quotient" , BinOp.floor_div (| M.get_name (| globals, "dividend" |), M.get_name (| globals, "divisor" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -304,7 +348,8 @@ Definition sdiv : Value.t -> Value.t -> M := The current EVM frame. " in - let dividend := + let _ := M.assign_local (| + "dividend" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -315,8 +360,10 @@ Definition sdiv : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let divisor := + |) + |) in + let _ := M.assign_local (| + "divisor" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -327,7 +374,8 @@ Definition sdiv : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -345,8 +393,10 @@ Definition sdiv : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let quotient := - Constant.int 0 in + let _ := M.assign_local (| + "quotient" , + Constant.int 0 + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -367,12 +417,15 @@ Definition sdiv : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let quotient := - UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in + let _ := M.assign_local (| + "quotient" , + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let sign := + let _ := M.assign_local (| + "sign" , M.call (| M.get_name (| globals, "get_sign" |), make_list [ @@ -382,8 +435,10 @@ Definition sdiv : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let quotient := + |) + |) in + let _ := M.assign_local (| + "quotient" , BinOp.mult (| M.get_name (| globals, "sign" |), BinOp.floor_div (| @@ -402,7 +457,8 @@ Definition sdiv : Value.t -> Value.t -> M := make_dict [] |) |) - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -428,7 +484,7 @@ Definition sdiv : Value.t -> Value.t -> M := |) in M.pure Constant.None_)). -Definition mod : Value.t -> Value.t -> M := +Definition mod_ : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in let _ := Constant.str " @@ -441,22 +497,26 @@ Definition mod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -474,22 +534,26 @@ Definition mod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let remainder := + let _ := M.assign_local (| + "remainder" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let remainder := + let _ := M.assign_local (| + "remainder" , BinOp.mod_ (| M.get_name (| globals, "x" |), M.get_name (| globals, "y" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -520,7 +584,8 @@ Definition smod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -531,8 +596,10 @@ Definition smod : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -543,7 +610,8 @@ Definition smod : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -561,12 +629,15 @@ Definition smod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let remainder := - Constant.int 0 in + let _ := M.assign_local (| + "remainder" , + Constant.int 0 + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let remainder := + let _ := M.assign_local (| + "remainder" , BinOp.mult (| M.call (| M.get_name (| globals, "get_sign" |), @@ -591,7 +662,8 @@ Definition smod : Value.t -> Value.t -> M := make_dict [] |) |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -628,7 +700,8 @@ Definition addmod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -641,8 +714,10 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -655,8 +730,10 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let z := + |) + |) in + let _ := M.assign_local (| + "z" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -669,7 +746,8 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -687,18 +765,21 @@ Definition addmod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -711,7 +792,8 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -742,7 +824,8 @@ Definition mulmod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -755,8 +838,10 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -769,8 +854,10 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let z := + |) + |) in + let _ := M.assign_local (| + "z" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -783,7 +870,8 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -801,18 +889,21 @@ Definition mulmod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -825,7 +916,8 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -856,7 +948,8 @@ Definition exp : Value.t -> Value.t -> M := The current EVM frame. " in - let base := + let _ := M.assign_local (| + "base" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -869,8 +962,10 @@ Definition exp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exponent := + |) + |) in + let _ := M.assign_local (| + "exponent" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -883,21 +978,26 @@ Definition exp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exponent_bits := + |) + |) in + let _ := M.assign_local (| + "exponent_bits" , M.call (| M.get_field (| M.get_name (| globals, "exponent" |), "bit_length" |), make_list [], make_dict [] - |) in - let exponent_bytes := + |) + |) in + let _ := M.assign_local (| + "exponent_bytes" , BinOp.floor_div (| BinOp.add (| M.get_name (| globals, "exponent_bits" |), Constant.int 7 |), Constant.int 8 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -912,7 +1012,8 @@ Definition exp : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -927,7 +1028,8 @@ Definition exp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -956,22 +1058,26 @@ Definition signextend : Value.t -> Value.t -> M := The current EVM frame. " in - let byte_num := + let _ := M.assign_local (| + "byte_num" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -989,12 +1095,15 @@ Definition signextend : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := - M.get_name (| globals, "value" |) in + let _ := M.assign_local (| + "result" , + M.get_name (| globals, "value" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let value_bytes := + let _ := M.assign_local (| + "value_bytes" , M.call (| M.get_name (| globals, "bytes" |), make_list [ @@ -1005,8 +1114,10 @@ Definition signextend : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let value_bytes := + |) + |) in + let _ := M.assign_local (| + "value_bytes" , M.slice (| M.get_name (| globals, "value_bytes" |), BinOp.sub (| @@ -1021,15 +1132,18 @@ Definition signextend : Value.t -> Value.t -> M := |), Constant.None_, Constant.None_ - |) in - let sign_bit := + |) + |) in + let _ := M.assign_local (| + "sign_bit" , BinOp.r_shift (| M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), Constant.int 7 - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1039,26 +1153,31 @@ Definition signextend : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "value_bytes" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let num_bytes_prepend := + let _ := M.assign_local (| + "num_bytes_prepend" , BinOp.sub (| Constant.int 32, BinOp.add (| M.get_name (| globals, "byte_num" |), Constant.int 1 |) - |) in - let result := + |) + |) in + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -1079,7 +1198,8 @@ Definition signextend : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/bitwise.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/bitwise.v index ada0bff..c580c05 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/bitwise.v @@ -17,17 +17,23 @@ Introduction Implementations of the EVM bitwise instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "U256_CEIL_VALUE" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_U256_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U256_CEIL_VALUE". -Axiom ethereum_gray_glacier_vm_imports : - AreImported globals "ethereum.gray_glacier.vm" [ "Evm" ]. +Axiom ethereum_gray_glacier_vm_imports_Evm : + IsImported globals "ethereum.gray_glacier.vm" "Evm". -Axiom ethereum_gray_glacier_vm_gas_imports : - AreImported globals "ethereum.gray_glacier.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_gray_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.gray_glacier.vm.gas" "charge_gas". -Axiom ethereum_gray_glacier_vm_stack_imports : - AreImported globals "ethereum.gray_glacier.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_gray_glacier_vm_stack_imports_pop : + IsImported globals "ethereum.gray_glacier.vm.stack" "pop". +Axiom ethereum_gray_glacier_vm_stack_imports_push : + IsImported globals "ethereum.gray_glacier.vm.stack" "push". Definition bitwise_and : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,22 +48,26 @@ Definition bitwise_and : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -97,22 +107,26 @@ Definition bitwise_or : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -152,22 +166,26 @@ Definition bitwise_xor : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -207,14 +225,16 @@ Definition bitwise_not : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -252,22 +272,26 @@ Definition get_byte : Value.t -> Value.t -> M := The current EVM frame. " in - let byte_index := + let _ := M.assign_local (| + "byte_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let word := + |) + |) in + let _ := M.assign_local (| + "word" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -285,43 +309,53 @@ Definition get_byte : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let extra_bytes_to_right := + let _ := M.assign_local (| + "extra_bytes_to_right" , BinOp.sub (| Constant.int 31, M.get_name (| globals, "byte_index" |) - |) in - let word := + |) + |) in + let _ := M.assign_local (| + "word" , BinOp.r_shift (| M.get_name (| globals, "word" |), BinOp.mult (| M.get_name (| globals, "extra_bytes_to_right" |), Constant.int 8 |) - |) in - let word := + |) + |) in + let _ := M.assign_local (| + "word" , BinOp.bit_and (| M.get_name (| globals, "word" |), Constant.int 255 - |) in - let result := + |) + |) in + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ M.get_name (| globals, "word" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -350,22 +384,26 @@ Definition bitwise_shl : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let shift := + let _ := M.assign_local (| + "shift" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -383,7 +421,8 @@ Definition bitwise_shl : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -396,18 +435,21 @@ Definition bitwise_shl : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -436,22 +478,26 @@ Definition bitwise_shr : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let shift := + let _ := M.assign_local (| + "shift" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -469,22 +515,26 @@ Definition bitwise_shr : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , BinOp.r_shift (| M.get_name (| globals, "value" |), M.get_name (| globals, "shift" |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -513,15 +563,18 @@ Definition bitwise_sar : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let shift := + let _ := M.assign_local (| + "shift" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let signed_value := + |) + |) in + let _ := M.assign_local (| + "signed_value" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -532,7 +585,8 @@ Definition bitwise_sar : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -550,7 +604,8 @@ Definition bitwise_sar : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), make_list [ @@ -560,7 +615,8 @@ Definition bitwise_sar : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -573,19 +629,23 @@ Definition bitwise_sar : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := - M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) in + let _ := M.assign_local (| + "result" , + M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/block.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/block.v index 4f07399..1b25dc5 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/block.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/block.v @@ -17,17 +17,23 @@ Introduction Implementations of the EVM block instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_gray_glacier_vm_imports : - AreImported globals "ethereum.gray_glacier.vm" [ "Evm" ]. +Axiom ethereum_gray_glacier_vm_imports_Evm : + IsImported globals "ethereum.gray_glacier.vm" "Evm". -Axiom ethereum_gray_glacier_vm_gas_imports : - AreImported globals "ethereum.gray_glacier.vm.gas" [ "GAS_BASE"; "GAS_BLOCK_HASH"; "charge_gas" ]. +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_BASE". +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_BLOCK_HASH : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_BLOCK_HASH". +Axiom ethereum_gray_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.gray_glacier.vm.gas" "charge_gas". -Axiom ethereum_gray_glacier_vm_stack_imports : - AreImported globals "ethereum.gray_glacier.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_gray_glacier_vm_stack_imports_pop : + IsImported globals "ethereum.gray_glacier.vm.stack" "pop". +Axiom ethereum_gray_glacier_vm_stack_imports_push : + IsImported globals "ethereum.gray_glacier.vm.stack" "push". Definition block_hash : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,14 +48,16 @@ Definition block_hash : Value.t -> Value.t -> M := The current EVM frame. " in - let block_number := + let _ := M.assign_local (| + "block_number" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -78,19 +86,23 @@ Definition block_hash : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let hash := - Constant.bytes "00" in + let _ := M.assign_local (| + "hash" , + Constant.bytes "00" + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let hash := + let _ := M.assign_local (| + "hash" , M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), M.get_name (| globals, "block_number" |) |) |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/comparison.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/comparison.v index b32daf2..64165db 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/comparison.v @@ -17,17 +17,21 @@ Introduction Implementations of the EVM Comparison instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_gray_glacier_vm_imports : - AreImported globals "ethereum.gray_glacier.vm" [ "Evm" ]. +Axiom ethereum_gray_glacier_vm_imports_Evm : + IsImported globals "ethereum.gray_glacier.vm" "Evm". -Axiom ethereum_gray_glacier_vm_gas_imports : - AreImported globals "ethereum.gray_glacier.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_gray_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.gray_glacier.vm.gas" "charge_gas". -Axiom ethereum_gray_glacier_vm_stack_imports : - AreImported globals "ethereum.gray_glacier.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_gray_glacier_vm_stack_imports_pop : + IsImported globals "ethereum.gray_glacier.vm.stack" "pop". +Axiom ethereum_gray_glacier_vm_stack_imports_push : + IsImported globals "ethereum.gray_glacier.vm.stack" "push". Definition less_than : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,22 +46,26 @@ Definition less_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -66,7 +74,8 @@ Definition less_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -76,7 +85,8 @@ Definition less_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -104,7 +114,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -115,8 +126,10 @@ Definition signed_less_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -127,7 +140,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -136,7 +150,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -146,7 +161,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -175,22 +191,26 @@ Definition greater_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -199,7 +219,8 @@ Definition greater_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -209,7 +230,8 @@ Definition greater_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -237,7 +259,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -248,8 +271,10 @@ Definition signed_greater_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -260,7 +285,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -269,7 +295,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -279,7 +306,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -308,22 +336,26 @@ Definition equal : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -332,7 +364,8 @@ Definition equal : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -342,7 +375,8 @@ Definition equal : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -371,14 +405,16 @@ Definition is_zero : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -387,7 +423,8 @@ Definition is_zero : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -397,7 +434,8 @@ Definition is_zero : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/control_flow.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/control_flow.v index 25a48b1..0438b4c 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/control_flow.v @@ -17,20 +17,32 @@ Introduction Implementations of the EVM control flow instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_gray_glacier_vm_gas_imports : - AreImported globals "ethereum.gray_glacier.vm.gas" [ "GAS_BASE"; "GAS_HIGH"; "GAS_JUMPDEST"; "GAS_MID"; "charge_gas" ]. +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_BASE". +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_HIGH : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_HIGH". +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_JUMPDEST : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_JUMPDEST". +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_MID : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_MID". +Axiom ethereum_gray_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.gray_glacier.vm.gas" "charge_gas". -Axiom ethereum_gray_glacier_vm_imports : - AreImported globals "ethereum.gray_glacier.vm" [ "Evm" ]. +Axiom ethereum_gray_glacier_vm_imports_Evm : + IsImported globals "ethereum.gray_glacier.vm" "Evm". -Axiom ethereum_gray_glacier_vm_exceptions_imports : - AreImported globals "ethereum.gray_glacier.vm.exceptions" [ "InvalidJumpDestError" ]. +Axiom ethereum_gray_glacier_vm_exceptions_imports_InvalidJumpDestError : + IsImported globals "ethereum.gray_glacier.vm.exceptions" "InvalidJumpDestError". -Axiom ethereum_gray_glacier_vm_stack_imports : - AreImported globals "ethereum.gray_glacier.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_gray_glacier_vm_stack_imports_pop : + IsImported globals "ethereum.gray_glacier.vm.stack" "pop". +Axiom ethereum_gray_glacier_vm_stack_imports_push : + IsImported globals "ethereum.gray_glacier.vm.stack" "push". Definition stop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -69,7 +81,8 @@ Definition jump : Value.t -> Value.t -> M := The current EVM frame. " in - let jump_dest := + let _ := M.assign_local (| + "jump_dest" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -82,7 +95,8 @@ Definition jump : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -132,7 +146,8 @@ Definition jumpi : Value.t -> Value.t -> M := The current EVM frame. " in - let jump_dest := + let _ := M.assign_local (| + "jump_dest" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -145,15 +160,18 @@ Definition jumpi : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let conditional_value := + |) + |) in + let _ := M.assign_local (| + "conditional_value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -171,11 +189,13 @@ Definition jumpi : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let destination := + let _ := M.assign_local (| + "destination" , BinOp.add (| M.get_field (| M.get_name (| globals, "evm" |), "pc" |), Constant.int 1 - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -192,8 +212,10 @@ Definition jumpi : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let destination := - M.get_name (| globals, "jump_dest" |) in + let _ := M.assign_local (| + "destination" , + M.get_name (| globals, "jump_dest" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/environment.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/environment.v index efeb715..13a017d 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/environment.v @@ -17,41 +17,63 @@ Introduction Implementations of the EVM environment related instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. - -Axiom ethereum_gray_glacier_fork_types_imports : - AreImported globals "ethereum.gray_glacier.fork_types" [ "EMPTY_ACCOUNT" ]. - -Axiom ethereum_gray_glacier_state_imports : - AreImported globals "ethereum.gray_glacier.state" [ "get_account" ]. - -Axiom ethereum_gray_glacier_utils_address_imports : - AreImported globals "ethereum.gray_glacier.utils.address" [ "to_address" ]. - -Axiom ethereum_gray_glacier_vm_memory_imports : - AreImported globals "ethereum.gray_glacier.vm.memory" [ "buffer_read"; "memory_write" ]. - -Axiom ethereum_gray_glacier_vm_imports : - AreImported globals "ethereum.gray_glacier.vm" [ "Evm" ]. - -Axiom ethereum_gray_glacier_vm_exceptions_imports : - AreImported globals "ethereum.gray_glacier.vm.exceptions" [ "OutOfBoundsRead" ]. - -Axiom ethereum_gray_glacier_vm_gas_imports : - AreImported globals "ethereum.gray_glacier.vm.gas" [ "GAS_BASE"; "GAS_COLD_ACCOUNT_ACCESS"; "GAS_COPY"; "GAS_FAST_STEP"; "GAS_RETURN_DATA_COPY"; "GAS_VERY_LOW"; "GAS_WARM_ACCESS"; "calculate_gas_extend_memory"; "charge_gas" ]. - -Axiom ethereum_gray_glacier_vm_stack_imports : - AreImported globals "ethereum.gray_glacier.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". + +Axiom ethereum_gray_glacier_fork_types_imports_EMPTY_ACCOUNT : + IsImported globals "ethereum.gray_glacier.fork_types" "EMPTY_ACCOUNT". + +Axiom ethereum_gray_glacier_state_imports_get_account : + IsImported globals "ethereum.gray_glacier.state" "get_account". + +Axiom ethereum_gray_glacier_utils_address_imports_to_address : + IsImported globals "ethereum.gray_glacier.utils.address" "to_address". + +Axiom ethereum_gray_glacier_vm_memory_imports_buffer_read : + IsImported globals "ethereum.gray_glacier.vm.memory" "buffer_read". +Axiom ethereum_gray_glacier_vm_memory_imports_memory_write : + IsImported globals "ethereum.gray_glacier.vm.memory" "memory_write". + +Axiom ethereum_gray_glacier_vm_imports_Evm : + IsImported globals "ethereum.gray_glacier.vm" "Evm". + +Axiom ethereum_gray_glacier_vm_exceptions_imports_OutOfBoundsRead : + IsImported globals "ethereum.gray_glacier.vm.exceptions" "OutOfBoundsRead". + +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_BASE". +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_COLD_ACCOUNT_ACCESS : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_COLD_ACCOUNT_ACCESS". +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_COPY : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_COPY". +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_FAST_STEP : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_FAST_STEP". +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_RETURN_DATA_COPY : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_RETURN_DATA_COPY". +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_WARM_ACCESS : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_WARM_ACCESS". +Axiom ethereum_gray_glacier_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.gray_glacier.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_gray_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.gray_glacier.vm.gas" "charge_gas". + +Axiom ethereum_gray_glacier_vm_stack_imports_pop : + IsImported globals "ethereum.gray_glacier.vm.stack" "pop". +Axiom ethereum_gray_glacier_vm_stack_imports_push : + IsImported globals "ethereum.gray_glacier.vm.stack" "push". Definition address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -107,7 +129,8 @@ Definition balance : Value.t -> Value.t -> M := The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -120,7 +143,8 @@ Definition balance : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -158,7 +182,8 @@ Definition balance : Value.t -> Value.t -> M := |) in M.pure Constant.None_ )) |) in - let balance := + let _ := M.assign_local (| + "balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -166,7 +191,8 @@ Definition balance : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -316,14 +342,16 @@ Definition calldataload : Value.t -> Value.t -> M := The current EVM frame. " in - let start_index := + let _ := M.assign_local (| + "start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -332,7 +360,8 @@ Definition calldataload : Value.t -> Value.t -> M := ], make_dict [] |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -347,7 +376,8 @@ Definition calldataload : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -432,31 +462,38 @@ Definition calldatacopy : Value.t -> Value.t -> M := The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let data_start_index := + |) + |) in + let _ := M.assign_local (| + "data_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -472,13 +509,17 @@ Definition calldatacopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -488,7 +529,8 @@ Definition calldatacopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -511,7 +553,8 @@ Definition calldatacopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -520,7 +563,8 @@ Definition calldatacopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -600,31 +644,38 @@ Definition codecopy : Value.t -> Value.t -> M := The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let code_start_index := + |) + |) in + let _ := M.assign_local (| + "code_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -640,13 +691,17 @@ Definition codecopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -656,7 +711,8 @@ Definition codecopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -679,7 +735,8 @@ Definition codecopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -688,7 +745,8 @@ Definition codecopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -759,7 +817,8 @@ Definition extcodesize : Value.t -> Value.t -> M := The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -772,7 +831,8 @@ Definition extcodesize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -810,7 +870,8 @@ Definition extcodesize : Value.t -> Value.t -> M := |) in M.pure Constant.None_ )) |) in - let codesize := + let _ := M.assign_local (| + "codesize" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -830,7 +891,8 @@ Definition extcodesize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -858,7 +920,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -871,32 +934,40 @@ Definition extcodecopy : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let memory_start_index := + |) + |) in + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let code_start_index := + |) + |) in + let _ := M.assign_local (| + "code_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -912,13 +983,17 @@ Definition extcodecopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -928,7 +1003,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -986,7 +1062,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let code := + let _ := M.assign_local (| + "code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -994,8 +1071,10 @@ Definition extcodecopy : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |), "code" |) in - let value := + |), "code" |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -1004,7 +1083,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -1079,31 +1159,38 @@ Definition returndatacopy : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let return_data_start_position := + |) + |) in + let _ := M.assign_local (| + "return_data_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -1119,13 +1206,17 @@ Definition returndatacopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_RETURN_DATA_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1135,7 +1226,8 @@ Definition returndatacopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1190,7 +1282,8 @@ Definition returndatacopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.slice (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |), @@ -1199,7 +1292,8 @@ Definition returndatacopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) |), Constant.None_ - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -1226,7 +1320,8 @@ Definition extcodehash : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1239,7 +1334,8 @@ Definition extcodehash : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1277,7 +1373,8 @@ Definition extcodehash : Value.t -> Value.t -> M := |) in M.pure Constant.None_ )) |) in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1285,7 +1382,8 @@ Definition extcodehash : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1295,18 +1393,21 @@ Definition extcodehash : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let codehash := + let _ := M.assign_local (| + "codehash" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let codehash := + let _ := M.assign_local (| + "codehash" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -1319,7 +1420,8 @@ Definition extcodehash : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -1358,7 +1460,8 @@ Definition self_balance : Value.t -> Value.t -> M := ], make_dict [] |) in - let balance := + let _ := M.assign_local (| + "balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1366,7 +1469,8 @@ Definition self_balance : Value.t -> Value.t -> M := M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/keccak.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/keccak.v index f6861d6..a82edc7 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/keccak.v @@ -17,26 +17,36 @@ Introduction Implementations of the EVM keccak instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_gray_glacier_vm_imports : - AreImported globals "ethereum.gray_glacier.vm" [ "Evm" ]. +Axiom ethereum_gray_glacier_vm_imports_Evm : + IsImported globals "ethereum.gray_glacier.vm" "Evm". -Axiom ethereum_gray_glacier_vm_gas_imports : - AreImported globals "ethereum.gray_glacier.vm.gas" [ "GAS_KECCAK256"; "GAS_KECCAK256_WORD"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_KECCAK256 : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_KECCAK256". +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_KECCAK256_WORD : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_KECCAK256_WORD". +Axiom ethereum_gray_glacier_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.gray_glacier.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_gray_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.gray_glacier.vm.gas" "charge_gas". -Axiom ethereum_gray_glacier_vm_memory_imports : - AreImported globals "ethereum.gray_glacier.vm.memory" [ "memory_read_bytes" ]. +Axiom ethereum_gray_glacier_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.gray_glacier.vm.memory" "memory_read_bytes". -Axiom ethereum_gray_glacier_vm_stack_imports : - AreImported globals "ethereum.gray_glacier.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_gray_glacier_vm_stack_imports_pop : + IsImported globals "ethereum.gray_glacier.vm.stack" "pop". +Axiom ethereum_gray_glacier_vm_stack_imports_push : + IsImported globals "ethereum.gray_glacier.vm.stack" "push". Definition keccak : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -53,23 +63,28 @@ Definition keccak : Value.t -> Value.t -> M := The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -85,13 +100,17 @@ Definition keccak : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let word_gas_cost := + |) + |) in + let _ := M.assign_local (| + "word_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_KECCAK256_WORD" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -101,7 +120,8 @@ Definition keccak : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -124,7 +144,8 @@ Definition keccak : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let data := + let _ := M.assign_local (| + "data" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -133,15 +154,18 @@ Definition keccak : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in - let hash := + |) + |) in + let _ := M.assign_local (| + "hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "data" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/log.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/log.v index b438023..6e41a53 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/log.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/log.v @@ -17,32 +17,40 @@ Introduction Implementations of the EVM logging instructions. ". -Axiom functools_imports : - AreImported globals "functools" [ "partial" ]. +Axiom functools_imports_partial : + IsImported globals "functools" "partial". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_gray_glacier_blocks_imports : - AreImported globals "ethereum.gray_glacier.blocks" [ "Log" ]. +Axiom ethereum_gray_glacier_blocks_imports_Log : + IsImported globals "ethereum.gray_glacier.blocks" "Log". -Axiom ethereum_gray_glacier_vm_imports : - AreImported globals "ethereum.gray_glacier.vm" [ "Evm" ]. +Axiom ethereum_gray_glacier_vm_imports_Evm : + IsImported globals "ethereum.gray_glacier.vm" "Evm". -Axiom ethereum_gray_glacier_vm_exceptions_imports : - AreImported globals "ethereum.gray_glacier.vm.exceptions" [ "WriteInStaticContext" ]. +Axiom ethereum_gray_glacier_vm_exceptions_imports_WriteInStaticContext : + IsImported globals "ethereum.gray_glacier.vm.exceptions" "WriteInStaticContext". -Axiom ethereum_gray_glacier_vm_gas_imports : - AreImported globals "ethereum.gray_glacier.vm.gas" [ "GAS_LOG"; "GAS_LOG_DATA"; "GAS_LOG_TOPIC"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_LOG : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_LOG". +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_LOG_DATA : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_LOG_DATA". +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_LOG_TOPIC : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_LOG_TOPIC". +Axiom ethereum_gray_glacier_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.gray_glacier.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_gray_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.gray_glacier.vm.gas" "charge_gas". -Axiom ethereum_gray_glacier_vm_memory_imports : - AreImported globals "ethereum.gray_glacier.vm.memory" [ "memory_read_bytes" ]. +Axiom ethereum_gray_glacier_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.gray_glacier.vm.memory" "memory_read_bytes". -Axiom ethereum_gray_glacier_vm_stack_imports : - AreImported globals "ethereum.gray_glacier.vm.stack" [ "pop" ]. +Axiom ethereum_gray_glacier_vm_stack_imports_pop : + IsImported globals "ethereum.gray_glacier.vm.stack" "pop". Definition log_n : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -61,24 +69,30 @@ Definition log_n : Value.t -> Value.t -> M := The number of topics to be included in the log entry. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let topics := - make_list [] in + |) + |) in + let _ := M.assign_local (| + "topics" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "_" |), @@ -90,7 +104,8 @@ Definition log_n : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let topic := + let _ := M.assign_local (| + "topic" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -101,7 +116,8 @@ Definition log_n : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "topics" |), "append" |), make_list [ @@ -115,7 +131,8 @@ Definition log_n : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let extend_memory := + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -125,7 +142,8 @@ Definition log_n : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -165,12 +183,14 @@ Definition log_n : Value.t -> Value.t -> M := ], make_dict [] |) in - let log_entry := + let _ := M.assign_local (| + "log_entry" , M.call (| M.get_name (| globals, "Log" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "logs" |), BinOp.add (| diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/memory.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/memory.v index a86572c..1516f1c 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/memory.v @@ -17,20 +17,32 @@ Introduction Implementations of the EVM Memory instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". -Axiom ethereum_gray_glacier_vm_imports : - AreImported globals "ethereum.gray_glacier.vm" [ "Evm" ]. +Axiom ethereum_gray_glacier_vm_imports_Evm : + IsImported globals "ethereum.gray_glacier.vm" "Evm". -Axiom ethereum_gray_glacier_vm_gas_imports : - AreImported globals "ethereum.gray_glacier.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_BASE". +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_gray_glacier_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.gray_glacier.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_gray_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.gray_glacier.vm.gas" "charge_gas". -Axiom ethereum_gray_glacier_vm_memory_imports : - AreImported globals "ethereum.gray_glacier.vm.memory" [ "memory_read_bytes"; "memory_write" ]. +Axiom ethereum_gray_glacier_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.gray_glacier.vm.memory" "memory_read_bytes". +Axiom ethereum_gray_glacier_vm_memory_imports_memory_write : + IsImported globals "ethereum.gray_glacier.vm.memory" "memory_write". -Axiom ethereum_gray_glacier_vm_stack_imports : - AreImported globals "ethereum.gray_glacier.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_gray_glacier_vm_stack_imports_pop : + IsImported globals "ethereum.gray_glacier.vm.stack" "pop". +Axiom ethereum_gray_glacier_vm_stack_imports_push : + IsImported globals "ethereum.gray_glacier.vm.stack" "push". Definition mstore : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -46,15 +58,18 @@ Definition mstore : Value.t -> Value.t -> M := The current EVM frame. " in - let start_position := + let _ := M.assign_local (| + "start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -65,8 +80,10 @@ Definition mstore : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -88,7 +105,8 @@ Definition mstore : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -138,23 +156,28 @@ Definition mstore8 : Value.t -> Value.t -> M := The current EVM frame. " in - let start_position := + let _ := M.assign_local (| + "start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -170,7 +193,8 @@ Definition mstore8 : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -190,7 +214,8 @@ Definition mstore8 : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let normalized_bytes_value := + let _ := M.assign_local (| + "normalized_bytes_value" , M.call (| M.get_name (| globals, "Bytes" |), make_list [ @@ -202,7 +227,8 @@ Definition mstore8 : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -231,15 +257,18 @@ Definition mload : Value.t -> Value.t -> M := The current EVM frame. " in - let start_position := + let _ := M.assign_local (| + "start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -255,7 +284,8 @@ Definition mload : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -275,7 +305,8 @@ Definition mload : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -296,7 +327,8 @@ Definition mload : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/stack.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/stack.v index 73ca8c9..c680a10 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/stack.v @@ -17,26 +17,32 @@ Introduction Implementations of the EVM stack related instructions. ". -Axiom functools_imports : - AreImported globals "functools" [ "partial" ]. +Axiom functools_imports_partial : + IsImported globals "functools" "partial". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_gray_glacier_vm_imports : - AreImported globals "ethereum.gray_glacier.vm" [ "Evm"; "stack" ]. +Axiom ethereum_gray_glacier_vm_imports_Evm : + IsImported globals "ethereum.gray_glacier.vm" "Evm". +Axiom ethereum_gray_glacier_vm_imports_stack : + IsImported globals "ethereum.gray_glacier.vm" "stack". -Axiom ethereum_gray_glacier_vm_exceptions_imports : - AreImported globals "ethereum.gray_glacier.vm.exceptions" [ "StackUnderflowError" ]. +Axiom ethereum_gray_glacier_vm_exceptions_imports_StackUnderflowError : + IsImported globals "ethereum.gray_glacier.vm.exceptions" "StackUnderflowError". -Axiom ethereum_gray_glacier_vm_gas_imports : - AreImported globals "ethereum.gray_glacier.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_BASE". +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_gray_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.gray_glacier.vm.gas" "charge_gas". -Axiom ethereum_gray_glacier_vm_memory_imports : - AreImported globals "ethereum.gray_glacier.vm.memory" [ "buffer_read" ]. +Axiom ethereum_gray_glacier_vm_memory_imports_buffer_read : + IsImported globals "ethereum.gray_glacier.vm.memory" "buffer_read". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -98,7 +104,8 @@ Definition push_n : Value.t -> Value.t -> M := ], make_dict [] |) in - let data_to_push := + let _ := M.assign_local (| + "data_to_push" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -128,7 +135,8 @@ Definition push_n : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "stack" |), "push" |), make_list [ @@ -189,7 +197,8 @@ Definition dup_n : Value.t -> Value.t -> M := ], make_dict [] |) in - let data_to_duplicate := + let _ := M.assign_local (| + "data_to_duplicate" , M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| @@ -205,7 +214,8 @@ Definition dup_n : Value.t -> Value.t -> M := |), M.get_name (| globals, "item_number" |) |) - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "stack" |), "push" |), make_list [ diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/storage.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/storage.v index 7bb3cb1..81cda0d 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/storage.v @@ -17,26 +17,46 @@ Introduction Implementations of the EVM storage related instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_gray_glacier_state_imports : - AreImported globals "ethereum.gray_glacier.state" [ "get_storage"; "get_storage_original"; "set_storage" ]. +Axiom ethereum_gray_glacier_state_imports_get_storage : + IsImported globals "ethereum.gray_glacier.state" "get_storage". +Axiom ethereum_gray_glacier_state_imports_get_storage_original : + IsImported globals "ethereum.gray_glacier.state" "get_storage_original". +Axiom ethereum_gray_glacier_state_imports_set_storage : + IsImported globals "ethereum.gray_glacier.state" "set_storage". -Axiom ethereum_gray_glacier_vm_imports : - AreImported globals "ethereum.gray_glacier.vm" [ "Evm" ]. +Axiom ethereum_gray_glacier_vm_imports_Evm : + IsImported globals "ethereum.gray_glacier.vm" "Evm". -Axiom ethereum_gray_glacier_vm_exceptions_imports : - AreImported globals "ethereum.gray_glacier.vm.exceptions" [ "OutOfGasError"; "WriteInStaticContext" ]. +Axiom ethereum_gray_glacier_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.gray_glacier.vm.exceptions" "OutOfGasError". +Axiom ethereum_gray_glacier_vm_exceptions_imports_WriteInStaticContext : + IsImported globals "ethereum.gray_glacier.vm.exceptions" "WriteInStaticContext". -Axiom ethereum_gray_glacier_vm_gas_imports : - AreImported globals "ethereum.gray_glacier.vm.gas" [ "GAS_CALL_STIPEND"; "GAS_COLD_SLOAD"; "GAS_STORAGE_CLEAR_REFUND"; "GAS_STORAGE_SET"; "GAS_STORAGE_UPDATE"; "GAS_WARM_ACCESS"; "charge_gas" ]. +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_CALL_STIPEND : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_CALL_STIPEND". +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_COLD_SLOAD : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_COLD_SLOAD". +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_STORAGE_CLEAR_REFUND : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_STORAGE_CLEAR_REFUND". +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_STORAGE_SET : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_STORAGE_SET". +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_STORAGE_UPDATE : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_STORAGE_UPDATE". +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_WARM_ACCESS : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_WARM_ACCESS". +Axiom ethereum_gray_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.gray_glacier.vm.gas" "charge_gas". -Axiom ethereum_gray_glacier_vm_stack_imports : - AreImported globals "ethereum.gray_glacier.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_gray_glacier_vm_stack_imports_pop : + IsImported globals "ethereum.gray_glacier.vm.stack" "pop". +Axiom ethereum_gray_glacier_vm_stack_imports_push : + IsImported globals "ethereum.gray_glacier.vm.stack" "push". Definition sload : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -51,7 +71,8 @@ Definition sload : Value.t -> Value.t -> M := The current EVM frame. " in - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -62,7 +83,8 @@ Definition sload : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -100,7 +122,8 @@ Definition sload : Value.t -> Value.t -> M := |) in M.pure Constant.None_ )) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "get_storage" |), make_list [ @@ -109,7 +132,8 @@ Definition sload : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -137,7 +161,8 @@ Definition sstore : Value.t -> Value.t -> M := The current EVM frame. " in - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -148,15 +173,18 @@ Definition sstore : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in - let new_value := + |) + |) in + let _ := M.assign_local (| + "new_value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -168,7 +196,8 @@ Definition sstore : Value.t -> Value.t -> M := ], make_dict [] |) in - let original_value := + let _ := M.assign_local (| + "original_value" , M.call (| M.get_name (| globals, "get_storage_original" |), make_list [ @@ -177,8 +206,10 @@ Definition sstore : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in - let current_value := + |) + |) in + let _ := M.assign_local (| + "current_value" , M.call (| M.get_name (| globals, "get_storage" |), make_list [ @@ -187,15 +218,18 @@ Definition sstore : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in - let gas_cost := + |) + |) in + let _ := M.assign_local (| + "gas_cost" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -212,9 +246,11 @@ Definition sstore : Value.t -> Value.t -> M := ], make_dict [] |) in - let gas_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "gas_cost", M.get_name (| globals, "GAS_COLD_SLOAD" |) - M.get_name (| globals, "GAS_COLD_SLOAD" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -246,29 +282,32 @@ Definition sstore : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let gas_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "gas_cost", M.get_name (| globals, "GAS_STORAGE_SET" |) - M.get_name (| globals, "GAS_STORAGE_SET" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let gas_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "gas_cost", BinOp.sub (| M.get_name (| globals, "GAS_STORAGE_UPDATE" |), M.get_name (| globals, "GAS_COLD_SLOAD" |) |) - BinOp.sub (| - M.get_name (| globals, "GAS_STORAGE_UPDATE" |), - M.get_name (| globals, "GAS_COLD_SLOAD" |) - |) in + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let gas_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "gas_cost", M.get_name (| globals, "GAS_WARM_ACCESS" |) - M.get_name (| globals, "GAS_WARM_ACCESS" |) in + |) in M.pure Constant.None_ )) |) in let _ := diff --git a/CoqOfPython/ethereum/gray_glacier/vm/instructions/system.v b/CoqOfPython/ethereum/gray_glacier/vm/instructions/system.v index c4320ce..0bd77ce 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/instructions/system.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/instructions/system.v @@ -17,38 +17,92 @@ Introduction Implementations of the EVM system related instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_gray_glacier_fork_types_imports : - AreImported globals "ethereum.gray_glacier.fork_types" [ "Address" ]. +Axiom ethereum_gray_glacier_fork_types_imports_Address : + IsImported globals "ethereum.gray_glacier.fork_types" "Address". -Axiom ethereum_gray_glacier_state_imports : - AreImported globals "ethereum.gray_glacier.state" [ "account_exists_and_is_empty"; "account_has_code_or_nonce"; "get_account"; "increment_nonce"; "is_account_alive"; "set_account_balance" ]. +Axiom ethereum_gray_glacier_state_imports_account_exists_and_is_empty : + IsImported globals "ethereum.gray_glacier.state" "account_exists_and_is_empty". +Axiom ethereum_gray_glacier_state_imports_account_has_code_or_nonce : + IsImported globals "ethereum.gray_glacier.state" "account_has_code_or_nonce". +Axiom ethereum_gray_glacier_state_imports_get_account : + IsImported globals "ethereum.gray_glacier.state" "get_account". +Axiom ethereum_gray_glacier_state_imports_increment_nonce : + IsImported globals "ethereum.gray_glacier.state" "increment_nonce". +Axiom ethereum_gray_glacier_state_imports_is_account_alive : + IsImported globals "ethereum.gray_glacier.state" "is_account_alive". +Axiom ethereum_gray_glacier_state_imports_set_account_balance : + IsImported globals "ethereum.gray_glacier.state" "set_account_balance". -Axiom ethereum_gray_glacier_utils_address_imports : - AreImported globals "ethereum.gray_glacier.utils.address" [ "compute_contract_address"; "compute_create2_contract_address"; "to_address" ]. +Axiom ethereum_gray_glacier_utils_address_imports_compute_contract_address : + IsImported globals "ethereum.gray_glacier.utils.address" "compute_contract_address". +Axiom ethereum_gray_glacier_utils_address_imports_compute_create2_contract_address : + IsImported globals "ethereum.gray_glacier.utils.address" "compute_create2_contract_address". +Axiom ethereum_gray_glacier_utils_address_imports_to_address : + IsImported globals "ethereum.gray_glacier.utils.address" "to_address". -Axiom ethereum_gray_glacier_vm_imports : - AreImported globals "ethereum.gray_glacier.vm" [ "Evm"; "Message"; "incorporate_child_on_error"; "incorporate_child_on_success" ]. +Axiom ethereum_gray_glacier_vm_imports_Evm : + IsImported globals "ethereum.gray_glacier.vm" "Evm". +Axiom ethereum_gray_glacier_vm_imports_Message : + IsImported globals "ethereum.gray_glacier.vm" "Message". +Axiom ethereum_gray_glacier_vm_imports_incorporate_child_on_error : + IsImported globals "ethereum.gray_glacier.vm" "incorporate_child_on_error". +Axiom ethereum_gray_glacier_vm_imports_incorporate_child_on_success : + IsImported globals "ethereum.gray_glacier.vm" "incorporate_child_on_success". -Axiom ethereum_gray_glacier_vm_exceptions_imports : - AreImported globals "ethereum.gray_glacier.vm.exceptions" [ "Revert"; "WriteInStaticContext" ]. +Axiom ethereum_gray_glacier_vm_exceptions_imports_Revert : + IsImported globals "ethereum.gray_glacier.vm.exceptions" "Revert". +Axiom ethereum_gray_glacier_vm_exceptions_imports_WriteInStaticContext : + IsImported globals "ethereum.gray_glacier.vm.exceptions" "WriteInStaticContext". -Axiom ethereum_gray_glacier_vm_gas_imports : - AreImported globals "ethereum.gray_glacier.vm.gas" [ "GAS_CALL_VALUE"; "GAS_COLD_ACCOUNT_ACCESS"; "GAS_CREATE"; "GAS_KECCAK256_WORD"; "GAS_NEW_ACCOUNT"; "GAS_SELF_DESTRUCT"; "GAS_SELF_DESTRUCT_NEW_ACCOUNT"; "GAS_WARM_ACCESS"; "GAS_ZERO"; "calculate_gas_extend_memory"; "calculate_message_call_gas"; "charge_gas"; "max_message_call_gas" ]. +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_CALL_VALUE : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_CALL_VALUE". +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_COLD_ACCOUNT_ACCESS : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_COLD_ACCOUNT_ACCESS". +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_CREATE : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_CREATE". +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_KECCAK256_WORD : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_KECCAK256_WORD". +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_NEW_ACCOUNT : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_NEW_ACCOUNT". +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_SELF_DESTRUCT : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_SELF_DESTRUCT". +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_SELF_DESTRUCT_NEW_ACCOUNT : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_SELF_DESTRUCT_NEW_ACCOUNT". +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_WARM_ACCESS : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_WARM_ACCESS". +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_ZERO : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_ZERO". +Axiom ethereum_gray_glacier_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.gray_glacier.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_gray_glacier_vm_gas_imports_calculate_message_call_gas : + IsImported globals "ethereum.gray_glacier.vm.gas" "calculate_message_call_gas". +Axiom ethereum_gray_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.gray_glacier.vm.gas" "charge_gas". +Axiom ethereum_gray_glacier_vm_gas_imports_max_message_call_gas : + IsImported globals "ethereum.gray_glacier.vm.gas" "max_message_call_gas". -Axiom ethereum_gray_glacier_vm_memory_imports : - AreImported globals "ethereum.gray_glacier.vm.memory" [ "memory_read_bytes"; "memory_write" ]. +Axiom ethereum_gray_glacier_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.gray_glacier.vm.memory" "memory_read_bytes". +Axiom ethereum_gray_glacier_vm_memory_imports_memory_write : + IsImported globals "ethereum.gray_glacier.vm.memory" "memory_write". -Axiom ethereum_gray_glacier_vm_stack_imports : - AreImported globals "ethereum.gray_glacier.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_gray_glacier_vm_stack_imports_pop : + IsImported globals "ethereum.gray_glacier.vm.stack" "pop". +Axiom ethereum_gray_glacier_vm_stack_imports_push : + IsImported globals "ethereum.gray_glacier.vm.stack" "push". Definition generic_create : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -64,7 +118,8 @@ Definition generic_create : Value.t -> Value.t -> M := ], make_dict [] |) in - let create_message_gas := + let _ := M.assign_local (| + "create_message_gas" , M.call (| M.get_name (| globals, "max_message_call_gas" |), make_list [ @@ -77,7 +132,8 @@ Definition generic_create : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.assign_op (| BinOp.sub, M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), @@ -95,9 +151,12 @@ Definition generic_create : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), Constant.bytes "" |) in - let sender_address := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in - let sender := + let _ := M.assign_local (| + "sender_address" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + |) in + let _ := M.assign_local (| + "sender" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -105,7 +164,8 @@ Definition generic_create : Value.t -> Value.t -> M := M.get_name (| globals, "sender_address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -216,7 +276,8 @@ Definition generic_create : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let call_data := + let _ := M.assign_local (| + "call_data" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -225,7 +286,8 @@ Definition generic_create : Value.t -> Value.t -> M := M.get_name (| globals, "memory_size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "increment_nonce" |), make_list [ @@ -234,13 +296,16 @@ Definition generic_create : Value.t -> Value.t -> M := ], make_dict [] |) in - let child_message := + let _ := M.assign_local (| + "child_message" , M.call (| M.get_name (| globals, "Message" |), make_list [], make_dict [] - |) in - let child_evm := + |) + |) in + let _ := M.assign_local (| + "child_evm" , M.call (| M.get_name (| globals, "process_create_message" |), make_list [ @@ -248,7 +313,8 @@ Definition generic_create : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -325,31 +391,38 @@ Definition create : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let endowment := + let _ := M.assign_local (| + "endowment" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_size := + |) + |) in + let _ := M.assign_local (| + "memory_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -359,7 +432,8 @@ Definition create : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -379,7 +453,8 @@ Definition create : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let contract_address := + let _ := M.assign_local (| + "contract_address" , M.call (| M.get_name (| globals, "compute_contract_address" |), make_list [ @@ -394,7 +469,8 @@ Definition create : Value.t -> Value.t -> M := |), "nonce" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "generic_create" |), make_list [ @@ -427,31 +503,38 @@ Definition create2 : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let endowment := + let _ := M.assign_local (| + "endowment" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_size := + |) + |) in + let _ := M.assign_local (| + "memory_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let salt := + |) + |) in + let _ := M.assign_local (| + "salt" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -462,8 +545,10 @@ Definition create2 : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -473,8 +558,10 @@ Definition create2 : Value.t -> Value.t -> M := ] ], make_dict [] - |) in - let call_data_words := + |) + |) in + let _ := M.assign_local (| + "call_data_words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -490,7 +577,8 @@ Definition create2 : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -516,7 +604,8 @@ Definition create2 : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let contract_address := + let _ := M.assign_local (| + "contract_address" , M.call (| M.get_name (| globals, "compute_create2_contract_address" |), make_list [ @@ -533,7 +622,8 @@ Definition create2 : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "generic_create" |), make_list [ @@ -563,23 +653,28 @@ Definition return_ : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let memory_start_position := + let _ := M.assign_local (| + "memory_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_size := + |) + |) in + let _ := M.assign_local (| + "memory_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -589,7 +684,8 @@ Definition return_ : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -678,7 +774,8 @@ Definition generic_call : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let call_data := + let _ := M.assign_local (| + "call_data" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -687,8 +784,10 @@ Definition generic_call : Value.t -> Value.t -> M := M.get_name (| globals, "memory_input_size" |) ], make_dict [] - |) in - let code := + |) + |) in + let _ := M.assign_local (| + "code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -696,14 +795,18 @@ Definition generic_call : Value.t -> Value.t -> M := M.get_name (| globals, "code_address" |) ], make_dict [] - |), "code" |) in - let child_message := + |), "code" |) + |) in + let _ := M.assign_local (| + "child_message" , M.call (| M.get_name (| globals, "Message" |), make_list [], make_dict [] - |) in - let child_evm := + |) + |) in + let _ := M.assign_local (| + "child_evm" , M.call (| M.get_name (| globals, "process_message" |), make_list [ @@ -711,7 +814,8 @@ Definition generic_call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -775,7 +879,8 @@ Definition generic_call : Value.t -> Value.t -> M := |) in M.pure Constant.None_ )) |) in - let actual_output_size := + let _ := M.assign_local (| + "actual_output_size" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -795,7 +900,8 @@ Definition generic_call : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -823,7 +929,8 @@ Definition call : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -836,8 +943,10 @@ Definition call : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let to := + |) + |) in + let _ := M.assign_local (| + "to" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -850,48 +959,60 @@ Definition call : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -902,7 +1023,8 @@ Definition call : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -912,8 +1034,10 @@ Definition call : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let access_gas_cost := - M.get_name (| globals, "GAS_WARM_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -924,11 +1048,14 @@ Definition call : Value.t -> Value.t -> M := ], make_dict [] |) in - let access_gas_cost := - M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + |) in M.pure Constant.None_ )) |) in - let create_gas_cost := + let _ := M.assign_local (| + "create_gas_cost" , (* if *) M.if_then_else (| BoolOp.or (| @@ -959,8 +1086,10 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "GAS_NEW_ACCOUNT" |) - )) |) in - let transfer_gas_cost := + )) |) + |) in + let _ := M.assign_local (| + "transfer_gas_cost" , (* if *) M.if_then_else (| Compare.eq (| @@ -979,8 +1108,10 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "GAS_CALL_VALUE" |) - )) |) in - let message_call_gas := + )) |) + |) in + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -1003,7 +1134,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1045,7 +1177,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let sender_balance := + let _ := M.assign_local (| + "sender_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1053,7 +1186,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := (* if *) M.if_then_else (| @@ -1127,7 +1261,8 @@ Definition callcode : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -1140,8 +1275,10 @@ Definition callcode : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let code_address := + |) + |) in + let _ := M.assign_local (| + "code_address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1154,50 +1291,64 @@ Definition callcode : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let to := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "to" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1208,7 +1359,8 @@ Definition callcode : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1218,8 +1370,10 @@ Definition callcode : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let access_gas_cost := - M.get_name (| globals, "GAS_WARM_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1230,11 +1384,14 @@ Definition callcode : Value.t -> Value.t -> M := ], make_dict [] |) in - let access_gas_cost := - M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + |) in M.pure Constant.None_ )) |) in - let transfer_gas_cost := + let _ := M.assign_local (| + "transfer_gas_cost" , (* if *) M.if_then_else (| Compare.eq (| @@ -1253,8 +1410,10 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "GAS_CALL_VALUE" |) - )) |) in - let message_call_gas := + )) |) + |) in + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -1274,7 +1433,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1294,7 +1454,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let sender_balance := + let _ := M.assign_local (| + "sender_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1302,7 +1463,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := (* if *) M.if_then_else (| @@ -1376,7 +1538,8 @@ Definition selfdestruct : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let beneficiary := + let _ := M.assign_local (| + "beneficiary" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1389,9 +1552,12 @@ Definition selfdestruct : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let gas_cost := - M.get_name (| globals, "GAS_SELF_DESTRUCT" |) in + |) + |) in + let _ := M.assign_local (| + "gas_cost" , + M.get_name (| globals, "GAS_SELF_DESTRUCT" |) + |) in let _ := (* if *) M.if_then_else (| @@ -1408,9 +1574,11 @@ Definition selfdestruct : Value.t -> Value.t -> M := ], make_dict [] |) in - let gas_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "gas_cost", M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) - M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1444,9 +1612,11 @@ Definition selfdestruct : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let gas_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "gas_cost", M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) - M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1468,9 +1638,12 @@ Definition selfdestruct : Value.t -> Value.t -> M := ], make_dict [] |) in - let originator := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in - let beneficiary_balance := + let _ := M.assign_local (| + "originator" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + |) in + let _ := M.assign_local (| + "beneficiary_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1478,8 +1651,10 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_name (| globals, "beneficiary" |) ], make_dict [] - |), "balance" |) in - let originator_balance := + |), "balance" |) + |) in + let _ := M.assign_local (| + "originator_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1487,7 +1662,8 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_name (| globals, "originator" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -1565,7 +1741,8 @@ Definition delegatecall : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -1578,8 +1755,10 @@ Definition delegatecall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let code_address := + |) + |) in + let _ := M.assign_local (| + "code_address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1592,40 +1771,50 @@ Definition delegatecall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1636,7 +1825,8 @@ Definition delegatecall : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1646,8 +1836,10 @@ Definition delegatecall : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let access_gas_cost := - M.get_name (| globals, "GAS_WARM_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1658,11 +1850,14 @@ Definition delegatecall : Value.t -> Value.t -> M := ], make_dict [] |) in - let access_gas_cost := - M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + |) in M.pure Constant.None_ )) |) in - let message_call_gas := + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -1685,7 +1880,8 @@ Definition delegatecall : Value.t -> Value.t -> M := M.get_name (| globals, "access_gas_cost" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1741,7 +1937,8 @@ Definition staticcall : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -1754,8 +1951,10 @@ Definition staticcall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let to := + |) + |) in + let _ := M.assign_local (| + "to" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1768,40 +1967,50 @@ Definition staticcall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1812,7 +2021,8 @@ Definition staticcall : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1822,8 +2032,10 @@ Definition staticcall : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let access_gas_cost := - M.get_name (| globals, "GAS_WARM_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1834,11 +2046,14 @@ Definition staticcall : Value.t -> Value.t -> M := ], make_dict [] |) in - let access_gas_cost := - M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + |) in M.pure Constant.None_ )) |) in - let message_call_gas := + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -1861,7 +2076,8 @@ Definition staticcall : Value.t -> Value.t -> M := M.get_name (| globals, "access_gas_cost" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1923,23 +2139,28 @@ Definition revert : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1949,7 +2170,8 @@ Definition revert : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1966,7 +2188,8 @@ Definition revert : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let output := + let _ := M.assign_local (| + "output" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -1975,7 +2198,8 @@ Definition revert : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| diff --git a/CoqOfPython/ethereum/gray_glacier/vm/interpreter.v b/CoqOfPython/ethereum/gray_glacier/vm/interpreter.v index 9d7e97e..af521c5 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/interpreter.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/interpreter.v @@ -17,50 +17,112 @@ Introduction A straightforward interpreter that executes EVM code. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Iterable"; "Optional"; "Set"; "Tuple" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. - -Axiom ethereum_trace_imports : - AreImported globals "ethereum.trace" [ "EvmStop"; "OpEnd"; "OpException"; "OpStart"; "PrecompileEnd"; "PrecompileStart"; "TransactionEnd"; "evm_trace" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_gray_glacier_blocks_imports : - AreImported globals "ethereum.gray_glacier.blocks" [ "Log" ]. - -Axiom ethereum_gray_glacier_fork_types_imports : - AreImported globals "ethereum.gray_glacier.fork_types" [ "Address" ]. - -Axiom ethereum_gray_glacier_state_imports : - AreImported globals "ethereum.gray_glacier.state" [ "account_exists_and_is_empty"; "account_has_code_or_nonce"; "begin_transaction"; "commit_transaction"; "destroy_storage"; "increment_nonce"; "mark_account_created"; "move_ether"; "rollback_transaction"; "set_code"; "touch_account" ]. - -Axiom ethereum_gray_glacier_vm_imports : - AreImported globals "ethereum.gray_glacier.vm" [ "Message" ]. - -Axiom ethereum_gray_glacier_vm_gas_imports : - AreImported globals "ethereum.gray_glacier.vm.gas" [ "GAS_CODE_DEPOSIT"; "charge_gas" ]. - -Axiom ethereum_gray_glacier_vm_precompiled_contracts_mapping_imports : - AreImported globals "ethereum.gray_glacier.vm.precompiled_contracts.mapping" [ "PRE_COMPILED_CONTRACTS" ]. - -Axiom ethereum_gray_glacier_vm_imports : - AreImported globals "ethereum.gray_glacier.vm" [ "Environment"; "Evm" ]. - -Axiom ethereum_gray_glacier_vm_exceptions_imports : - AreImported globals "ethereum.gray_glacier.vm.exceptions" [ "AddressCollision"; "ExceptionalHalt"; "InvalidContractPrefix"; "InvalidOpcode"; "OutOfGasError"; "Revert"; "StackDepthLimitError" ]. - -Axiom ethereum_gray_glacier_vm_instructions_imports : - AreImported globals "ethereum.gray_glacier.vm.instructions" [ "Ops"; "op_implementation" ]. - -Axiom ethereum_gray_glacier_vm_runtime_imports : - AreImported globals "ethereum.gray_glacier.vm.runtime" [ "get_valid_jump_destinations" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_Iterable : + IsImported globals "typing" "Iterable". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_trace_imports_EvmStop : + IsImported globals "ethereum.trace" "EvmStop". +Axiom ethereum_trace_imports_OpEnd : + IsImported globals "ethereum.trace" "OpEnd". +Axiom ethereum_trace_imports_OpException : + IsImported globals "ethereum.trace" "OpException". +Axiom ethereum_trace_imports_OpStart : + IsImported globals "ethereum.trace" "OpStart". +Axiom ethereum_trace_imports_PrecompileEnd : + IsImported globals "ethereum.trace" "PrecompileEnd". +Axiom ethereum_trace_imports_PrecompileStart : + IsImported globals "ethereum.trace" "PrecompileStart". +Axiom ethereum_trace_imports_TransactionEnd : + IsImported globals "ethereum.trace" "TransactionEnd". +Axiom ethereum_trace_imports_evm_trace : + IsImported globals "ethereum.trace" "evm_trace". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_gray_glacier_blocks_imports_Log : + IsImported globals "ethereum.gray_glacier.blocks" "Log". + +Axiom ethereum_gray_glacier_fork_types_imports_Address : + IsImported globals "ethereum.gray_glacier.fork_types" "Address". + +Axiom ethereum_gray_glacier_state_imports_account_exists_and_is_empty : + IsImported globals "ethereum.gray_glacier.state" "account_exists_and_is_empty". +Axiom ethereum_gray_glacier_state_imports_account_has_code_or_nonce : + IsImported globals "ethereum.gray_glacier.state" "account_has_code_or_nonce". +Axiom ethereum_gray_glacier_state_imports_begin_transaction : + IsImported globals "ethereum.gray_glacier.state" "begin_transaction". +Axiom ethereum_gray_glacier_state_imports_commit_transaction : + IsImported globals "ethereum.gray_glacier.state" "commit_transaction". +Axiom ethereum_gray_glacier_state_imports_destroy_storage : + IsImported globals "ethereum.gray_glacier.state" "destroy_storage". +Axiom ethereum_gray_glacier_state_imports_increment_nonce : + IsImported globals "ethereum.gray_glacier.state" "increment_nonce". +Axiom ethereum_gray_glacier_state_imports_mark_account_created : + IsImported globals "ethereum.gray_glacier.state" "mark_account_created". +Axiom ethereum_gray_glacier_state_imports_move_ether : + IsImported globals "ethereum.gray_glacier.state" "move_ether". +Axiom ethereum_gray_glacier_state_imports_rollback_transaction : + IsImported globals "ethereum.gray_glacier.state" "rollback_transaction". +Axiom ethereum_gray_glacier_state_imports_set_code : + IsImported globals "ethereum.gray_glacier.state" "set_code". +Axiom ethereum_gray_glacier_state_imports_touch_account : + IsImported globals "ethereum.gray_glacier.state" "touch_account". + +Axiom ethereum_gray_glacier_vm_imports_Message : + IsImported globals "ethereum.gray_glacier.vm" "Message". + +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_CODE_DEPOSIT : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_CODE_DEPOSIT". +Axiom ethereum_gray_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.gray_glacier.vm.gas" "charge_gas". + +Axiom ethereum_gray_glacier_vm_precompiled_contracts_mapping_imports_PRE_COMPILED_CONTRACTS : + IsImported globals "ethereum.gray_glacier.vm.precompiled_contracts.mapping" "PRE_COMPILED_CONTRACTS". + +Axiom ethereum_gray_glacier_vm_imports_Environment : + IsImported globals "ethereum.gray_glacier.vm" "Environment". +Axiom ethereum_gray_glacier_vm_imports_Evm : + IsImported globals "ethereum.gray_glacier.vm" "Evm". + +Axiom ethereum_gray_glacier_vm_exceptions_imports_AddressCollision : + IsImported globals "ethereum.gray_glacier.vm.exceptions" "AddressCollision". +Axiom ethereum_gray_glacier_vm_exceptions_imports_ExceptionalHalt : + IsImported globals "ethereum.gray_glacier.vm.exceptions" "ExceptionalHalt". +Axiom ethereum_gray_glacier_vm_exceptions_imports_InvalidContractPrefix : + IsImported globals "ethereum.gray_glacier.vm.exceptions" "InvalidContractPrefix". +Axiom ethereum_gray_glacier_vm_exceptions_imports_InvalidOpcode : + IsImported globals "ethereum.gray_glacier.vm.exceptions" "InvalidOpcode". +Axiom ethereum_gray_glacier_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.gray_glacier.vm.exceptions" "OutOfGasError". +Axiom ethereum_gray_glacier_vm_exceptions_imports_Revert : + IsImported globals "ethereum.gray_glacier.vm.exceptions" "Revert". +Axiom ethereum_gray_glacier_vm_exceptions_imports_StackDepthLimitError : + IsImported globals "ethereum.gray_glacier.vm.exceptions" "StackDepthLimitError". + +Axiom ethereum_gray_glacier_vm_instructions_imports_Ops : + IsImported globals "ethereum.gray_glacier.vm.instructions" "Ops". +Axiom ethereum_gray_glacier_vm_instructions_imports_op_implementation : + IsImported globals "ethereum.gray_glacier.vm.instructions" "op_implementation". + +Axiom ethereum_gray_glacier_vm_runtime_imports_get_valid_jump_destinations : + IsImported globals "ethereum.gray_glacier.vm.runtime" "get_valid_jump_destinations". Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -121,7 +183,8 @@ Definition process_message_call : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let is_collision := + let _ := M.assign_local (| + "is_collision" , M.call (| M.get_name (| globals, "account_has_code_or_nonce" |), make_list [ @@ -129,7 +192,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "message" |), "current_target" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -181,7 +245,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "process_create_message" |), make_list [ @@ -189,13 +254,15 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "process_message" |), make_list [ @@ -203,7 +270,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -250,46 +318,61 @@ Definition process_message_call : Value.t -> Value.t -> M := (* then *) ltac:(M.monadic ( (* At stmt: unsupported node type: AnnAssign *) - let accounts_to_delete := + let _ := M.assign_local (| + "accounts_to_delete" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let touched_accounts := + |) + |) in + let _ := M.assign_local (| + "touched_accounts" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let refund_counter := + |) + |) in + let _ := M.assign_local (| + "refund_counter" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let logs := - M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in - let accounts_to_delete := - M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in - let touched_accounts := - M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |) in - let refund_counter := + let _ := M.assign_local (| + "logs" , + M.get_field (| M.get_name (| globals, "evm" |), "logs" |) + |) in + let _ := M.assign_local (| + "accounts_to_delete" , + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) + |) in + let _ := M.assign_local (| + "touched_accounts" , + M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |) + |) in + let _ := M.assign_local (| + "refund_counter" , M.call (| M.get_name (| globals, "U256" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in - let tx_end := + let _ := M.assign_local (| + "tx_end" , M.call (| M.get_name (| globals, "TransactionEnd" |), make_list [ @@ -301,7 +384,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "error" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "evm_trace" |), make_list [ @@ -368,7 +452,8 @@ Definition process_create_message : Value.t -> Value.t -> M := ], make_dict [] |) in - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "process_message" |), make_list [ @@ -376,16 +461,20 @@ Definition process_create_message : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), (* then *) ltac:(M.monadic ( - let contract_code := - M.get_field (| M.get_name (| globals, "evm" |), "output" |) in - let contract_code_gas := + let _ := M.assign_local (| + "contract_code" , + M.get_field (| M.get_name (| globals, "evm" |), "output" |) + |) in + let _ := M.assign_local (| + "contract_code_gas" , BinOp.mult (| M.call (| M.get_name (| globals, "len" |), @@ -395,7 +484,8 @@ Definition process_create_message : Value.t -> Value.t -> M := make_dict [] |), M.get_name (| globals, "GAS_CODE_DEPOSIT" |) - |) in + |) + |) in (* At stmt: unsupported node type: Try *) M.pure Constant.None_ (* else *) @@ -497,7 +587,8 @@ Definition process_message : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "execute_code" |), make_list [ @@ -505,7 +596,8 @@ Definition process_message : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -554,22 +646,28 @@ Definition execute_code : Value.t -> Value.t -> M := evm: `ethereum.vm.EVM` Items containing execution specific objects " in - let code := - M.get_field (| M.get_name (| globals, "message" |), "code" |) in - let valid_jump_destinations := + let _ := M.assign_local (| + "code" , + M.get_field (| M.get_name (| globals, "message" |), "code" |) + |) in + let _ := M.assign_local (| + "valid_jump_destinations" , M.call (| M.get_name (| globals, "get_valid_jump_destinations" |), make_list [ M.get_name (| globals, "code" |) ], make_dict [] - |) in - let evm := + |) + |) in + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "Evm" |), make_list [], make_dict [] - |) in + |) + |) in (* At stmt: unsupported node type: Try *) let _ := M.return_ (| M.get_name (| globals, "evm" |) diff --git a/CoqOfPython/ethereum/gray_glacier/vm/memory.v b/CoqOfPython/ethereum/gray_glacier/vm/memory.v index 3f05578..3aa8c8a 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/memory.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/memory.v @@ -17,11 +17,15 @@ Introduction EVM memory operations. ". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "right_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_right_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "right_pad_zero_bytes". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". Definition memory_write : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/__init__.v index c0cc5cf..fd5c1ed 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/__init__.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/__init__.v @@ -18,8 +18,8 @@ Addresses of precompiled contracts and mappings to their implementations. ". -Axiom ethereum_gray_glacier_utils_hexadecimal_imports : - AreImported globals "ethereum.gray_glacier.utils.hexadecimal" [ "hex_to_address" ]. +Axiom ethereum_gray_glacier_utils_hexadecimal_imports_hex_to_address : + IsImported globals "ethereum.gray_glacier.utils.hexadecimal" "hex_to_address". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS"; Constant.str "MODEXP_ADDRESS"; Constant.str "ALT_BN128_ADD_ADDRESS"; Constant.str "ALT_BN128_MUL_ADDRESS"; Constant.str "ALT_BN128_PAIRING_CHECK_ADDRESS"; Constant.str "BLAKE2F_ADDRESS" ] diff --git a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/alt_bn128.v index 70533ad..35d4975 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/alt_bn128.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/alt_bn128.v @@ -17,26 +17,42 @@ Introduction Implementation of the ALT_BN128 precompiled contracts. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_alt_bn128_imports : - AreImported globals "ethereum.crypto.alt_bn128" [ "ALT_BN128_CURVE_ORDER"; "ALT_BN128_PRIME"; "BNF"; "BNF2"; "BNF12"; "BNP"; "BNP2"; "pairing" ]. +Axiom ethereum_crypto_alt_bn128_imports_ALT_BN128_CURVE_ORDER : + IsImported globals "ethereum.crypto.alt_bn128" "ALT_BN128_CURVE_ORDER". +Axiom ethereum_crypto_alt_bn128_imports_ALT_BN128_PRIME : + IsImported globals "ethereum.crypto.alt_bn128" "ALT_BN128_PRIME". +Axiom ethereum_crypto_alt_bn128_imports_BNF : + IsImported globals "ethereum.crypto.alt_bn128" "BNF". +Axiom ethereum_crypto_alt_bn128_imports_BNF2 : + IsImported globals "ethereum.crypto.alt_bn128" "BNF2". +Axiom ethereum_crypto_alt_bn128_imports_BNF12 : + IsImported globals "ethereum.crypto.alt_bn128" "BNF12". +Axiom ethereum_crypto_alt_bn128_imports_BNP : + IsImported globals "ethereum.crypto.alt_bn128" "BNP". +Axiom ethereum_crypto_alt_bn128_imports_BNP2 : + IsImported globals "ethereum.crypto.alt_bn128" "BNP2". +Axiom ethereum_crypto_alt_bn128_imports_pairing : + IsImported globals "ethereum.crypto.alt_bn128" "pairing". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_gray_glacier_vm_imports : - AreImported globals "ethereum.gray_glacier.vm" [ "Evm" ]. +Axiom ethereum_gray_glacier_vm_imports_Evm : + IsImported globals "ethereum.gray_glacier.vm" "Evm". -Axiom ethereum_gray_glacier_vm_gas_imports : - AreImported globals "ethereum.gray_glacier.vm.gas" [ "charge_gas" ]. +Axiom ethereum_gray_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.gray_glacier.vm.gas" "charge_gas". -Axiom ethereum_gray_glacier_vm_memory_imports : - AreImported globals "ethereum.gray_glacier.vm.memory" [ "buffer_read" ]. +Axiom ethereum_gray_glacier_vm_memory_imports_buffer_read : + IsImported globals "ethereum.gray_glacier.vm.memory" "buffer_read". -Axiom ethereum_gray_glacier_vm_exceptions_imports : - AreImported globals "ethereum.gray_glacier.vm.exceptions" [ "OutOfGasError" ]. +Axiom ethereum_gray_glacier_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.gray_glacier.vm.exceptions" "OutOfGasError". Definition alt_bn128_add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -49,8 +65,10 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -65,7 +83,8 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := ], make_dict [] |) in - let x0_bytes := + let _ := M.assign_local (| + "x0_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -86,16 +105,20 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let x0_value := + |) + |) in + let _ := M.assign_local (| + "x0_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "x0_bytes" |) ], make_dict [] - |) in - let y0_bytes := + |) + |) in + let _ := M.assign_local (| + "y0_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -116,16 +139,20 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y0_value := + |) + |) in + let _ := M.assign_local (| + "y0_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "y0_bytes" |) ], make_dict [] - |) in - let x1_bytes := + |) + |) in + let _ := M.assign_local (| + "x1_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -146,16 +173,20 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let x1_value := + |) + |) in + let _ := M.assign_local (| + "x1_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "x1_bytes" |) ], make_dict [] - |) in - let y1_bytes := + |) + |) in + let _ := M.assign_local (| + "y1_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -176,15 +207,18 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y1_value := + |) + |) in + let _ := M.assign_local (| + "y1_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "y1_bytes" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "i" |), @@ -212,11 +246,13 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := )) |) in (* At stmt: unsupported node type: Try *) - let p := + let _ := M.assign_local (| + "p" , BinOp.add (| M.get_name (| globals, "p0" |), M.get_name (| globals, "p1" |) - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), BinOp.add (| @@ -245,8 +281,10 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -261,7 +299,8 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := ], make_dict [] |) in - let x0_bytes := + let _ := M.assign_local (| + "x0_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -282,16 +321,20 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let x0_value := + |) + |) in + let _ := M.assign_local (| + "x0_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "x0_bytes" |) ], make_dict [] - |) in - let y0_bytes := + |) + |) in + let _ := M.assign_local (| + "y0_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -312,16 +355,20 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y0_value := + |) + |) in + let _ := M.assign_local (| + "y0_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "y0_bytes" |) ], make_dict [] - |) in - let n := + |) + |) in + let _ := M.assign_local (| + "n" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -348,7 +395,8 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "i" |), @@ -376,14 +424,16 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := )) |) in (* At stmt: unsupported node type: Try *) - let p := + let _ := M.assign_local (| + "p" , M.call (| M.get_field (| M.get_name (| globals, "p0" |), "mul_by" |), make_list [ M.get_name (| globals, "n" |) ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), BinOp.add (| @@ -412,8 +462,10 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -467,14 +519,16 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), make_list [ Constant.int 1 ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "i" |), @@ -495,8 +549,10 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let values := - make_list [] in + let _ := M.assign_local (| + "values" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "j" |), @@ -508,7 +564,8 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -541,7 +598,8 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -644,7 +702,8 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , BinOp.mult (| M.get_name (| globals, "result" |), M.call (| @@ -655,7 +714,8 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/blake2f.v b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/blake2f.v index 4f52681..febbff6 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/blake2f.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/blake2f.v @@ -17,20 +17,22 @@ Introduction Implementation of the `Blake2` precompiled contract. ". -Axiom ethereum_crypto_blake2_imports : - AreImported globals "ethereum.crypto.blake2" [ "Blake2b" ]. +Axiom ethereum_crypto_blake2_imports_Blake2b : + IsImported globals "ethereum.crypto.blake2" "Blake2b". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_gray_glacier_vm_imports : - AreImported globals "ethereum.gray_glacier.vm" [ "Evm" ]. +Axiom ethereum_gray_glacier_vm_imports_Evm : + IsImported globals "ethereum.gray_glacier.vm" "Evm". -Axiom ethereum_gray_glacier_vm_gas_imports : - AreImported globals "ethereum.gray_glacier.vm.gas" [ "GAS_BLAKE2_PER_ROUND"; "charge_gas" ]. +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_BLAKE2_PER_ROUND : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_BLAKE2_PER_ROUND". +Axiom ethereum_gray_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.gray_glacier.vm.gas" "charge_gas". -Axiom ethereum_gray_glacier_vm_exceptions_imports : - AreImported globals "ethereum.gray_glacier.vm.exceptions" [ "InvalidParameter" ]. +Axiom ethereum_gray_glacier_vm_exceptions_imports_InvalidParameter : + IsImported globals "ethereum.gray_glacier.vm.exceptions" "InvalidParameter". Definition blake2f : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -43,8 +45,10 @@ Definition blake2f : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -62,12 +66,14 @@ Definition blake2f : Value.t -> Value.t -> M := ], make_dict [] |) in - let blake2b := + let _ := M.assign_local (| + "blake2b" , M.call (| M.get_name (| globals, "Blake2b" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "rounds" |); M.get_name (| globals, "h" |); M.get_name (| globals, "m" |); M.get_name (| globals, "t_0" |); M.get_name (| globals, "t_1" |); M.get_name (| globals, "f" |) ], M.call (| diff --git a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/ecrecover.v index 9538a33..2df1000 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/ecrecover.v @@ -17,26 +17,32 @@ Introduction Implementation of the ECRECOVER precompiled contract. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_crypto_elliptic_curve_imports : - AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. +Axiom ethereum_crypto_elliptic_curve_imports_SECP256K1N : + IsImported globals "ethereum.crypto.elliptic_curve" "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_imports_secp256k1_recover : + IsImported globals "ethereum.crypto.elliptic_curve" "secp256k1_recover". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_left_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "left_pad_zero_bytes". -Axiom ethereum_gray_glacier_vm_imports : - AreImported globals "ethereum.gray_glacier.vm" [ "Evm" ]. +Axiom ethereum_gray_glacier_vm_imports_Evm : + IsImported globals "ethereum.gray_glacier.vm" "Evm". -Axiom ethereum_gray_glacier_vm_gas_imports : - AreImported globals "ethereum.gray_glacier.vm.gas" [ "GAS_ECRECOVER"; "charge_gas" ]. +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_ECRECOVER : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_ECRECOVER". +Axiom ethereum_gray_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.gray_glacier.vm.gas" "charge_gas". -Axiom ethereum_gray_glacier_vm_memory_imports : - AreImported globals "ethereum.gray_glacier.vm.memory" [ "buffer_read" ]. +Axiom ethereum_gray_glacier_vm_memory_imports_buffer_read : + IsImported globals "ethereum.gray_glacier.vm.memory" "buffer_read". Definition ecrecover : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -50,8 +56,10 @@ Definition ecrecover : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -60,7 +68,8 @@ Definition ecrecover : Value.t -> Value.t -> M := ], make_dict [] |) in - let message_hash_bytes := + let _ := M.assign_local (| + "message_hash_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -81,16 +90,20 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let message_hash := + |) + |) in + let _ := M.assign_local (| + "message_hash" , M.call (| M.get_name (| globals, "Hash32" |), make_list [ M.get_name (| globals, "message_hash_bytes" |) ], make_dict [] - |) in - let v := + |) + |) in + let _ := M.assign_local (| + "v" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -117,8 +130,10 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let r := + |) + |) in + let _ := M.assign_local (| + "r" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -145,8 +160,10 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let s := + |) + |) in + let _ := M.assign_local (| + "s" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -173,7 +190,8 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -250,7 +268,8 @@ Definition ecrecover : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: Try *) - let address := + let _ := M.assign_local (| + "address" , M.slice (| M.call (| M.get_name (| globals, "keccak256" |), @@ -262,8 +281,10 @@ Definition ecrecover : Value.t -> Value.t -> M := Constant.int 12, Constant.int 32, Constant.None_ - |) in - let padded_address := + |) + |) in + let _ := M.assign_local (| + "padded_address" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -271,7 +292,8 @@ Definition ecrecover : Value.t -> Value.t -> M := Constant.int 32 ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.get_name (| globals, "padded_address" |) diff --git a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/identity.v index 8442cd7..e41c6b5 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/identity.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/identity.v @@ -17,17 +17,21 @@ Introduction Implementation of the `IDENTITY` precompiled contract. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_gray_glacier_vm_imports : - AreImported globals "ethereum.gray_glacier.vm" [ "Evm" ]. +Axiom ethereum_gray_glacier_vm_imports_Evm : + IsImported globals "ethereum.gray_glacier.vm" "Evm". -Axiom ethereum_gray_glacier_vm_gas_imports : - AreImported globals "ethereum.gray_glacier.vm.gas" [ "GAS_IDENTITY"; "GAS_IDENTITY_WORD"; "charge_gas" ]. +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_IDENTITY : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_IDENTITY". +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_IDENTITY_WORD : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_IDENTITY_WORD". +Axiom ethereum_gray_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.gray_glacier.vm.gas" "charge_gas". Definition identity : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -40,9 +44,12 @@ Definition identity : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let word_count := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "word_count" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -64,7 +71,8 @@ Definition identity : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ diff --git a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/mapping.v index 94e0d64..61078a7 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/mapping.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/mapping.v @@ -17,34 +17,56 @@ Introduction Mapping of precompiled contracts their implementations. ". -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict" ]. - -Axiom ethereum_gray_glacier_fork_types_imports : - AreImported globals "ethereum.gray_glacier.fork_types" [ "Address" ]. - -Axiom ethereum_gray_glacier_vm_precompiled_contracts_imports : - AreImported globals "ethereum.gray_glacier.vm.precompiled_contracts" [ "ALT_BN128_ADD_ADDRESS"; "ALT_BN128_MUL_ADDRESS"; "ALT_BN128_PAIRING_CHECK_ADDRESS"; "BLAKE2F_ADDRESS"; "ECRECOVER_ADDRESS"; "IDENTITY_ADDRESS"; "MODEXP_ADDRESS"; "RIPEMD160_ADDRESS"; "SHA256_ADDRESS" ]. - -Axiom ethereum_gray_glacier_vm_precompiled_contracts_alt_bn128_imports : - AreImported globals "ethereum.gray_glacier.vm.precompiled_contracts.alt_bn128" [ "alt_bn128_add"; "alt_bn128_mul"; "alt_bn128_pairing_check" ]. - -Axiom ethereum_gray_glacier_vm_precompiled_contracts_blake2f_imports : - AreImported globals "ethereum.gray_glacier.vm.precompiled_contracts.blake2f" [ "blake2f" ]. - -Axiom ethereum_gray_glacier_vm_precompiled_contracts_ecrecover_imports : - AreImported globals "ethereum.gray_glacier.vm.precompiled_contracts.ecrecover" [ "ecrecover" ]. - -Axiom ethereum_gray_glacier_vm_precompiled_contracts_identity_imports : - AreImported globals "ethereum.gray_glacier.vm.precompiled_contracts.identity" [ "identity" ]. - -Axiom ethereum_gray_glacier_vm_precompiled_contracts_modexp_imports : - AreImported globals "ethereum.gray_glacier.vm.precompiled_contracts.modexp" [ "modexp" ]. - -Axiom ethereum_gray_glacier_vm_precompiled_contracts_ripemd160_imports : - AreImported globals "ethereum.gray_glacier.vm.precompiled_contracts.ripemd160" [ "ripemd160" ]. - -Axiom ethereum_gray_glacier_vm_precompiled_contracts_sha256_imports : - AreImported globals "ethereum.gray_glacier.vm.precompiled_contracts.sha256" [ "sha256" ]. +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". + +Axiom ethereum_gray_glacier_fork_types_imports_Address : + IsImported globals "ethereum.gray_glacier.fork_types" "Address". + +Axiom ethereum_gray_glacier_vm_precompiled_contracts_imports_ALT_BN128_ADD_ADDRESS : + IsImported globals "ethereum.gray_glacier.vm.precompiled_contracts" "ALT_BN128_ADD_ADDRESS". +Axiom ethereum_gray_glacier_vm_precompiled_contracts_imports_ALT_BN128_MUL_ADDRESS : + IsImported globals "ethereum.gray_glacier.vm.precompiled_contracts" "ALT_BN128_MUL_ADDRESS". +Axiom ethereum_gray_glacier_vm_precompiled_contracts_imports_ALT_BN128_PAIRING_CHECK_ADDRESS : + IsImported globals "ethereum.gray_glacier.vm.precompiled_contracts" "ALT_BN128_PAIRING_CHECK_ADDRESS". +Axiom ethereum_gray_glacier_vm_precompiled_contracts_imports_BLAKE2F_ADDRESS : + IsImported globals "ethereum.gray_glacier.vm.precompiled_contracts" "BLAKE2F_ADDRESS". +Axiom ethereum_gray_glacier_vm_precompiled_contracts_imports_ECRECOVER_ADDRESS : + IsImported globals "ethereum.gray_glacier.vm.precompiled_contracts" "ECRECOVER_ADDRESS". +Axiom ethereum_gray_glacier_vm_precompiled_contracts_imports_IDENTITY_ADDRESS : + IsImported globals "ethereum.gray_glacier.vm.precompiled_contracts" "IDENTITY_ADDRESS". +Axiom ethereum_gray_glacier_vm_precompiled_contracts_imports_MODEXP_ADDRESS : + IsImported globals "ethereum.gray_glacier.vm.precompiled_contracts" "MODEXP_ADDRESS". +Axiom ethereum_gray_glacier_vm_precompiled_contracts_imports_RIPEMD160_ADDRESS : + IsImported globals "ethereum.gray_glacier.vm.precompiled_contracts" "RIPEMD160_ADDRESS". +Axiom ethereum_gray_glacier_vm_precompiled_contracts_imports_SHA256_ADDRESS : + IsImported globals "ethereum.gray_glacier.vm.precompiled_contracts" "SHA256_ADDRESS". + +Axiom ethereum_gray_glacier_vm_precompiled_contracts_alt_bn128_imports_alt_bn128_add : + IsImported globals "ethereum.gray_glacier.vm.precompiled_contracts.alt_bn128" "alt_bn128_add". +Axiom ethereum_gray_glacier_vm_precompiled_contracts_alt_bn128_imports_alt_bn128_mul : + IsImported globals "ethereum.gray_glacier.vm.precompiled_contracts.alt_bn128" "alt_bn128_mul". +Axiom ethereum_gray_glacier_vm_precompiled_contracts_alt_bn128_imports_alt_bn128_pairing_check : + IsImported globals "ethereum.gray_glacier.vm.precompiled_contracts.alt_bn128" "alt_bn128_pairing_check". + +Axiom ethereum_gray_glacier_vm_precompiled_contracts_blake2f_imports_blake2f : + IsImported globals "ethereum.gray_glacier.vm.precompiled_contracts.blake2f" "blake2f". + +Axiom ethereum_gray_glacier_vm_precompiled_contracts_ecrecover_imports_ecrecover : + IsImported globals "ethereum.gray_glacier.vm.precompiled_contracts.ecrecover" "ecrecover". + +Axiom ethereum_gray_glacier_vm_precompiled_contracts_identity_imports_identity : + IsImported globals "ethereum.gray_glacier.vm.precompiled_contracts.identity" "identity". + +Axiom ethereum_gray_glacier_vm_precompiled_contracts_modexp_imports_modexp : + IsImported globals "ethereum.gray_glacier.vm.precompiled_contracts.modexp" "modexp". + +Axiom ethereum_gray_glacier_vm_precompiled_contracts_ripemd160_imports_ripemd160 : + IsImported globals "ethereum.gray_glacier.vm.precompiled_contracts.ripemd160" "ripemd160". + +Axiom ethereum_gray_glacier_vm_precompiled_contracts_sha256_imports_sha256 : + IsImported globals "ethereum.gray_glacier.vm.precompiled_contracts.sha256" "sha256". (* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/modexp.v index 8c46415..a12f219 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/modexp.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/modexp.v @@ -17,17 +17,21 @@ Introduction Implementation of the `MODEXP` precompiled contract. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_gray_glacier_vm_imports : - AreImported globals "ethereum.gray_glacier.vm" [ "Evm" ]. +Axiom ethereum_gray_glacier_vm_imports_Evm : + IsImported globals "ethereum.gray_glacier.vm" "Evm". -Axiom ethereum_gray_glacier_vm_gas_imports : - AreImported globals "ethereum.gray_glacier.vm.gas" [ "charge_gas" ]. +Axiom ethereum_gray_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.gray_glacier.vm.gas" "charge_gas". -Axiom ethereum_gray_glacier_vm_memory_imports : - AreImported globals "ethereum.gray_glacier.vm.memory" [ "buffer_read" ]. +Axiom ethereum_gray_glacier_vm_memory_imports_buffer_read : + IsImported globals "ethereum.gray_glacier.vm.memory" "buffer_read". Definition GQUADDIVISOR : Value.t := M.run ltac:(M.monadic ( Constant.int 3 @@ -40,9 +44,12 @@ Definition modexp : Value.t -> Value.t -> M := Calculates `(base**exp) % modulus` for arbitrary sized `base`, `exp` and. `modulus`. The return value is the same length as the modulus. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let base_length := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "base_length" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -69,8 +76,10 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exp_length := + |) + |) in + let _ := M.assign_local (| + "exp_length" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -97,8 +106,10 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let modulus_length := + |) + |) in + let _ := M.assign_local (| + "modulus_length" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -125,8 +136,10 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exp_start := + |) + |) in + let _ := M.assign_local (| + "exp_start" , BinOp.add (| M.call (| M.get_name (| globals, "U256" |), @@ -136,8 +149,10 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |), M.get_name (| globals, "base_length" |) - |) in - let exp_head := + |) + |) in + let _ := M.assign_local (| + "exp_head" , M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ @@ -165,7 +180,8 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -216,7 +232,8 @@ Definition modexp : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let base := + let _ := M.assign_local (| + "base" , M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ @@ -237,8 +254,10 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exp := + |) + |) in + let _ := M.assign_local (| + "exp" , M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ @@ -253,13 +272,17 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let modulus_start := + |) + |) in + let _ := M.assign_local (| + "modulus_start" , BinOp.add (| M.get_name (| globals, "exp_start" |), M.get_name (| globals, "exp_length" |) - |) in - let modulus := + |) + |) in + let _ := M.assign_local (| + "modulus" , M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ @@ -274,7 +297,8 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -350,7 +374,8 @@ Definition complexity : Value.t -> Value.t -> M := complexity : `Uint` Complexity of performing the operation. " in - let max_length := + let _ := M.assign_local (| + "max_length" , M.call (| M.get_name (| globals, "max" |), make_list [ @@ -370,15 +395,18 @@ Definition complexity : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| BinOp.add (| M.get_name (| globals, "max_length" |), Constant.int 7 |), Constant.int 8 - |) in + |) + |) in let _ := M.return_ (| BinOp.pow (| M.get_name (| globals, "words" |), @@ -427,14 +455,16 @@ Definition iterations : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let count := + let _ := M.assign_local (| + "count" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -447,7 +477,8 @@ Definition iterations : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let bit_length := + let _ := M.assign_local (| + "bit_length" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -458,7 +489,8 @@ Definition iterations : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -468,20 +500,25 @@ Definition iterations : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let bit_length := BinOp.sub + let _ := M.assign_op_local (| + BinOp.sub, + "bit_length", Constant.int 1 - Constant.int 1 in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let count := - M.get_name (| globals, "bit_length" |) in + let _ := M.assign_local (| + "count" , + M.get_name (| globals, "bit_length" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let length_part := + let _ := M.assign_local (| + "length_part" , BinOp.mult (| Constant.int 8, BinOp.sub (| @@ -494,8 +531,10 @@ Definition iterations : Value.t -> Value.t -> M := |), Constant.int 32 |) - |) in - let bits_part := + |) + |) in + let _ := M.assign_local (| + "bits_part" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -506,7 +545,8 @@ Definition iterations : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -516,19 +556,23 @@ Definition iterations : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let bits_part := BinOp.sub + let _ := M.assign_op_local (| + BinOp.sub, + "bits_part", Constant.int 1 - Constant.int 1 in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let count := + let _ := M.assign_local (| + "count" , BinOp.add (| M.get_name (| globals, "length_part" |), M.get_name (| globals, "bits_part" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -579,7 +623,8 @@ Definition gas_cost : Value.t -> Value.t -> M := gas_cost : `Uint` Gas required for performing the operation. " in - let multiplication_complexity := + let _ := M.assign_local (| + "multiplication_complexity" , M.call (| M.get_name (| globals, "complexity" |), make_list [ @@ -587,8 +632,10 @@ Definition gas_cost : Value.t -> Value.t -> M := M.get_name (| globals, "modulus_length" |) ], make_dict [] - |) in - let iteration_count := + |) + |) in + let _ := M.assign_local (| + "iteration_count" , M.call (| M.get_name (| globals, "iterations" |), make_list [ @@ -596,15 +643,20 @@ Definition gas_cost : Value.t -> Value.t -> M := M.get_name (| globals, "exponent_head" |) ], make_dict [] - |) in - let cost := + |) + |) in + let _ := M.assign_local (| + "cost" , BinOp.mult (| M.get_name (| globals, "multiplication_complexity" |), M.get_name (| globals, "iteration_count" |) - |) in - let cost := BinOp.floor_div + |) + |) in + let _ := M.assign_op_local (| + BinOp.floor_div, + "cost", M.get_name (| globals, "GQUADDIVISOR" |) - M.get_name (| globals, "GQUADDIVISOR" |) in + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "max" |), diff --git a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/ripemd160.v index 5766b64..553c4c2 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/ripemd160.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/ripemd160.v @@ -19,20 +19,24 @@ Implementation of the `RIPEMD160` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_left_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "left_pad_zero_bytes". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_gray_glacier_vm_imports : - AreImported globals "ethereum.gray_glacier.vm" [ "Evm" ]. +Axiom ethereum_gray_glacier_vm_imports_Evm : + IsImported globals "ethereum.gray_glacier.vm" "Evm". -Axiom ethereum_gray_glacier_vm_gas_imports : - AreImported globals "ethereum.gray_glacier.vm.gas" [ "GAS_RIPEMD160"; "GAS_RIPEMD160_WORD"; "charge_gas" ]. +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_RIPEMD160 : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_RIPEMD160". +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_RIPEMD160_WORD : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_RIPEMD160_WORD". +Axiom ethereum_gray_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.gray_glacier.vm.gas" "charge_gas". Definition ripemd160 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,9 +49,12 @@ Definition ripemd160 : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let word_count := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "word_count" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -69,7 +76,8 @@ Definition ripemd160 : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -84,7 +92,8 @@ Definition ripemd160 : Value.t -> Value.t -> M := ], make_dict [] |) in - let hash_bytes := + let _ := M.assign_local (| + "hash_bytes" , M.call (| M.get_field (| M.call (| M.get_field (| M.get_name (| globals, "hashlib" |), "new" |), @@ -96,8 +105,10 @@ Definition ripemd160 : Value.t -> Value.t -> M := |), "digest" |), make_list [], make_dict [] - |) in - let padded_hash := + |) + |) in + let _ := M.assign_local (| + "padded_hash" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -105,7 +116,8 @@ Definition ripemd160 : Value.t -> Value.t -> M := Constant.int 32 ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.get_name (| globals, "padded_hash" |) diff --git a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/sha256.v index 8a9ad1b..ae4e91d 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/sha256.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/precompiled_contracts/sha256.v @@ -19,17 +19,21 @@ Implementation of the `SHA256` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_gray_glacier_vm_imports : - AreImported globals "ethereum.gray_glacier.vm" [ "Evm" ]. +Axiom ethereum_gray_glacier_vm_imports_Evm : + IsImported globals "ethereum.gray_glacier.vm" "Evm". -Axiom ethereum_gray_glacier_vm_gas_imports : - AreImported globals "ethereum.gray_glacier.vm.gas" [ "GAS_SHA256"; "GAS_SHA256_WORD"; "charge_gas" ]. +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_SHA256 : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_SHA256". +Axiom ethereum_gray_glacier_vm_gas_imports_GAS_SHA256_WORD : + IsImported globals "ethereum.gray_glacier.vm.gas" "GAS_SHA256_WORD". +Axiom ethereum_gray_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.gray_glacier.vm.gas" "charge_gas". Definition sha256 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,9 +46,12 @@ Definition sha256 : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let word_count := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "word_count" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -66,7 +73,8 @@ Definition sha256 : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ diff --git a/CoqOfPython/ethereum/gray_glacier/vm/runtime.v b/CoqOfPython/ethereum/gray_glacier/vm/runtime.v index 6cb1c91..4c10884 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/runtime.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/runtime.v @@ -17,14 +17,14 @@ Introduction Runtime related operations used while executing EVM code. ". -Axiom typing_imports : - AreImported globals "typing" [ "Set" ]. +Axiom typing_imports_Set : + IsImported globals "typing" "Set". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_gray_glacier_vm_instructions_imports : - AreImported globals "ethereum.gray_glacier.vm.instructions" [ "Ops" ]. +Axiom ethereum_gray_glacier_vm_instructions_imports_Ops : + IsImported globals "ethereum.gray_glacier.vm.instructions" "Ops". Definition get_valid_jump_destinations : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -50,20 +50,24 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := valid_jump_destinations: `Set[Uint]` The set of valid jump destinations in the code. " in - let valid_jump_destinations := + let _ := M.assign_local (| + "valid_jump_destinations" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let pc := + |) + |) in + let _ := M.assign_local (| + "pc" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in let _ := M.while (| Compare.lt (| @@ -114,17 +118,21 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let push_data_size := + let _ := M.assign_local (| + "push_data_size" , BinOp.add (| BinOp.sub (| M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) |), Constant.int 1 - |) in - let pc := BinOp.add + |) + |) in + let _ := M.assign_op_local (| + BinOp.add, + "pc", M.get_name (| globals, "push_data_size" |) - M.get_name (| globals, "push_data_size" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -132,9 +140,11 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - let pc := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "pc", Constant.int 1 - Constant.int 1 in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/gray_glacier/vm/stack.v b/CoqOfPython/ethereum/gray_glacier/vm/stack.v index 8f04eae..4742c55 100644 --- a/CoqOfPython/ethereum/gray_glacier/vm/stack.v +++ b/CoqOfPython/ethereum/gray_glacier/vm/stack.v @@ -17,14 +17,16 @@ Introduction Implementation of the stack operators for the EVM. ". -Axiom typing_imports : - AreImported globals "typing" [ "List" ]. +Axiom typing_imports_List : + IsImported globals "typing" "List". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_gray_glacier_vm_exceptions_imports : - AreImported globals "ethereum.gray_glacier.vm.exceptions" [ "StackOverflowError"; "StackUnderflowError" ]. +Axiom ethereum_gray_glacier_vm_exceptions_imports_StackOverflowError : + IsImported globals "ethereum.gray_glacier.vm.exceptions" "StackOverflowError". +Axiom ethereum_gray_glacier_vm_exceptions_imports_StackUnderflowError : + IsImported globals "ethereum.gray_glacier.vm.exceptions" "StackUnderflowError". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/homestead/__init__.v b/CoqOfPython/ethereum/homestead/__init__.v index cc7997c..b8b69f5 100644 --- a/CoqOfPython/ethereum/homestead/__init__.v +++ b/CoqOfPython/ethereum/homestead/__init__.v @@ -10,8 +10,8 @@ the behavior of contract creation with insufficient gas, delays the difficulty bomb, and adds an improved delegate call EVM instruction. ". -Axiom ethereum_fork_criteria_imports : - AreImported globals "ethereum.fork_criteria" [ "ByBlockNumber" ]. +Axiom ethereum_fork_criteria_imports_ByBlockNumber : + IsImported globals "ethereum.fork_criteria" "ByBlockNumber". Definition FORK_CRITERIA : Value.t := M.run ltac:(M.monadic ( M.call (| diff --git a/CoqOfPython/ethereum/homestead/blocks.v b/CoqOfPython/ethereum/homestead/blocks.v index a725a0e..237a920 100644 --- a/CoqOfPython/ethereum/homestead/blocks.v +++ b/CoqOfPython/ethereum/homestead/blocks.v @@ -14,23 +14,37 @@ history of all state transitions that have happened since the genesis of the chain. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Tuple" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes8"; "Bytes32"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. - -Axiom ethereum_homestead_fork_types_imports : - AreImported globals "ethereum.homestead.fork_types" [ "Address"; "Bloom"; "Root" ]. - -Axiom ethereum_homestead_transactions_imports : - AreImported globals "ethereum.homestead.transactions" [ "Transaction" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes8 : + IsImported globals "ethereum.base_types" "Bytes8". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". + +Axiom ethereum_homestead_fork_types_imports_Address : + IsImported globals "ethereum.homestead.fork_types" "Address". +Axiom ethereum_homestead_fork_types_imports_Bloom : + IsImported globals "ethereum.homestead.fork_types" "Bloom". +Axiom ethereum_homestead_fork_types_imports_Root : + IsImported globals "ethereum.homestead.fork_types" "Root". + +Axiom ethereum_homestead_transactions_imports_Transaction : + IsImported globals "ethereum.homestead.transactions" "Transaction". Definition Header : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/homestead/bloom.v b/CoqOfPython/ethereum/homestead/bloom.v index 412a1c1..04c7450 100644 --- a/CoqOfPython/ethereum/homestead/bloom.v +++ b/CoqOfPython/ethereum/homestead/bloom.v @@ -21,20 +21,20 @@ for efficient searching of logs by address and/or topic, by rapidly eliminating blocks and receipts from their search. ". -Axiom typing_imports : - AreImported globals "typing" [ "Tuple" ]. +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_homestead_blocks_imports : - AreImported globals "ethereum.homestead.blocks" [ "Log" ]. +Axiom ethereum_homestead_blocks_imports_Log : + IsImported globals "ethereum.homestead.blocks" "Log". -Axiom ethereum_homestead_fork_types_imports : - AreImported globals "ethereum.homestead.fork_types" [ "Bloom" ]. +Axiom ethereum_homestead_fork_types_imports_Bloom : + IsImported globals "ethereum.homestead.fork_types" "Bloom". Definition add_to_bloom : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -53,20 +53,23 @@ Definition add_to_bloom : Value.t -> Value.t -> M := bloom_entry : An entry which is to be added to bloom filter. " in - let hash := + let _ := M.assign_local (| + "hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "bloom_entry" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "idx" |), make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ], ltac:(M.monadic ( - let bit_to_set := + let _ := M.assign_local (| + "bit_to_set" , BinOp.bit_and (| M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), @@ -84,18 +87,24 @@ Definition add_to_bloom : Value.t -> Value.t -> M := make_dict [] |), Constant.int 2047 - |) in - let bit_index := + |) + |) in + let _ := M.assign_local (| + "bit_index" , BinOp.sub (| Constant.int 2047, M.get_name (| globals, "bit_to_set" |) - |) in - let byte_index := + |) + |) in + let _ := M.assign_local (| + "byte_index" , BinOp.floor_div (| M.get_name (| globals, "bit_index" |), Constant.int 8 - |) in - let bit_value := + |) + |) in + let _ := M.assign_local (| + "bit_value" , BinOp.l_shift (| Constant.int 1, BinOp.sub (| @@ -105,7 +114,8 @@ Definition add_to_bloom : Value.t -> Value.t -> M := Constant.int 8 |) |) - |) in + |) + |) in let _ := M.assign (| M.get_subscript (| M.get_name (| globals, "bloom" |), diff --git a/CoqOfPython/ethereum/homestead/fork.v b/CoqOfPython/ethereum/homestead/fork.v index 4c5e111..44f0c2f 100644 --- a/CoqOfPython/ethereum/homestead/fork.v +++ b/CoqOfPython/ethereum/homestead/fork.v @@ -17,62 +17,120 @@ Introduction Entry point for the Ethereum specification. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Bytes0" ]. - -Axiom ethereum_crypto_elliptic_curve_imports : - AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. - -Axiom ethereum_ethash_imports : - AreImported globals "ethereum.ethash" [ "dataset_size"; "generate_cache"; "hashimoto_light" ]. - -Axiom ethereum_exceptions_imports : - AreImported globals "ethereum.exceptions" [ "InvalidBlock" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U64"; "U256"; "U256_CEIL_VALUE"; "Bytes"; "Bytes32"; "Uint" ]. - -Axiom ethereum_homestead_imports : - AreImported globals "ethereum.homestead" [ "vm" ]. - -Axiom ethereum_homestead_blocks_imports : - AreImported globals "ethereum.homestead.blocks" [ "Block"; "Header"; "Log"; "Receipt" ]. - -Axiom ethereum_homestead_bloom_imports : - AreImported globals "ethereum.homestead.bloom" [ "logs_bloom" ]. - -Axiom ethereum_homestead_fork_types_imports : - AreImported globals "ethereum.homestead.fork_types" [ "Address"; "Bloom"; "Root" ]. - -Axiom ethereum_homestead_state_imports : - AreImported globals "ethereum.homestead.state" [ "State"; "create_ether"; "destroy_account"; "get_account"; "increment_nonce"; "set_account_balance"; "state_root" ]. - -Axiom ethereum_homestead_transactions_imports : - AreImported globals "ethereum.homestead.transactions" [ "TX_BASE_COST"; "TX_CREATE_COST"; "TX_DATA_COST_PER_NON_ZERO"; "TX_DATA_COST_PER_ZERO"; "Transaction" ]. - -Axiom ethereum_homestead_trie_imports : - AreImported globals "ethereum.homestead.trie" [ "Trie"; "root"; "trie_set" ]. - -Axiom ethereum_homestead_utils_message_imports : - AreImported globals "ethereum.homestead.utils.message" [ "prepare_message" ]. - -Axiom ethereum_homestead_vm_interpreter_imports : - AreImported globals "ethereum.homestead.vm.interpreter" [ "process_message_call" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". + +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". + +Axiom ethereum_crypto_elliptic_curve_imports_SECP256K1N : + IsImported globals "ethereum.crypto.elliptic_curve" "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_imports_secp256k1_recover : + IsImported globals "ethereum.crypto.elliptic_curve" "secp256k1_recover". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". + +Axiom ethereum_ethash_imports_dataset_size : + IsImported globals "ethereum.ethash" "dataset_size". +Axiom ethereum_ethash_imports_generate_cache : + IsImported globals "ethereum.ethash" "generate_cache". +Axiom ethereum_ethash_imports_hashimoto_light : + IsImported globals "ethereum.ethash" "hashimoto_light". + +Axiom ethereum_exceptions_imports_InvalidBlock : + IsImported globals "ethereum.exceptions" "InvalidBlock". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U64 : + IsImported globals "ethereum.base_types" "U64". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_U256_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U256_CEIL_VALUE". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_homestead_imports_vm : + IsImported globals "ethereum.homestead" "vm". + +Axiom ethereum_homestead_blocks_imports_Block : + IsImported globals "ethereum.homestead.blocks" "Block". +Axiom ethereum_homestead_blocks_imports_Header : + IsImported globals "ethereum.homestead.blocks" "Header". +Axiom ethereum_homestead_blocks_imports_Log : + IsImported globals "ethereum.homestead.blocks" "Log". +Axiom ethereum_homestead_blocks_imports_Receipt : + IsImported globals "ethereum.homestead.blocks" "Receipt". + +Axiom ethereum_homestead_bloom_imports_logs_bloom : + IsImported globals "ethereum.homestead.bloom" "logs_bloom". + +Axiom ethereum_homestead_fork_types_imports_Address : + IsImported globals "ethereum.homestead.fork_types" "Address". +Axiom ethereum_homestead_fork_types_imports_Bloom : + IsImported globals "ethereum.homestead.fork_types" "Bloom". +Axiom ethereum_homestead_fork_types_imports_Root : + IsImported globals "ethereum.homestead.fork_types" "Root". + +Axiom ethereum_homestead_state_imports_State : + IsImported globals "ethereum.homestead.state" "State". +Axiom ethereum_homestead_state_imports_create_ether : + IsImported globals "ethereum.homestead.state" "create_ether". +Axiom ethereum_homestead_state_imports_destroy_account : + IsImported globals "ethereum.homestead.state" "destroy_account". +Axiom ethereum_homestead_state_imports_get_account : + IsImported globals "ethereum.homestead.state" "get_account". +Axiom ethereum_homestead_state_imports_increment_nonce : + IsImported globals "ethereum.homestead.state" "increment_nonce". +Axiom ethereum_homestead_state_imports_set_account_balance : + IsImported globals "ethereum.homestead.state" "set_account_balance". +Axiom ethereum_homestead_state_imports_state_root : + IsImported globals "ethereum.homestead.state" "state_root". + +Axiom ethereum_homestead_transactions_imports_TX_BASE_COST : + IsImported globals "ethereum.homestead.transactions" "TX_BASE_COST". +Axiom ethereum_homestead_transactions_imports_TX_CREATE_COST : + IsImported globals "ethereum.homestead.transactions" "TX_CREATE_COST". +Axiom ethereum_homestead_transactions_imports_TX_DATA_COST_PER_NON_ZERO : + IsImported globals "ethereum.homestead.transactions" "TX_DATA_COST_PER_NON_ZERO". +Axiom ethereum_homestead_transactions_imports_TX_DATA_COST_PER_ZERO : + IsImported globals "ethereum.homestead.transactions" "TX_DATA_COST_PER_ZERO". +Axiom ethereum_homestead_transactions_imports_Transaction : + IsImported globals "ethereum.homestead.transactions" "Transaction". + +Axiom ethereum_homestead_trie_imports_Trie : + IsImported globals "ethereum.homestead.trie" "Trie". +Axiom ethereum_homestead_trie_imports_root : + IsImported globals "ethereum.homestead.trie" "root". +Axiom ethereum_homestead_trie_imports_trie_set : + IsImported globals "ethereum.homestead.trie" "trie_set". + +Axiom ethereum_homestead_utils_message_imports_prepare_message : + IsImported globals "ethereum.homestead.utils.message" "prepare_message". + +Axiom ethereum_homestead_vm_interpreter_imports_process_message_call : + IsImported globals "ethereum.homestead.vm.interpreter" "process_message_call". Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -170,13 +228,15 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := recent_block_hashes : `List[Hash32]` Hashes of the recent 256 blocks in order of increasing block number. " in - let recent_blocks := + let _ := M.assign_local (| + "recent_blocks" , M.slice (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |), Constant.None_, Constant.None_ - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -200,15 +260,19 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let recent_block_hashes := - make_list [] in + let _ := M.assign_local (| + "recent_block_hashes" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "block" |), M.get_name (| globals, "recent_blocks" |), ltac:(M.monadic ( - let prev_block_hash := - M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in + let _ := M.assign_local (| + "prev_block_hash" , + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), make_list [ @@ -222,7 +286,8 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let most_recent_block_hash := + let _ := M.assign_local (| + "most_recent_block_hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -238,7 +303,8 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), make_list [ @@ -275,11 +341,13 @@ Definition state_transition : Value.t -> Value.t -> M := block : Block to apply to `chain`. " in - let parent_header := + let _ := M.assign_local (| + "parent_header" , M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 1 |) - |), "header" |) in + |), "header" |) + |) in let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ @@ -297,7 +365,8 @@ Definition state_transition : Value.t -> Value.t -> M := ], make_dict [] |) in - let apply_body_output := + let _ := M.assign_local (| + "apply_body_output" , M.call (| M.get_name (| globals, "apply_body" |), make_list [ @@ -318,7 +387,8 @@ Definition state_transition : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "block" |), "ommers" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -489,7 +559,8 @@ Definition validate_header : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_difficulty := + let _ := M.assign_local (| + "block_difficulty" , M.call (| M.get_name (| globals, "calculate_block_difficulty" |), make_list [ @@ -499,7 +570,8 @@ Definition validate_header : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "parent_header" |), "difficulty" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -511,7 +583,8 @@ Definition validate_header : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_parent_hash := + let _ := M.assign_local (| + "block_parent_hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -524,7 +597,8 @@ Definition validate_header : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -570,7 +644,8 @@ Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := hash : `Hash32` The PoW valid rlp hash of the passed in header. " in - let header_data_without_pow_artefacts := + let _ := M.assign_local (| + "header_data_without_pow_artefacts" , make_list [ M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |); M.get_field (| M.get_name (| globals, "header" |), "ommers_hash" |); @@ -585,7 +660,8 @@ Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "header" |), "gas_used" |); M.get_field (| M.get_name (| globals, "header" |), "timestamp" |); M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) - ] in + ] + |) in let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), @@ -614,22 +690,26 @@ Definition validate_proof_of_work : Value.t -> Value.t -> M := header : Header of interest. " in - let header_hash := + let _ := M.assign_local (| + "header_hash" , M.call (| M.get_name (| globals, "generate_header_hash_for_pow" |), make_list [ M.get_name (| globals, "header" |) ], make_dict [] - |) in - let cache := + |) + |) in + let _ := M.assign_local (| + "cache" , M.call (| M.get_name (| globals, "generate_cache" |), make_list [ M.get_field (| M.get_name (| globals, "header" |), "number" |) ], make_dict [] - |) in + |) + |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "mix_digest" |); M.get_name (| globals, "result" |) ], M.call (| @@ -716,14 +796,16 @@ Definition check_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_address := + let _ := M.assign_local (| + "sender_address" , M.call (| M.get_name (| globals, "recover_sender" |), make_list [ M.get_name (| globals, "tx" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "sender_address" |) |) in @@ -752,12 +834,14 @@ Definition make_receipt : Value.t -> Value.t -> M := receipt : The receipt for the transaction. " in - let receipt := + let _ := M.assign_local (| + "receipt" , M.call (| M.get_name (| globals, "Receipt" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "receipt" |) |) in @@ -814,8 +898,10 @@ Definition apply_body : Value.t -> Value.t -> M := apply_body_output : `ApplyBodyOutput` Output of applying the block body to the state. " in - let gas_available := - M.get_name (| globals, "block_gas_limit" |) in + let _ := M.assign_local (| + "gas_available" , + M.get_name (| globals, "block_gas_limit" |) + |) in (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) @@ -851,7 +937,8 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_address := + let _ := M.assign_local (| + "sender_address" , M.call (| M.get_name (| globals, "check_transaction" |), make_list [ @@ -859,13 +946,16 @@ Definition apply_body : Value.t -> Value.t -> M := M.get_name (| globals, "gas_available" |) ], make_dict [] - |) in - let env := + |) + |) in + let _ := M.assign_local (| + "env" , M.call (| M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |) ], M.call (| @@ -877,10 +967,13 @@ Definition apply_body : Value.t -> Value.t -> M := make_dict [] |) |) in - let gas_available := BinOp.sub + let _ := M.assign_op_local (| + BinOp.sub, + "gas_available", M.get_name (| globals, "gas_used" |) - M.get_name (| globals, "gas_used" |) in - let receipt := + |) in + let _ := M.assign_local (| + "receipt" , M.call (| M.get_name (| globals, "make_receipt" |), make_list [ @@ -899,7 +992,8 @@ Definition apply_body : Value.t -> Value.t -> M := M.get_name (| globals, "logs" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ @@ -921,9 +1015,11 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_logs := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "block_logs", M.get_name (| globals, "logs" |) - M.get_name (| globals, "logs" |) in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -940,19 +1036,23 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_gas_used := + let _ := M.assign_local (| + "block_gas_used" , BinOp.sub (| M.get_name (| globals, "block_gas_limit" |), M.get_name (| globals, "gas_available" |) - |) in - let block_logs_bloom := + |) + |) in + let _ := M.assign_local (| + "block_logs_bloom" , M.call (| M.get_name (| globals, "logs_bloom" |), make_list [ M.get_name (| globals, "block_logs" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ApplyBodyOutput" |), @@ -1010,14 +1110,16 @@ Definition validate_ommers : Value.t -> Value.t -> M := chain : History and current state. " in - let block_hash := + let _ := M.assign_local (| + "block_hash" , M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), make_list [ M.get_name (| globals, "block_header" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1082,7 +1184,8 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_parent_header := + let _ := M.assign_local (| + "ommer_parent_header" , M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), BinOp.sub (| @@ -1092,7 +1195,8 @@ Definition validate_ommers : Value.t -> Value.t -> M := |) |), Constant.int 1 |) - |), "header" |) in + |), "header" |) + |) in let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ @@ -1124,8 +1228,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommers_hashes := - Constant.str "(* At expr: unsupported node type: ListComp *)" in + let _ := M.assign_local (| + "ommers_hashes" , + Constant.str "(* At expr: unsupported node type: ListComp *)" + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1155,7 +1261,8 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let recent_canonical_blocks := + let _ := M.assign_local (| + "recent_canonical_blocks" , M.slice (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| BinOp.add (| @@ -1164,23 +1271,28 @@ Definition validate_ommers : Value.t -> Value.t -> M := |) |), Constant.None_, Constant.None_ - |) in - let recent_canonical_block_hashes := - Constant.str "(* At expr: unsupported node type: SetComp *)" in + |) + |) in + let _ := M.assign_local (| + "recent_canonical_block_hashes" , + Constant.str "(* At expr: unsupported node type: SetComp *)" + |) in (* At stmt: unsupported node type: AnnAssign *) let _ := M.for_ (| M.get_name (| globals, "block" |), M.get_name (| globals, "recent_canonical_blocks" |), ltac:(M.monadic ( - let recent_ommers_hashes := + let _ := M.assign_local (| + "recent_ommers_hashes" , M.call (| M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), make_list [ Constant.str "(* At expr: unsupported node type: SetComp *)" ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -1198,11 +1310,13 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let ommer_hash := + let _ := M.assign_local (| + "ommer_hash" , M.get_subscript (| M.get_name (| globals, "ommers_hashes" |), M.get_name (| globals, "ommer_index" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1236,11 +1350,13 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_age := + let _ := M.assign_local (| + "ommer_age" , BinOp.sub (| M.get_field (| M.get_name (| globals, "block_header" |), "number" |), M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1318,7 +1434,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := ommers : List of ommers mentioned in the current block. " in - let miner_reward := + let _ := M.assign_local (| + "miner_reward" , BinOp.add (| M.get_name (| globals, "BLOCK_REWARD" |), BinOp.mult (| @@ -1334,7 +1451,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := Constant.int 32 |) |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "create_ether" |), make_list [ @@ -1349,7 +1467,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := M.get_name (| globals, "ommer" |), M.get_name (| globals, "ommers" |), ltac:(M.monadic ( - let ommer_age := + let _ := M.assign_local (| + "ommer_age" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -1359,8 +1478,10 @@ Definition pay_rewards : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let ommer_miner_reward := + |) + |) in + let _ := M.assign_local (| + "ommer_miner_reward" , BinOp.floor_div (| BinOp.mult (| BinOp.sub (| @@ -1370,7 +1491,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := M.get_name (| globals, "BLOCK_REWARD" |) |), Constant.int 8 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "create_ether" |), make_list [ @@ -1431,9 +1553,12 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender := - M.get_field (| M.get_name (| globals, "env" |), "origin" |) in - let sender_account := + let _ := M.assign_local (| + "sender" , + M.get_field (| M.get_name (| globals, "env" |), "origin" |) + |) in + let _ := M.assign_local (| + "sender_account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1441,12 +1566,15 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "sender" |) ], make_dict [] - |) in - let gas_fee := + |) + |) in + let _ := M.assign_local (| + "gas_fee" , BinOp.mult (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1487,7 +1615,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let gas := + let _ := M.assign_local (| + "gas" , BinOp.sub (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.call (| @@ -1497,7 +1626,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "increment_nonce" |), make_list [ @@ -1506,11 +1636,13 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_balance_after_gas_fee := + let _ := M.assign_local (| + "sender_balance_after_gas_fee" , BinOp.sub (| M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), M.get_name (| globals, "gas_fee" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -1520,7 +1652,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let message := + let _ := M.assign_local (| + "message" , M.call (| M.get_name (| globals, "prepare_message" |), make_list [ @@ -1532,8 +1665,10 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in - let output := + |) + |) in + let _ := M.assign_local (| + "output" , M.call (| M.get_name (| globals, "process_message_call" |), make_list [ @@ -1541,13 +1676,17 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in - let gas_used := + |) + |) in + let _ := M.assign_local (| + "gas_used" , BinOp.sub (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_field (| M.get_name (| globals, "output" |), "gas_left" |) - |) in - let gas_refund := + |) + |) in + let _ := M.assign_local (| + "gas_refund" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -1558,16 +1697,20 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "output" |), "refund_counter" |) ], make_dict [] - |) in - let gas_refund_amount := + |) + |) in + let _ := M.assign_local (| + "gas_refund_amount" , BinOp.mult (| BinOp.add (| M.get_field (| M.get_name (| globals, "output" |), "gas_left" |), M.get_name (| globals, "gas_refund" |) |), M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) - |) in - let transaction_fee := + |) + |) in + let _ := M.assign_local (| + "transaction_fee" , BinOp.mult (| BinOp.sub (| BinOp.sub (| @@ -1577,13 +1720,17 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "gas_refund" |) |), M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) - |) in - let total_gas_used := + |) + |) in + let _ := M.assign_local (| + "total_gas_used" , BinOp.sub (| M.get_name (| globals, "gas_used" |), M.get_name (| globals, "gas_refund" |) - |) in - let sender_balance_after_refund := + |) + |) in + let _ := M.assign_local (| + "sender_balance_after_refund" , BinOp.add (| M.get_field (| M.call (| M.get_name (| globals, "get_account" |), @@ -1594,7 +1741,8 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |), "balance" |), M.get_name (| globals, "gas_refund_amount" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -1604,7 +1752,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let coinbase_balance_after_mining_fee := + let _ := M.assign_local (| + "coinbase_balance_after_mining_fee" , BinOp.add (| M.get_field (| M.call (| M.get_name (| globals, "get_account" |), @@ -1615,7 +1764,8 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |), "balance" |), M.get_name (| globals, "transaction_fee" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -1729,8 +1879,10 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := verified : `ethereum.base_types.Uint` The intrinsic cost of the transaction. " in - let data_cost := - Constant.int 0 in + let _ := M.assign_local (| + "data_cost" , + Constant.int 0 + |) in let _ := M.for_ (| M.get_name (| globals, "byte" |), @@ -1745,15 +1897,19 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let data_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "data_cost", M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let data_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "data_cost", M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -1777,13 +1933,17 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let create_cost := - M.get_name (| globals, "TX_CREATE_COST" |) in + let _ := M.assign_local (| + "create_cost" , + M.get_name (| globals, "TX_CREATE_COST" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let create_cost := - Constant.int 0 in + let _ := M.assign_local (| + "create_cost" , + Constant.int 0 + |) in M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1889,7 +2049,8 @@ Definition recover_sender : Value.t -> Value.t -> M := ], make_dict [] |) in - let public_key := + let _ := M.assign_local (| + "public_key" , M.call (| M.get_name (| globals, "secp256k1_recover" |), make_list [ @@ -1908,7 +2069,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Address" |), @@ -2049,11 +2211,13 @@ Definition check_gas_limit : Value.t -> Value.t -> M := check : `bool` True if gas limit constraints are satisfied, False otherwise. " in - let max_adjustment_delta := + let _ := M.assign_local (| + "max_adjustment_delta" , BinOp.floor_div (| M.get_name (| globals, "parent_gas_limit" |), M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -2155,7 +2319,8 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := difficulty : `ethereum.base_types.Uint` Computed difficulty for a block. " in - let offset := + let _ := M.assign_local (| + "offset" , BinOp.mult (| BinOp.floor_div (| M.call (| @@ -2190,8 +2355,10 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := ], make_dict [] |) - |) in - let difficulty := + |) + |) in + let _ := M.assign_local (| + "difficulty" , BinOp.add (| M.call (| M.get_name (| globals, "int" |), @@ -2201,8 +2368,10 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := make_dict [] |), M.get_name (| globals, "offset" |) - |) in - let num_bomb_periods := + |) + |) in + let _ := M.assign_local (| + "num_bomb_periods" , BinOp.sub (| BinOp.floor_div (| M.call (| @@ -2215,7 +2384,8 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := Constant.int 100000 |), Constant.int 2 - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -2225,15 +2395,14 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let difficulty := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "difficulty", BinOp.pow (| Constant.int 2, M.get_name (| globals, "num_bomb_periods" |) |) - BinOp.pow (| - Constant.int 2, - M.get_name (| globals, "num_bomb_periods" |) - |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/homestead/fork_types.v b/CoqOfPython/ethereum/homestead/fork_types.v index 90a973d..b6ac107 100644 --- a/CoqOfPython/ethereum/homestead/fork_types.v +++ b/CoqOfPython/ethereum/homestead/fork_types.v @@ -17,17 +17,29 @@ Introduction Types re-used throughout the specification, which are specific to Ethereum. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes20"; "Bytes256"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes20 : + IsImported globals "ethereum.base_types" "Bytes20". +Axiom ethereum_base_types_imports_Bytes256 : + IsImported globals "ethereum.base_types" "Bytes256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) diff --git a/CoqOfPython/ethereum/homestead/state.v b/CoqOfPython/ethereum/homestead/state.v index 6053a03..139e07b 100644 --- a/CoqOfPython/ethereum/homestead/state.v +++ b/CoqOfPython/ethereum/homestead/state.v @@ -22,23 +22,55 @@ There is a distinction between an account that does not exist and `EMPTY_ACCOUNT`. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass"; "field" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict"; "List"; "Optional"; "Tuple" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "modify" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_homestead_fork_types_imports : - AreImported globals "ethereum.homestead.fork_types" [ "EMPTY_ACCOUNT"; "Account"; "Address"; "Root" ]. - -Axiom ethereum_homestead_trie_imports : - AreImported globals "ethereum.homestead.trie" [ "EMPTY_TRIE_ROOT"; "Trie"; "copy_trie"; "root"; "trie_get"; "trie_set" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". +Axiom dataclasses_imports_field : + IsImported globals "dataclasses" "field". + +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_modify : + IsImported globals "ethereum.base_types" "modify". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_homestead_fork_types_imports_EMPTY_ACCOUNT : + IsImported globals "ethereum.homestead.fork_types" "EMPTY_ACCOUNT". +Axiom ethereum_homestead_fork_types_imports_Account : + IsImported globals "ethereum.homestead.fork_types" "Account". +Axiom ethereum_homestead_fork_types_imports_Address : + IsImported globals "ethereum.homestead.fork_types" "Address". +Axiom ethereum_homestead_fork_types_imports_Root : + IsImported globals "ethereum.homestead.fork_types" "Root". + +Axiom ethereum_homestead_trie_imports_EMPTY_TRIE_ROOT : + IsImported globals "ethereum.homestead.trie" "EMPTY_TRIE_ROOT". +Axiom ethereum_homestead_trie_imports_Trie : + IsImported globals "ethereum.homestead.trie" "Trie". +Axiom ethereum_homestead_trie_imports_copy_trie : + IsImported globals "ethereum.homestead.trie" "copy_trie". +Axiom ethereum_homestead_trie_imports_root : + IsImported globals "ethereum.homestead.trie" "root". +Axiom ethereum_homestead_trie_imports_trie_get : + IsImported globals "ethereum.homestead.trie" "trie_get". +Axiom ethereum_homestead_trie_imports_trie_set : + IsImported globals "ethereum.homestead.trie" "trie_set". Definition State : Value.t := builtins.make_klass @@ -153,7 +185,8 @@ Definition get_account : Value.t -> Value.t -> M := account : `Account` Account at address. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account_optional" |), make_list [ @@ -161,7 +194,8 @@ Definition get_account : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -207,7 +241,8 @@ Definition get_account_optional : Value.t -> Value.t -> M := account : `Account` Account at address. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "trie_get" |), make_list [ @@ -215,7 +250,8 @@ Definition get_account_optional : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "account" |) |) in @@ -338,14 +374,16 @@ Definition get_storage : Value.t -> Value.t -> M := value : `U256` Value at the key. " in - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -369,7 +407,8 @@ Definition get_storage : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "trie_get" |), make_list [ @@ -377,7 +416,8 @@ Definition get_storage : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -420,14 +460,16 @@ Definition set_storage : Value.t -> Value.t -> M := |), Constant.None_ |) |) in - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -437,12 +479,14 @@ Definition set_storage : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_name (| globals, "Trie" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), @@ -469,7 +513,7 @@ Definition set_storage : Value.t -> Value.t -> M := M.if_then_else (| Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), - {} + Constant.str "(* At expr: unsupported node type: Dict *)" |), (* then *) ltac:(M.monadic ( @@ -615,7 +659,8 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := True if if an account has non zero nonce or non empty code, False otherwise. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -623,7 +668,8 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| BoolOp.or (| Compare.not_eq (| diff --git a/CoqOfPython/ethereum/homestead/transactions.v b/CoqOfPython/ethereum/homestead/transactions.v index 32c8227..18720ce 100644 --- a/CoqOfPython/ethereum/homestead/transactions.v +++ b/CoqOfPython/ethereum/homestead/transactions.v @@ -9,17 +9,25 @@ submitted to be executed. If Ethereum is viewed as a state machine, transactions are the events that move between states. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Union" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_homestead_fork_types_imports : - AreImported globals "ethereum.homestead.fork_types" [ "Address" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_Union : + IsImported globals "typing" "Union". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_homestead_fork_types_imports_Address : + IsImported globals "ethereum.homestead.fork_types" "Address". Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( Constant.int 21000 diff --git a/CoqOfPython/ethereum/homestead/trie.v b/CoqOfPython/ethereum/homestead/trie.v index fad7c92..62f57c9 100644 --- a/CoqOfPython/ethereum/homestead/trie.v +++ b/CoqOfPython/ethereum/homestead/trie.v @@ -20,38 +20,72 @@ The state trie is the structure responsible for storing (* At top_level_stmt: unsupported node type: Import *) -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass"; "field" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict"; "Generic"; "List"; "Mapping"; "MutableMapping"; "Optional"; "Sequence"; "TypeVar"; "Union"; "cast" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. - -Axiom ethereum_frontier_imports : - AreImported globals "ethereum.frontier" [ "trie" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_utils_hexadecimal_imports : - AreImported globals "ethereum.utils.hexadecimal" [ "hex_to_bytes" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_homestead_blocks_imports : - AreImported globals "ethereum.homestead.blocks" [ "Receipt" ]. - -Axiom ethereum_homestead_fork_types_imports : - AreImported globals "ethereum.homestead.fork_types" [ "Account"; "Address"; "Root"; "encode_account" ]. - -Axiom ethereum_homestead_transactions_imports : - AreImported globals "ethereum.homestead.transactions" [ "Transaction" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". +Axiom dataclasses_imports_field : + IsImported globals "dataclasses" "field". + +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". +Axiom typing_imports_Generic : + IsImported globals "typing" "Generic". +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Mapping : + IsImported globals "typing" "Mapping". +Axiom typing_imports_MutableMapping : + IsImported globals "typing" "MutableMapping". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Sequence : + IsImported globals "typing" "Sequence". +Axiom typing_imports_TypeVar : + IsImported globals "typing" "TypeVar". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". +Axiom typing_imports_cast : + IsImported globals "typing" "cast". + +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". + +Axiom ethereum_frontier_imports_trie : + IsImported globals "ethereum.frontier" "trie". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_utils_hexadecimal_imports_hex_to_bytes : + IsImported globals "ethereum.utils.hexadecimal" "hex_to_bytes". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_homestead_blocks_imports_Receipt : + IsImported globals "ethereum.homestead.blocks" "Receipt". + +Axiom ethereum_homestead_fork_types_imports_Account : + IsImported globals "ethereum.homestead.fork_types" "Account". +Axiom ethereum_homestead_fork_types_imports_Address : + IsImported globals "ethereum.homestead.fork_types" "Address". +Axiom ethereum_homestead_fork_types_imports_Root : + IsImported globals "ethereum.homestead.fork_types" "Root". +Axiom ethereum_homestead_fork_types_imports_encode_account : + IsImported globals "ethereum.homestead.fork_types" "encode_account". + +Axiom ethereum_homestead_transactions_imports_Transaction : + IsImported globals "ethereum.homestead.transactions" "Transaction". Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -161,7 +195,7 @@ Definition encode_internal_node : Value.t -> Value.t -> M := when serialized. This function also accepts `None`, representing the absence of a node, - which is encoded to `b""""""`. + which is encoded to `b""""`. Parameters ---------- @@ -183,8 +217,10 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := - Constant.bytes "" in + let _ := M.assign_local (| + "unencoded" , + Constant.bytes "" + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -201,7 +237,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := + let _ := M.assign_local (| + "unencoded" , make_tuple [ M.call (| M.get_name (| globals, "nibble_list_to_compact" |), make_list [ @@ -209,7 +246,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := Constant.bool true ], make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in + |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -226,7 +264,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := + let _ := M.assign_local (| + "unencoded" , make_tuple [ M.call (| M.get_name (| globals, "nibble_list_to_compact" |), make_list [ @@ -234,7 +273,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := Constant.bool false ], make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in + |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -251,13 +291,15 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := + let _ := M.assign_local (| + "unencoded" , BinOp.add (| M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), make_list [ M.get_field (| M.get_name (| globals, "node" |), "value" |) ] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -276,14 +318,16 @@ Definition encode_internal_node : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - let encoded := + let _ := M.assign_local (| + "encoded" , M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), make_list [ M.get_name (| globals, "unencoded" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -675,12 +719,14 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := compressed : `bytearray` Compact byte array. " in - let compact := + let _ := M.assign_local (| + "compact" , M.call (| M.get_name (| globals, "bytearray" |), make_list [], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -860,7 +906,8 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := nibble_list : `Bytes` The `Bytes` in nibble-list format. " in - let nibble_list := + let _ := M.assign_local (| + "nibble_list" , M.call (| M.get_name (| globals, "bytearray" |), make_list [ @@ -876,7 +923,8 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ], @@ -984,15 +1032,18 @@ Definition _prepare_trie : Value.t -> Value.t -> M := M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "Address" |), make_list [ M.get_name (| globals, "preimage" |) ], make_dict [] - |) in - let encoded_value := + |) + |) in + let _ := M.assign_local (| + "encoded_value" , M.call (| M.get_name (| globals, "encode_node" |), make_list [ @@ -1006,18 +1057,21 @@ Definition _prepare_trie : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let encoded_value := + let _ := M.assign_local (| + "encoded_value" , M.call (| M.get_name (| globals, "encode_node" |), make_list [ M.get_name (| globals, "value" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -1038,19 +1092,23 @@ Definition _prepare_trie : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "trie" |), "secured" |), (* then *) ltac:(M.monadic ( - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "preimage" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let key := - M.get_name (| globals, "preimage" |) in + let _ := M.assign_local (| + "key" , + M.get_name (| globals, "preimage" |) + |) in M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -1097,7 +1155,8 @@ Definition root : Value.t -> Value.t -> M := root : `.fork_types.Root` MPT root of the underlying key-value pairs. " in - let obj := + let _ := M.assign_local (| + "obj" , M.call (| M.get_name (| globals, "_prepare_trie" |), make_list [ @@ -1105,8 +1164,10 @@ Definition root : Value.t -> Value.t -> M := M.get_name (| globals, "get_storage_root" |) ], make_dict [] - |) in - let root_node := + |) + |) in + let _ := M.assign_local (| + "root_node" , M.call (| M.get_name (| globals, "encode_internal_node" |), make_list [ @@ -1126,7 +1187,8 @@ Definition root : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1231,7 +1293,8 @@ Definition patricialize : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let arbitrary_key := + let _ := M.assign_local (| + "arbitrary_key" , M.call (| M.get_name (| globals, "next" |), make_list [ @@ -1244,7 +1307,8 @@ Definition patricialize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1260,7 +1324,8 @@ Definition patricialize : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let leaf := + let _ := M.assign_local (| + "leaf" , M.call (| M.get_name (| globals, "LeafNode" |), make_list [ @@ -1276,7 +1341,8 @@ Definition patricialize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "leaf" |) |) in @@ -1285,27 +1351,32 @@ Definition patricialize : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let substring := + let _ := M.assign_local (| + "substring" , M.slice (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |), Constant.None_, Constant.None_ - |) in - let prefix_length := + |) + |) in + let _ := M.assign_local (| + "prefix_length" , M.call (| M.get_name (| globals, "len" |), make_list [ M.get_name (| globals, "substring" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "key" |), M.get_name (| globals, "obj" |), ltac:(M.monadic ( - let prefix_length := + let _ := M.assign_local (| + "prefix_length" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -1325,7 +1396,8 @@ Definition patricialize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1356,7 +1428,8 @@ Definition patricialize : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let prefix := + let _ := M.assign_local (| + "prefix" , M.slice (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |), @@ -1365,7 +1438,8 @@ Definition patricialize : Value.t -> Value.t -> M := M.get_name (| globals, "prefix_length" |) |), Constant.None_ - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ExtensionNode" |), @@ -1412,7 +1486,7 @@ Definition patricialize : Value.t -> Value.t -> M := let _ := M.call (| M.get_field (| M.get_name (| globals, "branches" |), "append" |), make_list [ - {} + Constant.str "(* At expr: unsupported node type: Dict *)" ], make_dict [] |) in @@ -1422,8 +1496,10 @@ Definition patricialize : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let value := - Constant.bytes "" in + let _ := M.assign_local (| + "value" , + Constant.bytes "" + |) in let _ := M.for_ (| M.get_name (| globals, "key" |), @@ -1466,11 +1542,13 @@ Definition patricialize : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let value := + let _ := M.assign_local (| + "value" , M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/homestead/utils/address.v b/CoqOfPython/ethereum/homestead/utils/address.v index 4105423..82ad5d5 100644 --- a/CoqOfPython/ethereum/homestead/utils/address.v +++ b/CoqOfPython/ethereum/homestead/utils/address.v @@ -17,23 +17,25 @@ Introduction Address specific functions used in this homestead version of specification. ". -Axiom typing_imports : - AreImported globals "typing" [ "Union" ]. +Axiom typing_imports_Union : + IsImported globals "typing" "Union". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_left_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "left_pad_zero_bytes". -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". -Axiom ethereum_homestead_fork_types_imports : - AreImported globals "ethereum.homestead.fork_types" [ "Address" ]. +Axiom ethereum_homestead_fork_types_imports_Address : + IsImported globals "ethereum.homestead.fork_types" "Address". Definition to_address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -90,7 +92,8 @@ Definition compute_contract_address : Value.t -> Value.t -> M := address: `ethereum.homestead.fork_types.Address` The computed address of the new account. " in - let computed_address := + let _ := M.assign_local (| + "computed_address" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -106,15 +109,19 @@ Definition compute_contract_address : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let canonical_address := + |) + |) in + let _ := M.assign_local (| + "canonical_address" , M.slice (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |), Constant.None_, Constant.None_ - |) in - let padded_address := + |) + |) in + let _ := M.assign_local (| + "padded_address" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -122,7 +129,8 @@ Definition compute_contract_address : Value.t -> Value.t -> M := Constant.int 20 ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Address" |), diff --git a/CoqOfPython/ethereum/homestead/utils/hexadecimal.v b/CoqOfPython/ethereum/homestead/utils/hexadecimal.v index 6c9c4df..83917ff 100644 --- a/CoqOfPython/ethereum/homestead/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/homestead/utils/hexadecimal.v @@ -18,11 +18,15 @@ Hexadecimal utility functions used in this specification, specific to Homestead types. ". -Axiom ethereum_utils_hexadecimal_imports : - AreImported globals "ethereum.utils.hexadecimal" [ "remove_hex_prefix" ]. - -Axiom ethereum_homestead_fork_types_imports : - AreImported globals "ethereum.homestead.fork_types" [ "Address"; "Bloom"; "Root" ]. +Axiom ethereum_utils_hexadecimal_imports_remove_hex_prefix : + IsImported globals "ethereum.utils.hexadecimal" "remove_hex_prefix". + +Axiom ethereum_homestead_fork_types_imports_Address : + IsImported globals "ethereum.homestead.fork_types" "Address". +Axiom ethereum_homestead_fork_types_imports_Bloom : + IsImported globals "ethereum.homestead.fork_types" "Bloom". +Axiom ethereum_homestead_fork_types_imports_Root : + IsImported globals "ethereum.homestead.fork_types" "Root". Definition hex_to_root : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/homestead/utils/message.v b/CoqOfPython/ethereum/homestead/utils/message.v index 16ddc16..9f53490 100644 --- a/CoqOfPython/ethereum/homestead/utils/message.v +++ b/CoqOfPython/ethereum/homestead/utils/message.v @@ -17,23 +17,33 @@ Introduction Message specific functions used in this homestead version of specification. ". -Axiom typing_imports : - AreImported globals "typing" [ "Optional"; "Union" ]. +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_homestead_fork_types_imports : - AreImported globals "ethereum.homestead.fork_types" [ "Address" ]. +Axiom ethereum_homestead_fork_types_imports_Address : + IsImported globals "ethereum.homestead.fork_types" "Address". -Axiom ethereum_homestead_state_imports : - AreImported globals "ethereum.homestead.state" [ "get_account" ]. +Axiom ethereum_homestead_state_imports_get_account : + IsImported globals "ethereum.homestead.state" "get_account". -Axiom ethereum_homestead_vm_imports : - AreImported globals "ethereum.homestead.vm" [ "Environment"; "Message" ]. +Axiom ethereum_homestead_vm_imports_Environment : + IsImported globals "ethereum.homestead.vm" "Environment". +Axiom ethereum_homestead_vm_imports_Message : + IsImported globals "ethereum.homestead.vm" "Message". -Axiom ethereum_homestead_utils_address_imports : - AreImported globals "ethereum.homestead.utils.address" [ "compute_contract_address" ]. +Axiom ethereum_homestead_utils_address_imports_compute_contract_address : + IsImported globals "ethereum.homestead.utils.address" "compute_contract_address". Definition prepare_message : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -80,7 +90,8 @@ Definition prepare_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let current_target := + let _ := M.assign_local (| + "current_target" , M.call (| M.get_name (| globals, "compute_contract_address" |), make_list [ @@ -104,17 +115,22 @@ Definition prepare_message : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let msg_data := + |) + |) in + let _ := M.assign_local (| + "msg_data" , M.call (| M.get_name (| globals, "Bytes" |), make_list [ Constant.bytes "" ], make_dict [] - |) in - let code := - M.get_name (| globals, "data" |) in + |) + |) in + let _ := M.assign_local (| + "code" , + M.get_name (| globals, "data" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -131,11 +147,16 @@ Definition prepare_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let current_target := - M.get_name (| globals, "target" |) in - let msg_data := - M.get_name (| globals, "data" |) in - let code := + let _ := M.assign_local (| + "current_target" , + M.get_name (| globals, "target" |) + |) in + let _ := M.assign_local (| + "msg_data" , + M.get_name (| globals, "data" |) + |) in + let _ := M.assign_local (| + "code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -143,7 +164,8 @@ Definition prepare_message : Value.t -> Value.t -> M := M.get_name (| globals, "target" |) ], make_dict [] - |), "code" |) in + |), "code" |) + |) in let _ := (* if *) M.if_then_else (| @@ -153,8 +175,10 @@ Definition prepare_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let code_address := - M.get_name (| globals, "target" |) in + let _ := M.assign_local (| + "code_address" , + M.get_name (| globals, "target" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/homestead/vm/__init__.v b/CoqOfPython/ethereum/homestead/vm/__init__.v index 6bc6543..3653dc8 100644 --- a/CoqOfPython/ethereum/homestead/vm/__init__.v +++ b/CoqOfPython/ethereum/homestead/vm/__init__.v @@ -18,26 +18,40 @@ The abstract computer which runs the code stored in an `.fork_types.Account`. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple"; "Union" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. - -Axiom ethereum_homestead_blocks_imports : - AreImported globals "ethereum.homestead.blocks" [ "Log" ]. - -Axiom ethereum_homestead_fork_types_imports : - AreImported globals "ethereum.homestead.fork_types" [ "Address" ]. - -Axiom ethereum_homestead_state_imports : - AreImported globals "ethereum.homestead.state" [ "State" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". + +Axiom ethereum_homestead_blocks_imports_Log : + IsImported globals "ethereum.homestead.blocks" "Log". + +Axiom ethereum_homestead_fork_types_imports_Address : + IsImported globals "ethereum.homestead.fork_types" "Address". + +Axiom ethereum_homestead_state_imports_State : + IsImported globals "ethereum.homestead.state" "State". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] diff --git a/CoqOfPython/ethereum/homestead/vm/exceptions.v b/CoqOfPython/ethereum/homestead/vm/exceptions.v index 5676be5..3c7fd2e 100644 --- a/CoqOfPython/ethereum/homestead/vm/exceptions.v +++ b/CoqOfPython/ethereum/homestead/vm/exceptions.v @@ -17,8 +17,8 @@ Introduction Exceptions which cause the EVM to halt exceptionally. ". -Axiom ethereum_exceptions_imports : - AreImported globals "ethereum.exceptions" [ "EthereumException" ]. +Axiom ethereum_exceptions_imports_EthereumException : + IsImported globals "ethereum.exceptions" "EthereumException". Definition ExceptionalHalt : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/homestead/vm/gas.v b/CoqOfPython/ethereum/homestead/vm/gas.v index 28b51e6..db0a564 100644 --- a/CoqOfPython/ethereum/homestead/vm/gas.v +++ b/CoqOfPython/ethereum/homestead/vm/gas.v @@ -17,32 +17,40 @@ Introduction EVM gas constants and calculators. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Tuple" ]. +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_trace_imports : - AreImported globals "ethereum.trace" [ "GasAndRefund"; "evm_trace" ]. +Axiom ethereum_trace_imports_GasAndRefund : + IsImported globals "ethereum.trace" "GasAndRefund". +Axiom ethereum_trace_imports_evm_trace : + IsImported globals "ethereum.trace" "evm_trace". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_homestead_fork_types_imports : - AreImported globals "ethereum.homestead.fork_types" [ "Address" ]. +Axiom ethereum_homestead_fork_types_imports_Address : + IsImported globals "ethereum.homestead.fork_types" "Address". -Axiom ethereum_homestead_state_imports : - AreImported globals "ethereum.homestead.state" [ "State"; "account_exists" ]. +Axiom ethereum_homestead_state_imports_State : + IsImported globals "ethereum.homestead.state" "State". +Axiom ethereum_homestead_state_imports_account_exists : + IsImported globals "ethereum.homestead.state" "account_exists". -Axiom ethereum_homestead_vm_imports : - AreImported globals "ethereum.homestead.vm" [ "Evm" ]. +Axiom ethereum_homestead_vm_imports_Evm : + IsImported globals "ethereum.homestead.vm" "Evm". -Axiom ethereum_homestead_vm_exceptions_imports : - AreImported globals "ethereum.homestead.vm.exceptions" [ "OutOfGasError" ]. +Axiom ethereum_homestead_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.homestead.vm.exceptions" "OutOfGasError". Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -508,7 +516,8 @@ Definition calculate_memory_gas_cost : Value.t -> Value.t -> M := total_gas_cost : `ethereum.base_types.Uint` The gas cost for storing data in memory. " in - let size_in_words := + let _ := M.assign_local (| + "size_in_words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -518,25 +527,32 @@ Definition calculate_memory_gas_cost : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let linear_cost := + |) + |) in + let _ := M.assign_local (| + "linear_cost" , BinOp.mult (| M.get_name (| globals, "size_in_words" |), M.get_name (| globals, "GAS_MEMORY" |) - |) in - let quadratic_cost := + |) + |) in + let _ := M.assign_local (| + "quadratic_cost" , BinOp.floor_div (| BinOp.pow (| M.get_name (| globals, "size_in_words" |), Constant.int 2 |), Constant.int 512 - |) in - let total_gas_cost := + |) + |) in + let _ := M.assign_local (| + "total_gas_cost" , BinOp.add (| M.get_name (| globals, "linear_cost" |), M.get_name (| globals, "quadratic_cost" |) - |) in + |) + |) in (* At stmt: unsupported node type: Try *) M.pure Constant.None_)). @@ -558,23 +574,28 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := ------- extend_memory: `ExtendMemory` " in - let size_to_extend := + let _ := M.assign_local (| + "size_to_extend" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in - let to_be_paid := + |) + |) in + let _ := M.assign_local (| + "to_be_paid" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in - let current_size := + |) + |) in + let _ := M.assign_local (| + "current_size" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -587,7 +608,8 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ], @@ -608,15 +630,18 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let before_size := + let _ := M.assign_local (| + "before_size" , M.call (| M.get_name (| globals, "ceil32" |), make_list [ M.get_name (| globals, "current_size" |) ], make_dict [] - |) in - let after_size := + |) + |) in + let _ := M.assign_local (| + "after_size" , M.call (| M.get_name (| globals, "ceil32" |), make_list [ @@ -638,7 +663,8 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -654,42 +680,46 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let size_to_extend := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "size_to_extend", BinOp.sub (| M.get_name (| globals, "after_size" |), M.get_name (| globals, "before_size" |) |) - BinOp.sub (| - M.get_name (| globals, "after_size" |), - M.get_name (| globals, "before_size" |) - |) in - let already_paid := + |) in + let _ := M.assign_local (| + "already_paid" , M.call (| M.get_name (| globals, "calculate_memory_gas_cost" |), make_list [ M.get_name (| globals, "before_size" |) ], make_dict [] - |) in - let total_cost := + |) + |) in + let _ := M.assign_local (| + "total_cost" , M.call (| M.get_name (| globals, "calculate_memory_gas_cost" |), make_list [ M.get_name (| globals, "after_size" |) ], make_dict [] - |) in - let to_be_paid := BinOp.add + |) + |) in + let _ := M.assign_op_local (| + BinOp.add, + "to_be_paid", BinOp.sub (| M.get_name (| globals, "total_cost" |), M.get_name (| globals, "already_paid" |) |) - BinOp.sub (| - M.get_name (| globals, "total_cost" |), - M.get_name (| globals, "already_paid" |) - |) in - let current_size := - M.get_name (| globals, "after_size" |) in + |) in + let _ := M.assign_local (| + "current_size" , + M.get_name (| globals, "after_size" |) + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -729,7 +759,8 @@ Definition calculate_message_call_gas : Value.t -> Value.t -> M := ------- message_call_gas: `MessageCallGas` " in - let create_gas_cost := + let _ := M.assign_local (| + "create_gas_cost" , (* if *) M.if_then_else (| M.call (| @@ -752,8 +783,10 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "GAS_NEW_ACCOUNT" |) - )) |) in - let transfer_gas_cost := + )) |) + |) in + let _ := M.assign_local (| + "transfer_gas_cost" , (* if *) M.if_then_else (| Compare.eq (| @@ -772,8 +805,10 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "GAS_CALL_VALUE" |) - )) |) in - let cost := + )) |) + |) in + let _ := M.assign_local (| + "cost" , BinOp.add (| BinOp.add (| BinOp.add (| @@ -783,8 +818,10 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_name (| globals, "create_gas_cost" |) |), M.get_name (| globals, "transfer_gas_cost" |) - |) in - let stipend := + |) + |) in + let _ := M.assign_local (| + "stipend" , (* if *) M.if_then_else (| Compare.eq (| @@ -800,7 +837,8 @@ BinOp.add (| M.get_name (| globals, "GAS_CALL_STIPEND" |), M.get_name (| globals, "gas" |) |) - )) |) in + )) |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "MessageCallGas" |), diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/__init__.v b/CoqOfPython/ethereum/homestead/vm/instructions/__init__.v index b5be76b..7a70aef 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/__init__.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/__init__.v @@ -20,44 +20,46 @@ implementations. (* At top_level_stmt: unsupported node type: Import *) -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict" ]. +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". -Axiom ethereum_homestead_vm_instructions_imports : - AreImported globals "ethereum.homestead.vm.instructions" [ "arithmetic" ]. +Axiom ethereum_homestead_vm_instructions_imports_arithmetic : + IsImported globals "ethereum.homestead.vm.instructions" "arithmetic". -Axiom ethereum_homestead_vm_instructions_imports : - AreImported globals "ethereum.homestead.vm.instructions" [ "bitwise" ]. +Axiom ethereum_homestead_vm_instructions_imports_bitwise : + IsImported globals "ethereum.homestead.vm.instructions" "bitwise". -Axiom ethereum_homestead_vm_instructions_imports : - AreImported globals "ethereum.homestead.vm.instructions" [ "block" ]. +Axiom ethereum_homestead_vm_instructions_imports_block : + IsImported globals "ethereum.homestead.vm.instructions" "block". -Axiom ethereum_homestead_vm_instructions_imports : - AreImported globals "ethereum.homestead.vm.instructions" [ "comparison" ]. +Axiom ethereum_homestead_vm_instructions_imports_comparison : + IsImported globals "ethereum.homestead.vm.instructions" "comparison". -Axiom ethereum_homestead_vm_instructions_imports : - AreImported globals "ethereum.homestead.vm.instructions" [ "control_flow" ]. +Axiom ethereum_homestead_vm_instructions_imports_control_flow : + IsImported globals "ethereum.homestead.vm.instructions" "control_flow". -Axiom ethereum_homestead_vm_instructions_imports : - AreImported globals "ethereum.homestead.vm.instructions" [ "environment" ]. +Axiom ethereum_homestead_vm_instructions_imports_environment : + IsImported globals "ethereum.homestead.vm.instructions" "environment". -Axiom ethereum_homestead_vm_instructions_imports : - AreImported globals "ethereum.homestead.vm.instructions" [ "keccak" ]. +Axiom ethereum_homestead_vm_instructions_imports_keccak : + IsImported globals "ethereum.homestead.vm.instructions" "keccak". -Axiom ethereum_homestead_vm_instructions_imports : - AreImported globals "ethereum.homestead.vm.instructions" [ "log" ]. +Axiom ethereum_homestead_vm_instructions_imports_log : + IsImported globals "ethereum.homestead.vm.instructions" "log". -Axiom ethereum_homestead_vm_instructions_imports : - AreImported globals "ethereum.homestead.vm.instructions" [ "memory" ]. +Axiom ethereum_homestead_vm_instructions_imports_memory : + IsImported globals "ethereum.homestead.vm.instructions" "memory". -Axiom ethereum_homestead_vm_instructions_imports : - AreImported globals "ethereum.homestead.vm.instructions" [ "stack" ]. +Axiom ethereum_homestead_vm_instructions_imports_stack : + IsImported globals "ethereum.homestead.vm.instructions" "stack". -Axiom ethereum_homestead_vm_instructions_imports : - AreImported globals "ethereum.homestead.vm.instructions" [ "storage" ]. +Axiom ethereum_homestead_vm_instructions_imports_storage : + IsImported globals "ethereum.homestead.vm.instructions" "storage". -Axiom ethereum_homestead_vm_instructions_imports : - AreImported globals "ethereum.homestead.vm.instructions" [ "system" ]. +Axiom ethereum_homestead_vm_instructions_imports_system : + IsImported globals "ethereum.homestead.vm.instructions" "system". Definition Ops : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/homestead/vm/instructions/arithmetic.v index 6c67fc6..1c889a2 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/arithmetic.v @@ -17,20 +17,38 @@ Introduction Implementations of the EVM Arithmetic instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U255_CEIL_VALUE"; "U256"; "U256_CEIL_VALUE"; "Uint" ]. +Axiom ethereum_base_types_imports_U255_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U255_CEIL_VALUE". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_U256_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U256_CEIL_VALUE". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "get_sign" ]. +Axiom ethereum_utils_numeric_imports_get_sign : + IsImported globals "ethereum.utils.numeric" "get_sign". -Axiom ethereum_homestead_vm_imports : - AreImported globals "ethereum.homestead.vm" [ "Evm" ]. +Axiom ethereum_homestead_vm_imports_Evm : + IsImported globals "ethereum.homestead.vm" "Evm". -Axiom ethereum_homestead_vm_gas_imports : - AreImported globals "ethereum.homestead.vm.gas" [ "GAS_EXPONENTIATION"; "GAS_EXPONENTIATION_PER_BYTE"; "GAS_LOW"; "GAS_MID"; "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_homestead_vm_gas_imports_GAS_EXPONENTIATION : + IsImported globals "ethereum.homestead.vm.gas" "GAS_EXPONENTIATION". +Axiom ethereum_homestead_vm_gas_imports_GAS_EXPONENTIATION_PER_BYTE : + IsImported globals "ethereum.homestead.vm.gas" "GAS_EXPONENTIATION_PER_BYTE". +Axiom ethereum_homestead_vm_gas_imports_GAS_LOW : + IsImported globals "ethereum.homestead.vm.gas" "GAS_LOW". +Axiom ethereum_homestead_vm_gas_imports_GAS_MID : + IsImported globals "ethereum.homestead.vm.gas" "GAS_MID". +Axiom ethereum_homestead_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.homestead.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_homestead_vm_gas_imports_charge_gas : + IsImported globals "ethereum.homestead.vm.gas" "charge_gas". -Axiom ethereum_homestead_vm_stack_imports : - AreImported globals "ethereum.homestead.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_homestead_vm_stack_imports_pop : + IsImported globals "ethereum.homestead.vm.stack" "pop". +Axiom ethereum_homestead_vm_stack_imports_push : + IsImported globals "ethereum.homestead.vm.stack" "push". Definition add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,22 +63,26 @@ Definition add : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -69,14 +91,16 @@ Definition add : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "x" |), "wrapping_add" |), make_list [ M.get_name (| globals, "y" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -105,22 +129,26 @@ Definition sub : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -129,14 +157,16 @@ Definition sub : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "x" |), "wrapping_sub" |), make_list [ M.get_name (| globals, "y" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -165,22 +195,26 @@ Definition mul : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -189,14 +223,16 @@ Definition mul : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "x" |), "wrapping_mul" |), make_list [ M.get_name (| globals, "y" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -225,22 +261,26 @@ Definition div : Value.t -> Value.t -> M := The current EVM frame. " in - let dividend := + let _ := M.assign_local (| + "dividend" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let divisor := + |) + |) in + let _ := M.assign_local (| + "divisor" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -258,22 +298,26 @@ Definition div : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let quotient := + let _ := M.assign_local (| + "quotient" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let quotient := + let _ := M.assign_local (| + "quotient" , BinOp.floor_div (| M.get_name (| globals, "dividend" |), M.get_name (| globals, "divisor" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -304,7 +348,8 @@ Definition sdiv : Value.t -> Value.t -> M := The current EVM frame. " in - let dividend := + let _ := M.assign_local (| + "dividend" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -315,8 +360,10 @@ Definition sdiv : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let divisor := + |) + |) in + let _ := M.assign_local (| + "divisor" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -327,7 +374,8 @@ Definition sdiv : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -345,8 +393,10 @@ Definition sdiv : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let quotient := - Constant.int 0 in + let _ := M.assign_local (| + "quotient" , + Constant.int 0 + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -367,12 +417,15 @@ Definition sdiv : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let quotient := - UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in + let _ := M.assign_local (| + "quotient" , + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let sign := + let _ := M.assign_local (| + "sign" , M.call (| M.get_name (| globals, "get_sign" |), make_list [ @@ -382,8 +435,10 @@ Definition sdiv : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let quotient := + |) + |) in + let _ := M.assign_local (| + "quotient" , BinOp.mult (| M.get_name (| globals, "sign" |), BinOp.floor_div (| @@ -402,7 +457,8 @@ Definition sdiv : Value.t -> Value.t -> M := make_dict [] |) |) - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -428,7 +484,7 @@ Definition sdiv : Value.t -> Value.t -> M := |) in M.pure Constant.None_)). -Definition mod : Value.t -> Value.t -> M := +Definition mod_ : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in let _ := Constant.str " @@ -441,22 +497,26 @@ Definition mod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -474,22 +534,26 @@ Definition mod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let remainder := + let _ := M.assign_local (| + "remainder" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let remainder := + let _ := M.assign_local (| + "remainder" , BinOp.mod_ (| M.get_name (| globals, "x" |), M.get_name (| globals, "y" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -520,7 +584,8 @@ Definition smod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -531,8 +596,10 @@ Definition smod : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -543,7 +610,8 @@ Definition smod : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -561,12 +629,15 @@ Definition smod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let remainder := - Constant.int 0 in + let _ := M.assign_local (| + "remainder" , + Constant.int 0 + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let remainder := + let _ := M.assign_local (| + "remainder" , BinOp.mult (| M.call (| M.get_name (| globals, "get_sign" |), @@ -591,7 +662,8 @@ Definition smod : Value.t -> Value.t -> M := make_dict [] |) |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -628,7 +700,8 @@ Definition addmod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -641,8 +714,10 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -655,8 +730,10 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let z := + |) + |) in + let _ := M.assign_local (| + "z" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -669,7 +746,8 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -687,18 +765,21 @@ Definition addmod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -711,7 +792,8 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -742,7 +824,8 @@ Definition mulmod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -755,8 +838,10 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -769,8 +854,10 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let z := + |) + |) in + let _ := M.assign_local (| + "z" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -783,7 +870,8 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -801,18 +889,21 @@ Definition mulmod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -825,7 +916,8 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -856,7 +948,8 @@ Definition exp : Value.t -> Value.t -> M := The current EVM frame. " in - let base := + let _ := M.assign_local (| + "base" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -869,8 +962,10 @@ Definition exp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exponent := + |) + |) in + let _ := M.assign_local (| + "exponent" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -883,21 +978,26 @@ Definition exp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exponent_bits := + |) + |) in + let _ := M.assign_local (| + "exponent_bits" , M.call (| M.get_field (| M.get_name (| globals, "exponent" |), "bit_length" |), make_list [], make_dict [] - |) in - let exponent_bytes := + |) + |) in + let _ := M.assign_local (| + "exponent_bytes" , BinOp.floor_div (| BinOp.add (| M.get_name (| globals, "exponent_bits" |), Constant.int 7 |), Constant.int 8 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -912,7 +1012,8 @@ Definition exp : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -927,7 +1028,8 @@ Definition exp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -956,22 +1058,26 @@ Definition signextend : Value.t -> Value.t -> M := The current EVM frame. " in - let byte_num := + let _ := M.assign_local (| + "byte_num" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -989,12 +1095,15 @@ Definition signextend : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := - M.get_name (| globals, "value" |) in + let _ := M.assign_local (| + "result" , + M.get_name (| globals, "value" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let value_bytes := + let _ := M.assign_local (| + "value_bytes" , M.call (| M.get_name (| globals, "bytes" |), make_list [ @@ -1005,8 +1114,10 @@ Definition signextend : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let value_bytes := + |) + |) in + let _ := M.assign_local (| + "value_bytes" , M.slice (| M.get_name (| globals, "value_bytes" |), BinOp.sub (| @@ -1021,15 +1132,18 @@ Definition signextend : Value.t -> Value.t -> M := |), Constant.None_, Constant.None_ - |) in - let sign_bit := + |) + |) in + let _ := M.assign_local (| + "sign_bit" , BinOp.r_shift (| M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), Constant.int 7 - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1039,26 +1153,31 @@ Definition signextend : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "value_bytes" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let num_bytes_prepend := + let _ := M.assign_local (| + "num_bytes_prepend" , BinOp.sub (| Constant.int 32, BinOp.add (| M.get_name (| globals, "byte_num" |), Constant.int 1 |) - |) in - let result := + |) + |) in + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -1079,7 +1198,8 @@ Definition signextend : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/bitwise.v b/CoqOfPython/ethereum/homestead/vm/instructions/bitwise.v index a42f204..9a886dd 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/bitwise.v @@ -17,17 +17,21 @@ Introduction Implementations of the EVM bitwise instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_homestead_vm_imports : - AreImported globals "ethereum.homestead.vm" [ "Evm" ]. +Axiom ethereum_homestead_vm_imports_Evm : + IsImported globals "ethereum.homestead.vm" "Evm". -Axiom ethereum_homestead_vm_gas_imports : - AreImported globals "ethereum.homestead.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_homestead_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.homestead.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_homestead_vm_gas_imports_charge_gas : + IsImported globals "ethereum.homestead.vm.gas" "charge_gas". -Axiom ethereum_homestead_vm_stack_imports : - AreImported globals "ethereum.homestead.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_homestead_vm_stack_imports_pop : + IsImported globals "ethereum.homestead.vm.stack" "pop". +Axiom ethereum_homestead_vm_stack_imports_push : + IsImported globals "ethereum.homestead.vm.stack" "push". Definition bitwise_and : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,22 +46,26 @@ Definition bitwise_and : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -97,22 +105,26 @@ Definition bitwise_or : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -152,22 +164,26 @@ Definition bitwise_xor : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -207,14 +223,16 @@ Definition bitwise_not : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -252,22 +270,26 @@ Definition get_byte : Value.t -> Value.t -> M := The current EVM frame. " in - let byte_index := + let _ := M.assign_local (| + "byte_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let word := + |) + |) in + let _ := M.assign_local (| + "word" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -285,43 +307,53 @@ Definition get_byte : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let extra_bytes_to_right := + let _ := M.assign_local (| + "extra_bytes_to_right" , BinOp.sub (| Constant.int 31, M.get_name (| globals, "byte_index" |) - |) in - let word := + |) + |) in + let _ := M.assign_local (| + "word" , BinOp.r_shift (| M.get_name (| globals, "word" |), BinOp.mult (| M.get_name (| globals, "extra_bytes_to_right" |), Constant.int 8 |) - |) in - let word := + |) + |) in + let _ := M.assign_local (| + "word" , BinOp.bit_and (| M.get_name (| globals, "word" |), Constant.int 255 - |) in - let result := + |) + |) in + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ M.get_name (| globals, "word" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/block.v b/CoqOfPython/ethereum/homestead/vm/instructions/block.v index adca5ee..b5d16dd 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/block.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/block.v @@ -17,17 +17,23 @@ Introduction Implementations of the EVM block instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_homestead_vm_imports : - AreImported globals "ethereum.homestead.vm" [ "Evm" ]. +Axiom ethereum_homestead_vm_imports_Evm : + IsImported globals "ethereum.homestead.vm" "Evm". -Axiom ethereum_homestead_vm_gas_imports : - AreImported globals "ethereum.homestead.vm.gas" [ "GAS_BASE"; "GAS_BLOCK_HASH"; "charge_gas" ]. +Axiom ethereum_homestead_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.homestead.vm.gas" "GAS_BASE". +Axiom ethereum_homestead_vm_gas_imports_GAS_BLOCK_HASH : + IsImported globals "ethereum.homestead.vm.gas" "GAS_BLOCK_HASH". +Axiom ethereum_homestead_vm_gas_imports_charge_gas : + IsImported globals "ethereum.homestead.vm.gas" "charge_gas". -Axiom ethereum_homestead_vm_stack_imports : - AreImported globals "ethereum.homestead.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_homestead_vm_stack_imports_pop : + IsImported globals "ethereum.homestead.vm.stack" "pop". +Axiom ethereum_homestead_vm_stack_imports_push : + IsImported globals "ethereum.homestead.vm.stack" "push". Definition block_hash : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,14 +48,16 @@ Definition block_hash : Value.t -> Value.t -> M := The current EVM frame. " in - let block_number := + let _ := M.assign_local (| + "block_number" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -78,19 +86,23 @@ Definition block_hash : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let hash := - Constant.bytes "00" in + let _ := M.assign_local (| + "hash" , + Constant.bytes "00" + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let hash := + let _ := M.assign_local (| + "hash" , M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), M.get_name (| globals, "block_number" |) |) |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/comparison.v b/CoqOfPython/ethereum/homestead/vm/instructions/comparison.v index 6adc1a7..dae8d81 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/comparison.v @@ -17,17 +17,21 @@ Introduction Implementations of the EVM Comparison instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_homestead_vm_imports : - AreImported globals "ethereum.homestead.vm" [ "Evm" ]. +Axiom ethereum_homestead_vm_imports_Evm : + IsImported globals "ethereum.homestead.vm" "Evm". -Axiom ethereum_homestead_vm_gas_imports : - AreImported globals "ethereum.homestead.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_homestead_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.homestead.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_homestead_vm_gas_imports_charge_gas : + IsImported globals "ethereum.homestead.vm.gas" "charge_gas". -Axiom ethereum_homestead_vm_stack_imports : - AreImported globals "ethereum.homestead.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_homestead_vm_stack_imports_pop : + IsImported globals "ethereum.homestead.vm.stack" "pop". +Axiom ethereum_homestead_vm_stack_imports_push : + IsImported globals "ethereum.homestead.vm.stack" "push". Definition less_than : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,22 +46,26 @@ Definition less_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -66,7 +74,8 @@ Definition less_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -76,7 +85,8 @@ Definition less_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -104,7 +114,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -115,8 +126,10 @@ Definition signed_less_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -127,7 +140,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -136,7 +150,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -146,7 +161,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -175,22 +191,26 @@ Definition greater_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -199,7 +219,8 @@ Definition greater_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -209,7 +230,8 @@ Definition greater_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -237,7 +259,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -248,8 +271,10 @@ Definition signed_greater_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -260,7 +285,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -269,7 +295,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -279,7 +306,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -308,22 +336,26 @@ Definition equal : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -332,7 +364,8 @@ Definition equal : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -342,7 +375,8 @@ Definition equal : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -371,14 +405,16 @@ Definition is_zero : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -387,7 +423,8 @@ Definition is_zero : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -397,7 +434,8 @@ Definition is_zero : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/control_flow.v b/CoqOfPython/ethereum/homestead/vm/instructions/control_flow.v index a0cc7cb..80e73c8 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/control_flow.v @@ -17,20 +17,32 @@ Introduction Implementations of the EVM control flow instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_homestead_vm_gas_imports : - AreImported globals "ethereum.homestead.vm.gas" [ "GAS_BASE"; "GAS_HIGH"; "GAS_JUMPDEST"; "GAS_MID"; "charge_gas" ]. +Axiom ethereum_homestead_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.homestead.vm.gas" "GAS_BASE". +Axiom ethereum_homestead_vm_gas_imports_GAS_HIGH : + IsImported globals "ethereum.homestead.vm.gas" "GAS_HIGH". +Axiom ethereum_homestead_vm_gas_imports_GAS_JUMPDEST : + IsImported globals "ethereum.homestead.vm.gas" "GAS_JUMPDEST". +Axiom ethereum_homestead_vm_gas_imports_GAS_MID : + IsImported globals "ethereum.homestead.vm.gas" "GAS_MID". +Axiom ethereum_homestead_vm_gas_imports_charge_gas : + IsImported globals "ethereum.homestead.vm.gas" "charge_gas". -Axiom ethereum_homestead_vm_imports : - AreImported globals "ethereum.homestead.vm" [ "Evm" ]. +Axiom ethereum_homestead_vm_imports_Evm : + IsImported globals "ethereum.homestead.vm" "Evm". -Axiom ethereum_homestead_vm_exceptions_imports : - AreImported globals "ethereum.homestead.vm.exceptions" [ "InvalidJumpDestError" ]. +Axiom ethereum_homestead_vm_exceptions_imports_InvalidJumpDestError : + IsImported globals "ethereum.homestead.vm.exceptions" "InvalidJumpDestError". -Axiom ethereum_homestead_vm_stack_imports : - AreImported globals "ethereum.homestead.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_homestead_vm_stack_imports_pop : + IsImported globals "ethereum.homestead.vm.stack" "pop". +Axiom ethereum_homestead_vm_stack_imports_push : + IsImported globals "ethereum.homestead.vm.stack" "push". Definition stop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -69,7 +81,8 @@ Definition jump : Value.t -> Value.t -> M := The current EVM frame. " in - let jump_dest := + let _ := M.assign_local (| + "jump_dest" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -82,7 +95,8 @@ Definition jump : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -132,7 +146,8 @@ Definition jumpi : Value.t -> Value.t -> M := The current EVM frame. " in - let jump_dest := + let _ := M.assign_local (| + "jump_dest" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -145,15 +160,18 @@ Definition jumpi : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let conditional_value := + |) + |) in + let _ := M.assign_local (| + "conditional_value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -171,11 +189,13 @@ Definition jumpi : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let destination := + let _ := M.assign_local (| + "destination" , BinOp.add (| M.get_field (| M.get_name (| globals, "evm" |), "pc" |), Constant.int 1 - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -192,8 +212,10 @@ Definition jumpi : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let destination := - M.get_name (| globals, "jump_dest" |) in + let _ := M.assign_local (| + "destination" , + M.get_name (| globals, "jump_dest" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/environment.v b/CoqOfPython/ethereum/homestead/vm/instructions/environment.v index ecb0f65..d7f3281 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/environment.v @@ -17,29 +17,47 @@ Introduction Implementations of the EVM environment related instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. - -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. - -Axiom ethereum_homestead_state_imports : - AreImported globals "ethereum.homestead.state" [ "get_account" ]. - -Axiom ethereum_homestead_utils_address_imports : - AreImported globals "ethereum.homestead.utils.address" [ "to_address" ]. - -Axiom ethereum_homestead_vm_memory_imports : - AreImported globals "ethereum.homestead.vm.memory" [ "buffer_read"; "memory_write" ]. - -Axiom ethereum_homestead_vm_imports : - AreImported globals "ethereum.homestead.vm" [ "Evm" ]. - -Axiom ethereum_homestead_vm_gas_imports : - AreImported globals "ethereum.homestead.vm.gas" [ "GAS_BALANCE"; "GAS_BASE"; "GAS_COPY"; "GAS_EXTERNAL"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. - -Axiom ethereum_homestead_vm_stack_imports : - AreImported globals "ethereum.homestead.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". + +Axiom ethereum_homestead_state_imports_get_account : + IsImported globals "ethereum.homestead.state" "get_account". + +Axiom ethereum_homestead_utils_address_imports_to_address : + IsImported globals "ethereum.homestead.utils.address" "to_address". + +Axiom ethereum_homestead_vm_memory_imports_buffer_read : + IsImported globals "ethereum.homestead.vm.memory" "buffer_read". +Axiom ethereum_homestead_vm_memory_imports_memory_write : + IsImported globals "ethereum.homestead.vm.memory" "memory_write". + +Axiom ethereum_homestead_vm_imports_Evm : + IsImported globals "ethereum.homestead.vm" "Evm". + +Axiom ethereum_homestead_vm_gas_imports_GAS_BALANCE : + IsImported globals "ethereum.homestead.vm.gas" "GAS_BALANCE". +Axiom ethereum_homestead_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.homestead.vm.gas" "GAS_BASE". +Axiom ethereum_homestead_vm_gas_imports_GAS_COPY : + IsImported globals "ethereum.homestead.vm.gas" "GAS_COPY". +Axiom ethereum_homestead_vm_gas_imports_GAS_EXTERNAL : + IsImported globals "ethereum.homestead.vm.gas" "GAS_EXTERNAL". +Axiom ethereum_homestead_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.homestead.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_homestead_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.homestead.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_homestead_vm_gas_imports_charge_gas : + IsImported globals "ethereum.homestead.vm.gas" "charge_gas". + +Axiom ethereum_homestead_vm_stack_imports_pop : + IsImported globals "ethereum.homestead.vm.stack" "pop". +Axiom ethereum_homestead_vm_stack_imports_push : + IsImported globals "ethereum.homestead.vm.stack" "push". Definition address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -95,7 +113,8 @@ Definition balance : Value.t -> Value.t -> M := The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -108,7 +127,8 @@ Definition balance : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -117,7 +137,8 @@ Definition balance : Value.t -> Value.t -> M := ], make_dict [] |) in - let balance := + let _ := M.assign_local (| + "balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -125,7 +146,8 @@ Definition balance : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -275,14 +297,16 @@ Definition calldataload : Value.t -> Value.t -> M := The current EVM frame. " in - let start_index := + let _ := M.assign_local (| + "start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -291,7 +315,8 @@ Definition calldataload : Value.t -> Value.t -> M := ], make_dict [] |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -306,7 +331,8 @@ Definition calldataload : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -391,31 +417,38 @@ Definition calldatacopy : Value.t -> Value.t -> M := The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let data_start_index := + |) + |) in + let _ := M.assign_local (| + "data_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -431,13 +464,17 @@ Definition calldatacopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -447,7 +484,8 @@ Definition calldatacopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -470,7 +508,8 @@ Definition calldatacopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -479,7 +518,8 @@ Definition calldatacopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -559,31 +599,38 @@ Definition codecopy : Value.t -> Value.t -> M := The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let code_start_index := + |) + |) in + let _ := M.assign_local (| + "code_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -599,13 +646,17 @@ Definition codecopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -615,7 +666,8 @@ Definition codecopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -638,7 +690,8 @@ Definition codecopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -647,7 +700,8 @@ Definition codecopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -718,7 +772,8 @@ Definition extcodesize : Value.t -> Value.t -> M := The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -731,7 +786,8 @@ Definition extcodesize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -740,7 +796,8 @@ Definition extcodesize : Value.t -> Value.t -> M := ], make_dict [] |) in - let codesize := + let _ := M.assign_local (| + "codesize" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -760,7 +817,8 @@ Definition extcodesize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -788,7 +846,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -801,32 +860,40 @@ Definition extcodecopy : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let memory_start_index := + |) + |) in + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let code_start_index := + |) + |) in + let _ := M.assign_local (| + "code_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -842,13 +909,17 @@ Definition extcodecopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -858,7 +929,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -881,7 +953,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let code := + let _ := M.assign_local (| + "code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -889,8 +962,10 @@ Definition extcodecopy : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |), "code" |) in - let value := + |), "code" |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -899,7 +974,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/keccak.v b/CoqOfPython/ethereum/homestead/vm/instructions/keccak.v index edb6298..6e22190 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/keccak.v @@ -17,26 +17,36 @@ Introduction Implementations of the EVM keccak instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_homestead_vm_imports : - AreImported globals "ethereum.homestead.vm" [ "Evm" ]. +Axiom ethereum_homestead_vm_imports_Evm : + IsImported globals "ethereum.homestead.vm" "Evm". -Axiom ethereum_homestead_vm_gas_imports : - AreImported globals "ethereum.homestead.vm.gas" [ "GAS_KECCAK256"; "GAS_KECCAK256_WORD"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_homestead_vm_gas_imports_GAS_KECCAK256 : + IsImported globals "ethereum.homestead.vm.gas" "GAS_KECCAK256". +Axiom ethereum_homestead_vm_gas_imports_GAS_KECCAK256_WORD : + IsImported globals "ethereum.homestead.vm.gas" "GAS_KECCAK256_WORD". +Axiom ethereum_homestead_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.homestead.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_homestead_vm_gas_imports_charge_gas : + IsImported globals "ethereum.homestead.vm.gas" "charge_gas". -Axiom ethereum_homestead_vm_memory_imports : - AreImported globals "ethereum.homestead.vm.memory" [ "memory_read_bytes" ]. +Axiom ethereum_homestead_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.homestead.vm.memory" "memory_read_bytes". -Axiom ethereum_homestead_vm_stack_imports : - AreImported globals "ethereum.homestead.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_homestead_vm_stack_imports_pop : + IsImported globals "ethereum.homestead.vm.stack" "pop". +Axiom ethereum_homestead_vm_stack_imports_push : + IsImported globals "ethereum.homestead.vm.stack" "push". Definition keccak : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -53,23 +63,28 @@ Definition keccak : Value.t -> Value.t -> M := The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -85,13 +100,17 @@ Definition keccak : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let word_gas_cost := + |) + |) in + let _ := M.assign_local (| + "word_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_KECCAK256_WORD" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -101,7 +120,8 @@ Definition keccak : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -124,7 +144,8 @@ Definition keccak : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let data := + let _ := M.assign_local (| + "data" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -133,15 +154,18 @@ Definition keccak : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in - let hash := + |) + |) in + let _ := M.assign_local (| + "hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "data" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/log.v b/CoqOfPython/ethereum/homestead/vm/instructions/log.v index 72dbe65..7780f07 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/log.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/log.v @@ -17,26 +17,34 @@ Introduction Implementations of the EVM logging instructions. ". -Axiom functools_imports : - AreImported globals "functools" [ "partial" ]. +Axiom functools_imports_partial : + IsImported globals "functools" "partial". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_homestead_blocks_imports : - AreImported globals "ethereum.homestead.blocks" [ "Log" ]. +Axiom ethereum_homestead_blocks_imports_Log : + IsImported globals "ethereum.homestead.blocks" "Log". -Axiom ethereum_homestead_vm_imports : - AreImported globals "ethereum.homestead.vm" [ "Evm" ]. +Axiom ethereum_homestead_vm_imports_Evm : + IsImported globals "ethereum.homestead.vm" "Evm". -Axiom ethereum_homestead_vm_gas_imports : - AreImported globals "ethereum.homestead.vm.gas" [ "GAS_LOG"; "GAS_LOG_DATA"; "GAS_LOG_TOPIC"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_homestead_vm_gas_imports_GAS_LOG : + IsImported globals "ethereum.homestead.vm.gas" "GAS_LOG". +Axiom ethereum_homestead_vm_gas_imports_GAS_LOG_DATA : + IsImported globals "ethereum.homestead.vm.gas" "GAS_LOG_DATA". +Axiom ethereum_homestead_vm_gas_imports_GAS_LOG_TOPIC : + IsImported globals "ethereum.homestead.vm.gas" "GAS_LOG_TOPIC". +Axiom ethereum_homestead_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.homestead.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_homestead_vm_gas_imports_charge_gas : + IsImported globals "ethereum.homestead.vm.gas" "charge_gas". -Axiom ethereum_homestead_vm_memory_imports : - AreImported globals "ethereum.homestead.vm.memory" [ "memory_read_bytes" ]. +Axiom ethereum_homestead_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.homestead.vm.memory" "memory_read_bytes". -Axiom ethereum_homestead_vm_stack_imports : - AreImported globals "ethereum.homestead.vm.stack" [ "pop" ]. +Axiom ethereum_homestead_vm_stack_imports_pop : + IsImported globals "ethereum.homestead.vm.stack" "pop". Definition log_n : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -55,24 +63,30 @@ Definition log_n : Value.t -> Value.t -> M := The number of topics to be included in the log entry. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let topics := - make_list [] in + |) + |) in + let _ := M.assign_local (| + "topics" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "_" |), @@ -84,7 +98,8 @@ Definition log_n : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let topic := + let _ := M.assign_local (| + "topic" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -95,7 +110,8 @@ Definition log_n : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "topics" |), "append" |), make_list [ @@ -109,7 +125,8 @@ Definition log_n : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let extend_memory := + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -119,7 +136,8 @@ Definition log_n : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -151,12 +169,14 @@ Definition log_n : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let log_entry := + let _ := M.assign_local (| + "log_entry" , M.call (| M.get_name (| globals, "Log" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "logs" |), BinOp.add (| diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/memory.v b/CoqOfPython/ethereum/homestead/vm/instructions/memory.v index e440cba..e8029f0 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/memory.v @@ -17,20 +17,32 @@ Introduction Implementations of the EVM Memory instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". -Axiom ethereum_homestead_vm_imports : - AreImported globals "ethereum.homestead.vm" [ "Evm" ]. +Axiom ethereum_homestead_vm_imports_Evm : + IsImported globals "ethereum.homestead.vm" "Evm". -Axiom ethereum_homestead_vm_gas_imports : - AreImported globals "ethereum.homestead.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_homestead_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.homestead.vm.gas" "GAS_BASE". +Axiom ethereum_homestead_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.homestead.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_homestead_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.homestead.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_homestead_vm_gas_imports_charge_gas : + IsImported globals "ethereum.homestead.vm.gas" "charge_gas". -Axiom ethereum_homestead_vm_memory_imports : - AreImported globals "ethereum.homestead.vm.memory" [ "memory_read_bytes"; "memory_write" ]. +Axiom ethereum_homestead_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.homestead.vm.memory" "memory_read_bytes". +Axiom ethereum_homestead_vm_memory_imports_memory_write : + IsImported globals "ethereum.homestead.vm.memory" "memory_write". -Axiom ethereum_homestead_vm_stack_imports : - AreImported globals "ethereum.homestead.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_homestead_vm_stack_imports_pop : + IsImported globals "ethereum.homestead.vm.stack" "pop". +Axiom ethereum_homestead_vm_stack_imports_push : + IsImported globals "ethereum.homestead.vm.stack" "push". Definition mstore : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -46,15 +58,18 @@ Definition mstore : Value.t -> Value.t -> M := The current EVM frame. " in - let start_position := + let _ := M.assign_local (| + "start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -65,8 +80,10 @@ Definition mstore : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -88,7 +105,8 @@ Definition mstore : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -138,23 +156,28 @@ Definition mstore8 : Value.t -> Value.t -> M := The current EVM frame. " in - let start_position := + let _ := M.assign_local (| + "start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -170,7 +193,8 @@ Definition mstore8 : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -190,7 +214,8 @@ Definition mstore8 : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let normalized_bytes_value := + let _ := M.assign_local (| + "normalized_bytes_value" , M.call (| M.get_name (| globals, "Bytes" |), make_list [ @@ -202,7 +227,8 @@ Definition mstore8 : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -231,15 +257,18 @@ Definition mload : Value.t -> Value.t -> M := The current EVM frame. " in - let start_position := + let _ := M.assign_local (| + "start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -255,7 +284,8 @@ Definition mload : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -275,7 +305,8 @@ Definition mload : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -296,7 +327,8 @@ Definition mload : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/stack.v b/CoqOfPython/ethereum/homestead/vm/instructions/stack.v index e1cc81e..dbfa9fb 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/stack.v @@ -17,26 +17,32 @@ Introduction Implementations of the EVM stack related instructions. ". -Axiom functools_imports : - AreImported globals "functools" [ "partial" ]. +Axiom functools_imports_partial : + IsImported globals "functools" "partial". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_homestead_vm_imports : - AreImported globals "ethereum.homestead.vm" [ "Evm"; "stack" ]. +Axiom ethereum_homestead_vm_imports_Evm : + IsImported globals "ethereum.homestead.vm" "Evm". +Axiom ethereum_homestead_vm_imports_stack : + IsImported globals "ethereum.homestead.vm" "stack". -Axiom ethereum_homestead_vm_exceptions_imports : - AreImported globals "ethereum.homestead.vm.exceptions" [ "StackUnderflowError" ]. +Axiom ethereum_homestead_vm_exceptions_imports_StackUnderflowError : + IsImported globals "ethereum.homestead.vm.exceptions" "StackUnderflowError". -Axiom ethereum_homestead_vm_gas_imports : - AreImported globals "ethereum.homestead.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_homestead_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.homestead.vm.gas" "GAS_BASE". +Axiom ethereum_homestead_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.homestead.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_homestead_vm_gas_imports_charge_gas : + IsImported globals "ethereum.homestead.vm.gas" "charge_gas". -Axiom ethereum_homestead_vm_memory_imports : - AreImported globals "ethereum.homestead.vm.memory" [ "buffer_read" ]. +Axiom ethereum_homestead_vm_memory_imports_buffer_read : + IsImported globals "ethereum.homestead.vm.memory" "buffer_read". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -98,7 +104,8 @@ Definition push_n : Value.t -> Value.t -> M := ], make_dict [] |) in - let data_to_push := + let _ := M.assign_local (| + "data_to_push" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -128,7 +135,8 @@ Definition push_n : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "stack" |), "push" |), make_list [ @@ -189,7 +197,8 @@ Definition dup_n : Value.t -> Value.t -> M := ], make_dict [] |) in - let data_to_duplicate := + let _ := M.assign_local (| + "data_to_duplicate" , M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| @@ -205,7 +214,8 @@ Definition dup_n : Value.t -> Value.t -> M := |), M.get_name (| globals, "item_number" |) |) - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "stack" |), "push" |), make_list [ diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/storage.v b/CoqOfPython/ethereum/homestead/vm/instructions/storage.v index bf4e8aa..aa3f335 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/storage.v @@ -17,17 +17,29 @@ Introduction Implementations of the EVM storage related instructions. ". -Axiom ethereum_homestead_state_imports : - AreImported globals "ethereum.homestead.state" [ "get_storage"; "set_storage" ]. +Axiom ethereum_homestead_state_imports_get_storage : + IsImported globals "ethereum.homestead.state" "get_storage". +Axiom ethereum_homestead_state_imports_set_storage : + IsImported globals "ethereum.homestead.state" "set_storage". -Axiom ethereum_homestead_vm_imports : - AreImported globals "ethereum.homestead.vm" [ "Evm" ]. +Axiom ethereum_homestead_vm_imports_Evm : + IsImported globals "ethereum.homestead.vm" "Evm". -Axiom ethereum_homestead_vm_gas_imports : - AreImported globals "ethereum.homestead.vm.gas" [ "GAS_SLOAD"; "GAS_STORAGE_CLEAR_REFUND"; "GAS_STORAGE_SET"; "GAS_STORAGE_UPDATE"; "charge_gas" ]. +Axiom ethereum_homestead_vm_gas_imports_GAS_SLOAD : + IsImported globals "ethereum.homestead.vm.gas" "GAS_SLOAD". +Axiom ethereum_homestead_vm_gas_imports_GAS_STORAGE_CLEAR_REFUND : + IsImported globals "ethereum.homestead.vm.gas" "GAS_STORAGE_CLEAR_REFUND". +Axiom ethereum_homestead_vm_gas_imports_GAS_STORAGE_SET : + IsImported globals "ethereum.homestead.vm.gas" "GAS_STORAGE_SET". +Axiom ethereum_homestead_vm_gas_imports_GAS_STORAGE_UPDATE : + IsImported globals "ethereum.homestead.vm.gas" "GAS_STORAGE_UPDATE". +Axiom ethereum_homestead_vm_gas_imports_charge_gas : + IsImported globals "ethereum.homestead.vm.gas" "charge_gas". -Axiom ethereum_homestead_vm_stack_imports : - AreImported globals "ethereum.homestead.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_homestead_vm_stack_imports_pop : + IsImported globals "ethereum.homestead.vm.stack" "pop". +Axiom ethereum_homestead_vm_stack_imports_push : + IsImported globals "ethereum.homestead.vm.stack" "push". Definition sload : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,7 +54,8 @@ Definition sload : Value.t -> Value.t -> M := The current EVM frame. " in - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -53,7 +66,8 @@ Definition sload : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -62,7 +76,8 @@ Definition sload : Value.t -> Value.t -> M := ], make_dict [] |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "get_storage" |), make_list [ @@ -71,7 +86,8 @@ Definition sload : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -99,7 +115,8 @@ Definition sstore : Value.t -> Value.t -> M := The current EVM frame. " in - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -110,16 +127,20 @@ Definition sstore : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in - let new_value := + |) + |) in + let _ := M.assign_local (| + "new_value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let current_value := + |) + |) in + let _ := M.assign_local (| + "current_value" , M.call (| M.get_name (| globals, "get_storage" |), make_list [ @@ -128,7 +149,8 @@ Definition sstore : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -146,13 +168,17 @@ Definition sstore : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let gas_cost := - M.get_name (| globals, "GAS_STORAGE_SET" |) in + let _ := M.assign_local (| + "gas_cost" , + M.get_name (| globals, "GAS_STORAGE_SET" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let gas_cost := - M.get_name (| globals, "GAS_STORAGE_UPDATE" |) in + let _ := M.assign_local (| + "gas_cost" , + M.get_name (| globals, "GAS_STORAGE_UPDATE" |) + |) in M.pure Constant.None_ )) |) in let _ := diff --git a/CoqOfPython/ethereum/homestead/vm/instructions/system.v b/CoqOfPython/ethereum/homestead/vm/instructions/system.v index f88541e..924bdf2 100644 --- a/CoqOfPython/ethereum/homestead/vm/instructions/system.v +++ b/CoqOfPython/ethereum/homestead/vm/instructions/system.v @@ -17,29 +17,63 @@ Introduction Implementations of the EVM system related instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_homestead_fork_types_imports : - AreImported globals "ethereum.homestead.fork_types" [ "Address" ]. +Axiom ethereum_homestead_fork_types_imports_Address : + IsImported globals "ethereum.homestead.fork_types" "Address". -Axiom ethereum_homestead_state_imports : - AreImported globals "ethereum.homestead.state" [ "account_has_code_or_nonce"; "get_account"; "increment_nonce"; "set_account_balance" ]. +Axiom ethereum_homestead_state_imports_account_has_code_or_nonce : + IsImported globals "ethereum.homestead.state" "account_has_code_or_nonce". +Axiom ethereum_homestead_state_imports_get_account : + IsImported globals "ethereum.homestead.state" "get_account". +Axiom ethereum_homestead_state_imports_increment_nonce : + IsImported globals "ethereum.homestead.state" "increment_nonce". +Axiom ethereum_homestead_state_imports_set_account_balance : + IsImported globals "ethereum.homestead.state" "set_account_balance". -Axiom ethereum_homestead_utils_address_imports : - AreImported globals "ethereum.homestead.utils.address" [ "compute_contract_address"; "to_address" ]. +Axiom ethereum_homestead_utils_address_imports_compute_contract_address : + IsImported globals "ethereum.homestead.utils.address" "compute_contract_address". +Axiom ethereum_homestead_utils_address_imports_to_address : + IsImported globals "ethereum.homestead.utils.address" "to_address". -Axiom ethereum_homestead_vm_imports : - AreImported globals "ethereum.homestead.vm" [ "Evm"; "Message"; "incorporate_child_on_error"; "incorporate_child_on_success" ]. +Axiom ethereum_homestead_vm_imports_Evm : + IsImported globals "ethereum.homestead.vm" "Evm". +Axiom ethereum_homestead_vm_imports_Message : + IsImported globals "ethereum.homestead.vm" "Message". +Axiom ethereum_homestead_vm_imports_incorporate_child_on_error : + IsImported globals "ethereum.homestead.vm" "incorporate_child_on_error". +Axiom ethereum_homestead_vm_imports_incorporate_child_on_success : + IsImported globals "ethereum.homestead.vm" "incorporate_child_on_success". -Axiom ethereum_homestead_vm_gas_imports : - AreImported globals "ethereum.homestead.vm.gas" [ "GAS_CALL"; "GAS_CREATE"; "GAS_ZERO"; "REFUND_SELF_DESTRUCT"; "calculate_gas_extend_memory"; "calculate_message_call_gas"; "charge_gas" ]. +Axiom ethereum_homestead_vm_gas_imports_GAS_CALL : + IsImported globals "ethereum.homestead.vm.gas" "GAS_CALL". +Axiom ethereum_homestead_vm_gas_imports_GAS_CREATE : + IsImported globals "ethereum.homestead.vm.gas" "GAS_CREATE". +Axiom ethereum_homestead_vm_gas_imports_GAS_ZERO : + IsImported globals "ethereum.homestead.vm.gas" "GAS_ZERO". +Axiom ethereum_homestead_vm_gas_imports_REFUND_SELF_DESTRUCT : + IsImported globals "ethereum.homestead.vm.gas" "REFUND_SELF_DESTRUCT". +Axiom ethereum_homestead_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.homestead.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_homestead_vm_gas_imports_calculate_message_call_gas : + IsImported globals "ethereum.homestead.vm.gas" "calculate_message_call_gas". +Axiom ethereum_homestead_vm_gas_imports_charge_gas : + IsImported globals "ethereum.homestead.vm.gas" "charge_gas". -Axiom ethereum_homestead_vm_memory_imports : - AreImported globals "ethereum.homestead.vm.memory" [ "memory_read_bytes"; "memory_write" ]. +Axiom ethereum_homestead_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.homestead.vm.memory" "memory_read_bytes". +Axiom ethereum_homestead_vm_memory_imports_memory_write : + IsImported globals "ethereum.homestead.vm.memory" "memory_write". -Axiom ethereum_homestead_vm_stack_imports : - AreImported globals "ethereum.homestead.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_homestead_vm_stack_imports_pop : + IsImported globals "ethereum.homestead.vm.stack" "pop". +Axiom ethereum_homestead_vm_stack_imports_push : + IsImported globals "ethereum.homestead.vm.stack" "push". Definition create : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -53,31 +87,38 @@ Definition create : Value.t -> Value.t -> M := The current EVM frame. " in (* At stmt: unsupported node type: ImportFrom *) - let endowment := + let _ := M.assign_local (| + "endowment" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_size := + |) + |) in + let _ := M.assign_local (| + "memory_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -87,7 +128,8 @@ Definition create : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -99,8 +141,10 @@ Definition create : Value.t -> Value.t -> M := ], make_dict [] |) in - let create_message_gas := - M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) in + let _ := M.assign_local (| + "create_message_gas" , + M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), M.call (| @@ -119,9 +163,12 @@ Definition create : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let sender_address := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in - let sender := + let _ := M.assign_local (| + "sender_address" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + |) in + let _ := M.assign_local (| + "sender" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -129,8 +176,10 @@ Definition create : Value.t -> Value.t -> M := M.get_name (| globals, "sender_address" |) ], make_dict [] - |) in - let contract_address := + |) + |) in + let _ := M.assign_local (| + "contract_address" , M.call (| M.get_name (| globals, "compute_contract_address" |), make_list [ @@ -145,7 +194,8 @@ Definition create : Value.t -> Value.t -> M := |), "nonce" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -246,7 +296,8 @@ Definition create : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let call_data := + let _ := M.assign_local (| + "call_data" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -255,7 +306,8 @@ Definition create : Value.t -> Value.t -> M := M.get_name (| globals, "memory_size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "increment_nonce" |), make_list [ @@ -264,13 +316,16 @@ Definition create : Value.t -> Value.t -> M := ], make_dict [] |) in - let child_message := + let _ := M.assign_local (| + "child_message" , M.call (| M.get_name (| globals, "Message" |), make_list [], make_dict [] - |) in - let child_evm := + |) + |) in + let _ := M.assign_local (| + "child_evm" , M.call (| M.get_name (| globals, "process_create_message" |), make_list [ @@ -278,7 +333,8 @@ Definition create : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -356,23 +412,28 @@ Definition return_ : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let memory_start_position := + let _ := M.assign_local (| + "memory_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_size := + |) + |) in + let _ := M.assign_local (| + "memory_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -382,7 +443,8 @@ Definition return_ : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -467,7 +529,8 @@ Definition generic_call : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let call_data := + let _ := M.assign_local (| + "call_data" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -476,8 +539,10 @@ Definition generic_call : Value.t -> Value.t -> M := M.get_name (| globals, "memory_input_size" |) ], make_dict [] - |) in - let code := + |) + |) in + let _ := M.assign_local (| + "code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -485,14 +550,18 @@ Definition generic_call : Value.t -> Value.t -> M := M.get_name (| globals, "code_address" |) ], make_dict [] - |), "code" |) in - let child_message := + |), "code" |) + |) in + let _ := M.assign_local (| + "child_message" , M.call (| M.get_name (| globals, "Message" |), make_list [], make_dict [] - |) in - let child_evm := + |) + |) in + let _ := M.assign_local (| + "child_evm" , M.call (| M.get_name (| globals, "process_message" |), make_list [ @@ -500,7 +569,8 @@ Definition generic_call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -556,7 +626,8 @@ Definition generic_call : Value.t -> Value.t -> M := |) in M.pure Constant.None_ )) |) in - let actual_output_size := + let _ := M.assign_local (| + "actual_output_size" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -576,7 +647,8 @@ Definition generic_call : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -604,7 +676,8 @@ Definition call : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -617,8 +690,10 @@ Definition call : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let to := + |) + |) in + let _ := M.assign_local (| + "to" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -631,48 +706,60 @@ Definition call : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -683,8 +770,10 @@ Definition call : Value.t -> Value.t -> M := ] ], make_dict [] - |) in - let message_call_gas := + |) + |) in + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -694,7 +783,8 @@ Definition call : Value.t -> Value.t -> M := M.get_name (| globals, "value" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -714,7 +804,8 @@ Definition call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let sender_balance := + let _ := M.assign_local (| + "sender_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -722,7 +813,8 @@ Definition call : Value.t -> Value.t -> M := M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := (* if *) M.if_then_else (| @@ -791,7 +883,8 @@ Definition callcode : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -804,8 +897,10 @@ Definition callcode : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let code_address := + |) + |) in + let _ := M.assign_local (| + "code_address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -818,50 +913,64 @@ Definition callcode : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let to := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "to" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -872,8 +981,10 @@ Definition callcode : Value.t -> Value.t -> M := ] ], make_dict [] - |) in - let message_call_gas := + |) + |) in + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -883,7 +994,8 @@ Definition callcode : Value.t -> Value.t -> M := M.get_name (| globals, "value" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -903,7 +1015,8 @@ Definition callcode : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let sender_balance := + let _ := M.assign_local (| + "sender_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -911,7 +1024,8 @@ Definition callcode : Value.t -> Value.t -> M := M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := (* if *) M.if_then_else (| @@ -980,7 +1094,8 @@ Definition selfdestruct : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let beneficiary := + let _ := M.assign_local (| + "beneficiary" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -993,15 +1108,24 @@ Definition selfdestruct : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let gas_cost := - M.get_name (| globals, "GAS_ZERO" |) in - let originator := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in - let refunded_accounts := - M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in - let parent_evm := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "parent_evm" |) in + |) + |) in + let _ := M.assign_local (| + "gas_cost" , + M.get_name (| globals, "GAS_ZERO" |) + |) in + let _ := M.assign_local (| + "originator" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + |) in + let _ := M.assign_local (| + "refunded_accounts" , + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) + |) in + let _ := M.assign_local (| + "parent_evm" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "parent_evm" |) + |) in let _ := M.while (| Compare.is_not (| @@ -1016,8 +1140,10 @@ Definition selfdestruct : Value.t -> Value.t -> M := ], make_dict [] |) in - let parent_evm := - M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in + let _ := M.assign_local (| + "parent_evm" , + M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -1051,7 +1177,8 @@ Definition selfdestruct : Value.t -> Value.t -> M := ], make_dict [] |) in - let beneficiary_balance := + let _ := M.assign_local (| + "beneficiary_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1059,8 +1186,10 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_name (| globals, "beneficiary" |) ], make_dict [] - |), "balance" |) in - let originator_balance := + |), "balance" |) + |) in + let _ := M.assign_local (| + "originator_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1068,7 +1197,8 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_name (| globals, "originator" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -1121,7 +1251,8 @@ Definition delegatecall : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -1134,8 +1265,10 @@ Definition delegatecall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let code_address := + |) + |) in + let _ := M.assign_local (| + "code_address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1148,40 +1281,50 @@ Definition delegatecall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1192,7 +1335,8 @@ Definition delegatecall : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ diff --git a/CoqOfPython/ethereum/homestead/vm/interpreter.v b/CoqOfPython/ethereum/homestead/vm/interpreter.v index f1c68be..e60282d 100644 --- a/CoqOfPython/ethereum/homestead/vm/interpreter.v +++ b/CoqOfPython/ethereum/homestead/vm/interpreter.v @@ -17,47 +17,95 @@ Introduction A straightforward interpreter that executes EVM code. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Optional"; "Set"; "Tuple" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. - -Axiom ethereum_trace_imports : - AreImported globals "ethereum.trace" [ "EvmStop"; "OpEnd"; "OpException"; "OpStart"; "PrecompileEnd"; "PrecompileStart"; "TransactionEnd"; "evm_trace" ]. - -Axiom ethereum_homestead_blocks_imports : - AreImported globals "ethereum.homestead.blocks" [ "Log" ]. - -Axiom ethereum_homestead_fork_types_imports : - AreImported globals "ethereum.homestead.fork_types" [ "Address" ]. - -Axiom ethereum_homestead_state_imports : - AreImported globals "ethereum.homestead.state" [ "account_has_code_or_nonce"; "begin_transaction"; "commit_transaction"; "destroy_storage"; "move_ether"; "rollback_transaction"; "set_code"; "touch_account" ]. - -Axiom ethereum_homestead_vm_imports : - AreImported globals "ethereum.homestead.vm" [ "Message" ]. - -Axiom ethereum_homestead_vm_gas_imports : - AreImported globals "ethereum.homestead.vm.gas" [ "GAS_CODE_DEPOSIT"; "charge_gas" ]. - -Axiom ethereum_homestead_vm_precompiled_contracts_mapping_imports : - AreImported globals "ethereum.homestead.vm.precompiled_contracts.mapping" [ "PRE_COMPILED_CONTRACTS" ]. - -Axiom ethereum_homestead_vm_imports : - AreImported globals "ethereum.homestead.vm" [ "Environment"; "Evm" ]. - -Axiom ethereum_homestead_vm_exceptions_imports : - AreImported globals "ethereum.homestead.vm.exceptions" [ "AddressCollision"; "ExceptionalHalt"; "InvalidOpcode"; "StackDepthLimitError" ]. - -Axiom ethereum_homestead_vm_instructions_imports : - AreImported globals "ethereum.homestead.vm.instructions" [ "Ops"; "op_implementation" ]. - -Axiom ethereum_homestead_vm_runtime_imports : - AreImported globals "ethereum.homestead.vm.runtime" [ "get_valid_jump_destinations" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_trace_imports_EvmStop : + IsImported globals "ethereum.trace" "EvmStop". +Axiom ethereum_trace_imports_OpEnd : + IsImported globals "ethereum.trace" "OpEnd". +Axiom ethereum_trace_imports_OpException : + IsImported globals "ethereum.trace" "OpException". +Axiom ethereum_trace_imports_OpStart : + IsImported globals "ethereum.trace" "OpStart". +Axiom ethereum_trace_imports_PrecompileEnd : + IsImported globals "ethereum.trace" "PrecompileEnd". +Axiom ethereum_trace_imports_PrecompileStart : + IsImported globals "ethereum.trace" "PrecompileStart". +Axiom ethereum_trace_imports_TransactionEnd : + IsImported globals "ethereum.trace" "TransactionEnd". +Axiom ethereum_trace_imports_evm_trace : + IsImported globals "ethereum.trace" "evm_trace". + +Axiom ethereum_homestead_blocks_imports_Log : + IsImported globals "ethereum.homestead.blocks" "Log". + +Axiom ethereum_homestead_fork_types_imports_Address : + IsImported globals "ethereum.homestead.fork_types" "Address". + +Axiom ethereum_homestead_state_imports_account_has_code_or_nonce : + IsImported globals "ethereum.homestead.state" "account_has_code_or_nonce". +Axiom ethereum_homestead_state_imports_begin_transaction : + IsImported globals "ethereum.homestead.state" "begin_transaction". +Axiom ethereum_homestead_state_imports_commit_transaction : + IsImported globals "ethereum.homestead.state" "commit_transaction". +Axiom ethereum_homestead_state_imports_destroy_storage : + IsImported globals "ethereum.homestead.state" "destroy_storage". +Axiom ethereum_homestead_state_imports_move_ether : + IsImported globals "ethereum.homestead.state" "move_ether". +Axiom ethereum_homestead_state_imports_rollback_transaction : + IsImported globals "ethereum.homestead.state" "rollback_transaction". +Axiom ethereum_homestead_state_imports_set_code : + IsImported globals "ethereum.homestead.state" "set_code". +Axiom ethereum_homestead_state_imports_touch_account : + IsImported globals "ethereum.homestead.state" "touch_account". + +Axiom ethereum_homestead_vm_imports_Message : + IsImported globals "ethereum.homestead.vm" "Message". + +Axiom ethereum_homestead_vm_gas_imports_GAS_CODE_DEPOSIT : + IsImported globals "ethereum.homestead.vm.gas" "GAS_CODE_DEPOSIT". +Axiom ethereum_homestead_vm_gas_imports_charge_gas : + IsImported globals "ethereum.homestead.vm.gas" "charge_gas". + +Axiom ethereum_homestead_vm_precompiled_contracts_mapping_imports_PRE_COMPILED_CONTRACTS : + IsImported globals "ethereum.homestead.vm.precompiled_contracts.mapping" "PRE_COMPILED_CONTRACTS". + +Axiom ethereum_homestead_vm_imports_Environment : + IsImported globals "ethereum.homestead.vm" "Environment". +Axiom ethereum_homestead_vm_imports_Evm : + IsImported globals "ethereum.homestead.vm" "Evm". + +Axiom ethereum_homestead_vm_exceptions_imports_AddressCollision : + IsImported globals "ethereum.homestead.vm.exceptions" "AddressCollision". +Axiom ethereum_homestead_vm_exceptions_imports_ExceptionalHalt : + IsImported globals "ethereum.homestead.vm.exceptions" "ExceptionalHalt". +Axiom ethereum_homestead_vm_exceptions_imports_InvalidOpcode : + IsImported globals "ethereum.homestead.vm.exceptions" "InvalidOpcode". +Axiom ethereum_homestead_vm_exceptions_imports_StackDepthLimitError : + IsImported globals "ethereum.homestead.vm.exceptions" "StackDepthLimitError". + +Axiom ethereum_homestead_vm_instructions_imports_Ops : + IsImported globals "ethereum.homestead.vm.instructions" "Ops". +Axiom ethereum_homestead_vm_instructions_imports_op_implementation : + IsImported globals "ethereum.homestead.vm.instructions" "op_implementation". + +Axiom ethereum_homestead_vm_runtime_imports_get_valid_jump_destinations : + IsImported globals "ethereum.homestead.vm.runtime" "get_valid_jump_destinations". Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -114,7 +162,8 @@ Definition process_message_call : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let is_collision := + let _ := M.assign_local (| + "is_collision" , M.call (| M.get_name (| globals, "account_has_code_or_nonce" |), make_list [ @@ -122,7 +171,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "message" |), "current_target" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -169,7 +219,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "process_create_message" |), make_list [ @@ -177,13 +228,15 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "process_message" |), make_list [ @@ -191,7 +244,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := @@ -201,32 +255,43 @@ Definition process_message_call : Value.t -> Value.t -> M := (* then *) ltac:(M.monadic ( (* At stmt: unsupported node type: AnnAssign *) - let accounts_to_delete := + let _ := M.assign_local (| + "accounts_to_delete" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let refund_counter := + |) + |) in + let _ := M.assign_local (| + "refund_counter" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let logs := - M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in - let accounts_to_delete := - M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in - let refund_counter := - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |) in + let _ := M.assign_local (| + "logs" , + M.get_field (| M.get_name (| globals, "evm" |), "logs" |) + |) in + let _ := M.assign_local (| + "accounts_to_delete" , + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) + |) in + let _ := M.assign_local (| + "refund_counter" , + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |) + |) in M.pure Constant.None_ )) |) in - let tx_end := + let _ := M.assign_local (| + "tx_end" , M.call (| M.get_name (| globals, "TransactionEnd" |), make_list [ @@ -238,7 +303,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "error" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "evm_trace" |), make_list [ @@ -289,7 +355,8 @@ Definition process_create_message : Value.t -> Value.t -> M := ], make_dict [] |) in - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "process_message" |), make_list [ @@ -297,16 +364,20 @@ Definition process_create_message : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), (* then *) ltac:(M.monadic ( - let contract_code := - M.get_field (| M.get_name (| globals, "evm" |), "output" |) in - let contract_code_gas := + let _ := M.assign_local (| + "contract_code" , + M.get_field (| M.get_name (| globals, "evm" |), "output" |) + |) in + let _ := M.assign_local (| + "contract_code_gas" , BinOp.mult (| M.call (| M.get_name (| globals, "len" |), @@ -316,7 +387,8 @@ Definition process_create_message : Value.t -> Value.t -> M := make_dict [] |), M.get_name (| globals, "GAS_CODE_DEPOSIT" |) - |) in + |) + |) in (* At stmt: unsupported node type: Try *) M.pure Constant.None_ (* else *) @@ -418,7 +490,8 @@ Definition process_message : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "execute_code" |), make_list [ @@ -426,7 +499,8 @@ Definition process_message : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -475,22 +549,28 @@ Definition execute_code : Value.t -> Value.t -> M := evm: `ethereum.vm.EVM` Items containing execution specific objects " in - let code := - M.get_field (| M.get_name (| globals, "message" |), "code" |) in - let valid_jump_destinations := + let _ := M.assign_local (| + "code" , + M.get_field (| M.get_name (| globals, "message" |), "code" |) + |) in + let _ := M.assign_local (| + "valid_jump_destinations" , M.call (| M.get_name (| globals, "get_valid_jump_destinations" |), make_list [ M.get_name (| globals, "code" |) ], make_dict [] - |) in - let evm := + |) + |) in + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "Evm" |), make_list [], make_dict [] - |) in + |) + |) in (* At stmt: unsupported node type: Try *) let _ := M.return_ (| M.get_name (| globals, "evm" |) diff --git a/CoqOfPython/ethereum/homestead/vm/memory.v b/CoqOfPython/ethereum/homestead/vm/memory.v index c36e579..e10df21 100644 --- a/CoqOfPython/ethereum/homestead/vm/memory.v +++ b/CoqOfPython/ethereum/homestead/vm/memory.v @@ -17,11 +17,15 @@ Introduction EVM memory operations. ". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "right_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_right_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "right_pad_zero_bytes". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". Definition memory_write : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/__init__.v index 0649114..f7f7382 100644 --- a/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/__init__.v +++ b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/__init__.v @@ -18,8 +18,8 @@ Addresses of precompiled contracts and mappings to their implementations. ". -Axiom ethereum_homestead_utils_hexadecimal_imports : - AreImported globals "ethereum.homestead.utils.hexadecimal" [ "hex_to_address" ]. +Axiom ethereum_homestead_utils_hexadecimal_imports_hex_to_address : + IsImported globals "ethereum.homestead.utils.hexadecimal" "hex_to_address". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS" ] diff --git a/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/ecrecover.v index ef0e625..e4781ca 100644 --- a/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/ecrecover.v @@ -17,26 +17,32 @@ Introduction Implementation of the ECRECOVER precompiled contract. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_crypto_elliptic_curve_imports : - AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. +Axiom ethereum_crypto_elliptic_curve_imports_SECP256K1N : + IsImported globals "ethereum.crypto.elliptic_curve" "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_imports_secp256k1_recover : + IsImported globals "ethereum.crypto.elliptic_curve" "secp256k1_recover". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_left_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "left_pad_zero_bytes". -Axiom ethereum_homestead_vm_imports : - AreImported globals "ethereum.homestead.vm" [ "Evm" ]. +Axiom ethereum_homestead_vm_imports_Evm : + IsImported globals "ethereum.homestead.vm" "Evm". -Axiom ethereum_homestead_vm_gas_imports : - AreImported globals "ethereum.homestead.vm.gas" [ "GAS_ECRECOVER"; "charge_gas" ]. +Axiom ethereum_homestead_vm_gas_imports_GAS_ECRECOVER : + IsImported globals "ethereum.homestead.vm.gas" "GAS_ECRECOVER". +Axiom ethereum_homestead_vm_gas_imports_charge_gas : + IsImported globals "ethereum.homestead.vm.gas" "charge_gas". -Axiom ethereum_homestead_vm_memory_imports : - AreImported globals "ethereum.homestead.vm.memory" [ "buffer_read" ]. +Axiom ethereum_homestead_vm_memory_imports_buffer_read : + IsImported globals "ethereum.homestead.vm.memory" "buffer_read". Definition ecrecover : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -50,8 +56,10 @@ Definition ecrecover : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -60,7 +68,8 @@ Definition ecrecover : Value.t -> Value.t -> M := ], make_dict [] |) in - let message_hash_bytes := + let _ := M.assign_local (| + "message_hash_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -81,16 +90,20 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let message_hash := + |) + |) in + let _ := M.assign_local (| + "message_hash" , M.call (| M.get_name (| globals, "Hash32" |), make_list [ M.get_name (| globals, "message_hash_bytes" |) ], make_dict [] - |) in - let v := + |) + |) in + let _ := M.assign_local (| + "v" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -117,8 +130,10 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let r := + |) + |) in + let _ := M.assign_local (| + "r" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -145,8 +160,10 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let s := + |) + |) in + let _ := M.assign_local (| + "s" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -173,7 +190,8 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -250,7 +268,8 @@ Definition ecrecover : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: Try *) - let address := + let _ := M.assign_local (| + "address" , M.slice (| M.call (| M.get_name (| globals, "keccak256" |), @@ -262,8 +281,10 @@ Definition ecrecover : Value.t -> Value.t -> M := Constant.int 12, Constant.int 32, Constant.None_ - |) in - let padded_address := + |) + |) in + let _ := M.assign_local (| + "padded_address" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -271,7 +292,8 @@ Definition ecrecover : Value.t -> Value.t -> M := Constant.int 32 ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.get_name (| globals, "padded_address" |) diff --git a/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/identity.v index b5a7610..1f02089 100644 --- a/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/identity.v +++ b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/identity.v @@ -17,17 +17,21 @@ Introduction Implementation of the `IDENTITY` precompiled contract. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_homestead_vm_imports : - AreImported globals "ethereum.homestead.vm" [ "Evm" ]. +Axiom ethereum_homestead_vm_imports_Evm : + IsImported globals "ethereum.homestead.vm" "Evm". -Axiom ethereum_homestead_vm_gas_imports : - AreImported globals "ethereum.homestead.vm.gas" [ "GAS_IDENTITY"; "GAS_IDENTITY_WORD"; "charge_gas" ]. +Axiom ethereum_homestead_vm_gas_imports_GAS_IDENTITY : + IsImported globals "ethereum.homestead.vm.gas" "GAS_IDENTITY". +Axiom ethereum_homestead_vm_gas_imports_GAS_IDENTITY_WORD : + IsImported globals "ethereum.homestead.vm.gas" "GAS_IDENTITY_WORD". +Axiom ethereum_homestead_vm_gas_imports_charge_gas : + IsImported globals "ethereum.homestead.vm.gas" "charge_gas". Definition identity : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -40,9 +44,12 @@ Definition identity : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let word_count := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "word_count" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -64,7 +71,8 @@ Definition identity : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ diff --git a/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/mapping.v index e083ecf..317a774 100644 --- a/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/mapping.v +++ b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/mapping.v @@ -17,25 +17,33 @@ Introduction Mapping of precompiled contracts their implementations. ". -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict" ]. - -Axiom ethereum_homestead_fork_types_imports : - AreImported globals "ethereum.homestead.fork_types" [ "Address" ]. - -Axiom ethereum_homestead_vm_precompiled_contracts_imports : - AreImported globals "ethereum.homestead.vm.precompiled_contracts" [ "ECRECOVER_ADDRESS"; "IDENTITY_ADDRESS"; "RIPEMD160_ADDRESS"; "SHA256_ADDRESS" ]. - -Axiom ethereum_homestead_vm_precompiled_contracts_ecrecover_imports : - AreImported globals "ethereum.homestead.vm.precompiled_contracts.ecrecover" [ "ecrecover" ]. - -Axiom ethereum_homestead_vm_precompiled_contracts_identity_imports : - AreImported globals "ethereum.homestead.vm.precompiled_contracts.identity" [ "identity" ]. - -Axiom ethereum_homestead_vm_precompiled_contracts_ripemd160_imports : - AreImported globals "ethereum.homestead.vm.precompiled_contracts.ripemd160" [ "ripemd160" ]. - -Axiom ethereum_homestead_vm_precompiled_contracts_sha256_imports : - AreImported globals "ethereum.homestead.vm.precompiled_contracts.sha256" [ "sha256" ]. +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". + +Axiom ethereum_homestead_fork_types_imports_Address : + IsImported globals "ethereum.homestead.fork_types" "Address". + +Axiom ethereum_homestead_vm_precompiled_contracts_imports_ECRECOVER_ADDRESS : + IsImported globals "ethereum.homestead.vm.precompiled_contracts" "ECRECOVER_ADDRESS". +Axiom ethereum_homestead_vm_precompiled_contracts_imports_IDENTITY_ADDRESS : + IsImported globals "ethereum.homestead.vm.precompiled_contracts" "IDENTITY_ADDRESS". +Axiom ethereum_homestead_vm_precompiled_contracts_imports_RIPEMD160_ADDRESS : + IsImported globals "ethereum.homestead.vm.precompiled_contracts" "RIPEMD160_ADDRESS". +Axiom ethereum_homestead_vm_precompiled_contracts_imports_SHA256_ADDRESS : + IsImported globals "ethereum.homestead.vm.precompiled_contracts" "SHA256_ADDRESS". + +Axiom ethereum_homestead_vm_precompiled_contracts_ecrecover_imports_ecrecover : + IsImported globals "ethereum.homestead.vm.precompiled_contracts.ecrecover" "ecrecover". + +Axiom ethereum_homestead_vm_precompiled_contracts_identity_imports_identity : + IsImported globals "ethereum.homestead.vm.precompiled_contracts.identity" "identity". + +Axiom ethereum_homestead_vm_precompiled_contracts_ripemd160_imports_ripemd160 : + IsImported globals "ethereum.homestead.vm.precompiled_contracts.ripemd160" "ripemd160". + +Axiom ethereum_homestead_vm_precompiled_contracts_sha256_imports_sha256 : + IsImported globals "ethereum.homestead.vm.precompiled_contracts.sha256" "sha256". (* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/ripemd160.v index 1ad1433..659b238 100644 --- a/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/ripemd160.v +++ b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/ripemd160.v @@ -19,20 +19,24 @@ Implementation of the `RIPEMD160` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_left_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "left_pad_zero_bytes". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_homestead_vm_imports : - AreImported globals "ethereum.homestead.vm" [ "Evm" ]. +Axiom ethereum_homestead_vm_imports_Evm : + IsImported globals "ethereum.homestead.vm" "Evm". -Axiom ethereum_homestead_vm_gas_imports : - AreImported globals "ethereum.homestead.vm.gas" [ "GAS_RIPEMD160"; "GAS_RIPEMD160_WORD"; "charge_gas" ]. +Axiom ethereum_homestead_vm_gas_imports_GAS_RIPEMD160 : + IsImported globals "ethereum.homestead.vm.gas" "GAS_RIPEMD160". +Axiom ethereum_homestead_vm_gas_imports_GAS_RIPEMD160_WORD : + IsImported globals "ethereum.homestead.vm.gas" "GAS_RIPEMD160_WORD". +Axiom ethereum_homestead_vm_gas_imports_charge_gas : + IsImported globals "ethereum.homestead.vm.gas" "charge_gas". Definition ripemd160 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,9 +49,12 @@ Definition ripemd160 : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let word_count := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "word_count" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -69,7 +76,8 @@ Definition ripemd160 : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -84,7 +92,8 @@ Definition ripemd160 : Value.t -> Value.t -> M := ], make_dict [] |) in - let hash_bytes := + let _ := M.assign_local (| + "hash_bytes" , M.call (| M.get_field (| M.call (| M.get_field (| M.get_name (| globals, "hashlib" |), "new" |), @@ -96,8 +105,10 @@ Definition ripemd160 : Value.t -> Value.t -> M := |), "digest" |), make_list [], make_dict [] - |) in - let padded_hash := + |) + |) in + let _ := M.assign_local (| + "padded_hash" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -105,7 +116,8 @@ Definition ripemd160 : Value.t -> Value.t -> M := Constant.int 32 ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.get_name (| globals, "padded_hash" |) diff --git a/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/sha256.v index c6bc0bc..e8dbb14 100644 --- a/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/sha256.v +++ b/CoqOfPython/ethereum/homestead/vm/precompiled_contracts/sha256.v @@ -19,17 +19,21 @@ Implementation of the `SHA256` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_homestead_vm_imports : - AreImported globals "ethereum.homestead.vm" [ "Evm" ]. +Axiom ethereum_homestead_vm_imports_Evm : + IsImported globals "ethereum.homestead.vm" "Evm". -Axiom ethereum_homestead_vm_gas_imports : - AreImported globals "ethereum.homestead.vm.gas" [ "GAS_SHA256"; "GAS_SHA256_WORD"; "charge_gas" ]. +Axiom ethereum_homestead_vm_gas_imports_GAS_SHA256 : + IsImported globals "ethereum.homestead.vm.gas" "GAS_SHA256". +Axiom ethereum_homestead_vm_gas_imports_GAS_SHA256_WORD : + IsImported globals "ethereum.homestead.vm.gas" "GAS_SHA256_WORD". +Axiom ethereum_homestead_vm_gas_imports_charge_gas : + IsImported globals "ethereum.homestead.vm.gas" "charge_gas". Definition sha256 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,9 +46,12 @@ Definition sha256 : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let word_count := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "word_count" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -66,7 +73,8 @@ Definition sha256 : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ diff --git a/CoqOfPython/ethereum/homestead/vm/runtime.v b/CoqOfPython/ethereum/homestead/vm/runtime.v index fe4477f..d8d8829 100644 --- a/CoqOfPython/ethereum/homestead/vm/runtime.v +++ b/CoqOfPython/ethereum/homestead/vm/runtime.v @@ -17,14 +17,14 @@ Introduction Runtime related operations used while executing EVM code. ". -Axiom typing_imports : - AreImported globals "typing" [ "Set" ]. +Axiom typing_imports_Set : + IsImported globals "typing" "Set". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_homestead_vm_instructions_imports : - AreImported globals "ethereum.homestead.vm.instructions" [ "Ops" ]. +Axiom ethereum_homestead_vm_instructions_imports_Ops : + IsImported globals "ethereum.homestead.vm.instructions" "Ops". Definition get_valid_jump_destinations : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -50,20 +50,24 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := valid_jump_destinations: `Set[Uint]` The set of valid jump destinations in the code. " in - let valid_jump_destinations := + let _ := M.assign_local (| + "valid_jump_destinations" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let pc := + |) + |) in + let _ := M.assign_local (| + "pc" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in let _ := M.while (| Compare.lt (| @@ -114,17 +118,21 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let push_data_size := + let _ := M.assign_local (| + "push_data_size" , BinOp.add (| BinOp.sub (| M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) |), Constant.int 1 - |) in - let pc := BinOp.add + |) + |) in + let _ := M.assign_op_local (| + BinOp.add, + "pc", M.get_name (| globals, "push_data_size" |) - M.get_name (| globals, "push_data_size" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -132,9 +140,11 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - let pc := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "pc", Constant.int 1 - Constant.int 1 in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/homestead/vm/stack.v b/CoqOfPython/ethereum/homestead/vm/stack.v index caaa1d4..e8c3493 100644 --- a/CoqOfPython/ethereum/homestead/vm/stack.v +++ b/CoqOfPython/ethereum/homestead/vm/stack.v @@ -17,14 +17,16 @@ Introduction Implementation of the stack operators for the EVM. ". -Axiom typing_imports : - AreImported globals "typing" [ "List" ]. +Axiom typing_imports_List : + IsImported globals "typing" "List". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_homestead_vm_exceptions_imports : - AreImported globals "ethereum.homestead.vm.exceptions" [ "StackOverflowError"; "StackUnderflowError" ]. +Axiom ethereum_homestead_vm_exceptions_imports_StackOverflowError : + IsImported globals "ethereum.homestead.vm.exceptions" "StackOverflowError". +Axiom ethereum_homestead_vm_exceptions_imports_StackUnderflowError : + IsImported globals "ethereum.homestead.vm.exceptions" "StackUnderflowError". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/istanbul/__init__.v b/CoqOfPython/ethereum/istanbul/__init__.v index 2a28913..41dba6f 100644 --- a/CoqOfPython/ethereum/istanbul/__init__.v +++ b/CoqOfPython/ethereum/istanbul/__init__.v @@ -9,8 +9,8 @@ adds a cryptographic primitive, and introduces an instruction to fetch the current chain identifier. ". -Axiom ethereum_fork_criteria_imports : - AreImported globals "ethereum.fork_criteria" [ "ByBlockNumber" ]. +Axiom ethereum_fork_criteria_imports_ByBlockNumber : + IsImported globals "ethereum.fork_criteria" "ByBlockNumber". Definition FORK_CRITERIA : Value.t := M.run ltac:(M.monadic ( M.call (| diff --git a/CoqOfPython/ethereum/istanbul/blocks.v b/CoqOfPython/ethereum/istanbul/blocks.v index ea63e2d..09c7599 100644 --- a/CoqOfPython/ethereum/istanbul/blocks.v +++ b/CoqOfPython/ethereum/istanbul/blocks.v @@ -14,23 +14,37 @@ history of all state transitions that have happened since the genesis of the chain. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Tuple" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes8"; "Bytes32"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. - -Axiom ethereum_istanbul_fork_types_imports : - AreImported globals "ethereum.istanbul.fork_types" [ "Address"; "Bloom"; "Root" ]. - -Axiom ethereum_istanbul_transactions_imports : - AreImported globals "ethereum.istanbul.transactions" [ "Transaction" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes8 : + IsImported globals "ethereum.base_types" "Bytes8". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". + +Axiom ethereum_istanbul_fork_types_imports_Address : + IsImported globals "ethereum.istanbul.fork_types" "Address". +Axiom ethereum_istanbul_fork_types_imports_Bloom : + IsImported globals "ethereum.istanbul.fork_types" "Bloom". +Axiom ethereum_istanbul_fork_types_imports_Root : + IsImported globals "ethereum.istanbul.fork_types" "Root". + +Axiom ethereum_istanbul_transactions_imports_Transaction : + IsImported globals "ethereum.istanbul.transactions" "Transaction". Definition Header : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/istanbul/bloom.v b/CoqOfPython/ethereum/istanbul/bloom.v index f2f7123..9f67f06 100644 --- a/CoqOfPython/ethereum/istanbul/bloom.v +++ b/CoqOfPython/ethereum/istanbul/bloom.v @@ -21,20 +21,20 @@ for efficient searching of logs by address and/or topic, by rapidly eliminating blocks and receipts from their search. ". -Axiom typing_imports : - AreImported globals "typing" [ "Tuple" ]. +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_istanbul_blocks_imports : - AreImported globals "ethereum.istanbul.blocks" [ "Log" ]. +Axiom ethereum_istanbul_blocks_imports_Log : + IsImported globals "ethereum.istanbul.blocks" "Log". -Axiom ethereum_istanbul_fork_types_imports : - AreImported globals "ethereum.istanbul.fork_types" [ "Bloom" ]. +Axiom ethereum_istanbul_fork_types_imports_Bloom : + IsImported globals "ethereum.istanbul.fork_types" "Bloom". Definition add_to_bloom : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -53,20 +53,23 @@ Definition add_to_bloom : Value.t -> Value.t -> M := bloom_entry : An entry which is to be added to bloom filter. " in - let hash := + let _ := M.assign_local (| + "hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "bloom_entry" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "idx" |), make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ], ltac:(M.monadic ( - let bit_to_set := + let _ := M.assign_local (| + "bit_to_set" , BinOp.bit_and (| M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), @@ -84,18 +87,24 @@ Definition add_to_bloom : Value.t -> Value.t -> M := make_dict [] |), Constant.int 2047 - |) in - let bit_index := + |) + |) in + let _ := M.assign_local (| + "bit_index" , BinOp.sub (| Constant.int 2047, M.get_name (| globals, "bit_to_set" |) - |) in - let byte_index := + |) + |) in + let _ := M.assign_local (| + "byte_index" , BinOp.floor_div (| M.get_name (| globals, "bit_index" |), Constant.int 8 - |) in - let bit_value := + |) + |) in + let _ := M.assign_local (| + "bit_value" , BinOp.l_shift (| Constant.int 1, BinOp.sub (| @@ -105,7 +114,8 @@ Definition add_to_bloom : Value.t -> Value.t -> M := Constant.int 8 |) |) - |) in + |) + |) in let _ := M.assign (| M.get_subscript (| M.get_name (| globals, "bloom" |), diff --git a/CoqOfPython/ethereum/istanbul/fork.v b/CoqOfPython/ethereum/istanbul/fork.v index 39cc961..ce58ae7 100644 --- a/CoqOfPython/ethereum/istanbul/fork.v +++ b/CoqOfPython/ethereum/istanbul/fork.v @@ -17,62 +17,120 @@ Introduction Entry point for the Ethereum specification. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Bytes0" ]. - -Axiom ethereum_crypto_elliptic_curve_imports : - AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. - -Axiom ethereum_ethash_imports : - AreImported globals "ethereum.ethash" [ "dataset_size"; "generate_cache"; "hashimoto_light" ]. - -Axiom ethereum_exceptions_imports : - AreImported globals "ethereum.exceptions" [ "InvalidBlock" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U64"; "U256"; "U256_CEIL_VALUE"; "Bytes"; "Uint" ]. - -Axiom ethereum_istanbul_imports : - AreImported globals "ethereum.istanbul" [ "vm" ]. - -Axiom ethereum_istanbul_blocks_imports : - AreImported globals "ethereum.istanbul.blocks" [ "Block"; "Header"; "Log"; "Receipt" ]. - -Axiom ethereum_istanbul_bloom_imports : - AreImported globals "ethereum.istanbul.bloom" [ "logs_bloom" ]. - -Axiom ethereum_istanbul_fork_types_imports : - AreImported globals "ethereum.istanbul.fork_types" [ "Address"; "Bloom"; "Root" ]. - -Axiom ethereum_istanbul_state_imports : - AreImported globals "ethereum.istanbul.state" [ "State"; "account_exists_and_is_empty"; "create_ether"; "destroy_account"; "get_account"; "increment_nonce"; "set_account_balance"; "state_root" ]. - -Axiom ethereum_istanbul_transactions_imports : - AreImported globals "ethereum.istanbul.transactions" [ "TX_BASE_COST"; "TX_CREATE_COST"; "TX_DATA_COST_PER_NON_ZERO"; "TX_DATA_COST_PER_ZERO"; "Transaction" ]. - -Axiom ethereum_istanbul_trie_imports : - AreImported globals "ethereum.istanbul.trie" [ "Trie"; "root"; "trie_set" ]. - -Axiom ethereum_istanbul_utils_message_imports : - AreImported globals "ethereum.istanbul.utils.message" [ "prepare_message" ]. - -Axiom ethereum_istanbul_vm_interpreter_imports : - AreImported globals "ethereum.istanbul.vm.interpreter" [ "process_message_call" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". + +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". + +Axiom ethereum_crypto_elliptic_curve_imports_SECP256K1N : + IsImported globals "ethereum.crypto.elliptic_curve" "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_imports_secp256k1_recover : + IsImported globals "ethereum.crypto.elliptic_curve" "secp256k1_recover". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". + +Axiom ethereum_ethash_imports_dataset_size : + IsImported globals "ethereum.ethash" "dataset_size". +Axiom ethereum_ethash_imports_generate_cache : + IsImported globals "ethereum.ethash" "generate_cache". +Axiom ethereum_ethash_imports_hashimoto_light : + IsImported globals "ethereum.ethash" "hashimoto_light". + +Axiom ethereum_exceptions_imports_InvalidBlock : + IsImported globals "ethereum.exceptions" "InvalidBlock". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U64 : + IsImported globals "ethereum.base_types" "U64". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_U256_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U256_CEIL_VALUE". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_istanbul_imports_vm : + IsImported globals "ethereum.istanbul" "vm". + +Axiom ethereum_istanbul_blocks_imports_Block : + IsImported globals "ethereum.istanbul.blocks" "Block". +Axiom ethereum_istanbul_blocks_imports_Header : + IsImported globals "ethereum.istanbul.blocks" "Header". +Axiom ethereum_istanbul_blocks_imports_Log : + IsImported globals "ethereum.istanbul.blocks" "Log". +Axiom ethereum_istanbul_blocks_imports_Receipt : + IsImported globals "ethereum.istanbul.blocks" "Receipt". + +Axiom ethereum_istanbul_bloom_imports_logs_bloom : + IsImported globals "ethereum.istanbul.bloom" "logs_bloom". + +Axiom ethereum_istanbul_fork_types_imports_Address : + IsImported globals "ethereum.istanbul.fork_types" "Address". +Axiom ethereum_istanbul_fork_types_imports_Bloom : + IsImported globals "ethereum.istanbul.fork_types" "Bloom". +Axiom ethereum_istanbul_fork_types_imports_Root : + IsImported globals "ethereum.istanbul.fork_types" "Root". + +Axiom ethereum_istanbul_state_imports_State : + IsImported globals "ethereum.istanbul.state" "State". +Axiom ethereum_istanbul_state_imports_account_exists_and_is_empty : + IsImported globals "ethereum.istanbul.state" "account_exists_and_is_empty". +Axiom ethereum_istanbul_state_imports_create_ether : + IsImported globals "ethereum.istanbul.state" "create_ether". +Axiom ethereum_istanbul_state_imports_destroy_account : + IsImported globals "ethereum.istanbul.state" "destroy_account". +Axiom ethereum_istanbul_state_imports_get_account : + IsImported globals "ethereum.istanbul.state" "get_account". +Axiom ethereum_istanbul_state_imports_increment_nonce : + IsImported globals "ethereum.istanbul.state" "increment_nonce". +Axiom ethereum_istanbul_state_imports_set_account_balance : + IsImported globals "ethereum.istanbul.state" "set_account_balance". +Axiom ethereum_istanbul_state_imports_state_root : + IsImported globals "ethereum.istanbul.state" "state_root". + +Axiom ethereum_istanbul_transactions_imports_TX_BASE_COST : + IsImported globals "ethereum.istanbul.transactions" "TX_BASE_COST". +Axiom ethereum_istanbul_transactions_imports_TX_CREATE_COST : + IsImported globals "ethereum.istanbul.transactions" "TX_CREATE_COST". +Axiom ethereum_istanbul_transactions_imports_TX_DATA_COST_PER_NON_ZERO : + IsImported globals "ethereum.istanbul.transactions" "TX_DATA_COST_PER_NON_ZERO". +Axiom ethereum_istanbul_transactions_imports_TX_DATA_COST_PER_ZERO : + IsImported globals "ethereum.istanbul.transactions" "TX_DATA_COST_PER_ZERO". +Axiom ethereum_istanbul_transactions_imports_Transaction : + IsImported globals "ethereum.istanbul.transactions" "Transaction". + +Axiom ethereum_istanbul_trie_imports_Trie : + IsImported globals "ethereum.istanbul.trie" "Trie". +Axiom ethereum_istanbul_trie_imports_root : + IsImported globals "ethereum.istanbul.trie" "root". +Axiom ethereum_istanbul_trie_imports_trie_set : + IsImported globals "ethereum.istanbul.trie" "trie_set". + +Axiom ethereum_istanbul_utils_message_imports_prepare_message : + IsImported globals "ethereum.istanbul.utils.message" "prepare_message". + +Axiom ethereum_istanbul_vm_interpreter_imports_process_message_call : + IsImported globals "ethereum.istanbul.vm.interpreter" "process_message_call". Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -190,13 +248,15 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := recent_block_hashes : `List[Hash32]` Hashes of the recent 256 blocks in order of increasing block number. " in - let recent_blocks := + let _ := M.assign_local (| + "recent_blocks" , M.slice (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |), Constant.None_, Constant.None_ - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -220,15 +280,19 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let recent_block_hashes := - make_list [] in + let _ := M.assign_local (| + "recent_block_hashes" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "block" |), M.get_name (| globals, "recent_blocks" |), ltac:(M.monadic ( - let prev_block_hash := - M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in + let _ := M.assign_local (| + "prev_block_hash" , + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), make_list [ @@ -242,7 +306,8 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let most_recent_block_hash := + let _ := M.assign_local (| + "most_recent_block_hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -258,7 +323,8 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), make_list [ @@ -295,11 +361,13 @@ Definition state_transition : Value.t -> Value.t -> M := block : Block to apply to `chain`. " in - let parent_header := + let _ := M.assign_local (| + "parent_header" , M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 1 |) - |), "header" |) in + |), "header" |) + |) in let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ @@ -317,7 +385,8 @@ Definition state_transition : Value.t -> Value.t -> M := ], make_dict [] |) in - let apply_body_output := + let _ := M.assign_local (| + "apply_body_output" , M.call (| M.get_name (| globals, "apply_body" |), make_list [ @@ -339,7 +408,8 @@ Definition state_transition : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "chain" |), "chain_id" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -453,11 +523,13 @@ Definition validate_header : Value.t -> Value.t -> M := parent_header : Parent Header of the header to check for correctness " in - let parent_has_ommers := + let _ := M.assign_local (| + "parent_has_ommers" , Compare.not_eq (| M.get_field (| M.get_name (| globals, "parent_header" |), "ommers_hash" |), M.get_name (| globals, "EMPTY_OMMER_HASH" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -515,7 +587,8 @@ Definition validate_header : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_difficulty := + let _ := M.assign_local (| + "block_difficulty" , M.call (| M.get_name (| globals, "calculate_block_difficulty" |), make_list [ @@ -526,7 +599,8 @@ Definition validate_header : Value.t -> Value.t -> M := M.get_name (| globals, "parent_has_ommers" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -538,7 +612,8 @@ Definition validate_header : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_parent_hash := + let _ := M.assign_local (| + "block_parent_hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -551,7 +626,8 @@ Definition validate_header : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -597,7 +673,8 @@ Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := hash : `Hash32` The PoW valid rlp hash of the passed in header. " in - let header_data_without_pow_artefacts := + let _ := M.assign_local (| + "header_data_without_pow_artefacts" , make_list [ M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |); M.get_field (| M.get_name (| globals, "header" |), "ommers_hash" |); @@ -612,7 +689,8 @@ Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "header" |), "gas_used" |); M.get_field (| M.get_name (| globals, "header" |), "timestamp" |); M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) - ] in + ] + |) in let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), @@ -641,22 +719,26 @@ Definition validate_proof_of_work : Value.t -> Value.t -> M := header : Header of interest. " in - let header_hash := + let _ := M.assign_local (| + "header_hash" , M.call (| M.get_name (| globals, "generate_header_hash_for_pow" |), make_list [ M.get_name (| globals, "header" |) ], make_dict [] - |) in - let cache := + |) + |) in + let _ := M.assign_local (| + "cache" , M.call (| M.get_name (| globals, "generate_cache" |), make_list [ M.get_field (| M.get_name (| globals, "header" |), "number" |) ], make_dict [] - |) in + |) + |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "mix_digest" |); M.get_name (| globals, "result" |) ], M.call (| @@ -745,7 +827,8 @@ Definition check_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_address := + let _ := M.assign_local (| + "sender_address" , M.call (| M.get_name (| globals, "recover_sender" |), make_list [ @@ -753,7 +836,8 @@ Definition check_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "tx" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "sender_address" |) |) in @@ -782,12 +866,14 @@ Definition make_receipt : Value.t -> Value.t -> M := receipt : The receipt for the transaction. " in - let receipt := + let _ := M.assign_local (| + "receipt" , M.call (| M.get_name (| globals, "Receipt" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "receipt" |) |) in @@ -846,8 +932,10 @@ Definition apply_body : Value.t -> Value.t -> M := apply_body_output : `ApplyBodyOutput` Output of applying the block body to the state. " in - let gas_available := - M.get_name (| globals, "block_gas_limit" |) in + let _ := M.assign_local (| + "gas_available" , + M.get_name (| globals, "block_gas_limit" |) + |) in (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) @@ -883,7 +971,8 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_address := + let _ := M.assign_local (| + "sender_address" , M.call (| M.get_name (| globals, "check_transaction" |), make_list [ @@ -892,13 +981,16 @@ Definition apply_body : Value.t -> Value.t -> M := M.get_name (| globals, "chain_id" |) ], make_dict [] - |) in - let env := + |) + |) in + let _ := M.assign_local (| + "env" , M.call (| M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |); M.get_name (| globals, "error" |) ], M.call (| @@ -910,10 +1002,13 @@ Definition apply_body : Value.t -> Value.t -> M := make_dict [] |) |) in - let gas_available := BinOp.sub + let _ := M.assign_op_local (| + BinOp.sub, + "gas_available", M.get_name (| globals, "gas_used" |) - M.get_name (| globals, "gas_used" |) in - let receipt := + |) in + let _ := M.assign_local (| + "receipt" , M.call (| M.get_name (| globals, "make_receipt" |), make_list [ @@ -926,7 +1021,8 @@ Definition apply_body : Value.t -> Value.t -> M := M.get_name (| globals, "logs" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ @@ -948,9 +1044,11 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_logs := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "block_logs", M.get_name (| globals, "logs" |) - M.get_name (| globals, "logs" |) in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -967,19 +1065,23 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_gas_used := + let _ := M.assign_local (| + "block_gas_used" , BinOp.sub (| M.get_name (| globals, "block_gas_limit" |), M.get_name (| globals, "gas_available" |) - |) in - let block_logs_bloom := + |) + |) in + let _ := M.assign_local (| + "block_logs_bloom" , M.call (| M.get_name (| globals, "logs_bloom" |), make_list [ M.get_name (| globals, "block_logs" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ApplyBodyOutput" |), @@ -1037,14 +1139,16 @@ Definition validate_ommers : Value.t -> Value.t -> M := chain : History and current state. " in - let block_hash := + let _ := M.assign_local (| + "block_hash" , M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), make_list [ M.get_name (| globals, "block_header" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1109,7 +1213,8 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_parent_header := + let _ := M.assign_local (| + "ommer_parent_header" , M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), BinOp.sub (| @@ -1119,7 +1224,8 @@ Definition validate_ommers : Value.t -> Value.t -> M := |) |), Constant.int 1 |) - |), "header" |) in + |), "header" |) + |) in let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ @@ -1151,8 +1257,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommers_hashes := - Constant.str "(* At expr: unsupported node type: ListComp *)" in + let _ := M.assign_local (| + "ommers_hashes" , + Constant.str "(* At expr: unsupported node type: ListComp *)" + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1182,7 +1290,8 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let recent_canonical_blocks := + let _ := M.assign_local (| + "recent_canonical_blocks" , M.slice (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| BinOp.add (| @@ -1191,23 +1300,28 @@ Definition validate_ommers : Value.t -> Value.t -> M := |) |), Constant.None_, Constant.None_ - |) in - let recent_canonical_block_hashes := - Constant.str "(* At expr: unsupported node type: SetComp *)" in + |) + |) in + let _ := M.assign_local (| + "recent_canonical_block_hashes" , + Constant.str "(* At expr: unsupported node type: SetComp *)" + |) in (* At stmt: unsupported node type: AnnAssign *) let _ := M.for_ (| M.get_name (| globals, "block" |), M.get_name (| globals, "recent_canonical_blocks" |), ltac:(M.monadic ( - let recent_ommers_hashes := + let _ := M.assign_local (| + "recent_ommers_hashes" , M.call (| M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), make_list [ Constant.str "(* At expr: unsupported node type: SetComp *)" ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -1225,11 +1339,13 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let ommer_hash := + let _ := M.assign_local (| + "ommer_hash" , M.get_subscript (| M.get_name (| globals, "ommers_hashes" |), M.get_name (| globals, "ommer_index" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1263,11 +1379,13 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_age := + let _ := M.assign_local (| + "ommer_age" , BinOp.sub (| M.get_field (| M.get_name (| globals, "block_header" |), "number" |), M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1345,7 +1463,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := ommers : List of ommers mentioned in the current block. " in - let miner_reward := + let _ := M.assign_local (| + "miner_reward" , BinOp.add (| M.get_name (| globals, "BLOCK_REWARD" |), BinOp.mult (| @@ -1361,7 +1480,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := Constant.int 32 |) |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "create_ether" |), make_list [ @@ -1376,7 +1496,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := M.get_name (| globals, "ommer" |), M.get_name (| globals, "ommers" |), ltac:(M.monadic ( - let ommer_age := + let _ := M.assign_local (| + "ommer_age" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -1386,8 +1507,10 @@ Definition pay_rewards : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let ommer_miner_reward := + |) + |) in + let _ := M.assign_local (| + "ommer_miner_reward" , BinOp.floor_div (| BinOp.mult (| BinOp.sub (| @@ -1397,7 +1520,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := M.get_name (| globals, "BLOCK_REWARD" |) |), Constant.int 8 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "create_ether" |), make_list [ @@ -1458,9 +1582,12 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender := - M.get_field (| M.get_name (| globals, "env" |), "origin" |) in - let sender_account := + let _ := M.assign_local (| + "sender" , + M.get_field (| M.get_name (| globals, "env" |), "origin" |) + |) in + let _ := M.assign_local (| + "sender_account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1468,12 +1595,15 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "sender" |) ], make_dict [] - |) in - let gas_fee := + |) + |) in + let _ := M.assign_local (| + "gas_fee" , BinOp.mult (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1514,7 +1644,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let gas := + let _ := M.assign_local (| + "gas" , BinOp.sub (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.call (| @@ -1524,7 +1655,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "increment_nonce" |), make_list [ @@ -1533,11 +1665,13 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_balance_after_gas_fee := + let _ := M.assign_local (| + "sender_balance_after_gas_fee" , BinOp.sub (| M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), M.get_name (| globals, "gas_fee" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -1547,7 +1681,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let message := + let _ := M.assign_local (| + "message" , M.call (| M.get_name (| globals, "prepare_message" |), make_list [ @@ -1559,8 +1694,10 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in - let output := + |) + |) in + let _ := M.assign_local (| + "output" , M.call (| M.get_name (| globals, "process_message_call" |), make_list [ @@ -1568,13 +1705,17 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in - let gas_used := + |) + |) in + let _ := M.assign_local (| + "gas_used" , BinOp.sub (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_field (| M.get_name (| globals, "output" |), "gas_left" |) - |) in - let gas_refund := + |) + |) in + let _ := M.assign_local (| + "gas_refund" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -1585,16 +1726,20 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "output" |), "refund_counter" |) ], make_dict [] - |) in - let gas_refund_amount := + |) + |) in + let _ := M.assign_local (| + "gas_refund_amount" , BinOp.mult (| BinOp.add (| M.get_field (| M.get_name (| globals, "output" |), "gas_left" |), M.get_name (| globals, "gas_refund" |) |), M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) - |) in - let transaction_fee := + |) + |) in + let _ := M.assign_local (| + "transaction_fee" , BinOp.mult (| BinOp.sub (| BinOp.sub (| @@ -1604,13 +1749,17 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "gas_refund" |) |), M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) - |) in - let total_gas_used := + |) + |) in + let _ := M.assign_local (| + "total_gas_used" , BinOp.sub (| M.get_name (| globals, "gas_used" |), M.get_name (| globals, "gas_refund" |) - |) in - let sender_balance_after_refund := + |) + |) in + let _ := M.assign_local (| + "sender_balance_after_refund" , BinOp.add (| M.get_field (| M.call (| M.get_name (| globals, "get_account" |), @@ -1621,7 +1770,8 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |), "balance" |), M.get_name (| globals, "gas_refund_amount" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -1631,7 +1781,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let coinbase_balance_after_mining_fee := + let _ := M.assign_local (| + "coinbase_balance_after_mining_fee" , BinOp.add (| M.get_field (| M.call (| M.get_name (| globals, "get_account" |), @@ -1642,7 +1793,8 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |), "balance" |), M.get_name (| globals, "transaction_fee" |) - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1833,8 +1985,10 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := verified : `ethereum.base_types.Uint` The intrinsic cost of the transaction. " in - let data_cost := - Constant.int 0 in + let _ := M.assign_local (| + "data_cost" , + Constant.int 0 + |) in let _ := M.for_ (| M.get_name (| globals, "byte" |), @@ -1849,15 +2003,19 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let data_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "data_cost", M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let data_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "data_cost", M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -1881,13 +2039,17 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let create_cost := - M.get_name (| globals, "TX_CREATE_COST" |) in + let _ := M.assign_local (| + "create_cost" , + M.get_name (| globals, "TX_CREATE_COST" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let create_cost := - Constant.int 0 in + let _ := M.assign_local (| + "create_cost" , + Constant.int 0 + |) in M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1993,7 +2155,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let public_key := + let _ := M.assign_local (| + "public_key" , M.call (| M.get_name (| globals, "secp256k1_recover" |), make_list [ @@ -2012,7 +2175,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -2047,7 +2211,8 @@ Definition recover_sender : Value.t -> Value.t -> M := ], make_dict [] |) in - let public_key := + let _ := M.assign_local (| + "public_key" , M.call (| M.get_name (| globals, "secp256k1_recover" |), make_list [ @@ -2073,7 +2238,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -2259,11 +2425,13 @@ Definition check_gas_limit : Value.t -> Value.t -> M := check : `bool` True if gas limit constraints are satisfied, False otherwise. " in - let max_adjustment_delta := + let _ := M.assign_local (| + "max_adjustment_delta" , BinOp.floor_div (| M.get_name (| globals, "parent_gas_limit" |), M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -2367,7 +2535,8 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := difficulty : `ethereum.base_types.Uint` Computed difficulty for a block. " in - let offset := + let _ := M.assign_local (| + "offset" , BinOp.mult (| BinOp.floor_div (| M.call (| @@ -2411,8 +2580,10 @@ Constant.int 1 ], make_dict [] |) - |) in - let difficulty := + |) + |) in + let _ := M.assign_local (| + "difficulty" , BinOp.add (| M.call (| M.get_name (| globals, "int" |), @@ -2422,8 +2593,10 @@ Constant.int 1 make_dict [] |), M.get_name (| globals, "offset" |) - |) in - let num_bomb_periods := + |) + |) in + let _ := M.assign_local (| + "num_bomb_periods" , BinOp.sub (| BinOp.floor_div (| BinOp.sub (| @@ -2439,7 +2612,8 @@ Constant.int 1 Constant.int 100000 |), Constant.int 2 - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -2449,15 +2623,14 @@ Constant.int 1 |), (* then *) ltac:(M.monadic ( - let difficulty := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "difficulty", BinOp.pow (| Constant.int 2, M.get_name (| globals, "num_bomb_periods" |) |) - BinOp.pow (| - Constant.int 2, - M.get_name (| globals, "num_bomb_periods" |) - |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/istanbul/fork_types.v b/CoqOfPython/ethereum/istanbul/fork_types.v index e78c8f6..f19cd79 100644 --- a/CoqOfPython/ethereum/istanbul/fork_types.v +++ b/CoqOfPython/ethereum/istanbul/fork_types.v @@ -17,17 +17,29 @@ Introduction Types re-used throughout the specification, which are specific to Ethereum. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes20"; "Bytes256"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes20 : + IsImported globals "ethereum.base_types" "Bytes20". +Axiom ethereum_base_types_imports_Bytes256 : + IsImported globals "ethereum.base_types" "Bytes256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) diff --git a/CoqOfPython/ethereum/istanbul/state.v b/CoqOfPython/ethereum/istanbul/state.v index 928472f..d2aaed7 100644 --- a/CoqOfPython/ethereum/istanbul/state.v +++ b/CoqOfPython/ethereum/istanbul/state.v @@ -22,23 +22,57 @@ There is a distinction between an account that does not exist and `EMPTY_ACCOUNT`. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass"; "field" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict"; "List"; "Optional"; "Set"; "Tuple" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "modify" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_istanbul_fork_types_imports : - AreImported globals "ethereum.istanbul.fork_types" [ "EMPTY_ACCOUNT"; "Account"; "Address"; "Root" ]. - -Axiom ethereum_istanbul_trie_imports : - AreImported globals "ethereum.istanbul.trie" [ "EMPTY_TRIE_ROOT"; "Trie"; "copy_trie"; "root"; "trie_get"; "trie_set" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". +Axiom dataclasses_imports_field : + IsImported globals "dataclasses" "field". + +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_modify : + IsImported globals "ethereum.base_types" "modify". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_istanbul_fork_types_imports_EMPTY_ACCOUNT : + IsImported globals "ethereum.istanbul.fork_types" "EMPTY_ACCOUNT". +Axiom ethereum_istanbul_fork_types_imports_Account : + IsImported globals "ethereum.istanbul.fork_types" "Account". +Axiom ethereum_istanbul_fork_types_imports_Address : + IsImported globals "ethereum.istanbul.fork_types" "Address". +Axiom ethereum_istanbul_fork_types_imports_Root : + IsImported globals "ethereum.istanbul.fork_types" "Root". + +Axiom ethereum_istanbul_trie_imports_EMPTY_TRIE_ROOT : + IsImported globals "ethereum.istanbul.trie" "EMPTY_TRIE_ROOT". +Axiom ethereum_istanbul_trie_imports_Trie : + IsImported globals "ethereum.istanbul.trie" "Trie". +Axiom ethereum_istanbul_trie_imports_copy_trie : + IsImported globals "ethereum.istanbul.trie" "copy_trie". +Axiom ethereum_istanbul_trie_imports_root : + IsImported globals "ethereum.istanbul.trie" "root". +Axiom ethereum_istanbul_trie_imports_trie_get : + IsImported globals "ethereum.istanbul.trie" "trie_get". +Axiom ethereum_istanbul_trie_imports_trie_set : + IsImported globals "ethereum.istanbul.trie" "trie_set". Definition State : Value.t := builtins.make_klass @@ -186,7 +220,8 @@ Definition get_account : Value.t -> Value.t -> M := account : `Account` Account at address. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account_optional" |), make_list [ @@ -194,7 +229,8 @@ Definition get_account : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -240,7 +276,8 @@ Definition get_account_optional : Value.t -> Value.t -> M := account : `Account` Account at address. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "trie_get" |), make_list [ @@ -248,7 +285,8 @@ Definition get_account_optional : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "account" |) |) in @@ -399,14 +437,16 @@ Definition get_storage : Value.t -> Value.t -> M := value : `U256` Value at the key. " in - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -430,7 +470,8 @@ Definition get_storage : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "trie_get" |), make_list [ @@ -438,7 +479,8 @@ Definition get_storage : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -481,14 +523,16 @@ Definition set_storage : Value.t -> Value.t -> M := |), Constant.None_ |) |) in - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -498,12 +542,14 @@ Definition set_storage : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_name (| globals, "Trie" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), @@ -530,7 +576,7 @@ Definition set_storage : Value.t -> Value.t -> M := M.if_then_else (| Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), - {} + Constant.str "(* At expr: unsupported node type: Dict *)" |), (* then *) ltac:(M.monadic ( @@ -676,7 +722,8 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := True if if an account has non zero nonce or non empty code, False otherwise. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -684,7 +731,8 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| BoolOp.or (| Compare.not_eq (| @@ -726,7 +774,8 @@ Definition is_account_empty : Value.t -> Value.t -> M := True if if an account has zero nonce, empty code and zero balance, False otherwise. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -734,7 +783,8 @@ Definition is_account_empty : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| BoolOp.and (| Compare.eq (| @@ -785,7 +835,8 @@ Definition account_exists_and_is_empty : Value.t -> Value.t -> M := True if an account exists and has zero nonce, empty code and zero balance, False otherwise. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account_optional" |), make_list [ @@ -793,7 +844,8 @@ Definition account_exists_and_is_empty : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| BoolOp.and (| Compare.is_not (| @@ -850,7 +902,8 @@ Definition is_account_alive : Value.t -> Value.t -> M := is_alive : `bool` True if the account is alive. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account_optional" |), make_list [ @@ -858,7 +911,8 @@ Definition is_account_alive : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1166,14 +1220,16 @@ Definition get_storage_original : Value.t -> Value.t -> M := Constant.int 0 |) |) in - let original_account_trie := + let _ := M.assign_local (| + "original_account_trie" , M.call (| M.get_field (| M.get_name (| globals, "original_trie" |), "get" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1183,18 +1239,21 @@ Definition get_storage_original : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let original_value := + let _ := M.assign_local (| + "original_value" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let original_value := + let _ := M.assign_local (| + "original_value" , M.call (| M.get_name (| globals, "trie_get" |), make_list [ @@ -1202,7 +1261,8 @@ Definition get_storage_original : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.assert (| M.call (| diff --git a/CoqOfPython/ethereum/istanbul/transactions.v b/CoqOfPython/ethereum/istanbul/transactions.v index 0dbad42..0658f47 100644 --- a/CoqOfPython/ethereum/istanbul/transactions.v +++ b/CoqOfPython/ethereum/istanbul/transactions.v @@ -9,17 +9,25 @@ submitted to be executed. If Ethereum is viewed as a state machine, transactions are the events that move between states. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Union" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_istanbul_fork_types_imports : - AreImported globals "ethereum.istanbul.fork_types" [ "Address" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_Union : + IsImported globals "typing" "Union". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_istanbul_fork_types_imports_Address : + IsImported globals "ethereum.istanbul.fork_types" "Address". Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( Constant.int 21000 diff --git a/CoqOfPython/ethereum/istanbul/trie.v b/CoqOfPython/ethereum/istanbul/trie.v index 579b49d..0265390 100644 --- a/CoqOfPython/ethereum/istanbul/trie.v +++ b/CoqOfPython/ethereum/istanbul/trie.v @@ -20,38 +20,72 @@ The state trie is the structure responsible for storing (* At top_level_stmt: unsupported node type: Import *) -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass"; "field" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict"; "Generic"; "List"; "Mapping"; "MutableMapping"; "Optional"; "Sequence"; "TypeVar"; "Union"; "cast" ]. - -Axiom ethereum_constantinople_imports : - AreImported globals "ethereum.constantinople" [ "trie" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_utils_hexadecimal_imports : - AreImported globals "ethereum.utils.hexadecimal" [ "hex_to_bytes" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_istanbul_blocks_imports : - AreImported globals "ethereum.istanbul.blocks" [ "Receipt" ]. - -Axiom ethereum_istanbul_fork_types_imports : - AreImported globals "ethereum.istanbul.fork_types" [ "Account"; "Address"; "Root"; "encode_account" ]. - -Axiom ethereum_istanbul_transactions_imports : - AreImported globals "ethereum.istanbul.transactions" [ "Transaction" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". +Axiom dataclasses_imports_field : + IsImported globals "dataclasses" "field". + +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". +Axiom typing_imports_Generic : + IsImported globals "typing" "Generic". +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Mapping : + IsImported globals "typing" "Mapping". +Axiom typing_imports_MutableMapping : + IsImported globals "typing" "MutableMapping". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Sequence : + IsImported globals "typing" "Sequence". +Axiom typing_imports_TypeVar : + IsImported globals "typing" "TypeVar". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". +Axiom typing_imports_cast : + IsImported globals "typing" "cast". + +Axiom ethereum_constantinople_imports_trie : + IsImported globals "ethereum.constantinople" "trie". + +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_utils_hexadecimal_imports_hex_to_bytes : + IsImported globals "ethereum.utils.hexadecimal" "hex_to_bytes". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_istanbul_blocks_imports_Receipt : + IsImported globals "ethereum.istanbul.blocks" "Receipt". + +Axiom ethereum_istanbul_fork_types_imports_Account : + IsImported globals "ethereum.istanbul.fork_types" "Account". +Axiom ethereum_istanbul_fork_types_imports_Address : + IsImported globals "ethereum.istanbul.fork_types" "Address". +Axiom ethereum_istanbul_fork_types_imports_Root : + IsImported globals "ethereum.istanbul.fork_types" "Root". +Axiom ethereum_istanbul_fork_types_imports_encode_account : + IsImported globals "ethereum.istanbul.fork_types" "encode_account". + +Axiom ethereum_istanbul_transactions_imports_Transaction : + IsImported globals "ethereum.istanbul.transactions" "Transaction". Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -161,7 +195,7 @@ Definition encode_internal_node : Value.t -> Value.t -> M := when serialized. This function also accepts `None`, representing the absence of a node, - which is encoded to `b""""""`. + which is encoded to `b""""`. Parameters ---------- @@ -183,8 +217,10 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := - Constant.bytes "" in + let _ := M.assign_local (| + "unencoded" , + Constant.bytes "" + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -201,7 +237,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := + let _ := M.assign_local (| + "unencoded" , make_tuple [ M.call (| M.get_name (| globals, "nibble_list_to_compact" |), make_list [ @@ -209,7 +246,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := Constant.bool true ], make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in + |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -226,7 +264,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := + let _ := M.assign_local (| + "unencoded" , make_tuple [ M.call (| M.get_name (| globals, "nibble_list_to_compact" |), make_list [ @@ -234,7 +273,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := Constant.bool false ], make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in + |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -251,13 +291,15 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := + let _ := M.assign_local (| + "unencoded" , BinOp.add (| M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), make_list [ M.get_field (| M.get_name (| globals, "node" |), "value" |) ] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -276,14 +318,16 @@ Definition encode_internal_node : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - let encoded := + let _ := M.assign_local (| + "encoded" , M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), make_list [ M.get_name (| globals, "unencoded" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -675,12 +719,14 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := compressed : `bytearray` Compact byte array. " in - let compact := + let _ := M.assign_local (| + "compact" , M.call (| M.get_name (| globals, "bytearray" |), make_list [], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -860,7 +906,8 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := nibble_list : `Bytes` The `Bytes` in nibble-list format. " in - let nibble_list := + let _ := M.assign_local (| + "nibble_list" , M.call (| M.get_name (| globals, "bytearray" |), make_list [ @@ -876,7 +923,8 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ], @@ -984,15 +1032,18 @@ Definition _prepare_trie : Value.t -> Value.t -> M := M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "Address" |), make_list [ M.get_name (| globals, "preimage" |) ], make_dict [] - |) in - let encoded_value := + |) + |) in + let _ := M.assign_local (| + "encoded_value" , M.call (| M.get_name (| globals, "encode_node" |), make_list [ @@ -1006,18 +1057,21 @@ Definition _prepare_trie : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let encoded_value := + let _ := M.assign_local (| + "encoded_value" , M.call (| M.get_name (| globals, "encode_node" |), make_list [ M.get_name (| globals, "value" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -1038,19 +1092,23 @@ Definition _prepare_trie : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "trie" |), "secured" |), (* then *) ltac:(M.monadic ( - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "preimage" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let key := - M.get_name (| globals, "preimage" |) in + let _ := M.assign_local (| + "key" , + M.get_name (| globals, "preimage" |) + |) in M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -1097,7 +1155,8 @@ Definition root : Value.t -> Value.t -> M := root : `.fork_types.Root` MPT root of the underlying key-value pairs. " in - let obj := + let _ := M.assign_local (| + "obj" , M.call (| M.get_name (| globals, "_prepare_trie" |), make_list [ @@ -1105,8 +1164,10 @@ Definition root : Value.t -> Value.t -> M := M.get_name (| globals, "get_storage_root" |) ], make_dict [] - |) in - let root_node := + |) + |) in + let _ := M.assign_local (| + "root_node" , M.call (| M.get_name (| globals, "encode_internal_node" |), make_list [ @@ -1126,7 +1187,8 @@ Definition root : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1231,7 +1293,8 @@ Definition patricialize : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let arbitrary_key := + let _ := M.assign_local (| + "arbitrary_key" , M.call (| M.get_name (| globals, "next" |), make_list [ @@ -1244,7 +1307,8 @@ Definition patricialize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1260,7 +1324,8 @@ Definition patricialize : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let leaf := + let _ := M.assign_local (| + "leaf" , M.call (| M.get_name (| globals, "LeafNode" |), make_list [ @@ -1276,7 +1341,8 @@ Definition patricialize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "leaf" |) |) in @@ -1285,27 +1351,32 @@ Definition patricialize : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let substring := + let _ := M.assign_local (| + "substring" , M.slice (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |), Constant.None_, Constant.None_ - |) in - let prefix_length := + |) + |) in + let _ := M.assign_local (| + "prefix_length" , M.call (| M.get_name (| globals, "len" |), make_list [ M.get_name (| globals, "substring" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "key" |), M.get_name (| globals, "obj" |), ltac:(M.monadic ( - let prefix_length := + let _ := M.assign_local (| + "prefix_length" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -1325,7 +1396,8 @@ Definition patricialize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1356,7 +1428,8 @@ Definition patricialize : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let prefix := + let _ := M.assign_local (| + "prefix" , M.slice (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |), @@ -1365,7 +1438,8 @@ Definition patricialize : Value.t -> Value.t -> M := M.get_name (| globals, "prefix_length" |) |), Constant.None_ - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ExtensionNode" |), @@ -1412,7 +1486,7 @@ Definition patricialize : Value.t -> Value.t -> M := let _ := M.call (| M.get_field (| M.get_name (| globals, "branches" |), "append" |), make_list [ - {} + Constant.str "(* At expr: unsupported node type: Dict *)" ], make_dict [] |) in @@ -1422,8 +1496,10 @@ Definition patricialize : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let value := - Constant.bytes "" in + let _ := M.assign_local (| + "value" , + Constant.bytes "" + |) in let _ := M.for_ (| M.get_name (| globals, "key" |), @@ -1466,11 +1542,13 @@ Definition patricialize : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let value := + let _ := M.assign_local (| + "value" , M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/istanbul/utils/address.v b/CoqOfPython/ethereum/istanbul/utils/address.v index cb5fb4d..340714a 100644 --- a/CoqOfPython/ethereum/istanbul/utils/address.v +++ b/CoqOfPython/ethereum/istanbul/utils/address.v @@ -18,23 +18,27 @@ Address specific functions used in this istanbul version of specification. ". -Axiom typing_imports : - AreImported globals "typing" [ "Union" ]. +Axiom typing_imports_Union : + IsImported globals "typing" "Union". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes32"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_left_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "left_pad_zero_bytes". -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". -Axiom ethereum_istanbul_fork_types_imports : - AreImported globals "ethereum.istanbul.fork_types" [ "Address" ]. +Axiom ethereum_istanbul_fork_types_imports_Address : + IsImported globals "ethereum.istanbul.fork_types" "Address". Definition to_address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -91,7 +95,8 @@ Definition compute_contract_address : Value.t -> Value.t -> M := address: `Address` The computed address of the new account. " in - let computed_address := + let _ := M.assign_local (| + "computed_address" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -107,15 +112,19 @@ Definition compute_contract_address : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let canonical_address := + |) + |) in + let _ := M.assign_local (| + "canonical_address" , M.slice (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |), Constant.None_, Constant.None_ - |) in - let padded_address := + |) + |) in + let _ := M.assign_local (| + "padded_address" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -123,7 +132,8 @@ Definition compute_contract_address : Value.t -> Value.t -> M := Constant.int 20 ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Address" |), @@ -156,7 +166,8 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := address: `ethereum.istanbul.fork_types.Address` The computed address of the new account. " in - let preimage := + let _ := M.assign_local (| + "preimage" , BinOp.add (| BinOp.add (| BinOp.add (| @@ -172,23 +183,29 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in - let computed_address := + |) + |) in + let _ := M.assign_local (| + "computed_address" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "preimage" |) ], make_dict [] - |) in - let canonical_address := + |) + |) in + let _ := M.assign_local (| + "canonical_address" , M.slice (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |), Constant.None_, Constant.None_ - |) in - let padded_address := + |) + |) in + let _ := M.assign_local (| + "padded_address" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -196,7 +213,8 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := Constant.int 20 ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Address" |), diff --git a/CoqOfPython/ethereum/istanbul/utils/hexadecimal.v b/CoqOfPython/ethereum/istanbul/utils/hexadecimal.v index d797c37..0486e96 100644 --- a/CoqOfPython/ethereum/istanbul/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/istanbul/utils/hexadecimal.v @@ -18,11 +18,15 @@ Hexadecimal utility functions used in this specification, specific to Istanbul types. ". -Axiom ethereum_utils_hexadecimal_imports : - AreImported globals "ethereum.utils.hexadecimal" [ "remove_hex_prefix" ]. - -Axiom ethereum_istanbul_fork_types_imports : - AreImported globals "ethereum.istanbul.fork_types" [ "Address"; "Bloom"; "Root" ]. +Axiom ethereum_utils_hexadecimal_imports_remove_hex_prefix : + IsImported globals "ethereum.utils.hexadecimal" "remove_hex_prefix". + +Axiom ethereum_istanbul_fork_types_imports_Address : + IsImported globals "ethereum.istanbul.fork_types" "Address". +Axiom ethereum_istanbul_fork_types_imports_Bloom : + IsImported globals "ethereum.istanbul.fork_types" "Bloom". +Axiom ethereum_istanbul_fork_types_imports_Root : + IsImported globals "ethereum.istanbul.fork_types" "Root". Definition hex_to_root : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/istanbul/utils/message.v b/CoqOfPython/ethereum/istanbul/utils/message.v index 88cd234..2ff4fec 100644 --- a/CoqOfPython/ethereum/istanbul/utils/message.v +++ b/CoqOfPython/ethereum/istanbul/utils/message.v @@ -18,23 +18,33 @@ Message specific functions used in this istanbul version of specification. ". -Axiom typing_imports : - AreImported globals "typing" [ "Optional"; "Union" ]. +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_istanbul_fork_types_imports : - AreImported globals "ethereum.istanbul.fork_types" [ "Address" ]. +Axiom ethereum_istanbul_fork_types_imports_Address : + IsImported globals "ethereum.istanbul.fork_types" "Address". -Axiom ethereum_istanbul_state_imports : - AreImported globals "ethereum.istanbul.state" [ "get_account" ]. +Axiom ethereum_istanbul_state_imports_get_account : + IsImported globals "ethereum.istanbul.state" "get_account". -Axiom ethereum_istanbul_vm_imports : - AreImported globals "ethereum.istanbul.vm" [ "Environment"; "Message" ]. +Axiom ethereum_istanbul_vm_imports_Environment : + IsImported globals "ethereum.istanbul.vm" "Environment". +Axiom ethereum_istanbul_vm_imports_Message : + IsImported globals "ethereum.istanbul.vm" "Message". -Axiom ethereum_istanbul_utils_address_imports : - AreImported globals "ethereum.istanbul.utils.address" [ "compute_contract_address" ]. +Axiom ethereum_istanbul_utils_address_imports_compute_contract_address : + IsImported globals "ethereum.istanbul.utils.address" "compute_contract_address". Definition prepare_message : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -84,7 +94,8 @@ Definition prepare_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let current_target := + let _ := M.assign_local (| + "current_target" , M.call (| M.get_name (| globals, "compute_contract_address" |), make_list [ @@ -108,17 +119,22 @@ Definition prepare_message : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let msg_data := + |) + |) in + let _ := M.assign_local (| + "msg_data" , M.call (| M.get_name (| globals, "Bytes" |), make_list [ Constant.bytes "" ], make_dict [] - |) in - let code := - M.get_name (| globals, "data" |) in + |) + |) in + let _ := M.assign_local (| + "code" , + M.get_name (| globals, "data" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -135,11 +151,16 @@ Definition prepare_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let current_target := - M.get_name (| globals, "target" |) in - let msg_data := - M.get_name (| globals, "data" |) in - let code := + let _ := M.assign_local (| + "current_target" , + M.get_name (| globals, "target" |) + |) in + let _ := M.assign_local (| + "msg_data" , + M.get_name (| globals, "data" |) + |) in + let _ := M.assign_local (| + "code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -147,7 +168,8 @@ Definition prepare_message : Value.t -> Value.t -> M := M.get_name (| globals, "target" |) ], make_dict [] - |), "code" |) in + |), "code" |) + |) in let _ := (* if *) M.if_then_else (| @@ -157,8 +179,10 @@ Definition prepare_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let code_address := - M.get_name (| globals, "target" |) in + let _ := M.assign_local (| + "code_address" , + M.get_name (| globals, "target" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/istanbul/vm/__init__.v b/CoqOfPython/ethereum/istanbul/vm/__init__.v index 365da0c..dc4ef8a 100644 --- a/CoqOfPython/ethereum/istanbul/vm/__init__.v +++ b/CoqOfPython/ethereum/istanbul/vm/__init__.v @@ -18,29 +18,47 @@ The abstract computer which runs the code stored in an `.fork_types.Account`. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple"; "Union" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U64"; "U256"; "Bytes"; "Bytes0"; "Uint" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. - -Axiom ethereum_istanbul_blocks_imports : - AreImported globals "ethereum.istanbul.blocks" [ "Log" ]. - -Axiom ethereum_istanbul_fork_types_imports : - AreImported globals "ethereum.istanbul.fork_types" [ "Address" ]. - -Axiom ethereum_istanbul_state_imports : - AreImported globals "ethereum.istanbul.state" [ "State"; "account_exists_and_is_empty" ]. - -Axiom ethereum_istanbul_vm_precompiled_contracts_imports : - AreImported globals "ethereum.istanbul.vm.precompiled_contracts" [ "RIPEMD160_ADDRESS" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". + +Axiom ethereum_base_types_imports_U64 : + IsImported globals "ethereum.base_types" "U64". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". + +Axiom ethereum_istanbul_blocks_imports_Log : + IsImported globals "ethereum.istanbul.blocks" "Log". + +Axiom ethereum_istanbul_fork_types_imports_Address : + IsImported globals "ethereum.istanbul.fork_types" "Address". + +Axiom ethereum_istanbul_state_imports_State : + IsImported globals "ethereum.istanbul.state" "State". +Axiom ethereum_istanbul_state_imports_account_exists_and_is_empty : + IsImported globals "ethereum.istanbul.state" "account_exists_and_is_empty". + +Axiom ethereum_istanbul_vm_precompiled_contracts_imports_RIPEMD160_ADDRESS : + IsImported globals "ethereum.istanbul.vm.precompiled_contracts" "RIPEMD160_ADDRESS". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] diff --git a/CoqOfPython/ethereum/istanbul/vm/exceptions.v b/CoqOfPython/ethereum/istanbul/vm/exceptions.v index 87a9d29..3ba8068 100644 --- a/CoqOfPython/ethereum/istanbul/vm/exceptions.v +++ b/CoqOfPython/ethereum/istanbul/vm/exceptions.v @@ -17,8 +17,8 @@ Introduction Exceptions which cause the EVM to halt exceptionally. ". -Axiom ethereum_exceptions_imports : - AreImported globals "ethereum.exceptions" [ "EthereumException" ]. +Axiom ethereum_exceptions_imports_EthereumException : + IsImported globals "ethereum.exceptions" "EthereumException". Definition ExceptionalHalt : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/istanbul/vm/gas.v b/CoqOfPython/ethereum/istanbul/vm/gas.v index 921b718..b2000e8 100644 --- a/CoqOfPython/ethereum/istanbul/vm/gas.v +++ b/CoqOfPython/ethereum/istanbul/vm/gas.v @@ -17,26 +17,32 @@ Introduction EVM gas constants and calculators. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Tuple" ]. +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_trace_imports : - AreImported globals "ethereum.trace" [ "GasAndRefund"; "evm_trace" ]. +Axiom ethereum_trace_imports_GasAndRefund : + IsImported globals "ethereum.trace" "GasAndRefund". +Axiom ethereum_trace_imports_evm_trace : + IsImported globals "ethereum.trace" "evm_trace". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_istanbul_vm_imports : - AreImported globals "ethereum.istanbul.vm" [ "Evm" ]. +Axiom ethereum_istanbul_vm_imports_Evm : + IsImported globals "ethereum.istanbul.vm" "Evm". -Axiom ethereum_istanbul_vm_exceptions_imports : - AreImported globals "ethereum.istanbul.vm.exceptions" [ "OutOfGasError" ]. +Axiom ethereum_istanbul_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.istanbul.vm.exceptions" "OutOfGasError". Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -562,7 +568,8 @@ Definition calculate_memory_gas_cost : Value.t -> Value.t -> M := total_gas_cost : `ethereum.base_types.Uint` The gas cost for storing data in memory. " in - let size_in_words := + let _ := M.assign_local (| + "size_in_words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -572,25 +579,32 @@ Definition calculate_memory_gas_cost : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let linear_cost := + |) + |) in + let _ := M.assign_local (| + "linear_cost" , BinOp.mult (| M.get_name (| globals, "size_in_words" |), M.get_name (| globals, "GAS_MEMORY" |) - |) in - let quadratic_cost := + |) + |) in + let _ := M.assign_local (| + "quadratic_cost" , BinOp.floor_div (| BinOp.pow (| M.get_name (| globals, "size_in_words" |), Constant.int 2 |), Constant.int 512 - |) in - let total_gas_cost := + |) + |) in + let _ := M.assign_local (| + "total_gas_cost" , BinOp.add (| M.get_name (| globals, "linear_cost" |), M.get_name (| globals, "quadratic_cost" |) - |) in + |) + |) in (* At stmt: unsupported node type: Try *) M.pure Constant.None_)). @@ -612,23 +626,28 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := ------- extend_memory: `ExtendMemory` " in - let size_to_extend := + let _ := M.assign_local (| + "size_to_extend" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in - let to_be_paid := + |) + |) in + let _ := M.assign_local (| + "to_be_paid" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in - let current_size := + |) + |) in + let _ := M.assign_local (| + "current_size" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -641,7 +660,8 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ], @@ -662,15 +682,18 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let before_size := + let _ := M.assign_local (| + "before_size" , M.call (| M.get_name (| globals, "ceil32" |), make_list [ M.get_name (| globals, "current_size" |) ], make_dict [] - |) in - let after_size := + |) + |) in + let _ := M.assign_local (| + "after_size" , M.call (| M.get_name (| globals, "ceil32" |), make_list [ @@ -692,7 +715,8 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -708,42 +732,46 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let size_to_extend := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "size_to_extend", BinOp.sub (| M.get_name (| globals, "after_size" |), M.get_name (| globals, "before_size" |) |) - BinOp.sub (| - M.get_name (| globals, "after_size" |), - M.get_name (| globals, "before_size" |) - |) in - let already_paid := + |) in + let _ := M.assign_local (| + "already_paid" , M.call (| M.get_name (| globals, "calculate_memory_gas_cost" |), make_list [ M.get_name (| globals, "before_size" |) ], make_dict [] - |) in - let total_cost := + |) + |) in + let _ := M.assign_local (| + "total_cost" , M.call (| M.get_name (| globals, "calculate_memory_gas_cost" |), make_list [ M.get_name (| globals, "after_size" |) ], make_dict [] - |) in - let to_be_paid := BinOp.add + |) + |) in + let _ := M.assign_op_local (| + BinOp.add, + "to_be_paid", BinOp.sub (| M.get_name (| globals, "total_cost" |), M.get_name (| globals, "already_paid" |) |) - BinOp.sub (| - M.get_name (| globals, "total_cost" |), - M.get_name (| globals, "already_paid" |) - |) in - let current_size := - M.get_name (| globals, "after_size" |) in + |) in + let _ := M.assign_local (| + "current_size" , + M.get_name (| globals, "after_size" |) + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -790,7 +818,8 @@ Definition calculate_message_call_gas : Value.t -> Value.t -> M := ------- message_call_gas: `MessageCallGas` " in - let call_stipend := + let _ := M.assign_local (| + "call_stipend" , (* if *) M.if_then_else (| Compare.eq (| @@ -809,7 +838,8 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "call_stipend" |) - )) |) in + )) |) + |) in let _ := (* if *) M.if_then_else (| @@ -843,7 +873,8 @@ M.get_name (| globals, "call_stipend" |) )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -863,7 +894,8 @@ M.get_name (| globals, "call_stipend" |) |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "MessageCallGas" |), diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/__init__.v b/CoqOfPython/ethereum/istanbul/vm/instructions/__init__.v index 60ca1c4..645b22b 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/__init__.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/__init__.v @@ -20,44 +20,46 @@ implementations. (* At top_level_stmt: unsupported node type: Import *) -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict" ]. +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". -Axiom ethereum_istanbul_vm_instructions_imports : - AreImported globals "ethereum.istanbul.vm.instructions" [ "arithmetic" ]. +Axiom ethereum_istanbul_vm_instructions_imports_arithmetic : + IsImported globals "ethereum.istanbul.vm.instructions" "arithmetic". -Axiom ethereum_istanbul_vm_instructions_imports : - AreImported globals "ethereum.istanbul.vm.instructions" [ "bitwise" ]. +Axiom ethereum_istanbul_vm_instructions_imports_bitwise : + IsImported globals "ethereum.istanbul.vm.instructions" "bitwise". -Axiom ethereum_istanbul_vm_instructions_imports : - AreImported globals "ethereum.istanbul.vm.instructions" [ "block" ]. +Axiom ethereum_istanbul_vm_instructions_imports_block : + IsImported globals "ethereum.istanbul.vm.instructions" "block". -Axiom ethereum_istanbul_vm_instructions_imports : - AreImported globals "ethereum.istanbul.vm.instructions" [ "comparison" ]. +Axiom ethereum_istanbul_vm_instructions_imports_comparison : + IsImported globals "ethereum.istanbul.vm.instructions" "comparison". -Axiom ethereum_istanbul_vm_instructions_imports : - AreImported globals "ethereum.istanbul.vm.instructions" [ "control_flow" ]. +Axiom ethereum_istanbul_vm_instructions_imports_control_flow : + IsImported globals "ethereum.istanbul.vm.instructions" "control_flow". -Axiom ethereum_istanbul_vm_instructions_imports : - AreImported globals "ethereum.istanbul.vm.instructions" [ "environment" ]. +Axiom ethereum_istanbul_vm_instructions_imports_environment : + IsImported globals "ethereum.istanbul.vm.instructions" "environment". -Axiom ethereum_istanbul_vm_instructions_imports : - AreImported globals "ethereum.istanbul.vm.instructions" [ "keccak" ]. +Axiom ethereum_istanbul_vm_instructions_imports_keccak : + IsImported globals "ethereum.istanbul.vm.instructions" "keccak". -Axiom ethereum_istanbul_vm_instructions_imports : - AreImported globals "ethereum.istanbul.vm.instructions" [ "log" ]. +Axiom ethereum_istanbul_vm_instructions_imports_log : + IsImported globals "ethereum.istanbul.vm.instructions" "log". -Axiom ethereum_istanbul_vm_instructions_imports : - AreImported globals "ethereum.istanbul.vm.instructions" [ "memory" ]. +Axiom ethereum_istanbul_vm_instructions_imports_memory : + IsImported globals "ethereum.istanbul.vm.instructions" "memory". -Axiom ethereum_istanbul_vm_instructions_imports : - AreImported globals "ethereum.istanbul.vm.instructions" [ "stack" ]. +Axiom ethereum_istanbul_vm_instructions_imports_stack : + IsImported globals "ethereum.istanbul.vm.instructions" "stack". -Axiom ethereum_istanbul_vm_instructions_imports : - AreImported globals "ethereum.istanbul.vm.instructions" [ "storage" ]. +Axiom ethereum_istanbul_vm_instructions_imports_storage : + IsImported globals "ethereum.istanbul.vm.instructions" "storage". -Axiom ethereum_istanbul_vm_instructions_imports : - AreImported globals "ethereum.istanbul.vm.instructions" [ "system" ]. +Axiom ethereum_istanbul_vm_instructions_imports_system : + IsImported globals "ethereum.istanbul.vm.instructions" "system". Definition Ops : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/istanbul/vm/instructions/arithmetic.v index 5ffc75b..6c1634f 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/arithmetic.v @@ -17,20 +17,38 @@ Introduction Implementations of the EVM Arithmetic instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U255_CEIL_VALUE"; "U256"; "U256_CEIL_VALUE"; "Uint" ]. +Axiom ethereum_base_types_imports_U255_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U255_CEIL_VALUE". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_U256_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U256_CEIL_VALUE". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "get_sign" ]. +Axiom ethereum_utils_numeric_imports_get_sign : + IsImported globals "ethereum.utils.numeric" "get_sign". -Axiom ethereum_istanbul_vm_imports : - AreImported globals "ethereum.istanbul.vm" [ "Evm" ]. +Axiom ethereum_istanbul_vm_imports_Evm : + IsImported globals "ethereum.istanbul.vm" "Evm". -Axiom ethereum_istanbul_vm_gas_imports : - AreImported globals "ethereum.istanbul.vm.gas" [ "GAS_EXPONENTIATION"; "GAS_EXPONENTIATION_PER_BYTE"; "GAS_LOW"; "GAS_MID"; "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_istanbul_vm_gas_imports_GAS_EXPONENTIATION : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_EXPONENTIATION". +Axiom ethereum_istanbul_vm_gas_imports_GAS_EXPONENTIATION_PER_BYTE : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_EXPONENTIATION_PER_BYTE". +Axiom ethereum_istanbul_vm_gas_imports_GAS_LOW : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_LOW". +Axiom ethereum_istanbul_vm_gas_imports_GAS_MID : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_MID". +Axiom ethereum_istanbul_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_istanbul_vm_gas_imports_charge_gas : + IsImported globals "ethereum.istanbul.vm.gas" "charge_gas". -Axiom ethereum_istanbul_vm_stack_imports : - AreImported globals "ethereum.istanbul.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_istanbul_vm_stack_imports_pop : + IsImported globals "ethereum.istanbul.vm.stack" "pop". +Axiom ethereum_istanbul_vm_stack_imports_push : + IsImported globals "ethereum.istanbul.vm.stack" "push". Definition add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,22 +63,26 @@ Definition add : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -69,14 +91,16 @@ Definition add : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "x" |), "wrapping_add" |), make_list [ M.get_name (| globals, "y" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -105,22 +129,26 @@ Definition sub : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -129,14 +157,16 @@ Definition sub : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "x" |), "wrapping_sub" |), make_list [ M.get_name (| globals, "y" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -165,22 +195,26 @@ Definition mul : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -189,14 +223,16 @@ Definition mul : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "x" |), "wrapping_mul" |), make_list [ M.get_name (| globals, "y" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -225,22 +261,26 @@ Definition div : Value.t -> Value.t -> M := The current EVM frame. " in - let dividend := + let _ := M.assign_local (| + "dividend" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let divisor := + |) + |) in + let _ := M.assign_local (| + "divisor" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -258,22 +298,26 @@ Definition div : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let quotient := + let _ := M.assign_local (| + "quotient" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let quotient := + let _ := M.assign_local (| + "quotient" , BinOp.floor_div (| M.get_name (| globals, "dividend" |), M.get_name (| globals, "divisor" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -304,7 +348,8 @@ Definition sdiv : Value.t -> Value.t -> M := The current EVM frame. " in - let dividend := + let _ := M.assign_local (| + "dividend" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -315,8 +360,10 @@ Definition sdiv : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let divisor := + |) + |) in + let _ := M.assign_local (| + "divisor" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -327,7 +374,8 @@ Definition sdiv : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -345,8 +393,10 @@ Definition sdiv : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let quotient := - Constant.int 0 in + let _ := M.assign_local (| + "quotient" , + Constant.int 0 + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -367,12 +417,15 @@ Definition sdiv : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let quotient := - UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in + let _ := M.assign_local (| + "quotient" , + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let sign := + let _ := M.assign_local (| + "sign" , M.call (| M.get_name (| globals, "get_sign" |), make_list [ @@ -382,8 +435,10 @@ Definition sdiv : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let quotient := + |) + |) in + let _ := M.assign_local (| + "quotient" , BinOp.mult (| M.get_name (| globals, "sign" |), BinOp.floor_div (| @@ -402,7 +457,8 @@ Definition sdiv : Value.t -> Value.t -> M := make_dict [] |) |) - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -428,7 +484,7 @@ Definition sdiv : Value.t -> Value.t -> M := |) in M.pure Constant.None_)). -Definition mod : Value.t -> Value.t -> M := +Definition mod_ : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in let _ := Constant.str " @@ -441,22 +497,26 @@ Definition mod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -474,22 +534,26 @@ Definition mod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let remainder := + let _ := M.assign_local (| + "remainder" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let remainder := + let _ := M.assign_local (| + "remainder" , BinOp.mod_ (| M.get_name (| globals, "x" |), M.get_name (| globals, "y" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -520,7 +584,8 @@ Definition smod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -531,8 +596,10 @@ Definition smod : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -543,7 +610,8 @@ Definition smod : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -561,12 +629,15 @@ Definition smod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let remainder := - Constant.int 0 in + let _ := M.assign_local (| + "remainder" , + Constant.int 0 + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let remainder := + let _ := M.assign_local (| + "remainder" , BinOp.mult (| M.call (| M.get_name (| globals, "get_sign" |), @@ -591,7 +662,8 @@ Definition smod : Value.t -> Value.t -> M := make_dict [] |) |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -628,7 +700,8 @@ Definition addmod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -641,8 +714,10 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -655,8 +730,10 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let z := + |) + |) in + let _ := M.assign_local (| + "z" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -669,7 +746,8 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -687,18 +765,21 @@ Definition addmod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -711,7 +792,8 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -742,7 +824,8 @@ Definition mulmod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -755,8 +838,10 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -769,8 +854,10 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let z := + |) + |) in + let _ := M.assign_local (| + "z" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -783,7 +870,8 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -801,18 +889,21 @@ Definition mulmod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -825,7 +916,8 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -856,7 +948,8 @@ Definition exp : Value.t -> Value.t -> M := The current EVM frame. " in - let base := + let _ := M.assign_local (| + "base" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -869,8 +962,10 @@ Definition exp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exponent := + |) + |) in + let _ := M.assign_local (| + "exponent" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -883,21 +978,26 @@ Definition exp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exponent_bits := + |) + |) in + let _ := M.assign_local (| + "exponent_bits" , M.call (| M.get_field (| M.get_name (| globals, "exponent" |), "bit_length" |), make_list [], make_dict [] - |) in - let exponent_bytes := + |) + |) in + let _ := M.assign_local (| + "exponent_bytes" , BinOp.floor_div (| BinOp.add (| M.get_name (| globals, "exponent_bits" |), Constant.int 7 |), Constant.int 8 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -912,7 +1012,8 @@ Definition exp : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -927,7 +1028,8 @@ Definition exp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -956,22 +1058,26 @@ Definition signextend : Value.t -> Value.t -> M := The current EVM frame. " in - let byte_num := + let _ := M.assign_local (| + "byte_num" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -989,12 +1095,15 @@ Definition signextend : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := - M.get_name (| globals, "value" |) in + let _ := M.assign_local (| + "result" , + M.get_name (| globals, "value" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let value_bytes := + let _ := M.assign_local (| + "value_bytes" , M.call (| M.get_name (| globals, "bytes" |), make_list [ @@ -1005,8 +1114,10 @@ Definition signextend : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let value_bytes := + |) + |) in + let _ := M.assign_local (| + "value_bytes" , M.slice (| M.get_name (| globals, "value_bytes" |), BinOp.sub (| @@ -1021,15 +1132,18 @@ Definition signextend : Value.t -> Value.t -> M := |), Constant.None_, Constant.None_ - |) in - let sign_bit := + |) + |) in + let _ := M.assign_local (| + "sign_bit" , BinOp.r_shift (| M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), Constant.int 7 - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1039,26 +1153,31 @@ Definition signextend : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "value_bytes" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let num_bytes_prepend := + let _ := M.assign_local (| + "num_bytes_prepend" , BinOp.sub (| Constant.int 32, BinOp.add (| M.get_name (| globals, "byte_num" |), Constant.int 1 |) - |) in - let result := + |) + |) in + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -1079,7 +1198,8 @@ Definition signextend : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/bitwise.v b/CoqOfPython/ethereum/istanbul/vm/instructions/bitwise.v index f83e61e..cf2b256 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/bitwise.v @@ -17,17 +17,23 @@ Introduction Implementations of the EVM bitwise instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "U256_CEIL_VALUE" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_U256_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U256_CEIL_VALUE". -Axiom ethereum_istanbul_vm_imports : - AreImported globals "ethereum.istanbul.vm" [ "Evm" ]. +Axiom ethereum_istanbul_vm_imports_Evm : + IsImported globals "ethereum.istanbul.vm" "Evm". -Axiom ethereum_istanbul_vm_gas_imports : - AreImported globals "ethereum.istanbul.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_istanbul_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_istanbul_vm_gas_imports_charge_gas : + IsImported globals "ethereum.istanbul.vm.gas" "charge_gas". -Axiom ethereum_istanbul_vm_stack_imports : - AreImported globals "ethereum.istanbul.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_istanbul_vm_stack_imports_pop : + IsImported globals "ethereum.istanbul.vm.stack" "pop". +Axiom ethereum_istanbul_vm_stack_imports_push : + IsImported globals "ethereum.istanbul.vm.stack" "push". Definition bitwise_and : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,22 +48,26 @@ Definition bitwise_and : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -97,22 +107,26 @@ Definition bitwise_or : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -152,22 +166,26 @@ Definition bitwise_xor : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -207,14 +225,16 @@ Definition bitwise_not : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -252,22 +272,26 @@ Definition get_byte : Value.t -> Value.t -> M := The current EVM frame. " in - let byte_index := + let _ := M.assign_local (| + "byte_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let word := + |) + |) in + let _ := M.assign_local (| + "word" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -285,43 +309,53 @@ Definition get_byte : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let extra_bytes_to_right := + let _ := M.assign_local (| + "extra_bytes_to_right" , BinOp.sub (| Constant.int 31, M.get_name (| globals, "byte_index" |) - |) in - let word := + |) + |) in + let _ := M.assign_local (| + "word" , BinOp.r_shift (| M.get_name (| globals, "word" |), BinOp.mult (| M.get_name (| globals, "extra_bytes_to_right" |), Constant.int 8 |) - |) in - let word := + |) + |) in + let _ := M.assign_local (| + "word" , BinOp.bit_and (| M.get_name (| globals, "word" |), Constant.int 255 - |) in - let result := + |) + |) in + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ M.get_name (| globals, "word" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -350,22 +384,26 @@ Definition bitwise_shl : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let shift := + let _ := M.assign_local (| + "shift" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -383,7 +421,8 @@ Definition bitwise_shl : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -396,18 +435,21 @@ Definition bitwise_shl : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -436,22 +478,26 @@ Definition bitwise_shr : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let shift := + let _ := M.assign_local (| + "shift" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -469,22 +515,26 @@ Definition bitwise_shr : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , BinOp.r_shift (| M.get_name (| globals, "value" |), M.get_name (| globals, "shift" |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -513,15 +563,18 @@ Definition bitwise_sar : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let shift := + let _ := M.assign_local (| + "shift" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let signed_value := + |) + |) in + let _ := M.assign_local (| + "signed_value" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -532,7 +585,8 @@ Definition bitwise_sar : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -550,7 +604,8 @@ Definition bitwise_sar : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), make_list [ @@ -560,7 +615,8 @@ Definition bitwise_sar : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -573,19 +629,23 @@ Definition bitwise_sar : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := - M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) in + let _ := M.assign_local (| + "result" , + M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/block.v b/CoqOfPython/ethereum/istanbul/vm/instructions/block.v index 1e79e21..9b0f81f 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/block.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/block.v @@ -17,17 +17,23 @@ Introduction Implementations of the EVM block instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_istanbul_vm_imports : - AreImported globals "ethereum.istanbul.vm" [ "Evm" ]. +Axiom ethereum_istanbul_vm_imports_Evm : + IsImported globals "ethereum.istanbul.vm" "Evm". -Axiom ethereum_istanbul_vm_gas_imports : - AreImported globals "ethereum.istanbul.vm.gas" [ "GAS_BASE"; "GAS_BLOCK_HASH"; "charge_gas" ]. +Axiom ethereum_istanbul_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_BASE". +Axiom ethereum_istanbul_vm_gas_imports_GAS_BLOCK_HASH : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_BLOCK_HASH". +Axiom ethereum_istanbul_vm_gas_imports_charge_gas : + IsImported globals "ethereum.istanbul.vm.gas" "charge_gas". -Axiom ethereum_istanbul_vm_stack_imports : - AreImported globals "ethereum.istanbul.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_istanbul_vm_stack_imports_pop : + IsImported globals "ethereum.istanbul.vm.stack" "pop". +Axiom ethereum_istanbul_vm_stack_imports_push : + IsImported globals "ethereum.istanbul.vm.stack" "push". Definition block_hash : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,14 +48,16 @@ Definition block_hash : Value.t -> Value.t -> M := The current EVM frame. " in - let block_number := + let _ := M.assign_local (| + "block_number" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -78,19 +86,23 @@ Definition block_hash : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let hash := - Constant.bytes "00" in + let _ := M.assign_local (| + "hash" , + Constant.bytes "00" + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let hash := + let _ := M.assign_local (| + "hash" , M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), M.get_name (| globals, "block_number" |) |) |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/comparison.v b/CoqOfPython/ethereum/istanbul/vm/instructions/comparison.v index 2f35a57..3ddb9b3 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/comparison.v @@ -17,17 +17,21 @@ Introduction Implementations of the EVM Comparison instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_istanbul_vm_imports : - AreImported globals "ethereum.istanbul.vm" [ "Evm" ]. +Axiom ethereum_istanbul_vm_imports_Evm : + IsImported globals "ethereum.istanbul.vm" "Evm". -Axiom ethereum_istanbul_vm_gas_imports : - AreImported globals "ethereum.istanbul.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_istanbul_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_istanbul_vm_gas_imports_charge_gas : + IsImported globals "ethereum.istanbul.vm.gas" "charge_gas". -Axiom ethereum_istanbul_vm_stack_imports : - AreImported globals "ethereum.istanbul.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_istanbul_vm_stack_imports_pop : + IsImported globals "ethereum.istanbul.vm.stack" "pop". +Axiom ethereum_istanbul_vm_stack_imports_push : + IsImported globals "ethereum.istanbul.vm.stack" "push". Definition less_than : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,22 +46,26 @@ Definition less_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -66,7 +74,8 @@ Definition less_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -76,7 +85,8 @@ Definition less_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -104,7 +114,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -115,8 +126,10 @@ Definition signed_less_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -127,7 +140,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -136,7 +150,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -146,7 +161,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -175,22 +191,26 @@ Definition greater_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -199,7 +219,8 @@ Definition greater_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -209,7 +230,8 @@ Definition greater_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -237,7 +259,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -248,8 +271,10 @@ Definition signed_greater_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -260,7 +285,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -269,7 +295,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -279,7 +306,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -308,22 +336,26 @@ Definition equal : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -332,7 +364,8 @@ Definition equal : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -342,7 +375,8 @@ Definition equal : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -371,14 +405,16 @@ Definition is_zero : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -387,7 +423,8 @@ Definition is_zero : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -397,7 +434,8 @@ Definition is_zero : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/control_flow.v b/CoqOfPython/ethereum/istanbul/vm/instructions/control_flow.v index b53d5d1..540d4de 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/control_flow.v @@ -17,20 +17,32 @@ Introduction Implementations of the EVM control flow instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_istanbul_vm_gas_imports : - AreImported globals "ethereum.istanbul.vm.gas" [ "GAS_BASE"; "GAS_HIGH"; "GAS_JUMPDEST"; "GAS_MID"; "charge_gas" ]. +Axiom ethereum_istanbul_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_BASE". +Axiom ethereum_istanbul_vm_gas_imports_GAS_HIGH : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_HIGH". +Axiom ethereum_istanbul_vm_gas_imports_GAS_JUMPDEST : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_JUMPDEST". +Axiom ethereum_istanbul_vm_gas_imports_GAS_MID : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_MID". +Axiom ethereum_istanbul_vm_gas_imports_charge_gas : + IsImported globals "ethereum.istanbul.vm.gas" "charge_gas". -Axiom ethereum_istanbul_vm_imports : - AreImported globals "ethereum.istanbul.vm" [ "Evm" ]. +Axiom ethereum_istanbul_vm_imports_Evm : + IsImported globals "ethereum.istanbul.vm" "Evm". -Axiom ethereum_istanbul_vm_exceptions_imports : - AreImported globals "ethereum.istanbul.vm.exceptions" [ "InvalidJumpDestError" ]. +Axiom ethereum_istanbul_vm_exceptions_imports_InvalidJumpDestError : + IsImported globals "ethereum.istanbul.vm.exceptions" "InvalidJumpDestError". -Axiom ethereum_istanbul_vm_stack_imports : - AreImported globals "ethereum.istanbul.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_istanbul_vm_stack_imports_pop : + IsImported globals "ethereum.istanbul.vm.stack" "pop". +Axiom ethereum_istanbul_vm_stack_imports_push : + IsImported globals "ethereum.istanbul.vm.stack" "push". Definition stop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -69,7 +81,8 @@ Definition jump : Value.t -> Value.t -> M := The current EVM frame. " in - let jump_dest := + let _ := M.assign_local (| + "jump_dest" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -82,7 +95,8 @@ Definition jump : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -132,7 +146,8 @@ Definition jumpi : Value.t -> Value.t -> M := The current EVM frame. " in - let jump_dest := + let _ := M.assign_local (| + "jump_dest" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -145,15 +160,18 @@ Definition jumpi : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let conditional_value := + |) + |) in + let _ := M.assign_local (| + "conditional_value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -171,11 +189,13 @@ Definition jumpi : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let destination := + let _ := M.assign_local (| + "destination" , BinOp.add (| M.get_field (| M.get_name (| globals, "evm" |), "pc" |), Constant.int 1 - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -192,8 +212,10 @@ Definition jumpi : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let destination := - M.get_name (| globals, "jump_dest" |) in + let _ := M.assign_local (| + "destination" , + M.get_name (| globals, "jump_dest" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/environment.v b/CoqOfPython/ethereum/istanbul/vm/instructions/environment.v index 7311123..6cda0d2 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/environment.v @@ -17,41 +17,65 @@ Introduction Implementations of the EVM environment related instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. - -Axiom ethereum_istanbul_fork_types_imports : - AreImported globals "ethereum.istanbul.fork_types" [ "EMPTY_ACCOUNT" ]. - -Axiom ethereum_istanbul_state_imports : - AreImported globals "ethereum.istanbul.state" [ "get_account" ]. - -Axiom ethereum_istanbul_utils_address_imports : - AreImported globals "ethereum.istanbul.utils.address" [ "to_address" ]. - -Axiom ethereum_istanbul_vm_memory_imports : - AreImported globals "ethereum.istanbul.vm.memory" [ "buffer_read"; "memory_write" ]. - -Axiom ethereum_istanbul_vm_imports : - AreImported globals "ethereum.istanbul.vm" [ "Evm" ]. - -Axiom ethereum_istanbul_vm_exceptions_imports : - AreImported globals "ethereum.istanbul.vm.exceptions" [ "OutOfBoundsRead" ]. - -Axiom ethereum_istanbul_vm_gas_imports : - AreImported globals "ethereum.istanbul.vm.gas" [ "GAS_BALANCE"; "GAS_BASE"; "GAS_CODE_HASH"; "GAS_COPY"; "GAS_EXTERNAL"; "GAS_FAST_STEP"; "GAS_RETURN_DATA_COPY"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. - -Axiom ethereum_istanbul_vm_stack_imports : - AreImported globals "ethereum.istanbul.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". + +Axiom ethereum_istanbul_fork_types_imports_EMPTY_ACCOUNT : + IsImported globals "ethereum.istanbul.fork_types" "EMPTY_ACCOUNT". + +Axiom ethereum_istanbul_state_imports_get_account : + IsImported globals "ethereum.istanbul.state" "get_account". + +Axiom ethereum_istanbul_utils_address_imports_to_address : + IsImported globals "ethereum.istanbul.utils.address" "to_address". + +Axiom ethereum_istanbul_vm_memory_imports_buffer_read : + IsImported globals "ethereum.istanbul.vm.memory" "buffer_read". +Axiom ethereum_istanbul_vm_memory_imports_memory_write : + IsImported globals "ethereum.istanbul.vm.memory" "memory_write". + +Axiom ethereum_istanbul_vm_imports_Evm : + IsImported globals "ethereum.istanbul.vm" "Evm". + +Axiom ethereum_istanbul_vm_exceptions_imports_OutOfBoundsRead : + IsImported globals "ethereum.istanbul.vm.exceptions" "OutOfBoundsRead". + +Axiom ethereum_istanbul_vm_gas_imports_GAS_BALANCE : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_BALANCE". +Axiom ethereum_istanbul_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_BASE". +Axiom ethereum_istanbul_vm_gas_imports_GAS_CODE_HASH : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_CODE_HASH". +Axiom ethereum_istanbul_vm_gas_imports_GAS_COPY : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_COPY". +Axiom ethereum_istanbul_vm_gas_imports_GAS_EXTERNAL : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_EXTERNAL". +Axiom ethereum_istanbul_vm_gas_imports_GAS_FAST_STEP : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_FAST_STEP". +Axiom ethereum_istanbul_vm_gas_imports_GAS_RETURN_DATA_COPY : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_RETURN_DATA_COPY". +Axiom ethereum_istanbul_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_istanbul_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.istanbul.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_istanbul_vm_gas_imports_charge_gas : + IsImported globals "ethereum.istanbul.vm.gas" "charge_gas". + +Axiom ethereum_istanbul_vm_stack_imports_pop : + IsImported globals "ethereum.istanbul.vm.stack" "pop". +Axiom ethereum_istanbul_vm_stack_imports_push : + IsImported globals "ethereum.istanbul.vm.stack" "push". Definition address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -107,7 +131,8 @@ Definition balance : Value.t -> Value.t -> M := The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -120,7 +145,8 @@ Definition balance : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -129,7 +155,8 @@ Definition balance : Value.t -> Value.t -> M := ], make_dict [] |) in - let balance := + let _ := M.assign_local (| + "balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -137,7 +164,8 @@ Definition balance : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -287,14 +315,16 @@ Definition calldataload : Value.t -> Value.t -> M := The current EVM frame. " in - let start_index := + let _ := M.assign_local (| + "start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -303,7 +333,8 @@ Definition calldataload : Value.t -> Value.t -> M := ], make_dict [] |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -318,7 +349,8 @@ Definition calldataload : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -403,31 +435,38 @@ Definition calldatacopy : Value.t -> Value.t -> M := The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let data_start_index := + |) + |) in + let _ := M.assign_local (| + "data_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -443,13 +482,17 @@ Definition calldatacopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -459,7 +502,8 @@ Definition calldatacopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -482,7 +526,8 @@ Definition calldatacopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -491,7 +536,8 @@ Definition calldatacopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -571,31 +617,38 @@ Definition codecopy : Value.t -> Value.t -> M := The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let code_start_index := + |) + |) in + let _ := M.assign_local (| + "code_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -611,13 +664,17 @@ Definition codecopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -627,7 +684,8 @@ Definition codecopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -650,7 +708,8 @@ Definition codecopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -659,7 +718,8 @@ Definition codecopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -730,7 +790,8 @@ Definition extcodesize : Value.t -> Value.t -> M := The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -743,7 +804,8 @@ Definition extcodesize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -752,7 +814,8 @@ Definition extcodesize : Value.t -> Value.t -> M := ], make_dict [] |) in - let codesize := + let _ := M.assign_local (| + "codesize" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -772,7 +835,8 @@ Definition extcodesize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -800,7 +864,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -813,32 +878,40 @@ Definition extcodecopy : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let memory_start_index := + |) + |) in + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let code_start_index := + |) + |) in + let _ := M.assign_local (| + "code_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -854,13 +927,17 @@ Definition extcodecopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -870,7 +947,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -893,7 +971,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let code := + let _ := M.assign_local (| + "code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -901,8 +980,10 @@ Definition extcodecopy : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |), "code" |) in - let value := + |), "code" |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -911,7 +992,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -986,31 +1068,38 @@ Definition returndatacopy : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let return_data_start_position := + |) + |) in + let _ := M.assign_local (| + "return_data_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -1026,13 +1115,17 @@ Definition returndatacopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_RETURN_DATA_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1042,7 +1135,8 @@ Definition returndatacopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1097,7 +1191,8 @@ Definition returndatacopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.slice (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |), @@ -1106,7 +1201,8 @@ Definition returndatacopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) |), Constant.None_ - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -1133,7 +1229,8 @@ Definition extcodehash : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1146,7 +1243,8 @@ Definition extcodehash : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1155,7 +1253,8 @@ Definition extcodehash : Value.t -> Value.t -> M := ], make_dict [] |) in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1163,7 +1262,8 @@ Definition extcodehash : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1173,18 +1273,21 @@ Definition extcodehash : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let codehash := + let _ := M.assign_local (| + "codehash" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let codehash := + let _ := M.assign_local (| + "codehash" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -1197,7 +1300,8 @@ Definition extcodehash : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -1236,7 +1340,8 @@ Definition self_balance : Value.t -> Value.t -> M := ], make_dict [] |) in - let balance := + let _ := M.assign_local (| + "balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1244,7 +1349,8 @@ Definition self_balance : Value.t -> Value.t -> M := M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/keccak.v b/CoqOfPython/ethereum/istanbul/vm/instructions/keccak.v index b21b84d..e4fa0c2 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/keccak.v @@ -17,26 +17,36 @@ Introduction Implementations of the EVM keccak instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_istanbul_vm_imports : - AreImported globals "ethereum.istanbul.vm" [ "Evm" ]. +Axiom ethereum_istanbul_vm_imports_Evm : + IsImported globals "ethereum.istanbul.vm" "Evm". -Axiom ethereum_istanbul_vm_gas_imports : - AreImported globals "ethereum.istanbul.vm.gas" [ "GAS_KECCAK256"; "GAS_KECCAK256_WORD"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_istanbul_vm_gas_imports_GAS_KECCAK256 : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_KECCAK256". +Axiom ethereum_istanbul_vm_gas_imports_GAS_KECCAK256_WORD : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_KECCAK256_WORD". +Axiom ethereum_istanbul_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.istanbul.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_istanbul_vm_gas_imports_charge_gas : + IsImported globals "ethereum.istanbul.vm.gas" "charge_gas". -Axiom ethereum_istanbul_vm_memory_imports : - AreImported globals "ethereum.istanbul.vm.memory" [ "memory_read_bytes" ]. +Axiom ethereum_istanbul_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.istanbul.vm.memory" "memory_read_bytes". -Axiom ethereum_istanbul_vm_stack_imports : - AreImported globals "ethereum.istanbul.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_istanbul_vm_stack_imports_pop : + IsImported globals "ethereum.istanbul.vm.stack" "pop". +Axiom ethereum_istanbul_vm_stack_imports_push : + IsImported globals "ethereum.istanbul.vm.stack" "push". Definition keccak : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -53,23 +63,28 @@ Definition keccak : Value.t -> Value.t -> M := The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -85,13 +100,17 @@ Definition keccak : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let word_gas_cost := + |) + |) in + let _ := M.assign_local (| + "word_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_KECCAK256_WORD" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -101,7 +120,8 @@ Definition keccak : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -124,7 +144,8 @@ Definition keccak : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let data := + let _ := M.assign_local (| + "data" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -133,15 +154,18 @@ Definition keccak : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in - let hash := + |) + |) in + let _ := M.assign_local (| + "hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "data" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/log.v b/CoqOfPython/ethereum/istanbul/vm/instructions/log.v index 14591b8..8471fb8 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/log.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/log.v @@ -17,32 +17,40 @@ Introduction Implementations of the EVM logging instructions. ". -Axiom functools_imports : - AreImported globals "functools" [ "partial" ]. +Axiom functools_imports_partial : + IsImported globals "functools" "partial". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_istanbul_blocks_imports : - AreImported globals "ethereum.istanbul.blocks" [ "Log" ]. +Axiom ethereum_istanbul_blocks_imports_Log : + IsImported globals "ethereum.istanbul.blocks" "Log". -Axiom ethereum_istanbul_vm_imports : - AreImported globals "ethereum.istanbul.vm" [ "Evm" ]. +Axiom ethereum_istanbul_vm_imports_Evm : + IsImported globals "ethereum.istanbul.vm" "Evm". -Axiom ethereum_istanbul_vm_exceptions_imports : - AreImported globals "ethereum.istanbul.vm.exceptions" [ "WriteInStaticContext" ]. +Axiom ethereum_istanbul_vm_exceptions_imports_WriteInStaticContext : + IsImported globals "ethereum.istanbul.vm.exceptions" "WriteInStaticContext". -Axiom ethereum_istanbul_vm_gas_imports : - AreImported globals "ethereum.istanbul.vm.gas" [ "GAS_LOG"; "GAS_LOG_DATA"; "GAS_LOG_TOPIC"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_istanbul_vm_gas_imports_GAS_LOG : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_LOG". +Axiom ethereum_istanbul_vm_gas_imports_GAS_LOG_DATA : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_LOG_DATA". +Axiom ethereum_istanbul_vm_gas_imports_GAS_LOG_TOPIC : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_LOG_TOPIC". +Axiom ethereum_istanbul_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.istanbul.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_istanbul_vm_gas_imports_charge_gas : + IsImported globals "ethereum.istanbul.vm.gas" "charge_gas". -Axiom ethereum_istanbul_vm_memory_imports : - AreImported globals "ethereum.istanbul.vm.memory" [ "memory_read_bytes" ]. +Axiom ethereum_istanbul_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.istanbul.vm.memory" "memory_read_bytes". -Axiom ethereum_istanbul_vm_stack_imports : - AreImported globals "ethereum.istanbul.vm.stack" [ "pop" ]. +Axiom ethereum_istanbul_vm_stack_imports_pop : + IsImported globals "ethereum.istanbul.vm.stack" "pop". Definition log_n : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -61,24 +69,30 @@ Definition log_n : Value.t -> Value.t -> M := The number of topics to be included in the log entry. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let topics := - make_list [] in + |) + |) in + let _ := M.assign_local (| + "topics" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "_" |), @@ -90,7 +104,8 @@ Definition log_n : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let topic := + let _ := M.assign_local (| + "topic" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -101,7 +116,8 @@ Definition log_n : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "topics" |), "append" |), make_list [ @@ -115,7 +131,8 @@ Definition log_n : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let extend_memory := + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -125,7 +142,8 @@ Definition log_n : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -165,12 +183,14 @@ Definition log_n : Value.t -> Value.t -> M := ], make_dict [] |) in - let log_entry := + let _ := M.assign_local (| + "log_entry" , M.call (| M.get_name (| globals, "Log" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "logs" |), BinOp.add (| diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/memory.v b/CoqOfPython/ethereum/istanbul/vm/instructions/memory.v index e214883..139811a 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/memory.v @@ -17,20 +17,32 @@ Introduction Implementations of the EVM Memory instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". -Axiom ethereum_istanbul_vm_imports : - AreImported globals "ethereum.istanbul.vm" [ "Evm" ]. +Axiom ethereum_istanbul_vm_imports_Evm : + IsImported globals "ethereum.istanbul.vm" "Evm". -Axiom ethereum_istanbul_vm_gas_imports : - AreImported globals "ethereum.istanbul.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_istanbul_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_BASE". +Axiom ethereum_istanbul_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_istanbul_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.istanbul.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_istanbul_vm_gas_imports_charge_gas : + IsImported globals "ethereum.istanbul.vm.gas" "charge_gas". -Axiom ethereum_istanbul_vm_memory_imports : - AreImported globals "ethereum.istanbul.vm.memory" [ "memory_read_bytes"; "memory_write" ]. +Axiom ethereum_istanbul_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.istanbul.vm.memory" "memory_read_bytes". +Axiom ethereum_istanbul_vm_memory_imports_memory_write : + IsImported globals "ethereum.istanbul.vm.memory" "memory_write". -Axiom ethereum_istanbul_vm_stack_imports : - AreImported globals "ethereum.istanbul.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_istanbul_vm_stack_imports_pop : + IsImported globals "ethereum.istanbul.vm.stack" "pop". +Axiom ethereum_istanbul_vm_stack_imports_push : + IsImported globals "ethereum.istanbul.vm.stack" "push". Definition mstore : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -46,15 +58,18 @@ Definition mstore : Value.t -> Value.t -> M := The current EVM frame. " in - let start_position := + let _ := M.assign_local (| + "start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -65,8 +80,10 @@ Definition mstore : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -88,7 +105,8 @@ Definition mstore : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -138,23 +156,28 @@ Definition mstore8 : Value.t -> Value.t -> M := The current EVM frame. " in - let start_position := + let _ := M.assign_local (| + "start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -170,7 +193,8 @@ Definition mstore8 : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -190,7 +214,8 @@ Definition mstore8 : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let normalized_bytes_value := + let _ := M.assign_local (| + "normalized_bytes_value" , M.call (| M.get_name (| globals, "Bytes" |), make_list [ @@ -202,7 +227,8 @@ Definition mstore8 : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -231,15 +257,18 @@ Definition mload : Value.t -> Value.t -> M := The current EVM frame. " in - let start_position := + let _ := M.assign_local (| + "start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -255,7 +284,8 @@ Definition mload : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -275,7 +305,8 @@ Definition mload : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -296,7 +327,8 @@ Definition mload : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/stack.v b/CoqOfPython/ethereum/istanbul/vm/instructions/stack.v index 90b7219..36a6974 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/stack.v @@ -17,26 +17,32 @@ Introduction Implementations of the EVM stack related instructions. ". -Axiom functools_imports : - AreImported globals "functools" [ "partial" ]. +Axiom functools_imports_partial : + IsImported globals "functools" "partial". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_istanbul_vm_imports : - AreImported globals "ethereum.istanbul.vm" [ "Evm"; "stack" ]. +Axiom ethereum_istanbul_vm_imports_Evm : + IsImported globals "ethereum.istanbul.vm" "Evm". +Axiom ethereum_istanbul_vm_imports_stack : + IsImported globals "ethereum.istanbul.vm" "stack". -Axiom ethereum_istanbul_vm_exceptions_imports : - AreImported globals "ethereum.istanbul.vm.exceptions" [ "StackUnderflowError" ]. +Axiom ethereum_istanbul_vm_exceptions_imports_StackUnderflowError : + IsImported globals "ethereum.istanbul.vm.exceptions" "StackUnderflowError". -Axiom ethereum_istanbul_vm_gas_imports : - AreImported globals "ethereum.istanbul.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_istanbul_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_BASE". +Axiom ethereum_istanbul_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_istanbul_vm_gas_imports_charge_gas : + IsImported globals "ethereum.istanbul.vm.gas" "charge_gas". -Axiom ethereum_istanbul_vm_memory_imports : - AreImported globals "ethereum.istanbul.vm.memory" [ "buffer_read" ]. +Axiom ethereum_istanbul_vm_memory_imports_buffer_read : + IsImported globals "ethereum.istanbul.vm.memory" "buffer_read". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -98,7 +104,8 @@ Definition push_n : Value.t -> Value.t -> M := ], make_dict [] |) in - let data_to_push := + let _ := M.assign_local (| + "data_to_push" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -128,7 +135,8 @@ Definition push_n : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "stack" |), "push" |), make_list [ @@ -189,7 +197,8 @@ Definition dup_n : Value.t -> Value.t -> M := ], make_dict [] |) in - let data_to_duplicate := + let _ := M.assign_local (| + "data_to_duplicate" , M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| @@ -205,7 +214,8 @@ Definition dup_n : Value.t -> Value.t -> M := |), M.get_name (| globals, "item_number" |) |) - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "stack" |), "push" |), make_list [ diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/storage.v b/CoqOfPython/ethereum/istanbul/vm/instructions/storage.v index 11a5c83..e5e7cdf 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/storage.v @@ -17,23 +17,41 @@ Introduction Implementations of the EVM storage related instructions. ". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_istanbul_state_imports : - AreImported globals "ethereum.istanbul.state" [ "get_storage"; "get_storage_original"; "set_storage" ]. +Axiom ethereum_istanbul_state_imports_get_storage : + IsImported globals "ethereum.istanbul.state" "get_storage". +Axiom ethereum_istanbul_state_imports_get_storage_original : + IsImported globals "ethereum.istanbul.state" "get_storage_original". +Axiom ethereum_istanbul_state_imports_set_storage : + IsImported globals "ethereum.istanbul.state" "set_storage". -Axiom ethereum_istanbul_vm_imports : - AreImported globals "ethereum.istanbul.vm" [ "Evm" ]. +Axiom ethereum_istanbul_vm_imports_Evm : + IsImported globals "ethereum.istanbul.vm" "Evm". -Axiom ethereum_istanbul_vm_exceptions_imports : - AreImported globals "ethereum.istanbul.vm.exceptions" [ "OutOfGasError"; "WriteInStaticContext" ]. +Axiom ethereum_istanbul_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.istanbul.vm.exceptions" "OutOfGasError". +Axiom ethereum_istanbul_vm_exceptions_imports_WriteInStaticContext : + IsImported globals "ethereum.istanbul.vm.exceptions" "WriteInStaticContext". -Axiom ethereum_istanbul_vm_gas_imports : - AreImported globals "ethereum.istanbul.vm.gas" [ "GAS_CALL_STIPEND"; "GAS_SLOAD"; "GAS_STORAGE_CLEAR_REFUND"; "GAS_STORAGE_SET"; "GAS_STORAGE_UPDATE"; "charge_gas" ]. +Axiom ethereum_istanbul_vm_gas_imports_GAS_CALL_STIPEND : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_CALL_STIPEND". +Axiom ethereum_istanbul_vm_gas_imports_GAS_SLOAD : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_SLOAD". +Axiom ethereum_istanbul_vm_gas_imports_GAS_STORAGE_CLEAR_REFUND : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_STORAGE_CLEAR_REFUND". +Axiom ethereum_istanbul_vm_gas_imports_GAS_STORAGE_SET : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_STORAGE_SET". +Axiom ethereum_istanbul_vm_gas_imports_GAS_STORAGE_UPDATE : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_STORAGE_UPDATE". +Axiom ethereum_istanbul_vm_gas_imports_charge_gas : + IsImported globals "ethereum.istanbul.vm.gas" "charge_gas". -Axiom ethereum_istanbul_vm_stack_imports : - AreImported globals "ethereum.istanbul.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_istanbul_vm_stack_imports_pop : + IsImported globals "ethereum.istanbul.vm.stack" "pop". +Axiom ethereum_istanbul_vm_stack_imports_push : + IsImported globals "ethereum.istanbul.vm.stack" "push". Definition sload : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -48,7 +66,8 @@ Definition sload : Value.t -> Value.t -> M := The current EVM frame. " in - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -59,7 +78,8 @@ Definition sload : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -68,7 +88,8 @@ Definition sload : Value.t -> Value.t -> M := ], make_dict [] |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "get_storage" |), make_list [ @@ -77,7 +98,8 @@ Definition sload : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -105,7 +127,8 @@ Definition sstore : Value.t -> Value.t -> M := The current EVM frame. " in - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -116,15 +139,18 @@ Definition sstore : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in - let new_value := + |) + |) in + let _ := M.assign_local (| + "new_value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -136,7 +162,8 @@ Definition sstore : Value.t -> Value.t -> M := ], make_dict [] |) in - let original_value := + let _ := M.assign_local (| + "original_value" , M.call (| M.get_name (| globals, "get_storage_original" |), make_list [ @@ -145,8 +172,10 @@ Definition sstore : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in - let current_value := + |) + |) in + let _ := M.assign_local (| + "current_value" , M.call (| M.get_name (| globals, "get_storage" |), make_list [ @@ -155,7 +184,8 @@ Definition sstore : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -182,20 +212,26 @@ Definition sstore : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let gas_cost := - M.get_name (| globals, "GAS_STORAGE_SET" |) in + let _ := M.assign_local (| + "gas_cost" , + M.get_name (| globals, "GAS_STORAGE_SET" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let gas_cost := - M.get_name (| globals, "GAS_STORAGE_UPDATE" |) in + let _ := M.assign_local (| + "gas_cost" , + M.get_name (| globals, "GAS_STORAGE_UPDATE" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let gas_cost := - M.get_name (| globals, "GAS_SLOAD" |) in + let _ := M.assign_local (| + "gas_cost" , + M.get_name (| globals, "GAS_SLOAD" |) + |) in M.pure Constant.None_ )) |) in let _ := diff --git a/CoqOfPython/ethereum/istanbul/vm/instructions/system.v b/CoqOfPython/ethereum/istanbul/vm/instructions/system.v index 3e57a51..04f4e5a 100644 --- a/CoqOfPython/ethereum/istanbul/vm/instructions/system.v +++ b/CoqOfPython/ethereum/istanbul/vm/instructions/system.v @@ -17,38 +17,92 @@ Introduction Implementations of the EVM system related instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_istanbul_fork_types_imports : - AreImported globals "ethereum.istanbul.fork_types" [ "Address" ]. +Axiom ethereum_istanbul_fork_types_imports_Address : + IsImported globals "ethereum.istanbul.fork_types" "Address". -Axiom ethereum_istanbul_state_imports : - AreImported globals "ethereum.istanbul.state" [ "account_exists_and_is_empty"; "account_has_code_or_nonce"; "get_account"; "increment_nonce"; "is_account_alive"; "set_account_balance" ]. +Axiom ethereum_istanbul_state_imports_account_exists_and_is_empty : + IsImported globals "ethereum.istanbul.state" "account_exists_and_is_empty". +Axiom ethereum_istanbul_state_imports_account_has_code_or_nonce : + IsImported globals "ethereum.istanbul.state" "account_has_code_or_nonce". +Axiom ethereum_istanbul_state_imports_get_account : + IsImported globals "ethereum.istanbul.state" "get_account". +Axiom ethereum_istanbul_state_imports_increment_nonce : + IsImported globals "ethereum.istanbul.state" "increment_nonce". +Axiom ethereum_istanbul_state_imports_is_account_alive : + IsImported globals "ethereum.istanbul.state" "is_account_alive". +Axiom ethereum_istanbul_state_imports_set_account_balance : + IsImported globals "ethereum.istanbul.state" "set_account_balance". -Axiom ethereum_istanbul_utils_address_imports : - AreImported globals "ethereum.istanbul.utils.address" [ "compute_contract_address"; "compute_create2_contract_address"; "to_address" ]. +Axiom ethereum_istanbul_utils_address_imports_compute_contract_address : + IsImported globals "ethereum.istanbul.utils.address" "compute_contract_address". +Axiom ethereum_istanbul_utils_address_imports_compute_create2_contract_address : + IsImported globals "ethereum.istanbul.utils.address" "compute_create2_contract_address". +Axiom ethereum_istanbul_utils_address_imports_to_address : + IsImported globals "ethereum.istanbul.utils.address" "to_address". -Axiom ethereum_istanbul_vm_imports : - AreImported globals "ethereum.istanbul.vm" [ "Evm"; "Message"; "incorporate_child_on_error"; "incorporate_child_on_success" ]. +Axiom ethereum_istanbul_vm_imports_Evm : + IsImported globals "ethereum.istanbul.vm" "Evm". +Axiom ethereum_istanbul_vm_imports_Message : + IsImported globals "ethereum.istanbul.vm" "Message". +Axiom ethereum_istanbul_vm_imports_incorporate_child_on_error : + IsImported globals "ethereum.istanbul.vm" "incorporate_child_on_error". +Axiom ethereum_istanbul_vm_imports_incorporate_child_on_success : + IsImported globals "ethereum.istanbul.vm" "incorporate_child_on_success". -Axiom ethereum_istanbul_vm_exceptions_imports : - AreImported globals "ethereum.istanbul.vm.exceptions" [ "Revert"; "WriteInStaticContext" ]. +Axiom ethereum_istanbul_vm_exceptions_imports_Revert : + IsImported globals "ethereum.istanbul.vm.exceptions" "Revert". +Axiom ethereum_istanbul_vm_exceptions_imports_WriteInStaticContext : + IsImported globals "ethereum.istanbul.vm.exceptions" "WriteInStaticContext". -Axiom ethereum_istanbul_vm_gas_imports : - AreImported globals "ethereum.istanbul.vm.gas" [ "GAS_CALL"; "GAS_CALL_VALUE"; "GAS_CREATE"; "GAS_KECCAK256_WORD"; "GAS_NEW_ACCOUNT"; "GAS_SELF_DESTRUCT"; "GAS_SELF_DESTRUCT_NEW_ACCOUNT"; "GAS_ZERO"; "REFUND_SELF_DESTRUCT"; "calculate_gas_extend_memory"; "calculate_message_call_gas"; "charge_gas"; "max_message_call_gas" ]. +Axiom ethereum_istanbul_vm_gas_imports_GAS_CALL : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_CALL". +Axiom ethereum_istanbul_vm_gas_imports_GAS_CALL_VALUE : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_CALL_VALUE". +Axiom ethereum_istanbul_vm_gas_imports_GAS_CREATE : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_CREATE". +Axiom ethereum_istanbul_vm_gas_imports_GAS_KECCAK256_WORD : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_KECCAK256_WORD". +Axiom ethereum_istanbul_vm_gas_imports_GAS_NEW_ACCOUNT : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_NEW_ACCOUNT". +Axiom ethereum_istanbul_vm_gas_imports_GAS_SELF_DESTRUCT : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_SELF_DESTRUCT". +Axiom ethereum_istanbul_vm_gas_imports_GAS_SELF_DESTRUCT_NEW_ACCOUNT : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_SELF_DESTRUCT_NEW_ACCOUNT". +Axiom ethereum_istanbul_vm_gas_imports_GAS_ZERO : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_ZERO". +Axiom ethereum_istanbul_vm_gas_imports_REFUND_SELF_DESTRUCT : + IsImported globals "ethereum.istanbul.vm.gas" "REFUND_SELF_DESTRUCT". +Axiom ethereum_istanbul_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.istanbul.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_istanbul_vm_gas_imports_calculate_message_call_gas : + IsImported globals "ethereum.istanbul.vm.gas" "calculate_message_call_gas". +Axiom ethereum_istanbul_vm_gas_imports_charge_gas : + IsImported globals "ethereum.istanbul.vm.gas" "charge_gas". +Axiom ethereum_istanbul_vm_gas_imports_max_message_call_gas : + IsImported globals "ethereum.istanbul.vm.gas" "max_message_call_gas". -Axiom ethereum_istanbul_vm_memory_imports : - AreImported globals "ethereum.istanbul.vm.memory" [ "memory_read_bytes"; "memory_write" ]. +Axiom ethereum_istanbul_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.istanbul.vm.memory" "memory_read_bytes". +Axiom ethereum_istanbul_vm_memory_imports_memory_write : + IsImported globals "ethereum.istanbul.vm.memory" "memory_write". -Axiom ethereum_istanbul_vm_stack_imports : - AreImported globals "ethereum.istanbul.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_istanbul_vm_stack_imports_pop : + IsImported globals "ethereum.istanbul.vm.stack" "pop". +Axiom ethereum_istanbul_vm_stack_imports_push : + IsImported globals "ethereum.istanbul.vm.stack" "push". Definition generic_create : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -57,7 +111,8 @@ Definition generic_create : Value.t -> Value.t -> M := Core logic used by the `CREATE*` family of opcodes. " in (* At stmt: unsupported node type: ImportFrom *) - let create_message_gas := + let _ := M.assign_local (| + "create_message_gas" , M.call (| M.get_name (| globals, "max_message_call_gas" |), make_list [ @@ -70,7 +125,8 @@ Definition generic_create : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.assign_op (| BinOp.sub, M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), @@ -88,9 +144,12 @@ Definition generic_create : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), Constant.bytes "" |) in - let sender_address := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in - let sender := + let _ := M.assign_local (| + "sender_address" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + |) in + let _ := M.assign_local (| + "sender" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -98,7 +157,8 @@ Definition generic_create : Value.t -> Value.t -> M := M.get_name (| globals, "sender_address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -209,7 +269,8 @@ Definition generic_create : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let call_data := + let _ := M.assign_local (| + "call_data" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -218,7 +279,8 @@ Definition generic_create : Value.t -> Value.t -> M := M.get_name (| globals, "memory_size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "increment_nonce" |), make_list [ @@ -227,13 +289,16 @@ Definition generic_create : Value.t -> Value.t -> M := ], make_dict [] |) in - let child_message := + let _ := M.assign_local (| + "child_message" , M.call (| M.get_name (| globals, "Message" |), make_list [], make_dict [] - |) in - let child_evm := + |) + |) in + let _ := M.assign_local (| + "child_evm" , M.call (| M.get_name (| globals, "process_create_message" |), make_list [ @@ -241,7 +306,8 @@ Definition generic_create : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -318,31 +384,38 @@ Definition create : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let endowment := + let _ := M.assign_local (| + "endowment" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_size := + |) + |) in + let _ := M.assign_local (| + "memory_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -352,7 +425,8 @@ Definition create : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -372,7 +446,8 @@ Definition create : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let contract_address := + let _ := M.assign_local (| + "contract_address" , M.call (| M.get_name (| globals, "compute_contract_address" |), make_list [ @@ -387,7 +462,8 @@ Definition create : Value.t -> Value.t -> M := |), "nonce" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "generic_create" |), make_list [ @@ -420,31 +496,38 @@ Definition create2 : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let endowment := + let _ := M.assign_local (| + "endowment" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_size := + |) + |) in + let _ := M.assign_local (| + "memory_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let salt := + |) + |) in + let _ := M.assign_local (| + "salt" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -455,8 +538,10 @@ Definition create2 : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -466,8 +551,10 @@ Definition create2 : Value.t -> Value.t -> M := ] ], make_dict [] - |) in - let call_data_words := + |) + |) in + let _ := M.assign_local (| + "call_data_words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -483,7 +570,8 @@ Definition create2 : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -509,7 +597,8 @@ Definition create2 : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let contract_address := + let _ := M.assign_local (| + "contract_address" , M.call (| M.get_name (| globals, "compute_create2_contract_address" |), make_list [ @@ -526,7 +615,8 @@ Definition create2 : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "generic_create" |), make_list [ @@ -556,23 +646,28 @@ Definition return_ : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let memory_start_position := + let _ := M.assign_local (| + "memory_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_size := + |) + |) in + let _ := M.assign_local (| + "memory_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -582,7 +677,8 @@ Definition return_ : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -671,7 +767,8 @@ Definition generic_call : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let call_data := + let _ := M.assign_local (| + "call_data" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -680,8 +777,10 @@ Definition generic_call : Value.t -> Value.t -> M := M.get_name (| globals, "memory_input_size" |) ], make_dict [] - |) in - let code := + |) + |) in + let _ := M.assign_local (| + "code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -689,14 +788,18 @@ Definition generic_call : Value.t -> Value.t -> M := M.get_name (| globals, "code_address" |) ], make_dict [] - |), "code" |) in - let child_message := + |), "code" |) + |) in + let _ := M.assign_local (| + "child_message" , M.call (| M.get_name (| globals, "Message" |), make_list [], make_dict [] - |) in - let child_evm := + |) + |) in + let _ := M.assign_local (| + "child_evm" , M.call (| M.get_name (| globals, "process_message" |), make_list [ @@ -704,7 +807,8 @@ Definition generic_call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -768,7 +872,8 @@ Definition generic_call : Value.t -> Value.t -> M := |) in M.pure Constant.None_ )) |) in - let actual_output_size := + let _ := M.assign_local (| + "actual_output_size" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -788,7 +893,8 @@ Definition generic_call : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -816,7 +922,8 @@ Definition call : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -829,8 +936,10 @@ Definition call : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let to := + |) + |) in + let _ := M.assign_local (| + "to" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -843,48 +952,60 @@ Definition call : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -895,8 +1016,10 @@ Definition call : Value.t -> Value.t -> M := ] ], make_dict [] - |) in - let create_gas_cost := + |) + |) in + let _ := M.assign_local (| + "create_gas_cost" , (* if *) M.if_then_else (| BoolOp.or (| @@ -927,8 +1050,10 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "GAS_NEW_ACCOUNT" |) - )) |) in - let transfer_gas_cost := + )) |) + |) in + let _ := M.assign_local (| + "transfer_gas_cost" , (* if *) M.if_then_else (| Compare.eq (| @@ -947,8 +1072,10 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "GAS_CALL_VALUE" |) - )) |) in - let message_call_gas := + )) |) + |) in + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -971,7 +1098,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1013,7 +1141,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let sender_balance := + let _ := M.assign_local (| + "sender_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1021,7 +1150,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := (* if *) M.if_then_else (| @@ -1095,7 +1225,8 @@ Definition callcode : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -1108,8 +1239,10 @@ Definition callcode : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let code_address := + |) + |) in + let _ := M.assign_local (| + "code_address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1122,50 +1255,64 @@ Definition callcode : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let to := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "to" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1176,8 +1323,10 @@ Definition callcode : Value.t -> Value.t -> M := ] ], make_dict [] - |) in - let transfer_gas_cost := + |) + |) in + let _ := M.assign_local (| + "transfer_gas_cost" , (* if *) M.if_then_else (| Compare.eq (| @@ -1196,8 +1345,10 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "GAS_CALL_VALUE" |) - )) |) in - let message_call_gas := + )) |) + |) in + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -1217,7 +1368,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1237,7 +1389,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let sender_balance := + let _ := M.assign_local (| + "sender_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1245,7 +1398,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := (* if *) M.if_then_else (| @@ -1319,7 +1473,8 @@ Definition selfdestruct : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let beneficiary := + let _ := M.assign_local (| + "beneficiary" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1332,9 +1487,12 @@ Definition selfdestruct : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let gas_cost := - M.get_name (| globals, "GAS_SELF_DESTRUCT" |) in + |) + |) in + let _ := M.assign_local (| + "gas_cost" , + M.get_name (| globals, "GAS_SELF_DESTRUCT" |) + |) in let _ := (* if *) M.if_then_else (| @@ -1363,20 +1521,28 @@ Definition selfdestruct : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let gas_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "gas_cost", M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) - M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let originator := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in - let refunded_accounts := - M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in - let parent_evm := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "parent_evm" |) in + let _ := M.assign_local (| + "originator" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + |) in + let _ := M.assign_local (| + "refunded_accounts" , + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) + |) in + let _ := M.assign_local (| + "parent_evm" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "parent_evm" |) + |) in let _ := M.while (| Compare.is_not (| @@ -1391,8 +1557,10 @@ Definition selfdestruct : Value.t -> Value.t -> M := ], make_dict [] |) in - let parent_evm := - M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in + let _ := M.assign_local (| + "parent_evm" , + M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -1434,7 +1602,8 @@ Definition selfdestruct : Value.t -> Value.t -> M := ], make_dict [] |) in - let beneficiary_balance := + let _ := M.assign_local (| + "beneficiary_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1442,8 +1611,10 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_name (| globals, "beneficiary" |) ], make_dict [] - |), "balance" |) in - let originator_balance := + |), "balance" |) + |) in + let _ := M.assign_local (| + "originator_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1451,7 +1622,8 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_name (| globals, "originator" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -1529,7 +1701,8 @@ Definition delegatecall : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -1542,8 +1715,10 @@ Definition delegatecall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let code_address := + |) + |) in + let _ := M.assign_local (| + "code_address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1556,40 +1731,50 @@ Definition delegatecall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1600,8 +1785,10 @@ Definition delegatecall : Value.t -> Value.t -> M := ] ], make_dict [] - |) in - let message_call_gas := + |) + |) in + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -1624,7 +1811,8 @@ Definition delegatecall : Value.t -> Value.t -> M := M.get_name (| globals, "GAS_CALL" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1680,7 +1868,8 @@ Definition staticcall : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -1693,8 +1882,10 @@ Definition staticcall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let to := + |) + |) in + let _ := M.assign_local (| + "to" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1707,40 +1898,50 @@ Definition staticcall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1751,8 +1952,10 @@ Definition staticcall : Value.t -> Value.t -> M := ] ], make_dict [] - |) in - let message_call_gas := + |) + |) in + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -1775,7 +1978,8 @@ Definition staticcall : Value.t -> Value.t -> M := M.get_name (| globals, "GAS_CALL" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1837,23 +2041,28 @@ Definition revert : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1863,7 +2072,8 @@ Definition revert : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1880,7 +2090,8 @@ Definition revert : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let output := + let _ := M.assign_local (| + "output" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -1889,7 +2100,8 @@ Definition revert : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| diff --git a/CoqOfPython/ethereum/istanbul/vm/interpreter.v b/CoqOfPython/ethereum/istanbul/vm/interpreter.v index 993fb31..dc57fbf 100644 --- a/CoqOfPython/ethereum/istanbul/vm/interpreter.v +++ b/CoqOfPython/ethereum/istanbul/vm/interpreter.v @@ -17,50 +17,110 @@ Introduction A straightforward interpreter that executes EVM code. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Iterable"; "Optional"; "Set"; "Tuple" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. - -Axiom ethereum_trace_imports : - AreImported globals "ethereum.trace" [ "EvmStop"; "OpEnd"; "OpException"; "OpStart"; "PrecompileEnd"; "PrecompileStart"; "TransactionEnd"; "evm_trace" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_istanbul_blocks_imports : - AreImported globals "ethereum.istanbul.blocks" [ "Log" ]. - -Axiom ethereum_istanbul_fork_types_imports : - AreImported globals "ethereum.istanbul.fork_types" [ "Address" ]. - -Axiom ethereum_istanbul_state_imports : - AreImported globals "ethereum.istanbul.state" [ "account_exists_and_is_empty"; "account_has_code_or_nonce"; "begin_transaction"; "commit_transaction"; "destroy_storage"; "increment_nonce"; "mark_account_created"; "move_ether"; "rollback_transaction"; "set_code"; "touch_account" ]. - -Axiom ethereum_istanbul_vm_imports : - AreImported globals "ethereum.istanbul.vm" [ "Message" ]. - -Axiom ethereum_istanbul_vm_gas_imports : - AreImported globals "ethereum.istanbul.vm.gas" [ "GAS_CODE_DEPOSIT"; "charge_gas" ]. - -Axiom ethereum_istanbul_vm_precompiled_contracts_mapping_imports : - AreImported globals "ethereum.istanbul.vm.precompiled_contracts.mapping" [ "PRE_COMPILED_CONTRACTS" ]. - -Axiom ethereum_istanbul_vm_imports : - AreImported globals "ethereum.istanbul.vm" [ "Environment"; "Evm" ]. - -Axiom ethereum_istanbul_vm_exceptions_imports : - AreImported globals "ethereum.istanbul.vm.exceptions" [ "AddressCollision"; "ExceptionalHalt"; "InvalidOpcode"; "OutOfGasError"; "Revert"; "StackDepthLimitError" ]. - -Axiom ethereum_istanbul_vm_instructions_imports : - AreImported globals "ethereum.istanbul.vm.instructions" [ "Ops"; "op_implementation" ]. - -Axiom ethereum_istanbul_vm_runtime_imports : - AreImported globals "ethereum.istanbul.vm.runtime" [ "get_valid_jump_destinations" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_Iterable : + IsImported globals "typing" "Iterable". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_trace_imports_EvmStop : + IsImported globals "ethereum.trace" "EvmStop". +Axiom ethereum_trace_imports_OpEnd : + IsImported globals "ethereum.trace" "OpEnd". +Axiom ethereum_trace_imports_OpException : + IsImported globals "ethereum.trace" "OpException". +Axiom ethereum_trace_imports_OpStart : + IsImported globals "ethereum.trace" "OpStart". +Axiom ethereum_trace_imports_PrecompileEnd : + IsImported globals "ethereum.trace" "PrecompileEnd". +Axiom ethereum_trace_imports_PrecompileStart : + IsImported globals "ethereum.trace" "PrecompileStart". +Axiom ethereum_trace_imports_TransactionEnd : + IsImported globals "ethereum.trace" "TransactionEnd". +Axiom ethereum_trace_imports_evm_trace : + IsImported globals "ethereum.trace" "evm_trace". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_istanbul_blocks_imports_Log : + IsImported globals "ethereum.istanbul.blocks" "Log". + +Axiom ethereum_istanbul_fork_types_imports_Address : + IsImported globals "ethereum.istanbul.fork_types" "Address". + +Axiom ethereum_istanbul_state_imports_account_exists_and_is_empty : + IsImported globals "ethereum.istanbul.state" "account_exists_and_is_empty". +Axiom ethereum_istanbul_state_imports_account_has_code_or_nonce : + IsImported globals "ethereum.istanbul.state" "account_has_code_or_nonce". +Axiom ethereum_istanbul_state_imports_begin_transaction : + IsImported globals "ethereum.istanbul.state" "begin_transaction". +Axiom ethereum_istanbul_state_imports_commit_transaction : + IsImported globals "ethereum.istanbul.state" "commit_transaction". +Axiom ethereum_istanbul_state_imports_destroy_storage : + IsImported globals "ethereum.istanbul.state" "destroy_storage". +Axiom ethereum_istanbul_state_imports_increment_nonce : + IsImported globals "ethereum.istanbul.state" "increment_nonce". +Axiom ethereum_istanbul_state_imports_mark_account_created : + IsImported globals "ethereum.istanbul.state" "mark_account_created". +Axiom ethereum_istanbul_state_imports_move_ether : + IsImported globals "ethereum.istanbul.state" "move_ether". +Axiom ethereum_istanbul_state_imports_rollback_transaction : + IsImported globals "ethereum.istanbul.state" "rollback_transaction". +Axiom ethereum_istanbul_state_imports_set_code : + IsImported globals "ethereum.istanbul.state" "set_code". +Axiom ethereum_istanbul_state_imports_touch_account : + IsImported globals "ethereum.istanbul.state" "touch_account". + +Axiom ethereum_istanbul_vm_imports_Message : + IsImported globals "ethereum.istanbul.vm" "Message". + +Axiom ethereum_istanbul_vm_gas_imports_GAS_CODE_DEPOSIT : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_CODE_DEPOSIT". +Axiom ethereum_istanbul_vm_gas_imports_charge_gas : + IsImported globals "ethereum.istanbul.vm.gas" "charge_gas". + +Axiom ethereum_istanbul_vm_precompiled_contracts_mapping_imports_PRE_COMPILED_CONTRACTS : + IsImported globals "ethereum.istanbul.vm.precompiled_contracts.mapping" "PRE_COMPILED_CONTRACTS". + +Axiom ethereum_istanbul_vm_imports_Environment : + IsImported globals "ethereum.istanbul.vm" "Environment". +Axiom ethereum_istanbul_vm_imports_Evm : + IsImported globals "ethereum.istanbul.vm" "Evm". + +Axiom ethereum_istanbul_vm_exceptions_imports_AddressCollision : + IsImported globals "ethereum.istanbul.vm.exceptions" "AddressCollision". +Axiom ethereum_istanbul_vm_exceptions_imports_ExceptionalHalt : + IsImported globals "ethereum.istanbul.vm.exceptions" "ExceptionalHalt". +Axiom ethereum_istanbul_vm_exceptions_imports_InvalidOpcode : + IsImported globals "ethereum.istanbul.vm.exceptions" "InvalidOpcode". +Axiom ethereum_istanbul_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.istanbul.vm.exceptions" "OutOfGasError". +Axiom ethereum_istanbul_vm_exceptions_imports_Revert : + IsImported globals "ethereum.istanbul.vm.exceptions" "Revert". +Axiom ethereum_istanbul_vm_exceptions_imports_StackDepthLimitError : + IsImported globals "ethereum.istanbul.vm.exceptions" "StackDepthLimitError". + +Axiom ethereum_istanbul_vm_instructions_imports_Ops : + IsImported globals "ethereum.istanbul.vm.instructions" "Ops". +Axiom ethereum_istanbul_vm_instructions_imports_op_implementation : + IsImported globals "ethereum.istanbul.vm.instructions" "op_implementation". + +Axiom ethereum_istanbul_vm_runtime_imports_get_valid_jump_destinations : + IsImported globals "ethereum.istanbul.vm.runtime" "get_valid_jump_destinations". Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -121,7 +181,8 @@ Definition process_message_call : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let is_collision := + let _ := M.assign_local (| + "is_collision" , M.call (| M.get_name (| globals, "account_has_code_or_nonce" |), make_list [ @@ -129,7 +190,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "message" |), "current_target" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -181,7 +243,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "process_create_message" |), make_list [ @@ -189,13 +252,15 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "process_message" |), make_list [ @@ -203,7 +268,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -250,46 +316,61 @@ Definition process_message_call : Value.t -> Value.t -> M := (* then *) ltac:(M.monadic ( (* At stmt: unsupported node type: AnnAssign *) - let accounts_to_delete := + let _ := M.assign_local (| + "accounts_to_delete" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let touched_accounts := + |) + |) in + let _ := M.assign_local (| + "touched_accounts" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let refund_counter := + |) + |) in + let _ := M.assign_local (| + "refund_counter" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let logs := - M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in - let accounts_to_delete := - M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in - let touched_accounts := - M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |) in - let refund_counter := + let _ := M.assign_local (| + "logs" , + M.get_field (| M.get_name (| globals, "evm" |), "logs" |) + |) in + let _ := M.assign_local (| + "accounts_to_delete" , + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) + |) in + let _ := M.assign_local (| + "touched_accounts" , + M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |) + |) in + let _ := M.assign_local (| + "refund_counter" , M.call (| M.get_name (| globals, "U256" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in - let tx_end := + let _ := M.assign_local (| + "tx_end" , M.call (| M.get_name (| globals, "TransactionEnd" |), make_list [ @@ -301,7 +382,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "error" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "evm_trace" |), make_list [ @@ -368,7 +450,8 @@ Definition process_create_message : Value.t -> Value.t -> M := ], make_dict [] |) in - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "process_message" |), make_list [ @@ -376,16 +459,20 @@ Definition process_create_message : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), (* then *) ltac:(M.monadic ( - let contract_code := - M.get_field (| M.get_name (| globals, "evm" |), "output" |) in - let contract_code_gas := + let _ := M.assign_local (| + "contract_code" , + M.get_field (| M.get_name (| globals, "evm" |), "output" |) + |) in + let _ := M.assign_local (| + "contract_code_gas" , BinOp.mult (| M.call (| M.get_name (| globals, "len" |), @@ -395,7 +482,8 @@ Definition process_create_message : Value.t -> Value.t -> M := make_dict [] |), M.get_name (| globals, "GAS_CODE_DEPOSIT" |) - |) in + |) + |) in (* At stmt: unsupported node type: Try *) M.pure Constant.None_ (* else *) @@ -497,7 +585,8 @@ Definition process_message : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "execute_code" |), make_list [ @@ -505,7 +594,8 @@ Definition process_message : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -554,22 +644,28 @@ Definition execute_code : Value.t -> Value.t -> M := evm: `ethereum.vm.EVM` Items containing execution specific objects " in - let code := - M.get_field (| M.get_name (| globals, "message" |), "code" |) in - let valid_jump_destinations := + let _ := M.assign_local (| + "code" , + M.get_field (| M.get_name (| globals, "message" |), "code" |) + |) in + let _ := M.assign_local (| + "valid_jump_destinations" , M.call (| M.get_name (| globals, "get_valid_jump_destinations" |), make_list [ M.get_name (| globals, "code" |) ], make_dict [] - |) in - let evm := + |) + |) in + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "Evm" |), make_list [], make_dict [] - |) in + |) + |) in (* At stmt: unsupported node type: Try *) let _ := M.return_ (| M.get_name (| globals, "evm" |) diff --git a/CoqOfPython/ethereum/istanbul/vm/memory.v b/CoqOfPython/ethereum/istanbul/vm/memory.v index 7a5c377..743e878 100644 --- a/CoqOfPython/ethereum/istanbul/vm/memory.v +++ b/CoqOfPython/ethereum/istanbul/vm/memory.v @@ -17,11 +17,15 @@ Introduction EVM memory operations. ". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "right_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_right_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "right_pad_zero_bytes". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". Definition memory_write : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/__init__.v index 0dced64..1419ef4 100644 --- a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/__init__.v +++ b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/__init__.v @@ -18,8 +18,8 @@ Addresses of precompiled contracts and mappings to their implementations. ". -Axiom ethereum_istanbul_utils_hexadecimal_imports : - AreImported globals "ethereum.istanbul.utils.hexadecimal" [ "hex_to_address" ]. +Axiom ethereum_istanbul_utils_hexadecimal_imports_hex_to_address : + IsImported globals "ethereum.istanbul.utils.hexadecimal" "hex_to_address". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS"; Constant.str "MODEXP_ADDRESS"; Constant.str "ALT_BN128_ADD_ADDRESS"; Constant.str "ALT_BN128_MUL_ADDRESS"; Constant.str "ALT_BN128_PAIRING_CHECK_ADDRESS"; Constant.str "BLAKE2F_ADDRESS" ] diff --git a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/alt_bn128.v index 7cada44..e074092 100644 --- a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/alt_bn128.v +++ b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/alt_bn128.v @@ -17,26 +17,42 @@ Introduction Implementation of the ALT_BN128 precompiled contracts. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_alt_bn128_imports : - AreImported globals "ethereum.crypto.alt_bn128" [ "ALT_BN128_CURVE_ORDER"; "ALT_BN128_PRIME"; "BNF"; "BNF2"; "BNF12"; "BNP"; "BNP2"; "pairing" ]. +Axiom ethereum_crypto_alt_bn128_imports_ALT_BN128_CURVE_ORDER : + IsImported globals "ethereum.crypto.alt_bn128" "ALT_BN128_CURVE_ORDER". +Axiom ethereum_crypto_alt_bn128_imports_ALT_BN128_PRIME : + IsImported globals "ethereum.crypto.alt_bn128" "ALT_BN128_PRIME". +Axiom ethereum_crypto_alt_bn128_imports_BNF : + IsImported globals "ethereum.crypto.alt_bn128" "BNF". +Axiom ethereum_crypto_alt_bn128_imports_BNF2 : + IsImported globals "ethereum.crypto.alt_bn128" "BNF2". +Axiom ethereum_crypto_alt_bn128_imports_BNF12 : + IsImported globals "ethereum.crypto.alt_bn128" "BNF12". +Axiom ethereum_crypto_alt_bn128_imports_BNP : + IsImported globals "ethereum.crypto.alt_bn128" "BNP". +Axiom ethereum_crypto_alt_bn128_imports_BNP2 : + IsImported globals "ethereum.crypto.alt_bn128" "BNP2". +Axiom ethereum_crypto_alt_bn128_imports_pairing : + IsImported globals "ethereum.crypto.alt_bn128" "pairing". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_istanbul_vm_imports : - AreImported globals "ethereum.istanbul.vm" [ "Evm" ]. +Axiom ethereum_istanbul_vm_imports_Evm : + IsImported globals "ethereum.istanbul.vm" "Evm". -Axiom ethereum_istanbul_vm_gas_imports : - AreImported globals "ethereum.istanbul.vm.gas" [ "charge_gas" ]. +Axiom ethereum_istanbul_vm_gas_imports_charge_gas : + IsImported globals "ethereum.istanbul.vm.gas" "charge_gas". -Axiom ethereum_istanbul_vm_memory_imports : - AreImported globals "ethereum.istanbul.vm.memory" [ "buffer_read" ]. +Axiom ethereum_istanbul_vm_memory_imports_buffer_read : + IsImported globals "ethereum.istanbul.vm.memory" "buffer_read". -Axiom ethereum_istanbul_vm_exceptions_imports : - AreImported globals "ethereum.istanbul.vm.exceptions" [ "OutOfGasError" ]. +Axiom ethereum_istanbul_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.istanbul.vm.exceptions" "OutOfGasError". Definition alt_bn128_add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -49,8 +65,10 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -65,7 +83,8 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := ], make_dict [] |) in - let x0_bytes := + let _ := M.assign_local (| + "x0_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -86,16 +105,20 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let x0_value := + |) + |) in + let _ := M.assign_local (| + "x0_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "x0_bytes" |) ], make_dict [] - |) in - let y0_bytes := + |) + |) in + let _ := M.assign_local (| + "y0_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -116,16 +139,20 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y0_value := + |) + |) in + let _ := M.assign_local (| + "y0_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "y0_bytes" |) ], make_dict [] - |) in - let x1_bytes := + |) + |) in + let _ := M.assign_local (| + "x1_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -146,16 +173,20 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let x1_value := + |) + |) in + let _ := M.assign_local (| + "x1_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "x1_bytes" |) ], make_dict [] - |) in - let y1_bytes := + |) + |) in + let _ := M.assign_local (| + "y1_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -176,15 +207,18 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y1_value := + |) + |) in + let _ := M.assign_local (| + "y1_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "y1_bytes" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "i" |), @@ -212,11 +246,13 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := )) |) in (* At stmt: unsupported node type: Try *) - let p := + let _ := M.assign_local (| + "p" , BinOp.add (| M.get_name (| globals, "p0" |), M.get_name (| globals, "p1" |) - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), BinOp.add (| @@ -245,8 +281,10 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -261,7 +299,8 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := ], make_dict [] |) in - let x0_bytes := + let _ := M.assign_local (| + "x0_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -282,16 +321,20 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let x0_value := + |) + |) in + let _ := M.assign_local (| + "x0_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "x0_bytes" |) ], make_dict [] - |) in - let y0_bytes := + |) + |) in + let _ := M.assign_local (| + "y0_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -312,16 +355,20 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y0_value := + |) + |) in + let _ := M.assign_local (| + "y0_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "y0_bytes" |) ], make_dict [] - |) in - let n := + |) + |) in + let _ := M.assign_local (| + "n" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -348,7 +395,8 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "i" |), @@ -376,14 +424,16 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := )) |) in (* At stmt: unsupported node type: Try *) - let p := + let _ := M.assign_local (| + "p" , M.call (| M.get_field (| M.get_name (| globals, "p0" |), "mul_by" |), make_list [ M.get_name (| globals, "n" |) ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), BinOp.add (| @@ -412,8 +462,10 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -467,14 +519,16 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), make_list [ Constant.int 1 ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "i" |), @@ -495,8 +549,10 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let values := - make_list [] in + let _ := M.assign_local (| + "values" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "j" |), @@ -508,7 +564,8 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -541,7 +598,8 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -644,7 +702,8 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , BinOp.mult (| M.get_name (| globals, "result" |), M.call (| @@ -655,7 +714,8 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/blake2f.v b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/blake2f.v index 6c768ea..da836ff 100644 --- a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/blake2f.v +++ b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/blake2f.v @@ -17,20 +17,22 @@ Introduction Implementation of the `Blake2` precompiled contract. ". -Axiom ethereum_crypto_blake2_imports : - AreImported globals "ethereum.crypto.blake2" [ "Blake2b" ]. +Axiom ethereum_crypto_blake2_imports_Blake2b : + IsImported globals "ethereum.crypto.blake2" "Blake2b". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_istanbul_vm_imports : - AreImported globals "ethereum.istanbul.vm" [ "Evm" ]. +Axiom ethereum_istanbul_vm_imports_Evm : + IsImported globals "ethereum.istanbul.vm" "Evm". -Axiom ethereum_istanbul_vm_gas_imports : - AreImported globals "ethereum.istanbul.vm.gas" [ "GAS_BLAKE2_PER_ROUND"; "charge_gas" ]. +Axiom ethereum_istanbul_vm_gas_imports_GAS_BLAKE2_PER_ROUND : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_BLAKE2_PER_ROUND". +Axiom ethereum_istanbul_vm_gas_imports_charge_gas : + IsImported globals "ethereum.istanbul.vm.gas" "charge_gas". -Axiom ethereum_istanbul_vm_exceptions_imports : - AreImported globals "ethereum.istanbul.vm.exceptions" [ "InvalidParameter" ]. +Axiom ethereum_istanbul_vm_exceptions_imports_InvalidParameter : + IsImported globals "ethereum.istanbul.vm.exceptions" "InvalidParameter". Definition blake2f : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -43,8 +45,10 @@ Definition blake2f : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -62,12 +66,14 @@ Definition blake2f : Value.t -> Value.t -> M := ], make_dict [] |) in - let blake2b := + let _ := M.assign_local (| + "blake2b" , M.call (| M.get_name (| globals, "Blake2b" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "rounds" |); M.get_name (| globals, "h" |); M.get_name (| globals, "m" |); M.get_name (| globals, "t_0" |); M.get_name (| globals, "t_1" |); M.get_name (| globals, "f" |) ], M.call (| diff --git a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/ecrecover.v index 3b38ee1..de71626 100644 --- a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/ecrecover.v @@ -17,26 +17,32 @@ Introduction Implementation of the ECRECOVER precompiled contract. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_crypto_elliptic_curve_imports : - AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. +Axiom ethereum_crypto_elliptic_curve_imports_SECP256K1N : + IsImported globals "ethereum.crypto.elliptic_curve" "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_imports_secp256k1_recover : + IsImported globals "ethereum.crypto.elliptic_curve" "secp256k1_recover". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_left_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "left_pad_zero_bytes". -Axiom ethereum_istanbul_vm_imports : - AreImported globals "ethereum.istanbul.vm" [ "Evm" ]. +Axiom ethereum_istanbul_vm_imports_Evm : + IsImported globals "ethereum.istanbul.vm" "Evm". -Axiom ethereum_istanbul_vm_gas_imports : - AreImported globals "ethereum.istanbul.vm.gas" [ "GAS_ECRECOVER"; "charge_gas" ]. +Axiom ethereum_istanbul_vm_gas_imports_GAS_ECRECOVER : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_ECRECOVER". +Axiom ethereum_istanbul_vm_gas_imports_charge_gas : + IsImported globals "ethereum.istanbul.vm.gas" "charge_gas". -Axiom ethereum_istanbul_vm_memory_imports : - AreImported globals "ethereum.istanbul.vm.memory" [ "buffer_read" ]. +Axiom ethereum_istanbul_vm_memory_imports_buffer_read : + IsImported globals "ethereum.istanbul.vm.memory" "buffer_read". Definition ecrecover : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -50,8 +56,10 @@ Definition ecrecover : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -60,7 +68,8 @@ Definition ecrecover : Value.t -> Value.t -> M := ], make_dict [] |) in - let message_hash_bytes := + let _ := M.assign_local (| + "message_hash_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -81,16 +90,20 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let message_hash := + |) + |) in + let _ := M.assign_local (| + "message_hash" , M.call (| M.get_name (| globals, "Hash32" |), make_list [ M.get_name (| globals, "message_hash_bytes" |) ], make_dict [] - |) in - let v := + |) + |) in + let _ := M.assign_local (| + "v" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -117,8 +130,10 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let r := + |) + |) in + let _ := M.assign_local (| + "r" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -145,8 +160,10 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let s := + |) + |) in + let _ := M.assign_local (| + "s" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -173,7 +190,8 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -250,7 +268,8 @@ Definition ecrecover : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: Try *) - let address := + let _ := M.assign_local (| + "address" , M.slice (| M.call (| M.get_name (| globals, "keccak256" |), @@ -262,8 +281,10 @@ Definition ecrecover : Value.t -> Value.t -> M := Constant.int 12, Constant.int 32, Constant.None_ - |) in - let padded_address := + |) + |) in + let _ := M.assign_local (| + "padded_address" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -271,7 +292,8 @@ Definition ecrecover : Value.t -> Value.t -> M := Constant.int 32 ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.get_name (| globals, "padded_address" |) diff --git a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/identity.v index 9250b3c..894529f 100644 --- a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/identity.v +++ b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/identity.v @@ -17,17 +17,21 @@ Introduction Implementation of the `IDENTITY` precompiled contract. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_istanbul_vm_imports : - AreImported globals "ethereum.istanbul.vm" [ "Evm" ]. +Axiom ethereum_istanbul_vm_imports_Evm : + IsImported globals "ethereum.istanbul.vm" "Evm". -Axiom ethereum_istanbul_vm_gas_imports : - AreImported globals "ethereum.istanbul.vm.gas" [ "GAS_IDENTITY"; "GAS_IDENTITY_WORD"; "charge_gas" ]. +Axiom ethereum_istanbul_vm_gas_imports_GAS_IDENTITY : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_IDENTITY". +Axiom ethereum_istanbul_vm_gas_imports_GAS_IDENTITY_WORD : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_IDENTITY_WORD". +Axiom ethereum_istanbul_vm_gas_imports_charge_gas : + IsImported globals "ethereum.istanbul.vm.gas" "charge_gas". Definition identity : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -40,9 +44,12 @@ Definition identity : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let word_count := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "word_count" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -64,7 +71,8 @@ Definition identity : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ diff --git a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/mapping.v index 7aeb360..d88667d 100644 --- a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/mapping.v +++ b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/mapping.v @@ -17,34 +17,56 @@ Introduction Mapping of precompiled contracts their implementations. ". -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict" ]. - -Axiom ethereum_istanbul_fork_types_imports : - AreImported globals "ethereum.istanbul.fork_types" [ "Address" ]. - -Axiom ethereum_istanbul_vm_precompiled_contracts_imports : - AreImported globals "ethereum.istanbul.vm.precompiled_contracts" [ "ALT_BN128_ADD_ADDRESS"; "ALT_BN128_MUL_ADDRESS"; "ALT_BN128_PAIRING_CHECK_ADDRESS"; "BLAKE2F_ADDRESS"; "ECRECOVER_ADDRESS"; "IDENTITY_ADDRESS"; "MODEXP_ADDRESS"; "RIPEMD160_ADDRESS"; "SHA256_ADDRESS" ]. - -Axiom ethereum_istanbul_vm_precompiled_contracts_alt_bn128_imports : - AreImported globals "ethereum.istanbul.vm.precompiled_contracts.alt_bn128" [ "alt_bn128_add"; "alt_bn128_mul"; "alt_bn128_pairing_check" ]. - -Axiom ethereum_istanbul_vm_precompiled_contracts_blake2f_imports : - AreImported globals "ethereum.istanbul.vm.precompiled_contracts.blake2f" [ "blake2f" ]. - -Axiom ethereum_istanbul_vm_precompiled_contracts_ecrecover_imports : - AreImported globals "ethereum.istanbul.vm.precompiled_contracts.ecrecover" [ "ecrecover" ]. - -Axiom ethereum_istanbul_vm_precompiled_contracts_identity_imports : - AreImported globals "ethereum.istanbul.vm.precompiled_contracts.identity" [ "identity" ]. - -Axiom ethereum_istanbul_vm_precompiled_contracts_modexp_imports : - AreImported globals "ethereum.istanbul.vm.precompiled_contracts.modexp" [ "modexp" ]. - -Axiom ethereum_istanbul_vm_precompiled_contracts_ripemd160_imports : - AreImported globals "ethereum.istanbul.vm.precompiled_contracts.ripemd160" [ "ripemd160" ]. - -Axiom ethereum_istanbul_vm_precompiled_contracts_sha256_imports : - AreImported globals "ethereum.istanbul.vm.precompiled_contracts.sha256" [ "sha256" ]. +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". + +Axiom ethereum_istanbul_fork_types_imports_Address : + IsImported globals "ethereum.istanbul.fork_types" "Address". + +Axiom ethereum_istanbul_vm_precompiled_contracts_imports_ALT_BN128_ADD_ADDRESS : + IsImported globals "ethereum.istanbul.vm.precompiled_contracts" "ALT_BN128_ADD_ADDRESS". +Axiom ethereum_istanbul_vm_precompiled_contracts_imports_ALT_BN128_MUL_ADDRESS : + IsImported globals "ethereum.istanbul.vm.precompiled_contracts" "ALT_BN128_MUL_ADDRESS". +Axiom ethereum_istanbul_vm_precompiled_contracts_imports_ALT_BN128_PAIRING_CHECK_ADDRESS : + IsImported globals "ethereum.istanbul.vm.precompiled_contracts" "ALT_BN128_PAIRING_CHECK_ADDRESS". +Axiom ethereum_istanbul_vm_precompiled_contracts_imports_BLAKE2F_ADDRESS : + IsImported globals "ethereum.istanbul.vm.precompiled_contracts" "BLAKE2F_ADDRESS". +Axiom ethereum_istanbul_vm_precompiled_contracts_imports_ECRECOVER_ADDRESS : + IsImported globals "ethereum.istanbul.vm.precompiled_contracts" "ECRECOVER_ADDRESS". +Axiom ethereum_istanbul_vm_precompiled_contracts_imports_IDENTITY_ADDRESS : + IsImported globals "ethereum.istanbul.vm.precompiled_contracts" "IDENTITY_ADDRESS". +Axiom ethereum_istanbul_vm_precompiled_contracts_imports_MODEXP_ADDRESS : + IsImported globals "ethereum.istanbul.vm.precompiled_contracts" "MODEXP_ADDRESS". +Axiom ethereum_istanbul_vm_precompiled_contracts_imports_RIPEMD160_ADDRESS : + IsImported globals "ethereum.istanbul.vm.precompiled_contracts" "RIPEMD160_ADDRESS". +Axiom ethereum_istanbul_vm_precompiled_contracts_imports_SHA256_ADDRESS : + IsImported globals "ethereum.istanbul.vm.precompiled_contracts" "SHA256_ADDRESS". + +Axiom ethereum_istanbul_vm_precompiled_contracts_alt_bn128_imports_alt_bn128_add : + IsImported globals "ethereum.istanbul.vm.precompiled_contracts.alt_bn128" "alt_bn128_add". +Axiom ethereum_istanbul_vm_precompiled_contracts_alt_bn128_imports_alt_bn128_mul : + IsImported globals "ethereum.istanbul.vm.precompiled_contracts.alt_bn128" "alt_bn128_mul". +Axiom ethereum_istanbul_vm_precompiled_contracts_alt_bn128_imports_alt_bn128_pairing_check : + IsImported globals "ethereum.istanbul.vm.precompiled_contracts.alt_bn128" "alt_bn128_pairing_check". + +Axiom ethereum_istanbul_vm_precompiled_contracts_blake2f_imports_blake2f : + IsImported globals "ethereum.istanbul.vm.precompiled_contracts.blake2f" "blake2f". + +Axiom ethereum_istanbul_vm_precompiled_contracts_ecrecover_imports_ecrecover : + IsImported globals "ethereum.istanbul.vm.precompiled_contracts.ecrecover" "ecrecover". + +Axiom ethereum_istanbul_vm_precompiled_contracts_identity_imports_identity : + IsImported globals "ethereum.istanbul.vm.precompiled_contracts.identity" "identity". + +Axiom ethereum_istanbul_vm_precompiled_contracts_modexp_imports_modexp : + IsImported globals "ethereum.istanbul.vm.precompiled_contracts.modexp" "modexp". + +Axiom ethereum_istanbul_vm_precompiled_contracts_ripemd160_imports_ripemd160 : + IsImported globals "ethereum.istanbul.vm.precompiled_contracts.ripemd160" "ripemd160". + +Axiom ethereum_istanbul_vm_precompiled_contracts_sha256_imports_sha256 : + IsImported globals "ethereum.istanbul.vm.precompiled_contracts.sha256" "sha256". (* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/modexp.v index d0bfc29..6178170 100644 --- a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/modexp.v +++ b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/modexp.v @@ -17,17 +17,21 @@ Introduction Implementation of the `MODEXP` precompiled contract. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_istanbul_vm_imports : - AreImported globals "ethereum.istanbul.vm" [ "Evm" ]. +Axiom ethereum_istanbul_vm_imports_Evm : + IsImported globals "ethereum.istanbul.vm" "Evm". -Axiom ethereum_istanbul_vm_gas_imports : - AreImported globals "ethereum.istanbul.vm.gas" [ "charge_gas" ]. +Axiom ethereum_istanbul_vm_gas_imports_charge_gas : + IsImported globals "ethereum.istanbul.vm.gas" "charge_gas". -Axiom ethereum_istanbul_vm_memory_imports : - AreImported globals "ethereum.istanbul.vm.memory" [ "buffer_read" ]. +Axiom ethereum_istanbul_vm_memory_imports_buffer_read : + IsImported globals "ethereum.istanbul.vm.memory" "buffer_read". Definition GQUADDIVISOR : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -46,9 +50,12 @@ Definition modexp : Value.t -> Value.t -> M := Calculates `(base**exp) % modulus` for arbitrary sized `base`, `exp` and. `modulus`. The return value is the same length as the modulus. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let base_length := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "base_length" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -75,8 +82,10 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exp_length := + |) + |) in + let _ := M.assign_local (| + "exp_length" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -103,8 +112,10 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let modulus_length := + |) + |) in + let _ := M.assign_local (| + "modulus_length" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -131,8 +142,10 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exp_start := + |) + |) in + let _ := M.assign_local (| + "exp_start" , BinOp.add (| M.call (| M.get_name (| globals, "U256" |), @@ -142,8 +155,10 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |), M.get_name (| globals, "base_length" |) - |) in - let exp_head := + |) + |) in + let _ := M.assign_local (| + "exp_head" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -171,7 +186,8 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -181,7 +197,8 @@ Definition modexp : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let adjusted_exp_length := + let _ := M.assign_local (| + "adjusted_exp_length" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -202,11 +219,13 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let adjusted_exp_length := + let _ := M.assign_local (| + "adjusted_exp_length" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -242,7 +261,8 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -324,7 +344,8 @@ Definition modexp : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let base := + let _ := M.assign_local (| + "base" , M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ @@ -345,8 +366,10 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exp := + |) + |) in + let _ := M.assign_local (| + "exp" , M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ @@ -361,13 +384,17 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let modulus_start := + |) + |) in + let _ := M.assign_local (| + "modulus_start" , BinOp.add (| M.get_name (| globals, "exp_start" |), M.get_name (| globals, "exp_length" |) - |) in - let modulus := + |) + |) in + let _ := M.assign_local (| + "modulus" , M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ @@ -382,7 +409,8 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| diff --git a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/ripemd160.v index 0cc1522..9355562 100644 --- a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/ripemd160.v +++ b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/ripemd160.v @@ -19,20 +19,24 @@ Implementation of the `RIPEMD160` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_left_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "left_pad_zero_bytes". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_istanbul_vm_imports : - AreImported globals "ethereum.istanbul.vm" [ "Evm" ]. +Axiom ethereum_istanbul_vm_imports_Evm : + IsImported globals "ethereum.istanbul.vm" "Evm". -Axiom ethereum_istanbul_vm_gas_imports : - AreImported globals "ethereum.istanbul.vm.gas" [ "GAS_RIPEMD160"; "GAS_RIPEMD160_WORD"; "charge_gas" ]. +Axiom ethereum_istanbul_vm_gas_imports_GAS_RIPEMD160 : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_RIPEMD160". +Axiom ethereum_istanbul_vm_gas_imports_GAS_RIPEMD160_WORD : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_RIPEMD160_WORD". +Axiom ethereum_istanbul_vm_gas_imports_charge_gas : + IsImported globals "ethereum.istanbul.vm.gas" "charge_gas". Definition ripemd160 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,9 +49,12 @@ Definition ripemd160 : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let word_count := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "word_count" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -69,7 +76,8 @@ Definition ripemd160 : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -84,7 +92,8 @@ Definition ripemd160 : Value.t -> Value.t -> M := ], make_dict [] |) in - let hash_bytes := + let _ := M.assign_local (| + "hash_bytes" , M.call (| M.get_field (| M.call (| M.get_field (| M.get_name (| globals, "hashlib" |), "new" |), @@ -96,8 +105,10 @@ Definition ripemd160 : Value.t -> Value.t -> M := |), "digest" |), make_list [], make_dict [] - |) in - let padded_hash := + |) + |) in + let _ := M.assign_local (| + "padded_hash" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -105,7 +116,8 @@ Definition ripemd160 : Value.t -> Value.t -> M := Constant.int 32 ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.get_name (| globals, "padded_hash" |) diff --git a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/sha256.v index d5850ca..36128c8 100644 --- a/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/sha256.v +++ b/CoqOfPython/ethereum/istanbul/vm/precompiled_contracts/sha256.v @@ -19,17 +19,21 @@ Implementation of the `SHA256` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_istanbul_vm_imports : - AreImported globals "ethereum.istanbul.vm" [ "Evm" ]. +Axiom ethereum_istanbul_vm_imports_Evm : + IsImported globals "ethereum.istanbul.vm" "Evm". -Axiom ethereum_istanbul_vm_gas_imports : - AreImported globals "ethereum.istanbul.vm.gas" [ "GAS_SHA256"; "GAS_SHA256_WORD"; "charge_gas" ]. +Axiom ethereum_istanbul_vm_gas_imports_GAS_SHA256 : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_SHA256". +Axiom ethereum_istanbul_vm_gas_imports_GAS_SHA256_WORD : + IsImported globals "ethereum.istanbul.vm.gas" "GAS_SHA256_WORD". +Axiom ethereum_istanbul_vm_gas_imports_charge_gas : + IsImported globals "ethereum.istanbul.vm.gas" "charge_gas". Definition sha256 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,9 +46,12 @@ Definition sha256 : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let word_count := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "word_count" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -66,7 +73,8 @@ Definition sha256 : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ diff --git a/CoqOfPython/ethereum/istanbul/vm/runtime.v b/CoqOfPython/ethereum/istanbul/vm/runtime.v index 4f6271e..88abdd0 100644 --- a/CoqOfPython/ethereum/istanbul/vm/runtime.v +++ b/CoqOfPython/ethereum/istanbul/vm/runtime.v @@ -17,14 +17,14 @@ Introduction Runtime related operations used while executing EVM code. ". -Axiom typing_imports : - AreImported globals "typing" [ "Set" ]. +Axiom typing_imports_Set : + IsImported globals "typing" "Set". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_istanbul_vm_instructions_imports : - AreImported globals "ethereum.istanbul.vm.instructions" [ "Ops" ]. +Axiom ethereum_istanbul_vm_instructions_imports_Ops : + IsImported globals "ethereum.istanbul.vm.instructions" "Ops". Definition get_valid_jump_destinations : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -50,20 +50,24 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := valid_jump_destinations: `Set[Uint]` The set of valid jump destinations in the code. " in - let valid_jump_destinations := + let _ := M.assign_local (| + "valid_jump_destinations" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let pc := + |) + |) in + let _ := M.assign_local (| + "pc" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in let _ := M.while (| Compare.lt (| @@ -114,17 +118,21 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let push_data_size := + let _ := M.assign_local (| + "push_data_size" , BinOp.add (| BinOp.sub (| M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) |), Constant.int 1 - |) in - let pc := BinOp.add + |) + |) in + let _ := M.assign_op_local (| + BinOp.add, + "pc", M.get_name (| globals, "push_data_size" |) - M.get_name (| globals, "push_data_size" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -132,9 +140,11 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - let pc := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "pc", Constant.int 1 - Constant.int 1 in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/istanbul/vm/stack.v b/CoqOfPython/ethereum/istanbul/vm/stack.v index abea471..8a72fb1 100644 --- a/CoqOfPython/ethereum/istanbul/vm/stack.v +++ b/CoqOfPython/ethereum/istanbul/vm/stack.v @@ -17,14 +17,16 @@ Introduction Implementation of the stack operators for the EVM. ". -Axiom typing_imports : - AreImported globals "typing" [ "List" ]. +Axiom typing_imports_List : + IsImported globals "typing" "List". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_istanbul_vm_exceptions_imports : - AreImported globals "ethereum.istanbul.vm.exceptions" [ "StackOverflowError"; "StackUnderflowError" ]. +Axiom ethereum_istanbul_vm_exceptions_imports_StackOverflowError : + IsImported globals "ethereum.istanbul.vm.exceptions" "StackOverflowError". +Axiom ethereum_istanbul_vm_exceptions_imports_StackUnderflowError : + IsImported globals "ethereum.istanbul.vm.exceptions" "StackUnderflowError". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/london/__init__.v b/CoqOfPython/ethereum/london/__init__.v index 219f2eb..d0a16e4 100644 --- a/CoqOfPython/ethereum/london/__init__.v +++ b/CoqOfPython/ethereum/london/__init__.v @@ -8,8 +8,8 @@ The London fork overhauls the transaction fee market, changes gas refunds, reserves a contract prefix for future use, and delays the difficulty bomb. ". -Axiom ethereum_fork_criteria_imports : - AreImported globals "ethereum.fork_criteria" [ "ByBlockNumber" ]. +Axiom ethereum_fork_criteria_imports_ByBlockNumber : + IsImported globals "ethereum.fork_criteria" "ByBlockNumber". Definition FORK_CRITERIA : Value.t := M.run ltac:(M.monadic ( M.call (| diff --git a/CoqOfPython/ethereum/london/blocks.v b/CoqOfPython/ethereum/london/blocks.v index 50027c9..acc6316 100644 --- a/CoqOfPython/ethereum/london/blocks.v +++ b/CoqOfPython/ethereum/london/blocks.v @@ -14,23 +14,39 @@ history of all state transitions that have happened since the genesis of the chain. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Tuple"; "Union" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes8"; "Bytes32"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. - -Axiom ethereum_london_fork_types_imports : - AreImported globals "ethereum.london.fork_types" [ "Address"; "Bloom"; "Root" ]. - -Axiom ethereum_london_transactions_imports : - AreImported globals "ethereum.london.transactions" [ "LegacyTransaction" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes8 : + IsImported globals "ethereum.base_types" "Bytes8". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". + +Axiom ethereum_london_fork_types_imports_Address : + IsImported globals "ethereum.london.fork_types" "Address". +Axiom ethereum_london_fork_types_imports_Bloom : + IsImported globals "ethereum.london.fork_types" "Bloom". +Axiom ethereum_london_fork_types_imports_Root : + IsImported globals "ethereum.london.fork_types" "Root". + +Axiom ethereum_london_transactions_imports_LegacyTransaction : + IsImported globals "ethereum.london.transactions" "LegacyTransaction". Definition Header : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/london/bloom.v b/CoqOfPython/ethereum/london/bloom.v index 9a8f4fc..ede68b4 100644 --- a/CoqOfPython/ethereum/london/bloom.v +++ b/CoqOfPython/ethereum/london/bloom.v @@ -21,20 +21,20 @@ for efficient searching of logs by address and/or topic, by rapidly eliminating blocks and receipts from their search. ". -Axiom typing_imports : - AreImported globals "typing" [ "Tuple" ]. +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_london_blocks_imports : - AreImported globals "ethereum.london.blocks" [ "Log" ]. +Axiom ethereum_london_blocks_imports_Log : + IsImported globals "ethereum.london.blocks" "Log". -Axiom ethereum_london_fork_types_imports : - AreImported globals "ethereum.london.fork_types" [ "Bloom" ]. +Axiom ethereum_london_fork_types_imports_Bloom : + IsImported globals "ethereum.london.fork_types" "Bloom". Definition add_to_bloom : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -53,20 +53,23 @@ Definition add_to_bloom : Value.t -> Value.t -> M := bloom_entry : An entry which is to be added to bloom filter. " in - let hash := + let _ := M.assign_local (| + "hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "bloom_entry" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "idx" |), make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ], ltac:(M.monadic ( - let bit_to_set := + let _ := M.assign_local (| + "bit_to_set" , BinOp.bit_and (| M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), @@ -84,18 +87,24 @@ Definition add_to_bloom : Value.t -> Value.t -> M := make_dict [] |), Constant.int 2047 - |) in - let bit_index := + |) + |) in + let _ := M.assign_local (| + "bit_index" , BinOp.sub (| Constant.int 2047, M.get_name (| globals, "bit_to_set" |) - |) in - let byte_index := + |) + |) in + let _ := M.assign_local (| + "byte_index" , BinOp.floor_div (| M.get_name (| globals, "bit_index" |), Constant.int 8 - |) in - let bit_value := + |) + |) in + let _ := M.assign_local (| + "bit_value" , BinOp.l_shift (| Constant.int 1, BinOp.sub (| @@ -105,7 +114,8 @@ Definition add_to_bloom : Value.t -> Value.t -> M := Constant.int 8 |) |) - |) in + |) + |) in let _ := M.assign (| M.get_subscript (| M.get_name (| globals, "bloom" |), diff --git a/CoqOfPython/ethereum/london/fork.v b/CoqOfPython/ethereum/london/fork.v index aa592fc..2a268b2 100644 --- a/CoqOfPython/ethereum/london/fork.v +++ b/CoqOfPython/ethereum/london/fork.v @@ -17,62 +17,138 @@ Introduction Entry point for the Ethereum specification. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple"; "Union" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Bytes0" ]. - -Axiom ethereum_crypto_elliptic_curve_imports : - AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. - -Axiom ethereum_ethash_imports : - AreImported globals "ethereum.ethash" [ "dataset_size"; "generate_cache"; "hashimoto_light" ]. - -Axiom ethereum_exceptions_imports : - AreImported globals "ethereum.exceptions" [ "InvalidBlock" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U64"; "U256"; "U256_CEIL_VALUE"; "Bytes"; "Uint" ]. - -Axiom ethereum_london_imports : - AreImported globals "ethereum.london" [ "FORK_CRITERIA"; "vm" ]. - -Axiom ethereum_london_blocks_imports : - AreImported globals "ethereum.london.blocks" [ "Block"; "Header"; "Log"; "Receipt" ]. - -Axiom ethereum_london_bloom_imports : - AreImported globals "ethereum.london.bloom" [ "logs_bloom" ]. - -Axiom ethereum_london_fork_types_imports : - AreImported globals "ethereum.london.fork_types" [ "Address"; "Bloom"; "Root" ]. - -Axiom ethereum_london_state_imports : - AreImported globals "ethereum.london.state" [ "State"; "account_exists_and_is_empty"; "create_ether"; "destroy_account"; "get_account"; "increment_nonce"; "set_account_balance"; "state_root" ]. - -Axiom ethereum_london_transactions_imports : - AreImported globals "ethereum.london.transactions" [ "TX_ACCESS_LIST_ADDRESS_COST"; "TX_ACCESS_LIST_STORAGE_KEY_COST"; "TX_BASE_COST"; "TX_CREATE_COST"; "TX_DATA_COST_PER_NON_ZERO"; "TX_DATA_COST_PER_ZERO"; "AccessListTransaction"; "FeeMarketTransaction"; "LegacyTransaction"; "Transaction"; "decode_transaction"; "encode_transaction" ]. - -Axiom ethereum_london_trie_imports : - AreImported globals "ethereum.london.trie" [ "Trie"; "root"; "trie_set" ]. - -Axiom ethereum_london_utils_message_imports : - AreImported globals "ethereum.london.utils.message" [ "prepare_message" ]. - -Axiom ethereum_london_vm_interpreter_imports : - AreImported globals "ethereum.london.vm.interpreter" [ "process_message_call" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". + +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". + +Axiom ethereum_crypto_elliptic_curve_imports_SECP256K1N : + IsImported globals "ethereum.crypto.elliptic_curve" "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_imports_secp256k1_recover : + IsImported globals "ethereum.crypto.elliptic_curve" "secp256k1_recover". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". + +Axiom ethereum_ethash_imports_dataset_size : + IsImported globals "ethereum.ethash" "dataset_size". +Axiom ethereum_ethash_imports_generate_cache : + IsImported globals "ethereum.ethash" "generate_cache". +Axiom ethereum_ethash_imports_hashimoto_light : + IsImported globals "ethereum.ethash" "hashimoto_light". + +Axiom ethereum_exceptions_imports_InvalidBlock : + IsImported globals "ethereum.exceptions" "InvalidBlock". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U64 : + IsImported globals "ethereum.base_types" "U64". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_U256_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U256_CEIL_VALUE". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_london_imports_FORK_CRITERIA : + IsImported globals "ethereum.london" "FORK_CRITERIA". +Axiom ethereum_london_imports_vm : + IsImported globals "ethereum.london" "vm". + +Axiom ethereum_london_blocks_imports_Block : + IsImported globals "ethereum.london.blocks" "Block". +Axiom ethereum_london_blocks_imports_Header : + IsImported globals "ethereum.london.blocks" "Header". +Axiom ethereum_london_blocks_imports_Log : + IsImported globals "ethereum.london.blocks" "Log". +Axiom ethereum_london_blocks_imports_Receipt : + IsImported globals "ethereum.london.blocks" "Receipt". + +Axiom ethereum_london_bloom_imports_logs_bloom : + IsImported globals "ethereum.london.bloom" "logs_bloom". + +Axiom ethereum_london_fork_types_imports_Address : + IsImported globals "ethereum.london.fork_types" "Address". +Axiom ethereum_london_fork_types_imports_Bloom : + IsImported globals "ethereum.london.fork_types" "Bloom". +Axiom ethereum_london_fork_types_imports_Root : + IsImported globals "ethereum.london.fork_types" "Root". + +Axiom ethereum_london_state_imports_State : + IsImported globals "ethereum.london.state" "State". +Axiom ethereum_london_state_imports_account_exists_and_is_empty : + IsImported globals "ethereum.london.state" "account_exists_and_is_empty". +Axiom ethereum_london_state_imports_create_ether : + IsImported globals "ethereum.london.state" "create_ether". +Axiom ethereum_london_state_imports_destroy_account : + IsImported globals "ethereum.london.state" "destroy_account". +Axiom ethereum_london_state_imports_get_account : + IsImported globals "ethereum.london.state" "get_account". +Axiom ethereum_london_state_imports_increment_nonce : + IsImported globals "ethereum.london.state" "increment_nonce". +Axiom ethereum_london_state_imports_set_account_balance : + IsImported globals "ethereum.london.state" "set_account_balance". +Axiom ethereum_london_state_imports_state_root : + IsImported globals "ethereum.london.state" "state_root". + +Axiom ethereum_london_transactions_imports_TX_ACCESS_LIST_ADDRESS_COST : + IsImported globals "ethereum.london.transactions" "TX_ACCESS_LIST_ADDRESS_COST". +Axiom ethereum_london_transactions_imports_TX_ACCESS_LIST_STORAGE_KEY_COST : + IsImported globals "ethereum.london.transactions" "TX_ACCESS_LIST_STORAGE_KEY_COST". +Axiom ethereum_london_transactions_imports_TX_BASE_COST : + IsImported globals "ethereum.london.transactions" "TX_BASE_COST". +Axiom ethereum_london_transactions_imports_TX_CREATE_COST : + IsImported globals "ethereum.london.transactions" "TX_CREATE_COST". +Axiom ethereum_london_transactions_imports_TX_DATA_COST_PER_NON_ZERO : + IsImported globals "ethereum.london.transactions" "TX_DATA_COST_PER_NON_ZERO". +Axiom ethereum_london_transactions_imports_TX_DATA_COST_PER_ZERO : + IsImported globals "ethereum.london.transactions" "TX_DATA_COST_PER_ZERO". +Axiom ethereum_london_transactions_imports_AccessListTransaction : + IsImported globals "ethereum.london.transactions" "AccessListTransaction". +Axiom ethereum_london_transactions_imports_FeeMarketTransaction : + IsImported globals "ethereum.london.transactions" "FeeMarketTransaction". +Axiom ethereum_london_transactions_imports_LegacyTransaction : + IsImported globals "ethereum.london.transactions" "LegacyTransaction". +Axiom ethereum_london_transactions_imports_Transaction : + IsImported globals "ethereum.london.transactions" "Transaction". +Axiom ethereum_london_transactions_imports_decode_transaction : + IsImported globals "ethereum.london.transactions" "decode_transaction". +Axiom ethereum_london_transactions_imports_encode_transaction : + IsImported globals "ethereum.london.transactions" "encode_transaction". + +Axiom ethereum_london_trie_imports_Trie : + IsImported globals "ethereum.london.trie" "Trie". +Axiom ethereum_london_trie_imports_root : + IsImported globals "ethereum.london.trie" "root". +Axiom ethereum_london_trie_imports_trie_set : + IsImported globals "ethereum.london.trie" "trie_set". + +Axiom ethereum_london_utils_message_imports_prepare_message : + IsImported globals "ethereum.london.utils.message" "prepare_message". + +Axiom ethereum_london_vm_interpreter_imports_process_message_call : + IsImported globals "ethereum.london.vm.interpreter" "process_message_call". Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -202,13 +278,15 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := recent_block_hashes : `List[Hash32]` Hashes of the recent 256 blocks in order of increasing block number. " in - let recent_blocks := + let _ := M.assign_local (| + "recent_blocks" , M.slice (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |), Constant.None_, Constant.None_ - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -232,15 +310,19 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let recent_block_hashes := - make_list [] in + let _ := M.assign_local (| + "recent_block_hashes" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "block" |), M.get_name (| globals, "recent_blocks" |), ltac:(M.monadic ( - let prev_block_hash := - M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in + let _ := M.assign_local (| + "prev_block_hash" , + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), make_list [ @@ -254,7 +336,8 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let most_recent_block_hash := + let _ := M.assign_local (| + "most_recent_block_hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -270,7 +353,8 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), make_list [ @@ -307,11 +391,13 @@ Definition state_transition : Value.t -> Value.t -> M := block : Block to apply to `chain`. " in - let parent_header := + let _ := M.assign_local (| + "parent_header" , M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 1 |) - |), "header" |) in + |), "header" |) + |) in let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ @@ -329,7 +415,8 @@ Definition state_transition : Value.t -> Value.t -> M := ], make_dict [] |) in - let apply_body_output := + let _ := M.assign_local (| + "apply_body_output" , M.call (| M.get_name (| globals, "apply_body" |), make_list [ @@ -352,7 +439,8 @@ Definition state_transition : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "chain" |), "chain_id" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -490,11 +578,13 @@ Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let parent_gas_target := + let _ := M.assign_local (| + "parent_gas_target" , BinOp.floor_div (| M.get_name (| globals, "parent_gas_limit" |), M.get_name (| globals, "ELASTICITY_MULTIPLIER" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -519,8 +609,10 @@ Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let expected_base_fee_per_gas := - M.get_name (| globals, "parent_base_fee_per_gas" |) in + let _ := M.assign_local (| + "expected_base_fee_per_gas" , + M.get_name (| globals, "parent_base_fee_per_gas" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -533,22 +625,29 @@ Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let gas_used_delta := + let _ := M.assign_local (| + "gas_used_delta" , BinOp.sub (| M.get_name (| globals, "parent_gas_used" |), M.get_name (| globals, "parent_gas_target" |) - |) in - let parent_fee_gas_delta := + |) + |) in + let _ := M.assign_local (| + "parent_fee_gas_delta" , BinOp.mult (| M.get_name (| globals, "parent_base_fee_per_gas" |), M.get_name (| globals, "gas_used_delta" |) - |) in - let target_fee_gas_delta := + |) + |) in + let _ := M.assign_local (| + "target_fee_gas_delta" , BinOp.floor_div (| M.get_name (| globals, "parent_fee_gas_delta" |), M.get_name (| globals, "parent_gas_target" |) - |) in - let base_fee_per_gas_delta := + |) + |) in + let _ := M.assign_local (| + "base_fee_per_gas_delta" , M.call (| M.get_name (| globals, "max" |), make_list [ @@ -559,40 +658,53 @@ Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := Constant.int 1 ], make_dict [] - |) in - let expected_base_fee_per_gas := + |) + |) in + let _ := M.assign_local (| + "expected_base_fee_per_gas" , BinOp.add (| M.get_name (| globals, "parent_base_fee_per_gas" |), M.get_name (| globals, "base_fee_per_gas_delta" |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let gas_used_delta := + let _ := M.assign_local (| + "gas_used_delta" , BinOp.sub (| M.get_name (| globals, "parent_gas_target" |), M.get_name (| globals, "parent_gas_used" |) - |) in - let parent_fee_gas_delta := + |) + |) in + let _ := M.assign_local (| + "parent_fee_gas_delta" , BinOp.mult (| M.get_name (| globals, "parent_base_fee_per_gas" |), M.get_name (| globals, "gas_used_delta" |) - |) in - let target_fee_gas_delta := + |) + |) in + let _ := M.assign_local (| + "target_fee_gas_delta" , BinOp.floor_div (| M.get_name (| globals, "parent_fee_gas_delta" |), M.get_name (| globals, "parent_gas_target" |) - |) in - let base_fee_per_gas_delta := + |) + |) in + let _ := M.assign_local (| + "base_fee_per_gas_delta" , BinOp.floor_div (| M.get_name (| globals, "target_fee_gas_delta" |), M.get_name (| globals, "BASE_FEE_MAX_CHANGE_DENOMINATOR" |) - |) in - let expected_base_fee_per_gas := + |) + |) in + let _ := M.assign_local (| + "expected_base_fee_per_gas" , BinOp.sub (| M.get_name (| globals, "parent_base_fee_per_gas" |), M.get_name (| globals, "base_fee_per_gas_delta" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -639,12 +751,15 @@ Definition validate_header : Value.t -> Value.t -> M := ], make_dict [] |) in - let is_fork_block := + let _ := M.assign_local (| + "is_fork_block" , Compare.eq (| M.get_field (| M.get_name (| globals, "header" |), "number" |), M.get_field (| M.get_name (| globals, "FORK_CRITERIA" |), "block_number" |) - |) in - let expected_base_fee_per_gas := + |) + |) in + let _ := M.assign_local (| + "expected_base_fee_per_gas" , M.call (| M.get_name (| globals, "calculate_base_fee_per_gas" |), make_list [ @@ -655,7 +770,8 @@ Definition validate_header : Value.t -> Value.t -> M := M.get_name (| globals, "is_fork_block" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -667,11 +783,13 @@ Definition validate_header : Value.t -> Value.t -> M := ], make_dict [] |) in - let parent_has_ommers := + let _ := M.assign_local (| + "parent_has_ommers" , Compare.not_eq (| M.get_field (| M.get_name (| globals, "parent_header" |), "ommers_hash" |), M.get_name (| globals, "EMPTY_OMMER_HASH" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -714,7 +832,8 @@ Definition validate_header : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_difficulty := + let _ := M.assign_local (| + "block_difficulty" , M.call (| M.get_name (| globals, "calculate_block_difficulty" |), make_list [ @@ -725,7 +844,8 @@ Definition validate_header : Value.t -> Value.t -> M := M.get_name (| globals, "parent_has_ommers" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -737,7 +857,8 @@ Definition validate_header : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_parent_hash := + let _ := M.assign_local (| + "block_parent_hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -750,7 +871,8 @@ Definition validate_header : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -796,7 +918,8 @@ Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := hash : `Hash32` The PoW valid rlp hash of the passed in header. " in - let header_data_without_pow_artefacts := + let _ := M.assign_local (| + "header_data_without_pow_artefacts" , make_list [ M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |); M.get_field (| M.get_name (| globals, "header" |), "ommers_hash" |); @@ -812,7 +935,8 @@ Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "header" |), "timestamp" |); M.get_field (| M.get_name (| globals, "header" |), "extra_data" |); M.get_field (| M.get_name (| globals, "header" |), "base_fee_per_gas" |) - ] in + ] + |) in let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), @@ -841,22 +965,26 @@ Definition validate_proof_of_work : Value.t -> Value.t -> M := header : Header of interest. " in - let header_hash := + let _ := M.assign_local (| + "header_hash" , M.call (| M.get_name (| globals, "generate_header_hash_for_pow" |), make_list [ M.get_name (| globals, "header" |) ], make_dict [] - |) in - let cache := + |) + |) in + let _ := M.assign_local (| + "cache" , M.call (| M.get_name (| globals, "generate_cache" |), make_list [ M.get_field (| M.get_name (| globals, "header" |), "number" |) ], make_dict [] - |) in + |) + |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "mix_digest" |); M.get_name (| globals, "result" |) ], M.call (| @@ -949,7 +1077,8 @@ Definition check_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_address := + let _ := M.assign_local (| + "sender_address" , M.call (| M.get_name (| globals, "recover_sender" |), make_list [ @@ -957,7 +1086,8 @@ Definition check_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "tx" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -993,7 +1123,8 @@ Definition check_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let priority_fee_per_gas := + let _ := M.assign_local (| + "priority_fee_per_gas" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -1004,12 +1135,15 @@ Definition check_transaction : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let effective_gas_price := + |) + |) in + let _ := M.assign_local (| + "effective_gas_price" , BinOp.add (| M.get_name (| globals, "priority_fee_per_gas" |), M.get_name (| globals, "base_fee_per_gas" |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1024,8 +1158,10 @@ Definition check_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let effective_gas_price := - M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) in + let _ := M.assign_local (| + "effective_gas_price" , + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) + |) in M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1056,12 +1192,14 @@ Definition make_receipt : Value.t -> Value.t -> M := receipt : The receipt for the transaction. " in - let receipt := + let _ := M.assign_local (| + "receipt" , M.call (| M.get_name (| globals, "Receipt" |), make_list [], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1182,8 +1320,10 @@ Definition apply_body : Value.t -> Value.t -> M := apply_body_output : `ApplyBodyOutput` Output of applying the block body to the state. " in - let gas_available := - M.get_name (| globals, "block_gas_limit" |) in + let _ := M.assign_local (| + "gas_available" , + M.get_name (| globals, "block_gas_limit" |) + |) in (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) @@ -1245,12 +1385,14 @@ Definition apply_body : Value.t -> Value.t -> M := make_dict [] |) |) in - let env := + let _ := M.assign_local (| + "env" , M.call (| M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |); M.get_name (| globals, "error" |) ], M.call (| @@ -1262,10 +1404,13 @@ Definition apply_body : Value.t -> Value.t -> M := make_dict [] |) |) in - let gas_available := BinOp.sub + let _ := M.assign_op_local (| + BinOp.sub, + "gas_available", M.get_name (| globals, "gas_used" |) - M.get_name (| globals, "gas_used" |) in - let receipt := + |) in + let _ := M.assign_local (| + "receipt" , M.call (| M.get_name (| globals, "make_receipt" |), make_list [ @@ -1278,7 +1423,8 @@ Definition apply_body : Value.t -> Value.t -> M := M.get_name (| globals, "logs" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ @@ -1300,9 +1446,11 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_logs := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "block_logs", M.get_name (| globals, "logs" |) - M.get_name (| globals, "logs" |) in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -1319,19 +1467,23 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_gas_used := + let _ := M.assign_local (| + "block_gas_used" , BinOp.sub (| M.get_name (| globals, "block_gas_limit" |), M.get_name (| globals, "gas_available" |) - |) in - let block_logs_bloom := + |) + |) in + let _ := M.assign_local (| + "block_logs_bloom" , M.call (| M.get_name (| globals, "logs_bloom" |), make_list [ M.get_name (| globals, "block_logs" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ApplyBodyOutput" |), @@ -1389,14 +1541,16 @@ Definition validate_ommers : Value.t -> Value.t -> M := chain : History and current state. " in - let block_hash := + let _ := M.assign_local (| + "block_hash" , M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), make_list [ M.get_name (| globals, "block_header" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1461,7 +1615,8 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_parent_header := + let _ := M.assign_local (| + "ommer_parent_header" , M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), BinOp.sub (| @@ -1471,7 +1626,8 @@ Definition validate_ommers : Value.t -> Value.t -> M := |) |), Constant.int 1 |) - |), "header" |) in + |), "header" |) + |) in let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ @@ -1503,8 +1659,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommers_hashes := - Constant.str "(* At expr: unsupported node type: ListComp *)" in + let _ := M.assign_local (| + "ommers_hashes" , + Constant.str "(* At expr: unsupported node type: ListComp *)" + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1534,7 +1692,8 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let recent_canonical_blocks := + let _ := M.assign_local (| + "recent_canonical_blocks" , M.slice (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| BinOp.add (| @@ -1543,23 +1702,28 @@ Definition validate_ommers : Value.t -> Value.t -> M := |) |), Constant.None_, Constant.None_ - |) in - let recent_canonical_block_hashes := - Constant.str "(* At expr: unsupported node type: SetComp *)" in + |) + |) in + let _ := M.assign_local (| + "recent_canonical_block_hashes" , + Constant.str "(* At expr: unsupported node type: SetComp *)" + |) in (* At stmt: unsupported node type: AnnAssign *) let _ := M.for_ (| M.get_name (| globals, "block" |), M.get_name (| globals, "recent_canonical_blocks" |), ltac:(M.monadic ( - let recent_ommers_hashes := + let _ := M.assign_local (| + "recent_ommers_hashes" , M.call (| M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), make_list [ Constant.str "(* At expr: unsupported node type: SetComp *)" ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -1577,11 +1741,13 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let ommer_hash := + let _ := M.assign_local (| + "ommer_hash" , M.get_subscript (| M.get_name (| globals, "ommers_hashes" |), M.get_name (| globals, "ommer_index" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1615,11 +1781,13 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_age := + let _ := M.assign_local (| + "ommer_age" , BinOp.sub (| M.get_field (| M.get_name (| globals, "block_header" |), "number" |), M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1697,7 +1865,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := ommers : List of ommers mentioned in the current block. " in - let miner_reward := + let _ := M.assign_local (| + "miner_reward" , BinOp.add (| M.get_name (| globals, "BLOCK_REWARD" |), BinOp.mult (| @@ -1713,7 +1882,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := Constant.int 32 |) |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "create_ether" |), make_list [ @@ -1728,7 +1898,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := M.get_name (| globals, "ommer" |), M.get_name (| globals, "ommers" |), ltac:(M.monadic ( - let ommer_age := + let _ := M.assign_local (| + "ommer_age" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -1738,8 +1909,10 @@ Definition pay_rewards : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let ommer_miner_reward := + |) + |) in + let _ := M.assign_local (| + "ommer_miner_reward" , BinOp.floor_div (| BinOp.mult (| BinOp.sub (| @@ -1749,7 +1922,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := M.get_name (| globals, "BLOCK_REWARD" |) |), Constant.int 8 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "create_ether" |), make_list [ @@ -1810,9 +1984,12 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender := - M.get_field (| M.get_name (| globals, "env" |), "origin" |) in - let sender_account := + let _ := M.assign_local (| + "sender" , + M.get_field (| M.get_name (| globals, "env" |), "origin" |) + |) in + let _ := M.assign_local (| + "sender_account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1820,7 +1997,8 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "sender" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1834,19 +2012,23 @@ Definition process_transaction : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let max_gas_fee := + let _ := M.assign_local (| + "max_gas_fee" , BinOp.mult (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let max_gas_fee := + let _ := M.assign_local (| + "max_gas_fee" , BinOp.mult (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -1889,12 +2071,15 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let effective_gas_fee := + let _ := M.assign_local (| + "effective_gas_fee" , BinOp.mult (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_field (| M.get_name (| globals, "env" |), "gas_price" |) - |) in - let gas := + |) + |) in + let _ := M.assign_local (| + "gas" , BinOp.sub (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.call (| @@ -1904,7 +2089,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "increment_nonce" |), make_list [ @@ -1913,11 +2099,13 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_balance_after_gas_fee := + let _ := M.assign_local (| + "sender_balance_after_gas_fee" , BinOp.sub (| M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), M.get_name (| globals, "effective_gas_fee" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -1927,18 +2115,22 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let preaccessed_addresses := + let _ := M.assign_local (| + "preaccessed_addresses" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let preaccessed_storage_keys := + |) + |) in + let _ := M.assign_local (| + "preaccessed_storage_keys" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1993,7 +2185,8 @@ Definition process_transaction : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let message := + let _ := M.assign_local (| + "message" , M.call (| M.get_name (| globals, "prepare_message" |), make_list [ @@ -2005,8 +2198,10 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in - let output := + |) + |) in + let _ := M.assign_local (| + "output" , M.call (| M.get_name (| globals, "process_message_call" |), make_list [ @@ -2014,13 +2209,17 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in - let gas_used := + |) + |) in + let _ := M.assign_local (| + "gas_used" , BinOp.sub (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_field (| M.get_name (| globals, "output" |), "gas_left" |) - |) in - let gas_refund := + |) + |) in + let _ := M.assign_local (| + "gas_refund" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -2031,21 +2230,27 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "output" |), "refund_counter" |) ], make_dict [] - |) in - let gas_refund_amount := + |) + |) in + let _ := M.assign_local (| + "gas_refund_amount" , BinOp.mult (| BinOp.add (| M.get_field (| M.get_name (| globals, "output" |), "gas_left" |), M.get_name (| globals, "gas_refund" |) |), M.get_field (| M.get_name (| globals, "env" |), "gas_price" |) - |) in - let priority_fee_per_gas := + |) + |) in + let _ := M.assign_local (| + "priority_fee_per_gas" , BinOp.sub (| M.get_field (| M.get_name (| globals, "env" |), "gas_price" |), M.get_field (| M.get_name (| globals, "env" |), "base_fee_per_gas" |) - |) in - let transaction_fee := + |) + |) in + let _ := M.assign_local (| + "transaction_fee" , BinOp.mult (| BinOp.sub (| BinOp.sub (| @@ -2055,13 +2260,17 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "gas_refund" |) |), M.get_name (| globals, "priority_fee_per_gas" |) - |) in - let total_gas_used := + |) + |) in + let _ := M.assign_local (| + "total_gas_used" , BinOp.sub (| M.get_name (| globals, "gas_used" |), M.get_name (| globals, "gas_refund" |) - |) in - let sender_balance_after_refund := + |) + |) in + let _ := M.assign_local (| + "sender_balance_after_refund" , BinOp.add (| M.get_field (| M.call (| M.get_name (| globals, "get_account" |), @@ -2072,7 +2281,8 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |), "balance" |), M.get_name (| globals, "gas_refund_amount" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -2082,7 +2292,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let coinbase_balance_after_mining_fee := + let _ := M.assign_local (| + "coinbase_balance_after_mining_fee" , BinOp.add (| M.get_field (| M.call (| M.get_name (| globals, "get_account" |), @@ -2093,7 +2304,8 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |), "balance" |), M.get_name (| globals, "transaction_fee" |) - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -2284,8 +2496,10 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := verified : `ethereum.base_types.Uint` The intrinsic cost of the transaction. " in - let data_cost := - Constant.int 0 in + let _ := M.assign_local (| + "data_cost" , + Constant.int 0 + |) in let _ := M.for_ (| M.get_name (| globals, "byte" |), @@ -2300,15 +2514,19 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let data_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "data_cost", M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let data_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "data_cost", M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -2332,17 +2550,23 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let create_cost := - M.get_name (| globals, "TX_CREATE_COST" |) in + let _ := M.assign_local (| + "create_cost" , + M.get_name (| globals, "TX_CREATE_COST" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let create_cost := - Constant.int 0 in + let _ := M.assign_local (| + "create_cost" , + Constant.int 0 + |) in M.pure Constant.None_ )) |) in - let access_list_cost := - Constant.int 0 in + let _ := M.assign_local (| + "access_list_cost" , + Constant.int 0 + |) in let _ := (* if *) M.if_then_else (| @@ -2361,10 +2585,14 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := make_tuple [ M.get_name (| globals, "_address" |); M.get_name (| globals, "keys" |) ], M.get_field (| M.get_name (| globals, "tx" |), "access_list" |), ltac:(M.monadic ( - let access_list_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "access_list_cost", M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) - M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) in - let access_list_cost := BinOp.add + |) in + let _ := M.assign_op_local (| + BinOp.add, + "access_list_cost", BinOp.mult (| M.call (| M.get_name (| globals, "len" |), @@ -2375,16 +2603,7 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) |) - BinOp.mult (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "keys" |) - ], - make_dict [] - |), - M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) - |) in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -2498,8 +2717,10 @@ Definition recover_sender : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let v := - M.get_field (| M.get_name (| globals, "tx" |), "v" |) in + let _ := M.assign_local (| + "v" , + M.get_field (| M.get_name (| globals, "tx" |), "v" |) + |) in let _ := (* if *) M.if_then_else (| @@ -2517,7 +2738,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let public_key := + let _ := M.assign_local (| + "public_key" , M.call (| M.get_name (| globals, "secp256k1_recover" |), make_list [ @@ -2536,7 +2758,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -2571,7 +2794,8 @@ Definition recover_sender : Value.t -> Value.t -> M := ], make_dict [] |) in - let public_key := + let _ := M.assign_local (| + "public_key" , M.call (| M.get_name (| globals, "secp256k1_recover" |), make_list [ @@ -2597,7 +2821,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -2616,7 +2841,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let public_key := + let _ := M.assign_local (| + "public_key" , M.call (| M.get_name (| globals, "secp256k1_recover" |), make_list [ @@ -2632,7 +2858,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -2649,7 +2876,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let public_key := + let _ := M.assign_local (| + "public_key" , M.call (| M.get_name (| globals, "secp256k1_recover" |), make_list [ @@ -2665,7 +2893,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -2930,11 +3159,13 @@ Definition check_gas_limit : Value.t -> Value.t -> M := check : `bool` True if gas limit constraints are satisfied, False otherwise. " in - let max_adjustment_delta := + let _ := M.assign_local (| + "max_adjustment_delta" , BinOp.floor_div (| M.get_name (| globals, "parent_gas_limit" |), M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -3038,7 +3269,8 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := difficulty : `ethereum.base_types.Uint` Computed difficulty for a block. " in - let offset := + let _ := M.assign_local (| + "offset" , BinOp.mult (| BinOp.floor_div (| M.call (| @@ -3082,8 +3314,10 @@ Constant.int 1 ], make_dict [] |) - |) in - let difficulty := + |) + |) in + let _ := M.assign_local (| + "difficulty" , BinOp.add (| M.call (| M.get_name (| globals, "int" |), @@ -3093,8 +3327,10 @@ Constant.int 1 make_dict [] |), M.get_name (| globals, "offset" |) - |) in - let num_bomb_periods := + |) + |) in + let _ := M.assign_local (| + "num_bomb_periods" , BinOp.sub (| BinOp.floor_div (| BinOp.sub (| @@ -3110,7 +3346,8 @@ Constant.int 1 Constant.int 100000 |), Constant.int 2 - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -3120,15 +3357,14 @@ Constant.int 1 |), (* then *) ltac:(M.monadic ( - let difficulty := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "difficulty", BinOp.pow (| Constant.int 2, M.get_name (| globals, "num_bomb_periods" |) |) - BinOp.pow (| - Constant.int 2, - M.get_name (| globals, "num_bomb_periods" |) - |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/london/fork_types.v b/CoqOfPython/ethereum/london/fork_types.v index d6c2db5..3c5e125 100644 --- a/CoqOfPython/ethereum/london/fork_types.v +++ b/CoqOfPython/ethereum/london/fork_types.v @@ -17,17 +17,29 @@ Introduction Types re-used throughout the specification, which are specific to Ethereum. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes20"; "Bytes256"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes20 : + IsImported globals "ethereum.base_types" "Bytes20". +Axiom ethereum_base_types_imports_Bytes256 : + IsImported globals "ethereum.base_types" "Bytes256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) diff --git a/CoqOfPython/ethereum/london/state.v b/CoqOfPython/ethereum/london/state.v index e32ff35..afa32da 100644 --- a/CoqOfPython/ethereum/london/state.v +++ b/CoqOfPython/ethereum/london/state.v @@ -22,23 +22,57 @@ There is a distinction between an account that does not exist and `EMPTY_ACCOUNT`. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass"; "field" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict"; "List"; "Optional"; "Set"; "Tuple" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "modify" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_london_fork_types_imports : - AreImported globals "ethereum.london.fork_types" [ "EMPTY_ACCOUNT"; "Account"; "Address"; "Root" ]. - -Axiom ethereum_london_trie_imports : - AreImported globals "ethereum.london.trie" [ "EMPTY_TRIE_ROOT"; "Trie"; "copy_trie"; "root"; "trie_get"; "trie_set" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". +Axiom dataclasses_imports_field : + IsImported globals "dataclasses" "field". + +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_modify : + IsImported globals "ethereum.base_types" "modify". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_london_fork_types_imports_EMPTY_ACCOUNT : + IsImported globals "ethereum.london.fork_types" "EMPTY_ACCOUNT". +Axiom ethereum_london_fork_types_imports_Account : + IsImported globals "ethereum.london.fork_types" "Account". +Axiom ethereum_london_fork_types_imports_Address : + IsImported globals "ethereum.london.fork_types" "Address". +Axiom ethereum_london_fork_types_imports_Root : + IsImported globals "ethereum.london.fork_types" "Root". + +Axiom ethereum_london_trie_imports_EMPTY_TRIE_ROOT : + IsImported globals "ethereum.london.trie" "EMPTY_TRIE_ROOT". +Axiom ethereum_london_trie_imports_Trie : + IsImported globals "ethereum.london.trie" "Trie". +Axiom ethereum_london_trie_imports_copy_trie : + IsImported globals "ethereum.london.trie" "copy_trie". +Axiom ethereum_london_trie_imports_root : + IsImported globals "ethereum.london.trie" "root". +Axiom ethereum_london_trie_imports_trie_get : + IsImported globals "ethereum.london.trie" "trie_get". +Axiom ethereum_london_trie_imports_trie_set : + IsImported globals "ethereum.london.trie" "trie_set". Definition State : Value.t := builtins.make_klass @@ -186,7 +220,8 @@ Definition get_account : Value.t -> Value.t -> M := account : `Account` Account at address. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account_optional" |), make_list [ @@ -194,7 +229,8 @@ Definition get_account : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -240,7 +276,8 @@ Definition get_account_optional : Value.t -> Value.t -> M := account : `Account` Account at address. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "trie_get" |), make_list [ @@ -248,7 +285,8 @@ Definition get_account_optional : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "account" |) |) in @@ -399,14 +437,16 @@ Definition get_storage : Value.t -> Value.t -> M := value : `U256` Value at the key. " in - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -430,7 +470,8 @@ Definition get_storage : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "trie_get" |), make_list [ @@ -438,7 +479,8 @@ Definition get_storage : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -481,14 +523,16 @@ Definition set_storage : Value.t -> Value.t -> M := |), Constant.None_ |) |) in - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -498,12 +542,14 @@ Definition set_storage : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_name (| globals, "Trie" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), @@ -530,7 +576,7 @@ Definition set_storage : Value.t -> Value.t -> M := M.if_then_else (| Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), - {} + Constant.str "(* At expr: unsupported node type: Dict *)" |), (* then *) ltac:(M.monadic ( @@ -676,7 +722,8 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := True if if an account has non zero nonce or non empty code, False otherwise. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -684,7 +731,8 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| BoolOp.or (| Compare.not_eq (| @@ -726,7 +774,8 @@ Definition is_account_empty : Value.t -> Value.t -> M := True if if an account has zero nonce, empty code and zero balance, False otherwise. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -734,7 +783,8 @@ Definition is_account_empty : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| BoolOp.and (| Compare.eq (| @@ -785,7 +835,8 @@ Definition account_exists_and_is_empty : Value.t -> Value.t -> M := True if an account exists and has zero nonce, empty code and zero balance, False otherwise. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account_optional" |), make_list [ @@ -793,7 +844,8 @@ Definition account_exists_and_is_empty : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| BoolOp.and (| Compare.is_not (| @@ -850,7 +902,8 @@ Definition is_account_alive : Value.t -> Value.t -> M := is_alive : `bool` True if the account is alive. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account_optional" |), make_list [ @@ -858,7 +911,8 @@ Definition is_account_alive : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1166,14 +1220,16 @@ Definition get_storage_original : Value.t -> Value.t -> M := Constant.int 0 |) |) in - let original_account_trie := + let _ := M.assign_local (| + "original_account_trie" , M.call (| M.get_field (| M.get_name (| globals, "original_trie" |), "get" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1183,18 +1239,21 @@ Definition get_storage_original : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let original_value := + let _ := M.assign_local (| + "original_value" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let original_value := + let _ := M.assign_local (| + "original_value" , M.call (| M.get_name (| globals, "trie_get" |), make_list [ @@ -1202,7 +1261,8 @@ Definition get_storage_original : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.assert (| M.call (| diff --git a/CoqOfPython/ethereum/london/transactions.v b/CoqOfPython/ethereum/london/transactions.v index a1c9195..432578b 100644 --- a/CoqOfPython/ethereum/london/transactions.v +++ b/CoqOfPython/ethereum/london/transactions.v @@ -9,23 +9,37 @@ submitted to be executed. If Ethereum is viewed as a state machine, transactions are the events that move between states. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". -Axiom typing_imports : - AreImported globals "typing" [ "Tuple"; "Union" ]. +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U64"; "U256"; "Bytes"; "Bytes0"; "Bytes32"; "Uint"; "slotted_freezable" ]. +Axiom ethereum_base_types_imports_U64 : + IsImported globals "ethereum.base_types" "U64". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". -Axiom ethereum_exceptions_imports : - AreImported globals "ethereum.exceptions" [ "InvalidBlock" ]. +Axiom ethereum_exceptions_imports_InvalidBlock : + IsImported globals "ethereum.exceptions" "InvalidBlock". -Axiom ethereum_london_fork_types_imports : - AreImported globals "ethereum.london.fork_types" [ "Address" ]. +Axiom ethereum_london_fork_types_imports_Address : + IsImported globals "ethereum.london.fork_types" "Address". Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( Constant.int 21000 diff --git a/CoqOfPython/ethereum/london/trie.v b/CoqOfPython/ethereum/london/trie.v index 08540f1..dac8ce1 100644 --- a/CoqOfPython/ethereum/london/trie.v +++ b/CoqOfPython/ethereum/london/trie.v @@ -20,38 +20,72 @@ The state trie is the structure responsible for storing (* At top_level_stmt: unsupported node type: Import *) -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass"; "field" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict"; "Generic"; "List"; "Mapping"; "MutableMapping"; "Optional"; "Sequence"; "TypeVar"; "Union"; "cast" ]. - -Axiom ethereum_berlin_imports : - AreImported globals "ethereum.berlin" [ "trie" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_utils_hexadecimal_imports : - AreImported globals "ethereum.utils.hexadecimal" [ "hex_to_bytes" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_london_blocks_imports : - AreImported globals "ethereum.london.blocks" [ "Receipt" ]. - -Axiom ethereum_london_fork_types_imports : - AreImported globals "ethereum.london.fork_types" [ "Account"; "Address"; "Root"; "encode_account" ]. - -Axiom ethereum_london_transactions_imports : - AreImported globals "ethereum.london.transactions" [ "LegacyTransaction" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". +Axiom dataclasses_imports_field : + IsImported globals "dataclasses" "field". + +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". +Axiom typing_imports_Generic : + IsImported globals "typing" "Generic". +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Mapping : + IsImported globals "typing" "Mapping". +Axiom typing_imports_MutableMapping : + IsImported globals "typing" "MutableMapping". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Sequence : + IsImported globals "typing" "Sequence". +Axiom typing_imports_TypeVar : + IsImported globals "typing" "TypeVar". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". +Axiom typing_imports_cast : + IsImported globals "typing" "cast". + +Axiom ethereum_berlin_imports_trie : + IsImported globals "ethereum.berlin" "trie". + +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_utils_hexadecimal_imports_hex_to_bytes : + IsImported globals "ethereum.utils.hexadecimal" "hex_to_bytes". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_london_blocks_imports_Receipt : + IsImported globals "ethereum.london.blocks" "Receipt". + +Axiom ethereum_london_fork_types_imports_Account : + IsImported globals "ethereum.london.fork_types" "Account". +Axiom ethereum_london_fork_types_imports_Address : + IsImported globals "ethereum.london.fork_types" "Address". +Axiom ethereum_london_fork_types_imports_Root : + IsImported globals "ethereum.london.fork_types" "Root". +Axiom ethereum_london_fork_types_imports_encode_account : + IsImported globals "ethereum.london.fork_types" "encode_account". + +Axiom ethereum_london_transactions_imports_LegacyTransaction : + IsImported globals "ethereum.london.transactions" "LegacyTransaction". Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -167,7 +201,7 @@ Definition encode_internal_node : Value.t -> Value.t -> M := when serialized. This function also accepts `None`, representing the absence of a node, - which is encoded to `b""""""`. + which is encoded to `b""""`. Parameters ---------- @@ -189,8 +223,10 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := - Constant.bytes "" in + let _ := M.assign_local (| + "unencoded" , + Constant.bytes "" + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -207,7 +243,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := + let _ := M.assign_local (| + "unencoded" , make_tuple [ M.call (| M.get_name (| globals, "nibble_list_to_compact" |), make_list [ @@ -215,7 +252,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := Constant.bool true ], make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in + |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -232,7 +270,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := + let _ := M.assign_local (| + "unencoded" , make_tuple [ M.call (| M.get_name (| globals, "nibble_list_to_compact" |), make_list [ @@ -240,7 +279,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := Constant.bool false ], make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in + |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -257,13 +297,15 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := + let _ := M.assign_local (| + "unencoded" , BinOp.add (| M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), make_list [ M.get_field (| M.get_name (| globals, "node" |), "value" |) ] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -282,14 +324,16 @@ Definition encode_internal_node : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - let encoded := + let _ := M.assign_local (| + "encoded" , M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), make_list [ M.get_name (| globals, "unencoded" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -681,12 +725,14 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := compressed : `bytearray` Compact byte array. " in - let compact := + let _ := M.assign_local (| + "compact" , M.call (| M.get_name (| globals, "bytearray" |), make_list [], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -866,7 +912,8 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := nibble_list : `Bytes` The `Bytes` in nibble-list format. " in - let nibble_list := + let _ := M.assign_local (| + "nibble_list" , M.call (| M.get_name (| globals, "bytearray" |), make_list [ @@ -882,7 +929,8 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ], @@ -990,15 +1038,18 @@ Definition _prepare_trie : Value.t -> Value.t -> M := M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "Address" |), make_list [ M.get_name (| globals, "preimage" |) ], make_dict [] - |) in - let encoded_value := + |) + |) in + let _ := M.assign_local (| + "encoded_value" , M.call (| M.get_name (| globals, "encode_node" |), make_list [ @@ -1012,18 +1063,21 @@ Definition _prepare_trie : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let encoded_value := + let _ := M.assign_local (| + "encoded_value" , M.call (| M.get_name (| globals, "encode_node" |), make_list [ M.get_name (| globals, "value" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -1044,19 +1098,23 @@ Definition _prepare_trie : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "trie" |), "secured" |), (* then *) ltac:(M.monadic ( - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "preimage" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let key := - M.get_name (| globals, "preimage" |) in + let _ := M.assign_local (| + "key" , + M.get_name (| globals, "preimage" |) + |) in M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -1103,7 +1161,8 @@ Definition root : Value.t -> Value.t -> M := root : `.fork_types.Root` MPT root of the underlying key-value pairs. " in - let obj := + let _ := M.assign_local (| + "obj" , M.call (| M.get_name (| globals, "_prepare_trie" |), make_list [ @@ -1111,8 +1170,10 @@ Definition root : Value.t -> Value.t -> M := M.get_name (| globals, "get_storage_root" |) ], make_dict [] - |) in - let root_node := + |) + |) in + let _ := M.assign_local (| + "root_node" , M.call (| M.get_name (| globals, "encode_internal_node" |), make_list [ @@ -1132,7 +1193,8 @@ Definition root : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1237,7 +1299,8 @@ Definition patricialize : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let arbitrary_key := + let _ := M.assign_local (| + "arbitrary_key" , M.call (| M.get_name (| globals, "next" |), make_list [ @@ -1250,7 +1313,8 @@ Definition patricialize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1266,7 +1330,8 @@ Definition patricialize : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let leaf := + let _ := M.assign_local (| + "leaf" , M.call (| M.get_name (| globals, "LeafNode" |), make_list [ @@ -1282,7 +1347,8 @@ Definition patricialize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "leaf" |) |) in @@ -1291,27 +1357,32 @@ Definition patricialize : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let substring := + let _ := M.assign_local (| + "substring" , M.slice (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |), Constant.None_, Constant.None_ - |) in - let prefix_length := + |) + |) in + let _ := M.assign_local (| + "prefix_length" , M.call (| M.get_name (| globals, "len" |), make_list [ M.get_name (| globals, "substring" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "key" |), M.get_name (| globals, "obj" |), ltac:(M.monadic ( - let prefix_length := + let _ := M.assign_local (| + "prefix_length" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -1331,7 +1402,8 @@ Definition patricialize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1362,7 +1434,8 @@ Definition patricialize : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let prefix := + let _ := M.assign_local (| + "prefix" , M.slice (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |), @@ -1371,7 +1444,8 @@ Definition patricialize : Value.t -> Value.t -> M := M.get_name (| globals, "prefix_length" |) |), Constant.None_ - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ExtensionNode" |), @@ -1418,7 +1492,7 @@ Definition patricialize : Value.t -> Value.t -> M := let _ := M.call (| M.get_field (| M.get_name (| globals, "branches" |), "append" |), make_list [ - {} + Constant.str "(* At expr: unsupported node type: Dict *)" ], make_dict [] |) in @@ -1428,8 +1502,10 @@ Definition patricialize : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let value := - Constant.bytes "" in + let _ := M.assign_local (| + "value" , + Constant.bytes "" + |) in let _ := M.for_ (| M.get_name (| globals, "key" |), @@ -1472,11 +1548,13 @@ Definition patricialize : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let value := + let _ := M.assign_local (| + "value" , M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/london/utils/address.v b/CoqOfPython/ethereum/london/utils/address.v index 7008573..f43bd88 100644 --- a/CoqOfPython/ethereum/london/utils/address.v +++ b/CoqOfPython/ethereum/london/utils/address.v @@ -18,23 +18,27 @@ Address specific functions used in this london version of specification. ". -Axiom typing_imports : - AreImported globals "typing" [ "Union" ]. +Axiom typing_imports_Union : + IsImported globals "typing" "Union". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes32"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_left_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "left_pad_zero_bytes". -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". -Axiom ethereum_london_fork_types_imports : - AreImported globals "ethereum.london.fork_types" [ "Address" ]. +Axiom ethereum_london_fork_types_imports_Address : + IsImported globals "ethereum.london.fork_types" "Address". Definition to_address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -91,7 +95,8 @@ Definition compute_contract_address : Value.t -> Value.t -> M := address: `Address` The computed address of the new account. " in - let computed_address := + let _ := M.assign_local (| + "computed_address" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -107,15 +112,19 @@ Definition compute_contract_address : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let canonical_address := + |) + |) in + let _ := M.assign_local (| + "canonical_address" , M.slice (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |), Constant.None_, Constant.None_ - |) in - let padded_address := + |) + |) in + let _ := M.assign_local (| + "padded_address" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -123,7 +132,8 @@ Definition compute_contract_address : Value.t -> Value.t -> M := Constant.int 20 ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Address" |), @@ -156,7 +166,8 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := address: `ethereum.london.fork_types.Address` The computed address of the new account. " in - let preimage := + let _ := M.assign_local (| + "preimage" , BinOp.add (| BinOp.add (| BinOp.add (| @@ -172,23 +183,29 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in - let computed_address := + |) + |) in + let _ := M.assign_local (| + "computed_address" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "preimage" |) ], make_dict [] - |) in - let canonical_address := + |) + |) in + let _ := M.assign_local (| + "canonical_address" , M.slice (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |), Constant.None_, Constant.None_ - |) in - let padded_address := + |) + |) in + let _ := M.assign_local (| + "padded_address" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -196,7 +213,8 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := Constant.int 20 ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Address" |), diff --git a/CoqOfPython/ethereum/london/utils/hexadecimal.v b/CoqOfPython/ethereum/london/utils/hexadecimal.v index bf7ef1e..94f210a 100644 --- a/CoqOfPython/ethereum/london/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/london/utils/hexadecimal.v @@ -18,11 +18,15 @@ Hexadecimal utility functions used in this specification, specific to London types. ". -Axiom ethereum_utils_hexadecimal_imports : - AreImported globals "ethereum.utils.hexadecimal" [ "remove_hex_prefix" ]. - -Axiom ethereum_london_fork_types_imports : - AreImported globals "ethereum.london.fork_types" [ "Address"; "Bloom"; "Root" ]. +Axiom ethereum_utils_hexadecimal_imports_remove_hex_prefix : + IsImported globals "ethereum.utils.hexadecimal" "remove_hex_prefix". + +Axiom ethereum_london_fork_types_imports_Address : + IsImported globals "ethereum.london.fork_types" "Address". +Axiom ethereum_london_fork_types_imports_Bloom : + IsImported globals "ethereum.london.fork_types" "Bloom". +Axiom ethereum_london_fork_types_imports_Root : + IsImported globals "ethereum.london.fork_types" "Root". Definition hex_to_root : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/london/utils/message.v b/CoqOfPython/ethereum/london/utils/message.v index ce358ab..573dcf4 100644 --- a/CoqOfPython/ethereum/london/utils/message.v +++ b/CoqOfPython/ethereum/london/utils/message.v @@ -18,26 +18,42 @@ Message specific functions used in this london version of specification. ". -Axiom typing_imports : - AreImported globals "typing" [ "FrozenSet"; "Optional"; "Tuple"; "Union" ]. +Axiom typing_imports_FrozenSet : + IsImported globals "typing" "FrozenSet". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Bytes32"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_london_fork_types_imports : - AreImported globals "ethereum.london.fork_types" [ "Address" ]. +Axiom ethereum_london_fork_types_imports_Address : + IsImported globals "ethereum.london.fork_types" "Address". -Axiom ethereum_london_state_imports : - AreImported globals "ethereum.london.state" [ "get_account" ]. +Axiom ethereum_london_state_imports_get_account : + IsImported globals "ethereum.london.state" "get_account". -Axiom ethereum_london_vm_imports : - AreImported globals "ethereum.london.vm" [ "Environment"; "Message" ]. +Axiom ethereum_london_vm_imports_Environment : + IsImported globals "ethereum.london.vm" "Environment". +Axiom ethereum_london_vm_imports_Message : + IsImported globals "ethereum.london.vm" "Message". -Axiom ethereum_london_vm_precompiled_contracts_mapping_imports : - AreImported globals "ethereum.london.vm.precompiled_contracts.mapping" [ "PRE_COMPILED_CONTRACTS" ]. +Axiom ethereum_london_vm_precompiled_contracts_mapping_imports_PRE_COMPILED_CONTRACTS : + IsImported globals "ethereum.london.vm.precompiled_contracts.mapping" "PRE_COMPILED_CONTRACTS". -Axiom ethereum_london_utils_address_imports : - AreImported globals "ethereum.london.utils.address" [ "compute_contract_address" ]. +Axiom ethereum_london_utils_address_imports_compute_contract_address : + IsImported globals "ethereum.london.utils.address" "compute_contract_address". Definition prepare_message : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -92,7 +108,8 @@ Definition prepare_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let current_target := + let _ := M.assign_local (| + "current_target" , M.call (| M.get_name (| globals, "compute_contract_address" |), make_list [ @@ -116,17 +133,22 @@ Definition prepare_message : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let msg_data := + |) + |) in + let _ := M.assign_local (| + "msg_data" , M.call (| M.get_name (| globals, "Bytes" |), make_list [ Constant.bytes "" ], make_dict [] - |) in - let code := - M.get_name (| globals, "data" |) in + |) + |) in + let _ := M.assign_local (| + "code" , + M.get_name (| globals, "data" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -143,11 +165,16 @@ Definition prepare_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let current_target := - M.get_name (| globals, "target" |) in - let msg_data := - M.get_name (| globals, "data" |) in - let code := + let _ := M.assign_local (| + "current_target" , + M.get_name (| globals, "target" |) + |) in + let _ := M.assign_local (| + "msg_data" , + M.get_name (| globals, "data" |) + |) in + let _ := M.assign_local (| + "code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -155,7 +182,8 @@ Definition prepare_message : Value.t -> Value.t -> M := M.get_name (| globals, "target" |) ], make_dict [] - |), "code" |) in + |), "code" |) + |) in let _ := (* if *) M.if_then_else (| @@ -165,8 +193,10 @@ Definition prepare_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let code_address := - M.get_name (| globals, "target" |) in + let _ := M.assign_local (| + "code_address" , + M.get_name (| globals, "target" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -186,12 +216,14 @@ Definition prepare_message : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - let accessed_addresses := + let _ := M.assign_local (| + "accessed_addresses" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "accessed_addresses" |), "add" |), make_list [ diff --git a/CoqOfPython/ethereum/london/vm/__init__.v b/CoqOfPython/ethereum/london/vm/__init__.v index 908c463..9d60f4a 100644 --- a/CoqOfPython/ethereum/london/vm/__init__.v +++ b/CoqOfPython/ethereum/london/vm/__init__.v @@ -18,29 +18,49 @@ The abstract computer which runs the code stored in an `.fork_types.Account`. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple"; "Union" ]. +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U64"; "U256"; "Bytes"; "Bytes0"; "Bytes32"; "Uint" ]. +Axiom ethereum_base_types_imports_U64 : + IsImported globals "ethereum.base_types" "U64". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". -Axiom ethereum_london_blocks_imports : - AreImported globals "ethereum.london.blocks" [ "Log" ]. +Axiom ethereum_london_blocks_imports_Log : + IsImported globals "ethereum.london.blocks" "Log". -Axiom ethereum_london_fork_types_imports : - AreImported globals "ethereum.london.fork_types" [ "Address" ]. +Axiom ethereum_london_fork_types_imports_Address : + IsImported globals "ethereum.london.fork_types" "Address". -Axiom ethereum_london_state_imports : - AreImported globals "ethereum.london.state" [ "State"; "account_exists_and_is_empty" ]. +Axiom ethereum_london_state_imports_State : + IsImported globals "ethereum.london.state" "State". +Axiom ethereum_london_state_imports_account_exists_and_is_empty : + IsImported globals "ethereum.london.state" "account_exists_and_is_empty". -Axiom ethereum_london_vm_precompiled_contracts_imports : - AreImported globals "ethereum.london.vm.precompiled_contracts" [ "RIPEMD160_ADDRESS" ]. +Axiom ethereum_london_vm_precompiled_contracts_imports_RIPEMD160_ADDRESS : + IsImported globals "ethereum.london.vm.precompiled_contracts" "RIPEMD160_ADDRESS". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] diff --git a/CoqOfPython/ethereum/london/vm/exceptions.v b/CoqOfPython/ethereum/london/vm/exceptions.v index 93e464a..277efd6 100644 --- a/CoqOfPython/ethereum/london/vm/exceptions.v +++ b/CoqOfPython/ethereum/london/vm/exceptions.v @@ -17,8 +17,8 @@ Introduction Exceptions which cause the EVM to halt exceptionally. ". -Axiom ethereum_exceptions_imports : - AreImported globals "ethereum.exceptions" [ "EthereumException" ]. +Axiom ethereum_exceptions_imports_EthereumException : + IsImported globals "ethereum.exceptions" "EthereumException". Definition ExceptionalHalt : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/london/vm/gas.v b/CoqOfPython/ethereum/london/vm/gas.v index bc67712..08eb313 100644 --- a/CoqOfPython/ethereum/london/vm/gas.v +++ b/CoqOfPython/ethereum/london/vm/gas.v @@ -17,26 +17,32 @@ Introduction EVM gas constants and calculators. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Tuple" ]. +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_trace_imports : - AreImported globals "ethereum.trace" [ "GasAndRefund"; "evm_trace" ]. +Axiom ethereum_trace_imports_GasAndRefund : + IsImported globals "ethereum.trace" "GasAndRefund". +Axiom ethereum_trace_imports_evm_trace : + IsImported globals "ethereum.trace" "evm_trace". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_london_vm_imports : - AreImported globals "ethereum.london.vm" [ "Evm" ]. +Axiom ethereum_london_vm_imports_Evm : + IsImported globals "ethereum.london.vm" "Evm". -Axiom ethereum_london_vm_exceptions_imports : - AreImported globals "ethereum.london.vm.exceptions" [ "OutOfGasError" ]. +Axiom ethereum_london_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.london.vm.exceptions" "OutOfGasError". Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -532,7 +538,8 @@ Definition calculate_memory_gas_cost : Value.t -> Value.t -> M := total_gas_cost : `ethereum.base_types.Uint` The gas cost for storing data in memory. " in - let size_in_words := + let _ := M.assign_local (| + "size_in_words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -542,25 +549,32 @@ Definition calculate_memory_gas_cost : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let linear_cost := + |) + |) in + let _ := M.assign_local (| + "linear_cost" , BinOp.mult (| M.get_name (| globals, "size_in_words" |), M.get_name (| globals, "GAS_MEMORY" |) - |) in - let quadratic_cost := + |) + |) in + let _ := M.assign_local (| + "quadratic_cost" , BinOp.floor_div (| BinOp.pow (| M.get_name (| globals, "size_in_words" |), Constant.int 2 |), Constant.int 512 - |) in - let total_gas_cost := + |) + |) in + let _ := M.assign_local (| + "total_gas_cost" , BinOp.add (| M.get_name (| globals, "linear_cost" |), M.get_name (| globals, "quadratic_cost" |) - |) in + |) + |) in (* At stmt: unsupported node type: Try *) M.pure Constant.None_)). @@ -582,23 +596,28 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := ------- extend_memory: `ExtendMemory` " in - let size_to_extend := + let _ := M.assign_local (| + "size_to_extend" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in - let to_be_paid := + |) + |) in + let _ := M.assign_local (| + "to_be_paid" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in - let current_size := + |) + |) in + let _ := M.assign_local (| + "current_size" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -611,7 +630,8 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ], @@ -632,15 +652,18 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let before_size := + let _ := M.assign_local (| + "before_size" , M.call (| M.get_name (| globals, "ceil32" |), make_list [ M.get_name (| globals, "current_size" |) ], make_dict [] - |) in - let after_size := + |) + |) in + let _ := M.assign_local (| + "after_size" , M.call (| M.get_name (| globals, "ceil32" |), make_list [ @@ -662,7 +685,8 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -678,42 +702,46 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let size_to_extend := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "size_to_extend", BinOp.sub (| M.get_name (| globals, "after_size" |), M.get_name (| globals, "before_size" |) |) - BinOp.sub (| - M.get_name (| globals, "after_size" |), - M.get_name (| globals, "before_size" |) - |) in - let already_paid := + |) in + let _ := M.assign_local (| + "already_paid" , M.call (| M.get_name (| globals, "calculate_memory_gas_cost" |), make_list [ M.get_name (| globals, "before_size" |) ], make_dict [] - |) in - let total_cost := + |) + |) in + let _ := M.assign_local (| + "total_cost" , M.call (| M.get_name (| globals, "calculate_memory_gas_cost" |), make_list [ M.get_name (| globals, "after_size" |) ], make_dict [] - |) in - let to_be_paid := BinOp.add + |) + |) in + let _ := M.assign_op_local (| + BinOp.add, + "to_be_paid", BinOp.sub (| M.get_name (| globals, "total_cost" |), M.get_name (| globals, "already_paid" |) |) - BinOp.sub (| - M.get_name (| globals, "total_cost" |), - M.get_name (| globals, "already_paid" |) - |) in - let current_size := - M.get_name (| globals, "after_size" |) in + |) in + let _ := M.assign_local (| + "current_size" , + M.get_name (| globals, "after_size" |) + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -760,7 +788,8 @@ Definition calculate_message_call_gas : Value.t -> Value.t -> M := ------- message_call_gas: `MessageCallGas` " in - let call_stipend := + let _ := M.assign_local (| + "call_stipend" , (* if *) M.if_then_else (| Compare.eq (| @@ -779,7 +808,8 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "call_stipend" |) - )) |) in + )) |) + |) in let _ := (* if *) M.if_then_else (| @@ -813,7 +843,8 @@ M.get_name (| globals, "call_stipend" |) )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -833,7 +864,8 @@ M.get_name (| globals, "call_stipend" |) |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "MessageCallGas" |), diff --git a/CoqOfPython/ethereum/london/vm/instructions/__init__.v b/CoqOfPython/ethereum/london/vm/instructions/__init__.v index bf96acb..ed385be 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/__init__.v +++ b/CoqOfPython/ethereum/london/vm/instructions/__init__.v @@ -20,44 +20,46 @@ implementations. (* At top_level_stmt: unsupported node type: Import *) -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict" ]. +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". -Axiom ethereum_london_vm_instructions_imports : - AreImported globals "ethereum.london.vm.instructions" [ "arithmetic" ]. +Axiom ethereum_london_vm_instructions_imports_arithmetic : + IsImported globals "ethereum.london.vm.instructions" "arithmetic". -Axiom ethereum_london_vm_instructions_imports : - AreImported globals "ethereum.london.vm.instructions" [ "bitwise" ]. +Axiom ethereum_london_vm_instructions_imports_bitwise : + IsImported globals "ethereum.london.vm.instructions" "bitwise". -Axiom ethereum_london_vm_instructions_imports : - AreImported globals "ethereum.london.vm.instructions" [ "block" ]. +Axiom ethereum_london_vm_instructions_imports_block : + IsImported globals "ethereum.london.vm.instructions" "block". -Axiom ethereum_london_vm_instructions_imports : - AreImported globals "ethereum.london.vm.instructions" [ "comparison" ]. +Axiom ethereum_london_vm_instructions_imports_comparison : + IsImported globals "ethereum.london.vm.instructions" "comparison". -Axiom ethereum_london_vm_instructions_imports : - AreImported globals "ethereum.london.vm.instructions" [ "control_flow" ]. +Axiom ethereum_london_vm_instructions_imports_control_flow : + IsImported globals "ethereum.london.vm.instructions" "control_flow". -Axiom ethereum_london_vm_instructions_imports : - AreImported globals "ethereum.london.vm.instructions" [ "environment" ]. +Axiom ethereum_london_vm_instructions_imports_environment : + IsImported globals "ethereum.london.vm.instructions" "environment". -Axiom ethereum_london_vm_instructions_imports : - AreImported globals "ethereum.london.vm.instructions" [ "keccak" ]. +Axiom ethereum_london_vm_instructions_imports_keccak : + IsImported globals "ethereum.london.vm.instructions" "keccak". -Axiom ethereum_london_vm_instructions_imports : - AreImported globals "ethereum.london.vm.instructions" [ "log" ]. +Axiom ethereum_london_vm_instructions_imports_log : + IsImported globals "ethereum.london.vm.instructions" "log". -Axiom ethereum_london_vm_instructions_imports : - AreImported globals "ethereum.london.vm.instructions" [ "memory" ]. +Axiom ethereum_london_vm_instructions_imports_memory : + IsImported globals "ethereum.london.vm.instructions" "memory". -Axiom ethereum_london_vm_instructions_imports : - AreImported globals "ethereum.london.vm.instructions" [ "stack" ]. +Axiom ethereum_london_vm_instructions_imports_stack : + IsImported globals "ethereum.london.vm.instructions" "stack". -Axiom ethereum_london_vm_instructions_imports : - AreImported globals "ethereum.london.vm.instructions" [ "storage" ]. +Axiom ethereum_london_vm_instructions_imports_storage : + IsImported globals "ethereum.london.vm.instructions" "storage". -Axiom ethereum_london_vm_instructions_imports : - AreImported globals "ethereum.london.vm.instructions" [ "system" ]. +Axiom ethereum_london_vm_instructions_imports_system : + IsImported globals "ethereum.london.vm.instructions" "system". Definition Ops : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/london/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/london/vm/instructions/arithmetic.v index c37cf66..1b66ceb 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/london/vm/instructions/arithmetic.v @@ -17,20 +17,38 @@ Introduction Implementations of the EVM Arithmetic instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U255_CEIL_VALUE"; "U256"; "U256_CEIL_VALUE"; "Uint" ]. +Axiom ethereum_base_types_imports_U255_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U255_CEIL_VALUE". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_U256_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U256_CEIL_VALUE". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "get_sign" ]. +Axiom ethereum_utils_numeric_imports_get_sign : + IsImported globals "ethereum.utils.numeric" "get_sign". -Axiom ethereum_london_vm_imports : - AreImported globals "ethereum.london.vm" [ "Evm" ]. +Axiom ethereum_london_vm_imports_Evm : + IsImported globals "ethereum.london.vm" "Evm". -Axiom ethereum_london_vm_gas_imports : - AreImported globals "ethereum.london.vm.gas" [ "GAS_EXPONENTIATION"; "GAS_EXPONENTIATION_PER_BYTE"; "GAS_LOW"; "GAS_MID"; "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_london_vm_gas_imports_GAS_EXPONENTIATION : + IsImported globals "ethereum.london.vm.gas" "GAS_EXPONENTIATION". +Axiom ethereum_london_vm_gas_imports_GAS_EXPONENTIATION_PER_BYTE : + IsImported globals "ethereum.london.vm.gas" "GAS_EXPONENTIATION_PER_BYTE". +Axiom ethereum_london_vm_gas_imports_GAS_LOW : + IsImported globals "ethereum.london.vm.gas" "GAS_LOW". +Axiom ethereum_london_vm_gas_imports_GAS_MID : + IsImported globals "ethereum.london.vm.gas" "GAS_MID". +Axiom ethereum_london_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.london.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_london_vm_gas_imports_charge_gas : + IsImported globals "ethereum.london.vm.gas" "charge_gas". -Axiom ethereum_london_vm_stack_imports : - AreImported globals "ethereum.london.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_london_vm_stack_imports_pop : + IsImported globals "ethereum.london.vm.stack" "pop". +Axiom ethereum_london_vm_stack_imports_push : + IsImported globals "ethereum.london.vm.stack" "push". Definition add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,22 +63,26 @@ Definition add : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -69,14 +91,16 @@ Definition add : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "x" |), "wrapping_add" |), make_list [ M.get_name (| globals, "y" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -105,22 +129,26 @@ Definition sub : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -129,14 +157,16 @@ Definition sub : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "x" |), "wrapping_sub" |), make_list [ M.get_name (| globals, "y" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -165,22 +195,26 @@ Definition mul : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -189,14 +223,16 @@ Definition mul : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "x" |), "wrapping_mul" |), make_list [ M.get_name (| globals, "y" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -225,22 +261,26 @@ Definition div : Value.t -> Value.t -> M := The current EVM frame. " in - let dividend := + let _ := M.assign_local (| + "dividend" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let divisor := + |) + |) in + let _ := M.assign_local (| + "divisor" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -258,22 +298,26 @@ Definition div : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let quotient := + let _ := M.assign_local (| + "quotient" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let quotient := + let _ := M.assign_local (| + "quotient" , BinOp.floor_div (| M.get_name (| globals, "dividend" |), M.get_name (| globals, "divisor" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -304,7 +348,8 @@ Definition sdiv : Value.t -> Value.t -> M := The current EVM frame. " in - let dividend := + let _ := M.assign_local (| + "dividend" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -315,8 +360,10 @@ Definition sdiv : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let divisor := + |) + |) in + let _ := M.assign_local (| + "divisor" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -327,7 +374,8 @@ Definition sdiv : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -345,8 +393,10 @@ Definition sdiv : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let quotient := - Constant.int 0 in + let _ := M.assign_local (| + "quotient" , + Constant.int 0 + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -367,12 +417,15 @@ Definition sdiv : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let quotient := - UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in + let _ := M.assign_local (| + "quotient" , + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let sign := + let _ := M.assign_local (| + "sign" , M.call (| M.get_name (| globals, "get_sign" |), make_list [ @@ -382,8 +435,10 @@ Definition sdiv : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let quotient := + |) + |) in + let _ := M.assign_local (| + "quotient" , BinOp.mult (| M.get_name (| globals, "sign" |), BinOp.floor_div (| @@ -402,7 +457,8 @@ Definition sdiv : Value.t -> Value.t -> M := make_dict [] |) |) - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -428,7 +484,7 @@ Definition sdiv : Value.t -> Value.t -> M := |) in M.pure Constant.None_)). -Definition mod : Value.t -> Value.t -> M := +Definition mod_ : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in let _ := Constant.str " @@ -441,22 +497,26 @@ Definition mod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -474,22 +534,26 @@ Definition mod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let remainder := + let _ := M.assign_local (| + "remainder" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let remainder := + let _ := M.assign_local (| + "remainder" , BinOp.mod_ (| M.get_name (| globals, "x" |), M.get_name (| globals, "y" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -520,7 +584,8 @@ Definition smod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -531,8 +596,10 @@ Definition smod : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -543,7 +610,8 @@ Definition smod : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -561,12 +629,15 @@ Definition smod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let remainder := - Constant.int 0 in + let _ := M.assign_local (| + "remainder" , + Constant.int 0 + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let remainder := + let _ := M.assign_local (| + "remainder" , BinOp.mult (| M.call (| M.get_name (| globals, "get_sign" |), @@ -591,7 +662,8 @@ Definition smod : Value.t -> Value.t -> M := make_dict [] |) |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -628,7 +700,8 @@ Definition addmod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -641,8 +714,10 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -655,8 +730,10 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let z := + |) + |) in + let _ := M.assign_local (| + "z" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -669,7 +746,8 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -687,18 +765,21 @@ Definition addmod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -711,7 +792,8 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -742,7 +824,8 @@ Definition mulmod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -755,8 +838,10 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -769,8 +854,10 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let z := + |) + |) in + let _ := M.assign_local (| + "z" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -783,7 +870,8 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -801,18 +889,21 @@ Definition mulmod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -825,7 +916,8 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -856,7 +948,8 @@ Definition exp : Value.t -> Value.t -> M := The current EVM frame. " in - let base := + let _ := M.assign_local (| + "base" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -869,8 +962,10 @@ Definition exp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exponent := + |) + |) in + let _ := M.assign_local (| + "exponent" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -883,21 +978,26 @@ Definition exp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exponent_bits := + |) + |) in + let _ := M.assign_local (| + "exponent_bits" , M.call (| M.get_field (| M.get_name (| globals, "exponent" |), "bit_length" |), make_list [], make_dict [] - |) in - let exponent_bytes := + |) + |) in + let _ := M.assign_local (| + "exponent_bytes" , BinOp.floor_div (| BinOp.add (| M.get_name (| globals, "exponent_bits" |), Constant.int 7 |), Constant.int 8 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -912,7 +1012,8 @@ Definition exp : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -927,7 +1028,8 @@ Definition exp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -956,22 +1058,26 @@ Definition signextend : Value.t -> Value.t -> M := The current EVM frame. " in - let byte_num := + let _ := M.assign_local (| + "byte_num" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -989,12 +1095,15 @@ Definition signextend : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := - M.get_name (| globals, "value" |) in + let _ := M.assign_local (| + "result" , + M.get_name (| globals, "value" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let value_bytes := + let _ := M.assign_local (| + "value_bytes" , M.call (| M.get_name (| globals, "bytes" |), make_list [ @@ -1005,8 +1114,10 @@ Definition signextend : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let value_bytes := + |) + |) in + let _ := M.assign_local (| + "value_bytes" , M.slice (| M.get_name (| globals, "value_bytes" |), BinOp.sub (| @@ -1021,15 +1132,18 @@ Definition signextend : Value.t -> Value.t -> M := |), Constant.None_, Constant.None_ - |) in - let sign_bit := + |) + |) in + let _ := M.assign_local (| + "sign_bit" , BinOp.r_shift (| M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), Constant.int 7 - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1039,26 +1153,31 @@ Definition signextend : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "value_bytes" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let num_bytes_prepend := + let _ := M.assign_local (| + "num_bytes_prepend" , BinOp.sub (| Constant.int 32, BinOp.add (| M.get_name (| globals, "byte_num" |), Constant.int 1 |) - |) in - let result := + |) + |) in + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -1079,7 +1198,8 @@ Definition signextend : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/london/vm/instructions/bitwise.v b/CoqOfPython/ethereum/london/vm/instructions/bitwise.v index 5568bf4..02bebb6 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/london/vm/instructions/bitwise.v @@ -17,17 +17,23 @@ Introduction Implementations of the EVM bitwise instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "U256_CEIL_VALUE" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_U256_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U256_CEIL_VALUE". -Axiom ethereum_london_vm_imports : - AreImported globals "ethereum.london.vm" [ "Evm" ]. +Axiom ethereum_london_vm_imports_Evm : + IsImported globals "ethereum.london.vm" "Evm". -Axiom ethereum_london_vm_gas_imports : - AreImported globals "ethereum.london.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_london_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.london.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_london_vm_gas_imports_charge_gas : + IsImported globals "ethereum.london.vm.gas" "charge_gas". -Axiom ethereum_london_vm_stack_imports : - AreImported globals "ethereum.london.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_london_vm_stack_imports_pop : + IsImported globals "ethereum.london.vm.stack" "pop". +Axiom ethereum_london_vm_stack_imports_push : + IsImported globals "ethereum.london.vm.stack" "push". Definition bitwise_and : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,22 +48,26 @@ Definition bitwise_and : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -97,22 +107,26 @@ Definition bitwise_or : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -152,22 +166,26 @@ Definition bitwise_xor : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -207,14 +225,16 @@ Definition bitwise_not : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -252,22 +272,26 @@ Definition get_byte : Value.t -> Value.t -> M := The current EVM frame. " in - let byte_index := + let _ := M.assign_local (| + "byte_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let word := + |) + |) in + let _ := M.assign_local (| + "word" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -285,43 +309,53 @@ Definition get_byte : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let extra_bytes_to_right := + let _ := M.assign_local (| + "extra_bytes_to_right" , BinOp.sub (| Constant.int 31, M.get_name (| globals, "byte_index" |) - |) in - let word := + |) + |) in + let _ := M.assign_local (| + "word" , BinOp.r_shift (| M.get_name (| globals, "word" |), BinOp.mult (| M.get_name (| globals, "extra_bytes_to_right" |), Constant.int 8 |) - |) in - let word := + |) + |) in + let _ := M.assign_local (| + "word" , BinOp.bit_and (| M.get_name (| globals, "word" |), Constant.int 255 - |) in - let result := + |) + |) in + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ M.get_name (| globals, "word" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -350,22 +384,26 @@ Definition bitwise_shl : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let shift := + let _ := M.assign_local (| + "shift" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -383,7 +421,8 @@ Definition bitwise_shl : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -396,18 +435,21 @@ Definition bitwise_shl : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -436,22 +478,26 @@ Definition bitwise_shr : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let shift := + let _ := M.assign_local (| + "shift" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -469,22 +515,26 @@ Definition bitwise_shr : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , BinOp.r_shift (| M.get_name (| globals, "value" |), M.get_name (| globals, "shift" |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -513,15 +563,18 @@ Definition bitwise_sar : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let shift := + let _ := M.assign_local (| + "shift" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let signed_value := + |) + |) in + let _ := M.assign_local (| + "signed_value" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -532,7 +585,8 @@ Definition bitwise_sar : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -550,7 +604,8 @@ Definition bitwise_sar : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), make_list [ @@ -560,7 +615,8 @@ Definition bitwise_sar : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -573,19 +629,23 @@ Definition bitwise_sar : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := - M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) in + let _ := M.assign_local (| + "result" , + M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/london/vm/instructions/block.v b/CoqOfPython/ethereum/london/vm/instructions/block.v index 2fdf889..e3bee4c 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/block.v +++ b/CoqOfPython/ethereum/london/vm/instructions/block.v @@ -17,17 +17,23 @@ Introduction Implementations of the EVM block instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_london_vm_imports : - AreImported globals "ethereum.london.vm" [ "Evm" ]. +Axiom ethereum_london_vm_imports_Evm : + IsImported globals "ethereum.london.vm" "Evm". -Axiom ethereum_london_vm_gas_imports : - AreImported globals "ethereum.london.vm.gas" [ "GAS_BASE"; "GAS_BLOCK_HASH"; "charge_gas" ]. +Axiom ethereum_london_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.london.vm.gas" "GAS_BASE". +Axiom ethereum_london_vm_gas_imports_GAS_BLOCK_HASH : + IsImported globals "ethereum.london.vm.gas" "GAS_BLOCK_HASH". +Axiom ethereum_london_vm_gas_imports_charge_gas : + IsImported globals "ethereum.london.vm.gas" "charge_gas". -Axiom ethereum_london_vm_stack_imports : - AreImported globals "ethereum.london.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_london_vm_stack_imports_pop : + IsImported globals "ethereum.london.vm.stack" "pop". +Axiom ethereum_london_vm_stack_imports_push : + IsImported globals "ethereum.london.vm.stack" "push". Definition block_hash : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,14 +48,16 @@ Definition block_hash : Value.t -> Value.t -> M := The current EVM frame. " in - let block_number := + let _ := M.assign_local (| + "block_number" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -78,19 +86,23 @@ Definition block_hash : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let hash := - Constant.bytes "00" in + let _ := M.assign_local (| + "hash" , + Constant.bytes "00" + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let hash := + let _ := M.assign_local (| + "hash" , M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), M.get_name (| globals, "block_number" |) |) |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/london/vm/instructions/comparison.v b/CoqOfPython/ethereum/london/vm/instructions/comparison.v index bc6ca77..4a78f2d 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/london/vm/instructions/comparison.v @@ -17,17 +17,21 @@ Introduction Implementations of the EVM Comparison instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_london_vm_imports : - AreImported globals "ethereum.london.vm" [ "Evm" ]. +Axiom ethereum_london_vm_imports_Evm : + IsImported globals "ethereum.london.vm" "Evm". -Axiom ethereum_london_vm_gas_imports : - AreImported globals "ethereum.london.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_london_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.london.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_london_vm_gas_imports_charge_gas : + IsImported globals "ethereum.london.vm.gas" "charge_gas". -Axiom ethereum_london_vm_stack_imports : - AreImported globals "ethereum.london.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_london_vm_stack_imports_pop : + IsImported globals "ethereum.london.vm.stack" "pop". +Axiom ethereum_london_vm_stack_imports_push : + IsImported globals "ethereum.london.vm.stack" "push". Definition less_than : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,22 +46,26 @@ Definition less_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -66,7 +74,8 @@ Definition less_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -76,7 +85,8 @@ Definition less_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -104,7 +114,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -115,8 +126,10 @@ Definition signed_less_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -127,7 +140,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -136,7 +150,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -146,7 +161,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -175,22 +191,26 @@ Definition greater_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -199,7 +219,8 @@ Definition greater_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -209,7 +230,8 @@ Definition greater_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -237,7 +259,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -248,8 +271,10 @@ Definition signed_greater_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -260,7 +285,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -269,7 +295,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -279,7 +306,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -308,22 +336,26 @@ Definition equal : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -332,7 +364,8 @@ Definition equal : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -342,7 +375,8 @@ Definition equal : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -371,14 +405,16 @@ Definition is_zero : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -387,7 +423,8 @@ Definition is_zero : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -397,7 +434,8 @@ Definition is_zero : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/london/vm/instructions/control_flow.v b/CoqOfPython/ethereum/london/vm/instructions/control_flow.v index 25913ee..263e036 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/london/vm/instructions/control_flow.v @@ -17,20 +17,32 @@ Introduction Implementations of the EVM control flow instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_london_vm_gas_imports : - AreImported globals "ethereum.london.vm.gas" [ "GAS_BASE"; "GAS_HIGH"; "GAS_JUMPDEST"; "GAS_MID"; "charge_gas" ]. +Axiom ethereum_london_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.london.vm.gas" "GAS_BASE". +Axiom ethereum_london_vm_gas_imports_GAS_HIGH : + IsImported globals "ethereum.london.vm.gas" "GAS_HIGH". +Axiom ethereum_london_vm_gas_imports_GAS_JUMPDEST : + IsImported globals "ethereum.london.vm.gas" "GAS_JUMPDEST". +Axiom ethereum_london_vm_gas_imports_GAS_MID : + IsImported globals "ethereum.london.vm.gas" "GAS_MID". +Axiom ethereum_london_vm_gas_imports_charge_gas : + IsImported globals "ethereum.london.vm.gas" "charge_gas". -Axiom ethereum_london_vm_imports : - AreImported globals "ethereum.london.vm" [ "Evm" ]. +Axiom ethereum_london_vm_imports_Evm : + IsImported globals "ethereum.london.vm" "Evm". -Axiom ethereum_london_vm_exceptions_imports : - AreImported globals "ethereum.london.vm.exceptions" [ "InvalidJumpDestError" ]. +Axiom ethereum_london_vm_exceptions_imports_InvalidJumpDestError : + IsImported globals "ethereum.london.vm.exceptions" "InvalidJumpDestError". -Axiom ethereum_london_vm_stack_imports : - AreImported globals "ethereum.london.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_london_vm_stack_imports_pop : + IsImported globals "ethereum.london.vm.stack" "pop". +Axiom ethereum_london_vm_stack_imports_push : + IsImported globals "ethereum.london.vm.stack" "push". Definition stop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -69,7 +81,8 @@ Definition jump : Value.t -> Value.t -> M := The current EVM frame. " in - let jump_dest := + let _ := M.assign_local (| + "jump_dest" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -82,7 +95,8 @@ Definition jump : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -132,7 +146,8 @@ Definition jumpi : Value.t -> Value.t -> M := The current EVM frame. " in - let jump_dest := + let _ := M.assign_local (| + "jump_dest" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -145,15 +160,18 @@ Definition jumpi : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let conditional_value := + |) + |) in + let _ := M.assign_local (| + "conditional_value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -171,11 +189,13 @@ Definition jumpi : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let destination := + let _ := M.assign_local (| + "destination" , BinOp.add (| M.get_field (| M.get_name (| globals, "evm" |), "pc" |), Constant.int 1 - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -192,8 +212,10 @@ Definition jumpi : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let destination := - M.get_name (| globals, "jump_dest" |) in + let _ := M.assign_local (| + "destination" , + M.get_name (| globals, "jump_dest" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/london/vm/instructions/environment.v b/CoqOfPython/ethereum/london/vm/instructions/environment.v index fe79dbd..f91ee73 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/london/vm/instructions/environment.v @@ -17,41 +17,63 @@ Introduction Implementations of the EVM environment related instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. - -Axiom ethereum_london_fork_types_imports : - AreImported globals "ethereum.london.fork_types" [ "EMPTY_ACCOUNT" ]. - -Axiom ethereum_london_state_imports : - AreImported globals "ethereum.london.state" [ "get_account" ]. - -Axiom ethereum_london_utils_address_imports : - AreImported globals "ethereum.london.utils.address" [ "to_address" ]. - -Axiom ethereum_london_vm_memory_imports : - AreImported globals "ethereum.london.vm.memory" [ "buffer_read"; "memory_write" ]. - -Axiom ethereum_london_vm_imports : - AreImported globals "ethereum.london.vm" [ "Evm" ]. - -Axiom ethereum_london_vm_exceptions_imports : - AreImported globals "ethereum.london.vm.exceptions" [ "OutOfBoundsRead" ]. - -Axiom ethereum_london_vm_gas_imports : - AreImported globals "ethereum.london.vm.gas" [ "GAS_BASE"; "GAS_COLD_ACCOUNT_ACCESS"; "GAS_COPY"; "GAS_FAST_STEP"; "GAS_RETURN_DATA_COPY"; "GAS_VERY_LOW"; "GAS_WARM_ACCESS"; "calculate_gas_extend_memory"; "charge_gas" ]. - -Axiom ethereum_london_vm_stack_imports : - AreImported globals "ethereum.london.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". + +Axiom ethereum_london_fork_types_imports_EMPTY_ACCOUNT : + IsImported globals "ethereum.london.fork_types" "EMPTY_ACCOUNT". + +Axiom ethereum_london_state_imports_get_account : + IsImported globals "ethereum.london.state" "get_account". + +Axiom ethereum_london_utils_address_imports_to_address : + IsImported globals "ethereum.london.utils.address" "to_address". + +Axiom ethereum_london_vm_memory_imports_buffer_read : + IsImported globals "ethereum.london.vm.memory" "buffer_read". +Axiom ethereum_london_vm_memory_imports_memory_write : + IsImported globals "ethereum.london.vm.memory" "memory_write". + +Axiom ethereum_london_vm_imports_Evm : + IsImported globals "ethereum.london.vm" "Evm". + +Axiom ethereum_london_vm_exceptions_imports_OutOfBoundsRead : + IsImported globals "ethereum.london.vm.exceptions" "OutOfBoundsRead". + +Axiom ethereum_london_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.london.vm.gas" "GAS_BASE". +Axiom ethereum_london_vm_gas_imports_GAS_COLD_ACCOUNT_ACCESS : + IsImported globals "ethereum.london.vm.gas" "GAS_COLD_ACCOUNT_ACCESS". +Axiom ethereum_london_vm_gas_imports_GAS_COPY : + IsImported globals "ethereum.london.vm.gas" "GAS_COPY". +Axiom ethereum_london_vm_gas_imports_GAS_FAST_STEP : + IsImported globals "ethereum.london.vm.gas" "GAS_FAST_STEP". +Axiom ethereum_london_vm_gas_imports_GAS_RETURN_DATA_COPY : + IsImported globals "ethereum.london.vm.gas" "GAS_RETURN_DATA_COPY". +Axiom ethereum_london_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.london.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_london_vm_gas_imports_GAS_WARM_ACCESS : + IsImported globals "ethereum.london.vm.gas" "GAS_WARM_ACCESS". +Axiom ethereum_london_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.london.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_london_vm_gas_imports_charge_gas : + IsImported globals "ethereum.london.vm.gas" "charge_gas". + +Axiom ethereum_london_vm_stack_imports_pop : + IsImported globals "ethereum.london.vm.stack" "pop". +Axiom ethereum_london_vm_stack_imports_push : + IsImported globals "ethereum.london.vm.stack" "push". Definition address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -107,7 +129,8 @@ Definition balance : Value.t -> Value.t -> M := The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -120,7 +143,8 @@ Definition balance : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -158,7 +182,8 @@ Definition balance : Value.t -> Value.t -> M := |) in M.pure Constant.None_ )) |) in - let balance := + let _ := M.assign_local (| + "balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -166,7 +191,8 @@ Definition balance : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -316,14 +342,16 @@ Definition calldataload : Value.t -> Value.t -> M := The current EVM frame. " in - let start_index := + let _ := M.assign_local (| + "start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -332,7 +360,8 @@ Definition calldataload : Value.t -> Value.t -> M := ], make_dict [] |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -347,7 +376,8 @@ Definition calldataload : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -432,31 +462,38 @@ Definition calldatacopy : Value.t -> Value.t -> M := The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let data_start_index := + |) + |) in + let _ := M.assign_local (| + "data_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -472,13 +509,17 @@ Definition calldatacopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -488,7 +529,8 @@ Definition calldatacopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -511,7 +553,8 @@ Definition calldatacopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -520,7 +563,8 @@ Definition calldatacopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -600,31 +644,38 @@ Definition codecopy : Value.t -> Value.t -> M := The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let code_start_index := + |) + |) in + let _ := M.assign_local (| + "code_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -640,13 +691,17 @@ Definition codecopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -656,7 +711,8 @@ Definition codecopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -679,7 +735,8 @@ Definition codecopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -688,7 +745,8 @@ Definition codecopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -759,7 +817,8 @@ Definition extcodesize : Value.t -> Value.t -> M := The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -772,7 +831,8 @@ Definition extcodesize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -810,7 +870,8 @@ Definition extcodesize : Value.t -> Value.t -> M := |) in M.pure Constant.None_ )) |) in - let codesize := + let _ := M.assign_local (| + "codesize" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -830,7 +891,8 @@ Definition extcodesize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -858,7 +920,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -871,32 +934,40 @@ Definition extcodecopy : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let memory_start_index := + |) + |) in + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let code_start_index := + |) + |) in + let _ := M.assign_local (| + "code_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -912,13 +983,17 @@ Definition extcodecopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -928,7 +1003,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -986,7 +1062,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let code := + let _ := M.assign_local (| + "code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -994,8 +1071,10 @@ Definition extcodecopy : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |), "code" |) in - let value := + |), "code" |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -1004,7 +1083,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -1079,31 +1159,38 @@ Definition returndatacopy : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let return_data_start_position := + |) + |) in + let _ := M.assign_local (| + "return_data_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -1119,13 +1206,17 @@ Definition returndatacopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_RETURN_DATA_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1135,7 +1226,8 @@ Definition returndatacopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1190,7 +1282,8 @@ Definition returndatacopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.slice (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |), @@ -1199,7 +1292,8 @@ Definition returndatacopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) |), Constant.None_ - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -1226,7 +1320,8 @@ Definition extcodehash : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1239,7 +1334,8 @@ Definition extcodehash : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1277,7 +1373,8 @@ Definition extcodehash : Value.t -> Value.t -> M := |) in M.pure Constant.None_ )) |) in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1285,7 +1382,8 @@ Definition extcodehash : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1295,18 +1393,21 @@ Definition extcodehash : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let codehash := + let _ := M.assign_local (| + "codehash" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let codehash := + let _ := M.assign_local (| + "codehash" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -1319,7 +1420,8 @@ Definition extcodehash : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -1358,7 +1460,8 @@ Definition self_balance : Value.t -> Value.t -> M := ], make_dict [] |) in - let balance := + let _ := M.assign_local (| + "balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1366,7 +1469,8 @@ Definition self_balance : Value.t -> Value.t -> M := M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/london/vm/instructions/keccak.v b/CoqOfPython/ethereum/london/vm/instructions/keccak.v index bfd364b..ddef676 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/london/vm/instructions/keccak.v @@ -17,26 +17,36 @@ Introduction Implementations of the EVM keccak instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_london_vm_imports : - AreImported globals "ethereum.london.vm" [ "Evm" ]. +Axiom ethereum_london_vm_imports_Evm : + IsImported globals "ethereum.london.vm" "Evm". -Axiom ethereum_london_vm_gas_imports : - AreImported globals "ethereum.london.vm.gas" [ "GAS_KECCAK256"; "GAS_KECCAK256_WORD"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_london_vm_gas_imports_GAS_KECCAK256 : + IsImported globals "ethereum.london.vm.gas" "GAS_KECCAK256". +Axiom ethereum_london_vm_gas_imports_GAS_KECCAK256_WORD : + IsImported globals "ethereum.london.vm.gas" "GAS_KECCAK256_WORD". +Axiom ethereum_london_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.london.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_london_vm_gas_imports_charge_gas : + IsImported globals "ethereum.london.vm.gas" "charge_gas". -Axiom ethereum_london_vm_memory_imports : - AreImported globals "ethereum.london.vm.memory" [ "memory_read_bytes" ]. +Axiom ethereum_london_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.london.vm.memory" "memory_read_bytes". -Axiom ethereum_london_vm_stack_imports : - AreImported globals "ethereum.london.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_london_vm_stack_imports_pop : + IsImported globals "ethereum.london.vm.stack" "pop". +Axiom ethereum_london_vm_stack_imports_push : + IsImported globals "ethereum.london.vm.stack" "push". Definition keccak : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -53,23 +63,28 @@ Definition keccak : Value.t -> Value.t -> M := The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -85,13 +100,17 @@ Definition keccak : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let word_gas_cost := + |) + |) in + let _ := M.assign_local (| + "word_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_KECCAK256_WORD" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -101,7 +120,8 @@ Definition keccak : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -124,7 +144,8 @@ Definition keccak : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let data := + let _ := M.assign_local (| + "data" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -133,15 +154,18 @@ Definition keccak : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in - let hash := + |) + |) in + let _ := M.assign_local (| + "hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "data" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/london/vm/instructions/log.v b/CoqOfPython/ethereum/london/vm/instructions/log.v index ce64677..8122664 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/log.v +++ b/CoqOfPython/ethereum/london/vm/instructions/log.v @@ -17,32 +17,40 @@ Introduction Implementations of the EVM logging instructions. ". -Axiom functools_imports : - AreImported globals "functools" [ "partial" ]. +Axiom functools_imports_partial : + IsImported globals "functools" "partial". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_london_blocks_imports : - AreImported globals "ethereum.london.blocks" [ "Log" ]. +Axiom ethereum_london_blocks_imports_Log : + IsImported globals "ethereum.london.blocks" "Log". -Axiom ethereum_london_vm_imports : - AreImported globals "ethereum.london.vm" [ "Evm" ]. +Axiom ethereum_london_vm_imports_Evm : + IsImported globals "ethereum.london.vm" "Evm". -Axiom ethereum_london_vm_exceptions_imports : - AreImported globals "ethereum.london.vm.exceptions" [ "WriteInStaticContext" ]. +Axiom ethereum_london_vm_exceptions_imports_WriteInStaticContext : + IsImported globals "ethereum.london.vm.exceptions" "WriteInStaticContext". -Axiom ethereum_london_vm_gas_imports : - AreImported globals "ethereum.london.vm.gas" [ "GAS_LOG"; "GAS_LOG_DATA"; "GAS_LOG_TOPIC"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_london_vm_gas_imports_GAS_LOG : + IsImported globals "ethereum.london.vm.gas" "GAS_LOG". +Axiom ethereum_london_vm_gas_imports_GAS_LOG_DATA : + IsImported globals "ethereum.london.vm.gas" "GAS_LOG_DATA". +Axiom ethereum_london_vm_gas_imports_GAS_LOG_TOPIC : + IsImported globals "ethereum.london.vm.gas" "GAS_LOG_TOPIC". +Axiom ethereum_london_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.london.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_london_vm_gas_imports_charge_gas : + IsImported globals "ethereum.london.vm.gas" "charge_gas". -Axiom ethereum_london_vm_memory_imports : - AreImported globals "ethereum.london.vm.memory" [ "memory_read_bytes" ]. +Axiom ethereum_london_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.london.vm.memory" "memory_read_bytes". -Axiom ethereum_london_vm_stack_imports : - AreImported globals "ethereum.london.vm.stack" [ "pop" ]. +Axiom ethereum_london_vm_stack_imports_pop : + IsImported globals "ethereum.london.vm.stack" "pop". Definition log_n : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -61,24 +69,30 @@ Definition log_n : Value.t -> Value.t -> M := The number of topics to be included in the log entry. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let topics := - make_list [] in + |) + |) in + let _ := M.assign_local (| + "topics" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "_" |), @@ -90,7 +104,8 @@ Definition log_n : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let topic := + let _ := M.assign_local (| + "topic" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -101,7 +116,8 @@ Definition log_n : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "topics" |), "append" |), make_list [ @@ -115,7 +131,8 @@ Definition log_n : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let extend_memory := + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -125,7 +142,8 @@ Definition log_n : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -165,12 +183,14 @@ Definition log_n : Value.t -> Value.t -> M := ], make_dict [] |) in - let log_entry := + let _ := M.assign_local (| + "log_entry" , M.call (| M.get_name (| globals, "Log" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "logs" |), BinOp.add (| diff --git a/CoqOfPython/ethereum/london/vm/instructions/memory.v b/CoqOfPython/ethereum/london/vm/instructions/memory.v index 1dd7862..494a8b3 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/london/vm/instructions/memory.v @@ -17,20 +17,32 @@ Introduction Implementations of the EVM Memory instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". -Axiom ethereum_london_vm_imports : - AreImported globals "ethereum.london.vm" [ "Evm" ]. +Axiom ethereum_london_vm_imports_Evm : + IsImported globals "ethereum.london.vm" "Evm". -Axiom ethereum_london_vm_gas_imports : - AreImported globals "ethereum.london.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_london_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.london.vm.gas" "GAS_BASE". +Axiom ethereum_london_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.london.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_london_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.london.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_london_vm_gas_imports_charge_gas : + IsImported globals "ethereum.london.vm.gas" "charge_gas". -Axiom ethereum_london_vm_memory_imports : - AreImported globals "ethereum.london.vm.memory" [ "memory_read_bytes"; "memory_write" ]. +Axiom ethereum_london_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.london.vm.memory" "memory_read_bytes". +Axiom ethereum_london_vm_memory_imports_memory_write : + IsImported globals "ethereum.london.vm.memory" "memory_write". -Axiom ethereum_london_vm_stack_imports : - AreImported globals "ethereum.london.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_london_vm_stack_imports_pop : + IsImported globals "ethereum.london.vm.stack" "pop". +Axiom ethereum_london_vm_stack_imports_push : + IsImported globals "ethereum.london.vm.stack" "push". Definition mstore : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -46,15 +58,18 @@ Definition mstore : Value.t -> Value.t -> M := The current EVM frame. " in - let start_position := + let _ := M.assign_local (| + "start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -65,8 +80,10 @@ Definition mstore : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -88,7 +105,8 @@ Definition mstore : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -138,23 +156,28 @@ Definition mstore8 : Value.t -> Value.t -> M := The current EVM frame. " in - let start_position := + let _ := M.assign_local (| + "start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -170,7 +193,8 @@ Definition mstore8 : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -190,7 +214,8 @@ Definition mstore8 : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let normalized_bytes_value := + let _ := M.assign_local (| + "normalized_bytes_value" , M.call (| M.get_name (| globals, "Bytes" |), make_list [ @@ -202,7 +227,8 @@ Definition mstore8 : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -231,15 +257,18 @@ Definition mload : Value.t -> Value.t -> M := The current EVM frame. " in - let start_position := + let _ := M.assign_local (| + "start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -255,7 +284,8 @@ Definition mload : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -275,7 +305,8 @@ Definition mload : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -296,7 +327,8 @@ Definition mload : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/london/vm/instructions/stack.v b/CoqOfPython/ethereum/london/vm/instructions/stack.v index 42b7bec..b5976e8 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/london/vm/instructions/stack.v @@ -17,26 +17,32 @@ Introduction Implementations of the EVM stack related instructions. ". -Axiom functools_imports : - AreImported globals "functools" [ "partial" ]. +Axiom functools_imports_partial : + IsImported globals "functools" "partial". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_london_vm_imports : - AreImported globals "ethereum.london.vm" [ "Evm"; "stack" ]. +Axiom ethereum_london_vm_imports_Evm : + IsImported globals "ethereum.london.vm" "Evm". +Axiom ethereum_london_vm_imports_stack : + IsImported globals "ethereum.london.vm" "stack". -Axiom ethereum_london_vm_exceptions_imports : - AreImported globals "ethereum.london.vm.exceptions" [ "StackUnderflowError" ]. +Axiom ethereum_london_vm_exceptions_imports_StackUnderflowError : + IsImported globals "ethereum.london.vm.exceptions" "StackUnderflowError". -Axiom ethereum_london_vm_gas_imports : - AreImported globals "ethereum.london.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_london_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.london.vm.gas" "GAS_BASE". +Axiom ethereum_london_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.london.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_london_vm_gas_imports_charge_gas : + IsImported globals "ethereum.london.vm.gas" "charge_gas". -Axiom ethereum_london_vm_memory_imports : - AreImported globals "ethereum.london.vm.memory" [ "buffer_read" ]. +Axiom ethereum_london_vm_memory_imports_buffer_read : + IsImported globals "ethereum.london.vm.memory" "buffer_read". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -98,7 +104,8 @@ Definition push_n : Value.t -> Value.t -> M := ], make_dict [] |) in - let data_to_push := + let _ := M.assign_local (| + "data_to_push" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -128,7 +135,8 @@ Definition push_n : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "stack" |), "push" |), make_list [ @@ -189,7 +197,8 @@ Definition dup_n : Value.t -> Value.t -> M := ], make_dict [] |) in - let data_to_duplicate := + let _ := M.assign_local (| + "data_to_duplicate" , M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| @@ -205,7 +214,8 @@ Definition dup_n : Value.t -> Value.t -> M := |), M.get_name (| globals, "item_number" |) |) - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "stack" |), "push" |), make_list [ diff --git a/CoqOfPython/ethereum/london/vm/instructions/storage.v b/CoqOfPython/ethereum/london/vm/instructions/storage.v index 2ca159e..ed374ae 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/london/vm/instructions/storage.v @@ -17,26 +17,46 @@ Introduction Implementations of the EVM storage related instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_london_state_imports : - AreImported globals "ethereum.london.state" [ "get_storage"; "get_storage_original"; "set_storage" ]. +Axiom ethereum_london_state_imports_get_storage : + IsImported globals "ethereum.london.state" "get_storage". +Axiom ethereum_london_state_imports_get_storage_original : + IsImported globals "ethereum.london.state" "get_storage_original". +Axiom ethereum_london_state_imports_set_storage : + IsImported globals "ethereum.london.state" "set_storage". -Axiom ethereum_london_vm_imports : - AreImported globals "ethereum.london.vm" [ "Evm" ]. +Axiom ethereum_london_vm_imports_Evm : + IsImported globals "ethereum.london.vm" "Evm". -Axiom ethereum_london_vm_exceptions_imports : - AreImported globals "ethereum.london.vm.exceptions" [ "OutOfGasError"; "WriteInStaticContext" ]. +Axiom ethereum_london_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.london.vm.exceptions" "OutOfGasError". +Axiom ethereum_london_vm_exceptions_imports_WriteInStaticContext : + IsImported globals "ethereum.london.vm.exceptions" "WriteInStaticContext". -Axiom ethereum_london_vm_gas_imports : - AreImported globals "ethereum.london.vm.gas" [ "GAS_CALL_STIPEND"; "GAS_COLD_SLOAD"; "GAS_STORAGE_CLEAR_REFUND"; "GAS_STORAGE_SET"; "GAS_STORAGE_UPDATE"; "GAS_WARM_ACCESS"; "charge_gas" ]. +Axiom ethereum_london_vm_gas_imports_GAS_CALL_STIPEND : + IsImported globals "ethereum.london.vm.gas" "GAS_CALL_STIPEND". +Axiom ethereum_london_vm_gas_imports_GAS_COLD_SLOAD : + IsImported globals "ethereum.london.vm.gas" "GAS_COLD_SLOAD". +Axiom ethereum_london_vm_gas_imports_GAS_STORAGE_CLEAR_REFUND : + IsImported globals "ethereum.london.vm.gas" "GAS_STORAGE_CLEAR_REFUND". +Axiom ethereum_london_vm_gas_imports_GAS_STORAGE_SET : + IsImported globals "ethereum.london.vm.gas" "GAS_STORAGE_SET". +Axiom ethereum_london_vm_gas_imports_GAS_STORAGE_UPDATE : + IsImported globals "ethereum.london.vm.gas" "GAS_STORAGE_UPDATE". +Axiom ethereum_london_vm_gas_imports_GAS_WARM_ACCESS : + IsImported globals "ethereum.london.vm.gas" "GAS_WARM_ACCESS". +Axiom ethereum_london_vm_gas_imports_charge_gas : + IsImported globals "ethereum.london.vm.gas" "charge_gas". -Axiom ethereum_london_vm_stack_imports : - AreImported globals "ethereum.london.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_london_vm_stack_imports_pop : + IsImported globals "ethereum.london.vm.stack" "pop". +Axiom ethereum_london_vm_stack_imports_push : + IsImported globals "ethereum.london.vm.stack" "push". Definition sload : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -51,7 +71,8 @@ Definition sload : Value.t -> Value.t -> M := The current EVM frame. " in - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -62,7 +83,8 @@ Definition sload : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -100,7 +122,8 @@ Definition sload : Value.t -> Value.t -> M := |) in M.pure Constant.None_ )) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "get_storage" |), make_list [ @@ -109,7 +132,8 @@ Definition sload : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -137,7 +161,8 @@ Definition sstore : Value.t -> Value.t -> M := The current EVM frame. " in - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -148,15 +173,18 @@ Definition sstore : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in - let new_value := + |) + |) in + let _ := M.assign_local (| + "new_value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -168,7 +196,8 @@ Definition sstore : Value.t -> Value.t -> M := ], make_dict [] |) in - let original_value := + let _ := M.assign_local (| + "original_value" , M.call (| M.get_name (| globals, "get_storage_original" |), make_list [ @@ -177,8 +206,10 @@ Definition sstore : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in - let current_value := + |) + |) in + let _ := M.assign_local (| + "current_value" , M.call (| M.get_name (| globals, "get_storage" |), make_list [ @@ -187,15 +218,18 @@ Definition sstore : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in - let gas_cost := + |) + |) in + let _ := M.assign_local (| + "gas_cost" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -212,9 +246,11 @@ Definition sstore : Value.t -> Value.t -> M := ], make_dict [] |) in - let gas_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "gas_cost", M.get_name (| globals, "GAS_COLD_SLOAD" |) - M.get_name (| globals, "GAS_COLD_SLOAD" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -246,29 +282,32 @@ Definition sstore : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let gas_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "gas_cost", M.get_name (| globals, "GAS_STORAGE_SET" |) - M.get_name (| globals, "GAS_STORAGE_SET" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let gas_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "gas_cost", BinOp.sub (| M.get_name (| globals, "GAS_STORAGE_UPDATE" |), M.get_name (| globals, "GAS_COLD_SLOAD" |) |) - BinOp.sub (| - M.get_name (| globals, "GAS_STORAGE_UPDATE" |), - M.get_name (| globals, "GAS_COLD_SLOAD" |) - |) in + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let gas_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "gas_cost", M.get_name (| globals, "GAS_WARM_ACCESS" |) - M.get_name (| globals, "GAS_WARM_ACCESS" |) in + |) in M.pure Constant.None_ )) |) in let _ := diff --git a/CoqOfPython/ethereum/london/vm/instructions/system.v b/CoqOfPython/ethereum/london/vm/instructions/system.v index 6d68d15..a747adf 100644 --- a/CoqOfPython/ethereum/london/vm/instructions/system.v +++ b/CoqOfPython/ethereum/london/vm/instructions/system.v @@ -17,38 +17,92 @@ Introduction Implementations of the EVM system related instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_london_fork_types_imports : - AreImported globals "ethereum.london.fork_types" [ "Address" ]. +Axiom ethereum_london_fork_types_imports_Address : + IsImported globals "ethereum.london.fork_types" "Address". -Axiom ethereum_london_state_imports : - AreImported globals "ethereum.london.state" [ "account_exists_and_is_empty"; "account_has_code_or_nonce"; "get_account"; "increment_nonce"; "is_account_alive"; "set_account_balance" ]. +Axiom ethereum_london_state_imports_account_exists_and_is_empty : + IsImported globals "ethereum.london.state" "account_exists_and_is_empty". +Axiom ethereum_london_state_imports_account_has_code_or_nonce : + IsImported globals "ethereum.london.state" "account_has_code_or_nonce". +Axiom ethereum_london_state_imports_get_account : + IsImported globals "ethereum.london.state" "get_account". +Axiom ethereum_london_state_imports_increment_nonce : + IsImported globals "ethereum.london.state" "increment_nonce". +Axiom ethereum_london_state_imports_is_account_alive : + IsImported globals "ethereum.london.state" "is_account_alive". +Axiom ethereum_london_state_imports_set_account_balance : + IsImported globals "ethereum.london.state" "set_account_balance". -Axiom ethereum_london_utils_address_imports : - AreImported globals "ethereum.london.utils.address" [ "compute_contract_address"; "compute_create2_contract_address"; "to_address" ]. +Axiom ethereum_london_utils_address_imports_compute_contract_address : + IsImported globals "ethereum.london.utils.address" "compute_contract_address". +Axiom ethereum_london_utils_address_imports_compute_create2_contract_address : + IsImported globals "ethereum.london.utils.address" "compute_create2_contract_address". +Axiom ethereum_london_utils_address_imports_to_address : + IsImported globals "ethereum.london.utils.address" "to_address". -Axiom ethereum_london_vm_imports : - AreImported globals "ethereum.london.vm" [ "Evm"; "Message"; "incorporate_child_on_error"; "incorporate_child_on_success" ]. +Axiom ethereum_london_vm_imports_Evm : + IsImported globals "ethereum.london.vm" "Evm". +Axiom ethereum_london_vm_imports_Message : + IsImported globals "ethereum.london.vm" "Message". +Axiom ethereum_london_vm_imports_incorporate_child_on_error : + IsImported globals "ethereum.london.vm" "incorporate_child_on_error". +Axiom ethereum_london_vm_imports_incorporate_child_on_success : + IsImported globals "ethereum.london.vm" "incorporate_child_on_success". -Axiom ethereum_london_vm_exceptions_imports : - AreImported globals "ethereum.london.vm.exceptions" [ "Revert"; "WriteInStaticContext" ]. +Axiom ethereum_london_vm_exceptions_imports_Revert : + IsImported globals "ethereum.london.vm.exceptions" "Revert". +Axiom ethereum_london_vm_exceptions_imports_WriteInStaticContext : + IsImported globals "ethereum.london.vm.exceptions" "WriteInStaticContext". -Axiom ethereum_london_vm_gas_imports : - AreImported globals "ethereum.london.vm.gas" [ "GAS_CALL_VALUE"; "GAS_COLD_ACCOUNT_ACCESS"; "GAS_CREATE"; "GAS_KECCAK256_WORD"; "GAS_NEW_ACCOUNT"; "GAS_SELF_DESTRUCT"; "GAS_SELF_DESTRUCT_NEW_ACCOUNT"; "GAS_WARM_ACCESS"; "GAS_ZERO"; "calculate_gas_extend_memory"; "calculate_message_call_gas"; "charge_gas"; "max_message_call_gas" ]. +Axiom ethereum_london_vm_gas_imports_GAS_CALL_VALUE : + IsImported globals "ethereum.london.vm.gas" "GAS_CALL_VALUE". +Axiom ethereum_london_vm_gas_imports_GAS_COLD_ACCOUNT_ACCESS : + IsImported globals "ethereum.london.vm.gas" "GAS_COLD_ACCOUNT_ACCESS". +Axiom ethereum_london_vm_gas_imports_GAS_CREATE : + IsImported globals "ethereum.london.vm.gas" "GAS_CREATE". +Axiom ethereum_london_vm_gas_imports_GAS_KECCAK256_WORD : + IsImported globals "ethereum.london.vm.gas" "GAS_KECCAK256_WORD". +Axiom ethereum_london_vm_gas_imports_GAS_NEW_ACCOUNT : + IsImported globals "ethereum.london.vm.gas" "GAS_NEW_ACCOUNT". +Axiom ethereum_london_vm_gas_imports_GAS_SELF_DESTRUCT : + IsImported globals "ethereum.london.vm.gas" "GAS_SELF_DESTRUCT". +Axiom ethereum_london_vm_gas_imports_GAS_SELF_DESTRUCT_NEW_ACCOUNT : + IsImported globals "ethereum.london.vm.gas" "GAS_SELF_DESTRUCT_NEW_ACCOUNT". +Axiom ethereum_london_vm_gas_imports_GAS_WARM_ACCESS : + IsImported globals "ethereum.london.vm.gas" "GAS_WARM_ACCESS". +Axiom ethereum_london_vm_gas_imports_GAS_ZERO : + IsImported globals "ethereum.london.vm.gas" "GAS_ZERO". +Axiom ethereum_london_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.london.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_london_vm_gas_imports_calculate_message_call_gas : + IsImported globals "ethereum.london.vm.gas" "calculate_message_call_gas". +Axiom ethereum_london_vm_gas_imports_charge_gas : + IsImported globals "ethereum.london.vm.gas" "charge_gas". +Axiom ethereum_london_vm_gas_imports_max_message_call_gas : + IsImported globals "ethereum.london.vm.gas" "max_message_call_gas". -Axiom ethereum_london_vm_memory_imports : - AreImported globals "ethereum.london.vm.memory" [ "memory_read_bytes"; "memory_write" ]. +Axiom ethereum_london_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.london.vm.memory" "memory_read_bytes". +Axiom ethereum_london_vm_memory_imports_memory_write : + IsImported globals "ethereum.london.vm.memory" "memory_write". -Axiom ethereum_london_vm_stack_imports : - AreImported globals "ethereum.london.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_london_vm_stack_imports_pop : + IsImported globals "ethereum.london.vm.stack" "pop". +Axiom ethereum_london_vm_stack_imports_push : + IsImported globals "ethereum.london.vm.stack" "push". Definition generic_create : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -64,7 +118,8 @@ Definition generic_create : Value.t -> Value.t -> M := ], make_dict [] |) in - let create_message_gas := + let _ := M.assign_local (| + "create_message_gas" , M.call (| M.get_name (| globals, "max_message_call_gas" |), make_list [ @@ -77,7 +132,8 @@ Definition generic_create : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.assign_op (| BinOp.sub, M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), @@ -95,9 +151,12 @@ Definition generic_create : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), Constant.bytes "" |) in - let sender_address := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in - let sender := + let _ := M.assign_local (| + "sender_address" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + |) in + let _ := M.assign_local (| + "sender" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -105,7 +164,8 @@ Definition generic_create : Value.t -> Value.t -> M := M.get_name (| globals, "sender_address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -216,7 +276,8 @@ Definition generic_create : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let call_data := + let _ := M.assign_local (| + "call_data" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -225,7 +286,8 @@ Definition generic_create : Value.t -> Value.t -> M := M.get_name (| globals, "memory_size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "increment_nonce" |), make_list [ @@ -234,13 +296,16 @@ Definition generic_create : Value.t -> Value.t -> M := ], make_dict [] |) in - let child_message := + let _ := M.assign_local (| + "child_message" , M.call (| M.get_name (| globals, "Message" |), make_list [], make_dict [] - |) in - let child_evm := + |) + |) in + let _ := M.assign_local (| + "child_evm" , M.call (| M.get_name (| globals, "process_create_message" |), make_list [ @@ -248,7 +313,8 @@ Definition generic_create : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -325,31 +391,38 @@ Definition create : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let endowment := + let _ := M.assign_local (| + "endowment" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_size := + |) + |) in + let _ := M.assign_local (| + "memory_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -359,7 +432,8 @@ Definition create : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -379,7 +453,8 @@ Definition create : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let contract_address := + let _ := M.assign_local (| + "contract_address" , M.call (| M.get_name (| globals, "compute_contract_address" |), make_list [ @@ -394,7 +469,8 @@ Definition create : Value.t -> Value.t -> M := |), "nonce" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "generic_create" |), make_list [ @@ -427,31 +503,38 @@ Definition create2 : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let endowment := + let _ := M.assign_local (| + "endowment" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_size := + |) + |) in + let _ := M.assign_local (| + "memory_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let salt := + |) + |) in + let _ := M.assign_local (| + "salt" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -462,8 +545,10 @@ Definition create2 : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -473,8 +558,10 @@ Definition create2 : Value.t -> Value.t -> M := ] ], make_dict [] - |) in - let call_data_words := + |) + |) in + let _ := M.assign_local (| + "call_data_words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -490,7 +577,8 @@ Definition create2 : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -516,7 +604,8 @@ Definition create2 : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let contract_address := + let _ := M.assign_local (| + "contract_address" , M.call (| M.get_name (| globals, "compute_create2_contract_address" |), make_list [ @@ -533,7 +622,8 @@ Definition create2 : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "generic_create" |), make_list [ @@ -563,23 +653,28 @@ Definition return_ : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let memory_start_position := + let _ := M.assign_local (| + "memory_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_size := + |) + |) in + let _ := M.assign_local (| + "memory_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -589,7 +684,8 @@ Definition return_ : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -678,7 +774,8 @@ Definition generic_call : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let call_data := + let _ := M.assign_local (| + "call_data" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -687,8 +784,10 @@ Definition generic_call : Value.t -> Value.t -> M := M.get_name (| globals, "memory_input_size" |) ], make_dict [] - |) in - let code := + |) + |) in + let _ := M.assign_local (| + "code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -696,14 +795,18 @@ Definition generic_call : Value.t -> Value.t -> M := M.get_name (| globals, "code_address" |) ], make_dict [] - |), "code" |) in - let child_message := + |), "code" |) + |) in + let _ := M.assign_local (| + "child_message" , M.call (| M.get_name (| globals, "Message" |), make_list [], make_dict [] - |) in - let child_evm := + |) + |) in + let _ := M.assign_local (| + "child_evm" , M.call (| M.get_name (| globals, "process_message" |), make_list [ @@ -711,7 +814,8 @@ Definition generic_call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -775,7 +879,8 @@ Definition generic_call : Value.t -> Value.t -> M := |) in M.pure Constant.None_ )) |) in - let actual_output_size := + let _ := M.assign_local (| + "actual_output_size" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -795,7 +900,8 @@ Definition generic_call : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -823,7 +929,8 @@ Definition call : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -836,8 +943,10 @@ Definition call : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let to := + |) + |) in + let _ := M.assign_local (| + "to" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -850,48 +959,60 @@ Definition call : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -902,7 +1023,8 @@ Definition call : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -912,8 +1034,10 @@ Definition call : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let access_gas_cost := - M.get_name (| globals, "GAS_WARM_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -924,11 +1048,14 @@ Definition call : Value.t -> Value.t -> M := ], make_dict [] |) in - let access_gas_cost := - M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + |) in M.pure Constant.None_ )) |) in - let create_gas_cost := + let _ := M.assign_local (| + "create_gas_cost" , (* if *) M.if_then_else (| BoolOp.or (| @@ -959,8 +1086,10 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "GAS_NEW_ACCOUNT" |) - )) |) in - let transfer_gas_cost := + )) |) + |) in + let _ := M.assign_local (| + "transfer_gas_cost" , (* if *) M.if_then_else (| Compare.eq (| @@ -979,8 +1108,10 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "GAS_CALL_VALUE" |) - )) |) in - let message_call_gas := + )) |) + |) in + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -1003,7 +1134,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1045,7 +1177,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let sender_balance := + let _ := M.assign_local (| + "sender_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1053,7 +1186,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := (* if *) M.if_then_else (| @@ -1127,7 +1261,8 @@ Definition callcode : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -1140,8 +1275,10 @@ Definition callcode : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let code_address := + |) + |) in + let _ := M.assign_local (| + "code_address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1154,50 +1291,64 @@ Definition callcode : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let to := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "to" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1208,7 +1359,8 @@ Definition callcode : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1218,8 +1370,10 @@ Definition callcode : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let access_gas_cost := - M.get_name (| globals, "GAS_WARM_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1230,11 +1384,14 @@ Definition callcode : Value.t -> Value.t -> M := ], make_dict [] |) in - let access_gas_cost := - M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + |) in M.pure Constant.None_ )) |) in - let transfer_gas_cost := + let _ := M.assign_local (| + "transfer_gas_cost" , (* if *) M.if_then_else (| Compare.eq (| @@ -1253,8 +1410,10 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "GAS_CALL_VALUE" |) - )) |) in - let message_call_gas := + )) |) + |) in + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -1274,7 +1433,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1294,7 +1454,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let sender_balance := + let _ := M.assign_local (| + "sender_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1302,7 +1463,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := (* if *) M.if_then_else (| @@ -1376,7 +1538,8 @@ Definition selfdestruct : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let beneficiary := + let _ := M.assign_local (| + "beneficiary" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1389,9 +1552,12 @@ Definition selfdestruct : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let gas_cost := - M.get_name (| globals, "GAS_SELF_DESTRUCT" |) in + |) + |) in + let _ := M.assign_local (| + "gas_cost" , + M.get_name (| globals, "GAS_SELF_DESTRUCT" |) + |) in let _ := (* if *) M.if_then_else (| @@ -1408,9 +1574,11 @@ Definition selfdestruct : Value.t -> Value.t -> M := ], make_dict [] |) in - let gas_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "gas_cost", M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) - M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1444,9 +1612,11 @@ Definition selfdestruct : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let gas_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "gas_cost", M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) - M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1468,9 +1638,12 @@ Definition selfdestruct : Value.t -> Value.t -> M := ], make_dict [] |) in - let originator := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in - let beneficiary_balance := + let _ := M.assign_local (| + "originator" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + |) in + let _ := M.assign_local (| + "beneficiary_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1478,8 +1651,10 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_name (| globals, "beneficiary" |) ], make_dict [] - |), "balance" |) in - let originator_balance := + |), "balance" |) + |) in + let _ := M.assign_local (| + "originator_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1487,7 +1662,8 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_name (| globals, "originator" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -1565,7 +1741,8 @@ Definition delegatecall : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -1578,8 +1755,10 @@ Definition delegatecall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let code_address := + |) + |) in + let _ := M.assign_local (| + "code_address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1592,40 +1771,50 @@ Definition delegatecall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1636,7 +1825,8 @@ Definition delegatecall : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1646,8 +1836,10 @@ Definition delegatecall : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let access_gas_cost := - M.get_name (| globals, "GAS_WARM_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1658,11 +1850,14 @@ Definition delegatecall : Value.t -> Value.t -> M := ], make_dict [] |) in - let access_gas_cost := - M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + |) in M.pure Constant.None_ )) |) in - let message_call_gas := + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -1685,7 +1880,8 @@ Definition delegatecall : Value.t -> Value.t -> M := M.get_name (| globals, "access_gas_cost" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1741,7 +1937,8 @@ Definition staticcall : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -1754,8 +1951,10 @@ Definition staticcall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let to := + |) + |) in + let _ := M.assign_local (| + "to" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1768,40 +1967,50 @@ Definition staticcall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1812,7 +2021,8 @@ Definition staticcall : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1822,8 +2032,10 @@ Definition staticcall : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let access_gas_cost := - M.get_name (| globals, "GAS_WARM_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1834,11 +2046,14 @@ Definition staticcall : Value.t -> Value.t -> M := ], make_dict [] |) in - let access_gas_cost := - M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + |) in M.pure Constant.None_ )) |) in - let message_call_gas := + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -1861,7 +2076,8 @@ Definition staticcall : Value.t -> Value.t -> M := M.get_name (| globals, "access_gas_cost" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1923,23 +2139,28 @@ Definition revert : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1949,7 +2170,8 @@ Definition revert : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1966,7 +2188,8 @@ Definition revert : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let output := + let _ := M.assign_local (| + "output" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -1975,7 +2198,8 @@ Definition revert : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| diff --git a/CoqOfPython/ethereum/london/vm/interpreter.v b/CoqOfPython/ethereum/london/vm/interpreter.v index 0fa190a..6398f45 100644 --- a/CoqOfPython/ethereum/london/vm/interpreter.v +++ b/CoqOfPython/ethereum/london/vm/interpreter.v @@ -17,50 +17,112 @@ Introduction A straightforward interpreter that executes EVM code. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Iterable"; "Optional"; "Set"; "Tuple" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. - -Axiom ethereum_trace_imports : - AreImported globals "ethereum.trace" [ "EvmStop"; "OpEnd"; "OpException"; "OpStart"; "PrecompileEnd"; "PrecompileStart"; "TransactionEnd"; "evm_trace" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_london_blocks_imports : - AreImported globals "ethereum.london.blocks" [ "Log" ]. - -Axiom ethereum_london_fork_types_imports : - AreImported globals "ethereum.london.fork_types" [ "Address" ]. - -Axiom ethereum_london_state_imports : - AreImported globals "ethereum.london.state" [ "account_exists_and_is_empty"; "account_has_code_or_nonce"; "begin_transaction"; "commit_transaction"; "destroy_storage"; "increment_nonce"; "mark_account_created"; "move_ether"; "rollback_transaction"; "set_code"; "touch_account" ]. - -Axiom ethereum_london_vm_imports : - AreImported globals "ethereum.london.vm" [ "Message" ]. - -Axiom ethereum_london_vm_gas_imports : - AreImported globals "ethereum.london.vm.gas" [ "GAS_CODE_DEPOSIT"; "charge_gas" ]. - -Axiom ethereum_london_vm_precompiled_contracts_mapping_imports : - AreImported globals "ethereum.london.vm.precompiled_contracts.mapping" [ "PRE_COMPILED_CONTRACTS" ]. - -Axiom ethereum_london_vm_imports : - AreImported globals "ethereum.london.vm" [ "Environment"; "Evm" ]. - -Axiom ethereum_london_vm_exceptions_imports : - AreImported globals "ethereum.london.vm.exceptions" [ "AddressCollision"; "ExceptionalHalt"; "InvalidContractPrefix"; "InvalidOpcode"; "OutOfGasError"; "Revert"; "StackDepthLimitError" ]. - -Axiom ethereum_london_vm_instructions_imports : - AreImported globals "ethereum.london.vm.instructions" [ "Ops"; "op_implementation" ]. - -Axiom ethereum_london_vm_runtime_imports : - AreImported globals "ethereum.london.vm.runtime" [ "get_valid_jump_destinations" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_Iterable : + IsImported globals "typing" "Iterable". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_trace_imports_EvmStop : + IsImported globals "ethereum.trace" "EvmStop". +Axiom ethereum_trace_imports_OpEnd : + IsImported globals "ethereum.trace" "OpEnd". +Axiom ethereum_trace_imports_OpException : + IsImported globals "ethereum.trace" "OpException". +Axiom ethereum_trace_imports_OpStart : + IsImported globals "ethereum.trace" "OpStart". +Axiom ethereum_trace_imports_PrecompileEnd : + IsImported globals "ethereum.trace" "PrecompileEnd". +Axiom ethereum_trace_imports_PrecompileStart : + IsImported globals "ethereum.trace" "PrecompileStart". +Axiom ethereum_trace_imports_TransactionEnd : + IsImported globals "ethereum.trace" "TransactionEnd". +Axiom ethereum_trace_imports_evm_trace : + IsImported globals "ethereum.trace" "evm_trace". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_london_blocks_imports_Log : + IsImported globals "ethereum.london.blocks" "Log". + +Axiom ethereum_london_fork_types_imports_Address : + IsImported globals "ethereum.london.fork_types" "Address". + +Axiom ethereum_london_state_imports_account_exists_and_is_empty : + IsImported globals "ethereum.london.state" "account_exists_and_is_empty". +Axiom ethereum_london_state_imports_account_has_code_or_nonce : + IsImported globals "ethereum.london.state" "account_has_code_or_nonce". +Axiom ethereum_london_state_imports_begin_transaction : + IsImported globals "ethereum.london.state" "begin_transaction". +Axiom ethereum_london_state_imports_commit_transaction : + IsImported globals "ethereum.london.state" "commit_transaction". +Axiom ethereum_london_state_imports_destroy_storage : + IsImported globals "ethereum.london.state" "destroy_storage". +Axiom ethereum_london_state_imports_increment_nonce : + IsImported globals "ethereum.london.state" "increment_nonce". +Axiom ethereum_london_state_imports_mark_account_created : + IsImported globals "ethereum.london.state" "mark_account_created". +Axiom ethereum_london_state_imports_move_ether : + IsImported globals "ethereum.london.state" "move_ether". +Axiom ethereum_london_state_imports_rollback_transaction : + IsImported globals "ethereum.london.state" "rollback_transaction". +Axiom ethereum_london_state_imports_set_code : + IsImported globals "ethereum.london.state" "set_code". +Axiom ethereum_london_state_imports_touch_account : + IsImported globals "ethereum.london.state" "touch_account". + +Axiom ethereum_london_vm_imports_Message : + IsImported globals "ethereum.london.vm" "Message". + +Axiom ethereum_london_vm_gas_imports_GAS_CODE_DEPOSIT : + IsImported globals "ethereum.london.vm.gas" "GAS_CODE_DEPOSIT". +Axiom ethereum_london_vm_gas_imports_charge_gas : + IsImported globals "ethereum.london.vm.gas" "charge_gas". + +Axiom ethereum_london_vm_precompiled_contracts_mapping_imports_PRE_COMPILED_CONTRACTS : + IsImported globals "ethereum.london.vm.precompiled_contracts.mapping" "PRE_COMPILED_CONTRACTS". + +Axiom ethereum_london_vm_imports_Environment : + IsImported globals "ethereum.london.vm" "Environment". +Axiom ethereum_london_vm_imports_Evm : + IsImported globals "ethereum.london.vm" "Evm". + +Axiom ethereum_london_vm_exceptions_imports_AddressCollision : + IsImported globals "ethereum.london.vm.exceptions" "AddressCollision". +Axiom ethereum_london_vm_exceptions_imports_ExceptionalHalt : + IsImported globals "ethereum.london.vm.exceptions" "ExceptionalHalt". +Axiom ethereum_london_vm_exceptions_imports_InvalidContractPrefix : + IsImported globals "ethereum.london.vm.exceptions" "InvalidContractPrefix". +Axiom ethereum_london_vm_exceptions_imports_InvalidOpcode : + IsImported globals "ethereum.london.vm.exceptions" "InvalidOpcode". +Axiom ethereum_london_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.london.vm.exceptions" "OutOfGasError". +Axiom ethereum_london_vm_exceptions_imports_Revert : + IsImported globals "ethereum.london.vm.exceptions" "Revert". +Axiom ethereum_london_vm_exceptions_imports_StackDepthLimitError : + IsImported globals "ethereum.london.vm.exceptions" "StackDepthLimitError". + +Axiom ethereum_london_vm_instructions_imports_Ops : + IsImported globals "ethereum.london.vm.instructions" "Ops". +Axiom ethereum_london_vm_instructions_imports_op_implementation : + IsImported globals "ethereum.london.vm.instructions" "op_implementation". + +Axiom ethereum_london_vm_runtime_imports_get_valid_jump_destinations : + IsImported globals "ethereum.london.vm.runtime" "get_valid_jump_destinations". Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -121,7 +183,8 @@ Definition process_message_call : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let is_collision := + let _ := M.assign_local (| + "is_collision" , M.call (| M.get_name (| globals, "account_has_code_or_nonce" |), make_list [ @@ -129,7 +192,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "message" |), "current_target" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -181,7 +245,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "process_create_message" |), make_list [ @@ -189,13 +254,15 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "process_message" |), make_list [ @@ -203,7 +270,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -250,46 +318,61 @@ Definition process_message_call : Value.t -> Value.t -> M := (* then *) ltac:(M.monadic ( (* At stmt: unsupported node type: AnnAssign *) - let accounts_to_delete := + let _ := M.assign_local (| + "accounts_to_delete" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let touched_accounts := + |) + |) in + let _ := M.assign_local (| + "touched_accounts" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let refund_counter := + |) + |) in + let _ := M.assign_local (| + "refund_counter" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let logs := - M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in - let accounts_to_delete := - M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in - let touched_accounts := - M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |) in - let refund_counter := + let _ := M.assign_local (| + "logs" , + M.get_field (| M.get_name (| globals, "evm" |), "logs" |) + |) in + let _ := M.assign_local (| + "accounts_to_delete" , + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) + |) in + let _ := M.assign_local (| + "touched_accounts" , + M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |) + |) in + let _ := M.assign_local (| + "refund_counter" , M.call (| M.get_name (| globals, "U256" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in - let tx_end := + let _ := M.assign_local (| + "tx_end" , M.call (| M.get_name (| globals, "TransactionEnd" |), make_list [ @@ -301,7 +384,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "error" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "evm_trace" |), make_list [ @@ -368,7 +452,8 @@ Definition process_create_message : Value.t -> Value.t -> M := ], make_dict [] |) in - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "process_message" |), make_list [ @@ -376,16 +461,20 @@ Definition process_create_message : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), (* then *) ltac:(M.monadic ( - let contract_code := - M.get_field (| M.get_name (| globals, "evm" |), "output" |) in - let contract_code_gas := + let _ := M.assign_local (| + "contract_code" , + M.get_field (| M.get_name (| globals, "evm" |), "output" |) + |) in + let _ := M.assign_local (| + "contract_code_gas" , BinOp.mult (| M.call (| M.get_name (| globals, "len" |), @@ -395,7 +484,8 @@ Definition process_create_message : Value.t -> Value.t -> M := make_dict [] |), M.get_name (| globals, "GAS_CODE_DEPOSIT" |) - |) in + |) + |) in (* At stmt: unsupported node type: Try *) M.pure Constant.None_ (* else *) @@ -497,7 +587,8 @@ Definition process_message : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "execute_code" |), make_list [ @@ -505,7 +596,8 @@ Definition process_message : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -554,22 +646,28 @@ Definition execute_code : Value.t -> Value.t -> M := evm: `ethereum.vm.EVM` Items containing execution specific objects " in - let code := - M.get_field (| M.get_name (| globals, "message" |), "code" |) in - let valid_jump_destinations := + let _ := M.assign_local (| + "code" , + M.get_field (| M.get_name (| globals, "message" |), "code" |) + |) in + let _ := M.assign_local (| + "valid_jump_destinations" , M.call (| M.get_name (| globals, "get_valid_jump_destinations" |), make_list [ M.get_name (| globals, "code" |) ], make_dict [] - |) in - let evm := + |) + |) in + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "Evm" |), make_list [], make_dict [] - |) in + |) + |) in (* At stmt: unsupported node type: Try *) let _ := M.return_ (| M.get_name (| globals, "evm" |) diff --git a/CoqOfPython/ethereum/london/vm/memory.v b/CoqOfPython/ethereum/london/vm/memory.v index 197e545..69b3e08 100644 --- a/CoqOfPython/ethereum/london/vm/memory.v +++ b/CoqOfPython/ethereum/london/vm/memory.v @@ -17,11 +17,15 @@ Introduction EVM memory operations. ". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "right_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_right_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "right_pad_zero_bytes". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". Definition memory_write : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/london/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/london/vm/precompiled_contracts/__init__.v index b034b9c..3866316 100644 --- a/CoqOfPython/ethereum/london/vm/precompiled_contracts/__init__.v +++ b/CoqOfPython/ethereum/london/vm/precompiled_contracts/__init__.v @@ -18,8 +18,8 @@ Addresses of precompiled contracts and mappings to their implementations. ". -Axiom ethereum_london_utils_hexadecimal_imports : - AreImported globals "ethereum.london.utils.hexadecimal" [ "hex_to_address" ]. +Axiom ethereum_london_utils_hexadecimal_imports_hex_to_address : + IsImported globals "ethereum.london.utils.hexadecimal" "hex_to_address". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS"; Constant.str "MODEXP_ADDRESS"; Constant.str "ALT_BN128_ADD_ADDRESS"; Constant.str "ALT_BN128_MUL_ADDRESS"; Constant.str "ALT_BN128_PAIRING_CHECK_ADDRESS"; Constant.str "BLAKE2F_ADDRESS" ] diff --git a/CoqOfPython/ethereum/london/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/london/vm/precompiled_contracts/alt_bn128.v index 37bf4a5..40ca063 100644 --- a/CoqOfPython/ethereum/london/vm/precompiled_contracts/alt_bn128.v +++ b/CoqOfPython/ethereum/london/vm/precompiled_contracts/alt_bn128.v @@ -17,26 +17,42 @@ Introduction Implementation of the ALT_BN128 precompiled contracts. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_alt_bn128_imports : - AreImported globals "ethereum.crypto.alt_bn128" [ "ALT_BN128_CURVE_ORDER"; "ALT_BN128_PRIME"; "BNF"; "BNF2"; "BNF12"; "BNP"; "BNP2"; "pairing" ]. +Axiom ethereum_crypto_alt_bn128_imports_ALT_BN128_CURVE_ORDER : + IsImported globals "ethereum.crypto.alt_bn128" "ALT_BN128_CURVE_ORDER". +Axiom ethereum_crypto_alt_bn128_imports_ALT_BN128_PRIME : + IsImported globals "ethereum.crypto.alt_bn128" "ALT_BN128_PRIME". +Axiom ethereum_crypto_alt_bn128_imports_BNF : + IsImported globals "ethereum.crypto.alt_bn128" "BNF". +Axiom ethereum_crypto_alt_bn128_imports_BNF2 : + IsImported globals "ethereum.crypto.alt_bn128" "BNF2". +Axiom ethereum_crypto_alt_bn128_imports_BNF12 : + IsImported globals "ethereum.crypto.alt_bn128" "BNF12". +Axiom ethereum_crypto_alt_bn128_imports_BNP : + IsImported globals "ethereum.crypto.alt_bn128" "BNP". +Axiom ethereum_crypto_alt_bn128_imports_BNP2 : + IsImported globals "ethereum.crypto.alt_bn128" "BNP2". +Axiom ethereum_crypto_alt_bn128_imports_pairing : + IsImported globals "ethereum.crypto.alt_bn128" "pairing". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_london_vm_imports : - AreImported globals "ethereum.london.vm" [ "Evm" ]. +Axiom ethereum_london_vm_imports_Evm : + IsImported globals "ethereum.london.vm" "Evm". -Axiom ethereum_london_vm_gas_imports : - AreImported globals "ethereum.london.vm.gas" [ "charge_gas" ]. +Axiom ethereum_london_vm_gas_imports_charge_gas : + IsImported globals "ethereum.london.vm.gas" "charge_gas". -Axiom ethereum_london_vm_memory_imports : - AreImported globals "ethereum.london.vm.memory" [ "buffer_read" ]. +Axiom ethereum_london_vm_memory_imports_buffer_read : + IsImported globals "ethereum.london.vm.memory" "buffer_read". -Axiom ethereum_london_vm_exceptions_imports : - AreImported globals "ethereum.london.vm.exceptions" [ "OutOfGasError" ]. +Axiom ethereum_london_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.london.vm.exceptions" "OutOfGasError". Definition alt_bn128_add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -49,8 +65,10 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -65,7 +83,8 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := ], make_dict [] |) in - let x0_bytes := + let _ := M.assign_local (| + "x0_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -86,16 +105,20 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let x0_value := + |) + |) in + let _ := M.assign_local (| + "x0_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "x0_bytes" |) ], make_dict [] - |) in - let y0_bytes := + |) + |) in + let _ := M.assign_local (| + "y0_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -116,16 +139,20 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y0_value := + |) + |) in + let _ := M.assign_local (| + "y0_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "y0_bytes" |) ], make_dict [] - |) in - let x1_bytes := + |) + |) in + let _ := M.assign_local (| + "x1_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -146,16 +173,20 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let x1_value := + |) + |) in + let _ := M.assign_local (| + "x1_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "x1_bytes" |) ], make_dict [] - |) in - let y1_bytes := + |) + |) in + let _ := M.assign_local (| + "y1_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -176,15 +207,18 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y1_value := + |) + |) in + let _ := M.assign_local (| + "y1_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "y1_bytes" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "i" |), @@ -212,11 +246,13 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := )) |) in (* At stmt: unsupported node type: Try *) - let p := + let _ := M.assign_local (| + "p" , BinOp.add (| M.get_name (| globals, "p0" |), M.get_name (| globals, "p1" |) - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), BinOp.add (| @@ -245,8 +281,10 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -261,7 +299,8 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := ], make_dict [] |) in - let x0_bytes := + let _ := M.assign_local (| + "x0_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -282,16 +321,20 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let x0_value := + |) + |) in + let _ := M.assign_local (| + "x0_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "x0_bytes" |) ], make_dict [] - |) in - let y0_bytes := + |) + |) in + let _ := M.assign_local (| + "y0_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -312,16 +355,20 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y0_value := + |) + |) in + let _ := M.assign_local (| + "y0_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "y0_bytes" |) ], make_dict [] - |) in - let n := + |) + |) in + let _ := M.assign_local (| + "n" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -348,7 +395,8 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "i" |), @@ -376,14 +424,16 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := )) |) in (* At stmt: unsupported node type: Try *) - let p := + let _ := M.assign_local (| + "p" , M.call (| M.get_field (| M.get_name (| globals, "p0" |), "mul_by" |), make_list [ M.get_name (| globals, "n" |) ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), BinOp.add (| @@ -412,8 +462,10 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -467,14 +519,16 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), make_list [ Constant.int 1 ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "i" |), @@ -495,8 +549,10 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let values := - make_list [] in + let _ := M.assign_local (| + "values" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "j" |), @@ -508,7 +564,8 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -541,7 +598,8 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -644,7 +702,8 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , BinOp.mult (| M.get_name (| globals, "result" |), M.call (| @@ -655,7 +714,8 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/london/vm/precompiled_contracts/blake2f.v b/CoqOfPython/ethereum/london/vm/precompiled_contracts/blake2f.v index 9673476..19507e0 100644 --- a/CoqOfPython/ethereum/london/vm/precompiled_contracts/blake2f.v +++ b/CoqOfPython/ethereum/london/vm/precompiled_contracts/blake2f.v @@ -17,20 +17,22 @@ Introduction Implementation of the `Blake2` precompiled contract. ". -Axiom ethereum_crypto_blake2_imports : - AreImported globals "ethereum.crypto.blake2" [ "Blake2b" ]. +Axiom ethereum_crypto_blake2_imports_Blake2b : + IsImported globals "ethereum.crypto.blake2" "Blake2b". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_london_vm_imports : - AreImported globals "ethereum.london.vm" [ "Evm" ]. +Axiom ethereum_london_vm_imports_Evm : + IsImported globals "ethereum.london.vm" "Evm". -Axiom ethereum_london_vm_gas_imports : - AreImported globals "ethereum.london.vm.gas" [ "GAS_BLAKE2_PER_ROUND"; "charge_gas" ]. +Axiom ethereum_london_vm_gas_imports_GAS_BLAKE2_PER_ROUND : + IsImported globals "ethereum.london.vm.gas" "GAS_BLAKE2_PER_ROUND". +Axiom ethereum_london_vm_gas_imports_charge_gas : + IsImported globals "ethereum.london.vm.gas" "charge_gas". -Axiom ethereum_london_vm_exceptions_imports : - AreImported globals "ethereum.london.vm.exceptions" [ "InvalidParameter" ]. +Axiom ethereum_london_vm_exceptions_imports_InvalidParameter : + IsImported globals "ethereum.london.vm.exceptions" "InvalidParameter". Definition blake2f : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -43,8 +45,10 @@ Definition blake2f : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -62,12 +66,14 @@ Definition blake2f : Value.t -> Value.t -> M := ], make_dict [] |) in - let blake2b := + let _ := M.assign_local (| + "blake2b" , M.call (| M.get_name (| globals, "Blake2b" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "rounds" |); M.get_name (| globals, "h" |); M.get_name (| globals, "m" |); M.get_name (| globals, "t_0" |); M.get_name (| globals, "t_1" |); M.get_name (| globals, "f" |) ], M.call (| diff --git a/CoqOfPython/ethereum/london/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/london/vm/precompiled_contracts/ecrecover.v index 3b1bf86..30d0b1a 100644 --- a/CoqOfPython/ethereum/london/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/london/vm/precompiled_contracts/ecrecover.v @@ -17,26 +17,32 @@ Introduction Implementation of the ECRECOVER precompiled contract. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_crypto_elliptic_curve_imports : - AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. +Axiom ethereum_crypto_elliptic_curve_imports_SECP256K1N : + IsImported globals "ethereum.crypto.elliptic_curve" "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_imports_secp256k1_recover : + IsImported globals "ethereum.crypto.elliptic_curve" "secp256k1_recover". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_left_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "left_pad_zero_bytes". -Axiom ethereum_london_vm_imports : - AreImported globals "ethereum.london.vm" [ "Evm" ]. +Axiom ethereum_london_vm_imports_Evm : + IsImported globals "ethereum.london.vm" "Evm". -Axiom ethereum_london_vm_gas_imports : - AreImported globals "ethereum.london.vm.gas" [ "GAS_ECRECOVER"; "charge_gas" ]. +Axiom ethereum_london_vm_gas_imports_GAS_ECRECOVER : + IsImported globals "ethereum.london.vm.gas" "GAS_ECRECOVER". +Axiom ethereum_london_vm_gas_imports_charge_gas : + IsImported globals "ethereum.london.vm.gas" "charge_gas". -Axiom ethereum_london_vm_memory_imports : - AreImported globals "ethereum.london.vm.memory" [ "buffer_read" ]. +Axiom ethereum_london_vm_memory_imports_buffer_read : + IsImported globals "ethereum.london.vm.memory" "buffer_read". Definition ecrecover : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -50,8 +56,10 @@ Definition ecrecover : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -60,7 +68,8 @@ Definition ecrecover : Value.t -> Value.t -> M := ], make_dict [] |) in - let message_hash_bytes := + let _ := M.assign_local (| + "message_hash_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -81,16 +90,20 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let message_hash := + |) + |) in + let _ := M.assign_local (| + "message_hash" , M.call (| M.get_name (| globals, "Hash32" |), make_list [ M.get_name (| globals, "message_hash_bytes" |) ], make_dict [] - |) in - let v := + |) + |) in + let _ := M.assign_local (| + "v" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -117,8 +130,10 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let r := + |) + |) in + let _ := M.assign_local (| + "r" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -145,8 +160,10 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let s := + |) + |) in + let _ := M.assign_local (| + "s" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -173,7 +190,8 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -250,7 +268,8 @@ Definition ecrecover : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: Try *) - let address := + let _ := M.assign_local (| + "address" , M.slice (| M.call (| M.get_name (| globals, "keccak256" |), @@ -262,8 +281,10 @@ Definition ecrecover : Value.t -> Value.t -> M := Constant.int 12, Constant.int 32, Constant.None_ - |) in - let padded_address := + |) + |) in + let _ := M.assign_local (| + "padded_address" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -271,7 +292,8 @@ Definition ecrecover : Value.t -> Value.t -> M := Constant.int 32 ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.get_name (| globals, "padded_address" |) diff --git a/CoqOfPython/ethereum/london/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/london/vm/precompiled_contracts/identity.v index df82aa3..df382e7 100644 --- a/CoqOfPython/ethereum/london/vm/precompiled_contracts/identity.v +++ b/CoqOfPython/ethereum/london/vm/precompiled_contracts/identity.v @@ -17,17 +17,21 @@ Introduction Implementation of the `IDENTITY` precompiled contract. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_london_vm_imports : - AreImported globals "ethereum.london.vm" [ "Evm" ]. +Axiom ethereum_london_vm_imports_Evm : + IsImported globals "ethereum.london.vm" "Evm". -Axiom ethereum_london_vm_gas_imports : - AreImported globals "ethereum.london.vm.gas" [ "GAS_IDENTITY"; "GAS_IDENTITY_WORD"; "charge_gas" ]. +Axiom ethereum_london_vm_gas_imports_GAS_IDENTITY : + IsImported globals "ethereum.london.vm.gas" "GAS_IDENTITY". +Axiom ethereum_london_vm_gas_imports_GAS_IDENTITY_WORD : + IsImported globals "ethereum.london.vm.gas" "GAS_IDENTITY_WORD". +Axiom ethereum_london_vm_gas_imports_charge_gas : + IsImported globals "ethereum.london.vm.gas" "charge_gas". Definition identity : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -40,9 +44,12 @@ Definition identity : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let word_count := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "word_count" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -64,7 +71,8 @@ Definition identity : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ diff --git a/CoqOfPython/ethereum/london/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/london/vm/precompiled_contracts/mapping.v index 83041fa..021da76 100644 --- a/CoqOfPython/ethereum/london/vm/precompiled_contracts/mapping.v +++ b/CoqOfPython/ethereum/london/vm/precompiled_contracts/mapping.v @@ -17,34 +17,56 @@ Introduction Mapping of precompiled contracts their implementations. ". -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict" ]. - -Axiom ethereum_london_fork_types_imports : - AreImported globals "ethereum.london.fork_types" [ "Address" ]. - -Axiom ethereum_london_vm_precompiled_contracts_imports : - AreImported globals "ethereum.london.vm.precompiled_contracts" [ "ALT_BN128_ADD_ADDRESS"; "ALT_BN128_MUL_ADDRESS"; "ALT_BN128_PAIRING_CHECK_ADDRESS"; "BLAKE2F_ADDRESS"; "ECRECOVER_ADDRESS"; "IDENTITY_ADDRESS"; "MODEXP_ADDRESS"; "RIPEMD160_ADDRESS"; "SHA256_ADDRESS" ]. - -Axiom ethereum_london_vm_precompiled_contracts_alt_bn128_imports : - AreImported globals "ethereum.london.vm.precompiled_contracts.alt_bn128" [ "alt_bn128_add"; "alt_bn128_mul"; "alt_bn128_pairing_check" ]. - -Axiom ethereum_london_vm_precompiled_contracts_blake2f_imports : - AreImported globals "ethereum.london.vm.precompiled_contracts.blake2f" [ "blake2f" ]. - -Axiom ethereum_london_vm_precompiled_contracts_ecrecover_imports : - AreImported globals "ethereum.london.vm.precompiled_contracts.ecrecover" [ "ecrecover" ]. - -Axiom ethereum_london_vm_precompiled_contracts_identity_imports : - AreImported globals "ethereum.london.vm.precompiled_contracts.identity" [ "identity" ]. - -Axiom ethereum_london_vm_precompiled_contracts_modexp_imports : - AreImported globals "ethereum.london.vm.precompiled_contracts.modexp" [ "modexp" ]. - -Axiom ethereum_london_vm_precompiled_contracts_ripemd160_imports : - AreImported globals "ethereum.london.vm.precompiled_contracts.ripemd160" [ "ripemd160" ]. - -Axiom ethereum_london_vm_precompiled_contracts_sha256_imports : - AreImported globals "ethereum.london.vm.precompiled_contracts.sha256" [ "sha256" ]. +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". + +Axiom ethereum_london_fork_types_imports_Address : + IsImported globals "ethereum.london.fork_types" "Address". + +Axiom ethereum_london_vm_precompiled_contracts_imports_ALT_BN128_ADD_ADDRESS : + IsImported globals "ethereum.london.vm.precompiled_contracts" "ALT_BN128_ADD_ADDRESS". +Axiom ethereum_london_vm_precompiled_contracts_imports_ALT_BN128_MUL_ADDRESS : + IsImported globals "ethereum.london.vm.precompiled_contracts" "ALT_BN128_MUL_ADDRESS". +Axiom ethereum_london_vm_precompiled_contracts_imports_ALT_BN128_PAIRING_CHECK_ADDRESS : + IsImported globals "ethereum.london.vm.precompiled_contracts" "ALT_BN128_PAIRING_CHECK_ADDRESS". +Axiom ethereum_london_vm_precompiled_contracts_imports_BLAKE2F_ADDRESS : + IsImported globals "ethereum.london.vm.precompiled_contracts" "BLAKE2F_ADDRESS". +Axiom ethereum_london_vm_precompiled_contracts_imports_ECRECOVER_ADDRESS : + IsImported globals "ethereum.london.vm.precompiled_contracts" "ECRECOVER_ADDRESS". +Axiom ethereum_london_vm_precompiled_contracts_imports_IDENTITY_ADDRESS : + IsImported globals "ethereum.london.vm.precompiled_contracts" "IDENTITY_ADDRESS". +Axiom ethereum_london_vm_precompiled_contracts_imports_MODEXP_ADDRESS : + IsImported globals "ethereum.london.vm.precompiled_contracts" "MODEXP_ADDRESS". +Axiom ethereum_london_vm_precompiled_contracts_imports_RIPEMD160_ADDRESS : + IsImported globals "ethereum.london.vm.precompiled_contracts" "RIPEMD160_ADDRESS". +Axiom ethereum_london_vm_precompiled_contracts_imports_SHA256_ADDRESS : + IsImported globals "ethereum.london.vm.precompiled_contracts" "SHA256_ADDRESS". + +Axiom ethereum_london_vm_precompiled_contracts_alt_bn128_imports_alt_bn128_add : + IsImported globals "ethereum.london.vm.precompiled_contracts.alt_bn128" "alt_bn128_add". +Axiom ethereum_london_vm_precompiled_contracts_alt_bn128_imports_alt_bn128_mul : + IsImported globals "ethereum.london.vm.precompiled_contracts.alt_bn128" "alt_bn128_mul". +Axiom ethereum_london_vm_precompiled_contracts_alt_bn128_imports_alt_bn128_pairing_check : + IsImported globals "ethereum.london.vm.precompiled_contracts.alt_bn128" "alt_bn128_pairing_check". + +Axiom ethereum_london_vm_precompiled_contracts_blake2f_imports_blake2f : + IsImported globals "ethereum.london.vm.precompiled_contracts.blake2f" "blake2f". + +Axiom ethereum_london_vm_precompiled_contracts_ecrecover_imports_ecrecover : + IsImported globals "ethereum.london.vm.precompiled_contracts.ecrecover" "ecrecover". + +Axiom ethereum_london_vm_precompiled_contracts_identity_imports_identity : + IsImported globals "ethereum.london.vm.precompiled_contracts.identity" "identity". + +Axiom ethereum_london_vm_precompiled_contracts_modexp_imports_modexp : + IsImported globals "ethereum.london.vm.precompiled_contracts.modexp" "modexp". + +Axiom ethereum_london_vm_precompiled_contracts_ripemd160_imports_ripemd160 : + IsImported globals "ethereum.london.vm.precompiled_contracts.ripemd160" "ripemd160". + +Axiom ethereum_london_vm_precompiled_contracts_sha256_imports_sha256 : + IsImported globals "ethereum.london.vm.precompiled_contracts.sha256" "sha256". (* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/london/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/london/vm/precompiled_contracts/modexp.v index 609b589..638770d 100644 --- a/CoqOfPython/ethereum/london/vm/precompiled_contracts/modexp.v +++ b/CoqOfPython/ethereum/london/vm/precompiled_contracts/modexp.v @@ -17,17 +17,21 @@ Introduction Implementation of the `MODEXP` precompiled contract. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_london_vm_imports : - AreImported globals "ethereum.london.vm" [ "Evm" ]. +Axiom ethereum_london_vm_imports_Evm : + IsImported globals "ethereum.london.vm" "Evm". -Axiom ethereum_london_vm_gas_imports : - AreImported globals "ethereum.london.vm.gas" [ "charge_gas" ]. +Axiom ethereum_london_vm_gas_imports_charge_gas : + IsImported globals "ethereum.london.vm.gas" "charge_gas". -Axiom ethereum_london_vm_memory_imports : - AreImported globals "ethereum.london.vm.memory" [ "buffer_read" ]. +Axiom ethereum_london_vm_memory_imports_buffer_read : + IsImported globals "ethereum.london.vm.memory" "buffer_read". Definition GQUADDIVISOR : Value.t := M.run ltac:(M.monadic ( Constant.int 3 @@ -40,9 +44,12 @@ Definition modexp : Value.t -> Value.t -> M := Calculates `(base**exp) % modulus` for arbitrary sized `base`, `exp` and. `modulus`. The return value is the same length as the modulus. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let base_length := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "base_length" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -69,8 +76,10 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exp_length := + |) + |) in + let _ := M.assign_local (| + "exp_length" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -97,8 +106,10 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let modulus_length := + |) + |) in + let _ := M.assign_local (| + "modulus_length" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -125,8 +136,10 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exp_start := + |) + |) in + let _ := M.assign_local (| + "exp_start" , BinOp.add (| M.call (| M.get_name (| globals, "U256" |), @@ -136,8 +149,10 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |), M.get_name (| globals, "base_length" |) - |) in - let exp_head := + |) + |) in + let _ := M.assign_local (| + "exp_head" , M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ @@ -165,7 +180,8 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -216,7 +232,8 @@ Definition modexp : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let base := + let _ := M.assign_local (| + "base" , M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ @@ -237,8 +254,10 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exp := + |) + |) in + let _ := M.assign_local (| + "exp" , M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ @@ -253,13 +272,17 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let modulus_start := + |) + |) in + let _ := M.assign_local (| + "modulus_start" , BinOp.add (| M.get_name (| globals, "exp_start" |), M.get_name (| globals, "exp_length" |) - |) in - let modulus := + |) + |) in + let _ := M.assign_local (| + "modulus" , M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ @@ -274,7 +297,8 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -350,7 +374,8 @@ Definition complexity : Value.t -> Value.t -> M := complexity : `Uint` Complexity of performing the operation. " in - let max_length := + let _ := M.assign_local (| + "max_length" , M.call (| M.get_name (| globals, "max" |), make_list [ @@ -370,15 +395,18 @@ Definition complexity : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| BinOp.add (| M.get_name (| globals, "max_length" |), Constant.int 7 |), Constant.int 8 - |) in + |) + |) in let _ := M.return_ (| BinOp.pow (| M.get_name (| globals, "words" |), @@ -427,14 +455,16 @@ Definition iterations : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let count := + let _ := M.assign_local (| + "count" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -447,7 +477,8 @@ Definition iterations : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let bit_length := + let _ := M.assign_local (| + "bit_length" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -458,7 +489,8 @@ Definition iterations : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -468,20 +500,25 @@ Definition iterations : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let bit_length := BinOp.sub + let _ := M.assign_op_local (| + BinOp.sub, + "bit_length", Constant.int 1 - Constant.int 1 in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let count := - M.get_name (| globals, "bit_length" |) in + let _ := M.assign_local (| + "count" , + M.get_name (| globals, "bit_length" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let length_part := + let _ := M.assign_local (| + "length_part" , BinOp.mult (| Constant.int 8, BinOp.sub (| @@ -494,8 +531,10 @@ Definition iterations : Value.t -> Value.t -> M := |), Constant.int 32 |) - |) in - let bits_part := + |) + |) in + let _ := M.assign_local (| + "bits_part" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -506,7 +545,8 @@ Definition iterations : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -516,19 +556,23 @@ Definition iterations : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let bits_part := BinOp.sub + let _ := M.assign_op_local (| + BinOp.sub, + "bits_part", Constant.int 1 - Constant.int 1 in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let count := + let _ := M.assign_local (| + "count" , BinOp.add (| M.get_name (| globals, "length_part" |), M.get_name (| globals, "bits_part" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -579,7 +623,8 @@ Definition gas_cost : Value.t -> Value.t -> M := gas_cost : `Uint` Gas required for performing the operation. " in - let multiplication_complexity := + let _ := M.assign_local (| + "multiplication_complexity" , M.call (| M.get_name (| globals, "complexity" |), make_list [ @@ -587,8 +632,10 @@ Definition gas_cost : Value.t -> Value.t -> M := M.get_name (| globals, "modulus_length" |) ], make_dict [] - |) in - let iteration_count := + |) + |) in + let _ := M.assign_local (| + "iteration_count" , M.call (| M.get_name (| globals, "iterations" |), make_list [ @@ -596,15 +643,20 @@ Definition gas_cost : Value.t -> Value.t -> M := M.get_name (| globals, "exponent_head" |) ], make_dict [] - |) in - let cost := + |) + |) in + let _ := M.assign_local (| + "cost" , BinOp.mult (| M.get_name (| globals, "multiplication_complexity" |), M.get_name (| globals, "iteration_count" |) - |) in - let cost := BinOp.floor_div + |) + |) in + let _ := M.assign_op_local (| + BinOp.floor_div, + "cost", M.get_name (| globals, "GQUADDIVISOR" |) - M.get_name (| globals, "GQUADDIVISOR" |) in + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "max" |), diff --git a/CoqOfPython/ethereum/london/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/london/vm/precompiled_contracts/ripemd160.v index 2cb0913..9c8567e 100644 --- a/CoqOfPython/ethereum/london/vm/precompiled_contracts/ripemd160.v +++ b/CoqOfPython/ethereum/london/vm/precompiled_contracts/ripemd160.v @@ -19,20 +19,24 @@ Implementation of the `RIPEMD160` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_left_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "left_pad_zero_bytes". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_london_vm_imports : - AreImported globals "ethereum.london.vm" [ "Evm" ]. +Axiom ethereum_london_vm_imports_Evm : + IsImported globals "ethereum.london.vm" "Evm". -Axiom ethereum_london_vm_gas_imports : - AreImported globals "ethereum.london.vm.gas" [ "GAS_RIPEMD160"; "GAS_RIPEMD160_WORD"; "charge_gas" ]. +Axiom ethereum_london_vm_gas_imports_GAS_RIPEMD160 : + IsImported globals "ethereum.london.vm.gas" "GAS_RIPEMD160". +Axiom ethereum_london_vm_gas_imports_GAS_RIPEMD160_WORD : + IsImported globals "ethereum.london.vm.gas" "GAS_RIPEMD160_WORD". +Axiom ethereum_london_vm_gas_imports_charge_gas : + IsImported globals "ethereum.london.vm.gas" "charge_gas". Definition ripemd160 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,9 +49,12 @@ Definition ripemd160 : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let word_count := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "word_count" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -69,7 +76,8 @@ Definition ripemd160 : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -84,7 +92,8 @@ Definition ripemd160 : Value.t -> Value.t -> M := ], make_dict [] |) in - let hash_bytes := + let _ := M.assign_local (| + "hash_bytes" , M.call (| M.get_field (| M.call (| M.get_field (| M.get_name (| globals, "hashlib" |), "new" |), @@ -96,8 +105,10 @@ Definition ripemd160 : Value.t -> Value.t -> M := |), "digest" |), make_list [], make_dict [] - |) in - let padded_hash := + |) + |) in + let _ := M.assign_local (| + "padded_hash" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -105,7 +116,8 @@ Definition ripemd160 : Value.t -> Value.t -> M := Constant.int 32 ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.get_name (| globals, "padded_hash" |) diff --git a/CoqOfPython/ethereum/london/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/london/vm/precompiled_contracts/sha256.v index 6a7d01d..ea0b74a 100644 --- a/CoqOfPython/ethereum/london/vm/precompiled_contracts/sha256.v +++ b/CoqOfPython/ethereum/london/vm/precompiled_contracts/sha256.v @@ -19,17 +19,21 @@ Implementation of the `SHA256` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_london_vm_imports : - AreImported globals "ethereum.london.vm" [ "Evm" ]. +Axiom ethereum_london_vm_imports_Evm : + IsImported globals "ethereum.london.vm" "Evm". -Axiom ethereum_london_vm_gas_imports : - AreImported globals "ethereum.london.vm.gas" [ "GAS_SHA256"; "GAS_SHA256_WORD"; "charge_gas" ]. +Axiom ethereum_london_vm_gas_imports_GAS_SHA256 : + IsImported globals "ethereum.london.vm.gas" "GAS_SHA256". +Axiom ethereum_london_vm_gas_imports_GAS_SHA256_WORD : + IsImported globals "ethereum.london.vm.gas" "GAS_SHA256_WORD". +Axiom ethereum_london_vm_gas_imports_charge_gas : + IsImported globals "ethereum.london.vm.gas" "charge_gas". Definition sha256 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,9 +46,12 @@ Definition sha256 : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let word_count := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "word_count" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -66,7 +73,8 @@ Definition sha256 : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ diff --git a/CoqOfPython/ethereum/london/vm/runtime.v b/CoqOfPython/ethereum/london/vm/runtime.v index 5900241..0b7292e 100644 --- a/CoqOfPython/ethereum/london/vm/runtime.v +++ b/CoqOfPython/ethereum/london/vm/runtime.v @@ -17,14 +17,14 @@ Introduction Runtime related operations used while executing EVM code. ". -Axiom typing_imports : - AreImported globals "typing" [ "Set" ]. +Axiom typing_imports_Set : + IsImported globals "typing" "Set". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_london_vm_instructions_imports : - AreImported globals "ethereum.london.vm.instructions" [ "Ops" ]. +Axiom ethereum_london_vm_instructions_imports_Ops : + IsImported globals "ethereum.london.vm.instructions" "Ops". Definition get_valid_jump_destinations : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -50,20 +50,24 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := valid_jump_destinations: `Set[Uint]` The set of valid jump destinations in the code. " in - let valid_jump_destinations := + let _ := M.assign_local (| + "valid_jump_destinations" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let pc := + |) + |) in + let _ := M.assign_local (| + "pc" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in let _ := M.while (| Compare.lt (| @@ -114,17 +118,21 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let push_data_size := + let _ := M.assign_local (| + "push_data_size" , BinOp.add (| BinOp.sub (| M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) |), Constant.int 1 - |) in - let pc := BinOp.add + |) + |) in + let _ := M.assign_op_local (| + BinOp.add, + "pc", M.get_name (| globals, "push_data_size" |) - M.get_name (| globals, "push_data_size" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -132,9 +140,11 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - let pc := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "pc", Constant.int 1 - Constant.int 1 in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/london/vm/stack.v b/CoqOfPython/ethereum/london/vm/stack.v index b72a931..745ac5c 100644 --- a/CoqOfPython/ethereum/london/vm/stack.v +++ b/CoqOfPython/ethereum/london/vm/stack.v @@ -17,14 +17,16 @@ Introduction Implementation of the stack operators for the EVM. ". -Axiom typing_imports : - AreImported globals "typing" [ "List" ]. +Axiom typing_imports_List : + IsImported globals "typing" "List". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_london_vm_exceptions_imports : - AreImported globals "ethereum.london.vm.exceptions" [ "StackOverflowError"; "StackUnderflowError" ]. +Axiom ethereum_london_vm_exceptions_imports_StackOverflowError : + IsImported globals "ethereum.london.vm.exceptions" "StackOverflowError". +Axiom ethereum_london_vm_exceptions_imports_StackUnderflowError : + IsImported globals "ethereum.london.vm.exceptions" "StackUnderflowError". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/muir_glacier/__init__.v b/CoqOfPython/ethereum/muir_glacier/__init__.v index 199ea08..bb77935 100644 --- a/CoqOfPython/ethereum/muir_glacier/__init__.v +++ b/CoqOfPython/ethereum/muir_glacier/__init__.v @@ -8,8 +8,8 @@ The Muir Glacier fork delays the difficulty bomb. There are no other changes in this fork. ". -Axiom ethereum_fork_criteria_imports : - AreImported globals "ethereum.fork_criteria" [ "ByBlockNumber" ]. +Axiom ethereum_fork_criteria_imports_ByBlockNumber : + IsImported globals "ethereum.fork_criteria" "ByBlockNumber". Definition FORK_CRITERIA : Value.t := M.run ltac:(M.monadic ( M.call (| diff --git a/CoqOfPython/ethereum/muir_glacier/blocks.v b/CoqOfPython/ethereum/muir_glacier/blocks.v index 2d9367b..2a404eb 100644 --- a/CoqOfPython/ethereum/muir_glacier/blocks.v +++ b/CoqOfPython/ethereum/muir_glacier/blocks.v @@ -14,23 +14,37 @@ history of all state transitions that have happened since the genesis of the chain. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Tuple" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes8"; "Bytes32"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. - -Axiom ethereum_muir_glacier_fork_types_imports : - AreImported globals "ethereum.muir_glacier.fork_types" [ "Address"; "Bloom"; "Root" ]. - -Axiom ethereum_muir_glacier_transactions_imports : - AreImported globals "ethereum.muir_glacier.transactions" [ "Transaction" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes8 : + IsImported globals "ethereum.base_types" "Bytes8". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". + +Axiom ethereum_muir_glacier_fork_types_imports_Address : + IsImported globals "ethereum.muir_glacier.fork_types" "Address". +Axiom ethereum_muir_glacier_fork_types_imports_Bloom : + IsImported globals "ethereum.muir_glacier.fork_types" "Bloom". +Axiom ethereum_muir_glacier_fork_types_imports_Root : + IsImported globals "ethereum.muir_glacier.fork_types" "Root". + +Axiom ethereum_muir_glacier_transactions_imports_Transaction : + IsImported globals "ethereum.muir_glacier.transactions" "Transaction". Definition Header : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/muir_glacier/bloom.v b/CoqOfPython/ethereum/muir_glacier/bloom.v index a821322..ee72a93 100644 --- a/CoqOfPython/ethereum/muir_glacier/bloom.v +++ b/CoqOfPython/ethereum/muir_glacier/bloom.v @@ -21,20 +21,20 @@ for efficient searching of logs by address and/or topic, by rapidly eliminating blocks and receipts from their search. ". -Axiom typing_imports : - AreImported globals "typing" [ "Tuple" ]. +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_muir_glacier_blocks_imports : - AreImported globals "ethereum.muir_glacier.blocks" [ "Log" ]. +Axiom ethereum_muir_glacier_blocks_imports_Log : + IsImported globals "ethereum.muir_glacier.blocks" "Log". -Axiom ethereum_muir_glacier_fork_types_imports : - AreImported globals "ethereum.muir_glacier.fork_types" [ "Bloom" ]. +Axiom ethereum_muir_glacier_fork_types_imports_Bloom : + IsImported globals "ethereum.muir_glacier.fork_types" "Bloom". Definition add_to_bloom : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -53,20 +53,23 @@ Definition add_to_bloom : Value.t -> Value.t -> M := bloom_entry : An entry which is to be added to bloom filter. " in - let hash := + let _ := M.assign_local (| + "hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "bloom_entry" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "idx" |), make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ], ltac:(M.monadic ( - let bit_to_set := + let _ := M.assign_local (| + "bit_to_set" , BinOp.bit_and (| M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), @@ -84,18 +87,24 @@ Definition add_to_bloom : Value.t -> Value.t -> M := make_dict [] |), Constant.int 2047 - |) in - let bit_index := + |) + |) in + let _ := M.assign_local (| + "bit_index" , BinOp.sub (| Constant.int 2047, M.get_name (| globals, "bit_to_set" |) - |) in - let byte_index := + |) + |) in + let _ := M.assign_local (| + "byte_index" , BinOp.floor_div (| M.get_name (| globals, "bit_index" |), Constant.int 8 - |) in - let bit_value := + |) + |) in + let _ := M.assign_local (| + "bit_value" , BinOp.l_shift (| Constant.int 1, BinOp.sub (| @@ -105,7 +114,8 @@ Definition add_to_bloom : Value.t -> Value.t -> M := Constant.int 8 |) |) - |) in + |) + |) in let _ := M.assign (| M.get_subscript (| M.get_name (| globals, "bloom" |), diff --git a/CoqOfPython/ethereum/muir_glacier/fork.v b/CoqOfPython/ethereum/muir_glacier/fork.v index c7af4a6..7b80d97 100644 --- a/CoqOfPython/ethereum/muir_glacier/fork.v +++ b/CoqOfPython/ethereum/muir_glacier/fork.v @@ -17,62 +17,120 @@ Introduction Entry point for the Ethereum specification. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Bytes0" ]. - -Axiom ethereum_crypto_elliptic_curve_imports : - AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. - -Axiom ethereum_ethash_imports : - AreImported globals "ethereum.ethash" [ "dataset_size"; "generate_cache"; "hashimoto_light" ]. - -Axiom ethereum_exceptions_imports : - AreImported globals "ethereum.exceptions" [ "InvalidBlock" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U64"; "U256"; "U256_CEIL_VALUE"; "Bytes"; "Uint" ]. - -Axiom ethereum_muir_glacier_imports : - AreImported globals "ethereum.muir_glacier" [ "vm" ]. - -Axiom ethereum_muir_glacier_blocks_imports : - AreImported globals "ethereum.muir_glacier.blocks" [ "Block"; "Header"; "Log"; "Receipt" ]. - -Axiom ethereum_muir_glacier_bloom_imports : - AreImported globals "ethereum.muir_glacier.bloom" [ "logs_bloom" ]. - -Axiom ethereum_muir_glacier_fork_types_imports : - AreImported globals "ethereum.muir_glacier.fork_types" [ "Address"; "Bloom"; "Root" ]. - -Axiom ethereum_muir_glacier_state_imports : - AreImported globals "ethereum.muir_glacier.state" [ "State"; "account_exists_and_is_empty"; "create_ether"; "destroy_account"; "get_account"; "increment_nonce"; "set_account_balance"; "state_root" ]. - -Axiom ethereum_muir_glacier_transactions_imports : - AreImported globals "ethereum.muir_glacier.transactions" [ "TX_BASE_COST"; "TX_CREATE_COST"; "TX_DATA_COST_PER_NON_ZERO"; "TX_DATA_COST_PER_ZERO"; "Transaction" ]. - -Axiom ethereum_muir_glacier_trie_imports : - AreImported globals "ethereum.muir_glacier.trie" [ "Trie"; "root"; "trie_set" ]. - -Axiom ethereum_muir_glacier_utils_message_imports : - AreImported globals "ethereum.muir_glacier.utils.message" [ "prepare_message" ]. - -Axiom ethereum_muir_glacier_vm_interpreter_imports : - AreImported globals "ethereum.muir_glacier.vm.interpreter" [ "process_message_call" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". + +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". + +Axiom ethereum_crypto_elliptic_curve_imports_SECP256K1N : + IsImported globals "ethereum.crypto.elliptic_curve" "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_imports_secp256k1_recover : + IsImported globals "ethereum.crypto.elliptic_curve" "secp256k1_recover". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". + +Axiom ethereum_ethash_imports_dataset_size : + IsImported globals "ethereum.ethash" "dataset_size". +Axiom ethereum_ethash_imports_generate_cache : + IsImported globals "ethereum.ethash" "generate_cache". +Axiom ethereum_ethash_imports_hashimoto_light : + IsImported globals "ethereum.ethash" "hashimoto_light". + +Axiom ethereum_exceptions_imports_InvalidBlock : + IsImported globals "ethereum.exceptions" "InvalidBlock". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U64 : + IsImported globals "ethereum.base_types" "U64". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_U256_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U256_CEIL_VALUE". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_muir_glacier_imports_vm : + IsImported globals "ethereum.muir_glacier" "vm". + +Axiom ethereum_muir_glacier_blocks_imports_Block : + IsImported globals "ethereum.muir_glacier.blocks" "Block". +Axiom ethereum_muir_glacier_blocks_imports_Header : + IsImported globals "ethereum.muir_glacier.blocks" "Header". +Axiom ethereum_muir_glacier_blocks_imports_Log : + IsImported globals "ethereum.muir_glacier.blocks" "Log". +Axiom ethereum_muir_glacier_blocks_imports_Receipt : + IsImported globals "ethereum.muir_glacier.blocks" "Receipt". + +Axiom ethereum_muir_glacier_bloom_imports_logs_bloom : + IsImported globals "ethereum.muir_glacier.bloom" "logs_bloom". + +Axiom ethereum_muir_glacier_fork_types_imports_Address : + IsImported globals "ethereum.muir_glacier.fork_types" "Address". +Axiom ethereum_muir_glacier_fork_types_imports_Bloom : + IsImported globals "ethereum.muir_glacier.fork_types" "Bloom". +Axiom ethereum_muir_glacier_fork_types_imports_Root : + IsImported globals "ethereum.muir_glacier.fork_types" "Root". + +Axiom ethereum_muir_glacier_state_imports_State : + IsImported globals "ethereum.muir_glacier.state" "State". +Axiom ethereum_muir_glacier_state_imports_account_exists_and_is_empty : + IsImported globals "ethereum.muir_glacier.state" "account_exists_and_is_empty". +Axiom ethereum_muir_glacier_state_imports_create_ether : + IsImported globals "ethereum.muir_glacier.state" "create_ether". +Axiom ethereum_muir_glacier_state_imports_destroy_account : + IsImported globals "ethereum.muir_glacier.state" "destroy_account". +Axiom ethereum_muir_glacier_state_imports_get_account : + IsImported globals "ethereum.muir_glacier.state" "get_account". +Axiom ethereum_muir_glacier_state_imports_increment_nonce : + IsImported globals "ethereum.muir_glacier.state" "increment_nonce". +Axiom ethereum_muir_glacier_state_imports_set_account_balance : + IsImported globals "ethereum.muir_glacier.state" "set_account_balance". +Axiom ethereum_muir_glacier_state_imports_state_root : + IsImported globals "ethereum.muir_glacier.state" "state_root". + +Axiom ethereum_muir_glacier_transactions_imports_TX_BASE_COST : + IsImported globals "ethereum.muir_glacier.transactions" "TX_BASE_COST". +Axiom ethereum_muir_glacier_transactions_imports_TX_CREATE_COST : + IsImported globals "ethereum.muir_glacier.transactions" "TX_CREATE_COST". +Axiom ethereum_muir_glacier_transactions_imports_TX_DATA_COST_PER_NON_ZERO : + IsImported globals "ethereum.muir_glacier.transactions" "TX_DATA_COST_PER_NON_ZERO". +Axiom ethereum_muir_glacier_transactions_imports_TX_DATA_COST_PER_ZERO : + IsImported globals "ethereum.muir_glacier.transactions" "TX_DATA_COST_PER_ZERO". +Axiom ethereum_muir_glacier_transactions_imports_Transaction : + IsImported globals "ethereum.muir_glacier.transactions" "Transaction". + +Axiom ethereum_muir_glacier_trie_imports_Trie : + IsImported globals "ethereum.muir_glacier.trie" "Trie". +Axiom ethereum_muir_glacier_trie_imports_root : + IsImported globals "ethereum.muir_glacier.trie" "root". +Axiom ethereum_muir_glacier_trie_imports_trie_set : + IsImported globals "ethereum.muir_glacier.trie" "trie_set". + +Axiom ethereum_muir_glacier_utils_message_imports_prepare_message : + IsImported globals "ethereum.muir_glacier.utils.message" "prepare_message". + +Axiom ethereum_muir_glacier_vm_interpreter_imports_process_message_call : + IsImported globals "ethereum.muir_glacier.vm.interpreter" "process_message_call". Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -190,13 +248,15 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := recent_block_hashes : `List[Hash32]` Hashes of the recent 256 blocks in order of increasing block number. " in - let recent_blocks := + let _ := M.assign_local (| + "recent_blocks" , M.slice (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |), Constant.None_, Constant.None_ - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -220,15 +280,19 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let recent_block_hashes := - make_list [] in + let _ := M.assign_local (| + "recent_block_hashes" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "block" |), M.get_name (| globals, "recent_blocks" |), ltac:(M.monadic ( - let prev_block_hash := - M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in + let _ := M.assign_local (| + "prev_block_hash" , + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), make_list [ @@ -242,7 +306,8 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let most_recent_block_hash := + let _ := M.assign_local (| + "most_recent_block_hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -258,7 +323,8 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), make_list [ @@ -295,11 +361,13 @@ Definition state_transition : Value.t -> Value.t -> M := block : Block to apply to `chain`. " in - let parent_header := + let _ := M.assign_local (| + "parent_header" , M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 1 |) - |), "header" |) in + |), "header" |) + |) in let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ @@ -317,7 +385,8 @@ Definition state_transition : Value.t -> Value.t -> M := ], make_dict [] |) in - let apply_body_output := + let _ := M.assign_local (| + "apply_body_output" , M.call (| M.get_name (| globals, "apply_body" |), make_list [ @@ -339,7 +408,8 @@ Definition state_transition : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "chain" |), "chain_id" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -453,11 +523,13 @@ Definition validate_header : Value.t -> Value.t -> M := parent_header : Parent Header of the header to check for correctness " in - let parent_has_ommers := + let _ := M.assign_local (| + "parent_has_ommers" , Compare.not_eq (| M.get_field (| M.get_name (| globals, "parent_header" |), "ommers_hash" |), M.get_name (| globals, "EMPTY_OMMER_HASH" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -515,7 +587,8 @@ Definition validate_header : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_difficulty := + let _ := M.assign_local (| + "block_difficulty" , M.call (| M.get_name (| globals, "calculate_block_difficulty" |), make_list [ @@ -526,7 +599,8 @@ Definition validate_header : Value.t -> Value.t -> M := M.get_name (| globals, "parent_has_ommers" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -538,7 +612,8 @@ Definition validate_header : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_parent_hash := + let _ := M.assign_local (| + "block_parent_hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -551,7 +626,8 @@ Definition validate_header : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -597,7 +673,8 @@ Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := hash : `Hash32` The PoW valid rlp hash of the passed in header. " in - let header_data_without_pow_artefacts := + let _ := M.assign_local (| + "header_data_without_pow_artefacts" , make_list [ M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |); M.get_field (| M.get_name (| globals, "header" |), "ommers_hash" |); @@ -612,7 +689,8 @@ Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "header" |), "gas_used" |); M.get_field (| M.get_name (| globals, "header" |), "timestamp" |); M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) - ] in + ] + |) in let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), @@ -641,22 +719,26 @@ Definition validate_proof_of_work : Value.t -> Value.t -> M := header : Header of interest. " in - let header_hash := + let _ := M.assign_local (| + "header_hash" , M.call (| M.get_name (| globals, "generate_header_hash_for_pow" |), make_list [ M.get_name (| globals, "header" |) ], make_dict [] - |) in - let cache := + |) + |) in + let _ := M.assign_local (| + "cache" , M.call (| M.get_name (| globals, "generate_cache" |), make_list [ M.get_field (| M.get_name (| globals, "header" |), "number" |) ], make_dict [] - |) in + |) + |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "mix_digest" |); M.get_name (| globals, "result" |) ], M.call (| @@ -745,7 +827,8 @@ Definition check_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_address := + let _ := M.assign_local (| + "sender_address" , M.call (| M.get_name (| globals, "recover_sender" |), make_list [ @@ -753,7 +836,8 @@ Definition check_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "tx" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "sender_address" |) |) in @@ -782,12 +866,14 @@ Definition make_receipt : Value.t -> Value.t -> M := receipt : The receipt for the transaction. " in - let receipt := + let _ := M.assign_local (| + "receipt" , M.call (| M.get_name (| globals, "Receipt" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "receipt" |) |) in @@ -846,8 +932,10 @@ Definition apply_body : Value.t -> Value.t -> M := apply_body_output : `ApplyBodyOutput` Output of applying the block body to the state. " in - let gas_available := - M.get_name (| globals, "block_gas_limit" |) in + let _ := M.assign_local (| + "gas_available" , + M.get_name (| globals, "block_gas_limit" |) + |) in (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) @@ -883,7 +971,8 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_address := + let _ := M.assign_local (| + "sender_address" , M.call (| M.get_name (| globals, "check_transaction" |), make_list [ @@ -892,13 +981,16 @@ Definition apply_body : Value.t -> Value.t -> M := M.get_name (| globals, "chain_id" |) ], make_dict [] - |) in - let env := + |) + |) in + let _ := M.assign_local (| + "env" , M.call (| M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |); M.get_name (| globals, "error" |) ], M.call (| @@ -910,10 +1002,13 @@ Definition apply_body : Value.t -> Value.t -> M := make_dict [] |) |) in - let gas_available := BinOp.sub + let _ := M.assign_op_local (| + BinOp.sub, + "gas_available", M.get_name (| globals, "gas_used" |) - M.get_name (| globals, "gas_used" |) in - let receipt := + |) in + let _ := M.assign_local (| + "receipt" , M.call (| M.get_name (| globals, "make_receipt" |), make_list [ @@ -926,7 +1021,8 @@ Definition apply_body : Value.t -> Value.t -> M := M.get_name (| globals, "logs" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ @@ -948,9 +1044,11 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_logs := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "block_logs", M.get_name (| globals, "logs" |) - M.get_name (| globals, "logs" |) in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -967,19 +1065,23 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_gas_used := + let _ := M.assign_local (| + "block_gas_used" , BinOp.sub (| M.get_name (| globals, "block_gas_limit" |), M.get_name (| globals, "gas_available" |) - |) in - let block_logs_bloom := + |) + |) in + let _ := M.assign_local (| + "block_logs_bloom" , M.call (| M.get_name (| globals, "logs_bloom" |), make_list [ M.get_name (| globals, "block_logs" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ApplyBodyOutput" |), @@ -1037,14 +1139,16 @@ Definition validate_ommers : Value.t -> Value.t -> M := chain : History and current state. " in - let block_hash := + let _ := M.assign_local (| + "block_hash" , M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), make_list [ M.get_name (| globals, "block_header" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1109,7 +1213,8 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_parent_header := + let _ := M.assign_local (| + "ommer_parent_header" , M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), BinOp.sub (| @@ -1119,7 +1224,8 @@ Definition validate_ommers : Value.t -> Value.t -> M := |) |), Constant.int 1 |) - |), "header" |) in + |), "header" |) + |) in let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ @@ -1151,8 +1257,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommers_hashes := - Constant.str "(* At expr: unsupported node type: ListComp *)" in + let _ := M.assign_local (| + "ommers_hashes" , + Constant.str "(* At expr: unsupported node type: ListComp *)" + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1182,7 +1290,8 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let recent_canonical_blocks := + let _ := M.assign_local (| + "recent_canonical_blocks" , M.slice (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| BinOp.add (| @@ -1191,23 +1300,28 @@ Definition validate_ommers : Value.t -> Value.t -> M := |) |), Constant.None_, Constant.None_ - |) in - let recent_canonical_block_hashes := - Constant.str "(* At expr: unsupported node type: SetComp *)" in + |) + |) in + let _ := M.assign_local (| + "recent_canonical_block_hashes" , + Constant.str "(* At expr: unsupported node type: SetComp *)" + |) in (* At stmt: unsupported node type: AnnAssign *) let _ := M.for_ (| M.get_name (| globals, "block" |), M.get_name (| globals, "recent_canonical_blocks" |), ltac:(M.monadic ( - let recent_ommers_hashes := + let _ := M.assign_local (| + "recent_ommers_hashes" , M.call (| M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), make_list [ Constant.str "(* At expr: unsupported node type: SetComp *)" ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -1225,11 +1339,13 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let ommer_hash := + let _ := M.assign_local (| + "ommer_hash" , M.get_subscript (| M.get_name (| globals, "ommers_hashes" |), M.get_name (| globals, "ommer_index" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1263,11 +1379,13 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_age := + let _ := M.assign_local (| + "ommer_age" , BinOp.sub (| M.get_field (| M.get_name (| globals, "block_header" |), "number" |), M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1345,7 +1463,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := ommers : List of ommers mentioned in the current block. " in - let miner_reward := + let _ := M.assign_local (| + "miner_reward" , BinOp.add (| M.get_name (| globals, "BLOCK_REWARD" |), BinOp.mult (| @@ -1361,7 +1480,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := Constant.int 32 |) |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "create_ether" |), make_list [ @@ -1376,7 +1496,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := M.get_name (| globals, "ommer" |), M.get_name (| globals, "ommers" |), ltac:(M.monadic ( - let ommer_age := + let _ := M.assign_local (| + "ommer_age" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -1386,8 +1507,10 @@ Definition pay_rewards : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let ommer_miner_reward := + |) + |) in + let _ := M.assign_local (| + "ommer_miner_reward" , BinOp.floor_div (| BinOp.mult (| BinOp.sub (| @@ -1397,7 +1520,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := M.get_name (| globals, "BLOCK_REWARD" |) |), Constant.int 8 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "create_ether" |), make_list [ @@ -1458,9 +1582,12 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender := - M.get_field (| M.get_name (| globals, "env" |), "origin" |) in - let sender_account := + let _ := M.assign_local (| + "sender" , + M.get_field (| M.get_name (| globals, "env" |), "origin" |) + |) in + let _ := M.assign_local (| + "sender_account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1468,12 +1595,15 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "sender" |) ], make_dict [] - |) in - let gas_fee := + |) + |) in + let _ := M.assign_local (| + "gas_fee" , BinOp.mult (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1514,7 +1644,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let gas := + let _ := M.assign_local (| + "gas" , BinOp.sub (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.call (| @@ -1524,7 +1655,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "increment_nonce" |), make_list [ @@ -1533,11 +1665,13 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_balance_after_gas_fee := + let _ := M.assign_local (| + "sender_balance_after_gas_fee" , BinOp.sub (| M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), M.get_name (| globals, "gas_fee" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -1547,7 +1681,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let message := + let _ := M.assign_local (| + "message" , M.call (| M.get_name (| globals, "prepare_message" |), make_list [ @@ -1559,8 +1694,10 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in - let output := + |) + |) in + let _ := M.assign_local (| + "output" , M.call (| M.get_name (| globals, "process_message_call" |), make_list [ @@ -1568,13 +1705,17 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in - let gas_used := + |) + |) in + let _ := M.assign_local (| + "gas_used" , BinOp.sub (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_field (| M.get_name (| globals, "output" |), "gas_left" |) - |) in - let gas_refund := + |) + |) in + let _ := M.assign_local (| + "gas_refund" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -1585,16 +1726,20 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "output" |), "refund_counter" |) ], make_dict [] - |) in - let gas_refund_amount := + |) + |) in + let _ := M.assign_local (| + "gas_refund_amount" , BinOp.mult (| BinOp.add (| M.get_field (| M.get_name (| globals, "output" |), "gas_left" |), M.get_name (| globals, "gas_refund" |) |), M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) - |) in - let transaction_fee := + |) + |) in + let _ := M.assign_local (| + "transaction_fee" , BinOp.mult (| BinOp.sub (| BinOp.sub (| @@ -1604,13 +1749,17 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "gas_refund" |) |), M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) - |) in - let total_gas_used := + |) + |) in + let _ := M.assign_local (| + "total_gas_used" , BinOp.sub (| M.get_name (| globals, "gas_used" |), M.get_name (| globals, "gas_refund" |) - |) in - let sender_balance_after_refund := + |) + |) in + let _ := M.assign_local (| + "sender_balance_after_refund" , BinOp.add (| M.get_field (| M.call (| M.get_name (| globals, "get_account" |), @@ -1621,7 +1770,8 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |), "balance" |), M.get_name (| globals, "gas_refund_amount" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -1631,7 +1781,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let coinbase_balance_after_mining_fee := + let _ := M.assign_local (| + "coinbase_balance_after_mining_fee" , BinOp.add (| M.get_field (| M.call (| M.get_name (| globals, "get_account" |), @@ -1642,7 +1793,8 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |), "balance" |), M.get_name (| globals, "transaction_fee" |) - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1833,8 +1985,10 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := verified : `ethereum.base_types.Uint` The intrinsic cost of the transaction. " in - let data_cost := - Constant.int 0 in + let _ := M.assign_local (| + "data_cost" , + Constant.int 0 + |) in let _ := M.for_ (| M.get_name (| globals, "byte" |), @@ -1849,15 +2003,19 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let data_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "data_cost", M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let data_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "data_cost", M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -1881,13 +2039,17 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let create_cost := - M.get_name (| globals, "TX_CREATE_COST" |) in + let _ := M.assign_local (| + "create_cost" , + M.get_name (| globals, "TX_CREATE_COST" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let create_cost := - Constant.int 0 in + let _ := M.assign_local (| + "create_cost" , + Constant.int 0 + |) in M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1993,7 +2155,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let public_key := + let _ := M.assign_local (| + "public_key" , M.call (| M.get_name (| globals, "secp256k1_recover" |), make_list [ @@ -2012,7 +2175,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -2047,7 +2211,8 @@ Definition recover_sender : Value.t -> Value.t -> M := ], make_dict [] |) in - let public_key := + let _ := M.assign_local (| + "public_key" , M.call (| M.get_name (| globals, "secp256k1_recover" |), make_list [ @@ -2073,7 +2238,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -2259,11 +2425,13 @@ Definition check_gas_limit : Value.t -> Value.t -> M := check : `bool` True if gas limit constraints are satisfied, False otherwise. " in - let max_adjustment_delta := + let _ := M.assign_local (| + "max_adjustment_delta" , BinOp.floor_div (| M.get_name (| globals, "parent_gas_limit" |), M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -2367,7 +2535,8 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := difficulty : `ethereum.base_types.Uint` Computed difficulty for a block. " in - let offset := + let _ := M.assign_local (| + "offset" , BinOp.mult (| BinOp.floor_div (| M.call (| @@ -2411,8 +2580,10 @@ Constant.int 1 ], make_dict [] |) - |) in - let difficulty := + |) + |) in + let _ := M.assign_local (| + "difficulty" , BinOp.add (| M.call (| M.get_name (| globals, "int" |), @@ -2422,8 +2593,10 @@ Constant.int 1 make_dict [] |), M.get_name (| globals, "offset" |) - |) in - let num_bomb_periods := + |) + |) in + let _ := M.assign_local (| + "num_bomb_periods" , BinOp.sub (| BinOp.floor_div (| BinOp.sub (| @@ -2439,7 +2612,8 @@ Constant.int 1 Constant.int 100000 |), Constant.int 2 - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -2449,15 +2623,14 @@ Constant.int 1 |), (* then *) ltac:(M.monadic ( - let difficulty := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "difficulty", BinOp.pow (| Constant.int 2, M.get_name (| globals, "num_bomb_periods" |) |) - BinOp.pow (| - Constant.int 2, - M.get_name (| globals, "num_bomb_periods" |) - |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/muir_glacier/fork_types.v b/CoqOfPython/ethereum/muir_glacier/fork_types.v index 775b1dd..100f313 100644 --- a/CoqOfPython/ethereum/muir_glacier/fork_types.v +++ b/CoqOfPython/ethereum/muir_glacier/fork_types.v @@ -17,17 +17,29 @@ Introduction Types re-used throughout the specification, which are specific to Ethereum. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes20"; "Bytes256"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes20 : + IsImported globals "ethereum.base_types" "Bytes20". +Axiom ethereum_base_types_imports_Bytes256 : + IsImported globals "ethereum.base_types" "Bytes256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) diff --git a/CoqOfPython/ethereum/muir_glacier/state.v b/CoqOfPython/ethereum/muir_glacier/state.v index d7321e4..28df1ec 100644 --- a/CoqOfPython/ethereum/muir_glacier/state.v +++ b/CoqOfPython/ethereum/muir_glacier/state.v @@ -22,23 +22,57 @@ There is a distinction between an account that does not exist and `EMPTY_ACCOUNT`. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass"; "field" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict"; "List"; "Optional"; "Set"; "Tuple" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "modify" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_muir_glacier_fork_types_imports : - AreImported globals "ethereum.muir_glacier.fork_types" [ "EMPTY_ACCOUNT"; "Account"; "Address"; "Root" ]. - -Axiom ethereum_muir_glacier_trie_imports : - AreImported globals "ethereum.muir_glacier.trie" [ "EMPTY_TRIE_ROOT"; "Trie"; "copy_trie"; "root"; "trie_get"; "trie_set" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". +Axiom dataclasses_imports_field : + IsImported globals "dataclasses" "field". + +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_modify : + IsImported globals "ethereum.base_types" "modify". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_muir_glacier_fork_types_imports_EMPTY_ACCOUNT : + IsImported globals "ethereum.muir_glacier.fork_types" "EMPTY_ACCOUNT". +Axiom ethereum_muir_glacier_fork_types_imports_Account : + IsImported globals "ethereum.muir_glacier.fork_types" "Account". +Axiom ethereum_muir_glacier_fork_types_imports_Address : + IsImported globals "ethereum.muir_glacier.fork_types" "Address". +Axiom ethereum_muir_glacier_fork_types_imports_Root : + IsImported globals "ethereum.muir_glacier.fork_types" "Root". + +Axiom ethereum_muir_glacier_trie_imports_EMPTY_TRIE_ROOT : + IsImported globals "ethereum.muir_glacier.trie" "EMPTY_TRIE_ROOT". +Axiom ethereum_muir_glacier_trie_imports_Trie : + IsImported globals "ethereum.muir_glacier.trie" "Trie". +Axiom ethereum_muir_glacier_trie_imports_copy_trie : + IsImported globals "ethereum.muir_glacier.trie" "copy_trie". +Axiom ethereum_muir_glacier_trie_imports_root : + IsImported globals "ethereum.muir_glacier.trie" "root". +Axiom ethereum_muir_glacier_trie_imports_trie_get : + IsImported globals "ethereum.muir_glacier.trie" "trie_get". +Axiom ethereum_muir_glacier_trie_imports_trie_set : + IsImported globals "ethereum.muir_glacier.trie" "trie_set". Definition State : Value.t := builtins.make_klass @@ -186,7 +220,8 @@ Definition get_account : Value.t -> Value.t -> M := account : `Account` Account at address. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account_optional" |), make_list [ @@ -194,7 +229,8 @@ Definition get_account : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -240,7 +276,8 @@ Definition get_account_optional : Value.t -> Value.t -> M := account : `Account` Account at address. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "trie_get" |), make_list [ @@ -248,7 +285,8 @@ Definition get_account_optional : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "account" |) |) in @@ -399,14 +437,16 @@ Definition get_storage : Value.t -> Value.t -> M := value : `U256` Value at the key. " in - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -430,7 +470,8 @@ Definition get_storage : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "trie_get" |), make_list [ @@ -438,7 +479,8 @@ Definition get_storage : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -481,14 +523,16 @@ Definition set_storage : Value.t -> Value.t -> M := |), Constant.None_ |) |) in - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -498,12 +542,14 @@ Definition set_storage : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_name (| globals, "Trie" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), @@ -530,7 +576,7 @@ Definition set_storage : Value.t -> Value.t -> M := M.if_then_else (| Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), - {} + Constant.str "(* At expr: unsupported node type: Dict *)" |), (* then *) ltac:(M.monadic ( @@ -676,7 +722,8 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := True if if an account has non zero nonce or non empty code, False otherwise. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -684,7 +731,8 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| BoolOp.or (| Compare.not_eq (| @@ -726,7 +774,8 @@ Definition is_account_empty : Value.t -> Value.t -> M := True if if an account has zero nonce, empty code and zero balance, False otherwise. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -734,7 +783,8 @@ Definition is_account_empty : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| BoolOp.and (| Compare.eq (| @@ -785,7 +835,8 @@ Definition account_exists_and_is_empty : Value.t -> Value.t -> M := True if an account exists and has zero nonce, empty code and zero balance, False otherwise. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account_optional" |), make_list [ @@ -793,7 +844,8 @@ Definition account_exists_and_is_empty : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| BoolOp.and (| Compare.is_not (| @@ -850,7 +902,8 @@ Definition is_account_alive : Value.t -> Value.t -> M := is_alive : `bool` True if the account is alive. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account_optional" |), make_list [ @@ -858,7 +911,8 @@ Definition is_account_alive : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1166,14 +1220,16 @@ Definition get_storage_original : Value.t -> Value.t -> M := Constant.int 0 |) |) in - let original_account_trie := + let _ := M.assign_local (| + "original_account_trie" , M.call (| M.get_field (| M.get_name (| globals, "original_trie" |), "get" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1183,18 +1239,21 @@ Definition get_storage_original : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let original_value := + let _ := M.assign_local (| + "original_value" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let original_value := + let _ := M.assign_local (| + "original_value" , M.call (| M.get_name (| globals, "trie_get" |), make_list [ @@ -1202,7 +1261,8 @@ Definition get_storage_original : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.assert (| M.call (| diff --git a/CoqOfPython/ethereum/muir_glacier/transactions.v b/CoqOfPython/ethereum/muir_glacier/transactions.v index 0db6afa..0443ebc 100644 --- a/CoqOfPython/ethereum/muir_glacier/transactions.v +++ b/CoqOfPython/ethereum/muir_glacier/transactions.v @@ -9,17 +9,25 @@ submitted to be executed. If Ethereum is viewed as a state machine, transactions are the events that move between states. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Union" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_muir_glacier_fork_types_imports : - AreImported globals "ethereum.muir_glacier.fork_types" [ "Address" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_Union : + IsImported globals "typing" "Union". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_muir_glacier_fork_types_imports_Address : + IsImported globals "ethereum.muir_glacier.fork_types" "Address". Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( Constant.int 21000 diff --git a/CoqOfPython/ethereum/muir_glacier/trie.v b/CoqOfPython/ethereum/muir_glacier/trie.v index b8c79e6..5e9b0cd 100644 --- a/CoqOfPython/ethereum/muir_glacier/trie.v +++ b/CoqOfPython/ethereum/muir_glacier/trie.v @@ -20,38 +20,72 @@ The state trie is the structure responsible for storing (* At top_level_stmt: unsupported node type: Import *) -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass"; "field" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict"; "Generic"; "List"; "Mapping"; "MutableMapping"; "Optional"; "Sequence"; "TypeVar"; "Union"; "cast" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. - -Axiom ethereum_istanbul_imports : - AreImported globals "ethereum.istanbul" [ "trie" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_utils_hexadecimal_imports : - AreImported globals "ethereum.utils.hexadecimal" [ "hex_to_bytes" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_muir_glacier_blocks_imports : - AreImported globals "ethereum.muir_glacier.blocks" [ "Receipt" ]. - -Axiom ethereum_muir_glacier_fork_types_imports : - AreImported globals "ethereum.muir_glacier.fork_types" [ "Account"; "Address"; "Root"; "encode_account" ]. - -Axiom ethereum_muir_glacier_transactions_imports : - AreImported globals "ethereum.muir_glacier.transactions" [ "Transaction" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". +Axiom dataclasses_imports_field : + IsImported globals "dataclasses" "field". + +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". +Axiom typing_imports_Generic : + IsImported globals "typing" "Generic". +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Mapping : + IsImported globals "typing" "Mapping". +Axiom typing_imports_MutableMapping : + IsImported globals "typing" "MutableMapping". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Sequence : + IsImported globals "typing" "Sequence". +Axiom typing_imports_TypeVar : + IsImported globals "typing" "TypeVar". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". +Axiom typing_imports_cast : + IsImported globals "typing" "cast". + +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". + +Axiom ethereum_istanbul_imports_trie : + IsImported globals "ethereum.istanbul" "trie". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_utils_hexadecimal_imports_hex_to_bytes : + IsImported globals "ethereum.utils.hexadecimal" "hex_to_bytes". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_muir_glacier_blocks_imports_Receipt : + IsImported globals "ethereum.muir_glacier.blocks" "Receipt". + +Axiom ethereum_muir_glacier_fork_types_imports_Account : + IsImported globals "ethereum.muir_glacier.fork_types" "Account". +Axiom ethereum_muir_glacier_fork_types_imports_Address : + IsImported globals "ethereum.muir_glacier.fork_types" "Address". +Axiom ethereum_muir_glacier_fork_types_imports_Root : + IsImported globals "ethereum.muir_glacier.fork_types" "Root". +Axiom ethereum_muir_glacier_fork_types_imports_encode_account : + IsImported globals "ethereum.muir_glacier.fork_types" "encode_account". + +Axiom ethereum_muir_glacier_transactions_imports_Transaction : + IsImported globals "ethereum.muir_glacier.transactions" "Transaction". Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -161,7 +195,7 @@ Definition encode_internal_node : Value.t -> Value.t -> M := when serialized. This function also accepts `None`, representing the absence of a node, - which is encoded to `b""""""`. + which is encoded to `b""""`. Parameters ---------- @@ -183,8 +217,10 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := - Constant.bytes "" in + let _ := M.assign_local (| + "unencoded" , + Constant.bytes "" + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -201,7 +237,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := + let _ := M.assign_local (| + "unencoded" , make_tuple [ M.call (| M.get_name (| globals, "nibble_list_to_compact" |), make_list [ @@ -209,7 +246,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := Constant.bool true ], make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in + |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -226,7 +264,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := + let _ := M.assign_local (| + "unencoded" , make_tuple [ M.call (| M.get_name (| globals, "nibble_list_to_compact" |), make_list [ @@ -234,7 +273,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := Constant.bool false ], make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in + |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -251,13 +291,15 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := + let _ := M.assign_local (| + "unencoded" , BinOp.add (| M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), make_list [ M.get_field (| M.get_name (| globals, "node" |), "value" |) ] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -276,14 +318,16 @@ Definition encode_internal_node : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - let encoded := + let _ := M.assign_local (| + "encoded" , M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), make_list [ M.get_name (| globals, "unencoded" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -675,12 +719,14 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := compressed : `bytearray` Compact byte array. " in - let compact := + let _ := M.assign_local (| + "compact" , M.call (| M.get_name (| globals, "bytearray" |), make_list [], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -860,7 +906,8 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := nibble_list : `Bytes` The `Bytes` in nibble-list format. " in - let nibble_list := + let _ := M.assign_local (| + "nibble_list" , M.call (| M.get_name (| globals, "bytearray" |), make_list [ @@ -876,7 +923,8 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ], @@ -984,15 +1032,18 @@ Definition _prepare_trie : Value.t -> Value.t -> M := M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "Address" |), make_list [ M.get_name (| globals, "preimage" |) ], make_dict [] - |) in - let encoded_value := + |) + |) in + let _ := M.assign_local (| + "encoded_value" , M.call (| M.get_name (| globals, "encode_node" |), make_list [ @@ -1006,18 +1057,21 @@ Definition _prepare_trie : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let encoded_value := + let _ := M.assign_local (| + "encoded_value" , M.call (| M.get_name (| globals, "encode_node" |), make_list [ M.get_name (| globals, "value" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -1038,19 +1092,23 @@ Definition _prepare_trie : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "trie" |), "secured" |), (* then *) ltac:(M.monadic ( - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "preimage" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let key := - M.get_name (| globals, "preimage" |) in + let _ := M.assign_local (| + "key" , + M.get_name (| globals, "preimage" |) + |) in M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -1097,7 +1155,8 @@ Definition root : Value.t -> Value.t -> M := root : `.fork_types.Root` MPT root of the underlying key-value pairs. " in - let obj := + let _ := M.assign_local (| + "obj" , M.call (| M.get_name (| globals, "_prepare_trie" |), make_list [ @@ -1105,8 +1164,10 @@ Definition root : Value.t -> Value.t -> M := M.get_name (| globals, "get_storage_root" |) ], make_dict [] - |) in - let root_node := + |) + |) in + let _ := M.assign_local (| + "root_node" , M.call (| M.get_name (| globals, "encode_internal_node" |), make_list [ @@ -1126,7 +1187,8 @@ Definition root : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1231,7 +1293,8 @@ Definition patricialize : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let arbitrary_key := + let _ := M.assign_local (| + "arbitrary_key" , M.call (| M.get_name (| globals, "next" |), make_list [ @@ -1244,7 +1307,8 @@ Definition patricialize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1260,7 +1324,8 @@ Definition patricialize : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let leaf := + let _ := M.assign_local (| + "leaf" , M.call (| M.get_name (| globals, "LeafNode" |), make_list [ @@ -1276,7 +1341,8 @@ Definition patricialize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "leaf" |) |) in @@ -1285,27 +1351,32 @@ Definition patricialize : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let substring := + let _ := M.assign_local (| + "substring" , M.slice (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |), Constant.None_, Constant.None_ - |) in - let prefix_length := + |) + |) in + let _ := M.assign_local (| + "prefix_length" , M.call (| M.get_name (| globals, "len" |), make_list [ M.get_name (| globals, "substring" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "key" |), M.get_name (| globals, "obj" |), ltac:(M.monadic ( - let prefix_length := + let _ := M.assign_local (| + "prefix_length" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -1325,7 +1396,8 @@ Definition patricialize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1356,7 +1428,8 @@ Definition patricialize : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let prefix := + let _ := M.assign_local (| + "prefix" , M.slice (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |), @@ -1365,7 +1438,8 @@ Definition patricialize : Value.t -> Value.t -> M := M.get_name (| globals, "prefix_length" |) |), Constant.None_ - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ExtensionNode" |), @@ -1412,7 +1486,7 @@ Definition patricialize : Value.t -> Value.t -> M := let _ := M.call (| M.get_field (| M.get_name (| globals, "branches" |), "append" |), make_list [ - {} + Constant.str "(* At expr: unsupported node type: Dict *)" ], make_dict [] |) in @@ -1422,8 +1496,10 @@ Definition patricialize : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let value := - Constant.bytes "" in + let _ := M.assign_local (| + "value" , + Constant.bytes "" + |) in let _ := M.for_ (| M.get_name (| globals, "key" |), @@ -1466,11 +1542,13 @@ Definition patricialize : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let value := + let _ := M.assign_local (| + "value" , M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/muir_glacier/utils/address.v b/CoqOfPython/ethereum/muir_glacier/utils/address.v index d56d7fd..7c8c1f0 100644 --- a/CoqOfPython/ethereum/muir_glacier/utils/address.v +++ b/CoqOfPython/ethereum/muir_glacier/utils/address.v @@ -18,23 +18,27 @@ Address specific functions used in this muir_glacier version of specification. ". -Axiom typing_imports : - AreImported globals "typing" [ "Union" ]. +Axiom typing_imports_Union : + IsImported globals "typing" "Union". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes32"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_left_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "left_pad_zero_bytes". -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". -Axiom ethereum_muir_glacier_fork_types_imports : - AreImported globals "ethereum.muir_glacier.fork_types" [ "Address" ]. +Axiom ethereum_muir_glacier_fork_types_imports_Address : + IsImported globals "ethereum.muir_glacier.fork_types" "Address". Definition to_address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -91,7 +95,8 @@ Definition compute_contract_address : Value.t -> Value.t -> M := address: `Address` The computed address of the new account. " in - let computed_address := + let _ := M.assign_local (| + "computed_address" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -107,15 +112,19 @@ Definition compute_contract_address : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let canonical_address := + |) + |) in + let _ := M.assign_local (| + "canonical_address" , M.slice (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |), Constant.None_, Constant.None_ - |) in - let padded_address := + |) + |) in + let _ := M.assign_local (| + "padded_address" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -123,7 +132,8 @@ Definition compute_contract_address : Value.t -> Value.t -> M := Constant.int 20 ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Address" |), @@ -156,7 +166,8 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := address: `ethereum.muir_glacier.fork_types.Address` The computed address of the new account. " in - let preimage := + let _ := M.assign_local (| + "preimage" , BinOp.add (| BinOp.add (| BinOp.add (| @@ -172,23 +183,29 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in - let computed_address := + |) + |) in + let _ := M.assign_local (| + "computed_address" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "preimage" |) ], make_dict [] - |) in - let canonical_address := + |) + |) in + let _ := M.assign_local (| + "canonical_address" , M.slice (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |), Constant.None_, Constant.None_ - |) in - let padded_address := + |) + |) in + let _ := M.assign_local (| + "padded_address" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -196,7 +213,8 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := Constant.int 20 ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Address" |), diff --git a/CoqOfPython/ethereum/muir_glacier/utils/hexadecimal.v b/CoqOfPython/ethereum/muir_glacier/utils/hexadecimal.v index b4ee57d..56e0dcc 100644 --- a/CoqOfPython/ethereum/muir_glacier/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/muir_glacier/utils/hexadecimal.v @@ -18,11 +18,15 @@ Hexadecimal utility functions used in this specification, specific to Muir Glacier types. ". -Axiom ethereum_utils_hexadecimal_imports : - AreImported globals "ethereum.utils.hexadecimal" [ "remove_hex_prefix" ]. - -Axiom ethereum_muir_glacier_fork_types_imports : - AreImported globals "ethereum.muir_glacier.fork_types" [ "Address"; "Bloom"; "Root" ]. +Axiom ethereum_utils_hexadecimal_imports_remove_hex_prefix : + IsImported globals "ethereum.utils.hexadecimal" "remove_hex_prefix". + +Axiom ethereum_muir_glacier_fork_types_imports_Address : + IsImported globals "ethereum.muir_glacier.fork_types" "Address". +Axiom ethereum_muir_glacier_fork_types_imports_Bloom : + IsImported globals "ethereum.muir_glacier.fork_types" "Bloom". +Axiom ethereum_muir_glacier_fork_types_imports_Root : + IsImported globals "ethereum.muir_glacier.fork_types" "Root". Definition hex_to_root : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/muir_glacier/utils/message.v b/CoqOfPython/ethereum/muir_glacier/utils/message.v index dede9cd..e7c7551 100644 --- a/CoqOfPython/ethereum/muir_glacier/utils/message.v +++ b/CoqOfPython/ethereum/muir_glacier/utils/message.v @@ -18,23 +18,33 @@ Message specific functions used in this muir_glacier version of specification. ". -Axiom typing_imports : - AreImported globals "typing" [ "Optional"; "Union" ]. +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_muir_glacier_fork_types_imports : - AreImported globals "ethereum.muir_glacier.fork_types" [ "Address" ]. +Axiom ethereum_muir_glacier_fork_types_imports_Address : + IsImported globals "ethereum.muir_glacier.fork_types" "Address". -Axiom ethereum_muir_glacier_state_imports : - AreImported globals "ethereum.muir_glacier.state" [ "get_account" ]. +Axiom ethereum_muir_glacier_state_imports_get_account : + IsImported globals "ethereum.muir_glacier.state" "get_account". -Axiom ethereum_muir_glacier_vm_imports : - AreImported globals "ethereum.muir_glacier.vm" [ "Environment"; "Message" ]. +Axiom ethereum_muir_glacier_vm_imports_Environment : + IsImported globals "ethereum.muir_glacier.vm" "Environment". +Axiom ethereum_muir_glacier_vm_imports_Message : + IsImported globals "ethereum.muir_glacier.vm" "Message". -Axiom ethereum_muir_glacier_utils_address_imports : - AreImported globals "ethereum.muir_glacier.utils.address" [ "compute_contract_address" ]. +Axiom ethereum_muir_glacier_utils_address_imports_compute_contract_address : + IsImported globals "ethereum.muir_glacier.utils.address" "compute_contract_address". Definition prepare_message : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -84,7 +94,8 @@ Definition prepare_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let current_target := + let _ := M.assign_local (| + "current_target" , M.call (| M.get_name (| globals, "compute_contract_address" |), make_list [ @@ -108,17 +119,22 @@ Definition prepare_message : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let msg_data := + |) + |) in + let _ := M.assign_local (| + "msg_data" , M.call (| M.get_name (| globals, "Bytes" |), make_list [ Constant.bytes "" ], make_dict [] - |) in - let code := - M.get_name (| globals, "data" |) in + |) + |) in + let _ := M.assign_local (| + "code" , + M.get_name (| globals, "data" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -135,11 +151,16 @@ Definition prepare_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let current_target := - M.get_name (| globals, "target" |) in - let msg_data := - M.get_name (| globals, "data" |) in - let code := + let _ := M.assign_local (| + "current_target" , + M.get_name (| globals, "target" |) + |) in + let _ := M.assign_local (| + "msg_data" , + M.get_name (| globals, "data" |) + |) in + let _ := M.assign_local (| + "code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -147,7 +168,8 @@ Definition prepare_message : Value.t -> Value.t -> M := M.get_name (| globals, "target" |) ], make_dict [] - |), "code" |) in + |), "code" |) + |) in let _ := (* if *) M.if_then_else (| @@ -157,8 +179,10 @@ Definition prepare_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let code_address := - M.get_name (| globals, "target" |) in + let _ := M.assign_local (| + "code_address" , + M.get_name (| globals, "target" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/muir_glacier/vm/__init__.v b/CoqOfPython/ethereum/muir_glacier/vm/__init__.v index ebce706..e34d6a5 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/__init__.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/__init__.v @@ -18,29 +18,47 @@ The abstract computer which runs the code stored in an `.fork_types.Account`. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple"; "Union" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U64"; "U256"; "Bytes"; "Bytes0"; "Uint" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. - -Axiom ethereum_muir_glacier_blocks_imports : - AreImported globals "ethereum.muir_glacier.blocks" [ "Log" ]. - -Axiom ethereum_muir_glacier_fork_types_imports : - AreImported globals "ethereum.muir_glacier.fork_types" [ "Address" ]. - -Axiom ethereum_muir_glacier_state_imports : - AreImported globals "ethereum.muir_glacier.state" [ "State"; "account_exists_and_is_empty" ]. - -Axiom ethereum_muir_glacier_vm_precompiled_contracts_imports : - AreImported globals "ethereum.muir_glacier.vm.precompiled_contracts" [ "RIPEMD160_ADDRESS" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". + +Axiom ethereum_base_types_imports_U64 : + IsImported globals "ethereum.base_types" "U64". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". + +Axiom ethereum_muir_glacier_blocks_imports_Log : + IsImported globals "ethereum.muir_glacier.blocks" "Log". + +Axiom ethereum_muir_glacier_fork_types_imports_Address : + IsImported globals "ethereum.muir_glacier.fork_types" "Address". + +Axiom ethereum_muir_glacier_state_imports_State : + IsImported globals "ethereum.muir_glacier.state" "State". +Axiom ethereum_muir_glacier_state_imports_account_exists_and_is_empty : + IsImported globals "ethereum.muir_glacier.state" "account_exists_and_is_empty". + +Axiom ethereum_muir_glacier_vm_precompiled_contracts_imports_RIPEMD160_ADDRESS : + IsImported globals "ethereum.muir_glacier.vm.precompiled_contracts" "RIPEMD160_ADDRESS". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] diff --git a/CoqOfPython/ethereum/muir_glacier/vm/exceptions.v b/CoqOfPython/ethereum/muir_glacier/vm/exceptions.v index cff930b..9843a2b 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/exceptions.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/exceptions.v @@ -17,8 +17,8 @@ Introduction Exceptions which cause the EVM to halt exceptionally. ". -Axiom ethereum_exceptions_imports : - AreImported globals "ethereum.exceptions" [ "EthereumException" ]. +Axiom ethereum_exceptions_imports_EthereumException : + IsImported globals "ethereum.exceptions" "EthereumException". Definition ExceptionalHalt : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/muir_glacier/vm/gas.v b/CoqOfPython/ethereum/muir_glacier/vm/gas.v index 3597875..6ebc8c4 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/gas.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/gas.v @@ -17,26 +17,32 @@ Introduction EVM gas constants and calculators. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Tuple" ]. +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_trace_imports : - AreImported globals "ethereum.trace" [ "GasAndRefund"; "evm_trace" ]. +Axiom ethereum_trace_imports_GasAndRefund : + IsImported globals "ethereum.trace" "GasAndRefund". +Axiom ethereum_trace_imports_evm_trace : + IsImported globals "ethereum.trace" "evm_trace". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_muir_glacier_vm_imports : - AreImported globals "ethereum.muir_glacier.vm" [ "Evm" ]. +Axiom ethereum_muir_glacier_vm_imports_Evm : + IsImported globals "ethereum.muir_glacier.vm" "Evm". -Axiom ethereum_muir_glacier_vm_exceptions_imports : - AreImported globals "ethereum.muir_glacier.vm.exceptions" [ "OutOfGasError" ]. +Axiom ethereum_muir_glacier_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.muir_glacier.vm.exceptions" "OutOfGasError". Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -562,7 +568,8 @@ Definition calculate_memory_gas_cost : Value.t -> Value.t -> M := total_gas_cost : `ethereum.base_types.Uint` The gas cost for storing data in memory. " in - let size_in_words := + let _ := M.assign_local (| + "size_in_words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -572,25 +579,32 @@ Definition calculate_memory_gas_cost : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let linear_cost := + |) + |) in + let _ := M.assign_local (| + "linear_cost" , BinOp.mult (| M.get_name (| globals, "size_in_words" |), M.get_name (| globals, "GAS_MEMORY" |) - |) in - let quadratic_cost := + |) + |) in + let _ := M.assign_local (| + "quadratic_cost" , BinOp.floor_div (| BinOp.pow (| M.get_name (| globals, "size_in_words" |), Constant.int 2 |), Constant.int 512 - |) in - let total_gas_cost := + |) + |) in + let _ := M.assign_local (| + "total_gas_cost" , BinOp.add (| M.get_name (| globals, "linear_cost" |), M.get_name (| globals, "quadratic_cost" |) - |) in + |) + |) in (* At stmt: unsupported node type: Try *) M.pure Constant.None_)). @@ -612,23 +626,28 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := ------- extend_memory: `ExtendMemory` " in - let size_to_extend := + let _ := M.assign_local (| + "size_to_extend" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in - let to_be_paid := + |) + |) in + let _ := M.assign_local (| + "to_be_paid" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in - let current_size := + |) + |) in + let _ := M.assign_local (| + "current_size" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -641,7 +660,8 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ], @@ -662,15 +682,18 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let before_size := + let _ := M.assign_local (| + "before_size" , M.call (| M.get_name (| globals, "ceil32" |), make_list [ M.get_name (| globals, "current_size" |) ], make_dict [] - |) in - let after_size := + |) + |) in + let _ := M.assign_local (| + "after_size" , M.call (| M.get_name (| globals, "ceil32" |), make_list [ @@ -692,7 +715,8 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -708,42 +732,46 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let size_to_extend := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "size_to_extend", BinOp.sub (| M.get_name (| globals, "after_size" |), M.get_name (| globals, "before_size" |) |) - BinOp.sub (| - M.get_name (| globals, "after_size" |), - M.get_name (| globals, "before_size" |) - |) in - let already_paid := + |) in + let _ := M.assign_local (| + "already_paid" , M.call (| M.get_name (| globals, "calculate_memory_gas_cost" |), make_list [ M.get_name (| globals, "before_size" |) ], make_dict [] - |) in - let total_cost := + |) + |) in + let _ := M.assign_local (| + "total_cost" , M.call (| M.get_name (| globals, "calculate_memory_gas_cost" |), make_list [ M.get_name (| globals, "after_size" |) ], make_dict [] - |) in - let to_be_paid := BinOp.add + |) + |) in + let _ := M.assign_op_local (| + BinOp.add, + "to_be_paid", BinOp.sub (| M.get_name (| globals, "total_cost" |), M.get_name (| globals, "already_paid" |) |) - BinOp.sub (| - M.get_name (| globals, "total_cost" |), - M.get_name (| globals, "already_paid" |) - |) in - let current_size := - M.get_name (| globals, "after_size" |) in + |) in + let _ := M.assign_local (| + "current_size" , + M.get_name (| globals, "after_size" |) + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -790,7 +818,8 @@ Definition calculate_message_call_gas : Value.t -> Value.t -> M := ------- message_call_gas: `MessageCallGas` " in - let call_stipend := + let _ := M.assign_local (| + "call_stipend" , (* if *) M.if_then_else (| Compare.eq (| @@ -809,7 +838,8 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "call_stipend" |) - )) |) in + )) |) + |) in let _ := (* if *) M.if_then_else (| @@ -843,7 +873,8 @@ M.get_name (| globals, "call_stipend" |) )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -863,7 +894,8 @@ M.get_name (| globals, "call_stipend" |) |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "MessageCallGas" |), diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/__init__.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/__init__.v index e9a8f65..d7a2ea0 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/__init__.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/__init__.v @@ -20,44 +20,46 @@ implementations. (* At top_level_stmt: unsupported node type: Import *) -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict" ]. +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". -Axiom ethereum_muir_glacier_vm_instructions_imports : - AreImported globals "ethereum.muir_glacier.vm.instructions" [ "arithmetic" ]. +Axiom ethereum_muir_glacier_vm_instructions_imports_arithmetic : + IsImported globals "ethereum.muir_glacier.vm.instructions" "arithmetic". -Axiom ethereum_muir_glacier_vm_instructions_imports : - AreImported globals "ethereum.muir_glacier.vm.instructions" [ "bitwise" ]. +Axiom ethereum_muir_glacier_vm_instructions_imports_bitwise : + IsImported globals "ethereum.muir_glacier.vm.instructions" "bitwise". -Axiom ethereum_muir_glacier_vm_instructions_imports : - AreImported globals "ethereum.muir_glacier.vm.instructions" [ "block" ]. +Axiom ethereum_muir_glacier_vm_instructions_imports_block : + IsImported globals "ethereum.muir_glacier.vm.instructions" "block". -Axiom ethereum_muir_glacier_vm_instructions_imports : - AreImported globals "ethereum.muir_glacier.vm.instructions" [ "comparison" ]. +Axiom ethereum_muir_glacier_vm_instructions_imports_comparison : + IsImported globals "ethereum.muir_glacier.vm.instructions" "comparison". -Axiom ethereum_muir_glacier_vm_instructions_imports : - AreImported globals "ethereum.muir_glacier.vm.instructions" [ "control_flow" ]. +Axiom ethereum_muir_glacier_vm_instructions_imports_control_flow : + IsImported globals "ethereum.muir_glacier.vm.instructions" "control_flow". -Axiom ethereum_muir_glacier_vm_instructions_imports : - AreImported globals "ethereum.muir_glacier.vm.instructions" [ "environment" ]. +Axiom ethereum_muir_glacier_vm_instructions_imports_environment : + IsImported globals "ethereum.muir_glacier.vm.instructions" "environment". -Axiom ethereum_muir_glacier_vm_instructions_imports : - AreImported globals "ethereum.muir_glacier.vm.instructions" [ "keccak" ]. +Axiom ethereum_muir_glacier_vm_instructions_imports_keccak : + IsImported globals "ethereum.muir_glacier.vm.instructions" "keccak". -Axiom ethereum_muir_glacier_vm_instructions_imports : - AreImported globals "ethereum.muir_glacier.vm.instructions" [ "log" ]. +Axiom ethereum_muir_glacier_vm_instructions_imports_log : + IsImported globals "ethereum.muir_glacier.vm.instructions" "log". -Axiom ethereum_muir_glacier_vm_instructions_imports : - AreImported globals "ethereum.muir_glacier.vm.instructions" [ "memory" ]. +Axiom ethereum_muir_glacier_vm_instructions_imports_memory : + IsImported globals "ethereum.muir_glacier.vm.instructions" "memory". -Axiom ethereum_muir_glacier_vm_instructions_imports : - AreImported globals "ethereum.muir_glacier.vm.instructions" [ "stack" ]. +Axiom ethereum_muir_glacier_vm_instructions_imports_stack : + IsImported globals "ethereum.muir_glacier.vm.instructions" "stack". -Axiom ethereum_muir_glacier_vm_instructions_imports : - AreImported globals "ethereum.muir_glacier.vm.instructions" [ "storage" ]. +Axiom ethereum_muir_glacier_vm_instructions_imports_storage : + IsImported globals "ethereum.muir_glacier.vm.instructions" "storage". -Axiom ethereum_muir_glacier_vm_instructions_imports : - AreImported globals "ethereum.muir_glacier.vm.instructions" [ "system" ]. +Axiom ethereum_muir_glacier_vm_instructions_imports_system : + IsImported globals "ethereum.muir_glacier.vm.instructions" "system". Definition Ops : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/arithmetic.v index d28e88d..6e651f5 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/arithmetic.v @@ -17,20 +17,38 @@ Introduction Implementations of the EVM Arithmetic instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U255_CEIL_VALUE"; "U256"; "U256_CEIL_VALUE"; "Uint" ]. +Axiom ethereum_base_types_imports_U255_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U255_CEIL_VALUE". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_U256_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U256_CEIL_VALUE". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "get_sign" ]. +Axiom ethereum_utils_numeric_imports_get_sign : + IsImported globals "ethereum.utils.numeric" "get_sign". -Axiom ethereum_muir_glacier_vm_imports : - AreImported globals "ethereum.muir_glacier.vm" [ "Evm" ]. +Axiom ethereum_muir_glacier_vm_imports_Evm : + IsImported globals "ethereum.muir_glacier.vm" "Evm". -Axiom ethereum_muir_glacier_vm_gas_imports : - AreImported globals "ethereum.muir_glacier.vm.gas" [ "GAS_EXPONENTIATION"; "GAS_EXPONENTIATION_PER_BYTE"; "GAS_LOW"; "GAS_MID"; "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_EXPONENTIATION : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_EXPONENTIATION". +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_EXPONENTIATION_PER_BYTE : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_EXPONENTIATION_PER_BYTE". +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_LOW : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_LOW". +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_MID : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_MID". +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_muir_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.muir_glacier.vm.gas" "charge_gas". -Axiom ethereum_muir_glacier_vm_stack_imports : - AreImported globals "ethereum.muir_glacier.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_muir_glacier_vm_stack_imports_pop : + IsImported globals "ethereum.muir_glacier.vm.stack" "pop". +Axiom ethereum_muir_glacier_vm_stack_imports_push : + IsImported globals "ethereum.muir_glacier.vm.stack" "push". Definition add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,22 +63,26 @@ Definition add : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -69,14 +91,16 @@ Definition add : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "x" |), "wrapping_add" |), make_list [ M.get_name (| globals, "y" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -105,22 +129,26 @@ Definition sub : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -129,14 +157,16 @@ Definition sub : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "x" |), "wrapping_sub" |), make_list [ M.get_name (| globals, "y" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -165,22 +195,26 @@ Definition mul : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -189,14 +223,16 @@ Definition mul : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "x" |), "wrapping_mul" |), make_list [ M.get_name (| globals, "y" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -225,22 +261,26 @@ Definition div : Value.t -> Value.t -> M := The current EVM frame. " in - let dividend := + let _ := M.assign_local (| + "dividend" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let divisor := + |) + |) in + let _ := M.assign_local (| + "divisor" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -258,22 +298,26 @@ Definition div : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let quotient := + let _ := M.assign_local (| + "quotient" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let quotient := + let _ := M.assign_local (| + "quotient" , BinOp.floor_div (| M.get_name (| globals, "dividend" |), M.get_name (| globals, "divisor" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -304,7 +348,8 @@ Definition sdiv : Value.t -> Value.t -> M := The current EVM frame. " in - let dividend := + let _ := M.assign_local (| + "dividend" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -315,8 +360,10 @@ Definition sdiv : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let divisor := + |) + |) in + let _ := M.assign_local (| + "divisor" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -327,7 +374,8 @@ Definition sdiv : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -345,8 +393,10 @@ Definition sdiv : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let quotient := - Constant.int 0 in + let _ := M.assign_local (| + "quotient" , + Constant.int 0 + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -367,12 +417,15 @@ Definition sdiv : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let quotient := - UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in + let _ := M.assign_local (| + "quotient" , + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let sign := + let _ := M.assign_local (| + "sign" , M.call (| M.get_name (| globals, "get_sign" |), make_list [ @@ -382,8 +435,10 @@ Definition sdiv : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let quotient := + |) + |) in + let _ := M.assign_local (| + "quotient" , BinOp.mult (| M.get_name (| globals, "sign" |), BinOp.floor_div (| @@ -402,7 +457,8 @@ Definition sdiv : Value.t -> Value.t -> M := make_dict [] |) |) - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -428,7 +484,7 @@ Definition sdiv : Value.t -> Value.t -> M := |) in M.pure Constant.None_)). -Definition mod : Value.t -> Value.t -> M := +Definition mod_ : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in let _ := Constant.str " @@ -441,22 +497,26 @@ Definition mod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -474,22 +534,26 @@ Definition mod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let remainder := + let _ := M.assign_local (| + "remainder" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let remainder := + let _ := M.assign_local (| + "remainder" , BinOp.mod_ (| M.get_name (| globals, "x" |), M.get_name (| globals, "y" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -520,7 +584,8 @@ Definition smod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -531,8 +596,10 @@ Definition smod : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -543,7 +610,8 @@ Definition smod : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -561,12 +629,15 @@ Definition smod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let remainder := - Constant.int 0 in + let _ := M.assign_local (| + "remainder" , + Constant.int 0 + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let remainder := + let _ := M.assign_local (| + "remainder" , BinOp.mult (| M.call (| M.get_name (| globals, "get_sign" |), @@ -591,7 +662,8 @@ Definition smod : Value.t -> Value.t -> M := make_dict [] |) |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -628,7 +700,8 @@ Definition addmod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -641,8 +714,10 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -655,8 +730,10 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let z := + |) + |) in + let _ := M.assign_local (| + "z" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -669,7 +746,8 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -687,18 +765,21 @@ Definition addmod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -711,7 +792,8 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -742,7 +824,8 @@ Definition mulmod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -755,8 +838,10 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -769,8 +854,10 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let z := + |) + |) in + let _ := M.assign_local (| + "z" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -783,7 +870,8 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -801,18 +889,21 @@ Definition mulmod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -825,7 +916,8 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -856,7 +948,8 @@ Definition exp : Value.t -> Value.t -> M := The current EVM frame. " in - let base := + let _ := M.assign_local (| + "base" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -869,8 +962,10 @@ Definition exp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exponent := + |) + |) in + let _ := M.assign_local (| + "exponent" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -883,21 +978,26 @@ Definition exp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exponent_bits := + |) + |) in + let _ := M.assign_local (| + "exponent_bits" , M.call (| M.get_field (| M.get_name (| globals, "exponent" |), "bit_length" |), make_list [], make_dict [] - |) in - let exponent_bytes := + |) + |) in + let _ := M.assign_local (| + "exponent_bytes" , BinOp.floor_div (| BinOp.add (| M.get_name (| globals, "exponent_bits" |), Constant.int 7 |), Constant.int 8 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -912,7 +1012,8 @@ Definition exp : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -927,7 +1028,8 @@ Definition exp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -956,22 +1058,26 @@ Definition signextend : Value.t -> Value.t -> M := The current EVM frame. " in - let byte_num := + let _ := M.assign_local (| + "byte_num" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -989,12 +1095,15 @@ Definition signextend : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := - M.get_name (| globals, "value" |) in + let _ := M.assign_local (| + "result" , + M.get_name (| globals, "value" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let value_bytes := + let _ := M.assign_local (| + "value_bytes" , M.call (| M.get_name (| globals, "bytes" |), make_list [ @@ -1005,8 +1114,10 @@ Definition signextend : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let value_bytes := + |) + |) in + let _ := M.assign_local (| + "value_bytes" , M.slice (| M.get_name (| globals, "value_bytes" |), BinOp.sub (| @@ -1021,15 +1132,18 @@ Definition signextend : Value.t -> Value.t -> M := |), Constant.None_, Constant.None_ - |) in - let sign_bit := + |) + |) in + let _ := M.assign_local (| + "sign_bit" , BinOp.r_shift (| M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), Constant.int 7 - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1039,26 +1153,31 @@ Definition signextend : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "value_bytes" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let num_bytes_prepend := + let _ := M.assign_local (| + "num_bytes_prepend" , BinOp.sub (| Constant.int 32, BinOp.add (| M.get_name (| globals, "byte_num" |), Constant.int 1 |) - |) in - let result := + |) + |) in + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -1079,7 +1198,8 @@ Definition signextend : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/bitwise.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/bitwise.v index a68dc9b..7fff3d6 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/bitwise.v @@ -17,17 +17,23 @@ Introduction Implementations of the EVM bitwise instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "U256_CEIL_VALUE" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_U256_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U256_CEIL_VALUE". -Axiom ethereum_muir_glacier_vm_imports : - AreImported globals "ethereum.muir_glacier.vm" [ "Evm" ]. +Axiom ethereum_muir_glacier_vm_imports_Evm : + IsImported globals "ethereum.muir_glacier.vm" "Evm". -Axiom ethereum_muir_glacier_vm_gas_imports : - AreImported globals "ethereum.muir_glacier.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_muir_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.muir_glacier.vm.gas" "charge_gas". -Axiom ethereum_muir_glacier_vm_stack_imports : - AreImported globals "ethereum.muir_glacier.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_muir_glacier_vm_stack_imports_pop : + IsImported globals "ethereum.muir_glacier.vm.stack" "pop". +Axiom ethereum_muir_glacier_vm_stack_imports_push : + IsImported globals "ethereum.muir_glacier.vm.stack" "push". Definition bitwise_and : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,22 +48,26 @@ Definition bitwise_and : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -97,22 +107,26 @@ Definition bitwise_or : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -152,22 +166,26 @@ Definition bitwise_xor : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -207,14 +225,16 @@ Definition bitwise_not : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -252,22 +272,26 @@ Definition get_byte : Value.t -> Value.t -> M := The current EVM frame. " in - let byte_index := + let _ := M.assign_local (| + "byte_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let word := + |) + |) in + let _ := M.assign_local (| + "word" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -285,43 +309,53 @@ Definition get_byte : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let extra_bytes_to_right := + let _ := M.assign_local (| + "extra_bytes_to_right" , BinOp.sub (| Constant.int 31, M.get_name (| globals, "byte_index" |) - |) in - let word := + |) + |) in + let _ := M.assign_local (| + "word" , BinOp.r_shift (| M.get_name (| globals, "word" |), BinOp.mult (| M.get_name (| globals, "extra_bytes_to_right" |), Constant.int 8 |) - |) in - let word := + |) + |) in + let _ := M.assign_local (| + "word" , BinOp.bit_and (| M.get_name (| globals, "word" |), Constant.int 255 - |) in - let result := + |) + |) in + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ M.get_name (| globals, "word" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -350,22 +384,26 @@ Definition bitwise_shl : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let shift := + let _ := M.assign_local (| + "shift" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -383,7 +421,8 @@ Definition bitwise_shl : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -396,18 +435,21 @@ Definition bitwise_shl : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -436,22 +478,26 @@ Definition bitwise_shr : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let shift := + let _ := M.assign_local (| + "shift" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -469,22 +515,26 @@ Definition bitwise_shr : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , BinOp.r_shift (| M.get_name (| globals, "value" |), M.get_name (| globals, "shift" |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -513,15 +563,18 @@ Definition bitwise_sar : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let shift := + let _ := M.assign_local (| + "shift" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let signed_value := + |) + |) in + let _ := M.assign_local (| + "signed_value" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -532,7 +585,8 @@ Definition bitwise_sar : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -550,7 +604,8 @@ Definition bitwise_sar : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), make_list [ @@ -560,7 +615,8 @@ Definition bitwise_sar : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -573,19 +629,23 @@ Definition bitwise_sar : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := - M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) in + let _ := M.assign_local (| + "result" , + M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/block.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/block.v index 404f2ac..167e4e0 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/block.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/block.v @@ -17,17 +17,23 @@ Introduction Implementations of the EVM block instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_muir_glacier_vm_imports : - AreImported globals "ethereum.muir_glacier.vm" [ "Evm" ]. +Axiom ethereum_muir_glacier_vm_imports_Evm : + IsImported globals "ethereum.muir_glacier.vm" "Evm". -Axiom ethereum_muir_glacier_vm_gas_imports : - AreImported globals "ethereum.muir_glacier.vm.gas" [ "GAS_BASE"; "GAS_BLOCK_HASH"; "charge_gas" ]. +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_BASE". +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_BLOCK_HASH : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_BLOCK_HASH". +Axiom ethereum_muir_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.muir_glacier.vm.gas" "charge_gas". -Axiom ethereum_muir_glacier_vm_stack_imports : - AreImported globals "ethereum.muir_glacier.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_muir_glacier_vm_stack_imports_pop : + IsImported globals "ethereum.muir_glacier.vm.stack" "pop". +Axiom ethereum_muir_glacier_vm_stack_imports_push : + IsImported globals "ethereum.muir_glacier.vm.stack" "push". Definition block_hash : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,14 +48,16 @@ Definition block_hash : Value.t -> Value.t -> M := The current EVM frame. " in - let block_number := + let _ := M.assign_local (| + "block_number" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -78,19 +86,23 @@ Definition block_hash : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let hash := - Constant.bytes "00" in + let _ := M.assign_local (| + "hash" , + Constant.bytes "00" + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let hash := + let _ := M.assign_local (| + "hash" , M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), M.get_name (| globals, "block_number" |) |) |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/comparison.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/comparison.v index 881d3fd..63bffa3 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/comparison.v @@ -17,17 +17,21 @@ Introduction Implementations of the EVM Comparison instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_muir_glacier_vm_imports : - AreImported globals "ethereum.muir_glacier.vm" [ "Evm" ]. +Axiom ethereum_muir_glacier_vm_imports_Evm : + IsImported globals "ethereum.muir_glacier.vm" "Evm". -Axiom ethereum_muir_glacier_vm_gas_imports : - AreImported globals "ethereum.muir_glacier.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_muir_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.muir_glacier.vm.gas" "charge_gas". -Axiom ethereum_muir_glacier_vm_stack_imports : - AreImported globals "ethereum.muir_glacier.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_muir_glacier_vm_stack_imports_pop : + IsImported globals "ethereum.muir_glacier.vm.stack" "pop". +Axiom ethereum_muir_glacier_vm_stack_imports_push : + IsImported globals "ethereum.muir_glacier.vm.stack" "push". Definition less_than : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,22 +46,26 @@ Definition less_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -66,7 +74,8 @@ Definition less_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -76,7 +85,8 @@ Definition less_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -104,7 +114,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -115,8 +126,10 @@ Definition signed_less_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -127,7 +140,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -136,7 +150,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -146,7 +161,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -175,22 +191,26 @@ Definition greater_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -199,7 +219,8 @@ Definition greater_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -209,7 +230,8 @@ Definition greater_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -237,7 +259,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -248,8 +271,10 @@ Definition signed_greater_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -260,7 +285,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -269,7 +295,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -279,7 +306,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -308,22 +336,26 @@ Definition equal : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -332,7 +364,8 @@ Definition equal : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -342,7 +375,8 @@ Definition equal : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -371,14 +405,16 @@ Definition is_zero : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -387,7 +423,8 @@ Definition is_zero : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -397,7 +434,8 @@ Definition is_zero : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/control_flow.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/control_flow.v index 486d6cd..50f5c02 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/control_flow.v @@ -17,20 +17,32 @@ Introduction Implementations of the EVM control flow instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_muir_glacier_vm_gas_imports : - AreImported globals "ethereum.muir_glacier.vm.gas" [ "GAS_BASE"; "GAS_HIGH"; "GAS_JUMPDEST"; "GAS_MID"; "charge_gas" ]. +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_BASE". +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_HIGH : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_HIGH". +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_JUMPDEST : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_JUMPDEST". +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_MID : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_MID". +Axiom ethereum_muir_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.muir_glacier.vm.gas" "charge_gas". -Axiom ethereum_muir_glacier_vm_imports : - AreImported globals "ethereum.muir_glacier.vm" [ "Evm" ]. +Axiom ethereum_muir_glacier_vm_imports_Evm : + IsImported globals "ethereum.muir_glacier.vm" "Evm". -Axiom ethereum_muir_glacier_vm_exceptions_imports : - AreImported globals "ethereum.muir_glacier.vm.exceptions" [ "InvalidJumpDestError" ]. +Axiom ethereum_muir_glacier_vm_exceptions_imports_InvalidJumpDestError : + IsImported globals "ethereum.muir_glacier.vm.exceptions" "InvalidJumpDestError". -Axiom ethereum_muir_glacier_vm_stack_imports : - AreImported globals "ethereum.muir_glacier.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_muir_glacier_vm_stack_imports_pop : + IsImported globals "ethereum.muir_glacier.vm.stack" "pop". +Axiom ethereum_muir_glacier_vm_stack_imports_push : + IsImported globals "ethereum.muir_glacier.vm.stack" "push". Definition stop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -69,7 +81,8 @@ Definition jump : Value.t -> Value.t -> M := The current EVM frame. " in - let jump_dest := + let _ := M.assign_local (| + "jump_dest" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -82,7 +95,8 @@ Definition jump : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -132,7 +146,8 @@ Definition jumpi : Value.t -> Value.t -> M := The current EVM frame. " in - let jump_dest := + let _ := M.assign_local (| + "jump_dest" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -145,15 +160,18 @@ Definition jumpi : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let conditional_value := + |) + |) in + let _ := M.assign_local (| + "conditional_value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -171,11 +189,13 @@ Definition jumpi : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let destination := + let _ := M.assign_local (| + "destination" , BinOp.add (| M.get_field (| M.get_name (| globals, "evm" |), "pc" |), Constant.int 1 - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -192,8 +212,10 @@ Definition jumpi : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let destination := - M.get_name (| globals, "jump_dest" |) in + let _ := M.assign_local (| + "destination" , + M.get_name (| globals, "jump_dest" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/environment.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/environment.v index 77a757c..dc3f915 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/environment.v @@ -17,41 +17,65 @@ Introduction Implementations of the EVM environment related instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. - -Axiom ethereum_muir_glacier_fork_types_imports : - AreImported globals "ethereum.muir_glacier.fork_types" [ "EMPTY_ACCOUNT" ]. - -Axiom ethereum_muir_glacier_state_imports : - AreImported globals "ethereum.muir_glacier.state" [ "get_account" ]. - -Axiom ethereum_muir_glacier_utils_address_imports : - AreImported globals "ethereum.muir_glacier.utils.address" [ "to_address" ]. - -Axiom ethereum_muir_glacier_vm_memory_imports : - AreImported globals "ethereum.muir_glacier.vm.memory" [ "buffer_read"; "memory_write" ]. - -Axiom ethereum_muir_glacier_vm_imports : - AreImported globals "ethereum.muir_glacier.vm" [ "Evm" ]. - -Axiom ethereum_muir_glacier_vm_exceptions_imports : - AreImported globals "ethereum.muir_glacier.vm.exceptions" [ "OutOfBoundsRead" ]. - -Axiom ethereum_muir_glacier_vm_gas_imports : - AreImported globals "ethereum.muir_glacier.vm.gas" [ "GAS_BALANCE"; "GAS_BASE"; "GAS_CODE_HASH"; "GAS_COPY"; "GAS_EXTERNAL"; "GAS_FAST_STEP"; "GAS_RETURN_DATA_COPY"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. - -Axiom ethereum_muir_glacier_vm_stack_imports : - AreImported globals "ethereum.muir_glacier.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". + +Axiom ethereum_muir_glacier_fork_types_imports_EMPTY_ACCOUNT : + IsImported globals "ethereum.muir_glacier.fork_types" "EMPTY_ACCOUNT". + +Axiom ethereum_muir_glacier_state_imports_get_account : + IsImported globals "ethereum.muir_glacier.state" "get_account". + +Axiom ethereum_muir_glacier_utils_address_imports_to_address : + IsImported globals "ethereum.muir_glacier.utils.address" "to_address". + +Axiom ethereum_muir_glacier_vm_memory_imports_buffer_read : + IsImported globals "ethereum.muir_glacier.vm.memory" "buffer_read". +Axiom ethereum_muir_glacier_vm_memory_imports_memory_write : + IsImported globals "ethereum.muir_glacier.vm.memory" "memory_write". + +Axiom ethereum_muir_glacier_vm_imports_Evm : + IsImported globals "ethereum.muir_glacier.vm" "Evm". + +Axiom ethereum_muir_glacier_vm_exceptions_imports_OutOfBoundsRead : + IsImported globals "ethereum.muir_glacier.vm.exceptions" "OutOfBoundsRead". + +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_BALANCE : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_BALANCE". +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_BASE". +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_CODE_HASH : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_CODE_HASH". +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_COPY : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_COPY". +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_EXTERNAL : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_EXTERNAL". +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_FAST_STEP : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_FAST_STEP". +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_RETURN_DATA_COPY : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_RETURN_DATA_COPY". +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_muir_glacier_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.muir_glacier.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_muir_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.muir_glacier.vm.gas" "charge_gas". + +Axiom ethereum_muir_glacier_vm_stack_imports_pop : + IsImported globals "ethereum.muir_glacier.vm.stack" "pop". +Axiom ethereum_muir_glacier_vm_stack_imports_push : + IsImported globals "ethereum.muir_glacier.vm.stack" "push". Definition address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -107,7 +131,8 @@ Definition balance : Value.t -> Value.t -> M := The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -120,7 +145,8 @@ Definition balance : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -129,7 +155,8 @@ Definition balance : Value.t -> Value.t -> M := ], make_dict [] |) in - let balance := + let _ := M.assign_local (| + "balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -137,7 +164,8 @@ Definition balance : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -287,14 +315,16 @@ Definition calldataload : Value.t -> Value.t -> M := The current EVM frame. " in - let start_index := + let _ := M.assign_local (| + "start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -303,7 +333,8 @@ Definition calldataload : Value.t -> Value.t -> M := ], make_dict [] |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -318,7 +349,8 @@ Definition calldataload : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -403,31 +435,38 @@ Definition calldatacopy : Value.t -> Value.t -> M := The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let data_start_index := + |) + |) in + let _ := M.assign_local (| + "data_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -443,13 +482,17 @@ Definition calldatacopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -459,7 +502,8 @@ Definition calldatacopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -482,7 +526,8 @@ Definition calldatacopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -491,7 +536,8 @@ Definition calldatacopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -571,31 +617,38 @@ Definition codecopy : Value.t -> Value.t -> M := The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let code_start_index := + |) + |) in + let _ := M.assign_local (| + "code_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -611,13 +664,17 @@ Definition codecopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -627,7 +684,8 @@ Definition codecopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -650,7 +708,8 @@ Definition codecopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -659,7 +718,8 @@ Definition codecopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -730,7 +790,8 @@ Definition extcodesize : Value.t -> Value.t -> M := The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -743,7 +804,8 @@ Definition extcodesize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -752,7 +814,8 @@ Definition extcodesize : Value.t -> Value.t -> M := ], make_dict [] |) in - let codesize := + let _ := M.assign_local (| + "codesize" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -772,7 +835,8 @@ Definition extcodesize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -800,7 +864,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -813,32 +878,40 @@ Definition extcodecopy : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let memory_start_index := + |) + |) in + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let code_start_index := + |) + |) in + let _ := M.assign_local (| + "code_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -854,13 +927,17 @@ Definition extcodecopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -870,7 +947,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -893,7 +971,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let code := + let _ := M.assign_local (| + "code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -901,8 +980,10 @@ Definition extcodecopy : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |), "code" |) in - let value := + |), "code" |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -911,7 +992,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -986,31 +1068,38 @@ Definition returndatacopy : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let return_data_start_position := + |) + |) in + let _ := M.assign_local (| + "return_data_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -1026,13 +1115,17 @@ Definition returndatacopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_RETURN_DATA_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1042,7 +1135,8 @@ Definition returndatacopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1097,7 +1191,8 @@ Definition returndatacopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.slice (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |), @@ -1106,7 +1201,8 @@ Definition returndatacopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) |), Constant.None_ - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -1133,7 +1229,8 @@ Definition extcodehash : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1146,7 +1243,8 @@ Definition extcodehash : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1155,7 +1253,8 @@ Definition extcodehash : Value.t -> Value.t -> M := ], make_dict [] |) in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1163,7 +1262,8 @@ Definition extcodehash : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1173,18 +1273,21 @@ Definition extcodehash : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let codehash := + let _ := M.assign_local (| + "codehash" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let codehash := + let _ := M.assign_local (| + "codehash" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -1197,7 +1300,8 @@ Definition extcodehash : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -1236,7 +1340,8 @@ Definition self_balance : Value.t -> Value.t -> M := ], make_dict [] |) in - let balance := + let _ := M.assign_local (| + "balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1244,7 +1349,8 @@ Definition self_balance : Value.t -> Value.t -> M := M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/keccak.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/keccak.v index 788dc38..a317bc4 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/keccak.v @@ -17,26 +17,36 @@ Introduction Implementations of the EVM keccak instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_muir_glacier_vm_imports : - AreImported globals "ethereum.muir_glacier.vm" [ "Evm" ]. +Axiom ethereum_muir_glacier_vm_imports_Evm : + IsImported globals "ethereum.muir_glacier.vm" "Evm". -Axiom ethereum_muir_glacier_vm_gas_imports : - AreImported globals "ethereum.muir_glacier.vm.gas" [ "GAS_KECCAK256"; "GAS_KECCAK256_WORD"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_KECCAK256 : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_KECCAK256". +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_KECCAK256_WORD : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_KECCAK256_WORD". +Axiom ethereum_muir_glacier_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.muir_glacier.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_muir_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.muir_glacier.vm.gas" "charge_gas". -Axiom ethereum_muir_glacier_vm_memory_imports : - AreImported globals "ethereum.muir_glacier.vm.memory" [ "memory_read_bytes" ]. +Axiom ethereum_muir_glacier_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.muir_glacier.vm.memory" "memory_read_bytes". -Axiom ethereum_muir_glacier_vm_stack_imports : - AreImported globals "ethereum.muir_glacier.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_muir_glacier_vm_stack_imports_pop : + IsImported globals "ethereum.muir_glacier.vm.stack" "pop". +Axiom ethereum_muir_glacier_vm_stack_imports_push : + IsImported globals "ethereum.muir_glacier.vm.stack" "push". Definition keccak : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -53,23 +63,28 @@ Definition keccak : Value.t -> Value.t -> M := The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -85,13 +100,17 @@ Definition keccak : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let word_gas_cost := + |) + |) in + let _ := M.assign_local (| + "word_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_KECCAK256_WORD" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -101,7 +120,8 @@ Definition keccak : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -124,7 +144,8 @@ Definition keccak : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let data := + let _ := M.assign_local (| + "data" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -133,15 +154,18 @@ Definition keccak : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in - let hash := + |) + |) in + let _ := M.assign_local (| + "hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "data" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/log.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/log.v index e21e74a..6d8d000 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/log.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/log.v @@ -17,32 +17,40 @@ Introduction Implementations of the EVM logging instructions. ". -Axiom functools_imports : - AreImported globals "functools" [ "partial" ]. +Axiom functools_imports_partial : + IsImported globals "functools" "partial". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_muir_glacier_blocks_imports : - AreImported globals "ethereum.muir_glacier.blocks" [ "Log" ]. +Axiom ethereum_muir_glacier_blocks_imports_Log : + IsImported globals "ethereum.muir_glacier.blocks" "Log". -Axiom ethereum_muir_glacier_vm_imports : - AreImported globals "ethereum.muir_glacier.vm" [ "Evm" ]. +Axiom ethereum_muir_glacier_vm_imports_Evm : + IsImported globals "ethereum.muir_glacier.vm" "Evm". -Axiom ethereum_muir_glacier_vm_exceptions_imports : - AreImported globals "ethereum.muir_glacier.vm.exceptions" [ "WriteInStaticContext" ]. +Axiom ethereum_muir_glacier_vm_exceptions_imports_WriteInStaticContext : + IsImported globals "ethereum.muir_glacier.vm.exceptions" "WriteInStaticContext". -Axiom ethereum_muir_glacier_vm_gas_imports : - AreImported globals "ethereum.muir_glacier.vm.gas" [ "GAS_LOG"; "GAS_LOG_DATA"; "GAS_LOG_TOPIC"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_LOG : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_LOG". +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_LOG_DATA : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_LOG_DATA". +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_LOG_TOPIC : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_LOG_TOPIC". +Axiom ethereum_muir_glacier_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.muir_glacier.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_muir_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.muir_glacier.vm.gas" "charge_gas". -Axiom ethereum_muir_glacier_vm_memory_imports : - AreImported globals "ethereum.muir_glacier.vm.memory" [ "memory_read_bytes" ]. +Axiom ethereum_muir_glacier_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.muir_glacier.vm.memory" "memory_read_bytes". -Axiom ethereum_muir_glacier_vm_stack_imports : - AreImported globals "ethereum.muir_glacier.vm.stack" [ "pop" ]. +Axiom ethereum_muir_glacier_vm_stack_imports_pop : + IsImported globals "ethereum.muir_glacier.vm.stack" "pop". Definition log_n : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -61,24 +69,30 @@ Definition log_n : Value.t -> Value.t -> M := The number of topics to be included in the log entry. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let topics := - make_list [] in + |) + |) in + let _ := M.assign_local (| + "topics" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "_" |), @@ -90,7 +104,8 @@ Definition log_n : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let topic := + let _ := M.assign_local (| + "topic" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -101,7 +116,8 @@ Definition log_n : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "topics" |), "append" |), make_list [ @@ -115,7 +131,8 @@ Definition log_n : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let extend_memory := + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -125,7 +142,8 @@ Definition log_n : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -165,12 +183,14 @@ Definition log_n : Value.t -> Value.t -> M := ], make_dict [] |) in - let log_entry := + let _ := M.assign_local (| + "log_entry" , M.call (| M.get_name (| globals, "Log" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "logs" |), BinOp.add (| diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/memory.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/memory.v index 2413644..c12ac45 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/memory.v @@ -17,20 +17,32 @@ Introduction Implementations of the EVM Memory instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". -Axiom ethereum_muir_glacier_vm_imports : - AreImported globals "ethereum.muir_glacier.vm" [ "Evm" ]. +Axiom ethereum_muir_glacier_vm_imports_Evm : + IsImported globals "ethereum.muir_glacier.vm" "Evm". -Axiom ethereum_muir_glacier_vm_gas_imports : - AreImported globals "ethereum.muir_glacier.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_BASE". +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_muir_glacier_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.muir_glacier.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_muir_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.muir_glacier.vm.gas" "charge_gas". -Axiom ethereum_muir_glacier_vm_memory_imports : - AreImported globals "ethereum.muir_glacier.vm.memory" [ "memory_read_bytes"; "memory_write" ]. +Axiom ethereum_muir_glacier_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.muir_glacier.vm.memory" "memory_read_bytes". +Axiom ethereum_muir_glacier_vm_memory_imports_memory_write : + IsImported globals "ethereum.muir_glacier.vm.memory" "memory_write". -Axiom ethereum_muir_glacier_vm_stack_imports : - AreImported globals "ethereum.muir_glacier.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_muir_glacier_vm_stack_imports_pop : + IsImported globals "ethereum.muir_glacier.vm.stack" "pop". +Axiom ethereum_muir_glacier_vm_stack_imports_push : + IsImported globals "ethereum.muir_glacier.vm.stack" "push". Definition mstore : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -46,15 +58,18 @@ Definition mstore : Value.t -> Value.t -> M := The current EVM frame. " in - let start_position := + let _ := M.assign_local (| + "start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -65,8 +80,10 @@ Definition mstore : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -88,7 +105,8 @@ Definition mstore : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -138,23 +156,28 @@ Definition mstore8 : Value.t -> Value.t -> M := The current EVM frame. " in - let start_position := + let _ := M.assign_local (| + "start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -170,7 +193,8 @@ Definition mstore8 : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -190,7 +214,8 @@ Definition mstore8 : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let normalized_bytes_value := + let _ := M.assign_local (| + "normalized_bytes_value" , M.call (| M.get_name (| globals, "Bytes" |), make_list [ @@ -202,7 +227,8 @@ Definition mstore8 : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -231,15 +257,18 @@ Definition mload : Value.t -> Value.t -> M := The current EVM frame. " in - let start_position := + let _ := M.assign_local (| + "start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -255,7 +284,8 @@ Definition mload : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -275,7 +305,8 @@ Definition mload : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -296,7 +327,8 @@ Definition mload : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/stack.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/stack.v index 84aa293..c20b432 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/stack.v @@ -17,26 +17,32 @@ Introduction Implementations of the EVM stack related instructions. ". -Axiom functools_imports : - AreImported globals "functools" [ "partial" ]. +Axiom functools_imports_partial : + IsImported globals "functools" "partial". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_muir_glacier_vm_imports : - AreImported globals "ethereum.muir_glacier.vm" [ "Evm"; "stack" ]. +Axiom ethereum_muir_glacier_vm_imports_Evm : + IsImported globals "ethereum.muir_glacier.vm" "Evm". +Axiom ethereum_muir_glacier_vm_imports_stack : + IsImported globals "ethereum.muir_glacier.vm" "stack". -Axiom ethereum_muir_glacier_vm_exceptions_imports : - AreImported globals "ethereum.muir_glacier.vm.exceptions" [ "StackUnderflowError" ]. +Axiom ethereum_muir_glacier_vm_exceptions_imports_StackUnderflowError : + IsImported globals "ethereum.muir_glacier.vm.exceptions" "StackUnderflowError". -Axiom ethereum_muir_glacier_vm_gas_imports : - AreImported globals "ethereum.muir_glacier.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_BASE". +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_muir_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.muir_glacier.vm.gas" "charge_gas". -Axiom ethereum_muir_glacier_vm_memory_imports : - AreImported globals "ethereum.muir_glacier.vm.memory" [ "buffer_read" ]. +Axiom ethereum_muir_glacier_vm_memory_imports_buffer_read : + IsImported globals "ethereum.muir_glacier.vm.memory" "buffer_read". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -98,7 +104,8 @@ Definition push_n : Value.t -> Value.t -> M := ], make_dict [] |) in - let data_to_push := + let _ := M.assign_local (| + "data_to_push" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -128,7 +135,8 @@ Definition push_n : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "stack" |), "push" |), make_list [ @@ -189,7 +197,8 @@ Definition dup_n : Value.t -> Value.t -> M := ], make_dict [] |) in - let data_to_duplicate := + let _ := M.assign_local (| + "data_to_duplicate" , M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| @@ -205,7 +214,8 @@ Definition dup_n : Value.t -> Value.t -> M := |), M.get_name (| globals, "item_number" |) |) - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "stack" |), "push" |), make_list [ diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/storage.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/storage.v index 884a80d..dd601c1 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/storage.v @@ -17,23 +17,41 @@ Introduction Implementations of the EVM storage related instructions. ". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_muir_glacier_state_imports : - AreImported globals "ethereum.muir_glacier.state" [ "get_storage"; "get_storage_original"; "set_storage" ]. +Axiom ethereum_muir_glacier_state_imports_get_storage : + IsImported globals "ethereum.muir_glacier.state" "get_storage". +Axiom ethereum_muir_glacier_state_imports_get_storage_original : + IsImported globals "ethereum.muir_glacier.state" "get_storage_original". +Axiom ethereum_muir_glacier_state_imports_set_storage : + IsImported globals "ethereum.muir_glacier.state" "set_storage". -Axiom ethereum_muir_glacier_vm_imports : - AreImported globals "ethereum.muir_glacier.vm" [ "Evm" ]. +Axiom ethereum_muir_glacier_vm_imports_Evm : + IsImported globals "ethereum.muir_glacier.vm" "Evm". -Axiom ethereum_muir_glacier_vm_exceptions_imports : - AreImported globals "ethereum.muir_glacier.vm.exceptions" [ "OutOfGasError"; "WriteInStaticContext" ]. +Axiom ethereum_muir_glacier_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.muir_glacier.vm.exceptions" "OutOfGasError". +Axiom ethereum_muir_glacier_vm_exceptions_imports_WriteInStaticContext : + IsImported globals "ethereum.muir_glacier.vm.exceptions" "WriteInStaticContext". -Axiom ethereum_muir_glacier_vm_gas_imports : - AreImported globals "ethereum.muir_glacier.vm.gas" [ "GAS_CALL_STIPEND"; "GAS_SLOAD"; "GAS_STORAGE_CLEAR_REFUND"; "GAS_STORAGE_SET"; "GAS_STORAGE_UPDATE"; "charge_gas" ]. +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_CALL_STIPEND : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_CALL_STIPEND". +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_SLOAD : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_SLOAD". +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_STORAGE_CLEAR_REFUND : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_STORAGE_CLEAR_REFUND". +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_STORAGE_SET : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_STORAGE_SET". +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_STORAGE_UPDATE : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_STORAGE_UPDATE". +Axiom ethereum_muir_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.muir_glacier.vm.gas" "charge_gas". -Axiom ethereum_muir_glacier_vm_stack_imports : - AreImported globals "ethereum.muir_glacier.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_muir_glacier_vm_stack_imports_pop : + IsImported globals "ethereum.muir_glacier.vm.stack" "pop". +Axiom ethereum_muir_glacier_vm_stack_imports_push : + IsImported globals "ethereum.muir_glacier.vm.stack" "push". Definition sload : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -48,7 +66,8 @@ Definition sload : Value.t -> Value.t -> M := The current EVM frame. " in - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -59,7 +78,8 @@ Definition sload : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -68,7 +88,8 @@ Definition sload : Value.t -> Value.t -> M := ], make_dict [] |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "get_storage" |), make_list [ @@ -77,7 +98,8 @@ Definition sload : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -105,7 +127,8 @@ Definition sstore : Value.t -> Value.t -> M := The current EVM frame. " in - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -116,15 +139,18 @@ Definition sstore : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in - let new_value := + |) + |) in + let _ := M.assign_local (| + "new_value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -136,7 +162,8 @@ Definition sstore : Value.t -> Value.t -> M := ], make_dict [] |) in - let original_value := + let _ := M.assign_local (| + "original_value" , M.call (| M.get_name (| globals, "get_storage_original" |), make_list [ @@ -145,8 +172,10 @@ Definition sstore : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in - let current_value := + |) + |) in + let _ := M.assign_local (| + "current_value" , M.call (| M.get_name (| globals, "get_storage" |), make_list [ @@ -155,7 +184,8 @@ Definition sstore : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -182,20 +212,26 @@ Definition sstore : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let gas_cost := - M.get_name (| globals, "GAS_STORAGE_SET" |) in + let _ := M.assign_local (| + "gas_cost" , + M.get_name (| globals, "GAS_STORAGE_SET" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let gas_cost := - M.get_name (| globals, "GAS_STORAGE_UPDATE" |) in + let _ := M.assign_local (| + "gas_cost" , + M.get_name (| globals, "GAS_STORAGE_UPDATE" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let gas_cost := - M.get_name (| globals, "GAS_SLOAD" |) in + let _ := M.assign_local (| + "gas_cost" , + M.get_name (| globals, "GAS_SLOAD" |) + |) in M.pure Constant.None_ )) |) in let _ := diff --git a/CoqOfPython/ethereum/muir_glacier/vm/instructions/system.v b/CoqOfPython/ethereum/muir_glacier/vm/instructions/system.v index 86d3a13..087a683 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/instructions/system.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/instructions/system.v @@ -17,38 +17,92 @@ Introduction Implementations of the EVM system related instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_muir_glacier_fork_types_imports : - AreImported globals "ethereum.muir_glacier.fork_types" [ "Address" ]. +Axiom ethereum_muir_glacier_fork_types_imports_Address : + IsImported globals "ethereum.muir_glacier.fork_types" "Address". -Axiom ethereum_muir_glacier_state_imports : - AreImported globals "ethereum.muir_glacier.state" [ "account_exists_and_is_empty"; "account_has_code_or_nonce"; "get_account"; "increment_nonce"; "is_account_alive"; "set_account_balance" ]. +Axiom ethereum_muir_glacier_state_imports_account_exists_and_is_empty : + IsImported globals "ethereum.muir_glacier.state" "account_exists_and_is_empty". +Axiom ethereum_muir_glacier_state_imports_account_has_code_or_nonce : + IsImported globals "ethereum.muir_glacier.state" "account_has_code_or_nonce". +Axiom ethereum_muir_glacier_state_imports_get_account : + IsImported globals "ethereum.muir_glacier.state" "get_account". +Axiom ethereum_muir_glacier_state_imports_increment_nonce : + IsImported globals "ethereum.muir_glacier.state" "increment_nonce". +Axiom ethereum_muir_glacier_state_imports_is_account_alive : + IsImported globals "ethereum.muir_glacier.state" "is_account_alive". +Axiom ethereum_muir_glacier_state_imports_set_account_balance : + IsImported globals "ethereum.muir_glacier.state" "set_account_balance". -Axiom ethereum_muir_glacier_utils_address_imports : - AreImported globals "ethereum.muir_glacier.utils.address" [ "compute_contract_address"; "compute_create2_contract_address"; "to_address" ]. +Axiom ethereum_muir_glacier_utils_address_imports_compute_contract_address : + IsImported globals "ethereum.muir_glacier.utils.address" "compute_contract_address". +Axiom ethereum_muir_glacier_utils_address_imports_compute_create2_contract_address : + IsImported globals "ethereum.muir_glacier.utils.address" "compute_create2_contract_address". +Axiom ethereum_muir_glacier_utils_address_imports_to_address : + IsImported globals "ethereum.muir_glacier.utils.address" "to_address". -Axiom ethereum_muir_glacier_vm_imports : - AreImported globals "ethereum.muir_glacier.vm" [ "Evm"; "Message"; "incorporate_child_on_error"; "incorporate_child_on_success" ]. +Axiom ethereum_muir_glacier_vm_imports_Evm : + IsImported globals "ethereum.muir_glacier.vm" "Evm". +Axiom ethereum_muir_glacier_vm_imports_Message : + IsImported globals "ethereum.muir_glacier.vm" "Message". +Axiom ethereum_muir_glacier_vm_imports_incorporate_child_on_error : + IsImported globals "ethereum.muir_glacier.vm" "incorporate_child_on_error". +Axiom ethereum_muir_glacier_vm_imports_incorporate_child_on_success : + IsImported globals "ethereum.muir_glacier.vm" "incorporate_child_on_success". -Axiom ethereum_muir_glacier_vm_exceptions_imports : - AreImported globals "ethereum.muir_glacier.vm.exceptions" [ "Revert"; "WriteInStaticContext" ]. +Axiom ethereum_muir_glacier_vm_exceptions_imports_Revert : + IsImported globals "ethereum.muir_glacier.vm.exceptions" "Revert". +Axiom ethereum_muir_glacier_vm_exceptions_imports_WriteInStaticContext : + IsImported globals "ethereum.muir_glacier.vm.exceptions" "WriteInStaticContext". -Axiom ethereum_muir_glacier_vm_gas_imports : - AreImported globals "ethereum.muir_glacier.vm.gas" [ "GAS_CALL"; "GAS_CALL_VALUE"; "GAS_CREATE"; "GAS_KECCAK256_WORD"; "GAS_NEW_ACCOUNT"; "GAS_SELF_DESTRUCT"; "GAS_SELF_DESTRUCT_NEW_ACCOUNT"; "GAS_ZERO"; "REFUND_SELF_DESTRUCT"; "calculate_gas_extend_memory"; "calculate_message_call_gas"; "charge_gas"; "max_message_call_gas" ]. +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_CALL : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_CALL". +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_CALL_VALUE : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_CALL_VALUE". +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_CREATE : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_CREATE". +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_KECCAK256_WORD : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_KECCAK256_WORD". +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_NEW_ACCOUNT : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_NEW_ACCOUNT". +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_SELF_DESTRUCT : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_SELF_DESTRUCT". +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_SELF_DESTRUCT_NEW_ACCOUNT : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_SELF_DESTRUCT_NEW_ACCOUNT". +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_ZERO : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_ZERO". +Axiom ethereum_muir_glacier_vm_gas_imports_REFUND_SELF_DESTRUCT : + IsImported globals "ethereum.muir_glacier.vm.gas" "REFUND_SELF_DESTRUCT". +Axiom ethereum_muir_glacier_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.muir_glacier.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_muir_glacier_vm_gas_imports_calculate_message_call_gas : + IsImported globals "ethereum.muir_glacier.vm.gas" "calculate_message_call_gas". +Axiom ethereum_muir_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.muir_glacier.vm.gas" "charge_gas". +Axiom ethereum_muir_glacier_vm_gas_imports_max_message_call_gas : + IsImported globals "ethereum.muir_glacier.vm.gas" "max_message_call_gas". -Axiom ethereum_muir_glacier_vm_memory_imports : - AreImported globals "ethereum.muir_glacier.vm.memory" [ "memory_read_bytes"; "memory_write" ]. +Axiom ethereum_muir_glacier_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.muir_glacier.vm.memory" "memory_read_bytes". +Axiom ethereum_muir_glacier_vm_memory_imports_memory_write : + IsImported globals "ethereum.muir_glacier.vm.memory" "memory_write". -Axiom ethereum_muir_glacier_vm_stack_imports : - AreImported globals "ethereum.muir_glacier.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_muir_glacier_vm_stack_imports_pop : + IsImported globals "ethereum.muir_glacier.vm.stack" "pop". +Axiom ethereum_muir_glacier_vm_stack_imports_push : + IsImported globals "ethereum.muir_glacier.vm.stack" "push". Definition generic_create : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -57,7 +111,8 @@ Definition generic_create : Value.t -> Value.t -> M := Core logic used by the `CREATE*` family of opcodes. " in (* At stmt: unsupported node type: ImportFrom *) - let create_message_gas := + let _ := M.assign_local (| + "create_message_gas" , M.call (| M.get_name (| globals, "max_message_call_gas" |), make_list [ @@ -70,7 +125,8 @@ Definition generic_create : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.assign_op (| BinOp.sub, M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), @@ -88,9 +144,12 @@ Definition generic_create : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), Constant.bytes "" |) in - let sender_address := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in - let sender := + let _ := M.assign_local (| + "sender_address" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + |) in + let _ := M.assign_local (| + "sender" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -98,7 +157,8 @@ Definition generic_create : Value.t -> Value.t -> M := M.get_name (| globals, "sender_address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -209,7 +269,8 @@ Definition generic_create : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let call_data := + let _ := M.assign_local (| + "call_data" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -218,7 +279,8 @@ Definition generic_create : Value.t -> Value.t -> M := M.get_name (| globals, "memory_size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "increment_nonce" |), make_list [ @@ -227,13 +289,16 @@ Definition generic_create : Value.t -> Value.t -> M := ], make_dict [] |) in - let child_message := + let _ := M.assign_local (| + "child_message" , M.call (| M.get_name (| globals, "Message" |), make_list [], make_dict [] - |) in - let child_evm := + |) + |) in + let _ := M.assign_local (| + "child_evm" , M.call (| M.get_name (| globals, "process_create_message" |), make_list [ @@ -241,7 +306,8 @@ Definition generic_create : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -318,31 +384,38 @@ Definition create : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let endowment := + let _ := M.assign_local (| + "endowment" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_size := + |) + |) in + let _ := M.assign_local (| + "memory_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -352,7 +425,8 @@ Definition create : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -372,7 +446,8 @@ Definition create : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let contract_address := + let _ := M.assign_local (| + "contract_address" , M.call (| M.get_name (| globals, "compute_contract_address" |), make_list [ @@ -387,7 +462,8 @@ Definition create : Value.t -> Value.t -> M := |), "nonce" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "generic_create" |), make_list [ @@ -420,31 +496,38 @@ Definition create2 : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let endowment := + let _ := M.assign_local (| + "endowment" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_size := + |) + |) in + let _ := M.assign_local (| + "memory_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let salt := + |) + |) in + let _ := M.assign_local (| + "salt" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -455,8 +538,10 @@ Definition create2 : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -466,8 +551,10 @@ Definition create2 : Value.t -> Value.t -> M := ] ], make_dict [] - |) in - let call_data_words := + |) + |) in + let _ := M.assign_local (| + "call_data_words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -483,7 +570,8 @@ Definition create2 : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -509,7 +597,8 @@ Definition create2 : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let contract_address := + let _ := M.assign_local (| + "contract_address" , M.call (| M.get_name (| globals, "compute_create2_contract_address" |), make_list [ @@ -526,7 +615,8 @@ Definition create2 : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "generic_create" |), make_list [ @@ -556,23 +646,28 @@ Definition return_ : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let memory_start_position := + let _ := M.assign_local (| + "memory_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_size := + |) + |) in + let _ := M.assign_local (| + "memory_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -582,7 +677,8 @@ Definition return_ : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -671,7 +767,8 @@ Definition generic_call : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let call_data := + let _ := M.assign_local (| + "call_data" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -680,8 +777,10 @@ Definition generic_call : Value.t -> Value.t -> M := M.get_name (| globals, "memory_input_size" |) ], make_dict [] - |) in - let code := + |) + |) in + let _ := M.assign_local (| + "code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -689,14 +788,18 @@ Definition generic_call : Value.t -> Value.t -> M := M.get_name (| globals, "code_address" |) ], make_dict [] - |), "code" |) in - let child_message := + |), "code" |) + |) in + let _ := M.assign_local (| + "child_message" , M.call (| M.get_name (| globals, "Message" |), make_list [], make_dict [] - |) in - let child_evm := + |) + |) in + let _ := M.assign_local (| + "child_evm" , M.call (| M.get_name (| globals, "process_message" |), make_list [ @@ -704,7 +807,8 @@ Definition generic_call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -768,7 +872,8 @@ Definition generic_call : Value.t -> Value.t -> M := |) in M.pure Constant.None_ )) |) in - let actual_output_size := + let _ := M.assign_local (| + "actual_output_size" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -788,7 +893,8 @@ Definition generic_call : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -816,7 +922,8 @@ Definition call : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -829,8 +936,10 @@ Definition call : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let to := + |) + |) in + let _ := M.assign_local (| + "to" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -843,48 +952,60 @@ Definition call : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -895,8 +1016,10 @@ Definition call : Value.t -> Value.t -> M := ] ], make_dict [] - |) in - let create_gas_cost := + |) + |) in + let _ := M.assign_local (| + "create_gas_cost" , (* if *) M.if_then_else (| BoolOp.or (| @@ -927,8 +1050,10 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "GAS_NEW_ACCOUNT" |) - )) |) in - let transfer_gas_cost := + )) |) + |) in + let _ := M.assign_local (| + "transfer_gas_cost" , (* if *) M.if_then_else (| Compare.eq (| @@ -947,8 +1072,10 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "GAS_CALL_VALUE" |) - )) |) in - let message_call_gas := + )) |) + |) in + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -971,7 +1098,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1013,7 +1141,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let sender_balance := + let _ := M.assign_local (| + "sender_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1021,7 +1150,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := (* if *) M.if_then_else (| @@ -1095,7 +1225,8 @@ Definition callcode : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -1108,8 +1239,10 @@ Definition callcode : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let code_address := + |) + |) in + let _ := M.assign_local (| + "code_address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1122,50 +1255,64 @@ Definition callcode : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let to := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "to" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1176,8 +1323,10 @@ Definition callcode : Value.t -> Value.t -> M := ] ], make_dict [] - |) in - let transfer_gas_cost := + |) + |) in + let _ := M.assign_local (| + "transfer_gas_cost" , (* if *) M.if_then_else (| Compare.eq (| @@ -1196,8 +1345,10 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "GAS_CALL_VALUE" |) - )) |) in - let message_call_gas := + )) |) + |) in + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -1217,7 +1368,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1237,7 +1389,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let sender_balance := + let _ := M.assign_local (| + "sender_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1245,7 +1398,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := (* if *) M.if_then_else (| @@ -1319,7 +1473,8 @@ Definition selfdestruct : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let beneficiary := + let _ := M.assign_local (| + "beneficiary" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1332,9 +1487,12 @@ Definition selfdestruct : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let gas_cost := - M.get_name (| globals, "GAS_SELF_DESTRUCT" |) in + |) + |) in + let _ := M.assign_local (| + "gas_cost" , + M.get_name (| globals, "GAS_SELF_DESTRUCT" |) + |) in let _ := (* if *) M.if_then_else (| @@ -1363,20 +1521,28 @@ Definition selfdestruct : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let gas_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "gas_cost", M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) - M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let originator := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in - let refunded_accounts := - M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in - let parent_evm := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "parent_evm" |) in + let _ := M.assign_local (| + "originator" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + |) in + let _ := M.assign_local (| + "refunded_accounts" , + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) + |) in + let _ := M.assign_local (| + "parent_evm" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "parent_evm" |) + |) in let _ := M.while (| Compare.is_not (| @@ -1391,8 +1557,10 @@ Definition selfdestruct : Value.t -> Value.t -> M := ], make_dict [] |) in - let parent_evm := - M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in + let _ := M.assign_local (| + "parent_evm" , + M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -1434,7 +1602,8 @@ Definition selfdestruct : Value.t -> Value.t -> M := ], make_dict [] |) in - let beneficiary_balance := + let _ := M.assign_local (| + "beneficiary_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1442,8 +1611,10 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_name (| globals, "beneficiary" |) ], make_dict [] - |), "balance" |) in - let originator_balance := + |), "balance" |) + |) in + let _ := M.assign_local (| + "originator_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1451,7 +1622,8 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_name (| globals, "originator" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -1529,7 +1701,8 @@ Definition delegatecall : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -1542,8 +1715,10 @@ Definition delegatecall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let code_address := + |) + |) in + let _ := M.assign_local (| + "code_address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1556,40 +1731,50 @@ Definition delegatecall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1600,8 +1785,10 @@ Definition delegatecall : Value.t -> Value.t -> M := ] ], make_dict [] - |) in - let message_call_gas := + |) + |) in + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -1624,7 +1811,8 @@ Definition delegatecall : Value.t -> Value.t -> M := M.get_name (| globals, "GAS_CALL" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1680,7 +1868,8 @@ Definition staticcall : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -1693,8 +1882,10 @@ Definition staticcall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let to := + |) + |) in + let _ := M.assign_local (| + "to" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1707,40 +1898,50 @@ Definition staticcall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1751,8 +1952,10 @@ Definition staticcall : Value.t -> Value.t -> M := ] ], make_dict [] - |) in - let message_call_gas := + |) + |) in + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -1775,7 +1978,8 @@ Definition staticcall : Value.t -> Value.t -> M := M.get_name (| globals, "GAS_CALL" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1837,23 +2041,28 @@ Definition revert : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1863,7 +2072,8 @@ Definition revert : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1880,7 +2090,8 @@ Definition revert : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let output := + let _ := M.assign_local (| + "output" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -1889,7 +2100,8 @@ Definition revert : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| diff --git a/CoqOfPython/ethereum/muir_glacier/vm/interpreter.v b/CoqOfPython/ethereum/muir_glacier/vm/interpreter.v index 01f6a58..03f7f66 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/interpreter.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/interpreter.v @@ -17,50 +17,110 @@ Introduction A straightforward interpreter that executes EVM code. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Iterable"; "Optional"; "Set"; "Tuple" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. - -Axiom ethereum_trace_imports : - AreImported globals "ethereum.trace" [ "EvmStop"; "OpEnd"; "OpException"; "OpStart"; "PrecompileEnd"; "PrecompileStart"; "TransactionEnd"; "evm_trace" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_muir_glacier_blocks_imports : - AreImported globals "ethereum.muir_glacier.blocks" [ "Log" ]. - -Axiom ethereum_muir_glacier_fork_types_imports : - AreImported globals "ethereum.muir_glacier.fork_types" [ "Address" ]. - -Axiom ethereum_muir_glacier_state_imports : - AreImported globals "ethereum.muir_glacier.state" [ "account_exists_and_is_empty"; "account_has_code_or_nonce"; "begin_transaction"; "commit_transaction"; "destroy_storage"; "increment_nonce"; "mark_account_created"; "move_ether"; "rollback_transaction"; "set_code"; "touch_account" ]. - -Axiom ethereum_muir_glacier_vm_imports : - AreImported globals "ethereum.muir_glacier.vm" [ "Message" ]. - -Axiom ethereum_muir_glacier_vm_gas_imports : - AreImported globals "ethereum.muir_glacier.vm.gas" [ "GAS_CODE_DEPOSIT"; "charge_gas" ]. - -Axiom ethereum_muir_glacier_vm_precompiled_contracts_mapping_imports : - AreImported globals "ethereum.muir_glacier.vm.precompiled_contracts.mapping" [ "PRE_COMPILED_CONTRACTS" ]. - -Axiom ethereum_muir_glacier_vm_imports : - AreImported globals "ethereum.muir_glacier.vm" [ "Environment"; "Evm" ]. - -Axiom ethereum_muir_glacier_vm_exceptions_imports : - AreImported globals "ethereum.muir_glacier.vm.exceptions" [ "AddressCollision"; "ExceptionalHalt"; "InvalidOpcode"; "OutOfGasError"; "Revert"; "StackDepthLimitError" ]. - -Axiom ethereum_muir_glacier_vm_instructions_imports : - AreImported globals "ethereum.muir_glacier.vm.instructions" [ "Ops"; "op_implementation" ]. - -Axiom ethereum_muir_glacier_vm_runtime_imports : - AreImported globals "ethereum.muir_glacier.vm.runtime" [ "get_valid_jump_destinations" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_Iterable : + IsImported globals "typing" "Iterable". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_trace_imports_EvmStop : + IsImported globals "ethereum.trace" "EvmStop". +Axiom ethereum_trace_imports_OpEnd : + IsImported globals "ethereum.trace" "OpEnd". +Axiom ethereum_trace_imports_OpException : + IsImported globals "ethereum.trace" "OpException". +Axiom ethereum_trace_imports_OpStart : + IsImported globals "ethereum.trace" "OpStart". +Axiom ethereum_trace_imports_PrecompileEnd : + IsImported globals "ethereum.trace" "PrecompileEnd". +Axiom ethereum_trace_imports_PrecompileStart : + IsImported globals "ethereum.trace" "PrecompileStart". +Axiom ethereum_trace_imports_TransactionEnd : + IsImported globals "ethereum.trace" "TransactionEnd". +Axiom ethereum_trace_imports_evm_trace : + IsImported globals "ethereum.trace" "evm_trace". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_muir_glacier_blocks_imports_Log : + IsImported globals "ethereum.muir_glacier.blocks" "Log". + +Axiom ethereum_muir_glacier_fork_types_imports_Address : + IsImported globals "ethereum.muir_glacier.fork_types" "Address". + +Axiom ethereum_muir_glacier_state_imports_account_exists_and_is_empty : + IsImported globals "ethereum.muir_glacier.state" "account_exists_and_is_empty". +Axiom ethereum_muir_glacier_state_imports_account_has_code_or_nonce : + IsImported globals "ethereum.muir_glacier.state" "account_has_code_or_nonce". +Axiom ethereum_muir_glacier_state_imports_begin_transaction : + IsImported globals "ethereum.muir_glacier.state" "begin_transaction". +Axiom ethereum_muir_glacier_state_imports_commit_transaction : + IsImported globals "ethereum.muir_glacier.state" "commit_transaction". +Axiom ethereum_muir_glacier_state_imports_destroy_storage : + IsImported globals "ethereum.muir_glacier.state" "destroy_storage". +Axiom ethereum_muir_glacier_state_imports_increment_nonce : + IsImported globals "ethereum.muir_glacier.state" "increment_nonce". +Axiom ethereum_muir_glacier_state_imports_mark_account_created : + IsImported globals "ethereum.muir_glacier.state" "mark_account_created". +Axiom ethereum_muir_glacier_state_imports_move_ether : + IsImported globals "ethereum.muir_glacier.state" "move_ether". +Axiom ethereum_muir_glacier_state_imports_rollback_transaction : + IsImported globals "ethereum.muir_glacier.state" "rollback_transaction". +Axiom ethereum_muir_glacier_state_imports_set_code : + IsImported globals "ethereum.muir_glacier.state" "set_code". +Axiom ethereum_muir_glacier_state_imports_touch_account : + IsImported globals "ethereum.muir_glacier.state" "touch_account". + +Axiom ethereum_muir_glacier_vm_imports_Message : + IsImported globals "ethereum.muir_glacier.vm" "Message". + +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_CODE_DEPOSIT : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_CODE_DEPOSIT". +Axiom ethereum_muir_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.muir_glacier.vm.gas" "charge_gas". + +Axiom ethereum_muir_glacier_vm_precompiled_contracts_mapping_imports_PRE_COMPILED_CONTRACTS : + IsImported globals "ethereum.muir_glacier.vm.precompiled_contracts.mapping" "PRE_COMPILED_CONTRACTS". + +Axiom ethereum_muir_glacier_vm_imports_Environment : + IsImported globals "ethereum.muir_glacier.vm" "Environment". +Axiom ethereum_muir_glacier_vm_imports_Evm : + IsImported globals "ethereum.muir_glacier.vm" "Evm". + +Axiom ethereum_muir_glacier_vm_exceptions_imports_AddressCollision : + IsImported globals "ethereum.muir_glacier.vm.exceptions" "AddressCollision". +Axiom ethereum_muir_glacier_vm_exceptions_imports_ExceptionalHalt : + IsImported globals "ethereum.muir_glacier.vm.exceptions" "ExceptionalHalt". +Axiom ethereum_muir_glacier_vm_exceptions_imports_InvalidOpcode : + IsImported globals "ethereum.muir_glacier.vm.exceptions" "InvalidOpcode". +Axiom ethereum_muir_glacier_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.muir_glacier.vm.exceptions" "OutOfGasError". +Axiom ethereum_muir_glacier_vm_exceptions_imports_Revert : + IsImported globals "ethereum.muir_glacier.vm.exceptions" "Revert". +Axiom ethereum_muir_glacier_vm_exceptions_imports_StackDepthLimitError : + IsImported globals "ethereum.muir_glacier.vm.exceptions" "StackDepthLimitError". + +Axiom ethereum_muir_glacier_vm_instructions_imports_Ops : + IsImported globals "ethereum.muir_glacier.vm.instructions" "Ops". +Axiom ethereum_muir_glacier_vm_instructions_imports_op_implementation : + IsImported globals "ethereum.muir_glacier.vm.instructions" "op_implementation". + +Axiom ethereum_muir_glacier_vm_runtime_imports_get_valid_jump_destinations : + IsImported globals "ethereum.muir_glacier.vm.runtime" "get_valid_jump_destinations". Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -121,7 +181,8 @@ Definition process_message_call : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let is_collision := + let _ := M.assign_local (| + "is_collision" , M.call (| M.get_name (| globals, "account_has_code_or_nonce" |), make_list [ @@ -129,7 +190,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "message" |), "current_target" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -181,7 +243,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "process_create_message" |), make_list [ @@ -189,13 +252,15 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "process_message" |), make_list [ @@ -203,7 +268,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -250,46 +316,61 @@ Definition process_message_call : Value.t -> Value.t -> M := (* then *) ltac:(M.monadic ( (* At stmt: unsupported node type: AnnAssign *) - let accounts_to_delete := + let _ := M.assign_local (| + "accounts_to_delete" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let touched_accounts := + |) + |) in + let _ := M.assign_local (| + "touched_accounts" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let refund_counter := + |) + |) in + let _ := M.assign_local (| + "refund_counter" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let logs := - M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in - let accounts_to_delete := - M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in - let touched_accounts := - M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |) in - let refund_counter := + let _ := M.assign_local (| + "logs" , + M.get_field (| M.get_name (| globals, "evm" |), "logs" |) + |) in + let _ := M.assign_local (| + "accounts_to_delete" , + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) + |) in + let _ := M.assign_local (| + "touched_accounts" , + M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |) + |) in + let _ := M.assign_local (| + "refund_counter" , M.call (| M.get_name (| globals, "U256" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in - let tx_end := + let _ := M.assign_local (| + "tx_end" , M.call (| M.get_name (| globals, "TransactionEnd" |), make_list [ @@ -301,7 +382,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "error" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "evm_trace" |), make_list [ @@ -368,7 +450,8 @@ Definition process_create_message : Value.t -> Value.t -> M := ], make_dict [] |) in - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "process_message" |), make_list [ @@ -376,16 +459,20 @@ Definition process_create_message : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), (* then *) ltac:(M.monadic ( - let contract_code := - M.get_field (| M.get_name (| globals, "evm" |), "output" |) in - let contract_code_gas := + let _ := M.assign_local (| + "contract_code" , + M.get_field (| M.get_name (| globals, "evm" |), "output" |) + |) in + let _ := M.assign_local (| + "contract_code_gas" , BinOp.mult (| M.call (| M.get_name (| globals, "len" |), @@ -395,7 +482,8 @@ Definition process_create_message : Value.t -> Value.t -> M := make_dict [] |), M.get_name (| globals, "GAS_CODE_DEPOSIT" |) - |) in + |) + |) in (* At stmt: unsupported node type: Try *) M.pure Constant.None_ (* else *) @@ -497,7 +585,8 @@ Definition process_message : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "execute_code" |), make_list [ @@ -505,7 +594,8 @@ Definition process_message : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -554,22 +644,28 @@ Definition execute_code : Value.t -> Value.t -> M := evm: `ethereum.vm.EVM` Items containing execution specific objects " in - let code := - M.get_field (| M.get_name (| globals, "message" |), "code" |) in - let valid_jump_destinations := + let _ := M.assign_local (| + "code" , + M.get_field (| M.get_name (| globals, "message" |), "code" |) + |) in + let _ := M.assign_local (| + "valid_jump_destinations" , M.call (| M.get_name (| globals, "get_valid_jump_destinations" |), make_list [ M.get_name (| globals, "code" |) ], make_dict [] - |) in - let evm := + |) + |) in + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "Evm" |), make_list [], make_dict [] - |) in + |) + |) in (* At stmt: unsupported node type: Try *) let _ := M.return_ (| M.get_name (| globals, "evm" |) diff --git a/CoqOfPython/ethereum/muir_glacier/vm/memory.v b/CoqOfPython/ethereum/muir_glacier/vm/memory.v index ebeaeaf..2bdcef4 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/memory.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/memory.v @@ -17,11 +17,15 @@ Introduction EVM memory operations. ". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "right_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_right_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "right_pad_zero_bytes". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". Definition memory_write : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/__init__.v index 4c9fbd4..714a0bb 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/__init__.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/__init__.v @@ -18,8 +18,8 @@ Addresses of precompiled contracts and mappings to their implementations. ". -Axiom ethereum_muir_glacier_utils_hexadecimal_imports : - AreImported globals "ethereum.muir_glacier.utils.hexadecimal" [ "hex_to_address" ]. +Axiom ethereum_muir_glacier_utils_hexadecimal_imports_hex_to_address : + IsImported globals "ethereum.muir_glacier.utils.hexadecimal" "hex_to_address". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS"; Constant.str "MODEXP_ADDRESS"; Constant.str "ALT_BN128_ADD_ADDRESS"; Constant.str "ALT_BN128_MUL_ADDRESS"; Constant.str "ALT_BN128_PAIRING_CHECK_ADDRESS"; Constant.str "BLAKE2F_ADDRESS" ] diff --git a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/alt_bn128.v index 56b7599..e709832 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/alt_bn128.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/alt_bn128.v @@ -17,26 +17,42 @@ Introduction Implementation of the ALT_BN128 precompiled contracts. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_alt_bn128_imports : - AreImported globals "ethereum.crypto.alt_bn128" [ "ALT_BN128_CURVE_ORDER"; "ALT_BN128_PRIME"; "BNF"; "BNF2"; "BNF12"; "BNP"; "BNP2"; "pairing" ]. +Axiom ethereum_crypto_alt_bn128_imports_ALT_BN128_CURVE_ORDER : + IsImported globals "ethereum.crypto.alt_bn128" "ALT_BN128_CURVE_ORDER". +Axiom ethereum_crypto_alt_bn128_imports_ALT_BN128_PRIME : + IsImported globals "ethereum.crypto.alt_bn128" "ALT_BN128_PRIME". +Axiom ethereum_crypto_alt_bn128_imports_BNF : + IsImported globals "ethereum.crypto.alt_bn128" "BNF". +Axiom ethereum_crypto_alt_bn128_imports_BNF2 : + IsImported globals "ethereum.crypto.alt_bn128" "BNF2". +Axiom ethereum_crypto_alt_bn128_imports_BNF12 : + IsImported globals "ethereum.crypto.alt_bn128" "BNF12". +Axiom ethereum_crypto_alt_bn128_imports_BNP : + IsImported globals "ethereum.crypto.alt_bn128" "BNP". +Axiom ethereum_crypto_alt_bn128_imports_BNP2 : + IsImported globals "ethereum.crypto.alt_bn128" "BNP2". +Axiom ethereum_crypto_alt_bn128_imports_pairing : + IsImported globals "ethereum.crypto.alt_bn128" "pairing". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_muir_glacier_vm_imports : - AreImported globals "ethereum.muir_glacier.vm" [ "Evm" ]. +Axiom ethereum_muir_glacier_vm_imports_Evm : + IsImported globals "ethereum.muir_glacier.vm" "Evm". -Axiom ethereum_muir_glacier_vm_gas_imports : - AreImported globals "ethereum.muir_glacier.vm.gas" [ "charge_gas" ]. +Axiom ethereum_muir_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.muir_glacier.vm.gas" "charge_gas". -Axiom ethereum_muir_glacier_vm_memory_imports : - AreImported globals "ethereum.muir_glacier.vm.memory" [ "buffer_read" ]. +Axiom ethereum_muir_glacier_vm_memory_imports_buffer_read : + IsImported globals "ethereum.muir_glacier.vm.memory" "buffer_read". -Axiom ethereum_muir_glacier_vm_exceptions_imports : - AreImported globals "ethereum.muir_glacier.vm.exceptions" [ "OutOfGasError" ]. +Axiom ethereum_muir_glacier_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.muir_glacier.vm.exceptions" "OutOfGasError". Definition alt_bn128_add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -49,8 +65,10 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -65,7 +83,8 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := ], make_dict [] |) in - let x0_bytes := + let _ := M.assign_local (| + "x0_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -86,16 +105,20 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let x0_value := + |) + |) in + let _ := M.assign_local (| + "x0_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "x0_bytes" |) ], make_dict [] - |) in - let y0_bytes := + |) + |) in + let _ := M.assign_local (| + "y0_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -116,16 +139,20 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y0_value := + |) + |) in + let _ := M.assign_local (| + "y0_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "y0_bytes" |) ], make_dict [] - |) in - let x1_bytes := + |) + |) in + let _ := M.assign_local (| + "x1_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -146,16 +173,20 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let x1_value := + |) + |) in + let _ := M.assign_local (| + "x1_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "x1_bytes" |) ], make_dict [] - |) in - let y1_bytes := + |) + |) in + let _ := M.assign_local (| + "y1_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -176,15 +207,18 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y1_value := + |) + |) in + let _ := M.assign_local (| + "y1_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "y1_bytes" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "i" |), @@ -212,11 +246,13 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := )) |) in (* At stmt: unsupported node type: Try *) - let p := + let _ := M.assign_local (| + "p" , BinOp.add (| M.get_name (| globals, "p0" |), M.get_name (| globals, "p1" |) - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), BinOp.add (| @@ -245,8 +281,10 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -261,7 +299,8 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := ], make_dict [] |) in - let x0_bytes := + let _ := M.assign_local (| + "x0_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -282,16 +321,20 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let x0_value := + |) + |) in + let _ := M.assign_local (| + "x0_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "x0_bytes" |) ], make_dict [] - |) in - let y0_bytes := + |) + |) in + let _ := M.assign_local (| + "y0_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -312,16 +355,20 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y0_value := + |) + |) in + let _ := M.assign_local (| + "y0_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "y0_bytes" |) ], make_dict [] - |) in - let n := + |) + |) in + let _ := M.assign_local (| + "n" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -348,7 +395,8 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "i" |), @@ -376,14 +424,16 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := )) |) in (* At stmt: unsupported node type: Try *) - let p := + let _ := M.assign_local (| + "p" , M.call (| M.get_field (| M.get_name (| globals, "p0" |), "mul_by" |), make_list [ M.get_name (| globals, "n" |) ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), BinOp.add (| @@ -412,8 +462,10 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -467,14 +519,16 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), make_list [ Constant.int 1 ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "i" |), @@ -495,8 +549,10 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let values := - make_list [] in + let _ := M.assign_local (| + "values" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "j" |), @@ -508,7 +564,8 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -541,7 +598,8 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -644,7 +702,8 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , BinOp.mult (| M.get_name (| globals, "result" |), M.call (| @@ -655,7 +714,8 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/blake2f.v b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/blake2f.v index 506c825..4a75fc0 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/blake2f.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/blake2f.v @@ -17,20 +17,22 @@ Introduction Implementation of the `Blake2` precompiled contract. ". -Axiom ethereum_crypto_blake2_imports : - AreImported globals "ethereum.crypto.blake2" [ "Blake2b" ]. +Axiom ethereum_crypto_blake2_imports_Blake2b : + IsImported globals "ethereum.crypto.blake2" "Blake2b". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_muir_glacier_vm_imports : - AreImported globals "ethereum.muir_glacier.vm" [ "Evm" ]. +Axiom ethereum_muir_glacier_vm_imports_Evm : + IsImported globals "ethereum.muir_glacier.vm" "Evm". -Axiom ethereum_muir_glacier_vm_gas_imports : - AreImported globals "ethereum.muir_glacier.vm.gas" [ "GAS_BLAKE2_PER_ROUND"; "charge_gas" ]. +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_BLAKE2_PER_ROUND : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_BLAKE2_PER_ROUND". +Axiom ethereum_muir_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.muir_glacier.vm.gas" "charge_gas". -Axiom ethereum_muir_glacier_vm_exceptions_imports : - AreImported globals "ethereum.muir_glacier.vm.exceptions" [ "InvalidParameter" ]. +Axiom ethereum_muir_glacier_vm_exceptions_imports_InvalidParameter : + IsImported globals "ethereum.muir_glacier.vm.exceptions" "InvalidParameter". Definition blake2f : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -43,8 +45,10 @@ Definition blake2f : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -62,12 +66,14 @@ Definition blake2f : Value.t -> Value.t -> M := ], make_dict [] |) in - let blake2b := + let _ := M.assign_local (| + "blake2b" , M.call (| M.get_name (| globals, "Blake2b" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "rounds" |); M.get_name (| globals, "h" |); M.get_name (| globals, "m" |); M.get_name (| globals, "t_0" |); M.get_name (| globals, "t_1" |); M.get_name (| globals, "f" |) ], M.call (| diff --git a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/ecrecover.v index 1adae4d..8312694 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/ecrecover.v @@ -17,26 +17,32 @@ Introduction Implementation of the ECRECOVER precompiled contract. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_crypto_elliptic_curve_imports : - AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. +Axiom ethereum_crypto_elliptic_curve_imports_SECP256K1N : + IsImported globals "ethereum.crypto.elliptic_curve" "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_imports_secp256k1_recover : + IsImported globals "ethereum.crypto.elliptic_curve" "secp256k1_recover". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_left_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "left_pad_zero_bytes". -Axiom ethereum_muir_glacier_vm_imports : - AreImported globals "ethereum.muir_glacier.vm" [ "Evm" ]. +Axiom ethereum_muir_glacier_vm_imports_Evm : + IsImported globals "ethereum.muir_glacier.vm" "Evm". -Axiom ethereum_muir_glacier_vm_gas_imports : - AreImported globals "ethereum.muir_glacier.vm.gas" [ "GAS_ECRECOVER"; "charge_gas" ]. +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_ECRECOVER : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_ECRECOVER". +Axiom ethereum_muir_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.muir_glacier.vm.gas" "charge_gas". -Axiom ethereum_muir_glacier_vm_memory_imports : - AreImported globals "ethereum.muir_glacier.vm.memory" [ "buffer_read" ]. +Axiom ethereum_muir_glacier_vm_memory_imports_buffer_read : + IsImported globals "ethereum.muir_glacier.vm.memory" "buffer_read". Definition ecrecover : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -50,8 +56,10 @@ Definition ecrecover : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -60,7 +68,8 @@ Definition ecrecover : Value.t -> Value.t -> M := ], make_dict [] |) in - let message_hash_bytes := + let _ := M.assign_local (| + "message_hash_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -81,16 +90,20 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let message_hash := + |) + |) in + let _ := M.assign_local (| + "message_hash" , M.call (| M.get_name (| globals, "Hash32" |), make_list [ M.get_name (| globals, "message_hash_bytes" |) ], make_dict [] - |) in - let v := + |) + |) in + let _ := M.assign_local (| + "v" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -117,8 +130,10 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let r := + |) + |) in + let _ := M.assign_local (| + "r" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -145,8 +160,10 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let s := + |) + |) in + let _ := M.assign_local (| + "s" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -173,7 +190,8 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -250,7 +268,8 @@ Definition ecrecover : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: Try *) - let address := + let _ := M.assign_local (| + "address" , M.slice (| M.call (| M.get_name (| globals, "keccak256" |), @@ -262,8 +281,10 @@ Definition ecrecover : Value.t -> Value.t -> M := Constant.int 12, Constant.int 32, Constant.None_ - |) in - let padded_address := + |) + |) in + let _ := M.assign_local (| + "padded_address" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -271,7 +292,8 @@ Definition ecrecover : Value.t -> Value.t -> M := Constant.int 32 ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.get_name (| globals, "padded_address" |) diff --git a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/identity.v index e6ee61a..f2eb008 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/identity.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/identity.v @@ -17,17 +17,21 @@ Introduction Implementation of the `IDENTITY` precompiled contract. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_muir_glacier_vm_imports : - AreImported globals "ethereum.muir_glacier.vm" [ "Evm" ]. +Axiom ethereum_muir_glacier_vm_imports_Evm : + IsImported globals "ethereum.muir_glacier.vm" "Evm". -Axiom ethereum_muir_glacier_vm_gas_imports : - AreImported globals "ethereum.muir_glacier.vm.gas" [ "GAS_IDENTITY"; "GAS_IDENTITY_WORD"; "charge_gas" ]. +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_IDENTITY : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_IDENTITY". +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_IDENTITY_WORD : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_IDENTITY_WORD". +Axiom ethereum_muir_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.muir_glacier.vm.gas" "charge_gas". Definition identity : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -40,9 +44,12 @@ Definition identity : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let word_count := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "word_count" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -64,7 +71,8 @@ Definition identity : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ diff --git a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/mapping.v index ffd941a..e59e8d5 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/mapping.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/mapping.v @@ -17,34 +17,56 @@ Introduction Mapping of precompiled contracts their implementations. ". -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict" ]. - -Axiom ethereum_muir_glacier_fork_types_imports : - AreImported globals "ethereum.muir_glacier.fork_types" [ "Address" ]. - -Axiom ethereum_muir_glacier_vm_precompiled_contracts_imports : - AreImported globals "ethereum.muir_glacier.vm.precompiled_contracts" [ "ALT_BN128_ADD_ADDRESS"; "ALT_BN128_MUL_ADDRESS"; "ALT_BN128_PAIRING_CHECK_ADDRESS"; "BLAKE2F_ADDRESS"; "ECRECOVER_ADDRESS"; "IDENTITY_ADDRESS"; "MODEXP_ADDRESS"; "RIPEMD160_ADDRESS"; "SHA256_ADDRESS" ]. - -Axiom ethereum_muir_glacier_vm_precompiled_contracts_alt_bn128_imports : - AreImported globals "ethereum.muir_glacier.vm.precompiled_contracts.alt_bn128" [ "alt_bn128_add"; "alt_bn128_mul"; "alt_bn128_pairing_check" ]. - -Axiom ethereum_muir_glacier_vm_precompiled_contracts_blake2f_imports : - AreImported globals "ethereum.muir_glacier.vm.precompiled_contracts.blake2f" [ "blake2f" ]. - -Axiom ethereum_muir_glacier_vm_precompiled_contracts_ecrecover_imports : - AreImported globals "ethereum.muir_glacier.vm.precompiled_contracts.ecrecover" [ "ecrecover" ]. - -Axiom ethereum_muir_glacier_vm_precompiled_contracts_identity_imports : - AreImported globals "ethereum.muir_glacier.vm.precompiled_contracts.identity" [ "identity" ]. - -Axiom ethereum_muir_glacier_vm_precompiled_contracts_modexp_imports : - AreImported globals "ethereum.muir_glacier.vm.precompiled_contracts.modexp" [ "modexp" ]. - -Axiom ethereum_muir_glacier_vm_precompiled_contracts_ripemd160_imports : - AreImported globals "ethereum.muir_glacier.vm.precompiled_contracts.ripemd160" [ "ripemd160" ]. - -Axiom ethereum_muir_glacier_vm_precompiled_contracts_sha256_imports : - AreImported globals "ethereum.muir_glacier.vm.precompiled_contracts.sha256" [ "sha256" ]. +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". + +Axiom ethereum_muir_glacier_fork_types_imports_Address : + IsImported globals "ethereum.muir_glacier.fork_types" "Address". + +Axiom ethereum_muir_glacier_vm_precompiled_contracts_imports_ALT_BN128_ADD_ADDRESS : + IsImported globals "ethereum.muir_glacier.vm.precompiled_contracts" "ALT_BN128_ADD_ADDRESS". +Axiom ethereum_muir_glacier_vm_precompiled_contracts_imports_ALT_BN128_MUL_ADDRESS : + IsImported globals "ethereum.muir_glacier.vm.precompiled_contracts" "ALT_BN128_MUL_ADDRESS". +Axiom ethereum_muir_glacier_vm_precompiled_contracts_imports_ALT_BN128_PAIRING_CHECK_ADDRESS : + IsImported globals "ethereum.muir_glacier.vm.precompiled_contracts" "ALT_BN128_PAIRING_CHECK_ADDRESS". +Axiom ethereum_muir_glacier_vm_precompiled_contracts_imports_BLAKE2F_ADDRESS : + IsImported globals "ethereum.muir_glacier.vm.precompiled_contracts" "BLAKE2F_ADDRESS". +Axiom ethereum_muir_glacier_vm_precompiled_contracts_imports_ECRECOVER_ADDRESS : + IsImported globals "ethereum.muir_glacier.vm.precompiled_contracts" "ECRECOVER_ADDRESS". +Axiom ethereum_muir_glacier_vm_precompiled_contracts_imports_IDENTITY_ADDRESS : + IsImported globals "ethereum.muir_glacier.vm.precompiled_contracts" "IDENTITY_ADDRESS". +Axiom ethereum_muir_glacier_vm_precompiled_contracts_imports_MODEXP_ADDRESS : + IsImported globals "ethereum.muir_glacier.vm.precompiled_contracts" "MODEXP_ADDRESS". +Axiom ethereum_muir_glacier_vm_precompiled_contracts_imports_RIPEMD160_ADDRESS : + IsImported globals "ethereum.muir_glacier.vm.precompiled_contracts" "RIPEMD160_ADDRESS". +Axiom ethereum_muir_glacier_vm_precompiled_contracts_imports_SHA256_ADDRESS : + IsImported globals "ethereum.muir_glacier.vm.precompiled_contracts" "SHA256_ADDRESS". + +Axiom ethereum_muir_glacier_vm_precompiled_contracts_alt_bn128_imports_alt_bn128_add : + IsImported globals "ethereum.muir_glacier.vm.precompiled_contracts.alt_bn128" "alt_bn128_add". +Axiom ethereum_muir_glacier_vm_precompiled_contracts_alt_bn128_imports_alt_bn128_mul : + IsImported globals "ethereum.muir_glacier.vm.precompiled_contracts.alt_bn128" "alt_bn128_mul". +Axiom ethereum_muir_glacier_vm_precompiled_contracts_alt_bn128_imports_alt_bn128_pairing_check : + IsImported globals "ethereum.muir_glacier.vm.precompiled_contracts.alt_bn128" "alt_bn128_pairing_check". + +Axiom ethereum_muir_glacier_vm_precompiled_contracts_blake2f_imports_blake2f : + IsImported globals "ethereum.muir_glacier.vm.precompiled_contracts.blake2f" "blake2f". + +Axiom ethereum_muir_glacier_vm_precompiled_contracts_ecrecover_imports_ecrecover : + IsImported globals "ethereum.muir_glacier.vm.precompiled_contracts.ecrecover" "ecrecover". + +Axiom ethereum_muir_glacier_vm_precompiled_contracts_identity_imports_identity : + IsImported globals "ethereum.muir_glacier.vm.precompiled_contracts.identity" "identity". + +Axiom ethereum_muir_glacier_vm_precompiled_contracts_modexp_imports_modexp : + IsImported globals "ethereum.muir_glacier.vm.precompiled_contracts.modexp" "modexp". + +Axiom ethereum_muir_glacier_vm_precompiled_contracts_ripemd160_imports_ripemd160 : + IsImported globals "ethereum.muir_glacier.vm.precompiled_contracts.ripemd160" "ripemd160". + +Axiom ethereum_muir_glacier_vm_precompiled_contracts_sha256_imports_sha256 : + IsImported globals "ethereum.muir_glacier.vm.precompiled_contracts.sha256" "sha256". (* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/modexp.v index 7e5d8f5..adf5841 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/modexp.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/modexp.v @@ -17,17 +17,21 @@ Introduction Implementation of the `MODEXP` precompiled contract. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_muir_glacier_vm_imports : - AreImported globals "ethereum.muir_glacier.vm" [ "Evm" ]. +Axiom ethereum_muir_glacier_vm_imports_Evm : + IsImported globals "ethereum.muir_glacier.vm" "Evm". -Axiom ethereum_muir_glacier_vm_gas_imports : - AreImported globals "ethereum.muir_glacier.vm.gas" [ "charge_gas" ]. +Axiom ethereum_muir_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.muir_glacier.vm.gas" "charge_gas". -Axiom ethereum_muir_glacier_vm_memory_imports : - AreImported globals "ethereum.muir_glacier.vm.memory" [ "buffer_read" ]. +Axiom ethereum_muir_glacier_vm_memory_imports_buffer_read : + IsImported globals "ethereum.muir_glacier.vm.memory" "buffer_read". Definition GQUADDIVISOR : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -46,9 +50,12 @@ Definition modexp : Value.t -> Value.t -> M := Calculates `(base**exp) % modulus` for arbitrary sized `base`, `exp` and. `modulus`. The return value is the same length as the modulus. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let base_length := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "base_length" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -75,8 +82,10 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exp_length := + |) + |) in + let _ := M.assign_local (| + "exp_length" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -103,8 +112,10 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let modulus_length := + |) + |) in + let _ := M.assign_local (| + "modulus_length" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -131,8 +142,10 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exp_start := + |) + |) in + let _ := M.assign_local (| + "exp_start" , BinOp.add (| M.call (| M.get_name (| globals, "U256" |), @@ -142,8 +155,10 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |), M.get_name (| globals, "base_length" |) - |) in - let exp_head := + |) + |) in + let _ := M.assign_local (| + "exp_head" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -171,7 +186,8 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -181,7 +197,8 @@ Definition modexp : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let adjusted_exp_length := + let _ := M.assign_local (| + "adjusted_exp_length" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -202,11 +219,13 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let adjusted_exp_length := + let _ := M.assign_local (| + "adjusted_exp_length" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -242,7 +261,8 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -324,7 +344,8 @@ Definition modexp : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let base := + let _ := M.assign_local (| + "base" , M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ @@ -345,8 +366,10 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exp := + |) + |) in + let _ := M.assign_local (| + "exp" , M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ @@ -361,13 +384,17 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let modulus_start := + |) + |) in + let _ := M.assign_local (| + "modulus_start" , BinOp.add (| M.get_name (| globals, "exp_start" |), M.get_name (| globals, "exp_length" |) - |) in - let modulus := + |) + |) in + let _ := M.assign_local (| + "modulus" , M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ @@ -382,7 +409,8 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| diff --git a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/ripemd160.v index 29b3b14..d68f6cf 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/ripemd160.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/ripemd160.v @@ -19,20 +19,24 @@ Implementation of the `RIPEMD160` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_left_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "left_pad_zero_bytes". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_muir_glacier_vm_imports : - AreImported globals "ethereum.muir_glacier.vm" [ "Evm" ]. +Axiom ethereum_muir_glacier_vm_imports_Evm : + IsImported globals "ethereum.muir_glacier.vm" "Evm". -Axiom ethereum_muir_glacier_vm_gas_imports : - AreImported globals "ethereum.muir_glacier.vm.gas" [ "GAS_RIPEMD160"; "GAS_RIPEMD160_WORD"; "charge_gas" ]. +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_RIPEMD160 : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_RIPEMD160". +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_RIPEMD160_WORD : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_RIPEMD160_WORD". +Axiom ethereum_muir_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.muir_glacier.vm.gas" "charge_gas". Definition ripemd160 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,9 +49,12 @@ Definition ripemd160 : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let word_count := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "word_count" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -69,7 +76,8 @@ Definition ripemd160 : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -84,7 +92,8 @@ Definition ripemd160 : Value.t -> Value.t -> M := ], make_dict [] |) in - let hash_bytes := + let _ := M.assign_local (| + "hash_bytes" , M.call (| M.get_field (| M.call (| M.get_field (| M.get_name (| globals, "hashlib" |), "new" |), @@ -96,8 +105,10 @@ Definition ripemd160 : Value.t -> Value.t -> M := |), "digest" |), make_list [], make_dict [] - |) in - let padded_hash := + |) + |) in + let _ := M.assign_local (| + "padded_hash" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -105,7 +116,8 @@ Definition ripemd160 : Value.t -> Value.t -> M := Constant.int 32 ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.get_name (| globals, "padded_hash" |) diff --git a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/sha256.v index 0639c19..778e74c 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/sha256.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/precompiled_contracts/sha256.v @@ -19,17 +19,21 @@ Implementation of the `SHA256` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_muir_glacier_vm_imports : - AreImported globals "ethereum.muir_glacier.vm" [ "Evm" ]. +Axiom ethereum_muir_glacier_vm_imports_Evm : + IsImported globals "ethereum.muir_glacier.vm" "Evm". -Axiom ethereum_muir_glacier_vm_gas_imports : - AreImported globals "ethereum.muir_glacier.vm.gas" [ "GAS_SHA256"; "GAS_SHA256_WORD"; "charge_gas" ]. +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_SHA256 : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_SHA256". +Axiom ethereum_muir_glacier_vm_gas_imports_GAS_SHA256_WORD : + IsImported globals "ethereum.muir_glacier.vm.gas" "GAS_SHA256_WORD". +Axiom ethereum_muir_glacier_vm_gas_imports_charge_gas : + IsImported globals "ethereum.muir_glacier.vm.gas" "charge_gas". Definition sha256 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,9 +46,12 @@ Definition sha256 : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let word_count := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "word_count" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -66,7 +73,8 @@ Definition sha256 : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ diff --git a/CoqOfPython/ethereum/muir_glacier/vm/runtime.v b/CoqOfPython/ethereum/muir_glacier/vm/runtime.v index d9903d3..b541b08 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/runtime.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/runtime.v @@ -17,14 +17,14 @@ Introduction Runtime related operations used while executing EVM code. ". -Axiom typing_imports : - AreImported globals "typing" [ "Set" ]. +Axiom typing_imports_Set : + IsImported globals "typing" "Set". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_muir_glacier_vm_instructions_imports : - AreImported globals "ethereum.muir_glacier.vm.instructions" [ "Ops" ]. +Axiom ethereum_muir_glacier_vm_instructions_imports_Ops : + IsImported globals "ethereum.muir_glacier.vm.instructions" "Ops". Definition get_valid_jump_destinations : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -50,20 +50,24 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := valid_jump_destinations: `Set[Uint]` The set of valid jump destinations in the code. " in - let valid_jump_destinations := + let _ := M.assign_local (| + "valid_jump_destinations" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let pc := + |) + |) in + let _ := M.assign_local (| + "pc" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in let _ := M.while (| Compare.lt (| @@ -114,17 +118,21 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let push_data_size := + let _ := M.assign_local (| + "push_data_size" , BinOp.add (| BinOp.sub (| M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) |), Constant.int 1 - |) in - let pc := BinOp.add + |) + |) in + let _ := M.assign_op_local (| + BinOp.add, + "pc", M.get_name (| globals, "push_data_size" |) - M.get_name (| globals, "push_data_size" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -132,9 +140,11 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - let pc := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "pc", Constant.int 1 - Constant.int 1 in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/muir_glacier/vm/stack.v b/CoqOfPython/ethereum/muir_glacier/vm/stack.v index f39ae16..41a8707 100644 --- a/CoqOfPython/ethereum/muir_glacier/vm/stack.v +++ b/CoqOfPython/ethereum/muir_glacier/vm/stack.v @@ -17,14 +17,16 @@ Introduction Implementation of the stack operators for the EVM. ". -Axiom typing_imports : - AreImported globals "typing" [ "List" ]. +Axiom typing_imports_List : + IsImported globals "typing" "List". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_muir_glacier_vm_exceptions_imports : - AreImported globals "ethereum.muir_glacier.vm.exceptions" [ "StackOverflowError"; "StackUnderflowError" ]. +Axiom ethereum_muir_glacier_vm_exceptions_imports_StackOverflowError : + IsImported globals "ethereum.muir_glacier.vm.exceptions" "StackOverflowError". +Axiom ethereum_muir_glacier_vm_exceptions_imports_StackUnderflowError : + IsImported globals "ethereum.muir_glacier.vm.exceptions" "StackUnderflowError". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/paris/__init__.v b/CoqOfPython/ethereum/paris/__init__.v index 8931eb8..fa10075 100644 --- a/CoqOfPython/ethereum/paris/__init__.v +++ b/CoqOfPython/ethereum/paris/__init__.v @@ -5,15 +5,15 @@ Definition globals : string := "ethereum.paris.__init__". Definition expr_1 : Value.t := Constant.str " The Paris fork transitions Ethereum from a proof-of-work consensus model to a -proof-of-stake one. This fork is often referred to as """The Merge""" because it +proof-of-stake one. This fork is often referred to as ""The Merge"" because it marks the integration of the [consensus layer] with the execution layer (defined in this project.) [consensus layer]: https://github.com/ethereum/consensus-specs ". -Axiom ethereum_fork_criteria_imports : - AreImported globals "ethereum.fork_criteria" [ "ByBlockNumber" ]. +Axiom ethereum_fork_criteria_imports_ByBlockNumber : + IsImported globals "ethereum.fork_criteria" "ByBlockNumber". Definition FORK_CRITERIA : Value.t := M.run ltac:(M.monadic ( M.call (| diff --git a/CoqOfPython/ethereum/paris/blocks.v b/CoqOfPython/ethereum/paris/blocks.v index 7fcc061..2aa7600 100644 --- a/CoqOfPython/ethereum/paris/blocks.v +++ b/CoqOfPython/ethereum/paris/blocks.v @@ -14,23 +14,39 @@ history of all state transitions that have happened since the genesis of the chain. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Tuple"; "Union" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes8"; "Bytes32"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. - -Axiom ethereum_paris_fork_types_imports : - AreImported globals "ethereum.paris.fork_types" [ "Address"; "Bloom"; "Root" ]. - -Axiom ethereum_paris_transactions_imports : - AreImported globals "ethereum.paris.transactions" [ "LegacyTransaction" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes8 : + IsImported globals "ethereum.base_types" "Bytes8". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". + +Axiom ethereum_paris_fork_types_imports_Address : + IsImported globals "ethereum.paris.fork_types" "Address". +Axiom ethereum_paris_fork_types_imports_Bloom : + IsImported globals "ethereum.paris.fork_types" "Bloom". +Axiom ethereum_paris_fork_types_imports_Root : + IsImported globals "ethereum.paris.fork_types" "Root". + +Axiom ethereum_paris_transactions_imports_LegacyTransaction : + IsImported globals "ethereum.paris.transactions" "LegacyTransaction". Definition Header : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/paris/bloom.v b/CoqOfPython/ethereum/paris/bloom.v index 71adf2c..6f6cc6b 100644 --- a/CoqOfPython/ethereum/paris/bloom.v +++ b/CoqOfPython/ethereum/paris/bloom.v @@ -21,20 +21,20 @@ for efficient searching of logs by address and/or topic, by rapidly eliminating blocks and receipts from their search. ". -Axiom typing_imports : - AreImported globals "typing" [ "Tuple" ]. +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_paris_blocks_imports : - AreImported globals "ethereum.paris.blocks" [ "Log" ]. +Axiom ethereum_paris_blocks_imports_Log : + IsImported globals "ethereum.paris.blocks" "Log". -Axiom ethereum_paris_fork_types_imports : - AreImported globals "ethereum.paris.fork_types" [ "Bloom" ]. +Axiom ethereum_paris_fork_types_imports_Bloom : + IsImported globals "ethereum.paris.fork_types" "Bloom". Definition add_to_bloom : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -53,20 +53,23 @@ Definition add_to_bloom : Value.t -> Value.t -> M := bloom_entry : An entry which is to be added to bloom filter. " in - let hash := + let _ := M.assign_local (| + "hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "bloom_entry" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "idx" |), make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ], ltac:(M.monadic ( - let bit_to_set := + let _ := M.assign_local (| + "bit_to_set" , BinOp.bit_and (| M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), @@ -84,18 +87,24 @@ Definition add_to_bloom : Value.t -> Value.t -> M := make_dict [] |), Constant.int 2047 - |) in - let bit_index := + |) + |) in + let _ := M.assign_local (| + "bit_index" , BinOp.sub (| Constant.int 2047, M.get_name (| globals, "bit_to_set" |) - |) in - let byte_index := + |) + |) in + let _ := M.assign_local (| + "byte_index" , BinOp.floor_div (| M.get_name (| globals, "bit_index" |), Constant.int 8 - |) in - let bit_value := + |) + |) in + let _ := M.assign_local (| + "bit_value" , BinOp.l_shift (| Constant.int 1, BinOp.sub (| @@ -105,7 +114,8 @@ Definition add_to_bloom : Value.t -> Value.t -> M := Constant.int 8 |) |) - |) in + |) + |) in let _ := M.assign (| M.get_subscript (| M.get_name (| globals, "bloom" |), diff --git a/CoqOfPython/ethereum/paris/fork.v b/CoqOfPython/ethereum/paris/fork.v index 9051393..442ce2d 100644 --- a/CoqOfPython/ethereum/paris/fork.v +++ b/CoqOfPython/ethereum/paris/fork.v @@ -17,59 +17,125 @@ Introduction Entry point for the Ethereum specification. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Optional"; "Tuple"; "Union" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Bytes0"; "Bytes32" ]. - -Axiom ethereum_crypto_elliptic_curve_imports : - AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. - -Axiom ethereum_exceptions_imports : - AreImported globals "ethereum.exceptions" [ "InvalidBlock" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U64"; "U256"; "Bytes"; "Uint" ]. - -Axiom ethereum_paris_imports : - AreImported globals "ethereum.paris" [ "vm" ]. - -Axiom ethereum_paris_blocks_imports : - AreImported globals "ethereum.paris.blocks" [ "Block"; "Header"; "Log"; "Receipt" ]. - -Axiom ethereum_paris_bloom_imports : - AreImported globals "ethereum.paris.bloom" [ "logs_bloom" ]. - -Axiom ethereum_paris_fork_types_imports : - AreImported globals "ethereum.paris.fork_types" [ "Address"; "Bloom"; "Root" ]. - -Axiom ethereum_paris_state_imports : - AreImported globals "ethereum.paris.state" [ "State"; "account_exists_and_is_empty"; "destroy_account"; "get_account"; "increment_nonce"; "set_account_balance"; "state_root" ]. - -Axiom ethereum_paris_transactions_imports : - AreImported globals "ethereum.paris.transactions" [ "TX_ACCESS_LIST_ADDRESS_COST"; "TX_ACCESS_LIST_STORAGE_KEY_COST"; "TX_BASE_COST"; "TX_CREATE_COST"; "TX_DATA_COST_PER_NON_ZERO"; "TX_DATA_COST_PER_ZERO"; "AccessListTransaction"; "FeeMarketTransaction"; "LegacyTransaction"; "Transaction"; "decode_transaction"; "encode_transaction" ]. - -Axiom ethereum_paris_trie_imports : - AreImported globals "ethereum.paris.trie" [ "Trie"; "root"; "trie_set" ]. - -Axiom ethereum_paris_utils_message_imports : - AreImported globals "ethereum.paris.utils.message" [ "prepare_message" ]. - -Axiom ethereum_paris_vm_interpreter_imports : - AreImported globals "ethereum.paris.vm.interpreter" [ "process_message_call" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". + +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". + +Axiom ethereum_crypto_elliptic_curve_imports_SECP256K1N : + IsImported globals "ethereum.crypto.elliptic_curve" "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_imports_secp256k1_recover : + IsImported globals "ethereum.crypto.elliptic_curve" "secp256k1_recover". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". + +Axiom ethereum_exceptions_imports_InvalidBlock : + IsImported globals "ethereum.exceptions" "InvalidBlock". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U64 : + IsImported globals "ethereum.base_types" "U64". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_paris_imports_vm : + IsImported globals "ethereum.paris" "vm". + +Axiom ethereum_paris_blocks_imports_Block : + IsImported globals "ethereum.paris.blocks" "Block". +Axiom ethereum_paris_blocks_imports_Header : + IsImported globals "ethereum.paris.blocks" "Header". +Axiom ethereum_paris_blocks_imports_Log : + IsImported globals "ethereum.paris.blocks" "Log". +Axiom ethereum_paris_blocks_imports_Receipt : + IsImported globals "ethereum.paris.blocks" "Receipt". + +Axiom ethereum_paris_bloom_imports_logs_bloom : + IsImported globals "ethereum.paris.bloom" "logs_bloom". + +Axiom ethereum_paris_fork_types_imports_Address : + IsImported globals "ethereum.paris.fork_types" "Address". +Axiom ethereum_paris_fork_types_imports_Bloom : + IsImported globals "ethereum.paris.fork_types" "Bloom". +Axiom ethereum_paris_fork_types_imports_Root : + IsImported globals "ethereum.paris.fork_types" "Root". + +Axiom ethereum_paris_state_imports_State : + IsImported globals "ethereum.paris.state" "State". +Axiom ethereum_paris_state_imports_account_exists_and_is_empty : + IsImported globals "ethereum.paris.state" "account_exists_and_is_empty". +Axiom ethereum_paris_state_imports_destroy_account : + IsImported globals "ethereum.paris.state" "destroy_account". +Axiom ethereum_paris_state_imports_get_account : + IsImported globals "ethereum.paris.state" "get_account". +Axiom ethereum_paris_state_imports_increment_nonce : + IsImported globals "ethereum.paris.state" "increment_nonce". +Axiom ethereum_paris_state_imports_set_account_balance : + IsImported globals "ethereum.paris.state" "set_account_balance". +Axiom ethereum_paris_state_imports_state_root : + IsImported globals "ethereum.paris.state" "state_root". + +Axiom ethereum_paris_transactions_imports_TX_ACCESS_LIST_ADDRESS_COST : + IsImported globals "ethereum.paris.transactions" "TX_ACCESS_LIST_ADDRESS_COST". +Axiom ethereum_paris_transactions_imports_TX_ACCESS_LIST_STORAGE_KEY_COST : + IsImported globals "ethereum.paris.transactions" "TX_ACCESS_LIST_STORAGE_KEY_COST". +Axiom ethereum_paris_transactions_imports_TX_BASE_COST : + IsImported globals "ethereum.paris.transactions" "TX_BASE_COST". +Axiom ethereum_paris_transactions_imports_TX_CREATE_COST : + IsImported globals "ethereum.paris.transactions" "TX_CREATE_COST". +Axiom ethereum_paris_transactions_imports_TX_DATA_COST_PER_NON_ZERO : + IsImported globals "ethereum.paris.transactions" "TX_DATA_COST_PER_NON_ZERO". +Axiom ethereum_paris_transactions_imports_TX_DATA_COST_PER_ZERO : + IsImported globals "ethereum.paris.transactions" "TX_DATA_COST_PER_ZERO". +Axiom ethereum_paris_transactions_imports_AccessListTransaction : + IsImported globals "ethereum.paris.transactions" "AccessListTransaction". +Axiom ethereum_paris_transactions_imports_FeeMarketTransaction : + IsImported globals "ethereum.paris.transactions" "FeeMarketTransaction". +Axiom ethereum_paris_transactions_imports_LegacyTransaction : + IsImported globals "ethereum.paris.transactions" "LegacyTransaction". +Axiom ethereum_paris_transactions_imports_Transaction : + IsImported globals "ethereum.paris.transactions" "Transaction". +Axiom ethereum_paris_transactions_imports_decode_transaction : + IsImported globals "ethereum.paris.transactions" "decode_transaction". +Axiom ethereum_paris_transactions_imports_encode_transaction : + IsImported globals "ethereum.paris.transactions" "encode_transaction". + +Axiom ethereum_paris_trie_imports_Trie : + IsImported globals "ethereum.paris.trie" "Trie". +Axiom ethereum_paris_trie_imports_root : + IsImported globals "ethereum.paris.trie" "root". +Axiom ethereum_paris_trie_imports_trie_set : + IsImported globals "ethereum.paris.trie" "trie_set". + +Axiom ethereum_paris_utils_message_imports_prepare_message : + IsImported globals "ethereum.paris.utils.message" "prepare_message". + +Axiom ethereum_paris_vm_interpreter_imports_process_message_call : + IsImported globals "ethereum.paris.vm.interpreter" "process_message_call". Definition BASE_FEE_MAX_CHANGE_DENOMINATOR : Value.t := M.run ltac:(M.monadic ( Constant.int 8 @@ -161,13 +227,15 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := recent_block_hashes : `List[Hash32]` Hashes of the recent 256 blocks in order of increasing block number. " in - let recent_blocks := + let _ := M.assign_local (| + "recent_blocks" , M.slice (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |), Constant.None_, Constant.None_ - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -191,15 +259,19 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let recent_block_hashes := - make_list [] in + let _ := M.assign_local (| + "recent_block_hashes" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "block" |), M.get_name (| globals, "recent_blocks" |), ltac:(M.monadic ( - let prev_block_hash := - M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in + let _ := M.assign_local (| + "prev_block_hash" , + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), make_list [ @@ -213,7 +285,8 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let most_recent_block_hash := + let _ := M.assign_local (| + "most_recent_block_hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -229,7 +302,8 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), make_list [ @@ -266,11 +340,13 @@ Definition state_transition : Value.t -> Value.t -> M := block : Block to apply to `chain`. " in - let parent_header := + let _ := M.assign_local (| + "parent_header" , M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 1 |) - |), "header" |) in + |), "header" |) + |) in let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ @@ -290,7 +366,8 @@ Definition state_transition : Value.t -> Value.t -> M := ], make_dict [] |) in - let apply_body_output := + let _ := M.assign_local (| + "apply_body_output" , M.call (| M.get_name (| globals, "apply_body" |), make_list [ @@ -312,7 +389,8 @@ Definition state_transition : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "chain" |), "chain_id" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -428,11 +506,13 @@ Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := base_fee_per_gas : `Uint` Base fee per gas for the block. " in - let parent_gas_target := + let _ := M.assign_local (| + "parent_gas_target" , BinOp.floor_div (| M.get_name (| globals, "parent_gas_limit" |), M.get_name (| globals, "ELASTICITY_MULTIPLIER" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -457,8 +537,10 @@ Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let expected_base_fee_per_gas := - M.get_name (| globals, "parent_base_fee_per_gas" |) in + let _ := M.assign_local (| + "expected_base_fee_per_gas" , + M.get_name (| globals, "parent_base_fee_per_gas" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -471,22 +553,29 @@ Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let gas_used_delta := + let _ := M.assign_local (| + "gas_used_delta" , BinOp.sub (| M.get_name (| globals, "parent_gas_used" |), M.get_name (| globals, "parent_gas_target" |) - |) in - let parent_fee_gas_delta := + |) + |) in + let _ := M.assign_local (| + "parent_fee_gas_delta" , BinOp.mult (| M.get_name (| globals, "parent_base_fee_per_gas" |), M.get_name (| globals, "gas_used_delta" |) - |) in - let target_fee_gas_delta := + |) + |) in + let _ := M.assign_local (| + "target_fee_gas_delta" , BinOp.floor_div (| M.get_name (| globals, "parent_fee_gas_delta" |), M.get_name (| globals, "parent_gas_target" |) - |) in - let base_fee_per_gas_delta := + |) + |) in + let _ := M.assign_local (| + "base_fee_per_gas_delta" , M.call (| M.get_name (| globals, "max" |), make_list [ @@ -497,40 +586,53 @@ Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := Constant.int 1 ], make_dict [] - |) in - let expected_base_fee_per_gas := + |) + |) in + let _ := M.assign_local (| + "expected_base_fee_per_gas" , BinOp.add (| M.get_name (| globals, "parent_base_fee_per_gas" |), M.get_name (| globals, "base_fee_per_gas_delta" |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let gas_used_delta := + let _ := M.assign_local (| + "gas_used_delta" , BinOp.sub (| M.get_name (| globals, "parent_gas_target" |), M.get_name (| globals, "parent_gas_used" |) - |) in - let parent_fee_gas_delta := + |) + |) in + let _ := M.assign_local (| + "parent_fee_gas_delta" , BinOp.mult (| M.get_name (| globals, "parent_base_fee_per_gas" |), M.get_name (| globals, "gas_used_delta" |) - |) in - let target_fee_gas_delta := + |) + |) in + let _ := M.assign_local (| + "target_fee_gas_delta" , BinOp.floor_div (| M.get_name (| globals, "parent_fee_gas_delta" |), M.get_name (| globals, "parent_gas_target" |) - |) in - let base_fee_per_gas_delta := + |) + |) in + let _ := M.assign_local (| + "base_fee_per_gas_delta" , BinOp.floor_div (| M.get_name (| globals, "target_fee_gas_delta" |), M.get_name (| globals, "BASE_FEE_MAX_CHANGE_DENOMINATOR" |) - |) in - let expected_base_fee_per_gas := + |) + |) in + let _ := M.assign_local (| + "expected_base_fee_per_gas" , BinOp.sub (| M.get_name (| globals, "parent_base_fee_per_gas" |), M.get_name (| globals, "base_fee_per_gas_delta" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -577,7 +679,8 @@ Definition validate_header : Value.t -> Value.t -> M := ], make_dict [] |) in - let expected_base_fee_per_gas := + let _ := M.assign_local (| + "expected_base_fee_per_gas" , M.call (| M.get_name (| globals, "calculate_base_fee_per_gas" |), make_list [ @@ -587,7 +690,8 @@ Definition validate_header : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "parent_header" |), "base_fee_per_gas" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -674,7 +778,8 @@ Definition validate_header : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_parent_hash := + let _ := M.assign_local (| + "block_parent_hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -687,7 +792,8 @@ Definition validate_header : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -741,7 +847,8 @@ Definition check_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_address := + let _ := M.assign_local (| + "sender_address" , M.call (| M.get_name (| globals, "recover_sender" |), make_list [ @@ -749,7 +856,8 @@ Definition check_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "tx" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -785,7 +893,8 @@ Definition check_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let priority_fee_per_gas := + let _ := M.assign_local (| + "priority_fee_per_gas" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -796,12 +905,15 @@ Definition check_transaction : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let effective_gas_price := + |) + |) in + let _ := M.assign_local (| + "effective_gas_price" , BinOp.add (| M.get_name (| globals, "priority_fee_per_gas" |), M.get_name (| globals, "base_fee_per_gas" |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -816,8 +928,10 @@ Definition check_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let effective_gas_price := - M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) in + let _ := M.assign_local (| + "effective_gas_price" , + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) + |) in M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -848,12 +962,14 @@ Definition make_receipt : Value.t -> Value.t -> M := receipt : The receipt for the transaction. " in - let receipt := + let _ := M.assign_local (| + "receipt" , M.call (| M.get_name (| globals, "Receipt" |), make_list [], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -974,8 +1090,10 @@ Definition apply_body : Value.t -> Value.t -> M := apply_body_output : `ApplyBodyOutput` Output of applying the block body to the state. " in - let gas_available := - M.get_name (| globals, "block_gas_limit" |) in + let _ := M.assign_local (| + "gas_available" , + M.get_name (| globals, "block_gas_limit" |) + |) in (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) @@ -1037,12 +1155,14 @@ Definition apply_body : Value.t -> Value.t -> M := make_dict [] |) |) in - let env := + let _ := M.assign_local (| + "env" , M.call (| M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |); M.get_name (| globals, "error" |) ], M.call (| @@ -1054,10 +1174,13 @@ Definition apply_body : Value.t -> Value.t -> M := make_dict [] |) |) in - let gas_available := BinOp.sub + let _ := M.assign_op_local (| + BinOp.sub, + "gas_available", M.get_name (| globals, "gas_used" |) - M.get_name (| globals, "gas_used" |) in - let receipt := + |) in + let _ := M.assign_local (| + "receipt" , M.call (| M.get_name (| globals, "make_receipt" |), make_list [ @@ -1070,7 +1193,8 @@ Definition apply_body : Value.t -> Value.t -> M := M.get_name (| globals, "logs" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ @@ -1092,28 +1216,34 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_logs := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "block_logs", M.get_name (| globals, "logs" |) - M.get_name (| globals, "logs" |) in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let block_gas_used := + let _ := M.assign_local (| + "block_gas_used" , BinOp.sub (| M.get_name (| globals, "block_gas_limit" |), M.get_name (| globals, "gas_available" |) - |) in - let block_logs_bloom := + |) + |) in + let _ := M.assign_local (| + "block_logs_bloom" , M.call (| M.get_name (| globals, "logs_bloom" |), make_list [ M.get_name (| globals, "block_logs" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ApplyBodyOutput" |), @@ -1190,9 +1320,12 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender := - M.get_field (| M.get_name (| globals, "env" |), "origin" |) in - let sender_account := + let _ := M.assign_local (| + "sender" , + M.get_field (| M.get_name (| globals, "env" |), "origin" |) + |) in + let _ := M.assign_local (| + "sender_account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1200,7 +1333,8 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "sender" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1214,19 +1348,23 @@ Definition process_transaction : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let max_gas_fee := + let _ := M.assign_local (| + "max_gas_fee" , BinOp.mult (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let max_gas_fee := + let _ := M.assign_local (| + "max_gas_fee" , BinOp.mult (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -1269,12 +1407,15 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let effective_gas_fee := + let _ := M.assign_local (| + "effective_gas_fee" , BinOp.mult (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_field (| M.get_name (| globals, "env" |), "gas_price" |) - |) in - let gas := + |) + |) in + let _ := M.assign_local (| + "gas" , BinOp.sub (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.call (| @@ -1284,7 +1425,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "increment_nonce" |), make_list [ @@ -1293,11 +1435,13 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_balance_after_gas_fee := + let _ := M.assign_local (| + "sender_balance_after_gas_fee" , BinOp.sub (| M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), M.get_name (| globals, "effective_gas_fee" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -1307,18 +1451,22 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let preaccessed_addresses := + let _ := M.assign_local (| + "preaccessed_addresses" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let preaccessed_storage_keys := + |) + |) in + let _ := M.assign_local (| + "preaccessed_storage_keys" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1373,7 +1521,8 @@ Definition process_transaction : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let message := + let _ := M.assign_local (| + "message" , M.call (| M.get_name (| globals, "prepare_message" |), make_list [ @@ -1385,8 +1534,10 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in - let output := + |) + |) in + let _ := M.assign_local (| + "output" , M.call (| M.get_name (| globals, "process_message_call" |), make_list [ @@ -1394,13 +1545,17 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in - let gas_used := + |) + |) in + let _ := M.assign_local (| + "gas_used" , BinOp.sub (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_field (| M.get_name (| globals, "output" |), "gas_left" |) - |) in - let gas_refund := + |) + |) in + let _ := M.assign_local (| + "gas_refund" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -1411,21 +1566,27 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "output" |), "refund_counter" |) ], make_dict [] - |) in - let gas_refund_amount := + |) + |) in + let _ := M.assign_local (| + "gas_refund_amount" , BinOp.mult (| BinOp.add (| M.get_field (| M.get_name (| globals, "output" |), "gas_left" |), M.get_name (| globals, "gas_refund" |) |), M.get_field (| M.get_name (| globals, "env" |), "gas_price" |) - |) in - let priority_fee_per_gas := + |) + |) in + let _ := M.assign_local (| + "priority_fee_per_gas" , BinOp.sub (| M.get_field (| M.get_name (| globals, "env" |), "gas_price" |), M.get_field (| M.get_name (| globals, "env" |), "base_fee_per_gas" |) - |) in - let transaction_fee := + |) + |) in + let _ := M.assign_local (| + "transaction_fee" , BinOp.mult (| BinOp.sub (| BinOp.sub (| @@ -1435,13 +1596,17 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "gas_refund" |) |), M.get_name (| globals, "priority_fee_per_gas" |) - |) in - let total_gas_used := + |) + |) in + let _ := M.assign_local (| + "total_gas_used" , BinOp.sub (| M.get_name (| globals, "gas_used" |), M.get_name (| globals, "gas_refund" |) - |) in - let sender_balance_after_refund := + |) + |) in + let _ := M.assign_local (| + "sender_balance_after_refund" , BinOp.add (| M.get_field (| M.call (| M.get_name (| globals, "get_account" |), @@ -1452,7 +1617,8 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |), "balance" |), M.get_name (| globals, "gas_refund_amount" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -1462,7 +1628,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let coinbase_balance_after_mining_fee := + let _ := M.assign_local (| + "coinbase_balance_after_mining_fee" , BinOp.add (| M.get_field (| M.call (| M.get_name (| globals, "get_account" |), @@ -1473,7 +1640,8 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |), "balance" |), M.get_name (| globals, "transaction_fee" |) - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1664,8 +1832,10 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := verified : `ethereum.base_types.Uint` The intrinsic cost of the transaction. " in - let data_cost := - Constant.int 0 in + let _ := M.assign_local (| + "data_cost" , + Constant.int 0 + |) in let _ := M.for_ (| M.get_name (| globals, "byte" |), @@ -1680,15 +1850,19 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let data_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "data_cost", M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let data_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "data_cost", M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -1712,17 +1886,23 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let create_cost := - M.get_name (| globals, "TX_CREATE_COST" |) in + let _ := M.assign_local (| + "create_cost" , + M.get_name (| globals, "TX_CREATE_COST" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let create_cost := - Constant.int 0 in + let _ := M.assign_local (| + "create_cost" , + Constant.int 0 + |) in M.pure Constant.None_ )) |) in - let access_list_cost := - Constant.int 0 in + let _ := M.assign_local (| + "access_list_cost" , + Constant.int 0 + |) in let _ := (* if *) M.if_then_else (| @@ -1741,10 +1921,14 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := make_tuple [ M.get_name (| globals, "_address" |); M.get_name (| globals, "keys" |) ], M.get_field (| M.get_name (| globals, "tx" |), "access_list" |), ltac:(M.monadic ( - let access_list_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "access_list_cost", M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) - M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) in - let access_list_cost := BinOp.add + |) in + let _ := M.assign_op_local (| + BinOp.add, + "access_list_cost", BinOp.mult (| M.call (| M.get_name (| globals, "len" |), @@ -1755,16 +1939,7 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) |) - BinOp.mult (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "keys" |) - ], - make_dict [] - |), - M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) - |) in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -1878,8 +2053,10 @@ Definition recover_sender : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let v := - M.get_field (| M.get_name (| globals, "tx" |), "v" |) in + let _ := M.assign_local (| + "v" , + M.get_field (| M.get_name (| globals, "tx" |), "v" |) + |) in let _ := (* if *) M.if_then_else (| @@ -1897,7 +2074,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let public_key := + let _ := M.assign_local (| + "public_key" , M.call (| M.get_name (| globals, "secp256k1_recover" |), make_list [ @@ -1916,7 +2094,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1951,7 +2130,8 @@ Definition recover_sender : Value.t -> Value.t -> M := ], make_dict [] |) in - let public_key := + let _ := M.assign_local (| + "public_key" , M.call (| M.get_name (| globals, "secp256k1_recover" |), make_list [ @@ -1977,7 +2157,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -1996,7 +2177,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let public_key := + let _ := M.assign_local (| + "public_key" , M.call (| M.get_name (| globals, "secp256k1_recover" |), make_list [ @@ -2012,7 +2194,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -2029,7 +2212,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let public_key := + let _ := M.assign_local (| + "public_key" , M.call (| M.get_name (| globals, "secp256k1_recover" |), make_list [ @@ -2045,7 +2229,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -2310,11 +2495,13 @@ Definition check_gas_limit : Value.t -> Value.t -> M := check : `bool` True if gas limit constraints are satisfied, False otherwise. " in - let max_adjustment_delta := + let _ := M.assign_local (| + "max_adjustment_delta" , BinOp.floor_div (| M.get_name (| globals, "parent_gas_limit" |), M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) - |) in + |) + |) in let _ := (* if *) M.if_then_else (| diff --git a/CoqOfPython/ethereum/paris/fork_types.v b/CoqOfPython/ethereum/paris/fork_types.v index 9570ed3..a4242a8 100644 --- a/CoqOfPython/ethereum/paris/fork_types.v +++ b/CoqOfPython/ethereum/paris/fork_types.v @@ -17,17 +17,29 @@ Introduction Types re-used throughout the specification, which are specific to Ethereum. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes20"; "Bytes256"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes20 : + IsImported globals "ethereum.base_types" "Bytes20". +Axiom ethereum_base_types_imports_Bytes256 : + IsImported globals "ethereum.base_types" "Bytes256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) diff --git a/CoqOfPython/ethereum/paris/state.v b/CoqOfPython/ethereum/paris/state.v index 9599f90..a1eda52 100644 --- a/CoqOfPython/ethereum/paris/state.v +++ b/CoqOfPython/ethereum/paris/state.v @@ -22,23 +22,57 @@ There is a distinction between an account that does not exist and `EMPTY_ACCOUNT`. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass"; "field" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict"; "List"; "Optional"; "Set"; "Tuple" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "modify" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_paris_fork_types_imports : - AreImported globals "ethereum.paris.fork_types" [ "EMPTY_ACCOUNT"; "Account"; "Address"; "Root" ]. - -Axiom ethereum_paris_trie_imports : - AreImported globals "ethereum.paris.trie" [ "EMPTY_TRIE_ROOT"; "Trie"; "copy_trie"; "root"; "trie_get"; "trie_set" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". +Axiom dataclasses_imports_field : + IsImported globals "dataclasses" "field". + +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_modify : + IsImported globals "ethereum.base_types" "modify". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_paris_fork_types_imports_EMPTY_ACCOUNT : + IsImported globals "ethereum.paris.fork_types" "EMPTY_ACCOUNT". +Axiom ethereum_paris_fork_types_imports_Account : + IsImported globals "ethereum.paris.fork_types" "Account". +Axiom ethereum_paris_fork_types_imports_Address : + IsImported globals "ethereum.paris.fork_types" "Address". +Axiom ethereum_paris_fork_types_imports_Root : + IsImported globals "ethereum.paris.fork_types" "Root". + +Axiom ethereum_paris_trie_imports_EMPTY_TRIE_ROOT : + IsImported globals "ethereum.paris.trie" "EMPTY_TRIE_ROOT". +Axiom ethereum_paris_trie_imports_Trie : + IsImported globals "ethereum.paris.trie" "Trie". +Axiom ethereum_paris_trie_imports_copy_trie : + IsImported globals "ethereum.paris.trie" "copy_trie". +Axiom ethereum_paris_trie_imports_root : + IsImported globals "ethereum.paris.trie" "root". +Axiom ethereum_paris_trie_imports_trie_get : + IsImported globals "ethereum.paris.trie" "trie_get". +Axiom ethereum_paris_trie_imports_trie_set : + IsImported globals "ethereum.paris.trie" "trie_set". Definition State : Value.t := builtins.make_klass @@ -186,7 +220,8 @@ Definition get_account : Value.t -> Value.t -> M := account : `Account` Account at address. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account_optional" |), make_list [ @@ -194,7 +229,8 @@ Definition get_account : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -240,7 +276,8 @@ Definition get_account_optional : Value.t -> Value.t -> M := account : `Account` Account at address. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "trie_get" |), make_list [ @@ -248,7 +285,8 @@ Definition get_account_optional : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "account" |) |) in @@ -399,14 +437,16 @@ Definition get_storage : Value.t -> Value.t -> M := value : `U256` Value at the key. " in - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -430,7 +470,8 @@ Definition get_storage : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "trie_get" |), make_list [ @@ -438,7 +479,8 @@ Definition get_storage : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -481,14 +523,16 @@ Definition set_storage : Value.t -> Value.t -> M := |), Constant.None_ |) |) in - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -498,12 +542,14 @@ Definition set_storage : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_name (| globals, "Trie" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), @@ -530,7 +576,7 @@ Definition set_storage : Value.t -> Value.t -> M := M.if_then_else (| Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), - {} + Constant.str "(* At expr: unsupported node type: Dict *)" |), (* then *) ltac:(M.monadic ( @@ -676,7 +722,8 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := True if if an account has non zero nonce or non empty code, False otherwise. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -684,7 +731,8 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| BoolOp.or (| Compare.not_eq (| @@ -726,7 +774,8 @@ Definition is_account_empty : Value.t -> Value.t -> M := True if if an account has zero nonce, empty code and zero balance, False otherwise. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -734,7 +783,8 @@ Definition is_account_empty : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| BoolOp.and (| Compare.eq (| @@ -785,7 +835,8 @@ Definition account_exists_and_is_empty : Value.t -> Value.t -> M := True if an account exists and has zero nonce, empty code and zero balance, False otherwise. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account_optional" |), make_list [ @@ -793,7 +844,8 @@ Definition account_exists_and_is_empty : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| BoolOp.and (| Compare.is_not (| @@ -850,7 +902,8 @@ Definition is_account_alive : Value.t -> Value.t -> M := is_alive : `bool` True if the account is alive. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account_optional" |), make_list [ @@ -858,7 +911,8 @@ Definition is_account_alive : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1139,14 +1193,16 @@ Definition get_storage_original : Value.t -> Value.t -> M := Constant.int 0 |) |) in - let original_account_trie := + let _ := M.assign_local (| + "original_account_trie" , M.call (| M.get_field (| M.get_name (| globals, "original_trie" |), "get" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1156,18 +1212,21 @@ Definition get_storage_original : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let original_value := + let _ := M.assign_local (| + "original_value" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let original_value := + let _ := M.assign_local (| + "original_value" , M.call (| M.get_name (| globals, "trie_get" |), make_list [ @@ -1175,7 +1234,8 @@ Definition get_storage_original : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.assert (| M.call (| diff --git a/CoqOfPython/ethereum/paris/transactions.v b/CoqOfPython/ethereum/paris/transactions.v index 55db9ea..c466978 100644 --- a/CoqOfPython/ethereum/paris/transactions.v +++ b/CoqOfPython/ethereum/paris/transactions.v @@ -9,23 +9,37 @@ submitted to be executed. If Ethereum is viewed as a state machine, transactions are the events that move between states. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". -Axiom typing_imports : - AreImported globals "typing" [ "Tuple"; "Union" ]. +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U64"; "U256"; "Bytes"; "Bytes0"; "Bytes32"; "Uint"; "slotted_freezable" ]. +Axiom ethereum_base_types_imports_U64 : + IsImported globals "ethereum.base_types" "U64". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". -Axiom ethereum_exceptions_imports : - AreImported globals "ethereum.exceptions" [ "InvalidBlock" ]. +Axiom ethereum_exceptions_imports_InvalidBlock : + IsImported globals "ethereum.exceptions" "InvalidBlock". -Axiom ethereum_paris_fork_types_imports : - AreImported globals "ethereum.paris.fork_types" [ "Address" ]. +Axiom ethereum_paris_fork_types_imports_Address : + IsImported globals "ethereum.paris.fork_types" "Address". Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( Constant.int 21000 diff --git a/CoqOfPython/ethereum/paris/trie.v b/CoqOfPython/ethereum/paris/trie.v index 4325e35..90b1e2c 100644 --- a/CoqOfPython/ethereum/paris/trie.v +++ b/CoqOfPython/ethereum/paris/trie.v @@ -20,38 +20,72 @@ The state trie is the structure responsible for storing (* At top_level_stmt: unsupported node type: Import *) -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass"; "field" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict"; "Generic"; "List"; "Mapping"; "MutableMapping"; "Optional"; "Sequence"; "TypeVar"; "Union"; "cast" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. - -Axiom ethereum_gray_glacier_imports : - AreImported globals "ethereum.gray_glacier" [ "trie" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_utils_hexadecimal_imports : - AreImported globals "ethereum.utils.hexadecimal" [ "hex_to_bytes" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_paris_blocks_imports : - AreImported globals "ethereum.paris.blocks" [ "Receipt" ]. - -Axiom ethereum_paris_fork_types_imports : - AreImported globals "ethereum.paris.fork_types" [ "Account"; "Address"; "Root"; "encode_account" ]. - -Axiom ethereum_paris_transactions_imports : - AreImported globals "ethereum.paris.transactions" [ "LegacyTransaction" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". +Axiom dataclasses_imports_field : + IsImported globals "dataclasses" "field". + +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". +Axiom typing_imports_Generic : + IsImported globals "typing" "Generic". +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Mapping : + IsImported globals "typing" "Mapping". +Axiom typing_imports_MutableMapping : + IsImported globals "typing" "MutableMapping". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Sequence : + IsImported globals "typing" "Sequence". +Axiom typing_imports_TypeVar : + IsImported globals "typing" "TypeVar". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". +Axiom typing_imports_cast : + IsImported globals "typing" "cast". + +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". + +Axiom ethereum_gray_glacier_imports_trie : + IsImported globals "ethereum.gray_glacier" "trie". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_utils_hexadecimal_imports_hex_to_bytes : + IsImported globals "ethereum.utils.hexadecimal" "hex_to_bytes". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_paris_blocks_imports_Receipt : + IsImported globals "ethereum.paris.blocks" "Receipt". + +Axiom ethereum_paris_fork_types_imports_Account : + IsImported globals "ethereum.paris.fork_types" "Account". +Axiom ethereum_paris_fork_types_imports_Address : + IsImported globals "ethereum.paris.fork_types" "Address". +Axiom ethereum_paris_fork_types_imports_Root : + IsImported globals "ethereum.paris.fork_types" "Root". +Axiom ethereum_paris_fork_types_imports_encode_account : + IsImported globals "ethereum.paris.fork_types" "encode_account". + +Axiom ethereum_paris_transactions_imports_LegacyTransaction : + IsImported globals "ethereum.paris.transactions" "LegacyTransaction". Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -167,7 +201,7 @@ Definition encode_internal_node : Value.t -> Value.t -> M := when serialized. This function also accepts `None`, representing the absence of a node, - which is encoded to `b""""""`. + which is encoded to `b""""`. Parameters ---------- @@ -189,8 +223,10 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := - Constant.bytes "" in + let _ := M.assign_local (| + "unencoded" , + Constant.bytes "" + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -207,7 +243,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := + let _ := M.assign_local (| + "unencoded" , make_tuple [ M.call (| M.get_name (| globals, "nibble_list_to_compact" |), make_list [ @@ -215,7 +252,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := Constant.bool true ], make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in + |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -232,7 +270,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := + let _ := M.assign_local (| + "unencoded" , make_tuple [ M.call (| M.get_name (| globals, "nibble_list_to_compact" |), make_list [ @@ -240,7 +279,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := Constant.bool false ], make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in + |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -257,13 +297,15 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := + let _ := M.assign_local (| + "unencoded" , BinOp.add (| M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), make_list [ M.get_field (| M.get_name (| globals, "node" |), "value" |) ] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -282,14 +324,16 @@ Definition encode_internal_node : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - let encoded := + let _ := M.assign_local (| + "encoded" , M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), make_list [ M.get_name (| globals, "unencoded" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -681,12 +725,14 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := compressed : `bytearray` Compact byte array. " in - let compact := + let _ := M.assign_local (| + "compact" , M.call (| M.get_name (| globals, "bytearray" |), make_list [], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -866,7 +912,8 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := nibble_list : `Bytes` The `Bytes` in nibble-list format. " in - let nibble_list := + let _ := M.assign_local (| + "nibble_list" , M.call (| M.get_name (| globals, "bytearray" |), make_list [ @@ -882,7 +929,8 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ], @@ -990,15 +1038,18 @@ Definition _prepare_trie : Value.t -> Value.t -> M := M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "Address" |), make_list [ M.get_name (| globals, "preimage" |) ], make_dict [] - |) in - let encoded_value := + |) + |) in + let _ := M.assign_local (| + "encoded_value" , M.call (| M.get_name (| globals, "encode_node" |), make_list [ @@ -1012,18 +1063,21 @@ Definition _prepare_trie : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let encoded_value := + let _ := M.assign_local (| + "encoded_value" , M.call (| M.get_name (| globals, "encode_node" |), make_list [ M.get_name (| globals, "value" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -1044,19 +1098,23 @@ Definition _prepare_trie : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "trie" |), "secured" |), (* then *) ltac:(M.monadic ( - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "preimage" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let key := - M.get_name (| globals, "preimage" |) in + let _ := M.assign_local (| + "key" , + M.get_name (| globals, "preimage" |) + |) in M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -1103,7 +1161,8 @@ Definition root : Value.t -> Value.t -> M := root : `.fork_types.Root` MPT root of the underlying key-value pairs. " in - let obj := + let _ := M.assign_local (| + "obj" , M.call (| M.get_name (| globals, "_prepare_trie" |), make_list [ @@ -1111,8 +1170,10 @@ Definition root : Value.t -> Value.t -> M := M.get_name (| globals, "get_storage_root" |) ], make_dict [] - |) in - let root_node := + |) + |) in + let _ := M.assign_local (| + "root_node" , M.call (| M.get_name (| globals, "encode_internal_node" |), make_list [ @@ -1132,7 +1193,8 @@ Definition root : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1237,7 +1299,8 @@ Definition patricialize : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let arbitrary_key := + let _ := M.assign_local (| + "arbitrary_key" , M.call (| M.get_name (| globals, "next" |), make_list [ @@ -1250,7 +1313,8 @@ Definition patricialize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1266,7 +1330,8 @@ Definition patricialize : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let leaf := + let _ := M.assign_local (| + "leaf" , M.call (| M.get_name (| globals, "LeafNode" |), make_list [ @@ -1282,7 +1347,8 @@ Definition patricialize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "leaf" |) |) in @@ -1291,27 +1357,32 @@ Definition patricialize : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let substring := + let _ := M.assign_local (| + "substring" , M.slice (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |), Constant.None_, Constant.None_ - |) in - let prefix_length := + |) + |) in + let _ := M.assign_local (| + "prefix_length" , M.call (| M.get_name (| globals, "len" |), make_list [ M.get_name (| globals, "substring" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "key" |), M.get_name (| globals, "obj" |), ltac:(M.monadic ( - let prefix_length := + let _ := M.assign_local (| + "prefix_length" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -1331,7 +1402,8 @@ Definition patricialize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1362,7 +1434,8 @@ Definition patricialize : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let prefix := + let _ := M.assign_local (| + "prefix" , M.slice (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |), @@ -1371,7 +1444,8 @@ Definition patricialize : Value.t -> Value.t -> M := M.get_name (| globals, "prefix_length" |) |), Constant.None_ - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ExtensionNode" |), @@ -1418,7 +1492,7 @@ Definition patricialize : Value.t -> Value.t -> M := let _ := M.call (| M.get_field (| M.get_name (| globals, "branches" |), "append" |), make_list [ - {} + Constant.str "(* At expr: unsupported node type: Dict *)" ], make_dict [] |) in @@ -1428,8 +1502,10 @@ Definition patricialize : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let value := - Constant.bytes "" in + let _ := M.assign_local (| + "value" , + Constant.bytes "" + |) in let _ := M.for_ (| M.get_name (| globals, "key" |), @@ -1472,11 +1548,13 @@ Definition patricialize : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let value := + let _ := M.assign_local (| + "value" , M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/paris/utils/address.v b/CoqOfPython/ethereum/paris/utils/address.v index ad264a6..bd0c332 100644 --- a/CoqOfPython/ethereum/paris/utils/address.v +++ b/CoqOfPython/ethereum/paris/utils/address.v @@ -18,23 +18,27 @@ Address specific functions used in this paris version of specification. ". -Axiom typing_imports : - AreImported globals "typing" [ "Union" ]. +Axiom typing_imports_Union : + IsImported globals "typing" "Union". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes32"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_left_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "left_pad_zero_bytes". -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". -Axiom ethereum_paris_fork_types_imports : - AreImported globals "ethereum.paris.fork_types" [ "Address" ]. +Axiom ethereum_paris_fork_types_imports_Address : + IsImported globals "ethereum.paris.fork_types" "Address". Definition to_address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -91,7 +95,8 @@ Definition compute_contract_address : Value.t -> Value.t -> M := address: `Address` The computed address of the new account. " in - let computed_address := + let _ := M.assign_local (| + "computed_address" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -107,15 +112,19 @@ Definition compute_contract_address : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let canonical_address := + |) + |) in + let _ := M.assign_local (| + "canonical_address" , M.slice (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |), Constant.None_, Constant.None_ - |) in - let padded_address := + |) + |) in + let _ := M.assign_local (| + "padded_address" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -123,7 +132,8 @@ Definition compute_contract_address : Value.t -> Value.t -> M := Constant.int 20 ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Address" |), @@ -156,7 +166,8 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := address: `ethereum.paris.fork_types.Address` The computed address of the new account. " in - let preimage := + let _ := M.assign_local (| + "preimage" , BinOp.add (| BinOp.add (| BinOp.add (| @@ -172,23 +183,29 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in - let computed_address := + |) + |) in + let _ := M.assign_local (| + "computed_address" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "preimage" |) ], make_dict [] - |) in - let canonical_address := + |) + |) in + let _ := M.assign_local (| + "canonical_address" , M.slice (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |), Constant.None_, Constant.None_ - |) in - let padded_address := + |) + |) in + let _ := M.assign_local (| + "padded_address" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -196,7 +213,8 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := Constant.int 20 ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Address" |), diff --git a/CoqOfPython/ethereum/paris/utils/hexadecimal.v b/CoqOfPython/ethereum/paris/utils/hexadecimal.v index af069d3..62e084d 100644 --- a/CoqOfPython/ethereum/paris/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/paris/utils/hexadecimal.v @@ -18,11 +18,15 @@ Hexadecimal utility functions used in this specification, specific to Paris types. ". -Axiom ethereum_utils_hexadecimal_imports : - AreImported globals "ethereum.utils.hexadecimal" [ "remove_hex_prefix" ]. - -Axiom ethereum_paris_fork_types_imports : - AreImported globals "ethereum.paris.fork_types" [ "Address"; "Bloom"; "Root" ]. +Axiom ethereum_utils_hexadecimal_imports_remove_hex_prefix : + IsImported globals "ethereum.utils.hexadecimal" "remove_hex_prefix". + +Axiom ethereum_paris_fork_types_imports_Address : + IsImported globals "ethereum.paris.fork_types" "Address". +Axiom ethereum_paris_fork_types_imports_Bloom : + IsImported globals "ethereum.paris.fork_types" "Bloom". +Axiom ethereum_paris_fork_types_imports_Root : + IsImported globals "ethereum.paris.fork_types" "Root". Definition hex_to_root : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/paris/utils/message.v b/CoqOfPython/ethereum/paris/utils/message.v index 752cf70..9e2da6d 100644 --- a/CoqOfPython/ethereum/paris/utils/message.v +++ b/CoqOfPython/ethereum/paris/utils/message.v @@ -18,26 +18,42 @@ Message specific functions used in this paris version of specification. ". -Axiom typing_imports : - AreImported globals "typing" [ "FrozenSet"; "Optional"; "Tuple"; "Union" ]. +Axiom typing_imports_FrozenSet : + IsImported globals "typing" "FrozenSet". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Bytes32"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_paris_fork_types_imports : - AreImported globals "ethereum.paris.fork_types" [ "Address" ]. +Axiom ethereum_paris_fork_types_imports_Address : + IsImported globals "ethereum.paris.fork_types" "Address". -Axiom ethereum_paris_state_imports : - AreImported globals "ethereum.paris.state" [ "get_account" ]. +Axiom ethereum_paris_state_imports_get_account : + IsImported globals "ethereum.paris.state" "get_account". -Axiom ethereum_paris_vm_imports : - AreImported globals "ethereum.paris.vm" [ "Environment"; "Message" ]. +Axiom ethereum_paris_vm_imports_Environment : + IsImported globals "ethereum.paris.vm" "Environment". +Axiom ethereum_paris_vm_imports_Message : + IsImported globals "ethereum.paris.vm" "Message". -Axiom ethereum_paris_vm_precompiled_contracts_mapping_imports : - AreImported globals "ethereum.paris.vm.precompiled_contracts.mapping" [ "PRE_COMPILED_CONTRACTS" ]. +Axiom ethereum_paris_vm_precompiled_contracts_mapping_imports_PRE_COMPILED_CONTRACTS : + IsImported globals "ethereum.paris.vm.precompiled_contracts.mapping" "PRE_COMPILED_CONTRACTS". -Axiom ethereum_paris_utils_address_imports : - AreImported globals "ethereum.paris.utils.address" [ "compute_contract_address" ]. +Axiom ethereum_paris_utils_address_imports_compute_contract_address : + IsImported globals "ethereum.paris.utils.address" "compute_contract_address". Definition prepare_message : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -92,7 +108,8 @@ Definition prepare_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let current_target := + let _ := M.assign_local (| + "current_target" , M.call (| M.get_name (| globals, "compute_contract_address" |), make_list [ @@ -116,17 +133,22 @@ Definition prepare_message : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let msg_data := + |) + |) in + let _ := M.assign_local (| + "msg_data" , M.call (| M.get_name (| globals, "Bytes" |), make_list [ Constant.bytes "" ], make_dict [] - |) in - let code := - M.get_name (| globals, "data" |) in + |) + |) in + let _ := M.assign_local (| + "code" , + M.get_name (| globals, "data" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -143,11 +165,16 @@ Definition prepare_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let current_target := - M.get_name (| globals, "target" |) in - let msg_data := - M.get_name (| globals, "data" |) in - let code := + let _ := M.assign_local (| + "current_target" , + M.get_name (| globals, "target" |) + |) in + let _ := M.assign_local (| + "msg_data" , + M.get_name (| globals, "data" |) + |) in + let _ := M.assign_local (| + "code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -155,7 +182,8 @@ Definition prepare_message : Value.t -> Value.t -> M := M.get_name (| globals, "target" |) ], make_dict [] - |), "code" |) in + |), "code" |) + |) in let _ := (* if *) M.if_then_else (| @@ -165,8 +193,10 @@ Definition prepare_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let code_address := - M.get_name (| globals, "target" |) in + let _ := M.assign_local (| + "code_address" , + M.get_name (| globals, "target" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -186,12 +216,14 @@ Definition prepare_message : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - let accessed_addresses := + let _ := M.assign_local (| + "accessed_addresses" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "accessed_addresses" |), "add" |), make_list [ diff --git a/CoqOfPython/ethereum/paris/vm/__init__.v b/CoqOfPython/ethereum/paris/vm/__init__.v index dcfac8a..472ccd5 100644 --- a/CoqOfPython/ethereum/paris/vm/__init__.v +++ b/CoqOfPython/ethereum/paris/vm/__init__.v @@ -18,29 +18,49 @@ The abstract computer which runs the code stored in an `.fork_types.Account`. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple"; "Union" ]. +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U64"; "U256"; "Bytes"; "Bytes0"; "Bytes32"; "Uint" ]. +Axiom ethereum_base_types_imports_U64 : + IsImported globals "ethereum.base_types" "U64". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". -Axiom ethereum_paris_blocks_imports : - AreImported globals "ethereum.paris.blocks" [ "Log" ]. +Axiom ethereum_paris_blocks_imports_Log : + IsImported globals "ethereum.paris.blocks" "Log". -Axiom ethereum_paris_fork_types_imports : - AreImported globals "ethereum.paris.fork_types" [ "Address" ]. +Axiom ethereum_paris_fork_types_imports_Address : + IsImported globals "ethereum.paris.fork_types" "Address". -Axiom ethereum_paris_state_imports : - AreImported globals "ethereum.paris.state" [ "State"; "account_exists_and_is_empty" ]. +Axiom ethereum_paris_state_imports_State : + IsImported globals "ethereum.paris.state" "State". +Axiom ethereum_paris_state_imports_account_exists_and_is_empty : + IsImported globals "ethereum.paris.state" "account_exists_and_is_empty". -Axiom ethereum_paris_vm_precompiled_contracts_imports : - AreImported globals "ethereum.paris.vm.precompiled_contracts" [ "RIPEMD160_ADDRESS" ]. +Axiom ethereum_paris_vm_precompiled_contracts_imports_RIPEMD160_ADDRESS : + IsImported globals "ethereum.paris.vm.precompiled_contracts" "RIPEMD160_ADDRESS". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] diff --git a/CoqOfPython/ethereum/paris/vm/exceptions.v b/CoqOfPython/ethereum/paris/vm/exceptions.v index 4df4ea7..95b6cd9 100644 --- a/CoqOfPython/ethereum/paris/vm/exceptions.v +++ b/CoqOfPython/ethereum/paris/vm/exceptions.v @@ -17,8 +17,8 @@ Introduction Exceptions which cause the EVM to halt exceptionally. ". -Axiom ethereum_exceptions_imports : - AreImported globals "ethereum.exceptions" [ "EthereumException" ]. +Axiom ethereum_exceptions_imports_EthereumException : + IsImported globals "ethereum.exceptions" "EthereumException". Definition ExceptionalHalt : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/paris/vm/gas.v b/CoqOfPython/ethereum/paris/vm/gas.v index a170113..7b37d78 100644 --- a/CoqOfPython/ethereum/paris/vm/gas.v +++ b/CoqOfPython/ethereum/paris/vm/gas.v @@ -17,26 +17,32 @@ Introduction EVM gas constants and calculators. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Tuple" ]. +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_trace_imports : - AreImported globals "ethereum.trace" [ "GasAndRefund"; "evm_trace" ]. +Axiom ethereum_trace_imports_GasAndRefund : + IsImported globals "ethereum.trace" "GasAndRefund". +Axiom ethereum_trace_imports_evm_trace : + IsImported globals "ethereum.trace" "evm_trace". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_paris_vm_imports : - AreImported globals "ethereum.paris.vm" [ "Evm" ]. +Axiom ethereum_paris_vm_imports_Evm : + IsImported globals "ethereum.paris.vm" "Evm". -Axiom ethereum_paris_vm_exceptions_imports : - AreImported globals "ethereum.paris.vm.exceptions" [ "OutOfGasError" ]. +Axiom ethereum_paris_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.paris.vm.exceptions" "OutOfGasError". Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -532,7 +538,8 @@ Definition calculate_memory_gas_cost : Value.t -> Value.t -> M := total_gas_cost : `ethereum.base_types.Uint` The gas cost for storing data in memory. " in - let size_in_words := + let _ := M.assign_local (| + "size_in_words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -542,25 +549,32 @@ Definition calculate_memory_gas_cost : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let linear_cost := + |) + |) in + let _ := M.assign_local (| + "linear_cost" , BinOp.mult (| M.get_name (| globals, "size_in_words" |), M.get_name (| globals, "GAS_MEMORY" |) - |) in - let quadratic_cost := + |) + |) in + let _ := M.assign_local (| + "quadratic_cost" , BinOp.floor_div (| BinOp.pow (| M.get_name (| globals, "size_in_words" |), Constant.int 2 |), Constant.int 512 - |) in - let total_gas_cost := + |) + |) in + let _ := M.assign_local (| + "total_gas_cost" , BinOp.add (| M.get_name (| globals, "linear_cost" |), M.get_name (| globals, "quadratic_cost" |) - |) in + |) + |) in (* At stmt: unsupported node type: Try *) M.pure Constant.None_)). @@ -582,23 +596,28 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := ------- extend_memory: `ExtendMemory` " in - let size_to_extend := + let _ := M.assign_local (| + "size_to_extend" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in - let to_be_paid := + |) + |) in + let _ := M.assign_local (| + "to_be_paid" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in - let current_size := + |) + |) in + let _ := M.assign_local (| + "current_size" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -611,7 +630,8 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ], @@ -632,15 +652,18 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let before_size := + let _ := M.assign_local (| + "before_size" , M.call (| M.get_name (| globals, "ceil32" |), make_list [ M.get_name (| globals, "current_size" |) ], make_dict [] - |) in - let after_size := + |) + |) in + let _ := M.assign_local (| + "after_size" , M.call (| M.get_name (| globals, "ceil32" |), make_list [ @@ -662,7 +685,8 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -678,42 +702,46 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let size_to_extend := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "size_to_extend", BinOp.sub (| M.get_name (| globals, "after_size" |), M.get_name (| globals, "before_size" |) |) - BinOp.sub (| - M.get_name (| globals, "after_size" |), - M.get_name (| globals, "before_size" |) - |) in - let already_paid := + |) in + let _ := M.assign_local (| + "already_paid" , M.call (| M.get_name (| globals, "calculate_memory_gas_cost" |), make_list [ M.get_name (| globals, "before_size" |) ], make_dict [] - |) in - let total_cost := + |) + |) in + let _ := M.assign_local (| + "total_cost" , M.call (| M.get_name (| globals, "calculate_memory_gas_cost" |), make_list [ M.get_name (| globals, "after_size" |) ], make_dict [] - |) in - let to_be_paid := BinOp.add + |) + |) in + let _ := M.assign_op_local (| + BinOp.add, + "to_be_paid", BinOp.sub (| M.get_name (| globals, "total_cost" |), M.get_name (| globals, "already_paid" |) |) - BinOp.sub (| - M.get_name (| globals, "total_cost" |), - M.get_name (| globals, "already_paid" |) - |) in - let current_size := - M.get_name (| globals, "after_size" |) in + |) in + let _ := M.assign_local (| + "current_size" , + M.get_name (| globals, "after_size" |) + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -760,7 +788,8 @@ Definition calculate_message_call_gas : Value.t -> Value.t -> M := ------- message_call_gas: `MessageCallGas` " in - let call_stipend := + let _ := M.assign_local (| + "call_stipend" , (* if *) M.if_then_else (| Compare.eq (| @@ -779,7 +808,8 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "call_stipend" |) - )) |) in + )) |) + |) in let _ := (* if *) M.if_then_else (| @@ -813,7 +843,8 @@ M.get_name (| globals, "call_stipend" |) )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -833,7 +864,8 @@ M.get_name (| globals, "call_stipend" |) |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "MessageCallGas" |), diff --git a/CoqOfPython/ethereum/paris/vm/instructions/__init__.v b/CoqOfPython/ethereum/paris/vm/instructions/__init__.v index 1dcc787..8cfce01 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/__init__.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/__init__.v @@ -20,44 +20,46 @@ implementations. (* At top_level_stmt: unsupported node type: Import *) -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict" ]. +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". -Axiom ethereum_paris_vm_instructions_imports : - AreImported globals "ethereum.paris.vm.instructions" [ "arithmetic" ]. +Axiom ethereum_paris_vm_instructions_imports_arithmetic : + IsImported globals "ethereum.paris.vm.instructions" "arithmetic". -Axiom ethereum_paris_vm_instructions_imports : - AreImported globals "ethereum.paris.vm.instructions" [ "bitwise" ]. +Axiom ethereum_paris_vm_instructions_imports_bitwise : + IsImported globals "ethereum.paris.vm.instructions" "bitwise". -Axiom ethereum_paris_vm_instructions_imports : - AreImported globals "ethereum.paris.vm.instructions" [ "block" ]. +Axiom ethereum_paris_vm_instructions_imports_block : + IsImported globals "ethereum.paris.vm.instructions" "block". -Axiom ethereum_paris_vm_instructions_imports : - AreImported globals "ethereum.paris.vm.instructions" [ "comparison" ]. +Axiom ethereum_paris_vm_instructions_imports_comparison : + IsImported globals "ethereum.paris.vm.instructions" "comparison". -Axiom ethereum_paris_vm_instructions_imports : - AreImported globals "ethereum.paris.vm.instructions" [ "control_flow" ]. +Axiom ethereum_paris_vm_instructions_imports_control_flow : + IsImported globals "ethereum.paris.vm.instructions" "control_flow". -Axiom ethereum_paris_vm_instructions_imports : - AreImported globals "ethereum.paris.vm.instructions" [ "environment" ]. +Axiom ethereum_paris_vm_instructions_imports_environment : + IsImported globals "ethereum.paris.vm.instructions" "environment". -Axiom ethereum_paris_vm_instructions_imports : - AreImported globals "ethereum.paris.vm.instructions" [ "keccak" ]. +Axiom ethereum_paris_vm_instructions_imports_keccak : + IsImported globals "ethereum.paris.vm.instructions" "keccak". -Axiom ethereum_paris_vm_instructions_imports : - AreImported globals "ethereum.paris.vm.instructions" [ "log" ]. +Axiom ethereum_paris_vm_instructions_imports_log : + IsImported globals "ethereum.paris.vm.instructions" "log". -Axiom ethereum_paris_vm_instructions_imports : - AreImported globals "ethereum.paris.vm.instructions" [ "memory" ]. +Axiom ethereum_paris_vm_instructions_imports_memory : + IsImported globals "ethereum.paris.vm.instructions" "memory". -Axiom ethereum_paris_vm_instructions_imports : - AreImported globals "ethereum.paris.vm.instructions" [ "stack" ]. +Axiom ethereum_paris_vm_instructions_imports_stack : + IsImported globals "ethereum.paris.vm.instructions" "stack". -Axiom ethereum_paris_vm_instructions_imports : - AreImported globals "ethereum.paris.vm.instructions" [ "storage" ]. +Axiom ethereum_paris_vm_instructions_imports_storage : + IsImported globals "ethereum.paris.vm.instructions" "storage". -Axiom ethereum_paris_vm_instructions_imports : - AreImported globals "ethereum.paris.vm.instructions" [ "system" ]. +Axiom ethereum_paris_vm_instructions_imports_system : + IsImported globals "ethereum.paris.vm.instructions" "system". Definition Ops : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/paris/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/paris/vm/instructions/arithmetic.v index 8708af7..3996ed7 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/arithmetic.v @@ -17,20 +17,38 @@ Introduction Implementations of the EVM Arithmetic instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U255_CEIL_VALUE"; "U256"; "U256_CEIL_VALUE"; "Uint" ]. +Axiom ethereum_base_types_imports_U255_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U255_CEIL_VALUE". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_U256_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U256_CEIL_VALUE". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "get_sign" ]. +Axiom ethereum_utils_numeric_imports_get_sign : + IsImported globals "ethereum.utils.numeric" "get_sign". -Axiom ethereum_paris_vm_imports : - AreImported globals "ethereum.paris.vm" [ "Evm" ]. +Axiom ethereum_paris_vm_imports_Evm : + IsImported globals "ethereum.paris.vm" "Evm". -Axiom ethereum_paris_vm_gas_imports : - AreImported globals "ethereum.paris.vm.gas" [ "GAS_EXPONENTIATION"; "GAS_EXPONENTIATION_PER_BYTE"; "GAS_LOW"; "GAS_MID"; "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_paris_vm_gas_imports_GAS_EXPONENTIATION : + IsImported globals "ethereum.paris.vm.gas" "GAS_EXPONENTIATION". +Axiom ethereum_paris_vm_gas_imports_GAS_EXPONENTIATION_PER_BYTE : + IsImported globals "ethereum.paris.vm.gas" "GAS_EXPONENTIATION_PER_BYTE". +Axiom ethereum_paris_vm_gas_imports_GAS_LOW : + IsImported globals "ethereum.paris.vm.gas" "GAS_LOW". +Axiom ethereum_paris_vm_gas_imports_GAS_MID : + IsImported globals "ethereum.paris.vm.gas" "GAS_MID". +Axiom ethereum_paris_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.paris.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_paris_vm_gas_imports_charge_gas : + IsImported globals "ethereum.paris.vm.gas" "charge_gas". -Axiom ethereum_paris_vm_stack_imports : - AreImported globals "ethereum.paris.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_paris_vm_stack_imports_pop : + IsImported globals "ethereum.paris.vm.stack" "pop". +Axiom ethereum_paris_vm_stack_imports_push : + IsImported globals "ethereum.paris.vm.stack" "push". Definition add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,22 +63,26 @@ Definition add : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -69,14 +91,16 @@ Definition add : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "x" |), "wrapping_add" |), make_list [ M.get_name (| globals, "y" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -105,22 +129,26 @@ Definition sub : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -129,14 +157,16 @@ Definition sub : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "x" |), "wrapping_sub" |), make_list [ M.get_name (| globals, "y" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -165,22 +195,26 @@ Definition mul : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -189,14 +223,16 @@ Definition mul : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "x" |), "wrapping_mul" |), make_list [ M.get_name (| globals, "y" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -225,22 +261,26 @@ Definition div : Value.t -> Value.t -> M := The current EVM frame. " in - let dividend := + let _ := M.assign_local (| + "dividend" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let divisor := + |) + |) in + let _ := M.assign_local (| + "divisor" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -258,22 +298,26 @@ Definition div : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let quotient := + let _ := M.assign_local (| + "quotient" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let quotient := + let _ := M.assign_local (| + "quotient" , BinOp.floor_div (| M.get_name (| globals, "dividend" |), M.get_name (| globals, "divisor" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -304,7 +348,8 @@ Definition sdiv : Value.t -> Value.t -> M := The current EVM frame. " in - let dividend := + let _ := M.assign_local (| + "dividend" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -315,8 +360,10 @@ Definition sdiv : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let divisor := + |) + |) in + let _ := M.assign_local (| + "divisor" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -327,7 +374,8 @@ Definition sdiv : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -345,8 +393,10 @@ Definition sdiv : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let quotient := - Constant.int 0 in + let _ := M.assign_local (| + "quotient" , + Constant.int 0 + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -367,12 +417,15 @@ Definition sdiv : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let quotient := - UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in + let _ := M.assign_local (| + "quotient" , + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let sign := + let _ := M.assign_local (| + "sign" , M.call (| M.get_name (| globals, "get_sign" |), make_list [ @@ -382,8 +435,10 @@ Definition sdiv : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let quotient := + |) + |) in + let _ := M.assign_local (| + "quotient" , BinOp.mult (| M.get_name (| globals, "sign" |), BinOp.floor_div (| @@ -402,7 +457,8 @@ Definition sdiv : Value.t -> Value.t -> M := make_dict [] |) |) - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -428,7 +484,7 @@ Definition sdiv : Value.t -> Value.t -> M := |) in M.pure Constant.None_)). -Definition mod : Value.t -> Value.t -> M := +Definition mod_ : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in let _ := Constant.str " @@ -441,22 +497,26 @@ Definition mod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -474,22 +534,26 @@ Definition mod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let remainder := + let _ := M.assign_local (| + "remainder" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let remainder := + let _ := M.assign_local (| + "remainder" , BinOp.mod_ (| M.get_name (| globals, "x" |), M.get_name (| globals, "y" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -520,7 +584,8 @@ Definition smod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -531,8 +596,10 @@ Definition smod : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -543,7 +610,8 @@ Definition smod : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -561,12 +629,15 @@ Definition smod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let remainder := - Constant.int 0 in + let _ := M.assign_local (| + "remainder" , + Constant.int 0 + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let remainder := + let _ := M.assign_local (| + "remainder" , BinOp.mult (| M.call (| M.get_name (| globals, "get_sign" |), @@ -591,7 +662,8 @@ Definition smod : Value.t -> Value.t -> M := make_dict [] |) |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -628,7 +700,8 @@ Definition addmod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -641,8 +714,10 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -655,8 +730,10 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let z := + |) + |) in + let _ := M.assign_local (| + "z" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -669,7 +746,8 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -687,18 +765,21 @@ Definition addmod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -711,7 +792,8 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -742,7 +824,8 @@ Definition mulmod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -755,8 +838,10 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -769,8 +854,10 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let z := + |) + |) in + let _ := M.assign_local (| + "z" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -783,7 +870,8 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -801,18 +889,21 @@ Definition mulmod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -825,7 +916,8 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -856,7 +948,8 @@ Definition exp : Value.t -> Value.t -> M := The current EVM frame. " in - let base := + let _ := M.assign_local (| + "base" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -869,8 +962,10 @@ Definition exp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exponent := + |) + |) in + let _ := M.assign_local (| + "exponent" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -883,21 +978,26 @@ Definition exp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exponent_bits := + |) + |) in + let _ := M.assign_local (| + "exponent_bits" , M.call (| M.get_field (| M.get_name (| globals, "exponent" |), "bit_length" |), make_list [], make_dict [] - |) in - let exponent_bytes := + |) + |) in + let _ := M.assign_local (| + "exponent_bytes" , BinOp.floor_div (| BinOp.add (| M.get_name (| globals, "exponent_bits" |), Constant.int 7 |), Constant.int 8 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -912,7 +1012,8 @@ Definition exp : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -927,7 +1028,8 @@ Definition exp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -956,22 +1058,26 @@ Definition signextend : Value.t -> Value.t -> M := The current EVM frame. " in - let byte_num := + let _ := M.assign_local (| + "byte_num" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -989,12 +1095,15 @@ Definition signextend : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := - M.get_name (| globals, "value" |) in + let _ := M.assign_local (| + "result" , + M.get_name (| globals, "value" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let value_bytes := + let _ := M.assign_local (| + "value_bytes" , M.call (| M.get_name (| globals, "bytes" |), make_list [ @@ -1005,8 +1114,10 @@ Definition signextend : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let value_bytes := + |) + |) in + let _ := M.assign_local (| + "value_bytes" , M.slice (| M.get_name (| globals, "value_bytes" |), BinOp.sub (| @@ -1021,15 +1132,18 @@ Definition signextend : Value.t -> Value.t -> M := |), Constant.None_, Constant.None_ - |) in - let sign_bit := + |) + |) in + let _ := M.assign_local (| + "sign_bit" , BinOp.r_shift (| M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), Constant.int 7 - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1039,26 +1153,31 @@ Definition signextend : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "value_bytes" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let num_bytes_prepend := + let _ := M.assign_local (| + "num_bytes_prepend" , BinOp.sub (| Constant.int 32, BinOp.add (| M.get_name (| globals, "byte_num" |), Constant.int 1 |) - |) in - let result := + |) + |) in + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -1079,7 +1198,8 @@ Definition signextend : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/paris/vm/instructions/bitwise.v b/CoqOfPython/ethereum/paris/vm/instructions/bitwise.v index aed53c1..68e07c4 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/bitwise.v @@ -17,17 +17,23 @@ Introduction Implementations of the EVM bitwise instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "U256_CEIL_VALUE" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_U256_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U256_CEIL_VALUE". -Axiom ethereum_paris_vm_imports : - AreImported globals "ethereum.paris.vm" [ "Evm" ]. +Axiom ethereum_paris_vm_imports_Evm : + IsImported globals "ethereum.paris.vm" "Evm". -Axiom ethereum_paris_vm_gas_imports : - AreImported globals "ethereum.paris.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_paris_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.paris.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_paris_vm_gas_imports_charge_gas : + IsImported globals "ethereum.paris.vm.gas" "charge_gas". -Axiom ethereum_paris_vm_stack_imports : - AreImported globals "ethereum.paris.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_paris_vm_stack_imports_pop : + IsImported globals "ethereum.paris.vm.stack" "pop". +Axiom ethereum_paris_vm_stack_imports_push : + IsImported globals "ethereum.paris.vm.stack" "push". Definition bitwise_and : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,22 +48,26 @@ Definition bitwise_and : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -97,22 +107,26 @@ Definition bitwise_or : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -152,22 +166,26 @@ Definition bitwise_xor : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -207,14 +225,16 @@ Definition bitwise_not : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -252,22 +272,26 @@ Definition get_byte : Value.t -> Value.t -> M := The current EVM frame. " in - let byte_index := + let _ := M.assign_local (| + "byte_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let word := + |) + |) in + let _ := M.assign_local (| + "word" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -285,43 +309,53 @@ Definition get_byte : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let extra_bytes_to_right := + let _ := M.assign_local (| + "extra_bytes_to_right" , BinOp.sub (| Constant.int 31, M.get_name (| globals, "byte_index" |) - |) in - let word := + |) + |) in + let _ := M.assign_local (| + "word" , BinOp.r_shift (| M.get_name (| globals, "word" |), BinOp.mult (| M.get_name (| globals, "extra_bytes_to_right" |), Constant.int 8 |) - |) in - let word := + |) + |) in + let _ := M.assign_local (| + "word" , BinOp.bit_and (| M.get_name (| globals, "word" |), Constant.int 255 - |) in - let result := + |) + |) in + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ M.get_name (| globals, "word" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -350,22 +384,26 @@ Definition bitwise_shl : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let shift := + let _ := M.assign_local (| + "shift" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -383,7 +421,8 @@ Definition bitwise_shl : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -396,18 +435,21 @@ Definition bitwise_shl : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -436,22 +478,26 @@ Definition bitwise_shr : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let shift := + let _ := M.assign_local (| + "shift" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -469,22 +515,26 @@ Definition bitwise_shr : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , BinOp.r_shift (| M.get_name (| globals, "value" |), M.get_name (| globals, "shift" |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -513,15 +563,18 @@ Definition bitwise_sar : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let shift := + let _ := M.assign_local (| + "shift" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let signed_value := + |) + |) in + let _ := M.assign_local (| + "signed_value" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -532,7 +585,8 @@ Definition bitwise_sar : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -550,7 +604,8 @@ Definition bitwise_sar : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), make_list [ @@ -560,7 +615,8 @@ Definition bitwise_sar : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -573,19 +629,23 @@ Definition bitwise_sar : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := - M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) in + let _ := M.assign_local (| + "result" , + M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/paris/vm/instructions/block.v b/CoqOfPython/ethereum/paris/vm/instructions/block.v index 05a2cd3..5869617 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/block.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/block.v @@ -17,17 +17,23 @@ Introduction Implementations of the EVM block instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_paris_vm_imports : - AreImported globals "ethereum.paris.vm" [ "Evm" ]. +Axiom ethereum_paris_vm_imports_Evm : + IsImported globals "ethereum.paris.vm" "Evm". -Axiom ethereum_paris_vm_gas_imports : - AreImported globals "ethereum.paris.vm.gas" [ "GAS_BASE"; "GAS_BLOCK_HASH"; "charge_gas" ]. +Axiom ethereum_paris_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.paris.vm.gas" "GAS_BASE". +Axiom ethereum_paris_vm_gas_imports_GAS_BLOCK_HASH : + IsImported globals "ethereum.paris.vm.gas" "GAS_BLOCK_HASH". +Axiom ethereum_paris_vm_gas_imports_charge_gas : + IsImported globals "ethereum.paris.vm.gas" "charge_gas". -Axiom ethereum_paris_vm_stack_imports : - AreImported globals "ethereum.paris.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_paris_vm_stack_imports_pop : + IsImported globals "ethereum.paris.vm.stack" "pop". +Axiom ethereum_paris_vm_stack_imports_push : + IsImported globals "ethereum.paris.vm.stack" "push". Definition block_hash : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -48,14 +54,16 @@ Definition block_hash : Value.t -> Value.t -> M := :py:class:`~ethereum.paris.vm.exceptions.OutOfGasError` If `evm.gas_left` is less than `20`. " in - let block_number := + let _ := M.assign_local (| + "block_number" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -84,19 +92,23 @@ Definition block_hash : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let hash := - Constant.bytes "00" in + let _ := M.assign_local (| + "hash" , + Constant.bytes "00" + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let hash := + let _ := M.assign_local (| + "hash" , M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), M.get_name (| globals, "block_number" |) |) |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/paris/vm/instructions/comparison.v b/CoqOfPython/ethereum/paris/vm/instructions/comparison.v index b80d897..f0bbc4a 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/comparison.v @@ -17,17 +17,21 @@ Introduction Implementations of the EVM Comparison instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_paris_vm_imports : - AreImported globals "ethereum.paris.vm" [ "Evm" ]. +Axiom ethereum_paris_vm_imports_Evm : + IsImported globals "ethereum.paris.vm" "Evm". -Axiom ethereum_paris_vm_gas_imports : - AreImported globals "ethereum.paris.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_paris_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.paris.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_paris_vm_gas_imports_charge_gas : + IsImported globals "ethereum.paris.vm.gas" "charge_gas". -Axiom ethereum_paris_vm_stack_imports : - AreImported globals "ethereum.paris.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_paris_vm_stack_imports_pop : + IsImported globals "ethereum.paris.vm.stack" "pop". +Axiom ethereum_paris_vm_stack_imports_push : + IsImported globals "ethereum.paris.vm.stack" "push". Definition less_than : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,22 +46,26 @@ Definition less_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -66,7 +74,8 @@ Definition less_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -76,7 +85,8 @@ Definition less_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -104,7 +114,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -115,8 +126,10 @@ Definition signed_less_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -127,7 +140,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -136,7 +150,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -146,7 +161,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -175,22 +191,26 @@ Definition greater_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -199,7 +219,8 @@ Definition greater_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -209,7 +230,8 @@ Definition greater_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -237,7 +259,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -248,8 +271,10 @@ Definition signed_greater_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -260,7 +285,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -269,7 +295,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -279,7 +306,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -308,22 +336,26 @@ Definition equal : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -332,7 +364,8 @@ Definition equal : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -342,7 +375,8 @@ Definition equal : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -371,14 +405,16 @@ Definition is_zero : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -387,7 +423,8 @@ Definition is_zero : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -397,7 +434,8 @@ Definition is_zero : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/paris/vm/instructions/control_flow.v b/CoqOfPython/ethereum/paris/vm/instructions/control_flow.v index fa26588..077810e 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/control_flow.v @@ -17,20 +17,32 @@ Introduction Implementations of the EVM control flow instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_paris_vm_gas_imports : - AreImported globals "ethereum.paris.vm.gas" [ "GAS_BASE"; "GAS_HIGH"; "GAS_JUMPDEST"; "GAS_MID"; "charge_gas" ]. +Axiom ethereum_paris_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.paris.vm.gas" "GAS_BASE". +Axiom ethereum_paris_vm_gas_imports_GAS_HIGH : + IsImported globals "ethereum.paris.vm.gas" "GAS_HIGH". +Axiom ethereum_paris_vm_gas_imports_GAS_JUMPDEST : + IsImported globals "ethereum.paris.vm.gas" "GAS_JUMPDEST". +Axiom ethereum_paris_vm_gas_imports_GAS_MID : + IsImported globals "ethereum.paris.vm.gas" "GAS_MID". +Axiom ethereum_paris_vm_gas_imports_charge_gas : + IsImported globals "ethereum.paris.vm.gas" "charge_gas". -Axiom ethereum_paris_vm_imports : - AreImported globals "ethereum.paris.vm" [ "Evm" ]. +Axiom ethereum_paris_vm_imports_Evm : + IsImported globals "ethereum.paris.vm" "Evm". -Axiom ethereum_paris_vm_exceptions_imports : - AreImported globals "ethereum.paris.vm.exceptions" [ "InvalidJumpDestError" ]. +Axiom ethereum_paris_vm_exceptions_imports_InvalidJumpDestError : + IsImported globals "ethereum.paris.vm.exceptions" "InvalidJumpDestError". -Axiom ethereum_paris_vm_stack_imports : - AreImported globals "ethereum.paris.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_paris_vm_stack_imports_pop : + IsImported globals "ethereum.paris.vm.stack" "pop". +Axiom ethereum_paris_vm_stack_imports_push : + IsImported globals "ethereum.paris.vm.stack" "push". Definition stop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -69,7 +81,8 @@ Definition jump : Value.t -> Value.t -> M := The current EVM frame. " in - let jump_dest := + let _ := M.assign_local (| + "jump_dest" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -82,7 +95,8 @@ Definition jump : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -132,7 +146,8 @@ Definition jumpi : Value.t -> Value.t -> M := The current EVM frame. " in - let jump_dest := + let _ := M.assign_local (| + "jump_dest" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -145,15 +160,18 @@ Definition jumpi : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let conditional_value := + |) + |) in + let _ := M.assign_local (| + "conditional_value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -171,11 +189,13 @@ Definition jumpi : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let destination := + let _ := M.assign_local (| + "destination" , BinOp.add (| M.get_field (| M.get_name (| globals, "evm" |), "pc" |), Constant.int 1 - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -192,8 +212,10 @@ Definition jumpi : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let destination := - M.get_name (| globals, "jump_dest" |) in + let _ := M.assign_local (| + "destination" , + M.get_name (| globals, "jump_dest" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/paris/vm/instructions/environment.v b/CoqOfPython/ethereum/paris/vm/instructions/environment.v index 5b2a06c..44987c3 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/environment.v @@ -17,41 +17,63 @@ Introduction Implementations of the EVM environment related instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. - -Axiom ethereum_paris_fork_types_imports : - AreImported globals "ethereum.paris.fork_types" [ "EMPTY_ACCOUNT" ]. - -Axiom ethereum_paris_state_imports : - AreImported globals "ethereum.paris.state" [ "get_account" ]. - -Axiom ethereum_paris_utils_address_imports : - AreImported globals "ethereum.paris.utils.address" [ "to_address" ]. - -Axiom ethereum_paris_vm_memory_imports : - AreImported globals "ethereum.paris.vm.memory" [ "buffer_read"; "memory_write" ]. - -Axiom ethereum_paris_vm_imports : - AreImported globals "ethereum.paris.vm" [ "Evm" ]. - -Axiom ethereum_paris_vm_exceptions_imports : - AreImported globals "ethereum.paris.vm.exceptions" [ "OutOfBoundsRead" ]. - -Axiom ethereum_paris_vm_gas_imports : - AreImported globals "ethereum.paris.vm.gas" [ "GAS_BASE"; "GAS_COLD_ACCOUNT_ACCESS"; "GAS_COPY"; "GAS_FAST_STEP"; "GAS_RETURN_DATA_COPY"; "GAS_VERY_LOW"; "GAS_WARM_ACCESS"; "calculate_gas_extend_memory"; "charge_gas" ]. - -Axiom ethereum_paris_vm_stack_imports : - AreImported globals "ethereum.paris.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". + +Axiom ethereum_paris_fork_types_imports_EMPTY_ACCOUNT : + IsImported globals "ethereum.paris.fork_types" "EMPTY_ACCOUNT". + +Axiom ethereum_paris_state_imports_get_account : + IsImported globals "ethereum.paris.state" "get_account". + +Axiom ethereum_paris_utils_address_imports_to_address : + IsImported globals "ethereum.paris.utils.address" "to_address". + +Axiom ethereum_paris_vm_memory_imports_buffer_read : + IsImported globals "ethereum.paris.vm.memory" "buffer_read". +Axiom ethereum_paris_vm_memory_imports_memory_write : + IsImported globals "ethereum.paris.vm.memory" "memory_write". + +Axiom ethereum_paris_vm_imports_Evm : + IsImported globals "ethereum.paris.vm" "Evm". + +Axiom ethereum_paris_vm_exceptions_imports_OutOfBoundsRead : + IsImported globals "ethereum.paris.vm.exceptions" "OutOfBoundsRead". + +Axiom ethereum_paris_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.paris.vm.gas" "GAS_BASE". +Axiom ethereum_paris_vm_gas_imports_GAS_COLD_ACCOUNT_ACCESS : + IsImported globals "ethereum.paris.vm.gas" "GAS_COLD_ACCOUNT_ACCESS". +Axiom ethereum_paris_vm_gas_imports_GAS_COPY : + IsImported globals "ethereum.paris.vm.gas" "GAS_COPY". +Axiom ethereum_paris_vm_gas_imports_GAS_FAST_STEP : + IsImported globals "ethereum.paris.vm.gas" "GAS_FAST_STEP". +Axiom ethereum_paris_vm_gas_imports_GAS_RETURN_DATA_COPY : + IsImported globals "ethereum.paris.vm.gas" "GAS_RETURN_DATA_COPY". +Axiom ethereum_paris_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.paris.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_paris_vm_gas_imports_GAS_WARM_ACCESS : + IsImported globals "ethereum.paris.vm.gas" "GAS_WARM_ACCESS". +Axiom ethereum_paris_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.paris.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_paris_vm_gas_imports_charge_gas : + IsImported globals "ethereum.paris.vm.gas" "charge_gas". + +Axiom ethereum_paris_vm_stack_imports_pop : + IsImported globals "ethereum.paris.vm.stack" "pop". +Axiom ethereum_paris_vm_stack_imports_push : + IsImported globals "ethereum.paris.vm.stack" "push". Definition address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -107,7 +129,8 @@ Definition balance : Value.t -> Value.t -> M := The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -120,7 +143,8 @@ Definition balance : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -158,7 +182,8 @@ Definition balance : Value.t -> Value.t -> M := |) in M.pure Constant.None_ )) |) in - let balance := + let _ := M.assign_local (| + "balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -166,7 +191,8 @@ Definition balance : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -316,14 +342,16 @@ Definition calldataload : Value.t -> Value.t -> M := The current EVM frame. " in - let start_index := + let _ := M.assign_local (| + "start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -332,7 +360,8 @@ Definition calldataload : Value.t -> Value.t -> M := ], make_dict [] |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -347,7 +376,8 @@ Definition calldataload : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -432,31 +462,38 @@ Definition calldatacopy : Value.t -> Value.t -> M := The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let data_start_index := + |) + |) in + let _ := M.assign_local (| + "data_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -472,13 +509,17 @@ Definition calldatacopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -488,7 +529,8 @@ Definition calldatacopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -511,7 +553,8 @@ Definition calldatacopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -520,7 +563,8 @@ Definition calldatacopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -600,31 +644,38 @@ Definition codecopy : Value.t -> Value.t -> M := The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let code_start_index := + |) + |) in + let _ := M.assign_local (| + "code_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -640,13 +691,17 @@ Definition codecopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -656,7 +711,8 @@ Definition codecopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -679,7 +735,8 @@ Definition codecopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -688,7 +745,8 @@ Definition codecopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -759,7 +817,8 @@ Definition extcodesize : Value.t -> Value.t -> M := The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -772,7 +831,8 @@ Definition extcodesize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -810,7 +870,8 @@ Definition extcodesize : Value.t -> Value.t -> M := |) in M.pure Constant.None_ )) |) in - let codesize := + let _ := M.assign_local (| + "codesize" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -830,7 +891,8 @@ Definition extcodesize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -858,7 +920,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -871,32 +934,40 @@ Definition extcodecopy : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let memory_start_index := + |) + |) in + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let code_start_index := + |) + |) in + let _ := M.assign_local (| + "code_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -912,13 +983,17 @@ Definition extcodecopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -928,7 +1003,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -986,7 +1062,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let code := + let _ := M.assign_local (| + "code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -994,8 +1071,10 @@ Definition extcodecopy : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |), "code" |) in - let value := + |), "code" |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -1004,7 +1083,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -1079,31 +1159,38 @@ Definition returndatacopy : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let return_data_start_position := + |) + |) in + let _ := M.assign_local (| + "return_data_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -1119,13 +1206,17 @@ Definition returndatacopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_RETURN_DATA_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1135,7 +1226,8 @@ Definition returndatacopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1190,7 +1282,8 @@ Definition returndatacopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.slice (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |), @@ -1199,7 +1292,8 @@ Definition returndatacopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) |), Constant.None_ - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -1226,7 +1320,8 @@ Definition extcodehash : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1239,7 +1334,8 @@ Definition extcodehash : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1277,7 +1373,8 @@ Definition extcodehash : Value.t -> Value.t -> M := |) in M.pure Constant.None_ )) |) in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1285,7 +1382,8 @@ Definition extcodehash : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1295,18 +1393,21 @@ Definition extcodehash : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let codehash := + let _ := M.assign_local (| + "codehash" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let codehash := + let _ := M.assign_local (| + "codehash" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -1319,7 +1420,8 @@ Definition extcodehash : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -1358,7 +1460,8 @@ Definition self_balance : Value.t -> Value.t -> M := ], make_dict [] |) in - let balance := + let _ := M.assign_local (| + "balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1366,7 +1469,8 @@ Definition self_balance : Value.t -> Value.t -> M := M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/paris/vm/instructions/keccak.v b/CoqOfPython/ethereum/paris/vm/instructions/keccak.v index 12f0bec..e935544 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/keccak.v @@ -17,26 +17,36 @@ Introduction Implementations of the EVM keccak instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_paris_vm_imports : - AreImported globals "ethereum.paris.vm" [ "Evm" ]. +Axiom ethereum_paris_vm_imports_Evm : + IsImported globals "ethereum.paris.vm" "Evm". -Axiom ethereum_paris_vm_gas_imports : - AreImported globals "ethereum.paris.vm.gas" [ "GAS_KECCAK256"; "GAS_KECCAK256_WORD"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_paris_vm_gas_imports_GAS_KECCAK256 : + IsImported globals "ethereum.paris.vm.gas" "GAS_KECCAK256". +Axiom ethereum_paris_vm_gas_imports_GAS_KECCAK256_WORD : + IsImported globals "ethereum.paris.vm.gas" "GAS_KECCAK256_WORD". +Axiom ethereum_paris_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.paris.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_paris_vm_gas_imports_charge_gas : + IsImported globals "ethereum.paris.vm.gas" "charge_gas". -Axiom ethereum_paris_vm_memory_imports : - AreImported globals "ethereum.paris.vm.memory" [ "memory_read_bytes" ]. +Axiom ethereum_paris_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.paris.vm.memory" "memory_read_bytes". -Axiom ethereum_paris_vm_stack_imports : - AreImported globals "ethereum.paris.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_paris_vm_stack_imports_pop : + IsImported globals "ethereum.paris.vm.stack" "pop". +Axiom ethereum_paris_vm_stack_imports_push : + IsImported globals "ethereum.paris.vm.stack" "push". Definition keccak : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -53,23 +63,28 @@ Definition keccak : Value.t -> Value.t -> M := The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -85,13 +100,17 @@ Definition keccak : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let word_gas_cost := + |) + |) in + let _ := M.assign_local (| + "word_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_KECCAK256_WORD" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -101,7 +120,8 @@ Definition keccak : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -124,7 +144,8 @@ Definition keccak : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let data := + let _ := M.assign_local (| + "data" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -133,15 +154,18 @@ Definition keccak : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in - let hash := + |) + |) in + let _ := M.assign_local (| + "hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "data" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/paris/vm/instructions/log.v b/CoqOfPython/ethereum/paris/vm/instructions/log.v index 3c8093d..e38fab2 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/log.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/log.v @@ -17,32 +17,40 @@ Introduction Implementations of the EVM logging instructions. ". -Axiom functools_imports : - AreImported globals "functools" [ "partial" ]. +Axiom functools_imports_partial : + IsImported globals "functools" "partial". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_paris_blocks_imports : - AreImported globals "ethereum.paris.blocks" [ "Log" ]. +Axiom ethereum_paris_blocks_imports_Log : + IsImported globals "ethereum.paris.blocks" "Log". -Axiom ethereum_paris_vm_imports : - AreImported globals "ethereum.paris.vm" [ "Evm" ]. +Axiom ethereum_paris_vm_imports_Evm : + IsImported globals "ethereum.paris.vm" "Evm". -Axiom ethereum_paris_vm_exceptions_imports : - AreImported globals "ethereum.paris.vm.exceptions" [ "WriteInStaticContext" ]. +Axiom ethereum_paris_vm_exceptions_imports_WriteInStaticContext : + IsImported globals "ethereum.paris.vm.exceptions" "WriteInStaticContext". -Axiom ethereum_paris_vm_gas_imports : - AreImported globals "ethereum.paris.vm.gas" [ "GAS_LOG"; "GAS_LOG_DATA"; "GAS_LOG_TOPIC"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_paris_vm_gas_imports_GAS_LOG : + IsImported globals "ethereum.paris.vm.gas" "GAS_LOG". +Axiom ethereum_paris_vm_gas_imports_GAS_LOG_DATA : + IsImported globals "ethereum.paris.vm.gas" "GAS_LOG_DATA". +Axiom ethereum_paris_vm_gas_imports_GAS_LOG_TOPIC : + IsImported globals "ethereum.paris.vm.gas" "GAS_LOG_TOPIC". +Axiom ethereum_paris_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.paris.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_paris_vm_gas_imports_charge_gas : + IsImported globals "ethereum.paris.vm.gas" "charge_gas". -Axiom ethereum_paris_vm_memory_imports : - AreImported globals "ethereum.paris.vm.memory" [ "memory_read_bytes" ]. +Axiom ethereum_paris_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.paris.vm.memory" "memory_read_bytes". -Axiom ethereum_paris_vm_stack_imports : - AreImported globals "ethereum.paris.vm.stack" [ "pop" ]. +Axiom ethereum_paris_vm_stack_imports_pop : + IsImported globals "ethereum.paris.vm.stack" "pop". Definition log_n : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -61,24 +69,30 @@ Definition log_n : Value.t -> Value.t -> M := The number of topics to be included in the log entry. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let topics := - make_list [] in + |) + |) in + let _ := M.assign_local (| + "topics" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "_" |), @@ -90,7 +104,8 @@ Definition log_n : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let topic := + let _ := M.assign_local (| + "topic" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -101,7 +116,8 @@ Definition log_n : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "topics" |), "append" |), make_list [ @@ -115,7 +131,8 @@ Definition log_n : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let extend_memory := + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -125,7 +142,8 @@ Definition log_n : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -165,12 +183,14 @@ Definition log_n : Value.t -> Value.t -> M := ], make_dict [] |) in - let log_entry := + let _ := M.assign_local (| + "log_entry" , M.call (| M.get_name (| globals, "Log" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "logs" |), BinOp.add (| diff --git a/CoqOfPython/ethereum/paris/vm/instructions/memory.v b/CoqOfPython/ethereum/paris/vm/instructions/memory.v index 4c214b5..211fafb 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/memory.v @@ -17,20 +17,32 @@ Introduction Implementations of the EVM Memory instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". -Axiom ethereum_paris_vm_imports : - AreImported globals "ethereum.paris.vm" [ "Evm" ]. +Axiom ethereum_paris_vm_imports_Evm : + IsImported globals "ethereum.paris.vm" "Evm". -Axiom ethereum_paris_vm_gas_imports : - AreImported globals "ethereum.paris.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_paris_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.paris.vm.gas" "GAS_BASE". +Axiom ethereum_paris_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.paris.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_paris_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.paris.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_paris_vm_gas_imports_charge_gas : + IsImported globals "ethereum.paris.vm.gas" "charge_gas". -Axiom ethereum_paris_vm_memory_imports : - AreImported globals "ethereum.paris.vm.memory" [ "memory_read_bytes"; "memory_write" ]. +Axiom ethereum_paris_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.paris.vm.memory" "memory_read_bytes". +Axiom ethereum_paris_vm_memory_imports_memory_write : + IsImported globals "ethereum.paris.vm.memory" "memory_write". -Axiom ethereum_paris_vm_stack_imports : - AreImported globals "ethereum.paris.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_paris_vm_stack_imports_pop : + IsImported globals "ethereum.paris.vm.stack" "pop". +Axiom ethereum_paris_vm_stack_imports_push : + IsImported globals "ethereum.paris.vm.stack" "push". Definition mstore : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -46,15 +58,18 @@ Definition mstore : Value.t -> Value.t -> M := The current EVM frame. " in - let start_position := + let _ := M.assign_local (| + "start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -65,8 +80,10 @@ Definition mstore : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -88,7 +105,8 @@ Definition mstore : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -138,23 +156,28 @@ Definition mstore8 : Value.t -> Value.t -> M := The current EVM frame. " in - let start_position := + let _ := M.assign_local (| + "start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -170,7 +193,8 @@ Definition mstore8 : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -190,7 +214,8 @@ Definition mstore8 : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let normalized_bytes_value := + let _ := M.assign_local (| + "normalized_bytes_value" , M.call (| M.get_name (| globals, "Bytes" |), make_list [ @@ -202,7 +227,8 @@ Definition mstore8 : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -231,15 +257,18 @@ Definition mload : Value.t -> Value.t -> M := The current EVM frame. " in - let start_position := + let _ := M.assign_local (| + "start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -255,7 +284,8 @@ Definition mload : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -275,7 +305,8 @@ Definition mload : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -296,7 +327,8 @@ Definition mload : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/paris/vm/instructions/stack.v b/CoqOfPython/ethereum/paris/vm/instructions/stack.v index 1a7d994..7c6a4bf 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/stack.v @@ -17,26 +17,32 @@ Introduction Implementations of the EVM stack related instructions. ". -Axiom functools_imports : - AreImported globals "functools" [ "partial" ]. +Axiom functools_imports_partial : + IsImported globals "functools" "partial". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_paris_vm_imports : - AreImported globals "ethereum.paris.vm" [ "Evm"; "stack" ]. +Axiom ethereum_paris_vm_imports_Evm : + IsImported globals "ethereum.paris.vm" "Evm". +Axiom ethereum_paris_vm_imports_stack : + IsImported globals "ethereum.paris.vm" "stack". -Axiom ethereum_paris_vm_exceptions_imports : - AreImported globals "ethereum.paris.vm.exceptions" [ "StackUnderflowError" ]. +Axiom ethereum_paris_vm_exceptions_imports_StackUnderflowError : + IsImported globals "ethereum.paris.vm.exceptions" "StackUnderflowError". -Axiom ethereum_paris_vm_gas_imports : - AreImported globals "ethereum.paris.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_paris_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.paris.vm.gas" "GAS_BASE". +Axiom ethereum_paris_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.paris.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_paris_vm_gas_imports_charge_gas : + IsImported globals "ethereum.paris.vm.gas" "charge_gas". -Axiom ethereum_paris_vm_memory_imports : - AreImported globals "ethereum.paris.vm.memory" [ "buffer_read" ]. +Axiom ethereum_paris_vm_memory_imports_buffer_read : + IsImported globals "ethereum.paris.vm.memory" "buffer_read". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -98,7 +104,8 @@ Definition push_n : Value.t -> Value.t -> M := ], make_dict [] |) in - let data_to_push := + let _ := M.assign_local (| + "data_to_push" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -128,7 +135,8 @@ Definition push_n : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "stack" |), "push" |), make_list [ @@ -189,7 +197,8 @@ Definition dup_n : Value.t -> Value.t -> M := ], make_dict [] |) in - let data_to_duplicate := + let _ := M.assign_local (| + "data_to_duplicate" , M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| @@ -205,7 +214,8 @@ Definition dup_n : Value.t -> Value.t -> M := |), M.get_name (| globals, "item_number" |) |) - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "stack" |), "push" |), make_list [ diff --git a/CoqOfPython/ethereum/paris/vm/instructions/storage.v b/CoqOfPython/ethereum/paris/vm/instructions/storage.v index 236ef48..760b3c6 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/storage.v @@ -17,26 +17,46 @@ Introduction Implementations of the EVM storage related instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_paris_state_imports : - AreImported globals "ethereum.paris.state" [ "get_storage"; "get_storage_original"; "set_storage" ]. +Axiom ethereum_paris_state_imports_get_storage : + IsImported globals "ethereum.paris.state" "get_storage". +Axiom ethereum_paris_state_imports_get_storage_original : + IsImported globals "ethereum.paris.state" "get_storage_original". +Axiom ethereum_paris_state_imports_set_storage : + IsImported globals "ethereum.paris.state" "set_storage". -Axiom ethereum_paris_vm_imports : - AreImported globals "ethereum.paris.vm" [ "Evm" ]. +Axiom ethereum_paris_vm_imports_Evm : + IsImported globals "ethereum.paris.vm" "Evm". -Axiom ethereum_paris_vm_exceptions_imports : - AreImported globals "ethereum.paris.vm.exceptions" [ "OutOfGasError"; "WriteInStaticContext" ]. +Axiom ethereum_paris_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.paris.vm.exceptions" "OutOfGasError". +Axiom ethereum_paris_vm_exceptions_imports_WriteInStaticContext : + IsImported globals "ethereum.paris.vm.exceptions" "WriteInStaticContext". -Axiom ethereum_paris_vm_gas_imports : - AreImported globals "ethereum.paris.vm.gas" [ "GAS_CALL_STIPEND"; "GAS_COLD_SLOAD"; "GAS_STORAGE_CLEAR_REFUND"; "GAS_STORAGE_SET"; "GAS_STORAGE_UPDATE"; "GAS_WARM_ACCESS"; "charge_gas" ]. +Axiom ethereum_paris_vm_gas_imports_GAS_CALL_STIPEND : + IsImported globals "ethereum.paris.vm.gas" "GAS_CALL_STIPEND". +Axiom ethereum_paris_vm_gas_imports_GAS_COLD_SLOAD : + IsImported globals "ethereum.paris.vm.gas" "GAS_COLD_SLOAD". +Axiom ethereum_paris_vm_gas_imports_GAS_STORAGE_CLEAR_REFUND : + IsImported globals "ethereum.paris.vm.gas" "GAS_STORAGE_CLEAR_REFUND". +Axiom ethereum_paris_vm_gas_imports_GAS_STORAGE_SET : + IsImported globals "ethereum.paris.vm.gas" "GAS_STORAGE_SET". +Axiom ethereum_paris_vm_gas_imports_GAS_STORAGE_UPDATE : + IsImported globals "ethereum.paris.vm.gas" "GAS_STORAGE_UPDATE". +Axiom ethereum_paris_vm_gas_imports_GAS_WARM_ACCESS : + IsImported globals "ethereum.paris.vm.gas" "GAS_WARM_ACCESS". +Axiom ethereum_paris_vm_gas_imports_charge_gas : + IsImported globals "ethereum.paris.vm.gas" "charge_gas". -Axiom ethereum_paris_vm_stack_imports : - AreImported globals "ethereum.paris.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_paris_vm_stack_imports_pop : + IsImported globals "ethereum.paris.vm.stack" "pop". +Axiom ethereum_paris_vm_stack_imports_push : + IsImported globals "ethereum.paris.vm.stack" "push". Definition sload : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -51,7 +71,8 @@ Definition sload : Value.t -> Value.t -> M := The current EVM frame. " in - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -62,7 +83,8 @@ Definition sload : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -100,7 +122,8 @@ Definition sload : Value.t -> Value.t -> M := |) in M.pure Constant.None_ )) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "get_storage" |), make_list [ @@ -109,7 +132,8 @@ Definition sload : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -137,7 +161,8 @@ Definition sstore : Value.t -> Value.t -> M := The current EVM frame. " in - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -148,15 +173,18 @@ Definition sstore : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in - let new_value := + |) + |) in + let _ := M.assign_local (| + "new_value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -168,7 +196,8 @@ Definition sstore : Value.t -> Value.t -> M := ], make_dict [] |) in - let original_value := + let _ := M.assign_local (| + "original_value" , M.call (| M.get_name (| globals, "get_storage_original" |), make_list [ @@ -177,8 +206,10 @@ Definition sstore : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in - let current_value := + |) + |) in + let _ := M.assign_local (| + "current_value" , M.call (| M.get_name (| globals, "get_storage" |), make_list [ @@ -187,15 +218,18 @@ Definition sstore : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in - let gas_cost := + |) + |) in + let _ := M.assign_local (| + "gas_cost" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -212,9 +246,11 @@ Definition sstore : Value.t -> Value.t -> M := ], make_dict [] |) in - let gas_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "gas_cost", M.get_name (| globals, "GAS_COLD_SLOAD" |) - M.get_name (| globals, "GAS_COLD_SLOAD" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -246,29 +282,32 @@ Definition sstore : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let gas_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "gas_cost", M.get_name (| globals, "GAS_STORAGE_SET" |) - M.get_name (| globals, "GAS_STORAGE_SET" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let gas_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "gas_cost", BinOp.sub (| M.get_name (| globals, "GAS_STORAGE_UPDATE" |), M.get_name (| globals, "GAS_COLD_SLOAD" |) |) - BinOp.sub (| - M.get_name (| globals, "GAS_STORAGE_UPDATE" |), - M.get_name (| globals, "GAS_COLD_SLOAD" |) - |) in + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let gas_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "gas_cost", M.get_name (| globals, "GAS_WARM_ACCESS" |) - M.get_name (| globals, "GAS_WARM_ACCESS" |) in + |) in M.pure Constant.None_ )) |) in let _ := diff --git a/CoqOfPython/ethereum/paris/vm/instructions/system.v b/CoqOfPython/ethereum/paris/vm/instructions/system.v index 303ebfa..2ed4520 100644 --- a/CoqOfPython/ethereum/paris/vm/instructions/system.v +++ b/CoqOfPython/ethereum/paris/vm/instructions/system.v @@ -17,38 +17,92 @@ Introduction Implementations of the EVM system related instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_paris_fork_types_imports : - AreImported globals "ethereum.paris.fork_types" [ "Address" ]. +Axiom ethereum_paris_fork_types_imports_Address : + IsImported globals "ethereum.paris.fork_types" "Address". -Axiom ethereum_paris_state_imports : - AreImported globals "ethereum.paris.state" [ "account_exists_and_is_empty"; "account_has_code_or_nonce"; "get_account"; "increment_nonce"; "is_account_alive"; "set_account_balance" ]. +Axiom ethereum_paris_state_imports_account_exists_and_is_empty : + IsImported globals "ethereum.paris.state" "account_exists_and_is_empty". +Axiom ethereum_paris_state_imports_account_has_code_or_nonce : + IsImported globals "ethereum.paris.state" "account_has_code_or_nonce". +Axiom ethereum_paris_state_imports_get_account : + IsImported globals "ethereum.paris.state" "get_account". +Axiom ethereum_paris_state_imports_increment_nonce : + IsImported globals "ethereum.paris.state" "increment_nonce". +Axiom ethereum_paris_state_imports_is_account_alive : + IsImported globals "ethereum.paris.state" "is_account_alive". +Axiom ethereum_paris_state_imports_set_account_balance : + IsImported globals "ethereum.paris.state" "set_account_balance". -Axiom ethereum_paris_utils_address_imports : - AreImported globals "ethereum.paris.utils.address" [ "compute_contract_address"; "compute_create2_contract_address"; "to_address" ]. +Axiom ethereum_paris_utils_address_imports_compute_contract_address : + IsImported globals "ethereum.paris.utils.address" "compute_contract_address". +Axiom ethereum_paris_utils_address_imports_compute_create2_contract_address : + IsImported globals "ethereum.paris.utils.address" "compute_create2_contract_address". +Axiom ethereum_paris_utils_address_imports_to_address : + IsImported globals "ethereum.paris.utils.address" "to_address". -Axiom ethereum_paris_vm_imports : - AreImported globals "ethereum.paris.vm" [ "Evm"; "Message"; "incorporate_child_on_error"; "incorporate_child_on_success" ]. +Axiom ethereum_paris_vm_imports_Evm : + IsImported globals "ethereum.paris.vm" "Evm". +Axiom ethereum_paris_vm_imports_Message : + IsImported globals "ethereum.paris.vm" "Message". +Axiom ethereum_paris_vm_imports_incorporate_child_on_error : + IsImported globals "ethereum.paris.vm" "incorporate_child_on_error". +Axiom ethereum_paris_vm_imports_incorporate_child_on_success : + IsImported globals "ethereum.paris.vm" "incorporate_child_on_success". -Axiom ethereum_paris_vm_exceptions_imports : - AreImported globals "ethereum.paris.vm.exceptions" [ "Revert"; "WriteInStaticContext" ]. +Axiom ethereum_paris_vm_exceptions_imports_Revert : + IsImported globals "ethereum.paris.vm.exceptions" "Revert". +Axiom ethereum_paris_vm_exceptions_imports_WriteInStaticContext : + IsImported globals "ethereum.paris.vm.exceptions" "WriteInStaticContext". -Axiom ethereum_paris_vm_gas_imports : - AreImported globals "ethereum.paris.vm.gas" [ "GAS_CALL_VALUE"; "GAS_COLD_ACCOUNT_ACCESS"; "GAS_CREATE"; "GAS_KECCAK256_WORD"; "GAS_NEW_ACCOUNT"; "GAS_SELF_DESTRUCT"; "GAS_SELF_DESTRUCT_NEW_ACCOUNT"; "GAS_WARM_ACCESS"; "GAS_ZERO"; "calculate_gas_extend_memory"; "calculate_message_call_gas"; "charge_gas"; "max_message_call_gas" ]. +Axiom ethereum_paris_vm_gas_imports_GAS_CALL_VALUE : + IsImported globals "ethereum.paris.vm.gas" "GAS_CALL_VALUE". +Axiom ethereum_paris_vm_gas_imports_GAS_COLD_ACCOUNT_ACCESS : + IsImported globals "ethereum.paris.vm.gas" "GAS_COLD_ACCOUNT_ACCESS". +Axiom ethereum_paris_vm_gas_imports_GAS_CREATE : + IsImported globals "ethereum.paris.vm.gas" "GAS_CREATE". +Axiom ethereum_paris_vm_gas_imports_GAS_KECCAK256_WORD : + IsImported globals "ethereum.paris.vm.gas" "GAS_KECCAK256_WORD". +Axiom ethereum_paris_vm_gas_imports_GAS_NEW_ACCOUNT : + IsImported globals "ethereum.paris.vm.gas" "GAS_NEW_ACCOUNT". +Axiom ethereum_paris_vm_gas_imports_GAS_SELF_DESTRUCT : + IsImported globals "ethereum.paris.vm.gas" "GAS_SELF_DESTRUCT". +Axiom ethereum_paris_vm_gas_imports_GAS_SELF_DESTRUCT_NEW_ACCOUNT : + IsImported globals "ethereum.paris.vm.gas" "GAS_SELF_DESTRUCT_NEW_ACCOUNT". +Axiom ethereum_paris_vm_gas_imports_GAS_WARM_ACCESS : + IsImported globals "ethereum.paris.vm.gas" "GAS_WARM_ACCESS". +Axiom ethereum_paris_vm_gas_imports_GAS_ZERO : + IsImported globals "ethereum.paris.vm.gas" "GAS_ZERO". +Axiom ethereum_paris_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.paris.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_paris_vm_gas_imports_calculate_message_call_gas : + IsImported globals "ethereum.paris.vm.gas" "calculate_message_call_gas". +Axiom ethereum_paris_vm_gas_imports_charge_gas : + IsImported globals "ethereum.paris.vm.gas" "charge_gas". +Axiom ethereum_paris_vm_gas_imports_max_message_call_gas : + IsImported globals "ethereum.paris.vm.gas" "max_message_call_gas". -Axiom ethereum_paris_vm_memory_imports : - AreImported globals "ethereum.paris.vm.memory" [ "memory_read_bytes"; "memory_write" ]. +Axiom ethereum_paris_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.paris.vm.memory" "memory_read_bytes". +Axiom ethereum_paris_vm_memory_imports_memory_write : + IsImported globals "ethereum.paris.vm.memory" "memory_write". -Axiom ethereum_paris_vm_stack_imports : - AreImported globals "ethereum.paris.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_paris_vm_stack_imports_pop : + IsImported globals "ethereum.paris.vm.stack" "pop". +Axiom ethereum_paris_vm_stack_imports_push : + IsImported globals "ethereum.paris.vm.stack" "push". Definition generic_create : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -64,7 +118,8 @@ Definition generic_create : Value.t -> Value.t -> M := ], make_dict [] |) in - let create_message_gas := + let _ := M.assign_local (| + "create_message_gas" , M.call (| M.get_name (| globals, "max_message_call_gas" |), make_list [ @@ -77,7 +132,8 @@ Definition generic_create : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.assign_op (| BinOp.sub, M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), @@ -95,9 +151,12 @@ Definition generic_create : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), Constant.bytes "" |) in - let sender_address := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in - let sender := + let _ := M.assign_local (| + "sender_address" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + |) in + let _ := M.assign_local (| + "sender" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -105,7 +164,8 @@ Definition generic_create : Value.t -> Value.t -> M := M.get_name (| globals, "sender_address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -216,7 +276,8 @@ Definition generic_create : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let call_data := + let _ := M.assign_local (| + "call_data" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -225,7 +286,8 @@ Definition generic_create : Value.t -> Value.t -> M := M.get_name (| globals, "memory_size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "increment_nonce" |), make_list [ @@ -234,13 +296,16 @@ Definition generic_create : Value.t -> Value.t -> M := ], make_dict [] |) in - let child_message := + let _ := M.assign_local (| + "child_message" , M.call (| M.get_name (| globals, "Message" |), make_list [], make_dict [] - |) in - let child_evm := + |) + |) in + let _ := M.assign_local (| + "child_evm" , M.call (| M.get_name (| globals, "process_create_message" |), make_list [ @@ -248,7 +313,8 @@ Definition generic_create : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -325,31 +391,38 @@ Definition create : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let endowment := + let _ := M.assign_local (| + "endowment" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_size := + |) + |) in + let _ := M.assign_local (| + "memory_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -359,7 +432,8 @@ Definition create : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -379,7 +453,8 @@ Definition create : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let contract_address := + let _ := M.assign_local (| + "contract_address" , M.call (| M.get_name (| globals, "compute_contract_address" |), make_list [ @@ -394,7 +469,8 @@ Definition create : Value.t -> Value.t -> M := |), "nonce" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "generic_create" |), make_list [ @@ -427,31 +503,38 @@ Definition create2 : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let endowment := + let _ := M.assign_local (| + "endowment" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_size := + |) + |) in + let _ := M.assign_local (| + "memory_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let salt := + |) + |) in + let _ := M.assign_local (| + "salt" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -462,8 +545,10 @@ Definition create2 : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -473,8 +558,10 @@ Definition create2 : Value.t -> Value.t -> M := ] ], make_dict [] - |) in - let call_data_words := + |) + |) in + let _ := M.assign_local (| + "call_data_words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -490,7 +577,8 @@ Definition create2 : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -516,7 +604,8 @@ Definition create2 : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let contract_address := + let _ := M.assign_local (| + "contract_address" , M.call (| M.get_name (| globals, "compute_create2_contract_address" |), make_list [ @@ -533,7 +622,8 @@ Definition create2 : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "generic_create" |), make_list [ @@ -563,23 +653,28 @@ Definition return_ : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let memory_start_position := + let _ := M.assign_local (| + "memory_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_size := + |) + |) in + let _ := M.assign_local (| + "memory_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -589,7 +684,8 @@ Definition return_ : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -678,7 +774,8 @@ Definition generic_call : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let call_data := + let _ := M.assign_local (| + "call_data" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -687,8 +784,10 @@ Definition generic_call : Value.t -> Value.t -> M := M.get_name (| globals, "memory_input_size" |) ], make_dict [] - |) in - let code := + |) + |) in + let _ := M.assign_local (| + "code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -696,14 +795,18 @@ Definition generic_call : Value.t -> Value.t -> M := M.get_name (| globals, "code_address" |) ], make_dict [] - |), "code" |) in - let child_message := + |), "code" |) + |) in + let _ := M.assign_local (| + "child_message" , M.call (| M.get_name (| globals, "Message" |), make_list [], make_dict [] - |) in - let child_evm := + |) + |) in + let _ := M.assign_local (| + "child_evm" , M.call (| M.get_name (| globals, "process_message" |), make_list [ @@ -711,7 +814,8 @@ Definition generic_call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -775,7 +879,8 @@ Definition generic_call : Value.t -> Value.t -> M := |) in M.pure Constant.None_ )) |) in - let actual_output_size := + let _ := M.assign_local (| + "actual_output_size" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -795,7 +900,8 @@ Definition generic_call : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -823,7 +929,8 @@ Definition call : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -836,8 +943,10 @@ Definition call : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let to := + |) + |) in + let _ := M.assign_local (| + "to" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -850,48 +959,60 @@ Definition call : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -902,7 +1023,8 @@ Definition call : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -912,8 +1034,10 @@ Definition call : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let access_gas_cost := - M.get_name (| globals, "GAS_WARM_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -924,11 +1048,14 @@ Definition call : Value.t -> Value.t -> M := ], make_dict [] |) in - let access_gas_cost := - M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + |) in M.pure Constant.None_ )) |) in - let create_gas_cost := + let _ := M.assign_local (| + "create_gas_cost" , (* if *) M.if_then_else (| BoolOp.or (| @@ -959,8 +1086,10 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "GAS_NEW_ACCOUNT" |) - )) |) in - let transfer_gas_cost := + )) |) + |) in + let _ := M.assign_local (| + "transfer_gas_cost" , (* if *) M.if_then_else (| Compare.eq (| @@ -979,8 +1108,10 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "GAS_CALL_VALUE" |) - )) |) in - let message_call_gas := + )) |) + |) in + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -1003,7 +1134,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1045,7 +1177,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let sender_balance := + let _ := M.assign_local (| + "sender_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1053,7 +1186,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := (* if *) M.if_then_else (| @@ -1127,7 +1261,8 @@ Definition callcode : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -1140,8 +1275,10 @@ Definition callcode : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let code_address := + |) + |) in + let _ := M.assign_local (| + "code_address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1154,50 +1291,64 @@ Definition callcode : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let to := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "to" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1208,7 +1359,8 @@ Definition callcode : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1218,8 +1370,10 @@ Definition callcode : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let access_gas_cost := - M.get_name (| globals, "GAS_WARM_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1230,11 +1384,14 @@ Definition callcode : Value.t -> Value.t -> M := ], make_dict [] |) in - let access_gas_cost := - M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + |) in M.pure Constant.None_ )) |) in - let transfer_gas_cost := + let _ := M.assign_local (| + "transfer_gas_cost" , (* if *) M.if_then_else (| Compare.eq (| @@ -1253,8 +1410,10 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "GAS_CALL_VALUE" |) - )) |) in - let message_call_gas := + )) |) + |) in + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -1274,7 +1433,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1294,7 +1454,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let sender_balance := + let _ := M.assign_local (| + "sender_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1302,7 +1463,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := (* if *) M.if_then_else (| @@ -1376,7 +1538,8 @@ Definition selfdestruct : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let beneficiary := + let _ := M.assign_local (| + "beneficiary" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1389,9 +1552,12 @@ Definition selfdestruct : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let gas_cost := - M.get_name (| globals, "GAS_SELF_DESTRUCT" |) in + |) + |) in + let _ := M.assign_local (| + "gas_cost" , + M.get_name (| globals, "GAS_SELF_DESTRUCT" |) + |) in let _ := (* if *) M.if_then_else (| @@ -1408,9 +1574,11 @@ Definition selfdestruct : Value.t -> Value.t -> M := ], make_dict [] |) in - let gas_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "gas_cost", M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) - M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1444,9 +1612,11 @@ Definition selfdestruct : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let gas_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "gas_cost", M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) - M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1468,9 +1638,12 @@ Definition selfdestruct : Value.t -> Value.t -> M := ], make_dict [] |) in - let originator := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in - let beneficiary_balance := + let _ := M.assign_local (| + "originator" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + |) in + let _ := M.assign_local (| + "beneficiary_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1478,8 +1651,10 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_name (| globals, "beneficiary" |) ], make_dict [] - |), "balance" |) in - let originator_balance := + |), "balance" |) + |) in + let _ := M.assign_local (| + "originator_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1487,7 +1662,8 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_name (| globals, "originator" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -1565,7 +1741,8 @@ Definition delegatecall : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -1578,8 +1755,10 @@ Definition delegatecall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let code_address := + |) + |) in + let _ := M.assign_local (| + "code_address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1592,40 +1771,50 @@ Definition delegatecall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1636,7 +1825,8 @@ Definition delegatecall : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1646,8 +1836,10 @@ Definition delegatecall : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let access_gas_cost := - M.get_name (| globals, "GAS_WARM_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1658,11 +1850,14 @@ Definition delegatecall : Value.t -> Value.t -> M := ], make_dict [] |) in - let access_gas_cost := - M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + |) in M.pure Constant.None_ )) |) in - let message_call_gas := + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -1685,7 +1880,8 @@ Definition delegatecall : Value.t -> Value.t -> M := M.get_name (| globals, "access_gas_cost" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1741,7 +1937,8 @@ Definition staticcall : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -1754,8 +1951,10 @@ Definition staticcall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let to := + |) + |) in + let _ := M.assign_local (| + "to" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1768,40 +1967,50 @@ Definition staticcall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1812,7 +2021,8 @@ Definition staticcall : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1822,8 +2032,10 @@ Definition staticcall : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let access_gas_cost := - M.get_name (| globals, "GAS_WARM_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1834,11 +2046,14 @@ Definition staticcall : Value.t -> Value.t -> M := ], make_dict [] |) in - let access_gas_cost := - M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + |) in M.pure Constant.None_ )) |) in - let message_call_gas := + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -1861,7 +2076,8 @@ Definition staticcall : Value.t -> Value.t -> M := M.get_name (| globals, "access_gas_cost" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1923,23 +2139,28 @@ Definition revert : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1949,7 +2170,8 @@ Definition revert : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1966,7 +2188,8 @@ Definition revert : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let output := + let _ := M.assign_local (| + "output" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -1975,7 +2198,8 @@ Definition revert : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| diff --git a/CoqOfPython/ethereum/paris/vm/interpreter.v b/CoqOfPython/ethereum/paris/vm/interpreter.v index f9d52c1..ddfc003 100644 --- a/CoqOfPython/ethereum/paris/vm/interpreter.v +++ b/CoqOfPython/ethereum/paris/vm/interpreter.v @@ -17,50 +17,114 @@ Introduction A straightforward interpreter that executes EVM code. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Iterable"; "Optional"; "Set"; "Tuple"; "Union" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. - -Axiom ethereum_trace_imports : - AreImported globals "ethereum.trace" [ "EvmStop"; "OpEnd"; "OpException"; "OpStart"; "PrecompileEnd"; "PrecompileStart"; "TransactionEnd"; "evm_trace" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_paris_blocks_imports : - AreImported globals "ethereum.paris.blocks" [ "Log" ]. - -Axiom ethereum_paris_fork_types_imports : - AreImported globals "ethereum.paris.fork_types" [ "Address" ]. - -Axiom ethereum_paris_state_imports : - AreImported globals "ethereum.paris.state" [ "account_exists_and_is_empty"; "account_has_code_or_nonce"; "begin_transaction"; "commit_transaction"; "destroy_storage"; "increment_nonce"; "mark_account_created"; "move_ether"; "rollback_transaction"; "set_code"; "touch_account" ]. - -Axiom ethereum_paris_vm_imports : - AreImported globals "ethereum.paris.vm" [ "Message" ]. - -Axiom ethereum_paris_vm_gas_imports : - AreImported globals "ethereum.paris.vm.gas" [ "GAS_CODE_DEPOSIT"; "charge_gas" ]. - -Axiom ethereum_paris_vm_precompiled_contracts_mapping_imports : - AreImported globals "ethereum.paris.vm.precompiled_contracts.mapping" [ "PRE_COMPILED_CONTRACTS" ]. - -Axiom ethereum_paris_vm_imports : - AreImported globals "ethereum.paris.vm" [ "Environment"; "Evm" ]. - -Axiom ethereum_paris_vm_exceptions_imports : - AreImported globals "ethereum.paris.vm.exceptions" [ "AddressCollision"; "ExceptionalHalt"; "InvalidContractPrefix"; "InvalidOpcode"; "OutOfGasError"; "Revert"; "StackDepthLimitError" ]. - -Axiom ethereum_paris_vm_instructions_imports : - AreImported globals "ethereum.paris.vm.instructions" [ "Ops"; "op_implementation" ]. - -Axiom ethereum_paris_vm_runtime_imports : - AreImported globals "ethereum.paris.vm.runtime" [ "get_valid_jump_destinations" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_Iterable : + IsImported globals "typing" "Iterable". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_trace_imports_EvmStop : + IsImported globals "ethereum.trace" "EvmStop". +Axiom ethereum_trace_imports_OpEnd : + IsImported globals "ethereum.trace" "OpEnd". +Axiom ethereum_trace_imports_OpException : + IsImported globals "ethereum.trace" "OpException". +Axiom ethereum_trace_imports_OpStart : + IsImported globals "ethereum.trace" "OpStart". +Axiom ethereum_trace_imports_PrecompileEnd : + IsImported globals "ethereum.trace" "PrecompileEnd". +Axiom ethereum_trace_imports_PrecompileStart : + IsImported globals "ethereum.trace" "PrecompileStart". +Axiom ethereum_trace_imports_TransactionEnd : + IsImported globals "ethereum.trace" "TransactionEnd". +Axiom ethereum_trace_imports_evm_trace : + IsImported globals "ethereum.trace" "evm_trace". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_paris_blocks_imports_Log : + IsImported globals "ethereum.paris.blocks" "Log". + +Axiom ethereum_paris_fork_types_imports_Address : + IsImported globals "ethereum.paris.fork_types" "Address". + +Axiom ethereum_paris_state_imports_account_exists_and_is_empty : + IsImported globals "ethereum.paris.state" "account_exists_and_is_empty". +Axiom ethereum_paris_state_imports_account_has_code_or_nonce : + IsImported globals "ethereum.paris.state" "account_has_code_or_nonce". +Axiom ethereum_paris_state_imports_begin_transaction : + IsImported globals "ethereum.paris.state" "begin_transaction". +Axiom ethereum_paris_state_imports_commit_transaction : + IsImported globals "ethereum.paris.state" "commit_transaction". +Axiom ethereum_paris_state_imports_destroy_storage : + IsImported globals "ethereum.paris.state" "destroy_storage". +Axiom ethereum_paris_state_imports_increment_nonce : + IsImported globals "ethereum.paris.state" "increment_nonce". +Axiom ethereum_paris_state_imports_mark_account_created : + IsImported globals "ethereum.paris.state" "mark_account_created". +Axiom ethereum_paris_state_imports_move_ether : + IsImported globals "ethereum.paris.state" "move_ether". +Axiom ethereum_paris_state_imports_rollback_transaction : + IsImported globals "ethereum.paris.state" "rollback_transaction". +Axiom ethereum_paris_state_imports_set_code : + IsImported globals "ethereum.paris.state" "set_code". +Axiom ethereum_paris_state_imports_touch_account : + IsImported globals "ethereum.paris.state" "touch_account". + +Axiom ethereum_paris_vm_imports_Message : + IsImported globals "ethereum.paris.vm" "Message". + +Axiom ethereum_paris_vm_gas_imports_GAS_CODE_DEPOSIT : + IsImported globals "ethereum.paris.vm.gas" "GAS_CODE_DEPOSIT". +Axiom ethereum_paris_vm_gas_imports_charge_gas : + IsImported globals "ethereum.paris.vm.gas" "charge_gas". + +Axiom ethereum_paris_vm_precompiled_contracts_mapping_imports_PRE_COMPILED_CONTRACTS : + IsImported globals "ethereum.paris.vm.precompiled_contracts.mapping" "PRE_COMPILED_CONTRACTS". + +Axiom ethereum_paris_vm_imports_Environment : + IsImported globals "ethereum.paris.vm" "Environment". +Axiom ethereum_paris_vm_imports_Evm : + IsImported globals "ethereum.paris.vm" "Evm". + +Axiom ethereum_paris_vm_exceptions_imports_AddressCollision : + IsImported globals "ethereum.paris.vm.exceptions" "AddressCollision". +Axiom ethereum_paris_vm_exceptions_imports_ExceptionalHalt : + IsImported globals "ethereum.paris.vm.exceptions" "ExceptionalHalt". +Axiom ethereum_paris_vm_exceptions_imports_InvalidContractPrefix : + IsImported globals "ethereum.paris.vm.exceptions" "InvalidContractPrefix". +Axiom ethereum_paris_vm_exceptions_imports_InvalidOpcode : + IsImported globals "ethereum.paris.vm.exceptions" "InvalidOpcode". +Axiom ethereum_paris_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.paris.vm.exceptions" "OutOfGasError". +Axiom ethereum_paris_vm_exceptions_imports_Revert : + IsImported globals "ethereum.paris.vm.exceptions" "Revert". +Axiom ethereum_paris_vm_exceptions_imports_StackDepthLimitError : + IsImported globals "ethereum.paris.vm.exceptions" "StackDepthLimitError". + +Axiom ethereum_paris_vm_instructions_imports_Ops : + IsImported globals "ethereum.paris.vm.instructions" "Ops". +Axiom ethereum_paris_vm_instructions_imports_op_implementation : + IsImported globals "ethereum.paris.vm.instructions" "op_implementation". + +Axiom ethereum_paris_vm_runtime_imports_get_valid_jump_destinations : + IsImported globals "ethereum.paris.vm.runtime" "get_valid_jump_destinations". Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -121,7 +185,8 @@ Definition process_message_call : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let is_collision := + let _ := M.assign_local (| + "is_collision" , M.call (| M.get_name (| globals, "account_has_code_or_nonce" |), make_list [ @@ -129,7 +194,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "message" |), "current_target" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -181,7 +247,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "process_create_message" |), make_list [ @@ -189,13 +256,15 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "process_message" |), make_list [ @@ -203,7 +272,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -250,46 +320,61 @@ Definition process_message_call : Value.t -> Value.t -> M := (* then *) ltac:(M.monadic ( (* At stmt: unsupported node type: AnnAssign *) - let accounts_to_delete := + let _ := M.assign_local (| + "accounts_to_delete" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let touched_accounts := + |) + |) in + let _ := M.assign_local (| + "touched_accounts" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let refund_counter := + |) + |) in + let _ := M.assign_local (| + "refund_counter" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let logs := - M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in - let accounts_to_delete := - M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in - let touched_accounts := - M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |) in - let refund_counter := + let _ := M.assign_local (| + "logs" , + M.get_field (| M.get_name (| globals, "evm" |), "logs" |) + |) in + let _ := M.assign_local (| + "accounts_to_delete" , + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) + |) in + let _ := M.assign_local (| + "touched_accounts" , + M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |) + |) in + let _ := M.assign_local (| + "refund_counter" , M.call (| M.get_name (| globals, "U256" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in - let tx_end := + let _ := M.assign_local (| + "tx_end" , M.call (| M.get_name (| globals, "TransactionEnd" |), make_list [ @@ -301,7 +386,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "error" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "evm_trace" |), make_list [ @@ -368,7 +454,8 @@ Definition process_create_message : Value.t -> Value.t -> M := ], make_dict [] |) in - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "process_message" |), make_list [ @@ -376,16 +463,20 @@ Definition process_create_message : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), (* then *) ltac:(M.monadic ( - let contract_code := - M.get_field (| M.get_name (| globals, "evm" |), "output" |) in - let contract_code_gas := + let _ := M.assign_local (| + "contract_code" , + M.get_field (| M.get_name (| globals, "evm" |), "output" |) + |) in + let _ := M.assign_local (| + "contract_code_gas" , BinOp.mult (| M.call (| M.get_name (| globals, "len" |), @@ -395,7 +486,8 @@ Definition process_create_message : Value.t -> Value.t -> M := make_dict [] |), M.get_name (| globals, "GAS_CODE_DEPOSIT" |) - |) in + |) + |) in (* At stmt: unsupported node type: Try *) M.pure Constant.None_ (* else *) @@ -497,7 +589,8 @@ Definition process_message : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "execute_code" |), make_list [ @@ -505,7 +598,8 @@ Definition process_message : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -554,22 +648,28 @@ Definition execute_code : Value.t -> Value.t -> M := evm: `ethereum.vm.EVM` Items containing execution specific objects " in - let code := - M.get_field (| M.get_name (| globals, "message" |), "code" |) in - let valid_jump_destinations := + let _ := M.assign_local (| + "code" , + M.get_field (| M.get_name (| globals, "message" |), "code" |) + |) in + let _ := M.assign_local (| + "valid_jump_destinations" , M.call (| M.get_name (| globals, "get_valid_jump_destinations" |), make_list [ M.get_name (| globals, "code" |) ], make_dict [] - |) in - let evm := + |) + |) in + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "Evm" |), make_list [], make_dict [] - |) in + |) + |) in (* At stmt: unsupported node type: Try *) let _ := M.return_ (| M.get_name (| globals, "evm" |) diff --git a/CoqOfPython/ethereum/paris/vm/memory.v b/CoqOfPython/ethereum/paris/vm/memory.v index 72ec45f..0a1308d 100644 --- a/CoqOfPython/ethereum/paris/vm/memory.v +++ b/CoqOfPython/ethereum/paris/vm/memory.v @@ -17,11 +17,15 @@ Introduction EVM memory operations. ". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "right_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_right_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "right_pad_zero_bytes". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". Definition memory_write : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/__init__.v index a7d0bd0..0726d50 100644 --- a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/__init__.v +++ b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/__init__.v @@ -18,8 +18,8 @@ Addresses of precompiled contracts and mappings to their implementations. ". -Axiom ethereum_paris_utils_hexadecimal_imports : - AreImported globals "ethereum.paris.utils.hexadecimal" [ "hex_to_address" ]. +Axiom ethereum_paris_utils_hexadecimal_imports_hex_to_address : + IsImported globals "ethereum.paris.utils.hexadecimal" "hex_to_address". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS"; Constant.str "MODEXP_ADDRESS"; Constant.str "ALT_BN128_ADD_ADDRESS"; Constant.str "ALT_BN128_MUL_ADDRESS"; Constant.str "ALT_BN128_PAIRING_CHECK_ADDRESS"; Constant.str "BLAKE2F_ADDRESS" ] diff --git a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/alt_bn128.v index 8c25271..21ebabe 100644 --- a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/alt_bn128.v +++ b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/alt_bn128.v @@ -17,26 +17,42 @@ Introduction Implementation of the ALT_BN128 precompiled contracts. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_alt_bn128_imports : - AreImported globals "ethereum.crypto.alt_bn128" [ "ALT_BN128_CURVE_ORDER"; "ALT_BN128_PRIME"; "BNF"; "BNF2"; "BNF12"; "BNP"; "BNP2"; "pairing" ]. +Axiom ethereum_crypto_alt_bn128_imports_ALT_BN128_CURVE_ORDER : + IsImported globals "ethereum.crypto.alt_bn128" "ALT_BN128_CURVE_ORDER". +Axiom ethereum_crypto_alt_bn128_imports_ALT_BN128_PRIME : + IsImported globals "ethereum.crypto.alt_bn128" "ALT_BN128_PRIME". +Axiom ethereum_crypto_alt_bn128_imports_BNF : + IsImported globals "ethereum.crypto.alt_bn128" "BNF". +Axiom ethereum_crypto_alt_bn128_imports_BNF2 : + IsImported globals "ethereum.crypto.alt_bn128" "BNF2". +Axiom ethereum_crypto_alt_bn128_imports_BNF12 : + IsImported globals "ethereum.crypto.alt_bn128" "BNF12". +Axiom ethereum_crypto_alt_bn128_imports_BNP : + IsImported globals "ethereum.crypto.alt_bn128" "BNP". +Axiom ethereum_crypto_alt_bn128_imports_BNP2 : + IsImported globals "ethereum.crypto.alt_bn128" "BNP2". +Axiom ethereum_crypto_alt_bn128_imports_pairing : + IsImported globals "ethereum.crypto.alt_bn128" "pairing". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_paris_vm_imports : - AreImported globals "ethereum.paris.vm" [ "Evm" ]. +Axiom ethereum_paris_vm_imports_Evm : + IsImported globals "ethereum.paris.vm" "Evm". -Axiom ethereum_paris_vm_gas_imports : - AreImported globals "ethereum.paris.vm.gas" [ "charge_gas" ]. +Axiom ethereum_paris_vm_gas_imports_charge_gas : + IsImported globals "ethereum.paris.vm.gas" "charge_gas". -Axiom ethereum_paris_vm_memory_imports : - AreImported globals "ethereum.paris.vm.memory" [ "buffer_read" ]. +Axiom ethereum_paris_vm_memory_imports_buffer_read : + IsImported globals "ethereum.paris.vm.memory" "buffer_read". -Axiom ethereum_paris_vm_exceptions_imports : - AreImported globals "ethereum.paris.vm.exceptions" [ "OutOfGasError" ]. +Axiom ethereum_paris_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.paris.vm.exceptions" "OutOfGasError". Definition alt_bn128_add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -49,8 +65,10 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -65,7 +83,8 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := ], make_dict [] |) in - let x0_bytes := + let _ := M.assign_local (| + "x0_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -86,16 +105,20 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let x0_value := + |) + |) in + let _ := M.assign_local (| + "x0_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "x0_bytes" |) ], make_dict [] - |) in - let y0_bytes := + |) + |) in + let _ := M.assign_local (| + "y0_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -116,16 +139,20 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y0_value := + |) + |) in + let _ := M.assign_local (| + "y0_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "y0_bytes" |) ], make_dict [] - |) in - let x1_bytes := + |) + |) in + let _ := M.assign_local (| + "x1_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -146,16 +173,20 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let x1_value := + |) + |) in + let _ := M.assign_local (| + "x1_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "x1_bytes" |) ], make_dict [] - |) in - let y1_bytes := + |) + |) in + let _ := M.assign_local (| + "y1_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -176,15 +207,18 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y1_value := + |) + |) in + let _ := M.assign_local (| + "y1_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "y1_bytes" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "i" |), @@ -212,11 +246,13 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := )) |) in (* At stmt: unsupported node type: Try *) - let p := + let _ := M.assign_local (| + "p" , BinOp.add (| M.get_name (| globals, "p0" |), M.get_name (| globals, "p1" |) - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), BinOp.add (| @@ -245,8 +281,10 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -261,7 +299,8 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := ], make_dict [] |) in - let x0_bytes := + let _ := M.assign_local (| + "x0_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -282,16 +321,20 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let x0_value := + |) + |) in + let _ := M.assign_local (| + "x0_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "x0_bytes" |) ], make_dict [] - |) in - let y0_bytes := + |) + |) in + let _ := M.assign_local (| + "y0_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -312,16 +355,20 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y0_value := + |) + |) in + let _ := M.assign_local (| + "y0_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "y0_bytes" |) ], make_dict [] - |) in - let n := + |) + |) in + let _ := M.assign_local (| + "n" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -348,7 +395,8 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "i" |), @@ -376,14 +424,16 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := )) |) in (* At stmt: unsupported node type: Try *) - let p := + let _ := M.assign_local (| + "p" , M.call (| M.get_field (| M.get_name (| globals, "p0" |), "mul_by" |), make_list [ M.get_name (| globals, "n" |) ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), BinOp.add (| @@ -412,8 +462,10 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -467,14 +519,16 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), make_list [ Constant.int 1 ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "i" |), @@ -495,8 +549,10 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let values := - make_list [] in + let _ := M.assign_local (| + "values" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "j" |), @@ -508,7 +564,8 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -541,7 +598,8 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -644,7 +702,8 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , BinOp.mult (| M.get_name (| globals, "result" |), M.call (| @@ -655,7 +714,8 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/blake2f.v b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/blake2f.v index 77a5a42..e4c8b13 100644 --- a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/blake2f.v +++ b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/blake2f.v @@ -17,20 +17,22 @@ Introduction Implementation of the `Blake2` precompiled contract. ". -Axiom ethereum_crypto_blake2_imports : - AreImported globals "ethereum.crypto.blake2" [ "Blake2b" ]. +Axiom ethereum_crypto_blake2_imports_Blake2b : + IsImported globals "ethereum.crypto.blake2" "Blake2b". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_paris_vm_imports : - AreImported globals "ethereum.paris.vm" [ "Evm" ]. +Axiom ethereum_paris_vm_imports_Evm : + IsImported globals "ethereum.paris.vm" "Evm". -Axiom ethereum_paris_vm_gas_imports : - AreImported globals "ethereum.paris.vm.gas" [ "GAS_BLAKE2_PER_ROUND"; "charge_gas" ]. +Axiom ethereum_paris_vm_gas_imports_GAS_BLAKE2_PER_ROUND : + IsImported globals "ethereum.paris.vm.gas" "GAS_BLAKE2_PER_ROUND". +Axiom ethereum_paris_vm_gas_imports_charge_gas : + IsImported globals "ethereum.paris.vm.gas" "charge_gas". -Axiom ethereum_paris_vm_exceptions_imports : - AreImported globals "ethereum.paris.vm.exceptions" [ "InvalidParameter" ]. +Axiom ethereum_paris_vm_exceptions_imports_InvalidParameter : + IsImported globals "ethereum.paris.vm.exceptions" "InvalidParameter". Definition blake2f : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -43,8 +45,10 @@ Definition blake2f : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -62,12 +66,14 @@ Definition blake2f : Value.t -> Value.t -> M := ], make_dict [] |) in - let blake2b := + let _ := M.assign_local (| + "blake2b" , M.call (| M.get_name (| globals, "Blake2b" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "rounds" |); M.get_name (| globals, "h" |); M.get_name (| globals, "m" |); M.get_name (| globals, "t_0" |); M.get_name (| globals, "t_1" |); M.get_name (| globals, "f" |) ], M.call (| diff --git a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/ecrecover.v index c1ca85f..62c83c2 100644 --- a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/ecrecover.v @@ -17,26 +17,32 @@ Introduction Implementation of the ECRECOVER precompiled contract. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_crypto_elliptic_curve_imports : - AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. +Axiom ethereum_crypto_elliptic_curve_imports_SECP256K1N : + IsImported globals "ethereum.crypto.elliptic_curve" "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_imports_secp256k1_recover : + IsImported globals "ethereum.crypto.elliptic_curve" "secp256k1_recover". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_left_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "left_pad_zero_bytes". -Axiom ethereum_paris_vm_imports : - AreImported globals "ethereum.paris.vm" [ "Evm" ]. +Axiom ethereum_paris_vm_imports_Evm : + IsImported globals "ethereum.paris.vm" "Evm". -Axiom ethereum_paris_vm_gas_imports : - AreImported globals "ethereum.paris.vm.gas" [ "GAS_ECRECOVER"; "charge_gas" ]. +Axiom ethereum_paris_vm_gas_imports_GAS_ECRECOVER : + IsImported globals "ethereum.paris.vm.gas" "GAS_ECRECOVER". +Axiom ethereum_paris_vm_gas_imports_charge_gas : + IsImported globals "ethereum.paris.vm.gas" "charge_gas". -Axiom ethereum_paris_vm_memory_imports : - AreImported globals "ethereum.paris.vm.memory" [ "buffer_read" ]. +Axiom ethereum_paris_vm_memory_imports_buffer_read : + IsImported globals "ethereum.paris.vm.memory" "buffer_read". Definition ecrecover : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -50,8 +56,10 @@ Definition ecrecover : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -60,7 +68,8 @@ Definition ecrecover : Value.t -> Value.t -> M := ], make_dict [] |) in - let message_hash_bytes := + let _ := M.assign_local (| + "message_hash_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -81,16 +90,20 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let message_hash := + |) + |) in + let _ := M.assign_local (| + "message_hash" , M.call (| M.get_name (| globals, "Hash32" |), make_list [ M.get_name (| globals, "message_hash_bytes" |) ], make_dict [] - |) in - let v := + |) + |) in + let _ := M.assign_local (| + "v" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -117,8 +130,10 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let r := + |) + |) in + let _ := M.assign_local (| + "r" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -145,8 +160,10 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let s := + |) + |) in + let _ := M.assign_local (| + "s" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -173,7 +190,8 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -250,7 +268,8 @@ Definition ecrecover : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: Try *) - let address := + let _ := M.assign_local (| + "address" , M.slice (| M.call (| M.get_name (| globals, "keccak256" |), @@ -262,8 +281,10 @@ Definition ecrecover : Value.t -> Value.t -> M := Constant.int 12, Constant.int 32, Constant.None_ - |) in - let padded_address := + |) + |) in + let _ := M.assign_local (| + "padded_address" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -271,7 +292,8 @@ Definition ecrecover : Value.t -> Value.t -> M := Constant.int 32 ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.get_name (| globals, "padded_address" |) diff --git a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/identity.v index 1ccc7ab..1936c37 100644 --- a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/identity.v +++ b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/identity.v @@ -17,17 +17,21 @@ Introduction Implementation of the `IDENTITY` precompiled contract. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_paris_vm_imports : - AreImported globals "ethereum.paris.vm" [ "Evm" ]. +Axiom ethereum_paris_vm_imports_Evm : + IsImported globals "ethereum.paris.vm" "Evm". -Axiom ethereum_paris_vm_gas_imports : - AreImported globals "ethereum.paris.vm.gas" [ "GAS_IDENTITY"; "GAS_IDENTITY_WORD"; "charge_gas" ]. +Axiom ethereum_paris_vm_gas_imports_GAS_IDENTITY : + IsImported globals "ethereum.paris.vm.gas" "GAS_IDENTITY". +Axiom ethereum_paris_vm_gas_imports_GAS_IDENTITY_WORD : + IsImported globals "ethereum.paris.vm.gas" "GAS_IDENTITY_WORD". +Axiom ethereum_paris_vm_gas_imports_charge_gas : + IsImported globals "ethereum.paris.vm.gas" "charge_gas". Definition identity : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -40,9 +44,12 @@ Definition identity : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let word_count := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "word_count" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -64,7 +71,8 @@ Definition identity : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ diff --git a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/mapping.v index 45e83d9..eb81d35 100644 --- a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/mapping.v +++ b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/mapping.v @@ -17,34 +17,56 @@ Introduction Mapping of precompiled contracts their implementations. ". -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict" ]. - -Axiom ethereum_paris_fork_types_imports : - AreImported globals "ethereum.paris.fork_types" [ "Address" ]. - -Axiom ethereum_paris_vm_precompiled_contracts_imports : - AreImported globals "ethereum.paris.vm.precompiled_contracts" [ "ALT_BN128_ADD_ADDRESS"; "ALT_BN128_MUL_ADDRESS"; "ALT_BN128_PAIRING_CHECK_ADDRESS"; "BLAKE2F_ADDRESS"; "ECRECOVER_ADDRESS"; "IDENTITY_ADDRESS"; "MODEXP_ADDRESS"; "RIPEMD160_ADDRESS"; "SHA256_ADDRESS" ]. - -Axiom ethereum_paris_vm_precompiled_contracts_alt_bn128_imports : - AreImported globals "ethereum.paris.vm.precompiled_contracts.alt_bn128" [ "alt_bn128_add"; "alt_bn128_mul"; "alt_bn128_pairing_check" ]. - -Axiom ethereum_paris_vm_precompiled_contracts_blake2f_imports : - AreImported globals "ethereum.paris.vm.precompiled_contracts.blake2f" [ "blake2f" ]. - -Axiom ethereum_paris_vm_precompiled_contracts_ecrecover_imports : - AreImported globals "ethereum.paris.vm.precompiled_contracts.ecrecover" [ "ecrecover" ]. - -Axiom ethereum_paris_vm_precompiled_contracts_identity_imports : - AreImported globals "ethereum.paris.vm.precompiled_contracts.identity" [ "identity" ]. - -Axiom ethereum_paris_vm_precompiled_contracts_modexp_imports : - AreImported globals "ethereum.paris.vm.precompiled_contracts.modexp" [ "modexp" ]. - -Axiom ethereum_paris_vm_precompiled_contracts_ripemd160_imports : - AreImported globals "ethereum.paris.vm.precompiled_contracts.ripemd160" [ "ripemd160" ]. - -Axiom ethereum_paris_vm_precompiled_contracts_sha256_imports : - AreImported globals "ethereum.paris.vm.precompiled_contracts.sha256" [ "sha256" ]. +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". + +Axiom ethereum_paris_fork_types_imports_Address : + IsImported globals "ethereum.paris.fork_types" "Address". + +Axiom ethereum_paris_vm_precompiled_contracts_imports_ALT_BN128_ADD_ADDRESS : + IsImported globals "ethereum.paris.vm.precompiled_contracts" "ALT_BN128_ADD_ADDRESS". +Axiom ethereum_paris_vm_precompiled_contracts_imports_ALT_BN128_MUL_ADDRESS : + IsImported globals "ethereum.paris.vm.precompiled_contracts" "ALT_BN128_MUL_ADDRESS". +Axiom ethereum_paris_vm_precompiled_contracts_imports_ALT_BN128_PAIRING_CHECK_ADDRESS : + IsImported globals "ethereum.paris.vm.precompiled_contracts" "ALT_BN128_PAIRING_CHECK_ADDRESS". +Axiom ethereum_paris_vm_precompiled_contracts_imports_BLAKE2F_ADDRESS : + IsImported globals "ethereum.paris.vm.precompiled_contracts" "BLAKE2F_ADDRESS". +Axiom ethereum_paris_vm_precompiled_contracts_imports_ECRECOVER_ADDRESS : + IsImported globals "ethereum.paris.vm.precompiled_contracts" "ECRECOVER_ADDRESS". +Axiom ethereum_paris_vm_precompiled_contracts_imports_IDENTITY_ADDRESS : + IsImported globals "ethereum.paris.vm.precompiled_contracts" "IDENTITY_ADDRESS". +Axiom ethereum_paris_vm_precompiled_contracts_imports_MODEXP_ADDRESS : + IsImported globals "ethereum.paris.vm.precompiled_contracts" "MODEXP_ADDRESS". +Axiom ethereum_paris_vm_precompiled_contracts_imports_RIPEMD160_ADDRESS : + IsImported globals "ethereum.paris.vm.precompiled_contracts" "RIPEMD160_ADDRESS". +Axiom ethereum_paris_vm_precompiled_contracts_imports_SHA256_ADDRESS : + IsImported globals "ethereum.paris.vm.precompiled_contracts" "SHA256_ADDRESS". + +Axiom ethereum_paris_vm_precompiled_contracts_alt_bn128_imports_alt_bn128_add : + IsImported globals "ethereum.paris.vm.precompiled_contracts.alt_bn128" "alt_bn128_add". +Axiom ethereum_paris_vm_precompiled_contracts_alt_bn128_imports_alt_bn128_mul : + IsImported globals "ethereum.paris.vm.precompiled_contracts.alt_bn128" "alt_bn128_mul". +Axiom ethereum_paris_vm_precompiled_contracts_alt_bn128_imports_alt_bn128_pairing_check : + IsImported globals "ethereum.paris.vm.precompiled_contracts.alt_bn128" "alt_bn128_pairing_check". + +Axiom ethereum_paris_vm_precompiled_contracts_blake2f_imports_blake2f : + IsImported globals "ethereum.paris.vm.precompiled_contracts.blake2f" "blake2f". + +Axiom ethereum_paris_vm_precompiled_contracts_ecrecover_imports_ecrecover : + IsImported globals "ethereum.paris.vm.precompiled_contracts.ecrecover" "ecrecover". + +Axiom ethereum_paris_vm_precompiled_contracts_identity_imports_identity : + IsImported globals "ethereum.paris.vm.precompiled_contracts.identity" "identity". + +Axiom ethereum_paris_vm_precompiled_contracts_modexp_imports_modexp : + IsImported globals "ethereum.paris.vm.precompiled_contracts.modexp" "modexp". + +Axiom ethereum_paris_vm_precompiled_contracts_ripemd160_imports_ripemd160 : + IsImported globals "ethereum.paris.vm.precompiled_contracts.ripemd160" "ripemd160". + +Axiom ethereum_paris_vm_precompiled_contracts_sha256_imports_sha256 : + IsImported globals "ethereum.paris.vm.precompiled_contracts.sha256" "sha256". (* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/modexp.v index b21b98a..6904c05 100644 --- a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/modexp.v +++ b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/modexp.v @@ -17,17 +17,21 @@ Introduction Implementation of the `MODEXP` precompiled contract. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_paris_vm_imports : - AreImported globals "ethereum.paris.vm" [ "Evm" ]. +Axiom ethereum_paris_vm_imports_Evm : + IsImported globals "ethereum.paris.vm" "Evm". -Axiom ethereum_paris_vm_gas_imports : - AreImported globals "ethereum.paris.vm.gas" [ "charge_gas" ]. +Axiom ethereum_paris_vm_gas_imports_charge_gas : + IsImported globals "ethereum.paris.vm.gas" "charge_gas". -Axiom ethereum_paris_vm_memory_imports : - AreImported globals "ethereum.paris.vm.memory" [ "buffer_read" ]. +Axiom ethereum_paris_vm_memory_imports_buffer_read : + IsImported globals "ethereum.paris.vm.memory" "buffer_read". Definition GQUADDIVISOR : Value.t := M.run ltac:(M.monadic ( Constant.int 3 @@ -40,9 +44,12 @@ Definition modexp : Value.t -> Value.t -> M := Calculates `(base**exp) % modulus` for arbitrary sized `base`, `exp` and. `modulus`. The return value is the same length as the modulus. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let base_length := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "base_length" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -69,8 +76,10 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exp_length := + |) + |) in + let _ := M.assign_local (| + "exp_length" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -97,8 +106,10 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let modulus_length := + |) + |) in + let _ := M.assign_local (| + "modulus_length" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -125,8 +136,10 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exp_start := + |) + |) in + let _ := M.assign_local (| + "exp_start" , BinOp.add (| M.call (| M.get_name (| globals, "U256" |), @@ -136,8 +149,10 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |), M.get_name (| globals, "base_length" |) - |) in - let exp_head := + |) + |) in + let _ := M.assign_local (| + "exp_head" , M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ @@ -165,7 +180,8 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -216,7 +232,8 @@ Definition modexp : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let base := + let _ := M.assign_local (| + "base" , M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ @@ -237,8 +254,10 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exp := + |) + |) in + let _ := M.assign_local (| + "exp" , M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ @@ -253,13 +272,17 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let modulus_start := + |) + |) in + let _ := M.assign_local (| + "modulus_start" , BinOp.add (| M.get_name (| globals, "exp_start" |), M.get_name (| globals, "exp_length" |) - |) in - let modulus := + |) + |) in + let _ := M.assign_local (| + "modulus" , M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ @@ -274,7 +297,8 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -350,7 +374,8 @@ Definition complexity : Value.t -> Value.t -> M := complexity : `Uint` Complexity of performing the operation. " in - let max_length := + let _ := M.assign_local (| + "max_length" , M.call (| M.get_name (| globals, "max" |), make_list [ @@ -370,15 +395,18 @@ Definition complexity : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| BinOp.add (| M.get_name (| globals, "max_length" |), Constant.int 7 |), Constant.int 8 - |) in + |) + |) in let _ := M.return_ (| BinOp.pow (| M.get_name (| globals, "words" |), @@ -427,14 +455,16 @@ Definition iterations : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let count := + let _ := M.assign_local (| + "count" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -447,7 +477,8 @@ Definition iterations : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let bit_length := + let _ := M.assign_local (| + "bit_length" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -458,7 +489,8 @@ Definition iterations : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -468,20 +500,25 @@ Definition iterations : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let bit_length := BinOp.sub + let _ := M.assign_op_local (| + BinOp.sub, + "bit_length", Constant.int 1 - Constant.int 1 in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let count := - M.get_name (| globals, "bit_length" |) in + let _ := M.assign_local (| + "count" , + M.get_name (| globals, "bit_length" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let length_part := + let _ := M.assign_local (| + "length_part" , BinOp.mult (| Constant.int 8, BinOp.sub (| @@ -494,8 +531,10 @@ Definition iterations : Value.t -> Value.t -> M := |), Constant.int 32 |) - |) in - let bits_part := + |) + |) in + let _ := M.assign_local (| + "bits_part" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -506,7 +545,8 @@ Definition iterations : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -516,19 +556,23 @@ Definition iterations : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let bits_part := BinOp.sub + let _ := M.assign_op_local (| + BinOp.sub, + "bits_part", Constant.int 1 - Constant.int 1 in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let count := + let _ := M.assign_local (| + "count" , BinOp.add (| M.get_name (| globals, "length_part" |), M.get_name (| globals, "bits_part" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -579,7 +623,8 @@ Definition gas_cost : Value.t -> Value.t -> M := gas_cost : `Uint` Gas required for performing the operation. " in - let multiplication_complexity := + let _ := M.assign_local (| + "multiplication_complexity" , M.call (| M.get_name (| globals, "complexity" |), make_list [ @@ -587,8 +632,10 @@ Definition gas_cost : Value.t -> Value.t -> M := M.get_name (| globals, "modulus_length" |) ], make_dict [] - |) in - let iteration_count := + |) + |) in + let _ := M.assign_local (| + "iteration_count" , M.call (| M.get_name (| globals, "iterations" |), make_list [ @@ -596,15 +643,20 @@ Definition gas_cost : Value.t -> Value.t -> M := M.get_name (| globals, "exponent_head" |) ], make_dict [] - |) in - let cost := + |) + |) in + let _ := M.assign_local (| + "cost" , BinOp.mult (| M.get_name (| globals, "multiplication_complexity" |), M.get_name (| globals, "iteration_count" |) - |) in - let cost := BinOp.floor_div + |) + |) in + let _ := M.assign_op_local (| + BinOp.floor_div, + "cost", M.get_name (| globals, "GQUADDIVISOR" |) - M.get_name (| globals, "GQUADDIVISOR" |) in + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "max" |), diff --git a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/ripemd160.v index 8dc4508..5a9416e 100644 --- a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/ripemd160.v +++ b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/ripemd160.v @@ -19,20 +19,24 @@ Implementation of the `RIPEMD160` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_left_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "left_pad_zero_bytes". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_paris_vm_imports : - AreImported globals "ethereum.paris.vm" [ "Evm" ]. +Axiom ethereum_paris_vm_imports_Evm : + IsImported globals "ethereum.paris.vm" "Evm". -Axiom ethereum_paris_vm_gas_imports : - AreImported globals "ethereum.paris.vm.gas" [ "GAS_RIPEMD160"; "GAS_RIPEMD160_WORD"; "charge_gas" ]. +Axiom ethereum_paris_vm_gas_imports_GAS_RIPEMD160 : + IsImported globals "ethereum.paris.vm.gas" "GAS_RIPEMD160". +Axiom ethereum_paris_vm_gas_imports_GAS_RIPEMD160_WORD : + IsImported globals "ethereum.paris.vm.gas" "GAS_RIPEMD160_WORD". +Axiom ethereum_paris_vm_gas_imports_charge_gas : + IsImported globals "ethereum.paris.vm.gas" "charge_gas". Definition ripemd160 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,9 +49,12 @@ Definition ripemd160 : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let word_count := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "word_count" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -69,7 +76,8 @@ Definition ripemd160 : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -84,7 +92,8 @@ Definition ripemd160 : Value.t -> Value.t -> M := ], make_dict [] |) in - let hash_bytes := + let _ := M.assign_local (| + "hash_bytes" , M.call (| M.get_field (| M.call (| M.get_field (| M.get_name (| globals, "hashlib" |), "new" |), @@ -96,8 +105,10 @@ Definition ripemd160 : Value.t -> Value.t -> M := |), "digest" |), make_list [], make_dict [] - |) in - let padded_hash := + |) + |) in + let _ := M.assign_local (| + "padded_hash" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -105,7 +116,8 @@ Definition ripemd160 : Value.t -> Value.t -> M := Constant.int 32 ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.get_name (| globals, "padded_hash" |) diff --git a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/sha256.v index 97f82e5..882cecd 100644 --- a/CoqOfPython/ethereum/paris/vm/precompiled_contracts/sha256.v +++ b/CoqOfPython/ethereum/paris/vm/precompiled_contracts/sha256.v @@ -19,17 +19,21 @@ Implementation of the `SHA256` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_paris_vm_imports : - AreImported globals "ethereum.paris.vm" [ "Evm" ]. +Axiom ethereum_paris_vm_imports_Evm : + IsImported globals "ethereum.paris.vm" "Evm". -Axiom ethereum_paris_vm_gas_imports : - AreImported globals "ethereum.paris.vm.gas" [ "GAS_SHA256"; "GAS_SHA256_WORD"; "charge_gas" ]. +Axiom ethereum_paris_vm_gas_imports_GAS_SHA256 : + IsImported globals "ethereum.paris.vm.gas" "GAS_SHA256". +Axiom ethereum_paris_vm_gas_imports_GAS_SHA256_WORD : + IsImported globals "ethereum.paris.vm.gas" "GAS_SHA256_WORD". +Axiom ethereum_paris_vm_gas_imports_charge_gas : + IsImported globals "ethereum.paris.vm.gas" "charge_gas". Definition sha256 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,9 +46,12 @@ Definition sha256 : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let word_count := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "word_count" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -66,7 +73,8 @@ Definition sha256 : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ diff --git a/CoqOfPython/ethereum/paris/vm/runtime.v b/CoqOfPython/ethereum/paris/vm/runtime.v index 4c01cde..4733e48 100644 --- a/CoqOfPython/ethereum/paris/vm/runtime.v +++ b/CoqOfPython/ethereum/paris/vm/runtime.v @@ -17,14 +17,14 @@ Introduction Runtime related operations used while executing EVM code. ". -Axiom typing_imports : - AreImported globals "typing" [ "Set" ]. +Axiom typing_imports_Set : + IsImported globals "typing" "Set". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_paris_vm_instructions_imports : - AreImported globals "ethereum.paris.vm.instructions" [ "Ops" ]. +Axiom ethereum_paris_vm_instructions_imports_Ops : + IsImported globals "ethereum.paris.vm.instructions" "Ops". Definition get_valid_jump_destinations : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -50,20 +50,24 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := valid_jump_destinations: `Set[Uint]` The set of valid jump destinations in the code. " in - let valid_jump_destinations := + let _ := M.assign_local (| + "valid_jump_destinations" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let pc := + |) + |) in + let _ := M.assign_local (| + "pc" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in let _ := M.while (| Compare.lt (| @@ -114,17 +118,21 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let push_data_size := + let _ := M.assign_local (| + "push_data_size" , BinOp.add (| BinOp.sub (| M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) |), Constant.int 1 - |) in - let pc := BinOp.add + |) + |) in + let _ := M.assign_op_local (| + BinOp.add, + "pc", M.get_name (| globals, "push_data_size" |) - M.get_name (| globals, "push_data_size" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -132,9 +140,11 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - let pc := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "pc", Constant.int 1 - Constant.int 1 in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/paris/vm/stack.v b/CoqOfPython/ethereum/paris/vm/stack.v index d52ab7d..026c5b4 100644 --- a/CoqOfPython/ethereum/paris/vm/stack.v +++ b/CoqOfPython/ethereum/paris/vm/stack.v @@ -17,14 +17,16 @@ Introduction Implementation of the stack operators for the EVM. ". -Axiom typing_imports : - AreImported globals "typing" [ "List" ]. +Axiom typing_imports_List : + IsImported globals "typing" "List". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_paris_vm_exceptions_imports : - AreImported globals "ethereum.paris.vm.exceptions" [ "StackOverflowError"; "StackUnderflowError" ]. +Axiom ethereum_paris_vm_exceptions_imports_StackOverflowError : + IsImported globals "ethereum.paris.vm.exceptions" "StackOverflowError". +Axiom ethereum_paris_vm_exceptions_imports_StackUnderflowError : + IsImported globals "ethereum.paris.vm.exceptions" "StackUnderflowError". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/rlp.v b/CoqOfPython/ethereum/rlp.v index a99ae1d..d513852 100644 --- a/CoqOfPython/ethereum/rlp.v +++ b/CoqOfPython/ethereum/rlp.v @@ -19,23 +19,55 @@ Introduction Defines the serialization and deserialization format used throughout Ethereum. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "astuple"; "fields"; "is_dataclass" ]. +Axiom dataclasses_imports_astuple : + IsImported globals "dataclasses" "astuple". +Axiom dataclasses_imports_fields : + IsImported globals "dataclasses" "fields". +Axiom dataclasses_imports_is_dataclass : + IsImported globals "dataclasses" "is_dataclass". -Axiom typing_imports : - AreImported globals "typing" [ "Any"; "List"; "Sequence"; "Tuple"; "Type"; "TypeVar"; "Union"; "cast" ]. +Axiom typing_imports_Any : + IsImported globals "typing" "Any". +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Sequence : + IsImported globals "typing" "Sequence". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Type : + IsImported globals "typing" "Type". +Axiom typing_imports_TypeVar : + IsImported globals "typing" "TypeVar". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". +Axiom typing_imports_cast : + IsImported globals "typing" "cast". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_exceptions_imports : - AreImported globals "ethereum.exceptions" [ "RLPDecodingError"; "RLPEncodingError" ]. +Axiom ethereum_exceptions_imports_RLPDecodingError : + IsImported globals "ethereum.exceptions" "RLPDecodingError". +Axiom ethereum_exceptions_imports_RLPEncodingError : + IsImported globals "ethereum.exceptions" "RLPEncodingError". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Bytes"; "Bytes0"; "Bytes20"; "FixedBytes"; "FixedUint"; "Uint" ]. +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Bytes20 : + IsImported globals "ethereum.base_types" "Bytes20". +Axiom ethereum_base_types_imports_FixedBytes : + IsImported globals "ethereum.base_types" "FixedBytes". +Axiom ethereum_base_types_imports_FixedUint : + IsImported globals "ethereum.base_types" "FixedUint". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". Definition RLP : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Any" |) @@ -290,7 +322,8 @@ Definition encode_bytes : Value.t -> Value.t -> M := encoded : `ethereum.base_types.Bytes` The RLP encoded bytes representing `raw_bytes`. " in - let len_raw_data := + let _ := M.assign_local (| + "len_raw_data" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -303,7 +336,8 @@ Definition encode_bytes : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -359,12 +393,14 @@ Definition encode_bytes : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let len_raw_data_as_be := + let _ := M.assign_local (| + "len_raw_data_as_be" , M.call (| M.get_field (| M.get_name (| globals, "len_raw_data" |), "to_be_bytes" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.return_ (| BinOp.add (| BinOp.add (| @@ -413,15 +449,18 @@ Definition encode_sequence : Value.t -> Value.t -> M := encoded : `ethereum.base_types.Bytes` The RLP encoded bytes representing `raw_sequence`. " in - let joined_encodings := + let _ := M.assign_local (| + "joined_encodings" , M.call (| M.get_name (| globals, "get_joined_encodings" |), make_list [ M.get_name (| globals, "raw_sequence" |) ], make_dict [] - |) in - let len_joined_encodings := + |) + |) in + let _ := M.assign_local (| + "len_joined_encodings" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -434,7 +473,8 @@ Definition encode_sequence : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -464,12 +504,14 @@ Definition encode_sequence : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let len_joined_encodings_as_be := + let _ := M.assign_local (| + "len_joined_encodings_as_be" , M.call (| M.get_field (| M.get_name (| globals, "len_joined_encodings" |), "to_be_bytes" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.return_ (| BinOp.add (| BinOp.add (| @@ -686,7 +728,7 @@ Definition _decode_to : Value.t -> Value.t -> M := make_list [ M.get_subscript (| M.get_name (| globals, "Tuple" |), - make_tuple [ M.get_name (| globals, "Uint" |); (* At constant: unsupported node type: Constant *) ] + make_tuple [ M.get_name (| globals, "Uint" |); Constant.ellipsis ] |) ], make_dict [] @@ -726,12 +768,14 @@ Definition _decode_to : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "cls" |), "__args__" |), Constant.int 1 |), - (* At constant: unsupported node type: Constant *) + Constant.ellipsis |), (* then *) ltac:(M.monadic ( - let args := - make_list [] in + let _ := M.assign_local (| + "args" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "raw_item" |), @@ -772,8 +816,10 @@ Definition _decode_to : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let args := - make_list [] in + let _ := M.assign_local (| + "args" , + make_list [] + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -993,8 +1039,10 @@ Definition _decode_to : Value.t -> Value.t -> M := ], make_dict [] |) in - let items := - make_list [] in + let _ := M.assign_local (| + "items" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "raw_item" |), @@ -1404,8 +1452,10 @@ Definition _decode_to : Value.t -> Value.t -> M := ], make_dict [] |) |) in - let args := - make_list [] in + let _ := M.assign_local (| + "args" , + make_list [] + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1584,14 +1634,16 @@ Definition decode_to_bytes : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let len_raw_data := + let _ := M.assign_local (| + "len_raw_data" , BinOp.sub (| M.get_subscript (| M.get_name (| globals, "encoded_bytes" |), Constant.int 0 |), Constant.int 128 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1609,7 +1661,8 @@ Definition decode_to_bytes : Value.t -> Value.t -> M := ], make_dict [] |) in - let raw_data := + let _ := M.assign_local (| + "raw_data" , M.slice (| M.get_name (| globals, "encoded_bytes" |), Constant.int 1, @@ -1618,7 +1671,8 @@ Definition decode_to_bytes : Value.t -> Value.t -> M := M.get_name (| globals, "len_raw_data" |) |), Constant.None_ - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1647,7 +1701,8 @@ Definition decode_to_bytes : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let decoded_data_start_idx := + let _ := M.assign_local (| + "decoded_data_start_idx" , BinOp.sub (| BinOp.add (| Constant.int 1, @@ -1657,7 +1712,8 @@ Definition decode_to_bytes : Value.t -> Value.t -> M := |) |), Constant.int 183 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1692,7 +1748,8 @@ Definition decode_to_bytes : Value.t -> Value.t -> M := ], make_dict [] |) in - let len_decoded_data := + let _ := M.assign_local (| + "len_decoded_data" , M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ @@ -1704,7 +1761,8 @@ Definition decode_to_bytes : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1716,11 +1774,13 @@ Definition decode_to_bytes : Value.t -> Value.t -> M := ], make_dict [] |) in - let decoded_data_end_idx := + let _ := M.assign_local (| + "decoded_data_end_idx" , BinOp.add (| M.get_name (| globals, "decoded_data_start_idx" |), M.get_name (| globals, "len_decoded_data" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1784,14 +1844,16 @@ Definition decode_to_sequence : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let len_joined_encodings := + let _ := M.assign_local (| + "len_joined_encodings" , BinOp.sub (| M.get_subscript (| M.get_name (| globals, "encoded_sequence" |), Constant.int 0 |), Constant.int 192 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1809,7 +1871,8 @@ Definition decode_to_sequence : Value.t -> Value.t -> M := ], make_dict [] |) in - let joined_encodings := + let _ := M.assign_local (| + "joined_encodings" , M.slice (| M.get_name (| globals, "encoded_sequence" |), Constant.int 1, @@ -1818,11 +1881,13 @@ Definition decode_to_sequence : Value.t -> Value.t -> M := M.get_name (| globals, "len_joined_encodings" |) |), Constant.None_ - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let joined_encodings_start_idx := + let _ := M.assign_local (| + "joined_encodings_start_idx" , BinOp.sub (| BinOp.add (| Constant.int 1, @@ -1832,7 +1897,8 @@ Definition decode_to_sequence : Value.t -> Value.t -> M := |) |), Constant.int 247 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1867,7 +1933,8 @@ Definition decode_to_sequence : Value.t -> Value.t -> M := ], make_dict [] |) in - let len_joined_encodings := + let _ := M.assign_local (| + "len_joined_encodings" , M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ @@ -1879,7 +1946,8 @@ Definition decode_to_sequence : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1891,11 +1959,13 @@ Definition decode_to_sequence : Value.t -> Value.t -> M := ], make_dict [] |) in - let joined_encodings_end_idx := + let _ := M.assign_local (| + "joined_encodings_end_idx" , BinOp.add (| M.get_name (| globals, "joined_encodings_start_idx" |), M.get_name (| globals, "len_joined_encodings" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1916,13 +1986,15 @@ Definition decode_to_sequence : Value.t -> Value.t -> M := ], make_dict [] |) in - let joined_encodings := + let _ := M.assign_local (| + "joined_encodings" , M.slice (| M.get_name (| globals, "encoded_sequence" |), M.get_name (| globals, "joined_encodings_start_idx" |), M.get_name (| globals, "joined_encodings_end_idx" |), Constant.None_ - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1953,10 +2025,14 @@ Definition decode_joined_encodings : Value.t -> Value.t -> M := decoded : `List[RLP]` A list of objects decoded from `joined_encodings`. " in - let decoded_sequence := - make_list [] in - let item_start_idx := - Constant.int 0 in + let _ := M.assign_local (| + "decoded_sequence" , + make_list [] + |) in + let _ := M.assign_local (| + "item_start_idx" , + Constant.int 0 + |) in let _ := M.while (| Compare.lt (| @@ -1970,7 +2046,8 @@ Definition decode_joined_encodings : Value.t -> Value.t -> M := |) |), ltac:(M.monadic ( - let encoded_item_length := + let _ := M.assign_local (| + "encoded_item_length" , M.call (| M.get_name (| globals, "decode_item_length" |), make_list [ @@ -1982,7 +2059,8 @@ Definition decode_joined_encodings : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -2006,7 +2084,8 @@ Definition decode_joined_encodings : Value.t -> Value.t -> M := ], make_dict [] |) in - let encoded_item := + let _ := M.assign_local (| + "encoded_item" , M.slice (| M.get_name (| globals, "joined_encodings" |), M.get_name (| globals, "item_start_idx" |), @@ -2015,7 +2094,8 @@ Definition decode_joined_encodings : Value.t -> Value.t -> M := M.get_name (| globals, "encoded_item_length" |) |), Constant.None_ - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "decoded_sequence" |), "append" |), make_list [ @@ -2029,9 +2109,11 @@ Definition decode_joined_encodings : Value.t -> Value.t -> M := ], make_dict [] |) in - let item_start_idx := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "item_start_idx", M.get_name (| globals, "encoded_item_length" |) - M.get_name (| globals, "encoded_item_length" |) in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -2082,7 +2164,8 @@ Definition decode_item_length : Value.t -> Value.t -> M := ], make_dict [] |) in - let first_rlp_byte := + let _ := M.assign_local (| + "first_rlp_byte" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -2092,17 +2175,22 @@ Definition decode_item_length : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let length_length := + |) + |) in + let _ := M.assign_local (| + "length_length" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in - let decoded_data_length := - Constant.int 0 in + |) + |) in + let _ := M.assign_local (| + "decoded_data_length" , + Constant.int 0 + |) in let _ := (* if *) M.if_then_else (| @@ -2127,11 +2215,13 @@ Definition decode_item_length : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let decoded_data_length := + let _ := M.assign_local (| + "decoded_data_length" , BinOp.sub (| M.get_name (| globals, "first_rlp_byte" |), Constant.int 128 - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -2144,11 +2234,13 @@ Definition decode_item_length : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let length_length := + let _ := M.assign_local (| + "length_length" , BinOp.sub (| M.get_name (| globals, "first_rlp_byte" |), Constant.int 183 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -2180,7 +2272,8 @@ Definition decode_item_length : Value.t -> Value.t -> M := ], make_dict [] |) in - let decoded_data_length := + let _ := M.assign_local (| + "decoded_data_length" , M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ @@ -2195,7 +2288,8 @@ Definition decode_item_length : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -2208,11 +2302,13 @@ Definition decode_item_length : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let decoded_data_length := + let _ := M.assign_local (| + "decoded_data_length" , BinOp.sub (| M.get_name (| globals, "first_rlp_byte" |), Constant.int 192 - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -2225,11 +2321,13 @@ Definition decode_item_length : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let length_length := + let _ := M.assign_local (| + "length_length" , BinOp.sub (| M.get_name (| globals, "first_rlp_byte" |), Constant.int 247 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -2261,7 +2359,8 @@ Definition decode_item_length : Value.t -> Value.t -> M := ], make_dict [] |) in - let decoded_data_length := + let _ := M.assign_local (| + "decoded_data_length" , M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ @@ -2276,7 +2375,8 @@ Definition decode_item_length : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/shanghai/__init__.v b/CoqOfPython/ethereum/shanghai/__init__.v index c966ed2..c452ed3 100644 --- a/CoqOfPython/ethereum/shanghai/__init__.v +++ b/CoqOfPython/ethereum/shanghai/__init__.v @@ -9,8 +9,8 @@ push-zero EVM instruction, limits the maximum size of initialization bytecode, and deprecates the self-destruct EVM instruction. ". -Axiom ethereum_fork_criteria_imports : - AreImported globals "ethereum.fork_criteria" [ "ByTimestamp" ]. +Axiom ethereum_fork_criteria_imports_ByTimestamp : + IsImported globals "ethereum.fork_criteria" "ByTimestamp". Definition FORK_CRITERIA : Value.t := M.run ltac:(M.monadic ( M.call (| diff --git a/CoqOfPython/ethereum/shanghai/blocks.v b/CoqOfPython/ethereum/shanghai/blocks.v index 5d51a1c..3dccfcd 100644 --- a/CoqOfPython/ethereum/shanghai/blocks.v +++ b/CoqOfPython/ethereum/shanghai/blocks.v @@ -14,23 +14,41 @@ history of all state transitions that have happened since the genesis of the chain. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Tuple"; "Union" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U64"; "U256"; "Bytes"; "Bytes8"; "Bytes32"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. - -Axiom ethereum_shanghai_fork_types_imports : - AreImported globals "ethereum.shanghai.fork_types" [ "Address"; "Bloom"; "Root" ]. - -Axiom ethereum_shanghai_transactions_imports : - AreImported globals "ethereum.shanghai.transactions" [ "LegacyTransaction" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". + +Axiom ethereum_base_types_imports_U64 : + IsImported globals "ethereum.base_types" "U64". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes8 : + IsImported globals "ethereum.base_types" "Bytes8". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". + +Axiom ethereum_shanghai_fork_types_imports_Address : + IsImported globals "ethereum.shanghai.fork_types" "Address". +Axiom ethereum_shanghai_fork_types_imports_Bloom : + IsImported globals "ethereum.shanghai.fork_types" "Bloom". +Axiom ethereum_shanghai_fork_types_imports_Root : + IsImported globals "ethereum.shanghai.fork_types" "Root". + +Axiom ethereum_shanghai_transactions_imports_LegacyTransaction : + IsImported globals "ethereum.shanghai.transactions" "LegacyTransaction". Definition Withdrawal : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/shanghai/bloom.v b/CoqOfPython/ethereum/shanghai/bloom.v index 7395a1d..f6a336d 100644 --- a/CoqOfPython/ethereum/shanghai/bloom.v +++ b/CoqOfPython/ethereum/shanghai/bloom.v @@ -21,20 +21,20 @@ for efficient searching of logs by address and/or topic, by rapidly eliminating blocks and receipts from their search. ". -Axiom typing_imports : - AreImported globals "typing" [ "Tuple" ]. +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_shanghai_blocks_imports : - AreImported globals "ethereum.shanghai.blocks" [ "Log" ]. +Axiom ethereum_shanghai_blocks_imports_Log : + IsImported globals "ethereum.shanghai.blocks" "Log". -Axiom ethereum_shanghai_fork_types_imports : - AreImported globals "ethereum.shanghai.fork_types" [ "Bloom" ]. +Axiom ethereum_shanghai_fork_types_imports_Bloom : + IsImported globals "ethereum.shanghai.fork_types" "Bloom". Definition add_to_bloom : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -53,20 +53,23 @@ Definition add_to_bloom : Value.t -> Value.t -> M := bloom_entry : An entry which is to be added to bloom filter. " in - let hash := + let _ := M.assign_local (| + "hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "bloom_entry" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "idx" |), make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ], ltac:(M.monadic ( - let bit_to_set := + let _ := M.assign_local (| + "bit_to_set" , BinOp.bit_and (| M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), @@ -84,18 +87,24 @@ Definition add_to_bloom : Value.t -> Value.t -> M := make_dict [] |), Constant.int 2047 - |) in - let bit_index := + |) + |) in + let _ := M.assign_local (| + "bit_index" , BinOp.sub (| Constant.int 2047, M.get_name (| globals, "bit_to_set" |) - |) in - let byte_index := + |) + |) in + let _ := M.assign_local (| + "byte_index" , BinOp.floor_div (| M.get_name (| globals, "bit_index" |), Constant.int 8 - |) in - let bit_value := + |) + |) in + let _ := M.assign_local (| + "bit_value" , BinOp.l_shift (| Constant.int 1, BinOp.sub (| @@ -105,7 +114,8 @@ Definition add_to_bloom : Value.t -> Value.t -> M := Constant.int 8 |) |) - |) in + |) + |) in let _ := M.assign (| M.get_subscript (| M.get_name (| globals, "bloom" |), diff --git a/CoqOfPython/ethereum/shanghai/fork.v b/CoqOfPython/ethereum/shanghai/fork.v index 2e2552a..1ec1953 100644 --- a/CoqOfPython/ethereum/shanghai/fork.v +++ b/CoqOfPython/ethereum/shanghai/fork.v @@ -17,62 +17,134 @@ Introduction Entry point for the Ethereum specification. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Optional"; "Tuple"; "Union" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Bytes0"; "Bytes32" ]. - -Axiom ethereum_crypto_elliptic_curve_imports : - AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. - -Axiom ethereum_exceptions_imports : - AreImported globals "ethereum.exceptions" [ "InvalidBlock" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U64"; "U256"; "Bytes"; "Uint" ]. - -Axiom ethereum_shanghai_imports : - AreImported globals "ethereum.shanghai" [ "vm" ]. - -Axiom ethereum_shanghai_blocks_imports : - AreImported globals "ethereum.shanghai.blocks" [ "Block"; "Header"; "Log"; "Receipt"; "Withdrawal" ]. - -Axiom ethereum_shanghai_bloom_imports : - AreImported globals "ethereum.shanghai.bloom" [ "logs_bloom" ]. - -Axiom ethereum_shanghai_fork_types_imports : - AreImported globals "ethereum.shanghai.fork_types" [ "Address"; "Bloom"; "Root" ]. - -Axiom ethereum_shanghai_state_imports : - AreImported globals "ethereum.shanghai.state" [ "State"; "account_exists_and_is_empty"; "destroy_account"; "get_account"; "increment_nonce"; "process_withdrawal"; "set_account_balance"; "state_root" ]. - -Axiom ethereum_shanghai_transactions_imports : - AreImported globals "ethereum.shanghai.transactions" [ "TX_ACCESS_LIST_ADDRESS_COST"; "TX_ACCESS_LIST_STORAGE_KEY_COST"; "TX_BASE_COST"; "TX_CREATE_COST"; "TX_DATA_COST_PER_NON_ZERO"; "TX_DATA_COST_PER_ZERO"; "AccessListTransaction"; "FeeMarketTransaction"; "LegacyTransaction"; "Transaction"; "decode_transaction"; "encode_transaction" ]. - -Axiom ethereum_shanghai_trie_imports : - AreImported globals "ethereum.shanghai.trie" [ "Trie"; "root"; "trie_set" ]. - -Axiom ethereum_shanghai_utils_message_imports : - AreImported globals "ethereum.shanghai.utils.message" [ "prepare_message" ]. - -Axiom ethereum_shanghai_vm_gas_imports : - AreImported globals "ethereum.shanghai.vm.gas" [ "init_code_cost" ]. - -Axiom ethereum_shanghai_vm_interpreter_imports : - AreImported globals "ethereum.shanghai.vm.interpreter" [ "MAX_CODE_SIZE"; "process_message_call" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". + +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". + +Axiom ethereum_crypto_elliptic_curve_imports_SECP256K1N : + IsImported globals "ethereum.crypto.elliptic_curve" "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_imports_secp256k1_recover : + IsImported globals "ethereum.crypto.elliptic_curve" "secp256k1_recover". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". + +Axiom ethereum_exceptions_imports_InvalidBlock : + IsImported globals "ethereum.exceptions" "InvalidBlock". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U64 : + IsImported globals "ethereum.base_types" "U64". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_shanghai_imports_vm : + IsImported globals "ethereum.shanghai" "vm". + +Axiom ethereum_shanghai_blocks_imports_Block : + IsImported globals "ethereum.shanghai.blocks" "Block". +Axiom ethereum_shanghai_blocks_imports_Header : + IsImported globals "ethereum.shanghai.blocks" "Header". +Axiom ethereum_shanghai_blocks_imports_Log : + IsImported globals "ethereum.shanghai.blocks" "Log". +Axiom ethereum_shanghai_blocks_imports_Receipt : + IsImported globals "ethereum.shanghai.blocks" "Receipt". +Axiom ethereum_shanghai_blocks_imports_Withdrawal : + IsImported globals "ethereum.shanghai.blocks" "Withdrawal". + +Axiom ethereum_shanghai_bloom_imports_logs_bloom : + IsImported globals "ethereum.shanghai.bloom" "logs_bloom". + +Axiom ethereum_shanghai_fork_types_imports_Address : + IsImported globals "ethereum.shanghai.fork_types" "Address". +Axiom ethereum_shanghai_fork_types_imports_Bloom : + IsImported globals "ethereum.shanghai.fork_types" "Bloom". +Axiom ethereum_shanghai_fork_types_imports_Root : + IsImported globals "ethereum.shanghai.fork_types" "Root". + +Axiom ethereum_shanghai_state_imports_State : + IsImported globals "ethereum.shanghai.state" "State". +Axiom ethereum_shanghai_state_imports_account_exists_and_is_empty : + IsImported globals "ethereum.shanghai.state" "account_exists_and_is_empty". +Axiom ethereum_shanghai_state_imports_destroy_account : + IsImported globals "ethereum.shanghai.state" "destroy_account". +Axiom ethereum_shanghai_state_imports_get_account : + IsImported globals "ethereum.shanghai.state" "get_account". +Axiom ethereum_shanghai_state_imports_increment_nonce : + IsImported globals "ethereum.shanghai.state" "increment_nonce". +Axiom ethereum_shanghai_state_imports_process_withdrawal : + IsImported globals "ethereum.shanghai.state" "process_withdrawal". +Axiom ethereum_shanghai_state_imports_set_account_balance : + IsImported globals "ethereum.shanghai.state" "set_account_balance". +Axiom ethereum_shanghai_state_imports_state_root : + IsImported globals "ethereum.shanghai.state" "state_root". + +Axiom ethereum_shanghai_transactions_imports_TX_ACCESS_LIST_ADDRESS_COST : + IsImported globals "ethereum.shanghai.transactions" "TX_ACCESS_LIST_ADDRESS_COST". +Axiom ethereum_shanghai_transactions_imports_TX_ACCESS_LIST_STORAGE_KEY_COST : + IsImported globals "ethereum.shanghai.transactions" "TX_ACCESS_LIST_STORAGE_KEY_COST". +Axiom ethereum_shanghai_transactions_imports_TX_BASE_COST : + IsImported globals "ethereum.shanghai.transactions" "TX_BASE_COST". +Axiom ethereum_shanghai_transactions_imports_TX_CREATE_COST : + IsImported globals "ethereum.shanghai.transactions" "TX_CREATE_COST". +Axiom ethereum_shanghai_transactions_imports_TX_DATA_COST_PER_NON_ZERO : + IsImported globals "ethereum.shanghai.transactions" "TX_DATA_COST_PER_NON_ZERO". +Axiom ethereum_shanghai_transactions_imports_TX_DATA_COST_PER_ZERO : + IsImported globals "ethereum.shanghai.transactions" "TX_DATA_COST_PER_ZERO". +Axiom ethereum_shanghai_transactions_imports_AccessListTransaction : + IsImported globals "ethereum.shanghai.transactions" "AccessListTransaction". +Axiom ethereum_shanghai_transactions_imports_FeeMarketTransaction : + IsImported globals "ethereum.shanghai.transactions" "FeeMarketTransaction". +Axiom ethereum_shanghai_transactions_imports_LegacyTransaction : + IsImported globals "ethereum.shanghai.transactions" "LegacyTransaction". +Axiom ethereum_shanghai_transactions_imports_Transaction : + IsImported globals "ethereum.shanghai.transactions" "Transaction". +Axiom ethereum_shanghai_transactions_imports_decode_transaction : + IsImported globals "ethereum.shanghai.transactions" "decode_transaction". +Axiom ethereum_shanghai_transactions_imports_encode_transaction : + IsImported globals "ethereum.shanghai.transactions" "encode_transaction". + +Axiom ethereum_shanghai_trie_imports_Trie : + IsImported globals "ethereum.shanghai.trie" "Trie". +Axiom ethereum_shanghai_trie_imports_root : + IsImported globals "ethereum.shanghai.trie" "root". +Axiom ethereum_shanghai_trie_imports_trie_set : + IsImported globals "ethereum.shanghai.trie" "trie_set". + +Axiom ethereum_shanghai_utils_message_imports_prepare_message : + IsImported globals "ethereum.shanghai.utils.message" "prepare_message". + +Axiom ethereum_shanghai_vm_gas_imports_init_code_cost : + IsImported globals "ethereum.shanghai.vm.gas" "init_code_cost". + +Axiom ethereum_shanghai_vm_interpreter_imports_MAX_CODE_SIZE : + IsImported globals "ethereum.shanghai.vm.interpreter" "MAX_CODE_SIZE". +Axiom ethereum_shanghai_vm_interpreter_imports_process_message_call : + IsImported globals "ethereum.shanghai.vm.interpreter" "process_message_call". Definition BASE_FEE_MAX_CHANGE_DENOMINATOR : Value.t := M.run ltac:(M.monadic ( Constant.int 8 @@ -164,13 +236,15 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := recent_block_hashes : `List[Hash32]` Hashes of the recent 256 blocks in order of increasing block number. " in - let recent_blocks := + let _ := M.assign_local (| + "recent_blocks" , M.slice (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |), Constant.None_, Constant.None_ - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -194,15 +268,19 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let recent_block_hashes := - make_list [] in + let _ := M.assign_local (| + "recent_block_hashes" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "block" |), M.get_name (| globals, "recent_blocks" |), ltac:(M.monadic ( - let prev_block_hash := - M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in + let _ := M.assign_local (| + "prev_block_hash" , + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), make_list [ @@ -216,7 +294,8 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let most_recent_block_hash := + let _ := M.assign_local (| + "most_recent_block_hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -232,7 +311,8 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), make_list [ @@ -269,11 +349,13 @@ Definition state_transition : Value.t -> Value.t -> M := block : Block to apply to `chain`. " in - let parent_header := + let _ := M.assign_local (| + "parent_header" , M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 1 |) - |), "header" |) in + |), "header" |) + |) in let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ @@ -293,7 +375,8 @@ Definition state_transition : Value.t -> Value.t -> M := ], make_dict [] |) in - let apply_body_output := + let _ := M.assign_local (| + "apply_body_output" , M.call (| M.get_name (| globals, "apply_body" |), make_list [ @@ -316,7 +399,8 @@ Definition state_transition : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "block" |), "withdrawals" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -443,11 +527,13 @@ Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := base_fee_per_gas : `Uint` Base fee per gas for the block. " in - let parent_gas_target := + let _ := M.assign_local (| + "parent_gas_target" , BinOp.floor_div (| M.get_name (| globals, "parent_gas_limit" |), M.get_name (| globals, "ELASTICITY_MULTIPLIER" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -472,8 +558,10 @@ Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let expected_base_fee_per_gas := - M.get_name (| globals, "parent_base_fee_per_gas" |) in + let _ := M.assign_local (| + "expected_base_fee_per_gas" , + M.get_name (| globals, "parent_base_fee_per_gas" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -486,22 +574,29 @@ Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let gas_used_delta := + let _ := M.assign_local (| + "gas_used_delta" , BinOp.sub (| M.get_name (| globals, "parent_gas_used" |), M.get_name (| globals, "parent_gas_target" |) - |) in - let parent_fee_gas_delta := + |) + |) in + let _ := M.assign_local (| + "parent_fee_gas_delta" , BinOp.mult (| M.get_name (| globals, "parent_base_fee_per_gas" |), M.get_name (| globals, "gas_used_delta" |) - |) in - let target_fee_gas_delta := + |) + |) in + let _ := M.assign_local (| + "target_fee_gas_delta" , BinOp.floor_div (| M.get_name (| globals, "parent_fee_gas_delta" |), M.get_name (| globals, "parent_gas_target" |) - |) in - let base_fee_per_gas_delta := + |) + |) in + let _ := M.assign_local (| + "base_fee_per_gas_delta" , M.call (| M.get_name (| globals, "max" |), make_list [ @@ -512,40 +607,53 @@ Definition calculate_base_fee_per_gas : Value.t -> Value.t -> M := Constant.int 1 ], make_dict [] - |) in - let expected_base_fee_per_gas := + |) + |) in + let _ := M.assign_local (| + "expected_base_fee_per_gas" , BinOp.add (| M.get_name (| globals, "parent_base_fee_per_gas" |), M.get_name (| globals, "base_fee_per_gas_delta" |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let gas_used_delta := + let _ := M.assign_local (| + "gas_used_delta" , BinOp.sub (| M.get_name (| globals, "parent_gas_target" |), M.get_name (| globals, "parent_gas_used" |) - |) in - let parent_fee_gas_delta := + |) + |) in + let _ := M.assign_local (| + "parent_fee_gas_delta" , BinOp.mult (| M.get_name (| globals, "parent_base_fee_per_gas" |), M.get_name (| globals, "gas_used_delta" |) - |) in - let target_fee_gas_delta := + |) + |) in + let _ := M.assign_local (| + "target_fee_gas_delta" , BinOp.floor_div (| M.get_name (| globals, "parent_fee_gas_delta" |), M.get_name (| globals, "parent_gas_target" |) - |) in - let base_fee_per_gas_delta := + |) + |) in + let _ := M.assign_local (| + "base_fee_per_gas_delta" , BinOp.floor_div (| M.get_name (| globals, "target_fee_gas_delta" |), M.get_name (| globals, "BASE_FEE_MAX_CHANGE_DENOMINATOR" |) - |) in - let expected_base_fee_per_gas := + |) + |) in + let _ := M.assign_local (| + "expected_base_fee_per_gas" , BinOp.sub (| M.get_name (| globals, "parent_base_fee_per_gas" |), M.get_name (| globals, "base_fee_per_gas_delta" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -592,7 +700,8 @@ Definition validate_header : Value.t -> Value.t -> M := ], make_dict [] |) in - let expected_base_fee_per_gas := + let _ := M.assign_local (| + "expected_base_fee_per_gas" , M.call (| M.get_name (| globals, "calculate_base_fee_per_gas" |), make_list [ @@ -602,7 +711,8 @@ Definition validate_header : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "parent_header" |), "base_fee_per_gas" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -689,7 +799,8 @@ Definition validate_header : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_parent_hash := + let _ := M.assign_local (| + "block_parent_hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -702,7 +813,8 @@ Definition validate_header : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -756,7 +868,8 @@ Definition check_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_address := + let _ := M.assign_local (| + "sender_address" , M.call (| M.get_name (| globals, "recover_sender" |), make_list [ @@ -764,7 +877,8 @@ Definition check_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "tx" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -800,7 +914,8 @@ Definition check_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let priority_fee_per_gas := + let _ := M.assign_local (| + "priority_fee_per_gas" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -811,12 +926,15 @@ Definition check_transaction : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let effective_gas_price := + |) + |) in + let _ := M.assign_local (| + "effective_gas_price" , BinOp.add (| M.get_name (| globals, "priority_fee_per_gas" |), M.get_name (| globals, "base_fee_per_gas" |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -831,8 +949,10 @@ Definition check_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let effective_gas_price := - M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) in + let _ := M.assign_local (| + "effective_gas_price" , + M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) + |) in M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -863,12 +983,14 @@ Definition make_receipt : Value.t -> Value.t -> M := receipt : The receipt for the transaction. " in - let receipt := + let _ := M.assign_local (| + "receipt" , M.call (| M.get_name (| globals, "Receipt" |), make_list [], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -991,8 +1113,10 @@ Definition apply_body : Value.t -> Value.t -> M := apply_body_output : `ApplyBodyOutput` Output of applying the block body to the state. " in - let gas_available := - M.get_name (| globals, "block_gas_limit" |) in + let _ := M.assign_local (| + "gas_available" , + M.get_name (| globals, "block_gas_limit" |) + |) in (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) @@ -1055,12 +1179,14 @@ Definition apply_body : Value.t -> Value.t -> M := make_dict [] |) |) in - let env := + let _ := M.assign_local (| + "env" , M.call (| M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |); M.get_name (| globals, "error" |) ], M.call (| @@ -1072,10 +1198,13 @@ Definition apply_body : Value.t -> Value.t -> M := make_dict [] |) |) in - let gas_available := BinOp.sub + let _ := M.assign_op_local (| + BinOp.sub, + "gas_available", M.get_name (| globals, "gas_used" |) - M.get_name (| globals, "gas_used" |) in - let receipt := + |) in + let _ := M.assign_local (| + "receipt" , M.call (| M.get_name (| globals, "make_receipt" |), make_list [ @@ -1088,7 +1217,8 @@ Definition apply_body : Value.t -> Value.t -> M := M.get_name (| globals, "logs" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ @@ -1110,28 +1240,34 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_logs := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "block_logs", M.get_name (| globals, "logs" |) - M.get_name (| globals, "logs" |) in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let block_gas_used := + let _ := M.assign_local (| + "block_gas_used" , BinOp.sub (| M.get_name (| globals, "block_gas_limit" |), M.get_name (| globals, "gas_available" |) - |) in - let block_logs_bloom := + |) + |) in + let _ := M.assign_local (| + "block_logs_bloom" , M.call (| M.get_name (| globals, "logs_bloom" |), make_list [ M.get_name (| globals, "block_logs" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| make_tuple [ M.get_name (| globals, "i" |); M.get_name (| globals, "wd" |) ], @@ -1293,9 +1429,12 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender := - M.get_field (| M.get_name (| globals, "env" |), "origin" |) in - let sender_account := + let _ := M.assign_local (| + "sender" , + M.get_field (| M.get_name (| globals, "env" |), "origin" |) + |) in + let _ := M.assign_local (| + "sender_account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1303,7 +1442,8 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "sender" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1317,19 +1457,23 @@ Definition process_transaction : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let max_gas_fee := + let _ := M.assign_local (| + "max_gas_fee" , BinOp.mult (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_field (| M.get_name (| globals, "tx" |), "max_fee_per_gas" |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let max_gas_fee := + let _ := M.assign_local (| + "max_gas_fee" , BinOp.mult (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -1372,12 +1516,15 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let effective_gas_fee := + let _ := M.assign_local (| + "effective_gas_fee" , BinOp.mult (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_field (| M.get_name (| globals, "env" |), "gas_price" |) - |) in - let gas := + |) + |) in + let _ := M.assign_local (| + "gas" , BinOp.sub (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.call (| @@ -1387,7 +1534,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "increment_nonce" |), make_list [ @@ -1396,11 +1544,13 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_balance_after_gas_fee := + let _ := M.assign_local (| + "sender_balance_after_gas_fee" , BinOp.sub (| M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), M.get_name (| globals, "effective_gas_fee" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -1410,18 +1560,22 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let preaccessed_addresses := + let _ := M.assign_local (| + "preaccessed_addresses" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let preaccessed_storage_keys := + |) + |) in + let _ := M.assign_local (| + "preaccessed_storage_keys" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "preaccessed_addresses" |), "add" |), make_list [ @@ -1483,7 +1637,8 @@ Definition process_transaction : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let message := + let _ := M.assign_local (| + "message" , M.call (| M.get_name (| globals, "prepare_message" |), make_list [ @@ -1495,8 +1650,10 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in - let output := + |) + |) in + let _ := M.assign_local (| + "output" , M.call (| M.get_name (| globals, "process_message_call" |), make_list [ @@ -1504,13 +1661,17 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in - let gas_used := + |) + |) in + let _ := M.assign_local (| + "gas_used" , BinOp.sub (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_field (| M.get_name (| globals, "output" |), "gas_left" |) - |) in - let gas_refund := + |) + |) in + let _ := M.assign_local (| + "gas_refund" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -1521,21 +1682,27 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "output" |), "refund_counter" |) ], make_dict [] - |) in - let gas_refund_amount := + |) + |) in + let _ := M.assign_local (| + "gas_refund_amount" , BinOp.mult (| BinOp.add (| M.get_field (| M.get_name (| globals, "output" |), "gas_left" |), M.get_name (| globals, "gas_refund" |) |), M.get_field (| M.get_name (| globals, "env" |), "gas_price" |) - |) in - let priority_fee_per_gas := + |) + |) in + let _ := M.assign_local (| + "priority_fee_per_gas" , BinOp.sub (| M.get_field (| M.get_name (| globals, "env" |), "gas_price" |), M.get_field (| M.get_name (| globals, "env" |), "base_fee_per_gas" |) - |) in - let transaction_fee := + |) + |) in + let _ := M.assign_local (| + "transaction_fee" , BinOp.mult (| BinOp.sub (| BinOp.sub (| @@ -1545,13 +1712,17 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "gas_refund" |) |), M.get_name (| globals, "priority_fee_per_gas" |) - |) in - let total_gas_used := + |) + |) in + let _ := M.assign_local (| + "total_gas_used" , BinOp.sub (| M.get_name (| globals, "gas_used" |), M.get_name (| globals, "gas_refund" |) - |) in - let sender_balance_after_refund := + |) + |) in + let _ := M.assign_local (| + "sender_balance_after_refund" , BinOp.add (| M.get_field (| M.call (| M.get_name (| globals, "get_account" |), @@ -1562,7 +1733,8 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |), "balance" |), M.get_name (| globals, "gas_refund_amount" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -1572,7 +1744,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let coinbase_balance_after_mining_fee := + let _ := M.assign_local (| + "coinbase_balance_after_mining_fee" , BinOp.add (| M.get_field (| M.call (| M.get_name (| globals, "get_account" |), @@ -1583,7 +1756,8 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |), "balance" |), M.get_name (| globals, "transaction_fee" |) - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1837,8 +2011,10 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := verified : `ethereum.base_types.Uint` The intrinsic cost of the transaction. " in - let data_cost := - Constant.int 0 in + let _ := M.assign_local (| + "data_cost" , + Constant.int 0 + |) in let _ := M.for_ (| M.get_name (| globals, "byte" |), @@ -1853,15 +2029,19 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let data_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "data_cost", M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let data_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "data_cost", M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -1885,7 +2065,8 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let create_cost := + let _ := M.assign_local (| + "create_cost" , BinOp.add (| M.get_name (| globals, "TX_CREATE_COST" |), M.call (| @@ -1913,16 +2094,21 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := ], make_dict [] |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let create_cost := - Constant.int 0 in + let _ := M.assign_local (| + "create_cost" , + Constant.int 0 + |) in M.pure Constant.None_ )) |) in - let access_list_cost := - Constant.int 0 in + let _ := M.assign_local (| + "access_list_cost" , + Constant.int 0 + |) in let _ := (* if *) M.if_then_else (| @@ -1941,10 +2127,14 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := make_tuple [ M.get_name (| globals, "_address" |); M.get_name (| globals, "keys" |) ], M.get_field (| M.get_name (| globals, "tx" |), "access_list" |), ltac:(M.monadic ( - let access_list_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "access_list_cost", M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) - M.get_name (| globals, "TX_ACCESS_LIST_ADDRESS_COST" |) in - let access_list_cost := BinOp.add + |) in + let _ := M.assign_op_local (| + BinOp.add, + "access_list_cost", BinOp.mult (| M.call (| M.get_name (| globals, "len" |), @@ -1955,16 +2145,7 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) |) - BinOp.mult (| - M.call (| - M.get_name (| globals, "len" |), - make_list [ - M.get_name (| globals, "keys" |) - ], - make_dict [] - |), - M.get_name (| globals, "TX_ACCESS_LIST_STORAGE_KEY_COST" |) - |) in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -2078,8 +2259,10 @@ Definition recover_sender : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let v := - M.get_field (| M.get_name (| globals, "tx" |), "v" |) in + let _ := M.assign_local (| + "v" , + M.get_field (| M.get_name (| globals, "tx" |), "v" |) + |) in let _ := (* if *) M.if_then_else (| @@ -2097,7 +2280,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let public_key := + let _ := M.assign_local (| + "public_key" , M.call (| M.get_name (| globals, "secp256k1_recover" |), make_list [ @@ -2116,7 +2300,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -2151,7 +2336,8 @@ Definition recover_sender : Value.t -> Value.t -> M := ], make_dict [] |) in - let public_key := + let _ := M.assign_local (| + "public_key" , M.call (| M.get_name (| globals, "secp256k1_recover" |), make_list [ @@ -2177,7 +2363,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -2196,7 +2383,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let public_key := + let _ := M.assign_local (| + "public_key" , M.call (| M.get_name (| globals, "secp256k1_recover" |), make_list [ @@ -2212,7 +2400,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -2229,7 +2418,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let public_key := + let _ := M.assign_local (| + "public_key" , M.call (| M.get_name (| globals, "secp256k1_recover" |), make_list [ @@ -2245,7 +2435,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -2510,11 +2701,13 @@ Definition check_gas_limit : Value.t -> Value.t -> M := check : `bool` True if gas limit constraints are satisfied, False otherwise. " in - let max_adjustment_delta := + let _ := M.assign_local (| + "max_adjustment_delta" , BinOp.floor_div (| M.get_name (| globals, "parent_gas_limit" |), M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) - |) in + |) + |) in let _ := (* if *) M.if_then_else (| diff --git a/CoqOfPython/ethereum/shanghai/fork_types.v b/CoqOfPython/ethereum/shanghai/fork_types.v index 0f4ef00..ce691e3 100644 --- a/CoqOfPython/ethereum/shanghai/fork_types.v +++ b/CoqOfPython/ethereum/shanghai/fork_types.v @@ -17,17 +17,29 @@ Introduction Types re-used throughout the specification, which are specific to Ethereum. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes20"; "Bytes256"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes20 : + IsImported globals "ethereum.base_types" "Bytes20". +Axiom ethereum_base_types_imports_Bytes256 : + IsImported globals "ethereum.base_types" "Bytes256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) diff --git a/CoqOfPython/ethereum/shanghai/state.v b/CoqOfPython/ethereum/shanghai/state.v index 8434eb0..6c39384 100644 --- a/CoqOfPython/ethereum/shanghai/state.v +++ b/CoqOfPython/ethereum/shanghai/state.v @@ -22,26 +22,60 @@ There is a distinction between an account that does not exist and `EMPTY_ACCOUNT`. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass"; "field" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict"; "List"; "Optional"; "Set"; "Tuple" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "modify" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_shanghai_blocks_imports : - AreImported globals "ethereum.shanghai.blocks" [ "Withdrawal" ]. - -Axiom ethereum_shanghai_fork_types_imports : - AreImported globals "ethereum.shanghai.fork_types" [ "EMPTY_ACCOUNT"; "Account"; "Address"; "Root" ]. - -Axiom ethereum_shanghai_trie_imports : - AreImported globals "ethereum.shanghai.trie" [ "EMPTY_TRIE_ROOT"; "Trie"; "copy_trie"; "root"; "trie_get"; "trie_set" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". +Axiom dataclasses_imports_field : + IsImported globals "dataclasses" "field". + +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_modify : + IsImported globals "ethereum.base_types" "modify". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_shanghai_blocks_imports_Withdrawal : + IsImported globals "ethereum.shanghai.blocks" "Withdrawal". + +Axiom ethereum_shanghai_fork_types_imports_EMPTY_ACCOUNT : + IsImported globals "ethereum.shanghai.fork_types" "EMPTY_ACCOUNT". +Axiom ethereum_shanghai_fork_types_imports_Account : + IsImported globals "ethereum.shanghai.fork_types" "Account". +Axiom ethereum_shanghai_fork_types_imports_Address : + IsImported globals "ethereum.shanghai.fork_types" "Address". +Axiom ethereum_shanghai_fork_types_imports_Root : + IsImported globals "ethereum.shanghai.fork_types" "Root". + +Axiom ethereum_shanghai_trie_imports_EMPTY_TRIE_ROOT : + IsImported globals "ethereum.shanghai.trie" "EMPTY_TRIE_ROOT". +Axiom ethereum_shanghai_trie_imports_Trie : + IsImported globals "ethereum.shanghai.trie" "Trie". +Axiom ethereum_shanghai_trie_imports_copy_trie : + IsImported globals "ethereum.shanghai.trie" "copy_trie". +Axiom ethereum_shanghai_trie_imports_root : + IsImported globals "ethereum.shanghai.trie" "root". +Axiom ethereum_shanghai_trie_imports_trie_get : + IsImported globals "ethereum.shanghai.trie" "trie_get". +Axiom ethereum_shanghai_trie_imports_trie_set : + IsImported globals "ethereum.shanghai.trie" "trie_set". Definition State : Value.t := builtins.make_klass @@ -189,7 +223,8 @@ Definition get_account : Value.t -> Value.t -> M := account : `Account` Account at address. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account_optional" |), make_list [ @@ -197,7 +232,8 @@ Definition get_account : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -243,7 +279,8 @@ Definition get_account_optional : Value.t -> Value.t -> M := account : `Account` Account at address. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "trie_get" |), make_list [ @@ -251,7 +288,8 @@ Definition get_account_optional : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "account" |) |) in @@ -402,14 +440,16 @@ Definition get_storage : Value.t -> Value.t -> M := value : `U256` Value at the key. " in - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -433,7 +473,8 @@ Definition get_storage : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "trie_get" |), make_list [ @@ -441,7 +482,8 @@ Definition get_storage : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -484,14 +526,16 @@ Definition set_storage : Value.t -> Value.t -> M := |), Constant.None_ |) |) in - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -501,12 +545,14 @@ Definition set_storage : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_name (| globals, "Trie" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), @@ -533,7 +579,7 @@ Definition set_storage : Value.t -> Value.t -> M := M.if_then_else (| Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), - {} + Constant.str "(* At expr: unsupported node type: Dict *)" |), (* then *) ltac:(M.monadic ( @@ -679,7 +725,8 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := True if if an account has non zero nonce or non empty code, False otherwise. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -687,7 +734,8 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| BoolOp.or (| Compare.not_eq (| @@ -729,7 +777,8 @@ Definition is_account_empty : Value.t -> Value.t -> M := True if if an account has zero nonce, empty code and zero balance, False otherwise. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -737,7 +786,8 @@ Definition is_account_empty : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| BoolOp.and (| Compare.eq (| @@ -788,7 +838,8 @@ Definition account_exists_and_is_empty : Value.t -> Value.t -> M := True if an account exists and has zero nonce, empty code and zero balance, False otherwise. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account_optional" |), make_list [ @@ -796,7 +847,8 @@ Definition account_exists_and_is_empty : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| BoolOp.and (| Compare.is_not (| @@ -853,7 +905,8 @@ Definition is_account_alive : Value.t -> Value.t -> M := is_alive : `bool` True if the account is alive. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account_optional" |), make_list [ @@ -861,7 +914,8 @@ Definition is_account_alive : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1160,14 +1214,16 @@ Definition get_storage_original : Value.t -> Value.t -> M := Constant.int 0 |) |) in - let original_account_trie := + let _ := M.assign_local (| + "original_account_trie" , M.call (| M.get_field (| M.get_name (| globals, "original_trie" |), "get" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1177,18 +1233,21 @@ Definition get_storage_original : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let original_value := + let _ := M.assign_local (| + "original_value" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let original_value := + let _ := M.assign_local (| + "original_value" , M.call (| M.get_name (| globals, "trie_get" |), make_list [ @@ -1196,7 +1255,8 @@ Definition get_storage_original : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.assert (| M.call (| diff --git a/CoqOfPython/ethereum/shanghai/transactions.v b/CoqOfPython/ethereum/shanghai/transactions.v index 6e939bf..76f69cd 100644 --- a/CoqOfPython/ethereum/shanghai/transactions.v +++ b/CoqOfPython/ethereum/shanghai/transactions.v @@ -9,23 +9,37 @@ submitted to be executed. If Ethereum is viewed as a state machine, transactions are the events that move between states. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". -Axiom typing_imports : - AreImported globals "typing" [ "Tuple"; "Union" ]. +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U64"; "U256"; "Bytes"; "Bytes0"; "Bytes32"; "Uint"; "slotted_freezable" ]. +Axiom ethereum_base_types_imports_U64 : + IsImported globals "ethereum.base_types" "U64". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". -Axiom ethereum_exceptions_imports : - AreImported globals "ethereum.exceptions" [ "InvalidBlock" ]. +Axiom ethereum_exceptions_imports_InvalidBlock : + IsImported globals "ethereum.exceptions" "InvalidBlock". -Axiom ethereum_shanghai_fork_types_imports : - AreImported globals "ethereum.shanghai.fork_types" [ "Address" ]. +Axiom ethereum_shanghai_fork_types_imports_Address : + IsImported globals "ethereum.shanghai.fork_types" "Address". Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( Constant.int 21000 diff --git a/CoqOfPython/ethereum/shanghai/trie.v b/CoqOfPython/ethereum/shanghai/trie.v index 2983dcf..3192625 100644 --- a/CoqOfPython/ethereum/shanghai/trie.v +++ b/CoqOfPython/ethereum/shanghai/trie.v @@ -20,38 +20,74 @@ The state trie is the structure responsible for storing (* At top_level_stmt: unsupported node type: Import *) -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass"; "field" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict"; "Generic"; "List"; "Mapping"; "MutableMapping"; "Optional"; "Sequence"; "TypeVar"; "Union"; "cast" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. - -Axiom ethereum_paris_imports : - AreImported globals "ethereum.paris" [ "trie" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_utils_hexadecimal_imports : - AreImported globals "ethereum.utils.hexadecimal" [ "hex_to_bytes" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_shanghai_blocks_imports : - AreImported globals "ethereum.shanghai.blocks" [ "Receipt"; "Withdrawal" ]. - -Axiom ethereum_shanghai_fork_types_imports : - AreImported globals "ethereum.shanghai.fork_types" [ "Account"; "Address"; "Root"; "encode_account" ]. - -Axiom ethereum_shanghai_transactions_imports : - AreImported globals "ethereum.shanghai.transactions" [ "LegacyTransaction" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". +Axiom dataclasses_imports_field : + IsImported globals "dataclasses" "field". + +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". +Axiom typing_imports_Generic : + IsImported globals "typing" "Generic". +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Mapping : + IsImported globals "typing" "Mapping". +Axiom typing_imports_MutableMapping : + IsImported globals "typing" "MutableMapping". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Sequence : + IsImported globals "typing" "Sequence". +Axiom typing_imports_TypeVar : + IsImported globals "typing" "TypeVar". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". +Axiom typing_imports_cast : + IsImported globals "typing" "cast". + +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". + +Axiom ethereum_paris_imports_trie : + IsImported globals "ethereum.paris" "trie". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_utils_hexadecimal_imports_hex_to_bytes : + IsImported globals "ethereum.utils.hexadecimal" "hex_to_bytes". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_shanghai_blocks_imports_Receipt : + IsImported globals "ethereum.shanghai.blocks" "Receipt". +Axiom ethereum_shanghai_blocks_imports_Withdrawal : + IsImported globals "ethereum.shanghai.blocks" "Withdrawal". + +Axiom ethereum_shanghai_fork_types_imports_Account : + IsImported globals "ethereum.shanghai.fork_types" "Account". +Axiom ethereum_shanghai_fork_types_imports_Address : + IsImported globals "ethereum.shanghai.fork_types" "Address". +Axiom ethereum_shanghai_fork_types_imports_Root : + IsImported globals "ethereum.shanghai.fork_types" "Root". +Axiom ethereum_shanghai_fork_types_imports_encode_account : + IsImported globals "ethereum.shanghai.fork_types" "encode_account". + +Axiom ethereum_shanghai_transactions_imports_LegacyTransaction : + IsImported globals "ethereum.shanghai.transactions" "LegacyTransaction". Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -174,7 +210,7 @@ Definition encode_internal_node : Value.t -> Value.t -> M := when serialized. This function also accepts `None`, representing the absence of a node, - which is encoded to `b""""""`. + which is encoded to `b""""`. Parameters ---------- @@ -196,8 +232,10 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := - Constant.bytes "" in + let _ := M.assign_local (| + "unencoded" , + Constant.bytes "" + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -214,7 +252,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := + let _ := M.assign_local (| + "unencoded" , make_tuple [ M.call (| M.get_name (| globals, "nibble_list_to_compact" |), make_list [ @@ -222,7 +261,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := Constant.bool true ], make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in + |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -239,7 +279,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := + let _ := M.assign_local (| + "unencoded" , make_tuple [ M.call (| M.get_name (| globals, "nibble_list_to_compact" |), make_list [ @@ -247,7 +288,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := Constant.bool false ], make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in + |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -264,13 +306,15 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := + let _ := M.assign_local (| + "unencoded" , BinOp.add (| M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), make_list [ M.get_field (| M.get_name (| globals, "node" |), "value" |) ] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -289,14 +333,16 @@ Definition encode_internal_node : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - let encoded := + let _ := M.assign_local (| + "encoded" , M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), make_list [ M.get_name (| globals, "unencoded" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -688,12 +734,14 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := compressed : `bytearray` Compact byte array. " in - let compact := + let _ := M.assign_local (| + "compact" , M.call (| M.get_name (| globals, "bytearray" |), make_list [], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -873,7 +921,8 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := nibble_list : `Bytes` The `Bytes` in nibble-list format. " in - let nibble_list := + let _ := M.assign_local (| + "nibble_list" , M.call (| M.get_name (| globals, "bytearray" |), make_list [ @@ -889,7 +938,8 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ], @@ -997,15 +1047,18 @@ Definition _prepare_trie : Value.t -> Value.t -> M := M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "Address" |), make_list [ M.get_name (| globals, "preimage" |) ], make_dict [] - |) in - let encoded_value := + |) + |) in + let _ := M.assign_local (| + "encoded_value" , M.call (| M.get_name (| globals, "encode_node" |), make_list [ @@ -1019,18 +1072,21 @@ Definition _prepare_trie : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let encoded_value := + let _ := M.assign_local (| + "encoded_value" , M.call (| M.get_name (| globals, "encode_node" |), make_list [ M.get_name (| globals, "value" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -1051,19 +1107,23 @@ Definition _prepare_trie : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "trie" |), "secured" |), (* then *) ltac:(M.monadic ( - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "preimage" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let key := - M.get_name (| globals, "preimage" |) in + let _ := M.assign_local (| + "key" , + M.get_name (| globals, "preimage" |) + |) in M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -1110,7 +1170,8 @@ Definition root : Value.t -> Value.t -> M := root : `.fork_types.Root` MPT root of the underlying key-value pairs. " in - let obj := + let _ := M.assign_local (| + "obj" , M.call (| M.get_name (| globals, "_prepare_trie" |), make_list [ @@ -1118,8 +1179,10 @@ Definition root : Value.t -> Value.t -> M := M.get_name (| globals, "get_storage_root" |) ], make_dict [] - |) in - let root_node := + |) + |) in + let _ := M.assign_local (| + "root_node" , M.call (| M.get_name (| globals, "encode_internal_node" |), make_list [ @@ -1139,7 +1202,8 @@ Definition root : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1244,7 +1308,8 @@ Definition patricialize : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let arbitrary_key := + let _ := M.assign_local (| + "arbitrary_key" , M.call (| M.get_name (| globals, "next" |), make_list [ @@ -1257,7 +1322,8 @@ Definition patricialize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1273,7 +1339,8 @@ Definition patricialize : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let leaf := + let _ := M.assign_local (| + "leaf" , M.call (| M.get_name (| globals, "LeafNode" |), make_list [ @@ -1289,7 +1356,8 @@ Definition patricialize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "leaf" |) |) in @@ -1298,27 +1366,32 @@ Definition patricialize : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let substring := + let _ := M.assign_local (| + "substring" , M.slice (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |), Constant.None_, Constant.None_ - |) in - let prefix_length := + |) + |) in + let _ := M.assign_local (| + "prefix_length" , M.call (| M.get_name (| globals, "len" |), make_list [ M.get_name (| globals, "substring" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "key" |), M.get_name (| globals, "obj" |), ltac:(M.monadic ( - let prefix_length := + let _ := M.assign_local (| + "prefix_length" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -1338,7 +1411,8 @@ Definition patricialize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1369,7 +1443,8 @@ Definition patricialize : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let prefix := + let _ := M.assign_local (| + "prefix" , M.slice (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |), @@ -1378,7 +1453,8 @@ Definition patricialize : Value.t -> Value.t -> M := M.get_name (| globals, "prefix_length" |) |), Constant.None_ - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ExtensionNode" |), @@ -1425,7 +1501,7 @@ Definition patricialize : Value.t -> Value.t -> M := let _ := M.call (| M.get_field (| M.get_name (| globals, "branches" |), "append" |), make_list [ - {} + Constant.str "(* At expr: unsupported node type: Dict *)" ], make_dict [] |) in @@ -1435,8 +1511,10 @@ Definition patricialize : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let value := - Constant.bytes "" in + let _ := M.assign_local (| + "value" , + Constant.bytes "" + |) in let _ := M.for_ (| M.get_name (| globals, "key" |), @@ -1479,11 +1557,13 @@ Definition patricialize : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let value := + let _ := M.assign_local (| + "value" , M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/shanghai/utils/address.v b/CoqOfPython/ethereum/shanghai/utils/address.v index f2d8436..309f4c7 100644 --- a/CoqOfPython/ethereum/shanghai/utils/address.v +++ b/CoqOfPython/ethereum/shanghai/utils/address.v @@ -18,23 +18,27 @@ Address specific functions used in this shanghai version of specification. ". -Axiom typing_imports : - AreImported globals "typing" [ "Union" ]. +Axiom typing_imports_Union : + IsImported globals "typing" "Union". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes32"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_left_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "left_pad_zero_bytes". -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". -Axiom ethereum_shanghai_fork_types_imports : - AreImported globals "ethereum.shanghai.fork_types" [ "Address" ]. +Axiom ethereum_shanghai_fork_types_imports_Address : + IsImported globals "ethereum.shanghai.fork_types" "Address". Definition to_address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -91,7 +95,8 @@ Definition compute_contract_address : Value.t -> Value.t -> M := address: `Address` The computed address of the new account. " in - let computed_address := + let _ := M.assign_local (| + "computed_address" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -107,15 +112,19 @@ Definition compute_contract_address : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let canonical_address := + |) + |) in + let _ := M.assign_local (| + "canonical_address" , M.slice (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |), Constant.None_, Constant.None_ - |) in - let padded_address := + |) + |) in + let _ := M.assign_local (| + "padded_address" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -123,7 +132,8 @@ Definition compute_contract_address : Value.t -> Value.t -> M := Constant.int 20 ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Address" |), @@ -156,7 +166,8 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := address: `ethereum.shanghai.fork_types.Address` The computed address of the new account. " in - let preimage := + let _ := M.assign_local (| + "preimage" , BinOp.add (| BinOp.add (| BinOp.add (| @@ -172,23 +183,29 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := ], make_dict [] |) - |) in - let computed_address := + |) + |) in + let _ := M.assign_local (| + "computed_address" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "preimage" |) ], make_dict [] - |) in - let canonical_address := + |) + |) in + let _ := M.assign_local (| + "canonical_address" , M.slice (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |), Constant.None_, Constant.None_ - |) in - let padded_address := + |) + |) in + let _ := M.assign_local (| + "padded_address" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -196,7 +213,8 @@ Definition compute_create2_contract_address : Value.t -> Value.t -> M := Constant.int 20 ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Address" |), diff --git a/CoqOfPython/ethereum/shanghai/utils/hexadecimal.v b/CoqOfPython/ethereum/shanghai/utils/hexadecimal.v index e7da0f7..d044fd0 100644 --- a/CoqOfPython/ethereum/shanghai/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/shanghai/utils/hexadecimal.v @@ -18,11 +18,15 @@ Hexadecimal utility functions used in this specification, specific to Shanghai types. ". -Axiom ethereum_utils_hexadecimal_imports : - AreImported globals "ethereum.utils.hexadecimal" [ "remove_hex_prefix" ]. - -Axiom ethereum_shanghai_fork_types_imports : - AreImported globals "ethereum.shanghai.fork_types" [ "Address"; "Bloom"; "Root" ]. +Axiom ethereum_utils_hexadecimal_imports_remove_hex_prefix : + IsImported globals "ethereum.utils.hexadecimal" "remove_hex_prefix". + +Axiom ethereum_shanghai_fork_types_imports_Address : + IsImported globals "ethereum.shanghai.fork_types" "Address". +Axiom ethereum_shanghai_fork_types_imports_Bloom : + IsImported globals "ethereum.shanghai.fork_types" "Bloom". +Axiom ethereum_shanghai_fork_types_imports_Root : + IsImported globals "ethereum.shanghai.fork_types" "Root". Definition hex_to_root : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/shanghai/utils/message.v b/CoqOfPython/ethereum/shanghai/utils/message.v index 706cf76..d1e2dbc 100644 --- a/CoqOfPython/ethereum/shanghai/utils/message.v +++ b/CoqOfPython/ethereum/shanghai/utils/message.v @@ -18,26 +18,42 @@ Message specific functions used in this shanghai version of specification. ". -Axiom typing_imports : - AreImported globals "typing" [ "FrozenSet"; "Optional"; "Tuple"; "Union" ]. +Axiom typing_imports_FrozenSet : + IsImported globals "typing" "FrozenSet". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Bytes32"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_shanghai_fork_types_imports : - AreImported globals "ethereum.shanghai.fork_types" [ "Address" ]. +Axiom ethereum_shanghai_fork_types_imports_Address : + IsImported globals "ethereum.shanghai.fork_types" "Address". -Axiom ethereum_shanghai_state_imports : - AreImported globals "ethereum.shanghai.state" [ "get_account" ]. +Axiom ethereum_shanghai_state_imports_get_account : + IsImported globals "ethereum.shanghai.state" "get_account". -Axiom ethereum_shanghai_vm_imports : - AreImported globals "ethereum.shanghai.vm" [ "Environment"; "Message" ]. +Axiom ethereum_shanghai_vm_imports_Environment : + IsImported globals "ethereum.shanghai.vm" "Environment". +Axiom ethereum_shanghai_vm_imports_Message : + IsImported globals "ethereum.shanghai.vm" "Message". -Axiom ethereum_shanghai_vm_precompiled_contracts_mapping_imports : - AreImported globals "ethereum.shanghai.vm.precompiled_contracts.mapping" [ "PRE_COMPILED_CONTRACTS" ]. +Axiom ethereum_shanghai_vm_precompiled_contracts_mapping_imports_PRE_COMPILED_CONTRACTS : + IsImported globals "ethereum.shanghai.vm.precompiled_contracts.mapping" "PRE_COMPILED_CONTRACTS". -Axiom ethereum_shanghai_utils_address_imports : - AreImported globals "ethereum.shanghai.utils.address" [ "compute_contract_address" ]. +Axiom ethereum_shanghai_utils_address_imports_compute_contract_address : + IsImported globals "ethereum.shanghai.utils.address" "compute_contract_address". Definition prepare_message : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -92,7 +108,8 @@ Definition prepare_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let current_target := + let _ := M.assign_local (| + "current_target" , M.call (| M.get_name (| globals, "compute_contract_address" |), make_list [ @@ -116,17 +133,22 @@ Definition prepare_message : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let msg_data := + |) + |) in + let _ := M.assign_local (| + "msg_data" , M.call (| M.get_name (| globals, "Bytes" |), make_list [ Constant.bytes "" ], make_dict [] - |) in - let code := - M.get_name (| globals, "data" |) in + |) + |) in + let _ := M.assign_local (| + "code" , + M.get_name (| globals, "data" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -143,11 +165,16 @@ Definition prepare_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let current_target := - M.get_name (| globals, "target" |) in - let msg_data := - M.get_name (| globals, "data" |) in - let code := + let _ := M.assign_local (| + "current_target" , + M.get_name (| globals, "target" |) + |) in + let _ := M.assign_local (| + "msg_data" , + M.get_name (| globals, "data" |) + |) in + let _ := M.assign_local (| + "code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -155,7 +182,8 @@ Definition prepare_message : Value.t -> Value.t -> M := M.get_name (| globals, "target" |) ], make_dict [] - |), "code" |) in + |), "code" |) + |) in let _ := (* if *) M.if_then_else (| @@ -165,8 +193,10 @@ Definition prepare_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let code_address := - M.get_name (| globals, "target" |) in + let _ := M.assign_local (| + "code_address" , + M.get_name (| globals, "target" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -186,12 +216,14 @@ Definition prepare_message : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - let accessed_addresses := + let _ := M.assign_local (| + "accessed_addresses" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "accessed_addresses" |), "add" |), make_list [ diff --git a/CoqOfPython/ethereum/shanghai/vm/__init__.v b/CoqOfPython/ethereum/shanghai/vm/__init__.v index a40457f..1cfebb9 100644 --- a/CoqOfPython/ethereum/shanghai/vm/__init__.v +++ b/CoqOfPython/ethereum/shanghai/vm/__init__.v @@ -18,29 +18,49 @@ The abstract computer which runs the code stored in an `.fork_types.Account`. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple"; "Union" ]. +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U64"; "U256"; "Bytes"; "Bytes0"; "Bytes32"; "Uint" ]. +Axiom ethereum_base_types_imports_U64 : + IsImported globals "ethereum.base_types" "U64". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". -Axiom ethereum_shanghai_blocks_imports : - AreImported globals "ethereum.shanghai.blocks" [ "Log" ]. +Axiom ethereum_shanghai_blocks_imports_Log : + IsImported globals "ethereum.shanghai.blocks" "Log". -Axiom ethereum_shanghai_fork_types_imports : - AreImported globals "ethereum.shanghai.fork_types" [ "Address" ]. +Axiom ethereum_shanghai_fork_types_imports_Address : + IsImported globals "ethereum.shanghai.fork_types" "Address". -Axiom ethereum_shanghai_state_imports : - AreImported globals "ethereum.shanghai.state" [ "State"; "account_exists_and_is_empty" ]. +Axiom ethereum_shanghai_state_imports_State : + IsImported globals "ethereum.shanghai.state" "State". +Axiom ethereum_shanghai_state_imports_account_exists_and_is_empty : + IsImported globals "ethereum.shanghai.state" "account_exists_and_is_empty". -Axiom ethereum_shanghai_vm_precompiled_contracts_imports : - AreImported globals "ethereum.shanghai.vm.precompiled_contracts" [ "RIPEMD160_ADDRESS" ]. +Axiom ethereum_shanghai_vm_precompiled_contracts_imports_RIPEMD160_ADDRESS : + IsImported globals "ethereum.shanghai.vm.precompiled_contracts" "RIPEMD160_ADDRESS". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] diff --git a/CoqOfPython/ethereum/shanghai/vm/exceptions.v b/CoqOfPython/ethereum/shanghai/vm/exceptions.v index fc20be3..b659bce 100644 --- a/CoqOfPython/ethereum/shanghai/vm/exceptions.v +++ b/CoqOfPython/ethereum/shanghai/vm/exceptions.v @@ -17,8 +17,8 @@ Introduction Exceptions which cause the EVM to halt exceptionally. ". -Axiom ethereum_exceptions_imports : - AreImported globals "ethereum.exceptions" [ "EthereumException" ]. +Axiom ethereum_exceptions_imports_EthereumException : + IsImported globals "ethereum.exceptions" "EthereumException". Definition ExceptionalHalt : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/shanghai/vm/gas.v b/CoqOfPython/ethereum/shanghai/vm/gas.v index 92abbef..3604b0f 100644 --- a/CoqOfPython/ethereum/shanghai/vm/gas.v +++ b/CoqOfPython/ethereum/shanghai/vm/gas.v @@ -17,26 +17,32 @@ Introduction EVM gas constants and calculators. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Tuple" ]. +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_trace_imports : - AreImported globals "ethereum.trace" [ "GasAndRefund"; "evm_trace" ]. +Axiom ethereum_trace_imports_GasAndRefund : + IsImported globals "ethereum.trace" "GasAndRefund". +Axiom ethereum_trace_imports_evm_trace : + IsImported globals "ethereum.trace" "evm_trace". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_shanghai_vm_imports : - AreImported globals "ethereum.shanghai.vm" [ "Evm" ]. +Axiom ethereum_shanghai_vm_imports_Evm : + IsImported globals "ethereum.shanghai.vm" "Evm". -Axiom ethereum_shanghai_vm_exceptions_imports : - AreImported globals "ethereum.shanghai.vm.exceptions" [ "OutOfGasError" ]. +Axiom ethereum_shanghai_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.shanghai.vm.exceptions" "OutOfGasError". Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -536,7 +542,8 @@ Definition calculate_memory_gas_cost : Value.t -> Value.t -> M := total_gas_cost : `ethereum.base_types.Uint` The gas cost for storing data in memory. " in - let size_in_words := + let _ := M.assign_local (| + "size_in_words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -546,25 +553,32 @@ Definition calculate_memory_gas_cost : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let linear_cost := + |) + |) in + let _ := M.assign_local (| + "linear_cost" , BinOp.mult (| M.get_name (| globals, "size_in_words" |), M.get_name (| globals, "GAS_MEMORY" |) - |) in - let quadratic_cost := + |) + |) in + let _ := M.assign_local (| + "quadratic_cost" , BinOp.floor_div (| BinOp.pow (| M.get_name (| globals, "size_in_words" |), Constant.int 2 |), Constant.int 512 - |) in - let total_gas_cost := + |) + |) in + let _ := M.assign_local (| + "total_gas_cost" , BinOp.add (| M.get_name (| globals, "linear_cost" |), M.get_name (| globals, "quadratic_cost" |) - |) in + |) + |) in (* At stmt: unsupported node type: Try *) M.pure Constant.None_)). @@ -586,23 +600,28 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := ------- extend_memory: `ExtendMemory` " in - let size_to_extend := + let _ := M.assign_local (| + "size_to_extend" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in - let to_be_paid := + |) + |) in + let _ := M.assign_local (| + "to_be_paid" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in - let current_size := + |) + |) in + let _ := M.assign_local (| + "current_size" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -615,7 +634,8 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ], @@ -636,15 +656,18 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let before_size := + let _ := M.assign_local (| + "before_size" , M.call (| M.get_name (| globals, "ceil32" |), make_list [ M.get_name (| globals, "current_size" |) ], make_dict [] - |) in - let after_size := + |) + |) in + let _ := M.assign_local (| + "after_size" , M.call (| M.get_name (| globals, "ceil32" |), make_list [ @@ -666,7 +689,8 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -682,42 +706,46 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let size_to_extend := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "size_to_extend", BinOp.sub (| M.get_name (| globals, "after_size" |), M.get_name (| globals, "before_size" |) |) - BinOp.sub (| - M.get_name (| globals, "after_size" |), - M.get_name (| globals, "before_size" |) - |) in - let already_paid := + |) in + let _ := M.assign_local (| + "already_paid" , M.call (| M.get_name (| globals, "calculate_memory_gas_cost" |), make_list [ M.get_name (| globals, "before_size" |) ], make_dict [] - |) in - let total_cost := + |) + |) in + let _ := M.assign_local (| + "total_cost" , M.call (| M.get_name (| globals, "calculate_memory_gas_cost" |), make_list [ M.get_name (| globals, "after_size" |) ], make_dict [] - |) in - let to_be_paid := BinOp.add + |) + |) in + let _ := M.assign_op_local (| + BinOp.add, + "to_be_paid", BinOp.sub (| M.get_name (| globals, "total_cost" |), M.get_name (| globals, "already_paid" |) |) - BinOp.sub (| - M.get_name (| globals, "total_cost" |), - M.get_name (| globals, "already_paid" |) - |) in - let current_size := - M.get_name (| globals, "after_size" |) in + |) in + let _ := M.assign_local (| + "current_size" , + M.get_name (| globals, "after_size" |) + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -764,7 +792,8 @@ Definition calculate_message_call_gas : Value.t -> Value.t -> M := ------- message_call_gas: `MessageCallGas` " in - let call_stipend := + let _ := M.assign_local (| + "call_stipend" , (* if *) M.if_then_else (| Compare.eq (| @@ -783,7 +812,8 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "call_stipend" |) - )) |) in + )) |) + |) in let _ := (* if *) M.if_then_else (| @@ -817,7 +847,8 @@ M.get_name (| globals, "call_stipend" |) )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -837,7 +868,8 @@ M.get_name (| globals, "call_stipend" |) |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "MessageCallGas" |), diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/__init__.v b/CoqOfPython/ethereum/shanghai/vm/instructions/__init__.v index 4281cd7..bf085c7 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/__init__.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/__init__.v @@ -20,44 +20,46 @@ implementations. (* At top_level_stmt: unsupported node type: Import *) -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict" ]. +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". -Axiom ethereum_shanghai_vm_instructions_imports : - AreImported globals "ethereum.shanghai.vm.instructions" [ "arithmetic" ]. +Axiom ethereum_shanghai_vm_instructions_imports_arithmetic : + IsImported globals "ethereum.shanghai.vm.instructions" "arithmetic". -Axiom ethereum_shanghai_vm_instructions_imports : - AreImported globals "ethereum.shanghai.vm.instructions" [ "bitwise" ]. +Axiom ethereum_shanghai_vm_instructions_imports_bitwise : + IsImported globals "ethereum.shanghai.vm.instructions" "bitwise". -Axiom ethereum_shanghai_vm_instructions_imports : - AreImported globals "ethereum.shanghai.vm.instructions" [ "block" ]. +Axiom ethereum_shanghai_vm_instructions_imports_block : + IsImported globals "ethereum.shanghai.vm.instructions" "block". -Axiom ethereum_shanghai_vm_instructions_imports : - AreImported globals "ethereum.shanghai.vm.instructions" [ "comparison" ]. +Axiom ethereum_shanghai_vm_instructions_imports_comparison : + IsImported globals "ethereum.shanghai.vm.instructions" "comparison". -Axiom ethereum_shanghai_vm_instructions_imports : - AreImported globals "ethereum.shanghai.vm.instructions" [ "control_flow" ]. +Axiom ethereum_shanghai_vm_instructions_imports_control_flow : + IsImported globals "ethereum.shanghai.vm.instructions" "control_flow". -Axiom ethereum_shanghai_vm_instructions_imports : - AreImported globals "ethereum.shanghai.vm.instructions" [ "environment" ]. +Axiom ethereum_shanghai_vm_instructions_imports_environment : + IsImported globals "ethereum.shanghai.vm.instructions" "environment". -Axiom ethereum_shanghai_vm_instructions_imports : - AreImported globals "ethereum.shanghai.vm.instructions" [ "keccak" ]. +Axiom ethereum_shanghai_vm_instructions_imports_keccak : + IsImported globals "ethereum.shanghai.vm.instructions" "keccak". -Axiom ethereum_shanghai_vm_instructions_imports : - AreImported globals "ethereum.shanghai.vm.instructions" [ "log" ]. +Axiom ethereum_shanghai_vm_instructions_imports_log : + IsImported globals "ethereum.shanghai.vm.instructions" "log". -Axiom ethereum_shanghai_vm_instructions_imports : - AreImported globals "ethereum.shanghai.vm.instructions" [ "memory" ]. +Axiom ethereum_shanghai_vm_instructions_imports_memory : + IsImported globals "ethereum.shanghai.vm.instructions" "memory". -Axiom ethereum_shanghai_vm_instructions_imports : - AreImported globals "ethereum.shanghai.vm.instructions" [ "stack" ]. +Axiom ethereum_shanghai_vm_instructions_imports_stack : + IsImported globals "ethereum.shanghai.vm.instructions" "stack". -Axiom ethereum_shanghai_vm_instructions_imports : - AreImported globals "ethereum.shanghai.vm.instructions" [ "storage" ]. +Axiom ethereum_shanghai_vm_instructions_imports_storage : + IsImported globals "ethereum.shanghai.vm.instructions" "storage". -Axiom ethereum_shanghai_vm_instructions_imports : - AreImported globals "ethereum.shanghai.vm.instructions" [ "system" ]. +Axiom ethereum_shanghai_vm_instructions_imports_system : + IsImported globals "ethereum.shanghai.vm.instructions" "system". Definition Ops : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/shanghai/vm/instructions/arithmetic.v index d155846..d62c2ed 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/arithmetic.v @@ -17,20 +17,38 @@ Introduction Implementations of the EVM Arithmetic instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U255_CEIL_VALUE"; "U256"; "U256_CEIL_VALUE"; "Uint" ]. +Axiom ethereum_base_types_imports_U255_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U255_CEIL_VALUE". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_U256_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U256_CEIL_VALUE". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "get_sign" ]. +Axiom ethereum_utils_numeric_imports_get_sign : + IsImported globals "ethereum.utils.numeric" "get_sign". -Axiom ethereum_shanghai_vm_imports : - AreImported globals "ethereum.shanghai.vm" [ "Evm" ]. +Axiom ethereum_shanghai_vm_imports_Evm : + IsImported globals "ethereum.shanghai.vm" "Evm". -Axiom ethereum_shanghai_vm_gas_imports : - AreImported globals "ethereum.shanghai.vm.gas" [ "GAS_EXPONENTIATION"; "GAS_EXPONENTIATION_PER_BYTE"; "GAS_LOW"; "GAS_MID"; "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_shanghai_vm_gas_imports_GAS_EXPONENTIATION : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_EXPONENTIATION". +Axiom ethereum_shanghai_vm_gas_imports_GAS_EXPONENTIATION_PER_BYTE : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_EXPONENTIATION_PER_BYTE". +Axiom ethereum_shanghai_vm_gas_imports_GAS_LOW : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_LOW". +Axiom ethereum_shanghai_vm_gas_imports_GAS_MID : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_MID". +Axiom ethereum_shanghai_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_shanghai_vm_gas_imports_charge_gas : + IsImported globals "ethereum.shanghai.vm.gas" "charge_gas". -Axiom ethereum_shanghai_vm_stack_imports : - AreImported globals "ethereum.shanghai.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_shanghai_vm_stack_imports_pop : + IsImported globals "ethereum.shanghai.vm.stack" "pop". +Axiom ethereum_shanghai_vm_stack_imports_push : + IsImported globals "ethereum.shanghai.vm.stack" "push". Definition add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,22 +63,26 @@ Definition add : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -69,14 +91,16 @@ Definition add : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "x" |), "wrapping_add" |), make_list [ M.get_name (| globals, "y" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -105,22 +129,26 @@ Definition sub : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -129,14 +157,16 @@ Definition sub : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "x" |), "wrapping_sub" |), make_list [ M.get_name (| globals, "y" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -165,22 +195,26 @@ Definition mul : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -189,14 +223,16 @@ Definition mul : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "x" |), "wrapping_mul" |), make_list [ M.get_name (| globals, "y" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -225,22 +261,26 @@ Definition div : Value.t -> Value.t -> M := The current EVM frame. " in - let dividend := + let _ := M.assign_local (| + "dividend" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let divisor := + |) + |) in + let _ := M.assign_local (| + "divisor" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -258,22 +298,26 @@ Definition div : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let quotient := + let _ := M.assign_local (| + "quotient" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let quotient := + let _ := M.assign_local (| + "quotient" , BinOp.floor_div (| M.get_name (| globals, "dividend" |), M.get_name (| globals, "divisor" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -304,7 +348,8 @@ Definition sdiv : Value.t -> Value.t -> M := The current EVM frame. " in - let dividend := + let _ := M.assign_local (| + "dividend" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -315,8 +360,10 @@ Definition sdiv : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let divisor := + |) + |) in + let _ := M.assign_local (| + "divisor" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -327,7 +374,8 @@ Definition sdiv : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -345,8 +393,10 @@ Definition sdiv : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let quotient := - Constant.int 0 in + let _ := M.assign_local (| + "quotient" , + Constant.int 0 + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -367,12 +417,15 @@ Definition sdiv : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let quotient := - UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in + let _ := M.assign_local (| + "quotient" , + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let sign := + let _ := M.assign_local (| + "sign" , M.call (| M.get_name (| globals, "get_sign" |), make_list [ @@ -382,8 +435,10 @@ Definition sdiv : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let quotient := + |) + |) in + let _ := M.assign_local (| + "quotient" , BinOp.mult (| M.get_name (| globals, "sign" |), BinOp.floor_div (| @@ -402,7 +457,8 @@ Definition sdiv : Value.t -> Value.t -> M := make_dict [] |) |) - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -428,7 +484,7 @@ Definition sdiv : Value.t -> Value.t -> M := |) in M.pure Constant.None_)). -Definition mod : Value.t -> Value.t -> M := +Definition mod_ : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in let _ := Constant.str " @@ -441,22 +497,26 @@ Definition mod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -474,22 +534,26 @@ Definition mod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let remainder := + let _ := M.assign_local (| + "remainder" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let remainder := + let _ := M.assign_local (| + "remainder" , BinOp.mod_ (| M.get_name (| globals, "x" |), M.get_name (| globals, "y" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -520,7 +584,8 @@ Definition smod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -531,8 +596,10 @@ Definition smod : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -543,7 +610,8 @@ Definition smod : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -561,12 +629,15 @@ Definition smod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let remainder := - Constant.int 0 in + let _ := M.assign_local (| + "remainder" , + Constant.int 0 + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let remainder := + let _ := M.assign_local (| + "remainder" , BinOp.mult (| M.call (| M.get_name (| globals, "get_sign" |), @@ -591,7 +662,8 @@ Definition smod : Value.t -> Value.t -> M := make_dict [] |) |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -628,7 +700,8 @@ Definition addmod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -641,8 +714,10 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -655,8 +730,10 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let z := + |) + |) in + let _ := M.assign_local (| + "z" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -669,7 +746,8 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -687,18 +765,21 @@ Definition addmod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -711,7 +792,8 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -742,7 +824,8 @@ Definition mulmod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -755,8 +838,10 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -769,8 +854,10 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let z := + |) + |) in + let _ := M.assign_local (| + "z" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -783,7 +870,8 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -801,18 +889,21 @@ Definition mulmod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -825,7 +916,8 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -856,7 +948,8 @@ Definition exp : Value.t -> Value.t -> M := The current EVM frame. " in - let base := + let _ := M.assign_local (| + "base" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -869,8 +962,10 @@ Definition exp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exponent := + |) + |) in + let _ := M.assign_local (| + "exponent" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -883,21 +978,26 @@ Definition exp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exponent_bits := + |) + |) in + let _ := M.assign_local (| + "exponent_bits" , M.call (| M.get_field (| M.get_name (| globals, "exponent" |), "bit_length" |), make_list [], make_dict [] - |) in - let exponent_bytes := + |) + |) in + let _ := M.assign_local (| + "exponent_bytes" , BinOp.floor_div (| BinOp.add (| M.get_name (| globals, "exponent_bits" |), Constant.int 7 |), Constant.int 8 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -912,7 +1012,8 @@ Definition exp : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -927,7 +1028,8 @@ Definition exp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -956,22 +1058,26 @@ Definition signextend : Value.t -> Value.t -> M := The current EVM frame. " in - let byte_num := + let _ := M.assign_local (| + "byte_num" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -989,12 +1095,15 @@ Definition signextend : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := - M.get_name (| globals, "value" |) in + let _ := M.assign_local (| + "result" , + M.get_name (| globals, "value" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let value_bytes := + let _ := M.assign_local (| + "value_bytes" , M.call (| M.get_name (| globals, "bytes" |), make_list [ @@ -1005,8 +1114,10 @@ Definition signextend : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let value_bytes := + |) + |) in + let _ := M.assign_local (| + "value_bytes" , M.slice (| M.get_name (| globals, "value_bytes" |), BinOp.sub (| @@ -1021,15 +1132,18 @@ Definition signextend : Value.t -> Value.t -> M := |), Constant.None_, Constant.None_ - |) in - let sign_bit := + |) + |) in + let _ := M.assign_local (| + "sign_bit" , BinOp.r_shift (| M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), Constant.int 7 - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1039,26 +1153,31 @@ Definition signextend : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "value_bytes" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let num_bytes_prepend := + let _ := M.assign_local (| + "num_bytes_prepend" , BinOp.sub (| Constant.int 32, BinOp.add (| M.get_name (| globals, "byte_num" |), Constant.int 1 |) - |) in - let result := + |) + |) in + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -1079,7 +1198,8 @@ Definition signextend : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/bitwise.v b/CoqOfPython/ethereum/shanghai/vm/instructions/bitwise.v index ac97518..5e49a28 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/bitwise.v @@ -17,17 +17,23 @@ Introduction Implementations of the EVM bitwise instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "U256_CEIL_VALUE" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_U256_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U256_CEIL_VALUE". -Axiom ethereum_shanghai_vm_imports : - AreImported globals "ethereum.shanghai.vm" [ "Evm" ]. +Axiom ethereum_shanghai_vm_imports_Evm : + IsImported globals "ethereum.shanghai.vm" "Evm". -Axiom ethereum_shanghai_vm_gas_imports : - AreImported globals "ethereum.shanghai.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_shanghai_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_shanghai_vm_gas_imports_charge_gas : + IsImported globals "ethereum.shanghai.vm.gas" "charge_gas". -Axiom ethereum_shanghai_vm_stack_imports : - AreImported globals "ethereum.shanghai.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_shanghai_vm_stack_imports_pop : + IsImported globals "ethereum.shanghai.vm.stack" "pop". +Axiom ethereum_shanghai_vm_stack_imports_push : + IsImported globals "ethereum.shanghai.vm.stack" "push". Definition bitwise_and : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,22 +48,26 @@ Definition bitwise_and : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -97,22 +107,26 @@ Definition bitwise_or : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -152,22 +166,26 @@ Definition bitwise_xor : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -207,14 +225,16 @@ Definition bitwise_not : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -252,22 +272,26 @@ Definition get_byte : Value.t -> Value.t -> M := The current EVM frame. " in - let byte_index := + let _ := M.assign_local (| + "byte_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let word := + |) + |) in + let _ := M.assign_local (| + "word" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -285,43 +309,53 @@ Definition get_byte : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let extra_bytes_to_right := + let _ := M.assign_local (| + "extra_bytes_to_right" , BinOp.sub (| Constant.int 31, M.get_name (| globals, "byte_index" |) - |) in - let word := + |) + |) in + let _ := M.assign_local (| + "word" , BinOp.r_shift (| M.get_name (| globals, "word" |), BinOp.mult (| M.get_name (| globals, "extra_bytes_to_right" |), Constant.int 8 |) - |) in - let word := + |) + |) in + let _ := M.assign_local (| + "word" , BinOp.bit_and (| M.get_name (| globals, "word" |), Constant.int 255 - |) in - let result := + |) + |) in + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ M.get_name (| globals, "word" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -350,22 +384,26 @@ Definition bitwise_shl : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let shift := + let _ := M.assign_local (| + "shift" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -383,7 +421,8 @@ Definition bitwise_shl : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -396,18 +435,21 @@ Definition bitwise_shl : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -436,22 +478,26 @@ Definition bitwise_shr : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let shift := + let _ := M.assign_local (| + "shift" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -469,22 +515,26 @@ Definition bitwise_shr : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , BinOp.r_shift (| M.get_name (| globals, "value" |), M.get_name (| globals, "shift" |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -513,15 +563,18 @@ Definition bitwise_sar : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let shift := + let _ := M.assign_local (| + "shift" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let signed_value := + |) + |) in + let _ := M.assign_local (| + "signed_value" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -532,7 +585,8 @@ Definition bitwise_sar : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -550,7 +604,8 @@ Definition bitwise_sar : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_signed" |), make_list [ @@ -560,7 +615,8 @@ Definition bitwise_sar : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -573,19 +629,23 @@ Definition bitwise_sar : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := - M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) in + let _ := M.assign_local (| + "result" , + M.get_field (| M.get_name (| globals, "U256" |), "MAX_VALUE" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/block.v b/CoqOfPython/ethereum/shanghai/vm/instructions/block.v index 60c3592..72e72da 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/block.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/block.v @@ -17,17 +17,23 @@ Introduction Implementations of the EVM block instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_shanghai_vm_imports : - AreImported globals "ethereum.shanghai.vm" [ "Evm" ]. +Axiom ethereum_shanghai_vm_imports_Evm : + IsImported globals "ethereum.shanghai.vm" "Evm". -Axiom ethereum_shanghai_vm_gas_imports : - AreImported globals "ethereum.shanghai.vm.gas" [ "GAS_BASE"; "GAS_BLOCK_HASH"; "charge_gas" ]. +Axiom ethereum_shanghai_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_BASE". +Axiom ethereum_shanghai_vm_gas_imports_GAS_BLOCK_HASH : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_BLOCK_HASH". +Axiom ethereum_shanghai_vm_gas_imports_charge_gas : + IsImported globals "ethereum.shanghai.vm.gas" "charge_gas". -Axiom ethereum_shanghai_vm_stack_imports : - AreImported globals "ethereum.shanghai.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_shanghai_vm_stack_imports_pop : + IsImported globals "ethereum.shanghai.vm.stack" "pop". +Axiom ethereum_shanghai_vm_stack_imports_push : + IsImported globals "ethereum.shanghai.vm.stack" "push". Definition block_hash : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -48,14 +54,16 @@ Definition block_hash : Value.t -> Value.t -> M := :py:class:`~ethereum.shanghai.vm.exceptions.OutOfGasError` If `evm.gas_left` is less than `20`. " in - let block_number := + let _ := M.assign_local (| + "block_number" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -84,19 +92,23 @@ Definition block_hash : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let hash := - Constant.bytes "00" in + let _ := M.assign_local (| + "hash" , + Constant.bytes "00" + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let hash := + let _ := M.assign_local (| + "hash" , M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), M.get_name (| globals, "block_number" |) |) |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/comparison.v b/CoqOfPython/ethereum/shanghai/vm/instructions/comparison.v index 6ae5902..53c9557 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/comparison.v @@ -17,17 +17,21 @@ Introduction Implementations of the EVM Comparison instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_shanghai_vm_imports : - AreImported globals "ethereum.shanghai.vm" [ "Evm" ]. +Axiom ethereum_shanghai_vm_imports_Evm : + IsImported globals "ethereum.shanghai.vm" "Evm". -Axiom ethereum_shanghai_vm_gas_imports : - AreImported globals "ethereum.shanghai.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_shanghai_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_shanghai_vm_gas_imports_charge_gas : + IsImported globals "ethereum.shanghai.vm.gas" "charge_gas". -Axiom ethereum_shanghai_vm_stack_imports : - AreImported globals "ethereum.shanghai.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_shanghai_vm_stack_imports_pop : + IsImported globals "ethereum.shanghai.vm.stack" "pop". +Axiom ethereum_shanghai_vm_stack_imports_push : + IsImported globals "ethereum.shanghai.vm.stack" "push". Definition less_than : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,22 +46,26 @@ Definition less_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -66,7 +74,8 @@ Definition less_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -76,7 +85,8 @@ Definition less_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -104,7 +114,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -115,8 +126,10 @@ Definition signed_less_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -127,7 +140,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -136,7 +150,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -146,7 +161,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -175,22 +191,26 @@ Definition greater_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -199,7 +219,8 @@ Definition greater_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -209,7 +230,8 @@ Definition greater_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -237,7 +259,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -248,8 +271,10 @@ Definition signed_greater_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -260,7 +285,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -269,7 +295,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -279,7 +306,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -308,22 +336,26 @@ Definition equal : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -332,7 +364,8 @@ Definition equal : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -342,7 +375,8 @@ Definition equal : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -371,14 +405,16 @@ Definition is_zero : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -387,7 +423,8 @@ Definition is_zero : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -397,7 +434,8 @@ Definition is_zero : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/control_flow.v b/CoqOfPython/ethereum/shanghai/vm/instructions/control_flow.v index c1d696d..e43ea45 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/control_flow.v @@ -17,20 +17,32 @@ Introduction Implementations of the EVM control flow instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_shanghai_vm_gas_imports : - AreImported globals "ethereum.shanghai.vm.gas" [ "GAS_BASE"; "GAS_HIGH"; "GAS_JUMPDEST"; "GAS_MID"; "charge_gas" ]. +Axiom ethereum_shanghai_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_BASE". +Axiom ethereum_shanghai_vm_gas_imports_GAS_HIGH : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_HIGH". +Axiom ethereum_shanghai_vm_gas_imports_GAS_JUMPDEST : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_JUMPDEST". +Axiom ethereum_shanghai_vm_gas_imports_GAS_MID : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_MID". +Axiom ethereum_shanghai_vm_gas_imports_charge_gas : + IsImported globals "ethereum.shanghai.vm.gas" "charge_gas". -Axiom ethereum_shanghai_vm_imports : - AreImported globals "ethereum.shanghai.vm" [ "Evm" ]. +Axiom ethereum_shanghai_vm_imports_Evm : + IsImported globals "ethereum.shanghai.vm" "Evm". -Axiom ethereum_shanghai_vm_exceptions_imports : - AreImported globals "ethereum.shanghai.vm.exceptions" [ "InvalidJumpDestError" ]. +Axiom ethereum_shanghai_vm_exceptions_imports_InvalidJumpDestError : + IsImported globals "ethereum.shanghai.vm.exceptions" "InvalidJumpDestError". -Axiom ethereum_shanghai_vm_stack_imports : - AreImported globals "ethereum.shanghai.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_shanghai_vm_stack_imports_pop : + IsImported globals "ethereum.shanghai.vm.stack" "pop". +Axiom ethereum_shanghai_vm_stack_imports_push : + IsImported globals "ethereum.shanghai.vm.stack" "push". Definition stop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -69,7 +81,8 @@ Definition jump : Value.t -> Value.t -> M := The current EVM frame. " in - let jump_dest := + let _ := M.assign_local (| + "jump_dest" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -82,7 +95,8 @@ Definition jump : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -132,7 +146,8 @@ Definition jumpi : Value.t -> Value.t -> M := The current EVM frame. " in - let jump_dest := + let _ := M.assign_local (| + "jump_dest" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -145,15 +160,18 @@ Definition jumpi : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let conditional_value := + |) + |) in + let _ := M.assign_local (| + "conditional_value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -171,11 +189,13 @@ Definition jumpi : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let destination := + let _ := M.assign_local (| + "destination" , BinOp.add (| M.get_field (| M.get_name (| globals, "evm" |), "pc" |), Constant.int 1 - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -192,8 +212,10 @@ Definition jumpi : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let destination := - M.get_name (| globals, "jump_dest" |) in + let _ := M.assign_local (| + "destination" , + M.get_name (| globals, "jump_dest" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/environment.v b/CoqOfPython/ethereum/shanghai/vm/instructions/environment.v index e529efa..17798fb 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/environment.v @@ -17,41 +17,63 @@ Introduction Implementations of the EVM environment related instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. - -Axiom ethereum_shanghai_fork_types_imports : - AreImported globals "ethereum.shanghai.fork_types" [ "EMPTY_ACCOUNT" ]. - -Axiom ethereum_shanghai_state_imports : - AreImported globals "ethereum.shanghai.state" [ "get_account" ]. - -Axiom ethereum_shanghai_utils_address_imports : - AreImported globals "ethereum.shanghai.utils.address" [ "to_address" ]. - -Axiom ethereum_shanghai_vm_memory_imports : - AreImported globals "ethereum.shanghai.vm.memory" [ "buffer_read"; "memory_write" ]. - -Axiom ethereum_shanghai_vm_imports : - AreImported globals "ethereum.shanghai.vm" [ "Evm" ]. - -Axiom ethereum_shanghai_vm_exceptions_imports : - AreImported globals "ethereum.shanghai.vm.exceptions" [ "OutOfBoundsRead" ]. - -Axiom ethereum_shanghai_vm_gas_imports : - AreImported globals "ethereum.shanghai.vm.gas" [ "GAS_BASE"; "GAS_COLD_ACCOUNT_ACCESS"; "GAS_COPY"; "GAS_FAST_STEP"; "GAS_RETURN_DATA_COPY"; "GAS_VERY_LOW"; "GAS_WARM_ACCESS"; "calculate_gas_extend_memory"; "charge_gas" ]. - -Axiom ethereum_shanghai_vm_stack_imports : - AreImported globals "ethereum.shanghai.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". + +Axiom ethereum_shanghai_fork_types_imports_EMPTY_ACCOUNT : + IsImported globals "ethereum.shanghai.fork_types" "EMPTY_ACCOUNT". + +Axiom ethereum_shanghai_state_imports_get_account : + IsImported globals "ethereum.shanghai.state" "get_account". + +Axiom ethereum_shanghai_utils_address_imports_to_address : + IsImported globals "ethereum.shanghai.utils.address" "to_address". + +Axiom ethereum_shanghai_vm_memory_imports_buffer_read : + IsImported globals "ethereum.shanghai.vm.memory" "buffer_read". +Axiom ethereum_shanghai_vm_memory_imports_memory_write : + IsImported globals "ethereum.shanghai.vm.memory" "memory_write". + +Axiom ethereum_shanghai_vm_imports_Evm : + IsImported globals "ethereum.shanghai.vm" "Evm". + +Axiom ethereum_shanghai_vm_exceptions_imports_OutOfBoundsRead : + IsImported globals "ethereum.shanghai.vm.exceptions" "OutOfBoundsRead". + +Axiom ethereum_shanghai_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_BASE". +Axiom ethereum_shanghai_vm_gas_imports_GAS_COLD_ACCOUNT_ACCESS : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_COLD_ACCOUNT_ACCESS". +Axiom ethereum_shanghai_vm_gas_imports_GAS_COPY : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_COPY". +Axiom ethereum_shanghai_vm_gas_imports_GAS_FAST_STEP : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_FAST_STEP". +Axiom ethereum_shanghai_vm_gas_imports_GAS_RETURN_DATA_COPY : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_RETURN_DATA_COPY". +Axiom ethereum_shanghai_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_shanghai_vm_gas_imports_GAS_WARM_ACCESS : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_WARM_ACCESS". +Axiom ethereum_shanghai_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.shanghai.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_shanghai_vm_gas_imports_charge_gas : + IsImported globals "ethereum.shanghai.vm.gas" "charge_gas". + +Axiom ethereum_shanghai_vm_stack_imports_pop : + IsImported globals "ethereum.shanghai.vm.stack" "pop". +Axiom ethereum_shanghai_vm_stack_imports_push : + IsImported globals "ethereum.shanghai.vm.stack" "push". Definition address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -107,7 +129,8 @@ Definition balance : Value.t -> Value.t -> M := The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -120,7 +143,8 @@ Definition balance : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -158,7 +182,8 @@ Definition balance : Value.t -> Value.t -> M := |) in M.pure Constant.None_ )) |) in - let balance := + let _ := M.assign_local (| + "balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -166,7 +191,8 @@ Definition balance : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -316,14 +342,16 @@ Definition calldataload : Value.t -> Value.t -> M := The current EVM frame. " in - let start_index := + let _ := M.assign_local (| + "start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -332,7 +360,8 @@ Definition calldataload : Value.t -> Value.t -> M := ], make_dict [] |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -347,7 +376,8 @@ Definition calldataload : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -432,31 +462,38 @@ Definition calldatacopy : Value.t -> Value.t -> M := The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let data_start_index := + |) + |) in + let _ := M.assign_local (| + "data_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -472,13 +509,17 @@ Definition calldatacopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -488,7 +529,8 @@ Definition calldatacopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -511,7 +553,8 @@ Definition calldatacopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -520,7 +563,8 @@ Definition calldatacopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -600,31 +644,38 @@ Definition codecopy : Value.t -> Value.t -> M := The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let code_start_index := + |) + |) in + let _ := M.assign_local (| + "code_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -640,13 +691,17 @@ Definition codecopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -656,7 +711,8 @@ Definition codecopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -679,7 +735,8 @@ Definition codecopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -688,7 +745,8 @@ Definition codecopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -759,7 +817,8 @@ Definition extcodesize : Value.t -> Value.t -> M := The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -772,7 +831,8 @@ Definition extcodesize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -810,7 +870,8 @@ Definition extcodesize : Value.t -> Value.t -> M := |) in M.pure Constant.None_ )) |) in - let codesize := + let _ := M.assign_local (| + "codesize" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -830,7 +891,8 @@ Definition extcodesize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -858,7 +920,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -871,32 +934,40 @@ Definition extcodecopy : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let memory_start_index := + |) + |) in + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let code_start_index := + |) + |) in + let _ := M.assign_local (| + "code_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -912,13 +983,17 @@ Definition extcodecopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -928,7 +1003,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -986,7 +1062,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let code := + let _ := M.assign_local (| + "code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -994,8 +1071,10 @@ Definition extcodecopy : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |), "code" |) in - let value := + |), "code" |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -1004,7 +1083,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -1079,31 +1159,38 @@ Definition returndatacopy : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let return_data_start_position := + |) + |) in + let _ := M.assign_local (| + "return_data_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -1119,13 +1206,17 @@ Definition returndatacopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_RETURN_DATA_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1135,7 +1226,8 @@ Definition returndatacopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1190,7 +1282,8 @@ Definition returndatacopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.slice (| M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), M.get_name (| globals, "return_data_start_position" |), @@ -1199,7 +1292,8 @@ Definition returndatacopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) |), Constant.None_ - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -1226,7 +1320,8 @@ Definition extcodehash : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1239,7 +1334,8 @@ Definition extcodehash : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1277,7 +1373,8 @@ Definition extcodehash : Value.t -> Value.t -> M := |) in M.pure Constant.None_ )) |) in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1285,7 +1382,8 @@ Definition extcodehash : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1295,18 +1393,21 @@ Definition extcodehash : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let codehash := + let _ := M.assign_local (| + "codehash" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let codehash := + let _ := M.assign_local (| + "codehash" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -1319,7 +1420,8 @@ Definition extcodehash : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -1358,7 +1460,8 @@ Definition self_balance : Value.t -> Value.t -> M := ], make_dict [] |) in - let balance := + let _ := M.assign_local (| + "balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1366,7 +1469,8 @@ Definition self_balance : Value.t -> Value.t -> M := M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/keccak.v b/CoqOfPython/ethereum/shanghai/vm/instructions/keccak.v index ec50b85..1565118 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/keccak.v @@ -17,26 +17,36 @@ Introduction Implementations of the EVM keccak instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_shanghai_vm_imports : - AreImported globals "ethereum.shanghai.vm" [ "Evm" ]. +Axiom ethereum_shanghai_vm_imports_Evm : + IsImported globals "ethereum.shanghai.vm" "Evm". -Axiom ethereum_shanghai_vm_gas_imports : - AreImported globals "ethereum.shanghai.vm.gas" [ "GAS_KECCAK256"; "GAS_KECCAK256_WORD"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_shanghai_vm_gas_imports_GAS_KECCAK256 : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_KECCAK256". +Axiom ethereum_shanghai_vm_gas_imports_GAS_KECCAK256_WORD : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_KECCAK256_WORD". +Axiom ethereum_shanghai_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.shanghai.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_shanghai_vm_gas_imports_charge_gas : + IsImported globals "ethereum.shanghai.vm.gas" "charge_gas". -Axiom ethereum_shanghai_vm_memory_imports : - AreImported globals "ethereum.shanghai.vm.memory" [ "memory_read_bytes" ]. +Axiom ethereum_shanghai_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.shanghai.vm.memory" "memory_read_bytes". -Axiom ethereum_shanghai_vm_stack_imports : - AreImported globals "ethereum.shanghai.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_shanghai_vm_stack_imports_pop : + IsImported globals "ethereum.shanghai.vm.stack" "pop". +Axiom ethereum_shanghai_vm_stack_imports_push : + IsImported globals "ethereum.shanghai.vm.stack" "push". Definition keccak : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -53,23 +63,28 @@ Definition keccak : Value.t -> Value.t -> M := The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -85,13 +100,17 @@ Definition keccak : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let word_gas_cost := + |) + |) in + let _ := M.assign_local (| + "word_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_KECCAK256_WORD" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -101,7 +120,8 @@ Definition keccak : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -124,7 +144,8 @@ Definition keccak : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let data := + let _ := M.assign_local (| + "data" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -133,15 +154,18 @@ Definition keccak : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in - let hash := + |) + |) in + let _ := M.assign_local (| + "hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "data" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/log.v b/CoqOfPython/ethereum/shanghai/vm/instructions/log.v index 6759b95..b7f272a 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/log.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/log.v @@ -17,32 +17,40 @@ Introduction Implementations of the EVM logging instructions. ". -Axiom functools_imports : - AreImported globals "functools" [ "partial" ]. +Axiom functools_imports_partial : + IsImported globals "functools" "partial". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_shanghai_blocks_imports : - AreImported globals "ethereum.shanghai.blocks" [ "Log" ]. +Axiom ethereum_shanghai_blocks_imports_Log : + IsImported globals "ethereum.shanghai.blocks" "Log". -Axiom ethereum_shanghai_vm_imports : - AreImported globals "ethereum.shanghai.vm" [ "Evm" ]. +Axiom ethereum_shanghai_vm_imports_Evm : + IsImported globals "ethereum.shanghai.vm" "Evm". -Axiom ethereum_shanghai_vm_exceptions_imports : - AreImported globals "ethereum.shanghai.vm.exceptions" [ "WriteInStaticContext" ]. +Axiom ethereum_shanghai_vm_exceptions_imports_WriteInStaticContext : + IsImported globals "ethereum.shanghai.vm.exceptions" "WriteInStaticContext". -Axiom ethereum_shanghai_vm_gas_imports : - AreImported globals "ethereum.shanghai.vm.gas" [ "GAS_LOG"; "GAS_LOG_DATA"; "GAS_LOG_TOPIC"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_shanghai_vm_gas_imports_GAS_LOG : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_LOG". +Axiom ethereum_shanghai_vm_gas_imports_GAS_LOG_DATA : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_LOG_DATA". +Axiom ethereum_shanghai_vm_gas_imports_GAS_LOG_TOPIC : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_LOG_TOPIC". +Axiom ethereum_shanghai_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.shanghai.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_shanghai_vm_gas_imports_charge_gas : + IsImported globals "ethereum.shanghai.vm.gas" "charge_gas". -Axiom ethereum_shanghai_vm_memory_imports : - AreImported globals "ethereum.shanghai.vm.memory" [ "memory_read_bytes" ]. +Axiom ethereum_shanghai_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.shanghai.vm.memory" "memory_read_bytes". -Axiom ethereum_shanghai_vm_stack_imports : - AreImported globals "ethereum.shanghai.vm.stack" [ "pop" ]. +Axiom ethereum_shanghai_vm_stack_imports_pop : + IsImported globals "ethereum.shanghai.vm.stack" "pop". Definition log_n : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -61,24 +69,30 @@ Definition log_n : Value.t -> Value.t -> M := The number of topics to be included in the log entry. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let topics := - make_list [] in + |) + |) in + let _ := M.assign_local (| + "topics" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "_" |), @@ -90,7 +104,8 @@ Definition log_n : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let topic := + let _ := M.assign_local (| + "topic" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -101,7 +116,8 @@ Definition log_n : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "topics" |), "append" |), make_list [ @@ -115,7 +131,8 @@ Definition log_n : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let extend_memory := + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -125,7 +142,8 @@ Definition log_n : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -165,12 +183,14 @@ Definition log_n : Value.t -> Value.t -> M := ], make_dict [] |) in - let log_entry := + let _ := M.assign_local (| + "log_entry" , M.call (| M.get_name (| globals, "Log" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "logs" |), BinOp.add (| diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/memory.v b/CoqOfPython/ethereum/shanghai/vm/instructions/memory.v index 1293676..f71e369 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/memory.v @@ -17,20 +17,32 @@ Introduction Implementations of the EVM Memory instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". -Axiom ethereum_shanghai_vm_imports : - AreImported globals "ethereum.shanghai.vm" [ "Evm" ]. +Axiom ethereum_shanghai_vm_imports_Evm : + IsImported globals "ethereum.shanghai.vm" "Evm". -Axiom ethereum_shanghai_vm_gas_imports : - AreImported globals "ethereum.shanghai.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_shanghai_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_BASE". +Axiom ethereum_shanghai_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_shanghai_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.shanghai.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_shanghai_vm_gas_imports_charge_gas : + IsImported globals "ethereum.shanghai.vm.gas" "charge_gas". -Axiom ethereum_shanghai_vm_memory_imports : - AreImported globals "ethereum.shanghai.vm.memory" [ "memory_read_bytes"; "memory_write" ]. +Axiom ethereum_shanghai_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.shanghai.vm.memory" "memory_read_bytes". +Axiom ethereum_shanghai_vm_memory_imports_memory_write : + IsImported globals "ethereum.shanghai.vm.memory" "memory_write". -Axiom ethereum_shanghai_vm_stack_imports : - AreImported globals "ethereum.shanghai.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_shanghai_vm_stack_imports_pop : + IsImported globals "ethereum.shanghai.vm.stack" "pop". +Axiom ethereum_shanghai_vm_stack_imports_push : + IsImported globals "ethereum.shanghai.vm.stack" "push". Definition mstore : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -46,15 +58,18 @@ Definition mstore : Value.t -> Value.t -> M := The current EVM frame. " in - let start_position := + let _ := M.assign_local (| + "start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -65,8 +80,10 @@ Definition mstore : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -88,7 +105,8 @@ Definition mstore : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -138,23 +156,28 @@ Definition mstore8 : Value.t -> Value.t -> M := The current EVM frame. " in - let start_position := + let _ := M.assign_local (| + "start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -170,7 +193,8 @@ Definition mstore8 : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -190,7 +214,8 @@ Definition mstore8 : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let normalized_bytes_value := + let _ := M.assign_local (| + "normalized_bytes_value" , M.call (| M.get_name (| globals, "Bytes" |), make_list [ @@ -202,7 +227,8 @@ Definition mstore8 : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -231,15 +257,18 @@ Definition mload : Value.t -> Value.t -> M := The current EVM frame. " in - let start_position := + let _ := M.assign_local (| + "start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -255,7 +284,8 @@ Definition mload : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -275,7 +305,8 @@ Definition mload : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -296,7 +327,8 @@ Definition mload : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/stack.v b/CoqOfPython/ethereum/shanghai/vm/instructions/stack.v index 522ea88..8c4b767 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/stack.v @@ -17,26 +17,32 @@ Introduction Implementations of the EVM stack related instructions. ". -Axiom functools_imports : - AreImported globals "functools" [ "partial" ]. +Axiom functools_imports_partial : + IsImported globals "functools" "partial". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_shanghai_vm_imports : - AreImported globals "ethereum.shanghai.vm" [ "Evm"; "stack" ]. +Axiom ethereum_shanghai_vm_imports_Evm : + IsImported globals "ethereum.shanghai.vm" "Evm". +Axiom ethereum_shanghai_vm_imports_stack : + IsImported globals "ethereum.shanghai.vm" "stack". -Axiom ethereum_shanghai_vm_exceptions_imports : - AreImported globals "ethereum.shanghai.vm.exceptions" [ "StackUnderflowError" ]. +Axiom ethereum_shanghai_vm_exceptions_imports_StackUnderflowError : + IsImported globals "ethereum.shanghai.vm.exceptions" "StackUnderflowError". -Axiom ethereum_shanghai_vm_gas_imports : - AreImported globals "ethereum.shanghai.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_shanghai_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_BASE". +Axiom ethereum_shanghai_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_shanghai_vm_gas_imports_charge_gas : + IsImported globals "ethereum.shanghai.vm.gas" "charge_gas". -Axiom ethereum_shanghai_vm_memory_imports : - AreImported globals "ethereum.shanghai.vm.memory" [ "buffer_read" ]. +Axiom ethereum_shanghai_vm_memory_imports_buffer_read : + IsImported globals "ethereum.shanghai.vm.memory" "buffer_read". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -120,7 +126,8 @@ Definition push_n : Value.t -> Value.t -> M := |) in M.pure Constant.None_ )) |) in - let data_to_push := + let _ := M.assign_local (| + "data_to_push" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -150,7 +157,8 @@ Definition push_n : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "stack" |), "push" |), make_list [ @@ -211,7 +219,8 @@ Definition dup_n : Value.t -> Value.t -> M := ], make_dict [] |) in - let data_to_duplicate := + let _ := M.assign_local (| + "data_to_duplicate" , M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| @@ -227,7 +236,8 @@ Definition dup_n : Value.t -> Value.t -> M := |), M.get_name (| globals, "item_number" |) |) - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "stack" |), "push" |), make_list [ diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/storage.v b/CoqOfPython/ethereum/shanghai/vm/instructions/storage.v index d5bd6f6..a05890f 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/storage.v @@ -17,26 +17,46 @@ Introduction Implementations of the EVM storage related instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_shanghai_state_imports : - AreImported globals "ethereum.shanghai.state" [ "get_storage"; "get_storage_original"; "set_storage" ]. +Axiom ethereum_shanghai_state_imports_get_storage : + IsImported globals "ethereum.shanghai.state" "get_storage". +Axiom ethereum_shanghai_state_imports_get_storage_original : + IsImported globals "ethereum.shanghai.state" "get_storage_original". +Axiom ethereum_shanghai_state_imports_set_storage : + IsImported globals "ethereum.shanghai.state" "set_storage". -Axiom ethereum_shanghai_vm_imports : - AreImported globals "ethereum.shanghai.vm" [ "Evm" ]. +Axiom ethereum_shanghai_vm_imports_Evm : + IsImported globals "ethereum.shanghai.vm" "Evm". -Axiom ethereum_shanghai_vm_exceptions_imports : - AreImported globals "ethereum.shanghai.vm.exceptions" [ "OutOfGasError"; "WriteInStaticContext" ]. +Axiom ethereum_shanghai_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.shanghai.vm.exceptions" "OutOfGasError". +Axiom ethereum_shanghai_vm_exceptions_imports_WriteInStaticContext : + IsImported globals "ethereum.shanghai.vm.exceptions" "WriteInStaticContext". -Axiom ethereum_shanghai_vm_gas_imports : - AreImported globals "ethereum.shanghai.vm.gas" [ "GAS_CALL_STIPEND"; "GAS_COLD_SLOAD"; "GAS_STORAGE_CLEAR_REFUND"; "GAS_STORAGE_SET"; "GAS_STORAGE_UPDATE"; "GAS_WARM_ACCESS"; "charge_gas" ]. +Axiom ethereum_shanghai_vm_gas_imports_GAS_CALL_STIPEND : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_CALL_STIPEND". +Axiom ethereum_shanghai_vm_gas_imports_GAS_COLD_SLOAD : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_COLD_SLOAD". +Axiom ethereum_shanghai_vm_gas_imports_GAS_STORAGE_CLEAR_REFUND : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_STORAGE_CLEAR_REFUND". +Axiom ethereum_shanghai_vm_gas_imports_GAS_STORAGE_SET : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_STORAGE_SET". +Axiom ethereum_shanghai_vm_gas_imports_GAS_STORAGE_UPDATE : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_STORAGE_UPDATE". +Axiom ethereum_shanghai_vm_gas_imports_GAS_WARM_ACCESS : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_WARM_ACCESS". +Axiom ethereum_shanghai_vm_gas_imports_charge_gas : + IsImported globals "ethereum.shanghai.vm.gas" "charge_gas". -Axiom ethereum_shanghai_vm_stack_imports : - AreImported globals "ethereum.shanghai.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_shanghai_vm_stack_imports_pop : + IsImported globals "ethereum.shanghai.vm.stack" "pop". +Axiom ethereum_shanghai_vm_stack_imports_push : + IsImported globals "ethereum.shanghai.vm.stack" "push". Definition sload : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -51,7 +71,8 @@ Definition sload : Value.t -> Value.t -> M := The current EVM frame. " in - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -62,7 +83,8 @@ Definition sload : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -100,7 +122,8 @@ Definition sload : Value.t -> Value.t -> M := |) in M.pure Constant.None_ )) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "get_storage" |), make_list [ @@ -109,7 +132,8 @@ Definition sload : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -137,7 +161,8 @@ Definition sstore : Value.t -> Value.t -> M := The current EVM frame. " in - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -148,15 +173,18 @@ Definition sstore : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in - let new_value := + |) + |) in + let _ := M.assign_local (| + "new_value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -168,7 +196,8 @@ Definition sstore : Value.t -> Value.t -> M := ], make_dict [] |) in - let original_value := + let _ := M.assign_local (| + "original_value" , M.call (| M.get_name (| globals, "get_storage_original" |), make_list [ @@ -177,8 +206,10 @@ Definition sstore : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in - let current_value := + |) + |) in + let _ := M.assign_local (| + "current_value" , M.call (| M.get_name (| globals, "get_storage" |), make_list [ @@ -187,15 +218,18 @@ Definition sstore : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in - let gas_cost := + |) + |) in + let _ := M.assign_local (| + "gas_cost" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -212,9 +246,11 @@ Definition sstore : Value.t -> Value.t -> M := ], make_dict [] |) in - let gas_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "gas_cost", M.get_name (| globals, "GAS_COLD_SLOAD" |) - M.get_name (| globals, "GAS_COLD_SLOAD" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -246,29 +282,32 @@ Definition sstore : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let gas_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "gas_cost", M.get_name (| globals, "GAS_STORAGE_SET" |) - M.get_name (| globals, "GAS_STORAGE_SET" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let gas_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "gas_cost", BinOp.sub (| M.get_name (| globals, "GAS_STORAGE_UPDATE" |), M.get_name (| globals, "GAS_COLD_SLOAD" |) |) - BinOp.sub (| - M.get_name (| globals, "GAS_STORAGE_UPDATE" |), - M.get_name (| globals, "GAS_COLD_SLOAD" |) - |) in + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let gas_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "gas_cost", M.get_name (| globals, "GAS_WARM_ACCESS" |) - M.get_name (| globals, "GAS_WARM_ACCESS" |) in + |) in M.pure Constant.None_ )) |) in let _ := diff --git a/CoqOfPython/ethereum/shanghai/vm/instructions/system.v b/CoqOfPython/ethereum/shanghai/vm/instructions/system.v index 034932a..4fc7b71 100644 --- a/CoqOfPython/ethereum/shanghai/vm/instructions/system.v +++ b/CoqOfPython/ethereum/shanghai/vm/instructions/system.v @@ -17,38 +17,96 @@ Introduction Implementations of the EVM system related instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_shanghai_fork_types_imports : - AreImported globals "ethereum.shanghai.fork_types" [ "Address" ]. +Axiom ethereum_shanghai_fork_types_imports_Address : + IsImported globals "ethereum.shanghai.fork_types" "Address". -Axiom ethereum_shanghai_state_imports : - AreImported globals "ethereum.shanghai.state" [ "account_exists_and_is_empty"; "account_has_code_or_nonce"; "get_account"; "increment_nonce"; "is_account_alive"; "set_account_balance" ]. +Axiom ethereum_shanghai_state_imports_account_exists_and_is_empty : + IsImported globals "ethereum.shanghai.state" "account_exists_and_is_empty". +Axiom ethereum_shanghai_state_imports_account_has_code_or_nonce : + IsImported globals "ethereum.shanghai.state" "account_has_code_or_nonce". +Axiom ethereum_shanghai_state_imports_get_account : + IsImported globals "ethereum.shanghai.state" "get_account". +Axiom ethereum_shanghai_state_imports_increment_nonce : + IsImported globals "ethereum.shanghai.state" "increment_nonce". +Axiom ethereum_shanghai_state_imports_is_account_alive : + IsImported globals "ethereum.shanghai.state" "is_account_alive". +Axiom ethereum_shanghai_state_imports_set_account_balance : + IsImported globals "ethereum.shanghai.state" "set_account_balance". -Axiom ethereum_shanghai_utils_address_imports : - AreImported globals "ethereum.shanghai.utils.address" [ "compute_contract_address"; "compute_create2_contract_address"; "to_address" ]. +Axiom ethereum_shanghai_utils_address_imports_compute_contract_address : + IsImported globals "ethereum.shanghai.utils.address" "compute_contract_address". +Axiom ethereum_shanghai_utils_address_imports_compute_create2_contract_address : + IsImported globals "ethereum.shanghai.utils.address" "compute_create2_contract_address". +Axiom ethereum_shanghai_utils_address_imports_to_address : + IsImported globals "ethereum.shanghai.utils.address" "to_address". -Axiom ethereum_shanghai_vm_imports : - AreImported globals "ethereum.shanghai.vm" [ "Evm"; "Message"; "incorporate_child_on_error"; "incorporate_child_on_success" ]. +Axiom ethereum_shanghai_vm_imports_Evm : + IsImported globals "ethereum.shanghai.vm" "Evm". +Axiom ethereum_shanghai_vm_imports_Message : + IsImported globals "ethereum.shanghai.vm" "Message". +Axiom ethereum_shanghai_vm_imports_incorporate_child_on_error : + IsImported globals "ethereum.shanghai.vm" "incorporate_child_on_error". +Axiom ethereum_shanghai_vm_imports_incorporate_child_on_success : + IsImported globals "ethereum.shanghai.vm" "incorporate_child_on_success". -Axiom ethereum_shanghai_vm_exceptions_imports : - AreImported globals "ethereum.shanghai.vm.exceptions" [ "OutOfGasError"; "Revert"; "WriteInStaticContext" ]. +Axiom ethereum_shanghai_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.shanghai.vm.exceptions" "OutOfGasError". +Axiom ethereum_shanghai_vm_exceptions_imports_Revert : + IsImported globals "ethereum.shanghai.vm.exceptions" "Revert". +Axiom ethereum_shanghai_vm_exceptions_imports_WriteInStaticContext : + IsImported globals "ethereum.shanghai.vm.exceptions" "WriteInStaticContext". -Axiom ethereum_shanghai_vm_gas_imports : - AreImported globals "ethereum.shanghai.vm.gas" [ "GAS_CALL_VALUE"; "GAS_COLD_ACCOUNT_ACCESS"; "GAS_CREATE"; "GAS_KECCAK256_WORD"; "GAS_NEW_ACCOUNT"; "GAS_SELF_DESTRUCT"; "GAS_SELF_DESTRUCT_NEW_ACCOUNT"; "GAS_WARM_ACCESS"; "GAS_ZERO"; "calculate_gas_extend_memory"; "calculate_message_call_gas"; "charge_gas"; "init_code_cost"; "max_message_call_gas" ]. +Axiom ethereum_shanghai_vm_gas_imports_GAS_CALL_VALUE : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_CALL_VALUE". +Axiom ethereum_shanghai_vm_gas_imports_GAS_COLD_ACCOUNT_ACCESS : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_COLD_ACCOUNT_ACCESS". +Axiom ethereum_shanghai_vm_gas_imports_GAS_CREATE : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_CREATE". +Axiom ethereum_shanghai_vm_gas_imports_GAS_KECCAK256_WORD : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_KECCAK256_WORD". +Axiom ethereum_shanghai_vm_gas_imports_GAS_NEW_ACCOUNT : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_NEW_ACCOUNT". +Axiom ethereum_shanghai_vm_gas_imports_GAS_SELF_DESTRUCT : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_SELF_DESTRUCT". +Axiom ethereum_shanghai_vm_gas_imports_GAS_SELF_DESTRUCT_NEW_ACCOUNT : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_SELF_DESTRUCT_NEW_ACCOUNT". +Axiom ethereum_shanghai_vm_gas_imports_GAS_WARM_ACCESS : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_WARM_ACCESS". +Axiom ethereum_shanghai_vm_gas_imports_GAS_ZERO : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_ZERO". +Axiom ethereum_shanghai_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.shanghai.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_shanghai_vm_gas_imports_calculate_message_call_gas : + IsImported globals "ethereum.shanghai.vm.gas" "calculate_message_call_gas". +Axiom ethereum_shanghai_vm_gas_imports_charge_gas : + IsImported globals "ethereum.shanghai.vm.gas" "charge_gas". +Axiom ethereum_shanghai_vm_gas_imports_init_code_cost : + IsImported globals "ethereum.shanghai.vm.gas" "init_code_cost". +Axiom ethereum_shanghai_vm_gas_imports_max_message_call_gas : + IsImported globals "ethereum.shanghai.vm.gas" "max_message_call_gas". -Axiom ethereum_shanghai_vm_memory_imports : - AreImported globals "ethereum.shanghai.vm.memory" [ "memory_read_bytes"; "memory_write" ]. +Axiom ethereum_shanghai_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.shanghai.vm.memory" "memory_read_bytes". +Axiom ethereum_shanghai_vm_memory_imports_memory_write : + IsImported globals "ethereum.shanghai.vm.memory" "memory_write". -Axiom ethereum_shanghai_vm_stack_imports : - AreImported globals "ethereum.shanghai.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_shanghai_vm_stack_imports_pop : + IsImported globals "ethereum.shanghai.vm.stack" "pop". +Axiom ethereum_shanghai_vm_stack_imports_push : + IsImported globals "ethereum.shanghai.vm.stack" "push". Definition generic_create : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -57,7 +115,8 @@ Definition generic_create : Value.t -> Value.t -> M := Core logic used by the `CREATE*` family of opcodes. " in (* At stmt: unsupported node type: ImportFrom *) - let call_data := + let _ := M.assign_local (| + "call_data" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -66,7 +125,8 @@ Definition generic_create : Value.t -> Value.t -> M := M.get_name (| globals, "memory_size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -94,7 +154,8 @@ Definition generic_create : Value.t -> Value.t -> M := ], make_dict [] |) in - let create_message_gas := + let _ := M.assign_local (| + "create_message_gas" , M.call (| M.get_name (| globals, "max_message_call_gas" |), make_list [ @@ -107,7 +168,8 @@ Definition generic_create : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.assign_op (| BinOp.sub, M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), @@ -125,9 +187,12 @@ Definition generic_create : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "return_data" |), Constant.bytes "" |) in - let sender_address := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in - let sender := + let _ := M.assign_local (| + "sender_address" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + |) in + let _ := M.assign_local (| + "sender" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -135,7 +200,8 @@ Definition generic_create : Value.t -> Value.t -> M := M.get_name (| globals, "sender_address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -254,13 +320,16 @@ Definition generic_create : Value.t -> Value.t -> M := ], make_dict [] |) in - let child_message := + let _ := M.assign_local (| + "child_message" , M.call (| M.get_name (| globals, "Message" |), make_list [], make_dict [] - |) in - let child_evm := + |) + |) in + let _ := M.assign_local (| + "child_evm" , M.call (| M.get_name (| globals, "process_create_message" |), make_list [ @@ -268,7 +337,8 @@ Definition generic_create : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -345,31 +415,38 @@ Definition create : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let endowment := + let _ := M.assign_local (| + "endowment" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_size := + |) + |) in + let _ := M.assign_local (| + "memory_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -379,8 +456,10 @@ Definition create : Value.t -> Value.t -> M := ] ], make_dict [] - |) in - let init_code_gas := + |) + |) in + let _ := M.assign_local (| + "init_code_gas" , M.call (| M.get_name (| globals, "init_code_cost" |), make_list [ @@ -393,7 +472,8 @@ Definition create : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -416,7 +496,8 @@ Definition create : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let contract_address := + let _ := M.assign_local (| + "contract_address" , M.call (| M.get_name (| globals, "compute_contract_address" |), make_list [ @@ -431,7 +512,8 @@ Definition create : Value.t -> Value.t -> M := |), "nonce" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "generic_create" |), make_list [ @@ -465,31 +547,38 @@ Definition create2 : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let endowment := + let _ := M.assign_local (| + "endowment" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_size := + |) + |) in + let _ := M.assign_local (| + "memory_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let salt := + |) + |) in + let _ := M.assign_local (| + "salt" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -500,8 +589,10 @@ Definition create2 : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -511,8 +602,10 @@ Definition create2 : Value.t -> Value.t -> M := ] ], make_dict [] - |) in - let call_data_words := + |) + |) in + let _ := M.assign_local (| + "call_data_words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -528,8 +621,10 @@ Definition create2 : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let init_code_gas := + |) + |) in + let _ := M.assign_local (| + "init_code_gas" , M.call (| M.get_name (| globals, "init_code_cost" |), make_list [ @@ -542,7 +637,8 @@ Definition create2 : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -571,7 +667,8 @@ Definition create2 : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let contract_address := + let _ := M.assign_local (| + "contract_address" , M.call (| M.get_name (| globals, "compute_create2_contract_address" |), make_list [ @@ -588,7 +685,8 @@ Definition create2 : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "generic_create" |), make_list [ @@ -619,23 +717,28 @@ Definition return_ : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let memory_start_position := + let _ := M.assign_local (| + "memory_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_size := + |) + |) in + let _ := M.assign_local (| + "memory_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -645,7 +748,8 @@ Definition return_ : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -734,7 +838,8 @@ Definition generic_call : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let call_data := + let _ := M.assign_local (| + "call_data" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -743,8 +848,10 @@ Definition generic_call : Value.t -> Value.t -> M := M.get_name (| globals, "memory_input_size" |) ], make_dict [] - |) in - let code := + |) + |) in + let _ := M.assign_local (| + "code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -752,14 +859,18 @@ Definition generic_call : Value.t -> Value.t -> M := M.get_name (| globals, "code_address" |) ], make_dict [] - |), "code" |) in - let child_message := + |), "code" |) + |) in + let _ := M.assign_local (| + "child_message" , M.call (| M.get_name (| globals, "Message" |), make_list [], make_dict [] - |) in - let child_evm := + |) + |) in + let _ := M.assign_local (| + "child_evm" , M.call (| M.get_name (| globals, "process_message" |), make_list [ @@ -767,7 +878,8 @@ Definition generic_call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -831,7 +943,8 @@ Definition generic_call : Value.t -> Value.t -> M := |) in M.pure Constant.None_ )) |) in - let actual_output_size := + let _ := M.assign_local (| + "actual_output_size" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -851,7 +964,8 @@ Definition generic_call : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -879,7 +993,8 @@ Definition call : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -892,8 +1007,10 @@ Definition call : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let to := + |) + |) in + let _ := M.assign_local (| + "to" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -906,48 +1023,60 @@ Definition call : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -958,7 +1087,8 @@ Definition call : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -968,8 +1098,10 @@ Definition call : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let access_gas_cost := - M.get_name (| globals, "GAS_WARM_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -980,11 +1112,14 @@ Definition call : Value.t -> Value.t -> M := ], make_dict [] |) in - let access_gas_cost := - M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + |) in M.pure Constant.None_ )) |) in - let create_gas_cost := + let _ := M.assign_local (| + "create_gas_cost" , (* if *) M.if_then_else (| BoolOp.or (| @@ -1015,8 +1150,10 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "GAS_NEW_ACCOUNT" |) - )) |) in - let transfer_gas_cost := + )) |) + |) in + let _ := M.assign_local (| + "transfer_gas_cost" , (* if *) M.if_then_else (| Compare.eq (| @@ -1035,8 +1172,10 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "GAS_CALL_VALUE" |) - )) |) in - let message_call_gas := + )) |) + |) in + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -1059,7 +1198,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1101,7 +1241,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let sender_balance := + let _ := M.assign_local (| + "sender_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1109,7 +1250,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := (* if *) M.if_then_else (| @@ -1183,7 +1325,8 @@ Definition callcode : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -1196,8 +1339,10 @@ Definition callcode : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let code_address := + |) + |) in + let _ := M.assign_local (| + "code_address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1210,50 +1355,64 @@ Definition callcode : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let to := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "to" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1264,7 +1423,8 @@ Definition callcode : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1274,8 +1434,10 @@ Definition callcode : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let access_gas_cost := - M.get_name (| globals, "GAS_WARM_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1286,11 +1448,14 @@ Definition callcode : Value.t -> Value.t -> M := ], make_dict [] |) in - let access_gas_cost := - M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + |) in M.pure Constant.None_ )) |) in - let transfer_gas_cost := + let _ := M.assign_local (| + "transfer_gas_cost" , (* if *) M.if_then_else (| Compare.eq (| @@ -1309,8 +1474,10 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "GAS_CALL_VALUE" |) - )) |) in - let message_call_gas := + )) |) + |) in + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -1330,7 +1497,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1350,7 +1518,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let sender_balance := + let _ := M.assign_local (| + "sender_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1358,7 +1527,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := (* if *) M.if_then_else (| @@ -1432,7 +1602,8 @@ Definition selfdestruct : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let beneficiary := + let _ := M.assign_local (| + "beneficiary" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1445,9 +1616,12 @@ Definition selfdestruct : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let gas_cost := - M.get_name (| globals, "GAS_SELF_DESTRUCT" |) in + |) + |) in + let _ := M.assign_local (| + "gas_cost" , + M.get_name (| globals, "GAS_SELF_DESTRUCT" |) + |) in let _ := (* if *) M.if_then_else (| @@ -1464,9 +1638,11 @@ Definition selfdestruct : Value.t -> Value.t -> M := ], make_dict [] |) in - let gas_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "gas_cost", M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) - M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1500,9 +1676,11 @@ Definition selfdestruct : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let gas_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "gas_cost", M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) - M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1524,9 +1702,12 @@ Definition selfdestruct : Value.t -> Value.t -> M := ], make_dict [] |) in - let originator := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in - let beneficiary_balance := + let _ := M.assign_local (| + "originator" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + |) in + let _ := M.assign_local (| + "beneficiary_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1534,8 +1715,10 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_name (| globals, "beneficiary" |) ], make_dict [] - |), "balance" |) in - let originator_balance := + |), "balance" |) + |) in + let _ := M.assign_local (| + "originator_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1543,7 +1726,8 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_name (| globals, "originator" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -1621,7 +1805,8 @@ Definition delegatecall : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -1634,8 +1819,10 @@ Definition delegatecall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let code_address := + |) + |) in + let _ := M.assign_local (| + "code_address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1648,40 +1835,50 @@ Definition delegatecall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1692,7 +1889,8 @@ Definition delegatecall : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1702,8 +1900,10 @@ Definition delegatecall : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let access_gas_cost := - M.get_name (| globals, "GAS_WARM_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1714,11 +1914,14 @@ Definition delegatecall : Value.t -> Value.t -> M := ], make_dict [] |) in - let access_gas_cost := - M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + |) in M.pure Constant.None_ )) |) in - let message_call_gas := + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -1741,7 +1944,8 @@ Definition delegatecall : Value.t -> Value.t -> M := M.get_name (| globals, "access_gas_cost" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1797,7 +2001,8 @@ Definition staticcall : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -1810,8 +2015,10 @@ Definition staticcall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let to := + |) + |) in + let _ := M.assign_local (| + "to" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1824,40 +2031,50 @@ Definition staticcall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1868,7 +2085,8 @@ Definition staticcall : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1878,8 +2096,10 @@ Definition staticcall : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let access_gas_cost := - M.get_name (| globals, "GAS_WARM_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_WARM_ACCESS" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -1890,11 +2110,14 @@ Definition staticcall : Value.t -> Value.t -> M := ], make_dict [] |) in - let access_gas_cost := - M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) in + let _ := M.assign_local (| + "access_gas_cost" , + M.get_name (| globals, "GAS_COLD_ACCOUNT_ACCESS" |) + |) in M.pure Constant.None_ )) |) in - let message_call_gas := + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -1917,7 +2140,8 @@ Definition staticcall : Value.t -> Value.t -> M := M.get_name (| globals, "access_gas_cost" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1979,23 +2203,28 @@ Definition revert : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -2005,7 +2234,8 @@ Definition revert : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -2022,7 +2252,8 @@ Definition revert : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let output := + let _ := M.assign_local (| + "output" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -2031,7 +2262,8 @@ Definition revert : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.call (| diff --git a/CoqOfPython/ethereum/shanghai/vm/interpreter.v b/CoqOfPython/ethereum/shanghai/vm/interpreter.v index 5d5bb22..f12f04a 100644 --- a/CoqOfPython/ethereum/shanghai/vm/interpreter.v +++ b/CoqOfPython/ethereum/shanghai/vm/interpreter.v @@ -17,50 +17,114 @@ Introduction A straightforward interpreter that executes EVM code. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Iterable"; "Optional"; "Set"; "Tuple"; "Union" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. - -Axiom ethereum_trace_imports : - AreImported globals "ethereum.trace" [ "EvmStop"; "OpEnd"; "OpException"; "OpStart"; "PrecompileEnd"; "PrecompileStart"; "TransactionEnd"; "evm_trace" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_shanghai_blocks_imports : - AreImported globals "ethereum.shanghai.blocks" [ "Log" ]. - -Axiom ethereum_shanghai_fork_types_imports : - AreImported globals "ethereum.shanghai.fork_types" [ "Address" ]. - -Axiom ethereum_shanghai_state_imports : - AreImported globals "ethereum.shanghai.state" [ "account_exists_and_is_empty"; "account_has_code_or_nonce"; "begin_transaction"; "commit_transaction"; "destroy_storage"; "increment_nonce"; "mark_account_created"; "move_ether"; "rollback_transaction"; "set_code"; "touch_account" ]. - -Axiom ethereum_shanghai_vm_imports : - AreImported globals "ethereum.shanghai.vm" [ "Message" ]. - -Axiom ethereum_shanghai_vm_gas_imports : - AreImported globals "ethereum.shanghai.vm.gas" [ "GAS_CODE_DEPOSIT"; "charge_gas" ]. - -Axiom ethereum_shanghai_vm_precompiled_contracts_mapping_imports : - AreImported globals "ethereum.shanghai.vm.precompiled_contracts.mapping" [ "PRE_COMPILED_CONTRACTS" ]. - -Axiom ethereum_shanghai_vm_imports : - AreImported globals "ethereum.shanghai.vm" [ "Environment"; "Evm" ]. - -Axiom ethereum_shanghai_vm_exceptions_imports : - AreImported globals "ethereum.shanghai.vm.exceptions" [ "AddressCollision"; "ExceptionalHalt"; "InvalidContractPrefix"; "InvalidOpcode"; "OutOfGasError"; "Revert"; "StackDepthLimitError" ]. - -Axiom ethereum_shanghai_vm_instructions_imports : - AreImported globals "ethereum.shanghai.vm.instructions" [ "Ops"; "op_implementation" ]. - -Axiom ethereum_shanghai_vm_runtime_imports : - AreImported globals "ethereum.shanghai.vm.runtime" [ "get_valid_jump_destinations" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_Iterable : + IsImported globals "typing" "Iterable". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_trace_imports_EvmStop : + IsImported globals "ethereum.trace" "EvmStop". +Axiom ethereum_trace_imports_OpEnd : + IsImported globals "ethereum.trace" "OpEnd". +Axiom ethereum_trace_imports_OpException : + IsImported globals "ethereum.trace" "OpException". +Axiom ethereum_trace_imports_OpStart : + IsImported globals "ethereum.trace" "OpStart". +Axiom ethereum_trace_imports_PrecompileEnd : + IsImported globals "ethereum.trace" "PrecompileEnd". +Axiom ethereum_trace_imports_PrecompileStart : + IsImported globals "ethereum.trace" "PrecompileStart". +Axiom ethereum_trace_imports_TransactionEnd : + IsImported globals "ethereum.trace" "TransactionEnd". +Axiom ethereum_trace_imports_evm_trace : + IsImported globals "ethereum.trace" "evm_trace". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_shanghai_blocks_imports_Log : + IsImported globals "ethereum.shanghai.blocks" "Log". + +Axiom ethereum_shanghai_fork_types_imports_Address : + IsImported globals "ethereum.shanghai.fork_types" "Address". + +Axiom ethereum_shanghai_state_imports_account_exists_and_is_empty : + IsImported globals "ethereum.shanghai.state" "account_exists_and_is_empty". +Axiom ethereum_shanghai_state_imports_account_has_code_or_nonce : + IsImported globals "ethereum.shanghai.state" "account_has_code_or_nonce". +Axiom ethereum_shanghai_state_imports_begin_transaction : + IsImported globals "ethereum.shanghai.state" "begin_transaction". +Axiom ethereum_shanghai_state_imports_commit_transaction : + IsImported globals "ethereum.shanghai.state" "commit_transaction". +Axiom ethereum_shanghai_state_imports_destroy_storage : + IsImported globals "ethereum.shanghai.state" "destroy_storage". +Axiom ethereum_shanghai_state_imports_increment_nonce : + IsImported globals "ethereum.shanghai.state" "increment_nonce". +Axiom ethereum_shanghai_state_imports_mark_account_created : + IsImported globals "ethereum.shanghai.state" "mark_account_created". +Axiom ethereum_shanghai_state_imports_move_ether : + IsImported globals "ethereum.shanghai.state" "move_ether". +Axiom ethereum_shanghai_state_imports_rollback_transaction : + IsImported globals "ethereum.shanghai.state" "rollback_transaction". +Axiom ethereum_shanghai_state_imports_set_code : + IsImported globals "ethereum.shanghai.state" "set_code". +Axiom ethereum_shanghai_state_imports_touch_account : + IsImported globals "ethereum.shanghai.state" "touch_account". + +Axiom ethereum_shanghai_vm_imports_Message : + IsImported globals "ethereum.shanghai.vm" "Message". + +Axiom ethereum_shanghai_vm_gas_imports_GAS_CODE_DEPOSIT : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_CODE_DEPOSIT". +Axiom ethereum_shanghai_vm_gas_imports_charge_gas : + IsImported globals "ethereum.shanghai.vm.gas" "charge_gas". + +Axiom ethereum_shanghai_vm_precompiled_contracts_mapping_imports_PRE_COMPILED_CONTRACTS : + IsImported globals "ethereum.shanghai.vm.precompiled_contracts.mapping" "PRE_COMPILED_CONTRACTS". + +Axiom ethereum_shanghai_vm_imports_Environment : + IsImported globals "ethereum.shanghai.vm" "Environment". +Axiom ethereum_shanghai_vm_imports_Evm : + IsImported globals "ethereum.shanghai.vm" "Evm". + +Axiom ethereum_shanghai_vm_exceptions_imports_AddressCollision : + IsImported globals "ethereum.shanghai.vm.exceptions" "AddressCollision". +Axiom ethereum_shanghai_vm_exceptions_imports_ExceptionalHalt : + IsImported globals "ethereum.shanghai.vm.exceptions" "ExceptionalHalt". +Axiom ethereum_shanghai_vm_exceptions_imports_InvalidContractPrefix : + IsImported globals "ethereum.shanghai.vm.exceptions" "InvalidContractPrefix". +Axiom ethereum_shanghai_vm_exceptions_imports_InvalidOpcode : + IsImported globals "ethereum.shanghai.vm.exceptions" "InvalidOpcode". +Axiom ethereum_shanghai_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.shanghai.vm.exceptions" "OutOfGasError". +Axiom ethereum_shanghai_vm_exceptions_imports_Revert : + IsImported globals "ethereum.shanghai.vm.exceptions" "Revert". +Axiom ethereum_shanghai_vm_exceptions_imports_StackDepthLimitError : + IsImported globals "ethereum.shanghai.vm.exceptions" "StackDepthLimitError". + +Axiom ethereum_shanghai_vm_instructions_imports_Ops : + IsImported globals "ethereum.shanghai.vm.instructions" "Ops". +Axiom ethereum_shanghai_vm_instructions_imports_op_implementation : + IsImported globals "ethereum.shanghai.vm.instructions" "op_implementation". + +Axiom ethereum_shanghai_vm_runtime_imports_get_valid_jump_destinations : + IsImported globals "ethereum.shanghai.vm.runtime" "get_valid_jump_destinations". Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -121,7 +185,8 @@ Definition process_message_call : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let is_collision := + let _ := M.assign_local (| + "is_collision" , M.call (| M.get_name (| globals, "account_has_code_or_nonce" |), make_list [ @@ -129,7 +194,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "message" |), "current_target" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -181,7 +247,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "process_create_message" |), make_list [ @@ -189,13 +256,15 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "process_message" |), make_list [ @@ -203,7 +272,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -250,46 +320,61 @@ Definition process_message_call : Value.t -> Value.t -> M := (* then *) ltac:(M.monadic ( (* At stmt: unsupported node type: AnnAssign *) - let accounts_to_delete := + let _ := M.assign_local (| + "accounts_to_delete" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let touched_accounts := + |) + |) in + let _ := M.assign_local (| + "touched_accounts" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let refund_counter := + |) + |) in + let _ := M.assign_local (| + "refund_counter" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let logs := - M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in - let accounts_to_delete := - M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in - let touched_accounts := - M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |) in - let refund_counter := + let _ := M.assign_local (| + "logs" , + M.get_field (| M.get_name (| globals, "evm" |), "logs" |) + |) in + let _ := M.assign_local (| + "accounts_to_delete" , + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) + |) in + let _ := M.assign_local (| + "touched_accounts" , + M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |) + |) in + let _ := M.assign_local (| + "refund_counter" , M.call (| M.get_name (| globals, "U256" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in - let tx_end := + let _ := M.assign_local (| + "tx_end" , M.call (| M.get_name (| globals, "TransactionEnd" |), make_list [ @@ -301,7 +386,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "error" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "evm_trace" |), make_list [ @@ -368,7 +454,8 @@ Definition process_create_message : Value.t -> Value.t -> M := ], make_dict [] |) in - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "process_message" |), make_list [ @@ -376,16 +463,20 @@ Definition process_create_message : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), (* then *) ltac:(M.monadic ( - let contract_code := - M.get_field (| M.get_name (| globals, "evm" |), "output" |) in - let contract_code_gas := + let _ := M.assign_local (| + "contract_code" , + M.get_field (| M.get_name (| globals, "evm" |), "output" |) + |) in + let _ := M.assign_local (| + "contract_code_gas" , BinOp.mult (| M.call (| M.get_name (| globals, "len" |), @@ -395,7 +486,8 @@ Definition process_create_message : Value.t -> Value.t -> M := make_dict [] |), M.get_name (| globals, "GAS_CODE_DEPOSIT" |) - |) in + |) + |) in (* At stmt: unsupported node type: Try *) M.pure Constant.None_ (* else *) @@ -497,7 +589,8 @@ Definition process_message : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "execute_code" |), make_list [ @@ -505,7 +598,8 @@ Definition process_message : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -554,22 +648,28 @@ Definition execute_code : Value.t -> Value.t -> M := evm: `ethereum.vm.EVM` Items containing execution specific objects " in - let code := - M.get_field (| M.get_name (| globals, "message" |), "code" |) in - let valid_jump_destinations := + let _ := M.assign_local (| + "code" , + M.get_field (| M.get_name (| globals, "message" |), "code" |) + |) in + let _ := M.assign_local (| + "valid_jump_destinations" , M.call (| M.get_name (| globals, "get_valid_jump_destinations" |), make_list [ M.get_name (| globals, "code" |) ], make_dict [] - |) in - let evm := + |) + |) in + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "Evm" |), make_list [], make_dict [] - |) in + |) + |) in (* At stmt: unsupported node type: Try *) let _ := M.return_ (| M.get_name (| globals, "evm" |) diff --git a/CoqOfPython/ethereum/shanghai/vm/memory.v b/CoqOfPython/ethereum/shanghai/vm/memory.v index e5006c5..6e9a8b2 100644 --- a/CoqOfPython/ethereum/shanghai/vm/memory.v +++ b/CoqOfPython/ethereum/shanghai/vm/memory.v @@ -17,11 +17,15 @@ Introduction EVM memory operations. ". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "right_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_right_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "right_pad_zero_bytes". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". Definition memory_write : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/__init__.v index c3a26d6..4a90702 100644 --- a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/__init__.v +++ b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/__init__.v @@ -18,8 +18,8 @@ Addresses of precompiled contracts and mappings to their implementations. ". -Axiom ethereum_shanghai_utils_hexadecimal_imports : - AreImported globals "ethereum.shanghai.utils.hexadecimal" [ "hex_to_address" ]. +Axiom ethereum_shanghai_utils_hexadecimal_imports_hex_to_address : + IsImported globals "ethereum.shanghai.utils.hexadecimal" "hex_to_address". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS"; Constant.str "MODEXP_ADDRESS"; Constant.str "ALT_BN128_ADD_ADDRESS"; Constant.str "ALT_BN128_MUL_ADDRESS"; Constant.str "ALT_BN128_PAIRING_CHECK_ADDRESS"; Constant.str "BLAKE2F_ADDRESS" ] diff --git a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/alt_bn128.v b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/alt_bn128.v index 598f17f..69c7cc0 100644 --- a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/alt_bn128.v +++ b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/alt_bn128.v @@ -17,26 +17,42 @@ Introduction Implementation of the ALT_BN128 precompiled contracts. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_alt_bn128_imports : - AreImported globals "ethereum.crypto.alt_bn128" [ "ALT_BN128_CURVE_ORDER"; "ALT_BN128_PRIME"; "BNF"; "BNF2"; "BNF12"; "BNP"; "BNP2"; "pairing" ]. +Axiom ethereum_crypto_alt_bn128_imports_ALT_BN128_CURVE_ORDER : + IsImported globals "ethereum.crypto.alt_bn128" "ALT_BN128_CURVE_ORDER". +Axiom ethereum_crypto_alt_bn128_imports_ALT_BN128_PRIME : + IsImported globals "ethereum.crypto.alt_bn128" "ALT_BN128_PRIME". +Axiom ethereum_crypto_alt_bn128_imports_BNF : + IsImported globals "ethereum.crypto.alt_bn128" "BNF". +Axiom ethereum_crypto_alt_bn128_imports_BNF2 : + IsImported globals "ethereum.crypto.alt_bn128" "BNF2". +Axiom ethereum_crypto_alt_bn128_imports_BNF12 : + IsImported globals "ethereum.crypto.alt_bn128" "BNF12". +Axiom ethereum_crypto_alt_bn128_imports_BNP : + IsImported globals "ethereum.crypto.alt_bn128" "BNP". +Axiom ethereum_crypto_alt_bn128_imports_BNP2 : + IsImported globals "ethereum.crypto.alt_bn128" "BNP2". +Axiom ethereum_crypto_alt_bn128_imports_pairing : + IsImported globals "ethereum.crypto.alt_bn128" "pairing". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_shanghai_vm_imports : - AreImported globals "ethereum.shanghai.vm" [ "Evm" ]. +Axiom ethereum_shanghai_vm_imports_Evm : + IsImported globals "ethereum.shanghai.vm" "Evm". -Axiom ethereum_shanghai_vm_gas_imports : - AreImported globals "ethereum.shanghai.vm.gas" [ "charge_gas" ]. +Axiom ethereum_shanghai_vm_gas_imports_charge_gas : + IsImported globals "ethereum.shanghai.vm.gas" "charge_gas". -Axiom ethereum_shanghai_vm_memory_imports : - AreImported globals "ethereum.shanghai.vm.memory" [ "buffer_read" ]. +Axiom ethereum_shanghai_vm_memory_imports_buffer_read : + IsImported globals "ethereum.shanghai.vm.memory" "buffer_read". -Axiom ethereum_shanghai_vm_exceptions_imports : - AreImported globals "ethereum.shanghai.vm.exceptions" [ "OutOfGasError" ]. +Axiom ethereum_shanghai_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.shanghai.vm.exceptions" "OutOfGasError". Definition alt_bn128_add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -49,8 +65,10 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -65,7 +83,8 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := ], make_dict [] |) in - let x0_bytes := + let _ := M.assign_local (| + "x0_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -86,16 +105,20 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let x0_value := + |) + |) in + let _ := M.assign_local (| + "x0_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "x0_bytes" |) ], make_dict [] - |) in - let y0_bytes := + |) + |) in + let _ := M.assign_local (| + "y0_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -116,16 +139,20 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y0_value := + |) + |) in + let _ := M.assign_local (| + "y0_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "y0_bytes" |) ], make_dict [] - |) in - let x1_bytes := + |) + |) in + let _ := M.assign_local (| + "x1_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -146,16 +173,20 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let x1_value := + |) + |) in + let _ := M.assign_local (| + "x1_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "x1_bytes" |) ], make_dict [] - |) in - let y1_bytes := + |) + |) in + let _ := M.assign_local (| + "y1_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -176,15 +207,18 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y1_value := + |) + |) in + let _ := M.assign_local (| + "y1_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "y1_bytes" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "i" |), @@ -212,11 +246,13 @@ Definition alt_bn128_add : Value.t -> Value.t -> M := )) |) in (* At stmt: unsupported node type: Try *) - let p := + let _ := M.assign_local (| + "p" , BinOp.add (| M.get_name (| globals, "p0" |), M.get_name (| globals, "p1" |) - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), BinOp.add (| @@ -245,8 +281,10 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -261,7 +299,8 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := ], make_dict [] |) in - let x0_bytes := + let _ := M.assign_local (| + "x0_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -282,16 +321,20 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let x0_value := + |) + |) in + let _ := M.assign_local (| + "x0_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "x0_bytes" |) ], make_dict [] - |) in - let y0_bytes := + |) + |) in + let _ := M.assign_local (| + "y0_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -312,16 +355,20 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y0_value := + |) + |) in + let _ := M.assign_local (| + "y0_value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "y0_bytes" |) ], make_dict [] - |) in - let n := + |) + |) in + let _ := M.assign_local (| + "n" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -348,7 +395,8 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "i" |), @@ -376,14 +424,16 @@ Definition alt_bn128_mul : Value.t -> Value.t -> M := )) |) in (* At stmt: unsupported node type: Try *) - let p := + let _ := M.assign_local (| + "p" , M.call (| M.get_field (| M.get_name (| globals, "p0" |), "mul_by" |), make_list [ M.get_name (| globals, "n" |) ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), BinOp.add (| @@ -412,8 +462,10 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -467,14 +519,16 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "BNF12" |), "from_int" |), make_list [ Constant.int 1 ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "i" |), @@ -495,8 +549,10 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let values := - make_list [] in + let _ := M.assign_local (| + "values" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "j" |), @@ -508,7 +564,8 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -541,7 +598,8 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -644,7 +702,8 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , BinOp.mult (| M.get_name (| globals, "result" |), M.call (| @@ -655,7 +714,8 @@ Definition alt_bn128_pairing_check : Value.t -> Value.t -> M := ], make_dict [] |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/blake2f.v b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/blake2f.v index 142ed4a..1bef272 100644 --- a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/blake2f.v +++ b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/blake2f.v @@ -17,20 +17,22 @@ Introduction Implementation of the `Blake2` precompiled contract. ". -Axiom ethereum_crypto_blake2_imports : - AreImported globals "ethereum.crypto.blake2" [ "Blake2b" ]. +Axiom ethereum_crypto_blake2_imports_Blake2b : + IsImported globals "ethereum.crypto.blake2" "Blake2b". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_shanghai_vm_imports : - AreImported globals "ethereum.shanghai.vm" [ "Evm" ]. +Axiom ethereum_shanghai_vm_imports_Evm : + IsImported globals "ethereum.shanghai.vm" "Evm". -Axiom ethereum_shanghai_vm_gas_imports : - AreImported globals "ethereum.shanghai.vm.gas" [ "GAS_BLAKE2_PER_ROUND"; "charge_gas" ]. +Axiom ethereum_shanghai_vm_gas_imports_GAS_BLAKE2_PER_ROUND : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_BLAKE2_PER_ROUND". +Axiom ethereum_shanghai_vm_gas_imports_charge_gas : + IsImported globals "ethereum.shanghai.vm.gas" "charge_gas". -Axiom ethereum_shanghai_vm_exceptions_imports : - AreImported globals "ethereum.shanghai.vm.exceptions" [ "InvalidParameter" ]. +Axiom ethereum_shanghai_vm_exceptions_imports_InvalidParameter : + IsImported globals "ethereum.shanghai.vm.exceptions" "InvalidParameter". Definition blake2f : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -43,8 +45,10 @@ Definition blake2f : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -62,12 +66,14 @@ Definition blake2f : Value.t -> Value.t -> M := ], make_dict [] |) in - let blake2b := + let _ := M.assign_local (| + "blake2b" , M.call (| M.get_name (| globals, "Blake2b" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "rounds" |); M.get_name (| globals, "h" |); M.get_name (| globals, "m" |); M.get_name (| globals, "t_0" |); M.get_name (| globals, "t_1" |); M.get_name (| globals, "f" |) ], M.call (| diff --git a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/ecrecover.v index 08460e2..ac4b74e 100644 --- a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/ecrecover.v @@ -17,26 +17,32 @@ Introduction Implementation of the ECRECOVER precompiled contract. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_crypto_elliptic_curve_imports : - AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. +Axiom ethereum_crypto_elliptic_curve_imports_SECP256K1N : + IsImported globals "ethereum.crypto.elliptic_curve" "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_imports_secp256k1_recover : + IsImported globals "ethereum.crypto.elliptic_curve" "secp256k1_recover". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_left_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "left_pad_zero_bytes". -Axiom ethereum_shanghai_vm_imports : - AreImported globals "ethereum.shanghai.vm" [ "Evm" ]. +Axiom ethereum_shanghai_vm_imports_Evm : + IsImported globals "ethereum.shanghai.vm" "Evm". -Axiom ethereum_shanghai_vm_gas_imports : - AreImported globals "ethereum.shanghai.vm.gas" [ "GAS_ECRECOVER"; "charge_gas" ]. +Axiom ethereum_shanghai_vm_gas_imports_GAS_ECRECOVER : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_ECRECOVER". +Axiom ethereum_shanghai_vm_gas_imports_charge_gas : + IsImported globals "ethereum.shanghai.vm.gas" "charge_gas". -Axiom ethereum_shanghai_vm_memory_imports : - AreImported globals "ethereum.shanghai.vm.memory" [ "buffer_read" ]. +Axiom ethereum_shanghai_vm_memory_imports_buffer_read : + IsImported globals "ethereum.shanghai.vm.memory" "buffer_read". Definition ecrecover : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -50,8 +56,10 @@ Definition ecrecover : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -60,7 +68,8 @@ Definition ecrecover : Value.t -> Value.t -> M := ], make_dict [] |) in - let message_hash_bytes := + let _ := M.assign_local (| + "message_hash_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -81,16 +90,20 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let message_hash := + |) + |) in + let _ := M.assign_local (| + "message_hash" , M.call (| M.get_name (| globals, "Hash32" |), make_list [ M.get_name (| globals, "message_hash_bytes" |) ], make_dict [] - |) in - let v := + |) + |) in + let _ := M.assign_local (| + "v" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -117,8 +130,10 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let r := + |) + |) in + let _ := M.assign_local (| + "r" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -145,8 +160,10 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let s := + |) + |) in + let _ := M.assign_local (| + "s" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -173,7 +190,8 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -250,7 +268,8 @@ Definition ecrecover : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: Try *) - let address := + let _ := M.assign_local (| + "address" , M.slice (| M.call (| M.get_name (| globals, "keccak256" |), @@ -262,8 +281,10 @@ Definition ecrecover : Value.t -> Value.t -> M := Constant.int 12, Constant.int 32, Constant.None_ - |) in - let padded_address := + |) + |) in + let _ := M.assign_local (| + "padded_address" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -271,7 +292,8 @@ Definition ecrecover : Value.t -> Value.t -> M := Constant.int 32 ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.get_name (| globals, "padded_address" |) diff --git a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/identity.v index d912b9e..554096f 100644 --- a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/identity.v +++ b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/identity.v @@ -17,17 +17,21 @@ Introduction Implementation of the `IDENTITY` precompiled contract. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_shanghai_vm_imports : - AreImported globals "ethereum.shanghai.vm" [ "Evm" ]. +Axiom ethereum_shanghai_vm_imports_Evm : + IsImported globals "ethereum.shanghai.vm" "Evm". -Axiom ethereum_shanghai_vm_gas_imports : - AreImported globals "ethereum.shanghai.vm.gas" [ "GAS_IDENTITY"; "GAS_IDENTITY_WORD"; "charge_gas" ]. +Axiom ethereum_shanghai_vm_gas_imports_GAS_IDENTITY : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_IDENTITY". +Axiom ethereum_shanghai_vm_gas_imports_GAS_IDENTITY_WORD : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_IDENTITY_WORD". +Axiom ethereum_shanghai_vm_gas_imports_charge_gas : + IsImported globals "ethereum.shanghai.vm.gas" "charge_gas". Definition identity : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -40,9 +44,12 @@ Definition identity : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let word_count := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "word_count" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -64,7 +71,8 @@ Definition identity : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ diff --git a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/mapping.v index d240a83..9fd8e82 100644 --- a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/mapping.v +++ b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/mapping.v @@ -17,34 +17,56 @@ Introduction Mapping of precompiled contracts their implementations. ". -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict" ]. - -Axiom ethereum_shanghai_fork_types_imports : - AreImported globals "ethereum.shanghai.fork_types" [ "Address" ]. - -Axiom ethereum_shanghai_vm_precompiled_contracts_imports : - AreImported globals "ethereum.shanghai.vm.precompiled_contracts" [ "ALT_BN128_ADD_ADDRESS"; "ALT_BN128_MUL_ADDRESS"; "ALT_BN128_PAIRING_CHECK_ADDRESS"; "BLAKE2F_ADDRESS"; "ECRECOVER_ADDRESS"; "IDENTITY_ADDRESS"; "MODEXP_ADDRESS"; "RIPEMD160_ADDRESS"; "SHA256_ADDRESS" ]. - -Axiom ethereum_shanghai_vm_precompiled_contracts_alt_bn128_imports : - AreImported globals "ethereum.shanghai.vm.precompiled_contracts.alt_bn128" [ "alt_bn128_add"; "alt_bn128_mul"; "alt_bn128_pairing_check" ]. - -Axiom ethereum_shanghai_vm_precompiled_contracts_blake2f_imports : - AreImported globals "ethereum.shanghai.vm.precompiled_contracts.blake2f" [ "blake2f" ]. - -Axiom ethereum_shanghai_vm_precompiled_contracts_ecrecover_imports : - AreImported globals "ethereum.shanghai.vm.precompiled_contracts.ecrecover" [ "ecrecover" ]. - -Axiom ethereum_shanghai_vm_precompiled_contracts_identity_imports : - AreImported globals "ethereum.shanghai.vm.precompiled_contracts.identity" [ "identity" ]. - -Axiom ethereum_shanghai_vm_precompiled_contracts_modexp_imports : - AreImported globals "ethereum.shanghai.vm.precompiled_contracts.modexp" [ "modexp" ]. - -Axiom ethereum_shanghai_vm_precompiled_contracts_ripemd160_imports : - AreImported globals "ethereum.shanghai.vm.precompiled_contracts.ripemd160" [ "ripemd160" ]. - -Axiom ethereum_shanghai_vm_precompiled_contracts_sha256_imports : - AreImported globals "ethereum.shanghai.vm.precompiled_contracts.sha256" [ "sha256" ]. +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". + +Axiom ethereum_shanghai_fork_types_imports_Address : + IsImported globals "ethereum.shanghai.fork_types" "Address". + +Axiom ethereum_shanghai_vm_precompiled_contracts_imports_ALT_BN128_ADD_ADDRESS : + IsImported globals "ethereum.shanghai.vm.precompiled_contracts" "ALT_BN128_ADD_ADDRESS". +Axiom ethereum_shanghai_vm_precompiled_contracts_imports_ALT_BN128_MUL_ADDRESS : + IsImported globals "ethereum.shanghai.vm.precompiled_contracts" "ALT_BN128_MUL_ADDRESS". +Axiom ethereum_shanghai_vm_precompiled_contracts_imports_ALT_BN128_PAIRING_CHECK_ADDRESS : + IsImported globals "ethereum.shanghai.vm.precompiled_contracts" "ALT_BN128_PAIRING_CHECK_ADDRESS". +Axiom ethereum_shanghai_vm_precompiled_contracts_imports_BLAKE2F_ADDRESS : + IsImported globals "ethereum.shanghai.vm.precompiled_contracts" "BLAKE2F_ADDRESS". +Axiom ethereum_shanghai_vm_precompiled_contracts_imports_ECRECOVER_ADDRESS : + IsImported globals "ethereum.shanghai.vm.precompiled_contracts" "ECRECOVER_ADDRESS". +Axiom ethereum_shanghai_vm_precompiled_contracts_imports_IDENTITY_ADDRESS : + IsImported globals "ethereum.shanghai.vm.precompiled_contracts" "IDENTITY_ADDRESS". +Axiom ethereum_shanghai_vm_precompiled_contracts_imports_MODEXP_ADDRESS : + IsImported globals "ethereum.shanghai.vm.precompiled_contracts" "MODEXP_ADDRESS". +Axiom ethereum_shanghai_vm_precompiled_contracts_imports_RIPEMD160_ADDRESS : + IsImported globals "ethereum.shanghai.vm.precompiled_contracts" "RIPEMD160_ADDRESS". +Axiom ethereum_shanghai_vm_precompiled_contracts_imports_SHA256_ADDRESS : + IsImported globals "ethereum.shanghai.vm.precompiled_contracts" "SHA256_ADDRESS". + +Axiom ethereum_shanghai_vm_precompiled_contracts_alt_bn128_imports_alt_bn128_add : + IsImported globals "ethereum.shanghai.vm.precompiled_contracts.alt_bn128" "alt_bn128_add". +Axiom ethereum_shanghai_vm_precompiled_contracts_alt_bn128_imports_alt_bn128_mul : + IsImported globals "ethereum.shanghai.vm.precompiled_contracts.alt_bn128" "alt_bn128_mul". +Axiom ethereum_shanghai_vm_precompiled_contracts_alt_bn128_imports_alt_bn128_pairing_check : + IsImported globals "ethereum.shanghai.vm.precompiled_contracts.alt_bn128" "alt_bn128_pairing_check". + +Axiom ethereum_shanghai_vm_precompiled_contracts_blake2f_imports_blake2f : + IsImported globals "ethereum.shanghai.vm.precompiled_contracts.blake2f" "blake2f". + +Axiom ethereum_shanghai_vm_precompiled_contracts_ecrecover_imports_ecrecover : + IsImported globals "ethereum.shanghai.vm.precompiled_contracts.ecrecover" "ecrecover". + +Axiom ethereum_shanghai_vm_precompiled_contracts_identity_imports_identity : + IsImported globals "ethereum.shanghai.vm.precompiled_contracts.identity" "identity". + +Axiom ethereum_shanghai_vm_precompiled_contracts_modexp_imports_modexp : + IsImported globals "ethereum.shanghai.vm.precompiled_contracts.modexp" "modexp". + +Axiom ethereum_shanghai_vm_precompiled_contracts_ripemd160_imports_ripemd160 : + IsImported globals "ethereum.shanghai.vm.precompiled_contracts.ripemd160" "ripemd160". + +Axiom ethereum_shanghai_vm_precompiled_contracts_sha256_imports_sha256 : + IsImported globals "ethereum.shanghai.vm.precompiled_contracts.sha256" "sha256". (* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/modexp.v b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/modexp.v index ce3a676..9c94a82 100644 --- a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/modexp.v +++ b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/modexp.v @@ -17,17 +17,21 @@ Introduction Implementation of the `MODEXP` precompiled contract. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_shanghai_vm_imports : - AreImported globals "ethereum.shanghai.vm" [ "Evm" ]. +Axiom ethereum_shanghai_vm_imports_Evm : + IsImported globals "ethereum.shanghai.vm" "Evm". -Axiom ethereum_shanghai_vm_gas_imports : - AreImported globals "ethereum.shanghai.vm.gas" [ "charge_gas" ]. +Axiom ethereum_shanghai_vm_gas_imports_charge_gas : + IsImported globals "ethereum.shanghai.vm.gas" "charge_gas". -Axiom ethereum_shanghai_vm_memory_imports : - AreImported globals "ethereum.shanghai.vm.memory" [ "buffer_read" ]. +Axiom ethereum_shanghai_vm_memory_imports_buffer_read : + IsImported globals "ethereum.shanghai.vm.memory" "buffer_read". Definition GQUADDIVISOR : Value.t := M.run ltac:(M.monadic ( Constant.int 3 @@ -40,9 +44,12 @@ Definition modexp : Value.t -> Value.t -> M := Calculates `(base**exp) % modulus` for arbitrary sized `base`, `exp` and. `modulus`. The return value is the same length as the modulus. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let base_length := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "base_length" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -69,8 +76,10 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exp_length := + |) + |) in + let _ := M.assign_local (| + "exp_length" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -97,8 +106,10 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let modulus_length := + |) + |) in + let _ := M.assign_local (| + "modulus_length" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -125,8 +136,10 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exp_start := + |) + |) in + let _ := M.assign_local (| + "exp_start" , BinOp.add (| M.call (| M.get_name (| globals, "U256" |), @@ -136,8 +149,10 @@ Definition modexp : Value.t -> Value.t -> M := make_dict [] |), M.get_name (| globals, "base_length" |) - |) in - let exp_head := + |) + |) in + let _ := M.assign_local (| + "exp_head" , M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ @@ -165,7 +180,8 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -216,7 +232,8 @@ Definition modexp : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let base := + let _ := M.assign_local (| + "base" , M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ @@ -237,8 +254,10 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exp := + |) + |) in + let _ := M.assign_local (| + "exp" , M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ @@ -253,13 +272,17 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let modulus_start := + |) + |) in + let _ := M.assign_local (| + "modulus_start" , BinOp.add (| M.get_name (| globals, "exp_start" |), M.get_name (| globals, "exp_length" |) - |) in - let modulus := + |) + |) in + let _ := M.assign_local (| + "modulus" , M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), make_list [ @@ -274,7 +297,8 @@ Definition modexp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -350,7 +374,8 @@ Definition complexity : Value.t -> Value.t -> M := complexity : `Uint` Complexity of performing the operation. " in - let max_length := + let _ := M.assign_local (| + "max_length" , M.call (| M.get_name (| globals, "max" |), make_list [ @@ -370,15 +395,18 @@ Definition complexity : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| BinOp.add (| M.get_name (| globals, "max_length" |), Constant.int 7 |), Constant.int 8 - |) in + |) + |) in let _ := M.return_ (| BinOp.pow (| M.get_name (| globals, "words" |), @@ -427,14 +455,16 @@ Definition iterations : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let count := + let _ := M.assign_local (| + "count" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -447,7 +477,8 @@ Definition iterations : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let bit_length := + let _ := M.assign_local (| + "bit_length" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -458,7 +489,8 @@ Definition iterations : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -468,20 +500,25 @@ Definition iterations : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let bit_length := BinOp.sub + let _ := M.assign_op_local (| + BinOp.sub, + "bit_length", Constant.int 1 - Constant.int 1 in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let count := - M.get_name (| globals, "bit_length" |) in + let _ := M.assign_local (| + "count" , + M.get_name (| globals, "bit_length" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let length_part := + let _ := M.assign_local (| + "length_part" , BinOp.mult (| Constant.int 8, BinOp.sub (| @@ -494,8 +531,10 @@ Definition iterations : Value.t -> Value.t -> M := |), Constant.int 32 |) - |) in - let bits_part := + |) + |) in + let _ := M.assign_local (| + "bits_part" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -506,7 +545,8 @@ Definition iterations : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -516,19 +556,23 @@ Definition iterations : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let bits_part := BinOp.sub + let _ := M.assign_op_local (| + BinOp.sub, + "bits_part", Constant.int 1 - Constant.int 1 in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let count := + let _ := M.assign_local (| + "count" , BinOp.add (| M.get_name (| globals, "length_part" |), M.get_name (| globals, "bits_part" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -579,7 +623,8 @@ Definition gas_cost : Value.t -> Value.t -> M := gas_cost : `Uint` Gas required for performing the operation. " in - let multiplication_complexity := + let _ := M.assign_local (| + "multiplication_complexity" , M.call (| M.get_name (| globals, "complexity" |), make_list [ @@ -587,8 +632,10 @@ Definition gas_cost : Value.t -> Value.t -> M := M.get_name (| globals, "modulus_length" |) ], make_dict [] - |) in - let iteration_count := + |) + |) in + let _ := M.assign_local (| + "iteration_count" , M.call (| M.get_name (| globals, "iterations" |), make_list [ @@ -596,15 +643,20 @@ Definition gas_cost : Value.t -> Value.t -> M := M.get_name (| globals, "exponent_head" |) ], make_dict [] - |) in - let cost := + |) + |) in + let _ := M.assign_local (| + "cost" , BinOp.mult (| M.get_name (| globals, "multiplication_complexity" |), M.get_name (| globals, "iteration_count" |) - |) in - let cost := BinOp.floor_div + |) + |) in + let _ := M.assign_op_local (| + BinOp.floor_div, + "cost", M.get_name (| globals, "GQUADDIVISOR" |) - M.get_name (| globals, "GQUADDIVISOR" |) in + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "max" |), diff --git a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/ripemd160.v index 81d2ec2..9ca951c 100644 --- a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/ripemd160.v +++ b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/ripemd160.v @@ -19,20 +19,24 @@ Implementation of the `RIPEMD160` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_left_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "left_pad_zero_bytes". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_shanghai_vm_imports : - AreImported globals "ethereum.shanghai.vm" [ "Evm" ]. +Axiom ethereum_shanghai_vm_imports_Evm : + IsImported globals "ethereum.shanghai.vm" "Evm". -Axiom ethereum_shanghai_vm_gas_imports : - AreImported globals "ethereum.shanghai.vm.gas" [ "GAS_RIPEMD160"; "GAS_RIPEMD160_WORD"; "charge_gas" ]. +Axiom ethereum_shanghai_vm_gas_imports_GAS_RIPEMD160 : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_RIPEMD160". +Axiom ethereum_shanghai_vm_gas_imports_GAS_RIPEMD160_WORD : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_RIPEMD160_WORD". +Axiom ethereum_shanghai_vm_gas_imports_charge_gas : + IsImported globals "ethereum.shanghai.vm.gas" "charge_gas". Definition ripemd160 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,9 +49,12 @@ Definition ripemd160 : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let word_count := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "word_count" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -69,7 +76,8 @@ Definition ripemd160 : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -84,7 +92,8 @@ Definition ripemd160 : Value.t -> Value.t -> M := ], make_dict [] |) in - let hash_bytes := + let _ := M.assign_local (| + "hash_bytes" , M.call (| M.get_field (| M.call (| M.get_field (| M.get_name (| globals, "hashlib" |), "new" |), @@ -96,8 +105,10 @@ Definition ripemd160 : Value.t -> Value.t -> M := |), "digest" |), make_list [], make_dict [] - |) in - let padded_hash := + |) + |) in + let _ := M.assign_local (| + "padded_hash" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -105,7 +116,8 @@ Definition ripemd160 : Value.t -> Value.t -> M := Constant.int 32 ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.get_name (| globals, "padded_hash" |) diff --git a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/sha256.v index 1562fc4..d8d222a 100644 --- a/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/sha256.v +++ b/CoqOfPython/ethereum/shanghai/vm/precompiled_contracts/sha256.v @@ -19,17 +19,21 @@ Implementation of the `SHA256` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_shanghai_vm_imports : - AreImported globals "ethereum.shanghai.vm" [ "Evm" ]. +Axiom ethereum_shanghai_vm_imports_Evm : + IsImported globals "ethereum.shanghai.vm" "Evm". -Axiom ethereum_shanghai_vm_gas_imports : - AreImported globals "ethereum.shanghai.vm.gas" [ "GAS_SHA256"; "GAS_SHA256_WORD"; "charge_gas" ]. +Axiom ethereum_shanghai_vm_gas_imports_GAS_SHA256 : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_SHA256". +Axiom ethereum_shanghai_vm_gas_imports_GAS_SHA256_WORD : + IsImported globals "ethereum.shanghai.vm.gas" "GAS_SHA256_WORD". +Axiom ethereum_shanghai_vm_gas_imports_charge_gas : + IsImported globals "ethereum.shanghai.vm.gas" "charge_gas". Definition sha256 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,9 +46,12 @@ Definition sha256 : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let word_count := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "word_count" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -66,7 +73,8 @@ Definition sha256 : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ diff --git a/CoqOfPython/ethereum/shanghai/vm/runtime.v b/CoqOfPython/ethereum/shanghai/vm/runtime.v index 93e75b8..44bf9bf 100644 --- a/CoqOfPython/ethereum/shanghai/vm/runtime.v +++ b/CoqOfPython/ethereum/shanghai/vm/runtime.v @@ -17,14 +17,14 @@ Introduction Runtime related operations used while executing EVM code. ". -Axiom typing_imports : - AreImported globals "typing" [ "Set" ]. +Axiom typing_imports_Set : + IsImported globals "typing" "Set". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_shanghai_vm_instructions_imports : - AreImported globals "ethereum.shanghai.vm.instructions" [ "Ops" ]. +Axiom ethereum_shanghai_vm_instructions_imports_Ops : + IsImported globals "ethereum.shanghai.vm.instructions" "Ops". Definition get_valid_jump_destinations : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -50,20 +50,24 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := valid_jump_destinations: `Set[Uint]` The set of valid jump destinations in the code. " in - let valid_jump_destinations := + let _ := M.assign_local (| + "valid_jump_destinations" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let pc := + |) + |) in + let _ := M.assign_local (| + "pc" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in let _ := M.while (| Compare.lt (| @@ -114,17 +118,21 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let push_data_size := + let _ := M.assign_local (| + "push_data_size" , BinOp.add (| BinOp.sub (| M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) |), Constant.int 1 - |) in - let pc := BinOp.add + |) + |) in + let _ := M.assign_op_local (| + BinOp.add, + "pc", M.get_name (| globals, "push_data_size" |) - M.get_name (| globals, "push_data_size" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -132,9 +140,11 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - let pc := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "pc", Constant.int 1 - Constant.int 1 in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/shanghai/vm/stack.v b/CoqOfPython/ethereum/shanghai/vm/stack.v index 4ff4d79..cbab960 100644 --- a/CoqOfPython/ethereum/shanghai/vm/stack.v +++ b/CoqOfPython/ethereum/shanghai/vm/stack.v @@ -17,14 +17,16 @@ Introduction Implementation of the stack operators for the EVM. ". -Axiom typing_imports : - AreImported globals "typing" [ "List" ]. +Axiom typing_imports_List : + IsImported globals "typing" "List". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_shanghai_vm_exceptions_imports : - AreImported globals "ethereum.shanghai.vm.exceptions" [ "StackOverflowError"; "StackUnderflowError" ]. +Axiom ethereum_shanghai_vm_exceptions_imports_StackOverflowError : + IsImported globals "ethereum.shanghai.vm.exceptions" "StackOverflowError". +Axiom ethereum_shanghai_vm_exceptions_imports_StackUnderflowError : + IsImported globals "ethereum.shanghai.vm.exceptions" "StackUnderflowError". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/spurious_dragon/__init__.v b/CoqOfPython/ethereum/spurious_dragon/__init__.v index 46bdc54..1f1b6ac 100644 --- a/CoqOfPython/ethereum/spurious_dragon/__init__.v +++ b/CoqOfPython/ethereum/spurious_dragon/__init__.v @@ -11,8 +11,8 @@ chains, limits the maximum size of contract code, and enables the removal of empty accounts. ". -Axiom ethereum_fork_criteria_imports : - AreImported globals "ethereum.fork_criteria" [ "ByBlockNumber" ]. +Axiom ethereum_fork_criteria_imports_ByBlockNumber : + IsImported globals "ethereum.fork_criteria" "ByBlockNumber". Definition FORK_CRITERIA : Value.t := M.run ltac:(M.monadic ( M.call (| diff --git a/CoqOfPython/ethereum/spurious_dragon/blocks.v b/CoqOfPython/ethereum/spurious_dragon/blocks.v index fe188c1..1057a2e 100644 --- a/CoqOfPython/ethereum/spurious_dragon/blocks.v +++ b/CoqOfPython/ethereum/spurious_dragon/blocks.v @@ -14,23 +14,37 @@ history of all state transitions that have happened since the genesis of the chain. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Tuple" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes8"; "Bytes32"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. - -Axiom ethereum_spurious_dragon_fork_types_imports : - AreImported globals "ethereum.spurious_dragon.fork_types" [ "Address"; "Bloom"; "Root" ]. - -Axiom ethereum_spurious_dragon_transactions_imports : - AreImported globals "ethereum.spurious_dragon.transactions" [ "Transaction" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes8 : + IsImported globals "ethereum.base_types" "Bytes8". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". + +Axiom ethereum_spurious_dragon_fork_types_imports_Address : + IsImported globals "ethereum.spurious_dragon.fork_types" "Address". +Axiom ethereum_spurious_dragon_fork_types_imports_Bloom : + IsImported globals "ethereum.spurious_dragon.fork_types" "Bloom". +Axiom ethereum_spurious_dragon_fork_types_imports_Root : + IsImported globals "ethereum.spurious_dragon.fork_types" "Root". + +Axiom ethereum_spurious_dragon_transactions_imports_Transaction : + IsImported globals "ethereum.spurious_dragon.transactions" "Transaction". Definition Header : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/spurious_dragon/bloom.v b/CoqOfPython/ethereum/spurious_dragon/bloom.v index 6a34d82..ba09205 100644 --- a/CoqOfPython/ethereum/spurious_dragon/bloom.v +++ b/CoqOfPython/ethereum/spurious_dragon/bloom.v @@ -21,20 +21,20 @@ for efficient searching of logs by address and/or topic, by rapidly eliminating blocks and receipts from their search. ". -Axiom typing_imports : - AreImported globals "typing" [ "Tuple" ]. +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_spurious_dragon_blocks_imports : - AreImported globals "ethereum.spurious_dragon.blocks" [ "Log" ]. +Axiom ethereum_spurious_dragon_blocks_imports_Log : + IsImported globals "ethereum.spurious_dragon.blocks" "Log". -Axiom ethereum_spurious_dragon_fork_types_imports : - AreImported globals "ethereum.spurious_dragon.fork_types" [ "Bloom" ]. +Axiom ethereum_spurious_dragon_fork_types_imports_Bloom : + IsImported globals "ethereum.spurious_dragon.fork_types" "Bloom". Definition add_to_bloom : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -53,20 +53,23 @@ Definition add_to_bloom : Value.t -> Value.t -> M := bloom_entry : An entry which is to be added to bloom filter. " in - let hash := + let _ := M.assign_local (| + "hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "bloom_entry" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "idx" |), make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ], ltac:(M.monadic ( - let bit_to_set := + let _ := M.assign_local (| + "bit_to_set" , BinOp.bit_and (| M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), @@ -84,18 +87,24 @@ Definition add_to_bloom : Value.t -> Value.t -> M := make_dict [] |), Constant.int 2047 - |) in - let bit_index := + |) + |) in + let _ := M.assign_local (| + "bit_index" , BinOp.sub (| Constant.int 2047, M.get_name (| globals, "bit_to_set" |) - |) in - let byte_index := + |) + |) in + let _ := M.assign_local (| + "byte_index" , BinOp.floor_div (| M.get_name (| globals, "bit_index" |), Constant.int 8 - |) in - let bit_value := + |) + |) in + let _ := M.assign_local (| + "bit_value" , BinOp.l_shift (| Constant.int 1, BinOp.sub (| @@ -105,7 +114,8 @@ Definition add_to_bloom : Value.t -> Value.t -> M := Constant.int 8 |) |) - |) in + |) + |) in let _ := M.assign (| M.get_subscript (| M.get_name (| globals, "bloom" |), diff --git a/CoqOfPython/ethereum/spurious_dragon/fork.v b/CoqOfPython/ethereum/spurious_dragon/fork.v index 19a0751..db39a8f 100644 --- a/CoqOfPython/ethereum/spurious_dragon/fork.v +++ b/CoqOfPython/ethereum/spurious_dragon/fork.v @@ -17,62 +17,122 @@ Introduction Entry point for the Ethereum specification. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Bytes0" ]. - -Axiom ethereum_crypto_elliptic_curve_imports : - AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. - -Axiom ethereum_ethash_imports : - AreImported globals "ethereum.ethash" [ "dataset_size"; "generate_cache"; "hashimoto_light" ]. - -Axiom ethereum_exceptions_imports : - AreImported globals "ethereum.exceptions" [ "InvalidBlock" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U64"; "U256"; "U256_CEIL_VALUE"; "Bytes"; "Bytes32"; "Uint" ]. - -Axiom ethereum_spurious_dragon_imports : - AreImported globals "ethereum.spurious_dragon" [ "vm" ]. - -Axiom ethereum_spurious_dragon_blocks_imports : - AreImported globals "ethereum.spurious_dragon.blocks" [ "Block"; "Header"; "Log"; "Receipt" ]. - -Axiom ethereum_spurious_dragon_bloom_imports : - AreImported globals "ethereum.spurious_dragon.bloom" [ "logs_bloom" ]. - -Axiom ethereum_spurious_dragon_fork_types_imports : - AreImported globals "ethereum.spurious_dragon.fork_types" [ "Address"; "Bloom"; "Root" ]. - -Axiom ethereum_spurious_dragon_state_imports : - AreImported globals "ethereum.spurious_dragon.state" [ "State"; "account_exists_and_is_empty"; "create_ether"; "destroy_account"; "get_account"; "increment_nonce"; "set_account_balance"; "state_root" ]. - -Axiom ethereum_spurious_dragon_transactions_imports : - AreImported globals "ethereum.spurious_dragon.transactions" [ "TX_BASE_COST"; "TX_CREATE_COST"; "TX_DATA_COST_PER_NON_ZERO"; "TX_DATA_COST_PER_ZERO"; "Transaction" ]. - -Axiom ethereum_spurious_dragon_trie_imports : - AreImported globals "ethereum.spurious_dragon.trie" [ "Trie"; "root"; "trie_set" ]. - -Axiom ethereum_spurious_dragon_utils_message_imports : - AreImported globals "ethereum.spurious_dragon.utils.message" [ "prepare_message" ]. - -Axiom ethereum_spurious_dragon_vm_interpreter_imports : - AreImported globals "ethereum.spurious_dragon.vm.interpreter" [ "process_message_call" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". + +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". + +Axiom ethereum_crypto_elliptic_curve_imports_SECP256K1N : + IsImported globals "ethereum.crypto.elliptic_curve" "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_imports_secp256k1_recover : + IsImported globals "ethereum.crypto.elliptic_curve" "secp256k1_recover". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". + +Axiom ethereum_ethash_imports_dataset_size : + IsImported globals "ethereum.ethash" "dataset_size". +Axiom ethereum_ethash_imports_generate_cache : + IsImported globals "ethereum.ethash" "generate_cache". +Axiom ethereum_ethash_imports_hashimoto_light : + IsImported globals "ethereum.ethash" "hashimoto_light". + +Axiom ethereum_exceptions_imports_InvalidBlock : + IsImported globals "ethereum.exceptions" "InvalidBlock". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U64 : + IsImported globals "ethereum.base_types" "U64". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_U256_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U256_CEIL_VALUE". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_spurious_dragon_imports_vm : + IsImported globals "ethereum.spurious_dragon" "vm". + +Axiom ethereum_spurious_dragon_blocks_imports_Block : + IsImported globals "ethereum.spurious_dragon.blocks" "Block". +Axiom ethereum_spurious_dragon_blocks_imports_Header : + IsImported globals "ethereum.spurious_dragon.blocks" "Header". +Axiom ethereum_spurious_dragon_blocks_imports_Log : + IsImported globals "ethereum.spurious_dragon.blocks" "Log". +Axiom ethereum_spurious_dragon_blocks_imports_Receipt : + IsImported globals "ethereum.spurious_dragon.blocks" "Receipt". + +Axiom ethereum_spurious_dragon_bloom_imports_logs_bloom : + IsImported globals "ethereum.spurious_dragon.bloom" "logs_bloom". + +Axiom ethereum_spurious_dragon_fork_types_imports_Address : + IsImported globals "ethereum.spurious_dragon.fork_types" "Address". +Axiom ethereum_spurious_dragon_fork_types_imports_Bloom : + IsImported globals "ethereum.spurious_dragon.fork_types" "Bloom". +Axiom ethereum_spurious_dragon_fork_types_imports_Root : + IsImported globals "ethereum.spurious_dragon.fork_types" "Root". + +Axiom ethereum_spurious_dragon_state_imports_State : + IsImported globals "ethereum.spurious_dragon.state" "State". +Axiom ethereum_spurious_dragon_state_imports_account_exists_and_is_empty : + IsImported globals "ethereum.spurious_dragon.state" "account_exists_and_is_empty". +Axiom ethereum_spurious_dragon_state_imports_create_ether : + IsImported globals "ethereum.spurious_dragon.state" "create_ether". +Axiom ethereum_spurious_dragon_state_imports_destroy_account : + IsImported globals "ethereum.spurious_dragon.state" "destroy_account". +Axiom ethereum_spurious_dragon_state_imports_get_account : + IsImported globals "ethereum.spurious_dragon.state" "get_account". +Axiom ethereum_spurious_dragon_state_imports_increment_nonce : + IsImported globals "ethereum.spurious_dragon.state" "increment_nonce". +Axiom ethereum_spurious_dragon_state_imports_set_account_balance : + IsImported globals "ethereum.spurious_dragon.state" "set_account_balance". +Axiom ethereum_spurious_dragon_state_imports_state_root : + IsImported globals "ethereum.spurious_dragon.state" "state_root". + +Axiom ethereum_spurious_dragon_transactions_imports_TX_BASE_COST : + IsImported globals "ethereum.spurious_dragon.transactions" "TX_BASE_COST". +Axiom ethereum_spurious_dragon_transactions_imports_TX_CREATE_COST : + IsImported globals "ethereum.spurious_dragon.transactions" "TX_CREATE_COST". +Axiom ethereum_spurious_dragon_transactions_imports_TX_DATA_COST_PER_NON_ZERO : + IsImported globals "ethereum.spurious_dragon.transactions" "TX_DATA_COST_PER_NON_ZERO". +Axiom ethereum_spurious_dragon_transactions_imports_TX_DATA_COST_PER_ZERO : + IsImported globals "ethereum.spurious_dragon.transactions" "TX_DATA_COST_PER_ZERO". +Axiom ethereum_spurious_dragon_transactions_imports_Transaction : + IsImported globals "ethereum.spurious_dragon.transactions" "Transaction". + +Axiom ethereum_spurious_dragon_trie_imports_Trie : + IsImported globals "ethereum.spurious_dragon.trie" "Trie". +Axiom ethereum_spurious_dragon_trie_imports_root : + IsImported globals "ethereum.spurious_dragon.trie" "root". +Axiom ethereum_spurious_dragon_trie_imports_trie_set : + IsImported globals "ethereum.spurious_dragon.trie" "trie_set". + +Axiom ethereum_spurious_dragon_utils_message_imports_prepare_message : + IsImported globals "ethereum.spurious_dragon.utils.message" "prepare_message". + +Axiom ethereum_spurious_dragon_vm_interpreter_imports_process_message_call : + IsImported globals "ethereum.spurious_dragon.vm.interpreter" "process_message_call". Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -170,13 +230,15 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := recent_block_hashes : `List[Hash32]` Hashes of the recent 256 blocks in order of increasing block number. " in - let recent_blocks := + let _ := M.assign_local (| + "recent_blocks" , M.slice (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |), Constant.None_, Constant.None_ - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -200,15 +262,19 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let recent_block_hashes := - make_list [] in + let _ := M.assign_local (| + "recent_block_hashes" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "block" |), M.get_name (| globals, "recent_blocks" |), ltac:(M.monadic ( - let prev_block_hash := - M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in + let _ := M.assign_local (| + "prev_block_hash" , + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), make_list [ @@ -222,7 +288,8 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let most_recent_block_hash := + let _ := M.assign_local (| + "most_recent_block_hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -238,7 +305,8 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), make_list [ @@ -275,11 +343,13 @@ Definition state_transition : Value.t -> Value.t -> M := block : Block to apply to `chain`. " in - let parent_header := + let _ := M.assign_local (| + "parent_header" , M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 1 |) - |), "header" |) in + |), "header" |) + |) in let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ @@ -297,7 +367,8 @@ Definition state_transition : Value.t -> Value.t -> M := ], make_dict [] |) in - let apply_body_output := + let _ := M.assign_local (| + "apply_body_output" , M.call (| M.get_name (| globals, "apply_body" |), make_list [ @@ -319,7 +390,8 @@ Definition state_transition : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "chain" |), "chain_id" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -490,7 +562,8 @@ Definition validate_header : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_difficulty := + let _ := M.assign_local (| + "block_difficulty" , M.call (| M.get_name (| globals, "calculate_block_difficulty" |), make_list [ @@ -500,7 +573,8 @@ Definition validate_header : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "parent_header" |), "difficulty" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -512,7 +586,8 @@ Definition validate_header : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_parent_hash := + let _ := M.assign_local (| + "block_parent_hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -525,7 +600,8 @@ Definition validate_header : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -571,7 +647,8 @@ Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := hash : `Hash32` The PoW valid rlp hash of the passed in header. " in - let header_data_without_pow_artefacts := + let _ := M.assign_local (| + "header_data_without_pow_artefacts" , make_list [ M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |); M.get_field (| M.get_name (| globals, "header" |), "ommers_hash" |); @@ -586,7 +663,8 @@ Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "header" |), "gas_used" |); M.get_field (| M.get_name (| globals, "header" |), "timestamp" |); M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) - ] in + ] + |) in let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), @@ -615,22 +693,26 @@ Definition validate_proof_of_work : Value.t -> Value.t -> M := header : Header of interest. " in - let header_hash := + let _ := M.assign_local (| + "header_hash" , M.call (| M.get_name (| globals, "generate_header_hash_for_pow" |), make_list [ M.get_name (| globals, "header" |) ], make_dict [] - |) in - let cache := + |) + |) in + let _ := M.assign_local (| + "cache" , M.call (| M.get_name (| globals, "generate_cache" |), make_list [ M.get_field (| M.get_name (| globals, "header" |), "number" |) ], make_dict [] - |) in + |) + |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "mix_digest" |); M.get_name (| globals, "result" |) ], M.call (| @@ -719,7 +801,8 @@ Definition check_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_address := + let _ := M.assign_local (| + "sender_address" , M.call (| M.get_name (| globals, "recover_sender" |), make_list [ @@ -727,7 +810,8 @@ Definition check_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "tx" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "sender_address" |) |) in @@ -756,12 +840,14 @@ Definition make_receipt : Value.t -> Value.t -> M := receipt : The receipt for the transaction. " in - let receipt := + let _ := M.assign_local (| + "receipt" , M.call (| M.get_name (| globals, "Receipt" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "receipt" |) |) in @@ -820,8 +906,10 @@ Definition apply_body : Value.t -> Value.t -> M := apply_body_output : `ApplyBodyOutput` Output of applying the block body to the state. " in - let gas_available := - M.get_name (| globals, "block_gas_limit" |) in + let _ := M.assign_local (| + "gas_available" , + M.get_name (| globals, "block_gas_limit" |) + |) in (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) @@ -857,7 +945,8 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_address := + let _ := M.assign_local (| + "sender_address" , M.call (| M.get_name (| globals, "check_transaction" |), make_list [ @@ -866,13 +955,16 @@ Definition apply_body : Value.t -> Value.t -> M := M.get_name (| globals, "chain_id" |) ], make_dict [] - |) in - let env := + |) + |) in + let _ := M.assign_local (| + "env" , M.call (| M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |) ], M.call (| @@ -884,10 +976,13 @@ Definition apply_body : Value.t -> Value.t -> M := make_dict [] |) |) in - let gas_available := BinOp.sub + let _ := M.assign_op_local (| + BinOp.sub, + "gas_available", M.get_name (| globals, "gas_used" |) - M.get_name (| globals, "gas_used" |) in - let receipt := + |) in + let _ := M.assign_local (| + "receipt" , M.call (| M.get_name (| globals, "make_receipt" |), make_list [ @@ -906,7 +1001,8 @@ Definition apply_body : Value.t -> Value.t -> M := M.get_name (| globals, "logs" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ @@ -928,9 +1024,11 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_logs := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "block_logs", M.get_name (| globals, "logs" |) - M.get_name (| globals, "logs" |) in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -947,19 +1045,23 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_gas_used := + let _ := M.assign_local (| + "block_gas_used" , BinOp.sub (| M.get_name (| globals, "block_gas_limit" |), M.get_name (| globals, "gas_available" |) - |) in - let block_logs_bloom := + |) + |) in + let _ := M.assign_local (| + "block_logs_bloom" , M.call (| M.get_name (| globals, "logs_bloom" |), make_list [ M.get_name (| globals, "block_logs" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ApplyBodyOutput" |), @@ -1017,14 +1119,16 @@ Definition validate_ommers : Value.t -> Value.t -> M := chain : History and current state. " in - let block_hash := + let _ := M.assign_local (| + "block_hash" , M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), make_list [ M.get_name (| globals, "block_header" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1089,7 +1193,8 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_parent_header := + let _ := M.assign_local (| + "ommer_parent_header" , M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), BinOp.sub (| @@ -1099,7 +1204,8 @@ Definition validate_ommers : Value.t -> Value.t -> M := |) |), Constant.int 1 |) - |), "header" |) in + |), "header" |) + |) in let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ @@ -1131,8 +1237,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommers_hashes := - Constant.str "(* At expr: unsupported node type: ListComp *)" in + let _ := M.assign_local (| + "ommers_hashes" , + Constant.str "(* At expr: unsupported node type: ListComp *)" + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1162,7 +1270,8 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let recent_canonical_blocks := + let _ := M.assign_local (| + "recent_canonical_blocks" , M.slice (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| BinOp.add (| @@ -1171,23 +1280,28 @@ Definition validate_ommers : Value.t -> Value.t -> M := |) |), Constant.None_, Constant.None_ - |) in - let recent_canonical_block_hashes := - Constant.str "(* At expr: unsupported node type: SetComp *)" in + |) + |) in + let _ := M.assign_local (| + "recent_canonical_block_hashes" , + Constant.str "(* At expr: unsupported node type: SetComp *)" + |) in (* At stmt: unsupported node type: AnnAssign *) let _ := M.for_ (| M.get_name (| globals, "block" |), M.get_name (| globals, "recent_canonical_blocks" |), ltac:(M.monadic ( - let recent_ommers_hashes := + let _ := M.assign_local (| + "recent_ommers_hashes" , M.call (| M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), make_list [ Constant.str "(* At expr: unsupported node type: SetComp *)" ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -1205,11 +1319,13 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let ommer_hash := + let _ := M.assign_local (| + "ommer_hash" , M.get_subscript (| M.get_name (| globals, "ommers_hashes" |), M.get_name (| globals, "ommer_index" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1243,11 +1359,13 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_age := + let _ := M.assign_local (| + "ommer_age" , BinOp.sub (| M.get_field (| M.get_name (| globals, "block_header" |), "number" |), M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1325,7 +1443,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := ommers : List of ommers mentioned in the current block. " in - let miner_reward := + let _ := M.assign_local (| + "miner_reward" , BinOp.add (| M.get_name (| globals, "BLOCK_REWARD" |), BinOp.mult (| @@ -1341,7 +1460,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := Constant.int 32 |) |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "create_ether" |), make_list [ @@ -1356,7 +1476,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := M.get_name (| globals, "ommer" |), M.get_name (| globals, "ommers" |), ltac:(M.monadic ( - let ommer_age := + let _ := M.assign_local (| + "ommer_age" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -1366,8 +1487,10 @@ Definition pay_rewards : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let ommer_miner_reward := + |) + |) in + let _ := M.assign_local (| + "ommer_miner_reward" , BinOp.floor_div (| BinOp.mult (| BinOp.sub (| @@ -1377,7 +1500,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := M.get_name (| globals, "BLOCK_REWARD" |) |), Constant.int 8 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "create_ether" |), make_list [ @@ -1438,9 +1562,12 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender := - M.get_field (| M.get_name (| globals, "env" |), "origin" |) in - let sender_account := + let _ := M.assign_local (| + "sender" , + M.get_field (| M.get_name (| globals, "env" |), "origin" |) + |) in + let _ := M.assign_local (| + "sender_account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1448,12 +1575,15 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "sender" |) ], make_dict [] - |) in - let gas_fee := + |) + |) in + let _ := M.assign_local (| + "gas_fee" , BinOp.mult (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1494,7 +1624,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let gas := + let _ := M.assign_local (| + "gas" , BinOp.sub (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.call (| @@ -1504,7 +1635,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "increment_nonce" |), make_list [ @@ -1513,11 +1645,13 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_balance_after_gas_fee := + let _ := M.assign_local (| + "sender_balance_after_gas_fee" , BinOp.sub (| M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), M.get_name (| globals, "gas_fee" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -1527,7 +1661,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let message := + let _ := M.assign_local (| + "message" , M.call (| M.get_name (| globals, "prepare_message" |), make_list [ @@ -1539,8 +1674,10 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in - let output := + |) + |) in + let _ := M.assign_local (| + "output" , M.call (| M.get_name (| globals, "process_message_call" |), make_list [ @@ -1548,13 +1685,17 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in - let gas_used := + |) + |) in + let _ := M.assign_local (| + "gas_used" , BinOp.sub (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_field (| M.get_name (| globals, "output" |), "gas_left" |) - |) in - let gas_refund := + |) + |) in + let _ := M.assign_local (| + "gas_refund" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -1565,16 +1706,20 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "output" |), "refund_counter" |) ], make_dict [] - |) in - let gas_refund_amount := + |) + |) in + let _ := M.assign_local (| + "gas_refund_amount" , BinOp.mult (| BinOp.add (| M.get_field (| M.get_name (| globals, "output" |), "gas_left" |), M.get_name (| globals, "gas_refund" |) |), M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) - |) in - let transaction_fee := + |) + |) in + let _ := M.assign_local (| + "transaction_fee" , BinOp.mult (| BinOp.sub (| BinOp.sub (| @@ -1584,13 +1729,17 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "gas_refund" |) |), M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) - |) in - let total_gas_used := + |) + |) in + let _ := M.assign_local (| + "total_gas_used" , BinOp.sub (| M.get_name (| globals, "gas_used" |), M.get_name (| globals, "gas_refund" |) - |) in - let sender_balance_after_refund := + |) + |) in + let _ := M.assign_local (| + "sender_balance_after_refund" , BinOp.add (| M.get_field (| M.call (| M.get_name (| globals, "get_account" |), @@ -1601,7 +1750,8 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |), "balance" |), M.get_name (| globals, "gas_refund_amount" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -1611,7 +1761,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let coinbase_balance_after_mining_fee := + let _ := M.assign_local (| + "coinbase_balance_after_mining_fee" , BinOp.add (| M.get_field (| M.call (| M.get_name (| globals, "get_account" |), @@ -1622,7 +1773,8 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |), "balance" |), M.get_name (| globals, "transaction_fee" |) - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1813,8 +1965,10 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := verified : `ethereum.base_types.Uint` The intrinsic cost of the transaction. " in - let data_cost := - Constant.int 0 in + let _ := M.assign_local (| + "data_cost" , + Constant.int 0 + |) in let _ := M.for_ (| M.get_name (| globals, "byte" |), @@ -1829,15 +1983,19 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let data_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "data_cost", M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let data_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "data_cost", M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -1861,13 +2019,17 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let create_cost := - M.get_name (| globals, "TX_CREATE_COST" |) in + let _ := M.assign_local (| + "create_cost" , + M.get_name (| globals, "TX_CREATE_COST" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let create_cost := - Constant.int 0 in + let _ := M.assign_local (| + "create_cost" , + Constant.int 0 + |) in M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1973,7 +2135,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let public_key := + let _ := M.assign_local (| + "public_key" , M.call (| M.get_name (| globals, "secp256k1_recover" |), make_list [ @@ -1992,7 +2155,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -2027,7 +2191,8 @@ Definition recover_sender : Value.t -> Value.t -> M := ], make_dict [] |) in - let public_key := + let _ := M.assign_local (| + "public_key" , M.call (| M.get_name (| globals, "secp256k1_recover" |), make_list [ @@ -2053,7 +2218,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -2239,11 +2405,13 @@ Definition check_gas_limit : Value.t -> Value.t -> M := check : `bool` True if gas limit constraints are satisfied, False otherwise. " in - let max_adjustment_delta := + let _ := M.assign_local (| + "max_adjustment_delta" , BinOp.floor_div (| M.get_name (| globals, "parent_gas_limit" |), M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -2345,7 +2513,8 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := difficulty : `ethereum.base_types.Uint` Computed difficulty for a block. " in - let offset := + let _ := M.assign_local (| + "offset" , BinOp.mult (| BinOp.floor_div (| M.call (| @@ -2380,8 +2549,10 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := ], make_dict [] |) - |) in - let difficulty := + |) + |) in + let _ := M.assign_local (| + "difficulty" , BinOp.add (| M.call (| M.get_name (| globals, "int" |), @@ -2391,8 +2562,10 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := make_dict [] |), M.get_name (| globals, "offset" |) - |) in - let num_bomb_periods := + |) + |) in + let _ := M.assign_local (| + "num_bomb_periods" , BinOp.sub (| BinOp.floor_div (| M.call (| @@ -2405,7 +2578,8 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := Constant.int 100000 |), Constant.int 2 - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -2415,15 +2589,14 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let difficulty := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "difficulty", BinOp.pow (| Constant.int 2, M.get_name (| globals, "num_bomb_periods" |) |) - BinOp.pow (| - Constant.int 2, - M.get_name (| globals, "num_bomb_periods" |) - |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/spurious_dragon/fork_types.v b/CoqOfPython/ethereum/spurious_dragon/fork_types.v index 2016387..92672ad 100644 --- a/CoqOfPython/ethereum/spurious_dragon/fork_types.v +++ b/CoqOfPython/ethereum/spurious_dragon/fork_types.v @@ -17,17 +17,29 @@ Introduction Types re-used throughout the specification, which are specific to Ethereum. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes20"; "Bytes256"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes20 : + IsImported globals "ethereum.base_types" "Bytes20". +Axiom ethereum_base_types_imports_Bytes256 : + IsImported globals "ethereum.base_types" "Bytes256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) diff --git a/CoqOfPython/ethereum/spurious_dragon/state.v b/CoqOfPython/ethereum/spurious_dragon/state.v index 088ce84..d7957d0 100644 --- a/CoqOfPython/ethereum/spurious_dragon/state.v +++ b/CoqOfPython/ethereum/spurious_dragon/state.v @@ -22,23 +22,55 @@ There is a distinction between an account that does not exist and `EMPTY_ACCOUNT`. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass"; "field" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict"; "List"; "Optional"; "Tuple" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "modify" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_spurious_dragon_fork_types_imports : - AreImported globals "ethereum.spurious_dragon.fork_types" [ "EMPTY_ACCOUNT"; "Account"; "Address"; "Root" ]. - -Axiom ethereum_spurious_dragon_trie_imports : - AreImported globals "ethereum.spurious_dragon.trie" [ "EMPTY_TRIE_ROOT"; "Trie"; "copy_trie"; "root"; "trie_get"; "trie_set" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". +Axiom dataclasses_imports_field : + IsImported globals "dataclasses" "field". + +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_modify : + IsImported globals "ethereum.base_types" "modify". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_spurious_dragon_fork_types_imports_EMPTY_ACCOUNT : + IsImported globals "ethereum.spurious_dragon.fork_types" "EMPTY_ACCOUNT". +Axiom ethereum_spurious_dragon_fork_types_imports_Account : + IsImported globals "ethereum.spurious_dragon.fork_types" "Account". +Axiom ethereum_spurious_dragon_fork_types_imports_Address : + IsImported globals "ethereum.spurious_dragon.fork_types" "Address". +Axiom ethereum_spurious_dragon_fork_types_imports_Root : + IsImported globals "ethereum.spurious_dragon.fork_types" "Root". + +Axiom ethereum_spurious_dragon_trie_imports_EMPTY_TRIE_ROOT : + IsImported globals "ethereum.spurious_dragon.trie" "EMPTY_TRIE_ROOT". +Axiom ethereum_spurious_dragon_trie_imports_Trie : + IsImported globals "ethereum.spurious_dragon.trie" "Trie". +Axiom ethereum_spurious_dragon_trie_imports_copy_trie : + IsImported globals "ethereum.spurious_dragon.trie" "copy_trie". +Axiom ethereum_spurious_dragon_trie_imports_root : + IsImported globals "ethereum.spurious_dragon.trie" "root". +Axiom ethereum_spurious_dragon_trie_imports_trie_get : + IsImported globals "ethereum.spurious_dragon.trie" "trie_get". +Axiom ethereum_spurious_dragon_trie_imports_trie_set : + IsImported globals "ethereum.spurious_dragon.trie" "trie_set". Definition State : Value.t := builtins.make_klass @@ -153,7 +185,8 @@ Definition get_account : Value.t -> Value.t -> M := account : `Account` Account at address. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account_optional" |), make_list [ @@ -161,7 +194,8 @@ Definition get_account : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -207,7 +241,8 @@ Definition get_account_optional : Value.t -> Value.t -> M := account : `Account` Account at address. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "trie_get" |), make_list [ @@ -215,7 +250,8 @@ Definition get_account_optional : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "account" |) |) in @@ -338,14 +374,16 @@ Definition get_storage : Value.t -> Value.t -> M := value : `U256` Value at the key. " in - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -369,7 +407,8 @@ Definition get_storage : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "trie_get" |), make_list [ @@ -377,7 +416,8 @@ Definition get_storage : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -420,14 +460,16 @@ Definition set_storage : Value.t -> Value.t -> M := |), Constant.None_ |) |) in - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -437,12 +479,14 @@ Definition set_storage : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_name (| globals, "Trie" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), @@ -469,7 +513,7 @@ Definition set_storage : Value.t -> Value.t -> M := M.if_then_else (| Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), - {} + Constant.str "(* At expr: unsupported node type: Dict *)" |), (* then *) ltac:(M.monadic ( @@ -615,7 +659,8 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := True if if an account has non zero nonce or non empty code, False otherwise. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -623,7 +668,8 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| BoolOp.or (| Compare.not_eq (| @@ -665,7 +711,8 @@ Definition is_account_empty : Value.t -> Value.t -> M := True if if an account has zero nonce, empty code and zero balance, False otherwise. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -673,7 +720,8 @@ Definition is_account_empty : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| BoolOp.and (| Compare.eq (| @@ -724,7 +772,8 @@ Definition account_exists_and_is_empty : Value.t -> Value.t -> M := True if an account exists and has zero nonce, empty code and zero balance, False otherwise. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account_optional" |), make_list [ @@ -732,7 +781,8 @@ Definition account_exists_and_is_empty : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| BoolOp.and (| Compare.is_not (| @@ -789,7 +839,8 @@ Definition is_account_alive : Value.t -> Value.t -> M := is_alive : `bool` True if the account is alive. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account_optional" |), make_list [ @@ -797,7 +848,8 @@ Definition is_account_alive : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| diff --git a/CoqOfPython/ethereum/spurious_dragon/transactions.v b/CoqOfPython/ethereum/spurious_dragon/transactions.v index e1289b5..d563ae6 100644 --- a/CoqOfPython/ethereum/spurious_dragon/transactions.v +++ b/CoqOfPython/ethereum/spurious_dragon/transactions.v @@ -9,17 +9,25 @@ submitted to be executed. If Ethereum is viewed as a state machine, transactions are the events that move between states. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Union" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_spurious_dragon_fork_types_imports : - AreImported globals "ethereum.spurious_dragon.fork_types" [ "Address" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_Union : + IsImported globals "typing" "Union". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_spurious_dragon_fork_types_imports_Address : + IsImported globals "ethereum.spurious_dragon.fork_types" "Address". Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( Constant.int 21000 diff --git a/CoqOfPython/ethereum/spurious_dragon/trie.v b/CoqOfPython/ethereum/spurious_dragon/trie.v index dae0e12..acd6b08 100644 --- a/CoqOfPython/ethereum/spurious_dragon/trie.v +++ b/CoqOfPython/ethereum/spurious_dragon/trie.v @@ -20,38 +20,72 @@ The state trie is the structure responsible for storing (* At top_level_stmt: unsupported node type: Import *) -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass"; "field" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict"; "Generic"; "List"; "Mapping"; "MutableMapping"; "Optional"; "Sequence"; "TypeVar"; "Union"; "cast" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. - -Axiom ethereum_tangerine_whistle_imports : - AreImported globals "ethereum.tangerine_whistle" [ "trie" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_utils_hexadecimal_imports : - AreImported globals "ethereum.utils.hexadecimal" [ "hex_to_bytes" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_spurious_dragon_blocks_imports : - AreImported globals "ethereum.spurious_dragon.blocks" [ "Receipt" ]. - -Axiom ethereum_spurious_dragon_fork_types_imports : - AreImported globals "ethereum.spurious_dragon.fork_types" [ "Account"; "Address"; "Root"; "encode_account" ]. - -Axiom ethereum_spurious_dragon_transactions_imports : - AreImported globals "ethereum.spurious_dragon.transactions" [ "Transaction" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". +Axiom dataclasses_imports_field : + IsImported globals "dataclasses" "field". + +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". +Axiom typing_imports_Generic : + IsImported globals "typing" "Generic". +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Mapping : + IsImported globals "typing" "Mapping". +Axiom typing_imports_MutableMapping : + IsImported globals "typing" "MutableMapping". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Sequence : + IsImported globals "typing" "Sequence". +Axiom typing_imports_TypeVar : + IsImported globals "typing" "TypeVar". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". +Axiom typing_imports_cast : + IsImported globals "typing" "cast". + +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". + +Axiom ethereum_tangerine_whistle_imports_trie : + IsImported globals "ethereum.tangerine_whistle" "trie". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_utils_hexadecimal_imports_hex_to_bytes : + IsImported globals "ethereum.utils.hexadecimal" "hex_to_bytes". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_spurious_dragon_blocks_imports_Receipt : + IsImported globals "ethereum.spurious_dragon.blocks" "Receipt". + +Axiom ethereum_spurious_dragon_fork_types_imports_Account : + IsImported globals "ethereum.spurious_dragon.fork_types" "Account". +Axiom ethereum_spurious_dragon_fork_types_imports_Address : + IsImported globals "ethereum.spurious_dragon.fork_types" "Address". +Axiom ethereum_spurious_dragon_fork_types_imports_Root : + IsImported globals "ethereum.spurious_dragon.fork_types" "Root". +Axiom ethereum_spurious_dragon_fork_types_imports_encode_account : + IsImported globals "ethereum.spurious_dragon.fork_types" "encode_account". + +Axiom ethereum_spurious_dragon_transactions_imports_Transaction : + IsImported globals "ethereum.spurious_dragon.transactions" "Transaction". Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -161,7 +195,7 @@ Definition encode_internal_node : Value.t -> Value.t -> M := when serialized. This function also accepts `None`, representing the absence of a node, - which is encoded to `b""""""`. + which is encoded to `b""""`. Parameters ---------- @@ -183,8 +217,10 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := - Constant.bytes "" in + let _ := M.assign_local (| + "unencoded" , + Constant.bytes "" + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -201,7 +237,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := + let _ := M.assign_local (| + "unencoded" , make_tuple [ M.call (| M.get_name (| globals, "nibble_list_to_compact" |), make_list [ @@ -209,7 +246,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := Constant.bool true ], make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in + |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -226,7 +264,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := + let _ := M.assign_local (| + "unencoded" , make_tuple [ M.call (| M.get_name (| globals, "nibble_list_to_compact" |), make_list [ @@ -234,7 +273,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := Constant.bool false ], make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in + |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -251,13 +291,15 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := + let _ := M.assign_local (| + "unencoded" , BinOp.add (| M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), make_list [ M.get_field (| M.get_name (| globals, "node" |), "value" |) ] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -276,14 +318,16 @@ Definition encode_internal_node : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - let encoded := + let _ := M.assign_local (| + "encoded" , M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), make_list [ M.get_name (| globals, "unencoded" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -675,12 +719,14 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := compressed : `bytearray` Compact byte array. " in - let compact := + let _ := M.assign_local (| + "compact" , M.call (| M.get_name (| globals, "bytearray" |), make_list [], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -860,7 +906,8 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := nibble_list : `Bytes` The `Bytes` in nibble-list format. " in - let nibble_list := + let _ := M.assign_local (| + "nibble_list" , M.call (| M.get_name (| globals, "bytearray" |), make_list [ @@ -876,7 +923,8 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ], @@ -984,15 +1032,18 @@ Definition _prepare_trie : Value.t -> Value.t -> M := M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "Address" |), make_list [ M.get_name (| globals, "preimage" |) ], make_dict [] - |) in - let encoded_value := + |) + |) in + let _ := M.assign_local (| + "encoded_value" , M.call (| M.get_name (| globals, "encode_node" |), make_list [ @@ -1006,18 +1057,21 @@ Definition _prepare_trie : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let encoded_value := + let _ := M.assign_local (| + "encoded_value" , M.call (| M.get_name (| globals, "encode_node" |), make_list [ M.get_name (| globals, "value" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -1038,19 +1092,23 @@ Definition _prepare_trie : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "trie" |), "secured" |), (* then *) ltac:(M.monadic ( - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "preimage" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let key := - M.get_name (| globals, "preimage" |) in + let _ := M.assign_local (| + "key" , + M.get_name (| globals, "preimage" |) + |) in M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -1097,7 +1155,8 @@ Definition root : Value.t -> Value.t -> M := root : `.fork_types.Root` MPT root of the underlying key-value pairs. " in - let obj := + let _ := M.assign_local (| + "obj" , M.call (| M.get_name (| globals, "_prepare_trie" |), make_list [ @@ -1105,8 +1164,10 @@ Definition root : Value.t -> Value.t -> M := M.get_name (| globals, "get_storage_root" |) ], make_dict [] - |) in - let root_node := + |) + |) in + let _ := M.assign_local (| + "root_node" , M.call (| M.get_name (| globals, "encode_internal_node" |), make_list [ @@ -1126,7 +1187,8 @@ Definition root : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1231,7 +1293,8 @@ Definition patricialize : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let arbitrary_key := + let _ := M.assign_local (| + "arbitrary_key" , M.call (| M.get_name (| globals, "next" |), make_list [ @@ -1244,7 +1307,8 @@ Definition patricialize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1260,7 +1324,8 @@ Definition patricialize : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let leaf := + let _ := M.assign_local (| + "leaf" , M.call (| M.get_name (| globals, "LeafNode" |), make_list [ @@ -1276,7 +1341,8 @@ Definition patricialize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "leaf" |) |) in @@ -1285,27 +1351,32 @@ Definition patricialize : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let substring := + let _ := M.assign_local (| + "substring" , M.slice (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |), Constant.None_, Constant.None_ - |) in - let prefix_length := + |) + |) in + let _ := M.assign_local (| + "prefix_length" , M.call (| M.get_name (| globals, "len" |), make_list [ M.get_name (| globals, "substring" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "key" |), M.get_name (| globals, "obj" |), ltac:(M.monadic ( - let prefix_length := + let _ := M.assign_local (| + "prefix_length" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -1325,7 +1396,8 @@ Definition patricialize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1356,7 +1428,8 @@ Definition patricialize : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let prefix := + let _ := M.assign_local (| + "prefix" , M.slice (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |), @@ -1365,7 +1438,8 @@ Definition patricialize : Value.t -> Value.t -> M := M.get_name (| globals, "prefix_length" |) |), Constant.None_ - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ExtensionNode" |), @@ -1412,7 +1486,7 @@ Definition patricialize : Value.t -> Value.t -> M := let _ := M.call (| M.get_field (| M.get_name (| globals, "branches" |), "append" |), make_list [ - {} + Constant.str "(* At expr: unsupported node type: Dict *)" ], make_dict [] |) in @@ -1422,8 +1496,10 @@ Definition patricialize : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let value := - Constant.bytes "" in + let _ := M.assign_local (| + "value" , + Constant.bytes "" + |) in let _ := M.for_ (| M.get_name (| globals, "key" |), @@ -1466,11 +1542,13 @@ Definition patricialize : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let value := + let _ := M.assign_local (| + "value" , M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/spurious_dragon/utils/address.v b/CoqOfPython/ethereum/spurious_dragon/utils/address.v index 0281007..a4a5c3d 100644 --- a/CoqOfPython/ethereum/spurious_dragon/utils/address.v +++ b/CoqOfPython/ethereum/spurious_dragon/utils/address.v @@ -18,23 +18,25 @@ Address specific functions used in this spurious dragon version of specification. ". -Axiom typing_imports : - AreImported globals "typing" [ "Union" ]. +Axiom typing_imports_Union : + IsImported globals "typing" "Union". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_left_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "left_pad_zero_bytes". -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". -Axiom ethereum_spurious_dragon_fork_types_imports : - AreImported globals "ethereum.spurious_dragon.fork_types" [ "Address" ]. +Axiom ethereum_spurious_dragon_fork_types_imports_Address : + IsImported globals "ethereum.spurious_dragon.fork_types" "Address". Definition to_address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -91,7 +93,8 @@ Definition compute_contract_address : Value.t -> Value.t -> M := address: `ethereum.spurious_dragon.fork_types.Address` The computed address of the new account. " in - let computed_address := + let _ := M.assign_local (| + "computed_address" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -107,15 +110,19 @@ Definition compute_contract_address : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let canonical_address := + |) + |) in + let _ := M.assign_local (| + "canonical_address" , M.slice (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |), Constant.None_, Constant.None_ - |) in - let padded_address := + |) + |) in + let _ := M.assign_local (| + "padded_address" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -123,7 +130,8 @@ Definition compute_contract_address : Value.t -> Value.t -> M := Constant.int 20 ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Address" |), diff --git a/CoqOfPython/ethereum/spurious_dragon/utils/hexadecimal.v b/CoqOfPython/ethereum/spurious_dragon/utils/hexadecimal.v index 0cd23a2..bbdbabf 100644 --- a/CoqOfPython/ethereum/spurious_dragon/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/spurious_dragon/utils/hexadecimal.v @@ -18,11 +18,15 @@ Hexadecimal utility functions used in this specification, specific to Spurious Dragon types. ". -Axiom ethereum_utils_hexadecimal_imports : - AreImported globals "ethereum.utils.hexadecimal" [ "remove_hex_prefix" ]. - -Axiom ethereum_spurious_dragon_fork_types_imports : - AreImported globals "ethereum.spurious_dragon.fork_types" [ "Address"; "Bloom"; "Root" ]. +Axiom ethereum_utils_hexadecimal_imports_remove_hex_prefix : + IsImported globals "ethereum.utils.hexadecimal" "remove_hex_prefix". + +Axiom ethereum_spurious_dragon_fork_types_imports_Address : + IsImported globals "ethereum.spurious_dragon.fork_types" "Address". +Axiom ethereum_spurious_dragon_fork_types_imports_Bloom : + IsImported globals "ethereum.spurious_dragon.fork_types" "Bloom". +Axiom ethereum_spurious_dragon_fork_types_imports_Root : + IsImported globals "ethereum.spurious_dragon.fork_types" "Root". Definition hex_to_root : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/spurious_dragon/utils/message.v b/CoqOfPython/ethereum/spurious_dragon/utils/message.v index a3cd59e..a356277 100644 --- a/CoqOfPython/ethereum/spurious_dragon/utils/message.v +++ b/CoqOfPython/ethereum/spurious_dragon/utils/message.v @@ -18,23 +18,33 @@ Message specific functions used in this spurious dragon version of specification. ". -Axiom typing_imports : - AreImported globals "typing" [ "Optional"; "Union" ]. +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_spurious_dragon_fork_types_imports : - AreImported globals "ethereum.spurious_dragon.fork_types" [ "Address" ]. +Axiom ethereum_spurious_dragon_fork_types_imports_Address : + IsImported globals "ethereum.spurious_dragon.fork_types" "Address". -Axiom ethereum_spurious_dragon_state_imports : - AreImported globals "ethereum.spurious_dragon.state" [ "get_account" ]. +Axiom ethereum_spurious_dragon_state_imports_get_account : + IsImported globals "ethereum.spurious_dragon.state" "get_account". -Axiom ethereum_spurious_dragon_vm_imports : - AreImported globals "ethereum.spurious_dragon.vm" [ "Environment"; "Message" ]. +Axiom ethereum_spurious_dragon_vm_imports_Environment : + IsImported globals "ethereum.spurious_dragon.vm" "Environment". +Axiom ethereum_spurious_dragon_vm_imports_Message : + IsImported globals "ethereum.spurious_dragon.vm" "Message". -Axiom ethereum_spurious_dragon_utils_address_imports : - AreImported globals "ethereum.spurious_dragon.utils.address" [ "compute_contract_address" ]. +Axiom ethereum_spurious_dragon_utils_address_imports_compute_contract_address : + IsImported globals "ethereum.spurious_dragon.utils.address" "compute_contract_address". Definition prepare_message : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -81,7 +91,8 @@ Definition prepare_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let current_target := + let _ := M.assign_local (| + "current_target" , M.call (| M.get_name (| globals, "compute_contract_address" |), make_list [ @@ -105,17 +116,22 @@ Definition prepare_message : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let msg_data := + |) + |) in + let _ := M.assign_local (| + "msg_data" , M.call (| M.get_name (| globals, "Bytes" |), make_list [ Constant.bytes "" ], make_dict [] - |) in - let code := - M.get_name (| globals, "data" |) in + |) + |) in + let _ := M.assign_local (| + "code" , + M.get_name (| globals, "data" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -132,11 +148,16 @@ Definition prepare_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let current_target := - M.get_name (| globals, "target" |) in - let msg_data := - M.get_name (| globals, "data" |) in - let code := + let _ := M.assign_local (| + "current_target" , + M.get_name (| globals, "target" |) + |) in + let _ := M.assign_local (| + "msg_data" , + M.get_name (| globals, "data" |) + |) in + let _ := M.assign_local (| + "code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -144,7 +165,8 @@ Definition prepare_message : Value.t -> Value.t -> M := M.get_name (| globals, "target" |) ], make_dict [] - |), "code" |) in + |), "code" |) + |) in let _ := (* if *) M.if_then_else (| @@ -154,8 +176,10 @@ Definition prepare_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let code_address := - M.get_name (| globals, "target" |) in + let _ := M.assign_local (| + "code_address" , + M.get_name (| globals, "target" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/__init__.v b/CoqOfPython/ethereum/spurious_dragon/vm/__init__.v index cff1138..9637d09 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/__init__.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/__init__.v @@ -18,29 +18,45 @@ The abstract computer which runs the code stored in an `.fork_types.Account`. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple"; "Union" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. - -Axiom ethereum_spurious_dragon_blocks_imports : - AreImported globals "ethereum.spurious_dragon.blocks" [ "Log" ]. - -Axiom ethereum_spurious_dragon_fork_types_imports : - AreImported globals "ethereum.spurious_dragon.fork_types" [ "Address" ]. - -Axiom ethereum_spurious_dragon_state_imports : - AreImported globals "ethereum.spurious_dragon.state" [ "State"; "account_exists_and_is_empty" ]. - -Axiom ethereum_spurious_dragon_vm_precompiled_contracts_imports : - AreImported globals "ethereum.spurious_dragon.vm.precompiled_contracts" [ "RIPEMD160_ADDRESS" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". + +Axiom ethereum_spurious_dragon_blocks_imports_Log : + IsImported globals "ethereum.spurious_dragon.blocks" "Log". + +Axiom ethereum_spurious_dragon_fork_types_imports_Address : + IsImported globals "ethereum.spurious_dragon.fork_types" "Address". + +Axiom ethereum_spurious_dragon_state_imports_State : + IsImported globals "ethereum.spurious_dragon.state" "State". +Axiom ethereum_spurious_dragon_state_imports_account_exists_and_is_empty : + IsImported globals "ethereum.spurious_dragon.state" "account_exists_and_is_empty". + +Axiom ethereum_spurious_dragon_vm_precompiled_contracts_imports_RIPEMD160_ADDRESS : + IsImported globals "ethereum.spurious_dragon.vm.precompiled_contracts" "RIPEMD160_ADDRESS". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/exceptions.v b/CoqOfPython/ethereum/spurious_dragon/vm/exceptions.v index aa6a22c..5caf2c5 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/exceptions.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/exceptions.v @@ -17,8 +17,8 @@ Introduction Exceptions which cause the EVM to halt exceptionally. ". -Axiom ethereum_exceptions_imports : - AreImported globals "ethereum.exceptions" [ "EthereumException" ]. +Axiom ethereum_exceptions_imports_EthereumException : + IsImported globals "ethereum.exceptions" "EthereumException". Definition ExceptionalHalt : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/gas.v b/CoqOfPython/ethereum/spurious_dragon/vm/gas.v index 7a7bcbe..6f64c28 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/gas.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/gas.v @@ -17,26 +17,32 @@ Introduction EVM gas constants and calculators. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Tuple" ]. +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_trace_imports : - AreImported globals "ethereum.trace" [ "GasAndRefund"; "evm_trace" ]. +Axiom ethereum_trace_imports_GasAndRefund : + IsImported globals "ethereum.trace" "GasAndRefund". +Axiom ethereum_trace_imports_evm_trace : + IsImported globals "ethereum.trace" "evm_trace". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_spurious_dragon_vm_imports : - AreImported globals "ethereum.spurious_dragon.vm" [ "Evm" ]. +Axiom ethereum_spurious_dragon_vm_imports_Evm : + IsImported globals "ethereum.spurious_dragon.vm" "Evm". -Axiom ethereum_spurious_dragon_vm_exceptions_imports : - AreImported globals "ethereum.spurious_dragon.vm.exceptions" [ "OutOfGasError" ]. +Axiom ethereum_spurious_dragon_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.spurious_dragon.vm.exceptions" "OutOfGasError". Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -522,7 +528,8 @@ Definition calculate_memory_gas_cost : Value.t -> Value.t -> M := total_gas_cost : `ethereum.base_types.Uint` The gas cost for storing data in memory. " in - let size_in_words := + let _ := M.assign_local (| + "size_in_words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -532,25 +539,32 @@ Definition calculate_memory_gas_cost : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let linear_cost := + |) + |) in + let _ := M.assign_local (| + "linear_cost" , BinOp.mult (| M.get_name (| globals, "size_in_words" |), M.get_name (| globals, "GAS_MEMORY" |) - |) in - let quadratic_cost := + |) + |) in + let _ := M.assign_local (| + "quadratic_cost" , BinOp.floor_div (| BinOp.pow (| M.get_name (| globals, "size_in_words" |), Constant.int 2 |), Constant.int 512 - |) in - let total_gas_cost := + |) + |) in + let _ := M.assign_local (| + "total_gas_cost" , BinOp.add (| M.get_name (| globals, "linear_cost" |), M.get_name (| globals, "quadratic_cost" |) - |) in + |) + |) in (* At stmt: unsupported node type: Try *) M.pure Constant.None_)). @@ -572,23 +586,28 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := ------- extend_memory: `ExtendMemory` " in - let size_to_extend := + let _ := M.assign_local (| + "size_to_extend" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in - let to_be_paid := + |) + |) in + let _ := M.assign_local (| + "to_be_paid" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in - let current_size := + |) + |) in + let _ := M.assign_local (| + "current_size" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -601,7 +620,8 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ], @@ -622,15 +642,18 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let before_size := + let _ := M.assign_local (| + "before_size" , M.call (| M.get_name (| globals, "ceil32" |), make_list [ M.get_name (| globals, "current_size" |) ], make_dict [] - |) in - let after_size := + |) + |) in + let _ := M.assign_local (| + "after_size" , M.call (| M.get_name (| globals, "ceil32" |), make_list [ @@ -652,7 +675,8 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -668,42 +692,46 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let size_to_extend := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "size_to_extend", BinOp.sub (| M.get_name (| globals, "after_size" |), M.get_name (| globals, "before_size" |) |) - BinOp.sub (| - M.get_name (| globals, "after_size" |), - M.get_name (| globals, "before_size" |) - |) in - let already_paid := + |) in + let _ := M.assign_local (| + "already_paid" , M.call (| M.get_name (| globals, "calculate_memory_gas_cost" |), make_list [ M.get_name (| globals, "before_size" |) ], make_dict [] - |) in - let total_cost := + |) + |) in + let _ := M.assign_local (| + "total_cost" , M.call (| M.get_name (| globals, "calculate_memory_gas_cost" |), make_list [ M.get_name (| globals, "after_size" |) ], make_dict [] - |) in - let to_be_paid := BinOp.add + |) + |) in + let _ := M.assign_op_local (| + BinOp.add, + "to_be_paid", BinOp.sub (| M.get_name (| globals, "total_cost" |), M.get_name (| globals, "already_paid" |) |) - BinOp.sub (| - M.get_name (| globals, "total_cost" |), - M.get_name (| globals, "already_paid" |) - |) in - let current_size := - M.get_name (| globals, "after_size" |) in + |) in + let _ := M.assign_local (| + "current_size" , + M.get_name (| globals, "after_size" |) + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -750,7 +778,8 @@ Definition calculate_message_call_gas : Value.t -> Value.t -> M := ------- message_call_gas: `MessageCallGas` " in - let call_stipend := + let _ := M.assign_local (| + "call_stipend" , (* if *) M.if_then_else (| Compare.eq (| @@ -769,7 +798,8 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "call_stipend" |) - )) |) in + )) |) + |) in let _ := (* if *) M.if_then_else (| @@ -803,7 +833,8 @@ M.get_name (| globals, "call_stipend" |) )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -823,7 +854,8 @@ M.get_name (| globals, "call_stipend" |) |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "MessageCallGas" |), diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/__init__.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/__init__.v index 2c3e746..a4fd34b 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/__init__.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/__init__.v @@ -20,44 +20,46 @@ implementations. (* At top_level_stmt: unsupported node type: Import *) -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict" ]. +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". -Axiom ethereum_spurious_dragon_vm_instructions_imports : - AreImported globals "ethereum.spurious_dragon.vm.instructions" [ "arithmetic" ]. +Axiom ethereum_spurious_dragon_vm_instructions_imports_arithmetic : + IsImported globals "ethereum.spurious_dragon.vm.instructions" "arithmetic". -Axiom ethereum_spurious_dragon_vm_instructions_imports : - AreImported globals "ethereum.spurious_dragon.vm.instructions" [ "bitwise" ]. +Axiom ethereum_spurious_dragon_vm_instructions_imports_bitwise : + IsImported globals "ethereum.spurious_dragon.vm.instructions" "bitwise". -Axiom ethereum_spurious_dragon_vm_instructions_imports : - AreImported globals "ethereum.spurious_dragon.vm.instructions" [ "block" ]. +Axiom ethereum_spurious_dragon_vm_instructions_imports_block : + IsImported globals "ethereum.spurious_dragon.vm.instructions" "block". -Axiom ethereum_spurious_dragon_vm_instructions_imports : - AreImported globals "ethereum.spurious_dragon.vm.instructions" [ "comparison" ]. +Axiom ethereum_spurious_dragon_vm_instructions_imports_comparison : + IsImported globals "ethereum.spurious_dragon.vm.instructions" "comparison". -Axiom ethereum_spurious_dragon_vm_instructions_imports : - AreImported globals "ethereum.spurious_dragon.vm.instructions" [ "control_flow" ]. +Axiom ethereum_spurious_dragon_vm_instructions_imports_control_flow : + IsImported globals "ethereum.spurious_dragon.vm.instructions" "control_flow". -Axiom ethereum_spurious_dragon_vm_instructions_imports : - AreImported globals "ethereum.spurious_dragon.vm.instructions" [ "environment" ]. +Axiom ethereum_spurious_dragon_vm_instructions_imports_environment : + IsImported globals "ethereum.spurious_dragon.vm.instructions" "environment". -Axiom ethereum_spurious_dragon_vm_instructions_imports : - AreImported globals "ethereum.spurious_dragon.vm.instructions" [ "keccak" ]. +Axiom ethereum_spurious_dragon_vm_instructions_imports_keccak : + IsImported globals "ethereum.spurious_dragon.vm.instructions" "keccak". -Axiom ethereum_spurious_dragon_vm_instructions_imports : - AreImported globals "ethereum.spurious_dragon.vm.instructions" [ "log" ]. +Axiom ethereum_spurious_dragon_vm_instructions_imports_log : + IsImported globals "ethereum.spurious_dragon.vm.instructions" "log". -Axiom ethereum_spurious_dragon_vm_instructions_imports : - AreImported globals "ethereum.spurious_dragon.vm.instructions" [ "memory" ]. +Axiom ethereum_spurious_dragon_vm_instructions_imports_memory : + IsImported globals "ethereum.spurious_dragon.vm.instructions" "memory". -Axiom ethereum_spurious_dragon_vm_instructions_imports : - AreImported globals "ethereum.spurious_dragon.vm.instructions" [ "stack" ]. +Axiom ethereum_spurious_dragon_vm_instructions_imports_stack : + IsImported globals "ethereum.spurious_dragon.vm.instructions" "stack". -Axiom ethereum_spurious_dragon_vm_instructions_imports : - AreImported globals "ethereum.spurious_dragon.vm.instructions" [ "storage" ]. +Axiom ethereum_spurious_dragon_vm_instructions_imports_storage : + IsImported globals "ethereum.spurious_dragon.vm.instructions" "storage". -Axiom ethereum_spurious_dragon_vm_instructions_imports : - AreImported globals "ethereum.spurious_dragon.vm.instructions" [ "system" ]. +Axiom ethereum_spurious_dragon_vm_instructions_imports_system : + IsImported globals "ethereum.spurious_dragon.vm.instructions" "system". Definition Ops : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/arithmetic.v index f0df563..2256f4d 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/arithmetic.v @@ -17,20 +17,38 @@ Introduction Implementations of the EVM Arithmetic instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U255_CEIL_VALUE"; "U256"; "U256_CEIL_VALUE"; "Uint" ]. +Axiom ethereum_base_types_imports_U255_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U255_CEIL_VALUE". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_U256_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U256_CEIL_VALUE". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "get_sign" ]. +Axiom ethereum_utils_numeric_imports_get_sign : + IsImported globals "ethereum.utils.numeric" "get_sign". -Axiom ethereum_spurious_dragon_vm_imports : - AreImported globals "ethereum.spurious_dragon.vm" [ "Evm" ]. +Axiom ethereum_spurious_dragon_vm_imports_Evm : + IsImported globals "ethereum.spurious_dragon.vm" "Evm". -Axiom ethereum_spurious_dragon_vm_gas_imports : - AreImported globals "ethereum.spurious_dragon.vm.gas" [ "GAS_EXPONENTIATION"; "GAS_EXPONENTIATION_PER_BYTE"; "GAS_LOW"; "GAS_MID"; "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_spurious_dragon_vm_gas_imports_GAS_EXPONENTIATION : + IsImported globals "ethereum.spurious_dragon.vm.gas" "GAS_EXPONENTIATION". +Axiom ethereum_spurious_dragon_vm_gas_imports_GAS_EXPONENTIATION_PER_BYTE : + IsImported globals "ethereum.spurious_dragon.vm.gas" "GAS_EXPONENTIATION_PER_BYTE". +Axiom ethereum_spurious_dragon_vm_gas_imports_GAS_LOW : + IsImported globals "ethereum.spurious_dragon.vm.gas" "GAS_LOW". +Axiom ethereum_spurious_dragon_vm_gas_imports_GAS_MID : + IsImported globals "ethereum.spurious_dragon.vm.gas" "GAS_MID". +Axiom ethereum_spurious_dragon_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.spurious_dragon.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_spurious_dragon_vm_gas_imports_charge_gas : + IsImported globals "ethereum.spurious_dragon.vm.gas" "charge_gas". -Axiom ethereum_spurious_dragon_vm_stack_imports : - AreImported globals "ethereum.spurious_dragon.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_spurious_dragon_vm_stack_imports_pop : + IsImported globals "ethereum.spurious_dragon.vm.stack" "pop". +Axiom ethereum_spurious_dragon_vm_stack_imports_push : + IsImported globals "ethereum.spurious_dragon.vm.stack" "push". Definition add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,22 +63,26 @@ Definition add : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -69,14 +91,16 @@ Definition add : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "x" |), "wrapping_add" |), make_list [ M.get_name (| globals, "y" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -105,22 +129,26 @@ Definition sub : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -129,14 +157,16 @@ Definition sub : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "x" |), "wrapping_sub" |), make_list [ M.get_name (| globals, "y" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -165,22 +195,26 @@ Definition mul : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -189,14 +223,16 @@ Definition mul : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "x" |), "wrapping_mul" |), make_list [ M.get_name (| globals, "y" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -225,22 +261,26 @@ Definition div : Value.t -> Value.t -> M := The current EVM frame. " in - let dividend := + let _ := M.assign_local (| + "dividend" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let divisor := + |) + |) in + let _ := M.assign_local (| + "divisor" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -258,22 +298,26 @@ Definition div : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let quotient := + let _ := M.assign_local (| + "quotient" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let quotient := + let _ := M.assign_local (| + "quotient" , BinOp.floor_div (| M.get_name (| globals, "dividend" |), M.get_name (| globals, "divisor" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -304,7 +348,8 @@ Definition sdiv : Value.t -> Value.t -> M := The current EVM frame. " in - let dividend := + let _ := M.assign_local (| + "dividend" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -315,8 +360,10 @@ Definition sdiv : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let divisor := + |) + |) in + let _ := M.assign_local (| + "divisor" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -327,7 +374,8 @@ Definition sdiv : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -345,8 +393,10 @@ Definition sdiv : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let quotient := - Constant.int 0 in + let _ := M.assign_local (| + "quotient" , + Constant.int 0 + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -367,12 +417,15 @@ Definition sdiv : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let quotient := - UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in + let _ := M.assign_local (| + "quotient" , + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let sign := + let _ := M.assign_local (| + "sign" , M.call (| M.get_name (| globals, "get_sign" |), make_list [ @@ -382,8 +435,10 @@ Definition sdiv : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let quotient := + |) + |) in + let _ := M.assign_local (| + "quotient" , BinOp.mult (| M.get_name (| globals, "sign" |), BinOp.floor_div (| @@ -402,7 +457,8 @@ Definition sdiv : Value.t -> Value.t -> M := make_dict [] |) |) - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -428,7 +484,7 @@ Definition sdiv : Value.t -> Value.t -> M := |) in M.pure Constant.None_)). -Definition mod : Value.t -> Value.t -> M := +Definition mod_ : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in let _ := Constant.str " @@ -441,22 +497,26 @@ Definition mod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -474,22 +534,26 @@ Definition mod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let remainder := + let _ := M.assign_local (| + "remainder" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let remainder := + let _ := M.assign_local (| + "remainder" , BinOp.mod_ (| M.get_name (| globals, "x" |), M.get_name (| globals, "y" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -520,7 +584,8 @@ Definition smod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -531,8 +596,10 @@ Definition smod : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -543,7 +610,8 @@ Definition smod : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -561,12 +629,15 @@ Definition smod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let remainder := - Constant.int 0 in + let _ := M.assign_local (| + "remainder" , + Constant.int 0 + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let remainder := + let _ := M.assign_local (| + "remainder" , BinOp.mult (| M.call (| M.get_name (| globals, "get_sign" |), @@ -591,7 +662,8 @@ Definition smod : Value.t -> Value.t -> M := make_dict [] |) |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -628,7 +700,8 @@ Definition addmod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -641,8 +714,10 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -655,8 +730,10 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let z := + |) + |) in + let _ := M.assign_local (| + "z" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -669,7 +746,8 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -687,18 +765,21 @@ Definition addmod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -711,7 +792,8 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -742,7 +824,8 @@ Definition mulmod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -755,8 +838,10 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -769,8 +854,10 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let z := + |) + |) in + let _ := M.assign_local (| + "z" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -783,7 +870,8 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -801,18 +889,21 @@ Definition mulmod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -825,7 +916,8 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -856,7 +948,8 @@ Definition exp : Value.t -> Value.t -> M := The current EVM frame. " in - let base := + let _ := M.assign_local (| + "base" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -869,8 +962,10 @@ Definition exp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exponent := + |) + |) in + let _ := M.assign_local (| + "exponent" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -883,21 +978,26 @@ Definition exp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exponent_bits := + |) + |) in + let _ := M.assign_local (| + "exponent_bits" , M.call (| M.get_field (| M.get_name (| globals, "exponent" |), "bit_length" |), make_list [], make_dict [] - |) in - let exponent_bytes := + |) + |) in + let _ := M.assign_local (| + "exponent_bytes" , BinOp.floor_div (| BinOp.add (| M.get_name (| globals, "exponent_bits" |), Constant.int 7 |), Constant.int 8 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -912,7 +1012,8 @@ Definition exp : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -927,7 +1028,8 @@ Definition exp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -956,22 +1058,26 @@ Definition signextend : Value.t -> Value.t -> M := The current EVM frame. " in - let byte_num := + let _ := M.assign_local (| + "byte_num" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -989,12 +1095,15 @@ Definition signextend : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := - M.get_name (| globals, "value" |) in + let _ := M.assign_local (| + "result" , + M.get_name (| globals, "value" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let value_bytes := + let _ := M.assign_local (| + "value_bytes" , M.call (| M.get_name (| globals, "bytes" |), make_list [ @@ -1005,8 +1114,10 @@ Definition signextend : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let value_bytes := + |) + |) in + let _ := M.assign_local (| + "value_bytes" , M.slice (| M.get_name (| globals, "value_bytes" |), BinOp.sub (| @@ -1021,15 +1132,18 @@ Definition signextend : Value.t -> Value.t -> M := |), Constant.None_, Constant.None_ - |) in - let sign_bit := + |) + |) in + let _ := M.assign_local (| + "sign_bit" , BinOp.r_shift (| M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), Constant.int 7 - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1039,26 +1153,31 @@ Definition signextend : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "value_bytes" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let num_bytes_prepend := + let _ := M.assign_local (| + "num_bytes_prepend" , BinOp.sub (| Constant.int 32, BinOp.add (| M.get_name (| globals, "byte_num" |), Constant.int 1 |) - |) in - let result := + |) + |) in + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -1079,7 +1198,8 @@ Definition signextend : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/bitwise.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/bitwise.v index f364066..fc29c9b 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/bitwise.v @@ -17,17 +17,21 @@ Introduction Implementations of the EVM bitwise instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_spurious_dragon_vm_imports : - AreImported globals "ethereum.spurious_dragon.vm" [ "Evm" ]. +Axiom ethereum_spurious_dragon_vm_imports_Evm : + IsImported globals "ethereum.spurious_dragon.vm" "Evm". -Axiom ethereum_spurious_dragon_vm_gas_imports : - AreImported globals "ethereum.spurious_dragon.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_spurious_dragon_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.spurious_dragon.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_spurious_dragon_vm_gas_imports_charge_gas : + IsImported globals "ethereum.spurious_dragon.vm.gas" "charge_gas". -Axiom ethereum_spurious_dragon_vm_stack_imports : - AreImported globals "ethereum.spurious_dragon.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_spurious_dragon_vm_stack_imports_pop : + IsImported globals "ethereum.spurious_dragon.vm.stack" "pop". +Axiom ethereum_spurious_dragon_vm_stack_imports_push : + IsImported globals "ethereum.spurious_dragon.vm.stack" "push". Definition bitwise_and : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,22 +46,26 @@ Definition bitwise_and : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -97,22 +105,26 @@ Definition bitwise_or : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -152,22 +164,26 @@ Definition bitwise_xor : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -207,14 +223,16 @@ Definition bitwise_not : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -252,22 +270,26 @@ Definition get_byte : Value.t -> Value.t -> M := The current EVM frame. " in - let byte_index := + let _ := M.assign_local (| + "byte_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let word := + |) + |) in + let _ := M.assign_local (| + "word" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -285,43 +307,53 @@ Definition get_byte : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let extra_bytes_to_right := + let _ := M.assign_local (| + "extra_bytes_to_right" , BinOp.sub (| Constant.int 31, M.get_name (| globals, "byte_index" |) - |) in - let word := + |) + |) in + let _ := M.assign_local (| + "word" , BinOp.r_shift (| M.get_name (| globals, "word" |), BinOp.mult (| M.get_name (| globals, "extra_bytes_to_right" |), Constant.int 8 |) - |) in - let word := + |) + |) in + let _ := M.assign_local (| + "word" , BinOp.bit_and (| M.get_name (| globals, "word" |), Constant.int 255 - |) in - let result := + |) + |) in + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ M.get_name (| globals, "word" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/block.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/block.v index db5c548..d8850a8 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/block.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/block.v @@ -17,17 +17,23 @@ Introduction Implementations of the EVM block instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_spurious_dragon_vm_imports : - AreImported globals "ethereum.spurious_dragon.vm" [ "Evm" ]. +Axiom ethereum_spurious_dragon_vm_imports_Evm : + IsImported globals "ethereum.spurious_dragon.vm" "Evm". -Axiom ethereum_spurious_dragon_vm_gas_imports : - AreImported globals "ethereum.spurious_dragon.vm.gas" [ "GAS_BASE"; "GAS_BLOCK_HASH"; "charge_gas" ]. +Axiom ethereum_spurious_dragon_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.spurious_dragon.vm.gas" "GAS_BASE". +Axiom ethereum_spurious_dragon_vm_gas_imports_GAS_BLOCK_HASH : + IsImported globals "ethereum.spurious_dragon.vm.gas" "GAS_BLOCK_HASH". +Axiom ethereum_spurious_dragon_vm_gas_imports_charge_gas : + IsImported globals "ethereum.spurious_dragon.vm.gas" "charge_gas". -Axiom ethereum_spurious_dragon_vm_stack_imports : - AreImported globals "ethereum.spurious_dragon.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_spurious_dragon_vm_stack_imports_pop : + IsImported globals "ethereum.spurious_dragon.vm.stack" "pop". +Axiom ethereum_spurious_dragon_vm_stack_imports_push : + IsImported globals "ethereum.spurious_dragon.vm.stack" "push". Definition block_hash : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,14 +48,16 @@ Definition block_hash : Value.t -> Value.t -> M := The current EVM frame. " in - let block_number := + let _ := M.assign_local (| + "block_number" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -78,19 +86,23 @@ Definition block_hash : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let hash := - Constant.bytes "00" in + let _ := M.assign_local (| + "hash" , + Constant.bytes "00" + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let hash := + let _ := M.assign_local (| + "hash" , M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), M.get_name (| globals, "block_number" |) |) |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/comparison.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/comparison.v index 3e22c3e..e7f431c 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/comparison.v @@ -17,17 +17,21 @@ Introduction Implementations of the EVM Comparison instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_spurious_dragon_vm_imports : - AreImported globals "ethereum.spurious_dragon.vm" [ "Evm" ]. +Axiom ethereum_spurious_dragon_vm_imports_Evm : + IsImported globals "ethereum.spurious_dragon.vm" "Evm". -Axiom ethereum_spurious_dragon_vm_gas_imports : - AreImported globals "ethereum.spurious_dragon.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_spurious_dragon_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.spurious_dragon.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_spurious_dragon_vm_gas_imports_charge_gas : + IsImported globals "ethereum.spurious_dragon.vm.gas" "charge_gas". -Axiom ethereum_spurious_dragon_vm_stack_imports : - AreImported globals "ethereum.spurious_dragon.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_spurious_dragon_vm_stack_imports_pop : + IsImported globals "ethereum.spurious_dragon.vm.stack" "pop". +Axiom ethereum_spurious_dragon_vm_stack_imports_push : + IsImported globals "ethereum.spurious_dragon.vm.stack" "push". Definition less_than : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,22 +46,26 @@ Definition less_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -66,7 +74,8 @@ Definition less_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -76,7 +85,8 @@ Definition less_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -104,7 +114,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -115,8 +126,10 @@ Definition signed_less_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -127,7 +140,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -136,7 +150,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -146,7 +161,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -175,22 +191,26 @@ Definition greater_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -199,7 +219,8 @@ Definition greater_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -209,7 +230,8 @@ Definition greater_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -237,7 +259,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -248,8 +271,10 @@ Definition signed_greater_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -260,7 +285,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -269,7 +295,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -279,7 +306,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -308,22 +336,26 @@ Definition equal : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -332,7 +364,8 @@ Definition equal : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -342,7 +375,8 @@ Definition equal : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -371,14 +405,16 @@ Definition is_zero : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -387,7 +423,8 @@ Definition is_zero : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -397,7 +434,8 @@ Definition is_zero : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/control_flow.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/control_flow.v index 4d7ebd5..f96d87f 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/control_flow.v @@ -17,20 +17,32 @@ Introduction Implementations of the EVM control flow instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_spurious_dragon_vm_gas_imports : - AreImported globals "ethereum.spurious_dragon.vm.gas" [ "GAS_BASE"; "GAS_HIGH"; "GAS_JUMPDEST"; "GAS_MID"; "charge_gas" ]. +Axiom ethereum_spurious_dragon_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.spurious_dragon.vm.gas" "GAS_BASE". +Axiom ethereum_spurious_dragon_vm_gas_imports_GAS_HIGH : + IsImported globals "ethereum.spurious_dragon.vm.gas" "GAS_HIGH". +Axiom ethereum_spurious_dragon_vm_gas_imports_GAS_JUMPDEST : + IsImported globals "ethereum.spurious_dragon.vm.gas" "GAS_JUMPDEST". +Axiom ethereum_spurious_dragon_vm_gas_imports_GAS_MID : + IsImported globals "ethereum.spurious_dragon.vm.gas" "GAS_MID". +Axiom ethereum_spurious_dragon_vm_gas_imports_charge_gas : + IsImported globals "ethereum.spurious_dragon.vm.gas" "charge_gas". -Axiom ethereum_spurious_dragon_vm_imports : - AreImported globals "ethereum.spurious_dragon.vm" [ "Evm" ]. +Axiom ethereum_spurious_dragon_vm_imports_Evm : + IsImported globals "ethereum.spurious_dragon.vm" "Evm". -Axiom ethereum_spurious_dragon_vm_exceptions_imports : - AreImported globals "ethereum.spurious_dragon.vm.exceptions" [ "InvalidJumpDestError" ]. +Axiom ethereum_spurious_dragon_vm_exceptions_imports_InvalidJumpDestError : + IsImported globals "ethereum.spurious_dragon.vm.exceptions" "InvalidJumpDestError". -Axiom ethereum_spurious_dragon_vm_stack_imports : - AreImported globals "ethereum.spurious_dragon.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_spurious_dragon_vm_stack_imports_pop : + IsImported globals "ethereum.spurious_dragon.vm.stack" "pop". +Axiom ethereum_spurious_dragon_vm_stack_imports_push : + IsImported globals "ethereum.spurious_dragon.vm.stack" "push". Definition stop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -69,7 +81,8 @@ Definition jump : Value.t -> Value.t -> M := The current EVM frame. " in - let jump_dest := + let _ := M.assign_local (| + "jump_dest" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -82,7 +95,8 @@ Definition jump : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -132,7 +146,8 @@ Definition jumpi : Value.t -> Value.t -> M := The current EVM frame. " in - let jump_dest := + let _ := M.assign_local (| + "jump_dest" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -145,15 +160,18 @@ Definition jumpi : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let conditional_value := + |) + |) in + let _ := M.assign_local (| + "conditional_value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -171,11 +189,13 @@ Definition jumpi : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let destination := + let _ := M.assign_local (| + "destination" , BinOp.add (| M.get_field (| M.get_name (| globals, "evm" |), "pc" |), Constant.int 1 - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -192,8 +212,10 @@ Definition jumpi : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let destination := - M.get_name (| globals, "jump_dest" |) in + let _ := M.assign_local (| + "destination" , + M.get_name (| globals, "jump_dest" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/environment.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/environment.v index 01557ae..00c40fe 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/environment.v @@ -17,29 +17,47 @@ Introduction Implementations of the EVM environment related instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. - -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. - -Axiom ethereum_spurious_dragon_state_imports : - AreImported globals "ethereum.spurious_dragon.state" [ "get_account" ]. - -Axiom ethereum_spurious_dragon_utils_address_imports : - AreImported globals "ethereum.spurious_dragon.utils.address" [ "to_address" ]. - -Axiom ethereum_spurious_dragon_vm_memory_imports : - AreImported globals "ethereum.spurious_dragon.vm.memory" [ "buffer_read"; "memory_write" ]. - -Axiom ethereum_spurious_dragon_vm_imports : - AreImported globals "ethereum.spurious_dragon.vm" [ "Evm" ]. - -Axiom ethereum_spurious_dragon_vm_gas_imports : - AreImported globals "ethereum.spurious_dragon.vm.gas" [ "GAS_BALANCE"; "GAS_BASE"; "GAS_COPY"; "GAS_EXTERNAL"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. - -Axiom ethereum_spurious_dragon_vm_stack_imports : - AreImported globals "ethereum.spurious_dragon.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". + +Axiom ethereum_spurious_dragon_state_imports_get_account : + IsImported globals "ethereum.spurious_dragon.state" "get_account". + +Axiom ethereum_spurious_dragon_utils_address_imports_to_address : + IsImported globals "ethereum.spurious_dragon.utils.address" "to_address". + +Axiom ethereum_spurious_dragon_vm_memory_imports_buffer_read : + IsImported globals "ethereum.spurious_dragon.vm.memory" "buffer_read". +Axiom ethereum_spurious_dragon_vm_memory_imports_memory_write : + IsImported globals "ethereum.spurious_dragon.vm.memory" "memory_write". + +Axiom ethereum_spurious_dragon_vm_imports_Evm : + IsImported globals "ethereum.spurious_dragon.vm" "Evm". + +Axiom ethereum_spurious_dragon_vm_gas_imports_GAS_BALANCE : + IsImported globals "ethereum.spurious_dragon.vm.gas" "GAS_BALANCE". +Axiom ethereum_spurious_dragon_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.spurious_dragon.vm.gas" "GAS_BASE". +Axiom ethereum_spurious_dragon_vm_gas_imports_GAS_COPY : + IsImported globals "ethereum.spurious_dragon.vm.gas" "GAS_COPY". +Axiom ethereum_spurious_dragon_vm_gas_imports_GAS_EXTERNAL : + IsImported globals "ethereum.spurious_dragon.vm.gas" "GAS_EXTERNAL". +Axiom ethereum_spurious_dragon_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.spurious_dragon.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_spurious_dragon_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.spurious_dragon.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_spurious_dragon_vm_gas_imports_charge_gas : + IsImported globals "ethereum.spurious_dragon.vm.gas" "charge_gas". + +Axiom ethereum_spurious_dragon_vm_stack_imports_pop : + IsImported globals "ethereum.spurious_dragon.vm.stack" "pop". +Axiom ethereum_spurious_dragon_vm_stack_imports_push : + IsImported globals "ethereum.spurious_dragon.vm.stack" "push". Definition address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -95,7 +113,8 @@ Definition balance : Value.t -> Value.t -> M := The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -108,7 +127,8 @@ Definition balance : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -117,7 +137,8 @@ Definition balance : Value.t -> Value.t -> M := ], make_dict [] |) in - let balance := + let _ := M.assign_local (| + "balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -125,7 +146,8 @@ Definition balance : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -275,14 +297,16 @@ Definition calldataload : Value.t -> Value.t -> M := The current EVM frame. " in - let start_index := + let _ := M.assign_local (| + "start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -291,7 +315,8 @@ Definition calldataload : Value.t -> Value.t -> M := ], make_dict [] |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -306,7 +331,8 @@ Definition calldataload : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -391,31 +417,38 @@ Definition calldatacopy : Value.t -> Value.t -> M := The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let data_start_index := + |) + |) in + let _ := M.assign_local (| + "data_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -431,13 +464,17 @@ Definition calldatacopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -447,7 +484,8 @@ Definition calldatacopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -470,7 +508,8 @@ Definition calldatacopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -479,7 +518,8 @@ Definition calldatacopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -559,31 +599,38 @@ Definition codecopy : Value.t -> Value.t -> M := The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let code_start_index := + |) + |) in + let _ := M.assign_local (| + "code_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -599,13 +646,17 @@ Definition codecopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -615,7 +666,8 @@ Definition codecopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -638,7 +690,8 @@ Definition codecopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -647,7 +700,8 @@ Definition codecopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -718,7 +772,8 @@ Definition extcodesize : Value.t -> Value.t -> M := The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -731,7 +786,8 @@ Definition extcodesize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -740,7 +796,8 @@ Definition extcodesize : Value.t -> Value.t -> M := ], make_dict [] |) in - let codesize := + let _ := M.assign_local (| + "codesize" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -760,7 +817,8 @@ Definition extcodesize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -788,7 +846,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -801,32 +860,40 @@ Definition extcodecopy : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let memory_start_index := + |) + |) in + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let code_start_index := + |) + |) in + let _ := M.assign_local (| + "code_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -842,13 +909,17 @@ Definition extcodecopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -858,7 +929,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -881,7 +953,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let code := + let _ := M.assign_local (| + "code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -889,8 +962,10 @@ Definition extcodecopy : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |), "code" |) in - let value := + |), "code" |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -899,7 +974,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/keccak.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/keccak.v index 41dbfda..b4aecb5 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/keccak.v @@ -17,26 +17,36 @@ Introduction Implementations of the EVM keccak instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_spurious_dragon_vm_imports : - AreImported globals "ethereum.spurious_dragon.vm" [ "Evm" ]. +Axiom ethereum_spurious_dragon_vm_imports_Evm : + IsImported globals "ethereum.spurious_dragon.vm" "Evm". -Axiom ethereum_spurious_dragon_vm_gas_imports : - AreImported globals "ethereum.spurious_dragon.vm.gas" [ "GAS_KECCAK256"; "GAS_KECCAK256_WORD"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_spurious_dragon_vm_gas_imports_GAS_KECCAK256 : + IsImported globals "ethereum.spurious_dragon.vm.gas" "GAS_KECCAK256". +Axiom ethereum_spurious_dragon_vm_gas_imports_GAS_KECCAK256_WORD : + IsImported globals "ethereum.spurious_dragon.vm.gas" "GAS_KECCAK256_WORD". +Axiom ethereum_spurious_dragon_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.spurious_dragon.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_spurious_dragon_vm_gas_imports_charge_gas : + IsImported globals "ethereum.spurious_dragon.vm.gas" "charge_gas". -Axiom ethereum_spurious_dragon_vm_memory_imports : - AreImported globals "ethereum.spurious_dragon.vm.memory" [ "memory_read_bytes" ]. +Axiom ethereum_spurious_dragon_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.spurious_dragon.vm.memory" "memory_read_bytes". -Axiom ethereum_spurious_dragon_vm_stack_imports : - AreImported globals "ethereum.spurious_dragon.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_spurious_dragon_vm_stack_imports_pop : + IsImported globals "ethereum.spurious_dragon.vm.stack" "pop". +Axiom ethereum_spurious_dragon_vm_stack_imports_push : + IsImported globals "ethereum.spurious_dragon.vm.stack" "push". Definition keccak : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -53,23 +63,28 @@ Definition keccak : Value.t -> Value.t -> M := The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -85,13 +100,17 @@ Definition keccak : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let word_gas_cost := + |) + |) in + let _ := M.assign_local (| + "word_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_KECCAK256_WORD" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -101,7 +120,8 @@ Definition keccak : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -124,7 +144,8 @@ Definition keccak : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let data := + let _ := M.assign_local (| + "data" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -133,15 +154,18 @@ Definition keccak : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in - let hash := + |) + |) in + let _ := M.assign_local (| + "hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "data" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/log.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/log.v index 8aa3ef5..db24bd8 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/log.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/log.v @@ -17,26 +17,34 @@ Introduction Implementations of the EVM logging instructions. ". -Axiom functools_imports : - AreImported globals "functools" [ "partial" ]. +Axiom functools_imports_partial : + IsImported globals "functools" "partial". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_spurious_dragon_blocks_imports : - AreImported globals "ethereum.spurious_dragon.blocks" [ "Log" ]. +Axiom ethereum_spurious_dragon_blocks_imports_Log : + IsImported globals "ethereum.spurious_dragon.blocks" "Log". -Axiom ethereum_spurious_dragon_vm_imports : - AreImported globals "ethereum.spurious_dragon.vm" [ "Evm" ]. +Axiom ethereum_spurious_dragon_vm_imports_Evm : + IsImported globals "ethereum.spurious_dragon.vm" "Evm". -Axiom ethereum_spurious_dragon_vm_gas_imports : - AreImported globals "ethereum.spurious_dragon.vm.gas" [ "GAS_LOG"; "GAS_LOG_DATA"; "GAS_LOG_TOPIC"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_spurious_dragon_vm_gas_imports_GAS_LOG : + IsImported globals "ethereum.spurious_dragon.vm.gas" "GAS_LOG". +Axiom ethereum_spurious_dragon_vm_gas_imports_GAS_LOG_DATA : + IsImported globals "ethereum.spurious_dragon.vm.gas" "GAS_LOG_DATA". +Axiom ethereum_spurious_dragon_vm_gas_imports_GAS_LOG_TOPIC : + IsImported globals "ethereum.spurious_dragon.vm.gas" "GAS_LOG_TOPIC". +Axiom ethereum_spurious_dragon_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.spurious_dragon.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_spurious_dragon_vm_gas_imports_charge_gas : + IsImported globals "ethereum.spurious_dragon.vm.gas" "charge_gas". -Axiom ethereum_spurious_dragon_vm_memory_imports : - AreImported globals "ethereum.spurious_dragon.vm.memory" [ "memory_read_bytes" ]. +Axiom ethereum_spurious_dragon_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.spurious_dragon.vm.memory" "memory_read_bytes". -Axiom ethereum_spurious_dragon_vm_stack_imports : - AreImported globals "ethereum.spurious_dragon.vm.stack" [ "pop" ]. +Axiom ethereum_spurious_dragon_vm_stack_imports_pop : + IsImported globals "ethereum.spurious_dragon.vm.stack" "pop". Definition log_n : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -55,24 +63,30 @@ Definition log_n : Value.t -> Value.t -> M := The number of topics to be included in the log entry. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let topics := - make_list [] in + |) + |) in + let _ := M.assign_local (| + "topics" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "_" |), @@ -84,7 +98,8 @@ Definition log_n : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let topic := + let _ := M.assign_local (| + "topic" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -95,7 +110,8 @@ Definition log_n : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "topics" |), "append" |), make_list [ @@ -109,7 +125,8 @@ Definition log_n : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let extend_memory := + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -119,7 +136,8 @@ Definition log_n : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -151,12 +169,14 @@ Definition log_n : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let log_entry := + let _ := M.assign_local (| + "log_entry" , M.call (| M.get_name (| globals, "Log" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "logs" |), BinOp.add (| diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/memory.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/memory.v index b6ed42f..a320784 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/memory.v @@ -17,20 +17,32 @@ Introduction Implementations of the EVM Memory instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". -Axiom ethereum_spurious_dragon_vm_imports : - AreImported globals "ethereum.spurious_dragon.vm" [ "Evm" ]. +Axiom ethereum_spurious_dragon_vm_imports_Evm : + IsImported globals "ethereum.spurious_dragon.vm" "Evm". -Axiom ethereum_spurious_dragon_vm_gas_imports : - AreImported globals "ethereum.spurious_dragon.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_spurious_dragon_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.spurious_dragon.vm.gas" "GAS_BASE". +Axiom ethereum_spurious_dragon_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.spurious_dragon.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_spurious_dragon_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.spurious_dragon.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_spurious_dragon_vm_gas_imports_charge_gas : + IsImported globals "ethereum.spurious_dragon.vm.gas" "charge_gas". -Axiom ethereum_spurious_dragon_vm_memory_imports : - AreImported globals "ethereum.spurious_dragon.vm.memory" [ "memory_read_bytes"; "memory_write" ]. +Axiom ethereum_spurious_dragon_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.spurious_dragon.vm.memory" "memory_read_bytes". +Axiom ethereum_spurious_dragon_vm_memory_imports_memory_write : + IsImported globals "ethereum.spurious_dragon.vm.memory" "memory_write". -Axiom ethereum_spurious_dragon_vm_stack_imports : - AreImported globals "ethereum.spurious_dragon.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_spurious_dragon_vm_stack_imports_pop : + IsImported globals "ethereum.spurious_dragon.vm.stack" "pop". +Axiom ethereum_spurious_dragon_vm_stack_imports_push : + IsImported globals "ethereum.spurious_dragon.vm.stack" "push". Definition mstore : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -46,15 +58,18 @@ Definition mstore : Value.t -> Value.t -> M := The current EVM frame. " in - let start_position := + let _ := M.assign_local (| + "start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -65,8 +80,10 @@ Definition mstore : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -88,7 +105,8 @@ Definition mstore : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -138,23 +156,28 @@ Definition mstore8 : Value.t -> Value.t -> M := The current EVM frame. " in - let start_position := + let _ := M.assign_local (| + "start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -170,7 +193,8 @@ Definition mstore8 : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -190,7 +214,8 @@ Definition mstore8 : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let normalized_bytes_value := + let _ := M.assign_local (| + "normalized_bytes_value" , M.call (| M.get_name (| globals, "Bytes" |), make_list [ @@ -202,7 +227,8 @@ Definition mstore8 : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -231,15 +257,18 @@ Definition mload : Value.t -> Value.t -> M := The current EVM frame. " in - let start_position := + let _ := M.assign_local (| + "start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -255,7 +284,8 @@ Definition mload : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -275,7 +305,8 @@ Definition mload : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -296,7 +327,8 @@ Definition mload : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/stack.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/stack.v index 04f9a66..4846fa5 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/stack.v @@ -17,26 +17,32 @@ Introduction Implementations of the EVM stack related instructions. ". -Axiom functools_imports : - AreImported globals "functools" [ "partial" ]. +Axiom functools_imports_partial : + IsImported globals "functools" "partial". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_spurious_dragon_vm_imports : - AreImported globals "ethereum.spurious_dragon.vm" [ "Evm"; "stack" ]. +Axiom ethereum_spurious_dragon_vm_imports_Evm : + IsImported globals "ethereum.spurious_dragon.vm" "Evm". +Axiom ethereum_spurious_dragon_vm_imports_stack : + IsImported globals "ethereum.spurious_dragon.vm" "stack". -Axiom ethereum_spurious_dragon_vm_exceptions_imports : - AreImported globals "ethereum.spurious_dragon.vm.exceptions" [ "StackUnderflowError" ]. +Axiom ethereum_spurious_dragon_vm_exceptions_imports_StackUnderflowError : + IsImported globals "ethereum.spurious_dragon.vm.exceptions" "StackUnderflowError". -Axiom ethereum_spurious_dragon_vm_gas_imports : - AreImported globals "ethereum.spurious_dragon.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_spurious_dragon_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.spurious_dragon.vm.gas" "GAS_BASE". +Axiom ethereum_spurious_dragon_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.spurious_dragon.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_spurious_dragon_vm_gas_imports_charge_gas : + IsImported globals "ethereum.spurious_dragon.vm.gas" "charge_gas". -Axiom ethereum_spurious_dragon_vm_memory_imports : - AreImported globals "ethereum.spurious_dragon.vm.memory" [ "buffer_read" ]. +Axiom ethereum_spurious_dragon_vm_memory_imports_buffer_read : + IsImported globals "ethereum.spurious_dragon.vm.memory" "buffer_read". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -98,7 +104,8 @@ Definition push_n : Value.t -> Value.t -> M := ], make_dict [] |) in - let data_to_push := + let _ := M.assign_local (| + "data_to_push" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -128,7 +135,8 @@ Definition push_n : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "stack" |), "push" |), make_list [ @@ -189,7 +197,8 @@ Definition dup_n : Value.t -> Value.t -> M := ], make_dict [] |) in - let data_to_duplicate := + let _ := M.assign_local (| + "data_to_duplicate" , M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| @@ -205,7 +214,8 @@ Definition dup_n : Value.t -> Value.t -> M := |), M.get_name (| globals, "item_number" |) |) - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "stack" |), "push" |), make_list [ diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/storage.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/storage.v index 0d72826..2c14d8c 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/storage.v @@ -17,17 +17,29 @@ Introduction Implementations of the EVM storage related instructions. ". -Axiom ethereum_spurious_dragon_state_imports : - AreImported globals "ethereum.spurious_dragon.state" [ "get_storage"; "set_storage" ]. +Axiom ethereum_spurious_dragon_state_imports_get_storage : + IsImported globals "ethereum.spurious_dragon.state" "get_storage". +Axiom ethereum_spurious_dragon_state_imports_set_storage : + IsImported globals "ethereum.spurious_dragon.state" "set_storage". -Axiom ethereum_spurious_dragon_vm_imports : - AreImported globals "ethereum.spurious_dragon.vm" [ "Evm" ]. +Axiom ethereum_spurious_dragon_vm_imports_Evm : + IsImported globals "ethereum.spurious_dragon.vm" "Evm". -Axiom ethereum_spurious_dragon_vm_gas_imports : - AreImported globals "ethereum.spurious_dragon.vm.gas" [ "GAS_SLOAD"; "GAS_STORAGE_CLEAR_REFUND"; "GAS_STORAGE_SET"; "GAS_STORAGE_UPDATE"; "charge_gas" ]. +Axiom ethereum_spurious_dragon_vm_gas_imports_GAS_SLOAD : + IsImported globals "ethereum.spurious_dragon.vm.gas" "GAS_SLOAD". +Axiom ethereum_spurious_dragon_vm_gas_imports_GAS_STORAGE_CLEAR_REFUND : + IsImported globals "ethereum.spurious_dragon.vm.gas" "GAS_STORAGE_CLEAR_REFUND". +Axiom ethereum_spurious_dragon_vm_gas_imports_GAS_STORAGE_SET : + IsImported globals "ethereum.spurious_dragon.vm.gas" "GAS_STORAGE_SET". +Axiom ethereum_spurious_dragon_vm_gas_imports_GAS_STORAGE_UPDATE : + IsImported globals "ethereum.spurious_dragon.vm.gas" "GAS_STORAGE_UPDATE". +Axiom ethereum_spurious_dragon_vm_gas_imports_charge_gas : + IsImported globals "ethereum.spurious_dragon.vm.gas" "charge_gas". -Axiom ethereum_spurious_dragon_vm_stack_imports : - AreImported globals "ethereum.spurious_dragon.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_spurious_dragon_vm_stack_imports_pop : + IsImported globals "ethereum.spurious_dragon.vm.stack" "pop". +Axiom ethereum_spurious_dragon_vm_stack_imports_push : + IsImported globals "ethereum.spurious_dragon.vm.stack" "push". Definition sload : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,7 +54,8 @@ Definition sload : Value.t -> Value.t -> M := The current EVM frame. " in - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -53,7 +66,8 @@ Definition sload : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -62,7 +76,8 @@ Definition sload : Value.t -> Value.t -> M := ], make_dict [] |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "get_storage" |), make_list [ @@ -71,7 +86,8 @@ Definition sload : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -99,7 +115,8 @@ Definition sstore : Value.t -> Value.t -> M := The current EVM frame. " in - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -110,16 +127,20 @@ Definition sstore : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in - let new_value := + |) + |) in + let _ := M.assign_local (| + "new_value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let current_value := + |) + |) in + let _ := M.assign_local (| + "current_value" , M.call (| M.get_name (| globals, "get_storage" |), make_list [ @@ -128,7 +149,8 @@ Definition sstore : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -146,13 +168,17 @@ Definition sstore : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let gas_cost := - M.get_name (| globals, "GAS_STORAGE_SET" |) in + let _ := M.assign_local (| + "gas_cost" , + M.get_name (| globals, "GAS_STORAGE_SET" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let gas_cost := - M.get_name (| globals, "GAS_STORAGE_UPDATE" |) in + let _ := M.assign_local (| + "gas_cost" , + M.get_name (| globals, "GAS_STORAGE_UPDATE" |) + |) in M.pure Constant.None_ )) |) in let _ := diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/system.v b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/system.v index 4a8dd1f..1bb34af 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/instructions/system.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/instructions/system.v @@ -17,29 +17,77 @@ Introduction Implementations of the EVM system related instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_spurious_dragon_fork_types_imports : - AreImported globals "ethereum.spurious_dragon.fork_types" [ "Address" ]. +Axiom ethereum_spurious_dragon_fork_types_imports_Address : + IsImported globals "ethereum.spurious_dragon.fork_types" "Address". -Axiom ethereum_spurious_dragon_state_imports : - AreImported globals "ethereum.spurious_dragon.state" [ "account_exists_and_is_empty"; "account_has_code_or_nonce"; "get_account"; "increment_nonce"; "is_account_alive"; "set_account_balance" ]. +Axiom ethereum_spurious_dragon_state_imports_account_exists_and_is_empty : + IsImported globals "ethereum.spurious_dragon.state" "account_exists_and_is_empty". +Axiom ethereum_spurious_dragon_state_imports_account_has_code_or_nonce : + IsImported globals "ethereum.spurious_dragon.state" "account_has_code_or_nonce". +Axiom ethereum_spurious_dragon_state_imports_get_account : + IsImported globals "ethereum.spurious_dragon.state" "get_account". +Axiom ethereum_spurious_dragon_state_imports_increment_nonce : + IsImported globals "ethereum.spurious_dragon.state" "increment_nonce". +Axiom ethereum_spurious_dragon_state_imports_is_account_alive : + IsImported globals "ethereum.spurious_dragon.state" "is_account_alive". +Axiom ethereum_spurious_dragon_state_imports_set_account_balance : + IsImported globals "ethereum.spurious_dragon.state" "set_account_balance". -Axiom ethereum_spurious_dragon_utils_address_imports : - AreImported globals "ethereum.spurious_dragon.utils.address" [ "compute_contract_address"; "to_address" ]. +Axiom ethereum_spurious_dragon_utils_address_imports_compute_contract_address : + IsImported globals "ethereum.spurious_dragon.utils.address" "compute_contract_address". +Axiom ethereum_spurious_dragon_utils_address_imports_to_address : + IsImported globals "ethereum.spurious_dragon.utils.address" "to_address". -Axiom ethereum_spurious_dragon_vm_imports : - AreImported globals "ethereum.spurious_dragon.vm" [ "Evm"; "Message"; "incorporate_child_on_error"; "incorporate_child_on_success" ]. +Axiom ethereum_spurious_dragon_vm_imports_Evm : + IsImported globals "ethereum.spurious_dragon.vm" "Evm". +Axiom ethereum_spurious_dragon_vm_imports_Message : + IsImported globals "ethereum.spurious_dragon.vm" "Message". +Axiom ethereum_spurious_dragon_vm_imports_incorporate_child_on_error : + IsImported globals "ethereum.spurious_dragon.vm" "incorporate_child_on_error". +Axiom ethereum_spurious_dragon_vm_imports_incorporate_child_on_success : + IsImported globals "ethereum.spurious_dragon.vm" "incorporate_child_on_success". -Axiom ethereum_spurious_dragon_vm_gas_imports : - AreImported globals "ethereum.spurious_dragon.vm.gas" [ "GAS_CALL"; "GAS_CALL_VALUE"; "GAS_CREATE"; "GAS_NEW_ACCOUNT"; "GAS_SELF_DESTRUCT"; "GAS_SELF_DESTRUCT_NEW_ACCOUNT"; "GAS_ZERO"; "REFUND_SELF_DESTRUCT"; "calculate_gas_extend_memory"; "calculate_message_call_gas"; "charge_gas"; "max_message_call_gas" ]. +Axiom ethereum_spurious_dragon_vm_gas_imports_GAS_CALL : + IsImported globals "ethereum.spurious_dragon.vm.gas" "GAS_CALL". +Axiom ethereum_spurious_dragon_vm_gas_imports_GAS_CALL_VALUE : + IsImported globals "ethereum.spurious_dragon.vm.gas" "GAS_CALL_VALUE". +Axiom ethereum_spurious_dragon_vm_gas_imports_GAS_CREATE : + IsImported globals "ethereum.spurious_dragon.vm.gas" "GAS_CREATE". +Axiom ethereum_spurious_dragon_vm_gas_imports_GAS_NEW_ACCOUNT : + IsImported globals "ethereum.spurious_dragon.vm.gas" "GAS_NEW_ACCOUNT". +Axiom ethereum_spurious_dragon_vm_gas_imports_GAS_SELF_DESTRUCT : + IsImported globals "ethereum.spurious_dragon.vm.gas" "GAS_SELF_DESTRUCT". +Axiom ethereum_spurious_dragon_vm_gas_imports_GAS_SELF_DESTRUCT_NEW_ACCOUNT : + IsImported globals "ethereum.spurious_dragon.vm.gas" "GAS_SELF_DESTRUCT_NEW_ACCOUNT". +Axiom ethereum_spurious_dragon_vm_gas_imports_GAS_ZERO : + IsImported globals "ethereum.spurious_dragon.vm.gas" "GAS_ZERO". +Axiom ethereum_spurious_dragon_vm_gas_imports_REFUND_SELF_DESTRUCT : + IsImported globals "ethereum.spurious_dragon.vm.gas" "REFUND_SELF_DESTRUCT". +Axiom ethereum_spurious_dragon_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.spurious_dragon.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_spurious_dragon_vm_gas_imports_calculate_message_call_gas : + IsImported globals "ethereum.spurious_dragon.vm.gas" "calculate_message_call_gas". +Axiom ethereum_spurious_dragon_vm_gas_imports_charge_gas : + IsImported globals "ethereum.spurious_dragon.vm.gas" "charge_gas". +Axiom ethereum_spurious_dragon_vm_gas_imports_max_message_call_gas : + IsImported globals "ethereum.spurious_dragon.vm.gas" "max_message_call_gas". -Axiom ethereum_spurious_dragon_vm_memory_imports : - AreImported globals "ethereum.spurious_dragon.vm.memory" [ "memory_read_bytes"; "memory_write" ]. +Axiom ethereum_spurious_dragon_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.spurious_dragon.vm.memory" "memory_read_bytes". +Axiom ethereum_spurious_dragon_vm_memory_imports_memory_write : + IsImported globals "ethereum.spurious_dragon.vm.memory" "memory_write". -Axiom ethereum_spurious_dragon_vm_stack_imports : - AreImported globals "ethereum.spurious_dragon.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_spurious_dragon_vm_stack_imports_pop : + IsImported globals "ethereum.spurious_dragon.vm.stack" "pop". +Axiom ethereum_spurious_dragon_vm_stack_imports_push : + IsImported globals "ethereum.spurious_dragon.vm.stack" "push". Definition create : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -53,31 +101,38 @@ Definition create : Value.t -> Value.t -> M := The current EVM frame. " in (* At stmt: unsupported node type: ImportFrom *) - let endowment := + let _ := M.assign_local (| + "endowment" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_size := + |) + |) in + let _ := M.assign_local (| + "memory_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -87,7 +142,8 @@ Definition create : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -99,7 +155,8 @@ Definition create : Value.t -> Value.t -> M := ], make_dict [] |) in - let create_message_gas := + let _ := M.assign_local (| + "create_message_gas" , M.call (| M.get_name (| globals, "max_message_call_gas" |), make_list [ @@ -112,7 +169,8 @@ Definition create : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.assign_op (| BinOp.sub, M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), @@ -126,9 +184,12 @@ Definition create : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let sender_address := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in - let sender := + let _ := M.assign_local (| + "sender_address" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + |) in + let _ := M.assign_local (| + "sender" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -136,8 +197,10 @@ Definition create : Value.t -> Value.t -> M := M.get_name (| globals, "sender_address" |) ], make_dict [] - |) in - let contract_address := + |) + |) in + let _ := M.assign_local (| + "contract_address" , M.call (| M.get_name (| globals, "compute_contract_address" |), make_list [ @@ -152,7 +215,8 @@ Definition create : Value.t -> Value.t -> M := |), "nonce" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -253,7 +317,8 @@ Definition create : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let call_data := + let _ := M.assign_local (| + "call_data" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -262,7 +327,8 @@ Definition create : Value.t -> Value.t -> M := M.get_name (| globals, "memory_size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "increment_nonce" |), make_list [ @@ -271,13 +337,16 @@ Definition create : Value.t -> Value.t -> M := ], make_dict [] |) in - let child_message := + let _ := M.assign_local (| + "child_message" , M.call (| M.get_name (| globals, "Message" |), make_list [], make_dict [] - |) in - let child_evm := + |) + |) in + let _ := M.assign_local (| + "child_evm" , M.call (| M.get_name (| globals, "process_create_message" |), make_list [ @@ -285,7 +354,8 @@ Definition create : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -363,23 +433,28 @@ Definition return_ : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let memory_start_position := + let _ := M.assign_local (| + "memory_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_size := + |) + |) in + let _ := M.assign_local (| + "memory_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -389,7 +464,8 @@ Definition return_ : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -474,7 +550,8 @@ Definition generic_call : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let call_data := + let _ := M.assign_local (| + "call_data" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -483,8 +560,10 @@ Definition generic_call : Value.t -> Value.t -> M := M.get_name (| globals, "memory_input_size" |) ], make_dict [] - |) in - let code := + |) + |) in + let _ := M.assign_local (| + "code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -492,14 +571,18 @@ Definition generic_call : Value.t -> Value.t -> M := M.get_name (| globals, "code_address" |) ], make_dict [] - |), "code" |) in - let child_message := + |), "code" |) + |) in + let _ := M.assign_local (| + "child_message" , M.call (| M.get_name (| globals, "Message" |), make_list [], make_dict [] - |) in - let child_evm := + |) + |) in + let _ := M.assign_local (| + "child_evm" , M.call (| M.get_name (| globals, "process_message" |), make_list [ @@ -507,7 +590,8 @@ Definition generic_call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -563,7 +647,8 @@ Definition generic_call : Value.t -> Value.t -> M := |) in M.pure Constant.None_ )) |) in - let actual_output_size := + let _ := M.assign_local (| + "actual_output_size" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -583,7 +668,8 @@ Definition generic_call : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -611,7 +697,8 @@ Definition call : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -624,8 +711,10 @@ Definition call : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let to := + |) + |) in + let _ := M.assign_local (| + "to" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -638,48 +727,60 @@ Definition call : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -690,8 +791,10 @@ Definition call : Value.t -> Value.t -> M := ] ], make_dict [] - |) in - let create_gas_cost := + |) + |) in + let _ := M.assign_local (| + "create_gas_cost" , (* if *) M.if_then_else (| BoolOp.or (| @@ -722,8 +825,10 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "GAS_NEW_ACCOUNT" |) - )) |) in - let transfer_gas_cost := + )) |) + |) in + let _ := M.assign_local (| + "transfer_gas_cost" , (* if *) M.if_then_else (| Compare.eq (| @@ -742,8 +847,10 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "GAS_CALL_VALUE" |) - )) |) in - let message_call_gas := + )) |) + |) in + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -766,7 +873,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -786,7 +894,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let sender_balance := + let _ := M.assign_local (| + "sender_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -794,7 +903,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := (* if *) M.if_then_else (| @@ -863,7 +973,8 @@ Definition callcode : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -876,8 +987,10 @@ Definition callcode : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let code_address := + |) + |) in + let _ := M.assign_local (| + "code_address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -890,50 +1003,64 @@ Definition callcode : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let to := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "to" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -944,8 +1071,10 @@ Definition callcode : Value.t -> Value.t -> M := ] ], make_dict [] - |) in - let transfer_gas_cost := + |) + |) in + let _ := M.assign_local (| + "transfer_gas_cost" , (* if *) M.if_then_else (| Compare.eq (| @@ -964,8 +1093,10 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "GAS_CALL_VALUE" |) - )) |) in - let message_call_gas := + )) |) + |) in + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -985,7 +1116,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -1005,7 +1137,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let sender_balance := + let _ := M.assign_local (| + "sender_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1013,7 +1146,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := (* if *) M.if_then_else (| @@ -1082,7 +1216,8 @@ Definition selfdestruct : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let beneficiary := + let _ := M.assign_local (| + "beneficiary" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1095,9 +1230,12 @@ Definition selfdestruct : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let gas_cost := - M.get_name (| globals, "GAS_SELF_DESTRUCT" |) in + |) + |) in + let _ := M.assign_local (| + "gas_cost" , + M.get_name (| globals, "GAS_SELF_DESTRUCT" |) + |) in let _ := (* if *) M.if_then_else (| @@ -1126,20 +1264,28 @@ Definition selfdestruct : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let gas_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "gas_cost", M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) - M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let originator := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in - let refunded_accounts := - M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in - let parent_evm := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "parent_evm" |) in + let _ := M.assign_local (| + "originator" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + |) in + let _ := M.assign_local (| + "refunded_accounts" , + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) + |) in + let _ := M.assign_local (| + "parent_evm" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "parent_evm" |) + |) in let _ := M.while (| Compare.is_not (| @@ -1154,8 +1300,10 @@ Definition selfdestruct : Value.t -> Value.t -> M := ], make_dict [] |) in - let parent_evm := - M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in + let _ := M.assign_local (| + "parent_evm" , + M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -1189,7 +1337,8 @@ Definition selfdestruct : Value.t -> Value.t -> M := ], make_dict [] |) in - let beneficiary_balance := + let _ := M.assign_local (| + "beneficiary_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1197,8 +1346,10 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_name (| globals, "beneficiary" |) ], make_dict [] - |), "balance" |) in - let originator_balance := + |), "balance" |) + |) in + let _ := M.assign_local (| + "originator_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1206,7 +1357,8 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_name (| globals, "originator" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -1284,7 +1436,8 @@ Definition delegatecall : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -1297,8 +1450,10 @@ Definition delegatecall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let code_address := + |) + |) in + let _ := M.assign_local (| + "code_address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1311,40 +1466,50 @@ Definition delegatecall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1355,8 +1520,10 @@ Definition delegatecall : Value.t -> Value.t -> M := ] ], make_dict [] - |) in - let message_call_gas := + |) + |) in + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -1379,7 +1546,8 @@ Definition delegatecall : Value.t -> Value.t -> M := M.get_name (| globals, "GAS_CALL" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/interpreter.v b/CoqOfPython/ethereum/spurious_dragon/vm/interpreter.v index 8e8287b..e58aeba 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/interpreter.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/interpreter.v @@ -17,50 +17,106 @@ Introduction A straightforward interpreter that executes EVM code. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Iterable"; "Optional"; "Set"; "Tuple" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. - -Axiom ethereum_trace_imports : - AreImported globals "ethereum.trace" [ "EvmStop"; "OpEnd"; "OpException"; "OpStart"; "PrecompileEnd"; "PrecompileStart"; "TransactionEnd"; "evm_trace" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_spurious_dragon_blocks_imports : - AreImported globals "ethereum.spurious_dragon.blocks" [ "Log" ]. - -Axiom ethereum_spurious_dragon_fork_types_imports : - AreImported globals "ethereum.spurious_dragon.fork_types" [ "Address" ]. - -Axiom ethereum_spurious_dragon_state_imports : - AreImported globals "ethereum.spurious_dragon.state" [ "account_exists_and_is_empty"; "account_has_code_or_nonce"; "begin_transaction"; "commit_transaction"; "destroy_storage"; "increment_nonce"; "move_ether"; "rollback_transaction"; "set_code"; "touch_account" ]. - -Axiom ethereum_spurious_dragon_vm_imports : - AreImported globals "ethereum.spurious_dragon.vm" [ "Message" ]. - -Axiom ethereum_spurious_dragon_vm_gas_imports : - AreImported globals "ethereum.spurious_dragon.vm.gas" [ "GAS_CODE_DEPOSIT"; "charge_gas" ]. - -Axiom ethereum_spurious_dragon_vm_precompiled_contracts_mapping_imports : - AreImported globals "ethereum.spurious_dragon.vm.precompiled_contracts.mapping" [ "PRE_COMPILED_CONTRACTS" ]. - -Axiom ethereum_spurious_dragon_vm_imports : - AreImported globals "ethereum.spurious_dragon.vm" [ "Environment"; "Evm" ]. - -Axiom ethereum_spurious_dragon_vm_exceptions_imports : - AreImported globals "ethereum.spurious_dragon.vm.exceptions" [ "AddressCollision"; "ExceptionalHalt"; "InvalidOpcode"; "OutOfGasError"; "StackDepthLimitError" ]. - -Axiom ethereum_spurious_dragon_vm_instructions_imports : - AreImported globals "ethereum.spurious_dragon.vm.instructions" [ "Ops"; "op_implementation" ]. - -Axiom ethereum_spurious_dragon_vm_runtime_imports : - AreImported globals "ethereum.spurious_dragon.vm.runtime" [ "get_valid_jump_destinations" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_Iterable : + IsImported globals "typing" "Iterable". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_trace_imports_EvmStop : + IsImported globals "ethereum.trace" "EvmStop". +Axiom ethereum_trace_imports_OpEnd : + IsImported globals "ethereum.trace" "OpEnd". +Axiom ethereum_trace_imports_OpException : + IsImported globals "ethereum.trace" "OpException". +Axiom ethereum_trace_imports_OpStart : + IsImported globals "ethereum.trace" "OpStart". +Axiom ethereum_trace_imports_PrecompileEnd : + IsImported globals "ethereum.trace" "PrecompileEnd". +Axiom ethereum_trace_imports_PrecompileStart : + IsImported globals "ethereum.trace" "PrecompileStart". +Axiom ethereum_trace_imports_TransactionEnd : + IsImported globals "ethereum.trace" "TransactionEnd". +Axiom ethereum_trace_imports_evm_trace : + IsImported globals "ethereum.trace" "evm_trace". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_spurious_dragon_blocks_imports_Log : + IsImported globals "ethereum.spurious_dragon.blocks" "Log". + +Axiom ethereum_spurious_dragon_fork_types_imports_Address : + IsImported globals "ethereum.spurious_dragon.fork_types" "Address". + +Axiom ethereum_spurious_dragon_state_imports_account_exists_and_is_empty : + IsImported globals "ethereum.spurious_dragon.state" "account_exists_and_is_empty". +Axiom ethereum_spurious_dragon_state_imports_account_has_code_or_nonce : + IsImported globals "ethereum.spurious_dragon.state" "account_has_code_or_nonce". +Axiom ethereum_spurious_dragon_state_imports_begin_transaction : + IsImported globals "ethereum.spurious_dragon.state" "begin_transaction". +Axiom ethereum_spurious_dragon_state_imports_commit_transaction : + IsImported globals "ethereum.spurious_dragon.state" "commit_transaction". +Axiom ethereum_spurious_dragon_state_imports_destroy_storage : + IsImported globals "ethereum.spurious_dragon.state" "destroy_storage". +Axiom ethereum_spurious_dragon_state_imports_increment_nonce : + IsImported globals "ethereum.spurious_dragon.state" "increment_nonce". +Axiom ethereum_spurious_dragon_state_imports_move_ether : + IsImported globals "ethereum.spurious_dragon.state" "move_ether". +Axiom ethereum_spurious_dragon_state_imports_rollback_transaction : + IsImported globals "ethereum.spurious_dragon.state" "rollback_transaction". +Axiom ethereum_spurious_dragon_state_imports_set_code : + IsImported globals "ethereum.spurious_dragon.state" "set_code". +Axiom ethereum_spurious_dragon_state_imports_touch_account : + IsImported globals "ethereum.spurious_dragon.state" "touch_account". + +Axiom ethereum_spurious_dragon_vm_imports_Message : + IsImported globals "ethereum.spurious_dragon.vm" "Message". + +Axiom ethereum_spurious_dragon_vm_gas_imports_GAS_CODE_DEPOSIT : + IsImported globals "ethereum.spurious_dragon.vm.gas" "GAS_CODE_DEPOSIT". +Axiom ethereum_spurious_dragon_vm_gas_imports_charge_gas : + IsImported globals "ethereum.spurious_dragon.vm.gas" "charge_gas". + +Axiom ethereum_spurious_dragon_vm_precompiled_contracts_mapping_imports_PRE_COMPILED_CONTRACTS : + IsImported globals "ethereum.spurious_dragon.vm.precompiled_contracts.mapping" "PRE_COMPILED_CONTRACTS". + +Axiom ethereum_spurious_dragon_vm_imports_Environment : + IsImported globals "ethereum.spurious_dragon.vm" "Environment". +Axiom ethereum_spurious_dragon_vm_imports_Evm : + IsImported globals "ethereum.spurious_dragon.vm" "Evm". + +Axiom ethereum_spurious_dragon_vm_exceptions_imports_AddressCollision : + IsImported globals "ethereum.spurious_dragon.vm.exceptions" "AddressCollision". +Axiom ethereum_spurious_dragon_vm_exceptions_imports_ExceptionalHalt : + IsImported globals "ethereum.spurious_dragon.vm.exceptions" "ExceptionalHalt". +Axiom ethereum_spurious_dragon_vm_exceptions_imports_InvalidOpcode : + IsImported globals "ethereum.spurious_dragon.vm.exceptions" "InvalidOpcode". +Axiom ethereum_spurious_dragon_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.spurious_dragon.vm.exceptions" "OutOfGasError". +Axiom ethereum_spurious_dragon_vm_exceptions_imports_StackDepthLimitError : + IsImported globals "ethereum.spurious_dragon.vm.exceptions" "StackDepthLimitError". + +Axiom ethereum_spurious_dragon_vm_instructions_imports_Ops : + IsImported globals "ethereum.spurious_dragon.vm.instructions" "Ops". +Axiom ethereum_spurious_dragon_vm_instructions_imports_op_implementation : + IsImported globals "ethereum.spurious_dragon.vm.instructions" "op_implementation". + +Axiom ethereum_spurious_dragon_vm_runtime_imports_get_valid_jump_destinations : + IsImported globals "ethereum.spurious_dragon.vm.runtime" "get_valid_jump_destinations". Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -121,7 +177,8 @@ Definition process_message_call : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let is_collision := + let _ := M.assign_local (| + "is_collision" , M.call (| M.get_name (| globals, "account_has_code_or_nonce" |), make_list [ @@ -129,7 +186,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "message" |), "current_target" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -181,7 +239,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "process_create_message" |), make_list [ @@ -189,13 +248,15 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "process_message" |), make_list [ @@ -203,7 +264,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -250,40 +312,55 @@ Definition process_message_call : Value.t -> Value.t -> M := (* then *) ltac:(M.monadic ( (* At stmt: unsupported node type: AnnAssign *) - let accounts_to_delete := + let _ := M.assign_local (| + "accounts_to_delete" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let touched_accounts := + |) + |) in + let _ := M.assign_local (| + "touched_accounts" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let refund_counter := + |) + |) in + let _ := M.assign_local (| + "refund_counter" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let logs := - M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in - let accounts_to_delete := - M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in - let touched_accounts := - M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |) in - let refund_counter := - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |) in + let _ := M.assign_local (| + "logs" , + M.get_field (| M.get_name (| globals, "evm" |), "logs" |) + |) in + let _ := M.assign_local (| + "accounts_to_delete" , + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) + |) in + let _ := M.assign_local (| + "touched_accounts" , + M.get_field (| M.get_name (| globals, "evm" |), "touched_accounts" |) + |) in + let _ := M.assign_local (| + "refund_counter" , + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |) + |) in M.pure Constant.None_ )) |) in - let tx_end := + let _ := M.assign_local (| + "tx_end" , M.call (| M.get_name (| globals, "TransactionEnd" |), make_list [ @@ -295,7 +372,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "error" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "evm_trace" |), make_list [ @@ -354,7 +432,8 @@ Definition process_create_message : Value.t -> Value.t -> M := ], make_dict [] |) in - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "process_message" |), make_list [ @@ -362,16 +441,20 @@ Definition process_create_message : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), (* then *) ltac:(M.monadic ( - let contract_code := - M.get_field (| M.get_name (| globals, "evm" |), "output" |) in - let contract_code_gas := + let _ := M.assign_local (| + "contract_code" , + M.get_field (| M.get_name (| globals, "evm" |), "output" |) + |) in + let _ := M.assign_local (| + "contract_code_gas" , BinOp.mult (| M.call (| M.get_name (| globals, "len" |), @@ -381,7 +464,8 @@ Definition process_create_message : Value.t -> Value.t -> M := make_dict [] |), M.get_name (| globals, "GAS_CODE_DEPOSIT" |) - |) in + |) + |) in (* At stmt: unsupported node type: Try *) M.pure Constant.None_ (* else *) @@ -483,7 +567,8 @@ Definition process_message : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "execute_code" |), make_list [ @@ -491,7 +576,8 @@ Definition process_message : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -540,22 +626,28 @@ Definition execute_code : Value.t -> Value.t -> M := evm: `ethereum.vm.EVM` Items containing execution specific objects " in - let code := - M.get_field (| M.get_name (| globals, "message" |), "code" |) in - let valid_jump_destinations := + let _ := M.assign_local (| + "code" , + M.get_field (| M.get_name (| globals, "message" |), "code" |) + |) in + let _ := M.assign_local (| + "valid_jump_destinations" , M.call (| M.get_name (| globals, "get_valid_jump_destinations" |), make_list [ M.get_name (| globals, "code" |) ], make_dict [] - |) in - let evm := + |) + |) in + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "Evm" |), make_list [], make_dict [] - |) in + |) + |) in (* At stmt: unsupported node type: Try *) let _ := M.return_ (| M.get_name (| globals, "evm" |) diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/memory.v b/CoqOfPython/ethereum/spurious_dragon/vm/memory.v index d6d4144..b492085 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/memory.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/memory.v @@ -17,11 +17,15 @@ Introduction EVM memory operations. ". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "right_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_right_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "right_pad_zero_bytes". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". Definition memory_write : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/__init__.v index 4f4bcd1..1d7b891 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/__init__.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/__init__.v @@ -18,8 +18,8 @@ Addresses of precompiled contracts and mappings to their implementations. ". -Axiom ethereum_spurious_dragon_utils_hexadecimal_imports : - AreImported globals "ethereum.spurious_dragon.utils.hexadecimal" [ "hex_to_address" ]. +Axiom ethereum_spurious_dragon_utils_hexadecimal_imports_hex_to_address : + IsImported globals "ethereum.spurious_dragon.utils.hexadecimal" "hex_to_address". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS" ] diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/ecrecover.v index f527432..c1ae66e 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/ecrecover.v @@ -17,26 +17,32 @@ Introduction Implementation of the ECRECOVER precompiled contract. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_crypto_elliptic_curve_imports : - AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. +Axiom ethereum_crypto_elliptic_curve_imports_SECP256K1N : + IsImported globals "ethereum.crypto.elliptic_curve" "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_imports_secp256k1_recover : + IsImported globals "ethereum.crypto.elliptic_curve" "secp256k1_recover". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_left_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "left_pad_zero_bytes". -Axiom ethereum_spurious_dragon_vm_imports : - AreImported globals "ethereum.spurious_dragon.vm" [ "Evm" ]. +Axiom ethereum_spurious_dragon_vm_imports_Evm : + IsImported globals "ethereum.spurious_dragon.vm" "Evm". -Axiom ethereum_spurious_dragon_vm_gas_imports : - AreImported globals "ethereum.spurious_dragon.vm.gas" [ "GAS_ECRECOVER"; "charge_gas" ]. +Axiom ethereum_spurious_dragon_vm_gas_imports_GAS_ECRECOVER : + IsImported globals "ethereum.spurious_dragon.vm.gas" "GAS_ECRECOVER". +Axiom ethereum_spurious_dragon_vm_gas_imports_charge_gas : + IsImported globals "ethereum.spurious_dragon.vm.gas" "charge_gas". -Axiom ethereum_spurious_dragon_vm_memory_imports : - AreImported globals "ethereum.spurious_dragon.vm.memory" [ "buffer_read" ]. +Axiom ethereum_spurious_dragon_vm_memory_imports_buffer_read : + IsImported globals "ethereum.spurious_dragon.vm.memory" "buffer_read". Definition ecrecover : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -50,8 +56,10 @@ Definition ecrecover : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -60,7 +68,8 @@ Definition ecrecover : Value.t -> Value.t -> M := ], make_dict [] |) in - let message_hash_bytes := + let _ := M.assign_local (| + "message_hash_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -81,16 +90,20 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let message_hash := + |) + |) in + let _ := M.assign_local (| + "message_hash" , M.call (| M.get_name (| globals, "Hash32" |), make_list [ M.get_name (| globals, "message_hash_bytes" |) ], make_dict [] - |) in - let v := + |) + |) in + let _ := M.assign_local (| + "v" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -117,8 +130,10 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let r := + |) + |) in + let _ := M.assign_local (| + "r" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -145,8 +160,10 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let s := + |) + |) in + let _ := M.assign_local (| + "s" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -173,7 +190,8 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -250,7 +268,8 @@ Definition ecrecover : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: Try *) - let address := + let _ := M.assign_local (| + "address" , M.slice (| M.call (| M.get_name (| globals, "keccak256" |), @@ -262,8 +281,10 @@ Definition ecrecover : Value.t -> Value.t -> M := Constant.int 12, Constant.int 32, Constant.None_ - |) in - let padded_address := + |) + |) in + let _ := M.assign_local (| + "padded_address" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -271,7 +292,8 @@ Definition ecrecover : Value.t -> Value.t -> M := Constant.int 32 ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.get_name (| globals, "padded_address" |) diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/identity.v index a727fec..c36d5ee 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/identity.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/identity.v @@ -17,17 +17,21 @@ Introduction Implementation of the `IDENTITY` precompiled contract. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_spurious_dragon_vm_imports : - AreImported globals "ethereum.spurious_dragon.vm" [ "Evm" ]. +Axiom ethereum_spurious_dragon_vm_imports_Evm : + IsImported globals "ethereum.spurious_dragon.vm" "Evm". -Axiom ethereum_spurious_dragon_vm_gas_imports : - AreImported globals "ethereum.spurious_dragon.vm.gas" [ "GAS_IDENTITY"; "GAS_IDENTITY_WORD"; "charge_gas" ]. +Axiom ethereum_spurious_dragon_vm_gas_imports_GAS_IDENTITY : + IsImported globals "ethereum.spurious_dragon.vm.gas" "GAS_IDENTITY". +Axiom ethereum_spurious_dragon_vm_gas_imports_GAS_IDENTITY_WORD : + IsImported globals "ethereum.spurious_dragon.vm.gas" "GAS_IDENTITY_WORD". +Axiom ethereum_spurious_dragon_vm_gas_imports_charge_gas : + IsImported globals "ethereum.spurious_dragon.vm.gas" "charge_gas". Definition identity : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -40,9 +44,12 @@ Definition identity : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let word_count := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "word_count" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -64,7 +71,8 @@ Definition identity : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/mapping.v index 5c95c6e..cba9815 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/mapping.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/mapping.v @@ -17,25 +17,33 @@ Introduction Mapping of precompiled contracts their implementations. ". -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict" ]. - -Axiom ethereum_spurious_dragon_fork_types_imports : - AreImported globals "ethereum.spurious_dragon.fork_types" [ "Address" ]. - -Axiom ethereum_spurious_dragon_vm_precompiled_contracts_imports : - AreImported globals "ethereum.spurious_dragon.vm.precompiled_contracts" [ "ECRECOVER_ADDRESS"; "IDENTITY_ADDRESS"; "RIPEMD160_ADDRESS"; "SHA256_ADDRESS" ]. - -Axiom ethereum_spurious_dragon_vm_precompiled_contracts_ecrecover_imports : - AreImported globals "ethereum.spurious_dragon.vm.precompiled_contracts.ecrecover" [ "ecrecover" ]. - -Axiom ethereum_spurious_dragon_vm_precompiled_contracts_identity_imports : - AreImported globals "ethereum.spurious_dragon.vm.precompiled_contracts.identity" [ "identity" ]. - -Axiom ethereum_spurious_dragon_vm_precompiled_contracts_ripemd160_imports : - AreImported globals "ethereum.spurious_dragon.vm.precompiled_contracts.ripemd160" [ "ripemd160" ]. - -Axiom ethereum_spurious_dragon_vm_precompiled_contracts_sha256_imports : - AreImported globals "ethereum.spurious_dragon.vm.precompiled_contracts.sha256" [ "sha256" ]. +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". + +Axiom ethereum_spurious_dragon_fork_types_imports_Address : + IsImported globals "ethereum.spurious_dragon.fork_types" "Address". + +Axiom ethereum_spurious_dragon_vm_precompiled_contracts_imports_ECRECOVER_ADDRESS : + IsImported globals "ethereum.spurious_dragon.vm.precompiled_contracts" "ECRECOVER_ADDRESS". +Axiom ethereum_spurious_dragon_vm_precompiled_contracts_imports_IDENTITY_ADDRESS : + IsImported globals "ethereum.spurious_dragon.vm.precompiled_contracts" "IDENTITY_ADDRESS". +Axiom ethereum_spurious_dragon_vm_precompiled_contracts_imports_RIPEMD160_ADDRESS : + IsImported globals "ethereum.spurious_dragon.vm.precompiled_contracts" "RIPEMD160_ADDRESS". +Axiom ethereum_spurious_dragon_vm_precompiled_contracts_imports_SHA256_ADDRESS : + IsImported globals "ethereum.spurious_dragon.vm.precompiled_contracts" "SHA256_ADDRESS". + +Axiom ethereum_spurious_dragon_vm_precompiled_contracts_ecrecover_imports_ecrecover : + IsImported globals "ethereum.spurious_dragon.vm.precompiled_contracts.ecrecover" "ecrecover". + +Axiom ethereum_spurious_dragon_vm_precompiled_contracts_identity_imports_identity : + IsImported globals "ethereum.spurious_dragon.vm.precompiled_contracts.identity" "identity". + +Axiom ethereum_spurious_dragon_vm_precompiled_contracts_ripemd160_imports_ripemd160 : + IsImported globals "ethereum.spurious_dragon.vm.precompiled_contracts.ripemd160" "ripemd160". + +Axiom ethereum_spurious_dragon_vm_precompiled_contracts_sha256_imports_sha256 : + IsImported globals "ethereum.spurious_dragon.vm.precompiled_contracts.sha256" "sha256". (* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/ripemd160.v index 4a39a9c..029a148 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/ripemd160.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/ripemd160.v @@ -19,20 +19,24 @@ Implementation of the `RIPEMD160` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_left_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "left_pad_zero_bytes". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_spurious_dragon_vm_imports : - AreImported globals "ethereum.spurious_dragon.vm" [ "Evm" ]. +Axiom ethereum_spurious_dragon_vm_imports_Evm : + IsImported globals "ethereum.spurious_dragon.vm" "Evm". -Axiom ethereum_spurious_dragon_vm_gas_imports : - AreImported globals "ethereum.spurious_dragon.vm.gas" [ "GAS_RIPEMD160"; "GAS_RIPEMD160_WORD"; "charge_gas" ]. +Axiom ethereum_spurious_dragon_vm_gas_imports_GAS_RIPEMD160 : + IsImported globals "ethereum.spurious_dragon.vm.gas" "GAS_RIPEMD160". +Axiom ethereum_spurious_dragon_vm_gas_imports_GAS_RIPEMD160_WORD : + IsImported globals "ethereum.spurious_dragon.vm.gas" "GAS_RIPEMD160_WORD". +Axiom ethereum_spurious_dragon_vm_gas_imports_charge_gas : + IsImported globals "ethereum.spurious_dragon.vm.gas" "charge_gas". Definition ripemd160 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,9 +49,12 @@ Definition ripemd160 : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let word_count := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "word_count" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -69,7 +76,8 @@ Definition ripemd160 : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -84,7 +92,8 @@ Definition ripemd160 : Value.t -> Value.t -> M := ], make_dict [] |) in - let hash_bytes := + let _ := M.assign_local (| + "hash_bytes" , M.call (| M.get_field (| M.call (| M.get_field (| M.get_name (| globals, "hashlib" |), "new" |), @@ -96,8 +105,10 @@ Definition ripemd160 : Value.t -> Value.t -> M := |), "digest" |), make_list [], make_dict [] - |) in - let padded_hash := + |) + |) in + let _ := M.assign_local (| + "padded_hash" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -105,7 +116,8 @@ Definition ripemd160 : Value.t -> Value.t -> M := Constant.int 32 ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.get_name (| globals, "padded_hash" |) diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/sha256.v index d82133c..c155fe7 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/sha256.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/precompiled_contracts/sha256.v @@ -19,17 +19,21 @@ Implementation of the `SHA256` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_spurious_dragon_vm_imports : - AreImported globals "ethereum.spurious_dragon.vm" [ "Evm" ]. +Axiom ethereum_spurious_dragon_vm_imports_Evm : + IsImported globals "ethereum.spurious_dragon.vm" "Evm". -Axiom ethereum_spurious_dragon_vm_gas_imports : - AreImported globals "ethereum.spurious_dragon.vm.gas" [ "GAS_SHA256"; "GAS_SHA256_WORD"; "charge_gas" ]. +Axiom ethereum_spurious_dragon_vm_gas_imports_GAS_SHA256 : + IsImported globals "ethereum.spurious_dragon.vm.gas" "GAS_SHA256". +Axiom ethereum_spurious_dragon_vm_gas_imports_GAS_SHA256_WORD : + IsImported globals "ethereum.spurious_dragon.vm.gas" "GAS_SHA256_WORD". +Axiom ethereum_spurious_dragon_vm_gas_imports_charge_gas : + IsImported globals "ethereum.spurious_dragon.vm.gas" "charge_gas". Definition sha256 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,9 +46,12 @@ Definition sha256 : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let word_count := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "word_count" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -66,7 +73,8 @@ Definition sha256 : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/runtime.v b/CoqOfPython/ethereum/spurious_dragon/vm/runtime.v index 1ee9b82..9f6ecd8 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/runtime.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/runtime.v @@ -17,14 +17,14 @@ Introduction Runtime related operations used while executing EVM code. ". -Axiom typing_imports : - AreImported globals "typing" [ "Set" ]. +Axiom typing_imports_Set : + IsImported globals "typing" "Set". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_spurious_dragon_vm_instructions_imports : - AreImported globals "ethereum.spurious_dragon.vm.instructions" [ "Ops" ]. +Axiom ethereum_spurious_dragon_vm_instructions_imports_Ops : + IsImported globals "ethereum.spurious_dragon.vm.instructions" "Ops". Definition get_valid_jump_destinations : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -50,20 +50,24 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := valid_jump_destinations: `Set[Uint]` The set of valid jump destinations in the code. " in - let valid_jump_destinations := + let _ := M.assign_local (| + "valid_jump_destinations" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let pc := + |) + |) in + let _ := M.assign_local (| + "pc" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in let _ := M.while (| Compare.lt (| @@ -114,17 +118,21 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let push_data_size := + let _ := M.assign_local (| + "push_data_size" , BinOp.add (| BinOp.sub (| M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) |), Constant.int 1 - |) in - let pc := BinOp.add + |) + |) in + let _ := M.assign_op_local (| + BinOp.add, + "pc", M.get_name (| globals, "push_data_size" |) - M.get_name (| globals, "push_data_size" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -132,9 +140,11 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - let pc := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "pc", Constant.int 1 - Constant.int 1 in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/spurious_dragon/vm/stack.v b/CoqOfPython/ethereum/spurious_dragon/vm/stack.v index 5cf5f43..b6fb48a 100644 --- a/CoqOfPython/ethereum/spurious_dragon/vm/stack.v +++ b/CoqOfPython/ethereum/spurious_dragon/vm/stack.v @@ -17,14 +17,16 @@ Introduction Implementation of the stack operators for the EVM. ". -Axiom typing_imports : - AreImported globals "typing" [ "List" ]. +Axiom typing_imports_List : + IsImported globals "typing" "List". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_spurious_dragon_vm_exceptions_imports : - AreImported globals "ethereum.spurious_dragon.vm.exceptions" [ "StackOverflowError"; "StackUnderflowError" ]. +Axiom ethereum_spurious_dragon_vm_exceptions_imports_StackOverflowError : + IsImported globals "ethereum.spurious_dragon.vm.exceptions" "StackOverflowError". +Axiom ethereum_spurious_dragon_vm_exceptions_imports_StackUnderflowError : + IsImported globals "ethereum.spurious_dragon.vm.exceptions" "StackUnderflowError". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/tangerine_whistle/__init__.v b/CoqOfPython/ethereum/tangerine_whistle/__init__.v index aa34c97..fd543a7 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/__init__.v +++ b/CoqOfPython/ethereum/tangerine_whistle/__init__.v @@ -10,8 +10,8 @@ EVM instructions, and reduces the state size by removing a number of empty accounts. ". -Axiom ethereum_fork_criteria_imports : - AreImported globals "ethereum.fork_criteria" [ "ByBlockNumber" ]. +Axiom ethereum_fork_criteria_imports_ByBlockNumber : + IsImported globals "ethereum.fork_criteria" "ByBlockNumber". Definition FORK_CRITERIA : Value.t := M.run ltac:(M.monadic ( M.call (| diff --git a/CoqOfPython/ethereum/tangerine_whistle/blocks.v b/CoqOfPython/ethereum/tangerine_whistle/blocks.v index c21d5ca..b921a0d 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/blocks.v +++ b/CoqOfPython/ethereum/tangerine_whistle/blocks.v @@ -14,23 +14,37 @@ history of all state transitions that have happened since the genesis of the chain. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Tuple" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes8"; "Bytes32"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. - -Axiom ethereum_tangerine_whistle_fork_types_imports : - AreImported globals "ethereum.tangerine_whistle.fork_types" [ "Address"; "Bloom"; "Root" ]. - -Axiom ethereum_tangerine_whistle_transactions_imports : - AreImported globals "ethereum.tangerine_whistle.transactions" [ "Transaction" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes8 : + IsImported globals "ethereum.base_types" "Bytes8". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". + +Axiom ethereum_tangerine_whistle_fork_types_imports_Address : + IsImported globals "ethereum.tangerine_whistle.fork_types" "Address". +Axiom ethereum_tangerine_whistle_fork_types_imports_Bloom : + IsImported globals "ethereum.tangerine_whistle.fork_types" "Bloom". +Axiom ethereum_tangerine_whistle_fork_types_imports_Root : + IsImported globals "ethereum.tangerine_whistle.fork_types" "Root". + +Axiom ethereum_tangerine_whistle_transactions_imports_Transaction : + IsImported globals "ethereum.tangerine_whistle.transactions" "Transaction". Definition Header : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/tangerine_whistle/bloom.v b/CoqOfPython/ethereum/tangerine_whistle/bloom.v index 1451af7..ccf56cd 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/bloom.v +++ b/CoqOfPython/ethereum/tangerine_whistle/bloom.v @@ -21,20 +21,20 @@ for efficient searching of logs by address and/or topic, by rapidly eliminating blocks and receipts from their search. ". -Axiom typing_imports : - AreImported globals "typing" [ "Tuple" ]. +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_tangerine_whistle_blocks_imports : - AreImported globals "ethereum.tangerine_whistle.blocks" [ "Log" ]. +Axiom ethereum_tangerine_whistle_blocks_imports_Log : + IsImported globals "ethereum.tangerine_whistle.blocks" "Log". -Axiom ethereum_tangerine_whistle_fork_types_imports : - AreImported globals "ethereum.tangerine_whistle.fork_types" [ "Bloom" ]. +Axiom ethereum_tangerine_whistle_fork_types_imports_Bloom : + IsImported globals "ethereum.tangerine_whistle.fork_types" "Bloom". Definition add_to_bloom : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -53,20 +53,23 @@ Definition add_to_bloom : Value.t -> Value.t -> M := bloom_entry : An entry which is to be added to bloom filter. " in - let hash := + let _ := M.assign_local (| + "hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "bloom_entry" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "idx" |), make_tuple [ Constant.int 0; Constant.int 2; Constant.int 4 ], ltac:(M.monadic ( - let bit_to_set := + let _ := M.assign_local (| + "bit_to_set" , BinOp.bit_and (| M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_be_bytes" |), @@ -84,18 +87,24 @@ Definition add_to_bloom : Value.t -> Value.t -> M := make_dict [] |), Constant.int 2047 - |) in - let bit_index := + |) + |) in + let _ := M.assign_local (| + "bit_index" , BinOp.sub (| Constant.int 2047, M.get_name (| globals, "bit_to_set" |) - |) in - let byte_index := + |) + |) in + let _ := M.assign_local (| + "byte_index" , BinOp.floor_div (| M.get_name (| globals, "bit_index" |), Constant.int 8 - |) in - let bit_value := + |) + |) in + let _ := M.assign_local (| + "bit_value" , BinOp.l_shift (| Constant.int 1, BinOp.sub (| @@ -105,7 +114,8 @@ Definition add_to_bloom : Value.t -> Value.t -> M := Constant.int 8 |) |) - |) in + |) + |) in let _ := M.assign (| M.get_subscript (| M.get_name (| globals, "bloom" |), diff --git a/CoqOfPython/ethereum/tangerine_whistle/fork.v b/CoqOfPython/ethereum/tangerine_whistle/fork.v index b7f1c88..bc0e99d 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/fork.v +++ b/CoqOfPython/ethereum/tangerine_whistle/fork.v @@ -17,62 +17,120 @@ Introduction Entry point for the Ethereum specification. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Bytes0" ]. - -Axiom ethereum_crypto_elliptic_curve_imports : - AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. - -Axiom ethereum_ethash_imports : - AreImported globals "ethereum.ethash" [ "dataset_size"; "generate_cache"; "hashimoto_light" ]. - -Axiom ethereum_exceptions_imports : - AreImported globals "ethereum.exceptions" [ "InvalidBlock" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U64"; "U256"; "U256_CEIL_VALUE"; "Bytes"; "Bytes32"; "Uint" ]. - -Axiom ethereum_tangerine_whistle_imports : - AreImported globals "ethereum.tangerine_whistle" [ "vm" ]. - -Axiom ethereum_tangerine_whistle_blocks_imports : - AreImported globals "ethereum.tangerine_whistle.blocks" [ "Block"; "Header"; "Log"; "Receipt" ]. - -Axiom ethereum_tangerine_whistle_bloom_imports : - AreImported globals "ethereum.tangerine_whistle.bloom" [ "logs_bloom" ]. - -Axiom ethereum_tangerine_whistle_fork_types_imports : - AreImported globals "ethereum.tangerine_whistle.fork_types" [ "Address"; "Bloom"; "Root" ]. - -Axiom ethereum_tangerine_whistle_state_imports : - AreImported globals "ethereum.tangerine_whistle.state" [ "State"; "create_ether"; "destroy_account"; "get_account"; "increment_nonce"; "set_account_balance"; "state_root" ]. - -Axiom ethereum_tangerine_whistle_transactions_imports : - AreImported globals "ethereum.tangerine_whistle.transactions" [ "TX_BASE_COST"; "TX_CREATE_COST"; "TX_DATA_COST_PER_NON_ZERO"; "TX_DATA_COST_PER_ZERO"; "Transaction" ]. - -Axiom ethereum_tangerine_whistle_trie_imports : - AreImported globals "ethereum.tangerine_whistle.trie" [ "Trie"; "root"; "trie_set" ]. - -Axiom ethereum_tangerine_whistle_utils_message_imports : - AreImported globals "ethereum.tangerine_whistle.utils.message" [ "prepare_message" ]. - -Axiom ethereum_tangerine_whistle_vm_interpreter_imports : - AreImported globals "ethereum.tangerine_whistle.vm.interpreter" [ "process_message_call" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". + +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". + +Axiom ethereum_crypto_elliptic_curve_imports_SECP256K1N : + IsImported globals "ethereum.crypto.elliptic_curve" "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_imports_secp256k1_recover : + IsImported globals "ethereum.crypto.elliptic_curve" "secp256k1_recover". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". + +Axiom ethereum_ethash_imports_dataset_size : + IsImported globals "ethereum.ethash" "dataset_size". +Axiom ethereum_ethash_imports_generate_cache : + IsImported globals "ethereum.ethash" "generate_cache". +Axiom ethereum_ethash_imports_hashimoto_light : + IsImported globals "ethereum.ethash" "hashimoto_light". + +Axiom ethereum_exceptions_imports_InvalidBlock : + IsImported globals "ethereum.exceptions" "InvalidBlock". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U64 : + IsImported globals "ethereum.base_types" "U64". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_U256_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U256_CEIL_VALUE". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_tangerine_whistle_imports_vm : + IsImported globals "ethereum.tangerine_whistle" "vm". + +Axiom ethereum_tangerine_whistle_blocks_imports_Block : + IsImported globals "ethereum.tangerine_whistle.blocks" "Block". +Axiom ethereum_tangerine_whistle_blocks_imports_Header : + IsImported globals "ethereum.tangerine_whistle.blocks" "Header". +Axiom ethereum_tangerine_whistle_blocks_imports_Log : + IsImported globals "ethereum.tangerine_whistle.blocks" "Log". +Axiom ethereum_tangerine_whistle_blocks_imports_Receipt : + IsImported globals "ethereum.tangerine_whistle.blocks" "Receipt". + +Axiom ethereum_tangerine_whistle_bloom_imports_logs_bloom : + IsImported globals "ethereum.tangerine_whistle.bloom" "logs_bloom". + +Axiom ethereum_tangerine_whistle_fork_types_imports_Address : + IsImported globals "ethereum.tangerine_whistle.fork_types" "Address". +Axiom ethereum_tangerine_whistle_fork_types_imports_Bloom : + IsImported globals "ethereum.tangerine_whistle.fork_types" "Bloom". +Axiom ethereum_tangerine_whistle_fork_types_imports_Root : + IsImported globals "ethereum.tangerine_whistle.fork_types" "Root". + +Axiom ethereum_tangerine_whistle_state_imports_State : + IsImported globals "ethereum.tangerine_whistle.state" "State". +Axiom ethereum_tangerine_whistle_state_imports_create_ether : + IsImported globals "ethereum.tangerine_whistle.state" "create_ether". +Axiom ethereum_tangerine_whistle_state_imports_destroy_account : + IsImported globals "ethereum.tangerine_whistle.state" "destroy_account". +Axiom ethereum_tangerine_whistle_state_imports_get_account : + IsImported globals "ethereum.tangerine_whistle.state" "get_account". +Axiom ethereum_tangerine_whistle_state_imports_increment_nonce : + IsImported globals "ethereum.tangerine_whistle.state" "increment_nonce". +Axiom ethereum_tangerine_whistle_state_imports_set_account_balance : + IsImported globals "ethereum.tangerine_whistle.state" "set_account_balance". +Axiom ethereum_tangerine_whistle_state_imports_state_root : + IsImported globals "ethereum.tangerine_whistle.state" "state_root". + +Axiom ethereum_tangerine_whistle_transactions_imports_TX_BASE_COST : + IsImported globals "ethereum.tangerine_whistle.transactions" "TX_BASE_COST". +Axiom ethereum_tangerine_whistle_transactions_imports_TX_CREATE_COST : + IsImported globals "ethereum.tangerine_whistle.transactions" "TX_CREATE_COST". +Axiom ethereum_tangerine_whistle_transactions_imports_TX_DATA_COST_PER_NON_ZERO : + IsImported globals "ethereum.tangerine_whistle.transactions" "TX_DATA_COST_PER_NON_ZERO". +Axiom ethereum_tangerine_whistle_transactions_imports_TX_DATA_COST_PER_ZERO : + IsImported globals "ethereum.tangerine_whistle.transactions" "TX_DATA_COST_PER_ZERO". +Axiom ethereum_tangerine_whistle_transactions_imports_Transaction : + IsImported globals "ethereum.tangerine_whistle.transactions" "Transaction". + +Axiom ethereum_tangerine_whistle_trie_imports_Trie : + IsImported globals "ethereum.tangerine_whistle.trie" "Trie". +Axiom ethereum_tangerine_whistle_trie_imports_root : + IsImported globals "ethereum.tangerine_whistle.trie" "root". +Axiom ethereum_tangerine_whistle_trie_imports_trie_set : + IsImported globals "ethereum.tangerine_whistle.trie" "trie_set". + +Axiom ethereum_tangerine_whistle_utils_message_imports_prepare_message : + IsImported globals "ethereum.tangerine_whistle.utils.message" "prepare_message". + +Axiom ethereum_tangerine_whistle_vm_interpreter_imports_process_message_call : + IsImported globals "ethereum.tangerine_whistle.vm.interpreter" "process_message_call". Definition BLOCK_REWARD : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -170,13 +228,15 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := recent_block_hashes : `List[Hash32]` Hashes of the recent 256 blocks in order of increasing block number. " in - let recent_blocks := + let _ := M.assign_local (| + "recent_blocks" , M.slice (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 255 |), Constant.None_, Constant.None_ - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -200,15 +260,19 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let recent_block_hashes := - make_list [] in + let _ := M.assign_local (| + "recent_block_hashes" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "block" |), M.get_name (| globals, "recent_blocks" |), ltac:(M.monadic ( - let prev_block_hash := - M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) in + let _ := M.assign_local (| + "prev_block_hash" , + M.get_field (| M.get_field (| M.get_name (| globals, "block" |), "header" |), "parent_hash" |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), make_list [ @@ -222,7 +286,8 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let most_recent_block_hash := + let _ := M.assign_local (| + "most_recent_block_hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -238,7 +303,8 @@ Definition get_last_256_block_hashes : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "recent_block_hashes" |), "append" |), make_list [ @@ -275,11 +341,13 @@ Definition state_transition : Value.t -> Value.t -> M := block : Block to apply to `chain`. " in - let parent_header := + let _ := M.assign_local (| + "parent_header" , M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| Constant.int 1 |) - |), "header" |) in + |), "header" |) + |) in let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ @@ -297,7 +365,8 @@ Definition state_transition : Value.t -> Value.t -> M := ], make_dict [] |) in - let apply_body_output := + let _ := M.assign_local (| + "apply_body_output" , M.call (| M.get_name (| globals, "apply_body" |), make_list [ @@ -318,7 +387,8 @@ Definition state_transition : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "block" |), "ommers" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -489,7 +559,8 @@ Definition validate_header : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_difficulty := + let _ := M.assign_local (| + "block_difficulty" , M.call (| M.get_name (| globals, "calculate_block_difficulty" |), make_list [ @@ -499,7 +570,8 @@ Definition validate_header : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "parent_header" |), "difficulty" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -511,7 +583,8 @@ Definition validate_header : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_parent_hash := + let _ := M.assign_local (| + "block_parent_hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -524,7 +597,8 @@ Definition validate_header : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -570,7 +644,8 @@ Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := hash : `Hash32` The PoW valid rlp hash of the passed in header. " in - let header_data_without_pow_artefacts := + let _ := M.assign_local (| + "header_data_without_pow_artefacts" , make_list [ M.get_field (| M.get_name (| globals, "header" |), "parent_hash" |); M.get_field (| M.get_name (| globals, "header" |), "ommers_hash" |); @@ -585,7 +660,8 @@ Definition generate_header_hash_for_pow : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "header" |), "gas_used" |); M.get_field (| M.get_name (| globals, "header" |), "timestamp" |); M.get_field (| M.get_name (| globals, "header" |), "extra_data" |) - ] in + ] + |) in let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), @@ -614,22 +690,26 @@ Definition validate_proof_of_work : Value.t -> Value.t -> M := header : Header of interest. " in - let header_hash := + let _ := M.assign_local (| + "header_hash" , M.call (| M.get_name (| globals, "generate_header_hash_for_pow" |), make_list [ M.get_name (| globals, "header" |) ], make_dict [] - |) in - let cache := + |) + |) in + let _ := M.assign_local (| + "cache" , M.call (| M.get_name (| globals, "generate_cache" |), make_list [ M.get_field (| M.get_name (| globals, "header" |), "number" |) ], make_dict [] - |) in + |) + |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "mix_digest" |); M.get_name (| globals, "result" |) ], M.call (| @@ -716,14 +796,16 @@ Definition check_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_address := + let _ := M.assign_local (| + "sender_address" , M.call (| M.get_name (| globals, "recover_sender" |), make_list [ M.get_name (| globals, "tx" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "sender_address" |) |) in @@ -752,12 +834,14 @@ Definition make_receipt : Value.t -> Value.t -> M := receipt : The receipt for the transaction. " in - let receipt := + let _ := M.assign_local (| + "receipt" , M.call (| M.get_name (| globals, "Receipt" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "receipt" |) |) in @@ -814,8 +898,10 @@ Definition apply_body : Value.t -> Value.t -> M := apply_body_output : `ApplyBodyOutput` Output of applying the block body to the state. " in - let gas_available := - M.get_name (| globals, "block_gas_limit" |) in + let _ := M.assign_local (| + "gas_available" , + M.get_name (| globals, "block_gas_limit" |) + |) in (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) (* At stmt: unsupported node type: AnnAssign *) @@ -851,7 +937,8 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_address := + let _ := M.assign_local (| + "sender_address" , M.call (| M.get_name (| globals, "check_transaction" |), make_list [ @@ -859,13 +946,16 @@ Definition apply_body : Value.t -> Value.t -> M := M.get_name (| globals, "gas_available" |) ], make_dict [] - |) in - let env := + |) + |) in + let _ := M.assign_local (| + "env" , M.call (| M.get_field (| M.get_name (| globals, "vm" |), "Environment" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| make_tuple [ M.get_name (| globals, "gas_used" |); M.get_name (| globals, "logs" |) ], M.call (| @@ -877,10 +967,13 @@ Definition apply_body : Value.t -> Value.t -> M := make_dict [] |) |) in - let gas_available := BinOp.sub + let _ := M.assign_op_local (| + BinOp.sub, + "gas_available", M.get_name (| globals, "gas_used" |) - M.get_name (| globals, "gas_used" |) in - let receipt := + |) in + let _ := M.assign_local (| + "receipt" , M.call (| M.get_name (| globals, "make_receipt" |), make_list [ @@ -899,7 +992,8 @@ Definition apply_body : Value.t -> Value.t -> M := M.get_name (| globals, "logs" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "trie_set" |), make_list [ @@ -921,9 +1015,11 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_logs := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "block_logs", M.get_name (| globals, "logs" |) - M.get_name (| globals, "logs" |) in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -940,19 +1036,23 @@ Definition apply_body : Value.t -> Value.t -> M := ], make_dict [] |) in - let block_gas_used := + let _ := M.assign_local (| + "block_gas_used" , BinOp.sub (| M.get_name (| globals, "block_gas_limit" |), M.get_name (| globals, "gas_available" |) - |) in - let block_logs_bloom := + |) + |) in + let _ := M.assign_local (| + "block_logs_bloom" , M.call (| M.get_name (| globals, "logs_bloom" |), make_list [ M.get_name (| globals, "block_logs" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ApplyBodyOutput" |), @@ -1010,14 +1110,16 @@ Definition validate_ommers : Value.t -> Value.t -> M := chain : History and current state. " in - let block_hash := + let _ := M.assign_local (| + "block_hash" , M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "rlp_hash" |), make_list [ M.get_name (| globals, "block_header" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1082,7 +1184,8 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_parent_header := + let _ := M.assign_local (| + "ommer_parent_header" , M.get_field (| M.get_subscript (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), BinOp.sub (| @@ -1092,7 +1195,8 @@ Definition validate_ommers : Value.t -> Value.t -> M := |) |), Constant.int 1 |) - |), "header" |) in + |), "header" |) + |) in let _ := M.call (| M.get_name (| globals, "validate_header" |), make_list [ @@ -1124,8 +1228,10 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommers_hashes := - Constant.str "(* At expr: unsupported node type: ListComp *)" in + let _ := M.assign_local (| + "ommers_hashes" , + Constant.str "(* At expr: unsupported node type: ListComp *)" + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1155,7 +1261,8 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let recent_canonical_blocks := + let _ := M.assign_local (| + "recent_canonical_blocks" , M.slice (| M.get_field (| M.get_name (| globals, "chain" |), "blocks" |), UnOp.sub (| BinOp.add (| @@ -1164,23 +1271,28 @@ Definition validate_ommers : Value.t -> Value.t -> M := |) |), Constant.None_, Constant.None_ - |) in - let recent_canonical_block_hashes := - Constant.str "(* At expr: unsupported node type: SetComp *)" in + |) + |) in + let _ := M.assign_local (| + "recent_canonical_block_hashes" , + Constant.str "(* At expr: unsupported node type: SetComp *)" + |) in (* At stmt: unsupported node type: AnnAssign *) let _ := M.for_ (| M.get_name (| globals, "block" |), M.get_name (| globals, "recent_canonical_blocks" |), ltac:(M.monadic ( - let recent_ommers_hashes := + let _ := M.assign_local (| + "recent_ommers_hashes" , M.call (| M.get_field (| M.get_name (| globals, "recent_ommers_hashes" |), "union" |), make_list [ Constant.str "(* At expr: unsupported node type: SetComp *)" ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -1198,11 +1310,13 @@ Definition validate_ommers : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let ommer_hash := + let _ := M.assign_local (| + "ommer_hash" , M.get_subscript (| M.get_name (| globals, "ommers_hashes" |), M.get_name (| globals, "ommer_index" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1236,11 +1350,13 @@ Definition validate_ommers : Value.t -> Value.t -> M := ], make_dict [] |) in - let ommer_age := + let _ := M.assign_local (| + "ommer_age" , BinOp.sub (| M.get_field (| M.get_name (| globals, "block_header" |), "number" |), M.get_field (| M.get_name (| globals, "ommer" |), "number" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1318,7 +1434,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := ommers : List of ommers mentioned in the current block. " in - let miner_reward := + let _ := M.assign_local (| + "miner_reward" , BinOp.add (| M.get_name (| globals, "BLOCK_REWARD" |), BinOp.mult (| @@ -1334,7 +1451,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := Constant.int 32 |) |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "create_ether" |), make_list [ @@ -1349,7 +1467,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := M.get_name (| globals, "ommer" |), M.get_name (| globals, "ommers" |), ltac:(M.monadic ( - let ommer_age := + let _ := M.assign_local (| + "ommer_age" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -1359,8 +1478,10 @@ Definition pay_rewards : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let ommer_miner_reward := + |) + |) in + let _ := M.assign_local (| + "ommer_miner_reward" , BinOp.floor_div (| BinOp.mult (| BinOp.sub (| @@ -1370,7 +1491,8 @@ Definition pay_rewards : Value.t -> Value.t -> M := M.get_name (| globals, "BLOCK_REWARD" |) |), Constant.int 8 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "create_ether" |), make_list [ @@ -1431,9 +1553,12 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender := - M.get_field (| M.get_name (| globals, "env" |), "origin" |) in - let sender_account := + let _ := M.assign_local (| + "sender" , + M.get_field (| M.get_name (| globals, "env" |), "origin" |) + |) in + let _ := M.assign_local (| + "sender_account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1441,12 +1566,15 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "sender" |) ], make_dict [] - |) in - let gas_fee := + |) + |) in + let _ := M.assign_local (| + "gas_fee" , BinOp.mult (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "ensure" |), make_list [ @@ -1487,7 +1615,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let gas := + let _ := M.assign_local (| + "gas" , BinOp.sub (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.call (| @@ -1497,7 +1626,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "increment_nonce" |), make_list [ @@ -1506,11 +1636,13 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let sender_balance_after_gas_fee := + let _ := M.assign_local (| + "sender_balance_after_gas_fee" , BinOp.sub (| M.get_field (| M.get_name (| globals, "sender_account" |), "balance" |), M.get_name (| globals, "gas_fee" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -1520,7 +1652,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let message := + let _ := M.assign_local (| + "message" , M.call (| M.get_name (| globals, "prepare_message" |), make_list [ @@ -1532,8 +1665,10 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in - let output := + |) + |) in + let _ := M.assign_local (| + "output" , M.call (| M.get_name (| globals, "process_message_call" |), make_list [ @@ -1541,13 +1676,17 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in - let gas_used := + |) + |) in + let _ := M.assign_local (| + "gas_used" , BinOp.sub (| M.get_field (| M.get_name (| globals, "tx" |), "gas" |), M.get_field (| M.get_name (| globals, "output" |), "gas_left" |) - |) in - let gas_refund := + |) + |) in + let _ := M.assign_local (| + "gas_refund" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -1558,16 +1697,20 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "output" |), "refund_counter" |) ], make_dict [] - |) in - let gas_refund_amount := + |) + |) in + let _ := M.assign_local (| + "gas_refund_amount" , BinOp.mult (| BinOp.add (| M.get_field (| M.get_name (| globals, "output" |), "gas_left" |), M.get_name (| globals, "gas_refund" |) |), M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) - |) in - let transaction_fee := + |) + |) in + let _ := M.assign_local (| + "transaction_fee" , BinOp.mult (| BinOp.sub (| BinOp.sub (| @@ -1577,13 +1720,17 @@ Definition process_transaction : Value.t -> Value.t -> M := M.get_name (| globals, "gas_refund" |) |), M.get_field (| M.get_name (| globals, "tx" |), "gas_price" |) - |) in - let total_gas_used := + |) + |) in + let _ := M.assign_local (| + "total_gas_used" , BinOp.sub (| M.get_name (| globals, "gas_used" |), M.get_name (| globals, "gas_refund" |) - |) in - let sender_balance_after_refund := + |) + |) in + let _ := M.assign_local (| + "sender_balance_after_refund" , BinOp.add (| M.get_field (| M.call (| M.get_name (| globals, "get_account" |), @@ -1594,7 +1741,8 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |), "balance" |), M.get_name (| globals, "gas_refund_amount" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -1604,7 +1752,8 @@ Definition process_transaction : Value.t -> Value.t -> M := ], make_dict [] |) in - let coinbase_balance_after_mining_fee := + let _ := M.assign_local (| + "coinbase_balance_after_mining_fee" , BinOp.add (| M.get_field (| M.call (| M.get_name (| globals, "get_account" |), @@ -1615,7 +1764,8 @@ Definition process_transaction : Value.t -> Value.t -> M := make_dict [] |), "balance" |), M.get_name (| globals, "transaction_fee" |) - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -1729,8 +1879,10 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := verified : `ethereum.base_types.Uint` The intrinsic cost of the transaction. " in - let data_cost := - Constant.int 0 in + let _ := M.assign_local (| + "data_cost" , + Constant.int 0 + |) in let _ := M.for_ (| M.get_name (| globals, "byte" |), @@ -1745,15 +1897,19 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let data_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "data_cost", M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_ZERO" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let data_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "data_cost", M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) - M.get_name (| globals, "TX_DATA_COST_PER_NON_ZERO" |) in + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -1777,13 +1933,17 @@ Definition calculate_intrinsic_cost : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let create_cost := - M.get_name (| globals, "TX_CREATE_COST" |) in + let _ := M.assign_local (| + "create_cost" , + M.get_name (| globals, "TX_CREATE_COST" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let create_cost := - Constant.int 0 in + let _ := M.assign_local (| + "create_cost" , + Constant.int 0 + |) in M.pure Constant.None_ )) |) in let _ := M.return_ (| @@ -1889,7 +2049,8 @@ Definition recover_sender : Value.t -> Value.t -> M := ], make_dict [] |) in - let public_key := + let _ := M.assign_local (| + "public_key" , M.call (| M.get_name (| globals, "secp256k1_recover" |), make_list [ @@ -1908,7 +2069,8 @@ Definition recover_sender : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Address" |), @@ -2049,11 +2211,13 @@ Definition check_gas_limit : Value.t -> Value.t -> M := check : `bool` True if gas limit constraints are satisfied, False otherwise. " in - let max_adjustment_delta := + let _ := M.assign_local (| + "max_adjustment_delta" , BinOp.floor_div (| M.get_name (| globals, "parent_gas_limit" |), M.get_name (| globals, "GAS_LIMIT_ADJUSTMENT_FACTOR" |) - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -2155,7 +2319,8 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := difficulty : `ethereum.base_types.Uint` Computed difficulty for a block. " in - let offset := + let _ := M.assign_local (| + "offset" , BinOp.mult (| BinOp.floor_div (| M.call (| @@ -2190,8 +2355,10 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := ], make_dict [] |) - |) in - let difficulty := + |) + |) in + let _ := M.assign_local (| + "difficulty" , BinOp.add (| M.call (| M.get_name (| globals, "int" |), @@ -2201,8 +2368,10 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := make_dict [] |), M.get_name (| globals, "offset" |) - |) in - let num_bomb_periods := + |) + |) in + let _ := M.assign_local (| + "num_bomb_periods" , BinOp.sub (| BinOp.floor_div (| M.call (| @@ -2215,7 +2384,8 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := Constant.int 100000 |), Constant.int 2 - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -2225,15 +2395,14 @@ Definition calculate_block_difficulty : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let difficulty := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "difficulty", BinOp.pow (| Constant.int 2, M.get_name (| globals, "num_bomb_periods" |) |) - BinOp.pow (| - Constant.int 2, - M.get_name (| globals, "num_bomb_periods" |) - |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/tangerine_whistle/fork_types.v b/CoqOfPython/ethereum/tangerine_whistle/fork_types.v index 58d7a57..d749dca 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/fork_types.v +++ b/CoqOfPython/ethereum/tangerine_whistle/fork_types.v @@ -17,17 +17,29 @@ Introduction Types re-used throughout the specification, which are specific to Ethereum. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes20"; "Bytes256"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes20 : + IsImported globals "ethereum.base_types" "Bytes20". +Axiom ethereum_base_types_imports_Bytes256 : + IsImported globals "ethereum.base_types" "Bytes256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". Definition Address : Value.t := M.run ltac:(M.monadic ( M.get_name (| globals, "Bytes20" |) diff --git a/CoqOfPython/ethereum/tangerine_whistle/state.v b/CoqOfPython/ethereum/tangerine_whistle/state.v index 26851e6..ffd4f3b 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/state.v +++ b/CoqOfPython/ethereum/tangerine_whistle/state.v @@ -22,23 +22,55 @@ There is a distinction between an account that does not exist and `EMPTY_ACCOUNT`. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass"; "field" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict"; "List"; "Optional"; "Tuple" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "modify" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_tangerine_whistle_fork_types_imports : - AreImported globals "ethereum.tangerine_whistle.fork_types" [ "EMPTY_ACCOUNT"; "Account"; "Address"; "Root" ]. - -Axiom ethereum_tangerine_whistle_trie_imports : - AreImported globals "ethereum.tangerine_whistle.trie" [ "EMPTY_TRIE_ROOT"; "Trie"; "copy_trie"; "root"; "trie_get"; "trie_set" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". +Axiom dataclasses_imports_field : + IsImported globals "dataclasses" "field". + +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_modify : + IsImported globals "ethereum.base_types" "modify". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_tangerine_whistle_fork_types_imports_EMPTY_ACCOUNT : + IsImported globals "ethereum.tangerine_whistle.fork_types" "EMPTY_ACCOUNT". +Axiom ethereum_tangerine_whistle_fork_types_imports_Account : + IsImported globals "ethereum.tangerine_whistle.fork_types" "Account". +Axiom ethereum_tangerine_whistle_fork_types_imports_Address : + IsImported globals "ethereum.tangerine_whistle.fork_types" "Address". +Axiom ethereum_tangerine_whistle_fork_types_imports_Root : + IsImported globals "ethereum.tangerine_whistle.fork_types" "Root". + +Axiom ethereum_tangerine_whistle_trie_imports_EMPTY_TRIE_ROOT : + IsImported globals "ethereum.tangerine_whistle.trie" "EMPTY_TRIE_ROOT". +Axiom ethereum_tangerine_whistle_trie_imports_Trie : + IsImported globals "ethereum.tangerine_whistle.trie" "Trie". +Axiom ethereum_tangerine_whistle_trie_imports_copy_trie : + IsImported globals "ethereum.tangerine_whistle.trie" "copy_trie". +Axiom ethereum_tangerine_whistle_trie_imports_root : + IsImported globals "ethereum.tangerine_whistle.trie" "root". +Axiom ethereum_tangerine_whistle_trie_imports_trie_get : + IsImported globals "ethereum.tangerine_whistle.trie" "trie_get". +Axiom ethereum_tangerine_whistle_trie_imports_trie_set : + IsImported globals "ethereum.tangerine_whistle.trie" "trie_set". Definition State : Value.t := builtins.make_klass @@ -153,7 +185,8 @@ Definition get_account : Value.t -> Value.t -> M := account : `Account` Account at address. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account_optional" |), make_list [ @@ -161,7 +194,8 @@ Definition get_account : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -207,7 +241,8 @@ Definition get_account_optional : Value.t -> Value.t -> M := account : `Account` Account at address. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "trie_get" |), make_list [ @@ -215,7 +250,8 @@ Definition get_account_optional : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "account" |) |) in @@ -338,14 +374,16 @@ Definition get_storage : Value.t -> Value.t -> M := value : `U256` Value at the key. " in - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -369,7 +407,8 @@ Definition get_storage : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "trie_get" |), make_list [ @@ -377,7 +416,8 @@ Definition get_storage : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in let _ := M.assert (| M.call (| M.get_name (| globals, "isinstance" |), make_list [ @@ -420,14 +460,16 @@ Definition set_storage : Value.t -> Value.t -> M := |), Constant.None_ |) |) in - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_field (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), "get" |), make_list [ M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -437,12 +479,14 @@ Definition set_storage : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let trie := + let _ := M.assign_local (| + "trie" , M.call (| M.get_name (| globals, "Trie" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_subscript (| M.get_field (| M.get_name (| globals, "state" |), "_storage_tries" |), @@ -469,7 +513,7 @@ Definition set_storage : Value.t -> Value.t -> M := M.if_then_else (| Compare.eq (| M.get_field (| M.get_name (| globals, "trie" |), "_data" |), - {} + Constant.str "(* At expr: unsupported node type: Dict *)" |), (* then *) ltac:(M.monadic ( @@ -615,7 +659,8 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := True if if an account has non zero nonce or non empty code, False otherwise. " in - let account := + let _ := M.assign_local (| + "account" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -623,7 +668,8 @@ Definition account_has_code_or_nonce : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| BoolOp.or (| Compare.not_eq (| diff --git a/CoqOfPython/ethereum/tangerine_whistle/transactions.v b/CoqOfPython/ethereum/tangerine_whistle/transactions.v index 29fdcd2..cfb821b 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/transactions.v +++ b/CoqOfPython/ethereum/tangerine_whistle/transactions.v @@ -9,17 +9,25 @@ submitted to be executed. If Ethereum is viewed as a state machine, transactions are the events that move between states. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Union" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_tangerine_whistle_fork_types_imports : - AreImported globals "ethereum.tangerine_whistle.fork_types" [ "Address" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_Union : + IsImported globals "typing" "Union". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_tangerine_whistle_fork_types_imports_Address : + IsImported globals "ethereum.tangerine_whistle.fork_types" "Address". Definition TX_BASE_COST : Value.t := M.run ltac:(M.monadic ( Constant.int 21000 diff --git a/CoqOfPython/ethereum/tangerine_whistle/trie.v b/CoqOfPython/ethereum/tangerine_whistle/trie.v index 02f7b48..1390bd6 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/trie.v +++ b/CoqOfPython/ethereum/tangerine_whistle/trie.v @@ -20,38 +20,72 @@ The state trie is the structure responsible for storing (* At top_level_stmt: unsupported node type: Import *) -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass"; "field" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict"; "Generic"; "List"; "Mapping"; "MutableMapping"; "Optional"; "Sequence"; "TypeVar"; "Union"; "cast" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. - -Axiom ethereum_dao_fork_imports : - AreImported globals "ethereum.dao_fork" [ "trie" ]. - -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. - -Axiom ethereum_utils_hexadecimal_imports : - AreImported globals "ethereum.utils.hexadecimal" [ "hex_to_bytes" ]. - -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint"; "slotted_freezable" ]. - -Axiom ethereum_tangerine_whistle_blocks_imports : - AreImported globals "ethereum.tangerine_whistle.blocks" [ "Receipt" ]. - -Axiom ethereum_tangerine_whistle_fork_types_imports : - AreImported globals "ethereum.tangerine_whistle.fork_types" [ "Account"; "Address"; "Root"; "encode_account" ]. - -Axiom ethereum_tangerine_whistle_transactions_imports : - AreImported globals "ethereum.tangerine_whistle.transactions" [ "Transaction" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". +Axiom dataclasses_imports_field : + IsImported globals "dataclasses" "field". + +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". +Axiom typing_imports_Generic : + IsImported globals "typing" "Generic". +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Mapping : + IsImported globals "typing" "Mapping". +Axiom typing_imports_MutableMapping : + IsImported globals "typing" "MutableMapping". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Sequence : + IsImported globals "typing" "Sequence". +Axiom typing_imports_TypeVar : + IsImported globals "typing" "TypeVar". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". +Axiom typing_imports_cast : + IsImported globals "typing" "cast". + +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". + +Axiom ethereum_dao_fork_imports_trie : + IsImported globals "ethereum.dao_fork" "trie". + +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". + +Axiom ethereum_utils_hexadecimal_imports_hex_to_bytes : + IsImported globals "ethereum.utils.hexadecimal" "hex_to_bytes". + +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". +Axiom ethereum_base_types_imports_slotted_freezable : + IsImported globals "ethereum.base_types" "slotted_freezable". + +Axiom ethereum_tangerine_whistle_blocks_imports_Receipt : + IsImported globals "ethereum.tangerine_whistle.blocks" "Receipt". + +Axiom ethereum_tangerine_whistle_fork_types_imports_Account : + IsImported globals "ethereum.tangerine_whistle.fork_types" "Account". +Axiom ethereum_tangerine_whistle_fork_types_imports_Address : + IsImported globals "ethereum.tangerine_whistle.fork_types" "Address". +Axiom ethereum_tangerine_whistle_fork_types_imports_Root : + IsImported globals "ethereum.tangerine_whistle.fork_types" "Root". +Axiom ethereum_tangerine_whistle_fork_types_imports_encode_account : + IsImported globals "ethereum.tangerine_whistle.fork_types" "encode_account". + +Axiom ethereum_tangerine_whistle_transactions_imports_Transaction : + IsImported globals "ethereum.tangerine_whistle.transactions" "Transaction". Definition EMPTY_TRIE_ROOT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -161,7 +195,7 @@ Definition encode_internal_node : Value.t -> Value.t -> M := when serialized. This function also accepts `None`, representing the absence of a node, - which is encoded to `b""""""`. + which is encoded to `b""""`. Parameters ---------- @@ -183,8 +217,10 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := - Constant.bytes "" in + let _ := M.assign_local (| + "unencoded" , + Constant.bytes "" + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -201,7 +237,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := + let _ := M.assign_local (| + "unencoded" , make_tuple [ M.call (| M.get_name (| globals, "nibble_list_to_compact" |), make_list [ @@ -209,7 +246,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := Constant.bool true ], make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] in + |); M.get_field (| M.get_name (| globals, "node" |), "value" |) ] + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -226,7 +264,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := + let _ := M.assign_local (| + "unencoded" , make_tuple [ M.call (| M.get_name (| globals, "nibble_list_to_compact" |), make_list [ @@ -234,7 +273,8 @@ Definition encode_internal_node : Value.t -> Value.t -> M := Constant.bool false ], make_dict [] - |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] in + |); M.get_field (| M.get_name (| globals, "node" |), "subnode" |) ] + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -251,13 +291,15 @@ Definition encode_internal_node : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let unencoded := + let _ := M.assign_local (| + "unencoded" , BinOp.add (| M.get_field (| M.get_name (| globals, "node" |), "subnodes" |), make_list [ M.get_field (| M.get_name (| globals, "node" |), "value" |) ] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -276,14 +318,16 @@ Definition encode_internal_node : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - let encoded := + let _ := M.assign_local (| + "encoded" , M.call (| M.get_field (| M.get_name (| globals, "rlp" |), "encode" |), make_list [ M.get_name (| globals, "unencoded" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -675,12 +719,14 @@ Definition nibble_list_to_compact : Value.t -> Value.t -> M := compressed : `bytearray` Compact byte array. " in - let compact := + let _ := M.assign_local (| + "compact" , M.call (| M.get_name (| globals, "bytearray" |), make_list [], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -860,7 +906,8 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := nibble_list : `Bytes` The `Bytes` in nibble-list format. " in - let nibble_list := + let _ := M.assign_local (| + "nibble_list" , M.call (| M.get_name (| globals, "bytearray" |), make_list [ @@ -876,7 +923,8 @@ Definition bytes_to_nibble_list : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| make_tuple [ M.get_name (| globals, "byte_index" |); M.get_name (| globals, "byte" |) ], @@ -984,15 +1032,18 @@ Definition _prepare_trie : Value.t -> Value.t -> M := M.get_name (| globals, "get_storage_root" |), Constant.None_ |) |) in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "Address" |), make_list [ M.get_name (| globals, "preimage" |) ], make_dict [] - |) in - let encoded_value := + |) + |) in + let _ := M.assign_local (| + "encoded_value" , M.call (| M.get_name (| globals, "encode_node" |), make_list [ @@ -1006,18 +1057,21 @@ Definition _prepare_trie : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let encoded_value := + let _ := M.assign_local (| + "encoded_value" , M.call (| M.get_name (| globals, "encode_node" |), make_list [ M.get_name (| globals, "value" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -1038,19 +1092,23 @@ Definition _prepare_trie : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "trie" |), "secured" |), (* then *) ltac:(M.monadic ( - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "preimage" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let key := - M.get_name (| globals, "preimage" |) in + let _ := M.assign_local (| + "key" , + M.get_name (| globals, "preimage" |) + |) in M.pure Constant.None_ )) |) in let _ := M.assign (| @@ -1097,7 +1155,8 @@ Definition root : Value.t -> Value.t -> M := root : `.fork_types.Root` MPT root of the underlying key-value pairs. " in - let obj := + let _ := M.assign_local (| + "obj" , M.call (| M.get_name (| globals, "_prepare_trie" |), make_list [ @@ -1105,8 +1164,10 @@ Definition root : Value.t -> Value.t -> M := M.get_name (| globals, "get_storage_root" |) ], make_dict [] - |) in - let root_node := + |) + |) in + let _ := M.assign_local (| + "root_node" , M.call (| M.get_name (| globals, "encode_internal_node" |), make_list [ @@ -1126,7 +1187,8 @@ Definition root : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1231,7 +1293,8 @@ Definition patricialize : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let arbitrary_key := + let _ := M.assign_local (| + "arbitrary_key" , M.call (| M.get_name (| globals, "next" |), make_list [ @@ -1244,7 +1307,8 @@ Definition patricialize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1260,7 +1324,8 @@ Definition patricialize : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let leaf := + let _ := M.assign_local (| + "leaf" , M.call (| M.get_name (| globals, "LeafNode" |), make_list [ @@ -1276,7 +1341,8 @@ Definition patricialize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.get_name (| globals, "leaf" |) |) in @@ -1285,27 +1351,32 @@ Definition patricialize : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let substring := + let _ := M.assign_local (| + "substring" , M.slice (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |), Constant.None_, Constant.None_ - |) in - let prefix_length := + |) + |) in + let _ := M.assign_local (| + "prefix_length" , M.call (| M.get_name (| globals, "len" |), make_list [ M.get_name (| globals, "substring" |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| M.get_name (| globals, "key" |), M.get_name (| globals, "obj" |), ltac:(M.monadic ( - let prefix_length := + let _ := M.assign_local (| + "prefix_length" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -1325,7 +1396,8 @@ Definition patricialize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1356,7 +1428,8 @@ Definition patricialize : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let prefix := + let _ := M.assign_local (| + "prefix" , M.slice (| M.get_name (| globals, "arbitrary_key" |), M.get_name (| globals, "level" |), @@ -1365,7 +1438,8 @@ Definition patricialize : Value.t -> Value.t -> M := M.get_name (| globals, "prefix_length" |) |), Constant.None_ - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "ExtensionNode" |), @@ -1412,7 +1486,7 @@ Definition patricialize : Value.t -> Value.t -> M := let _ := M.call (| M.get_field (| M.get_name (| globals, "branches" |), "append" |), make_list [ - {} + Constant.str "(* At expr: unsupported node type: Dict *)" ], make_dict [] |) in @@ -1422,8 +1496,10 @@ Definition patricialize : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let value := - Constant.bytes "" in + let _ := M.assign_local (| + "value" , + Constant.bytes "" + |) in let _ := M.for_ (| M.get_name (| globals, "key" |), @@ -1466,11 +1542,13 @@ Definition patricialize : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let value := + let _ := M.assign_local (| + "value" , M.get_subscript (| M.get_name (| globals, "obj" |), M.get_name (| globals, "key" |) - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/tangerine_whistle/utils/address.v b/CoqOfPython/ethereum/tangerine_whistle/utils/address.v index 3acee7a..e130a74 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/utils/address.v +++ b/CoqOfPython/ethereum/tangerine_whistle/utils/address.v @@ -18,23 +18,25 @@ Address specific functions used in this tangerine whistle version of specification. ". -Axiom typing_imports : - AreImported globals "typing" [ "Union" ]. +Axiom typing_imports_Union : + IsImported globals "typing" "Union". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_left_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "left_pad_zero_bytes". -Axiom ethereum_imports : - AreImported globals "ethereum" [ "rlp" ]. +Axiom ethereum_imports_rlp : + IsImported globals "ethereum" "rlp". -Axiom ethereum_tangerine_whistle_fork_types_imports : - AreImported globals "ethereum.tangerine_whistle.fork_types" [ "Address" ]. +Axiom ethereum_tangerine_whistle_fork_types_imports_Address : + IsImported globals "ethereum.tangerine_whistle.fork_types" "Address". Definition to_address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -91,7 +93,8 @@ Definition compute_contract_address : Value.t -> Value.t -> M := address: `ethereum.tangerine_whistle.fork_types.Address` The computed address of the new account. " in - let computed_address := + let _ := M.assign_local (| + "computed_address" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ @@ -107,15 +110,19 @@ Definition compute_contract_address : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let canonical_address := + |) + |) in + let _ := M.assign_local (| + "canonical_address" , M.slice (| M.get_name (| globals, "computed_address" |), UnOp.sub (| Constant.int 20 |), Constant.None_, Constant.None_ - |) in - let padded_address := + |) + |) in + let _ := M.assign_local (| + "padded_address" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -123,7 +130,8 @@ Definition compute_contract_address : Value.t -> Value.t -> M := Constant.int 20 ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "Address" |), diff --git a/CoqOfPython/ethereum/tangerine_whistle/utils/hexadecimal.v b/CoqOfPython/ethereum/tangerine_whistle/utils/hexadecimal.v index 3ba1301..0079ced 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/tangerine_whistle/utils/hexadecimal.v @@ -18,11 +18,15 @@ Hexadecimal utility functions used in this specification, specific to Tangerine Whistle types. ". -Axiom ethereum_utils_hexadecimal_imports : - AreImported globals "ethereum.utils.hexadecimal" [ "remove_hex_prefix" ]. - -Axiom ethereum_tangerine_whistle_fork_types_imports : - AreImported globals "ethereum.tangerine_whistle.fork_types" [ "Address"; "Bloom"; "Root" ]. +Axiom ethereum_utils_hexadecimal_imports_remove_hex_prefix : + IsImported globals "ethereum.utils.hexadecimal" "remove_hex_prefix". + +Axiom ethereum_tangerine_whistle_fork_types_imports_Address : + IsImported globals "ethereum.tangerine_whistle.fork_types" "Address". +Axiom ethereum_tangerine_whistle_fork_types_imports_Bloom : + IsImported globals "ethereum.tangerine_whistle.fork_types" "Bloom". +Axiom ethereum_tangerine_whistle_fork_types_imports_Root : + IsImported globals "ethereum.tangerine_whistle.fork_types" "Root". Definition hex_to_root : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/tangerine_whistle/utils/message.v b/CoqOfPython/ethereum/tangerine_whistle/utils/message.v index d1c4cdc..8382bfd 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/utils/message.v +++ b/CoqOfPython/ethereum/tangerine_whistle/utils/message.v @@ -18,23 +18,33 @@ Message specific functions used in this tangerine whistle version of specification. ". -Axiom typing_imports : - AreImported globals "typing" [ "Optional"; "Union" ]. +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_tangerine_whistle_fork_types_imports : - AreImported globals "ethereum.tangerine_whistle.fork_types" [ "Address" ]. +Axiom ethereum_tangerine_whistle_fork_types_imports_Address : + IsImported globals "ethereum.tangerine_whistle.fork_types" "Address". -Axiom ethereum_tangerine_whistle_state_imports : - AreImported globals "ethereum.tangerine_whistle.state" [ "get_account" ]. +Axiom ethereum_tangerine_whistle_state_imports_get_account : + IsImported globals "ethereum.tangerine_whistle.state" "get_account". -Axiom ethereum_tangerine_whistle_vm_imports : - AreImported globals "ethereum.tangerine_whistle.vm" [ "Environment"; "Message" ]. +Axiom ethereum_tangerine_whistle_vm_imports_Environment : + IsImported globals "ethereum.tangerine_whistle.vm" "Environment". +Axiom ethereum_tangerine_whistle_vm_imports_Message : + IsImported globals "ethereum.tangerine_whistle.vm" "Message". -Axiom ethereum_tangerine_whistle_utils_address_imports : - AreImported globals "ethereum.tangerine_whistle.utils.address" [ "compute_contract_address" ]. +Axiom ethereum_tangerine_whistle_utils_address_imports_compute_contract_address : + IsImported globals "ethereum.tangerine_whistle.utils.address" "compute_contract_address". Definition prepare_message : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -81,7 +91,8 @@ Definition prepare_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let current_target := + let _ := M.assign_local (| + "current_target" , M.call (| M.get_name (| globals, "compute_contract_address" |), make_list [ @@ -105,17 +116,22 @@ Definition prepare_message : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let msg_data := + |) + |) in + let _ := M.assign_local (| + "msg_data" , M.call (| M.get_name (| globals, "Bytes" |), make_list [ Constant.bytes "" ], make_dict [] - |) in - let code := - M.get_name (| globals, "data" |) in + |) + |) in + let _ := M.assign_local (| + "code" , + M.get_name (| globals, "data" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -132,11 +148,16 @@ Definition prepare_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let current_target := - M.get_name (| globals, "target" |) in - let msg_data := - M.get_name (| globals, "data" |) in - let code := + let _ := M.assign_local (| + "current_target" , + M.get_name (| globals, "target" |) + |) in + let _ := M.assign_local (| + "msg_data" , + M.get_name (| globals, "data" |) + |) in + let _ := M.assign_local (| + "code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -144,7 +165,8 @@ Definition prepare_message : Value.t -> Value.t -> M := M.get_name (| globals, "target" |) ], make_dict [] - |), "code" |) in + |), "code" |) + |) in let _ := (* if *) M.if_then_else (| @@ -154,8 +176,10 @@ Definition prepare_message : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let code_address := - M.get_name (| globals, "target" |) in + let _ := M.assign_local (| + "code_address" , + M.get_name (| globals, "target" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/__init__.v b/CoqOfPython/ethereum/tangerine_whistle/vm/__init__.v index f840ed3..fb5763a 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/__init__.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/__init__.v @@ -18,26 +18,40 @@ The abstract computer which runs the code stored in an `.fork_types.Account`. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Optional"; "Set"; "Tuple"; "Union" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Bytes0"; "Uint" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. - -Axiom ethereum_tangerine_whistle_blocks_imports : - AreImported globals "ethereum.tangerine_whistle.blocks" [ "Log" ]. - -Axiom ethereum_tangerine_whistle_fork_types_imports : - AreImported globals "ethereum.tangerine_whistle.fork_types" [ "Address" ]. - -Axiom ethereum_tangerine_whistle_state_imports : - AreImported globals "ethereum.tangerine_whistle.state" [ "State" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". + +Axiom ethereum_tangerine_whistle_blocks_imports_Log : + IsImported globals "ethereum.tangerine_whistle.blocks" "Log". + +Axiom ethereum_tangerine_whistle_fork_types_imports_Address : + IsImported globals "ethereum.tangerine_whistle.fork_types" "Address". + +Axiom ethereum_tangerine_whistle_state_imports_State : + IsImported globals "ethereum.tangerine_whistle.state" "State". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "Environment"; Constant.str "Evm"; Constant.str "Message" ] diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/exceptions.v b/CoqOfPython/ethereum/tangerine_whistle/vm/exceptions.v index 3a03a51..97898c1 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/exceptions.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/exceptions.v @@ -17,8 +17,8 @@ Introduction Exceptions which cause the EVM to halt exceptionally. ". -Axiom ethereum_exceptions_imports : - AreImported globals "ethereum.exceptions" [ "EthereumException" ]. +Axiom ethereum_exceptions_imports_EthereumException : + IsImported globals "ethereum.exceptions" "EthereumException". Definition ExceptionalHalt : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/gas.v b/CoqOfPython/ethereum/tangerine_whistle/vm/gas.v index 31134c8..716b689 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/gas.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/gas.v @@ -17,26 +17,32 @@ Introduction EVM gas constants and calculators. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". -Axiom typing_imports : - AreImported globals "typing" [ "List"; "Tuple" ]. +Axiom typing_imports_List : + IsImported globals "typing" "List". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_trace_imports : - AreImported globals "ethereum.trace" [ "GasAndRefund"; "evm_trace" ]. +Axiom ethereum_trace_imports_GasAndRefund : + IsImported globals "ethereum.trace" "GasAndRefund". +Axiom ethereum_trace_imports_evm_trace : + IsImported globals "ethereum.trace" "evm_trace". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_tangerine_whistle_vm_imports : - AreImported globals "ethereum.tangerine_whistle.vm" [ "Evm" ]. +Axiom ethereum_tangerine_whistle_vm_imports_Evm : + IsImported globals "ethereum.tangerine_whistle.vm" "Evm". -Axiom ethereum_tangerine_whistle_vm_exceptions_imports : - AreImported globals "ethereum.tangerine_whistle.vm.exceptions" [ "OutOfGasError" ]. +Axiom ethereum_tangerine_whistle_vm_exceptions_imports_OutOfGasError : + IsImported globals "ethereum.tangerine_whistle.vm.exceptions" "OutOfGasError". Definition GAS_JUMPDEST : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -522,7 +528,8 @@ Definition calculate_memory_gas_cost : Value.t -> Value.t -> M := total_gas_cost : `ethereum.base_types.Uint` The gas cost for storing data in memory. " in - let size_in_words := + let _ := M.assign_local (| + "size_in_words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -532,25 +539,32 @@ Definition calculate_memory_gas_cost : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let linear_cost := + |) + |) in + let _ := M.assign_local (| + "linear_cost" , BinOp.mult (| M.get_name (| globals, "size_in_words" |), M.get_name (| globals, "GAS_MEMORY" |) - |) in - let quadratic_cost := + |) + |) in + let _ := M.assign_local (| + "quadratic_cost" , BinOp.floor_div (| BinOp.pow (| M.get_name (| globals, "size_in_words" |), Constant.int 2 |), Constant.int 512 - |) in - let total_gas_cost := + |) + |) in + let _ := M.assign_local (| + "total_gas_cost" , BinOp.add (| M.get_name (| globals, "linear_cost" |), M.get_name (| globals, "quadratic_cost" |) - |) in + |) + |) in (* At stmt: unsupported node type: Try *) M.pure Constant.None_)). @@ -572,23 +586,28 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := ------- extend_memory: `ExtendMemory` " in - let size_to_extend := + let _ := M.assign_local (| + "size_to_extend" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in - let to_be_paid := + |) + |) in + let _ := M.assign_local (| + "to_be_paid" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in - let current_size := + |) + |) in + let _ := M.assign_local (| + "current_size" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -601,7 +620,8 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.for_ (| make_tuple [ M.get_name (| globals, "start_position" |); M.get_name (| globals, "size" |) ], @@ -622,15 +642,18 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let before_size := + let _ := M.assign_local (| + "before_size" , M.call (| M.get_name (| globals, "ceil32" |), make_list [ M.get_name (| globals, "current_size" |) ], make_dict [] - |) in - let after_size := + |) + |) in + let _ := M.assign_local (| + "after_size" , M.call (| M.get_name (| globals, "ceil32" |), make_list [ @@ -652,7 +675,8 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -668,42 +692,46 @@ Definition calculate_gas_extend_memory : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let size_to_extend := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "size_to_extend", BinOp.sub (| M.get_name (| globals, "after_size" |), M.get_name (| globals, "before_size" |) |) - BinOp.sub (| - M.get_name (| globals, "after_size" |), - M.get_name (| globals, "before_size" |) - |) in - let already_paid := + |) in + let _ := M.assign_local (| + "already_paid" , M.call (| M.get_name (| globals, "calculate_memory_gas_cost" |), make_list [ M.get_name (| globals, "before_size" |) ], make_dict [] - |) in - let total_cost := + |) + |) in + let _ := M.assign_local (| + "total_cost" , M.call (| M.get_name (| globals, "calculate_memory_gas_cost" |), make_list [ M.get_name (| globals, "after_size" |) ], make_dict [] - |) in - let to_be_paid := BinOp.add + |) + |) in + let _ := M.assign_op_local (| + BinOp.add, + "to_be_paid", BinOp.sub (| M.get_name (| globals, "total_cost" |), M.get_name (| globals, "already_paid" |) |) - BinOp.sub (| - M.get_name (| globals, "total_cost" |), - M.get_name (| globals, "already_paid" |) - |) in - let current_size := - M.get_name (| globals, "after_size" |) in + |) in + let _ := M.assign_local (| + "current_size" , + M.get_name (| globals, "after_size" |) + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -750,7 +778,8 @@ Definition calculate_message_call_gas : Value.t -> Value.t -> M := ------- message_call_gas: `MessageCallGas` " in - let call_stipend := + let _ := M.assign_local (| + "call_stipend" , (* if *) M.if_then_else (| Compare.eq (| @@ -769,7 +798,8 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "call_stipend" |) - )) |) in + )) |) + |) in let _ := (* if *) M.if_then_else (| @@ -803,7 +833,8 @@ M.get_name (| globals, "call_stipend" |) )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -823,7 +854,8 @@ M.get_name (| globals, "call_stipend" |) |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_name (| globals, "MessageCallGas" |), diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/__init__.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/__init__.v index cb5f046..22a0b88 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/__init__.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/__init__.v @@ -20,44 +20,46 @@ implementations. (* At top_level_stmt: unsupported node type: Import *) -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict" ]. +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". -Axiom ethereum_tangerine_whistle_vm_instructions_imports : - AreImported globals "ethereum.tangerine_whistle.vm.instructions" [ "arithmetic" ]. +Axiom ethereum_tangerine_whistle_vm_instructions_imports_arithmetic : + IsImported globals "ethereum.tangerine_whistle.vm.instructions" "arithmetic". -Axiom ethereum_tangerine_whistle_vm_instructions_imports : - AreImported globals "ethereum.tangerine_whistle.vm.instructions" [ "bitwise" ]. +Axiom ethereum_tangerine_whistle_vm_instructions_imports_bitwise : + IsImported globals "ethereum.tangerine_whistle.vm.instructions" "bitwise". -Axiom ethereum_tangerine_whistle_vm_instructions_imports : - AreImported globals "ethereum.tangerine_whistle.vm.instructions" [ "block" ]. +Axiom ethereum_tangerine_whistle_vm_instructions_imports_block : + IsImported globals "ethereum.tangerine_whistle.vm.instructions" "block". -Axiom ethereum_tangerine_whistle_vm_instructions_imports : - AreImported globals "ethereum.tangerine_whistle.vm.instructions" [ "comparison" ]. +Axiom ethereum_tangerine_whistle_vm_instructions_imports_comparison : + IsImported globals "ethereum.tangerine_whistle.vm.instructions" "comparison". -Axiom ethereum_tangerine_whistle_vm_instructions_imports : - AreImported globals "ethereum.tangerine_whistle.vm.instructions" [ "control_flow" ]. +Axiom ethereum_tangerine_whistle_vm_instructions_imports_control_flow : + IsImported globals "ethereum.tangerine_whistle.vm.instructions" "control_flow". -Axiom ethereum_tangerine_whistle_vm_instructions_imports : - AreImported globals "ethereum.tangerine_whistle.vm.instructions" [ "environment" ]. +Axiom ethereum_tangerine_whistle_vm_instructions_imports_environment : + IsImported globals "ethereum.tangerine_whistle.vm.instructions" "environment". -Axiom ethereum_tangerine_whistle_vm_instructions_imports : - AreImported globals "ethereum.tangerine_whistle.vm.instructions" [ "keccak" ]. +Axiom ethereum_tangerine_whistle_vm_instructions_imports_keccak : + IsImported globals "ethereum.tangerine_whistle.vm.instructions" "keccak". -Axiom ethereum_tangerine_whistle_vm_instructions_imports : - AreImported globals "ethereum.tangerine_whistle.vm.instructions" [ "log" ]. +Axiom ethereum_tangerine_whistle_vm_instructions_imports_log : + IsImported globals "ethereum.tangerine_whistle.vm.instructions" "log". -Axiom ethereum_tangerine_whistle_vm_instructions_imports : - AreImported globals "ethereum.tangerine_whistle.vm.instructions" [ "memory" ]. +Axiom ethereum_tangerine_whistle_vm_instructions_imports_memory : + IsImported globals "ethereum.tangerine_whistle.vm.instructions" "memory". -Axiom ethereum_tangerine_whistle_vm_instructions_imports : - AreImported globals "ethereum.tangerine_whistle.vm.instructions" [ "stack" ]. +Axiom ethereum_tangerine_whistle_vm_instructions_imports_stack : + IsImported globals "ethereum.tangerine_whistle.vm.instructions" "stack". -Axiom ethereum_tangerine_whistle_vm_instructions_imports : - AreImported globals "ethereum.tangerine_whistle.vm.instructions" [ "storage" ]. +Axiom ethereum_tangerine_whistle_vm_instructions_imports_storage : + IsImported globals "ethereum.tangerine_whistle.vm.instructions" "storage". -Axiom ethereum_tangerine_whistle_vm_instructions_imports : - AreImported globals "ethereum.tangerine_whistle.vm.instructions" [ "system" ]. +Axiom ethereum_tangerine_whistle_vm_instructions_imports_system : + IsImported globals "ethereum.tangerine_whistle.vm.instructions" "system". Definition Ops : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/arithmetic.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/arithmetic.v index b72a216..6908f7e 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/arithmetic.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/arithmetic.v @@ -17,20 +17,38 @@ Introduction Implementations of the EVM Arithmetic instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U255_CEIL_VALUE"; "U256"; "U256_CEIL_VALUE"; "Uint" ]. +Axiom ethereum_base_types_imports_U255_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U255_CEIL_VALUE". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_U256_CEIL_VALUE : + IsImported globals "ethereum.base_types" "U256_CEIL_VALUE". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "get_sign" ]. +Axiom ethereum_utils_numeric_imports_get_sign : + IsImported globals "ethereum.utils.numeric" "get_sign". -Axiom ethereum_tangerine_whistle_vm_imports : - AreImported globals "ethereum.tangerine_whistle.vm" [ "Evm" ]. +Axiom ethereum_tangerine_whistle_vm_imports_Evm : + IsImported globals "ethereum.tangerine_whistle.vm" "Evm". -Axiom ethereum_tangerine_whistle_vm_gas_imports : - AreImported globals "ethereum.tangerine_whistle.vm.gas" [ "GAS_EXPONENTIATION"; "GAS_EXPONENTIATION_PER_BYTE"; "GAS_LOW"; "GAS_MID"; "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_tangerine_whistle_vm_gas_imports_GAS_EXPONENTIATION : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "GAS_EXPONENTIATION". +Axiom ethereum_tangerine_whistle_vm_gas_imports_GAS_EXPONENTIATION_PER_BYTE : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "GAS_EXPONENTIATION_PER_BYTE". +Axiom ethereum_tangerine_whistle_vm_gas_imports_GAS_LOW : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "GAS_LOW". +Axiom ethereum_tangerine_whistle_vm_gas_imports_GAS_MID : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "GAS_MID". +Axiom ethereum_tangerine_whistle_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_tangerine_whistle_vm_gas_imports_charge_gas : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "charge_gas". -Axiom ethereum_tangerine_whistle_vm_stack_imports : - AreImported globals "ethereum.tangerine_whistle.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_tangerine_whistle_vm_stack_imports_pop : + IsImported globals "ethereum.tangerine_whistle.vm.stack" "pop". +Axiom ethereum_tangerine_whistle_vm_stack_imports_push : + IsImported globals "ethereum.tangerine_whistle.vm.stack" "push". Definition add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,22 +63,26 @@ Definition add : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -69,14 +91,16 @@ Definition add : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "x" |), "wrapping_add" |), make_list [ M.get_name (| globals, "y" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -105,22 +129,26 @@ Definition sub : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -129,14 +157,16 @@ Definition sub : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "x" |), "wrapping_sub" |), make_list [ M.get_name (| globals, "y" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -165,22 +195,26 @@ Definition mul : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -189,14 +223,16 @@ Definition mul : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "x" |), "wrapping_mul" |), make_list [ M.get_name (| globals, "y" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -225,22 +261,26 @@ Definition div : Value.t -> Value.t -> M := The current EVM frame. " in - let dividend := + let _ := M.assign_local (| + "dividend" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let divisor := + |) + |) in + let _ := M.assign_local (| + "divisor" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -258,22 +298,26 @@ Definition div : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let quotient := + let _ := M.assign_local (| + "quotient" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let quotient := + let _ := M.assign_local (| + "quotient" , BinOp.floor_div (| M.get_name (| globals, "dividend" |), M.get_name (| globals, "divisor" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -304,7 +348,8 @@ Definition sdiv : Value.t -> Value.t -> M := The current EVM frame. " in - let dividend := + let _ := M.assign_local (| + "dividend" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -315,8 +360,10 @@ Definition sdiv : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let divisor := + |) + |) in + let _ := M.assign_local (| + "divisor" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -327,7 +374,8 @@ Definition sdiv : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -345,8 +393,10 @@ Definition sdiv : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let quotient := - Constant.int 0 in + let _ := M.assign_local (| + "quotient" , + Constant.int 0 + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -367,12 +417,15 @@ Definition sdiv : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let quotient := - UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) in + let _ := M.assign_local (| + "quotient" , + UnOp.sub (| M.get_name (| globals, "U255_CEIL_VALUE" |) |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let sign := + let _ := M.assign_local (| + "sign" , M.call (| M.get_name (| globals, "get_sign" |), make_list [ @@ -382,8 +435,10 @@ Definition sdiv : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let quotient := + |) + |) in + let _ := M.assign_local (| + "quotient" , BinOp.mult (| M.get_name (| globals, "sign" |), BinOp.floor_div (| @@ -402,7 +457,8 @@ Definition sdiv : Value.t -> Value.t -> M := make_dict [] |) |) - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ @@ -428,7 +484,7 @@ Definition sdiv : Value.t -> Value.t -> M := |) in M.pure Constant.None_)). -Definition mod : Value.t -> Value.t -> M := +Definition mod_ : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( let _ := M.set_locals (| args, kwargs, [ "evm" ] |) in let _ := Constant.str " @@ -441,22 +497,26 @@ Definition mod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -474,22 +534,26 @@ Definition mod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let remainder := + let _ := M.assign_local (| + "remainder" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let remainder := + let _ := M.assign_local (| + "remainder" , BinOp.mod_ (| M.get_name (| globals, "x" |), M.get_name (| globals, "y" |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -520,7 +584,8 @@ Definition smod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -531,8 +596,10 @@ Definition smod : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -543,7 +610,8 @@ Definition smod : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -561,12 +629,15 @@ Definition smod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let remainder := - Constant.int 0 in + let _ := M.assign_local (| + "remainder" , + Constant.int 0 + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let remainder := + let _ := M.assign_local (| + "remainder" , BinOp.mult (| M.call (| M.get_name (| globals, "get_sign" |), @@ -591,7 +662,8 @@ Definition smod : Value.t -> Value.t -> M := make_dict [] |) |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -628,7 +700,8 @@ Definition addmod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -641,8 +714,10 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -655,8 +730,10 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let z := + |) + |) in + let _ := M.assign_local (| + "z" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -669,7 +746,8 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -687,18 +765,21 @@ Definition addmod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -711,7 +792,8 @@ Definition addmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -742,7 +824,8 @@ Definition mulmod : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -755,8 +838,10 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -769,8 +854,10 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let z := + |) + |) in + let _ := M.assign_local (| + "z" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -783,7 +870,8 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -801,18 +889,21 @@ Definition mulmod : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -825,7 +916,8 @@ Definition mulmod : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| @@ -856,7 +948,8 @@ Definition exp : Value.t -> Value.t -> M := The current EVM frame. " in - let base := + let _ := M.assign_local (| + "base" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -869,8 +962,10 @@ Definition exp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exponent := + |) + |) in + let _ := M.assign_local (| + "exponent" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -883,21 +978,26 @@ Definition exp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let exponent_bits := + |) + |) in + let _ := M.assign_local (| + "exponent_bits" , M.call (| M.get_field (| M.get_name (| globals, "exponent" |), "bit_length" |), make_list [], make_dict [] - |) in - let exponent_bytes := + |) + |) in + let _ := M.assign_local (| + "exponent_bytes" , BinOp.floor_div (| BinOp.add (| M.get_name (| globals, "exponent_bits" |), Constant.int 7 |), Constant.int 8 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -912,7 +1012,8 @@ Definition exp : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -927,7 +1028,8 @@ Definition exp : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -956,22 +1058,26 @@ Definition signextend : Value.t -> Value.t -> M := The current EVM frame. " in - let byte_num := + let _ := M.assign_local (| + "byte_num" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -989,12 +1095,15 @@ Definition signextend : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := - M.get_name (| globals, "value" |) in + let _ := M.assign_local (| + "result" , + M.get_name (| globals, "value" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let value_bytes := + let _ := M.assign_local (| + "value_bytes" , M.call (| M.get_name (| globals, "bytes" |), make_list [ @@ -1005,8 +1114,10 @@ Definition signextend : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let value_bytes := + |) + |) in + let _ := M.assign_local (| + "value_bytes" , M.slice (| M.get_name (| globals, "value_bytes" |), BinOp.sub (| @@ -1021,15 +1132,18 @@ Definition signextend : Value.t -> Value.t -> M := |), Constant.None_, Constant.None_ - |) in - let sign_bit := + |) + |) in + let _ := M.assign_local (| + "sign_bit" , BinOp.r_shift (| M.get_subscript (| M.get_name (| globals, "value_bytes" |), Constant.int 0 |), Constant.int 7 - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -1039,26 +1153,31 @@ Definition signextend : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ M.get_name (| globals, "value_bytes" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let num_bytes_prepend := + let _ := M.assign_local (| + "num_bytes_prepend" , BinOp.sub (| Constant.int 32, BinOp.add (| M.get_name (| globals, "byte_num" |), Constant.int 1 |) - |) in - let result := + |) + |) in + let _ := M.assign_local (| + "result" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -1079,7 +1198,8 @@ Definition signextend : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/bitwise.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/bitwise.v index 476749d..b526d4e 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/bitwise.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/bitwise.v @@ -17,17 +17,21 @@ Introduction Implementations of the EVM bitwise instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_tangerine_whistle_vm_imports : - AreImported globals "ethereum.tangerine_whistle.vm" [ "Evm" ]. +Axiom ethereum_tangerine_whistle_vm_imports_Evm : + IsImported globals "ethereum.tangerine_whistle.vm" "Evm". -Axiom ethereum_tangerine_whistle_vm_gas_imports : - AreImported globals "ethereum.tangerine_whistle.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_tangerine_whistle_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_tangerine_whistle_vm_gas_imports_charge_gas : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "charge_gas". -Axiom ethereum_tangerine_whistle_vm_stack_imports : - AreImported globals "ethereum.tangerine_whistle.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_tangerine_whistle_vm_stack_imports_pop : + IsImported globals "ethereum.tangerine_whistle.vm.stack" "pop". +Axiom ethereum_tangerine_whistle_vm_stack_imports_push : + IsImported globals "ethereum.tangerine_whistle.vm.stack" "push". Definition bitwise_and : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,22 +46,26 @@ Definition bitwise_and : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -97,22 +105,26 @@ Definition bitwise_or : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -152,22 +164,26 @@ Definition bitwise_xor : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let y := + |) + |) in + let _ := M.assign_local (| + "y" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -207,14 +223,16 @@ Definition bitwise_not : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -252,22 +270,26 @@ Definition get_byte : Value.t -> Value.t -> M := The current EVM frame. " in - let byte_index := + let _ := M.assign_local (| + "byte_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let word := + |) + |) in + let _ := M.assign_local (| + "word" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -285,43 +307,53 @@ Definition get_byte : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let extra_bytes_to_right := + let _ := M.assign_local (| + "extra_bytes_to_right" , BinOp.sub (| Constant.int 31, M.get_name (| globals, "byte_index" |) - |) in - let word := + |) + |) in + let _ := M.assign_local (| + "word" , BinOp.r_shift (| M.get_name (| globals, "word" |), BinOp.mult (| M.get_name (| globals, "extra_bytes_to_right" |), Constant.int 8 |) - |) in - let word := + |) + |) in + let _ := M.assign_local (| + "word" , BinOp.bit_and (| M.get_name (| globals, "word" |), Constant.int 255 - |) in - let result := + |) + |) in + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ M.get_name (| globals, "word" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/block.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/block.v index 976f1f2..22c744e 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/block.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/block.v @@ -17,17 +17,23 @@ Introduction Implementations of the EVM block instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_tangerine_whistle_vm_imports : - AreImported globals "ethereum.tangerine_whistle.vm" [ "Evm" ]. +Axiom ethereum_tangerine_whistle_vm_imports_Evm : + IsImported globals "ethereum.tangerine_whistle.vm" "Evm". -Axiom ethereum_tangerine_whistle_vm_gas_imports : - AreImported globals "ethereum.tangerine_whistle.vm.gas" [ "GAS_BASE"; "GAS_BLOCK_HASH"; "charge_gas" ]. +Axiom ethereum_tangerine_whistle_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "GAS_BASE". +Axiom ethereum_tangerine_whistle_vm_gas_imports_GAS_BLOCK_HASH : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "GAS_BLOCK_HASH". +Axiom ethereum_tangerine_whistle_vm_gas_imports_charge_gas : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "charge_gas". -Axiom ethereum_tangerine_whistle_vm_stack_imports : - AreImported globals "ethereum.tangerine_whistle.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_tangerine_whistle_vm_stack_imports_pop : + IsImported globals "ethereum.tangerine_whistle.vm.stack" "pop". +Axiom ethereum_tangerine_whistle_vm_stack_imports_push : + IsImported globals "ethereum.tangerine_whistle.vm.stack" "push". Definition block_hash : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,14 +48,16 @@ Definition block_hash : Value.t -> Value.t -> M := The current EVM frame. " in - let block_number := + let _ := M.assign_local (| + "block_number" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -78,19 +86,23 @@ Definition block_hash : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let hash := - Constant.bytes "00" in + let _ := M.assign_local (| + "hash" , + Constant.bytes "00" + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let hash := + let _ := M.assign_local (| + "hash" , M.get_subscript (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "block_hashes" |), UnOp.sub (| BinOp.sub (| M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "env" |), "number" |), M.get_name (| globals, "block_number" |) |) |) - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := M.call (| diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/comparison.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/comparison.v index 014d467..7e7ac0d 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/comparison.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/comparison.v @@ -17,17 +17,21 @@ Introduction Implementations of the EVM Comparison instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_tangerine_whistle_vm_imports : - AreImported globals "ethereum.tangerine_whistle.vm" [ "Evm" ]. +Axiom ethereum_tangerine_whistle_vm_imports_Evm : + IsImported globals "ethereum.tangerine_whistle.vm" "Evm". -Axiom ethereum_tangerine_whistle_vm_gas_imports : - AreImported globals "ethereum.tangerine_whistle.vm.gas" [ "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_tangerine_whistle_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_tangerine_whistle_vm_gas_imports_charge_gas : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "charge_gas". -Axiom ethereum_tangerine_whistle_vm_stack_imports : - AreImported globals "ethereum.tangerine_whistle.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_tangerine_whistle_vm_stack_imports_pop : + IsImported globals "ethereum.tangerine_whistle.vm.stack" "pop". +Axiom ethereum_tangerine_whistle_vm_stack_imports_push : + IsImported globals "ethereum.tangerine_whistle.vm.stack" "push". Definition less_than : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,22 +46,26 @@ Definition less_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -66,7 +74,8 @@ Definition less_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -76,7 +85,8 @@ Definition less_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -104,7 +114,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -115,8 +126,10 @@ Definition signed_less_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -127,7 +140,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -136,7 +150,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -146,7 +161,8 @@ Definition signed_less_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -175,22 +191,26 @@ Definition greater_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -199,7 +219,8 @@ Definition greater_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -209,7 +230,8 @@ Definition greater_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -237,7 +259,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -248,8 +271,10 @@ Definition signed_greater_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -260,7 +285,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := |), "to_signed" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -269,7 +295,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -279,7 +306,8 @@ Definition signed_greater_than : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -308,22 +336,26 @@ Definition equal : Value.t -> Value.t -> M := The current EVM frame. " in - let left := + let _ := M.assign_local (| + "left" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let right := + |) + |) in + let _ := M.assign_local (| + "right" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -332,7 +364,8 @@ Definition equal : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -342,7 +375,8 @@ Definition equal : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -371,14 +405,16 @@ Definition is_zero : Value.t -> Value.t -> M := The current EVM frame. " in - let x := + let _ := M.assign_local (| + "x" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -387,7 +423,8 @@ Definition is_zero : Value.t -> Value.t -> M := ], make_dict [] |) in - let result := + let _ := M.assign_local (| + "result" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -397,7 +434,8 @@ Definition is_zero : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/control_flow.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/control_flow.v index c615c86..6ba53bf 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/control_flow.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/control_flow.v @@ -17,20 +17,32 @@ Introduction Implementations of the EVM control flow instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_tangerine_whistle_vm_gas_imports : - AreImported globals "ethereum.tangerine_whistle.vm.gas" [ "GAS_BASE"; "GAS_HIGH"; "GAS_JUMPDEST"; "GAS_MID"; "charge_gas" ]. +Axiom ethereum_tangerine_whistle_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "GAS_BASE". +Axiom ethereum_tangerine_whistle_vm_gas_imports_GAS_HIGH : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "GAS_HIGH". +Axiom ethereum_tangerine_whistle_vm_gas_imports_GAS_JUMPDEST : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "GAS_JUMPDEST". +Axiom ethereum_tangerine_whistle_vm_gas_imports_GAS_MID : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "GAS_MID". +Axiom ethereum_tangerine_whistle_vm_gas_imports_charge_gas : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "charge_gas". -Axiom ethereum_tangerine_whistle_vm_imports : - AreImported globals "ethereum.tangerine_whistle.vm" [ "Evm" ]. +Axiom ethereum_tangerine_whistle_vm_imports_Evm : + IsImported globals "ethereum.tangerine_whistle.vm" "Evm". -Axiom ethereum_tangerine_whistle_vm_exceptions_imports : - AreImported globals "ethereum.tangerine_whistle.vm.exceptions" [ "InvalidJumpDestError" ]. +Axiom ethereum_tangerine_whistle_vm_exceptions_imports_InvalidJumpDestError : + IsImported globals "ethereum.tangerine_whistle.vm.exceptions" "InvalidJumpDestError". -Axiom ethereum_tangerine_whistle_vm_stack_imports : - AreImported globals "ethereum.tangerine_whistle.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_tangerine_whistle_vm_stack_imports_pop : + IsImported globals "ethereum.tangerine_whistle.vm.stack" "pop". +Axiom ethereum_tangerine_whistle_vm_stack_imports_push : + IsImported globals "ethereum.tangerine_whistle.vm.stack" "push". Definition stop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -69,7 +81,8 @@ Definition jump : Value.t -> Value.t -> M := The current EVM frame. " in - let jump_dest := + let _ := M.assign_local (| + "jump_dest" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -82,7 +95,8 @@ Definition jump : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -132,7 +146,8 @@ Definition jumpi : Value.t -> Value.t -> M := The current EVM frame. " in - let jump_dest := + let _ := M.assign_local (| + "jump_dest" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -145,15 +160,18 @@ Definition jumpi : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let conditional_value := + |) + |) in + let _ := M.assign_local (| + "conditional_value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -171,11 +189,13 @@ Definition jumpi : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let destination := + let _ := M.assign_local (| + "destination" , BinOp.add (| M.get_field (| M.get_name (| globals, "evm" |), "pc" |), Constant.int 1 - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -192,8 +212,10 @@ Definition jumpi : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let destination := - M.get_name (| globals, "jump_dest" |) in + let _ := M.assign_local (| + "destination" , + M.get_name (| globals, "jump_dest" |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/environment.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/environment.v index 68c919a..6f5e691 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/environment.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/environment.v @@ -17,29 +17,47 @@ Introduction Implementations of the EVM environment related instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. - -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. - -Axiom ethereum_tangerine_whistle_state_imports : - AreImported globals "ethereum.tangerine_whistle.state" [ "get_account" ]. - -Axiom ethereum_tangerine_whistle_utils_address_imports : - AreImported globals "ethereum.tangerine_whistle.utils.address" [ "to_address" ]. - -Axiom ethereum_tangerine_whistle_vm_memory_imports : - AreImported globals "ethereum.tangerine_whistle.vm.memory" [ "buffer_read"; "memory_write" ]. - -Axiom ethereum_tangerine_whistle_vm_imports : - AreImported globals "ethereum.tangerine_whistle.vm" [ "Evm" ]. - -Axiom ethereum_tangerine_whistle_vm_gas_imports : - AreImported globals "ethereum.tangerine_whistle.vm.gas" [ "GAS_BALANCE"; "GAS_BASE"; "GAS_COPY"; "GAS_EXTERNAL"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. - -Axiom ethereum_tangerine_whistle_vm_stack_imports : - AreImported globals "ethereum.tangerine_whistle.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". + +Axiom ethereum_tangerine_whistle_state_imports_get_account : + IsImported globals "ethereum.tangerine_whistle.state" "get_account". + +Axiom ethereum_tangerine_whistle_utils_address_imports_to_address : + IsImported globals "ethereum.tangerine_whistle.utils.address" "to_address". + +Axiom ethereum_tangerine_whistle_vm_memory_imports_buffer_read : + IsImported globals "ethereum.tangerine_whistle.vm.memory" "buffer_read". +Axiom ethereum_tangerine_whistle_vm_memory_imports_memory_write : + IsImported globals "ethereum.tangerine_whistle.vm.memory" "memory_write". + +Axiom ethereum_tangerine_whistle_vm_imports_Evm : + IsImported globals "ethereum.tangerine_whistle.vm" "Evm". + +Axiom ethereum_tangerine_whistle_vm_gas_imports_GAS_BALANCE : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "GAS_BALANCE". +Axiom ethereum_tangerine_whistle_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "GAS_BASE". +Axiom ethereum_tangerine_whistle_vm_gas_imports_GAS_COPY : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "GAS_COPY". +Axiom ethereum_tangerine_whistle_vm_gas_imports_GAS_EXTERNAL : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "GAS_EXTERNAL". +Axiom ethereum_tangerine_whistle_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_tangerine_whistle_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_tangerine_whistle_vm_gas_imports_charge_gas : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "charge_gas". + +Axiom ethereum_tangerine_whistle_vm_stack_imports_pop : + IsImported globals "ethereum.tangerine_whistle.vm.stack" "pop". +Axiom ethereum_tangerine_whistle_vm_stack_imports_push : + IsImported globals "ethereum.tangerine_whistle.vm.stack" "push". Definition address : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -95,7 +113,8 @@ Definition balance : Value.t -> Value.t -> M := The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -108,7 +127,8 @@ Definition balance : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -117,7 +137,8 @@ Definition balance : Value.t -> Value.t -> M := ], make_dict [] |) in - let balance := + let _ := M.assign_local (| + "balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -125,7 +146,8 @@ Definition balance : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -275,14 +297,16 @@ Definition calldataload : Value.t -> Value.t -> M := The current EVM frame. " in - let start_index := + let _ := M.assign_local (| + "start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -291,7 +315,8 @@ Definition calldataload : Value.t -> Value.t -> M := ], make_dict [] |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -306,7 +331,8 @@ Definition calldataload : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -391,31 +417,38 @@ Definition calldatacopy : Value.t -> Value.t -> M := The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let data_start_index := + |) + |) in + let _ := M.assign_local (| + "data_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -431,13 +464,17 @@ Definition calldatacopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -447,7 +484,8 @@ Definition calldatacopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -470,7 +508,8 @@ Definition calldatacopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -479,7 +518,8 @@ Definition calldatacopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -559,31 +599,38 @@ Definition codecopy : Value.t -> Value.t -> M := The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let code_start_index := + |) + |) in + let _ := M.assign_local (| + "code_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -599,13 +646,17 @@ Definition codecopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -615,7 +666,8 @@ Definition codecopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -638,7 +690,8 @@ Definition codecopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -647,7 +700,8 @@ Definition codecopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -718,7 +772,8 @@ Definition extcodesize : Value.t -> Value.t -> M := The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -731,7 +786,8 @@ Definition extcodesize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -740,7 +796,8 @@ Definition extcodesize : Value.t -> Value.t -> M := ], make_dict [] |) in - let codesize := + let _ := M.assign_local (| + "codesize" , M.call (| M.get_name (| globals, "U256" |), make_list [ @@ -760,7 +817,8 @@ Definition extcodesize : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -788,7 +846,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := The current EVM frame. " in - let address := + let _ := M.assign_local (| + "address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -801,32 +860,40 @@ Definition extcodecopy : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let memory_start_index := + |) + |) in + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let code_start_index := + |) + |) in + let _ := M.assign_local (| + "code_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -842,13 +909,17 @@ Definition extcodecopy : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let copy_gas_cost := + |) + |) in + let _ := M.assign_local (| + "copy_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_COPY" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -858,7 +929,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -881,7 +953,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let code := + let _ := M.assign_local (| + "code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -889,8 +962,10 @@ Definition extcodecopy : Value.t -> Value.t -> M := M.get_name (| globals, "address" |) ], make_dict [] - |), "code" |) in - let value := + |), "code" |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -899,7 +974,8 @@ Definition extcodecopy : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/keccak.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/keccak.v index 0559a39..d8e8086 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/keccak.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/keccak.v @@ -17,26 +17,36 @@ Introduction Implementations of the EVM keccak instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "keccak256" ]. +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_tangerine_whistle_vm_imports : - AreImported globals "ethereum.tangerine_whistle.vm" [ "Evm" ]. +Axiom ethereum_tangerine_whistle_vm_imports_Evm : + IsImported globals "ethereum.tangerine_whistle.vm" "Evm". -Axiom ethereum_tangerine_whistle_vm_gas_imports : - AreImported globals "ethereum.tangerine_whistle.vm.gas" [ "GAS_KECCAK256"; "GAS_KECCAK256_WORD"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_tangerine_whistle_vm_gas_imports_GAS_KECCAK256 : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "GAS_KECCAK256". +Axiom ethereum_tangerine_whistle_vm_gas_imports_GAS_KECCAK256_WORD : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "GAS_KECCAK256_WORD". +Axiom ethereum_tangerine_whistle_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_tangerine_whistle_vm_gas_imports_charge_gas : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "charge_gas". -Axiom ethereum_tangerine_whistle_vm_memory_imports : - AreImported globals "ethereum.tangerine_whistle.vm.memory" [ "memory_read_bytes" ]. +Axiom ethereum_tangerine_whistle_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.tangerine_whistle.vm.memory" "memory_read_bytes". -Axiom ethereum_tangerine_whistle_vm_stack_imports : - AreImported globals "ethereum.tangerine_whistle.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_tangerine_whistle_vm_stack_imports_pop : + IsImported globals "ethereum.tangerine_whistle.vm.stack" "pop". +Axiom ethereum_tangerine_whistle_vm_stack_imports_push : + IsImported globals "ethereum.tangerine_whistle.vm.stack" "push". Definition keccak : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -53,23 +63,28 @@ Definition keccak : Value.t -> Value.t -> M := The current EVM frame. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let words := + |) + |) in + let _ := M.assign_local (| + "words" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -85,13 +100,17 @@ Definition keccak : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in - let word_gas_cost := + |) + |) in + let _ := M.assign_local (| + "word_gas_cost" , BinOp.mult (| M.get_name (| globals, "GAS_KECCAK256_WORD" |), M.get_name (| globals, "words" |) - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -101,7 +120,8 @@ Definition keccak : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -124,7 +144,8 @@ Definition keccak : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let data := + let _ := M.assign_local (| + "data" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -133,15 +154,18 @@ Definition keccak : Value.t -> Value.t -> M := M.get_name (| globals, "size" |) ], make_dict [] - |) in - let hash := + |) + |) in + let _ := M.assign_local (| + "hash" , M.call (| M.get_name (| globals, "keccak256" |), make_list [ M.get_name (| globals, "data" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/log.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/log.v index d705a66..45018dd 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/log.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/log.v @@ -17,26 +17,34 @@ Introduction Implementations of the EVM logging instructions. ". -Axiom functools_imports : - AreImported globals "functools" [ "partial" ]. +Axiom functools_imports_partial : + IsImported globals "functools" "partial". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_tangerine_whistle_blocks_imports : - AreImported globals "ethereum.tangerine_whistle.blocks" [ "Log" ]. +Axiom ethereum_tangerine_whistle_blocks_imports_Log : + IsImported globals "ethereum.tangerine_whistle.blocks" "Log". -Axiom ethereum_tangerine_whistle_vm_imports : - AreImported globals "ethereum.tangerine_whistle.vm" [ "Evm" ]. +Axiom ethereum_tangerine_whistle_vm_imports_Evm : + IsImported globals "ethereum.tangerine_whistle.vm" "Evm". -Axiom ethereum_tangerine_whistle_vm_gas_imports : - AreImported globals "ethereum.tangerine_whistle.vm.gas" [ "GAS_LOG"; "GAS_LOG_DATA"; "GAS_LOG_TOPIC"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_tangerine_whistle_vm_gas_imports_GAS_LOG : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "GAS_LOG". +Axiom ethereum_tangerine_whistle_vm_gas_imports_GAS_LOG_DATA : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "GAS_LOG_DATA". +Axiom ethereum_tangerine_whistle_vm_gas_imports_GAS_LOG_TOPIC : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "GAS_LOG_TOPIC". +Axiom ethereum_tangerine_whistle_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_tangerine_whistle_vm_gas_imports_charge_gas : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "charge_gas". -Axiom ethereum_tangerine_whistle_vm_memory_imports : - AreImported globals "ethereum.tangerine_whistle.vm.memory" [ "memory_read_bytes" ]. +Axiom ethereum_tangerine_whistle_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.tangerine_whistle.vm.memory" "memory_read_bytes". -Axiom ethereum_tangerine_whistle_vm_stack_imports : - AreImported globals "ethereum.tangerine_whistle.vm.stack" [ "pop" ]. +Axiom ethereum_tangerine_whistle_vm_stack_imports_pop : + IsImported globals "ethereum.tangerine_whistle.vm.stack" "pop". Definition log_n : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -55,24 +63,30 @@ Definition log_n : Value.t -> Value.t -> M := The number of topics to be included in the log entry. " in - let memory_start_index := + let _ := M.assign_local (| + "memory_start_index" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let size := + |) + |) in + let _ := M.assign_local (| + "size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let topics := - make_list [] in + |) + |) in + let _ := M.assign_local (| + "topics" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "_" |), @@ -84,7 +98,8 @@ Definition log_n : Value.t -> Value.t -> M := make_dict [] |), ltac:(M.monadic ( - let topic := + let _ := M.assign_local (| + "topic" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -95,7 +110,8 @@ Definition log_n : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "topics" |), "append" |), make_list [ @@ -109,7 +125,8 @@ Definition log_n : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in - let extend_memory := + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -119,7 +136,8 @@ Definition log_n : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -151,12 +169,14 @@ Definition log_n : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let log_entry := + let _ := M.assign_local (| + "log_entry" , M.call (| M.get_name (| globals, "Log" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "logs" |), BinOp.add (| diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/memory.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/memory.v index 6b34ce0..ca0b278 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/memory.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/memory.v @@ -17,20 +17,32 @@ Introduction Implementations of the EVM Memory instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". -Axiom ethereum_tangerine_whistle_vm_imports : - AreImported globals "ethereum.tangerine_whistle.vm" [ "Evm" ]. +Axiom ethereum_tangerine_whistle_vm_imports_Evm : + IsImported globals "ethereum.tangerine_whistle.vm" "Evm". -Axiom ethereum_tangerine_whistle_vm_gas_imports : - AreImported globals "ethereum.tangerine_whistle.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "calculate_gas_extend_memory"; "charge_gas" ]. +Axiom ethereum_tangerine_whistle_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "GAS_BASE". +Axiom ethereum_tangerine_whistle_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_tangerine_whistle_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_tangerine_whistle_vm_gas_imports_charge_gas : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "charge_gas". -Axiom ethereum_tangerine_whistle_vm_memory_imports : - AreImported globals "ethereum.tangerine_whistle.vm.memory" [ "memory_read_bytes"; "memory_write" ]. +Axiom ethereum_tangerine_whistle_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.tangerine_whistle.vm.memory" "memory_read_bytes". +Axiom ethereum_tangerine_whistle_vm_memory_imports_memory_write : + IsImported globals "ethereum.tangerine_whistle.vm.memory" "memory_write". -Axiom ethereum_tangerine_whistle_vm_stack_imports : - AreImported globals "ethereum.tangerine_whistle.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_tangerine_whistle_vm_stack_imports_pop : + IsImported globals "ethereum.tangerine_whistle.vm.stack" "pop". +Axiom ethereum_tangerine_whistle_vm_stack_imports_push : + IsImported globals "ethereum.tangerine_whistle.vm.stack" "push". Definition mstore : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -46,15 +58,18 @@ Definition mstore : Value.t -> Value.t -> M := The current EVM frame. " in - let start_position := + let _ := M.assign_local (| + "start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -65,8 +80,10 @@ Definition mstore : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -88,7 +105,8 @@ Definition mstore : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -138,23 +156,28 @@ Definition mstore8 : Value.t -> Value.t -> M := The current EVM frame. " in - let start_position := + let _ := M.assign_local (| + "start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -170,7 +193,8 @@ Definition mstore8 : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -190,7 +214,8 @@ Definition mstore8 : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let normalized_bytes_value := + let _ := M.assign_local (| + "normalized_bytes_value" , M.call (| M.get_name (| globals, "Bytes" |), make_list [ @@ -202,7 +227,8 @@ Definition mstore8 : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -231,15 +257,18 @@ Definition mload : Value.t -> Value.t -> M := The current EVM frame. " in - let start_position := + let _ := M.assign_local (| + "start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -255,7 +284,8 @@ Definition mload : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -275,7 +305,8 @@ Definition mload : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -296,7 +327,8 @@ Definition mload : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/stack.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/stack.v index 4ddab44..91f636b 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/stack.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/stack.v @@ -17,26 +17,32 @@ Introduction Implementations of the EVM stack related instructions. ". -Axiom functools_imports : - AreImported globals "functools" [ "partial" ]. +Axiom functools_imports_partial : + IsImported globals "functools" "partial". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_utils_ensure_imports : - AreImported globals "ethereum.utils.ensure" [ "ensure" ]. +Axiom ethereum_utils_ensure_imports_ensure : + IsImported globals "ethereum.utils.ensure" "ensure". -Axiom ethereum_tangerine_whistle_vm_imports : - AreImported globals "ethereum.tangerine_whistle.vm" [ "Evm"; "stack" ]. +Axiom ethereum_tangerine_whistle_vm_imports_Evm : + IsImported globals "ethereum.tangerine_whistle.vm" "Evm". +Axiom ethereum_tangerine_whistle_vm_imports_stack : + IsImported globals "ethereum.tangerine_whistle.vm" "stack". -Axiom ethereum_tangerine_whistle_vm_exceptions_imports : - AreImported globals "ethereum.tangerine_whistle.vm.exceptions" [ "StackUnderflowError" ]. +Axiom ethereum_tangerine_whistle_vm_exceptions_imports_StackUnderflowError : + IsImported globals "ethereum.tangerine_whistle.vm.exceptions" "StackUnderflowError". -Axiom ethereum_tangerine_whistle_vm_gas_imports : - AreImported globals "ethereum.tangerine_whistle.vm.gas" [ "GAS_BASE"; "GAS_VERY_LOW"; "charge_gas" ]. +Axiom ethereum_tangerine_whistle_vm_gas_imports_GAS_BASE : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "GAS_BASE". +Axiom ethereum_tangerine_whistle_vm_gas_imports_GAS_VERY_LOW : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "GAS_VERY_LOW". +Axiom ethereum_tangerine_whistle_vm_gas_imports_charge_gas : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "charge_gas". -Axiom ethereum_tangerine_whistle_vm_memory_imports : - AreImported globals "ethereum.tangerine_whistle.vm.memory" [ "buffer_read" ]. +Axiom ethereum_tangerine_whistle_vm_memory_imports_buffer_read : + IsImported globals "ethereum.tangerine_whistle.vm.memory" "buffer_read". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -98,7 +104,8 @@ Definition push_n : Value.t -> Value.t -> M := ], make_dict [] |) in - let data_to_push := + let _ := M.assign_local (| + "data_to_push" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -128,7 +135,8 @@ Definition push_n : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "stack" |), "push" |), make_list [ @@ -189,7 +197,8 @@ Definition dup_n : Value.t -> Value.t -> M := ], make_dict [] |) in - let data_to_duplicate := + let _ := M.assign_local (| + "data_to_duplicate" , M.get_subscript (| M.get_field (| M.get_name (| globals, "evm" |), "stack" |), BinOp.sub (| @@ -205,7 +214,8 @@ Definition dup_n : Value.t -> Value.t -> M := |), M.get_name (| globals, "item_number" |) |) - |) in + |) + |) in let _ := M.call (| M.get_field (| M.get_name (| globals, "stack" |), "push" |), make_list [ diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/storage.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/storage.v index a02fde8..d1261c9 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/storage.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/storage.v @@ -17,17 +17,29 @@ Introduction Implementations of the EVM storage related instructions. ". -Axiom ethereum_tangerine_whistle_state_imports : - AreImported globals "ethereum.tangerine_whistle.state" [ "get_storage"; "set_storage" ]. +Axiom ethereum_tangerine_whistle_state_imports_get_storage : + IsImported globals "ethereum.tangerine_whistle.state" "get_storage". +Axiom ethereum_tangerine_whistle_state_imports_set_storage : + IsImported globals "ethereum.tangerine_whistle.state" "set_storage". -Axiom ethereum_tangerine_whistle_vm_imports : - AreImported globals "ethereum.tangerine_whistle.vm" [ "Evm" ]. +Axiom ethereum_tangerine_whistle_vm_imports_Evm : + IsImported globals "ethereum.tangerine_whistle.vm" "Evm". -Axiom ethereum_tangerine_whistle_vm_gas_imports : - AreImported globals "ethereum.tangerine_whistle.vm.gas" [ "GAS_SLOAD"; "GAS_STORAGE_CLEAR_REFUND"; "GAS_STORAGE_SET"; "GAS_STORAGE_UPDATE"; "charge_gas" ]. +Axiom ethereum_tangerine_whistle_vm_gas_imports_GAS_SLOAD : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "GAS_SLOAD". +Axiom ethereum_tangerine_whistle_vm_gas_imports_GAS_STORAGE_CLEAR_REFUND : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "GAS_STORAGE_CLEAR_REFUND". +Axiom ethereum_tangerine_whistle_vm_gas_imports_GAS_STORAGE_SET : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "GAS_STORAGE_SET". +Axiom ethereum_tangerine_whistle_vm_gas_imports_GAS_STORAGE_UPDATE : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "GAS_STORAGE_UPDATE". +Axiom ethereum_tangerine_whistle_vm_gas_imports_charge_gas : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "charge_gas". -Axiom ethereum_tangerine_whistle_vm_stack_imports : - AreImported globals "ethereum.tangerine_whistle.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_tangerine_whistle_vm_stack_imports_pop : + IsImported globals "ethereum.tangerine_whistle.vm.stack" "pop". +Axiom ethereum_tangerine_whistle_vm_stack_imports_push : + IsImported globals "ethereum.tangerine_whistle.vm.stack" "push". Definition sload : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,7 +54,8 @@ Definition sload : Value.t -> Value.t -> M := The current EVM frame. " in - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -53,7 +66,8 @@ Definition sload : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -62,7 +76,8 @@ Definition sload : Value.t -> Value.t -> M := ], make_dict [] |) in - let value := + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "get_storage" |), make_list [ @@ -71,7 +86,8 @@ Definition sload : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "push" |), make_list [ @@ -99,7 +115,8 @@ Definition sstore : Value.t -> Value.t -> M := The current EVM frame. " in - let key := + let _ := M.assign_local (| + "key" , M.call (| M.get_field (| M.call (| M.get_name (| globals, "pop" |), @@ -110,16 +127,20 @@ Definition sstore : Value.t -> Value.t -> M := |), "to_be_bytes32" |), make_list [], make_dict [] - |) in - let new_value := + |) + |) in + let _ := M.assign_local (| + "new_value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let current_value := + |) + |) in + let _ := M.assign_local (| + "current_value" , M.call (| M.get_name (| globals, "get_storage" |), make_list [ @@ -128,7 +149,8 @@ Definition sstore : Value.t -> Value.t -> M := M.get_name (| globals, "key" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -146,13 +168,17 @@ Definition sstore : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let gas_cost := - M.get_name (| globals, "GAS_STORAGE_SET" |) in + let _ := M.assign_local (| + "gas_cost" , + M.get_name (| globals, "GAS_STORAGE_SET" |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let gas_cost := - M.get_name (| globals, "GAS_STORAGE_UPDATE" |) in + let _ := M.assign_local (| + "gas_cost" , + M.get_name (| globals, "GAS_STORAGE_UPDATE" |) + |) in M.pure Constant.None_ )) |) in let _ := diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/system.v b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/system.v index c782996..a103f8e 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/system.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/instructions/system.v @@ -17,29 +17,75 @@ Introduction Implementations of the EVM system related instructions. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_tangerine_whistle_fork_types_imports : - AreImported globals "ethereum.tangerine_whistle.fork_types" [ "Address" ]. +Axiom ethereum_tangerine_whistle_fork_types_imports_Address : + IsImported globals "ethereum.tangerine_whistle.fork_types" "Address". -Axiom ethereum_tangerine_whistle_state_imports : - AreImported globals "ethereum.tangerine_whistle.state" [ "account_exists"; "account_has_code_or_nonce"; "get_account"; "increment_nonce"; "set_account_balance" ]. +Axiom ethereum_tangerine_whistle_state_imports_account_exists : + IsImported globals "ethereum.tangerine_whistle.state" "account_exists". +Axiom ethereum_tangerine_whistle_state_imports_account_has_code_or_nonce : + IsImported globals "ethereum.tangerine_whistle.state" "account_has_code_or_nonce". +Axiom ethereum_tangerine_whistle_state_imports_get_account : + IsImported globals "ethereum.tangerine_whistle.state" "get_account". +Axiom ethereum_tangerine_whistle_state_imports_increment_nonce : + IsImported globals "ethereum.tangerine_whistle.state" "increment_nonce". +Axiom ethereum_tangerine_whistle_state_imports_set_account_balance : + IsImported globals "ethereum.tangerine_whistle.state" "set_account_balance". -Axiom ethereum_tangerine_whistle_utils_address_imports : - AreImported globals "ethereum.tangerine_whistle.utils.address" [ "compute_contract_address"; "to_address" ]. +Axiom ethereum_tangerine_whistle_utils_address_imports_compute_contract_address : + IsImported globals "ethereum.tangerine_whistle.utils.address" "compute_contract_address". +Axiom ethereum_tangerine_whistle_utils_address_imports_to_address : + IsImported globals "ethereum.tangerine_whistle.utils.address" "to_address". -Axiom ethereum_tangerine_whistle_vm_imports : - AreImported globals "ethereum.tangerine_whistle.vm" [ "Evm"; "Message"; "incorporate_child_on_error"; "incorporate_child_on_success" ]. +Axiom ethereum_tangerine_whistle_vm_imports_Evm : + IsImported globals "ethereum.tangerine_whistle.vm" "Evm". +Axiom ethereum_tangerine_whistle_vm_imports_Message : + IsImported globals "ethereum.tangerine_whistle.vm" "Message". +Axiom ethereum_tangerine_whistle_vm_imports_incorporate_child_on_error : + IsImported globals "ethereum.tangerine_whistle.vm" "incorporate_child_on_error". +Axiom ethereum_tangerine_whistle_vm_imports_incorporate_child_on_success : + IsImported globals "ethereum.tangerine_whistle.vm" "incorporate_child_on_success". -Axiom ethereum_tangerine_whistle_vm_gas_imports : - AreImported globals "ethereum.tangerine_whistle.vm.gas" [ "GAS_CALL"; "GAS_CALL_VALUE"; "GAS_CREATE"; "GAS_NEW_ACCOUNT"; "GAS_SELF_DESTRUCT"; "GAS_SELF_DESTRUCT_NEW_ACCOUNT"; "GAS_ZERO"; "REFUND_SELF_DESTRUCT"; "calculate_gas_extend_memory"; "calculate_message_call_gas"; "charge_gas"; "max_message_call_gas" ]. +Axiom ethereum_tangerine_whistle_vm_gas_imports_GAS_CALL : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "GAS_CALL". +Axiom ethereum_tangerine_whistle_vm_gas_imports_GAS_CALL_VALUE : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "GAS_CALL_VALUE". +Axiom ethereum_tangerine_whistle_vm_gas_imports_GAS_CREATE : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "GAS_CREATE". +Axiom ethereum_tangerine_whistle_vm_gas_imports_GAS_NEW_ACCOUNT : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "GAS_NEW_ACCOUNT". +Axiom ethereum_tangerine_whistle_vm_gas_imports_GAS_SELF_DESTRUCT : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "GAS_SELF_DESTRUCT". +Axiom ethereum_tangerine_whistle_vm_gas_imports_GAS_SELF_DESTRUCT_NEW_ACCOUNT : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "GAS_SELF_DESTRUCT_NEW_ACCOUNT". +Axiom ethereum_tangerine_whistle_vm_gas_imports_GAS_ZERO : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "GAS_ZERO". +Axiom ethereum_tangerine_whistle_vm_gas_imports_REFUND_SELF_DESTRUCT : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "REFUND_SELF_DESTRUCT". +Axiom ethereum_tangerine_whistle_vm_gas_imports_calculate_gas_extend_memory : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "calculate_gas_extend_memory". +Axiom ethereum_tangerine_whistle_vm_gas_imports_calculate_message_call_gas : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "calculate_message_call_gas". +Axiom ethereum_tangerine_whistle_vm_gas_imports_charge_gas : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "charge_gas". +Axiom ethereum_tangerine_whistle_vm_gas_imports_max_message_call_gas : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "max_message_call_gas". -Axiom ethereum_tangerine_whistle_vm_memory_imports : - AreImported globals "ethereum.tangerine_whistle.vm.memory" [ "memory_read_bytes"; "memory_write" ]. +Axiom ethereum_tangerine_whistle_vm_memory_imports_memory_read_bytes : + IsImported globals "ethereum.tangerine_whistle.vm.memory" "memory_read_bytes". +Axiom ethereum_tangerine_whistle_vm_memory_imports_memory_write : + IsImported globals "ethereum.tangerine_whistle.vm.memory" "memory_write". -Axiom ethereum_tangerine_whistle_vm_stack_imports : - AreImported globals "ethereum.tangerine_whistle.vm.stack" [ "pop"; "push" ]. +Axiom ethereum_tangerine_whistle_vm_stack_imports_pop : + IsImported globals "ethereum.tangerine_whistle.vm.stack" "pop". +Axiom ethereum_tangerine_whistle_vm_stack_imports_push : + IsImported globals "ethereum.tangerine_whistle.vm.stack" "push". Definition create : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -53,31 +99,38 @@ Definition create : Value.t -> Value.t -> M := The current EVM frame. " in (* At stmt: unsupported node type: ImportFrom *) - let endowment := + let _ := M.assign_local (| + "endowment" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_size := + |) + |) in + let _ := M.assign_local (| + "memory_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -87,7 +140,8 @@ Definition create : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -99,7 +153,8 @@ Definition create : Value.t -> Value.t -> M := ], make_dict [] |) in - let create_message_gas := + let _ := M.assign_local (| + "create_message_gas" , M.call (| M.get_name (| globals, "max_message_call_gas" |), make_list [ @@ -112,7 +167,8 @@ Definition create : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.assign_op (| BinOp.sub, M.get_field (| M.get_name (| globals, "evm" |), "gas_left" |), @@ -126,9 +182,12 @@ Definition create : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let sender_address := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in - let sender := + let _ := M.assign_local (| + "sender_address" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + |) in + let _ := M.assign_local (| + "sender" , M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -136,8 +195,10 @@ Definition create : Value.t -> Value.t -> M := M.get_name (| globals, "sender_address" |) ], make_dict [] - |) in - let contract_address := + |) + |) in + let _ := M.assign_local (| + "contract_address" , M.call (| M.get_name (| globals, "compute_contract_address" |), make_list [ @@ -152,7 +213,8 @@ Definition create : Value.t -> Value.t -> M := |), "nonce" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -253,7 +315,8 @@ Definition create : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let call_data := + let _ := M.assign_local (| + "call_data" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -262,7 +325,8 @@ Definition create : Value.t -> Value.t -> M := M.get_name (| globals, "memory_size" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "increment_nonce" |), make_list [ @@ -271,13 +335,16 @@ Definition create : Value.t -> Value.t -> M := ], make_dict [] |) in - let child_message := + let _ := M.assign_local (| + "child_message" , M.call (| M.get_name (| globals, "Message" |), make_list [], make_dict [] - |) in - let child_evm := + |) + |) in + let _ := M.assign_local (| + "child_evm" , M.call (| M.get_name (| globals, "process_create_message" |), make_list [ @@ -285,7 +352,8 @@ Definition create : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -363,23 +431,28 @@ Definition return_ : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let memory_start_position := + let _ := M.assign_local (| + "memory_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_size := + |) + |) in + let _ := M.assign_local (| + "memory_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -389,7 +462,8 @@ Definition return_ : Value.t -> Value.t -> M := ] ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -474,7 +548,8 @@ Definition generic_call : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let call_data := + let _ := M.assign_local (| + "call_data" , M.call (| M.get_name (| globals, "memory_read_bytes" |), make_list [ @@ -483,8 +558,10 @@ Definition generic_call : Value.t -> Value.t -> M := M.get_name (| globals, "memory_input_size" |) ], make_dict [] - |) in - let code := + |) + |) in + let _ := M.assign_local (| + "code" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -492,14 +569,18 @@ Definition generic_call : Value.t -> Value.t -> M := M.get_name (| globals, "code_address" |) ], make_dict [] - |), "code" |) in - let child_message := + |), "code" |) + |) in + let _ := M.assign_local (| + "child_message" , M.call (| M.get_name (| globals, "Message" |), make_list [], make_dict [] - |) in - let child_evm := + |) + |) in + let _ := M.assign_local (| + "child_evm" , M.call (| M.get_name (| globals, "process_message" |), make_list [ @@ -507,7 +588,8 @@ Definition generic_call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -563,7 +645,8 @@ Definition generic_call : Value.t -> Value.t -> M := |) in M.pure Constant.None_ )) |) in - let actual_output_size := + let _ := M.assign_local (| + "actual_output_size" , M.call (| M.get_name (| globals, "min" |), make_list [ @@ -583,7 +666,8 @@ Definition generic_call : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "memory_write" |), make_list [ @@ -611,7 +695,8 @@ Definition call : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -624,8 +709,10 @@ Definition call : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let to := + |) + |) in + let _ := M.assign_local (| + "to" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -638,48 +725,60 @@ Definition call : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -690,8 +789,10 @@ Definition call : Value.t -> Value.t -> M := ] ], make_dict [] - |) in - let _account_exists := + |) + |) in + let _ := M.assign_local (| + "_account_exists" , M.call (| M.get_name (| globals, "account_exists" |), make_list [ @@ -699,8 +800,10 @@ Definition call : Value.t -> Value.t -> M := M.get_name (| globals, "to" |) ], make_dict [] - |) in - let create_gas_cost := + |) + |) in + let _ := M.assign_local (| + "create_gas_cost" , (* if *) M.if_then_else (| M.get_name (| globals, "_account_exists" |), @@ -716,8 +819,10 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "GAS_NEW_ACCOUNT" |) - )) |) in - let transfer_gas_cost := + )) |) + |) in + let _ := M.assign_local (| + "transfer_gas_cost" , (* if *) M.if_then_else (| Compare.eq (| @@ -736,8 +841,10 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "GAS_CALL_VALUE" |) - )) |) in - let message_call_gas := + )) |) + |) in + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -760,7 +867,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -780,7 +888,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let sender_balance := + let _ := M.assign_local (| + "sender_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -788,7 +897,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := (* if *) M.if_then_else (| @@ -857,7 +967,8 @@ Definition callcode : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -870,8 +981,10 @@ Definition callcode : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let code_address := + |) + |) in + let _ := M.assign_local (| + "code_address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -884,50 +997,64 @@ Definition callcode : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let value := + |) + |) in + let _ := M.assign_local (| + "value" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let to := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "to" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -938,8 +1065,10 @@ Definition callcode : Value.t -> Value.t -> M := ] ], make_dict [] - |) in - let transfer_gas_cost := + |) + |) in + let _ := M.assign_local (| + "transfer_gas_cost" , (* if *) M.if_then_else (| Compare.eq (| @@ -958,8 +1087,10 @@ M.call (| (* else *) )), ltac:(M.monadic ( M.get_name (| globals, "GAS_CALL_VALUE" |) - )) |) in - let message_call_gas := + )) |) + |) in + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -979,7 +1110,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -999,7 +1131,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_name (| globals, "extend_memory" |), "expand_by" |) |) |) in - let sender_balance := + let _ := M.assign_local (| + "sender_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1007,7 +1140,8 @@ M.get_name (| globals, "GAS_CALL_VALUE" |) M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := (* if *) M.if_then_else (| @@ -1076,7 +1210,8 @@ Definition selfdestruct : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let beneficiary := + let _ := M.assign_local (| + "beneficiary" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1089,9 +1224,12 @@ Definition selfdestruct : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let gas_cost := - M.get_name (| globals, "GAS_SELF_DESTRUCT" |) in + |) + |) in + let _ := M.assign_local (| + "gas_cost" , + M.get_name (| globals, "GAS_SELF_DESTRUCT" |) + |) in let _ := (* if *) M.if_then_else (| @@ -1105,20 +1243,28 @@ Definition selfdestruct : Value.t -> Value.t -> M := |) |), (* then *) ltac:(M.monadic ( - let gas_cost := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "gas_cost", M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) - M.get_name (| globals, "GAS_SELF_DESTRUCT_NEW_ACCOUNT" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let originator := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) in - let refunded_accounts := - M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in - let parent_evm := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "parent_evm" |) in + let _ := M.assign_local (| + "originator" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "current_target" |) + |) in + let _ := M.assign_local (| + "refunded_accounts" , + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) + |) in + let _ := M.assign_local (| + "parent_evm" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "parent_evm" |) + |) in let _ := M.while (| Compare.is_not (| @@ -1133,8 +1279,10 @@ Definition selfdestruct : Value.t -> Value.t -> M := ], make_dict [] |) in - let parent_evm := - M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) in + let _ := M.assign_local (| + "parent_evm" , + M.get_field (| M.get_field (| M.get_name (| globals, "parent_evm" |), "message" |), "parent_evm" |) + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -1168,7 +1316,8 @@ Definition selfdestruct : Value.t -> Value.t -> M := ], make_dict [] |) in - let beneficiary_balance := + let _ := M.assign_local (| + "beneficiary_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1176,8 +1325,10 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_name (| globals, "beneficiary" |) ], make_dict [] - |), "balance" |) in - let originator_balance := + |), "balance" |) + |) in + let _ := M.assign_local (| + "originator_balance" , M.get_field (| M.call (| M.get_name (| globals, "get_account" |), make_list [ @@ -1185,7 +1336,8 @@ Definition selfdestruct : Value.t -> Value.t -> M := M.get_name (| globals, "originator" |) ], make_dict [] - |), "balance" |) in + |), "balance" |) + |) in let _ := M.call (| M.get_name (| globals, "set_account_balance" |), make_list [ @@ -1238,7 +1390,8 @@ Definition delegatecall : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let gas := + let _ := M.assign_local (| + "gas" , M.call (| M.get_name (| globals, "Uint" |), make_list [ @@ -1251,8 +1404,10 @@ Definition delegatecall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let code_address := + |) + |) in + let _ := M.assign_local (| + "code_address" , M.call (| M.get_name (| globals, "to_address" |), make_list [ @@ -1265,40 +1420,50 @@ Definition delegatecall : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let memory_input_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_input_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_input_size := + |) + |) in + let _ := M.assign_local (| + "memory_input_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_start_position := + |) + |) in + let _ := M.assign_local (| + "memory_output_start_position" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let memory_output_size := + |) + |) in + let _ := M.assign_local (| + "memory_output_size" , M.call (| M.get_name (| globals, "pop" |), make_list [ M.get_field (| M.get_name (| globals, "evm" |), "stack" |) ], make_dict [] - |) in - let extend_memory := + |) + |) in + let _ := M.assign_local (| + "extend_memory" , M.call (| M.get_name (| globals, "calculate_gas_extend_memory" |), make_list [ @@ -1309,8 +1474,10 @@ Definition delegatecall : Value.t -> Value.t -> M := ] ], make_dict [] - |) in - let message_call_gas := + |) + |) in + let _ := M.assign_local (| + "message_call_gas" , M.call (| M.get_name (| globals, "calculate_message_call_gas" |), make_list [ @@ -1333,7 +1500,8 @@ Definition delegatecall : Value.t -> Value.t -> M := M.get_name (| globals, "GAS_CALL" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/interpreter.v b/CoqOfPython/ethereum/tangerine_whistle/vm/interpreter.v index 3214ea1..df0b3aa 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/interpreter.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/interpreter.v @@ -17,47 +17,95 @@ Introduction A straightforward interpreter that executes EVM code. ". -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. - -Axiom typing_imports : - AreImported globals "typing" [ "Optional"; "Set"; "Tuple" ]. - -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes0"; "Uint" ]. - -Axiom ethereum_trace_imports : - AreImported globals "ethereum.trace" [ "EvmStop"; "OpEnd"; "OpException"; "OpStart"; "PrecompileEnd"; "PrecompileStart"; "TransactionEnd"; "evm_trace" ]. - -Axiom ethereum_tangerine_whistle_blocks_imports : - AreImported globals "ethereum.tangerine_whistle.blocks" [ "Log" ]. - -Axiom ethereum_tangerine_whistle_fork_types_imports : - AreImported globals "ethereum.tangerine_whistle.fork_types" [ "Address" ]. - -Axiom ethereum_tangerine_whistle_state_imports : - AreImported globals "ethereum.tangerine_whistle.state" [ "account_has_code_or_nonce"; "begin_transaction"; "commit_transaction"; "destroy_storage"; "move_ether"; "rollback_transaction"; "set_code"; "touch_account" ]. - -Axiom ethereum_tangerine_whistle_vm_imports : - AreImported globals "ethereum.tangerine_whistle.vm" [ "Message" ]. - -Axiom ethereum_tangerine_whistle_vm_gas_imports : - AreImported globals "ethereum.tangerine_whistle.vm.gas" [ "GAS_CODE_DEPOSIT"; "charge_gas" ]. - -Axiom ethereum_tangerine_whistle_vm_precompiled_contracts_mapping_imports : - AreImported globals "ethereum.tangerine_whistle.vm.precompiled_contracts.mapping" [ "PRE_COMPILED_CONTRACTS" ]. - -Axiom ethereum_tangerine_whistle_vm_imports : - AreImported globals "ethereum.tangerine_whistle.vm" [ "Environment"; "Evm" ]. - -Axiom ethereum_tangerine_whistle_vm_exceptions_imports : - AreImported globals "ethereum.tangerine_whistle.vm.exceptions" [ "AddressCollision"; "ExceptionalHalt"; "InvalidOpcode"; "StackDepthLimitError" ]. - -Axiom ethereum_tangerine_whistle_vm_instructions_imports : - AreImported globals "ethereum.tangerine_whistle.vm.instructions" [ "Ops"; "op_implementation" ]. - -Axiom ethereum_tangerine_whistle_vm_runtime_imports : - AreImported globals "ethereum.tangerine_whistle.vm.runtime" [ "get_valid_jump_destinations" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". + +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Set : + IsImported globals "typing" "Set". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". + +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes0 : + IsImported globals "ethereum.base_types" "Bytes0". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_trace_imports_EvmStop : + IsImported globals "ethereum.trace" "EvmStop". +Axiom ethereum_trace_imports_OpEnd : + IsImported globals "ethereum.trace" "OpEnd". +Axiom ethereum_trace_imports_OpException : + IsImported globals "ethereum.trace" "OpException". +Axiom ethereum_trace_imports_OpStart : + IsImported globals "ethereum.trace" "OpStart". +Axiom ethereum_trace_imports_PrecompileEnd : + IsImported globals "ethereum.trace" "PrecompileEnd". +Axiom ethereum_trace_imports_PrecompileStart : + IsImported globals "ethereum.trace" "PrecompileStart". +Axiom ethereum_trace_imports_TransactionEnd : + IsImported globals "ethereum.trace" "TransactionEnd". +Axiom ethereum_trace_imports_evm_trace : + IsImported globals "ethereum.trace" "evm_trace". + +Axiom ethereum_tangerine_whistle_blocks_imports_Log : + IsImported globals "ethereum.tangerine_whistle.blocks" "Log". + +Axiom ethereum_tangerine_whistle_fork_types_imports_Address : + IsImported globals "ethereum.tangerine_whistle.fork_types" "Address". + +Axiom ethereum_tangerine_whistle_state_imports_account_has_code_or_nonce : + IsImported globals "ethereum.tangerine_whistle.state" "account_has_code_or_nonce". +Axiom ethereum_tangerine_whistle_state_imports_begin_transaction : + IsImported globals "ethereum.tangerine_whistle.state" "begin_transaction". +Axiom ethereum_tangerine_whistle_state_imports_commit_transaction : + IsImported globals "ethereum.tangerine_whistle.state" "commit_transaction". +Axiom ethereum_tangerine_whistle_state_imports_destroy_storage : + IsImported globals "ethereum.tangerine_whistle.state" "destroy_storage". +Axiom ethereum_tangerine_whistle_state_imports_move_ether : + IsImported globals "ethereum.tangerine_whistle.state" "move_ether". +Axiom ethereum_tangerine_whistle_state_imports_rollback_transaction : + IsImported globals "ethereum.tangerine_whistle.state" "rollback_transaction". +Axiom ethereum_tangerine_whistle_state_imports_set_code : + IsImported globals "ethereum.tangerine_whistle.state" "set_code". +Axiom ethereum_tangerine_whistle_state_imports_touch_account : + IsImported globals "ethereum.tangerine_whistle.state" "touch_account". + +Axiom ethereum_tangerine_whistle_vm_imports_Message : + IsImported globals "ethereum.tangerine_whistle.vm" "Message". + +Axiom ethereum_tangerine_whistle_vm_gas_imports_GAS_CODE_DEPOSIT : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "GAS_CODE_DEPOSIT". +Axiom ethereum_tangerine_whistle_vm_gas_imports_charge_gas : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "charge_gas". + +Axiom ethereum_tangerine_whistle_vm_precompiled_contracts_mapping_imports_PRE_COMPILED_CONTRACTS : + IsImported globals "ethereum.tangerine_whistle.vm.precompiled_contracts.mapping" "PRE_COMPILED_CONTRACTS". + +Axiom ethereum_tangerine_whistle_vm_imports_Environment : + IsImported globals "ethereum.tangerine_whistle.vm" "Environment". +Axiom ethereum_tangerine_whistle_vm_imports_Evm : + IsImported globals "ethereum.tangerine_whistle.vm" "Evm". + +Axiom ethereum_tangerine_whistle_vm_exceptions_imports_AddressCollision : + IsImported globals "ethereum.tangerine_whistle.vm.exceptions" "AddressCollision". +Axiom ethereum_tangerine_whistle_vm_exceptions_imports_ExceptionalHalt : + IsImported globals "ethereum.tangerine_whistle.vm.exceptions" "ExceptionalHalt". +Axiom ethereum_tangerine_whistle_vm_exceptions_imports_InvalidOpcode : + IsImported globals "ethereum.tangerine_whistle.vm.exceptions" "InvalidOpcode". +Axiom ethereum_tangerine_whistle_vm_exceptions_imports_StackDepthLimitError : + IsImported globals "ethereum.tangerine_whistle.vm.exceptions" "StackDepthLimitError". + +Axiom ethereum_tangerine_whistle_vm_instructions_imports_Ops : + IsImported globals "ethereum.tangerine_whistle.vm.instructions" "Ops". +Axiom ethereum_tangerine_whistle_vm_instructions_imports_op_implementation : + IsImported globals "ethereum.tangerine_whistle.vm.instructions" "op_implementation". + +Axiom ethereum_tangerine_whistle_vm_runtime_imports_get_valid_jump_destinations : + IsImported globals "ethereum.tangerine_whistle.vm.runtime" "get_valid_jump_destinations". Definition STACK_DEPTH_LIMIT : Value.t := M.run ltac:(M.monadic ( M.call (| @@ -114,7 +162,8 @@ Definition process_message_call : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let is_collision := + let _ := M.assign_local (| + "is_collision" , M.call (| M.get_name (| globals, "account_has_code_or_nonce" |), make_list [ @@ -122,7 +171,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "message" |), "current_target" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -169,7 +219,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "process_create_message" |), make_list [ @@ -177,13 +228,15 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "process_message" |), make_list [ @@ -191,7 +244,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ )) |) in let _ := @@ -201,32 +255,43 @@ Definition process_message_call : Value.t -> Value.t -> M := (* then *) ltac:(M.monadic ( (* At stmt: unsupported node type: AnnAssign *) - let accounts_to_delete := + let _ := M.assign_local (| + "accounts_to_delete" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let refund_counter := + |) + |) in + let _ := M.assign_local (| + "refund_counter" , M.call (| M.get_name (| globals, "U256" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( - let logs := - M.get_field (| M.get_name (| globals, "evm" |), "logs" |) in - let accounts_to_delete := - M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) in - let refund_counter := - M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |) in + let _ := M.assign_local (| + "logs" , + M.get_field (| M.get_name (| globals, "evm" |), "logs" |) + |) in + let _ := M.assign_local (| + "accounts_to_delete" , + M.get_field (| M.get_name (| globals, "evm" |), "accounts_to_delete" |) + |) in + let _ := M.assign_local (| + "refund_counter" , + M.get_field (| M.get_name (| globals, "evm" |), "refund_counter" |) + |) in M.pure Constant.None_ )) |) in - let tx_end := + let _ := M.assign_local (| + "tx_end" , M.call (| M.get_name (| globals, "TransactionEnd" |), make_list [ @@ -238,7 +303,8 @@ Definition process_message_call : Value.t -> Value.t -> M := M.get_field (| M.get_name (| globals, "evm" |), "error" |) ], make_dict [] - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "evm_trace" |), make_list [ @@ -289,7 +355,8 @@ Definition process_create_message : Value.t -> Value.t -> M := ], make_dict [] |) in - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "process_message" |), make_list [ @@ -297,16 +364,20 @@ Definition process_create_message : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| UnOp.not (| M.get_field (| M.get_name (| globals, "evm" |), "error" |) |), (* then *) ltac:(M.monadic ( - let contract_code := - M.get_field (| M.get_name (| globals, "evm" |), "output" |) in - let contract_code_gas := + let _ := M.assign_local (| + "contract_code" , + M.get_field (| M.get_name (| globals, "evm" |), "output" |) + |) in + let _ := M.assign_local (| + "contract_code_gas" , BinOp.mult (| M.call (| M.get_name (| globals, "len" |), @@ -316,7 +387,8 @@ Definition process_create_message : Value.t -> Value.t -> M := make_dict [] |), M.get_name (| globals, "GAS_CODE_DEPOSIT" |) - |) in + |) + |) in (* At stmt: unsupported node type: Try *) M.pure Constant.None_ (* else *) @@ -418,7 +490,8 @@ Definition process_message : Value.t -> Value.t -> M := )), ltac:(M.monadic ( M.pure Constant.None_ )) |) in - let evm := + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "execute_code" |), make_list [ @@ -426,7 +499,8 @@ Definition process_message : Value.t -> Value.t -> M := M.get_name (| globals, "env" |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -475,22 +549,28 @@ Definition execute_code : Value.t -> Value.t -> M := evm: `ethereum.vm.EVM` Items containing execution specific objects " in - let code := - M.get_field (| M.get_name (| globals, "message" |), "code" |) in - let valid_jump_destinations := + let _ := M.assign_local (| + "code" , + M.get_field (| M.get_name (| globals, "message" |), "code" |) + |) in + let _ := M.assign_local (| + "valid_jump_destinations" , M.call (| M.get_name (| globals, "get_valid_jump_destinations" |), make_list [ M.get_name (| globals, "code" |) ], make_dict [] - |) in - let evm := + |) + |) in + let _ := M.assign_local (| + "evm" , M.call (| M.get_name (| globals, "Evm" |), make_list [], make_dict [] - |) in + |) + |) in (* At stmt: unsupported node type: Try *) let _ := M.return_ (| M.get_name (| globals, "evm" |) diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/memory.v b/CoqOfPython/ethereum/tangerine_whistle/vm/memory.v index 1bc0926..e8d40e2 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/memory.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/memory.v @@ -17,11 +17,15 @@ Introduction EVM memory operations. ". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "right_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_right_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "right_pad_zero_bytes". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Bytes"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". Definition memory_write : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/__init__.v b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/__init__.v index 533c3c9..8931f02 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/__init__.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/__init__.v @@ -18,8 +18,8 @@ Addresses of precompiled contracts and mappings to their implementations. ". -Axiom ethereum_tangerine_whistle_utils_hexadecimal_imports : - AreImported globals "ethereum.tangerine_whistle.utils.hexadecimal" [ "hex_to_address" ]. +Axiom ethereum_tangerine_whistle_utils_hexadecimal_imports_hex_to_address : + IsImported globals "ethereum.tangerine_whistle.utils.hexadecimal" "hex_to_address". Definition __all__ : Value.t := M.run ltac:(M.monadic ( make_tuple [ Constant.str "ECRECOVER_ADDRESS"; Constant.str "SHA256_ADDRESS"; Constant.str "RIPEMD160_ADDRESS"; Constant.str "IDENTITY_ADDRESS" ] diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/ecrecover.v b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/ecrecover.v index 8d8ddd1..1d6afbb 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/ecrecover.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/ecrecover.v @@ -17,26 +17,32 @@ Introduction Implementation of the ECRECOVER precompiled contract. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_crypto_elliptic_curve_imports : - AreImported globals "ethereum.crypto.elliptic_curve" [ "SECP256K1N"; "secp256k1_recover" ]. +Axiom ethereum_crypto_elliptic_curve_imports_SECP256K1N : + IsImported globals "ethereum.crypto.elliptic_curve" "SECP256K1N". +Axiom ethereum_crypto_elliptic_curve_imports_secp256k1_recover : + IsImported globals "ethereum.crypto.elliptic_curve" "secp256k1_recover". -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32"; "keccak256" ]. +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". +Axiom ethereum_crypto_hash_imports_keccak256 : + IsImported globals "ethereum.crypto.hash" "keccak256". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_left_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "left_pad_zero_bytes". -Axiom ethereum_tangerine_whistle_vm_imports : - AreImported globals "ethereum.tangerine_whistle.vm" [ "Evm" ]. +Axiom ethereum_tangerine_whistle_vm_imports_Evm : + IsImported globals "ethereum.tangerine_whistle.vm" "Evm". -Axiom ethereum_tangerine_whistle_vm_gas_imports : - AreImported globals "ethereum.tangerine_whistle.vm.gas" [ "GAS_ECRECOVER"; "charge_gas" ]. +Axiom ethereum_tangerine_whistle_vm_gas_imports_GAS_ECRECOVER : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "GAS_ECRECOVER". +Axiom ethereum_tangerine_whistle_vm_gas_imports_charge_gas : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "charge_gas". -Axiom ethereum_tangerine_whistle_vm_memory_imports : - AreImported globals "ethereum.tangerine_whistle.vm.memory" [ "buffer_read" ]. +Axiom ethereum_tangerine_whistle_vm_memory_imports_buffer_read : + IsImported globals "ethereum.tangerine_whistle.vm.memory" "buffer_read". Definition ecrecover : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -50,8 +56,10 @@ Definition ecrecover : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -60,7 +68,8 @@ Definition ecrecover : Value.t -> Value.t -> M := ], make_dict [] |) in - let message_hash_bytes := + let _ := M.assign_local (| + "message_hash_bytes" , M.call (| M.get_name (| globals, "buffer_read" |), make_list [ @@ -81,16 +90,20 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let message_hash := + |) + |) in + let _ := M.assign_local (| + "message_hash" , M.call (| M.get_name (| globals, "Hash32" |), make_list [ M.get_name (| globals, "message_hash_bytes" |) ], make_dict [] - |) in - let v := + |) + |) in + let _ := M.assign_local (| + "v" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -117,8 +130,10 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let r := + |) + |) in + let _ := M.assign_local (| + "r" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -145,8 +160,10 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in - let s := + |) + |) in + let _ := M.assign_local (| + "s" , M.call (| M.get_field (| M.get_name (| globals, "U256" |), "from_be_bytes" |), make_list [ @@ -173,7 +190,8 @@ Definition ecrecover : Value.t -> Value.t -> M := |) ], make_dict [] - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -250,7 +268,8 @@ Definition ecrecover : Value.t -> Value.t -> M := M.pure Constant.None_ )) |) in (* At stmt: unsupported node type: Try *) - let address := + let _ := M.assign_local (| + "address" , M.slice (| M.call (| M.get_name (| globals, "keccak256" |), @@ -262,8 +281,10 @@ Definition ecrecover : Value.t -> Value.t -> M := Constant.int 12, Constant.int 32, Constant.None_ - |) in - let padded_address := + |) + |) in + let _ := M.assign_local (| + "padded_address" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -271,7 +292,8 @@ Definition ecrecover : Value.t -> Value.t -> M := Constant.int 32 ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.get_name (| globals, "padded_address" |) diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/identity.v b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/identity.v index 655cd9a..9226b27 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/identity.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/identity.v @@ -17,17 +17,21 @@ Introduction Implementation of the `IDENTITY` precompiled contract. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_tangerine_whistle_vm_imports : - AreImported globals "ethereum.tangerine_whistle.vm" [ "Evm" ]. +Axiom ethereum_tangerine_whistle_vm_imports_Evm : + IsImported globals "ethereum.tangerine_whistle.vm" "Evm". -Axiom ethereum_tangerine_whistle_vm_gas_imports : - AreImported globals "ethereum.tangerine_whistle.vm.gas" [ "GAS_IDENTITY"; "GAS_IDENTITY_WORD"; "charge_gas" ]. +Axiom ethereum_tangerine_whistle_vm_gas_imports_GAS_IDENTITY : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "GAS_IDENTITY". +Axiom ethereum_tangerine_whistle_vm_gas_imports_GAS_IDENTITY_WORD : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "GAS_IDENTITY_WORD". +Axiom ethereum_tangerine_whistle_vm_gas_imports_charge_gas : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "charge_gas". Definition identity : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -40,9 +44,12 @@ Definition identity : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let word_count := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "word_count" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -64,7 +71,8 @@ Definition identity : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/mapping.v b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/mapping.v index e678e41..450b048 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/mapping.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/mapping.v @@ -17,25 +17,33 @@ Introduction Mapping of precompiled contracts their implementations. ". -Axiom typing_imports : - AreImported globals "typing" [ "Callable"; "Dict" ]. - -Axiom ethereum_tangerine_whistle_fork_types_imports : - AreImported globals "ethereum.tangerine_whistle.fork_types" [ "Address" ]. - -Axiom ethereum_tangerine_whistle_vm_precompiled_contracts_imports : - AreImported globals "ethereum.tangerine_whistle.vm.precompiled_contracts" [ "ECRECOVER_ADDRESS"; "IDENTITY_ADDRESS"; "RIPEMD160_ADDRESS"; "SHA256_ADDRESS" ]. - -Axiom ethereum_tangerine_whistle_vm_precompiled_contracts_ecrecover_imports : - AreImported globals "ethereum.tangerine_whistle.vm.precompiled_contracts.ecrecover" [ "ecrecover" ]. - -Axiom ethereum_tangerine_whistle_vm_precompiled_contracts_identity_imports : - AreImported globals "ethereum.tangerine_whistle.vm.precompiled_contracts.identity" [ "identity" ]. - -Axiom ethereum_tangerine_whistle_vm_precompiled_contracts_ripemd160_imports : - AreImported globals "ethereum.tangerine_whistle.vm.precompiled_contracts.ripemd160" [ "ripemd160" ]. - -Axiom ethereum_tangerine_whistle_vm_precompiled_contracts_sha256_imports : - AreImported globals "ethereum.tangerine_whistle.vm.precompiled_contracts.sha256" [ "sha256" ]. +Axiom typing_imports_Callable : + IsImported globals "typing" "Callable". +Axiom typing_imports_Dict : + IsImported globals "typing" "Dict". + +Axiom ethereum_tangerine_whistle_fork_types_imports_Address : + IsImported globals "ethereum.tangerine_whistle.fork_types" "Address". + +Axiom ethereum_tangerine_whistle_vm_precompiled_contracts_imports_ECRECOVER_ADDRESS : + IsImported globals "ethereum.tangerine_whistle.vm.precompiled_contracts" "ECRECOVER_ADDRESS". +Axiom ethereum_tangerine_whistle_vm_precompiled_contracts_imports_IDENTITY_ADDRESS : + IsImported globals "ethereum.tangerine_whistle.vm.precompiled_contracts" "IDENTITY_ADDRESS". +Axiom ethereum_tangerine_whistle_vm_precompiled_contracts_imports_RIPEMD160_ADDRESS : + IsImported globals "ethereum.tangerine_whistle.vm.precompiled_contracts" "RIPEMD160_ADDRESS". +Axiom ethereum_tangerine_whistle_vm_precompiled_contracts_imports_SHA256_ADDRESS : + IsImported globals "ethereum.tangerine_whistle.vm.precompiled_contracts" "SHA256_ADDRESS". + +Axiom ethereum_tangerine_whistle_vm_precompiled_contracts_ecrecover_imports_ecrecover : + IsImported globals "ethereum.tangerine_whistle.vm.precompiled_contracts.ecrecover" "ecrecover". + +Axiom ethereum_tangerine_whistle_vm_precompiled_contracts_identity_imports_identity : + IsImported globals "ethereum.tangerine_whistle.vm.precompiled_contracts.identity" "identity". + +Axiom ethereum_tangerine_whistle_vm_precompiled_contracts_ripemd160_imports_ripemd160 : + IsImported globals "ethereum.tangerine_whistle.vm.precompiled_contracts.ripemd160" "ripemd160". + +Axiom ethereum_tangerine_whistle_vm_precompiled_contracts_sha256_imports_sha256 : + IsImported globals "ethereum.tangerine_whistle.vm.precompiled_contracts.sha256" "sha256". (* At top_level_stmt: unsupported node type: AnnAssign *) diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/ripemd160.v b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/ripemd160.v index 145db2b..52fd66f 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/ripemd160.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/ripemd160.v @@ -19,20 +19,24 @@ Implementation of the `RIPEMD160` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_byte_imports : - AreImported globals "ethereum.utils.byte" [ "left_pad_zero_bytes" ]. +Axiom ethereum_utils_byte_imports_left_pad_zero_bytes : + IsImported globals "ethereum.utils.byte" "left_pad_zero_bytes". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_tangerine_whistle_vm_imports : - AreImported globals "ethereum.tangerine_whistle.vm" [ "Evm" ]. +Axiom ethereum_tangerine_whistle_vm_imports_Evm : + IsImported globals "ethereum.tangerine_whistle.vm" "Evm". -Axiom ethereum_tangerine_whistle_vm_gas_imports : - AreImported globals "ethereum.tangerine_whistle.vm.gas" [ "GAS_RIPEMD160"; "GAS_RIPEMD160_WORD"; "charge_gas" ]. +Axiom ethereum_tangerine_whistle_vm_gas_imports_GAS_RIPEMD160 : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "GAS_RIPEMD160". +Axiom ethereum_tangerine_whistle_vm_gas_imports_GAS_RIPEMD160_WORD : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "GAS_RIPEMD160_WORD". +Axiom ethereum_tangerine_whistle_vm_gas_imports_charge_gas : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "charge_gas". Definition ripemd160 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -45,9 +49,12 @@ Definition ripemd160 : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let word_count := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "word_count" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -69,7 +76,8 @@ Definition ripemd160 : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ @@ -84,7 +92,8 @@ Definition ripemd160 : Value.t -> Value.t -> M := ], make_dict [] |) in - let hash_bytes := + let _ := M.assign_local (| + "hash_bytes" , M.call (| M.get_field (| M.call (| M.get_field (| M.get_name (| globals, "hashlib" |), "new" |), @@ -96,8 +105,10 @@ Definition ripemd160 : Value.t -> Value.t -> M := |), "digest" |), make_list [], make_dict [] - |) in - let padded_hash := + |) + |) in + let _ := M.assign_local (| + "padded_hash" , M.call (| M.get_name (| globals, "left_pad_zero_bytes" |), make_list [ @@ -105,7 +116,8 @@ Definition ripemd160 : Value.t -> Value.t -> M := Constant.int 32 ], make_dict [] - |) in + |) + |) in let _ := M.assign (| M.get_field (| M.get_name (| globals, "evm" |), "output" |), M.get_name (| globals, "padded_hash" |) diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/sha256.v b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/sha256.v index 9d5702e..5144a3e 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/sha256.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/precompiled_contracts/sha256.v @@ -19,17 +19,21 @@ Implementation of the `SHA256` precompiled contract. (* At top_level_stmt: unsupported node type: Import *) -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_utils_numeric_imports : - AreImported globals "ethereum.utils.numeric" [ "ceil32" ]. +Axiom ethereum_utils_numeric_imports_ceil32 : + IsImported globals "ethereum.utils.numeric" "ceil32". -Axiom ethereum_tangerine_whistle_vm_imports : - AreImported globals "ethereum.tangerine_whistle.vm" [ "Evm" ]. +Axiom ethereum_tangerine_whistle_vm_imports_Evm : + IsImported globals "ethereum.tangerine_whistle.vm" "Evm". -Axiom ethereum_tangerine_whistle_vm_gas_imports : - AreImported globals "ethereum.tangerine_whistle.vm.gas" [ "GAS_SHA256"; "GAS_SHA256_WORD"; "charge_gas" ]. +Axiom ethereum_tangerine_whistle_vm_gas_imports_GAS_SHA256 : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "GAS_SHA256". +Axiom ethereum_tangerine_whistle_vm_gas_imports_GAS_SHA256_WORD : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "GAS_SHA256_WORD". +Axiom ethereum_tangerine_whistle_vm_gas_imports_charge_gas : + IsImported globals "ethereum.tangerine_whistle.vm.gas" "charge_gas". Definition sha256 : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -42,9 +46,12 @@ Definition sha256 : Value.t -> Value.t -> M := evm : The current EVM frame. " in - let data := - M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) in - let word_count := + let _ := M.assign_local (| + "data" , + M.get_field (| M.get_field (| M.get_name (| globals, "evm" |), "message" |), "data" |) + |) in + let _ := M.assign_local (| + "word_count" , BinOp.floor_div (| M.call (| M.get_name (| globals, "ceil32" |), @@ -66,7 +73,8 @@ Definition sha256 : Value.t -> Value.t -> M := make_dict [] |), Constant.int 32 - |) in + |) + |) in let _ := M.call (| M.get_name (| globals, "charge_gas" |), make_list [ diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/runtime.v b/CoqOfPython/ethereum/tangerine_whistle/vm/runtime.v index dc740b0..fc5eb03 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/runtime.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/runtime.v @@ -17,14 +17,14 @@ Introduction Runtime related operations used while executing EVM code. ". -Axiom typing_imports : - AreImported globals "typing" [ "Set" ]. +Axiom typing_imports_Set : + IsImported globals "typing" "Set". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Uint" ]. +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". -Axiom ethereum_tangerine_whistle_vm_instructions_imports : - AreImported globals "ethereum.tangerine_whistle.vm.instructions" [ "Ops" ]. +Axiom ethereum_tangerine_whistle_vm_instructions_imports_Ops : + IsImported globals "ethereum.tangerine_whistle.vm.instructions" "Ops". Definition get_valid_jump_destinations : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -50,20 +50,24 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := valid_jump_destinations: `Set[Uint]` The set of valid jump destinations in the code. " in - let valid_jump_destinations := + let _ := M.assign_local (| + "valid_jump_destinations" , M.call (| M.get_name (| globals, "set" |), make_list [], make_dict [] - |) in - let pc := + |) + |) in + let _ := M.assign_local (| + "pc" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 0 ], make_dict [] - |) in + |) + |) in let _ := M.while (| Compare.lt (| @@ -114,17 +118,21 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := |), (* then *) ltac:(M.monadic ( - let push_data_size := + let _ := M.assign_local (| + "push_data_size" , BinOp.add (| BinOp.sub (| M.get_field (| M.get_name (| globals, "current_opcode" |), "value" |), M.get_field (| M.get_field (| M.get_name (| globals, "Ops" |), "PUSH1" |), "value" |) |), Constant.int 1 - |) in - let pc := BinOp.add + |) + |) in + let _ := M.assign_op_local (| + BinOp.add, + "pc", M.get_name (| globals, "push_data_size" |) - M.get_name (| globals, "push_data_size" |) in + |) in M.pure Constant.None_ (* else *) )), ltac:(M.monadic ( @@ -132,9 +140,11 @@ Definition get_valid_jump_destinations : Value.t -> Value.t -> M := )) |) in M.pure Constant.None_ )) |) in - let pc := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "pc", Constant.int 1 - Constant.int 1 in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/tangerine_whistle/vm/stack.v b/CoqOfPython/ethereum/tangerine_whistle/vm/stack.v index b163880..6311bf2 100644 --- a/CoqOfPython/ethereum/tangerine_whistle/vm/stack.v +++ b/CoqOfPython/ethereum/tangerine_whistle/vm/stack.v @@ -17,14 +17,16 @@ Introduction Implementation of the stack operators for the EVM. ". -Axiom typing_imports : - AreImported globals "typing" [ "List" ]. +Axiom typing_imports_List : + IsImported globals "typing" "List". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". -Axiom ethereum_tangerine_whistle_vm_exceptions_imports : - AreImported globals "ethereum.tangerine_whistle.vm.exceptions" [ "StackOverflowError"; "StackUnderflowError" ]. +Axiom ethereum_tangerine_whistle_vm_exceptions_imports_StackOverflowError : + IsImported globals "ethereum.tangerine_whistle.vm.exceptions" "StackOverflowError". +Axiom ethereum_tangerine_whistle_vm_exceptions_imports_StackUnderflowError : + IsImported globals "ethereum.tangerine_whistle.vm.exceptions" "StackUnderflowError". Definition pop : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/trace.v b/CoqOfPython/ethereum/trace.v index a0176e9..c659277 100644 --- a/CoqOfPython/ethereum/trace.v +++ b/CoqOfPython/ethereum/trace.v @@ -21,11 +21,13 @@ Defines the functions required for creating evm traces during execution. (* At top_level_stmt: unsupported node type: Import *) -Axiom dataclasses_imports : - AreImported globals "dataclasses" [ "dataclass" ]. +Axiom dataclasses_imports_dataclass : + IsImported globals "dataclasses" "dataclass". -Axiom typing_imports : - AreImported globals "typing" [ "Optional"; "Union" ]. +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". Definition TransactionStart : Value.t := builtins.make_klass diff --git a/CoqOfPython/ethereum/utils/byte.v b/CoqOfPython/ethereum/utils/byte.v index 0d41aa0..07efce7 100644 --- a/CoqOfPython/ethereum/utils/byte.v +++ b/CoqOfPython/ethereum/utils/byte.v @@ -17,8 +17,8 @@ Introduction Byte specific utility functions used in this specification. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "Bytes" ]. +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". Definition left_pad_zero_bytes : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/utils/ensure.v b/CoqOfPython/ethereum/utils/ensure.v index 8955c24..88c6e02 100644 --- a/CoqOfPython/ethereum/utils/ensure.v +++ b/CoqOfPython/ethereum/utils/ensure.v @@ -17,8 +17,10 @@ Introduction Functions that simplify checking assertions and raising exceptions. ". -Axiom typing_imports : - AreImported globals "typing" [ "Type"; "Union" ]. +Axiom typing_imports_Type : + IsImported globals "typing" "Type". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". Definition ensure : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/utils/hexadecimal.v b/CoqOfPython/ethereum/utils/hexadecimal.v index a63732a..822bc50 100644 --- a/CoqOfPython/ethereum/utils/hexadecimal.v +++ b/CoqOfPython/ethereum/utils/hexadecimal.v @@ -17,11 +17,25 @@ Introduction Hexadecimal strings specific utility functions used in this specification. ". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U64"; "U256"; "Bytes"; "Bytes8"; "Bytes20"; "Bytes32"; "Bytes256"; "Uint" ]. - -Axiom ethereum_crypto_hash_imports : - AreImported globals "ethereum.crypto.hash" [ "Hash32" ]. +Axiom ethereum_base_types_imports_U64 : + IsImported globals "ethereum.base_types" "U64". +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Bytes : + IsImported globals "ethereum.base_types" "Bytes". +Axiom ethereum_base_types_imports_Bytes8 : + IsImported globals "ethereum.base_types" "Bytes8". +Axiom ethereum_base_types_imports_Bytes20 : + IsImported globals "ethereum.base_types" "Bytes20". +Axiom ethereum_base_types_imports_Bytes32 : + IsImported globals "ethereum.base_types" "Bytes32". +Axiom ethereum_base_types_imports_Bytes256 : + IsImported globals "ethereum.base_types" "Bytes256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". + +Axiom ethereum_crypto_hash_imports_Hash32 : + IsImported globals "ethereum.crypto.hash" "Hash32". Definition has_hex_prefix : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/utils/numeric.v b/CoqOfPython/ethereum/utils/numeric.v index c1c111b..a3fc348 100644 --- a/CoqOfPython/ethereum/utils/numeric.v +++ b/CoqOfPython/ethereum/utils/numeric.v @@ -17,11 +17,15 @@ Introduction Numeric operations specific utility functions used in this specification. ". -Axiom typing_imports : - AreImported globals "typing" [ "Sequence"; "Tuple" ]. +Axiom typing_imports_Sequence : + IsImported globals "typing" "Sequence". +Axiom typing_imports_Tuple : + IsImported globals "typing" "Tuple". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U32"; "Uint" ]. +Axiom ethereum_base_types_imports_U32 : + IsImported globals "ethereum.base_types" "U32". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". Definition get_sign : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -97,19 +101,23 @@ Definition ceil32 : Value.t -> Value.t -> M := else it returns the smallest multiple of 32 that is greater than `value`. " in - let ceiling := + let _ := M.assign_local (| + "ceiling" , M.call (| M.get_name (| globals, "Uint" |), make_list [ Constant.int 32 ], make_dict [] - |) in - let remainder := + |) + |) in + let _ := M.assign_local (| + "remainder" , BinOp.mod_ (| M.get_name (| globals, "value" |), M.get_name (| globals, "ceiling" |) - |) in + |) + |) in let _ := (* if *) M.if_then_else (| @@ -190,7 +198,7 @@ Definition is_prime : Value.t -> Value.t -> M := make_list [ BinOp.pow (| M.get_name (| globals, "number" |), - Value.Float 0.5 + Constant.float "0.5" |) ], make_dict [] @@ -252,8 +260,10 @@ Definition le_bytes_to_uint32_sequence : Value.t -> Value.t -> M := Sequence of U32 numbers obtained from the little endian byte stream. " in - let sequence := - make_list [] in + let _ := M.assign_local (| + "sequence" , + make_list [] + |) in let _ := M.for_ (| M.get_name (| globals, "i" |), @@ -338,24 +348,24 @@ Definition le_uint32_sequence_to_bytes : Value.t -> Value.t -> M := result : `bytes` The byte stream obtained from the little endian U32 stream. " in - let result_bytes := - Constant.bytes "" in + let _ := M.assign_local (| + "result_bytes" , + Constant.bytes "" + |) in let _ := M.for_ (| M.get_name (| globals, "item" |), M.get_name (| globals, "sequence" |), ltac:(M.monadic ( - let result_bytes := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "result_bytes", M.call (| M.get_field (| M.get_name (| globals, "item" |), "to_le_bytes4" |), make_list [], make_dict [] |) - M.call (| - M.get_field (| M.get_name (| globals, "item" |), "to_le_bytes4" |), - make_list [], - make_dict [] - |) in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( @@ -386,14 +396,16 @@ Definition le_uint32_sequence_to_uint : Value.t -> Value.t -> M := The Uint number obtained from the conversion of the little endian U32 stream. " in - let sequence_as_bytes := + let _ := M.assign_local (| + "sequence_as_bytes" , M.call (| M.get_name (| globals, "le_uint32_sequence_to_bytes" |), make_list [ M.get_name (| globals, "sequence" |) ], make_dict [] - |) in + |) + |) in let _ := M.return_ (| M.call (| M.get_field (| M.get_name (| globals, "Uint" |), "from_le_bytes" |), @@ -427,15 +439,21 @@ Definition taylor_exponential : Value.t -> Value.t -> M := The approximation of factor * e ** (numerator / denominator). " in - let i := - Constant.int 1 in - let output := - Constant.int 0 in - let numerator_accumulated := + let _ := M.assign_local (| + "i" , + Constant.int 1 + |) in + let _ := M.assign_local (| + "output" , + Constant.int 0 + |) in + let _ := M.assign_local (| + "numerator_accumulated" , BinOp.mult (| M.get_name (| globals, "factor" |), M.get_name (| globals, "denominator" |) - |) in + |) + |) in let _ := M.while (| Compare.gt (| @@ -443,10 +461,13 @@ Definition taylor_exponential : Value.t -> Value.t -> M := Constant.int 0 |), ltac:(M.monadic ( - let output := BinOp.add + let _ := M.assign_op_local (| + BinOp.add, + "output", M.get_name (| globals, "numerator_accumulated" |) - M.get_name (| globals, "numerator_accumulated" |) in - let numerator_accumulated := + |) in + let _ := M.assign_local (| + "numerator_accumulated" , BinOp.floor_div (| BinOp.mult (| M.get_name (| globals, "numerator_accumulated" |), @@ -456,10 +477,13 @@ Definition taylor_exponential : Value.t -> Value.t -> M := M.get_name (| globals, "denominator" |), M.get_name (| globals, "i" |) |) - |) in - let i := BinOp.add + |) + |) in + let _ := M.assign_op_local (| + BinOp.add, + "i", Constant.int 1 - Constant.int 1 in + |) in M.pure Constant.None_ )), ltac:(M.monadic ( diff --git a/CoqOfPython/ethereum/utils/safe_arithmetic.v b/CoqOfPython/ethereum/utils/safe_arithmetic.v index be5bf78..0702f0e 100644 --- a/CoqOfPython/ethereum/utils/safe_arithmetic.v +++ b/CoqOfPython/ethereum/utils/safe_arithmetic.v @@ -17,11 +17,17 @@ Introduction Safe arithmetic utility functions for U256 integer type. ". -Axiom typing_imports : - AreImported globals "typing" [ "Optional"; "Type"; "Union" ]. +Axiom typing_imports_Optional : + IsImported globals "typing" "Optional". +Axiom typing_imports_Type : + IsImported globals "typing" "Type". +Axiom typing_imports_Union : + IsImported globals "typing" "Union". -Axiom ethereum_base_types_imports : - AreImported globals "ethereum.base_types" [ "U256"; "Uint" ]. +Axiom ethereum_base_types_imports_U256 : + IsImported globals "ethereum.base_types" "U256". +Axiom ethereum_base_types_imports_Uint : + IsImported globals "ethereum.base_types" "Uint". Definition u256_safe_add : Value.t -> Value.t -> M := fun (args kwargs : Value.t) => ltac:(M.monadic ( @@ -82,10 +88,12 @@ Definition u256_safe_multiply : Value.t -> Value.t -> M := one raised by `U256` when `U256.value > U256.MAX_VALUE` else `exception_type` is raised. " in - let result := + let _ := M.assign_local (| + "result" , M.get_subscript (| M.get_name (| globals, "numbers" |), Constant.int 0 - |) in + |) + |) in (* At stmt: unsupported node type: Try *) M.pure Constant.None_)). diff --git a/main.py b/main.py index 2b532fc..332e894 100644 --- a/main.py +++ b/main.py @@ -58,13 +58,15 @@ def generate_constant(node, value): elif isinstance(value, int): return f"Constant.int {str(value)}" elif isinstance(value, float): - return f"Value.Float {str(value)}" + return f"Constant.float \"{str(value)}\"" elif isinstance(value, str): - return "Constant.str \"" + value.replace("\"", "\"\"\"") + "\"" + return "Constant.str \"" + value.replace("\"", "\"\"") + "\"" elif isinstance(value, bytes): return "Constant.bytes \"" + value.hex() + "\"" + elif value == ...: + return "Constant.ellipsis" else: - return generate_error("constant", node) + return generate_error(f"constant {type(value)}", node) def generate_mod(node: ast.mod): @@ -99,7 +101,7 @@ def get_globals_of_import(node: ast.ImportFrom) -> str: def generate_top_level_stmt(node: ast.stmt): if isinstance(node, ast.FunctionDef): - return f"Definition {node.name} : Value.t -> Value.t -> M :=\n" + \ + return f"Definition {generate_name(node.name)} : Value.t -> Value.t -> M :=\n" + \ generate_indent(1) + generate_function_def_body(1, node) + "." elif isinstance(node, ast.AsyncFunctionDef): return generate_error("top_level_stmt", node) @@ -174,10 +176,12 @@ def generate_top_level_stmt(node: ast.stmt): module = get_globals_of_import(node) snake_module = module.replace(".", "_") - return f"Axiom {snake_module}_imports :\n" + \ - generate_indent(1) + \ - f"AreImported globals \"{module}\" [ " + \ - "; ".join(f"\"{alias.name}\"" for alias in node.names) + " ]." + return "\n".join( + f"Axiom {snake_module}_imports_{alias.name} :\n" + + generate_indent(1) + + f"IsImported globals \"{module}\" \"{alias.name}\"." + for alias in node.names + ) elif isinstance(node, ast.Global): return generate_error("top_level_stmt", node) elif isinstance(node, ast.Nonlocal): @@ -258,9 +262,12 @@ def generate_stmt(indent, node: ast.stmt): target = node.targets[0] if isinstance(target, ast.Name): - return generate_indent(indent) + "let " + target.id + " :=\n" + \ + return generate_indent(indent) + "let _ := M.assign_local (|\n" + \ + generate_indent(indent + 1) + \ + "\"" + target.id + "\" ,\n" + \ generate_indent(indent + 1) + \ - generate_expr(indent + 1, False, node.value) + " in" + generate_expr(indent + 1, False, node.value) + "\n" + \ + generate_indent(indent) + "|) in" return generate_indent(indent) + "let _ := M.assign (|\n" + \ generate_indent(indent + 1) + \ @@ -272,11 +279,11 @@ def generate_stmt(indent, node: ast.stmt): # return generate_error("stmt", node) elif isinstance(node, ast.AugAssign): if isinstance(node.target, ast.Name): - return generate_indent(indent) + "let " + node.target.id + " := " + \ - generate_operator(node.op) + "\n" + \ - generate_indent(indent + 1) + generate_expr(1, False, node.value) + "\n" + \ - generate_indent(indent + 1) + \ - generate_expr(1, False, node.value) + " in" + return generate_indent(indent) + "let _ := M.assign_op_local (|\n" + \ + generate_indent(indent + 1) + generate_operator(node.op) + ",\n" + \ + generate_indent(indent + 1) + "\"" + node.target.id + "\",\n" + \ + generate_indent(indent + 1) + generate_expr(1, False, node.value) + "\n" +\ + generate_indent(indent) + "|) in" return generate_indent(indent) + "let _ := M.assign_op (|\n" + \ generate_indent(indent + 1) + generate_operator(node.op) + ",\n" + \ @@ -497,17 +504,9 @@ def generate_expr(indent, is_with_paren, node: ast.expr): generate_if_then_else(indent, node.test, node.body, node.orelse) ) elif isinstance(node, ast.Dict): - return "{" + \ - ", ".join( - (generate_expr(indent, False, key) - if key is not None - else "?") + - ": " + generate_expr(indent, False, value) - for key, value in zip(node.keys, node.values) - ) + \ - "}" + return generate_error("expr", node) elif isinstance(node, ast.Set): - return "{" + ", ".join(generate_expr(indent, False, elt) for elt in node.elts) + "}" + return generate_error("expr", node) elif isinstance(node, ast.ListComp): return generate_error("expr", node) elif isinstance(node, ast.SetComp): From d3bda96196f9d665130d7e899476339b28be06b3 Mon Sep 17 00:00:00 2001 From: Guillaume Claret Date: Fri, 10 May 2024 22:08:09 +0200 Subject: [PATCH 6/6] Add CI --- .github/workflows/coq.yml | 34 ++++++++++++++++++++++++++++++++++ CoqOfPython/coq-of-python.opam | 23 +++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 .github/workflows/coq.yml create mode 100644 CoqOfPython/coq-of-python.opam diff --git a/.github/workflows/coq.yml b/.github/workflows/coq.yml new file mode 100644 index 0000000..5949cec --- /dev/null +++ b/.github/workflows/coq.yml @@ -0,0 +1,34 @@ +name: Coq + +on: + push: + branches: ["main"] + pull_request: + branches: ["main"] + +env: + CARGO_TERM_COLOR: always + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Download Git submodules + run: git submodule update --init --recursive + - uses: coq-community/docker-coq-action@v1 + with: + custom_image: coqorg/coq:8.17-ocaml-4.14-flambda + custom_script: | + startGroup "Install dependencies" + opam install -y --deps-only CoqOfPython/coq-of-python.opam + endGroup + startGroup "Set the rights" + sudo chown -R $(whoami) . + endGroup + startGroup "Compile Coq translations" + cd CoqOfPython + make + cd .. + endGroup diff --git a/CoqOfPython/coq-of-python.opam b/CoqOfPython/coq-of-python.opam new file mode 100644 index 0000000..5204e4d --- /dev/null +++ b/CoqOfPython/coq-of-python.opam @@ -0,0 +1,23 @@ +opam-version: "2.0" +name: "coq-of-python" +version: "0.1" +synopsis: "Coq of Python" +description: """ +Formal verification for Python by translation to the proof system Coq +""" +maintainer: "Guillaume Claret " +authors: [ + "Formal Land " +] +license: "MIT" +homepage: "https://github.com/formal-land/coq-of-python" +bug-reports: "https://github.com/formal-land/coq-of-python/issues" +dev-repo: "git+https://github.com/formal-land/coq-of-python.git" +depends: [ + "ocaml" {>= "4.08"} + "coq" {>= "8.17.1" & < "8.18"} + "coq-hammer" {>= "1.3.2+8.17" & < "1.3.2+8.18"} +] +build: [ + [make] +]